Skip to content

Commit

Permalink
Add pagination to list records CLI (#82)
Browse files Browse the repository at this point in the history
Part of [Create a public laconicd testnet](https://www.notion.so/Create-a-public-laconicd-testnet-896a11bdd8094eff8f1b49c0be0ca3b8)
Requires https://git.vdb.to/cerc-io/registry-sdk/pulls/27

Example CLI commands with changes:
```bash
laconic registry record list --type WebsiteRegistrationRecord --all true | jq 'length'
# 16

laconic registry record list --limit 4 --type WebsiteRegistrationRecord --all true | jq '[.[] | {id, createTime}]'
# [
#   {
#     "id": "bafyreifmjc7kc76ihrolzqhynwrebjyr7bw7pstlv2lcdq5qu4cleql7ke",
#     "createTime": "2024-09-05T13:25:46Z"
#   },
#   {
#     "id": "bafyreifipscluxu43nx5frx54tyxnkkki2edsw3jydgexfjsluq674esfa",
#     "createTime": "2024-09-05T13:25:49Z"
#   },
#   {
#     "id": "bafyreidco4d3pjro2fp6rinlazm3xcsnfm2ibzeigsqwlmmtvne25ukpjy",
#     "createTime": "2024-09-05T13:25:52Z"
#   },
#   {
#     "id": "bafyreigqoz4ffaqod5fut3rebrtctnp3ktvph46fgocmgmfqbkofnmombe",
#     "createTime": "2024-09-05T13:25:55Z"
#   }
# ]

laconic registry record list --limit 4 --offset 2 --type WebsiteRegistrationRecord --all true | jq '[.[] | {id, createTime}]'
# [
#   {
#     "id": "bafyreidco4d3pjro2fp6rinlazm3xcsnfm2ibzeigsqwlmmtvne25ukpjy",
#     "createTime": "2024-09-05T13:25:52Z"
#   },
#   {
#     "id": "bafyreigqoz4ffaqod5fut3rebrtctnp3ktvph46fgocmgmfqbkofnmombe",
#     "createTime": "2024-09-05T13:25:55Z"
#   },
#   {
#     "id": "bafyreieku22he546fsxrgwxd3mfpbtcobwjasl6zimkizl65rwvybwerci",
#     "createTime": "2024-09-05T13:25:58Z"
#   },
#   {
#     "id": "bafyreia4zjuap7v3tnilersrzsht75mqf3mhzsk72jgpcct7u6lj54zwyq",
#     "createTime": "2024-09-05T13:26:01Z"
#   }
# ]
```

Co-authored-by: IshaVenikar <ishavenikar7@gmail.com>
Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/82
Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
Co-committed-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
  • Loading branch information
2 people authored and nabarun committed Sep 5, 2024
1 parent 6055da6 commit cf4bf5e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cerc-io/laconic-registry-cli",
"version": "0.2.6",
"version": "0.2.7",
"main": "index.js",
"repository": "git@github.com:cerc-io/laconic-registry-cli.git",
"author": "",
Expand Down Expand Up @@ -29,7 +29,7 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@cerc-io/registry-sdk": "^0.2.6",
"@cerc-io/registry-sdk": "^0.2.8",
"fs-extra": "^10.1.0",
"js-yaml": "^3.14.1",
"lodash": "^4.17.21",
Expand Down
9 changes: 8 additions & 1 deletion src/cmds/registry-cmds/bond-cmds/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ export const handler = async (argv: Arguments) => {

const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);

let result: any;

const { owner } = argv;
const result = await registry.queryBonds({ owner });
if (owner) {
const [bondsByOwnerResult] = await registry.queryBondsByOwner([String(owner)]);
result = bondsByOwnerResult.bonds;
} else {
result = await registry.queryBonds();
}

queryOutput(result, argv.output);
};
14 changes: 12 additions & 2 deletions src/cmds/registry-cmds/record-cmds/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ export const builder = {
all: {
type: 'boolean',
default: false
},
refs: {
type: 'boolean',
default: false
},
limit: {
type: 'number'
},
offset: {
type: 'number'
}
};

export const handler = async (argv: Arguments) => {
const { services: { registry: registryConfig } } = getConfig(argv.config as string);
const { rpcEndpoint, gqlEndpoint, chainId } = getConnectionInfo(argv, registryConfig);
const { type, name, bondId, owner, all } = argv;
const { type, name, bondId, owner, all, refs, limit, offset } = argv;
const filters: any = {};

const filterArgs = argv._.slice(3);
Expand All @@ -44,7 +54,7 @@ export const handler = async (argv: Arguments) => {

const registry = new Registry(gqlEndpoint, rpcEndpoint, chainId);

let result = await registry.queryRecords({ ...filters, type, name }, all as boolean);
let result = await registry.queryRecords({ ...filters, type, name }, all as boolean, refs as boolean, limit as number, offset as number);

// Apply ex post filters.
if (bondId) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@cerc-io/registry-sdk@^0.2.6":
version "0.2.6"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.6/registry-sdk-0.2.6.tgz#af8a5844bdb742a01d322a9d93ace90d35aad37e"
integrity sha512-Z2rneeoPLTJk9aBTqMrR9WPKfPQZhNWShI4IYOb7kzoIorp3eD8mEals0I5bVjzStjapw/5RKf8lVnDCX9I4iA==
"@cerc-io/registry-sdk@^0.2.8":
version "0.2.8"
resolved "https://git.vdb.to/api/packages/cerc-io/npm/%40cerc-io%2Fregistry-sdk/-/0.2.8/registry-sdk-0.2.8.tgz#d71837f735d998987055068457fdf8b2e94ca69c"
integrity sha512-utK3Rq5qZrEoRs/eOsOkowcsD740nlnBs6C3KKFRHgKIiR0XedD6t33KukUPLKbGp4mYZOYXRTA7/A04x58lKw==
dependencies:
"@cosmjs/amino" "^0.28.1"
"@cosmjs/crypto" "^0.28.1"
Expand Down

0 comments on commit cf4bf5e

Please sign in to comment.