@shaclmate/compiler 2.0.23 → 3.0.0
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 +5 -5
- package/dist/ShapesGraphToAstTransformer.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.d.ts +2 -0
- package/dist/_ShapesGraphToAstTransformer/InheritableShapeConstraints.js +2 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.d.ts +15 -0
- package/dist/_ShapesGraphToAstTransformer/ShapeStack.js +51 -0
- package/dist/_ShapesGraphToAstTransformer/index.d.ts +5 -5
- package/dist/_ShapesGraphToAstTransformer/index.js +5 -5
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +77 -29
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompositeType.js +185 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstIdentifierType.js +32 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.d.ts +10 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstLiteralType.js +46 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.d.ts +12 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +24 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.d.ts +13 -0
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstType.js +14 -0
- package/dist/ast/OptionType.d.ts +0 -2
- package/dist/ast/SetType.d.ts +1 -6
- package/dist/ast/index.d.ts +1 -0
- package/dist/ast/index.js +1 -0
- package/dist/generators/json/AstJsonGenerator.js +7 -1
- package/dist/generators/ts/BooleanType.d.ts +2 -1
- package/dist/generators/ts/BooleanType.js +9 -4
- package/dist/generators/ts/DateTimeType.d.ts +2 -1
- package/dist/generators/ts/DateTimeType.js +9 -4
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +20 -14
- package/dist/generators/ts/Import.d.ts +2 -1
- package/dist/generators/ts/Import.js +29 -24
- package/dist/generators/ts/ListType.js +16 -5
- package/dist/generators/ts/LiteralType.d.ts +5 -2
- package/dist/generators/ts/LiteralType.js +81 -15
- package/dist/generators/ts/NumberType.d.ts +2 -1
- package/dist/generators/ts/NumberType.js +9 -4
- package/dist/generators/ts/ObjectType.d.ts +3 -2
- package/dist/generators/ts/ObjectType.js +16 -6
- package/dist/generators/ts/ObjectUnionType.d.ts +2 -0
- package/dist/generators/ts/ObjectUnionType.js +21 -9
- package/dist/generators/ts/OptionType.d.ts +1 -1
- package/dist/generators/ts/OptionType.js +6 -4
- package/dist/generators/ts/PrimitiveType.d.ts +1 -1
- package/dist/generators/ts/PrimitiveType.js +6 -3
- package/dist/generators/ts/SetType.d.ts +4 -4
- package/dist/generators/ts/SetType.js +15 -12
- package/dist/generators/ts/SnippetDeclarations.d.ts +3 -2
- package/dist/generators/ts/SnippetDeclarations.js +41 -3
- package/dist/generators/ts/StringType.d.ts +2 -1
- package/dist/generators/ts/StringType.js +14 -7
- package/dist/generators/ts/TermType.d.ts +18 -19
- package/dist/generators/ts/TermType.js +55 -51
- package/dist/generators/ts/TsGenerator.js +24 -12
- package/dist/generators/ts/Type.d.ts +12 -3
- package/dist/generators/ts/Type.js +1 -0
- package/dist/generators/ts/TypeFactory.d.ts +8 -0
- package/dist/generators/ts/TypeFactory.js +114 -23
- package/dist/generators/ts/UnionType.js +1 -1
- package/dist/generators/ts/_ObjectType/EagerShaclProperty.js +3 -2
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/IdentifierPrefixProperty.js +15 -1
- package/dist/generators/ts/_ObjectType/IdentifierProperty.d.ts +6 -6
- package/dist/generators/ts/_ObjectType/IdentifierProperty.js +59 -29
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.d.ts +14 -1
- package/dist/generators/ts/_ObjectType/LazyShaclProperty.js +89 -11
- package/dist/generators/ts/_ObjectType/Property.d.ts +10 -4
- package/dist/generators/ts/_ObjectType/ShaclProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/ShaclProperty.js +14 -2
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.d.ts +1 -1
- package/dist/generators/ts/_ObjectType/TypeDiscriminatorProperty.js +1 -1
- package/dist/generators/ts/_ObjectType/classDeclaration.js +16 -12
- package/dist/generators/ts/_ObjectType/createFunctionDeclaration.js +22 -10
- package/dist/generators/ts/_ObjectType/equalsFunctionOrMethodDeclaration.js +3 -1
- package/dist/generators/ts/_ObjectType/graphqlTypeVariableStatement.js +14 -2
- package/dist/generators/ts/_ObjectType/jsonFunctionDeclarations.js +1 -1
- package/dist/generators/ts/_ObjectType/rdfFunctionDeclarations.js +95 -84
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryFunctionDeclaration.js +3 -3
- package/dist/generators/ts/_ObjectType/sparqlConstructQueryStringFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_ObjectType/sparqlFunctionDeclarations.js +35 -15
- package/dist/generators/ts/_ObjectType/toRdfFunctionOrMethodDeclaration.js +19 -12
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.d.ts +8 -0
- package/dist/generators/ts/forwardingObjectSetClassDeclaration.js +29 -0
- package/dist/generators/ts/objectSetDeclarations.js +2 -0
- package/dist/generators/ts/rdfjsDatasetObjectSetClassDeclaration.js +26 -19
- package/dist/generators/ts/rdfjsTermExpression.js +3 -3
- package/dist/generators/ts/sparqlObjectSetClassDeclaration.js +6 -6
- package/dist/input/PropertyPath.d.ts +2 -3
- package/dist/input/PropertyPath.js +6 -8
- package/dist/input/ShapesGraph.js +4 -8
- package/dist/input/generated.d.ts +96 -54
- package/dist/input/generated.js +1350 -744
- package/package.json +5 -8
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstCompositeType.js +0 -193
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstIdentifierType.js +0 -29
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.d.ts +0 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstLiteralType.js +0 -43
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.d.ts +0 -14
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstTermType.js +0 -21
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.d.ts +0 -15
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstType.js +0 -60
|
@@ -120,31 +120,62 @@ export class TermType extends Type {
|
|
|
120
120
|
: `((${variables.value}.termType === "${nodeKind}") ? (${valueToNodeKind}) : (${expression}))`;
|
|
121
121
|
}, "");
|
|
122
122
|
}
|
|
123
|
-
fromRdfExpression(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
123
|
+
fromRdfExpression(parameters) {
|
|
124
|
+
// invariant(
|
|
125
|
+
// this.nodeKinds.has("Literal") &&
|
|
126
|
+
// (this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")),
|
|
127
|
+
// "IdentifierType and LiteralType should override",
|
|
128
|
+
// );
|
|
129
|
+
const chain = this.fromRdfExpressionChain(parameters);
|
|
130
|
+
const { variables } = parameters;
|
|
131
|
+
return [
|
|
132
|
+
variables.resourceValues,
|
|
133
|
+
chain.defaultValue,
|
|
134
|
+
chain.hasValues,
|
|
135
|
+
chain.languageIn,
|
|
136
|
+
chain.preferredLanguages,
|
|
137
|
+
chain.valueTo,
|
|
138
|
+
]
|
|
139
|
+
.filter((_) => typeof _ !== "undefined")
|
|
140
|
+
.join(".");
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The fromRdfExpression for a term type can be decomposed into multiple sub-expressions with different purposes:
|
|
144
|
+
*
|
|
145
|
+
* defaultValues: add the default value to the values sequence if the latter doesn't contain values already
|
|
146
|
+
* hasValues: test whether the values sequence has sh:hasValue values
|
|
147
|
+
* languageIn: filter the values sequence to literals with the right sh:languageIn (or runtime languageIn)
|
|
148
|
+
* valueTo: convert values in the values sequence to the appropriate term type/sub-type (literal, string, etc.)
|
|
149
|
+
*
|
|
150
|
+
* Considering the sub-expressions as a record instead of an array allows them to be selectively overridden by subclasses.
|
|
151
|
+
*/
|
|
152
|
+
fromRdfExpressionChain({ variables, }) {
|
|
153
|
+
let valueToExpression = "purify.Either.of<Error, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>(value.toTerm())";
|
|
154
|
+
if (this.nodeKinds.size < 3) {
|
|
155
|
+
const eitherTypeParameters = `<Error, ${this.name}>`;
|
|
156
|
+
valueToExpression = `${valueToExpression}.chain(term => {
|
|
157
|
+
switch (term.termType) {
|
|
158
|
+
${[...this.nodeKinds].map((nodeKind) => `case "${nodeKind}":`).join("\n")} return purify.Either.of${eitherTypeParameters}(term);
|
|
159
|
+
default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "term", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })}));
|
|
160
|
+
}})`;
|
|
133
161
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
162
|
+
return {
|
|
163
|
+
defaultValue: this.defaultValue
|
|
164
|
+
.map((defaultValue) => `map(values => values.length > 0 ? values : new rdfjsResource.Resource.Value(${objectInitializer({ subject: variables.resource, predicate: variables.predicate, object: rdfjsTermExpression(defaultValue) })}).toValues())`)
|
|
165
|
+
.extract(),
|
|
166
|
+
hasValues: this.hasValues.length > 0
|
|
167
|
+
? `chain(values => {
|
|
168
|
+
for (const hasValue of [${this.hasValues.map(rdfjsTermExpression).join(", ")}]) {
|
|
169
|
+
const findResult = values.find(value => value.toTerm().equals(hasValue));
|
|
170
|
+
if (findResult.isLeft()) {
|
|
171
|
+
return findResult;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return purify.Either.of<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>>(values);
|
|
175
|
+
})`
|
|
176
|
+
: undefined,
|
|
177
|
+
valueTo: `chain(values => values.chainMap(value => ${valueToExpression}))`,
|
|
178
|
+
};
|
|
148
179
|
}
|
|
149
180
|
graphqlResolveExpression(_parameters) {
|
|
150
181
|
throw new Error("not implemented");
|
|
@@ -231,33 +262,6 @@ export class TermType extends Type {
|
|
|
231
262
|
}
|
|
232
263
|
return imports;
|
|
233
264
|
}
|
|
234
|
-
/**
|
|
235
|
-
* Filter the rdfjsResource.Resource.Values to those that are relevant to the type.
|
|
236
|
-
*
|
|
237
|
-
* This is done before
|
|
238
|
-
*/
|
|
239
|
-
propertyFilterRdfResourceValuesExpression({ variables, }) {
|
|
240
|
-
return variables.resourceValues;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Convert an rdfjsResource.Resource.Value to a value of this type.
|
|
244
|
-
* @param variables
|
|
245
|
-
* @protected
|
|
246
|
-
*/
|
|
247
|
-
propertyFromRdfResourceValueExpression({ variables, }) {
|
|
248
|
-
invariant(this.nodeKinds.has("Literal") &&
|
|
249
|
-
(this.nodeKinds.has("BlankNode") || this.nodeKinds.has("NamedNode")), "IdentifierType and LiteralType should override");
|
|
250
|
-
let expression = `purify.Either.of<Error, rdfjs.BlankNode | rdfjs.Literal | rdfjs.NamedNode>(${variables.resourceValue}.toTerm())`;
|
|
251
|
-
if (this.nodeKinds.size < 3) {
|
|
252
|
-
const eitherTypeParameters = `<Error, ${this.name}>`;
|
|
253
|
-
expression = `${expression}.chain(term => {
|
|
254
|
-
switch (term.termType) {
|
|
255
|
-
${[...this.nodeKinds].map((nodeKind) => `case "${nodeKind}":`).join("\n")} return purify.Either.of${eitherTypeParameters}(term);
|
|
256
|
-
default: return purify.Left${eitherTypeParameters}(new rdfjsResource.Resource.MistypedValueError(${objectInitializer({ actualValue: "term", expectedValueType: JSON.stringify(this.name), focusResource: variables.resource, predicate: variables.predicate })}));
|
|
257
|
-
}})`;
|
|
258
|
-
}
|
|
259
|
-
return expression;
|
|
260
|
-
}
|
|
261
265
|
}
|
|
262
266
|
__decorate([
|
|
263
267
|
Memoize()
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { invariant } from "ts-invariant";
|
|
1
2
|
import { Project, } from "ts-morph";
|
|
2
3
|
import * as ast from "../../ast/index.js";
|
|
4
|
+
import { Import } from "./Import.js";
|
|
3
5
|
import { ObjectType } from "./ObjectType.js";
|
|
4
6
|
import { ObjectUnionType } from "./ObjectUnionType.js";
|
|
5
7
|
import { TypeFactory } from "./TypeFactory.js";
|
|
@@ -27,33 +29,43 @@ export class TsGenerator {
|
|
|
27
29
|
return project.getFileSystem().readFileSync(sourceFile.getFilePath());
|
|
28
30
|
}
|
|
29
31
|
addStatements({ objectTypes, objectUnionTypes, sourceFile, }) {
|
|
30
|
-
// sourceFile.addStatements(this.configuration.dataFactoryImport);
|
|
31
|
-
sourceFile.addStatements('import N3, { DataFactory as dataFactory } from "n3"');
|
|
32
32
|
const declaredTypes = [
|
|
33
33
|
...objectTypes,
|
|
34
34
|
...objectUnionTypes,
|
|
35
35
|
];
|
|
36
36
|
// Gather imports
|
|
37
|
-
const imports = [];
|
|
37
|
+
const imports = [Import.DATA_FACTORY, Import.DATASET_FACTORY];
|
|
38
38
|
for (const declaredType of declaredTypes) {
|
|
39
39
|
imports.push(...declaredType.declarationImports);
|
|
40
40
|
}
|
|
41
41
|
// Deduplicate and add imports
|
|
42
|
-
const
|
|
43
|
-
const
|
|
42
|
+
const stringImports = new Set();
|
|
43
|
+
const structureImports = [];
|
|
44
44
|
for (const import_ of imports) {
|
|
45
45
|
if (typeof import_ === "string") {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
stringImports.add(import_);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const importWithSameModuleSpecifier = structureImports.find((structureImport) => structureImport.moduleSpecifier === import_.moduleSpecifier);
|
|
50
|
+
if (!importWithSameModuleSpecifier) {
|
|
51
|
+
structureImports.push(import_);
|
|
50
52
|
continue;
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
// Merge named imports
|
|
55
|
+
invariant(!import_.namespaceImport);
|
|
56
|
+
invariant(Array.isArray(import_.namedImports) &&
|
|
57
|
+
import_.namedImports.every((value) => typeof value === "string"));
|
|
58
|
+
invariant(!importWithSameModuleSpecifier.namespaceImport);
|
|
59
|
+
invariant(Array.isArray(importWithSameModuleSpecifier.namedImports) &&
|
|
60
|
+
importWithSameModuleSpecifier.namedImports.every((value) => typeof value === "string"));
|
|
61
|
+
for (const newNamedImport of import_.namedImports) {
|
|
62
|
+
if (!importWithSameModuleSpecifier.namedImports.includes(newNamedImport)) {
|
|
63
|
+
importWithSameModuleSpecifier.namedImports.push(newNamedImport);
|
|
64
|
+
}
|
|
55
65
|
}
|
|
56
66
|
}
|
|
67
|
+
sourceFile.addStatements([...stringImports]);
|
|
68
|
+
sourceFile.addStatements(structureImports);
|
|
57
69
|
// Deduplicate and add snippet declarations
|
|
58
70
|
const addedSnippetDeclarations = new Set();
|
|
59
71
|
for (const declaredType of declaredTypes) {
|
|
@@ -50,15 +50,21 @@ export declare abstract class Type {
|
|
|
50
50
|
};
|
|
51
51
|
}): string;
|
|
52
52
|
/**
|
|
53
|
-
* An expression that converts a rdfjsResource.Resource.Values to a
|
|
54
|
-
*
|
|
53
|
+
* An expression that converts a purify.Either<Error, rdfjsResource.Resource.Values<rdfjsResource.Resource.Value>> to a
|
|
54
|
+
* purify.Either<Error, rdfjsResource.Resource.Values<this type>>.
|
|
55
|
+
*
|
|
56
|
+
* Some types need to filter on the set of all objects/values of a (subject, predicate). For example, all sh:hasValue values must be present in the set for any values
|
|
57
|
+
* to be considered valid. Similar
|
|
58
|
+
*
|
|
59
|
+
* Values may also need to be sorted. For example, specifying preferredLanguages should sort the values in the order of the specified languages so that the first value
|
|
60
|
+
* (if it exists) is always of the first preferred language.
|
|
55
61
|
*/
|
|
56
62
|
abstract fromRdfExpression(parameters: {
|
|
57
63
|
variables: {
|
|
58
64
|
context: string;
|
|
59
65
|
ignoreRdfType?: boolean;
|
|
60
|
-
languageIn: string;
|
|
61
66
|
objectSet: string;
|
|
67
|
+
preferredLanguages: string;
|
|
62
68
|
predicate: string;
|
|
63
69
|
resource: string;
|
|
64
70
|
resourceValues: string;
|
|
@@ -69,6 +75,7 @@ export declare abstract class Type {
|
|
|
69
75
|
*/
|
|
70
76
|
abstract graphqlResolveExpression(parameters: {
|
|
71
77
|
variables: {
|
|
78
|
+
args: string;
|
|
72
79
|
value: string;
|
|
73
80
|
};
|
|
74
81
|
}): string;
|
|
@@ -154,6 +161,7 @@ export declare abstract class Type {
|
|
|
154
161
|
variables: {
|
|
155
162
|
object: string;
|
|
156
163
|
predicate: string;
|
|
164
|
+
preferredLanguages: string;
|
|
157
165
|
subject: string;
|
|
158
166
|
variablePrefix: string;
|
|
159
167
|
};
|
|
@@ -161,6 +169,7 @@ export declare abstract class Type {
|
|
|
161
169
|
allowIgnoreRdfType: boolean;
|
|
162
170
|
context: "subject";
|
|
163
171
|
variables: {
|
|
172
|
+
preferredLanguages: string;
|
|
164
173
|
subject: string;
|
|
165
174
|
variablePrefix: string;
|
|
166
175
|
};
|
|
@@ -66,6 +66,7 @@ export class Type {
|
|
|
66
66
|
allowIgnoreRdfType,
|
|
67
67
|
context: "subject",
|
|
68
68
|
variables: {
|
|
69
|
+
preferredLanguages: variables.preferredLanguages,
|
|
69
70
|
subject: variables.object,
|
|
70
71
|
variablePrefix: variables.object.substring(objectPrefix.length, variables.object.length - objectSuffix.length),
|
|
71
72
|
},
|
|
@@ -2,9 +2,17 @@ import type * as ast from "../../ast/index.js";
|
|
|
2
2
|
import { ObjectType } from "./ObjectType.js";
|
|
3
3
|
import type { Type } from "./Type.js";
|
|
4
4
|
export declare class TypeFactory {
|
|
5
|
+
private cachedBooleanType;
|
|
6
|
+
private cachedDateType;
|
|
7
|
+
private cachedDateTimeType;
|
|
8
|
+
private cachedFloatType;
|
|
9
|
+
private cachedIdentifierType;
|
|
10
|
+
private cachedIntType;
|
|
11
|
+
private cachedNamedIdentifierType;
|
|
5
12
|
private cachedObjectTypePropertiesByIdentifier;
|
|
6
13
|
private cachedObjectTypesByIdentifier;
|
|
7
14
|
private cachedObjectUnionTypesByIdentifier;
|
|
15
|
+
private cachedStringType;
|
|
8
16
|
createObjectTypeFromAstType(astType: ast.ObjectType): ObjectType;
|
|
9
17
|
createTypeFromAstType(astType: ast.Type): Type;
|
|
10
18
|
private createObjectTypePropertyFromAstProperty;
|
|
@@ -24,9 +24,69 @@ import { UnionType } from "./UnionType.js";
|
|
|
24
24
|
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
25
25
|
import { tsName } from "./tsName.js";
|
|
26
26
|
export class TypeFactory {
|
|
27
|
+
cachedBooleanType = new BooleanType({
|
|
28
|
+
defaultValue: Maybe.empty(),
|
|
29
|
+
hasValues: [],
|
|
30
|
+
in_: [],
|
|
31
|
+
languageIn: [],
|
|
32
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
33
|
+
primitiveIn: [],
|
|
34
|
+
});
|
|
35
|
+
cachedDateType = new DateType({
|
|
36
|
+
defaultValue: Maybe.empty(),
|
|
37
|
+
hasValues: [],
|
|
38
|
+
in_: [],
|
|
39
|
+
languageIn: [],
|
|
40
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
41
|
+
primitiveIn: [],
|
|
42
|
+
});
|
|
43
|
+
cachedDateTimeType = new DateTimeType({
|
|
44
|
+
defaultValue: Maybe.empty(),
|
|
45
|
+
hasValues: [],
|
|
46
|
+
in_: [],
|
|
47
|
+
languageIn: [],
|
|
48
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
49
|
+
primitiveIn: [],
|
|
50
|
+
});
|
|
51
|
+
cachedFloatType = new FloatType({
|
|
52
|
+
defaultValue: Maybe.empty(),
|
|
53
|
+
hasValues: [],
|
|
54
|
+
in_: [],
|
|
55
|
+
languageIn: [],
|
|
56
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
57
|
+
primitiveIn: [],
|
|
58
|
+
});
|
|
59
|
+
cachedIdentifierType = new IdentifierType({
|
|
60
|
+
defaultValue: Maybe.empty(),
|
|
61
|
+
hasValues: [],
|
|
62
|
+
in_: [],
|
|
63
|
+
nodeKinds: new Set(["BlankNode", "NamedNode"]),
|
|
64
|
+
});
|
|
65
|
+
cachedIntType = new IntType({
|
|
66
|
+
defaultValue: Maybe.empty(),
|
|
67
|
+
hasValues: [],
|
|
68
|
+
in_: [],
|
|
69
|
+
languageIn: [],
|
|
70
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
71
|
+
primitiveIn: [],
|
|
72
|
+
});
|
|
73
|
+
cachedNamedIdentifierType = new IdentifierType({
|
|
74
|
+
defaultValue: Maybe.empty(),
|
|
75
|
+
hasValues: [],
|
|
76
|
+
in_: [],
|
|
77
|
+
nodeKinds: new Set(["NamedNode"]),
|
|
78
|
+
});
|
|
27
79
|
cachedObjectTypePropertiesByIdentifier = new TermMap();
|
|
28
80
|
cachedObjectTypesByIdentifier = new TermMap();
|
|
29
81
|
cachedObjectUnionTypesByIdentifier = new TermMap();
|
|
82
|
+
cachedStringType = new StringType({
|
|
83
|
+
defaultValue: Maybe.empty(),
|
|
84
|
+
hasValues: [],
|
|
85
|
+
in_: [],
|
|
86
|
+
languageIn: [],
|
|
87
|
+
primitiveDefaultValue: Maybe.empty(),
|
|
88
|
+
primitiveIn: [],
|
|
89
|
+
});
|
|
30
90
|
createObjectTypeFromAstType(astType) {
|
|
31
91
|
{
|
|
32
92
|
const cachedObjectType = this.cachedObjectTypesByIdentifier.get(astType.name.identifier);
|
|
@@ -106,21 +166,14 @@ export class TypeFactory {
|
|
|
106
166
|
own: !astType.ancestorObjectTypes.some(objectTypeNeedsIdentifierPrefixProperty),
|
|
107
167
|
name: `${syntheticNamePrefix}identifierPrefix`,
|
|
108
168
|
objectType,
|
|
109
|
-
type:
|
|
110
|
-
defaultValue: Maybe.empty(),
|
|
111
|
-
hasValues: [],
|
|
112
|
-
in_: [],
|
|
113
|
-
languageIn: [],
|
|
114
|
-
primitiveDefaultValue: Maybe.empty(),
|
|
115
|
-
primitiveIn: [],
|
|
116
|
-
}),
|
|
169
|
+
type: this.cachedStringType,
|
|
117
170
|
visibility: "protected",
|
|
118
171
|
}));
|
|
119
172
|
}
|
|
120
173
|
// Every ObjectType has an identifier property. Some are abstract.
|
|
121
174
|
properties.splice(0, 0, new ObjectType.IdentifierProperty({
|
|
122
175
|
abstract: astType.abstract,
|
|
123
|
-
|
|
176
|
+
getAccessorScope: (() => {
|
|
124
177
|
if (astType.abstract) {
|
|
125
178
|
return Maybe.empty();
|
|
126
179
|
}
|
|
@@ -130,7 +183,12 @@ export class TypeFactory {
|
|
|
130
183
|
}
|
|
131
184
|
return Maybe.empty();
|
|
132
185
|
})(),
|
|
133
|
-
|
|
186
|
+
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
187
|
+
identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
|
|
188
|
+
name: `${syntheticNamePrefix}identifier`,
|
|
189
|
+
objectType,
|
|
190
|
+
override: astType.parentObjectTypes.length > 0,
|
|
191
|
+
propertyDeclarationVisibility: (() => {
|
|
134
192
|
if (astType.abstract) {
|
|
135
193
|
// If the type is abstract, don't declare an identifier property.
|
|
136
194
|
return Maybe.empty();
|
|
@@ -145,11 +203,6 @@ export class TypeFactory {
|
|
|
145
203
|
}
|
|
146
204
|
return Maybe.of("private");
|
|
147
205
|
})(),
|
|
148
|
-
identifierMintingStrategy: astType.identifierMintingStrategy,
|
|
149
|
-
identifierPrefixPropertyName: `${syntheticNamePrefix}identifierPrefix`,
|
|
150
|
-
name: `${syntheticNamePrefix}identifier`,
|
|
151
|
-
objectType,
|
|
152
|
-
override: astType.parentObjectTypes.length > 0,
|
|
153
206
|
type: identifierType,
|
|
154
207
|
typeAlias: `${staticModuleName}.${syntheticNamePrefix}Identifier`,
|
|
155
208
|
visibility: "public",
|
|
@@ -168,6 +221,17 @@ export class TypeFactory {
|
|
|
168
221
|
createTypeFromAstType(astType) {
|
|
169
222
|
switch (astType.kind) {
|
|
170
223
|
case "IdentifierType":
|
|
224
|
+
if (astType.defaultValue.isNothing() &&
|
|
225
|
+
astType.hasValues.length === 0 &&
|
|
226
|
+
astType.in_.length === 0) {
|
|
227
|
+
if (astType.nodeKinds.size === 2) {
|
|
228
|
+
return this.cachedIdentifierType;
|
|
229
|
+
}
|
|
230
|
+
if (astType.nodeKinds.size === 1 &&
|
|
231
|
+
astType.nodeKinds.has("NamedNode")) {
|
|
232
|
+
return this.cachedNamedIdentifierType;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
171
235
|
return new IdentifierType({
|
|
172
236
|
defaultValue: astType.defaultValue,
|
|
173
237
|
hasValues: astType.hasValues,
|
|
@@ -201,6 +265,11 @@ export class TypeFactory {
|
|
|
201
265
|
if (datatypes.size === 1) {
|
|
202
266
|
const datatype = [...datatypes][0];
|
|
203
267
|
if (datatype.equals(xsd.boolean)) {
|
|
268
|
+
if (astType.defaultValue.isNothing() &&
|
|
269
|
+
astType.hasValues.length === 0 &&
|
|
270
|
+
astType.in_.length === 0) {
|
|
271
|
+
return this.cachedBooleanType;
|
|
272
|
+
}
|
|
204
273
|
return new BooleanType({
|
|
205
274
|
defaultValue: astType.defaultValue,
|
|
206
275
|
hasValues: astType.hasValues,
|
|
@@ -215,6 +284,13 @@ export class TypeFactory {
|
|
|
215
284
|
});
|
|
216
285
|
}
|
|
217
286
|
if (datatype.equals(xsd.date) || datatype.equals(xsd.dateTime)) {
|
|
287
|
+
if (astType.defaultValue.isNothing() &&
|
|
288
|
+
astType.hasValues.length === 0 &&
|
|
289
|
+
astType.in_.length === 0) {
|
|
290
|
+
return datatype.equals(xsd.date)
|
|
291
|
+
? this.cachedDateType
|
|
292
|
+
: this.cachedDateTimeType;
|
|
293
|
+
}
|
|
218
294
|
return new (datatype.equals(xsd.date) ? DateType : DateTimeType)({
|
|
219
295
|
defaultValue: astType.defaultValue,
|
|
220
296
|
hasValues: astType.hasValues,
|
|
@@ -231,6 +307,13 @@ export class TypeFactory {
|
|
|
231
307
|
for (const [floatOrInt, numberDatatypes_] of Object.entries(numberDatatypes)) {
|
|
232
308
|
for (const numberDatatype of numberDatatypes_) {
|
|
233
309
|
if (datatype.equals(numberDatatype)) {
|
|
310
|
+
if (astType.defaultValue.isNothing() &&
|
|
311
|
+
astType.hasValues.length === 0 &&
|
|
312
|
+
astType.in_.length === 0) {
|
|
313
|
+
return floatOrInt === "float"
|
|
314
|
+
? this.cachedFloatType
|
|
315
|
+
: this.cachedIntType;
|
|
316
|
+
}
|
|
234
317
|
return new (floatOrInt === "float" ? FloatType : IntType)({
|
|
235
318
|
defaultValue: astType.defaultValue,
|
|
236
319
|
hasValues: astType.hasValues,
|
|
@@ -247,10 +330,16 @@ export class TypeFactory {
|
|
|
247
330
|
}
|
|
248
331
|
}
|
|
249
332
|
if (datatype.equals(xsd.anyURI) || datatype.equals(xsd.string)) {
|
|
333
|
+
if (astType.defaultValue.isNothing() &&
|
|
334
|
+
astType.hasValues.length === 0 &&
|
|
335
|
+
astType.in_.length === 0 &&
|
|
336
|
+
astType.languageIn.length === 0) {
|
|
337
|
+
return this.cachedStringType;
|
|
338
|
+
}
|
|
250
339
|
return new StringType({
|
|
251
340
|
defaultValue: astType.defaultValue,
|
|
252
341
|
hasValues: astType.hasValues,
|
|
253
|
-
languageIn:
|
|
342
|
+
languageIn: astType.languageIn,
|
|
254
343
|
in_: astType.in_,
|
|
255
344
|
primitiveDefaultValue: astType.defaultValue.map((value) => value.value),
|
|
256
345
|
primitiveIn: astType.in_.map((value) => value.value),
|
|
@@ -329,6 +418,14 @@ export class TypeFactory {
|
|
|
329
418
|
stubType,
|
|
330
419
|
});
|
|
331
420
|
}
|
|
421
|
+
else if (resolvedType instanceof ObjectType ||
|
|
422
|
+
resolvedType instanceof ObjectUnionType) {
|
|
423
|
+
invariant(stubType instanceof ObjectType || stubType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
|
|
424
|
+
lazyType = new ObjectType.LazyShaclProperty.RequiredObjectType({
|
|
425
|
+
resolvedType: resolvedType,
|
|
426
|
+
stubType: stubType,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
332
429
|
else if (resolvedType instanceof SetType) {
|
|
333
430
|
invariant(resolvedType.itemType instanceof ObjectType ||
|
|
334
431
|
resolvedType.itemType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind} ${resolvedType.itemType.kind} items`);
|
|
@@ -339,13 +436,7 @@ export class TypeFactory {
|
|
|
339
436
|
});
|
|
340
437
|
}
|
|
341
438
|
else {
|
|
342
|
-
|
|
343
|
-
resolvedType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${resolvedType.kind}`);
|
|
344
|
-
invariant(stubType instanceof ObjectType || stubType instanceof ObjectUnionType, `lazy property ${name} on ${objectType.name} has ${stubType.kind} stubs`);
|
|
345
|
-
lazyType = new ObjectType.LazyShaclProperty.RequiredObjectType({
|
|
346
|
-
resolvedType,
|
|
347
|
-
stubType,
|
|
348
|
-
});
|
|
439
|
+
throw new Error(`lazy property ${name} on ${objectType.name} has ${resolvedType.kind}`);
|
|
349
440
|
}
|
|
350
441
|
property = new ObjectType.LazyShaclProperty({
|
|
351
442
|
comment: astObjectTypeProperty.comment,
|
|
@@ -257,7 +257,7 @@ ${this.memberTypes
|
|
|
257
257
|
if (this._discriminator.kind === "syntheticProperty") {
|
|
258
258
|
typeExpression = `${typeExpression}.map(value => ({ ${this._discriminator.name}: "${memberType.discriminatorValues[0]}" as const, value }) as (${this.name}))`;
|
|
259
259
|
}
|
|
260
|
-
typeExpression = `(${typeExpression} as purify.Either<Error,
|
|
260
|
+
typeExpression = `(${typeExpression} as purify.Either<Error, rdfjsResource.Resource.Values<${this.name}>>)`;
|
|
261
261
|
return expression.length > 0
|
|
262
262
|
? `${expression}.altLazy(() => ${typeExpression})`
|
|
263
263
|
: typeExpression;
|
|
@@ -17,9 +17,10 @@ export class EagerShaclProperty extends ShaclProperty {
|
|
|
17
17
|
}
|
|
18
18
|
get graphqlField() {
|
|
19
19
|
return Maybe.of({
|
|
20
|
-
|
|
20
|
+
args: Maybe.empty(),
|
|
21
|
+
description: this.comment.map(JSON.stringify),
|
|
21
22
|
name: this.name,
|
|
22
|
-
resolve: `(source) => ${this.type.graphqlResolveExpression({ variables: { value: `source.${this.name}` } })}`,
|
|
23
|
+
resolve: `(source, _args) => ${this.type.graphqlResolveExpression({ variables: { args: "_args", value: `source.${this.name}` } })}`,
|
|
23
24
|
type: this.type.graphqlName.toString(),
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -7,7 +7,6 @@ import { Property } from "./Property.js";
|
|
|
7
7
|
export declare class IdentifierPrefixProperty extends Property<StringType> {
|
|
8
8
|
private readonly own;
|
|
9
9
|
readonly declarationImports: readonly Import[];
|
|
10
|
-
readonly equalsFunction = "$strictEquals";
|
|
11
10
|
readonly graphqlField: Property<StringType>["graphqlField"];
|
|
12
11
|
readonly propertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
13
12
|
readonly jsonPropertySignature: Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
@@ -18,6 +17,7 @@ export declare class IdentifierPrefixProperty extends Property<StringType> {
|
|
|
18
17
|
type: StringType;
|
|
19
18
|
} & ConstructorParameters<typeof Property>[0]);
|
|
20
19
|
get constructorParametersPropertySignature(): Maybe<OptionalKind<PropertySignatureStructure>>;
|
|
20
|
+
get equalsFunction(): Maybe<string>;
|
|
21
21
|
constructorStatements({ variables, }: Parameters<Property<IdentifierType>["constructorStatements"]>[0]): readonly string[];
|
|
22
22
|
fromJsonStatements(): readonly string[];
|
|
23
23
|
fromRdfStatements(): readonly string[];
|
|
@@ -1,13 +1,19 @@
|
|
|
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
|
+
};
|
|
1
7
|
import { Maybe } from "purify-ts";
|
|
2
8
|
import { invariant } from "ts-invariant";
|
|
3
9
|
import { Scope, } from "ts-morph";
|
|
10
|
+
import { Memoize } from "typescript-memoize";
|
|
4
11
|
import { SnippetDeclarations } from "../SnippetDeclarations.js";
|
|
5
12
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
6
13
|
import { Property } from "./Property.js";
|
|
7
14
|
export class IdentifierPrefixProperty extends Property {
|
|
8
15
|
own;
|
|
9
16
|
declarationImports = [];
|
|
10
|
-
equalsFunction = `${syntheticNamePrefix}strictEquals`;
|
|
11
17
|
graphqlField = Maybe.empty();
|
|
12
18
|
propertySignature = Maybe.empty();
|
|
13
19
|
jsonPropertySignature = Maybe.empty();
|
|
@@ -26,6 +32,11 @@ export class IdentifierPrefixProperty extends Property {
|
|
|
26
32
|
type: this.type.name,
|
|
27
33
|
});
|
|
28
34
|
}
|
|
35
|
+
get equalsFunction() {
|
|
36
|
+
return this.objectType.declarationType === "class"
|
|
37
|
+
? Maybe.of(`${syntheticNamePrefix}strictEquals`)
|
|
38
|
+
: Maybe.empty();
|
|
39
|
+
}
|
|
29
40
|
constructorStatements({ variables, }) {
|
|
30
41
|
switch (this.objectType.declarationType) {
|
|
31
42
|
case "class":
|
|
@@ -94,4 +105,7 @@ export class IdentifierPrefixProperty extends Property {
|
|
|
94
105
|
return [];
|
|
95
106
|
}
|
|
96
107
|
}
|
|
108
|
+
__decorate([
|
|
109
|
+
Memoize()
|
|
110
|
+
], IdentifierPrefixProperty.prototype, "equalsFunction", null);
|
|
97
111
|
//# sourceMappingURL=IdentifierPrefixProperty.js.map
|
|
@@ -5,20 +5,20 @@ import type { IdentifierType } from "../IdentifierType.js";
|
|
|
5
5
|
import { Import } from "../Import.js";
|
|
6
6
|
import { Property } from "./Property.js";
|
|
7
7
|
export declare class IdentifierProperty extends Property<IdentifierType> {
|
|
8
|
-
private readonly
|
|
9
|
-
private readonly classPropertyDeclarationVisibility;
|
|
8
|
+
private readonly getAccessorScope;
|
|
10
9
|
private readonly identifierMintingStrategy;
|
|
11
10
|
private readonly identifierPrefixPropertyName;
|
|
12
11
|
private readonly override;
|
|
12
|
+
private readonly propertyDeclarationVisibility;
|
|
13
13
|
private readonly typeAlias;
|
|
14
14
|
readonly abstract: boolean;
|
|
15
|
-
readonly equalsFunction
|
|
15
|
+
readonly equalsFunction: Maybe<string>;
|
|
16
16
|
readonly mutable = false;
|
|
17
17
|
readonly recursive = false;
|
|
18
|
-
constructor({ abstract,
|
|
18
|
+
constructor({ abstract, getAccessorScope, identifierMintingStrategy, identifierPrefixPropertyName, override, propertyDeclarationVisibility, typeAlias, ...superParameters }: {
|
|
19
19
|
abstract: boolean;
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
getAccessorScope: Maybe<Scope>;
|
|
21
|
+
propertyDeclarationVisibility: Maybe<PropertyVisibility>;
|
|
22
22
|
identifierMintingStrategy: Maybe<IdentifierMintingStrategy>;
|
|
23
23
|
identifierPrefixPropertyName: string;
|
|
24
24
|
override: boolean;
|