@shaclmate/compiler 4.0.52 → 4.0.54
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 -1
- package/dist/ShapesGraphToAstTransformer.js +2 -4
- package/dist/_ShapesGraphToAstTransformer/shapeNodeKinds.js +23 -1
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstStructTypeField.js +3 -2
- package/dist/generators/ts/AbstractContainerType.d.ts +2 -1
- package/dist/generators/ts/AbstractContainerType.js +1 -0
- package/dist/generators/ts/AbstractDateType.d.ts +8 -8
- package/dist/generators/ts/AbstractDateType.js +7 -16
- package/dist/generators/ts/AbstractLiteralType.d.ts +3 -4
- package/dist/generators/ts/AbstractLiteralType.js +3 -5
- package/dist/generators/ts/AbstractNumericType.d.ts +0 -2
- package/dist/generators/ts/AbstractNumericType.js +1 -20
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +8 -13
- package/dist/generators/ts/AbstractPrimitiveType.js +22 -19
- package/dist/generators/ts/AbstractTypedLiteralType.d.ts +32 -0
- package/dist/generators/ts/AbstractTypedLiteralType.js +36 -0
- package/dist/generators/ts/BigDecimalType.d.ts +4 -2
- package/dist/generators/ts/BigDecimalType.js +6 -11
- package/dist/generators/ts/BigIntType.js +20 -9
- package/dist/generators/ts/BooleanType.d.ts +0 -2
- package/dist/generators/ts/BooleanType.js +0 -15
- package/dist/generators/ts/DateTimeType.d.ts +1 -1
- package/dist/generators/ts/DateTimeType.js +4 -4
- package/dist/generators/ts/DateType.d.ts +1 -2
- package/dist/generators/ts/DateType.js +4 -4
- package/dist/generators/ts/DefaultValueType.d.ts +3 -0
- package/dist/generators/ts/LangStringType.d.ts +31 -0
- package/dist/generators/ts/LangStringType.js +67 -0
- package/dist/generators/ts/ListType.d.ts +2 -1
- package/dist/generators/ts/ListType.js +1 -0
- package/dist/generators/ts/LiteralType.d.ts +4 -0
- package/dist/generators/ts/LiteralType.js +5 -0
- package/dist/generators/ts/Snippets.d.ts +4 -1
- package/dist/generators/ts/Snippets.js +28 -7
- package/dist/generators/ts/StringType.d.ts +5 -2
- package/dist/generators/ts/StringType.js +9 -17
- package/dist/generators/ts/Type.d.ts +2 -1
- package/dist/generators/ts/TypeFactory.js +32 -81
- package/dist/generators/ts/UnionType.d.ts +1 -1
- package/dist/generators/ts/_snippets/snippets_LangStringSchema.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_LangStringSchema.js +4 -0
- package/dist/generators/ts/_snippets/snippets_RdfVocabularies.js +1 -0
- package/dist/generators/ts/_snippets/snippets_bigDecimalFromRdfResourceValues.js +1 -1
- package/dist/generators/ts/_snippets/snippets_convertToLangString.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_convertToLangString.js +15 -0
- package/dist/generators/ts/_snippets/snippets_langStringFromRdfResourceValues.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_langStringFromRdfResourceValues.js +6 -0
- package/dist/generators/ts/_snippets/snippets_langStringSparqlWherePatterns.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_langStringSparqlWherePatterns.js +5 -0
- package/dist/generators/ts/_snippets/snippets_literalFromRdfResourceValues.js +1 -1
- package/dist/generators/ts/_snippets/snippets_literalSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_sparqlValueInPattern.js +4 -1
- package/dist/generators/ts/_snippets/snippets_termFromRdfResourceValues.js +2 -2
- package/dist/generators/ts/_snippets/snippets_termLikeFromRdfResourceValues.js +1 -1
- package/dist/generators/ts/rdfjsTermExpression.js +1 -0
- package/dist/input/input.shaclmate.js +3 -3
- package/package.json +19 -8
- package/dist/generators/ts/_snippets/snippets_decodeBigDecimalLiteral.d.ts +0 -3
- package/dist/generators/ts/_snippets/snippets_decodeBigDecimalLiteral.js +0 -9
|
@@ -6,7 +6,7 @@ import type * as ast from "./ast/index.js";
|
|
|
6
6
|
import type * as input from "./input/index.js";
|
|
7
7
|
export declare class ShapesGraphToAstTransformer {
|
|
8
8
|
protected readonly cachedAstTypesByShapeIdentifier: TermMap<BlankNode | NamedNode, ast.Type>;
|
|
9
|
-
protected readonly
|
|
9
|
+
protected readonly syntheticAstStructTypes: ast.StructType[];
|
|
10
10
|
protected readonly logger: Logger;
|
|
11
11
|
protected readonly shapesGraph: input.ShapesGraph;
|
|
12
12
|
constructor({ logger, shapesGraph, }: {
|
|
@@ -5,7 +5,7 @@ import { transformShapeToAstType } from "./_ShapesGraphToAstTransformer/transfor
|
|
|
5
5
|
export class ShapesGraphToAstTransformer {
|
|
6
6
|
// Members are protected so they're accessible to functions in other files
|
|
7
7
|
cachedAstTypesByShapeIdentifier = new TermMap();
|
|
8
|
-
|
|
8
|
+
syntheticAstStructTypes = [];
|
|
9
9
|
logger;
|
|
10
10
|
shapesGraph;
|
|
11
11
|
constructor({ logger, shapesGraph, }) {
|
|
@@ -41,9 +41,7 @@ export class ShapesGraphToAstTransformer {
|
|
|
41
41
|
return acc;
|
|
42
42
|
}
|
|
43
43
|
}, 0),
|
|
44
|
-
namedTypes: astNamedTypes.concat(
|
|
45
|
-
...this.syntheticAstStructTypesByName.values(),
|
|
46
|
-
]),
|
|
44
|
+
namedTypes: astNamedTypes.concat(this.syntheticAstStructTypes),
|
|
47
45
|
});
|
|
48
46
|
}
|
|
49
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeKind } from "@shaclmate/shacl-ast";
|
|
2
|
-
import { Either, Left } from "purify-ts";
|
|
2
|
+
import { Either, Left, Maybe } from "purify-ts";
|
|
3
3
|
import { defaultNodeShapeNodeKinds } from "./defaultNodeShapeNodeKinds.js";
|
|
4
4
|
const defaultPropertyShapeNodeKinds = new Set([
|
|
5
5
|
"BlankNode",
|
|
@@ -90,6 +90,28 @@ export function shapeNodeKinds(shape, options) {
|
|
|
90
90
|
.orDefault([]),
|
|
91
91
|
},
|
|
92
92
|
],
|
|
93
|
+
[
|
|
94
|
+
"sh:node",
|
|
95
|
+
{
|
|
96
|
+
includeNodeKinds: shape.node
|
|
97
|
+
.chain((node) => this.shapesGraph.nodeShape(node).toMaybe())
|
|
98
|
+
.chain((nodeShape) => shapeNodeKinds.call(this, nodeShape).toMaybe())
|
|
99
|
+
.map((nodeKinds) => [...nodeKinds])
|
|
100
|
+
.orDefault([]),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
"shaclmate:resolve",
|
|
105
|
+
{
|
|
106
|
+
includeNodeKinds: (shape.$type === "PropertyShape"
|
|
107
|
+
? shape.resolve
|
|
108
|
+
: Maybe.empty())
|
|
109
|
+
.chain((resolve) => this.shapesGraph.nodeShape(resolve).toMaybe())
|
|
110
|
+
.chain((nodeShape) => shapeNodeKinds.call(this, nodeShape).toMaybe())
|
|
111
|
+
.map((nodeKinds) => [...nodeKinds])
|
|
112
|
+
.orDefault([]),
|
|
113
|
+
},
|
|
114
|
+
],
|
|
93
115
|
]) {
|
|
94
116
|
for (const excludeNodeKind of excludeNodeKinds ?? []) {
|
|
95
117
|
if (explicitNodeKinds.size > 0 &&
|
|
@@ -60,7 +60,8 @@ function synthesizePartialAstStructType({ identifierType, }) {
|
|
|
60
60
|
syntheticName = "NamedDefaultPartial";
|
|
61
61
|
break;
|
|
62
62
|
}
|
|
63
|
-
let partialAstStructType = this.
|
|
63
|
+
let partialAstStructType = this.syntheticAstStructTypes.find((syntheticAstStructType) => syntheticAstStructType.name.extract() === syntheticName &&
|
|
64
|
+
ast.Type.equals(syntheticAstStructType.identifierType, identifierType));
|
|
64
65
|
if (partialAstStructType) {
|
|
65
66
|
return partialAstStructType;
|
|
66
67
|
}
|
|
@@ -76,7 +77,7 @@ function synthesizePartialAstStructType({ identifierType, }) {
|
|
|
76
77
|
toRdfTypes: [],
|
|
77
78
|
tsImports: [],
|
|
78
79
|
});
|
|
79
|
-
this.
|
|
80
|
+
this.syntheticAstStructTypes.push(partialAstStructType);
|
|
80
81
|
return partialAstStructType;
|
|
81
82
|
}
|
|
82
83
|
function transformPropertyShapeToAstType(propertyShape, shapeStack) {
|
|
@@ -10,6 +10,7 @@ import type { FloatType } from "./FloatType.js";
|
|
|
10
10
|
import type { IdentifierType } from "./IdentifierType.js";
|
|
11
11
|
import type { IntType } from "./IntType.js";
|
|
12
12
|
import type { IriType } from "./IriType.js";
|
|
13
|
+
import type { LangStringType } from "./LangStringType.js";
|
|
13
14
|
import type { ListType } from "./ListType.js";
|
|
14
15
|
import type { LiteralType } from "./LiteralType.js";
|
|
15
16
|
import type { ObjectType } from "./ObjectType.js";
|
|
@@ -45,7 +46,7 @@ export declare namespace AbstractContainerType {
|
|
|
45
46
|
type DiscriminantProperty = AbstractType.DiscriminantProperty;
|
|
46
47
|
const GraphqlType: typeof AbstractType.GraphqlType;
|
|
47
48
|
type GraphqlType = AbstractType.GraphqlType;
|
|
48
|
-
type ItemType = BigDecimalType | BigIntType | BlankNodeType | BooleanType | DateTimeType | DateType | FloatType | IdentifierType | IntType | IriType | ListType<ListType.ItemType> | LiteralType | ObjectUnionType | ObjectType | StringType | TermType | UnionType<Type>;
|
|
49
|
+
type ItemType = BigDecimalType | BigIntType | BlankNodeType | BooleanType | DateTimeType | DateType | FloatType | IdentifierType | IntType | IriType | LangStringType | ListType<ListType.ItemType> | LiteralType | ObjectUnionType | ObjectType | StringType | TermType | UnionType<Type>;
|
|
49
50
|
function isItemType(type: Type): type is ItemType;
|
|
50
51
|
const JsonType: typeof AbstractType.JsonType;
|
|
51
52
|
type JsonType = AbstractType.JsonType;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
2
3
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
3
|
-
export declare abstract class AbstractDateType extends
|
|
4
|
+
export declare abstract class AbstractDateType extends AbstractTypedLiteralType<Date> {
|
|
4
5
|
protected readonly inlineExpression: Code;
|
|
6
|
+
readonly conversionFunction: Maybe<AbstractTypedLiteralType.ConversionFunction>;
|
|
5
7
|
readonly equalsFunction: Code;
|
|
6
8
|
readonly filterFunction: Code;
|
|
7
9
|
readonly filterType: Code;
|
|
@@ -9,15 +11,13 @@ export declare abstract class AbstractDateType extends AbstractPrimitiveType<Dat
|
|
|
9
11
|
readonly instanceof: "Date";
|
|
10
12
|
readonly typeof: "object";
|
|
11
13
|
}];
|
|
12
|
-
abstract readonly kind: "DateTime" | "Date";
|
|
13
|
-
readonly mutable = false;
|
|
14
14
|
readonly schemaType: Code;
|
|
15
15
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
16
|
-
fromJsonExpression({ variables, }: Parameters<
|
|
17
|
-
jsonType():
|
|
18
|
-
toRdfResourceValuesExpression({ variables, }: Parameters<
|
|
16
|
+
fromJsonExpression({ variables, }: Parameters<AbstractTypedLiteralType<Date>["fromJsonExpression"]>[0]): Code;
|
|
17
|
+
jsonType(): AbstractTypedLiteralType.JsonType;
|
|
18
|
+
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractTypedLiteralType<Date>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
19
19
|
}
|
|
20
20
|
export declare namespace AbstractDateType {
|
|
21
|
-
type ConversionFunction =
|
|
21
|
+
type ConversionFunction = AbstractTypedLiteralType.ConversionFunction;
|
|
22
22
|
}
|
|
23
23
|
//# sourceMappingURL=AbstractDateType.d.ts.map
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Memoize } from "typescript-memoize";
|
|
8
|
-
import { AbstractPrimitiveType } from "./AbstractPrimitiveType.js";
|
|
9
|
-
import { code } from "./ts-poet-wrapper.js";
|
|
10
|
-
export class AbstractDateType extends AbstractPrimitiveType {
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
3
|
+
import { code, literalOf } from "./ts-poet-wrapper.js";
|
|
4
|
+
export class AbstractDateType extends AbstractTypedLiteralType {
|
|
11
5
|
inlineExpression = code `Date`;
|
|
6
|
+
conversionFunction = Maybe.empty();
|
|
12
7
|
equalsFunction = code `${this.reusables.snippets.dateEquals}`;
|
|
13
8
|
filterFunction = code `${this.reusables.snippets.filterDate}`;
|
|
14
9
|
filterType = code `${this.reusables.snippets.DateFilter}`;
|
|
@@ -18,20 +13,16 @@ export class AbstractDateType extends AbstractPrimitiveType {
|
|
|
18
13
|
typeof: "object",
|
|
19
14
|
},
|
|
20
15
|
];
|
|
21
|
-
mutable = false;
|
|
22
16
|
schemaType = code `${this.reusables.snippets.DateSchema}`;
|
|
23
17
|
valueSparqlWherePatternsFunction = code `${this.reusables.snippets.dateSparqlWherePatterns}`;
|
|
24
18
|
fromJsonExpression({ variables, }) {
|
|
25
|
-
return code `${this.reusables.imports.Either}.of<Error, Date>(new Date(${variables.value}))`;
|
|
19
|
+
return code `${this.reusables.imports.Either}.of<Error, Date>(new Date(${variables.value}["@value"]))`;
|
|
26
20
|
}
|
|
27
21
|
jsonType() {
|
|
28
|
-
return new
|
|
22
|
+
return new AbstractTypedLiteralType.JsonType(code `{ readonly "@type": ${literalOf(this.datatype.value)}, readonly "@value": string }`);
|
|
29
23
|
}
|
|
30
24
|
toRdfResourceValuesExpression({ variables, }) {
|
|
31
25
|
return code `[${this.reusables.snippets.literalFactory}.date(${variables.value}, ${this.rdfjsTermExpression(this.datatype)})]`;
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
|
-
__decorate([
|
|
35
|
-
Memoize()
|
|
36
|
-
], AbstractDateType.prototype, "jsonType", null);
|
|
37
28
|
//# sourceMappingURL=AbstractDateType.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { Literal } from "@rdfjs/types";
|
|
2
2
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
3
3
|
import type { Code } from "./ts-poet-wrapper.js";
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class of all types that are literals in RDF.
|
|
6
|
+
*/
|
|
4
7
|
export declare abstract class AbstractLiteralType extends AbstractTermType<Literal, Literal> {
|
|
5
|
-
protected readonly languageIn: readonly string[];
|
|
6
8
|
readonly nodeKinds: ReadonlySet<"Literal">;
|
|
7
|
-
constructor({ languageIn, ...superParameters }: {
|
|
8
|
-
languageIn: readonly string[];
|
|
9
|
-
} & ConstructorParameters<typeof AbstractTermType<Literal, Literal>>[0]);
|
|
10
9
|
/**
|
|
11
10
|
* An expression that converts a compile-time RDF/JS Literal into a runtime TypeScript literal.
|
|
12
11
|
*
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { AbstractTermType } from "./AbstractTermType.js";
|
|
2
|
+
/**
|
|
3
|
+
* Abstract base class of all types that are literals in RDF.
|
|
4
|
+
*/
|
|
2
5
|
export class AbstractLiteralType extends AbstractTermType {
|
|
3
|
-
languageIn;
|
|
4
6
|
nodeKinds = nodeKinds;
|
|
5
|
-
constructor({ languageIn, ...superParameters }) {
|
|
6
|
-
super(superParameters);
|
|
7
|
-
this.languageIn = languageIn;
|
|
8
|
-
}
|
|
9
7
|
}
|
|
10
8
|
(function (AbstractLiteralType) {
|
|
11
9
|
AbstractLiteralType.GraphqlType = AbstractTermType.GraphqlType;
|
|
@@ -10,8 +10,6 @@ export declare abstract class AbstractNumericType<ValueT extends bigint | number
|
|
|
10
10
|
get filterType(): Code;
|
|
11
11
|
get schemaType(): Code;
|
|
12
12
|
get valueSparqlWherePatternsFunction(): Code;
|
|
13
|
-
protected get inlineExpression(): Code;
|
|
14
|
-
jsonSchema(_parameters: Parameters<AbstractPrimitiveType<ValueT>["jsonSchema"]>[0]): Code;
|
|
15
13
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<string>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
16
14
|
}
|
|
17
15
|
export declare namespace AbstractNumericType {
|
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Memoize } from "typescript-memoize";
|
|
8
8
|
import { AbstractPrimitiveType } from "./AbstractPrimitiveType.js";
|
|
9
|
-
import { code
|
|
9
|
+
import { code } from "./ts-poet-wrapper.js";
|
|
10
10
|
/**
|
|
11
11
|
* Abstract base class for TypeScript numeric types (bigint | number).
|
|
12
12
|
*/
|
|
@@ -24,22 +24,6 @@ export class AbstractNumericType extends AbstractPrimitiveType {
|
|
|
24
24
|
get valueSparqlWherePatternsFunction() {
|
|
25
25
|
return code `${this.reusables.snippets.numericSparqlWherePatterns}<${this.expression}>`;
|
|
26
26
|
}
|
|
27
|
-
get inlineExpression() {
|
|
28
|
-
if (this.primitiveIn.length > 0) {
|
|
29
|
-
return code `${joinCode(this.primitiveIn.map((value) => this.literalValueExpression(value)), { on: " | " })}`;
|
|
30
|
-
}
|
|
31
|
-
return code `${this.jsTypes[0].typeof}`;
|
|
32
|
-
}
|
|
33
|
-
jsonSchema(_parameters) {
|
|
34
|
-
switch (this.primitiveIn.length) {
|
|
35
|
-
case 0:
|
|
36
|
-
return code `${this.reusables.imports.z}.${this.jsTypes[0].typeof}()`;
|
|
37
|
-
case 1:
|
|
38
|
-
return code `${this.reusables.imports.z}.literal(${this.literalValueExpression(this.primitiveIn[0])})`;
|
|
39
|
-
default:
|
|
40
|
-
return code `${this.reusables.imports.z}.union([${joinCode(this.primitiveIn.map((value) => code `${this.reusables.imports.z}.literal(${this.literalValueExpression(value)})`), { on: "," })}])`;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
27
|
toRdfResourceValuesExpression({ variables, }) {
|
|
44
28
|
return code `[${this.reusables.snippets.literalFactory}.${this.jsTypes[0].typeof}(${variables.value}, ${this.rdfjsTermExpression(this.datatype)})]`;
|
|
45
29
|
}
|
|
@@ -56,9 +40,6 @@ __decorate([
|
|
|
56
40
|
__decorate([
|
|
57
41
|
Memoize()
|
|
58
42
|
], AbstractNumericType.prototype, "valueSparqlWherePatternsFunction", null);
|
|
59
|
-
__decorate([
|
|
60
|
-
Memoize()
|
|
61
|
-
], AbstractNumericType.prototype, "inlineExpression", null);
|
|
62
43
|
(function (AbstractNumericType) {
|
|
63
44
|
AbstractNumericType.JsonType = AbstractPrimitiveType.JsonType;
|
|
64
45
|
})(AbstractNumericType || (AbstractNumericType = {}));
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Primitive } from "@rdfx/literal";
|
|
2
2
|
import { Maybe } from "purify-ts";
|
|
3
3
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
4
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
4
5
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class of typed literals whose datatype corresponds to a JavaScript primitive type.
|
|
8
|
+
*/
|
|
9
|
+
export declare abstract class AbstractPrimitiveType<ValueT extends Primitive> extends AbstractTypedLiteralType<ValueT> {
|
|
7
10
|
readonly conversionFunction: Maybe<AbstractLiteralType.ConversionFunction>;
|
|
8
11
|
readonly equalsFunction: Code;
|
|
9
|
-
|
|
10
|
-
readonly primitiveIn: readonly ValueT[];
|
|
11
|
-
constructor({ datatype, primitiveIn, ...superParameters }: {
|
|
12
|
-
datatype: NamedNode;
|
|
13
|
-
primitiveIn: readonly ValueT[];
|
|
14
|
-
} & ConstructorParameters<typeof AbstractLiteralType>[0]);
|
|
15
|
-
get discriminantProperty(): Maybe<AbstractLiteralType.DiscriminantProperty>;
|
|
16
|
-
protected get schemaInitializers(): readonly Code[];
|
|
12
|
+
protected get inlineExpression(): Code;
|
|
17
13
|
fromJsonExpression({ variables, }: Parameters<AbstractLiteralType["fromJsonExpression"]>[0]): Code;
|
|
18
|
-
|
|
14
|
+
jsonSchema(_parameters: Parameters<AbstractTypedLiteralType<ValueT>["jsonSchema"]>[0]): Code;
|
|
19
15
|
jsonType(): AbstractLiteralType.JsonType;
|
|
20
|
-
abstract literalValueExpression(literal: Literal | ValueT): Code;
|
|
21
16
|
toJsonExpression({ variables, }: Parameters<AbstractLiteralType["toJsonExpression"]>[0]): Code;
|
|
22
17
|
}
|
|
23
18
|
export declare namespace AbstractPrimitiveType {
|
|
@@ -7,32 +7,32 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
11
|
+
import { arrayOf, code, joinCode } from "./ts-poet-wrapper.js";
|
|
12
|
+
/**
|
|
13
|
+
* Abstract base class of typed literals whose datatype corresponds to a JavaScript primitive type.
|
|
14
|
+
*/
|
|
15
|
+
export class AbstractPrimitiveType extends AbstractTypedLiteralType {
|
|
13
16
|
conversionFunction = Maybe.empty();
|
|
14
17
|
equalsFunction = code `${this.reusables.snippets.strictEquals}`;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.datatype = datatype;
|
|
19
|
-
this.primitiveIn = primitiveIn;
|
|
20
|
-
}
|
|
21
|
-
get discriminantProperty() {
|
|
22
|
-
return Maybe.empty();
|
|
23
|
-
}
|
|
24
|
-
get schemaInitializers() {
|
|
25
|
-
let initializers = super.schemaInitializers;
|
|
26
|
-
if (this.primitiveIn.length > 0) {
|
|
27
|
-
initializers = initializers.concat(code `in: ${arrayOf(...this.primitiveIn.map((in_) => this.literalValueExpression(in_)))} as const`);
|
|
18
|
+
get inlineExpression() {
|
|
19
|
+
if (this.decodedIn.length > 0) {
|
|
20
|
+
return code `${joinCode(this.decodedIn.map((value) => this.literalValueExpression(value)), { on: " | " })}`;
|
|
28
21
|
}
|
|
29
|
-
return
|
|
22
|
+
return code `${this.jsTypes[0].typeof}`;
|
|
30
23
|
}
|
|
31
24
|
fromJsonExpression({ variables, }) {
|
|
32
25
|
return code `${this.reusables.imports.Either}.of<Error, ${this.expression}>(${variables.value})`;
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
jsonSchema(_parameters) {
|
|
28
|
+
switch (this.decodedIn.length) {
|
|
29
|
+
case 0:
|
|
30
|
+
return code `${this.reusables.imports.z}.${this.jsTypes[0].typeof}()`;
|
|
31
|
+
case 1:
|
|
32
|
+
return code `${this.reusables.imports.z}.literal(${this.literalValueExpression(this.decodedIn[0])})`;
|
|
33
|
+
default:
|
|
34
|
+
return code `${this.reusables.imports.z}.union(${arrayOf(...this.decodedIn.map((value) => code `${this.reusables.imports.z}.literal(${this.literalValueExpression(value)})`))})`;
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
jsonType() {
|
|
38
38
|
return new AbstractLiteralType.JsonType(this.expression);
|
|
@@ -41,6 +41,9 @@ export class AbstractPrimitiveType extends AbstractLiteralType {
|
|
|
41
41
|
return variables.value;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
__decorate([
|
|
45
|
+
Memoize()
|
|
46
|
+
], AbstractPrimitiveType.prototype, "inlineExpression", null);
|
|
44
47
|
__decorate([
|
|
45
48
|
Memoize()
|
|
46
49
|
], AbstractPrimitiveType.prototype, "jsonType", null);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Literal, NamedNode } from "@rdfjs/types";
|
|
2
|
+
import { Maybe } from "purify-ts";
|
|
3
|
+
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
4
|
+
import { AbstractTermType } from "./AbstractTermType.js";
|
|
5
|
+
import { type Code } from "./ts-poet-wrapper.js";
|
|
6
|
+
/**
|
|
7
|
+
* Abstract base class of all types that are typed literals in RDF. In RDF every literal is either
|
|
8
|
+
* - a language-tagged string literal (datatype = rdf:langString, language = not empty)
|
|
9
|
+
* - a typed literal (datatype = anything else, language = empty)
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class AbstractTypedLiteralType<ValueT> extends AbstractLiteralType {
|
|
12
|
+
readonly datatype: NamedNode;
|
|
13
|
+
readonly decodedIn: readonly ValueT[];
|
|
14
|
+
constructor({ datatype, decodedIn, ...superParameters }: {
|
|
15
|
+
datatype: NamedNode;
|
|
16
|
+
readonly decodedIn: readonly ValueT[];
|
|
17
|
+
} & ConstructorParameters<typeof AbstractLiteralType>[0]);
|
|
18
|
+
get discriminantProperty(): Maybe<AbstractLiteralType.DiscriminantProperty>;
|
|
19
|
+
protected get schemaInitializers(): readonly Code[];
|
|
20
|
+
graphqlResolveExpression({ variables, }: Parameters<AbstractLiteralType["graphqlResolveExpression"]>[0]): Code;
|
|
21
|
+
abstract literalValueExpression(literal: Literal | ValueT): Code;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace AbstractTypedLiteralType {
|
|
24
|
+
type ConversionFunction = AbstractTermType.ConversionFunction;
|
|
25
|
+
type DiscriminantProperty = AbstractTermType.DiscriminantProperty;
|
|
26
|
+
const GraphqlType: typeof import("./AbstractType.js").AbstractType.GraphqlType;
|
|
27
|
+
type GraphqlType = AbstractTermType.GraphqlType;
|
|
28
|
+
type JsType = AbstractTermType.JsType;
|
|
29
|
+
const JsonType: typeof import("./AbstractType.js").AbstractType.JsonType;
|
|
30
|
+
type JsonType = AbstractTermType.JsonType;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=AbstractTypedLiteralType.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
|
+
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
3
|
+
import { AbstractTermType } from "./AbstractTermType.js";
|
|
4
|
+
import { arrayOf, code } from "./ts-poet-wrapper.js";
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class of all types that are typed literals in RDF. In RDF every literal is either
|
|
7
|
+
* - a language-tagged string literal (datatype = rdf:langString, language = not empty)
|
|
8
|
+
* - a typed literal (datatype = anything else, language = empty)
|
|
9
|
+
*/
|
|
10
|
+
export class AbstractTypedLiteralType extends AbstractLiteralType {
|
|
11
|
+
datatype;
|
|
12
|
+
decodedIn;
|
|
13
|
+
constructor({ datatype, decodedIn, ...superParameters }) {
|
|
14
|
+
super(superParameters);
|
|
15
|
+
this.datatype = datatype;
|
|
16
|
+
this.decodedIn = decodedIn;
|
|
17
|
+
}
|
|
18
|
+
get discriminantProperty() {
|
|
19
|
+
return Maybe.empty();
|
|
20
|
+
}
|
|
21
|
+
get schemaInitializers() {
|
|
22
|
+
let initializers = super.schemaInitializers;
|
|
23
|
+
if (this.decodedIn.length > 0) {
|
|
24
|
+
initializers = initializers.concat(code `in: ${arrayOf(...this.decodedIn.map((in_) => this.literalValueExpression(in_)))} as const`);
|
|
25
|
+
}
|
|
26
|
+
return initializers;
|
|
27
|
+
}
|
|
28
|
+
graphqlResolveExpression({ variables, }) {
|
|
29
|
+
return variables.value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
(function (AbstractTypedLiteralType) {
|
|
33
|
+
AbstractTypedLiteralType.GraphqlType = AbstractTermType.GraphqlType;
|
|
34
|
+
AbstractTypedLiteralType.JsonType = AbstractTermType.JsonType;
|
|
35
|
+
})(AbstractTypedLiteralType || (AbstractTypedLiteralType = {}));
|
|
36
|
+
//# sourceMappingURL=AbstractTypedLiteralType.js.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Literal } from "@rdfjs/types";
|
|
2
|
+
import type { Decimal } from "decimal.js";
|
|
2
3
|
import { Maybe } from "purify-ts";
|
|
3
4
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
5
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
4
6
|
import { type Code } from "./ts-poet-wrapper.js";
|
|
5
|
-
export declare class BigDecimalType extends
|
|
7
|
+
export declare class BigDecimalType extends AbstractTypedLiteralType<Decimal> {
|
|
6
8
|
protected readonly inlineExpression: Code;
|
|
7
9
|
readonly conversionFunction: Maybe<AbstractLiteralType.ConversionFunction>;
|
|
8
10
|
readonly filterFunction: Code;
|
|
@@ -22,7 +24,7 @@ export declare class BigDecimalType extends AbstractLiteralType {
|
|
|
22
24
|
jsonSchema(): Code;
|
|
23
25
|
jsonType(): AbstractLiteralType.JsonType;
|
|
24
26
|
literalValueExpression(literal: Literal): Code;
|
|
25
|
-
toJsonExpression({ variables, }: Parameters<
|
|
27
|
+
toJsonExpression({ variables, }: Parameters<AbstractTypedLiteralType<Decimal>["toJsonExpression"]>[0]): Code;
|
|
26
28
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractLiteralType["toRdfResourceValuesExpression"]>[0]): Code;
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=BigDecimalType.d.ts.map
|
|
@@ -7,8 +7,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractLiteralType } from "./AbstractLiteralType.js";
|
|
10
|
+
import { AbstractTypedLiteralType } from "./AbstractTypedLiteralType.js";
|
|
10
11
|
import { code, literalOf } from "./ts-poet-wrapper.js";
|
|
11
|
-
export class BigDecimalType extends
|
|
12
|
+
export class BigDecimalType extends AbstractTypedLiteralType {
|
|
12
13
|
inlineExpression = code `${this.reusables.imports.BigDecimal}`;
|
|
13
14
|
conversionFunction = Maybe.empty();
|
|
14
15
|
filterFunction = code `${this.reusables.snippets.filterBigDecimal}`;
|
|
@@ -25,22 +26,22 @@ export class BigDecimalType extends AbstractLiteralType {
|
|
|
25
26
|
return new AbstractLiteralType.GraphqlType(code `${this.reusables.imports.GraphQLString}`, this.reusables);
|
|
26
27
|
}
|
|
27
28
|
fromJsonExpression({ variables, }) {
|
|
28
|
-
return code `${this.reusables.imports.Either}.encase<Error, ${this.expression}>(() => new ${this.expression}(${variables.value}))`;
|
|
29
|
+
return code `${this.reusables.imports.Either}.encase<Error, ${this.expression}>(() => new ${this.expression}(${variables.value}["@value"]))`;
|
|
29
30
|
}
|
|
30
31
|
graphqlResolveExpression({ variables, }) {
|
|
31
32
|
return code `${variables.value}.toFixed()`;
|
|
32
33
|
}
|
|
33
34
|
jsonSchema() {
|
|
34
|
-
return code `${this.reusables.imports.z}.string()`;
|
|
35
|
+
return code `${this.reusables.imports.z}.object({ "@type": ${this.reusables.imports.z}.literal(${literalOf(this.datatype.value)}), "@value": ${this.reusables.imports.z}.string() })`;
|
|
35
36
|
}
|
|
36
37
|
jsonType() {
|
|
37
|
-
return new AbstractLiteralType.JsonType(code `string`);
|
|
38
|
+
return new AbstractLiteralType.JsonType(code `{ readonly "@type": ${literalOf(this.datatype.value)}, readonly "@value": string }`);
|
|
38
39
|
}
|
|
39
40
|
literalValueExpression(literal) {
|
|
40
41
|
return code `new ${this.reusables.imports.BigDecimal}(${literalOf(literal.value)})`;
|
|
41
42
|
}
|
|
42
43
|
toJsonExpression({ variables, }) {
|
|
43
|
-
return code
|
|
44
|
+
return code `{ "@type": ${literalOf(this.datatype.value)} as const, "@value": ${variables.value}.toFixed() }`;
|
|
44
45
|
}
|
|
45
46
|
toRdfResourceValuesExpression({ variables, }) {
|
|
46
47
|
return code `[${this.reusables.snippets.bigDecimalLiteral}(${variables.value})]`;
|
|
@@ -49,10 +50,4 @@ export class BigDecimalType extends AbstractLiteralType {
|
|
|
49
50
|
__decorate([
|
|
50
51
|
Memoize()
|
|
51
52
|
], BigDecimalType.prototype, "graphqlType", null);
|
|
52
|
-
__decorate([
|
|
53
|
-
Memoize()
|
|
54
|
-
], BigDecimalType.prototype, "jsonSchema", null);
|
|
55
|
-
__decorate([
|
|
56
|
-
Memoize()
|
|
57
|
-
], BigDecimalType.prototype, "jsonType", null);
|
|
58
53
|
//# sourceMappingURL=BigDecimalType.js.map
|
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { LiteralDecoder } from "@rdfx/literal";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { AbstractNumericType } from "./AbstractNumericType.js";
|
|
10
|
-
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
10
|
+
import { arrayOf, code, joinCode, literalOf, } from "./ts-poet-wrapper.js";
|
|
11
11
|
export class BigIntType extends AbstractNumericType {
|
|
12
12
|
jsTypes = [{ typeof: "bigint" }];
|
|
13
13
|
kind = "BigInt";
|
|
@@ -18,30 +18,41 @@ export class BigIntType extends AbstractNumericType {
|
|
|
18
18
|
return new AbstractNumericType.GraphqlType(code `${this.reusables.imports.GraphQLBigInt}`, this.reusables);
|
|
19
19
|
}
|
|
20
20
|
fromJsonExpression({ variables, }) {
|
|
21
|
-
let expression = code `BigInt(${variables.value})`;
|
|
22
|
-
if (this.
|
|
21
|
+
let expression = code `BigInt(${variables.value}["@value"])`;
|
|
22
|
+
if (this.decodedIn.length > 0) {
|
|
23
23
|
expression = code `${expression} as ${this.expression}`;
|
|
24
24
|
}
|
|
25
25
|
return code `${this.reusables.imports.Either}.encase<Error, ${this.expression}>(() => ${expression})`;
|
|
26
26
|
}
|
|
27
27
|
jsonSchema(_parameters) {
|
|
28
|
-
|
|
28
|
+
let valueJsonSchema;
|
|
29
|
+
switch (this.decodedIn.length) {
|
|
29
30
|
case 0:
|
|
30
|
-
|
|
31
|
+
valueJsonSchema = code `${this.reusables.imports.z}.string()`;
|
|
32
|
+
break;
|
|
31
33
|
case 1:
|
|
32
|
-
|
|
34
|
+
valueJsonSchema = code `${this.reusables.imports.z}.literal(${literalOf(this.decodedIn[0].toString())})`;
|
|
35
|
+
break;
|
|
33
36
|
default:
|
|
34
|
-
|
|
37
|
+
valueJsonSchema = code `${this.reusables.imports.z}.enum(${arrayOf(...this.decodedIn.map((value) => code `${literalOf(value.toString())}`))})`;
|
|
38
|
+
break;
|
|
35
39
|
}
|
|
40
|
+
return code `${this.reusables.imports.z}.object({ "@type": ${this.reusables.imports.z}.literal(${literalOf(this.datatype.value)}), "@value": ${valueJsonSchema} })`;
|
|
36
41
|
}
|
|
37
42
|
jsonType() {
|
|
38
|
-
return new AbstractNumericType.JsonType(code `
|
|
43
|
+
return new AbstractNumericType.JsonType(code `{ readonly "@type": ${literalOf(this.datatype.value)}, readonly "@value": ${this.decodedIn.length === 0
|
|
44
|
+
? "string"
|
|
45
|
+
: joinCode(this.decodedIn.map((in_) => code `${literalOf(in_.toString())}`), { on: " | " })} }`);
|
|
39
46
|
}
|
|
40
47
|
literalValueExpression(literal) {
|
|
41
48
|
return code `${typeof literal === "bigint" ? literal : LiteralDecoder.decodeBigIntLiteral(literal).unsafeCoerce()}n`;
|
|
42
49
|
}
|
|
43
50
|
toJsonExpression({ variables, }) {
|
|
44
|
-
|
|
51
|
+
let valueExpression = code `${variables.value}.toString()`;
|
|
52
|
+
if (this.decodedIn.length > 0) {
|
|
53
|
+
valueExpression = code `${valueExpression} as ${joinCode(this.decodedIn.map((in_) => code `${literalOf(in_.toString())}`), { on: " | " })}`;
|
|
54
|
+
}
|
|
55
|
+
return code `{ "@type": ${literalOf(this.datatype.value)} as const, "@value": ${valueExpression} }`;
|
|
45
56
|
}
|
|
46
57
|
}
|
|
47
58
|
__decorate([
|
|
@@ -13,8 +13,6 @@ export declare class BooleanType extends AbstractPrimitiveType<boolean> {
|
|
|
13
13
|
readonly valueSparqlWherePatternsFunction: Code;
|
|
14
14
|
get fromRdfResourceValuesFunction(): Code;
|
|
15
15
|
get schemaType(): Code;
|
|
16
|
-
protected get inlineExpression(): Code;
|
|
17
|
-
jsonSchema(_parameters: Parameters<AbstractPrimitiveType<number>["jsonSchema"]>[0]): Code;
|
|
18
16
|
literalValueExpression(literal: boolean | Literal): Code;
|
|
19
17
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractPrimitiveType<boolean>["toRdfResourceValuesExpression"]>[0]): Code;
|
|
20
18
|
}
|
|
@@ -22,18 +22,6 @@ export class BooleanType extends AbstractPrimitiveType {
|
|
|
22
22
|
get schemaType() {
|
|
23
23
|
return code `${this.reusables.snippets.BooleanSchema}<${this.expression}>`;
|
|
24
24
|
}
|
|
25
|
-
get inlineExpression() {
|
|
26
|
-
if (this.primitiveIn.length > 0) {
|
|
27
|
-
return code `${this.primitiveIn.map((value) => value.toString()).join(" | ")}`;
|
|
28
|
-
}
|
|
29
|
-
return code `boolean`;
|
|
30
|
-
}
|
|
31
|
-
jsonSchema(_parameters) {
|
|
32
|
-
if (this.primitiveIn.length === 1) {
|
|
33
|
-
return code `${this.reusables.imports.z}.literal(${this.primitiveIn[0]})`;
|
|
34
|
-
}
|
|
35
|
-
return code `${this.reusables.imports.z}.boolean()`;
|
|
36
|
-
}
|
|
37
25
|
literalValueExpression(literal) {
|
|
38
26
|
return code `${typeof literal === "boolean" ? literal : LiteralDecoder.decodeBooleanLiteral(literal).unsafeCoerce()}`;
|
|
39
27
|
}
|
|
@@ -47,7 +35,4 @@ __decorate([
|
|
|
47
35
|
__decorate([
|
|
48
36
|
Memoize()
|
|
49
37
|
], BooleanType.prototype, "schemaType", null);
|
|
50
|
-
__decorate([
|
|
51
|
-
Memoize()
|
|
52
|
-
], BooleanType.prototype, "inlineExpression", null);
|
|
53
38
|
//# sourceMappingURL=BooleanType.js.map
|
|
@@ -6,7 +6,7 @@ export declare class DateTimeType extends AbstractDateType {
|
|
|
6
6
|
readonly hashFunction: Code;
|
|
7
7
|
readonly kind = "DateTime";
|
|
8
8
|
get fromRdfResourceValuesFunction(): Code;
|
|
9
|
-
jsonSchema(
|
|
9
|
+
jsonSchema(): Code;
|
|
10
10
|
literalValueExpression(literal: Date | Literal): Code;
|
|
11
11
|
toJsonExpression({ variables, }: Parameters<AbstractDateType["toJsonExpression"]>[0]): Code;
|
|
12
12
|
}
|