Skip to content

Commit

Permalink
refactor: use absolute import paths and sort imports with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
tmrdlt committed Apr 16, 2024
1 parent 35a62dc commit 830f94c
Show file tree
Hide file tree
Showing 52 changed files with 299 additions and 250 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -36,5 +36,7 @@ module.exports = {
},
],
eqeqeq: ['error', 'always', { null: 'ignore' }],
'simple-import-sort/imports': 'warn',
'simple-import-sort/exports': 'warn',
},
};
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -97,6 +98,10 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^@/test/(.*)$": "<rootDir>/test/$1",
"^@/(.*)$": "<rootDir>/src/$1"
}
}
}
15 changes: 8 additions & 7 deletions src/api/api.module.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
13 changes: 7 additions & 6 deletions src/api/pairs/pairs.controller.ts
Original file line number Diff line number Diff line change
@@ -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 & {
Expand Down
5 changes: 3 additions & 2 deletions src/api/pairs/pairs.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
17 changes: 9 additions & 8 deletions src/api/tokens/tokens.controller.ts
Original file line number Diff line number Diff line change
@@ -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 <T>(
auth: string,
Expand Down
7 changes: 4 additions & 3 deletions src/api/tokens/tokens.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
19 changes: 10 additions & 9 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
7 changes: 4 additions & 3 deletions src/clients/clients.module.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
2 changes: 1 addition & 1 deletion src/clients/mdw-http-client.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
KeyBlockHash,
MicroBlockHash,
TxHash,
} from './sdk-client.model';
} from '@/clients/sdk-client.model';

export type MdwPaginatedResponse<T> = {
next?: string;
Expand Down
11 changes: 6 additions & 5 deletions src/clients/mdw-http-client.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/clients/mdw-ws-client.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/clients/mdw-ws-client.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/clients/mdw-ws-client.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/clients/sdk-client.service.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
15 changes: 8 additions & 7 deletions src/database/database.module.ts
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {}
Expand Down
Loading

0 comments on commit 830f94c

Please sign in to comment.