@shaclmate/compiler 4.0.37 → 4.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ShapesGraphToAstTransformer.js +12 -12
- package/dist/_ShapesGraphToAstTransformer/transformPropertyShapeToAstObjectTypeProperty.js +24 -24
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstCompoundType.js +4 -4
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstListType.js +1 -1
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstObjectType.js +16 -16
- package/dist/_ShapesGraphToAstTransformer/transformShapeToAstTermType.js +1 -1
- package/dist/ast/AbstractCollectionType.d.ts +1 -1
- package/dist/ast/AbstractCompoundType.d.ts +1 -1
- package/dist/ast/AbstractCompoundType.js +15 -15
- package/dist/ast/AbstractContainerType.d.ts +1 -1
- package/dist/ast/AbstractContainerType.js +15 -15
- package/dist/ast/AbstractLazyObjectType.d.ts +1 -1
- package/dist/ast/AbstractTermType.d.ts +1 -1
- package/dist/ast/BlankNodeType.d.ts +1 -1
- package/dist/ast/BlankNodeType.js +1 -1
- package/dist/ast/DefaultValueType.d.ts +1 -1
- package/dist/ast/DefaultValueType.js +2 -2
- package/dist/ast/IdentifierType.d.ts +1 -1
- package/dist/ast/IdentifierType.js +1 -1
- package/dist/ast/IntersectionType.d.ts +1 -1
- package/dist/ast/IntersectionType.js +3 -3
- package/dist/ast/IriType.d.ts +1 -1
- package/dist/ast/IriType.js +1 -1
- package/dist/ast/LazyObjectOptionType.d.ts +1 -1
- package/dist/ast/LazyObjectOptionType.js +1 -1
- package/dist/ast/LazyObjectSetType.d.ts +1 -1
- package/dist/ast/LazyObjectSetType.js +1 -1
- package/dist/ast/LazyObjectType.d.ts +1 -1
- package/dist/ast/LazyObjectType.js +1 -1
- package/dist/ast/ListType.d.ts +1 -1
- package/dist/ast/ListType.js +16 -16
- package/dist/ast/LiteralType.d.ts +1 -1
- package/dist/ast/LiteralType.js +1 -1
- package/dist/ast/ObjectCompoundType.js +3 -3
- package/dist/ast/ObjectType.d.ts +1 -1
- package/dist/ast/ObjectType.js +16 -16
- package/dist/ast/OptionType.d.ts +1 -1
- package/dist/ast/OptionType.js +1 -1
- package/dist/ast/SetType.d.ts +1 -1
- package/dist/ast/SetType.js +1 -1
- package/dist/ast/TermType.d.ts +1 -1
- package/dist/ast/TermType.js +1 -1
- package/dist/ast/Type.js +15 -15
- package/dist/ast/UnionType.d.ts +1 -1
- package/dist/ast/UnionType.js +3 -3
- package/dist/generators/transformAstToLabeledPropertyGraph.js +10 -10
- package/dist/generators/ts/AbstractCollectionType.d.ts +1 -5
- package/dist/generators/ts/AbstractCollectionType.js +6 -5
- package/dist/generators/ts/AbstractContainerType.d.ts +3 -6
- package/dist/generators/ts/AbstractContainerType.js +34 -34
- package/dist/generators/ts/AbstractDateType.d.ts +1 -1
- package/dist/generators/ts/AbstractIdentifierType.d.ts +1 -1
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +7 -10
- package/dist/generators/ts/AbstractLazyObjectType.js +20 -32
- package/dist/generators/ts/AbstractLiteralType.d.ts +1 -5
- package/dist/generators/ts/AbstractLiteralType.js +7 -6
- package/dist/generators/ts/AbstractNumericType.d.ts +1 -1
- package/dist/generators/ts/AbstractPrimitiveType.d.ts +2 -6
- package/dist/generators/ts/AbstractPrimitiveType.js +7 -8
- package/dist/generators/ts/AbstractTermType.d.ts +1 -5
- package/dist/generators/ts/AbstractTermType.js +1 -15
- package/dist/generators/ts/AbstractType.d.ts +7 -5
- package/dist/generators/ts/AbstractType.js +12 -7
- package/dist/generators/ts/AbstractUnionType.d.ts +7 -10
- package/dist/generators/ts/AbstractUnionType.js +70 -81
- package/dist/generators/ts/AnonymousUnionType.d.ts +1 -1
- package/dist/generators/ts/AnonymousUnionType.js +1 -1
- package/dist/generators/ts/BigDecimalType.d.ts +1 -1
- package/dist/generators/ts/BigDecimalType.js +1 -1
- package/dist/generators/ts/BigIntType.d.ts +1 -1
- package/dist/generators/ts/BigIntType.js +1 -1
- package/dist/generators/ts/BlankNodeType.d.ts +1 -1
- package/dist/generators/ts/BlankNodeType.js +1 -1
- package/dist/generators/ts/BooleanType.d.ts +1 -1
- package/dist/generators/ts/BooleanType.js +2 -2
- package/dist/generators/ts/DateTimeType.d.ts +1 -1
- package/dist/generators/ts/DateTimeType.js +1 -1
- package/dist/generators/ts/DateType.d.ts +1 -1
- package/dist/generators/ts/DateType.js +1 -1
- package/dist/generators/ts/DefaultValueType.d.ts +2 -6
- package/dist/generators/ts/DefaultValueType.js +12 -15
- package/dist/generators/ts/FloatType.d.ts +1 -1
- package/dist/generators/ts/FloatType.js +1 -1
- package/dist/generators/ts/IdentifierType.d.ts +1 -1
- package/dist/generators/ts/IdentifierType.js +1 -1
- package/dist/generators/ts/IntType.d.ts +1 -1
- package/dist/generators/ts/IntType.js +1 -1
- package/dist/generators/ts/IriType.d.ts +3 -1
- package/dist/generators/ts/IriType.js +22 -17
- package/dist/generators/ts/LazyObjectOptionType.d.ts +1 -1
- package/dist/generators/ts/LazyObjectOptionType.js +1 -1
- package/dist/generators/ts/LazyObjectSetType.d.ts +1 -1
- package/dist/generators/ts/LazyObjectSetType.js +1 -1
- package/dist/generators/ts/LazyObjectType.d.ts +1 -1
- package/dist/generators/ts/LazyObjectType.js +1 -1
- package/dist/generators/ts/ListType.d.ts +1 -1
- package/dist/generators/ts/ListType.js +24 -24
- package/dist/generators/ts/LiteralType.d.ts +2 -1
- package/dist/generators/ts/LiteralType.js +9 -2
- package/dist/generators/ts/NamedObjectType.d.ts +1 -0
- package/dist/generators/ts/NamedObjectType.js +2 -1
- package/dist/generators/ts/NamedObjectUnionType.d.ts +1 -1
- package/dist/generators/ts/NamedObjectUnionType.js +6 -8
- package/dist/generators/ts/NamedUnionType.d.ts +1 -1
- package/dist/generators/ts/NamedUnionType.js +1 -1
- package/dist/generators/ts/OptionType.d.ts +1 -5
- package/dist/generators/ts/OptionType.js +2 -8
- package/dist/generators/ts/RdfjsDatasetObjectSetType.js +1 -1
- package/dist/generators/ts/SetType.d.ts +1 -1
- package/dist/generators/ts/SetType.js +1 -1
- package/dist/generators/ts/Snippets.d.ts +1 -0
- package/dist/generators/ts/Snippets.js +7 -0
- package/dist/generators/ts/StringType.d.ts +1 -1
- package/dist/generators/ts/StringType.js +2 -2
- package/dist/generators/ts/TermType.d.ts +1 -1
- package/dist/generators/ts/TermType.js +1 -1
- package/dist/generators/ts/TypeFactory.js +18 -18
- package/dist/generators/ts/ZodGenerator.js +1 -1
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.d.ts +7 -7
- package/dist/generators/ts/_NamedObjectType/AbstractProperty.js +8 -11
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.d.ts +2 -1
- package/dist/generators/ts/_NamedObjectType/DiscriminantProperty.js +16 -7
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.d.ts +2 -1
- package/dist/generators/ts/_NamedObjectType/IdentifierProperty.js +6 -3
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_equalsFunctionDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js +3 -27
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_hashFunctionDeclarations.js +2 -2
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_interfaceDeclaration.js +1 -1
- package/dist/generators/ts/_NamedObjectType/NamedObjectType_schemaVariableStatement.js +1 -1
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.d.ts +2 -6
- package/dist/generators/ts/_NamedObjectType/ShaclProperty.js +19 -23
- package/dist/generators/ts/_snippets/snippets_BooleanSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_CollectionSchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_DefaultValueSchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_IriSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_MaybeSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_ShaclPropertySchema.js +1 -1
- package/dist/generators/ts/_snippets/snippets_StringSchema.js +2 -2
- package/dist/generators/ts/_snippets/snippets_booleanSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_convertToIri.js +1 -1
- package/dist/generators/ts/_snippets/snippets_defaultValueSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_ensureRdfResourceType.d.ts +3 -0
- package/dist/generators/ts/_snippets/snippets_ensureRdfResourceType.js +16 -0
- package/dist/generators/ts/_snippets/snippets_iriSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_listSparqlConstructTriples.js +2 -2
- package/dist/generators/ts/_snippets/snippets_listSparqlWherePatterns.js +2 -2
- package/dist/generators/ts/_snippets/snippets_maybeSparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_maybeSparqlWherePatterns.js +3 -3
- package/dist/generators/ts/_snippets/snippets_monkeyPatchObject.js +2 -2
- package/dist/generators/ts/_snippets/snippets_setSparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_setSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlConstructTriples.js +1 -1
- package/dist/generators/ts/_snippets/snippets_shaclPropertySparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_stringSparqlWherePatterns.js +1 -1
- package/dist/generators/ts/_snippets/snippets_validateArray.js +1 -1
- package/dist/generators/ts/_snippets/snippets_validateMaybe.js +1 -1
- package/dist/generators/ts/tsComment.js +1 -1
- package/dist/input/generated.d.ts +1397 -1466
- package/dist/input/generated.js +520 -655
- package/package.json +6 -6
- package/dist/generators/ts/removeUndefined.d.ts +0 -2
- package/dist/generators/ts/removeUndefined.js +0 -17
|
@@ -149,35 +149,35 @@ export class TypeFactory {
|
|
|
149
149
|
}
|
|
150
150
|
createType(astType, parameters) {
|
|
151
151
|
switch (astType.kind) {
|
|
152
|
-
case "
|
|
152
|
+
case "BlankNode":
|
|
153
153
|
return this.createBlankNodeType(astType);
|
|
154
|
-
case "
|
|
154
|
+
case "DefaultValue":
|
|
155
155
|
return this.createDefaultValueType(astType);
|
|
156
|
-
case "
|
|
156
|
+
case "Identifier":
|
|
157
157
|
return this.createIdentifierType(astType);
|
|
158
|
-
case "
|
|
158
|
+
case "Intersection":
|
|
159
159
|
throw new Error("not implemented");
|
|
160
|
-
case "
|
|
160
|
+
case "Iri":
|
|
161
161
|
return this.createIriType(astType);
|
|
162
|
-
case "
|
|
162
|
+
case "LazyObjectOption":
|
|
163
163
|
return this.createLazyObjectOptionType(astType);
|
|
164
|
-
case "
|
|
164
|
+
case "LazyObjectSet":
|
|
165
165
|
return this.createLazyObjectSetType(astType);
|
|
166
|
-
case "
|
|
166
|
+
case "LazyObject":
|
|
167
167
|
return this.createLazyObjectType(astType);
|
|
168
|
-
case "
|
|
168
|
+
case "List":
|
|
169
169
|
return this.createListType(astType);
|
|
170
|
-
case "
|
|
170
|
+
case "Literal":
|
|
171
171
|
return this.createLiteralType(astType, parameters);
|
|
172
|
-
case "
|
|
172
|
+
case "Object":
|
|
173
173
|
return this.createNamedObjectType(astType);
|
|
174
|
-
case "
|
|
174
|
+
case "Option":
|
|
175
175
|
return this.createOptionType(astType);
|
|
176
|
-
case "
|
|
176
|
+
case "Set":
|
|
177
177
|
return this.createSetType(astType);
|
|
178
|
-
case "
|
|
178
|
+
case "Term":
|
|
179
179
|
return this.createTermType(astType);
|
|
180
|
-
case "
|
|
180
|
+
case "Union":
|
|
181
181
|
return this.createUnionType(astType);
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -240,9 +240,9 @@ export class TypeFactory {
|
|
|
240
240
|
}
|
|
241
241
|
createIdentifierType(astType) {
|
|
242
242
|
switch (astType.kind) {
|
|
243
|
-
case "
|
|
243
|
+
case "BlankNode":
|
|
244
244
|
return this.createBlankNodeType(astType);
|
|
245
|
-
case "
|
|
245
|
+
case "Identifier":
|
|
246
246
|
return new IdentifierType({
|
|
247
247
|
comment: astType.comment,
|
|
248
248
|
configuration: this.configuration,
|
|
@@ -250,7 +250,7 @@ export class TypeFactory {
|
|
|
250
250
|
logger: this.logger,
|
|
251
251
|
reusables: this.reusables,
|
|
252
252
|
});
|
|
253
|
-
case "
|
|
253
|
+
case "Iri":
|
|
254
254
|
return this.createIriType(astType);
|
|
255
255
|
}
|
|
256
256
|
}
|
|
@@ -31,7 +31,7 @@ export namespace ${namedObjectType.name} {
|
|
|
31
31
|
}`);
|
|
32
32
|
}
|
|
33
33
|
for (const astNamedUnionType of ast_.namedUnionTypes.map((astNamedUnionType) => typeFactory.createUnionType(astNamedUnionType))) {
|
|
34
|
-
invariant(astNamedUnionType.kind !== "
|
|
34
|
+
invariant(astNamedUnionType.kind !== "AnonymousUnion");
|
|
35
35
|
declarations.push(code `\
|
|
36
36
|
export namespace ${astNamedUnionType.name} {
|
|
37
37
|
${astNamedUnionType.jsonTypeAliasDeclaration}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Maybe } from "purify-ts";
|
|
2
2
|
import type { Logger } from "ts-log";
|
|
3
3
|
import type { NamedObjectType } from "../NamedObjectType.js";
|
|
4
4
|
import type { Reusables } from "../Reusables.js";
|
|
@@ -50,7 +50,7 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
50
50
|
*/
|
|
51
51
|
abstract readonly jsonSignature: Maybe<Code>;
|
|
52
52
|
/**
|
|
53
|
-
* Property type discriminant e.g., "
|
|
53
|
+
* Property type discriminant e.g., "Shacl".
|
|
54
54
|
*/
|
|
55
55
|
abstract readonly kind: string;
|
|
56
56
|
/**
|
|
@@ -80,11 +80,11 @@ export declare abstract class AbstractProperty<TypeT extends Pick<Type, "filterF
|
|
|
80
80
|
/**
|
|
81
81
|
* TypeScript object describing this type, for runtime use.
|
|
82
82
|
*/
|
|
83
|
-
get schema(): Code
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
get schema(): Maybe<Code>;
|
|
84
|
+
/**
|
|
85
|
+
* Helper to compose the result of schema along the type hierarchy.
|
|
86
|
+
*/
|
|
87
|
+
protected get schemaInitializers(): readonly Code[];
|
|
88
88
|
/**
|
|
89
89
|
* Expression to access the value of this property on an object instance. May evaluate a thunk.
|
|
90
90
|
*/
|
|
@@ -4,11 +4,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
7
|
+
import { Maybe } from "purify-ts";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
9
|
import { rdfjsTermExpression } from "../rdfjsTermExpression.js";
|
|
10
|
-
import {
|
|
11
|
-
import { code, literalOf } from "../ts-poet-wrapper.js";
|
|
10
|
+
import { code, joinCode, literalOf } from "../ts-poet-wrapper.js";
|
|
12
11
|
export class AbstractProperty {
|
|
13
12
|
configuration;
|
|
14
13
|
logger;
|
|
@@ -39,15 +38,13 @@ export class AbstractProperty {
|
|
|
39
38
|
* TypeScript object describing this type, for runtime use.
|
|
40
39
|
*/
|
|
41
40
|
get schema() {
|
|
42
|
-
return code
|
|
41
|
+
return Maybe.of(code `{ ${joinCode(this.schemaInitializers.concat(), { on: ", " })} }`);
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
type: code `() => (${this.type.schema})`,
|
|
50
|
-
};
|
|
43
|
+
/**
|
|
44
|
+
* Helper to compose the result of schema along the type hierarchy.
|
|
45
|
+
*/
|
|
46
|
+
get schemaInitializers() {
|
|
47
|
+
return [code `kind: ${literalOf(this.kind)}`];
|
|
51
48
|
}
|
|
52
49
|
/**
|
|
53
50
|
* Expression to access the value of this property on an object instance. May evaluate a thunk.
|
|
@@ -5,7 +5,7 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
|
|
|
5
5
|
readonly constructorParameter: Maybe<Code>;
|
|
6
6
|
readonly filterProperty: AbstractProperty<DiscriminantProperty.Type>["filterProperty"];
|
|
7
7
|
readonly graphqlField: AbstractProperty<DiscriminantProperty.Type>["graphqlField"];
|
|
8
|
-
readonly kind = "
|
|
8
|
+
readonly kind = "Discriminant";
|
|
9
9
|
readonly mutable = false;
|
|
10
10
|
readonly recursive = false;
|
|
11
11
|
constructor({ type, ...superParameters }: {
|
|
@@ -15,6 +15,7 @@ export declare class DiscriminantProperty extends AbstractProperty<DiscriminantP
|
|
|
15
15
|
get jsonName(): string;
|
|
16
16
|
get jsonSchema(): AbstractProperty<DiscriminantProperty.Type>["jsonSchema"];
|
|
17
17
|
get jsonSignature(): Maybe<Code>;
|
|
18
|
+
get schema(): Maybe<Code>;
|
|
18
19
|
private get constValue();
|
|
19
20
|
constructorInitializer(): Maybe<Code>;
|
|
20
21
|
fromJsonInitializer(): Maybe<Code>;
|
|
@@ -6,14 +6,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { Maybe } from "purify-ts";
|
|
8
8
|
import { Memoize } from "typescript-memoize";
|
|
9
|
-
import { removeUndefined } from "../removeUndefined.js";
|
|
10
9
|
import { arrayOf, code, literalOf } from "../ts-poet-wrapper.js";
|
|
11
10
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
12
11
|
export class DiscriminantProperty extends AbstractProperty {
|
|
13
12
|
constructorParameter = Maybe.empty();
|
|
14
13
|
filterProperty = Maybe.empty();
|
|
15
14
|
graphqlField = Maybe.empty();
|
|
16
|
-
kind = "
|
|
15
|
+
kind = "Discriminant";
|
|
17
16
|
mutable = false;
|
|
18
17
|
recursive = false;
|
|
19
18
|
constructor({ type, ...superParameters }) {
|
|
@@ -36,6 +35,12 @@ export class DiscriminantProperty extends AbstractProperty {
|
|
|
36
35
|
get jsonSignature() {
|
|
37
36
|
return Maybe.of(code `readonly "${this.jsonName}": ${this.type.name}`);
|
|
38
37
|
}
|
|
38
|
+
get schema() {
|
|
39
|
+
return Maybe.empty();
|
|
40
|
+
}
|
|
41
|
+
// protected override get schemaInitializers(): readonly Code[] {
|
|
42
|
+
// return super.schemaInitializers.concat(code`type: ${this.type.schema}`);
|
|
43
|
+
// }
|
|
39
44
|
get constValue() {
|
|
40
45
|
return code `${literalOf(this.namedObjectType.discriminantValue)} as const`;
|
|
41
46
|
}
|
|
@@ -101,11 +106,15 @@ __decorate([
|
|
|
101
106
|
return `${this.values.map((name) => `"${name}"`).join(" | ")}`;
|
|
102
107
|
}
|
|
103
108
|
get schema() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
+
throw new Error("should never be called");
|
|
110
|
+
// const initializers: Record<string, unknown> = {};
|
|
111
|
+
// if (this.descendantValues.length > 0) {
|
|
112
|
+
// initializers["descendantValues"] = this.descendantValues;
|
|
113
|
+
// }
|
|
114
|
+
// if (this.ownValues.length > 0) {
|
|
115
|
+
// initializers["ownValues"] = this.ownValues;
|
|
116
|
+
// }
|
|
117
|
+
// return code`${initializers}`;
|
|
109
118
|
}
|
|
110
119
|
get values() {
|
|
111
120
|
return this.ownValues.concat(this.descendantValues);
|
|
@@ -6,7 +6,7 @@ import { type Code } from "../ts-poet-wrapper.js";
|
|
|
6
6
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
7
7
|
export declare class IdentifierProperty extends AbstractProperty<BlankNodeType | IdentifierType | IriType> {
|
|
8
8
|
private readonly typeAlias;
|
|
9
|
-
readonly kind = "
|
|
9
|
+
readonly kind = "Identifier";
|
|
10
10
|
readonly mutable = false;
|
|
11
11
|
readonly recursive = false;
|
|
12
12
|
constructor({ typeAlias, ...superParameters }: {
|
|
@@ -22,6 +22,7 @@ export declare class IdentifierProperty extends AbstractProperty<BlankNodeType |
|
|
|
22
22
|
get graphqlField(): AbstractProperty<IdentifierType>["graphqlField"];
|
|
23
23
|
get jsonSchema(): AbstractProperty<IdentifierType>["jsonSchema"];
|
|
24
24
|
get jsonSignature(): Maybe<Code>;
|
|
25
|
+
protected get schemaInitializers(): readonly Code[];
|
|
25
26
|
accessExpression({ variables, }: Parameters<AbstractProperty<BlankNodeType | IdentifierType | IriType>["accessExpression"]>[0]): Code;
|
|
26
27
|
constructorInitializer({ variables, }: Parameters<AbstractProperty<IdentifierType>["constructorInitializer"]>[0]): Maybe<Code>;
|
|
27
28
|
fromJsonInitializer({ variables, }: Parameters<AbstractProperty<IdentifierType>["fromJsonInitializer"]>[0]): Maybe<Code>;
|
|
@@ -13,7 +13,7 @@ import { arrayOf, code, joinCode, literalOf, } from "../ts-poet-wrapper.js";
|
|
|
13
13
|
import { AbstractProperty } from "./AbstractProperty.js";
|
|
14
14
|
export class IdentifierProperty extends AbstractProperty {
|
|
15
15
|
typeAlias;
|
|
16
|
-
kind = "
|
|
16
|
+
kind = "Identifier";
|
|
17
17
|
mutable = false;
|
|
18
18
|
recursive = false;
|
|
19
19
|
constructor({ typeAlias, ...superParameters }) {
|
|
@@ -56,7 +56,7 @@ export class IdentifierProperty extends AbstractProperty {
|
|
|
56
56
|
}
|
|
57
57
|
get jsonSchema() {
|
|
58
58
|
let schema;
|
|
59
|
-
if (this.type.in_.length > 0 && this.type.kind === "
|
|
59
|
+
if (this.type.in_.length > 0 && this.type.kind === "Iri") {
|
|
60
60
|
// Treat sh:in as a union of the IRIs
|
|
61
61
|
// rdfjs.NamedNode<"http://example.com/1" | "http://example.com/2">
|
|
62
62
|
schema = code `${this.reusables.imports.z}.enum(${arrayOf(...this.type.in_.map((iri) => iri.value))})`;
|
|
@@ -75,6 +75,9 @@ export class IdentifierProperty extends AbstractProperty {
|
|
|
75
75
|
}
|
|
76
76
|
return Maybe.of(code `readonly "@id": string`);
|
|
77
77
|
}
|
|
78
|
+
get schemaInitializers() {
|
|
79
|
+
return super.schemaInitializers.concat(code `type: ${this.type.schema}`);
|
|
80
|
+
}
|
|
78
81
|
accessExpression({ variables, }) {
|
|
79
82
|
return code `${variables.object}.${this.name}()`;
|
|
80
83
|
}
|
|
@@ -128,7 +131,7 @@ export class IdentifierProperty extends AbstractProperty {
|
|
|
128
131
|
ignoreRdfType: true, // Unused
|
|
129
132
|
preferredLanguages: variables.preferredLanguages,
|
|
130
133
|
propertyPatterns: code `[]`,
|
|
131
|
-
schema: code `${this.namedObjectType.name}.schema.properties.${this.name}.type
|
|
134
|
+
schema: code `${this.namedObjectType.name}.schema.properties.${this.name}.type`,
|
|
132
135
|
valueVariable: variables.focusIdentifier,
|
|
133
136
|
variablePrefix: variables.variablePrefix, // Unused
|
|
134
137
|
}})`,
|
|
@@ -10,7 +10,7 @@ export function NamedObjectType_equalsFunctionDeclaration() {
|
|
|
10
10
|
chain.push(code `${parentObjectType.name}.equals(left, right)`);
|
|
11
11
|
}
|
|
12
12
|
for (const property of this.properties) {
|
|
13
|
-
if (property.kind === "
|
|
13
|
+
if (property.kind === "Discriminant") {
|
|
14
14
|
continue;
|
|
15
15
|
}
|
|
16
16
|
chain.push(code `(${property.type.equalsFunction})(${property.accessExpression({ variables: { object: code `left` } })}, ${property.accessExpression({ variables: { object: code `right` } })}).mapLeft(propertyValuesUnequal => ({ left, right, propertyName: "${property.name}", propertyValuesUnequal, type: "property" as const }))`);
|
package/dist/generators/ts/_NamedObjectType/NamedObjectType_fromRdfResourceFunctionDeclaration.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
1
|
import { Maybe } from "purify-ts";
|
|
3
|
-
import { code, joinCode } from "../ts-poet-wrapper.js";
|
|
2
|
+
import { arrayOf, code, joinCode } from "../ts-poet-wrapper.js";
|
|
4
3
|
export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
|
|
5
4
|
if (!this.configuration.features.has("Object.fromRdf")) {
|
|
6
5
|
return Maybe.empty();
|
|
@@ -31,32 +30,9 @@ export function NamedObjectType_fromRdfResourceFunctionDeclaration() {
|
|
|
31
30
|
});
|
|
32
31
|
partials.push(`super${parentObjectTypeI}`);
|
|
33
32
|
});
|
|
34
|
-
this.
|
|
35
|
-
const fromRdfTypeVariable = this.fromRdfTypeVariable.unsafeCoerce();
|
|
36
|
-
const predicate = this.rdfjsTermExpression(rdf.type);
|
|
37
|
-
// Check the expected type and its known subtypes
|
|
38
|
-
const cases = new Set();
|
|
39
|
-
cases.add(fromRdfType.value);
|
|
40
|
-
for (const descendantFromRdfType of this.descendantFromRdfTypes) {
|
|
41
|
-
cases.add(descendantFromRdfType.value);
|
|
42
|
-
}
|
|
33
|
+
this.fromRdfTypeVariable.ifJust((fromRdfTypeVariable) => {
|
|
43
34
|
chains.push({
|
|
44
|
-
expression: code `!${variables.ignoreRdfType} ? ${variables.resource}
|
|
45
|
-
.chain(actualRdfType => actualRdfType.toIri())
|
|
46
|
-
.chain((actualRdfType) => {
|
|
47
|
-
// Check the expected type and its known subtypes
|
|
48
|
-
switch (actualRdfType.value) {
|
|
49
|
-
${[...cases].map((fromRdfType) => `case "${fromRdfType}":`).join("\n")}
|
|
50
|
-
return ${this.reusables.imports.Right}(true as const);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Check arbitrary rdfs:subClassOf's of the expected type
|
|
54
|
-
if (${variables.resource}.isInstanceOf(${fromRdfTypeVariable}, ${{ graph: variables.graph }})) {
|
|
55
|
-
return ${this.reusables.imports.Right}(true as const);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return ${this.reusables.imports.Left}(new Error(\`\${${variables.resource}.identifier} has unexpected RDF type (actual: \${actualRdfType.value}, expected: ${fromRdfType.value})\`));
|
|
59
|
-
}) : ${this.reusables.imports.Right}(true as const)`,
|
|
35
|
+
expression: code `!${variables.ignoreRdfType} ? ${this.reusables.snippets.ensureRdfResourceType}(${variables.resource}, ${arrayOf(fromRdfTypeVariable, ...this.descendantFromRdfTypeVariables)}, ${{ graph: variables.graph }}) : ${this.reusables.imports.Right}(true as const)`,
|
|
60
36
|
variable: `_rdfTypeCheck`,
|
|
61
37
|
});
|
|
62
38
|
});
|
|
@@ -4,7 +4,7 @@ export function NamedObjectType_hashFunctionDeclarations() {
|
|
|
4
4
|
if (!this.configuration.features.has("Object.hash")) {
|
|
5
5
|
return [];
|
|
6
6
|
}
|
|
7
|
-
const hashOwnShaclPropertiesStatements = this.properties.flatMap((property) => property.kind === "
|
|
7
|
+
const hashOwnShaclPropertiesStatements = this.properties.flatMap((property) => property.kind === "Shacl"
|
|
8
8
|
? property.hashStatements({
|
|
9
9
|
variables: {
|
|
10
10
|
hasher: hasherVariable,
|
|
@@ -23,7 +23,7 @@ export function NamedObjectType_hashFunctionDeclarations() {
|
|
|
23
23
|
hashShaclPropertiesStatements.push(...hashOwnShaclPropertiesStatements);
|
|
24
24
|
hashShaclPropertiesStatements.push(code `return ${hasherVariable};`);
|
|
25
25
|
hashStatements.push(...this.properties
|
|
26
|
-
.filter((property) => property.kind !== "
|
|
26
|
+
.filter((property) => property.kind !== "Shacl")
|
|
27
27
|
.flatMap((property) => property.hashStatements({
|
|
28
28
|
variables: {
|
|
29
29
|
hasher: hasherVariable,
|
|
@@ -10,7 +10,7 @@ ${this.comment
|
|
|
10
10
|
.map((parentObjectType) => parentObjectType.name)
|
|
11
11
|
.join(", ")}`
|
|
12
12
|
: ""} {
|
|
13
|
-
${joinCode(this.properties.map((property) => property.declaration))}
|
|
13
|
+
${joinCode(this.properties.map((property) => property.declaration), { on: "\n\n" })}
|
|
14
14
|
}`;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=NamedObjectType_interfaceDeclaration.js.map
|
|
@@ -7,6 +7,6 @@ export function NamedObjectType_schemaVariableStatement() {
|
|
|
7
7
|
return Maybe.of(code `\
|
|
8
8
|
export const schema = { properties: { ${joinCode(this.parentObjectTypes
|
|
9
9
|
.map((parentObjectType) => code `...${parentObjectType.name}.schema.properties`)
|
|
10
|
-
.concat(this.properties.
|
|
10
|
+
.concat(this.properties.flatMap(property => property.schema.toList().map(propertySchema => code `${property.name}: ${propertySchema}`))), { on: ", " })} } } as const;`);
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=NamedObjectType_schemaVariableStatement.js.map
|
|
@@ -8,7 +8,7 @@ export declare class ShaclProperty<TypeT extends Type> extends AbstractProperty<
|
|
|
8
8
|
private readonly description;
|
|
9
9
|
private readonly display;
|
|
10
10
|
private readonly label;
|
|
11
|
-
readonly kind = "
|
|
11
|
+
readonly kind = "Shacl";
|
|
12
12
|
readonly mutable: boolean;
|
|
13
13
|
readonly path: PropertyPath;
|
|
14
14
|
readonly recursive: boolean;
|
|
@@ -30,11 +30,7 @@ export declare class ShaclProperty<TypeT extends Type> extends AbstractProperty<
|
|
|
30
30
|
get graphqlField(): AbstractProperty<TypeT>["graphqlField"];
|
|
31
31
|
get jsonSchema(): AbstractProperty<TypeT>["jsonSchema"];
|
|
32
32
|
get jsonSignature(): Maybe<Code>;
|
|
33
|
-
protected get
|
|
34
|
-
path: Code | undefined;
|
|
35
|
-
kind: Code;
|
|
36
|
-
type: Code;
|
|
37
|
-
};
|
|
33
|
+
protected get schemaInitializers(): readonly Code[];
|
|
38
34
|
constructorInitializer({ variables, }: Parameters<AbstractProperty<TypeT>["constructorInitializer"]>[0]): Maybe<Code>;
|
|
39
35
|
fromJsonInitializer({ variables, }: Parameters<AbstractProperty<TypeT>["fromJsonInitializer"]>[0]): Maybe<Code>;
|
|
40
36
|
fromRdfResourceValuesInitializer({ variables, }: Parameters<AbstractProperty<TypeT>["fromRdfResourceValuesInitializer"]>[0]): Maybe<Code>;
|
|
@@ -14,7 +14,7 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
14
14
|
description;
|
|
15
15
|
display;
|
|
16
16
|
label;
|
|
17
|
-
kind = "
|
|
17
|
+
kind = "Shacl";
|
|
18
18
|
mutable;
|
|
19
19
|
path;
|
|
20
20
|
recursive;
|
|
@@ -97,24 +97,20 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
97
97
|
const typeJsonType = this.type.jsonType();
|
|
98
98
|
return Maybe.of(code `${!this.mutable ? "readonly " : ""}${this.name}${typeJsonType.optional ? "?" : ""}: ${typeJsonType.requiredName}`);
|
|
99
99
|
}
|
|
100
|
-
get
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
// this.visibility !== "public"
|
|
115
|
-
// ? `${JSON.stringify(this.visibility)} as const`
|
|
116
|
-
// : undefined,
|
|
117
|
-
};
|
|
100
|
+
get schemaInitializers() {
|
|
101
|
+
const initializers = super.schemaInitializers.concat();
|
|
102
|
+
if (this.configuration.features.has("Object.fromRdf") ||
|
|
103
|
+
this.configuration.features.has("Object.toRdf")) {
|
|
104
|
+
initializers.push(code `path: ${this.propertyPathToCode(this.path)}`);
|
|
105
|
+
}
|
|
106
|
+
// Use a getter if the type is recursive or the type is an object type, which may have forward references in the file
|
|
107
|
+
if (this.recursive || this.type.referencesObjectType) {
|
|
108
|
+
initializers.push(code `get type() { return ${this.type.schema}; }`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
initializers.push(code `type: ${this.type.schema}`);
|
|
112
|
+
}
|
|
113
|
+
return initializers;
|
|
118
114
|
}
|
|
119
115
|
constructorInitializer({ variables, }) {
|
|
120
116
|
const parameterVariable = code `${variables.parameters}.${this.name}`;
|
|
@@ -122,13 +118,13 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
122
118
|
const validationFunction = this.type.validationFunction.extract();
|
|
123
119
|
let rhs;
|
|
124
120
|
if (conversionFunction && validationFunction) {
|
|
125
|
-
rhs = code `${conversionFunction}(${parameterVariable}).chain(value => ${validationFunction}(${this.namedObjectType.name}.schema.properties.${this.name}.type
|
|
121
|
+
rhs = code `${conversionFunction}(${parameterVariable}).chain(value => ${validationFunction}(${this.namedObjectType.name}.schema.properties.${this.name}.type, value))`;
|
|
126
122
|
}
|
|
127
123
|
else if (conversionFunction) {
|
|
128
124
|
rhs = code `${conversionFunction}(${parameterVariable})`;
|
|
129
125
|
}
|
|
130
126
|
else if (validationFunction) {
|
|
131
|
-
rhs = code `${validationFunction}(${this.namedObjectType.name}.schema.properties.${this.name}.type
|
|
127
|
+
rhs = code `${validationFunction}(${this.namedObjectType.name}.schema.properties.${this.name}.type, ${parameterVariable})`;
|
|
132
128
|
}
|
|
133
129
|
else {
|
|
134
130
|
rhs = code `${this.reusables.imports.Either}.of(${parameterVariable})`;
|
|
@@ -230,12 +226,12 @@ export class ShaclProperty extends AbstractProperty {
|
|
|
230
226
|
switch (propertyPath.termType) {
|
|
231
227
|
case "AlternativePath":
|
|
232
228
|
case "SequencePath":
|
|
233
|
-
return code `{ members: [${joinCode(propertyPath.members.map((member) => this.propertyPathToCode(member)), { on: "," })}]
|
|
229
|
+
return code `{ members: [${joinCode(propertyPath.members.map((member) => this.propertyPathToCode(member)), { on: "," })}], termType: ${literalOf(propertyPath.termType)} }`;
|
|
234
230
|
case "InversePath":
|
|
235
231
|
case "OneOrMorePath":
|
|
236
232
|
case "ZeroOrMorePath":
|
|
237
233
|
case "ZeroOrOnePath":
|
|
238
|
-
return code `{ path: ${this.propertyPathToCode(propertyPath.path)}, termType: ${literalOf(propertyPath.termType)}
|
|
234
|
+
return code `{ path: ${this.propertyPathToCode(propertyPath.path)}, termType: ${literalOf(propertyPath.termType)} }`;
|
|
239
235
|
case "NamedNode":
|
|
240
236
|
return this.rdfjsTermExpression(propertyPath);
|
|
241
237
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_BooleanSchema = ({ syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}BooleanSchema`, code `\
|
|
3
|
-
interface ${syntheticNamePrefix}BooleanSchema {
|
|
3
|
+
interface ${syntheticNamePrefix}BooleanSchema<T extends boolean> {
|
|
4
|
+
readonly in?: readonly T[];
|
|
4
5
|
readonly kind: "Boolean";
|
|
5
|
-
readonly in?: readonly boolean[];
|
|
6
6
|
}`);
|
|
7
7
|
//# sourceMappingURL=snippets_BooleanSchema.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_CollectionSchema = ({ syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}CollectionSchema`, code `\
|
|
3
3
|
interface ${syntheticNamePrefix}CollectionSchema<ItemSchemaT> {
|
|
4
|
-
readonly
|
|
4
|
+
readonly itemType: ItemSchemaT;
|
|
5
5
|
readonly kind: "List" | "Set";
|
|
6
6
|
readonly minCount?: number;
|
|
7
7
|
}`);
|
|
@@ -2,7 +2,7 @@ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
|
2
2
|
export const snippets_DefaultValueSchema = ({ syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}DefaultValueSchema`, code `\
|
|
3
3
|
interface ${syntheticNamePrefix}DefaultValueSchema<DefaultValueT, ItemSchemaT> {
|
|
4
4
|
readonly defaultValue: DefaultValueT;
|
|
5
|
-
readonly
|
|
5
|
+
readonly itemType: ItemSchemaT;
|
|
6
6
|
readonly kind: "DefaultValue";
|
|
7
7
|
}`);
|
|
8
8
|
//# sourceMappingURL=snippets_DefaultValueSchema.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_IriSchema = ({ imports, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}IriSchema`, code `\
|
|
3
|
-
interface ${syntheticNamePrefix}IriSchema {
|
|
4
|
-
readonly in?: readonly ${imports.NamedNode}[];
|
|
3
|
+
interface ${syntheticNamePrefix}IriSchema<IriT extends string = string> {
|
|
4
|
+
readonly in?: readonly ${imports.NamedNode}<IriT>[];
|
|
5
5
|
readonly kind: "Iri";
|
|
6
6
|
}`);
|
|
7
7
|
//# sourceMappingURL=snippets_IriSchema.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_MaybeSchema = ({ syntheticNamePrefix }) => conditionalOutput(`${syntheticNamePrefix}MaybeSchema`, code `\
|
|
3
3
|
interface ${syntheticNamePrefix}MaybeSchema<ItemSchemaT>{
|
|
4
|
-
readonly
|
|
5
|
-
readonly kind: "
|
|
4
|
+
readonly itemType: ItemSchemaT;
|
|
5
|
+
readonly kind: "Option";
|
|
6
6
|
}`);
|
|
7
7
|
//# sourceMappingURL=snippets_MaybeSchema.js.map
|
|
@@ -3,6 +3,6 @@ export const snippets_ShaclPropertySchema = ({ snippets, syntheticNamePrefix, })
|
|
|
3
3
|
export interface ${syntheticNamePrefix}ShaclPropertySchema<TypeSchemaT = object> {
|
|
4
4
|
readonly kind: "Shacl";
|
|
5
5
|
readonly path: ${snippets.PropertyPath};
|
|
6
|
-
readonly type:
|
|
6
|
+
readonly type: TypeSchemaT;
|
|
7
7
|
}`);
|
|
8
8
|
//# sourceMappingURL=snippets_ShaclPropertySchema.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_StringSchema = ({ syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}StringSchema`, code `\
|
|
3
|
-
interface ${syntheticNamePrefix}StringSchema {
|
|
4
|
-
readonly in?: readonly
|
|
3
|
+
interface ${syntheticNamePrefix}StringSchema<T extends string> {
|
|
4
|
+
readonly in?: readonly T[];
|
|
5
5
|
readonly kind: "String";
|
|
6
6
|
}`);
|
|
7
7
|
//# sourceMappingURL=snippets_StringSchema.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_booleanSparqlWherePatterns = ({ snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}booleanSparqlWherePatterns`, code `\
|
|
3
|
-
const ${syntheticNamePrefix}booleanSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${snippets.BooleanFilter}, ${snippets.BooleanSchema}
|
|
3
|
+
const ${syntheticNamePrefix}booleanSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${snippets.BooleanFilter}, ${snippets.BooleanSchema}<boolean>> =
|
|
4
4
|
({ filter, valueVariable, ...otherParameters }) => {
|
|
5
5
|
const filterPatterns: ${snippets.SparqlFilterPattern}[] = [];
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_convertToIri = ({ imports, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}convertToIri`, code `\
|
|
3
|
-
function ${syntheticNamePrefix}convertToIri<IriT extends string
|
|
3
|
+
function ${syntheticNamePrefix}convertToIri<IriT extends string>(value: IriT | ${imports.NamedNode}<IriT>): ${imports.Either}<Error, ${imports.NamedNode}<IriT>> {
|
|
4
4
|
switch (typeof value) {
|
|
5
5
|
case "object":
|
|
6
6
|
return ${imports.Either}.of(value);
|
|
@@ -2,7 +2,7 @@ import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
|
2
2
|
export const snippets_defaultValueSparqlWherePatterns = ({ snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}defaultValueSparqlWherePatterns`, code `\
|
|
3
3
|
function ${syntheticNamePrefix}defaultValueSparqlWherePatterns<ItemFilterT, ItemSchemaT>(itemSparqlWherePatternsFunction: ${snippets.ValueSparqlWherePatternsFunction}<ItemFilterT, ItemSchemaT>): ${snippets.ValueSparqlWherePatternsFunction}<ItemFilterT, ${snippets.DefaultValueSchema}<unknown, ItemSchemaT>> {
|
|
4
4
|
return ({ schema, ...otherParameters }) => {
|
|
5
|
-
const [itemSparqlWherePatterns, liftSparqlPatterns] = ${snippets.liftSparqlPatterns}(itemSparqlWherePatternsFunction({ ...otherParameters, schema: schema.
|
|
5
|
+
const [itemSparqlWherePatterns, liftSparqlPatterns] = ${snippets.liftSparqlPatterns}(itemSparqlWherePatternsFunction({ ...otherParameters, schema: schema.itemType }));
|
|
6
6
|
return [{ patterns: itemSparqlWherePatterns.concat(), type: "optional" }, ...liftSparqlPatterns];
|
|
7
7
|
}
|
|
8
8
|
}`);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { rdf } from "@tpluscode/rdf-ns-builders";
|
|
2
|
+
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
3
|
+
export const snippets_ensureRdfResourceType = ({ imports, rdfjsTermExpression, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}ensureRdfResourceType`, code `\
|
|
4
|
+
function ${syntheticNamePrefix}ensureRdfResourceType(resource: ${imports.Resource}, types: readonly ${imports.NamedNode}[], options: { graph: Exclude<${imports.Quad_Graph}, ${imports.Variable}> | undefined }): ${imports.Either}<Error, undefined> {
|
|
5
|
+
return resource.value(${rdfjsTermExpression(rdf.type)}, options).chain(actualRdfTypeValue => actualRdfTypeValue.toIri()).chain(actualRdfType => {
|
|
6
|
+
// Check the expected type and its known subtypes
|
|
7
|
+
for (const type of types) {
|
|
8
|
+
if (resource.isInstanceOf(type, options)) {
|
|
9
|
+
return ${imports.Right}(undefined);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return ${imports.Left}(new Error(\`\${resource.identifier} has unexpected RDF type (actual: \${actualRdfType}, expected one of \${types})\`));
|
|
14
|
+
});
|
|
15
|
+
}`);
|
|
16
|
+
//# sourceMappingURL=snippets_ensureRdfResourceType.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
2
2
|
export const snippets_iriSparqlWherePatterns = ({ snippets, syntheticNamePrefix, }) => conditionalOutput(`${syntheticNamePrefix}iriSparqlWherePatterns`, code `\
|
|
3
|
-
const ${syntheticNamePrefix}iriSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${snippets.IriFilter}, ${snippets.IriSchema}
|
|
3
|
+
const ${syntheticNamePrefix}iriSparqlWherePatterns: ${snippets.ValueSparqlWherePatternsFunction}<${snippets.IriFilter}, ${snippets.IriSchema}<string>> =
|
|
4
4
|
({ filter, valueVariable, ...otherParameters }) => {
|
|
5
5
|
const filterPatterns: ${snippets.SparqlFilterPattern}[] = [];
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ function ${syntheticNamePrefix}listSparqlConstructTriples<ItemFilterT, ItemSchem
|
|
|
10
10
|
// ?list rdf:first ?item0
|
|
11
11
|
const item0Variable = variable("Item0");
|
|
12
12
|
triples.push({ subject: listVariable, predicate: ${snippets.RdfVocabularies}.rdf.first, object: item0Variable });
|
|
13
|
-
triples = triples.concat(itemSparqlConstructTriplesFunction({ filter, ignoreRdfType: false, schema: schema.
|
|
13
|
+
triples = triples.concat(itemSparqlConstructTriplesFunction({ filter, ignoreRdfType: false, schema: schema.itemType, valueVariable: item0Variable, variablePrefix: variablePrefix("Item0") }));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
{
|
|
@@ -25,7 +25,7 @@ function ${syntheticNamePrefix}listSparqlConstructTriples<ItemFilterT, ItemSchem
|
|
|
25
25
|
// ?rest rdf:first ?itemN
|
|
26
26
|
const itemNVariable = variable("ItemN");
|
|
27
27
|
triples.push({ subject: restNVariable, predicate: ${snippets.RdfVocabularies}.rdf.first, object: itemNVariable });
|
|
28
|
-
triples = triples.concat(itemSparqlConstructTriplesFunction({ filter, ignoreRdfType: false, schema: schema.
|
|
28
|
+
triples = triples.concat(itemSparqlConstructTriplesFunction({ filter, ignoreRdfType: false, schema: schema.itemType, valueVariable: itemNVariable, variablePrefix: variablePrefix("ItemN") }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// ?restN rdf:rest ?restNBasic to get the rdf:rest statement in the CONSTRUCT
|