Skip to content

Commit 64a7a99

Browse files
committed
chore: narrow rpc stream integration changes
1 parent 1679ad6 commit 64a7a99

2 files changed

Lines changed: 51 additions & 19 deletions

File tree

packages/indexer/src/indexer.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ export type HandlerArgs<TBlock> = {
117117
abortSignal?: AbortSignal;
118118
};
119119

120-
export type IndexerConfig<TFilter, TBlock> = {
121-
streamUrl?: string;
120+
export type BaseIndexerConfig<TFilter, TBlock> = {
122121
filter: TFilter;
123122
finality?: DataFinality;
124123
clientOptions?: CreateClientOptions;
@@ -131,43 +130,68 @@ export type IndexerConfig<TFilter, TBlock> = {
131130
debug?: boolean;
132131
} & IndexerStartingCursor;
133132

133+
export type IndexerConfig<TFilter, TBlock> = BaseIndexerConfig<
134+
TFilter,
135+
TBlock
136+
> & {
137+
streamUrl: string;
138+
};
139+
140+
export type RpcIndexerConfig<TFilter, TBlock> = BaseIndexerConfig<
141+
TFilter,
142+
TBlock
143+
> & {
144+
streamUrl?: string;
145+
};
146+
134147
export type IndexerStreamConfig<TFilter, TBlock> =
135148
| StreamConfig<TFilter, TBlock>
136149
| RpcStreamConfig<TFilter, TBlock>;
137150

138-
export type IndexerWithStreamConfig<TFilter, TBlock> = IndexerConfig<
151+
export type IndexerWithDnaStreamConfig<TFilter, TBlock> = IndexerConfig<
139152
TFilter,
140153
TBlock
141154
> & {
142-
streamConfig: IndexerStreamConfig<TFilter, TBlock>;
155+
streamConfig: StreamConfig<TFilter, TBlock>;
143156
};
144157

158+
export type IndexerWithRpcStreamConfig<TFilter, TBlock> = RpcIndexerConfig<
159+
TFilter,
160+
TBlock
161+
> & {
162+
streamConfig: RpcStreamConfig<TFilter, TBlock>;
163+
};
164+
165+
export type IndexerWithStreamConfig<TFilter, TBlock> =
166+
| IndexerWithDnaStreamConfig<TFilter, TBlock>
167+
| IndexerWithRpcStreamConfig<TFilter, TBlock>;
168+
145169
export function defineIndexer<TFilter, TBlock>(
146170
streamConfig: StreamConfig<TFilter, TBlock>,
147171
): (
148-
config: IndexerConfig<TFilter, TBlock> & { streamUrl: string },
149-
) => IndexerWithStreamConfig<TFilter, TBlock>;
172+
config: IndexerConfig<TFilter, TBlock>,
173+
) => IndexerWithDnaStreamConfig<TFilter, TBlock>;
150174

151175
export function defineIndexer<TFilter, TBlock>(
152176
streamConfig: RpcStreamConfig<TFilter, TBlock>,
153177
): (
154-
config: IndexerConfig<TFilter, TBlock>,
155-
) => IndexerWithStreamConfig<TFilter, TBlock>;
178+
config: RpcIndexerConfig<TFilter, TBlock>,
179+
) => IndexerWithRpcStreamConfig<TFilter, TBlock>;
156180

157181
export function defineIndexer<TFilter, TBlock>(
158182
streamConfig: IndexerStreamConfig<TFilter, TBlock>,
159-
) {
183+
): unknown {
160184
return (
161-
config: IndexerConfig<TFilter, TBlock>,
162-
): IndexerWithStreamConfig<TFilter, TBlock> => ({
185+
config: IndexerConfig<TFilter, TBlock> | RpcIndexerConfig<TFilter, TBlock>,
186+
) => ({
163187
streamConfig,
164188
...config,
165189
});
166190
}
167191

168192
export interface Indexer<TFilter, TBlock> {
169193
streamConfig: IndexerStreamConfig<TFilter, TBlock>;
170-
options: IndexerConfig<TFilter, TBlock>;
194+
options: IndexerConfig<TFilter, TBlock> | RpcIndexerConfig<TFilter, TBlock>;
171195
hooks: Hookable<IndexerHooks<TFilter, TBlock>>;
172196
}
173197

pnpm-lock.yaml

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)