Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

›Threads

Getting Started

  • Introduction
  • Package Overview

Users API

  • Users class

Buckets

  • Buckets class

Threads

  • Client class

Common Methods & Classes

  • ThreadID class
  • createUserAuth() function
  • createAPISig() function

@textile/hub > Client

Client class

Client is a web-gRPC wrapper client for communicating with a webgRPC-enabled Threads server. This client library can be used to interact with a local or remote Textile gRPC-service It is a wrapper around Textile Thread's 'DB' API, which is defined here: https://github.com/textileio/go-threads/blob/master/api/pb/threads.proto.

Signature:

export declare class Client 

Example

import {Client, Identity, UserAuth} from '@textile/hub'

async function setupDB(auth: UserAuth, identity: Identity) {
  // Initialize the client
  const client = Client.withUserAuth(auth)

  // Connect the user to your API
  const userToken = await client.getToken(identity)

  // Create a new DB
  const threadID = await client.newDB(undefined, 'nasa')

  // Create a new Collection from an Object
  const buzz = {
    name: 'Buzz',
    missions: 2,
    _id: '',
  }
  await client.newCollectionFromObject(threadID, buzz, { name: 'astronauts' })

  // Store the buzz object in the new collection
  await client.create(threadID, 'astronauts', [buzz])

  return threadID
}

Constructors

ConstructorModifiersDescription
(constructor)(context, debug)Creates a new gRPC client instance for accessing the Textile Threads API.

Properties

PropertyModifiersTypeDescription
contextContextInterface
rpcOptionsgrpc.RpcOptions
serviceHoststring

Methods

MethodModifiersDescription
create(threadID, collectionName, values)Creates a new model instance in the given store.
delete(threadID, collectionName, IDs)Deletes an existing model instance from the given store.
deleteCollection(threadID, name)Deletes an existing collection.
deleteDB(threadID)Deletes an entire DB.
find(threadID, collectionName, query)Queries a collection for entities matching the given query parameters.
findByID(threadID, collectionName, ID)Queries the collection by a known instance ID.
getCollectionIndexes(threadID, name)Returns an existing indexes for a collection.
getCollectionInfo(threadID, name)
getDBInfo(threadID)Returns a DBInfo objection containing metadata required to invite other peers to join a given thread.
getToken(identity, ctx)Obtain a token per user (identity) for interacting with the remote API.
getTokenChallenge(publicKey, callback, ctx)Obtain a token per user (identity) for interacting with the remote API.
has(threadID, collectionName, IDs)Check if a given instance exists in the collection.
joinFromInfo(info, includeLocal, collections)Connect client to an existing database using information in the DBInfo object This should be called before any operation on the store, and is an alternative to open, which re-opens a database already opened by the user.
listCollections(thread)Lists the collections in a thread
listDBs()Lists all known DBs.
listen(threadID, filters, callback)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.
newCollection(threadID, config)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.
newCollectionFromObject(threadID, obj, config)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.
newDB(threadID, name)newDB creates a new store on the remote node.
newDBFromAddr(address, key, collections)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/follow key, which should be a Uint8Array or base32-encoded string.
open(threadID, name)open creates and enters a new store on the remote node.
readTransaction(threadID, collectionName)readTransaction creates a new read-only transaction object. See ReadTransaction for details.
save(threadID, collectionName, values)Saves changes to an existing model instance in the given store.
updateCollection(threadID, config)updateCollection updates an existing collection. Currently, updates can include name and schema. Allow update of indexing information.
verify(threadID, collectionName, values)Verify checks existing instance changes. Each model instance must have a valid existing _id property.
withKeyInfo(key, host, debug)staticCreate a new gRPC client instance from a supplied key and secret
withUserAuth(auth, host, debug)staticCreate a new gRPC client instance from a supplied user auth object. Assumes all default gRPC settlings. For customization options, use a context object directly. The callback method will automatically refresh expiring credentials.
writeTransaction(threadID, collectionName)writeTransaction creates a new writeable transaction object. See WriteTransaction for details.
← Buckets classNext →
  • Client class
  • Example
  • Constructors
  • Properties
  • Methods
Hub JS Package
Docs
Getting StartedThreadDBBuckets
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @textileio