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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

```shell
pnpm i

# Start PostgreSQL and Redis for development
pnpm docker:up:dev

pnpm dev

cd apps/backend
Expand Down
19 changes: 3 additions & 16 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@metro-now/backend",
"scripts": {
"typegen": "ts-node ./src/scripts/generate-types.ts",
"prebuild": "rimraf dist && pnpm prisma:generate && pnpm typegen",
"prebuild": "rimraf dist && pnpm typegen",
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
"build": "nest build",
"start": "nest start",
"dev": "nest start --watch",
Expand All @@ -15,18 +15,13 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./e2e/jest-e2e.json",
"prisma:studio": "dotenv -e .env.local -- prisma studio",
"prisma:generate": "prisma generate",
"prisma:migrate:create": "dotenv -e .env.local -- prisma migrate dev",
"prisma:migrate:deploy": "dotenv -e .env.local -- prisma migrate deploy",
"prisma:push": "dotenv -e .env.local -- prisma db push",
"prisma:seed": "prisma db seed"
"test:e2e": "jest --config ./e2e/jest-e2e.json"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

test:e2e should prepare workspace deps too.

Line 16 now builds @metro-now/shared and @metro-now/database before Jest, but Line 20 still skips that step. After a clean checkout—or after changing either workspace package—pnpm test:e2e can still run against missing or stale output even though pnpm test passes.

🔁 Suggested fix
-        "test:e2e": "jest --config ./e2e/jest-e2e.json"
+        "test:e2e": "pnpm --filter `@metro-now/shared` build && pnpm --filter `@metro-now/database` build && jest --config ./e2e/jest-e2e.json"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"test:e2e": "jest --config ./e2e/jest-e2e.json"
"test:e2e": "pnpm --filter `@metro-now/shared` build && pnpm --filter `@metro-now/database` build && jest --config ./e2e/jest-e2e.json"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/backend/package.json` at line 20, The test:e2e npm script is missing the
workspace-prebuild step that ensures `@metro-now/shared` and `@metro-now/database`
are built; update the "test:e2e" script in package.json so it runs the same
prebuild command used by the regular test flow (build the workspace packages
`@metro-now/shared` and `@metro-now/database`) before invoking Jest (i.e., prepend
or incorporate the workspace build step that exists for the other test script so
test:e2e always builds those packages first).

},
"dependencies": {
"@apollo/server": "^4.11.3",
"@fast-csv/parse": "^5.0.2",
"@keyv/redis": "^4.3.3",
"@metro-now/database": "workspace:*",
"@nestjs/apollo": "^13.0.4",
"@nestjs/cache-manager": "^3.0.1",
"@nestjs/common": "^11.0.13",
Expand All @@ -36,7 +31,6 @@
"@nestjs/platform-express": "^11.0.13",
"@nestjs/schedule": "^5.0.1",
"@nestjs/swagger": "^11.1.1",
"@prisma/client": "5.20.0",
"cache-manager": "^6.4.2",
"dataloader": "^2.2.3",
"graphql": "^16.10.0",
Expand Down Expand Up @@ -74,10 +68,6 @@
"tsconfig-paths": "^4.2.0",
"typescript": "^5.8.3"
},
"optionalDependencies": {
"dotenv-cli": "^8.0.0",
"prisma": "^5.20.0"
},
"jest": {
"moduleFileExtensions": [
"js",
Expand All @@ -97,8 +87,5 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"prisma": {
"seed": "dotenv -e .env.local -- ts-node prisma/seed.ts"
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/modules/import/import.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { VehicleType } from "@prisma/client";
import { VehicleType } from "@metro-now/database";
import { unique } from "radash";

import {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/platform/platform.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { Prisma } from "@metro-now/database";

import { PlatformWithDistanceSchema } from "src/modules/platform/schema/platform-with-distance.schema";
import { PlatformSchema } from "src/modules/platform/schema/platform.schema";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common";
import { PrismaClient } from "@prisma/client";
import { PrismaClient } from "@metro-now/database";

@Injectable()
export class PrismaService
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/route/route.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { Prisma } from "@metro-now/database";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Prisma model types missing via @metro-now/database; generate and re‑export properly

The switch to @metro-now/database breaks model‑specific types (GtfsRouteSelect, GtfsRouteGetPayload, GtfsRouteWhereInput). This usually happens when the Prisma client in the database package hasn’t been generated or the Prisma namespace isn’t re‑exported as types. Ensure:

  • apps/database runs prisma generate (prepare/postinstall or via workspace script before backend build).
  • apps/database/index.ts explicitly re‑exports the Prisma namespace as types.

Minimal code tweak (type‑only import) to avoid value import, though the root cause still needs the generation step:

-import { Prisma } from "@metro-now/database";
+import type { Prisma } from "@metro-now/database";

To restore CI determinism, reintroduce a workspace generate step in backend prebuild (see package.json comment).

Run to verify database pkg wiring:


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "Check database index.ts re-exports:"
fd -a '^index\.(ts|tsx|cts|mts)$' apps/database | xargs -I{} sed -n '1,120p' {}
echo "Check prisma generate hooks in apps/database/package.json:"
jq -r '.scripts | to_entries[] | select(.key|test("prepare|postinstall|generate|prisma")).key + ": " + .value' apps/database/package.json || true
echo "Check root/workspace db scripts:"
jq -r '.scripts | to_entries[] | select(.key|test("^db:")).key + ": " + .value' package.json || true
echo "Check backend prebuild:"
jq -r '.scripts.prebuild' apps/backend/package.json

Length of output: 1252


Import Prisma types as type-only and run workspace prisma:generate before backend build

  • apps/database already re-exports @prisma/client (export * from "@prisma/client";) and contains a prisma:generate script; the root workspace has db:generate. apps/backend prebuild currently does not run it (rimraf dist && pnpm typegen).
  • Change the import in apps/backend/src/modules/route/route.service.ts to a type-only import:
-import { Prisma } from "@metro-now/database";
+import type { Prisma } from "@metro-now/database";
  • Add a workspace generate step to apps/backend/package.json prebuild so the generated client exists before building, e.g.
"prebuild": "rimraf dist && pnpm -w run db:generate && pnpm typegen"
🤖 Prompt for AI Agents
In apps/backend/src/modules/route/route.service.ts around line 2, the import of
Prisma is not marked type-only which can cause runtime dependency on the
generated Prisma client that may not exist; change the import to a type-only
import (e.g., "import type { Prisma } from ...") and update
apps/backend/package.json to run the workspace db:generate before build by
adding a prebuild script that ensures the generated client exists (for example
run rimraf dist && pnpm -w run db:generate && pnpm typegen) so the backend build
does not fail due to missing generated Prisma client.

import { group } from "radash";

import { PrismaService } from "src/modules/prisma/prisma.service";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/modules/stop/stop.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { Prisma } from "@metro-now/database";

import { platformSelect } from "src/modules/platform/platform.service";
import { PrismaService } from "src/modules/prisma/prisma.service";
Expand Down
1 change: 1 addition & 0 deletions apps/database/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgresql://postgres_user:postgres_password@localhost:5432/metro-now?schema=public"
1 change: 1 addition & 0 deletions apps/database/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@prisma/client";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Re-export Prisma namespace explicitly (unblocks compile errors for Prisma.sql/empty and generated model types).

Some TS setups don’t forward the namespace cleanly with export *. Explicit re-exports fix missing members like Prisma.sql, Prisma.empty, and model‑scoped types (e.g., PlatformSelect).

-export * from "@prisma/client";
+export { Prisma, PrismaClient } from "@prisma/client";
+export * from "@prisma/client";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export * from "@prisma/client";
export { Prisma, PrismaClient } from "@prisma/client";
export * from "@prisma/client";
🤖 Prompt for AI Agents
In apps/database/index.ts around line 1, re-exporting the entire Prisma package
with `export *` misses the Prisma namespace and some generated model types
(e.g., Prisma.sql, Prisma.empty, PlatformSelect); explicitly re-export the
Prisma namespace and any needed generated types from "@prisma/client" so
consumers can import Prisma.* and model-scoped types reliably (add an explicit
export for Prisma and export the specific generated types your codebase
requires).

29 changes: 29 additions & 0 deletions apps/database/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@metro-now/database",
"main": "index.ts",
"types": "index.ts",
"scripts": {
"prisma:studio": "dotenv -e ../backend/.env.local -- prisma studio",
"prisma:generate": "prisma generate",
"prisma:migrate:create": "dotenv -e ../backend/.env.local -- prisma migrate dev",
"prisma:migrate:deploy": "dotenv -e ../backend/.env.local -- prisma migrate deploy",
"prisma:push": "dotenv -e ../backend/.env.local -- prisma db push",
"prisma:seed": "prisma db seed",
"prisma:reset": "dotenv -e ../backend/.env.local -- prisma migrate reset",
"prisma:status": "dotenv -e ../backend/.env.local -- prisma migrate status"
},
"dependencies": {
"@prisma/client": "5.20.0"
},
"devDependencies": {
"typescript": "^5.8.3",
"ts-node": "^10.9.2"
},
"optionalDependencies": {
"dotenv-cli": "^8.0.0",
"prisma": "^5.20.0"
},
"prisma": {
"seed": "dotenv -e ../backend/.env.local -- ts-node prisma/seed.ts"
}
}
Comment on lines +1 to +23

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

🧩 Analysis chain

Publish built artifacts and generate Prisma client on install (prevents backend TS errors).

Point main/types to dist, add a build step, and run prisma generate automatically so downstream packages always see generated types (e.g., Prisma.PlatformSelect). Also keep Studio/migrate scripts.

 {
   "name": "@metro-now/database",
-  "main": "index.ts",
-  "types": "index.ts",
+  "main": "dist/index.js",
+  "types": "dist/index.d.ts",
   "scripts": {
+    "build": "tsc -p tsconfig.json",
+    "prepare": "pnpm run build",
+    "postinstall": "pnpm run prisma:generate",
     "prisma:studio": "dotenv -e ../backend/.env.local -- prisma studio",
     "prisma:generate": "prisma generate",
     "prisma:migrate:create": "dotenv -e ../backend/.env.local -- prisma migrate dev",
     "prisma:migrate:deploy": "dotenv -e ../backend/.env.local -- prisma migrate deploy",
     "prisma:push": "dotenv -e ../backend/.env.local -- prisma db push",
     "prisma:seed": "prisma db seed",
     "prisma:reset": "dotenv -e ../backend/.env.local -- prisma migrate reset",
     "prisma:status": "dotenv -e ../backend/.env.local -- prisma migrate status"
   },

Optional: add an exports map for Node resolution hygiene.


🏁 Script executed:

#!/bin/bash
set -euo pipefail
echo "PWD: $(pwd)"
echo "---- root package.json (upto 200 lines) ----"
[ -f package.json ] && sed -n '1,200p' package.json || echo "no root package.json"
echo "---- apps/database/package.json ----"
[ -f apps/database/package.json ] && sed -n '1,200p' apps/database/package.json || echo "no apps/database/package.json"
echo "---- apps/database listing ----"
ls -la apps/database || true
echo "---- apps/database/tsconfig.json ----"
[ -f apps/database/tsconfig.json ] && sed -n '1,200p' apps/database/tsconfig.json || echo "no apps/database/tsconfig.json"
echo "---- root tsconfig.json ----"
[ -f tsconfig.json ] && sed -n '1,200p' tsconfig.json || echo "no root tsconfig.json"
echo "---- apps/database/dist exists? ----"
[ -d apps/database/dist ] && { echo "dist exists:"; ls -la apps/database/dist || true; } || echo "no apps/database/dist"
echo "---- search repo for prisma/schema and related scripts ----"
rg -n --hidden --glob '!node_modules/**' "schema.prisma|prisma generate|prisma:generate|prisma:studio" || true
echo "---- search repo for @metro-now/database usage ----"
rg -n --hidden --glob '!node_modules/**' "@metro-now/database" || true
echo "---- search for 'main\": \"index.ts' occurrences ----"
rg -n --hidden --glob '!node_modules/**' '"main"\s*:\s*"index\.ts"' || true
echo "---- search for prepare/postinstall/build scripts ----"
rg -n --hidden --glob '!node_modules/**' '"prepare"\s*:|"postinstall"\s*:|"build"\s*:' || true
echo "---- pnpm markers ----"
[ -f pnpm-workspace.yaml ] && echo "pnpm-workspace.yaml present" || echo "no pnpm-workspace.yaml"
[ -f pnpm-lock.yaml ] && echo "pnpm-lock.yaml present" || echo "no pnpm-lock.yaml"
rg -n --hidden --glob '!node_modules/**' '"packageManager"\s*:\s*".*pnpm' || true
echo "---- done ----"

Length of output: 5392


Publish built artifacts and run Prisma generate on install

tsconfig outputs to ./dist but package.json points at index.ts and has no build — add build/prepare/postinstall so workspace builds the package and generated Prisma types are present.

File: apps/database/package.json

 {
   "name": "@metro-now/database",
-  "main": "index.ts",
-  "types": "index.ts",
+  "main": "dist/index.js",
+  "types": "dist/index.d.ts",
   "scripts": {
+    "build": "tsc -p tsconfig.json",
+    "prepare": "pnpm run build",
+    "postinstall": "pnpm run prisma:generate",
     "prisma:studio": "dotenv -e ../backend/.env.local -- prisma studio",
     "prisma:generate": "prisma generate",
     "prisma:migrate:create": "dotenv -e ../backend/.env.local -- prisma migrate dev",
     "prisma:migrate:deploy": "dotenv -e ../backend/.env.local -- prisma migrate deploy",
     "prisma:push": "dotenv -e ../backend/.env.local -- prisma db push",
     "prisma:seed": "prisma db seed",
     "prisma:reset": "dotenv -e ../backend/.env.local -- prisma migrate reset",
     "prisma:status": "dotenv -e ../backend/.env.local -- prisma migrate status"
   },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"name": "@metro-now/database",
"main": "index.ts",
"types": "index.ts",
"scripts": {
"prisma:studio": "dotenv -e ../backend/.env.local -- prisma studio",
"prisma:generate": "prisma generate",
"prisma:migrate:create": "dotenv -e ../backend/.env.local -- prisma migrate dev",
"prisma:migrate:deploy": "dotenv -e ../backend/.env.local -- prisma migrate deploy",
"prisma:push": "dotenv -e ../backend/.env.local -- prisma db push",
"prisma:seed": "prisma db seed",
"prisma:reset": "dotenv -e ../backend/.env.local -- prisma migrate reset",
"prisma:status": "dotenv -e ../backend/.env.local -- prisma migrate status"
},
"dependencies": {
"@prisma/client": "5.20.0"
},
"devDependencies": {
"typescript": "^5.8.3",
"ts-node": "^10.9.2"
},
"optionalDependencies": {
"dotenv-cli": "^8.0.0",
"prisma": "^5.20.0"
},
"prisma": {
"seed": "dotenv -e ../backend/.env.local -- ts-node prisma/seed.ts"
}
}
{
"name": "@metro-now/database",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.json",
"prepare": "pnpm run build",
"postinstall": "pnpm run prisma:generate",
"prisma:studio": "dotenv -e ../backend/.env.local -- prisma studio",
"prisma:generate": "prisma generate",
"prisma:migrate:create": "dotenv -e ../backend/.env.local -- prisma migrate dev",
"prisma:migrate:deploy": "dotenv -e ../backend/.env.local -- prisma migrate deploy",
"prisma:push": "dotenv -e ../backend/.env.local -- prisma db push",
"prisma:seed": "prisma db seed",
"prisma:reset": "dotenv -e ../backend/.env.local -- prisma migrate reset",
"prisma:status": "dotenv -e ../backend/.env.local -- prisma migrate status"
},
"dependencies": {
"@prisma/client": "5.20.0"
},
"devDependencies": {
"typescript": "^5.8.3",
"ts-node": "^10.9.2"
},
"optionalDependencies": {
"dotenv-cli": "^8.0.0",
"prisma": "^5.20.0"
},
"prisma": {
"seed": "dotenv -e ../backend/.env.local -- ts-node prisma/seed.ts"
}
}
🤖 Prompt for AI Agents
In apps/database/package.json (lines 1-29) the package currently points at
source files (index.ts) and lacks build/prepare/postinstall hooks so published
package won't include compiled output or generated Prisma types; update
package.json to point main/types to the compiled outputs (e.g., dist/index.js
and dist/index.d.ts), add a "build" script to compile TypeScript to ./dist, add
a "prepare" (or "prepublishOnly") script that runs the build, and add a
"postinstall" script that runs prisma generate (or a combined script that
sources ../backend/.env.local then runs prisma generate) so Prisma client types
are generated on install; ensure dev/optional deps used for these steps are
available in the workspace or move prisma/@prisma/client to proper dependency if
needed.

File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions apps/database/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["ES2020"],
"outDir": "./dist",
"rootDir": "./",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true
},
"include": ["index.ts", "prisma/**/*"],
"exclude": ["node_modules", "dist"]
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
"backend:build": "pnpm run -r --filter @metro-now/backend build",
"backend:dev": "pnpm run -r --filter @metro-now/backend dev",
"web:dev": "pnpm run -r --filter @metro-now/web dev",
"db:studio": "pnpm run -r --filter @metro-now/database prisma:studio",
"db:generate": "pnpm run -r --filter @metro-now/database prisma:generate",
"db:migrate:create": "pnpm run -r --filter @metro-now/database prisma:migrate:create",
"db:migrate:deploy": "pnpm run -r --filter @metro-now/database prisma:migrate:deploy",
"db:push": "pnpm run -r --filter @metro-now/database prisma:push",
"db:seed": "pnpm run -r --filter @metro-now/database prisma:seed",
"db:reset": "pnpm run -r --filter @metro-now/database prisma:reset",
"db:status": "pnpm run -r --filter @metro-now/database prisma:status",
"precommit": "pnpm format",
"format": "pnpm --recursive --parallel format && pnpm exec prettier . --write",
"app:format": "pnpm --filter @metro-now/mobile format",
Expand Down
33 changes: 23 additions & 10 deletions pnpm-lock.yaml

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

Loading