@shaclmate/compiler 4.0.40 → 4.0.41
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.d.ts +0 -8
- package/dist/ShapesGraphToAstTransformer.js +5 -85
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +128 -160
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.d.ts +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +0 -16
- package/dist/ast/AbstractCompoundType.d.ts +2 -1
- package/dist/ast/AbstractCompoundType.js +1 -1
- package/dist/ast/AbstractLazyObjectType.d.ts +0 -2
- package/dist/ast/Ast.d.ts +1 -3
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +1 -1
- package/dist/ast/ObjectType.d.ts +0 -12
- package/dist/ast/ObjectType.js +0 -78
- package/dist/generators/AstJsonGenerator.js +7 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +59 -56
- package/dist/generators/ts/AbstractCollectionType.d.ts +4 -11
- package/dist/generators/ts/AbstractCollectionType.js +3 -62
- package/dist/generators/ts/AbstractContainerType.d.ts +0 -1
- package/dist/generators/ts/AbstractContainerType.js +1 -4
- package/dist/generators/ts/AbstractDateType.d.ts +4 -1
- package/dist/generators/ts/AbstractDateType.js +6 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -0
- package/dist/generators/ts/AbstractIdentifierType.js +3 -0
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +12 -1
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -0
- package/dist/generators/ts/AbstractNumericType.js +7 -7
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +1 -0
- package/dist/generators/ts/AbstractTermType.d.ts +1 -2
- package/dist/generators/ts/AbstractTermType.js +1 -3
- package/dist/generators/ts/AbstractType.d.ts +46 -16
- package/dist/generators/ts/AbstractType.js +31 -16
- package/dist/generators/ts/BigDecimalType.d.ts +4 -0
- package/dist/generators/ts/BigDecimalType.js +4 -1
- package/dist/generators/ts/BigIntType.d.ts +3 -1
- package/dist/generators/ts/BigIntType.js +1 -1
- package/dist/generators/ts/BlankNodeType.d.ts +1 -1
- package/dist/generators/ts/BlankNodeType.js +3 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +39 -1
- package/dist/generators/ts/DefaultValueType.js +6 -3
- package/dist/generators/ts/FloatType.d.ts +3 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/GraphqlSchema.js +2 -2
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +7 -5
- package/dist/generators/ts/IntType.d.ts +3 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.js +4 -2
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -0
- package/dist/generators/ts/LazyObjectOptionType.js +8 -4
- package/dist/generators/ts/LazyObjectSetType.js +9 -3
- package/dist/generators/ts/LazyObjectType.js +5 -2
- package/dist/generators/ts/ListType.d.ts +10 -1
- package/dist/generators/ts/ListType.js +45 -8
- package/dist/generators/ts/LiteralType.d.ts +4 -0
- package/dist/generators/ts/LiteralType.js +6 -3
- package/dist/generators/ts/ObjectType.d.ts +8 -22
- package/dist/generators/ts/ObjectType.js +6 -74
- package/dist/generators/ts/ObjectUnionType.js +2 -2
- package/dist/generators/ts/OptionType.d.ts +5 -1
- package/dist/generators/ts/OptionType.js +10 -5
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +1 -4
- package/dist/generators/ts/SetType.d.ts +16 -1
- package/dist/generators/ts/SetType.js +80 -2
- package/dist/generators/ts/Snippets.d.ts +3 -1
- package/dist/generators/ts/Snippets.js +18 -4
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +5 -1
- package/dist/generators/ts/TermType.d.ts +4 -0
- package/dist/generators/ts/TermType.js +3 -0
- package/dist/generators/ts/TsGenerator.d.ts +1 -1
- package/dist/generators/ts/TsGenerator.js +53 -28
- package/dist/generators/ts/TypeFactory.js +12 -25
- package/dist/generators/ts/UnionType.d.ts +3 -6
- package/dist/generators/ts/UnionType.js +42 -55
- package/dist/generators/ts/ZodGenerator.d.ts +1 -1
- package/dist/generators/ts/ZodGenerator.js +19 -12
- package/dist/generators/ts/_ObjectType/AbstractProperty.d.ts +6 -3
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.d.ts +8 -12
- package/dist/generators/ts/_ObjectType/DiscriminantProperty.js +18 -35
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +5 -5
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.js +9 -30
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.js +0 -3
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js +3 -22
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.js +4 -29
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js +10 -39
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionDeclarations.js +25 -29
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.js +1 -5
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.js +11 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +3 -9
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.js +1 -8
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js +1 -3
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.js +2 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionDeclaration.js +10 -31
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/ObjectType_toStringFunctionDeclarations.js +2 -9
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +6 -6
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +0 -11
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArraySet.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToList.js +7 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToScalarSet.js +15 -0
- package/dist/input/generated.d.ts +756 -115
- package/dist/input/generated.js +634 -126
- package/package.json +2 -4
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +0 -8
package/dist/ast/ObjectType.js
CHANGED
|
@@ -5,38 +5,12 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { PropertyPath } from "@rdfx/resource";
|
|
8
|
-
import { NTriplesIdentifier } from "@rdfx/string";
|
|
9
|
-
import genericToposort from "toposort";
|
|
10
8
|
import { invariant } from "ts-invariant";
|
|
11
9
|
import { Memoize } from "typescript-memoize";
|
|
12
10
|
import { AbstractType } from "./AbstractType.js";
|
|
13
11
|
import { arrayEquals } from "./equals.js";
|
|
14
12
|
import { Type } from "./Type.js";
|
|
15
13
|
export class ObjectType extends AbstractType {
|
|
16
|
-
/**
|
|
17
|
-
* Ancestor (parents, their parents, ad nauseum) ObjectTypes of this ObjectType.
|
|
18
|
-
*
|
|
19
|
-
* Mutable to support cycle-handling logic in the compiler.
|
|
20
|
-
*/
|
|
21
|
-
#ancestorObjectTypes = [];
|
|
22
|
-
/**
|
|
23
|
-
* Immediate child ObjectTypes of this ObjectType.
|
|
24
|
-
*
|
|
25
|
-
* Mutable to support cycle-handling logic in the compiler.
|
|
26
|
-
*/
|
|
27
|
-
#childObjectTypes = [];
|
|
28
|
-
/**
|
|
29
|
-
* Descendant (children, their children, ad nauseum) ObjectTypes of this ObjectType.
|
|
30
|
-
*
|
|
31
|
-
* Mutable to support cycle-handling logic in the compiler.
|
|
32
|
-
*/
|
|
33
|
-
#descendantObjectTypes = [];
|
|
34
|
-
/**
|
|
35
|
-
* Immediate parent ObjectTypes of this Object types.
|
|
36
|
-
*
|
|
37
|
-
* Mutable to support cycle-handling logic in the compiler.
|
|
38
|
-
*/
|
|
39
|
-
#parentObjectTypes = [];
|
|
40
14
|
/**
|
|
41
15
|
* Properties of this ObjectType.
|
|
42
16
|
*
|
|
@@ -94,36 +68,12 @@ export class ObjectType extends AbstractType {
|
|
|
94
68
|
this.toRdfTypes = toRdfTypes;
|
|
95
69
|
this.tsImports = tsImports;
|
|
96
70
|
}
|
|
97
|
-
get ancestorObjectTypes() {
|
|
98
|
-
return this.#ancestorObjectTypes;
|
|
99
|
-
}
|
|
100
|
-
get childObjectTypes() {
|
|
101
|
-
return this.#childObjectTypes;
|
|
102
|
-
}
|
|
103
|
-
get descendantObjectTypes() {
|
|
104
|
-
return this.#descendantObjectTypes;
|
|
105
|
-
}
|
|
106
|
-
get parentObjectTypes() {
|
|
107
|
-
return this.#parentObjectTypes;
|
|
108
|
-
}
|
|
109
71
|
get properties() {
|
|
110
72
|
return this.#properties;
|
|
111
73
|
}
|
|
112
74
|
get recursive() {
|
|
113
75
|
return this.properties.some((property) => property.recursive);
|
|
114
76
|
}
|
|
115
|
-
addAncestorObjectTypes(...ancestorObjectTypes) {
|
|
116
|
-
this.#ancestorObjectTypes.push(...ancestorObjectTypes);
|
|
117
|
-
}
|
|
118
|
-
addChildObjectTypes(...childObjectTypes) {
|
|
119
|
-
this.#childObjectTypes.push(...childObjectTypes);
|
|
120
|
-
}
|
|
121
|
-
addDescendantObjectTypes(...descendantObjectTypes) {
|
|
122
|
-
this.#descendantObjectTypes.push(...descendantObjectTypes);
|
|
123
|
-
}
|
|
124
|
-
addParentObjectTypes(...parentObjectTypes) {
|
|
125
|
-
this.#parentObjectTypes.push(...parentObjectTypes);
|
|
126
|
-
}
|
|
127
77
|
addProperties(...properties) {
|
|
128
78
|
this.#properties.push(...properties);
|
|
129
79
|
for (const property of properties) {
|
|
@@ -150,10 +100,6 @@ export class ObjectType extends AbstractType {
|
|
|
150
100
|
...super.toJSON(),
|
|
151
101
|
fromRdfType: this.fromRdfType.extract(),
|
|
152
102
|
identifierType: this.identifierType.toJSON(),
|
|
153
|
-
parentObjectTypes: this.parentObjectTypes.length > 0
|
|
154
|
-
? this.parentObjectTypes.map((parentObjectType) => parentObjectType.name.extract() ??
|
|
155
|
-
parentObjectType.shapeIdentifier)
|
|
156
|
-
: undefined,
|
|
157
103
|
synthetic: this.synthetic ? true : undefined,
|
|
158
104
|
toRdfTypes: this.toRdfTypes.length > 0 ? this.toRdfTypes : undefined,
|
|
159
105
|
};
|
|
@@ -362,28 +308,4 @@ const nodeKinds = new Set(["BlankNode", "IRI"]);
|
|
|
362
308
|
], Property.prototype, "recursive", null);
|
|
363
309
|
ObjectType.Property = Property;
|
|
364
310
|
})(ObjectType || (ObjectType = {}));
|
|
365
|
-
(function (ObjectType) {
|
|
366
|
-
function toposort(objectTypes) {
|
|
367
|
-
const objectTypesByShapeIdentifier = {};
|
|
368
|
-
const objectTypeGraphNodes = [];
|
|
369
|
-
const objectTypeGraphEdges = [];
|
|
370
|
-
for (const objectType of objectTypes) {
|
|
371
|
-
const objectTypeShapeIdentifier = NTriplesIdentifier.stringify(objectType.shapeIdentifier);
|
|
372
|
-
invariant(!objectTypesByShapeIdentifier[objectTypeShapeIdentifier]);
|
|
373
|
-
objectTypesByShapeIdentifier[objectTypeShapeIdentifier] = objectType;
|
|
374
|
-
objectTypeGraphNodes.push(objectTypeShapeIdentifier);
|
|
375
|
-
for (const parentAstObjectType of objectType.parentObjectTypes) {
|
|
376
|
-
objectTypeGraphEdges.push([
|
|
377
|
-
objectTypeShapeIdentifier,
|
|
378
|
-
NTriplesIdentifier.stringify(parentAstObjectType.shapeIdentifier),
|
|
379
|
-
]);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
return genericToposort
|
|
383
|
-
.array(objectTypeGraphNodes, objectTypeGraphEdges)
|
|
384
|
-
.map((objectTypeIdentifier) => objectTypesByShapeIdentifier[objectTypeIdentifier])
|
|
385
|
-
.reverse();
|
|
386
|
-
}
|
|
387
|
-
ObjectType.toposort = toposort;
|
|
388
|
-
})(ObjectType || (ObjectType = {}));
|
|
389
311
|
//# sourceMappingURL=ObjectType.js.map
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
export class AstJsonGenerator {
|
|
2
2
|
generate(ast) {
|
|
3
3
|
return JSON.stringify({
|
|
4
|
-
|
|
5
|
-
...
|
|
6
|
-
|
|
4
|
+
namedTypes: ast.namedTypes.map((namedType) => ({
|
|
5
|
+
...namedType.toJSON(),
|
|
6
|
+
...(namedType.kind === "Object"
|
|
7
|
+
? {
|
|
8
|
+
properties: namedType.properties.map((property) => property.toJSON()),
|
|
9
|
+
}
|
|
10
|
+
: {}),
|
|
7
11
|
})),
|
|
8
12
|
}, undefined, 2);
|
|
9
13
|
}
|
|
@@ -2,64 +2,67 @@ import { Maybe } from "purify-ts";
|
|
|
2
2
|
export function transformAstToLabeledPropertyGraph(ast) {
|
|
3
3
|
const nodes = [];
|
|
4
4
|
const relationships = [];
|
|
5
|
-
for (const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
5
|
+
for (const namedType of ast.namedTypes) {
|
|
6
|
+
if (namedType.kind === "Object") {
|
|
7
|
+
const namedObjectType = namedType;
|
|
8
|
+
const id = typeId(namedType);
|
|
9
|
+
const properties = {
|
|
10
|
+
name: { type: "string", value: typeName(namedType) },
|
|
11
|
+
};
|
|
12
|
+
for (const namedObjectTypeProperty of namedObjectType.properties) {
|
|
13
|
+
let itemType;
|
|
14
|
+
switch (namedObjectTypeProperty.type.kind) {
|
|
15
|
+
case "DefaultValue":
|
|
16
|
+
case "List":
|
|
17
|
+
case "Option":
|
|
18
|
+
case "Set":
|
|
19
|
+
itemType = namedObjectTypeProperty.type.itemType;
|
|
20
|
+
break;
|
|
21
|
+
case "LazyObject":
|
|
22
|
+
itemType = namedObjectTypeProperty.type.resolveType;
|
|
23
|
+
break;
|
|
24
|
+
case "LazyObjectOption":
|
|
25
|
+
case "LazyObjectSet":
|
|
26
|
+
itemType = namedObjectTypeProperty.type.resolveType.itemType;
|
|
27
|
+
break;
|
|
28
|
+
default:
|
|
29
|
+
itemType = namedObjectTypeProperty.type;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
switch (itemType.kind) {
|
|
33
|
+
case "Intersection":
|
|
34
|
+
case "Object":
|
|
35
|
+
case "Union":
|
|
36
|
+
if (itemType.name.isJust()) {
|
|
37
|
+
relationships.push({
|
|
38
|
+
id: namedObjectTypeProperty.shapeIdentifier.toString(),
|
|
39
|
+
label: Maybe.of(namedObjectTypeProperty.name),
|
|
40
|
+
properties: {},
|
|
41
|
+
sourceNodeId: id,
|
|
42
|
+
targetNodeId: typeId(itemType),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
properties[namedObjectTypeProperty.name] = {
|
|
48
|
+
type: "string",
|
|
49
|
+
value: namedObjectTypeProperty.toString(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
49
52
|
}
|
|
53
|
+
nodes.push({
|
|
54
|
+
id,
|
|
55
|
+
label: typeName(namedObjectType),
|
|
56
|
+
properties: properties,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else if (namedType.kind === "Union") {
|
|
60
|
+
nodes.push({
|
|
61
|
+
id: typeId(namedType),
|
|
62
|
+
label: typeName(namedType),
|
|
63
|
+
properties: {},
|
|
64
|
+
});
|
|
50
65
|
}
|
|
51
|
-
nodes.push({
|
|
52
|
-
id,
|
|
53
|
-
label: typeName(namedObjectType),
|
|
54
|
-
properties: properties,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
for (const namedUnionType of ast.namedUnionTypes) {
|
|
58
|
-
nodes.push({
|
|
59
|
-
id: typeId(namedUnionType),
|
|
60
|
-
label: typeName(namedUnionType),
|
|
61
|
-
properties: {},
|
|
62
|
-
});
|
|
63
66
|
}
|
|
64
67
|
return {
|
|
65
68
|
nodes,
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
2
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
3
|
-
import type { AbstractType } from "./AbstractType.js";
|
|
4
3
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
4
|
/**
|
|
6
5
|
* Abstract base class for ListType and SetType.
|
|
7
6
|
*/
|
|
8
7
|
export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractCollectionType.ItemType> extends AbstractContainerType<ItemTypeT> {
|
|
9
8
|
protected readonly _mutable: boolean;
|
|
10
|
-
protected readonly minCount: bigint;
|
|
11
9
|
readonly discriminantProperty: Maybe<AbstractContainerType.DiscriminantProperty>;
|
|
12
10
|
readonly graphqlArgs: AbstractContainerType<ItemTypeT>["graphqlArgs"];
|
|
13
|
-
|
|
14
|
-
constructor({ minCount, mutable, ...superParameters }: {
|
|
15
|
-
minCount: bigint;
|
|
11
|
+
constructor({ mutable, ...superParameters }: {
|
|
16
12
|
mutable: boolean;
|
|
17
13
|
} & ConstructorParameters<typeof AbstractContainerType<ItemTypeT>>[0]);
|
|
18
|
-
get conversionFunction(): Maybe<AbstractType.ConversionFunction>;
|
|
19
14
|
get equalsFunction(): Code;
|
|
20
15
|
get expression(): Code;
|
|
21
16
|
get filterFunction(): Code;
|
|
@@ -25,20 +20,18 @@ export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractC
|
|
|
25
20
|
get mutable(): boolean;
|
|
26
21
|
get schemaType(): Code;
|
|
27
22
|
get validationFunction(): Maybe<Code>;
|
|
28
|
-
protected get schemaInitializers(): readonly Code[];
|
|
29
|
-
fromJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["fromJsonExpression"]>[0]): Code;
|
|
30
23
|
graphqlResolveExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["graphqlResolveExpression"]>[0]): Code;
|
|
31
|
-
jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
|
|
32
24
|
jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
33
25
|
toJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toJsonExpression"]>[0]): Code;
|
|
34
26
|
}
|
|
35
27
|
export declare namespace AbstractCollectionType {
|
|
28
|
+
type ConversionFunction = AbstractContainerType.ConversionFunction;
|
|
36
29
|
type DiscriminantProperty = AbstractContainerType.DiscriminantProperty;
|
|
37
|
-
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
30
|
+
const GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
38
31
|
type GraphqlType = AbstractContainerType.GraphqlType;
|
|
39
32
|
const isItemType: typeof AbstractContainerType.isItemType;
|
|
40
33
|
type ItemType = AbstractContainerType.ItemType;
|
|
41
|
-
const JsonType: typeof AbstractType.JsonType;
|
|
34
|
+
const JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
42
35
|
type JsonType = AbstractContainerType.JsonType;
|
|
43
36
|
}
|
|
44
37
|
//# sourceMappingURL=AbstractCollectionType.d.ts.map
|
|
@@ -5,46 +5,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
|
-
import { invariant } from "ts-invariant";
|
|
9
8
|
import { Memoize } from "typescript-memoize";
|
|
10
9
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
11
|
-
import { code,
|
|
10
|
+
import { code, literalOf } from "./ts-poet-wrapper.js";
|
|
12
11
|
/**
|
|
13
12
|
* Abstract base class for ListType and SetType.
|
|
14
13
|
*/
|
|
15
14
|
export class AbstractCollectionType extends AbstractContainerType {
|
|
16
15
|
_mutable;
|
|
17
|
-
minCount;
|
|
18
16
|
discriminantProperty = Maybe.empty();
|
|
19
17
|
graphqlArgs = Maybe.empty();
|
|
20
|
-
|
|
21
|
-
constructor({ minCount, mutable, ...superParameters }) {
|
|
18
|
+
constructor({ mutable, ...superParameters }) {
|
|
22
19
|
super(superParameters);
|
|
23
|
-
this.minCount = minCount;
|
|
24
|
-
invariant(this.minCount >= 0n);
|
|
25
20
|
this._mutable = mutable;
|
|
26
|
-
if (mutable) {
|
|
27
|
-
invariant(this.minCount === 0n);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
get conversionFunction() {
|
|
31
|
-
const itemConversionFunction = this.itemType.conversionFunction.orDefault(this.itemConversionFunctionDefault);
|
|
32
|
-
const sourceTypes = [
|
|
33
|
-
{
|
|
34
|
-
expression: code `readonly (${joinCode(itemConversionFunction.sourceTypes.map((itemSourceType) => code `${itemSourceType.expression}`), { on: " | " })})[]`,
|
|
35
|
-
typeof: "object",
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
if (this.minCount === 0n) {
|
|
39
|
-
sourceTypes.push({
|
|
40
|
-
expression: code `undefined`,
|
|
41
|
-
typeof: "undefined",
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return Maybe.of({
|
|
45
|
-
code: code `${this.reusables.snippets.convertToArray}(${itemConversionFunction.code}, ${literalOf(!this._mutable)})`,
|
|
46
|
-
sourceTypes,
|
|
47
|
-
});
|
|
48
21
|
}
|
|
49
22
|
get equalsFunction() {
|
|
50
23
|
return code `((left, right) => ${this.reusables.snippets.arrayEquals}(left, right, ${this.itemType.equalsFunction}))`;
|
|
@@ -59,7 +32,7 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
59
32
|
return code `${this.reusables.snippets.CollectionFilter}<${this.itemType.filterType}>`;
|
|
60
33
|
}
|
|
61
34
|
get graphqlType() {
|
|
62
|
-
return new AbstractContainerType.GraphqlType(code `new ${this.reusables.imports.GraphQLList}(${this.itemType.graphqlType.
|
|
35
|
+
return new AbstractContainerType.GraphqlType(code `new ${this.reusables.imports.GraphQLList}(${this.itemType.graphqlType.expression})`, this.reusables);
|
|
63
36
|
}
|
|
64
37
|
get hashFunction() {
|
|
65
38
|
return code `${this.reusables.snippets.hashArray}(${this.itemType.hashFunction})`;
|
|
@@ -73,38 +46,9 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
73
46
|
get validationFunction() {
|
|
74
47
|
return Maybe.of(code `${this.reusables.snippets.validateArray}(${this.itemType.validationFunction.orDefault(this.itemValidationFunctionDefault)}, ${literalOf(!this._mutable)})`);
|
|
75
48
|
}
|
|
76
|
-
get schemaInitializers() {
|
|
77
|
-
let schemaInitializers = super.schemaInitializers;
|
|
78
|
-
if (this.minCount > 0n) {
|
|
79
|
-
schemaInitializers = schemaInitializers.concat(code `minCount: ${Number(this.minCount)}`);
|
|
80
|
-
}
|
|
81
|
-
return schemaInitializers;
|
|
82
|
-
}
|
|
83
|
-
fromJsonExpression({ variables, }) {
|
|
84
|
-
let expression = variables.value;
|
|
85
|
-
if (this.minCount === 0n) {
|
|
86
|
-
expression = code `(${expression} ?? [])`;
|
|
87
|
-
}
|
|
88
|
-
return code `${this.reusables.imports.Either}.sequence<Error, ${this.itemType.expression}>(${expression}.map(item => (${this.itemType.fromJsonExpression({
|
|
89
|
-
variables: { value: code `item` },
|
|
90
|
-
})})))`;
|
|
91
|
-
}
|
|
92
49
|
graphqlResolveExpression({ variables, }) {
|
|
93
50
|
return variables.value;
|
|
94
51
|
}
|
|
95
|
-
jsonSchema(parameters) {
|
|
96
|
-
let schema = code `${this.itemType.jsonSchema(parameters)}.array()`;
|
|
97
|
-
if (this.minCount > 0n) {
|
|
98
|
-
schema = code `${schema}.nonempty().min(${this.minCount})`;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
schema = code `${schema}.optional()`;
|
|
102
|
-
}
|
|
103
|
-
if (!this._mutable) {
|
|
104
|
-
schema = code `${schema}.readonly()`;
|
|
105
|
-
}
|
|
106
|
-
return schema;
|
|
107
|
-
}
|
|
108
52
|
jsonUiSchemaElement(parameters) {
|
|
109
53
|
return this.itemType.jsonUiSchemaElement(parameters);
|
|
110
54
|
}
|
|
@@ -112,9 +56,6 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
112
56
|
return code `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: code `item` } })}))`;
|
|
113
57
|
}
|
|
114
58
|
}
|
|
115
|
-
__decorate([
|
|
116
|
-
Memoize()
|
|
117
|
-
], AbstractCollectionType.prototype, "conversionFunction", null);
|
|
118
59
|
__decorate([
|
|
119
60
|
Memoize()
|
|
120
61
|
], AbstractCollectionType.prototype, "equalsFunction", null);
|
|
@@ -36,7 +36,6 @@ export declare abstract class AbstractContainerType<ItemTypeT extends AbstractCo
|
|
|
36
36
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
37
37
|
get recursive(): boolean;
|
|
38
38
|
get referencesObjectType(): boolean;
|
|
39
|
-
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
40
39
|
protected get itemConversionFunctionDefault(): AbstractType.ConversionFunction;
|
|
41
40
|
protected get itemValidationFunctionDefault(): Code;
|
|
42
41
|
protected get schemaInitializers(): readonly Code[];
|
|
@@ -29,16 +29,13 @@ export class AbstractContainerType extends AbstractType {
|
|
|
29
29
|
get referencesObjectType() {
|
|
30
30
|
return this.itemType.referencesObjectType;
|
|
31
31
|
}
|
|
32
|
-
get toRdfResourceValueTypes() {
|
|
33
|
-
return this.itemType.toRdfResourceValueTypes;
|
|
34
|
-
}
|
|
35
32
|
get itemConversionFunctionDefault() {
|
|
36
33
|
return {
|
|
37
34
|
code: code `${this.reusables.snippets.identityConversionFunction}`,
|
|
38
35
|
sourceTypes: [
|
|
39
36
|
{
|
|
40
37
|
expression: this.itemType.expression,
|
|
41
|
-
|
|
38
|
+
jsType: this.itemType.jsTypes[0],
|
|
42
39
|
},
|
|
43
40
|
],
|
|
44
41
|
};
|
|
@@ -5,10 +5,13 @@ export declare abstract class AbstractDateType extends AbstractPrimitiveType<Dat
|
|
|
5
5
|
readonly expression: Code;
|
|
6
6
|
readonly filterFunction: Code;
|
|
7
7
|
readonly filterType: Code;
|
|
8
|
+
readonly jsTypes: readonly [{
|
|
9
|
+
readonly instanceof: "Date";
|
|
10
|
+
readonly typeof: "object";
|
|
11
|
+
}];
|
|
8
12
|
abstract readonly kind: "DateTime" | "Date";
|
|
9
13
|
readonly mutable = false;
|
|
10
14
|
readonly schemaType: Code;
|
|
11
|
-
readonly typeofs: "object"[];
|
|
12
15
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
13
16
|
fromJsonExpression({ variables, }: Parameters<AbstractPrimitiveType<Date>["fromJsonExpression"]>[0]): Code;
|
|
14
17
|
jsonType(): AbstractPrimitiveType.JsonType;
|
|
@@ -12,9 +12,14 @@ export class AbstractDateType extends AbstractPrimitiveType {
|
|
|
12
12
|
expression = code `Date`;
|
|
13
13
|
filterFunction = code `${this.reusables.snippets.filterDate}`;
|
|
14
14
|
filterType = code `${this.reusables.snippets.DateFilter}`;
|
|
15
|
+
jsTypes = [
|
|
16
|
+
{
|
|
17
|
+
instanceof: "Date",
|
|
18
|
+
typeof: "object",
|
|
19
|
+
},
|
|
20
|
+
];
|
|
15
21
|
mutable = false;
|
|
16
22
|
schemaType = code `${this.reusables.snippets.DateSchema}`;
|
|
17
|
-
typeofs = ["object"];
|
|
18
23
|
valueSparqlWherePatternsFunction = code `${this.reusables.snippets.dateSparqlWherePatterns}`;
|
|
19
24
|
fromJsonExpression({ variables, }) {
|
|
20
25
|
return code `${this.reusables.imports.Either}.of<Error, Date>(new Date(${variables.value}))`;
|
|
@@ -3,6 +3,10 @@ import type { IdentifierNodeKind } from "@shaclmate/shacl-ast";
|
|
|
3
3
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
4
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
5
|
export declare abstract class AbstractIdentifierType<IdentifierT extends BlankNode | NamedNode> extends AbstractTermType<NamedNode, IdentifierT> {
|
|
6
|
+
readonly jsTypes: readonly [{
|
|
7
|
+
readonly instanceof: "Object";
|
|
8
|
+
readonly typeof: "object";
|
|
9
|
+
}];
|
|
6
10
|
abstract readonly kind: "BlankNode" | "Identifier" | "Iri";
|
|
7
11
|
abstract readonly nodeKinds: ReadonlySet<IdentifierNodeKind>;
|
|
8
12
|
abstract readonly parseFunction: Code;
|
|
@@ -8,6 +8,9 @@ import { Memoize } from "typescript-memoize";
|
|
|
8
8
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
9
9
|
import { code } from "./ts-poet-wrapper.js";
|
|
10
10
|
export class AbstractIdentifierType extends AbstractTermType {
|
|
11
|
+
jsTypes = [
|
|
12
|
+
{ instanceof: "Object", typeof: "object" },
|
|
13
|
+
];
|
|
11
14
|
stringifyFunction = code `${this.reusables.imports.NTriplesTerm}.stringify`;
|
|
12
15
|
get graphqlType() {
|
|
13
16
|
return new AbstractTermType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
|
|
@@ -17,7 +17,6 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
17
17
|
readonly discriminantProperty: AbstractType["discriminantProperty"];
|
|
18
18
|
readonly mutable = false;
|
|
19
19
|
readonly referencesObjectType = true;
|
|
20
|
-
readonly typeofs: "object"[];
|
|
21
20
|
readonly validationFunction: Maybe<Code>;
|
|
22
21
|
constructor({ partialType, resolveType, ...superParameters }: {
|
|
23
22
|
partialType: PartialTypeT;
|
|
@@ -29,6 +28,7 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
29
28
|
get filterType(): Code;
|
|
30
29
|
get graphqlType(): AbstractType.GraphqlType;
|
|
31
30
|
get hashFunction(): Code;
|
|
31
|
+
get jsTypes(): readonly AbstractType.JsType[];
|
|
32
32
|
get recursive(): boolean;
|
|
33
33
|
get schemaType(): Code;
|
|
34
34
|
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
@@ -16,7 +16,6 @@ export class AbstractLazyObjectType extends AbstractType {
|
|
|
16
16
|
discriminantProperty = Maybe.empty();
|
|
17
17
|
mutable = false;
|
|
18
18
|
referencesObjectType = true;
|
|
19
|
-
typeofs = ["object"];
|
|
20
19
|
validationFunction = Maybe.empty();
|
|
21
20
|
constructor({ partialType, resolveType, ...superParameters }) {
|
|
22
21
|
super(superParameters);
|
|
@@ -41,6 +40,15 @@ export class AbstractLazyObjectType extends AbstractType {
|
|
|
41
40
|
get hashFunction() {
|
|
42
41
|
return code `((hasher, value) => ${this.partialType.hashFunction}(hasher, value.${this.runtimeClass.partialPropertyName}))`;
|
|
43
42
|
}
|
|
43
|
+
get jsTypes() {
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
className: this.runtimeClass.rawName,
|
|
47
|
+
instanceof: "class",
|
|
48
|
+
typeof: "object",
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
}
|
|
44
52
|
get recursive() {
|
|
45
53
|
return this.partialType.recursive;
|
|
46
54
|
}
|
|
@@ -125,6 +133,9 @@ __decorate([
|
|
|
125
133
|
__decorate([
|
|
126
134
|
Memoize()
|
|
127
135
|
], AbstractLazyObjectType.prototype, "hashFunction", null);
|
|
136
|
+
__decorate([
|
|
137
|
+
Memoize()
|
|
138
|
+
], AbstractLazyObjectType.prototype, "jsTypes", null);
|
|
128
139
|
__decorate([
|
|
129
140
|
Memoize()
|
|
130
141
|
], AbstractLazyObjectType.prototype, "schemaType", null);
|
|
@@ -22,6 +22,7 @@ export declare namespace AbstractLiteralType {
|
|
|
22
22
|
type DiscriminantProperty = AbstractTermType.DiscriminantProperty;
|
|
23
23
|
const GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
24
24
|
type GraphqlType = AbstractTermType.GraphqlType;
|
|
25
|
+
type JsType = AbstractTermType.JsType;
|
|
25
26
|
const JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
26
27
|
type JsonType = AbstractTermType.JsonType;
|
|
27
28
|
}
|
|
@@ -13,27 +13,27 @@ import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
|
13
13
|
export class AbstractNumericType extends AbstractPrimitiveType {
|
|
14
14
|
hashFunction = code `${this.reusables.snippets.hashNumeric}`;
|
|
15
15
|
get filterFunction() {
|
|
16
|
-
return code `${this.reusables.snippets.filterNumeric}<${this.
|
|
16
|
+
return code `${this.reusables.snippets.filterNumeric}<${this.jsTypes[0].typeof}>`;
|
|
17
17
|
}
|
|
18
18
|
get filterType() {
|
|
19
|
-
return code `${this.reusables.snippets.NumericFilter}<${this.
|
|
19
|
+
return code `${this.reusables.snippets.NumericFilter}<${this.jsTypes[0].typeof}>`;
|
|
20
20
|
}
|
|
21
21
|
get expression() {
|
|
22
22
|
if (this.primitiveIn.length > 0) {
|
|
23
23
|
return code `${joinCode(this.primitiveIn.map((value) => this.literalExpression(value)), { on: " | " })}`;
|
|
24
24
|
}
|
|
25
|
-
return code `${this.
|
|
25
|
+
return code `${this.jsTypes[0].typeof}`;
|
|
26
26
|
}
|
|
27
27
|
get schemaType() {
|
|
28
|
-
return code `${this.reusables.snippets.NumericSchema}<${this.
|
|
28
|
+
return code `${this.reusables.snippets.NumericSchema}<${this.jsTypes[0].typeof}>`;
|
|
29
29
|
}
|
|
30
30
|
get valueSparqlWherePatternsFunction() {
|
|
31
|
-
return code `${this.reusables.snippets.numericSparqlWherePatterns}<${this.
|
|
31
|
+
return code `${this.reusables.snippets.numericSparqlWherePatterns}<${this.jsTypes[0].typeof}>`;
|
|
32
32
|
}
|
|
33
33
|
jsonSchema(_parameters) {
|
|
34
34
|
switch (this.primitiveIn.length) {
|
|
35
35
|
case 0:
|
|
36
|
-
return code `${this.reusables.imports.z}.${this.
|
|
36
|
+
return code `${this.reusables.imports.z}.${this.jsTypes[0].typeof}()`;
|
|
37
37
|
case 1:
|
|
38
38
|
return code `${this.reusables.imports.z}.literal(${this.literalExpression(this.primitiveIn[0])})`;
|
|
39
39
|
default:
|
|
@@ -41,7 +41,7 @@ export class AbstractNumericType extends AbstractPrimitiveType {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
toRdfResourceValuesExpression({ variables, }) {
|
|
44
|
-
return code `[${this.reusables.snippets.literalFactory}.${this.
|
|
44
|
+
return code `[${this.reusables.snippets.literalFactory}.${this.jsTypes[0].typeof}(${variables.value}, ${this.rdfjsTermExpression(this.datatype)})]`;
|
|
45
45
|
}
|
|
46
46
|
fromRdfResourceValuesExpressionChain({ variables, }) {
|
|
47
47
|
return {
|
|
@@ -23,6 +23,7 @@ export declare abstract class AbstractPrimitiveType<ValueT extends bigint | bool
|
|
|
23
23
|
export declare namespace AbstractPrimitiveType {
|
|
24
24
|
type ConversionFunction = AbstractLiteralType.ConversionFunction;
|
|
25
25
|
type DiscriminantProperty = AbstractLiteralType.DiscriminantProperty;
|
|
26
|
+
type JsType = AbstractLiteralType.JsType;
|
|
26
27
|
const GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
27
28
|
type GraphqlType = AbstractLiteralType.GraphqlType;
|
|
28
29
|
const JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
@@ -3,7 +3,6 @@ import { NodeKind } from "@shaclmate/shacl-ast";
|
|
|
3
3
|
import { Maybe } from "purify-ts";
|
|
4
4
|
import { AbstractType } from "./AbstractType.js";
|
|
5
5
|
import type { Type } from "./Type.js";
|
|
6
|
-
import type { Typeof } from "./Typeof.js";
|
|
7
6
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
8
7
|
/**
|
|
9
8
|
* Abstract base class for IdentifierType and LiteralType.
|
|
@@ -24,7 +23,6 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
|
|
|
24
23
|
abstract readonly nodeKinds: ReadonlySet<NodeKind>;
|
|
25
24
|
readonly recursive = false;
|
|
26
25
|
readonly referencesObjectType = false;
|
|
27
|
-
readonly typeofs: readonly Typeof[];
|
|
28
26
|
readonly validationFunction: Maybe<Code>;
|
|
29
27
|
constructor({ hasValues, in_, ...superParameters }: {
|
|
30
28
|
hasValues: readonly ConstantTermT[];
|
|
@@ -60,6 +58,7 @@ export declare namespace AbstractTermType {
|
|
|
60
58
|
type DiscriminantProperty = AbstractType.DiscriminantProperty;
|
|
61
59
|
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
62
60
|
type GraphqlType = AbstractType.GraphqlType;
|
|
61
|
+
type JsType = AbstractType.JsType;
|
|
63
62
|
const JsonType: typeof AbstractType.JsonType;
|
|
64
63
|
type JsonType = AbstractType.JsonType;
|
|
65
64
|
}
|
|
@@ -27,7 +27,6 @@ export class AbstractTermType extends AbstractType {
|
|
|
27
27
|
mutable = false;
|
|
28
28
|
recursive = false;
|
|
29
29
|
referencesObjectType = false;
|
|
30
|
-
typeofs = ["object"];
|
|
31
30
|
validationFunction = Maybe.empty();
|
|
32
31
|
constructor({ hasValues, in_, ...superParameters }) {
|
|
33
32
|
super(superParameters);
|
|
@@ -39,10 +38,9 @@ export class AbstractTermType extends AbstractType {
|
|
|
39
38
|
}
|
|
40
39
|
get discriminantProperty() {
|
|
41
40
|
return Maybe.of({
|
|
42
|
-
descendantValues: [],
|
|
43
41
|
jsonName: "termType",
|
|
44
42
|
name: "termType",
|
|
45
|
-
|
|
43
|
+
values: [...this.nodeKinds].map(NodeKind.toTermType),
|
|
46
44
|
type: "string",
|
|
47
45
|
});
|
|
48
46
|
}
|