Skip to content

Commit

Permalink
Refactor import paths to use scoped aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Mar 2, 2025
1 parent 34fedb2 commit debed9c
Show file tree
Hide file tree
Showing 30 changed files with 83 additions and 82 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FuelType } from "@/types";
import { FuelType } from "@api/types";

export const CACHE_TTL = 24 * 60 * 60;

Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/lib/getCarsByFuelType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import db from "@/config/db";
import { getLatestMonth } from "@/lib/getLatestMonth";
import type { FuelType } from "@/types";
import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths";
import db from "@api/config/db";
import { getLatestMonth } from "@api/lib/getLatestMonth";
import type { FuelType } from "@api/types";
import getTrailingTwelveMonths from "@api/utils/getTrailingTwelveMonths";
import { cars } from "@sgcarstrends/schema";
import { and, asc, between, desc, eq, ilike, or } from "drizzle-orm";

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/getLatestMonth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import db from "@/config/db";
import db from "@api/config/db";
import { max } from "drizzle-orm";
import type { PgTable } from "drizzle-orm/pg-core";

Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/lib/getUniqueMonths.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CACHE_TTL } from "@/config";
import db from "@/config/db";
import redis from "@/config/redis";
import { CACHE_TTL } from "@api/config";
import db from "@api/config/db";
import redis from "@api/config/redis";
import { desc, getTableName } from "drizzle-orm";
import type { PgTable } from "drizzle-orm/pg-core";

export const getUniqueMonths = async <T extends PgTable>(
table: T,
key = "month"
key = "month",
) => {
const tableName = getTableName(table);
const CACHE_KEY = `${tableName}:months`;
Expand All @@ -22,7 +22,7 @@ export const getUniqueMonths = async <T extends PgTable>(

months = results.map(({ month }) => month);

await redis.sadd(CACHE_KEY, ...months);
await redis.sadd(CACHE_KEY, months);
await redis.expire(CACHE_KEY, CACHE_TTL);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/groupMonthsByYear.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const groupMonthsByYear = (
months: string[]
months: string[],
): { year: string; months: string[] }[] => {
const groupedData: Record<string, string[]> = {};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths";
import getTrailingTwelveMonths from "@api/utils/getTrailingTwelveMonths";
import { describe, expect, it } from "vitest";

describe("getTrailingTwelveMonths", () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCarsByFuelType } from "@/lib/getCarsByFuelType";
import { FuelType } from "@/types";
import { getCarsByFuelType } from "@api/lib/getCarsByFuelType";
import { FuelType } from "@api/types";
import { Hono } from "hono";
import { bearerAuth } from "hono/bearer-auth";
import { Resource } from "sst";
Expand Down
18 changes: 9 additions & 9 deletions apps/api/src/v1/routes/cars.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CACHE_TTL, HYBRID_REGEX } from "@/config";
import db from "@/config/db";
import redis from "@/config/redis";
import { getLatestMonth } from "@/lib/getLatestMonth";
import { getUniqueMonths } from "@/lib/getUniqueMonths";
import { groupMonthsByYear } from "@/lib/groupMonthsByYear";
import { CarQuerySchema, MonthsQuerySchema } from "@/schemas";
import type { Make } from "@/types";
import getTrailingTwelveMonths from "@/utils/getTrailingTwelveMonths";
import { CACHE_TTL, HYBRID_REGEX } from "@api/config";
import db from "@api/config/db";
import redis from "@api/config/redis";
import { getLatestMonth } from "@api/lib/getLatestMonth";
import { getUniqueMonths } from "@api/lib/getUniqueMonths";
import { groupMonthsByYear } from "@api/lib/groupMonthsByYear";
import { CarQuerySchema, MonthsQuerySchema } from "@api/schemas";
import type { Make } from "@api/types";
import getTrailingTwelveMonths from "@api/utils/getTrailingTwelveMonths";
import { zValidator } from "@hono/zod-validator";
import { cars } from "@sgcarstrends/schema";
import { and, asc, between, desc, eq, ilike, sql } from "drizzle-orm";
Expand Down
12 changes: 6 additions & 6 deletions apps/api/src/v1/routes/coe.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CACHE_TTL } from "@/config";
import db from "@/config/db";
import redis from "@/config/redis";
import { getUniqueMonths } from "@/lib/getUniqueMonths";
import { groupMonthsByYear } from "@/lib/groupMonthsByYear";
import { type COE, COEQuerySchema, MonthsQuerySchema } from "@/schemas";
import { CACHE_TTL } from "@api/config";
import db from "@api/config/db";
import redis from "@api/config/redis";
import { getUniqueMonths } from "@api/lib/getUniqueMonths";
import { groupMonthsByYear } from "@api/lib/groupMonthsByYear";
import { type COE, COEQuerySchema, MonthsQuerySchema } from "@api/schemas";
import { zValidator } from "@hono/zod-validator";
import { coe, coePQP } from "@sgcarstrends/schema";
import { and, asc, desc, eq, gte, inArray, lte, max } from "drizzle-orm";
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/v1/routes/makes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CACHE_TTL } from "@/config";
import db from "@/config/db";
import redis from "@/config/redis";
import { MakeParamSchema, MakeQuerySchema } from "@/schemas";
import type { Make } from "@/types";
import { CACHE_TTL } from "@api/config";
import db from "@api/config/db";
import redis from "@api/config/redis";
import { MakeParamSchema, MakeQuerySchema } from "@api/schemas";
import type { Make } from "@api/types";
import { zValidator } from "@hono/zod-validator";
import { cars } from "@sgcarstrends/schema";
import { and, asc, desc, eq, ilike } from "drizzle-orm";
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/v1/routes/months.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getLatestMonth } from "@/lib/getLatestMonth";
import { LatestMonthQuerySchema } from "@/schemas";
import { getLatestMonth } from "@api/lib/getLatestMonth";
import { LatestMonthQuerySchema } from "@api/schemas";
import { zValidator } from "@hono/zod-validator";
import { cars, coe } from "@sgcarstrends/schema";
import { Hono } from "hono";
Expand Down
6 changes: 3 additions & 3 deletions apps/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"baseUrl": ".",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"paths": {
"@/*": ["src/*"]
},
"resolveJsonModule": true
"@api/*": ["src/*"]
}
},
"include": ["**/*.ts"]
}
2 changes: 1 addition & 1 deletion apps/api/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineConfig({
},
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
"@api": resolve(__dirname, "./src"),
},
},
});
2 changes: 1 addition & 1 deletion apps/updater/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { updateCOEPQP } from "@/lib/updateCOEPQP";
import { updateCOEPQP } from "@updater/lib/updateCOEPQP";
import { Hono } from "hono";
import { handle } from "hono/aws-lambda";
import { bearerAuth } from "hono/bearer-auth";
Expand Down
4 changes: 2 additions & 2 deletions apps/updater/src/lib/updateCOE.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LTA_DATAMALL_BASE_URL } from "@/config";
import type { COE } from "@/types";
import { coe } from "@sgcarstrends/schema";
import { LTA_DATAMALL_BASE_URL } from "@updater/config";
import type { COE } from "@updater/types";
import { updater } from "./updater";

export const updateCOE = () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/updater/src/lib/updateCOEPQP.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LTA_DATAMALL_BASE_URL } from "@/config";
import type { PQP } from "@/types";
import { coePQP } from "@sgcarstrends/schema";
import { LTA_DATAMALL_BASE_URL } from "@updater/config";
import type { PQP } from "@updater/types";
import { updater } from "./updater";

export const updateCOEPQP = () => {
Expand Down
6 changes: 3 additions & 3 deletions apps/updater/src/lib/updateCars.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LTA_DATAMALL_BASE_URL } from "@/config";
import type { Car } from "@/types";
import { cleanSpecialChars } from "@/utils/cleanSpecialChars";
import { cars } from "@sgcarstrends/schema";
import { LTA_DATAMALL_BASE_URL } from "@updater/config";
import type { Car } from "@updater/types";
import { cleanSpecialChars } from "@updater/utils/cleanSpecialChars";
import { updater } from "./updater";

export const updateCars = () => {
Expand Down
17 changes: 10 additions & 7 deletions apps/updater/src/lib/updater.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import path from "node:path";
import { AWS_LAMBDA_TEMP_DIR } from "@/config";
import { db } from "@/db";
import { calculateChecksum } from "@/utils/calculateChecksum";
import { createUniqueKey } from "@/utils/createUniqueKey";
import { downloadFile } from "@/utils/downloadFile";
import { type CSVTransformOptions, processCSV } from "@/utils/processCSV";
import { cacheChecksum, getCachedChecksum } from "@/utils/redisCache";
import { AWS_LAMBDA_TEMP_DIR } from "@updater/config";
import { db } from "@updater/db";
import { calculateChecksum } from "@updater/utils/calculateChecksum";
import { createUniqueKey } from "@updater/utils/createUniqueKey";
import { downloadFile } from "@updater/utils/downloadFile";
import {
type CSVTransformOptions,
processCSV,
} from "@updater/utils/processCSV";
import { cacheChecksum, getCachedChecksum } from "@updater/utils/redisCache";
import { type Table, getTableName } from "drizzle-orm";

export interface UpdaterConfig<T> {
Expand Down
6 changes: 3 additions & 3 deletions apps/updater/src/trigger/update-cars.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { schedulers } from "@/config/schedulers";
import { updateCars } from "@/lib/updateCars";
import { createUpdateTask } from "@/utils/createUpdateTask";
import { schedulers } from "@updater/config/schedulers";
import { updateCars } from "@updater/lib/updateCars";
import { createUpdateTask } from "@updater/utils/createUpdateTask";

export const updateCarsTask = createUpdateTask(
"cars",
Expand Down
6 changes: 3 additions & 3 deletions apps/updater/src/trigger/update-coe-pqp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { schedulers } from "@/config/schedulers";
import { updateCOEPQP } from "@/lib/updateCOEPQP";
import { createUpdateTask } from "@/utils/createUpdateTask";
import { schedulers } from "@updater/config/schedulers";
import { updateCOEPQP } from "@updater/lib/updateCOEPQP";
import { createUpdateTask } from "@updater/utils/createUpdateTask";

export const updateCOEPQPTask = createUpdateTask(
"coe-pqp",
Expand Down
6 changes: 3 additions & 3 deletions apps/updater/src/trigger/update-coe.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { schedulers } from "@/config/schedulers";
import { updateCOE } from "@/lib/updateCOE";
import { createUpdateTask } from "@/utils/createUpdateTask";
import { schedulers } from "@updater/config/schedulers";
import { updateCOE } from "@updater/lib/updateCOE";
import { createUpdateTask } from "@updater/utils/createUpdateTask";

export const updateCOETask = createUpdateTask("coe", schedulers.coe, updateCOE);
2 changes: 1 addition & 1 deletion apps/updater/src/utils/__tests__/calculateChecksum.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import crypto from "node:crypto";
import { unlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { calculateChecksum } from "@/utils/calculateChecksum";
import { calculateChecksum } from "@updater/utils/calculateChecksum";
import { afterEach, beforeEach, describe, expect, it } from "vitest";

describe("calculateChecksum", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/updater/src/utils/__tests__/cleanSpecialChars.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cleanSpecialChars } from "@/utils/cleanSpecialChars";
import { cleanSpecialChars } from "@updater/utils/cleanSpecialChars";
import { describe, expect, it } from "vitest";

describe("cleanSpecialChars", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/updater/src/utils/__tests__/createUniqueKey.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createUniqueKey } from "@/utils/createUniqueKey";
import { createUniqueKey } from "@updater/utils/createUniqueKey";
import { describe, expect, it } from "vitest";

describe("createUniqueKey", () => {
Expand Down
9 changes: 6 additions & 3 deletions apps/updater/src/utils/createUpdateTask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import redis from "@/config/redis";
import type { ScheduleOptions, SchedulerName } from "@/config/schedulers";
import type { UpdaterResult } from "@/lib/updater";
import { AbortTaskRunError, logger, schedules } from "@trigger.dev/sdk/v3";
import redis from "@updater/config/redis";
import type {
ScheduleOptions,
SchedulerName,
} from "@updater/config/schedulers";
import type { UpdaterResult } from "@updater/lib/updater";

type UpdaterFunction = () => Promise<UpdaterResult>;

Expand Down
2 changes: 1 addition & 1 deletion apps/updater/src/utils/downloadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AWS_LAMBDA_TEMP_DIR } from "@/config";
import { AWS_LAMBDA_TEMP_DIR } from "@updater/config";
import AdmZip from "adm-zip";

export const downloadFile = async (url: string, csvFile?: string) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/updater/src/utils/redisCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import redis from "@/config/redis";
import redis from "@updater/config/redis";

/**
* Caches a checksum value for a given file name
Expand Down
10 changes: 2 additions & 8 deletions apps/updater/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@
"declaration": true,
"resolveJsonModule": true,
"paths": {
"@/*": ["./src/*"]
"@updater/*": ["src/*"]
},
"types": ["node"]
},
"include": [
"src/**/*",
"drizzle.config.ts",
"sst.config.ts",
"sst-env.d.ts",
"trigger.config.ts"
],
"include": ["*.ts"],
"exclude": ["node_modules", "dist"]
}
2 changes: 1 addition & 1 deletion apps/updater/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
"@updater": path.resolve(__dirname, "./src"),
},
},
test: {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"target": "ESNext",
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"moduleResolution": "bundler",
"skipLibCheck": true,
"verbatimModuleSyntax": true,
"paths": {
Expand Down

0 comments on commit debed9c

Please sign in to comment.