@isoftdata/utility-dashboard-backend 2.4.0 → 2.4.1

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,177 +1,177 @@
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
- ## Prerequisites
5
- > Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
6
- * A MySQL database schema as outlined in [schema.md](schema.md)
7
- * 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.
8
- * A connection or pool of connections from the `mysql` NPM module for running the charts' queries
9
- * The [dashboard Ractive component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard) on the client
10
-
11
- ## API
12
-
13
- ### formatReportMetadata
14
-
15
- This function returns data in the format expected for the `loadReportMetadata` function on the dashboard client component.
16
-
17
- #### Function signature
18
-
19
- ```js
20
- async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
21
- ```
22
-
23
- #### Example Usage (From Pro Web `server/chart-loader.js`)
24
-
25
- ```js
26
- async function loadReportMetadata({ dashboardReportId, chartId, session }) {
27
- const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
28
- 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.
29
- return await formatReportMetadata(db.pool, { report, chartsInReport, session })
30
- }
31
- ```
32
-
33
- #### mysqlConnection
34
- A connection or pool of connections from the `mysql` npm module.
35
-
36
- #### report
37
-
38
- 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.
39
-
40
- Example:
41
-
42
- ```js
43
- {
44
- dashboardReportId: 1,
45
- reportName: 'report_overview',
46
- reportTitle: 'Overview',
47
- shareType: 'everyone',
48
- shareId: null,
49
- ownerId: null,
50
- parameters: [ // parameters deconstructed from `json` column after parsing
51
- {
52
- name: 'date_range',
53
- type: 'dateRange',
54
- title: 'Date Range',
55
- default: 'This Year'
56
- }
57
- ]
58
- }
59
- ```
60
-
61
- #### chartsInReport
62
-
63
- 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.
64
-
65
- Example:
66
-
67
- ```js
68
- [
69
- {
70
- chartId: 10,
71
- name: 'line_sales_over_time_and_previous_period',
72
- title: 'Sales over Time',
73
- supertype: 'google',
74
- formatting: { Sales: [Object] },
75
- multiSeries: {
76
- value: 'Sales',
77
- series: 'Period',
78
- tooltip: 'Tooltip',
79
- groupXAxisBy: 'Date'
80
- },
81
- chartWrapper: { options: [Object], chartType: 'LineChart' },
82
- rank: 1
83
- },
84
- {
85
- chartId: 16,
86
- name: 'map_sales_by_lat_long',
87
- title: 'Sales Map',
88
- supertype: 'google',
89
- formatting: { Sales: [Object] },
90
- chartWrapper: { options: [Object], chartType: 'GeoChart' },
91
- rank: 2
92
- }
93
- ]
94
- ```
95
-
96
- #### session
97
- Session object from the Auth Module
98
-
99
- #### site (optional)
100
- 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.
101
- #### siteIdColumn (optional)
102
- The name of the column that stores the site id in the site table. Defaults to `${site}id`.
103
- #### siteNameColumn (optional)
104
- The store name column.
105
-
106
- ### formatChartDataForReport
107
-
108
- 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.
109
-
110
- #### Function signature
111
-
112
- ```js
113
- async formatChartDataForReport(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session })
114
- ```
115
-
116
- #### Example usage: (from Pro Web `server/chart-loader.js`)
117
-
118
- ```js
119
- async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
120
- const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
121
- const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
122
- const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
123
- try {
124
- const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
125
- return chartData
126
- } catch (err) {
127
- console.error(err)
128
- return { isErrored: true }
129
- }
130
- }
131
- ```
132
-
133
- #### mysqlConnection
134
- A connection or pool of connections from the `mysql` npm module.
135
-
136
- #### reportParameters
137
- The `parameters` array from a report object.
138
-
139
- #### chartId
140
- The id of a chart row in `wa_dashboard_chart`.
141
-
142
- #### parameterSelectionList
143
- The array of selected parameters sent from the client dashboard.
144
-
145
- #### session
146
- Session object from the Auth Module
147
-
148
- ### loadOutputParameterValues
149
-
150
- 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.
151
-
152
- ### Function signature
153
-
154
- ```js
155
- async function loadOutputParameterValues(mysqlConnection, { definitionList, selectionList = [], forClient = false })
156
- ```
157
-
158
- #### Example Usage
159
-
160
- #### mysqlConnection
161
- A connection or pool of connections from the `mysql` npm module.
162
-
163
- #### definitionList
164
-
165
- The `parameters` property from the `json` column of a row in the `dashboard_report` table.
166
-
167
- #### selectionList
168
-
169
- 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).
170
-
171
- #### forClient
172
-
173
- If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
174
-
175
- ### Returns
176
-
177
- 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
+ ## Prerequisites
5
+ > Version 3.Y.Z of the frontend component is required for use with version 2.Y.Z of the backend component.
6
+ * A MySQL database schema as outlined in [schema.md](schema.md)
7
+ * 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.
8
+ * A connection or pool of connections from the `mysql` NPM module for running the charts' queries
9
+ * The [dashboard Ractive component](https://github.com/ISoft-Data-Systems/ractive-component-web-dashboard) on the client
10
+
11
+ ## API
12
+
13
+ ### formatReportMetadata
14
+
15
+ This function returns data in the format expected for the `loadReportMetadata` function on the dashboard client component.
16
+
17
+ #### Function signature
18
+
19
+ ```js
20
+ async formatReportMetadata(mysqlConnection, { report, chartsInReport, session })
21
+ ```
22
+
23
+ #### Example Usage (From Pro Web `server/chart-loader.js`)
24
+
25
+ ```js
26
+ async function loadReportMetadata({ dashboardReportId, chartId, session }) {
27
+ const report = await db.dashboardReport.loadById({ dashboardReportId }) // gets a report by its id
28
+ 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.
29
+ return await formatReportMetadata(db.pool, { report, chartsInReport, session })
30
+ }
31
+ ```
32
+
33
+ #### mysqlConnection
34
+ A connection or pool of connections from the `mysql` npm module.
35
+
36
+ #### report
37
+
38
+ 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.
39
+
40
+ Example:
41
+
42
+ ```js
43
+ {
44
+ dashboardReportId: 1,
45
+ reportName: 'report_overview',
46
+ reportTitle: 'Overview',
47
+ shareType: 'everyone',
48
+ shareId: null,
49
+ ownerId: null,
50
+ parameters: [ // parameters deconstructed from `json` column after parsing
51
+ {
52
+ name: 'date_range',
53
+ type: 'dateRange',
54
+ title: 'Date Range',
55
+ default: 'This Year'
56
+ }
57
+ ]
58
+ }
59
+ ```
60
+
61
+ #### chartsInReport
62
+
63
+ 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.
64
+
65
+ Example:
66
+
67
+ ```js
68
+ [
69
+ {
70
+ chartId: 10,
71
+ name: 'line_sales_over_time_and_previous_period',
72
+ title: 'Sales over Time',
73
+ supertype: 'google',
74
+ formatting: { Sales: [Object] },
75
+ multiSeries: {
76
+ value: 'Sales',
77
+ series: 'Period',
78
+ tooltip: 'Tooltip',
79
+ groupXAxisBy: 'Date'
80
+ },
81
+ chartWrapper: { options: [Object], chartType: 'LineChart' },
82
+ rank: 1
83
+ },
84
+ {
85
+ chartId: 16,
86
+ name: 'map_sales_by_lat_long',
87
+ title: 'Sales Map',
88
+ supertype: 'google',
89
+ formatting: { Sales: [Object] },
90
+ chartWrapper: { options: [Object], chartType: 'GeoChart' },
91
+ rank: 2
92
+ }
93
+ ]
94
+ ```
95
+
96
+ #### session
97
+ Session object from the Auth Module
98
+
99
+ #### site (optional)
100
+ 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.
101
+ #### siteIdColumn (optional)
102
+ The name of the column that stores the site id in the site table. Defaults to `${site}id`.
103
+ #### siteNameColumn (optional)
104
+ The store name column.
105
+
106
+ ### formatChartDataForReport
107
+
108
+ 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.
109
+
110
+ #### Function signature
111
+
112
+ ```js
113
+ async formatChartDataForReport(mysqlConnection, { reportParameters, chart, reportChart, parameterSelectionList, session })
114
+ ```
115
+
116
+ #### Example usage: (from Pro Web `server/chart-loader.js`)
117
+
118
+ ```js
119
+ async function loadChartDataForReport ({ dashboardReportId, chartId, parameterSelectionList, session }) {
120
+ const report = await db.dashboardReport.loadById({ dashboardReportId }) // get the report object
121
+ const chart = await db.dashboardChart.loadById({ chartId }) // get the chart object
122
+ const reportChart = await db.dashboardReportChart.loadByReportAndChartId({ chartId, dashboardReportId }) // get the report chart for the rank/overrides
123
+ try {
124
+ const chartData = await formatChartDataForReport(db.pool, { reportParameters: report.parameters, chart, reportChart, parameterSelectionList, session })
125
+ return chartData
126
+ } catch (err) {
127
+ console.error(err)
128
+ return { isErrored: true }
129
+ }
130
+ }
131
+ ```
132
+
133
+ #### mysqlConnection
134
+ A connection or pool of connections from the `mysql` npm module.
135
+
136
+ #### reportParameters
137
+ The `parameters` array from a report object.
138
+
139
+ #### chartId
140
+ The id of a chart row in `wa_dashboard_chart`.
141
+
142
+ #### parameterSelectionList
143
+ The array of selected parameters sent from the client dashboard.
144
+
145
+ #### session
146
+ Session object from the Auth Module
147
+
148
+ ### loadOutputParameterValues
149
+
150
+ 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.
151
+
152
+ ### Function signature
153
+
154
+ ```js
155
+ async function loadOutputParameterValues(mysqlConnection, { definitionList, selectionList = [], forClient = false })
156
+ ```
157
+
158
+ #### Example Usage
159
+
160
+ #### mysqlConnection
161
+ A connection or pool of connections from the `mysql` npm module.
162
+
163
+ #### definitionList
164
+
165
+ The `parameters` property from the `json` column of a row in the `dashboard_report` table.
166
+
167
+ #### selectionList
168
+
169
+ 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).
170
+
171
+ #### forClient
172
+
173
+ If this value is truthy, parameters' `queryValues` properties will be excluded, as the client does not need them.
174
+
175
+ ### Returns
176
+
177
+ An array of objects matching the format outlined in [schema.md](schema.md)
@@ -1,30 +1,30 @@
1
- import { Connection, RowDataPacket } from "mysql";
2
- import { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from "./types/chart";
3
- export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date';
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[];
10
- fields: QueryFieldsObject;
11
- }>;
12
- export type getMultiSeriesDataInput = {
13
- data: RowDataPacket[];
14
- seriesOptions: MultiSeriesOptions;
15
- formatting?: Formatting;
16
- fields: QueryFieldsObject;
17
- };
18
- export declare function getMultiSeriesData({ data: queryResult, seriesOptions, formatting, fields }: getMultiSeriesDataInput): {
19
- data: RowDataPacket[];
20
- formatting: Formatting;
21
- fields: QueryFieldsObject;
22
- };
23
- export declare function makeNegativeNumericValuesZero(resultSet: RowDataPacket[]): RowDataPacket[];
24
- export declare function coerceNullColumn(columnProp: string, data: RowDataPacket[], destinationType?: unknown): RowDataPacket[];
25
- export declare function handleFormattingTemplates(formatting?: Formatting): ProcessedFormatting;
26
- export declare function getDataTableFormat(data: RowDataPacket[], fields: QueryFieldsObject, multiSeries?: MultiSeriesOptions): GoogleDataTable;
27
- export declare function makeDataCumulative(dataTable: GoogleDataTable, cumulative?: boolean): GoogleDataTable;
28
- export declare function getRactiveTableDataFormat(rows: RowDataPacket[], fields: {
29
- [key: string]: string;
30
- }, formatting: ProcessedFormatting, styleTemplates?: {}): Table;
1
+ import { Connection, RowDataPacket } from "mysql";
2
+ import { Formatting, GoogleDataTable, MultiSeriesOptions, ProcessedFormatting, Table } from "./types/chart";
3
+ export type FieldType = 'string' | 'number' | 'datetime' | 'timeofday' | 'date';
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[];
10
+ fields: QueryFieldsObject;
11
+ }>;
12
+ export type getMultiSeriesDataInput = {
13
+ data: RowDataPacket[];
14
+ seriesOptions: MultiSeriesOptions;
15
+ formatting?: Formatting;
16
+ fields: QueryFieldsObject;
17
+ };
18
+ export declare function getMultiSeriesData({ data: queryResult, seriesOptions, formatting, fields }: getMultiSeriesDataInput): {
19
+ data: RowDataPacket[];
20
+ formatting: Formatting;
21
+ fields: QueryFieldsObject;
22
+ };
23
+ export declare function makeNegativeNumericValuesZero(resultSet: RowDataPacket[]): RowDataPacket[];
24
+ export declare function coerceNullColumn(columnProp: string, data: RowDataPacket[], destinationType?: unknown): RowDataPacket[];
25
+ export declare function handleFormattingTemplates(formatting?: Formatting): ProcessedFormatting;
26
+ export declare function getDataTableFormat(data: RowDataPacket[], fields: QueryFieldsObject, multiSeries?: MultiSeriesOptions): GoogleDataTable;
27
+ export declare function makeDataCumulative(dataTable: GoogleDataTable, cumulative?: boolean): GoogleDataTable;
28
+ export declare function getRactiveTableDataFormat(rows: RowDataPacket[], fields: {
29
+ [key: string]: string;
30
+ }, formatting: ProcessedFormatting, styleTemplates?: {}): Table;