@lightdash/query-sdk 0.2753.0 → 0.2755.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.
@@ -13,7 +13,7 @@ import type { Column, LightdashClientConfig, Transport } from './types';
13
13
  * The default implementation uses `Authorization: ApiKey` header.
14
14
  * Supply a custom adapter to use session cookies or other auth mechanisms.
15
15
  */
16
- export type FetchAdapter = <T>(method: string, path: string, body?: unknown) => Promise<T>;
16
+ export type FetchAdapter = <T>(method: string, path: string, body?: unknown, metadata?: Record<string, unknown>) => Promise<T>;
17
17
  export declare function mapColumnType(type: string): Column['type'];
18
18
  /**
19
19
  * Creates a transport that executes queries via the Lightdash REST API.
@@ -112,7 +112,12 @@ export function createApiTransport(config, adapter) {
112
112
  tableCalculations: [],
113
113
  },
114
114
  };
115
- const execResult = await fetchFn('POST', `/api/v2/projects/${config.projectUuid}/query/metric-query`, body);
115
+ // Pass label as transport metadata (not in the API body)
116
+ // so the parent bridge can display it in the query inspector.
117
+ const metadata = query.label
118
+ ? { label: query.label }
119
+ : undefined;
120
+ const execResult = await fetchFn('POST', `/api/v2/projects/${config.projectUuid}/query/metric-query`, body, metadata);
116
121
  const { queryUuid, fields } = execResult;
117
122
  // Step 2: Poll for results
118
123
  let attempts = 0;
@@ -15,6 +15,8 @@ export type SdkFetchRequest = {
15
15
  method: string;
16
16
  path: string;
17
17
  body?: unknown;
18
+ /** Transport metadata for dev tools (not sent to the API) */
19
+ metadata?: Record<string, unknown>;
18
20
  };
19
21
  export type SdkFetchResponse = {
20
22
  type: 'lightdash:sdk:fetch-response';
@@ -51,7 +51,7 @@ function createPostMessageFetchAdapter(config) {
51
51
  }
52
52
  }
53
53
  });
54
- return async (method, path, body) => {
54
+ return async (method, path, body, metadata) => {
55
55
  await readyPromise;
56
56
  const id = crypto.randomUUID();
57
57
  return new Promise((resolve, reject) => {
@@ -70,6 +70,7 @@ function createPostMessageFetchAdapter(config) {
70
70
  method,
71
71
  path,
72
72
  body,
73
+ ...(metadata ? { metadata } : {}),
73
74
  };
74
75
  targetWindow.postMessage(message, '*');
75
76
  });
package/dist/query.d.ts CHANGED
@@ -29,10 +29,13 @@ export declare class QueryBuilder {
29
29
  private readonly _filters;
30
30
  private readonly _sorts;
31
31
  private readonly _limit;
32
+ private readonly _label;
32
33
  constructor(explore: string, dimensions?: string[], metrics?: string[], filters?: InternalFilterDefinition[], sorts?: {
33
34
  fieldId: string;
34
35
  descending: boolean;
35
- }[], limit?: number);
36
+ }[], limit?: number, label?: string);
37
+ /** Human-readable label for dev tools / query inspector */
38
+ label(name: string): QueryBuilder;
36
39
  /** Set dimension fields (GROUP BY columns) */
37
40
  dimensions(fields: string[]): QueryBuilder;
38
41
  /** Set metric fields (aggregations) */
package/dist/query.js CHANGED
@@ -24,21 +24,26 @@ export function query(modelName) {
24
24
  return new QueryBuilder(modelName);
25
25
  }
26
26
  export class QueryBuilder {
27
- constructor(explore, dimensions = [], metrics = [], filters = [], sorts = [], limit = 500) {
27
+ constructor(explore, dimensions = [], metrics = [], filters = [], sorts = [], limit = 500, label) {
28
28
  this._explore = explore;
29
29
  this._dimensions = dimensions;
30
30
  this._metrics = metrics;
31
31
  this._filters = filters;
32
32
  this._sorts = sorts;
33
33
  this._limit = limit;
34
+ this._label = label;
35
+ }
36
+ /** Human-readable label for dev tools / query inspector */
37
+ label(name) {
38
+ return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, this._limit, name);
34
39
  }
35
40
  /** Set dimension fields (GROUP BY columns) */
36
41
  dimensions(fields) {
37
- return new QueryBuilder(this._explore, [...this._dimensions, ...fields], this._metrics, this._filters, this._sorts, this._limit);
42
+ return new QueryBuilder(this._explore, [...this._dimensions, ...fields], this._metrics, this._filters, this._sorts, this._limit, this._label);
38
43
  }
39
44
  /** Set metric fields (aggregations) */
40
45
  metrics(fields) {
41
- return new QueryBuilder(this._explore, this._dimensions, [...this._metrics, ...fields], this._filters, this._sorts, this._limit);
46
+ return new QueryBuilder(this._explore, this._dimensions, [...this._metrics, ...fields], this._filters, this._sorts, this._limit, this._label);
42
47
  }
43
48
  /** Add filters */
44
49
  filters(filters) {
@@ -59,7 +64,7 @@ export class QueryBuilder {
59
64
  settings: f.unit ? { unitOfTime: f.unit } : null,
60
65
  };
61
66
  });
62
- return new QueryBuilder(this._explore, this._dimensions, this._metrics, [...this._filters, ...converted], this._sorts, this._limit);
67
+ return new QueryBuilder(this._explore, this._dimensions, this._metrics, [...this._filters, ...converted], this._sorts, this._limit, this._label);
63
68
  }
64
69
  /** Add sorts */
65
70
  sorts(sorts) {
@@ -67,11 +72,11 @@ export class QueryBuilder {
67
72
  fieldId: s.field,
68
73
  descending: s.direction === 'desc',
69
74
  }));
70
- return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, [...this._sorts, ...converted], this._limit);
75
+ return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, [...this._sorts, ...converted], this._limit, this._label);
71
76
  }
72
77
  /** Set the maximum number of rows to return (default: 500) */
73
78
  limit(n) {
74
- return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, n);
79
+ return new QueryBuilder(this._explore, this._dimensions, this._metrics, this._filters, this._sorts, n, this._label);
75
80
  }
76
81
  /** Convert to a plain QueryDefinition object */
77
82
  build() {
@@ -82,6 +87,7 @@ export class QueryBuilder {
82
87
  filters: this._filters,
83
88
  sorts: this._sorts,
84
89
  limit: this._limit,
90
+ ...(this._label ? { label: this._label } : {}),
85
91
  };
86
92
  }
87
93
  }
package/dist/types.d.ts CHANGED
@@ -32,6 +32,8 @@ export type QueryDefinition = {
32
32
  descending: boolean;
33
33
  }[];
34
34
  limit: number;
35
+ /** Human-readable label for dev tools / query inspector (not sent to the API) */
36
+ label?: string;
35
37
  };
36
38
  export type ColumnType = 'string' | 'number' | 'date' | 'timestamp' | 'boolean';
37
39
  export type Column = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/query-sdk",
3
- "version": "0.2753.0",
3
+ "version": "0.2755.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "SDK for building custom data apps against the Lightdash semantic layer",