Skip to content

Commit

Permalink
[refactor] Flatten options to be consistent across all, remove casts,…
Browse files Browse the repository at this point in the history
… fix imports and exports (#207)

* [args] Flatten all options args to a single level

Having multiple levels made it a harder to find all the
inputs considering sometimes pagination was deeper than
one level.

* [refactor] Remove most usages of casts

Many of the casts were unnecessary, and can hide refactor bugs. This
removes them, and adds appropriate functions when necessary.

* [refactor] Remove more casting

* [refactor] Remove more casts

* [refactor] Cleanup imports in tests to be src, export AnyPublicKey/Signature

* [CHANGELOG] Add new changes
  • Loading branch information
gregnazario authored Nov 28, 2023
1 parent b7e03dc commit fbb32c3
Show file tree
Hide file tree
Showing 53 changed files with 597 additions and 472 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T
- Respect `API_KEY` option in `clientConfig` when making indexer and/or fullnode queries
- [`Added`] Added `waitForIndexer` function to wait for indexer to sync up with full node. All indexer query functions now accepts a new optional param `minimumLedgerVersion` to wait for indexer to sync up with the target processor.
- Add `getSigningMessage` to allow users to sign transactions with external signers and other use cases

Breaking:
- Changes ANS date usage to consistently use epoch timestamps represented in milliseconds.
- [`Breaking`] Changes ANS date usage to consistently use epoch timestamps represented in milliseconds.
- `getExpiration`: Previously returned seconds, now returns milliseconds
- `registerName`: Argument `expiration.expirationDate` was previously a `Date` object, now it is an epoch timestamp represented in milliseconds
- All query functions return epoch milliseconds instead of ISO date strings.
- [`Breaking`] Flatten options for all functions to be a single level
- Cleanup internal usage of casting
- Export AnyPublicKey and AnySignature types

## 0.0.7 (2023-11-16)

Expand Down
68 changes: 26 additions & 42 deletions src/api/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import {
GetAccountOwnedObjectsResponse,
GetAccountOwnedTokensFromCollectionResponse,
GetAccountOwnedTokensQueryResponse,
LedgerVersion,
LedgerVersionArg,
MoveModuleBytecode,
MoveResource,
MoveStructId,
OrderBy,
OrderByArg,
PaginationArgs,
TokenStandard,
TokenStandardArg,
TransactionResponse,
WhereArg,
} from "../types";
import {
deriveAccountFromPrivateKey,
Expand Down Expand Up @@ -84,7 +85,7 @@ export class Account {

async getAccountModules(args: {
accountAddress: AccountAddressInput;
options?: PaginationArgs & LedgerVersion;
options?: PaginationArgs & LedgerVersionArg;
}): Promise<MoveModuleBytecode[]> {
return getModules({ aptosConfig: this.config, ...args });
}
Expand All @@ -109,7 +110,7 @@ export class Account {
async getAccountModule(args: {
accountAddress: AccountAddressInput;
moduleName: string;
options?: LedgerVersion;
options?: LedgerVersionArg;
}): Promise<MoveModuleBytecode> {
return getModule({ aptosConfig: this.config, ...args });
}
Expand Down Expand Up @@ -150,7 +151,7 @@ export class Account {
*/
async getAccountResources(args: {
accountAddress: AccountAddressInput;
options?: PaginationArgs & LedgerVersion;
options?: PaginationArgs & LedgerVersionArg;
}): Promise<MoveResource[]> {
return getResources({ aptosConfig: this.config, ...args });
}
Expand All @@ -176,7 +177,7 @@ export class Account {
async getAccountResource<T extends {} = any>(args: {
accountAddress: AccountAddressInput;
resourceType: MoveStructId;
options?: LedgerVersion;
options?: LedgerVersionArg;
}): Promise<T> {
return getResource<T>({ aptosConfig: this.config, ...args });
}
Expand All @@ -194,7 +195,7 @@ export class Account {
async lookupOriginalAccountAddress(args: {
authenticationKey: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: LedgerVersion;
options?: LedgerVersionArg;
}): Promise<AccountAddress> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down Expand Up @@ -236,19 +237,15 @@ export class Account {
* @param args.accountAddress The account address we want to get the tokens for
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param args.options.tokenStandard The NFT standard to query for
* @param args.options.pagination.offset The number token to start returning results from
* @param args.options.pagination.limit The number of results to return
* @param args.options.offset The number token to start returning results from
* @param args.options.limit The number of results to return
* @param args.options.orderBy The order to sort the tokens by
* @returns Tokens array with the token data
*/
async getAccountOwnedTokens(args: {
accountAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
tokenStandard?: TokenStandard;
pagination?: PaginationArgs;
orderBy?: OrderBy<GetAccountOwnedTokensQueryResponse[0]>;
};
options?: TokenStandardArg & PaginationArgs & OrderByArg<GetAccountOwnedTokensQueryResponse[0]>;
}): Promise<GetAccountOwnedTokensQueryResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -271,20 +268,16 @@ export class Account {
* @param args.collectionAddress The address of the collection being queried
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param args.options.tokenStandard The NFT standard to query for
* @param args.options.pagination.offset The number token to start returning results from
* @param args.options.pagination.limit The number of results to return
* @param args.options.offset The number token to start returning results from
* @param args.options.limit The number of results to return
* @param args.options.orderBy The order to sort the tokens by
* @returns Tokens array with the token data
*/
async getAccountOwnedTokensFromCollectionAddress(args: {
accountAddress: AccountAddressInput;
collectionAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
tokenStandard?: TokenStandard;
pagination?: PaginationArgs;
orderBy?: OrderBy<GetAccountOwnedTokensFromCollectionResponse[0]>;
};
options?: TokenStandardArg & PaginationArgs & OrderByArg<GetAccountOwnedTokensFromCollectionResponse[0]>;
}): Promise<GetAccountOwnedTokensFromCollectionResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -306,19 +299,15 @@ export class Account {
* @param args.accountAddress The account address we want to get the collections for
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param args.options.tokenStandard The NFT standard to query for
* @param args.options.pagination.offset The number collection to start returning results from
* @param args.options.pagination.limit The number of results to return
* @param args.options.offset The number collection to start returning results from
* @param args.options.limit The number of results to return
* @param args.options.orderBy The order to sort the tokens by
* @returns Collections array with the collections data
*/
async getAccountCollectionsWithOwnedTokens(args: {
accountAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
tokenStandard?: TokenStandard;
pagination?: PaginationArgs;
orderBy?: OrderBy<GetAccountCollectionsWithOwnedTokenResponse[0]>;
};
options?: TokenStandardArg & PaginationArgs & OrderByArg<GetAccountCollectionsWithOwnedTokenResponse[0]>;
}): Promise<GetAccountCollectionsWithOwnedTokenResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down Expand Up @@ -358,20 +347,18 @@ export class Account {
*
* @param args.accountAddress The account address we want to get the coins data for
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param args.options.pagination.offset optional. The number coin to start returning results from
* @param args.options.pagination.limit optional. The number of results to return
* @param args.options.offset optional. The number coin to start returning results from
* @param args.options.limit optional. The number of results to return
* @param args.options.orderBy optional. The order to sort the coins by
* @param args.options.where optional. Filter the results by
* @returns Array with the coins data
*/
async getAccountCoinsData(args: {
accountAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetAccountCoinsDataResponse[0]>;
where?: CurrentFungibleAssetBalancesBoolExp;
};
options?: PaginationArgs &
OrderByArg<GetAccountCoinsDataResponse[0]> &
WhereArg<CurrentFungibleAssetBalancesBoolExp>;
}): Promise<GetAccountCoinsDataResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down Expand Up @@ -448,18 +435,15 @@ export class Account {
*
* @param args.accountAddress The account address we want to get the objects for
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param args.options.pagination.offset The starting position to start returning results from
* @param args.options.pagination.limit The number of results to return
* @param args.options.offset The starting position to start returning results from
* @param args.options.limit The number of results to return
* @param args.options.orderBy The order to sort the objects by
* @returns Objects array with the object data
*/
async getAccountOwnedObjects(args: {
accountAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetAccountOwnedObjectsResponse[0]>;
};
options?: PaginationArgs & OrderByArg<GetAccountOwnedObjectsResponse[0]>;
}): Promise<GetAccountOwnedObjectsResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down
18 changes: 9 additions & 9 deletions src/api/ans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class ANS {
*/
async setPrimaryName(args: {
sender: Account;
name: string | null;
name?: string;
options?: InputGenerateTransactionOptions;
}): Promise<SingleSignerTransaction> {
return setPrimaryName({ aptosConfig: this.config, ...args });
Expand Down Expand Up @@ -233,8 +233,8 @@ export class ANS {
*
* @param args
* @param args.accountAddress - A AccountAddressInput of the address to retrieve names for.
* @param args.options.pagination.offset - Optional, the offset to start from when fetching names
* @param args.options.pagination.limit - Optional, A number of the names to fetch per request
* @param args.options.offset - Optional, the offset to start from when fetching names
* @param args.options.limit - Optional, A number of the names to fetch per request
* @param args.options.orderBy - The order to sort the names by
* @param args.options.where - Additional filters to apply to the query
*
Expand All @@ -249,8 +249,8 @@ export class ANS {
*
* @param args
* @param args.accountAddress - A AccountAddressInput of the address to retrieve domain names for.
* @param args.options.pagination.offset - Optional, the offset to start from when fetching names
* @param args.options.pagination.limit - Optional, A number of the names to fetch per request
* @param args.options.offset - Optional, the offset to start from when fetching names
* @param args.options.limit - Optional, A number of the names to fetch per request
* @param args.options.orderBy - The order to sort the names by
* @param args.options.where - Additional filters to apply to the query
*
Expand All @@ -265,8 +265,8 @@ export class ANS {
*
* @param args
* @param args.accountAddress - A AccountAddressInput of the address to retrieve subdomains names for.
* @param args.options.pagination.offset - Optional, the offset to start from when fetching names
* @param args.options.pagination.limit - Optional, A number of the names to fetch per request
* @param args.options.offset - Optional, the offset to start from when fetching names
* @param args.options.limit - Optional, A number of the names to fetch per request
* @param args.options.orderBy - The order to sort the names by
* @param args.options.where - Additional filters to apply to the query
*
Expand All @@ -281,8 +281,8 @@ export class ANS {
*
* @param args
* @param args.domain - A string of the domain name: eg. "test.apt" or "test" (without the suffix of .apt)
* @param args.options.pagination.offset - Optional, the offset to start from when fetching names
* @param args.options.pagination.limit - Optional, A number of the names to fetch per request
* @param args.options.offset - Optional, the offset to start from when fetching names
* @param args.options.limit - Optional, A number of the names to fetch per request
* @param args.options.orderBy - The order to sort the names by
* @param args.options.where - Additional filters to apply to the query
*
Expand Down
21 changes: 6 additions & 15 deletions src/api/digitalAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import {
GetOwnedTokensResponse,
GetTokenActivityResponse,
GetTokenDataResponse,
OrderBy,
OrderByArg,
PaginationArgs,
TokenStandard,
TokenStandardArg,
} from "../types";
import { Account, AccountAddressInput } from "../core";
import { InputGenerateTransactionOptions, SingleSignerTransaction } from "../transactions/types";
Expand Down Expand Up @@ -88,9 +89,7 @@ export class DigitalAsset {
creatorAddress: AccountAddressInput;
collectionName: string;
minimumLedgerVersion?: AnyNumber;
options?: {
tokenStandard?: TokenStandard;
};
options?: TokenStandardArg;
}): Promise<GetCollectionDataResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -116,9 +115,7 @@ export class DigitalAsset {
creatorAddress: AccountAddressInput;
collectionName: string;
minimumLedgerVersion?: AnyNumber;
options?: {
tokenStandard?: TokenStandard;
};
options?: TokenStandardArg;
}): Promise<string> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down Expand Up @@ -200,10 +197,7 @@ export class DigitalAsset {
async getOwnedTokens(args: {
ownerAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetOwnedTokensResponse[0]>;
};
options?: PaginationArgs & OrderByArg<GetOwnedTokensResponse[0]>;
}): Promise<GetOwnedTokensResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -224,10 +218,7 @@ export class DigitalAsset {
async getTokenActivity(args: {
tokenAddress: AccountAddressInput;
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetTokenActivityResponse[0]>;
};
options?: PaginationArgs & OrderByArg<GetTokenActivityResponse[0]>;
}): Promise<GetTokenActivityResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down
13 changes: 3 additions & 10 deletions src/api/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { getAccountEventsByCreationNumber, getAccountEventsByEventType, getEvents } from "../internal/event";
import { AnyNumber, GetEventsResponse, MoveStructId, OrderBy, PaginationArgs } from "../types";
import { AnyNumber, GetEventsResponse, MoveStructId, OrderByArg, PaginationArgs, WhereArg } from "../types";
import { EventsBoolExp } from "../types/generated/types";
import { AccountAddressInput } from "../core";
import { ProcessorType } from "../utils/const";
Expand Down Expand Up @@ -50,10 +50,7 @@ export class Event {
accountAddress: AccountAddressInput;
eventType: MoveStructId;
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
orderBy?: OrderBy<GetEventsResponse[0]>;
};
options?: PaginationArgs & OrderByArg<GetEventsResponse[0]>;
}): Promise<GetEventsResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down Expand Up @@ -81,11 +78,7 @@ export class Event {
*/
async getEvents(args?: {
minimumLedgerVersion?: AnyNumber;
options?: {
where?: EventsBoolExp;
pagination?: PaginationArgs;
orderBy?: OrderBy<GetEventsResponse[0]>;
};
options?: PaginationArgs & OrderByArg<GetEventsResponse[0]> & WhereArg<EventsBoolExp>;
}): Promise<GetEventsResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down
18 changes: 5 additions & 13 deletions src/api/fungibleAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GetFungibleAssetActivitiesResponse,
GetFungibleAssetMetadataResponse,
PaginationArgs,
WhereArg,
} from "../types";
import {
getCurrentFungibleAssetBalances,
Expand Down Expand Up @@ -39,10 +40,7 @@ export class FungibleAsset {
*/
async getFungibleAssetMetadata(args?: {
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
where?: FungibleAssetMetadataBoolExp;
};
options?: PaginationArgs & WhereArg<FungibleAssetMetadataBoolExp>;
}): Promise<GetFungibleAssetMetadataResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -58,7 +56,7 @@ export class FungibleAsset {
* This query returns the fungible asset metadata for a specific fungible asset.
*
* @param args.minimumLedgerVersion Optional ledger version to sync up to, before querying
* @param assetType The asset type of the fungible asset.
* @param args.assetType The asset type of the fungible asset.
* e.g
* "0x1::aptos_coin::AptosCoin" for Aptos Coin
* "0xc2948283c2ce03aafbb294821de7ee684b06116bb378ab614fa2de07a99355a8" - address format if this is fungible asset
Expand Down Expand Up @@ -97,10 +95,7 @@ export class FungibleAsset {
*/
async getFungibleAssetActivities(args?: {
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
where?: FungibleAssetActivitiesBoolExp;
};
options?: PaginationArgs & WhereArg<FungibleAssetActivitiesBoolExp>;
}): Promise<GetFungibleAssetActivitiesResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand All @@ -121,10 +116,7 @@ export class FungibleAsset {
*/
async getCurrentFungibleAssetBalances(args?: {
minimumLedgerVersion?: AnyNumber;
options?: {
pagination?: PaginationArgs;
where?: CurrentFungibleAssetBalancesBoolExp;
};
options?: PaginationArgs & WhereArg<CurrentFungibleAssetBalancesBoolExp>;
}): Promise<GetCurrentFungibleAssetBalancesResponse> {
await waitForIndexerOnVersion({
config: this.config,
Expand Down
Loading

0 comments on commit fbb32c3

Please sign in to comment.