Skip to content

Commit

Permalink
fix: rename class and argument
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Dec 13, 2024
1 parent aa3ee27 commit fe62481
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions apps/processing/src/services/sharedDependencies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
KyselyDonationRepository,
KyselyProjectRepository,
KyselyRoundRepository,
KyselyStrategyRepository,
KyselyStrategyRegistryRepository,
} from "@grants-stack-indexer/repository";
import { Logger } from "@grants-stack-indexer/shared";

Expand Down Expand Up @@ -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,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export interface IStrategyRegistry {
* Get all the strategies
* @returns The strategies
*/
getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]>;
getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export class InMemoryCachedStrategyRegistry implements IStrategyRegistry {
}

/** @inheritdoc */
async getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]> {
return this.strategyRegistry.getStrategies(params);
async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]> {
return this.strategyRegistry.getStrategies(filters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<Strategy[]> {
return this.strategyRepository.getStrategies(params);
async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]> {
return this.strategyRepository.getStrategies(filters);
}

/** @inheritdoc */
Expand Down
4 changes: 2 additions & 2 deletions packages/data-flow/test/registries/dbStrategyRegistry.spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -14,7 +14,7 @@ describe("DatabaseStrategyRegistry", () => {
warn: vi.fn(),
};

const mockStrategyRepository: IStrategyRepository = {
const mockStrategyRepository: IStrategyRegistryRepository = {
getStrategies: vi.fn(),
getStrategyByChainIdAndAddress: vi.fn(),
saveStrategy: vi.fn(),
Expand Down
4 changes: 2 additions & 2 deletions packages/repository/src/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type {
IApplicationReadRepository,
IDonationRepository,
IApplicationPayoutRepository,
IStrategyRepository,
IStrategyRegistryRepository,
DatabaseConfig,
} from "./internal.js";

Expand Down Expand Up @@ -53,7 +53,7 @@ export {
KyselyApplicationRepository,
KyselyDonationRepository,
KyselyApplicationPayoutRepository,
KyselyStrategyRepository,
KyselyStrategyRegistryRepository,
} from "./repositories/kysely/index.js";

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<Strategy[]>;
getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]>;
}
2 changes: 1 addition & 1 deletion packages/repository/src/repositories/kysely/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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<Database>,
private readonly schemaName: string,
Expand Down Expand Up @@ -35,15 +35,16 @@ export class KyselyStrategyRepository implements IStrategyRepository {
.execute();
}

async getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]> {
/** @inheritdoc */
async getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]> {
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();
Expand Down

0 comments on commit fe62481

Please sign in to comment.