@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
57 lines (56 loc) • 2.72 kB
TypeScript
import { PassThrough } from 'node:stream';
import type { RepresentationMetadata } from '../../http/representation/RepresentationMetadata';
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
import type { Guarded } from '../../util/GuardedStream';
import type { Size } from '../size-reporter/Size';
import type { SizeReporter } from '../size-reporter/SizeReporter';
/**
* A QuotaStrategy is used when we want to set a limit to the amount of data that can be
* stored on the server.
* This can range from a limit for the whole server to a limit on a per pod basis.
* The way the size of a resource is calculated is implemented by the implementing classes.
* This can be bytes, quads, file count, ...
*/
export declare abstract class QuotaStrategy {
readonly reporter: SizeReporter<unknown>;
readonly limit: Size;
protected constructor(reporter: SizeReporter<unknown>, limit: Size);
/**
* Get the available space when writing data to the given identifier.
* If the given resource already exists it will deduct the already taken up
* space by that resource since it is going to be overwritten and thus counts
* as available space.
*
* @param identifier - the identifier of the resource of which you want the available space
*
* @returns the available space and the unit of the space as a Size object
*/
getAvailableSpace(identifier: ResourceIdentifier): Promise<Size>;
/**
* Get the currently used/occupied space.
*
* @param identifier - the identifier that should be used to calculate the total
*
* @returns a Size object containing the requested value.
* If quota is not relevant for this identifier, Size.amount should be Number.MAX_SAFE_INTEGER
*/
protected abstract getTotalSpaceUsed(identifier: ResourceIdentifier): Promise<Size>;
/**
* Get an estimated size of the resource
*
* @param metadata - the metadata that might include the size
*
* @returns a Size object containing the estimated size and unit of the resource
*/
estimateSize(metadata: RepresentationMetadata): Promise<Size | undefined>;
/**
* Get a Passthrough stream that will keep track of the available space.
* If the quota is exceeded the stream will emit an error and destroy itself.
* Like other Passthrough instances this will simply pass on the chunks, when the quota isn't exceeded.
*
* @param identifier - the identifier of the resource in question
*
* @returns a Passthrough instance that errors when quota is exceeded
*/
createQuotaGuard(identifier: ResourceIdentifier): Promise<Guarded<PassThrough>>;
}