@opengis/bi 1.0.13 → 1.0.15

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.
Files changed (58) hide show
  1. package/README.md +50 -52
  2. package/config.js +12 -12
  3. package/dist/bi.js +1 -1
  4. package/dist/bi.umd.cjs +120 -134
  5. package/dist/{import-file-1T7kpSzt.js → import-file-CRC0sYYT.js} +11974 -11522
  6. package/dist/{map-component-mixin-BLM9iEWA.js → map-component-mixin-BCtWEvzv.js} +4830 -3150
  7. package/dist/style.css +1 -1
  8. package/dist/vs-calendar-5ot79n0N.js +110 -0
  9. package/dist/vs-funnel-bar-CLo6gXI_.js +105 -0
  10. package/dist/vs-heatmap-DHGA8dRk.js +97 -0
  11. package/dist/{vs-map-cluster-Dfe9INqE.js → vs-map-cluster-CNgX6JVF.js} +28 -25
  12. package/dist/vs-map-pIn5wS4G.js +74 -0
  13. package/dist/vs-number-DYfok8VU.js +55 -0
  14. package/dist/{vs-text-DcrAdQ40.js → vs-text-Dckykz09.js} +19 -13
  15. package/package.json +107 -72
  16. package/plugin.js +14 -13
  17. package/server/migrations/bi.dataset.sql +26 -0
  18. package/server/migrations/bi.sql +93 -27
  19. package/server/plugins/docs.js +48 -47
  20. package/server/plugins/hook.js +89 -86
  21. package/server/plugins/vite.js +69 -55
  22. package/server/routes/dashboard/controllers/dashboard.delete.js +38 -35
  23. package/server/routes/dashboard/controllers/dashboard.js +118 -80
  24. package/server/routes/dashboard/controllers/dashboard.list.js +30 -39
  25. package/server/routes/dashboard/controllers/utils/yaml.js +11 -12
  26. package/server/routes/dashboard/index.mjs +25 -24
  27. package/server/routes/data/controllers/data.js +168 -97
  28. package/server/routes/data/controllers/util/chartSQL.js +42 -25
  29. package/server/routes/data/controllers/util/normalizeData.js +59 -34
  30. package/server/routes/data/index.mjs +29 -26
  31. package/server/routes/dataset/controllers/bi.dataset.demo.add.js +97 -0
  32. package/server/routes/dataset/controllers/bi.dataset.import.js +67 -0
  33. package/server/routes/dataset/controllers/util/create.table.js +22 -0
  34. package/server/routes/dataset/controllers/util/prepare.data.js +49 -0
  35. package/server/routes/dataset/index.mjs +19 -0
  36. package/server/routes/db/controllers/dbTablePreview.js +63 -0
  37. package/server/routes/db/controllers/dbTables.js +36 -0
  38. package/server/routes/db/index.mjs +17 -0
  39. package/server/routes/edit/controllers/dashboard.add.js +26 -23
  40. package/server/routes/edit/controllers/dashboard.edit.js +46 -37
  41. package/server/routes/edit/controllers/widget.add.js +75 -49
  42. package/server/routes/edit/controllers/widget.del.js +69 -63
  43. package/server/routes/edit/controllers/widget.edit.js +52 -82
  44. package/server/routes/edit/index.mjs +31 -27
  45. package/server/routes/map/controllers/cluster.js +109 -75
  46. package/server/routes/map/controllers/clusterVtile.js +166 -143
  47. package/server/routes/map/controllers/geojson.js +127 -101
  48. package/server/routes/map/controllers/map.js +60 -57
  49. package/server/routes/map/controllers/utils/downloadClusterData.js +43 -0
  50. package/server/routes/map/controllers/vtile.js +183 -161
  51. package/server/routes/map/index.mjs +25 -25
  52. package/server/utils/getWidget.js +85 -56
  53. package/utils.js +12 -11
  54. package/dist/vs-calendar-WiK1hcHS.js +0 -96
  55. package/dist/vs-funnel-bar-CpPbYZ0_.js +0 -92
  56. package/dist/vs-heatmap-BG4eIROH.js +0 -83
  57. package/dist/vs-map-BRk6Fmks.js +0 -66
  58. package/dist/vs-number-CJq-vi95.js +0 -39
@@ -1,86 +1,89 @@
1
- import fp from 'fastify-plugin';
2
- import fs from 'fs';
3
-
4
-
5
- // the use of fastify-plugin is required to be able
6
- // to export the decorators to the outer scope
7
-
8
- async function plugin(fastify) {
9
-
10
-
11
-
12
-
13
- // preSerialization
14
- fastify.addHook('preSerialization', async (req, reply, payload) => {
15
- if (!req.session?.passport?.user?.uid) {
16
- // return reply.redirect('/login');
17
- }
18
- if (req.url.includes('/suggest/') && !req.query.json) {
19
- return payload?.data;
20
- }
21
- if (payload.redirect) {
22
- return reply.redirect(payload.redirect);
23
- }
24
- if (reply.sent) {
25
- return null;
26
- }
27
-
28
- if (payload.status) {
29
- reply.status(payload.status);
30
- }
31
- /*if (payload.headers) {
32
- reply.headers(payload.headers);
33
- }*/
34
- if (payload.buffer) {
35
- return payload.buffer;
36
- }
37
- if (payload.file) {
38
- // const buffer = await readFile(payload.file);
39
- // return reply.send(buffer);
40
- const stream = fs.createReadStream(payload.file);
41
- return stream;
42
- // return reply.send(stream);
43
- }
44
-
45
- if (payload.message) {
46
- return payload.message;
47
- }
48
- return payload;
49
- });
50
-
51
- // preValidation
52
- fastify.addHook('preValidation', async (req) => {
53
- const parseRawBody = ['POST', 'PUT'].includes(req.method) && req.body && typeof req.body === 'string'
54
- && req.body.trim(/\r\n/g).startsWith('{')
55
- && req.body.trim(/\r\n/g).endsWith('}');
56
- if (parseRawBody) {
57
- try {
58
- req.body = JSON.parse(req.body || '{}');
59
- }
60
- catch (err) {
61
- // throw new Error('invalid body');
62
- // return { error: 'invalid body', status: 400 };
63
- }
64
- }
65
- });
66
-
67
- // allow upload file
68
- const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
69
- fastify.addContentTypeParser('multipart', (request, _, done) => {
70
- request[kIsMultipart] = true;
71
- done(null);
72
- });
73
-
74
- // parse Body
75
- function contentParser(req, body, done) {
76
- const parseBody = decodeURIComponent(body.toString()).split('&').reduce((acc, el) => {
77
- const [key, val] = el.split('=');
78
- return { ...acc, [key]: val };
79
- }, {});
80
- done(null, parseBody);
81
- }
82
-
83
- fastify.addContentTypeParser('application/x-www-form-urlencoded', { parseAs: 'buffer' }, contentParser);
84
- }
85
-
86
- export default fp(plugin);
1
+ import fp from 'fastify-plugin';
2
+ import fs from 'fs';
3
+
4
+ // the use of fastify-plugin is required to be able
5
+ // to export the decorators to the outer scope
6
+
7
+ async function plugin(fastify) {
8
+ // preSerialization
9
+ fastify.addHook('preSerialization', async (req, reply, payload) => {
10
+ if (!req.session?.passport?.user?.uid) {
11
+ // return reply.redirect('/login');
12
+ }
13
+ if (req.url.includes('/suggest/') && !req.query.json) {
14
+ return payload?.data;
15
+ }
16
+ if (payload.redirect) {
17
+ return reply.redirect(payload.redirect);
18
+ }
19
+ if (reply.sent) {
20
+ return null;
21
+ }
22
+
23
+ if (payload.status) {
24
+ reply.status(payload.status);
25
+ }
26
+ /* if (payload.headers) {
27
+ reply.headers(payload.headers);
28
+ } */
29
+ if (payload.buffer) {
30
+ return payload.buffer;
31
+ }
32
+ if (payload.file) {
33
+ // const buffer = await readFile(payload.file);
34
+ // return reply.send(buffer);
35
+ const stream = fs.createReadStream(payload.file);
36
+ return stream;
37
+ // return reply.send(stream);
38
+ }
39
+
40
+ if (payload.message) {
41
+ return payload.message;
42
+ }
43
+ return payload;
44
+ });
45
+
46
+ // preValidation
47
+ fastify.addHook('preValidation', async (req) => {
48
+ const parseRawBody =
49
+ ['POST', 'PUT'].includes(req.method) &&
50
+ req.body &&
51
+ typeof req.body === 'string' &&
52
+ req.body.trim(/\r\n/g).startsWith('{') &&
53
+ req.body.trim(/\r\n/g).endsWith('}');
54
+ if (parseRawBody) {
55
+ try {
56
+ req.body = JSON.parse(req.body || '{}');
57
+ } catch (err) {
58
+ // throw new Error('invalid body');
59
+ // return { error: 'invalid body', status: 400 };
60
+ }
61
+ }
62
+ });
63
+
64
+ // allow upload file
65
+ const kIsMultipart = Symbol.for('[FastifyMultipart.isMultipart]');
66
+ fastify.addContentTypeParser('multipart', (request, _, done) => {
67
+ request[kIsMultipart] = true;
68
+ done(null);
69
+ });
70
+
71
+ // parse Body
72
+ function contentParser(req, body, done) {
73
+ const parseBody = decodeURIComponent(body.toString())
74
+ .split('&')
75
+ .reduce((acc, el) => {
76
+ const [key, val] = el.split('=');
77
+ return { ...acc, [key]: val };
78
+ }, {});
79
+ done(null, parseBody);
80
+ }
81
+
82
+ fastify.addContentTypeParser(
83
+ 'application/x-www-form-urlencoded',
84
+ { parseAs: 'buffer' },
85
+ contentParser
86
+ );
87
+ }
88
+
89
+ export default fp(plugin);
@@ -1,55 +1,69 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- import config from '../../config.js';
4
- const { disableAuth } = config;
5
- const isProduction = process.env.NODE_ENV === 'production';
6
-
7
- async function plugin(fastify) {
8
- // vite server
9
- if (!isProduction) {
10
- const vite = await import('vite');
11
-
12
- const viteServer = await vite.createServer({
13
- server: {
14
- middlewareMode: true,
15
- },
16
- });
17
- // hot reload
18
- viteServer.watcher.on('all', function (d, t) {
19
- if (!t.includes('module') && !t.includes('templates')) return;
20
- console.log(d, t);
21
- viteServer.ws.send({ type: 'full-reload' });
22
- });
23
-
24
- // this is middleware for vite's dev servert
25
- fastify.addHook('onRequest', async (req, reply) => {
26
- // const { user } = req.session?.passport || {};
27
- const next = () => new Promise((resolve) => {
28
- viteServer.middlewares(req.raw, reply.raw, () => resolve());
29
- });
30
- await next();
31
- });
32
- fastify.get('*', async () => { });
33
- return;
34
- }
35
-
36
- // From Build
37
- fastify.get('*', async (req, reply) => {
38
- // console.log(disableAuth)
39
- if (!req.user && !disableAuth) return reply.redirect('/login');
40
- const stream = fs.createReadStream('dist/index.html');
41
- return reply.headers({ 'Cache-Control': 'public, no-cache' }).type('text/html').send(stream);
42
- });
43
- fastify.get('/assets/:file', async (req, reply) => {
44
- const stream = fs.createReadStream(`dist/assets/${req.params.file}`);
45
- const ext = path.extname(req.params.file);
46
- const mime = {
47
- '.js': 'text/javascript', '.css': 'text/css', '.woff2': 'application/font-woff', '.png': 'image/png',
48
- }[ext];
49
- //reply.cacheControl('max-age', '1d');
50
- return mime ? reply.headers({ 'Cache-Control': 'public, max-age=3600' }).type(mime).send(stream) : stream;
51
-
52
- });
53
- }
54
-
55
- export default plugin;
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import config from '../../config.js';
4
+
5
+ const { disableAuth } = config;
6
+ const isProduction = process.env.NODE_ENV === 'production';
7
+
8
+ async function plugin(fastify) {
9
+ // vite server
10
+ if (!isProduction) {
11
+ const vite = await import('vite');
12
+
13
+ const viteServer = await vite.createServer({
14
+ server: {
15
+ middlewareMode: true,
16
+ },
17
+ });
18
+ // hot reload
19
+ viteServer.watcher.on('all', (d, t) => {
20
+ if (!t.includes('module') && !t.includes('templates')) return;
21
+ // console.log(d, t);
22
+ viteServer.ws.send({ type: 'full-reload' });
23
+ });
24
+
25
+ // this is middleware for vite's dev servert
26
+ fastify.addHook('onRequest', async (req, reply) => {
27
+ // const { user } = req.session?.passport || {};
28
+ const next = () => new Promise((resolve) => {
29
+ viteServer.middlewares(req.raw, reply.raw, () => resolve());
30
+ });
31
+ await next();
32
+ });
33
+ fastify.get('*', async () => {});
34
+ return;
35
+ }
36
+
37
+ // From Build
38
+ fastify.get('*', async (req, reply) => {
39
+ // console.log(disableAuth)
40
+ if (!req.user && !disableAuth) return reply.redirect('/login');
41
+ const stream = fs.createReadStream('dist/index.html');
42
+ return reply
43
+ .headers({ 'Cache-Control': 'public, no-cache' })
44
+ .type('text/html')
45
+ .send(stream);
46
+ });
47
+ fastify.get('/assets/:file', async (req, reply) => {
48
+ const stream = fs.createReadStream(`dist/assets/${req.params.file}`);
49
+ const ext = path.extname(req.params.file);
50
+ const mime = {
51
+ '.js': 'text/javascript',
52
+ '.css': 'text/css',
53
+ '.woff2': 'application/font-woff',
54
+ '.png': 'image/png',
55
+ }[ext];
56
+ // reply.cacheControl('max-age', '1d');
57
+ return mime
58
+ ? reply
59
+ .headers({
60
+ 'Cache-Control': 'public, max-age=3600',
61
+ 'Content-Encoding': 'identity',
62
+ })
63
+ .type(mime)
64
+ .send(stream)
65
+ : stream;
66
+ });
67
+ }
68
+
69
+ export default plugin;
@@ -1,35 +1,38 @@
1
- import { existsSync, readdirSync } from 'fs';
2
- import path from 'path';
3
- import pgClients from '@opengis/fastify-table/pg/pgClients.js';
4
-
5
- const cwd = process.cwd();
6
- const dashboardDir = path.join(cwd, 'server/templates/dashboard');
7
-
8
- export default async function data({ pg = pgClients.client, params = {} }) {
9
- const { id } = params;
10
-
11
- if (!id) {
12
- return { message: 'not enough params: id', status: 400 };
13
- }
14
-
15
- const dirContent = existsSync(dashboardDir) ? readdirSync(dashboardDir) : [];
16
-
17
- if (dirContent.includes(id)) {
18
- return { message: 'access restricted: ' + id, status: 403 };
19
- }
20
- try {
21
- const { rowCount } = await pg.query(
22
- `select * from bi.dashboard where $1 in (dashboard_id,name)`,
23
- [id]
24
- );
25
-
26
- if (rowCount === 0) {
27
- return { message: 'not found ' + id, status: 404 };
28
- }
29
- await pg.query(`delete from bi.widget where $1 in (dashboard_id)`, [id]);
30
- await pg.query(`delete from bi.dashboard where $1 in (dashboard_id,name)`, [id]);
31
- return { message: 'successfully deleted', status: 200 };
32
- } catch (err) {
33
- return { error: err.toString(), status: 500 };
34
- }
35
- }
1
+ import { existsSync, readdirSync } from 'fs';
2
+ import path from 'path';
3
+
4
+ import { pgClients } from '@opengis/fastify-table/utils.js';
5
+
6
+ const cwd = process.cwd();
7
+ const dashboardDir = path.join(cwd, 'server/templates/dashboard');
8
+
9
+ export default async function data({ pg = pgClients.client, params = {} }) {
10
+ const { id } = params;
11
+
12
+ if (!id) {
13
+ return { message: 'not enough params: id', status: 400 };
14
+ }
15
+
16
+ const dirContent = existsSync(dashboardDir) ? readdirSync(dashboardDir) : [];
17
+
18
+ if (dirContent.includes(id)) {
19
+ return { message: `access restricted: ${id}`, status: 403 };
20
+ }
21
+ try {
22
+ const { rowCount } = await pg.query(
23
+ `select * from bi.dashboard where $1 in (dashboard_id,name)`,
24
+ [id]
25
+ );
26
+
27
+ if (rowCount === 0) {
28
+ return { message: `not found ${id}`, status: 404 };
29
+ }
30
+ await pg.query(`delete from bi.widget where $1 in (dashboard_id)`, [id]);
31
+ await pg.query(`delete from bi.dashboard where $1 in (dashboard_id,name)`, [
32
+ id,
33
+ ]);
34
+ return { message: 'successfully deleted', status: 200 };
35
+ } catch (err) {
36
+ return { error: err.toString(), status: 500 };
37
+ }
38
+ }
@@ -1,80 +1,118 @@
1
- import path from 'path';
2
- import { existsSync, readFileSync, readdirSync } from 'fs';
3
-
4
- import pgClients from '@opengis/fastify-table/pg/pgClients.js';
5
- import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
6
- import { getTemplate } from '@opengis/fastify-table/utils.js';
7
- import { getPGAsync } from '@opengis/fastify-table/utils.js';
8
-
9
- export default async function data({
10
- pg = pgClients.client, params = {},
11
- }) {
12
- const time = Date.now();
13
- const { id } = params;
14
-
15
- if (!id) {
16
- return { message: 'not enough params: dashboard required', status: 400 };
17
- }
18
- const dashboards = await getTemplatePath('dashboard');
19
-
20
- const fileDashboard = dashboards.find(el => el[0] === id)
21
- if (!fileDashboard) {
22
- const sql = `select title, description, table_name, panels, grid, widgets, filters, style
23
- from bi.dashboard where $1 in (dashboard_id, name)`;
24
-
25
- const data = await pg.query(sql, [id]).then((res) => res.rows?.[0] || {});
26
- data.type = 'bd';
27
- const { table_name: table } = data;
28
-
29
- if (!table) {
30
- return { message: 'not enough params: table required', status: 400 };
31
- }
32
-
33
- const { fields = [] } = table && pg.pk?.[table] ? await pg.query(`select * from ${table} limit 1`) : {};
34
-
35
- const columns = table ? fields.map(({ name, dataTypeID }) => ({ name, type: pg.pgType?.[dataTypeID] })) : [];
36
- return { ...data, error: table && !pg.pk?.[table] ? `table pkey not found: ${table}` : undefined, table_name: table, time: Date.now() - time, columns };
37
- }
38
-
39
-
40
-
41
- const fileData = await getTemplate('dashboard', id);
42
- const index = fileData.find(el => el[0] === 'index.yml')[1]
43
-
44
- if (!index) {
45
- return { message: 'not found ' + id, status: 404 };
46
- }
47
-
48
- if (index?.filters?.filter((el) => el?.type === 'Check')?.length) {
49
- await Promise.all(index.filters.filter((el) => el?.type === 'Check' && el?.data).map(async (el) => {
50
- const options = await getTemplate('cls', el.data);
51
- Object.assign(el, { options });
52
- }));
53
- }
54
-
55
-
56
- const data = index;
57
- data.type = 'file';
58
- const { table } = data?.data || { table: data?.table_name };
59
- // console.log(fileData)
60
- const widgets = fileData
61
- .filter((el) => el[0] !== 'index.yml')
62
- .map((el) =>
63
- el[1].data
64
- ? {
65
- name: el[0].split('.')[0],
66
- type: el[1].type,
67
- title: el[1].title,
68
- style: el[1].style,
69
- data: el[1].data
70
- }
71
- : { name: el[0].split('.')[0], title: el[1] }
72
- );
73
- const pg1 = data.db ? await getPGAsync(data.db) : pg
74
-
75
- const { fields = [] } = table ? await pg1.query(`select * from ${table} limit 1`) : {};
76
-
77
- const columns = fields.map(({ name, dataTypeID }) => ({ name, type: pg.pgType?.[dataTypeID] }));
78
-
79
- return { ...data, table_name: table, time: Date.now() - time, columns, widgets };
80
- }
1
+ import yaml from 'js-yaml';
2
+ import {
3
+ pgClients,
4
+ getTemplatePath,
5
+ getTemplate,
6
+ getPGAsync,
7
+ } from '@opengis/fastify-table/utils.js';
8
+
9
+ export default async function dashboard({
10
+ pg = pgClients.client,
11
+ params = {},
12
+ }) {
13
+ const time = Date.now();
14
+ const { id } = params;
15
+
16
+ if (!id) {
17
+ return { message: 'not enough params: dashboard required', status: 400 };
18
+ }
19
+ const dashboards = await getTemplatePath('dashboard');
20
+
21
+ const fileDashboard = dashboards.find((el) => el[0] === id);
22
+ if (!fileDashboard) {
23
+ const sql = `select title, description, table_name, panels, grid, widgets, filters, style
24
+ from bi.dashboard where $1 in (dashboard_id, name)`;
25
+
26
+ const data = await pg.query(sql, [id]).then((res) => res.rows?.[0] || {});
27
+ data.type = 'bd';
28
+ const { table_name: table } = data;
29
+
30
+ if (!table) {
31
+ return { message: 'not enough params: table required', status: 400 };
32
+ }
33
+
34
+ const { fields = [] } =
35
+ table && pg.pk?.[table]
36
+ ? await pg.query(`select * from ${table} limit 0`)
37
+ : {};
38
+
39
+ const columns = table
40
+ ? fields.map(({ name, dataTypeID }) => ({
41
+ name,
42
+ type: pg.pgType?.[dataTypeID],
43
+ }))
44
+ : [];
45
+ data?.widgets?.forEach?.(el => {
46
+ const { style, data = {}, type, title, x, metrics } = el;
47
+ el.yml = yaml.dump({ title, type, data: { x, metrics, ...data }, style, })
48
+ // el.yml = yaml.dump({ style, data, type, title });
49
+ })
50
+ return {
51
+ ...data || {},
52
+ error:
53
+ table && !pg.pk?.[table] ? `table pkey not found: ${table}` : undefined,
54
+ table_name: table,
55
+ time: Date.now() - time,
56
+ columns,
57
+ };
58
+ }
59
+
60
+ const fileData = await getTemplate('dashboard', id);
61
+ const index = fileData.find((el) => el[0] === 'index.yml')[1];
62
+
63
+ if (!index) {
64
+ return { message: `not found ${id}`, status: 404 };
65
+ }
66
+
67
+ const data = index;
68
+ data.type = 'file';
69
+ const { table } = data?.data || { table: data?.table_name };
70
+
71
+ const pg1 = data.db ? await getPGAsync(data.db) : pg;
72
+
73
+ const { fields = [] } = table
74
+ ? await pg1.query(`select * from ${table} limit 0`)
75
+ : {};
76
+
77
+ const columns = fields.map(({ name, dataTypeID }) => ({
78
+ name,
79
+ type: pg.pgType?.[dataTypeID],
80
+ }));
81
+
82
+ const checks = index?.filters?.filter((el) => el?.id && columns.map((el) => el?.name).includes(el?.id) && el?.type === 'Check');
83
+ if (checks?.length) {
84
+ await Promise.all(checks.map(async (el) => {
85
+ if (el?.data) {
86
+ const options = await getTemplate('cls', el.data);
87
+ Object.assign(el, { options });
88
+ } else if (index?.table_name || index?.table) {
89
+ const { rows = [] } = await pg.query(`select "${el.id}" as id, count(*) from ${index?.table_name || index?.table} group by "${el.id}"`);
90
+ Object.assign(el, { options: rows });
91
+ }
92
+ }));
93
+ }
94
+
95
+ // console.log(fileData)
96
+ const widgets = fileData
97
+ .filter((el) => el[0] !== 'index.yml')
98
+ .map((el) =>
99
+ el[1].data
100
+ ? {
101
+ name: el[0].split('.')[0],
102
+ type: el[1].type,
103
+ title: el[1].title,
104
+ style: el[1].style,
105
+ data: el[1].data,
106
+
107
+ }
108
+ : { name: el[0].split('.')[0], title: el[1] }
109
+ );
110
+
111
+ return {
112
+ ...data,
113
+ table_name: table,
114
+ time: Date.now() - time,
115
+ columns,
116
+ widgets,
117
+ };
118
+ }
@@ -1,39 +1,30 @@
1
- import { readFileSync, readdirSync } from 'fs';
2
- import path from 'path';
3
- import pgClients from '@opengis/fastify-table/pg/pgClients.js';
4
- import { getTemplate } from '@opengis/fastify-table/utils.js';
5
- import getTemplatePath from '@opengis/fastify-table/table/controllers/utils/getTemplatePath.js';
6
-
7
- import yaml from './utils/yaml.js';
8
- //import getTemplate from '@opengis/fastify-table/table/controllers/utils/getTemplate.js';
9
-
10
-
11
- const cwd = process.cwd();
12
-
13
-
14
- const q = `select dashboard_id as name, 'db' as type, title, description, table_name from bi.dashboard`;
15
-
16
- export default async function data({ pg = pgClients.client }) {
17
- const time = Date.now();
18
- const data = await getTemplatePath('dashboard');
19
- const dir = await Promise.all(
20
- data.map(async ([filename]) => {
21
-
22
- const data = await getTemplate('dashboard', filename);
23
- const index = data.find(el => el[0] === 'index.yml')[1]
24
- const { table_name, description, title } = index || {};
25
-
26
- return { name: filename, type: 'file', title, description, table_name };
27
- })
28
- );
29
-
30
- const { rows = [] } = await pg.query(q);
31
-
32
- const list = dir.concat(rows);
33
-
34
- const res = {
35
- time: Date.now() - time,
36
- rows: list,
37
- };
38
- return res;
39
- }
1
+ import { pgClients, getTemplate, getTemplatePath } from '@opengis/fastify-table/utils.js';
2
+
3
+ // import yaml from './utils/yaml.js';
4
+ // const cwd = process.cwd();
5
+
6
+ const q = `select dashboard_id as name, 'db' as type, title, description, table_name from bi.dashboard`;
7
+
8
+ export default async function data({ pg = pgClients.client }) {
9
+ const time = Date.now();
10
+ const data = await getTemplatePath('dashboard');
11
+ const dir = await Promise.all(
12
+ data.map(async ([filename]) => {
13
+ const data = await getTemplate('dashboard', filename);
14
+ const index = data.find((el) => el[0] === 'index.yml')[1];
15
+ const { table_name, description, title } = index || {};
16
+
17
+ return { name: filename, type: 'file', title, description, table_name };
18
+ })
19
+ );
20
+
21
+ const { rows = [] } = await pg.query(q);
22
+
23
+ const list = dir.concat(rows);
24
+
25
+ const res = {
26
+ time: Date.now() - time,
27
+ rows: list,
28
+ };
29
+ return res;
30
+ }