Skip to content

Commit 208605b

Browse files
committed
fix: codeRabbit comment
1 parent 0e4a349 commit 208605b

File tree

3 files changed

+3142
-8837
lines changed

3 files changed

+3142
-8837
lines changed

packages/sdk-ts/src/client/base/BaseGrpcConsumer.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import type { GrpcWebTransportAdditionalOptions } from '../../types'
1414
* It uses the GrpcWebRpcTransport with GrpcWebFetchTransport from @protobuf-ts/grpcweb-transport.
1515
*/
1616
export default class BaseGrpcConsumer {
17-
protected transport: GrpcWebRpcTransport
17+
private _client: unknown
18+
protected endpoint: string
1819
protected module: string = ''
20+
protected transport: GrpcWebRpcTransport
1921
protected metadata?: Record<string, string>
20-
protected endpoint: string
2122
protected options?: GrpcWebTransportAdditionalOptions
22-
private _client: unknown
2323

2424
constructor(endpoint: string, options?: GrpcWebTransportAdditionalOptions) {
25-
this.endpoint = endpoint
2625
this.options = options
26+
this.endpoint = endpoint
2727
this.transport = new GrpcWebRpcTransport(endpoint, options)
2828
}
2929

@@ -37,6 +37,10 @@ export default class BaseGrpcConsumer {
3737
...this.options,
3838
meta: this.metadata,
3939
})
40+
41+
// Invalidate cached client so initClient creates a new client with updated transport
42+
this._client = undefined
43+
4044
return this
4145
}
4246

@@ -45,6 +49,10 @@ export default class BaseGrpcConsumer {
4549
*/
4650
public clearMetadata() {
4751
this.metadata = undefined
52+
// Recreate transport without metadata, preserving existing options
53+
this.transport = new GrpcWebRpcTransport(this.endpoint, this.options)
54+
// Invalidate cached client so initClient creates a new client with updated transport
55+
this._client = undefined
4856
}
4957

5058
public getTransport(): GrpcWebRpcTransport {
@@ -66,6 +74,7 @@ export default class BaseGrpcConsumer {
6674
if (!this._client) {
6775
this._client = new ClientClass(this.transport)
6876
}
77+
6978
return this._client as TClient
7079
}
7180

packages/sdk-ts/src/types/grpc.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
import type { GrpcWebOptions } from '@protobuf-ts/grpcweb-transport'
22

3-
export type GrpcWebTransportAdditionalOptions = Omit<GrpcWebOptions, 'baseUrl'>
3+
export type GrpcWebTransportAdditionalOptions = Omit<
4+
GrpcWebOptions,
5+
'baseUrl'
6+
> & {
7+
meta?: Record<string, string>
8+
}

0 commit comments

Comments
 (0)