diff --git a/packages/node-core/CHANGELOG.md b/packages/node-core/CHANGELOG.md index 689c2aff23..d150546bbf 100644 --- a/packages/node-core/CHANGELOG.md +++ b/packages/node-core/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - revert yargs version as it was returning a promise +- DS Processor types not being able to distinguish input and filter types (#2522) ## [14.1.0] - 2024-08-05 ### Changed diff --git a/packages/node-core/src/indexer/ds-processor.service.ts b/packages/node-core/src/indexer/ds-processor.service.ts index 99e7b29b29..ad57868c2b 100644 --- a/packages/node-core/src/indexer/ds-processor.service.ts +++ b/packages/node-core/src/indexer/ds-processor.service.ts @@ -5,7 +5,6 @@ import fs from 'fs'; import path from 'path'; import {Inject} from '@nestjs/common'; import { - HandlerInputMap, BaseCustomDataSource, SecondLayerHandlerProcessor_0_0_0, SecondLayerHandlerProcessor_1_0_0, @@ -22,48 +21,51 @@ import {ISubqueryProject} from './types'; const logger = getLogger('ds-sandbox'); function isSecondLayerHandlerProcessor_0_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, API, DS extends BaseCustomDataSource = BaseCustomDataSource >( processor: - | SecondLayerHandlerProcessor_0_0_0 - | SecondLayerHandlerProcessor_1_0_0 -): processor is SecondLayerHandlerProcessor_0_0_0 { + | SecondLayerHandlerProcessor_0_0_0 + | SecondLayerHandlerProcessor_1_0_0 +): processor is SecondLayerHandlerProcessor_0_0_0 { // Exisiting datasource processors had no concept of specVersion, therefore undefined is equivalent to 0.0.0 return processor.specVersion === undefined; } function isSecondLayerHandlerProcessor_1_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, API, DS extends BaseCustomDataSource = BaseCustomDataSource >( processor: - | SecondLayerHandlerProcessor_0_0_0 - | SecondLayerHandlerProcessor_1_0_0 -): processor is SecondLayerHandlerProcessor_1_0_0 { + | SecondLayerHandlerProcessor_0_0_0 + | SecondLayerHandlerProcessor_1_0_0 +): processor is SecondLayerHandlerProcessor_1_0_0 { return processor.specVersion === '1.0.0'; } export function asSecondLayerHandlerProcessor_1_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, API, DS extends BaseCustomDataSource = BaseCustomDataSource >( processor: - | SecondLayerHandlerProcessor_0_0_0 - | SecondLayerHandlerProcessor_1_0_0 -): SecondLayerHandlerProcessor_1_0_0 { + | SecondLayerHandlerProcessor_0_0_0 + | SecondLayerHandlerProcessor_1_0_0 +): SecondLayerHandlerProcessor_1_0_0 { if (isSecondLayerHandlerProcessor_1_0_0(processor)) { return processor; } diff --git a/packages/types-core/CHANGELOG.md b/packages/types-core/CHANGELOG.md index e739372604..6729e67d76 100644 --- a/packages/types-core/CHANGELOG.md +++ b/packages/types-core/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] +### Fixed +- DS Processor types not being able to distinguish input and filter types (#2522) ## [1.1.0] - 2024-08-05 ### Changed diff --git a/packages/types-core/src/project/datasourceProcessors.ts b/packages/types-core/src/project/datasourceProcessors.ts index efc1510a1b..c348b91281 100644 --- a/packages/types-core/src/project/datasourceProcessors.ts +++ b/packages/types-core/src/project/datasourceProcessors.ts @@ -14,70 +14,73 @@ import {BaseCustomDataSource} from './versioned'; export type HandlerInputMap = Record; export interface HandlerInputTransformer_0_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + Input, DS extends BaseCustomDataSource, API, E // Output type > { - (input: IM[K], ds: DS, api: API, assets?: Record): Promise; + (input: Input, ds: DS, api: API, assets?: Record): Promise; } export interface HandlerInputTransformer_1_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + Input, DS extends BaseCustomDataSource, API, F extends Record, E // Output type > { - (params: {input: IM[K]; ds: DS; api: API; filter?: F; assets?: Record}): Promise; + (params: {input: Input; ds: DS; api: API; filter?: F; assets?: Record}): Promise; } interface SecondLayerHandlerProcessorBase< - IM extends HandlerInputMap, - K extends keyof IM, + BaseFilterMap extends HandlerInputMap, + K extends keyof BaseFilterMap, F extends Record, DS extends BaseCustomDataSource > { baseHandlerKind: K; - baseFilter: IM[K] | IM[K][]; + baseFilter: BaseFilterMap[K] | BaseFilterMap[K][]; filterValidator: (filter?: F) => void; dictionaryQuery?: (filter: F, ds: DS) => DictionaryQueryEntry | undefined; } // only allow one custom handler for each baseHandler kind export interface SecondLayerHandlerProcessor_0_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, DS extends BaseCustomDataSource, API -> extends SecondLayerHandlerProcessorBase { +> extends SecondLayerHandlerProcessorBase { specVersion: undefined; - transformer: HandlerInputTransformer_0_0_0; - filterProcessor: (filter: F | undefined, input: IM[K], ds: DS) => boolean; + transformer: HandlerInputTransformer_0_0_0; + filterProcessor: (filter: F | undefined, input: HandlerInput[InputKinds], ds: DS) => boolean; } export interface SecondLayerHandlerProcessor_1_0_0< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, DS extends BaseCustomDataSource, API -> extends SecondLayerHandlerProcessorBase { +> extends SecondLayerHandlerProcessorBase { specVersion: '1.0.0'; - transformer: HandlerInputTransformer_1_0_0; - filterProcessor: (params: {filter: F | undefined; input: IM[K]; ds: DS}) => boolean; + transformer: HandlerInputTransformer_1_0_0; + filterProcessor: (params: {filter: F | undefined; input: HandlerInput[InputKinds]; ds: DS}) => boolean; } export type SecondLayerHandlerProcessor< - IM extends HandlerInputMap, - K extends keyof IM, + InputKinds extends string | symbol, + HandlerInput extends Record, + BaseHandlerFilters extends Record, F extends Record, E, DS extends BaseCustomDataSource, API -> = SecondLayerHandlerProcessor_0_0_0 | SecondLayerHandlerProcessor_1_0_0; +> = + | SecondLayerHandlerProcessor_0_0_0 + | SecondLayerHandlerProcessor_1_0_0; diff --git a/packages/types/CHANGELOG.md b/packages/types/CHANGELOG.md index 80cf0c76d5..ae993954ea 100644 --- a/packages/types/CHANGELOG.md +++ b/packages/types/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] +### Fixed +- DS Processor types not being able to distinguish input and filter types (#2522) ## [3.11.0] - 2024-08-05 ### Changed diff --git a/packages/types/src/project.ts b/packages/types/src/project.ts index 9cbdeb94c6..81d3198656 100644 --- a/packages/types/src/project.ts +++ b/packages/types/src/project.ts @@ -237,7 +237,7 @@ type ISubstrateDatasource = BaseDataSource). */ export interface SubstrateRuntimeDatasource< - M extends SubstrateMapping = SubstrateMapping, + M extends SubstrateMapping = SubstrateMapping > extends ISubstrateDatasource { /** * The kind of the datasource, which is `substrate/Runtime`. @@ -262,7 +262,7 @@ export type SubstrateDatasource = SubstrateRuntimeDatasource | SubstrateCustomDa export interface SubstrateCustomDatasource< K extends string = string, M extends SubstrateMapping = SubstrateMapping, - O = any, + O = any > extends BaseCustomDataSource { /** * The kind of the custom datasource. This should follow the pattern `substrate/*`. @@ -293,8 +293,8 @@ export type HandlerInputTransformer_0_0_0< IM extends RuntimeHandlerInputMap, T extends SubstrateHandlerKind, E, - DS extends SubstrateCustomDatasource = SubstrateCustomDatasource, -> = BaseHandlerInputTransformer_0_0_0; + DS extends SubstrateCustomDatasource = SubstrateCustomDatasource +> = BaseHandlerInputTransformer_0_0_0; /** * @deprecated use types core version. datasource processors need updating before this can be removed @@ -305,14 +305,14 @@ export type HandlerInputTransformer_1_0_0< T extends SubstrateHandlerKind, F extends Record, E, - DS extends SubstrateCustomDatasource = SubstrateCustomDatasource, -> = BaseHandlerInputTransformer_1_0_0; + DS extends SubstrateCustomDatasource = SubstrateCustomDatasource +> = BaseHandlerInputTransformer_1_0_0; export type SecondLayerHandlerProcessorArray< K extends string, F extends Record, T, - DS extends SubstrateCustomDatasource = SubstrateCustomDatasource, + DS extends SubstrateCustomDatasource = SubstrateCustomDatasource > = | SecondLayerHandlerProcessor | SecondLayerHandlerProcessor @@ -328,17 +328,17 @@ export type SubstrateDatasourceProcessor< P extends Record> = Record< string, SecondLayerHandlerProcessorArray - >, + > > = DsProcessor; export type SecondLayerHandlerProcessor< K extends SubstrateHandlerKind, F extends Record, E, - DS extends SubstrateCustomDatasource = SubstrateCustomDatasource, + DS extends SubstrateCustomDatasource = SubstrateCustomDatasource > = - | SecondLayerHandlerProcessor_0_0_0 - | SecondLayerHandlerProcessor_1_0_0; + | SecondLayerHandlerProcessor_0_0_0 + | SecondLayerHandlerProcessor_1_0_0; /** * Represents a Substrate subquery network configuration, which is based on the CommonSubqueryNetworkConfig template.