@opengis/bi 1.0.32 → 1.0.34

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 (28) hide show
  1. package/config.js +12 -12
  2. package/dist/bi.js +1 -1
  3. package/dist/bi.umd.cjs +97 -81
  4. package/dist/{import-file-CGUzCAix.js → import-file-CdxxTyee.js} +9993 -9941
  5. package/dist/{map-component-mixin-BkEQzSdJ.js → map-component-mixin-_65X587R.js} +3573 -3568
  6. package/dist/style.css +1 -1
  7. package/dist/{vs-donut-DiNanKYo.js → vs-donut-ByLcnGfq.js} +7 -7
  8. package/dist/{vs-funnel-bar-BM7WMuDM.js → vs-funnel-bar-B1MOYsMV.js} +5 -5
  9. package/dist/vs-map-Cx1mU3Y2.js +79 -0
  10. package/dist/vs-map-cluster-BgY06S_H.js +104 -0
  11. package/dist/{vs-number-EfOaU6-B.js → vs-number-ClRapRct.js} +3 -3
  12. package/dist/{vs-table-BdxjaLf1.js → vs-table-CfNU4mMc.js} +6 -6
  13. package/dist/{vs-text-DhA-8Fxf.js → vs-text-B3QTQjzZ.js} +39 -32
  14. package/package.json +1 -1
  15. package/server/plugins/docs.js +48 -48
  16. package/server/plugins/hook.js +89 -89
  17. package/server/plugins/vite.js +69 -69
  18. package/server/routes/dashboard/controllers/utils/yaml.js +11 -11
  19. package/server/routes/data/controllers/util/normalizeData.js +61 -61
  20. package/server/routes/map/controllers/cluster.js +110 -110
  21. package/server/routes/map/controllers/clusterVtile.js +166 -166
  22. package/server/routes/map/controllers/geojson.js +127 -127
  23. package/server/routes/map/controllers/map.js +61 -61
  24. package/server/routes/map/controllers/utils/downloadClusterData.js +44 -44
  25. package/server/routes/map/controllers/vtile.js +183 -183
  26. package/utils.js +12 -12
  27. package/dist/vs-map-DLALMtkA.js +0 -75
  28. package/dist/vs-map-cluster-DLJPVkGz.js +0 -76
@@ -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 ([200, 400, 403, 409, 404, 500].includes(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 ([200, 400, 403, 409, 404, 500].includes(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,11 +1,11 @@
1
- import yaml from 'js-yaml';
2
-
3
- yaml.loadSafe = (yml) => {
4
- try {
5
- return yaml.load(yml);
6
- } catch (err) {
7
- return { error: err.toString() };
8
- }
9
- };
10
-
11
- export default yaml;
1
+ import yaml from 'js-yaml';
2
+
3
+ yaml.loadSafe = (yml) => {
4
+ try {
5
+ return yaml.load(yml);
6
+ } catch (err) {
7
+ return { error: err.toString() };
8
+ }
9
+ };
10
+
11
+ export default yaml;
@@ -1,61 +1,61 @@
1
- function normalizeData(data, query = {}, columnTypes = []) {
2
- const skip = [];
3
- ['x', 'groupby', 'granularity'].forEach((el) => {
4
- // console.log(el, query[el], columnTypes.find(col => col.name == query[el]))
5
- if (!columnTypes.find((col) => col.name == query[el])) {
6
- if (query[el] && query[el] !== 'null') skip.push(`column not found: ${query[el]}`);
7
- if (!(el === 'groupby' && query[el] === 'null')) delete query[el];
8
- }
9
- });
10
-
11
- if (
12
- !columnTypes.find(
13
- (col) => col.type === 'numeric' && col.name == query.metric
14
- )
15
- ) {
16
- delete query.metric;
17
- }
18
-
19
- const xName = query.x || (Array.isArray(data.x) ? data.x[0] : data.x);
20
- const xType = columnTypes.find((el) => el.name == xName)?.type;
21
-
22
- const granularity =
23
- xType === 'date' || xType?.includes('timestamp')
24
- ? query.granularity || data.granularity || 'year'
25
- : null;
26
-
27
- const x =
28
- (granularity
29
- ? `date_trunc('${granularity}',${xName})::date::text`
30
- : null) || xName;
31
-
32
- const metrics = Array.isArray(data.metrics || data.metric) ? (data.metrics || data.metric) : [data.metrics || data.metric];
33
- const metric =
34
- (query.metric ? `sum(${query.metric})` : null) ||
35
- (metrics.length
36
- ? (metrics
37
- ?.filter((el) => el && columnTypes.find((col) => col.name == (el?.name || el)))
38
- ?.map((el) => el.fx || `${el.operator || 'sum'}(${el.name || el})`)?.join(',') || 'count(*)')
39
- : 'count(*)');
40
-
41
- const yName = metrics?.[0]?.name || metrics?.[0];
42
- const yType = columnTypes.find((el) => el.name == yName)?.type;
43
-
44
- const { cls, table, filterCustom } = data;
45
- const groupby = (query.groupby || data.groupby) === 'null' ? null : (query.groupby || data.groupby);
46
- // const orderby = query.orderby || data.orderby || 'count(*)';
47
-
48
- const custom = query?.filterCustom
49
- ?.split(',')
50
- ?.map((el) => filterCustom?.find((item) => item?.name === el)?.sql)
51
- ?.filter((el) => el)
52
- ?.join(' and ');
53
- const where = `${data.query || '1=1'} and ${custom || 'true'}`;
54
-
55
- const tableSQL = data.tableSQL?.length
56
- ? `(select * from ${data?.table} t ${data.tableSQL.join(' \n ')} where ${where})q`
57
- : undefined;
58
-
59
- return { x, cls, metric, table, where, tableSQL, groupby, xName, xType, yName, yType, error: skip.length ? skip.join(',') : undefined };
60
- }
61
- export default normalizeData;
1
+ function normalizeData(data, query = {}, columnTypes = []) {
2
+ const skip = [];
3
+ ['x', 'groupby', 'granularity'].forEach((el) => {
4
+ // console.log(el, query[el], columnTypes.find(col => col.name == query[el]))
5
+ if (!columnTypes.find((col) => col.name == query[el])) {
6
+ if (query[el] && query[el] !== 'null') skip.push(`column not found: ${query[el]}`);
7
+ if (!(el === 'groupby' && query[el] === 'null')) delete query[el];
8
+ }
9
+ });
10
+
11
+ if (
12
+ !columnTypes.find(
13
+ (col) => col.type === 'numeric' && col.name == query.metric
14
+ )
15
+ ) {
16
+ delete query.metric;
17
+ }
18
+
19
+ const xName = query.x || (Array.isArray(data.x) ? data.x[0] : data.x);
20
+ const xType = columnTypes.find((el) => el.name == xName)?.type;
21
+
22
+ const granularity =
23
+ xType === 'date' || xType?.includes('timestamp')
24
+ ? query.granularity || data.granularity || 'year'
25
+ : null;
26
+
27
+ const x =
28
+ (granularity
29
+ ? `date_trunc('${granularity}',${xName})::date::text`
30
+ : null) || xName;
31
+
32
+ const metrics = Array.isArray(data.metrics || data.metric) ? (data.metrics || data.metric) : [data.metrics || data.metric];
33
+ const metric =
34
+ (query.metric ? `sum(${query.metric})` : null) ||
35
+ (metrics.length
36
+ ? (metrics
37
+ ?.filter((el) => el && columnTypes.find((col) => col.name == (el?.name || el)))
38
+ ?.map((el) => el.fx || `${el.operator || 'sum'}(${el.name || el})`)?.join(',') || 'count(*)')
39
+ : 'count(*)');
40
+
41
+ const yName = metrics?.[0]?.name || metrics?.[0];
42
+ const yType = columnTypes.find((el) => el.name == yName)?.type;
43
+
44
+ const { cls, table, filterCustom } = data;
45
+ const groupby = (query.groupby || data.groupby) === 'null' ? null : (query.groupby || data.groupby);
46
+ // const orderby = query.orderby || data.orderby || 'count(*)';
47
+
48
+ const custom = query?.filterCustom
49
+ ?.split(',')
50
+ ?.map((el) => filterCustom?.find((item) => item?.name === el)?.sql)
51
+ ?.filter((el) => el)
52
+ ?.join(' and ');
53
+ const where = `${data.query || '1=1'} and ${custom || 'true'}`;
54
+
55
+ const tableSQL = data.tableSQL?.length
56
+ ? `(select * from ${data?.table} t ${data.tableSQL.join(' \n ')} where ${where})q`
57
+ : undefined;
58
+
59
+ return { x, cls, metric, table, where, tableSQL, groupby, xName, xType, yName, yType, error: skip.length ? skip.join(',') : undefined };
60
+ }
61
+ export default normalizeData;