Skip to content

Commit

Permalink
Deprecate createPromiseClient in favor of createClient (#1235)
Browse files Browse the repository at this point in the history
Signed-off-by: Sri Krishna Paritala <skrishna@buf.build>
  • Loading branch information
srikrsna-buf authored Sep 18, 2024
1 parent 0c40e1f commit fd7b7ca
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 85 deletions.
4 changes: 2 additions & 2 deletions packages/connect-cloudflare/conformance/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
createGrpcTransport,
createGrpcWebTransport,
} from "@connectrpc/connect-node";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import type { Transport } from "@connectrpc/connect";
import { InvokeService } from "./invoke-service.js";
import { parseArgs } from "node:util";
Expand Down Expand Up @@ -64,7 +64,7 @@ async function main() {
default:
throw new Error(`Unknown protocol: ${flags.protocol}`);
}
const client = createPromiseClient(InvokeService, transport);
const client = createClient(InvokeService, transport);
for await (const next of readSizeDelimitedBuffers(process.stdin)) {
const req = ClientCompatRequest.fromBinary(next);
req.host = process.env["CLOUDFLARE_WORKERS_REFERENCE_SERVER_HOST"]!;
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-conformance/src/promise-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import type { PromiseClient, Transport } from "@connectrpc/connect";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import {
ClientCompatRequest,
ClientResponseResult,
Expand Down Expand Up @@ -48,7 +48,7 @@ export function invokeWithPromiseClient(
transport: Transport,
compatRequest: ClientCompatRequest,
) {
const client = createPromiseClient(ConformanceService, transport);
const client = createClient(ConformanceService, transport);

switch (compatRequest.method) {
case ConformanceService.methods.unary.name:
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-express/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ curl \
Node.js with the gRPC-web protocol (using a transport from [@connectrpc/connect-node](https://www.npmjs.com/package/@connectrpc/connect-node)):

```ts
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -62,7 +62,7 @@ const transport = createGrpcWebTransport({
httpVersion: "1.1",
});

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence); // you said: I feel happy.
```
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-express/src/express-readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import * as http from "http";
import { Message, MethodKind, proto3 } from "@bufbuild/protobuf";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import type { ConnectRouter } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-node";
import express from "express";
Expand Down Expand Up @@ -83,7 +83,7 @@ describe("express readme", function () {
baseUrl: `http://localhost:${port}`,
httpVersion: "1.1",
});
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const res = await client.say({ sentence: "I feel happy." });
// console.log(res.sentence) // you said: I feel happy.
expect(res.sentence).toBe("you said: I feel happy.");
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-fastify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ curl \
Node.js with the gRPC protocol (using a transport from [@connectrpc/connect-node](https://www.npmjs.com/package/@connectrpc/connect-node)):

```ts
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -76,7 +76,7 @@ const transport = createGrpcTransport({
httpVersion: "2",
});

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence); // you said: I feel happy.
```
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ curl \
Node.js with the gRPC-web protocol (using a transport from [@connectrpc/connect-node](https://www.npmjs.com/package/@connectrpc/connect-node)):

```ts
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { createGrpcWebTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -74,7 +74,7 @@ const transport = createGrpcWebTransport({
httpVersion: "1.1",
});

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence); // you said: I feel happy.
```
Expand Down
16 changes: 8 additions & 8 deletions packages/connect-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TypeScript.
Lets your clients running on Node.js talk to a server with the Connect protocol:

```diff
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
+ import { createConnectTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -21,7 +21,7 @@ import { ElizaService } from "./gen/eliza_connect.js";
+ httpVersion: "1.1"
+ });

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.
```
Expand All @@ -31,7 +31,7 @@ console.log(sentence) // you said: I feel happy.
Lets your clients running on Node.js talk to a server with the gRPC protocol:

```diff
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
+ import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -41,7 +41,7 @@ import { ElizaService } from "./gen/eliza_connect.js";
+ httpVersion: "2"
+ });

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.
```
Expand All @@ -51,7 +51,7 @@ console.log(sentence) // you said: I feel happy.
Lets your clients running on Node.js talk to a server with the gRPC-web protocol:

```diff
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
+ import { createGrpcWebTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -61,7 +61,7 @@ import { ElizaService } from "./gen/eliza_connect.js";
+ httpVersion: "1.1"
+ });

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence) // you said: I feel happy.
```
Expand Down Expand Up @@ -117,7 +117,7 @@ curl \
Node.js with the gRPC protocol:

```ts
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { createGrpcTransport } from "@connectrpc/connect-node";
import { ElizaService } from "./gen/eliza_connect.js";

Expand All @@ -126,7 +126,7 @@ const transport = createGrpcTransport({
httpVersion: "2",
});

const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
console.log(sentence); // you said: I feel happy.
```
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-node/src/connect-transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe("using a session manager to explicitly close all connections", function
baseUrl: "https://demo.connectrpc.com",
sessionManager,
});
// const client = createPromiseClient(..., transport);
// const client = createClient(..., transport);

// make calls with the client

Expand Down
16 changes: 8 additions & 8 deletions packages/connect-node/src/node-readme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { PartialMessage } from "@bufbuild/protobuf";
import {
createContextKey,
createContextValues,
createPromiseClient,
createClient,
createRouterTransport,
} from "@connectrpc/connect";
import type { ConnectRouter } from "@connectrpc/connect";
Expand Down Expand Up @@ -103,23 +103,23 @@ describe("node readme", function () {
baseUrl: "https://demo.connectrpc.com",
httpVersion: "1.1",
});
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
expect(sentence).toBeDefined();
});

it("createGrpcTransport()", async function () {
// A transport for clients using the gRPC protocol with Node.js `http2` module
const transport = createGrpcTransport(optionsHttp2);
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
expect(sentence).toBeDefined();
});

it("createGrpcWebTransport()", async function () {
// A transport for clients using the gRPC-web protocol with Node.js `http` module
const transport = createGrpcWebTransport(optionsHttp1);
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
expect(sentence).toBeDefined();
});
Expand All @@ -138,7 +138,7 @@ describe("node readme", function () {
transport: optionsHttp1,
},
);
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const { sentence } = await client.say({ sentence: "I feel happy." });
expect(sentence).toBeDefined();
});
Expand Down Expand Up @@ -170,7 +170,7 @@ describe("node readme", function () {
baseUrl: `http://localhost:${port}`,
httpVersion: "2",
});
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const res = await client.say({ sentence: "I feel happy." });
// console.log(res.sentence) // you said: I feel happy.
expect(res.sentence).toBe("you said: I feel happy.");
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("node readme", function () {
baseUrl: `http://localhost:${port}`,
httpVersion: "2",
});
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const res = await client.say(
{ sentence: "I feel happy." },
{ headers: { "x-user": "alice" } },
Expand Down Expand Up @@ -265,7 +265,7 @@ describe("node readme", function () {
baseUrl: `http://localhost:${port}`,
httpVersion: "2",
});
const client = createPromiseClient(ElizaService, transport);
const client = createClient(ElizaService, transport);
const req = createWritableIterable<PartialMessage<ConverseRequest>>();
try {
const res = client.converse(req);
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-node/src/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Int32Value, StringValue, MethodKind } from "@bufbuild/protobuf";
import { useNodeServer } from "./use-node-server-helper.spec.js";
import * as http2 from "node:http2";
import { connectNodeAdapter } from "./connect-node-adapter.js";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import type { Transport } from "@connectrpc/connect";
import { createTransport as createGrpcTransport } from "@connectrpc/connect/protocol-grpc";
import { createTransport as createGrpcWebTransport } from "@connectrpc/connect/protocol-grpc-web";
Expand Down Expand Up @@ -65,7 +65,7 @@ describe("Calls should fail with code internal on RST_STREAM no_error before tra
}),
);
async function testRstStream(transport: Transport) {
const client = createPromiseClient(TestService, transport);
const client = createClient(TestService, transport);
const it = client.server({ value: 1 })[Symbol.asyncIterator]();
const first = await it.next();
expect(first.done).toBeFalse();
Expand Down
8 changes: 4 additions & 4 deletions packages/connect-web-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ usually do. We repeat this for an increasing number of RPCs.

| code generator | RPCs | bundle size | minified | compressed |
| -------------- | ---: | ----------: | --------: | ---------: |
| Connect-ES | 1 | 152,706 b | 66,483 b | 16,394 b |
| Connect-ES | 4 | 168,148 b | 72,422 b | 16,888 b |
| Connect-ES | 8 | 193,461 b | 82,145 b | 17,496 b |
| Connect-ES | 16 | 227,100 b | 96,411 b | 18,258 b |
| Connect-ES | 1 | 152,692 b | 66,483 b | 16,385 b |
| Connect-ES | 4 | 168,120 b | 72,422 b | 16,893 b |
| Connect-ES | 8 | 193,426 b | 82,145 b | 17,484 b |
| Connect-ES | 16 | 227,051 b | 96,411 b | 18,238 b |
| gRPC-Web | 1 | 876,563 b | 548,495 b | 52,300 b |
| gRPC-Web | 4 | 928,964 b | 580,477 b | 54,673 b |
| gRPC-Web | 8 | 1,004,833 b | 628,223 b | 57,118 b |
Expand Down
10 changes: 5 additions & 5 deletions packages/connect-web-bench/chart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/connect-web-bench/src/gen/connectweb/entry-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { createConnectTransport } from "@connectrpc/connect-web";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { CommitService } from "./buf/registry/module/v1/commit_service_connect.js";

/* eslint-disable no-console */
Expand All @@ -25,6 +25,6 @@ export async function call() {
const transport = createConnectTransport({
baseUrl: "https://buf.build/",
});
const commitClient = createPromiseClient(CommitService, transport);
const commitClient = createClient(CommitService, transport);
console.log(await commitClient.getCommits({}));
}
14 changes: 7 additions & 7 deletions packages/connect-web-bench/src/gen/connectweb/entry-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { createConnectTransport } from "@connectrpc/connect-web";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { CommitService } from "./buf/registry/module/v1/commit_service_connect.js";
import { DownloadService } from "./buf/registry/module/v1/download_service_connect.js";
import { GraphService } from "./buf/registry/module/v1/graph_service_connect.js";
Expand All @@ -30,26 +30,26 @@ export async function call() {
const transport = createConnectTransport({
baseUrl: "https://buf.build/",
});
const commitClient = createPromiseClient(CommitService, transport);
const commitClient = createClient(CommitService, transport);
console.log(await commitClient.getCommits({}));
console.log(await commitClient.listCommits({}));
const downloadClient = createPromiseClient(DownloadService, transport);
const downloadClient = createClient(DownloadService, transport);
console.log(await downloadClient.download({}));
const graphClient = createPromiseClient(GraphService, transport);
const graphClient = createClient(GraphService, transport);
console.log(await graphClient.getGraph({}));
const labelClient = createPromiseClient(LabelService, transport);
const labelClient = createClient(LabelService, transport);
console.log(await labelClient.getLabels({}));
console.log(await labelClient.listLabels({}));
console.log(await labelClient.listLabelHistory({}));
console.log(await labelClient.createOrUpdateLabels({}));
console.log(await labelClient.archiveLabels({}));
console.log(await labelClient.unarchiveLabels({}));
const moduleClient = createPromiseClient(ModuleService, transport);
const moduleClient = createClient(ModuleService, transport);
console.log(await moduleClient.getModules({}));
console.log(await moduleClient.listModules({}));
console.log(await moduleClient.createModules({}));
console.log(await moduleClient.updateModules({}));
console.log(await moduleClient.deleteModules({}));
const resourceClient = createPromiseClient(ResourceService, transport);
const resourceClient = createClient(ResourceService, transport);
console.log(await resourceClient.getResources({}));
}
8 changes: 4 additions & 4 deletions packages/connect-web-bench/src/gen/connectweb/entry-4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { createConnectTransport } from "@connectrpc/connect-web";
import { createPromiseClient } from "@connectrpc/connect";
import { createClient } from "@connectrpc/connect";
import { CommitService } from "./buf/registry/module/v1/commit_service_connect.js";
import { DownloadService } from "./buf/registry/module/v1/download_service_connect.js";
import { GraphService } from "./buf/registry/module/v1/graph_service_connect.js";
Expand All @@ -27,11 +27,11 @@ export async function call() {
const transport = createConnectTransport({
baseUrl: "https://buf.build/",
});
const commitClient = createPromiseClient(CommitService, transport);
const commitClient = createClient(CommitService, transport);
console.log(await commitClient.getCommits({}));
console.log(await commitClient.listCommits({}));
const downloadClient = createPromiseClient(DownloadService, transport);
const downloadClient = createClient(DownloadService, transport);
console.log(await downloadClient.download({}));
const graphClient = createPromiseClient(GraphService, transport);
const graphClient = createClient(GraphService, transport);
console.log(await graphClient.getGraph({}));
}
Loading

0 comments on commit fd7b7ca

Please sign in to comment.