Releases: connectrpc/connect-es
v1.2.0
What's Changed
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_commonjsTo view the full PR, see Support CommonJS in protoc-gen-connect-es by @timostamm in #956
Full Changelog: v1.1.4...v1.2.0
v1.1.4
What's Changed
- Support zero-length compressed request and response messages on Node.js by @timostamm in #893.
- Don't set
User-Agentheader in connect-web by @srikrsna-buf in #912. - Always capture header in
ConnectErrorby @srikrsna-buf in #924. - Introduce experimental
ConnectRouter.rpcoverload to not require fullServiceTypeby @paul-sachs in #925. - Add explicit exports for node by @smaye81 in #921.
Full Changelog: v1.1.3...v1.1.4
v1.1.3
What's Changed
- Fix multiple read attempts in fetch client by @srikrsna-buf in #876
Full Changelog: v1.1.2...v1.1.3
v1.1.2
What's Changed
- Add ESM wrapper to avoid dual package hazard by @timostamm in #842
Full Changelog: v1.1.1...v1.1.2
v1.1.1
What's Changed
- Fix ping not timing out in nodejs after H2 sessions verify by @srikrsna-buf in #869
Full Changelog: v1.1.0...v1.1.1
v1.1.0
What's Changed
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);
};
};Enhancements
- Update to latest versions in
connect-migrateby @mkusaka in #837 - Add default request timeout for clients by @srikrsna-buf in #844
- Add support for graceful shutdown in fastify by @srikrsna-buf in #843
Bug fixes
- Fix early event loop exit on nodejs when H2 sessions are in the verify state by @srikrsna-buf in #861
- Fix type exports and integrate
arethetypeswrongby @smaye81 in #838
New Contributors
Full Changelog: v1.0.0...v1.1.0
v1.0.0
v1.0.0-rc1
If you are coming from version 0.13.0 or earlier, run
npx @connectrpc/connect-migrate@latestto update your dependencies. See here for details.
What's Changed
- Make
@connectrpc/connecta peer dependency and pin the version by @srikrsna-buf in #817 - Remove deprecated code by @timostamm in #814
Full Changelog: v0.13.2...v1.0.0-rc1
v0.13.2
If you are coming from version 0.13.0 or earlier, run
npx @connectrpc/connect-migrate@latestto update your dependencies. See here for details.
What's Changed
- Propagate errors back to the handler by @srikrsna-buf in #751
- Add defensive check for http2 sessions by @srikrsna-buf in #783
- Call
throwandreturnon response iterables in the node adaptor by @srikrsna-buf in #775 - Abort handler signal on error/return by @srikrsna-buf in #786
- Switch Node.js Headers polyfill to use undici in versions < 18 by @timostamm in #791
- Set User-Agent in gRPC-web clients on Node.js by @timostamm in #784
- Add version checks to migration CLI by @paul-sachs in #782
Full Changelog: v0.13.1...v0.13.2
v0.13.1
What's Changed
To keep Connect well-maintained and responsive to its users' needs over the long term, we're preparing to donate it to a foundation. (More details on that soon!) To cleanly separate Connect from Buf's other code, we're moving development to the connectrpc GitHub organization and to the connectrpc organization on npmjs.com.
This is the first release that publishes packages with the new @connectrpc scope. To make the switch seamless, we are introducing a small tool that updates all references in your project automatically, @connectrpc/connect-migrate.
The switch is as simple as running a single command:
$ npx @connectrpc/connect-migrate@latest
Scanning... ✓
1 package.json file
1 lock file
5 source files
Updating source files...
src/client.ts ✓
src/server.ts ✓
src/webclient.ts ✓
Updating packages... ✓
package.json ✓
Updating lock file...
package-lock.json ✓
| Old package | New package |
|---|---|
| @bufbuild/connect v0.13.0 | @connectrpc/connect v0.13.1 |
| @bufbuild/connect-web v0.13.0 | @connectrpc/connect-web v0.13.1 |
| @bufbuild/connect-fastify v0.13.0 | @connectrpc/connect-fastify v0.13.1 |
| @bufbuild/connect-node v0.13.0 | @connectrpc/connect-node v0.13.1 |
| @bufbuild/connect-next v0.13.0 | @connectrpc/connect-next v0.13.1 |
| @bufbuild/connect-express v0.13.0 | @connectrpc/connect-express v0.13.1 |
| @bufbuild/protoc-gen-connect-es v0.13.0 | @connectrpc/protoc-gen-connect-es v0.13.1 |
| @bufbuild/connect-query v0.4.1 | @connectrpc/connect-query v0.4.2 |
| @bufbuild/protoc-gen-connect-query v0.4.1 | @connectrpc/protoc-gen-connect-query v0.4.2 |
| @bufbuild/protoc-gen-connect-query-react v0.4.1 | @connectrpc/protoc-gen-connect-query-react v0.4.2 |
Full Changelog: v0.13.0...v0.13.1