Comments (9)
Hey! You can use toPlainMessage
function in @bufbuild/protobuf
to covert them to plain objects that are serializable. #505 has more context.
from connect-es.
Looking over the details on the react docs site, this still looks fairly experimental so it makes sense to me that this would still be handled in user-land, with a solution something like what you've got above (just modified to support exporting all methods):
// server-client.ts
'use server'
export const client = createPromiseClient(...);
// some-component.tsx
import { client } from "./server-client";
...
client.a(...);
This doesn't export individual methods but it does export the client with those methods, which should provide similar functionality.
I suppose you could build a buf plugin to create a client that exports ALL the methods but I would guess it wouldn't be worth the effort.
from connect-es.
So spent some time learning about RSC, and put together an example of using nextjs and server actions along with connect. Hopefully that can at least provide an idea. Also, being a total newbie to RSC, we can build on that with better practices.
from connect-es.
Hey! You can use
toPlainMessage
function in@bufbuild/protobuf
to covert them to plain objects that are serializable. #505 has more context.
Thank you
from connect-es.
Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔
from connect-es.
Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔
I don't quite follow, can you elaborate?
from connect-es.
Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔
I don't quite follow, can you elaborate?
Yes.
In .proto
service AnyhowService {
rpc A() returns ();
rpc B() ...
}
then
const xs : PromiseClient<AnyhowService>
xs.A({})
xs.B({})
those call is not server actions, one should
'use server'
const client = createPromiseClient...
export A = client.A
export B = client.B
then the exported functions are finally server actions
from connect-es.
Looking over the details on the react docs site, this still looks fairly experimental so it makes sense to me that this would still be handled in user-land, with a solution something like what you've got above (just modified to support exporting all methods):
// server-client.ts 'use server' export const client = createPromiseClient(...); // some-component.tsx import { client } from "./server-client"; ... client.a(...);This doesn't export individual methods but it does export the client with those methods, which should provide similar functionality.
I suppose you could build a buf plugin to create a client that exports ALL the methods but I would guess it wouldn't be worth the effort.
thank you, but top level can only export async functions. In this case client is an object
anyway, keeps manually write the exports for every function is not very bad, since the server actions needs auth
from connect-es.
Hmm I see. Clearly RSC is more complicated than I thought. In that case, I definitely think a dedicated buf plugin or userland code would be the better approach. This would also be necessary if the entities that need to be returned should be plain objects instead of class objects as well. A plugin would also be easier to update as the RSC paradigm evolves without having to consider how it changes the core client.
from connect-es.
Related Issues (20)
- Inconsistent debug Field Type in Error Details After connect-go v1.15.0 Update HOT 2
- Documentation: No mention of support for client or bidi streaming HOT 1
- WebTransport transport HOT 3
- RST_STREAM Handling HOT 10
- API Response Omits Properties with Falsy Values HOT 2
- Missing trailers override? HOT 5
- Returning or throwing from a method always triggers an abort HOT 10
- Ping-related error: "session has been destroyed" HOT 5
- Models not exported on Connect package HOT 4
- Not getting all Set-Cookie headers in response when using Node client
- Headers in NodeTransportOptions are not being passed to the request when using createConnectTransport()
- createPromiseClient Not assignable to parameter of type ServiceType HOT 2
- V2: gRPC error code's no longer present in thrown ConnectError HOT 1
- Nodejs Getting started guide is not working HOT 7
- [QUESTION] Auto Reconnect Mechanism
- How to get more information about Connect Protocol Error for streaming request? HOT 1
- Test files included in shipped package of connect-node HOT 2
- Cannot encode message google.protobuf.Any in the v2.0.0-alpha HOT 2
- Failing to generate proper types v1.4.0 HOT 14
- Coherent client/server way to work with "infinite" streams HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connect-es.