-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use MaybeAccount types in fetch account helpers of js-experimental (#152
) * Rename safeFetch into fetchMaybe functions * Generate MaybeAccount type for each account * Update account fetch helpers * Add changeset
- Loading branch information
1 parent
1877460
commit 7695a7a
Showing
21 changed files
with
525 additions
and
307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@metaplex-foundation/kinobi': patch | ||
--- | ||
|
||
Use MaybeAccount types in fetch account helpers of js-experimental |
32 changes: 15 additions & 17 deletions
32
src/renderers/js-experimental/fragments/accountFetchHelpers.njk
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,45 +1,43 @@ | ||
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): {{ accountType }}<TAddress> { | ||
return decodeAccount(encodedAccount, {{ decoderFunction }}); | ||
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): {{ accountType }}<TAddress>; | ||
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): {{ accountMaybeType }}<TAddress>; | ||
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): {{ accountType }}<TAddress> | {{ accountMaybeType }}<TAddress> { | ||
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, {{ decoderFunction }}); | ||
} | ||
|
||
export async function {{ fetchFunction }}<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig, | ||
): Promise<{{ accountType }}<TAddress>> { | ||
const maybeAccount = await fetchEncodedAccount(rpc, address, config); | ||
const maybeAccount = await {{ fetchMaybeFunction }}(rpc, address, config); | ||
assertAccountExists(maybeAccount); | ||
return {{ decodeFunction }}(maybeAccount); | ||
return maybeAccount; | ||
} | ||
|
||
export async function {{ safeFetchFunction }}<TAddress extends string = string>( | ||
export async function {{ fetchMaybeFunction }}<TAddress extends string = string>( | ||
rpc: Parameters<typeof fetchEncodedAccount>[0], | ||
address: Address<TAddress>, | ||
config?: FetchAccountConfig, | ||
): Promise<{{ accountType }}<TAddress> | null> { | ||
): Promise<{{ accountMaybeType }}<TAddress>> { | ||
const maybeAccount = await fetchEncodedAccount(rpc, address, config); | ||
return maybeAccount.exists ? {{ decodeFunction }}(maybeAccount) : null; | ||
return {{ decodeFunction }}(maybeAccount); | ||
} | ||
|
||
export async function {{ fetchAllFunction }}( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig, | ||
): Promise<{{ accountType }}[]> { | ||
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); | ||
return maybeAccounts.map((maybeAccount) => { | ||
assertAccountExists(maybeAccount); | ||
return {{ decodeFunction }}(maybeAccount); | ||
}); | ||
const maybeAccounts = await {{ fetchAllMaybeFunction }}(rpc, addresses, config); | ||
assertAccountsExist(maybeAccounts); | ||
return maybeAccounts; | ||
} | ||
|
||
export async function {{ safeFetchAllFunction }}( | ||
export async function {{ fetchAllMaybeFunction }}( | ||
rpc: Parameters<typeof fetchEncodedAccounts>[0], | ||
addresses: Array<Address>, | ||
config?: FetchAccountsConfig, | ||
): Promise<{{ accountType }}[]> { | ||
): Promise<{{ accountMaybeType }}[]> { | ||
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); | ||
return maybeAccounts | ||
.filter((maybeAccount) => maybeAccount.exists) | ||
.map((maybeAccount) => {{ decodeFunction }}(maybeAccount as EncodedAccount)); | ||
return maybeAccounts.map((maybeAccount) => {{ decodeFunction }}(maybeAccount)); | ||
} |
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
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
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
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
Oops, something went wrong.