Skip to content

Commit ecbab5d

Browse files
knickishknickishCarmenPopoviciu
authoredMar 28, 2025··
[wrangler] improve formatting of cache options in hyperdrive list command (#8583)
Co-authored-by: knickish <knickish@cloudflare.com> Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>
1 parent 42f4912 commit ecbab5d

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed
 

‎.changeset/good-taxis-repeat.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Improve formatting of cache options for hyperdrive list command

‎packages/wrangler/src/__tests__/hyperdrive.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -668,15 +668,15 @@ describe("hyperdrive commands", () => {
668668
await runWrangler("hyperdrive list");
669669
expect(std.out).toMatchInlineSnapshot(`
670670
"📋 Listing Hyperdrive configs
671-
┌──────────────────────────────────────┬─────────────┬─────────┬────────────────┬──────┬────────────┬───────────┬───────────────────┬───────────────────────────────────────────────────────────────┐
672-
│ id │ name │ user │ host │ port │ scheme │ database │ caching │ mtls │
673-
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────────────────┤
674-
│ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │ test123 │ test │ example.com │ 5432 │ PostgreSQL │ neondb │ │ │
675-
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────────────────┤
676-
│ yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy │ new-db │ dbuser │ www.google.com │ 3211 │ PostgreSQL │ mydb │ {\\"disabled\\":true} │ │
677-
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼───────────────────┼───────────────────────────────────────────────────────────────┤
678-
│ zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz │ new-db-mtls │ pg-mtls │ www.mtls.com │ 3212 │ │ mydb-mtls │ │ {\\"ca_certificate_uuid\\":\\"1234\\",\\"mtls_certificate_uuid\\":\\"1234\\"} │
679-
└──────────────────────────────────────┴─────────────┴─────────┴────────────────┴──────┴────────────┴───────────┴───────────────────┴───────────────────────────────────────────────────────────────┘"
671+
┌──────────────────────────────────────┬─────────────┬─────────┬────────────────┬──────┬────────────┬───────────┬──────────┬───────────────────────────────────────────────────────────────┐
672+
│ id │ name │ user │ host │ port │ scheme │ database │ caching │ mtls │
673+
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼──────────┼───────────────────────────────────────────────────────────────┤
674+
│ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │ test123 │ test │ example.com │ 5432 │ PostgreSQL │ neondb │ enabled │ │
675+
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼──────────┼───────────────────────────────────────────────────────────────┤
676+
│ yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy │ new-db │ dbuser │ www.google.com │ 3211 │ PostgreSQL │ mydb │ disabled │ │
677+
├──────────────────────────────────────┼─────────────┼─────────┼────────────────┼──────┼────────────┼───────────┼──────────┼───────────────────────────────────────────────────────────────┤
678+
│ zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz │ new-db-mtls │ pg-mtls │ www.mtls.com │ 3212 │ │ mydb-mtls │ enabled │ {\\"ca_certificate_uuid\\":\\"1234\\",\\"mtls_certificate_uuid\\":\\"1234\\"} │
679+
└──────────────────────────────────────┴─────────────┴─────────┴────────────────┴──────┴────────────┴───────────┴──────────┴───────────────────────────────────────────────────────────────┘"
680680
`);
681681
});
682682

‎packages/wrangler/src/hyperdrive/list.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { readConfig } from "../config";
22
import { logger } from "../logger";
33
import { listConfigs } from "./client";
4-
import { capitalizeScheme } from "./shared";
4+
import { capitalizeScheme, formatCachingOptions } from "./shared";
55
import type {
66
CommonYargsArgv,
77
StrictYargsOptionsToInterface,
@@ -27,7 +27,7 @@ export async function handler(
2727
port: database.origin.port?.toString() ?? "",
2828
scheme: capitalizeScheme(database.origin.scheme),
2929
database: database.origin.database ?? "",
30-
caching: JSON.stringify(database.caching),
30+
caching: formatCachingOptions(database.caching),
3131
mtls: JSON.stringify(database.mtls),
3232
}))
3333
);

‎packages/wrangler/src/hyperdrive/shared.ts

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { CachingOptions } from "./client";
2+
13
export function capitalizeScheme(scheme: string | undefined) {
24
switch (scheme) {
35
case "mysql":
@@ -9,3 +11,25 @@ export function capitalizeScheme(scheme: string | undefined) {
911
return "";
1012
}
1113
}
14+
15+
export function formatCachingOptions(
16+
cachingOptions: CachingOptions | undefined
17+
): string {
18+
switch (cachingOptions?.disabled) {
19+
case false: {
20+
if (cachingOptions.stale_while_revalidate === 0) {
21+
return `max_age: ${cachingOptions.max_age}, stale_while_revalidate: disabled`;
22+
} else {
23+
return `max_age: ${cachingOptions.max_age}, stale_while_revalidate: ${cachingOptions.stale_while_revalidate}`;
24+
}
25+
}
26+
case undefined: {
27+
return "enabled";
28+
}
29+
case true: {
30+
return "disabled";
31+
}
32+
default:
33+
return JSON.stringify(cachingOptions);
34+
}
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.