UNPKG

@subsocial/api

Version:
352 lines (351 loc) 15.4 kB
import { ApiPromise as SubstrateApi } from '@polkadot/api'; import { Space, Post, Reaction } from '../types/substrate'; import { FindSpaceQuery, FindSpacesQuery, FindPostsQuery, FindPostQuery } from '../filters'; import { SpacePermissionKey, AnyAccountId, AnyPostId, AnySpaceId, AnyReactionId } from '../types'; import BN from 'bn.js'; declare type SubstrateApiProps = { api: SubstrateApi; }; export declare class SubsocialSubstrateApi { private _api; constructor({ api }: SubstrateApiProps); static create(substrateNodeUrl: string): Promise<SubsocialSubstrateApi>; private getPalletQuery; get api(): Promise<SubstrateApi>; private queryPallet; private queryPosts; private querySpaces; private queryProfiles; private queryPalletMulti; private isBooleanByAccount; /** * Find and load data about reaction ids from Subsocial blockchain and IPFS by a given `accountId` and * an array of `structIds`. * * * @param accountId - An account id of desired reaction ids. * * @param postIds - An array of post ids of desired reaction ids. * * @returns An array of reaction ids aggregated from Subsocial blockchain. If no corresponding reaction ids to given * `accountId` and `structIds`, an empty array is returned. * */ private getReactionIdsByAccount; private getStorageLength; /** * Find and load data about the number of posts of a space from Subsocial blockchain and IPFS by a given space id `spaceId`. * * * @param spaceId - A space id. * * * @returns Number of posts of a given space id `spaceId` aggregated from Subsocial blockchain in BN. */ postsCountBySpaceId(spaceId: AnySpaceId): Promise<BN>; /** * Find and load data about the number of shares of a post from Subsocial blockchain and IPFS by a given `postId`. * * * @param postId - A post id. * * * @returns Number of shares of a given `postId` aggregated from Subsocial blockchain in BN. */ sharesCountByPostId(postId: AnyPostId): Promise<BN>; /** * Find and load data about the number of replies of a post from Subsocial blockchain and IPFS by a given `postId`. * * * @param postId - A post id. * * * @returns Number of replies of a given `postId` aggregated from Subsocial blockchain in BN. */ repliesCountByPostId(postId: AnyPostId): Promise<BN>; /** * Find and load data about the number of account followers of an account from Subsocial blockchain and IPFS by a given `accountId`. * * * @param accountId - An account id. * * * @returns Number of account followers of a given `accountId` aggregated from Subsocial blockchain in BN. */ accountFollowersCountByAccountId(accountId: AnyAccountId): Promise<BN>; /** * Find and load data about the number of account followed by an account from Subsocial blockchain and IPFS by a given `accountId`. * * * @param accountId - An account id. * * * @returns Number of account followers of a given `accountId` aggregated from Subsocial blockchain in BN. */ accountsFollowedCountByAccount(accountId: AnyAccountId): Promise<BN>; private findStructs; /** * Find and load an array of information about spaces from Subsocial blockchain and IPFS by a given array of `ids`, * `visibility` filter, and `content` filter. * * @param params - An object containing an array of space `ids`, visibility filter (`hidden` field), and `content` filter. * * @returns An array of data about desired spaces from Subsocial blockchain and IPFS. If no corresponding spaces to given array * of `ids`, `content` and `visibility` filter, an empty array is returned. */ findSpaces(params: FindSpacesQuery): Promise<Space[]>; /** * Find and load an array of information about posts from Subsocial blockchain and IPFS by a given array of `ids`, `content` and * `visibility` filter. * * @param params - An object containing an array of space `ids`, visibility filter (`hidden` field), and `content` filter. * * @returns An array of data about desired posts from Subsocial blockchain and IPFS. If no corresponding posts to given array * of `ids`, `content` and `visibility` filter, an empty array is returned. */ findPosts(params: FindPostsQuery): Promise<Post[]>; /** * Find and load an array of information about reactions from Subsocial blockchain by a given array of reaction `ids`. * * @param ids - An array of ids of desired reactions. * * @returns An array of data about desired reactions from Subsocial blockchain. If no corresponding reactions to given * array of `ids`, an empty array is returned. */ findReactions(ids: AnyReactionId[]): Promise<Reaction[]>; /** * Find and load information about a space from Subsocial blockchain and IPFS by a given `id`, `content` and `visibility` filter. * * @param params - An object containing a space `id`, visibility filter (`hidden` field), and `content` filter. * * @returns Data about desired space from Subsocial blockchain and IPFS. If no corresponding space to given `id`, `content` and * `visibility` filter, `undefined` is returned. */ findSpace(params: FindSpaceQuery): Promise<Space | undefined>; /** * Find and load information about a post from Subsocial blockchain and IPFS by a given `id`, `content` and `visibility` filter. * * @param params - An object containing a post `id`, visibility filter (`hidden` field), and `content` filter. * * @returns Data about desired post from Subsocial blockchain and IPFS. If no corresponding post to given `id`, `content` and * `visibility` filter, `undefined` is returned. */ findPost(params: FindPostQuery): Promise<Post | undefined>; /** * Find and load information about a reaction from Subsocial blockchain by a given reaction `id`. * * @param id - Id of desired reaction. * * @returns Data about desired reaction from Subsocial blockchain. If no corresponding reaction to given reaction `id`, * `undefined` is returned. */ findReaction(id: AnyReactionId): Promise<Reaction | undefined>; /** * Find and load data about a reaction id from Subsocial blockchain and IPFS by a given `accountId` and * and `postId`. * * * @param accountId - Id of desired account. * * @param postId - Id of desired post. * * @returns Data of reaction id aggregated from Subsocial blockchain. If no corresponding reaction id to given * `accountId` and `postId`, undefined is returned. * */ getPostReactionIdByAccount(accountId: AnyAccountId, postId: AnyPostId): Promise<string | undefined>; /** * Find and load an array of information about reaction ids from Subsocial blockchain and IPFS by a given `accountId` and * and an array of `postIds`. * * * @param accountId - Id of desired account. * * @param postIds - An array of ids of desired posts. * * @returns An array of reaction id aggregated from Subsocial blockchain. If no corresponding reaction id to given * `accountId` and and array of `postIds`, an empty array is returned. * */ getPostReactionIdsByAccount(accountId: AnyAccountId, postIds: AnyPostId[]): Promise<string[]>; /** * Find and load next space id from Subsocial blockchain. * * @returns A string of the next space id. * */ nextSpaceId(): Promise<string>; /** * Find and load next post id from Subsocial blockchain. * * @returns A string of the next post id. * */ nextPostId(): Promise<string>; /** * Find and load an array of reply ids from Subsocial blockchain by a given post `id`. * * @param id - Id of desired post. * * @returns An array of reply id aggregated from Subsocial blockchain. If no corresponding reply id to given * post `id`, an empty array is returned. * */ getReplyIdsByPostId(id: AnyPostId): Promise<string[]>; /** * Find and load an array of space ids from Subsocial blockchain of an owner by a given account `id`. * * @param id - Id of desired account as spaces owner. * * @returns An array of space id aggregated from Subsocial blockchain. If no corresponding space id to given * account `id`, an empty array is returned. * */ spaceIdsByOwner(id: AnyAccountId): Promise<string[]>; /** * Find and load an array of space ids from Subsocial blockchain followed by a given account `id`. * * @param id - Id of desired account as spaces follower. * * @returns An array of space id aggregated from Subsocial blockchain. If no corresponding space id followed by a given * account `id`, an empty array is returned. * */ spaceIdsFollowedByAccount(id: AnyAccountId): Promise<string[]>; /** * Find and load an array of post ids from Subsocial blockchain by a given space `id`. * * @param id - Id of desired space. * * @returns An array of post id aggregated from Subsocial blockchain. If no corresponding post id to given * space `id`, an empty array is returned. * */ postIdsBySpaceId(id: AnySpaceId): Promise<string[]>; /** * Find and load profile space id from Subsocial blockchain by a given account `id`. * * @param accountId - Id of desired account. * * @returns Data of profile space id from Subsocial blockchain. * */ profileSpaceIdByAccount(accountId: AnyAccountId): Promise<string>; /** * Find and load an array of profile space ids from Subsocial blockchain by a given array of `accountIds`. * * @param accountIds - An array of desired account ids. * * @returns An array of profile space ids aggregated from Subsocial blockchain. If no corresponding space id to given * array of `accountIds`, an empty array is returned. * */ profileSpaceIdsByAccounts(accountIds: AnyAccountId[]): Promise<string[]>; /** * Find and load boolean value from Subsocial blockchain by a given `myAddress` and `followedAddress`. * * @param myAddress - Id of own account. * * @param followedAddress - Id of followedAccount. * * @returns A boolean value whether `myAddress` is following `followedAddress` or not, retrieved from Subsocial blockchain. * */ isAccountFollower(myAddress: AnyAccountId, followedAddress: AnyAccountId): Promise<boolean>; /** * Find and load boolean value from Subsocial blockchain by a given `myAddress` and `spaceId`. * * @param myAddress - Id of own account. * * @param spaceId - Id of desired space. * * @returns A boolean value whether `myAddress` is following a given `spaceId` or not, retrieved from Subsocial blockchain. * */ isSpaceFollower(myAddress: AnyAccountId, spaceId: AnySpaceId): Promise<boolean>; /** * Find and load an array of account ids with any role from Subsocial blockchain by a given `spaceId`. * * @param spaceId - Id of desired space. * * @returns An array of string representing accounts in any role retrieved from Subsocial blockchain by a given `spaceId`. * If no corresponding account with any role to a given `spaceId`, an empty array is returned. * */ getAccountsWithAnyRoleInSpace(spaceId: AnySpaceId): Promise<string[]>; /** * Find and load an array of role ids owned by a given `accountId` from Subsocial blockchain within a given space. * * @param accountId - Id of desired account. * * @returns An array of role ids retrieved from Subsocial blockchain by a given `accountId` within a space. * If no corresponding role id to a given `accountId`, an empty array is returned. * */ getSpaceIdsWithRolesByAccount(accountId: AnyAccountId): Promise<string[]>; /** * Find and load an array of space permissions owned by a given `accountId` from Subsocial blockchain within a given `spaceId`. * * @param accountId - Id of desired account. * * @param spaceId - Id of desired space. * * @returns An array of space permissions retrieved from Subsocial blockchain by a given `accountId` within a `spaceId`. * If no corresponding space permissions to a given `accountId` within a `spaceId`, an empty array is returned. * */ getSpacePermissionsByAccount(accountId: AnyAccountId, spaceId: AnySpaceId): Promise<SpacePermissionKey[]>; /** * Find and load an array of domain names by key pairs [Owner, SpaceId] from Subsocial blockchain. * * @param keys - An array of keypairs [Owner, SpaceId]. * * @returns An array of domain names retrieved from Subsocial blockchain by a given array of key pairs [Owner, SpaceId]. * If no corresponding domain name to given key pairs, an empty array is returned. * */ getDomainNames(keys: [AnyAccountId, AnySpaceId][]): Promise<string[]>; /** * Find and load domain by a given `accountId` and `spaceId` from Subsocial blockchain. * * @param accountId - Id of a desired account. * * @param spaceId - Id of desired space. * * @returns Data about domain name (in string) retrieved from Subsocial blockchain by a given `accountId` and `spaceId`. * If no corresponding domain name to given `accountId` and `spaceId`, undefined is returned. * */ domainNameBySpaceId(accountId: AnyAccountId, spaceId: AnySpaceId): Promise<string | undefined>; /** * Find and load an array of domain structs of registered domains by a given array of `domainNames` from Subsocial blockchain. * * @param domainNames - An array of desired domain names. * * @returns An array of information about domain structs of registered domains retrieved from Subsocial blockchain * by a given array of `domainNames`. If no corresponding domain structs to given array of `domainNames`, an empty array is returned. * */ registeredDomains(domainNames: string[]): Promise<import("@polkadot/types/lookup").PalletDomainsDomainMeta[]>; /** * Find and load information about domain structs of registered domain by a given `domainName` from Subsocial blockchain. * * @param domainName - A string of desired domain name. * * @returns Data about domain structs of a registered domain retrieved from Subsocial blockchain * by a given `domainName`. * */ registeredDomain(domainName: string): Promise<import("@polkadot/types/lookup").PalletDomainsDomainMeta[]>; /** * Find and load an array of information about domains by a given `accountId` from Subsocial blockchain. * * @param accountId - Id of owner of domains. * * @returns An array of information about domains retrieved from Subsocial blockchain by an owner `accountId`. * If no corresponding domain to given owner `accountId`, an empty array is returned. * */ domainsByOwner(accountId: AnyAccountId): Promise<string[]>; } export {};