index.d.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. declare module '@discoveryjs/json-ext' {
  2. type Chunk = string | Uint8Array | Buffer;
  3. type Reviver = (this: any, key: string, value: any) => any;
  4. type ParseChunkState = {
  5. readonly mode: 'json' | 'jsonl';
  6. readonly rootValuesCount: number;
  7. readonly consumed: number;
  8. readonly parsed: number;
  9. };
  10. type OnRootValue = (value: any, state: ParseChunkState) => void;
  11. type OnChunk = (chunkParsed: number, chunk: string | null, pending: string | null, state: ParseChunkState) => void;
  12. type ParseOptions = {
  13. reviver?: Reviver;
  14. mode?: 'json' | 'jsonl' | 'auto';
  15. onRootValue?: OnRootValue;
  16. onChunk?: OnChunk;
  17. };
  18. type Replacer =
  19. | ((this: any, key: string, value: any) => any)
  20. | (string | number)[]
  21. | null;
  22. type Space = string | number | null;
  23. type StringifyOptions = {
  24. replacer?: Replacer;
  25. space?: Space;
  26. mode?: 'json' | 'jsonl';
  27. highWaterMark?: number;
  28. }
  29. type StringifyInfoOptions = {
  30. replacer?: Replacer;
  31. space?: Space;
  32. mode?: 'json' | 'jsonl';
  33. continueOnCircular?: boolean;
  34. }
  35. type StringifyInfoResult = {
  36. bytes: number;
  37. spaceBytes: number;
  38. circular: object[];
  39. };
  40. export function parseChunked(input: Iterable<Chunk> | AsyncIterable<Chunk>, reviver?: Reviver): Promise<any>;
  41. export function parseChunked(input: Iterable<Chunk> | AsyncIterable<Chunk>, options: ParseOptions & { onRootValue: OnRootValue }): Promise<number>;
  42. export function parseChunked(input: Iterable<Chunk> | AsyncIterable<Chunk>, options?: ParseOptions): Promise<any>;
  43. export function parseChunked(input: () => (Iterable<Chunk> | AsyncIterable<Chunk>), reviver?: Reviver): Promise<any>;
  44. export function parseChunked(input: () => (Iterable<Chunk> | AsyncIterable<Chunk>), options: ParseOptions & { onRootValue: OnRootValue }): Promise<number>;
  45. export function parseChunked(input: () => (Iterable<Chunk> | AsyncIterable<Chunk>), options?: ParseOptions): Promise<any>;
  46. export function stringifyChunked(value: any, replacer?: Replacer, space?: Space): Generator<string>;
  47. export function stringifyChunked(value: any, options: StringifyOptions): Generator<string>;
  48. export function stringifyInfo(value: any, replacer?: Replacer, space?: Space): StringifyInfoResult;
  49. export function stringifyInfo(value: any, options?: StringifyInfoOptions): StringifyInfoResult;
  50. // Web streams
  51. export function parseFromWebStream(stream: ReadableStream<Chunk>): Promise<any>;
  52. export function createStringifyWebStream(value: any, replacer?: Replacer, space?: Space): ReadableStream<string>;
  53. export function createStringifyWebStream(value: any, options: StringifyOptions): ReadableStream<string>;
  54. }