Skip to content

Commit 42969f2

Browse files
authored
chore: Add path alias to api package (#107)
small dev ex improvement: Before: `import { ... } from '../../../fixtures';` After: `import { ... } from '@/fixtures';` after checking out, rebuild `api` and `task-check-alerts` containers: ```sh docker compose -f docker-compose.dev.yml up -d --no-deps --build task-check-alerts api ```
1 parent c56fe9c commit 42969f2

36 files changed

+128
-109
lines changed

.changeset/friendly-ravens-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hyperdx/api': patch
3+
---
4+
5+
chore: Add path aliases

packages/api/jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ module.exports = {
66
rootDir: './src',
77
testMatch: ['**/__tests__/*.test.ts?(x)'],
88
testTimeout: 30000,
9+
moduleNameMapper: {
10+
'@/(.*)$': '<rootDir>/$1',
11+
},
912
};

packages/api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@
7777
"supertest": "^6.3.1",
7878
"ts-jest": "^28.0.5",
7979
"ts-node": "^10.8.1",
80+
"tsconfig-paths": "^4.2.0",
8081
"typescript": "^4.9.5"
8182
},
8283
"scripts": {
8384
"start": "node ./build/index.js",
84-
"dev": "nodemon --signal SIGTERM -e ts,json --exec 'ts-node' --transpile-only -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/index.ts",
85-
"dev:task": "ts-node -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts",
85+
"dev": "nodemon --signal SIGTERM -e ts,json --exec 'ts-node' --transpile-only -r tsconfig-paths/register -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/index.ts",
86+
"dev:task": "ts-node -r tsconfig-paths/register -r tsconfig-paths/register -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts",
8687
"build": "rimraf ./build && tsc",
8788
"lint": "eslint . --ext .ts",
8889
"ci:lint": "yarn lint && yarn tsc --noEmit",

packages/api/src/clickhouse/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import {
1414
} from '@clickhouse/client/dist/logger';
1515
import { serializeError } from 'serialize-error';
1616

17-
import * as config from '../config';
18-
import logger from '../utils/logger';
19-
import { sleep } from '../utils/common';
17+
import * as config from '@/config';
18+
import logger from '@/utils/logger';
19+
import { sleep } from '@/utils/common';
2020
import {
2121
LogsPropertyTypeMappingsModel,
2222
MetricsPropertyTypeMappingsModel,
@@ -36,7 +36,7 @@ import type {
3636
LogStreamModel,
3737
MetricModel,
3838
RrwebEventModel,
39-
} from '../utils/logParser';
39+
} from '@/utils/logParser';
4040

4141
const tracer = opentelemetry.trace.getTracer(__filename);
4242

packages/api/src/clickhouse/propertyTypeMappingsModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import ms from 'ms';
22
import { serializeError } from 'serialize-error';
33

4-
import logger from '../utils/logger';
5-
import redisClient from '../utils/redis';
6-
import { IS_DEV } from '../config';
4+
import logger from '@/utils/logger';
5+
import redisClient from '@/utils/redis';
6+
import { IS_DEV } from '@/config';
77

88
import type { ResponseJSON } from '@clickhouse/client';
99

packages/api/src/clickhouse/searchQueryParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SqlString from 'sqlstring';
22
import lucene from '@hyperdx/lucene';
33
import { serializeError } from 'serialize-error';
44

5-
import { LogPlatform, LogType } from '../utils/logParser';
5+
import { LogPlatform, LogType } from '@/utils/logParser';
66
import { PropertyTypeMappingsModel } from './propertyTypeMappingsModel';
77

88
function encodeSpecialTokens(query: string): string {

packages/api/src/controllers/__tests__/team.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { clearDBCollections, closeDB, connectDB } from '../../fixtures';
2-
import { createTeam, getTeam, getTeamByApiKey } from '../../controllers/team';
1+
import { clearDBCollections, closeDB, connectDB } from '@/fixtures';
2+
import { createTeam, getTeam, getTeamByApiKey } from '@/controllers/team';
33

44
describe('team controller', () => {
55
beforeAll(async () => {

packages/api/src/controllers/alerts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import Alert, {
55
AlertInterval,
66
AlertType,
77
AlertSource,
8-
} from '../models/alert';
9-
import * as clickhouse from '../clickhouse';
10-
import { SQLSerializer } from '../clickhouse/searchQueryParser';
8+
} from '@/models/alert';
9+
import * as clickhouse from '@/clickhouse';
10+
import { SQLSerializer } from '@/clickhouse/searchQueryParser';
1111
import ms from 'ms';
1212

1313
export type AlertInput = {

packages/api/src/controllers/team.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { v4 as uuidv4 } from 'uuid';
22

3-
import Team from '../models/team';
3+
import Team from '@/models/team';
44

5-
import type { ObjectId } from '../models';
5+
import type { ObjectId } from '@/models';
66

77
export async function isTeamExisting() {
88
const teamCount = await Team.countDocuments({});

packages/api/src/controllers/user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import User from '../models/user';
1+
import User from '@/models/user';
22

3-
import type { ObjectId } from '../models';
3+
import type { ObjectId } from '@/models';
44

55
export function findUserById(id: string) {
66
return User.findById(id);

0 commit comments

Comments
 (0)