@lightdash/cli 2.327.2 → 2.329.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/config.d.ts CHANGED
@@ -9,6 +9,7 @@ export type Config = {
9
9
  serverUrl?: string;
10
10
  project?: string;
11
11
  projectName?: string;
12
+ source?: string;
12
13
  /**
13
14
  * This is an API token that is used to authenticate with the Lightdash API.
14
15
  * It could be a personal access token or a service account token.
@@ -30,6 +31,7 @@ export declare const writeConfigToFile: (filePath: string, config: Config) => Pr
30
31
  export declare const getConfig: () => Promise<Config>;
31
32
  export declare const setProject: (projectUuid: string, projectName: string) => Promise<void>;
32
33
  export declare const unsetProject: () => Promise<void>;
34
+ export declare const setSource: (source: string) => Promise<void>;
33
35
  export declare const setPreviewProject: (projectUuid: string, name: string) => Promise<void>;
34
36
  export declare const unsetPreviewProject: () => Promise<void>;
35
37
  export declare const setDefaultUser: (userUuid: string, organizationUuid: string) => Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,QAAsC,CAAC;AAElE,MAAM,MAAM,MAAM,GAAG;IACjB,IAAI,CAAC,EAAE;QACH,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF,OAAO,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB;;;WAGG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,OAAO,CAAC,EAAE;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H,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,WAAW,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,OAAO,CAAC,EAAE;QACN,qCAAqC,CAAC,EAAE,OAAO,CAAC;QAChD,gCAAgC,CAAC,EAAE,OAAO,CAAC;KAC9C,CAAC;CACL,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,2BAA2B,aAC1B,MAAM,KACjB,OAAO,CAAC,IAAI,CAgBd,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,aAChB,MAAM,UACR,MAAM,KACf,OAAO,CAAC,IAAI,CAed,CAAC;AAiCF,eAAO,MAAM,SAAS,QAAa,OAAO,CAAC,MAAM,CA6BhD,CAAC;AAEF,eAAO,MAAM,UAAU,gBAAuB,MAAM,eAAe,MAAM,kBAcxE,CAAC;AAEF,eAAO,MAAM,YAAY,qBAWxB,CAAC;AAEF,eAAO,MAAM,SAAS,WAAkB,MAAM,kBAS7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,gBAAuB,MAAM,QAAQ,MAAM,kBAUxE,CAAC;AAEF,eAAO,MAAM,mBAAmB,qBAU/B,CAAC;AAEF,eAAO,MAAM,cAAc,aACb,MAAM,oBACE,MAAM,kBAW3B,CAAC;AAEF,eAAO,MAAM,UAAU,YAAmB,MAAM,CAAC,SAAS,CAAC,kBAM1D,CAAC;AAEF,eAAO,MAAM,SAAS,WAAkB,MAAM,CAAC,SAAS,CAAC,kBAMxD,CAAC"}
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setAnswer = exports.setContext = exports.setDefaultUser = exports.unsetPreviewProject = exports.setPreviewProject = exports.unsetProject = exports.setProject = exports.getConfig = exports.writeConfigToFile = exports.ensureConfigFilePermissions = exports.configFilePath = void 0;
3
+ exports.setAnswer = exports.setContext = exports.setDefaultUser = exports.unsetPreviewProject = exports.setPreviewProject = exports.setSource = exports.unsetProject = exports.setProject = exports.getConfig = exports.writeConfigToFile = exports.ensureConfigFilePermissions = exports.configFilePath = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = require("fs");
6
6
  const yaml = tslib_1.__importStar(require("js-yaml"));
@@ -88,6 +88,10 @@ const getConfig = async () => {
88
88
  process.env.LIGHTDASH_PROJECT !== rawConfig.context?.project
89
89
  ? undefined
90
90
  : rawConfig.context?.projectName,
91
+ source: process.env.LIGHTDASH_PROJECT &&
92
+ process.env.LIGHTDASH_PROJECT !== rawConfig.context?.project
93
+ ? undefined
94
+ : rawConfig.context?.source,
91
95
  serverUrl: process.env.LIGHTDASH_URL || rawConfig.context?.serverUrl,
92
96
  proxyAuthorization: process.env.LIGHTDASH_PROXY_AUTHORIZATION ||
93
97
  rawConfig.context?.proxyAuthorization,
@@ -103,6 +107,9 @@ const setProject = async (projectUuid, projectName) => {
103
107
  ...(config.context || {}),
104
108
  project: projectUuid,
105
109
  projectName,
110
+ source: config.context?.project === projectUuid
111
+ ? config.context.source
112
+ : undefined,
106
113
  },
107
114
  });
108
115
  };
@@ -115,10 +122,22 @@ const unsetProject = async () => {
115
122
  ...(config.context || {}),
116
123
  project: undefined,
117
124
  projectName: undefined,
125
+ source: undefined,
118
126
  },
119
127
  });
120
128
  };
121
129
  exports.unsetProject = unsetProject;
130
+ const setSource = async (source) => {
131
+ const config = await getRawConfig();
132
+ await setConfig({
133
+ ...config,
134
+ context: {
135
+ ...(config.context || {}),
136
+ source,
137
+ },
138
+ });
139
+ };
140
+ exports.setSource = setSource;
122
141
  const setPreviewProject = async (projectUuid, name) => {
123
142
  const config = await getRawConfig();
124
143
  await setConfig({
@@ -1,4 +1,5 @@
1
- import { Explore, ExploreError } from '@lightdash/common';
1
+ import { Explore, ExploreError, type ConnectionRoute, type DeployTarget } from '@lightdash/common';
2
+ import { CliProjectType } from '../lightdash/projectType';
2
3
  import { DbtCompileOptions } from './dbt/compile';
3
4
  type DeployHandlerOptions = DbtCompileOptions & {
4
5
  projectDir: string;
@@ -20,12 +21,16 @@ type DeployHandlerOptions = DbtCompileOptions & {
20
21
  disableTimestampConversion?: boolean;
21
22
  validateWarehouseColumns: boolean;
22
23
  partialCompilation?: boolean;
24
+ source?: string;
23
25
  };
24
26
  type DeployArgs = DeployHandlerOptions & {
25
27
  projectUuid: string;
26
28
  complete?: boolean;
27
29
  dbtModelNames?: string[];
30
+ sourceUuid?: string;
31
+ deployTarget?: DeployTarget;
28
32
  };
33
+ export declare const getDeployTarget: (options: Pick<DeployHandlerOptions, 'projectDir' | 'targetPath' | 'profilesDir' | 'profile' | 'target'>, projectType: CliProjectType, connectionRoute: ConnectionRoute | undefined) => Promise<DeployTarget | undefined>;
29
34
  export declare const deploy: (explores: (Explore | ExploreError)[], options: DeployArgs) => Promise<void>;
30
35
  export declare const deployHandler: (originalOptions: DeployHandlerOptions) => Promise<void>;
31
36
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/handlers/deploy.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,OAAO,EACP,YAAY,EASf,MAAM,mBAAmB,CAAC;AA2B3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AASlD,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,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,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,EAA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ploy = void 0;
3
+ exports.deployHandler = exports.deploy = exports.getDeployTarget = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@lightdash/common");
6
6
  const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
@@ -20,7 +20,56 @@ const createProject_1 = require("./createProject");
20
20
  const apiClient_1 = require("./dbt/apiClient");
21
21
  const getDbtVersion_1 = require("./dbt/getDbtVersion");
22
22
  const selectProject_1 = require("./selectProject");
23
+ const sourceSelection_1 = require("./sourceSelection");
23
24
  const timestampConversion_1 = require("./timestampConversion");
25
+ const deployDestinationQuery = (options) => [
26
+ options.sourceUuid === undefined
27
+ ? undefined
28
+ : `sourceUuid=${encodeURIComponent(options.sourceUuid)}`,
29
+ options.deployTarget === undefined
30
+ ? undefined
31
+ : `targetDatabase=${encodeURIComponent(options.deployTarget.database)}`,
32
+ options.deployTarget?.region === undefined
33
+ ? undefined
34
+ : `targetRegion=${encodeURIComponent(options.deployTarget.region)}`,
35
+ ]
36
+ .filter((parameter) => parameter !== undefined)
37
+ .map((parameter) => `&${parameter}`)
38
+ .join('');
39
+ const getDeployTarget = async (options, projectType, connectionRoute) => {
40
+ if (projectType !== projectType_1.CliProjectType.Dbt || connectionRoute !== 'multi') {
41
+ return undefined;
42
+ }
43
+ try {
44
+ const context = await (0, context_1.getDbtContext)({
45
+ projectDir: path_1.default.resolve(options.projectDir),
46
+ targetPath: options.targetPath,
47
+ });
48
+ const { target } = await (0, profile_1.loadDbtTarget)({
49
+ profilesDir: path_1.default.resolve(options.profilesDir),
50
+ profileName: options.profile || context.profileName,
51
+ targetName: options.target,
52
+ });
53
+ if (target.type === 'spark')
54
+ return undefined;
55
+ const credentials = await (0, profile_1.warehouseCredentialsFromDbtTarget)(target);
56
+ const location = (0, common_1.getWarehouseLocation)(credentials);
57
+ const database = location.database ?? location.schema;
58
+ if (!database)
59
+ return undefined;
60
+ return {
61
+ database,
62
+ ...(credentials.type === common_1.WarehouseTypes.ATHENA
63
+ ? { region: credentials.region }
64
+ : {}),
65
+ };
66
+ }
67
+ catch (e) {
68
+ globalState_1.default.debug(`> Could not read the dbt target database: ${(0, common_1.getErrorMessage)(e)}`);
69
+ return undefined;
70
+ }
71
+ };
72
+ exports.getDeployTarget = getDeployTarget;
24
73
  const logDeployWarnings = (warningResults) => {
25
74
  if (!warningResults ||
26
75
  warningResults.warningCount === 0 ||
@@ -184,7 +233,11 @@ const deployBatched = async (explores, options) => {
184
233
  const finalizeResponse = await (0, apiClient_1.lightdashApi)({
185
234
  method: 'POST',
186
235
  url: `/api/v2/projects/${options.projectUuid}/deploy/${sessionUuid}/finalize`,
187
- body: JSON.stringify({ dbtModelNames: options.dbtModelNames }),
236
+ body: JSON.stringify({
237
+ dbtModelNames: options.dbtModelNames,
238
+ sourceUuid: options.sourceUuid,
239
+ target: options.deployTarget,
240
+ }),
188
241
  });
189
242
  globalState_1.default.log(styles.success(`Deploy completed! ${finalizeResponse.exploreCount} explores deployed.`));
190
243
  logDeployWarnings(finalizeResponse.warnings);
@@ -249,12 +302,14 @@ const deploy = async (explores, options) => {
249
302
  explores: deployableExplores,
250
303
  dbtModelNames: options.dbtModelNames,
251
304
  complete: options.complete === true,
305
+ sourceUuid: options.sourceUuid,
306
+ target: options.deployTarget,
252
307
  });
253
308
  try {
254
309
  const deployResponse = await (0, apiClient_1.lightdashApi)({
255
310
  method: 'PUT',
256
311
  url: options.dbtModelNames === undefined
257
- ? `/api/v1/projects/${options.projectUuid}/explores?complete=${options.complete === true}`
312
+ ? `/api/v1/projects/${options.projectUuid}/explores?complete=${options.complete === true}${deployDestinationQuery(options)}`
258
313
  : `/api/v2/projects/${options.projectUuid}/deploy`,
259
314
  body: deployPayload,
260
315
  }).catch(async (error) => {
@@ -266,7 +321,7 @@ const deploy = async (explores, options) => {
266
321
  globalState_1.default.log(styles.warning('This server does not support deleted dbt model cleanup; deploying without cleanup. Upgrade the server to enable it.'));
267
322
  return (0, apiClient_1.lightdashApi)({
268
323
  method: 'PUT',
269
- url: `/api/v1/projects/${options.projectUuid}/explores?complete=${options.complete === true}`,
324
+ url: `/api/v1/projects/${options.projectUuid}/explores?complete=${options.complete === true}${deployDestinationQuery(options)}`,
270
325
  body: JSON.stringify(deployableExplores),
271
326
  });
272
327
  });
@@ -457,6 +512,8 @@ const deployHandler = async (originalOptions) => {
457
512
  const executionId = (0, uuid_1.v4)();
458
513
  const config = await (0, config_1.getConfig)();
459
514
  let existingProjectSelection;
515
+ let sourceUuid;
516
+ let connectionRoute;
460
517
  if (options.create === undefined) {
461
518
  if (!config.context?.serverUrl) {
462
519
  throw new common_1.AuthorizationError(`No active Lightdash project. Run 'lightdash login --help'`);
@@ -467,8 +524,11 @@ const deployHandler = async (originalOptions) => {
467
524
  }
468
525
  // Log current project info
469
526
  (0, selectProject_1.logSelectedProject)(existingProjectSelection, config, 'Deploying to');
527
+ sourceUuid = await (0, sourceSelection_1.resolveProjectSourceUuid)(existingProjectSelection.projectUuid, options.source);
528
+ const projectSettings = await (0, timestampConversion_1.getProjectDeploySettings)(options.disableTimestampConversion, existingProjectSelection.projectUuid);
470
529
  options.disableTimestampConversion =
471
- await (0, timestampConversion_1.getProjectDisableTimestampConversion)(options.disableTimestampConversion, existingProjectSelection.projectUuid);
530
+ projectSettings.disableTimestampConversion;
531
+ connectionRoute = projectSettings.connectionRoute;
472
532
  }
473
533
  const { explores, isProjectComplete, dbtModelNames } = await (0, compile_1.compileProject)(options);
474
534
  let projectUuid;
@@ -485,6 +545,7 @@ const deployHandler = async (originalOptions) => {
485
545
  }
486
546
  projectUuid = project.projectUuid;
487
547
  await (0, config_1.setProject)(projectUuid, project.name);
548
+ sourceUuid = await (0, sourceSelection_1.resolveProjectSourceUuid)(projectUuid, options.source);
488
549
  }
489
550
  else if (existingProjectSelection) {
490
551
  projectUuid = existingProjectSelection.projectUuid;
@@ -497,6 +558,8 @@ const deployHandler = async (originalOptions) => {
497
558
  projectUuid,
498
559
  complete: isProjectComplete,
499
560
  dbtModelNames,
561
+ sourceUuid,
562
+ deployTarget: await (0, exports.getDeployTarget)(options, projectTypeConfig.type, connectionRoute),
500
563
  });
501
564
  const serverUrl = config.context?.serverUrl?.replace(/\/$/, '');
502
565
  let displayUrl = options.create
@@ -24,6 +24,7 @@ type PreviewHandlerOptions = DbtCompileOptions & {
24
24
  partialCompilation?: boolean;
25
25
  combine?: boolean;
26
26
  combineManifestProjectUuid?: string;
27
+ source?: string;
27
28
  };
28
29
  type StopPreviewHandlerOptions = {
29
30
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../src/handlers/preview.ts"],"names":[],"mappings":"AACA,OAAO,EACH,+BAA+B,EAKlC,MAAM,mBAAmB,CAAC;AAmB3B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAYlD,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,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,wB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AAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,wBAAwB,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAoBF,KAAK,yBAAyB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AA2GF,eAAO,MAAM,cAAc,oBACN,qBAAqB,KACvC,OAAO,CAAC,IAAI,CAmTd,CAAC;AAuDF,eAAO,MAAM,mBAAmB,oBACX,qBAAqB,KACvC,OAAO,CAAC,IAAI,CA2Md,CAAC;AAEF,eAAO,MAAM,kBAAkB,YAClB,yBAAyB,KACnC,OAAO,CAAC,IAAI,CA0Cd,CAAC"}
@@ -21,8 +21,13 @@ const createProject_1 = require("./createProject");
21
21
  const apiClient_1 = require("./dbt/apiClient");
22
22
  const refresh_1 = require("./dbt/refresh");
23
23
  const deploy_1 = require("./deploy");
24
+ const sourceSelection_1 = require("./sourceSelection");
24
25
  const timestampConversion_1 = require("./timestampConversion");
25
26
  const warehouseConnection_1 = require("./warehouseConnection");
27
+ const previewDeployDestination = async (project, options, projectType, upstreamProjectUuid) => ({
28
+ sourceUuid: await (0, sourceSelection_1.resolveProjectSourceUuid)(project.projectUuid, options.source, upstreamProjectUuid),
29
+ deployTarget: await (0, deploy_1.getDeployTarget)(options, projectType, project.connectionRoute),
30
+ });
26
31
  const deletePreviewProject = async (projectUuid) => {
27
32
  /**
28
33
  * projectUuid may be undefined here if a command fails early enough
@@ -223,6 +228,7 @@ const previewHandler = async (originalOptions) => {
223
228
  await (0, deploy_1.deploy)(explores, {
224
229
  ...options,
225
230
  projectUuid: project.projectUuid,
231
+ ...(await previewDeployDestination(project, options, projectTypeConfig.type, config.context?.project)),
226
232
  complete: isProjectComplete,
227
233
  });
228
234
  await (0, config_1.setPreviewProject)(project.projectUuid, name);
@@ -272,6 +278,7 @@ const previewHandler = async (originalOptions) => {
272
278
  await (0, deploy_1.deploy)(compileResult.explores, {
273
279
  ...options,
274
280
  projectUuid: project.projectUuid,
281
+ ...(await previewDeployDestination(project, options, projectTypeConfig.type, config.context?.project)),
275
282
  complete: compileResult.isProjectComplete,
276
283
  });
277
284
  }
@@ -393,12 +400,17 @@ const startPreviewHandler = async (originalOptions) => {
393
400
  warehouseCredentials: projectTypeConfig.warehouseCredentials,
394
401
  });
395
402
  // Update
403
+ const previewSettings = await (0, timestampConversion_1.getProjectDeploySettings)(options.disableTimestampConversion, previewProject.projectUuid);
396
404
  options.disableTimestampConversion =
397
- await (0, timestampConversion_1.getProjectDisableTimestampConversion)(options.disableTimestampConversion, previewProject.projectUuid);
405
+ previewSettings.disableTimestampConversion;
398
406
  const { explores, isProjectComplete } = await (0, compile_1.compileProject)(options);
399
407
  await (0, deploy_1.deploy)(explores, {
400
408
  ...options,
401
409
  projectUuid: previewProject.projectUuid,
410
+ ...(await previewDeployDestination({
411
+ projectUuid: previewProject.projectUuid,
412
+ connectionRoute: previewSettings.connectionRoute,
413
+ }, options, projectTypeConfig.type, config.context?.project)),
402
414
  complete: isProjectComplete,
403
415
  });
404
416
  const url = await projectUrl(previewProject);
@@ -460,6 +472,7 @@ const startPreviewHandler = async (originalOptions) => {
460
472
  await (0, deploy_1.deploy)(explores, {
461
473
  ...options,
462
474
  projectUuid: project.projectUuid,
475
+ ...(await previewDeployDestination(project, options, projectTypeConfig.type, config.context?.project)),
463
476
  complete: isProjectComplete,
464
477
  });
465
478
  const url = await projectUrl(project);
@@ -0,0 +1,7 @@
1
+ import { type ProjectDbtSourceSummary } from '@lightdash/common';
2
+ export declare const selectProjectSource: (sources: ProjectDbtSourceSummary[], name: string) => ProjectDbtSourceSummary;
3
+ export declare const resolveProjectSourceUuid: (projectUuid: string, sourceOverride: string | undefined, configuredProjectUuid?: string) => Promise<string | undefined>;
4
+ export declare const setSourceHandler: (name: string, options: {
5
+ verbose: boolean;
6
+ }) => Promise<void>;
7
+ //# sourceMappingURL=sourceSelection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sourceSelection.d.ts","sourceRoot":"","sources":["../../src/handlers/sourceSelection.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,KAAK,uBAAuB,EAC/B,MAAM,mBAAmB,CAAC;AAQ3B,eAAO,MAAM,mBAAmB,YACnB,uBAAuB,EAAE,QAC5B,MAAM,KACb,uBAQF,CAAC;AAWF,eAAO,MAAM,wBAAwB,gBACpB,MAAM,kBACH,MAAM,GAAG,SAAS,0BACX,MAAM,KAC9B,OAAO,CAAC,MAAM,GAAG,SAAS,CAU5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,SACnB,MAAM,WACH;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,kBAehC,CAAC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setSourceHandler = exports.resolveProjectSourceUuid = exports.selectProjectSource = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@lightdash/common");
6
+ const config_1 = require("../config");
7
+ const globalState_1 = tslib_1.__importDefault(require("../globalState"));
8
+ const apiClient_1 = require("./dbt/apiClient");
9
+ const formatSourceNames = (sources) => sources.map(({ name }) => ` - ${name}`).join('\n');
10
+ const selectProjectSource = (sources, name) => {
11
+ const selected = sources.find((source) => source.name === name);
12
+ if (!selected) {
13
+ throw new Error(`The dbt source "${name}" does not belong to this project.\n\nAvailable sources:\n${formatSourceNames(sources)}`);
14
+ }
15
+ return selected;
16
+ };
17
+ exports.selectProjectSource = selectProjectSource;
18
+ const getProjectSources = async (projectUuid) => (0, apiClient_1.lightdashApi)({
19
+ method: 'GET',
20
+ url: `/api/v1/projects/${projectUuid}/dbt-sources`,
21
+ body: undefined,
22
+ });
23
+ const resolveProjectSourceUuid = async (projectUuid, sourceOverride, configuredProjectUuid = projectUuid) => {
24
+ const config = await (0, config_1.getConfig)();
25
+ const name = sourceOverride ??
26
+ (config.context?.project === configuredProjectUuid
27
+ ? config.context.source
28
+ : undefined);
29
+ if (name === undefined)
30
+ return undefined;
31
+ return (0, exports.selectProjectSource)(await getProjectSources(projectUuid), name)
32
+ .projectDbtSourceUuid;
33
+ };
34
+ exports.resolveProjectSourceUuid = resolveProjectSourceUuid;
35
+ const setSourceHandler = async (name, options) => {
36
+ globalState_1.default.setVerbose(options.verbose);
37
+ const config = await (0, config_1.getConfig)();
38
+ if (!config.context?.project) {
39
+ throw new common_1.AuthorizationError(`No project selected. Run 'lightdash config set-project' first.`);
40
+ }
41
+ const source = (0, exports.selectProjectSource)(await getProjectSources(config.context.project), name);
42
+ await (0, config_1.setSource)(source.name);
43
+ console.error(`\n ✅️ Selected dbt source: ${source.name}\n`);
44
+ };
45
+ exports.setSourceHandler = setSourceHandler;
@@ -1,9 +1,8 @@
1
- import { Project } from '@lightdash/common';
1
+ import { Project, type ConnectionRoute } from '@lightdash/common';
2
2
  export declare const getDisableTimestampConversionFromProject: (warehouseConnection: Project['warehouseConnection']) => boolean | undefined;
3
- /**
4
- * Reads `disableTimestampConversion` from an existing project's settings.
5
- * The CLI flag is ignored for commands targeting an existing project — the
6
- * project settings are the source of truth.
7
- */
3
+ export declare const getProjectDeploySettings: (cliValue: boolean | undefined, projectUuid: string) => Promise<{
4
+ disableTimestampConversion: boolean | undefined;
5
+ connectionRoute: ConnectionRoute | undefined;
6
+ }>;
8
7
  export declare const getProjectDisableTimestampConversion: (cliValue: boolean | undefined, projectUuid: string) => Promise<boolean | undefined>;
9
8
  //# sourceMappingURL=timestampConversion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"timestampConversion.d.ts","sourceRoot":"","sources":["../../src/handlers/timestampConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,OAAO,EAAkB,MAAM,mBAAmB,CAAC;AAK7E,eAAO,MAAM,wCAAwC,wBAC5B,OAAO,CAAC,qBAAqB,CAAC,KACpD,OAAO,GAAG,SAGM,CAAC;AAEpB;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,aACnC,OAAO,GAAG,SAAS,eAChB,MAAM,KACpB,OAAO,CAAC,OAAO,GAAG,SAAS,CAgC7B,CAAC"}
1
+ {"version":3,"file":"timestampConversion.d.ts","sourceRoot":"","sources":["../../src/handlers/timestampConversion.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,OAAO,EAEP,KAAK,eAAe,EACvB,MAAM,mBAAmB,CAAC;AAK3B,eAAO,MAAM,wCAAwC,wBAC5B,OAAO,CAAC,qBAAqB,CAAC,KACpD,OAAO,GAAG,SAGM,CAAC;AAEpB,eAAO,MAAM,wBAAwB,aACvB,OAAO,GAAG,SAAS,eAChB,MAAM,KACpB,OAAO,CAAC;IACP,0BAA0B,EAAE,OAAO,GAAG,SAAS,CAAC;IAChD,eAAe,EAAE,eAAe,GAAG,SAAS,CAAC;CAChD,CAsCA,CAAC;AAEF,eAAO,MAAM,oCAAoC,aACnC,OAAO,GAAG,SAAS,eAChB,MAAM,KACpB,OAAO,CAAC,OAAO,GAAG,SAAS,CAEK,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProjectDisableTimestampConversion = exports.getDisableTimestampConversionFromProject = void 0;
3
+ exports.getProjectDisableTimestampConversion = exports.getProjectDeploySettings = exports.getDisableTimestampConversionFromProject = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const common_1 = require("@lightdash/common");
6
6
  const globalState_1 = tslib_1.__importDefault(require("../globalState"));
@@ -10,12 +10,7 @@ const getDisableTimestampConversionFromProject = (warehouseConnection) => wareho
10
10
  ? warehouseConnection.disableTimestampConversion
11
11
  : undefined;
12
12
  exports.getDisableTimestampConversionFromProject = getDisableTimestampConversionFromProject;
13
- /**
14
- * Reads `disableTimestampConversion` from an existing project's settings.
15
- * The CLI flag is ignored for commands targeting an existing project — the
16
- * project settings are the source of truth.
17
- */
18
- const getProjectDisableTimestampConversion = async (cliValue, projectUuid) => {
13
+ const getProjectDeploySettings = async (cliValue, projectUuid) => {
19
14
  if (cliValue !== undefined) {
20
15
  console.error(styles.warning('Ignoring --disable-timestamp-conversion: this command reads the setting from the project settings.'));
21
16
  }
@@ -27,11 +22,20 @@ const getProjectDisableTimestampConversion = async (cliValue, projectUuid) => {
27
22
  });
28
23
  const disableTimestampConversion = (0, exports.getDisableTimestampConversionFromProject)(project.warehouseConnection);
29
24
  globalState_1.default.debug(`> Using disable-timestamp-conversion=${String(disableTimestampConversion ?? false)} from project settings`);
30
- return disableTimestampConversion;
25
+ return {
26
+ disableTimestampConversion,
27
+ connectionRoute: project.connectionRoute,
28
+ };
31
29
  }
32
30
  catch (e) {
33
31
  globalState_1.default.debug(`> Could not fetch project settings for timestamp conversion: ${(0, common_1.getErrorMessage)(e)}`);
34
- return undefined;
32
+ return {
33
+ disableTimestampConversion: undefined,
34
+ connectionRoute: undefined,
35
+ };
35
36
  }
36
37
  };
38
+ exports.getProjectDeploySettings = getProjectDeploySettings;
39
+ const getProjectDisableTimestampConversion = async (cliValue, projectUuid) => (await (0, exports.getProjectDeploySettings)(cliValue, projectUuid))
40
+ .disableTimestampConversion;
37
41
  exports.getProjectDisableTimestampConversion = getProjectDisableTimestampConversion;
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ const runChart_1 = require("./handlers/runChart");
35
35
  const setProject_1 = require("./handlers/setProject");
36
36
  const setWarehouse_1 = require("./handlers/setWarehouse");
37
37
  const slugUpdate_1 = require("./handlers/slugUpdate");
38
+ const sourceSelection_1 = require("./handlers/sourceSelection");
38
39
  const sql_1 = require("./handlers/sql");
39
40
  const upgradeCheck_1 = require("./handlers/upgradeCheck");
40
41
  const validate_2 = require("./handlers/validate");
@@ -161,6 +162,11 @@ configProgram
161
162
  .addOption(new commander_1.Option('--name <project_name>', 'Set the project non-interactively by passing a project name.'))
162
163
  .addOption(new commander_1.Option('--uuid <project_uuid>', 'Set the project non-interactively by passing a project uuid.').conflicts('name'))
163
164
  .action(setProject_1.setProjectHandler);
165
+ configProgram
166
+ .command('set-source <name>')
167
+ .description('Choose the dbt source that deploys to the active project use, by name.')
168
+ .option('--verbose', undefined, false)
169
+ .action(sourceSelection_1.setSourceHandler);
164
170
  configProgram
165
171
  .command('list-projects')
166
172
  .description('List all projects in the organization (excludes preview projects)')
@@ -245,6 +251,7 @@ commander_1.program
245
251
  commander_1.program
246
252
  .command('preview')
247
253
  .description('Creates a new preview project - waits for a keypress to stop')
254
+ .option('--source <name>', 'The dbt source to deploy, by name. Its explores use the warehouse connection of that source. Overrides `lightdash config set-source`')
248
255
  .option('--name <preview name>', 'Custom name for the preview. If a name is not provided, a unique, randomly generated name will be created.')
249
256
  .option('--project-dir <path>', 'The directory of the dbt project', env_1.DEFAULT_DBT_PROJECT_DIR)
250
257
  .option('--profiles-dir <path>', 'The directory of the dbt profiles', env_1.DEFAULT_DBT_PROFILES_DIR)
@@ -288,6 +295,7 @@ commander_1.program
288
295
  commander_1.program
289
296
  .command('start-preview')
290
297
  .description('Creates a new preview project')
298
+ .option('--source <name>', 'The dbt source to deploy, by name. Its explores use the warehouse connection of that source. Overrides `lightdash config set-source`')
291
299
  .option('--name [preview name]', '[required] Name for the preview project. If a preview project with this name already exists, it will be updated, otherwise it will create a new preview project ')
292
300
  .option('--project-dir <path>', 'The directory of the dbt project', env_1.DEFAULT_DBT_PROJECT_DIR)
293
301
  .option('--profiles-dir <path>', 'The directory of the dbt profiles', env_1.DEFAULT_DBT_PROFILES_DIR)
@@ -489,6 +497,7 @@ appsProgram
489
497
  commander_1.program
490
498
  .command('deploy')
491
499
  .description('Compiles and deploys a Lightdash project')
500
+ .option('--source <name>', 'The dbt source to deploy, by name. Its explores use the warehouse connection of that source. Overrides `lightdash config set-source`')
492
501
  .option('--project <project uuid or slug>', 'Project UUID or slug to deploy to. Overrides the default project configured via `lightdash config set-project`')
493
502
  .option('--project-dir <path>', 'The directory of the dbt project', env_1.DEFAULT_DBT_PROJECT_DIR)
494
503
  .option('--profiles-dir <path>', 'The directory of the dbt profiles', env_1.DEFAULT_DBT_PROFILES_DIR)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash/cli",
3
- "version": "2.327.2",
3
+ "version": "2.329.0",
4
4
  "description": "Lightdash CLI tool",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,8 +22,8 @@
22
22
  "@actions/core": "1.11.1",
23
23
  "@aws-sdk/credential-providers": "3.995.0",
24
24
  "@casl/ability": "6.8.0",
25
- "@lightdash/common": "2.327.2",
26
- "@lightdash/warehouses": "2.327.2",
25
+ "@lightdash/common": "2.329.0",
26
+ "@lightdash/warehouses": "2.329.0",
27
27
  "@sidvind/better-ajv-errors": "7.0.0",
28
28
  "@types/columnify": "1.5.1",
29
29
  "ajv": "8.18.0",