Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "protocol: make client options configurable",
"packageName": "@apibara/protocol",
"email": "francesco@ceccon.me",
"dependentChangeType": "patch"
}
24 changes: 19 additions & 5 deletions packages/protocol/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Schema } from "@effect/schema";
import {
type ChannelCredentials,
type ChannelOptions,
type DefaultCallOptions,
type NormalizedServiceDefinition,
createChannel,
Expand Down Expand Up @@ -44,20 +46,32 @@ export interface Client<TFilter, TBlock> {
): AsyncIterable<StreamDataResponse<TBlock>>;
}

export type CreateClientOptions = {
defaultCallOptions?: DefaultCallOptions<
NormalizedServiceDefinition<proto.stream.DnaStreamDefinition>
>;
credentials?: ChannelCredentials;
channelOptions?: ChannelOptions;
};

/** Create a client connecting to the DNA grpc service. */
export function createClient<TFilter, TBlock>(
config: StreamConfig<TFilter, TBlock>,
streamUrl: string,
defaultCallOptions?: DefaultCallOptions<
NormalizedServiceDefinition<proto.stream.DnaStreamDefinition>
>,
options: CreateClientOptions = {},
) {
const channel = createChannel(streamUrl);
const channel = createChannel(
streamUrl,
options?.credentials,
options?.channelOptions,
);

const client: proto.stream.DnaStreamClient = grpcCreateClient(
proto.stream.DnaStreamDefinition,
channel,
defaultCallOptions,
options?.defaultCallOptions,
);

return new GrpcClient(config, client);
}

Expand Down
Loading