@lightdash/cli 0.2394.2 → 0.2396.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/.tsbuildinfo +1 -1
- package/dist/globalState.d.ts +2 -0
- package/dist/globalState.d.ts.map +1 -1
- package/dist/globalState.js +4 -0
- package/dist/handlers/dbt/refresh.d.ts.map +1 -1
- package/dist/handlers/dbt/refresh.js +2 -0
- package/dist/handlers/deploy.d.ts.map +1 -1
- package/dist/handlers/deploy.js +4 -0
- package/dist/handlers/download.d.ts.map +1 -1
- package/dist/handlers/download.js +14 -0
- package/dist/handlers/generateExposures.d.ts.map +1 -1
- package/dist/handlers/generateExposures.js +2 -0
- package/dist/handlers/getProject.d.ts +6 -0
- package/dist/handlers/getProject.d.ts.map +1 -0
- package/dist/handlers/getProject.js +23 -0
- package/dist/handlers/listProjects.d.ts +6 -0
- package/dist/handlers/listProjects.d.ts.map +1 -0
- package/dist/handlers/listProjects.js +33 -0
- package/dist/handlers/preview.d.ts.map +1 -1
- package/dist/handlers/preview.js +7 -3
- package/dist/handlers/renameHandler.d.ts.map +1 -1
- package/dist/handlers/renameHandler.js +7 -0
- package/dist/handlers/sql.d.ts +9 -0
- package/dist/handlers/sql.d.ts.map +1 -0
- package/dist/handlers/sql.js +115 -0
- package/dist/handlers/validate.d.ts.map +1 -1
- package/dist/handlers/validate.js +2 -0
- package/dist/index.js +22 -0
- package/package.json +3 -3
package/dist/globalState.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ora from 'ora';
|
|
2
|
+
import { Config } from './config';
|
|
2
3
|
type PromptAnswer = {
|
|
3
4
|
useFallbackDbtVersion?: boolean;
|
|
4
5
|
useExperimentalDbtCloudCLI?: boolean;
|
|
@@ -16,6 +17,7 @@ declare class GlobalState {
|
|
|
16
17
|
savePromptAnswer<T extends keyof PromptAnswer>(prompt: T, value: PromptAnswer[T]): void;
|
|
17
18
|
clearPromptAnswer(): void;
|
|
18
19
|
debug(message: string): void;
|
|
20
|
+
logProjectInfo(config: Config): void;
|
|
19
21
|
}
|
|
20
22
|
declare const _default: GlobalState;
|
|
21
23
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globalState.d.ts","sourceRoot":"","sources":["../src/globalState.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"globalState.d.ts","sourceRoot":"","sources":["../src/globalState.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,KAAK,YAAY,GAAG;IAChB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACxC,CAAC;AAEF,cAAM,WAAW;IACb,OAAO,CAAC,OAAO,CAAkB;IAEjC,OAAO,CAAC,aAAa,CAAsB;IAE3C,OAAO,CAAC,kBAAkB,CAAe;;IAMzC,gBAAgB;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC,GAAG;IAMrD,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE;IAUlD,UAAU,CAAC,OAAO,EAAE,OAAO;IAI3B,oBAAoB,CAAC,CAAC,SAAS,MAAM,YAAY,EAC7C,MAAM,EAAE,CAAC,GACV,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS;IAI9B,gBAAgB,CAAC,CAAC,SAAS,MAAM,YAAY,EACzC,MAAM,EAAE,CAAC,EACT,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;IAK1B,iBAAiB;IAIjB,KAAK,CAAC,OAAO,EAAE,MAAM;IAMrB,cAAc,CAAC,MAAM,EAAE,MAAM;CAKhC;;AAED,wBAAiC"}
|
package/dist/globalState.js
CHANGED
|
@@ -44,5 +44,9 @@ class GlobalState {
|
|
|
44
44
|
this.log(styles.debug(message));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
logProjectInfo(config) {
|
|
48
|
+
const projectUuid = config.context?.project;
|
|
49
|
+
this.log(`\n${styles.success('Using project:')} ${projectUuid}\n`);
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
52
|
exports.default = new GlobalState();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,OAAO,EAGP,OAAO,EACV,MAAM,mBAAmB,CAAC;AAQ3B,eAAO,MAAM,UAAU,gBAAuB,MAAM,qBAK9C,CAAC;AAsBP,eAAO,MAAM,sBAAsB,UAAW,OAAO,EAAE,KAAG,MAUzD,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,OAAO,EAAE,KAAG,MAUvD,CAAC;AAoBF,KAAK,qBAAqB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,cAAc,YAAmB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,OAAO,EAGP,OAAO,EACV,MAAM,mBAAmB,CAAC;AAQ3B,eAAO,MAAM,UAAU,gBAAuB,MAAM,qBAK9C,CAAC;AAsBP,eAAO,MAAM,sBAAsB,UAAW,OAAO,EAAE,KAAG,MAUzD,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,OAAO,EAAE,KAAG,MAUvD,CAAC;AAoBF,KAAK,qBAAqB,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,cAAc,YAAmB,qBAAqB,kBA8DlE,CAAC"}
|
|
@@ -64,6 +64,8 @@ const refreshHandler = async (options) => {
|
|
|
64
64
|
throw new common_1.AuthorizationError(`No active Lightdash project. Run 'lightdash login --help'`);
|
|
65
65
|
}
|
|
66
66
|
const projectUuid = config.context.project;
|
|
67
|
+
// Log current project info
|
|
68
|
+
globalState_1.default.logProjectInfo(config);
|
|
67
69
|
const project = await (0, exports.getProject)(projectUuid);
|
|
68
70
|
if (project.dbtConnection.type === common_1.DbtProjectType.NONE) {
|
|
69
71
|
throw new common_1.ParameterError('Lightdash project must be connected to a remote repository. eg: GitHub, Gitlab, etc');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/handlers/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EACP,YAAY,EASf,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,KAAK,oBAAoB,GAAG,iBAAiB,GAAG;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,KAAK,UAAU,GAAG,oBAAoB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AAkCF,eAAO,MAAM,MAAM,aACL,CAAC,OAAO,GAAG,YAAY,CAAC,EAAE,WAC3B,UAAU,KACpB,OAAO,CAAC,IAAI,CAmEd,CAAC;AA8FF,eAAO,MAAM,aAAa,oBAA2B,oBAAoB,
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/handlers/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EACP,YAAY,EASf,MAAM,mBAAmB,CAAC;AAiB3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,KAAK,oBAAoB,GAAG,iBAAiB,GAAG;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,KAAK,UAAU,GAAG,oBAAoB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;CACvB,CAAC;AAkCF,eAAO,MAAM,MAAM,aACL,CAAC,OAAO,GAAG,YAAY,CAAC,EAAE,WAC3B,UAAU,KACpB,OAAO,CAAC,IAAI,CAmEd,CAAC;AA8FF,eAAO,MAAM,aAAa,oBAA2B,oBAAoB,kBAwFxE,CAAC"}
|
package/dist/handlers/deploy.js
CHANGED
|
@@ -183,6 +183,10 @@ const deployHandler = async (originalOptions) => {
|
|
|
183
183
|
const explores = await (0, compile_1.compile)(options);
|
|
184
184
|
const config = await (0, config_1.getConfig)();
|
|
185
185
|
let projectUuid;
|
|
186
|
+
// Log current project info if not creating a new one
|
|
187
|
+
if (options.create === undefined) {
|
|
188
|
+
globalState_1.default.logProjectInfo(config);
|
|
189
|
+
}
|
|
186
190
|
if (options.create !== undefined) {
|
|
187
191
|
const project = await createNewProject(executionId, options);
|
|
188
192
|
if (!project) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/handlers/download.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,sBAAsB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;CACnB,CAAC;AA2PF,KAAK,mBAAmB,GAAG,QAAQ,GAAG,YAAY,GAAG,WAAW,CAAC;AAkDjE,eAAO,MAAM,eAAe,QACnB,MAAM,EAAE,QACP,mBAAmB,aACd,MAAM,eACJ,MAAM,eACN,MAAM,gBACN,OAAO,WACZ,OAAO,KAChB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA2G5B,CAAC;AAEF,eAAO,MAAM,eAAe,YACf,sBAAsB,KAChC,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/handlers/download.ts"],"names":[],"mappings":"AA6BA,MAAM,MAAM,sBAAsB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,MAAM,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;CACnB,CAAC;AA2PF,KAAK,mBAAmB,GAAG,QAAQ,GAAG,YAAY,GAAG,WAAW,CAAC;AAkDjE,eAAO,MAAM,eAAe,QACnB,MAAM,EAAE,QACP,mBAAmB,aACd,MAAM,eACJ,MAAM,eACN,MAAM,gBACN,OAAO,WACZ,OAAO,KAChB,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA2G5B,CAAC;AAEF,eAAO,MAAM,eAAe,YACf,sBAAsB,KAChC,OAAO,CAAC,IAAI,CA2Kd,CAAC;AA2NF,eAAO,MAAM,aAAa,YACb,sBAAsB,KAChC,OAAO,CAAC,IAAI,CAgId,CAAC"}
|
|
@@ -275,6 +275,13 @@ const downloadHandler = async (options) => {
|
|
|
275
275
|
if (!projectId) {
|
|
276
276
|
throw new Error('No project selected. Run lightdash config set-project');
|
|
277
277
|
}
|
|
278
|
+
// Log current project info
|
|
279
|
+
if (options.project) {
|
|
280
|
+
console.error(`\n${styles.success('Downloading from project:')} ${projectId}\n`);
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
globalState_1.default.logProjectInfo(config);
|
|
284
|
+
}
|
|
278
285
|
// Fetch project details to get project name for folder structure
|
|
279
286
|
const project = await (0, apiClient_1.lightdashApi)({
|
|
280
287
|
method: 'GET',
|
|
@@ -501,6 +508,13 @@ const uploadHandler = async (options) => {
|
|
|
501
508
|
if (!projectId) {
|
|
502
509
|
throw new Error('No project selected. Run lightdash config set-project');
|
|
503
510
|
}
|
|
511
|
+
// Log current project info
|
|
512
|
+
if (options.project) {
|
|
513
|
+
console.error(`\n${styles.success('Uploading to project:')} ${projectId}\n`);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
globalState_1.default.logProjectInfo(config);
|
|
517
|
+
}
|
|
504
518
|
let changes = {};
|
|
505
519
|
// For analytics
|
|
506
520
|
let chartTotal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateExposures.d.ts","sourceRoot":"","sources":["../../src/handlers/generateExposures.ts"],"names":[],"mappings":"AAkBA,KAAK,+BAA+B,GAAG;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,YACxB,+BAA+B,
|
|
1
|
+
{"version":3,"file":"generateExposures.d.ts","sourceRoot":"","sources":["../../src/handlers/generateExposures.ts"],"names":[],"mappings":"AAkBA,KAAK,+BAA+B,GAAG;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,wBAAwB,YACxB,+BAA+B,kBA2G3C,CAAC"}
|
|
@@ -28,6 +28,8 @@ const generateExposuresHandler = async (options) => {
|
|
|
28
28
|
},
|
|
29
29
|
});
|
|
30
30
|
console.info(styles.warning(`This is an experimental feature and may change in future versions`));
|
|
31
|
+
// Log current project info
|
|
32
|
+
globalState_1.default.logProjectInfo(config);
|
|
31
33
|
const spinner = globalState_1.default.startSpinner(` Generating Lightdash exposures .yml for project ${styles.bold(config.context.projectName || config.context.project)}`);
|
|
32
34
|
try {
|
|
33
35
|
const absoluteProjectPath = path.resolve(options.projectDir);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getProject.d.ts","sourceRoot":"","sources":["../../src/handlers/getProject.ts"],"names":[],"mappings":"AAIA,KAAK,iBAAiB,GAAG;IACrB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAmB,iBAAiB,kBAuBjE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProjectHandler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
|
7
|
+
const styles = tslib_1.__importStar(require("../styles"));
|
|
8
|
+
const getProjectHandler = async (options) => {
|
|
9
|
+
globalState_1.default.setVerbose(options.verbose);
|
|
10
|
+
const config = await (0, config_1.getConfig)();
|
|
11
|
+
globalState_1.default.debug(`> Config: ${JSON.stringify(config)}`);
|
|
12
|
+
const projectUuid = config.context?.project;
|
|
13
|
+
const projectName = config.context?.projectName;
|
|
14
|
+
if (!projectUuid) {
|
|
15
|
+
console.error(styles.warning('No project set. Use `lightdash config set-project` to select a project.'));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
console.error(styles.bold('\nCurrent project:\n'));
|
|
19
|
+
console.error(` Name: ${projectName || '(unknown)'}`);
|
|
20
|
+
console.error(` UUID: ${projectUuid}`);
|
|
21
|
+
console.error('');
|
|
22
|
+
};
|
|
23
|
+
exports.getProjectHandler = getProjectHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listProjects.d.ts","sourceRoot":"","sources":["../../src/handlers/listProjects.ts"],"names":[],"mappings":"AAKA,KAAK,mBAAmB,GAAG;IACvB,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,mBAAmB,YAAmB,mBAAmB,kBAiCrE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listProjectsHandler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@lightdash/common");
|
|
6
|
+
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
|
7
|
+
const styles = tslib_1.__importStar(require("../styles"));
|
|
8
|
+
const apiClient_1 = require("./dbt/apiClient");
|
|
9
|
+
const listProjectsHandler = async (options) => {
|
|
10
|
+
globalState_1.default.setVerbose(options.verbose);
|
|
11
|
+
const projects = await (0, apiClient_1.lightdashApi)({
|
|
12
|
+
method: 'GET',
|
|
13
|
+
url: `/api/v1/org/projects`,
|
|
14
|
+
body: undefined,
|
|
15
|
+
});
|
|
16
|
+
globalState_1.default.debug(`> List projects returned response: ${JSON.stringify(projects)}`);
|
|
17
|
+
// Filter out preview projects
|
|
18
|
+
const filteredProjects = projects.filter((project) => project.type !== common_1.ProjectType.PREVIEW);
|
|
19
|
+
if (filteredProjects.length === 0) {
|
|
20
|
+
console.error(styles.warning('No projects found.'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
console.error(styles.bold(`\nProjects (${filteredProjects.length}):\n`));
|
|
24
|
+
filteredProjects.forEach((project) => {
|
|
25
|
+
console.error(` ${styles.bold(project.name)}`);
|
|
26
|
+
console.error(` UUID: ${project.projectUuid}`);
|
|
27
|
+
if (project.warehouseType) {
|
|
28
|
+
console.error(` Warehouse: ${project.warehouseType}`);
|
|
29
|
+
}
|
|
30
|
+
console.error('');
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
exports.listProjectsHandler = listProjectsHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/handlers/preview.ts"],"names":[],"mappings":"AACA,OAAO,EACH,+BAA+B,EAIlC,MAAM,mBAAmB,CAAC;AAe3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,KAAK,qBAAqB,GAAG,iBAAiB,GAAG;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAyEF,eAAO,MAAM,cAAc,YACd,qBAAqB,KAC/B,OAAO,CAAC,IAAI,CAkPd,CAAC;AAEF,eAAO,MAAM,mBAAmB,YACnB,qBAAqB,KAC/B,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/handlers/preview.ts"],"names":[],"mappings":"AACA,OAAO,EACH,+BAA+B,EAIlC,MAAM,mBAAmB,CAAC;AAe3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGlD,KAAK,qBAAqB,GAAG,iBAAiB,GAAG;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CACpC,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAyEF,eAAO,MAAM,cAAc,YACd,qBAAqB,KAC/B,OAAO,CAAC,IAAI,CAkPd,CAAC;AAEF,eAAO,MAAM,mBAAmB,YACnB,qBAAqB,KAC/B,OAAO,CAAC,IAAI,CAqId,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAClB,yBAAyB,KACnC,OAAO,CAAC,IAAI,CA0Cd,CAAC"}
|
package/dist/handlers/preview.js
CHANGED
|
@@ -257,8 +257,14 @@ const startPreviewHandler = async (options) => {
|
|
|
257
257
|
return;
|
|
258
258
|
}
|
|
259
259
|
const projectName = options.name;
|
|
260
|
+
const config = await (0, config_1.getConfig)();
|
|
261
|
+
// Log current source project info if copying content
|
|
262
|
+
if (!options.skipCopyContent && config.context?.project) {
|
|
263
|
+
console.error(`\n${styles.success('Source project for content:')} ${styles.bold(config.context.projectName || config.context.project)}\n`);
|
|
264
|
+
}
|
|
260
265
|
const previewProject = await getPreviewProject(projectName);
|
|
261
266
|
if (previewProject) {
|
|
267
|
+
console.error(`\n${styles.success('Updating preview project:')} ${styles.bold(projectName)}\n`);
|
|
262
268
|
await (0, config_1.setPreviewProject)(previewProject.projectUuid, projectName);
|
|
263
269
|
await analytics_1.LightdashAnalytics.track({
|
|
264
270
|
event: 'start_preview.update',
|
|
@@ -269,7 +275,6 @@ const startPreviewHandler = async (options) => {
|
|
|
269
275
|
},
|
|
270
276
|
});
|
|
271
277
|
// Update
|
|
272
|
-
console.error(`Updating project preview ${projectName}`);
|
|
273
278
|
const explores = await (0, compile_1.compile)(options);
|
|
274
279
|
await (0, deploy_1.deploy)(explores, {
|
|
275
280
|
...options,
|
|
@@ -283,7 +288,7 @@ const startPreviewHandler = async (options) => {
|
|
|
283
288
|
}
|
|
284
289
|
}
|
|
285
290
|
else {
|
|
286
|
-
|
|
291
|
+
console.error(`\n${styles.success('Creating preview project:')} ${styles.bold(projectName)}\n`);
|
|
287
292
|
if (!config.context?.project) {
|
|
288
293
|
console.error(styles.warning(`\n\nDeveloper preview will be deployed without any copied content!\nPlease set a project to copy content from by running 'lightdash config set-project'.\n`));
|
|
289
294
|
}
|
|
@@ -294,7 +299,6 @@ const startPreviewHandler = async (options) => {
|
|
|
294
299
|
console.error(`\n${styles.success('✔')} Copying charts and dashboards from "${config.context?.projectName || 'source project'}"`);
|
|
295
300
|
}
|
|
296
301
|
// Create
|
|
297
|
-
console.error(`Creating new project preview ${projectName}`);
|
|
298
302
|
const results = await (0, createProject_1.createProject)({
|
|
299
303
|
...options,
|
|
300
304
|
name: projectName,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renameHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/renameHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,UAAU,EAEb,MAAM,mBAAmB,CAAC;AAiB3B,KAAK,oBAAoB,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACrB,CAAC;AAsCF,eAAO,MAAM,aAAa,YAAmB,oBAAoB,
|
|
1
|
+
{"version":3,"file":"renameHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/renameHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,UAAU,EAEb,MAAM,mBAAmB,CAAC;AAiB3B,KAAK,oBAAoB,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACrB,CAAC;AAsCF,eAAO,MAAM,aAAa,YAAmB,oBAAoB,kBA0KhE,CAAC"}
|
|
@@ -46,6 +46,13 @@ const renameHandler = async (options) => {
|
|
|
46
46
|
if (!projectUuid) {
|
|
47
47
|
throw new Error('No project selected. Run lightdash config set-project');
|
|
48
48
|
}
|
|
49
|
+
// Log current project info
|
|
50
|
+
if (options.project) {
|
|
51
|
+
console.error(`\n${styles.success('Renaming in project:')} ${projectUuid}\n`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
globalState_1.default.logProjectInfo(config);
|
|
55
|
+
}
|
|
49
56
|
const isValidInput = (input) => /^[a-z_]+$/.test(input);
|
|
50
57
|
if (!isValidInput(options.from) || !isValidInput(options.to)) {
|
|
51
58
|
throw new Error('Invalid input: Only lowercase letters (a-z) and underscores (_) are allowed.');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/handlers/sql.ts"],"names":[],"mappings":"AAYA,KAAK,iBAAiB,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AA0FF,eAAO,MAAM,UAAU,QACd,MAAM,WACF,iBAAiB,KAC3B,OAAO,CAAC,IAAI,CAiEd,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sqlHandler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@lightdash/common");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const config_1 = require("../config");
|
|
8
|
+
const globalState_1 = tslib_1.__importDefault(require("../globalState"));
|
|
9
|
+
const styles = tslib_1.__importStar(require("../styles"));
|
|
10
|
+
const apiClient_1 = require("./dbt/apiClient");
|
|
11
|
+
const DEFAULT_PAGE_SIZE = 500;
|
|
12
|
+
const POLL_INTERVAL_MS = 500;
|
|
13
|
+
/**
|
|
14
|
+
* Convert ResultRow array to CSV string
|
|
15
|
+
*/
|
|
16
|
+
function resultsToCsv(columns, rows) {
|
|
17
|
+
// Escape CSV value: wrap in quotes if contains comma, quote, or newline
|
|
18
|
+
const escapeValue = (value) => {
|
|
19
|
+
if (value === null || value === undefined) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
const str = String(value);
|
|
23
|
+
if (str.includes(',') || str.includes('"') || str.includes('\n')) {
|
|
24
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
25
|
+
}
|
|
26
|
+
return str;
|
|
27
|
+
};
|
|
28
|
+
const header = columns.map(escapeValue).join(',');
|
|
29
|
+
const dataRows = rows.map((row) => columns.map((col) => escapeValue(row[col]?.value?.raw)).join(','));
|
|
30
|
+
return [header, ...dataRows].join('\n');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Fetch query results once
|
|
34
|
+
*/
|
|
35
|
+
async function fetchQueryResults(projectUuid, queryUuid, pageSize) {
|
|
36
|
+
const url = `/api/v2/projects/${projectUuid}/query/${queryUuid}?pageSize=${pageSize}`;
|
|
37
|
+
return (0, apiClient_1.lightdashApi)({
|
|
38
|
+
method: 'GET',
|
|
39
|
+
url,
|
|
40
|
+
body: undefined,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Sleep for a given duration
|
|
45
|
+
*/
|
|
46
|
+
function sleep(ms) {
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
setTimeout(resolve, ms);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Poll for query results until status is READY or ERROR
|
|
53
|
+
*/
|
|
54
|
+
async function pollQueryResults(projectUuid, queryUuid, pageSize) {
|
|
55
|
+
const poll = async () => {
|
|
56
|
+
const result = await fetchQueryResults(projectUuid, queryUuid, pageSize);
|
|
57
|
+
globalState_1.default.debug(`> Query status: ${result.status}`);
|
|
58
|
+
if (result.status === common_1.QueryHistoryStatus.READY) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
if (result.status === common_1.QueryHistoryStatus.ERROR) {
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
if (result.status === common_1.QueryHistoryStatus.CANCELLED) {
|
|
65
|
+
throw new Error('Query was cancelled');
|
|
66
|
+
}
|
|
67
|
+
// Still pending, wait and poll again
|
|
68
|
+
await sleep(POLL_INTERVAL_MS);
|
|
69
|
+
return poll();
|
|
70
|
+
};
|
|
71
|
+
return poll();
|
|
72
|
+
}
|
|
73
|
+
const sqlHandler = async (sql, options) => {
|
|
74
|
+
globalState_1.default.setVerbose(options.verbose ?? false);
|
|
75
|
+
const config = await (0, config_1.getConfig)();
|
|
76
|
+
const projectUuid = config.context?.project;
|
|
77
|
+
if (!projectUuid) {
|
|
78
|
+
throw new Error(`No project selected. Run 'lightdash config set-project' first.`);
|
|
79
|
+
}
|
|
80
|
+
globalState_1.default.debug(`> Running SQL query against project: ${projectUuid}`);
|
|
81
|
+
globalState_1.default.debug(`> SQL: ${sql}`);
|
|
82
|
+
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
83
|
+
// Submit the query
|
|
84
|
+
const spinner = globalState_1.default.startSpinner('Submitting SQL query...');
|
|
85
|
+
const submitResult = await (0, apiClient_1.lightdashApi)({
|
|
86
|
+
method: 'POST',
|
|
87
|
+
url: `/api/v2/projects/${projectUuid}/query/sql`,
|
|
88
|
+
body: JSON.stringify({
|
|
89
|
+
sql,
|
|
90
|
+
limit: options.limit,
|
|
91
|
+
context: 'cli',
|
|
92
|
+
}),
|
|
93
|
+
});
|
|
94
|
+
globalState_1.default.debug(`> Query UUID: ${submitResult.queryUuid}`);
|
|
95
|
+
spinner.text = 'Waiting for query results...';
|
|
96
|
+
// Poll for results
|
|
97
|
+
const result = await pollQueryResults(projectUuid, submitResult.queryUuid, pageSize);
|
|
98
|
+
if (result.status === common_1.QueryHistoryStatus.ERROR) {
|
|
99
|
+
spinner.fail('Query failed');
|
|
100
|
+
throw new Error(result.error ?? 'Query execution failed');
|
|
101
|
+
}
|
|
102
|
+
if (result.status !== common_1.QueryHistoryStatus.READY) {
|
|
103
|
+
spinner.fail('Unexpected query status');
|
|
104
|
+
throw new Error(`Unexpected query status: ${result.status}`);
|
|
105
|
+
}
|
|
106
|
+
// Extract column names from the columns metadata
|
|
107
|
+
const columns = Object.keys(result.columns);
|
|
108
|
+
const rowCount = result.rows.length;
|
|
109
|
+
spinner.text = `Writing ${rowCount} rows to ${options.output}...`;
|
|
110
|
+
// Convert to CSV and write to file
|
|
111
|
+
const csv = resultsToCsv(columns, result.rows);
|
|
112
|
+
await fs_1.promises.writeFile(options.output, csv, 'utf8');
|
|
113
|
+
spinner.succeed(`${styles.success('Success!')} Wrote ${rowCount} rows to ${options.output}`);
|
|
114
|
+
};
|
|
115
|
+
exports.sqlHandler = sqlHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/handlers/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,OAAO,EACP,YAAY,EAMZ,kBAAkB,EAGlB,gBAAgB,EACnB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAW,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAG3D,eAAO,MAAM,iBAAiB,gBACb,MAAM,YACT,CAAC,OAAO,GAAG,YAAY,CAAC,EAAE,qBACjB,gBAAgB,EAAE;;EAMnC,CAAC;AAEP,eAAO,MAAM,WAAW,YAAmB,MAAM;;;EAK3C,CAAC;AAEP,eAAO,MAAM,aAAa,gBAAuB,MAAM,SAAS,MAAM,8DAKhE,CAAC;AAEP,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAI/B;AAWD,KAAK,sBAAsB,GAAG,qBAAqB,GAAG;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACzB,8BAA8B,EAAE,OAAO,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAmB,MAAM,KAAG,OAAO,CAAC,MAAM,CAYvE,CAAC;AAEF,eAAO,MAAM,eAAe,YAAmB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/handlers/validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,OAAO,EACP,YAAY,EAMZ,kBAAkB,EAGlB,gBAAgB,EACnB,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAW,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAG3D,eAAO,MAAM,iBAAiB,gBACb,MAAM,YACT,CAAC,OAAO,GAAG,YAAY,CAAC,EAAE,qBACjB,gBAAgB,EAAE;;EAMnC,CAAC;AAEP,eAAO,MAAM,WAAW,YAAmB,MAAM;;;EAK3C,CAAC;AAEP,eAAO,MAAM,aAAa,gBAAuB,MAAM,SAAS,MAAM,8DAKhE,CAAC;AAEP,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,oBAI/B;AAWD,KAAK,sBAAsB,GAAG,qBAAqB,GAAG;IAClD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,gBAAgB,EAAE,CAAC;IACzB,8BAA8B,EAAE,OAAO,CAAC;CAC3C,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAmB,MAAM,KAAG,OAAO,CAAC,MAAM,CAYvE,CAAC;AAEF,eAAO,MAAM,eAAe,YAAmB,sBAAsB,kBAyKpE,CAAC"}
|
|
@@ -55,6 +55,8 @@ const validateHandler = async (options) => {
|
|
|
55
55
|
globalState_1.default.setVerbose(options.verbose);
|
|
56
56
|
await (0, apiClient_1.checkLightdashVersion)();
|
|
57
57
|
const config = await (0, config_1.getConfig)();
|
|
58
|
+
// Log current project info
|
|
59
|
+
globalState_1.default.logProjectInfo(config);
|
|
58
60
|
const explores = await (0, compile_1.compile)(options);
|
|
59
61
|
globalState_1.default.debug(`> Compiled ${explores.length} explores`);
|
|
60
62
|
const selectedProject = options.preview
|
package/dist/index.js
CHANGED
|
@@ -14,11 +14,14 @@ const diagnostics_1 = require("./handlers/diagnostics");
|
|
|
14
14
|
const download_1 = require("./handlers/download");
|
|
15
15
|
const generate_1 = require("./handlers/generate");
|
|
16
16
|
const generateExposures_1 = require("./handlers/generateExposures");
|
|
17
|
+
const getProject_1 = require("./handlers/getProject");
|
|
17
18
|
const lint_1 = require("./handlers/lint");
|
|
19
|
+
const listProjects_1 = require("./handlers/listProjects");
|
|
18
20
|
const login_1 = require("./handlers/login");
|
|
19
21
|
const preview_1 = require("./handlers/preview");
|
|
20
22
|
const renameHandler_1 = require("./handlers/renameHandler");
|
|
21
23
|
const setProject_1 = require("./handlers/setProject");
|
|
24
|
+
const sql_1 = require("./handlers/sql");
|
|
22
25
|
const validate_1 = require("./handlers/validate");
|
|
23
26
|
const styles = tslib_1.__importStar(require("./styles"));
|
|
24
27
|
// Trigger CLI tests
|
|
@@ -110,6 +113,16 @@ configProgram
|
|
|
110
113
|
.addOption(new commander_1.Option('--name <project_name>', 'Set the project non-interactively by passing a project name.'))
|
|
111
114
|
.addOption(new commander_1.Option('--uuid <project_uuid>', 'Set the project non-interactively by passing a project uuid.').conflicts('name'))
|
|
112
115
|
.action(setProject_1.setProjectHandler);
|
|
116
|
+
configProgram
|
|
117
|
+
.command('list-projects')
|
|
118
|
+
.description('List all projects in the organization (excludes preview projects)')
|
|
119
|
+
.option('--verbose', undefined, false)
|
|
120
|
+
.action(listProjects_1.listProjectsHandler);
|
|
121
|
+
configProgram
|
|
122
|
+
.command('get-project')
|
|
123
|
+
.description('Show the currently selected project')
|
|
124
|
+
.option('--verbose', undefined, false)
|
|
125
|
+
.action(getProject_1.getProjectHandler);
|
|
113
126
|
const dbtProgram = commander_1.program.command('dbt').description('Runs dbt commands');
|
|
114
127
|
dbtProgram
|
|
115
128
|
.command('run')
|
|
@@ -411,6 +424,15 @@ ${styles.bold('Examples:')}
|
|
|
411
424
|
.option('--verbose', 'Show detailed output', false)
|
|
412
425
|
.option('-f, --format <format>', 'Output format: cli (default) or json (SARIF format)', 'cli')
|
|
413
426
|
.action(lint_1.lintHandler);
|
|
427
|
+
commander_1.program
|
|
428
|
+
.command('sql')
|
|
429
|
+
.description('Run raw SQL query against the warehouse using project credentials')
|
|
430
|
+
.argument('<query>', 'SQL query to execute')
|
|
431
|
+
.requiredOption('-o, --output <file>', 'Output file path for CSV results')
|
|
432
|
+
.option('--limit <number>', 'Maximum rows to return from query', parseIntArgument)
|
|
433
|
+
.option('--page-size <number>', 'Number of rows per page (default: 500, max: 5000)', parseIntArgument)
|
|
434
|
+
.option('--verbose', 'Show detailed output', false)
|
|
435
|
+
.action(sql_1.sqlHandler);
|
|
414
436
|
const errorHandler = (err) => {
|
|
415
437
|
// Use error message with fallback for safety
|
|
416
438
|
const errorMessage = (0, common_1.getErrorMessage)(err) || 'An unexpected error occurred';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2396.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"unique-names-generator": "^4.7.1",
|
|
39
39
|
"uuid": "^11.0.3",
|
|
40
40
|
"yaml": "^2.7.0",
|
|
41
|
-
"@lightdash/
|
|
42
|
-
"@lightdash/
|
|
41
|
+
"@lightdash/common": "0.2396.0",
|
|
42
|
+
"@lightdash/warehouses": "0.2396.0"
|
|
43
43
|
},
|
|
44
44
|
"description": "Lightdash CLI tool",
|
|
45
45
|
"devDependencies": {
|