Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing bindings to init --from-dash #6791

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "[email protected]",
allowed_destination_addresses: ["[email protected]"],
},
{
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: ["[email protected]"],
destination_address: "[email protected]",
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 = \\"[email protected]\\"
allowed_destination_addresses = [ \\"[email protected]\\" ]

[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;
}
Comment on lines +1174 to +1181
Copy link
Member

@edmundhung edmundhung Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe you want this?

Suggested change
case "version_metadata": {
{
configObj.version_metadata = {
binding: binding.name,
};
}
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
Loading