postgresdk 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -52
- package/dist/cli.js +58 -20
- package/dist/index.js +53 -15
- package/package.json +1 -1
package/README.md
CHANGED
@@ -43,7 +43,7 @@ Get a complete, type-safe SDK with:
|
|
43
43
|
### 🎯 Client SDK with Full TypeScript Support
|
44
44
|
|
45
45
|
```typescript
|
46
|
-
import { SDK } from "./
|
46
|
+
import { SDK } from "./api/client";
|
47
47
|
|
48
48
|
const sdk = new SDK({
|
49
49
|
baseUrl: "http://localhost:3000",
|
@@ -89,7 +89,7 @@ const recentBooks = await sdk.books.list({
|
|
89
89
|
```typescript
|
90
90
|
import { Hono } from "hono";
|
91
91
|
import { Client } from "pg";
|
92
|
-
import { createRouter } from "./
|
92
|
+
import { createRouter } from "./api/server/router";
|
93
93
|
|
94
94
|
const app = new Hono();
|
95
95
|
const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -124,7 +124,7 @@ const book = await sdk.books.create({
|
|
124
124
|
});
|
125
125
|
|
126
126
|
// Generated Zod schemas for runtime validation
|
127
|
-
import { InsertBooksSchema } from "./
|
127
|
+
import { InsertBooksSchema } from "./api/server/zod/books";
|
128
128
|
|
129
129
|
const validated = InsertBooksSchema.parse(requestBody);
|
130
130
|
```
|
@@ -182,7 +182,7 @@ postgresdk generate
|
|
182
182
|
// Server (Hono)
|
183
183
|
import { Hono } from "hono";
|
184
184
|
import { Client } from "pg";
|
185
|
-
import { registerUsersRoutes } from "./
|
185
|
+
import { registerUsersRoutes } from "./api/server/routes/users";
|
186
186
|
|
187
187
|
const app = new Hono();
|
188
188
|
const pg = new Client({ connectionString: "..." });
|
@@ -191,7 +191,7 @@ await pg.connect();
|
|
191
191
|
registerUsersRoutes(app, { pg });
|
192
192
|
|
193
193
|
// Client
|
194
|
-
import { SDK } from "./
|
194
|
+
import { SDK } from "./api/client";
|
195
195
|
|
196
196
|
const sdk = new SDK({ baseUrl: "http://localhost:3000" });
|
197
197
|
|
@@ -213,8 +213,8 @@ export default {
|
|
213
213
|
|
214
214
|
// Optional (with defaults)
|
215
215
|
schema: "public", // Database schema to introspect
|
216
|
-
outServer: "./
|
217
|
-
outClient: "./
|
216
|
+
outServer: "./api/server", // Server code output directory
|
217
|
+
outClient: "./api/client", // Client SDK output directory
|
218
218
|
softDeleteColumn: null, // Column name for soft deletes (e.g., "deleted_at")
|
219
219
|
includeDepthLimit: 3, // Max depth for nested includes
|
220
220
|
dateType: "date", // "date" | "string" - How to handle timestamps
|
@@ -507,7 +507,7 @@ Server setup:
|
|
507
507
|
```typescript
|
508
508
|
import { Hono } from "hono";
|
509
509
|
import { Client } from "pg";
|
510
|
-
import { createRouter } from "./
|
510
|
+
import { createRouter } from "./api/server/router";
|
511
511
|
|
512
512
|
const app = new Hono();
|
513
513
|
|
@@ -540,7 +540,7 @@ Server setup:
|
|
540
540
|
```typescript
|
541
541
|
import { Hono } from "hono";
|
542
542
|
import { Pool } from "@neondatabase/serverless";
|
543
|
-
import { createRouter } from "./
|
543
|
+
import { createRouter } from "./api/server/router";
|
544
544
|
|
545
545
|
const app = new Hono();
|
546
546
|
|
@@ -577,7 +577,7 @@ For production Node.js deployments, use connection pooling:
|
|
577
577
|
|
578
578
|
```typescript
|
579
579
|
import { Pool } from "pg";
|
580
|
-
import { createRouter } from "./
|
580
|
+
import { createRouter } from "./api/server/router";
|
581
581
|
|
582
582
|
const pool = new Pool({
|
583
583
|
connectionString: process.env.DATABASE_URL,
|
@@ -627,7 +627,7 @@ postgresdk generates a `createRouter` function that returns a Hono router with a
|
|
627
627
|
import { Hono } from "hono";
|
628
628
|
import { serve } from "@hono/node-server";
|
629
629
|
import { Client } from "pg";
|
630
|
-
import { createRouter } from "./
|
630
|
+
import { createRouter } from "./api/server/router";
|
631
631
|
|
632
632
|
const app = new Hono();
|
633
633
|
|
@@ -650,7 +650,7 @@ The `createRouter` function returns a Hono router that can be mounted anywhere:
|
|
650
650
|
|
651
651
|
```typescript
|
652
652
|
import { Hono } from "hono";
|
653
|
-
import { createRouter } from "./
|
653
|
+
import { createRouter } from "./api/server/router";
|
654
654
|
|
655
655
|
const app = new Hono();
|
656
656
|
|
@@ -671,7 +671,7 @@ app.route("/v2", apiRouter); // Routes will be at /v2/v1/users, /v2/v1/posts,
|
|
671
671
|
If you prefer to register routes directly on your app without a sub-router:
|
672
672
|
|
673
673
|
```typescript
|
674
|
-
import { registerAllRoutes } from "./
|
674
|
+
import { registerAllRoutes } from "./api/server/router";
|
675
675
|
|
676
676
|
const app = new Hono();
|
677
677
|
const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -686,7 +686,7 @@ registerAllRoutes(app, { pg });
|
|
686
686
|
You can also import and register individual routes:
|
687
687
|
|
688
688
|
```typescript
|
689
|
-
import { registerUsersRoutes, registerPostsRoutes } from "./
|
689
|
+
import { registerUsersRoutes, registerPostsRoutes } from "./api/server/router";
|
690
690
|
|
691
691
|
const app = new Hono();
|
692
692
|
|
@@ -717,8 +717,8 @@ const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
|
717
717
|
await pg.connect();
|
718
718
|
|
719
719
|
// All generated routes are prefixed with /v1 by default
|
720
|
-
import { registerUsersRoutes } from "./
|
721
|
-
import { registerPostsRoutes } from "./
|
720
|
+
import { registerUsersRoutes } from "./api/server/routes/users";
|
721
|
+
import { registerPostsRoutes } from "./api/server/routes/posts";
|
722
722
|
|
723
723
|
registerUsersRoutes(app, { pg }); // Adds /v1/users/*
|
724
724
|
registerPostsRoutes(app, { pg }); // Adds /v1/posts/*
|
@@ -756,7 +756,7 @@ app.use("*", async (c, next) => {
|
|
756
756
|
const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
757
757
|
await pg.connect();
|
758
758
|
|
759
|
-
import { registerUsersRoutes } from "./
|
759
|
+
import { registerUsersRoutes } from "./api/server/routes/users";
|
760
760
|
registerUsersRoutes(app, { pg });
|
761
761
|
```
|
762
762
|
|
@@ -779,8 +779,8 @@ const pool = new Pool({
|
|
779
779
|
const app = new Hono();
|
780
780
|
|
781
781
|
// The generated routes work with both Client and Pool
|
782
|
-
import { registerUsersRoutes } from "./
|
783
|
-
import { registerPostsRoutes } from "./
|
782
|
+
import { registerUsersRoutes } from "./api/server/routes/users";
|
783
|
+
import { registerPostsRoutes } from "./api/server/routes/posts";
|
784
784
|
|
785
785
|
registerUsersRoutes(app, { pg: pool });
|
786
786
|
registerPostsRoutes(app, { pg: pool });
|
@@ -831,9 +831,9 @@ import { serve } from "@hono/node-server";
|
|
831
831
|
import { Pool } from "pg";
|
832
832
|
|
833
833
|
// Import all generated route registrations
|
834
|
-
import { registerUsersRoutes } from "./
|
835
|
-
import { registerPostsRoutes } from "./
|
836
|
-
import { registerCommentsRoutes } from "./
|
834
|
+
import { registerUsersRoutes } from "./api/server/routes/users";
|
835
|
+
import { registerPostsRoutes } from "./api/server/routes/posts";
|
836
|
+
import { registerCommentsRoutes } from "./api/server/routes/comments";
|
837
837
|
|
838
838
|
// Create app with type safety
|
839
839
|
const app = new Hono();
|
@@ -988,7 +988,7 @@ export default {
|
|
988
988
|
|
989
989
|
tests: {
|
990
990
|
generate: true, // Enable test generation
|
991
|
-
output: "./
|
991
|
+
output: "./api/tests", // Output directory
|
992
992
|
framework: "vitest" // Test framework (vitest, jest, or bun)
|
993
993
|
}
|
994
994
|
};
|
@@ -1005,38 +1005,30 @@ When tests are enabled, postgresdk generates:
|
|
1005
1005
|
|
1006
1006
|
### Running Tests with Docker
|
1007
1007
|
|
1008
|
-
The generated
|
1008
|
+
The generated test setup includes a Docker Compose file and a test runner script:
|
1009
1009
|
|
1010
1010
|
```bash
|
1011
|
-
#
|
1012
|
-
|
1013
|
-
|
1014
|
-
#
|
1015
|
-
|
1016
|
-
|
1017
|
-
#
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
#
|
1025
|
-
#
|
1026
|
-
|
1027
|
-
#
|
1028
|
-
npm run dev &
|
1029
|
-
|
1030
|
-
# Run tests
|
1031
|
-
npm test
|
1032
|
-
|
1033
|
-
# Stop database when done
|
1034
|
-
docker-compose down
|
1035
|
-
|
1036
|
-
# Or use the generated script
|
1037
|
-
bash run-tests.sh
|
1011
|
+
# 1. Make the test script executable (first time only)
|
1012
|
+
chmod +x api/tests/run-tests.sh
|
1013
|
+
|
1014
|
+
# 2. Edit api/tests/run-tests.sh to configure:
|
1015
|
+
# - Your API server startup command
|
1016
|
+
# - Migration commands (if needed)
|
1017
|
+
# - Any other setup specific to your project
|
1018
|
+
|
1019
|
+
# 3. Run the tests
|
1020
|
+
./api/tests/run-tests.sh
|
1021
|
+
|
1022
|
+
# The script will:
|
1023
|
+
# - Start a PostgreSQL 17 test database in Docker
|
1024
|
+
# - Wait for it to be ready
|
1025
|
+
# - Run your API server (once configured)
|
1026
|
+
# - Execute the test suite
|
1027
|
+
# - Provide cleanup instructions
|
1038
1028
|
```
|
1039
1029
|
|
1030
|
+
The test script includes detailed comments and examples for common setups. You'll need to uncomment and customize the API server startup section for your specific project.
|
1031
|
+
|
1040
1032
|
### Customizing Tests
|
1041
1033
|
|
1042
1034
|
The generated tests are basic and meant as a starting point. Create your own test files for:
|
@@ -1052,7 +1044,7 @@ Example custom test:
|
|
1052
1044
|
```typescript
|
1053
1045
|
// tests/custom/user-workflow.test.ts
|
1054
1046
|
import { describe, it, expect } from 'vitest';
|
1055
|
-
import { createTestSDK, randomEmail } from '../
|
1047
|
+
import { createTestSDK, randomEmail } from '../api/tests/setup';
|
1056
1048
|
|
1057
1049
|
describe('User Registration Workflow', () => {
|
1058
1050
|
const sdk = createTestSDK();
|
package/dist/cli.js
CHANGED
@@ -535,15 +535,15 @@ export default {
|
|
535
535
|
|
536
536
|
/**
|
537
537
|
* Output directory for server-side code (routes, validators, etc.)
|
538
|
-
* @default "./
|
538
|
+
* @default "./api/server"
|
539
539
|
*/
|
540
|
-
// outServer: "./
|
540
|
+
// outServer: "./api/server",
|
541
541
|
|
542
542
|
/**
|
543
543
|
* Output directory for client SDK
|
544
|
-
* @default "./
|
544
|
+
* @default "./api/client"
|
545
545
|
*/
|
546
|
-
// outClient: "./
|
546
|
+
// outClient: "./api/client",
|
547
547
|
|
548
548
|
// ========== ADVANCED OPTIONS ==========
|
549
549
|
|
@@ -598,7 +598,7 @@ export default {
|
|
598
598
|
*/
|
599
599
|
// tests: {
|
600
600
|
// generate: true,
|
601
|
-
// output: "./
|
601
|
+
// output: "./api/tests",
|
602
602
|
// framework: "vitest" // or "jest" or "bun"
|
603
603
|
// },
|
604
604
|
|
@@ -2428,7 +2428,7 @@ version: '3.8'
|
|
2428
2428
|
|
2429
2429
|
services:
|
2430
2430
|
postgres:
|
2431
|
-
image: postgres:
|
2431
|
+
image: postgres:17-alpine
|
2432
2432
|
environment:
|
2433
2433
|
POSTGRES_USER: testuser
|
2434
2434
|
POSTGRES_PASSWORD: testpass
|
@@ -2452,11 +2452,23 @@ function emitTestScript(framework = "vitest") {
|
|
2452
2452
|
return `#!/bin/bash
|
2453
2453
|
# Test Runner Script
|
2454
2454
|
#
|
2455
|
-
# This script sets up and runs tests with a Docker PostgreSQL database
|
2455
|
+
# This script sets up and runs tests with a Docker PostgreSQL database.
|
2456
|
+
#
|
2457
|
+
# Usage:
|
2458
|
+
# chmod +x run-tests.sh # Make executable (first time only)
|
2459
|
+
# ./run-tests.sh
|
2460
|
+
#
|
2461
|
+
# Prerequisites:
|
2462
|
+
# - Docker installed and running
|
2463
|
+
# - Your API server code in the parent directories
|
2464
|
+
# - Test framework installed (${framework})
|
2456
2465
|
|
2457
2466
|
set -e
|
2458
2467
|
|
2468
|
+
SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
|
2469
|
+
|
2459
2470
|
echo "\uD83D\uDC33 Starting test database..."
|
2471
|
+
cd "$SCRIPT_DIR"
|
2460
2472
|
docker-compose up -d --wait
|
2461
2473
|
|
2462
2474
|
# Export test database URL
|
@@ -2465,24 +2477,43 @@ export TEST_API_URL="http://localhost:3000"
|
|
2465
2477
|
|
2466
2478
|
# Wait for database to be ready
|
2467
2479
|
echo "⏳ Waiting for database..."
|
2468
|
-
sleep
|
2480
|
+
sleep 3
|
2469
2481
|
|
2470
|
-
# Run migrations
|
2471
|
-
#
|
2482
|
+
# TODO: Run your migrations on the test database
|
2483
|
+
# Example:
|
2484
|
+
# echo "\uD83D\uDCCA Running migrations..."
|
2485
|
+
# npm run migrate -- --database-url="$TEST_DATABASE_URL"
|
2472
2486
|
|
2473
2487
|
echo "\uD83D\uDE80 Starting API server..."
|
2474
|
-
|
2475
|
-
|
2488
|
+
echo "⚠️ TODO: Uncomment and customize the API server startup command below:"
|
2489
|
+
echo ""
|
2490
|
+
echo " # Example for Node.js/Bun:"
|
2491
|
+
echo " # cd ../.. && npm run dev &"
|
2492
|
+
echo " # SERVER_PID=$!"
|
2493
|
+
echo ""
|
2494
|
+
echo " # Example for custom server file:"
|
2495
|
+
echo " # cd ../.. && node server.js &"
|
2496
|
+
echo " # SERVER_PID=$!"
|
2497
|
+
echo ""
|
2498
|
+
echo " Please edit this script to start your API server."
|
2499
|
+
echo ""
|
2500
|
+
# cd ../.. && npm run dev &
|
2476
2501
|
# SERVER_PID=$!
|
2477
2502
|
# sleep 3
|
2478
2503
|
|
2479
2504
|
echo "\uD83E\uDDEA Running tests..."
|
2480
|
-
${runCommand} $@
|
2505
|
+
${runCommand} "$@"
|
2481
2506
|
|
2482
2507
|
# Cleanup
|
2483
|
-
#
|
2508
|
+
# if [ ! -z "\${SERVER_PID}" ]; then
|
2509
|
+
# echo "\uD83D\uDED1 Stopping API server..."
|
2510
|
+
# kill $SERVER_PID 2>/dev/null || true
|
2511
|
+
# fi
|
2484
2512
|
|
2485
2513
|
echo "✅ Tests completed!"
|
2514
|
+
echo ""
|
2515
|
+
echo "To stop the test database, run:"
|
2516
|
+
echo " cd $SCRIPT_DIR && docker-compose down"
|
2486
2517
|
`;
|
2487
2518
|
}
|
2488
2519
|
function getFrameworkImports(framework) {
|
@@ -2682,8 +2713,8 @@ async function generate(configPath) {
|
|
2682
2713
|
const model = await introspect(cfg.connectionString, cfg.schema || "public");
|
2683
2714
|
console.log("\uD83D\uDD17 Building relationship graph...");
|
2684
2715
|
const graph = buildGraph(model);
|
2685
|
-
const serverDir = cfg.outServer || "./
|
2686
|
-
const originalClientDir = cfg.outClient || "./
|
2716
|
+
const serverDir = cfg.outServer || "./api/server";
|
2717
|
+
const originalClientDir = cfg.outClient || "./api/client";
|
2687
2718
|
const sameDirectory = serverDir === originalClientDir;
|
2688
2719
|
let clientDir = originalClientDir;
|
2689
2720
|
if (sameDirectory) {
|
@@ -2692,7 +2723,11 @@ async function generate(configPath) {
|
|
2692
2723
|
const normDateType = cfg.dateType === "string" ? "string" : "date";
|
2693
2724
|
const serverFramework = cfg.serverFramework || "hono";
|
2694
2725
|
const generateTests = cfg.tests?.generate ?? false;
|
2695
|
-
const
|
2726
|
+
const originalTestDir = cfg.tests?.output || "./api/tests";
|
2727
|
+
let testDir = originalTestDir;
|
2728
|
+
if (generateTests && (originalTestDir === serverDir || originalTestDir === originalClientDir)) {
|
2729
|
+
testDir = join(originalTestDir, "tests");
|
2730
|
+
}
|
2696
2731
|
const testFramework = cfg.tests?.framework || "vitest";
|
2697
2732
|
console.log("\uD83D\uDCC1 Creating directories...");
|
2698
2733
|
const dirs = [
|
@@ -2800,9 +2835,12 @@ async function generate(configPath) {
|
|
2800
2835
|
console.log(` Server: ${serverDir}`);
|
2801
2836
|
console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
|
2802
2837
|
if (generateTests) {
|
2803
|
-
|
2804
|
-
console.log(`
|
2805
|
-
console.log(` \
|
2838
|
+
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2839
|
+
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2840
|
+
console.log(` \uD83D\uDCDD Test setup:`);
|
2841
|
+
console.log(` 1. Make script executable: chmod +x ${testDir}/run-tests.sh`);
|
2842
|
+
console.log(` 2. Edit the script to configure your API server startup`);
|
2843
|
+
console.log(` 3. Run tests: ${testDir}/run-tests.sh`);
|
2806
2844
|
}
|
2807
2845
|
}
|
2808
2846
|
|
package/dist/index.js
CHANGED
@@ -2158,7 +2158,7 @@ version: '3.8'
|
|
2158
2158
|
|
2159
2159
|
services:
|
2160
2160
|
postgres:
|
2161
|
-
image: postgres:
|
2161
|
+
image: postgres:17-alpine
|
2162
2162
|
environment:
|
2163
2163
|
POSTGRES_USER: testuser
|
2164
2164
|
POSTGRES_PASSWORD: testpass
|
@@ -2182,11 +2182,23 @@ function emitTestScript(framework = "vitest") {
|
|
2182
2182
|
return `#!/bin/bash
|
2183
2183
|
# Test Runner Script
|
2184
2184
|
#
|
2185
|
-
# This script sets up and runs tests with a Docker PostgreSQL database
|
2185
|
+
# This script sets up and runs tests with a Docker PostgreSQL database.
|
2186
|
+
#
|
2187
|
+
# Usage:
|
2188
|
+
# chmod +x run-tests.sh # Make executable (first time only)
|
2189
|
+
# ./run-tests.sh
|
2190
|
+
#
|
2191
|
+
# Prerequisites:
|
2192
|
+
# - Docker installed and running
|
2193
|
+
# - Your API server code in the parent directories
|
2194
|
+
# - Test framework installed (${framework})
|
2186
2195
|
|
2187
2196
|
set -e
|
2188
2197
|
|
2198
|
+
SCRIPT_DIR="$( cd "$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
|
2199
|
+
|
2189
2200
|
echo "\uD83D\uDC33 Starting test database..."
|
2201
|
+
cd "$SCRIPT_DIR"
|
2190
2202
|
docker-compose up -d --wait
|
2191
2203
|
|
2192
2204
|
# Export test database URL
|
@@ -2195,24 +2207,43 @@ export TEST_API_URL="http://localhost:3000"
|
|
2195
2207
|
|
2196
2208
|
# Wait for database to be ready
|
2197
2209
|
echo "⏳ Waiting for database..."
|
2198
|
-
sleep
|
2210
|
+
sleep 3
|
2199
2211
|
|
2200
|
-
# Run migrations
|
2201
|
-
#
|
2212
|
+
# TODO: Run your migrations on the test database
|
2213
|
+
# Example:
|
2214
|
+
# echo "\uD83D\uDCCA Running migrations..."
|
2215
|
+
# npm run migrate -- --database-url="$TEST_DATABASE_URL"
|
2202
2216
|
|
2203
2217
|
echo "\uD83D\uDE80 Starting API server..."
|
2204
|
-
|
2205
|
-
|
2218
|
+
echo "⚠️ TODO: Uncomment and customize the API server startup command below:"
|
2219
|
+
echo ""
|
2220
|
+
echo " # Example for Node.js/Bun:"
|
2221
|
+
echo " # cd ../.. && npm run dev &"
|
2222
|
+
echo " # SERVER_PID=$!"
|
2223
|
+
echo ""
|
2224
|
+
echo " # Example for custom server file:"
|
2225
|
+
echo " # cd ../.. && node server.js &"
|
2226
|
+
echo " # SERVER_PID=$!"
|
2227
|
+
echo ""
|
2228
|
+
echo " Please edit this script to start your API server."
|
2229
|
+
echo ""
|
2230
|
+
# cd ../.. && npm run dev &
|
2206
2231
|
# SERVER_PID=$!
|
2207
2232
|
# sleep 3
|
2208
2233
|
|
2209
2234
|
echo "\uD83E\uDDEA Running tests..."
|
2210
|
-
${runCommand} $@
|
2235
|
+
${runCommand} "$@"
|
2211
2236
|
|
2212
2237
|
# Cleanup
|
2213
|
-
#
|
2238
|
+
# if [ ! -z "\${SERVER_PID}" ]; then
|
2239
|
+
# echo "\uD83D\uDED1 Stopping API server..."
|
2240
|
+
# kill $SERVER_PID 2>/dev/null || true
|
2241
|
+
# fi
|
2214
2242
|
|
2215
2243
|
echo "✅ Tests completed!"
|
2244
|
+
echo ""
|
2245
|
+
echo "To stop the test database, run:"
|
2246
|
+
echo " cd $SCRIPT_DIR && docker-compose down"
|
2216
2247
|
`;
|
2217
2248
|
}
|
2218
2249
|
function getFrameworkImports(framework) {
|
@@ -2412,8 +2443,8 @@ async function generate(configPath) {
|
|
2412
2443
|
const model = await introspect(cfg.connectionString, cfg.schema || "public");
|
2413
2444
|
console.log("\uD83D\uDD17 Building relationship graph...");
|
2414
2445
|
const graph = buildGraph(model);
|
2415
|
-
const serverDir = cfg.outServer || "./
|
2416
|
-
const originalClientDir = cfg.outClient || "./
|
2446
|
+
const serverDir = cfg.outServer || "./api/server";
|
2447
|
+
const originalClientDir = cfg.outClient || "./api/client";
|
2417
2448
|
const sameDirectory = serverDir === originalClientDir;
|
2418
2449
|
let clientDir = originalClientDir;
|
2419
2450
|
if (sameDirectory) {
|
@@ -2422,7 +2453,11 @@ async function generate(configPath) {
|
|
2422
2453
|
const normDateType = cfg.dateType === "string" ? "string" : "date";
|
2423
2454
|
const serverFramework = cfg.serverFramework || "hono";
|
2424
2455
|
const generateTests = cfg.tests?.generate ?? false;
|
2425
|
-
const
|
2456
|
+
const originalTestDir = cfg.tests?.output || "./api/tests";
|
2457
|
+
let testDir = originalTestDir;
|
2458
|
+
if (generateTests && (originalTestDir === serverDir || originalTestDir === originalClientDir)) {
|
2459
|
+
testDir = join(originalTestDir, "tests");
|
2460
|
+
}
|
2426
2461
|
const testFramework = cfg.tests?.framework || "vitest";
|
2427
2462
|
console.log("\uD83D\uDCC1 Creating directories...");
|
2428
2463
|
const dirs = [
|
@@ -2530,9 +2565,12 @@ async function generate(configPath) {
|
|
2530
2565
|
console.log(` Server: ${serverDir}`);
|
2531
2566
|
console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
|
2532
2567
|
if (generateTests) {
|
2533
|
-
|
2534
|
-
console.log(`
|
2535
|
-
console.log(` \
|
2568
|
+
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2569
|
+
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2570
|
+
console.log(` \uD83D\uDCDD Test setup:`);
|
2571
|
+
console.log(` 1. Make script executable: chmod +x ${testDir}/run-tests.sh`);
|
2572
|
+
console.log(` 2. Edit the script to configure your API server startup`);
|
2573
|
+
console.log(` 3. Run tests: ${testDir}/run-tests.sh`);
|
2536
2574
|
}
|
2537
2575
|
}
|
2538
2576
|
export {
|