@opengis/bi 1.0.44 → 1.0.46

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/bi",
3
- "version": "1.0.44",
3
+ "version": "1.0.46",
4
4
  "description": "BI data visualization module",
5
5
  "main": "dist/bi.js",
6
6
  "browser": "dist/bi.umd.cjs",
@@ -24,14 +24,9 @@
24
24
  "test21": "node --test ./test/plugins/*",
25
25
  "start": "node server.js",
26
26
  "prod": "cross-env NODE_ENV=production npm run start",
27
- "docs:local": "cross-env docs=local vitepress build docs",
28
27
  "docs:dev": "vitepress dev docs",
29
28
  "docs:build": "vitepress build docs",
30
29
  "docs:preview": "vitepress preview docs",
31
- "docs-dev:local": "cross-env docs=local vitepress build docs-dev",
32
- "docs-dev:dev": "vitepress dev docs-dev",
33
- "docs-dev:build": "vitepress build docs-dev",
34
- "docs-dev:preview": "vitepress preview docs-dev",
35
30
  "adduser": "node script/adduser.js"
36
31
  },
37
32
  "keywords": [
@@ -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*', async (req, reply) => {
10
+ if (!fs.existsSync(path.join(root, 'docs/.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/.vitepress/dist/', url)
20
+ : path.join(root, 'docs/.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;
@@ -7,6 +7,7 @@ import {
7
7
  getSelectVal,
8
8
  getFilterSQL,
9
9
  getMeta,
10
+ logger,
10
11
  } from '@opengis/fastify-table/utils.js';
11
12
 
12
13
  import chartSQL from './util/chartSQL.js';
@@ -141,7 +142,10 @@ export default async function dataAPI(req, reply) {
141
142
 
142
143
  if (config.trace) console.log(sql, user?.uid);
143
144
 
144
- const { rows, fields } = await pg.query(sql.replace('{{uid}}', user?.uid)); // test with limit
145
+ const { rows = [], fields = [], errorSql } = await pg.query(sql.replace('{{uid}}', user?.uid)).catch(err => {
146
+ logger.file('bi/data', { error: err.toString(), sql });
147
+ return { errorSql: err.toString() };
148
+ }); // test with limit
145
149
 
146
150
  if (cls) {
147
151
  const values = rows
@@ -167,7 +171,7 @@ export default async function dataAPI(req, reply) {
167
171
 
168
172
  const res = {
169
173
  time: Date.now() - time,
170
- error,
174
+ error: errorSql || (!widgetData.sql ? widgetData.error : undefined),
171
175
  dimensions,
172
176
  filter: xName,
173
177
  dimensionsType: [xType, yType].filter((el) => el)?.length
@@ -113,7 +113,7 @@ export default async function cluster(req, reply) {
113
113
  vals[Math.floor(len * 0.75)],
114
114
  vals[len - 1],
115
115
  ];
116
- return { sizes, style, controls, rows, bounds, extent, count: rows.length, total: rows?.reduce((acc, curr) => (curr.metric || 0) + acc, 0) };
116
+ return { sizes, style, controls, metrics, rows, columns: columns.map(({ name, title, dataTypeID }) => ({ name, title, type: pg.pgType[dataTypeID] })), bounds, extent, count: rows.length, total: rows?.reduce((acc, curr) => (curr.metric || 0) + acc, 0) };
117
117
  } catch (err) {
118
118
  logger.file('bi/cluster/error', { error: err.toString(), query });
119
119
  return { error: err.toString(), status: 500 };