-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filters build: args required, filters array, singular event
- Loading branch information
1 parent
6ae709a
commit a150566
Showing
3 changed files
with
97 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,50 @@ | ||
import type { Abi, GetEventArgs } from "viem"; | ||
import type { ParseAbiEvent, SafeEventNames } from "./utilityTypes.js"; | ||
|
||
// TODO: Fix this type ( changes: args are required, event is singular for each filter ) | ||
// Filters are only for topic1/2/3 filtering | ||
export type GetEventFilter< | ||
abi extends Abi, | ||
contract, | ||
/// | ||
safeEventNames extends string = SafeEventNames<abi>, | ||
> = contract extends { | ||
filter: { | ||
event: infer event extends readonly string[] | string; | ||
event: infer event extends string; | ||
}; | ||
} | ||
? // 1. Contract has a filter with event | ||
event extends readonly string[] | ||
? // 1.a Filter event is an array | ||
? event extends safeEventNames | ||
? // 1.b.i Filter event is a valid string | ||
{ | ||
filter?: { | ||
event: readonly safeEventNames[]; | ||
event: safeEventNames | event; | ||
args: GetEventArgs< | ||
abi, | ||
string, | ||
{ | ||
EnableUnion: true; | ||
IndexedOnly: true; | ||
Required: false; | ||
}, | ||
ParseAbiEvent<abi, event> | ||
>; | ||
}; | ||
} | ||
: // 1.b Filter event is a string | ||
event extends safeEventNames | ||
? // 1.b.i Filter event is a valid string | ||
{ | ||
filter?: { | ||
event: safeEventNames | event; | ||
args?: GetEventArgs< | ||
abi, | ||
string, | ||
{ | ||
EnableUnion: true; | ||
IndexedOnly: true; | ||
Required: false; | ||
}, | ||
ParseAbiEvent<abi, event> | ||
>; | ||
}; | ||
} | ||
: // 1.b.ii Filter event is an invalid string | ||
{ | ||
filter?: { | ||
: // 1.b.ii Filter event is an invalid string | ||
{ | ||
filter?: { | ||
event: safeEventNames; | ||
args: GetEventArgs<Abi | readonly unknown[], string>; | ||
}; | ||
} | ||
: { | ||
filter?: | ||
| { | ||
event: safeEventNames; | ||
args: GetEventArgs<Abi | readonly unknown[], string>; | ||
}[] | ||
| { | ||
event: safeEventNames; | ||
args?: GetEventArgs<Abi | readonly unknown[], string>; | ||
args: GetEventArgs<Abi | readonly unknown[], string>; | ||
}; | ||
} | ||
: // 2. Contract doesn't have a filter with event | ||
{ | ||
filter?: { | ||
event: safeEventNames | readonly safeEventNames[]; | ||
args?: GetEventArgs<Abi | readonly unknown[], string>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters