@prisma/cli-engine 0.7.0 → 0.8.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 CHANGED
@@ -10,6 +10,20 @@ 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
+ ## Mounting commands
14
+
15
+ `createCli` takes commands by path. Every path with more than one word needs its group declared in `groups`, and the group's `brief` is its row on the parent's help card. A path can be a command and a group at once:
16
+
17
+ ```ts
18
+ createCli({
19
+ groups: { dev: { brief: "Run the app locally. Start it, print URLs, stop it" } },
20
+ commands: { dev, "dev url": devUrl, "dev stop": devStop },
21
+ // ...
22
+ });
23
+ ```
24
+
25
+ `dev module.ts` runs `dev` with the positional `module.ts`, and `dev url gateway` runs `dev url`. When the word after `dev` names a command beneath it, that command runs, so `dev url` never reaches `dev` as a positional. To pass such a word as the positional, put `--` before it: `dev -- url` runs `dev` with `url`. A retired path declared as a redirect, such as `dev up`, wins over the positional the same way. `dev --help` shows the `dev` command's help and lists `url` and `stop`.
26
+
13
27
  ## Statement prompts
14
28
 
15
29
  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.
@@ -2183,17 +2183,19 @@ function statementBrief(verb, spec) {
2183
2183
  return spec.brief ?? `Say what happens to <subject>: ${verb}, instead of being asked (repeatable)`;
2184
2184
  }
2185
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. */
2186
+ * leading words, group by group, until one names a command. A group
2187
+ * with its own command routes to it at the first word that names no
2188
+ * child. Like the parser, a kebab-case word matches a camelCase name. */
2188
2189
  function routedCommand(tree, argv) {
2189
2190
  let node = tree;
2190
2191
  for (const token of argv) {
2191
2192
  const entry = node.commands.get(token) ?? node.commands.get(camelCase(token));
2192
2193
  if (entry !== void 0) return entry;
2193
2194
  const child = node.children.get(token) ?? node.children.get(camelCase(token));
2194
- if (child === void 0) return;
2195
+ if (child === void 0) return node.ownCommand;
2195
2196
  node = child;
2196
2197
  }
2198
+ return node.ownCommand;
2197
2199
  }
2198
2200
  function statementFlagIn(token, statements) {
2199
2201
  if (!token.startsWith("--")) return;
@@ -2323,30 +2325,43 @@ function validateSpawnDeclarations(path, def) {
2323
2325
  }
2324
2326
  function emptyNode() {
2325
2327
  return {
2328
+ ownCommand: void 0,
2326
2329
  commands: /* @__PURE__ */ new Map(),
2327
2330
  children: /* @__PURE__ */ new Map()
2328
2331
  };
2329
2332
  }
2330
- function insertCommand(root, path, def, docsBaseUrl) {
2333
+ function childNode(node, segment) {
2334
+ let child = node.children.get(segment);
2335
+ if (child === void 0) {
2336
+ child = emptyNode();
2337
+ node.children.set(segment, child);
2338
+ }
2339
+ return child;
2340
+ }
2341
+ /** Every path some other mounted path extends: `dev` when `dev url` is
2342
+ * mounted. */
2343
+ function groupPathsOf(paths) {
2344
+ const groups = /* @__PURE__ */ new Set();
2345
+ for (const path of paths) {
2346
+ const segments = path.split(" ");
2347
+ for (let depth = 1; depth < segments.length; depth += 1) groups.add(segments.slice(0, depth).join(" "));
2348
+ }
2349
+ return groups;
2350
+ }
2351
+ /** A path that is also a group keeps its command on the group's node,
2352
+ * so the node's children and its own command meet in one place. */
2353
+ function insertCommand(root, path, def, docsBaseUrl, isGroup) {
2331
2354
  const segments = path.split(" ");
2332
2355
  if (segments.some((segment) => segment.length === 0)) throw constructionError(`invalid command path '${path}'`);
2333
- let node = root;
2334
- for (const segment of segments.slice(0, -1)) {
2335
- if (node.commands.has(segment)) throw constructionError(`command path '${path}' collides with a command mounted at a prefix of it`);
2336
- let child = node.children.get(segment);
2337
- if (child === void 0) {
2338
- child = emptyNode();
2339
- node.children.set(segment, child);
2340
- }
2341
- node = child;
2342
- }
2343
- const leaf = segments[segments.length - 1];
2344
- if (node.commands.has(leaf) || node.children.has(leaf)) throw constructionError(`command path '${path}' collides with another mounted command`);
2345
- node.commands.set(leaf, {
2356
+ const entry = {
2346
2357
  def,
2347
2358
  id: segments.join("."),
2348
2359
  docsBaseUrl
2349
- });
2360
+ };
2361
+ const parent = segments.slice(0, -1).reduce((node, segment) => childNode(node, segment), root);
2362
+ const leaf = segments[segments.length - 1];
2363
+ if (isGroup) childNode(parent, leaf).ownCommand = entry;
2364
+ else parent.commands.set(leaf, entry);
2350
2365
  }
2351
2366
  /** A command belongs to the family whose commands record contains it
2352
2367
  * (identity). Harness-mounted commands with no family are unowned. */
@@ -2389,6 +2404,7 @@ function buildCommandTree(spec) {
2389
2404
  if (paths.length === 0) throw constructionError("createCli requires at least one mounted command");
2390
2405
  validateDocsBaseUrls(spec);
2391
2406
  validateConfigSectionNames(spec);
2407
+ const groupPaths = groupPathsOf(paths);
2392
2408
  const root = emptyNode();
2393
2409
  for (const path of paths) {
2394
2410
  const def = spec.commands[path];
@@ -2403,7 +2419,7 @@ function buildCommandTree(spec) {
2403
2419
  const groupPath = segments.slice(0, depth).join(" ");
2404
2420
  if (spec.groups[groupPath] === void 0) throw constructionError(`command path '${path}' references unknown group '${groupPath}' (declare it in createCli's groups)`);
2405
2421
  }
2406
- insertCommand(root, path, def, commandFamilyOf(spec, def)?.docsBaseUrl);
2422
+ insertCommand(root, path, def, commandFamilyOf(spec, def)?.docsBaseUrl, groupPaths.has(path));
2407
2423
  }
2408
2424
  return root;
2409
2425
  }
@@ -2732,15 +2748,30 @@ function toStricliCommand(entry, cliName, runEntry) {
2732
2748
  docs: commandDocs(entry.def, cliName)
2733
2749
  });
2734
2750
  }
2751
+ /** The route a group's own command sits under, hidden from listings.
2752
+ * A child's name is one path segment and never contains a space, so no
2753
+ * child can take this name. A user can still type it, so it is dropped
2754
+ * from the path the parser reports. */
2755
+ const OWN_COMMAND_ROUTE = "<own command>";
2735
2756
  function buildRoutes(spec, node, groupPath, runEntry) {
2736
2757
  const routes = {};
2758
+ if (node.ownCommand !== void 0) routes[OWN_COMMAND_ROUTE] = toStricliCommand(node.ownCommand, spec.name, runEntry);
2737
2759
  for (const [name, entry] of node.commands) routes[name] = toStricliCommand(entry, spec.name, runEntry);
2738
2760
  for (const [name, child] of node.children) routes[name] = buildRoutes(spec, child, groupPath === "" ? name : `${groupPath} ${name}`, runEntry);
2761
+ const docs = groupPath === "" ? { brief: spec.name } : {
2762
+ brief: spec.groups[groupPath].brief,
2763
+ fullDescription: spec.groups[groupPath].description
2764
+ };
2765
+ if (node.ownCommand === void 0) return buildRouteMap({
2766
+ routes,
2767
+ docs
2768
+ });
2739
2769
  return buildRouteMap({
2740
2770
  routes,
2741
- docs: groupPath === "" ? { brief: spec.name } : {
2742
- brief: spec.groups[groupPath].brief,
2743
- fullDescription: spec.groups[groupPath].description
2771
+ defaultCommand: OWN_COMMAND_ROUTE,
2772
+ docs: {
2773
+ ...docs,
2774
+ hideRoute: { [OWN_COMMAND_ROUTE]: true }
2744
2775
  }
2745
2776
  });
2746
2777
  }
@@ -5000,7 +5031,8 @@ function helpPath(argv) {
5000
5031
  return segments;
5001
5032
  }
5002
5033
  /** Walks as far as the segments stay recognized; help for `project
5003
- * frobnicate` is project's help, not a dead end. */
5034
+ * frobnicate` is project's help, not a dead end. A group with its own
5035
+ * command answers with that command's help. */
5004
5036
  function resolveTarget(root, segments) {
5005
5037
  let node = root;
5006
5038
  const path = [];
@@ -5008,8 +5040,9 @@ function resolveTarget(root, segments) {
5008
5040
  const entry = node.commands.get(segment);
5009
5041
  if (entry !== void 0) return {
5010
5042
  target: {
5011
- kind: "leaf",
5012
- entry
5043
+ kind: "command",
5044
+ entry,
5045
+ subcommands: void 0
5013
5046
  },
5014
5047
  path: [...path, segment]
5015
5048
  };
@@ -5018,6 +5051,14 @@ function resolveTarget(root, segments) {
5018
5051
  node = child;
5019
5052
  path.push(segment);
5020
5053
  }
5054
+ if (node.ownCommand !== void 0) return {
5055
+ target: {
5056
+ kind: "command",
5057
+ entry: node.ownCommand,
5058
+ subcommands: node
5059
+ },
5060
+ path
5061
+ };
5021
5062
  return {
5022
5063
  target: {
5023
5064
  kind: "node",
@@ -5029,8 +5070,9 @@ function resolveTarget(root, segments) {
5029
5070
  /** A BARE group invocation (`prisma-cli project`, or no argv at all)
5030
5071
  * is a help request; anything carrying flags or extra tokens is not —
5031
5072
  * `cli --unknown` and `cli project --frobnicate` must reach routing
5032
- * and usage validation, not exit 0 with a help card. A bare leaf is a
5033
- * command run and is left alone. The format-selection flags do not
5073
+ * and usage validation, not exit 0 with a help card. A bare leaf, or
5074
+ * a bare group with its own command, is a command run and is left
5075
+ * alone. The format-selection flags do not
5034
5076
  * count: `cli project --format markdown` asks for the group's help in
5035
5077
  * Markdown. */
5036
5078
  function bareGroupInvocation(root, rawArgv) {
@@ -5051,7 +5093,7 @@ function renderHelp(spec, root, argv, options, out) {
5051
5093
  }
5052
5094
  function helpCard(spec, root, argv) {
5053
5095
  const { target, path } = resolveTarget(root, helpPath(argv));
5054
- return target.kind === "leaf" ? leafCard(spec, target.entry, path) : nodeCard(spec, target.node, path);
5096
+ return target.kind === "command" ? leafCard(spec, target.entry, target.subcommands, path) : nodeCard(spec, target.node, path);
5055
5097
  }
5056
5098
  function nodeCard(spec, node, path) {
5057
5099
  const atRoot = path.length === 0;
@@ -5073,7 +5115,7 @@ function nodeCard(spec, node, path) {
5073
5115
  docsUrl: atRoot ? spec.help?.docsUrl : void 0
5074
5116
  };
5075
5117
  }
5076
- function leafCard(spec, entry, path) {
5118
+ function leafCard(spec, entry, subcommands, path) {
5077
5119
  const def = entry.def;
5078
5120
  const usage = [
5079
5121
  spec.name,
@@ -5089,7 +5131,7 @@ function leafCard(spec, entry, path) {
5089
5131
  tagline: def.help.summary,
5090
5132
  usage,
5091
5133
  description: def.help.description,
5092
- commands: [],
5134
+ commands: subcommands === void 0 ? [] : nodeRows(spec, subcommands, path),
5093
5135
  workflow: [],
5094
5136
  arguments: Object.values(def.args.positionals).map((spec) => positionalRuntime(spec)).map((runtime) => ({
5095
5137
  name: runtime.placeholder,
@@ -5124,6 +5166,7 @@ function renderHelpTerminal(card, paint) {
5124
5166
  lines.push(rail(paint));
5125
5167
  proseLines(card.description, paint, lines);
5126
5168
  }
5169
+ if (card.kind === "leaf") rowSection("Commands", card.commands, paint, lines);
5127
5170
  workflowLines(card.workflow, paint, lines);
5128
5171
  rowSection("Arguments", card.arguments, paint, lines);
5129
5172
  rowSection("Options", card.options, paint, lines);
@@ -5647,7 +5690,7 @@ function settleCommandMoved(spec, invocation, redirect, commandId) {
5647
5690
  }
5648
5691
  /** The command path stricli resolved, without the binary name. */
5649
5692
  function commandSegments(spec, prefix) {
5650
- return prefix[0] === spec.name ? prefix.slice(1) : prefix;
5693
+ return (prefix[0] === spec.name ? prefix.slice(1) : prefix).filter((segment) => segment !== OWN_COMMAND_ROUTE);
5651
5694
  }
5652
5695
  /** Maps stricli's own settlement (parse/route failures, framework bugs)
5653
5696
  * onto the engine protocol when the pipeline never settled. A failure
@@ -5859,6 +5902,13 @@ var EngineImpl = class {
5859
5902
  }, stream);
5860
5903
  return 0;
5861
5904
  }
5905
+ const retired = this.retiredPathBeneathCommand(argv);
5906
+ if (retired !== void 0) {
5907
+ unsubscribe();
5908
+ const exitCode = settleCommandMoved(this.spec, invocation, retired, retired.from.replaceAll(" ", "."));
5909
+ this.fireOnSettled(invocation, exitCode, startedAtMs);
5910
+ return exitCode;
5911
+ }
5862
5912
  const stricliArgv = this.takeStatementFlags(invocation, argv, startedAtMs);
5863
5913
  if (stricliArgv === void 0) {
5864
5914
  unsubscribe();
@@ -5925,6 +5975,16 @@ var EngineImpl = class {
5925
5975
  state.statementValues = extraction.values;
5926
5976
  return extraction.argv;
5927
5977
  }
5978
+ /** A retired path beneath a mounted command, such as `dev up` beside
5979
+ * `dev`. The parser would hand `up` to `dev` as a positional, so the
5980
+ * redirect is matched first: a retired child's name wins over the
5981
+ * positional, as a live child's name does. */
5982
+ retiredPathBeneathCommand(argv) {
5983
+ const routed = routedCommand(this.tree, argv);
5984
+ if (routed === void 0) return;
5985
+ const redirect = matchVerbRedirect(this.redirects, attemptedPath(argv));
5986
+ return redirect !== void 0 && redirect.from.split(" ").length > routed.id.split(".").length ? redirect : void 0;
5987
+ }
5928
5988
  /** stricli routed or parsed nothing runnable. When the redirect table
5929
5989
  * claims the invocation the user typed, the run names its
5930
5990
  * replacement; otherwise it settles as the usage error it is. */
package/dist/index.d.ts CHANGED
@@ -37,8 +37,10 @@ interface Cli {
37
37
  run(argv: readonly string[], runtime: Runtime, hooks?: CliRunHooks): Promise<number>;
38
38
  }
39
39
  /**
40
- * Shell-side construction. Group help is declared with the mount.
41
- * Collisions, unknown groups, reserved-flag violations, grammar
40
+ * Shell-side construction. Group help is declared with the mount. A
41
+ * path may be both a command and a group (`dev` beside `dev url`); a
42
+ * child's name wins over the command's positional. Redirects onto
43
+ * mounted paths, unknown groups, reserved-flag violations, grammar
42
44
  * violations, and foreign-section references fail construction (build
43
45
  * time, not run time).
44
46
  */
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
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-DVJ5Ie5H.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-BE7WKK2X.js";
3
3
  import { dirname, isAbsolute, resolve } from "node:path";
4
4
  import { scope, type } from "arktype";
5
5
  //#region src/cli.ts
6
6
  /**
7
- * Shell-side construction. Group help is declared with the mount.
8
- * Collisions, unknown groups, reserved-flag violations, grammar
7
+ * Shell-side construction. Group help is declared with the mount. A
8
+ * path may be both a command and a group (`dev` beside `dev url`); a
9
+ * child's name wins over the command's positional. Redirects onto
10
+ * mounted paths, unknown groups, reserved-flag violations, grammar
9
11
  * violations, and foreign-section references fail construction (build
10
12
  * time, not run time).
11
13
  */
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-DVJ5Ie5H.js";
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-BE7WKK2X.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.7.0",
3
+ "version": "0.8.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.21-dev.143",
57
- "@repo/tsconfig": "8.0.0-rc.21-dev.143",
56
+ "@repo/cli-conformance": "8.0.0-rc.23-dev.152",
57
+ "@repo/tsconfig": "8.0.0-rc.23-dev.152",
58
58
  "@types/node": "^22.19.19",
59
59
  "ci-info": "^4.3.1",
60
60
  "tsdown": "^0.21.10",