feat: Include parent containers in POST and DELETE changes.

This commit is contained in:
Ruben Verborgh
2020-11-20 22:28:26 +01:00
parent 0099d1d5dc
commit d8799368fd
2 changed files with 51 additions and 24 deletions

View File

@@ -3,6 +3,7 @@ import type { Patch } from '../ldp/http/Patch';
import type { Representation } from '../ldp/representation/Representation';
import type { RepresentationPreferences } from '../ldp/representation/RepresentationPreferences';
import type { ResourceIdentifier } from '../ldp/representation/ResourceIdentifier';
import { getParentContainer } from '../util/PathUtil';
import type { Conditions } from './Conditions';
import type { ResourceStore } from './ResourceStore';
@@ -22,12 +23,24 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
public async addResource(container: ResourceIdentifier, representation: Representation,
conditions?: Conditions): Promise<ResourceIdentifier> {
const identifier = await this.source.addResource(container, representation, conditions);
// Both the container contents and the resource itself have changed
this.emit('changed', container);
this.emit('changed', identifier);
return identifier;
}
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
await this.source.deleteResource(identifier, conditions);
// Both the container contents and the resource itself have changed
try {
const container = getParentContainer(identifier);
this.emit('changed', container);
} catch {
// Parent container not found
}
this.emit('changed', identifier);
}