Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor const, enum, interface & dto definitions to a common component #510

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: graph compile
  • Loading branch information
JoeCap08055 committed Sep 16, 2024
commit 9226005cf05c662b6b21a242e23ae1d19899bf6e
2 changes: 1 addition & 1 deletion apps/graph-api/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ExpressAdapter } from '@bull-board/express';
import { GraphControllerV1 } from './controllers/v1/graph-v1.controller';
import { HealthController } from './controllers/health.controller';
import { ApiService } from './api.service';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import * as QueueConstants from '#types/constants/queue.constants';
import { WebhooksControllerV1 } from './controllers/v1/webhooks-v1.controller';
import { QueueModule } from '#graph-lib/queues/queue.module';
import { ConfigModule, ConfigService } from '#graph-lib/config';
Expand Down
11 changes: 6 additions & 5 deletions apps/graph-api/src/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Redis from 'ioredis';
import { InjectQueue } from '@nestjs/bullmq';
import { Queue } from 'bullmq';
import { createHash } from 'crypto';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import * as QueueConstants from '#types/constants/queue.constants';
import * as RedisConstants from '#graph-lib/utils/redis';
import { ConfigService } from '#graph-lib/config';
import { BlockchainService } from '#graph-lib/blockchain';
Expand All @@ -14,10 +14,11 @@ import {
WatchGraphsDto,
GraphsQueryParamsDto,
UserGraphDto,
} from '#graph-lib/dtos';
import { ProviderGraphUpdateJob } from '#graph-lib/interfaces';
} from '#types/dtos/graph';
import { ProviderGraphUpdateJob } from '#types/interfaces/graph';
import { AsyncDebouncerService } from '#graph-lib/services/async_debouncer';
import { GraphStateManager } from '#graph-lib/services/graph-state-manager';
import { DEBOUNCER_CACHE_KEY, LAST_PROCESSED_DSNP_ID_KEY } from '#types/constants';

async function hscanToObject(keyValues: string[]) {
const result = {};
Expand Down Expand Up @@ -49,8 +50,8 @@ export class ApiService implements BeforeApplicationShutdown {

beforeApplicationShutdown(_signal?: string | undefined) {
try {
this.redis.del(QueueConstants.DEBOUNCER_CACHE_KEY);
this.redis.del(QueueConstants.LAST_PROCESSED_DSNP_ID_KEY);
this.redis.del(DEBOUNCER_CACHE_KEY);
this.redis.del(LAST_PROCESSED_DSNP_ID_KEY);
this.logger.log('Cleanup on shutdown completed.');
} catch (e) {
this.logger.error(`Error during cleanup on shutdown: ${e}`);
Expand Down
2 changes: 1 addition & 1 deletion apps/graph-api/src/controllers/v1/graph-v1.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiService } from '#graph-api/api.service';
import { ReadOnlyGuard } from '#graph-api/guards/read-only.guard';
import { UserGraphDto, GraphsQueryParamsDto, GraphChangeRepsonseDto, ProviderGraphDto } from '#graph-lib/dtos';
import { UserGraphDto, GraphsQueryParamsDto, GraphChangeRepsonseDto, ProviderGraphDto } from '#types/dtos/graph';
import { Controller, Post, HttpCode, HttpStatus, Logger, Body, Put, UseGuards } from '@nestjs/common';
import { ApiBody, ApiCreatedResponse, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiService } from '#graph-api/api.service';
import { WatchGraphsDto } from '#graph-lib/dtos';
import { WatchGraphsDto } from '#types/dtos/graph';
import {
Controller,
HttpCode,
Expand Down
16 changes: 3 additions & 13 deletions apps/graph-api/src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
/* eslint-disable */
export default async () => {
const t = {
["../../../libs/graph-lib/src/dtos/privacy-type.enum"]: await import("../../../libs/graph-lib/src/dtos/privacy-type.enum"),
["../../../libs/graph-lib/src/dtos/direction.enum"]: await import("../../../libs/graph-lib/src/dtos/direction.enum"),
["../../../libs/graph-lib/src/dtos/connection-type.enum"]: await import("../../../libs/graph-lib/src/dtos/connection-type.enum"),
["../../../libs/graph-lib/src/dtos/connection.dto"]: await import("../../../libs/graph-lib/src/dtos/connection.dto"),
["../../../libs/graph-lib/src/dtos/key-type.enum"]: await import("../../../libs/graph-lib/src/dtos/key-type.enum"),
["../../../libs/graph-lib/src/dtos/graph-key-pair.dto"]: await import("../../../libs/graph-lib/src/dtos/graph-key-pair.dto"),
["../../../libs/graph-lib/src/dtos/dsnp-graph-edge.dto"]: await import("../../../libs/graph-lib/src/dtos/dsnp-graph-edge.dto"),
["../../../libs/graph-lib/src/dtos/user-graph.dto"]: await import("../../../libs/graph-lib/src/dtos/user-graph.dto"),
["../../../libs/graph-lib/src/dtos/graph-change-response.dto"]: await import("../../../libs/graph-lib/src/dtos/graph-change-response.dto")
};
return { "@nestjs/swagger": { "models": [[import("../../../libs/graph-lib/src/dtos/connection.dto"), { "ConnectionDto": { dsnpId: { required: true, type: () => String }, privacyType: { required: true, enum: t["../../../libs/graph-lib/src/dtos/privacy-type.enum"].PrivacyType }, direction: { required: true, enum: t["../../../libs/graph-lib/src/dtos/direction.enum"].Direction }, connectionType: { required: true, enum: t["../../../libs/graph-lib/src/dtos/connection-type.enum"].ConnectionType } }, "ConnectionDtoWrapper": { data: { required: true, type: () => [t["../../../libs/graph-lib/src/dtos/connection.dto"].ConnectionDto] } } }], [import("../../../libs/graph-lib/src/dtos/dsnp-graph-edge.dto"), { "DsnpGraphEdgeDto": { userId: { required: true, type: () => String }, since: { required: true, type: () => Number } } }], [import("../../../libs/graph-lib/src/dtos/graph-change-response.dto"), { "GraphChangeRepsonseDto": { referenceId: { required: true, type: () => String } } }], [import("../../../libs/graph-lib/src/dtos/graph-key-pair.dto"), { "GraphKeyPairDto": { publicKey: { required: true, type: () => String }, privateKey: { required: true, type: () => String }, keyType: { required: true, type: () => String, enum: t["../../../libs/graph-lib/src/dtos/key-type.enum"].KeyType } } }], [import("../../../libs/graph-lib/src/dtos/graph-query-params.dto"), { "GraphsQueryParamsDto": { dsnpIds: { required: true, type: () => [String] }, privacyType: { required: true, enum: t["../../../libs/graph-lib/src/dtos/privacy-type.enum"].PrivacyType }, graphKeyPairs: { required: false, type: () => [t["../../../libs/graph-lib/src/dtos/graph-key-pair.dto"].GraphKeyPairDto] } } }], [import("../../../libs/graph-lib/src/dtos/provider-graph.dto"), { "ProviderGraphDto": { dsnpId: { required: true, type: () => String }, connections: { required: true, type: () => ({ data: { required: true, type: () => [t["../../../libs/graph-lib/src/dtos/connection.dto"].ConnectionDto] } }) }, graphKeyPairs: { required: false, type: () => [t["../../../libs/graph-lib/src/dtos/graph-key-pair.dto"].GraphKeyPairDto] }, webhookUrl: { required: false, type: () => String } } }], [import("../../../libs/graph-lib/src/dtos/user-graph.dto"), { "UserGraphDto": { dsnpId: { required: true, type: () => String }, dsnpGraphEdges: { required: false, type: () => [t["../../../libs/graph-lib/src/dtos/dsnp-graph-edge.dto"].DsnpGraphEdgeDto] } } }], [import("../../../libs/graph-lib/src/dtos/watch-graphs.dto"), { "WatchGraphsDto": { dsnpIds: { required: false, type: () => [String] }, webhookEndpoint: { required: true, type: () => String } } }]], "controllers": [[import("./controllers/v1/graph-v1.controller"), { "GraphControllerV1": { "getGraphs": { type: [t["../../../libs/graph-lib/src/dtos/user-graph.dto"].UserGraphDto] }, "updateGraph": { type: t["../../../libs/graph-lib/src/dtos/graph-change-response.dto"].GraphChangeRepsonseDto } } }], [import("./controllers/health.controller"), { "HealthController": { "healthz": {}, "livez": {}, "readyz": {} } }], [import("./controllers/v1/webhooks-v1.controller"), { "WebhooksControllerV1": { "getAllWebhooks": { type: Object }, "getWebhooksForMsa": { type: [String] }, "getWebhooksForUrl": { type: [String] }, "watchGraphs": {}, "deleteAllWebhooks": {}, "deleteWebhooksForMsa": {}, "deleteAllWebhooksForUrl": {} } }]] } };
};
const t = {};
return { "@nestjs/swagger": { "models": [] } };
};
2 changes: 1 addition & 1 deletion apps/graph-api/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ProviderGraphDto,
Direction,
ConnectionDto,
} from '#graph-lib/dtos';
} from '#types/dtos/graph';

let app: INestApplication;
let testModule: TestingModule;
Expand Down
18 changes: 10 additions & 8 deletions apps/graph-worker/src/graph_notifier/graph.monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import { SchedulerRegistry } from '@nestjs/schedule';
import { SignedBlock } from '@polkadot/types/interfaces';
import { FrameSystemEventRecord, PalletSchemasSchemaVersionId } from '@polkadot/types/lookup';
import { HexString } from '@polkadot/util/types';
import { ITxStatus } from '#graph-lib/interfaces/tx-status.interface';
import { IGraphTxStatus } from '#types/interfaces';
import { CapacityCheckerService } from '#graph-lib/blockchain/capacity-checker.service';
import * as RedisConstants from '#graph-lib/utils/redis';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import * as QueueConstants from '#types/constants/queue.constants';
import * as GraphServiceWebhook from '#graph-lib/types/webhook-types';
import axios from 'axios';
import { ProviderGraphUpdateJob, createReconnectionJob, UpdateTransitiveGraphs } from '#graph-lib/interfaces';
import { SECONDS_PER_BLOCK, TXN_WATCH_LIST_KEY } from '#graph-lib/types/constants';
import { ProviderGraphUpdateJob, createReconnectionJob, UpdateTransitiveGraphs } from '#types/interfaces/graph';
import { SECONDS_PER_BLOCK, TXN_WATCH_LIST_KEY } from '#types/constants';

type GraphChangeNotification = GraphServiceWebhook.Components.Schemas.GraphChangeNotificationV1;
type GraphOperationStatus = GraphServiceWebhook.Components.Schemas.GraphOperationStatusV1;
type StatusUpdate = ITxStatus & GraphOperationStatus;
type StatusUpdate = IGraphTxStatus & GraphOperationStatus;

@Injectable()
export class GraphMonitorService extends BlockchainScannerService {
Expand All @@ -50,7 +50,7 @@ export class GraphMonitorService extends BlockchainScannerService {
const minBirthBlock = Math.min(
...Object.values(pendingTxns)
.map((jsonStr) => {
const txStatus = JSON.parse(jsonStr) as ITxStatus;
const txStatus = JSON.parse(jsonStr) as IGraphTxStatus;
return txStatus.birth;
})
.sort((a, b) => a - b),
Expand Down Expand Up @@ -112,7 +112,9 @@ export class GraphMonitorService extends BlockchainScannerService {
const currentBlockNumber = currentBlock.block.header.number.toNumber();

// Get set of tx hashes to monitor from cache
const pendingTxns = (await this.cacheManager.hvals(TXN_WATCH_LIST_KEY)).map((val) => JSON.parse(val) as ITxStatus);
const pendingTxns = (await this.cacheManager.hvals(TXN_WATCH_LIST_KEY)).map(
(val) => JSON.parse(val) as IGraphTxStatus,
);

const extrinsicIndices: [HexString, number][] = [];
currentBlock.block.extrinsics.forEach((extrinsic, index) => {
Expand Down Expand Up @@ -146,7 +148,7 @@ export class GraphMonitorService extends BlockchainScannerService {
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const txStatusStr = (await this.cacheManager.hget(TXN_WATCH_LIST_KEY, txHash))!;
const txStatus = JSON.parse(txStatusStr) as ITxStatus;
const txStatus = JSON.parse(txStatusStr) as IGraphTxStatus;
const successEvent = extrinsicEvents.find(
({ event }) =>
event.section === txStatus.successEvent.section && event.method === txStatus.successEvent.method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { SubmittableExtrinsic } from '@polkadot/api-base/types';
import { ISubmittableResult } from '@polkadot/types/types';
import { MILLISECONDS_PER_SECOND } from 'time-constants';
import { SchedulerRegistry } from '@nestjs/schedule';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import * as QueueConstants from '#types/constants/queue.constants';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { ITxStatus } from '#graph-lib/interfaces/tx-status.interface';
import { IGraphTxStatus } from '#types/interfaces';
import { ConfigService } from '#graph-lib/config';
import { BlockchainService, createKeys, ICapacityInfo } from '#graph-lib/blockchain';
import { GraphUpdateJob } from '#graph-lib/dtos';
import { GraphUpdateJob } from '#types/dtos/graph';
import { NonceService } from '#graph-lib/services/nonce.service';
import { BaseConsumer } from '#graph-lib/utils';
import { SECONDS_PER_BLOCK, TXN_WATCH_LIST_KEY } from '#graph-lib/types/constants';
import { SECONDS_PER_BLOCK, TXN_WATCH_LIST_KEY } from '#types/constants';

const CAPACITY_EPOCH_TIMEOUT_NAME = 'capacity_check';

Expand Down Expand Up @@ -104,7 +104,7 @@ export class GraphUpdatePublisherService extends BaseConsumer implements OnAppli

this.logger.debug(`Successful job: ${JSON.stringify(job, null, 2)}`);

const status: ITxStatus = {
const status: IGraphTxStatus = {
providerId: this.configService.providerId,
referenceId: job.data.originalRequestJob.referenceId,
txHash: payWithCapacityTxHash.toHex(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Job, Queue } from 'bullmq';
import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { MessageSourceId, ProviderId } from '@frequency-chain/api-augment/interfaces';
import { AxiosError, AxiosResponse } from 'axios';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import { ConnectionDto, GraphKeyPairDto } from '#graph-lib/dtos';
import { IGraphUpdateJob, ProviderGraphUpdateJob } from '#graph-lib/interfaces';
import * as QueueConstants from '#types/constants/queue.constants';
import { ConnectionDto, GraphKeyPairDto } from '#types/dtos/graph';
import { IGraphUpdateJob, ProviderGraphUpdateJob } from '#types/interfaces/graph';
import { ProviderWebhookService } from '#graph-lib/services/provider-webhook.service';
import { BaseConsumer } from '#graph-lib/utils';
import { ConfigService } from '#graph-lib/config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { Option, Vec } from '@polkadot/types';
import { AnyNumber } from '@polkadot/types/types';
import { MILLISECONDS_PER_SECOND } from 'time-constants';
import { BaseConsumer } from '../BaseConsumer';
import * as QueueConstants from '#graph-lib/queues/queue-constants';
import * as QueueConstants from '#types/constants/queue.constants';
import fs from 'fs';
import { BlockchainService } from '#graph-lib/blockchain';
import { GraphUpdateJob, ConnectionDto, Direction } from '#graph-lib/dtos';
import { ProviderGraphUpdateJob, createReconnectionJob, SkipTransitiveGraphs } from '#graph-lib/interfaces';
import { GraphUpdateJob, ConnectionDto, Direction } from '#types/dtos/graph';
import { ProviderGraphUpdateJob, createReconnectionJob, SkipTransitiveGraphs } from '#types/interfaces/graph';
import { GraphStateManager } from '#graph-lib/services/graph-state-manager';
import { SECONDS_PER_BLOCK } from '#graph-lib/types/constants';
import { LAST_PROCESSED_DSNP_ID_KEY, SECONDS_PER_BLOCK } from '#types/constants';

@Injectable()
@Processor(QueueConstants.GRAPH_CHANGE_REQUEST_QUEUE)
Expand Down Expand Up @@ -52,7 +52,7 @@ export class RequestProcessorService extends BaseConsumer implements OnModuleDes
this.logger.log(`Processing job ${job.id} of type ${job.name}`);
const blockDelay = SECONDS_PER_BLOCK * MILLISECONDS_PER_SECOND;
try {
const lastProcessedDsnpId = await this.cacheManager.get(QueueConstants.LAST_PROCESSED_DSNP_ID_KEY);
const lastProcessedDsnpId = await this.cacheManager.get(LAST_PROCESSED_DSNP_ID_KEY);
if (lastProcessedDsnpId && lastProcessedDsnpId === job.data.dsnpId) {
this.logger.debug(`Delaying processing of job ${job.id} for ${blockDelay}ms`);
// eslint-disable-next-line no-await-in-loop
Expand Down Expand Up @@ -103,11 +103,7 @@ export class RequestProcessorService extends BaseConsumer implements OnModuleDes
if (reImported) {
// Use lua script to update last processed dsnpId
// @ts-expect-error updateLastProcessed is defined in the constructor
await this.cacheManager.updateLastProcessed(
QueueConstants.LAST_PROCESSED_DSNP_ID_KEY,
dsnpId.toString(),
blockDelay,
);
await this.cacheManager.updateLastProcessed(LAST_PROCESSED_DSNP_ID_KEY, dsnpId.toString(), blockDelay);
this.logger.debug(`Re-imported bundles for ${dsnpId.toString()}`);
// eslint-disable-next-line no-await-in-loop
const userGraphExists = this.graphStateManager.graphContainsUser(dsnpId.toString());
Expand Down
39 changes: 0 additions & 39 deletions libs/graph-lib/src/blockchain/blockchain-constants.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/graph-lib/src/blockchain/capacity-checker.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICapacityLimit } from '#graph-lib/interfaces';
import { ICapacityLimit } from '#types/interfaces/graph';
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '#graph-lib/config';
import { InjectRedis } from '@songkeys/nestjs-redis';
Expand Down
1 change: 0 additions & 1 deletion libs/graph-lib/src/blockchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './blockchain-constants';
export * from './blockchain.module';
export * from './blockchain.service';
export * from './create-keys';
Expand Down
2 changes: 1 addition & 1 deletion libs/graph-lib/src/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { EnvironmentType } from '@dsnp/graph-sdk';
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { ConfigService as NestConfigService } from '@nestjs/config';
import { ICapacityLimits } from '#graph-lib/interfaces/capacity-limit.interface';
import { ICapacityLimits } from '#types/interfaces/graph/capacity-limit.interface';
import { Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';

Expand Down
5 changes: 0 additions & 5 deletions libs/graph-lib/src/dtos/connection-type.enum.ts

This file was deleted.

41 changes: 0 additions & 41 deletions libs/graph-lib/src/dtos/connection.dto.ts

This file was deleted.

7 changes: 0 additions & 7 deletions libs/graph-lib/src/dtos/direction.enum.ts

This file was deleted.

18 changes: 0 additions & 18 deletions libs/graph-lib/src/dtos/dsnp-graph-edge.dto.ts

This file was deleted.

Loading