Move event watcher to util (#262)

This commit is contained in:
prathamesh0
2022-11-25 17:19:37 +05:30
committed by GitHub
parent e47aab2ed7
commit 94c8ed9575
89 changed files with 111 additions and 590 deletions
+1 -1
View File
@@ -10,7 +10,6 @@
"copy-assets": "copyfiles -u 1 src/**/*.gql dist/"
},
"dependencies": {
"@cerc-io/ipld-eth-client": "^0.2.16",
"@cerc-io/util": "^0.2.16",
"@ethersproject/providers": "^5.4.4",
"@graphql-tools/utils": "^9.1.1",
@@ -24,6 +23,7 @@
"yargs": "^17.0.1"
},
"devDependencies": {
"@types/express": "^4.17.14",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint-config-semistandard": "^15.0.1",
+5 -13
View File
@@ -17,10 +17,9 @@ import {
IndexerInterface,
ServerConfig,
Clients,
EventWatcherInterface,
EventWatcher,
GraphWatcherInterface
} from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
export class BaseCmd {
_config?: Config;
@@ -29,7 +28,7 @@ export class BaseCmd {
_jobQueue?: JobQueue
_database?: DatabaseInterface;
_indexer?: IndexerInterface;
_eventWatcher?: EventWatcherInterface;
_eventWatcher?: EventWatcher;
get config (): Config | undefined {
return this._config;
@@ -55,7 +54,7 @@ export class BaseCmd {
return this._indexer;
}
get eventWatcher (): EventWatcherInterface | undefined {
get eventWatcher (): EventWatcher | undefined {
return this._eventWatcher;
}
@@ -103,7 +102,7 @@ export class BaseCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
assert(this._config);
assert(this._database);
assert(this._clients);
@@ -119,14 +118,7 @@ export class BaseCmd {
}
}
async initEventWatcher (
EventWatcher: new(
ethClient: EthClient,
indexer: IndexerInterface,
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface
): Promise<void> {
async initEventWatcher (): Promise<void> {
assert(this._clients?.ethClient);
assert(this._indexer);
assert(this._jobQueue);
+1 -1
View File
@@ -80,7 +80,7 @@ export class CreateCheckpointCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+1 -1
View File
@@ -81,7 +81,7 @@ export class VerifyCheckpointCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+1 -1
View File
@@ -87,7 +87,7 @@ export class ExportStateCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+2 -15
View File
@@ -8,7 +8,6 @@ import debug from 'debug';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import { JsonRpcProvider } from '@ethersproject/providers';
import {
@@ -19,12 +18,10 @@ import {
IndexerInterface,
ServerConfig,
Clients,
EventWatcherInterface,
fillBlocks,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { BaseCmd } from './base';
@@ -63,10 +60,6 @@ export class FillCmd {
return this._baseCmd.database;
}
get indexer (): IndexerInterface | undefined {
return this._baseCmd.indexer;
}
async initConfig<ConfigType> (): Promise<ConfigType> {
this._argv = this._getArgv();
assert(this._argv);
@@ -95,16 +88,10 @@ export class FillCmd {
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
indexer: IndexerInterface,
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
await this._baseCmd.initEventWatcher();
}
async exec (contractEntitiesMap: Map<string, string[]> = new Map()): Promise<void> {
+2 -11
View File
@@ -9,10 +9,8 @@ import path from 'path';
import fs from 'fs';
import debug from 'debug';
import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import { JsonRpcProvider } from '@ethersproject/providers';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
@@ -20,7 +18,6 @@ import {
IndexerInterface,
ServerConfig,
Clients,
EventWatcherInterface,
fillBlocks,
StateKind,
GraphWatcherInterface,
@@ -91,16 +88,10 @@ export class ImportStateCmd {
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
indexer: IndexerInterface,
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
await this._baseCmd.initEventWatcher();
}
async exec (State: new() => any, graphDb?: GraphDatabase): Promise<void> {
+1 -1
View File
@@ -80,7 +80,7 @@ export class IndexBlockCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+1 -1
View File
@@ -83,7 +83,7 @@ export class InspectCIDCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+1 -1
View File
@@ -89,7 +89,7 @@ export class JobRunnerCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+1 -1
View File
@@ -79,7 +79,7 @@ export class ResetWatcherCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}
+4 -12
View File
@@ -7,12 +7,10 @@ import { hideBin } from 'yargs/helpers';
import 'reflect-metadata';
import assert from 'assert';
import { ConnectionOptions } from 'typeorm';
import { PubSub } from 'graphql-subscriptions';
import express, { Application } from 'express';
import { ApolloServer } from 'apollo-server-express';
import { JsonRpcProvider } from '@ethersproject/providers';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
DEFAULT_CONFIG_PATH,
JobQueue,
@@ -20,10 +18,10 @@ import {
IndexerInterface,
ServerConfig,
Clients,
EventWatcherInterface,
KIND_ACTIVE,
createAndStartServer,
startGQLMetricsServer,
EventWatcher,
GraphWatcherInterface,
Config
} from '@cerc-io/util';
@@ -87,20 +85,14 @@ export class ServerCmd {
jobQueue: JobQueue,
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
EventWatcher: new(
ethClient: EthClient,
indexer: IndexerInterface,
pubsub: PubSub,
jobQueue: JobQueue
) => EventWatcherInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
await this._baseCmd.initIndexer(Indexer, graphWatcher);
await this._baseCmd.initEventWatcher(EventWatcher);
await this._baseCmd.initEventWatcher();
}
async exec (
createResolvers: (indexer: IndexerInterface, eventWatcher: EventWatcherInterface) => Promise<any>,
createResolvers: (indexer: IndexerInterface, eventWatcher: EventWatcher) => Promise<any>,
typeDefs: TypeSource
): Promise<{
app: Application,
+1 -1
View File
@@ -82,7 +82,7 @@ export class WatchContractCmd {
graphWatcher?: GraphWatcherInterface
) => IndexerInterface,
graphWatcher?: GraphWatcherInterface
) {
): Promise<void> {
return this._baseCmd.initIndexer(Indexer, graphWatcher);
}