@shaclmate/compiler 2.0.22 → 2.0.23
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 +1 -0
- package/dist/ShapesGraphToAstTransformer.js +56 -12
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/flattenAstObjectCompositeTypeMemberTypes.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/shapeAstName.js +53 -12
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.d.ts +5 -0
- package/dist/_ShapesGraphToAstTransformer/transformNodeShapeToAstType.js +130 -54
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +2 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +122 -129
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +2 -2
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +127 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +3 -3
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +2 -3
- package/dist/ast/Ast.d.ts +0 -1
- package/dist/ast/Curie.d.ts +14 -0
- package/dist/ast/Curie.js +21 -0
- package/dist/ast/IdentifierType.d.ts +3 -2
- package/dist/ast/ListType.d.ts +2 -1
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/Name.d.ts +40 -5
- package/dist/ast/ObjectCompositeType.d.ts +11 -0
- package/dist/ast/ObjectType.d.ts +18 -13
- package/dist/ast/ObjectUnionType.d.ts +0 -11
- package/dist/ast/OptionType.d.ts +2 -2
- package/dist/ast/SetType.d.ts +2 -2
- package/dist/ast/TermType.d.ts +12 -4
- package/dist/ast/Type.d.ts +1 -1
- package/dist/enums/TsFeature.d.ts +1 -4
- package/dist/enums/TsFeature.js +1 -15
- package/dist/generators/json/AstJsonGenerator.js +19 -3
- package/dist/generators/ts/BooleanType.d.ts +3 -1
- package/dist/generators/ts/BooleanType.js +11 -2
- package/dist/generators/ts/DateTimeType.d.ts +8 -7
- package/dist/generators/ts/DateTimeType.js +31 -7
- package/dist/generators/ts/DateType.d.ts +5 -2
- package/dist/generators/ts/DateType.js +15 -1
- package/dist/generators/ts/DeclaredType.d.ts +2 -2
- package/dist/generators/ts/DeclaredType.js +2 -2
- package/dist/generators/ts/FloatType.d.ts +6 -0
- package/dist/generators/ts/FloatType.js +18 -0
- package/dist/generators/ts/IdentifierType.d.ts +12 -7
- package/dist/generators/ts/IdentifierType.js +94 -6
- package/dist/generators/ts/Import.d.ts +2 -0
- package/dist/generators/ts/Import.js +10 -0
- package/dist/generators/ts/IntType.d.ts +6 -0
- package/dist/generators/ts/IntType.js +18 -0
- package/dist/generators/ts/ListType.d.ts +15 -12
- package/dist/generators/ts/ListType.js +98 -57
- package/dist/generators/ts/LiteralType.d.ts +10 -9
- package/dist/generators/ts/LiteralType.js +13 -2
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +7 -2
- package/dist/generators/ts/ObjectType.d.ts +66 -43
- package/dist/generators/ts/ObjectType.js +144 -123
- package/dist/generators/ts/ObjectUnionType.d.ts +49 -8
- package/dist/generators/ts/ObjectUnionType.js +290 -97
- package/dist/generators/ts/OptionType.d.ts +14 -10
- package/dist/generators/ts/OptionType.js +60 -34
- package/dist/generators/ts/PrimitiveType.d.ts +4 -4
- package/dist/generators/ts/PrimitiveType.js +18 -3
- package/dist/generators/ts/SetType.d.ts +16 -12
- package/dist/generators/ts/SetType.js +69 -40
- package/dist/generators/ts/SnippetDeclarations.d.ts +13 -8
- package/dist/generators/ts/SnippetDeclarations.js +215 -101
- package/dist/generators/ts/StringType.d.ts +3 -1
- package/dist/generators/ts/StringType.js +14 -2
- package/dist/generators/ts/TermType.d.ts +22 -14
- package/dist/generators/ts/TermType.js +53 -25
- package/dist/generators/ts/TsGenerator.d.ts +2 -1
- package/dist/generators/ts/TsGenerator.js +23 -12
- package/dist/generators/ts/Type.d.ts +89 -31
- package/dist/generators/ts/Type.js +57 -54
- package/dist/generators/ts/TypeFactory.d.ts +4 -5
- package/dist/generators/ts/TypeFactory.js +290 -226
- package/dist/generators/ts/UnionType.d.ts +14 -10
- package/dist/generators/ts/UnionType.js +319 -142
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.d.ts +12 -0
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +30 -0
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +13 -12
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +46 -47
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +20 -13
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +152 -124
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +87 -0
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +237 -0
- package/dist/generators/ts/_ObjectType/Property.d.ts +39 -44
- package/dist/generators/ts/_ObjectType/Property.js +1 -10
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +25 -30
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +108 -85
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +21 -17
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +61 -53
- package/dist/generators/ts/_ObjectType/classDeclaration.js +6 -5
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +5 -4
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/fromRdfTypeVariableStatement.js +8 -5
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/hashFunctionOrMethodDeclarations.js +7 -8
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +7 -0
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.js +54 -0
- package/dist/generators/ts/_ObjectType/index.d.ts +9 -7
- package/dist/generators/ts/_ObjectType/index.js +9 -7
- package/dist/generators/ts/_ObjectType/interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +189 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/jsonTypeAliasDeclaration.js +28 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/_ObjectType/objectSetMethodNames.js +18 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.d.ts +5 -0
- package/dist/generators/ts/_ObjectType/propertiesVariableStatement.js +37 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.d.ts +4 -0
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +152 -0
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +4 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +3 -2
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +103 -35
- package/dist/generators/ts/_ObjectType/toJsonFunctionOrMethodDeclaration.js +6 -6
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +15 -13
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +9 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +86 -0
- package/dist/generators/ts/objectSetDeclarations.d.ts +8 -0
- package/dist/generators/ts/objectSetDeclarations.js +59 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +8 -0
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +46 -0
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +11 -0
- package/dist/generators/ts/objectSetMethodSignatures.js +52 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +393 -0
- package/dist/generators/ts/rdfjsTermExpression.d.ts +3 -0
- package/dist/generators/ts/rdfjsTermExpression.js +57 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +415 -0
- package/dist/generators/ts/syntheticNamePrefix.d.ts +2 -0
- package/dist/generators/ts/syntheticNamePrefix.js +2 -0
- package/dist/generators/ts/tsName.js +27 -13
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +10 -0
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +19 -0
- package/dist/input/NodeShape.d.ts +6 -8
- package/dist/input/NodeShape.js +20 -44
- package/dist/input/Ontology.d.ts +0 -3
- package/dist/input/Ontology.js +0 -9
- package/dist/input/PropertyPath.d.ts +6 -5
- package/dist/input/PropertyPath.js +14 -22
- package/dist/input/PropertyShape.d.ts +3 -1
- package/dist/input/PropertyShape.js +8 -2
- package/dist/input/ShapesGraph.js +4 -4
- package/dist/input/generated.d.ts +923 -105
- package/dist/input/generated.js +1865 -969
- package/dist/input/tsFeatures.d.ts +3 -2
- package/dist/input/tsFeatures.js +44 -27
- package/package.json +18 -16
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromJsonFunctionDeclarations.js +0 -78
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/fromRdfFunctionDeclarations.js +0 -91
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonSchemaFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonUiSchemaFunctionDeclaration.js +0 -31
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/jsonZodSchemaFunctionDeclaration.js +0 -37
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.d.ts +0 -6
- package/dist/generators/ts/_ObjectType/rdfjsTermExpression.js +0 -17
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/toJsonReturnType.d.ts +0 -3
- package/dist/generators/ts/_ObjectType/toJsonReturnType.js +0 -17
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/toRdfFunctionDeclaration.js +0 -19
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type VariableStatementStructure } from "ts-morph";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function graphqlTypeVariableStatement(this: ObjectType): Maybe<VariableStatementStructure>;
|
|
5
|
+
//# sourceMappingURL=graphqlTypeVariableStatement.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StructureKind, VariableDeclarationKind, } from "ts-morph";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import { objectInitializer } from "../objectInitializer.js";
|
|
4
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
5
|
+
export function graphqlTypeVariableStatement() {
|
|
6
|
+
if (!this.features.has("graphql")) {
|
|
7
|
+
return Maybe.empty();
|
|
8
|
+
}
|
|
9
|
+
if (this.extern) {
|
|
10
|
+
return Maybe.empty();
|
|
11
|
+
}
|
|
12
|
+
if (this.synthetic) {
|
|
13
|
+
return Maybe.empty();
|
|
14
|
+
}
|
|
15
|
+
return Maybe.of({
|
|
16
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
17
|
+
kind: StructureKind.VariableStatement,
|
|
18
|
+
declarations: [
|
|
19
|
+
{
|
|
20
|
+
name: `${syntheticNamePrefix}GraphQL`,
|
|
21
|
+
initializer: `new graphql.GraphQLObjectType<${this.name}, { objectSet: ${syntheticNamePrefix}ObjectSet }>(${objectInitializer({
|
|
22
|
+
description: this.comment.map(JSON.stringify).extract(),
|
|
23
|
+
fields: `() => (${objectInitializer(this.properties.reduce((fields, property) => {
|
|
24
|
+
property.graphqlField.ifJust((field) => {
|
|
25
|
+
const { name: fieldName, ...fieldProps } = field;
|
|
26
|
+
fields[fieldName] = objectInitializer(fieldProps);
|
|
27
|
+
});
|
|
28
|
+
return fields;
|
|
29
|
+
}, {}))})`,
|
|
30
|
+
name: `"${this.name}"`,
|
|
31
|
+
})})`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isExported: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=graphqlTypeVariableStatement.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Scope, } from "ts-morph";
|
|
2
2
|
import { ObjectType } from "../ObjectType.js";
|
|
3
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
4
|
const hasherVariable = "_hasher";
|
|
4
5
|
export const hasherTypeConstraint = "{ update: (message: string | number[] | ArrayBuffer | Uint8Array) => void; }";
|
|
5
6
|
export function hashFunctionOrMethodDeclarations() {
|
|
@@ -35,13 +36,13 @@ export function hashFunctionOrMethodDeclarations() {
|
|
|
35
36
|
if (this.parentObjectTypes.length > 0) {
|
|
36
37
|
switch (this.declarationType) {
|
|
37
38
|
case "class": {
|
|
38
|
-
hashShaclPropertiesStatements.push(`super
|
|
39
|
+
hashShaclPropertiesStatements.push(`super.${syntheticNamePrefix}hashShaclProperties(${hasherVariable});`);
|
|
39
40
|
hasOverrideKeyword = true;
|
|
40
41
|
break;
|
|
41
42
|
}
|
|
42
43
|
case "interface": {
|
|
43
44
|
for (const parentObjectType of this.parentObjectTypes) {
|
|
44
|
-
hashShaclPropertiesStatements.push(`${parentObjectType.
|
|
45
|
+
hashShaclPropertiesStatements.push(`${parentObjectType.staticModuleName}.${syntheticNamePrefix}hashShaclProperties(${this.thisVariable}, ${hasherVariable});`);
|
|
45
46
|
}
|
|
46
47
|
break;
|
|
47
48
|
}
|
|
@@ -58,7 +59,7 @@ export function hashFunctionOrMethodDeclarations() {
|
|
|
58
59
|
return [
|
|
59
60
|
{
|
|
60
61
|
hasOverrideKeyword,
|
|
61
|
-
name:
|
|
62
|
+
name: `${syntheticNamePrefix}hash`,
|
|
62
63
|
parameters,
|
|
63
64
|
returnType,
|
|
64
65
|
statements: [
|
|
@@ -72,17 +73,15 @@ export function hashFunctionOrMethodDeclarations() {
|
|
|
72
73
|
},
|
|
73
74
|
})),
|
|
74
75
|
this.declarationType === "class"
|
|
75
|
-
? `this
|
|
76
|
-
: `${this.
|
|
76
|
+
? `this.${syntheticNamePrefix}hashShaclProperties(${hasherVariable});`
|
|
77
|
+
: `${this.staticModuleName}.${syntheticNamePrefix}hashShaclProperties(${this.thisVariable}, ${hasherVariable});`,
|
|
77
78
|
`return ${hasherVariable};`,
|
|
78
79
|
],
|
|
79
80
|
typeParameters,
|
|
80
81
|
},
|
|
81
82
|
{
|
|
82
83
|
hasOverrideKeyword,
|
|
83
|
-
name:
|
|
84
|
-
? "hashShaclProperties"
|
|
85
|
-
: this.hashShaclPropertiesFunctionName,
|
|
84
|
+
name: `${syntheticNamePrefix}hashShaclProperties`,
|
|
86
85
|
parameters,
|
|
87
86
|
returnType,
|
|
88
87
|
scope: this.declarationType === "class" ? Scope.Protected : undefined,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type VariableStatementStructure } from "ts-morph";
|
|
2
|
+
import { type FunctionDeclarationStructure, type ModuleDeclarationStructure, type TypeAliasDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
type IdentifierTypeDeclarations = readonly (FunctionDeclarationStructure | ModuleDeclarationStructure | TypeAliasDeclarationStructure | VariableStatementStructure)[];
|
|
5
|
+
export declare function identifierTypeDeclarations(this: ObjectType): IdentifierTypeDeclarations;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=identifierTypeDeclarations.d.ts.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { VariableDeclarationKind, } from "ts-morph";
|
|
2
|
+
import { StructureKind, } from "ts-morph";
|
|
3
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
4
|
+
export function identifierTypeDeclarations() {
|
|
5
|
+
if (this.extern) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
const ancestorObjectTypeWithSameIdentifierType = this.ancestorObjectTypes.find((ancestorObjectType) => ancestorObjectType.identifierType.name === this.identifierType.name);
|
|
9
|
+
if (ancestorObjectTypeWithSameIdentifierType) {
|
|
10
|
+
return reExportAncestorIdentifierTypeDeclarations(ancestorObjectTypeWithSameIdentifierType);
|
|
11
|
+
}
|
|
12
|
+
// Bespoke identifier type and associated functions
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
isExported: true,
|
|
16
|
+
kind: StructureKind.TypeAlias,
|
|
17
|
+
name: `${syntheticNamePrefix}Identifier`,
|
|
18
|
+
type: this.identifierType.name,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
isExported: true,
|
|
22
|
+
kind: StructureKind.Module,
|
|
23
|
+
name: `${syntheticNamePrefix}Identifier`,
|
|
24
|
+
statements: [
|
|
25
|
+
this.identifierType.fromStringFunctionDeclaration,
|
|
26
|
+
this.identifierType.toStringFunctionDeclaration,
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
function reExportAncestorIdentifierTypeDeclarations(ancestorObjectType) {
|
|
32
|
+
// This object type's identifier type has the same identifier type as an ancestor object type,
|
|
33
|
+
// so just reuse the latter.
|
|
34
|
+
return [
|
|
35
|
+
{
|
|
36
|
+
isExported: true,
|
|
37
|
+
kind: StructureKind.TypeAlias,
|
|
38
|
+
name: `${syntheticNamePrefix}Identifier`,
|
|
39
|
+
type: ancestorObjectType.identifierTypeAlias,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
isExported: true,
|
|
43
|
+
kind: StructureKind.VariableStatement,
|
|
44
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
45
|
+
declarations: [
|
|
46
|
+
{
|
|
47
|
+
initializer: ancestorObjectType.identifierTypeAlias,
|
|
48
|
+
name: `${syntheticNamePrefix}Identifier`,
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=identifierTypeDeclarations.js.map
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
export * from "./classDeclaration.js";
|
|
2
2
|
export * from "./createFunctionDeclaration.js";
|
|
3
|
+
export * from "./EagerShaclProperty.js";
|
|
3
4
|
export * from "./equalsFunctionDeclaration.js";
|
|
4
|
-
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
|
-
export * from "./fromRdfFunctionDeclarations.js";
|
|
6
5
|
export * from "./fromRdfTypeVariableStatement.js";
|
|
6
|
+
export * from "./graphqlTypeVariableStatement.js";
|
|
7
7
|
export * from "./hashFunctionDeclarations.js";
|
|
8
|
+
export * from "./identifierTypeDeclarations.js";
|
|
8
9
|
export * from "./IdentifierPrefixProperty.js";
|
|
9
10
|
export * from "./IdentifierProperty.js";
|
|
10
11
|
export * from "./interfaceDeclaration.js";
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
13
|
-
export * from "./
|
|
12
|
+
export * from "./jsonFunctionDeclarations.js";
|
|
13
|
+
export * from "./jsonTypeAliasDeclaration.js";
|
|
14
|
+
export * from "./LazyShaclProperty.js";
|
|
15
|
+
export * from "./objectSetMethodNames.js";
|
|
16
|
+
export * from "./propertiesVariableStatement.js";
|
|
14
17
|
export * from "./Property.js";
|
|
18
|
+
export * from "./rdfFunctionDeclarations.js";
|
|
15
19
|
export * from "./ShaclProperty.js";
|
|
16
20
|
export * from "./sparqlFunctionDeclarations.js";
|
|
17
|
-
export * from "./toJsonFunctionDeclaration.js";
|
|
18
|
-
export * from "./toRdfFunctionDeclaration.js";
|
|
19
21
|
export * from "./TypeDiscriminatorProperty.js";
|
|
20
22
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
export * from "./classDeclaration.js";
|
|
2
2
|
export * from "./createFunctionDeclaration.js";
|
|
3
|
+
export * from "./EagerShaclProperty.js";
|
|
3
4
|
export * from "./equalsFunctionDeclaration.js";
|
|
4
|
-
export * from "./fromJsonFunctionDeclarations.js";
|
|
5
|
-
export * from "./fromRdfFunctionDeclarations.js";
|
|
6
5
|
export * from "./fromRdfTypeVariableStatement.js";
|
|
6
|
+
export * from "./graphqlTypeVariableStatement.js";
|
|
7
7
|
export * from "./hashFunctionDeclarations.js";
|
|
8
|
+
export * from "./identifierTypeDeclarations.js";
|
|
8
9
|
export * from "./IdentifierPrefixProperty.js";
|
|
9
10
|
export * from "./IdentifierProperty.js";
|
|
10
11
|
export * from "./interfaceDeclaration.js";
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
13
|
-
export * from "./
|
|
12
|
+
export * from "./jsonFunctionDeclarations.js";
|
|
13
|
+
export * from "./jsonTypeAliasDeclaration.js";
|
|
14
|
+
export * from "./LazyShaclProperty.js";
|
|
15
|
+
export * from "./objectSetMethodNames.js";
|
|
16
|
+
export * from "./propertiesVariableStatement.js";
|
|
14
17
|
export * from "./Property.js";
|
|
18
|
+
export * from "./rdfFunctionDeclarations.js";
|
|
15
19
|
export * from "./ShaclProperty.js";
|
|
16
20
|
export * from "./sparqlFunctionDeclarations.js";
|
|
17
|
-
export * from "./toJsonFunctionDeclaration.js";
|
|
18
|
-
export * from "./toRdfFunctionDeclaration.js";
|
|
19
21
|
export * from "./TypeDiscriminatorProperty.js";
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -8,7 +8,7 @@ export function interfaceDeclaration() {
|
|
|
8
8
|
if (this.extern) {
|
|
9
9
|
return Maybe.empty();
|
|
10
10
|
}
|
|
11
|
-
const properties = this.properties.flatMap((property) => property.
|
|
11
|
+
const properties = this.properties.flatMap((property) => property.propertySignature.toList());
|
|
12
12
|
return Maybe.of({
|
|
13
13
|
extends: this.parentObjectTypes.map((parentObjectType) => parentObjectType.name),
|
|
14
14
|
isExported: true,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function jsonFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
|
|
4
|
+
//# sourceMappingURL=jsonFunctionDeclarations.d.ts.map
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
4
|
+
import { toJsonFunctionOrMethodDeclaration } from "./toJsonFunctionOrMethodDeclaration.js";
|
|
5
|
+
function fromJsonFunctionDeclarations() {
|
|
6
|
+
const deserializePropertiesReturnType = [];
|
|
7
|
+
const initializers = [];
|
|
8
|
+
const propertyReturnTypeSignatures = [];
|
|
9
|
+
const propertiesFromJsonStatements = [];
|
|
10
|
+
propertiesFromJsonStatements.push(`const ${syntheticNamePrefix}jsonSafeParseResult = ${syntheticNamePrefix}jsonZodSchema().safeParse(_json);`, `if (!${syntheticNamePrefix}jsonSafeParseResult.success) { return purify.Left(${syntheticNamePrefix}jsonSafeParseResult.error); }`, `const ${variables.jsonObject} = ${syntheticNamePrefix}jsonSafeParseResult.data;`);
|
|
11
|
+
this.parentObjectTypes.forEach((parentObjectType, parentObjectTypeI) => {
|
|
12
|
+
propertiesFromJsonStatements.push(`const ${syntheticNamePrefix}super${parentObjectTypeI}Either = ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromJson(${variables.jsonObject});`, `if (${syntheticNamePrefix}super${parentObjectTypeI}Either.isLeft()) { return ${syntheticNamePrefix}super${parentObjectTypeI}Either; }`, `const ${syntheticNamePrefix}super${parentObjectTypeI} = ${syntheticNamePrefix}super${parentObjectTypeI}Either.unsafeCoerce()`);
|
|
13
|
+
initializers.push(`...${syntheticNamePrefix}super${parentObjectTypeI}`);
|
|
14
|
+
deserializePropertiesReturnType.push(`${syntheticNamePrefix}UnwrapR<ReturnType<typeof ${parentObjectType.staticModuleName}.${syntheticNamePrefix}propertiesFromJson>>`);
|
|
15
|
+
});
|
|
16
|
+
for (const property of this.properties) {
|
|
17
|
+
const propertyFromJsonStatements = property.fromJsonStatements({
|
|
18
|
+
variables,
|
|
19
|
+
});
|
|
20
|
+
if (propertyFromJsonStatements.length > 0) {
|
|
21
|
+
propertiesFromJsonStatements.push(...propertyFromJsonStatements);
|
|
22
|
+
initializers.push(property.name);
|
|
23
|
+
propertyReturnTypeSignatures.push(`${property.name}: ${property.type.name};`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
propertiesFromJsonStatements.push(`return purify.Either.of({ ${initializers.join(", ")} })`);
|
|
27
|
+
if (propertyReturnTypeSignatures.length > 0) {
|
|
28
|
+
deserializePropertiesReturnType.splice(0, 0, `{ ${propertyReturnTypeSignatures.join(" ")} }`);
|
|
29
|
+
}
|
|
30
|
+
const functionDeclarations = [];
|
|
31
|
+
functionDeclarations.push({
|
|
32
|
+
isExported: true,
|
|
33
|
+
kind: StructureKind.Function,
|
|
34
|
+
name: `${syntheticNamePrefix}propertiesFromJson`,
|
|
35
|
+
parameters: [
|
|
36
|
+
{
|
|
37
|
+
name: "_json",
|
|
38
|
+
type: "unknown",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
returnType: `purify.Either<zod.ZodError, ${deserializePropertiesReturnType.join(" & ")}>`,
|
|
42
|
+
statements: propertiesFromJsonStatements,
|
|
43
|
+
});
|
|
44
|
+
let fromJsonStatements;
|
|
45
|
+
if (this.abstract) {
|
|
46
|
+
if (this.childObjectTypes.length > 0) {
|
|
47
|
+
// Similar to an object union type, alt-chain the fromJson of the different concrete subclasses together
|
|
48
|
+
fromJsonStatements = [
|
|
49
|
+
`return ${this.childObjectTypes.reduce((expression, childObjectType) => {
|
|
50
|
+
const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromJson(json) as purify.Either<zod.ZodError, ${this.name}>)`;
|
|
51
|
+
return expression.length > 0
|
|
52
|
+
? `${expression}.altLazy(() => ${childObjectTypeExpression})`
|
|
53
|
+
: childObjectTypeExpression;
|
|
54
|
+
}, "")};`,
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
fromJsonStatements = [];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
let propertiesFromJsonExpression = `${syntheticNamePrefix}propertiesFromJson(json)`;
|
|
63
|
+
if (this.declarationType === "class") {
|
|
64
|
+
propertiesFromJsonExpression = `${propertiesFromJsonExpression}.map(properties => new ${this.name}(properties))`;
|
|
65
|
+
}
|
|
66
|
+
if (this.childObjectTypes.length > 0) {
|
|
67
|
+
fromJsonStatements = [
|
|
68
|
+
`return ${this.childObjectTypes.reduce((expression, childObjectType) => {
|
|
69
|
+
const childObjectTypeExpression = `(${childObjectType.staticModuleName}.${syntheticNamePrefix}fromJson(json) as purify.Either<zod.ZodError, ${this.name}>)`;
|
|
70
|
+
return expression.length > 0
|
|
71
|
+
? `${expression}.altLazy(() => ${childObjectTypeExpression})`
|
|
72
|
+
: childObjectTypeExpression;
|
|
73
|
+
}, "")}.altLazy(() => ${propertiesFromJsonExpression});`,
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
fromJsonStatements = [`return ${propertiesFromJsonExpression};`];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (fromJsonStatements.length > 0) {
|
|
81
|
+
functionDeclarations.push({
|
|
82
|
+
isExported: true,
|
|
83
|
+
kind: StructureKind.Function,
|
|
84
|
+
name: `${syntheticNamePrefix}fromJson`,
|
|
85
|
+
parameters: [
|
|
86
|
+
{
|
|
87
|
+
name: "json",
|
|
88
|
+
type: "unknown",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
returnType: `purify.Either<zod.ZodError, ${this.name}>`,
|
|
92
|
+
statements: fromJsonStatements,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return functionDeclarations;
|
|
96
|
+
}
|
|
97
|
+
function jsonSchemaFunctionDeclaration() {
|
|
98
|
+
return {
|
|
99
|
+
isExported: true,
|
|
100
|
+
kind: StructureKind.Function,
|
|
101
|
+
name: `${syntheticNamePrefix}jsonSchema`,
|
|
102
|
+
statements: [
|
|
103
|
+
`return zodToJsonSchema(${syntheticNamePrefix}jsonZodSchema());`,
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function jsonUiSchemaFunctionDeclaration() {
|
|
108
|
+
const variables = { scopePrefix: "scopePrefix" };
|
|
109
|
+
const elements = this.parentObjectTypes
|
|
110
|
+
.map((parentObjectType) => `${parentObjectType.staticModuleName}.${syntheticNamePrefix}jsonUiSchema({ scopePrefix })`)
|
|
111
|
+
.concat(this.ownProperties.flatMap((property) => property.jsonUiSchemaElement({ variables }).toList()));
|
|
112
|
+
return {
|
|
113
|
+
isExported: true,
|
|
114
|
+
kind: StructureKind.Function,
|
|
115
|
+
name: `${syntheticNamePrefix}jsonUiSchema`,
|
|
116
|
+
parameters: [
|
|
117
|
+
{
|
|
118
|
+
hasQuestionToken: true,
|
|
119
|
+
name: "parameters",
|
|
120
|
+
type: "{ scopePrefix?: string }",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
returnType: "any",
|
|
124
|
+
statements: [
|
|
125
|
+
'const scopePrefix = parameters?.scopePrefix ?? "#";',
|
|
126
|
+
`return { "elements": [ ${elements.join(", ")} ], label: "${this.label.orDefault(this.name)}", type: "Group" }`,
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function jsonZodSchemaFunctionDeclaration() {
|
|
131
|
+
const variables = { zod: "zod" };
|
|
132
|
+
const mergeZodObjectSchemas = [];
|
|
133
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
134
|
+
mergeZodObjectSchemas.push(`${parentObjectType.jsonZodSchema({ context: "type", variables })}`);
|
|
135
|
+
}
|
|
136
|
+
if (this.properties.length > 0) {
|
|
137
|
+
mergeZodObjectSchemas.push(`${variables.zod}.object({ ${this.properties
|
|
138
|
+
.flatMap((property) => property.jsonZodSchema({ variables }).toList())
|
|
139
|
+
.map(({ key, schema }) => `"${key}": ${schema}`)
|
|
140
|
+
.join(",")} })`);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
isExported: true,
|
|
144
|
+
kind: StructureKind.Function,
|
|
145
|
+
name: `${syntheticNamePrefix}jsonZodSchema`,
|
|
146
|
+
statements: [
|
|
147
|
+
`return ${mergeZodObjectSchemas.length > 0
|
|
148
|
+
? mergeZodObjectSchemas.reduce((merged, zodObjectSchema) => {
|
|
149
|
+
if (merged.length === 0) {
|
|
150
|
+
return zodObjectSchema;
|
|
151
|
+
}
|
|
152
|
+
return `${merged}.merge(${zodObjectSchema})`;
|
|
153
|
+
}, "")
|
|
154
|
+
: `${variables.zod}.object()`} satisfies zod.ZodType<${syntheticNamePrefix}Json>;`,
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function toJsonFunctionDeclaration() {
|
|
159
|
+
if (this.declarationType !== "interface") {
|
|
160
|
+
return Maybe.empty();
|
|
161
|
+
}
|
|
162
|
+
return toJsonFunctionOrMethodDeclaration
|
|
163
|
+
.bind(this)()
|
|
164
|
+
.map((toJsonFunctionOrMethodDeclaration) => ({
|
|
165
|
+
...toJsonFunctionOrMethodDeclaration,
|
|
166
|
+
isExported: true,
|
|
167
|
+
kind: StructureKind.Function,
|
|
168
|
+
name: `${syntheticNamePrefix}toJson`,
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
export function jsonFunctionDeclarations() {
|
|
172
|
+
if (!this.features.has("json")) {
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
if (this.extern) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
return [
|
|
179
|
+
...fromJsonFunctionDeclarations.bind(this)(),
|
|
180
|
+
jsonSchemaFunctionDeclaration.bind(this)(),
|
|
181
|
+
jsonUiSchemaFunctionDeclaration.bind(this)(),
|
|
182
|
+
...toJsonFunctionDeclaration.bind(this)().toList(),
|
|
183
|
+
jsonZodSchemaFunctionDeclaration.bind(this)(),
|
|
184
|
+
];
|
|
185
|
+
}
|
|
186
|
+
const variables = {
|
|
187
|
+
jsonObject: `${syntheticNamePrefix}jsonObject`,
|
|
188
|
+
};
|
|
189
|
+
//# sourceMappingURL=jsonFunctionDeclarations.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type TypeAliasDeclarationStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function jsonTypeAliasDeclaration(this: ObjectType): Maybe<TypeAliasDeclarationStructure>;
|
|
5
|
+
//# sourceMappingURL=jsonTypeAliasDeclaration.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind } from "ts-morph";
|
|
3
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
4
|
+
export function jsonTypeAliasDeclaration() {
|
|
5
|
+
if (!this.features.has("json")) {
|
|
6
|
+
return Maybe.empty();
|
|
7
|
+
}
|
|
8
|
+
if (this.extern) {
|
|
9
|
+
return Maybe.empty();
|
|
10
|
+
}
|
|
11
|
+
const members = [];
|
|
12
|
+
if (this.ownProperties.length > 0) {
|
|
13
|
+
members.push(`{ ${this.ownProperties
|
|
14
|
+
.flatMap((property) => property.jsonPropertySignature.toList())
|
|
15
|
+
.map((propertySignature) => `readonly "${propertySignature.name}"${propertySignature.hasQuestionToken ? "?" : ""}: ${propertySignature.type}`)
|
|
16
|
+
.join("; ")} }`);
|
|
17
|
+
}
|
|
18
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
19
|
+
members.push(parentObjectType.jsonName.toString());
|
|
20
|
+
}
|
|
21
|
+
return Maybe.of({
|
|
22
|
+
isExported: true,
|
|
23
|
+
kind: StructureKind.TypeAlias,
|
|
24
|
+
name: `${syntheticNamePrefix}Json`,
|
|
25
|
+
type: members.length > 0 ? members.join(" & ") : "object",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=jsonTypeAliasDeclaration.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { camelCase, trainCase } from "change-case";
|
|
2
|
+
import plur from "plur";
|
|
3
|
+
export function objectSetMethodNames() {
|
|
4
|
+
const prefixSingular = camelCase(this.name);
|
|
5
|
+
const thisNameParts = trainCase(this.name).split("-");
|
|
6
|
+
let prefixPlural = camelCase(`${thisNameParts.slice(0, thisNameParts.length - 1).join("")}${plur(thisNameParts[thisNameParts.length - 1])}`);
|
|
7
|
+
if (prefixPlural === prefixSingular) {
|
|
8
|
+
// Happens with singular-s nouns like "series"
|
|
9
|
+
prefixPlural = `${prefixPlural}s`;
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
object: prefixSingular,
|
|
13
|
+
objectIdentifiers: `${prefixSingular}Identifiers`,
|
|
14
|
+
objects: prefixPlural,
|
|
15
|
+
objectsCount: `${prefixPlural}Count`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=objectSetMethodNames.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { type VariableStatementStructure } from "ts-morph";
|
|
3
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
4
|
+
export declare function propertiesVariableStatement(this: ObjectType): Maybe<VariableStatementStructure>;
|
|
5
|
+
//# sourceMappingURL=propertiesVariableStatement.d.ts.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { StructureKind, VariableDeclarationKind, } from "ts-morph";
|
|
3
|
+
import { objectInitializer } from "../objectInitializer.js";
|
|
4
|
+
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
5
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
6
|
+
import { ShaclProperty } from "./ShaclProperty.js";
|
|
7
|
+
export function propertiesVariableStatement() {
|
|
8
|
+
if (this.extern) {
|
|
9
|
+
return Maybe.empty();
|
|
10
|
+
}
|
|
11
|
+
const propertiesObject = [];
|
|
12
|
+
for (const parentObjectType of this.parentObjectTypes) {
|
|
13
|
+
propertiesObject.push(`...${parentObjectType.staticModuleName}.${syntheticNamePrefix}properties`);
|
|
14
|
+
}
|
|
15
|
+
for (const property of this.properties) {
|
|
16
|
+
if (!(property instanceof ShaclProperty)) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const propertyObject = {};
|
|
20
|
+
if (this.features.has("rdf")) {
|
|
21
|
+
propertyObject["identifier"] = rdfjsTermExpression(property.path);
|
|
22
|
+
}
|
|
23
|
+
propertiesObject.push(`${property.name}: ${objectInitializer(propertyObject)}`);
|
|
24
|
+
}
|
|
25
|
+
return Maybe.of({
|
|
26
|
+
declarationKind: VariableDeclarationKind.Const,
|
|
27
|
+
kind: StructureKind.VariableStatement,
|
|
28
|
+
declarations: [
|
|
29
|
+
{
|
|
30
|
+
name: `${syntheticNamePrefix}properties`,
|
|
31
|
+
initializer: `{${propertiesObject.join(", ")}}`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
isExported: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=propertiesVariableStatement.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type FunctionDeclarationStructure } from "ts-morph";
|
|
2
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
3
|
+
export declare function rdfFunctionDeclarations(this: ObjectType): readonly FunctionDeclarationStructure[];
|
|
4
|
+
//# sourceMappingURL=rdfFunctionDeclarations.d.ts.map
|