Options
All
  • Public
  • Public/Protected
  • All
Menu

Threads Client

[DEPRECATED]: This project/library has been moved to https://github.com/textileio/js-threads

js-threads-client

Made by Textile Chat on Slack Threads version GitHub license Build status

Textile's JS client for interacting with remote Threads

Go to the docs for more about Textile.

Join us on our public Slack channel for news, discussions, and status updates. Check out our blog for the latest posts and announcements.

Table of Contents

Install

npm install @textile/threads-client

Docs

Read the docs.

Usage in Typescript

create a threads client

import {Client} from '@textile/threads-client'

client = new Client()

create a threads client using Textile APIs

import {API} from '@textile/textile'
import {Client} from '@textile/threads-client'

const api = new API({
    token: '<project token>',
    deviceId: '<user id>'
})
await api.start()

const client = new Client(api.threadsConfig)

create a store

const store = await client.newDB()
await client.newCollection(store.id, 'Folder2P', schema)

get all instances

const found = await client.find(this.finderID, 'Folder2P', {})
console.debug('found:', found.instancesList.length)
this.folders = found.instancesList.map((instance) => instance).map((obj) => {
  return new YourModel(obj)
})

add an instance

// matches YourModel and schema
const created = await client.instanceCreate(this.finderID, 'Folder2', [{
  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"
  }
}

Contributing

This project is a work in progress. As such, there's a few things you can do right now to help out:

  • Ask questions! We'll try to help. Be sure to drop a note (on the above issue) if there is anything you'd like to work on and we'll update the issue to let others know. Also get in touch on Slack.
  • Open issues, file issues, submit pull requests!
  • Perform code reviews. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
  • Take a look at the code. Contributions here that would be most helpful are top-level comments about how it should look based on your understanding. Again, the more eyes the better.
  • Add tests. There can never be enough tests.

Before you get started, be sure to read our contributors guide and our contributor covenant code of conduct.

Changelog

Changelog is published to Releases.

License

MIT