streaming.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { ReadableStream, type Response } from "./_shims/index.js";
  2. export type ServerSentEvent = {
  3. event: string | null;
  4. data: string;
  5. raw: string[];
  6. };
  7. export declare class Stream<Item> implements AsyncIterable<Item> {
  8. private iterator;
  9. controller: AbortController;
  10. constructor(iterator: () => AsyncIterator<Item>, controller: AbortController);
  11. static fromSSEResponse<Item>(response: Response, controller: AbortController): Stream<Item>;
  12. /**
  13. * Generates a Stream from a newline-separated ReadableStream
  14. * where each item is a JSON value.
  15. */
  16. static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController): Stream<Item>;
  17. [Symbol.asyncIterator](): AsyncIterator<Item>;
  18. /**
  19. * Splits the stream into two streams which can be
  20. * independently read from at different speeds.
  21. */
  22. tee(): [Stream<Item>, Stream<Item>];
  23. /**
  24. * Converts this stream to a newline-separated ReadableStream of
  25. * JSON stringified values in the stream
  26. * which can be turned back into a Stream with `Stream.fromReadableStream()`.
  27. */
  28. toReadableStream(): ReadableStream;
  29. }
  30. export declare function _iterSSEMessages(response: Response, controller: AbortController): AsyncGenerator<ServerSentEvent, void, unknown>;
  31. //# sourceMappingURL=streaming.d.ts.map