@opengis/fastify-table 2.0.18 → 2.0.19

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.
@@ -7,8 +7,8 @@ export default function getTemplateDir(type) {
7
7
  const arr = Array.isArray(type)
8
8
  ? type.map((el) => getTemplatePath(el)).flat()
9
9
  : getTemplatePath(type);
10
- if (!loadTemplate[type]) {
11
- loadTemplate[type] = arr.filter((el) => fs.existsSync(el[1]));
10
+ if (!loadTemplate[type.toString()]) {
11
+ loadTemplate[type.toString()] = arr.filter((el) => fs.existsSync(el[1]));
12
12
  }
13
- return loadTemplate[type];
13
+ return loadTemplate[type.toString()];
14
14
  }
@@ -1,5 +1,6 @@
1
1
  import { handlebars } from "../../../../helpers/index.js";
2
2
  import getTemplate from "../getTemplate.js";
3
+ import getTemplates from "../getTemplates.js";
3
4
  import getSelectVal from "./getSelectVal.js";
4
5
  import pgClients from "../../../pg/pgClients.js";
5
6
  export default async function metaFormat({ rows: original, table, cls = {}, htmls = {}, sufix = true, reassign = true, }, pg = pgClients.client) {
@@ -11,11 +12,21 @@ export default async function metaFormat({ rows: original, table, cls = {}, html
11
12
  name: el,
12
13
  data: loadTable?.meta?.cls[el],
13
14
  }));
15
+ const list = getTemplates(["cls", "select"]).map((el) => el[0]);
16
+ const columnNameAsCls = Object.keys(original?.[0] || {})
17
+ .filter((key) => list.includes(`${table}.${key}`) || list.includes(key))
18
+ .map((key) => ({
19
+ name: key,
20
+ data: list.find((clsName) => [key, `${table}.${key}`].includes(clsName)),
21
+ }));
14
22
  const htmlCols = Object.keys(htmls || {})
15
23
  .map((key) => ({ name: key, html: htmls[key] }))
16
24
  .concat(loadTable?.columns?.filter?.((e) => e.name && e.html && e.format && ["html", "slot"].includes(e.format)) || []);
17
25
  if (!original?.length ||
18
- (!selectCols?.length && !metaCls?.length && !htmlCols?.length))
26
+ (!selectCols?.length &&
27
+ !metaCls?.length &&
28
+ !columnNameAsCls.length &&
29
+ !htmlCols?.length))
19
30
  return original;
20
31
  const rows = reassign ? original : JSON.parse(JSON.stringify(original));
21
32
  // html && slot (vue component) format
@@ -31,7 +42,10 @@ export default async function metaFormat({ rows: original, table, cls = {}, html
31
42
  }));
32
43
  }));
33
44
  // cls & select format
34
- await Promise.all(selectCols.concat(metaCls)?.map(async (attr) => {
45
+ await Promise.all(selectCols
46
+ .concat(metaCls)
47
+ .concat(columnNameAsCls)
48
+ ?.map(async (attr) => {
35
49
  const values = [
36
50
  ...new Set(rows?.map((el) => el[attr.name]).flat()),
37
51
  ].filter((el) => (typeof el === "boolean" ? true : el));
@@ -52,9 +66,7 @@ export default async function metaFormat({ rows: original, table, cls = {}, html
52
66
  }
53
67
  else {
54
68
  Object.assign(el, {
55
- [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: val.color
56
- ? val
57
- : val.text || val,
69
+ [val?.color ? `${attr.name}_data` : `${attr.name}_text`]: val.color ? val : val.text || val,
58
70
  });
59
71
  }
60
72
  });
@@ -18,6 +18,9 @@ export default async function filterAPI(req, reply, iscalled) {
18
18
  if (!table) {
19
19
  return { status: 404, message: "not found" };
20
20
  }
21
+ if (!pg.pk?.[table]) {
22
+ return { status: 404, message: "table not found" };
23
+ }
21
24
  const sqlTable = sql
22
25
  ?.filter?.((el) => !el?.disabled && el?.sql?.replace)
23
26
  ?.map?.((el, i) => ` left join lateral (${el.sql.replace("{{uid}}", user?.uid)}) ${el.name || `t${i}`} on 1=1 `)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [