@oap75/types
Version:
JavaScript type definitions for Subsocial blockchain.
154 lines (153 loc) • 5.51 kB
TypeScript
import BN from 'bn.js';
import { FlatSpacePermissions } from '../substrate';
import { Content, SocialAccount, WhoAndWhen } from '../substrate/interfaces';
import { Option } from '@polkadot/types/codec';
import { GenericAccountId } from '@polkadot/types/generic';
import { bool } from '@polkadot/types/primitive';
import * as content from '../offchain';
declare type Id = string;
export declare type Cid = string;
export declare type RoleId = string;
export declare type HasId = {
id: Id;
};
export declare type CanHaveParentId = {
parentId?: Id;
};
export declare type CanHaveSpaceId = {
spaceId?: Id;
};
export declare type CanHaveContent = {
contentId?: Cid;
};
export declare type HasOwner = {
ownerId: string;
};
export declare type HasHandle = {
handle: string;
};
export declare type CanHaveHandle = Partial<HasHandle>;
export declare type HasCreated = {
createdByAccount: string;
createdAtBlock: number;
createdAtTime: number;
};
export declare type CanBeUpdated = {
isUpdated?: boolean;
updatedByAccount?: string;
updatedAtBlock?: number;
updatedAtTime?: number;
};
export declare type CanBeHidden = {
hidden: boolean;
};
export declare type FlatSuperCommon = HasCreated & CanBeUpdated & CanHaveContent;
export declare type FlatSpaceOrPost = FlatSuperCommon & HasId & HasOwner & CanBeHidden;
/** Flat space struct. */
export declare type SpaceStruct = FlatSpaceOrPost & CanHaveParentId & CanHaveHandle & FlatSpacePermissions & {
postsCount: number;
hiddenPostsCount: number;
visiblePostsCount: number;
canFollowerCreatePosts: boolean;
canEveryoneCreatePosts: boolean;
followersCount: number;
score: number;
};
/** Flat post struct. */
export declare type PostStruct = FlatSpaceOrPost & CanHaveSpaceId & {
repliesCount: number;
hiddenRepliesCount: number;
visibleRepliesCount: number;
sharesCount: number;
upvotesCount: number;
downvotesCount: number;
score: number;
isRegularPost: boolean;
isSharedPost: boolean;
isComment: boolean;
};
export declare type CommentExtension = {
parentId?: Id;
rootPostId: Id;
};
export declare type SharedPostExtension = {
sharedPostId: Id;
};
export declare type FlatPostExtension = {} | CommentExtension | SharedPostExtension;
export declare type SharedPostStruct = PostStruct & SharedPostExtension;
export declare type CommentStruct = PostStruct & CommentExtension;
declare type SocialAccountStruct = HasId & {
followersCount: number;
followingAccountsCount: number;
followingSpacesCount: number;
reputation: number;
hasProfile: boolean;
};
/** Flat representation of a social account that does not have a profile content. */
export declare type ProfileStruct = SocialAccountStruct & Partial<FlatSuperCommon>;
/** Flat representation of a social account that created a profile content. */
export declare type PublicProfileStruct = SocialAccountStruct & FlatSuperCommon;
export declare type SuperCommonStruct = {
created: WhoAndWhen;
updated: Option<WhoAndWhen>;
content: Content;
};
export declare type SpaceOrPostStruct = SuperCommonStruct & {
id: BN;
owner: GenericAccountId;
hidden: bool;
};
export declare type AnyId = EntityId | BN;
export declare type EntityId = string;
export declare type AccountId = EntityId;
export declare type SpaceId = EntityId;
export declare type PostId = EntityId;
export declare type ReactionId = EntityId;
/** `ProfileId` is the alias for `AccountId`. */
export declare type ProfileId = EntityId;
export declare type SummarizedContent = {
summary: string;
isShowMore: boolean;
};
export declare type DerivedContent<C extends content.CommonContent> = C & SummarizedContent;
export declare type CommonContent = content.CommonContent & SummarizedContent;
export declare type ProfileContent = DerivedContent<content.ProfileContent>;
export declare type SpaceContent = DerivedContent<content.SpaceContent>;
export declare type PostContent = DerivedContent<content.PostContent>;
export declare type CommentContent = DerivedContent<content.CommentContent>;
export declare type SharedPostContent = DerivedContent<content.SharedPostContent>;
export declare type EntityData<S extends HasId, C extends CommonContent> = {
id: EntityId;
struct: S;
content?: C;
};
export declare type ProfileData = EntityData<ProfileStruct, ProfileContent>;
export declare type SpaceData = EntityData<SpaceStruct, SpaceContent>;
export declare type PostData = EntityData<PostStruct, PostContent>;
export declare type CommentData = EntityData<CommentStruct, CommentContent>;
export declare type SharedPostData = EntityData<SharedPostStruct, SharedPostContent>;
export declare type AnySubsocialData = ProfileData | SpaceData | PostData | CommentData | SharedPostData;
declare type PostExtensionData = Exclude<PostWithSomeDetails, 'ext'>;
export declare type SpaceWithSomeDetails = SpaceData & {
owner?: ProfileData;
};
export declare type PostWithSomeDetails = {
id: EntityId;
post: PostData;
ext?: PostExtensionData;
owner?: ProfileData;
space?: SpaceData;
};
export declare type PostWithAllDetails = Omit<PostWithSomeDetails, 'owner' | 'space'> & {
owner: ProfileData;
space: SpaceData;
};
export declare type ReactionType = 'Upvote' | 'Downvote';
export declare enum ReactionEnum {
Upvote = "Upvote",
Downvote = "Downvote"
}
export declare type SocialAccountWithId = SocialAccount & {
id: AccountId;
};
export {};