Skip to content

json bgon redux#17

Draft
Fang- wants to merge 50 commits intomasterfrom
wip/json-bgon
Draft

json bgon redux#17
Fang- wants to merge 50 commits intomasterfrom
wip/json-bgon

Conversation

@Fang-
Copy link
Contributor

@Fang- Fang- commented Mar 7, 2026

#4 died due to account deletion. We continued this work last year. It's been sitting idle for a little while, but we want to make sure we don't lose track of it completely. Not a company area of focus right now but I have a personal interest in revivifying this.

Will write up a tldr of status and remaining work once we dive into this again.

xiphiness and others added 30 commits March 16, 2023 14:20
Since the nockjs api has changed lightly since the code herein was
written, we have to make some small adjustments.

Note that this also changes the interface for the .err() subscription
interface callback, to bring it in line with the changed to the .event()
interface we introduced during earlier cleanup.
We no longer use a special path (/~/channel-jam), but instead make use
of request headers to indicate what mode to open a channel in, and how
to interpret a channel event.

This required loosening up the headers type a little bit, making changes
to the fetchOptions, making them dynamic rather than static.
It includes the desk, so that mark files can be picked from the correct
desk by eyre internally. This implementation detail ends up leaking into
its interface right now, so we must account for it when unpacking the
fact.
We were going out of and back into Atom shape, but we can just toString
it in-place.
Replace json with nouns, make sure to test nouns for equality properly.
There were shenanigans aronud .eventSource getting recursively called
into by .sendNounToChannel. This whole structure was unnecessarily
recursive and hard to follow.

Here we flatten it out a little bit, making .eventSource responsible for
continuing after an initialization poke, in the "not yet initialized"
case.

This means that developers using this library need to explicitly call
.eventSource() in order to establish a connection. This probably makes
for a better API, although we should add a success/failure return value
to it in the near future.
Eyre takes a list of commands for each incoming PUT. Here, we update
sendNounToChannel() into sendNounsToChannel(), taking a variable number
of arguments, which get converted into "real" Nouns inside of the
function, using nockjs's dwim logic. (Of course, this means callers are
still free to pass pre-built Nouns also.) This way, we don't end up with
Noun construction boilerplate all over the place, and this lets us send
the list of empty commands, which we want to use for channel
initialization.
- renamed eventSource to connect
- renamed authenticate to setupChannel
- renamed connect to authenticate
- no longer accept ship in the constructor
- refactored constructor to take object instead of individual arguments
- consistently follow patp syntax for ship and our
- removed desk as a parameter and now require for thread
- onReconnect removed in favor of onOpen, reconnect still signalled with param
- various comment fixes and formatting
Instead of any, we can use Noun in many places. We also don't want/need
to parameterize types as often as we used to.

Also throws away unused types from types.ts.
Necessarily includes logic for turning the jambuffer in the response,
into a proper Noun object.

Only somewhat surprisingly, we need to reverse the byte order in the
response, even though to accurately mock it, we don't need to reverse
the bytes from the jam generated by nockjs.

It would be most prudent to manually test this in the browser, to make
sure we didn't trip ourselves up over endianness shenanigans here.
This adds a `fetch` option to the `Urbit` class, which allows you to
pass in the local fetch implementation that works for you. Notably we
did this to support React Native, which needs special fetch parameters.

We also removed todos that were no longer relevant.
As currently written, the library really only supports the one mode.
This is probably the way forward, too. So here we remove vestigial
references to mode switching within the library.
This makes sure we re-export important functions from @urbit/nockjs. We
also removed the URL prefixing which was causing issues with passing empty
string as the URL. Finally, we reconfigured the setup so that the Urbit
instance returned is immediately available and all interactions wait for
the connection to be established.
Which just does a scry() call, but enforces a json mark, and handles the
parsing of the ReadableStream for you.
Fang- and others added 20 commits March 19, 2024 17:11
Accept it as either pre-interpolated string, array of segments, or
directly as a Noun.

The conversion logic in subscribe() should maybe be factored out.
Now defaults to speaking raw nouns with spider, as supported through
urbit/urbit#6943.

Provides a jsonThread() fallback for speaking json. Doesn't yet support
the "json one way, nouns the other" case.

Factors out noun<->bytebuffer conversions into utility functions.
Make sure we use Path instead of flat strings where appropriate.

Rename subscription callbacks, and unify callbacks into their
"interface" types. Store those interface types, even if we strictly only
need the callbacks themselves, it's useful data to keep around.
We do remove the eventId from the callback interfaces though, you can't
know them ahead of time, and client software is generally better off
rolling their own identifiers if they really don't want to do anonymous
callback function or similar.

Updates tests to match.
Canonical aura formatting or bust.
This has the same kind of bignums that nockjs uses, letting us skip a
double-conversion.
When initializing a channel connection, you may now optionally specify
the channel mode, either 'noun' (default) or 'json'. This mode
determines the shape of the responses that come back out of the library
into your callbacks.

Sending pokes may be done with either nouns or js data. Scries and
threads retain their separate functions depending on what kind of
response you want.
Typescript can't check these correctly, but we do want to give either a
Noun or js-object depending on the channel mode. The function signatures
should've been checked when they were first provided by the client.
The ship sends a heartbeat, but may be slow to do so due to other work.
Here, we bump the timeout to be even longer, so that we are less likely
to erroneously detect disconnects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants