Skip to content

Commit efd8e9f

Browse files
oliypenalosa
authored andcommitted
PIPE-155 Add pipelines prefix option (#7510)
1 parent 48590c0 commit efd8e9f

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

.changeset/clean-peas-exist.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Add file prefix option to wrangler pipelines commands

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,29 @@ describe("pipelines", () => {
1616
runInTempDir();
1717

1818
const samplePipeline = {
19-
currentVersion: 1,
2019
id: "0001",
20+
version: 1,
2121
name: "my-pipeline",
2222
metadata: {},
2323
source: [
2424
{
2525
type: "binding",
2626
format: "json",
2727
},
28+
{
29+
type: "http",
30+
format: "json",
31+
authentication: false,
32+
},
2833
],
2934
transforms: [],
3035
destination: {
31-
type: "json",
36+
type: "r2",
37+
format: "json",
3238
batch: {},
3339
compression: {
3440
type: "none",
3541
},
36-
format: "json",
3742
path: {
3843
bucket: "bucket",
3944
},
@@ -365,10 +370,12 @@ describe("pipelines", () => {
365370
Default: No transformation worker [string]
366371
--compression Sets the compression format of output files
367372
Default: gzip [string] [choices: \\"none\\", \\"gzip\\", \\"deflate\\"]
368-
--filepath The path to store files in the destination bucket
373+
--prefix Optional base path to store files in the destination bucket
374+
Default: (none) [string]
375+
--filepath The path to store partitioned files in the destination bucket
369376
Default: event_date=\${date}/hr=\${hr} [string]
370-
--filename The name of the file in the bucket. Must contain \\"\${slug}\\". File extension is optional
371-
Default: \${slug}-\${hr}.json [string]
377+
--filename The name of each unique file in the bucket. Must contain \\"\${slug}\\". File extension is optional
378+
Default: \${slug}\${extension} [string]
372379
--binding Enable Worker binding to this pipeline [boolean] [default: true]
373380
--http Enable HTTPS endpoint to send data to this pipeline [boolean] [default: true]
374381
--authentication Require authentication (Cloudflare API Token) to send data to the HTTPS endpoint [boolean] [default: false]
@@ -465,24 +472,29 @@ describe("pipelines", () => {
465472
expect(std.out).toMatchInlineSnapshot(`
466473
"Retrieving config for pipeline \\"foo\\".
467474
{
468-
\\"currentVersion\\": 1,
469475
\\"id\\": \\"0001\\",
476+
\\"version\\": 1,
470477
\\"name\\": \\"my-pipeline\\",
471478
\\"metadata\\": {},
472479
\\"source\\": [
473480
{
474481
\\"type\\": \\"binding\\",
475482
\\"format\\": \\"json\\"
483+
},
484+
{
485+
\\"type\\": \\"http\\",
486+
\\"format\\": \\"json\\",
487+
\\"authentication\\": false
476488
}
477489
],
478490
\\"transforms\\": [],
479491
\\"destination\\": {
480-
\\"type\\": \\"json\\",
492+
\\"type\\": \\"r2\\",
493+
\\"format\\": \\"json\\",
481494
\\"batch\\": {},
482495
\\"compression\\": {
483496
\\"type\\": \\"none\\"
484497
},
485-
\\"format\\": \\"json\\",
486498
\\"path\\": {
487499
\\"bucket\\": \\"bucket\\"
488500
}

packages/wrangler/src/pipelines/client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type PipelineUserConfig = {
4444
};
4545
path: {
4646
bucket: string;
47+
prefix?: string;
4748
filepath?: string;
4849
filename?: string;
4950
};
@@ -58,7 +59,7 @@ export type PipelineUserConfig = {
5859
// Pipeline from v4 API
5960
export type Pipeline = Omit<PipelineUserConfig, "destination"> & {
6061
id: string;
61-
currentVersion: number;
62+
version: number;
6263
endpoint: string;
6364
destination: Omit<PipelineUserConfig["destination"], "credentials"> & {
6465
credentials?: PipelineUserConfig["destination"]["credentials"];

packages/wrangler/src/pipelines/index.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,21 @@ function addCreateAndUpdateOptions(yargs: Argv<CommonYargsOptions>) {
129129
choices: ["none", "gzip", "deflate"],
130130
demandOption: false,
131131
})
132+
.option("prefix", {
133+
describe:
134+
"Optional base path to store files in the destination bucket \nDefault: (none)",
135+
type: "string",
136+
demandOption: false,
137+
})
132138
.option("filepath", {
133139
describe:
134-
"The path to store files in the destination bucket \nDefault: event_date=${date}/hr=${hr}",
140+
"The path to store partitioned files in the destination bucket \nDefault: event_date=${date}/hr=${hr}",
135141
type: "string",
136142
demandOption: false,
137143
})
138144
.option("filename", {
139145
describe:
140-
'The name of the file in the bucket. Must contain "${slug}". File extension is optional \nDefault: ${slug}-${hr}.json',
146+
'The name of each unique file in the bucket. Must contain "${slug}". File extension is optional \nDefault: ${slug}${extension}',
141147
type: "string",
142148
demandOption: false,
143149
})
@@ -275,6 +281,9 @@ export function pipelines(pipelineYargs: CommonYargsArgv) {
275281
pipelineConfig.transforms.push(parseTransform(args.transform));
276282
}
277283

284+
if (args.prefix) {
285+
pipelineConfig.destination.path.prefix = args.prefix;
286+
}
278287
if (args.filepath) {
279288
pipelineConfig.destination.path.filepath = args.filepath;
280289
}
@@ -464,6 +473,9 @@ export function pipelines(pipelineYargs: CommonYargsArgv) {
464473
pipelineConfig.transforms.push(parseTransform(args.transform));
465474
}
466475

476+
if (args.prefix) {
477+
pipelineConfig.destination.path.prefix = args.prefix;
478+
}
467479
if (args.filepath) {
468480
pipelineConfig.destination.path.filepath = args.filepath;
469481
}

0 commit comments

Comments
 (0)