/**
 * @packageDocumentation
 * @module @textile/threads-client
 */
import { grpc } from '@improbable-eng/grpc-web';
import * as pb from '@textile/threads-client-grpc/threads_pb';
import { Identity, Libp2pCryptoIdentity } from '@textile/threads-core';
import { ThreadID } from '@textile/threads-id';
import { ContextInterface } from '@textile/context';
import { UserAuth, KeyInfo } from '@textile/security';
import { QueryJSON, Instance, InstanceList, Filter, Query, Where, WriteTransaction, ReadTransaction } from './models';
export { Query, Where, WriteTransaction, ReadTransaction, Instance, QueryJSON };
export interface CollectionConfig {
    name: string;
    schema: any;
    indexes: pb.Index.AsObject;
}
/**
 * Client is a web-gRPC wrapper client for communicating with a webgRPC-enabled Textile server.
 * This client library can be used to interact with a local or remote Textile gRPC-service
 * It is a wrapper around Textile's 'DB' API, which is defined here:
 * https://github.com/textileio/go-threads/blob/master/api/pb/api.proto.
 */
export declare class Client {
    context: ContextInterface;
    serviceHost: string;
    rpcOptions: grpc.RpcOptions;
    /**
     * Creates a new gRPC client instance for accessing the Textile Threads API.
     * @param context The context to use for interacting with the APIs. Can be modified later.
     */
    constructor(context?: ContextInterface);
    /**
     * Create a new gRPC client instance from a supplied user auth object.
     * Assumes all default gRPC setttings. For custimization options, use a context object directly.
     * @param auth The user auth object.
     * @example
     * ```typescript
     * import {UserAuth, Client} from '@textile/threads'
     *
     * async function create (auth: UserAuth) {
     *   return await Client.withUserAuth(auth)
     * }
     * ```
     */
    static withUserAuth(auth: UserAuth, host?: string, debug?: boolean): Client;
    /**
     * Create a new gRPC client instance from a supplied key and secret
     * @param key The KeyInfo object containing {key: string, secret: string, type: 0}. 0 === User Group Key, 1 === Account Key
     * @example
     * ```typescript
     * import {KeyInfo, Client} from '@textile/threads'
     *
     * async function create (keyInfo: KeyInfo) {
     *   return await Client.withKeyInfo(keyInfo)
     * }
     * ```
     */
    static withKeyInfo(key: KeyInfo, host?: string, debug?: boolean): Promise<Client>;
    /**
     * Create a random user identity.
     * @example
     * ```typescript
     * import {Client} from '@textile/threads'
     *
     * async function newIdentity () {
     *   const user = await Client.randomIdentity()
     *   return user
     * }
     * ```
     */
    static randomIdentity(): Promise<Libp2pCryptoIdentity>;
    /**
     * Obtain a token for interacting with the remote API.
     * @param identity A user identity to use for creating records in the database. A random identity
     * can be created with `Client.randomIdentity(), however, it is not easy/possible to migrate
     * identities after the fact. Please store or otherwise persist any identity information if
     * you wish to retrieve user data later, or use an external identity provider.
     * @param ctx Context object containing web-gRPC headers and settings.
     * @example
     * ```typescript
     * import {Client, Identity} from '@textile/threads'
     *
     * async function newToken (client: Client, user: Identity) {
     *   // Token is added to the client connection at the same time
     *   const token = await client.getToken(user)
     *   return token
     * }
     * ```
     */
    getToken(identity: Identity, ctx?: ContextInterface): Promise<string>;
    /**
     * Obtain a token for interacting with the remote API.
     * @param publicKey The public key of a user identity to use for creating records in the database.
     * A random identity can be created with `Client.randomIdentity(), however, it is not
     * easy/possible to migrate identities after the fact. Please store or otherwise persist any
     * identity information if you wish to retrieve user data later, or use an external identity
     * provider.
     * @param callback A callback function that takes a `challenge` argument and returns a signed
     * message using the input challenge and the private key associated with `publicKey`.
     * @param ctx Context object containing web-gRPC headers and settings.
     * @note `publicKey` must be the corresponding public key of the private key used in `callback`.
     */
    getTokenChallenge(publicKey: string, callback: (challenge: Uint8Array) => Uint8Array | Promise<Uint8Array>, ctx?: ContextInterface): Promise<string>;
    /**
     * newDB creates a new store on the remote node.
     * @param threadID the ID of the database
     * @param name The human-readable name for the database
     * @example
     * ```typescript
     * import {Client, ThreadID} from '@textile/threads'
     *
     * async function createDB (client: Client) {
     *   const thread: ThreadID = await client.newDB()
     *   return thread
     * }
     * ```
     */
    newDB(threadID?: ThreadID, name?: string): Promise<ThreadID>;
    /**
     * Deletes an entire DB.
     * @param threadID the ID of the database.
     * @example
     * ```typescript
     * import {Client, ThreadID} from '@textile/threads'
     *
     * async function deleteDB (client: Client, thread: ThreadID) {
     *   await client.deleteDB(thread)
     *   return
     * }
     * ```
     */
    deleteDB(threadID: ThreadID): Promise<void>;
    /**
     * Lists all known DBs.
     */
    listDBs(): Promise<Record<string, pb.GetDBInfoReply.AsObject | undefined>>;
    /**
     * newCollection registers a new collection schema under the given name.
     * The schema must be a valid json-schema.org schema, and can be a JSON string or object.
     * @param threadID the ID of the database
     * @param name The human-readable name for the collection.
     * @param schema The actual json-schema.org compatible schema object.
     * @param indexes A set of index definitions for indexing instance fields.
     */
    newCollection(threadID: ThreadID, name: string, schema: any, indexes?: pb.Index.AsObject[]): Promise<void>;
    /**
     * newCollectionFromObject creates and registers a new collection under the given name.
     * The input object must be serializable to JSON, and contain only json-schema.org types.
     * @param threadID the ID of the database
     * @param name The human-readable name for the collection.
     * @param obj The actual object to attempt to extract a schema from.
     * @param indexes A set of index definitions for indexing instance fields.
     * @example
     * ```typescript
     * import {Client, ThreadID} from '@textile/threads'
     *
     * async function fromObject (client: Client, thread: ThreadID, name: string, obj: any) {
     *   await client.newCollectionFromObject(thread, name, obj)
     *   return
     * }
     *
     * // Example object
     * // const person = {name: 'Buzz', missions: 3}
     * ```
     */
    newCollectionFromObject(threadID: ThreadID, name: string, obj: any, indexes?: pb.Index.AsObject[]): Promise<void>;
    /**
     * updateCollection updates an existing collection.
     * Currenrly, updates can include name and schema.
     * @todo Allow update of indexing information.
     * @param threadID the ID of the database
     * @param name The human-readable name for the collection.
     * @param config The new collection configuration values to use when updating.
     */
    updateCollection(threadID: ThreadID, name: string, schema: any, indexes?: pb.Index.AsObject[]): Promise<void>;
    /**
     * deleteCollection deletes an existing collection.
     * @param threadID the ID of the database.
     * @param name The human-readable name for the collection.
     * @param schema The actual json-schema.org compatible schema object.
     * @example
     * ```typescript
     * import {Client, ThreadID} from '@textile/threads'
     *
     * async function deleteCollection (client: Client, thread: ThreadID, name: string) {
     *   await client.deleteCollection(thread, name)
     *   return
     * }
     *
     * // Example object
     * // const person = {name: 'Buzz', missions: 3}
     * ```
     */
    deleteCollection(threadID: ThreadID, name: string): Promise<void>;
    /**
     * getCollectionIndexes returns an existing collection's indexes.
     * @param threadID the ID of the database.
     * @param name The human-readable name for the collection.
     */
    getCollectionIndexes(threadID: ThreadID, name: string): Promise<pb.Index.AsObject[]>;
    /**
     * newDBFromAddr initializes the client with the given store, connecting to the given
     * thread address (database). It should be called before any operation on the store, and is an
     * alternative to start, which creates a local store. newDBFromAddr should also include the
     * read and follow keys, which should be Buffer, Uint8Array or base58-encoded strings.
     * See `getDBInfo` for a possible source of the address and keys.
     * @param address The address for the thread with which to connect.
     * Should be of the form /ip4/<url/ip-address>/tcp/<port>/p2p/<peer-id>/thread/<thread-id>
     * @param key The set of keys to use to connect to the database
     * @param collections An array of Name and JSON Schemas for collections in the DB.
     */
    newDBFromAddr(address: string, key: string | Uint8Array, collections: Array<{
        name: string;
        schema: any;
    }>): Promise<unknown>;
    /**
     * getDBInfo returns invite 'links' unseful for inviting other peers to join a given store/thread.
     * @param threadID the ID of the database
     */
    getDBInfo(threadID: ThreadID): Promise<{
        address: string;
        key: string;
    }[]>;
    /**
     * Creates a new model instance in the given store.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param values An array of model instances as JSON/JS objects.
     */
    create(threadID: ThreadID, collectionName: string, values: any[]): Promise<string[]>;
    /**
     * Saves changes to an existing model instance in the given store.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param values An array of model instances as JSON/JS objects. Each model instance must have a valid existing `ID` property.
     */
    save(threadID: ThreadID, collectionName: string, values: any[]): Promise<void>;
    /**
     * Deletes an existing model instance from the given store.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param IDs An array of instance ids to delete.
     */
    delete(threadID: ThreadID, collectionName: string, IDs: string[]): Promise<void>;
    /**
     * has checks whether a given instance exists in the given store.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param IDs An array of instance ids to check for.
     */
    has(threadID: ThreadID, collectionName: string, IDs: string[]): Promise<boolean>;
    /**
     * find queries the store for entities matching the given query parameters.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param query The object that describes the query. User Query class or primitive QueryJSON type.
     */
    find<T = any>(threadID: ThreadID, collectionName: string, query: QueryJSON): Promise<InstanceList<T>>;
    /**
     * findByID queries the store for the id of an instance.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     * @param ID The id of the instance to search for.
     */
    findByID<T = any>(threadID: ThreadID, collectionName: string, ID: string): Promise<Instance<T>>;
    /**
     * readTransaction creates a new read-only transaction object. See ReadTransaction for details.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     */
    readTransaction(threadID: ThreadID, collectionName: string): ReadTransaction;
    /**
     * writeTransaction creates a new writeable transaction object. See WriteTransaction for details.
     * @param threadID the ID of the database
     * @param collectionName The human-readable name of the model to use.
     */
    writeTransaction(threadID: ThreadID, collectionName: string): WriteTransaction;
    /**
     * listen opens a long-lived connection with a remote node, running the given callback on each new update to the given instance.
     * The return value is a `close` function, which cleanly closes the connection with the remote node.
     * @param threadID the ID of the database
     * @param filters contains an array of Filters
     * @param callback The callback to call on each update to the given instance.
     */
    listen<T = any>(threadID: ThreadID, filters: Filter[], callback: (reply?: Instance<T>, err?: Error) => void): () => void;
    private unary;
}
export default Client;
