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
2
index.ts
2
index.ts
@@ -47,8 +47,6 @@ export * from './src/ldp/permissions/BasePermissionsExtractor';
|
||||
export * from './src/ldp/permissions/SparqlPatchPermissionsExtractor';
|
||||
|
||||
// LDP/Representation
|
||||
export * from './src/ldp/representation/BinaryRepresentation';
|
||||
export * from './src/ldp/representation/QuadRepresentation';
|
||||
export * from './src/ldp/representation/Representation';
|
||||
export * from './src/ldp/representation/RepresentationMetadata';
|
||||
export * from './src/ldp/representation/RepresentationPreference';
|
||||
|
||||
@@ -2,7 +2,6 @@ import streamifyArray from 'streamify-array';
|
||||
import { AclManager } from '../authorization/AclManager';
|
||||
import { ExpressHttpServer } from '../server/ExpressHttpServer';
|
||||
import { ResourceStore } from '../storage/ResourceStore';
|
||||
import { DATA_TYPE_BINARY } from '../util/ContentTypes';
|
||||
import { RuntimeConfig, RuntimeConfigData } from './RuntimeConfig';
|
||||
|
||||
/**
|
||||
@@ -52,7 +51,7 @@ export class Setup {
|
||||
await this.store.setRepresentation(
|
||||
await this.aclManager.getAcl({ path: this.runtimeConfig.base }),
|
||||
{
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: streamifyArray([ acl ]),
|
||||
metadata: {
|
||||
raw: [],
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { HttpResponse } from '../../server/HttpResponse';
|
||||
import { DATA_TYPE_BINARY } from '../../util/ContentTypes';
|
||||
import { HttpError } from '../../util/errors/HttpError';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { ResponseDescription } from '../operations/ResponseDescription';
|
||||
@@ -12,8 +11,7 @@ import { ResponseWriter } from './ResponseWriter';
|
||||
export class BasicResponseWriter extends ResponseWriter {
|
||||
public async canHandle(input: { response: HttpResponse; result: ResponseDescription | Error }): Promise<void> {
|
||||
if (!(input.result instanceof Error)) {
|
||||
const dataType = input.result.body?.dataType;
|
||||
if (dataType && dataType !== DATA_TYPE_BINARY) {
|
||||
if (input.result.body && !input.result.body.binary) {
|
||||
throw new UnsupportedHttpError('Only binary results are supported.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { HttpRequest } from '../../server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { BinaryRepresentation } from '../representation/BinaryRepresentation';
|
||||
import { Representation } from '../representation/Representation';
|
||||
import { RepresentationMetadata } from '../representation/RepresentationMetadata';
|
||||
import { BodyParser } from './BodyParser';
|
||||
|
||||
@@ -17,13 +16,13 @@ export class RawBodyParser extends BodyParser {
|
||||
|
||||
// Note that the only reason this is a union is in case the body is empty.
|
||||
// If this check gets moved away from the BodyParsers this union could be removed
|
||||
public async handle(input: HttpRequest): Promise<BinaryRepresentation | undefined> {
|
||||
public async handle(input: HttpRequest): Promise<Representation | undefined> {
|
||||
if (!input.headers['content-type']) {
|
||||
return;
|
||||
}
|
||||
|
||||
return {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: input,
|
||||
metadata: this.parseMetadata(input),
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { PassThrough } from 'stream';
|
||||
import { translate } from 'sparqlalgebrajs';
|
||||
import { HttpRequest } from '../../server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../util/errors/UnsupportedMediaTypeHttpError';
|
||||
import { readableToString } from '../../util/Util';
|
||||
@@ -37,7 +36,7 @@ export class SparqlUpdateBodyParser extends BodyParser {
|
||||
// Prevent body from being requested again
|
||||
return {
|
||||
algebra,
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: dataCopy,
|
||||
metadata: {
|
||||
raw: [],
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Readable } from 'stream';
|
||||
import { Representation } from './Representation';
|
||||
|
||||
/**
|
||||
* A representation containing binary data.
|
||||
*/
|
||||
export interface BinaryRepresentation extends Representation {
|
||||
dataType: 'binary';
|
||||
data: Readable;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { Readable } from 'stream';
|
||||
import { Representation } from './Representation';
|
||||
|
||||
/**
|
||||
* A representation containing quads as data.
|
||||
*/
|
||||
export interface QuadRepresentation extends Representation {
|
||||
dataType: 'quad';
|
||||
data: Readable;
|
||||
}
|
||||
@@ -14,7 +14,8 @@ export interface Representation {
|
||||
*/
|
||||
data: Readable;
|
||||
/**
|
||||
* The data type of the contents in the data stream.
|
||||
* Whether the data stream consists of binary/string chunks
|
||||
* (as opposed to complex objects).
|
||||
*/
|
||||
dataType: string;
|
||||
binary: boolean;
|
||||
}
|
||||
|
||||
@@ -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: [],
|
||||
|
||||
@@ -1,4 +1,2 @@
|
||||
export const DATA_TYPE_BINARY = 'binary';
|
||||
export const DATA_TYPE_QUAD = 'quad';
|
||||
|
||||
// Internal (non-exposed) content types
|
||||
export const CONTENT_TYPE_QUADS = 'internal/quads';
|
||||
|
||||
@@ -26,7 +26,6 @@ import { RepresentationConvertingStore } from '../../src/storage/RepresentationC
|
||||
import { ResourceStore } from '../../src/storage/ResourceStore';
|
||||
import { UrlContainerManager } from '../../src/storage/UrlContainerManager';
|
||||
import { CompositeAsyncHandler } from '../../src/util/CompositeAsyncHandler';
|
||||
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||
import { call } from '../util/Util';
|
||||
|
||||
const setAcl = async(store: ResourceStore, id: string, permissions: PermissionSet, control: boolean,
|
||||
@@ -61,8 +60,8 @@ const setAcl = async(store: ResourceStore, id: string, permissions: PermissionSe
|
||||
acl.push('.');
|
||||
|
||||
const representation = {
|
||||
binary: true,
|
||||
data: streamifyArray(acl),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {
|
||||
raw: [],
|
||||
profiles: [],
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Representation } from '../../src/ldp/representation/Representation';
|
||||
import { ChainedConverter } from '../../src/storage/conversion/ChainedConverter';
|
||||
import { QuadToRdfConverter } from '../../src/storage/conversion/QuadToRdfConverter';
|
||||
import { RdfToQuadConverter } from '../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||
import { readableToString } from '../../src/util/Util';
|
||||
|
||||
describe('A ChainedConverter', (): void => {
|
||||
@@ -15,7 +14,7 @@ describe('A ChainedConverter', (): void => {
|
||||
|
||||
it('can convert from JSON-LD to turtle.', async(): Promise<void> => {
|
||||
const representation: Representation = {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: streamifyArray([ '{"@id": "http://test.com/s", "http://test.com/p": { "@id": "http://test.com/o" }}' ]),
|
||||
metadata: { raw: [], contentType: 'application/ld+json' },
|
||||
};
|
||||
@@ -32,7 +31,7 @@ describe('A ChainedConverter', (): void => {
|
||||
|
||||
it('can convert from turtle to JSON-LD.', async(): Promise<void> => {
|
||||
const representation: Representation = {
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
|
||||
metadata: { raw: [], contentType: 'text/turtle' },
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ import { BasicRequestParser } from '../../src/ldp/http/BasicRequestParser';
|
||||
import { BasicTargetExtractor } from '../../src/ldp/http/BasicTargetExtractor';
|
||||
import { RawBodyParser } from '../../src/ldp/http/RawBodyParser';
|
||||
import { HttpRequest } from '../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../src/util/ContentTypes';
|
||||
|
||||
describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
const targetExtractor = new BasicTargetExtractor();
|
||||
@@ -35,7 +34,7 @@ describe('A SimpleRequestParser with simple input parsers', (): void => {
|
||||
},
|
||||
body: {
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
raw: [],
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Quad } from 'rdf-js';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { BasicResponseWriter } from '../../../../src/ldp/http/BasicResponseWriter';
|
||||
import { ResponseDescription } from '../../../../src/ldp/operations/ResponseDescription';
|
||||
import { DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A BasicResponseWriter', (): void => {
|
||||
@@ -16,9 +15,9 @@ describe('A BasicResponseWriter', (): void => {
|
||||
});
|
||||
|
||||
it('requires the description body to be a string or binary stream if present.', async(): Promise<void> => {
|
||||
await expect(writer.canHandle({ response, result: { body: { dataType: DATA_TYPE_QUAD }} as ResponseDescription }))
|
||||
await expect(writer.canHandle({ response, result: { body: { binary: false }} as ResponseDescription }))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(writer.canHandle({ response, result: { body: { dataType: DATA_TYPE_BINARY }} as ResponseDescription }))
|
||||
await expect(writer.canHandle({ response, result: { body: { binary: true }} as ResponseDescription }))
|
||||
.resolves.toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -31,8 +30,8 @@ describe('A BasicResponseWriter', (): void => {
|
||||
|
||||
it('responds with a body if the description has a body.', async(done): Promise<void> => {
|
||||
const body = {
|
||||
binary: true,
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {
|
||||
raw: [] as Quad[],
|
||||
profiles: [] as string[],
|
||||
@@ -52,8 +51,8 @@ describe('A BasicResponseWriter', (): void => {
|
||||
|
||||
it('responds with a content-type if the metadata has it.', async(done): Promise<void> => {
|
||||
const body = {
|
||||
binary: true,
|
||||
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {
|
||||
raw: [] as Quad[],
|
||||
profiles: [] as string[],
|
||||
|
||||
@@ -2,7 +2,6 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { RawBodyParser } from '../../../../src/ldp/http/RawBodyParser';
|
||||
import { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import 'jest-rdf';
|
||||
|
||||
@@ -22,8 +21,8 @@ describe('A RawBodyparser', (): void => {
|
||||
input.headers = { 'content-type': 'text/turtle' };
|
||||
const result = (await bodyParser.handle(input))!;
|
||||
expect(result).toEqual({
|
||||
binary: true,
|
||||
data: input,
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
raw: [],
|
||||
|
||||
@@ -4,7 +4,6 @@ import { Algebra } from 'sparqlalgebrajs';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { SparqlUpdateBodyParser } from '../../../../src/ldp/http/SparqlUpdateBodyParser';
|
||||
import { HttpRequest } from '../../../../src/server/HttpRequest';
|
||||
import { DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../../../../src/util/errors/UnsupportedMediaTypeHttpError';
|
||||
|
||||
@@ -34,7 +33,7 @@ describe('A SparqlUpdateBodyParser', (): void => {
|
||||
namedNode('http://test.com/p'),
|
||||
namedNode('http://test.com/o'),
|
||||
) ]);
|
||||
expect(result.dataType).toBe(DATA_TYPE_BINARY);
|
||||
expect(result.binary).toBe(true);
|
||||
expect(result.metadata).toEqual({
|
||||
raw: [],
|
||||
profiles: [],
|
||||
|
||||
@@ -2,12 +2,11 @@ import { GetOperationHandler } from '../../../../src/ldp/operations/GetOperation
|
||||
import { Operation } from '../../../../src/ldp/operations/Operation';
|
||||
import { Representation } from '../../../../src/ldp/representation/Representation';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A GetOperationHandler', (): void => {
|
||||
const store = {
|
||||
getRepresentation: async(): Promise<Representation> => ({ dataType: DATA_TYPE_QUAD } as Representation),
|
||||
getRepresentation: async(): Promise<Representation> => ({ binary: false } as Representation),
|
||||
} as unknown as ResourceStore;
|
||||
const handler = new GetOperationHandler(store);
|
||||
|
||||
@@ -18,7 +17,7 @@ describe('A GetOperationHandler', (): void => {
|
||||
|
||||
it('returns the representation from the store with the input identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ target: { path: 'url' }} as Operation)).resolves.toEqual(
|
||||
{ identifier: { path: 'url' }, body: { dataType: DATA_TYPE_QUAD }},
|
||||
{ identifier: { path: 'url' }, body: { binary: false }},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,9 +16,9 @@ describe('A PatchOperationHandler', (): void => {
|
||||
});
|
||||
|
||||
it('deletes the resource from the store and returns its identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ target: { path: 'url' }, body: { dataType: 'patch' }} as Operation))
|
||||
await expect(handler.handle({ target: { path: 'url' }, body: { binary: false }} as Operation))
|
||||
.resolves.toEqual({ identifier: { path: 'url' }});
|
||||
expect(store.modifyResource).toHaveBeenCalledTimes(1);
|
||||
expect(store.modifyResource).toHaveBeenLastCalledWith({ path: 'url' }, { dataType: 'patch' });
|
||||
expect(store.modifyResource).toHaveBeenLastCalledWith({ path: 'url' }, { binary: false });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,15 +11,15 @@ describe('A PostOperationHandler', (): void => {
|
||||
const handler = new PostOperationHandler(store);
|
||||
|
||||
it('only supports POST operations with a body.', async(): Promise<void> => {
|
||||
await expect(handler.canHandle({ method: 'POST', body: { dataType: 'test' }} as Operation))
|
||||
await expect(handler.canHandle({ method: 'POST', body: { }} as Operation))
|
||||
.resolves.toBeUndefined();
|
||||
await expect(handler.canHandle({ method: 'GET', body: { dataType: 'test' }} as Operation))
|
||||
await expect(handler.canHandle({ method: 'GET', body: { }} as Operation))
|
||||
.rejects.toThrow(UnsupportedHttpError);
|
||||
await expect(handler.canHandle({ method: 'POST' } as Operation)).rejects.toThrow(UnsupportedHttpError);
|
||||
});
|
||||
|
||||
it('adds the given representation to the store and returns the new identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ method: 'POST', body: { dataType: 'test' }} as Operation))
|
||||
await expect(handler.handle({ method: 'POST', body: { }} as Operation))
|
||||
.resolves.toEqual({ identifier: { path: 'newPath' }});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,10 +17,10 @@ describe('A PutOperationHandler', (): void => {
|
||||
});
|
||||
|
||||
it('sets the representation in the store and returns its identifier.', async(): Promise<void> => {
|
||||
await expect(handler.handle({ target: { path: 'url' }, body: { dataType: 'test' }} as Operation))
|
||||
await expect(handler.handle({ target: { path: 'url' }, body: {}} as Operation))
|
||||
.resolves.toEqual({ identifier: { path: 'url' }});
|
||||
expect(store.setRepresentation).toHaveBeenCalledTimes(1);
|
||||
expect(store.setRepresentation).toHaveBeenLastCalledWith({ path: 'url' }, { dataType: 'test' });
|
||||
expect(store.setRepresentation).toHaveBeenLastCalledWith({ path: 'url' }, {});
|
||||
});
|
||||
|
||||
it('errors when there is no body.', async(): Promise<void> => {
|
||||
|
||||
@@ -6,10 +6,10 @@ import arrayifyStream from 'arrayify-stream';
|
||||
import { DataFactory } from 'n3';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { FileResourceStore } from '../../../src/storage/FileResourceStore';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY, DATA_TYPE_QUAD } from '../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../src/util/ContentTypes';
|
||||
import { ConflictHttpError } from '../../../src/util/errors/ConflictHttpError';
|
||||
import { MethodNotAllowedHttpError } from '../../../src/util/errors/MethodNotAllowedHttpError';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
@@ -33,7 +33,7 @@ fsPromises.access = jest.fn();
|
||||
|
||||
describe('A FileResourceStore', (): void => {
|
||||
let store: FileResourceStore;
|
||||
let representation: BinaryRepresentation;
|
||||
let representation: Representation;
|
||||
let readableMock: Readable;
|
||||
let stats: Stats;
|
||||
let writeStream: WriteStream;
|
||||
@@ -56,8 +56,8 @@ describe('A FileResourceStore', (): void => {
|
||||
);
|
||||
|
||||
representation = {
|
||||
binary: true,
|
||||
data: streamifyArray([ rawData ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: { raw: [], linkRel: { type: new Set() }} as RepresentationMetadata,
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ describe('A FileResourceStore', (): void => {
|
||||
});
|
||||
|
||||
it('errors for wrong input data types.', async(): Promise<void> => {
|
||||
(representation as any).dataType = DATA_TYPE_QUAD;
|
||||
(representation as any).binary = false;
|
||||
await expect(store.addResource({ path: base }, representation)).rejects.toThrow(UnsupportedMediaTypeHttpError);
|
||||
await expect(store.setRepresentation({ path: `${base}foo` }, representation)).rejects
|
||||
.toThrow(UnsupportedMediaTypeHttpError);
|
||||
@@ -142,7 +142,7 @@ describe('A FileResourceStore', (): void => {
|
||||
// Read container
|
||||
const result = await store.getRepresentation(identifier);
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -212,7 +212,7 @@ describe('A FileResourceStore', (): void => {
|
||||
expect(fs.createWriteStream as jest.Mock).toBeCalledWith(joinPath(rootFilepath, 'file.txt'));
|
||||
const result = await store.getRepresentation({ path: `${base}file.txt` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -365,7 +365,7 @@ describe('A FileResourceStore', (): void => {
|
||||
];
|
||||
const result = await store.getRepresentation({ path: `${base}foo/` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
@@ -492,7 +492,7 @@ describe('A FileResourceStore', (): void => {
|
||||
|
||||
const result = await store.getRepresentation({ path: `${base}.htaccess` });
|
||||
expect(result).toEqual({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: {
|
||||
raw: [],
|
||||
|
||||
@@ -2,25 +2,24 @@ import { Readable } from 'stream';
|
||||
import arrayifyStream from 'arrayify-stream';
|
||||
import streamifyArray from 'streamify-array';
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { BinaryRepresentation } from '../../../src/ldp/representation/BinaryRepresentation';
|
||||
import { Representation } from '../../../src/ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
|
||||
import { InMemoryResourceStore } from '../../../src/storage/InMemoryResourceStore';
|
||||
import { DATA_TYPE_BINARY } from '../../../src/util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../../../src/util/errors/NotFoundHttpError';
|
||||
|
||||
const base = 'http://test.com/';
|
||||
|
||||
describe('A InMemoryResourceStore', (): void => {
|
||||
let store: InMemoryResourceStore;
|
||||
let representation: BinaryRepresentation;
|
||||
let representation: Representation;
|
||||
const dataString = '<http://test.com/s> <http://test.com/p> <http://test.com/o>.';
|
||||
|
||||
beforeEach(async(): Promise<void> => {
|
||||
store = new InMemoryResourceStore(new RuntimeConfig({ base }));
|
||||
|
||||
representation = {
|
||||
binary: true,
|
||||
data: streamifyArray([ dataString ]),
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
metadata: {} as RepresentationMetadata,
|
||||
};
|
||||
});
|
||||
@@ -43,7 +42,7 @@ describe('A InMemoryResourceStore', (): void => {
|
||||
expect(identifier.path.startsWith(base)).toBeTruthy();
|
||||
const result = await store.getRepresentation(identifier);
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
@@ -61,7 +60,7 @@ describe('A InMemoryResourceStore', (): void => {
|
||||
await store.setRepresentation({ path: base }, representation);
|
||||
const result = await store.getRepresentation({ path: base });
|
||||
expect(result).toEqual({
|
||||
dataType: representation.dataType,
|
||||
binary: true,
|
||||
data: expect.any(Readable),
|
||||
metadata: representation.metadata,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { QuadToRdfConverter } from '../../../../src/storage/conversion/QuadToRdfConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
|
||||
describe('A QuadToRdfConverter', (): void => {
|
||||
const converter = new QuadToRdfConverter();
|
||||
@@ -44,7 +44,7 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
},
|
||||
@@ -67,7 +67,7 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'application/ld+json', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'application/ld+json',
|
||||
},
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { QuadToTurtleConverter } from '../../../../src/storage/conversion/QuadToTurtleConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_BINARY } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
|
||||
describe('A QuadToTurtleConverter', (): void => {
|
||||
const converter = new QuadToTurtleConverter();
|
||||
@@ -29,7 +29,7 @@ describe('A QuadToTurtleConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toMatchObject({
|
||||
dataType: DATA_TYPE_BINARY,
|
||||
binary: true,
|
||||
metadata: {
|
||||
contentType: 'text/turtle',
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { RdfToQuadConverter } from '../../../../src/storage/conversion/RdfToQuadConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
@@ -42,8 +42,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -63,8 +63,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -84,8 +84,8 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Representation } from '../../../../src/ldp/representation/Representatio
|
||||
import { RepresentationPreferences } from '../../../../src/ldp/representation/RepresentationPreferences';
|
||||
import { ResourceIdentifier } from '../../../../src/ldp/representation/ResourceIdentifier';
|
||||
import { TurtleToQuadConverter } from '../../../../src/storage/conversion/TurtleToQuadConverter';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A TurtleToQuadConverter', (): void => {
|
||||
@@ -27,8 +27,8 @@ describe('A TurtleToQuadConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
@@ -48,8 +48,8 @@ describe('A TurtleToQuadConverter', (): void => {
|
||||
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
|
||||
const result = await converter.handle({ identifier, representation, preferences });
|
||||
expect(result).toEqual({
|
||||
binary: false,
|
||||
data: expect.any(Readable),
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
metadata: {
|
||||
contentType: CONTENT_TYPE_QUADS,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Lock } from '../../../../src/storage/Lock';
|
||||
import { SparqlUpdatePatchHandler } from '../../../../src/storage/patch/SparqlUpdatePatchHandler';
|
||||
import { ResourceLocker } from '../../../../src/storage/ResourceLocker';
|
||||
import { ResourceStore } from '../../../../src/storage/ResourceStore';
|
||||
import { CONTENT_TYPE_QUADS, DATA_TYPE_QUAD } from '../../../../src/util/ContentTypes';
|
||||
import { CONTENT_TYPE_QUADS } from '../../../../src/util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';
|
||||
|
||||
describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
@@ -72,7 +72,7 @@ describe('A SparqlUpdatePatchHandler', (): void => {
|
||||
const setParams = (source.setRepresentation as jest.Mock).mock.calls[0];
|
||||
expect(setParams[0]).toEqual({ path: 'path' });
|
||||
expect(setParams[1]).toEqual(expect.objectContaining({
|
||||
dataType: DATA_TYPE_QUAD,
|
||||
binary: false,
|
||||
metadata: { raw: [], profiles: [], contentType: CONTENT_TYPE_QUADS },
|
||||
}));
|
||||
await expect(arrayifyStream(setParams[1].data)).resolves.toBeRdfIsomorphic(quads);
|
||||
|
||||
Reference in New Issue
Block a user