wrangler 0.0.0-e33bea9b → 0.0.0-e351afcf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/miniflare-dist/index.mjs +167 -93
  2. package/package.json +14 -9
  3. package/src/__tests__/api-devregistry.test.ts +121 -0
  4. package/src/__tests__/api.test.ts +27 -5
  5. package/src/__tests__/configuration.test.ts +59 -12
  6. package/src/__tests__/constellation.test.ts +371 -0
  7. package/src/__tests__/d1/execute.test.ts +2 -0
  8. package/src/__tests__/d1/migrate.test.ts +102 -0
  9. package/src/__tests__/delete.test.ts +6 -0
  10. package/src/__tests__/deployments.test.ts +335 -95
  11. package/src/__tests__/dev.test.tsx +71 -56
  12. package/src/__tests__/generate.test.ts +3 -4
  13. package/src/__tests__/helpers/mock-console.ts +6 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  15. package/src/__tests__/helpers/msw/index.ts +4 -2
  16. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  17. package/src/__tests__/index.test.ts +14 -6
  18. package/src/__tests__/init.test.ts +127 -96
  19. package/src/__tests__/jest.setup.ts +4 -0
  20. package/src/__tests__/kv.test.ts +9 -9
  21. package/src/__tests__/logger.test.ts +68 -2
  22. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  23. package/src/__tests__/middleware.test.ts +2 -2
  24. package/src/__tests__/mtls-certificates.test.ts +7 -3
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +70 -0
  27. package/src/__tests__/pages/project-list.test.ts +2 -0
  28. package/src/__tests__/pages/project-upload.test.ts +43 -24
  29. package/src/__tests__/pages/publish.test.ts +136 -92
  30. package/src/__tests__/publish.test.ts +878 -332
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  34. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  35. package/src/__tests__/user.test.ts +1 -1
  36. package/src/__tests__/worker-namespace.test.ts +1 -0
  37. package/src/api/dev.ts +12 -18
  38. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  39. package/src/api/pages/publish.tsx +28 -12
  40. package/src/bundle.ts +26 -9
  41. package/src/config/environment.ts +27 -0
  42. package/src/config/index.ts +18 -0
  43. package/src/config/validation.ts +91 -1
  44. package/src/constellation/createProject.tsx +51 -0
  45. package/src/constellation/deleteProject.ts +51 -0
  46. package/src/constellation/deleteProjectModel.ts +68 -0
  47. package/src/constellation/index.ts +75 -0
  48. package/src/constellation/listCatalog.tsx +35 -0
  49. package/src/constellation/listModel.tsx +41 -0
  50. package/src/constellation/listProject.tsx +28 -0
  51. package/src/constellation/listRuntime.tsx +28 -0
  52. package/src/constellation/options.ts +17 -0
  53. package/src/constellation/types.ts +17 -0
  54. package/src/constellation/uploadModel.tsx +64 -0
  55. package/src/constellation/utils.ts +90 -0
  56. package/src/create-worker-upload-form.ts +18 -1
  57. package/src/d1/backups.tsx +19 -15
  58. package/src/d1/create.tsx +45 -39
  59. package/src/d1/delete.ts +1 -1
  60. package/src/d1/execute.tsx +23 -20
  61. package/src/d1/list.tsx +14 -12
  62. package/src/d1/migrations/apply.tsx +36 -30
  63. package/src/d1/migrations/create.tsx +15 -12
  64. package/src/d1/migrations/helpers.ts +5 -8
  65. package/src/d1/migrations/list.tsx +10 -7
  66. package/src/deployments.ts +260 -8
  67. package/src/dev/dev.tsx +2 -0
  68. package/src/dev/local.tsx +48 -20
  69. package/src/dev/start-server.ts +49 -46
  70. package/src/dev/use-esbuild.ts +52 -49
  71. package/src/dev-registry.ts +2 -1
  72. package/src/dev.tsx +11 -5
  73. package/src/docs/helpers.ts +50 -0
  74. package/src/docs/index.ts +25 -68
  75. package/src/entry.ts +19 -8
  76. package/src/environment-variables/factory.ts +2 -1
  77. package/src/generate/index.ts +2 -2
  78. package/src/index.ts +86 -23
  79. package/src/init.ts +144 -135
  80. package/src/kv/helpers.ts +7 -4
  81. package/src/logger.ts +23 -4
  82. package/src/metrics/send-event.ts +2 -1
  83. package/src/miniflare-cli/index.ts +2 -2
  84. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  85. package/src/module-collection.ts +92 -26
  86. package/src/pages/build.ts +29 -17
  87. package/src/pages/deployments.tsx +3 -5
  88. package/src/pages/dev.ts +24 -6
  89. package/src/pages/functions/buildPlugin.ts +1 -0
  90. package/src/pages/functions/buildWorker.ts +59 -8
  91. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  92. package/src/pages/projects.tsx +2 -5
  93. package/src/pages/upload.tsx +24 -4
  94. package/src/publish/publish.ts +10 -26
  95. package/src/queues/cli/commands/consumer/add.ts +6 -0
  96. package/src/queues/client.ts +1 -0
  97. package/src/secret/index.ts +1 -0
  98. package/src/sites.ts +164 -52
  99. package/src/traverse-module-graph.ts +53 -0
  100. package/src/user/user.ts +1 -0
  101. package/src/utils/render.ts +93 -0
  102. package/src/worker.ts +10 -0
  103. package/wrangler-dist/cli.d.ts +29 -2
  104. package/wrangler-dist/cli.js +23270 -22110
  105. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -0,0 +1,68 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { withConfig } from "../config";
3
+ import { confirm } from "../dialogs";
4
+ import { logger } from "../logger";
5
+ import { requireAuth } from "../user";
6
+ import { takeName } from "./options";
7
+ import {
8
+ constellationBetaWarning,
9
+ getProjectByName,
10
+ getProjectModelByName,
11
+ } from "./utils";
12
+ import type {
13
+ CommonYargsArgv,
14
+ StrictYargsOptionsToInterface,
15
+ } from "../yargs-types";
16
+ import type { Project, Model } from "./types";
17
+
18
+ export function options(yargs: CommonYargsArgv) {
19
+ return takeName(yargs)
20
+ .positional("modelName", {
21
+ describe: "The name of the uploaded model",
22
+ type: "string",
23
+ demandOption: true,
24
+ })
25
+ .option("force", {
26
+ describe: "Skip confirmation",
27
+ type: "boolean",
28
+ alias: "f",
29
+ default: false,
30
+ })
31
+ .epilogue(constellationBetaWarning);
32
+ }
33
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
34
+ export const handler = withConfig<HandlerOptions>(
35
+ async ({ name, modelName, force, config }): Promise<void> => {
36
+ const accountId = await requireAuth(config);
37
+ logger.log(constellationBetaWarning);
38
+
39
+ const proj: Project = await getProjectByName(config, accountId, name);
40
+
41
+ const model: Model = await getProjectModelByName(
42
+ config,
43
+ accountId,
44
+ proj,
45
+ modelName
46
+ );
47
+
48
+ logger.log(`About to delete Model '${modelName}' (${model.id}).`);
49
+ if (!force) {
50
+ const response = await confirm(`Ok to proceed?`);
51
+ if (!response) {
52
+ logger.log(`Not deleting.`);
53
+ return;
54
+ }
55
+
56
+ logger.log("Deleting...");
57
+ }
58
+
59
+ await fetchResult(
60
+ `/accounts/${accountId}/constellation/project/${proj.id}/model/${model.id}`,
61
+ {
62
+ method: "DELETE",
63
+ }
64
+ );
65
+
66
+ logger.log(`Deleted '${modelName}' successfully.`);
67
+ }
68
+ );
@@ -0,0 +1,75 @@
1
+ import * as CreateProject from "./createProject";
2
+ import * as DeleteProject from "./deleteProject";
3
+ import * as DeleteProjectModel from "./deleteProjectModel";
4
+ import * as ListCatalog from "./listCatalog";
5
+ import * as ListModel from "./listModel";
6
+ import * as ListProject from "./listProject";
7
+ import * as ListRuntime from "./listRuntime";
8
+ import * as UploadModel from "./uploadModel";
9
+ import type { CommonYargsArgv } from "../yargs-types";
10
+
11
+ export function constellation(yargs: CommonYargsArgv) {
12
+ return yargs
13
+ .command("project", "Manage your projects", (constProjYargs) => {
14
+ return constProjYargs
15
+ .command(
16
+ "list",
17
+ "List your projects",
18
+ ListProject.options,
19
+ ListProject.handler
20
+ )
21
+ .command(
22
+ "create <name> <runtime>",
23
+ "Create project",
24
+ CreateProject.options,
25
+ CreateProject.handler
26
+ )
27
+ .command(
28
+ "delete <name>",
29
+ "Delete project",
30
+ DeleteProject.options,
31
+ DeleteProject.handler
32
+ );
33
+ })
34
+ .command("model", "Manage your models", (constModelYargs) => {
35
+ return constModelYargs
36
+ .command(
37
+ "upload <name> <modelName> <modelFile>",
38
+ "Upload a model for an existing project",
39
+ UploadModel.options,
40
+ UploadModel.handler
41
+ )
42
+ .command(
43
+ "list <name>",
44
+ "List models of a project",
45
+ ListModel.options,
46
+ ListModel.handler
47
+ )
48
+ .command(
49
+ "delete <name> <modelName>",
50
+ "Delete a model of a project",
51
+ DeleteProjectModel.options,
52
+ DeleteProjectModel.handler
53
+ );
54
+ })
55
+ .command(
56
+ "catalog",
57
+ "Check the curated model catalog",
58
+ (constCatalogYargs) => {
59
+ return constCatalogYargs.command(
60
+ "list",
61
+ "List catalog models",
62
+ ListCatalog.options,
63
+ ListCatalog.handler
64
+ );
65
+ }
66
+ )
67
+ .command("runtime", "Check the suported runtimes", (constRuntimeYargs) => {
68
+ return constRuntimeYargs.command(
69
+ "list",
70
+ "List suported runtimes",
71
+ ListRuntime.options,
72
+ ListRuntime.handler
73
+ );
74
+ });
75
+ }
@@ -0,0 +1,35 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listCatalogEntries } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const entries = await listCatalogEntries(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(entries, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(
26
+ entries.map((entry) => ({
27
+ project_id: entry.project.id,
28
+ project_name: entry.project.name,
29
+ project_runtime: entry.project.runtime,
30
+ models: entry.models.map((model) => model.name).join(","),
31
+ }))
32
+ );
33
+ }
34
+ }
35
+ );
@@ -0,0 +1,41 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { takeName } from "./options";
5
+ import {
6
+ constellationBetaWarning,
7
+ getProjectByName,
8
+ listModels,
9
+ } from "./utils";
10
+ import type {
11
+ CommonYargsArgv,
12
+ StrictYargsOptionsToInterface,
13
+ } from "../yargs-types";
14
+ import type { Project } from "./types";
15
+
16
+ export function options(yargs: CommonYargsArgv) {
17
+ return takeName(yargs)
18
+ .option("json", {
19
+ describe: "return output as clean JSON",
20
+ type: "boolean",
21
+ default: false,
22
+ })
23
+ .epilogue(constellationBetaWarning);
24
+ }
25
+
26
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
27
+ export const handler = withConfig<HandlerOptions>(
28
+ async ({ name, json, config }): Promise<void> => {
29
+ const accountId = await requireAuth(config);
30
+ const proj: Project = await getProjectByName(config, accountId, name);
31
+
32
+ const models = await listModels(accountId, proj);
33
+
34
+ if (json) {
35
+ logger.log(JSON.stringify(models, null, 2));
36
+ } else {
37
+ logger.log(constellationBetaWarning);
38
+ logger.table(models);
39
+ }
40
+ }
41
+ );
@@ -0,0 +1,28 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listProjects } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const projs = await listProjects(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(projs, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(projs);
26
+ }
27
+ }
28
+ );
@@ -0,0 +1,28 @@
1
+ import { withConfig } from "../config";
2
+ import { logger } from "../logger";
3
+ import { requireAuth } from "../user";
4
+ import { asJson } from "./options";
5
+ import { constellationBetaWarning, listRuntimes } from "./utils";
6
+ import type {
7
+ CommonYargsArgv,
8
+ StrictYargsOptionsToInterface,
9
+ } from "../yargs-types";
10
+
11
+ export function options(yargs: CommonYargsArgv) {
12
+ return asJson(yargs).epilogue(constellationBetaWarning);
13
+ }
14
+
15
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
16
+ export const handler = withConfig<HandlerOptions>(
17
+ async ({ json, config }): Promise<void> => {
18
+ const accountId = await requireAuth(config);
19
+ const runtimes = await listRuntimes(accountId);
20
+
21
+ if (json) {
22
+ logger.log(JSON.stringify(runtimes, null, 2));
23
+ } else {
24
+ logger.log(constellationBetaWarning);
25
+ logger.table(runtimes.map((runtime) => ({ name: runtime })));
26
+ }
27
+ }
28
+ );
@@ -0,0 +1,17 @@
1
+ import type { CommonYargsArgv } from "../yargs-types";
2
+
3
+ export function takeName(yargs: CommonYargsArgv) {
4
+ return yargs.positional("name", {
5
+ describe: "The name of the project",
6
+ type: "string",
7
+ demandOption: true,
8
+ });
9
+ }
10
+
11
+ export function asJson(yargs: CommonYargsArgv) {
12
+ return yargs.option("json", {
13
+ describe: "return output as clean JSON",
14
+ type: "boolean",
15
+ default: false,
16
+ });
17
+ }
@@ -0,0 +1,17 @@
1
+ export type Project = {
2
+ id: string;
3
+ name: string;
4
+ runtime: string;
5
+ };
6
+
7
+ export type Model = {
8
+ id: string;
9
+ project_id: string;
10
+ name: string;
11
+ description: string;
12
+ };
13
+
14
+ export type CatalogEntry = {
15
+ project: Project;
16
+ models: Model[];
17
+ };
@@ -0,0 +1,64 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { FormData, File } from "undici";
3
+ import { fetchResult } from "../cfetch";
4
+ import { withConfig } from "../config";
5
+ import { logger } from "../logger";
6
+ import { requireAuth } from "../user";
7
+ import { takeName } from "./options";
8
+ import { constellationBetaWarning, getProjectByName } from "./utils";
9
+ import type {
10
+ CommonYargsArgv,
11
+ StrictYargsOptionsToInterface,
12
+ } from "../yargs-types";
13
+ import type { Model } from "./types";
14
+
15
+ export function options(yargs: CommonYargsArgv) {
16
+ return takeName(yargs)
17
+ .positional("modelName", {
18
+ describe: "The name of the uploaded model",
19
+ type: "string",
20
+ demandOption: true,
21
+ })
22
+ .positional("modelFile", {
23
+ describe: "The name of the local file with the model contents",
24
+ type: "string",
25
+ demandOption: true,
26
+ })
27
+ .epilogue(constellationBetaWarning);
28
+ }
29
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof options>;
30
+ export const handler = withConfig<HandlerOptions>(
31
+ async ({ name, modelName, modelFile, config }): Promise<void> => {
32
+ const accountId = await requireAuth(config);
33
+ logger.log(constellationBetaWarning);
34
+
35
+ const proj = await getProjectByName(config, accountId, name);
36
+
37
+ const formData = new FormData();
38
+ formData.set(
39
+ "file",
40
+ new File([readFileSync(modelFile)], modelFile, {
41
+ type: "application/octet-stream",
42
+ })
43
+ );
44
+ formData.set("name", modelName);
45
+
46
+ let model: Model;
47
+ try {
48
+ model = await fetchResult(
49
+ `/accounts/${accountId}/constellation/project/${proj.id}/model`,
50
+ {
51
+ method: "POST",
52
+ body: formData,
53
+ }
54
+ );
55
+ } catch (e) {
56
+ if ((e as { code: number }).code === 7408) {
57
+ throw new Error("A model with that name already exists");
58
+ }
59
+ throw e;
60
+ }
61
+
62
+ logger.log(`✅ Successfully uploaded Model "${model.name}"!`);
63
+ }
64
+ );
@@ -0,0 +1,90 @@
1
+ import { fetchResult } from "../cfetch";
2
+ import { getEnvironmentVariableFactory } from "../environment-variables/factory";
3
+ import type { Config } from "../config";
4
+ import type { Project, Model, CatalogEntry } from "./types";
5
+
6
+ export const getConstellationWarningFromEnv = getEnvironmentVariableFactory({
7
+ variableName: "NO_CONSTELLATION_WARNING",
8
+ });
9
+
10
+ export const constellationBetaWarning =
11
+ getConstellationWarningFromEnv() !== undefined
12
+ ? ""
13
+ : "--------------------\n🚧 Constellation AI is currently in open alpha and is not recommended for production data and traffic\n🚧 Please report any bugs to https://github.com/cloudflare/workers-sdk/issues/new/choose\n🚧 To give feedback, visit https://discord.gg/cloudflaredev\n--------------------\n";
14
+
15
+ export const getProjectByName = async (
16
+ config: Config,
17
+ accountId: string,
18
+ name: string
19
+ ): Promise<Project> => {
20
+ const allProjects = await listProjects(accountId);
21
+ const matchingProj = allProjects.find((proj) => proj.name === name);
22
+ if (!matchingProj) {
23
+ throw new Error(`Couldn't find Project with name '${name}'`);
24
+ }
25
+ return matchingProj;
26
+ };
27
+
28
+ export const getProjectModelByName = async (
29
+ config: Config,
30
+ accountId: string,
31
+ proj: Project,
32
+ modelName: string
33
+ ): Promise<Model> => {
34
+ const allModels = await listModels(accountId, proj);
35
+ const matchingModel = allModels.find((model) => model.name === modelName);
36
+ if (!matchingModel) {
37
+ throw new Error(`Couldn't find Model with name '${modelName}'`);
38
+ }
39
+ return matchingModel;
40
+ };
41
+
42
+ export async function constellationList<ResponseType>(
43
+ accountId: string,
44
+ partialUrl: string
45
+ ): Promise<Array<ResponseType>> {
46
+ const pageSize = 50;
47
+ let page = 1;
48
+ const results = [];
49
+ while (results.length % pageSize === 0) {
50
+ const json: Array<ResponseType> = await fetchResult(
51
+ `/accounts/${accountId}/constellation/${partialUrl}`,
52
+ {},
53
+ new URLSearchParams({
54
+ per_page: pageSize.toString(),
55
+ page: page.toString(),
56
+ })
57
+ );
58
+ page++;
59
+ results.push(...json);
60
+ if (json.length < pageSize) {
61
+ break;
62
+ }
63
+ }
64
+ return results;
65
+ }
66
+
67
+ export const listCatalogEntries = async (
68
+ accountId: string
69
+ ): Promise<Array<CatalogEntry>> => {
70
+ return await constellationList(accountId, "catalog");
71
+ };
72
+
73
+ export const listModels = async (
74
+ accountId: string,
75
+ proj: Project
76
+ ): Promise<Array<Model>> => {
77
+ return constellationList(accountId, `project/${proj.id}/model`);
78
+ };
79
+
80
+ export const listProjects = async (
81
+ accountId: string
82
+ ): Promise<Array<Project>> => {
83
+ return await constellationList(accountId, "project");
84
+ };
85
+
86
+ export const listRuntimes = async (
87
+ accountId: string
88
+ ): Promise<Array<string>> => {
89
+ return await constellationList(accountId, "runtime");
90
+ };
@@ -23,7 +23,7 @@ export function toMimeType(type: CfModuleType): string {
23
23
  }
24
24
  }
25
25
 
26
- type WorkerMetadataBinding =
26
+ export type WorkerMetadataBinding =
27
27
  // If you add any new binding types here, also add it to safeBindings
28
28
  // under validateUnsafeBinding in config/validation.ts
29
29
  | { type: "plain_text"; name: string; text: string }
@@ -32,6 +32,12 @@ type WorkerMetadataBinding =
32
32
  | { type: "text_blob"; name: string; part: string }
33
33
  | { type: "data_blob"; name: string; part: string }
34
34
  | { type: "kv_namespace"; name: string; namespace_id: string }
35
+ | {
36
+ type: "send_email";
37
+ name: string;
38
+ destination_address?: string;
39
+ allowed_destination_addresses?: string[];
40
+ }
35
41
  | {
36
42
  type: "durable_object_namespace";
37
43
  name: string;
@@ -105,6 +111,17 @@ export function createWorkerUploadForm(worker: CfWorkerInit): FormData {
105
111
  });
106
112
  });
107
113
 
114
+ bindings.send_email?.forEach(
115
+ ({ name, destination_address, allowed_destination_addresses }) => {
116
+ metadataBindings.push({
117
+ name: name,
118
+ type: "send_email",
119
+ destination_address,
120
+ allowed_destination_addresses,
121
+ });
122
+ }
123
+ );
124
+
108
125
  bindings.durable_objects?.bindings.forEach(
109
126
  ({ name, class_name, script_name, environment }) => {
110
127
  metadataBindings.push({
@@ -1,6 +1,5 @@
1
1
  import fs from "node:fs/promises";
2
2
  import * as path from "path";
3
- import { render } from "ink";
4
3
  import Table from "ink-table";
5
4
  import React from "react";
6
5
  import { fetchResult } from "../cfetch";
@@ -8,6 +7,7 @@ import { performApiFetch } from "../cfetch/internal";
8
7
  import { withConfig } from "../config";
9
8
  import { logger } from "../logger";
10
9
  import { requireAuth } from "../user";
10
+ import { renderToString } from "../utils/render";
11
11
  import { formatBytes, formatTimeAgo } from "./formatTimeAgo";
12
12
  import { Name } from "./options";
13
13
  import { d1BetaWarning, getDatabaseByNameOrBinding } from "./utils";
@@ -24,7 +24,7 @@ export function ListOptions(yargs: CommonYargsArgv) {
24
24
  type ListHandlerOptions = StrictYargsOptionsToInterface<typeof ListOptions>;
25
25
  export const ListHandler = withConfig<ListHandlerOptions>(
26
26
  async ({ config, name }): Promise<void> => {
27
- const accountId = await requireAuth({});
27
+ const accountId = await requireAuth(config);
28
28
  logger.log(d1BetaWarning);
29
29
  const db: Database = await getDatabaseByNameOrBinding(
30
30
  config,
@@ -33,11 +33,13 @@ export const ListHandler = withConfig<ListHandlerOptions>(
33
33
  );
34
34
 
35
35
  const backups: Backup[] = await listBackups(accountId, db.uuid);
36
- render(
37
- <Table
38
- data={backups}
39
- columns={["created_at", "id", "num_tables", "size"]}
40
- ></Table>
36
+ logger.log(
37
+ renderToString(
38
+ <Table
39
+ data={backups}
40
+ columns={["created_at", "id", "num_tables", "size"]}
41
+ ></Table>
42
+ )
41
43
  );
42
44
  }
43
45
  );
@@ -85,7 +87,7 @@ type CreateHandlerOptions = StrictYargsOptionsToInterface<typeof CreateOptions>;
85
87
 
86
88
  export const CreateHandler = withConfig<CreateHandlerOptions>(
87
89
  async ({ config, name }): Promise<void> => {
88
- const accountId = await requireAuth({});
90
+ const accountId = await requireAuth(config);
89
91
  logger.log(d1BetaWarning);
90
92
  const db: Database = await getDatabaseByNameOrBinding(
91
93
  config,
@@ -94,11 +96,13 @@ export const CreateHandler = withConfig<CreateHandlerOptions>(
94
96
  );
95
97
 
96
98
  const backup: Backup = await createBackup(accountId, db.uuid);
97
- render(
98
- <Table
99
- data={[backup]}
100
- columns={["created_at", "id", "num_tables", "size", "state"]}
101
- ></Table>
99
+ logger.log(
100
+ renderToString(
101
+ <Table
102
+ data={[backup]}
103
+ columns={["created_at", "id", "num_tables", "size", "state"]}
104
+ ></Table>
105
+ )
102
106
  );
103
107
  }
104
108
  );
@@ -131,7 +135,7 @@ type RestoreHandlerOptions = StrictYargsOptionsToInterface<
131
135
  >;
132
136
  export const RestoreHandler = withConfig<RestoreHandlerOptions>(
133
137
  async ({ config, name, backupId }): Promise<void> => {
134
- const accountId = await requireAuth({});
138
+ const accountId = await requireAuth(config);
135
139
  logger.log(d1BetaWarning);
136
140
  const db: Database = await getDatabaseByNameOrBinding(
137
141
  config,
@@ -179,7 +183,7 @@ type DownloadHandlerOptions = StrictYargsOptionsToInterface<
179
183
  >;
180
184
  export const DownloadHandler = withConfig<DownloadHandlerOptions>(
181
185
  async ({ name, backupId, output, config }): Promise<void> => {
182
- const accountId = await requireAuth({});
186
+ const accountId = await requireAuth(config);
183
187
  logger.log(d1BetaWarning);
184
188
  const db: Database = await getDatabaseByNameOrBinding(
185
189
  config,