@lightdash/common 0.1407.1 → 0.1408.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.
@@ -15,5 +15,14 @@ type PivotQueryResultsArgs = {
15
15
  getFieldLabel: FieldLabelFunction;
16
16
  };
17
17
  export declare const pivotQueryResults: ({ pivotConfig, metricQuery, rows, options, getField, getFieldLabel, }: PivotQueryResultsArgs) => PivotData;
18
- export declare const pivotResultsAsCsv: (pivotConfig: PivotConfig, rows: ResultRow[], itemMap: ItemsMap, metricQuery: MetricQuery, customLabels: Record<string, string> | undefined, onlyRaw: boolean, maxColumnLimit: number) => string[][];
18
+ export declare const pivotResultsAsCsv: ({ pivotConfig, rows, itemMap, metricQuery, customLabels, onlyRaw, maxColumnLimit, undefinedCharacter, }: {
19
+ pivotConfig: PivotConfig;
20
+ rows: ResultRow[];
21
+ itemMap: ItemsMap;
22
+ metricQuery: MetricQuery;
23
+ customLabels: Record<string, string> | undefined;
24
+ onlyRaw: boolean;
25
+ maxColumnLimit: number;
26
+ undefinedCharacter?: string | undefined;
27
+ }) => string[][];
19
28
  export {};
@@ -502,7 +502,7 @@ const pivotQueryResults = ({ pivotConfig, metricQuery, rows, options, getField,
502
502
  return combinedRetrofit(pivotData, getField, getFieldLabel);
503
503
  };
504
504
  exports.pivotQueryResults = pivotQueryResults;
505
- const pivotResultsAsCsv = (pivotConfig, rows, itemMap, metricQuery, customLabels, onlyRaw, maxColumnLimit) => {
505
+ const pivotResultsAsCsv = ({ pivotConfig, rows, itemMap, metricQuery, customLabels, onlyRaw, maxColumnLimit, undefinedCharacter = '', }) => {
506
506
  const getFieldLabel = (fieldId) => {
507
507
  const customLabel = customLabels?.[fieldId];
508
508
  if (customLabel !== undefined)
@@ -526,7 +526,7 @@ const pivotResultsAsCsv = (pivotConfig, rows, itemMap, metricQuery, customLabels
526
526
  ? header.value[formatField]
527
527
  : getFieldLabel(header.fieldId));
528
528
  const fields = pivotedResults.titleFields[i];
529
- const fieldLabels = fields.map((field) => field ? getFieldLabel(field.fieldId) : '-');
529
+ const fieldLabels = fields.map((field) => field ? getFieldLabel(field.fieldId) : undefinedCharacter);
530
530
  acc[i] = [...fieldLabels, ...values];
531
531
  return acc;
532
532
  }, [[]]);
@@ -536,7 +536,8 @@ const pivotResultsAsCsv = (pivotConfig, rows, itemMap, metricQuery, customLabels
536
536
  // Fields that return `null` don't appear in the pivot table
537
537
  // If there are no index fields, we need to add an empty string to the beginning of the row
538
538
  const noIndexPrefix = hasIndex ? [] : [''];
539
- const formattedRows = fieldIds.map((fieldId) => row[fieldId]?.value?.[formatField] || '-');
539
+ const formattedRows = fieldIds.map((fieldId) => row[fieldId]?.value?.[formatField] ||
540
+ undefinedCharacter);
540
541
  return [...noIndexPrefix, ...formattedRows];
541
542
  });
542
543
  return [...headers, ...pivotedRows];
@@ -1,4 +1,5 @@
1
1
  import { type MetricQueryResponse } from './metricQuery';
2
+ import { type PivotConfig } from './pivot';
2
3
  export type ApiGdriveAccessTokenResponse = {
3
4
  status: 'ok';
4
5
  results: string;
@@ -14,6 +15,7 @@ export type UploadMetricGsheet = {
14
15
  columnOrder: string[];
15
16
  customLabels?: CustomLabel;
16
17
  hiddenFields?: string[];
18
+ pivotConfig?: PivotConfig;
17
19
  };
18
20
  export type UploadMetricGsheetPayload = UploadMetricGsheet & {
19
21
  userUuid: string;
@@ -1,5 +1,6 @@
1
1
  import { type FieldType } from './field';
2
2
  import { type ResultRow, type ResultValue } from './results';
3
+ import { type CreateSavedChartVersion } from './savedCharts';
3
4
  export type PivotConfig = {
4
5
  pivotDimensions: string[];
5
6
  metricsAsRows: boolean;
@@ -60,4 +61,5 @@ export type PivotData = {
60
61
  pivotColumnInfo: PivotColumn[];
61
62
  };
62
63
  };
64
+ export declare const getPivotConfig: (savedChart: CreateSavedChartVersion) => PivotConfig | undefined;
63
65
  export {};
@@ -1,2 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPivotConfig = void 0;
4
+ const savedCharts_1 = require("./savedCharts");
5
+ const getPivotConfig = (savedChart) => savedChart.chartConfig.type === savedCharts_1.ChartType.TABLE &&
6
+ savedChart.pivotConfig !== undefined
7
+ ? {
8
+ pivotDimensions: savedChart.pivotConfig.columns,
9
+ metricsAsRows: false,
10
+ hiddenMetricFieldIds: (0, savedCharts_1.getHiddenTableFields)(savedChart.chartConfig),
11
+ columnOrder: savedChart.tableConfig.columnOrder,
12
+ }
13
+ : undefined;
14
+ exports.getPivotConfig = getPivotConfig;
@@ -1,3 +1,4 @@
1
1
  import { RequestMethod } from '../types/api';
2
2
  export declare const LightdashRequestMethodHeader = "Lightdash-Request-Method";
3
+ export declare const LightdashVersionHeader = "Lightdash-Version";
3
4
  export declare const getRequestMethod: (headerValue: string | undefined) => RequestMethod;
package/dist/utils/api.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRequestMethod = exports.LightdashRequestMethodHeader = void 0;
3
+ exports.getRequestMethod = exports.LightdashVersionHeader = exports.LightdashRequestMethodHeader = void 0;
4
4
  const api_1 = require("../types/api");
5
5
  exports.LightdashRequestMethodHeader = 'Lightdash-Request-Method';
6
+ exports.LightdashVersionHeader = 'Lightdash-Version';
6
7
  const getRequestMethod = (headerValue) => (0, api_1.isRequestMethod)(headerValue) ? headerValue : api_1.RequestMethod.UNKNOWN;
7
8
  exports.getRequestMethod = getRequestMethod;
@@ -146,7 +146,7 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
146
146
  const groupByCompareMetricRows = (0, lodash_1.groupBy)(compareMetricRows, (row) => new Date(String(row[compareDimensionId].value.raw)).toISOString());
147
147
  const offsetGroupByCompareMetricRows = (0, lodash_1.mapKeys)(groupByCompareMetricRows, (_, date) => comparison.type === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD
148
148
  ? (0, exports.getDateCalcUtils)(timeFrames_1.TimeFrames.YEAR)
149
- .back(new Date(date))
149
+ .forward(new Date(date))
150
150
  .toISOString()
151
151
  : date);
152
152
  const dates = new Set([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1407.1",
3
+ "version": "0.1408.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [