feat: Make stores return modified resources.

This commit is contained in:
Ruben Verborgh
2021-02-23 22:58:39 +01:00
committed by Joachim Van Herwegen
parent 28c0eb7e88
commit 6edc255707
23 changed files with 228 additions and 124 deletions

View File

@@ -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[]>;
}