Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
kentonv
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
17 ms
·
271.
▲
by
kentonv
1y ago
The input to the map function (when it is called in "record" mode on the client) is an RpcPromise for the eventual value. That means you can't actually inspect the value, you can only queue pipelined calls on it. Since you ca
272.
▲
by
kentonv
1y ago
Right, your methods in JSON RPC could be dynamic. JSON RPC really doesn't specify anything, so you can do anything with it. But you need conventions around that, like how does a client find out that the server exported new methods,
273.
▲
by
kentonv
1y ago
Here is the Cap'n Proto RPC protocol: https://github.com/capnproto/capnproto/blob/v2/c%2B%2B/src/c... That's just the RPC state machine -- the serialization is specified elsewhere,
274.
▲
by
kentonv
1y ago
Yes, when you reconnect the WebSocket, the client will need to call methods to get new instances of any objects it needs. The old stubs are permanently broken. FWIW the way I've handled this in a React app is, the root stub gets passed
275.
▲
by
kentonv
1y ago
The fear here is that if a class wasn't explicitly designed to be an RPC interface, then it could very easily offer functionality that isn't safe to expose over a security boundary with RPC. Normally, JavaScript classes do not exp
276.
▲
by
kentonv
1y ago
The server constructs a new AuthenticatedSession implementation each time authenticate() is called, and can store the key (or just the authenticated user info) in the server-side object. This does mean the server is holding onto state, but
277.
▲
by
kentonv
1y ago
The protocol explicitly blocks overriding `toString()` (and all other Object.prototype members), as well as `toJSON()`, to prevent the obvious ways that you might accidentally invoke a callback when you weren't expecting to. How else m
278.
▲
by
kentonv
1y ago
I generally agree that the .map() trick doesn't actually replace GraphQL without some sort of server-side optimizations to avoid turning this into N+1 selects. However, if your database is sqlite in a Cloudflare Durable Object, and the
279.
▲
by
kentonv
1y ago
You can use TypeScript to define your API, and get all the benefits of schemas. Well, except you don't get runtime type checking with TypeScript, which might be something you really want over RPC. For now I actually suggest using zod f
280.
▲
by
kentonv
1y ago
Yeah, JSON RPC doesn't support the pass-by-reference and lifecycle management stuff. You just have a static list of top-level functions you can call. This makes a pretty big difference in what kinds of APIs you can express. OTOH, JSON
281.
▲
by
kentonv
1y ago
The state only lives for a single RPC session. When using WebSockets, that's the lifetime of the WebSocket. But when using the HTTP batch transport, a session is a single HTTP request, that performs a batch of calls all at once. So the
282.
▲
by
kentonv
1y ago
I'm hoping the answer will be: * Use Cap'n Proto in your Rust backend. This is what you want in a type-safe language like Rust: generated code based on a well-defined schema. * We'll build some sort of proxy that, given a Cap
283.
▲
by
kentonv
1y ago
Of course, all programming language APIs even in dynamic languages have some implied type (aka schema). You can't write code against an API without knowing what methods it provides, what their inputs and outputs are, etc. -- and that
284.
▲
by
kentonv
1y ago
The .map() callback receives as its input an RpcPromise, not the actual value. You can't do any computation (including branching) on an RpcPromise, the only thing you can do is pipeline on it. Since the map callback must be synchronous
285.
▲
by
kentonv
1y ago
To chain three calls, the client will send three messages, yes. (At least when using the WebSocket transport. With the HTTP batch transport, the entire batch is concatenated into one HTTP request body.) But the client can send all three mes
286.
▲
by
kentonv
1y ago
I think we'll likely keep them pretty close to in-sync, at least when it comes to features that make sense in both. If anything I'd expect Cap'n Web to run ahead of Workers RPC (as it is already doing, with the new pipeline f
287.
▲
by
kentonv
1y ago
What do you mean? Async programming exists in tons of languages. Just off the top of my head, I've used async/await in JavaScript, C++, Python, Rust, C#, ... Anyway, the point here is that early RPC systems worked by blocking the
288.
▲
by
kentonv
1y ago
Ugh, looks like a copy-pasto when moving the blog into the CMS, will get that fixed, thanks. The code was supposed to be: let namePromise = api.getMyName(); let result = await api.hello(namePromise); console.log(result);
289.
▲
by
kentonv
1y ago
No, in fact this is the first I've heard of Cap'n Jazz. The name "Cap'n Proto" came from "capabilities and protobuf". The first, never-released version was based on Protobuf serialization. The first public
290.
▲
by
kentonv
1y ago
Yeah I now want to go back and redesign the Cap'n Proto RPC protocol to be based on this new design, as it accomplishes all the same features with a lot less complexity! But it may be tough to justify when we already have working Cap&#
291.
▲
by
kentonv
1y ago
I’d love to add 3PH support in the future, but it wasn’t a priority for an initial release as this is very focused on enabling browser<->web server communications specifically. SturdyRefs are tricky. My feeling is that they don’t real
292.
▲
by
kentonv
1y ago
Good old Douglas Crockford. He also put the "must be used for good, not evil" restriction on JSON, which he invented. Obviously JSON is used for all kinds of evil, though. A much younger, more naive me (~20 years ago) actually ema
293.
▲
by
kentonv
1y ago
Ah you are just trying to gaslight me. pytype doesn't do static bounds checking. What compels you to do this? Posting just to make people angry? Do you not have anything better to do with all that PL theory expertise?
294.
▲
by
kentonv
1y ago
You seem to have merged the required fields issue and the oneof issue, but these are unrelated threads. > Can you address the part where I mention isomorphism of (oneof token) and (oneof (token {})), and clarify what exactly do you think
295.
▲
by
kentonv
1y ago
Throwing a theorem-prover at the problem, unaided by developer hints, is not realistic in a large codebase. You need annotations that let you say "this array's size is is the same as that array" or "this integer is withi
296.
▲
by
kentonv
1y ago
You can still verify presence explicitly if you want, with the `has` methods. But if you don't check, it should return a default value rather than null. You don't want your server to crash on bad input.
297.
▲
by
kentonv
1y ago
> It gets super frustrating to have to empty/null check fields everywhere you use them, especially for fields that are effectively required for the message to make sense. That's why Protobuf and Cap'n Proto have default va
298.
▲
by
kentonv
1y ago
> how often? as practiced by who, and where? This was my experience in Google Search infrastructure circa 2005-2010. This was a system with dozens of teams and hundreds of developers all pushing their data through a common message bus. I
299.
▲
by
kentonv
1y ago
> type algebra either doesn't exist or impractical because only PL theorists know about it, not Kenton. Hi I'm Kenton. I, too, was enamored with advanced PL theory in college. Designed and implemented my own purely-functional p
300.
▲
by
kentonv
1y ago
Hi, I'm the apparently-FUD-spreading Cap'n Proto author. Sure! You could certainly imagine extending Protobuf or Cap'n Proto with a way to specify validation that only happens when you explicitly request it. You'd then h
More ›