@webda/core
Version:
Expose API with Lambda
161 lines (160 loc) • 4.41 kB
TypeScript
import { Readable, Transform, TransformCallback, Writable } from "stream";
type WalkerOptionsType = {
followSymlinks?: boolean;
resolveSymlink?: boolean;
includeDir?: boolean;
maxDepth?: number;
};
type FinderOptionsType = WalkerOptionsType & {
filterPattern?: RegExp;
processor?: (filepath: string) => void;
};
/**
* NDJSONStream is a Readable stream that emits JSON objects separated by newlines.
*/
export declare class NDJSONStream extends Readable {
private data;
private index;
constructor(data: any[]);
_read(): void;
}
/**
* Read a NDJSON stream
*/
export declare class NDJSonReader extends Writable {
current: string;
_write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
}
/**
* Gunzip a stream only if it is gzipped
*/
export declare class GunzipConditional extends Transform {
first: boolean;
zlib: Transform;
destination: NodeJS.WritableStream;
source: any;
constructor();
pipe<T extends NodeJS.WritableStream>(destination: T, options?: {
end?: boolean;
}): T;
_transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
}
/**
* Type of format managed
*/
type Format = "json" | "yaml";
/**
* Define a Finder that can be use
*/
export interface StorageFinder {
/**
* Recursively browse the path and call processor on each
*/
walk(path: string, processor: (filepath: string) => void, options?: WalkerOptionsType, depth?: number): void;
/**
* Find
*/
find(currentPath: string, options?: FinderOptionsType): string[];
/**
* Get a write stream based on the id return by the finder
*/
getWriteStream(path: string): Writable;
/**
* Get a read stream based on the id return by the finder
*/
getReadStream(path: string): Readable;
}
/**
* Allow save/load of yaml or json file
*/
export declare const FileUtils: StorageFinder & {
save: (object: any, filename: string, publicAudience?: boolean, format?: Format) => void;
load: (filename: string, format?: Format) => any;
clean: (...files: string[]) => void;
};
/**
* Simple JSON utils
*/
export declare const JSONUtils: {
/**
* Safe Stringify stringify a object included circular object
* and also remove any attributes starting with a __
*
* @param value
* @param replacer
* @param space
* @returns
*/
safeStringify: (value: any, replacer?: (key: string, value: any) => any, space?: number | string, publicAudience?: boolean) => string;
/**
* See JSON.stringify
*
* @param value
* @param replacer
* @param space
* @returns
*/
stringify: (value: any, replacer?: (key: string, value: any) => any, space?: number | string, publicAudience?: boolean) => string;
/**
* Parse a JSON data
*
* @param value to parse
* @returns object parsed
*/
parse: (value: any) => any;
/**
* Duplicate an object using serializer
*/
duplicate: (value: any) => any;
/**
* Visit a json/jsonc file for update
* @param filename
*/
updateFile: (filename: string, replacer: (value: any) => any) => Promise<void>;
/**
* Helper to FileUtils.save
*/
loadFile: (filename: string) => any;
/**
* Helper to FileUtils.save
*/
saveFile: (object: any, filename: string, publicAudience?: boolean) => void;
/**
* Sort object keys
* @param unordered
* @returns
*/
sortObject: (unordered: any, transformer?: (obj: any) => any) => any;
};
/**
* Expose basic YAML function
*/
export declare const YAMLUtils: {
/**
* Helper to FileUtils.save
*/
loadFile: (filename: string) => any;
/**
* Helper to FileUtils.save
*/
saveFile: (object: any, filename: string, publicAudience?: boolean) => void;
/**
* Duplicate an object using serializer
*/
duplicate: (value: any) => any;
/**
* Parse a single or multiple document yaml
*
* @param value to parse
* @returns object parsed
*/
parse: (value: any) => any;
/**
* YAML helper
* @param value to serialize
* @param options as defined by https://eemeli.org/yaml/v1/#yaml-stringify
* @returns
*/
stringify: (value: any, options?: any) => string;
};
export {};