Skip to content

Commit c0c7db4

Browse files
committed
fix: improve stdout handling in callTsProxy and enhance resource column synchronization error handling
1 parent 0b9e623 commit c0c7db4

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

adminforth/commands/callTsProxy.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ export function callTsProxy(tsCode, silent=false) {
4747
env: getEnvWithLocalBin(currentDirectory),
4848
});
4949
let stderr = "";
50-
let stdoutLogs = [];
50+
let stdout = "";
5151

5252
child.stdout.on("data", (data) => {
53-
stdoutLogs.push(data.toString());
53+
stdout += data.toString();
5454
});
5555

5656
child.stderr.on("data", (data) => {
@@ -62,17 +62,18 @@ export function callTsProxy(tsCode, silent=false) {
6262
});
6363

6464
child.on("close", (code) => {
65-
const tsProxyResult = stdoutLogs.find(log => log.includes('>>>>>>>'));
66-
if (!tsProxyResult) {
67-
reject(new Error(`Invalid JSON from tsproxy. stdout: ${stdoutLogs.join("")}, stderr: ${stderr}`));
65+
const resultStart = stdout.indexOf('>>>>>>>');
66+
const resultEnd = stdout.lastIndexOf('<<<<<<<');
67+
if (resultStart === -1 || resultEnd === -1 || resultEnd < resultStart) {
68+
reject(new Error(`Invalid JSON from tsproxy. stdout: ${stdout}, stderr: ${stderr}`));
6869
return;
6970
}
70-
const preparedStdout = tsProxyResult.slice(tsProxyResult.indexOf('>>>>>>>') + 7, tsProxyResult.lastIndexOf('<<<<<<<'));
71-
const preparedStdoutLogs = stdoutLogs.filter(log => !log.includes('>>>>>>>'));
71+
const preparedStdout = stdout.slice(resultStart + 7, resultEnd);
72+
const preparedStdoutLogs = stdout.slice(0, resultStart);
7273
if (code === 0) {
7374
try {
74-
for (const log of preparedStdoutLogs) {
75-
console.log(log);
75+
if (preparedStdoutLogs) {
76+
process.stdout.write(preparedStdoutLogs);
7677
}
7778
const parsed = JSON.parse(preparedStdout);
7879
if (!silent) {

adminforth/commands/createResource/generateResourceFile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,16 @@ async function syncResourceColumns(filePath, content, discoveredColumns) {
130130
throw new Error(`Could not find resource columns array in ${filePath}`);
131131
}
132132

133+
const dynamicColumnElements = columnsArray.elements.filter((element) => !n.ObjectExpression.check(element));
134+
if (dynamicColumnElements.length) {
135+
throw new Error(
136+
`Resource columns array in ${filePath} contains dynamic entries. ` +
137+
`Please sync this resource manually because automatic column import only supports literal column objects.`
138+
);
139+
}
140+
133141
const existingColumnNames = new Set(
134142
columnsArray.elements
135-
.filter((element) => n.ObjectExpression.check(element))
136143
.map((element) => getObjectPropertyValue(element, "name"))
137144
.filter(Boolean)
138145
);

adminforth/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ class AdminForth implements IAdminForth {
522522

523523
async getAllColumnsInTable(
524524
tableName: string,
525-
dataSourceId?: string
525+
requestedDataSourceId?: string
526526
): Promise<{ [dataSourceId: string]: Array<{ name: string; type?: string; isPrimaryKey?: boolean; isUUID?: boolean; }> }> {
527527
const results: { [dataSourceId: string]: Array<{ name: string; type?: string; isPrimaryKey?: boolean; isUUID?: boolean; }> } = {};
528528

@@ -532,7 +532,7 @@ class AdminForth implements IAdminForth {
532532

533533
await Promise.all(
534534
Object.entries(this.connectors)
535-
.filter(([connectorDataSourceId]) => !dataSourceId || connectorDataSourceId === dataSourceId)
535+
.filter(([dataSourceId]) => !requestedDataSourceId || dataSourceId === requestedDataSourceId)
536536
.map(async ([dataSourceId, connector]) => {
537537
if (typeof connector.getAllColumnsInTable === 'function') {
538538
try {
@@ -838,4 +838,4 @@ class AdminForth implements IAdminForth {
838838

839839
}
840840

841-
export default AdminForth;
841+
export default AdminForth;

0 commit comments

Comments
 (0)