@lightdash/query-sdk 1.202.0 → 1.202.2

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/features.js CHANGED
@@ -71,6 +71,12 @@ export const SDK_FEATURES = [
71
71
  description: "Let viewers adjust the visualization from the Lightdash config panel — toggles, dropdowns, numbers, text and colours — and take series colours from the chart's palette, without regenerating the app.",
72
72
  wiring: 'Declare configOptions (and colorPalette, if the viz colours series) in the viz schema, then read options[name] and colorPalette from useVizContext().',
73
73
  },
74
+ {
75
+ key: 'viz-pivoted-results',
76
+ label: 'Pivoted results',
77
+ description: 'Render reusable charts and tables from backend-pivoted rows and their complete layout metadata.',
78
+ wiring: 'When useVizContext().pivotDetails is non-null, use valuesColumns to resolve generated row keys and use indexColumn, groupByColumns, originalColumns, sortBy, totalColumnCount, and passthroughDimensions when the visualization needs their layout semantics. Keep the existing fieldMapping path when pivotDetails is null.',
79
+ },
74
80
  {
75
81
  key: 'follow-host-theme',
76
82
  label: 'Follow the host light/dark mode',
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.202.0";
1
+ export declare const SDK_VERSION = "1.202.2";
@@ -1,2 +1,2 @@
1
1
  // Generated by scripts/generateSdkVersion.mjs (prebuild) — do not edit.
2
- export const SDK_VERSION = '1.202.0';
2
+ export const SDK_VERSION = '1.202.2';
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { LightdashProvider, useLightdashClient } from './LightdashProvider';
7
7
  export { createApiTransport, type FetchAdapter } from './apiTransport';
8
8
  export { createPostMessageTransport } from './postMessageTransport';
9
9
  export { SDK_FEATURES, SDK_FEATURE_KEYS, SDK_MANIFEST_MESSAGE_TYPE, type SdkFeature, type SdkManifestMessage, } from './features';
10
- export type { AdditionalMetric, Column, CustomDimension, DownloadResultsFileType, DownloadResultsLimit, DownloadResultsOptions, DownloadResultsResult, DownloadResultsValues, DownloadUnderlyingDataOptions, ExternalFetchMethod, ExternalFetchOptions, ExternalFetchResult, Filter, FilterOperator, FilterValue, FormatFunction, LightdashClientConfig, LightdashUser, MetricType, QueryDefinition, QueryResult, Row, Sort, TableCalculation, Transport, UnitOfTime, UnderlyingDataOptions, UnderlyingDataResult, } from './types';
10
+ export type { AdditionalMetric, Column, ColumnType, CustomDimension, DownloadResultsFileType, DownloadResultsLimit, DownloadResultsOptions, DownloadResultsResult, DownloadResultsValues, DownloadUnderlyingDataOptions, ExternalFetchMethod, ExternalFetchOptions, ExternalFetchResult, Filter, FilterOperator, FilterValue, FormatFunction, LightdashClientConfig, LightdashUser, MetricType, QueryDefinition, QueryResult, Row, Sort, TableCalculation, Transport, UnitOfTime, UnderlyingDataOptions, UnderlyingDataResult, } from './types';
11
11
  export type { SdkExternalFetchRequest, SdkExternalFetchResponse, SdkFetchRequest, SdkFetchResponse, SdkReadyMessage, SdkScreenshotAvailableMessage, SdkScreenshotRequest, SdkScreenshotResponse, SdkGsheetExportRequest, SdkGsheetExportResponse, SdkGsheetExportColumn, SdkGsheetExportColumnType, SdkGsheetExportRow, } from './postMessageTransport';
12
12
  export type { InspectAvailableMessage, InspectSelectedMessage, } from './inspector';
13
13
  export { useDelivery } from './delivery';
@@ -15,7 +15,7 @@ export type { DeliveryQuery } from './delivery';
15
15
  export { exportToSheets } from './exportToSheets';
16
16
  export type { ExportToSheetsOptions, ExportToSheetsResult, } from './exportToSheets';
17
17
  export { VizContextProvider, useVizContext, getFormatted, getRaw, } from './vizContext';
18
- export type { VizContext, VizContextCell, VizContextOptionValue, VizContextRow, VizUnderlyingData, DataAppVizContextMessage, VizContextRequestMessage, } from './vizContext';
18
+ export type { VizContext, VizContextCell, VizContextOptionValue, VizContextPivotDetails, VizContextRow, VizUnderlyingData, DataAppVizContextMessage, VizContextRequestMessage, } from './vizContext';
19
19
  export { useColorScheme } from './colorScheme';
20
20
  export type { HostColorScheme, HostColorSchemeMessage, HostColorSchemeRequestMessage, } from './colorScheme';
21
21
  export { isDeliveryRender, useDeliveryRender } from './deliveryRender';
@@ -14,7 +14,7 @@
14
14
  * host's reply therefore can't be missed. No timers, no races.
15
15
  */
16
16
  import { type ReactNode } from 'react';
17
- import type { DownloadResultsOptions, DownloadResultsResult, Transport, UnderlyingDataResult } from './types';
17
+ import type { ColumnType, DownloadResultsOptions, DownloadResultsResult, Transport, UnderlyingDataResult } from './types';
18
18
  /** A single cell of a Lightdash result row: `{ value: { raw, formatted } }`. */
19
19
  export type VizContextCell = {
20
20
  value?: {
@@ -30,6 +30,51 @@ export type VizContextRow = Record<string, VizContextCell | undefined>;
30
30
  * Series colours are not an option — they arrive on `colorPalette`.
31
31
  */
32
32
  export type VizContextOptionValue = boolean | number | string;
33
+ /**
34
+ * The host's complete backend-pivot layout metadata. This is a structural
35
+ * mirror because query-sdk is published without a dependency on
36
+ * `@lightdash/common`.
37
+ */
38
+ export type VizContextPivotDetails = {
39
+ totalColumnCount: number | null;
40
+ indexColumn: {
41
+ reference: string;
42
+ type: 'time' | 'category';
43
+ } | {
44
+ reference: string;
45
+ type: 'time' | 'category';
46
+ }[] | undefined;
47
+ valuesColumns: {
48
+ referenceField: string;
49
+ pivotColumnName: string;
50
+ aggregation: string;
51
+ pivotValues: {
52
+ referenceField: string;
53
+ value: unknown;
54
+ formatted?: string;
55
+ }[];
56
+ columnIndex?: number;
57
+ }[];
58
+ groupByColumns: {
59
+ reference: string;
60
+ }[] | undefined;
61
+ sortBy: {
62
+ reference: string;
63
+ direction: 'ASC' | 'DESC';
64
+ nullsFirst?: boolean;
65
+ pivotValues?: {
66
+ reference: string;
67
+ value: string | number | boolean | null;
68
+ }[];
69
+ }[] | undefined;
70
+ originalColumns: Record<string, {
71
+ reference: string;
72
+ type: ColumnType;
73
+ }>;
74
+ passthroughDimensions?: {
75
+ reference: string;
76
+ }[];
77
+ };
33
78
  /**
34
79
  * Pushed by the host into the iframe. `fieldMapping` maps each field name the
35
80
  * renderer declared to the query field id it resolves to; `rows` are the
@@ -46,6 +91,8 @@ export type DataAppVizContextMessage = {
46
91
  options?: Record<string, VizContextOptionValue>;
47
92
  /** Absent when the installed host predates palette delivery. */
48
93
  colorPalette?: string[];
94
+ /** Null for unpivoted rows; absent when the installed host predates pivot metadata delivery. */
95
+ pivotDetails?: VizContextPivotDetails | null;
49
96
  /** Absent when the installed host predates underlying-data delivery. */
50
97
  underlyingData?: {
51
98
  enabled?: boolean;
@@ -92,6 +139,8 @@ export type VizContext = {
92
139
  * resolved no palette; keep a fallback array in your own code for that.
93
140
  */
94
141
  colorPalette: string[];
142
+ /** Metadata that maps generated pivot column names back to their metric and series values. */
143
+ pivotDetails: VizContextPivotDetails | null;
95
144
  /** False until the first context arrives — render a placeholder while false. */
96
145
  ready: boolean;
97
146
  /** Fetch/export the raw rows behind a clicked data point via the host. */
@@ -102,14 +151,13 @@ type VizContextValue = {
102
151
  rows: VizContextRow[];
103
152
  options: Record<string, VizContextOptionValue>;
104
153
  colorPalette: string[];
154
+ pivotDetails: VizContextPivotDetails | null;
105
155
  underlyingDataEnabled: boolean;
106
156
  };
107
157
  type VizContextState = VizContextValue | null;
108
158
  /**
109
- * Normalises an inbound host message into provider state. The payload crosses a
110
- * postMessage boundary so every key is treated as untrusted; `options` and
111
- * `colorPalette` are also absent from hosts predating them, and fall back to
112
- * `{}` / `[]`.
159
+ * Normalises an inbound host message into provider state. Optional capabilities
160
+ * are absent from hosts predating them and receive stable fallback values.
113
161
  */
114
162
  export declare function toVizContextState(message: DataAppVizContextMessage): VizContextValue;
115
163
  /**
@@ -41,10 +41,8 @@ const normalizeOptions = (options) => {
41
41
  return Object.fromEntries(Object.entries(options).filter((entry) => isVizContextOptionValue(entry[1])));
42
42
  };
43
43
  /**
44
- * Normalises an inbound host message into provider state. The payload crosses a
45
- * postMessage boundary so every key is treated as untrusted; `options` and
46
- * `colorPalette` are also absent from hosts predating them, and fall back to
47
- * `{}` / `[]`.
44
+ * Normalises an inbound host message into provider state. Optional capabilities
45
+ * are absent from hosts predating them and receive stable fallback values.
48
46
  */
49
47
  export function toVizContextState(message) {
50
48
  return {
@@ -54,6 +52,7 @@ export function toVizContextState(message) {
54
52
  colorPalette: Array.isArray(message.colorPalette)
55
53
  ? message.colorPalette.filter((color) => typeof color === 'string')
56
54
  : [],
55
+ pivotDetails: message.pivotDetails ?? null,
57
56
  // Strict boolean check — non-boolean payloads read as disabled.
58
57
  underlyingDataEnabled: message.underlyingData?.enabled === true,
59
58
  };
@@ -158,6 +157,7 @@ export function useVizContext() {
158
157
  rows: context?.rows ?? [],
159
158
  options: context?.options ?? {},
160
159
  colorPalette: context?.colorPalette ?? [],
160
+ pivotDetails: context?.pivotDetails ?? null,
161
161
  ready: context !== null,
162
162
  underlyingData,
163
163
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/query-sdk",
3
- "version": "1.202.0",
3
+ "version": "1.202.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SDK for building custom data apps against the Lightdash semantic layer",
@@ -34,7 +34,7 @@
34
34
  "jsdom": "26.1.0",
35
35
  "typescript": "7.0.2",
36
36
  "vitest": "4.1.6",
37
- "@lightdash/common": "1.202.0"
37
+ "@lightdash/common": "1.202.2"
38
38
  },
39
39
  "scripts": {
40
40
  "prebuild": "node ./scripts/generateSdkVersion.mjs",