@rdfx/tinybase 0.0.47 → 0.0.49

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.
@@ -4,18 +4,18 @@ import { Either, Maybe } from "purify-ts";
4
4
  import { type NoValuesSchema, type Store } from "tinybase/with-schemas";
5
5
  import type { Logger } from "ts-log";
6
6
  export declare class TinyBaseGraphStore implements GraphStore {
7
- private readonly dataFactory;
8
- private readonly datasetFactory;
9
- private readonly logger;
7
+ protected readonly dataFactory: DataFactory;
8
+ protected readonly datasetFactory: DatasetCoreFactory;
9
+ protected readonly logger: Logger;
10
10
  readonly tinyBaseStore: TinyBaseGraphStore.TinyBaseStore;
11
- constructor({ dataFactory, datasetFactory, logger, parseGraph, tinyBaseStore, }: {
11
+ constructor({ dataFactory, datasetFactory, logger, tinyBaseStore, }: {
12
12
  dataFactory: DataFactory;
13
13
  datasetFactory: DatasetCoreFactory;
14
14
  logger: Logger;
15
- parseGraph?: (identifier: GraphIdentifier, ntriples: string) => Either<Error, Quad[]>;
16
15
  tinyBaseStore?: TinyBaseGraphStore.TinyBaseStore;
17
16
  });
18
17
  clear(): Promise<Either<Error, object>>;
18
+ clearSync(): Either<Error, object>;
19
19
  delete(identifier: GraphIdentifier): Promise<Either<Error, object>>;
20
20
  deleteSync(identifier: GraphIdentifier): Either<Error, object>;
21
21
  get(identifier: GraphIdentifier): Promise<Either<Error, Maybe<Stream>>>;
@@ -29,8 +29,15 @@ export declare class TinyBaseGraphStore implements GraphStore {
29
29
  isEmptySync(): Either<Error, boolean>;
30
30
  post(quads: Stream): Promise<Either<Error, object>>;
31
31
  put(quads: Stream): Promise<Either<Error, object>>;
32
- private clearSync;
33
- private readonly parseGraph;
32
+ /**
33
+ * Parse the given N-Triples string (which has no graphs specified) into Quads
34
+ * with every Quad's graph set to the given graph identifier.
35
+ *
36
+ * @param identifier graph identifier
37
+ * @param ntriples \n-joined N-Triples string
38
+ * @returns array of Quads
39
+ */
40
+ protected parseRow(identifier: GraphIdentifier, ntriples: string): Either<Error, readonly Quad[]>;
34
41
  }
35
42
  export declare namespace TinyBaseGraphStore {
36
43
  type TinyBaseStore = Store<[typeof tablesSchema, NoValuesSchema]>;
@@ -9,18 +9,10 @@ export class TinyBaseGraphStore {
9
9
  datasetFactory;
10
10
  logger;
11
11
  tinyBaseStore;
12
- constructor({ dataFactory, datasetFactory, logger, parseGraph, tinyBaseStore, }) {
12
+ constructor({ dataFactory, datasetFactory, logger, tinyBaseStore, }) {
13
13
  this.dataFactory = dataFactory;
14
14
  this.datasetFactory = datasetFactory;
15
15
  this.logger = logger;
16
- this.parseGraph =
17
- parseGraph ??
18
- ((identifier, ntriples) => Either.encase(() => {
19
- const parser = new Parser({ format: "application/n-triples" });
20
- // Hack to put the quads in this named graph rather than rewriting them all after parsing.
21
- parser.DEFAULTGRAPH = identifier;
22
- return parser.parse(ntriples);
23
- }));
24
16
  this.tinyBaseStore =
25
17
  tinyBaseStore ??
26
18
  createMergeableStore().setTablesSchema(TinyBaseGraphStore.tablesSchema);
@@ -28,6 +20,12 @@ export class TinyBaseGraphStore {
28
20
  async clear() {
29
21
  return this.clearSync();
30
22
  }
23
+ clearSync() {
24
+ return Either.encase(() => {
25
+ this.tinyBaseStore.delTable("graph");
26
+ return {};
27
+ });
28
+ }
31
29
  async delete(identifier) {
32
30
  return this.deleteSync(identifier);
33
31
  }
@@ -47,7 +45,7 @@ export class TinyBaseGraphStore {
47
45
  if (Object.values(row).length === 0) {
48
46
  return Maybe.empty();
49
47
  }
50
- const parsedQuadsEither = this.parseGraph(identifier, row.ntriples);
48
+ const parsedQuadsEither = this.parseRow(identifier, row.ntriples);
51
49
  if (parsedQuadsEither.isLeft()) {
52
50
  this.logger.warn("error parsing row %s: %s", GraphIdentifier.stringify(identifier), parsedQuadsEither.extract().message);
53
51
  return Maybe.empty();
@@ -62,7 +60,7 @@ export class TinyBaseGraphStore {
62
60
  for (const [rowId, row] of rows) {
63
61
  // this.logger.debug("parsing row %s", rowId);
64
62
  const identifier = GraphIdentifier.parse(this.dataFactory, rowId);
65
- this.parseGraph(identifier, row.ntriples)
63
+ this.parseRow(identifier, row.ntriples)
66
64
  .ifLeft((error) => {
67
65
  this.logger.warn("error parsing row %s: %s", rowId, error.message);
68
66
  })
@@ -163,13 +161,22 @@ export class TinyBaseGraphStore {
163
161
  });
164
162
  });
165
163
  }
166
- clearSync() {
164
+ /**
165
+ * Parse the given N-Triples string (which has no graphs specified) into Quads
166
+ * with every Quad's graph set to the given graph identifier.
167
+ *
168
+ * @param identifier graph identifier
169
+ * @param ntriples \n-joined N-Triples string
170
+ * @returns array of Quads
171
+ */
172
+ parseRow(identifier, ntriples) {
167
173
  return Either.encase(() => {
168
- this.tinyBaseStore.delTable("graph");
169
- return {};
174
+ const parser = new Parser({ format: "application/n-triples" });
175
+ // Hack to put the quads in this named graph rather than rewriting them all after parsing.
176
+ parser.DEFAULTGRAPH = identifier;
177
+ return parser.parse(ntriples);
170
178
  });
171
179
  }
172
- parseGraph;
173
180
  }
174
181
  (function (TinyBaseGraphStore) {
175
182
  TinyBaseGraphStore.tablesSchema = {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "dependencies": {
3
- "@rdfx/graph-store": "0.0.47",
4
- "@rdfx/stream": "0.0.47",
5
- "@rdfx/string": "0.0.47",
3
+ "@rdfx/graph-store": "0.0.49",
4
+ "@rdfx/stream": "0.0.49",
5
+ "@rdfx/string": "0.0.49",
6
6
  "@rdfjs/types": "~2.0.1",
7
7
  "@types/n3": "~1.26.0",
8
8
  "n3": "~1.26.0",
@@ -11,8 +11,8 @@
11
11
  "ts-log": "~3.0.2"
12
12
  },
13
13
  "devDependencies": {
14
- "@rdfx/collection": "0.0.47",
15
- "@rdfx/data-factory": "0.0.47"
14
+ "@rdfx/collection": "0.0.49",
15
+ "@rdfx/data-factory": "0.0.49"
16
16
  },
17
17
  "files": [
18
18
  "LICENSE",
@@ -37,5 +37,5 @@
37
37
  },
38
38
  "type": "module",
39
39
  "types": "./dist/index.d.ts",
40
- "version": "0.0.47"
40
+ "version": "0.0.49"
41
41
  }