UNPKG

harperdb

Version:

HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.

58 lines (57 loc) 2.35 kB
import { Readable } from 'stream'; type Deserialize = (data: Buffer) => { contentType?: string; data: unknown; } | unknown; export declare const contentTypes: Map<string, { serialize?: unknown; deserialize?: Deserialize; serializeStream?: unknown; compressible?: boolean; q?: number; }>; export declare function registerContentHandlers(app: any): void; /** * This is returns the best serializer for the request's Accept header (content negotiation) * @param incoming_message * @returns {{serializer, type: string, parameters: {q: number}}|{serializer(): void}} */ export declare function findBestSerializer(incoming_message: any): { serializer: any; type: any; parameters: any; }; /** * Serialize a response * @param response_data * @param request * @param response_object * @returns {Uint8Array|*} */ export declare function serialize(response_data: any, request: any, response_object: any): any; /** * Serialize a message, may be use multiple times (like with WebSockets) * @param message * @param request * @returns {*} */ export declare function serializeMessage(message: any, request?: Request, inAsyncContinuation?: boolean): Buffer | string | Promise<Buffer | string>; /** * This can be called during serialization indicating that an object requires asynchronous serialization (or async completion of a task prior to serialization) to be properly serialized. * A promise for when the object is ready to be serialized. Typically serialization will be re-executed and this object should be ready to be synchronously serialized * @param promiseToSerialize */ export declare function asyncSerialization(promiseToSerialize: Promise<any>): void; export declare function hasAsyncSerialization(): boolean; /** * Given a content-type header string, get a deserializer function that can be used to parse the body. */ export declare function getDeserializer(content_type_string: string, streaming: false): Deserialize; export declare function getDeserializer(content_type_string: string, streaming: true): (stream: Readable) => Promise<ReturnType<Deserialize>>; /** * Converts JS objects/arrays/iterators to a CSV stream. Should support iterators with full backpressure handling * @param data * @returns stream */ export declare function toCsvStream(data: any, columns: any): any; export {};