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:
committed by
Joachim Van Herwegen
parent
85e3117efe
commit
ee3b847033
@@ -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)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user