postgresdk 0.7.0 → 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
@@ -1685,9 +1685,57 @@ ${fields}
1685
1685
  });
1686
1686
 
1687
1687
  export const Update${Type}Schema = Insert${Type}Schema.partial();
1688
+ `;
1689
+ }
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();
1688
1737
 
1689
- export type Insert${Type} = z.infer<typeof Insert${Type}Schema>;
1690
- export type Update${Type} = z.infer<typeof Update${Type}Schema>;
1738
+ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
1691
1739
  `;
1692
1740
  }
1693
1741
 
@@ -1916,9 +1964,7 @@ function emitClientIndex(tables, useJsExtensions) {
1916
1964
  `;
1917
1965
  }
1918
1966
  out += `
1919
- // Re-export auth types for convenience
1920
- `;
1921
- out += `export type { AuthConfig as SDKAuth, AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${ext}";
1967
+ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${ext}";
1922
1968
 
1923
1969
  `;
1924
1970
  out += `/**
@@ -1947,22 +1993,27 @@ function emitClientIndex(tables, useJsExtensions) {
1947
1993
  out += `}
1948
1994
 
1949
1995
  `;
1950
- out += `// Export individual table clients
1996
+ out += `export { BaseClient } from "./base-client${ext}";
1951
1997
  `;
1952
- for (const t of tables) {
1953
- out += `export { ${pascal(t.name)}Client } from "./${t.name}${ext}";
1998
+ out += `export * from "./include-spec${ext}";
1954
1999
  `;
1955
- }
1956
2000
  out += `
1957
- // Export base client for custom extensions
2001
+ // Zod schemas for form validation
1958
2002
  `;
1959
- out += `export { BaseClient } from "./base-client${ext}";
2003
+ for (const t of tables) {
2004
+ out += `export { Insert${pascal(t.name)}Schema, Update${pascal(t.name)}Schema } from "./zod/${t.name}${ext}";
1960
2005
  `;
2006
+ }
1961
2007
  out += `
1962
- // Export include specifications
2008
+ // Zod schemas for query parameters
1963
2009
  `;
1964
- out += `export * from "./include-spec${ext}";
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}";
1965
2015
  `;
2016
+ }
1966
2017
  return out;
1967
2018
  }
1968
2019
 
@@ -3778,7 +3829,9 @@ async function generate(configPath) {
3778
3829
  join(serverDir, "zod"),
3779
3830
  join(serverDir, "routes"),
3780
3831
  clientDir,
3781
- join(clientDir, "types")
3832
+ join(clientDir, "types"),
3833
+ join(clientDir, "zod"),
3834
+ join(clientDir, "params")
3782
3835
  ];
3783
3836
  if (generateTests) {
3784
3837
  dirs.push(testDir);
@@ -3788,6 +3841,7 @@ async function generate(configPath) {
3788
3841
  const includeSpec = emitIncludeSpec(graph);
3789
3842
  files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
3790
3843
  files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
3844
+ files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
3791
3845
  files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
3792
3846
  files.push({
3793
3847
  path: join(serverDir, "include-builder.ts"),
@@ -3812,10 +3866,11 @@ async function generate(configPath) {
3812
3866
  const typesSrc = emitTypes(table, { numericMode: "string" });
3813
3867
  files.push({ path: join(serverDir, "types", `${table.name}.ts`), content: typesSrc });
3814
3868
  files.push({ path: join(clientDir, "types", `${table.name}.ts`), content: typesSrc });
3815
- files.push({
3816
- path: join(serverDir, "zod", `${table.name}.ts`),
3817
- content: emitZod(table, { numericMode: "string" })
3818
- });
3869
+ const zodSrc = emitZod(table, { numericMode: "string" });
3870
+ files.push({ path: join(serverDir, "zod", `${table.name}.ts`), content: zodSrc });
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 });
3819
3874
  let routeContent;
3820
3875
  if (serverFramework === "hono") {
3821
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
@@ -1422,9 +1422,57 @@ ${fields}
1422
1422
  });
1423
1423
 
1424
1424
  export const Update${Type}Schema = Insert${Type}Schema.partial();
1425
+ `;
1426
+ }
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();
1425
1474
 
1426
- export type Insert${Type} = z.infer<typeof Insert${Type}Schema>;
1427
- export type Update${Type} = z.infer<typeof Update${Type}Schema>;
1475
+ export type PaginationParams = z.infer<typeof PaginationParamsSchema>;
1428
1476
  `;
1429
1477
  }
1430
1478
 
@@ -1653,9 +1701,7 @@ function emitClientIndex(tables, useJsExtensions) {
1653
1701
  `;
1654
1702
  }
1655
1703
  out += `
1656
- // Re-export auth types for convenience
1657
- `;
1658
- out += `export type { AuthConfig as SDKAuth, AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${ext}";
1704
+ export type { AuthConfig, HeaderMap, AuthHeadersProvider } from "./base-client${ext}";
1659
1705
 
1660
1706
  `;
1661
1707
  out += `/**
@@ -1684,22 +1730,27 @@ function emitClientIndex(tables, useJsExtensions) {
1684
1730
  out += `}
1685
1731
 
1686
1732
  `;
1687
- out += `// Export individual table clients
1733
+ out += `export { BaseClient } from "./base-client${ext}";
1688
1734
  `;
1689
- for (const t of tables) {
1690
- out += `export { ${pascal(t.name)}Client } from "./${t.name}${ext}";
1735
+ out += `export * from "./include-spec${ext}";
1691
1736
  `;
1692
- }
1693
1737
  out += `
1694
- // Export base client for custom extensions
1738
+ // Zod schemas for form validation
1695
1739
  `;
1696
- out += `export { BaseClient } from "./base-client${ext}";
1740
+ for (const t of tables) {
1741
+ out += `export { Insert${pascal(t.name)}Schema, Update${pascal(t.name)}Schema } from "./zod/${t.name}${ext}";
1697
1742
  `;
1743
+ }
1698
1744
  out += `
1699
- // Export include specifications
1745
+ // Zod schemas for query parameters
1700
1746
  `;
1701
- out += `export * from "./include-spec${ext}";
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}";
1702
1752
  `;
1753
+ }
1703
1754
  return out;
1704
1755
  }
1705
1756
 
@@ -3515,7 +3566,9 @@ async function generate(configPath) {
3515
3566
  join(serverDir, "zod"),
3516
3567
  join(serverDir, "routes"),
3517
3568
  clientDir,
3518
- join(clientDir, "types")
3569
+ join(clientDir, "types"),
3570
+ join(clientDir, "zod"),
3571
+ join(clientDir, "params")
3519
3572
  ];
3520
3573
  if (generateTests) {
3521
3574
  dirs.push(testDir);
@@ -3525,6 +3578,7 @@ async function generate(configPath) {
3525
3578
  const includeSpec = emitIncludeSpec(graph);
3526
3579
  files.push({ path: join(serverDir, "include-spec.ts"), content: includeSpec });
3527
3580
  files.push({ path: join(clientDir, "include-spec.ts"), content: includeSpec });
3581
+ files.push({ path: join(clientDir, "params", "shared.ts"), content: emitSharedParamsZod() });
3528
3582
  files.push({ path: join(clientDir, "base-client.ts"), content: emitBaseClient() });
3529
3583
  files.push({
3530
3584
  path: join(serverDir, "include-builder.ts"),
@@ -3549,10 +3603,11 @@ async function generate(configPath) {
3549
3603
  const typesSrc = emitTypes(table, { numericMode: "string" });
3550
3604
  files.push({ path: join(serverDir, "types", `${table.name}.ts`), content: typesSrc });
3551
3605
  files.push({ path: join(clientDir, "types", `${table.name}.ts`), content: typesSrc });
3552
- files.push({
3553
- path: join(serverDir, "zod", `${table.name}.ts`),
3554
- content: emitZod(table, { numericMode: "string" })
3555
- });
3606
+ const zodSrc = emitZod(table, { numericMode: "string" });
3607
+ files.push({ path: join(serverDir, "zod", `${table.name}.ts`), content: zodSrc });
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 });
3556
3611
  let routeContent;
3557
3612
  if (serverFramework === "hono") {
3558
3613
  routeContent = emitHonoRoutes(table, graph, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.7.0",
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": {
@@ -42,6 +42,7 @@
42
42
  "zod": "^4.0.15"
43
43
  },
44
44
  "devDependencies": {
45
+ "@types/bun": "^1.2.20",
45
46
  "@types/node": "^20.0.0",
46
47
  "@types/pg": "^8.15.5",
47
48
  "drizzle-kit": "^0.31.4",