@shaclmate/compiler 4.0.26 → 4.0.28
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/transformPropertyShapeToAstObjectTypeProperty.js +10 -10
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +3 -7
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +4 -4
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +7 -1
- package/dist/ast/SetType.d.ts +2 -2
- package/dist/ast/SetType.js +1 -1
- package/dist/generators/ts/AbstractCollectionType.d.ts +2 -2
- package/dist/generators/ts/AbstractCollectionType.js +8 -8
- package/dist/generators/ts/AbstractNumericType.d.ts +1 -0
- package/dist/generators/ts/BigIntType.d.ts +1 -0
- package/dist/generators/ts/BigIntType.js +11 -0
- package/dist/generators/ts/SetType.js +3 -3
- package/dist/generators/ts/TypeFactory.js +4 -4
- package/dist/input/generated.d.ts +136 -150
- package/dist/input/generated.js +194 -160
- package/package.json +2 -2
|
@@ -82,19 +82,19 @@ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
|
|
|
82
82
|
return transformShapeToAstType
|
|
83
83
|
.call(this, propertyShape, shapeStack)
|
|
84
84
|
.chain((propertyShapeAstType) => {
|
|
85
|
-
let maxCount = propertyShape.maxCount.orDefault(Number.MAX_SAFE_INTEGER);
|
|
86
|
-
let minCount = propertyShape.minCount.orDefault(
|
|
87
|
-
if (minCount <
|
|
88
|
-
minCount =
|
|
85
|
+
let maxCount = propertyShape.maxCount.orDefault(BigInt(Number.MAX_SAFE_INTEGER));
|
|
86
|
+
let minCount = propertyShape.minCount.orDefault(0n);
|
|
87
|
+
if (minCount < 0n) {
|
|
88
|
+
minCount = 0n;
|
|
89
89
|
}
|
|
90
90
|
if (propertyShape.hasValues.length > minCount) {
|
|
91
|
-
minCount = propertyShape.hasValues.length;
|
|
91
|
+
minCount = BigInt(propertyShape.hasValues.length);
|
|
92
92
|
}
|
|
93
93
|
if (maxCount < minCount) {
|
|
94
94
|
maxCount = minCount;
|
|
95
95
|
}
|
|
96
96
|
if (propertyShapeAstType.kind === "DefaultValueType") {
|
|
97
|
-
if (minCount >
|
|
97
|
+
if (minCount > 0n) {
|
|
98
98
|
return Left(new Error(`${propertyShape}: has sh:minCount > 0 and sh:defaultValue`));
|
|
99
99
|
}
|
|
100
100
|
if (maxCount > 1) {
|
|
@@ -102,10 +102,10 @@ function transformPropertyShapeToAstType(propertyShape, shapeStack) {
|
|
|
102
102
|
}
|
|
103
103
|
return Either.of(propertyShapeAstType);
|
|
104
104
|
}
|
|
105
|
-
if (minCount ===
|
|
105
|
+
if (minCount === 1n && maxCount === 1n) {
|
|
106
106
|
return Either.of(propertyShapeAstType);
|
|
107
107
|
}
|
|
108
|
-
if (minCount ===
|
|
108
|
+
if (minCount === 0n && maxCount === 1n) {
|
|
109
109
|
if (!ast.OptionType.isItemType(propertyShapeAstType)) {
|
|
110
110
|
return Left(new Error(`${propertyShape}: ${propertyShapeAstType} is not an OptionType item type`));
|
|
111
111
|
}
|
|
@@ -228,12 +228,12 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
|
|
|
228
228
|
...astAbstractTypeProperties,
|
|
229
229
|
partialType: new ast.SetType({
|
|
230
230
|
itemType: astPartialItemType,
|
|
231
|
-
minCount:
|
|
231
|
+
minCount: 0n,
|
|
232
232
|
mutable: false,
|
|
233
233
|
}),
|
|
234
234
|
resolveType: new ast.SetType({
|
|
235
235
|
itemType: astResolveItemType,
|
|
236
|
-
minCount:
|
|
236
|
+
minCount: 0n,
|
|
237
237
|
mutable: false,
|
|
238
238
|
}),
|
|
239
239
|
});
|
|
@@ -11,13 +11,13 @@ import { transformShapeToAstType } from "./transformShapeToAstType.js";
|
|
|
11
11
|
export function transformShapeToAstCompoundType(shape, shapeStack) {
|
|
12
12
|
shapeStack.push(shape);
|
|
13
13
|
try {
|
|
14
|
-
return Eithers.
|
|
14
|
+
return Eithers.chain3(Either.sequence(shape.and
|
|
15
15
|
.orDefault([])
|
|
16
|
-
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))),
|
|
16
|
+
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))), shape.$type === "NodeShape"
|
|
17
17
|
? nodeShapeTsFeatures.call(this, shape)
|
|
18
18
|
: Either.of(new Set()), Either.sequence(shape.xone
|
|
19
19
|
.orDefault([])
|
|
20
|
-
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier)))).chain(([andConstraintShapes,
|
|
20
|
+
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier)))).chain(([andConstraintShapes, tsFeatures, xoneConstraintShapes]) => {
|
|
21
21
|
let compoundTypeKind;
|
|
22
22
|
// Distinguish constraints that take arbitrary shapes from those that only take node shapes
|
|
23
23
|
// With the latter we'll do special transformations.
|
|
@@ -26,10 +26,6 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
|
|
|
26
26
|
memberShapes = andConstraintShapes;
|
|
27
27
|
compoundTypeKind = "IntersectionType";
|
|
28
28
|
}
|
|
29
|
-
else if (nodeConstraintShapes.length > 0) {
|
|
30
|
-
memberShapes = nodeConstraintShapes;
|
|
31
|
-
compoundTypeKind = "IntersectionType";
|
|
32
|
-
}
|
|
33
29
|
else if (xoneConstraintShapes.length > 0) {
|
|
34
30
|
memberShapes = xoneConstraintShapes;
|
|
35
31
|
compoundTypeKind = "UnionType";
|
|
@@ -92,15 +92,15 @@ export function transformShapeToAstListType(shape, shapeStack) {
|
|
|
92
92
|
if (!firstPropertyShape) {
|
|
93
93
|
return empty;
|
|
94
94
|
}
|
|
95
|
-
if (firstPropertyShape.maxCount.extract() !==
|
|
96
|
-
firstPropertyShape.minCount.extract() !==
|
|
95
|
+
if (firstPropertyShape.maxCount.extract() !== 1n ||
|
|
96
|
+
firstPropertyShape.minCount.extract() !== 1n) {
|
|
97
97
|
return Left(new Error(`${nodeShape} non-empty list shape rdf:first property shape does not have sh:maxCount=1 and/or sh:minCount=1`));
|
|
98
98
|
}
|
|
99
99
|
if (!restPropertyShape) {
|
|
100
100
|
return empty;
|
|
101
101
|
}
|
|
102
|
-
if (restPropertyShape.maxCount.extract() !==
|
|
103
|
-
restPropertyShape.minCount.extract() !==
|
|
102
|
+
if (restPropertyShape.maxCount.extract() !== 1n ||
|
|
103
|
+
restPropertyShape.minCount.extract() !== 1n) {
|
|
104
104
|
return Left(new Error(`${nodeShape} non-empty list shape rdf:rest property shape does not have sh:maxCount=1 and/or sh:minCount=1`));
|
|
105
105
|
}
|
|
106
106
|
return transformPropertyShapeToAstObjectTypeProperty
|
|
@@ -3,5 +3,5 @@ import * as ast from "../ast/index.js";
|
|
|
3
3
|
import type * as input from "../input/index.js";
|
|
4
4
|
import type { ShapesGraphToAstTransformer } from "../ShapesGraphToAstTransformer.js";
|
|
5
5
|
import { ShapeStack } from "./ShapeStack.js";
|
|
6
|
-
export declare function transformShapeToAstObjectType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<ast.
|
|
6
|
+
export declare function transformShapeToAstObjectType(this: ShapesGraphToAstTransformer, shape: input.Shape, shapeStack: ShapeStack): Either<Error, Maybe<ast.Type>>;
|
|
7
7
|
//# sourceMappingURL=transformShapeToAstObjectType.d.ts.map
|
|
@@ -17,7 +17,7 @@ function isObjectTypePropertyRequired(property) {
|
|
|
17
17
|
case "LazyObjectOptionType":
|
|
18
18
|
return false;
|
|
19
19
|
case "LazyObjectSetType":
|
|
20
|
-
return property.type.partialType.minCount >
|
|
20
|
+
return property.type.partialType.minCount > 0n;
|
|
21
21
|
case "OptionType":
|
|
22
22
|
return false;
|
|
23
23
|
case "SetType":
|
|
@@ -43,6 +43,12 @@ function isObjectTypePropertyRequired(property) {
|
|
|
43
43
|
export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
44
44
|
shapeStack.push(shape);
|
|
45
45
|
try {
|
|
46
|
+
if (shape.node.isJust()) {
|
|
47
|
+
return this.shapesGraph
|
|
48
|
+
.nodeShape(shape.node.unsafeCoerce())
|
|
49
|
+
.chain((nodeShape) => transformShapeToAstType.call(this, nodeShape, shapeStack))
|
|
50
|
+
.map(Maybe.of);
|
|
51
|
+
}
|
|
46
52
|
if (shape.$type !== "NodeShape") {
|
|
47
53
|
return Either.of(Maybe.empty());
|
|
48
54
|
}
|
package/dist/ast/SetType.d.ts
CHANGED
|
@@ -7,9 +7,9 @@ export declare class SetType<ItemTypeT extends SetType.ItemType = SetType.ItemTy
|
|
|
7
7
|
/**
|
|
8
8
|
* Minimum number of items in the set.
|
|
9
9
|
*/
|
|
10
|
-
readonly minCount:
|
|
10
|
+
readonly minCount: bigint;
|
|
11
11
|
constructor({ itemType, minCount, ...superParameters }: {
|
|
12
|
-
minCount:
|
|
12
|
+
minCount: bigint;
|
|
13
13
|
} & Pick<ConstructorParameters<typeof AbstractCollectionType<ItemTypeT>>[0], "itemType" | "mutable">);
|
|
14
14
|
equals(other: SetType<ItemTypeT>): boolean;
|
|
15
15
|
toJSON(): {
|
package/dist/ast/SetType.js
CHANGED
|
@@ -6,12 +6,12 @@ import { type Code } from "./ts-poet-wrapper.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractCollectionType.ItemType> extends AbstractContainerType<ItemTypeT> {
|
|
8
8
|
protected readonly _mutable: boolean;
|
|
9
|
-
protected readonly minCount:
|
|
9
|
+
protected readonly minCount: bigint;
|
|
10
10
|
readonly discriminantProperty: Maybe<AbstractContainerType.DiscriminantProperty>;
|
|
11
11
|
readonly graphqlArgs: AbstractContainerType<ItemTypeT>["graphqlArgs"];
|
|
12
12
|
readonly typeofs: NonEmptyList<"object">;
|
|
13
13
|
constructor({ minCount, mutable, ...superParameters }: {
|
|
14
|
-
minCount:
|
|
14
|
+
minCount: bigint;
|
|
15
15
|
mutable: boolean;
|
|
16
16
|
} & ConstructorParameters<typeof AbstractContainerType<ItemTypeT>>[0]);
|
|
17
17
|
get conversions(): readonly AbstractContainerType.Conversion[];
|
|
@@ -24,10 +24,10 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
24
24
|
constructor({ minCount, mutable, ...superParameters }) {
|
|
25
25
|
super(superParameters);
|
|
26
26
|
this.minCount = minCount;
|
|
27
|
-
invariant(this.minCount >=
|
|
27
|
+
invariant(this.minCount >= 0n);
|
|
28
28
|
this._mutable = mutable;
|
|
29
29
|
if (mutable) {
|
|
30
|
-
invariant(this.minCount ===
|
|
30
|
+
invariant(this.minCount === 0n);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
get conversions() {
|
|
@@ -54,7 +54,7 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
if (this.minCount ===
|
|
57
|
+
if (this.minCount === 0n) {
|
|
58
58
|
if (Object.keys(itemTypeConversionsByTypeof).length <= 1) {
|
|
59
59
|
// There were no additional conversions with different item typeof's, so we don't need to check .every or do .map
|
|
60
60
|
// Just check that the original value is an array with typeof "object". Array.isArray() doesn't narrow types for some reason.
|
|
@@ -135,7 +135,7 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
135
135
|
if (this._mutable) {
|
|
136
136
|
return code `(${this.itemType.name})[]`;
|
|
137
137
|
}
|
|
138
|
-
if (this.minCount ===
|
|
138
|
+
if (this.minCount === 0n) {
|
|
139
139
|
return code `readonly (${this.itemType.name})[]`;
|
|
140
140
|
}
|
|
141
141
|
return code `${imports.NonEmptyList}<${this.itemType.name}>`;
|
|
@@ -146,15 +146,15 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
146
146
|
get schemaObject() {
|
|
147
147
|
return {
|
|
148
148
|
...super.schemaObject,
|
|
149
|
-
minCount: this.minCount >
|
|
149
|
+
minCount: this.minCount > 0n ? Number(this.minCount) : undefined,
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
fromJsonExpression({ variables, }) {
|
|
153
153
|
let expression = variables.value;
|
|
154
|
-
if (!this._mutable && this.minCount >
|
|
154
|
+
if (!this._mutable && this.minCount > 0n) {
|
|
155
155
|
expression = code `${imports.NonEmptyList}.fromArray(${expression}).unsafeCoerce()`;
|
|
156
156
|
}
|
|
157
|
-
if (this.minCount ===
|
|
157
|
+
if (this.minCount === 0n) {
|
|
158
158
|
expression = code `(${expression} ?? [])`;
|
|
159
159
|
}
|
|
160
160
|
const valueVariable = code `item`;
|
|
@@ -186,7 +186,7 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
186
186
|
}
|
|
187
187
|
jsonSchema(parameters) {
|
|
188
188
|
let schema = code `${this.itemType.jsonSchema(parameters)}.array()`;
|
|
189
|
-
if (this.minCount >
|
|
189
|
+
if (this.minCount > 0n) {
|
|
190
190
|
schema = code `${schema}.nonempty().min(${this.minCount})`;
|
|
191
191
|
}
|
|
192
192
|
else {
|
|
@@ -26,6 +26,7 @@ export declare abstract class AbstractNumericType<ValueT extends bigint | number
|
|
|
26
26
|
protected abstract literalOf(value: ValueT): string;
|
|
27
27
|
}
|
|
28
28
|
export declare namespace AbstractNumericType {
|
|
29
|
+
type Conversion = AbstractPrimitiveType.Conversion;
|
|
29
30
|
const JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
30
31
|
type JsonType = AbstractPrimitiveType.JsonType;
|
|
31
32
|
}
|
|
@@ -5,6 +5,7 @@ export declare class BigIntType extends AbstractNumericType<bigint> {
|
|
|
5
5
|
readonly graphqlType: import("./AbstractType.js").AbstractType.GraphqlType;
|
|
6
6
|
readonly kind = "BigIntType";
|
|
7
7
|
readonly typeofs: NonEmptyList<"bigint">;
|
|
8
|
+
get conversions(): readonly AbstractNumericType.Conversion[];
|
|
8
9
|
fromJsonExpression({ variables, }: Parameters<AbstractNumericType<bigint>["fromJsonExpression"]>[0]): Code;
|
|
9
10
|
jsonSchema(_parameters: Parameters<AbstractNumericType<bigint>["jsonSchema"]>[0]): Code;
|
|
10
11
|
jsonType(): AbstractNumericType.JsonType;
|
|
@@ -13,6 +13,17 @@ export class BigIntType extends AbstractNumericType {
|
|
|
13
13
|
graphqlType = new AbstractNumericType.GraphqlType(code `${imports.GraphQLBigInt}`);
|
|
14
14
|
kind = "BigIntType";
|
|
15
15
|
typeofs = NonEmptyList(["bigint"]);
|
|
16
|
+
get conversions() {
|
|
17
|
+
if (this.in_.length > 0) {
|
|
18
|
+
return super.conversions;
|
|
19
|
+
}
|
|
20
|
+
return super.conversions.concat({
|
|
21
|
+
conversionExpression: (value) => code `BigInt(${value})`,
|
|
22
|
+
sourceTypeCheckExpression: (value) => code `typeof ${value} === "number"`,
|
|
23
|
+
sourceTypeName: "number",
|
|
24
|
+
sourceTypeof: "number",
|
|
25
|
+
});
|
|
26
|
+
}
|
|
16
27
|
fromJsonExpression({ variables, }) {
|
|
17
28
|
let expression = code `BigInt(${variables.value})`;
|
|
18
29
|
if (this.primitiveIn.length > 0) {
|
|
@@ -15,7 +15,7 @@ export class SetType extends AbstractCollectionType {
|
|
|
15
15
|
kind = "SetType";
|
|
16
16
|
get conversions() {
|
|
17
17
|
const conversions = [];
|
|
18
|
-
if (this.minCount ===
|
|
18
|
+
if (this.minCount === 0n) {
|
|
19
19
|
conversions.push({
|
|
20
20
|
conversionExpression: () => code `[]`,
|
|
21
21
|
sourceTypeCheckExpression: (value) => code `${value} === undefined`,
|
|
@@ -36,7 +36,7 @@ export class SetType extends AbstractCollectionType {
|
|
|
36
36
|
const chain = [
|
|
37
37
|
this.itemType.fromRdfResourceValuesExpression(parameters),
|
|
38
38
|
];
|
|
39
|
-
if (this.minCount ===
|
|
39
|
+
if (this.minCount === 0n || this._mutable) {
|
|
40
40
|
chain.push(code `map(values => values.toArray()${this._mutable ? ".concat()" : ""})`);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
@@ -47,7 +47,7 @@ export class SetType extends AbstractCollectionType {
|
|
|
47
47
|
}
|
|
48
48
|
jsonType() {
|
|
49
49
|
const name = code `${!this.mutable ? "readonly " : ""}(${this.itemType.jsonType().name})[]`;
|
|
50
|
-
if (this.minCount ===
|
|
50
|
+
if (this.minCount === 0n) {
|
|
51
51
|
return new AbstractCollectionType.JsonType(name, { optional: true });
|
|
52
52
|
}
|
|
53
53
|
return new AbstractCollectionType.JsonType(name);
|
|
@@ -281,7 +281,7 @@ export class TypeFactory {
|
|
|
281
281
|
itemType,
|
|
282
282
|
label: astType.label,
|
|
283
283
|
logger: this.logger,
|
|
284
|
-
minCount:
|
|
284
|
+
minCount: 0n,
|
|
285
285
|
mutable: astType.mutable,
|
|
286
286
|
toRdfTypes: astType.toRdfTypes,
|
|
287
287
|
});
|
|
@@ -394,9 +394,9 @@ export class TypeFactory {
|
|
|
394
394
|
else if (datatypes.size > 0) {
|
|
395
395
|
this.logger.warn("literal type has multiple datatypes: %s", JSON.stringify([...datatypes].map((datatype) => datatype.value)));
|
|
396
396
|
}
|
|
397
|
-
else {
|
|
398
|
-
|
|
399
|
-
}
|
|
397
|
+
// } else {
|
|
398
|
+
// // this.logger.debug("literal type has no datatypes");
|
|
399
|
+
// }
|
|
400
400
|
return new LiteralType({
|
|
401
401
|
comment: astType.comment,
|
|
402
402
|
hasValues: astType.hasValues,
|