@shaclmate/compiler 4.0.33 → 4.0.35
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/Compiler.d.ts +0 -3
- package/dist/Compiler.js +0 -2
- package/dist/ShapesGraphToAstTransformer.d.ts +1 -4
- package/dist/ShapesGraphToAstTransformer.js +1 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +1 -3
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +4 -7
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +0 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +1 -3
- package/dist/ast/AbstractCompoundType.d.ts +6 -4
- package/dist/ast/AbstractCompoundType.js +4 -37
- package/dist/ast/ObjectType.d.ts +1 -7
- package/dist/ast/ObjectType.js +1 -6
- package/dist/generators/ts/AbstractCollectionType.d.ts +9 -8
- package/dist/generators/ts/AbstractCollectionType.js +38 -120
- package/dist/generators/ts/AbstractContainerType.d.ts +3 -1
- package/dist/generators/ts/AbstractContainerType.js +20 -0
- package/dist/generators/ts/AbstractDateType.d.ts +5 -10
- package/dist/generators/ts/AbstractDateType.js +5 -32
- package/dist/generators/ts/AbstractIdentifierType.d.ts +4 -1
- package/dist/generators/ts/AbstractIdentifierType.js +0 -17
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +9 -5
- package/dist/generators/ts/AbstractLazyObjectType.js +22 -21
- package/dist/generators/ts/AbstractLiteralType.d.ts +12 -4
- package/dist/generators/ts/AbstractLiteralType.js +3 -3
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +2 -5
- package/dist/generators/ts/AbstractNamedUnionType.js +27 -58
- package/dist/generators/ts/AbstractNumericType.d.ts +3 -9
- package/dist/generators/ts/AbstractNumericType.js +6 -13
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +9 -4
- package/dist/generators/ts/AbstractPrimitiveType.js +11 -18
- package/dist/generators/ts/AbstractTermType.d.ts +10 -5
- package/dist/generators/ts/AbstractTermType.js +14 -53
- package/dist/generators/ts/AbstractType.d.ts +39 -24
- package/dist/generators/ts/AbstractType.js +4 -2
- package/dist/generators/ts/AbstractUnionType.d.ts +3 -2
- package/dist/generators/ts/AbstractUnionType.js +29 -39
- package/dist/generators/ts/AnonymousUnionType.d.ts +1 -1
- package/dist/generators/ts/AnonymousUnionType.js +3 -3
- package/dist/generators/ts/BigDecimalType.d.ts +7 -4
- package/dist/generators/ts/BigDecimalType.js +11 -45
- package/dist/generators/ts/BigIntType.d.ts +3 -4
- package/dist/generators/ts/BigIntType.js +6 -17
- package/dist/generators/ts/BlankNodeType.d.ts +8 -7
- package/dist/generators/ts/BlankNodeType.js +18 -5
- package/dist/generators/ts/BooleanType.d.ts +6 -9
- package/dist/generators/ts/BooleanType.js +9 -16
- package/dist/generators/ts/DateTimeType.d.ts +4 -1
- package/dist/generators/ts/DateTimeType.js +6 -13
- package/dist/generators/ts/DateType.d.ts +4 -1
- package/dist/generators/ts/DateType.js +7 -14
- package/dist/generators/ts/DefaultValueType.d.ts +6 -6
- package/dist/generators/ts/DefaultValueType.js +30 -63
- package/dist/generators/ts/FloatType.d.ts +3 -3
- package/dist/generators/ts/FloatType.js +5 -5
- package/dist/generators/ts/IdentifierType.d.ts +7 -6
- package/dist/generators/ts/IdentifierType.js +26 -5
- package/dist/generators/ts/IntType.d.ts +3 -3
- package/dist/generators/ts/IntType.js +5 -5
- package/dist/generators/ts/IriType.d.ts +9 -12
- package/dist/generators/ts/IriType.js +43 -32
- package/dist/generators/ts/LazyObjectOptionType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectOptionType.js +23 -44
- package/dist/generators/ts/LazyObjectSetType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectSetType.js +19 -29
- package/dist/generators/ts/LazyObjectType.d.ts +2 -1
- package/dist/generators/ts/LazyObjectType.js +18 -26
- package/dist/generators/ts/LiteralType.d.ts +6 -3
- package/dist/generators/ts/LiteralType.js +27 -13
- package/dist/generators/ts/NamedObjectType.d.ts +7 -9
- package/dist/generators/ts/NamedObjectType.js +24 -32
- package/dist/generators/ts/NamedObjectUnionType.d.ts +3 -1
- package/dist/generators/ts/NamedObjectUnionType.js +21 -14
- package/dist/generators/ts/OptionType.d.ts +6 -5
- package/dist/generators/ts/OptionType.js +31 -51
- package/dist/generators/ts/Reusables.d.ts +3 -1
- package/dist/generators/ts/Reusables.js +2 -1
- package/dist/generators/ts/SetType.d.ts +0 -1
- package/dist/generators/ts/SetType.js +4 -22
- package/dist/generators/ts/SnippetFactory.d.ts +2 -0
- package/dist/generators/ts/Snippets.d.ts +36 -8
- package/dist/generators/ts/Snippets.js +207 -30
- package/dist/generators/ts/StringType.d.ts +6 -10
- package/dist/generators/ts/StringType.js +8 -21
- package/dist/generators/ts/TermType.d.ts +2 -4
- package/dist/generators/ts/TermType.js +6 -10
- package/dist/generators/ts/TsGenerator.d.ts +14 -1
- package/dist/generators/ts/TsGenerator.js +41 -12
- package/dist/generators/ts/TypeFactory.d.ts +8 -4
- package/dist/generators/ts/TypeFactory.js +73 -49
- package/dist/generators/ts/ZodGenerator.js +6 -3
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +27 -20
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +4 -2
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +7 -7
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +9 -9
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +6 -6
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +36 -39
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.js +34 -31
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js +31 -19
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +30 -36
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js +2 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +6 -8
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js +1 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts +2 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionDeclaration.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toStringFunctionDeclarations.js +14 -18
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +7 -7
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +41 -29
- package/dist/generators/ts/_snippets/snippets_ConversionFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ConversionFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_DefaultValueSchema.js +3 -3
- package/dist/generators/ts/_snippets/snippets_HashFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_HashFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_PropertyPath.js +34 -24
- package/dist/generators/ts/_snippets/snippets_ValidationFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ValidationFunction.js +4 -0
- package/dist/generators/ts/_snippets/snippets_convertToArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToArray.js +8 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNode.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNode.js +11 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToBlankNodeIdentifierProperty.js +17 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifier.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifier.js +13 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIdentifierProperty.js +21 -0
- package/dist/generators/ts/_snippets/snippets_convertToIri.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIri.js +11 -0
- package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToIriIdentifierProperty.js +17 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObject.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObject.js +15 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectOption.js +31 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLazyObjectSet.js +25 -0
- package/dist/generators/ts/_snippets/snippets_convertToLiteral.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLiteral.js +13 -0
- package/dist/generators/ts/_snippets/snippets_convertToMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToMaybe.js +19 -0
- package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertWithDefaultValue.js +11 -0
- package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_hashArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashArray.js +11 -0
- package/dist/generators/ts/_snippets/snippets_hashBigDecimal.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashBigDecimal.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashBoolean.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashBoolean.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashDate.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashDate.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashDateTime.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashDateTime.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashMaybe.js +11 -0
- package/dist/generators/ts/_snippets/snippets_hashNumeric.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashNumeric.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashString.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashString.js +7 -0
- package/dist/generators/ts/_snippets/snippets_hashTerm.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_hashTerm.js +12 -0
- package/dist/generators/ts/_snippets/snippets_identityConversionFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_identityConversionFunction.js +6 -0
- package/dist/generators/ts/_snippets/snippets_identityValidationFunction.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_identityValidationFunction.js +6 -0
- package/dist/generators/ts/_snippets/snippets_toIsoDateString.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_toIsoDateString.js +6 -0
- package/dist/generators/ts/_snippets/snippets_validateArray.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_validateArray.js +13 -0
- package/dist/generators/ts/_snippets/snippets_validateMaybe.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_validateMaybe.js +7 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +1 -1
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +7 -4
- package/dist/generators/ts/objectSetDeclarations.js +4 -34
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +1 -1
- package/dist/generators/ts/objectSetMethodSignatures.js +2 -2
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +2 -2
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +2 -2
- package/dist/input/ShapesGraph.d.ts +5 -8
- package/dist/input/ShapesGraph.js +5 -6
- package/dist/input/generated.d.ts +175 -230
- package/dist/input/generated.js +226 -1748
- package/package.json +2 -2
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.d.ts +0 -6
- package/dist/_ShapesGraphToAstTransformer/nodeShapeTsFeatures.js +0 -67
- package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyBigIntArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyBooleanArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyNumberArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyObjectArray.js +0 -6
- package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_isReadonlyStringArray.js +0 -6
- package/dist/generators/ts/syntheticNamePrefix.d.ts +0 -2
- package/dist/generators/ts/syntheticNamePrefix.js +0 -2
package/dist/Compiler.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { Either } from "purify-ts";
|
|
2
2
|
import type { Logger } from "ts-log";
|
|
3
3
|
import type { Generator } from "./generators/Generator.js";
|
|
4
|
-
import type { TsFeature } from "./generators/ts/TsFeature.js";
|
|
5
4
|
import type { ShapesGraph } from "./input/ShapesGraph.js";
|
|
6
5
|
export declare class Compiler {
|
|
7
6
|
private readonly generator;
|
|
8
7
|
private readonly logger;
|
|
9
|
-
private readonly tsFeaturesDefault?;
|
|
10
8
|
constructor({ generator, logger, }: {
|
|
11
9
|
generator: Generator;
|
|
12
10
|
logger: Logger;
|
|
13
|
-
tsFeaturesDefault?: ReadonlySet<TsFeature>;
|
|
14
11
|
});
|
|
15
12
|
compile(shapesGraph: ShapesGraph): Either<Error, string>;
|
|
16
13
|
}
|
package/dist/Compiler.js
CHANGED
|
@@ -2,7 +2,6 @@ import { ShapesGraphToAstTransformer } from "./ShapesGraphToAstTransformer.js";
|
|
|
2
2
|
export class Compiler {
|
|
3
3
|
generator;
|
|
4
4
|
logger;
|
|
5
|
-
tsFeaturesDefault;
|
|
6
5
|
constructor({ generator, logger, }) {
|
|
7
6
|
this.generator = generator;
|
|
8
7
|
this.logger = logger;
|
|
@@ -11,7 +10,6 @@ export class Compiler {
|
|
|
11
10
|
return new ShapesGraphToAstTransformer({
|
|
12
11
|
logger: this.logger,
|
|
13
12
|
shapesGraph,
|
|
14
|
-
tsFeaturesDefault: this.tsFeaturesDefault,
|
|
15
13
|
})
|
|
16
14
|
.transform()
|
|
17
15
|
.map((ast) => this.generator.generate(ast));
|
|
@@ -3,7 +3,6 @@ import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
|
3
3
|
import { Either } from "purify-ts";
|
|
4
4
|
import type { Logger } from "ts-log";
|
|
5
5
|
import type * as ast from "./ast/index.js";
|
|
6
|
-
import type { TsFeature } from "./generators/ts/TsFeature.js";
|
|
7
6
|
import type * as input from "./input/index.js";
|
|
8
7
|
interface RelatedNodeShapes {
|
|
9
8
|
readonly ancestors: input.NodeShape[];
|
|
@@ -16,11 +15,9 @@ export declare class ShapesGraphToAstTransformer {
|
|
|
16
15
|
protected readonly logger: Logger;
|
|
17
16
|
protected readonly shapesGraph: input.ShapesGraph;
|
|
18
17
|
protected readonly relatedNodeShapesByIdentifier: TermMap<BlankNode | NamedNode, RelatedNodeShapes>;
|
|
19
|
-
|
|
20
|
-
constructor({ logger, shapesGraph, tsFeaturesDefault, }: {
|
|
18
|
+
constructor({ logger, shapesGraph, }: {
|
|
21
19
|
logger: Logger;
|
|
22
20
|
shapesGraph: input.ShapesGraph;
|
|
23
|
-
tsFeaturesDefault?: ReadonlySet<TsFeature>;
|
|
24
21
|
});
|
|
25
22
|
transform(): Either<Error, ast.Ast>;
|
|
26
23
|
}
|
|
@@ -77,17 +77,13 @@ export class ShapesGraphToAstTransformer {
|
|
|
77
77
|
logger;
|
|
78
78
|
shapesGraph;
|
|
79
79
|
relatedNodeShapesByIdentifier = new TermMap();
|
|
80
|
-
|
|
81
|
-
constructor({ logger, shapesGraph, tsFeaturesDefault, }) {
|
|
80
|
+
constructor({ logger, shapesGraph, }) {
|
|
82
81
|
this.logger = logger;
|
|
83
82
|
this.relatedNodeShapesByIdentifier = relatedNodeShapes({
|
|
84
83
|
logger: this.logger,
|
|
85
84
|
shapesGraph,
|
|
86
85
|
});
|
|
87
86
|
this.shapesGraph = shapesGraph;
|
|
88
|
-
this.tsFeaturesDefault =
|
|
89
|
-
tsFeaturesDefault ??
|
|
90
|
-
new Set(["create", "equals", "hash", "json", "rdf"]);
|
|
91
87
|
}
|
|
92
88
|
transform() {
|
|
93
89
|
const astNamedIntersectionTypes = [];
|
|
@@ -6,7 +6,7 @@ import * as ast from "../ast/index.js";
|
|
|
6
6
|
import { Eithers } from "../Eithers.js";
|
|
7
7
|
import { ShapeStack } from "./ShapeStack.js";
|
|
8
8
|
import { transformShapeToAstType } from "./transformShapeToAstType.js";
|
|
9
|
-
function synthesizePartialAstObjectType({ identifierType,
|
|
9
|
+
function synthesizePartialAstObjectType({ identifierType, }) {
|
|
10
10
|
let syntheticName;
|
|
11
11
|
switch (identifierType.kind) {
|
|
12
12
|
case "BlankNodeType":
|
|
@@ -28,7 +28,6 @@ function synthesizePartialAstObjectType({ identifierType, tsFeatures, }) {
|
|
|
28
28
|
shapeIdentifier: dataFactory.namedNode(`urn:shaclmate:synthetic:${syntheticName}`),
|
|
29
29
|
synthetic: true,
|
|
30
30
|
toRdfTypes: [],
|
|
31
|
-
tsFeatures,
|
|
32
31
|
tsImports: [],
|
|
33
32
|
});
|
|
34
33
|
}
|
|
@@ -179,7 +178,6 @@ export function transformPropertyShapeToAstObjectTypeProperty({ objectType, prop
|
|
|
179
178
|
case "IriType":
|
|
180
179
|
astPartialItemType = synthesizePartialAstObjectType({
|
|
181
180
|
identifierType: astItemType,
|
|
182
|
-
tsFeatures: astResolveItemType.tsFeatures,
|
|
183
181
|
});
|
|
184
182
|
break;
|
|
185
183
|
case "ObjectType":
|
|
@@ -2,7 +2,6 @@ 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 { nodeShapeTsFeatures } from "./nodeShapeTsFeatures.js";
|
|
6
5
|
import { shapeAstTypeName } from "./shapeAstTypeName.js";
|
|
7
6
|
import { transformShapeToAstType } from "./transformShapeToAstType.js";
|
|
8
7
|
/**
|
|
@@ -11,13 +10,11 @@ import { transformShapeToAstType } from "./transformShapeToAstType.js";
|
|
|
11
10
|
export function transformShapeToAstCompoundType(shape, shapeStack) {
|
|
12
11
|
shapeStack.push(shape);
|
|
13
12
|
try {
|
|
14
|
-
return Eithers.
|
|
13
|
+
return Eithers.chain2(Either.sequence(shape.and
|
|
15
14
|
.orDefault([])
|
|
16
|
-
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))), shape
|
|
17
|
-
? nodeShapeTsFeatures.call(this, shape)
|
|
18
|
-
: Either.of(new Set()), Either.sequence(shape.xone
|
|
15
|
+
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier))), Either.sequence(shape.xone
|
|
19
16
|
.orDefault([])
|
|
20
|
-
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier)))).chain(([andConstraintShapes,
|
|
17
|
+
.map((shapeIdentifier) => this.shapesGraph.shape(shapeIdentifier)))).chain(([andConstraintShapes, xoneConstraintShapes]) => {
|
|
21
18
|
let compoundTypeKind;
|
|
22
19
|
// Distinguish constraints that take arbitrary shapes from those that only take node shapes
|
|
23
20
|
// With the latter we'll do special transformations.
|
|
@@ -42,7 +39,7 @@ export function transformShapeToAstCompoundType(shape, shapeStack) {
|
|
|
42
39
|
label: shape.label,
|
|
43
40
|
name: shapeAstTypeName(shape),
|
|
44
41
|
shapeIdentifier: shape.$identifier(),
|
|
45
|
-
|
|
42
|
+
synthetic: false,
|
|
46
43
|
});
|
|
47
44
|
if (memberShapes.length === 1) {
|
|
48
45
|
return transformShapeToAstType
|
|
@@ -4,7 +4,6 @@ import { invariant } from "ts-invariant";
|
|
|
4
4
|
import * as ast from "../ast/index.js";
|
|
5
5
|
import { Eithers } from "../Eithers.js";
|
|
6
6
|
import { defaultNodeShapeNodeKinds } from "./defaultNodeShapeNodeKinds.js";
|
|
7
|
-
import { nodeShapeTsFeatures } from "./nodeShapeTsFeatures.js";
|
|
8
7
|
import { ShapeStack } from "./ShapeStack.js";
|
|
9
8
|
import { shapeAstTypeName } from "./shapeAstTypeName.js";
|
|
10
9
|
import { shapeNodeKinds } from "./shapeNodeKinds.js";
|
|
@@ -60,7 +59,7 @@ export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
|
60
59
|
if (nodeShape.$identifier().termType !== "NamedNode") {
|
|
61
60
|
return Either.of(Maybe.empty());
|
|
62
61
|
}
|
|
63
|
-
return Eithers.
|
|
62
|
+
return Eithers.chain2(shapeNodeKinds.call(this, nodeShape, { defaultNodeShapeNodeKinds }), Either.sequence(nodeShape.properties.map((propertyShapeIdentifier) => this.shapesGraph.propertyShape(propertyShapeIdentifier)))).chain(([nodeKinds, propertyShapes]) => {
|
|
64
63
|
const nodeShapeIdentifier = nodeShape.$identifier();
|
|
65
64
|
const { ancestors: ancestorNodeShapes, descendants: descendantNodeShapes, children: childNodeShapes, parents: parentNodeShapes, } = this.relatedNodeShapesByIdentifier.get(nodeShapeIdentifier);
|
|
66
65
|
const isClass = nodeShape.subClassOf.length > 0 ||
|
|
@@ -128,7 +127,6 @@ export function transformShapeToAstObjectType(shape, shapeStack) {
|
|
|
128
127
|
shapeIdentifier: nodeShape.$identifier(),
|
|
129
128
|
synthetic: false,
|
|
130
129
|
toRdfTypes,
|
|
131
|
-
tsFeatures,
|
|
132
130
|
tsImports: nodeShape.tsImports,
|
|
133
131
|
});
|
|
134
132
|
this.cachedAstTypesByShapeIdentifier.set(nodeShape.$identifier(), objectType);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NodeKind } from "@shaclmate/shacl-ast";
|
|
2
|
-
import type { TsFeature } from "../generators/ts/TsFeature.js";
|
|
3
2
|
import { AbstractType } from "./AbstractType.js";
|
|
4
3
|
import type { BlankNodeType } from "./BlankNodeType.js";
|
|
5
4
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
@@ -22,13 +21,16 @@ export declare abstract class AbstractCompoundType<MemberT extends AbstractCompo
|
|
|
22
21
|
* Type discriminant
|
|
23
22
|
*/
|
|
24
23
|
abstract readonly kind: "IntersectionType" | "UnionType";
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Was this type synthesized or did it come from SHACL?
|
|
26
|
+
*/
|
|
27
|
+
readonly synthetic: boolean;
|
|
28
|
+
constructor({ synthetic, ...superParameters }: {
|
|
29
|
+
synthetic: boolean;
|
|
27
30
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
28
31
|
get members(): readonly MemberT[];
|
|
29
32
|
get nodeKinds(): ReadonlySet<NodeKind>;
|
|
30
33
|
get recursive(): boolean;
|
|
31
|
-
get tsFeatures(): ReadonlySet<TsFeature>;
|
|
32
34
|
addMember(member: MemberT): void;
|
|
33
35
|
equals(other: AbstractCompoundType<MemberT, MemberTypeT>): boolean;
|
|
34
36
|
}
|
|
@@ -20,12 +20,12 @@ export class AbstractCompoundType extends AbstractType {
|
|
|
20
20
|
*/
|
|
21
21
|
#members = [];
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Was this type synthesized or did it come from SHACL?
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
constructor({
|
|
25
|
+
synthetic;
|
|
26
|
+
constructor({ synthetic, ...superParameters }) {
|
|
27
27
|
super(superParameters);
|
|
28
|
-
this
|
|
28
|
+
this.synthetic = synthetic;
|
|
29
29
|
}
|
|
30
30
|
get members() {
|
|
31
31
|
return this.#members;
|
|
@@ -42,36 +42,6 @@ export class AbstractCompoundType extends AbstractType {
|
|
|
42
42
|
get recursive() {
|
|
43
43
|
return this.members.some((member) => member.type.recursive);
|
|
44
44
|
}
|
|
45
|
-
get tsFeatures() {
|
|
46
|
-
// Members of the compound type must have the same tsFeatures.
|
|
47
|
-
// They must also have distinct RDF types or no RDF types at all.
|
|
48
|
-
const mergedMemberTsFeatures = new Set();
|
|
49
|
-
for (let memberI = 0; memberI < this.members.length; memberI++) {
|
|
50
|
-
const member = this.members[memberI];
|
|
51
|
-
switch (member.type.kind) {
|
|
52
|
-
case "IntersectionType":
|
|
53
|
-
case "ObjectType":
|
|
54
|
-
case "UnionType":
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (memberI === 0) {
|
|
60
|
-
for (const tsFeature of member.type.tsFeatures) {
|
|
61
|
-
mergedMemberTsFeatures.add(tsFeature);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (member.type.tsFeatures.size !== mergedMemberTsFeatures.size) {
|
|
65
|
-
throw new Error(`${this} has a member (${member}) with different tsFeatures than the other members`);
|
|
66
|
-
}
|
|
67
|
-
for (const tsFeature of member.type.tsFeatures) {
|
|
68
|
-
if (!mergedMemberTsFeatures.has(tsFeature)) {
|
|
69
|
-
throw new Error(`${this} has a member (${member}) with different tsFeatures than the other members`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return this.#tsFeatures;
|
|
74
|
-
}
|
|
75
45
|
addMember(member) {
|
|
76
46
|
this.#members.push(member);
|
|
77
47
|
}
|
|
@@ -84,9 +54,6 @@ export class AbstractCompoundType extends AbstractType {
|
|
|
84
54
|
__decorate([
|
|
85
55
|
Memoize()
|
|
86
56
|
], AbstractCompoundType.prototype, "nodeKinds", null);
|
|
87
|
-
__decorate([
|
|
88
|
-
Memoize()
|
|
89
|
-
], AbstractCompoundType.prototype, "tsFeatures", null);
|
|
90
57
|
(function (AbstractCompoundType) {
|
|
91
58
|
function isMemberType(type) {
|
|
92
59
|
switch (type.kind) {
|
package/dist/ast/ObjectType.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { BlankNode, NamedNode } from "@rdfjs/types";
|
|
|
2
2
|
import { PropertyPath } from "@rdfx/resource";
|
|
3
3
|
import type { NodeKind } from "@shaclmate/shacl-ast";
|
|
4
4
|
import type { Maybe } from "purify-ts";
|
|
5
|
-
import type { TsFeature } from "../generators/ts/TsFeature.js";
|
|
6
5
|
import { AbstractType } from "./AbstractType.js";
|
|
7
6
|
import type { BlankNodeType } from "./BlankNodeType.js";
|
|
8
7
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
@@ -43,10 +42,6 @@ export declare class ObjectType extends AbstractType {
|
|
|
43
42
|
* class targets).
|
|
44
43
|
*/
|
|
45
44
|
readonly toRdfTypes: readonly NamedNode[];
|
|
46
|
-
/**
|
|
47
|
-
* TypeScript features to generate.
|
|
48
|
-
*/
|
|
49
|
-
readonly tsFeatures: ReadonlySet<TsFeature>;
|
|
50
45
|
/**
|
|
51
46
|
* TypeScript imports to add to generated code.
|
|
52
47
|
*
|
|
@@ -56,13 +51,12 @@ export declare class ObjectType extends AbstractType {
|
|
|
56
51
|
* import { MyType } from "./MyType.js"
|
|
57
52
|
*/
|
|
58
53
|
readonly tsImports: readonly string[];
|
|
59
|
-
constructor({ extern, fromRdfType, identifierType, synthetic, toRdfTypes,
|
|
54
|
+
constructor({ extern, fromRdfType, identifierType, synthetic, toRdfTypes, tsImports, ...superParameters }: {
|
|
60
55
|
extern: boolean;
|
|
61
56
|
fromRdfType: Maybe<NamedNode>;
|
|
62
57
|
identifierType: BlankNodeType | IdentifierType | IriType;
|
|
63
58
|
synthetic: boolean;
|
|
64
59
|
toRdfTypes: readonly NamedNode[];
|
|
65
|
-
tsFeatures: ReadonlySet<TsFeature>;
|
|
66
60
|
tsImports: readonly string[];
|
|
67
61
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
68
62
|
get ancestorObjectTypes(): readonly ObjectType[];
|
package/dist/ast/ObjectType.js
CHANGED
|
@@ -76,10 +76,6 @@ export class ObjectType extends AbstractType {
|
|
|
76
76
|
* class targets).
|
|
77
77
|
*/
|
|
78
78
|
toRdfTypes;
|
|
79
|
-
/**
|
|
80
|
-
* TypeScript features to generate.
|
|
81
|
-
*/
|
|
82
|
-
tsFeatures;
|
|
83
79
|
/**
|
|
84
80
|
* TypeScript imports to add to generated code.
|
|
85
81
|
*
|
|
@@ -89,14 +85,13 @@ export class ObjectType extends AbstractType {
|
|
|
89
85
|
* import { MyType } from "./MyType.js"
|
|
90
86
|
*/
|
|
91
87
|
tsImports;
|
|
92
|
-
constructor({ extern, fromRdfType, identifierType, synthetic, toRdfTypes,
|
|
88
|
+
constructor({ extern, fromRdfType, identifierType, synthetic, toRdfTypes, tsImports, ...superParameters }) {
|
|
93
89
|
super(superParameters);
|
|
94
90
|
this.extern = extern;
|
|
95
91
|
this.fromRdfType = fromRdfType;
|
|
96
92
|
this.identifierType = identifierType;
|
|
97
93
|
this.synthetic = synthetic;
|
|
98
94
|
this.toRdfTypes = toRdfTypes;
|
|
99
|
-
this.tsFeatures = tsFeatures;
|
|
100
95
|
this.tsImports = tsImports;
|
|
101
96
|
}
|
|
102
97
|
get ancestorObjectTypes() {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Maybe
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
2
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
3
|
+
import type { AbstractType } from "./AbstractType.js";
|
|
3
4
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
4
5
|
/**
|
|
5
6
|
* Abstract base class for ListType and SetType.
|
|
@@ -9,19 +10,21 @@ export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractC
|
|
|
9
10
|
protected readonly minCount: bigint;
|
|
10
11
|
readonly discriminantProperty: Maybe<AbstractContainerType.DiscriminantProperty>;
|
|
11
12
|
readonly graphqlArgs: AbstractContainerType<ItemTypeT>["graphqlArgs"];
|
|
12
|
-
readonly typeofs:
|
|
13
|
+
readonly typeofs: "object"[];
|
|
13
14
|
constructor({ minCount, mutable, ...superParameters }: {
|
|
14
15
|
minCount: bigint;
|
|
15
16
|
mutable: boolean;
|
|
16
17
|
} & ConstructorParameters<typeof AbstractContainerType<ItemTypeT>>[0]);
|
|
17
|
-
get
|
|
18
|
+
get conversionFunction(): Maybe<AbstractType.ConversionFunction>;
|
|
18
19
|
get equalsFunction(): Code;
|
|
19
20
|
get filterFunction(): Code;
|
|
20
21
|
get filterType(): Code;
|
|
21
22
|
get graphqlType(): AbstractContainerType.GraphqlType;
|
|
23
|
+
get hashFunction(): Code;
|
|
22
24
|
get mutable(): boolean;
|
|
23
25
|
get name(): Code;
|
|
24
26
|
get schemaType(): Code;
|
|
27
|
+
get validationFunction(): Maybe<Code>;
|
|
25
28
|
protected get schemaObject(): {
|
|
26
29
|
minCount: number | undefined;
|
|
27
30
|
item: Code;
|
|
@@ -29,19 +32,17 @@ export declare abstract class AbstractCollectionType<ItemTypeT extends AbstractC
|
|
|
29
32
|
};
|
|
30
33
|
fromJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["fromJsonExpression"]>[0]): Code;
|
|
31
34
|
graphqlResolveExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["graphqlResolveExpression"]>[0]): Code;
|
|
32
|
-
hashStatements({ depth, variables, }: Parameters<AbstractContainerType<ItemTypeT>["hashStatements"]>[0]): readonly Code[];
|
|
33
|
-
jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
34
35
|
jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
|
|
36
|
+
jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
35
37
|
toJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toJsonExpression"]>[0]): Code;
|
|
36
38
|
}
|
|
37
39
|
export declare namespace AbstractCollectionType {
|
|
38
|
-
type Conversion = AbstractContainerType.Conversion;
|
|
39
40
|
type DiscriminantProperty = AbstractContainerType.DiscriminantProperty;
|
|
40
|
-
const GraphqlType: typeof
|
|
41
|
+
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
41
42
|
type GraphqlType = AbstractContainerType.GraphqlType;
|
|
42
43
|
const isItemType: typeof AbstractContainerType.isItemType;
|
|
43
44
|
type ItemType = AbstractContainerType.ItemType;
|
|
44
|
-
const JsonType: typeof
|
|
45
|
+
const JsonType: typeof AbstractType.JsonType;
|
|
45
46
|
type JsonType = AbstractContainerType.JsonType;
|
|
46
47
|
}
|
|
47
48
|
//# sourceMappingURL=AbstractCollectionType.d.ts.map
|
|
@@ -4,12 +4,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { Maybe
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
11
|
-
import {
|
|
12
|
-
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
11
|
+
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
13
12
|
/**
|
|
14
13
|
* Abstract base class for ListType and SetType.
|
|
15
14
|
*/
|
|
@@ -18,7 +17,7 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
18
17
|
minCount;
|
|
19
18
|
discriminantProperty = Maybe.empty();
|
|
20
19
|
graphqlArgs = Maybe.empty();
|
|
21
|
-
typeofs =
|
|
20
|
+
typeofs = ["object"];
|
|
22
21
|
constructor({ minCount, mutable, ...superParameters }) {
|
|
23
22
|
super(superParameters);
|
|
24
23
|
this.minCount = minCount;
|
|
@@ -28,91 +27,24 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
28
27
|
invariant(this.minCount === 0n);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
get
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// array.every(item => typeof item === "string")
|
|
40
|
-
const itemTypeConversionsByTypeof = {};
|
|
41
|
-
if (this.itemType.typeofs.length === 1) {
|
|
42
|
-
itemTypeConversionsByTypeof[this.itemType.typeofs[0]] = {
|
|
43
|
-
conversionExpression: (value) => value,
|
|
44
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === ${this.itemType.typeofs[0]}`,
|
|
45
|
-
sourceTypeName: this.itemType.name,
|
|
46
|
-
sourceTypeof: this.itemType.typeofs[0],
|
|
47
|
-
};
|
|
48
|
-
for (const itemTypeConversion of this.itemType.conversions) {
|
|
49
|
-
if (!itemTypeConversionsByTypeof[itemTypeConversion.sourceTypeof]) {
|
|
50
|
-
itemTypeConversionsByTypeof[itemTypeConversion.sourceTypeof] =
|
|
51
|
-
itemTypeConversion;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
30
|
+
get conversionFunction() {
|
|
31
|
+
const itemConversionFunction = this.itemType.conversionFunction.orDefault(this.itemConversionFunctionDefault);
|
|
32
|
+
const sourceTypes = [
|
|
33
|
+
{
|
|
34
|
+
name: code `readonly (${joinCode(itemConversionFunction.sourceTypes.map((itemSourceType) => code `${itemSourceType.name}`), { on: " | " })})[]`,
|
|
35
|
+
typeof: "object",
|
|
36
|
+
},
|
|
37
|
+
];
|
|
55
38
|
if (this.minCount === 0n) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
conversions.push({
|
|
60
|
-
conversionExpression: (value) =>
|
|
61
|
-
// Defensive copy
|
|
62
|
-
code `${value}${this.mutable ? ".concat()" : ""}`,
|
|
63
|
-
sourceTypeCheckExpression: (value) => code `typeof ${value} === "object"`,
|
|
64
|
-
sourceTypeName: code `readonly (${this.itemType.name})[]`,
|
|
65
|
-
sourceTypeof: "object",
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// There were additional conversions with different item typeof's.
|
|
70
|
-
// We do .every (per above) to discriminate array types with different item typeof's and .map to convert the array at runtime.
|
|
71
|
-
for (const [itemTypeof, itemTypeofConversion] of Object.entries(itemTypeConversionsByTypeof)) {
|
|
72
|
-
const itemVariable = code `item`;
|
|
73
|
-
conversions.push({
|
|
74
|
-
conversionExpression: (value) => {
|
|
75
|
-
const itemTypeConversionExpression = itemTypeofConversion.conversionExpression(itemVariable);
|
|
76
|
-
return !codeEquals(itemTypeConversionExpression, itemVariable)
|
|
77
|
-
? code `${value}.map(item => ${itemTypeConversionExpression})`
|
|
78
|
-
: // Defensive copy
|
|
79
|
-
code `${value}${this.mutable ? ".concat()" : ""}`;
|
|
80
|
-
},
|
|
81
|
-
sourceTypeCheckExpression: (value) => {
|
|
82
|
-
switch (itemTypeof) {
|
|
83
|
-
case "bigint":
|
|
84
|
-
return code `${this.reusables.snippets.isReadonlyBigIntArray}(${value})`;
|
|
85
|
-
case "boolean":
|
|
86
|
-
return code `${this.reusables.snippets.isReadonlyBooleanArray}(${value})`;
|
|
87
|
-
case "number":
|
|
88
|
-
return code `${this.reusables.snippets.isReadonlyNumberArray}(${value})`;
|
|
89
|
-
case "object":
|
|
90
|
-
return code `${this.reusables.snippets.isReadonlyObjectArray}(${value})`;
|
|
91
|
-
case "string":
|
|
92
|
-
return code `${this.reusables.snippets.isReadonlyStringArray}(${value})`;
|
|
93
|
-
case "function":
|
|
94
|
-
case "symbol":
|
|
95
|
-
case "undefined":
|
|
96
|
-
throw new Error(`source type check on ${itemTypeof} not implemented`);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
sourceTypeName: code `readonly (${itemTypeofConversion.sourceTypeName})[]`,
|
|
100
|
-
sourceTypeof: itemTypeofConversion.sourceTypeof,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// minCount > 0
|
|
107
|
-
// Don't try to do any item type conversions here (yet).
|
|
108
|
-
conversions.push({
|
|
109
|
-
conversionExpression: (value) => value,
|
|
110
|
-
sourceTypeCheckExpression: (value) => code `${this.reusables.imports.NonEmptyList}.isNonEmpty(${value})`,
|
|
111
|
-
sourceTypeName: this.name,
|
|
112
|
-
sourceTypeof: "object",
|
|
39
|
+
sourceTypes.push({
|
|
40
|
+
name: "undefined",
|
|
41
|
+
typeof: "undefined",
|
|
113
42
|
});
|
|
114
43
|
}
|
|
115
|
-
return
|
|
44
|
+
return Maybe.of({
|
|
45
|
+
code: code `${this.reusables.snippets.convertToArray}(${itemConversionFunction.code}, ${literalOf(!this._mutable)})`,
|
|
46
|
+
sourceTypes,
|
|
47
|
+
});
|
|
116
48
|
}
|
|
117
49
|
get equalsFunction() {
|
|
118
50
|
return code `((left, right) => ${this.reusables.snippets.arrayEquals}(left, right, ${this.itemType.equalsFunction}))`;
|
|
@@ -126,21 +58,21 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
126
58
|
get graphqlType() {
|
|
127
59
|
return new AbstractContainerType.GraphqlType(code `new ${this.reusables.imports.GraphQLList}(${this.itemType.graphqlType.name})`, this.reusables);
|
|
128
60
|
}
|
|
61
|
+
get hashFunction() {
|
|
62
|
+
return code `${this.reusables.snippets.hashArray}(${this.itemType.hashFunction})`;
|
|
63
|
+
}
|
|
129
64
|
get mutable() {
|
|
130
65
|
return this._mutable || this.itemType.mutable;
|
|
131
66
|
}
|
|
132
67
|
get name() {
|
|
133
|
-
|
|
134
|
-
return code `(${this.itemType.name})[]`;
|
|
135
|
-
}
|
|
136
|
-
if (this.minCount === 0n) {
|
|
137
|
-
return code `readonly (${this.itemType.name})[]`;
|
|
138
|
-
}
|
|
139
|
-
return code `${this.reusables.imports.NonEmptyList}<${this.itemType.name}>`;
|
|
68
|
+
return code `${!this._mutable ? "readonly " : ""}(${this.itemType.name})[]`;
|
|
140
69
|
}
|
|
141
70
|
get schemaType() {
|
|
142
71
|
return code `${this.reusables.snippets.CollectionSchema}<${this.itemType.schemaType}>`;
|
|
143
72
|
}
|
|
73
|
+
get validationFunction() {
|
|
74
|
+
return Maybe.of(code `${this.reusables.snippets.validateArray}(${this.itemType.validationFunction.orDefault(this.itemValidationFunctionDefault)}, ${literalOf(!this._mutable)})`);
|
|
75
|
+
}
|
|
144
76
|
get schemaObject() {
|
|
145
77
|
return {
|
|
146
78
|
...super.schemaObject,
|
|
@@ -149,39 +81,16 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
149
81
|
}
|
|
150
82
|
fromJsonExpression({ variables, }) {
|
|
151
83
|
let expression = variables.value;
|
|
152
|
-
if (!this._mutable && this.minCount > 0n) {
|
|
153
|
-
expression = code `${this.reusables.imports.NonEmptyList}.fromArray(${expression}).unsafeCoerce()`;
|
|
154
|
-
}
|
|
155
84
|
if (this.minCount === 0n) {
|
|
156
85
|
expression = code `(${expression} ?? [])`;
|
|
157
86
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
return codeEquals(itemFromJsonExpression, valueVariable)
|
|
163
|
-
? expression
|
|
164
|
-
: code `${expression}.map(item => (${itemFromJsonExpression}))`;
|
|
87
|
+
return code `${this.reusables.imports.Either}.sequence<Error, ${this.itemType.name}>(${expression}.map(item => (${this.itemType.fromJsonExpression({
|
|
88
|
+
variables: { value: code `item` },
|
|
89
|
+
})})))`;
|
|
165
90
|
}
|
|
166
91
|
graphqlResolveExpression({ variables, }) {
|
|
167
92
|
return variables.value;
|
|
168
93
|
}
|
|
169
|
-
hashStatements({ depth, variables, }) {
|
|
170
|
-
return [
|
|
171
|
-
code `for (const item${depth} of ${variables.value}) { ${joinCode(this.itemType
|
|
172
|
-
.hashStatements({
|
|
173
|
-
depth: depth + 1,
|
|
174
|
-
variables: {
|
|
175
|
-
hasher: variables.hasher,
|
|
176
|
-
value: code `item${depth}`,
|
|
177
|
-
},
|
|
178
|
-
})
|
|
179
|
-
.concat())} }`,
|
|
180
|
-
];
|
|
181
|
-
}
|
|
182
|
-
jsonUiSchemaElement(parameters) {
|
|
183
|
-
return this.itemType.jsonUiSchemaElement(parameters);
|
|
184
|
-
}
|
|
185
94
|
jsonSchema(parameters) {
|
|
186
95
|
let schema = code `${this.itemType.jsonSchema(parameters)}.array()`;
|
|
187
96
|
if (this.minCount > 0n) {
|
|
@@ -195,13 +104,16 @@ export class AbstractCollectionType extends AbstractContainerType {
|
|
|
195
104
|
}
|
|
196
105
|
return schema;
|
|
197
106
|
}
|
|
107
|
+
jsonUiSchemaElement(parameters) {
|
|
108
|
+
return this.itemType.jsonUiSchemaElement(parameters);
|
|
109
|
+
}
|
|
198
110
|
toJsonExpression({ variables, }) {
|
|
199
111
|
return code `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: code `item` } })}))`;
|
|
200
112
|
}
|
|
201
113
|
}
|
|
202
114
|
__decorate([
|
|
203
115
|
Memoize()
|
|
204
|
-
], AbstractCollectionType.prototype, "
|
|
116
|
+
], AbstractCollectionType.prototype, "conversionFunction", null);
|
|
205
117
|
__decorate([
|
|
206
118
|
Memoize()
|
|
207
119
|
], AbstractCollectionType.prototype, "equalsFunction", null);
|
|
@@ -214,12 +126,18 @@ __decorate([
|
|
|
214
126
|
__decorate([
|
|
215
127
|
Memoize()
|
|
216
128
|
], AbstractCollectionType.prototype, "graphqlType", null);
|
|
129
|
+
__decorate([
|
|
130
|
+
Memoize()
|
|
131
|
+
], AbstractCollectionType.prototype, "hashFunction", null);
|
|
217
132
|
__decorate([
|
|
218
133
|
Memoize()
|
|
219
134
|
], AbstractCollectionType.prototype, "name", null);
|
|
220
135
|
__decorate([
|
|
221
136
|
Memoize()
|
|
222
137
|
], AbstractCollectionType.prototype, "schemaType", null);
|
|
138
|
+
__decorate([
|
|
139
|
+
Memoize()
|
|
140
|
+
], AbstractCollectionType.prototype, "validationFunction", null);
|
|
223
141
|
(function (AbstractCollectionType) {
|
|
224
142
|
AbstractCollectionType.GraphqlType = AbstractContainerType.GraphqlType;
|
|
225
143
|
AbstractCollectionType.isItemType = AbstractContainerType.isItemType;
|
|
@@ -38,13 +38,15 @@ export declare abstract class AbstractContainerType<ItemTypeT extends AbstractCo
|
|
|
38
38
|
get recursive(): boolean;
|
|
39
39
|
get schema(): Code;
|
|
40
40
|
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
41
|
+
protected get itemConversionFunctionDefault(): AbstractType.ConversionFunction;
|
|
42
|
+
protected get itemValidationFunctionDefault(): Code;
|
|
41
43
|
protected get schemaObject(): {
|
|
42
44
|
item: Code;
|
|
43
45
|
kind: Code;
|
|
44
46
|
};
|
|
45
47
|
}
|
|
46
48
|
export declare namespace AbstractContainerType {
|
|
47
|
-
type
|
|
49
|
+
type ConversionFunction = AbstractType.ConversionFunction;
|
|
48
50
|
type DiscriminantProperty = AbstractType.DiscriminantProperty;
|
|
49
51
|
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
50
52
|
type GraphqlType = AbstractType.GraphqlType;
|