mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Make URI constants consistent
This commit is contained in:
@@ -14,15 +14,8 @@ import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedMediaTypeHttpError } from '../util/errors/UnsupportedMediaTypeHttpError';
|
||||
import { InteractionController } from '../util/InteractionController';
|
||||
import { MetadataController } from '../util/MetadataController';
|
||||
import {
|
||||
HTTP_BYTE_SIZE,
|
||||
HTTP_LAST_CHANGED,
|
||||
HTTP_SLUG,
|
||||
MA_CONTENT_TYPE,
|
||||
RDF_TYPE,
|
||||
XSD_DATE_TIME,
|
||||
XSD_INTEGER,
|
||||
} from '../util/MetadataTypes';
|
||||
import { CONTENT_TYPE, DCTERMS, HTTP, POSIX, RDF, XSD } from '../util/UriConstants';
|
||||
import { getTypedLiteral } from '../util/UriUtil';
|
||||
import { ensureTrailingSlash } from '../util/Util';
|
||||
import { ExtensionBasedMapper } from './ExtensionBasedMapper';
|
||||
import { ResourceStore } from './ResourceStore';
|
||||
@@ -65,8 +58,8 @@ export class FileResourceStore implements ResourceStore {
|
||||
|
||||
// Get the path from the request URI, all metadata triples if any, and the Slug and Link header values.
|
||||
const path = this.resourceMapper.getRelativePath(container);
|
||||
const slug = representation.metadata.get(HTTP_SLUG)?.value;
|
||||
const types = representation.metadata.getAll(RDF_TYPE);
|
||||
const slug = representation.metadata.get(HTTP.slug)?.value;
|
||||
const types = representation.metadata.getAll(RDF.type);
|
||||
|
||||
// Create a new container or resource in the parent container with a specific name based on the incoming headers.
|
||||
const isContainer = this.interactionController.isContainer(slug, types);
|
||||
@@ -162,7 +155,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
representation.metadata.identifier = DataFactory.namedNode(identifier.path);
|
||||
const raw = representation.metadata.quads();
|
||||
const types = representation.metadata.getAll(RDF_TYPE);
|
||||
const types = representation.metadata.getAll(RDF.type);
|
||||
let metadata: Readable | undefined;
|
||||
if (raw.length > 0) {
|
||||
metadata = this.metadataController.serializeQuads(raw);
|
||||
@@ -231,8 +224,8 @@ export class FileResourceStore implements ResourceStore {
|
||||
// Metadata file doesn't exist so lets keep `rawMetaData` an empty array.
|
||||
}
|
||||
const metadata = new RepresentationMetadata(this.resourceMapper.mapFilePathToUrl(path)).addQuads(rawMetadata)
|
||||
.set(HTTP_LAST_CHANGED, DataFactory.literal(stats.mtime.toISOString(), XSD_DATE_TIME))
|
||||
.set(HTTP_BYTE_SIZE, DataFactory.literal(stats.size, XSD_INTEGER));
|
||||
.set(DCTERMS.modified, getTypedLiteral(stats.mtime.toISOString(), XSD.dateTime))
|
||||
.set(POSIX.size, getTypedLiteral(stats.size, XSD.integer));
|
||||
metadata.contentType = contentType;
|
||||
return { metadata, data: readStream, binary: true };
|
||||
}
|
||||
@@ -265,8 +258,8 @@ export class FileResourceStore implements ResourceStore {
|
||||
}
|
||||
|
||||
const metadata = new RepresentationMetadata(containerURI).addQuads(rawMetadata)
|
||||
.set(HTTP_LAST_CHANGED, DataFactory.literal(stats.mtime.toISOString(), XSD_DATE_TIME))
|
||||
.set(MA_CONTENT_TYPE, INTERNAL_QUADS);
|
||||
.set(DCTERMS.modified, getTypedLiteral(stats.mtime.toISOString(), XSD.dateTime))
|
||||
.set(CONTENT_TYPE, INTERNAL_QUADS);
|
||||
|
||||
return {
|
||||
binary: false,
|
||||
@@ -285,6 +278,7 @@ export class FileResourceStore implements ResourceStore {
|
||||
*/
|
||||
private async getDirChildrenQuadRepresentation(files: string[], path: string, containerURI: string): Promise<Quad[]> {
|
||||
const quads: Quad[] = [];
|
||||
const childURIs: string[] = [];
|
||||
for (const childName of files) {
|
||||
try {
|
||||
const childURI = this.resourceMapper.mapFilePathToUrl(joinPath(path, childName));
|
||||
@@ -293,13 +287,16 @@ export class FileResourceStore implements ResourceStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
quads.push(this.metadataController.generateContainerContainsResourceQuad(containerURI, childURI));
|
||||
quads.push(...this.metadataController.generateResourceQuads(childURI, childStats));
|
||||
childURIs.push(childURI);
|
||||
} catch (_) {
|
||||
// Skip the child if there is an error.
|
||||
}
|
||||
}
|
||||
return quads;
|
||||
|
||||
const containsQuads = this.metadataController.generateContainerContainsResourceQuads(containerURI, childURIs);
|
||||
|
||||
return quads.concat(containsQuads);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ import { RepresentationMetadata } from '../ldp/representation/RepresentationMeta
|
||||
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
|
||||
import { TEXT_TURTLE } from '../util/ContentTypes';
|
||||
import { NotFoundHttpError } from '../util/errors/NotFoundHttpError';
|
||||
import { MA_CONTENT_TYPE } from '../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../util/UriConstants';
|
||||
import { ensureTrailingSlash } from '../util/Util';
|
||||
import { ResourceStore } from './ResourceStore';
|
||||
|
||||
@@ -26,7 +26,7 @@ export class InMemoryResourceStore implements ResourceStore {
|
||||
public constructor(base: string) {
|
||||
this.base = ensureTrailingSlash(base);
|
||||
|
||||
const metadata = new RepresentationMetadata({ [MA_CONTENT_TYPE]: TEXT_TURTLE });
|
||||
const metadata = new RepresentationMetadata({ [CONTENT_TYPE]: TEXT_TURTLE });
|
||||
this.store = {
|
||||
// Default root entry (what you get when the identifier is equal to the base)
|
||||
'': {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { matchingMediaType } from '../../util/Util';
|
||||
import { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
@@ -53,7 +53,7 @@ export class ChainedConverter extends TypedRepresentationConverter {
|
||||
const idx = this.converters.length - 1;
|
||||
const lastChain = await this.getMatchingType(this.converters[idx - 1], this.converters[idx]);
|
||||
const oldMeta = input.representation.metadata;
|
||||
const metadata = new RepresentationMetadata(oldMeta, { [MA_CONTENT_TYPE]: lastChain });
|
||||
const metadata = new RepresentationMetadata(oldMeta, { [CONTENT_TYPE]: lastChain });
|
||||
const representation: Representation = { ...input.representation, metadata };
|
||||
await this.last.canHandle({ ...input, representation });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { RepresentationPreferences } from '../../ldp/representation/RepresentationPreferences';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { checkRequest, matchingTypes } from './ConversionUtil';
|
||||
import { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
import { TypedRepresentationConverter } from './TypedRepresentationConverter';
|
||||
@@ -31,7 +31,7 @@ export class QuadToRdfConverter extends TypedRepresentationConverter {
|
||||
|
||||
private async quadsToRdf(quads: Representation, preferences: RepresentationPreferences): Promise<Representation> {
|
||||
const contentType = matchingTypes(preferences, await rdfSerializer.getContentTypes())[0].value;
|
||||
const metadata = new RepresentationMetadata(quads.metadata, { [MA_CONTENT_TYPE]: contentType });
|
||||
const metadata = new RepresentationMetadata(quads.metadata, { [CONTENT_TYPE]: contentType });
|
||||
return {
|
||||
binary: true,
|
||||
data: rdfSerializer.serialize(quads.data, { contentType }) as Readable,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { StreamWriter } from 'n3';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS, TEXT_TURTLE } from '../../util/ContentTypes';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
@@ -19,7 +19,7 @@ export class QuadToTurtleConverter extends RepresentationConverter {
|
||||
}
|
||||
|
||||
private quadsToTurtle(quads: Representation): Representation {
|
||||
const metadata = new RepresentationMetadata(quads.metadata, { [MA_CONTENT_TYPE]: TEXT_TURTLE });
|
||||
const metadata = new RepresentationMetadata(quads.metadata, { [CONTENT_TYPE]: TEXT_TURTLE });
|
||||
return {
|
||||
binary: true,
|
||||
data: quads.data.pipe(new StreamWriter({ format: TEXT_TURTLE })),
|
||||
|
||||
@@ -3,7 +3,7 @@ import rdfParser from 'rdf-parse';
|
||||
import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { pipeStreamsAndErrors } from '../../util/Util';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverterArgs } from './RepresentationConverter';
|
||||
@@ -30,7 +30,7 @@ export class RdfToQuadConverter extends TypedRepresentationConverter {
|
||||
}
|
||||
|
||||
private rdfToQuads(representation: Representation, baseIRI: string): Representation {
|
||||
const metadata = new RepresentationMetadata(representation.metadata, { [MA_CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const metadata = new RepresentationMetadata(representation.metadata, { [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const rawQuads = rdfParser.parse(representation.data, {
|
||||
contentType: representation.metadata.contentType!,
|
||||
baseIRI,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Representation } from '../../ldp/representation/Representation';
|
||||
import { RepresentationMetadata } from '../../ldp/representation/RepresentationMetadata';
|
||||
import { TEXT_TURTLE, INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { checkRequest } from './ConversionUtil';
|
||||
import { RepresentationConverter, RepresentationConverterArgs } from './RepresentationConverter';
|
||||
|
||||
@@ -21,7 +21,7 @@ export class TurtleToQuadConverter extends RepresentationConverter {
|
||||
}
|
||||
|
||||
private turtleToQuads(turtle: Representation, baseIRI: string): Representation {
|
||||
const metadata = new RepresentationMetadata(turtle.metadata, { [MA_CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const metadata = new RepresentationMetadata(turtle.metadata, { [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
|
||||
// Catch parsing errors and emit correct error
|
||||
// Node 10 requires both writableObjectMode and readableObjectMode
|
||||
|
||||
@@ -10,7 +10,7 @@ import { RepresentationMetadata } from '../../ldp/representation/RepresentationM
|
||||
import { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { INTERNAL_QUADS } from '../../util/ContentTypes';
|
||||
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
|
||||
import { MA_CONTENT_TYPE } from '../../util/MetadataTypes';
|
||||
import { CONTENT_TYPE } from '../../util/UriConstants';
|
||||
import { ResourceLocker } from '../ResourceLocker';
|
||||
import { ResourceStore } from '../ResourceStore';
|
||||
import { PatchHandler } from './PatchHandler';
|
||||
@@ -67,7 +67,7 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
});
|
||||
store.removeQuads(deletes);
|
||||
store.addQuads(inserts);
|
||||
const metadata = new RepresentationMetadata(input.identifier.path, { [MA_CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const metadata = new RepresentationMetadata(input.identifier.path, { [CONTENT_TYPE]: INTERNAL_QUADS });
|
||||
const representation: Representation = {
|
||||
binary: false,
|
||||
data: store.match() as Readable,
|
||||
|
||||
Reference in New Issue
Block a user