Skip to content

Commit

Permalink
Merge pull request #151 from textileio/andrew/update-new-context-api2
Browse files Browse the repository at this point in the history
chore(deps): adds external context dep
  • Loading branch information
andrewxhill authored May 12, 2020
2 parents ba72c5f + 2e84f05 commit 2d04be6
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 538 deletions.
425 changes: 154 additions & 271 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@
"dependencies": {
"@improbable-eng/grpc-web": "^0.12.0",
"@textile/buckets-grpc": "1.0.2",
"@textile/context": "^0.1.0",
"@textile/hub-grpc": "1.0.2",
"@textile/threads-client": "^0.3.0-rc.0",
"@textile/threads-id": "0.0.3",
"@textile/threads-client": "v0.3.0",
"@textile/threads-id": "0.0.4",
"@textile/users-grpc": "1.0.2",
"@types/google-protobuf": "^3.7.2",
"axios": "^0.19.2",
"cids": "^0.8.0",
"delay": "^4.3.0",
"fast-sha256": "^1.3.0",
"google-protobuf": "^3.10.0",
"isomorphic-ws": "^4.0.1",
"loglevel": "^1.6.8",
"queueable": "^4.1.4"
},
"devDependencies": {
"@textile/threads-core": "^0.1.5-rc.0",
"@textile/threads-core": "^0.1.6",
"@types/browser-or-node": "^1.2.0",
"@types/chai": "^4.2.5",
"@types/mocha": "^7.0.1",
Expand All @@ -87,6 +87,7 @@
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-prettier": "^3.1.1",
"isomorphic-ws": "^4.0.1",
"mocha": "^6.2.2",
"nyc": "^15.0.0",
"polendina": "^1.0.0",
Expand All @@ -102,6 +103,7 @@
"typescript": "^3.7.2",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
"webpack-dev-server": "^3.9.0",
"ws": "^7.3.0"
}
}
54 changes: 26 additions & 28 deletions src/buckets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ThreadID } from '@textile/threads-id'
import { expect } from 'chai'
import { Client } from '@textile/threads-client'
import { InitReply } from '@textile/buckets-grpc/buckets_pb'
import { Context } from './context'
import { Context } from '@textile/context'
import { Buckets } from './buckets'
import { signUp } from './utils'

Expand All @@ -19,25 +19,23 @@ const wrongError = new Error('wrong error!')
const sessionSecret = 'textilesession'

describe('Buckets...', () => {
let ctx: Context = new Context(addrApiurl, undefined)
const ctx: Context = new Context(addrApiurl, undefined)
const client = new Buckets(ctx)
let buck: InitReply.AsObject
let fileSize: number
before(async () => {
const user = await signUp(ctx, addrGatewayUrl, sessionSecret)
ctx = ctx.withSession(user.user?.session).withThreadName('buckets')
const id = ThreadID.fromRandom()
const db = new Client(ctx)
await db.newDB(id.toBytes())
ctx = ctx.withThread(id)
const db = new Client(ctx.withSession(user.user?.session).withThreadName('buckets'))
await db.newDB(id, ctx.withThread(id))
})

it('should init a new bucket', async () => {
// Check that we're empty
const list = await client.list(ctx)
const list = await client.list()
expect(list).to.have.length(0)
// Now initialize a bucket
buck = await client.init('mybuck', ctx)
buck = await client.init('mybuck')
expect(buck).to.have.ownProperty('root')
expect(buck.root).to.have.ownProperty('key')
expect(buck.root).to.have.ownProperty('path')
Expand All @@ -46,7 +44,7 @@ describe('Buckets...', () => {
})

it('should list buckets', async () => {
const roots = await client.list(ctx)
const roots = await client.list()
expect(roots).to.have.length(1)
const root = roots[0]
expect(root).to.have.ownProperty('key', buck.root?.key)
Expand All @@ -57,7 +55,7 @@ describe('Buckets...', () => {

it('should list empty bucket content at path', async () => {
// Mostly empty
const res = await client.listPath(buck.root?.key || '', '', ctx)
const res = await client.listPath(buck.root?.key || '', '')
expect(res).to.have.ownProperty('root')
expect(res.root).to.not.be.undefined
expect(res.item?.isdir).to.be.true
Expand All @@ -74,7 +72,7 @@ describe('Buckets...', () => {
let length = 0

// Bucket path
const res = await client.pushPath(rootKey, 'dir1/file1.jpg', stream, ctx, {
const res = await client.pushPath(rootKey, 'dir1/file1.jpg', stream, undefined, {
progress: (num) => (length = num || 0),
})
expect(length).to.equal(fileSize)
Expand All @@ -83,11 +81,11 @@ describe('Buckets...', () => {

// Nested bucket path
stream = fs.createReadStream(path.join(pth, 'file2.jpg'))
const { root } = await client.pushPath(rootKey, 'path/to/file2.jpg', stream, ctx)
const { root } = await client.pushPath(rootKey, 'path/to/file2.jpg', stream)
expect(root).to.not.be.undefined

// Root dir
const rep = await client.listPath(rootKey, '', ctx)
const rep = await client.listPath(rootKey, '')
expect(rep.item?.isdir).to.be.true
expect(rep.item?.itemsList).to.have.length(2)
})
Expand All @@ -105,7 +103,7 @@ describe('Buckets...', () => {
let length = 0

// Bucket path
const res = await client.pushPath(rootKey, 'dir1/file1.jpg', file, ctx, {
const res = await client.pushPath(rootKey, 'dir1/file1.jpg', file, undefined, {
progress: (num) => (length = num || 0),
})
expect(length).to.equal(54)
Expand All @@ -114,11 +112,11 @@ describe('Buckets...', () => {

// Nested bucket path
// @note: We're reusing file here...
const { root } = await client.pushPath(rootKey, 'path/to/file2.jpg', file, ctx)
const { root } = await client.pushPath(rootKey, 'path/to/file2.jpg', file)
expect(root).to.not.be.undefined

// Root dir
const rep = await client.listPath(rootKey, '', ctx)
const rep = await client.listPath(rootKey, '')
expect(rep.item?.isdir).to.be.true
expect(rep.item?.itemsList).to.have.length(2)
})
Expand All @@ -127,12 +125,12 @@ describe('Buckets...', () => {
const rootKey = buck.root?.key || ''

// Nested dir
let rep = await client.listPath(rootKey, 'dir1', ctx)
let rep = await client.listPath(rootKey, 'dir1')
expect(rep.item?.isdir).to.be.true
expect(rep.item?.itemsList).to.have.length(1)

// File
rep = await client.listPath(rootKey, 'dir1/file1.jpg', ctx)
rep = await client.listPath(rootKey, 'dir1/file1.jpg')
expect(rep.item?.path.endsWith('file1.jpg')).to.be.true
expect(rep.item?.isdir).to.be.false
})
Expand All @@ -144,7 +142,7 @@ describe('Buckets...', () => {
let length = 0

// Bucket path
const chunks = client.pullPath(rootKey, 'dir1/file1.jpg', ctx, {
const chunks = client.pullPath(rootKey, 'dir1/file1.jpg', undefined, {
progress: (num) => (length = num || 0),
})
const pth = path.join(__dirname, '..', 'testdata')
Expand All @@ -162,33 +160,33 @@ describe('Buckets...', () => {

it('should remove files by path', async () => {
const rootKey = buck.root?.key || ''
await client.removePath(rootKey, 'path/to/file2.jpg', ctx)
await client.removePath(rootKey, 'path/to/file2.jpg')
try {
await client.listPath(rootKey, 'path/to/file2.jpg', ctx)
await client.listPath(rootKey, 'path/to/file2.jpg')
throw wrongError
} catch (err) {
expect(err).to.not.equal(wrongError)
}
let list = await client.listPath(rootKey, '', ctx)
let list = await client.listPath(rootKey, '')
expect(list.item?.itemsList).to.have.length(2)
await client.removePath(rootKey, 'path', ctx)
await client.removePath(rootKey, 'path')
try {
await client.listPath(rootKey, 'path', ctx)
await client.listPath(rootKey, 'path')
throw wrongError
} catch (err) {
expect(err).to.not.equal(wrongError)
}
list = await client.listPath(rootKey, '', ctx)
list = await client.listPath(rootKey, '')
expect(list.item?.itemsList).to.have.length(1)
})

it('should remove an entire bucket', async () => {
const rootKey = buck.root?.key || ''
const rep = await client.listPath(rootKey, 'dir1/file1.jpg', ctx)
const rep = await client.listPath(rootKey, 'dir1/file1.jpg')
expect(rep).to.not.be.undefined
await client.remove(rootKey, ctx)
await client.remove(rootKey)
try {
await client.listPath(rootKey, 'dir1/file1.jpg', ctx)
await client.listPath(rootKey, 'dir1/file1.jpg')
throw wrongError
} catch (err) {
expect(err).to.not.equal(wrongError)
Expand Down
2 changes: 1 addition & 1 deletion src/buckets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { API, APIPushPath } from '@textile/buckets-grpc/buckets_pb_service'
import CID from 'cids'
import { Channel } from 'queueable'
import { grpc } from '@improbable-eng/grpc-web'
import { Context } from './context'
import { Context } from '@textile/context'
import { normaliseInput, File } from './normalize'

const logger = log.getLogger('buckets')
Expand Down
156 changes: 0 additions & 156 deletions src/context.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './buckets'
export * from './context'
export * from './users'
export { createAPISig } from './utils'
Loading

0 comments on commit 2d04be6

Please sign in to comment.