@prisma/cli-engine 0.6.3 → 0.7.0
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/README.md +51 -0
- package/dist/{engine-BLU1DuVo.js → engine-DVJ5Ie5H.js} +473 -12
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -1
- package/dist/{report-B_8n69OY.d.ts → report-CQ30sy_e.d.ts} +108 -2
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,4 +10,55 @@ Every command describes its output once, as blocks, and the engine renders it in
|
|
|
10
10
|
- `@prisma/cli-engine/protocol` — the wire types for machine-readable (JSON) output.
|
|
11
11
|
- `@prisma/cli-engine/testing` — the test harness for running commands in-process.
|
|
12
12
|
|
|
13
|
+
## Statement prompts
|
|
14
|
+
|
|
15
|
+
A command asks what the user means to happen to something with `ctx.prompt.statement`. The answer is a verb and free text, and the command validates it.
|
|
16
|
+
|
|
17
|
+
The command declares the verbs it may ask with, each with its `arity` (how many values follow the flag) and a help `brief`:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
defineCommand({
|
|
21
|
+
statements: {
|
|
22
|
+
rename: { arity: 1, brief: "Rename a table instead of dropping it: --rename Old:New" },
|
|
23
|
+
delete: { arity: 1, brief: "Drop a table and its rows: --delete Table" },
|
|
24
|
+
},
|
|
25
|
+
// ...
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Only that command accepts `--rename` and `--delete`; on any other command they are unknown flags. Their values stay out of the handler's flags, and help lists them on the command's own card. A verb is one lowercase word, and may not be a shared flag or one of the command's own flags. Asking with a verb the command did not declare is a construction error, and so is a question with an empty subject or a verb listed twice.
|
|
30
|
+
|
|
31
|
+
Then, in the handler:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const answer = await ctx.prompt.statement(
|
|
35
|
+
'Table "Legacy" would be dropped and its rows lost. What do you mean?',
|
|
36
|
+
{
|
|
37
|
+
subject: "Legacy",
|
|
38
|
+
verbs: ["rename", "delete"],
|
|
39
|
+
forms: { rename: "Legacy:<new name>" },
|
|
40
|
+
validate: (verb, text) =>
|
|
41
|
+
verb === "rename" && !text.startsWith("Legacy:")
|
|
42
|
+
? "Write the rename as Legacy:<new name>."
|
|
43
|
+
: undefined,
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
// { verb: "delete", text: "Legacy", values: ["Legacy"] }
|
|
47
|
+
// or { verb: "rename", text: "Legacy:Archive", values: ["Legacy:Archive"] }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each occurrence of `--<verb>` takes exactly `arity` values, in argv order across all the verbs. A wrong count or an empty value is `CLI.INVALID_ARGUMENTS`. A token that starts with `-` reads as a flag, so a first value that starts with `-` must be written `--<verb>=<value>`. `values` holds them; `text` is them joined by one space.
|
|
51
|
+
|
|
52
|
+
The engine answers the question in this order:
|
|
53
|
+
|
|
54
|
+
1. A verb flag whose first value names the subject: the value is the subject, or starts with `<subject>:`. `--delete Legacy` and `--rename Legacy:Archive` both name `Legacy`. Within one batch, a value equal to a subject answers that subject first, and any other value goes to the longest subject it names, so `--delete A:B` answers the question about `A:B`, not the one about `A`. Ask questions whose subjects are prefixes of one another in one batch. A value `validate` rejects fails the run with `CLI.PROMPT_INVALID`.
|
|
55
|
+
2. With no such value, a non-interactive run, or one under `--yes`, fails with `CLI.CONSENT_REQUIRED`. Its next actions give one flag to pass per verb, safe to paste into a shell: a value with anything but plain characters is single-quoted, and a value starting with `-` is written `--<verb>=<value>`, and its `meta` carries `subject`, `verbs` and `unanswered`.
|
|
56
|
+
3. Otherwise the user is asked, and answers `<verb> <text>`, or `<verb>` alone to mean the subject. A verb with an arity above 1 takes its values from the text, separated by whitespace, and `text` is them joined by one space, as for a flag. A rejected answer is asked again on a terminal; with scripted or piped input it fails with `CLI.PROMPT_INVALID`.
|
|
57
|
+
|
|
58
|
+
`ctx.prompt.statements([...])` asks several questions at once and returns the answers in order. Flags answer what they can, a refusal lists every question still unanswered, and an interactive run asks the rest one after another.
|
|
59
|
+
|
|
60
|
+
A statement is the command's own declared input, unlike a `--confirm` value, which a handler never sees. A command that needs some statements as input to its work, before it can know what to ask, takes them with `ctx.statements.take("rename")`: every unconsumed value of that verb, in argv order, as `{ verb, values, text }[]`. Taken values are consumed, and other verbs' values stay for the questions. A later question may still list a taken verb: no flag value of it is left to answer the question, so the verb serves the refusal's `--<verb>` form and what a user may type. `ctx.statements.values()` lists every unconsumed value of every verb in argv order without consuming any, for showing what a run was given, such as in a line that repeats the command. Take, and ask any consent with a token, before any `last: true` batch, which reports every value still unconsumed.
|
|
61
|
+
|
|
62
|
+
Each flag answers one question. A run that succeeds with a flag nothing consumed fails with `CLI.CONSENT_UNUSED`, so a mistyped subject or a second answer to one question is never ignored. The same holds for a `--confirm` token no consent asked for, on a command that declares statements (other commands still ignore a leftover `--confirm`; see [#339](https://github.com/prisma/prisma-cli/issues/339)). A refusal also names any given statement flag that matches none of its questions, and any `--confirm` token, so the user hears of it before answering a prompt. That check runs when the handler returns, after the command has acted. A command that asks everything in one batch passes `statements(questions, { last: true })` to get the same failure right after the questions are answered, before it does anything with them.
|
|
63
|
+
|
|
13
64
|
Part of [prisma/prisma-cli](https://github.com/prisma/prisma-cli).
|
|
@@ -1158,7 +1158,7 @@ const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
|
1158
1158
|
* an ordinary character and reads `%` and `^` — so a line pasted into
|
|
1159
1159
|
* cmd.exe or PowerShell is not quoted for those shells.
|
|
1160
1160
|
*/
|
|
1161
|
-
function shellQuote(entry) {
|
|
1161
|
+
function shellQuote$1(entry) {
|
|
1162
1162
|
if (SHELL_SAFE.test(entry)) return entry;
|
|
1163
1163
|
return `'${entry.replaceAll("'", String.raw`'\''`)}'`;
|
|
1164
1164
|
}
|
|
@@ -1166,7 +1166,7 @@ function spell$1(file, args) {
|
|
|
1166
1166
|
return {
|
|
1167
1167
|
file,
|
|
1168
1168
|
args,
|
|
1169
|
-
line: [file, ...args].map(shellQuote).join(" ")
|
|
1169
|
+
line: [file, ...args].map(shellQuote$1).join(" ")
|
|
1170
1170
|
};
|
|
1171
1171
|
}
|
|
1172
1172
|
function addSpelling(file) {
|
|
@@ -2158,11 +2158,126 @@ function resolveLogLevel(shared) {
|
|
|
2158
2158
|
return shared.logLevel ?? "info";
|
|
2159
2159
|
}
|
|
2160
2160
|
//#endregion
|
|
2161
|
+
//#region src/execution/statement-flags.ts
|
|
2162
|
+
/**
|
|
2163
|
+
* Statement flags: `--<verb>` followed by the verb's `arity` values,
|
|
2164
|
+
* repeatable, accepted only by the command that declares the verb. The
|
|
2165
|
+
* engine takes them out of argv before the parser sees it, because the
|
|
2166
|
+
* parser gives a flag one value per occurrence and keeps no order
|
|
2167
|
+
* across flags. The values stay out of the handler's flags; the
|
|
2168
|
+
* handler reads them through ctx.prompt.statement or
|
|
2169
|
+
* ctx.statements.take.
|
|
2170
|
+
*/
|
|
2171
|
+
function statementsOf(def) {
|
|
2172
|
+
return def.kind === "result-command" ? def.statements ?? {} : {};
|
|
2173
|
+
}
|
|
2174
|
+
function declaredStatements(def) {
|
|
2175
|
+
return Object.keys(statementsOf(def));
|
|
2176
|
+
}
|
|
2177
|
+
/** How help shows the flag: `<subject>` for the first value, `<value>`
|
|
2178
|
+
* for each further one. */
|
|
2179
|
+
function statementPlaceholders(spec) {
|
|
2180
|
+
return ["<subject>", ...Array.from({ length: spec.arity - 1 }, () => "<value>")].join(" ");
|
|
2181
|
+
}
|
|
2182
|
+
function statementBrief(verb, spec) {
|
|
2183
|
+
return spec.brief ?? `Say what happens to <subject>: ${verb}, instead of being asked (repeatable)`;
|
|
2184
|
+
}
|
|
2185
|
+
/** The command argv routes to, found the way the parser routes: the
|
|
2186
|
+
* leading words, group by group, until one names a command. Like the
|
|
2187
|
+
* parser, a kebab-case word matches a camelCase name. */
|
|
2188
|
+
function routedCommand(tree, argv) {
|
|
2189
|
+
let node = tree;
|
|
2190
|
+
for (const token of argv) {
|
|
2191
|
+
const entry = node.commands.get(token) ?? node.commands.get(camelCase(token));
|
|
2192
|
+
if (entry !== void 0) return entry;
|
|
2193
|
+
const child = node.children.get(token) ?? node.children.get(camelCase(token));
|
|
2194
|
+
if (child === void 0) return;
|
|
2195
|
+
node = child;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
function statementFlagIn(token, statements) {
|
|
2199
|
+
if (!token.startsWith("--")) return;
|
|
2200
|
+
const equals = token.indexOf("=");
|
|
2201
|
+
const verb = token.slice(2, equals === -1 ? void 0 : equals);
|
|
2202
|
+
if (!Object.hasOwn(statements, verb)) return;
|
|
2203
|
+
return {
|
|
2204
|
+
verb,
|
|
2205
|
+
inline: equals === -1 ? void 0 : token.slice(equals + 1)
|
|
2206
|
+
};
|
|
2207
|
+
}
|
|
2208
|
+
/** A first value that starts with `-` reads as a flag, so it can only
|
|
2209
|
+
* be given inline; the error says so when that is what happened. */
|
|
2210
|
+
function wrongValueCount(verb, arity, given, next) {
|
|
2211
|
+
const wanted = arity === 1 ? "a value" : `${arity} values`;
|
|
2212
|
+
const summary = `--${verb} needs ${wanted}, and was given ${given}.`;
|
|
2213
|
+
if (given === 0 && next?.startsWith("-") === true) return new CliStructuredError("CLI.INVALID_ARGUMENTS", `${summary} A value that starts with '-' must be written --${verb}=<value>.`, { nextActions: [{
|
|
2214
|
+
kind: "user-choice",
|
|
2215
|
+
label: `Write --${verb}=<value>.`
|
|
2216
|
+
}] });
|
|
2217
|
+
return new CliStructuredError("CLI.INVALID_ARGUMENTS", summary, { nextActions: [{
|
|
2218
|
+
kind: "user-choice",
|
|
2219
|
+
label: `Pass --${verb} followed by ${wanted}.`
|
|
2220
|
+
}] });
|
|
2221
|
+
}
|
|
2222
|
+
function emptyValue(verb) {
|
|
2223
|
+
return new CliStructuredError("CLI.INVALID_ARGUMENTS", `--${verb} was given an empty value.`, { nextActions: [{
|
|
2224
|
+
kind: "user-choice",
|
|
2225
|
+
label: `Name what --${verb} is about.`
|
|
2226
|
+
}] });
|
|
2227
|
+
}
|
|
2228
|
+
/**
|
|
2229
|
+
* Takes the command's statement flags out of argv, keeping their
|
|
2230
|
+
* values in the order argv gave them. A value is any following token
|
|
2231
|
+
* that is not a flag; nothing after a bare `--` is a flag.
|
|
2232
|
+
*/
|
|
2233
|
+
function extractStatementFlags(argv, statements) {
|
|
2234
|
+
const terminator = argv.indexOf("--");
|
|
2235
|
+
const tokens = terminator === -1 ? argv : argv.slice(0, terminator);
|
|
2236
|
+
const rest = terminator === -1 ? [] : argv.slice(terminator);
|
|
2237
|
+
const kept = [];
|
|
2238
|
+
const values = [];
|
|
2239
|
+
let index = 0;
|
|
2240
|
+
while (index < tokens.length) {
|
|
2241
|
+
const token = tokens[index];
|
|
2242
|
+
index += 1;
|
|
2243
|
+
const flag = statementFlagIn(token, statements);
|
|
2244
|
+
if (flag === void 0) {
|
|
2245
|
+
kept.push(token);
|
|
2246
|
+
continue;
|
|
2247
|
+
}
|
|
2248
|
+
const { arity } = statements[flag.verb];
|
|
2249
|
+
const given = flag.inline === void 0 ? [] : [flag.inline];
|
|
2250
|
+
while (given.length < arity && index < tokens.length && !tokens[index].startsWith("-")) {
|
|
2251
|
+
given.push(tokens[index]);
|
|
2252
|
+
index += 1;
|
|
2253
|
+
}
|
|
2254
|
+
if (given.length !== arity) return {
|
|
2255
|
+
ok: false,
|
|
2256
|
+
error: wrongValueCount(flag.verb, arity, given.length, tokens[index])
|
|
2257
|
+
};
|
|
2258
|
+
if (given.some((value) => value.trim() === "")) return {
|
|
2259
|
+
ok: false,
|
|
2260
|
+
error: emptyValue(flag.verb)
|
|
2261
|
+
};
|
|
2262
|
+
values.push({
|
|
2263
|
+
verb: flag.verb,
|
|
2264
|
+
values: given,
|
|
2265
|
+
consumed: false
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
return {
|
|
2269
|
+
ok: true,
|
|
2270
|
+
argv: [...kept, ...rest],
|
|
2271
|
+
values
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
//#endregion
|
|
2161
2275
|
//#region src/execution/command-tree.ts
|
|
2162
2276
|
function constructionError(message) {
|
|
2163
2277
|
return /* @__PURE__ */ new Error(`@prisma/cli-engine: ${message}`);
|
|
2164
2278
|
}
|
|
2165
2279
|
const CAMEL_CASE = /^[a-z][a-zA-Z0-9]*$/;
|
|
2280
|
+
const ONE_LOWERCASE_WORD = /^[a-z]+$/;
|
|
2166
2281
|
const INTEGER_LIKE = /^\d+$/;
|
|
2167
2282
|
function validateFlags(path, def) {
|
|
2168
2283
|
const flags = def.args.flags;
|
|
@@ -2177,6 +2292,14 @@ function validateFlags(path, def) {
|
|
|
2177
2292
|
seenAliases.add(alias);
|
|
2178
2293
|
}
|
|
2179
2294
|
}
|
|
2295
|
+
function validateStatements(path, def) {
|
|
2296
|
+
for (const [verb, spec] of Object.entries(statementsOf(def))) {
|
|
2297
|
+
if (!ONE_LOWERCASE_WORD.test(verb)) throw constructionError(`command '${path}' statement '${verb}' must be one lowercase word (it is both the flag and the word typed at the prompt)`);
|
|
2298
|
+
if (RESERVED_FLAG_NAMES.has(verb)) throw constructionError(`command '${path}' declares statement '${verb}', which is a shared flag`);
|
|
2299
|
+
if (def.args.flags[verb] !== void 0) throw constructionError(`command '${path}' declares both a flag and a statement named '${verb}'`);
|
|
2300
|
+
if (!Number.isInteger(spec.arity) || spec.arity < 1) throw constructionError(`command '${path}' statement '${verb}' declares arity ${spec.arity}; arity is a whole number of values, at least 1`);
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2180
2303
|
function validatePositionals(path, def) {
|
|
2181
2304
|
const entries = Object.entries(def.args.positionals);
|
|
2182
2305
|
let sawOptional = false;
|
|
@@ -2270,6 +2393,7 @@ function buildCommandTree(spec) {
|
|
|
2270
2393
|
for (const path of paths) {
|
|
2271
2394
|
const def = spec.commands[path];
|
|
2272
2395
|
validateFlags(path, def);
|
|
2396
|
+
validateStatements(path, def);
|
|
2273
2397
|
validatePositionals(path, def);
|
|
2274
2398
|
validateExitCodes(path, def);
|
|
2275
2399
|
validateSpawnDeclarations(path, def);
|
|
@@ -2296,7 +2420,7 @@ function mountedAs(spec, path) {
|
|
|
2296
2420
|
/** Engine-injected shared flags count: a command answers them whether
|
|
2297
2421
|
* or not it declared them, so a redirect for one could never fire. */
|
|
2298
2422
|
function acceptsFlag(def, flag) {
|
|
2299
|
-
if (def.args.flags[flag] !== void 0) return true;
|
|
2423
|
+
if (def.args.flags[flag] !== void 0 || declaredStatements(def).includes(flag)) return true;
|
|
2300
2424
|
return def.kind !== "server-command" && RESERVED_FLAG_NAMES.has(flag);
|
|
2301
2425
|
}
|
|
2302
2426
|
function addVerbRedirect(spec, table, redirect) {
|
|
@@ -2973,7 +3097,11 @@ function writeDiagnostic(stream, diagnostic, paint = PLAIN) {
|
|
|
2973
3097
|
const glyph = paint(diagnostic.severity, DIAGNOSTIC_SYMBOL[diagnostic.severity]);
|
|
2974
3098
|
const code = paint("muted", `[${diagnostic.code}]`);
|
|
2975
3099
|
stream.write(`${glyph} ${code} ${diagnostic.summary}\n`);
|
|
2976
|
-
if (diagnostic.why !== void 0)
|
|
3100
|
+
if (diagnostic.why !== void 0) {
|
|
3101
|
+
const [first, ...rest] = String(diagnostic.why).split("\n");
|
|
3102
|
+
stream.write(` ${paint("muted", `why: ${first}`)}\n`);
|
|
3103
|
+
for (const line of rest) stream.write(` ${paint("muted", line)}\n`);
|
|
3104
|
+
}
|
|
2977
3105
|
for (const action of renderableNextActions(diagnostic.nextActions)) stream.write(`${renderNextAction(action, paint)}\n`);
|
|
2978
3106
|
if (diagnostic.docsUrl !== void 0) stream.write(` ${paint("muted", "docs:")} ${paint("link", diagnostic.docsUrl)}\n`);
|
|
2979
3107
|
}
|
|
@@ -3830,7 +3958,7 @@ function toWritable(out) {
|
|
|
3830
3958
|
callback();
|
|
3831
3959
|
} });
|
|
3832
3960
|
}
|
|
3833
|
-
async function makeClackRenderer(stdin, stderr) {
|
|
3961
|
+
async function makeClackRenderer(stdin, stderr, signal) {
|
|
3834
3962
|
const clack = await import("@clack/prompts");
|
|
3835
3963
|
const input = toReadable(stdin);
|
|
3836
3964
|
const output = toWritable(stderr);
|
|
@@ -3838,25 +3966,35 @@ async function makeClackRenderer(stdin, stderr) {
|
|
|
3838
3966
|
confirm: (question, initial) => clack.confirm({
|
|
3839
3967
|
input,
|
|
3840
3968
|
output,
|
|
3969
|
+
signal,
|
|
3841
3970
|
message: question,
|
|
3842
3971
|
initialValue: initial ?? false
|
|
3843
3972
|
}),
|
|
3844
3973
|
consent: (question) => clack.confirm({
|
|
3845
3974
|
input,
|
|
3846
3975
|
output,
|
|
3976
|
+
signal,
|
|
3847
3977
|
message: question,
|
|
3848
3978
|
initialValue: false
|
|
3849
3979
|
}),
|
|
3850
3980
|
confirmToken: (question, token) => clack.text({
|
|
3851
3981
|
input,
|
|
3852
3982
|
output,
|
|
3983
|
+
signal,
|
|
3853
3984
|
message: `${question} Type ${token} to confirm.`,
|
|
3854
3985
|
placeholder: token,
|
|
3855
3986
|
validate: (value) => value === token ? void 0 : `Type ${token} exactly, or press Ctrl-C.`
|
|
3856
3987
|
}),
|
|
3988
|
+
statement: (message) => clack.text({
|
|
3989
|
+
input,
|
|
3990
|
+
output,
|
|
3991
|
+
signal,
|
|
3992
|
+
message
|
|
3993
|
+
}),
|
|
3857
3994
|
select: (question, options, initial) => clack.select({
|
|
3858
3995
|
input,
|
|
3859
3996
|
output,
|
|
3997
|
+
signal,
|
|
3860
3998
|
message: question,
|
|
3861
3999
|
options: options.map((option) => ({
|
|
3862
4000
|
value: option.value,
|
|
@@ -3867,6 +4005,7 @@ async function makeClackRenderer(stdin, stderr) {
|
|
|
3867
4005
|
text: (question, placeholder, fallback) => clack.text({
|
|
3868
4006
|
input,
|
|
3869
4007
|
output,
|
|
4008
|
+
signal,
|
|
3870
4009
|
message: question,
|
|
3871
4010
|
placeholder,
|
|
3872
4011
|
defaultValue: fallback
|
|
@@ -3876,6 +4015,9 @@ async function makeClackRenderer(stdin, stderr) {
|
|
|
3876
4015
|
}
|
|
3877
4016
|
//#endregion
|
|
3878
4017
|
//#region src/execution/prompts.ts
|
|
4018
|
+
const WHITESPACE = /\s/;
|
|
4019
|
+
const SHELL_PLAIN = /^[A-Za-z0-9_.:@%+/,-][A-Za-z0-9_.:@%+/,=-]*$/;
|
|
4020
|
+
const WHITESPACES = /\s+/;
|
|
3879
4021
|
/** How often browserWait asks whether the user has finished. */
|
|
3880
4022
|
const BROWSER_WAIT_POLL_INTERVAL_MS = 1e3;
|
|
3881
4023
|
/** A `--confirm` value grants at most one consent: the matched value is
|
|
@@ -3886,6 +4028,174 @@ function consumeConfirmValue(state, token) {
|
|
|
3886
4028
|
state.confirmValues.splice(index, 1);
|
|
3887
4029
|
return true;
|
|
3888
4030
|
}
|
|
4031
|
+
/** A value as a POSIX shell reads it back: plain values as they are,
|
|
4032
|
+
* anything else in single quotes, an embedded quote written `'\''`. */
|
|
4033
|
+
function shellQuote(value) {
|
|
4034
|
+
return SHELL_PLAIN.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
|
|
4035
|
+
}
|
|
4036
|
+
/** The flag as a user would paste it. A first value starting with `-`
|
|
4037
|
+
* would read as a flag, so it is joined with `=`. */
|
|
4038
|
+
function flagForm(verb, values) {
|
|
4039
|
+
const [first, ...rest] = values.map(shellQuote);
|
|
4040
|
+
return [values[0].startsWith("-") ? `--${verb}=${first}` : `--${verb} ${first}`, ...rest].join(" ");
|
|
4041
|
+
}
|
|
4042
|
+
/** What a question accepts, as the prompt shows it: each verb with its
|
|
4043
|
+
* form when it has one. */
|
|
4044
|
+
function statementHint(question) {
|
|
4045
|
+
return question.verbs.map((verb) => {
|
|
4046
|
+
const form = question.forms?.[verb];
|
|
4047
|
+
return form === void 0 ? verb : `${verb} ${form}`;
|
|
4048
|
+
}).join(" or ");
|
|
4049
|
+
}
|
|
4050
|
+
function namesSubject(value, subject) {
|
|
4051
|
+
return value === subject || value.startsWith(`${subject}:`);
|
|
4052
|
+
}
|
|
4053
|
+
function subjectOf(value) {
|
|
4054
|
+
const colon = value.indexOf(":");
|
|
4055
|
+
return colon === -1 ? value : value.slice(0, colon);
|
|
4056
|
+
}
|
|
4057
|
+
/** The longest of `subjects` that `value` names: `A:B` names both `A`
|
|
4058
|
+
* and `A:B`, and belongs to `A:B`. */
|
|
4059
|
+
function longestSubjectNamed(value, subjects) {
|
|
4060
|
+
let longest;
|
|
4061
|
+
for (const subject of subjects) if (namesSubject(value, subject) && (longest === void 0 || subject.length > longest.length)) longest = subject;
|
|
4062
|
+
return longest;
|
|
4063
|
+
}
|
|
4064
|
+
/** The first unconsumed statement-flag value whose first value `fits`
|
|
4065
|
+
* the question, tried verb by verb. A value the command rejects fails
|
|
4066
|
+
* the run: a wrong flag cannot be corrected by asking again. */
|
|
4067
|
+
function answerFromFlags(state, question, fits) {
|
|
4068
|
+
for (const verb of question.verbs) {
|
|
4069
|
+
const value = state.statementValues.find((candidate) => !candidate.consumed && candidate.verb === verb && fits(candidate.values[0]));
|
|
4070
|
+
if (value === void 0) continue;
|
|
4071
|
+
const text = value.values.join(" ");
|
|
4072
|
+
const rejection = question.validate(verb, text);
|
|
4073
|
+
if (rejection !== void 0) throw new CliStructuredError("CLI.PROMPT_INVALID", `${flagForm(verb, value.values)} does not answer "${question.question}": ${rejection}`);
|
|
4074
|
+
value.consumed = true;
|
|
4075
|
+
return {
|
|
4076
|
+
verb,
|
|
4077
|
+
text,
|
|
4078
|
+
values: value.values
|
|
4079
|
+
};
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
/** Why a refusal could not be answered from the command line: the
|
|
4083
|
+
* statement values that name none of the batch's subjects, and any
|
|
4084
|
+
* `--confirm` value, which answers no statement. */
|
|
4085
|
+
function strayFlagLines(state, subjects) {
|
|
4086
|
+
return [...state.statementValues.filter((value) => !value.consumed && longestSubjectNamed(value.values[0], subjects) === void 0).map((value) => `${flagForm(value.verb, value.values)} answers no question; the questions are about ${subjects.join(", ")}.`), ...state.confirmValues.map((token) => `${flagForm("confirm", [token])} answers no consent in this run; a statement flag is what answers these questions.`)];
|
|
4087
|
+
}
|
|
4088
|
+
function statementUnavailable(unanswered, subjects, state) {
|
|
4089
|
+
const quoted = unanswered.map((question) => `"${question.subject}"`);
|
|
4090
|
+
const situation = state.yes ? "which --yes cannot give" : "and the session is not interactive";
|
|
4091
|
+
const summary = unanswered.length === 1 ? `${quoted[0]} needs a statement, ${situation}.` : `${unanswered.length} subjects need a statement, ${situation}: ${quoted.join(", ")}.`;
|
|
4092
|
+
const listed = unanswered.map(({ subject, verbs }) => ({
|
|
4093
|
+
subject,
|
|
4094
|
+
verbs
|
|
4095
|
+
}));
|
|
4096
|
+
const unmatched = state.statementValues.filter((value) => !value.consumed && longestSubjectNamed(value.values[0], subjects) === void 0).map(({ verb, values }) => ({
|
|
4097
|
+
verb,
|
|
4098
|
+
values
|
|
4099
|
+
}));
|
|
4100
|
+
return new CliStructuredError("CLI.CONSENT_REQUIRED", summary, {
|
|
4101
|
+
why: [...unanswered.map((question) => question.question), ...strayFlagLines(state, subjects)].join("\n"),
|
|
4102
|
+
nextActions: unanswered.flatMap((question) => question.verbs.map((verb) => ({
|
|
4103
|
+
kind: "user-choice",
|
|
4104
|
+
label: `Run the command again with ${flagForm(verb, [question.forms?.[verb] ?? question.subject])}`
|
|
4105
|
+
}))),
|
|
4106
|
+
meta: {
|
|
4107
|
+
...listed.length === 1 ? listed[0] : {},
|
|
4108
|
+
unanswered: listed,
|
|
4109
|
+
...unmatched.length === 0 ? {} : { unmatched },
|
|
4110
|
+
...state.confirmValues.length === 0 ? {} : { confirm: [...state.confirmValues] }
|
|
4111
|
+
}
|
|
4112
|
+
});
|
|
4113
|
+
}
|
|
4114
|
+
/** An interactive answer: `<verb> <text>`, or `<verb>` alone to mean
|
|
4115
|
+
* the subject. A verb taking several values reads them from the text,
|
|
4116
|
+
* separated by whitespace. */
|
|
4117
|
+
function parseStatement(raw, question, state) {
|
|
4118
|
+
const trimmed = raw.trim();
|
|
4119
|
+
const space = trimmed.search(WHITESPACE);
|
|
4120
|
+
const typedVerb = space === -1 ? trimmed : trimmed.slice(0, space);
|
|
4121
|
+
const rest = space === -1 ? "" : trimmed.slice(space).trim();
|
|
4122
|
+
const verb = question.verbs.find((candidate) => candidate === typedVerb);
|
|
4123
|
+
if (verb === void 0) return { problem: `Start the answer with ${question.verbs.join(" or ")}.` };
|
|
4124
|
+
const typed = rest === "" ? question.subject : rest;
|
|
4125
|
+
const { arity } = state.statements[verb];
|
|
4126
|
+
const values = arity === 1 ? [typed] : typed.split(WHITESPACES);
|
|
4127
|
+
if (values.length !== arity) return { problem: `Give ${arity} values after ${verb}.` };
|
|
4128
|
+
const text = values.join(" ");
|
|
4129
|
+
const rejection = question.validate(verb, text);
|
|
4130
|
+
return rejection === void 0 ? { answer: {
|
|
4131
|
+
verb,
|
|
4132
|
+
text,
|
|
4133
|
+
values
|
|
4134
|
+
} } : { problem: rejection };
|
|
4135
|
+
}
|
|
4136
|
+
/** What makes a question one the command could never have meant to
|
|
4137
|
+
* ask, if anything. */
|
|
4138
|
+
function malformation(question, declared) {
|
|
4139
|
+
const about = `about '${question.subject}'`;
|
|
4140
|
+
if (question.subject === "") return `${about}: a subject must be non-empty`;
|
|
4141
|
+
if (question.verbs.length === 0) return `${about} with no verbs`;
|
|
4142
|
+
if (new Set(question.verbs).size !== question.verbs.length) return `${about} listing a verb twice`;
|
|
4143
|
+
const undeclared = question.verbs.find((verb) => !Object.hasOwn(declared, verb));
|
|
4144
|
+
return undeclared === void 0 ? void 0 : `with verb '${undeclared}', which it does not declare in statements`;
|
|
4145
|
+
}
|
|
4146
|
+
/** The asked subject a value names, if any. */
|
|
4147
|
+
function askedSubjectOf(state, value) {
|
|
4148
|
+
return longestSubjectNamed(value.values[0], state.askedSubjects);
|
|
4149
|
+
}
|
|
4150
|
+
function unusedSentence(state, value) {
|
|
4151
|
+
const given = flagForm(value.verb, value.values);
|
|
4152
|
+
const asked = askedSubjectOf(state, value);
|
|
4153
|
+
return asked === void 0 ? `${given} was given but nothing in this run asked about ${subjectOf(value.values[0])}.` : `${given} was given, but the question about ${asked} was already answered by another flag.`;
|
|
4154
|
+
}
|
|
4155
|
+
/** `--confirm` tokens no consent consumed, reported only on a command
|
|
4156
|
+
* that declares statements, where one is certainly a mistake. Other
|
|
4157
|
+
* commands still take `--confirm` on paths that ask nothing; making
|
|
4158
|
+
* their leftovers an error waits on prisma/prisma-cli#339. */
|
|
4159
|
+
function leftoverConfirmTokens(state) {
|
|
4160
|
+
return Object.keys(state.statements).length === 0 ? [] : state.confirmValues;
|
|
4161
|
+
}
|
|
4162
|
+
function unusedActions(unused, state) {
|
|
4163
|
+
const actions = [];
|
|
4164
|
+
if (unused.some((value) => askedSubjectOf(state, value) === void 0)) actions.push({
|
|
4165
|
+
kind: "user-choice",
|
|
4166
|
+
label: "Remove the flag, or spell the subject the way the command names it."
|
|
4167
|
+
});
|
|
4168
|
+
if (unused.some((value) => askedSubjectOf(state, value) !== void 0)) actions.push({
|
|
4169
|
+
kind: "user-choice",
|
|
4170
|
+
label: "Give one flag per question."
|
|
4171
|
+
});
|
|
4172
|
+
if (leftoverConfirmTokens(state).length > 0) actions.push({
|
|
4173
|
+
kind: "user-choice",
|
|
4174
|
+
label: "Remove the --confirm flag: nothing in this run asks for it."
|
|
4175
|
+
});
|
|
4176
|
+
return actions;
|
|
4177
|
+
}
|
|
4178
|
+
/** Fails a run when a consent flag answered nothing: a mistyped
|
|
4179
|
+
* subject or token, or a second answer to one question, must not
|
|
4180
|
+
* pass silently. Covers statement values and `--confirm` tokens. */
|
|
4181
|
+
function unusedConsentError(state) {
|
|
4182
|
+
const unused = state.statementValues.filter((value) => !value.consumed);
|
|
4183
|
+
if (unused.length === 0 && leftoverConfirmTokens(state).length === 0) return;
|
|
4184
|
+
const sentences = [...unused.map((value) => unusedSentence(state, value)), ...leftoverConfirmTokens(state).map((token) => `${flagForm("confirm", [token])} answers no consent in this run.`)];
|
|
4185
|
+
const asked = [...state.askedSubjects];
|
|
4186
|
+
return new CliStructuredError("CLI.CONSENT_UNUSED", sentences.join(" "), {
|
|
4187
|
+
...asked.length === 0 ? {} : { why: `The run asked about ${asked.join(", ")}.` },
|
|
4188
|
+
nextActions: unusedActions(unused, state),
|
|
4189
|
+
meta: {
|
|
4190
|
+
unused: unused.map(({ verb, values }) => ({
|
|
4191
|
+
verb,
|
|
4192
|
+
values
|
|
4193
|
+
})),
|
|
4194
|
+
...leftoverConfirmTokens(state).length === 0 ? {} : { confirm: [...leftoverConfirmTokens(state)] },
|
|
4195
|
+
...asked.length === 0 ? {} : { asked }
|
|
4196
|
+
}
|
|
4197
|
+
});
|
|
4198
|
+
}
|
|
3889
4199
|
function makeLineReader(stdin, invocation) {
|
|
3890
4200
|
const iterator = stdin[Symbol.asyncIterator]();
|
|
3891
4201
|
invocation.state.stdinIterator = iterator;
|
|
@@ -4005,12 +4315,57 @@ function parseBooleanAnswer(raw, fallback, question) {
|
|
|
4005
4315
|
].includes(normalized)) return false;
|
|
4006
4316
|
throw promptInvalid(question, raw);
|
|
4007
4317
|
}
|
|
4318
|
+
/** ctx.statements: the command's statement values read as its own
|
|
4319
|
+
* input. `values` only reads them; `take` consumes a verb's values so
|
|
4320
|
+
* the leftover check does not report them. */
|
|
4321
|
+
function makeStatementSurface(invocation) {
|
|
4322
|
+
const { state } = invocation;
|
|
4323
|
+
return {
|
|
4324
|
+
values: () => state.statementValues.filter((value) => !value.consumed).map((value) => ({
|
|
4325
|
+
verb: value.verb,
|
|
4326
|
+
text: value.values.join(" "),
|
|
4327
|
+
values: value.values
|
|
4328
|
+
})),
|
|
4329
|
+
take: (verb) => {
|
|
4330
|
+
if (!Object.hasOwn(state.statements, verb)) throw constructionError(`command '${state.commandId}' took verb '${verb}', which it does not declare in statements`);
|
|
4331
|
+
return state.statementValues.filter((value) => !value.consumed && value.verb === verb).map((value) => {
|
|
4332
|
+
value.consumed = true;
|
|
4333
|
+
return {
|
|
4334
|
+
verb,
|
|
4335
|
+
text: value.values.join(" "),
|
|
4336
|
+
values: value.values
|
|
4337
|
+
};
|
|
4338
|
+
});
|
|
4339
|
+
}
|
|
4340
|
+
};
|
|
4341
|
+
}
|
|
4008
4342
|
function makePromptSurface(invocation) {
|
|
4009
4343
|
const { runtime, hooks, state } = invocation;
|
|
4010
4344
|
let readLine;
|
|
4011
4345
|
let answerCursor = 0;
|
|
4012
4346
|
let renderer;
|
|
4013
4347
|
const useClack = () => hooks.answers === void 0 && clackCapable(runtime);
|
|
4348
|
+
/** Marks the prompt as waiting for input, so a signal cancels it. */
|
|
4349
|
+
const reading = async (wait) => {
|
|
4350
|
+
state.readingPrompt = true;
|
|
4351
|
+
try {
|
|
4352
|
+
return await wait();
|
|
4353
|
+
} finally {
|
|
4354
|
+
state.readingPrompt = false;
|
|
4355
|
+
}
|
|
4356
|
+
};
|
|
4357
|
+
/** A line read that a signal cancels: resolves undefined, which the
|
|
4358
|
+
* caller reports as a cancelled prompt. */
|
|
4359
|
+
const untilCancelled = (line) => {
|
|
4360
|
+
const signal = state.promptCancel.signal;
|
|
4361
|
+
if (signal.aborted) return Promise.resolve(void 0);
|
|
4362
|
+
let onAbort = () => {};
|
|
4363
|
+
const aborted = new Promise((resolve) => {
|
|
4364
|
+
onAbort = () => resolve(void 0);
|
|
4365
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4366
|
+
});
|
|
4367
|
+
return Promise.race([line, aborted]).finally(() => signal.removeEventListener("abort", onAbort));
|
|
4368
|
+
};
|
|
4014
4369
|
const renderWithClack = async (question, run) => {
|
|
4015
4370
|
renderer ??= (() => {
|
|
4016
4371
|
const iterator = runtime.stdin[Symbol.asyncIterator]();
|
|
@@ -4018,10 +4373,10 @@ function makePromptSurface(invocation) {
|
|
|
4018
4373
|
return makeClackRenderer({
|
|
4019
4374
|
[Symbol.asyncIterator]: () => iterator,
|
|
4020
4375
|
setRawMode: (enabled) => runtime.stdin.setRawMode?.(enabled)
|
|
4021
|
-
}, runtime.stderr);
|
|
4376
|
+
}, runtime.stderr, state.promptCancel.signal);
|
|
4022
4377
|
})();
|
|
4023
4378
|
const r = await renderer;
|
|
4024
|
-
const value = await run(r);
|
|
4379
|
+
const value = await reading(() => run(r));
|
|
4025
4380
|
if (r.isCancel(value)) throw promptCancelled(question);
|
|
4026
4381
|
return value;
|
|
4027
4382
|
};
|
|
@@ -4035,7 +4390,8 @@ function makePromptSurface(invocation) {
|
|
|
4035
4390
|
}
|
|
4036
4391
|
runtime.stderr.write(rendered);
|
|
4037
4392
|
readLine ??= makeLineReader(runtime.stdin, invocation);
|
|
4038
|
-
const
|
|
4393
|
+
const readNext = readLine;
|
|
4394
|
+
const line = await reading(() => untilCancelled(readNext()));
|
|
4039
4395
|
if (line === void 0) throw promptCancelled(question);
|
|
4040
4396
|
return line;
|
|
4041
4397
|
};
|
|
@@ -4073,6 +4429,47 @@ function makePromptSurface(invocation) {
|
|
|
4073
4429
|
if (raw === "") return fallback ?? "";
|
|
4074
4430
|
return raw;
|
|
4075
4431
|
};
|
|
4432
|
+
const askStatement = async (question) => {
|
|
4433
|
+
const asked = `${question.question} (${statementHint(question)})`;
|
|
4434
|
+
if (useClack()) {
|
|
4435
|
+
const askWithClack = async (problem) => {
|
|
4436
|
+
const message = problem === void 0 ? asked : `${problem}\n${asked}`;
|
|
4437
|
+
const parsed = parseStatement(await renderWithClack(question.question, (r) => r.statement(message)), question, state);
|
|
4438
|
+
return "problem" in parsed ? askWithClack(parsed.problem) : parsed.answer;
|
|
4439
|
+
};
|
|
4440
|
+
return askWithClack(void 0);
|
|
4441
|
+
}
|
|
4442
|
+
const raw = await ask(question.question, `? ${asked} `);
|
|
4443
|
+
if (typeof raw !== "string") throw promptInvalid(question.question, String(raw));
|
|
4444
|
+
const parsed = parseStatement(raw, question, state);
|
|
4445
|
+
if ("problem" in parsed) throw new CliStructuredError("CLI.PROMPT_INVALID", `"${raw}" is not a valid answer to "${question.question}": ${parsed.problem}`);
|
|
4446
|
+
return parsed.answer;
|
|
4447
|
+
};
|
|
4448
|
+
const requireWellFormed = (questions) => {
|
|
4449
|
+
for (const question of questions) {
|
|
4450
|
+
const problem = malformation(question, state.statements);
|
|
4451
|
+
if (problem !== void 0) throw constructionError(`command '${state.commandId}' asked a statement ${problem}`);
|
|
4452
|
+
}
|
|
4453
|
+
};
|
|
4454
|
+
/** Flags answer first, so a refusal can name every question still
|
|
4455
|
+
* unanswered at once; the rest are asked one after another. */
|
|
4456
|
+
const statements = async (questions, opts) => {
|
|
4457
|
+
requireWellFormed(questions);
|
|
4458
|
+
for (const question of questions) state.askedSubjects.add(question.subject);
|
|
4459
|
+
const subjects = questions.map((question) => question.subject);
|
|
4460
|
+
const exact = questions.map((question) => answerFromFlags(state, question, (first) => first === question.subject));
|
|
4461
|
+
const fromFlags = questions.map((question, index) => exact[index] ?? answerFromFlags(state, question, (first) => longestSubjectNamed(first, subjects) === question.subject));
|
|
4462
|
+
const unanswered = questions.filter((_question, index) => fromFlags[index] === void 0);
|
|
4463
|
+
if (unanswered.length > 0 && (state.yes || !state.interactive)) throw statementUnavailable(unanswered, questions.map((question) => question.subject), state);
|
|
4464
|
+
const answerFrom = async (index) => {
|
|
4465
|
+
if (index === questions.length) return [];
|
|
4466
|
+
return [fromFlags[index] ?? await askStatement(questions[index]), ...await answerFrom(index + 1)];
|
|
4467
|
+
};
|
|
4468
|
+
const answers = await answerFrom(0);
|
|
4469
|
+
const unused = opts?.last === true ? unusedConsentError(state) : void 0;
|
|
4470
|
+
if (unused !== void 0) throw unused;
|
|
4471
|
+
return answers;
|
|
4472
|
+
};
|
|
4076
4473
|
/** A prompt writes to stderr and reads the engine's stdin — the same
|
|
4077
4474
|
* terminal a live child inherited. Like ctx.present, prompting while
|
|
4078
4475
|
* a child owns the terminal is a construction error. */
|
|
@@ -4143,6 +4540,14 @@ function makePromptSurface(invocation) {
|
|
|
4143
4540
|
consent: (question, opts) => claimTerminal(() => surface.consent(question, opts)),
|
|
4144
4541
|
select: (question, options, opts) => claimTerminal(() => surface.select(question, options, opts)),
|
|
4145
4542
|
text: (question, opts) => claimTerminal(() => surface.text(question, opts)),
|
|
4543
|
+
statement: async (question, opts) => {
|
|
4544
|
+
const [answer] = await claimTerminal(() => statements([{
|
|
4545
|
+
question,
|
|
4546
|
+
...opts
|
|
4547
|
+
}], void 0));
|
|
4548
|
+
return answer;
|
|
4549
|
+
},
|
|
4550
|
+
statements: (questions, opts) => claimTerminal(() => statements(questions, opts)),
|
|
4146
4551
|
browserWait: (request) => claimTerminal(() => surface.browserWait(request))
|
|
4147
4552
|
};
|
|
4148
4553
|
}
|
|
@@ -4440,6 +4845,7 @@ function makeContext(invocation, def, config, configFiles, capabilities) {
|
|
|
4440
4845
|
lastChild: () => state.lastChild,
|
|
4441
4846
|
report: (event) => reportEvent(invocation, event),
|
|
4442
4847
|
prompt: makePromptSurface(invocation),
|
|
4848
|
+
statements: makeStatementSurface(invocation),
|
|
4443
4849
|
openUrl: (request) => announceUrl(invocation, request),
|
|
4444
4850
|
signal: invocation.signal,
|
|
4445
4851
|
cwd: invocation.runtime.cwd,
|
|
@@ -4480,7 +4886,7 @@ function makeContext(invocation, def, config, configFiles, capabilities) {
|
|
|
4480
4886
|
* positional slots (reduced to a count on the spot).
|
|
4481
4887
|
*/
|
|
4482
4888
|
function declaredFlagKeys(def) {
|
|
4483
|
-
const own = Object.keys(def.args.flags);
|
|
4889
|
+
const own = [...Object.keys(def.args.flags), ...declaredStatements(def)];
|
|
4484
4890
|
if (def.kind === "server-command") return own;
|
|
4485
4891
|
return [...Object.keys(SHARED_FLAG_PARAMETERS), ...own];
|
|
4486
4892
|
}
|
|
@@ -4835,7 +5241,16 @@ function sharedFlagRows() {
|
|
|
4835
5241
|
}
|
|
4836
5242
|
];
|
|
4837
5243
|
}
|
|
5244
|
+
function statementFlagRows(def) {
|
|
5245
|
+
return Object.entries(statementsOf(def)).map(([verb, spec]) => ({
|
|
5246
|
+
name: ` --${verb} ${statementPlaceholders(spec)}...`,
|
|
5247
|
+
brief: statementBrief(verb, spec)
|
|
5248
|
+
}));
|
|
5249
|
+
}
|
|
4838
5250
|
function declaredFlagRows(def) {
|
|
5251
|
+
return [...ownFlagRows(def), ...statementFlagRows(def)];
|
|
5252
|
+
}
|
|
5253
|
+
function ownFlagRows(def) {
|
|
4839
5254
|
return Object.entries(def.args.flags).map(([key, spec]) => {
|
|
4840
5255
|
const runtime = flagRuntime(spec);
|
|
4841
5256
|
return {
|
|
@@ -4964,7 +5379,7 @@ function accompanyingFindings(diagnostics) {
|
|
|
4964
5379
|
}
|
|
4965
5380
|
function settleErrored(invocation, error, diagnostics = []) {
|
|
4966
5381
|
const state = invocation.state;
|
|
4967
|
-
state.settledExitCode = error.code === "CLI.PROMPT_CANCELLED" ?
|
|
5382
|
+
state.settledExitCode = error.code === "CLI.PROMPT_CANCELLED" ? cancelledExitCode(state) : 2;
|
|
4968
5383
|
emitErrored(invocation, {
|
|
4969
5384
|
ok: false,
|
|
4970
5385
|
commandId: state.commandId,
|
|
@@ -4973,6 +5388,12 @@ function settleErrored(invocation, error, diagnostics = []) {
|
|
|
4973
5388
|
nextActions: nextActionsWithBinName(error.nextActions, invocation.cliName)
|
|
4974
5389
|
});
|
|
4975
5390
|
}
|
|
5391
|
+
/** A cancelled prompt exits 3, the user declining, unless a SIGTERM
|
|
5392
|
+
* cancelled it while it waited for input: that ends the run as the
|
|
5393
|
+
* signal it is. */
|
|
5394
|
+
function cancelledExitCode(state) {
|
|
5395
|
+
return state.promptCancel.signal.reason === "SIGTERM" ? signalExitCode("SIGTERM") : 3;
|
|
5396
|
+
}
|
|
4976
5397
|
/** The conventional code for a delivered signal: 128 + its number, so
|
|
4977
5398
|
* 130 for SIGINT and 143 for SIGTERM. */
|
|
4978
5399
|
function signalExitCode(signal) {
|
|
@@ -5356,6 +5777,9 @@ var EngineImpl = class {
|
|
|
5356
5777
|
logLevel: "info",
|
|
5357
5778
|
yes: false,
|
|
5358
5779
|
confirmValues: [],
|
|
5780
|
+
statements: {},
|
|
5781
|
+
askedSubjects: /* @__PURE__ */ new Set(),
|
|
5782
|
+
statementValues: [],
|
|
5359
5783
|
interactive: defaultInteractive(runtime),
|
|
5360
5784
|
/** Pre-parse resolution so a run that never mounts a command — an
|
|
5361
5785
|
* unknown command, a parse failure — still colours its
|
|
@@ -5374,6 +5798,8 @@ var EngineImpl = class {
|
|
|
5374
5798
|
delegatedTerminal: void 0,
|
|
5375
5799
|
lastChild: void 0,
|
|
5376
5800
|
activePrompts: 0,
|
|
5801
|
+
readingPrompt: false,
|
|
5802
|
+
promptCancel: new AbortController(),
|
|
5377
5803
|
packageOperationRunning: false,
|
|
5378
5804
|
deliveredSignal: void 0,
|
|
5379
5805
|
pendingForceExit: void 0,
|
|
@@ -5389,10 +5815,14 @@ var EngineImpl = class {
|
|
|
5389
5815
|
recordSignalDuringSpawn(state.delegatedTerminal, signal);
|
|
5390
5816
|
return;
|
|
5391
5817
|
}
|
|
5392
|
-
if (state.deliveredSignal !== void 0) {
|
|
5818
|
+
if (state.deliveredSignal !== void 0 || state.promptCancel.signal.aborted) {
|
|
5393
5819
|
runtime.exit(signal === "SIGTERM" ? 143 : 130);
|
|
5394
5820
|
return;
|
|
5395
5821
|
}
|
|
5822
|
+
if (state.readingPrompt) {
|
|
5823
|
+
state.promptCancel.abort(signal);
|
|
5824
|
+
if (signal === "SIGINT") return;
|
|
5825
|
+
}
|
|
5396
5826
|
state.deliveredSignal = signal;
|
|
5397
5827
|
controller.abort(signal);
|
|
5398
5828
|
};
|
|
@@ -5429,6 +5859,11 @@ var EngineImpl = class {
|
|
|
5429
5859
|
}, stream);
|
|
5430
5860
|
return 0;
|
|
5431
5861
|
}
|
|
5862
|
+
const stricliArgv = this.takeStatementFlags(invocation, argv, startedAtMs);
|
|
5863
|
+
if (stricliArgv === void 0) {
|
|
5864
|
+
unsubscribe();
|
|
5865
|
+
return 2;
|
|
5866
|
+
}
|
|
5432
5867
|
const stricliProcess = {
|
|
5433
5868
|
/** stricli writes only help text here. In json mode stdout carries
|
|
5434
5869
|
* exactly the frame stream, so help prose goes to stderr instead. */
|
|
@@ -5451,7 +5886,7 @@ var EngineImpl = class {
|
|
|
5451
5886
|
localization: { text: capturingText(state) }
|
|
5452
5887
|
});
|
|
5453
5888
|
try {
|
|
5454
|
-
await run(app, [...
|
|
5889
|
+
await run(app, [...stricliArgv], {
|
|
5455
5890
|
process: stricliProcess,
|
|
5456
5891
|
forCommand: (info) => {
|
|
5457
5892
|
state.prefix = info.prefix;
|
|
@@ -5470,6 +5905,26 @@ var EngineImpl = class {
|
|
|
5470
5905
|
if (state.pendingForceExit !== void 0) runtime.exit(state.pendingForceExit === "SIGTERM" ? 143 : 130);
|
|
5471
5906
|
return exitCode;
|
|
5472
5907
|
}
|
|
5908
|
+
/** The routed command's statement flags come out of argv before the
|
|
5909
|
+
* parser sees it. Returns the argv left for the parser, or undefined
|
|
5910
|
+
* when a statement flag was malformed and the run has settled. */
|
|
5911
|
+
takeStatementFlags(invocation, argv, startedAtMs) {
|
|
5912
|
+
const state = invocation.state;
|
|
5913
|
+
const routed = routedCommand(this.tree, argv);
|
|
5914
|
+
if (routed === void 0) return argv;
|
|
5915
|
+
state.statements = statementsOf(routed.def);
|
|
5916
|
+
const extraction = extractStatementFlags(argv, state.statements);
|
|
5917
|
+
if (!extraction.ok) {
|
|
5918
|
+
state.commandId = routed.id;
|
|
5919
|
+
state.docsBaseUrl = routed.docsBaseUrl;
|
|
5920
|
+
state.snapshot = buildCommandSnapshot(routed.id, routed.def, argv, []);
|
|
5921
|
+
settleErrored(invocation, extraction.error);
|
|
5922
|
+
this.fireOnSettled(invocation, 2, startedAtMs);
|
|
5923
|
+
return;
|
|
5924
|
+
}
|
|
5925
|
+
state.statementValues = extraction.values;
|
|
5926
|
+
return extraction.argv;
|
|
5927
|
+
}
|
|
5473
5928
|
/** stricli routed or parsed nothing runnable. When the redirect table
|
|
5474
5929
|
* claims the invocation the user typed, the run names its
|
|
5475
5930
|
* replacement; otherwise it settles as the usage error it is. */
|
|
@@ -5534,7 +5989,9 @@ var EngineImpl = class {
|
|
|
5534
5989
|
const result = await runHandler();
|
|
5535
5990
|
if (await this.settleAbandonedChild(invocation, false)) return;
|
|
5536
5991
|
state.resolved = true;
|
|
5992
|
+
const unused = unusedConsentError(state);
|
|
5537
5993
|
if (!result.ok) settleErrored(invocation, result.failure, result.failure.diagnostics);
|
|
5994
|
+
else if (unused !== void 0 && succeeded(state, result.value)) settleErrored(invocation, unused);
|
|
5538
5995
|
else if (isChildStatusSettlement(result.value)) settleChildStatus(invocation, entry.def, result.value);
|
|
5539
5996
|
else settleCompletion(result.value);
|
|
5540
5997
|
} catch (cause) {
|
|
@@ -5660,6 +6117,10 @@ var EngineImpl = class {
|
|
|
5660
6117
|
}
|
|
5661
6118
|
}
|
|
5662
6119
|
};
|
|
6120
|
+
function succeeded(state, value) {
|
|
6121
|
+
if (!isChildStatusSettlement(value)) return true;
|
|
6122
|
+
return state.lastChild !== void 0 && childExitCode(state.lastChild) === 0;
|
|
6123
|
+
}
|
|
5663
6124
|
/** The path the user typed, for argv that routed to no command: the
|
|
5664
6125
|
* leading tokens up to the first flag or argument escape. */
|
|
5665
6126
|
function attemptedPath(argv) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as defineConfigSection, $t as ManagementApiClientConfig, A as StatementAnswer, At as PackageManagerRunResult, B as PresentedResult, Bt as positional, C as defineServerCommand, Ct as SpawnChild, D as OpenUrlOutcome, Dt as exitWithChildStatus, E as CommandContext, Et as SpawnedChild, F as Block, Ft as Char, G as TreeNode, Gt as CredentialManager, H as Status, Ht as ActiveCredential, I as Format, It as CommandArgs, J as Severity, Jt as Session, K as Ui, Kt as CredentialOrigin, L as Outcome, Lt as FlagSpec, M as StatementQuestion, Mt as PackageOperations, N as StatementSurface, Nt as Args, O as OpenUrlRequest, Ot as PackageManagerId, P as StatementsOptions, Pt as ArgsSpec, Q as SectionValidation, Qt as ManagementApiClient, R as PRESENTED, Rt as PositionalSpec, S as defineCommand, St as ExitWithChildStatusOptions, T as BrowserWaitRequest, Tt as SpawnRequest, U as Text, Ut as Credential, V as Span, Vt as ActiveAccessTokenOptions, W as Tone, Wt as CredentialIdentity, X as StreamMeta, Xt as CredentialRefreshResult, Y as StreamEvent, Yt as StoredSessions, Z as ConfigSection, Zt as CredentialRefresher, _ as ServerCommandDefinition, _t as TelemetryPayload, a as RedirectSpec, at as ResolvedSection, b as StatementSpec, bt as ChildResult, c as CommandDefinition, ct as resolveSectionPath, d as CommandNeeds, dt as InputStream, en as TokenStorage, et as ConfigSchema, f as CompletedEnvelope, ft as LoadedConfig, g as NeedsSpec, gt as Runtime, h as HelpSpec, ht as PRISMA_CONFIG_VERSION, i as MountedTree, it as validateSectionWithSchema, j as StatementOptions, jt as PackageManagerRunner, k as PromptSurface, kt as PackageManagerRunRequest, l as CommandHandler, lt as Host, m as Handler, mt as OutputStream, n as CommandFamily, nt as configSchema, o as defineCommandFamily, ot as SectionProvenance, p as ErroredEnvelope, pt as LoadedConfigFile, q as EngineEvent, qt as SERVICE_TOKEN_ENV_VAR, r as CommandRedirect, rt as reference, s as AnyCommand, st as resolveSectionOverChain, t as TelemetryDeclaration, tt as ConfigSchemaValue, u as CommandHelp, ut as HostProcess, v as SessionCommandDefinition, vt as EngineCommandSnapshot, w as defineSessionCommand, wt as SpawnOptions, x as WorkflowStep, xt as ChildStatusSettlement, y as SpawnDeclarations, yt as RunSummary, z as Presentations, zt as flag } from "./report-CQ30sy_e.js";
|
|
2
2
|
import { n as CliStructuredError } from "./protocol-YjqPCCOG.js";
|
|
3
3
|
|
|
4
4
|
//#region src/active-access-token.d.ts
|
|
@@ -225,4 +225,4 @@ declare function claimedExpiresAt(token: string): Date | undefined;
|
|
|
225
225
|
*/
|
|
226
226
|
declare function claimedIdentity(token: string): CredentialIdentity | undefined;
|
|
227
227
|
//#endregion
|
|
228
|
-
export { type ActiveAccessTokenOptions, type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSchema, type ConfigSchemaValue, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialRefreshResult, type CredentialRefresher, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type Host, type HostProcess, type InputStream, type LoadedConfig, type LoadedConfigFile, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PackageManagerId, type PackageManagerRunRequest, type PackageManagerRunResult, type PackageManagerRunner, type PackageOperations, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type ResolvedSection, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionProvenance, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type TelemetryDeclaration, type TelemetryPayload, type TelemetryStatus, type TelemetryStatusReason, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, type WorkflowStep, authServiceError, claimedExpiresAt, claimedIdentity, configSchema, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, detectCI, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, realpathOr, reference, resolveSectionOverChain, resolveSectionPath, telemetryCommandGroup, validateSectionWithSchema };
|
|
228
|
+
export { type ActiveAccessTokenOptions, type ActiveCredential, type AnyCommand, type Args, type ArgsSpec, type Block, type BrowserWaitRequest, type Char, type ChildResult, type ChildStatusSettlement, type Cli, type CliRunHooks, type CommandArgs, type CommandContext, type CommandDefinition, type CommandFamily, type CommandHandler, type CommandHelp, type CommandNeeds, type CommandRedirect, type CompletedEnvelope, type ConfigSchema, type ConfigSchemaValue, type ConfigSection, type Credential, type CredentialIdentity, type CredentialManager, type CredentialOrigin, type CredentialRefreshResult, type CredentialRefresher, type CredentialsRequiredReason, type EngineCommandSnapshot, type EngineEvent, EnvironmentCredentialManager, type ErroredEnvelope, type ExitWithChildStatusOptions, type FlagSpec, type Format, type Handler, type HelpSpec, type Host, type HostProcess, type InputStream, type LoadedConfig, type LoadedConfigFile, type ManagementApiClient, type ManagementApiClientConfig, type MountedTree, type NeedsSpec, type OpenUrlOutcome, type OpenUrlRequest, type Outcome, type OutputStream, PRESENTED, PRISMA_CONFIG_VERSION, type PackageManagerId, type PackageManagerRunRequest, type PackageManagerRunResult, type PackageManagerRunner, type PackageOperations, type PositionalSpec, type Presentations, type PresentedResult, type PromptSurface, type RedirectSpec, type ResolvedSection, type RunSummary, type Runtime, SERVICE_TOKEN_ENV_VAR, type SectionProvenance, type SectionValidation, type ServerCommandDefinition, type Session, type SessionCommandDefinition, type Severity, type Span, type SpawnChild, type SpawnDeclarations, type SpawnOptions, type SpawnRequest, type SpawnedChild, type StatementAnswer, type StatementOptions, type StatementQuestion, type StatementSpec, type StatementSurface, type StatementsOptions, type Status, type StoredSessions, type StreamEvent, type StreamMeta, type TelemetryDeclaration, type TelemetryPayload, type TelemetryStatus, type TelemetryStatusReason, type Text, type TokenStorage, type Tone, type TreeNode, type Ui, type WorkflowStep, authServiceError, claimedExpiresAt, claimedIdentity, configSchema, createCli, credentialRejectedError, credentialWorkspaceId, credentialWorkspaceMismatchError, credentialsRequiredError, defineCommand, defineCommandFamily, defineConfigSection, definePrismaConfig, defineServerCommand, defineSessionCommand, detectCI, emptyServiceTokenError, exitWithChildStatus, flag, loadConfig, noSessionForWorkspaceError, positional, readActiveAccessToken, realpathOr, reference, resolveSectionOverChain, resolveSectionPath, telemetryCommandGroup, validateSectionWithSchema };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as ok, r as notOk, t as CliStructuredError } from "./protocol-TtNVkeVS.js";
|
|
2
|
-
import { C as credentialWorkspaceId, D as credentialsRequiredError, E as credentialWorkspaceMismatchError, O as emptyServiceTokenError, S as claimedIdentity, T as credentialRejectedError, _ as detectCI, a as definePrismaConfig, b as readActiveAccessToken, c as PRISMA_CONFIG_VERSION, d as PRESENTED, f as readUserConfig, g as exitWithChildStatus, h as resolveGating, k as noSessionForWorkspaceError, l as SERVICE_TOKEN_ENV_VAR, m as writeUserConfig, n as resolveSectionOverChain, o as loadConfig, p as userConfigPath, r as resolveSectionPath, s as realpathOr, t as buildEngine, u as WORKSPACE_ID_ENV_VAR, v as flag, w as authServiceError, x as claimedExpiresAt, y as positional } from "./engine-
|
|
2
|
+
import { C as credentialWorkspaceId, D as credentialsRequiredError, E as credentialWorkspaceMismatchError, O as emptyServiceTokenError, S as claimedIdentity, T as credentialRejectedError, _ as detectCI, a as definePrismaConfig, b as readActiveAccessToken, c as PRISMA_CONFIG_VERSION, d as PRESENTED, f as readUserConfig, g as exitWithChildStatus, h as resolveGating, k as noSessionForWorkspaceError, l as SERVICE_TOKEN_ENV_VAR, m as writeUserConfig, n as resolveSectionOverChain, o as loadConfig, p as userConfigPath, r as resolveSectionPath, s as realpathOr, t as buildEngine, u as WORKSPACE_ID_ENV_VAR, v as flag, w as authServiceError, x as claimedExpiresAt, y as positional } from "./engine-DVJ5Ie5H.js";
|
|
3
3
|
import { dirname, isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { scope, type } from "arktype";
|
|
5
5
|
//#region src/cli.ts
|
|
@@ -69,10 +69,12 @@ function defineCommand(def) {
|
|
|
69
69
|
managesCredentials: def.managesCredentials ?? false,
|
|
70
70
|
maySpawn: def.maySpawn ?? false,
|
|
71
71
|
installsPackages: def.installsPackages ?? false,
|
|
72
|
+
statements: Object.freeze({ ...def.statements }),
|
|
72
73
|
handler: def.handler
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
function defineSessionCommand(def) {
|
|
77
|
+
if (Object.hasOwn(def, "statements")) throw new Error("@prisma/cli-engine: a session command cannot declare statements (only a result command asks them)");
|
|
76
78
|
return Object.freeze({
|
|
77
79
|
kind: "session-command",
|
|
78
80
|
help: normalizeHelp(def.help),
|
|
@@ -83,6 +85,7 @@ function defineSessionCommand(def) {
|
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
function defineServerCommand(def) {
|
|
88
|
+
if (Object.hasOwn(def, "statements")) throw new Error("@prisma/cli-engine: a server command cannot declare statements (it never prompts)");
|
|
86
89
|
return Object.freeze({
|
|
87
90
|
kind: "server-command",
|
|
88
91
|
help: normalizeHelp(def.help),
|
|
@@ -1254,6 +1254,8 @@ interface CommandContext<TConfig = undefined, TCode extends number = never> {
|
|
|
1254
1254
|
readonly report: (event: EngineEvent) => void;
|
|
1255
1255
|
/** Interactive input. */
|
|
1256
1256
|
readonly prompt: PromptSurface;
|
|
1257
|
+
/** The command's declared statement flags, read as its own input. */
|
|
1258
|
+
readonly statements: StatementSurface;
|
|
1257
1259
|
/**
|
|
1258
1260
|
* Shows the user a URL and, in an interactive session, opens it in
|
|
1259
1261
|
* their browser. Always announces the URL on the commentary channel
|
|
@@ -1332,6 +1334,62 @@ interface BrowserWaitRequest {
|
|
|
1332
1334
|
* interval; a command with its own configurable cadence passes it. */
|
|
1333
1335
|
readonly interval?: number;
|
|
1334
1336
|
}
|
|
1337
|
+
interface StatementOptions<V extends string> {
|
|
1338
|
+
/** What the answer is about, in the command's own vocabulary.
|
|
1339
|
+
* Non-empty; an empty subject is a construction error. A flag value
|
|
1340
|
+
* names it when it equals the subject or starts with `<subject>:`.
|
|
1341
|
+
* Within one batch a value equal to a subject answers that subject
|
|
1342
|
+
* first, and any other value goes to the longest subject it names,
|
|
1343
|
+
* so ask questions whose subjects are prefixes of one another (`A`
|
|
1344
|
+
* and `A:B`) in one `statements` call. */
|
|
1345
|
+
readonly subject: string;
|
|
1346
|
+
/** The verbs that may answer, in the order a refusal lists them. */
|
|
1347
|
+
readonly verbs: readonly V[];
|
|
1348
|
+
/** How a refusal writes a verb's flag value, such as
|
|
1349
|
+
* `Legacy:<new name>`. A verb without one is written with the
|
|
1350
|
+
* subject. */
|
|
1351
|
+
readonly forms?: Partial<Record<V, string>>;
|
|
1352
|
+
/** Returns undefined to accept the answer, or a message saying why it
|
|
1353
|
+
* is rejected. The engine never interprets the text. */
|
|
1354
|
+
readonly validate: (verb: V, text: string) => string | undefined;
|
|
1355
|
+
}
|
|
1356
|
+
interface StatementQuestion<V extends string> extends StatementOptions<V> {
|
|
1357
|
+
readonly question: string;
|
|
1358
|
+
}
|
|
1359
|
+
interface StatementAnswer<V extends string> {
|
|
1360
|
+
readonly verb: V;
|
|
1361
|
+
/** The values joined by one space. */
|
|
1362
|
+
readonly text: string;
|
|
1363
|
+
/** The verb's `arity` values: from the flag, or split from the
|
|
1364
|
+
* typed answer on whitespace. */
|
|
1365
|
+
readonly values: readonly string[];
|
|
1366
|
+
}
|
|
1367
|
+
interface StatementSurface {
|
|
1368
|
+
/**
|
|
1369
|
+
* Every unconsumed value of `verb`, in argv order, consumed so the
|
|
1370
|
+
* leftover check does not report them. For statements that are input
|
|
1371
|
+
* to the command's work rather than answers to a question; other
|
|
1372
|
+
* verbs' values stay for the questions. A verb the command did not
|
|
1373
|
+
* declare is a construction error. A later question may still list a
|
|
1374
|
+
* taken verb: no flag value of it is left to answer the question, so
|
|
1375
|
+
* the verb serves the refusal's flag form and the typed answer.
|
|
1376
|
+
*/
|
|
1377
|
+
readonly take: <V extends string>(verb: V) => StatementAnswer<V>[];
|
|
1378
|
+
/**
|
|
1379
|
+
* Every unconsumed value of every verb, in argv order, without
|
|
1380
|
+
* consuming any: for showing the statements a run was given, such as
|
|
1381
|
+
* in a line that repeats the command.
|
|
1382
|
+
*/
|
|
1383
|
+
readonly values: () => StatementAnswer<string>[];
|
|
1384
|
+
}
|
|
1385
|
+
interface StatementsOptions {
|
|
1386
|
+
/** This is the run's final ask: values still unconsumed once the
|
|
1387
|
+
* questions are answered fail with CLI.CONSENT_UNUSED here, before
|
|
1388
|
+
* the command acts on the answers. Take any verbs you take, and ask
|
|
1389
|
+
* any consent with a token, before the `last` batch: it reports
|
|
1390
|
+
* their flags as unused at once. */
|
|
1391
|
+
readonly last?: boolean;
|
|
1392
|
+
}
|
|
1335
1393
|
/**
|
|
1336
1394
|
* Prompts. Every prompt resolves to its answered value directly.
|
|
1337
1395
|
* Failures THROW engine-internal structured errors the engine catches
|
|
@@ -1340,12 +1398,17 @@ interface BrowserWaitRequest {
|
|
|
1340
1398
|
* 2. A handler that does not catch simply propagates; one that catches
|
|
1341
1399
|
* cannot swallow the settlement — rethrow or return notOk.
|
|
1342
1400
|
*
|
|
1343
|
-
* Every prompt except `consent` may carry a declared `default`. Under
|
|
1401
|
+
* Every prompt except `consent` and `statement` may carry a declared `default`. Under
|
|
1344
1402
|
* --yes and in non-interactive contexts (no TTY stdin, CI,
|
|
1345
1403
|
* --no-interactive — format never decides interactivity) a prompt with
|
|
1346
1404
|
* a default resolves to it; one without a default throws. The prompt UI
|
|
1347
1405
|
* writes to stderr, so an interactive json run prompts without touching
|
|
1348
1406
|
* the stdout stream.
|
|
1407
|
+
*
|
|
1408
|
+
* A SIGINT or SIGTERM delivered while a prompt waits cancels it with
|
|
1409
|
+
* CLI.PROMPT_CANCELLED (exit 3 for SIGINT, 143 for SIGTERM). The
|
|
1410
|
+
* cancellation holds for the rest of the run: every later prompt is
|
|
1411
|
+
* cancelled at once, and a further signal force-exits.
|
|
1349
1412
|
*/
|
|
1350
1413
|
interface PromptSurface {
|
|
1351
1414
|
readonly confirm: (question: string, opts?: {
|
|
@@ -1367,6 +1430,29 @@ interface PromptSurface {
|
|
|
1367
1430
|
readonly consent: (question: string, opts?: {
|
|
1368
1431
|
readonly token?: string;
|
|
1369
1432
|
}) => Promise<boolean>;
|
|
1433
|
+
/**
|
|
1434
|
+
* A consent answered with a verb and free text: what the user means
|
|
1435
|
+
* should happen to `subject`. Like `consent`, `--yes` and Enter never
|
|
1436
|
+
* answer it.
|
|
1437
|
+
*
|
|
1438
|
+
* A `--<verb>` flag whose value names the subject answers it first,
|
|
1439
|
+
* in any session, without rendering anything: the value names the
|
|
1440
|
+
* subject when it is the subject or starts with `<subject>:`. A
|
|
1441
|
+
* value `validate` rejects fails the run with `CLI.PROMPT_INVALID`.
|
|
1442
|
+
* Without such a flag a non-interactive run, or one under `--yes`,
|
|
1443
|
+
* fails with `CLI.CONSENT_REQUIRED`; an interactive run asks, and the
|
|
1444
|
+
* user answers `<verb> <text>`, or `<verb>` alone to mean the subject.
|
|
1445
|
+
* Each verb must be one the command declares in `statements`; the
|
|
1446
|
+
* flag takes that declaration's `arity` values per occurrence.
|
|
1447
|
+
*/
|
|
1448
|
+
readonly statement: <V extends string>(question: string, opts: StatementOptions<V>) => Promise<StatementAnswer<V>>;
|
|
1449
|
+
/**
|
|
1450
|
+
* Several statements asked together, answered in order. Flags answer
|
|
1451
|
+
* what they can; a refusal names every question still unanswered at
|
|
1452
|
+
* once, and an interactive run asks them one after another.
|
|
1453
|
+
* `statement(question, opts)` is `statements([{ question, ...opts }])`.
|
|
1454
|
+
*/
|
|
1455
|
+
readonly statements: <V extends string>(questions: readonly StatementQuestion<V>[], opts?: StatementsOptions) => Promise<StatementAnswer<V>[]>;
|
|
1370
1456
|
readonly select: <T extends string>(question: string, options: ReadonlyArray<{
|
|
1371
1457
|
value: T;
|
|
1372
1458
|
label: string;
|
|
@@ -1491,6 +1577,22 @@ interface CommandNeeds<TConfig> {
|
|
|
1491
1577
|
interface SpawnDeclarations {
|
|
1492
1578
|
readonly maySpawn?: boolean;
|
|
1493
1579
|
}
|
|
1580
|
+
/**
|
|
1581
|
+
* A statement the command may ask for with ctx.prompt.statement. Its
|
|
1582
|
+
* key is the verb, one lowercase word, and the command alone accepts
|
|
1583
|
+
* `--<verb>` followed by `arity` values, repeatable, to answer it. The
|
|
1584
|
+
* values stay out of the handler's flags; the handler reads them
|
|
1585
|
+
* through ctx.prompt.statement or ctx.statements.take.
|
|
1586
|
+
*/
|
|
1587
|
+
interface StatementSpec {
|
|
1588
|
+
/** How many argv values each occurrence of the flag takes. Giving
|
|
1589
|
+
* another number is CLI.INVALID_ARGUMENTS. Only the first value can
|
|
1590
|
+
* be written `--<verb>=<value>`, so with an arity above 1 a later
|
|
1591
|
+
* value starting with `-` cannot be passed. */
|
|
1592
|
+
readonly arity: number;
|
|
1593
|
+
/** The flag's help brief, held to the help standard like any flag's. */
|
|
1594
|
+
readonly brief?: string;
|
|
1595
|
+
}
|
|
1494
1596
|
interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = Record<never, FlagSpec<unknown>>, TPositionals extends Record<string, PositionalSpec<unknown>> = Record<never, PositionalSpec<unknown>>, TConfig = undefined, TCode extends number = never, TManagesCredentials extends boolean = false, TInstallsPackages extends boolean = false> {
|
|
1495
1597
|
readonly kind: "result-command";
|
|
1496
1598
|
readonly help: CommandHelp;
|
|
@@ -1519,6 +1621,9 @@ interface CommandDefinition<TFlags extends Record<string, FlagSpec<unknown>> = R
|
|
|
1519
1621
|
* user's project. Declaring it never fails a run.
|
|
1520
1622
|
*/
|
|
1521
1623
|
readonly installsPackages: TInstallsPackages;
|
|
1624
|
+
/** The statements ctx.prompt.statement may ask, by verb. Optional
|
|
1625
|
+
* because a command built by an older engine has none. */
|
|
1626
|
+
readonly statements?: Readonly<Record<string, StatementSpec>>;
|
|
1522
1627
|
/**
|
|
1523
1628
|
* The handler function, referenced directly — never a dynamic import
|
|
1524
1629
|
* (operator ruling, 2026-08-09). A handler that needs heavy
|
|
@@ -1542,6 +1647,7 @@ declare function defineCommand<TFlags extends Record<string, FlagSpec<unknown>>
|
|
|
1542
1647
|
readonly exitCodes?: Readonly<Record<TCode, string>>;
|
|
1543
1648
|
readonly managesCredentials?: TManagesCredentials;
|
|
1544
1649
|
readonly installsPackages?: TInstallsPackages;
|
|
1650
|
+
readonly statements?: Readonly<Record<string, StatementSpec>>;
|
|
1545
1651
|
readonly handler: Handler<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
|
|
1546
1652
|
} & SpawnDeclarations): CommandDefinition<TFlags, TPositionals, TConfig, TCode, TManagesCredentials, TInstallsPackages>;
|
|
1547
1653
|
/**
|
|
@@ -1729,4 +1835,4 @@ interface TelemetryDeclaration {
|
|
|
1729
1835
|
readonly docsUrl: string;
|
|
1730
1836
|
}
|
|
1731
1837
|
//#endregion
|
|
1732
|
-
export {
|
|
1838
|
+
export { defineConfigSection as $, ManagementApiClientConfig as $t, StatementAnswer as A, PackageManagerRunResult as At, PresentedResult as B, positional as Bt, defineServerCommand as C, SpawnChild as Ct, OpenUrlOutcome as D, exitWithChildStatus as Dt, CommandContext as E, SpawnedChild as Et, Block as F, Char as Ft, TreeNode as G, CredentialManager as Gt, Status as H, ActiveCredential as Ht, Format as I, CommandArgs as It, Severity as J, Session as Jt, Ui as K, CredentialOrigin as Kt, Outcome as L, FlagSpec as Lt, StatementQuestion as M, PackageOperations as Mt, StatementSurface as N, Args as Nt, OpenUrlRequest as O, PackageManagerId as Ot, StatementsOptions as P, ArgsSpec as Pt, SectionValidation as Q, ManagementApiClient$1 as Qt, PRESENTED as R, PositionalSpec as Rt, defineCommand as S, ExitWithChildStatusOptions as St, BrowserWaitRequest as T, SpawnRequest as Tt, Text as U, Credential as Ut, Span as V, ActiveAccessTokenOptions as Vt, Tone as W, CredentialIdentity as Wt, StreamMeta as X, CredentialRefreshResult as Xt, StreamEvent as Y, StoredSessions as Yt, ConfigSection as Z, CredentialRefresher as Zt, ServerCommandDefinition as _, TelemetryPayload as _t, RedirectSpec as a, ResolvedSection as at, StatementSpec as b, ChildResult as bt, CommandDefinition as c, resolveSectionPath as ct, CommandNeeds as d, InputStream as dt, TokenStorage$1 as en, ConfigSchema as et, CompletedEnvelope as f, LoadedConfig as ft, NeedsSpec as g, Runtime as gt, HelpSpec as h, PRISMA_CONFIG_VERSION as ht, MountedTree as i, validateSectionWithSchema as it, StatementOptions as j, PackageManagerRunner as jt, PromptSurface as k, PackageManagerRunRequest as kt, CommandHandler as l, Host as lt, Handler as m, OutputStream as mt, CommandFamily as n, configSchema as nt, defineCommandFamily as o, SectionProvenance as ot, ErroredEnvelope as p, LoadedConfigFile as pt, EngineEvent as q, SERVICE_TOKEN_ENV_VAR as qt, CommandRedirect as r, reference as rt, AnyCommand as s, resolveSectionOverChain as st, TelemetryDeclaration as t, ConfigSchemaValue as tt, CommandHelp as u, HostProcess as ut, SessionCommandDefinition as v, EngineCommandSnapshot as vt, defineSessionCommand as w, SpawnOptions as wt, WorkflowStep as x, ChildStatusSettlement as xt, SpawnDeclarations as y, RunSummary as yt, Presentations as z, flag as zt };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $t as ManagementApiClientConfig, B as PresentedResult, Ct as SpawnChild, Gt as CredentialManager, Ht as ActiveCredential, Jt as Session, Ot as PackageManagerId, Qt as ManagementApiClient, Tt as SpawnRequest, Ut as Credential, Vt as ActiveAccessTokenOptions, Y as StreamEvent, Yt as StoredSessions, Zt as CredentialRefresher, _t as TelemetryPayload, bt as ChildResult, en as TokenStorage, gt as Runtime, i as MountedTree, jt as PackageManagerRunner, lt as Host, n as CommandFamily, q as EngineEvent, t as TelemetryDeclaration, x as WorkflowStep, yt as RunSummary } from "./report-CQ30sy_e.js";
|
|
2
2
|
|
|
3
3
|
//#region src/in-memory-credential-manager.d.ts
|
|
4
4
|
/** A stored session with its credential material — what the manager
|
package/dist/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as credentialWorkspaceId, D as credentialsRequiredError, E as credentialWorkspaceMismatchError, S as claimedIdentity, b as readActiveAccessToken, k as noSessionForWorkspaceError, t as buildEngine, x as claimedExpiresAt } from "./engine-
|
|
1
|
+
import { C as credentialWorkspaceId, D as credentialsRequiredError, E as credentialWorkspaceMismatchError, S as claimedIdentity, b as readActiveAccessToken, k as noSessionForWorkspaceError, t as buildEngine, x as claimedExpiresAt } from "./engine-DVJ5Ie5H.js";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
//#region src/in-memory-credential-manager.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/cli-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The execution engine of the unified Prisma CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@prisma/management-api-sdk": "1.80.0",
|
|
56
|
-
"@repo/cli-conformance": "8.0.0-rc.
|
|
57
|
-
"@repo/tsconfig": "8.0.0-rc.
|
|
56
|
+
"@repo/cli-conformance": "8.0.0-rc.21-dev.143",
|
|
57
|
+
"@repo/tsconfig": "8.0.0-rc.21-dev.143",
|
|
58
58
|
"@types/node": "^22.19.19",
|
|
59
59
|
"ci-info": "^4.3.1",
|
|
60
60
|
"tsdown": "^0.21.10",
|