Skip to content

Commit

Permalink
Update copy and route names to reflect changes on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
OilyLime committed Sep 19, 2023
1 parent e3a4e79 commit d590c7c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 70 deletions.
56 changes: 21 additions & 35 deletions packages/wrangler/src/hyperdrive/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fetchResult } from "../cfetch";
import { requireAuth } from "../user";
import type { Config } from "../config";

export type HyperdriveDatabase = {
export type HyperdriveConfig = {
id: string;
name: string;
origin: PublicOrigin;
Expand All @@ -28,63 +28,49 @@ export type CreateUpdateHyperdriveBody = {
origin: OriginWithPassword;
};

export async function createDatabase(
export async function createConfig(
config: Config,
body: CreateUpdateHyperdriveBody
): Promise<HyperdriveDatabase> {
): Promise<HyperdriveConfig> {
const accountId = await requireAuth(config);
return await fetchResult(`/accounts/${accountId}/hyperdrive/databases`, {
return await fetchResult(`/accounts/${accountId}/hyperdrive/configs`, {
method: "POST",
body: JSON.stringify(body),
});
}

export async function deleteDatabase(
config: Config,
id: string
): Promise<void> {
export async function deleteConfig(config: Config, id: string): Promise<void> {
const accountId = await requireAuth(config);
return await fetchResult(
`/accounts/${accountId}/hyperdrive/databases/${id}`,
{
method: "DELETE",
}
);
return await fetchResult(`/accounts/${accountId}/hyperdrive/configs/${id}`, {
method: "DELETE",
});
}

export async function getDatabase(
export async function getConfig(
config: Config,
id: string
): Promise<HyperdriveDatabase> {
): Promise<HyperdriveConfig> {
const accountId = await requireAuth(config);
return await fetchResult(
`/accounts/${accountId}/hyperdrive/databases/${id}`,
{
method: "GET",
}
);
return await fetchResult(`/accounts/${accountId}/hyperdrive/configs/${id}`, {
method: "GET",
});
}

export async function listDatabases(
config: Config
): Promise<HyperdriveDatabase[]> {
export async function listConfigs(config: Config): Promise<HyperdriveConfig[]> {
const accountId = await requireAuth(config);
return await fetchResult(`/accounts/${accountId}/hyperdrive/databases`, {
return await fetchResult(`/accounts/${accountId}/hyperdrive/configs`, {
method: "GET",
});
}

export async function updateDatabase(
export async function updateConfig(
config: Config,
id: string,
body: CreateUpdateHyperdriveBody
): Promise<HyperdriveDatabase> {
): Promise<HyperdriveConfig> {
const accountId = await requireAuth(config);
return await fetchResult(
`/accounts/${accountId}/hyperdrive/databases/${id}`,
{
method: "PUT",
body: JSON.stringify(body),
}
);
return await fetchResult(`/accounts/${accountId}/hyperdrive/configs/${id}`, {
method: "PUT",
body: JSON.stringify(body),
});
}
10 changes: 5 additions & 5 deletions packages/wrangler/src/hyperdrive/create.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readConfig } from "../config";
import { logger } from "../logger";
import { createDatabase } from "./client";
import { createConfig } from "./client";
import { hyperdriveBetaWarning } from "./common";
import type {
CommonYargsArgv,
Expand All @@ -12,14 +12,14 @@ export function options(yargs: CommonYargsArgv) {
.positional("name", {
type: "string",
demandOption: true,
description: "The name of the Hyperdrive database configuration",
description: "The name of the Hyperdrive config",
})
.options({
"connection-string": {
type: "string",
demandOption: true,
describe:
"The connection string for the database want Hyperdrive to connect to - ex: protocol://user:password@host:port/database",
"The connection string for the database you want Hyperdrive to connect to - ex: protocol://user:password@host:port/database",
},
})
.epilogue(hyperdriveBetaWarning);
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function handler(
);
} else {
logger.log(`🚧 Creating '${args.name}'`);
const database = await createDatabase(config, {
const database = await createConfig(config, {
name: args.name,
origin: {
host: url.hostname,
Expand All @@ -76,7 +76,7 @@ export async function handler(
},
});
logger.log(
`✅ Created new Hyperdrive configuration\n`,
`✅ Created new Hyperdrive config\n`,
JSON.stringify(database, null, 2)
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/wrangler/src/hyperdrive/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readConfig } from "../config";
import { logger } from "../logger";
import { deleteDatabase } from "./client";
import { deleteConfig } from "./client";
import { hyperdriveBetaWarning } from "./common";
import type {
CommonYargsArgv,
Expand All @@ -12,7 +12,7 @@ export function options(yargs: CommonYargsArgv) {
.positional("id", {
type: "string",
demandOption: true,
description: "The ID of the Hyperdrive database configuration",
description: "The ID of the Hyperdrive config",
})
.epilogue(hyperdriveBetaWarning);
}
Expand All @@ -22,7 +22,7 @@ export async function handler(
) {
const config = readConfig(args.config, args);

logger.log(`🗑️ Deleting Hyperdrive database configuration ${args.id}`);
await deleteDatabase(config, args.id);
logger.log(`🗑️ Deleting Hyperdrive database config ${args.id}`);
await deleteConfig(config, args.id);
logger.log(`✅ Deleted`);
}
6 changes: 3 additions & 3 deletions packages/wrangler/src/hyperdrive/get.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readConfig } from "../config";
import { logger } from "../logger";
import { getDatabase } from "./client";
import { getConfig } from "./client";
import { hyperdriveBetaWarning } from "./common";
import type {
CommonYargsArgv,
Expand All @@ -12,7 +12,7 @@ export function options(yargs: CommonYargsArgv) {
.positional("id", {
type: "string",
demandOption: true,
description: "The ID of the Hyperdrive database configuration",
description: "The ID of the Hyperdrive config",
})
.epilogue(hyperdriveBetaWarning);
}
Expand All @@ -22,6 +22,6 @@ export async function handler(
) {
const config = readConfig(args.config, args);

const database = await getDatabase(config, args.id);
const database = await getConfig(config, args.id);
logger.log(JSON.stringify(database, null, 2));
}
20 changes: 5 additions & 15 deletions packages/wrangler/src/hyperdrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,21 @@ export function hyperdrive(yargs: CommonYargsArgv) {
return yargs
.command(
"create <name>",
"Create a Hyperdrive database configuration",
"Create a Hyperdrive config",
createOptions,
createHandler
)
.command(
"delete <id>",
"Delete a Hyperdrive database configuration",
"Delete a Hyperdrive config",
deleteOptions,
deleteHandler
)
.command(
"get <id>",
"Get a Hyperdrive database configuration",
getOptions,
getHandler
)
.command(
"list",
"List Hyperdrive database configurations",
listOptions,
listHandler
)
.command("get <id>", "Get a Hyperdrive config", getOptions, getHandler)
.command("list", "List Hyperdrive configs", listOptions, listHandler)
.command(
"update <id>",
"Update a Hyperdrive database configuration",
"Update a Hyperdrive config",
updateOptions,
updateHandler
)
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/hyperdrive/list.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readConfig } from "../config";
import { logger } from "../logger";
import { listDatabases } from "./client";
import { listConfigs } from "./client";
import { hyperdriveBetaWarning } from "./common";
import type {
CommonYargsArgv,
Expand All @@ -16,8 +16,8 @@ export async function handler(
) {
const config = readConfig(args.config, args);

logger.log(`📋 Listing Hyperdrive databases`);
const databases = await listDatabases(config);
logger.log(`📋 Listing Hyperdrive configs`);
const databases = await listConfigs(config);
logger.table(
databases.map((database) => ({
id: database.id,
Expand Down
10 changes: 5 additions & 5 deletions packages/wrangler/src/hyperdrive/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { readConfig } from "../config";
import { logger } from "../logger";
import { getDatabase, updateDatabase } from "./client";
import { getConfig, updateConfig } from "./client";
import { hyperdriveBetaWarning } from "./common";
import type {
CommonYargsArgv,
Expand All @@ -13,7 +13,7 @@ export function options(yargs: CommonYargsArgv) {
.positional("id", {
type: "string",
demandOption: true,
description: "The ID of the Hyperdrive configuration",
description: "The ID of the Hyperdrive config",
})
.options({
"origin-host": {
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function handler(
const config = readConfig(args.config, args);

logger.log(`🚧 Updating '${args.id}'`);
const database = (await getDatabase(
const database = (await getConfig(
config,
args.id
)) as CreateUpdateHyperdriveBody;
Expand All @@ -74,9 +74,9 @@ export async function handler(
database.origin.password = args.originPassword;
}

const updated = await updateDatabase(config, args.id, database);
const updated = await updateConfig(config, args.id, database);
logger.log(
`✅ Updated ${updated.id} Hyperdrive configuration\n`,
`✅ Updated ${updated.id} Hyperdrive config\n`,
JSON.stringify(updated, null, 2)
);
}

0 comments on commit d590c7c

Please sign in to comment.