postgresdk 0.1.2-alpha.1 → 0.1.2-alpha.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 +5 -5
- package/dist/cli.js +6 -6
- package/dist/emit-router.d.ts +5 -0
- package/dist/index.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
@@ -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 "./generated/server";
|
92
|
+
import { createRouter } from "./generated/server/router";
|
93
93
|
|
94
94
|
const app = new Hono();
|
95
95
|
const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -479,7 +479,7 @@ postgresdk generates a `createRouter` function that returns a Hono router with a
|
|
479
479
|
import { Hono } from "hono";
|
480
480
|
import { serve } from "@hono/node-server";
|
481
481
|
import { Client } from "pg";
|
482
|
-
import { createRouter } from "./generated/server";
|
482
|
+
import { createRouter } from "./generated/server/router";
|
483
483
|
|
484
484
|
const app = new Hono();
|
485
485
|
|
@@ -502,7 +502,7 @@ The `createRouter` function returns a Hono router that can be mounted anywhere:
|
|
502
502
|
|
503
503
|
```typescript
|
504
504
|
import { Hono } from "hono";
|
505
|
-
import { createRouter } from "./generated/server";
|
505
|
+
import { createRouter } from "./generated/server/router";
|
506
506
|
|
507
507
|
const app = new Hono();
|
508
508
|
|
@@ -523,7 +523,7 @@ app.route("/v2", apiRouter); // Routes will be at /v2/v1/users, /v2/v1/posts,
|
|
523
523
|
If you prefer to register routes directly on your app without a sub-router:
|
524
524
|
|
525
525
|
```typescript
|
526
|
-
import { registerAllRoutes } from "./generated/server";
|
526
|
+
import { registerAllRoutes } from "./generated/server/router";
|
527
527
|
|
528
528
|
const app = new Hono();
|
529
529
|
const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -538,7 +538,7 @@ registerAllRoutes(app, { pg });
|
|
538
538
|
You can also import and register individual routes:
|
539
539
|
|
540
540
|
```typescript
|
541
|
-
import { registerUsersRoutes, registerPostsRoutes } from "./generated/server";
|
541
|
+
import { registerUsersRoutes, registerPostsRoutes } from "./generated/server/router";
|
542
542
|
|
543
543
|
const app = new Hono();
|
544
544
|
|
package/dist/cli.js
CHANGED
@@ -1659,8 +1659,8 @@ export async function authMiddleware(c: Context, next: Next) {
|
|
1659
1659
|
`;
|
1660
1660
|
}
|
1661
1661
|
|
1662
|
-
// src/emit-
|
1663
|
-
function
|
1662
|
+
// src/emit-router.ts
|
1663
|
+
function emitRouter(tables, hasAuth) {
|
1664
1664
|
const tableNames = tables.map((t) => t.name).sort();
|
1665
1665
|
const imports = tableNames.map((name) => {
|
1666
1666
|
const Type = pascal(name);
|
@@ -1688,7 +1688,7 @@ ${hasAuth ? `export { authMiddleware } from "./auth";` : ""}
|
|
1688
1688
|
* @example
|
1689
1689
|
* import { Hono } from "hono";
|
1690
1690
|
* import { Client } from "pg";
|
1691
|
-
* import { createRouter } from "./generated/server";
|
1691
|
+
* import { createRouter } from "./generated/server/router";
|
1692
1692
|
*
|
1693
1693
|
* const app = new Hono();
|
1694
1694
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -1716,7 +1716,7 @@ ${registrations}
|
|
1716
1716
|
* @example
|
1717
1717
|
* import { Hono } from "hono";
|
1718
1718
|
* import { Client } from "pg";
|
1719
|
-
* import { registerAllRoutes } from "./generated/server";
|
1719
|
+
* import { registerAllRoutes } from "./generated/server/router";
|
1720
1720
|
*
|
1721
1721
|
* const app = new Hono();
|
1722
1722
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -1803,8 +1803,8 @@ async function generate(configPath) {
|
|
1803
1803
|
content: emitClientIndex(Object.values(model.tables))
|
1804
1804
|
});
|
1805
1805
|
files.push({
|
1806
|
-
path: join(serverDir, "
|
1807
|
-
content:
|
1806
|
+
path: join(serverDir, "router.ts"),
|
1807
|
+
content: emitRouter(Object.values(model.tables), !!cfg.auth?.strategy && cfg.auth.strategy !== "none")
|
1808
1808
|
});
|
1809
1809
|
console.log("✍️ Writing files...");
|
1810
1810
|
await writeFiles(files);
|
package/dist/index.js
CHANGED
@@ -1658,8 +1658,8 @@ export async function authMiddleware(c: Context, next: Next) {
|
|
1658
1658
|
`;
|
1659
1659
|
}
|
1660
1660
|
|
1661
|
-
// src/emit-
|
1662
|
-
function
|
1661
|
+
// src/emit-router.ts
|
1662
|
+
function emitRouter(tables, hasAuth) {
|
1663
1663
|
const tableNames = tables.map((t) => t.name).sort();
|
1664
1664
|
const imports = tableNames.map((name) => {
|
1665
1665
|
const Type = pascal(name);
|
@@ -1687,7 +1687,7 @@ ${hasAuth ? `export { authMiddleware } from "./auth";` : ""}
|
|
1687
1687
|
* @example
|
1688
1688
|
* import { Hono } from "hono";
|
1689
1689
|
* import { Client } from "pg";
|
1690
|
-
* import { createRouter } from "./generated/server";
|
1690
|
+
* import { createRouter } from "./generated/server/router";
|
1691
1691
|
*
|
1692
1692
|
* const app = new Hono();
|
1693
1693
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -1715,7 +1715,7 @@ ${registrations}
|
|
1715
1715
|
* @example
|
1716
1716
|
* import { Hono } from "hono";
|
1717
1717
|
* import { Client } from "pg";
|
1718
|
-
* import { registerAllRoutes } from "./generated/server";
|
1718
|
+
* import { registerAllRoutes } from "./generated/server/router";
|
1719
1719
|
*
|
1720
1720
|
* const app = new Hono();
|
1721
1721
|
* const pg = new Client({ connectionString: process.env.DATABASE_URL });
|
@@ -1802,8 +1802,8 @@ async function generate(configPath) {
|
|
1802
1802
|
content: emitClientIndex(Object.values(model.tables))
|
1803
1803
|
});
|
1804
1804
|
files.push({
|
1805
|
-
path: join(serverDir, "
|
1806
|
-
content:
|
1805
|
+
path: join(serverDir, "router.ts"),
|
1806
|
+
content: emitRouter(Object.values(model.tables), !!cfg.auth?.strategy && cfg.auth.strategy !== "none")
|
1807
1807
|
});
|
1808
1808
|
console.log("✍️ Writing files...");
|
1809
1809
|
await writeFiles(files);
|