The TypeScript implementation of Connect: Protobuf RPC that works.
This release includes support for server-side interceptors! Here's a quick example:
import * as http from "http";
import routes from "./connect";
import { connectNodeAdapter } from "@connectrpc/connect-node";
import type { Interceptor } from "@connectrpc/connect";
const logger: Interceptor = (next) => async (req) => {
console.log(`recevied message on ${req.url}`);
return await next(req);
};
http
.createServer(
connectNodeAdapter({
routes,
interceptors: [logger],
}),
)
.listen(8080);
For more on them please see the docs.
ts_nocheck
plugin option by @timostamm in https://github.com/connectrpc/connect-es/pull/1012
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.3.0...v1.4.0
*TransportOptions
types for connect-node
by @jrschumacher in https://github.com/connectrpc/connect-es/pull/959
instanceof
for ConnectError
by @srikrsna-buf in https://github.com/connectrpc/connect-es/pull/974
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.2.1...v1.3.0
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.2.0...v1.2.1
By default, protoc-gen-connect-es (and all other plugins based on @bufbuild/protoplugin) generate ECMAScript import
and export
statements. For use cases where CommonJS is difficult to avoid, a new plugin option has been added named js_import_style
which can be used to generate CommonJS require()
calls.
Here is an example buf.gen.yaml:
version: v1
plugins:
# You'll need @bufbuild/protoc-gen-es v1.6.0 or later
- plugin: es
out: src/gen
opt: js_import_style=legacy_commonjs
- plugin: connect-es
out: src/gen
opt: js_import_style=legacy_commonjs
To view the full PR, see Support CommonJS in protoc-gen-connect-es
by @timostamm in #956
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.4...v1.2.0
User-Agent
header in connect-web by @srikrsna-buf in #912.ConnectError
by @srikrsna-buf in #924.ConnectRouter.rpc
overload to not require full ServiceType
by @paul-sachs in #925.Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.3...v1.1.4
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.2...v1.1.3
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.1...v1.1.2
Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.0...v1.1.1
Add support for user provided context values in handlers and clients.
Create a context key with a default value:
export interface User {
id: string;
}
import { createContextKey } from "@connectrpc/connect";
export const kUser = createContextKey<User | undefined>(
undefined // The default value.
);
Use the contextValues
option to provide the context values for each request:
import { fastify } from "fastify";
import routes from "./connect";
import { fastifyConnectPlugin } from "@connectrpc/connect-fastify";
import { authenticate } from "./authenticate.js";
import { kUser } from "./user-ctx.js";
const server = fastify();
await server.register(fastifyConnectPlugin, {
routes,
contextValues: (req) => createContextValues().set(kUser, authenticate(req)),
});
await server.listen({
host: "localhost",
port: 8080,
});
Use the context value in the handler:
import { ConnectRouter } from "@connectrpc/connect";
import { ElizaService } from "./gen/eliza_connect.js";
export default (router: ConnectRouter) => {
// using const say
router.service(ElizaService, {
say: (req, { values }) => {
const currentUser = values.get(kUser);
if (currentUser === undefined) {
throw new ConnectError("Unauthenticated", Code.Unauthenticated);
}
// ...
},
});
};
Can be used in clients too:
import { ElizaService } from "gen/...";
import { createPromiseClient } from "@connectrpc/connect";
import transport from "./transport.js";
import kUser from "user-context.js";
const client = createPromiseClient(ElizeService, trasport);
await client.say({ sentence: "Hi" }, { values: createContextValues().set(kUser, { ... }) });
Which can be accessed in an interceptor:
const tokenInterceptor = (next) => {
return (req) => {
req.header.set("Authorization", `Bearer ${req.values.get(kUser).token}`);
return next(req);
};
};
connect-migrate
by @mkusaka in #837arethetypeswrong
by @smaye81 in #838Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.0.0...v1.1.0
This is Connect-ES
's first stable release! It does not contain any user-facing changes.
If you are coming from version 0.13.0 or earlier, run npx @connectrpc/connect-migrate@latest
to update your dependencies. See here for details.
Thanks to all contributors!