Skip to content

Commit

Permalink
Merge pull request #39 from textileio/asutula/pg-0.1.0
Browse files Browse the repository at this point in the history
Powergate 0.1.1 + More APIs
  • Loading branch information
asutula authored Jul 15, 2020
2 parents c37065f + 0a6e643 commit eb6f44b
Show file tree
Hide file tree
Showing 19 changed files with 725 additions and 172 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"types": "dist/index",
"scripts": {
"prepublishOnly": "npm run build",
"prepare": "npm run compile",
"prebuild": "npm run clean",
"build": "npm run compile",
"compile": "tsc -b tsconfig.json",
Expand Down Expand Up @@ -66,6 +65,6 @@
},
"dependencies": {
"@improbable-eng/grpc-web-node-http-transport": "^0.12.0",
"@textile/grpc-powergate-client": "0.0.1-beta.13"
"@textile/grpc-powergate-client": "0.1.1"
}
}
19 changes: 19 additions & 0 deletions src/asks/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from "chai"
import { createAsks } from "."
import { asksTypes } from "../types"
import { getTransport, host } from "../util"

describe("asks", () => {
const c = createAsks({ host, transport: getTransport() })

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

it("should query", async () => {
const q = new asksTypes.Query().toObject()
const res = await c.query(q)
expect(res).not.undefined
})
})
39 changes: 39 additions & 0 deletions src/asks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/ask/rpc/rpc_pb_service"
import { asksTypes, Config } from "../types"
import { promise } from "../util"
import { queryObjectToMsg } from "./util"

/**
* Creates the Asks API client
* @param config A config object that changes the behavior of the client
* @returns The Asks API client
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const createAsks = (config: Config) => {
const client = new RPCServiceClient(config.host, config)
return {
/**
* Gets the asks index
* @returns The asks index
*/
get: () =>
promise(
(cb) => client.get(new asksTypes.GetRequest(), cb),
(resp: asksTypes.GetResponse) => resp.toObject().index,
),

/**
* Queries the asks index
* @param query The query to run against the asks index
* @returns The asks matching the provided query
*/
query: (query: asksTypes.Query.AsObject) => {
const req = new asksTypes.QueryRequest()
req.setQuery(queryObjectToMsg(query))
return promise(
(cb) => client.query(req, cb),
(resp: asksTypes.QueryResponse) => resp.toObject().asksList,
)
},
}
}
10 changes: 10 additions & 0 deletions src/asks/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { asksTypes } from "../types"

export function queryObjectToMsg(query: asksTypes.Query.AsObject): asksTypes.Query {
const ret = new asksTypes.Query()
ret.setLimit(query.limit)
ret.setMaxPrice(query.maxPrice)
ret.setOffset(query.offset)
ret.setPieceSize(query.pieceSize)
return ret
}
12 changes: 12 additions & 0 deletions src/faults/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expect } from "chai"
import { createFaults } from "."
import { getTransport, host } from "../util"

describe("faults", () => {
const c = createFaults({ host, transport: getTransport() })

it("should get", async () => {
const index = await c.get()
expect(index).not.undefined
})
})
24 changes: 24 additions & 0 deletions src/faults/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/faults/rpc/rpc_pb_service"
import { Config, faultsTypes } from "../types"
import { promise } from "../util"

/**
* Creates the Faults API client
* @param config A config object that changes the behavior of the client
* @returns The Faults API client
*/
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const createFaults = (config: Config) => {
const client = new RPCServiceClient(config.host, config)
return {
/**
* Gets the faults index
* @returns The faults index
*/
get: () =>
promise(
(cb) => client.get(new faultsTypes.GetRequest(), cb),
(resp: faultsTypes.GetResponse) => resp.toObject().index,
),
}
}
Loading

0 comments on commit eb6f44b

Please sign in to comment.