Skip to content

Commit ef89e6b

Browse files
CarmenPopoviciuknickish
and
knickish
authored
[wrangler] improve formatting of cache options in hyperdrive list command (#8703)
Co-authored-by: knickish <[email protected]>
1 parent 90d93c9 commit ef89e6b

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

Diff for: .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

Diff for: packages/wrangler/src/__tests__/hyperdrive.test.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,13 @@ describe("hyperdrive commands", () => {
545545
await runWrangler("hyperdrive list");
546546
expect(std.out).toMatchInlineSnapshot(`
547547
"📋 Listing Hyperdrive configs
548-
┌──────────────────────────────────────┬─────────┬────────┬────────────────┬──────┬──────────┬───────────────────
549-
│ id │ name │ user │ host │ port │ database │ caching
550-
├──────────────────────────────────────┼─────────┼────────┼────────────────┼──────┼──────────┼───────────────────
551-
│ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │ test123 │ test │ example.com │ 5432 │ neondb │
552-
├──────────────────────────────────────┼─────────┼────────┼────────────────┼──────┼──────────┼───────────────────
553-
│ yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy │ new-db │ dbuser │ www.google.com │ 3211 │ mydb │ {\\"disabled\\":true}
554-
└──────────────────────────────────────┴─────────┴────────┴────────────────┴──────┴──────────┴───────────────────┘"
548+
┌──────────────────────────────────────┬─────────┬────────┬────────────────┬──────┬──────────┬──────────┐
549+
│ id │ name │ user │ host │ port │ database │ caching │
550+
├──────────────────────────────────────┼─────────┼────────┼────────────────┼──────┼──────────┼──────────┤
551+
│ xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx │ test123 │ test │ example.com │ 5432 │ neondb │ enabled
552+
├──────────────────────────────────────┼─────────┼────────┼────────────────┼──────┼──────────┼──────────┤
553+
│ yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy │ new-db │ dbuser │ www.google.com │ 3211 │ mydb │ disabled │
554+
└──────────────────────────────────────┴─────────┴────────┴────────────────┴──────┴──────────┴──────────┘"
555555
`);
556556
});
557557

Diff for: packages/wrangler/src/hyperdrive/list.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readConfig } from "../config";
22
import { logger } from "../logger";
33
import { listConfigs } from "./client";
4+
import { formatCachingOptions } from "./shared";
45
import type {
56
CommonYargsArgv,
67
StrictYargsOptionsToInterface,
@@ -25,7 +26,7 @@ export async function handler(
2526
host: database.origin.host ?? "",
2627
port: database.origin.port?.toString() ?? "",
2728
database: database.origin.database ?? "",
28-
caching: JSON.stringify(database.caching),
29+
caching: formatCachingOptions(database.caching),
2930
}))
3031
);
3132
}

Diff for: packages/wrangler/src/hyperdrive/shared.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { CachingOptions } from "./client";
2+
3+
export function formatCachingOptions(
4+
cachingOptions: CachingOptions | undefined
5+
): string {
6+
switch (cachingOptions?.disabled) {
7+
case false: {
8+
if (cachingOptions.stale_while_revalidate === 0) {
9+
return `max_age: ${cachingOptions.max_age}, stale_while_revalidate: disabled`;
10+
} else {
11+
return `max_age: ${cachingOptions.max_age}, stale_while_revalidate: ${cachingOptions.stale_while_revalidate}`;
12+
}
13+
}
14+
case undefined: {
15+
return "enabled";
16+
}
17+
case true: {
18+
return "disabled";
19+
}
20+
default:
21+
return JSON.stringify(cachingOptions);
22+
}
23+
}

0 commit comments

Comments
 (0)