@opengis/fastify-table 1.1.139 → 1.1.141

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.1.139",
3
+ "version": "1.1.141",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -61,7 +61,10 @@ export default async function logChanges({
61
61
  Object.keys(data || {}).filter(key => typeof data[key] === 'boolean').forEach(key => Object.assign(cls, { [key]: 'yes_no' }));
62
62
  const titles = (body?.columns || columns)?.reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.title || curr.ua }), {});
63
63
 
64
- await metaFormat({ rows: [data], cls, sufix: false });
64
+ if (data) {
65
+ await metaFormat({ rows: [data], cls, sufix: false });
66
+ }
67
+
65
68
  const newObj = Object.fromEntries(Object.entries(data || {}).map(el => ([[titles[el[0]] || el[0]], el[1]])));
66
69
  const changesData = Object.keys(newObj || {}).map(el => ({
67
70
  change_id: changeId,
@@ -7,7 +7,7 @@ export default async function getMeta(opt) {
7
7
  const pg = opt?.pg || getPG({ name: 'client' });
8
8
  const table = opt?.table || opt;
9
9
 
10
- if (data[table]) return data[table];
10
+ if (data[pg.options.database]?.[table]) return data[pg.options.database][table];
11
11
 
12
12
  if (!pg.tlist?.includes(table?.replace?.(/"/g, ''))) {
13
13
  return { error: `${table} - not found`, status: 400 };
@@ -25,9 +25,23 @@ export default async function getMeta(opt) {
25
25
 
26
26
  const geomAttr = fields.find((el) => pg.pgType?.[el.dataTypeID] === 'geometry')?.name; // change geometry text to geometry code
27
27
 
28
+ const dbColumns = await pg.query(`select json_object_agg(
29
+ attname,
30
+ json_build_object(
31
+ 'title', pg_catalog.col_description(attrelid,attnum)
32
+ /*,'type', atttypid::regtype */
33
+ )
34
+ ) from pg_catalog.pg_attribute a
35
+ where attrelid=$1::regclass and attnum>0`, [table]).then(el => el.rows?.[0]?.json_object_agg || {});
36
+
37
+ fields.forEach(el => Object.assign(el, { ...dbColumns[el.name] || {} }));
38
+
28
39
  const res = {
29
40
  pk, columns: fields, geom: geomAttr, view: pg.relkinds?.[table] === 'v',
30
41
  };
31
- data[table] = res;
42
+ if (!data[pg.options.database]) {
43
+ data[pg.options.database] = {};
44
+ }
45
+ data[pg.options.database][table] = res;
32
46
  return res;
33
47
  }