Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Remote

Hierarchy

  • Remote

Index

Constructors

constructor

  • Create a new Remote instance.

    Parameters

    • storage: Dexie

      The (private) storage provider. This is a pretty generic interface that can be satisfied by a basic object for tests, or a full- blown Dexie db for real usage.

    • Default value config: Partial<RemoteConfig> = defaults

      A set of configuration options for remote sync.

    Returns Remote

Properties

config

config: Partial<GrpcConfig>

Set of configuration options for remote sync.

Optional id

id: undefined | string

Database identity on remote peer. String encoding of a thread id.

Methods

applyStash

  • applyStash(...collections: string[]): Promise<void>
  • Apply the local stash back on top of the local changes.

    see

    Remote.createStash.

    Parameters

    • Rest ...collections: string[]

      The set of collections to filter on. This means you can fine-tune which changes are apoplied.

    Returns Promise<void>

authorize

  • authorize(identity: Identity): Promise<string>
  • authorize(identity: string, callback: (challenge: Uint8Array) => Uint8Array | Promise<Uint8Array>): Promise<string>
  • Authorize with a remote.

    see

    {@link getToken} or {@link getTokenChallenge} for lower-level access.

    note

    This is an online-only operation (i.e., can only be done when the peer is able to connect with the remote).

    example
    import type { PrivateKey } from "@textile/crypto";
    import type { Remote } from '@textile/threads'
    
    async function example (remote: Remote, identity: PrivateKey) {
      const token = await remote.authorize(identity)
      // The token is also automatically added to remote's `config.metadata`
      const { metadata } = remote.config
      console.log(metadata?.get("authorization"))
      // ...
      return token
    }

    Parameters

    • identity: Identity

      The identity to use for authorization, or the public key of an identity.

    Returns Promise<string>

  • Parameters

    • identity: string
    • callback: (challenge: Uint8Array) => Uint8Array | Promise<Uint8Array>
        • (challenge: Uint8Array): Uint8Array | Promise<Uint8Array>
        • Parameters

          • challenge: Uint8Array

          Returns Uint8Array | Promise<Uint8Array>

    Returns Promise<string>

clearStash

  • clearStash(): Promise<void>

createStash

  • createStash(): Promise<void>
  • Stash local changes. This moves local changes out of the local staging table into a stashed table. Making it possible to pull remote changes and re-apply local changes on top (like a git rebase).

    see

    Remote.applyStash.

    Returns Promise<void>

get

  • Get the remote configuration options.

    example
    import type { Remote } from '@textile/threads'
    
    function example (remote: Remote) {
      remote.set({ serviceHost: "http://example.com:6007" })
      console.log(remote.get())
      // { serviceHost: "http://example.com:6007", ... }
    }

    Returns Partial<RemoteConfig>

info

  • info(): Promise<DBInfo>

initialize

  • initialize(id?: ThreadID | string | undefined): Promise<string>
  • Initialize a new remote db/thread. Should only be done once, but only after opening the db.

    note

    This is an online-only operation (i.e., can only be done when the peer is able to connect with the remote).

    Parameters

    • Default value id: ThreadID | string | undefined = this.id

      The thread id for the new db. Will default to random thread id. Can be a thread id object or base32-encode string (the default).

    Returns Promise<string>

pull

  • pull(...collections: string[]): Promise<string[]>
  • Pull remote changes into local db. Attempts to force pull remote updates. This will automatically request updates from the remote.

    note

    This is an online-only operation (i.e., can only be done when the peer is able to connect with the remote).

    Parameters

    • Rest ...collections: string[]

      A (possibly empty) variadic set of collections to pull.

    Returns Promise<string[]>

    A promise that resolves to the set of modified keys.

push

  • push(...collections: string[]): Promise<void>
  • Parameters

    • Rest ...collections: string[]

    Returns Promise<void>

set

  • Set the remote configuration options.

    example
    import type { Remote } from '@textile/threads'
    
    function example (remote: Remote) {
      remote.set({ serviceHost: "http://example.com:6007" })
      console.log(remote.get())
      // { serviceHost: "http://example.com:6007", ... }
    }

    Parameters

    • config: Partial<RemoteConfig>

      The configuration options to use. All are optional.

    Returns this

setKeyInfo

  • setKeyInfo(key: KeyInfo): Promise<Remote>
  • Create a new gRPC client instance from a supplied key and secret

    example
    import {KeyInfo, Client} from '@textile/threads'
    
    async function create (keyInfo: KeyInfo) {
      return await Client.withKeyInfo(keyInfo)
    }

    Parameters

    • key: KeyInfo

      The KeyInfo object containing {key: string, secret: string, type: 0}. 0 === User Group Key, 1 === Account Key

    Returns Promise<Remote>

setUserAuth

  • setUserAuth(auth: UserAuth | (() => Promise<UserAuth>)): Promise<Remote>
  • Create 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.

    example
    import {UserAuth, Client} from '@textile/threads'
    
    function create (auth: UserAuth) {
      return Client.withUserAuth(auth)
    }
    example
    import {UserAuth, Client} from '@textile/threads'
    
    function setCallback (callback: () => Promise<UserAuth>) {
      return Client.withUserAuth(callback)
    }

    Parameters

    • auth: UserAuth | (() => Promise<UserAuth>)

      The user auth object or an async callback that returns a user auth object.

    Returns Promise<Remote>