-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from textileio/asutula/pg-0.1.0
Powergate 0.1.1 + More APIs
- Loading branch information
Showing
19 changed files
with
725 additions
and
172 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
} | ||
} |
Oops, something went wrong.