Skip to content

Commit

Permalink
fix: config resolution
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Sutula <[email protected]>
  • Loading branch information
asutula committed Jun 10, 2020
1 parent 22ea101 commit a10790c
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 77 deletions.
5 changes: 4 additions & 1 deletion examples/node/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ GITHUB_CLIENT_ID=f47f0f65206fc6f12d6c5
GITHUB_CLIENT_SECRET=3csdf87yf60ab5141dasfgsegvsfc3eaa3d12865270

# Application Port - express server listens on this port (default 3000).
PORT=3000
EXPRESS_PORT=3000

# Powergate host (default is http://0.0.0.0:6002)
POW_HOST=http://my.powergate.io:6002
6 changes: 3 additions & 3 deletions examples/node/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 examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"watch-debug": "concurrently -k -p \"[{name}]\" -n \"Sass,TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-sass\" \"npm run watch-ts\" \"npm run serve-debug\""
},
"dependencies": {
"@textile/powergate-client": "0.1.0-beta.7",
"@textile/powergate-client": "0.1.0-beta.8",
"dotenv": "^8.2.0",
"errorhandler": "^1.5.1",
"express": "^4.17.1",
Expand Down
6 changes: 3 additions & 3 deletions examples/node/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import passport from "passport"
import path from "path"
import * as passportConfig from "./config/passport"
import { save, User } from "./models/user"
import { SESSION_SECRET } from "./util/env"
import { EXPRESS_PORT, POW_HOST, SESSION_SECRET } from "./util/env"

// Create the Powergate client
const pow = createPow()
const pow = createPow({ host: POW_HOST })

// Create Express server
const app = express()

// Express configuration
app.set("port", process.env.PORT || 3000)
app.set("port", EXPRESS_PORT || 3000)
app.use(express.static(path.join(__dirname, "public"), { maxAge: 31557600000 }))
app.set("views", path.join(__dirname, "../views"))
app.set("view engine", "pug")
Expand Down
4 changes: 4 additions & 0 deletions examples/node/src/util/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if (fs.existsSync(".env")) {
export const ENV = process.env.NODE_ENV
export const PROD = ENV === "production" // Anything else is treated as 'dev'

export const EXPRESS_PORT = process.env["EXPRESS_PORT"]

export const POW_HOST = process.env["POW_HOST"]

export const SESSION_SECRET = mustResolve("SESSION_SECRET")

export const GITHUB_CLIENT_ID = mustResolve("GITHUB_CLIENT_ID")
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

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

7 changes: 5 additions & 2 deletions 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.7",
"version": "0.1.0-beta.8",
"description": "Client for Textile's Powergate",
"main": "dist/index",
"types": "dist/index",
Expand All @@ -16,7 +16,9 @@
"test:node": "TS_NODE_FILES=true mocha --exit",
"test:browser": "polendina --timeout 3000 --cleanup src/**/*.spec.ts --webpack-config ./webpack.test.js",
"lint": "eslint --fix --ext .js,.ts src/**/*",
"docs": "typedoc"
"docs": "typedoc",
"devnet:up": "docker-compose -p devnet -f docker-compose-devnet.yml up --build -V",
"devnet:down": "docker-compose -p devnet -f docker-compose-devnet.yml down"
},
"keywords": [
"typescript",
Expand Down Expand Up @@ -47,6 +49,7 @@
"mocha": "^7.1.1",
"polendina": "^1.0.0",
"prettier": "^2.0.2",
"prettier-plugin-organize-imports": "^1.0.4",
"rimraf": "^3.0.2",
"touch": "^3.1.0",
"ts-loader": "^7.0.4",
Expand Down
10 changes: 5 additions & 5 deletions src/ffs/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import fs from "fs"
import { expect } from "chai"
import {
AddrInfo,
DefaultConfig,
CidConfig,
DefaultConfig,
JobStatus,
} from "@textile/grpc-powergate-client/dist/ffs/rpc/rpc_pb"
import { useToken, getTransport, host } from "../util"
import { createFFS, withOverrideConfig, withConfig, withHistory } from "."
import { expect } from "chai"
import fs from "fs"
import { createFFS, withConfig, withHistory, withOverrideConfig } from "."
import { getTransport, host, useToken } from "../util"

describe("ffs", () => {
const { getMeta, setToken } = useToken("")
Expand Down
72 changes: 36 additions & 36 deletions src/ffs/index.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
import { grpc } from "@improbable-eng/grpc-web"
import {
CreateRequest,
CreateResponse,
ListAPIRequest,
ListAPIResponse,
IDRequest,
IDResponse,
AddrsRequest,
AddrsResponse,
DefaultConfigRequest,
DefaultConfigResponse,
NewAddrRequest,
NewAddrResponse,
AddToHotRequest,
AddToHotResponse,
GetDefaultCidConfigRequest,
GetDefaultCidConfigResponse,
GetCidConfigRequest,
GetCidConfigResponse,
DefaultConfig,
HotConfig,
IpfsConfig,
CidConfig,
CloseRequest,
ColdConfig,
CreatePayChannelRequest,
CreatePayChannelResponse,
CreateRequest,
CreateResponse,
DefaultConfig,
DefaultConfigRequest,
DefaultConfigResponse,
FilConfig,
FilRenew,
SetDefaultConfigRequest,
GetCidConfigRequest,
GetCidConfigResponse,
GetDefaultCidConfigRequest,
GetDefaultCidConfigResponse,
GetRequest,
HotConfig,
IDRequest,
IDResponse,
InfoRequest,
InfoResponse,
IpfsConfig,
Job,
ListAPIRequest,
ListAPIResponse,
ListPayChannelsRequest,
ListPayChannelsResponse,
LogEntry,
NewAddrRequest,
NewAddrResponse,
PushConfigRequest,
CidConfig,
PushConfigResponse,
ShowRequest,
ShowResponse,
RedeemPayChannelRequest,
RemoveRequest,
ReplaceRequest,
ReplaceResponse,
RemoveRequest,
SendFilRequest,
CloseRequest,
WatchJobsRequest,
Job,
LogEntry,
WatchLogsRequest,
GetRequest,
SetDefaultConfigRequest,
ShowAllRequest,
ShowAllResponse,
ListPayChannelsRequest,
ListPayChannelsResponse,
CreatePayChannelRequest,
CreatePayChannelResponse,
RedeemPayChannelRequest,
ShowRequest,
ShowResponse,
WatchJobsRequest,
WatchLogsRequest,
} from "@textile/grpc-powergate-client/dist/ffs/rpc/rpc_pb"
import {
RPCServiceClient,
RPCService,
RPCServiceClient,
} from "@textile/grpc-powergate-client/dist/ffs/rpc/rpc_pb_service"
import { grpc } from "@improbable-eng/grpc-web"
import { promise } from "../util"
import { Config } from "../types"
import { promise } from "../util"

type PushConfigOption = (req: PushConfigRequest) => void

Expand Down
4 changes: 2 additions & 2 deletions src/health/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai"
import { Status } from "@textile/grpc-powergate-client/dist/health/rpc/rpc_pb"
import { getTransport, host } from "../util"
import { expect } from "chai"
import { createHealth } from "."
import { getTransport, host } from "../util"

describe("health", () => {
const health = createHealth({ host, transport: getTransport() })
Expand Down
4 changes: 2 additions & 2 deletions src/health/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/health/rpc/rpc_pb_service"
import { CheckRequest, CheckResponse } from "@textile/grpc-powergate-client/dist/health/rpc/rpc_pb"
import { promise } from "../util"
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/health/rpc/rpc_pb_service"
import { Config } from "../types"
import { promise } from "../util"

/**
* Creates the Health API client
Expand Down
1 change: 0 additions & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from "chai"
import cp from "child_process"
import path from "path"
import wait from "wait-on"

import { createPow } from "."
import { host } from "./util"

Expand Down
17 changes: 13 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { createHealth } from "./health"
import { createNet } from "./net"
import { createFFS } from "./ffs"
import { createHealth } from "./health"
import { createMiners } from "./miners"
import { useToken, getTransport, host } from "./util"
import { createNet } from "./net"
import { Config } from "./types"
import { getTransport, host, useToken } from "./util"

const defaultConfig: Config = {
host,
Expand All @@ -16,7 +16,7 @@ const defaultConfig: Config = {
* @returns A Powergate client API
*/
export const createPow = (config?: Partial<Config>) => {
const c = { ...defaultConfig, ...config }
const c = { ...defaultConfig, ...removeEmpty(config) }

const { getMeta, setToken } = useToken(c.authToken)

Expand Down Expand Up @@ -48,3 +48,12 @@ export const createPow = (config?: Partial<Config>) => {
miners: createMiners(c),
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const removeEmpty = (obj: any) => {
Object.keys(obj).forEach((key) => {
if (obj[key] && typeof obj[key] === "object") removeEmpty(obj[key])
else if (obj[key] === undefined) delete obj[key]
})
return obj
}
2 changes: 1 addition & 1 deletion src/miners/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai"
import { getTransport, host } from "../util"
import { createMiners } from "."
import { getTransport, host } from "../util"

describe("miners", () => {
const miners = createMiners({ host, transport: getTransport() })
Expand Down
4 changes: 2 additions & 2 deletions src/miners/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/miner/rpc/rpc_pb_service"
import { GetRequest, GetResponse } from "@textile/grpc-powergate-client/dist/index/miner/rpc/rpc_pb"
import { promise } from "../util"
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/index/miner/rpc/rpc_pb_service"
import { Config } from "../types"
import { promise } from "../util"

/**
* Creates the Miners API client
Expand Down
6 changes: 3 additions & 3 deletions src/net/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, assert } from "chai"
import { PeersResponse, Connectedness } from "@textile/grpc-powergate-client/dist/net/rpc/rpc_pb"
import { getTransport, host } from "../util"
import { Connectedness, PeersResponse } from "@textile/grpc-powergate-client/dist/net/rpc/rpc_pb"
import { assert, expect } from "chai"
import { createNet } from "."
import { getTransport, host } from "../util"

describe("net", () => {
const net = createNet({ host, transport: getTransport() })
Expand Down
20 changes: 10 additions & 10 deletions src/net/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/net/rpc/rpc_pb_service"
import {
PeersRequest,
PeersResponse,
ListenAddrRequest,
ListenAddrResponse,
ConnectednessRequest,
ConnectednessResponse,
ConnectPeerRequest,
DisconnectPeerRequest,
FindPeerRequest,
FindPeerResponse,
ConnectPeerRequest,
ListenAddrRequest,
ListenAddrResponse,
PeerAddrInfo,
DisconnectPeerRequest,
ConnectednessRequest,
ConnectednessResponse,
PeersRequest,
PeersResponse,
} from "@textile/grpc-powergate-client/dist/net/rpc/rpc_pb"
import { promise } from "../util"
import { RPCServiceClient } from "@textile/grpc-powergate-client/dist/net/rpc/rpc_pb_service"
import { Config } from "../types"
import { promise } from "../util"

/**
* Creates the Net API client
Expand Down

0 comments on commit a10790c

Please sign in to comment.