@claryai/cli 0.1.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/LICENSE +25 -0
- package/README.md +197 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/ajv.d.ts +3 -0
- package/dist/ajv.d.ts.map +1 -0
- package/dist/ajv.js +13 -0
- package/dist/analytics/analytics.d.ts +370 -0
- package/dist/analytics/analytics.d.ts.map +1 -0
- package/dist/analytics/analytics.js +143 -0
- package/dist/config.d.ts +34 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +134 -0
- package/dist/dbt/context.d.ts +14 -0
- package/dist/dbt/context.d.ts.map +1 -0
- package/dist/dbt/context.js +76 -0
- package/dist/dbt/context.test.d.ts +2 -0
- package/dist/dbt/context.test.d.ts.map +1 -0
- package/dist/dbt/context.test.js +152 -0
- package/dist/dbt/manifest.d.ts +7 -0
- package/dist/dbt/manifest.d.ts.map +1 -0
- package/dist/dbt/manifest.js +23 -0
- package/dist/dbt/models.d.ts +43 -0
- package/dist/dbt/models.d.ts.map +1 -0
- package/dist/dbt/models.js +256 -0
- package/dist/dbt/models.test.d.ts +2 -0
- package/dist/dbt/models.test.d.ts.map +1 -0
- package/dist/dbt/models.test.js +19 -0
- package/dist/dbt/profile.d.ts +9 -0
- package/dist/dbt/profile.d.ts.map +1 -0
- package/dist/dbt/profile.js +86 -0
- package/dist/dbt/profiles.test.d.ts +2 -0
- package/dist/dbt/profiles.test.d.ts.map +1 -0
- package/dist/dbt/profiles.test.js +50 -0
- package/dist/dbt/schema.d.ts +31 -0
- package/dist/dbt/schema.d.ts.map +1 -0
- package/dist/dbt/schema.js +49 -0
- package/dist/dbt/targets/Bigquery/index.d.ts +18 -0
- package/dist/dbt/targets/Bigquery/index.d.ts.map +1 -0
- package/dist/dbt/targets/Bigquery/index.js +105 -0
- package/dist/dbt/targets/Bigquery/oauth.d.ts +2 -0
- package/dist/dbt/targets/Bigquery/oauth.d.ts.map +1 -0
- package/dist/dbt/targets/Bigquery/oauth.js +43 -0
- package/dist/dbt/targets/Bigquery/serviceAccount.d.ts +35 -0
- package/dist/dbt/targets/Bigquery/serviceAccount.d.ts.map +1 -0
- package/dist/dbt/targets/Bigquery/serviceAccount.js +149 -0
- package/dist/dbt/targets/Databricks/oauth.d.ts +21 -0
- package/dist/dbt/targets/Databricks/oauth.d.ts.map +1 -0
- package/dist/dbt/targets/Databricks/oauth.js +184 -0
- package/dist/dbt/targets/athena.d.ts +21 -0
- package/dist/dbt/targets/athena.d.ts.map +1 -0
- package/dist/dbt/targets/athena.js +91 -0
- package/dist/dbt/targets/athena.test.d.ts +2 -0
- package/dist/dbt/targets/athena.test.d.ts.map +1 -0
- package/dist/dbt/targets/athena.test.js +60 -0
- package/dist/dbt/targets/clickhouse.d.ts +24 -0
- package/dist/dbt/targets/clickhouse.d.ts.map +1 -0
- package/dist/dbt/targets/clickhouse.js +90 -0
- package/dist/dbt/targets/databricks.d.ts +27 -0
- package/dist/dbt/targets/databricks.d.ts.map +1 -0
- package/dist/dbt/targets/databricks.js +138 -0
- package/dist/dbt/targets/duckdb.d.ts +16 -0
- package/dist/dbt/targets/duckdb.d.ts.map +1 -0
- package/dist/dbt/targets/duckdb.js +63 -0
- package/dist/dbt/targets/duckdb.test.d.ts +2 -0
- package/dist/dbt/targets/duckdb.test.d.ts.map +1 -0
- package/dist/dbt/targets/duckdb.test.js +37 -0
- package/dist/dbt/targets/postgres.d.ts +26 -0
- package/dist/dbt/targets/postgres.d.ts.map +1 -0
- package/dist/dbt/targets/postgres.js +142 -0
- package/dist/dbt/targets/redshift.d.ts +23 -0
- package/dist/dbt/targets/redshift.d.ts.map +1 -0
- package/dist/dbt/targets/redshift.js +96 -0
- package/dist/dbt/targets/snowflake.d.ts +4 -0
- package/dist/dbt/targets/snowflake.d.ts.map +1 -0
- package/dist/dbt/targets/snowflake.js +134 -0
- package/dist/dbt/targets/trino.d.ts +16 -0
- package/dist/dbt/targets/trino.d.ts.map +1 -0
- package/dist/dbt/targets/trino.js +65 -0
- package/dist/dbt/templating.d.ts +15 -0
- package/dist/dbt/templating.d.ts.map +1 -0
- package/dist/dbt/templating.js +50 -0
- package/dist/dbt/templating.test.d.ts +2 -0
- package/dist/dbt/templating.test.d.ts.map +1 -0
- package/dist/dbt/templating.test.js +51 -0
- package/dist/dbt/types.d.ts +17 -0
- package/dist/dbt/types.d.ts.map +1 -0
- package/dist/dbt/types.js +2 -0
- package/dist/dbt/validation.d.ts +9 -0
- package/dist/dbt/validation.d.ts.map +1 -0
- package/dist/dbt/validation.js +54 -0
- package/dist/env.d.ts +12 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +40 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +12 -0
- package/dist/globalState.d.ts +29 -0
- package/dist/globalState.d.ts.map +1 -0
- package/dist/globalState.js +67 -0
- package/dist/handlers/asyncQuery.d.ts +7 -0
- package/dist/handlers/asyncQuery.d.ts.map +1 -0
- package/dist/handlers/asyncQuery.js +50 -0
- package/dist/handlers/compile.d.ts +16 -0
- package/dist/handlers/compile.d.ts.map +1 -0
- package/dist/handlers/compile.js +277 -0
- package/dist/handlers/compile.test.d.ts +2 -0
- package/dist/handlers/compile.test.d.ts.map +1 -0
- package/dist/handlers/compile.test.js +201 -0
- package/dist/handlers/createProject.d.ts +37 -0
- package/dist/handlers/createProject.d.ts.map +1 -0
- package/dist/handlers/createProject.js +272 -0
- package/dist/handlers/dbt/apiClient.d.ts +14 -0
- package/dist/handlers/dbt/apiClient.d.ts.map +1 -0
- package/dist/handlers/dbt/apiClient.js +167 -0
- package/dist/handlers/dbt/compile.d.ts +35 -0
- package/dist/handlers/dbt/compile.d.ts.map +1 -0
- package/dist/handlers/dbt/compile.js +220 -0
- package/dist/handlers/dbt/getDbtProfileTargetName.d.ts +9 -0
- package/dist/handlers/dbt/getDbtProfileTargetName.d.ts.map +1 -0
- package/dist/handlers/dbt/getDbtProfileTargetName.js +44 -0
- package/dist/handlers/dbt/getDbtVersion.d.ts +16 -0
- package/dist/handlers/dbt/getDbtVersion.d.ts.map +1 -0
- package/dist/handlers/dbt/getDbtVersion.js +141 -0
- package/dist/handlers/dbt/getDbtVersion.mocks.d.ts +11 -0
- package/dist/handlers/dbt/getDbtVersion.mocks.d.ts.map +1 -0
- package/dist/handlers/dbt/getDbtVersion.mocks.js +70 -0
- package/dist/handlers/dbt/getDbtVersion.test.d.ts +2 -0
- package/dist/handlers/dbt/getDbtVersion.test.d.ts.map +1 -0
- package/dist/handlers/dbt/getDbtVersion.test.js +97 -0
- package/dist/handlers/dbt/getWarehouseClient.d.ts +24 -0
- package/dist/handlers/dbt/getWarehouseClient.d.ts.map +1 -0
- package/dist/handlers/dbt/getWarehouseClient.js +312 -0
- package/dist/handlers/dbt/refresh.d.ts +11 -0
- package/dist/handlers/dbt/refresh.d.ts.map +1 -0
- package/dist/handlers/dbt/refresh.js +114 -0
- package/dist/handlers/dbt/run.d.ts +14 -0
- package/dist/handlers/dbt/run.d.ts.map +1 -0
- package/dist/handlers/dbt/run.js +67 -0
- package/dist/handlers/deploy.d.ts +26 -0
- package/dist/handlers/deploy.d.ts.map +1 -0
- package/dist/handlers/deploy.js +377 -0
- package/dist/handlers/diagnostics.d.ts +11 -0
- package/dist/handlers/diagnostics.d.ts.map +1 -0
- package/dist/handlers/diagnostics.js +194 -0
- package/dist/handlers/download.d.ts +29 -0
- package/dist/handlers/download.d.ts.map +1 -0
- package/dist/handlers/download.js +955 -0
- package/dist/handlers/exportChartImage.d.ts +7 -0
- package/dist/handlers/exportChartImage.d.ts.map +1 -0
- package/dist/handlers/exportChartImage.js +33 -0
- package/dist/handlers/generate.d.ts +13 -0
- package/dist/handlers/generate.d.ts.map +1 -0
- package/dist/handlers/generate.js +159 -0
- package/dist/handlers/generateExposures.d.ts +8 -0
- package/dist/handlers/generateExposures.d.ts.map +1 -0
- package/dist/handlers/generateExposures.js +100 -0
- package/dist/handlers/getProject.d.ts +6 -0
- package/dist/handlers/getProject.d.ts.map +1 -0
- package/dist/handlers/getProject.js +43 -0
- package/dist/handlers/installSkills.d.ts +12 -0
- package/dist/handlers/installSkills.d.ts.map +1 -0
- package/dist/handlers/installSkills.js +321 -0
- package/dist/handlers/lint/ajvToSarif.d.ts +66 -0
- package/dist/handlers/lint/ajvToSarif.d.ts.map +1 -0
- package/dist/handlers/lint/ajvToSarif.js +222 -0
- package/dist/handlers/lint/sarifFormatter.d.ts +14 -0
- package/dist/handlers/lint/sarifFormatter.d.ts.map +1 -0
- package/dist/handlers/lint/sarifFormatter.js +111 -0
- package/dist/handlers/lint.d.ts +8 -0
- package/dist/handlers/lint.d.ts.map +1 -0
- package/dist/handlers/lint.js +308 -0
- package/dist/handlers/listProjects.d.ts +6 -0
- package/dist/handlers/listProjects.d.ts.map +1 -0
- package/dist/handlers/listProjects.js +53 -0
- package/dist/handlers/login/oauth.d.ts +2 -0
- package/dist/handlers/login/oauth.d.ts.map +1 -0
- package/dist/handlers/login/oauth.js +27 -0
- package/dist/handlers/login/pat.d.ts +2 -0
- package/dist/handlers/login/pat.d.ts.map +1 -0
- package/dist/handlers/login/pat.js +31 -0
- package/dist/handlers/login.d.ts +15 -0
- package/dist/handlers/login.d.ts.map +1 -0
- package/dist/handlers/login.js +239 -0
- package/dist/handlers/metadataFile.d.ts +9 -0
- package/dist/handlers/metadataFile.d.ts.map +1 -0
- package/dist/handlers/metadataFile.js +34 -0
- package/dist/handlers/oauthLogin.d.ts +6 -0
- package/dist/handlers/oauthLogin.d.ts.map +1 -0
- package/dist/handlers/oauthLogin.js +191 -0
- package/dist/handlers/preview.d.ts +29 -0
- package/dist/handlers/preview.d.ts.map +1 -0
- package/dist/handlers/preview.js +415 -0
- package/dist/handlers/renameHandler.d.ts +16 -0
- package/dist/handlers/renameHandler.d.ts.map +1 -0
- package/dist/handlers/renameHandler.js +160 -0
- package/dist/handlers/runChart.d.ts +10 -0
- package/dist/handlers/runChart.d.ts.map +1 -0
- package/dist/handlers/runChart.js +105 -0
- package/dist/handlers/selectProject.d.ts +20 -0
- package/dist/handlers/selectProject.d.ts.map +1 -0
- package/dist/handlers/selectProject.js +91 -0
- package/dist/handlers/setProject.d.ts +14 -0
- package/dist/handlers/setProject.d.ts.map +1 -0
- package/dist/handlers/setProject.js +131 -0
- package/dist/handlers/setWarehouse.d.ts +14 -0
- package/dist/handlers/setWarehouse.d.ts.map +1 -0
- package/dist/handlers/setWarehouse.js +94 -0
- package/dist/handlers/sql.d.ts +9 -0
- package/dist/handlers/sql.d.ts.map +1 -0
- package/dist/handlers/sql.js +89 -0
- package/dist/handlers/utils.d.ts +11 -0
- package/dist/handlers/utils.d.ts.map +1 -0
- package/dist/handlers/utils.js +36 -0
- package/dist/handlers/validate.d.ts +22 -0
- package/dist/handlers/validate.d.ts.map +1 -0
- package/dist/handlers/validate.js +201 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +581 -0
- package/dist/lightdash/loader.d.ts +21 -0
- package/dist/lightdash/loader.d.ts.map +1 -0
- package/dist/lightdash/loader.js +122 -0
- package/dist/lightdash/projectType.d.ts +84 -0
- package/dist/lightdash/projectType.d.ts.map +1 -0
- package/dist/lightdash/projectType.js +75 -0
- package/dist/lightdash-config/index.d.ts +2 -0
- package/dist/lightdash-config/index.d.ts.map +1 -0
- package/dist/lightdash-config/index.js +41 -0
- package/dist/lightdash-config/lightdash-config.test.d.ts +2 -0
- package/dist/lightdash-config/lightdash-config.test.d.ts.map +1 -0
- package/dist/lightdash-config/lightdash-config.test.js +70 -0
- package/dist/styles.d.ts +10 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +14 -0
- package/entitlements.plist +33 -0
- package/package.json +71 -0
- package/track.sh +116 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dbtCompile = void 0;
|
|
4
|
+
exports.dbtList = dbtList;
|
|
5
|
+
exports.maybeCompileModelsAndJoins = maybeCompileModelsAndJoins;
|
|
6
|
+
const tslib_1 = require("tslib");
|
|
7
|
+
const common_1 = require("@lightdash/common");
|
|
8
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
const path = tslib_1.__importStar(require("path"));
|
|
12
|
+
const manifest_1 = require("../../dbt/manifest");
|
|
13
|
+
const globalState_1 = tslib_1.__importDefault(require("../../globalState"));
|
|
14
|
+
const getDbtVersion_1 = require("./getDbtVersion");
|
|
15
|
+
const dbtCompileArgs = [
|
|
16
|
+
'profilesDir',
|
|
17
|
+
'projectDir',
|
|
18
|
+
'target',
|
|
19
|
+
'profile',
|
|
20
|
+
'select',
|
|
21
|
+
'models',
|
|
22
|
+
'vars',
|
|
23
|
+
'threads',
|
|
24
|
+
'noVersionCheck',
|
|
25
|
+
'exclude',
|
|
26
|
+
'selector',
|
|
27
|
+
'state',
|
|
28
|
+
'fullRefresh',
|
|
29
|
+
'defer',
|
|
30
|
+
'targetPath',
|
|
31
|
+
'favorState',
|
|
32
|
+
];
|
|
33
|
+
const camelToSnakeCase = (str) => str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
34
|
+
const optionsToArgs = (options) => Object.entries(options).reduce((acc, [key, value]) => {
|
|
35
|
+
if (value !== undefined && dbtCompileArgs.includes(key)) {
|
|
36
|
+
const argKey = `--${camelToSnakeCase(key)}`;
|
|
37
|
+
if (typeof value !== 'boolean') {
|
|
38
|
+
return [
|
|
39
|
+
...acc,
|
|
40
|
+
argKey,
|
|
41
|
+
Array.isArray(value) ? value.join(' ') : value,
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
return [...acc, argKey];
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, []);
|
|
48
|
+
const dbtCompile = async (options) => {
|
|
49
|
+
try {
|
|
50
|
+
const args = optionsToArgs(options);
|
|
51
|
+
globalState_1.default.debug(`> Running: dbt compile ${args.join(' ')}`);
|
|
52
|
+
const { stdout, stderr } = await (0, execa_1.default)('dbt', ['compile', ...args]);
|
|
53
|
+
console.error(stdout);
|
|
54
|
+
console.error(stderr);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
const msg = (0, common_1.getErrorMessage)(e);
|
|
58
|
+
throw new common_1.ParseError(`Failed to run dbt compile:\n ${msg}`);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
exports.dbtCompile = dbtCompile;
|
|
62
|
+
/**
|
|
63
|
+
* Reads run_results.json written by dbt after each compile/run to get the
|
|
64
|
+
* unique_ids of models that were actually processed in THIS run.
|
|
65
|
+
* This is more reliable than manifest.compiled, which can contain stale flags
|
|
66
|
+
* from previous runs (e.g. when state:modified+ selects 0 models, all previously
|
|
67
|
+
* compiled models still have compiled=true in the manifest).
|
|
68
|
+
*/
|
|
69
|
+
async function getCompiledModelIdsFromRunResults(targetDir) {
|
|
70
|
+
const runResultsPath = path.join(targetDir, 'run_results.json');
|
|
71
|
+
try {
|
|
72
|
+
const content = await fs_1.promises.readFile(runResultsPath, {
|
|
73
|
+
encoding: 'utf-8',
|
|
74
|
+
});
|
|
75
|
+
const runResults = JSON.parse(content);
|
|
76
|
+
const modelIds = runResults.results
|
|
77
|
+
.map((r) => r.unique_id)
|
|
78
|
+
.filter((id) => id.startsWith('model.'));
|
|
79
|
+
globalState_1.default.debug(`> Read ${modelIds.length} model(s) from run_results.json`);
|
|
80
|
+
return modelIds;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
globalState_1.default.debug(`> Warning: Could not read run_results.json from ${runResultsPath}: ${(0, common_1.getErrorMessage)(e)}`);
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const getJoinedModelsRecursively = (modelNode, allModelNodes, visited = new Set()) => {
|
|
88
|
+
if (visited.has(modelNode.name)) {
|
|
89
|
+
globalState_1.default.debug(`Already visited ${modelNode.name}. Skipping.`);
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
globalState_1.default.debug(`Getting joined models for ${modelNode.name}`);
|
|
93
|
+
visited.add(modelNode.name);
|
|
94
|
+
const joinedModelNames = modelNode.unrendered_config?.meta?.joins?.map((j) => j.join);
|
|
95
|
+
if (!joinedModelNames) {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
const joinedModelNodes = allModelNodes.filter((model) => joinedModelNames.includes(model.name));
|
|
99
|
+
return joinedModelNodes.reduce((acc, model) => [
|
|
100
|
+
...acc,
|
|
101
|
+
model.name,
|
|
102
|
+
...getJoinedModelsRecursively(model, allModelNodes, visited),
|
|
103
|
+
], []);
|
|
104
|
+
};
|
|
105
|
+
async function dbtList(options) {
|
|
106
|
+
try {
|
|
107
|
+
const args = [
|
|
108
|
+
...optionsToArgs(options),
|
|
109
|
+
'--output',
|
|
110
|
+
'json',
|
|
111
|
+
'--output-keys',
|
|
112
|
+
'unique_id',
|
|
113
|
+
];
|
|
114
|
+
const version = await (0, getDbtVersion_1.getDbtVersion)();
|
|
115
|
+
// only dbt 1.5 and above support --quiet flag
|
|
116
|
+
if (version.versionOption !== common_1.SupportedDbtVersions.V1_4) {
|
|
117
|
+
args.push('--quiet');
|
|
118
|
+
}
|
|
119
|
+
globalState_1.default.debug(`> Running: dbt ls ${args.join(' ')}`);
|
|
120
|
+
const { stdout, stderr } = await (0, execa_1.default)('dbt', ['ls', ...args]);
|
|
121
|
+
const models = stdout
|
|
122
|
+
.split('\n')
|
|
123
|
+
.map((line) => {
|
|
124
|
+
try {
|
|
125
|
+
// remove prefixed time in dbt cloud cli output
|
|
126
|
+
const lineWithoutPrefixedTime = line.replace(/^\d{2}:\d{2}:\d{2}\s*/, '');
|
|
127
|
+
return JSON.parse(lineWithoutPrefixedTime).unique_id;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// ignore non-json lines
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
.filter((modelId) => modelId.startsWith('model.')); // filter models by name because "--models" and "--resource_type" are mutually exclusive arguments
|
|
135
|
+
globalState_1.default.debug(`> Models: ${models.join(' ')}`);
|
|
136
|
+
console.error(stderr);
|
|
137
|
+
return models;
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
const msg = (0, common_1.getErrorMessage)(e);
|
|
141
|
+
throw new common_1.ParseError(`Error executing 'dbt ls':\n ${msg}\nEnsure you're on the latest patch version. '--use-dbt-list' is true by default; if you encounter issues, try using '--use-dbt-list=false`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async function maybeCompileModelsAndJoins(loadManifestOpts, initialOptions) {
|
|
145
|
+
const dbtVersion = await (0, getDbtVersion_1.getDbtVersion)();
|
|
146
|
+
let options = initialOptions;
|
|
147
|
+
if (dbtVersion.isDbtCloudCLI) {
|
|
148
|
+
options = {
|
|
149
|
+
...initialOptions,
|
|
150
|
+
projectDir: undefined,
|
|
151
|
+
profilesDir: undefined,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// Skipping assumes manifest.json already exists.
|
|
155
|
+
if (options.skipDbtCompile) {
|
|
156
|
+
// Check for incompatible selection options
|
|
157
|
+
if (options.select ||
|
|
158
|
+
options.exclude ||
|
|
159
|
+
options.selector ||
|
|
160
|
+
options.models) {
|
|
161
|
+
throw new common_1.ParseError('Model selection options (--select, --exclude, --selector, --models) cannot be used with --skip-dbt-compile. ' +
|
|
162
|
+
'Model selection requires running dbt commands to determine which models match the criteria.');
|
|
163
|
+
}
|
|
164
|
+
globalState_1.default.debug('> Skipping dbt compile');
|
|
165
|
+
return {
|
|
166
|
+
compiledModelIds: undefined,
|
|
167
|
+
originallySelectedModelIds: undefined,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// do initial compilation so we can get the list of models that are compiled after this command (e.g. selecting/excluding by tags)
|
|
171
|
+
let compiledModelIds;
|
|
172
|
+
if (options.useDbtList) {
|
|
173
|
+
compiledModelIds = await dbtList(options);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
await (0, exports.dbtCompile)(options);
|
|
177
|
+
compiledModelIds = await getCompiledModelIdsFromRunResults(loadManifestOpts.targetDir);
|
|
178
|
+
}
|
|
179
|
+
// If no models are explicitly selected or excluded, we don't need to explicitly find joined models
|
|
180
|
+
if (!options.select && !options.exclude) {
|
|
181
|
+
return {
|
|
182
|
+
compiledModelIds,
|
|
183
|
+
originallySelectedModelIds: undefined,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// Load manifest and get all models
|
|
187
|
+
const manifest = await (0, manifest_1.loadManifest)(loadManifestOpts);
|
|
188
|
+
const allManifestModels = (0, common_1.getModelsFromManifest)(manifest);
|
|
189
|
+
const currCompiledModels = (0, common_1.getCompiledModels)(allManifestModels, compiledModelIds);
|
|
190
|
+
// Save the originally selected model IDs (before join expansion)
|
|
191
|
+
const originallySelectedModelIds = currCompiledModels.map((model) => model.unique_id);
|
|
192
|
+
// Get models and their joined models
|
|
193
|
+
const requiredModels = new Set(currCompiledModels.reduce((acc, model) => {
|
|
194
|
+
const joinedModelNames = getJoinedModelsRecursively(model, allManifestModels, new Set(acc));
|
|
195
|
+
return [...acc, model.name, ...joinedModelNames];
|
|
196
|
+
}, []));
|
|
197
|
+
const requiredModelsNames = Array.from(requiredModels);
|
|
198
|
+
const missingJoinedModels = (0, lodash_1.xor)(requiredModelsNames, currCompiledModels.map((model) => model.name));
|
|
199
|
+
if (missingJoinedModels.length > 0) {
|
|
200
|
+
globalState_1.default.debug(`> Recompile project with missing joined models: ${missingJoinedModels.join(', ')}`);
|
|
201
|
+
if (options.useDbtList) {
|
|
202
|
+
return {
|
|
203
|
+
compiledModelIds: await dbtList({
|
|
204
|
+
...options,
|
|
205
|
+
select: requiredModelsNames,
|
|
206
|
+
}),
|
|
207
|
+
originallySelectedModelIds,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
await (0, exports.dbtCompile)({
|
|
211
|
+
...options,
|
|
212
|
+
select: requiredModelsNames,
|
|
213
|
+
});
|
|
214
|
+
return {
|
|
215
|
+
compiledModelIds: undefined,
|
|
216
|
+
originallySelectedModelIds,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return { compiledModelIds, originallySelectedModelIds };
|
|
220
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type GetDbtProfileTargetNameOptions = {
|
|
2
|
+
isDbtCloudCLI: boolean;
|
|
3
|
+
profilesDir: string;
|
|
4
|
+
profile: string;
|
|
5
|
+
target?: string;
|
|
6
|
+
};
|
|
7
|
+
export default function getDbtProfileTargetName(options: GetDbtProfileTargetNameOptions): Promise<string>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=getDbtProfileTargetName.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDbtProfileTargetName.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getDbtProfileTargetName.ts"],"names":[],"mappings":"AA6BA,KAAK,8BAA8B,GAAG;IAClC,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,wBAA8B,uBAAuB,CACjD,OAAO,EAAE,8BAA8B,GACxC,OAAO,CAAC,MAAM,CAAC,CAiBjB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = getDbtProfileTargetName;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@lightdash/common");
|
|
6
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const profile_1 = require("../../dbt/profile");
|
|
9
|
+
const globalState_1 = tslib_1.__importDefault(require("../../globalState"));
|
|
10
|
+
const DBT_CLOUD_TARGET_NAME_REGEX = /Target name\s+(\w+)/;
|
|
11
|
+
const getDbtCloudTargetName = async () => {
|
|
12
|
+
try {
|
|
13
|
+
const { all } = await (0, execa_1.default)('dbt', ['environment', 'show'], {
|
|
14
|
+
all: true,
|
|
15
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
16
|
+
});
|
|
17
|
+
const logs = all || '';
|
|
18
|
+
const targetName = logs.match(DBT_CLOUD_TARGET_NAME_REGEX);
|
|
19
|
+
if (targetName === null || targetName.length === 0) {
|
|
20
|
+
throw new common_1.ParseError(`Can't locate profile target name in 'dbt environment show' response`);
|
|
21
|
+
}
|
|
22
|
+
return targetName[1];
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
throw new common_1.ParseError(`Failed to get profile target name:\n ${(0, common_1.getErrorMessage)(e)}`);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
async function getDbtProfileTargetName(options) {
|
|
29
|
+
let targetName;
|
|
30
|
+
if (options.isDbtCloudCLI) {
|
|
31
|
+
targetName = await getDbtCloudTargetName();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const absoluteProfilesPath = path_1.default.resolve(options.profilesDir);
|
|
35
|
+
globalState_1.default.debug(`> Using profiles dir ${absoluteProfilesPath} and profile ${options.profile}`);
|
|
36
|
+
const { name } = await (0, profile_1.loadDbtTarget)({
|
|
37
|
+
profilesDir: absoluteProfilesPath,
|
|
38
|
+
profileName: options.profile,
|
|
39
|
+
targetName: options.target,
|
|
40
|
+
});
|
|
41
|
+
targetName = name;
|
|
42
|
+
}
|
|
43
|
+
return targetName;
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DbtVersionOption } from '@lightdash/common';
|
|
2
|
+
export declare const DBT_CLOUD_CLI_REGEX: RegExp;
|
|
3
|
+
export type DbtVersion = {
|
|
4
|
+
verboseVersion: string;
|
|
5
|
+
versionOption: DbtVersionOption;
|
|
6
|
+
isDbtCloudCLI: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const getDbtVersion: () => Promise<DbtVersion>;
|
|
9
|
+
export declare const tryGetDbtVersion: () => Promise<{
|
|
10
|
+
success: true;
|
|
11
|
+
version: DbtVersion;
|
|
12
|
+
} | {
|
|
13
|
+
success: false;
|
|
14
|
+
error: unknown;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=getDbtVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDbtVersion.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getDbtVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,gBAAgB,EAMnB,MAAM,mBAAmB,CAAC;AAO3B,eAAO,MAAM,mBAAmB,QAAoB,CAAC;AA0DrD,MAAM,MAAM,UAAU,GAAG;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,gBAAgB,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,aAAa,QAAa,OAAO,CAAC,UAAU,CA8ExD,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAa,OAAO,CAC7C;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAc9E,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryGetDbtVersion = exports.getDbtVersion = exports.DBT_CLOUD_CLI_REGEX = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@lightdash/common");
|
|
6
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
7
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
8
|
+
const globalState_1 = tslib_1.__importDefault(require("../../globalState"));
|
|
9
|
+
const styles = tslib_1.__importStar(require("../../styles"));
|
|
10
|
+
const DBT_CORE_VERSION_REGEX = /installed:.*/;
|
|
11
|
+
exports.DBT_CLOUD_CLI_REGEX = /dbt Cloud CLI.*/;
|
|
12
|
+
const DBT_FUSION_VERSION_REGEX = /dbt-fusion.*/;
|
|
13
|
+
const getDbtCLIVersion = async () => {
|
|
14
|
+
try {
|
|
15
|
+
const { all } = await (0, execa_1.default)('dbt', ['--version'], {
|
|
16
|
+
all: true,
|
|
17
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
18
|
+
});
|
|
19
|
+
const logs = all || '';
|
|
20
|
+
const cloudVersion = logs.match(exports.DBT_CLOUD_CLI_REGEX);
|
|
21
|
+
if (cloudVersion) {
|
|
22
|
+
return cloudVersion[0];
|
|
23
|
+
}
|
|
24
|
+
const fusionVersion = logs.match(DBT_FUSION_VERSION_REGEX);
|
|
25
|
+
if (fusionVersion) {
|
|
26
|
+
return fusionVersion[0]; // eg: dbt-fusion 2.0.0-preview.65
|
|
27
|
+
}
|
|
28
|
+
const version = logs.match(DBT_CORE_VERSION_REGEX);
|
|
29
|
+
if (version === null || version.length === 0)
|
|
30
|
+
throw new common_1.ParseError(`Can't locate dbt --version: ${logs}`);
|
|
31
|
+
return version[0].split(':')[1].trim();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
const msg = (0, common_1.getErrorMessage)(e);
|
|
35
|
+
throw new common_1.ParseError(`Failed to get dbt --version:\n ${msg}`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const isDbtCloudCLI = (version) => version.match(exports.DBT_CLOUD_CLI_REGEX) !== null;
|
|
39
|
+
const getSupportedDbtVersionOption = (version) => {
|
|
40
|
+
if (version.match(exports.DBT_CLOUD_CLI_REGEX))
|
|
41
|
+
return common_1.DbtVersionOptionLatest.LATEST;
|
|
42
|
+
if (version.match(DBT_FUSION_VERSION_REGEX))
|
|
43
|
+
return common_1.DbtVersionOptionLatest.LATEST;
|
|
44
|
+
if (version.startsWith('1.4.'))
|
|
45
|
+
return common_1.SupportedDbtVersions.V1_4;
|
|
46
|
+
if (version.startsWith('1.5.'))
|
|
47
|
+
return common_1.SupportedDbtVersions.V1_5;
|
|
48
|
+
if (version.startsWith('1.6.'))
|
|
49
|
+
return common_1.SupportedDbtVersions.V1_6;
|
|
50
|
+
if (version.startsWith('1.7.'))
|
|
51
|
+
return common_1.SupportedDbtVersions.V1_7;
|
|
52
|
+
if (version.startsWith('1.8.'))
|
|
53
|
+
return common_1.SupportedDbtVersions.V1_8;
|
|
54
|
+
if (version.startsWith('1.9.'))
|
|
55
|
+
return common_1.SupportedDbtVersions.V1_9;
|
|
56
|
+
if (version.startsWith('1.10.'))
|
|
57
|
+
return common_1.SupportedDbtVersions.V1_10;
|
|
58
|
+
if (version.startsWith('1.11.'))
|
|
59
|
+
return common_1.SupportedDbtVersions.V1_11;
|
|
60
|
+
// No supported version found
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
const getFallbackDbtVersionOption = (version) => {
|
|
64
|
+
if (version.startsWith('1.3.'))
|
|
65
|
+
return common_1.SupportedDbtVersions.V1_4; // legacy|deprecated support for dbt 1.3
|
|
66
|
+
return (0, common_1.getLatestSupportDbtVersion)();
|
|
67
|
+
};
|
|
68
|
+
const getDbtVersion = async () => {
|
|
69
|
+
const verboseVersion = await getDbtCLIVersion();
|
|
70
|
+
const supportedVersionOption = getSupportedDbtVersionOption(verboseVersion);
|
|
71
|
+
const fallbackVersionOption = getFallbackDbtVersionOption(verboseVersion);
|
|
72
|
+
const isSupported = !!supportedVersionOption;
|
|
73
|
+
if (!isSupported &&
|
|
74
|
+
!globalState_1.default.getSavedPromptAnswer('useFallbackDbtVersion')) {
|
|
75
|
+
const versions = Object.values(common_1.SupportedDbtVersions);
|
|
76
|
+
const supportedVersionsRangeMessage = `${versions[0]}.* - ${versions[versions.length - 1]}.*`;
|
|
77
|
+
const message = `We don't currently support version ${verboseVersion} on Lightdash. We'll interpret it as version ${fallbackVersionOption} instead, which might cause unexpected errors or behavior. For the best experience, please use a supported version (${supportedVersionsRangeMessage}).`;
|
|
78
|
+
const spinner = globalState_1.default.getActiveSpinner();
|
|
79
|
+
spinner?.stop();
|
|
80
|
+
if (globalState_1.default.isNonInteractive()) {
|
|
81
|
+
console.error(styles.warning(message));
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const answers = await inquirer_1.default.prompt([
|
|
85
|
+
{
|
|
86
|
+
type: 'confirm',
|
|
87
|
+
name: 'isConfirm',
|
|
88
|
+
message: `${styles.warning(message)}\nDo you still want to continue?`,
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
if (!answers.isConfirm) {
|
|
92
|
+
console.error(styles.error(`Unsupported dbt version ${verboseVersion}. Please consider using a supported version (${supportedVersionsRangeMessage}).`));
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
spinner?.start();
|
|
97
|
+
globalState_1.default.savePromptAnswer('useFallbackDbtVersion', true);
|
|
98
|
+
}
|
|
99
|
+
if (isDbtCloudCLI(verboseVersion) &&
|
|
100
|
+
!globalState_1.default.getSavedPromptAnswer('useExperimentalDbtCloudCLI')) {
|
|
101
|
+
const message = `Support for dbt Cloud CLI is still experimental and might not work as expected.`;
|
|
102
|
+
const spinner = globalState_1.default.getActiveSpinner();
|
|
103
|
+
spinner?.stop();
|
|
104
|
+
if (globalState_1.default.isNonInteractive()) {
|
|
105
|
+
console.error(styles.warning(message));
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const answers = await inquirer_1.default.prompt([
|
|
109
|
+
{
|
|
110
|
+
type: 'confirm',
|
|
111
|
+
name: 'isConfirm',
|
|
112
|
+
message: `${styles.warning(message)}\nDo you still want to continue?`,
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
if (!answers.isConfirm) {
|
|
116
|
+
console.error(styles.error(`Command using dbt cloud CLI has been canceled. Please consider using dbt core CLI for the best experience.`));
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
spinner?.start();
|
|
121
|
+
globalState_1.default.savePromptAnswer('useExperimentalDbtCloudCLI', true);
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
verboseVersion,
|
|
125
|
+
isDbtCloudCLI: isDbtCloudCLI(verboseVersion),
|
|
126
|
+
versionOption: supportedVersionOption ?? fallbackVersionOption,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
exports.getDbtVersion = getDbtVersion;
|
|
130
|
+
const tryGetDbtVersion = async () => {
|
|
131
|
+
try {
|
|
132
|
+
const version = await (0, exports.getDbtVersion)();
|
|
133
|
+
globalState_1.default.debug(`> dbt version ${version.verboseVersion}`);
|
|
134
|
+
return { success: true, version };
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
globalState_1.default.debug(`> dbt installation not found: ${(0, common_1.getErrorMessage)(e)} (might be using Lightdash YAML only)`);
|
|
138
|
+
return { success: false, error: e };
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
exports.tryGetDbtVersion = tryGetDbtVersion;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExecaError, ExecaReturnValue } from 'execa';
|
|
2
|
+
export declare const cliMocks: {
|
|
3
|
+
dbt1_3: Partial<ExecaReturnValue>;
|
|
4
|
+
dbt1_4: Partial<ExecaReturnValue>;
|
|
5
|
+
dbt1_9: Partial<ExecaReturnValue>;
|
|
6
|
+
dbt1_11: Partial<ExecaReturnValue>;
|
|
7
|
+
dbtCloud: Partial<ExecaReturnValue>;
|
|
8
|
+
dbt20_1: Partial<ExecaReturnValue>;
|
|
9
|
+
error: Partial<ExecaError>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=getDbtVersion.mocks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDbtVersion.mocks.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getDbtVersion.mocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAErD,eAAO,MAAM,QAAQ;YAMZ,OAAO,CAAC,gBAAgB,CAAC;YAuBzB,OAAO,CAAC,gBAAgB,CAAC;YAczB,OAAO,CAAC,gBAAgB,CAAC;aAczB,OAAO,CAAC,gBAAgB,CAAC;cAGzB,OAAO,CAAC,gBAAgB,CAAC;aAMzB,OAAO,CAAC,gBAAgB,CAAC;WAIzB,OAAO,CAAC,UAAU,CAAC;CAC3B,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cliMocks = void 0;
|
|
4
|
+
exports.cliMocks = {
|
|
5
|
+
dbt1_3: {
|
|
6
|
+
all: 'Core:\n' +
|
|
7
|
+
' - installed: 1.3.0\n' +
|
|
8
|
+
' - latest: 1.9.1 - Update available!\n',
|
|
9
|
+
},
|
|
10
|
+
dbt1_4: {
|
|
11
|
+
all: 'Core:\n' +
|
|
12
|
+
' - installed: 1.4.9\n' +
|
|
13
|
+
' - latest: 1.9.1 - Update available!\n' +
|
|
14
|
+
'\n' +
|
|
15
|
+
' Your version of dbt-core is out of date!\n' +
|
|
16
|
+
' You can find instructions for upgrading here:\n' +
|
|
17
|
+
' https://docs.getdbt.com/docs/installation\n' +
|
|
18
|
+
'\n' +
|
|
19
|
+
'Plugins:\n' +
|
|
20
|
+
' - trino: 1.4.2 - Update available!\n' +
|
|
21
|
+
' - databricks: 1.4.3 - Update available!\n' +
|
|
22
|
+
' - redshift: 1.4.1 - Update available!\n' +
|
|
23
|
+
' - spark: 1.4.3 - Update available!\n' +
|
|
24
|
+
' - bigquery: 1.4.5 - Update available!\n' +
|
|
25
|
+
' - snowflake: 1.4.5 - Update available!\n' +
|
|
26
|
+
' - postgres: 1.4.9 - Update available!\n' +
|
|
27
|
+
'\n' +
|
|
28
|
+
' At least one plugin is out of date or incompatible with dbt-core.\n' +
|
|
29
|
+
' You can find instructions for upgrading here:\n' +
|
|
30
|
+
' https://docs.getdbt.com/docs/installation\n',
|
|
31
|
+
},
|
|
32
|
+
dbt1_9: {
|
|
33
|
+
all: 'Core:\n' +
|
|
34
|
+
' - installed: 1.9.1\n' +
|
|
35
|
+
' - latest: 1.9.1 - Up to date!\n' +
|
|
36
|
+
'\n' +
|
|
37
|
+
'Plugins:\n' +
|
|
38
|
+
' - databricks: 1.9.1 - Up to date!\n' +
|
|
39
|
+
' - redshift: 1.9.0 - Up to date!\n' +
|
|
40
|
+
' - spark: 1.9.0 - Up to date!\n' +
|
|
41
|
+
' - bigquery: 1.9.0 - Up to date!\n' +
|
|
42
|
+
' - snowflake: 1.9.0 - Up to date!\n' +
|
|
43
|
+
' - postgres: 1.9.0 - Up to date!\n',
|
|
44
|
+
},
|
|
45
|
+
dbt1_11: {
|
|
46
|
+
all: 'Core:\n' +
|
|
47
|
+
' - installed: 1.11.0\n' +
|
|
48
|
+
' - latest: 1.11.0 - Up to date!\n' +
|
|
49
|
+
'\n' +
|
|
50
|
+
'Plugins:\n' +
|
|
51
|
+
' - databricks: 1.11.0 - Up to date!\n' +
|
|
52
|
+
' - redshift: 1.11.0 - Up to date!\n' +
|
|
53
|
+
' - spark: 1.11.0 - Up to date!\n' +
|
|
54
|
+
' - bigquery: 1.11.0 - Up to date!\n' +
|
|
55
|
+
' - snowflake: 1.11.0 - Up to date!\n' +
|
|
56
|
+
' - postgres: 1.11.0 - Up to date!\n',
|
|
57
|
+
},
|
|
58
|
+
dbtCloud: {
|
|
59
|
+
all: 'dbt Cloud CLI - 0.38.22 (1183c2abdb6003083b0fa91fcd89cd5feb25f9f7 2024-11-20T15:49:01Z)',
|
|
60
|
+
},
|
|
61
|
+
dbt20_1: {
|
|
62
|
+
all: 'Core:\n' +
|
|
63
|
+
' - installed: 20.1.0\n' +
|
|
64
|
+
' - latest: 20.2.0 - Update available!\n',
|
|
65
|
+
},
|
|
66
|
+
error: {
|
|
67
|
+
shortMessage: 'error message',
|
|
68
|
+
all: 'all error messages',
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDbtVersion.test.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getDbtVersion.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const common_1 = require("@lightdash/common");
|
|
5
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
6
|
+
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
7
|
+
const globalState_1 = tslib_1.__importDefault(require("../../globalState"));
|
|
8
|
+
const getDbtVersion_1 = require("./getDbtVersion");
|
|
9
|
+
const getDbtVersion_mocks_1 = require("./getDbtVersion.mocks");
|
|
10
|
+
jest.mock('execa');
|
|
11
|
+
const execaMock = execa_1.default;
|
|
12
|
+
jest.mock('inquirer', () => ({
|
|
13
|
+
prompt: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
const promptMock = inquirer_1.default.prompt;
|
|
16
|
+
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => { });
|
|
17
|
+
describe('Get dbt version', () => {
|
|
18
|
+
const { env } = process;
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.resetAllMocks();
|
|
21
|
+
jest.resetModules();
|
|
22
|
+
process.env = { ...env };
|
|
23
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_4);
|
|
24
|
+
promptMock.mockImplementation(async () => ({ isConfirm: true }));
|
|
25
|
+
globalState_1.default.clearPromptAnswer();
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
process.env = env;
|
|
29
|
+
});
|
|
30
|
+
describe('getDbtVersion', () => {
|
|
31
|
+
test('should return error if dbt cli is not installed', async () => {
|
|
32
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.error);
|
|
33
|
+
await expect((0, getDbtVersion_1.getDbtVersion)()).rejects.toThrowError();
|
|
34
|
+
});
|
|
35
|
+
test('should return supported dbt versions', async () => {
|
|
36
|
+
// Test for 1.4
|
|
37
|
+
const version = await (0, getDbtVersion_1.getDbtVersion)();
|
|
38
|
+
expect(version.verboseVersion).toEqual('1.4.9');
|
|
39
|
+
expect(version.versionOption).toEqual(common_1.SupportedDbtVersions.V1_4);
|
|
40
|
+
// Test for 1.9
|
|
41
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_9);
|
|
42
|
+
const version2 = await (0, getDbtVersion_1.getDbtVersion)();
|
|
43
|
+
expect(version2.verboseVersion).toEqual('1.9.1');
|
|
44
|
+
expect(version2.versionOption).toEqual(common_1.SupportedDbtVersions.V1_9);
|
|
45
|
+
// Test for 1.11
|
|
46
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_11);
|
|
47
|
+
const version3 = await (0, getDbtVersion_1.getDbtVersion)();
|
|
48
|
+
expect(version3.verboseVersion).toEqual('1.11.0');
|
|
49
|
+
expect(version3.versionOption).toEqual(common_1.SupportedDbtVersions.V1_11);
|
|
50
|
+
});
|
|
51
|
+
test('should return latest for dbt cloud', async () => {
|
|
52
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbtCloud);
|
|
53
|
+
const version3 = await (0, getDbtVersion_1.getDbtVersion)();
|
|
54
|
+
expect(version3.verboseVersion).toEqual(expect.stringContaining('dbt Cloud CLI'));
|
|
55
|
+
expect(version3.versionOption).toEqual(common_1.DbtVersionOptionLatest.LATEST);
|
|
56
|
+
});
|
|
57
|
+
test('when CI=true, should warn user about unsupported version and return fallback', async () => {
|
|
58
|
+
process.env.CI = 'true';
|
|
59
|
+
// Test for 1.3
|
|
60
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_3);
|
|
61
|
+
const version = await (0, getDbtVersion_1.getDbtVersion)();
|
|
62
|
+
expect(version.verboseVersion).toEqual('1.3.0');
|
|
63
|
+
expect(version.versionOption).toEqual(common_1.SupportedDbtVersions.V1_4);
|
|
64
|
+
expect(consoleError).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(consoleError).nthCalledWith(1, expect.stringContaining("We don't currently support version 1.3.0"));
|
|
66
|
+
// Clear saved prompt answer
|
|
67
|
+
globalState_1.default.clearPromptAnswer();
|
|
68
|
+
// Test for future version
|
|
69
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt20_1);
|
|
70
|
+
const version2 = await (0, getDbtVersion_1.getDbtVersion)();
|
|
71
|
+
expect(version2.verboseVersion).toEqual('20.1.0');
|
|
72
|
+
expect(version2.versionOption).toEqual((0, common_1.getLatestSupportDbtVersion)());
|
|
73
|
+
expect(consoleError).toHaveBeenCalledTimes(2);
|
|
74
|
+
expect(consoleError).nthCalledWith(2, expect.stringContaining("We don't currently support version 20.1.0"));
|
|
75
|
+
});
|
|
76
|
+
test('when CI=false, should return fallback version if user confirms', async () => {
|
|
77
|
+
process.env.CI = 'false';
|
|
78
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_3);
|
|
79
|
+
const version = await (0, getDbtVersion_1.getDbtVersion)();
|
|
80
|
+
expect(version.verboseVersion).toEqual('1.3.0');
|
|
81
|
+
expect(version.versionOption).toEqual(common_1.SupportedDbtVersions.V1_4);
|
|
82
|
+
expect(promptMock).toHaveBeenCalledTimes(1);
|
|
83
|
+
expect(consoleError).toHaveBeenCalledTimes(0);
|
|
84
|
+
});
|
|
85
|
+
test('when CI=false, should return error if user declines fallback', async () => {
|
|
86
|
+
const exitSpy = jest.spyOn(process, 'exit').mockImplementation();
|
|
87
|
+
process.env.CI = 'false';
|
|
88
|
+
execaMock.mockImplementation(async () => getDbtVersion_mocks_1.cliMocks.dbt1_3);
|
|
89
|
+
promptMock.mockImplementation(async () => ({ isConfirm: false }));
|
|
90
|
+
await (0, getDbtVersion_1.getDbtVersion)();
|
|
91
|
+
expect(promptMock).toHaveBeenCalledTimes(1);
|
|
92
|
+
expect(consoleError).toHaveBeenCalledTimes(1);
|
|
93
|
+
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
94
|
+
exitSpy.mockRestore();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CreateSnowflakeCredentials, CreateWarehouseCredentials, WarehouseTableSchema } from '@lightdash/common';
|
|
2
|
+
import { warehouseClientFromCredentials } from '@lightdash/warehouses';
|
|
3
|
+
type GetTableCatalogProps = {
|
|
4
|
+
projectUuid: string;
|
|
5
|
+
tableName: string;
|
|
6
|
+
schemaName: string;
|
|
7
|
+
databaseName?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const getTableSchema: ({ projectUuid, tableName, schemaName, databaseName, }: GetTableCatalogProps) => Promise<WarehouseTableSchema>;
|
|
10
|
+
type GetWarehouseClientOptions = {
|
|
11
|
+
isDbtCloudCLI: boolean;
|
|
12
|
+
profilesDir: string;
|
|
13
|
+
profile: string;
|
|
14
|
+
target?: string;
|
|
15
|
+
startOfWeek?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const createProgramaticallySnowflakePat: (credentials: CreateSnowflakeCredentials) => Promise<string>;
|
|
18
|
+
type GetWarehouseClientReturn = {
|
|
19
|
+
warehouseClient: ReturnType<typeof warehouseClientFromCredentials>;
|
|
20
|
+
credentials: CreateWarehouseCredentials;
|
|
21
|
+
};
|
|
22
|
+
export default function getWarehouseClient(options: GetWarehouseClientOptions): Promise<GetWarehouseClientReturn>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=getWarehouseClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getWarehouseClient.d.ts","sourceRoot":"","sources":["../../../src/handlers/dbt/getWarehouseClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,0BAA0B,EAC1B,0BAA0B,EAQ1B,oBAAoB,EAEvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAGH,8BAA8B,EACjC,MAAM,uBAAuB,CAAC;AA8C/B,KAAK,oBAAoB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,cAAc,GAAU,uDAKlC,oBAAoB,kCAKjB,CAAC;AAsIP,KAAK,yBAAyB,GAAG;IAC7B,aAAa,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AASF,eAAO,MAAM,iCAAiC,GAC1C,aAAa,0BAA0B,KACxC,OAAO,CAAC,MAAM,CAwBhB,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC5B,eAAe,EAAE,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC;IACnE,WAAW,EAAE,0BAA0B,CAAC;CAC3C,CAAC;AAEF,wBAA8B,kBAAkB,CAC5C,OAAO,EAAE,yBAAyB,GACnC,OAAO,CAAC,wBAAwB,CAAC,CAgLnC"}
|