Add --owner and --bond-id
All checks were successful
Tests / sdk_tests (pull_request) Successful in 3m33s

This commit is contained in:
Thomas E Lackey 2023-11-27 21:37:40 -06:00
parent f1e3f7b673
commit d3fc1658c9

View File

@ -9,6 +9,12 @@ export const command = 'list';
export const desc = 'List records.'; export const desc = 'List records.';
export const builder = { export const builder = {
'bond-id': {
type: 'string'
},
owner: {
type: 'string'
},
type: { type: {
type: 'string' type: 'string'
}, },
@ -24,7 +30,7 @@ export const builder = {
export const handler = async (argv: Arguments) => { export const handler = async (argv: Arguments) => {
const { services: { cns: cnsConfig } } = getConfig(argv.config as string) const { services: { cns: cnsConfig } } = getConfig(argv.config as string)
const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig); const { restEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, cnsConfig);
const { type, name, all } = argv; const { type, name, bondId, owner, all } = argv;
const filters: any = {}; const filters: any = {};
const filterArgs = argv._.slice(3); const filterArgs = argv._.slice(3);
@ -38,15 +44,25 @@ export const handler = async (argv: Arguments) => {
const registry = new Registry(gqlEndpoint, restEndpoint, chainId); const registry = new Registry(gqlEndpoint, restEndpoint, chainId);
let result: any[];
try { try {
const result = await registry.queryRecords({...filters, type, name}, all as boolean); result = await registry.queryRecords({...filters, type, name}, all as boolean);
queryOutput(result, argv.output)
} catch (e) { } catch (e) {
// https://git.vdb.to/cerc-io/laconicd/issues/118 // https://git.vdb.to/cerc-io/laconicd/issues/118
if (Array.isArray(e) && (e as []).length && e[0].message?.includes("store doesn't have key")) { if (Array.isArray(e) && (e as []).length && e[0].message?.includes("store doesn't have key")) {
queryOutput([], argv.output) result = [];
} else { } else {
throw e; throw e;
} }
} }
if (bondId) {
result = result.filter(v => v.bondId === bondId);
}
if (owner) {
result = result.filter(v => v.owners?.find((e: string) => e === owner));
}
queryOutput(result, argv.output)
} }