feat: Convert data from ResourceStore based on preferences

This commit is contained in:
Joachim Van Herwegen
2020-08-04 10:23:00 +02:00
parent d6a35f9954
commit 5e1bb10f81
17 changed files with 565 additions and 79 deletions

View File

@@ -1,8 +1,7 @@
import { Conditions } from './Conditions';
import { PassthroughStore } from './PassthroughStore';
import { Patch } from '../ldp/http/Patch';
import { PatchHandler } from './patch/PatchHandler';
import { Representation } from '../ldp/representation/Representation';
import { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences';
import { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
import { ResourceStore } from './ResourceStore';
@@ -11,34 +10,14 @@ import { ResourceStore } from './ResourceStore';
* If the original store supports the {@link Patch}, behaviour will be identical,
* otherwise one of the {@link PatchHandler}s supporting the given Patch will be called instead.
*/
export class PatchingStore implements ResourceStore {
private readonly source: ResourceStore;
export class PatchingStore extends PassthroughStore {
private readonly patcher: PatchHandler;
public constructor(source: ResourceStore, patcher: PatchHandler) {
this.source = source;
super(source);
this.patcher = patcher;
}
public async addResource(container: ResourceIdentifier, representation: Representation,
conditions?: Conditions): Promise<ResourceIdentifier> {
return this.source.addResource(container, representation, conditions);
}
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
return this.source.deleteResource(identifier, conditions);
}
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
conditions?: Conditions): Promise<Representation> {
return this.source.getRepresentation(identifier, preferences, conditions);
}
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
conditions?: Conditions): Promise<void> {
return this.source.setRepresentation(identifier, representation, conditions);
}
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
try {
return await this.source.modifyResource(identifier, patch, conditions);