From c91cc166491dc77b4e95059c00091e218fe0463f Mon Sep 17 00:00:00 2001 From: gerard1001 Date: Fri, 17 Apr 2026 12:37:20 +0200 Subject: [PATCH 1/2] Fix:show js code's provider table's fields --- table-provider.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/table-provider.js b/table-provider.js index 6fbd313..ef975fb 100644 --- a/table-provider.js +++ b/table-provider.js @@ -175,7 +175,23 @@ const configuration_workflow = (req) => module.exports = { "JavaScript code": { configuration_workflow, - fields: (cfg) => cfg?.columns || [], + fields: async (cfg) => { + const parsed = typeof cfg === "string" ? JSON.parse(cfg) : cfg; + if (parsed?.columns?.length) return parsed.columns; + if (!parsed?.code) return []; + try { + const rows = await runCode(parsed.code, {}, {}); + if (!Array.isArray(rows) || !rows.length) return []; + const sampleRow = rows[0]; + return Object.keys(sampleRow).map((name) => ({ + name, + label: Field.nameToLabel(name), + type: jsTypeGuess(sampleRow[name]), + })); + } catch { + return []; + } + }, get_table: (cfg) => ({ getRows: async (where, opts) => { const rows = await runCode(cfg.code, where, opts); From 0c5d0ff44e770af31e8198ba5d5e49e008e85972 Mon Sep 17 00:00:00 2001 From: gerard1001 Date: Fri, 17 Apr 2026 13:32:14 +0200 Subject: [PATCH 2/2] Fix provider table views display --- table-provider.js | 62 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/table-provider.js b/table-provider.js index ef975fb..af799ad 100644 --- a/table-provider.js +++ b/table-provider.js @@ -177,30 +177,46 @@ module.exports = { configuration_workflow, fields: async (cfg) => { const parsed = typeof cfg === "string" ? JSON.parse(cfg) : cfg; - if (parsed?.columns?.length) return parsed.columns; - if (!parsed?.code) return []; - try { - const rows = await runCode(parsed.code, {}, {}); - if (!Array.isArray(rows) || !rows.length) return []; - const sampleRow = rows[0]; - return Object.keys(sampleRow).map((name) => ({ - name, - label: Field.nameToLabel(name), - type: jsTypeGuess(sampleRow[name]), - })); - } catch { - return []; + let columns = parsed?.columns?.length ? parsed.columns : null; + if (!columns) { + if (!parsed?.code) return []; + try { + const rows = await runCode(parsed.code, {}, {}); + if (!Array.isArray(rows) || !rows.length) return []; + const sampleRow = rows[0]; + columns = Object.keys(sampleRow).map((name) => ({ + name, + label: Field.nameToLabel(name), + type: jsTypeGuess(sampleRow[name]), + })); + } catch { + return []; + } } + if (!columns.some((f) => f.primary_key)) + columns = [ + { name: "_idx", label: "Index", type: "Integer", primary_key: true }, + ...columns, + ]; + return columns; + }, + get_table: (cfg) => { + const parsed = typeof cfg === "string" ? JSON.parse(cfg) : cfg; + const hasPK = parsed?.columns?.some((f) => f.primary_key); + return { + getRows: async (where, opts) => { + const rows = await runCode(cfg.code, where, opts); + if (!Array.isArray(rows)) return []; + return hasPK ? rows : rows.map((r, i) => ({ _idx: i, ...r })); + }, + countRows: async (where, opts) => { + const rows = await runCode(cfg.code, where, opts); + return Array.isArray(rows) ? rows.length : 0; + }, + updateRow: async () => "Updates are not supported on JavaScript code provider tables", + insertRow: async () => "Inserts are not supported on JavaScript code provider tables", + deleteRows: async () => "Deletes are not supported on JavaScript code provider tables", + }; }, - get_table: (cfg) => ({ - getRows: async (where, opts) => { - const rows = await runCode(cfg.code, where, opts); - return Array.isArray(rows) ? rows : []; - }, - countRows: async (where, opts) => { - const rows = await runCode(cfg.code, where, opts); - return Array.isArray(rows) ? rows.length : 0; - }, - }), }, };