fix: Make root storage subject of storage description

This commit is contained in:
Joachim Van Herwegen 2023-06-12 09:12:40 +02:00
parent d6fd59f7c8
commit 9584ab7549
4 changed files with 14 additions and 6 deletions

View File

@ -1,6 +1,7 @@
import { OkResponseDescription } from '../../http/output/response/OkResponseDescription';
import type { ResponseDescription } from '../../http/output/response/ResponseDescription';
import { BasicRepresentation } from '../../http/representation/BasicRepresentation';
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
import type { ResourceStore } from '../../storage/ResourceStore';
import { INTERNAL_QUADS } from '../../util/ContentTypes';
import { MethodNotAllowedHttpError } from '../../util/errors/MethodNotAllowedHttpError';
@ -32,7 +33,7 @@ export class StorageDescriptionHandler extends OperationHttpHandler {
if (method !== 'GET') {
throw new MethodNotAllowedHttpError([ method ], `Only GET requests can target the storage description.`);
}
const container = { path: ensureTrailingSlash(target.path.slice(0, -this.path.length)) };
const container = this.getStorageIdentifier(target);
const representation = await this.store.getRepresentation(container, {});
representation.data.destroy();
if (!representation.metadata.has(RDF.terms.type, PIM.terms.Storage)) {
@ -43,10 +44,17 @@ export class StorageDescriptionHandler extends OperationHttpHandler {
}
public async handle({ operation: { target }}: OperationHttpHandlerInput): Promise<ResponseDescription> {
const quads = await this.describer.handle(target);
const quads = await this.describer.handle(this.getStorageIdentifier(target));
const representation = new BasicRepresentation(quads, INTERNAL_QUADS);
return new OkResponseDescription(representation.metadata, representation.data);
}
/**
* Determine the identifier of the root storage based on the identifier of the root storage description resource.
*/
protected getStorageIdentifier(descriptionIdentifier: ResourceIdentifier): ResourceIdentifier {
return { path: ensureTrailingSlash(descriptionIdentifier.path.slice(0, -this.path.length)) };
}
}

View File

@ -97,7 +97,7 @@ describe.each(stores)('A server supporting WebHookChannel2023 using %s', (name,
const quads = new Store(new Parser().parse(await response.text()));
// Find the notification channel for websockets
const subscriptions = quads.getObjects(storageDescriptionUrl, NOTIFY.terms.subscription, null);
const subscriptions = quads.getObjects(null, NOTIFY.terms.subscription, null);
const webhookSubscriptions = subscriptions.filter((channel): boolean => quads.has(
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebHookChannel2023`)),
));

View File

@ -86,7 +86,7 @@ describe.each(stores)('A server supporting WebSocketChannel2023 using %s', (name
const quads = new Store(new Parser().parse(await response.text()));
// Find the notification channel for websockets
const subscriptions = quads.getObjects(storageDescriptionUrl, NOTIFY.terms.subscription, null);
const subscriptions = quads.getObjects(null, NOTIFY.terms.subscription, null);
const websocketSubscriptions = subscriptions.filter((channel): boolean => quads.has(
quad(channel as NamedNode, NOTIFY.terms.channelType, namedNode(`${NOTIFY.namespace}WebSocketChannel2023`)),
));

View File

@ -83,8 +83,8 @@ describe('A StorageDescriptionHandler', (): void => {
expect(result.metadata?.contentType).toBe('internal/quads');
expect(result.data).toBeDefined();
const quads = await readableToQuads(result.data!);
expect(quads.countQuads(operation.target.path, RDF.terms.type, PIM.terms.Storage, null)).toBe(1);
expect(quads.countQuads('http://example.com/', RDF.terms.type, PIM.terms.Storage, null)).toBe(1);
expect(describer.handle).toHaveBeenCalledTimes(1);
expect(describer.handle).toHaveBeenLastCalledWith(operation.target);
expect(describer.handle).toHaveBeenLastCalledWith({ path: 'http://example.com/' });
});
});