Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/list-tables-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@proofkit/typegen": patch
---

Fix list-tables endpoint 431 error by converting from GET to POST
64 changes: 33 additions & 31 deletions packages/typegen/src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,42 +432,44 @@ export function createApiApp(context: ApiContext) {
}
},
)
.get("/list-tables", zValidator("query", z.object({ config: z.string() })), async (c) => {
const input = c.req.valid("query");
// Parse the JSON-encoded config string
let config: z.infer<typeof typegenConfigSingle>;
try {
config = typegenConfigSingle.parse(JSON.parse(input.config));
} catch (_err) {
return c.json({ error: "Invalid config format" }, 400);
}
if (config.type !== "fmodata") {
return c.json({ error: "Invalid config type" }, 400);
}
try {
const result = createOdataClientFromConfig(config);
if ("error" in result) {
.post(
"/list-tables",
zValidator("json", z.object({ config: typegenConfigSingleRequestForValidation })),
async (c) => {
const rawInput = c.req.valid("json");
const configWithType =
"type" in rawInput.config && rawInput.config.type
? rawInput.config
: { ...(rawInput.config as Record<string, unknown>), type: "fmdapi" as const };
const config = typegenConfigSingle.parse(configWithType);
if (config.type !== "fmodata") {
return c.json({ error: "Invalid config type" }, 400);
}
try {
const result = createOdataClientFromConfig(config);
if ("error" in result) {
return c.json(
{
error: result.error,
kind: result.kind,
suspectedField: result.suspectedField,
},
result.statusCode as ContentfulStatusCode,
);
}
const { db } = result;
const tableNames = await db.listTableNames();
return c.json({ tables: tableNames });
} catch (err) {
return c.json(
{
error: result.error,
kind: result.kind,
suspectedField: result.suspectedField,
error: err instanceof Error ? err.message : "Failed to list tables",
},
result.statusCode as ContentfulStatusCode,
500,
);
}
const { db } = result;
const tableNames = await db.listTableNames();
return c.json({ tables: tableNames });
} catch (err) {
return c.json(
{
error: err instanceof Error ? err.message : "Failed to list tables",
},
500,
);
}
})
},
)
// POST /api/test-connection
.post(
"/test-connection",
Expand Down
6 changes: 3 additions & 3 deletions packages/typegen/web/src/hooks/useListTables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export function useListTables(configIndex: number, enabled?: boolean) {
throw new Error("Config not found or invalid type");
}

const res = await client.api["list-tables"].$get({
query: {
config: JSON.stringify(config),
const res = await client.api["list-tables"].$post({
json: {
config,
},
});

Expand Down
Loading