Skip to content

Commit

Permalink
Merge branch 'bufbuild:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
oott123 authored Jun 7, 2023
2 parents fa2e6fa + f19a17d commit 9a86fe1
Show file tree
Hide file tree
Showing 25 changed files with 175 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.17.0
- uses: bufbuild/buf-setup-action@v1.20.0
with:
github_token: ${{ github.token }}
- name: cache
Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@types/express": "^4.17.17"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.2.0"
"@bufbuild/protobuf": "^1.2.1"
},
"files": [
"dist/**"
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"fastify": "^4.17.0"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.2.0"
"@bufbuild/protobuf": "^1.2.1"
},
"files": [
"dist/**"
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@bufbuild/connect-node": "^0.9.1"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.2.0",
"@bufbuild/protobuf": "^1.2.1",
"next": "^13.2.4"
},
"files": [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-node-test/src/gen/server/v1/server_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"headers-polyfill": "^3.1.2"
},
"peerDependencies": {
"@bufbuild/protobuf": "^1.2.0"
"@bufbuild/protobuf": "^1.2.1"
},
"devDependencies": {
"@types/jasmine": "^4.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-web-bench/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ it like a web server would usually do.

| code generator | bundle size | minified | compressed |
|----------------|-------------------:|-----------------------:|---------------------:|
| connect | 111,912 b | 48,912 b | 13,145 b |
| connect | 112,742 b | 49,450 b | 13,229 b |
| grpc-web | 414,906 b | 301,127 b | 53,279 b |
4 changes: 2 additions & 2 deletions packages/connect-web-bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"dependencies": {
"@bufbuild/connect-web": "0.9.1",
"@bufbuild/protobuf": "^1.2.0",
"@bufbuild/protoc-gen-es": "^1.2.0",
"@bufbuild/protobuf": "^1.2.1",
"@bufbuild/protoc-gen-es": "^1.2.1",
"brotli": "^1.3.3",
"esbuild": "^0.16.12",
"google-protobuf": "^3.21.0",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions packages/connect-web-test/src/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright 2021-2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { TestService } from "./gen/grpc/testing/test_connect.js";
import {
SimpleRequest,
SimpleResponse,
} from "./gen/grpc/testing/messages_pb.js";
import { createConnectTransport } from "@bufbuild/connect-web";

describe("custom fetch", function () {
describe("with Connect transport", () => {
it("should only call Response#json with the JSON format", async function () {
const response = new Response(
new SimpleResponse({ username: "donald" }).toJsonString(),
{
headers: {
"Content-Type": "application/json",
},
}
);
spyOn(response, "arrayBuffer").and.callThrough();
spyOn(response, "json").and.callThrough();
const transport = createConnectTransport({
baseUrl: "https://example.com",
fetch: () => Promise.resolve(response),
});
await transport.unary(
TestService,
TestService.methods.unaryCall,
undefined,
undefined,
undefined,
new SimpleRequest()
);
expect(response.json).toHaveBeenCalledTimes(1); // eslint-disable-line @typescript-eslint/unbound-method
expect(response.arrayBuffer).toHaveBeenCalledTimes(0); // eslint-disable-line @typescript-eslint/unbound-method
});
it("should only call Response#arrayBuffer with the binary format on the happy path", async function () {
const response = new Response(
new SimpleResponse({ username: "donald" }).toBinary(),
{
headers: {
"Content-Type": "application/proto",
},
}
);
spyOn(response, "arrayBuffer").and.callThrough();
spyOn(response, "json").and.callThrough();
const transport = createConnectTransport({
fetch: () => Promise.resolve(response),
baseUrl: "https://example.com",
useBinaryFormat: true,
});
await transport.unary(
TestService,
TestService.methods.unaryCall,
undefined,
undefined,
undefined,
new SimpleRequest()
);
expect(response.json).toHaveBeenCalledTimes(0); // eslint-disable-line @typescript-eslint/unbound-method
expect(response.arrayBuffer).toHaveBeenCalledTimes(1); // eslint-disable-line @typescript-eslint/unbound-method
});
it("should call Response#json with the binary format for an error response", async function () {
const response = new Response(
JSON.stringify({
code: "permission_denied",
message: "foobar",
}),
{
status: 403,
headers: {
"Content-Type": "application/json",
},
}
);
spyOn(response, "arrayBuffer").and.callThrough();
spyOn(response, "json").and.callThrough();
const transport = createConnectTransport({
fetch: () => Promise.resolve(response),
baseUrl: "https://example.com",
useBinaryFormat: true,
});
await expectAsync(
transport.unary(
TestService,
TestService.methods.unaryCall,
undefined,
undefined,
undefined,
new SimpleRequest()
)
).toBeRejectedWithError(/\[permission_denied] foobar/);
expect(response.json).toHaveBeenCalledTimes(1); // eslint-disable-line @typescript-eslint/unbound-method
expect(response.arrayBuffer).toHaveBeenCalledTimes(0); // eslint-disable-line @typescript-eslint/unbound-method
});
});
});
Loading

0 comments on commit 9a86fe1

Please sign in to comment.