-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(api): update hub to v0.6.2 #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { EventEmitter } from 'events' | ||
import { Libp2pCryptoIdentity } from '@textile/threads-core' | ||
import { Client, Buckets, ThreadID, KeyInfo } from '@textile/hub' | ||
import { Client, Buckets, ThreadID, KeyInfo, PrivateKey } from '@textile/hub' | ||
import { StorexHubApi_v0, StorexHubCallbacks_v0, HandleRemoteCallResult_v0 } from '@worldbrain/storex-hub/lib/public-api' | ||
import { SettingsStore, Settings } from './types' | ||
import { APP_NAME } from './constants' | ||
|
@@ -90,15 +89,15 @@ export class Application { | |
|
||
async createThreadsClient() { | ||
const client = await Client.withKeyInfo(await this.getKeyInfo()) | ||
const identity = await Libp2pCryptoIdentity.fromRandom() | ||
const identity = await PrivateKey.fromRandom() | ||
await client.getToken(identity) | ||
this.threadsClient = client | ||
return client | ||
} | ||
|
||
async createBucketsClient() { | ||
const client = await Buckets.withKeyInfo(await this.getKeyInfo()) | ||
const identity = await Libp2pCryptoIdentity.fromRandom() | ||
const identity = await PrivateKey.fromRandom() | ||
await client.getToken(identity) | ||
this.bucketsClient = client | ||
return client | ||
|
@@ -160,21 +159,9 @@ export class Application { | |
async ensureBucket(args: { bucketName: string }) { | ||
const client = await this.getBucketsClient() | ||
|
||
// Version 1 | ||
// const roots = await client.list(); | ||
// const existing = roots.find((bucket) => bucket.name === args.bucketName) | ||
// if (existing) { | ||
// return existing.key; | ||
// } | ||
|
||
// const created = await client.init(args.bucketName); | ||
// const bucketKey = created.root ? created.root.key : '' | ||
|
||
// Version 2 | ||
const result = await client.open(args.bucketName) | ||
const bucketKey = result?.key | ||
const result = await client.getOrInit(args.bucketName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the new |
||
const bucketKey = result.root?.key | ||
if (!bucketKey) throw new Error('bucket not created') | ||
|
||
return { bucketKey } | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
global['WebSocket'] = require('isomorphic-ws') | ||
import io from 'socket.io-client' | ||
import { createStorexHubSocketClient } from '@worldbrain/storex-hub/lib/client' | ||
// import { Identity, ThreadID, Libp2pCryptoIdentity } from '@textile/threads-core' | ||
// import { Database } from '@textile/threads-database' | ||
// import { Client, KeyInfo } from '@textile/hub' | ||
// import { Client, KeyInfo, ThreadID, Identity, PrivateKey } from '@textile/hub' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything should be imported from the single lib now |
||
import { Application } from './application' | ||
import { FileSettingsStore, StorexHubSettingsStore } from './settings' | ||
import { join } from 'path' | ||
|
@@ -19,33 +17,12 @@ export async function main(options?: { | |
// return ThreadID.fromString(threadIDString) | ||
// } | ||
|
||
// let database: Database | ||
// if (options?.local) { | ||
// const identity = await Database.randomIdentity() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We learned that the Database class wasn't the right method and was proving confusing to users. We are moving all the local methods directly into the Client as part of this, textileio/js-threads#414. So for now, just use Client and then it should pretty cleanly upgrade to just being local at the same time once that ticket is wrapped. |
||
// database = new Database('demo.db') | ||
// await database.start(identity) | ||
// } else { | ||
// const client = await Client.withKeyInfo(getKeyInfo()) | ||
// const identity = await Libp2pCryptoIdentity.fromRandom() | ||
// const token = await client.getToken(identity) | ||
// const threadId = ThreadID.fromRandom() | ||
// await client.newDB(threadId) | ||
// } | ||
|
||
// const db = new Database('demo.db') | ||
// await db.start(identity) | ||
|
||
// const Thing = db.collections.get('Thing') ?? await db.newCollection('Thing', {}) | ||
// const thing1 = new Thing({ test: 5 }) | ||
// const thing2 = new Thing({ test: 8 }) | ||
// await thing1.save() | ||
// await thing2.save() | ||
|
||
// for await (const test of Thing.find({ test: { $gt: 6 } })) { | ||
// console.log(await test) | ||
// } | ||
// const client = await Client.withKeyInfo(getKeyInfo()) | ||
// const identity = await PrivateKey.fromRandom() | ||
// const token = await client.getToken(identity) | ||
// const threadId = ThreadID.fromRandom() | ||
// await client.newDB(threadId) | ||
|
||
// const db = new Database() | ||
const port = options?.port ?? (process.env.NODE_ENV === 'production' ? 50482 : 50483) | ||
const socket = io(`http://localhost:${port}`) | ||
console.log('Connecting to Storex Hub') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Libp2pCryptoIdentity
has been replaced with the more usefulPrivateKey
,PublicKey
, andIdentity
classes