Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

Hierarchy

  • Client

Index

Constructors

constructor

  • Client creates a new gRPC client instance.

    Parameters

    • Default value config: Config = defaultConfig

      A set of configuration settings to control the client.

    Returns Client

Properties

config

config: Config

A set of configuration settings to control the client.

Methods

create

  • create(dbID: Buffer, collectionName: string, values: any[]): Promise<string[]>
  • Creates a new model instance in the given store.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • values: any[]

      An array of model instances as JSON/JS objects.

    Returns Promise<string[]>

delete

  • delete(dbID: Buffer, collectionName: string, IDs: string[]): Promise<void>
  • Deletes an existing model instance from the given store.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • IDs: string[]

      An array of instance ids to delete.

    Returns Promise<void>

find

  • find queries the store for entities matching the given query parameters.

    Type parameters

    • T

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • query: QueryJSON

      The object that describes the query. User Query class or primitive QueryJSON type.

    Returns Promise<InstanceList<T>>

findByID

  • findByID<T>(dbID: Buffer, collectionName: string, ID: string): Promise<Instance<T>>
  • findByID queries the store for the id of an instance.

    Type parameters

    • T

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • ID: string

      The id of the instance to search for.

    Returns Promise<Instance<T>>

getDBInfo

  • getDBInfo(dbID: Buffer): Promise<object[]>
  • getDBInfo returns invite 'links' unseful for inviting other peers to join a given store/thread.

    Parameters

    • dbID: Buffer

      the ID of the database

    Returns Promise<object[]>

getToken

  • getToken(identity: Identity): Promise<string>
  • Parameters

    • identity: Identity

    Returns Promise<string>

has

  • has(dbID: Buffer, collectionName: string, IDs: string[]): Promise<boolean>
  • has checks whether a given instance exists in the given store.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • IDs: string[]

      An array of instance ids to check for.

    Returns Promise<boolean>

listen

  • listen<T>(dbID: Buffer, filters: Filter[], callback: function): function
  • 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.

    Type parameters

    • T

    Parameters

    • dbID: Buffer

      the ID of the database

    • filters: Filter[]

      contains an array of Filters

    • callback: function

      The callback to call on each update to the given instance.

        • (reply?: Instance<T>, err?: Error): void
        • Parameters

          • Optional reply: Instance<T>
          • Optional err: Error

          Returns void

    Returns function

      • (): void
      • Returns void

newCollection

  • newCollection(dbID: Buffer, name: string, schema: any): Promise<void>
  • newCollection registers a new model schema under the given name on the remote node. The schema must be a valid json-schema.org schema, and can be a JSON string or Javascript object.

    Parameters

    • dbID: Buffer

      the ID of the database

    • name: string

      The human-readable name for the model.

    • schema: any

      The actual json-schema.org compatible schema object.

    Returns Promise<void>

newDB

  • newDB(dbID: Buffer): Promise<void>
  • newDB creates a new store on the remote node.

    Parameters

    • dbID: Buffer

      the ID of the database

    Returns Promise<void>

newDBFromAddr

  • newDBFromAddr(address: string, key: string | Uint8Array, collections: Array<object>): Promise<unknown>
  • 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.

    Parameters

    • address: string

      The address for the thread with which to connect. Should be of the form /ip4/<url/ip-address>/tcp//p2p//thread/

    • key: string | Uint8Array

      The set of keys to use to connect to the database

    • collections: Array<object>

      An array of Name and JSON Schemas for collections in the DB.

    Returns Promise<unknown>

readTransaction

  • readTransaction creates a new read-only transaction object. See ReadTransaction for details.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    Returns ReadTransaction

save

  • save(dbID: Buffer, collectionName: string, values: any[]): Promise<void>
  • Saves changes to an existing model instance in the given store.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    • values: any[]

      An array of model instances as JSON/JS objects. Each model instance must have a valid existing ID property.

    Returns Promise<void>

writeTransaction

  • writeTransaction creates a new writeable transaction object. See WriteTransaction for details.

    Parameters

    • dbID: Buffer

      the ID of the database

    • collectionName: string

      The human-readable name of the model to use.

    Returns WriteTransaction

Static version

  • version(): string
  • version is the release version.

    Returns string