postgresdk 0.9.6 → 0.9.8

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 CHANGED
@@ -88,7 +88,7 @@ export default {
88
88
  outServer: "./api/server", // Server code output directory
89
89
  outClient: "./api/client", // Client SDK output directory
90
90
  softDeleteColumn: null, // Column name for soft deletes (e.g., "deleted_at")
91
- includeDepthLimit: 3, // Max depth for nested includes
91
+ includeMethodsDepth: 2, // Max depth for nested includes
92
92
  dateType: "date", // "date" | "string" - How to handle timestamps
93
93
  serverFramework: "hono", // Currently only hono is supported
94
94
  useJsExtensions: false, // Add .js to imports (for Vercel Edge, Deno)
package/dist/cli.js CHANGED
@@ -1355,11 +1355,11 @@ function extractConfigFields(configContent) {
1355
1355
  isCommented: !!softDeleteMatch[1]
1356
1356
  });
1357
1357
  }
1358
- const depthMatch = configContent.match(/^\s*(\/\/)?\s*includeDepthLimit:\s*(\d+)/m);
1358
+ const depthMatch = configContent.match(/^\s*(\/\/)?\s*(includeMethodsDepth|includeDepthLimit):\s*(\d+)/m);
1359
1359
  if (depthMatch) {
1360
1360
  fields.push({
1361
- key: "includeDepthLimit",
1362
- value: parseInt(depthMatch[2]),
1361
+ key: "includeMethodsDepth",
1362
+ value: parseInt(depthMatch[3]),
1363
1363
  description: "Maximum depth for nested relationship includes",
1364
1364
  isCommented: !!depthMatch[1]
1365
1365
  });
@@ -1391,35 +1391,90 @@ function extractConfigFields(configContent) {
1391
1391
  isCommented: !!jsExtClientMatch[1]
1392
1392
  });
1393
1393
  }
1394
- const testsMatch = configContent.match(/^\s*(\/\/)?\s*tests:\s*\{/m);
1395
- if (testsMatch) {
1394
+ const testsBlock = extractComplexBlock(configContent, "tests");
1395
+ if (testsBlock) {
1396
1396
  fields.push({
1397
1397
  key: "tests",
1398
- value: "configured",
1398
+ value: testsBlock.content,
1399
1399
  description: "Test generation configuration",
1400
- isCommented: !!testsMatch[1]
1400
+ isCommented: testsBlock.isCommented
1401
1401
  });
1402
1402
  }
1403
- const authMatch = configContent.match(/^\s*(\/\/)?\s*auth:\s*\{/m);
1404
- if (authMatch) {
1403
+ const authBlock = extractComplexBlock(configContent, "auth");
1404
+ if (authBlock) {
1405
1405
  fields.push({
1406
1406
  key: "auth",
1407
- value: "configured",
1407
+ value: authBlock.content,
1408
1408
  description: "Authentication configuration",
1409
- isCommented: !!authMatch[1]
1409
+ isCommented: authBlock.isCommented
1410
1410
  });
1411
1411
  }
1412
- const pullMatch = configContent.match(/^\s*(\/\/)?\s*pull:\s*\{/m);
1413
- if (pullMatch) {
1412
+ const pullBlock = extractComplexBlock(configContent, "pull");
1413
+ if (pullBlock) {
1414
1414
  fields.push({
1415
1415
  key: "pull",
1416
- value: "configured",
1416
+ value: pullBlock.content,
1417
1417
  description: "SDK distribution configuration",
1418
- isCommented: !!pullMatch[1]
1418
+ isCommented: pullBlock.isCommented
1419
1419
  });
1420
1420
  }
1421
1421
  return fields;
1422
1422
  }
1423
+ function extractComplexBlock(configContent, blockName) {
1424
+ const blockStartRegex = new RegExp(`^\\s*(//)?\\s*${blockName}:\\s*\\{`, "m");
1425
+ const match = configContent.match(blockStartRegex);
1426
+ if (!match)
1427
+ return null;
1428
+ const isCommented = !!match[1];
1429
+ const startIndex = match.index;
1430
+ let braceCount = 0;
1431
+ let inString = false;
1432
+ let inComment = false;
1433
+ let stringChar = "";
1434
+ let i = startIndex;
1435
+ while (i < configContent.length && configContent[i] !== "{") {
1436
+ i++;
1437
+ }
1438
+ const blockStart = i;
1439
+ braceCount = 1;
1440
+ i++;
1441
+ while (i < configContent.length && braceCount > 0) {
1442
+ const char = configContent[i];
1443
+ const prevChar = i > 0 ? configContent[i - 1] : "";
1444
+ if (!inComment && (char === '"' || char === "'" || char === "`")) {
1445
+ if (!inString) {
1446
+ inString = true;
1447
+ stringChar = char;
1448
+ } else if (char === stringChar && prevChar !== "\\") {
1449
+ inString = false;
1450
+ stringChar = "";
1451
+ }
1452
+ }
1453
+ if (!inString && char === "/" && configContent[i + 1] === "/") {
1454
+ inComment = true;
1455
+ }
1456
+ if (inComment && char === `
1457
+ `) {
1458
+ inComment = false;
1459
+ }
1460
+ if (!inString && !inComment) {
1461
+ if (char === "{") {
1462
+ braceCount++;
1463
+ } else if (char === "}") {
1464
+ braceCount--;
1465
+ }
1466
+ }
1467
+ i++;
1468
+ }
1469
+ if (braceCount === 0) {
1470
+ const blockContent = configContent.slice(blockStart + 1, i - 1);
1471
+ return {
1472
+ content: `{${blockContent}}`,
1473
+ isCommented
1474
+ };
1475
+ }
1476
+ return null;
1477
+ }
1423
1478
  function generateMergedConfig(existingFields, mergeStrategy, userChoices = undefined) {
1424
1479
  const template = `/**
1425
1480
  * PostgreSDK Configuration
@@ -1469,9 +1524,9 @@ export default {
1469
1524
 
1470
1525
  /**
1471
1526
  * Maximum depth for nested relationship includes to prevent infinite loops
1472
- * @default 3
1527
+ * @default 2
1473
1528
  */
1474
- ${getFieldLine("includeDepthLimit", existingFields, mergeStrategy, "3", userChoices)}
1529
+ ${getFieldLine("includeMethodsDepth", existingFields, mergeStrategy, "2", userChoices)}
1475
1530
 
1476
1531
 
1477
1532
  /**
@@ -1501,11 +1556,7 @@ export default {
1501
1556
  * Generate basic SDK tests
1502
1557
  * Uncomment to enable test generation with Docker setup
1503
1558
  */
1504
- // tests: {
1505
- // generate: true,
1506
- // output: "./api/tests",
1507
- // framework: "vitest" // or "jest" or "bun"
1508
- // },
1559
+ ${getComplexBlockLine("tests", existingFields, mergeStrategy, userChoices)}
1509
1560
 
1510
1561
  // ========== AUTHENTICATION ==========
1511
1562
 
@@ -1521,24 +1572,7 @@ export default {
1521
1572
  *
1522
1573
  * Full syntax for advanced options:
1523
1574
  */
1524
- // auth: {
1525
- // // Strategy: "none" | "api-key" | "jwt-hs256"
1526
- // strategy: "none",
1527
- //
1528
- // // For API Key authentication
1529
- // apiKeyHeader: "x-api-key", // Header name for API key
1530
- // apiKeys: [ // List of valid API keys
1531
- // process.env.API_KEY_1,
1532
- // process.env.API_KEY_2,
1533
- // ],
1534
- //
1535
- // // For JWT (HS256) authentication
1536
- // jwt: {
1537
- // sharedSecret: process.env.JWT_SECRET, // Secret for signing/verifying
1538
- // issuer: "my-app", // Optional: validate 'iss' claim
1539
- // audience: "my-users", // Optional: validate 'aud' claim
1540
- // }
1541
- // },
1575
+ ${getComplexBlockLine("auth", existingFields, mergeStrategy, userChoices)}
1542
1576
 
1543
1577
  // ========== SDK DISTRIBUTION (Pull Configuration) ==========
1544
1578
 
@@ -1546,11 +1580,7 @@ export default {
1546
1580
  * Configuration for pulling SDK from a remote API
1547
1581
  * Used when running 'postgresdk pull' command
1548
1582
  */
1549
- // pull: {
1550
- // from: "https://api.myapp.com", // API URL to pull SDK from
1551
- // output: "./src/sdk", // Local directory for pulled SDK
1552
- // token: process.env.API_TOKEN, // Optional authentication token
1553
- // },
1583
+ ${getComplexBlockLine("pull", existingFields, mergeStrategy, userChoices)}
1554
1584
  };
1555
1585
  `;
1556
1586
  return template;
@@ -1589,6 +1619,55 @@ function getFieldLine(key, existingFields, mergeStrategy, defaultValue, userChoi
1589
1619
  }
1590
1620
  return `// ${key}: ${defaultValue},`;
1591
1621
  }
1622
+ function getComplexBlockLine(key, existingFields, mergeStrategy, userChoices) {
1623
+ const existing = existingFields.find((f) => f.key === key);
1624
+ const shouldUseExisting = mergeStrategy === "keep-existing" && existing && !existing.isCommented || mergeStrategy === "interactive" && userChoices?.get(key) === "keep" && existing && !existing.isCommented;
1625
+ const shouldUseNew = mergeStrategy === "use-defaults" || mergeStrategy === "interactive" && userChoices?.get(key) === "new";
1626
+ if (shouldUseExisting && existing) {
1627
+ return `${key}: ${existing.value},`;
1628
+ }
1629
+ if (shouldUseNew) {
1630
+ return getDefaultComplexBlock(key);
1631
+ }
1632
+ return getDefaultComplexBlock(key);
1633
+ }
1634
+ function getDefaultComplexBlock(key) {
1635
+ switch (key) {
1636
+ case "tests":
1637
+ return `// tests: {
1638
+ // generate: true,
1639
+ // output: "./api/tests",
1640
+ // framework: "vitest" // or "jest" or "bun"
1641
+ // },`;
1642
+ case "auth":
1643
+ return `// auth: {
1644
+ // // Strategy: "none" | "api-key" | "jwt-hs256"
1645
+ // strategy: "none",
1646
+ //
1647
+ // // For API Key authentication
1648
+ // apiKeyHeader: "x-api-key", // Header name for API key
1649
+ // apiKeys: [ // List of valid API keys
1650
+ // process.env.API_KEY_1,
1651
+ // process.env.API_KEY_2,
1652
+ // ],
1653
+ //
1654
+ // // For JWT (HS256) authentication
1655
+ // jwt: {
1656
+ // sharedSecret: process.env.JWT_SECRET, // Secret for signing/verifying
1657
+ // issuer: "my-app", // Optional: validate 'iss' claim
1658
+ // audience: "my-users", // Optional: validate 'aud' claim
1659
+ // }
1660
+ // },`;
1661
+ case "pull":
1662
+ return `// pull: {
1663
+ // from: "https://api.myapp.com", // API URL to pull SDK from
1664
+ // output: "./src/sdk", // Local directory for pulled SDK
1665
+ // token: process.env.API_TOKEN, // Optional authentication token
1666
+ // },`;
1667
+ default:
1668
+ return `// ${key}: {},`;
1669
+ }
1670
+ }
1592
1671
  var init_cli_config_utils = () => {};
1593
1672
 
1594
1673
  // src/cli-init.ts
@@ -1793,9 +1872,9 @@ export default {
1793
1872
 
1794
1873
  /**
1795
1874
  * Maximum depth for nested relationship includes to prevent infinite loops
1796
- * @default 3
1875
+ * @default 2
1797
1876
  */
1798
- // includeDepthLimit: 3,
1877
+ // includeMethodsDepth: 2,
1799
1878
 
1800
1879
 
1801
1880
  /**
@@ -2359,7 +2438,7 @@ export function register${Type}Routes(app: Hono, deps: { pg: { query: (text: str
2359
2438
  table: "${fileTableName}",
2360
2439
  pkColumns: ${JSON.stringify(safePkCols)},
2361
2440
  softDeleteColumn: ${softDel ? `"${softDel}"` : "null"},
2362
- includeDepthLimit: ${opts.includeDepthLimit}
2441
+ includeMethodsDepth: ${opts.includeMethodsDepth}
2363
2442
  };
2364
2443
  ${hasAuth ? `
2365
2444
  // \uD83D\uDD10 Auth: protect all routes for this table
@@ -2420,7 +2499,7 @@ ${hasAuth ? `
2420
2499
  result.data,
2421
2500
  result.includeSpec,
2422
2501
  deps.pg,
2423
- ${opts.includeDepthLimit}
2502
+ ${opts.includeMethodsDepth}
2424
2503
  );
2425
2504
  return c.json(stitched);
2426
2505
  } catch (e: any) {
@@ -3492,7 +3571,7 @@ export interface OperationContext {
3492
3571
  table: string;
3493
3572
  pkColumns: string[];
3494
3573
  softDeleteColumn?: string | null;
3495
- includeDepthLimit: number;
3574
+ includeMethodsDepth: number;
3496
3575
  }
3497
3576
 
3498
3577
  const DEBUG = process.env.SDK_DEBUG === "1" || process.env.SDK_DEBUG === "true";
@@ -4535,7 +4614,7 @@ async function generate(configPath) {
4535
4614
  if (serverFramework === "hono") {
4536
4615
  routeContent = emitHonoRoutes(table, graph, {
4537
4616
  softDeleteColumn: cfg.softDeleteColumn || null,
4538
- includeDepthLimit: cfg.includeMethodsDepth || 2,
4617
+ includeMethodsDepth: cfg.includeMethodsDepth || 2,
4539
4618
  authStrategy: normalizedAuth?.strategy,
4540
4619
  useJsExtensions: cfg.useJsExtensions
4541
4620
  });
@@ -12,7 +12,7 @@ export interface OperationContext {
12
12
  table: string;
13
13
  pkColumns: string[];
14
14
  softDeleteColumn?: string | null;
15
- includeDepthLimit: number;
15
+ includeMethodsDepth: number;
16
16
  }
17
17
  /**
18
18
  * CREATE operation - Insert a new record
@@ -5,7 +5,7 @@ import type { Table } from "./introspect";
5
5
  import type { Graph } from "./rel-classify";
6
6
  export declare function emitHonoRoutes(table: Table, _graph: Graph, opts: {
7
7
  softDeleteColumn: string | null;
8
- includeDepthLimit: number;
8
+ includeMethodsDepth: number;
9
9
  authStrategy?: string;
10
10
  useJsExtensions?: boolean;
11
11
  }): string;
@@ -16,6 +16,6 @@ import type { Graph } from "./rel-classify";
16
16
  */
17
17
  export declare function emitRoutes(table: Table, _graph: Graph, opts: {
18
18
  softDeleteColumn: string | null;
19
- includeDepthLimit: number;
19
+ includeMethodsDepth: number;
20
20
  authStrategy?: string;
21
21
  }): string;
package/dist/index.js CHANGED
@@ -1694,7 +1694,7 @@ export function register${Type}Routes(app: Hono, deps: { pg: { query: (text: str
1694
1694
  table: "${fileTableName}",
1695
1695
  pkColumns: ${JSON.stringify(safePkCols)},
1696
1696
  softDeleteColumn: ${softDel ? `"${softDel}"` : "null"},
1697
- includeDepthLimit: ${opts.includeDepthLimit}
1697
+ includeMethodsDepth: ${opts.includeMethodsDepth}
1698
1698
  };
1699
1699
  ${hasAuth ? `
1700
1700
  // \uD83D\uDD10 Auth: protect all routes for this table
@@ -1755,7 +1755,7 @@ ${hasAuth ? `
1755
1755
  result.data,
1756
1756
  result.includeSpec,
1757
1757
  deps.pg,
1758
- ${opts.includeDepthLimit}
1758
+ ${opts.includeMethodsDepth}
1759
1759
  );
1760
1760
  return c.json(stitched);
1761
1761
  } catch (e: any) {
@@ -2827,7 +2827,7 @@ export interface OperationContext {
2827
2827
  table: string;
2828
2828
  pkColumns: string[];
2829
2829
  softDeleteColumn?: string | null;
2830
- includeDepthLimit: number;
2830
+ includeMethodsDepth: number;
2831
2831
  }
2832
2832
 
2833
2833
  const DEBUG = process.env.SDK_DEBUG === "1" || process.env.SDK_DEBUG === "true";
@@ -3870,7 +3870,7 @@ async function generate(configPath) {
3870
3870
  if (serverFramework === "hono") {
3871
3871
  routeContent = emitHonoRoutes(table, graph, {
3872
3872
  softDeleteColumn: cfg.softDeleteColumn || null,
3873
- includeDepthLimit: cfg.includeMethodsDepth || 2,
3873
+ includeMethodsDepth: cfg.includeMethodsDepth || 2,
3874
3874
  authStrategy: normalizedAuth?.strategy,
3875
3875
  useJsExtensions: cfg.useJsExtensions
3876
3876
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
5
5
  "type": "module",
6
6
  "bin": {