@shaclmate/compiler 4.0.20 → 4.0.21
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/AbstractContainerType.d.ts +1 -0
- package/dist/generators/ts/AbstractContainerType.js +3 -0
- package/dist/generators/ts/AbstractLazyObjectType.d.ts +2 -1
- package/dist/generators/ts/AbstractLazyObjectType.js +6 -3
- package/dist/generators/ts/AbstractNamedUnionType.js +1 -1
- package/dist/generators/ts/AbstractTermType.d.ts +1 -0
- package/dist/generators/ts/AbstractTermType.js +6 -0
- package/dist/generators/ts/AbstractType.d.ts +4 -0
- package/dist/generators/ts/AbstractUnionType.d.ts +5 -4
- package/dist/generators/ts/AbstractUnionType.js +83 -59
- package/dist/generators/ts/NamedObjectType.d.ts +1 -0
- package/dist/generators/ts/NamedObjectType.js +7 -0
- package/dist/generators/ts/_snippets/snippets_ToRdfResourceValuesFunction.js +4 -3
- package/package.json +2 -2
|
@@ -38,6 +38,7 @@ export declare abstract class AbstractContainerType<ItemTypeT extends AbstractCo
|
|
|
38
38
|
} & ConstructorParameters<typeof AbstractType>[0]);
|
|
39
39
|
get recursive(): boolean;
|
|
40
40
|
get schema(): Code;
|
|
41
|
+
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
41
42
|
protected get schemaObject(): {
|
|
42
43
|
item: Code;
|
|
43
44
|
kind: Code;
|
|
@@ -31,6 +31,9 @@ export class AbstractContainerType extends AbstractType {
|
|
|
31
31
|
get schema() {
|
|
32
32
|
return code `${removeUndefined(this.schemaObject)}`;
|
|
33
33
|
}
|
|
34
|
+
get toRdfResourceValueTypes() {
|
|
35
|
+
return this.itemType.toRdfResourceValueTypes;
|
|
36
|
+
}
|
|
34
37
|
get schemaObject() {
|
|
35
38
|
return {
|
|
36
39
|
...super.schemaObject,
|
|
@@ -32,6 +32,7 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
32
32
|
get recursive(): boolean;
|
|
33
33
|
get schema(): Code;
|
|
34
34
|
get schemaType(): Code;
|
|
35
|
+
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
35
36
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
36
37
|
get valueSparqlWherePatternsFunction(): Code;
|
|
37
38
|
protected get schemaObject(): {
|
|
@@ -39,9 +40,9 @@ export declare abstract class AbstractLazyObjectType<PartialTypeT extends Abstra
|
|
|
39
40
|
kind: Code;
|
|
40
41
|
};
|
|
41
42
|
hashStatements({ depth, variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
|
|
43
|
+
jsonSchema(parameters: Parameters<AbstractType["jsonSchema"]>[0]): Code;
|
|
42
44
|
jsonType(parameters?: Parameters<AbstractType["jsonType"]>[0]): AbstractType.JsonType;
|
|
43
45
|
jsonUiSchemaElement(parameters: Parameters<AbstractType["jsonUiSchemaElement"]>[0]): Maybe<Code>;
|
|
44
|
-
jsonSchema(parameters: Parameters<AbstractType["jsonSchema"]>[0]): Code;
|
|
45
46
|
toJsonExpression({ variables, }: Parameters<AbstractType["toJsonExpression"]>[0]): Code;
|
|
46
47
|
toRdfResourceValuesExpression({ variables, }: Parameters<AbstractType["toRdfResourceValuesExpression"]>[0]): Code;
|
|
47
48
|
protected resolvedNamedObjectUnionTypeToPartialNamedObjectUnionTypeConversion({ resolvedNamedObjectUnionType, partialNamedObjectUnionType, variables, }: {
|
|
@@ -63,6 +63,9 @@ export class AbstractLazyObjectType extends AbstractType {
|
|
|
63
63
|
resolveType: this.resolveType.schemaType,
|
|
64
64
|
}}`;
|
|
65
65
|
}
|
|
66
|
+
get toRdfResourceValueTypes() {
|
|
67
|
+
return this.partialType.toRdfResourceValueTypes;
|
|
68
|
+
}
|
|
66
69
|
get valueSparqlConstructTriplesFunction() {
|
|
67
70
|
return code `(({ schema, ...otherParameters }) => ${this.partialType.valueSparqlConstructTriplesFunction}({ ...otherParameters, schema: schema.partial() }))`;
|
|
68
71
|
}
|
|
@@ -86,15 +89,15 @@ export class AbstractLazyObjectType extends AbstractType {
|
|
|
86
89
|
},
|
|
87
90
|
});
|
|
88
91
|
}
|
|
92
|
+
jsonSchema(parameters) {
|
|
93
|
+
return this.partialType.jsonSchema(parameters);
|
|
94
|
+
}
|
|
89
95
|
jsonType(parameters) {
|
|
90
96
|
return this.partialType.jsonType(parameters);
|
|
91
97
|
}
|
|
92
98
|
jsonUiSchemaElement(parameters) {
|
|
93
99
|
return this.partialType.jsonUiSchemaElement(parameters);
|
|
94
100
|
}
|
|
95
|
-
jsonSchema(parameters) {
|
|
96
|
-
return this.partialType.jsonSchema(parameters);
|
|
97
|
-
}
|
|
98
101
|
toJsonExpression({ variables, }) {
|
|
99
102
|
return this.partialType.toJsonExpression({
|
|
100
103
|
variables: {
|
|
@@ -107,7 +107,7 @@ export namespace ${syntheticNamePrefix}Json {
|
|
|
107
107
|
staticModuleDeclarations[`${syntheticNamePrefix}fromRdfResourceValues`] =
|
|
108
108
|
code `export const ${syntheticNamePrefix}fromRdfResourceValues: ${snippets.FromRdfResourceValuesFunction}<${this.name}> = ${this.inlineFromRdfResourceValuesFunction};`;
|
|
109
109
|
staticModuleDeclarations[`${syntheticNamePrefix}toRdfResourceValues`] =
|
|
110
|
-
code `export const ${syntheticNamePrefix}toRdfResourceValues
|
|
110
|
+
code `export const ${syntheticNamePrefix}toRdfResourceValues = ${this.inlineToRdfResourceValuesFunction};`;
|
|
111
111
|
}
|
|
112
112
|
if (this.features.has("sparql")) {
|
|
113
113
|
staticModuleDeclarations[`${syntheticNamePrefix}valueSparqlConstructTriples`] =
|
|
@@ -32,6 +32,7 @@ export declare abstract class AbstractTermType<ConstantTermT extends Literal | N
|
|
|
32
32
|
get discriminantProperty(): Maybe<AbstractType.DiscriminantProperty>;
|
|
33
33
|
get schema(): Code;
|
|
34
34
|
get termTypes(): ReadonlySet<"BlankNode" | "Literal" | "NamedNode">;
|
|
35
|
+
get toRdfResourceValueTypes(): Set<"BlankNode" | "Literal" | "NamedNode">;
|
|
35
36
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
36
37
|
fromRdfResourceValuesExpression(parameters: Parameters<AbstractType["fromRdfResourceValuesExpression"]>[0]): Code;
|
|
37
38
|
hashStatements({ variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
|
|
@@ -93,6 +93,9 @@ export class AbstractTermType extends AbstractType {
|
|
|
93
93
|
get termTypes() {
|
|
94
94
|
return new Set([...this.nodeKinds].map(NodeKind.toTermType));
|
|
95
95
|
}
|
|
96
|
+
get toRdfResourceValueTypes() {
|
|
97
|
+
return new Set([...this.nodeKinds].map(NodeKind.toTermType));
|
|
98
|
+
}
|
|
96
99
|
get valueSparqlConstructTriplesFunction() {
|
|
97
100
|
return code `((_: object) => [])`;
|
|
98
101
|
}
|
|
@@ -170,6 +173,9 @@ __decorate([
|
|
|
170
173
|
__decorate([
|
|
171
174
|
Memoize()
|
|
172
175
|
], AbstractTermType.prototype, "termTypes", null);
|
|
176
|
+
__decorate([
|
|
177
|
+
Memoize()
|
|
178
|
+
], AbstractTermType.prototype, "toRdfResourceValueTypes", null);
|
|
173
179
|
__decorate([
|
|
174
180
|
Memoize()
|
|
175
181
|
], AbstractTermType.prototype, "valueSparqlConstructTriplesFunction", null);
|
|
@@ -217,6 +217,10 @@ export declare abstract class AbstractType {
|
|
|
217
217
|
value: Code;
|
|
218
218
|
};
|
|
219
219
|
}): Code;
|
|
220
|
+
/**
|
|
221
|
+
* The type(s) of the array elements produced by the toRdfResourceValuesExpression.
|
|
222
|
+
*/
|
|
223
|
+
abstract readonly toRdfResourceValueTypes: ReadonlySet<"BlankNode" | "NamedNode" | "Literal">;
|
|
220
224
|
/**
|
|
221
225
|
* An expression that converts a property value of this type to a value or an array of values that can be .add'd to a Resource with
|
|
222
226
|
* resource.add(predicate, convertedValue, graph)
|
|
@@ -10,7 +10,6 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
10
10
|
private readonly discriminant;
|
|
11
11
|
private readonly identifierType;
|
|
12
12
|
readonly abstract = false;
|
|
13
|
-
private readonly lazyMembers;
|
|
14
13
|
readonly recursive: boolean;
|
|
15
14
|
constructor({ identifierType, members, recursive, ...superParameters }: {
|
|
16
15
|
identifierType: Maybe<BlankNodeType | IdentifierType | IriType>;
|
|
@@ -25,6 +24,7 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
25
24
|
get mutable(): boolean;
|
|
26
25
|
get schema(): Code;
|
|
27
26
|
get schemaType(): Code;
|
|
27
|
+
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
28
28
|
get typeofs(): AbstractType["typeofs"];
|
|
29
29
|
protected get concreteMembers(): readonly AbstractUnionType.ConcreteMember<MemberTypeT>[];
|
|
30
30
|
protected get inlineEqualsFunction(): Code;
|
|
@@ -32,19 +32,20 @@ export declare abstract class AbstractUnionType<MemberTypeT extends Type> extend
|
|
|
32
32
|
protected get inlineFilterType(): Code;
|
|
33
33
|
protected get inlineFromJsonFunction(): Code;
|
|
34
34
|
protected get inlineFromRdfResourceValuesFunction(): Code;
|
|
35
|
-
protected get inlineJsonType(): AbstractType.JsonType;
|
|
36
35
|
protected get inlineJsonSchema(): Code;
|
|
36
|
+
protected get inlineJsonType(): AbstractType.JsonType;
|
|
37
37
|
protected get inlineName(): Code;
|
|
38
|
-
protected get inlineValueSparqlConstructTriplesFunction(): Code;
|
|
39
|
-
protected get inlineValueSparqlWherePatternsFunction(): Code;
|
|
40
38
|
protected get inlineToJsonFunction(): Code;
|
|
41
39
|
protected get inlineToRdfResourceValuesFunction(): Code;
|
|
40
|
+
protected get inlineValueSparqlConstructTriplesFunction(): Code;
|
|
41
|
+
protected get inlineValueSparqlWherePatternsFunction(): Code;
|
|
42
42
|
protected get schemaObject(): {
|
|
43
43
|
kind: Code;
|
|
44
44
|
members: Code;
|
|
45
45
|
};
|
|
46
46
|
jsonUiSchemaElement(): Maybe<Code>;
|
|
47
47
|
protected inlineHashStatements({ depth, variables, }: Parameters<AbstractType["hashStatements"]>[0]): readonly Code[];
|
|
48
|
+
private readonly lazyMembers;
|
|
48
49
|
}
|
|
49
50
|
type Discriminant = ExtrinsicDiscriminant | HybridDiscriminant | IntrinsicDiscriminant | TypeofDiscriminant;
|
|
50
51
|
type ExtrinsicDiscriminant = {
|
|
@@ -13,24 +13,10 @@ import { removeUndefined } from "./removeUndefined.js";
|
|
|
13
13
|
import { snippets } from "./snippets.js";
|
|
14
14
|
import { syntheticNamePrefix } from "./syntheticNamePrefix.js";
|
|
15
15
|
import { code, joinCode, literalOf } from "./ts-poet-wrapper.js";
|
|
16
|
-
const emptyTermTypesSet = new Set();
|
|
17
|
-
function termTypes(type) {
|
|
18
|
-
switch (type.kind) {
|
|
19
|
-
case "BlankNodeType":
|
|
20
|
-
case "IriType":
|
|
21
|
-
case "IdentifierType":
|
|
22
|
-
case "LiteralType":
|
|
23
|
-
case "TermType":
|
|
24
|
-
return type.termTypes;
|
|
25
|
-
default:
|
|
26
|
-
return emptyTermTypesSet;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
16
|
export class AbstractUnionType extends AbstractType {
|
|
30
17
|
discriminant;
|
|
31
18
|
identifierType;
|
|
32
19
|
abstract = false;
|
|
33
|
-
lazyMembers;
|
|
34
20
|
recursive;
|
|
35
21
|
constructor({ identifierType, members, recursive, ...superParameters }) {
|
|
36
22
|
super(superParameters);
|
|
@@ -222,6 +208,15 @@ export class AbstractUnionType extends AbstractType {
|
|
|
222
208
|
}}`), { on: ";" })} }`,
|
|
223
209
|
}}`;
|
|
224
210
|
}
|
|
211
|
+
get toRdfResourceValueTypes() {
|
|
212
|
+
const set = new Set();
|
|
213
|
+
for (const member of this.members) {
|
|
214
|
+
for (const value of member.type.toRdfResourceValueTypes) {
|
|
215
|
+
set.add(value);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return set;
|
|
219
|
+
}
|
|
225
220
|
get typeofs() {
|
|
226
221
|
return NonEmptyList.fromArray(this.concreteMembers.flatMap((member) => member.type.typeofs)).unsafeCoerce();
|
|
227
222
|
}
|
|
@@ -318,55 +313,55 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
318
313
|
}))
|
|
319
314
|
) satisfies ${snippets.FromRdfResourceValuesFunction}<${this.name}>)`;
|
|
320
315
|
}
|
|
321
|
-
get
|
|
316
|
+
get inlineJsonSchema() {
|
|
322
317
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
323
318
|
switch (discriminant.kind) {
|
|
324
319
|
case "extrinsic":
|
|
325
|
-
return
|
|
320
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`), { on: "," })}]).readonly()`;
|
|
326
321
|
case "hybrid":
|
|
327
|
-
return
|
|
322
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ primaryDiscriminantValue, type }, memberI) => {
|
|
328
323
|
switch (discriminant.memberValues[memberI].kind) {
|
|
329
324
|
case "extrinsic":
|
|
330
|
-
return code
|
|
325
|
+
return code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
|
|
331
326
|
case "intrinsic":
|
|
332
|
-
return
|
|
327
|
+
return type.jsonSchema({
|
|
328
|
+
includeDiscriminantProperty: true,
|
|
329
|
+
context: "type",
|
|
330
|
+
});
|
|
333
331
|
default:
|
|
334
332
|
throw new Error();
|
|
335
333
|
}
|
|
336
|
-
}), { on: "
|
|
334
|
+
}), { on: "," })}]).readonly()`;
|
|
337
335
|
case "intrinsic":
|
|
336
|
+
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
337
|
+
includeDiscriminantProperty: true,
|
|
338
|
+
context: "type",
|
|
339
|
+
})), { on: "," })}]).readonly()`;
|
|
338
340
|
case "typeof":
|
|
339
|
-
return
|
|
341
|
+
return code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
|
|
340
342
|
default:
|
|
341
343
|
throw discriminant;
|
|
342
344
|
}
|
|
343
345
|
}
|
|
344
|
-
get
|
|
346
|
+
get inlineJsonType() {
|
|
345
347
|
const discriminant = this.discriminant; // To get type narrowing to work
|
|
346
348
|
switch (discriminant.kind) {
|
|
347
349
|
case "extrinsic":
|
|
348
|
-
return
|
|
350
|
+
return new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
|
|
349
351
|
case "hybrid":
|
|
350
|
-
return
|
|
352
|
+
return new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
|
|
351
353
|
switch (discriminant.memberValues[memberI].kind) {
|
|
352
354
|
case "extrinsic":
|
|
353
|
-
return code
|
|
355
|
+
return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
|
|
354
356
|
case "intrinsic":
|
|
355
|
-
return
|
|
356
|
-
includeDiscriminantProperty: true,
|
|
357
|
-
context: "type",
|
|
358
|
-
});
|
|
357
|
+
return code `${jsonType}`;
|
|
359
358
|
default:
|
|
360
359
|
throw new Error();
|
|
361
360
|
}
|
|
362
|
-
}), { on: "
|
|
361
|
+
}), { on: "|" })})`);
|
|
363
362
|
case "intrinsic":
|
|
364
|
-
return code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({
|
|
365
|
-
includeDiscriminantProperty: true,
|
|
366
|
-
context: "type",
|
|
367
|
-
})), { on: "," })}]).readonly()`;
|
|
368
363
|
case "typeof":
|
|
369
|
-
return
|
|
364
|
+
return new AbstractType.JsonType(joinCode(this.concreteMembers.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
|
|
370
365
|
default:
|
|
371
366
|
throw discriminant;
|
|
372
367
|
}
|
|
@@ -400,28 +395,6 @@ ${joinCode(this.concreteMembers.map(({ jsonType, jsonTypeCheck, type, unwrap, wr
|
|
|
400
395
|
throw new Error("should never reach this point");
|
|
401
396
|
}
|
|
402
397
|
}
|
|
403
|
-
get inlineValueSparqlConstructTriplesFunction() {
|
|
404
|
-
return code `\
|
|
405
|
-
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
406
|
-
let triples: ${imports.sparqljs}.Triple[] = [];
|
|
407
|
-
|
|
408
|
-
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
409
|
-
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
410
|
-
|
|
411
|
-
return triples;
|
|
412
|
-
}) satisfies ${snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
413
|
-
}
|
|
414
|
-
get inlineValueSparqlWherePatternsFunction() {
|
|
415
|
-
return code `\
|
|
416
|
-
((({ filter, schema, ...otherParameters }) => {
|
|
417
|
-
const unionPatterns: ${imports.sparqljs}.GroupPattern[] = [];
|
|
418
|
-
|
|
419
|
-
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
420
|
-
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
421
|
-
|
|
422
|
-
return [{ patterns: unionPatterns, type: "union" }];
|
|
423
|
-
}) satisfies ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
424
|
-
}
|
|
425
398
|
get inlineToJsonFunction() {
|
|
426
399
|
return code `\
|
|
427
400
|
((value: ${this.name}): ${this.jsonType().name} => {
|
|
@@ -432,7 +405,19 @@ ${joinCode(this.concreteMembers.map(({ typeCheck, typeToJsonExpression, unwrap,
|
|
|
432
405
|
}
|
|
433
406
|
get inlineToRdfResourceValuesFunction() {
|
|
434
407
|
return code `\
|
|
435
|
-
(((value, _options) => {
|
|
408
|
+
(((value, _options): (${joinCode([...this.toRdfResourceValueTypes].map((toRdfResourceValueType) => {
|
|
409
|
+
switch (toRdfResourceValueType) {
|
|
410
|
+
case "BlankNode":
|
|
411
|
+
return code `${imports.BlankNode}`;
|
|
412
|
+
case "Literal":
|
|
413
|
+
return code `${imports.Literal}`;
|
|
414
|
+
case "NamedNode":
|
|
415
|
+
return code `${imports.NamedNode}`;
|
|
416
|
+
default:
|
|
417
|
+
toRdfResourceValueType;
|
|
418
|
+
throw new Error();
|
|
419
|
+
}
|
|
420
|
+
}), { on: " | " })})[] => {
|
|
436
421
|
${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if (${typeCheck(code `value`)}) { return ${type.toRdfResourceValuesExpression({
|
|
437
422
|
variables: {
|
|
438
423
|
graph: code `_options.graph`,
|
|
@@ -444,7 +429,29 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
|
|
|
444
429
|
})}; }`))}
|
|
445
430
|
|
|
446
431
|
throw new Error("unable to serialize to RDF");
|
|
447
|
-
})
|
|
432
|
+
}) satisfies ${snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
|
|
433
|
+
}
|
|
434
|
+
get inlineValueSparqlConstructTriplesFunction() {
|
|
435
|
+
return code `\
|
|
436
|
+
((({ ignoreRdfType, filter, schema, ...otherParameters }) => {
|
|
437
|
+
let triples: ${imports.sparqljs}.Triple[] = [];
|
|
438
|
+
|
|
439
|
+
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
440
|
+
triples = triples.concat(${type.valueSparqlConstructTriplesFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }));`))}
|
|
441
|
+
|
|
442
|
+
return triples;
|
|
443
|
+
}) satisfies ${snippets.ValueSparqlConstructTriplesFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
444
|
+
}
|
|
445
|
+
get inlineValueSparqlWherePatternsFunction() {
|
|
446
|
+
return code `\
|
|
447
|
+
((({ filter, schema, ...otherParameters }) => {
|
|
448
|
+
const unionPatterns: ${imports.sparqljs}.GroupPattern[] = [];
|
|
449
|
+
|
|
450
|
+
${joinCode(this.concreteMembers.map(({ type, primaryDiscriminantValue }) => code `\
|
|
451
|
+
unionPatterns.push({ patterns: ${type.valueSparqlWherePatternsFunction}({ ...otherParameters, filter: filter?.on?.[${literalOf(primaryDiscriminantValue)}], ignoreRdfType: false, schema: schema.members[${literalOf(primaryDiscriminantValue)}].type }).concat(), type: "group" });`))}
|
|
452
|
+
|
|
453
|
+
return [{ patterns: unionPatterns, type: "union" }];
|
|
454
|
+
}) satisfies ${snippets.ValueSparqlWherePatternsFunction}<${this.filterType}, ${this.schemaType}>)`;
|
|
448
455
|
}
|
|
449
456
|
get schemaObject() {
|
|
450
457
|
return {
|
|
@@ -469,6 +476,7 @@ ${joinCode(this.concreteMembers.map(({ type, unwrap, typeCheck }) => code `if ($
|
|
|
469
476
|
})
|
|
470
477
|
.concat())} }`);
|
|
471
478
|
}
|
|
479
|
+
lazyMembers;
|
|
472
480
|
}
|
|
473
481
|
__decorate([
|
|
474
482
|
Memoize()
|
|
@@ -485,6 +493,9 @@ __decorate([
|
|
|
485
493
|
__decorate([
|
|
486
494
|
Memoize()
|
|
487
495
|
], AbstractUnionType.prototype, "schema", null);
|
|
496
|
+
__decorate([
|
|
497
|
+
Memoize()
|
|
498
|
+
], AbstractUnionType.prototype, "toRdfResourceValueTypes", null);
|
|
488
499
|
__decorate([
|
|
489
500
|
Memoize()
|
|
490
501
|
], AbstractUnionType.prototype, "typeofs", null);
|
|
@@ -512,6 +523,19 @@ __decorate([
|
|
|
512
523
|
__decorate([
|
|
513
524
|
Memoize()
|
|
514
525
|
], AbstractUnionType.prototype, "inlineValueSparqlWherePatternsFunction", null);
|
|
526
|
+
function termTypes(type) {
|
|
527
|
+
switch (type.kind) {
|
|
528
|
+
case "BlankNodeType":
|
|
529
|
+
case "IriType":
|
|
530
|
+
case "IdentifierType":
|
|
531
|
+
case "LiteralType":
|
|
532
|
+
case "TermType":
|
|
533
|
+
return type.termTypes;
|
|
534
|
+
default:
|
|
535
|
+
return emptyTermTypesSet;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
const emptyTermTypesSet = new Set();
|
|
515
539
|
export var Discriminant;
|
|
516
540
|
(function (Discriminant) {
|
|
517
541
|
function infer(members) {
|
|
@@ -77,6 +77,7 @@ export declare class NamedObjectType extends AbstractType {
|
|
|
77
77
|
get properties(): readonly NamedObjectType.Property[];
|
|
78
78
|
get schema(): Code;
|
|
79
79
|
get schemaType(): Code;
|
|
80
|
+
get toRdfResourceValueTypes(): AbstractType["toRdfResourceValueTypes"];
|
|
80
81
|
get toRdfjsResourceType(): Code;
|
|
81
82
|
get valueSparqlConstructTriplesFunction(): Code;
|
|
82
83
|
get valueSparqlWherePatternsFunction(): Code;
|
|
@@ -4,6 +4,7 @@ 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 { NodeKind } from "@shaclmate/shacl-ast";
|
|
7
8
|
import { camelCase } from "change-case";
|
|
8
9
|
import { Maybe, NonEmptyList } from "purify-ts";
|
|
9
10
|
import { Memoize } from "typescript-memoize";
|
|
@@ -228,6 +229,9 @@ ${joinCode(staticModuleDeclarations, { on: "\n\n" })}
|
|
|
228
229
|
get schemaType() {
|
|
229
230
|
return code `typeof ${this.schema}`;
|
|
230
231
|
}
|
|
232
|
+
get toRdfResourceValueTypes() {
|
|
233
|
+
return new Set([...this.identifierType.nodeKinds].map(NodeKind.toTermType));
|
|
234
|
+
}
|
|
231
235
|
get toRdfjsResourceType() {
|
|
232
236
|
if (this.parentObjectTypes.length > 0) {
|
|
233
237
|
return this.parentObjectTypes[0].toRdfjsResourceType;
|
|
@@ -396,6 +400,9 @@ __decorate([
|
|
|
396
400
|
__decorate([
|
|
397
401
|
Memoize()
|
|
398
402
|
], NamedObjectType.prototype, "schemaType", null);
|
|
403
|
+
__decorate([
|
|
404
|
+
Memoize()
|
|
405
|
+
], NamedObjectType.prototype, "toRdfResourceValueTypes", null);
|
|
399
406
|
__decorate([
|
|
400
407
|
Memoize()
|
|
401
408
|
], NamedObjectType.prototype, "toRdfjsResourceType", null);
|
|
@@ -2,9 +2,10 @@ import { imports } from "../imports.js";
|
|
|
2
2
|
import { syntheticNamePrefix } from "../syntheticNamePrefix.js";
|
|
3
3
|
import { code, conditionalOutput } from "../ts-poet-wrapper.js";
|
|
4
4
|
import { snippets_PropertyPath } from "./snippets_PropertyPath.js";
|
|
5
|
+
const ReturnT = code `${imports.BlankNode} | ${imports.Literal} | ${imports.NamedNode}`;
|
|
5
6
|
export const snippets_ToRdfResourceValuesFunction = conditionalOutput(`${syntheticNamePrefix}ToRdfResourceValuesFunction`, code `\
|
|
6
|
-
export type ${syntheticNamePrefix}ToRdfResourceValuesFunction<
|
|
7
|
-
(value:
|
|
7
|
+
export type ${syntheticNamePrefix}ToRdfResourceValuesFunction<ValueT, ReturnT extends ${ReturnT} = ${ReturnT}> =
|
|
8
|
+
(value: ValueT,
|
|
8
9
|
options: {
|
|
9
10
|
graph?: Exclude<${imports.Quad_Graph}, ${imports.Variable}>;
|
|
10
11
|
ignoreRdfType?: boolean;
|
|
@@ -12,5 +13,5 @@ export type ${syntheticNamePrefix}ToRdfResourceValuesFunction<T> =
|
|
|
12
13
|
resource: ${imports.Resource};
|
|
13
14
|
resourceSet: ${imports.ResourceSet};
|
|
14
15
|
}
|
|
15
|
-
) =>
|
|
16
|
+
) => ReturnT[];`);
|
|
16
17
|
//# sourceMappingURL=snippets_ToRdfResourceValuesFunction.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@shaclmate/shacl-ast": "4.0.
|
|
3
|
+
"@shaclmate/shacl-ast": "4.0.21",
|
|
4
4
|
"@rdfjs/dataset": "~2.0.2",
|
|
5
5
|
"@rdfjs/prefix-map": "~0.1.2",
|
|
6
6
|
"@rdfjs/term-map": "~2.0.2",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
},
|
|
71
71
|
"type": "module",
|
|
72
72
|
"types": "./dist/index.d.ts",
|
|
73
|
-
"version": "4.0.
|
|
73
|
+
"version": "4.0.21"
|
|
74
74
|
}
|