@rdfx/tinybase 0.0.48 → 0.0.50
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.
- package/dist/TinyBaseGraphStore.d.ts +10 -11
- package/dist/TinyBaseGraphStore.js +19 -12
- package/package.json +6 -6
|
@@ -7,21 +7,11 @@ export declare class TinyBaseGraphStore implements GraphStore {
|
|
|
7
7
|
protected readonly dataFactory: DataFactory;
|
|
8
8
|
protected readonly datasetFactory: DatasetCoreFactory;
|
|
9
9
|
protected readonly logger: Logger;
|
|
10
|
-
protected readonly parseGraph: (identifier: GraphIdentifier, ntriples: string) => Either<Error, readonly Quad[]>;
|
|
11
10
|
readonly tinyBaseStore: TinyBaseGraphStore.TinyBaseStore;
|
|
12
|
-
constructor({ dataFactory, datasetFactory, logger,
|
|
11
|
+
constructor({ dataFactory, datasetFactory, logger, tinyBaseStore, }: {
|
|
13
12
|
dataFactory: DataFactory;
|
|
14
13
|
datasetFactory: DatasetCoreFactory;
|
|
15
14
|
logger: Logger;
|
|
16
|
-
/**
|
|
17
|
-
* Function to parse the given N-Triples string (in the default graph) into Quads
|
|
18
|
-
* with every Quad's graph set to the given graph identifier.
|
|
19
|
-
*
|
|
20
|
-
* @param identifier graph identifier
|
|
21
|
-
* @param ntriples \n-joined N-Triples string
|
|
22
|
-
* @returns array of Quads
|
|
23
|
-
*/
|
|
24
|
-
parseGraph?: (identifier: GraphIdentifier, ntriples: string) => Either<Error, readonly Quad[]>;
|
|
25
15
|
tinyBaseStore?: TinyBaseGraphStore.TinyBaseStore;
|
|
26
16
|
});
|
|
27
17
|
clear(): Promise<Either<Error, object>>;
|
|
@@ -39,6 +29,15 @@ export declare class TinyBaseGraphStore implements GraphStore {
|
|
|
39
29
|
isEmptySync(): Either<Error, boolean>;
|
|
40
30
|
post(quads: Stream): Promise<Either<Error, object>>;
|
|
41
31
|
put(quads: Stream): Promise<Either<Error, object>>;
|
|
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[]>;
|
|
42
41
|
}
|
|
43
42
|
export declare namespace TinyBaseGraphStore {
|
|
44
43
|
type TinyBaseStore = Store<[typeof tablesSchema, NoValuesSchema]>;
|
|
@@ -8,20 +8,11 @@ export class TinyBaseGraphStore {
|
|
|
8
8
|
dataFactory;
|
|
9
9
|
datasetFactory;
|
|
10
10
|
logger;
|
|
11
|
-
parseGraph;
|
|
12
11
|
tinyBaseStore;
|
|
13
|
-
constructor({ dataFactory, datasetFactory, logger,
|
|
12
|
+
constructor({ dataFactory, datasetFactory, logger, tinyBaseStore, }) {
|
|
14
13
|
this.dataFactory = dataFactory;
|
|
15
14
|
this.datasetFactory = datasetFactory;
|
|
16
15
|
this.logger = logger;
|
|
17
|
-
this.parseGraph =
|
|
18
|
-
parseGraph ??
|
|
19
|
-
((identifier, ntriples) => Either.encase(() => {
|
|
20
|
-
const parser = new Parser({ format: "application/n-triples" });
|
|
21
|
-
// Hack to put the quads in this named graph rather than rewriting them all after parsing.
|
|
22
|
-
parser.DEFAULTGRAPH = identifier;
|
|
23
|
-
return parser.parse(ntriples);
|
|
24
|
-
}));
|
|
25
16
|
this.tinyBaseStore =
|
|
26
17
|
tinyBaseStore ??
|
|
27
18
|
createMergeableStore().setTablesSchema(TinyBaseGraphStore.tablesSchema);
|
|
@@ -54,7 +45,7 @@ export class TinyBaseGraphStore {
|
|
|
54
45
|
if (Object.values(row).length === 0) {
|
|
55
46
|
return Maybe.empty();
|
|
56
47
|
}
|
|
57
|
-
const parsedQuadsEither = this.
|
|
48
|
+
const parsedQuadsEither = this.parseRow(identifier, row.ntriples);
|
|
58
49
|
if (parsedQuadsEither.isLeft()) {
|
|
59
50
|
this.logger.warn("error parsing row %s: %s", GraphIdentifier.stringify(identifier), parsedQuadsEither.extract().message);
|
|
60
51
|
return Maybe.empty();
|
|
@@ -69,7 +60,7 @@ export class TinyBaseGraphStore {
|
|
|
69
60
|
for (const [rowId, row] of rows) {
|
|
70
61
|
// this.logger.debug("parsing row %s", rowId);
|
|
71
62
|
const identifier = GraphIdentifier.parse(this.dataFactory, rowId);
|
|
72
|
-
this.
|
|
63
|
+
this.parseRow(identifier, row.ntriples)
|
|
73
64
|
.ifLeft((error) => {
|
|
74
65
|
this.logger.warn("error parsing row %s: %s", rowId, error.message);
|
|
75
66
|
})
|
|
@@ -170,6 +161,22 @@ export class TinyBaseGraphStore {
|
|
|
170
161
|
});
|
|
171
162
|
});
|
|
172
163
|
}
|
|
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) {
|
|
173
|
+
return Either.encase(() => {
|
|
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);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
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.
|
|
4
|
-
"@rdfx/stream": "0.0.
|
|
5
|
-
"@rdfx/string": "0.0.
|
|
3
|
+
"@rdfx/graph-store": "0.0.50",
|
|
4
|
+
"@rdfx/stream": "0.0.50",
|
|
5
|
+
"@rdfx/string": "0.0.50",
|
|
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.
|
|
15
|
-
"@rdfx/data-factory": "0.0.
|
|
14
|
+
"@rdfx/collection": "0.0.50",
|
|
15
|
+
"@rdfx/data-factory": "0.0.50"
|
|
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.
|
|
40
|
+
"version": "0.0.50"
|
|
41
41
|
}
|