-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add binary
output port on HttpCallNode
#392
feat: add binary
output port on HttpCallNode
#392
Conversation
binary: ({ value }) => <>Binary (length {value.value.length.toLocaleString()})</>, | ||
binary: ({ value }) => { | ||
// FIXME: Coercing `value.value` into a `Uint8Array` here because `Uint8Array` gets parsed as an | ||
// object of shape `{ [index: number]: number }` when stringified via `JSON.stringify()`. | ||
// Consider coercing it back to `Uint8Array` at the entrypoints of the boundaries between | ||
// browser and node.js instead. | ||
const coercedValue = new Uint8Array(Object.values(value.value)); | ||
return <>Binary (length {coercedValue.length.toLocaleString()})</>; | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes an issue where hovering on the new binary
output port causes the app to crash:
It crashes because value.value
is a POJO instead of a Uint8Array
. For example, Uint8Array(2) [123, 45]
would end up being { "0": 123, "1": 45 }
here.
I suspect this is because Uint8Array
is serialised as such a POJO when stringified with JSON.stringify()
—as is required when passing the data over to the Node.js executor. This can be verified with:
const binaryOnBrowser = new Uint8Array([123,45]); // Uint8Array(2) [123, 45]
const binaryInTransit = JSON.stringify(binaryOnBrowser);
const binaryOnNode = JSON.parse(binaryInTransit); // { "0": 123, "1": 45 }
There's probably a better place to put this coercion fix but I'm not sure where. 😬 Need the help of the maintainers on this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, binary values don't get transmitted right across the remote debugger protocol. Definitely something that needs to be fixed at some point.
HttpCallNode
binary
output port on HttpCallNode
This is great @liaujianjie! I was thinking, what if there were a setting toggle in the node instead of both binary and text outputs? I can't really think of a case where you'd want both the binary and text output of an HTTP call, so instead we can just let the use choose which type the output of the node should be in the settings panel. That makes the node maybe simpler to use? |
Definitely agree with this approach, thought I'd need some pointers on how I should do that since I'm still pretty new to Rivet. An alternative would be to separate these into 2 PRs? So we have this PR for adding support for for the binary port on Thoughts? |
That would mean maybe two releases and backwards incompatible stuff, so probably better to nail this the first time. Should be pretty easy, just checking |
What about JSON outputs? Shouldn't the output type be one of:
|
@abrenneke I've went ahead to implement it such that the user can either switch between:
The option to select between the two is just below the body: What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
@all-contributors please add @liaujianjie for code |
I've put up a pull request to add @liaujianjie! 🎉 |
Resolves #386
Context
Previously, it wasn't possible to make a HTTP call (via
HttpCallNode
) and have the binary/blob data passed to anImageNode
. This PR introduces a newbinary
output port (alongside the existingbody
andjson
output ports) onHttpCallNode
to make this possible.Screengrab
How to test
ImageNode
, proving that the feature worksTest Rivet project