@opengis/fastify-table 1.2.82 → 1.2.84
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,5 +1,5 @@
|
|
|
1
1
|
import getTemplate from '../../..//table/funcs/getTemplate.js';
|
|
2
|
-
import
|
|
2
|
+
import metaFormat from '../../../table/funcs/metaFormat/index.js';
|
|
3
3
|
|
|
4
4
|
const defaultTitles = {
|
|
5
5
|
editor_date: 'Дата оновлення',
|
|
@@ -82,11 +82,9 @@ export default async function logChanges({
|
|
|
82
82
|
.filter(el => schema[el]?.data)
|
|
83
83
|
.reduce((acc, curr) => Object.assign(acc, { [curr]: schema[curr].data }), {});
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
await metaFormat({ rows: [data], cls, sufix: false });
|
|
87
|
-
}
|
|
85
|
+
const data1 = data ? await metaFormat({ rows: [data], cls, sufix: false, reassign: false }) : null;
|
|
88
86
|
|
|
89
|
-
const newObj = Object.fromEntries(Object.entries(
|
|
87
|
+
const newObj = Object.fromEntries(Object.entries(data1 || {}).map(el => ([[titles[el[0]] || defaultTitles[el[0]] || el[0]], el[1]])));
|
|
90
88
|
const changesData = Object.keys(newObj || {}).map(el => ({
|
|
91
89
|
change_id: changeId,
|
|
92
90
|
entity_key: el,
|
|
@@ -8,9 +8,21 @@ import getSelect from './getSelect.js';
|
|
|
8
8
|
const limit = 50;
|
|
9
9
|
const selectMeta = {};
|
|
10
10
|
|
|
11
|
-
export default async function getSelectMeta({ name, pg = pgClients.client, nocache }) {
|
|
11
|
+
export default async function getSelectMeta({ name, pg = pgClients.client, nocache, table, column, key, val }) {
|
|
12
12
|
if (selectMeta[name] && !nocache) return selectMeta[name];
|
|
13
13
|
|
|
14
|
+
if (table && column) {
|
|
15
|
+
const original = {
|
|
16
|
+
false: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column}, count(*) from ${table} group by ${column} limit ${limit}) select * from c`,
|
|
17
|
+
true: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column} from ${table}) select * from c`,
|
|
18
|
+
}[!!(key || val)];
|
|
19
|
+
return {
|
|
20
|
+
original,
|
|
21
|
+
searchQuery: '(lower("text") ~ $1 )',
|
|
22
|
+
pk: 'id',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
const cls = await getSelect(name, pg);
|
|
15
27
|
const db = typeof cls?.db === 'string' ? { database: cls.db } : cls?.db;
|
|
16
28
|
const pg1 = cls?.db ? getPG(db) : pg;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
import { handlebars } from '@opengis/fastify-hb/utils.js';
|
|
2
4
|
|
|
3
5
|
import getTemplate from '../getTemplate.js';
|
|
@@ -5,13 +7,15 @@ import getSelectVal from './getSelectVal.js';
|
|
|
5
7
|
import pgClients from '../../../pg/pgClients.js';
|
|
6
8
|
|
|
7
9
|
export default async function metaFormat({
|
|
8
|
-
rows, table, cls, sufix = true,
|
|
10
|
+
rows: original, table, cls, sufix = true, reassign = true,
|
|
9
11
|
}, pg = pgClients.client) {
|
|
10
12
|
const loadTable = table ? await getTemplate('table', table) : {};
|
|
11
13
|
const selectCols = Object.keys(cls || {}).map(key => ({ name: key, data: cls[key] })).concat(loadTable?.columns?.filter((e) => e.data) || []);
|
|
12
14
|
const metaCls = Object.keys(loadTable?.meta?.cls || {}).map((el) => ({ name: el, data: loadTable?.meta?.cls[el] }));
|
|
13
15
|
const htmlCols = loadTable?.columns?.filter?.((e) => e.name && e.format === 'html' && e.html) || [];
|
|
14
|
-
if (!selectCols?.length && !metaCls?.length && !htmlCols?.length) return
|
|
16
|
+
if (!original?.length || !selectCols?.length && !metaCls?.length && !htmlCols?.length) return original;
|
|
17
|
+
|
|
18
|
+
const rows = reassign ? original : JSON.parse(JSON.stringify(original));
|
|
15
19
|
|
|
16
20
|
await Promise.all(htmlCols.map(async (attr) => {
|
|
17
21
|
await Promise.all(rows.filter(row => row?.[attr.name])?.map(async (row) => {
|
|
@@ -42,12 +42,7 @@ export default async function suggest(req) {
|
|
|
42
42
|
return { status: 400, message: 'param limit is invalid' };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const meta = table
|
|
46
|
-
? {
|
|
47
|
-
original: `with c(id,text) as (select ${column || 'row_number() over()'}, ${column}, count(*) from ${tableName} group by ${column} limit ${limit}) select * from c`,
|
|
48
|
-
searchQuery: '(lower("text") ~ $1 )',
|
|
49
|
-
}
|
|
50
|
-
: await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache });
|
|
45
|
+
const meta = await getSelectMeta({ pg: pg1, name: selectName, nocache: query?.nocache, table, column, key: query?.key, val: query?.val });
|
|
51
46
|
|
|
52
47
|
if (meta?.minLength && query.key && query.key.length < meta?.minLength) {
|
|
53
48
|
return { message: `min length: ${meta.minLength}` };
|