@lightdash/common 0.1406.0 → 0.1407.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/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ import { type ApiCatalogAnalyticsResults, type ApiCatalogMetadataResults, type A
40
40
  import { type ApiChartAsCodeListResponse, type ApiChartAsCodeUpsertResponse } from './types/coder';
41
41
  import { type ApiChartContentResponse, type ApiContentResponse } from './types/content';
42
42
  import type { ApiGroupListResponse } from './types/groups';
43
- import type { ApiMetricsExplorerQueryResults } from './types/metricsExplorer';
43
+ import type { ApiMetricsExplorerQueryResults, ApiMetricsExplorerTotalResults } from './types/metricsExplorer';
44
44
  import { type ApiPromotionChangesResponse } from './types/promotion';
45
45
  import { type ApiSemanticLayerClientInfo, type ApiSemanticViewerChartCreate, type ApiSemanticViewerChartGet, type ApiSemanticViewerChartUpdate } from './types/semanticLayer';
46
46
  import { type ApiCreateSqlChart, type ApiCreateVirtualView, type ApiGithubDbtWritePreview, type ApiSqlChart, type ApiSqlRunnerJobStatusResponse, type ApiUpdateSqlChart } from './types/sqlRunner';
@@ -382,7 +382,7 @@ export type ApiAiGetDashboardSummaryResponse = {
382
382
  status: 'ok';
383
383
  results: DashboardSummary;
384
384
  };
385
- type ApiResults = ApiQueryResults | ApiSqlQueryResults | ApiCompiledQueryResults | ApiExploresResults | ApiExploreResults | ApiStatusResults | ApiRefreshResults | ApiHealthResults | Organization | LightdashUser | LoginOptions | SavedChart | SavedChart[] | Space[] | InviteLink | OrganizationProject[] | Project | WarehouseCredentials | OrganizationMemberProfile[] | ProjectCatalog | TablesConfiguration | Dashboard | DashboardBasicDetails[] | OnboardingStatus | Dashboard[] | DeleteOpenIdentity | ApiFlashResults | Record<OpenIdIdentitySummary['issuerType'], OpenIdIdentitySummary[]> | FilterableField[] | DashboardAvailableFilters | ProjectSavedChartStatus | null | Array<unknown> | ApiJobStartedResults | ApiCreateUserTokenResults | CreatePersonalAccessToken | PersonalAccessToken | ProjectMemberProfile[] | ProjectGroupAccess | SearchResults | Space | ShareUrl | SlackSettings | ApiSlackChannelsResponse['results'] | UserActivity | SchedulerAndTargets | SchedulerAndTargets[] | FieldValueSearchResult | ApiDownloadCsv | AllowedEmailDomains | UpdateAllowedEmailDomains | UserAllowedOrganization[] | EmailStatusExpiring | ApiScheduledDownloadCsv | PinnedItems | ViewStatistics | SchedulerWithLogs | ValidationResponse[] | ChartHistory | ChartVersion | Array<GitRepo> | PullRequestCreated | GitIntegrationConfiguration | UserWarehouseCredentials | ApiJobStatusResponse['results'] | ApiJobScheduledResponse['results'] | ApiSshKeyPairResponse['results'] | MostPopularAndRecentlyUpdated | ApiCalculateTotalResponse['results'] | Record<string, DbtExposure> | ApiCreateComment['results'] | ApiGetComments['results'] | ApiDeleteComment | ApiSuccessEmpty | ApiCreateProjectResults | ApiAiDashboardSummaryResponse['results'] | ApiAiGetDashboardSummaryResponse['results'] | ApiCatalogMetadataResults | ApiCatalogAnalyticsResults | ApiPromotionChangesResponse['results'] | ApiWarehouseTableFields['results'] | ApiTogglePinnedItem['results'] | ApiOrganizationMemberProfiles['results'] | ApiSqlChart['results'] | ApiCreateSqlChart['results'] | ApiUpdateSqlChart['results'] | ApiContentResponse['results'] | ApiChartContentResponse['results'] | ApiSqlRunnerJobStatusResponse['results'] | ApiSemanticLayerClientInfo['results'] | ApiSemanticViewerChartCreate['results'] | ApiSemanticViewerChartGet['results'] | ApiSemanticViewerChartUpdate['results'] | ApiCreateVirtualView['results'] | ApiGithubDbtWritePreview['results'] | ApiMetricsCatalog['results'] | ApiMetricsExplorerQueryResults['results'] | ApiGroupListResponse['results'] | ApiCreateTagResponse['results'] | ApiChartAsCodeListResponse['results'] | ApiChartAsCodeUpsertResponse['results'] | ApiGetMetricsTree['results'];
385
+ type ApiResults = ApiQueryResults | ApiSqlQueryResults | ApiCompiledQueryResults | ApiExploresResults | ApiExploreResults | ApiStatusResults | ApiRefreshResults | ApiHealthResults | Organization | LightdashUser | LoginOptions | SavedChart | SavedChart[] | Space[] | InviteLink | OrganizationProject[] | Project | WarehouseCredentials | OrganizationMemberProfile[] | ProjectCatalog | TablesConfiguration | Dashboard | DashboardBasicDetails[] | OnboardingStatus | Dashboard[] | DeleteOpenIdentity | ApiFlashResults | Record<OpenIdIdentitySummary['issuerType'], OpenIdIdentitySummary[]> | FilterableField[] | DashboardAvailableFilters | ProjectSavedChartStatus | null | Array<unknown> | ApiJobStartedResults | ApiCreateUserTokenResults | CreatePersonalAccessToken | PersonalAccessToken | ProjectMemberProfile[] | ProjectGroupAccess | SearchResults | Space | ShareUrl | SlackSettings | ApiSlackChannelsResponse['results'] | UserActivity | SchedulerAndTargets | SchedulerAndTargets[] | FieldValueSearchResult | ApiDownloadCsv | AllowedEmailDomains | UpdateAllowedEmailDomains | UserAllowedOrganization[] | EmailStatusExpiring | ApiScheduledDownloadCsv | PinnedItems | ViewStatistics | SchedulerWithLogs | ValidationResponse[] | ChartHistory | ChartVersion | Array<GitRepo> | PullRequestCreated | GitIntegrationConfiguration | UserWarehouseCredentials | ApiJobStatusResponse['results'] | ApiJobScheduledResponse['results'] | ApiSshKeyPairResponse['results'] | MostPopularAndRecentlyUpdated | ApiCalculateTotalResponse['results'] | Record<string, DbtExposure> | ApiCreateComment['results'] | ApiGetComments['results'] | ApiDeleteComment | ApiSuccessEmpty | ApiCreateProjectResults | ApiAiDashboardSummaryResponse['results'] | ApiAiGetDashboardSummaryResponse['results'] | ApiCatalogMetadataResults | ApiCatalogAnalyticsResults | ApiPromotionChangesResponse['results'] | ApiWarehouseTableFields['results'] | ApiTogglePinnedItem['results'] | ApiOrganizationMemberProfiles['results'] | ApiSqlChart['results'] | ApiCreateSqlChart['results'] | ApiUpdateSqlChart['results'] | ApiContentResponse['results'] | ApiChartContentResponse['results'] | ApiSqlRunnerJobStatusResponse['results'] | ApiSemanticLayerClientInfo['results'] | ApiSemanticViewerChartCreate['results'] | ApiSemanticViewerChartGet['results'] | ApiSemanticViewerChartUpdate['results'] | ApiCreateVirtualView['results'] | ApiGithubDbtWritePreview['results'] | ApiMetricsCatalog['results'] | ApiMetricsExplorerQueryResults['results'] | ApiGroupListResponse['results'] | ApiCreateTagResponse['results'] | ApiChartAsCodeListResponse['results'] | ApiChartAsCodeUpsertResponse['results'] | ApiGetMetricsTree['results'] | ApiMetricsExplorerTotalResults['results'];
386
386
  export type ApiResponse<T extends ApiResults = ApiResults> = {
387
387
  status: 'ok';
388
388
  results: T;
@@ -114,6 +114,7 @@ export type CatalogFieldMap = {
114
114
  fieldName: string;
115
115
  tableName: string;
116
116
  cachedExploreUuid: string;
117
+ fieldType: FieldType;
117
118
  };
118
119
  };
119
120
  export type CatalogItemSummary = Pick<CatalogItem, 'catalogSearchUuid' | 'name' | 'type'> & {
@@ -138,10 +139,35 @@ export type SchedulerIndexCatalogJobPayload = {
138
139
  prevCatalogItemsWithIcons: CatalogItemsWithIcons[];
139
140
  prevMetricTreeEdges: CatalogMetricsTreeEdge[];
140
141
  };
142
+ export type ChartFieldUpdates = {
143
+ oldChartFields: {
144
+ metrics: string[];
145
+ dimensions: string[];
146
+ };
147
+ newChartFields: {
148
+ metrics: string[];
149
+ dimensions: string[];
150
+ };
151
+ };
152
+ export type ChartFieldChanges = {
153
+ added: {
154
+ dimensions: string[];
155
+ metrics: string[];
156
+ };
157
+ removed: {
158
+ dimensions: string[];
159
+ metrics: string[];
160
+ };
161
+ };
141
162
  export type CatalogFieldWhere = {
142
163
  fieldName: string;
164
+ fieldType: FieldType;
143
165
  cachedExploreUuid: string;
144
166
  };
167
+ export type ChartFieldUsageChanges = {
168
+ fieldsToIncrement: CatalogFieldWhere[];
169
+ fieldsToDecrement: CatalogFieldWhere[];
170
+ };
145
171
  export type ChartUsageIn = CatalogFieldWhere & {
146
172
  chartUsage: number;
147
173
  };
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { type MetricWithAssociatedTimeDimension } from './catalog';
3
3
  import type { ItemsMap } from './field';
4
+ import type { ResultValue } from './results';
4
5
  export declare enum MetricExplorerComparison {
5
6
  NONE = "none",
6
7
  PREVIOUS_PERIOD = "previous_period",
@@ -52,3 +53,15 @@ export type ApiMetricsExplorerQueryResults = {
52
53
  status: 'ok';
53
54
  results: MetricsExplorerQueryResults;
54
55
  };
56
+ export declare enum MetricTotalComparisonType {
57
+ NONE = "none",
58
+ PREVIOUS_PERIOD = "previous_period"
59
+ }
60
+ export type MetricTotalResults = {
61
+ value: ResultValue | undefined;
62
+ comparisonValue: ResultValue | undefined;
63
+ };
64
+ export type ApiMetricsExplorerTotalResults = {
65
+ status: 'ok';
66
+ results: MetricTotalResults;
67
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.metricExploreDataPointWithDateValueSchema = exports.MetricExplorerComparison = void 0;
3
+ exports.MetricTotalComparisonType = exports.metricExploreDataPointWithDateValueSchema = exports.MetricExplorerComparison = void 0;
4
4
  const zod_1 = require("zod");
5
5
  var MetricExplorerComparison;
6
6
  (function (MetricExplorerComparison) {
@@ -16,3 +16,8 @@ const metricExploreDataPointSchema = zod_1.z.object({
16
16
  exports.metricExploreDataPointWithDateValueSchema = metricExploreDataPointSchema.extend({
17
17
  dateValue: zod_1.z.number(),
18
18
  });
19
+ var MetricTotalComparisonType;
20
+ (function (MetricTotalComparisonType) {
21
+ MetricTotalComparisonType["NONE"] = "none";
22
+ MetricTotalComparisonType["PREVIOUS_PERIOD"] = "previous_period";
23
+ })(MetricTotalComparisonType = exports.MetricTotalComparisonType || (exports.MetricTotalComparisonType = {}));
@@ -12,8 +12,10 @@ type ImpelemntedTimeframe = TimeFrames.DAY | TimeFrames.WEEK | TimeFrames.MONTH
12
12
  type UnimplementedTimeframe = Exclude<TimeFrames, ImpelemntedTimeframe>;
13
13
  export declare const assertUnimplementedTimeframe: (timeframe: UnimplementedTimeframe) => never;
14
14
  export declare const getFieldIdForDateDimension: (fieldId: string, timeframe: TimeFrames) => string;
15
- export declare const oneYearBack: (date: Date) => Date;
16
- export declare const oneYearForward: (date: Date) => Date;
15
+ export declare const getDateCalcUtils: (timeFrame: TimeFrames) => {
16
+ forward: (date: Date) => Date;
17
+ back: (date: Date) => Date;
18
+ };
17
19
  export declare const getGrainForDateRange: (dateRange: [Date, Date]) => ImpelemntedTimeframe;
18
20
  export declare const getMetricExplorerDateRangeFilters: (exploreName: string, dimensionName: string, dateRange: MetricExplorerDateRange) => DateFilter[];
19
21
  export declare const getMetricExplorerDataPoints: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[]) => Array<MetricExploreDataPoint>;
@@ -28,6 +30,7 @@ export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimensi
28
30
  * @returns The date range
29
31
  */
30
32
  export declare const getDefaultDateRangeFromInterval: (timeInterval: TimeFrames) => MetricExplorerDateRange;
33
+ export declare const getDefaultDateRangeForMetricTotal: (timeFrame: TimeFrames) => MetricExplorerDateRange;
31
34
  /**
32
35
  * Default time interval to use when no time interval is provided.
33
36
  * For example, when there is no default time dimension defined for a metric or table.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.oneYearForward = exports.oneYearBack = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
3
+ exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeForMetricTotal = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.getDateCalcUtils = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
6
6
  const lodash_1 = require("lodash");
@@ -52,14 +52,33 @@ const getFieldIdForDateDimension = (fieldId, timeframe) => {
52
52
  }
53
53
  };
54
54
  exports.getFieldIdForDateDimension = getFieldIdForDateDimension;
55
- const oneYearBack = (date) => (0, dayjs_1.default)(date)
56
- .set('year', (0, dayjs_1.default)(date).get('year') - 1)
57
- .toDate();
58
- exports.oneYearBack = oneYearBack;
59
- const oneYearForward = (date) => (0, dayjs_1.default)(date)
60
- .set('year', (0, dayjs_1.default)(date).get('year') + 1)
61
- .toDate();
62
- exports.oneYearForward = oneYearForward;
55
+ const getDateCalcUtils = (timeFrame) => {
56
+ switch (timeFrame) {
57
+ case timeFrames_1.TimeFrames.DAY:
58
+ return {
59
+ forward: (date) => (0, dayjs_1.default)(date).add(1, 'day').toDate(),
60
+ back: (date) => (0, dayjs_1.default)(date).subtract(1, 'day').toDate(),
61
+ };
62
+ case timeFrames_1.TimeFrames.WEEK:
63
+ return {
64
+ forward: (date) => (0, dayjs_1.default)(date).add(1, 'week').toDate(),
65
+ back: (date) => (0, dayjs_1.default)(date).subtract(1, 'week').toDate(),
66
+ };
67
+ case timeFrames_1.TimeFrames.MONTH:
68
+ return {
69
+ forward: (date) => (0, dayjs_1.default)(date).add(1, 'month').toDate(),
70
+ back: (date) => (0, dayjs_1.default)(date).subtract(1, 'month').toDate(),
71
+ };
72
+ case timeFrames_1.TimeFrames.YEAR:
73
+ return {
74
+ forward: (date) => (0, dayjs_1.default)(date).add(1, 'year').toDate(),
75
+ back: (date) => (0, dayjs_1.default)(date).subtract(1, 'year').toDate(),
76
+ };
77
+ default:
78
+ return (0, exports.assertUnimplementedTimeframe)(timeFrame);
79
+ }
80
+ };
81
+ exports.getDateCalcUtils = getDateCalcUtils;
63
82
  // TODO: refine the time grain for each time frame
64
83
  // Time grain Year: -> past 5 years (i.e. 5 completed years + this uncompleted year)
65
84
  // Time grain Month -> past 12 months (i.e. 12 completed months + this uncompleted month)
@@ -126,7 +145,9 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
126
145
  const groupByMetricRows = (0, lodash_1.groupBy)(metricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
127
146
  const groupByCompareMetricRows = (0, lodash_1.groupBy)(compareMetricRows, (row) => new Date(String(row[compareDimensionId].value.raw)).toISOString());
128
147
  const offsetGroupByCompareMetricRows = (0, lodash_1.mapKeys)(groupByCompareMetricRows, (_, date) => comparison.type === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD
129
- ? (0, exports.oneYearForward)(new Date(date)).toISOString()
148
+ ? (0, exports.getDateCalcUtils)(timeFrames_1.TimeFrames.YEAR)
149
+ .back(new Date(date))
150
+ .toISOString()
130
151
  : date);
131
152
  const dates = new Set([
132
153
  ...Object.keys(groupByMetricRows),
@@ -183,6 +204,22 @@ const getDefaultDateRangeFromInterval = (timeInterval) => {
183
204
  }
184
205
  };
185
206
  exports.getDefaultDateRangeFromInterval = getDefaultDateRangeFromInterval;
207
+ const getDefaultDateRangeForMetricTotal = (timeFrame) => {
208
+ const now = (0, dayjs_1.default)();
209
+ switch (timeFrame) {
210
+ case timeFrames_1.TimeFrames.DAY:
211
+ return [now.startOf('day').toDate(), now.endOf('day').toDate()];
212
+ case timeFrames_1.TimeFrames.WEEK:
213
+ return [now.startOf('week').toDate(), now.endOf('week').toDate()];
214
+ case timeFrames_1.TimeFrames.MONTH:
215
+ return [now.startOf('month').toDate(), now.endOf('month').toDate()];
216
+ case timeFrames_1.TimeFrames.YEAR:
217
+ return [now.startOf('year').toDate(), now.endOf('year').toDate()];
218
+ default:
219
+ return (0, exports.assertUnimplementedTimeframe)(timeFrame);
220
+ }
221
+ };
222
+ exports.getDefaultDateRangeForMetricTotal = getDefaultDateRangeForMetricTotal;
186
223
  /**
187
224
  * Default time interval to use when no time interval is provided.
188
225
  * For example, when there is no default time dimension defined for a metric or table.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/common",
3
- "version": "0.1406.0",
3
+ "version": "0.1407.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [