@shaclmate/shacl-ast 4.0.21 → 4.0.23

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.
@@ -71,7 +71,7 @@ export class AbstractShapesGraph {
71
71
  */
72
72
  toDataset() {
73
73
  const dataset = datasetFactory.dataset();
74
- const resourceSet = new ResourceSet(dataset);
74
+ const resourceSet = new ResourceSet({ dataFactory, dataset });
75
75
  for (const nodeShape of this.nodeShapes) {
76
76
  this.typeFunctions.NodeShape.$toRdfResource(nodeShape, { resourceSet });
77
77
  }
@@ -185,7 +185,10 @@ export class AbstractShapesGraph {
185
185
  else {
186
186
  curieDataset = dataset;
187
187
  }
188
- const curieResourceSet = new ResourceSet(curieDataset);
188
+ const curieResourceSet = new ResourceSet({
189
+ dataFactory,
190
+ dataset: curieDataset,
191
+ });
189
192
  return Either.encase(() => {
190
193
  function readGraph() {
191
194
  const graphs = new TermSet();
@@ -1,5 +1,5 @@
1
1
  import type { BlankNode, DatasetCore, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
- import { PropertyPath as RdfjsResourcePropertyPath, Resource, ResourceSet } from "@rdfx/resource";
2
+ import { PropertyPath as RdfxResourcePropertyPath, Resource, ResourceSet } from "@rdfx/resource";
3
3
  import { NTriplesTerm } from "@rdfx/string";
4
4
  import { Either, Maybe } from "purify-ts";
5
5
  interface $BooleanFilter {
@@ -50,7 +50,7 @@ type $PropertiesFromRdfResourceFunction<T> = (resource: Resource, options: {
50
50
  objectSet: $ObjectSet;
51
51
  preferredLanguages?: readonly string[];
52
52
  }) => Either<Error, T>;
53
- export type $PropertyPath = RdfjsResourcePropertyPath;
53
+ export type $PropertyPath = RdfxResourcePropertyPath;
54
54
  export declare namespace $PropertyPath {
55
55
  type $Filter = object;
56
56
  function $filter(_filter: $Filter, _value: $PropertyPath): boolean;
@@ -58,6 +58,7 @@ export declare namespace $PropertyPath {
58
58
  const $fromRdfResourceValues: $FromRdfResourceValuesFunction<$PropertyPath>;
59
59
  const $schema: Readonly<object>;
60
60
  const $toRdfResource: $ToRdfResourceFunction<$PropertyPath>;
61
+ const $toString: typeof RdfxResourcePropertyPath.toString;
61
62
  }
62
63
  export interface $ShaclPropertySchema<TypeSchemaT = object> {
63
64
  readonly kind: "Shacl";
@@ -80,13 +81,13 @@ export type $ToRdfResourceFunction<T> = (value: T, options?: {
80
81
  ignoreRdfType?: boolean;
81
82
  resourceSet?: ResourceSet;
82
83
  }) => Resource;
83
- export type $ToRdfResourceValuesFunction<T> = (value: T, options: {
84
+ export type $ToRdfResourceValuesFunction<ValueT, ReturnT extends BlankNode | Literal | NamedNode = BlankNode | Literal | NamedNode> = (value: ValueT, options: {
84
85
  graph?: Exclude<Quad_Graph, Variable>;
85
86
  ignoreRdfType?: boolean;
86
87
  propertyPath: $PropertyPath;
87
88
  resource: Resource;
88
89
  resourceSet: ResourceSet;
89
- }) => (bigint | boolean | number | string | BlankNode | Literal | NamedNode)[];
90
+ }) => ReturnT[];
90
91
  export interface PropertyShape {
91
92
  readonly $identifier: PropertyShape.$Identifier;
92
93
  readonly $type: "PropertyShape";
@@ -589,6 +590,9 @@ export declare namespace PropertyShape {
589
590
  };
590
591
  };
591
592
  function $toRdfResource(_propertyShape: PropertyShape, options?: Parameters<$ToRdfResourceFunction<PropertyShape>>[1]): Resource;
593
+ function $propertiesToStrings(_propertyShape: PropertyShape): Record<string, string>;
594
+ function $toString(this: PropertyShape): string;
595
+ function $toString(_propertyShape: PropertyShape): string;
592
596
  }
593
597
  export interface PropertyGroup {
594
598
  readonly $identifier: PropertyGroup.$Identifier;
@@ -661,6 +665,9 @@ export declare namespace PropertyGroup {
661
665
  };
662
666
  };
663
667
  function $toRdfResource(_propertyGroup: PropertyGroup, options?: Parameters<$ToRdfResourceFunction<PropertyGroup>>[1]): Resource;
668
+ function $propertiesToStrings(_propertyGroup: PropertyGroup): Record<string, string>;
669
+ function $toString(this: PropertyGroup): string;
670
+ function $toString(_propertyGroup: PropertyGroup): string;
664
671
  }
665
672
  export interface Ontology {
666
673
  readonly $identifier: Ontology.$Identifier;
@@ -733,6 +740,9 @@ export declare namespace Ontology {
733
740
  };
734
741
  };
735
742
  function $toRdfResource(_ontology: Ontology, options?: Parameters<$ToRdfResourceFunction<Ontology>>[1]): Resource;
743
+ function $propertiesToStrings(_ontology: Ontology): Record<string, string>;
744
+ function $toString(this: Ontology): string;
745
+ function $toString(_ontology: Ontology): string;
736
746
  }
737
747
  export interface NodeShape {
738
748
  readonly $identifier: NodeShape.$Identifier;
@@ -1216,6 +1226,9 @@ export declare namespace NodeShape {
1216
1226
  };
1217
1227
  };
1218
1228
  function $toRdfResource(_nodeShape: NodeShape, options?: Parameters<$ToRdfResourceFunction<NodeShape>>[1]): Resource;
1229
+ function $propertiesToStrings(_nodeShape: NodeShape): Record<string, string>;
1230
+ function $toString(this: NodeShape): string;
1231
+ function $toString(_nodeShape: NodeShape): string;
1219
1232
  }
1220
1233
  export type Shape = NodeShape | PropertyShape;
1221
1234
  export declare namespace Shape {
@@ -2198,7 +2211,14 @@ export declare namespace Shape {
2198
2211
  };
2199
2212
  };
2200
2213
  const $toRdfResource: $ToRdfResourceFunction<Shape>;
2201
- const $toRdfResourceValues: $ToRdfResourceValuesFunction<Shape>;
2214
+ const $toRdfResourceValues: (value: Shape, _options: {
2215
+ graph?: Exclude<Quad_Graph, Variable>;
2216
+ ignoreRdfType?: boolean;
2217
+ propertyPath: $PropertyPath;
2218
+ resource: Resource;
2219
+ resourceSet: ResourceSet;
2220
+ }) => (BlankNode | NamedNode)[];
2221
+ const $toString: (value: Shape) => string;
2202
2222
  function isShape(object: $Object): object is Shape;
2203
2223
  }
2204
2224
  export type $Object = NodeShape | Ontology | PropertyGroup | PropertyShape;
@@ -3018,7 +3038,14 @@ export declare namespace $Object {
3018
3038
  };
3019
3039
  };
3020
3040
  const $toRdfResource: $ToRdfResourceFunction<$Object>;
3021
- const $toRdfResourceValues: $ToRdfResourceValuesFunction<$Object>;
3041
+ const $toRdfResourceValues: (value: $Object, _options: {
3042
+ graph?: Exclude<Quad_Graph, Variable>;
3043
+ ignoreRdfType?: boolean;
3044
+ propertyPath: $PropertyPath;
3045
+ resource: Resource;
3046
+ resourceSet: ResourceSet;
3047
+ }) => (BlankNode | NamedNode)[];
3048
+ const $toString: (value: $Object) => string;
3022
3049
  }
3023
3050
  export interface $ObjectSet {
3024
3051
  nodeShape(identifier: NodeShape.$Identifier, options?: {
package/dist/generated.js CHANGED
@@ -1,9 +1,20 @@
1
1
  import datasetFactory from "@rdfjs/dataset";
2
2
  import dataFactory from "@rdfx/data-factory";
3
3
  import { LiteralFactory } from "@rdfx/literal";
4
- import { PropertyPath as RdfjsResourcePropertyPath, Resource, ResourceSet, } from "@rdfx/resource";
4
+ import { PropertyPath as RdfxResourcePropertyPath, Resource, ResourceSet, } from "@rdfx/resource";
5
5
  import { NTriplesIdentifier, NTriplesTerm } from "@rdfx/string";
6
6
  import { Either, Left, Maybe, Right } from "purify-ts";
7
+ /**
8
+ * Remove undefined values from a record.
9
+ */
10
+ function $compactRecord(record) {
11
+ return Object.entries(record).reduce((definedProperties, [propertyName, propertyValue]) => {
12
+ if (propertyValue !== undefined) {
13
+ definedProperties[propertyName] = propertyValue;
14
+ }
15
+ return definedProperties;
16
+ }, {});
17
+ }
7
18
  function $filterArray(filterItem) {
8
19
  return (filter, values) => {
9
20
  for (const value of values) {
@@ -184,12 +195,13 @@ export var $PropertyPath;
184
195
  return true;
185
196
  }
186
197
  $PropertyPath.$filter = $filter;
187
- $PropertyPath.$fromRdfResource = RdfjsResourcePropertyPath.fromResource;
198
+ $PropertyPath.$fromRdfResource = RdfxResourcePropertyPath.fromResource;
188
199
  $PropertyPath.$fromRdfResourceValues = (values, options) => values.chain((values) => values.chainMap((value) => value
189
200
  .toResource()
190
201
  .chain((resource) => $PropertyPath.$fromRdfResource(resource, options))));
191
202
  $PropertyPath.$schema = {};
192
- $PropertyPath.$toRdfResource = RdfjsResourcePropertyPath.toResource;
203
+ $PropertyPath.$toRdfResource = RdfxResourcePropertyPath.toResource;
204
+ $PropertyPath.$toString = RdfxResourcePropertyPath.toString;
193
205
  })($PropertyPath || ($PropertyPath = {}));
194
206
  var $RdfVocabularies;
195
207
  (function ($RdfVocabularies) {
@@ -1960,7 +1972,10 @@ export var PropertyShape;
1960
1972
  };
1961
1973
  function $toRdfResource(_propertyShape, options) {
1962
1974
  const resourceSet = options?.resourceSet ??
1963
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
1975
+ new ResourceSet({
1976
+ dataFactory: dataFactory,
1977
+ dataset: datasetFactory.dataset(),
1978
+ });
1964
1979
  const resource = resourceSet.resource(_propertyShape.$identifier);
1965
1980
  if (!options?.ignoreRdfType) {
1966
1981
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyShape"), options?.graph);
@@ -2146,6 +2161,19 @@ export var PropertyShape;
2146
2161
  return resource;
2147
2162
  }
2148
2163
  PropertyShape.$toRdfResource = $toRdfResource;
2164
+ function $propertiesToStrings(_propertyShape) {
2165
+ return $compactRecord({
2166
+ $identifier: _propertyShape.$identifier.toString(),
2167
+ label: _propertyShape.label.map((item) => item.toString()).extract(),
2168
+ name: _propertyShape.name.map((item) => item.toString()).extract(),
2169
+ path: $PropertyPath.$toString(_propertyShape.path),
2170
+ });
2171
+ }
2172
+ PropertyShape.$propertiesToStrings = $propertiesToStrings;
2173
+ function $toString(_propertyShape) {
2174
+ return `PropertyShape(${JSON.stringify($propertiesToStrings((_propertyShape ?? this)))})`;
2175
+ }
2176
+ PropertyShape.$toString = $toString;
2149
2177
  })(PropertyShape || (PropertyShape = {}));
2150
2178
  export var PropertyGroup;
2151
2179
  (function (PropertyGroup) {
@@ -2330,7 +2358,10 @@ export var PropertyGroup;
2330
2358
  };
2331
2359
  function $toRdfResource(_propertyGroup, options) {
2332
2360
  const resourceSet = options?.resourceSet ??
2333
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
2361
+ new ResourceSet({
2362
+ dataFactory: dataFactory,
2363
+ dataset: datasetFactory.dataset(),
2364
+ });
2334
2365
  const resource = resourceSet.resource(_propertyGroup.$identifier);
2335
2366
  if (!options?.ignoreRdfType) {
2336
2367
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#PropertyGroup"), options?.graph);
@@ -2344,6 +2375,17 @@ export var PropertyGroup;
2344
2375
  return resource;
2345
2376
  }
2346
2377
  PropertyGroup.$toRdfResource = $toRdfResource;
2378
+ function $propertiesToStrings(_propertyGroup) {
2379
+ return $compactRecord({
2380
+ $identifier: _propertyGroup.$identifier.toString(),
2381
+ label: _propertyGroup.label.map((item) => item.toString()).extract(),
2382
+ });
2383
+ }
2384
+ PropertyGroup.$propertiesToStrings = $propertiesToStrings;
2385
+ function $toString(_propertyGroup) {
2386
+ return `PropertyGroup(${JSON.stringify($propertiesToStrings((_propertyGroup ?? this)))})`;
2387
+ }
2388
+ PropertyGroup.$toString = $toString;
2347
2389
  })(PropertyGroup || (PropertyGroup = {}));
2348
2390
  export var Ontology;
2349
2391
  (function (Ontology) {
@@ -2528,7 +2570,10 @@ export var Ontology;
2528
2570
  };
2529
2571
  function $toRdfResource(_ontology, options) {
2530
2572
  const resourceSet = options?.resourceSet ??
2531
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
2573
+ new ResourceSet({
2574
+ dataFactory: dataFactory,
2575
+ dataset: datasetFactory.dataset(),
2576
+ });
2532
2577
  const resource = resourceSet.resource(_ontology.$identifier);
2533
2578
  if (!options?.ignoreRdfType) {
2534
2579
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/2002/07/owl#Ontology"), options?.graph);
@@ -2542,6 +2587,17 @@ export var Ontology;
2542
2587
  return resource;
2543
2588
  }
2544
2589
  Ontology.$toRdfResource = $toRdfResource;
2590
+ function $propertiesToStrings(_ontology) {
2591
+ return $compactRecord({
2592
+ $identifier: _ontology.$identifier.toString(),
2593
+ label: _ontology.label.map((item) => item.toString()).extract(),
2594
+ });
2595
+ }
2596
+ Ontology.$propertiesToStrings = $propertiesToStrings;
2597
+ function $toString(_ontology) {
2598
+ return `Ontology(${JSON.stringify($propertiesToStrings((_ontology ?? this)))})`;
2599
+ }
2600
+ Ontology.$toString = $toString;
2545
2601
  })(Ontology || (Ontology = {}));
2546
2602
  export var NodeShape;
2547
2603
  (function (NodeShape) {
@@ -4165,7 +4221,10 @@ export var NodeShape;
4165
4221
  };
4166
4222
  function $toRdfResource(_nodeShape, options) {
4167
4223
  const resourceSet = options?.resourceSet ??
4168
- new ResourceSet(datasetFactory.dataset(), { dataFactory: dataFactory });
4224
+ new ResourceSet({
4225
+ dataFactory: dataFactory,
4226
+ dataset: datasetFactory.dataset(),
4227
+ });
4169
4228
  const resource = resourceSet.resource(_nodeShape.$identifier);
4170
4229
  if (!options?.ignoreRdfType) {
4171
4230
  resource.add($RdfVocabularies.rdf.type, dataFactory.namedNode("http://www.w3.org/ns/shacl#NodeShape"), options?.graph);
@@ -4357,6 +4416,17 @@ export var NodeShape;
4357
4416
  return resource;
4358
4417
  }
4359
4418
  NodeShape.$toRdfResource = $toRdfResource;
4419
+ function $propertiesToStrings(_nodeShape) {
4420
+ return $compactRecord({
4421
+ $identifier: _nodeShape.$identifier.toString(),
4422
+ label: _nodeShape.label.map((item) => item.toString()).extract(),
4423
+ });
4424
+ }
4425
+ NodeShape.$propertiesToStrings = $propertiesToStrings;
4426
+ function $toString(_nodeShape) {
4427
+ return `NodeShape(${JSON.stringify($propertiesToStrings((_nodeShape ?? this)))})`;
4428
+ }
4429
+ NodeShape.$toString = $toString;
4360
4430
  })(NodeShape || (NodeShape = {}));
4361
4431
  export var Shape;
4362
4432
  (function (Shape) {
@@ -4678,6 +4748,15 @@ export var Shape;
4678
4748
  }
4679
4749
  throw new Error("unable to serialize to RDF");
4680
4750
  });
4751
+ Shape.$toString = (value) => {
4752
+ if (NodeShape.isNodeShape(value)) {
4753
+ return NodeShape.$toString(value);
4754
+ }
4755
+ if (PropertyShape.isPropertyShape(value)) {
4756
+ return PropertyShape.$toString(value);
4757
+ }
4758
+ throw new Error("unable to serialize to string");
4759
+ };
4681
4760
  function isShape(object) {
4682
4761
  return (NodeShape.isNodeShape(object) || PropertyShape.isPropertyShape(object));
4683
4762
  }
@@ -4859,6 +4938,21 @@ export var $Object;
4859
4938
  }
4860
4939
  throw new Error("unable to serialize to RDF");
4861
4940
  });
4941
+ $Object.$toString = (value) => {
4942
+ if (NodeShape.isNodeShape(value)) {
4943
+ return NodeShape.$toString(value);
4944
+ }
4945
+ if (Ontology.isOntology(value)) {
4946
+ return Ontology.$toString(value);
4947
+ }
4948
+ if (PropertyGroup.isPropertyGroup(value)) {
4949
+ return PropertyGroup.$toString(value);
4950
+ }
4951
+ if (PropertyShape.isPropertyShape(value)) {
4952
+ return PropertyShape.$toString(value);
4953
+ }
4954
+ throw new Error("unable to serialize to string");
4955
+ };
4862
4956
  })($Object || ($Object = {}));
4863
4957
  export class $RdfjsDatasetObjectSet {
4864
4958
  $graph;
@@ -4874,7 +4968,10 @@ export class $RdfjsDatasetObjectSet {
4874
4968
  return this.#dataset();
4875
4969
  }
4876
4970
  $resourceSet() {
4877
- return new ResourceSet(this.$dataset(), { dataFactory: dataFactory });
4971
+ return new ResourceSet({
4972
+ dataFactory: dataFactory,
4973
+ dataset: this.$dataset(),
4974
+ });
4878
4975
  }
4879
4976
  async nodeShape(identifier, options) {
4880
4977
  return this.nodeShapeSync(identifier, options);
package/package.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "@rdfjs/term-map": "~2.0.2",
5
5
  "@rdfjs/term-set": "~2.0.3",
6
6
  "@rdfjs/types": "~2.0.1",
7
- "@rdfx/data-factory": "0.0.11",
8
- "@rdfx/resource": "0.0.11",
9
- "@rdfx/string": "0.0.11",
7
+ "@rdfx/data-factory": "0.0.12",
8
+ "@rdfx/resource": "0.0.12",
9
+ "@rdfx/string": "0.0.12",
10
10
  "@tpluscode/rdf-ns-builders": "~4.3.0",
11
11
  "@types/rdfjs__dataset": "~2.0.7",
12
12
  "@types/rdfjs__term-map": "~2.0.10",
@@ -44,5 +44,5 @@
44
44
  },
45
45
  "type": "module",
46
46
  "types": "./dist/index.d.ts",
47
- "version": "4.0.21"
47
+ "version": "4.0.23"
48
48
  }