@solid/community-server
Version:
Community Solid Server: an open and modular implementation of the Solid specifications
89 lines (88 loc) • 3.47 kB
TypeScript
import type { EventEmitter } from 'node:events';
import type { DuplexOptions, ReadableOptions, Writable } from 'node:stream';
import { Readable, Transform } from 'node:stream';
import { Store } from 'n3';
import type { Guarded } from './GuardedStream';
import type { Json } from './Json';
import type { PromiseOrValue } from './PromiseUtil';
export declare const endOfStream: (arg1: NodeJS.ReadableStream | NodeJS.WritableStream) => Promise<void>;
/**
* Converts the stream into an array.
*
* @param stream - Stream to convert.
*
* @returns Array containing the stream entries.
*/
export declare function arrayifyStream<T = unknown>(stream: EventEmitter): Promise<T[]>;
/**
* Joins all strings of a stream.
*
* @param stream - Stream of strings.
*
* @returns The joined string.
*/
export declare function readableToString(stream: Readable): Promise<string>;
/**
* Imports quads from a stream into a Store.
*
* @param stream - Stream of quads.
*
* @returns A Store containing all the quads.
*/
export declare function readableToQuads(stream: Readable): Promise<Store>;
/**
* Interprets the stream as JSON and converts it to a Dict.
*
* @param stream - Stream of JSON data.
*
* @returns The parsed object.
*/
export declare function readJsonStream(stream: Readable): Promise<Json>;
/**
* Converts the stream to a single object.
* This assumes the stream is in object mode and only contains a single element,
* otherwise an error will be thrown.
*
* @param stream - Object stream with single entry.
*/
export declare function getSingleItem(stream: Readable): Promise<unknown>;
/**
* Pipes one stream into another and emits errors of the first stream with the second.
* If the first stream errors, the second one will be destroyed with the given error.
* This will also make the stream {@link Guarded}.
*
* @param readable - Initial readable stream.
* @param destination - The destination for writing data.
* @param mapError - Optional function that takes the error and converts it to a new error.
*
* @returns The destination stream.
*/
export declare function pipeSafely<T extends Writable>(readable: NodeJS.ReadableStream, destination: T, mapError?: (error: Error) => Error): Guarded<T>;
export interface AsyncTransformOptions<T = unknown> extends DuplexOptions {
/**
* Transforms data from the source by calling the `push` method
*/
transform?: (this: Transform, data: T, encoding: string) => PromiseOrValue<unknown>;
/**
* Performs any final actions after the source has ended
*/
flush?: (this: Transform) => PromiseOrValue<unknown>;
}
/**
* Transforms a stream, ensuring that all errors are forwarded.
*
* @param source - The stream to be transformed.
* @param options - The transformation options.
* @param options.transform - The transform function to use.
* @param options.flush - The flush function to use.
*
* @returns The transformed stream
*/
export declare function transformSafely<T = unknown>(source: NodeJS.ReadableStream, { transform, flush, ...options }?: AsyncTransformOptions<T>): Guarded<Transform>;
/**
* Converts a string or array to a stream and applies an error guard so that it is {@link Guarded}.
*
* @param contents - Data to stream.
* @param options - Options to pass to the Readable constructor. See {@link Readable.from}.
*/
export declare function guardedStreamFrom(contents: string | Iterable<unknown>, options?: ReadableOptions): Guarded<Readable>;