mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Make stores return modified resources.
This commit is contained in:
committed by
Joachim Van Herwegen
parent
28c0eb7e88
commit
6edc255707
@@ -11,26 +11,28 @@ import type { ResourceStore } from './ResourceStore';
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
export class BaseResourceStore implements ResourceStore {
|
||||
public async addResource(container: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
conditions?: Conditions): Promise<Representation> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
public async addResource(container: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new NotImplementedHttpError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
return newID;
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation): Promise<void> {
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation):
|
||||
Promise<ResourceIdentifier[]> {
|
||||
this.validateIdentifier(identifier);
|
||||
|
||||
// Ensure the representation is supported by the accessor
|
||||
@@ -161,14 +162,14 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
}
|
||||
|
||||
// Potentially have to create containers if it didn't exist yet
|
||||
await this.writeData(identifier, representation, isContainer, !oldMetadata);
|
||||
return this.writeData(identifier, representation, isContainer, !oldMetadata);
|
||||
}
|
||||
|
||||
public async modifyResource(): Promise<void> {
|
||||
public async modifyResource(): Promise<ResourceIdentifier[]> {
|
||||
throw new NotImplementedHttpError('Patches are not supported by the default store.');
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<ResourceIdentifier[]> {
|
||||
this.validateIdentifier(identifier);
|
||||
const metadata = await this.accessor.getMetadata(identifier);
|
||||
// Solid, §5.4: "When a DELETE request targets storage’s root container or its associated ACL resource,
|
||||
@@ -199,11 +200,14 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
// Solid, §5.4: "When a contained resource is deleted, the server MUST also delete the associated auxiliary
|
||||
// resources"
|
||||
// https://solid.github.io/specification/protocol#deleting-resources
|
||||
const deleted = [];
|
||||
if (!this.auxiliaryStrategy.isAuxiliaryIdentifier(identifier)) {
|
||||
await this.safelyDeleteAuxiliaryResources(this.auxiliaryStrategy.getAuxiliaryIdentifiers(identifier));
|
||||
const auxiliaries = this.auxiliaryStrategy.getAuxiliaryIdentifiers(identifier);
|
||||
deleted.push(...await this.safelyDeleteAuxiliaryResources(auxiliaries));
|
||||
}
|
||||
|
||||
return this.accessor.deleteResource(identifier);
|
||||
deleted.unshift(...await this.accessor.deleteResource(identifier));
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -265,9 +269,11 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
* @param representation - Corresponding Representation.
|
||||
* @param isContainer - Is the incoming resource a container?
|
||||
* @param createContainers - Should parent containers (potentially) be created?
|
||||
*
|
||||
* @returns Identifiers of resources that were possibly modified.
|
||||
*/
|
||||
protected async writeData(identifier: ResourceIdentifier, representation: Representation, isContainer: boolean,
|
||||
createContainers?: boolean): Promise<void> {
|
||||
createContainers?: boolean): Promise<ResourceIdentifier[]> {
|
||||
// Make sure the metadata has the correct identifier and correct type quads
|
||||
// Need to do this before handling container data to have the correct identifier
|
||||
const { metadata } = representation;
|
||||
@@ -288,13 +294,22 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
// Solid, §5.3: "Servers MUST create intermediate containers and include corresponding containment triples
|
||||
// in container representations derived from the URI path component of PUT and PATCH requests."
|
||||
// https://solid.github.io/specification/protocol#writing-resources
|
||||
if (createContainers && !this.identifierStrategy.isRootContainer(identifier)) {
|
||||
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(identifier));
|
||||
const modified = [];
|
||||
if (!this.identifierStrategy.isRootContainer(identifier)) {
|
||||
const container = this.identifierStrategy.getParentContainer(identifier);
|
||||
if (!createContainers) {
|
||||
modified.push(container);
|
||||
} else {
|
||||
const created = await this.createRecursiveContainers(container);
|
||||
modified.push(...created.length === 0 ? [ container ] : created);
|
||||
}
|
||||
}
|
||||
|
||||
await (isContainer ?
|
||||
this.accessor.writeContainer(identifier, representation.metadata) :
|
||||
this.accessor.writeDocument(identifier, representation.data, representation.metadata));
|
||||
|
||||
return [ ...modified, identifier ];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -442,10 +457,12 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
* Deletes the given array of auxiliary identifiers.
|
||||
* Does not throw an error if something goes wrong.
|
||||
*/
|
||||
protected async safelyDeleteAuxiliaryResources(identifiers: ResourceIdentifier[]): Promise<void[]> {
|
||||
return Promise.all(identifiers.map(async(identifier): Promise<void> => {
|
||||
protected async safelyDeleteAuxiliaryResources(identifiers: ResourceIdentifier[]): Promise<ResourceIdentifier[]> {
|
||||
const deleted: ResourceIdentifier[] = [];
|
||||
await Promise.all(identifiers.map(async(identifier): Promise<void> => {
|
||||
try {
|
||||
await this.accessor.deleteResource(identifier);
|
||||
deleted.push(identifier);
|
||||
} catch (error: unknown) {
|
||||
if (!NotFoundHttpError.isInstance(error)) {
|
||||
const errorMsg = isNativeError(error) ? error.message : error;
|
||||
@@ -453,6 +470,7 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
}
|
||||
}
|
||||
}));
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -460,7 +478,8 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
* Will throw errors if the identifier of the last existing "container" corresponds to an existing document.
|
||||
* @param container - Identifier of the container which will need to exist.
|
||||
*/
|
||||
protected async createRecursiveContainers(container: ResourceIdentifier): Promise<void> {
|
||||
protected async createRecursiveContainers(container: ResourceIdentifier): Promise<ResourceIdentifier[]> {
|
||||
// Verify whether the container already exists
|
||||
try {
|
||||
const metadata = await this.getNormalizedMetadata(container);
|
||||
// See #480
|
||||
@@ -471,16 +490,18 @@ export class DataAccessorBasedStore implements ResourceStore {
|
||||
if (!isContainerPath(metadata.identifier.value)) {
|
||||
throw new ForbiddenHttpError(`Creating container ${container.path} conflicts with an existing resource.`);
|
||||
}
|
||||
return [];
|
||||
} catch (error: unknown) {
|
||||
if (NotFoundHttpError.isInstance(error)) {
|
||||
// Make sure the parent exists first
|
||||
if (!this.identifierStrategy.isRootContainer(container)) {
|
||||
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container));
|
||||
}
|
||||
await this.writeData(container, new BasicRepresentation([], container), true);
|
||||
} else {
|
||||
if (!NotFoundHttpError.isInstance(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the container, starting with its parent
|
||||
const ancestors = this.identifierStrategy.isRootContainer(container) ?
|
||||
[] :
|
||||
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(container));
|
||||
await this.writeData(container, new BasicRepresentation([], container), true);
|
||||
return [ ...ancestors, container ];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,19 +48,21 @@ export class LockingResourceStore implements AtomicResourceStore {
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.locks.withWriteLock(this.getLockIdentifier(identifier),
|
||||
async(): Promise<void> => this.source.setRepresentation(identifier, representation, conditions));
|
||||
async(): Promise<ResourceIdentifier[]> => this.source.setRepresentation(identifier, representation, conditions));
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.locks.withWriteLock(this.getLockIdentifier(identifier),
|
||||
async(): Promise<void> => this.source.deleteResource(identifier, conditions));
|
||||
async(): Promise<ResourceIdentifier[]> => this.source.deleteResource(identifier, conditions));
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.locks.withWriteLock(this.getLockIdentifier(identifier),
|
||||
async(): Promise<void> => this.source.modifyResource(identifier, patch, conditions));
|
||||
async(): Promise<ResourceIdentifier[]> => this.source.modifyResource(identifier, patch, conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,8 +33,9 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
await this.source.deleteResource(identifier, conditions);
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
const modified = await this.source.deleteResource(identifier, conditions);
|
||||
|
||||
// Both the container contents and the resource itself have changed
|
||||
if (!this.identifierStrategy.isRootContainer(identifier)) {
|
||||
@@ -42,6 +43,8 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
|
||||
this.emit('changed', container);
|
||||
}
|
||||
this.emit('changed', identifier);
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
public async getRepresentation(identifier: ResourceIdentifier, preferences: RepresentationPreferences,
|
||||
@@ -49,14 +52,17 @@ export class MonitoringStore<T extends ResourceStore = ResourceStore>
|
||||
return this.source.getRepresentation(identifier, preferences, conditions);
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
await this.source.modifyResource(identifier, patch, conditions);
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
const modified = await this.source.modifyResource(identifier, patch, conditions);
|
||||
this.emit('changed', identifier);
|
||||
return modified;
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
await this.source.setRepresentation(identifier, representation, conditions);
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
const modified = await this.source.setRepresentation(identifier, representation, conditions);
|
||||
this.emit('changed', identifier);
|
||||
return modified;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,8 @@ export class PassthroughStore<T extends ResourceStore = ResourceStore> implement
|
||||
return this.source.addResource(container, representation, conditions);
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.source.deleteResource(identifier, conditions);
|
||||
}
|
||||
|
||||
@@ -31,12 +32,13 @@ export class PassthroughStore<T extends ResourceStore = ResourceStore> implement
|
||||
return this.source.getRepresentation(identifier, preferences, conditions);
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.source.modifyResource(identifier, patch, conditions);
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return this.source.setRepresentation(identifier, representation, conditions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ export class PatchingStore<T extends ResourceStore = ResourceStore> extends Pass
|
||||
this.patcher = patcher;
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
try {
|
||||
return await this.source.modifyResource(identifier, patch, conditions);
|
||||
} catch {
|
||||
|
||||
@@ -20,16 +20,18 @@ export class ReadOnlyStore<T extends ResourceStore = ResourceStore> extends Pass
|
||||
throw new ForbiddenHttpError();
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new ForbiddenHttpError();
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions): Promise<void> {
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new ForbiddenHttpError();
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
throw new ForbiddenHttpError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export class RepresentationConvertingStore<T extends ResourceStore = ResourceSto
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
representation = await this.inConverter.handleSafe({ identifier, representation, preferences: this.inPreferences });
|
||||
return this.source.setRepresentation(identifier, representation, conditions);
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ import type { Conditions } from './Conditions';
|
||||
*/
|
||||
export interface ResourceStore {
|
||||
/**
|
||||
* Read a resource.
|
||||
* Retrieves a representation of a resource.
|
||||
* @param identifier - Identifier of the resource to read.
|
||||
* @param preferences - Representation preferences.
|
||||
* @param conditions - Optional conditions.
|
||||
* @param preferences - Preferences indicating desired representations.
|
||||
* @param conditions - Optional conditions under which to proceed.
|
||||
*
|
||||
* @returns A promise containing the representation.
|
||||
* @returns A representation corresponding to the identifier.
|
||||
*/
|
||||
getRepresentation: (
|
||||
identifier: ResourceIdentifier,
|
||||
@@ -31,12 +31,27 @@ export interface ResourceStore {
|
||||
) => Promise<Representation>;
|
||||
|
||||
/**
|
||||
* Create a resource.
|
||||
* Sets or replaces the representation of a resource,
|
||||
* creating a new resource and intermediary containers as needed.
|
||||
* @param identifier - Identifier of resource to update.
|
||||
* @param representation - New representation of the resource.
|
||||
* @param conditions - Optional conditions under which to proceed.
|
||||
*
|
||||
* @returns Identifiers of resources that were possibly modified.
|
||||
*/
|
||||
setRepresentation: (
|
||||
identifier: ResourceIdentifier,
|
||||
representation: Representation,
|
||||
conditions?: Conditions,
|
||||
) => Promise<ResourceIdentifier[]>;
|
||||
|
||||
/**
|
||||
* Creates a new resource in the container.
|
||||
* @param container - Container in which to create a resource.
|
||||
* @param representation - Representation of the new resource
|
||||
* @param conditions - Optional conditions.
|
||||
* @param conditions - Optional conditions under which to proceed.
|
||||
*
|
||||
* @returns A promise containing the new identifier.
|
||||
* @returns The identifier of the newly created resource.
|
||||
*/
|
||||
addResource: (
|
||||
container: ResourceIdentifier,
|
||||
@@ -45,35 +60,29 @@ export interface ResourceStore {
|
||||
) => Promise<ResourceIdentifier>;
|
||||
|
||||
/**
|
||||
* Fully update a resource.
|
||||
* @param identifier - Identifier of resource to update.
|
||||
* @param representation - New representation of the resource.
|
||||
* @param conditions - Optional conditions.
|
||||
*
|
||||
* @returns A promise resolving when the update is finished.
|
||||
*/
|
||||
setRepresentation: (
|
||||
identifier: ResourceIdentifier,
|
||||
representation: Representation,
|
||||
conditions?: Conditions,
|
||||
) => Promise<void>;
|
||||
|
||||
/**
|
||||
* Delete a resource.
|
||||
* Deletes a resource.
|
||||
* @param identifier - Identifier of resource to delete.
|
||||
* @param conditions - Optional conditions.
|
||||
* @param conditions - Optional conditions under which to proceed.
|
||||
*
|
||||
* @returns A promise resolving when the delete is finished.
|
||||
* @returns Identifiers of resources that were possibly modified.
|
||||
*/
|
||||
deleteResource: (identifier: ResourceIdentifier, conditions?: Conditions) => Promise<void>;
|
||||
deleteResource: (
|
||||
identifier: ResourceIdentifier,
|
||||
conditions?: Conditions,
|
||||
) => Promise<ResourceIdentifier[]>;
|
||||
|
||||
/**
|
||||
* Partially update a resource.
|
||||
* Sets or updates the representation of a resource,
|
||||
* creating a new resource and intermediary containers as needed.
|
||||
* @param identifier - Identifier of resource to update.
|
||||
* @param patch - Description of which parts to update.
|
||||
* @param conditions - Optional conditions.
|
||||
* @param conditions - Optional conditions under which to proceed.
|
||||
*
|
||||
* @returns A promise resolving when the update is finished.
|
||||
* @returns Identifiers of resources that were possibly modified.
|
||||
*/
|
||||
modifyResource: (identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions) => Promise<void>;
|
||||
modifyResource: (
|
||||
identifier: ResourceIdentifier,
|
||||
patch: Patch,
|
||||
conditions?: Conditions,
|
||||
) => Promise<ResourceIdentifier[]>;
|
||||
}
|
||||
|
||||
@@ -31,16 +31,17 @@ export class RoutingResourceStore implements ResourceStore {
|
||||
}
|
||||
|
||||
public async setRepresentation(identifier: ResourceIdentifier, representation: Representation,
|
||||
conditions?: Conditions): Promise<void> {
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return (await this.getStore(identifier, representation)).setRepresentation(identifier, representation, conditions);
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier, conditions?: Conditions): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return (await this.getStore(identifier)).deleteResource(identifier, conditions);
|
||||
}
|
||||
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch, conditions?: Conditions):
|
||||
Promise<void> {
|
||||
public async modifyResource(identifier: ResourceIdentifier, patch: Patch,
|
||||
conditions?: Conditions): Promise<ResourceIdentifier[]> {
|
||||
return (await this.getStore(identifier)).modifyResource(identifier, patch, conditions);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ export interface DataAccessor {
|
||||
* https://solid.github.io/specification/protocol#deleting-resources
|
||||
*
|
||||
* @param identifier - Resource to delete.
|
||||
*
|
||||
* @returns Identifiers of resources that were possibly modified.
|
||||
*/
|
||||
deleteResource: (identifier: ResourceIdentifier) => Promise<void>;
|
||||
deleteResource: (identifier: ResourceIdentifier) => Promise<ResourceIdentifier[]>;
|
||||
}
|
||||
|
||||
@@ -117,12 +117,15 @@ export class FileDataAccessor implements DataAccessor {
|
||||
/**
|
||||
* Removes the corresponding file/folder (and metadata file).
|
||||
*/
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<ResourceIdentifier[]> {
|
||||
const link = await this.resourceMapper.mapUrlToFilePath(identifier);
|
||||
const metadataLink = await this.getMetadataLink(link.identifier);
|
||||
const stats = await this.getStats(link.filePath);
|
||||
const modified: ResourceIdentifier[] = [ identifier ];
|
||||
|
||||
try {
|
||||
await fsPromises.unlink((await this.getMetadataLink(link.identifier)).filePath);
|
||||
await fsPromises.unlink(metadataLink.filePath);
|
||||
modified.push(metadataLink.identifier);
|
||||
} catch (error: unknown) {
|
||||
// Ignore if it doesn't exist
|
||||
if (!isSystemError(error) || error.code !== 'ENOENT') {
|
||||
@@ -137,6 +140,8 @@ export class FileDataAccessor implements DataAccessor {
|
||||
} else {
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,13 +83,14 @@ export class InMemoryDataAccessor implements DataAccessor {
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<ResourceIdentifier[]> {
|
||||
const { parent, name } = this.getParentEntry(identifier);
|
||||
if (!parent.entries[name]) {
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
||||
delete parent.entries[name];
|
||||
return [ identifier ];
|
||||
}
|
||||
|
||||
private isDataEntry(entry: CacheEntry): entry is DataEntry {
|
||||
|
||||
@@ -134,9 +134,10 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
/**
|
||||
* Removes all graph data relevant to the given identifier.
|
||||
*/
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<void> {
|
||||
public async deleteResource(identifier: ResourceIdentifier): Promise<ResourceIdentifier[]> {
|
||||
const { name, parent } = this.getRelatedNames(identifier);
|
||||
return this.sendSparqlUpdate(this.sparqlDelete(name, parent));
|
||||
await this.sendSparqlUpdate(this.sparqlDelete(name, parent));
|
||||
return [ identifier ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,4 +2,5 @@ import type { Patch } from '../../ldp/http/Patch';
|
||||
import type { ResourceIdentifier } from '../../ldp/representation/ResourceIdentifier';
|
||||
import { AsyncHandler } from '../../util/handlers/AsyncHandler';
|
||||
|
||||
export abstract class PatchHandler extends AsyncHandler<{identifier: ResourceIdentifier; patch: Patch}> {}
|
||||
export abstract class PatchHandler
|
||||
extends AsyncHandler<{identifier: ResourceIdentifier; patch: Patch}, ResourceIdentifier[]> {}
|
||||
|
||||
@@ -34,13 +34,15 @@ export class SparqlUpdatePatchHandler extends PatchHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public async handle(input: {identifier: ResourceIdentifier; patch: SparqlUpdatePatch}): Promise<void> {
|
||||
public async handle(input: {identifier: ResourceIdentifier; patch: SparqlUpdatePatch}):
|
||||
Promise<ResourceIdentifier[]> {
|
||||
// Verify the patch
|
||||
const { identifier, patch } = input;
|
||||
const op = patch.algebra;
|
||||
this.validateUpdate(op);
|
||||
|
||||
await this.applyPatch(identifier, op);
|
||||
return [ identifier ];
|
||||
}
|
||||
|
||||
private isDeleteInsert(op: Algebra.Operation): op is Algebra.DeleteInsert {
|
||||
|
||||
Reference in New Issue
Block a user