mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Replace dataType by binary flag
This commit is contained in:
committed by
Joachim Van Herwegen
parent
385e1a4cdf
commit
c5c5d13570
@@ -9,7 +9,7 @@ import { RuntimeConfig } from '../init/RuntimeConfig';
|
||||
import { Representation } from '../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../ldp/representation/RepresentationMetadata';
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../util/ContentTypes';
|
||||
import { ConflictHttpError } from '../util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
@@ -59,7 +59,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
* @returns The newly generated identifier.
|
||||
*/
|
||||
public async addResource(container: ResourceIdentifier, representation: Representation): Promise<ResourceIdentifier> {
|
||||
if (representation.dataType !== DATA_TYPE_BINARY) {
|
||||
if (!representation.binary) {
|
||||
throw new UnsupportedMediaTypeHttpError('FileResourceStore only supports binary representations.');
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
* @param representation - New Representation.
|
||||
*/
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation): Promise<void> {
|
||||
if (representation.dataType !== DATA_TYPE_BINARY) {
|
||||
if (!representation.binary) {
|
||||
throw new UnsupportedMediaTypeHttpError('FileResourceStore only supports binary representations.');
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
if (contentType) {
|
||||
metadata.contentType = contentType;
|
||||
}
|
||||
return { metadata, data: readStream, dataType: DATA_TYPE_BINARY };
|
||||
return { metadata, data: readStream, binary: true };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -295,7 +295,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
}
|
||||
|
||||
return {
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: streamifyArray(quads),
|
||||
metadata: {
|
||||
raw: rawMetadata,
|
||||
|
||||
@@ -3,7 +3,6 @@ import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../init/RuntimeConfig';
|
||||
import { Representation } from '../ldp/representation/Representation';
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { DATA_TYPE_BINARY } from '../util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { ensureTrailingSlash } from '../util/Util';
|
||||
import { ResourceStore } from './ResourceStore';
|
||||
@@ -27,7 +26,7 @@ export class InMemoryResourceStore implements ResourceStore {
|
||||
this.store = {
|
||||
// Default root entry (what you get when the identifier is equal to the base)
|
||||
'': {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: streamifyArray([]),
|
||||
metadata: { raw: [], profiles: [], contentType: 'text/turtle' },
|
||||
},
|
||||
@@ -132,7 +131,7 @@ export class InMemoryResourceStore implements ResourceStore {
|
||||
private async copyRepresentation(source: Representation): Promise<Representation> {
|
||||
const arr = await arrayifyStream(source.data);
|
||||
return {
|
||||
dataType: source.dataType,
|
||||
binary: source.binary,
|
||||
data: streamifyArray([ ...arr ]),
|
||||
metadata: source.metadata,
|
||||
};
|
||||
@@ -152,7 +151,7 @@ export class InMemoryResourceStore implements ResourceStore {
|
||||
source.data = streamifyArray([ ...arr ]);
|
||||
|
||||
return {
|
||||
dataType: source.dataType,
|
||||
binary: source.binary,
|
||||
data: streamifyArray([ ...arr ]),
|
||||
metadata: source.metadata,
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import rdfSerializer from 'rdf-serialize';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
|
||||
import { checkRequest, matchingTypes } from './ConversionUtil';
|
||||
import { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
@@ -32,7 +32,7 @@ export class QuadToRdfConverter extends TypedRepresentationConverter {
|
||||
const contentType = matchingTypes(preferences, await rdfSerializer.getContentTypes())[0].value;
|
||||
const metadata: RepresentationMetadata = { ...quads.metadata, contentType };
|
||||
return {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: rdfSerializer.serialize(quads.data, { contentType }) as Readable,
|
||||
metadata,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { StreamWriter } from 'n3';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
@@ -20,7 +20,7 @@ export class QuadToTurtleConverter extends RepresentationConverter {
|
||||
private quadsToTurtle(quads: Representation): Representation {
|
||||
const metadata: RepresentationMetadata = { ...quads.metadata, contentType: 'text/turtle' };
|
||||
return {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: quads.data.pipe(new StreamWriter({ format: 'text/turtle' })),
|
||||
metadata,
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import { PassThrough } from 'stream';
|
||||
import rdfParser from 'rdf-parse';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
@@ -42,7 +42,7 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
|
||||
data.on('error', (error): boolean => errorStream.emit('error', new UnsupportedHttpError(error.message)));
|
||||
|
||||
return {
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: errorStream,
|
||||
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 { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
@@ -30,7 +30,7 @@ export class TurtleToQuadConverter extends RepresentationConverter {
|
||||
data.on('error', (error): boolean => errorStream.emit('error', new UnsupportedHttpError(error.message)));
|
||||
|
||||
return {
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: errorStream,
|
||||
metadata,
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Algebra } from 'sparqlalgebrajs';
|
||||
import { SparqlUpdatePatch } from '../../ldp/http/SparqlUpdatePatch';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { ResourceLocker } from '../ResourceLocker';
|
||||
import { ResourceStore } from '../ResourceStore';
|
||||
@@ -66,8 +66,8 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
store.removeQuads(deletes);
|
||||
store.addQuads(inserts);
|
||||
const representation: Representation = {
|
||||
binary: false,
|
||||
data: store.match() as Readable,
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
raw: [],
|
||||
profiles: [],
|
||||
|
||||
Reference in New Issue
Block a user