Skip to content

Commit 1cf9354

Browse files
committed
feat: Add types for renderStream & pipeableStream
1 parent 8ec4fa5 commit 1cf9354

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/stream-node.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { VNode } from 'preact';
2+
import { WritableStream } from 'node:stream';
3+
4+
interface RenderToPipeableStreamOptions {
5+
onShellReady?: () => void;
6+
onAllReady?: () => void;
7+
onError?: (error: any) => void;
8+
}
9+
10+
interface PipeableStream {
11+
abort: () => void;
12+
pipe: (writable: WritableStream) => void;
13+
}
14+
15+
export function renderToReadableStream(
16+
vnode: VNode,
17+
options: RenderToPipeableStreamOptions,
18+
context?: any
19+
): PipeableStream;

src/stream-node.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ import { renderToChunks } from './lib/chunked.js';
88
* @property {(error) => void} [onError]
99
*/
1010

11+
/**
12+
* @typedef {object} PipeableStream
13+
* @property {() => void} abort
14+
* @property {(writable: import('stream').Writable) => void} pipe
15+
*/
16+
1117
/**
1218
* @param {import('preact').VNode} vnode
1319
* @param {RenderToPipeableStreamOptions} options
1420
* @param {any} [context]
15-
* @returns {{}}
21+
* @returns {PipeableStream}
1622
*/
1723
export function renderToPipeableStream(vnode, options, context) {
1824
const encoder = new TextEncoder('utf-8');

src/stream.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { VNode } from 'preact';
2+
3+
interface RenderStream extends ReadableStream<Uint8Array> {
4+
allReady: Promise<void>;
5+
}
6+
7+
export function renderToReadableStream(
8+
vnode: VNode,
9+
context?: any
10+
): RenderStream;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy