mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Introduce TEXT_TURTLE constant
This commit is contained in:
parent
85e3117efe
commit
ee3b847033
@ -2,6 +2,7 @@ import streamifyArray from 'streamify-array';
|
||||
import { AclManager } from '../authorization/AclManager';
|
||||
import { ExpressHttpServer } from '../server/ExpressHttpServer';
|
||||
import { ResourceStore } from '../storage/ResourceStore';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { RuntimeConfig, RuntimeConfigData } from './RuntimeConfig';
|
||||
|
||||
/**
|
||||
@ -56,7 +57,7 @@ export class Setup {
|
||||
metadata: {
|
||||
raw: [],
|
||||
profiles: [],
|
||||
contentType: 'text/turtle',
|
||||
contentType: TEXT_TURTLE,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
@ -3,6 +3,7 @@ import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../init/RuntimeConfig';
|
||||
import { Representation } from '../ldp/representation/Representation';
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { ensureTrailingSlash } from '../util/Util';
|
||||
import { ResourceStore } from './ResourceStore';
|
||||
@ -28,7 +29,7 @@ export class InMemoryResourceStore implements ResourceStore {
|
||||
'': {
|
||||
binary: true,
|
||||
data: streamifyArray([]),
|
||||
metadata: { raw: [], profiles: [], contentType: 'text/turtle' },
|
||||
metadata: { raw: [], profiles: [], contentType: TEXT_TURTLE },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { StreamWriter } from 'n3';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { INTERNAL_QUADS, TEXT_TURTLE } from '../../util/ContentTypes';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
@ -10,7 +10,7 @@ import { RepresentationConverter, RepresentationConverterArgs } from './Represen
|
||||
*/
|
||||
export class QuadToTurtleConverter extends RepresentationConverter {
|
||||
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
|
||||
checkRequest(input, [ INTERNAL_QUADS ], [ 'text/turtle' ]);
|
||||
checkRequest(input, [ INTERNAL_QUADS ], [ TEXT_TURTLE ]);
|
||||
}
|
||||
|
||||
public async handle(input: RepresentationConverterArgs): Promise<Representation> {
|
||||
@ -18,10 +18,10 @@ export class QuadToTurtleConverter extends RepresentationConverter {
|
||||
}
|
||||
|
||||
private quadsToTurtle(quads: Representation): Representation {
|
||||
const metadata: RepresentationMetadata = { ...quads.metadata, contentType: 'text/turtle' };
|
||||
const metadata: RepresentationMetadata = { ...quads.metadata, contentType: TEXT_TURTLE };
|
||||
return {
|
||||
binary: true,
|
||||
data: quads.data.pipe(new StreamWriter({ format: 'text/turtle' })),
|
||||
data: quads.data.pipe(new StreamWriter({ format: TEXT_TURTLE })),
|
||||
metadata,
|
||||
};
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import { PassThrough } from 'stream';
|
||||
import { StreamParser } from 'n3';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { TEXT_TURTLE, INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
@ -12,7 +12,7 @@ import { RepresentationConverter, RepresentationConverterArgs } from './Represen
|
||||
*/
|
||||
export class TurtleToQuadConverter extends RepresentationConverter {
|
||||
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
|
||||
checkRequest(input, [ 'text/turtle' ], [ INTERNAL_QUADS ]);
|
||||
checkRequest(input, [ TEXT_TURTLE ], [ INTERNAL_QUADS ]);
|
||||
}
|
||||
|
||||
public async handle(input: RepresentationConverterArgs): Promise<Representation> {
|
||||
@ -25,7 +25,7 @@ export class TurtleToQuadConverter extends RepresentationConverter {
|
||||
// Catch parsing errors and emit correct error
|
||||
// Node 10 requires both writableObjectMode and readableObjectMode
|
||||
const errorStream = new PassThrough({ writableObjectMode: true, readableObjectMode: true });
|
||||
const data = turtle.data.pipe(new StreamParser({ format: 'text/turtle', baseIRI }));
|
||||
const data = turtle.data.pipe(new StreamParser({ format: TEXT_TURTLE, baseIRI }));
|
||||
data.pipe(errorStream);
|
||||
data.on('error', (error): boolean => errorStream.emit('error', new UnsupportedHttpError(error.message)));
|
||||
|
||||
|
@ -1,2 +1,5 @@
|
||||
// Well-known content types
|
||||
export const TEXT_TURTLE = 'text/turtle';
|
||||
|
||||
// Internal (non-exposed) content types
|
||||
export const INTERNAL_QUADS = 'internal/quads';
|
||||
|
@ -4,6 +4,7 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import { DataFactory, StreamParser, StreamWriter } from 'n3';
|
||||
import { NamedNode, Quad } from 'rdf-js';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { LDP, RDF, STAT, TERMS, XML } from './Prefixes';
|
||||
|
||||
export const TYPE_PREDICATE = DataFactory.namedNode(`${RDF}type`);
|
||||
@ -69,7 +70,7 @@ export class MetadataController {
|
||||
* @returns The Readable object.
|
||||
*/
|
||||
public generateReadableFromQuads(quads: Quad[]): Readable {
|
||||
return streamifyArray(quads).pipe(new StreamWriter({ format: 'text/turtle' }));
|
||||
return streamifyArray(quads).pipe(new StreamWriter({ format: TEXT_TURTLE }));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,6 +80,6 @@ export class MetadataController {
|
||||
* @returns A promise containing the array of quads.
|
||||
*/
|
||||
public async generateQuadsFromReadable(readable: Readable): Promise<Quad[]> {
|
||||
return arrayifyStream(readable.pipe(new StreamParser({ format: 'text/turtle' })));
|
||||
return arrayifyStream(readable.pipe(new StreamParser({ format: TEXT_TURTLE })));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user