Skip to content

Commit

Permalink
fix: re export proto types, release config
Browse files Browse the repository at this point in the history
  • Loading branch information
asutula committed Jun 10, 2020
1 parent 645add3 commit e6ba7bc
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 221 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: publish
on:
release:
types: [published]
jobs:
publish:
name: publish
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
- name: Get latest tag
id: latesttag
uses: "WyriHaximus/github-action-get-previous-tag@master"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: "12.x"
registry-url: "https://registry.npmjs.org"
- name: Get Dependencies
run: |
npm install
npm install -g json
npm install -g yaml-cli
- name: Build Library
run: |
npm run build
- name: Publish NPM Package
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: |
json -I -f package.json -e 'this.version=("${{ steps.latesttag.outputs.tag }}").replace("v", "")'
npm publish --access=public
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ npm i @textile/powergate-client
Start by creating an instance of the client.

```typescript
import { createPow } from '@textile/powergate-client'
import { createPow } from "@textile/powergate-client"

const host = 'http://0.0.0.0:6002' // or whatever powergate instance you want
const host = "http://0.0.0.0:6002" // or whatever powergate instance you want

const pow = createPow({ host })
```
Expand Down Expand Up @@ -74,13 +74,14 @@ pow.setToken(authToken)
Now, the FFS API is available for you to use.

```typescript
import fs from 'fs'
import fs from "fs"
import { ffs } from "@textile/powergate-client"

// get wallet addresses associated with your FFS instance
const { addrsList } = await pow.ffs.addrs()

// create a new address associated with your ffs instance
const { addr } = await pow.ffs.newAddr('my new addr')
const { addr } = await pow.ffs.newAddr("my new addr")

// get general info about your ffs instance
const { info } = await pow.ffs.info()
Expand All @@ -94,12 +95,12 @@ const { jobId } = await pow.ffs.pushConfig(cid)

// watch the FFS job status to see the storage process progressing
const cancel = pow.ffs.watchJobs((job) => {
if (job.status === JobStatus.CANCELED) {
console.log('job canceled')
} else if (job.status === JobStatus.FAILED) {
console.log('job failed')
} else if (job.status === JobStatus.SUCCESS) {
console.log('job success!')
if (job.status === ffs.JobStatus.CANCELED) {
console.log("job canceled")
} else if (job.status === ffs.JobStatus.FAILED) {
console.log("job failed")
} else if (job.status === ffs.JobStatus.SUCCESS) {
console.log("job success!")
}
}, jobId)

Expand All @@ -118,7 +119,7 @@ const { cidinfo } = await pow.ffs.show(cid)
const bytes = await pow.ffs.get(cid)

// senf FIL from an address managed by your FFS instance to any other address
await pow.ffs.sendFil(addrsList[0].addr, '<some other address>', 1000)
await pow.ffs.sendFil(addrsList[0].addr, "<some other address>", 1000)
```

There are also several useful examples included in the `*.spec.ts` files of this repo.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@textile/powergate-client",
"version": "0.1.0-beta.8",
"version": "0.0.0",
"description": "Client for Textile's Powergate",
"main": "dist/index",
"types": "dist/index",
Expand Down
91 changes: 43 additions & 48 deletions src/ffs/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import {
AddrInfo,
CidConfig,
DefaultConfig,
JobStatus,
} from "@textile/grpc-powergate-client/dist/ffs/rpc/rpc_pb"
import { expect } from "chai"
import fs from "fs"
import { createFFS, withConfig, withHistory, withOverrideConfig } from "."
import { ffs } from "../types"
import { getTransport, host, useToken } from "../util"

describe("ffs", () => {
const { getMeta, setToken } = useToken("")

const ffs = createFFS({ host, transport: getTransport() }, getMeta)
const c = createFFS({ host, transport: getTransport() }, getMeta)

let instanceId: string
let initialAddrs: AddrInfo.AsObject[]
let defaultConfig: DefaultConfig.AsObject
let initialAddrs: ffs.AddrInfo.AsObject[]
let defaultConfig: ffs.DefaultConfig.AsObject
let cid: string
let defaultCidConfig: CidConfig.AsObject
let defaultCidConfig: ffs.CidConfig.AsObject

it("should create an instance", async function () {
this.timeout(30000)
const res = await ffs.create()
const res = await c.create()
expect(res.id).not.empty
expect(res.token).not.empty
instanceId = res.id
Expand All @@ -32,53 +27,53 @@ describe("ffs", () => {
})

it("should list instances", async () => {
const res = await ffs.list()
const res = await c.list()
expect(res.instancesList).length.greaterThan(0)
})

it("should get instance id", async () => {
const res = await ffs.id()
const res = await c.id()
expect(res.id).eq(instanceId)
})

it("should get addrs", async () => {
const res = await ffs.addrs()
const res = await c.addrs()
initialAddrs = res.addrsList
expect(initialAddrs).length.greaterThan(0)
})

it("should get the default config", async () => {
const res = await ffs.defaultConfig()
const res = await c.defaultConfig()
expect(res.defaultConfig).not.undefined
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
defaultConfig = res.defaultConfig!
})

it("should create a new addr", async () => {
const res = await ffs.newAddr("my addr")
const res = await c.newAddr("my addr")
expect(res.addr).length.greaterThan(0)
const addrsRes = await ffs.addrs()
const addrsRes = await c.addrs()
expect(addrsRes.addrsList).length(initialAddrs.length + 1)
})

it("should set default config", async () => {
await ffs.setDefaultConfig(defaultConfig)
await c.setDefaultConfig(defaultConfig)
})

it("should get info", async () => {
const res = await ffs.info()
const res = await c.info()
expect(res.info).not.undefined
})

it("should add to hot", async () => {
const buffer = fs.readFileSync(`sample-data/samplefile`)
const res = await ffs.addToHot(buffer)
const res = await c.addToHot(buffer)
expect(res.cid).length.greaterThan(0)
cid = res.cid
})

it("should get default cid config", async () => {
const res = await ffs.getDefaultCidConfig(cid)
const res = await c.getDefaultCidConfig(cid)
expect(res.config?.cid).equal(cid)
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
defaultCidConfig = res.config!
Expand All @@ -87,18 +82,18 @@ describe("ffs", () => {
let jobId: string

it("should push config", async () => {
const res = await ffs.pushConfig(cid, withOverrideConfig(false), withConfig(defaultCidConfig))
const res = await c.pushConfig(cid, withOverrideConfig(false), withConfig(defaultCidConfig))
expect(res.jobId).length.greaterThan(0)
jobId = res.jobId
})

it("should watch job", function (done) {
this.timeout(180000)
const cancel = ffs.watchJobs((job) => {
const cancel = c.watchJobs((job) => {
expect(job.errCause).empty
expect(job.status).not.equal(JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(JobStatus.JOB_STATUS_FAILED)
if (job.status === JobStatus.JOB_STATUS_SUCCESS) {
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_FAILED)
if (job.status === ffs.JobStatus.JOB_STATUS_SUCCESS) {
cancel()
done()
}
Expand All @@ -107,7 +102,7 @@ describe("ffs", () => {

it("should watch logs", function (done) {
this.timeout(10000)
const cancel = ffs.watchLogs(
const cancel = c.watchLogs(
(logEvent) => {
expect(logEvent.cid).not.empty
cancel()
Expand All @@ -119,52 +114,52 @@ describe("ffs", () => {
})

it("should get cid config", async () => {
const res = await ffs.getCidConfig(cid)
const res = await c.getCidConfig(cid)
expect(res.config?.cid).equal(cid)
})

it("should show", async () => {
const res = await ffs.show(cid)
const res = await c.show(cid)
expect(res.cidInfo).not.undefined
})

it("should show all", async () => {
const res = await ffs.showAll()
const res = await c.showAll()
expect(res).not.empty
})

let buffer: Buffer

it("should replace", async () => {
buffer = fs.readFileSync(`sample-data/samplefile2`)
const res0 = await ffs.addToHot(buffer)
const res0 = await c.addToHot(buffer)
expect(res0.cid).length.greaterThan(0)
const res1 = await ffs.replace(cid, res0.cid)
const res1 = await c.replace(cid, res0.cid)
expect(res1.jobId).length.greaterThan(0)
cid = res0.cid
jobId = res1.jobId
})

it("should watch replace job", function (done) {
this.timeout(180000)
const cancel = ffs.watchJobs((job) => {
const cancel = c.watchJobs((job) => {
expect(job.errCause).empty
expect(job.status).not.equal(JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(JobStatus.JOB_STATUS_FAILED)
if (job.status === JobStatus.JOB_STATUS_SUCCESS) {
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_FAILED)
if (job.status === ffs.JobStatus.JOB_STATUS_SUCCESS) {
cancel()
done()
}
}, jobId)
})

it("should get", async () => {
const bytes = await ffs.get(cid)
const bytes = await c.get(cid)
expect(bytes.byteLength).equal(buffer.byteLength)
})

it("should list payment channels", async () => {
await ffs.listPayChannels()
await c.listPayChannels()
})

it("should create a payment channel", async () => {
Expand All @@ -176,7 +171,7 @@ describe("ffs", () => {
})

it("should push disable storage job", async () => {
const newConf: CidConfig.AsObject = {
const newConf: ffs.CidConfig.AsObject = {
cid,
repairable: false,
cold: {
Expand All @@ -187,35 +182,35 @@ describe("ffs", () => {
enabled: false,
},
}
const res0 = await ffs.pushConfig(cid, withOverrideConfig(true), withConfig(newConf))
const res0 = await c.pushConfig(cid, withOverrideConfig(true), withConfig(newConf))
expect(res0).not.undefined
jobId = res0.jobId
})

it("should watch disable storage job", function (done) {
this.timeout(180000)
const cancel = ffs.watchJobs((job) => {
const cancel = c.watchJobs((job) => {
expect(job.errCause).empty
expect(job.status).not.equal(JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(JobStatus.JOB_STATUS_FAILED)
if (job.status === JobStatus.JOB_STATUS_SUCCESS) {
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_CANCELED)
expect(job.status).not.equal(ffs.JobStatus.JOB_STATUS_FAILED)
if (job.status === ffs.JobStatus.JOB_STATUS_SUCCESS) {
cancel()
done()
}
}, jobId)
})

it("should remove", async () => {
await ffs.remove(cid)
await c.remove(cid)
})

it("should send fil", async () => {
const addrs = await ffs.addrs()
const addrs = await c.addrs()
expect(addrs.addrsList).lengthOf(2)
await ffs.sendFil(addrs.addrsList[0].addr, addrs.addrsList[1].addr, 10)
await c.sendFil(addrs.addrsList[0].addr, addrs.addrsList[1].addr, 10)
})

it("should close", async () => {
await ffs.close()
await c.close()
})
})
Loading

0 comments on commit e6ba7bc

Please sign in to comment.