@opengis/fastify-table 1.4.50 → 1.4.51
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 +1 -1
- package/server/plugins/crud/funcs/validateData.js +1 -0
- package/server/plugins/grpc/grpc.js +1 -0
- package/server/plugins/grpc/office2pdf.js +1 -0
- package/server/plugins/md/funcs/formatMdoc.js +4 -3
- package/server/plugins/migration/exec.migrations.js +0 -1
- package/server/plugins/migration/exec.sql.js +1 -0
- package/server/plugins/policy/index.js +2 -3
- package/server/plugins/table/funcs/getFilterSQL/index.js +2 -2
- package/server/plugins/table/funcs/getFilterSQL/util/getRangeQuery.js +4 -4
- package/server/plugins/table/funcs/getSelect.js +1 -1
- package/server/plugins/util/funcs/flattenObject.js +2 -2
- package/server/plugins/util/funcs/unflattenObject.js +2 -2
- package/server/routes/file/controllers/resize.js +1 -0
- package/server/routes/logger/controllers/logger.test.api.js +1 -0
- package/server/routes/table/controllers/filter.js +3 -3
- package/server/routes/table/functions/getData.js +8 -6
- package/server/plugins/migration/get.caller.dir.js +0 -26
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
function handleData(data, curr, acc, titles, plain, splittype = 1) {
|
|
2
3
|
const titleStr = {
|
|
3
4
|
1: `${(titles?.[curr] || curr)}\n`, // for lists
|
|
4
5
|
2: `${(titles?.[curr] || curr)}: `, // one-liner
|
|
@@ -8,8 +9,8 @@ function handleData(data, curr, acc, titles = {}, plain, splittype = 1) {
|
|
|
8
9
|
if (Array.isArray(data[curr])) {
|
|
9
10
|
const str = `${plain ? '' : '\n\n### '}${titleStr}${data[curr].map(el => {
|
|
10
11
|
if (typeof el === 'object' && !Array.isArray(el)) {
|
|
11
|
-
const
|
|
12
|
-
return `\n - ${
|
|
12
|
+
const str1 = Object.keys(el).filter(item => item !== 'id').reduce((acc1, curr1) => handleData(el, curr1, acc1, {}, 1, 3), '');
|
|
13
|
+
return `\n - ${str1}`;
|
|
13
14
|
}
|
|
14
15
|
return `\n - ${el}`;
|
|
15
16
|
})}`;
|
|
@@ -5,7 +5,6 @@ import { readdirSync, existsSync } from 'node:fs';
|
|
|
5
5
|
import config from '../../../config.js';
|
|
6
6
|
import execSql from './exec.sql.js';
|
|
7
7
|
import pgClients from '../pg/pgClients.js';
|
|
8
|
-
// import getCallerDir from './get.caller.dir.js';
|
|
9
8
|
|
|
10
9
|
const time = Date.now();
|
|
11
10
|
const debug = config.debug || config.local;
|
|
@@ -3,9 +3,8 @@ import checkPolicy from './funcs/checkPolicy.js';
|
|
|
3
3
|
async function plugin(fastify) {
|
|
4
4
|
fastify.addHook('preParsing', async (request, reply) => {
|
|
5
5
|
const resp = checkPolicy(request, reply);
|
|
6
|
-
if (resp) {
|
|
7
|
-
|
|
8
|
-
}
|
|
6
|
+
if (resp) { return resp; }
|
|
7
|
+
return null;
|
|
9
8
|
});
|
|
10
9
|
}
|
|
11
10
|
|
|
@@ -49,7 +49,7 @@ export default async function getFilterSQL({
|
|
|
49
49
|
if (body?.table && !checkInline[body?.table] && body?.sql?.length) {
|
|
50
50
|
const filterSql = body.sql.filter(el => !el?.disabled && (el.inline ?? true));
|
|
51
51
|
const sqlTable = filterSql.map((el, i) => ` left join lateral (${el.sql}) ${el.name || `t${i}`} on 1=1 `)?.join('') || '';
|
|
52
|
-
const d = await Promise.all(filterSql.map((el, i) => pg.query(`select ${el.name || `t${i}`}.* from(select * from ${body.table})t ${sqlTable} limit 0`).then(
|
|
52
|
+
const d = await Promise.all(filterSql.map((el, i) => pg.query(`select ${el.name || `t${i}`}.* from(select * from ${body.table})t ${sqlTable} limit 0`).then(item => item.fields)));
|
|
53
53
|
d.forEach((el, i) => {
|
|
54
54
|
filterSql[i].inline = el.length === 1;
|
|
55
55
|
filterSql[i].fields = el.map(f => f.name);
|
|
@@ -97,7 +97,7 @@ export default async function getFilterSQL({
|
|
|
97
97
|
.concat(filterResponse?.list || [])
|
|
98
98
|
?.filter(el => el.id || el.name)
|
|
99
99
|
?.map(async (el) => {
|
|
100
|
-
el
|
|
100
|
+
Object.assign(el, { name: el.name || el.id });
|
|
101
101
|
|
|
102
102
|
if (el.name && extraColumns.find(item => item?.name === el?.name)) {
|
|
103
103
|
Object.assign(el, { extra: { table: extraDataTable, input: extraColumns.find(item => item?.name === el?.name)?.type } });
|
|
@@ -136,14 +136,14 @@ export default function getRangeQuery(value, name, fieldType, filterType, sql, e
|
|
|
136
136
|
// default
|
|
137
137
|
if (max === 'max') {
|
|
138
138
|
return ['date', 'datepicker'].includes(filterType)
|
|
139
|
-
? `${name}
|
|
140
|
-
: `${name}
|
|
139
|
+
? `${name} >= '${min}'::date`
|
|
140
|
+
: `${name} >= ${min}`;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
if (min === 'min') {
|
|
144
144
|
return ['date', 'datepicker'].includes(filterType)
|
|
145
|
-
? `${name}
|
|
146
|
-
: `${name}
|
|
145
|
+
? `${name} <= '${max}'::date`
|
|
146
|
+
: `${name} <= ${max}`;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
if (['date', 'datepicker'].includes(filterType)) {
|
|
@@ -16,7 +16,7 @@ export default async function getSelect(name, pg = pgClients.client) {
|
|
|
16
16
|
const clsDataGIT = await getTemplate(['cls', 'select'], name);
|
|
17
17
|
const { type } = !clsDataGIT && pg.pk?.['admin.user_cls'] ? await pg.query('select type from admin.user_cls where parent is null and name=$1 union all select type from admin.cls where parent is null and name=$1 limit 1', [name]).then(el => el.rows?.[0] || {}) : {};
|
|
18
18
|
const q = !clsDataGIT && type && ['sql', 'json'].includes(type) ? sqls[type] : undefined;
|
|
19
|
-
const clsDataDB = q ? await pg.query(q, [name]).then(el => el.rows?.find(
|
|
19
|
+
const clsDataDB = q ? await pg.query(q, [name]).then(el => el.rows?.find(item => item?.data)?.data) : undefined;
|
|
20
20
|
const clsData = clsDataGIT || clsDataDB;
|
|
21
21
|
if (!clsData) return null;
|
|
22
22
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export default function flattenObject(obj
|
|
2
|
-
return Object.keys(obj).reduce((acc, key) => {
|
|
1
|
+
export default function flattenObject(obj, keys, parent = '') {
|
|
2
|
+
return Object.keys(obj || {}).reduce((acc, key) => {
|
|
3
3
|
const newKey = parent ? `${parent}.${key}` : key;
|
|
4
4
|
if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
|
|
5
5
|
Object.assign(acc, flattenObject(obj[key], keys, newKey));
|
|
@@ -12,7 +12,7 @@ export default function unflattenObject(flatObj) {
|
|
|
12
12
|
nestedObj[part] = JSON.parse(flatObj[key]);
|
|
13
13
|
}
|
|
14
14
|
catch (err) {
|
|
15
|
-
|
|
15
|
+
console.warn(`Error parsing JSON for key ${key}:`, err.toString());
|
|
16
16
|
nestedObj[part] = flatObj[key]; // fallback to original value if parsing fails
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -21,7 +21,7 @@ export default function unflattenObject(flatObj) {
|
|
|
21
21
|
nestedObj[part] = JSON.parse(flatObj[key]);
|
|
22
22
|
}
|
|
23
23
|
catch (err) {
|
|
24
|
-
|
|
24
|
+
console.warn(`Error parsing JSON for key ${key}:`, err.toString());
|
|
25
25
|
nestedObj[part] = flatObj[key]; // fallback to original value if parsing fails
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -105,10 +105,10 @@ export default async function filterAPI(req, reply, iscalled) {
|
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
const sqlList = loadTable?.sql
|
|
108
|
+
/* const sqlList = loadTable?.sql
|
|
109
109
|
?.filter((el) => !el.disabled && el?.sql?.replace)
|
|
110
110
|
?.map((el, i) => ` left join lateral (${el.filter ? el.sql.replace(/limit 1/ig, '') : el.sql}) as ${el.name || `t${i + 1}`} on 1=1 `)
|
|
111
|
-
?.join(' ') || '';
|
|
111
|
+
?.join(' ') || ''; */
|
|
112
112
|
|
|
113
113
|
// percentile_cont - alternative
|
|
114
114
|
await Promise.all(filters.filter((el) => el.name && el.type === 'Range' && fields?.find?.((item) => item?.name === el.name)).map(async (el) => {
|
|
@@ -119,7 +119,7 @@ export default async function filterAPI(req, reply, iscalled) {
|
|
|
119
119
|
percentile_disc(0.5) within group (order by ${el.name}),
|
|
120
120
|
percentile_disc(0.75) within group (order by ${el.name}),
|
|
121
121
|
max(${el.name})
|
|
122
|
-
] as range from ${table}
|
|
122
|
+
] as range from ${table} where ${tableQuery || '1=1'}`,
|
|
123
123
|
{ table },
|
|
124
124
|
).then(res => {
|
|
125
125
|
if (res.timeout) {
|
|
@@ -227,11 +227,13 @@ export default async function dataAPI(req, reply, called) {
|
|
|
227
227
|
|
|
228
228
|
if (uid && rows.length && !config.security?.disableToken && (editable || actions.includes('edit') || actions.includes('del'))) {
|
|
229
229
|
rows.forEach(row => {
|
|
230
|
-
row
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
230
|
+
Object.assign(row, {
|
|
231
|
+
token: setToken({
|
|
232
|
+
ids: [JSON.stringify({ id: row.id, table: tokenData?.table || hookData?.table || params.table, form: loadTable?.form })],
|
|
233
|
+
uid,
|
|
234
|
+
array: 1,
|
|
235
|
+
})?.[0],
|
|
236
|
+
});
|
|
235
237
|
});
|
|
236
238
|
}
|
|
237
239
|
|
|
@@ -308,7 +310,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
308
310
|
|
|
309
311
|
// conditions
|
|
310
312
|
panels?.filter(el => el.items).forEach(el => {
|
|
311
|
-
el
|
|
313
|
+
Object.assign(el, { items: el.items?.filter(item => conditions(item.conditions, rows[0])) });
|
|
312
314
|
});
|
|
313
315
|
|
|
314
316
|
// title, count
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
|
|
3
|
-
export default function getCallerDir() {
|
|
4
|
-
const originalFunc = Error.prepareStackTrace;
|
|
5
|
-
|
|
6
|
-
let callerfile;
|
|
7
|
-
try {
|
|
8
|
-
const err = new Error();
|
|
9
|
-
// let currentfile;
|
|
10
|
-
|
|
11
|
-
Error.prepareStackTrace = function (err, stack) { return stack; };
|
|
12
|
-
|
|
13
|
-
const currentfile = err.stack.shift().getFileName();
|
|
14
|
-
|
|
15
|
-
while (err.stack.length) {
|
|
16
|
-
callerfile = err.stack.shift().getFileName();
|
|
17
|
-
|
|
18
|
-
if (currentfile !== callerfile) break;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
catch (err) { }
|
|
22
|
-
|
|
23
|
-
Error.prepareStackTrace = originalFunc;
|
|
24
|
-
|
|
25
|
-
return path.dirname(callerfile);
|
|
26
|
-
}
|