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
package/src/d1/create.tsx CHANGED
@@ -1,8 +1,10 @@
1
- import { render, Text, Box } from "ink";
1
+ import { Text, Box } from "ink";
2
2
  import React from "react";
3
3
  import { fetchResult } from "../cfetch";
4
+ import { withConfig } from "../config";
4
5
  import { logger } from "../logger";
5
6
  import { requireAuth } from "../user";
7
+ import { renderToString } from "../utils/render";
6
8
  import { d1BetaWarning } from "./utils";
7
9
  import type {
8
10
  CommonYargsArgv,
@@ -20,45 +22,49 @@ export function Options(yargs: CommonYargsArgv) {
20
22
  .epilogue(d1BetaWarning);
21
23
  }
22
24
 
23
- export async function Handler({
24
- name,
25
- }: StrictYargsOptionsToInterface<typeof Options>): Promise<void> {
26
- const accountId = await requireAuth({});
25
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
26
+ export const Handler = withConfig<HandlerOptions>(
27
+ async ({ name, config }): Promise<void> => {
28
+ const accountId = await requireAuth(config);
27
29
 
28
- logger.log(d1BetaWarning);
30
+ logger.log(d1BetaWarning);
29
31
 
30
- let db: Database;
31
- try {
32
- db = await fetchResult(`/accounts/${accountId}/d1/database`, {
33
- method: "POST",
34
- headers: {
35
- "Content-Type": "application/json",
36
- },
37
- body: JSON.stringify({
38
- name,
39
- }),
40
- });
41
- } catch (e) {
42
- if ((e as { code: number }).code === 7502) {
43
- throw new Error("A database with that name already exists");
32
+ let db: Database;
33
+ try {
34
+ db = await fetchResult(`/accounts/${accountId}/d1/database`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ },
39
+ body: JSON.stringify({
40
+ name,
41
+ }),
42
+ });
43
+ } catch (e) {
44
+ if ((e as { code: number }).code === 7502) {
45
+ throw new Error("A database with that name already exists");
46
+ }
47
+ throw e;
44
48
  }
45
- throw e;
46
- }
47
49
 
48
- render(
49
- <Box flexDirection="column">
50
- <Text>✅ Successfully created DB &apos;{db.name}&apos;!</Text>
51
- <Text>&nbsp;</Text>
52
- <Text>
53
- Add the following to your wrangler.toml to connect to it from a Worker:
54
- </Text>
55
- <Text>&nbsp;</Text>
56
- <Text>[[ d1_databases ]]</Text>
57
- <Text>
58
- binding = &quot;DB&quot; # i.e. available in your Worker on env.DB
59
- </Text>
60
- <Text>database_name = &quot;{db.name}&quot;</Text>
61
- <Text>database_id = &quot;{db.uuid}&quot;</Text>
62
- </Box>
63
- );
64
- }
50
+ logger.log(
51
+ renderToString(
52
+ <Box flexDirection="column">
53
+ <Text>✅ Successfully created DB &apos;{db.name}&apos;!</Text>
54
+ <Text>&nbsp;</Text>
55
+ <Text>
56
+ Add the following to your wrangler.toml to connect to it from a
57
+ Worker:
58
+ </Text>
59
+ <Text>&nbsp;</Text>
60
+ <Text>[[ d1_databases ]]</Text>
61
+ <Text>
62
+ binding = &quot;DB&quot; # i.e. available in your Worker on env.DB
63
+ </Text>
64
+ <Text>database_name = &quot;{db.name}&quot;</Text>
65
+ <Text>database_id = &quot;{db.uuid}&quot;</Text>
66
+ </Box>
67
+ )
68
+ );
69
+ }
70
+ );
package/src/d1/delete.ts CHANGED
@@ -24,7 +24,7 @@ export function Options(d1ListYargs: CommonYargsArgv) {
24
24
  type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
25
25
  export const Handler = withConfig<HandlerOptions>(
26
26
  async ({ name, skipConfirmation, config }): Promise<void> => {
27
- const accountId = await requireAuth({});
27
+ const accountId = await requireAuth(config);
28
28
  logger.log(d1BetaWarning);
29
29
 
30
30
  const db: Database = await getDatabaseByNameOrBinding(
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { mkdir } from "node:fs/promises";
3
3
  import path from "node:path";
4
4
  import chalk from "chalk";
5
- import { render, Static, Text } from "ink";
5
+ import { Static, Text } from "ink";
6
6
  import Table from "ink-table";
7
7
  import { npxImport } from "npx-import";
8
8
  import React from "react";
@@ -14,6 +14,7 @@ import { logger } from "../logger";
14
14
  import { readFileSync } from "../parse";
15
15
  import { readableRelative } from "../paths";
16
16
  import { requireAuth } from "../user";
17
+ import { renderToString } from "../utils/render";
17
18
  import * as options from "./options";
18
19
  import splitSqlQuery from "./splitter";
19
20
  import {
@@ -36,7 +37,7 @@ export type QueryResult = {
36
37
  };
37
38
  query?: string;
38
39
  };
39
- // Max number of bytes to send in a single /execute call
40
+ // Max number of statements to send in a single /execute call
40
41
  const QUERY_LIMIT = 10_000;
41
42
 
42
43
  export function Options(yargs: CommonYargsArgv) {
@@ -110,25 +111,27 @@ export const Handler = async (args: HandlerOptions): Promise<void> => {
110
111
 
111
112
  if (isInteractive && !json) {
112
113
  // Render table if single result
113
- render(
114
- <Static items={response}>
115
- {(result) => {
116
- // batch results
117
- if (!Array.isArray(result)) {
118
- const { results, query } = result;
114
+ logger.log(
115
+ renderToString(
116
+ <Static items={response}>
117
+ {(result) => {
118
+ // batch results
119
+ if (!Array.isArray(result)) {
120
+ const { results, query } = result;
119
121
 
120
- if (Array.isArray(results) && results.length > 0) {
121
- const shortQuery = shorten(query, 48);
122
- return (
123
- <>
124
- {shortQuery ? <Text dimColor>{shortQuery}</Text> : null}
125
- <Table data={results}></Table>
126
- </>
127
- );
122
+ if (Array.isArray(results) && results.length > 0) {
123
+ const shortQuery = shorten(query, 48);
124
+ return (
125
+ <>
126
+ {shortQuery ? <Text dimColor>{shortQuery}</Text> : null}
127
+ <Table data={results}></Table>
128
+ </>
129
+ );
130
+ }
128
131
  }
129
- }
130
- }}
131
- </Static>
132
+ }}
133
+ </Static>
134
+ )
132
135
  );
133
136
  } else {
134
137
  // set loggerLevel back to what it was before to actually output the JSON in stdout
@@ -278,7 +281,7 @@ async function executeRemotely({
278
281
  }
279
282
  }
280
283
 
281
- const accountId = await requireAuth({});
284
+ const accountId = await requireAuth(config);
282
285
  const db: Database = await getDatabaseByNameOrBinding(
283
286
  config,
284
287
  accountId,
package/src/d1/list.tsx CHANGED
@@ -1,9 +1,10 @@
1
- import { render } from "ink";
2
1
  import Table from "ink-table";
3
2
  import React from "react";
4
3
  import { fetchResult } from "../cfetch";
4
+ import { withConfig } from "../config";
5
5
  import { logger } from "../logger";
6
6
  import { requireAuth } from "../user";
7
+ import { renderToString } from "../utils/render";
7
8
  import { d1BetaWarning } from "./utils";
8
9
  import type {
9
10
  CommonYargsArgv,
@@ -21,19 +22,20 @@ export function Options(d1ListYargs: CommonYargsArgv) {
21
22
  .epilogue(d1BetaWarning);
22
23
  }
23
24
 
24
- export async function Handler({
25
- json,
26
- }: StrictYargsOptionsToInterface<typeof Options>): Promise<void> {
27
- const accountId = await requireAuth({});
28
- const dbs: Array<Database> = await listDatabases(accountId);
25
+ type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
26
+ export const Handler = withConfig<HandlerOptions>(
27
+ async ({ json, config }): Promise<void> => {
28
+ const accountId = await requireAuth(config);
29
+ const dbs: Array<Database> = await listDatabases(accountId);
29
30
 
30
- if (json) {
31
- logger.log(JSON.stringify(dbs, null, 2));
32
- } else {
33
- logger.log(d1BetaWarning);
34
- render(<Table data={dbs}></Table>);
31
+ if (json) {
32
+ logger.log(JSON.stringify(dbs, null, 2));
33
+ } else {
34
+ logger.log(d1BetaWarning);
35
+ logger.log(renderToString(<Table data={dbs}></Table>));
36
+ }
35
37
  }
36
- }
38
+ );
37
39
 
38
40
  export const listDatabases = async (
39
41
  accountId: string
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert";
2
2
  import fs from "node:fs";
3
3
  import path from "path";
4
- import { Box, render, Text } from "ink";
4
+ import { Box, Text } from "ink";
5
5
  import Table from "ink-table";
6
6
  import React from "react";
7
7
  import { withConfig } from "../../config";
@@ -10,6 +10,7 @@ import { CI } from "../../is-ci";
10
10
  import isInteractive from "../../is-interactive";
11
11
  import { logger } from "../../logger";
12
12
  import { requireAuth } from "../../user";
13
+ import { renderToString } from "../../utils/render";
13
14
  import { createBackup } from "../backups";
14
15
  import { DEFAULT_MIGRATION_PATH, DEFAULT_MIGRATION_TABLE } from "../constants";
15
16
  import { executeSql } from "../execute";
@@ -97,14 +98,16 @@ export const ApplyHandler = withConfig<ApplyHandlerOptions>(
97
98
  });
98
99
 
99
100
  if (unappliedMigrations.length === 0) {
100
- render(<Text>✅ No migrations to apply!</Text>);
101
+ logger.log(renderToString(<Text>✅ No migrations to apply!</Text>));
101
102
  return;
102
103
  }
103
- render(
104
- <Box flexDirection="column">
105
- <Text>Migrations to be applied:</Text>
106
- <Table data={unappliedMigrations} columns={["Name"]}></Table>
107
- </Box>
104
+ logger.log(
105
+ renderToString(
106
+ <Box flexDirection="column">
107
+ <Text>Migrations to be applied:</Text>
108
+ <Table data={unappliedMigrations} columns={["Name"]}></Table>
109
+ </Box>
110
+ )
108
111
  );
109
112
  const ok = await confirm(
110
113
  `About to apply ${unappliedMigrations.length} migration(s)
@@ -118,8 +121,8 @@ Your database may not be available to serve requests during the migration, conti
118
121
  databaseInfo,
119
122
  "In non-local mode `databaseInfo` should be defined."
120
123
  );
121
- render(<Text>🕒 Creating backup...</Text>);
122
- const accountId = await requireAuth({});
124
+ logger.log(renderToString(<Text>🕒 Creating backup...</Text>));
125
+ const accountId = await requireAuth(config);
123
126
  await createBackup(accountId, databaseInfo.uuid);
124
127
  }
125
128
 
@@ -169,35 +172,38 @@ Your database may not be available to serve requests during the migration, conti
169
172
  }
170
173
  } catch (e) {
171
174
  const err = e as ParseError;
175
+ const maybeCause = (err.cause ?? err) as Error;
172
176
 
173
177
  success = false;
174
178
  errorNotes = err.notes?.map((msg) => msg.text) ?? [
175
- err.message ?? err.toString(),
179
+ maybeCause?.message ?? maybeCause.toString(),
176
180
  ];
177
181
  }
178
182
 
179
183
  migration.Status = success ? "✅" : "❌";
180
184
 
181
- render(
182
- <Box flexDirection="column">
183
- <Table
184
- data={unappliedMigrations}
185
- columns={["Name", "Status"]}
186
- ></Table>
187
- {errorNotes.length > 0 && (
188
- <Box flexDirection="column">
189
- <Text>&nbsp;</Text>
190
- <Text>
191
- ❌ Migration {migration.Name} failed with following Errors
192
- </Text>
193
- <Table
194
- data={errorNotes.map((err) => {
195
- return { Error: err };
196
- })}
197
- ></Table>
198
- </Box>
199
- )}
200
- </Box>
185
+ logger.log(
186
+ renderToString(
187
+ <Box flexDirection="column">
188
+ <Table
189
+ data={unappliedMigrations}
190
+ columns={["Name", "Status"]}
191
+ ></Table>
192
+ {errorNotes.length > 0 && (
193
+ <Box flexDirection="column">
194
+ <Text>&nbsp;</Text>
195
+ <Text>
196
+ ❌ Migration {migration.Name} failed with following Errors
197
+ </Text>
198
+ <Table
199
+ data={errorNotes.map((err) => {
200
+ return { Error: err };
201
+ })}
202
+ ></Table>
203
+ </Box>
204
+ )}
205
+ </Box>
206
+ )
201
207
  );
202
208
 
203
209
  if (errorNotes.length > 0) return;
@@ -1,9 +1,10 @@
1
1
  import fs from "node:fs";
2
2
  import path from "path";
3
- import { Box, render, Text } from "ink";
3
+ import { Box, Text } from "ink";
4
4
  import React from "react";
5
5
  import { withConfig } from "../../config";
6
6
  import { logger } from "../../logger";
7
+ import { renderToString } from "../../utils/render";
7
8
  import { DEFAULT_MIGRATION_PATH } from "../constants";
8
9
  import { Database } from "../options";
9
10
  import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
@@ -54,17 +55,19 @@ export const CreateHandler = withConfig<CreateHandlerOptions>(
54
55
  `-- Migration number: ${nextMigrationNumber} \t ${new Date().toISOString()}\n`
55
56
  );
56
57
 
57
- render(
58
- <Box flexDirection="column">
59
- <Text>
60
- ✅ Successfully created Migration &apos;{newMigrationName}&apos;!
61
- </Text>
62
- <Text>&nbsp;</Text>
63
- <Text>The migration is available for editing here</Text>
64
- <Text>
65
- {migrationsPath}/{newMigrationName}
66
- </Text>
67
- </Box>
58
+ logger.log(
59
+ renderToString(
60
+ <Box flexDirection="column">
61
+ <Text>
62
+ ✅ Successfully created Migration &apos;{newMigrationName}&apos;!
63
+ </Text>
64
+ <Text>&nbsp;</Text>
65
+ <Text>The migration is available for editing here</Text>
66
+ <Text>
67
+ {migrationsPath}/{newMigrationName}
68
+ </Text>
69
+ </Box>
70
+ )
68
71
  );
69
72
  }
70
73
  );
@@ -157,14 +157,11 @@ export const initMigrationsTable = async ({
157
157
  name,
158
158
  shouldPrompt: isInteractive() && !CI.isCI(),
159
159
  persistTo,
160
- command: `
161
- CREATE TABLE IF NOT EXISTS ${migrationsTableName}
162
- (
163
- id INTEGER PRIMARY KEY AUTOINCREMENT,
164
- name TEXT UNIQUE,
165
- applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
166
- );
167
- `,
160
+ command: `CREATE TABLE IF NOT EXISTS ${migrationsTableName}(
161
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
162
+ name TEXT UNIQUE,
163
+ applied_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
164
+ );`,
168
165
  file: undefined,
169
166
  json: undefined,
170
167
  preview,
@@ -1,10 +1,11 @@
1
1
  import path from "path";
2
- import { Box, render, Text } from "ink";
2
+ import { Box, Text } from "ink";
3
3
  import Table from "ink-table";
4
4
  import React from "react";
5
5
  import { withConfig } from "../../config";
6
6
  import { logger } from "../../logger";
7
7
  import { requireAuth } from "../../user";
8
+ import { renderToString } from "../../utils/render";
8
9
  import { DEFAULT_MIGRATION_PATH, DEFAULT_MIGRATION_TABLE } from "../constants";
9
10
  import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
10
11
  import {
@@ -78,15 +79,17 @@ export const ListHandler = withConfig<ListHandlerOptions>(
78
79
  });
79
80
 
80
81
  if (unappliedMigrations.length === 0) {
81
- render(<Text>✅ No migrations to apply!</Text>);
82
+ logger.log(renderToString(<Text>✅ No migrations to apply!</Text>));
82
83
  return;
83
84
  }
84
85
 
85
- render(
86
- <Box flexDirection="column">
87
- <Text>Migrations to be applied:</Text>
88
- <Table data={unappliedMigrations} columns={["Name"]}></Table>
89
- </Box>
86
+ logger.log(
87
+ renderToString(
88
+ <Box flexDirection="column">
89
+ <Text>Migrations to be applied:</Text>
90
+ <Table data={unappliedMigrations} columns={["Name"]}></Table>
91
+ </Box>
92
+ )
90
93
  );
91
94
  }
92
95
  );