postgresdk 0.2.0 → 0.2.1-alpha.1
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 -10
- package/dist/emit-sdk-bundle.d.ts +1 -1
- package/dist/index.js +17 -10
- package/package.json +3 -2
package/dist/cli.js
CHANGED
@@ -2041,7 +2041,7 @@ ${registrations}
|
|
2041
2041
|
|
2042
2042
|
router.get("/sdk/files/:path{.*}", (c) => {
|
2043
2043
|
const path = c.req.param("path");
|
2044
|
-
const content = SDK_MANIFEST.files[path];
|
2044
|
+
const content = SDK_MANIFEST.files[path as keyof typeof SDK_MANIFEST.files];
|
2045
2045
|
if (!content) {
|
2046
2046
|
return c.text("File not found", 404);
|
2047
2047
|
}
|
@@ -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
|
2091
|
-
const
|
2092
|
-
if (
|
2093
|
-
const relativePath =
|
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
|
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) =>
|
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
|
package/dist/index.js
CHANGED
@@ -1804,7 +1804,7 @@ ${registrations}
|
|
1804
1804
|
|
1805
1805
|
router.get("/sdk/files/:path{.*}", (c) => {
|
1806
1806
|
const path = c.req.param("path");
|
1807
|
-
const content = SDK_MANIFEST.files[path];
|
1807
|
+
const content = SDK_MANIFEST.files[path as keyof typeof SDK_MANIFEST.files];
|
1808
1808
|
if (!content) {
|
1809
1809
|
return c.text("File not found", 404);
|
1810
1810
|
}
|
@@ -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
|
1854
|
-
const
|
1855
|
-
if (
|
1856
|
-
const relativePath =
|
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
|
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) =>
|
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.
|
3
|
+
"version": "0.2.1-alpha.1",
|
4
4
|
"description": "Generate a typed server/client SDK from a Postgres schema (includes, Zod, Hono).",
|
5
5
|
"type": "module",
|
6
6
|
"bin": {
|
@@ -22,10 +22,11 @@
|
|
22
22
|
},
|
23
23
|
"scripts": {
|
24
24
|
"build": "bun build src/cli.ts src/index.ts --outdir dist --target node --format esm --external=pg --external=zod --external=hono --external=node:* && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
25
|
-
"test": "bun test:init && bun test:gen && bun test:pull",
|
25
|
+
"test": "bun test:init && bun test:gen && bun test:pull && bun test:typecheck",
|
26
26
|
"test:init": "bun test/test-init.ts",
|
27
27
|
"test:gen": "bun test/test-gen.ts",
|
28
28
|
"test:pull": "bun test/test-pull.ts",
|
29
|
+
"test:typecheck": "bun test/test-typecheck.ts",
|
29
30
|
"prepublishOnly": "npm run build",
|
30
31
|
"publish:patch": "./publish.sh",
|
31
32
|
"publish:minor": "./publish.sh",
|