@shaclmate/compiler 4.0.9 → 4.0.11
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.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +4 -1
- package/dist/ast/AbstractCompoundType.js +0 -2
- package/dist/ast/Ast.d.ts +1 -1
- package/dist/ast/IntersectionType.js +4 -3
- package/dist/ast/UnionType.js +3 -2
- package/dist/generators/json/AstJsonGenerator.js +1 -1
- package/dist/generators/ts/AbstractCollectionType.d.ts +1 -1
- package/dist/generators/ts/AbstractCollectionType.js +2 -2
- package/dist/generators/ts/AbstractContainerType.d.ts +2 -2
- package/dist/generators/ts/AbstractContainerType.js +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +3 -3
- package/dist/generators/ts/AbstractLazyObjectType.js +2 -2
- package/dist/generators/ts/AbstractNamedUnionType.d.ts +2 -2
- package/dist/generators/ts/AbstractNamedUnionType.js +17 -15
- package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
- package/dist/generators/ts/AbstractNumericType.js +1 -1
- package/dist/generators/ts/AbstractType.d.ts +5 -5
- package/dist/generators/ts/AbstractUnionType.d.ts +1 -1
- package/dist/generators/ts/AbstractUnionType.js +6 -6
- package/dist/generators/ts/AnonymousUnionType.d.ts +1 -1
- package/dist/generators/ts/AnonymousUnionType.js +2 -2
- package/dist/generators/ts/BigDecimalType.d.ts +1 -1
- package/dist/generators/ts/BigDecimalType.js +2 -2
- package/dist/generators/ts/BigIntType.d.ts +1 -1
- package/dist/generators/ts/BigIntType.js +1 -1
- package/dist/generators/ts/BlankNodeType.d.ts +1 -1
- package/dist/generators/ts/BlankNodeType.js +1 -1
- package/dist/generators/ts/BooleanType.d.ts +1 -1
- package/dist/generators/ts/BooleanType.js +1 -1
- package/dist/generators/ts/DateTimeType.d.ts +1 -1
- package/dist/generators/ts/DateTimeType.js +1 -1
- package/dist/generators/ts/DateType.d.ts +1 -1
- package/dist/generators/ts/DateType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +1 -1
- package/dist/generators/ts/DefaultValueType.js +3 -3
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +1 -1
- package/dist/generators/ts/IriType.js +1 -1
- package/dist/generators/ts/LazyObjectOptionType.js +1 -1
- package/dist/generators/ts/LazyObjectSetType.js +1 -1
- package/dist/generators/ts/LazyObjectType.js +2 -2
- package/dist/generators/ts/ListType.d.ts +2 -2
- package/dist/generators/ts/ListType.js +1 -1
- package/dist/generators/ts/LiteralType.d.ts +1 -1
- package/dist/generators/ts/LiteralType.js +1 -1
- package/dist/generators/ts/{ObjectType.d.ts → NamedObjectType.d.ts} +28 -28
- package/dist/generators/ts/{ObjectType.js → NamedObjectType.js} +105 -97
- package/dist/generators/ts/NamedObjectUnionType.d.ts +4 -4
- package/dist/generators/ts/NamedObjectUnionType.js +8 -12
- package/dist/generators/ts/OptionType.d.ts +1 -1
- package/dist/generators/ts/OptionType.js +2 -2
- package/dist/generators/ts/StringType.d.ts +1 -1
- package/dist/generators/ts/StringType.js +1 -1
- package/dist/generators/ts/TermType.d.ts +1 -1
- package/dist/generators/ts/TermType.js +1 -1
- package/dist/generators/ts/TsGenerator.js +8 -8
- package/dist/generators/ts/Type.d.ts +2 -2
- package/dist/generators/ts/TypeFactory.d.ts +2 -2
- package/dist/generators/ts/TypeFactory.js +36 -36
- package/dist/generators/ts/ZodGenerator.js +14 -12
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/AbstractProperty.d.ts +6 -6
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/AbstractProperty.js +3 -3
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/DiscriminantProperty.d.ts +1 -1
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/DiscriminantProperty.js +13 -11
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierPrefixProperty.d.ts +1 -1
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierPrefixProperty.js +4 -4
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierProperty.d.ts +1 -1
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/IdentifierProperty.js +24 -24
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_classDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_classDeclaration.js → _NamedObjectType/NamedObjectType_classDeclaration.js} +14 -14
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_createFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_createFunctionDeclaration.js → _NamedObjectType/NamedObjectType_createFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_equalsFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_equalsFunctionOrMethodDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_filterFunctionDeclaration.js → _NamedObjectType/NamedObjectType_filterFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_filterTypeDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_filterTypeDeclaration.js → _NamedObjectType/NamedObjectType_filterTypeDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.js → _NamedObjectType/NamedObjectType_focusSparqlConstructTriplesFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.js → _NamedObjectType/NamedObjectType_focusSparqlWherePatternsFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_fromJsonFunctionDeclaration.js → _NamedObjectType/NamedObjectType_fromJsonFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.js → _NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.js → _NamedObjectType/NamedObjectType_fromRdfResourceValuesFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_fromRdfTypeVariableStatement.js → _NamedObjectType/NamedObjectType_fromRdfTypeVariableStatement.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_graphqlTypeVariableStatement.js → _NamedObjectType/NamedObjectType_graphqlTypeVariableStatement.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_hashFunctionOrMethodDeclarations.js → _NamedObjectType/NamedObjectType_hashFunctionOrMethodDeclarations.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_interfaceDeclaration.js → _NamedObjectType/NamedObjectType_interfaceDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_isTypeFunctionDeclaration.js → _NamedObjectType/NamedObjectType_isTypeFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonParseFunctionDeclaration.js +19 -0
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.js → _NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js} +5 -5
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_jsonTypeAliasDeclaration.js → _NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.js → _NamedObjectType/NamedObjectType_jsonUiSchemaFunctionDeclaration.js} +4 -4
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_objectSetMethodNames.d.ts +9 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_objectSetMethodNames.js → _NamedObjectType/NamedObjectType_objectSetMethodNames.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_propertiesFromJsonFunctionDeclaration.js → _NamedObjectType/NamedObjectType_propertiesFromJsonFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_propertiesFromRdfResourceFunctionDeclaration.js → _NamedObjectType/NamedObjectType_propertiesFromRdfResourceFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.d.ts +4 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_schemaVariableStatement.js → _NamedObjectType/NamedObjectType_schemaVariableStatement.js} +2 -2
- package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.d.ts → _NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.d.ts} +2 -2
- package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryFunctionDeclaration.js → _NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts → _NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.d.ts} +2 -2
- package/dist/generators/ts/{_ObjectType/ObjectType_sparqlConstructQueryStringFunctionDeclaration.js → _NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_toJsonFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_toJsonFunctionOrMethodDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_toRdfResourceFunctionOrMethodDeclaration.js → _NamedObjectType/NamedObjectType_toRdfResourceFunctionOrMethodDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.js → _NamedObjectType/NamedObjectType_valueSparqlConstructTriplesFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +5 -0
- package/dist/generators/ts/{_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.js → _NamedObjectType/NamedObjectType_valueSparqlWherePatternsFunctionDeclaration.js} +2 -2
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/ShaclProperty.d.ts +1 -1
- package/dist/generators/ts/{_ObjectType → _NamedObjectType}/ShaclProperty.js +8 -8
- package/dist/generators/ts/_NamedObjectType/identifierTypeDeclarations.d.ts +4 -0
- package/dist/generators/ts/graphqlSchemaVariableStatement.d.ts +2 -2
- package/dist/generators/ts/graphqlSchemaVariableStatement.js +23 -23
- package/dist/generators/ts/objectSetDeclarations.d.ts +2 -2
- package/dist/generators/ts/objectSetDeclarations.js +19 -16
- package/dist/generators/ts/objectSetInterfaceDeclaration.d.ts +3 -3
- package/dist/generators/ts/objectSetInterfaceDeclaration.js +6 -4
- package/dist/generators/ts/objectSetMethodSignatures.d.ts +4 -4
- package/dist/generators/ts/objectSetMethodSignatures.js +9 -9
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.d.ts +3 -3
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +47 -45
- package/dist/generators/ts/singleEntryRecord.d.ts +2 -0
- package/dist/generators/ts/singleEntryRecord.js +6 -0
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.d.ts +3 -3
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +17 -17
- package/dist/generators/ts/synthesizeUberObjectUnionType.d.ts +2 -2
- package/dist/generators/ts/synthesizeUberObjectUnionType.js +8 -8
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.d.ts +5 -5
- package/dist/generators/ts/unsupportedObjectSetMethodDeclarations.js +2 -2
- package/package.json +4 -4
- package/dist/generators/ts/_ObjectType/ObjectType_classDeclaration.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_createFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_equalsFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_filterFunctionDeclaration.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_filterTypeDeclaration.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_focusSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_fromJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_graphqlTypeVariableStatement.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_hashFunctionOrMethodDeclarations.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_interfaceDeclaration.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_isTypeFunctionDeclaration.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_jsonSchemaFunctionDeclaration.js +0 -14
- package/dist/generators/ts/_ObjectType/ObjectType_jsonTypeAliasDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_jsonUiSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_jsonZodSchemaFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_objectSetMethodNames.d.ts +0 -9
- package/dist/generators/ts/_ObjectType/ObjectType_parseJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_parseJsonFunctionDeclaration.js +0 -19
- package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromJsonFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_propertiesFromRdfResourceFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_schemaVariableStatement.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_toJsonFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_toRdfResourceFunctionOrMethodDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlConstructTriplesFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/ObjectType_valueSparqlWherePatternsFunctionDeclaration.d.ts +0 -5
- package/dist/generators/ts/_ObjectType/identifierTypeDeclarations.d.ts +0 -4
- /package/dist/generators/ts/{_ObjectType → _NamedObjectType}/Property.d.ts +0 -0
- /package/dist/generators/ts/{_ObjectType → _NamedObjectType}/Property.js +0 -0
- /package/dist/generators/ts/{_ObjectType → _NamedObjectType}/identifierTypeDeclarations.js +0 -0
|
@@ -8,20 +8,16 @@ import { pascalCase } from "change-case";
|
|
|
8
8
|
import { Maybe } from "purify-ts";
|
|
9
9
|
import { PropertyPath } from "rdfjs-resource";
|
|
10
10
|
import { Memoize } from "typescript-memoize";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
11
|
+
import { NamedObjectType_objectSetMethodNames } from "./_NamedObjectType/NamedObjectType_objectSetMethodNames.js";
|
|
12
|
+
import { NamedObjectType_sparqlConstructQueryFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_sparqlConstructQueryFunctionDeclaration.js";
|
|
13
|
+
import { NamedObjectType_sparqlConstructQueryStringFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.js";
|
|
14
14
|
import { AbstractNamedUnionType } from "./AbstractNamedUnionType.js";
|
|
15
15
|
import { AbstractType } from "./AbstractType.js";
|
|
16
16
|
import { imports } from "./imports.js";
|
|
17
|
+
import { singleEntryRecord } from "./singleEntryRecord.js";
|
|
17
18
|
import { snippets } from "./snippets.js";
|
|
18
19
|
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
19
20
|
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
20
|
-
function singleEntryRecord(key, value) {
|
|
21
|
-
const record = {};
|
|
22
|
-
record[key] = value;
|
|
23
|
-
return record;
|
|
24
|
-
}
|
|
25
21
|
export class NamedObjectUnionType extends AbstractNamedUnionType {
|
|
26
22
|
#identifierType;
|
|
27
23
|
graphqlArgs = Maybe.empty();
|
|
@@ -37,7 +33,7 @@ export class NamedObjectUnionType extends AbstractNamedUnionType {
|
|
|
37
33
|
return code `${this.staticModuleName}.${syntheticNamePrefix}Identifier`;
|
|
38
34
|
}
|
|
39
35
|
get objectSetMethodNames() {
|
|
40
|
-
return
|
|
36
|
+
return NamedObjectType_objectSetMethodNames.call(this);
|
|
41
37
|
}
|
|
42
38
|
get schema() {
|
|
43
39
|
return code `${this.staticModuleName}.${syntheticNamePrefix}schema`;
|
|
@@ -55,10 +51,10 @@ export class NamedObjectUnionType extends AbstractNamedUnionType {
|
|
|
55
51
|
...this.graphqlTypeVariableStatement,
|
|
56
52
|
...this.isTypeFunctionDeclaration,
|
|
57
53
|
...this.schemaVariableStatement,
|
|
58
|
-
...
|
|
54
|
+
...NamedObjectType_sparqlConstructQueryFunctionDeclaration.call(this)
|
|
59
55
|
.map((code_) => singleEntryRecord(`${syntheticNamePrefix}sparqlConstructQuery`, code_))
|
|
60
56
|
.orDefault({}),
|
|
61
|
-
...
|
|
57
|
+
...NamedObjectType_sparqlConstructQueryStringFunctionDeclaration.call(this)
|
|
62
58
|
.map((code_) => singleEntryRecord(`${syntheticNamePrefix}sparqlConstructQueryString`, code_))
|
|
63
59
|
.orDefault({}),
|
|
64
60
|
...this.toRdfResourceFunctionDeclaration,
|
|
@@ -181,7 +177,7 @@ ${{
|
|
|
181
177
|
if (!this.features.has("rdf")) {
|
|
182
178
|
return {};
|
|
183
179
|
}
|
|
184
|
-
return singleEntryRecord(
|
|
180
|
+
return singleEntryRecord(`${syntheticNamePrefix}toRdfResource`, code `\
|
|
185
181
|
export const ${syntheticNamePrefix}toRdfResource: ${snippets.ToRdfResourceFunction}<${this.name}> = (value, options) => {
|
|
186
182
|
${joinCode(this.concreteMembers
|
|
187
183
|
.map((member) => {
|
|
@@ -26,7 +26,7 @@ export declare class OptionType<ItemTypeT extends OptionType.ItemType> extends A
|
|
|
26
26
|
hashStatements({ depth, variables, }: Parameters<AbstractContainerType<ItemTypeT>["hashStatements"]>[0]): readonly Code[];
|
|
27
27
|
jsonType(parameters?: Parameters<AbstractContainerType<ItemTypeT>["jsonType"]>[0]): AbstractContainerType.JsonType;
|
|
28
28
|
jsonUiSchemaElement(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
29
|
-
|
|
29
|
+
jsonSchema(parameters: Parameters<AbstractContainerType<ItemTypeT>["jsonSchema"]>[0]): Code;
|
|
30
30
|
toJsonExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toJsonExpression"]>[0]): Code;
|
|
31
31
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractContainerType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
32
32
|
}
|
|
@@ -122,8 +122,8 @@ export class OptionType extends AbstractContainerType {
|
|
|
122
122
|
jsonUiSchemaElement(parameters) {
|
|
123
123
|
return this.itemType.jsonUiSchemaElement(parameters);
|
|
124
124
|
}
|
|
125
|
-
|
|
126
|
-
return code `${this.itemType.
|
|
125
|
+
jsonSchema(parameters) {
|
|
126
|
+
return code `${this.itemType.jsonSchema(parameters)}.optional()`;
|
|
127
127
|
}
|
|
128
128
|
toJsonExpression({ variables, }) {
|
|
129
129
|
return code `${variables.value}.map(item => (${this.itemType.toJsonExpression({ variables: { value: code `item` } })})).extract()`;
|
|
@@ -16,7 +16,7 @@ export declare class StringType extends AbstractPrimitiveType<string> {
|
|
|
16
16
|
kind: Code;
|
|
17
17
|
};
|
|
18
18
|
hashStatements({ variables, }: Parameters<AbstractPrimitiveType<string>["hashStatements"]>[0]): readonly Code[];
|
|
19
|
-
|
|
19
|
+
jsonSchema(_parameters: Parameters<AbstractPrimitiveType<string>["jsonSchema"]>[0]): Code;
|
|
20
20
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<string>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
21
21
|
protected fromRdfExpressionChain({ variables, }: Parameters<AbstractPrimitiveType<string>["fromRdfExpressionChain"]>[0]): ReturnType<AbstractPrimitiveType<string>["fromRdfExpressionChain"]>;
|
|
22
22
|
}
|
|
@@ -37,7 +37,7 @@ export class StringType extends AbstractPrimitiveType {
|
|
|
37
37
|
hashStatements({ variables, }) {
|
|
38
38
|
return [code `${variables.hasher}.update(${variables.value});`];
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
jsonSchema(_parameters) {
|
|
41
41
|
switch (this.primitiveIn.length) {
|
|
42
42
|
case 0:
|
|
43
43
|
return code `${imports.z}.string()`;
|
|
@@ -21,7 +21,7 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
|
|
|
21
21
|
fromJsonExpression({ variables, }: Parameters<AbstractTermType["fromJsonExpression"]>[0]): Code;
|
|
22
22
|
graphqlResolveExpression(_parameters: Parameters<AbstractTermType["graphqlResolveExpression"]>[0]): Code;
|
|
23
23
|
jsonType(): AbstractTermType.JsonType;
|
|
24
|
-
|
|
24
|
+
jsonSchema(_parameters: Parameters<AbstractTermType["jsonSchema"]>[0]): Code;
|
|
25
25
|
toJsonExpression({ variables, }: Parameters<AbstractTermType["toJsonExpression"]>[0]): Code;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=TermType.d.ts.map
|
|
@@ -82,7 +82,7 @@ export class TermType extends AbstractTermType {
|
|
|
82
82
|
.map((nodeKind) => `"${NodeKind.toTermType(nodeKind)}"`)
|
|
83
83
|
.join(" | ")} } | { readonly "@language"?: string, readonly "@type"?: string, readonly "@value": string, readonly termType: "Literal" }`);
|
|
84
84
|
}
|
|
85
|
-
|
|
85
|
+
jsonSchema(_parameters) {
|
|
86
86
|
return code `${imports.z}.discriminatedUnion("termType", [${joinCode([...this.nodeKinds].map((nodeKind) => {
|
|
87
87
|
switch (nodeKind) {
|
|
88
88
|
case "BlankNode":
|
|
@@ -15,31 +15,31 @@ export class TsGenerator {
|
|
|
15
15
|
}
|
|
16
16
|
declarations = declarations.concat(this.typeFactory.createType(astNamedUnionType).declaration.toList());
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const namedObjectTypesToposorted = ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType));
|
|
19
19
|
const namedObjectUnionTypesToposorted = ast_.namedUnionTypes
|
|
20
20
|
.filter((_) => _.isObjectUnionType())
|
|
21
21
|
.map((astObjectUnionType) => this.typeFactory.createNamedObjectUnionType(astObjectUnionType));
|
|
22
|
-
for (const
|
|
23
|
-
declarations = declarations.concat(
|
|
22
|
+
for (const namedObjectType of namedObjectTypesToposorted) {
|
|
23
|
+
declarations = declarations.concat(namedObjectType.declaration.toList());
|
|
24
24
|
}
|
|
25
25
|
for (const namedObjectUnionType of namedObjectUnionTypesToposorted) {
|
|
26
26
|
declarations = declarations.concat(namedObjectUnionType.declaration.toList());
|
|
27
27
|
}
|
|
28
|
-
const
|
|
28
|
+
const namedObjectTypesNameSorted = namedObjectTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
|
|
29
29
|
const namedObjectUnionTypesNameSorted = namedObjectUnionTypesToposorted.toSorted((left, right) => left.name.localeCompare(right.name));
|
|
30
|
-
if (
|
|
30
|
+
if (namedObjectTypesToposorted.length > 0) {
|
|
31
31
|
const uberObjectUnionType = synthesizeUberObjectUnionType({
|
|
32
|
-
|
|
32
|
+
namedObjectTypes: namedObjectTypesToposorted.toReversed(), // Reverse topological order so children ane before parents
|
|
33
33
|
});
|
|
34
34
|
declarations = declarations.concat(uberObjectUnionType.declaration.toList());
|
|
35
35
|
namedObjectUnionTypesNameSorted.push(uberObjectUnionType);
|
|
36
36
|
}
|
|
37
37
|
declarations.push(...objectSetDeclarations({
|
|
38
|
-
|
|
38
|
+
namedObjectTypes: namedObjectTypesNameSorted,
|
|
39
39
|
namedObjectUnionTypes: namedObjectUnionTypesNameSorted,
|
|
40
40
|
}));
|
|
41
41
|
declarations.push(...graphqlSchemaVariableStatement({
|
|
42
|
-
|
|
42
|
+
namedObjectTypes: namedObjectTypesNameSorted,
|
|
43
43
|
namedObjectUnionTypes: namedObjectUnionTypesNameSorted,
|
|
44
44
|
}).toList());
|
|
45
45
|
declarations.splice(0, 0, joinCode(Object.values(snippets)
|
|
@@ -15,12 +15,12 @@ import type { LazyObjectSetType } from "./LazyObjectSetType.js";
|
|
|
15
15
|
import type { LazyObjectType } from "./LazyObjectType.js";
|
|
16
16
|
import type { ListType } from "./ListType.js";
|
|
17
17
|
import type { LiteralType } from "./LiteralType.js";
|
|
18
|
+
import type { NamedObjectType } from "./NamedObjectType.js";
|
|
18
19
|
import type { NamedObjectUnionType } from "./NamedObjectUnionType.js";
|
|
19
20
|
import type { NamedUnionType } from "./NamedUnionType.js";
|
|
20
|
-
import type { ObjectType } from "./ObjectType.js";
|
|
21
21
|
import type { OptionType } from "./OptionType.js";
|
|
22
22
|
import type { SetType } from "./SetType.js";
|
|
23
23
|
import type { StringType } from "./StringType.js";
|
|
24
24
|
import type { TermType } from "./TermType.js";
|
|
25
|
-
export type Type = AnonymousUnionType | BigDecimalType | BigIntType | BlankNodeType | BooleanType | DateTimeType | DateType | DefaultValueType<DefaultValueType.ItemType> | FloatType | IdentifierType | IntType | IriType | LazyObjectOptionType | LazyObjectSetType | LazyObjectType | ListType<ListType.ItemType> | LiteralType | NamedObjectUnionType | NamedUnionType |
|
|
25
|
+
export type Type = AnonymousUnionType | BigDecimalType | BigIntType | BlankNodeType | BooleanType | DateTimeType | DateType | DefaultValueType<DefaultValueType.ItemType> | FloatType | IdentifierType | IntType | IriType | LazyObjectOptionType | LazyObjectSetType | LazyObjectType | ListType<ListType.ItemType> | LiteralType | NamedObjectUnionType | NamedUnionType | NamedObjectType | OptionType<OptionType.ItemType> | SetType<SetType.ItemType> | StringType | TermType;
|
|
26
26
|
//# sourceMappingURL=Type.d.ts.map
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import * as ast from "../../ast/index.js";
|
|
3
3
|
import { AnonymousUnionType } from "./AnonymousUnionType.js";
|
|
4
|
+
import { NamedObjectType } from "./NamedObjectType.js";
|
|
4
5
|
import { NamedObjectUnionType } from "./NamedObjectUnionType.js";
|
|
5
6
|
import { NamedUnionType } from "./NamedUnionType.js";
|
|
6
|
-
import { ObjectType } from "./ObjectType.js";
|
|
7
7
|
import type { Type } from "./Type.js";
|
|
8
8
|
export declare class TypeFactory {
|
|
9
9
|
private cachedNamedObjectUnionTypesByShapeIdentifier;
|
|
10
10
|
private cachedObjectTypePropertiesByShapeIdentifier;
|
|
11
11
|
private cachedObjectTypesByShapeIdentifier;
|
|
12
12
|
createNamedObjectUnionType(astType: ast.ObjectUnionType): NamedObjectUnionType;
|
|
13
|
-
|
|
13
|
+
createNamedObjectType(astType: ast.ObjectType): NamedObjectType;
|
|
14
14
|
createType(astType: ast.Type, parameters?: {
|
|
15
15
|
defaultValue?: Literal | NamedNode;
|
|
16
16
|
}): Type;
|
|
@@ -25,9 +25,9 @@ import { LazyObjectSetType } from "./LazyObjectSetType.js";
|
|
|
25
25
|
import { LazyObjectType } from "./LazyObjectType.js";
|
|
26
26
|
import { ListType } from "./ListType.js";
|
|
27
27
|
import { LiteralType } from "./LiteralType.js";
|
|
28
|
+
import { NamedObjectType } from "./NamedObjectType.js";
|
|
28
29
|
import { NamedObjectUnionType } from "./NamedObjectUnionType.js";
|
|
29
30
|
import { NamedUnionType } from "./NamedUnionType.js";
|
|
30
|
-
import { ObjectType } from "./ObjectType.js";
|
|
31
31
|
import { OptionType } from "./OptionType.js";
|
|
32
32
|
import { SetType } from "./SetType.js";
|
|
33
33
|
import { StringType } from "./StringType.js";
|
|
@@ -50,9 +50,9 @@ export class TypeFactory {
|
|
|
50
50
|
features: astType.tsFeatures,
|
|
51
51
|
identifierType: this.createIdentifierType(ast.ObjectCompoundType.identifierType(astType)),
|
|
52
52
|
label: astType.label,
|
|
53
|
-
members: ast.ObjectCompoundType.memberObjectTypes(astType).map((
|
|
53
|
+
members: ast.ObjectCompoundType.memberObjectTypes(astType).map((namedObjectType) => ({
|
|
54
54
|
discriminantValue: Maybe.empty(),
|
|
55
|
-
type: this.
|
|
55
|
+
type: this.createNamedObjectType(namedObjectType),
|
|
56
56
|
})),
|
|
57
57
|
name: tsName(astType.name.unsafeCoerce()),
|
|
58
58
|
recursive: astType.recursive,
|
|
@@ -60,7 +60,7 @@ export class TypeFactory {
|
|
|
60
60
|
this.cachedNamedObjectUnionTypesByShapeIdentifier.set(astType.shapeIdentifier, namedObjectUnionType);
|
|
61
61
|
return namedObjectUnionType;
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
createNamedObjectType(astType) {
|
|
64
64
|
{
|
|
65
65
|
const cachedObjectType = this.cachedObjectTypesByShapeIdentifier.get(astType.shapeIdentifier);
|
|
66
66
|
if (cachedObjectType) {
|
|
@@ -72,7 +72,7 @@ export class TypeFactory {
|
|
|
72
72
|
synthetic: astType.synthetic,
|
|
73
73
|
});
|
|
74
74
|
const staticModuleName = astType.childObjectTypes.length > 0 ? `${name}Static` : name;
|
|
75
|
-
const
|
|
75
|
+
const namedObjectType = new NamedObjectType({
|
|
76
76
|
abstract: astType.abstract,
|
|
77
77
|
comment: astType.comment,
|
|
78
78
|
declarationType: astType.tsObjectDeclarationType,
|
|
@@ -82,24 +82,24 @@ export class TypeFactory {
|
|
|
82
82
|
identifierType,
|
|
83
83
|
imports: astType.tsImports,
|
|
84
84
|
label: astType.label,
|
|
85
|
-
lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.
|
|
86
|
-
lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.
|
|
87
|
-
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.
|
|
88
|
-
lazyDiscriminantProperty: (
|
|
85
|
+
lazyAncestorObjectTypes: () => astType.ancestorObjectTypes.map((astType) => this.createNamedObjectType(astType)),
|
|
86
|
+
lazyChildObjectTypes: () => astType.childObjectTypes.map((astType) => this.createNamedObjectType(astType)),
|
|
87
|
+
lazyDescendantObjectTypes: () => astType.descendantObjectTypes.map((astType) => this.createNamedObjectType(astType)),
|
|
88
|
+
lazyDiscriminantProperty: (namedObjectType) => {
|
|
89
89
|
// Discriminant property
|
|
90
90
|
const discriminantOwnValue = !astType.abstract
|
|
91
|
-
?
|
|
91
|
+
? namedObjectType.discriminantValue
|
|
92
92
|
: undefined;
|
|
93
93
|
const discriminantDescendantValues = new Set();
|
|
94
|
-
for (const descendantObjectType of
|
|
94
|
+
for (const descendantObjectType of namedObjectType.descendantObjectTypes) {
|
|
95
95
|
if (!descendantObjectType.abstract) {
|
|
96
96
|
discriminantDescendantValues.add(descendantObjectType.discriminantValue);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
|
-
return new
|
|
99
|
+
return new NamedObjectType.DiscriminantProperty({
|
|
100
100
|
name: `${syntheticNamePrefix}type`,
|
|
101
|
-
|
|
102
|
-
type: new
|
|
101
|
+
namedObjectType,
|
|
102
|
+
type: new NamedObjectType.DiscriminantProperty.Type({
|
|
103
103
|
descendantValues: [...discriminantDescendantValues].sort(),
|
|
104
104
|
mutable: false,
|
|
105
105
|
ownValues: discriminantOwnValue ? [discriminantOwnValue] : [],
|
|
@@ -107,17 +107,17 @@ export class TypeFactory {
|
|
|
107
107
|
visibility: "public",
|
|
108
108
|
});
|
|
109
109
|
},
|
|
110
|
-
lazyIdentifierProperty: (
|
|
110
|
+
lazyIdentifierProperty: (namedObjectType) => new NamedObjectType.IdentifierProperty({
|
|
111
111
|
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
112
112
|
identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
|
|
113
113
|
name: `${syntheticNamePrefix}identifier`,
|
|
114
|
-
|
|
114
|
+
namedObjectType,
|
|
115
115
|
type: identifierType,
|
|
116
116
|
typeAlias: code `${staticModuleName}.${syntheticNamePrefix}Identifier`,
|
|
117
117
|
visibility: "public",
|
|
118
118
|
}),
|
|
119
|
-
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.
|
|
120
|
-
lazyProperties: (
|
|
119
|
+
lazyParentObjectTypes: () => astType.parentObjectTypes.map((astType) => this.createNamedObjectType(astType)),
|
|
120
|
+
lazyProperties: (namedObjectType) => {
|
|
121
121
|
const properties = astType.properties
|
|
122
122
|
.toSorted((left, right) => {
|
|
123
123
|
if (left.order < right.order) {
|
|
@@ -130,18 +130,18 @@ export class TypeFactory {
|
|
|
130
130
|
})
|
|
131
131
|
.map((astProperty) => this.createObjectTypeProperty({
|
|
132
132
|
astObjectTypeProperty: astProperty,
|
|
133
|
-
|
|
133
|
+
namedObjectType,
|
|
134
134
|
}));
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
properties.splice(0, 0,
|
|
135
|
+
if (namedObjectType._discriminantProperty.type.ownValues.length > 0 ||
|
|
136
|
+
namedObjectType._discriminantProperty.type.descendantValues.length > 0) {
|
|
137
|
+
properties.splice(0, 0, namedObjectType._discriminantProperty);
|
|
138
138
|
}
|
|
139
139
|
// Some ObjectTypes have an identifierPrefix property, depending on their identifier minting strategy.
|
|
140
|
-
if (
|
|
141
|
-
properties.splice(0, 0, new
|
|
140
|
+
if (namedObjectTypeNeedsIdentifierPrefixProperty(astType)) {
|
|
141
|
+
properties.splice(0, 0, new NamedObjectType.IdentifierPrefixProperty({
|
|
142
142
|
name: `${syntheticNamePrefix}identifierPrefix`,
|
|
143
|
-
|
|
144
|
-
own: !astType.ancestorObjectTypes.some(
|
|
143
|
+
namedObjectType,
|
|
144
|
+
own: !astType.ancestorObjectTypes.some(namedObjectTypeNeedsIdentifierPrefixProperty),
|
|
145
145
|
type: new StringType({
|
|
146
146
|
comment: astType.comment,
|
|
147
147
|
datatype: xsd.string,
|
|
@@ -154,8 +154,8 @@ export class TypeFactory {
|
|
|
154
154
|
visibility: "protected",
|
|
155
155
|
}));
|
|
156
156
|
}
|
|
157
|
-
// Every
|
|
158
|
-
properties.splice(0, 0,
|
|
157
|
+
// Every NamedObjectType has an identifier property. Some are abstract.
|
|
158
|
+
properties.splice(0, 0, namedObjectType.identifierProperty);
|
|
159
159
|
return properties;
|
|
160
160
|
},
|
|
161
161
|
name,
|
|
@@ -164,8 +164,8 @@ export class TypeFactory {
|
|
|
164
164
|
synthetic: astType.synthetic,
|
|
165
165
|
toRdfTypes: astType.toRdfTypes,
|
|
166
166
|
});
|
|
167
|
-
this.cachedObjectTypesByShapeIdentifier.set(astType.shapeIdentifier,
|
|
168
|
-
return
|
|
167
|
+
this.cachedObjectTypesByShapeIdentifier.set(astType.shapeIdentifier, namedObjectType);
|
|
168
|
+
return namedObjectType;
|
|
169
169
|
}
|
|
170
170
|
createType(astType, parameters) {
|
|
171
171
|
switch (astType.kind) {
|
|
@@ -190,7 +190,7 @@ export class TypeFactory {
|
|
|
190
190
|
case "LiteralType":
|
|
191
191
|
return this.createLiteralType(astType, parameters);
|
|
192
192
|
case "ObjectType":
|
|
193
|
-
return this.
|
|
193
|
+
return this.createNamedObjectType(astType);
|
|
194
194
|
case "OptionType":
|
|
195
195
|
return this.createOptionType(astType);
|
|
196
196
|
case "SetType":
|
|
@@ -419,19 +419,19 @@ export class TypeFactory {
|
|
|
419
419
|
languageIn: astType.languageIn,
|
|
420
420
|
});
|
|
421
421
|
}
|
|
422
|
-
createObjectTypeProperty({ astObjectTypeProperty,
|
|
422
|
+
createObjectTypeProperty({ astObjectTypeProperty, namedObjectType, }) {
|
|
423
423
|
{
|
|
424
424
|
const cachedProperty = this.cachedObjectTypePropertiesByShapeIdentifier.get(astObjectTypeProperty.shapeIdentifier);
|
|
425
425
|
if (cachedProperty) {
|
|
426
426
|
return cachedProperty;
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
|
-
const property = new
|
|
429
|
+
const property = new NamedObjectType.ShaclProperty({
|
|
430
430
|
comment: astObjectTypeProperty.comment,
|
|
431
431
|
description: astObjectTypeProperty.description,
|
|
432
432
|
label: astObjectTypeProperty.label,
|
|
433
433
|
mutable: astObjectTypeProperty.mutable,
|
|
434
|
-
|
|
434
|
+
namedObjectType,
|
|
435
435
|
name: tsName(astObjectTypeProperty.name),
|
|
436
436
|
path: astObjectTypeProperty.path,
|
|
437
437
|
recursive: !!astObjectTypeProperty.recursive,
|
|
@@ -471,8 +471,8 @@ export class TypeFactory {
|
|
|
471
471
|
});
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
|
-
function
|
|
475
|
-
return
|
|
474
|
+
function namedObjectTypeNeedsIdentifierPrefixProperty(namedObjectType) {
|
|
475
|
+
return namedObjectType.identifierMintingStrategy
|
|
476
476
|
.map((identifierMintingStrategy) => {
|
|
477
477
|
switch (identifierMintingStrategy) {
|
|
478
478
|
case "blankNode":
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { invariant } from "ts-invariant";
|
|
2
2
|
import * as ast from "../../ast/index.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { NamedObjectType_jsonSchemaFunctionDeclaration } from "./_NamedObjectType/NamedObjectType_jsonSchemaFunctionDeclaration.js";
|
|
4
|
+
import { NamedObjectType_jsonTypeAliasDeclaration } from "./_NamedObjectType/NamedObjectType_jsonTypeAliasDeclaration.js";
|
|
5
5
|
import { snippets } from "./snippets.js";
|
|
6
|
+
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
6
7
|
import { TypeFactory } from "./TypeFactory.js";
|
|
7
8
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
8
9
|
export class ZodGenerator {
|
|
9
10
|
typeFactory = new TypeFactory();
|
|
10
11
|
generate(ast_) {
|
|
11
12
|
const declarations = [];
|
|
12
|
-
for (const
|
|
13
|
+
for (const namedObjectType of ast.ObjectType.toposort(ast_.namedObjectTypes).map((astObjectType) => this.typeFactory.createNamedObjectType(astObjectType))) {
|
|
13
14
|
declarations.push(code `\
|
|
14
|
-
export namespace ${
|
|
15
|
-
${joinCode(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
export namespace ${namedObjectType.staticModuleName} {
|
|
16
|
+
${joinCode(NamedObjectType_jsonTypeAliasDeclaration.bind(namedObjectType)().toList())}
|
|
17
|
+
|
|
18
|
+
export namespace ${syntheticNamePrefix}Json {
|
|
19
|
+
${joinCode(NamedObjectType_jsonSchemaFunctionDeclaration.bind(namedObjectType)().toList())}
|
|
20
|
+
}
|
|
19
21
|
}`);
|
|
20
22
|
}
|
|
21
23
|
for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => this.typeFactory.createUnionType(astNamedUnionType))) {
|
|
22
24
|
invariant(astNamedUnionType.kind !== "AnonymousUnionType");
|
|
23
25
|
declarations.push(code `\
|
|
24
26
|
export namespace ${astNamedUnionType.staticModuleName} {
|
|
25
|
-
${
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
${astNamedUnionType.jsonTypeAliasDeclaration}
|
|
28
|
+
export namespace ${syntheticNamePrefix}Json {
|
|
29
|
+
${astNamedUnionType.jsonSchemaFunctionDeclaration}
|
|
30
|
+
}
|
|
29
31
|
}`);
|
|
30
32
|
}
|
|
31
33
|
declarations.splice(0, 0, joinCode(Object.values(snippets)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { Maybe } from "purify-ts";
|
|
2
2
|
import type { PropertyVisibility } from "../../../enums/PropertyVisibility.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
4
4
|
import type { Type } from "../Type.js";
|
|
5
5
|
import { type Code } from "../ts-poet-wrapper.js";
|
|
6
6
|
export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterFunction" | "mutable" | "name" | "schema">> {
|
|
7
|
-
protected readonly
|
|
7
|
+
protected readonly namedObjectType: NamedObjectType;
|
|
8
8
|
/**
|
|
9
9
|
* Optional property to include in the parameters object of a class constructor.
|
|
10
10
|
*/
|
|
@@ -47,7 +47,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
47
47
|
/**
|
|
48
48
|
* zod Object key: schema pair on the property serialized by toJsonObjectMember.
|
|
49
49
|
*/
|
|
50
|
-
abstract readonly
|
|
50
|
+
abstract readonly jsonZchema: Maybe<{
|
|
51
51
|
readonly key: string;
|
|
52
52
|
readonly schema: Code;
|
|
53
53
|
}>;
|
|
@@ -64,7 +64,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
64
64
|
*/
|
|
65
65
|
readonly name: string;
|
|
66
66
|
/**
|
|
67
|
-
* Is the property's type the
|
|
67
|
+
* Is the property's type the NamedObjectType or does its type indirectly reference the NamedObjectType?
|
|
68
68
|
*/
|
|
69
69
|
abstract readonly recursive: boolean;
|
|
70
70
|
/**
|
|
@@ -75,9 +75,9 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
75
75
|
* Property visibility: private, protected, public.
|
|
76
76
|
*/
|
|
77
77
|
readonly visibility: PropertyVisibility;
|
|
78
|
-
constructor({ name,
|
|
78
|
+
constructor({ name, namedObjectType, type, visibility, }: {
|
|
79
79
|
name: string;
|
|
80
|
-
|
|
80
|
+
namedObjectType: NamedObjectType;
|
|
81
81
|
type: TypeT;
|
|
82
82
|
visibility: PropertyVisibility;
|
|
83
83
|
});
|
|
@@ -9,7 +9,7 @@ import { Memoize } from "typescript-memoize";
|
|
|
9
9
|
import { removeUndefined } from "../removeUndefined.js";
|
|
10
10
|
import { code, literalOf } from "../ts-poet-wrapper.js";
|
|
11
11
|
export class AbstractProperty {
|
|
12
|
-
|
|
12
|
+
namedObjectType;
|
|
13
13
|
/**
|
|
14
14
|
* TypeScript identifier-safe name of the property.
|
|
15
15
|
*/
|
|
@@ -22,9 +22,9 @@ export class AbstractProperty {
|
|
|
22
22
|
* Property visibility: private, protected, public.
|
|
23
23
|
*/
|
|
24
24
|
visibility;
|
|
25
|
-
constructor({ name,
|
|
25
|
+
constructor({ name, namedObjectType, type, visibility, }) {
|
|
26
26
|
this.name = name;
|
|
27
|
-
this.
|
|
27
|
+
this.namedObjectType = namedObjectType;
|
|
28
28
|
this.type = type;
|
|
29
29
|
this.visibility = visibility;
|
|
30
30
|
}
|
|
@@ -15,7 +15,7 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
|
|
|
15
15
|
} & ConstructorParameters<typeof AbstractProperty>[0]);
|
|
16
16
|
get declaration(): Maybe<Code>;
|
|
17
17
|
get jsonSignature(): Maybe<Code>;
|
|
18
|
-
get
|
|
18
|
+
get jsonZchema(): AbstractProperty<DiscriminantProperty.Type>["jsonZchema"];
|
|
19
19
|
private get abstract();
|
|
20
20
|
private get initializer();
|
|
21
21
|
private get override();
|
|
@@ -26,20 +26,20 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
26
26
|
invariant(this.visibility === "public");
|
|
27
27
|
}
|
|
28
28
|
get declaration() {
|
|
29
|
-
switch (this.
|
|
29
|
+
switch (this.namedObjectType.declarationType) {
|
|
30
30
|
case "class":
|
|
31
31
|
return Maybe.of(code `${this.abstract ? "abstract " : ""}${this.override ? "override " : ""}readonly ${this.name}: ${this.type.name}${!this.abstract ? code ` = ${this.initializer};` : ";"}`);
|
|
32
32
|
case "interface":
|
|
33
33
|
return Maybe.of(code `readonly ${this.name}: ${this.type.name};`);
|
|
34
34
|
default:
|
|
35
|
-
this.
|
|
35
|
+
this.namedObjectType.declarationType;
|
|
36
36
|
throw new Error("should never reach this point");
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
get jsonSignature() {
|
|
40
40
|
return Maybe.of(code `readonly ${this.name}: ${this.type.name}`);
|
|
41
41
|
}
|
|
42
|
-
get
|
|
42
|
+
get jsonZchema() {
|
|
43
43
|
return Maybe.of({
|
|
44
44
|
key: this.name,
|
|
45
45
|
schema: this.type.values.length > 1
|
|
@@ -48,16 +48,16 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
get abstract() {
|
|
51
|
-
return this.
|
|
51
|
+
return this.namedObjectType.abstract;
|
|
52
52
|
}
|
|
53
53
|
get initializer() {
|
|
54
|
-
return code `${literalOf(this.
|
|
54
|
+
return code `${literalOf(this.namedObjectType.discriminantValue)} as const`;
|
|
55
55
|
}
|
|
56
56
|
get override() {
|
|
57
|
-
return this.
|
|
57
|
+
return this.namedObjectType.parentObjectTypes.length > 0;
|
|
58
58
|
}
|
|
59
59
|
constructorStatements() {
|
|
60
|
-
switch (this.
|
|
60
|
+
switch (this.namedObjectType.declarationType) {
|
|
61
61
|
case "class":
|
|
62
62
|
return [];
|
|
63
63
|
case "interface":
|
|
@@ -68,13 +68,15 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
fromJsonStatements() {
|
|
71
|
-
return !this.abstract &&
|
|
71
|
+
return !this.abstract &&
|
|
72
|
+
this.namedObjectType.declarationType === "interface"
|
|
72
73
|
? [code `const ${this.name} = ${this.initializer};`]
|
|
73
74
|
: [];
|
|
74
75
|
}
|
|
75
76
|
fromRdfResourceValuesExpression() {
|
|
76
|
-
return !this.abstract &&
|
|
77
|
-
|
|
77
|
+
return !this.abstract &&
|
|
78
|
+
this.namedObjectType.declarationType === "interface"
|
|
79
|
+
? Maybe.of(code `${imports.Right}<${literalOf(this.namedObjectType.discriminantValue)}>(${this.initializer})`)
|
|
78
80
|
: Maybe.empty();
|
|
79
81
|
}
|
|
80
82
|
hashStatements({ variables, }) {
|
|
@@ -102,7 +104,7 @@ __decorate([
|
|
|
102
104
|
], DiscriminantProperty.prototype, "jsonSignature", null);
|
|
103
105
|
__decorate([
|
|
104
106
|
Memoize()
|
|
105
|
-
], DiscriminantProperty.prototype, "
|
|
107
|
+
], DiscriminantProperty.prototype, "jsonZchema", null);
|
|
106
108
|
(function (DiscriminantProperty) {
|
|
107
109
|
class Type {
|
|
108
110
|
filterFunction = code `nonextant`;
|
|
@@ -7,7 +7,7 @@ export declare class IdentifierPrefixProperty extends AbstractProperty<StringTyp
|
|
|
7
7
|
readonly filterProperty: AbstractProperty<StringType>["filterProperty"];
|
|
8
8
|
readonly graphqlField: AbstractProperty<StringType>["graphqlField"];
|
|
9
9
|
readonly jsonSignature: Maybe<Code>;
|
|
10
|
-
readonly
|
|
10
|
+
readonly jsonZchema: AbstractProperty<StringType>["jsonZchema"];
|
|
11
11
|
readonly kind = "IdentifierPrefixProperty";
|
|
12
12
|
readonly mutable = false;
|
|
13
13
|
readonly recursive = false;
|
|
@@ -16,7 +16,7 @@ export class IdentifierPrefixProperty extends AbstractProperty {
|
|
|
16
16
|
filterProperty = Maybe.empty();
|
|
17
17
|
graphqlField = Maybe.empty();
|
|
18
18
|
jsonSignature = Maybe.empty();
|
|
19
|
-
|
|
19
|
+
jsonZchema = Maybe.empty();
|
|
20
20
|
kind = "IdentifierPrefixProperty";
|
|
21
21
|
mutable = false;
|
|
22
22
|
recursive = false;
|
|
@@ -29,7 +29,7 @@ export class IdentifierPrefixProperty extends AbstractProperty {
|
|
|
29
29
|
return Maybe.of(code `readonly ${this.name}?: ${this.type.name};`);
|
|
30
30
|
}
|
|
31
31
|
get declaration() {
|
|
32
|
-
if (this.
|
|
32
|
+
if (this.namedObjectType.declarationType === "interface") {
|
|
33
33
|
return Maybe.empty();
|
|
34
34
|
}
|
|
35
35
|
if (!this.own) {
|
|
@@ -38,7 +38,7 @@ export class IdentifierPrefixProperty extends AbstractProperty {
|
|
|
38
38
|
return Maybe.of(code `protected readonly _${this.name}?: ${this.type.name};`);
|
|
39
39
|
}
|
|
40
40
|
get equalsFunction() {
|
|
41
|
-
return this.
|
|
41
|
+
return this.namedObjectType.declarationType === "class"
|
|
42
42
|
? Maybe.of(code `${snippets.strictEquals}`)
|
|
43
43
|
: Maybe.empty();
|
|
44
44
|
}
|
|
@@ -49,7 +49,7 @@ protected ${!this.own ? "override " : ""} get ${this.name}(): ${this.type.name}
|
|
|
49
49
|
}`);
|
|
50
50
|
}
|
|
51
51
|
constructorStatements({ variables, }) {
|
|
52
|
-
switch (this.
|
|
52
|
+
switch (this.namedObjectType.declarationType) {
|
|
53
53
|
case "class":
|
|
54
54
|
return this.declaration
|
|
55
55
|
.map(() => [code `this._${this.name} = ${variables.parameter};`])
|
|
@@ -28,7 +28,7 @@ export declare class IdentifierProperty extends AbstractProperty<BlankNodeType |
|
|
|
28
28
|
get getAccessorDeclaration(): Maybe<Code>;
|
|
29
29
|
get graphqlField(): AbstractProperty<IdentifierType>["graphqlField"];
|
|
30
30
|
get jsonSignature(): Maybe<Code>;
|
|
31
|
-
get
|
|
31
|
+
get jsonZchema(): AbstractProperty<IdentifierType>["jsonZchema"];
|
|
32
32
|
private get abstract();
|
|
33
33
|
private get declarationModifiers();
|
|
34
34
|
private get declarationName();
|