Skip to content

Commit

Permalink
PIPE-37 Small API restructuring for Worker Pipelines (#7046)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliy authored Oct 21, 2024
1 parent a8ca700 commit f9d5fdb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-ducks-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Minor change to 3rd party API shape for Workers Pipelines
18 changes: 8 additions & 10 deletions packages/wrangler/src/__tests__/pipelines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,9 @@ describe("pipelines", () => {

// contain http source and include auth
expect(requests.body?.source[1].type).toEqual("http");
expect(
(requests.body?.source[1] as HttpSource).config?.authentication
).toEqual(true);
expect((requests.body?.source[1] as HttpSource).authentication).toEqual(
true
);
});

it("should create a pipeline without http", async () => {
Expand Down Expand Up @@ -581,23 +581,21 @@ describe("pipelines", () => {
{
type: "http",
format: "json",
config: {
authenticated: true,
},
authenticated: true,
},
];
const updateReq = mockUpdateRequest(update.name, update);

await runWrangler(
"pipelines update my-pipeline --binding=false --http --authentication --r2 new-bucket --access-key-id new-key --secret-access-key new-secret"
"pipelines update my-pipeline --binding=false --http --authentication"
);

expect(updateReq.count).toEqual(1);
expect(updateReq.body?.source.length).toEqual(1);
expect(updateReq.body?.source[0].type).toEqual("http");
expect(
(updateReq.body?.source[0] as HttpSource).config?.authentication
).toEqual(true);
expect((updateReq.body?.source[0] as HttpSource).authentication).toEqual(
true
);
});

it("should fail a missing pipeline", async () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/wrangler/src/pipelines/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export type HttpSource = {
type: "http";
format: string;
schema?: string;
config?: {
authentication: boolean;
};
authentication?: boolean;
};
export type BindingSource = {
type: "binding";
Expand Down
26 changes: 12 additions & 14 deletions packages/wrangler/src/pipelines/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@ export function pipelines(pipelineYargs: CommonYargsArgv) {

// add http source (possibly authenticated), default to add
if (args.http === undefined || args.http) {
pipelineConfig.source.push({
const source: HttpSource = {
type: "http",
format: "json",
config: {
authentication:
args.authentication !== undefined && args.authentication,
},
} satisfies HttpSource);
};
if (args.authentication !== undefined) {
source.authentication = args.authentication;
}
pipelineConfig.source.push(source);
}
if (pipelineConfig.source.length < 1) {
throw new UserError(
Expand Down Expand Up @@ -450,14 +450,12 @@ export function pipelines(pipelineYargs: CommonYargsArgv) {
type: "http",
format: "json",
...source,
config: {
authentication:
args.authentication !== undefined
? // if auth specified, use it
args.authentication
: // if auth not specified, use previos value or default(false)
source?.config?.authentication || false,
},
authentication:
args.authentication !== undefined
? // if auth specified, use it
args.authentication
: // if auth not specified, use previos value or default(false)
source?.authentication,
} satisfies HttpSource);
}
}
Expand Down

0 comments on commit f9d5fdb

Please sign in to comment.