(
url: string | (() => string),
options: XhrConnectionOptionsResolver = {},
)
| 893 | * Create an XMLHttpRequest-backed newline-delimited JSON stream adapter. |
| 894 | */ |
| 895 | export function xhrHttpStream( |
| 896 | url: string | (() => string), |
| 897 | options: XhrConnectionOptionsResolver = {}, |
| 898 | ): ConnectConnectionAdapter { |
| 899 | return { |
| 900 | async *connect(messages, data, abortSignal, runContext) { |
| 901 | const resolvedUrl = typeof url === 'function' ? url() : url |
| 902 | const resolvedOptions = await resolveXhrConnectionOptions(options) |
| 903 | const signal = abortSignal || resolvedOptions.signal |
| 904 | const request = createConfiguredXhrRequest( |
| 905 | resolvedUrl, |
| 906 | resolvedOptions, |
| 907 | messages, |
| 908 | data, |
| 909 | runContext, |
| 910 | ) |
| 911 | const lines = readXhrLines(request.xhr, signal) |
| 912 | if (signal?.aborted) { |
| 913 | await lines.next() |
| 914 | return |
| 915 | } |
| 916 | request.xhr.send(request.body) |
| 917 | |
| 918 | for await (const line of lines) { |
| 919 | yield JSON.parse(line) as StreamChunk |
| 920 | } |
| 921 | }, |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | /** |
| 926 | * Create a direct stream connection adapter (for server functions or direct streams) |
no outgoing calls
no test coverage detected