@rdfx/parser 0.0.51
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/README.md +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/parse.d.ts +12 -0
- package/dist/parse.js +25 -0
- package/dist/parseSync copy.d.ts +9 -0
- package/dist/parseSync copy.js +9 -0
- package/dist/parseSync.d.ts +10 -0
- package/dist/parseSync.js +9 -0
- package/dist/parsers.d.ts +8 -0
- package/dist/parsers.js +16 -0
- package/dist/testData.d.ts +2 -0
- package/dist/testData.js +2 -0
- package/package.json +39 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ParserOptions as JsonLdParserOptions } from "@rdfjs/parser-jsonld";
|
|
2
|
+
import type { ParserOptions as N3ParserOptions } from "@rdfjs/parser-n3";
|
|
3
|
+
import type { DataFactory, Quad } from "@rdfjs/types";
|
|
4
|
+
import type { UncompressedRdfFormat } from "@rdfx/format";
|
|
5
|
+
import { type PrefixCallback } from "n3";
|
|
6
|
+
import { type Either } from "purify-ts";
|
|
7
|
+
export declare function parse(input: string, { dataFactory, format, prefixCallback, ...otherOptions }: {
|
|
8
|
+
dataFactory: DataFactory;
|
|
9
|
+
format?: UncompressedRdfFormat["mimeType"];
|
|
10
|
+
prefixCallback?: PrefixCallback;
|
|
11
|
+
} & Omit<JsonLdParserOptions & N3ParserOptions, "factory" | "format">): Promise<Either<Error, readonly Quad[]>>;
|
|
12
|
+
//# sourceMappingURL=parse.d.ts.map
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { streamToArray } from "@rdfx/stream";
|
|
2
|
+
import { Parser as SyncN3Parser } from "n3";
|
|
3
|
+
import { EitherAsync } from "purify-ts";
|
|
4
|
+
import { Readable } from "readable-stream";
|
|
5
|
+
import parsers from "./index.js";
|
|
6
|
+
export async function parse(input, { dataFactory, format, prefixCallback, ...otherOptions }) {
|
|
7
|
+
return EitherAsync(async ({ liftEither }) => {
|
|
8
|
+
if (format) {
|
|
9
|
+
const stream = parsers({ ...otherOptions, dataFactory }).import(format, Readable.from([input]));
|
|
10
|
+
if (stream === null) {
|
|
11
|
+
throw new RangeError(`unsupported format: ${format}`);
|
|
12
|
+
}
|
|
13
|
+
return await liftEither(await streamToArray(stream));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
const n3Parser = new SyncN3Parser({
|
|
17
|
+
...otherOptions,
|
|
18
|
+
factory: dataFactory,
|
|
19
|
+
format,
|
|
20
|
+
});
|
|
21
|
+
return n3Parser.parse(input, undefined, prefixCallback);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DataFactory, Quad } from "@rdfjs/types";
|
|
2
|
+
import { type ParserOptions as N3ParserOptions, type PrefixCallback } from "n3";
|
|
3
|
+
import { Either } from "purify-ts";
|
|
4
|
+
export declare function parseSync(input: string, { dataFactory, prefixCallback, ...otherOptions }: {
|
|
5
|
+
dataFactory: DataFactory;
|
|
6
|
+
format?: "application/n-quads" | "application/n-triples" | "application/trig" | "text/n3" | "text/turtle";
|
|
7
|
+
prefixCallback?: PrefixCallback;
|
|
8
|
+
} & Omit<N3ParserOptions, "factory" | "format">): Either<Error, readonly Quad[]>;
|
|
9
|
+
//# sourceMappingURL=parseSync%20copy.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Parser as N3Parser, } from "n3";
|
|
2
|
+
import { Either } from "purify-ts";
|
|
3
|
+
export function parseSync(input, { dataFactory, prefixCallback, ...otherOptions }) {
|
|
4
|
+
return Either.encase(() => {
|
|
5
|
+
const n3Parser = new N3Parser({ ...otherOptions, factory: dataFactory });
|
|
6
|
+
return n3Parser.parse(input, undefined, prefixCallback);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=parseSync%20copy.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DataFactory, Quad } from "@rdfjs/types";
|
|
2
|
+
import type { UncompressedRdfFormat } from "@rdfx/format";
|
|
3
|
+
import { type ParserOptions as N3ParserOptions, type PrefixCallback } from "n3";
|
|
4
|
+
import { Either } from "purify-ts";
|
|
5
|
+
export declare function parseSync(input: string, { dataFactory, prefixCallback, ...otherOptions }: {
|
|
6
|
+
dataFactory: DataFactory;
|
|
7
|
+
format?: Exclude<UncompressedRdfFormat["mimeType"], "application/ld+json">;
|
|
8
|
+
prefixCallback?: PrefixCallback;
|
|
9
|
+
} & Omit<N3ParserOptions, "factory" | "format">): Either<Error, readonly Quad[]>;
|
|
10
|
+
//# sourceMappingURL=parseSync.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Parser as N3Parser, } from "n3";
|
|
2
|
+
import { Either } from "purify-ts";
|
|
3
|
+
export function parseSync(input, { dataFactory, prefixCallback, ...otherOptions }) {
|
|
4
|
+
return Either.encase(() => {
|
|
5
|
+
const n3Parser = new N3Parser({ ...otherOptions, factory: dataFactory });
|
|
6
|
+
return n3Parser.parse(input, undefined, prefixCallback);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=parseSync.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ParserOptions as JsonLdParserOptions } from "@rdfjs/parser-jsonld";
|
|
2
|
+
import { type ParserOptions as N3ParserOptions } from "@rdfjs/parser-n3";
|
|
3
|
+
import SinkMap from "@rdfjs/sink-map";
|
|
4
|
+
import type { DataFactory } from "@rdfjs/types";
|
|
5
|
+
export declare function parsers({ dataFactory, ...otherOptions }: {
|
|
6
|
+
dataFactory: DataFactory;
|
|
7
|
+
} & Omit<JsonLdParserOptions & N3ParserOptions, "factory">): SinkMap<import("events")<[never]>, import("@rdfjs/types").Stream<import("@rdfjs/types").Quad>>;
|
|
8
|
+
//# sourceMappingURL=parsers.d.ts.map
|
package/dist/parsers.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import JsonLdParser from "@rdfjs/parser-jsonld";
|
|
2
|
+
import N3Parser from "@rdfjs/parser-n3";
|
|
3
|
+
import SinkMap from "@rdfjs/sink-map";
|
|
4
|
+
export function parsers({ dataFactory, ...otherOptions }) {
|
|
5
|
+
const options = { ...otherOptions, factory: dataFactory };
|
|
6
|
+
const n3Parser = new N3Parser(options);
|
|
7
|
+
return new SinkMap([
|
|
8
|
+
["application/ld+json", new JsonLdParser(options)],
|
|
9
|
+
["application/trig", n3Parser],
|
|
10
|
+
["application/n-quads", n3Parser],
|
|
11
|
+
["application/n-triples", n3Parser],
|
|
12
|
+
["text/n3", n3Parser],
|
|
13
|
+
["text/turtle", n3Parser],
|
|
14
|
+
]);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=parsers.js.map
|
package/dist/testData.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@rdfx/format": "0.0.51",
|
|
4
|
+
"@rdfx/stream": "0.0.51",
|
|
5
|
+
"@rdfjs/parser-jsonld": "~2.1.3",
|
|
6
|
+
"@rdfjs/parser-n3": "~2.1.0",
|
|
7
|
+
"@rdfjs/sink-map": "~2.0.1",
|
|
8
|
+
"@rdfjs/types": "~2.0.1",
|
|
9
|
+
"@types/rdfjs__parser-jsonld": "~2.1.7",
|
|
10
|
+
"@types/rdfjs__parser-n3": "~2.0.6",
|
|
11
|
+
"purify-ts": "~2.1.4"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {},
|
|
14
|
+
"files": [
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.md",
|
|
17
|
+
"dist/*.d.ts",
|
|
18
|
+
"dist/*.js"
|
|
19
|
+
],
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"name": "@rdfx/parser",
|
|
23
|
+
"packageManager": "npm@11.11.0",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/minorg/rdfx.git"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -b",
|
|
30
|
+
"clean": "rimraf dist",
|
|
31
|
+
"depcheck": "depcheck --ignores=\"@tsconfig/*,vitest,vitest-fetch-mock\" .",
|
|
32
|
+
"dev": "tsc -w --preserveWatchOutput",
|
|
33
|
+
"dev:tests": "tsc -p __tests__ -w --preserveWatchOutput",
|
|
34
|
+
"test": "cd ../.. && vitest run packages/parser/__tests__"
|
|
35
|
+
},
|
|
36
|
+
"type": "module",
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"version": "0.0.51"
|
|
39
|
+
}
|