Skip to content

Commit

Permalink
Add missing bindings to init --from-dash (#6791)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Sep 23, 2024
1 parent 9e44d88 commit 74d719f
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-months-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: Add missing binding to `init --from-dash`
120 changes: 120 additions & 0 deletions packages/wrangler/src/__tests__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,46 @@ describe("init", () => {
name: "UNSAFE_BINDING_TWO",
data: 1337,
},
{
type: "inherit",
name: "INHERIT_BINDING",
},
{
type: "pipelines",
name: "PIPELINE_BINDING",
id: "some-id",
},
{
type: "mtls_certificate",
name: "MTLS_BINDING",
certificate_id: "some-id",
},
{
type: "hyperdrive",
name: "HYPER_BINDING",
id: "some-id",
},
{
type: "vectorize",
name: "VECTOR_BINDING",
index_name: "some-name",
},
{
type: "queue",
name: "queue_BINDING",
queue_name: "some-name",
delivery_delay: 1,
},
{
type: "send_email",
name: "EMAIL_BINDING",
destination_address: "some@address.com",
allowed_destination_addresses: ["some2@address.com"],
},
{
type: "version_metadata",
name: "Version_BINDING",
},
],
routes = [
{
Expand Down Expand Up @@ -2721,6 +2761,53 @@ describe("init", () => {
type: "another unsafe thing",
data: 1337,
},
{
name: "INHERIT_BINDING",
type: "inherit",
},
],
},
vectorize: [
{
binding: "VECTOR_BINDING",
index_name: "some-name",
},
],
send_email: [
{
allowed_destination_addresses: ["some2@address.com"],
destination_address: "some@address.com",
name: "EMAIL_BINDING",
},
],
version_metadata: {
binding: "Version_BINDING",
},
hyperdrive: [
{
binding: "HYPER_BINDING",
id: "some-id",
},
],
mtls_certificates: [
{
binding: "MTLS_BINDING",
certificate_id: "some-id",
},
],
pipelines: [
{
binding: "PIPELINE_BINDING",
pipeline: "some-id",
},
],
queues: {
producers: [
{
binding: "queue_BINDING",
delivery_delay: 1,
queue: "some-name",
},
],
},
wasm_modules: {
Expand Down Expand Up @@ -3250,6 +3337,39 @@ describe("init", () => {
type = \\"another unsafe thing\\"
name = \\"UNSAFE_BINDING_TWO\\"
data = 1_337
[[unsafe.bindings]]
type = \\"inherit\\"
name = \\"INHERIT_BINDING\\"
[[pipelines]]
binding = \\"PIPELINE_BINDING\\"
pipeline = \\"some-id\\"
[[mtls_certificates]]
binding = \\"MTLS_BINDING\\"
certificate_id = \\"some-id\\"
[[hyperdrive]]
binding = \\"HYPER_BINDING\\"
id = \\"some-id\\"
[[vectorize]]
binding = \\"VECTOR_BINDING\\"
index_name = \\"some-name\\"
[[queues.producers]]
binding = \\"queue_BINDING\\"
queue = \\"some-name\\"
delivery_delay = 1
[[send_email]]
name = \\"EMAIL_BINDING\\"
destination_address = \\"some@address.com\\"
allowed_destination_addresses = [ \\"some2@address.com\\" ]
[version_metadata]
binding = \\"Version_BINDING\\"
"
`);
expect(std.out).toContain("cd isolinear-optical-chip");
Expand Down
89 changes: 83 additions & 6 deletions packages/wrangler/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import TOML from "@iarna/toml";
import { execa } from "execa";
import { findUp } from "find-up";
import { version as wranglerVersion } from "../package.json";
import { assertNever } from "./api/startDevWorker/utils";
import { fetchResult } from "./cfetch";
import { fetchWorker } from "./cfetch/internal";
import { readConfig } from "./config";
import { getDatabaseInfoFromId } from "./d1/utils";
import { confirm, select } from "./dialogs";
import { getC3CommandFromEnv } from "./environment-variables/misc-variables";
import { UserError } from "./errors";
import { FatalError, UserError } from "./errors";
import { getGitVersioon, initializeGit, isInsideGitRepo } from "./git-client";
import { logger } from "./logger";
import { getPackageManager } from "./package-manager";
Expand Down Expand Up @@ -1167,16 +1168,92 @@ export async function mapBindings(
};
}
break;
default: {
// If we don't know what the type is, its an unsafe binding
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!(binding as any)?.type) {
break;
case "secret_text":
// Ignore secrets
break;
case "version_metadata": {
{
configObj.version_metadata = {
binding: binding.name,
};
}
break;
}
case "send_email": {
configObj.send_email = [
...(configObj.send_email ?? []),
{
name: binding.name,
destination_address: binding.destination_address,
allowed_destination_addresses:
binding.allowed_destination_addresses,
},
];
break;
}
case "queue":
configObj.queues ??= { producers: [] };
configObj.queues.producers = [
...(configObj.queues.producers ?? []),
{
binding: binding.name,
queue: binding.queue_name,
delivery_delay: binding.delivery_delay,
},
];
break;
case "vectorize":
configObj.vectorize = [
...(configObj.vectorize ?? []),
{
binding: binding.name,
index_name: binding.index_name,
},
];
break;
case "hyperdrive":
configObj.hyperdrive = [
...(configObj.hyperdrive ?? []),
{
binding: binding.name,
id: binding.id,
},
];
break;
case "mtls_certificate":
configObj.mtls_certificates = [
...(configObj.mtls_certificates ?? []),
{
binding: binding.name,
certificate_id: binding.certificate_id,
},
];
break;
case "pipelines":
configObj.pipelines = [
...(configObj.pipelines ?? []),
{
binding: binding.name,
pipeline: binding.id,
},
];
break;
case "assets":
throw new FatalError(
"`wrangler init --from-dash` is not yet supported for Workers with Assets"
);
case "inherit":
configObj.unsafe = {
bindings: [...(configObj.unsafe?.bindings ?? []), binding],
metadata: configObj.unsafe?.metadata ?? undefined,
};
break;
default: {
configObj.unsafe = {
bindings: [...(configObj.unsafe?.bindings ?? []), binding],
metadata: configObj.unsafe?.metadata ?? undefined,
};
assertNever(binding);
}
}

Expand Down

0 comments on commit 74d719f

Please sign in to comment.