textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
112 lines (111 loc) • 3.77 kB
TypeScript
import { API } from '../core/api';
import { ApiOptions, Thread, ThreadList, ContactList } from '../models/index';
import Snapshots from './snapshots';
import Schemas from './schemas';
export declare type ThreadType = 'private' | 'read_only' | 'public' | 'open';
export declare type ThreadSharing = 'not_shared' | 'invite_only' | 'shared';
/**
* Threads is an API module for managing Textile threads
*
* Threads are distributed sets of encrypted files between peers governed by build-in or
* custom Schemas.
*
* Thread type controls read (R), annotate (A), and write (W) access:
*
* private --> initiator: RAW, whitelist:
* readonly --> initiator: RAW, whitelist: R
* public --> initiator: RAW, whitelist: RA
* open --> initiator: RAW, whitelist: RAW
*
* Thread sharing style controls if (Y/N) a thread can be shared:
*
* notshared --> initiator: N, whitelist: N
* inviteonly --> initiator: Y, whitelist: N
* shared --> initiator: Y, whitelist: Y
*
* @extends API
*/
export default class Threads extends API {
snapshots: Snapshots;
schemas: Schemas;
constructor(opts?: ApiOptions);
/**
* Adds and joins a new thread
*
* @param name The name of the new thread
* @param key A locally unique key used by an app to identify this thread on recovery
* @param type The type of thread, must be one of 'private' (default), 'read_only', 'public',
* or 'open'
* @param sharing The sharing style of thread, must be one of 'notshared'
* (default), 'invite_only', or 'shared'
* @param whitelist An array of contact addresses. When supplied, the thread will not allow
* additional peers, useful for 1-1 chat/file sharing or private threads.
* @param schema Schema ID for the new thread
* @returns The newly generated thread info
*/
add(name: string, schema?: string | object, key?: string, type?: ThreadType, sharing?: ThreadSharing, whitelist?: string[]): Promise<Thread>;
/**
* Adds or updates a thread directly, usually from a backup
*
* @param thread ID of the thread
* @param info Thread object
*/
addOrUpdate(thread: string, info: Thread): Promise<void>;
/**
* Retrieve a thread by ID
*
* @param thread ID of the thread
* @returns A thread object
*/
get(thread: string): Promise<Thread>;
/**
* Retrieve a thread by Key
*
* @param key Key of the thread
* @returns A thread object
*/
getByKey(key: string): Promise<Thread | undefined>;
/**
* Retrieve threads by Name
*
* @param name Name of the thread
* @returns An array thread objects
*/
getByName(name: string): Promise<Thread[]>;
/**
* Lists all local threads
*
* @returns An array of threads
*/
list(): Promise<ThreadList>;
/**
* Leave and remove a thread by ID
*
* @param thread ID of the thread
* @returns Whether the thread removal was successfull
*/
remove(thread: string): Promise<boolean>;
/**
* Leave and remove a thread by Key
*
* @param key thread.key of the thread
* @returns Whether the thread removal was successfull
*/
removeByKey(key: string): Promise<boolean>;
/**
* Renames a thread
*
* Note: Only initiators can rename a thread.
* @param thread ID of the thread
* @param name New name for the thread
* @returns Whether the rename was successfully
*/
rename(thread: string, name: string): Promise<boolean>;
/**
* List all peers in a thread
*
* @param thread ID of the thread (default is 'default').
* @returns An array of thread contacts
*/
peers(thread: string): Promise<ContactList>;
}