@shaclmate/compiler 4.0.98 → 4.0.99
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/generators/ts/AbstractCollectionType.d.ts +2 -1
- package/dist/generators/ts/AbstractCollectionType.js +10 -5
- package/dist/generators/ts/AbstractCompoundType.d.ts +11 -8
- package/dist/generators/ts/AbstractCompoundType.js +5 -2
- package/dist/generators/ts/AbstractContainerType.d.ts +11 -11
- package/dist/generators/ts/AbstractContainerType.js +21 -15
- package/dist/generators/ts/AbstractDateType.d.ts +7 -6
- package/dist/generators/ts/AbstractDateType.js +16 -6
- package/dist/generators/ts/AbstractDiscriminatedUnionType.d.ts +2 -3
- package/dist/generators/ts/AbstractDiscriminatedUnionType.js +25 -7
- package/dist/generators/ts/AbstractIntersectionType.d.ts +2 -2
- package/dist/generators/ts/AbstractIntersectionType.js +19 -8
- package/dist/generators/ts/AbstractLazyType.d.ts +23 -23
- package/dist/generators/ts/AbstractLazyType.js +21 -19
- package/dist/generators/ts/AbstractNumericType.d.ts +4 -3
- package/dist/generators/ts/AbstractNumericType.js +12 -7
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +2 -2
- package/dist/generators/ts/AbstractPrimitiveType.js +4 -4
- package/dist/generators/ts/AbstractTermType.d.ts +17 -16
- package/dist/generators/ts/AbstractTermType.js +21 -11
- package/dist/generators/ts/AbstractType.d.ts +6 -15
- package/dist/generators/ts/AbstractType.js +14 -33
- package/dist/generators/ts/AbstractTypedLiteralType.d.ts +2 -1
- package/dist/generators/ts/AbstractTypedLiteralType.js +20 -2
- package/dist/generators/ts/BigDecimalType.d.ts +12 -11
- package/dist/generators/ts/BigDecimalType.js +28 -11
- package/dist/generators/ts/BigIntType.js +6 -6
- package/dist/generators/ts/BlankNodeType.d.ts +11 -10
- package/dist/generators/ts/BlankNodeType.js +27 -10
- package/dist/generators/ts/BooleanType.d.ts +6 -5
- package/dist/generators/ts/BooleanType.js +18 -8
- package/dist/generators/ts/Callable.d.ts +2 -2
- package/dist/generators/ts/DateTimeType.d.ts +6 -6
- package/dist/generators/ts/DateTimeType.js +6 -6
- package/dist/generators/ts/DateType.d.ts +6 -6
- package/dist/generators/ts/DateType.js +6 -6
- package/dist/generators/ts/DefaultValueType.d.ts +2 -2
- package/dist/generators/ts/DefaultValueType.js +18 -8
- package/dist/generators/ts/FloatType.js +4 -4
- package/dist/generators/ts/IdentifierType.d.ts +11 -10
- package/dist/generators/ts/IdentifierType.js +27 -10
- package/dist/generators/ts/IntType.js +4 -4
- package/dist/generators/ts/IriType.d.ts +5 -5
- package/dist/generators/ts/IriType.js +27 -22
- package/dist/generators/ts/LangStringType.d.ts +10 -10
- package/dist/generators/ts/LangStringType.js +21 -13
- package/dist/generators/ts/ListType.js +7 -7
- package/dist/generators/ts/LiteralType.d.ts +10 -10
- package/dist/generators/ts/LiteralType.js +21 -13
- package/dist/generators/ts/ObjectType.d.ts +13 -15
- package/dist/generators/ts/ObjectType.js +32 -9
- package/dist/generators/ts/OptionType.d.ts +2 -1
- package/dist/generators/ts/OptionType.js +16 -11
- package/dist/generators/ts/SetType.d.ts +2 -1
- package/dist/generators/ts/SetType.js +22 -10
- package/dist/generators/ts/Snippets.d.ts +1 -0
- package/dist/generators/ts/Snippets.js +7 -0
- package/dist/generators/ts/StringType.d.ts +6 -6
- package/dist/generators/ts/StringType.js +20 -17
- package/dist/generators/ts/TermType.d.ts +7 -7
- package/dist/generators/ts/TermType.js +18 -13
- package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_fromJsonObjectFunction.js +1 -1
- package/dist/generators/ts/_AbstractType/AbstractType_JsonType.d.ts +39 -16
- package/dist/generators/ts/_AbstractType/AbstractType_JsonType.js +49 -33
- package/dist/generators/ts/_ObjectDiscriminatedUnionType/ObjectDiscriminatedUnionType_focusSparqlWherePatternsFunction.js +1 -1
- package/dist/generators/ts/_ObjectIntersectionType/ObjectIntersectionType_fromRdfResourceValuesFunction.js +1 -1
- package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.d.ts +4 -7
- package/dist/generators/ts/_ObjectType/ObjectType_AbstractProperty.js +1 -3
- package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.d.ts +0 -1
- package/dist/generators/ts/_ObjectType/ObjectType_DiscriminantProperty.js +0 -1
- package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.d.ts +3 -2
- package/dist/generators/ts/_ObjectType/ObjectType_IdentifierProperty.js +30 -10
- package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.d.ts +3 -2
- package/dist/generators/ts/_ObjectType/ObjectType_RdfTypeProperty.js +26 -10
- package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.d.ts +3 -2
- package/dist/generators/ts/_ObjectType/ObjectType_ShaclProperty.js +46 -22
- package/dist/generators/ts/_ObjectType/ObjectType_fromRdfResourceValuesFunction.js +1 -1
- package/package.json +2 -2
- package/dist/generators/ts/AbstractStructuredType.d.ts +0 -71
- package/dist/generators/ts/AbstractStructuredType.js +0 -273
- package/dist/generators/ts/ReferenceCallable.d.ts +0 -14
- package/dist/generators/ts/ReferenceCallable.js +0 -16
- package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.d.ts +0 -5
- package/dist/generators/ts/_AbstractDiscriminatedUnionType/AbstractDiscriminatedUnionType_schemaTypeExpression.js +0 -11
- package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_schemaExpression.js +0 -15
- package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.d.ts +0 -4
- package/dist/generators/ts/_ObjectType/ObjectType_schemaTypeExpression.js +0 -15
|
@@ -8,9 +8,10 @@ import { Maybe } from "purify-ts";
|
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { AbstractContainerType } from "./AbstractContainerType.js";
|
|
11
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
11
12
|
import { codeEquals } from "./codeEquals.js";
|
|
12
13
|
import { InlineCallable } from "./InlineCallable.js";
|
|
13
|
-
import {
|
|
14
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
14
15
|
import { code } from "./ts-poet-wrapper.js";
|
|
15
16
|
export class OptionType extends AbstractContainerType {
|
|
16
17
|
graphqlArgs = Maybe.empty();
|
|
@@ -47,13 +48,13 @@ export class OptionType extends AbstractContainerType {
|
|
|
47
48
|
return code `${this.reusables.snippets.MaybeFilter}<${this.itemType.filterType}>`;
|
|
48
49
|
}
|
|
49
50
|
get fromJsonValueFunction() {
|
|
50
|
-
return new
|
|
51
|
+
return new BuiltinCallable(code `${this.reusables.snippets.maybeFromJsonValue}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
|
|
51
52
|
}
|
|
52
53
|
get fromJsonObjectFunction() {
|
|
53
|
-
return new
|
|
54
|
+
return new BuiltinCallable(code `${this.reusables.snippets.maybeFromJsonObject}(${this.itemType.fromJsonObjectFunction.annotatedUsage})`);
|
|
54
55
|
}
|
|
55
56
|
get fromRdfResourceValuesFunction() {
|
|
56
|
-
return new InlineCallable(code `${this.reusables.snippets.maybeFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.
|
|
57
|
+
return new InlineCallable(code `${this.reusables.snippets.maybeFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schema.type.expression}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
|
|
57
58
|
}
|
|
58
59
|
get graphqlType() {
|
|
59
60
|
invariant(!this.itemType.graphqlType.nullable);
|
|
@@ -67,14 +68,18 @@ export class OptionType extends AbstractContainerType {
|
|
|
67
68
|
get mutable() {
|
|
68
69
|
return this.itemType.mutable;
|
|
69
70
|
}
|
|
70
|
-
get
|
|
71
|
-
return
|
|
71
|
+
get schema() {
|
|
72
|
+
return new SchemaObject({
|
|
73
|
+
properties: super.schema.properties,
|
|
74
|
+
type: new SchemaObject.BuiltinType(code `${this.reusables.snippets.MaybeSchema}<${this.itemType.schema.type.expression}>`),
|
|
75
|
+
variable: super.schema.variable,
|
|
76
|
+
});
|
|
72
77
|
}
|
|
73
78
|
get toJsonValueFunction() {
|
|
74
|
-
return new
|
|
79
|
+
return new BuiltinCallable(code `${this.reusables.snippets.maybeToJsonValue}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
|
|
75
80
|
}
|
|
76
81
|
get toJsonObjectFunction() {
|
|
77
|
-
return new
|
|
82
|
+
return new BuiltinCallable(code `${this.reusables.snippets.maybeToJsonObject}(${this.itemType.toJsonObjectFunction.annotatedUsage})`);
|
|
78
83
|
}
|
|
79
84
|
get toRdfResourceValueTypes() {
|
|
80
85
|
return this.itemType.toRdfResourceValueTypes;
|
|
@@ -85,10 +90,10 @@ export class OptionType extends AbstractContainerType {
|
|
|
85
90
|
.orDefault(this.itemValidationFunctionDefault.annotatedUsage)})`));
|
|
86
91
|
}
|
|
87
92
|
get valueSparqlConstructTriplesFunction() {
|
|
88
|
-
return new InlineCallable(code `${this.reusables.snippets.maybeSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.
|
|
93
|
+
return new InlineCallable(code `${this.reusables.snippets.maybeSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
|
|
89
94
|
}
|
|
90
95
|
get valueSparqlWherePatternsFunction() {
|
|
91
|
-
return new InlineCallable(code `${this.reusables.snippets.maybeSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.
|
|
96
|
+
return new InlineCallable(code `${this.reusables.snippets.maybeSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
|
|
92
97
|
}
|
|
93
98
|
get inlineExpression() {
|
|
94
99
|
return code `${this.reusables.imports.Maybe}<${this.itemType.expression}>`;
|
|
@@ -142,7 +147,7 @@ __decorate([
|
|
|
142
147
|
], OptionType.prototype, "hashFunction", null);
|
|
143
148
|
__decorate([
|
|
144
149
|
Memoize()
|
|
145
|
-
], OptionType.prototype, "
|
|
150
|
+
], OptionType.prototype, "schema", null);
|
|
146
151
|
__decorate([
|
|
147
152
|
Memoize()
|
|
148
153
|
], OptionType.prototype, "toJsonValueFunction", null);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
2
|
import { AbstractCollectionType } from "./AbstractCollectionType.js";
|
|
3
3
|
import type { Callable } from "./Callable.js";
|
|
4
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
4
5
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
6
|
export declare class SetType<ItemTypeT extends SetType.ItemType> extends AbstractCollectionType<ItemTypeT> {
|
|
6
7
|
readonly graphqlArgs: AbstractCollectionType<ItemTypeT>["graphqlArgs"];
|
|
@@ -24,7 +25,7 @@ export declare class SetType<ItemTypeT extends SetType.ItemType> extends Abstrac
|
|
|
24
25
|
get toRdfResourceValueTypes(): AbstractCollectionType<ItemTypeT>["toRdfResourceValueTypes"];
|
|
25
26
|
get valueSparqlConstructTriplesFunction(): Callable;
|
|
26
27
|
get valueSparqlWherePatternsFunction(): Callable;
|
|
27
|
-
|
|
28
|
+
get schema(): SchemaObject<SchemaObject.BuiltinType>;
|
|
28
29
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
29
30
|
toStringExpression({ variables, }: Parameters<AbstractCollectionType<ItemTypeT>["toStringExpression"]>[0]): Code;
|
|
30
31
|
}
|
|
@@ -8,8 +8,9 @@ import { Maybe } from "purify-ts";
|
|
|
8
8
|
import { invariant } from "ts-invariant";
|
|
9
9
|
import { Memoize } from "typescript-memoize";
|
|
10
10
|
import { AbstractCollectionType } from "./AbstractCollectionType.js";
|
|
11
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
11
12
|
import { InlineCallable } from "./InlineCallable.js";
|
|
12
|
-
import {
|
|
13
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
13
14
|
import { code, joinCode } from "./ts-poet-wrapper.js";
|
|
14
15
|
export class SetType extends AbstractCollectionType {
|
|
15
16
|
graphqlArgs = Maybe.empty();
|
|
@@ -70,16 +71,16 @@ export class SetType extends AbstractCollectionType {
|
|
|
70
71
|
throw new Error("should never be called");
|
|
71
72
|
}
|
|
72
73
|
get fromJsonValueFunction() {
|
|
73
|
-
return new
|
|
74
|
+
return new BuiltinCallable(code `${this.reusables.snippets.arrayFromJsonArray}(${this.itemType.fromJsonValueFunction.annotatedUsage})`);
|
|
74
75
|
}
|
|
75
76
|
get fromJsonObjectFunction() {
|
|
76
77
|
throw new Error("should never be called");
|
|
77
78
|
}
|
|
78
79
|
get fromRdfResourceValuesFunction() {
|
|
79
|
-
return new InlineCallable(code `${this._mutable ? this.reusables.snippets.mutableSetFromRdfResourceValues : this.reusables.snippets.setFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.
|
|
80
|
+
return new InlineCallable(code `${this._mutable ? this.reusables.snippets.mutableSetFromRdfResourceValues : this.reusables.snippets.setFromRdfResourceValues}<${this.itemType.expression}, ${this.itemType.schema.type.expression}>(${this.itemType.fromRdfResourceValuesFunction.unannotatedUsage})`);
|
|
80
81
|
}
|
|
81
82
|
get toJsonValueFunction() {
|
|
82
|
-
return new
|
|
83
|
+
return new BuiltinCallable(code `${this.reusables.snippets.arrayToJsonArray}(${this.itemType.toJsonValueFunction.annotatedUsage})`);
|
|
83
84
|
}
|
|
84
85
|
get toJsonObjectFunction() {
|
|
85
86
|
throw new Error("should never be called");
|
|
@@ -88,17 +89,25 @@ export class SetType extends AbstractCollectionType {
|
|
|
88
89
|
return this.itemType.toRdfResourceValueTypes;
|
|
89
90
|
}
|
|
90
91
|
get valueSparqlConstructTriplesFunction() {
|
|
91
|
-
return new InlineCallable(code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.
|
|
92
|
+
return new InlineCallable(code `${this.reusables.snippets.setSparqlConstructTriples}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlConstructTriplesFunction.unannotatedUsage})`);
|
|
92
93
|
}
|
|
93
94
|
get valueSparqlWherePatternsFunction() {
|
|
94
|
-
return new InlineCallable(code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.
|
|
95
|
+
return new InlineCallable(code `${this.reusables.snippets.setSparqlWherePatterns}<${this.itemType.filterType}, ${this.itemType.schema.type.expression}>(${this.itemType.valueSparqlWherePatternsFunction.unannotatedUsage})`);
|
|
95
96
|
}
|
|
96
|
-
get
|
|
97
|
-
let schemaInitializers = super.schemaInitializers;
|
|
97
|
+
get schema() {
|
|
98
98
|
if (this.minCount > 0n) {
|
|
99
|
-
|
|
99
|
+
return new SchemaObject({
|
|
100
|
+
properties: {
|
|
101
|
+
...super.schema.properties,
|
|
102
|
+
minCount: code `minCount: ${Number(this.minCount)}`,
|
|
103
|
+
},
|
|
104
|
+
type: super.schema.type,
|
|
105
|
+
variable: super.schema.variable,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return super.schema;
|
|
100
110
|
}
|
|
101
|
-
return schemaInitializers;
|
|
102
111
|
}
|
|
103
112
|
toRdfResourceValuesExpression({ variables, }) {
|
|
104
113
|
return code `${variables.value}.flatMap((item) => ${this.itemType.toRdfResourceValuesExpression({
|
|
@@ -130,6 +139,9 @@ __decorate([
|
|
|
130
139
|
__decorate([
|
|
131
140
|
Memoize()
|
|
132
141
|
], SetType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
142
|
+
__decorate([
|
|
143
|
+
Memoize()
|
|
144
|
+
], SetType.prototype, "schema", null);
|
|
133
145
|
(function (SetType) {
|
|
134
146
|
SetType.isItemType = AbstractCollectionType.isItemType;
|
|
135
147
|
})(SetType || (SetType = {}));
|
|
@@ -39,6 +39,7 @@ import { snippets_LangStringJsonObject } from "./_snippets/snippets_LangStringJs
|
|
|
39
39
|
import { snippets_LangStringSchema } from "./_snippets/snippets_LangStringSchema.js";
|
|
40
40
|
import { snippets_Lazy } from "./_snippets/snippets_Lazy.js";
|
|
41
41
|
import { snippets_LazyOption } from "./_snippets/snippets_LazyOption.js";
|
|
42
|
+
import { snippets_LazySchema } from "./_snippets/snippets_LazySchema.js";
|
|
42
43
|
import { snippets_LazySet } from "./_snippets/snippets_LazySet.js";
|
|
43
44
|
import { snippets_LiteralFilter } from "./_snippets/snippets_LiteralFilter.js";
|
|
44
45
|
import { snippets_LiteralJsonObject } from "./_snippets/snippets_LiteralJsonObject.js";
|
|
@@ -359,6 +360,9 @@ export class Snippets {
|
|
|
359
360
|
get LazyOption() {
|
|
360
361
|
return this.snippet(snippets_LazyOption);
|
|
361
362
|
}
|
|
363
|
+
get LazySchema() {
|
|
364
|
+
return this.snippet(snippets_LazySchema);
|
|
365
|
+
}
|
|
362
366
|
get LazySet() {
|
|
363
367
|
return this.snippet(snippets_LazySet);
|
|
364
368
|
}
|
|
@@ -1166,6 +1170,9 @@ __decorate([
|
|
|
1166
1170
|
__decorate([
|
|
1167
1171
|
Memoize()
|
|
1168
1172
|
], Snippets.prototype, "LazyOption", null);
|
|
1173
|
+
__decorate([
|
|
1174
|
+
Memoize()
|
|
1175
|
+
], Snippets.prototype, "LazySchema", null);
|
|
1169
1176
|
__decorate([
|
|
1170
1177
|
Memoize()
|
|
1171
1178
|
], Snippets.prototype, "LazySet", null);
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import type { Literal } from "@rdfjs/types";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
3
|
import { AbstractPrimitiveType } from "./AbstractPrimitiveType.js";
|
|
4
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
4
5
|
import type { Callable } from "./Callable.js";
|
|
5
|
-
import {
|
|
6
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
6
7
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
7
8
|
export declare class StringType extends AbstractPrimitiveType<string> {
|
|
8
9
|
private readonly languageIn;
|
|
9
10
|
protected readonly decodedIn: string[];
|
|
10
11
|
readonly conversionFunction: Maybe<AbstractPrimitiveType.ConversionFunction>;
|
|
11
|
-
readonly filterFunction:
|
|
12
|
+
readonly filterFunction: BuiltinCallable;
|
|
12
13
|
readonly filterType: Code;
|
|
13
14
|
readonly graphqlType: import("./_AbstractType/AbstractType_GraphqlType.js").AbstractType_GraphqlType;
|
|
14
|
-
readonly hashFunction:
|
|
15
|
+
readonly hashFunction: BuiltinCallable;
|
|
15
16
|
readonly jsTypes: readonly [{
|
|
16
17
|
readonly typeof: "string";
|
|
17
18
|
}];
|
|
18
19
|
readonly jsonValueType: AbstractPrimitiveType.JsonType;
|
|
19
20
|
readonly kind = "String";
|
|
20
|
-
readonly valueSparqlWherePatternsFunction:
|
|
21
|
+
readonly valueSparqlWherePatternsFunction: BuiltinCallable;
|
|
21
22
|
constructor({ languageIn, ...superParameters }: {
|
|
22
23
|
languageIn: readonly string[];
|
|
23
24
|
} & ConstructorParameters<typeof AbstractPrimitiveType<string>>[0]);
|
|
24
25
|
get fromJsonObjectFunction(): Callable;
|
|
25
26
|
get fromJsonValueFunction(): Callable;
|
|
26
27
|
get fromRdfResourceValuesFunction(): Callable;
|
|
27
|
-
get
|
|
28
|
-
protected get schemaInitializers(): readonly Code[];
|
|
28
|
+
get schema(): SchemaObject<SchemaObject.BuiltinType>;
|
|
29
29
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<string>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
30
30
|
valueExpression(literal: Literal | string): Code;
|
|
31
31
|
}
|
|
@@ -9,16 +9,17 @@ import { xsd } from "@tpluscode/rdf-ns-builders";
|
|
|
9
9
|
import { Maybe } from "purify-ts";
|
|
10
10
|
import { Memoize } from "typescript-memoize";
|
|
11
11
|
import { AbstractPrimitiveType } from "./AbstractPrimitiveType.js";
|
|
12
|
-
import {
|
|
12
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
13
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
13
14
|
import { arrayOf, code, literalOf } from "./ts-poet-wrapper.js";
|
|
14
15
|
export class StringType extends AbstractPrimitiveType {
|
|
15
16
|
languageIn;
|
|
16
17
|
decodedIn = this.in_.map((in_) => LiteralDecoder.decodeStringLiteral(in_).unsafeCoerce());
|
|
17
18
|
conversionFunction = Maybe.empty();
|
|
18
|
-
filterFunction = new
|
|
19
|
+
filterFunction = new BuiltinCallable(this.reusables.snippets.filterString);
|
|
19
20
|
filterType = code `${this.reusables.snippets.StringFilter}`;
|
|
20
21
|
graphqlType = new AbstractPrimitiveType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
|
|
21
|
-
hashFunction = new
|
|
22
|
+
hashFunction = new BuiltinCallable(this.reusables.snippets.hashString);
|
|
22
23
|
jsTypes = [
|
|
23
24
|
{
|
|
24
25
|
typeof: "string",
|
|
@@ -31,29 +32,31 @@ export class StringType extends AbstractPrimitiveType {
|
|
|
31
32
|
: undefined,
|
|
32
33
|
});
|
|
33
34
|
kind = "String";
|
|
34
|
-
valueSparqlWherePatternsFunction = new
|
|
35
|
+
valueSparqlWherePatternsFunction = new BuiltinCallable(this.reusables.snippets.stringSparqlWherePatterns);
|
|
35
36
|
constructor({ languageIn, ...superParameters }) {
|
|
36
37
|
super(superParameters);
|
|
37
38
|
this.languageIn = languageIn;
|
|
38
39
|
}
|
|
39
40
|
get fromJsonObjectFunction() {
|
|
40
|
-
return new
|
|
41
|
+
return new BuiltinCallable(code `${this.reusables.snippets.stringFromJsonObject}<${this.expression}>`);
|
|
41
42
|
}
|
|
42
43
|
get fromJsonValueFunction() {
|
|
43
|
-
return new
|
|
44
|
+
return new BuiltinCallable(code `${this.reusables.snippets.stringFromJsonString}<${this.expression}>`);
|
|
44
45
|
}
|
|
45
46
|
get fromRdfResourceValuesFunction() {
|
|
46
|
-
return new
|
|
47
|
+
return new BuiltinCallable(code `${this.reusables.snippets.stringFromRdfResourceValues}<${this.expression}>`);
|
|
47
48
|
}
|
|
48
|
-
get
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
get schema() {
|
|
50
|
+
return new SchemaObject({
|
|
51
|
+
properties: this.languageIn.length > 0
|
|
52
|
+
? {
|
|
53
|
+
...super.schema.properties,
|
|
54
|
+
languageIn: code `languageIn: ${arrayOf(...this.languageIn)}`,
|
|
55
|
+
}
|
|
56
|
+
: super.schema.properties,
|
|
57
|
+
type: new SchemaObject.BuiltinType(code `${this.reusables.snippets.StringSchema}<${this.expression}>`),
|
|
58
|
+
variable: super.schema.variable,
|
|
59
|
+
});
|
|
57
60
|
}
|
|
58
61
|
toRdfResourceValuesExpression({ variables, }) {
|
|
59
62
|
return code `[${this.reusables.snippets.literalFactory}.string(${variables.value}${!this.datatype.equals(xsd.string) ? `, ${this.rdfjsTermExpression(this.datatype)}` : ""})]`;
|
|
@@ -73,5 +76,5 @@ __decorate([
|
|
|
73
76
|
], StringType.prototype, "fromRdfResourceValuesFunction", null);
|
|
74
77
|
__decorate([
|
|
75
78
|
Memoize()
|
|
76
|
-
], StringType.prototype, "
|
|
79
|
+
], StringType.prototype, "schema", null);
|
|
77
80
|
//# sourceMappingURL=StringType.js.map
|
|
@@ -2,21 +2,22 @@ import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
|
2
2
|
import { NodeKind } from "@shaclmate/shacl-ast";
|
|
3
3
|
import { Maybe } from "purify-ts";
|
|
4
4
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
5
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
5
6
|
import type { Callable } from "./Callable.js";
|
|
6
|
-
import {
|
|
7
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
7
8
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
8
9
|
export declare class TermType<ConstantTermT extends Literal | NamedNode = Literal | NamedNode, RuntimeTermT extends BlankNode | Literal | NamedNode = BlankNode | Literal | NamedNode> extends AbstractTermType {
|
|
9
10
|
readonly conversionFunction: Maybe<AbstractTermType.ConversionFunction>;
|
|
10
|
-
readonly filterFunction:
|
|
11
|
+
readonly filterFunction: BuiltinCallable;
|
|
11
12
|
readonly jsTypes: readonly [{
|
|
12
13
|
readonly instanceof: "Object";
|
|
13
14
|
readonly typeof: "object";
|
|
14
15
|
}];
|
|
15
16
|
readonly kind = "Term";
|
|
16
17
|
readonly nodeKinds: ReadonlySet<NodeKind>;
|
|
17
|
-
readonly toJsonObjectFunction:
|
|
18
|
-
readonly toJsonValueFunction:
|
|
19
|
-
readonly valueSparqlWherePatternsFunction:
|
|
18
|
+
readonly toJsonObjectFunction: BuiltinCallable;
|
|
19
|
+
readonly toJsonValueFunction: BuiltinCallable;
|
|
20
|
+
readonly valueSparqlWherePatternsFunction: BuiltinCallable;
|
|
20
21
|
constructor({ nodeKinds, ...superParameters }: ConstructorParameters<typeof AbstractTermType<ConstantTermT, RuntimeTermT>>[0] & {
|
|
21
22
|
nodeKinds: ReadonlySet<NodeKind>;
|
|
22
23
|
});
|
|
@@ -28,9 +29,8 @@ export declare class TermType<ConstantTermT extends Literal | NamedNode = Litera
|
|
|
28
29
|
get graphqlType(): AbstractTermType.GraphqlType;
|
|
29
30
|
get jsonObjectType(): AbstractTermType["jsonObjectType"];
|
|
30
31
|
get jsonValueType(): AbstractTermType["jsonValueType"];
|
|
31
|
-
get schemaType(): Code;
|
|
32
32
|
protected get inlineExpression(): Code;
|
|
33
|
-
|
|
33
|
+
get schema(): SchemaObject<SchemaObject.BuiltinType>;
|
|
34
34
|
graphqlResolveExpression(_parameters: Parameters<AbstractTermType["graphqlResolveExpression"]>[0]): Code;
|
|
35
35
|
toLoggableExpression({ variables, }: Parameters<AbstractTermType["toLoggableExpression"]>[0]): Code;
|
|
36
36
|
}
|
|
@@ -9,19 +9,20 @@ import { Maybe } from "purify-ts";
|
|
|
9
9
|
import { invariant } from "ts-invariant";
|
|
10
10
|
import { Memoize } from "typescript-memoize";
|
|
11
11
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
12
|
-
import {
|
|
12
|
+
import { BuiltinCallable } from "./BuiltinCallable.js";
|
|
13
|
+
import { SchemaObject } from "./SchemaObject.js";
|
|
13
14
|
import { arrayOf, code, joinCode } from "./ts-poet-wrapper.js";
|
|
14
15
|
export class TermType extends AbstractTermType {
|
|
15
16
|
conversionFunction = Maybe.empty();
|
|
16
|
-
filterFunction = new
|
|
17
|
+
filterFunction = new BuiltinCallable(this.reusables.snippets.filterTerm);
|
|
17
18
|
jsTypes = [
|
|
18
19
|
{ instanceof: "Object", typeof: "object" },
|
|
19
20
|
];
|
|
20
21
|
kind = "Term";
|
|
21
22
|
nodeKinds;
|
|
22
|
-
toJsonObjectFunction = new
|
|
23
|
+
toJsonObjectFunction = new BuiltinCallable(this.reusables.snippets.termToJsonObject);
|
|
23
24
|
toJsonValueFunction = this.toJsonObjectFunction;
|
|
24
|
-
valueSparqlWherePatternsFunction = new
|
|
25
|
+
valueSparqlWherePatternsFunction = new BuiltinCallable(this.reusables.snippets.termSparqlWherePatterns);
|
|
25
26
|
constructor({ nodeKinds, ...superParameters }) {
|
|
26
27
|
super(superParameters);
|
|
27
28
|
this.nodeKinds = nodeKinds;
|
|
@@ -42,13 +43,13 @@ export class TermType extends AbstractTermType {
|
|
|
42
43
|
return code `${this.reusables.snippets.TermFilter}<${this.expression}>`;
|
|
43
44
|
}
|
|
44
45
|
get fromJsonObjectFunction() {
|
|
45
|
-
return new
|
|
46
|
+
return new BuiltinCallable(code `${this.reusables.snippets.termFromJsonObject}<${this.expression}>`);
|
|
46
47
|
}
|
|
47
48
|
get fromJsonValueFunction() {
|
|
48
49
|
return this.fromJsonObjectFunction;
|
|
49
50
|
}
|
|
50
51
|
get fromRdfResourceValuesFunction() {
|
|
51
|
-
return new
|
|
52
|
+
return new BuiltinCallable(code `${this.reusables.snippets.termFromRdfResourceValues}<${this.expression}>`);
|
|
52
53
|
}
|
|
53
54
|
get graphqlType() {
|
|
54
55
|
throw new Error("not implemented");
|
|
@@ -79,9 +80,6 @@ export class TermType extends AbstractTermType {
|
|
|
79
80
|
get jsonValueType() {
|
|
80
81
|
return this.jsonObjectType;
|
|
81
82
|
}
|
|
82
|
-
get schemaType() {
|
|
83
|
-
return code `${this.reusables.snippets.TermSchema}<${this.expression}>`;
|
|
84
|
-
}
|
|
85
83
|
get inlineExpression() {
|
|
86
84
|
return code `(${joinCode([...this.nodeKinds]
|
|
87
85
|
.map((nodeKind) => {
|
|
@@ -99,8 +97,15 @@ export class TermType extends AbstractTermType {
|
|
|
99
97
|
})
|
|
100
98
|
.map((import_) => code `${import_}`), { on: " | " })})`;
|
|
101
99
|
}
|
|
102
|
-
get
|
|
103
|
-
return
|
|
100
|
+
get schema() {
|
|
101
|
+
return new SchemaObject({
|
|
102
|
+
properties: {
|
|
103
|
+
...super.schema.properties,
|
|
104
|
+
types: code `types: ${arrayOf(...[...this.nodeKinds].map(NodeKind.toTermType))}`,
|
|
105
|
+
},
|
|
106
|
+
type: new SchemaObject.BuiltinType(code `${this.reusables.snippets.TermSchema}<${this.expression}>`),
|
|
107
|
+
variable: super.schema.variable,
|
|
108
|
+
});
|
|
104
109
|
}
|
|
105
110
|
graphqlResolveExpression(_parameters) {
|
|
106
111
|
throw new Error("not implemented");
|
|
@@ -126,8 +131,8 @@ __decorate([
|
|
|
126
131
|
], TermType.prototype, "jsonObjectType", null);
|
|
127
132
|
__decorate([
|
|
128
133
|
Memoize()
|
|
129
|
-
], TermType.prototype, "
|
|
134
|
+
], TermType.prototype, "inlineExpression", null);
|
|
130
135
|
__decorate([
|
|
131
136
|
Memoize()
|
|
132
|
-
], TermType.prototype, "
|
|
137
|
+
], TermType.prototype, "schema", null);
|
|
133
138
|
//# sourceMappingURL=TermType.js.map
|
|
@@ -9,7 +9,7 @@ ${joinCode(this.members.map(({ primaryDiscriminantValue, type, wrap }) => {
|
|
|
9
9
|
const mapAndWrapValue = codeEquals(wrappedValue, valueVariable)
|
|
10
10
|
? ""
|
|
11
11
|
: code `.map(${valueVariable} => (${wrappedValue}))`;
|
|
12
|
-
return code `if (value.${this.configuration.objectDiscriminantProperty.jsonName} === ${literalOf(primaryDiscriminantValue)}) { return ${type.fromJsonObjectFunction.unannotatedUsage}(value, { ...options, schema: ${this.schema}.members[${literalOf(primaryDiscriminantValue)}].type })${mapAndWrapValue} as ${this.reusables.imports.Either}<Error, ${this.expression}>; }`;
|
|
12
|
+
return code `if (value.${this.configuration.objectDiscriminantProperty.jsonName} === ${literalOf(primaryDiscriminantValue)}) { return ${type.fromJsonObjectFunction.unannotatedUsage}(value, { ...options, schema: ${this.schema.variable.map((variable) => code `${variable}.members[${literalOf(primaryDiscriminantValue)}].type`).orDefault(type.schema.expression)} })${mapAndWrapValue} as ${this.reusables.imports.Either}<Error, ${this.expression}>; }`;
|
|
13
13
|
}))}
|
|
14
14
|
|
|
15
15
|
throw new Error("unable to deserialize JSON");
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Maybe } from "purify-ts";
|
|
2
|
+
import type { Callable } from "../Callable.js";
|
|
2
3
|
import type { Reusables } from "../Reusables.js";
|
|
3
4
|
import type { Snippet } from "../Snippet.js";
|
|
4
5
|
import type { TsGenerator } from "../TsGenerator.js";
|
|
@@ -17,9 +18,6 @@ declare abstract class AbstractJsonType {
|
|
|
17
18
|
snippet: Maybe<Snippet>;
|
|
18
19
|
reusables: Reusables;
|
|
19
20
|
});
|
|
20
|
-
protected moduleDeclarations({ unqualifiedName, }: {
|
|
21
|
-
unqualifiedName: string;
|
|
22
|
-
}): Code[];
|
|
23
21
|
get declaration(): Maybe<Code>;
|
|
24
22
|
get expression(): Code;
|
|
25
23
|
get schema(): Code;
|
|
@@ -28,11 +26,17 @@ declare abstract class AbstractJsonType {
|
|
|
28
26
|
scopePrefix: Code;
|
|
29
27
|
};
|
|
30
28
|
}): Maybe<Code>;
|
|
29
|
+
protected moduleDeclarations({ unqualifiedName, }: {
|
|
30
|
+
unqualifiedName: string;
|
|
31
|
+
}): Code[];
|
|
32
|
+
protected schemaTypeExpression({ unqualifiedName, }: {
|
|
33
|
+
unqualifiedName: string;
|
|
34
|
+
}): Code;
|
|
31
35
|
}
|
|
32
36
|
declare abstract class AbstractJsonPrimitiveType<PrimitiveT extends boolean | number | string> extends AbstractJsonType {
|
|
37
|
+
protected abstract readonly typeof: "boolean" | "number" | "string";
|
|
33
38
|
readonly inReference: Maybe<Code>;
|
|
34
39
|
readonly in_: readonly PrimitiveT[];
|
|
35
|
-
protected abstract readonly typeof: "boolean" | "number" | "string";
|
|
36
40
|
constructor({ in_, inReference, ...superParameters }: {
|
|
37
41
|
in_: readonly PrimitiveT[];
|
|
38
42
|
inReference: Maybe<Code>;
|
|
@@ -52,8 +56,8 @@ declare class JsonArrayType extends AbstractJsonType {
|
|
|
52
56
|
protected get schemaExpression(): Code;
|
|
53
57
|
}
|
|
54
58
|
declare class JsonBooleanType extends AbstractJsonPrimitiveType<boolean> {
|
|
55
|
-
readonly kind = "JsonBoolean";
|
|
56
59
|
protected readonly typeof = "boolean";
|
|
60
|
+
readonly kind = "JsonBoolean";
|
|
57
61
|
}
|
|
58
62
|
declare class JsonDiscriminatedUnionType extends AbstractJsonType {
|
|
59
63
|
readonly kind = "JsonDiscriminatedUnion";
|
|
@@ -65,12 +69,6 @@ declare class JsonDiscriminatedUnionType extends AbstractJsonType {
|
|
|
65
69
|
protected get inlineExpression(): Code;
|
|
66
70
|
protected get schemaExpression(): Code;
|
|
67
71
|
}
|
|
68
|
-
declare namespace JsonDiscriminatedUnionType {
|
|
69
|
-
interface Member {
|
|
70
|
-
readonly discriminantValue: number | string;
|
|
71
|
-
readonly type: JsonIntersectionType | JsonObjectType;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
72
|
declare class JsonIntersectionType extends AbstractJsonType {
|
|
75
73
|
readonly kind = "JsonIntersection";
|
|
76
74
|
readonly memberTypes: readonly JsonType[];
|
|
@@ -82,24 +80,29 @@ declare class JsonIntersectionType extends AbstractJsonType {
|
|
|
82
80
|
protected get schemaExpression(): Code;
|
|
83
81
|
}
|
|
84
82
|
declare class JsonNumberType extends AbstractJsonPrimitiveType<number> {
|
|
85
|
-
readonly kind = "JsonNumber";
|
|
86
83
|
protected readonly typeof = "number";
|
|
84
|
+
readonly kind = "JsonNumber";
|
|
87
85
|
}
|
|
88
86
|
declare class JsonObjectType extends AbstractJsonType {
|
|
87
|
+
private readonly cachedMemberTypes;
|
|
88
|
+
private readonly shorthand;
|
|
89
89
|
readonly kind = "JsonObject";
|
|
90
90
|
readonly members: readonly JsonObjectType.Member[];
|
|
91
|
-
|
|
92
|
-
constructor({ members, ...superParameters }: {
|
|
91
|
+
constructor({ members, shorthand, ...superParameters }: {
|
|
93
92
|
members: readonly JsonObjectType.Member[];
|
|
93
|
+
shorthand: Maybe<JsonObjectType.Shorthand>;
|
|
94
94
|
} & ConstructorParameters<typeof AbstractJsonType>[0]);
|
|
95
95
|
protected get inlineExpression(): Code;
|
|
96
96
|
protected get schemaExpression(): Code;
|
|
97
|
+
protected schemaTypeExpression({ unqualifiedName, }: {
|
|
98
|
+
unqualifiedName: string;
|
|
99
|
+
}): Code;
|
|
97
100
|
private get uiSchemaFunctionExpression();
|
|
98
|
-
|
|
101
|
+
uiSchemaElement({ variables, }: Parameters<AbstractJsonType["uiSchemaElement"]>[0]): Maybe<Code>;
|
|
99
102
|
protected moduleDeclarations(parameters: {
|
|
100
103
|
unqualifiedName: string;
|
|
101
104
|
}): Code[];
|
|
102
|
-
|
|
105
|
+
private memberType;
|
|
103
106
|
}
|
|
104
107
|
declare class JsonStringType extends AbstractJsonPrimitiveType<string> {
|
|
105
108
|
private readonly format;
|
|
@@ -149,6 +152,7 @@ declare class JsonTypeFactory {
|
|
|
149
152
|
}): JsonNumberType;
|
|
150
153
|
createJsonObjectType(partialMembers: readonly JsonObjectType.PartialMember[] | Record<string, Omit<JsonObjectType.PartialMember, "name">>, options?: {
|
|
151
154
|
name?: AbstractJsonType.Name;
|
|
155
|
+
shorthand?: JsonObjectType.Shorthand;
|
|
152
156
|
snippet?: Snippet;
|
|
153
157
|
}): JsonObjectType;
|
|
154
158
|
createJsonStringType(options?: {
|
|
@@ -163,6 +167,12 @@ declare class JsonTypeFactory {
|
|
|
163
167
|
type JsonType = JsonArrayType | JsonBooleanType | JsonDiscriminatedUnionType | JsonIntersectionType | JsonNumberType | JsonObjectType | JsonStringType;
|
|
164
168
|
export type AbstractType_JsonType = JsonType;
|
|
165
169
|
export type AbstractType_JsonTypeFactory = JsonTypeFactory;
|
|
170
|
+
declare namespace JsonDiscriminatedUnionType {
|
|
171
|
+
interface Member {
|
|
172
|
+
readonly discriminantValue: number | string;
|
|
173
|
+
readonly type: JsonIntersectionType | JsonObjectType;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
166
176
|
export declare namespace AbstractJsonType {
|
|
167
177
|
type Name = readonly string[];
|
|
168
178
|
}
|
|
@@ -192,6 +202,19 @@ declare namespace JsonObjectType {
|
|
|
192
202
|
recursive?: boolean;
|
|
193
203
|
uiSchemaElement?: Maybe<MemberUiSchemaElementFunction> | MemberUiSchemaElementFunction;
|
|
194
204
|
};
|
|
205
|
+
/**
|
|
206
|
+
* Shorthand for the object type, such as a string that can be transformed into the object.
|
|
207
|
+
*/
|
|
208
|
+
export interface Shorthand {
|
|
209
|
+
/**
|
|
210
|
+
* Zod-compatible transformer that takes an instance of the shorthand type and transforms it to an instance of the object type.
|
|
211
|
+
*/
|
|
212
|
+
readonly transformer: Callable;
|
|
213
|
+
/**
|
|
214
|
+
* Shorthand type, such as a JSON string.
|
|
215
|
+
*/
|
|
216
|
+
readonly type: JsonType;
|
|
217
|
+
}
|
|
195
218
|
export {};
|
|
196
219
|
}
|
|
197
220
|
declare namespace JsonStringType {
|