connect-es

The TypeScript implementation of Connect: Protobuf RPC that works.

APACHE-2.0 License

Downloads
2.3M
Stars
1.3K
Committers
31

Bot releases are hidden (Show)

connect-es - v2.0.0-beta.1

Published by timostamm 28 days ago

What's changed

This is a beta release for version 2. See here for an introduction.

To give this version a try, run npx @connectrpc/connect-migrate@beta. Note that connect-query has not been updated yet.

New Contributors

Full Changelog: https://github.com/connectrpc/connect-es/compare/v2.0.0-alpha.1...v2.0.0-beta.1

connect-es - v1.5.0

Published by timostamm about 1 month ago

What's Changed

New Contributors

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.4.0...v1.5.0

connect-es - v2.0.0-alpha.1 Latest Release

Published by srikrsna-buf 4 months ago

What's new in version 2

To support protobuf editions, @bufbuild/protobuf had to make breaking changes, more on this here. Upgrading to v2 of @bufbuild/protobuf will be breaking change for connect users.

The most notable change is that v2 doesn't require a separate plugin anymore! we only need protoc-gen-es. For most users this will be a simple change of just removing the connect plugin and changing the import path to point to the protobuf generated types:

import { createPromiseClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-node";
// Before this was import { ElizaService } from "./gen/eliza_connect.js"
import { ElizaService } from "./gen/eliza_pb.js";

// Alternatively, use createGrpcTransport or createGrpcWebTransport here
// to use one of the other supported protocols.
const transport = createConnectTransport({
  httpVersion: "2",
  baseUrl: "https://localhost:8443",
  nodeOptions: { rejectUnauthorized },
});

const client = createPromiseClient(ElizaService, transport);
const res = await client.say({ sentence });

Please note that this is an alpha release, and APIs might still change. We're also missing documentation yet. But if you want to try it out, we welcome your feedback!

This release is published with the alpha tag. To install the alpha packages, you can run:

npm install @connectrpc/connect@alpha @bufbuild/protobuf@beta @bufbuild/protoc-gen-es@beta
connect-es - v1.4.0

Published by srikrsna-buf 8 months ago

What's Changed

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.

Other Changes

New Contributors

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.3.0...v1.4.0

connect-es - v1.3.0

Published by srikrsna-buf 9 months ago

What's Changed

New Contributors

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.2.1...v1.3.0

connect-es - v1.2.1

Published by timostamm 10 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.2.0...v1.2.1

connect-es - v1.2.0

Published by smaye81 10 months ago

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_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

connect-es - v1.1.4

Published by smaye81 11 months ago

What's Changed

  • Support zero-length compressed request and response messages on Node.js by @timostamm in #893.
  • Don't set User-Agent header in connect-web by @srikrsna-buf in #912.
  • Always capture header in ConnectError by @srikrsna-buf in #924.
  • Introduce experimental ConnectRouter.rpc overload to not require full ServiceType by @paul-sachs in #925.
  • Add explicit exports for node by @smaye81 in #921.

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.3...v1.1.4

connect-es - v1.1.3

Published by timostamm 12 months ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.2...v1.1.3

connect-es - v1.1.2

Published by timostamm about 1 year ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.1...v1.1.2

connect-es - v1.1.1

Published by srikrsna-buf about 1 year ago

What's Changed

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.1.0...v1.1.1

connect-es - v1.1.0

Published by srikrsna-buf about 1 year ago

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-migrate by @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

New Contributors

  • @mkusaka made their first contribution in #837

Full Changelog: https://github.com/connectrpc/connect-es/compare/v1.0.0...v1.1.0

connect-es -

Published by timostamm about 1 year ago

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!

connect-es - v1.0.0-rc1

Published by srikrsna-buf about 1 year ago

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.

What's Changed

  • Make @connectrpc/connect a peer dependency and pin the version by @srikrsna-buf in #817
  • Remove deprecated code by @timostamm in #814

Full Changelog: https://github.com/connectrpc/connect-es/compare/v0.13.2...v1.0.0-rc1

connect-es - v0.13.2

Published by smaye81 about 1 year ago

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.

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 throw and return on 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: https://github.com/connectrpc/connect-es/compare/v0.13.1...v0.13.2

connect-es - v0.13.1

Published by timostamm about 1 year ago

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: https://github.com/connectrpc/connect-es/compare/v0.13.0...v0.13.1

connect-es - v0.13.0

Published by timostamm about 1 year ago

What's Changed

This release changes the User-Agent used with gRPC and gRPC-web clients. Previously, the User-Agent was @bufbuild/connect-web, now it is connect-es/0.13.0. Future releases will bump the version number in the User-Agent string.

Enhancements

Bugfixes

New Contributors

Full Changelog: https://github.com/connectrpc/connect-es/compare/v0.12.0...v0.13.0

connect-es - v0.12.0

Published by timostamm about 1 year ago

What's Changed

Improvements and fixes to the HTTP/2 session management in Node.js

Other changes

New Contributors

Full Changelog: https://github.com/bufbuild/connect-es/compare/v0.11.0...v0.12.0

connect-es - v0.11.0

Published by smaye81 over 1 year ago

What's Changed

Disregard non-JSON error response bodies for unary requests

This release makes a change in how response bodies are parsed for Connect unary requests that result in an HTTP error. Previously, all response bodies for unary requests that returned an HTTP error status were parsed with response.json(). However, this could lead to errors with non-JSON bodies. Now, only responses with a Content-Type of application/json will have the body parsed as JSON and added to the resulting Connect error.

For all other errors, the resulting Connect error will show the HTTP status code as the message and the corresponding Connect error code as the code.

To reiterate, this only affects Connect protocol unary requests that end with an HTTP error status code. All other protocols and/or RPC types are unaffected.

Enhancements

New Contributors

Full Changelog: https://github.com/bufbuild/connect-es/compare/v0.10.1...v0.11.0

connect-es - v0.10.1

Published by timostamm over 1 year ago

What's Changed

Full Changelog: https://github.com/bufbuild/connect-es/compare/v0.10.0...v0.10.1