Skip to content

Commit

Permalink
fix ts
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Jul 3, 2024
1 parent f5cb669 commit 735bfdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
4 changes: 2 additions & 2 deletions vike/node/runtime/html/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { HtmlRender } from './renderHtml.js'
import {
getStreamFromReactStreaming,
isStreamReactStreaming,
StreamReactStreaming,
StreamReactStreamingPublic,
streamReactStreamingToString
} from './stream/react-streaming.js'
import { import_ } from '@brillout/import'
Expand All @@ -71,7 +71,7 @@ type StreamProviderNormalized =
| StreamPipeNode
type StreamProviderAny =
| StreamProviderNormalized
| StreamReactStreaming
| StreamReactStreamingPublic
// pipeWebStream()
| StreamPipeWebWrapped
// pipeNodeStream()
Expand Down
35 changes: 8 additions & 27 deletions vike/node/runtime/html/stream/react-streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,16 @@ export { isStreamReactStreaming }
export { streamReactStreamingToString }
export { getStreamFromReactStreaming }
export type { StreamReactStreaming }
export type { InjectToStream }
export type { StreamReactStreamingPublic }

import type { renderToStream } from 'react-streaming/server'
import { assert, assertUsage, hasProp, isVikeReactApp } from '../../utils.js'
import { streamPipeNodeToString, StreamReadableWeb, streamReadableWebToString, StreamWritableNode } from '../stream.js'

// Same as:
// ```
// import type { InjectToStream } from 'react-streaming/server'
// ```
type InjectToStreamOptions = { flush?: boolean; tolerateStreamEnded?: boolean }
type InjectToStream = (chunk: unknown, options?: InjectToStreamOptions) => boolean
// We use this simplistic public type to avoid type mismatches (when the user installed another version than Vike's devDependency#react-streaming install).
type StreamReactStreamingPublic = { injectToStream: Function }
type StreamReactStreaming = Awaited<ReturnType<typeof renderToStream>>

// ```js
// import { renderToStream } from 'react-streaming/server'
// const { pipe, readable, injectToStream } = await renderToStream()`
// ```
type StreamReactStreaming = {
injectToStream: InjectToStream
hasStreamEnded: () => boolean
disabled: boolean
} & (
| {
pipe: (writable: StreamWritableNode) => void
readable: null
}
| {
pipe: null
readable: StreamReadableWeb
}
)
function streamReactStreamingToString(stream: StreamReactStreaming) {
if (stream.pipe) {
return streamPipeNodeToString(stream.pipe)
Expand All @@ -58,9 +38,10 @@ function isStreamReactStreaming(thing: unknown): thing is StreamReactStreaming {
return false
}

function getStreamFromReactStreaming(stream: StreamReactStreaming) {
type Pipe = { __streamPipeNode: (writable: StreamWritableNode) => void }
type Readable = StreamReadableWeb
function getStreamFromReactStreaming(stream: StreamReactStreaming): Pipe | Readable {
if (stream.pipe) {
// TODO
return { __streamPipeNode: stream.pipe }
}
if (stream.readable) {
Expand Down

0 comments on commit 735bfdf

Please sign in to comment.