@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
46 lines (45 loc) • 2.1 kB
TypeScript
import type { Representation } from '../../http/representation/Representation';
import type { ResourceIdentifier } from '../../http/representation/ResourceIdentifier';
import type { ResourceStore } from '../ResourceStore';
import type { KeyValueStorage } from './KeyValueStorage';
/**
* A {@link KeyValueStorage} for JSON-like objects using a {@link ResourceStore} as backend.
*
* Creates a base URL by joining the input base URL with the container string.
* The storage assumes it has ownership over all entries in the target container
* so no other classes should access resources there to prevent issues.
*
* Assumes the input keys can be safely used to generate identifiers,
* which will be appended to the stored base URL.
*
* All non-404 errors will be re-thrown.
*/
export declare class JsonResourceStorage<T> implements KeyValueStorage<string, T> {
protected readonly logger: import("global-logger-factory").Logger<unknown>;
protected readonly source: ResourceStore;
protected readonly container: string;
constructor(source: ResourceStore, baseUrl: string, container: string);
get(key: string): Promise<T | undefined>;
has(key: string): Promise<boolean>;
set(key: string, value: unknown): Promise<this>;
delete(key: string): Promise<boolean>;
entries(): AsyncIterableIterator<[string, T]>;
/**
* Recursively iterates through the container to find all documents.
*/
protected getResourceEntries(identifier: ResourceIdentifier): AsyncIterableIterator<[string, T]>;
/**
* Returns the representation for the given identifier.
* Returns undefined if a 404 error is thrown.
* Re-throws the error in all other cases.
*/
protected safelyGetResource(identifier: ResourceIdentifier): Promise<Representation | undefined>;
/**
* Converts a key into an identifier for internal storage.
*/
protected keyToIdentifier(key: string): ResourceIdentifier;
/**
* Converts an internal identifier to an external key.
*/
protected identifierToKey(identifier: ResourceIdentifier): string;
}