Skip to content

Commit

Permalink
fix: imports, renamings and natspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Dec 13, 2024
1 parent 6adb666 commit aa3ee27
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 250 deletions.
8 changes: 3 additions & 5 deletions apps/processing/src/services/sharedDependencies.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
CoreDependencies,
InMemoryEventsRegistry,
IStrategyRegistry,
} from "@grants-stack-indexer/data-flow";
import {
DatabaseStrategyRegistry,
IEventsRegistry,
InMemoryCachedStrategyRegistry,
} from "@grants-stack-indexer/data-flow/dist/src/internal.js";
InMemoryEventsRegistry,
IStrategyRegistry,
} from "@grants-stack-indexer/data-flow";
import { EnvioIndexerClient } from "@grants-stack-indexer/indexer-client";
import { IpfsProvider } from "@grants-stack-indexer/metadata";
import { PricingProviderFactory } from "@grants-stack-indexer/pricing";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ vi.mock("@grants-stack-indexer/indexer-client", () => ({
EnvioIndexerClient: vi.fn(),
}));

// Update the mock to handle async initialization
vi.mock("@grants-stack-indexer/data-flow", () => {
const mockStrategyRegistry = {
getStrategies: vi.fn(),
Expand Down
1 change: 0 additions & 1 deletion packages/data-flow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ The `EventsFetcher` class is responsible for fetching events from the blockchain
The `StrategyRegistry` stores strategy IDs to populate strategy events with them given the Strategy address.
There are 3 implementations:

- `InMemoryStrategyRegistry`: stores map in-memory
- `DatabaseStrategyRegistry`: persists data to database using IStrategyRepository
- `InMemoryCachedStrategyRegistry`: stores map in-memory as cache and persists to database

Expand Down
3 changes: 2 additions & 1 deletion packages/data-flow/src/external.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export {
DataLoader,
InMemoryEventsRegistry,
InMemoryStrategyRegistry,
InMemoryCachedStrategyRegistry,
DatabaseStrategyRegistry,
Orchestrator,
} from "./internal.js";

Expand Down
4 changes: 1 addition & 3 deletions packages/data-flow/src/registries/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from "./cachedStrategyRegistry.js";
export * from "./dbStrategyRegistry.js";
export * from "./strategyRegistry.js";
export * from "./strategy/index.js";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Strategy } from "@grants-stack-indexer/repository";
import { Address, ChainId, Hex, ILogger } from "@grants-stack-indexer/shared";

import { IStrategyRegistry } from "../internal.js";
import { IStrategyRegistry } from "../../internal.js";

/**
* Proxy class to cache the strategy ids in memory or fallback to another strategy registry
Expand All @@ -17,10 +17,19 @@ export class InMemoryCachedStrategyRegistry implements IStrategyRegistry {
this.cache = structuredClone(cache);
}

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

/**
* Creates a new cached strategy registry instance. It will load the strategies into memory and cache them and
* fallback to the strategy registry if the strategy is not found in the cache.
*
* @param logger - The logger instance
* @param strategyRegistry - The strategy registry instance
* @returns The initialized cached strategy registry
*/
static async initialize(
logger: ILogger,
strategyRegistry: IStrategyRegistry,
Expand All @@ -40,6 +49,7 @@ export class InMemoryCachedStrategyRegistry implements IStrategyRegistry {
return new InMemoryCachedStrategyRegistry(logger, strategyRegistry, cache);
}

/** @inheritdoc */
async getStrategyId(chainId: ChainId, strategyAddress: Address): Promise<Strategy | undefined> {
const cache = this.cache.get(chainId)?.get(strategyAddress);
if (cache) {
Expand All @@ -53,6 +63,7 @@ export class InMemoryCachedStrategyRegistry implements IStrategyRegistry {
return strategy;
}

/** @inheritdoc */
async saveStrategyId(
chainId: ChainId,
strategyAddress: Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Address, Hex } from "viem";
import { IStrategyRepository, Strategy } from "@grants-stack-indexer/repository";
import { ChainId, ILogger } from "@grants-stack-indexer/shared";

import { IStrategyRegistry } from "../internal.js";
import { IStrategyRegistry } from "../../internal.js";

/**
* Class to store strategy ids in Database
Expand Down
2 changes: 2 additions & 0 deletions packages/data-flow/src/registries/strategy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./cachedStrategyRegistry.js";
export * from "./dbStrategyRegistry.js";
58 changes: 0 additions & 58 deletions packages/data-flow/src/registries/strategyRegistry.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Strategy } from "@grants-stack-indexer/repository";
import { ChainId, ILogger } from "@grants-stack-indexer/shared";

import { IStrategyRegistry } from "../../src/internal.js";
import { InMemoryCachedStrategyRegistry } from "../../src/registries/cachedStrategyRegistry.js";
import { InMemoryCachedStrategyRegistry } from "../../src/registries/strategy/cachedStrategyRegistry.js";

describe("InMemoryCachedStrategyRegistry", () => {
const logger: ILogger = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, expect, it, vi } from "vitest";
import { IStrategyRepository, Strategy } from "@grants-stack-indexer/repository";
import { ChainId, ILogger } from "@grants-stack-indexer/shared";

import { DatabaseStrategyRegistry } from "../../src/registries/dbStrategyRegistry.js";
import { DatabaseStrategyRegistry } from "../../src/registries/strategy/dbStrategyRegistry.js";

describe("DatabaseStrategyRegistry", () => {
const logger: ILogger = {
Expand Down
171 changes: 0 additions & 171 deletions packages/data-flow/test/registries/strategyRegistry.spec.ts

This file was deleted.

19 changes: 19 additions & 0 deletions packages/repository/src/interfaces/strategyRepository.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@ import { Address, ChainId } from "@grants-stack-indexer/shared";
import { Strategy } from "../internal.js";

export interface IStrategyRepository {
/**
* Retrieves a strategy by its chain ID and address.
* @param chainId - The chain ID of the strategy.
* @param strategyAddress - The address of the strategy.
* @returns A promise that resolves to the strategy object or undefined if not found.
*/
getStrategyByChainIdAndAddress(
chainId: ChainId,
strategyAddress: Address,
): Promise<Strategy | undefined>;

/**
* Saves a strategy to the repository.
* @param strategy - The strategy to save.
*/
saveStrategy(strategy: Strategy): Promise<void>;

/**
* 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.
* @returns A promise that resolves to an array of strategies.
*/
getStrategies(params?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]>;
}
Loading

0 comments on commit aa3ee27

Please sign in to comment.