@prisma/cli 3.0.0-alpha.9 → 3.0.0-beta.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.
@@ -1,9 +1,15 @@
1
- import { CliError } from "./errors.js";
1
+ import { CliError, authRequiredError } from "./errors.js";
2
2
  import { cliErrorToJson, writeHumanError, writeHumanLines, writeJsonError, writeJsonEvent, writeJsonSuccess } from "./output.js";
3
3
  import { getCommandDescriptor } from "./command-meta.js";
4
4
  import { resolveGlobalFlags } from "./global-flags.js";
5
5
  import { createCommandContext } from "./runtime.js";
6
+ import { AuthError } from "@prisma/management-api-sdk";
6
7
  //#region src/shell/command-runner.ts
8
+ function toCliError(error) {
9
+ if (error instanceof CliError) return error;
10
+ if (error instanceof AuthError) return authRequiredError(["prisma-cli auth login"], { debug: error.message });
11
+ return null;
12
+ }
7
13
  async function runCommand(runtime, commandName, options, handler, presenter) {
8
14
  const flags = resolveGlobalFlags(runtime.argv, options);
9
15
  const context = await createCommandContext(runtime, flags);
@@ -20,10 +26,11 @@ async function runCommand(runtime, commandName, options, handler, presenter) {
20
26
  if (flags.quiet) return;
21
27
  writeHumanLines(context.output, presenter.renderHuman(context, descriptor, success.result));
22
28
  } catch (error) {
23
- if (error instanceof CliError) {
24
- if (flags.json) writeJsonError(context.output, commandName, error);
25
- else writeHumanError(context.output, context.ui, error, { trace: flags.trace });
26
- process.exitCode = error.exitCode;
29
+ const cliError = toCliError(error);
30
+ if (cliError) {
31
+ if (flags.json) writeJsonError(context.output, commandName, cliError);
32
+ else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
33
+ process.exitCode = cliError.exitCode;
27
34
  return;
28
35
  }
29
36
  throw error;
@@ -40,20 +47,23 @@ async function runStreamingCommand(runtime, commandName, options, handler) {
40
47
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
41
48
  result: null,
42
49
  warnings: [],
43
- nextSteps: []
50
+ nextSteps: [],
51
+ nextActions: []
44
52
  });
45
53
  } catch (error) {
46
- if (error instanceof CliError) {
54
+ const cliError = toCliError(error);
55
+ if (cliError) {
47
56
  if (flags.json) writeJsonEvent(context.output, {
48
57
  type: "error",
49
58
  command: commandName,
50
59
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
51
- error: cliErrorToJson(error),
60
+ error: cliErrorToJson(cliError),
52
61
  warnings: [],
53
- nextSteps: error.nextSteps
62
+ nextSteps: cliError.nextSteps,
63
+ nextActions: cliError.nextActions
54
64
  });
55
- else writeHumanError(context.output, context.ui, error, { trace: flags.trace });
56
- process.exitCode = error.exitCode;
65
+ else writeHumanError(context.output, context.ui, cliError, { trace: flags.trace });
66
+ process.exitCode = cliError.exitCode;
57
67
  return;
58
68
  }
59
69
  throw error;
@@ -12,6 +12,7 @@ var CliError = class extends Error {
12
12
  docsUrl;
13
13
  exitCode;
14
14
  nextSteps;
15
+ nextActions;
15
16
  humanLines;
16
17
  constructor(options) {
17
18
  super(options.summary);
@@ -28,6 +29,7 @@ var CliError = class extends Error {
28
29
  this.docsUrl = options.docsUrl ?? null;
29
30
  this.exitCode = options.exitCode ?? 1;
30
31
  this.nextSteps = options.nextSteps ?? [];
32
+ this.nextActions = options.nextActions ?? [];
31
33
  this.humanLines = options.humanLines && options.humanLines.length > 0 ? [...options.humanLines] : null;
32
34
  }
33
35
  };
@@ -42,13 +44,14 @@ function usageError(summary, why, fix, nextSteps = [], domain = "cli") {
42
44
  nextSteps
43
45
  });
44
46
  }
45
- function authRequiredError(nextSteps = ["prisma-cli auth login"]) {
47
+ function authRequiredError(nextSteps = ["prisma-cli auth login"], options = {}) {
46
48
  return new CliError({
47
49
  code: "AUTH_REQUIRED",
48
50
  domain: "auth",
49
51
  summary: "Authentication required",
50
52
  why: "This command needs an authenticated session.",
51
53
  fix: "Run prisma-cli auth login, or rerun the command in a TTY to sign in interactively.",
54
+ debug: options.debug,
52
55
  exitCode: 1,
53
56
  nextSteps
54
57
  });
@@ -3,6 +3,7 @@ import { renderNextSteps, renderSummaryLine } from "./ui.js";
3
3
  function writeJsonSuccess(output, success) {
4
4
  output.stdout.write(`${JSON.stringify({
5
5
  ok: true,
6
+ nextActions: [],
6
7
  ...success
7
8
  }, null, 2)}\n`);
8
9
  }
@@ -28,7 +29,8 @@ function writeJsonError(output, command, error) {
28
29
  command,
29
30
  error: cliErrorToJson(error),
30
31
  warnings: [],
31
- nextSteps: error.nextSteps
32
+ nextSteps: error.nextSteps,
33
+ nextActions: error.nextActions
32
34
  }, null, 2)}\n`);
33
35
  }
34
36
  function writeHumanLines(output, lines) {
@@ -45,7 +45,8 @@ async function resolveCurrentAuthState(dependencies) {
45
45
  authenticated: false,
46
46
  provider: null,
47
47
  user: null,
48
- workspace: null
48
+ workspace: null,
49
+ credential: null
49
50
  };
50
51
  const provider = dependencies.identityGateway.getProvider(session.provider);
51
52
  const user = dependencies.identityGateway.getUser(session.userId);
@@ -54,13 +55,23 @@ async function resolveCurrentAuthState(dependencies) {
54
55
  authenticated: false,
55
56
  provider: null,
56
57
  user: null,
57
- workspace: null
58
+ workspace: null,
59
+ credential: null
58
60
  };
59
61
  return {
60
62
  authenticated: true,
61
63
  provider: provider.id,
62
- user: { email: user.email },
63
- workspace
64
+ user: {
65
+ id: user.id,
66
+ email: user.email,
67
+ name: user.name
68
+ },
69
+ workspace,
70
+ credential: {
71
+ type: "oauth",
72
+ id: null,
73
+ name: null
74
+ }
64
75
  };
65
76
  }
66
77
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prisma/cli",
3
- "version": "3.0.0-alpha.9",
4
- "description": "Preview of the unified Prisma CLI.",
3
+ "version": "3.0.0-beta.1",
4
+ "description": "Command-line interface for the Prisma Developer Platform.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "prisma-cli": "./dist/cli.js"
@@ -36,10 +36,10 @@
36
36
  "license": "Apache-2.0",
37
37
  "dependencies": {
38
38
  "@clack/prompts": "^1.2.0",
39
- "@prisma/compute-sdk": "^0.18.0",
39
+ "@prisma/compute-sdk": "^0.19.0",
40
40
  "c12": "4.0.0-beta.4",
41
41
  "@prisma/credentials-store": "^7.7.0",
42
- "@prisma/management-api-sdk": "^1.27.0",
42
+ "@prisma/management-api-sdk": "^1.34.0",
43
43
  "colorette": "^2.0.20",
44
44
  "commander": "^12.1.0",
45
45
  "magicast": "^0.3.5",