UNPKG

@subsocial/api

Version:
288 lines (287 loc) 16.5 kB
import { Filters, FindPostQuery, FindPostsQuery, FindPostsWithDetailsQuery, FindSpaceQuery, FindSpacesQuery } from '../filters'; import { BasicSubsocialApi } from './basic'; import { SpaceData, PostData, PostWithSomeDetails, PostWithAllDetails, AnyId, SpaceStruct, PostStruct, AnyAccountId, SubsocialApiProps, CreateSubsocialApiProps, AnyReactionId, ReactionStruct } from '../types'; export interface ISubsocialApi { findSpace: (query: FindSpaceQuery) => Promise<SpaceData | undefined>; findSpaces: (query: FindSpacesQuery) => Promise<SpaceData[]>; findPublicSpaces: (ids: AnyId[]) => Promise<SpaceData[]>; findUnlistedSpaces: (ids: AnyId[]) => Promise<SpaceData[]>; findSpaceStructs: (ids: AnyId[], filters?: Filters) => Promise<SpaceStruct[]>; findPostStructs: (ids: AnyId[], filters?: Filters) => Promise<PostStruct[]>; findSpaceStruct: (id: AnyId, filters?: Filters) => Promise<SpaceStruct | undefined>; findPostStruct: (id: AnyId, filters?: Filters) => Promise<PostStruct | undefined>; findPost: (query: FindPostQuery) => Promise<PostData | undefined>; findPosts: (query: FindPostsQuery) => Promise<PostData[]>; findPublicPosts: (ids: AnyId[]) => Promise<PostData[]>; findPostWithSomeDetails: (query: FindPostQuery) => Promise<PostWithSomeDetails | undefined>; findPostWithAllDetails: (id: AnyId) => Promise<PostWithAllDetails | undefined>; findPostsWithAllDetails: (query: FindPostsQuery) => Promise<PostWithAllDetails[]>; findPublicPostsWithSomeDetails: (query: FindPostsWithDetailsQuery) => Promise<PostWithSomeDetails[]>; findPublicPostsWithAllDetails: (ids: AnyId[]) => Promise<PostWithAllDetails[]>; findUnlistedPostsWithAllDetails: (ids: AnyId[]) => Promise<PostWithAllDetails[]>; findProfileSpace: (accountId: AnyAccountId) => Promise<SpaceData | undefined>; findProfileSpaces: (accountIds: AnyAccountId[]) => Promise<SpaceData[]>; findReaction: (id: AnyReactionId) => Promise<ReactionStruct | undefined>; findReactions: (id: AnyReactionId[]) => Promise<ReactionStruct[] | undefined>; } export declare class SubsocialApi implements ISubsocialApi { private readonly _base; constructor(props: SubsocialApiProps); /** Create an instance of subsocial api with given config and connected substrate node */ static create({ substrateNodeUrl, ...props }: CreateSubsocialApiProps): Promise<SubsocialApi>; /** @deprecated */ get subsocial(): BasicSubsocialApi; /** * @deprecated * Getter for an ApiPromise to connect to Subsocial nodes and query chain states, but in raw format. * The raw formatted data needs to be flattened first in order to be readable by JavaScript. * * Accessors for private field {@link _base}*/ get base(): BasicSubsocialApi; /** * Getter for an ApiPromise to connect to Subsocial nodes and query chain states. * It is useful in the case of querying data about posts, spaces, and profiles. * * Accessors for private field {@link _base.substrate}*/ get blockchain(): import("..").SubsocialSubstrateApi; /** * Getter for an aggregated ApiPromise to work with IPFS. * It is useful for getting the contents of spaces, posts, and profiles. * * Accessors for private field {@link _base.ipfs}*/ get ipfs(): import("..").SubsocialIpfsApi; /** * Getter for a Polkadot ApiPromise without wrappers to call functions from Subsocial Pallets. * It is useful for creating specific txs or queries. * * Accessors for private field {@link _base.substrate.api} **/ get substrateApi(): Promise<import("@polkadot/api").ApiPromise>; /** * Find and load an array of information about space structs (can be Unlisted or Public, depending on `filters`) from the Subsocial blockchain and IPFS * by a given array of space `ids` and `filters` object. * * * @param ids - An array of the space ids of the desired space structs. * * @param filters - (Optional) An object containing a visibility filter (`hidden` field) and content filter (with or without IPFS content). * * @returns An array of information about space structs aggregated from the Subsocial blockchain and IPFS. If there are no * space structs corresponding to the given space `ids` and `filters`, an empty array is returned. */ findSpaceStructs(ids: AnyId[], filters?: Filters): Promise<SpaceStruct[]>; /** * Find and load an array of information about post structs (can be Unlisted or Public, depending on `filters`) from the Subsocial blockchain and IPFS * by a given array of post `ids` and `filters` object. * * * @param ids - An array of the post ids of the desired post structs. * * @param filters - (Optional) An object containing a visibility filter (`hidden` field) and content filter (with or without IPFS content). * * @returns An array of information about post structs aggregated from the Subsocial blockchain and IPFS. If there are no * post structs corresponding to the given post `ids` and `filters` object, an empty array is returned. */ findPostStructs(ids: AnyId[], filters?: Filters): Promise<PostStruct[]>; /** * Find and load information about space structs (can be Unlisted or Public, depending on `filters`) from the Subsocial blockchain and IPFS * by a given space `id` and `filters` object. * * * @param id - The space id of the desired space structs. * * @param filters - (Optional) An object containing a visibility filter (`hidden` field) and content filter (with or without IPFS content). * * @returns Data about space structs aggregated from the Subsocial blockchain and IPFS. If there are no * space structs corresponding to the given space `id` and `filters` object, undefined is returned. */ findSpaceStruct(id: AnyId, filters?: Filters): Promise<SpaceStruct | undefined>; /** * Find and load information about post structs (can be Unlisted or Public, depending on `filters`) from the Subsocial blockchain and IPFS * by a given post `id` and `filters` object. * * * @param id - The post id of the desired post structs. * * @param filters - (Optional) An object containing a visibility filter (`hidden` field) and content filter (with or without IPFS content). * * @returns Data about post structs aggregated from the Subsocial blockchain and IPFS. If there are no * post structs corresponding to the given post `id` and `filters` object, undefined is returned. */ findPostStruct(id: AnyId, filters?: Filters): Promise<PostStruct | undefined>; /** * Find and load data about a space (can be Unlisted or Public, depending on filters set on `query`) from the Subsocial blockchain and IPFS by a given `query` object. * * * @param query - An object containing the desired space `id`, a visibility filter (`hidden` field), and a content filter (with or without IPFS content). * * @returns Data about a space aggregated from the Subsocial blockchain and IPFS. If there is no * space corresponding to the given `query` object, undefined is returned. */ findSpace(query: FindSpaceQuery): Promise<SpaceData | undefined>; /** * Find and load an array of information about spaces (can be Unlisted or Public, depending on `filter` object) from the Subsocial blockchain and IPFS by a given `filter` object. * * * @param filter - An object containing the desired space `ids`, a visibility filter (`hidden` field), and a content filter (with or without IPFS content). * * @returns An array of data about desired spaces aggregated from the Subsocial blockchain and IPFS. If there are no * spaces corresponding to the given `filter` object, undefined is returned. */ findSpaces(filter: FindSpacesQuery): Promise<SpaceData[]>; /** * Find and load an array of information about public spaces from the Subsocial blockchain and IPFS by a given array of * space `ids`. * * A space is considered public if it meets the following conditions: * - The `hidden` field on its blockchain structure is `false`. * - There is a corresponding JSON file that represents the space's content on IPFS. * * @param ids - An array of the ids of the desired spaces. * * @returns An array of data about the desired spaces aggregated from the Subsocial blockchain and IPFS. If there are no * spaces corresponding to the given array of `ids`, an empty array is returned. */ findPublicSpaces(ids: AnyId[]): Promise<SpaceData[]>; /** * Find and load an array of information about unlisted spaces from the Subsocial blockchain and IPFS by a given array of * space `ids`. * * A space is considered unlisted if it meets either of these conditions: * - The `hidden` field on its blockchain structure is `true`. * - There is no corresponding JSON file that represents the space's content on IPFS. * * @param ids - An array of the ids of the desired spaces. * * @returns An array of data about the desired spaces aggregated from the Subsocial blockchain and IPFS. If there are no * spaces corresponding to the given array of `ids`, an empty array is returned. */ findUnlistedSpaces(ids: AnyId[]): Promise<SpaceData[]>; /** * Find and load data about a post from the Subsocial blockchain and IPFS by a given `query` object. * * * @param query - An object containing the desired post `id`, a visibility filter (`hidden` field), and a content filter (with or without IPFS content). * * @returns Data about a post aggregated from the Subsocial blockchain and IPFS. If there is no * post corresponding to the given `query` object, undefined is returned. */ findPost(query: FindPostQuery): Promise<PostData | undefined>; /** * Find and load an array of information about posts (can be Unlisted or Public, depending on `filter` object) from the Subsocial blockchain and IPFS by a given `filter` object. * * * @param filter - An object containing the desired post `ids`, a visibility filter (`hidden` field), and a content filter (with or without IPFS content). * * @returns An array of data about the desired posts aggregated from the Subsocial blockchain and IPFS. If there are no * posts corresponding to the given `filter` object, an empty array is returned. */ findPosts(filter: FindPostsQuery): Promise<PostData[]>; /** * Find and load an array of public posts from the Subsocial blockchain and IPFS by a given array of post `ids`. * * A post is considered public if it meets the following conditions: * - The `hidden` field on its blockchain structure is `false`. * - There is a corresponding JSON file that represents the space's content on IPFS. * * @param ids - An array of the ids of the desired posts. * * @returns An array of data about the desired posts aggregated from the Subsocial blockchain and IPFS. If there are no * posts corresponding to the given array of `ids`, an empty array is returned. */ findPublicPosts(ids: AnyId[]): Promise<PostData[]>; /** * Find and load information about a post with some of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findPostWithSomeDetails(query: FindPostQuery): Promise<PostWithSomeDetails | undefined>; /** * Find and load information about a post with all of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findPostWithAllDetails(id: AnyId): Promise<PostWithAllDetails | undefined>; /** * Find and load an array of information about a post with all of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findPostsWithAllDetails(query: FindPostsQuery): Promise<PostWithAllDetails[]>; /** * Find and load an array of information about a public post with some of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findPublicPostsWithSomeDetails(query: FindPostsWithDetailsQuery): Promise<PostWithSomeDetails[]>; /** * Find and load an array of information about a public post with all of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findPublicPostsWithAllDetails(ids: AnyId[]): Promise<PostWithAllDetails[]>; /** * Find and load an array of information about an unlisted post with all of its details: extension (PostExtensionData), owner (SpaceData), and space (SpaceData). * These methods are **deprecated**, because they are slow (although quite useful for UI). */ findUnlistedPostsWithAllDetails(ids: AnyId[]): Promise<PostWithAllDetails[]>; /** * Find and load an array of information about profile spaces from Subsocial blockchain and IPFS by a given array of * account ids `accounts`. * * A profile space is just a space set to a profile. * * @param accounts - An array of the account ids related to the desired profile spaces * * @returns Find and load an array of information about the profile space of each accountId in the array * from the Subsocial blockchain and IPFS. * */ findProfileSpaces(accounts: AnyAccountId[]): Promise<SpaceData[]>; /** * Find and load information about a profile space from the Subsocial blockchain and IPFS using an account id. * * * A profile space is just a space set to a profile. * * @param account - An account id corresponding to a desired space profile. * * @returns Data about the desired profile space aggregated from the Subsocial blockchain and IPFS. If there is space corresponding to the given account id, * `undefined` is returned. */ findProfileSpace(account: AnyAccountId): Promise<SpaceData | undefined>; /** * Find and load an array of information about some domain structs from the Subsocial blockchain by a given array of `domainNames`. * * * @param domainNames - An array of domain names. * * @returns An array of data about the desired domain structs aggregated from the Subsocial blockchain. If there are no domains corresponding to the given array of `domainNames`, * an empty array is returned. */ findDomains(domainNames: string[]): Promise<import("../types").DomainStruct[]>; /** * Find and load data about a domain from the Subsocial blockchain by a given string of `domainName`. * * * @param domainName - A string that is a domain name. * * @returns Data about a desired domain name from the Subsocial blockchain. If there is no domain name corresponding to the given `domainName`, * `undefined` is returned. */ findDomain(domainName: string): Promise<import("../types").DomainStruct | undefined>; /** * Find and load data about a reaction from the Subsocial blockchain by a given `id`. * * * @param id - The desired reaction id * * @returns Data about the reaction consisting the reaction kind, creation, update metadata if any. If there is no * reaction with given id, undefined is returned. */ findReaction(id: AnyId): Promise<ReactionStruct | undefined>; /** * Find and load an array of information about a reactions from the Subsocial blockchain from all the given id in `ids` array. * * * @param ids - An array containing the desired reaction `ids`. * * @returns An array of data about desired reactions. */ findReactions(id: AnyId[]): Promise<ReactionStruct[]>; }