From e7ca1f6de44efa99f47eebff505da7f68b7bc87c Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Mon, 10 Apr 2023 17:35:59 -0400 Subject: [PATCH 1/6] connect-web: allows for a `fetch` override it was unclear to me whether it was necessary to pull in `createFetchClient`, but this seems to do the trick in the most obvious possible way. --- packages/connect-web/src/connect-transport.ts | 6 ++++++ packages/connect-web/src/grpc-web-transport.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/connect-web/src/connect-transport.ts b/packages/connect-web/src/connect-transport.ts index e84f4063e..d423f14ed 100644 --- a/packages/connect-web/src/connect-transport.ts +++ b/packages/connect-web/src/connect-transport.ts @@ -102,6 +102,11 @@ export interface ConnectTransportOptions { * Options for the binary wire format. */ binaryOptions?: Partial; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; } /** @@ -114,6 +119,7 @@ export function createConnectTransport( ): Transport { assertFetchApi(); const useBinaryFormat = options.useBinaryFormat ?? false; + const fetch = options.fetch ?? globalThis.fetch; return { async unary< I extends Message = AnyMessage, diff --git a/packages/connect-web/src/grpc-web-transport.ts b/packages/connect-web/src/grpc-web-transport.ts index 41c2cd801..cb9d896cc 100644 --- a/packages/connect-web/src/grpc-web-transport.ts +++ b/packages/connect-web/src/grpc-web-transport.ts @@ -100,6 +100,11 @@ export interface GrpcWebTransportOptions { * Options for the binary wire format. */ binaryOptions?: Partial; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; } /** @@ -117,6 +122,7 @@ export function createGrpcWebTransport( ): Transport { assertFetchApi(); const useBinaryFormat = options.useBinaryFormat ?? true; + const fetch = options.fetch ?? globalThis.fetch; return { async unary< I extends Message = AnyMessage, From 5643542eb45a451f20f4f5807b6e292605ae9233 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Mon, 10 Apr 2023 17:36:18 -0400 Subject: [PATCH 2/6] connect-node: allows for `fetch` override --- packages/connect-node/src/connect-transport.ts | 5 +++++ packages/connect-node/src/grpc-transport.ts | 5 +++++ packages/connect-node/src/grpc-web-transport.ts | 5 +++++ packages/connect/src/protocol/transport-options.ts | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/packages/connect-node/src/connect-transport.ts b/packages/connect-node/src/connect-transport.ts index 385954251..eae46a1e3 100644 --- a/packages/connect-node/src/connect-transport.ts +++ b/packages/connect-node/src/connect-transport.ts @@ -111,6 +111,11 @@ type ConnectTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect-node/src/grpc-transport.ts b/packages/connect-node/src/grpc-transport.ts index 9bf9ce7c7..c046a0b68 100644 --- a/packages/connect-node/src/grpc-transport.ts +++ b/packages/connect-node/src/grpc-transport.ts @@ -112,6 +112,11 @@ type GrpcTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect-node/src/grpc-web-transport.ts b/packages/connect-node/src/grpc-web-transport.ts index 10d0969cd..c539c8c08 100644 --- a/packages/connect-node/src/grpc-web-transport.ts +++ b/packages/connect-node/src/grpc-web-transport.ts @@ -112,6 +112,11 @@ type GrpcWebTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect/src/protocol/transport-options.ts b/packages/connect/src/protocol/transport-options.ts index 24e9b7a16..a1fa8feb4 100644 --- a/packages/connect/src/protocol/transport-options.ts +++ b/packages/connect/src/protocol/transport-options.ts @@ -113,4 +113,9 @@ export interface CommonTransportOptions { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes: number; + + /** + * Optional override of the fetch implementation used by the transport. + */ + fetch?: typeof globalThis.fetch; } From e971b1c73423b1144d3773424ef11b7756033b51 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Mon, 10 Apr 2023 17:36:18 -0400 Subject: [PATCH 3/6] Revert "connect-node: allows for `fetch` override" This reverts commit 5643542eb45a451f20f4f5807b6e292605ae9233. --- packages/connect-node/src/connect-transport.ts | 5 ----- packages/connect-node/src/grpc-transport.ts | 5 ----- packages/connect-node/src/grpc-web-transport.ts | 5 ----- packages/connect/src/protocol/transport-options.ts | 5 ----- 4 files changed, 20 deletions(-) diff --git a/packages/connect-node/src/connect-transport.ts b/packages/connect-node/src/connect-transport.ts index eae46a1e3..385954251 100644 --- a/packages/connect-node/src/connect-transport.ts +++ b/packages/connect-node/src/connect-transport.ts @@ -111,11 +111,6 @@ type ConnectTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; - - /** - * Optional override of the fetch implementation used by the transport. - */ - fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect-node/src/grpc-transport.ts b/packages/connect-node/src/grpc-transport.ts index c046a0b68..9bf9ce7c7 100644 --- a/packages/connect-node/src/grpc-transport.ts +++ b/packages/connect-node/src/grpc-transport.ts @@ -112,11 +112,6 @@ type GrpcTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; - - /** - * Optional override of the fetch implementation used by the transport. - */ - fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect-node/src/grpc-web-transport.ts b/packages/connect-node/src/grpc-web-transport.ts index c539c8c08..10d0969cd 100644 --- a/packages/connect-node/src/grpc-web-transport.ts +++ b/packages/connect-node/src/grpc-web-transport.ts @@ -112,11 +112,6 @@ type GrpcWebTransportOptions = NodeHttpClientOptions & { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes?: number; - - /** - * Optional override of the fetch implementation used by the transport. - */ - fetch?: typeof globalThis.fetch; }; /** diff --git a/packages/connect/src/protocol/transport-options.ts b/packages/connect/src/protocol/transport-options.ts index a1fa8feb4..24e9b7a16 100644 --- a/packages/connect/src/protocol/transport-options.ts +++ b/packages/connect/src/protocol/transport-options.ts @@ -113,9 +113,4 @@ export interface CommonTransportOptions { * The default limit is the maximum supported value of ~4GiB. */ writeMaxBytes: number; - - /** - * Optional override of the fetch implementation used by the transport. - */ - fetch?: typeof globalThis.fetch; } From 19a6fd3a80271ff777d38fafc0a9514dddc1974e Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 9 May 2023 11:31:33 -0400 Subject: [PATCH 4/6] updates README.md --- packages/connect-web-bench/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/connect-web-bench/README.md b/packages/connect-web-bench/README.md index 7557d1f48..73989ef31 100644 --- a/packages/connect-web-bench/README.md +++ b/packages/connect-web-bench/README.md @@ -10,5 +10,5 @@ it like a web server would usually do. | code generator | bundle size | minified | compressed | |----------------|-------------------:|-----------------------:|---------------------:| -| connect | 107,197 b | 46,935 b | 12,539 b | +| connect | 107,289 b | 46,984 b | 12,551 b | | grpc-web | 414,906 b | 301,127 b | 53,279 b | From 589c42d599b6c06bdd2169c05b33569960b8f174 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 9 May 2023 12:06:52 -0400 Subject: [PATCH 5/6] updates README.md --- packages/connect-web-bench/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/connect-web-bench/README.md b/packages/connect-web-bench/README.md index c8312f393..f6a1588ce 100644 --- a/packages/connect-web-bench/README.md +++ b/packages/connect-web-bench/README.md @@ -10,5 +10,5 @@ it like a web server would usually do. | code generator | bundle size | minified | compressed | |----------------|-------------------:|-----------------------:|---------------------:| -| connect | 107,175 b | 46,924 b | 12,556 b | +| connect | 107,267 b | 46,973 b | 12,522 b | | grpc-web | 414,906 b | 301,127 b | 53,279 b | From afab0e0eb20e32f21c6167a6a1621655f0c76d23 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Thu, 11 May 2023 10:28:08 -0400 Subject: [PATCH 6/6] updates README.md --- packages/connect-web-bench/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/connect-web-bench/README.md b/packages/connect-web-bench/README.md index a30985cb8..5fa9bcbe4 100644 --- a/packages/connect-web-bench/README.md +++ b/packages/connect-web-bench/README.md @@ -10,5 +10,5 @@ it like a web server would usually do. | code generator | bundle size | minified | compressed | |----------------|-------------------:|-----------------------:|---------------------:| -| connect | 109,136 b | 47,764 b | 12,825 b | +| connect | 109,228 b | 47,812 b | 12,847 b | | grpc-web | 414,906 b | 301,127 b | 53,279 b |