postgresdk 0.7.1 → 0.7.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/dist/cli.js CHANGED
@@ -1688,6 +1688,57 @@ export const Update${Type}Schema = Insert${Type}Schema.partial();
1688
1688
  `;
1689
1689
  }
1690
1690
 
1691
+ // src/emit-params-zod.ts
1692
+ init_utils();
1693
+ function emitParamsZod(table, graph) {
1694
+ const Type = pascal(table.name);
1695
+ const columnNames = table.columns.map((c) => `"${c.name}"`).join(", ");
1696
+ const pkCols = Array.isArray(table.pk) ? table.pk : table.pk ? [table.pk] : [];
1697
+ const safePk = pkCols.length ? pkCols : ["id"];
1698
+ const hasCompositePk = safePk.length > 1;
1699
+ const includeSpecSchema = `z.any()`;
1700
+ const pkSchema = hasCompositePk ? `z.object({ ${safePk.map((col) => `${col}: z.string().min(1)`).join(", ")} })` : `z.string().min(1)`;
1701
+ return `import { z } from "zod";
1702
+
1703
+ // Schema for primary key parameters
1704
+ export const ${Type}PkSchema = ${pkSchema};
1705
+
1706
+ // Schema for list query parameters
1707
+ export const ${Type}ListParamsSchema = z.object({
1708
+ include: ${includeSpecSchema}.optional(),
1709
+ limit: z.number().int().positive().max(1000).optional(),
1710
+ offset: z.number().int().nonnegative().optional(),
1711
+ where: z.any().optional(),
1712
+ orderBy: z.enum([${columnNames}]).optional(),
1713
+ order: z.enum(["asc", "desc"]).optional()
1714
+ }).strict();
1715
+
1716
+ // Schema for ordering parameters
1717
+ export const ${Type}OrderParamsSchema = z.object({
1718
+ orderBy: z.enum([${columnNames}]).optional(),
1719
+ order: z.enum(["asc", "desc"]).optional()
1720
+ }).strict();
1721
+
1722
+ export type ${Type}Pk = z.infer<typeof ${Type}PkSchema>;
1723
+ export type ${Type}ListParams = z.infer<typeof ${Type}ListParamsSchema>;
1724
+ export type ${Type}OrderParams = z.infer<typeof ${Type}OrderParamsSchema>;
1725
+ `;
1726
+ }
1727
+
1728
+ // src/emit-shared-params-zod.ts
1729
+ function emitSharedParamsZod() {
1730
+ return `import { z } from "zod";
1731
+
1732
+ // Shared pagination schema (used across all tables)
1733
+ export const PaginationParamsSchema = z.object({
1734
+ limit: z.number().int().positive().max(1000).optional(),
1735
+ offset: z.number().int().nonnegative().optional()
1736
+ }).strict();
1737
+
1738
+ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
1739
+ `;
1740
+ }
1741
+
1691
1742
  // src/emit-routes-hono.ts
1692
1743
  init_utils();
1693
1744
  function emitHonoRoutes(table, _graph, opts) {
@@ -1951,6 +2002,16 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
1951
2002
  `;
1952
2003
  for (const t of tables) {
1953
2004
  out += `export { Insert${pascal(t.name)}Schema, Update${pascal(t.name)}Schema } from "./zod/${t.name}${ext}";
2005
+ `;
2006
+ }
2007
+ out += `
2008
+ // Zod schemas for query parameters
2009
+ `;
2010
+ out += `export { PaginationParamsSchema } from "./params/shared${ext}";
2011
+ `;
2012
+ for (const t of tables) {
2013
+ const Type = pascal(t.name);
2014
+ out += `export { ${Type}PkSchema, ${Type}ListParamsSchema, ${Type}OrderParamsSchema } from "./params/${t.name}${ext}";
1954
2015
  `;
1955
2016
  }
1956
2017
  return out;
@@ -3769,7 +3830,8 @@ async function generate(configPath) {
3769
3830
  join(serverDir, "routes"),
3770
3831
  clientDir,
3771
3832
  join(clientDir, "types"),
3772
- join(clientDir, "zod")
3833
+ join(clientDir, "zod"),
3834
+ join(clientDir, "params")
3773
3835
  ];
3774
3836
  if (generateTests) {
3775
3837
  dirs.push(testDir);
@@ -3779,6 +3841,7 @@ async function generate(configPath) {
3779
3841
  const includeSpec = emitIncludeSpec(graph);
3780
3842
  files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
3781
3843
  files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
3844
+ files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
3782
3845
  files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
3783
3846
  files.push({
3784
3847
  path: join(serverDir, "include-builder.ts"),
@@ -3806,6 +3869,8 @@ async function generate(configPath) {
3806
3869
  const zodSrc = emitZod(table, { numericMode: "string" });
3807
3870
  files.push({ path: join(serverDir, "zod", `${table.name}.ts`), content: zodSrc });
3808
3871
  files.push({ path: join(clientDir, "zod", `${table.name}.ts`), content: zodSrc });
3872
+ const paramsZodSrc = emitParamsZod(table, graph);
3873
+ files.push({ path: join(clientDir, "params", `${table.name}.ts`), content: paramsZodSrc });
3809
3874
  let routeContent;
3810
3875
  if (serverFramework === "hono") {
3811
3876
  routeContent = emitHonoRoutes(table, graph, {
@@ -0,0 +1,3 @@
1
+ import type { Table } from "./introspect";
2
+ import type { Graph } from "./rel-classify";
3
+ export declare function emitParamsZod(table: Table, graph: Graph): string;
@@ -0,0 +1 @@
1
+ export declare function emitSharedParamsZod(): string;
package/dist/index.js CHANGED
@@ -1425,6 +1425,57 @@ export const Update${Type}Schema = Insert${Type}Schema.partial();
1425
1425
  `;
1426
1426
  }
1427
1427
 
1428
+ // src/emit-params-zod.ts
1429
+ init_utils();
1430
+ function emitParamsZod(table, graph) {
1431
+ const Type = pascal(table.name);
1432
+ const columnNames = table.columns.map((c) => `"${c.name}"`).join(", ");
1433
+ const pkCols = Array.isArray(table.pk) ? table.pk : table.pk ? [table.pk] : [];
1434
+ const safePk = pkCols.length ? pkCols : ["id"];
1435
+ const hasCompositePk = safePk.length > 1;
1436
+ const includeSpecSchema = `z.any()`;
1437
+ const pkSchema = hasCompositePk ? `z.object({ ${safePk.map((col) => `${col}: z.string().min(1)`).join(", ")} })` : `z.string().min(1)`;
1438
+ return `import { z } from "zod";
1439
+
1440
+ // Schema for primary key parameters
1441
+ export const ${Type}PkSchema = ${pkSchema};
1442
+
1443
+ // Schema for list query parameters
1444
+ export const ${Type}ListParamsSchema = z.object({
1445
+ include: ${includeSpecSchema}.optional(),
1446
+ limit: z.number().int().positive().max(1000).optional(),
1447
+ offset: z.number().int().nonnegative().optional(),
1448
+ where: z.any().optional(),
1449
+ orderBy: z.enum([${columnNames}]).optional(),
1450
+ order: z.enum(["asc", "desc"]).optional()
1451
+ }).strict();
1452
+
1453
+ // Schema for ordering parameters
1454
+ export const ${Type}OrderParamsSchema = z.object({
1455
+ orderBy: z.enum([${columnNames}]).optional(),
1456
+ order: z.enum(["asc", "desc"]).optional()
1457
+ }).strict();
1458
+
1459
+ export type ${Type}Pk = z.infer<typeof ${Type}PkSchema>;
1460
+ export type ${Type}ListParams = z.infer<typeof ${Type}ListParamsSchema>;
1461
+ export type ${Type}OrderParams = z.infer<typeof ${Type}OrderParamsSchema>;
1462
+ `;
1463
+ }
1464
+
1465
+ // src/emit-shared-params-zod.ts
1466
+ function emitSharedParamsZod() {
1467
+ return `import { z } from "zod";
1468
+
1469
+ // Shared pagination schema (used across all tables)
1470
+ export const PaginationParamsSchema = z.object({
1471
+ limit: z.number().int().positive().max(1000).optional(),
1472
+ offset: z.number().int().nonnegative().optional()
1473
+ }).strict();
1474
+
1475
+ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
1476
+ `;
1477
+ }
1478
+
1428
1479
  // src/emit-routes-hono.ts
1429
1480
  init_utils();
1430
1481
  function emitHonoRoutes(table, _graph, opts) {
@@ -1688,6 +1739,16 @@ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${
1688
1739
  `;
1689
1740
  for (const t of tables) {
1690
1741
  out += `export { Insert${pascal(t.name)}Schema, Update${pascal(t.name)}Schema } from "./zod/${t.name}${ext}";
1742
+ `;
1743
+ }
1744
+ out += `
1745
+ // Zod schemas for query parameters
1746
+ `;
1747
+ out += `export { PaginationParamsSchema } from "./params/shared${ext}";
1748
+ `;
1749
+ for (const t of tables) {
1750
+ const Type = pascal(t.name);
1751
+ out += `export { ${Type}PkSchema, ${Type}ListParamsSchema, ${Type}OrderParamsSchema } from "./params/${t.name}${ext}";
1691
1752
  `;
1692
1753
  }
1693
1754
  return out;
@@ -3506,7 +3567,8 @@ async function generate(configPath) {
3506
3567
  join(serverDir, "routes"),
3507
3568
  clientDir,
3508
3569
  join(clientDir, "types"),
3509
- join(clientDir, "zod")
3570
+ join(clientDir, "zod"),
3571
+ join(clientDir, "params")
3510
3572
  ];
3511
3573
  if (generateTests) {
3512
3574
  dirs.push(testDir);
@@ -3516,6 +3578,7 @@ async function generate(configPath) {
3516
3578
  const includeSpec = emitIncludeSpec(graph);
3517
3579
  files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
3518
3580
  files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
3581
+ files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
3519
3582
  files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
3520
3583
  files.push({
3521
3584
  path: join(serverDir, "include-builder.ts"),
@@ -3543,6 +3606,8 @@ async function generate(configPath) {
3543
3606
  const zodSrc = emitZod(table, { numericMode: "string" });
3544
3607
  files.push({ path: join(serverDir, "zod", `${table.name}.ts`), content: zodSrc });
3545
3608
  files.push({ path: join(clientDir, "zod", `${table.name}.ts`), content: zodSrc });
3609
+ const paramsZodSrc = emitParamsZod(table, graph);
3610
+ files.push({ path: join(clientDir, "params", `${table.name}.ts`), content: paramsZodSrc });
3546
3611
  let routeContent;
3547
3612
  if (serverFramework === "hono") {
3548
3613
  routeContent = emitHonoRoutes(table, graph, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
5
5
  "type": "module",
6
6
  "bin": {