Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@textile/threads-client

Package Overview
Dependencies
Maintainers
5
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@textile/threads-client

Server-side (remote) event sourced storage layer for Textile's Threads protocol & database

  • 1.0.0-alpha.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

Threads Client (threads-client)

Server-side (remote) event sourced storage layer for Textile's Threads protocol & database

Textile License npm (scoped)

This sub-package is part of js-threads. See the top-level documentation for details.

Install

npm install @textile/threads-client

Usage

create a threads client

import {Client} from '@textile/threads'

const client = new Client()

create a threads client using Textile Hub APIs

Read the full Hub API documentation.

create a store

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

async function newToken (client: Client, user: Identity) {
  const token = await client.getToken(user)
  return token
}

async function createDB (client: Client) {
  const thread: ThreadID = await client.newDB()
  return thread
}

async function collectionFromObject (client: Client, thread: ThreadID, name: string, obj: any) {
  await client.newCollectionFromObject(thread, name, obj)
  return
}

async function setup (auth: UserAuth) {
  const user = await Client.randomIdentity()

  const client = await Client.withUserAuth(auth)

  const token = await newToken(client, user)
  
  const thread = await createDB(client)

  const astronaut = {name: 'Buzz', missions: 3}
  await collectionFromObject(client, thread, 'astronauts', astronaut)
}

get all instances

import {Client, ThreadID} from '@textile/threads'
async function findEntity (client: Client, threadId: ThreadID, collection: string) {
  const found = await client.find(threadId, collection, {})
  console.debug('found:', found.instancesList.length)
}

add an instance

import {Client, ThreadID} from '@textile/threads'
// matches YourModel and schema
async function create (client: Client, threadId: ThreadID, collection: string) {
  const created = await client.create(threadId, collection, [{
    some: 'data',
    numbers: [1, 2, 3]
  }])
}

React Native

The following has been tested on Android Only.

js-thread-client should be compatible with React Native. Here are some helpful pointers if you find issues testing it out.

Connecting to the threads daemon

You can run the daemon released as part of the early preview. To do so,

git clone git@github.com:textileio/go-threads.git
cd go-threads
go run threadsd/main.go

Make daemon available to RN

You can make the daemon API port available to your app with,

adb reverse tcp:6007 tcp:6007

Altenatively, you can ensure this is run whenever you run your app by modifying your package.json as follows.

{
  ...
  "scripts": {
    ...
    "bind": "adb reverse tcp:6007 tcp:6007",
    "android": "npm run bind && npx react-native run-android",
    ...
  },
  ...
}

Then, run your app with,

npm run android

Buffer not found

js-threads-client relies on Buffer being available. To make Buffer available in your project, you may need to introduce a shim. Here are the steps.

install rn-nodeify

read more about rn-nodeify.

npm install -G rn-nodeify

run nodeify in the root of your project

rn-nodeify --install buffer --hack

This will create a shim.js in the root of your project. You need to import this at the top of your apps entry file (e.g. indes.js).

The top of index.js would look like,

require('./shim')
...

add nodeify to your postinstall

Ensure that the shim is still configured after any module updates. Inside package.json add the following line to your scripts tag,

{
  ...
  "scripts": {
    ...
    "postinstall": "rn-nodeify --install buffer --hack"
  }
}

FAQs

Package last updated on 17 Sep 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc