-
Notifications
You must be signed in to change notification settings - Fork 218
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
Implemented the new EventContext types in Typescript codegen #2224
Conversation
What's currently implemented in Rust is my intended design. I would not say I'm married to it, but I think it's fine, and at this point I consider the cost to change it quite high, as it would require PRs to all of public, private and docs. My reasoning for the design I chose: I think that having two distinct-but-equivalent ways to access the error will confuse users, and I don't see it as having a significant gain. Reading the error out of the context is easy. Keeping as much as possible inside the contexts is beneficial because we have more freedom to extend them in the future, whereas we essentially cannot change callback arglists post 1.0.
Reducer args are different from the error in that we don't have a clean way to make them accessible inside the context. Even after this change, reading them from the context requires pattern-matching to read a known variant from a nested field, which is tedious and verbose. However, reducer callbacks get metadata in addition to the arguments, e.g. sender identity and connection ID, which is only passed inside the context, not provided as unboxed arguments. |
Personally, I think having to access the error by I would strongly recommend surfacing the error as it's own argument in Rust. |
I don't think that is a good idea. It's better to do the change in a forwards-compatible manner via the context. Users will need to look inside the contexts for other information anyway so it's good to encourage them to do so. |
a5e00ed
to
16be609
Compare
Description of Changes
Relatively small PR. Corresponds to clockworklabs/spacetimedb-typescript-sdk#132
This PR generates a few new types based on new types added to the TypeScript SDK. Namely:
It also fixes a bug where
SubscriptionBuilder
was not actually type aware of the module types, soonApplied(ctx => ctx.reducers
did not have the reducer types.I have also improved the lint ignoring which in general reduces noise. I've wanted to do that for a while and since it helped debug here, I wanted to take the opportunity to merge it.
API and ABI breaking changes
This is a TypeScript API breaking change because now:
ctx.on<reducer>
passes in aReducerEventContext
instead of anEventContext
into its callbacksubscriptionBuilder.onApplied
passes in aSubscriptionEventContext
into its callbacksubscriptionBuilder.onError
passes in anErrorContext
into its callbackNote that
onConnectError
is of the form:@gefjon is that correct? I believe this is what I was told to do in the previous implementation but it looks like this is different in the Rust version:
SpacetimeDB/crates/sdk/examples/quickstart-chat/main.rs
Line 164 in b50b684
This seems like quite a confusing API to be forced to look into the
ErrorContext
when the error could also be surfaced as an argument. Surely the following would be better (and more aligned with the ReducerArgs handling for the reducer callback):In
TypeScript
the only meaningful difference beyond what I posted above is that the error is also available under theevent
field of theErrorContext
. OtherwiseDBConnection == ErrorContext
Expected complexity level and risk
2
Testing
TODO pending Phoebe's reply