Skip to content

Commit

Permalink
Merge pull request #69 from RadarTech/cf-return-default-values
Browse files Browse the repository at this point in the history
Optional flag to include default values
  • Loading branch information
cavanmflynn authored Dec 17, 2019
2 parents ea1a333 + d838551 commit 2568760
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/rpc/autopilot-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export async function createAutopilotRpc<T = unknown>(userConfig: AutopilotRpcCl
...defaults,
...userConfig,
};
const { autopilot, server, grpcLoader, grpc } = config;
const { autopilot, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/chain-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export async function createChainRpc<T = unknown>(userConfig: ChainRpcClientConf
...defaults,
...userConfig,
};
const { chainNotifier, server, grpcLoader, grpc } = config;
const { chainNotifier, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/create-grpc-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { GrpcObjectConfig, NestedGrpcObject } from '../types';
*/
export function createGrpcObject(config: GrpcObjectConfig) {
try {
const { protoFilePath, includeDirs, grpcLoader, grpc } = config;
const { protoFilePath, includeDirs, grpcLoader, grpc, includeDefaults } = config;
const packageDefinition = grpcLoader.loadSync(protoFilePath, {
longs: String,
defaults: includeDefaults ?? false,
includeDirs,
});
return grpc.loadPackageDefinition(packageDefinition) as NestedGrpcObject;
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/invoices-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export async function createInvoicesRpc<T = unknown>(userConfig: InvoicesRpcClie
...defaults,
...userConfig,
};
const { invoices, server, grpcLoader, grpc } = config;
const { invoices, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/ln-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export async function createLnRpc<T extends unknown>(userConfig: LnRpcClientConf
...defaults,
...userConfig,
};
const { lightning, walletUnlocker, server, grpcLoader, grpc } = config;
const { lightning, walletUnlocker, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/router-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export async function createRouterRpc<T = unknown>(userConfig: RouterRpcClientCo
...defaults,
...userConfig,
};
const { router, server, grpcLoader, grpc } = config;
const { router, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/sign-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export async function createSignRpc<T = unknown>(userConfig: SignRpcClientConfig
...defaults,
...userConfig,
};
const { signer, server, grpcLoader, grpc } = config;
const { signer, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/wallet-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export async function createWalletRpc<T = unknown>(userConfig: WalletRpcClientCo
...defaults,
...userConfig,
};
const { walletKit, server, grpcLoader, grpc } = config;
const { walletKit, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/watchtower-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export async function createWatchtowerRpc<T = unknown>(
...defaults,
...userConfig,
};
const { watchtower, server, grpcLoader, grpc } = config;
const { watchtower, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
3 changes: 2 additions & 1 deletion src/rpc/wt-client-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ export async function createWtClientRpc<T = unknown>(userConfig: WtClientRpcClie
...defaults,
...userConfig,
};
const { watchtowerClient, server, grpcLoader, grpc } = config;
const { watchtowerClient, server, grpcLoader, grpc, includeDefaults } = config;

// Generate grpc SSL credentials
const credentials = await createCredentials(config);

// Create RPC from proto and return GRPC
const grpcPkgObj = createGrpcObject({
includeDefaults,
protoFilePath,
grpcLoader,
grpc,
Expand Down
2 changes: 2 additions & 0 deletions src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface GrpcObjectConfig {
includeDirs?: string[];
grpcLoader: GrpcLoader;
grpc: Grpc;
includeDefaults?: boolean;
}

export interface RpcClientConfig {
Expand All @@ -38,6 +39,7 @@ export interface RpcClientConfig {
certEncoding?: string; // Default to utf-8
grpcLoader?: GrpcLoader;
grpc?: Grpc;
includeDefaults?: boolean; // Whether default values should be included in gRPC responses. Defaults to false.
}

export interface AutopilotRpcClientConfig extends RpcClientConfig {
Expand Down

0 comments on commit 2568760

Please sign in to comment.