@shaclmate/compiler 2.0.13 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Compiler.d.ts +15 -0
- package/Compiler.js +20 -0
- package/ShapesGraphToAstTransformer.d.ts +18 -23
- package/ShapesGraphToAstTransformer.js +21 -447
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.d.ts +3 -0
- package/_ShapesGraphToAstTransformer/NodeShapeAstType.js +2 -0
- package/_ShapesGraphToAstTransformer/index.d.ts +10 -0
- package/_ShapesGraphToAstTransformer/index.js +10 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/pickLiteral.js +18 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.d.ts +4 -0
- package/_ShapesGraphToAstTransformer/propertyShapeNodeKinds.js +26 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.d.ts +5 -0
- package/_ShapesGraphToAstTransformer/shapeAstName.js +28 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +165 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +13 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +198 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +29 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +12 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +43 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.d.ts +6 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +31 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +14 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +21 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +16 -0
- package/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +58 -0
- package/ast/Ast.d.ts +5 -0
- package/ast/CompositeType.d.ts +13 -0
- package/ast/CompositeType.js +2 -0
- package/ast/IdentifierType.d.ts +3 -6
- package/ast/IntersectionType.d.ts +2 -2
- package/ast/ListType.d.ts +53 -0
- package/ast/ListType.js +2 -0
- package/ast/LiteralType.d.ts +4 -3
- package/ast/Name.d.ts +1 -0
- package/ast/ObjectCompositeType.d.ts +22 -0
- package/ast/ObjectCompositeType.js +2 -0
- package/ast/ObjectIntersectionType.d.ts +8 -0
- package/ast/ObjectIntersectionType.js +2 -0
- package/ast/ObjectType.d.ts +91 -19
- package/ast/ObjectType.js +26 -1
- package/ast/ObjectUnionType.d.ts +19 -0
- package/ast/ObjectUnionType.js +2 -0
- package/ast/PlaceholderType.d.ts +7 -0
- package/ast/PlaceholderType.js +2 -0
- package/ast/SetType.d.ts +1 -1
- package/ast/TermType.d.ts +11 -0
- package/ast/TermType.js +2 -0
- package/ast/Type.d.ts +11 -3
- package/ast/UnionType.d.ts +3 -3
- package/ast/index.d.ts +6 -3
- package/ast/index.js +6 -3
- package/enums/MintingStrategy.d.ts +5 -0
- package/enums/MintingStrategy.js +2 -0
- package/enums/PropertyVisibility.d.ts +2 -0
- package/enums/PropertyVisibility.js +2 -0
- package/enums/TsFeature.d.ts +5 -0
- package/enums/TsFeature.js +16 -0
- package/enums/TsObjectDeclarationType.d.ts +5 -0
- package/enums/TsObjectDeclarationType.js +2 -0
- package/enums/index.d.ts +5 -0
- package/enums/index.js +5 -0
- package/generators/Generator.d.ts +5 -0
- package/generators/Generator.js +2 -0
- package/generators/index.d.ts +2 -2
- package/generators/index.js +2 -2
- package/generators/json/AstJsonGenerator.d.ts +4 -5
- package/generators/json/AstJsonGenerator.js +31 -22
- package/generators/ts/BooleanType.d.ts +7 -3
- package/generators/ts/BooleanType.js +58 -4
- package/generators/ts/DateTimeType.d.ts +17 -0
- package/generators/ts/DateTimeType.js +58 -0
- package/generators/ts/DeclaredType.d.ts +17 -0
- package/generators/ts/DeclaredType.js +10 -0
- package/generators/ts/IdentifierType.d.ts +7 -17
- package/generators/ts/IdentifierType.js +69 -60
- package/generators/ts/Import.d.ts +18 -0
- package/generators/ts/Import.js +59 -0
- package/generators/ts/ListType.d.ts +18 -8
- package/generators/ts/ListType.js +197 -43
- package/generators/ts/LiteralType.d.ts +13 -11
- package/generators/ts/LiteralType.js +36 -51
- package/generators/ts/NumberType.d.ts +7 -3
- package/generators/ts/NumberType.js +55 -4
- package/generators/ts/ObjectType.d.ts +47 -25
- package/generators/ts/ObjectType.js +222 -49
- package/generators/ts/ObjectUnionType.d.ts +58 -0
- package/generators/ts/ObjectUnionType.js +481 -0
- package/generators/ts/OptionType.d.ts +12 -4
- package/generators/ts/OptionType.js +65 -16
- package/generators/ts/PrimitiveType.d.ts +15 -5
- package/generators/ts/PrimitiveType.js +20 -29
- package/generators/ts/SetType.d.ts +12 -4
- package/generators/ts/SetType.js +103 -29
- package/generators/ts/StringType.d.ts +8 -3
- package/generators/ts/StringType.js +57 -3
- package/generators/ts/TermType.d.ts +52 -0
- package/generators/ts/TermType.js +234 -0
- package/generators/ts/TsGenerator.d.ts +4 -12
- package/generators/ts/TsGenerator.js +44 -100
- package/generators/ts/Type.d.ts +107 -46
- package/generators/ts/Type.js +78 -61
- package/generators/ts/TypeFactory.d.ts +4 -5
- package/generators/ts/TypeFactory.js +212 -89
- package/generators/ts/UnionType.d.ts +19 -6
- package/generators/ts/UnionType.js +230 -120
- package/generators/ts/_ObjectType/IdentifierProperty.d.ts +27 -7
- package/generators/ts/_ObjectType/IdentifierProperty.js +143 -31
- package/generators/ts/_ObjectType/Property.d.ts +125 -9
- package/generators/ts/_ObjectType/Property.js +25 -3
- package/generators/ts/_ObjectType/ShaclProperty.d.ts +23 -5
- package/generators/ts/_ObjectType/ShaclProperty.js +100 -26
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +24 -6
- package/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +75 -13
- package/generators/ts/_ObjectType/classDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/classDeclaration.js +79 -111
- package/generators/ts/_ObjectType/createFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/createFunctionDeclaration.js +60 -0
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.d.ts +2 -1
- package/generators/ts/_ObjectType/equalsFunctionDeclaration.js +12 -20
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +70 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +78 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +91 -0
- package/generators/ts/_ObjectType/hashFunctionDeclaration.d.ts +3 -3
- package/generators/ts/_ObjectType/hashFunctionDeclaration.js +11 -55
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.d.ts +11 -0
- package/generators/ts/_ObjectType/hashFunctionOrMethodDeclaration.js +64 -0
- package/generators/ts/_ObjectType/index.d.ts +8 -2
- package/generators/ts/_ObjectType/index.js +8 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/interfaceDeclaration.js +11 -2
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +31 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +37 -0
- package/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +6 -0
- package/generators/ts/{rdfjsTermExpression.js → _ObjectType/rdfjsTermExpression.js} +3 -1
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.d.ts +4 -0
- package/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +101 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +5 -0
- package/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +19 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +59 -0
- package/generators/ts/_ObjectType/toJsonReturnType.d.ts +3 -0
- package/generators/ts/_ObjectType/toJsonReturnType.js +19 -0
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +3 -2
- package/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +11 -45
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.d.ts +10 -0
- package/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +67 -0
- package/generators/ts/objectInitializer.d.ts +2 -0
- package/generators/ts/objectInitializer.js +14 -0
- package/generators/ts/tsComment.d.ts +5 -0
- package/generators/ts/tsComment.js +11 -0
- package/generators/ts/tsName.d.ts +1 -1
- package/generators/ts/tsName.js +1 -0
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/input/NodeShape.d.ts +46 -0
- package/input/NodeShape.js +165 -0
- package/input/Ontology.d.ts +13 -0
- package/input/Ontology.js +30 -0
- package/input/PropertyShape.d.ts +15 -0
- package/input/PropertyShape.js +34 -0
- package/input/Shape.d.ts +4 -0
- package/input/Shape.js +2 -0
- package/input/ShapesGraph.d.ts +9 -0
- package/input/ShapesGraph.js +50 -0
- package/input/ancestorClassIris.d.ts +4 -0
- package/input/ancestorClassIris.js +21 -0
- package/input/descendantClassIris.d.ts +4 -0
- package/input/descendantClassIris.js +21 -0
- package/input/generated.d.ts +274 -0
- package/input/generated.js +1420 -0
- package/input/index.d.ts +7 -0
- package/input/index.js +7 -0
- package/input/tsFeatures.d.ts +10 -0
- package/input/tsFeatures.js +42 -0
- package/package.json +14 -8
- package/ast/MintingStrategy.d.ts +0 -8
- package/ast/MintingStrategy.js +0 -9
- package/generators/ts/Configuration.d.ts +0 -29
- package/generators/ts/Configuration.js +0 -40
- package/generators/ts/IntersectionType.d.ts +0 -14
- package/generators/ts/IntersectionType.js +0 -26
- package/generators/ts/RdfjsTermType.d.ts +0 -25
- package/generators/ts/RdfjsTermType.js +0 -46
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/fromRdfFunctionDeclaration.js +0 -72
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.d.ts +0 -4
- package/generators/ts/_ObjectType/sparqlGraphPatternsClassDeclaration.js +0 -46
- package/generators/ts/rdfjsTermExpression.d.ts +0 -5
- package/vocabularies/dashDataset.d.ts +0 -3
- package/vocabularies/dashDataset.js +0 -2370
- package/vocabularies/index.d.ts +0 -2
- package/vocabularies/index.js +0 -2
- package/vocabularies/shaclmate.d.ts +0 -15
- package/vocabularies/shaclmate.js +0 -6
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
const variables = {
|
|
3
|
+
jsonObject: "_jsonObject",
|
|
4
|
+
};
|
|
5
|
+
export function fromJsonFunctionDeclarations() {
|
|
6
|
+
if (!this.features.has("fromJson")) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
if (this.extern) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const initializers = [];
|
|
13
|
+
const propertyReturnTypeSignatures = [];
|
|
14
|
+
const propertiesFromJsonFunctionReturnType = [];
|
|
15
|
+
const propertiesFromJsonFunctionStatements = [];
|
|
16
|
+
propertiesFromJsonFunctionStatements.push(`const _jsonSafeParseResult = ${this.jsonZodSchemaFunctionName}().safeParse(_json);`, "if (!_jsonSafeParseResult.success) { return purify.Left(_jsonSafeParseResult.error); }", `const ${variables.jsonObject} = _jsonSafeParseResult.data;`);
|
|
17
|
+
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
18
|
+
propertiesFromJsonFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromJson(${variables.jsonObject});`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
|
|
19
|
+
initializers.push(`..._super${parentObjectTypeI}`);
|
|
20
|
+
propertiesFromJsonFunctionReturnType.push(`purifyHelpers.Eithers.UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromJson>>`);
|
|
21
|
+
});
|
|
22
|
+
for (const property of this.properties) {
|
|
23
|
+
const propertyFromJsonStatements = property.fromJsonStatements({
|
|
24
|
+
variables,
|
|
25
|
+
});
|
|
26
|
+
if (propertyFromJsonStatements.length > 0) {
|
|
27
|
+
propertiesFromJsonFunctionStatements.push(...propertyFromJsonStatements);
|
|
28
|
+
initializers.push(property.name);
|
|
29
|
+
propertyReturnTypeSignatures.push(`${property.name}: ${property.type.name};`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
propertiesFromJsonFunctionStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
|
|
33
|
+
if (propertyReturnTypeSignatures.length > 0) {
|
|
34
|
+
propertiesFromJsonFunctionReturnType.splice(0, 0, `{ ${propertyReturnTypeSignatures.join(" ")} }`);
|
|
35
|
+
}
|
|
36
|
+
const fromJsonFunctionDeclarations = [];
|
|
37
|
+
fromJsonFunctionDeclarations.push({
|
|
38
|
+
isExported: true,
|
|
39
|
+
kind: StructureKind.Function,
|
|
40
|
+
name: "propertiesFromJson",
|
|
41
|
+
parameters: [
|
|
42
|
+
{
|
|
43
|
+
name: "_json",
|
|
44
|
+
type: "unknown",
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
returnType: `purify.Either<zod.ZodError, ${propertiesFromJsonFunctionReturnType.join(" & ")}>`,
|
|
48
|
+
statements: propertiesFromJsonFunctionStatements,
|
|
49
|
+
});
|
|
50
|
+
if (!this.abstract) {
|
|
51
|
+
let fromJsonStatements;
|
|
52
|
+
switch (this.declarationType) {
|
|
53
|
+
case "class":
|
|
54
|
+
fromJsonStatements = [
|
|
55
|
+
`return ${this.name}.propertiesFromJson(json).map(properties => new ${this.name}(properties));`,
|
|
56
|
+
];
|
|
57
|
+
break;
|
|
58
|
+
case "interface":
|
|
59
|
+
fromJsonStatements = [`return ${this.name}.propertiesFromJson(json);`];
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
fromJsonFunctionDeclarations.push({
|
|
63
|
+
isExported: true,
|
|
64
|
+
kind: StructureKind.Function,
|
|
65
|
+
name: "fromJson",
|
|
66
|
+
parameters: [
|
|
67
|
+
{
|
|
68
|
+
name: "json",
|
|
69
|
+
type: "unknown",
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
returnType: `purify.Either<zod.ZodError, ${this.name}>`,
|
|
73
|
+
statements: fromJsonStatements,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return fromJsonFunctionDeclarations;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=fromJsonFunctionDeclarations.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function fromRdfFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
|
|
4
|
+
//# sourceMappingURL=fromRdfFunctionDeclarations.d.ts.map
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { StructureKind } from "ts-morph";
|
|
2
|
+
import { objectInitializer } from "../objectInitializer.js";
|
|
3
|
+
const variables = {
|
|
4
|
+
context: "_context",
|
|
5
|
+
ignoreRdfType: "_ignoreRdfType",
|
|
6
|
+
languageIn: "_languageIn",
|
|
7
|
+
resource: "_resource",
|
|
8
|
+
};
|
|
9
|
+
export function fromRdfFunctionDeclarations() {
|
|
10
|
+
if (!this.features.has("fromRdf")) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
if (this.extern) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const initializers = [];
|
|
17
|
+
const propertySignatures = [];
|
|
18
|
+
const propertiesFromRdfFunctionReturnType = [];
|
|
19
|
+
const propertiesFromRdfFunctionStatements = [];
|
|
20
|
+
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
21
|
+
propertiesFromRdfFunctionStatements.push(`const _super${parentObjectTypeI}Either = ${parentObjectType.name}.propertiesFromRdf({ ...${variables.context}, ignoreRdfType: true, languageIn: ${variables.languageIn}, resource: ${variables.resource} });`, `if (_super${parentObjectTypeI}Either.isLeft()) { return _super${parentObjectTypeI}Either; }`, `const _super${parentObjectTypeI} = _super${parentObjectTypeI}Either.unsafeCoerce()`);
|
|
22
|
+
initializers.push(`..._super${parentObjectTypeI}`);
|
|
23
|
+
propertiesFromRdfFunctionReturnType.push(`purifyHelpers.Eithers.UnwrapR<ReturnType<typeof ${parentObjectType.name}.propertiesFromRdf>>`);
|
|
24
|
+
});
|
|
25
|
+
this.fromRdfType.ifJust((rdfType) => {
|
|
26
|
+
propertiesFromRdfFunctionStatements.push(`if (!${variables.ignoreRdfType} && !${variables.resource}.isInstanceOf(${this.rdfjsTermExpression(rdfType)})) { return purify.Left(new rdfjsResource.Resource.ValueError(${objectInitializer({ focusResource: variables.resource, message: `\`\${rdfjsResource.Resource.Identifier.toString(${variables.resource}.identifier)} has unexpected RDF type\``, predicate: this.rdfjsTermExpression(rdfType) })})); }`);
|
|
27
|
+
});
|
|
28
|
+
const propertyFromRdfVariables = {
|
|
29
|
+
context: variables.context,
|
|
30
|
+
languageIn: variables.languageIn,
|
|
31
|
+
resource: variables.resource,
|
|
32
|
+
};
|
|
33
|
+
for (const property of this.properties) {
|
|
34
|
+
const propertyFromRdfStatements = property.fromRdfStatements({
|
|
35
|
+
variables: propertyFromRdfVariables,
|
|
36
|
+
});
|
|
37
|
+
if (propertyFromRdfStatements.length > 0) {
|
|
38
|
+
propertiesFromRdfFunctionStatements.push(...propertyFromRdfStatements);
|
|
39
|
+
initializers.push(property.name);
|
|
40
|
+
propertySignatures.push(`${property.name}: ${property.type.name};`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
propertiesFromRdfFunctionStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
|
|
44
|
+
if (propertySignatures.length > 0) {
|
|
45
|
+
propertiesFromRdfFunctionReturnType.splice(0, 0, `{ ${propertySignatures.join(" ")} }`);
|
|
46
|
+
}
|
|
47
|
+
const fromRdfFunctionDeclarations = [];
|
|
48
|
+
fromRdfFunctionDeclarations.push({
|
|
49
|
+
isExported: true,
|
|
50
|
+
kind: StructureKind.Function,
|
|
51
|
+
name: "propertiesFromRdf",
|
|
52
|
+
parameters: [
|
|
53
|
+
{
|
|
54
|
+
name: `{ ignoreRdfType: ${variables.ignoreRdfType}, languageIn: ${variables.languageIn}, resource: ${variables.resource},\n// @ts-ignore\n...${variables.context} }`,
|
|
55
|
+
type: `{ [_index: string]: any; ignoreRdfType?: boolean; languageIn?: readonly string[]; resource: ${this.rdfjsResourceType().name}; }`,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${propertiesFromRdfFunctionReturnType.join(" & ")}>`,
|
|
59
|
+
statements: propertiesFromRdfFunctionStatements,
|
|
60
|
+
});
|
|
61
|
+
if (!this.abstract) {
|
|
62
|
+
let fromRdfStatements;
|
|
63
|
+
switch (this.declarationType) {
|
|
64
|
+
case "class":
|
|
65
|
+
fromRdfStatements = [
|
|
66
|
+
`return ${this.name}.propertiesFromRdf(parameters).map(properties => new ${this.name}(properties));`,
|
|
67
|
+
];
|
|
68
|
+
break;
|
|
69
|
+
case "interface":
|
|
70
|
+
fromRdfStatements = [
|
|
71
|
+
`return ${this.name}.propertiesFromRdf(parameters);`,
|
|
72
|
+
];
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
fromRdfFunctionDeclarations.push({
|
|
76
|
+
isExported: true,
|
|
77
|
+
kind: StructureKind.Function,
|
|
78
|
+
name: "fromRdf",
|
|
79
|
+
parameters: [
|
|
80
|
+
{
|
|
81
|
+
name: "parameters",
|
|
82
|
+
type: `Parameters<typeof ${this.name}.propertiesFromRdf>[0]`,
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
returnType: `purify.Either<rdfjsResource.Resource.ValueError, ${this.name}>`,
|
|
86
|
+
statements: fromRdfStatements,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return fromRdfFunctionDeclarations;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=fromRdfFunctionDeclarations.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
1
2
|
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
-
import type { ObjectType } from "../ObjectType";
|
|
3
|
-
export declare
|
|
4
|
-
export declare function hashFunctionDeclaration(this: ObjectType): FunctionDeclarationStructure;
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function hashFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
|
|
5
5
|
//# sourceMappingURL=hashFunctionDeclaration.d.ts.map
|
|
@@ -1,64 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
2
|
import { StructureKind } from "ts-morph";
|
|
3
|
-
|
|
4
|
-
export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
3
|
+
import { hashFunctionOrMethodDeclaration } from "./hashFunctionOrMethodDeclaration.js";
|
|
5
4
|
export function hashFunctionDeclaration() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
omitPropertyNamesSet.add(this.configuration.objectTypeIdentifierPropertyName);
|
|
9
|
-
omitPropertyNamesSet.add(this.configuration.objectTypeDiscriminatorPropertyName);
|
|
10
|
-
if (this.configuration.objectTypeDeclarationType === "class") {
|
|
11
|
-
omitPropertyNamesSet.add("equals");
|
|
12
|
-
omitPropertyNamesSet.add("hash");
|
|
13
|
-
omitPropertyNamesSet.add("toRdf");
|
|
5
|
+
if (this.declarationType !== "interface") {
|
|
6
|
+
return Maybe.empty();
|
|
14
7
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
statements.push(`${parentObjectType.name}.${parentObjectType.hashFunctionName}(${thisVariable}, ${hasherVariable})`);
|
|
8
|
+
if (this.extern) {
|
|
9
|
+
return Maybe.empty();
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
hasher: hasherVariable,
|
|
24
|
-
value: propertyValueVariable,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
if (propertyHashStatements.length === 0) {
|
|
28
|
-
omitPropertyNamesSet.add(property.name);
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
if (property.name === this.configuration.objectTypeIdentifierPropertyName) {
|
|
32
|
-
// Don't hash the identifier since we may be using hash to calculate the identifier, leading to infinite recursion
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
statements.push(...propertyHashStatements);
|
|
36
|
-
}
|
|
37
|
-
const omitPropertyNames = [...omitPropertyNamesSet];
|
|
38
|
-
omitPropertyNames.sort();
|
|
39
|
-
statements.push(`return ${hasherVariable};`);
|
|
40
|
-
return {
|
|
11
|
+
return hashFunctionOrMethodDeclaration
|
|
12
|
+
.bind(this)()
|
|
13
|
+
.map((hashFunctionOrMethodDeclaration) => ({
|
|
14
|
+
...hashFunctionOrMethodDeclaration,
|
|
41
15
|
isExported: true,
|
|
42
16
|
kind: StructureKind.Function,
|
|
43
17
|
name: this.hashFunctionName,
|
|
44
|
-
|
|
45
|
-
{
|
|
46
|
-
name: thisVariable,
|
|
47
|
-
type: `Omit<${this.name}, ${omitPropertyNames.map((propertyName) => `"${propertyName}"`).join(" | ")}>`,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: hasherVariable,
|
|
51
|
-
type: "HasherT",
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
returnType: "HasherT",
|
|
55
|
-
statements,
|
|
56
|
-
typeParameters: [
|
|
57
|
-
{
|
|
58
|
-
name: "HasherT",
|
|
59
|
-
constraint: hasherTypeConstraint,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
};
|
|
18
|
+
}));
|
|
63
19
|
}
|
|
64
20
|
//# sourceMappingURL=hashFunctionDeclaration.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { OptionalKind, ParameterDeclarationStructure, TypeParameterDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
5
|
+
export declare function hashFunctionOrMethodDeclaration(this: ObjectType): Maybe<{
|
|
6
|
+
parameters: OptionalKind<ParameterDeclarationStructure>[];
|
|
7
|
+
returnType: string;
|
|
8
|
+
statements: string[];
|
|
9
|
+
typeParameters: OptionalKind<TypeParameterDeclarationStructure>[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=hashFunctionOrMethodDeclaration.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
const hasherVariable = "_hasher";
|
|
3
|
+
export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
4
|
+
export function hashFunctionOrMethodDeclaration() {
|
|
5
|
+
if (!this.features.has("hash")) {
|
|
6
|
+
return Maybe.empty();
|
|
7
|
+
}
|
|
8
|
+
const propertyHashStatements = this.properties.flatMap((property) => property.hashStatements({
|
|
9
|
+
depth: 0,
|
|
10
|
+
variables: {
|
|
11
|
+
hasher: hasherVariable,
|
|
12
|
+
value: `${this.thisVariable}.${property.name}`,
|
|
13
|
+
},
|
|
14
|
+
}));
|
|
15
|
+
if (this.declarationType === "class" &&
|
|
16
|
+
this.parentObjectTypes.length > 0 &&
|
|
17
|
+
propertyHashStatements.length === 0) {
|
|
18
|
+
// If there's a parent class and no hash statements in this class, can skip overriding hash
|
|
19
|
+
return Maybe.empty();
|
|
20
|
+
}
|
|
21
|
+
const parameters = [];
|
|
22
|
+
if (this.declarationType === "interface") {
|
|
23
|
+
parameters.push({
|
|
24
|
+
name: this.thisVariable,
|
|
25
|
+
type: this.name,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
parameters.push({
|
|
29
|
+
name: hasherVariable,
|
|
30
|
+
type: "HasherT",
|
|
31
|
+
});
|
|
32
|
+
const statements = [];
|
|
33
|
+
let hasOverrideKeyword = false;
|
|
34
|
+
if (this.parentObjectTypes.length > 0) {
|
|
35
|
+
switch (this.declarationType) {
|
|
36
|
+
case "class": {
|
|
37
|
+
statements.push(`super.hash(${hasherVariable});`);
|
|
38
|
+
hasOverrideKeyword = true;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case "interface": {
|
|
42
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
43
|
+
statements.push(`${parentObjectType.name}.${parentObjectType.hashFunctionName}(${this.thisVariable}, ${hasherVariable});`);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
statements.push(...propertyHashStatements);
|
|
50
|
+
statements.push(`return ${hasherVariable};`);
|
|
51
|
+
return Maybe.of({
|
|
52
|
+
hasOverrideKeyword,
|
|
53
|
+
parameters,
|
|
54
|
+
returnType: "HasherT",
|
|
55
|
+
statements,
|
|
56
|
+
typeParameters: [
|
|
57
|
+
{
|
|
58
|
+
name: "HasherT",
|
|
59
|
+
constraint: hasherTypeConstraint,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=hashFunctionOrMethodDeclaration.js.map
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export * from "./classDeclaration.js";
|
|
2
|
+
export * from "./createFunctionDeclaration.js";
|
|
2
3
|
export * from "./equalsFunctionDeclaration.js";
|
|
3
|
-
export * from "./
|
|
4
|
+
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
|
+
export * from "./fromRdfFunctionDeclarations.js";
|
|
4
6
|
export * from "./hashFunctionDeclaration.js";
|
|
5
7
|
export * from "./IdentifierProperty.js";
|
|
6
8
|
export * from "./interfaceDeclaration.js";
|
|
9
|
+
export * from "./jsonSchemaFunctionDeclaration.js";
|
|
10
|
+
export * from "./jsonUiSchemaFunctionDeclaration.js";
|
|
11
|
+
export * from "./jsonZodSchemaFunctionDeclaration.js";
|
|
7
12
|
export * from "./Property.js";
|
|
8
13
|
export * from "./ShaclProperty.js";
|
|
9
|
-
export * from "./
|
|
14
|
+
export * from "./sparqlFunctionDeclarations.js";
|
|
15
|
+
export * from "./toJsonFunctionDeclaration.js";
|
|
10
16
|
export * from "./toRdfFunctionDeclaration.js";
|
|
11
17
|
export * from "./TypeDiscriminatorProperty.js";
|
|
12
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
export * from "./classDeclaration.js";
|
|
2
|
+
export * from "./createFunctionDeclaration.js";
|
|
2
3
|
export * from "./equalsFunctionDeclaration.js";
|
|
3
|
-
export * from "./
|
|
4
|
+
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
|
+
export * from "./fromRdfFunctionDeclarations.js";
|
|
4
6
|
export * from "./hashFunctionDeclaration.js";
|
|
5
7
|
export * from "./IdentifierProperty.js";
|
|
6
8
|
export * from "./interfaceDeclaration.js";
|
|
9
|
+
export * from "./jsonSchemaFunctionDeclaration.js";
|
|
10
|
+
export * from "./jsonUiSchemaFunctionDeclaration.js";
|
|
11
|
+
export * from "./jsonZodSchemaFunctionDeclaration.js";
|
|
7
12
|
export * from "./Property.js";
|
|
8
13
|
export * from "./ShaclProperty.js";
|
|
9
|
-
export * from "./
|
|
14
|
+
export * from "./sparqlFunctionDeclarations.js";
|
|
15
|
+
export * from "./toJsonFunctionDeclaration.js";
|
|
10
16
|
export * from "./toRdfFunctionDeclaration.js";
|
|
11
17
|
export * from "./TypeDiscriminatorProperty.js";
|
|
12
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
1
2
|
import { type InterfaceDeclarationStructure } from "ts-morph";
|
|
2
|
-
import type { ObjectType } from "../ObjectType";
|
|
3
|
-
export declare function interfaceDeclaration(this: ObjectType): InterfaceDeclarationStructure
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function interfaceDeclaration(this: ObjectType): Maybe<InterfaceDeclarationStructure>;
|
|
4
5
|
//# sourceMappingURL=interfaceDeclaration.d.ts.map
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
1
2
|
import { StructureKind, } from "ts-morph";
|
|
3
|
+
import { tsComment } from "../tsComment.js";
|
|
2
4
|
export function interfaceDeclaration() {
|
|
5
|
+
if (this.declarationType !== "interface") {
|
|
6
|
+
return Maybe.empty();
|
|
7
|
+
}
|
|
8
|
+
if (this.extern) {
|
|
9
|
+
return Maybe.empty();
|
|
10
|
+
}
|
|
3
11
|
const properties = this.properties.map((property) => property.interfacePropertySignature);
|
|
4
|
-
return {
|
|
12
|
+
return Maybe.of({
|
|
5
13
|
extends: this.parentObjectTypes.map((parentObjectType) => parentObjectType.name),
|
|
6
14
|
isExported: true,
|
|
7
15
|
kind: StructureKind.Interface,
|
|
16
|
+
leadingTrivia: this.comment.alt(this.label).map(tsComment).extract(),
|
|
8
17
|
name: this.name,
|
|
9
18
|
properties,
|
|
10
|
-
};
|
|
19
|
+
});
|
|
11
20
|
}
|
|
12
21
|
//# sourceMappingURL=interfaceDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function jsonSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
|
|
5
|
+
//# sourceMappingURL=jsonSchemaFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
export function jsonSchemaFunctionDeclaration() {
|
|
4
|
+
if (!this.features.has("jsonSchema")) {
|
|
5
|
+
return Maybe.empty();
|
|
6
|
+
}
|
|
7
|
+
if (this.extern) {
|
|
8
|
+
return Maybe.empty();
|
|
9
|
+
}
|
|
10
|
+
return Maybe.of({
|
|
11
|
+
isExported: true,
|
|
12
|
+
kind: StructureKind.Function,
|
|
13
|
+
name: "jsonSchema",
|
|
14
|
+
statements: [
|
|
15
|
+
`return zodToJsonSchema(${this.jsonZodSchemaFunctionName}());`,
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=jsonSchemaFunctionDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function jsonUiSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
|
|
5
|
+
//# sourceMappingURL=jsonUiSchemaFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
export function jsonUiSchemaFunctionDeclaration() {
|
|
4
|
+
if (!this.features.has("jsonUiSchema")) {
|
|
5
|
+
return Maybe.empty();
|
|
6
|
+
}
|
|
7
|
+
if (this.extern) {
|
|
8
|
+
return Maybe.empty();
|
|
9
|
+
}
|
|
10
|
+
const variables = { scopePrefix: "scopePrefix" };
|
|
11
|
+
const elements = this.parentObjectTypes
|
|
12
|
+
.map((parentObjectType) => `${parentObjectType.name}.${parentObjectType.jsonUiSchemaFunctionName}({ scopePrefix })`)
|
|
13
|
+
.concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
|
|
14
|
+
return Maybe.of({
|
|
15
|
+
isExported: true,
|
|
16
|
+
kind: StructureKind.Function,
|
|
17
|
+
name: this.jsonUiSchemaFunctionName,
|
|
18
|
+
parameters: [
|
|
19
|
+
{
|
|
20
|
+
hasQuestionToken: true,
|
|
21
|
+
name: "parameters",
|
|
22
|
+
type: "{ scopePrefix?: string }",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
statements: [
|
|
26
|
+
'const scopePrefix = parameters?.scopePrefix ?? "#";',
|
|
27
|
+
`return { "elements": [ ${elements.join(", ")} ], label: "${this.label.orDefault(this.name)}", type: "Group" }`,
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=jsonUiSchemaFunctionDeclaration.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function jsonZodSchemaFunctionDeclaration(this: ObjectType): Maybe<FunctionDeclarationStructure>;
|
|
5
|
+
//# sourceMappingURL=jsonZodSchemaFunctionDeclaration.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
export function jsonZodSchemaFunctionDeclaration() {
|
|
4
|
+
if (!this.features.has("fromJson") && !this.features.has("jsonSchema")) {
|
|
5
|
+
return Maybe.empty();
|
|
6
|
+
}
|
|
7
|
+
if (this.extern) {
|
|
8
|
+
return Maybe.empty();
|
|
9
|
+
}
|
|
10
|
+
const variables = { zod: "zod" };
|
|
11
|
+
const mergeZodObjectSchemas = [];
|
|
12
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
13
|
+
mergeZodObjectSchemas.push(`${parentObjectType.jsonZodSchema({ variables })}`);
|
|
14
|
+
}
|
|
15
|
+
if (this.properties.length > 0) {
|
|
16
|
+
mergeZodObjectSchemas.push(`${variables.zod}.object({ ${this.properties
|
|
17
|
+
.map((property) => property.jsonZodSchema({ variables }))
|
|
18
|
+
.map(({ key, schema }) => `"${key}": ${schema}`)
|
|
19
|
+
.join(",")} })`);
|
|
20
|
+
}
|
|
21
|
+
return Maybe.of({
|
|
22
|
+
isExported: true,
|
|
23
|
+
kind: StructureKind.Function,
|
|
24
|
+
name: this.jsonZodSchemaFunctionName,
|
|
25
|
+
statements: [
|
|
26
|
+
`return ${mergeZodObjectSchemas.length > 0
|
|
27
|
+
? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
|
|
28
|
+
if (merged.length === 0) {
|
|
29
|
+
return zodObjectSchema;
|
|
30
|
+
}
|
|
31
|
+
return `${merged}.merge(${zodObjectSchema})`;
|
|
32
|
+
}, "")
|
|
33
|
+
: `${variables.zod}.object()`};`,
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=jsonZodSchemaFunctionDeclaration.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
|
|
2
|
+
export declare function rdfjsTermExpression({ dataFactoryVariable, rdfjsTerm, }: {
|
|
3
|
+
dataFactoryVariable: string;
|
|
4
|
+
rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">;
|
|
5
|
+
}): string;
|
|
6
|
+
//# sourceMappingURL=rdfjsTermExpression.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
2
|
-
export function rdfjsTermExpression(
|
|
2
|
+
export function rdfjsTermExpression({ dataFactoryVariable, rdfjsTerm, }) {
|
|
3
3
|
switch (rdfjsTerm.termType) {
|
|
4
4
|
case "BlankNode":
|
|
5
5
|
return `${dataFactoryVariable}.blankNode("${rdfjsTerm.value}")`;
|
|
@@ -10,6 +10,8 @@ export function rdfjsTermExpression(rdfjsTerm, { dataFactoryVariable }) {
|
|
|
10
10
|
return `${dataFactoryVariable}.literal("${rdfjsTerm.value}", ${dataFactoryVariable}.namedNode("${rdfjsTerm.datatype.value}"))`;
|
|
11
11
|
case "NamedNode":
|
|
12
12
|
return `${dataFactoryVariable}.namedNode("${rdfjsTerm.value}")`;
|
|
13
|
+
case "Variable":
|
|
14
|
+
return `${dataFactoryVariable}.variable!("${rdfjsTerm.value}")`;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
//# sourceMappingURL=rdfjsTermExpression.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function sparqlFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
|
|
4
|
+
//# sourceMappingURL=sparqlFunctionDeclarations.d.ts.map
|