postgresdk 0.2.0 → 0.2.1-alpha.0

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
@@ -2084,13 +2084,13 @@ export * from "./include-spec";
2084
2084
  }
2085
2085
 
2086
2086
  // src/emit-sdk-bundle.ts
2087
- function emitSdkBundle(clientFiles) {
2087
+ function emitSdkBundle(clientFiles, clientDir) {
2088
2088
  const files = {};
2089
2089
  for (const file of clientFiles) {
2090
- const parts = file.path.split("/");
2091
- const clientIndex = parts.lastIndexOf("client");
2092
- if (clientIndex >= 0 && clientIndex < parts.length - 1) {
2093
- const relativePath = parts.slice(clientIndex + 1).join("/");
2090
+ const normalizedClientDir = clientDir.replace(/\\/g, "/");
2091
+ const normalizedFilePath = file.path.replace(/\\/g, "/");
2092
+ if (normalizedFilePath.startsWith(normalizedClientDir)) {
2093
+ const relativePath = normalizedFilePath.substring(normalizedClientDir.length).replace(/^\//, "");
2094
2094
  files[relativePath] = file.content;
2095
2095
  }
2096
2096
  }
@@ -2155,7 +2155,12 @@ async function generate(configPath) {
2155
2155
  console.log("\uD83D\uDD17 Building relationship graph...");
2156
2156
  const graph = buildGraph(model);
2157
2157
  const serverDir = cfg.outServer || "./generated/server";
2158
- const clientDir = cfg.outClient || "./generated/client";
2158
+ const originalClientDir = cfg.outClient || "./generated/client";
2159
+ const sameDirectory = serverDir === originalClientDir;
2160
+ let clientDir = originalClientDir;
2161
+ if (sameDirectory) {
2162
+ clientDir = join(originalClientDir, "sdk");
2163
+ }
2159
2164
  const normDateType = cfg.dateType === "string" ? "string" : "date";
2160
2165
  console.log("\uD83D\uDCC1 Creating directories...");
2161
2166
  await ensureDirs([
@@ -2212,16 +2217,18 @@ async function generate(configPath) {
2212
2217
  path: join(serverDir, "router.ts"),
2213
2218
  content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
2214
2219
  });
2215
- const clientFiles = files.filter((f) => f.path.includes(clientDir));
2220
+ const clientFiles = files.filter((f) => {
2221
+ return f.path.includes(clientDir);
2222
+ });
2216
2223
  files.push({
2217
2224
  path: join(serverDir, "sdk-bundle.ts"),
2218
- content: emitSdkBundle(clientFiles)
2225
+ content: emitSdkBundle(clientFiles, clientDir)
2219
2226
  });
2220
2227
  console.log("✍️ Writing files...");
2221
2228
  await writeFiles(files);
2222
2229
  console.log(`✅ Generated ${files.length} files`);
2223
2230
  console.log(` Server: ${serverDir}`);
2224
- console.log(` Client: ${clientDir}`);
2231
+ console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
2225
2232
  }
2226
2233
 
2227
2234
  // src/cli.ts
@@ -5,4 +5,4 @@
5
5
  export declare function emitSdkBundle(clientFiles: {
6
6
  path: string;
7
7
  content: string;
8
- }[]): string;
8
+ }[], clientDir: string): string;
package/dist/index.js CHANGED
@@ -1847,13 +1847,13 @@ export * from "./include-spec";
1847
1847
  }
1848
1848
 
1849
1849
  // src/emit-sdk-bundle.ts
1850
- function emitSdkBundle(clientFiles) {
1850
+ function emitSdkBundle(clientFiles, clientDir) {
1851
1851
  const files = {};
1852
1852
  for (const file of clientFiles) {
1853
- const parts = file.path.split("/");
1854
- const clientIndex = parts.lastIndexOf("client");
1855
- if (clientIndex >= 0 && clientIndex < parts.length - 1) {
1856
- const relativePath = parts.slice(clientIndex + 1).join("/");
1853
+ const normalizedClientDir = clientDir.replace(/\\/g, "/");
1854
+ const normalizedFilePath = file.path.replace(/\\/g, "/");
1855
+ if (normalizedFilePath.startsWith(normalizedClientDir)) {
1856
+ const relativePath = normalizedFilePath.substring(normalizedClientDir.length).replace(/^\//, "");
1857
1857
  files[relativePath] = file.content;
1858
1858
  }
1859
1859
  }
@@ -1918,7 +1918,12 @@ async function generate(configPath) {
1918
1918
  console.log("\uD83D\uDD17 Building relationship graph...");
1919
1919
  const graph = buildGraph(model);
1920
1920
  const serverDir = cfg.outServer || "./generated/server";
1921
- const clientDir = cfg.outClient || "./generated/client";
1921
+ const originalClientDir = cfg.outClient || "./generated/client";
1922
+ const sameDirectory = serverDir === originalClientDir;
1923
+ let clientDir = originalClientDir;
1924
+ if (sameDirectory) {
1925
+ clientDir = join(originalClientDir, "sdk");
1926
+ }
1922
1927
  const normDateType = cfg.dateType === "string" ? "string" : "date";
1923
1928
  console.log("\uD83D\uDCC1 Creating directories...");
1924
1929
  await ensureDirs([
@@ -1975,16 +1980,18 @@ async function generate(configPath) {
1975
1980
  path: join(serverDir, "router.ts"),
1976
1981
  content: emitRouter(Object.values(model.tables), !!normalizedAuth?.strategy && normalizedAuth.strategy !== "none")
1977
1982
  });
1978
- const clientFiles = files.filter((f) => f.path.includes(clientDir));
1983
+ const clientFiles = files.filter((f) => {
1984
+ return f.path.includes(clientDir);
1985
+ });
1979
1986
  files.push({
1980
1987
  path: join(serverDir, "sdk-bundle.ts"),
1981
- content: emitSdkBundle(clientFiles)
1988
+ content: emitSdkBundle(clientFiles, clientDir)
1982
1989
  });
1983
1990
  console.log("✍️ Writing files...");
1984
1991
  await writeFiles(files);
1985
1992
  console.log(`✅ Generated ${files.length} files`);
1986
1993
  console.log(` Server: ${serverDir}`);
1987
- console.log(` Client: ${clientDir}`);
1994
+ console.log(` Client: ${sameDirectory ? clientDir + " (in sdk subdir due to same output dir)" : clientDir}`);
1988
1995
  }
1989
1996
  export {
1990
1997
  generate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postgresdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1-alpha.0",
4
4
  "description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
5
5
  "type": "module",
6
6
  "bin": {