@lightdash-tools/client 0.19.0 → 0.20.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.
- package/dist/api/v1/sql-runner.d.ts +13 -0
- package/dist/api/v1/sql-runner.js +18 -0
- package/dist/api/v1/sql-runner.test.d.ts +1 -0
- package/dist/api/v1/sql-runner.test.js +53 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/package.json +2 -2
- package/src/api/v1/sql-runner.test.ts +61 -0
- package/src/api/v1/sql-runner.ts +26 -0
- package/src/client.ts +3 -0
- package/src/index.ts +2 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Runner API client. Endpoints for saved SQL charts (metadata + authored SQL body).
|
|
3
|
+
*/
|
|
4
|
+
import { BaseApiClient } from '../base-client';
|
|
5
|
+
import type { components } from '@lightdash-tools/common';
|
|
6
|
+
/** Saved SQL chart including authored `sql` body. */
|
|
7
|
+
export type SqlChart = components['schemas']['SqlChart'];
|
|
8
|
+
export declare class SqlRunnerClient extends BaseApiClient {
|
|
9
|
+
/** Get a saved SQL chart by UUID within a project (includes authored SQL). */
|
|
10
|
+
getSavedSqlChart(projectUuid: string, uuid: string): Promise<SqlChart>;
|
|
11
|
+
/** Get a saved SQL chart by slug within a project (includes authored SQL). */
|
|
12
|
+
getSavedSqlChartBySlug(projectUuid: string, slug: string): Promise<SqlChart>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SQL Runner API client. Endpoints for saved SQL charts (metadata + authored SQL body).
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SqlRunnerClient = void 0;
|
|
7
|
+
const base_client_1 = require("../base-client");
|
|
8
|
+
class SqlRunnerClient extends base_client_1.BaseApiClient {
|
|
9
|
+
/** Get a saved SQL chart by UUID within a project (includes authored SQL). */
|
|
10
|
+
async getSavedSqlChart(projectUuid, uuid) {
|
|
11
|
+
return this.http.get(`/projects/${projectUuid}/sqlRunner/saved/${encodeURIComponent(uuid)}`);
|
|
12
|
+
}
|
|
13
|
+
/** Get a saved SQL chart by slug within a project (includes authored SQL). */
|
|
14
|
+
async getSavedSqlChartBySlug(projectUuid, slug) {
|
|
15
|
+
return this.http.get(`/projects/${projectUuid}/sqlRunner/saved/slug/${encodeURIComponent(slug)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.SqlRunnerClient = SqlRunnerClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const sql_runner_js_1 = require("./sql-runner.js");
|
|
5
|
+
(0, vitest_1.describe)('SqlRunnerClient', () => {
|
|
6
|
+
let mockHttp;
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
mockHttp = {
|
|
9
|
+
get: vitest_1.vi.fn(),
|
|
10
|
+
post: vitest_1.vi.fn(),
|
|
11
|
+
put: vitest_1.vi.fn(),
|
|
12
|
+
patch: vitest_1.vi.fn(),
|
|
13
|
+
delete: vitest_1.vi.fn(),
|
|
14
|
+
getBytes: vitest_1.vi.fn(),
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('getSavedSqlChart should call GET /projects/{projectUuid}/sqlRunner/saved/{uuid}', async () => {
|
|
18
|
+
const client = new sql_runner_js_1.SqlRunnerClient(mockHttp);
|
|
19
|
+
const chart = {
|
|
20
|
+
savedSqlUuid: 'sql-1',
|
|
21
|
+
name: 'Orders SQL',
|
|
22
|
+
slug: 'orders-sql',
|
|
23
|
+
sql: 'SELECT 1',
|
|
24
|
+
limit: 500,
|
|
25
|
+
};
|
|
26
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
27
|
+
const result = await client.getSavedSqlChart('p1', 'sql-1');
|
|
28
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/sql-1');
|
|
29
|
+
(0, vitest_1.expect)(result).toEqual(chart);
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.it)('getSavedSqlChartBySlug should call GET …/sqlRunner/saved/slug/{slug}', async () => {
|
|
32
|
+
const client = new sql_runner_js_1.SqlRunnerClient(mockHttp);
|
|
33
|
+
const chart = {
|
|
34
|
+
savedSqlUuid: 'sql-1',
|
|
35
|
+
name: 'Orders SQL',
|
|
36
|
+
slug: 'orders-sql',
|
|
37
|
+
sql: 'SELECT 1',
|
|
38
|
+
limit: 500,
|
|
39
|
+
};
|
|
40
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
41
|
+
const result = await client.getSavedSqlChartBySlug('p1', 'orders-sql');
|
|
42
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/slug/orders-sql');
|
|
43
|
+
(0, vitest_1.expect)(result).toEqual(chart);
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('encodes uuid and slug path segments', async () => {
|
|
46
|
+
const client = new sql_runner_js_1.SqlRunnerClient(mockHttp);
|
|
47
|
+
vitest_1.vi.mocked(mockHttp.get).mockResolvedValue({});
|
|
48
|
+
await client.getSavedSqlChart('p1', 'a/b');
|
|
49
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/a%2Fb');
|
|
50
|
+
await client.getSavedSqlChartBySlug('p1', 'slug/with spaces');
|
|
51
|
+
(0, vitest_1.expect)(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/slug/slug%2Fwith%20spaces');
|
|
52
|
+
});
|
|
53
|
+
});
|
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { ProjectsClient } from './api/v1/projects';
|
|
|
14
14
|
import { QueryClient } from './api/v1/query';
|
|
15
15
|
import { SchedulersClient } from './api/v1/schedulers';
|
|
16
16
|
import { SpacesClient } from './api/v1/spaces';
|
|
17
|
+
import { SqlRunnerClient } from './api/v1/sql-runner';
|
|
17
18
|
import { TagsClient } from './api/v1/tags';
|
|
18
19
|
import { UsersClient } from './api/v1/users';
|
|
19
20
|
import { ValidationClient } from './api/v1/validation';
|
|
@@ -47,6 +48,7 @@ export declare class V1ApiClients {
|
|
|
47
48
|
readonly schedulers: SchedulersClient;
|
|
48
49
|
readonly tags: TagsClient;
|
|
49
50
|
readonly analytics: AnalyticsClient;
|
|
51
|
+
readonly sqlRunner: SqlRunnerClient;
|
|
50
52
|
constructor(http: HttpClient);
|
|
51
53
|
}
|
|
52
54
|
/**
|
package/dist/client.js
CHANGED
|
@@ -17,6 +17,7 @@ const projects_1 = require("./api/v1/projects");
|
|
|
17
17
|
const query_1 = require("./api/v1/query");
|
|
18
18
|
const schedulers_1 = require("./api/v1/schedulers");
|
|
19
19
|
const spaces_1 = require("./api/v1/spaces");
|
|
20
|
+
const sql_runner_1 = require("./api/v1/sql-runner");
|
|
20
21
|
const tags_1 = require("./api/v1/tags");
|
|
21
22
|
const users_1 = require("./api/v1/users");
|
|
22
23
|
const validation_1 = require("./api/v1/validation");
|
|
@@ -53,6 +54,7 @@ class V1ApiClients {
|
|
|
53
54
|
this.schedulers = new schedulers_1.SchedulersClient(http);
|
|
54
55
|
this.tags = new tags_1.TagsClient(http);
|
|
55
56
|
this.analytics = new analytics_1.AnalyticsClient(http);
|
|
57
|
+
this.sqlRunner = new sql_runner_1.SqlRunnerClient(http);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
exports.V1ApiClients = V1ApiClients;
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export { MetricsClient } from './api/v1/metrics';
|
|
|
12
12
|
export { SchedulersClient } from './api/v1/schedulers';
|
|
13
13
|
export { TagsClient } from './api/v1/tags';
|
|
14
14
|
export { AnalyticsClient } from './api/v1/analytics';
|
|
15
|
+
export { SqlRunnerClient } from './api/v1/sql-runner';
|
|
16
|
+
export type { SqlChart } from './api/v1/sql-runner';
|
|
15
17
|
export { ContentClient } from './api/v2/content';
|
|
16
18
|
export { ChartsClientV2 } from './api/v2/charts';
|
|
17
19
|
export { DashboardsClientV2 } from './api/v2/dashboards';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SecretString = exports.RateLimiter = exports.isApiSuccessEnvelope = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.isBlockedBinaryHostname = exports.DEFAULT_BINARY_MAX_BYTES = exports.CHART_IMAGE_MAX_BYTES = exports.CHART_IMAGE_EXPORT_TIMEOUT_MS = exports.CONTRACT_ERROR_MESSAGE = exports.CONTRACT_ERROR_NAME = exports.ChartImageSizeError = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ChartsClientV2 = exports.ContentClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
|
|
3
|
+
exports.SecretString = exports.RateLimiter = exports.isApiSuccessEnvelope = exports.HttpClient = exports.ENV_LIGHTDASH_PROXY_AUTHORIZATION = exports.ENV_LIGHTDASH_URL = exports.ENV_LIGHTDASH_API_KEY = exports.createBearerConfig = exports.mergeConfig = exports.loadConfigFromEnv = exports.isBlockedBinaryHostname = exports.DEFAULT_BINARY_MAX_BYTES = exports.CHART_IMAGE_MAX_BYTES = exports.CHART_IMAGE_EXPORT_TIMEOUT_MS = exports.CONTRACT_ERROR_MESSAGE = exports.CONTRACT_ERROR_NAME = exports.ChartImageSizeError = exports.NetworkError = exports.RateLimitError = exports.LightdashApiError = exports.DEFAULT_RETRY = exports.DEFAULT_TIMEOUT = exports.DEFAULT_RATE_LIMIT = exports.consoleLogger = exports.noopLogger = exports.DashboardsClientV2 = exports.ChartsClientV2 = exports.ContentClient = exports.SqlRunnerClient = exports.AnalyticsClient = exports.TagsClient = exports.SchedulersClient = exports.MetricsClient = exports.ValidationClientV2 = exports.ValidationClient = exports.ProjectAccessClient = exports.AiAgentsClient = exports.ProjectRoleAssignmentsClient = exports.OrganizationRolesClient = exports.GroupsClient = exports.UsersClient = exports.resolveEvaluationRun = exports.applyBundleDiff = exports.fetchBundleCurrentState = exports.V2ApiClients = exports.V1ApiClients = exports.LightdashClient = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "LightdashClient", { enumerable: true, get: function () { return client_1.LightdashClient; } });
|
|
6
6
|
Object.defineProperty(exports, "V1ApiClients", { enumerable: true, get: function () { return client_1.V1ApiClients; } });
|
|
@@ -33,6 +33,8 @@ var tags_1 = require("./api/v1/tags");
|
|
|
33
33
|
Object.defineProperty(exports, "TagsClient", { enumerable: true, get: function () { return tags_1.TagsClient; } });
|
|
34
34
|
var analytics_1 = require("./api/v1/analytics");
|
|
35
35
|
Object.defineProperty(exports, "AnalyticsClient", { enumerable: true, get: function () { return analytics_1.AnalyticsClient; } });
|
|
36
|
+
var sql_runner_1 = require("./api/v1/sql-runner");
|
|
37
|
+
Object.defineProperty(exports, "SqlRunnerClient", { enumerable: true, get: function () { return sql_runner_1.SqlRunnerClient; } });
|
|
36
38
|
var content_1 = require("./api/v2/content");
|
|
37
39
|
Object.defineProperty(exports, "ContentClient", { enumerable: true, get: function () { return content_1.ContentClient; } });
|
|
38
40
|
var charts_1 = require("./api/v2/charts");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Client library for Lightdash AI.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"axios": "^1.19.0",
|
|
17
17
|
"bottleneck": "^2.19.5",
|
|
18
|
-
"@lightdash-tools/common": "0.
|
|
18
|
+
"@lightdash-tools/common": "0.20.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^25.9.3"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { SqlRunnerClient } from './sql-runner.js';
|
|
4
|
+
|
|
5
|
+
import type { HttpClient } from '../../http/http-client';
|
|
6
|
+
|
|
7
|
+
describe('SqlRunnerClient', () => {
|
|
8
|
+
let mockHttp: HttpClient;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockHttp = {
|
|
12
|
+
get: vi.fn(),
|
|
13
|
+
post: vi.fn(),
|
|
14
|
+
put: vi.fn(),
|
|
15
|
+
patch: vi.fn(),
|
|
16
|
+
delete: vi.fn(),
|
|
17
|
+
getBytes: vi.fn(),
|
|
18
|
+
} as unknown as HttpClient;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('getSavedSqlChart should call GET /projects/{projectUuid}/sqlRunner/saved/{uuid}', async () => {
|
|
22
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
23
|
+
const chart = {
|
|
24
|
+
savedSqlUuid: 'sql-1',
|
|
25
|
+
name: 'Orders SQL',
|
|
26
|
+
slug: 'orders-sql',
|
|
27
|
+
sql: 'SELECT 1',
|
|
28
|
+
limit: 500,
|
|
29
|
+
};
|
|
30
|
+
vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
31
|
+
const result = await client.getSavedSqlChart('p1', 'sql-1');
|
|
32
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/sql-1');
|
|
33
|
+
expect(result).toEqual(chart);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('getSavedSqlChartBySlug should call GET …/sqlRunner/saved/slug/{slug}', async () => {
|
|
37
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
38
|
+
const chart = {
|
|
39
|
+
savedSqlUuid: 'sql-1',
|
|
40
|
+
name: 'Orders SQL',
|
|
41
|
+
slug: 'orders-sql',
|
|
42
|
+
sql: 'SELECT 1',
|
|
43
|
+
limit: 500,
|
|
44
|
+
};
|
|
45
|
+
vi.mocked(mockHttp.get).mockResolvedValue(chart);
|
|
46
|
+
const result = await client.getSavedSqlChartBySlug('p1', 'orders-sql');
|
|
47
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/slug/orders-sql');
|
|
48
|
+
expect(result).toEqual(chart);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('encodes uuid and slug path segments', async () => {
|
|
52
|
+
const client = new SqlRunnerClient(mockHttp);
|
|
53
|
+
vi.mocked(mockHttp.get).mockResolvedValue({});
|
|
54
|
+
await client.getSavedSqlChart('p1', 'a/b');
|
|
55
|
+
expect(mockHttp.get).toHaveBeenCalledWith('/projects/p1/sqlRunner/saved/a%2Fb');
|
|
56
|
+
await client.getSavedSqlChartBySlug('p1', 'slug/with spaces');
|
|
57
|
+
expect(mockHttp.get).toHaveBeenCalledWith(
|
|
58
|
+
'/projects/p1/sqlRunner/saved/slug/slug%2Fwith%20spaces',
|
|
59
|
+
);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQL Runner API client. Endpoints for saved SQL charts (metadata + authored SQL body).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { BaseApiClient } from '../base-client';
|
|
6
|
+
|
|
7
|
+
import type { components } from '@lightdash-tools/common';
|
|
8
|
+
|
|
9
|
+
/** Saved SQL chart including authored `sql` body. */
|
|
10
|
+
export type SqlChart = components['schemas']['SqlChart'];
|
|
11
|
+
|
|
12
|
+
export class SqlRunnerClient extends BaseApiClient {
|
|
13
|
+
/** Get a saved SQL chart by UUID within a project (includes authored SQL). */
|
|
14
|
+
async getSavedSqlChart(projectUuid: string, uuid: string): Promise<SqlChart> {
|
|
15
|
+
return this.http.get<SqlChart>(
|
|
16
|
+
`/projects/${projectUuid}/sqlRunner/saved/${encodeURIComponent(uuid)}`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Get a saved SQL chart by slug within a project (includes authored SQL). */
|
|
21
|
+
async getSavedSqlChartBySlug(projectUuid: string, slug: string): Promise<SqlChart> {
|
|
22
|
+
return this.http.get<SqlChart>(
|
|
23
|
+
`/projects/${projectUuid}/sqlRunner/saved/slug/${encodeURIComponent(slug)}`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { ProjectsClient } from './api/v1/projects';
|
|
|
15
15
|
import { QueryClient } from './api/v1/query';
|
|
16
16
|
import { SchedulersClient } from './api/v1/schedulers';
|
|
17
17
|
import { SpacesClient } from './api/v1/spaces';
|
|
18
|
+
import { SqlRunnerClient } from './api/v1/sql-runner';
|
|
18
19
|
import { TagsClient } from './api/v1/tags';
|
|
19
20
|
import { UsersClient } from './api/v1/users';
|
|
20
21
|
import { ValidationClient } from './api/v1/validation';
|
|
@@ -53,6 +54,7 @@ export class V1ApiClients {
|
|
|
53
54
|
readonly schedulers: SchedulersClient;
|
|
54
55
|
readonly tags: TagsClient;
|
|
55
56
|
readonly analytics: AnalyticsClient;
|
|
57
|
+
readonly sqlRunner: SqlRunnerClient;
|
|
56
58
|
|
|
57
59
|
constructor(http: HttpClient) {
|
|
58
60
|
this.projects = new ProjectsClient(http);
|
|
@@ -71,6 +73,7 @@ export class V1ApiClients {
|
|
|
71
73
|
this.schedulers = new SchedulersClient(http);
|
|
72
74
|
this.tags = new TagsClient(http);
|
|
73
75
|
this.analytics = new AnalyticsClient(http);
|
|
76
|
+
this.sqlRunner = new SqlRunnerClient(http);
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,8 @@ export { MetricsClient } from './api/v1/metrics';
|
|
|
20
20
|
export { SchedulersClient } from './api/v1/schedulers';
|
|
21
21
|
export { TagsClient } from './api/v1/tags';
|
|
22
22
|
export { AnalyticsClient } from './api/v1/analytics';
|
|
23
|
+
export { SqlRunnerClient } from './api/v1/sql-runner';
|
|
24
|
+
export type { SqlChart } from './api/v1/sql-runner';
|
|
23
25
|
export { ContentClient } from './api/v2/content';
|
|
24
26
|
export { ChartsClientV2 } from './api/v2/charts';
|
|
25
27
|
export { DashboardsClientV2 } from './api/v2/dashboards';
|