From 830f94cdfa3bf22ebbb1c40a6870ce1808608f4c Mon Sep 17 00:00:00 2001 From: Timo Erdelt Date: Tue, 16 Apr 2024 15:31:26 +0200 Subject: [PATCH] refactor: use absolute import paths and sort imports with eslint --- .eslintrc.js | 4 +- package-lock.json | 12 +++++- package.json | 7 ++- src/api/api.module.ts | 15 ++++--- ...-liquidity-info-history.controller.spec.ts | 11 ++--- .../pair-liquidity-info-history.controller.ts | 8 ++-- .../pair-liquidity-info-history.service.ts | 6 +-- src/api/pairs/pairs.controller.ts | 13 +++--- src/api/pairs/pairs.service.ts | 5 ++- src/api/tokens/tokens.controller.ts | 17 ++++---- src/api/tokens/tokens.service.ts | 7 +-- src/app.controller.ts | 7 +-- src/app.module.ts | 19 ++++---- src/clients/clients.module.ts | 7 +-- src/clients/mdw-http-client.model.ts | 2 +- src/clients/mdw-http-client.service.ts | 11 ++--- src/clients/mdw-ws-client.model.ts | 2 +- src/clients/mdw-ws-client.service.spec.ts | 10 ++--- src/clients/mdw-ws-client.service.ts | 9 ++-- src/clients/sdk-client.service.ts | 7 +-- src/database/database.module.ts | 15 ++++--- ...liquidity-info-history-error-db.service.ts | 3 +- ...uidity-info-history-v2-error-db.service.ts | 3 +- .../pair-liquidity-info-history-db.service.ts | 6 +-- ...ir-liquidity-info-history-v2-db.service.ts | 3 +- src/database/pair/pair-db.service.ts | 7 +-- src/database/token/token-db.service.ts | 4 +- src/lib/paths.spec.ts | 2 +- src/main.ts | 3 +- ...uidity-info-history-importer-v2.service.ts | 20 ++++----- ...dity-info-history-importer.service.spec.ts | 17 ++++---- ...liquidity-info-history-importer.service.ts | 18 ++++---- ...ity-info-history-validator.service.spec.ts | 9 ++-- ...iquidity-info-history-validator.service.ts | 9 ++-- src/tasks/pair-sync/pair-sync.model.ts | 5 ++- src/tasks/pair-sync/pair-sync.service.spec.ts | 28 ++++++------ src/tasks/pair-sync/pair-sync.service.ts | 23 +++++----- src/tasks/tasks.module.ts | 15 ++++--- src/tasks/tasks.service.spec.ts | 25 +++++------ src/tasks/tasks.service.ts | 7 +-- test/e2e/jest-e2e.json | 4 ++ ...uidity-info-history-db.service.e2e-spec.ts | 8 ++-- ...-info-history-error-db.service.e2e-spec.ts | 5 ++- test/e2e/pair-sync.service.e2e-spec.ts | 21 ++++----- test/e2e/pairs.e2e-spec.ts | 27 ++++++------ test/e2e/tokens.e2e-spec.ts | 43 +++++++++---------- test/test-utils/context-mock-data.ts | 4 +- test/test-utils/context-mock.spec.ts | 14 +++--- test/test-utils/context-mock.ts | 10 +++-- test/test-utils/db-helper.ts | 2 +- .../subscription-event-mock-data.ts | 2 +- tsconfig.json | 8 +++- 52 files changed, 299 insertions(+), 250 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 1ab6f73..4d745e5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,7 +4,7 @@ module.exports = { project: 'tsconfig.json', sourceType: 'module', }, - plugins: ['@typescript-eslint/eslint-plugin'], + plugins: ['@typescript-eslint/eslint-plugin', 'simple-import-sort'], extends: [ 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', @@ -36,5 +36,7 @@ module.exports = { }, ], eqeqeq: ['error', 'always', { null: 'ignore' }], + 'simple-import-sort/imports': 'warn', + 'simple-import-sort/exports': 'warn', }, }; diff --git a/package-lock.json b/package-lock.json index cd058b5..d8224ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "dex-backend", - "version": "1.1.1", + "version": "1.2.0", "hasInstallScript": true, "license": "UNLICENSED", "dependencies": { @@ -42,6 +42,7 @@ "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-simple-import-sort": "^10.0.0", "jest": "^29.7.0", "jest-mock-extended": "^3.0.5", "prettier": "^3.2.5", @@ -4748,6 +4749,15 @@ } } }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-10.0.0.tgz", + "integrity": "sha512-AeTvO9UCMSNzIHRkg8S6c3RPy5YEwKWSQPx3DYghLedo2ZQxowPFLGDN1AZ2evfg6r6mjBSZSLxLFsWSu3acsw==", + "dev": true, + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-scope": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", diff --git a/package.json b/package.json index a58c9fd..2753a2c 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", + "eslint-plugin-simple-import-sort": "^10.0.0", "jest": "^29.7.0", "jest-mock-extended": "^3.0.5", "prettier": "^3.2.5", @@ -97,6 +98,10 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "^@/test/(.*)$": "/test/$1", + "^@/(.*)$": "/src/$1" + } } } diff --git a/src/api/api.module.ts b/src/api/api.module.ts index 140dd07..badda35 100644 --- a/src/api/api.module.ts +++ b/src/api/api.module.ts @@ -1,11 +1,12 @@ import { Module } from '@nestjs/common'; -import { DatabaseModule } from '../database/database.module'; -import { PairLiquidityInfoHistoryController } from './pair-liquidity-info-history/pair-liquidity-info-history.controller'; -import { PairLiquidityInfoHistoryService } from './pair-liquidity-info-history/pair-liquidity-info-history.service'; -import { PairsController } from './pairs/pairs.controller'; -import { TokensController } from './tokens/tokens.controller'; -import { PairsService } from './pairs/pairs.service'; -import { TokensService } from './tokens/tokens.service'; + +import { PairLiquidityInfoHistoryController } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.controller'; +import { PairLiquidityInfoHistoryService } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.service'; +import { PairsController } from '@/api/pairs/pairs.controller'; +import { PairsService } from '@/api/pairs/pairs.service'; +import { TokensController } from '@/api/tokens/tokens.controller'; +import { TokensService } from '@/api/tokens/tokens.service'; +import { DatabaseModule } from '@/database/database.module'; @Module({ imports: [DatabaseModule], diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts index 155d39b..f2bbcc1 100644 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts +++ b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.spec.ts @@ -1,10 +1,11 @@ -import { PairLiquidityInfoHistoryController } from './pair-liquidity-info-history.controller'; -import { Test, TestingModule } from '@nestjs/testing'; -import { PairLiquidityInfoHistoryService } from './pair-liquidity-info-history.service'; import { INestApplication } from '@nestjs/common'; -import * as request from 'supertest'; +import { Test, TestingModule } from '@nestjs/testing'; import { Pair, PairLiquidityInfoHistory } from '@prisma/client'; -import { OrderQueryEnum } from '../api.model'; +import * as request from 'supertest'; + +import { OrderQueryEnum } from '@/api/api.model'; +import { PairLiquidityInfoHistoryController } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.controller'; +import { PairLiquidityInfoHistoryService } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.service'; const mockPairLiquidityInfoHistoryService = { getAllHistoryEntries: jest.fn(), diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.ts index c8c2df0..a6ba7ae 100644 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.ts +++ b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.controller.ts @@ -5,12 +5,12 @@ import { ParseIntPipe, Query, } from '@nestjs/common'; -import { PairLiquidityInfoHistoryService } from './pair-liquidity-info-history.service'; import { ApiOperation, ApiQuery, ApiResponse } from '@nestjs/swagger'; -import * as dto from '../api.model'; -import { OrderQueryEnum } from '../api.model'; -import { ContractAddress } from '../../clients/sdk-client.model'; +import * as dto from '@/api/api.model'; +import { OrderQueryEnum } from '@/api/api.model'; +import { PairLiquidityInfoHistoryService } from '@/api/pair-liquidity-info-history/pair-liquidity-info-history.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; @Controller('history/liquidity') export class PairLiquidityInfoHistoryController { diff --git a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts index 3fc4315..f9ede88 100644 --- a/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts +++ b/src/api/pair-liquidity-info-history/pair-liquidity-info-history.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@nestjs/common'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { Pair, PairLiquidityInfoHistory } from '@prisma/client'; -import { OrderQueryEnum } from '../api.model'; -import { ContractAddress } from '../../clients/sdk-client.model'; +import { OrderQueryEnum } from '@/api/api.model'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; @Injectable() export class PairLiquidityInfoHistoryService { diff --git a/src/api/pairs/pairs.controller.ts b/src/api/pairs/pairs.controller.ts index ccafc40..cb0abf4 100644 --- a/src/api/pairs/pairs.controller.ts +++ b/src/api/pairs/pairs.controller.ts @@ -1,16 +1,17 @@ import { Controller, Get, - Param, NotFoundException, + Param, Query, } from '@nestjs/common'; -import { PairsService } from './pairs.service'; -import * as dto from '../api.model'; +import { ApiOperation, ApiParam, ApiQuery, ApiResponse } from '@nestjs/swagger'; import * as prisma from '@prisma/client'; -import { getPaths } from '../../lib/paths'; -import { ApiOperation, ApiResponse, ApiQuery, ApiParam } from '@nestjs/swagger'; -import { removeId } from '../../lib/utils'; + +import * as dto from '@/api/api.model'; +import { PairsService } from '@/api/pairs/pairs.service'; +import { getPaths } from '@/lib/paths'; +import { removeId } from '@/lib/utils'; const toPair = ( pair: prisma.Pair & { diff --git a/src/api/pairs/pairs.service.ts b/src/api/pairs/pairs.service.ts index 490f93e..673b405 100644 --- a/src/api/pairs/pairs.service.ts +++ b/src/api/pairs/pairs.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@nestjs/common'; -import { presentInvalidTokens } from '../../lib/utils'; -import { PairDbService } from '../../database/pair/pair-db.service'; + +import { PairDbService } from '@/database/pair/pair-db.service'; +import { presentInvalidTokens } from '@/lib/utils'; @Injectable() export class PairsService { diff --git a/src/api/tokens/tokens.controller.ts b/src/api/tokens/tokens.controller.ts index 6bedfda..b345d84 100644 --- a/src/api/tokens/tokens.controller.ts +++ b/src/api/tokens/tokens.controller.ts @@ -1,24 +1,25 @@ import { Controller, + Delete, Get, - Param, Headers, NotFoundException, + Param, Post, - Delete, UnauthorizedException, } from '@nestjs/common'; -import { TokensService } from './tokens.service'; -import * as dto from '../api.model'; import { - ApiResponse, + ApiHeaders, ApiOperation, ApiParam, - ApiHeaders, + ApiResponse, } from '@nestjs/swagger'; -import { removeId } from '../../lib/utils'; import * as prisma from '@prisma/client'; -import { ContractAddress } from '../../clients/sdk-client.model'; + +import * as dto from '@/api/api.model'; +import { TokensService } from '@/api/tokens/tokens.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { removeId } from '@/lib/utils'; const withTokenAuthorization = async ( auth: string, diff --git a/src/api/tokens/tokens.service.ts b/src/api/tokens/tokens.service.ts index bd35a79..e63dc08 100644 --- a/src/api/tokens/tokens.service.ts +++ b/src/api/tokens/tokens.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; import { Pair, PairLiquidityInfo, Token } from '@prisma/client'; -import { presentInvalidTokens } from '../../lib/utils'; -import { TokenDbService } from '../../database/token/token-db.service'; -import { ContractAddress } from '../../clients/sdk-client.model'; + +import { ContractAddress } from '@/clients/sdk-client.model'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { presentInvalidTokens } from '@/lib/utils'; @Injectable() export class TokensService { diff --git a/src/app.controller.ts b/src/app.controller.ts index c7259cf..cf576da 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,9 +1,10 @@ import { Controller, Get } from '@nestjs/common'; -import { PairsService } from './api/pairs/pairs.service'; -import { TokensService } from './api/tokens/tokens.service'; -import * as dto from './api/api.model'; import { ApiOperation, ApiResponse } from '@nestjs/swagger'; +import * as dto from '@/api/api.model'; +import { PairsService } from '@/api/pairs/pairs.service'; +import { TokensService } from '@/api/tokens/tokens.service'; + @Controller('') export class AppController { constructor( diff --git a/src/app.module.ts b/src/app.module.ts index f1f8a45..2798290 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,13 +1,14 @@ import { Module } from '@nestjs/common'; -import { AppController } from './app.controller'; -import { DatabaseModule } from './database/database.module'; -import { TokensService } from './api/tokens/tokens.service'; -import { PairsService } from './api/pairs/pairs.service'; -import { ClientsModule } from './clients/clients.module'; -import { ApiModule } from './api/api.module'; -import { PairSyncService } from './tasks/pair-sync/pair-sync.service'; -import { MdwWsClientService } from './clients/mdw-ws-client.service'; -import { TasksModule } from './tasks/tasks.module'; + +import { ApiModule } from '@/api/api.module'; +import { PairsService } from '@/api/pairs/pairs.service'; +import { TokensService } from '@/api/tokens/tokens.service'; +import { AppController } from '@/app.controller'; +import { ClientsModule } from '@/clients/clients.module'; +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { DatabaseModule } from '@/database/database.module'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { TasksModule } from '@/tasks/tasks.module'; @Module({ imports: [ApiModule, ClientsModule, DatabaseModule, TasksModule], diff --git a/src/clients/clients.module.ts b/src/clients/clients.module.ts index afd1e57..272b235 100644 --- a/src/clients/clients.module.ts +++ b/src/clients/clients.module.ts @@ -1,7 +1,8 @@ import { Module } from '@nestjs/common'; -import { MdwHttpClientService } from './mdw-http-client.service'; -import { SdkClientService } from './sdk-client.service'; -import { MdwWsClientService } from './mdw-ws-client.service'; + +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; @Module({ providers: [MdwHttpClientService, MdwWsClientService, SdkClientService], diff --git a/src/clients/mdw-http-client.model.ts b/src/clients/mdw-http-client.model.ts index 46367c3..689ae3b 100644 --- a/src/clients/mdw-http-client.model.ts +++ b/src/clients/mdw-http-client.model.ts @@ -4,7 +4,7 @@ import { KeyBlockHash, MicroBlockHash, TxHash, -} from './sdk-client.model'; +} from '@/clients/sdk-client.model'; export type MdwPaginatedResponse = { next?: string; diff --git a/src/clients/mdw-http-client.service.ts b/src/clients/mdw-http-client.service.ts index 3f94b89..27bf705 100644 --- a/src/clients/mdw-http-client.service.ts +++ b/src/clients/mdw-http-client.service.ts @@ -1,20 +1,21 @@ import { Injectable } from '@nestjs/common'; -import NETWORKS from '../lib/network-config'; -import { nonNullable } from '../lib/utils'; + import { AccountBalance, - ContractBalance, Contract, + ContractBalance, ContractLog, MdwMicroBlock, MdwPaginatedResponse, -} from './mdw-http-client.model'; +} from '@/clients/mdw-http-client.model'; import { AccountAddress, ContractAddress, KeyBlockHash, MicroBlockHash, -} from './sdk-client.model'; +} from '@/clients/sdk-client.model'; +import NETWORKS from '@/lib/network-config'; +import { nonNullable } from '@/lib/utils'; @Injectable() export class MdwHttpClientService { diff --git a/src/clients/mdw-ws-client.model.ts b/src/clients/mdw-ws-client.model.ts index 6aa95ec..1801555 100644 --- a/src/clients/mdw-ws-client.model.ts +++ b/src/clients/mdw-ws-client.model.ts @@ -6,7 +6,7 @@ import { Signature, TxHash, WalletAddress, -} from './sdk-client.model'; +} from '@/clients/sdk-client.model'; export type SubscriptionEvent = { subscription: 'Object' | 'Transactions'; // add any other additional enum values if are used diff --git a/src/clients/mdw-ws-client.service.spec.ts b/src/clients/mdw-ws-client.service.spec.ts index 9c5e8a7..e661989 100644 --- a/src/clients/mdw-ws-client.service.spec.ts +++ b/src/clients/mdw-ws-client.service.spec.ts @@ -1,13 +1,13 @@ -import * as WebSocket from 'ws'; import { Logger } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; import { mock } from 'jest-mock-extended'; +import * as WebSocket from 'ws'; + +import { Callbacks, MdwWsClientService } from '@/clients/mdw-ws-client.service'; import { objSubEv, txSubEv, -} from '../../test/test-utils/subscription-event-mock-data'; - -import { Test, TestingModule } from '@nestjs/testing'; -import { Callbacks, MdwWsClientService } from './mdw-ws-client.service'; +} from '@/test/test-utils/subscription-event-mock-data'; describe('MdwWsClientService', () => { let service: MdwWsClientService; diff --git a/src/clients/mdw-ws-client.service.ts b/src/clients/mdw-ws-client.service.ts index 2814fbd..5a82880 100644 --- a/src/clients/mdw-ws-client.service.ts +++ b/src/clients/mdw-ws-client.service.ts @@ -1,9 +1,10 @@ import { Injectable, Logger } from '@nestjs/common'; import * as WebSocket from 'ws'; -import NETWORKS from '../lib/network-config'; -import { nonNullable, pluralize } from '../lib/utils'; -import { SubscriptionEvent } from './mdw-ws-client.model'; -import { ContractAddress } from './sdk-client.model'; + +import { SubscriptionEvent } from '@/clients/mdw-ws-client.model'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import NETWORKS from '@/lib/network-config'; +import { nonNullable, pluralize } from '@/lib/utils'; export type Callbacks = { onDisconnected?: (error?: Error) => any; diff --git a/src/clients/sdk-client.service.ts b/src/clients/sdk-client.service.ts index d32cd8d..f20a0e9 100644 --- a/src/clients/sdk-client.service.ts +++ b/src/clients/sdk-client.service.ts @@ -1,7 +1,8 @@ -import { Injectable } from '@nestjs/common'; import { AeSdk, Node } from '@aeternity/aepp-sdk'; -import { nonNullable } from '../lib/utils'; -import NETWORKS from '../lib/network-config'; +import { Injectable } from '@nestjs/common'; + +import NETWORKS from '@/lib/network-config'; +import { nonNullable } from '@/lib/utils'; @Injectable() export class SdkClientService { diff --git a/src/database/database.module.ts b/src/database/database.module.ts index 1850658..66a387d 100644 --- a/src/database/database.module.ts +++ b/src/database/database.module.ts @@ -1,11 +1,12 @@ import { Module } from '@nestjs/common'; -import { PrismaService } from './prisma.service'; -import { PairDbService } from './pair/pair-db.service'; -import { PairLiquidityInfoHistoryDbService } from './pair-liquidity-info-history/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from './pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; -import { TokenDbService } from './token/token-db.service'; -import { PairLiquidityInfoHistoryV2DbService } from './pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; -import { PairLiquidityInfoHistoryV2ErrorDbService } from './pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; + +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryV2DbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; +import { PairLiquidityInfoHistoryV2ErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; +import { PrismaService } from '@/database/prisma.service'; +import { TokenDbService } from '@/database/token/token-db.service'; @Module({ providers: [ diff --git a/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts index b1c8b9f..edf5099 100644 --- a/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts +++ b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistoryError } from '@prisma/client'; +import { PrismaService } from '@/database/prisma.service'; + @Injectable() export class PairLiquidityInfoHistoryErrorDbService { constructor(private prisma: PrismaService) {} diff --git a/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service.ts b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service.ts index 3a699d1..18c7a88 100644 --- a/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service.ts +++ b/src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistoryV2Error } from '@prisma/client'; +import { PrismaService } from '@/database/prisma.service'; + @Injectable() export class PairLiquidityInfoHistoryV2ErrorDbService { constructor(private prisma: PrismaService) {} diff --git a/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts index a4c99ce..b3ef271 100644 --- a/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts +++ b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistory } from '@prisma/client'; -import { OrderQueryEnum } from '../../api/api.model'; -import { ContractAddress } from '../../clients/sdk-client.model'; +import { OrderQueryEnum } from '@/api/api.model'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { PrismaService } from '@/database/prisma.service'; @Injectable() export class PairLiquidityInfoHistoryDbService { diff --git a/src/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service.ts b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service.ts index f16a250..8b0f710 100644 --- a/src/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service.ts +++ b/src/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service.ts @@ -1,7 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma.service'; import { PairLiquidityInfoHistoryV2 } from '@prisma/client'; +import { PrismaService } from '@/database/prisma.service'; + @Injectable() export class PairLiquidityInfoHistoryV2DbService { constructor(private prisma: PrismaService) {} diff --git a/src/database/pair/pair-db.service.ts b/src/database/pair/pair-db.service.ts index 2a666c3..9fb1348 100644 --- a/src/database/pair/pair-db.service.ts +++ b/src/database/pair/pair-db.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; import { Pair, Token } from '@prisma/client'; -import { PrismaService } from '../prisma.service'; -import { validTokenCondition } from '../token/token-db.service'; -import { ContractAddress } from '../../clients/sdk-client.model'; + +import { ContractAddress } from '@/clients/sdk-client.model'; +import { PrismaService } from '@/database/prisma.service'; +import { validTokenCondition } from '@/database/token/token-db.service'; export type PairWithTokens = { token0: Token; token1: Token } & Pair; export type CountMode = 'all' | 'listed' | 'synchronized'; diff --git a/src/database/token/token-db.service.ts b/src/database/token/token-db.service.ts index 745714b..9c49a18 100644 --- a/src/database/token/token-db.service.ts +++ b/src/database/token/token-db.service.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { PrismaService } from '../prisma.service'; import { Token } from '@prisma/client'; -import { ContractAddress } from '../../clients/sdk-client.model'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { PrismaService } from '@/database/prisma.service'; export const validTokenCondition = { malformed: false, noContract: false }; diff --git a/src/lib/paths.spec.ts b/src/lib/paths.spec.ts index 3322a9b..5a16e58 100644 --- a/src/lib/paths.spec.ts +++ b/src/lib/paths.spec.ts @@ -1,4 +1,4 @@ -import { getPaths, Edge } from './paths'; +import { Edge, getPaths } from '@/lib/paths'; it('a direct path', () => { const edges: Edge[] = [ diff --git a/src/main.ts b/src/main.ts index 39ba91b..7885ff1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,7 @@ import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; + +import { AppModule } from './app.module'; import { nonNullable } from './lib/utils'; import { PairSyncService } from './tasks/pair-sync/pair-sync.service'; diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service.ts index dea137d..2b0d85d 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service.ts @@ -1,16 +1,14 @@ import { Injectable, Logger } from '@nestjs/common'; -import { MdwHttpClientService } from '../../clients/mdw-http-client.service'; -import { - PairDbService, - PairWithTokens, -} from '../../database/pair/pair-db.service'; -import { SdkClientService } from '../../clients/sdk-client.service'; -import { ContractLog } from '../../clients/mdw-http-client.model'; -import { ContractAddress } from '../../clients/sdk-client.model'; import { orderBy } from 'lodash'; -import { PairLiquidityInfoHistoryV2DbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; -import { PairLiquidityInfoHistoryV2ErrorDbService } from '../../database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; -import { bigIntToDecimal } from '../../lib/utils'; + +import { ContractLog } from '@/clients/mdw-http-client.model'; +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService, PairWithTokens } from '@/database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryV2DbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; +import { PairLiquidityInfoHistoryV2ErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; +import { bigIntToDecimal } from '@/lib/utils'; enum EventType { Sync = 'Sync', diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts index d2f6997..6be13f4 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.spec.ts @@ -1,12 +1,13 @@ -import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { MdwHttpClientService } from '../../clients/mdw-http-client.service'; -import { PairDbService } from '../../database/pair/pair-db.service'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from '../../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; -import { Contract } from '../../clients/mdw-http-client.model'; -import { SdkClientService } from '../../clients/sdk-client.service'; -import { ContractAddress } from '../../clients/sdk-client.model'; + +import { Contract } from '@/clients/mdw-http-client.model'; +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; +import { PairLiquidityInfoHistoryImporterService } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; const mockMdwClientService = { getContract: jest.fn(), diff --git a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts index 182766a..0497332 100644 --- a/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts +++ b/src/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service.ts @@ -1,19 +1,17 @@ import { Injectable, Logger } from '@nestjs/common'; -import { MdwHttpClientService } from '../../clients/mdw-http-client.service'; -import { - PairDbService, - PairWithTokens, -} from '../../database/pair/pair-db.service'; import { isEqual, orderBy, uniqWith } from 'lodash'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryErrorDbService } from '../../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; -import { ContractLog } from '../../clients/mdw-http-client.model'; -import { SdkClientService } from '../../clients/sdk-client.service'; + +import { ContractLog } from '@/clients/mdw-http-client.model'; +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; import { ContractAddress, contractAddrToAccountAddr, MicroBlockHash, -} from '../../clients/sdk-client.model'; +} from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService, PairWithTokens } from '@/database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; type MicroBlock = { hash: MicroBlockHash; diff --git a/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.spec.ts b/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.spec.ts index 1f2e8e0..c2bf74b 100644 --- a/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.spec.ts +++ b/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.spec.ts @@ -1,8 +1,9 @@ -import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { MdwHttpClientService } from '../../clients/mdw-http-client.service'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; -import { SdkClientService } from '../../clients/sdk-client.service'; + +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryValidatorService } from '@/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; const mockMdwClientService = { getKeyBlockMicroBlocks: jest.fn(), diff --git a/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.ts b/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.ts index 58e87b3..e3a21c5 100644 --- a/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.ts +++ b/src/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service.ts @@ -1,9 +1,10 @@ -import { MdwHttpClientService } from '../../clients/mdw-http-client.service'; -import { PairLiquidityInfoHistoryDbService } from '../../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { Injectable, Logger } from '@nestjs/common'; import { uniq } from 'lodash'; -import { SdkClientService } from '../../clients/sdk-client.service'; -import { MicroBlockHash } from '../../clients/sdk-client.model'; + +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { MicroBlockHash } from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; @Injectable() export class PairLiquidityInfoHistoryValidatorService { diff --git a/src/tasks/pair-sync/pair-sync.model.ts b/src/tasks/pair-sync/pair-sync.model.ts index d3e673a..30fe97c 100644 --- a/src/tasks/pair-sync/pair-sync.model.ts +++ b/src/tasks/pair-sync/pair-sync.model.ts @@ -1,6 +1,7 @@ -import ContractWithMethods from '@aeternity/aepp-sdk/es/contract/Contract'; import { Node } from '@aeternity/aepp-sdk'; -import { ContractAddress } from '../../clients/sdk-client.model'; +import ContractWithMethods from '@aeternity/aepp-sdk/es/contract/Contract'; + +import { ContractAddress } from '@/clients/sdk-client.model'; export type MetaInfo = { name: string; diff --git a/src/tasks/pair-sync/pair-sync.service.spec.ts b/src/tasks/pair-sync/pair-sync.service.spec.ts index 387b52f..0a41108 100644 --- a/src/tasks/pair-sync/pair-sync.service.spec.ts +++ b/src/tasks/pair-sync/pair-sync.service.spec.ts @@ -1,26 +1,22 @@ import { Logger } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; import { mock } from 'jest-mock-extended'; -import * as data from '../../../test/test-utils/context-mock-data'; - +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { Context } from '@/tasks/pair-sync/pair-sync.model'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { mockContext } from '@/test/test-utils/context-mock'; +import * as data from '@/test/test-utils/context-mock-data'; +import { mockupEnvVars, TEST_NET_VARS } from '@/test/test-utils/env-mock'; import { objSubEv, swapEvent, swapTxInfo, -} from '../../../test/test-utils/subscription-event-mock-data'; -import { PairSyncService } from './pair-sync.service'; -import { Test, TestingModule } from '@nestjs/testing'; -import { PairDbService } from '../../database/pair/pair-db.service'; -import { TokenDbService } from '../../database/token/token-db.service'; -import { MdwWsClientService } from '../../clients/mdw-ws-client.service'; -import { Context } from './pair-sync.model'; -import { SdkClientService } from '../../clients/sdk-client.service'; -import { ContractAddress } from '../../clients/sdk-client.model'; -import { mockContext } from '../../../test/test-utils/context-mock'; -import { - mockupEnvVars, - TEST_NET_VARS, -} from '../../../test/test-utils/env-mock'; +} from '@/test/test-utils/subscription-event-mock-data'; describe('PairSyncService', () => { let service: PairSyncService; diff --git a/src/tasks/pair-sync/pair-sync.service.ts b/src/tasks/pair-sync/pair-sync.service.ts index ebf4191..9cac3af 100644 --- a/src/tasks/pair-sync/pair-sync.service.ts +++ b/src/tasks/pair-sync/pair-sync.service.ts @@ -1,24 +1,25 @@ -import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; -import { TokenDbService } from '../../database/token/token-db.service'; -import { PairDbService } from '../../database/pair/pair-db.service'; +import { AeSdk, ContractMethodsBase } from '@aeternity/aepp-sdk'; import ContractWithMethods from '@aeternity/aepp-sdk/es/contract/Contract'; +import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; import { Pair } from '@prisma/client'; -import { MdwWsClientService } from '../../clients/mdw-ws-client.service'; -import { SubscriptionEvent } from '../../clients/mdw-ws-client.model'; -import * as routerInterface from 'dex-contracts-v2/build/AedexV2Router.aci.json'; import * as factoryInterface from 'dex-contracts-v2/build/AedexV2Factory.aci.json'; import * as pairInterface from 'dex-contracts-v2/build/AedexV2Pair.aci.json'; -import { AeSdk, ContractMethodsBase } from '@aeternity/aepp-sdk'; -import { nonNullable } from '../../lib/utils'; +import * as routerInterface from 'dex-contracts-v2/build/AedexV2Router.aci.json'; + +import { SubscriptionEvent } from '@/clients/mdw-ws-client.model'; +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { nonNullable } from '@/lib/utils'; import { Aex9Methods, Context, FactoryMethods, PairMethods, RouterMethods, -} from './pair-sync.model'; -import { SdkClientService } from '../../clients/sdk-client.service'; -import { ContractAddress } from '../../clients/sdk-client.model'; +} from '@/tasks/pair-sync/pair-sync.model'; @Injectable() export class PairSyncService implements OnModuleInit { diff --git a/src/tasks/tasks.module.ts b/src/tasks/tasks.module.ts index 4a5b449..ddede2e 100644 --- a/src/tasks/tasks.module.ts +++ b/src/tasks/tasks.module.ts @@ -1,12 +1,13 @@ import { Module } from '@nestjs/common'; -import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; -import { DatabaseModule } from '../database/database.module'; -import { ClientsModule } from '../clients/clients.module'; import { ScheduleModule } from '@nestjs/schedule'; -import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; -import { TasksService } from './tasks.service'; -import { PairSyncService } from './pair-sync/pair-sync.service'; -import { PairLiquidityInfoHistoryImporterV2Service } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; + +import { ClientsModule } from '@/clients/clients.module'; +import { DatabaseModule } from '@/database/database.module'; +import { PairLiquidityInfoHistoryImporterService } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; +import { PairLiquidityInfoHistoryImporterV2Service } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; +import { PairLiquidityInfoHistoryValidatorService } from '@/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { TasksService } from '@/tasks/tasks.service'; @Module({ imports: [ClientsModule, DatabaseModule, ScheduleModule.forRoot()], diff --git a/src/tasks/tasks.service.spec.ts b/src/tasks/tasks.service.spec.ts index c8c17b9..1f179a0 100644 --- a/src/tasks/tasks.service.spec.ts +++ b/src/tasks/tasks.service.spec.ts @@ -1,16 +1,17 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { TasksService } from './tasks.service'; -import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; -import { MdwHttpClientService } from '../clients/mdw-http-client.service'; -import { PairDbService } from '../database/pair/pair-db.service'; -import { PrismaService } from '../database/prisma.service'; -import { SdkClientService } from '../clients/sdk-client.service'; -import { PairLiquidityInfoHistoryImporterV2Service } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; -import { PairLiquidityInfoHistoryV2ErrorDbService } from '../database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; -import { PairLiquidityInfoHistoryV2DbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; -import { PairLiquidityInfoHistoryDbService } from '../database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; -import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; -import { PairLiquidityInfoHistoryErrorDbService } from '../database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; + +import { MdwHttpClientService } from '@/clients/mdw-http-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PairLiquidityInfoHistoryV2DbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-v2-db.service'; +import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; +import { PairLiquidityInfoHistoryV2ErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-v2-error-db.service'; +import { PrismaService } from '@/database/prisma.service'; +import { PairLiquidityInfoHistoryImporterService } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; +import { PairLiquidityInfoHistoryImporterV2Service } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; +import { PairLiquidityInfoHistoryValidatorService } from '@/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; +import { TasksService } from '@/tasks/tasks.service'; describe('TasksService', () => { let tasksService: TasksService; diff --git a/src/tasks/tasks.service.ts b/src/tasks/tasks.service.ts index 8640224..6029c3f 100644 --- a/src/tasks/tasks.service.ts +++ b/src/tasks/tasks.service.ts @@ -1,8 +1,9 @@ import { Injectable } from '@nestjs/common'; import { Cron, CronExpression } from '@nestjs/schedule'; -import { PairLiquidityInfoHistoryValidatorService } from './pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; -import { PairLiquidityInfoHistoryImporterV2Service } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; -import { PairLiquidityInfoHistoryImporterService } from './pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; + +import { PairLiquidityInfoHistoryImporterService } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer.service'; +import { PairLiquidityInfoHistoryImporterV2Service } from '@/tasks/pair-liquidity-info-history-importer/pair-liquidity-info-history-importer-v2.service'; +import { PairLiquidityInfoHistoryValidatorService } from '@/tasks/pair-liquidity-info-history-validator/pair-liquidity-info-history-validator.service'; const EVERY_5_MINUTES_STARTING_AT_02_30 = '30 2-57/5 * * * *'; diff --git a/test/e2e/jest-e2e.json b/test/e2e/jest-e2e.json index 93400cd..cccba29 100644 --- a/test/e2e/jest-e2e.json +++ b/test/e2e/jest-e2e.json @@ -5,5 +5,9 @@ "testRegex": ".e2e-spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" + }, + "moduleNameMapper": { + "^@/test/(.*)$": "/../test/$1", + "^@/(.*)$": "/../src/$1" } } diff --git a/test/e2e/pair-liquidity-info-history-db.service.e2e-spec.ts b/test/e2e/pair-liquidity-info-history-db.service.e2e-spec.ts index 2b672fc..96bec5f 100644 --- a/test/e2e/pair-liquidity-info-history-db.service.e2e-spec.ts +++ b/test/e2e/pair-liquidity-info-history-db.service.e2e-spec.ts @@ -1,10 +1,10 @@ -import { PairLiquidityInfoHistoryDbService } from '../../src/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { PrismaService } from '../../src/database/prisma.service'; import { Pair, PairLiquidityInfoHistory, Token } from '@prisma/client'; -import { OrderQueryEnum } from '../../src/api/api.model'; -import { ContractAddress } from '../../src/clients/sdk-client.model'; +import { OrderQueryEnum } from '@/api/api.model'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { PairLiquidityInfoHistoryDbService } from '@/database/pair-liquidity-info-history/pair-liquidity-info-history-db.service'; +import { PrismaService } from '@/database/prisma.service'; const token1: Token = { id: 1, diff --git a/test/e2e/pair-liquidity-info-history-error-db.service.e2e-spec.ts b/test/e2e/pair-liquidity-info-history-error-db.service.e2e-spec.ts index 39a62e8..ea240b9 100644 --- a/test/e2e/pair-liquidity-info-history-error-db.service.e2e-spec.ts +++ b/test/e2e/pair-liquidity-info-history-error-db.service.e2e-spec.ts @@ -1,7 +1,8 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { PrismaService } from '../../src/database/prisma.service'; import { Pair, PairLiquidityInfoHistoryError, Token } from '@prisma/client'; -import { PairLiquidityInfoHistoryErrorDbService } from '../../src/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; + +import { PairLiquidityInfoHistoryErrorDbService } from '@/database/pair-liquidity-info-history-error/pair-liquidity-info-history-error-db.service'; +import { PrismaService } from '@/database/prisma.service'; const token1: Token = { id: 1, diff --git a/test/e2e/pair-sync.service.e2e-spec.ts b/test/e2e/pair-sync.service.e2e-spec.ts index 507a6fa..6dc11be 100644 --- a/test/e2e/pair-sync.service.e2e-spec.ts +++ b/test/e2e/pair-sync.service.e2e-spec.ts @@ -1,14 +1,15 @@ -import prisma from '@prisma/client'; -import * as data from '../test-utils/context-mock-data'; -import { PairSyncService } from '../../src/tasks/pair-sync/pair-sync.service'; -import { PrismaService } from '../../src/database/prisma.service'; import { Test, TestingModule } from '@nestjs/testing'; -import { TokenDbService } from '../../src/database/token/token-db.service'; -import { PairDbService } from '../../src/database/pair/pair-db.service'; -import { MdwWsClientService } from '../../src/clients/mdw-ws-client.service'; -import { cleanDb } from '../test-utils/db-helper'; -import { SdkClientService } from '../../src/clients/sdk-client.service'; -import { mockContext } from '../test-utils/context-mock'; +import prisma from '@prisma/client'; + +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PrismaService } from '@/database/prisma.service'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { mockContext } from '@/test/test-utils/context-mock'; +import * as data from '@/test/test-utils/context-mock-data'; +import { cleanDb } from '@/test/test-utils/db-helper'; // Testing method // 1. before all create a common context diff --git a/test/e2e/pairs.e2e-spec.ts b/test/e2e/pairs.e2e-spec.ts index a13c87d..a869e57 100644 --- a/test/e2e/pairs.e2e-spec.ts +++ b/test/e2e/pairs.e2e-spec.ts @@ -1,18 +1,19 @@ -import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; -import { sortByAddress } from '../test-utils/utils'; -import * as data from '../test-utils/context-mock-data'; -import { cleanDb, listToken } from '../test-utils/db-helper'; -import { PrismaService } from '../../src/database/prisma.service'; -import { PairSyncService } from '../../src/tasks/pair-sync/pair-sync.service'; -import { PairsController } from '../../src/api/pairs/pairs.controller'; -import { PairsService } from '../../src/api/pairs/pairs.service'; -import { PairDbService } from '../../src/database/pair/pair-db.service'; -import { TokenDbService } from '../../src/database/token/token-db.service'; -import { MdwWsClientService } from '../../src/clients/mdw-ws-client.service'; -import { SdkClientService } from '../../src/clients/sdk-client.service'; -import { mockContext } from '../test-utils/context-mock'; + +import { PairsController } from '@/api/pairs/pairs.controller'; +import { PairsService } from '@/api/pairs/pairs.service'; +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PrismaService } from '@/database/prisma.service'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { mockContext } from '@/test/test-utils/context-mock'; +import * as data from '@/test/test-utils/context-mock-data'; +import { cleanDb, listToken } from '@/test/test-utils/db-helper'; +import { sortByAddress } from '@/test/test-utils/utils'; // Testing method // before all diff --git a/test/e2e/tokens.e2e-spec.ts b/test/e2e/tokens.e2e-spec.ts index 8c53f58..41bcc2d 100644 --- a/test/e2e/tokens.e2e-spec.ts +++ b/test/e2e/tokens.e2e-spec.ts @@ -1,22 +1,21 @@ -import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; +import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; -import { cleanDb, listToken } from '../test-utils/db-helper'; -import * as data from '../test-utils/context-mock-data'; -import * as dto from '../../src/api/api.model'; -import * as utils from '../test-utils/utils'; -import { nonNullable } from '../../src/lib/utils'; -import { PrismaService } from '../../src/database/prisma.service'; -import { PairSyncService } from '../../src/tasks/pair-sync/pair-sync.service'; -import { PairDbService } from '../../src/database/pair/pair-db.service'; -import { TokenDbService } from '../../src/database/token/token-db.service'; -import { MdwWsClientService } from '../../src/clients/mdw-ws-client.service'; -import { TokensController } from '../../src/api/tokens/tokens.controller'; -import { TokensService } from '../../src/api/tokens/tokens.service'; -import { SdkClientService } from '../../src/clients/sdk-client.service'; -import { sortByAddress } from '../test-utils/utils'; -import { mockContext } from '../test-utils/context-mock'; +import * as dto from '@/api/api.model'; +import { TokensController } from '@/api/tokens/tokens.controller'; +import { TokensService } from '@/api/tokens/tokens.service'; +import { MdwWsClientService } from '@/clients/mdw-ws-client.service'; +import { SdkClientService } from '@/clients/sdk-client.service'; +import { PairDbService } from '@/database/pair/pair-db.service'; +import { PrismaService } from '@/database/prisma.service'; +import { TokenDbService } from '@/database/token/token-db.service'; +import { nonNullable } from '@/lib/utils'; +import { PairSyncService } from '@/tasks/pair-sync/pair-sync.service'; +import { mockContext } from '@/test/test-utils/context-mock'; +import * as data from '@/test/test-utils/context-mock-data'; +import { cleanDb, listToken } from '@/test/test-utils/db-helper'; +import { sortByAddress } from '@/test/test-utils/utils'; // Testing method // before all @@ -72,7 +71,7 @@ describe('TokenController', () => { .expect(200); const value: dto.TokenWithListed[] = JSON.parse(response.text); - expect(utils.sortByAddress(value)).toEqual([ + expect(sortByAddress(value)).toEqual([ { address: 'ct_t0', symbol: 'A', @@ -215,7 +214,7 @@ describe('TokenController', () => { const value: dto.TokenPairs = JSON.parse(response.text); - expect(utils.sortByAddress(value.pairs0)).toEqual([ + expect(sortByAddress(value.pairs0)).toEqual([ { address: 'ct_p1', synchronized: false, @@ -257,7 +256,7 @@ describe('TokenController', () => { const value: dto.TokenPairs = JSON.parse(response.text); expect(value.pairs1).toEqual([]); - expect(utils.sortByAddress(value.pairs0)).toEqual([ + expect(sortByAddress(value.pairs0)).toEqual([ { address: 'ct_p1', synchronized: true, @@ -332,7 +331,7 @@ describe('TokenController', () => { const value: dto.TokenPairs = JSON.parse(response.text); expect(value.pairs0).toEqual([]); - expect(utils.sortByAddress(value.pairs1)).toEqual([ + expect(sortByAddress(value.pairs1)).toEqual([ { address: 'ct_p2', synchronized: true, @@ -407,7 +406,7 @@ describe('TokenController', () => { const value: dto.TokenPairs = JSON.parse(response.text); - expect(utils.sortByAddress(value.pairs0)).toEqual([ + expect(sortByAddress(value.pairs0)).toEqual([ { address: 'ct_p5', synchronized: true, @@ -447,7 +446,7 @@ describe('TokenController', () => { }, }, ]); - expect(utils.sortByAddress(value.pairs1)).toEqual([ + expect(sortByAddress(value.pairs1)).toEqual([ { address: 'ct_p2', synchronized: true, diff --git a/test/test-utils/context-mock-data.ts b/test/test-utils/context-mock-data.ts index bd52abd..f359764 100644 --- a/test/test-utils/context-mock-data.ts +++ b/test/test-utils/context-mock-data.ts @@ -1,5 +1,5 @@ -import { ContractAddress } from '../../src/clients/sdk-client.model'; -import { ContextData } from './context-mock'; +import { ContractAddress } from '@/clients/sdk-client.model'; +import { ContextData } from '@/test/test-utils/context-mock'; const tokens = [ { diff --git a/test/test-utils/context-mock.spec.ts b/test/test-utils/context-mock.spec.ts index d47137b..828b9cb 100644 --- a/test/test-utils/context-mock.spec.ts +++ b/test/test-utils/context-mock.spec.ts @@ -1,11 +1,13 @@ -import { mockDeep } from 'jest-mock-extended'; -import * as data from './context-mock-data'; import ContractWithMethods from '@aeternity/aepp-sdk/es/contract/Contract'; +import { mockDeep } from 'jest-mock-extended'; + +import { Context, PairMethods } from '@/tasks/pair-sync/pair-sync.model'; import { - Context, - PairMethods, -} from '../../src/tasks/pair-sync/pair-sync.model'; -import { ContextData, mockContext, mockupContractMethod } from './context-mock'; + ContextData, + mockContext, + mockupContractMethod, +} from '@/test/test-utils/context-mock'; +import * as data from '@/test/test-utils/context-mock-data'; describe('Context', () => { it('sample mockup', async () => { diff --git a/test/test-utils/context-mock.ts b/test/test-utils/context-mock.ts index 27ec64a..4a6c8c2 100644 --- a/test/test-utils/context-mock.ts +++ b/test/test-utils/context-mock.ts @@ -1,13 +1,15 @@ -import { nonNullable } from '../../src/lib/utils'; -import { mockDeep } from 'jest-mock-extended'; import ContractWithMethods from '@aeternity/aepp-sdk/es/contract/Contract'; +import { mockDeep } from 'jest-mock-extended'; + +import { CallData, ContractAddress } from '@/clients/sdk-client.model'; +import { nonNullable } from '@/lib/utils'; import { Aex9Methods, Context, MetaInfo, PairMethods, -} from '../../src/tasks/pair-sync/pair-sync.model'; -import { CallData, ContractAddress } from '../../src/clients/sdk-client.model'; +} from '@/tasks/pair-sync/pair-sync.model'; + const mockupResult = () => mockDeep<{ callerId: string; diff --git a/test/test-utils/db-helper.ts b/test/test-utils/db-helper.ts index e4019d6..37941a3 100644 --- a/test/test-utils/db-helper.ts +++ b/test/test-utils/db-helper.ts @@ -1,4 +1,4 @@ -import { PrismaService } from '../../src/database/prisma.service'; +import { PrismaService } from '@/database/prisma.service'; export const cleanDb = async (prismaService: PrismaService) => { await prismaService.pairLiquidityInfo.deleteMany(); diff --git a/test/test-utils/subscription-event-mock-data.ts b/test/test-utils/subscription-event-mock-data.ts index 08d21a6..c15bd5f 100644 --- a/test/test-utils/subscription-event-mock-data.ts +++ b/test/test-utils/subscription-event-mock-data.ts @@ -1,4 +1,4 @@ -import { SubscriptionEvent } from '../../src/clients/mdw-ws-client.model'; +import { SubscriptionEvent } from '@/clients/mdw-ws-client.model'; export const objSubEv: SubscriptionEvent = { subscription: 'Object', diff --git a/tsconfig.json b/tsconfig.json index 9db9a79..4863998 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "target": "es2020", "sourceMap": true, "outDir": "./dist", - "baseUrl": "./", + "baseUrl": ".", "incremental": true, "skipLibCheck": true, "strictNullChecks": true, @@ -17,6 +17,10 @@ "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, - "types": ["node"] + "types": ["node"], + "paths": { + "@/*": ["./src/*"], + "@/test/*": ["./test/*"] + } } }