@shaclmate/compiler 4.0.20 → 4.0.22

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.
@@ -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: ${snippets.ToRdfResourceValuesFunction}<${this.name}> = ${this.inlineToRdfResourceValuesFunction};`;
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 inlineJsonType() {
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 new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }) => code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`), { on: "|" })})`);
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 new AbstractType.JsonType(code `(${joinCode(this.concreteMembers.map(({ jsonType, primaryDiscriminantValue }, memberI) => {
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 `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
325
+ return code `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
331
326
  case "intrinsic":
332
- return code `${jsonType}`;
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 new AbstractType.JsonType(joinCode(this.concreteMembers.map(({ jsonType }) => code `${jsonType}`), { on: "|" }));
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 inlineJsonSchema() {
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 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()`;
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 code `${imports.z}.discriminatedUnion("${discriminant.name}", [${joinCode(this.concreteMembers.map(({ primaryDiscriminantValue, type }, memberI) => {
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 `${imports.z}.object({ ${discriminant.name}: ${imports.z}.literal(${literalOf(primaryDiscriminantValue)}), value: ${type.jsonSchema({ context: "type" })} })`;
355
+ return code `{ ${discriminant.name}: ${literalOf(primaryDiscriminantValue)}, value: ${jsonType} }`;
354
356
  case "intrinsic":
355
- return type.jsonSchema({
356
- includeDiscriminantProperty: true,
357
- context: "type",
358
- });
357
+ return code `${jsonType}`;
359
358
  default:
360
359
  throw new Error();
361
360
  }
362
- }), { on: "," })}]).readonly()`;
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 code `${imports.z}.union([${joinCode(this.concreteMembers.map(({ type }) => type.jsonSchema({ context: "type" })), { on: "," })}]).readonly()`;
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
- }) as ${snippets.ToRdfResourceValuesFunction}<${this.name}>)`;
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);
@@ -20,7 +20,7 @@ export function NamedObjectType_toRdfResourceFunctionOrMethodDeclaration() {
20
20
  }
21
21
  parameters.push(code `options?: Parameters<${snippets.ToRdfResourceFunction}<${this.name}>>[1]`);
22
22
  const statements = [
23
- code `const ${variables.resourceSet} = options?.${variables.resourceSet} ?? new ${imports.ResourceSet}(${imports.datasetFactory}.dataset(), { dataFactory: ${imports.dataFactory} });`,
23
+ code `const ${variables.resourceSet} = options?.${variables.resourceSet} ?? new ${imports.ResourceSet}({ dataFactory: ${imports.dataFactory}, dataset: ${imports.datasetFactory}.dataset() });`,
24
24
  ];
25
25
  if (this.parentObjectTypes.length > 0) {
26
26
  const superToRdfOptions = code `{ ${variables.ignoreRdfType}: true, ${variables.graph}: options?.${variables.graph}, ${variables.resourceSet} }`;
@@ -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<T> =
7
- (value: T,
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
- ) => (bigint | boolean | number | string | ${imports.BlankNode} | ${imports.Literal} | ${imports.NamedNode})[];`);
16
+ ) => ReturnT[];`);
16
17
  //# sourceMappingURL=snippets_ToRdfResourceValuesFunction.js.map
@@ -37,7 +37,7 @@ export class ${syntheticNamePrefix}RdfjsDatasetObjectSet implements ${syntheticN
37
37
  }
38
38
 
39
39
  protected ${syntheticNamePrefix}resourceSet(): ${imports.ResourceSet} {
40
- return new ${imports.ResourceSet}(this.${syntheticNamePrefix}dataset(), { dataFactory: ${imports.dataFactory} });
40
+ return new ${imports.ResourceSet}({ dataFactory: ${imports.dataFactory}, dataset: this.${syntheticNamePrefix}dataset() });
41
41
  }
42
42
 
43
43
  ${joinCode([
@@ -161,7 +161,7 @@ async ${methodSignatures.objects.name}(${methodSignatures.objects.parameters}):
161
161
  const dataset = ${imports.datasetFactory}.dataset(quads.concat());
162
162
  const objects: ObjectT[] = [];
163
163
  for (const identifier of identifiers) {
164
- objects.push(await liftEither(namedObjectType.${syntheticNamePrefix}fromRdfResource(new ${imports.Resource}(dataset, identifier as ${imports.NamedNode}), { objectSet: this, preferredLanguages: query?.preferredLanguages })));
164
+ objects.push(await liftEither(namedObjectType.${syntheticNamePrefix}fromRdfResource(new ${imports.Resource}({ dataFactory: ${imports.dataFactory}, dataset: dataset, identifier: identifier as ${imports.NamedNode} }), { objectSet: this, preferredLanguages: query?.preferredLanguages })));
165
165
  }
166
166
  return objects;
167
167
  });
@@ -80,13 +80,13 @@ export type $ToRdfResourceFunction<T> = (value: T, options?: {
80
80
  ignoreRdfType?: boolean;
81
81
  resourceSet?: ResourceSet;
82
82
  }) => Resource;
83
- export type $ToRdfResourceValuesFunction<T> = (value: T, options: {
83
+ export type $ToRdfResourceValuesFunction<ValueT, ReturnT extends BlankNode | Literal | NamedNode = BlankNode | Literal | NamedNode> = (value: ValueT, options: {
84
84
  graph?: Exclude<Quad_Graph, Variable>;
85
85
  ignoreRdfType?: boolean;
86
86
  propertyPath: $PropertyPath;
87
87
  resource: Resource;
88
88
  resourceSet: ResourceSet;
89
- }) => (bigint | boolean | number | string | BlankNode | Literal | NamedNode)[];
89
+ }) => ReturnT[];
90
90
  export interface PropertyShape {
91
91
  readonly $identifier: PropertyShape.$Identifier;
92
92
  readonly $type: "PropertyShape";
@@ -2695,7 +2695,13 @@ export declare namespace Shape {
2695
2695
  };
2696
2696
  };
2697
2697
  const $toRdfResource: $ToRdfResourceFunction<Shape>;
2698
- const $toRdfResourceValues: $ToRdfResourceValuesFunction<Shape>;
2698
+ const $toRdfResourceValues: (value: Shape, _options: {
2699
+ graph?: Exclude<Quad_Graph, Variable>;
2700
+ ignoreRdfType?: boolean;
2701
+ propertyPath: $PropertyPath;
2702
+ resource: Resource;
2703
+ resourceSet: ResourceSet;
2704
+ }) => (BlankNode | NamedNode)[];
2699
2705
  function isShape(object: $Object): object is Shape;
2700
2706
  }
2701
2707
  export type $Object = NodeShape | Ontology | PropertyGroup | PropertyShape;
@@ -3733,7 +3739,13 @@ export declare namespace $Object {
3733
3739
  };
3734
3740
  };
3735
3741
  const $toRdfResource: $ToRdfResourceFunction<$Object>;
3736
- const $toRdfResourceValues: $ToRdfResourceValuesFunction<$Object>;
3742
+ const $toRdfResourceValues: (value: $Object, _options: {
3743
+ graph?: Exclude<Quad_Graph, Variable>;
3744
+ ignoreRdfType?: boolean;
3745
+ propertyPath: $PropertyPath;
3746
+ resource: Resource;
3747
+ resourceSet: ResourceSet;
3748
+ }) => (BlankNode | NamedNode)[];
3737
3749
  }
3738
3750
  export interface $ObjectSet {
3739
3751
  nodeShape(identifier: NodeShape.$Identifier, options?: {
@@ -2166,7 +2166,10 @@ export var PropertyShape;
2166
2166
  };
2167
2167
  function $toRdfResource(_propertyShape, options) {
2168
2168
  const resourceSet = options?.resourceSet ??
2169
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
2169
+ new ResourceSet({
2170
+ dataFactory: dataFactory,
2171
+ dataset: datasetFactory.dataset(),
2172
+ });
2170
2173
  const resource = resourceSet.resource(_propertyShape.$identifier);
2171
2174
  if (!options?.ignoreRdfType) {
2172
2175
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"), options?.graph);
@@ -2546,7 +2549,10 @@ export var PropertyGroup;
2546
2549
  };
2547
2550
  function $toRdfResource(_propertyGroup, options) {
2548
2551
  const resourceSet = options?.resourceSet ??
2549
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
2552
+ new ResourceSet({
2553
+ dataFactory: dataFactory,
2554
+ dataset: datasetFactory.dataset(),
2555
+ });
2550
2556
  const resource = resourceSet.resource(_propertyGroup.$identifier);
2551
2557
  if (!options?.ignoreRdfType) {
2552
2558
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"), options?.graph);
@@ -2974,7 +2980,10 @@ export var Ontology;
2974
2980
  };
2975
2981
  function $toRdfResource(_ontology, options) {
2976
2982
  const resourceSet = options?.resourceSet ??
2977
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
2983
+ new ResourceSet({
2984
+ dataFactory: dataFactory,
2985
+ dataset: datasetFactory.dataset(),
2986
+ });
2978
2987
  const resource = resourceSet.resource(_ontology.$identifier);
2979
2988
  if (!options?.ignoreRdfType) {
2980
2989
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"), options?.graph);
@@ -5315,7 +5324,10 @@ export var NodeShape;
5315
5324
  };
5316
5325
  function $toRdfResource(_nodeShape, options) {
5317
5326
  const resourceSet = options?.resourceSet ??
5318
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
5327
+ new ResourceSet({
5328
+ dataFactory: dataFactory,
5329
+ dataset: datasetFactory.dataset(),
5330
+ });
5319
5331
  const resource = resourceSet.resource(_nodeShape.$identifier);
5320
5332
  if (!options?.ignoreRdfType) {
5321
5333
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"), options?.graph);
@@ -6069,7 +6081,10 @@ export class $RdfjsDatasetObjectSet {
6069
6081
  return this.#dataset();
6070
6082
  }
6071
6083
  $resourceSet() {
6072
- return new ResourceSet(this.$dataset(), { dataFactory: dataFactory });
6084
+ return new ResourceSet({
6085
+ dataFactory: dataFactory,
6086
+ dataset: this.$dataset(),
6087
+ });
6073
6088
  }
6074
6089
  async nodeShape(identifier, options) {
6075
6090
  return this.nodeShapeSync(identifier, options);
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "dependencies": {
3
- "@shaclmate/shacl-ast": "4.0.20",
3
+ "@shaclmate/shacl-ast": "4.0.22",
4
4
  "@rdfjs/dataset": "~2.0.2",
5
5
  "@rdfjs/prefix-map": "~0.1.2",
6
6
  "@rdfjs/term-map": "~2.0.2",
7
7
  "@rdfjs/term-set": "~2.0.3",
8
8
  "@rdfjs/types": "~2.0.1",
9
- "@rdfx/data-factory": "0.0.11",
10
- "@rdfx/literal": "0.0.11",
11
- "@rdfx/resource": "0.0.11",
12
- "@rdfx/string": "0.0.11",
9
+ "@rdfx/data-factory": "0.0.12",
10
+ "@rdfx/literal": "0.0.12",
11
+ "@rdfx/resource": "0.0.12",
12
+ "@rdfx/string": "0.0.12",
13
13
  "@sindresorhus/base62": "~0.1.0",
14
14
  "@tpluscode/rdf-ns-builders": "~4.3.0",
15
15
  "@types/rdfjs__dataset": "~2.0.7",
@@ -70,5 +70,5 @@
70
70
  },
71
71
  "type": "module",
72
72
  "types": "./dist/index.d.ts",
73
- "version": "4.0.20"
73
+ "version": "4.0.22"
74
74
  }