kyush-llm-router/server/package.json
JellyBrick 18edad1085
refactor(server): centralise schema-file resolution + drop dead copy step
The three DB modules each carried their own copy-pasted
`path.join(moduleDir, '..', '..', '..', 'database', '<name>.sql')` to
locate the SQL schemas. That worked, but only by coincidence: the same
`../../../` count happened to land on `dist/` under the old compiled
runtime AND on the repo root under the new tsx runtime, because the file
lives at the same depth in both layouts. Move the file (or change the
run mode) and it silently breaks in three places at once.

Replace the per-file path math with a single `getSchemaPath(filename)`
helper in `db-paths.ts` that resolves against `import.meta.url`:

  const SCHEMA_DIR_URL = new URL('../../../database/', import.meta.url);
  export const getSchemaPath = (filename) =>
    fileURLToPath(new URL(filename, SCHEMA_DIR_URL));

- One place for the relative-path arithmetic (locally verifiable, no
  parallel copies to keep in sync).
- Anchored on the module's own URL, so the resolution is correct
  regardless of whether tsx, a future bundler, or `node` runs it.
- `database.ts` / `analytics-db.ts` / `request-logs-db.ts` all become
  one-liners: `fs.readFileSync(getSchemaPath('schema.sql'), 'utf-8')`.

Drop `server/scripts/copy-schemas.mjs` entirely — it was the build step
that used to populate `dist/database/` for the compiled runtime, but
since the previous commit switched `start` to `tsx src/main.ts` we read
the SQL directly from the source `database/` dir. The script has been
producing dead copies on every build. The empty `server/scripts/`
directory goes too, and `package.json`'s `build` script collapses to
just `tsc --noEmit`.

Verified by booting via tsx (all schemas load) and by running the
integration test suite that exercises every DB module — 59/59 passing.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-04-08 02:37:20 +09:00

45 lines
1.1 KiB
JSON

{
"name": "server",
"version": "1.0.0",
"description": "LLM Router Server",
"main": "src/main.ts",
"type": "module",
"scripts": {
"build": "tsc --noEmit",
"start": "tsx src/main.ts",
"dev": "tsx watch src/main.ts",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"bench": "tsx benchmarks/index.ts",
"sandbox": "tsx src/services/sandbox.ts"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@hono/node-server": "^1.13.7",
"@hono/swagger-ui": "^0.5.0",
"@hono/zod-openapi": "^0.18.0",
"@hono/zod-validator": "^0.4.2",
"@kyush/shared": "workspace:*",
"better-sqlite3": "^12.6.2",
"dotenv": "^17.3.1",
"es-toolkit": "^1.32.0",
"hono": "^4.6.14",
"isolated-vm": "^6.0.2",
"node-fetch": "^3.3.2",
"tsx": "^4.21.0",
"zod": "^3.23.8"
},
"devDependencies": {
"@total-typescript/ts-reset": "^0.6.1",
"@types/better-sqlite3": "^7.6.13",
"@types/node": "^25.3.3",
"chalk": "^5.6.0",
"cli-table3": "^0.6.5",
"commander": "^14.0.0",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
}
}