diff --git a/packages/indexer-agent/package.json b/packages/indexer-agent/package.json index dd200a022..fb84247a1 100644 --- a/packages/indexer-agent/package.json +++ b/packages/indexer-agent/package.json @@ -30,7 +30,7 @@ }, "dependencies": { "@graphprotocol/common-ts": "1.8.6", - "@graphprotocol/contracts": "1.13.0", + "@graphprotocol/contracts": "1.16.0", "@graphprotocol/indexer-common": "^0.20.4", "@thi.ng/heaps": "^1.3.1", "@uniswap/sdk": "3.0.3", diff --git a/packages/indexer-cli/src/actions.ts b/packages/indexer-cli/src/actions.ts index 55a5acea2..e654f9a77 100644 --- a/packages/indexer-cli/src/actions.ts +++ b/packages/indexer-cli/src/actions.ts @@ -276,6 +276,7 @@ export async function fetchAction( export async function fetchActions( client: IndexerManagementClient, actionFilter: ActionFilter, + first?: number, orderBy?: ActionParams, orderDirection?: OrderDirection, ): Promise { @@ -284,10 +285,16 @@ export async function fetchActions( gql` query actions( $filter: ActionFilter! + $first: Int $orderBy: ActionParams $orderDirection: OrderDirection ) { - actions(filter: $filter, orderBy: $orderBy, orderDirection: $orderDirection) { + actions( + filter: $filter + orderBy: $orderBy + orderDirection: $orderDirection + first: $first + ) { id type allocationID @@ -304,7 +311,7 @@ export async function fetchActions( } } `, - { filter: actionFilter, orderBy, orderDirection }, + { filter: actionFilter, orderBy, orderDirection, first }, ) .toPromise() diff --git a/packages/indexer-cli/src/commands/indexer/actions/get.ts b/packages/indexer-cli/src/commands/indexer/actions/get.ts index 87f0d3764..f96d8b96b 100644 --- a/packages/indexer-cli/src/commands/indexer/actions/get.ts +++ b/packages/indexer-cli/src/commands/indexer/actions/get.ts @@ -21,11 +21,12 @@ ${chalk.dim('Options:')} -h, --help Show usage information --type allocate|unallocate|reallocate|collect Filter by type - --status queued|approved|pending|success|failed|canceled Filter by status + --status queued|approved|pending|success|failed|canceled Filter by status --source Fetch only actions queued by a specific source --reason Fetch only actions queued for a specific reason --orderBy id|deploymentID|amount|priority|...|updatedAt Order actions by a specific field (default: id) --orderDirection asc|desc Order direction (default: desc) + --first [N] Fetch only the N first records (default: all records) -o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML ` @@ -38,8 +39,19 @@ module.exports = { const inputSpinner = toolbox.print.spin('Processing inputs') - const { type, status, source, reason, orderBy, orderDirection, h, help, o, output } = - parameters.options + const { + type, + status, + source, + reason, + orderBy, + orderDirection, + h, + help, + o, + output, + first, + } = parameters.options const [action] = fixParameters(parameters, { h, help }) || [] let orderByParam = ActionParams.ID @@ -50,7 +62,6 @@ module.exports = { inputSpinner.stopAndPersist({ symbol: '💁', text: HELP }) return } - try { if (!['json', 'yaml', 'table'].includes(outputFormat)) { throw Error( @@ -91,6 +102,11 @@ module.exports = { ? OrderDirection[orderDirection.toUpperCase() as keyof typeof OrderDirection] : OrderDirection.DESC } + + if (!['undefined', 'number'].includes(typeof first)) { + throw Error(`Invalid value for '--first' option, must have a numeric value.`) + } + inputSpinner.succeed('Processed input parameters') } catch (error) { inputSpinner.fail(error.toString()) @@ -110,7 +126,13 @@ module.exports = { let actions: ActionResult[] = [] if (action) { if (action === 'all') { - actions = await fetchActions(client, {}, orderByParam, orderDirectionValue) + actions = await fetchActions( + client, + {}, + first, + orderByParam, + orderDirectionValue, + ) } else { actions = [await fetchAction(client, +action)] } @@ -123,6 +145,7 @@ module.exports = { source, reason, }, + first, orderByParam, orderDirectionValue, ) diff --git a/packages/indexer-common/src/indexer-management/actions.ts b/packages/indexer-common/src/indexer-management/actions.ts index 462c5ca81..29cedebb8 100644 --- a/packages/indexer-common/src/indexer-management/actions.ts +++ b/packages/indexer-common/src/indexer-management/actions.ts @@ -157,6 +157,7 @@ export class ActionManager { filter: ActionFilter, orderBy?: ActionParams, orderDirection?: OrderDirection, + first?: number, ): Promise { const filterObject = JSON.parse(JSON.stringify(filter)) const orderObject: Order = orderBy @@ -165,6 +166,7 @@ export class ActionManager { return await this.models.Action.findAll({ where: filterObject, order: orderObject, + limit: first, }) } } diff --git a/packages/indexer-common/src/indexer-management/client.ts b/packages/indexer-common/src/indexer-management/client.ts index 73003cdad..a81bf39fc 100644 --- a/packages/indexer-common/src/indexer-management/client.ts +++ b/packages/indexer-common/src/indexer-management/client.ts @@ -376,6 +376,7 @@ const SCHEMA_SDL = gql` filter: ActionFilter orderBy: ActionParams orderDirection: OrderDirection + first: Int ): [Action]! } diff --git a/packages/indexer-common/src/indexer-management/resolvers/actions.ts b/packages/indexer-common/src/indexer-management/resolvers/actions.ts index 195f472bb..c544263f6 100644 --- a/packages/indexer-common/src/indexer-management/resolvers/actions.ts +++ b/packages/indexer-common/src/indexer-management/resolvers/actions.ts @@ -118,15 +118,22 @@ export default { filter, orderBy, orderDirection, - }: { filter: ActionFilter; orderBy: ActionParams; orderDirection: OrderDirection }, + first, + }: { + filter: ActionFilter + orderBy: ActionParams + orderDirection: OrderDirection + first: number + }, { actionManager, logger }: IndexerManagementResolverContext, ): Promise => { logger.debug(`Execute 'actions' query`, { filter, orderBy, orderDirection, + first, }) - return await actionManager.fetchActions(filter, orderBy, orderDirection) + return await actionManager.fetchActions(filter, orderBy, orderDirection, first) }, queueActions: async ( diff --git a/yarn.lock b/yarn.lock index c796d06df..596d34976 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,6 +811,13 @@ dependencies: ethers "^5.4.4" +"@graphprotocol/contracts@1.16.0": + version "1.16.0" + resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-1.16.0.tgz#3ecc43277b4da8ccbd14fb6ea42c93c888e52d53" + integrity sha512-/UldTtx6/GbeNqWlMf2P3a4l6gQYEiNdG+FooUfDQYansnOmLCe+vmnRnh+w2cnf3L6KteX2Qxih4ajI7q1gcQ== + dependencies: + ethers "^5.4.4" + "@graphprotocol/cost-model@0.1.14": version "0.1.14" resolved "https://registry.npmjs.org/@graphprotocol/cost-model/-/cost-model-0.1.14.tgz#0eeab1c3c63d94600c2cc67e46965e0ba65b2353"