@rdfx/graph-store 0.0.45 → 0.0.46

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,8 +1,9 @@
1
- import type { DefaultGraph, NamedNode, Quad_Graph } from "@rdfjs/types";
1
+ import type { DataFactory, DefaultGraph, NamedNode, Quad_Graph } from "@rdfjs/types";
2
2
  import { Either } from "purify-ts";
3
3
  export type GraphIdentifier = DefaultGraph | NamedNode;
4
4
  export declare namespace GraphIdentifier {
5
5
  function fromQuadGraph(quadGraph: Quad_Graph): Either<Error, GraphIdentifier>;
6
+ function parse(dataFactory: DataFactory, graphIdentifier: string): GraphIdentifier;
6
7
  function stringify(graphIdentifier: GraphIdentifier): string;
7
8
  }
8
9
  //# sourceMappingURL=GraphIdentifier.d.ts.map
@@ -11,6 +11,13 @@ export var GraphIdentifier;
11
11
  }
12
12
  }
13
13
  GraphIdentifier.fromQuadGraph = fromQuadGraph;
14
+ function parse(dataFactory, graphIdentifier) {
15
+ if (graphIdentifier.length === 0) {
16
+ return dataFactory.defaultGraph();
17
+ }
18
+ return dataFactory.namedNode(graphIdentifier);
19
+ }
20
+ GraphIdentifier.parse = parse;
14
21
  function stringify(graphIdentifier) {
15
22
  return graphIdentifier.value;
16
23
  }
@@ -6,14 +6,21 @@ import type { GraphStore } from "./GraphStore.js";
6
6
  * A GraphStore implementation backed by an RDF/JS Dataset.
7
7
  */
8
8
  export declare class RdfjsDatasetGraphStore implements GraphStore {
9
- protected readonly dataset: DatasetCore;
9
+ readonly dataset: DatasetCore;
10
10
  constructor(dataset: DatasetCore);
11
11
  clear(): Promise<Either<Error, object>>;
12
+ clearSync(): Either<Error, object>;
12
13
  delete(identifier: GraphIdentifier): Promise<Either<Error, object>>;
14
+ deleteSync(identifier: GraphIdentifier): Either<Error, object>;
15
+ get(identifier: GraphIdentifier): Promise<Either<Error, Maybe<Stream>>>;
16
+ getDatasetSync(identifier: GraphIdentifier): Either<Error, Maybe<DatasetCore>>;
17
+ getStreamSync(identifier: GraphIdentifier): Either<Error, Maybe<Stream>>;
13
18
  head(identifier: GraphIdentifier): Promise<Either<Error, boolean>>;
19
+ headSync(identifier: GraphIdentifier): Either<Error, boolean>;
14
20
  identifiers(): Promise<Either<Error, readonly GraphIdentifier[]>>;
21
+ identifiersSync(): Either<Error, readonly GraphIdentifier[]>;
15
22
  isEmpty(): Promise<Either<Error, boolean>>;
16
- get(identifier: GraphIdentifier): Promise<Either<Error, Maybe<Stream>>>;
23
+ isEmptySync(): Either<Error, boolean>;
17
24
  post(quads: Stream): Promise<Either<Error, object>>;
18
25
  put(quads: Stream): Promise<Either<Error, object>>;
19
26
  }
@@ -1,5 +1,5 @@
1
1
  import { iterableToStream } from "@rdfx/stream";
2
- import { Either, EitherAsync, Maybe } from "purify-ts";
2
+ import { Either, Left, Maybe } from "purify-ts";
3
3
  import { GraphIdentifier } from "./GraphIdentifier.js";
4
4
  /**
5
5
  * A GraphStore implementation backed by an RDF/JS Dataset.
@@ -10,7 +10,10 @@ export class RdfjsDatasetGraphStore {
10
10
  this.dataset = dataset;
11
11
  }
12
12
  async clear() {
13
- return EitherAsync(async () => {
13
+ return this.clearSync();
14
+ }
15
+ clearSync() {
16
+ return Either.encase(() => {
14
17
  for (const quad of this.dataset) {
15
18
  this.dataset.delete(quad);
16
19
  }
@@ -18,15 +21,35 @@ export class RdfjsDatasetGraphStore {
18
21
  });
19
22
  }
20
23
  async delete(identifier) {
21
- return EitherAsync(async () => {
24
+ return this.deleteSync(identifier);
25
+ }
26
+ deleteSync(identifier) {
27
+ return Either.encase(() => {
22
28
  for (const quad of this.dataset.match(null, null, null, identifier)) {
23
29
  this.dataset.delete(quad);
24
30
  }
25
31
  return {};
26
32
  });
27
33
  }
34
+ async get(identifier) {
35
+ return this.getStreamSync(identifier);
36
+ }
37
+ getDatasetSync(identifier) {
38
+ return Either.encase(() => {
39
+ for (const _ of this.dataset.match(null, null, null, identifier)) {
40
+ return Maybe.of(this.dataset.match(null, null, null, identifier));
41
+ }
42
+ return Maybe.empty();
43
+ });
44
+ }
45
+ getStreamSync(identifier) {
46
+ return this.getDatasetSync(identifier).map((datasetMaybe) => datasetMaybe.map(iterableToStream));
47
+ }
28
48
  async head(identifier) {
29
- return EitherAsync(async () => {
49
+ return this.headSync(identifier);
50
+ }
51
+ headSync(identifier) {
52
+ return Either.encase(() => {
30
53
  for (const _ of this.dataset.match(null, null, null, identifier)) {
31
54
  return true;
32
55
  }
@@ -34,7 +57,10 @@ export class RdfjsDatasetGraphStore {
34
57
  });
35
58
  }
36
59
  async identifiers() {
37
- return EitherAsync(async () => {
60
+ return this.identifiersSync();
61
+ }
62
+ identifiersSync() {
63
+ return Either.encase(() => {
38
64
  const identifiers = new Map();
39
65
  for (const quad of this.dataset.match()) {
40
66
  switch (quad.graph.termType) {
@@ -50,23 +76,23 @@ export class RdfjsDatasetGraphStore {
50
76
  });
51
77
  }
52
78
  async isEmpty() {
53
- return Either.of(this.dataset.size === 0);
79
+ return this.isEmptySync();
54
80
  }
55
- async get(identifier) {
56
- for (const _ of this.dataset.match(null, null, null, identifier)) {
57
- return Either.of(Maybe.of(iterableToStream(this.dataset.match(null, null, null, identifier))));
58
- }
59
- return Either.of(Maybe.empty());
81
+ isEmptySync() {
82
+ return Either.of(this.dataset.size === 0);
60
83
  }
61
84
  async post(quads) {
62
85
  return new Promise((resolve) => {
63
- quads.on("data", (quad) => {
86
+ quads
87
+ .on("data", (quad) => {
64
88
  this.dataset.add(quad);
65
- });
66
- quads.on("end", () => {
89
+ })
90
+ .on("end", () => {
67
91
  resolve(Either.of({}));
92
+ })
93
+ .on("error", (error) => {
94
+ resolve(Left(error));
68
95
  });
69
- quads.on("error", (error) => resolve(Either.of(error)));
70
96
  });
71
97
  }
72
98
  async put(quads) {
@@ -85,7 +111,7 @@ export class RdfjsDatasetGraphStore {
85
111
  quads.on("end", () => {
86
112
  resolve(Either.of({}));
87
113
  });
88
- quads.on("error", (error) => resolve(Either.of(error)));
114
+ quads.on("error", (error) => resolve(Left(error)));
89
115
  });
90
116
  }
91
117
  }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "dependencies": {
3
- "@rdfx/stream": "0.0.45",
3
+ "@rdfx/stream": "0.0.46",
4
4
  "@rdfjs/types": "~2.0.1",
5
5
  "purify-ts": "~2.1.4",
6
6
  "ts-log": "~3.0.2"
7
7
  },
8
8
  "devDependencies": {
9
- "@rdfx/collection": "0.0.45",
10
- "@rdfx/data-factory": "0.0.45",
11
- "@rdfx/testing": "0.0.45"
9
+ "@rdfx/collection": "0.0.46",
10
+ "@rdfx/data-factory": "0.0.46",
11
+ "@rdfx/testing": "0.0.46"
12
12
  },
13
13
  "files": [
14
14
  "LICENSE",
@@ -33,5 +33,5 @@
33
33
  },
34
34
  "type": "module",
35
35
  "types": "./dist/index.d.ts",
36
- "version": "0.0.45"
36
+ "version": "0.0.46"
37
37
  }