diff --git a/package.json b/package.json index 335185f..487a727 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "keywords": [], "author": "Vincent den Boer", "dependencies": { - "@textile/hub": "^0.4.1", - "@textile/threads-core": "^0.1.33", + "@textile/hub": "^0.6.2", "@worldbrain/storex": "^0.4.1", "@worldbrain/storex-pattern-modules": "^0.4.0", "@worldbrain/storex-middleware-change-watcher": "^0.1.1", diff --git a/ts/application.ts b/ts/application.ts index f0c631c..d2f2e62 100644 --- a/ts/application.ts +++ b/ts/application.ts @@ -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,7 +89,7 @@ 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 @@ -98,7 +97,7 @@ export class Application { 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) + const bucketKey = result.root?.key if (!bucketKey) throw new Error('bucket not created') - return { bucketKey } } diff --git a/ts/main.ts b/ts/main.ts index d1adec8..7bd6587 100644 --- a/ts/main.ts +++ b/ts/main.ts @@ -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' 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() - // 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')