UNPKG

@gecogvidanto/plugin-nedb

Version:

Nebd local database management plugin for ĞecoĞvidanto

66 lines (65 loc) 2.39 kB
/// <reference types="node" /> import BinaryStore, { BinaryData } from './BinaryStore'; export declare type BinaryFilter<T> = { [P in keyof T]: T[P] extends Buffer ? BinaryData : T[P] extends object ? BinaryFilter<T[P]> : T[P]; }; /** * This class manages the binary data. Binary data are transformed into an object for identification while * the real data is managed by the binary store. */ export default class BinaryDataManager { private readonly binaryStore; private readonly storeName; private readonly binaries; /** * Create a binary data manager. * * @param binaryStore - The binary store. * @param storeName - The name of the store creating this manager. */ constructor(binaryStore: BinaryStore, storeName: string); /** * Filter which should be input for a database calling method to replace binary data. Real binary data * will be ready to be saved. * * @param input - The input to filter. * @returns The filtered input. */ inputFilter<T>(input: T): Promise<BinaryFilter<T>>; /** * Filter all which should be output for a database calling method to replace hash with binary data. Data * will first be searched in filtered input data. * * @param outputs - The output to filter. * @returns The filtered output. */ outputFilterAll<T>(outputs: Array<BinaryFilter<T>>): Promise<T[]>; /** * Filter which should be output for a database calling method to replace hash with binary data. Data will * first be searched in filtered input data. * * @param output - The output to filter. * @returns The filtered output. */ outputFilter<T>(output: BinaryFilter<T>): Promise<T>; /** * Save the binary data seen while filtering input. * * @param recordId - The identifier of the current record to associate to binary data. */ save(recordId: string): Promise<void>; /** * Indicate if a given input has been transformed, meaning if binary data need to be (or already have * been) saved. * * @returns True if data need to be saved. */ get transformed(): boolean; /** * Search the binary data with the given hash. * * @param hash - The hash of the binary data to search for. * @returns The binary data for the hash. */ private searchData; }