Skip to content

Commit 6f0df2b

Browse files
authoredMar 30, 2023
Expose all supported mappings
1 parent 25088ff commit 6f0df2b

File tree

6 files changed

+306
-27
lines changed

6 files changed

+306
-27
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ coverage
2121
documentation
2222
engine-default.js
2323
components
24+
lib/mediaMappings.ts

‎lib/RdfParser.ts

+2-21
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,13 @@ import { ActionContext, Actor } from "@comunica/core";
22
import * as RDF from "@rdfjs/types";
33
import { Readable, PassThrough } from "readable-stream";
44
import { MediatorRdfParseHandle, MediatorRdfParseMediaTypes } from '@comunica/bus-rdf-parse';
5+
import mediaMappings from "./mediaMappings";
56

67
/**
78
* An RdfParser can parse any RDF serialization, based on a given content type.
89
*/
910
export class RdfParser<Q extends RDF.BaseQuad = RDF.Quad> {
10-
11-
// tslint:disable:object-literal-sort-keys
12-
public static readonly CONTENT_MAPPINGS: { [id: string]: string } = {
13-
ttl : "text/turtle",
14-
turtle : "text/turtle",
15-
nt : "application/n-triples",
16-
ntriples : "application/n-triples",
17-
nq : "application/n-quads",
18-
nquads : "application/n-quads",
19-
rdf : "application/rdf+xml",
20-
rdfxml : "application/rdf+xml",
21-
owl : "application/rdf+xml",
22-
n3 : "text/n3",
23-
shc : "text/shaclc",
24-
shaclc : "text/shaclc",
25-
shce : "text/shaclc-ext",
26-
shaclce : "text/shaclc-ext",
27-
trig : "application/trig",
28-
jsonld : "application/ld+json",
29-
json : "application/ld+json",
30-
};
11+
public static readonly CONTENT_MAPPINGS: Record<string, string> = mediaMappings;
3112

3213
public readonly mediatorRdfParseMediatypes: MediatorRdfParseMediaTypes;
3314
public readonly mediatorRdfParseHandle: MediatorRdfParseHandle;

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
"manual-git-changelog": "^1.0.1",
4444
"pre-commit": "^1.2.2",
4545
"rdf-data-factory": "^1.1.0",
46+
"rdf-dereference": "^2.1.0",
4647
"rdf-quad": "^1.5.0",
4748
"rdf-test-suite": "^1.18.0",
4849
"streamify-string": "^1.0.1",
4950
"ts-jest": "^29.0.0",
51+
"ts-node": "^10.9.1",
5052
"tslint": "^6.0.0",
5153
"tslint-eslint-rules": "^5.3.1",
5254
"typescript": "^4.0.0"
@@ -75,8 +77,9 @@
7577
"test": "jest ${1} --forceExit",
7678
"test-watch": "jest ${1} --watch",
7779
"lint": "tslint lib/index.ts lib/**/*.ts test/**/*.ts --exclude '**/*.d.ts'",
78-
"build": "npm run build:ts && npm run build:components",
80+
"build": "rm -rf lib/mediaMappings.* && npm run build:mediaMappings && npm run build:ts && npm run build:components",
7981
"build:ts": "tsc",
82+
"build:mediaMappings": "ts-node scripts/getMediaMappings",
8083
"build:components": "componentsjs-generator",
8184
"validate": "npm ls",
8285
"prepare": "npm run build && comunica-compile-config config/config-default.json urn:comunica:default:Runner > engine-default.js",

‎scripts/getMediaMappings.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import rdfDereference from 'rdf-dereference';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
const mediaMappings: Record<string, string> = (<any> rdfDereference.mediatorDereferenceRdf.bus).actors[0].mediaMappings;
6+
7+
fs.writeFileSync(
8+
path.join(__dirname, '..', 'lib', 'mediaMappings.ts'),
9+
// This json override is here for backwards compatibility and may
10+
// be removed in a major version bump
11+
// @see https://github.com/rubensworks/rdf-parse.js/pull/51#issuecomment-1439977639
12+
`export default ${JSON.stringify({ ...mediaMappings, json: "application/ld+json" }, null, 2)};\n`
13+
);

‎tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
],
2929
"exclude": [
3030
"**/node_modules",
31-
"**/test/*"
31+
"**/test/*",
32+
"lib/mediaMappings.ts"
3233
]
3334
}

‎yarn.lock

+284-4
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.