@opengis/fastify-table 1.4.27 → 1.4.29
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/file/isFileExists.js +2 -2
- package/server/plugins/file/uploadMultiPart.js +2 -1
- package/server/plugins/file/utils/getPath.js +1 -1
- package/server/plugins/file/utils/isFileExists.js +1 -0
- package/server/plugins/file/utils/uploadFileDisk.js +1 -1
- package/server/plugins/grpc/grpc.js +2 -1
- package/server/plugins/grpc/office2pdf.js +2 -1
- package/server/routes/file/controllers/export.js +14 -8
- package/server/routes/file/controllers/utils/{convertJSONToXls.js → jsonToXls.js} +1 -2
- package/server/routes/menu/controllers/getMenu.js +4 -3
- package/server/routes/table/controllers/cardData.js +2 -25
- package/server/routes/table/controllers/tableData.js +5 -3
- package/server/routes/table/functions/getData.js +26 -17
- package/utils.js +4 -0
- /package/server/routes/file/controllers/utils/{convertJSONToCSV.js → jsonToCsv.js} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
1
|
+
import path from 'node:path';
|
|
2
2
|
import providers from './providers/index.js';
|
|
3
3
|
|
|
4
|
-
async function isFileExists(filePath, options = {
|
|
4
|
+
async function isFileExists(filePath, options = {}) {
|
|
5
5
|
const filename = path.basename(filePath);
|
|
6
6
|
|
|
7
7
|
// prefix
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { mkdir } from 'node:fs/promises';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import config from '../../../config.js';
|
|
5
5
|
|
|
6
6
|
import providers from './providers/index.js';
|
|
7
|
+
|
|
7
8
|
import uploadFileDisk from './utils/uploadFileDisk.js';
|
|
8
9
|
|
|
9
10
|
import { all, images } from './utils/allowedExtensions.js';
|
|
@@ -4,7 +4,7 @@ import { rename, readFile, writeFile } from 'node:fs/promises';
|
|
|
4
4
|
import { formidable } from 'formidable';
|
|
5
5
|
import { imageSize } from 'image-size';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import config from '../../../../config.js';
|
|
8
8
|
|
|
9
9
|
import { images } from './allowedExtensions.js';
|
|
10
10
|
import grpc from '../../grpc/grpc.js';
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import grpc from '@grpc/grpc-js';
|
|
3
3
|
import protoLoader from '@grpc/proto-loader';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import config from '../../../config.js';
|
|
6
|
+
import logger from '../logger/getLogger.js';
|
|
6
7
|
|
|
7
8
|
config.ready = config.ready || {};
|
|
8
9
|
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import grpc from '@grpc/grpc-js';
|
|
3
3
|
import protoLoader from '@grpc/proto-loader';
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import config from '../../../config.js';
|
|
6
|
+
import logger from '../logger/getLogger.js';
|
|
6
7
|
|
|
7
8
|
config.ready = config.ready || {};
|
|
8
9
|
|
|
@@ -9,12 +9,18 @@ import {
|
|
|
9
9
|
mkdir, readFile, rm, writeFile,
|
|
10
10
|
} from 'node:fs/promises';
|
|
11
11
|
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
import
|
|
17
|
-
import
|
|
12
|
+
import config from '../../../../config.js';
|
|
13
|
+
import logger from '../../../plugins/logger/getLogger.js';
|
|
14
|
+
import getTemplate from '../../../plugins/table/funcs/getTemplate.js';
|
|
15
|
+
import getMeta from '../../../plugins/pg/funcs/getMeta.js';
|
|
16
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
17
|
+
import eventStream from '../../../plugins/util/funcs/eventStream.js';
|
|
18
|
+
import getData from '../../table/functions/getData.js';
|
|
19
|
+
import getFolder from '../../../plugins/crud/funcs/utils/getFolder.js';
|
|
20
|
+
import metaFormat from '../../../plugins/table/funcs/metaFormat/index.js';
|
|
21
|
+
|
|
22
|
+
import jsonToXls from './utils/jsonToXls.js';
|
|
23
|
+
import jsonToCsv from './utils/jsonToCsv.js';
|
|
18
24
|
import formatResult from './utils/formatResult.js';
|
|
19
25
|
|
|
20
26
|
const startStreamWithTotal = 10000;
|
|
@@ -262,12 +268,12 @@ export default async function exportTable({
|
|
|
262
268
|
const resp = {};
|
|
263
269
|
|
|
264
270
|
if (format === 'csv') {
|
|
265
|
-
await
|
|
271
|
+
await jsonToCsv({
|
|
266
272
|
filePath: filePathJSON, send, colmodel, domain: host, source, columnList,
|
|
267
273
|
});
|
|
268
274
|
}
|
|
269
275
|
if (format === 'xlsx') {
|
|
270
|
-
await
|
|
276
|
+
await jsonToXls({
|
|
271
277
|
filePath: filePathJSON, send, colmodel, domain: host, source, resp,
|
|
272
278
|
});
|
|
273
279
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import logger from '../../../../plugins/logger/getLogger.js';
|
|
6
5
|
import grpc from '../../../../plugins/grpc/grpc.js';
|
|
7
6
|
|
|
8
7
|
const { jsonToXls } = grpc();
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
6
6
|
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import config from '../../../../config.js';
|
|
8
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
9
|
+
import applyHook from '../../../plugins/hook/funcs/applyHook.js';
|
|
10
|
+
import menuDirs from '../../../plugins/table/funcs/menuDirs.js';
|
|
10
11
|
|
|
11
12
|
const menuCache = [];
|
|
12
13
|
|
|
@@ -50,31 +50,7 @@ export default async function getCardData(req, reply) {
|
|
|
50
50
|
return reply.status(403).send('access restricted: empty rows');
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const { rows = [] } = result;
|
|
54
|
-
|
|
55
|
-
// conditions
|
|
56
|
-
index.panels?.filter(el => el.items).forEach(el1 => {
|
|
57
|
-
el1.items = el1.items?.filter(item => conditions(item.conditions, rows[0]));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
// title, count
|
|
61
|
-
index.panels?.filter(el => el.items).forEach(async el => {
|
|
62
|
-
const filtered = el.items.filter(item => item.count?.toLowerCase?.().includes('select'));
|
|
63
|
-
|
|
64
|
-
const data = await Promise.all(filtered.map(el1 => pg.query(el1.count).then(item => item.rows?.[0] || {})));
|
|
65
|
-
|
|
66
|
-
filtered.forEach((item1, i) => {
|
|
67
|
-
Object.assign(item1, data[i] || {}, data[i].count ? {} : { count: undefined });
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const q = el.items.map((item2) => (item2.component ? components[item2.component] : null)).filter(item2 => item2).join(' union all ');
|
|
71
|
-
|
|
72
|
-
const counts = q && id
|
|
73
|
-
? await pg.query(q, [id])
|
|
74
|
-
.then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
|
|
75
|
-
: {};
|
|
76
|
-
el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts?.[item.component] }));
|
|
77
|
-
});
|
|
53
|
+
const { rows = [], panels } = result;
|
|
78
54
|
|
|
79
55
|
// tokens result
|
|
80
56
|
const tokens = {};
|
|
@@ -137,6 +113,7 @@ export default async function getCardData(req, reply) {
|
|
|
137
113
|
return {
|
|
138
114
|
time: Date.now() - time,
|
|
139
115
|
...index,
|
|
116
|
+
panels,
|
|
140
117
|
tokens,
|
|
141
118
|
vue,
|
|
142
119
|
data,
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import getToken from '../../../plugins/crud/funcs/getToken.js';
|
|
2
|
+
import getOpt from '../../../plugins/crud/funcs/getOpt.js';
|
|
3
|
+
import getTemplate from '../../../plugins/table/funcs/getTemplate.js';
|
|
4
|
+
import getMeta from '../../../plugins/pg/funcs/getMeta.js';
|
|
5
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
4
6
|
|
|
5
7
|
import getData from '../functions/getData.js';
|
|
6
8
|
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import config from '../../../../config.js';
|
|
2
|
+
import { handlebars, handlebarsSync } from '../../../helpers/index.js';
|
|
3
|
+
|
|
4
|
+
import getFilterSQL from '../../../plugins/table/funcs/getFilterSQL/index.js';
|
|
5
|
+
import getAccess from '../../../plugins/crud/funcs/getAccess.js';
|
|
6
|
+
import setToken from '../../../plugins/crud/funcs/setToken.js';
|
|
7
|
+
import gisIRColumn from '../../../plugins/table/funcs/gisIRColumn.js';
|
|
8
|
+
import applyHook from '../../../plugins/hook/funcs/applyHook.js';
|
|
9
|
+
import getSelect from '../../../plugins/table/funcs/getSelect.js';
|
|
10
|
+
import setOpt from '../../../plugins/crud/funcs/setOpt.js';
|
|
11
|
+
import getOpt from '../../../plugins/crud/funcs/getOpt.js';
|
|
12
|
+
import getFilter from '../../../plugins/table/funcs/getFilter.js';
|
|
13
|
+
import logger from '../../../plugins/logger/getLogger.js';
|
|
14
|
+
import getTemplate from '../../../plugins/table/funcs/getTemplate.js';
|
|
15
|
+
import getMeta from '../../../plugins/pg/funcs/getMeta.js';
|
|
16
|
+
import pgClients from '../../../plugins/pg/pgClients.js';
|
|
17
|
+
import metaFormat from '../../../plugins/table/funcs/metaFormat/index.js';
|
|
4
18
|
|
|
5
19
|
import extraDataGet from '../../../plugins/extra/extraDataGet.js';
|
|
6
20
|
|
|
@@ -17,14 +31,6 @@ const checkInline = {};
|
|
|
17
31
|
const maxLimit = 100;
|
|
18
32
|
const defaultLimit = 20;
|
|
19
33
|
|
|
20
|
-
function getOrder(query, columnList, orderColumn, loadTable, orderDir, called) {
|
|
21
|
-
if (query?.order && called) { return `order by ${query.order}`; }
|
|
22
|
-
if (typeof orderColumn === 'string' && Array.isArray(columnList) && columnList.includes(orderColumn)) {
|
|
23
|
-
return `order by ${orderColumn} ${query?.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`;
|
|
24
|
-
}
|
|
25
|
-
return `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
34
|
export default async function dataAPI(req, reply, called) {
|
|
29
35
|
const {
|
|
30
36
|
pg = pgClients.client, params, headers = {}, query = {}, user = {}, contextQuery, sufix = true,
|
|
@@ -174,8 +180,9 @@ export default async function dataAPI(req, reply, called) {
|
|
|
174
180
|
// id, query, filter
|
|
175
181
|
const [orderColumn, orderDir] = (query.order || loadTable?.order || '').split(/[- ]/);
|
|
176
182
|
|
|
177
|
-
const order =
|
|
178
|
-
|
|
183
|
+
const order = query.order && columnList.includes(orderColumn) && orderColumn?.length
|
|
184
|
+
? `order by ${orderColumn} ${query.desc || orderDir === 'desc' ? 'desc' : ''} nulls last`
|
|
185
|
+
: `order by ${(loadTable?.order || 'true::boolean')} nulls last`;
|
|
179
186
|
const search = loadTable?.meta?.search && query.search
|
|
180
187
|
? `(${loadTable?.meta?.search?.split(',')?.map(el => `${el} ilike '%${query.search.replace(/%/g, '\\%').replace(/'/g, "''")}%'`).join(' or ')})`
|
|
181
188
|
: null;
|
|
@@ -269,6 +276,7 @@ export default async function dataAPI(req, reply, called) {
|
|
|
269
276
|
const { panels = [] } = index;
|
|
270
277
|
|
|
271
278
|
const tokens = {};
|
|
279
|
+
|
|
272
280
|
if (template && objectId) {
|
|
273
281
|
// tokens result
|
|
274
282
|
if (!config.security?.disableToken && index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
|
|
@@ -300,19 +308,20 @@ export default async function dataAPI(req, reply, called) {
|
|
|
300
308
|
});
|
|
301
309
|
|
|
302
310
|
// title, count
|
|
303
|
-
panels
|
|
311
|
+
await Promise.all(panels.filter(el => el.items).map(async el => {
|
|
304
312
|
const filtered1 = el.items.filter(item => item.count?.toLowerCase?.().includes('select'));
|
|
305
|
-
const data = await Promise.all(filtered1.map(item => pg.query(item.count.replace(/{{id}}/g, params.id)).then(item1 => item1.rows[0] || {})));
|
|
313
|
+
const data = await Promise.all(filtered1.map(async item => pg.query(item.count.replace(/{{id}}/g, params.id)).then(item1 => item1.rows[0] || {})));
|
|
306
314
|
filtered1.forEach((el1, i) => {
|
|
315
|
+
// el1.title = data[i].title;
|
|
307
316
|
Object.assign(el1, data[i] || {}, data[i].count ? {} : { count: undefined });
|
|
308
317
|
});
|
|
309
318
|
const q1 = el.items.map((item) => (item.component ? components[item.component] : null)).filter(item => item).join(' union all ');
|
|
310
319
|
const counts1 = q1 && id
|
|
311
|
-
? await pg.query(
|
|
320
|
+
? await pg.query(q1, [id])
|
|
312
321
|
.then(e => e.rows.reduce((acc, curr) => Object.assign(acc, { [curr.component]: curr.count }), {}))
|
|
313
322
|
: {};
|
|
314
323
|
el.items?.filter?.(item => item.component)?.forEach(item => Object.assign(item, { count: counts1?.[item.component] }));
|
|
315
|
-
});
|
|
324
|
+
}));
|
|
316
325
|
|
|
317
326
|
// data result
|
|
318
327
|
const data = {};
|
package/utils.js
CHANGED
|
@@ -101,6 +101,8 @@ import grpc from './server/plugins/grpc/grpc.js';
|
|
|
101
101
|
import file2json from './server/plugins/grpc/file2json.js';
|
|
102
102
|
import officeConverter from './server/plugins/grpc/office2pdf.js';
|
|
103
103
|
import getExport from './server/plugins/file/getExport.js';
|
|
104
|
+
import jsonToCsv from './server/routes/file/controllers/utils/jsonToCsv.js';
|
|
105
|
+
import jsonToXls from './server/routes/file/controllers/utils/jsonToXls.js';
|
|
104
106
|
|
|
105
107
|
export default null;
|
|
106
108
|
export {
|
|
@@ -196,4 +198,6 @@ export {
|
|
|
196
198
|
getExport,
|
|
197
199
|
officeConverter,
|
|
198
200
|
allowedExtensions,
|
|
201
|
+
jsonToCsv,
|
|
202
|
+
jsonToXls,
|
|
199
203
|
};
|
|
File without changes
|