Skip to content

Commit ea8fc98

Browse files
committed
Updated behavior for legacy pipelines, remove --legacy arg
1 parent f119d22 commit ea8fc98

File tree

8 files changed

+610
-692
lines changed

8 files changed

+610
-692
lines changed

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

Lines changed: 0 additions & 574 deletions
This file was deleted.

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

Lines changed: 389 additions & 3 deletions
Large diffs are not rendered by default.

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
22
import { createCommand } from "../../core/create-command";
33
import { UserError } from "../../errors";
44
import { logger } from "../../logger";
5+
import { APIError } from "../../parse";
56
import { requireAuth } from "../../user";
67
import { createPipeline, getPipeline, getStream, validateSql } from "../client";
78
import { displayUsageExamples } from "./streams/utils";
@@ -27,24 +28,13 @@ export const pipelinesCreateCommand = createCommand({
2728
describe: "Path to file containing SQL query for the pipeline",
2829
type: "string",
2930
},
30-
legacy: {
31-
type: "boolean",
32-
describe: "Use the legacy Pipelines API",
33-
default: false,
34-
},
3531
},
3632
positionalArgs: ["pipeline"],
3733

3834
async handler(args, { config }) {
3935
await requireAuth(config);
4036
const pipelineName = args.pipeline;
4137

42-
if (args.legacy) {
43-
throw new UserError(
44-
"Creating legacy pipelines is not supported. Please use the v1 Pipelines API without the --legacy flag."
45-
);
46-
}
47-
4838
if (!args.sql && !args.sqlFile) {
4939
throw new UserError("Either --sql or --sql-file must be provided");
5040
}
@@ -115,7 +105,18 @@ export const pipelinesCreateCommand = createCommand({
115105

116106
logger.log(`🌀 Creating pipeline '${pipelineName}'...`);
117107

118-
const pipeline = await createPipeline(config, pipelineConfig);
108+
let pipeline;
109+
try {
110+
pipeline = await createPipeline(config, pipelineConfig);
111+
} catch (error) {
112+
if (error instanceof APIError && error.code === 10000) {
113+
// Show error when no access to v1 Pipelines API
114+
throw new UserError(
115+
`An authentication error has occurred creating a pipeline with this version of Wrangler. Please try: npm install [email protected]`
116+
);
117+
}
118+
throw error;
119+
}
119120

120121
logger.log(
121122
`✨ Successfully created pipeline '${pipeline.name}' with id '${pipeline.id}'.`
Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { createCommand } from "../../core/create-command";
22
import { confirm } from "../../dialogs";
33
import { logger } from "../../logger";
4+
import { APIError } from "../../parse";
45
import { requireAuth } from "../../user";
56
import { deletePipeline, getPipeline } from "../client";
6-
import { deleteLegacyPipeline } from "./legacy-helpers";
7+
import { tryDeleteLegacyPipeline } from "./legacy-helpers";
78

89
export const pipelinesDeleteCommand = createCommand({
910
metadata: {
@@ -14,14 +15,9 @@ export const pipelinesDeleteCommand = createCommand({
1415
args: {
1516
pipeline: {
1617
type: "string",
17-
describe: "The ID of the pipeline to delete (or name for --legacy)",
18+
describe: "The ID or name of the pipeline to delete",
1819
demandOption: true,
1920
},
20-
legacy: {
21-
type: "boolean",
22-
describe: "Use the legacy Pipelines API",
23-
default: false,
24-
},
2521
force: {
2622
describe: "Skip confirmation",
2723
type: "boolean",
@@ -34,32 +30,41 @@ export const pipelinesDeleteCommand = createCommand({
3430
const accountId = await requireAuth(config);
3531
const pipelineId = args.pipeline;
3632

37-
// Handle legacy API if flag is provided
38-
if (args.legacy) {
39-
return await deleteLegacyPipeline(
40-
config,
41-
accountId,
42-
pipelineId,
43-
args.force
44-
);
45-
}
33+
try {
34+
const pipeline = await getPipeline(config, pipelineId);
4635

47-
const pipeline = await getPipeline(config, pipelineId);
36+
if (!args.force) {
37+
const confirmedDelete = await confirm(
38+
`Are you sure you want to delete the pipeline '${pipeline.name}' (${pipelineId})?`
39+
);
40+
if (!confirmedDelete) {
41+
logger.log("Delete cancelled.");
42+
return;
43+
}
44+
}
45+
46+
await deletePipeline(config, pipelineId);
4847

49-
if (!args.force) {
50-
const confirmedDelete = await confirm(
51-
`Are you sure you want to delete the pipeline '${pipeline.name}' (${pipelineId})?`
48+
logger.log(
49+
`✨ Successfully deleted pipeline '${pipeline.name}' with id '${pipeline.id}'.`
5250
);
53-
if (!confirmedDelete) {
54-
logger.log("Delete cancelled.");
55-
return;
51+
} catch (error) {
52+
if (
53+
error instanceof APIError &&
54+
(error.code === 1000 || error.code === 2)
55+
) {
56+
const deletedFromLegacy = await tryDeleteLegacyPipeline(
57+
config,
58+
accountId,
59+
pipelineId,
60+
args.force
61+
);
62+
63+
if (deletedFromLegacy) {
64+
return;
65+
}
5666
}
67+
throw error;
5768
}
58-
59-
await deletePipeline(config, pipelineId);
60-
61-
logger.log(
62-
`✨ Successfully deleted pipeline '${pipeline.name}' with id '${pipeline.id}'.`
63-
);
6469
},
6570
});

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { createCommand } from "../../core/create-command";
22
import { logger } from "../../logger";
3+
import { APIError } from "../../parse";
34
import { requireAuth } from "../../user";
45
import formatLabelledValues from "../../utils/render-labelled-values";
56
import { getPipeline } from "../client";
6-
import { getLegacyPipeline } from "./legacy-helpers";
7+
import { tryGetLegacyPipeline } from "./legacy-helpers";
78

89
export const pipelinesGetCommand = createCommand({
910
metadata: {
@@ -14,36 +15,42 @@ export const pipelinesGetCommand = createCommand({
1415
args: {
1516
pipeline: {
1617
type: "string",
17-
describe: "The ID of the pipeline to retrieve (or name for --legacy)",
18+
describe: "The ID of the pipeline to retrieve",
1819
demandOption: true,
1920
},
2021
format: {
2122
choices: ["pretty", "json"],
2223
describe: "The output format for pipeline",
2324
default: "pretty",
2425
},
25-
legacy: {
26-
type: "boolean",
27-
describe: "Use the legacy Pipelines API",
28-
default: false,
29-
},
3026
},
3127
positionalArgs: ["pipeline"],
3228
async handler(args, { config }) {
3329
const accountId = await requireAuth(config);
3430
const pipelineId = args.pipeline;
3531

36-
// Handle legacy API if flag is provided
37-
if (args.legacy) {
38-
return await getLegacyPipeline(
39-
config,
40-
accountId,
41-
pipelineId,
42-
args.format as "pretty" | "json"
43-
);
44-
}
32+
let pipeline;
4533

46-
const pipeline = await getPipeline(config, pipelineId);
34+
try {
35+
pipeline = await getPipeline(config, pipelineId);
36+
} catch (error) {
37+
if (
38+
error instanceof APIError &&
39+
(error.code === 1000 || error.code === 2)
40+
) {
41+
const foundInLegacy = await tryGetLegacyPipeline(
42+
config,
43+
accountId,
44+
pipelineId,
45+
args.format as "pretty" | "json"
46+
);
47+
48+
if (foundInLegacy) {
49+
return;
50+
}
51+
}
52+
throw error;
53+
}
4754

4855
if (args.format === "json") {
4956
logger.log(JSON.stringify(pipeline, null, 2));

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

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { confirm } from "../../dialogs";
22
import { FatalError, UserError } from "../../errors";
33
import { logger } from "../../logger";
4+
import { APIError } from "../../parse";
45
import {
56
authorizeR2Bucket,
67
BYTES_PER_MB,
@@ -47,34 +48,14 @@ export async function getLegacyPipeline(
4748
logger.log(JSON.stringify(pipeline, null, 2));
4849
break;
4950
case "pretty":
51+
logger.warn(
52+
"⚠️ This is a legacy pipeline. Consider creating a new pipeline by running 'wrangler pipelines setup'."
53+
);
5054
logger.log(formatPipelinePretty(pipeline));
5155
break;
5256
}
5357
}
5458

55-
export async function deleteLegacyPipeline(
56-
config: Config,
57-
accountId: string,
58-
name: string,
59-
force: boolean = false
60-
): Promise<void> {
61-
validateName("pipeline name", name);
62-
63-
if (!force) {
64-
const confirmedDelete = await confirm(
65-
`Are you sure you want to delete the pipeline '${name}'?`
66-
);
67-
if (!confirmedDelete) {
68-
logger.log("Delete cancelled.");
69-
return;
70-
}
71-
}
72-
73-
await deletePipeline(config, accountId, name);
74-
75-
logger.log(`✨ Successfully deleted pipeline '${name}'.`);
76-
}
77-
7859
interface LegacyUpdateArgs {
7960
pipeline: string;
8061
compression?: string;
@@ -91,6 +72,69 @@ interface LegacyUpdateArgs {
9172
corsOrigins?: string[];
9273
}
9374

75+
export async function tryGetLegacyPipeline(
76+
config: Config,
77+
accountId: string,
78+
name: string,
79+
format: "pretty" | "json"
80+
): Promise<boolean> {
81+
try {
82+
await getLegacyPipeline(config, accountId, name, format);
83+
return true;
84+
} catch (error) {
85+
if (error instanceof APIError && error.code === 1000) {
86+
return false;
87+
}
88+
throw error;
89+
}
90+
}
91+
92+
export async function tryListLegacyPipelines(
93+
config: Config,
94+
accountId: string
95+
): Promise<Array<{ name: string; id: string; endpoint?: string }> | null> {
96+
try {
97+
const pipelines = await listPipelines(config, accountId);
98+
return pipelines;
99+
} catch {
100+
return [];
101+
}
102+
}
103+
104+
export async function tryDeleteLegacyPipeline(
105+
config: Config,
106+
accountId: string,
107+
name: string,
108+
force: boolean = false
109+
): Promise<boolean> {
110+
try {
111+
await getPipeline(config, accountId, name);
112+
113+
if (!force) {
114+
const confirmedDelete = await confirm(
115+
`Are you sure you want to delete the legacy pipeline '${name}'?`
116+
);
117+
if (!confirmedDelete) {
118+
logger.log("Delete cancelled.");
119+
return true;
120+
}
121+
}
122+
123+
await deletePipeline(config, accountId, name);
124+
logger.log(`✨ Successfully deleted legacy pipeline '${name}'.`);
125+
return true;
126+
} catch (error) {
127+
if (
128+
error instanceof APIError &&
129+
(error.code === 1000 || error.code === 2)
130+
) {
131+
// Not found in legacy API
132+
return false;
133+
}
134+
throw error;
135+
}
136+
}
137+
94138
export async function updateLegacyPipeline(
95139
config: Config,
96140
accountId: string,
@@ -100,6 +144,10 @@ export async function updateLegacyPipeline(
100144

101145
const pipelineConfig = await getPipeline(config, accountId, name);
102146

147+
logger.warn(
148+
"⚠️ Updating legacy pipeline. Consider recreating with 'wrangler pipelines setup'."
149+
);
150+
103151
if (args.compression) {
104152
pipelineConfig.destination.compression.type = args.compression;
105153
}

0 commit comments

Comments
 (0)