wrangler 2.8.1 → 2.9.1
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.
- package/miniflare-dist/index.mjs +1 -14
- package/package.json +2 -2
- package/src/__tests__/d1/d1.test.ts +11 -56
- package/src/__tests__/d1/migrate.test.ts +141 -0
- package/src/__tests__/dev.test.tsx +5 -4
- package/src/__tests__/generate.test.ts +1 -1
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/index.test.ts +36 -32
- package/src/__tests__/init.test.ts +1 -1
- package/src/__tests__/kv.test.ts +55 -44
- package/src/__tests__/pages/deployment-list.test.ts +78 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +108 -0
- package/src/__tests__/pages/project-upload.test.ts +481 -0
- package/src/__tests__/pages/publish.test.ts +2221 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/pubsub.test.ts +15 -12
- package/src/__tests__/queues.test.ts +35 -28
- package/src/__tests__/r2.test.ts +25 -20
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/worker-namespace.test.ts +26 -21
- package/src/api/dev.ts +80 -11
- package/src/api/pages/publish.tsx +7 -4
- package/src/bundle.ts +1 -1
- package/src/config/config.ts +7 -0
- package/src/config/index.ts +24 -20
- package/src/d1/backups.tsx +20 -24
- package/src/d1/create.tsx +6 -5
- package/src/d1/delete.ts +7 -10
- package/src/d1/execute.tsx +83 -85
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +21 -9
- package/src/d1/migrations/apply.tsx +13 -9
- package/src/d1/migrations/create.tsx +9 -10
- package/src/d1/migrations/list.tsx +19 -9
- package/src/d1/migrations/options.ts +2 -2
- package/src/d1/options.ts +3 -3
- package/src/delete.ts +5 -8
- package/src/deprecated/index.ts +7 -8
- package/src/dev.tsx +42 -80
- package/src/dispatch-namespace.ts +20 -16
- package/src/docs/index.ts +7 -8
- package/src/generate/index.ts +5 -7
- package/src/index.ts +22 -21
- package/src/init.ts +5 -7
- package/src/kv/index.ts +15 -17
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/pages/build.ts +6 -4
- package/src/pages/deployment-tails.ts +7 -10
- package/src/pages/deployments.tsx +6 -4
- package/src/pages/dev.ts +15 -17
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/functions.ts +8 -4
- package/src/pages/index.ts +3 -3
- package/src/pages/projects.tsx +7 -12
- package/src/pages/publish.tsx +6 -4
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +6 -4
- package/src/parse.ts +23 -1
- package/src/publish/index.ts +19 -15
- package/src/publish/publish.ts +2 -2
- package/src/pubsub/pubsub-commands.ts +18 -19
- package/src/queues/cli/commands/consumer/add.ts +18 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +9 -14
- package/src/tail/index.ts +6 -8
- package/src/yargs-types.ts +18 -5
- package/templates/checked-fetch.js +9 -1
- package/templates/tsconfig.init.json +1 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.js +2180 -1799
- package/src/__tests__/pages.test.ts +0 -2898
package/src/d1/execute.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Table from "ink-table";
|
|
|
7
7
|
import { npxImport } from "npx-import";
|
|
8
8
|
import React from "react";
|
|
9
9
|
import { fetchResult } from "../cfetch";
|
|
10
|
-
import {
|
|
10
|
+
import { readConfig } from "../config";
|
|
11
11
|
import { getLocalPersistencePath } from "../dev/get-local-persistence-path";
|
|
12
12
|
import { confirm } from "../dialogs";
|
|
13
13
|
import { logger } from "../logger";
|
|
@@ -22,10 +22,13 @@ import {
|
|
|
22
22
|
getDatabaseInfoFromConfig,
|
|
23
23
|
} from "./utils";
|
|
24
24
|
import type { Config, ConfigFields, DevConfig, Environment } from "../config";
|
|
25
|
+
import type {
|
|
26
|
+
CommonYargsArgv,
|
|
27
|
+
StrictYargsOptionsToInterface,
|
|
28
|
+
} from "../yargs-types";
|
|
25
29
|
import type { Database } from "./types";
|
|
26
30
|
import type { Statement as StatementType } from "@miniflare/d1";
|
|
27
31
|
import type { createSQLiteDB as createSQLiteDBType } from "@miniflare/shared";
|
|
28
|
-
import type { Argv } from "yargs";
|
|
29
32
|
|
|
30
33
|
type MiniflareNpxImportTypes = [
|
|
31
34
|
{
|
|
@@ -36,19 +39,6 @@ type MiniflareNpxImportTypes = [
|
|
|
36
39
|
}
|
|
37
40
|
];
|
|
38
41
|
|
|
39
|
-
export type BaseSqlExecuteArgs = {
|
|
40
|
-
config?: string;
|
|
41
|
-
database: string;
|
|
42
|
-
local?: boolean;
|
|
43
|
-
"persist-to"?: string;
|
|
44
|
-
yes?: boolean;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type ExecuteArgs = BaseSqlExecuteArgs & {
|
|
48
|
-
file?: string;
|
|
49
|
-
command?: string;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
42
|
export type QueryResult = {
|
|
53
43
|
results: Record<string, string | number | boolean>[];
|
|
54
44
|
success: boolean;
|
|
@@ -60,7 +50,7 @@ export type QueryResult = {
|
|
|
60
50
|
// Max number of bytes to send in a single /execute call
|
|
61
51
|
const QUERY_LIMIT = 10_000;
|
|
62
52
|
|
|
63
|
-
export function Options(yargs:
|
|
53
|
+
export function Options(yargs: CommonYargsArgv) {
|
|
64
54
|
return options
|
|
65
55
|
.Database(yargs)
|
|
66
56
|
.option("yes", {
|
|
@@ -74,7 +64,7 @@ export function Options(yargs: Argv): Argv<ExecuteArgs> {
|
|
|
74
64
|
type: "boolean",
|
|
75
65
|
})
|
|
76
66
|
.option("file", {
|
|
77
|
-
describe: "A .sql file to
|
|
67
|
+
describe: "A .sql file to ingest",
|
|
78
68
|
type: "string",
|
|
79
69
|
})
|
|
80
70
|
.option("command", {
|
|
@@ -85,6 +75,11 @@ export function Options(yargs: Argv): Argv<ExecuteArgs> {
|
|
|
85
75
|
describe: "Specify directory to use for local persistence (for --local)",
|
|
86
76
|
type: "string",
|
|
87
77
|
requiresArg: true,
|
|
78
|
+
})
|
|
79
|
+
.option("json", {
|
|
80
|
+
describe: "Return output as clean JSON",
|
|
81
|
+
type: "boolean",
|
|
82
|
+
default: false,
|
|
88
83
|
});
|
|
89
84
|
}
|
|
90
85
|
|
|
@@ -101,14 +96,13 @@ export async function executeSql(
|
|
|
101
96
|
shouldPrompt: boolean | undefined,
|
|
102
97
|
persistTo: undefined | string,
|
|
103
98
|
file?: string,
|
|
104
|
-
command?: string
|
|
99
|
+
command?: string,
|
|
100
|
+
json?: boolean
|
|
105
101
|
) {
|
|
106
102
|
const sql = file ? readFileSync(file) : command;
|
|
107
|
-
|
|
108
103
|
if (!sql) throw new Error(`Error: must provide --command or --file.`);
|
|
109
104
|
if (persistTo && !local)
|
|
110
105
|
throw new Error(`Error: can't use --persist-to without --local`);
|
|
111
|
-
|
|
112
106
|
logger.log(`🌀 Mapping SQL input into an array of statements`);
|
|
113
107
|
const queries = splitSqlQuery(sql);
|
|
114
108
|
|
|
@@ -122,72 +116,80 @@ export async function executeSql(
|
|
|
122
116
|
}
|
|
123
117
|
|
|
124
118
|
return local
|
|
125
|
-
? await executeLocally(config, name, shouldPrompt, queries, persistTo)
|
|
126
|
-
: await executeRemotely(
|
|
119
|
+
? await executeLocally(config, name, shouldPrompt, queries, persistTo, json)
|
|
120
|
+
: await executeRemotely(
|
|
121
|
+
config,
|
|
122
|
+
name,
|
|
123
|
+
shouldPrompt,
|
|
124
|
+
batchSplit(queries),
|
|
125
|
+
json
|
|
126
|
+
);
|
|
127
127
|
}
|
|
128
|
+
type HandlerOptions = StrictYargsOptionsToInterface<typeof Options>;
|
|
129
|
+
|
|
130
|
+
export const Handler = async (args: HandlerOptions): Promise<void> => {
|
|
131
|
+
const { local, database, yes, persistTo, file, command, json } = args;
|
|
132
|
+
const existingLogLevel = logger.loggerLevel;
|
|
133
|
+
if (json) {
|
|
134
|
+
// set loggerLevel to error to avoid readConfig warnings appearing in JSON output
|
|
135
|
+
logger.loggerLevel = "error";
|
|
136
|
+
}
|
|
137
|
+
const config = readConfig(args.config, args);
|
|
138
|
+
logger.log(d1BetaWarning);
|
|
139
|
+
if (file && command)
|
|
140
|
+
return logger.error(`Error: can't provide both --command and --file.`);
|
|
128
141
|
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
const isInteractive = process.stdout.isTTY;
|
|
143
|
+
const response: QueryResult[] | null = await executeSql(
|
|
144
|
+
local,
|
|
131
145
|
config,
|
|
132
146
|
database,
|
|
147
|
+
isInteractive && !yes,
|
|
148
|
+
persistTo,
|
|
133
149
|
file,
|
|
134
150
|
command,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
yes,
|
|
138
|
-
}): Promise<void> => {
|
|
139
|
-
logger.log(d1BetaWarning);
|
|
140
|
-
if (file && command)
|
|
141
|
-
return logger.error(`Error: can't provide both --command and --file.`);
|
|
142
|
-
|
|
143
|
-
const isInteractive = process.stdout.isTTY;
|
|
144
|
-
const response: QueryResult[] | null = await executeSql(
|
|
145
|
-
local,
|
|
146
|
-
config,
|
|
147
|
-
database,
|
|
148
|
-
isInteractive && !yes,
|
|
149
|
-
persistTo,
|
|
150
|
-
file,
|
|
151
|
-
command
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// Early exit if prompt rejected
|
|
155
|
-
if (!response) return;
|
|
156
|
-
|
|
157
|
-
if (isInteractive) {
|
|
158
|
-
// Render table if single result
|
|
159
|
-
render(
|
|
160
|
-
<Static items={response}>
|
|
161
|
-
{(result) => {
|
|
162
|
-
// batch results
|
|
163
|
-
if (!Array.isArray(result)) {
|
|
164
|
-
const { results, query } = result;
|
|
151
|
+
json
|
|
152
|
+
);
|
|
165
153
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
154
|
+
// Early exit if prompt rejected
|
|
155
|
+
if (!response) return;
|
|
156
|
+
|
|
157
|
+
if (isInteractive && !json) {
|
|
158
|
+
// Render table if single result
|
|
159
|
+
render(
|
|
160
|
+
<Static items={response}>
|
|
161
|
+
{(result) => {
|
|
162
|
+
// batch results
|
|
163
|
+
if (!Array.isArray(result)) {
|
|
164
|
+
const { results, query } = result;
|
|
165
|
+
|
|
166
|
+
if (Array.isArray(results) && results.length > 0) {
|
|
167
|
+
const shortQuery = shorten(query, 48);
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
{shortQuery ? <Text dimColor>{shortQuery}</Text> : null}
|
|
171
|
+
<Table data={results}></Table>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
175
174
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
}
|
|
176
|
+
}}
|
|
177
|
+
</Static>
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
// set loggerLevel back to what it was before to actually output the JSON in stdout
|
|
181
|
+
logger.loggerLevel = existingLogLevel;
|
|
182
|
+
logger.log(JSON.stringify(response, null, 2));
|
|
182
183
|
}
|
|
183
|
-
|
|
184
|
+
};
|
|
184
185
|
|
|
185
186
|
async function executeLocally(
|
|
186
187
|
config: Config,
|
|
187
188
|
name: string,
|
|
188
189
|
shouldPrompt: boolean | undefined,
|
|
189
190
|
queries: string[],
|
|
190
|
-
persistTo: string | undefined
|
|
191
|
+
persistTo: string | undefined,
|
|
192
|
+
json?: boolean
|
|
191
193
|
) {
|
|
192
194
|
const localDB = getDatabaseInfoFromConfig(config, name);
|
|
193
195
|
if (!localDB) {
|
|
@@ -210,10 +212,11 @@ async function executeLocally(
|
|
|
210
212
|
logger.log
|
|
211
213
|
);
|
|
212
214
|
|
|
213
|
-
if (!existsSync(dbDir)
|
|
214
|
-
const ok =
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
if (!existsSync(dbDir)) {
|
|
216
|
+
const ok =
|
|
217
|
+
json ||
|
|
218
|
+
!shouldPrompt ||
|
|
219
|
+
(await confirm(`About to create ${readableRelative(dbPath)}, ok?`));
|
|
217
220
|
if (!ok) return null;
|
|
218
221
|
await mkdir(dbDir, { recursive: true });
|
|
219
222
|
}
|
|
@@ -234,10 +237,12 @@ async function executeRemotely(
|
|
|
234
237
|
config: Config,
|
|
235
238
|
name: string,
|
|
236
239
|
shouldPrompt: boolean | undefined,
|
|
237
|
-
batches: string[]
|
|
240
|
+
batches: string[],
|
|
241
|
+
json?: boolean
|
|
238
242
|
) {
|
|
239
243
|
const multiple_batches = batches.length > 1;
|
|
240
|
-
|
|
244
|
+
// in JSON mode, we don't want a prompt here
|
|
245
|
+
if (multiple_batches && !json) {
|
|
241
246
|
const warning = `⚠️ Too much SQL to send at once, this execution will be sent as ${batches.length} batches.`;
|
|
242
247
|
|
|
243
248
|
if (shouldPrompt) {
|
|
@@ -258,14 +263,7 @@ async function executeRemotely(
|
|
|
258
263
|
name
|
|
259
264
|
);
|
|
260
265
|
|
|
261
|
-
|
|
262
|
-
logger.log(`🌀 Executing on ${name} (${db.uuid}):`);
|
|
263
|
-
|
|
264
|
-
// Don't output if shouldPrompt is undefined
|
|
265
|
-
} else if (shouldPrompt !== undefined) {
|
|
266
|
-
// Pipe to error so we don't break jq
|
|
267
|
-
logger.error(`Executing on ${name} (${db.uuid}):`);
|
|
268
|
-
}
|
|
266
|
+
logger.log(`🌀 Executing on ${name} (${db.uuid}):`);
|
|
269
267
|
|
|
270
268
|
const results: QueryResult[] = [];
|
|
271
269
|
for (const sql of batches) {
|
package/src/d1/index.ts
CHANGED
|
@@ -5,10 +5,9 @@ import * as Execute from "./execute";
|
|
|
5
5
|
import * as List from "./list";
|
|
6
6
|
import * as Migrations from "./migrations";
|
|
7
7
|
import { d1BetaWarning } from "./utils";
|
|
8
|
-
import type {
|
|
9
|
-
import type { Argv } from "yargs";
|
|
8
|
+
import type { CommonYargsArgv } from "../yargs-types";
|
|
10
9
|
|
|
11
|
-
export
|
|
10
|
+
export function d1(yargs: CommonYargsArgv) {
|
|
12
11
|
return (
|
|
13
12
|
yargs
|
|
14
13
|
.command("list", "List D1 databases", List.Options, List.Handler)
|
|
@@ -24,8 +23,8 @@ export const d1 = (yargs: Argv<CommonYargsOptions>) => {
|
|
|
24
23
|
Delete.Options,
|
|
25
24
|
Delete.Handler
|
|
26
25
|
)
|
|
27
|
-
.command("backup", "Interact with D1 Backups", (
|
|
28
|
-
|
|
26
|
+
.command("backup", "Interact with D1 Backups", (backupArgs) =>
|
|
27
|
+
backupArgs
|
|
29
28
|
.demandCommand()
|
|
30
29
|
.command(
|
|
31
30
|
"list <name>",
|
|
@@ -98,4 +97,4 @@ export const d1 = (yargs: Argv<CommonYargsOptions>) => {
|
|
|
98
97
|
)
|
|
99
98
|
.epilogue(d1BetaWarning)
|
|
100
99
|
);
|
|
101
|
-
}
|
|
100
|
+
}
|
package/src/d1/list.tsx
CHANGED
|
@@ -5,22 +5,34 @@ import { fetchResult } from "../cfetch";
|
|
|
5
5
|
import { logger } from "../logger";
|
|
6
6
|
import { requireAuth } from "../user";
|
|
7
7
|
import { d1BetaWarning } from "./utils";
|
|
8
|
+
import type {
|
|
9
|
+
CommonYargsArgv,
|
|
10
|
+
StrictYargsOptionsToInterface,
|
|
11
|
+
} from "../yargs-types";
|
|
8
12
|
import type { Database } from "./types";
|
|
9
|
-
import type { ArgumentsCamelCase, Argv } from "yargs";
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
export function Options(d1ListYargs: CommonYargsArgv) {
|
|
15
|
+
return d1ListYargs
|
|
16
|
+
.option("json", {
|
|
17
|
+
describe: "return output as clean JSON",
|
|
18
|
+
type: "boolean",
|
|
19
|
+
default: false,
|
|
20
|
+
})
|
|
21
|
+
.epilogue(d1BetaWarning);
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
export async function Handler(
|
|
24
|
+
export async function Handler({
|
|
25
|
+
json,
|
|
26
|
+
}: StrictYargsOptionsToInterface<typeof Options>): Promise<void> {
|
|
18
27
|
const accountId = await requireAuth({});
|
|
19
|
-
logger.log(d1BetaWarning);
|
|
20
|
-
|
|
21
28
|
const dbs: Array<Database> = await listDatabases(accountId);
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
if (json) {
|
|
31
|
+
logger.log(JSON.stringify(dbs, null, 2));
|
|
32
|
+
} else {
|
|
33
|
+
logger.log(d1BetaWarning);
|
|
34
|
+
render(<Table data={dbs}></Table>);
|
|
35
|
+
}
|
|
24
36
|
}
|
|
25
37
|
|
|
26
38
|
export const listDatabases = async (
|
|
@@ -21,18 +21,22 @@ import {
|
|
|
21
21
|
} from "./helpers";
|
|
22
22
|
import { DatabaseWithLocal } from "./options";
|
|
23
23
|
import type { ParseError } from "../../parse";
|
|
24
|
-
import type {
|
|
25
|
-
|
|
24
|
+
import type {
|
|
25
|
+
CommonYargsArgv,
|
|
26
|
+
StrictYargsOptionsToInterface,
|
|
27
|
+
} from "../../yargs-types";
|
|
26
28
|
|
|
27
|
-
export function ApplyOptions(yargs:
|
|
29
|
+
export function ApplyOptions(yargs: CommonYargsArgv) {
|
|
28
30
|
return DatabaseWithLocal(yargs);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
type ApplyHandlerOptions = StrictYargsOptionsToInterface<typeof ApplyOptions>;
|
|
34
|
+
|
|
35
|
+
export const ApplyHandler = withConfig<ApplyHandlerOptions>(
|
|
32
36
|
async ({ config, database, local, persistTo }): Promise<void> => {
|
|
33
37
|
logger.log(d1BetaWarning);
|
|
34
38
|
|
|
35
|
-
const databaseInfo =
|
|
39
|
+
const databaseInfo = getDatabaseInfoFromConfig(config, database);
|
|
36
40
|
if (!databaseInfo && !local) {
|
|
37
41
|
throw new Error(
|
|
38
42
|
`Can't find a DB with name/binding '${database}' in local config. Check info in wrangler.toml...`
|
|
@@ -49,10 +53,10 @@ export const ApplyHandler = withConfig<BaseSqlExecuteArgs>(
|
|
|
49
53
|
false
|
|
50
54
|
);
|
|
51
55
|
|
|
52
|
-
const
|
|
56
|
+
const migrationsTableName =
|
|
53
57
|
databaseInfo?.migrationsTableName ?? DEFAULT_MIGRATION_TABLE;
|
|
54
58
|
await initMigrationsTable(
|
|
55
|
-
|
|
59
|
+
migrationsTableName,
|
|
56
60
|
local,
|
|
57
61
|
config,
|
|
58
62
|
database,
|
|
@@ -61,7 +65,7 @@ export const ApplyHandler = withConfig<BaseSqlExecuteArgs>(
|
|
|
61
65
|
|
|
62
66
|
const unappliedMigrations = (
|
|
63
67
|
await getUnappliedMigrations(
|
|
64
|
-
|
|
68
|
+
migrationsTableName,
|
|
65
69
|
migrationsPath,
|
|
66
70
|
local,
|
|
67
71
|
config,
|
|
@@ -122,7 +126,7 @@ Your database may not be available to serve requests during the migration, conti
|
|
|
122
126
|
"utf8"
|
|
123
127
|
);
|
|
124
128
|
query += `
|
|
125
|
-
INSERT INTO ${
|
|
129
|
+
INSERT INTO ${migrationsTableName} (name)
|
|
126
130
|
values ('${migration.Name}');
|
|
127
131
|
`;
|
|
128
132
|
|
|
@@ -8,15 +8,12 @@ import { requireAuth } from "../../user";
|
|
|
8
8
|
import { Database } from "../options";
|
|
9
9
|
import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
|
|
10
10
|
import { getMigrationsPath, getNextMigrationNumber } from "./helpers";
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
CommonYargsArgv,
|
|
13
|
+
StrictYargsOptionsToInterface,
|
|
14
|
+
} from "../../yargs-types";
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
config?: string;
|
|
15
|
-
database: string;
|
|
16
|
-
message: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function CreateOptions(yargs: Argv): Argv<MigrationsCreateArgs> {
|
|
16
|
+
export function CreateOptions(yargs: CommonYargsArgv) {
|
|
20
17
|
return Database(yargs).positional("message", {
|
|
21
18
|
describe: "The Migration message",
|
|
22
19
|
type: "string",
|
|
@@ -24,12 +21,14 @@ export function CreateOptions(yargs: Argv): Argv<MigrationsCreateArgs> {
|
|
|
24
21
|
});
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
type CreateHandlerOptions = StrictYargsOptionsToInterface<typeof CreateOptions>;
|
|
25
|
+
|
|
26
|
+
export const CreateHandler = withConfig<CreateHandlerOptions>(
|
|
28
27
|
async ({ config, database, message }): Promise<void> => {
|
|
29
28
|
await requireAuth({});
|
|
30
29
|
logger.log(d1BetaWarning);
|
|
31
30
|
|
|
32
|
-
const databaseInfo =
|
|
31
|
+
const databaseInfo = getDatabaseInfoFromConfig(config, database);
|
|
33
32
|
if (!databaseInfo) {
|
|
34
33
|
throw new Error(
|
|
35
34
|
`Can't find a DB with name/binding '${database}' in local config. Check info in wrangler.toml...`
|
|
@@ -5,6 +5,7 @@ import React from "react";
|
|
|
5
5
|
import { withConfig } from "../../config";
|
|
6
6
|
import { logger } from "../../logger";
|
|
7
7
|
import { requireAuth } from "../../user";
|
|
8
|
+
import { DEFAULT_MIGRATION_PATH, DEFAULT_MIGRATION_TABLE } from "../constants";
|
|
8
9
|
import { d1BetaWarning, getDatabaseInfoFromConfig } from "../utils";
|
|
9
10
|
import {
|
|
10
11
|
getMigrationsPath,
|
|
@@ -12,20 +13,26 @@ import {
|
|
|
12
13
|
initMigrationsTable,
|
|
13
14
|
} from "./helpers";
|
|
14
15
|
import { DatabaseWithLocal } from "./options";
|
|
15
|
-
import type {
|
|
16
|
-
|
|
16
|
+
import type {
|
|
17
|
+
CommonYargsArgv,
|
|
18
|
+
StrictYargsOptionsToInterface,
|
|
19
|
+
} from "../../yargs-types";
|
|
17
20
|
|
|
18
|
-
export function ListOptions(yargs:
|
|
21
|
+
export function ListOptions(yargs: CommonYargsArgv) {
|
|
19
22
|
return DatabaseWithLocal(yargs);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
type ListHandlerOptions = StrictYargsOptionsToInterface<typeof ListOptions>;
|
|
26
|
+
|
|
27
|
+
export const ListHandler = withConfig<ListHandlerOptions>(
|
|
23
28
|
async ({ config, database, local, persistTo }): Promise<void> => {
|
|
24
|
-
|
|
29
|
+
if (!local) {
|
|
30
|
+
await requireAuth({});
|
|
31
|
+
}
|
|
25
32
|
logger.log(d1BetaWarning);
|
|
26
33
|
|
|
27
|
-
const databaseInfo =
|
|
28
|
-
if (!databaseInfo) {
|
|
34
|
+
const databaseInfo = getDatabaseInfoFromConfig(config, database);
|
|
35
|
+
if (!databaseInfo && !local) {
|
|
29
36
|
throw new Error(
|
|
30
37
|
`Can't find a DB with name/binding '${database}' in local config. Check info in wrangler.toml...`
|
|
31
38
|
);
|
|
@@ -34,13 +41,16 @@ export const ListHandler = withConfig<BaseSqlExecuteArgs>(
|
|
|
34
41
|
if (!config.configPath) {
|
|
35
42
|
return;
|
|
36
43
|
}
|
|
37
|
-
const { migrationsTableName, migrationsFolderPath } = databaseInfo;
|
|
38
44
|
|
|
39
45
|
const migrationsPath = await getMigrationsPath(
|
|
40
46
|
path.dirname(config.configPath),
|
|
41
|
-
migrationsFolderPath,
|
|
47
|
+
databaseInfo?.migrationsFolderPath ?? DEFAULT_MIGRATION_PATH,
|
|
42
48
|
false
|
|
43
49
|
);
|
|
50
|
+
|
|
51
|
+
const migrationsTableName =
|
|
52
|
+
databaseInfo?.migrationsTableName ?? DEFAULT_MIGRATION_TABLE;
|
|
53
|
+
|
|
44
54
|
await initMigrationsTable(
|
|
45
55
|
migrationsTableName,
|
|
46
56
|
local,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Database } from "../options";
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommonYargsArgv } from "../../yargs-types";
|
|
3
3
|
|
|
4
|
-
export function DatabaseWithLocal(yargs:
|
|
4
|
+
export function DatabaseWithLocal(yargs: CommonYargsArgv) {
|
|
5
5
|
return Database(yargs)
|
|
6
6
|
.option("local", {
|
|
7
7
|
describe:
|
package/src/d1/options.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d1BetaWarning } from "./utils";
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommonYargsArgv } from "../yargs-types";
|
|
3
3
|
|
|
4
|
-
export function Name(yargs:
|
|
4
|
+
export function Name(yargs: CommonYargsArgv) {
|
|
5
5
|
return yargs
|
|
6
6
|
.positional("name", {
|
|
7
7
|
describe: "The name or binding of the DB",
|
|
@@ -11,7 +11,7 @@ export function Name(yargs: Argv) {
|
|
|
11
11
|
.epilogue(d1BetaWarning);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export function Database(yargs:
|
|
14
|
+
export function Database(yargs: CommonYargsArgv) {
|
|
15
15
|
return yargs
|
|
16
16
|
.positional("database", {
|
|
17
17
|
describe: "The name or binding of the DB",
|
package/src/delete.ts
CHANGED
|
@@ -8,14 +8,12 @@ import { logger } from "./logger";
|
|
|
8
8
|
import * as metrics from "./metrics";
|
|
9
9
|
import { requireAuth } from "./user";
|
|
10
10
|
import { getScriptName, printWranglerBanner } from "./index";
|
|
11
|
-
import type { ConfigPath } from "./index";
|
|
12
11
|
import type {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
CommonYargsArgv,
|
|
13
|
+
StrictYargsOptionsToInterface,
|
|
15
14
|
} from "./yargs-types";
|
|
16
|
-
import type { Argv } from "yargs";
|
|
17
15
|
|
|
18
|
-
export function deleteOptions(yargs:
|
|
16
|
+
export function deleteOptions(yargs: CommonYargsArgv) {
|
|
19
17
|
return yargs
|
|
20
18
|
.positional("script", {
|
|
21
19
|
describe: "The path to an entry point for your worker",
|
|
@@ -38,14 +36,13 @@ export function deleteOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
type DeleteArgs =
|
|
39
|
+
type DeleteArgs = StrictYargsOptionsToInterface<typeof deleteOptions>;
|
|
42
40
|
|
|
43
41
|
export async function deleteHandler(args: DeleteArgs) {
|
|
44
42
|
await printWranglerBanner();
|
|
45
43
|
|
|
46
44
|
const configPath =
|
|
47
|
-
|
|
48
|
-
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
45
|
+
args.config || (args.script && findWranglerToml(path.dirname(args.script)));
|
|
49
46
|
const config = readConfig(configPath, args);
|
|
50
47
|
await metrics.sendMetricsEvent(
|
|
51
48
|
"delete worker script",
|
package/src/deprecated/index.ts
CHANGED
|
@@ -3,15 +3,14 @@ import { createCLIParser } from "../index";
|
|
|
3
3
|
import { logger } from "../logger";
|
|
4
4
|
import { formatMessage } from "../parse";
|
|
5
5
|
import type {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
CommonYargsArgv,
|
|
7
|
+
StrictYargsOptionsToInterface,
|
|
8
8
|
} from "../yargs-types";
|
|
9
|
-
import type { Argv, BuilderCallback } from "yargs";
|
|
10
9
|
|
|
11
|
-
export function buildOptions(yargs:
|
|
10
|
+
export function buildOptions(yargs: CommonYargsArgv) {
|
|
12
11
|
return yargs;
|
|
13
12
|
}
|
|
14
|
-
type BuildArgs =
|
|
13
|
+
type BuildArgs = StrictYargsOptionsToInterface<typeof buildOptions>;
|
|
15
14
|
export async function buildHandler(buildArgs: BuildArgs) {
|
|
16
15
|
// "[DEPRECATED] 🦀 Build your project (if applicable)",
|
|
17
16
|
|
|
@@ -47,7 +46,7 @@ export const configHandler = () => {
|
|
|
47
46
|
);
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
export function previewOptions(yargs:
|
|
49
|
+
export function previewOptions(yargs: CommonYargsArgv) {
|
|
51
50
|
return yargs
|
|
52
51
|
.positional("method", {
|
|
53
52
|
type: "string",
|
|
@@ -71,7 +70,7 @@ export function previewHandler() {
|
|
|
71
70
|
);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
export const route
|
|
73
|
+
export const route = (routeYargs: CommonYargsArgv) => {
|
|
75
74
|
return routeYargs
|
|
76
75
|
.command(
|
|
77
76
|
"list",
|
|
@@ -134,7 +133,7 @@ export const routeHandler = () => {
|
|
|
134
133
|
throw new DeprecationError(`${deprecationNotice}\n${shouldDo}`);
|
|
135
134
|
};
|
|
136
135
|
|
|
137
|
-
export const subdomainOptions = (yargs:
|
|
136
|
+
export const subdomainOptions = (yargs: CommonYargsArgv) => {
|
|
138
137
|
return yargs.positional("name", { type: "string" });
|
|
139
138
|
};
|
|
140
139
|
|