From fe62481ed3ce1ac2d5abcd8d897a552977a2c6bf Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Fri, 13 Dec 2024 19:13:33 -0300 Subject: [PATCH] fix: rename class and argument --- .../src/services/sharedDependencies.service.ts | 4 ++-- .../src/interfaces/strategyRegistry.interface.ts | 2 +- .../registries/strategy/cachedStrategyRegistry.ts | 4 ++-- .../src/registries/strategy/dbStrategyRegistry.ts | 8 ++++---- .../test/registries/dbStrategyRegistry.spec.ts | 4 ++-- packages/repository/src/external.ts | 4 ++-- .../interfaces/strategyRepository.interface.ts | 10 +++++----- .../repository/src/repositories/kysely/index.ts | 2 +- ...pository.ts => strategyRegistry.repository.ts} | 15 ++++++++------- 9 files changed, 27 insertions(+), 26 deletions(-) rename packages/repository/src/repositories/kysely/{strategy.repository.ts => strategyRegistry.repository.ts} (72%) diff --git a/apps/processing/src/services/sharedDependencies.service.ts b/apps/processing/src/services/sharedDependencies.service.ts index 92a9eba..b2e05ae 100644 --- a/apps/processing/src/services/sharedDependencies.service.ts +++ b/apps/processing/src/services/sharedDependencies.service.ts @@ -16,7 +16,7 @@ import { KyselyDonationRepository, KyselyProjectRepository, KyselyRoundRepository, - KyselyStrategyRepository, + KyselyStrategyRegistryRepository, } from "@grants-stack-indexer/repository"; import { Logger } from "@grants-stack-indexer/shared"; @@ -72,7 +72,7 @@ export class SharedDependenciesService { const eventsRegistry = new InMemoryEventsRegistry( new Logger({ className: "InMemoryEventsRegistry" }), ); - const strategyRepository = new KyselyStrategyRepository( + const strategyRepository = new KyselyStrategyRegistryRepository( kyselyDatabase, env.DATABASE_SCHEMA, ); diff --git a/packages/data-flow/src/interfaces/strategyRegistry.interface.ts b/packages/data-flow/src/interfaces/strategyRegistry.interface.ts index cb187c3..965ad44 100644 --- a/packages/data-flow/src/interfaces/strategyRegistry.interface.ts +++ b/packages/data-flow/src/interfaces/strategyRegistry.interface.ts @@ -34,5 +34,5 @@ export interface IStrategyRegistry { * Get all the strategies * @returns The strategies */ - getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise; + getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise; } diff --git a/packages/data-flow/src/registries/strategy/cachedStrategyRegistry.ts b/packages/data-flow/src/registries/strategy/cachedStrategyRegistry.ts index c89c9f9..16899cc 100644 --- a/packages/data-flow/src/registries/strategy/cachedStrategyRegistry.ts +++ b/packages/data-flow/src/registries/strategy/cachedStrategyRegistry.ts @@ -18,8 +18,8 @@ export class InMemoryCachedStrategyRegistry implements IStrategyRegistry { } /** @inheritdoc */ - async getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise { - return this.strategyRegistry.getStrategies(params); + async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise { + return this.strategyRegistry.getStrategies(filters); } /** diff --git a/packages/data-flow/src/registries/strategy/dbStrategyRegistry.ts b/packages/data-flow/src/registries/strategy/dbStrategyRegistry.ts index 5dcfe50..e29fa3f 100644 --- a/packages/data-flow/src/registries/strategy/dbStrategyRegistry.ts +++ b/packages/data-flow/src/registries/strategy/dbStrategyRegistry.ts @@ -1,6 +1,6 @@ import type { Address, Hex } from "viem"; -import { IStrategyRepository, Strategy } from "@grants-stack-indexer/repository"; +import { IStrategyRegistryRepository, Strategy } from "@grants-stack-indexer/repository"; import { ChainId, ILogger } from "@grants-stack-indexer/shared"; import { IStrategyRegistry } from "../../internal.js"; @@ -11,12 +11,12 @@ import { IStrategyRegistry } from "../../internal.js"; export class DatabaseStrategyRegistry implements IStrategyRegistry { constructor( private logger: ILogger, - private strategyRepository: IStrategyRepository, + private strategyRepository: IStrategyRegistryRepository, ) {} /** @inheritdoc */ - async getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise { - return this.strategyRepository.getStrategies(params); + async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise { + return this.strategyRepository.getStrategies(filters); } /** @inheritdoc */ diff --git a/packages/data-flow/test/registries/dbStrategyRegistry.spec.ts b/packages/data-flow/test/registries/dbStrategyRegistry.spec.ts index c80fa93..1974cdb 100644 --- a/packages/data-flow/test/registries/dbStrategyRegistry.spec.ts +++ b/packages/data-flow/test/registries/dbStrategyRegistry.spec.ts @@ -1,7 +1,7 @@ import { Address, Hex } from "viem"; import { describe, expect, it, vi } from "vitest"; -import { IStrategyRepository, Strategy } from "@grants-stack-indexer/repository"; +import { IStrategyRegistryRepository, Strategy } from "@grants-stack-indexer/repository"; import { ChainId, ILogger } from "@grants-stack-indexer/shared"; import { DatabaseStrategyRegistry } from "../../src/registries/strategy/dbStrategyRegistry.js"; @@ -14,7 +14,7 @@ describe("DatabaseStrategyRegistry", () => { warn: vi.fn(), }; - const mockStrategyRepository: IStrategyRepository = { + const mockStrategyRepository: IStrategyRegistryRepository = { getStrategies: vi.fn(), getStrategyByChainIdAndAddress: vi.fn(), saveStrategy: vi.fn(), diff --git a/packages/repository/src/external.ts b/packages/repository/src/external.ts index b8f9d36..fec981b 100644 --- a/packages/repository/src/external.ts +++ b/packages/repository/src/external.ts @@ -8,7 +8,7 @@ export type { IApplicationReadRepository, IDonationRepository, IApplicationPayoutRepository, - IStrategyRepository, + IStrategyRegistryRepository, DatabaseConfig, } from "./internal.js"; @@ -53,7 +53,7 @@ export { KyselyApplicationRepository, KyselyDonationRepository, KyselyApplicationPayoutRepository, - KyselyStrategyRepository, + KyselyStrategyRegistryRepository, } from "./repositories/kysely/index.js"; export { diff --git a/packages/repository/src/interfaces/strategyRepository.interface.ts b/packages/repository/src/interfaces/strategyRepository.interface.ts index b9aa195..c58d344 100644 --- a/packages/repository/src/interfaces/strategyRepository.interface.ts +++ b/packages/repository/src/interfaces/strategyRepository.interface.ts @@ -2,7 +2,7 @@ import { Address, ChainId } from "@grants-stack-indexer/shared"; import { Strategy } from "../internal.js"; -export interface IStrategyRepository { +export interface IStrategyRegistryRepository { /** * Retrieves a strategy by its chain ID and address. * @param chainId - The chain ID of the strategy. @@ -22,10 +22,10 @@ export interface IStrategyRepository { /** * Retrieves all strategies from the repository. - * @param params - The parameters to filter the strategies. - * @param params.handled - Whether to include handled strategies. - * @param params.chainId - The chain ID to filter the strategies. + * @param filters - The parameters to filter the strategies. + * @param filters.handled - Whether to include handled strategies. + * @param filters.chainId - The chain ID to filter the strategies. * @returns A promise that resolves to an array of strategies. */ - getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise; + getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise; } diff --git a/packages/repository/src/repositories/kysely/index.ts b/packages/repository/src/repositories/kysely/index.ts index 5d79682..ae4143a 100644 --- a/packages/repository/src/repositories/kysely/index.ts +++ b/packages/repository/src/repositories/kysely/index.ts @@ -3,4 +3,4 @@ export * from "./round.repository.js"; export * from "./application.repository.js"; export * from "./donation.repository.js"; export * from "./applicationPayout.repository.js"; -export * from "./strategy.repository.js"; +export * from "./strategyRegistry.repository.js"; diff --git a/packages/repository/src/repositories/kysely/strategy.repository.ts b/packages/repository/src/repositories/kysely/strategyRegistry.repository.ts similarity index 72% rename from packages/repository/src/repositories/kysely/strategy.repository.ts rename to packages/repository/src/repositories/kysely/strategyRegistry.repository.ts index d8a6124..a251f42 100644 --- a/packages/repository/src/repositories/kysely/strategy.repository.ts +++ b/packages/repository/src/repositories/kysely/strategyRegistry.repository.ts @@ -2,10 +2,10 @@ import { Kysely } from "kysely"; import { Address, ChainId } from "@grants-stack-indexer/shared"; -import { IStrategyRepository } from "../../interfaces/index.js"; +import { IStrategyRegistryRepository } from "../../interfaces/index.js"; import { Database, Strategy } from "../../internal.js"; -export class KyselyStrategyRepository implements IStrategyRepository { +export class KyselyStrategyRegistryRepository implements IStrategyRegistryRepository { constructor( private readonly db: Kysely, private readonly schemaName: string, @@ -35,15 +35,16 @@ export class KyselyStrategyRepository implements IStrategyRepository { .execute(); } - async getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise { + /** @inheritdoc */ + async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise { const query = this.db.withSchema(this.schemaName).selectFrom("strategies"); - if (params?.chainId) { - query.where("chainId", "=", params.chainId); + if (filters?.chainId) { + query.where("chainId", "=", filters.chainId); } - if (params?.handled) { - query.where("handled", "=", params.handled); + if (filters?.handled) { + query.where("handled", "=", filters.handled); } return query.selectAll().execute();