Open pg-wtatum opened 1 month ago
To elaborate further on the object -> JSON question, if I implement my server side as a typed generator that produces something other than string the inferred client type in treaty is AsyncGenerator[object Object]
instead
Sorry for the drip feed of info but the behavior is actually weirder than I first thought -- if I manually call JSON.stringify on the server, the values produced by
const res = await client.funky.get();
if (!res.error) {
for await (const d of res.data) {
console.log(d);
}
}
are objects rather than strings. This causes some significant typescript issues as I need to type the generator as string (but it actually returns objects)
edit to add I see that 1.1.3 was released today to address other issues related to the stream feature. I have updated and this appears to still be the case.
Currently implementing it using the Generator function as described in the docs, using for await
in both ends when data is string or a certain type, it's being inferred correctly but can't parse them well as sometimes it yields 2 or more at once. i think this needs to be moved at eden repo
Not sure it's strictly on the Eden side -- I've definitely seen cases where only one object is emitted and it still serializes onto the wire as [object Object], but if manually stringified with JSON.stringify it goes onto the wire as JSON (of course) and is parsed by Eden.
Given the content type is text/event-stream I would expect that the wire format is newline delimited and simultaneous emissions should not be an issue?
A few issues related to the new async generator feature for streaming responses, one of which applied to the legacy method as well.
What is the exact return type used to signal streaming and is it possible to do this without a generator? In the event an underlying operation is callback based the ergonomics of adapting that into yield calls can be difficult since you cannot yield inside a callback. Here is an example of how I "got this to work" for the listen/notify mechanism of postgresjs. I was able to wrap the notify call in a
ReadableStream
and then iterate the stream but maybe I'm missing something that allows skipping some of the ceremony