@lightdash/common 0.1431.0 → 0.1432.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import { type CompactOrAlias, type CompiledCustomDimension, type CompiledDimension, type CompiledMetric, type CompiledTableCalculation, type CustomDimension, type CustomFormat, type FieldId, type Format, type MetricType, type TableCalculation } from './field';
1
+ import { type CompactOrAlias, type CompiledCustomDimension, type CompiledDimension, type CompiledMetric, type CompiledTableCalculation, type CustomDimension, type CustomFormat, type FieldId, type Format, type Metric, type MetricType, type TableCalculation } from './field';
2
2
  import { type Filters, type MetricFilterRule } from './filter';
3
3
  import { type DateGranularity } from './timeFrames';
4
4
  export interface AdditionalMetric {
@@ -20,10 +20,13 @@ export interface AdditionalMetric {
20
20
  formatOptions?: CustomFormat;
21
21
  }
22
22
  export declare const isAdditionalMetric: (value: any) => value is AdditionalMetric;
23
- export declare const hasFormatOptions: (value: any) => value is AdditionalMetric & {
23
+ export declare const hasFormatOptions: (value: any) => value is {
24
24
  formatOptions: CustomFormat;
25
25
  };
26
26
  export declare const getCustomMetricDimensionId: (metric: AdditionalMetric) => string;
27
+ export type MetricOverrides = {
28
+ [key: string]: Pick<Metric, 'formatOptions'>;
29
+ };
27
30
  export type MetricQuery = {
28
31
  exploreName: string;
29
32
  dimensions: FieldId[];
@@ -34,6 +37,7 @@ export type MetricQuery = {
34
37
  tableCalculations: TableCalculation[];
35
38
  additionalMetrics?: AdditionalMetric[];
36
39
  customDimensions?: CustomDimension[];
40
+ metricOverrides?: MetricOverrides;
37
41
  timezone?: string;
38
42
  metadata?: {
39
43
  hasADateDimension: Pick<CompiledDimension, 'label' | 'name'>;
@@ -100,5 +104,6 @@ export type MetricQueryRequest = {
100
104
  granularity?: DateGranularity;
101
105
  metadata?: MetricQuery['metadata'];
102
106
  timezone?: string;
107
+ metricOverrides?: MetricOverrides;
103
108
  };
104
109
  export {};
@@ -19,6 +19,7 @@ export declare function getCustomFormatFromLegacy({ format, compact, round, }: {
19
19
  compact?: CompactOrAlias;
20
20
  round?: number;
21
21
  }): CustomFormat;
22
+ export declare function hasFormatting(item: Field | AdditionalMetric | TableCalculation | CustomDimension | undefined): boolean;
22
23
  export declare function getCustomFormat(item: Field | AdditionalMetric | TableCalculation | CustomDimension | undefined): CustomFormat | undefined;
23
24
  export declare function applyCustomFormat(value: unknown, format?: CustomFormat | undefined): string;
24
25
  export declare function formatItemValue(item: Field | Dimension | AdditionalMetric | TableCalculation | CustomDimension | undefined, value: unknown, convertToUTC?: boolean): string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatItemValue = exports.applyCustomFormat = exports.getCustomFormat = exports.getCustomFormatFromLegacy = exports.formatNumberValue = exports.isNumber = exports.valueIsNaN = exports.parseTimestamp = exports.parseDate = exports.getLocalTimeDisplay = exports.formatTimestamp = exports.formatDate = exports.isMomentInput = exports.getDateFormat = exports.formatBoolean = exports.currencies = void 0;
3
+ exports.formatItemValue = exports.applyCustomFormat = exports.getCustomFormat = exports.hasFormatting = exports.getCustomFormatFromLegacy = exports.formatNumberValue = exports.isNumber = exports.valueIsNaN = exports.parseTimestamp = exports.parseDate = exports.getLocalTimeDisplay = exports.formatTimestamp = exports.formatDate = exports.isMomentInput = exports.getDateFormat = exports.formatBoolean = exports.currencies = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
6
  const timezone_1 = tslib_1.__importDefault(require("dayjs/plugin/timezone"));
@@ -220,6 +220,23 @@ function getCustomFormatFromLegacy({ format, compact, round, }) {
220
220
  }
221
221
  }
222
222
  exports.getCustomFormatFromLegacy = getCustomFormatFromLegacy;
223
+ function hasFormatting(item) {
224
+ if (!item)
225
+ return false;
226
+ if ((0, metricQuery_1.hasFormatOptions)(item)) {
227
+ return true;
228
+ }
229
+ if ((0, field_1.isTableCalculation)(item)) {
230
+ return item.format !== undefined;
231
+ }
232
+ if ((0, field_1.isDimension)(item) || (0, field_1.isMetric)(item)) {
233
+ return (item.format !== undefined ||
234
+ item.compact !== undefined ||
235
+ item.round !== undefined);
236
+ }
237
+ return false;
238
+ }
239
+ exports.hasFormatting = hasFormatting;
223
240
  function getCustomFormat(item) {
224
241
  if (!item)
225
242
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1431.0",
3
+ "version": "0.1432.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [