rdfjs-resource 2.0.5 → 2.0.6

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.
@@ -1,12 +1,14 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
1
+ import type { BlankNode, DataFactory, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
2
  import { Either } from "purify-ts";
3
3
  import { MistypedTermValueError } from "./MistypedTermValueError.js";
4
4
  import { Resource } from "./Resource.js";
5
5
  export declare abstract class AbstractTermValue<TermT extends BlankNode | Literal | NamedNode> {
6
+ protected readonly dataFactory: DataFactory;
6
7
  protected readonly focusResource: Resource;
7
8
  protected readonly predicate: NamedNode;
8
9
  protected readonly term: TermT;
9
- constructor({ focusResource, predicate, term, }: {
10
+ constructor({ dataFactory, focusResource, predicate, term, }: {
11
+ dataFactory: DataFactory;
10
12
  focusResource: Resource;
11
13
  predicate: NamedNode;
12
14
  term: TermT;
@@ -23,7 +25,9 @@ export declare abstract class AbstractTermValue<TermT extends BlankNode | Litera
23
25
  /**
24
26
  * Try to convert the term to a named resource.
25
27
  */
26
- toNamedResource(): Either<MistypedTermValueError, Resource<NamedNode>>;
28
+ toNamedResource(options?: {
29
+ graph?: Exclude<Quad_Graph, Variable>;
30
+ }): Either<MistypedTermValueError, Resource<NamedNode>>;
27
31
  toTerm(): TermT;
28
32
  protected newMistypedValueError(expectedValueType: string): MistypedTermValueError;
29
33
  }
@@ -2,7 +2,8 @@ import { Either, Left } from "purify-ts";
2
2
  import { MistypedTermValueError } from "./MistypedTermValueError.js";
3
3
  import { Resource } from "./Resource.js";
4
4
  export class AbstractTermValue {
5
- constructor({ focusResource, predicate, term, }) {
5
+ constructor({ dataFactory, focusResource, predicate, term, }) {
6
+ this.dataFactory = dataFactory;
6
7
  this.focusResource = focusResource;
7
8
  this.predicate = predicate;
8
9
  this.term = term;
@@ -29,8 +30,11 @@ export class AbstractTermValue {
29
30
  /**
30
31
  * Try to convert the term to a named resource.
31
32
  */
32
- toNamedResource() {
33
- return this.toIri().map((identifier) => new Resource(this.focusResource.dataset, identifier));
33
+ toNamedResource(options) {
34
+ return this.toIri().map((identifier) => new Resource(this.focusResource.dataset, identifier, {
35
+ dataFactory: this.dataFactory,
36
+ graph: options?.graph,
37
+ }));
34
38
  }
35
39
  toTerm() {
36
40
  return this.term;
@@ -22,6 +22,7 @@ export class DatasetObjectValues extends DatasetValues {
22
22
  continue;
23
23
  }
24
24
  yield new TermValue({
25
+ dataFactory: this.dataFactory,
25
26
  focusResource: this.focusResource,
26
27
  predicate: this.predicate,
27
28
  term: nonUniqueTerm,
@@ -32,6 +33,7 @@ export class DatasetObjectValues extends DatasetValues {
32
33
  else {
33
34
  for (const nonUniqueTerm of this.nonUniqueTermIterator()) {
34
35
  yield new TermValue({
36
+ dataFactory: this.dataFactory,
35
37
  focusResource: this.focusResource,
36
38
  predicate: this.predicate,
37
39
  term: nonUniqueTerm,
@@ -53,7 +55,7 @@ export class DatasetObjectValues extends DatasetValues {
53
55
  // }
54
56
  // }
55
57
  // } else {
56
- for (const quad of this.focusResource.dataset.match(this.focusResource.identifier, this.predicate, null, null)) {
58
+ for (const quad of this.focusResource.dataset.match(this.focusResource.identifier, this.predicate, null, this.graph)) {
57
59
  switch (quad.object.termType) {
58
60
  case "BlankNode":
59
61
  case "Literal":
@@ -15,6 +15,7 @@ export class DatasetSubjectValues extends DatasetValues {
15
15
  continue;
16
16
  }
17
17
  yield new IdentifierValue({
18
+ dataFactory: this.dataFactory,
18
19
  focusResource: this.focusResource,
19
20
  predicate: this.predicate,
20
21
  term: nonUniqueIdentifier,
@@ -25,6 +26,7 @@ export class DatasetSubjectValues extends DatasetValues {
25
26
  else {
26
27
  for (const nonUniqueIdentifier of this.nonUniqueIdentifierIterator()) {
27
28
  yield new IdentifierValue({
29
+ dataFactory: this.dataFactory,
28
30
  focusResource: this.focusResource,
29
31
  predicate: this.predicate,
30
32
  term: nonUniqueIdentifier,
@@ -33,7 +35,7 @@ export class DatasetSubjectValues extends DatasetValues {
33
35
  }
34
36
  }
35
37
  *nonUniqueIdentifierIterator() {
36
- for (const quad of this.focusResource.dataset.match(null, this.predicate, this.focusResource.identifier)) {
38
+ for (const quad of this.focusResource.dataset.match(null, this.predicate, this.focusResource.identifier, this.graph)) {
37
39
  switch (quad.subject.termType) {
38
40
  case "BlankNode":
39
41
  case "NamedNode":
@@ -1,10 +1,14 @@
1
- import type { NamedNode } from "@rdfjs/types";
1
+ import type { DataFactory, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
2
  import type { Resource } from "./Resource.js";
3
3
  import { Values } from "./Values.js";
4
4
  export declare abstract class DatasetValues<ValueT> extends Values<ValueT> {
5
+ protected readonly dataFactory: DataFactory;
6
+ protected readonly graph: Exclude<Quad_Graph, Variable> | null;
5
7
  protected readonly unique: boolean;
6
- constructor({ focusResource, predicate, unique, }: {
8
+ constructor({ dataFactory, focusResource, graph, predicate, unique, }: {
9
+ dataFactory: DataFactory;
7
10
  focusResource: Resource;
11
+ graph: Exclude<Quad_Graph, Variable> | null;
8
12
  predicate: NamedNode;
9
13
  unique: boolean;
10
14
  });
@@ -1,7 +1,9 @@
1
1
  import { Values } from "./Values.js";
2
2
  export class DatasetValues extends Values {
3
- constructor({ focusResource, predicate, unique, }) {
3
+ constructor({ dataFactory, focusResource, graph, predicate, unique, }) {
4
4
  super({ focusResource, predicate });
5
+ this.dataFactory = dataFactory;
6
+ this.graph = graph;
5
7
  this.unique = unique;
6
8
  }
7
9
  get length() {
@@ -1,3 +1,4 @@
1
+ import type { Quad_Graph, Variable } from "@rdfjs/types";
1
2
  import { AbstractTermValue } from "./AbstractTermValue.js";
2
3
  import type { Identifier } from "./Identifier.js";
3
4
  import { Resource } from "./Resource.js";
@@ -6,6 +7,8 @@ import { Resource } from "./Resource.js";
6
7
  */
7
8
  export declare class IdentifierValue extends AbstractTermValue<Identifier> {
8
9
  toIdentifier(): Identifier;
9
- toResource(): Resource;
10
+ toResource(options?: {
11
+ graph?: Exclude<Quad_Graph, Variable>;
12
+ }): Resource;
10
13
  }
11
14
  //# sourceMappingURL=IdentifierValue.d.ts.map
@@ -7,8 +7,11 @@ export class IdentifierValue extends AbstractTermValue {
7
7
  toIdentifier() {
8
8
  return this.term;
9
9
  }
10
- toResource() {
11
- return new Resource(this.focusResource.dataset, this.term);
10
+ toResource(options) {
11
+ return new Resource(this.focusResource.dataset, this.term, {
12
+ dataFactory: this.dataFactory,
13
+ graph: options?.graph,
14
+ });
12
15
  }
13
16
  }
14
17
  //# sourceMappingURL=IdentifierValue.js.map
@@ -15,9 +15,11 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
15
15
  readonly dataset: DatasetCore;
16
16
  readonly identifier: IdentifierT;
17
17
  private readonly dataFactory;
18
+ private readonly graph?;
18
19
  private readonly literalFactory;
19
20
  constructor(dataset: DatasetCore, identifier: IdentifierT, options?: {
20
21
  dataFactory?: DataFactory;
22
+ graph?: Exclude<Quad_Graph, Variable>;
21
23
  });
22
24
  /**
23
25
  * Add zero or more values to this resource.
@@ -47,10 +49,12 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
47
49
  delete(predicate: NamedNode, object?: AddableValue | readonly AddableValue[], graph?: Exclude<Quad_Graph, Variable>): this;
48
50
  isInstanceOf(class_: NamedNode, options?: {
49
51
  excludeSubclasses?: boolean;
52
+ graph?: Exclude<Quad_Graph, Variable>;
50
53
  instanceOfPredicate?: NamedNode;
51
54
  subClassOfPredicate?: NamedNode;
52
55
  }): boolean;
53
56
  isSubClassOf(class_: NamedNode, options?: {
57
+ graph?: Exclude<Quad_Graph, Variable>;
54
58
  subClassOfPredicate?: NamedNode;
55
59
  }): boolean;
56
60
  /**
@@ -60,26 +64,34 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
60
64
  /**
61
65
  * Consider the resource itself as an RDF list.
62
66
  */
63
- toList(): Either<Resource.ValueError, readonly Resource.TermValue[]>;
67
+ toList(options?: {
68
+ graph?: Exclude<Quad_Graph, Variable>;
69
+ }): Either<Resource.ValueError, readonly Resource.TermValue[]>;
64
70
  /**
65
71
  * Get the first matching value of dataset statements (this.identifier, predicate, value).
66
72
  */
67
- value(predicate: NamedNode): Either<Resource.ValueError, Resource.TermValue>;
73
+ value(predicate: NamedNode, options?: {
74
+ graph?: Exclude<Quad_Graph, Variable>;
75
+ }): Either<Resource.ValueError, Resource.TermValue>;
68
76
  /**
69
77
  * Get the first matching subject of dataset statements (subject, predicate, this.identifier).
70
78
  */
71
- valueOf(predicate: NamedNode): Either<Resource.ValueError, Resource.IdentifierValue>;
79
+ valueOf(predicate: NamedNode, options?: {
80
+ graph?: Exclude<Quad_Graph, Variable>;
81
+ }): Either<Resource.ValueError, Resource.IdentifierValue>;
72
82
  /**
73
83
  * Get all values of dataset statements (this.identifier, predicate, value).
74
84
  */
75
85
  values(predicate: NamedNode, options?: {
86
+ graph?: Exclude<Quad_Graph, Variable>;
76
87
  unique?: boolean;
77
88
  }): Resource.Values<Resource.TermValue>;
78
89
  /**
79
90
  * Get the subject of dataset statements (subject, predicate, this.identifier).
80
91
  */
81
92
  valuesOf(predicate: NamedNode, options?: {
82
- unique: true;
93
+ graph?: Exclude<Quad_Graph, Variable>;
94
+ unique?: boolean;
83
95
  }): Resource.Values<Resource.IdentifierValue>;
84
96
  private addableValueToTerm;
85
97
  private addableValuesToTerms;
package/dist/Resource.js CHANGED
@@ -20,6 +20,7 @@ export class Resource {
20
20
  this.dataset = dataset;
21
21
  this.identifier = identifier;
22
22
  this.dataFactory = options?.dataFactory ?? DefaultDataFactory;
23
+ this.graph = options?.graph;
23
24
  this.literalFactory = new LiteralFactory({ dataFactory: this.dataFactory });
24
25
  }
25
26
  /**
@@ -27,7 +28,7 @@ export class Resource {
27
28
  */
28
29
  add(predicate, object, graph) {
29
30
  for (const term of this.addableValuesToTerms(object)) {
30
- this.dataset.add(this.dataFactory.quad(this.identifier, predicate, term, graph));
31
+ this.dataset.add(this.dataFactory.quad(this.identifier, predicate, term, graph ?? this.graph));
31
32
  }
32
33
  return this;
33
34
  }
@@ -38,16 +39,18 @@ export class Resource {
38
39
  * Returns the list resource.
39
40
  */
40
41
  addList(predicate, items, options) {
42
+ const graph = options?.graph ?? this.graph;
41
43
  const itemsArray = [...items];
42
44
  if (itemsArray.length === 0) {
43
45
  return new Resource(this.dataset, rdf.nil, {
44
46
  dataFactory: this.dataFactory,
47
+ graph,
45
48
  });
46
49
  }
47
50
  const mintSubListIdentifier = options?.mintSubListIdentifier ?? (() => this.dataFactory.blankNode());
48
- const listResource = new Resource(this.dataset, mintSubListIdentifier(itemsArray[0], 0), { dataFactory: this.dataFactory });
51
+ const listResource = new Resource(this.dataset, mintSubListIdentifier(itemsArray[0], 0), { dataFactory: this.dataFactory, graph });
49
52
  listResource.addListItems(itemsArray, { mintSubListIdentifier });
50
- this.add(predicate, listResource.identifier);
53
+ this.add(predicate, listResource.identifier, graph);
51
54
  return listResource;
52
55
  }
53
56
  /**
@@ -55,14 +58,14 @@ export class Resource {
55
58
  */
56
59
  addListItems(items, options) {
57
60
  const addSubListResourceValues = options?.addSubListResourceValues ?? (() => { });
58
- const graph = options?.graph;
61
+ const graph = options?.graph ?? this.graph;
59
62
  const mintSubListIdentifier = options?.mintSubListIdentifier ?? (() => this.dataFactory.blankNode());
60
63
  let currentHead = this;
61
64
  let itemIndex = 0;
62
65
  for (const item of items) {
63
66
  if (itemIndex > 0) {
64
67
  // If currentHead !== this, then create a new head and point the current head's rdf:rest at it
65
- const newHead = new Resource(this.dataset, mintSubListIdentifier(item, itemIndex), { dataFactory: this.dataFactory });
68
+ const newHead = new Resource(this.dataset, mintSubListIdentifier(item, itemIndex), { dataFactory: this.dataFactory, graph });
66
69
  addSubListResourceValues(newHead);
67
70
  currentHead.add(rdf.rest, newHead.identifier, graph);
68
71
  currentHead = newHead;
@@ -86,7 +89,7 @@ export class Resource {
86
89
  delete(predicate, object, graph) {
87
90
  if (!object) {
88
91
  for (const quad of [
89
- ...this.dataset.match(this.identifier, predicate, null, graph),
92
+ ...this.dataset.match(this.identifier, predicate, null, graph ?? this.graph),
90
93
  ]) {
91
94
  this.dataset.delete(quad);
92
95
  }
@@ -94,7 +97,7 @@ export class Resource {
94
97
  else {
95
98
  for (const term of this.addableValuesToTerms(object)) {
96
99
  for (const quad of [
97
- ...this.dataset.match(this.identifier, predicate, term, graph),
100
+ ...this.dataset.match(this.identifier, predicate, term, graph ?? this.graph),
98
101
  ]) {
99
102
  this.dataset.delete(quad);
100
103
  }
@@ -106,11 +109,12 @@ export class Resource {
106
109
  return isInstanceOfRecursive({
107
110
  class_,
108
111
  dataset: this.dataset,
112
+ graph: options?.graph ?? this.graph,
109
113
  instance: this.identifier,
110
114
  visitedClasses: new TermSet(),
111
115
  });
112
- function isInstanceOfRecursive({ class_, dataset, instance, visitedClasses, }) {
113
- for (const _ of dataset.match(instance, options?.instanceOfPredicate ?? rdf.type, class_)) {
116
+ function isInstanceOfRecursive({ class_, dataset, graph, instance, visitedClasses, }) {
117
+ for (const _ of dataset.match(instance, options?.instanceOfPredicate ?? rdf.type, class_, graph)) {
114
118
  return true;
115
119
  }
116
120
  visitedClasses.add(class_);
@@ -118,7 +122,7 @@ export class Resource {
118
122
  return false;
119
123
  }
120
124
  // Recurse into class's sub-classes that haven't been visited yet.
121
- for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, null)) {
125
+ for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
122
126
  if (quad.subject.termType !== "NamedNode") {
123
127
  continue;
124
128
  }
@@ -128,6 +132,7 @@ export class Resource {
128
132
  if (isInstanceOfRecursive({
129
133
  class_: quad.subject,
130
134
  dataset,
135
+ graph,
131
136
  instance,
132
137
  visitedClasses,
133
138
  })) {
@@ -141,16 +146,17 @@ export class Resource {
141
146
  return isSubClassOfRecursive({
142
147
  class_,
143
148
  dataset: this.dataset,
149
+ graph: options?.graph ?? this.graph,
144
150
  thisIdentifier: this.identifier,
145
151
  visitedClasses: new TermSet(),
146
152
  });
147
- function isSubClassOfRecursive({ class_, dataset, thisIdentifier, visitedClasses, }) {
148
- for (const _ of dataset.match(thisIdentifier, options?.subClassOfPredicate ?? rdfs.subClassOf, class_)) {
153
+ function isSubClassOfRecursive({ class_, dataset, graph, thisIdentifier, visitedClasses, }) {
154
+ for (const _ of dataset.match(thisIdentifier, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
149
155
  return true;
150
156
  }
151
157
  visitedClasses.add(class_);
152
158
  // Recurse into class's sub-classes that haven't been visited yet.
153
- for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, null)) {
159
+ for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
154
160
  if (quad.subject.termType !== "NamedNode") {
155
161
  continue;
156
162
  }
@@ -160,6 +166,7 @@ export class Resource {
160
166
  if (isSubClassOfRecursive({
161
167
  class_: quad.subject,
162
168
  dataset,
169
+ graph,
163
170
  thisIdentifier,
164
171
  visitedClasses,
165
172
  })) {
@@ -179,12 +186,13 @@ export class Resource {
179
186
  /**
180
187
  * Consider the resource itself as an RDF list.
181
188
  */
182
- toList() {
189
+ toList(options) {
183
190
  if (this.identifier.equals(rdf.nil)) {
184
191
  return Either.of([]);
185
192
  }
193
+ const graph = options?.graph ?? this.graph;
186
194
  const firstObjects = [
187
- ...new TermSet([...this.dataset.match(this.identifier, rdf.first, null)].map((quad) => quad.object)),
195
+ ...new TermSet([...this.dataset.match(this.identifier, rdf.first, null, graph)].map((quad) => quad.object)),
188
196
  ];
189
197
  if (firstObjects.length === 0) {
190
198
  return Left(new Resource.ListStructureError({
@@ -215,7 +223,7 @@ export class Resource {
215
223
  }));
216
224
  }
217
225
  const restObjects = [
218
- ...new TermSet([...this.dataset.match(this.identifier, rdf.rest, null)].map((quad) => quad.object)),
226
+ ...new TermSet([...this.dataset.match(this.identifier, rdf.rest, null, graph)].map((quad) => quad.object)),
219
227
  ];
220
228
  if (restObjects.length === 0) {
221
229
  return Left(new Resource.ListStructureError({
@@ -246,32 +254,38 @@ export class Resource {
246
254
  }
247
255
  return Either.of([
248
256
  new Resource.TermValue({
257
+ dataFactory: this.dataFactory,
249
258
  focusResource: this,
250
259
  predicate: rdf.first,
251
260
  term: firstObject,
252
261
  }),
253
- ]).chain((items) => new Resource(this.dataset, restObject)
254
- .toList()
262
+ ]).chain((items) => new Resource(this.dataset, restObject, {
263
+ dataFactory: this.dataFactory,
264
+ graph,
265
+ })
266
+ .toList({ graph })
255
267
  .map((restItems) => items.concat(restItems)));
256
268
  }
257
269
  /**
258
270
  * Get the first matching value of dataset statements (this.identifier, predicate, value).
259
271
  */
260
- value(predicate) {
261
- return this.values(predicate).head();
272
+ value(predicate, options) {
273
+ return this.values(predicate, options).head();
262
274
  }
263
275
  /**
264
276
  * Get the first matching subject of dataset statements (subject, predicate, this.identifier).
265
277
  */
266
- valueOf(predicate) {
267
- return this.valuesOf(predicate).head();
278
+ valueOf(predicate, options) {
279
+ return this.valuesOf(predicate, options).head();
268
280
  }
269
281
  /**
270
282
  * Get all values of dataset statements (this.identifier, predicate, value).
271
283
  */
272
284
  values(predicate, options) {
273
285
  return new DatasetObjectValues({
286
+ dataFactory: this.dataFactory,
274
287
  focusResource: this,
288
+ graph: options?.graph ?? this.graph ?? null,
275
289
  predicate,
276
290
  unique: !!options?.unique,
277
291
  });
@@ -281,7 +295,9 @@ export class Resource {
281
295
  */
282
296
  valuesOf(predicate, options) {
283
297
  return new DatasetSubjectValues({
298
+ dataFactory: this.dataFactory,
284
299
  focusResource: this,
300
+ graph: options?.graph ?? this.graph ?? null,
285
301
  predicate,
286
302
  unique: !!options?.unique,
287
303
  });
@@ -6,17 +6,21 @@ import { Resource } from "./Resource.js";
6
6
  export declare class ResourceSet {
7
7
  readonly dataset: DatasetCore;
8
8
  private readonly dataFactory;
9
+ private readonly graph?;
9
10
  constructor(dataset: DatasetCore, options?: {
10
11
  dataFactory?: DataFactory;
12
+ graph?: Exclude<Quad_Graph, Variable>;
11
13
  });
12
14
  instancesOf(class_: NamedNode, options?: {
13
15
  excludeSubclasses?: boolean;
14
- graph?: Exclude<Quad_Graph, Variable> | null;
16
+ graph?: Exclude<Quad_Graph, Variable>;
15
17
  instanceOfPredicate?: NamedNode;
16
18
  subClassOfPredicate?: NamedNode;
17
19
  }): Generator<Resource>;
18
20
  namedInstancesOf(class_: NamedNode, options?: Parameters<ResourceSet["instancesOf"]>[1]): Generator<Resource<NamedNode>>;
19
- resource<IdentifierT extends Resource.Identifier>(identifier: IdentifierT): Resource<IdentifierT>;
21
+ resource<IdentifierT extends Resource.Identifier>(identifier: IdentifierT, options?: {
22
+ graph?: Exclude<Quad_Graph, Variable>;
23
+ }): Resource<IdentifierT>;
20
24
  private instanceIdentifiers;
21
25
  }
22
26
  //# sourceMappingURL=ResourceSet.d.ts.map
@@ -9,6 +9,7 @@ export class ResourceSet {
9
9
  constructor(dataset, options) {
10
10
  this.dataset = dataset;
11
11
  this.dataFactory = options?.dataFactory ?? DefaultDataFactory;
12
+ this.graph = options?.graph;
12
13
  }
13
14
  *instancesOf(class_, options) {
14
15
  for (const identifier of this.instanceIdentifiers(class_, options)) {
@@ -18,24 +19,26 @@ export class ResourceSet {
18
19
  *namedInstancesOf(class_, options) {
19
20
  for (const identifier of this.instanceIdentifiers(class_, options)) {
20
21
  if (identifier.termType === "NamedNode")
21
- yield this.resource(identifier);
22
+ yield this.resource(identifier, { graph: options?.graph });
22
23
  }
23
24
  }
24
- resource(identifier) {
25
+ resource(identifier, options) {
25
26
  return new Resource(this.dataset, identifier, {
26
27
  dataFactory: this.dataFactory,
28
+ graph: options?.graph ?? this.graph,
27
29
  });
28
30
  }
29
31
  *instanceIdentifiers(class_, options) {
30
32
  yield* instanceIdentifiersRecursive({
31
33
  class_,
32
34
  dataset: this.dataset,
35
+ graph: options?.graph ?? this.graph,
33
36
  visitedClasses: new TermSet(),
34
37
  yieldedInstanceIdentifiers: new TermSet(),
35
38
  });
36
- function* instanceIdentifiersRecursive({ class_, dataset, visitedClasses, yieldedInstanceIdentifiers, }) {
39
+ function* instanceIdentifiersRecursive({ class_, dataset, graph, visitedClasses, yieldedInstanceIdentifiers, }) {
37
40
  // Get instanceQuads of the class
38
- for (const quad of dataset.match(null, options?.instanceOfPredicate ?? rdf.type, class_, options?.graph)) {
41
+ for (const quad of dataset.match(null, options?.instanceOfPredicate ?? rdf.type, class_, graph)) {
39
42
  switch (quad.subject.termType) {
40
43
  case "BlankNode":
41
44
  case "NamedNode":
@@ -53,7 +56,7 @@ export class ResourceSet {
53
56
  return;
54
57
  }
55
58
  // Recurse into class's sub-classes that haven't been visited yet.
56
- for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, options?.graph)) {
59
+ for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
57
60
  if (quad.subject.termType !== "NamedNode") {
58
61
  continue;
59
62
  }
@@ -63,6 +66,7 @@ export class ResourceSet {
63
66
  yield* instanceIdentifiersRecursive({
64
67
  class_: quad.subject,
65
68
  dataset,
69
+ graph,
66
70
  visitedClasses,
67
71
  yieldedInstanceIdentifiers,
68
72
  });
@@ -1,4 +1,4 @@
1
- import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
1
+ import type { BlankNode, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
2
2
  import { Either } from "purify-ts";
3
3
  import { AbstractTermValue } from "./AbstractTermValue.js";
4
4
  import type { Identifier } from "./Identifier.js";
@@ -42,7 +42,9 @@ export declare class TermValue extends AbstractTermValue<BlankNode | Literal | N
42
42
  /**
43
43
  * Try to convert the term to an RDF list.
44
44
  */
45
- toList(): Either<ValueError, readonly TermValue[]>;
45
+ toList(options?: {
46
+ graph?: Exclude<Quad_Graph, Variable>;
47
+ }): Either<ValueError, readonly TermValue[]>;
46
48
  /**
47
49
  * Try to convert the term to a Literal.
48
50
  */
@@ -58,7 +60,9 @@ export declare class TermValue extends AbstractTermValue<BlankNode | Literal | N
58
60
  /**
59
61
  * Try to convert the term to a resource (identified by a blank node or IRI).
60
62
  */
61
- toResource(): Either<MistypedTermValueError, Resource>;
63
+ toResource(options?: {
64
+ graph?: Exclude<Quad_Graph, Variable>;
65
+ }): Either<MistypedTermValueError, Resource>;
62
66
  /**
63
67
  * Try to convert the term to a string literal.
64
68
  */
package/dist/TermValue.js CHANGED
@@ -70,8 +70,8 @@ export class TermValue extends AbstractTermValue {
70
70
  /**
71
71
  * Try to convert the term to an RDF list.
72
72
  */
73
- toList() {
74
- return this.toResource().chain((resource) => resource.toList());
73
+ toList(options) {
74
+ return this.toResource({ graph: options?.graph }).chain((resource) => resource.toList({ graph: options?.graph }));
75
75
  }
76
76
  /**
77
77
  * Try to convert the term to a Literal.
@@ -100,8 +100,11 @@ export class TermValue extends AbstractTermValue {
100
100
  /**
101
101
  * Try to convert the term to a resource (identified by a blank node or IRI).
102
102
  */
103
- toResource() {
104
- return this.toIdentifier().map((identifier) => new Resource(this.focusResource.dataset, identifier));
103
+ toResource(options) {
104
+ return this.toIdentifier().map((identifier) => new Resource(this.focusResource.dataset, identifier, {
105
+ dataFactory: this.dataFactory,
106
+ graph: options?.graph,
107
+ }));
105
108
  }
106
109
  /**
107
110
  * Try to convert the term to a string literal.
package/package.json CHANGED
@@ -10,12 +10,12 @@
10
10
  "description": "Resource abstraction over RDF/JS Datasets",
11
11
  "devDependencies": {
12
12
  "@biomejs/biome": "2.3.10",
13
+ "@rdfjs/dataset": "~2.0.2",
13
14
  "@tpluscode/rdf-ns-builders": "~4.3.0",
14
15
  "@tsconfig/strictest": "~2.0.8",
15
- "@types/n3": "~1.26.1",
16
+ "@types/rdfjs__dataset": "~2.0.7",
16
17
  "@vitest/coverage-v8": "~4.0.18",
17
18
  "housemd": "0.1.3",
18
- "n3": "~1.26.0",
19
19
  "rimraf": "~6.0.1",
20
20
  "typescript": "5.9.3",
21
21
  "vitest": "~4.0.18"
@@ -46,5 +46,5 @@
46
46
  },
47
47
  "type": "module",
48
48
  "types": "dist/index.d.ts",
49
- "version": "2.0.5"
49
+ "version": "2.0.6"
50
50
  }