Skip to content

Commit 4c3b209

Browse files
committed
protocol: make client options configurable
1 parent 2ee8cc1 commit 4c3b209

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "protocol: make client options configurable",
4+
"packageName": "@apibara/protocol",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/protocol/src/client.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Schema } from "@effect/schema";
22
import {
3+
type ChannelCredentials,
4+
type ChannelOptions,
35
type DefaultCallOptions,
46
type NormalizedServiceDefinition,
57
createChannel,
@@ -44,20 +46,32 @@ export interface Client<TFilter, TBlock> {
4446
): AsyncIterable<StreamDataResponse<TBlock>>;
4547
}
4648

49+
export type CreateClientOptions = {
50+
defaultCallOptions?: DefaultCallOptions<
51+
NormalizedServiceDefinition<proto.stream.DnaStreamDefinition>
52+
>;
53+
credentials?: ChannelCredentials;
54+
channelOptions?: ChannelOptions;
55+
};
56+
4757
/** Create a client connecting to the DNA grpc service. */
4858
export function createClient<TFilter, TBlock>(
4959
config: StreamConfig<TFilter, TBlock>,
5060
streamUrl: string,
51-
defaultCallOptions?: DefaultCallOptions<
52-
NormalizedServiceDefinition<proto.stream.DnaStreamDefinition>
53-
>,
61+
options: CreateClientOptions = {},
5462
) {
55-
const channel = createChannel(streamUrl);
63+
const channel = createChannel(
64+
streamUrl,
65+
options?.credentials,
66+
options?.channelOptions,
67+
);
68+
5669
const client: proto.stream.DnaStreamClient = grpcCreateClient(
5770
proto.stream.DnaStreamDefinition,
5871
channel,
59-
defaultCallOptions,
72+
options?.defaultCallOptions,
6073
);
74+
6175
return new GrpcClient(config, client);
6276
}
6377

0 commit comments

Comments
 (0)