Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tweak getrecords types #163

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
54 changes: 23 additions & 31 deletions packages/ensjs/src/functions/public/getRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,18 @@ type WithCoinsResult = {
}

export type GetRecordsReturnType<
TTexts extends readonly string[] = readonly [string, ...string[]],
TCoins extends readonly (string | number)[] = readonly [
string | number,
...(string | number)[],
],
TContentHash extends boolean = true,
TAbi extends boolean = true,
TTexts extends readonly string[] | undefined = readonly string[],
TCoins extends readonly (string | number)[] | undefined = readonly (
| string
| number
)[],
TContentHash extends boolean | undefined = true,
TAbi extends boolean | undefined = true,
> = Prettify<
(TContentHash extends true ? WithContentHashResult : {}) &
(TAbi extends true ? WithAbiResult : {}) &
(TTexts extends readonly [string, ...string[]] ? WithTextsResult : {}) &
(TCoins extends readonly [string | number, ...(string | number)[]]
? WithCoinsResult
: {}) & {
(TTexts extends readonly string[] ? WithTextsResult : {}) &
(TCoins extends readonly (string | number)[] ? WithCoinsResult : {}) & {
/** Resolver address used for fetch */
resolverAddress: Address
}
Expand Down Expand Up @@ -261,8 +259,8 @@ const createEmptyResult = <
GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>,
'texts' | 'coins' | 'abi' | 'contentHash'
>) => ({
...(texts && texts.length > 0 ? { texts: [] as DecodedText[] } : {}),
...(coins && coins.length > 0 ? { coins: [] as DecodedAddr[] } : {}),
...(texts ? { texts: [] as DecodedText[] } : {}),
...(coins ? { coins: [] as DecodedAddr[] } : {}),
...(contentHash ? { contentHash: null } : {}),
...(abi ? { abi: null } : {}),
})
Expand Down Expand Up @@ -347,13 +345,13 @@ const createRecordResult = (
}

const decode = async <
const TTexts extends readonly string[] = readonly string[],
const TCoins extends readonly (string | number)[] = readonly (
const TTexts extends readonly string[] | undefined = readonly string[],
const TCoins extends readonly (string | number)[] | undefined = readonly (
| string
| number
)[],
const TContentHash extends boolean = true,
const TAbi extends boolean = true,
const TContentHash extends boolean | undefined = undefined,
const TAbi extends boolean | undefined = undefined,
>(
client: ClientWithEns,
data: Hex | BaseError,
Expand Down Expand Up @@ -434,13 +432,10 @@ type BatchableFunctionObject = {
encode: EncoderFunction
decode: DecoderFunction
batch: <
const TTexts extends readonly string[] = readonly string[],
const TCoins extends readonly (string | number)[] = readonly (
| string
| number
)[],
const TContentHash extends boolean = true,
const TAbi extends boolean = true,
const TTexts extends readonly string[] | undefined = undefined,
const TCoins extends readonly (string | number)[] | undefined = undefined,
const TContentHash extends boolean | undefined = undefined,
const TAbi extends boolean | undefined = undefined,
>(
args: GetRecordsParameters<TTexts, TCoins, TContentHash, TAbi>,
) => {
Expand Down Expand Up @@ -477,13 +472,10 @@ type BatchableFunctionObject = {
* // { texts: [{ key: 'com.twitter', value: 'ensdomains' }, { key: 'com.github', value: 'ensdomains' }], coins: [{ id: 60, name: 'ETH', value: '0xFe89cc7aBB2C4183683ab71653C4cdc9B02D44b7' }], contentHash: { protocolType: 'ipns', decoded: 'k51qzi5uqu5djdczd6zw0grmo23j2vkj9uzvujencg15s5rlkq0ss4ivll8wqw' } }
*/
const getRecords = generateFunction({ encode, decode }) as (<
const TTexts extends readonly string[] = readonly string[],
const TCoins extends readonly (string | number)[] = readonly (
| string
| number
)[],
const TContentHash extends boolean = true,
const TAbi extends boolean = true,
const TTexts extends readonly string[] | undefined = undefined,
const TCoins extends readonly (string | number)[] | undefined = undefined,
const TContentHash extends boolean | undefined = undefined,
const TAbi extends boolean | undefined = undefined,
>(
client: ClientWithEns,
{
Expand Down
Loading