@rdfx/fs 0.0.19 → 0.0.21
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/AbstractRdfFileSystemEntry.d.ts +4 -3
- package/dist/AbstractRdfFileSystemEntry.js +4 -3
- package/dist/RdfDirectory.d.ts +2 -0
- package/dist/RdfDirectory.js +1 -1
- package/dist/RdfFile.d.ts +6 -3
- package/dist/RdfFile.js +23 -7
- package/dist/RdfFileSystemEntry.js +1 -1
- package/package.json +3 -3
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
1
2
|
import type { DatasetCore, Quad, Stream } from "@rdfjs/types";
|
|
2
3
|
import type { Either } from "purify-ts";
|
|
3
4
|
import { type Logger } from "ts-log";
|
|
4
5
|
export declare abstract class AbstractRdfFileSystemEntry {
|
|
5
|
-
protected readonly logger: Logger;
|
|
6
6
|
readonly path: string;
|
|
7
|
-
|
|
7
|
+
protected readonly logger: Logger;
|
|
8
|
+
constructor(path: string, options?: {
|
|
8
9
|
logger?: Logger;
|
|
9
|
-
path: string;
|
|
10
10
|
});
|
|
11
11
|
abstract parse(options?: {
|
|
12
12
|
recursive?: boolean;
|
|
13
13
|
}): Stream<Quad>;
|
|
14
14
|
abstract parseInto(dataset: DatasetCore, options?: {
|
|
15
|
+
prefixMap?: PrefixMap;
|
|
15
16
|
recursive?: boolean;
|
|
16
17
|
}): Promise<Either<Error, DatasetCore>>;
|
|
17
18
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { dummyLogger } from "ts-log";
|
|
2
2
|
export class AbstractRdfFileSystemEntry {
|
|
3
|
-
logger;
|
|
4
3
|
path;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
logger;
|
|
5
|
+
constructor(path, options) {
|
|
6
|
+
this.path = path;
|
|
7
|
+
this.logger = options?.logger ?? dummyLogger;
|
|
7
8
|
this.path = path;
|
|
8
9
|
}
|
|
9
10
|
}
|
package/dist/RdfDirectory.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
1
2
|
import type { DatasetCore, Quad, Stream } from "@rdfjs/types";
|
|
2
3
|
import { type Either } from "purify-ts";
|
|
3
4
|
import { AbstractRdfFileSystemEntry } from "./AbstractRdfFileSystemEntry.js";
|
|
@@ -13,6 +14,7 @@ export declare class RdfDirectory extends AbstractRdfFileSystemEntry {
|
|
|
13
14
|
recursive?: boolean;
|
|
14
15
|
}): Stream<Quad>;
|
|
15
16
|
parseInto(dataset: DatasetCore, options?: {
|
|
17
|
+
prefixMap?: PrefixMap;
|
|
16
18
|
recursive?: boolean;
|
|
17
19
|
}): Promise<Either<Error, DatasetCore>>;
|
|
18
20
|
}
|
package/dist/RdfDirectory.js
CHANGED
|
@@ -83,7 +83,7 @@ export class RdfDirectory extends AbstractRdfFileSystemEntry {
|
|
|
83
83
|
async parseInto(dataset, options) {
|
|
84
84
|
return EitherAsync(async ({ liftEither }) => {
|
|
85
85
|
for await (const file of this.files(options)) {
|
|
86
|
-
await liftEither(await file.parseInto(dataset));
|
|
86
|
+
await liftEither(await file.parseInto(dataset, { prefixMap: options?.prefixMap }));
|
|
87
87
|
}
|
|
88
88
|
return dataset;
|
|
89
89
|
});
|
package/dist/RdfFile.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type PrefixMap from "@rdfjs/prefix-map/PrefixMap.js";
|
|
1
2
|
import type { DatasetCore, Quad, Stream } from "@rdfjs/types";
|
|
2
3
|
import { Either, type Maybe } from "purify-ts";
|
|
3
4
|
import type { Logger } from "ts-log";
|
|
@@ -5,14 +6,16 @@ import { AbstractRdfFileSystemEntry } from "./AbstractRdfFileSystemEntry.js";
|
|
|
5
6
|
import { type RdfFormat } from "./RdfFormat.js";
|
|
6
7
|
export declare class RdfFile extends AbstractRdfFileSystemEntry {
|
|
7
8
|
readonly format: RdfFile.Format;
|
|
8
|
-
constructor({ format, ...superParameters }: {
|
|
9
|
+
constructor(path: string, { format, ...superParameters }: {
|
|
9
10
|
format: RdfFile.Format;
|
|
10
|
-
} & ConstructorParameters<typeof AbstractRdfFileSystemEntry>[
|
|
11
|
+
} & ConstructorParameters<typeof AbstractRdfFileSystemEntry>[1]);
|
|
11
12
|
static fromPath(filePath: string, options?: {
|
|
12
13
|
logger?: Logger;
|
|
13
14
|
}): Either<Error, RdfFile>;
|
|
14
15
|
parse(): Stream<Quad>;
|
|
15
|
-
parseInto(dataset: DatasetCore
|
|
16
|
+
parseInto(dataset: DatasetCore, options?: {
|
|
17
|
+
prefixMap?: PrefixMap;
|
|
18
|
+
}): Promise<Either<Error, DatasetCore>>;
|
|
16
19
|
}
|
|
17
20
|
export declare namespace RdfFile {
|
|
18
21
|
const COMPRESSION_METHODS: readonly ["application/gzip", "application/x-brotli", "application/x-bzip2"];
|
package/dist/RdfFile.js
CHANGED
|
@@ -16,8 +16,8 @@ const mime = new Mime(standardMimeTypes, otherMimeTypes, {
|
|
|
16
16
|
});
|
|
17
17
|
export class RdfFile extends AbstractRdfFileSystemEntry {
|
|
18
18
|
format;
|
|
19
|
-
constructor({ format, ...superParameters }) {
|
|
20
|
-
super(superParameters);
|
|
19
|
+
constructor(path, { format, ...superParameters }) {
|
|
20
|
+
super(path, superParameters);
|
|
21
21
|
this.format = format;
|
|
22
22
|
}
|
|
23
23
|
static fromPath(filePath, options) {
|
|
@@ -34,13 +34,12 @@ export class RdfFile extends AbstractRdfFileSystemEntry {
|
|
|
34
34
|
}
|
|
35
35
|
for (const rdfFormat of RDF_FORMATS) {
|
|
36
36
|
if (uncompressedMimeType === rdfFormat) {
|
|
37
|
-
return Right(new RdfFile({
|
|
37
|
+
return Right(new RdfFile(filePath, {
|
|
38
38
|
format: {
|
|
39
39
|
compressionMethod: Just(compressionMethod),
|
|
40
40
|
rdfFormat,
|
|
41
41
|
},
|
|
42
42
|
logger: options?.logger,
|
|
43
|
-
path: filePath,
|
|
44
43
|
}));
|
|
45
44
|
}
|
|
46
45
|
}
|
|
@@ -48,13 +47,12 @@ export class RdfFile extends AbstractRdfFileSystemEntry {
|
|
|
48
47
|
}
|
|
49
48
|
for (const rdfFormat of RDF_FORMATS) {
|
|
50
49
|
if (mimeType === rdfFormat) {
|
|
51
|
-
return Right(new RdfFile({
|
|
50
|
+
return Right(new RdfFile(filePath, {
|
|
52
51
|
format: {
|
|
53
52
|
compressionMethod: Nothing,
|
|
54
53
|
rdfFormat,
|
|
55
54
|
},
|
|
56
55
|
logger: options?.logger,
|
|
57
|
-
path: filePath,
|
|
58
56
|
}));
|
|
59
57
|
}
|
|
60
58
|
}
|
|
@@ -77,10 +75,28 @@ export class RdfFile extends AbstractRdfFileSystemEntry {
|
|
|
77
75
|
}
|
|
78
76
|
return parsers.import(this.format.rdfFormat, rdfFileStream);
|
|
79
77
|
}
|
|
80
|
-
parseInto(dataset) {
|
|
78
|
+
parseInto(dataset, options) {
|
|
81
79
|
return new Promise((resolve) => {
|
|
82
80
|
const stream = this.parse();
|
|
83
81
|
stream.on("data", (quad) => dataset.add(quad));
|
|
82
|
+
stream.on("prefix", (prefix, prefixNode) => {
|
|
83
|
+
const prefixMap = options?.prefixMap;
|
|
84
|
+
if (!prefixMap) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const [existingPrefix, existingPrefixNode,] of prefixMap.entries()) {
|
|
88
|
+
if (existingPrefix === prefix) {
|
|
89
|
+
if (!prefixNode.equals(existingPrefixNode)) {
|
|
90
|
+
this.logger.warn("conflicting prefix %s: %s vs. %s", prefixNode.value, existingPrefixNode.value);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (prefixNode.equals(existingPrefixNode)) {
|
|
95
|
+
this.logger.debug("duplicate prefix %s: %s vs. %s", prefixNode.value, prefix, existingPrefix);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
prefixMap.set(prefix, prefixNode);
|
|
99
|
+
});
|
|
84
100
|
stream.on("end", () => resolve(Either.of(dataset)));
|
|
85
101
|
stream.on("error", (error) => resolve(Left(error)));
|
|
86
102
|
});
|
|
@@ -8,7 +8,7 @@ export var RdfFileSystemEntry;
|
|
|
8
8
|
return EitherAsync(async ({ liftEither }) => {
|
|
9
9
|
const stat_ = await liftEither(await stat(path));
|
|
10
10
|
if (stat_.isDirectory())
|
|
11
|
-
return new RdfDirectory({ logger: options?.logger
|
|
11
|
+
return new RdfDirectory(path, { logger: options?.logger });
|
|
12
12
|
if (stat_.isFile()) {
|
|
13
13
|
return await liftEither(RdfFile.fromPath(path, { logger: options?.logger }));
|
|
14
14
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@rdfx/data-factory": "0.0.
|
|
4
|
-
"@rdfx/parsers": "0.0.
|
|
3
|
+
"@rdfx/data-factory": "0.0.21",
|
|
4
|
+
"@rdfx/parsers": "0.0.21",
|
|
5
5
|
"@rdfjs/types": "~2.0.1",
|
|
6
6
|
"@types/unbzip2-stream": "~1.4.3",
|
|
7
7
|
"mime": "~4.1.0",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
},
|
|
37
37
|
"type": "module",
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
|
-
"version": "0.0.
|
|
39
|
+
"version": "0.0.21"
|
|
40
40
|
}
|