Skip to content

Commit

Permalink
refactor: Drop CONTENT_TYPE prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh authored and joachimvh committed Sep 3, 2020
1 parent c5c5d13 commit 85e3117
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/authorization/WebAclAuthorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Representation } from '../ldp/representation/Representation';
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
import { ContainerManager } from '../storage/ContainerManager';
import { ResourceStore } from '../storage/ResourceStore';
import { CONTENT_TYPE_QUADS } from '../util/ContentTypes';
import { INTERNAL_QUADS } from '../util/ContentTypes';
import { ForbiddenHttpError } from '../util/errors/ForbiddenHttpError';
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
import { UnauthorizedHttpError } from '../util/errors/UnauthorizedHttpError';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class WebAclAuthorizer extends Authorizer {
private async getAclRecursive(id: ResourceIdentifier, recurse?: boolean): Promise<Store> {
try {
const acl = await this.aclManager.getAcl(id);
const data = await this.resourceStore.getRepresentation(acl, { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]});
const data = await this.resourceStore.getRepresentation(acl, { type: [{ value: INTERNAL_QUADS, weight: 1 }]});
return this.filterData(data, recurse ? ACL.default : ACL.accessTo, id.path);
} catch (error) {
if (!(error instanceof NotFoundHttpError)) {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/FileResourceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../util/ContentTypes';
import { INTERNAL_QUADS } from '../util/ContentTypes';
import { ConflictHttpError } from '../util/errors/ConflictHttpError';
import { MethodNotAllowedHttpError } from '../util/errors/MethodNotAllowedHttpError';
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
Expand Down Expand Up @@ -300,7 +300,7 @@ export class FileResourceStore implements ResourceStore {
metadata: {
raw: rawMetadata,
dateTime: stats.mtime,
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/storage/conversion/QuadToRdfConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../util/ContentTypes';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { checkRequest, matchingTypes } from './ConversionUtil';
import { RepresentationConverterArgs } from './RepresentationConverter';
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
Expand All @@ -13,15 +13,15 @@ import { TypedRepresentationConverter } from './TypedRepresentationConverter';
*/
export class QuadToRdfConverter extends TypedRepresentationConverter {
public async getInputTypes(): Promise<{ [contentType: string]: number }> {
return { [CONTENT_TYPE_QUADS]: 1 };
return { [INTERNAL_QUADS]: 1 };
}

public async getOutputTypes(): Promise<{ [contentType: string]: number }> {
return rdfSerializer.getContentTypesPrioritized();
}

public async canHandle(input: RepresentationConverterArgs): Promise<void> {
checkRequest(input, [ CONTENT_TYPE_QUADS ], await rdfSerializer.getContentTypes());
checkRequest(input, [ INTERNAL_QUADS ], await rdfSerializer.getContentTypes());
}

public async handle(input: RepresentationConverterArgs): Promise<Representation> {
Expand Down
4 changes: 2 additions & 2 deletions src/storage/conversion/QuadToTurtleConverter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StreamWriter } from 'n3';
import { Representation } from '../../ldp/representation/Representation';
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
import { CONTENT_TYPE_QUADS } from '../../util/ContentTypes';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { checkRequest } from './ConversionUtil';
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';

Expand All @@ -10,7 +10,7 @@ import { RepresentationConverter, RepresentationConverterArgs } from './Represen
*/
export class QuadToTurtleConverter extends RepresentationConverter {
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
checkRequest(input, [ CONTENT_TYPE_QUADS ], [ 'text/turtle' ]);
checkRequest(input, [ INTERNAL_QUADS ], [ 'text/turtle' ]);
}

public async handle(input: RepresentationConverterArgs): Promise<Representation> {
Expand Down
8 changes: 4 additions & 4 deletions src/storage/conversion/RdfToQuadConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../util/ContentTypes';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { checkRequest } from './ConversionUtil';
import { RepresentationConverterArgs } from './RepresentationConverter';
Expand All @@ -17,19 +17,19 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
}

public async getOutputTypes(): Promise<{ [contentType: string]: number }> {
return { [CONTENT_TYPE_QUADS]: 1 };
return { [INTERNAL_QUADS]: 1 };
}

public async canHandle(input: RepresentationConverterArgs): Promise<void> {
checkRequest(input, await rdfParser.getContentTypes(), [ CONTENT_TYPE_QUADS ]);
checkRequest(input, await rdfParser.getContentTypes(), [ INTERNAL_QUADS ]);
}

public async handle(input: RepresentationConverterArgs): Promise<Representation> {
return this.rdfToQuads(input.representation, input.identifier.path);
}

private rdfToQuads(representation: Representation, baseIRI: string): Representation {
const metadata: RepresentationMetadata = { ...representation.metadata, contentType: CONTENT_TYPE_QUADS };
const metadata: RepresentationMetadata = { ...representation.metadata, contentType: INTERNAL_QUADS };

// Catch parsing errors and emit correct error
// Node 10 requires both writableObjectMode and readableObjectMode
Expand Down
6 changes: 3 additions & 3 deletions src/storage/conversion/TurtleToQuadConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../util/ContentTypes';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { checkRequest } from './ConversionUtil';
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
Expand All @@ -12,15 +12,15 @@ import { RepresentationConverter, RepresentationConverterArgs } from './Represen
*/
export class TurtleToQuadConverter extends RepresentationConverter {
public async canHandle(input: RepresentationConverterArgs): Promise<void> {
checkRequest(input, [ 'text/turtle' ], [ CONTENT_TYPE_QUADS ]);
checkRequest(input, [ 'text/turtle' ], [ INTERNAL_QUADS ]);
}

public async handle(input: RepresentationConverterArgs): Promise<Representation> {
return this.turtleToQuads(input.representation, input.identifier.path);
}

private turtleToQuads(turtle: Representation, baseIRI: string): Representation {
const metadata: RepresentationMetadata = { ...turtle.metadata, contentType: CONTENT_TYPE_QUADS };
const metadata: RepresentationMetadata = { ...turtle.metadata, contentType: INTERNAL_QUADS };

// Catch parsing errors and emit correct error
// Node 10 requires both writableObjectMode and readableObjectMode
Expand Down
6 changes: 3 additions & 3 deletions src/storage/patch/SparqlUpdatePatchHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../util/ContentTypes';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { ResourceLocker } from '../ResourceLocker';
import { ResourceStore } from '../ResourceStore';
Expand Down Expand Up @@ -56,7 +56,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {

const lock = await this.locker.acquire(input.identifier);
const quads = await this.source.getRepresentation(input.identifier,
{ type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]});
{ type: [{ value: INTERNAL_QUADS, weight: 1 }]});
const store = new Store<BaseQuad>();
const importEmitter = store.import(quads.data);
await new Promise((resolve, reject): void => {
Expand All @@ -71,7 +71,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
metadata: {
raw: [],
profiles: [],
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
};
await this.source.setRepresentation(input.identifier, representation);
Expand Down
2 changes: 1 addition & 1 deletion src/util/ContentTypes.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Internal (non-exposed) content types
export const CONTENT_TYPE_QUADS = 'internal/quads';
export const INTERNAL_QUADS = 'internal/quads';
6 changes: 3 additions & 3 deletions test/unit/storage/FileResourceStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
import { Representation } from '../../../src/ldp/representation/Representation';
import { RepresentationMetadata } from '../../../src/ldp/representation/RepresentationMetadata';
import { FileResourceStore } from '../../../src/storage/FileResourceStore';
import { CONTENT_TYPE_QUADS } from '../../../src/util/ContentTypes';
import { INTERNAL_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';
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('A FileResourceStore', (): void => {
metadata: {
raw: [],
dateTime: stats.mtime,
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
});
await expect(arrayifyStream(result.data)).resolves.toBeDefined();
Expand Down Expand Up @@ -370,7 +370,7 @@ describe('A FileResourceStore', (): void => {
metadata: {
raw: [],
dateTime: stats.mtime,
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
});
await expect(arrayifyStream(result.data)).resolves.toEqualRdfQuadArray(quads);
Expand Down
12 changes: 6 additions & 6 deletions test/unit/storage/conversion/QuadToRdfConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ 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 } from '../../../../src/util/ContentTypes';
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';

describe('A QuadToRdfConverter', (): void => {
const converter = new QuadToRdfConverter();
const identifier: ResourceIdentifier = { path: 'path' };

it('supports parsing quads.', async(): Promise<void> => {
await expect(converter.getInputTypes()).resolves.toEqual({ [CONTENT_TYPE_QUADS]: 1 });
await expect(converter.getInputTypes()).resolves.toEqual({ [INTERNAL_QUADS]: 1 });
});

it('supports serializing as the same types as rdfSerializer.', async(): Promise<void> => {
await expect(converter.getOutputTypes()).resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
});

it('can handle quad to turtle conversions.', async(): Promise<void> => {
const representation = { metadata: { contentType: CONTENT_TYPE_QUADS }} as Representation;
const representation = { metadata: { contentType: INTERNAL_QUADS }} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
});

it('can handle quad to JSON-LD conversions.', async(): Promise<void> => {
const representation = { metadata: { contentType: CONTENT_TYPE_QUADS }} as Representation;
const representation = { metadata: { contentType: INTERNAL_QUADS }} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'application/ld+json', weight: 1 }]};
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
});
Expand All @@ -39,7 +39,7 @@ describe('A QuadToRdfConverter', (): void => {
namedNode('http://test.com/p'),
namedNode('http://test.com/o'),
) ]),
metadata: { contentType: CONTENT_TYPE_QUADS },
metadata: { contentType: INTERNAL_QUADS },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
Expand All @@ -62,7 +62,7 @@ describe('A QuadToRdfConverter', (): void => {
namedNode('http://test.com/p'),
namedNode('http://test.com/o'),
) ]),
metadata: { contentType: CONTENT_TYPE_QUADS },
metadata: { contentType: INTERNAL_QUADS },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'application/ld+json', weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
Expand Down
6 changes: 3 additions & 3 deletions test/unit/storage/conversion/QuadToTurtleConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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 } from '../../../../src/util/ContentTypes';
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';

describe('A QuadToTurtleConverter', (): void => {
const converter = new QuadToTurtleConverter();
const identifier: ResourceIdentifier = { path: 'path' };

it('can handle quad to turtle conversions.', async(): Promise<void> => {
const representation = { metadata: { contentType: CONTENT_TYPE_QUADS }} as Representation;
const representation = { metadata: { contentType: INTERNAL_QUADS }} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
});
Expand All @@ -24,7 +24,7 @@ describe('A QuadToTurtleConverter', (): void => {
namedNode('http://test.com/p'),
namedNode('http://test.com/o'),
) ]),
metadata: { contentType: CONTENT_TYPE_QUADS },
metadata: { contentType: INTERNAL_QUADS },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: 'text/turtle', weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
Expand Down
20 changes: 10 additions & 10 deletions test/unit/storage/conversion/RdfToQuadConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '../../../../src/util/ContentTypes';
import { INTERNAL_QUADS } from '../../../../src/util/ContentTypes';
import { UnsupportedHttpError } from '../../../../src/util/errors/UnsupportedHttpError';

describe('A RdfToQuadConverter.test.ts', (): void => {
Expand All @@ -19,18 +19,18 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
});

it('supports serializing as quads.', async(): Promise<void> => {
await expect(converter.getOutputTypes()).resolves.toEqual({ [CONTENT_TYPE_QUADS]: 1 });
await expect(converter.getOutputTypes()).resolves.toEqual({ [INTERNAL_QUADS]: 1 });
});

it('can handle turtle to quad conversions.', async(): Promise<void> => {
const representation = { metadata: { contentType: 'text/turtle' }} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
const preferences: RepresentationPreferences = { type: [{ value: INTERNAL_QUADS, weight: 1 }]};
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
});

it('can handle JSON-LD to quad conversions.', async(): Promise<void> => {
const representation = { metadata: { contentType: 'application/ld+json' }} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
const preferences: RepresentationPreferences = { type: [{ value: INTERNAL_QUADS, weight: 1 }]};
await expect(converter.canHandle({ identifier, representation, preferences })).resolves.toBeUndefined();
});

Expand All @@ -39,13 +39,13 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.com/o>.' ]),
metadata: { contentType: 'text/turtle' },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
const preferences: RepresentationPreferences = { type: [{ value: INTERNAL_QUADS, weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
expect(result).toEqual({
binary: false,
data: expect.any(Readable),
metadata: {
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
});
await expect(arrayifyStream(result.data)).resolves.toEqualRdfQuadArray([ triple(
Expand All @@ -60,13 +60,13 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
data: streamifyArray([ '{"@id": "http://test.com/s", "http://test.com/p": { "@id": "http://test.com/o" }}' ]),
metadata: { contentType: 'application/ld+json' },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
const preferences: RepresentationPreferences = { type: [{ value: INTERNAL_QUADS, weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
expect(result).toEqual({
binary: false,
data: expect.any(Readable),
metadata: {
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
});
await expect(arrayifyStream(result.data)).resolves.toEqualRdfQuadArray([ triple(
Expand All @@ -81,13 +81,13 @@ describe('A RdfToQuadConverter.test.ts', (): void => {
data: streamifyArray([ '<http://test.com/s> <http://test.com/p> <http://test.co' ]),
metadata: { contentType: 'text/turtle' },
} as Representation;
const preferences: RepresentationPreferences = { type: [{ value: CONTENT_TYPE_QUADS, weight: 1 }]};
const preferences: RepresentationPreferences = { type: [{ value: INTERNAL_QUADS, weight: 1 }]};
const result = await converter.handle({ identifier, representation, preferences });
expect(result).toEqual({
binary: false,
data: expect.any(Readable),
metadata: {
contentType: CONTENT_TYPE_QUADS,
contentType: INTERNAL_QUADS,
},
});
await expect(arrayifyStream(result.data)).rejects.toThrow(UnsupportedHttpError);
Expand Down
Loading

0 comments on commit 85e3117

Please sign in to comment.