@opengis/bi 1.0.16 → 1.0.17

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 (49) hide show
  1. package/README.md +50 -50
  2. package/config.js +12 -12
  3. package/dist/bi.js +1 -1
  4. package/dist/bi.umd.cjs +63 -63
  5. package/dist/{import-file-BqdbrKVj.js → import-file-CJYiO_4_.js} +7640 -7643
  6. package/dist/{map-component-mixin-BeW3TYyl.js → map-component-mixin-zHwqWXJY.js} +3794 -2115
  7. package/dist/style.css +1 -1
  8. package/dist/{vs-calendar-CnosX1Ss.js → vs-calendar-BAPnMYRd.js} +1 -1
  9. package/dist/{vs-funnel-bar-CcXr5oIQ.js → vs-funnel-bar-DCK7gSj4.js} +1 -1
  10. package/dist/{vs-heatmap-DvOx7wot.js → vs-heatmap-kd6FKOrT.js} +1 -1
  11. package/dist/{vs-map-C2KEv_W6.js → vs-map-BNm381mR.js} +2 -2
  12. package/dist/{vs-map-cluster-DJpEG5n8.js → vs-map-cluster-D3jk7J8D.js} +2 -2
  13. package/dist/{vs-number-C23hqXxA.js → vs-number-DH5bYG7m.js} +1 -1
  14. package/dist/{vs-text-COR-T0yn.js → vs-text-DXkA7s1D.js} +2 -2
  15. package/package.json +88 -107
  16. package/plugin.js +14 -14
  17. package/server/migrations/bi.dataset.sql +26 -26
  18. package/server/migrations/bi.sql +93 -93
  19. package/server/plugins/docs.js +48 -48
  20. package/server/plugins/hook.js +89 -89
  21. package/server/plugins/vite.js +69 -69
  22. package/server/routes/dashboard/controllers/dashboard.delete.js +38 -38
  23. package/server/routes/dashboard/controllers/dashboard.js +118 -118
  24. package/server/routes/dashboard/controllers/dashboard.list.js +30 -30
  25. package/server/routes/dashboard/controllers/utils/yaml.js +11 -11
  26. package/server/routes/dashboard/index.mjs +25 -25
  27. package/server/routes/data/controllers/data.js +167 -167
  28. package/server/routes/data/controllers/util/chartSQL.js +42 -42
  29. package/server/routes/data/controllers/util/normalizeData.js +59 -59
  30. package/server/routes/data/index.mjs +29 -29
  31. package/server/routes/dataset/index.mjs +19 -19
  32. package/server/routes/db/controllers/dbTablePreview.js +63 -63
  33. package/server/routes/db/controllers/dbTables.js +36 -36
  34. package/server/routes/db/index.mjs +17 -17
  35. package/server/routes/edit/controllers/dashboard.add.js +26 -26
  36. package/server/routes/edit/controllers/dashboard.edit.js +46 -46
  37. package/server/routes/edit/controllers/widget.add.js +75 -75
  38. package/server/routes/edit/controllers/widget.del.js +69 -69
  39. package/server/routes/edit/controllers/widget.edit.js +54 -52
  40. package/server/routes/edit/index.mjs +31 -31
  41. package/server/routes/map/controllers/cluster.js +109 -109
  42. package/server/routes/map/controllers/clusterVtile.js +166 -166
  43. package/server/routes/map/controllers/geojson.js +127 -127
  44. package/server/routes/map/controllers/map.js +60 -60
  45. package/server/routes/map/controllers/utils/downloadClusterData.js +42 -42
  46. package/server/routes/map/controllers/vtile.js +183 -183
  47. package/server/routes/map/index.mjs +25 -25
  48. package/server/utils/getWidget.js +85 -85
  49. package/utils.js +12 -12
@@ -1,48 +1,48 @@
1
- import path, { dirname } from 'path';
2
- import { fileURLToPath } from 'url';
3
- import fs from 'fs';
4
-
5
- const dir = dirname(fileURLToPath(import.meta.url));
6
- const root = `${dir}/../../`;
7
-
8
- async function plugin(fastify, opts) {
9
- fastify.get('/docs-dev*', async (req, reply) => {
10
- if (!fs.existsSync(path.join(root, 'docs-dev/.vitepress/dist/'))) {
11
- return reply.status(404).send('docs not exists');
12
- }
13
-
14
- const { params } = req;
15
- const url = params['*'];
16
-
17
- const filePath =
18
- url && url[url.length - 1] !== '/'
19
- ? path.join(root, 'docs-dev/.vitepress/dist/', url)
20
- : path.join(root, 'docs-dev/.vitepress/dist/', url, 'index.html');
21
-
22
- if (!fs.existsSync(filePath)) {
23
- return reply.status(404).send('File not found');
24
- }
25
-
26
- const ext = path.extname(filePath);
27
- const mime = {
28
- '.js': 'text/javascript',
29
- '.css': 'text/css',
30
- '.woff2': 'application/font-woff',
31
- '.png': 'image/png',
32
- '.svg': 'image/svg+xml',
33
- '.jpg': 'image/jpg',
34
- '.html': 'text/html',
35
- '.json': 'application/json',
36
- '.pdf': 'application/pdf',
37
- }[ext];
38
-
39
- const stream = fs.createReadStream(filePath);
40
- stream.on('error', (err) => {
41
- reply.status(500).send('Error reading file');
42
- });
43
-
44
- return mime ? reply.type(mime).send(stream) : reply.send(stream);
45
- });
46
- }
47
-
48
- export default plugin;
1
+ import path, { dirname } from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ import fs from 'fs';
4
+
5
+ const dir = dirname(fileURLToPath(import.meta.url));
6
+ const root = `${dir}/../../`;
7
+
8
+ async function plugin(fastify, opts) {
9
+ fastify.get('/docs-dev*', async (req, reply) => {
10
+ if (!fs.existsSync(path.join(root, 'docs-dev/.vitepress/dist/'))) {
11
+ return reply.status(404).send('docs not exists');
12
+ }
13
+
14
+ const { params } = req;
15
+ const url = params['*'];
16
+
17
+ const filePath =
18
+ url && url[url.length - 1] !== '/'
19
+ ? path.join(root, 'docs-dev/.vitepress/dist/', url)
20
+ : path.join(root, 'docs-dev/.vitepress/dist/', url, 'index.html');
21
+
22
+ if (!fs.existsSync(filePath)) {
23
+ return reply.status(404).send('File not found');
24
+ }
25
+
26
+ const ext = path.extname(filePath);
27
+ const mime = {
28
+ '.js': 'text/javascript',
29
+ '.css': 'text/css',
30
+ '.woff2': 'application/font-woff',
31
+ '.png': 'image/png',
32
+ '.svg': 'image/svg+xml',
33
+ '.jpg': 'image/jpg',
34
+ '.html': 'text/html',
35
+ '.json': 'application/json',
36
+ '.pdf': 'application/pdf',
37
+ }[ext];
38
+
39
+ const stream = fs.createReadStream(filePath);
40
+ stream.on('error', (err) => {
41
+ reply.status(500).send('Error reading file');
42
+ });
43
+
44
+ return mime ? reply.type(mime).send(stream) : reply.send(stream);
45
+ });
46
+ }
47
+
48
+ export default plugin;
@@ -1,89 +1,89 @@
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
+ 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,69 +1,69 @@
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
+ 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,38 +1,38 @@
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
+ 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
+ }