@shaclmate/compiler 4.0.12 → 4.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/dist/ShapesGraphToAstTransformer.js +2 -2
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +6 -5
- package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.d.ts +3 -2
- package/dist/_ShapesGraphToAstTransformer/nodeShapeIdentifierMintingStrategy.js +8 -5
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +2 -1
- package/dist/_ShapesGraphToAstTransformer/shapeAstTypeName.js +6 -6
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.d.ts +2 -1
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +23 -17
- package/dist/_ShapesGraphToAstTransformer/shapeOntology.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/shapeOntology.js +25 -0
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +23 -16
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +6 -6
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +15 -15
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +122 -118
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +10 -8
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +3 -3
- package/dist/ast/ObjectType.d.ts +3 -3
- package/dist/enums/IdentifierMintingStrategy.d.ts +4 -0
- package/dist/enums/IdentifierMintingStrategy.js +17 -1
- package/dist/enums/TsObjectDeclarationType.d.ts +4 -0
- package/dist/enums/TsObjectDeclarationType.js +15 -1
- package/dist/enums/Visibility.d.ts +6 -0
- package/dist/enums/Visibility.js +18 -0
- package/dist/generators/ts/AbstractCollectionType.js +4 -1
- package/dist/generators/ts/AbstractUnionType.js +2 -2
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +3 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +6 -12
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +1 -1
- package/dist/input/NodeShape.d.ts +8 -46
- package/dist/input/NodeShape.js +1 -153
- package/dist/input/Shape.d.ts +2 -2
- package/dist/input/ShapesGraph.d.ts +10 -10
- package/dist/input/ShapesGraph.js +11 -13
- package/dist/input/generated.d.ts +185 -152
- package/dist/input/generated.js +316 -249
- package/dist/input/index.d.ts +1 -3
- package/dist/input/index.js +1 -3
- package/package.json +2 -2
- package/dist/enums/PropertyVisibility.d.ts +0 -2
- package/dist/enums/PropertyVisibility.js +0 -2
- package/dist/input/Ontology.d.ts +0 -13
- package/dist/input/Ontology.js +0 -40
- package/dist/input/PropertyShape.d.ts +0 -20
- package/dist/input/PropertyShape.js +0 -78
|
@@ -2,12 +2,14 @@ import { Either, Left, Maybe } from "purify-ts";
|
|
|
2
2
|
import { invariant } from "ts-invariant";
|
|
3
3
|
import * as ast from "../ast/index.js";
|
|
4
4
|
import { Eithers } from "../Eithers.js";
|
|
5
|
+
import { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
|
|
5
6
|
import { defaultNodeShapeNodeKinds } from "./defaultNodeShapeNodeKinds.js";
|
|
6
7
|
import { nodeShapeIdentifierMintingStrategy } from "./nodeShapeIdentifierMintingStrategy.js";
|
|
7
8
|
import { nodeShapeTsFeatures } from "./nodeShapeTsFeatures.js";
|
|
8
9
|
import { ShapeStack } from "./ShapeStack.js";
|
|
9
10
|
import { shapeAstTypeName } from "./shapeAstTypeName.js";
|
|
10
11
|
import { shapeNodeKinds } from "./shapeNodeKinds.js";
|
|
12
|
+
import { shapeOntology } from "./shapeOntology.js";
|
|
11
13
|
import { transformPropertyShapeToAstObjectTypeProperty } from "./transformPropertyShapeToAstObjectTypeProperty.js";
|
|
12
14
|
import { transformShapeToAstType } from "./transformShapeToAstType.js";
|
|
13
15
|
function isObjectTypePropertyRequired(property) {
|
|
@@ -43,135 +45,137 @@ function isObjectTypePropertyRequired(property) {
|
|
|
43
45
|
export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
44
46
|
shapeStack.push(shape);
|
|
45
47
|
try {
|
|
46
|
-
if (shape
|
|
48
|
+
if (shape.$type !== "NodeShape") {
|
|
47
49
|
return Either.of(Maybe.empty());
|
|
48
50
|
}
|
|
49
51
|
const nodeShape = shape;
|
|
50
|
-
if (nodeShape.
|
|
52
|
+
if (nodeShape.and.length > 0 || nodeShape.xone.length > 0) {
|
|
51
53
|
return Either.of(Maybe.empty());
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
toRdfTypes = nodeShape.toRdfTypes.concat();
|
|
70
|
-
if (toRdfTypes.length === 0) {
|
|
71
|
-
toRdfTypes.push(...nodeShape.rdfType.toList());
|
|
72
|
-
}
|
|
73
|
-
// Ensure toRdfTypes has fromRdfType
|
|
74
|
-
fromRdfType.ifJust((fromRdfType) => {
|
|
75
|
-
if (!toRdfTypes.some((toRdfType) => toRdfType.equals(fromRdfType))) {
|
|
76
|
-
toRdfTypes.push(fromRdfType);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
fromRdfType = Maybe.empty();
|
|
82
|
-
toRdfTypes = [];
|
|
83
|
-
}
|
|
84
|
-
if (nodeKinds.has("Literal")) {
|
|
85
|
-
return Left(new Error(`${nodeShape} should not have a nodeKind "Literal"`));
|
|
55
|
+
if (nodeShape.$identifier.termType !== "NamedNode") {
|
|
56
|
+
return Either.of(Maybe.empty());
|
|
57
|
+
}
|
|
58
|
+
return Eithers.chain9(Either.sequence(nodeShape.ancestorClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))), Either.sequence(nodeShape.childClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))), Either.sequence(nodeShape.descendantClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))), Either.sequence(nodeShape.parentClassIris.map((nodeShapeIdentifier) => this.shapesGraph.nodeShape(nodeShapeIdentifier))), nodeShapeIdentifierMintingStrategy.call(this, nodeShape), shapeNodeKinds.call(this, nodeShape, { defaultNodeShapeNodeKinds }), Either.sequence(nodeShape.properties.map((propertyShapeIdentifier) => this.shapesGraph.propertyShape(propertyShapeIdentifier))), nodeShapeTsFeatures.call(this, nodeShape), nodeShape.tsObjectDeclarationType.isJust()
|
|
59
|
+
? Either.of(nodeShape.tsObjectDeclarationType.map(TsObjectDeclarationType.fromIri))
|
|
60
|
+
: shapeOntology
|
|
61
|
+
.call(this, nodeShape)
|
|
62
|
+
.map((ontology) => ontology.chain((ontology) => ontology.tsObjectDeclarationType.map(TsObjectDeclarationType.fromIri)))).chain(([ancestorNodeShapes, childNodeShapes, descendantNodeShapes, parentNodeShapes, identifierMintingStrategy, nodeKinds, propertyShapes, tsFeatures, tsObjectDeclarationType,]) => {
|
|
63
|
+
const abstract = nodeShape.abstract.orDefault(false);
|
|
64
|
+
let fromRdfType;
|
|
65
|
+
let toRdfTypes;
|
|
66
|
+
if (!abstract) {
|
|
67
|
+
fromRdfType = nodeShape.fromRdfType.alt(nodeShape.rdfType);
|
|
68
|
+
if (nodeShape.isClass &&
|
|
69
|
+
nodeShape.$identifier.termType === "NamedNode") {
|
|
70
|
+
fromRdfType = fromRdfType.alt(Maybe.of(nodeShape.$identifier));
|
|
86
71
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
label: Maybe.empty(),
|
|
91
|
-
name: Maybe.empty(),
|
|
92
|
-
shapeIdentifier: nodeShape.identifier,
|
|
93
|
-
};
|
|
94
|
-
if (nodeKinds.size === 2) {
|
|
95
|
-
invariant(nodeShape.identifierIn.length === 0);
|
|
96
|
-
identifierType = new ast.IdentifierType(identifierTypeProperties);
|
|
72
|
+
toRdfTypes = nodeShape.toRdfTypes.concat();
|
|
73
|
+
if (toRdfTypes.length === 0) {
|
|
74
|
+
toRdfTypes.push(...nodeShape.rdfType.toList());
|
|
97
75
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
identifierType = new ast.BlankNodeType(identifierTypeProperties);
|
|
103
|
-
break;
|
|
104
|
-
case "IRI":
|
|
105
|
-
identifierType = new ast.IriType({
|
|
106
|
-
...identifierTypeProperties,
|
|
107
|
-
hasValues: [],
|
|
108
|
-
in_: nodeShape.identifierIn,
|
|
109
|
-
});
|
|
110
|
-
break;
|
|
111
|
-
case "Literal":
|
|
112
|
-
throw new Error("should never happen");
|
|
76
|
+
// Ensure toRdfTypes has fromRdfType
|
|
77
|
+
fromRdfType.ifJust((fromRdfType) => {
|
|
78
|
+
if (!toRdfTypes.some((toRdfType) => toRdfType.equals(fromRdfType))) {
|
|
79
|
+
toRdfTypes.push(fromRdfType);
|
|
113
80
|
}
|
|
114
|
-
}
|
|
115
|
-
invariant(identifierType);
|
|
116
|
-
// Put a placeholder in the cache to deal with cyclic references
|
|
117
|
-
// Remove the placeholder if the transformation fails.
|
|
118
|
-
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
119
|
-
// we'll return this placeholder.
|
|
120
|
-
const objectType = new ast.ObjectType({
|
|
121
|
-
abstract,
|
|
122
|
-
comment: nodeShape.comment,
|
|
123
|
-
extern: nodeShape.extern.orDefault(false),
|
|
124
|
-
fromRdfType,
|
|
125
|
-
label: nodeShape.label,
|
|
126
|
-
identifierType,
|
|
127
|
-
identifierMintingStrategy,
|
|
128
|
-
name: shapeAstTypeName(nodeShape),
|
|
129
|
-
shapeIdentifier: nodeShape.identifier,
|
|
130
|
-
synthetic: false,
|
|
131
|
-
toRdfTypes,
|
|
132
|
-
tsFeatures,
|
|
133
|
-
tsImports: nodeShape.tsImports,
|
|
134
|
-
tsObjectDeclarationType: tsObjectDeclarationType.orDefault("class"),
|
|
135
81
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
fromRdfType = Maybe.empty();
|
|
85
|
+
toRdfTypes = [];
|
|
86
|
+
}
|
|
87
|
+
if (nodeKinds.has("Literal")) {
|
|
88
|
+
return Left(new Error(`${nodeShape} should not have a nodeKind "Literal"`));
|
|
89
|
+
}
|
|
90
|
+
let identifierType;
|
|
91
|
+
const identifierTypeProperties = {
|
|
92
|
+
comment: Maybe.empty(),
|
|
93
|
+
label: Maybe.empty(),
|
|
94
|
+
name: Maybe.empty(),
|
|
95
|
+
shapeIdentifier: nodeShape.$identifier,
|
|
96
|
+
};
|
|
97
|
+
if (nodeKinds.size === 2) {
|
|
98
|
+
invariant(nodeShape.in_.isNothing());
|
|
99
|
+
identifierType = new ast.IdentifierType(identifierTypeProperties);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
switch ([...nodeKinds][0]) {
|
|
103
|
+
case "BlankNode":
|
|
104
|
+
invariant(nodeShape.in_.isNothing());
|
|
105
|
+
identifierType = new ast.BlankNodeType(identifierTypeProperties);
|
|
106
|
+
break;
|
|
107
|
+
case "IRI":
|
|
108
|
+
identifierType = new ast.IriType({
|
|
109
|
+
...identifierTypeProperties,
|
|
110
|
+
hasValues: [],
|
|
111
|
+
in_: nodeShape.in_
|
|
112
|
+
.orDefault([])
|
|
113
|
+
.filter((_) => _.termType === "NamedNode"),
|
|
162
114
|
});
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
throw new Error("should never happen");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
invariant(identifierType);
|
|
121
|
+
// Put a placeholder in the cache to deal with cyclic references
|
|
122
|
+
// Remove the placeholder if the transformation fails.
|
|
123
|
+
// If this node shape's properties (directly or indirectly) refer to the node shape itself,
|
|
124
|
+
// we'll return this placeholder.
|
|
125
|
+
const objectType = new ast.ObjectType({
|
|
126
|
+
abstract,
|
|
127
|
+
comment: nodeShape.comment,
|
|
128
|
+
extern: nodeShape.extern.orDefault(false),
|
|
129
|
+
fromRdfType,
|
|
130
|
+
label: nodeShape.label,
|
|
131
|
+
identifierType,
|
|
132
|
+
identifierMintingStrategy,
|
|
133
|
+
name: shapeAstTypeName(nodeShape),
|
|
134
|
+
shapeIdentifier: nodeShape.$identifier,
|
|
135
|
+
synthetic: false,
|
|
136
|
+
toRdfTypes,
|
|
137
|
+
tsFeatures,
|
|
138
|
+
tsImports: nodeShape.tsImports,
|
|
139
|
+
tsObjectDeclarationType: tsObjectDeclarationType.orDefault("class"),
|
|
140
|
+
});
|
|
141
|
+
this.cachedAstTypesByShapeIdentifier.set(nodeShape.$identifier, objectType);
|
|
142
|
+
return (() => {
|
|
143
|
+
// Populate ancestor and descendant object types
|
|
144
|
+
const relatedObjectTypes = (relatedNodeShapes) => {
|
|
145
|
+
return relatedNodeShapes
|
|
146
|
+
.flatMap((relatedNodeShape) => transformShapeToAstType
|
|
147
|
+
.call(this, relatedNodeShape, new ShapeStack())
|
|
148
|
+
.toMaybe()
|
|
149
|
+
.toList())
|
|
150
|
+
.filter((astType) => astType.kind === "ObjectType");
|
|
151
|
+
};
|
|
152
|
+
objectType.addAncestorObjectTypes(...relatedObjectTypes(ancestorNodeShapes));
|
|
153
|
+
objectType.addChildObjectTypes(...relatedObjectTypes(childNodeShapes));
|
|
154
|
+
objectType.addDescendantObjectTypes(...relatedObjectTypes(descendantNodeShapes));
|
|
155
|
+
objectType.addParentObjectTypes(...relatedObjectTypes(parentNodeShapes));
|
|
156
|
+
// Populate properties
|
|
157
|
+
for (const propertyShape of propertyShapes) {
|
|
158
|
+
const propertyEither = transformPropertyShapeToAstObjectTypeProperty.call(this, {
|
|
159
|
+
objectType,
|
|
160
|
+
propertyShape,
|
|
161
|
+
});
|
|
162
|
+
if (propertyEither.isLeft()) {
|
|
163
|
+
return propertyEither;
|
|
163
164
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
objectType.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
165
|
+
propertyEither.ifRight((property) => {
|
|
166
|
+
objectType.addProperties(property);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (!objectType.abstract &&
|
|
170
|
+
!objectType.extern &&
|
|
171
|
+
objectType.fromRdfType.isNothing() &&
|
|
172
|
+
!objectType.properties.some(isObjectTypePropertyRequired)) {
|
|
173
|
+
return Left(new Error(`${nodeShape} has no required properties and no implicitly required rdf:type`));
|
|
174
|
+
}
|
|
175
|
+
objectType.sortProperties();
|
|
176
|
+
return Either.of(Maybe.of(objectType));
|
|
177
|
+
})().ifLeft(() => {
|
|
178
|
+
this.cachedAstTypesByShapeIdentifier.delete(nodeShape.$identifier);
|
|
175
179
|
});
|
|
176
180
|
});
|
|
177
181
|
}
|
|
@@ -8,14 +8,14 @@ import { shapeNodeKinds } from "./shapeNodeKinds.js";
|
|
|
8
8
|
export function transformShapeToAstTermType(shape, shapeStack) {
|
|
9
9
|
shapeStack.push(shape);
|
|
10
10
|
try {
|
|
11
|
-
return shapeNodeKinds(shape).chain((nodeKinds) => {
|
|
11
|
+
return shapeNodeKinds.call(this, shape).chain((nodeKinds) => {
|
|
12
12
|
const hasValues = shapeStack.constraints.hasValues;
|
|
13
13
|
const in_ = shapeStack.constraints.in_;
|
|
14
14
|
const astAbstractTypeProperties = {
|
|
15
15
|
comment: Maybe.empty(),
|
|
16
16
|
name: Maybe.empty(),
|
|
17
17
|
label: Maybe.empty(),
|
|
18
|
-
shapeIdentifier: shape
|
|
18
|
+
shapeIdentifier: shape.$identifier,
|
|
19
19
|
};
|
|
20
20
|
let termType;
|
|
21
21
|
if (nodeKinds.size === 1) {
|
|
@@ -35,14 +35,16 @@ export function transformShapeToAstTermType(shape, shapeStack) {
|
|
|
35
35
|
case "Literal":
|
|
36
36
|
termType = new ast.LiteralType({
|
|
37
37
|
...astAbstractTypeProperties,
|
|
38
|
-
datatype: shape.
|
|
38
|
+
datatype: shape.datatype,
|
|
39
39
|
hasValues: hasValues.filter((_) => _.termType === "Literal"),
|
|
40
40
|
in_: in_.filter((_) => _.termType === "Literal"),
|
|
41
|
-
languageIn:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
languageIn: shape.languageIn
|
|
42
|
+
.map((languageIn) => [...new Set(languageIn)])
|
|
43
|
+
.orDefault([]),
|
|
44
|
+
maxExclusive: shape.maxExclusive,
|
|
45
|
+
maxInclusive: shape.maxInclusive,
|
|
46
|
+
minExclusive: shape.minExclusive,
|
|
47
|
+
minInclusive: shape.minInclusive,
|
|
46
48
|
});
|
|
47
49
|
break;
|
|
48
50
|
}
|
|
@@ -13,7 +13,7 @@ const tryTransformShapeToAstTypeMethods = [
|
|
|
13
13
|
* not the other transformShapeToAst*Type functions directly.
|
|
14
14
|
*/
|
|
15
15
|
export function transformShapeToAstType(shape, shapeStack) {
|
|
16
|
-
const astType = this.cachedAstTypesByShapeIdentifier.get(shape
|
|
16
|
+
const astType = this.cachedAstTypesByShapeIdentifier.get(shape.$identifier);
|
|
17
17
|
if (astType) {
|
|
18
18
|
return Either.of(astType);
|
|
19
19
|
}
|
|
@@ -28,14 +28,14 @@ export function transformShapeToAstType(shape, shapeStack) {
|
|
|
28
28
|
}
|
|
29
29
|
const astType = either.unsafeCoerce().extract();
|
|
30
30
|
if (astType) {
|
|
31
|
-
this.cachedAstTypesByShapeIdentifier.set(shape
|
|
31
|
+
this.cachedAstTypesByShapeIdentifier.set(shape.$identifier, astType);
|
|
32
32
|
return Either.of(astType);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
return transformShapeToAstTermType
|
|
36
36
|
.call(this, shape, shapeStack)
|
|
37
37
|
.ifRight((astType) => {
|
|
38
|
-
this.cachedAstTypesByShapeIdentifier.set(shape
|
|
38
|
+
this.cachedAstTypesByShapeIdentifier.set(shape.$identifier, astType);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
//# sourceMappingURL=transformShapeToAstType.js.map
|
package/dist/ast/ObjectType.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ import type { NodeKind } from "@shaclmate/shacl-ast";
|
|
|
3
3
|
import type { Maybe } from "purify-ts";
|
|
4
4
|
import { PropertyPath } from "rdfjs-resource";
|
|
5
5
|
import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
|
|
6
|
-
import type { PropertyVisibility } from "../enums/PropertyVisibility.js";
|
|
7
6
|
import type { TsFeature } from "../enums/TsFeature.js";
|
|
8
7
|
import type { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
|
|
8
|
+
import type { Visibility } from "../enums/Visibility.js";
|
|
9
9
|
import { AbstractType } from "./AbstractType.js";
|
|
10
10
|
import type { BlankNodeType } from "./BlankNodeType.js";
|
|
11
11
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
@@ -146,7 +146,7 @@ export declare namespace ObjectType {
|
|
|
146
146
|
/**
|
|
147
147
|
* Visibility: private, protected, public.
|
|
148
148
|
*/
|
|
149
|
-
readonly visibility:
|
|
149
|
+
readonly visibility: Visibility;
|
|
150
150
|
constructor({ comment, description, label, mutable, name, objectType, order, path, shapeIdentifier, type, visibility, }: {
|
|
151
151
|
comment: Maybe<string>;
|
|
152
152
|
description: Maybe<string>;
|
|
@@ -158,7 +158,7 @@ export declare namespace ObjectType {
|
|
|
158
158
|
path: PropertyPath;
|
|
159
159
|
shapeIdentifier: BlankNode | NamedNode;
|
|
160
160
|
type: Type;
|
|
161
|
-
visibility:
|
|
161
|
+
visibility: Visibility;
|
|
162
162
|
});
|
|
163
163
|
equals(other: Property): boolean;
|
|
164
164
|
/**
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
1
2
|
/**
|
|
2
3
|
* TypeScript enum corresponding to shaclmate:identifierMintingStrategy, for simpler manipulation.
|
|
3
4
|
*/
|
|
4
5
|
export type IdentifierMintingStrategy = "blankNode" | "sha256" | "uuidv4";
|
|
6
|
+
export declare namespace IdentifierMintingStrategy {
|
|
7
|
+
function fromIri(iri: NamedNode<"http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_BlankNode" | "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_SHA256" | "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_UUIDv4">): IdentifierMintingStrategy;
|
|
8
|
+
}
|
|
5
9
|
//# sourceMappingURL=IdentifierMintingStrategy.d.ts.map
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var IdentifierMintingStrategy;
|
|
2
|
+
(function (IdentifierMintingStrategy) {
|
|
3
|
+
function fromIri(iri) {
|
|
4
|
+
switch (iri.value) {
|
|
5
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_BlankNode":
|
|
6
|
+
return "blankNode";
|
|
7
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_SHA256":
|
|
8
|
+
return "sha256";
|
|
9
|
+
case "http://purl.org/shaclmate/ontology#_IdentifierMintingStrategy_UUIDv4":
|
|
10
|
+
return "uuidv4";
|
|
11
|
+
default:
|
|
12
|
+
iri.value;
|
|
13
|
+
throw new RangeError(iri.value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
IdentifierMintingStrategy.fromIri = fromIri;
|
|
17
|
+
})(IdentifierMintingStrategy || (IdentifierMintingStrategy = {}));
|
|
2
18
|
//# sourceMappingURL=IdentifierMintingStrategy.js.map
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
1
2
|
/**
|
|
2
3
|
* TypeScript enum corresponding to shaclmate:tsObjectDeclarationType, for simpler manipulation.
|
|
3
4
|
*/
|
|
4
5
|
export type TsObjectDeclarationType = "class" | "interface";
|
|
6
|
+
export declare namespace TsObjectDeclarationType {
|
|
7
|
+
function fromIri(iri: NamedNode<"http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Class" | "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Interface">): TsObjectDeclarationType;
|
|
8
|
+
}
|
|
5
9
|
//# sourceMappingURL=TsObjectDeclarationType.d.ts.map
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var TsObjectDeclarationType;
|
|
2
|
+
(function (TsObjectDeclarationType) {
|
|
3
|
+
function fromIri(iri) {
|
|
4
|
+
switch (iri.value) {
|
|
5
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Class":
|
|
6
|
+
return "class";
|
|
7
|
+
case "http://purl.org/shaclmate/ontology#_TsObjectDeclarationType_Interface":
|
|
8
|
+
return "interface";
|
|
9
|
+
default:
|
|
10
|
+
iri.value;
|
|
11
|
+
throw new RangeError(iri.value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
TsObjectDeclarationType.fromIri = fromIri;
|
|
15
|
+
})(TsObjectDeclarationType || (TsObjectDeclarationType = {}));
|
|
2
16
|
//# sourceMappingURL=TsObjectDeclarationType.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
+
export type Visibility = "private" | "protected" | "public";
|
|
3
|
+
export declare namespace Visibility {
|
|
4
|
+
function fromIri(iri: NamedNode<"http://purl.org/shaclmate/ontology#_Visibility_Private" | "http://purl.org/shaclmate/ontology#_Visibility_Protected" | "http://purl.org/shaclmate/ontology#_Visibility_Public">): Visibility;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=Visibility.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export var Visibility;
|
|
2
|
+
(function (Visibility) {
|
|
3
|
+
function fromIri(iri) {
|
|
4
|
+
switch (iri.value) {
|
|
5
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Private":
|
|
6
|
+
return "private";
|
|
7
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Protected":
|
|
8
|
+
return "protected";
|
|
9
|
+
case "http://purl.org/shaclmate/ontology#_Visibility_Public":
|
|
10
|
+
return "public";
|
|
11
|
+
default:
|
|
12
|
+
iri.value;
|
|
13
|
+
throw new RangeError(iri.value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
Visibility.fromIri = fromIri;
|
|
17
|
+
})(Visibility || (Visibility = {}));
|
|
18
|
+
//# sourceMappingURL=Visibility.js.map
|
|
@@ -196,7 +196,10 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
196
196
|
schema = code `${schema}.nonempty().min(${this.minCount})`;
|
|
197
197
|
}
|
|
198
198
|
else {
|
|
199
|
-
schema = code `${schema}.
|
|
199
|
+
schema = code `${schema}.optional()`;
|
|
200
|
+
}
|
|
201
|
+
if (!this._mutable) {
|
|
202
|
+
schema = code `${schema}.readonly()`;
|
|
200
203
|
}
|
|
201
204
|
return schema;
|
|
202
205
|
}
|
|
@@ -296,9 +296,9 @@ ${joinCode(this.concreteMembers.map(({ jsonTypeCheck, type, unwrap, wrap }) => c
|
|
|
296
296
|
return code `${imports.z}.discriminatedUnion("${this.discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
297
297
|
includeDiscriminantProperty: true,
|
|
298
298
|
context: "type",
|
|
299
|
-
})), { on: "," })}])`;
|
|
299
|
+
})), { on: "," })}]).readonly()`;
|
|
300
300
|
case "typeof":
|
|
301
|
-
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}])`;
|
|
301
|
+
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
302
302
|
default:
|
|
303
303
|
throw this.discriminant;
|
|
304
304
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Maybe } from "purify-ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Visibility } from "../../../enums/Visibility.js";
|
|
3
3
|
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
4
4
|
import type { Type } from "../Type.js";
|
|
5
5
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
@@ -74,12 +74,12 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
74
74
|
/**
|
|
75
75
|
* Property visibility: private, protected, public.
|
|
76
76
|
*/
|
|
77
|
-
readonly visibility:
|
|
77
|
+
readonly visibility: Visibility;
|
|
78
78
|
constructor({ name, namedObjectType, type, visibility, }: {
|
|
79
79
|
name: string;
|
|
80
80
|
namedObjectType: NamedObjectType;
|
|
81
81
|
type: TypeT;
|
|
82
|
-
visibility:
|
|
82
|
+
visibility: Visibility;
|
|
83
83
|
});
|
|
84
84
|
/**
|
|
85
85
|
* TypeScript object describing this type, for runtime use.
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js
CHANGED
|
@@ -6,25 +6,19 @@ export function NamedObjectType_jsonSchemaFunctionDeclaration() {
|
|
|
6
6
|
if (!this.features.has("json")) {
|
|
7
7
|
return Maybe.empty();
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
let properties = [];
|
|
10
10
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
11
|
-
|
|
11
|
+
properties.push(code `...${parentObjectType.jsonSchema({ context: "type" })}.shape`);
|
|
12
12
|
}
|
|
13
13
|
if (this.properties.length > 0) {
|
|
14
|
-
|
|
14
|
+
properties = properties.concat(this.properties
|
|
15
15
|
.flatMap((property) => property.jsonZchema.toList())
|
|
16
|
-
.map(({ key, schema }) => code `"${key}": ${schema}`)
|
|
16
|
+
.map(({ key, schema }) => code `"${key}": ${schema}`));
|
|
17
17
|
}
|
|
18
|
+
// ${this.properties.every((property) => !property.mutable) ? `.readonly()` : ""}
|
|
18
19
|
return Maybe.of(code `\
|
|
19
20
|
export function schema() {
|
|
20
|
-
return ${
|
|
21
|
-
? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
|
|
22
|
-
if (merged === null) {
|
|
23
|
-
return zodObjectSchema;
|
|
24
|
-
}
|
|
25
|
-
return code `${merged}.merge(${zodObjectSchema})`;
|
|
26
|
-
}, null)
|
|
27
|
-
: `${imports.z}.object()`} satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
|
|
21
|
+
return ${imports.z}.object({${joinCode(properties, { on: "," })}}) satisfies ${imports.z}.ZodType<${syntheticNamePrefix}Json>;
|
|
28
22
|
}`);
|
|
29
23
|
}
|
|
30
24
|
//# sourceMappingURL=NamedObjectType_jsonSchemaFunctionDeclaration.js.map
|
|
@@ -101,7 +101,7 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
101
101
|
}
|
|
102
102
|
get jsonSignature() {
|
|
103
103
|
const typeJsonType = this.type.jsonType();
|
|
104
|
-
return Maybe.of(code
|
|
104
|
+
return Maybe.of(code `${!this.mutable ? "readonly " : ""}${this.name}${typeJsonType.optional ? "?" : ""}: ${typeJsonType.requiredName}`);
|
|
105
105
|
}
|
|
106
106
|
get jsonZchema() {
|
|
107
107
|
let schema = this.type.jsonSchema({
|
|
@@ -1,49 +1,11 @@
|
|
|
1
1
|
import type { NamedNode } from "@rdfjs/types";
|
|
2
|
-
import { NodeShape as ShaclAstNodeShape } from "@shaclmate/shacl-ast";
|
|
3
|
-
import { Either, type Maybe } from "purify-ts";
|
|
4
|
-
import type { IdentifierMintingStrategy } from "../enums/IdentifierMintingStrategy.js";
|
|
5
|
-
import type { TsObjectDeclarationType } from "../enums/TsObjectDeclarationType.js";
|
|
6
2
|
import type * as generated from "./generated.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly isClass: boolean;
|
|
16
|
-
readonly isList: boolean;
|
|
17
|
-
readonly kind = "NodeShape";
|
|
18
|
-
constructor({ ancestorClassIris, childClassIris, descendantClassIris, generatedNodeShape, isClass, isList, parentClassIris, shapesGraph, }: {
|
|
19
|
-
ancestorClassIris: readonly NamedNode[];
|
|
20
|
-
generatedNodeShape: generated.NodeShape;
|
|
21
|
-
childClassIris: readonly NamedNode[];
|
|
22
|
-
descendantClassIris: readonly NamedNode[];
|
|
23
|
-
isClass: boolean;
|
|
24
|
-
isList: boolean;
|
|
25
|
-
parentClassIris: readonly NamedNode[];
|
|
26
|
-
shapesGraph: ShapesGraph;
|
|
27
|
-
});
|
|
28
|
-
get abstract(): Maybe<boolean>;
|
|
29
|
-
get ancestorNodeShapes(): Either<Error, readonly NodeShape[]>;
|
|
30
|
-
get childNodeShapes(): Either<Error, readonly NodeShape[]>;
|
|
31
|
-
get comment(): Maybe<string>;
|
|
32
|
-
get descendantNodeShapes(): Either<Error, readonly NodeShape[]>;
|
|
33
|
-
get discriminantValue(): Maybe<string>;
|
|
34
|
-
get extern(): Maybe<boolean>;
|
|
35
|
-
get fromRdfType(): Maybe<NamedNode>;
|
|
36
|
-
get identifierIn(): readonly NamedNode[];
|
|
37
|
-
get identifierMintingStrategy(): Maybe<IdentifierMintingStrategy>;
|
|
38
|
-
get label(): Maybe<string>;
|
|
39
|
-
get mutable(): Maybe<boolean>;
|
|
40
|
-
get parentNodeShapes(): Either<Error, readonly NodeShape[]>;
|
|
41
|
-
get rdfType(): Maybe<NamedNode>;
|
|
42
|
-
get shaclmateName(): Maybe<string>;
|
|
43
|
-
get toRdfTypes(): readonly NamedNode[];
|
|
44
|
-
get tsFeatureExcludes(): readonly NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
|
|
45
|
-
get tsFeatureIncludes(): readonly NamedNode<"http://purl.org/shaclmate/ontology#_TsFeatures_All" | "http://purl.org/shaclmate/ontology#_TsFeature_Create" | "http://purl.org/shaclmate/ontology#_TsFeatures_Default" | "http://purl.org/shaclmate/ontology#_TsFeature_Equals" | "http://purl.org/shaclmate/ontology#_TsFeature_Graphql" | "http://purl.org/shaclmate/ontology#_TsFeature_Hash" | "http://purl.org/shaclmate/ontology#_TsFeature_Json" | "http://purl.org/shaclmate/ontology#_TsFeatures_None" | "http://purl.org/shaclmate/ontology#_TsFeature_Rdf" | "http://purl.org/shaclmate/ontology#_TsFeature_Sparql">[];
|
|
46
|
-
get tsImports(): readonly string[];
|
|
47
|
-
get tsObjectDeclarationType(): Maybe<TsObjectDeclarationType>;
|
|
48
|
-
}
|
|
3
|
+
export type NodeShape = generated.NodeShape & Readonly<{
|
|
4
|
+
ancestorClassIris: readonly NamedNode[];
|
|
5
|
+
childClassIris: readonly NamedNode[];
|
|
6
|
+
descendantClassIris: readonly NamedNode[];
|
|
7
|
+
isClass: boolean;
|
|
8
|
+
isList: boolean;
|
|
9
|
+
parentClassIris: readonly NamedNode[];
|
|
10
|
+
}>;
|
|
49
11
|
//# sourceMappingURL=NodeShape.d.ts.map
|