UNPKG

giantdb

Version:

Large object database in native JavaScript, with encryption support

89 lines (88 loc) 3.29 kB
/// <reference types="node" /> import { Adapter } from 'fs-adapters'; import { MiddlewareManager } from './middleware/manager.js'; import { TransformResult } from './middleware/transformable.js'; import { Readable, Writable } from 'node:stream'; /** * Helper class for I/O operations. */ export declare class IOManager { private readonly _adapter; private readonly _middlewareManager; /** * Construct a new IOManager. * * @param adapter The IO adapter. * @param middlewareManager The middleware manager. */ constructor(adapter: Adapter, middlewareManager: MiddlewareManager); /** * Create a read stream for the item with the given id. Since this step may * modify item metadata, the result is an object with the following properties: * 'stream' (the readable stream), 'metadata' (the new metadata), and * 'metadataChanged' (a boolean indicating whether the metadata was modified). * * @param id The item id. * @param meta The item metadata. * @param options Middleware options. * @returns A Promise resolving to a result object. */ createReadStream(id: string, meta: object, options?: object): Promise<TransformResult<Readable>>; /** * Create a write stream for the item with the given id. Since this step may * modify item metadata, the result is an object with the following properties: * 'stream' (the writable stream), 'metadata' (the new metadata), and * 'metadataChanged' (a boolean indicating whether the metadata was modified). * * @param id The item id. * @param meta The item metadata. * @param options Middleware options. * @returns A Promise resolving to a result object. */ createWriteStream(id: string, meta: object, options?: object): Promise<TransformResult<Writable>>; /** * Create a temporary write stream to an item that can be published later. * * @param id The item id. * @param options Middleware options. * @returns A Promise that resolves to a Writable Stream. */ createTemporary(id: string, options?: object): Promise<Writable>; /** * Mark the item with the given id as non-temporary as part of the commit * process. * * @param id The item id. * @returns A Promise that resolves when done. */ publish(id: string): Promise<void>; /** * Delete all data for the item with the given id. * * @param id The item id. * @returns A Promise that resolves when done. */ delete(id: string): Promise<void>; /** * Delete the temporary item with the given id. * * @param id The item id. * @returns A Promise that resolves when done. */ deleteTemporary(id: string): Promise<void>; /** * Read the metadata object for the item with the given id. * * @param id The item's id. * @returns A Promise that resolves to the metadata. */ readMetadata(id: string): Promise<object>; /** * Write a metadata object for the item with the given id. * * @param id The item's id. * @param metadata The metadata to write. * @returns A Promise that resolves when done. */ writeMetadata(id: string, metadata: object): Promise<void>; }