postgresdk 0.6.1 → 0.6.2
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 +25 -25
- package/dist/cli.js +14 -9
- package/dist/index.js +9 -4
- 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
|
};
|
@@ -1009,7 +1009,7 @@ The generated Docker setup makes it easy to run tests in isolation:
|
|
1009
1009
|
|
1010
1010
|
```bash
|
1011
1011
|
# Navigate to test directory
|
1012
|
-
cd
|
1012
|
+
cd api/tests
|
1013
1013
|
|
1014
1014
|
# Start test database
|
1015
1015
|
docker-compose up -d
|
@@ -1052,7 +1052,7 @@ Example custom test:
|
|
1052
1052
|
```typescript
|
1053
1053
|
// tests/custom/user-workflow.test.ts
|
1054
1054
|
import { describe, it, expect } from 'vitest';
|
1055
|
-
import { createTestSDK, randomEmail } from '../
|
1055
|
+
import { createTestSDK, randomEmail } from '../api/tests/setup';
|
1056
1056
|
|
1057
1057
|
describe('User Registration Workflow', () => {
|
1058
1058
|
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
|
|
@@ -2682,8 +2682,8 @@ async function generate(configPath) {
|
|
2682
2682
|
const model = await introspect(cfg.connectionString, cfg.schema || "public");
|
2683
2683
|
console.log("\uD83D\uDD17 Building relationship graph...");
|
2684
2684
|
const graph = buildGraph(model);
|
2685
|
-
const serverDir = cfg.outServer || "./
|
2686
|
-
const originalClientDir = cfg.outClient || "./
|
2685
|
+
const serverDir = cfg.outServer || "./api/server";
|
2686
|
+
const originalClientDir = cfg.outClient || "./api/client";
|
2687
2687
|
const sameDirectory = serverDir === originalClientDir;
|
2688
2688
|
let clientDir = originalClientDir;
|
2689
2689
|
if (sameDirectory) {
|
@@ -2692,7 +2692,11 @@ async function generate(configPath) {
|
|
2692
2692
|
const normDateType = cfg.dateType === "string" ? "string" : "date";
|
2693
2693
|
const serverFramework = cfg.serverFramework || "hono";
|
2694
2694
|
const generateTests = cfg.tests?.generate ?? false;
|
2695
|
-
const
|
2695
|
+
const originalTestDir = cfg.tests?.output || "./api/tests";
|
2696
|
+
let testDir = originalTestDir;
|
2697
|
+
if (generateTests && (originalTestDir === serverDir || originalTestDir === originalClientDir)) {
|
2698
|
+
testDir = join(originalTestDir, "tests");
|
2699
|
+
}
|
2696
2700
|
const testFramework = cfg.tests?.framework || "vitest";
|
2697
2701
|
console.log("\uD83D\uDCC1 Creating directories...");
|
2698
2702
|
const dirs = [
|
@@ -2800,7 +2804,8 @@ async function generate(configPath) {
|
|
2800
2804
|
console.log(` Server: ${serverDir}`);
|
2801
2805
|
console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
|
2802
2806
|
if (generateTests) {
|
2803
|
-
|
2807
|
+
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2808
|
+
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2804
2809
|
console.log(` \uD83D\uDC33 Run 'cd ${testDir} && docker-compose up -d' to start test database`);
|
2805
2810
|
console.log(` \uD83E\uDDEA Run 'bash ${testDir}/run-tests.sh' to execute tests`);
|
2806
2811
|
}
|
package/dist/index.js
CHANGED
@@ -2412,8 +2412,8 @@ async function generate(configPath) {
|
|
2412
2412
|
const model = await introspect(cfg.connectionString, cfg.schema || "public");
|
2413
2413
|
console.log("\uD83D\uDD17 Building relationship graph...");
|
2414
2414
|
const graph = buildGraph(model);
|
2415
|
-
const serverDir = cfg.outServer || "./
|
2416
|
-
const originalClientDir = cfg.outClient || "./
|
2415
|
+
const serverDir = cfg.outServer || "./api/server";
|
2416
|
+
const originalClientDir = cfg.outClient || "./api/client";
|
2417
2417
|
const sameDirectory = serverDir === originalClientDir;
|
2418
2418
|
let clientDir = originalClientDir;
|
2419
2419
|
if (sameDirectory) {
|
@@ -2422,7 +2422,11 @@ async function generate(configPath) {
|
|
2422
2422
|
const normDateType = cfg.dateType === "string" ? "string" : "date";
|
2423
2423
|
const serverFramework = cfg.serverFramework || "hono";
|
2424
2424
|
const generateTests = cfg.tests?.generate ?? false;
|
2425
|
-
const
|
2425
|
+
const originalTestDir = cfg.tests?.output || "./api/tests";
|
2426
|
+
let testDir = originalTestDir;
|
2427
|
+
if (generateTests && (originalTestDir === serverDir || originalTestDir === originalClientDir)) {
|
2428
|
+
testDir = join(originalTestDir, "tests");
|
2429
|
+
}
|
2426
2430
|
const testFramework = cfg.tests?.framework || "vitest";
|
2427
2431
|
console.log("\uD83D\uDCC1 Creating directories...");
|
2428
2432
|
const dirs = [
|
@@ -2530,7 +2534,8 @@ async function generate(configPath) {
|
|
2530
2534
|
console.log(` Server: ${serverDir}`);
|
2531
2535
|
console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
|
2532
2536
|
if (generateTests) {
|
2533
|
-
|
2537
|
+
const testsInSubdir = originalTestDir === serverDir || originalTestDir === originalClientDir;
|
2538
|
+
console.log(` Tests: ${testsInSubdir ? testDir + " (in tests subdir due to same output dir)" : testDir}`);
|
2534
2539
|
console.log(` \uD83D\uDC33 Run 'cd ${testDir} && docker-compose up -d' to start test database`);
|
2535
2540
|
console.log(` \uD83E\uDDEA Run 'bash ${testDir}/run-tests.sh' to execute tests`);
|
2536
2541
|
}
|