Skip to content

Commit eb6f44b

Browse files
authored
Merge pull request #39 from textileio/asutula/pg-0.1.0
Powergate 0.1.1 + More APIs
2 parents c37065f + 0a6e643 commit eb6f44b

19 files changed

+725
-172
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"types": "dist/index",
77
"scripts": {
88
"prepublishOnly": "npm run build",
9-
"prepare": "npm run compile",
109
"prebuild": "npm run clean",
1110
"build": "npm run compile",
1211
"compile": "tsc -b tsconfig.json",
@@ -66,6 +65,6 @@
6665
},
6766
"dependencies": {
6867
"@improbable-eng/grpc-web-node-http-transport": "^0.12.0",
69-
"@textile/grpc-powergate-client": "0.0.1-beta.13"
68+
"@textile/grpc-powergate-client": "0.1.1"
7069
}
7170
}

src/asks/index.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect } from "chai"
2+
import { createAsks } from "."
3+
import { asksTypes } from "../types"
4+
import { getTransport, host } from "../util"
5+
6+
describe("asks", () => {
7+
const c = createAsks({ host, transport: getTransport() })
8+
9+
it("should get", async () => {
10+
const index = await c.get()
11+
expect(index).not.undefined
12+
})
13+
14+
it("should query", async () => {
15+
const q = new asksTypes.Query().toObject()
16+
const res = await c.query(q)
17+
expect(res).not.undefined
18+
})
19+
})

src/asks/index.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/ask/rpc/rpc_pb_service"
2+
import { asksTypes, Config } from "../types"
3+
import { promise } from "../util"
4+
import { queryObjectToMsg } from "./util"
5+
6+
/**
7+
* Creates the Asks API client
8+
* @param config A config object that changes the behavior of the client
9+
* @returns The Asks API client
10+
*/
11+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
12+
export const createAsks = (config: Config) => {
13+
const client = new RPCServiceClient(config.host, config)
14+
return {
15+
/**
16+
* Gets the asks index
17+
* @returns The asks index
18+
*/
19+
get: () =>
20+
promise(
21+
(cb) => client.get(new asksTypes.GetRequest(), cb),
22+
(resp: asksTypes.GetResponse) => resp.toObject().index,
23+
),
24+
25+
/**
26+
* Queries the asks index
27+
* @param query The query to run against the asks index
28+
* @returns The asks matching the provided query
29+
*/
30+
query: (query: asksTypes.Query.AsObject) => {
31+
const req = new asksTypes.QueryRequest()
32+
req.setQuery(queryObjectToMsg(query))
33+
return promise(
34+
(cb) => client.query(req, cb),
35+
(resp: asksTypes.QueryResponse) => resp.toObject().asksList,
36+
)
37+
},
38+
}
39+
}

src/asks/util.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { asksTypes } from "../types"
2+
3+
export function queryObjectToMsg(query: asksTypes.Query.AsObject): asksTypes.Query {
4+
const ret = new asksTypes.Query()
5+
ret.setLimit(query.limit)
6+
ret.setMaxPrice(query.maxPrice)
7+
ret.setOffset(query.offset)
8+
ret.setPieceSize(query.pieceSize)
9+
return ret
10+
}

src/faults/index.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { expect } from "chai"
2+
import { createFaults } from "."
3+
import { getTransport, host } from "../util"
4+
5+
describe("faults", () => {
6+
const c = createFaults({ host, transport: getTransport() })
7+
8+
it("should get", async () => {
9+
const index = await c.get()
10+
expect(index).not.undefined
11+
})
12+
})

src/faults/index.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/faults/rpc/rpc_pb_service"
2+
import { Config, faultsTypes } from "../types"
3+
import { promise } from "../util"
4+
5+
/**
6+
* Creates the Faults API client
7+
* @param config A config object that changes the behavior of the client
8+
* @returns The Faults API client
9+
*/
10+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
11+
export const createFaults = (config: Config) => {
12+
const client = new RPCServiceClient(config.host, config)
13+
return {
14+
/**
15+
* Gets the faults index
16+
* @returns The faults index
17+
*/
18+
get: () =>
19+
promise(
20+
(cb) => client.get(new faultsTypes.GetRequest(), cb),
21+
(resp: faultsTypes.GetResponse) => resp.toObject().index,
22+
),
23+
}
24+
}

0 commit comments

Comments
 (0)