Skip to content

Commit ee6f345

Browse files
mtlemilioRamIdeas
andauthored
wrangler: Improvements (#3999)
* Wrangler support for Hyperdrive * Update connection string parsing logic and API endpoints * Update some copy and general cleanup * Fix formatting * Send scheme when updating or creating database config * Update copy and route names to reflect changes on backend * Add changeset and tests * Fix trailing colon on scheme when sending create request * Add wrangler.toml file support for hyperdrive * Fix hyperdrive update and add option to disable caching * Update binding variables and add configuration and deploy tests * add `hyperdrive: []` to draftworker upload form --------- Co-authored-by: Rahul Sethi <[email protected]>
1 parent d538973 commit ee6f345

23 files changed

+898
-0
lines changed

.changeset/happy-keys-rhyme.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Adds support for Hyperdrive, via `wrangler hyperdrive`.

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

+96
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("normalizeAndValidateConfig()", () => {
2828
d1_databases: [],
2929
vectorize: [],
3030
constellation: [],
31+
hyperdrive: [],
3132
dev: {
3233
ip: "0.0.0.0",
3334
local_protocol: "http",
@@ -2076,6 +2077,101 @@ describe("normalizeAndValidateConfig()", () => {
20762077
});
20772078
});
20782079

2080+
describe("[hyperdrive]", () => {
2081+
it("should error if hyperdrive is an object", () => {
2082+
const { diagnostics } = normalizeAndValidateConfig(
2083+
{ hyperdrive: {} } as unknown as RawConfig,
2084+
undefined,
2085+
{ env: undefined }
2086+
);
2087+
2088+
expect(diagnostics.hasWarnings()).toBe(false);
2089+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2090+
"Processing wrangler configuration:
2091+
- The field \\"hyperdrive\\" should be an array but got {}."
2092+
`);
2093+
});
2094+
2095+
it("should error if hyperdrive is a string", () => {
2096+
const { diagnostics } = normalizeAndValidateConfig(
2097+
{ hyperdrive: "BAD" } as unknown as RawConfig,
2098+
undefined,
2099+
{ env: undefined }
2100+
);
2101+
2102+
expect(diagnostics.hasWarnings()).toBe(false);
2103+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2104+
"Processing wrangler configuration:
2105+
- The field \\"hyperdrive\\" should be an array but got \\"BAD\\"."
2106+
`);
2107+
});
2108+
2109+
it("should error if hyperdrive is a number", () => {
2110+
const { diagnostics } = normalizeAndValidateConfig(
2111+
{ hyperdrive: 999 } as unknown as RawConfig,
2112+
undefined,
2113+
{ env: undefined }
2114+
);
2115+
2116+
expect(diagnostics.hasWarnings()).toBe(false);
2117+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2118+
"Processing wrangler configuration:
2119+
- The field \\"hyperdrive\\" should be an array but got 999."
2120+
`);
2121+
});
2122+
2123+
it("should error if hyperdrive is null", () => {
2124+
const { diagnostics } = normalizeAndValidateConfig(
2125+
{ hyperdrive: null } as unknown as RawConfig,
2126+
undefined,
2127+
{ env: undefined }
2128+
);
2129+
2130+
expect(diagnostics.hasWarnings()).toBe(false);
2131+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2132+
"Processing wrangler configuration:
2133+
- The field \\"hyperdrive\\" should be an array but got null."
2134+
`);
2135+
});
2136+
2137+
it("should accept valid bindings", () => {
2138+
const { diagnostics } = normalizeAndValidateConfig(
2139+
{
2140+
hyperdrive: [
2141+
{ binding: "VALID", id: "343cd4f1d58c42fbb5bd082592fd7143" },
2142+
],
2143+
} as unknown as RawConfig,
2144+
undefined,
2145+
{ env: undefined }
2146+
);
2147+
2148+
expect(diagnostics.hasErrors()).toBe(false);
2149+
});
2150+
2151+
it("should error if hyperdrive.bindings are not valid", () => {
2152+
const { diagnostics } = normalizeAndValidateConfig(
2153+
{
2154+
hyperdrive: [
2155+
{},
2156+
{ binding: "VALID", id: "343cd4f1d58c42fbb5bd082592fd7143" },
2157+
{ binding: 2000, project: 2111 },
2158+
],
2159+
} as unknown as RawConfig,
2160+
undefined,
2161+
{ env: undefined }
2162+
);
2163+
2164+
expect(diagnostics.hasWarnings()).toBe(true);
2165+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2166+
"Processing wrangler configuration:
2167+
- \\"hyperdrive[0]\\" bindings should have a string \\"binding\\" field but got {}.
2168+
- \\"hyperdrive[0]\\" bindings must have a \\"id\\" field but got {}.
2169+
- \\"hyperdrive[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":2000,\\"project\\":2111}.
2170+
- \\"hyperdrive[2]\\" bindings must have a \\"id\\" field but got {\\"binding\\":2000,\\"project\\":2111}."
2171+
`);
2172+
});
2173+
});
2174+
20792175
describe("[queues]", () => {
20802176
it("should error if queues is not an object", () => {
20812177
const { config, diagnostics } = normalizeAndValidateConfig(

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

+36
Original file line numberDiff line numberDiff line change
@@ -8394,6 +8394,42 @@ export default{
83948394
});
83958395
});
83968396

8397+
describe("hyperdrive", () => {
8398+
it("should upload hyperdrive bindings", async () => {
8399+
writeWranglerToml({
8400+
hyperdrive: [
8401+
{
8402+
binding: "HYPERDRIVE",
8403+
id: "343cd4f1d58c42fbb5bd082592fd7143",
8404+
},
8405+
],
8406+
});
8407+
await fs.promises.writeFile("index.js", `export default {};`);
8408+
mockSubDomainRequest();
8409+
mockUploadWorkerRequest({
8410+
expectedBindings: [
8411+
{
8412+
type: "hyperdrive",
8413+
name: "HYPERDRIVE",
8414+
id: "343cd4f1d58c42fbb5bd082592fd7143",
8415+
},
8416+
],
8417+
});
8418+
8419+
await runWrangler("deploy index.js");
8420+
expect(std.out).toMatchInlineSnapshot(`
8421+
"Total Upload: xx KiB / gzip: xx KiB
8422+
Your worker has access to the following bindings:
8423+
- Hyperdrive Configs:
8424+
- HYPERDRIVE: 343cd4f1d58c42fbb5bd082592fd7143
8425+
Uploaded test-name (TIMINGS)
8426+
Published test-name (TIMINGS)
8427+
https://test-name.test-sub-domain.workers.dev
8428+
Current Deployment ID: Galaxy-Class"
8429+
`);
8430+
});
8431+
});
8432+
83978433
describe("mtls_certificates", () => {
83988434
it("should upload mtls_certificate bindings", async () => {
83998435
writeWranglerToml({

0 commit comments

Comments
 (0)