@isoftdata/utility-dashboard-backend 3.4.0 → 4.0.0-beta.0

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/README.md CHANGED
@@ -1,201 +1,185 @@
1
- # utility-dashboard-backend
2
-
3
- A backend utility for formatting and loading dashboard chart and report data to be usable by the [frontend dashboard component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard).
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm i @isoftdata/utility-dashboard-backend
9
- ```
10
-
11
- > Breaking change in version 3: ESM style exports
12
-
13
- ## Prerequisites
14
- >
15
- > Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
16
-
17
- * A MySQL database schema as outlined in [schema.md](schema.md)
18
- * A backend that can fetches rows from the chart, report, and report chart tables from the database with their primary keys. Any json columns should be parsed as objects.
19
- * A connection or pool of connections from the `mysql` NPM module for running the charts' queries
20
- * The [dashboard Ractive component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard) on the client
21
-
22
- ## API
23
-
24
- ### formatReportMetadata
25
-
26
- This function returns data in the format expected for the `loadReportMetadata` function on the dashboard client component.
27
-
28
- #### Function signature
29
-
30
- ```js
31
- async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
32
- ```
33
-
34
- #### Example Usage (From Pro Web `server/chart-loader.js`)
35
-
36
- ```js
37
- async function loadReportMetadata({ dashboardReportId, chartId, session }) {
38
- const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
39
- const chartsInReport = await db.dashboardChart.loadByReport({ dashboardReportId, chartId }) // gets all charts for a specified report, or if `chartId` is specified, only gets that chart for that report.
40
- return await formatReportMetadata(db.pool, { report, chartsInReport, session })
41
- }
42
- ```
43
-
44
- #### mysqlConnection
45
-
46
- A connection or pool of connections from the `mysql` npm module.
47
-
48
- #### report
49
-
50
- A report `object`, a single row from the `dashboard_report`/`wa_dashboard_report` table/view. The `parameters` Array from the `json` column should also be parsed from JSON and appended to this object.
51
-
52
- Example:
53
-
54
- ```js
55
- {
56
- dashboardReportId: 1,
57
- reportName: 'report_overview',
58
- reportTitle: 'Overview',
59
- shareType: 'everyone',
60
- shareId: null,
61
- ownerId: null,
62
- parameters: [ // parameters deconstructed from `json` column after parsing
63
- {
64
- name: 'date_range',
65
- type: 'dateRange',
66
- title: 'Date Range',
67
- default: 'This Year'
68
- }
69
- ]
70
- }
71
- ```
72
-
73
- #### chartsInReport
74
-
75
- An `Array` of chart `object`s, one for each chart in the report, multiple rows from the `dashboard_chart`/`wa_dashboard_chart` table/view joined with `dashboard_report_chart`/`wa_dashboard_report_chart` to get the chart's rank.
76
-
77
- Example:
78
-
79
- ```js
80
- [
81
- {
82
- chartId: 10,
83
- name: 'line_sales_over_time_and_previous_period',
84
- title: 'Sales over Time',
85
- supertype: 'google',
86
- formatting: { Sales: [Object] },
87
- multiSeries: {
88
- value: 'Sales',
89
- series: 'Period',
90
- tooltip: 'Tooltip',
91
- groupXAxisBy: 'Date'
92
- },
93
- chartWrapper: { options: [Object], chartType: 'LineChart' },
94
- rank: 1
95
- },
96
- {
97
- chartId: 16,
98
- name: 'map_sales_by_lat_long',
99
- title: 'Sales Map',
100
- supertype: 'google',
101
- formatting: { Sales: [Object] },
102
- chartWrapper: { options: [Object], chartType: 'GeoChart' },
103
- rank: 2
104
- }
105
- ]
106
- ```
107
-
108
- #### session
109
-
110
- Session object from the Auth Module
111
-
112
- #### site (optional)
113
-
114
- The 'type' of site for the product this is used in. Determines the MySQL table to query for site selection parameters, and used to calculate `siteIdColumn` if that is not specified.
115
-
116
- #### siteIdColumn (optional)
117
-
118
- The name of the column that stores the site id in the site table. Defaults to `${site}id`.
119
-
120
- #### siteNameColumn (optional)
121
-
122
- The store name column.
123
-
124
- ### formatChartDataForReport
125
-
126
- This function returns data in the format expected for the `loadChartDataForReport` function on the dashboard client component, including applying any report-specific chart options overrides and running the chart's query.
127
-
128
- #### Function signature
129
-
130
- ```js
131
- async formatChartDataForReport(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session })
132
- ```
133
-
134
- #### Example usage: (from Pro Web `server/chart-loader.js`)
135
-
136
- ```js
137
- async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
138
- const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
139
- const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
140
- const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
141
- try {
142
- const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
143
- return chartData
144
- } catch (err) {
145
- console.error(err)
146
- return { isErrored: true }
147
- }
148
- }
149
- ```
150
-
151
- #### mysqlConnection
152
-
153
- A connection or pool of connections from the `mysql` npm module.
154
-
155
- #### reportParameters
156
-
157
- The `parameters` array from a report object.
158
-
159
- #### chartId
160
-
161
- The id of a chart row in `wa_dashboard_chart`.
162
-
163
- #### parameterSelectionList
164
-
165
- The array of selected parameters sent from the client dashboard.
166
-
167
- #### session
168
-
169
- Session object from the Auth Module
170
-
171
- ### loadOutputParameterValues
172
-
173
- This function outputs the report's parameter values in the format expected by the dashboard client and backend. When sending to the client, including `forClient: true` will not include the properties only needed by the backend.
174
-
175
- ### Function signature
176
-
177
- ```js
178
- async function loadOutputParameterValues(mysqlConnection, { definitionList, selectionList = [], forClient = false })
179
- ```
180
-
181
- #### Example Usage
182
-
183
- #### mysqlConnection
184
-
185
- A connection or pool of connections from the `mysql` npm module.
186
-
187
- #### definitionList
188
-
189
- The `parameters` property from the `json` column of a row in the `dashboard_report` table.
190
-
191
- #### selectionList
192
-
193
- An array of objects representing the selected parameters sent from the client. Only needed when loading the chart data, not when loading the report "metadata". Each parameter object should match the format specified in [schema.md](schema.md).
194
-
195
- #### forClient
196
-
197
- If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
198
-
199
- ### Returns
200
-
201
- An array of objects matching the format outlined in [schema.md](schema.md)
1
+ # utility-dashboard-backend
2
+ A backend utility for formatting and loading dashboard chart and report data to be usable by the [frontend dashboard component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard).
3
+
4
+ ## Installation
5
+
6
+ ```bash
7
+ npm i @isoftdata/utility-dashboard-backend
8
+ ```
9
+
10
+ > Breaking change in version 3: ESM style exports
11
+
12
+ ## Prerequisites
13
+ > Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
14
+ * A MySQL database schema as outlined in [schema.md](schema.md)
15
+ * A backend that can fetches rows from the chart, report, and report chart tables from the database with their primary keys. Any json columns should be parsed as objects.
16
+ * A connection or pool of connections from the `mysql` NPM module for running the charts' queries
17
+ * The [dashboard Ractive component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard) on the client
18
+
19
+ ## API
20
+
21
+ ### formatReportMetadata
22
+
23
+ This function returns data in the format expected for the `loadReportMetadata` function on the dashboard client component.
24
+
25
+ #### Function signature
26
+
27
+ ```js
28
+ async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
29
+ ```
30
+
31
+ #### Example Usage (From Pro Web `server/chart-loader.js`)
32
+
33
+ ```js
34
+ async function loadReportMetadata({ dashboardReportId, chartId, session }) {
35
+ const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
36
+ const chartsInReport = await db.dashboardChart.loadByReport({ dashboardReportId, chartId }) // gets all charts for a specified report, or if `chartId` is specified, only gets that chart for that report.
37
+ return await formatReportMetadata(db.pool, { report, chartsInReport, session })
38
+ }
39
+ ```
40
+
41
+ #### mysqlConnection
42
+ A connection or pool of connections from the `mysql` npm module.
43
+
44
+ #### report
45
+
46
+ A report `object`, a single row from the `dashboard_report`/`wa_dashboard_report` table/view. The `parameters` Array from the `json` column should also be parsed from JSON and appended to this object.
47
+
48
+ Example:
49
+
50
+ ```js
51
+ {
52
+ dashboardReportId: 1,
53
+ reportName: 'report_overview',
54
+ reportTitle: 'Overview',
55
+ shareType: 'everyone',
56
+ shareId: null,
57
+ ownerId: null,
58
+ parameters: [ // parameters deconstructed from `json` column after parsing
59
+ {
60
+ name: 'date_range',
61
+ type: 'dateRange',
62
+ title: 'Date Range',
63
+ default: 'This Year'
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+ #### chartsInReport
70
+
71
+ An `Array` of chart `object`s, one for each chart in the report, multiple rows from the `dashboard_chart`/`wa_dashboard_chart` table/view joined with `dashboard_report_chart`/`wa_dashboard_report_chart` to get the chart's rank.
72
+
73
+ Example:
74
+
75
+ ```js
76
+ [
77
+ {
78
+ chartId: 10,
79
+ name: 'line_sales_over_time_and_previous_period',
80
+ title: 'Sales over Time',
81
+ supertype: 'google',
82
+ formatting: { Sales: [Object] },
83
+ multiSeries: {
84
+ value: 'Sales',
85
+ series: 'Period',
86
+ tooltip: 'Tooltip',
87
+ groupXAxisBy: 'Date'
88
+ },
89
+ chartWrapper: { options: [Object], chartType: 'LineChart' },
90
+ rank: 1
91
+ },
92
+ {
93
+ chartId: 16,
94
+ name: 'map_sales_by_lat_long',
95
+ title: 'Sales Map',
96
+ supertype: 'google',
97
+ formatting: { Sales: [Object] },
98
+ chartWrapper: { options: [Object], chartType: 'GeoChart' },
99
+ rank: 2
100
+ }
101
+ ]
102
+ ```
103
+
104
+ #### session
105
+ Session object from the Auth Module
106
+
107
+ #### site (optional)
108
+ The 'type' of site for the product this is used in. Determines the MySQL table to query for site selection parameters, and used to calculate `siteIdColumn` if that is not specified.
109
+ #### siteIdColumn (optional)
110
+ The name of the column that stores the site id in the site table. Defaults to `${site}id`.
111
+ #### siteNameColumn (optional)
112
+ The store name column.
113
+
114
+ ### formatChartDataForReport
115
+
116
+ This function returns data in the format expected for the `loadChartDataForReport` function on the dashboard client component, including applying any report-specific chart options overrides and running the chart's query.
117
+
118
+ #### Function signature
119
+
120
+ ```js
121
+ async formatChartDataForReport(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session })
122
+ ```
123
+
124
+ #### Example usage: (from Pro Web `server/chart-loader.js`)
125
+
126
+ ```js
127
+ async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
128
+ const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
129
+ const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
130
+ const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
131
+ try {
132
+ const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
133
+ return chartData
134
+ } catch (err) {
135
+ console.error(err)
136
+ return { isErrored: true }
137
+ }
138
+ }
139
+ ```
140
+
141
+ #### mysqlConnection
142
+ A connection or pool of connections from the `mysql` npm module.
143
+
144
+ #### reportParameters
145
+ The `parameters` array from a report object.
146
+
147
+ #### chartId
148
+ The id of a chart row in `wa_dashboard_chart`.
149
+
150
+ #### parameterSelectionList
151
+ The array of selected parameters sent from the client dashboard.
152
+
153
+ #### session
154
+ Session object from the Auth Module
155
+
156
+ ### loadOutputParameterValues
157
+
158
+ This function outputs the report's parameter values in the format expected by the dashboard client and backend. When sending to the client, including `forClient: true` will not include the properties only needed by the backend.
159
+
160
+ ### Function signature
161
+
162
+ ```js
163
+ async function loadOutputParameterValues(mysqlConnection, { definitionList, selectionList = [], forClient = false })
164
+ ```
165
+
166
+ #### Example Usage
167
+
168
+ #### mysqlConnection
169
+ A connection or pool of connections from the `mysql` npm module.
170
+
171
+ #### definitionList
172
+
173
+ The `parameters` property from the `json` column of a row in the `dashboard_report` table.
174
+
175
+ #### selectionList
176
+
177
+ An array of objects representing the selected parameters sent from the client. Only needed when loading the chart data, not when loading the report "metadata". Each parameter object should match the format specified in [schema.md](schema.md).
178
+
179
+ #### forClient
180
+
181
+ If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
182
+
183
+ ### Returns
184
+
185
+ An array of objects matching the format outlined in [schema.md](schema.md)
@@ -1,12 +1,9 @@
1
- import { Connection, RowDataPacket } from 'mysql';
2
- import type { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from './types/chart.js';
3
- export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date' | 'boolean';
1
+ import { DatabaseConnectionInterface, QueryCommand, RowDataPacket } from '@isoftdata/utility-db';
2
+ import type { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from './types/chart';
3
+ export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date';
4
4
  export type QueryFieldsObject = Record<string, FieldType>;
5
- export declare function queryWithFields(connection: Connection, query: {
6
- sql: string;
7
- values: unknown[];
8
- }): Promise<{
9
- results: RowDataPacket[];
5
+ export declare function queryWithFields(connection: DatabaseConnectionInterface, query: QueryCommand): Promise<{
6
+ results: object[];
10
7
  fields: QueryFieldsObject;
11
8
  }>;
12
9
  export type getMultiSeriesDataInput = {
@@ -25,7 +22,6 @@ export declare function coerceNullColumn(columnProp: string, data: RowDataPacket
25
22
  export declare function handleFormattingTemplates(formatting?: Formatting): ProcessedFormatting;
26
23
  export declare function getDataTableFormat(data: RowDataPacket[], fields: QueryFieldsObject, multiSeries?: MultiSeriesOptions): GoogleDataTable;
27
24
  export declare function makeDataCumulative(dataTable: GoogleDataTable, cumulative?: boolean): GoogleDataTable;
28
- export declare function getSvelteDataTableFormat(rows: RowDataPacket[], fields: {
25
+ export declare function getRactiveTableDataFormat(rows: RowDataPacket[], fields: {
29
26
  [key: string]: string;
30
27
  }, formatting: ProcessedFormatting, styleTemplates?: {}): Table;
31
- export { getSvelteDataTableFormat as getRactiveDataTableFormat };