@shaclmate/compiler 2.0.20 → 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,237 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
|
+
import "ts-morph";
|
|
9
|
+
import { Memoize } from "typescript-memoize";
|
|
10
|
+
import { Import } from "../Import.js";
|
|
11
|
+
import { SnippetDeclarations } from "../SnippetDeclarations.js";
|
|
12
|
+
import { Type as _Type } from "../Type.js";
|
|
13
|
+
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
14
|
+
import { ShaclProperty } from "./ShaclProperty.js";
|
|
15
|
+
export class LazyShaclProperty extends ShaclProperty {
|
|
16
|
+
mutable = false;
|
|
17
|
+
recursive = false;
|
|
18
|
+
get graphqlField() {
|
|
19
|
+
return Maybe.of({
|
|
20
|
+
description: this.comment.map(JSON.stringify).extract(),
|
|
21
|
+
name: this.name,
|
|
22
|
+
resolve: `async (source) => ${this.type.graphqlResolveExpression({ variables: { value: `source.${this.name}` } })}`,
|
|
23
|
+
type: this.type.graphqlName.toString(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
(function (LazyShaclProperty) {
|
|
28
|
+
class Type extends _Type {
|
|
29
|
+
discriminatorProperty = Maybe.empty();
|
|
30
|
+
mutable = false;
|
|
31
|
+
typeof = "object";
|
|
32
|
+
resolvedType;
|
|
33
|
+
runtimeClass;
|
|
34
|
+
stubType;
|
|
35
|
+
constructor({ stubType, resolvedType, runtimeClass, }) {
|
|
36
|
+
super();
|
|
37
|
+
this.stubType = stubType;
|
|
38
|
+
this.resolvedType = resolvedType;
|
|
39
|
+
this.runtimeClass = runtimeClass;
|
|
40
|
+
}
|
|
41
|
+
get conversions() {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
conversionExpression: (value) => value,
|
|
45
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof ${this.runtimeClass.rawName}`,
|
|
46
|
+
sourceTypeName: this.name,
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
get equalsFunction() {
|
|
51
|
+
return `((left, right) => ${this.stubType.equalsFunction}(left.${this.runtimeClass.stubPropertyName}, right.${this.runtimeClass.stubPropertyName}))`;
|
|
52
|
+
}
|
|
53
|
+
get graphqlName() {
|
|
54
|
+
return this.resolvedType.graphqlName;
|
|
55
|
+
}
|
|
56
|
+
graphqlResolveExpression({ variables, }) {
|
|
57
|
+
return `(await ${variables.value}.resolve()).unsafeCoerce()`;
|
|
58
|
+
}
|
|
59
|
+
hashStatements({ depth, variables, }) {
|
|
60
|
+
return this.stubType.hashStatements({
|
|
61
|
+
depth: depth + 1,
|
|
62
|
+
variables: {
|
|
63
|
+
...variables,
|
|
64
|
+
value: `${variables.value}.${this.runtimeClass.stubPropertyName}`,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
get jsonName() {
|
|
69
|
+
return this.stubType.jsonName;
|
|
70
|
+
}
|
|
71
|
+
jsonUiSchemaElement(parameters) {
|
|
72
|
+
return this.stubType.jsonUiSchemaElement(parameters);
|
|
73
|
+
}
|
|
74
|
+
jsonZodSchema(parameters) {
|
|
75
|
+
return this.stubType.jsonZodSchema(parameters);
|
|
76
|
+
}
|
|
77
|
+
get name() {
|
|
78
|
+
return this.runtimeClass.name;
|
|
79
|
+
}
|
|
80
|
+
snippetDeclarations(parameters) {
|
|
81
|
+
return this.stubType
|
|
82
|
+
.snippetDeclarations(parameters)
|
|
83
|
+
.concat(this.resolvedType.snippetDeclarations(parameters))
|
|
84
|
+
.concat(this.runtimeClass.snippetDeclaration);
|
|
85
|
+
}
|
|
86
|
+
sparqlConstructTemplateTriples(parameters) {
|
|
87
|
+
return this.stubType.sparqlConstructTemplateTriples(parameters);
|
|
88
|
+
}
|
|
89
|
+
sparqlWherePatterns(parameters) {
|
|
90
|
+
return this.stubType.sparqlWherePatterns(parameters);
|
|
91
|
+
}
|
|
92
|
+
toJsonExpression({ variables, }) {
|
|
93
|
+
return this.stubType.toJsonExpression({
|
|
94
|
+
variables: {
|
|
95
|
+
value: `${variables.value}.${this.runtimeClass.stubPropertyName}`,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
toRdfExpression({ variables, }) {
|
|
100
|
+
return this.stubType.toRdfExpression({
|
|
101
|
+
variables: {
|
|
102
|
+
...variables,
|
|
103
|
+
value: `${variables.value}.${this.runtimeClass.stubPropertyName}`,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
useImports(parameters) {
|
|
108
|
+
return this.resolvedType.useImports(parameters).concat(Import.PURIFY);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
__decorate([
|
|
112
|
+
Memoize()
|
|
113
|
+
], Type.prototype, "equalsFunction", null);
|
|
114
|
+
LazyShaclProperty.Type = Type;
|
|
115
|
+
class ObjectSetType extends Type {
|
|
116
|
+
constructor({ resolvedType, stubType, }) {
|
|
117
|
+
super({
|
|
118
|
+
resolvedType,
|
|
119
|
+
runtimeClass: {
|
|
120
|
+
name: `${syntheticNamePrefix}LazyObjectSet<${resolvedType.itemType.identifierTypeAlias}, ${resolvedType.itemType.name}, ${stubType.itemType.name}>`,
|
|
121
|
+
rawName: `${syntheticNamePrefix}LazyObjectSet`,
|
|
122
|
+
snippetDeclaration: SnippetDeclarations.LazyObjectSet,
|
|
123
|
+
stubPropertyName: "stubs",
|
|
124
|
+
},
|
|
125
|
+
stubType,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
get conversions() {
|
|
129
|
+
const conversions = super.conversions.concat();
|
|
130
|
+
if (this.stubType.itemType.kind === "ObjectType") {
|
|
131
|
+
conversions.push({
|
|
132
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(parameters => ${this.stubType.itemType.newExpression({ parameters: "parameters" })}), resolver: async () => purify.Either.of(${value} as readonly ${this.resolvedType.itemType.name}[]) })`,
|
|
133
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
134
|
+
sourceTypeName: `readonly ${this.resolvedType.itemType.name}[]`,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
conversions.push({
|
|
138
|
+
conversionExpression: () => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: [], resolver: async () => { throw new Error("should never be called"); } })`,
|
|
139
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
140
|
+
sourceTypeName: "undefined",
|
|
141
|
+
});
|
|
142
|
+
return conversions;
|
|
143
|
+
}
|
|
144
|
+
fromJsonExpression(parameters) {
|
|
145
|
+
return `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${this.stubType.fromJsonExpression(parameters)}, resolver: () => Promise.resolve(purify.Left(new Error("unable to resolve identifiers deserialized from JSON"))) })`;
|
|
146
|
+
}
|
|
147
|
+
fromRdfExpression(parameters) {
|
|
148
|
+
const { variables } = parameters;
|
|
149
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifiers) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.objects}({ where: { identifiers, type: "identifiers" }}) }))`;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
__decorate([
|
|
153
|
+
Memoize()
|
|
154
|
+
], ObjectSetType.prototype, "conversions", null);
|
|
155
|
+
LazyShaclProperty.ObjectSetType = ObjectSetType;
|
|
156
|
+
class SingleObjectType extends Type {
|
|
157
|
+
fromJsonExpression(parameters) {
|
|
158
|
+
return `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${this.stubType.fromJsonExpression(parameters)}, resolver: (identifier) => Promise.resolve(purify.Left(new Error(\`unable to resolve identifier \${rdfjsResource.Resource.Identifier.toString(identifier)} deserialized from JSON\`))) })`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
class OptionalObjectType extends SingleObjectType {
|
|
162
|
+
constructor({ resolvedType, stubType, }) {
|
|
163
|
+
super({
|
|
164
|
+
resolvedType,
|
|
165
|
+
runtimeClass: {
|
|
166
|
+
name: `${syntheticNamePrefix}LazyOptionalObject<${resolvedType.itemType.identifierTypeAlias}, ${resolvedType.itemType.name}, ${stubType.itemType.name}>`,
|
|
167
|
+
rawName: `${syntheticNamePrefix}LazyOptionalObject`,
|
|
168
|
+
snippetDeclaration: SnippetDeclarations.LazyOptionalObject,
|
|
169
|
+
stubPropertyName: "stub",
|
|
170
|
+
},
|
|
171
|
+
stubType,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
get conversions() {
|
|
175
|
+
const conversions = super.conversions.concat();
|
|
176
|
+
if (this.stubType.itemType.kind === "ObjectType") {
|
|
177
|
+
conversions.push({
|
|
178
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${value}.map(parameters => ${this.stubType.itemType.newExpression({ parameters: "parameters" })}), resolver: async () => purify.Either.of((${value} as purify.Maybe<${this.resolvedType.itemType.name}>).unsafeCoerce()) })`,
|
|
179
|
+
sourceTypeCheckExpression: (value) => `purify.Maybe.isMaybe(${value})`,
|
|
180
|
+
sourceTypeName: `purify.Maybe<${this.resolvedType.itemType.name}>`,
|
|
181
|
+
}, {
|
|
182
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: purify.Maybe.of(${this.stubType.itemType.newExpression({ parameters: value })}), resolver: async () => purify.Either.of(${value} as ${this.resolvedType.itemType.name}) })`,
|
|
183
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object"`,
|
|
184
|
+
sourceTypeName: this.resolvedType.itemType.name,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
conversions.push({
|
|
188
|
+
conversionExpression: () => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: purify.Maybe.empty(), resolver: async () => { throw new Error("should never be called"); } })`,
|
|
189
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "undefined"`,
|
|
190
|
+
sourceTypeName: "undefined",
|
|
191
|
+
});
|
|
192
|
+
return conversions;
|
|
193
|
+
}
|
|
194
|
+
fromRdfExpression(parameters) {
|
|
195
|
+
const { variables } = parameters;
|
|
196
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.itemType.objectSetMethodNames.object}(identifier) }))`;
|
|
197
|
+
}
|
|
198
|
+
graphqlResolveExpression(parameters) {
|
|
199
|
+
return `${super.graphqlResolveExpression(parameters)}.extractNullable()`;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
__decorate([
|
|
203
|
+
Memoize()
|
|
204
|
+
], OptionalObjectType.prototype, "conversions", null);
|
|
205
|
+
LazyShaclProperty.OptionalObjectType = OptionalObjectType;
|
|
206
|
+
class RequiredObjectType extends SingleObjectType {
|
|
207
|
+
constructor({ resolvedType, stubType, }) {
|
|
208
|
+
super({
|
|
209
|
+
resolvedType,
|
|
210
|
+
runtimeClass: {
|
|
211
|
+
name: `${syntheticNamePrefix}LazyRequiredObject<${resolvedType.identifierTypeAlias}, ${resolvedType.name}, ${stubType.name}>`,
|
|
212
|
+
rawName: `${syntheticNamePrefix}LazyRequiredObject`,
|
|
213
|
+
snippetDeclaration: SnippetDeclarations.LazyRequiredObject,
|
|
214
|
+
stubPropertyName: "stub",
|
|
215
|
+
},
|
|
216
|
+
stubType,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
get conversions() {
|
|
220
|
+
const conversions = super.conversions.concat();
|
|
221
|
+
if (this.stubType.kind === "ObjectType") {
|
|
222
|
+
conversions.push({
|
|
223
|
+
conversionExpression: (value) => `new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}: ${this.stubType.newExpression({ parameters: value })}, resolver: async () => purify.Either.of(${value} as ${this.resolvedType.name}) })`,
|
|
224
|
+
sourceTypeCheckExpression: (value) => `typeof ${value} === "object" && ${value} instanceof ${this.resolvedType.name}`,
|
|
225
|
+
sourceTypeName: this.resolvedType.name,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
return conversions;
|
|
229
|
+
}
|
|
230
|
+
fromRdfExpression(parameters) {
|
|
231
|
+
const { variables } = parameters;
|
|
232
|
+
return `${this.stubType.fromRdfExpression(parameters)}.map(${this.runtimeClass.stubPropertyName} => new ${this.runtimeClass.name}({ ${this.runtimeClass.stubPropertyName}, resolver: (identifier) => ${variables.objectSet}.${this.resolvedType.objectSetMethodNames.object}(identifier) }))`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
LazyShaclProperty.RequiredObjectType = RequiredObjectType;
|
|
236
|
+
})(LazyShaclProperty || (LazyShaclProperty = {}));
|
|
237
|
+
//# sourceMappingURL=LazyShaclProperty.js.map
|
|
@@ -1,33 +1,30 @@
|
|
|
1
|
-
import type { BlankNode, Literal, NamedNode, Variable } from "@rdfjs/types";
|
|
2
1
|
import type { Maybe } from "purify-ts";
|
|
3
2
|
import { type GetAccessorDeclarationStructure, type OptionalKind, type PropertyDeclarationStructure, type PropertySignatureStructure, Scope } from "ts-morph";
|
|
4
|
-
import type { PropertyVisibility
|
|
3
|
+
import type { PropertyVisibility } from "../../../enums/index.js";
|
|
5
4
|
import type { Import } from "../Import.js";
|
|
5
|
+
import type { ObjectType } from "../ObjectType.js";
|
|
6
6
|
import type { Type } from "../Type.js";
|
|
7
|
-
export declare abstract class Property<TypeT extends {
|
|
8
|
-
readonly mutable: boolean;
|
|
9
|
-
readonly name: string;
|
|
10
|
-
}> {
|
|
11
|
-
/**
|
|
12
|
-
* Optional get accessor to include in a class declaration of the object type.
|
|
13
|
-
*/
|
|
14
|
-
abstract readonly classGetAccessorDeclaration: Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
15
|
-
/**
|
|
16
|
-
* Optional property declaration to include in a class declaration of the object type.
|
|
17
|
-
*/
|
|
18
|
-
abstract readonly classPropertyDeclaration: Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
7
|
+
export declare abstract class Property<TypeT extends Pick<Type, "mutable" | "name">> {
|
|
19
8
|
/**
|
|
20
9
|
* Optional property to include in the parameters object of a class constructor.
|
|
21
10
|
*/
|
|
22
11
|
abstract readonly constructorParametersPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
23
12
|
/**
|
|
24
|
-
* Function declaration that takes two values of the property and compares them, returning
|
|
13
|
+
* Function declaration that takes two values of the property and compares them, returning an $EqualsResult.
|
|
25
14
|
*/
|
|
26
15
|
abstract readonly equalsFunction: string;
|
|
27
16
|
/**
|
|
28
|
-
*
|
|
17
|
+
* Optional get accessor to include in a class declaration of the object type.
|
|
18
|
+
*/
|
|
19
|
+
abstract readonly getAccessorDeclaration: Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
20
|
+
/**
|
|
21
|
+
* GraphQL.js field definition.
|
|
29
22
|
*/
|
|
30
|
-
abstract readonly
|
|
23
|
+
abstract readonly graphqlField: Maybe<{
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
type: string;
|
|
27
|
+
}>;
|
|
31
28
|
/**
|
|
32
29
|
* Signature of the property when serialized to JSON (the type of toJsonObjectMember).
|
|
33
30
|
*/
|
|
@@ -41,14 +38,17 @@ export declare abstract class Property<TypeT extends {
|
|
|
41
38
|
*/
|
|
42
39
|
readonly name: string;
|
|
43
40
|
/**
|
|
44
|
-
*
|
|
45
|
-
* relies on. For example, the equals function/method of ObjectType has a custom return type that's the same across all
|
|
46
|
-
* ObjectType's. Instead of re-declaring the return type anonymously on every equals function, declare a named type
|
|
47
|
-
* as a snippet and reference it.
|
|
48
|
-
*
|
|
49
|
-
* The generator deduplicates snippet declarations across all types before adding them to the source.
|
|
41
|
+
* Optional property declaration to include in a class declaration of the object type.
|
|
50
42
|
*/
|
|
51
|
-
abstract readonly
|
|
43
|
+
abstract readonly propertyDeclaration: Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
44
|
+
/**
|
|
45
|
+
* Signature of the property in an interface version of the object.
|
|
46
|
+
*/
|
|
47
|
+
abstract readonly propertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
48
|
+
/**
|
|
49
|
+
* Is the property's type the ObjectType or does its type indirectly reference the ObjectType?
|
|
50
|
+
*/
|
|
51
|
+
abstract readonly recursive: boolean;
|
|
52
52
|
/**
|
|
53
53
|
* Property type
|
|
54
54
|
. */
|
|
@@ -57,16 +57,10 @@ export declare abstract class Property<TypeT extends {
|
|
|
57
57
|
* Property visibility: private, protected, public.
|
|
58
58
|
*/
|
|
59
59
|
readonly visibility: PropertyVisibility;
|
|
60
|
-
protected readonly
|
|
61
|
-
|
|
62
|
-
readonly declarationType: TsObjectDeclarationType;
|
|
63
|
-
readonly features: Set<TsFeature>;
|
|
64
|
-
readonly mutable: () => boolean;
|
|
65
|
-
};
|
|
66
|
-
constructor({ dataFactoryVariable, name, objectType, type, visibility, }: {
|
|
67
|
-
dataFactoryVariable: string;
|
|
60
|
+
protected readonly objectType: ObjectType;
|
|
61
|
+
constructor({ name, objectType, type, visibility, }: {
|
|
68
62
|
name: string;
|
|
69
|
-
objectType:
|
|
63
|
+
objectType: ObjectType;
|
|
70
64
|
type: TypeT;
|
|
71
65
|
visibility: PropertyVisibility;
|
|
72
66
|
});
|
|
@@ -76,9 +70,9 @@ export declare abstract class Property<TypeT extends {
|
|
|
76
70
|
abstract get declarationImports(): readonly Import[];
|
|
77
71
|
protected static visibilityToScope(visibility: PropertyVisibility): Scope | undefined;
|
|
78
72
|
/**
|
|
79
|
-
* Statements to assign the parameter of described by constructorParametersPropertySignature to a class member.
|
|
73
|
+
* Statements to assign the parameter of described by constructorParametersPropertySignature to a class or interface member.
|
|
80
74
|
*/
|
|
81
|
-
abstract
|
|
75
|
+
abstract constructorStatements(parameters: {
|
|
82
76
|
variables: {
|
|
83
77
|
parameter: string;
|
|
84
78
|
};
|
|
@@ -98,6 +92,7 @@ export declare abstract class Property<TypeT extends {
|
|
|
98
92
|
variables: {
|
|
99
93
|
context: string;
|
|
100
94
|
languageIn: string;
|
|
95
|
+
objectSet: string;
|
|
101
96
|
resource: string;
|
|
102
97
|
};
|
|
103
98
|
}): readonly string[];
|
|
@@ -105,14 +100,6 @@ export declare abstract class Property<TypeT extends {
|
|
|
105
100
|
* Statements to hash this property using a hasher instance.
|
|
106
101
|
*/
|
|
107
102
|
abstract hashStatements(parameters: Parameters<Type["hashStatements"]>[0]): readonly string[];
|
|
108
|
-
/**
|
|
109
|
-
* Companion to classConstructorStatements with a similar purpose in an interface's create() function.
|
|
110
|
-
*/
|
|
111
|
-
abstract interfaceConstructorStatements(parameters: {
|
|
112
|
-
variables: {
|
|
113
|
-
parameter: string;
|
|
114
|
-
};
|
|
115
|
-
}): readonly string[];
|
|
116
103
|
/**
|
|
117
104
|
* Element object (usually a control https://jsonforms.io/docs/uischema/controls) for a JSON Forms UI schema.
|
|
118
105
|
*/
|
|
@@ -132,6 +119,15 @@ export declare abstract class Property<TypeT extends {
|
|
|
132
119
|
readonly key: string;
|
|
133
120
|
readonly schema: string;
|
|
134
121
|
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Reusable function, type, and other declarations that are not particular to this property but that property-specific code
|
|
124
|
+
* relies on. For example, the equals function/method of ObjectType has a custom return type that's the same across all
|
|
125
|
+
* ObjectType's. Instead of re-declaring the return type anonymously on every equals function, declare a named type
|
|
126
|
+
* as a snippet and reference it.
|
|
127
|
+
*
|
|
128
|
+
* The generator deduplicates snippet declarations across all types before adding them to the source.
|
|
129
|
+
*/
|
|
130
|
+
abstract snippetDeclarations(parameters: Parameters<Type["snippetDeclarations"]>[0]): readonly string[];
|
|
135
131
|
/**
|
|
136
132
|
* An array of SPARQL.js CONSTRUCT template triples for this property as strings (so they can incorporate runtime calls).
|
|
137
133
|
*/
|
|
@@ -164,6 +160,5 @@ export declare abstract class Property<TypeT extends {
|
|
|
164
160
|
abstract toRdfStatements(parameters: {
|
|
165
161
|
variables: Omit<Parameters<Type["toRdfExpression"]>[0]["variables"], "predicate">;
|
|
166
162
|
}): readonly string[];
|
|
167
|
-
protected rdfjsTermExpression(rdfjsTerm: Omit<BlankNode, "equals"> | Omit<Literal, "equals"> | Omit<NamedNode, "equals"> | Omit<Variable, "equals">): string;
|
|
168
163
|
}
|
|
169
164
|
//# sourceMappingURL=Property.d.ts.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Scope, } from "ts-morph";
|
|
2
|
-
import { rdfjsTermExpression } from "./rdfjsTermExpression.js";
|
|
3
2
|
export class Property {
|
|
4
3
|
/**
|
|
5
4
|
* TypeScript identifier-safe name of the property.
|
|
@@ -13,10 +12,8 @@ export class Property {
|
|
|
13
12
|
* Property visibility: private, protected, public.
|
|
14
13
|
*/
|
|
15
14
|
visibility;
|
|
16
|
-
dataFactoryVariable;
|
|
17
15
|
objectType;
|
|
18
|
-
constructor({
|
|
19
|
-
this.dataFactoryVariable = dataFactoryVariable;
|
|
16
|
+
constructor({ name, objectType, type, visibility, }) {
|
|
20
17
|
this.name = name;
|
|
21
18
|
this.objectType = objectType;
|
|
22
19
|
this.type = type;
|
|
@@ -32,11 +29,5 @@ export class Property {
|
|
|
32
29
|
return undefined;
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
rdfjsTermExpression(rdfjsTerm) {
|
|
36
|
-
return rdfjsTermExpression({
|
|
37
|
-
dataFactoryVariable: this.dataFactoryVariable,
|
|
38
|
-
rdfjsTerm,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
32
|
}
|
|
42
33
|
//# sourceMappingURL=Property.js.map
|
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
import type * as rdfjs from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
3
|
import type { GetAccessorDeclarationStructure, OptionalKind, PropertyDeclarationStructure, PropertySignatureStructure } from "ts-morph";
|
|
4
|
-
import type { IdentifierType } from "../IdentifierType.js";
|
|
5
4
|
import type { Import } from "../Import.js";
|
|
6
5
|
import type { Type } from "../Type.js";
|
|
7
6
|
import { Property } from "./Property.js";
|
|
8
|
-
export declare class ShaclProperty extends Property<
|
|
9
|
-
readonly
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
constructor({ comment, description, label, mutable, path, ...superParameters }: {
|
|
7
|
+
export declare abstract class ShaclProperty<TypeT extends Type> extends Property<TypeT> {
|
|
8
|
+
protected readonly comment: Maybe<string>;
|
|
9
|
+
protected readonly description: Maybe<string>;
|
|
10
|
+
protected readonly label: Maybe<string>;
|
|
11
|
+
readonly path: rdfjs.NamedNode;
|
|
12
|
+
constructor({ comment, description, label, path, ...superParameters }: {
|
|
15
13
|
comment: Maybe<string>;
|
|
16
14
|
description: Maybe<string>;
|
|
17
15
|
label: Maybe<string>;
|
|
18
|
-
mutable: boolean;
|
|
19
16
|
path: rdfjs.NamedNode;
|
|
20
|
-
|
|
21
|
-
} & ConstructorParameters<typeof Property>[0]);
|
|
22
|
-
get classGetAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
23
|
-
get classPropertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
24
|
-
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
25
|
-
get declarationImports(): readonly Import[];
|
|
17
|
+
} & ConstructorParameters<typeof Property<TypeT>>[0]);
|
|
26
18
|
get equalsFunction(): string;
|
|
27
|
-
get
|
|
19
|
+
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
20
|
+
constructorStatements({ variables, }: Parameters<Property<TypeT>["constructorStatements"]>[0]): readonly string[];
|
|
21
|
+
fromJsonStatements({ variables, }: Parameters<Property<TypeT>["fromJsonStatements"]>[0]): readonly string[];
|
|
22
|
+
get getAccessorDeclaration(): Maybe<OptionalKind<GetAccessorDeclarationStructure>>;
|
|
23
|
+
hashStatements(parameters: Parameters<Property<TypeT>["hashStatements"]>[0]): readonly string[];
|
|
28
24
|
get jsonPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
toRdfStatements({ variables, }: Parameters<Property<Type>["toRdfStatements"]>[0]): readonly string[];
|
|
25
|
+
jsonUiSchemaElement({ variables, }: Parameters<Property<TypeT>["jsonUiSchemaElement"]>[0]): Maybe<string>;
|
|
26
|
+
jsonZodSchema(parameters: Parameters<Property<TypeT>["jsonZodSchema"]>[0]): ReturnType<Property<TypeT>["jsonZodSchema"]>;
|
|
27
|
+
get propertyDeclaration(): Maybe<OptionalKind<PropertyDeclarationStructure>>;
|
|
28
|
+
get declarationImports(): readonly Import[];
|
|
29
|
+
get propertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
30
|
+
snippetDeclarations(parameters: Parameters<Property<Type>["snippetDeclarations"]>[0]): readonly string[];
|
|
31
|
+
fromRdfStatements({ variables, }: Parameters<Property<TypeT>["fromRdfStatements"]>[0]): readonly string[];
|
|
32
|
+
sparqlConstructTemplateTriples({ variables, }: Parameters<Property<TypeT>["sparqlConstructTemplateTriples"]>[0]): readonly string[];
|
|
33
|
+
sparqlWherePatterns({ variables, }: Parameters<Property<TypeT>["sparqlWherePatterns"]>[0]): readonly string[];
|
|
34
|
+
toJsonObjectMember(parameters: Parameters<Property<TypeT>["toJsonObjectMember"]>[0]): Maybe<string>;
|
|
35
|
+
toRdfStatements({ variables, }: Parameters<Property<TypeT>["toRdfStatements"]>[0]): readonly string[];
|
|
36
|
+
protected get declarationComment(): string | undefined;
|
|
37
|
+
protected get predicate(): string;
|
|
43
38
|
}
|
|
44
39
|
//# sourceMappingURL=ShaclProperty.d.ts.map
|