postgresdk 0.7.3 → 0.7.6
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 +17 -4
- package/dist/index.js +14 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1668,7 +1668,15 @@ function emitZod(table, opts) {
|
|
|
1668
1668
|
return `z.array(${zFor(pg.slice(1))})`;
|
|
1669
1669
|
return `z.string()`;
|
|
1670
1670
|
};
|
|
1671
|
-
const
|
|
1671
|
+
const selectFields = table.columns.map((c) => {
|
|
1672
|
+
let z = zFor(c.pgType);
|
|
1673
|
+
if (c.nullable) {
|
|
1674
|
+
z += `.nullable()`;
|
|
1675
|
+
}
|
|
1676
|
+
return ` ${c.name}: ${z}`;
|
|
1677
|
+
}).join(`,
|
|
1678
|
+
`);
|
|
1679
|
+
const insertFields = table.columns.map((c) => {
|
|
1672
1680
|
let z = zFor(c.pgType);
|
|
1673
1681
|
if (c.nullable) {
|
|
1674
1682
|
z += `.nullish()`;
|
|
@@ -1680,8 +1688,12 @@ function emitZod(table, opts) {
|
|
|
1680
1688
|
`);
|
|
1681
1689
|
return `import { z } from "zod";
|
|
1682
1690
|
|
|
1691
|
+
export const Select${Type}Schema = z.object({
|
|
1692
|
+
${selectFields}
|
|
1693
|
+
});
|
|
1694
|
+
|
|
1683
1695
|
export const Insert${Type}Schema = z.object({
|
|
1684
|
-
${
|
|
1696
|
+
${insertFields}
|
|
1685
1697
|
});
|
|
1686
1698
|
|
|
1687
1699
|
export const Update${Type}Schema = Insert${Type}Schema.partial();
|
|
@@ -4030,7 +4042,7 @@ Usage:
|
|
|
4030
4042
|
|
|
4031
4043
|
Commands:
|
|
4032
4044
|
init Create a postgresdk.config.ts file
|
|
4033
|
-
generate
|
|
4045
|
+
generate, gen Generate SDK from database
|
|
4034
4046
|
pull Pull SDK from API endpoint
|
|
4035
4047
|
version Show version
|
|
4036
4048
|
help Show help
|
|
@@ -4050,6 +4062,7 @@ Pull Options:
|
|
|
4050
4062
|
Examples:
|
|
4051
4063
|
postgresdk init # Create config file
|
|
4052
4064
|
postgresdk generate # Generate using postgresdk.config.ts
|
|
4065
|
+
postgresdk gen # Short alias for generate
|
|
4053
4066
|
postgresdk generate -c custom.config.ts
|
|
4054
4067
|
postgresdk pull --from=https://api.com --output=./src/sdk
|
|
4055
4068
|
postgresdk pull # Pull using config file
|
|
@@ -4059,7 +4072,7 @@ Examples:
|
|
|
4059
4072
|
if (command === "init") {
|
|
4060
4073
|
const { initCommand: initCommand2 } = await Promise.resolve().then(() => (init_cli_init(), exports_cli_init));
|
|
4061
4074
|
await initCommand2(args.slice(1));
|
|
4062
|
-
} else if (command === "generate") {
|
|
4075
|
+
} else if (command === "generate" || command === "gen") {
|
|
4063
4076
|
let configPath = "postgresdk.config.ts";
|
|
4064
4077
|
const configIndex = args.findIndex((a) => a === "-c" || a === "--config");
|
|
4065
4078
|
if (configIndex !== -1 && args[configIndex + 1]) {
|
package/dist/index.js
CHANGED
|
@@ -1405,7 +1405,15 @@ function emitZod(table, opts) {
|
|
|
1405
1405
|
return `z.array(${zFor(pg.slice(1))})`;
|
|
1406
1406
|
return `z.string()`;
|
|
1407
1407
|
};
|
|
1408
|
-
const
|
|
1408
|
+
const selectFields = table.columns.map((c) => {
|
|
1409
|
+
let z = zFor(c.pgType);
|
|
1410
|
+
if (c.nullable) {
|
|
1411
|
+
z += `.nullable()`;
|
|
1412
|
+
}
|
|
1413
|
+
return ` ${c.name}: ${z}`;
|
|
1414
|
+
}).join(`,
|
|
1415
|
+
`);
|
|
1416
|
+
const insertFields = table.columns.map((c) => {
|
|
1409
1417
|
let z = zFor(c.pgType);
|
|
1410
1418
|
if (c.nullable) {
|
|
1411
1419
|
z += `.nullish()`;
|
|
@@ -1417,8 +1425,12 @@ function emitZod(table, opts) {
|
|
|
1417
1425
|
`);
|
|
1418
1426
|
return `import { z } from "zod";
|
|
1419
1427
|
|
|
1428
|
+
export const Select${Type}Schema = z.object({
|
|
1429
|
+
${selectFields}
|
|
1430
|
+
});
|
|
1431
|
+
|
|
1420
1432
|
export const Insert${Type}Schema = z.object({
|
|
1421
|
-
${
|
|
1433
|
+
${insertFields}
|
|
1422
1434
|
});
|
|
1423
1435
|
|
|
1424
1436
|
export const Update${Type}Schema = Insert${Type}Schema.partial();
|