diff --git a/package.json b/package.json index 490be74b9c..a1bf8b8e82 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,13 @@ "eslint-plugin-header": "^3.1.1", "eslint-plugin-import": "^2.25.4", "eslint-plugin-jest": "^27.2.3", - "eslint-plugin-prettier": "^4.0.0", + "eslint-plugin-prettier": "^5.1.3", "eslint-plugin-sort-destructure-keys": "^1.4.0", "husky": "^7.0.4", "jest": "^29.5.0", "lint-staged": "^12.3.3", "node-fetch": "2.6.7", - "prettier": "^2.5.1", + "prettier": "^3.2.5", "pretty-quick": "^3.1.3", "regenerator-runtime": "^0.13.9", "ts-jest": "^29.1.1", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 755dc95fbd..bf0eb0612a 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- `--queryLimit` flag to deploy command for query service (#2419) ## [4.10.1] - 2024-05-27 ### Fixed diff --git a/packages/cli/src/commands/deployment/deploy.ts b/packages/cli/src/commands/deployment/deploy.ts index 53f8599b12..c94906f090 100644 --- a/packages/cli/src/commands/deployment/deploy.ts +++ b/packages/cli/src/commands/deployment/deploy.ts @@ -23,10 +23,11 @@ import {addV, checkToken, promptWithDefaultValues, valueOrPrompt} from '../../ut export default class Deploy extends Command { static description = 'Deployment to hosted service'; - static flags = Object.assign(DefaultDeployFlags, { + static flags = { + ...DefaultDeployFlags, ipfsCID: Flags.string({description: 'Enter IPFS CID'}), endpoint: Flags.string({description: 'Enter endpoint', required: true}), - }); + }; async run(): Promise { const {flags} = await this.parse(Deploy); @@ -119,12 +120,12 @@ export default class Deploy extends Command { await executeProjectDeployment({ log: this.log.bind(this), - authToken: authToken, - chains: chains, - flags: flags, + authToken, + chains, + flags, ipfsCID: flags.ipfsCID, org: flags.org, - projectInfo: flags.projectInfo, + projectInfo, projectName: flags.projectName, queryVersion: flags.queryVersion, }); diff --git a/packages/cli/src/commands/multi-chain/deploy.ts b/packages/cli/src/commands/multi-chain/deploy.ts index 633bc54f92..ec7d538e02 100644 --- a/packages/cli/src/commands/multi-chain/deploy.ts +++ b/packages/cli/src/commands/multi-chain/deploy.ts @@ -28,10 +28,11 @@ import {addV, checkToken, promptWithDefaultValues, resolveToAbsolutePath, valueO export default class MultiChainDeploy extends Command { static description = 'Multi-chain deployment to hosted service'; - static flags = Object.assign(DefaultDeployFlags, { + static flags = { + ...DefaultDeployFlags, location: Flags.string({char: 'f', description: 'from project folder or specify manifest file', required: true}), ipfs: Flags.string({description: 'IPFS gateway endpoint', required: false}), - }); + }; async run(): Promise { const {flags} = await this.parse(MultiChainDeploy); @@ -182,12 +183,12 @@ export default class MultiChainDeploy extends Command { await executeProjectDeployment({ log: this.log.bind(this), - authToken: authToken, - chains: chains, - flags: flags, + authToken, + chains, + flags, ipfsCID: ipfsCID, org: flags.org, - projectInfo: projectInfo, + projectInfo, projectName: flags.projectName, queryVersion: flags.queryVersion, }); diff --git a/packages/cli/src/controller/deploy-controller.ts b/packages/cli/src/controller/deploy-controller.ts index f6a620f528..f4cceeed84 100644 --- a/packages/cli/src/controller/deploy-controller.ts +++ b/packages/cli/src/controller/deploy-controller.ts @@ -1,11 +1,11 @@ // Copyright 2020-2024 SubQuery Pte Ltd authors & contributors // SPDX-License-Identifier: GPL-3.0 -import {Flags} from "@oclif/core"; -import {FlagInput} from "@oclif/core/lib/interfaces/parser"; +import {Flags} from '@oclif/core'; +import {FlagInput} from '@oclif/core/lib/interfaces/parser'; import axios, {Axios} from 'axios'; -import chalk from "chalk"; -import {BASE_PROJECT_URL, DEFAULT_DEPLOYMENT_TYPE, ROOT_API_URL_PROD} from "../constants"; +import chalk from 'chalk'; +import {BASE_PROJECT_URL, DEFAULT_DEPLOYMENT_TYPE, ROOT_API_URL_PROD} from '../constants'; import { DeploymentDataType, ProjectDataType, @@ -16,7 +16,7 @@ import { ProjectDeploymentInterface, GenerateDeploymentChainInterface, DeploymentFlagsInterface, - MultichainDataFieldType + MultichainDataFieldType, } from '../types'; import {buildProjectKey, errorHandle} from '../utils'; @@ -103,7 +103,7 @@ export async function deploymentStatus( url: string ): Promise { try { - const res = await getAxiosInstance(url, authToken).get<{ status: string }>( + const res = await getAxiosInstance(url, authToken).get<{status: string}>( `subqueries/${buildProjectKey(org, projectName)}/deployments/${deployID}/status` ); return `${res.data.status}`; @@ -161,7 +161,7 @@ export async function ipfsCID_validate(cid: string, authToken: string, url: stri const res = await getAxiosInstance(url, authToken).post(`ipfs/deployment-id/${cid}/validate`); if (res.status === 500) { - throw new Error((res.data as unknown as { message: string }).message); + throw new Error((res.data as unknown as {message: string}).message); } return res.data; @@ -208,7 +208,7 @@ export interface EndpointType { export function splitMultichainDataFields(fieldStr: string): MultichainDataFieldType { const result: MultichainDataFieldType = {}; - splitEndpoints(String(fieldStr)).forEach(unparsedRow => { + splitEndpoints(String(fieldStr)).forEach((unparsedRow) => { let regexpResult: string[] = unparsedRow.match(/(.*?):(.*)/); if (regexpResult) { regexpResult = Object.values(regexpResult); @@ -221,52 +221,51 @@ export function splitMultichainDataFields(fieldStr: string): MultichainDataField return result; } -export const DefaultDeployFlags: FlagInput = - { - org: Flags.string({description: 'Enter organization name'}), - projectName: Flags.string({description: 'Enter project name'}), - // ipfsCID: Flags.string({description: 'Enter IPFS CID'}), - - type: Flags.string({options: ['stage', 'primary'], default: DEFAULT_DEPLOYMENT_TYPE, required: false}), - indexerVersion: Flags.string({description: 'Enter indexer-version', required: false}), - queryVersion: Flags.string({description: 'Enter query-version', required: false}), - dict: Flags.string({description: 'Enter dictionary', required: false}), - endpoint: Flags.string({description: 'Enter endpoint', required: false}), - //indexer set up flags - indexerUnsafe: Flags.boolean({description: 'Enable indexer unsafe', required: false}), - indexerBatchSize: Flags.integer({description: 'Enter batchSize from 1 to 30', required: false}), - indexerSubscription: Flags.boolean({description: 'Enable Indexer subscription', required: false}), - disableHistorical: Flags.boolean({description: 'Disable Historical Data', required: false}), - indexerUnfinalized: Flags.boolean({ - description: 'Index unfinalized blocks (requires Historical to be enabled)', - required: false, - }), - indexerStoreCacheThreshold: Flags.integer({ - description: 'The number of items kept in the cache before flushing', - required: false, - }), - disableIndexerStoreCacheAsync: Flags.boolean({ - description: 'If enabled the store cache will flush data asynchronously relative to indexing data.', - required: false, - }), - indexerWorkers: Flags.integer({description: 'Enter worker threads from 1 to 5', required: false, max: 5}), - - //query flags - queryUnsafe: Flags.boolean({description: 'Enable indexer unsafe', required: false}), - querySubscription: Flags.boolean({description: 'Enable Query subscription', required: false}), - queryTimeout: Flags.integer({description: 'Enter timeout from 1000ms to 60000ms', required: false}), - queryMaxConnection: Flags.integer({description: 'Enter MaxConnection from 1 to 10', required: false}), - queryAggregate: Flags.boolean({description: 'Enable Aggregate', required: false}), - - useDefaults: Flags.boolean({ - char: 'd', - description: 'Use default values for indexerVersion, queryVersion, dictionary, endpoint', - required: false, - }) - }; - - -export function generateDeploymentChain(row: GenerateDeploymentChainInterface) { +export const DefaultDeployFlags = { + org: Flags.string({description: 'Enter organization name'}), + projectName: Flags.string({description: 'Enter project name'}), + // ipfsCID: Flags.string({description: 'Enter IPFS CID'}), + + type: Flags.string({options: ['stage', 'primary'], default: DEFAULT_DEPLOYMENT_TYPE, required: false}), + indexerVersion: Flags.string({description: 'Enter indexer-version', required: false}), + queryVersion: Flags.string({description: 'Enter query-version', required: false}), + dict: Flags.string({description: 'Enter dictionary', required: false}), + endpoint: Flags.string({description: 'Enter endpoint', required: false}), + //indexer set up flags + indexerUnsafe: Flags.boolean({description: 'Enable indexer unsafe', required: false}), + indexerBatchSize: Flags.integer({description: 'Enter batchSize from 1 to 30', required: false}), + indexerSubscription: Flags.boolean({description: 'Enable Indexer subscription', required: false}), + disableHistorical: Flags.boolean({description: 'Disable Historical Data', required: false}), + indexerUnfinalized: Flags.boolean({ + description: 'Index unfinalized blocks (requires Historical to be enabled)', + required: false, + }), + indexerStoreCacheThreshold: Flags.integer({ + description: 'The number of items kept in the cache before flushing', + required: false, + }), + disableIndexerStoreCacheAsync: Flags.boolean({ + description: 'If enabled the store cache will flush data asynchronously relative to indexing data.', + required: false, + }), + indexerWorkers: Flags.integer({description: 'Enter worker threads from 1 to 5', required: false, max: 5}), + + //query flags + queryUnsafe: Flags.boolean({description: 'Enable indexer unsafe', required: false}), + querySubscription: Flags.boolean({description: 'Enable Query subscription', required: false}), + queryTimeout: Flags.integer({description: 'Enter timeout from 1000ms to 60000ms', required: false}), + queryMaxConnection: Flags.integer({description: 'Enter MaxConnection from 1 to 10', required: false}), + queryAggregate: Flags.boolean({description: 'Enable Aggregate', required: false}), + queryLimit: Flags.integer({description: 'Set the max number of results the query service returns', required: false}), + + useDefaults: Flags.boolean({ + char: 'd', + description: 'Use default values for indexerVersion, queryVersion, dictionary, endpoint', + required: false, + }), +} satisfies FlagInput; + +export function generateDeploymentChain(row: GenerateDeploymentChainInterface): V3DeploymentIndexerType { return { cid: row.cid, dictEndpoint: row.dictEndpoint, @@ -283,13 +282,13 @@ export function generateDeploymentChain(row: GenerateDeploymentChainInterface) { disableStoreCacheAsync: row.flags.disableIndexerStoreCacheAsync, }, }, - extraParams: row.flags.indexerWorkers ? - { - workers: { - num: row.flags.indexerWorkers, - }, - } : - {} + extraParams: row.flags.indexerWorkers + ? { + workers: { + num: row.flags.indexerWorkers, + }, + } + : {}, }; } @@ -298,12 +297,12 @@ export function generateAdvancedQueryOptions(flags: DeploymentFlagsInterface): Q unsafe: !!flags.queryUnsafe, subscription: !!flags.querySubscription, queryTimeout: Number(flags.queryTimeout), + queryLimit: flags.queryLimit ? Number(flags.queryLimit) : undefined, // maxConnection: Number(flags.queryMaxConnection), // project version or plan does not support maxConnection aggregate: !!flags.queryAggregate, - } + }; } - export async function executeProjectDeployment(data: ProjectDeploymentInterface): Promise { let deploymentOutput: DeploymentDataType | void; @@ -332,7 +331,7 @@ export async function executeProjectDeployment(data: ProjectDeploymentInterface) data.chains, ROOT_API_URL_PROD ).catch((e) => { - throw e + throw e; }); if (deploymentOutput) { diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index 5860b03677..5697b708f0 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -15,6 +15,7 @@ export interface QueryAdvancedOpts { subscription?: boolean; queryTimeout?: number; maxConnection?: number; + queryLimit?: number; aggregate?: boolean; } export interface IndexerAdvancedOpts { @@ -186,6 +187,7 @@ export interface DeploymentFlagsInterface { queryTimeout: number; queryMaxConnection: number; queryAggregate: boolean; + queryLimit?: number; useDefaults: boolean; } diff --git a/packages/cli/src/utils/utils.ts b/packages/cli/src/utils/utils.ts index 5c7dc5e5d3..06e7f04ddc 100644 --- a/packages/cli/src/utils/utils.ts +++ b/packages/cli/src/utils/utils.ts @@ -76,7 +76,7 @@ export async function checkToken(token_path: string = ACCESS_TOKEN_PATH): Promis if (!authToken) { return await cli.prompt('Token cannot be found, Enter token'); } - return authToken; + return authToken.trim(); } catch (e) { return cli.prompt('Token cannot be found, Enter token'); } diff --git a/yarn.lock b/yarn.lock index 1b536efcc5..51b30cd55a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5362,6 +5362,13 @@ __metadata: languageName: node linkType: hard +"@pkgr/core@npm:^0.1.0": + version: 0.1.1 + resolution: "@pkgr/core@npm:0.1.1" + checksum: 6f25fd2e3008f259c77207ac9915b02f1628420403b2630c92a07ff963129238c9262afc9e84344c7a23b5cc1f3965e2cd17e3798219f5fd78a63d144d3cceba + languageName: node + linkType: hard + "@polkadot-api/json-rpc-provider-proxy@npm:0.0.1": version: 0.0.1 resolution: "@polkadot-api/json-rpc-provider-proxy@npm:0.0.1" @@ -11731,18 +11738,23 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-prettier@npm:^4.0.0": - version: 4.0.0 - resolution: "eslint-plugin-prettier@npm:4.0.0" +"eslint-plugin-prettier@npm:^5.1.3": + version: 5.1.3 + resolution: "eslint-plugin-prettier@npm:5.1.3" dependencies: prettier-linter-helpers: ^1.0.0 + synckit: ^0.8.6 peerDependencies: - eslint: ">=7.28.0" - prettier: ">=2.0.0" + "@types/eslint": ">=8.0.0" + eslint: ">=8.0.0" + eslint-config-prettier: "*" + prettier: ">=3.0.0" peerDependenciesMeta: + "@types/eslint": + optional: true eslint-config-prettier: optional: true - checksum: 03d69177a3c21fa2229c7e427ce604429f0b20ab7f411e2e824912f572a207c7f5a41fd1f0a95b9b8afe121e291c1b1f1dc1d44c7aad4b0837487f9c19f5210d + checksum: eb2a7d46a1887e1b93788ee8f8eb81e0b6b2a6f5a66a62bc6f375b033fc4e7ca16448da99380be800042786e76cf5c0df9c87a51a2c9b960ed47acbd7c0b9381 languageName: node linkType: hard @@ -18484,12 +18496,12 @@ __metadata: languageName: node linkType: hard -"prettier@npm:^2.5.1": - version: 2.6.2 - resolution: "prettier@npm:2.6.2" +"prettier@npm:^3.2.5": + version: 3.2.5 + resolution: "prettier@npm:3.2.5" bin: - prettier: bin-prettier.js - checksum: 48d08dde8e9fb1f5bccdd205baa7f192e9fc8bc98f86e1b97d919de804e28c806b0e6cc685e4a88211aa7987fa9668f30baae19580d87ced3ed0f2ec6572106f + prettier: bin/prettier.cjs + checksum: 2ee4e1417572372afb7a13bb446b34f20f1bf1747db77cf6ccaf57a9be005f2f15c40f903d41a6b79eec3f57fff14d32a20fb6dee1f126da48908926fe43c311 languageName: node linkType: hard @@ -20508,13 +20520,13 @@ __metadata: eslint-plugin-header: ^3.1.1 eslint-plugin-import: ^2.25.4 eslint-plugin-jest: ^27.2.3 - eslint-plugin-prettier: ^4.0.0 + eslint-plugin-prettier: ^5.1.3 eslint-plugin-sort-destructure-keys: ^1.4.0 husky: ^7.0.4 jest: ^29.5.0 lint-staged: ^12.3.3 node-fetch: 2.6.7 - prettier: ^2.5.1 + prettier: ^3.2.5 pretty-quick: ^3.1.3 regenerator-runtime: ^0.13.9 ts-jest: ^29.1.1 @@ -20634,6 +20646,16 @@ __metadata: languageName: node linkType: hard +"synckit@npm:^0.8.6": + version: 0.8.8 + resolution: "synckit@npm:0.8.8" + dependencies: + "@pkgr/core": ^0.1.0 + tslib: ^2.6.2 + checksum: 9ed5d33abb785f5f24e2531efd53b2782ca77abf7912f734d170134552b99001915531be5a50297aa45c5701b5c9041e8762e6cd7a38e41e2461c1e7fccdedf8 + languageName: node + linkType: hard + "table-layout@npm:^1.0.2": version: 1.0.2 resolution: "table-layout@npm:1.0.2"