-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Router v2 #326
base: main
Are you sure you want to change the base?
Router v2 #326
Conversation
Completed:
|
The following needs to end up in documentation somewhere.We will delay running SFM invalidated queries until all items in the batch are complete. For The response body needs to key items something like: pub enum Key {
Response(u32), // Reference to the request
SFM(String, serde_json::Value), // SFM key (procedure name and input)
}
type ResponseBody = HashMap<Key, Value>; This way we will never have problems with running a SFM query that was also including in the request batch. |
Goal:
Introduce the new router, make it supporting by integrations (rspc_axum
/rspc_tauri
) and allow converting a legacy router into it.General design:
TMeta
generic in favor of improved solution in upcoming middleware system. This has always been a half-baked feature.Using the newlol goodbyespecta::Language
trait for exporting, opening up the door for easily supporting other langauges.specta::Language
you won't be missed.Router::config
. You must export types via the new router with the new bindings format.Bindings
toBindingsLegacy
to use the existing clients.rspc_axum::endpoint
now takesrspc::Router2
(you need it for the types anyway)tracing
feature with no directly replacement.rspc_tauri::plugin
torspc_plugin_rspc::init
(rspc-tauri
totauri-plugin-rspc
(remember to yank old crate), andplugin
toinit
)Breaking changes:
let (routes, types) = Router2::from(legacy_router).build().unwrap();
(must be used for the runtime and the types)Router::config
has been removed. You can usetypes.export_to
.rspc_axum::endpoint(routes)
. Now takesroutes
instead ofrspc::Router
.jsonrpc
executor API with no real replacement for nowProcedures
toProceduresLegacy
in your TS code.location
field toProcedure
legacy
feature to get the old bindings format.For my future reference:
The HTTP interface has been refactored to run on
rspc_core::Procedure
which is designed around the queries path not being namespaced by the type this means keeping full backwards compatibility is really hard. Given we are going to change the bindings format withRouter2
and upgrade the clients to the new stuff first we may as well just do this as a breaking change. The old system beingBox<dyn Layer>
andArc<Router>
makes it tough to do conversions too.Future:
rspc-legacy
craterspc::legacy
in favor ofrspc-legacy
unstable
andnolegacy
features fromrspc
in favor oflegacy
Router2
, etc.example-legacy
serve the router via Axum. Figure that out?rspc_devtools
- fix itrspc_tracing
:Logger
inrspc_core
Router::setup
to inject aLogger
instance forrspc-tracing
input
/result
to existing span.rspc_procedure
rspc_core
DynOutput::value
) a nonfrom_*_stream
type?DynInput::new_value
.Option::None
will reach havoc.serde
/related crates an optional depedency (cause Binario doesn't need it)ResolverError::new
forces usage of Serde forvalue
. Can we allowdyn Any
?Error
should have a variant for a custom error by middleware (Eg. Zer). I'm not sure we can make it generate a type but it should be able to serialize any data so a JS package could throw types back onto it later.DynOutput
have a variant forProcedureError
? We can allow manually grabbing it but it would make the serialization code in userspace much cleaner.ProcedureStream
's constructor codeProcedureStream::from_error
is broken with flushing logic. Thetodo!()
inProcedureStream::poll_inner
flush
workProcedureStream::map
related typestype_name
onDynOutput
make it useful or remove itDynInput
andDynOutput
?Any
bounds cause they are impliedrequire_manual_stream
->block_streaming
,stream
->unblock_streaming
, etc.Procedures::new
impl Fn() -> TCtx
orTCtx: Clone
.rspc_invalidation
makes this annoying.wait_util
function similar to the Cloudflare Workers/Vercel feature. How would a CDN implement it properly?State
orData
?Debug
impls + clippy runerased_serde
in public APIZer::from_request
errors handled as anrspc_core::ProcedureError
??rspc
- cleanup module structure cause it's a mess.invalidate
?? We can't queue it again without conflicting keysflush
?? Cause we are well past that point.stream.resolved() || stream.flushable()
is badrspc_invalidation
.invalidate
after streaming has started. What should happen?rspc_invalidation
can we skipserde_json::Value
?rspc_invalidate
Invalidate::Any
rspc_invalidate
Invalidate::Many
FormData
item in the input.rspc-axum
/rspc-actix-web
/rspc-http
. Heavily dependant on how out of control the code in userspace ends up as.File
will bridgeAsyncWrite
/AsyncBufWrite
toStream<Item = Vec<u8>>
so it can reuse the existing streaming machinery. This will allow interleaving multiple file downloads in one response.Hyper
works so as much as I hate the overhead of buffering it's gonna happen anyway.AsBuffer(Vec<u8>)
and then we can know to set theContent-Type
in the transport layer correctly.TError
is fixed maybe we put it on theRouter
cause it's a bit wierd withBaseProcedure
?ResolverError
takes two args which should both beself
andanyhow::Error
is notClone
. I think we can do smart stuff with constructors to solve this.rspc::Error2
is super unsafe! It lets you choose to use#[error(...)]
for the repr which is astring
notTError
.rspc::Error2
in favor ofInto
?ProcedureStream
flushing stuffProcedureBuilder::subscription
implementedDataType::Unknown
)ProcedureMeta::state
called within aMiddleware::setup
should panic when accessed as it can't be valid.key
inProcedure2::builder
.specta_serde
integration prototypeIntoResponse: !
future compat warningProcedure2
intomodern::procedure
or keep in root?Middleware::setup
andExtension::setup
are overriding which is major cringe alert.Extension
map function working. Might needTError
generic?rspc_middleware
-ResolverInput
,ResolverOutput
,Middleware
,Extension
and related stuffrspc
and instead userspc_middleware
rspc-invalidation
to mutations and subscriptions. Should we make it typesafe?ProcedureStreamMap
error handlingProcedureError::Serializer
or not? If not clear out commented out stuff.rspc_tauri
should handle first-level serializer errors through rspc instead of throwing into Tauri.@rspc/tauri
with legacy systemFile
fromrspc_http
? Idk if their IPC can handle it but I suppose supporting it anyway would be worthwhile.WithDate
Serialize
?thread_local
to enable the special rspc encoding so the type doesn't mess with users other stuff.Accept: text/x-rspc
for it to use the special encoding.TypeMap
+TypeCollection
specta#294 &Language
in practice specta#297 & releasingspecta-rust
.Release:
rspc::Router2
can be implemented in userspace.ProceduresLegacy
works with the existing clients.legacy
stuff? Mayberspc_legacy
crate?Unsorted:
Procedure
'sArc
ing.Procedure2::error
beingOption<DataType>
or not?Serialize
on error. Similar to the regularOk
type.Remaining questions:
rspc_devtools
- Should we provide a way to set CORS header. If we leave it on the user the URL being the same is a problem.This PR will be merged but work will continue as #328, #332 and specta-rs/website#9.