feat(ts): generate <Proto>Client / dispatcher against @comline/runtime - #8
Merged
Conversation
The TypeScript `code` generator now emits the full RPC shape for a
`protocol`, not just the method signatures:
- `error <Name>` -> `export interface <Name>` (wire payload) + `export
class <Name>Error extends Error` carrying `.data` and a static
`.ordinal` (the throwable a provider raises / a client re-raises).
- `<Proto><Fn>Params` interface per function with arguments.
- `<Proto>` provider interface: `Promise`-returning methods, `@throws
{<Name>Error}` JSDoc.
- `<PROTO>_CALLS` const table.
- `<Proto>Dispatcher implements Dispatch` — decode params, run the impl,
map a caught `<Name>Error` to `reply.err(ordinal, ...)`, one-way calls
leave the reply empty.
- `<Proto>Client` + static `connect()` (runs the handshake from
`IR_HASH`): one method per function, decoding the `Envelope`, mapping
`env.err.id` back to `<Name>Error` or `RuntimeError.remote`.
- `serve<Proto>(impl, transport, codec, framing?)` helper.
Framing follows `@framing` on the protocol / the package `default_framing`
(same recognition set as the Rust generator): `DatagramFraming` default,
`JsonRpcFraming` for `jsonrpc`.
`runtime/test/generated/chat.ts` is real generator output (blessed by
`generate.rs`, `TS_BLESS=1` to refresh); `runtime/test/generated.test.ts`
type-checks it and runs a client ⇆ provider round-trip over `duplex()`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TypeScript
codegenerator now emits the full RPC shape for aprotocol, not just method signatures — mirroring what the Rust generator does.error <Name>export interface <Name>(wire payload) +export class <Name>Error extends Errorwith.dataand a static.ordinal<Proto><Fn>Params<Proto>Promise-returning methods,@throws {<Name>Error}JSDoc<PROTO>_CALLS<Proto>Dispatcherimplements Dispatch— decode → run impl → map a caught<Name>Errortoreply.err(ordinal, …); one-way calls leave the reply empty<Proto>Client+ static connect()(handshake fromIR_HASH); one method per function,Envelope→<Name>Error/RuntimeError.remoteserve<Proto>(impl, transport, codec, framing?)Framing follows
@framingon the protocol / the packagedefault_framing(same recognition as the Rust generator):DatagramFramingdefault,JsonRpcFramingforjsonrpc.Executable check:
runtime/test/generated/chat.tsis real generator output (blessed bygenerate.rs;TS_BLESS=1to refresh).runtime/test/generated.test.tstype-checks it and runs a client ⇆ provider round-trip overduplex()— a call, a list call, a raisedRejectedError, a one-way notify, a()return. 21 runtime tests + 7 codegen tests green.Companion generation PR re-blesses the
protocol/typescript.tsconformance golden.Next:
libmode (npm package output).