From 5d71d1396877e46a850115126a80a6c9a517f480 Mon Sep 17 00:00:00 2001 From: yoozo Date: Wed, 25 Sep 2024 05:40:23 +0800 Subject: [PATCH] runner query support `@subql/query-subgraph` option (#2561) --- packages/common/CHANGELOG.md | 3 ++ .../project/versioned/v1_0_0/model.spec.ts | 49 ++++++++++++++++++- .../src/project/versioned/v1_0_0/models.ts | 3 +- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/common/CHANGELOG.md b/packages/common/CHANGELOG.md index 6b4ab7326c..6e9fee6861 100644 --- a/packages/common/CHANGELOG.md +++ b/packages/common/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- `Runner.query` support `@subql/query-subgraph` option + ## [5.1.2] - 2024-09-09 ### Changed - Expose CID on IPFS Reader (#2551) diff --git a/packages/common/src/project/versioned/v1_0_0/model.spec.ts b/packages/common/src/project/versioned/v1_0_0/model.spec.ts index 7988d20fdd..d0bfb2440c 100644 --- a/packages/common/src/project/versioned/v1_0_0/model.spec.ts +++ b/packages/common/src/project/versioned/v1_0_0/model.spec.ts @@ -4,7 +4,7 @@ import {IProjectNetworkConfig} from '@subql/types-core'; import {plainToClass} from 'class-transformer'; import {validateSync} from 'class-validator'; -import {CommonProjectNetworkV1_0_0} from './models'; +import {CommonProjectNetworkV1_0_0, CommonRunnerSpecsImpl} from './models'; describe('Validating base v1_0_0 model', () => { it('correctly validates the various endpoint structures in a network config', () => { @@ -72,4 +72,51 @@ describe('Validating base v1_0_0 model', () => { expect(() => validate(bad3)).toThrow(); expect(() => validate(bad4)).toThrow(); }); + + it('validates manifest Runner', () => { + function validate(raw: unknown) { + const projectManifest = plainToClass(CommonRunnerSpecsImpl, raw); + const errors = validateSync(projectManifest, {whitelist: true}); + + if (errors.length) { + throw new Error(errors.map((e) => e.value).join('\n')); + } + } + + const normalRunner: unknown = { + node: { + name: '@subql/node', + version: '>=3.0.1', + }, + query: { + name: '@subql/query', + version: '*', + }, + }; + + const notExistQueryRunner: unknown = { + node: { + name: '@subql/node', + version: '>=3.0.1', + }, + query: { + name: '@subql/not-exist', + version: '*', + }, + }; + const subgraphQueryRunner: unknown = { + node: { + name: '@subql/node', + version: '>=3.0.1', + }, + query: { + name: '@subql/query-subgraph', + version: '*', + }, + }; + + expect(() => validate(normalRunner)).not.toThrow(); + expect(() => validate(notExistQueryRunner)).toThrow(); + expect(() => validate(subgraphQueryRunner)).not.toThrow(); + }); }); diff --git a/packages/common/src/project/versioned/v1_0_0/models.ts b/packages/common/src/project/versioned/v1_0_0/models.ts index 04895b8bbb..a8ac659917 100644 --- a/packages/common/src/project/versioned/v1_0_0/models.ts +++ b/packages/common/src/project/versioned/v1_0_0/models.ts @@ -28,12 +28,13 @@ import { Allow, ValidateIf, IsPositive, + IsIn, } from 'class-validator'; import {IsNetworkEndpoint, SemverVersionValidator} from '../../utils'; import {FileType} from '../base'; export class RunnerQueryBaseModel implements QuerySpec { - @Equals('@subql/query') + @IsIn(['@subql/query', '@subql/query-subgraph']) name!: string; @IsString() @Validate(SemverVersionValidator)