Skip to content

Commit d52a462

Browse files
committed
Addressed PR comments, further isolated legacy behavior
1 parent 12b80b3 commit d52a462

File tree

19 files changed

+284
-281
lines changed

19 files changed

+284
-281
lines changed

packages/wrangler/src/__tests__/pipelines.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,13 @@ describe("wrangler pipelines", () => {
381381
await expect(
382382
runWrangler(`pipelines create my_pipeline --sql "${sql}"`)
383383
).rejects.toThrowErrorMatchingInlineSnapshot(
384-
`[Error: An authentication error has occurred creating a pipeline with this version of Wrangler. Please try: npm install [email protected]]`
384+
`
385+
[Error: Your account does not have access to the new Pipelines API. To use the legacy Pipelines API, please run:
386+
387+
npx [email protected] pipelines create my_pipeline
388+
389+
This will use an older version of Wrangler that supports the legacy API.]
390+
`
385391
);
386392

387393
expect(validateRequest.count).toBe(1);
@@ -985,7 +991,7 @@ describe("wrangler pipelines", () => {
985991
it("should create stream with default settings", async () => {
986992
setIsTTY(true);
987993
mockConfirm({
988-
text: "No schema file provided. Create stream without a schema (unstructured JSON)?",
994+
text: "No schema file provided. Do you want to create stream without a schema (unstructured JSON)?",
989995
result: true,
990996
});
991997

packages/wrangler/src/pipelines/cli/create.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ export const pipelinesCreateCommand = createCommand({
2323
sql: {
2424
describe: "Inline SQL query for the pipeline",
2525
type: "string",
26+
conflicts: "sql-file",
2627
},
2728
"sql-file": {
2829
describe: "Path to file containing SQL query for the pipeline",
2930
type: "string",
31+
conflicts: "sql",
3032
},
3133
},
3234
positionalArgs: ["pipeline"],
@@ -35,13 +37,6 @@ export const pipelinesCreateCommand = createCommand({
3537
await requireAuth(config);
3638
const pipelineName = args.pipeline;
3739

38-
if (!args.sql && !args.sqlFile) {
39-
throw new UserError("Either --sql or --sql-file must be provided");
40-
}
41-
if (args.sql && args.sqlFile) {
42-
throw new UserError("Cannot specify both --sql and --sql-file");
43-
}
44-
4540
let sql: string;
4641
if (args.sql) {
4742
sql = args.sql;
@@ -54,7 +49,6 @@ export const pipelinesCreateCommand = createCommand({
5449
);
5550
}
5651
} else {
57-
// This should never happen due to earlier validation
5852
throw new UserError("Either --sql or --sql-file must be provided");
5953
}
6054

@@ -112,7 +106,7 @@ export const pipelinesCreateCommand = createCommand({
112106
if (error instanceof APIError && error.code === 10000) {
113107
// Show error when no access to v1 Pipelines API
114108
throw new UserError(
115-
`An authentication error has occurred creating a pipeline with this version of Wrangler. Please try: npm install [email protected]`
109+
`Your account does not have access to the new Pipelines API. To use the legacy Pipelines API, please run:\n\nnpx [email protected] pipelines create ${pipelineName}\n\nThis will use an older version of Wrangler that supports the legacy API.`
116110
);
117111
}
118112
throw error;
@@ -131,7 +125,7 @@ export const pipelinesCreateCommand = createCommand({
131125

132126
if (streamTable) {
133127
const stream = await getStream(config, streamTable.id);
134-
displayUsageExamples(stream);
128+
displayUsageExamples(stream, config);
135129
} else {
136130
logger.log(
137131
`\nRun 'wrangler pipelines get ${pipeline.id}' to view full details.`

packages/wrangler/src/pipelines/cli/delete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const pipelinesDeleteCommand = createCommand({
3535

3636
if (!args.force) {
3737
const confirmedDelete = await confirm(
38-
`Are you sure you want to delete the pipeline '${pipeline.name}' (${pipelineId})?`
38+
`Are you sure you want to delete the pipeline '${pipeline.name}' (${pipelineId})?`,
39+
{ fallbackValue: false }
3940
);
4041
if (!confirmedDelete) {
4142
logger.log("Delete cancelled.");

packages/wrangler/src/pipelines/cli/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const pipelinesGetCommand = createCommand({
5353
}
5454

5555
if (args.format === "json") {
56-
logger.log(JSON.stringify(pipeline, null, 2));
56+
logger.json(pipeline);
5757
return;
5858
}
5959

packages/wrangler/src/pipelines/cli/legacy-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { APIError } from "../../parse";
55
import {
66
authorizeR2Bucket,
77
BYTES_PER_MB,
8-
formatPipelinePretty,
98
getAccountR2Endpoint,
109
} from "../index";
1110
import {
1211
deletePipeline,
12+
formatPipelinePretty,
1313
getPipeline,
1414
listPipelines,
1515
updatePipeline,

packages/wrangler/src/pipelines/cli/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const pipelinesListCommand = createCommand({
4646
legacyPipelines: legacyPipelines,
4747
}
4848
: newPipelines || [];
49-
logger.log(JSON.stringify(result, null, 2));
49+
logger.json(result);
5050
return;
5151
}
5252

packages/wrangler/src/pipelines/cli/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const pipelinesSetupCommand = createCommand({
4848
},
4949
args: {
5050
name: {
51-
describe: "Pipeline name (optional - will prompt if not provided)",
51+
describe: "Pipeline name",
5252
type: "string",
5353
},
5454
},
@@ -792,7 +792,7 @@ async function createPipelineIfNeeded(
792792
logger.log("\n✨ Setup complete!");
793793

794794
if (created.stream) {
795-
displayUsageExamples(created.stream);
795+
displayUsageExamples(created.stream, config);
796796
}
797797
} catch (error) {
798798
logger.error(

packages/wrangler/src/pipelines/cli/sinks/create.ts

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createCommand } from "../../../core/create-command";
2-
import { UserError } from "../../../errors";
2+
import { CommandLineArgsError, UserError } from "../../../errors";
33
import { logger } from "../../../logger";
44
import { bucketFormatMessage, isValidR2BucketName } from "../../../r2/helpers";
55
import { requireAuth } from "../../../user";
@@ -67,17 +67,14 @@ export const pipelinesSinksCreateCommand = createCommand({
6767
type: "string",
6868
},
6969
"roll-size": {
70-
describe: "Roll file when size reaches (e.g., 100MB, 1GB)",
71-
type: "string",
72-
default:
73-
SINK_DEFAULTS.rolling_policy.file_size_bytes === 0
74-
? undefined
75-
: `${SINK_DEFAULTS.rolling_policy.file_size_bytes}`,
70+
describe: "Roll file size in MB",
71+
type: "number",
72+
default: SINK_DEFAULTS.rolling_policy.file_size_bytes / (1024 * 1024),
7673
},
7774
"roll-interval": {
78-
describe: "Roll file when time reaches (e.g., 5m, 1h)",
79-
type: "string",
80-
default: `${SINK_DEFAULTS.rolling_policy.interval_seconds}s`,
75+
describe: "Roll file interval in seconds",
76+
type: "number",
77+
default: SINK_DEFAULTS.rolling_policy.interval_seconds,
8178
},
8279
"access-key-id": {
8380
describe:
@@ -105,32 +102,37 @@ export const pipelinesSinksCreateCommand = createCommand({
105102
type: "string",
106103
},
107104
},
108-
async handler(args, { config }) {
109-
const accountId = await requireAuth(config);
110-
const sinkName = args.sink;
105+
validateArgs: (args) => {
111106
const sinkType = parseSinkType(args.type);
112107

113108
if (!isValidR2BucketName(args.bucket)) {
114-
throw new UserError(
109+
throw new CommandLineArgsError(
115110
`The bucket name "${args.bucket}" is invalid. ${bucketFormatMessage}`
116111
);
117112
}
118113

119114
if (sinkType === "r2_data_catalog") {
120115
if (!args.namespace) {
121-
throw new UserError(
116+
throw new CommandLineArgsError(
122117
"--namespace is required for r2-data-catalog sinks"
123118
);
124119
}
125120
if (!args.table) {
126-
throw new UserError("--table is required for r2-data-catalog sinks");
121+
throw new CommandLineArgsError(
122+
"--table is required for r2-data-catalog sinks"
123+
);
127124
}
128125
if (!args.catalogToken) {
129-
throw new UserError(
126+
throw new CommandLineArgsError(
130127
"--catalog-token is required for r2-data-catalog sinks"
131128
);
132129
}
133130
}
131+
},
132+
async handler(args, { config }) {
133+
const accountId = await requireAuth(config);
134+
const sinkName = args.sink;
135+
const sinkType = parseSinkType(args.type);
134136

135137
const sinkConfig: CreateSinkRequest = {
136138
name: sinkName,
@@ -182,23 +184,10 @@ export const pipelinesSinksCreateCommand = createCommand({
182184
SINK_DEFAULTS.rolling_policy.interval_seconds;
183185

184186
if (args.rollSize) {
185-
// Parse file size (e.g., "100MB" -> bytes)
186-
const sizeMatch = args.rollSize.match(/^(\d+)(MB|GB)?$/i);
187-
if (sizeMatch) {
188-
const size = parseInt(sizeMatch[1]);
189-
const unit = sizeMatch[2]?.toUpperCase() || "MB";
190-
file_size_bytes =
191-
unit === "GB" ? size * 1024 * 1024 * 1024 : size * 1024 * 1024;
192-
}
187+
file_size_bytes = args.rollSize * 1024 * 1024;
193188
}
194189
if (args.rollInterval) {
195-
// Parse interval (e.g., "300s" or "5m" -> seconds)
196-
const intervalMatch = args.rollInterval.match(/^(\d+)([sm])?$/i);
197-
if (intervalMatch) {
198-
const interval = parseInt(intervalMatch[1]);
199-
const unit = intervalMatch[2]?.toLowerCase() || "s";
200-
interval_seconds = unit === "m" ? interval * 60 : interval;
201-
}
190+
interval_seconds = args.rollInterval;
202191
}
203192

204193
sinkConfig.config.rolling_policy = {

packages/wrangler/src/pipelines/cli/sinks/delete.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export const pipelinesSinksDeleteCommand = createCommand({
3131

3232
if (!args.force) {
3333
const confirmedDelete = await confirm(
34-
`Are you sure you want to delete the sink '${sink.name}' (${args.sink})?`
34+
`Are you sure you want to delete the sink '${sink.name}' (${args.sink})?`,
35+
{ fallbackValue: false }
3536
);
3637
if (!confirmedDelete) {
3738
logger.log("Delete cancelled.");

packages/wrangler/src/pipelines/cli/sinks/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const pipelinesSinksGetCommand = createCommand({
3131
const rawSink = await getSink(config, args.sink);
3232

3333
if (args.json) {
34-
logger.log(JSON.stringify(rawSink, null, 2));
34+
logger.json(rawSink);
3535
return;
3636
}
3737

0 commit comments

Comments
 (0)