@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,52 +1,54 @@
1
- import { dataUpdate } from '@opengis/fastify-table/utils.js';
2
-
3
- import { yamlSafe } from '../../../../utils.js';
4
-
5
- export default async function widgetEdit({ pg, body, params, }) {
6
- const { widget: widgetName, name: dashboardName } = params;
7
- const data = body.yml && !body.style ? yamlSafe.load(body.yml) : body;
8
-
9
- const tableName =
10
- data.data?.table || data?.table || data.table_name || body.table_name;
11
-
12
- if (!widgetName || !dashboardName) {
13
- return {
14
- message: 'not enough params: dashboard and widget name',
15
- status: 400,
16
- };
17
- }
18
-
19
-
20
- const { widget_id: widgetId } = await pg.query(
21
- `select a.widget_id , b.dashboard_id from bi.widget a, bi.dashboard b
22
- where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
23
- [dashboardName, widgetName]
24
- ).then((res1) => res1.rows?.[0] || {});
25
-
26
- if (!widgetId) {
27
- return { message: `widget not found ${widgetName}`, status: 404 };
28
- }
29
-
30
- if (!tableName || !pg.pk?.[tableName]) {
31
- return { message: 'bad params: table', status: 400 };
32
- }
33
-
34
-
35
-
36
- // const widgetData = { ...data, data };
37
- const widgetData = body.yml && !body.style ? data : { style: data.style, data: { x: data.x, metrics: data.metrics }, controls: data.controls, type: data.type, title: data.title, table_name: data.table_name };
38
- // console.log(widgetId, widgetData)
39
- if (body?.yml) Object.assign(widgetData, { yml: body.yml });
40
- const rows = await dataUpdate({
41
- table: 'bi.widget',
42
- id: widgetId,
43
- data: widgetData,
44
- });
45
-
46
- return {
47
- message: rows,
48
- status: 200,
49
-
50
- };
51
-
52
- }
1
+ import { dataUpdate } from '@opengis/fastify-table/utils.js';
2
+
3
+ import { yamlSafe } from '../../../../utils.js';
4
+
5
+ export default async function widgetEdit({ pg, body, params, }) {
6
+ const { widget: widgetName, name: dashboardName } = params;
7
+ const data = body.yml && !body.style ? yamlSafe.load(body.yml) : body;
8
+
9
+ const tableName =
10
+ data.data?.table || data?.table || data.table_name || body.table_name;
11
+
12
+ if (!widgetName || !dashboardName) {
13
+ return {
14
+ message: 'not enough params: dashboard and widget name',
15
+ status: 400,
16
+ };
17
+ }
18
+ debugger;
19
+
20
+ const { widget_id: widgetId } = await pg.query(
21
+ `select a.widget_id , b.dashboard_id from bi.widget a, bi.dashboard b
22
+ where $2 in (a.widget_id, a.name) and $1 in (b.dashboard_id, b.name) order by 1,2`,
23
+ [dashboardName, widgetName]
24
+ ).then((res1) => res1.rows?.[0] || {});
25
+
26
+ if (!widgetId) {
27
+ return { message: `widget not found ${widgetName}`, status: 404 };
28
+ }
29
+
30
+ if (!tableName || !pg.pk?.[tableName]) {
31
+ return { message: 'bad params: table', status: 400 };
32
+ }
33
+
34
+
35
+
36
+ // const widgetData = { ...data, data };
37
+
38
+ const widgetData = body.yml ? { yml: body.yml } : { style: data.style, data: { x: data.x, metrics: data.metrics }, controls: data.controls, type: data.type, title: data.title, table_name: data.table_name };
39
+ // console.log(widgetId, widgetData)
40
+ // if (body?.yml) Object.assign(widgetData, { yml: body.yml });
41
+ console.log(widgetData)
42
+ const rows = await dataUpdate({
43
+ table: 'bi.widget',
44
+ id: widgetId,
45
+ data: widgetData,
46
+ });
47
+
48
+ return {
49
+ message: rows,
50
+ status: 200,
51
+
52
+ };
53
+
54
+ }
@@ -1,31 +1,31 @@
1
- /* eslint-disable import/extensions */
2
- import widgetAdd from './controllers/widget.add.js';
3
- import widgetEdit from './controllers/widget.edit.js';
4
- import widgetDel from './controllers/widget.del.js';
5
- import dashboardEdit from './controllers/dashboard.edit.js';
6
- import dashboardAdd from './controllers/dashboard.add.js';
7
-
8
- const biSchema = {
9
- querystring: {
10
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
11
- dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
12
- list: { type: 'string', pattern: '^([\\d])$' },
13
- sql: { type: 'string', pattern: '^([\\d])$' },
14
- },
15
- params: {
16
- name: { type: 'string', pattern: '^([\\d\\w]+)$' },
17
- widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
18
- },
19
- };
20
-
21
- export default async function route(fastify) {
22
- fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
23
- fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
24
- fastify.delete(
25
- `/bi-dashboard/:name/:widget`,
26
- { schema: biSchema },
27
- widgetDel
28
- );
29
- fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
30
- fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
31
- }
1
+ /* eslint-disable import/extensions */
2
+ import widgetAdd from './controllers/widget.add.js';
3
+ import widgetEdit from './controllers/widget.edit.js';
4
+ import widgetDel from './controllers/widget.del.js';
5
+ import dashboardEdit from './controllers/dashboard.edit.js';
6
+ import dashboardAdd from './controllers/dashboard.add.js';
7
+
8
+ const biSchema = {
9
+ querystring: {
10
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
11
+ dashboard: { type: 'string', pattern: '^([\\d\\w]+)$' },
12
+ list: { type: 'string', pattern: '^([\\d])$' },
13
+ sql: { type: 'string', pattern: '^([\\d])$' },
14
+ },
15
+ params: {
16
+ name: { type: 'string', pattern: '^([\\d\\w]+)$' },
17
+ widget: { type: 'string', pattern: '^([\\d\\w]+)$' },
18
+ },
19
+ };
20
+
21
+ export default async function route(fastify) {
22
+ fastify.post(`/bi-dashboard/:name`, { schema: biSchema }, widgetAdd);
23
+ fastify.put(`/bi-dashboard/:name/:widget`, { schema: biSchema }, widgetEdit);
24
+ fastify.delete(
25
+ `/bi-dashboard/:name/:widget`,
26
+ { schema: biSchema },
27
+ widgetDel
28
+ );
29
+ fastify.post(`/bi-dashboard`, { schema: biSchema }, dashboardAdd);
30
+ fastify.put(`/bi-dashboard/:name`, { schema: biSchema }, dashboardEdit);
31
+ }
@@ -1,109 +1,109 @@
1
- import { getFilterSQL } from '@opengis/fastify-table/utils.js';
2
-
3
- import { getWidget } from '../../../../utils.js';
4
-
5
- import downloadClusterData from './utils/downloadClusterData.js';
6
-
7
- const clusterExists = {};
8
-
9
- export default async function cluster({ pg, query = {}, log }) {
10
- const { widget, filter, dashboard, search } = query;
11
-
12
- if (!widget) {
13
- return { message: 'not enough params: widget', status: 400 };
14
- }
15
-
16
- const { data } = await getWidget({ dashboard, widget });
17
-
18
- try {
19
- const pkey = pg.pk?.[data?.table];
20
-
21
- if (!pkey) {
22
- return {
23
- message: `invalid ${widget ? 'widget' : 'dashboard'}: table pk not found (${data?.table})`,
24
- status: 400,
25
- };
26
- }
27
-
28
- // data param
29
- const {
30
- table,
31
- query: where = '1=1',
32
- metrics = [],
33
- cluster,
34
- clusterTable = {},
35
- } = data;
36
-
37
- if (!cluster) {
38
- return {
39
- message: `invalid ${widget ? 'widget' : 'dashboard'}: cluster column not specified`,
40
- status: 400,
41
- };
42
- }
43
-
44
- if (!metrics.length) {
45
- return {
46
- message: `invalid ${widget ? 'widget' : 'dashboard'}: metric columns not found`,
47
- status: 400,
48
- };
49
- }
50
-
51
- if (!clusterTable?.name) {
52
- Object.assign(clusterTable, {
53
- name: 'bi.cluster',
54
- title: 'title',
55
- query: `type='${cluster}'`,
56
- });
57
- }
58
-
59
- if (cluster && !clusterExists[cluster]) {
60
- const res = await downloadClusterData({ pg, log, cluster });
61
- if (res) return res;
62
- clusterExists[cluster] = 1;
63
- }
64
-
65
- if (clusterTable?.name && !pg.pk?.[clusterTable?.name]) {
66
- return {
67
- message: 'invalid widget params: clusterTable pkey not found',
68
- status: 404,
69
- };
70
- }
71
-
72
- const { bounds, extentStr } = await pg.query(`select count(*),
73
- st_asgeojson(st_extent(geom))::json as bounds,
74
- replace(regexp_replace(st_extent(geom)::box2d::text,'BOX\\(|\\)','','g'),' ',',') as "extentStr"
75
- from ${table} where ${where || '1=1'}`).then((res) => res.rows?.[0] || {});
76
- const extent = extentStr ? extentStr.split(',') : undefined;
77
-
78
- // get sql
79
- const { optimizedSQL } =
80
- filter || search
81
- ? await getFilterSQL({ pg, table, filter, search })
82
- : {};
83
-
84
- const q = `select "${cluster}" as name, sum("${metrics[0]}")::float as metric
85
- from ${optimizedSQL ? `(${optimizedSQL})` : table} q
86
- left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id from ${clusterTable?.name} where ${clusterTable?.title}=q."${cluster}" limit 1)b on 1=1
87
- where ${where} group by ${cluster}, b.id order by sum("${metrics[0]}")::float desc`;
88
-
89
- if (query.sql === '1') return q;
90
-
91
- // auto Index
92
- // autoIndex({ table, columns: (metrics || []).concat([cluster]) });
93
-
94
- const { rows = [] } = await pg.query(q);
95
- const vals = rows.map((el) => el.metric - 0).sort((a, b) => a - b);
96
- const len = vals.length;
97
- const sizes = [
98
- vals[0],
99
- vals[Math.floor(len / 4)],
100
- vals[Math.floor(len / 2)],
101
- vals[Math.floor(len * 0.75)],
102
- vals[len - 1],
103
- ];
104
- return { sizes, rows, bounds, extent, count: rows.length, total: rows?.reduce((acc, curr) => (curr.metric || 0) + acc, 0) };
105
- } catch (err) {
106
- log.error('bi/cluster', { error: err.toString(), query });
107
- return { error: err.toString(), status: 500 };
108
- }
109
- }
1
+ import { getFilterSQL } from '@opengis/fastify-table/utils.js';
2
+
3
+ import { getWidget } from '../../../../utils.js';
4
+
5
+ import downloadClusterData from './utils/downloadClusterData.js';
6
+
7
+ const clusterExists = {};
8
+
9
+ export default async function cluster({ pg, query = {}, log }) {
10
+ const { widget, filter, dashboard, search } = query;
11
+
12
+ if (!widget) {
13
+ return { message: 'not enough params: widget', status: 400 };
14
+ }
15
+
16
+ const { data } = await getWidget({ dashboard, widget });
17
+
18
+ try {
19
+ const pkey = pg.pk?.[data?.table];
20
+
21
+ if (!pkey) {
22
+ return {
23
+ message: `invalid ${widget ? 'widget' : 'dashboard'}: table pk not found (${data?.table})`,
24
+ status: 400,
25
+ };
26
+ }
27
+
28
+ // data param
29
+ const {
30
+ table,
31
+ query: where = '1=1',
32
+ metrics = [],
33
+ cluster,
34
+ clusterTable = {},
35
+ } = data;
36
+
37
+ if (!cluster) {
38
+ return {
39
+ message: `invalid ${widget ? 'widget' : 'dashboard'}: cluster column not specified`,
40
+ status: 400,
41
+ };
42
+ }
43
+
44
+ if (!metrics.length) {
45
+ return {
46
+ message: `invalid ${widget ? 'widget' : 'dashboard'}: metric columns not found`,
47
+ status: 400,
48
+ };
49
+ }
50
+
51
+ if (!clusterTable?.name) {
52
+ Object.assign(clusterTable, {
53
+ name: 'bi.cluster',
54
+ title: 'title',
55
+ query: `type='${cluster}'`,
56
+ });
57
+ }
58
+
59
+ if (cluster && !clusterExists[cluster]) {
60
+ const res = await downloadClusterData({ pg, log, cluster });
61
+ if (res) return res;
62
+ clusterExists[cluster] = 1;
63
+ }
64
+
65
+ if (clusterTable?.name && !pg.pk?.[clusterTable?.name]) {
66
+ return {
67
+ message: 'invalid widget params: clusterTable pkey not found',
68
+ status: 404,
69
+ };
70
+ }
71
+
72
+ const { bounds, extentStr } = await pg.query(`select count(*),
73
+ st_asgeojson(st_extent(geom))::json as bounds,
74
+ replace(regexp_replace(st_extent(geom)::box2d::text,'BOX\\(|\\)','','g'),' ',',') as "extentStr"
75
+ from ${table} where ${where || '1=1'}`).then((res) => res.rows?.[0] || {});
76
+ const extent = extentStr ? extentStr.split(',') : undefined;
77
+
78
+ // get sql
79
+ const { optimizedSQL } =
80
+ filter || search
81
+ ? await getFilterSQL({ pg, table, filter, search })
82
+ : {};
83
+
84
+ const q = `select "${cluster}" as name, sum("${metrics[0]}")::float as metric
85
+ from ${optimizedSQL ? `(${optimizedSQL})` : table} q
86
+ left join lateral (select "${pg.pk?.[clusterTable?.name]}" as id from ${clusterTable?.name} where ${clusterTable?.title}=q."${cluster}" limit 1)b on 1=1
87
+ where ${where} group by ${cluster}, b.id order by sum("${metrics[0]}")::float desc`;
88
+
89
+ if (query.sql === '1') return q;
90
+
91
+ // auto Index
92
+ // autoIndex({ table, columns: (metrics || []).concat([cluster]) });
93
+
94
+ const { rows = [] } = await pg.query(q);
95
+ const vals = rows.map((el) => el.metric - 0).sort((a, b) => a - b);
96
+ const len = vals.length;
97
+ const sizes = [
98
+ vals[0],
99
+ vals[Math.floor(len / 4)],
100
+ vals[Math.floor(len / 2)],
101
+ vals[Math.floor(len * 0.75)],
102
+ vals[len - 1],
103
+ ];
104
+ return { sizes, rows, bounds, extent, count: rows.length, total: rows?.reduce((acc, curr) => (curr.metric || 0) + acc, 0) };
105
+ } catch (err) {
106
+ log.error('bi/cluster', { error: err.toString(), query });
107
+ return { error: err.toString(), status: 500 };
108
+ }
109
+ }