UNPKG

@aptos-labs/ts-sdk

Version:
162 lines 5.29 kB
// Copyright © Aptos Foundation // SPDX-License-Identifier: Apache-2.0 import { Account } from "./account.js"; import { AptosConfig } from "./aptosConfig.js"; import { Coin } from "./coin.js"; import { DigitalAsset } from "./digitalAsset.js"; import { Faucet } from "./faucet.js"; import { FungibleAsset } from "./fungibleAsset.js"; import { General } from "./general.js"; import { ANS } from "./ans.js"; import { Staking } from "./staking.js"; import { Transaction } from "./transaction.js"; import { Table } from "./table.js"; import { Keyless } from "./keyless.js"; import { AptosObject } from "./object.js"; import { AccountAbstraction } from "./account/abstraction.js"; /** * The main entry point for interacting with the Aptos APIs, * providing access to various functionalities organized into * distinct namespaces. * * Note: Importing `Aptos` pulls in all sub-modules and is not tree-shakeable. * For smaller bundles, import namespace classes from sub-paths instead: * * ```typescript * import { General, AptosConfig } from "@aptos-labs/ts-sdk/general"; * const general = new General(new AptosConfig({ network: Network.TESTNET })); * await general.getLedgerInfo(); * ``` * * Or for maximum tree-shaking, import individual functions: * * ```typescript * import { getLedgerInfo } from "@aptos-labs/ts-sdk/general"; * await getLedgerInfo({ aptosConfig: config }); * ``` * * @example * ```typescript * import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"; * * const config = new AptosConfig({ network: Network.TESTNET }); * const aptos = new Aptos(config); * const ledgerInfo = await aptos.getLedgerInfo(); * ``` * @group Client */ export class Aptos { config; // Lazy-initialized sub-module backing fields #account; #abstraction; #ans; #coin; #digitalAsset; #faucet; #fungibleAsset; #general; #staking; #transaction; #table; #keyless; #object; /** * Initializes a new instance of the Aptos client with the provided configuration settings. * * @param config - Configuration settings for the Aptos client. * @group Client */ constructor(config) { this.config = config ?? new AptosConfig(); } get account() { this.#account ??= new Account(this.config); return this.#account; } get abstraction() { this.#abstraction ??= new AccountAbstraction(this.config); return this.#abstraction; } get ans() { this.#ans ??= new ANS(this.config); return this.#ans; } get coin() { this.#coin ??= new Coin(this.config); return this.#coin; } get digitalAsset() { this.#digitalAsset ??= new DigitalAsset(this.config); return this.#digitalAsset; } get faucet() { this.#faucet ??= new Faucet(this.config); return this.#faucet; } get fungibleAsset() { this.#fungibleAsset ??= new FungibleAsset(this.config); return this.#fungibleAsset; } get general() { this.#general ??= new General(this.config); return this.#general; } get staking() { this.#staking ??= new Staking(this.config); return this.#staking; } get transaction() { this.#transaction ??= new Transaction(this.config); return this.#transaction; } get table() { this.#table ??= new Table(this.config); return this.#table; } get keyless() { this.#keyless ??= new Keyless(this.config); return this.#keyless; } get object() { this.#object ??= new AptosObject(this.config); return this.#object; } setIgnoreTransactionSubmitter(ignore) { this.config.setIgnoreTransactionSubmitter(ignore); } } /** * Mixin helper: copies prototype methods from a sub-module class onto the * Aptos class, delegating calls to the lazily-initialized sub-module instance. * {@link https://www.typescriptlang.org/docs/handbook/mixins.html#alternative-pattern} */ function applyMixin(targetClass, baseClass, baseClassProp) { Object.getOwnPropertyNames(baseClass.prototype).forEach((propertyName) => { const propertyDescriptor = Object.getOwnPropertyDescriptor(baseClass.prototype, propertyName); if (!propertyDescriptor) return; Object.defineProperty(targetClass.prototype, propertyName, { value(...args) { return this[baseClassProp][propertyName](...args); }, writable: propertyDescriptor.writable, configurable: propertyDescriptor.configurable, enumerable: propertyDescriptor.enumerable, }); }); } applyMixin(Aptos, Account, "account"); applyMixin(Aptos, AccountAbstraction, "abstraction"); applyMixin(Aptos, ANS, "ans"); applyMixin(Aptos, Coin, "coin"); applyMixin(Aptos, DigitalAsset, "digitalAsset"); applyMixin(Aptos, Faucet, "faucet"); applyMixin(Aptos, FungibleAsset, "fungibleAsset"); applyMixin(Aptos, General, "general"); applyMixin(Aptos, Staking, "staking"); applyMixin(Aptos, Transaction, "transaction"); applyMixin(Aptos, Table, "table"); applyMixin(Aptos, Keyless, "keyless"); applyMixin(Aptos, AptosObject, "object"); //# sourceMappingURL=aptos.js.map