@lightdash-tools/cli 0.13.1 → 0.14.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.
@@ -4,42 +4,10 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.registerChartsCommand = registerChartsCommand;
7
- const fs_1 = require("fs");
8
7
  const common_1 = require("@lightdash-tools/common");
9
8
  const client_1 = require("../utils/client");
9
+ const file_input_1 = require("../utils/file-input");
10
10
  const safety_1 = require("../utils/safety");
11
- /**
12
- * Reads JSON from stdin or a file (for chart-as-code upsert body).
13
- */
14
- async function readChartJsonInput(filePath) {
15
- if (filePath) {
16
- const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
17
- return JSON.parse(content);
18
- }
19
- return new Promise((resolve, reject) => {
20
- if (process.stdin.isTTY) {
21
- reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
22
- return;
23
- }
24
- const chunks = [];
25
- process.stdin.setEncoding('utf8');
26
- process.stdin.on('data', (chunk) => {
27
- chunks.push(Buffer.from(chunk));
28
- });
29
- process.stdin.on('end', () => {
30
- try {
31
- const input = Buffer.concat(chunks).toString('utf-8');
32
- resolve(JSON.parse(input));
33
- }
34
- catch (err) {
35
- reject(new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`));
36
- }
37
- });
38
- process.stdin.on('error', (err) => {
39
- reject(err);
40
- });
41
- });
42
- }
43
11
  /**
44
12
  * Registers the projects charts subcommands under the existing projects command.
45
13
  */
@@ -95,7 +63,7 @@ function registerChartsCommand(program) {
95
63
  .option('--file <path>', 'Read chart JSON from file (default: stdin)')
96
64
  .action((0, safety_1.wrapAction)(common_1.WRITE_IDEMPOTENT, async (projectUuid, slug, options) => {
97
65
  try {
98
- const body = await readChartJsonInput(options.file);
66
+ const body = (await (0, file_input_1.readParsedInput)({ file: options.file }));
99
67
  const client = (0, client_1.getClient)();
100
68
  const result = await client.v1.charts.upsertChartAsCode(projectUuid, slug, body);
101
69
  console.log(JSON.stringify(result, null, 2));
@@ -4,44 +4,10 @@
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.registerQueryCommand = registerQueryCommand;
7
- const fs_1 = require("fs");
8
7
  const common_1 = require("@lightdash-tools/common");
9
8
  const client_1 = require("../utils/client");
9
+ const file_input_1 = require("../utils/file-input");
10
10
  const safety_1 = require("../utils/safety");
11
- /**
12
- * Reads JSON from stdin or a file.
13
- */
14
- async function readJsonInput(filePath) {
15
- if (filePath) {
16
- const content = (0, fs_1.readFileSync)(filePath, 'utf-8');
17
- return JSON.parse(content);
18
- }
19
- // Read from stdin
20
- return new Promise((resolve, reject) => {
21
- // Check if stdin is a TTY (interactive terminal)
22
- if (process.stdin.isTTY) {
23
- reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
24
- return;
25
- }
26
- const chunks = [];
27
- process.stdin.setEncoding('utf8');
28
- process.stdin.on('data', (chunk) => {
29
- chunks.push(Buffer.from(chunk));
30
- });
31
- process.stdin.on('end', () => {
32
- try {
33
- const input = Buffer.concat(chunks).toString('utf-8');
34
- resolve(JSON.parse(input));
35
- }
36
- catch (err) {
37
- reject(new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`));
38
- }
39
- });
40
- process.stdin.on('error', (err) => {
41
- reject(err);
42
- });
43
- });
44
- }
45
11
  /**
46
12
  * Registers the query command and its subcommands.
47
13
  */
@@ -55,16 +21,7 @@ function registerQueryCommand(program) {
55
21
  .option('--file <path>', 'Read metric query JSON from file (default: read from stdin)')
56
22
  .action((0, safety_1.wrapAction)(common_1.READ_ONLY_DEFAULT, async (projectUuid, exploreId, options) => {
57
23
  try {
58
- if (!projectUuid) {
59
- console.error('Error: projectUuid is required');
60
- process.exit(1);
61
- }
62
- if (!exploreId) {
63
- console.error('Error: exploreId is required');
64
- process.exit(1);
65
- }
66
- // Read JSON input
67
- const body = (await readJsonInput(options.file));
24
+ const body = (await (0, file_input_1.readParsedInput)({ file: options.file }));
68
25
  const client = (0, client_1.getClient)();
69
26
  const result = await client.v1.query.compileQuery(projectUuid, exploreId, body);
70
27
  console.log(JSON.stringify(result, null, 2));
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ const program = new commander_1.Command();
32
32
  program
33
33
  .name('lightdash-ai')
34
34
  .description('CLI for Lightdash AI')
35
- .version('0.13.1')
35
+ .version('0.14.0')
36
36
  .option('--safety-mode <mode>', 'Safety mode (read-only, write-idempotent, write-destructive)', 'read-only')
37
37
  .option('--projects <uuids>', 'Comma-separated list of allowed project UUIDs (security guardrail)')
38
38
  .option('--dry-run', 'Simulate mutating operations without executing (env: LIGHTDASH_TOOLS_DRY_RUN=1)');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightdash-tools/cli",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "CLI for Lightdash AI.",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -18,8 +18,8 @@
18
18
  "dependencies": {
19
19
  "commander": "^15.0.0",
20
20
  "yaml": "^2.9.0",
21
- "@lightdash-tools/common": "0.13.1",
22
- "@lightdash-tools/client": "0.13.1"
21
+ "@lightdash-tools/client": "0.14.0",
22
+ "@lightdash-tools/common": "0.14.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^25.9.3"
@@ -2,50 +2,15 @@
2
2
  * Charts (v1) command implementation.
3
3
  */
4
4
 
5
- import { readFileSync } from 'fs';
6
-
7
5
  import { READ_ONLY_DEFAULT, WRITE_IDEMPOTENT } from '@lightdash-tools/common';
8
6
 
9
7
  import { getClient } from '../utils/client';
8
+ import { readParsedInput } from '../utils/file-input';
10
9
  import { wrapAction } from '../utils/safety';
11
10
 
12
11
  import type { UpsertChartAsCodeBody } from '@lightdash-tools/common';
13
12
  import type { Command } from 'commander';
14
13
 
15
- /**
16
- * Reads JSON from stdin or a file (for chart-as-code upsert body).
17
- */
18
- async function readChartJsonInput(filePath?: string): Promise<UpsertChartAsCodeBody> {
19
- if (filePath) {
20
- const content = readFileSync(filePath, 'utf-8');
21
- return JSON.parse(content) as UpsertChartAsCodeBody;
22
- }
23
- return new Promise((resolve, reject) => {
24
- if (process.stdin.isTTY) {
25
- reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
26
- return;
27
- }
28
- const chunks: Buffer[] = [];
29
- process.stdin.setEncoding('utf8');
30
- process.stdin.on('data', (chunk) => {
31
- chunks.push(Buffer.from(chunk));
32
- });
33
- process.stdin.on('end', () => {
34
- try {
35
- const input = Buffer.concat(chunks).toString('utf-8');
36
- resolve(JSON.parse(input) as UpsertChartAsCodeBody);
37
- } catch (err) {
38
- reject(
39
- new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`),
40
- );
41
- }
42
- });
43
- process.stdin.on('error', (err) => {
44
- reject(err);
45
- });
46
- });
47
- }
48
-
49
14
  /**
50
15
  * Registers the projects charts subcommands under the existing projects command.
51
16
  */
@@ -123,7 +88,7 @@ export function registerChartsCommand(program: Command): void {
123
88
  WRITE_IDEMPOTENT,
124
89
  async (projectUuid: string, slug: string, options: { file?: string }) => {
125
90
  try {
126
- const body = await readChartJsonInput(options.file);
91
+ const body = (await readParsedInput({ file: options.file })) as UpsertChartAsCodeBody;
127
92
  const client = getClient();
128
93
  const result = await client.v1.charts.upsertChartAsCode(projectUuid, slug, body);
129
94
  console.log(JSON.stringify(result, null, 2));
@@ -2,52 +2,15 @@
2
2
  * Query command implementation.
3
3
  */
4
4
 
5
- import { readFileSync } from 'fs';
6
-
7
5
  import { READ_ONLY_DEFAULT } from '@lightdash-tools/common';
8
6
 
9
7
  import { getClient } from '../utils/client';
8
+ import { readParsedInput } from '../utils/file-input';
10
9
  import { wrapAction } from '../utils/safety';
11
10
 
12
11
  import type { CompileQueryRequest } from '@lightdash-tools/common';
13
12
  import type { Command } from 'commander';
14
13
 
15
- /**
16
- * Reads JSON from stdin or a file.
17
- */
18
- async function readJsonInput(filePath?: string): Promise<unknown> {
19
- if (filePath) {
20
- const content = readFileSync(filePath, 'utf-8');
21
- return JSON.parse(content);
22
- }
23
- // Read from stdin
24
- return new Promise((resolve, reject) => {
25
- // Check if stdin is a TTY (interactive terminal)
26
- if (process.stdin.isTTY) {
27
- reject(new Error('No input provided. Use --file <path> or pipe JSON to stdin.'));
28
- return;
29
- }
30
- const chunks: Buffer[] = [];
31
- process.stdin.setEncoding('utf8');
32
- process.stdin.on('data', (chunk) => {
33
- chunks.push(Buffer.from(chunk));
34
- });
35
- process.stdin.on('end', () => {
36
- try {
37
- const input = Buffer.concat(chunks).toString('utf-8');
38
- resolve(JSON.parse(input));
39
- } catch (err) {
40
- reject(
41
- new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}`),
42
- );
43
- }
44
- });
45
- process.stdin.on('error', (err) => {
46
- reject(err);
47
- });
48
- });
49
- }
50
-
51
14
  /**
52
15
  * Registers the query command and its subcommands.
53
16
  */
@@ -65,17 +28,7 @@ export function registerQueryCommand(program: Command): void {
65
28
  READ_ONLY_DEFAULT,
66
29
  async (projectUuid: string, exploreId: string, options: { file?: string }) => {
67
30
  try {
68
- if (!projectUuid) {
69
- console.error('Error: projectUuid is required');
70
- process.exit(1);
71
- }
72
- if (!exploreId) {
73
- console.error('Error: exploreId is required');
74
- process.exit(1);
75
- }
76
-
77
- // Read JSON input
78
- const body = (await readJsonInput(options.file)) as CompileQueryRequest;
31
+ const body = (await readParsedInput({ file: options.file })) as CompileQueryRequest;
79
32
 
80
33
  const client = getClient();
81
34
  const result = await client.v1.query.compileQuery(projectUuid, exploreId, body);
package/src/index.ts CHANGED
@@ -35,7 +35,7 @@ const program = new Command();
35
35
  program
36
36
  .name('lightdash-ai')
37
37
  .description('CLI for Lightdash AI')
38
- .version('0.13.1')
38
+ .version('0.14.0')
39
39
  .option(
40
40
  '--safety-mode <mode>',
41
41
  'Safety mode (read-only, write-idempotent, write-destructive)',