@prisma/cli 3.0.0-dev.99.1 → 8.0.0-rc.2
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 +3 -1
- package/dist/cli.js +15115 -16
- package/dist/deploy-framework-C7bQM00A.js +23 -0
- package/dist/payload-B88Qvzxk-CrtTXSOe.js +34 -0
- package/dist/sender.js +192 -0
- package/package.json +22 -18
- package/dist/adapters/git.js +0 -54
- package/dist/adapters/local-state.js +0 -144
- package/dist/adapters/mock-api.js +0 -136
- package/dist/adapters/token-storage.js +0 -418
- package/dist/cli2.js +0 -119
- package/dist/commands/app/index.js +0 -345
- package/dist/commands/auth/index.js +0 -96
- package/dist/commands/branch/index.js +0 -27
- package/dist/commands/database/index.js +0 -159
- package/dist/commands/env.js +0 -99
- package/dist/commands/git/index.js +0 -36
- package/dist/commands/project/index.js +0 -69
- package/dist/commands/version/index.js +0 -18
- package/dist/controllers/app-env-api.js +0 -54
- package/dist/controllers/app-env-file.js +0 -181
- package/dist/controllers/app-env.js +0 -502
- package/dist/controllers/app.js +0 -2443
- package/dist/controllers/auth.js +0 -316
- package/dist/controllers/branch.js +0 -103
- package/dist/controllers/database.js +0 -318
- package/dist/controllers/project.js +0 -731
- package/dist/controllers/select-prompt-port.js +0 -12
- package/dist/controllers/version.js +0 -12
- package/dist/lib/app/app-interaction.js +0 -5
- package/dist/lib/app/app-provider.js +0 -544
- package/dist/lib/app/branch-database-api.js +0 -102
- package/dist/lib/app/branch-database-deploy.js +0 -325
- package/dist/lib/app/branch-database.js +0 -215
- package/dist/lib/app/build-settings.js +0 -93
- package/dist/lib/app/build.js +0 -80
- package/dist/lib/app/bun-project.js +0 -45
- package/dist/lib/app/compute-config.js +0 -147
- package/dist/lib/app/deploy-output.js +0 -24
- package/dist/lib/app/deploy-plan.js +0 -58
- package/dist/lib/app/deploy-progress.js +0 -100
- package/dist/lib/app/domain-guidance.js +0 -14
- package/dist/lib/app/env-config.js +0 -67
- package/dist/lib/app/env-file.js +0 -82
- package/dist/lib/app/env-vars.js +0 -50
- package/dist/lib/app/local-dev.js +0 -109
- package/dist/lib/app/production-deploy-gate.js +0 -161
- package/dist/lib/app/read-branch.js +0 -30
- package/dist/lib/auth/auth-ops.js +0 -158
- package/dist/lib/auth/client.js +0 -22
- package/dist/lib/auth/guard.js +0 -38
- package/dist/lib/auth/login.js +0 -330
- package/dist/lib/database/provider.js +0 -167
- package/dist/lib/diagnostics.js +0 -15
- package/dist/lib/fs/home-path.js +0 -24
- package/dist/lib/git/local-branch.js +0 -53
- package/dist/lib/git/local-status.js +0 -57
- package/dist/lib/project/interactive-setup.js +0 -56
- package/dist/lib/project/local-pin.js +0 -200
- package/dist/lib/project/resolution.js +0 -386
- package/dist/lib/project/setup.js +0 -135
- package/dist/lib/version.js +0 -55
- package/dist/output/patterns.js +0 -90
- package/dist/presenters/app-env.js +0 -265
- package/dist/presenters/app.js +0 -646
- package/dist/presenters/auth.js +0 -183
- package/dist/presenters/branch.js +0 -46
- package/dist/presenters/database.js +0 -274
- package/dist/presenters/project.js +0 -174
- package/dist/presenters/verbose-context.js +0 -64
- package/dist/presenters/version.js +0 -29
- package/dist/shell/command-arguments.js +0 -6
- package/dist/shell/command-meta.js +0 -622
- package/dist/shell/command-runner.js +0 -112
- package/dist/shell/diagnostics-output.js +0 -57
- package/dist/shell/errors.js +0 -134
- package/dist/shell/global-flags.js +0 -37
- package/dist/shell/help.js +0 -89
- package/dist/shell/output.js +0 -82
- package/dist/shell/prompt.js +0 -41
- package/dist/shell/runtime.js +0 -55
- package/dist/shell/ui.js +0 -116
- package/dist/shell/update-check.js +0 -247
- package/dist/use-cases/auth.js +0 -145
- package/dist/use-cases/branch.js +0 -47
- package/dist/use-cases/create-cli-gateways.js +0 -68
- package/dist/use-cases/project.js +0 -30
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { usageError } from "../../shell/errors.js";
|
|
2
|
-
import { selectPrompt, textPrompt } from "../../shell/prompt.js";
|
|
3
|
-
import { inferTargetName, sortProjects } from "./resolution.js";
|
|
4
|
-
import { toProjectSummary, validateProjectSetupNameText } from "./setup.js";
|
|
5
|
-
//#region src/lib/project/interactive-setup.ts
|
|
6
|
-
async function promptForProjectSetupChoice(options) {
|
|
7
|
-
const sortedProjects = sortProjects(options.projects);
|
|
8
|
-
const projectNames = sortedProjects.map((project) => project.name);
|
|
9
|
-
const duplicateNames = new Set(projectNames.filter((name, index) => projectNames.indexOf(name) !== index));
|
|
10
|
-
const choice = await selectPrompt({
|
|
11
|
-
input: options.context.runtime.stdin,
|
|
12
|
-
output: options.context.runtime.stderr,
|
|
13
|
-
message: "Which Project should this directory use?",
|
|
14
|
-
choices: [
|
|
15
|
-
...sortedProjects.map((project) => ({
|
|
16
|
-
label: duplicateNames.has(project.name) ? `${project.name} (${project.id})` : project.name,
|
|
17
|
-
value: {
|
|
18
|
-
kind: "project",
|
|
19
|
-
project
|
|
20
|
-
}
|
|
21
|
-
})),
|
|
22
|
-
{
|
|
23
|
-
label: "Create a new Project",
|
|
24
|
-
value: { kind: "create" }
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
label: "Cancel",
|
|
28
|
-
value: { kind: "cancel" }
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
});
|
|
32
|
-
if (choice.kind === "cancel") throw usageError("Project setup canceled", options.cancel.why, options.cancel.fix, options.cancel.nextSteps, "project");
|
|
33
|
-
if (choice.kind === "project") return {
|
|
34
|
-
project: toProjectSummary(choice.project),
|
|
35
|
-
action: "linked",
|
|
36
|
-
targetName: choice.project.name,
|
|
37
|
-
targetNameSource: "prompt"
|
|
38
|
-
};
|
|
39
|
-
const suggestedName = await inferTargetName(options.context.runtime.cwd, options.context.runtime.signal);
|
|
40
|
-
const rawName = await textPrompt({
|
|
41
|
-
input: options.context.runtime.stdin,
|
|
42
|
-
output: options.context.runtime.stderr,
|
|
43
|
-
message: "Project name",
|
|
44
|
-
placeholder: suggestedName.name,
|
|
45
|
-
validate: (value) => validateProjectSetupNameText(value, suggestedName.name)
|
|
46
|
-
});
|
|
47
|
-
const projectName = rawName.trim() || suggestedName.name;
|
|
48
|
-
return {
|
|
49
|
-
project: toProjectSummary(await options.createProject(projectName)),
|
|
50
|
-
action: "created",
|
|
51
|
-
targetName: projectName,
|
|
52
|
-
targetNameSource: rawName.trim() ? "prompt" : suggestedName.source
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
//#endregion
|
|
56
|
-
export { promptForProjectSetupChoice };
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { Result, TaggedError, UnhandledException } from "better-result";
|
|
4
|
-
//#region src/lib/project/local-pin.ts
|
|
5
|
-
const LOCAL_RESOLUTION_PIN_RELATIVE_PATH = ".prisma/local.json";
|
|
6
|
-
var LocalResolutionPinInvalidJsonError = class extends TaggedError("LocalResolutionPinInvalidJsonError")() {
|
|
7
|
-
constructor(cause) {
|
|
8
|
-
super({
|
|
9
|
-
message: `${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} contains invalid JSON.`,
|
|
10
|
-
cause,
|
|
11
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
var LocalResolutionPinInvalidShapeError = class extends TaggedError("LocalResolutionPinInvalidShapeError")() {
|
|
16
|
-
constructor() {
|
|
17
|
-
super({
|
|
18
|
-
message: `${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} must contain workspaceId and projectId string fields only.`,
|
|
19
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var LocalResolutionPinReadAbortedError = class extends TaggedError("LocalResolutionPinReadAbortedError")() {
|
|
24
|
-
constructor(cause) {
|
|
25
|
-
super({
|
|
26
|
-
message: `Reading ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} was aborted.`,
|
|
27
|
-
cause,
|
|
28
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
var LocalResolutionPinSerializationError = class extends TaggedError("LocalResolutionPinSerializationError")() {
|
|
33
|
-
constructor(cause) {
|
|
34
|
-
super({
|
|
35
|
-
message: `Could not serialize ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH}.`,
|
|
36
|
-
cause,
|
|
37
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var LocalResolutionPinWriteAbortedError = class extends TaggedError("LocalResolutionPinWriteAbortedError")() {
|
|
42
|
-
constructor(cause) {
|
|
43
|
-
super({
|
|
44
|
-
message: `Writing ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} was aborted.`,
|
|
45
|
-
cause,
|
|
46
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var LocalResolutionPinWriteFailedError = class extends TaggedError("LocalResolutionPinWriteFailedError")() {
|
|
51
|
-
constructor(operation, cause) {
|
|
52
|
-
super({
|
|
53
|
-
message: `Could not write ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH}.`,
|
|
54
|
-
cause,
|
|
55
|
-
operation,
|
|
56
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var LocalResolutionPinGitignoreUpdateAbortedError = class extends TaggedError("LocalResolutionPinGitignoreUpdateAbortedError")() {
|
|
61
|
-
constructor(cause) {
|
|
62
|
-
super({
|
|
63
|
-
message: "Updating .gitignore for the local Project binding was aborted.",
|
|
64
|
-
cause,
|
|
65
|
-
gitignorePath: ".gitignore"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var LocalResolutionPinGitignoreUpdateFailedError = class extends TaggedError("LocalResolutionPinGitignoreUpdateFailedError")() {
|
|
70
|
-
constructor(operation, cause) {
|
|
71
|
-
super({
|
|
72
|
-
message: "Could not update .gitignore for the local Project binding.",
|
|
73
|
-
cause,
|
|
74
|
-
operation,
|
|
75
|
-
gitignorePath: ".gitignore"
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
async function readLocalResolutionPin(cwd, signal) {
|
|
80
|
-
return Result.gen(async function* () {
|
|
81
|
-
yield* ensureLocalResolutionPinReadNotAborted(signal);
|
|
82
|
-
const file = yield* Result.await(readLocalResolutionPinFile(cwd, signal));
|
|
83
|
-
if (file.kind === "missing") return Result.ok({ kind: "missing" });
|
|
84
|
-
const parsed = yield* parseLocalResolutionPin(file.raw);
|
|
85
|
-
if (!isLocalResolutionPin(parsed)) return Result.err(new LocalResolutionPinInvalidShapeError());
|
|
86
|
-
return Result.ok({
|
|
87
|
-
kind: "present",
|
|
88
|
-
pin: parsed
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function ensureLocalResolutionPinReadNotAborted(signal) {
|
|
93
|
-
return Result.try({
|
|
94
|
-
try: () => signal?.throwIfAborted(),
|
|
95
|
-
catch: (cause) => new LocalResolutionPinReadAbortedError(cause)
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
async function readLocalResolutionPinFile(cwd, signal) {
|
|
99
|
-
const readResult = await Result.tryPromise({
|
|
100
|
-
try: () => readFile(path.join(cwd, LOCAL_RESOLUTION_PIN_RELATIVE_PATH), {
|
|
101
|
-
encoding: "utf8",
|
|
102
|
-
signal
|
|
103
|
-
}),
|
|
104
|
-
catch: (cause) => signal?.aborted ? new LocalResolutionPinReadAbortedError(cause) : new UnhandledException({ cause })
|
|
105
|
-
});
|
|
106
|
-
if (readResult.isErr()) {
|
|
107
|
-
if (readResult.error instanceof UnhandledException && readResult.error.cause.code === "ENOENT") return Result.ok({ kind: "missing" });
|
|
108
|
-
return Result.err(readResult.error);
|
|
109
|
-
}
|
|
110
|
-
return Result.ok({
|
|
111
|
-
kind: "present",
|
|
112
|
-
raw: readResult.value
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function parseLocalResolutionPin(raw) {
|
|
116
|
-
return Result.try({
|
|
117
|
-
try: () => JSON.parse(raw),
|
|
118
|
-
catch: (cause) => cause instanceof SyntaxError ? new LocalResolutionPinInvalidJsonError(cause) : new UnhandledException({ cause })
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
async function writeLocalResolutionPin(cwd, pin, signal) {
|
|
122
|
-
return Result.gen(async function* () {
|
|
123
|
-
const prismaDir = path.join(cwd, ".prisma");
|
|
124
|
-
yield* ensureLocalResolutionPinWriteNotAborted(signal);
|
|
125
|
-
yield* Result.await(writeLocalResolutionPinBoundary(() => mkdir(prismaDir, { recursive: true }), "create-directory", signal));
|
|
126
|
-
const pinPath = path.join(cwd, LOCAL_RESOLUTION_PIN_RELATIVE_PATH);
|
|
127
|
-
const tmpPath = path.join(prismaDir, `local.${process.pid}.${Date.now()}.tmp`);
|
|
128
|
-
const serialized = yield* serializeLocalResolutionPin(pin);
|
|
129
|
-
yield* Result.await(writeLocalResolutionPinBoundary(() => writeFile(tmpPath, serialized, {
|
|
130
|
-
encoding: "utf8",
|
|
131
|
-
signal
|
|
132
|
-
}), "write-temp-file", signal));
|
|
133
|
-
yield* ensureLocalResolutionPinWriteNotAborted(signal);
|
|
134
|
-
yield* Result.await(writeLocalResolutionPinBoundary(() => rename(tmpPath, pinPath), "rename-temp-file", signal));
|
|
135
|
-
return Result.ok(void 0);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
async function ensureLocalResolutionPinGitignore(cwd, signal) {
|
|
139
|
-
const gitignorePath = path.join(cwd, ".gitignore");
|
|
140
|
-
let existing = null;
|
|
141
|
-
const notAborted = ensureLocalResolutionPinGitignoreUpdateNotAborted(signal);
|
|
142
|
-
if (notAborted.isErr()) return Result.err(notAborted.error);
|
|
143
|
-
const existingResult = await Result.tryPromise({
|
|
144
|
-
try: () => readFile(gitignorePath, {
|
|
145
|
-
encoding: "utf8",
|
|
146
|
-
signal
|
|
147
|
-
}),
|
|
148
|
-
catch: (cause) => signal?.aborted ? new LocalResolutionPinGitignoreUpdateAbortedError(cause) : new LocalResolutionPinGitignoreUpdateFailedError("read", cause)
|
|
149
|
-
});
|
|
150
|
-
if (existingResult.isErr()) if (existingResult.error instanceof LocalResolutionPinGitignoreUpdateFailedError && existingResult.error.cause.code === "ENOENT") existing = null;
|
|
151
|
-
else return Result.err(existingResult.error);
|
|
152
|
-
else existing = existingResult.value;
|
|
153
|
-
if (existing === null) return writeLocalResolutionPinGitignore(gitignorePath, ".prisma/\n", signal);
|
|
154
|
-
if (existing.split(/\r?\n/).map((line) => line.trim()).some((line) => line === ".prisma/" || line === ".prisma/local.json")) return Result.ok(void 0);
|
|
155
|
-
return writeLocalResolutionPinGitignore(gitignorePath, existing.endsWith("\n") ? `${existing}.prisma/\n` : `${existing}\n.prisma/\n`, signal);
|
|
156
|
-
}
|
|
157
|
-
function ensureLocalResolutionPinWriteNotAborted(signal) {
|
|
158
|
-
return Result.try({
|
|
159
|
-
try: () => signal?.throwIfAborted(),
|
|
160
|
-
catch: (cause) => new LocalResolutionPinWriteAbortedError(cause)
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function serializeLocalResolutionPin(pin) {
|
|
164
|
-
return Result.try({
|
|
165
|
-
try: () => `${JSON.stringify(pin, null, 2)}\n`,
|
|
166
|
-
catch: (cause) => new LocalResolutionPinSerializationError(cause)
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
function writeLocalResolutionPinBoundary(run, operation, signal) {
|
|
170
|
-
return Result.tryPromise({
|
|
171
|
-
try: async () => {
|
|
172
|
-
await run();
|
|
173
|
-
},
|
|
174
|
-
catch: (cause) => signal?.aborted ? new LocalResolutionPinWriteAbortedError(cause) : new LocalResolutionPinWriteFailedError(operation, cause)
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function ensureLocalResolutionPinGitignoreUpdateNotAborted(signal) {
|
|
178
|
-
return Result.try({
|
|
179
|
-
try: () => signal?.throwIfAborted(),
|
|
180
|
-
catch: (cause) => new LocalResolutionPinGitignoreUpdateAbortedError(cause)
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function writeLocalResolutionPinGitignore(gitignorePath, contents, signal) {
|
|
184
|
-
return Result.tryPromise({
|
|
185
|
-
try: () => writeFile(gitignorePath, contents, {
|
|
186
|
-
encoding: "utf8",
|
|
187
|
-
signal
|
|
188
|
-
}),
|
|
189
|
-
catch: (cause) => signal?.aborted ? new LocalResolutionPinGitignoreUpdateAbortedError(cause) : new LocalResolutionPinGitignoreUpdateFailedError("write", cause)
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function isLocalResolutionPin(value) {
|
|
193
|
-
if (!value || typeof value !== "object") return false;
|
|
194
|
-
const keys = Object.keys(value);
|
|
195
|
-
if (keys.length !== 2 || !keys.includes("workspaceId") || !keys.includes("projectId")) return false;
|
|
196
|
-
const candidate = value;
|
|
197
|
-
return typeof candidate.workspaceId === "string" && candidate.workspaceId.trim().length > 0 && typeof candidate.projectId === "string" && candidate.projectId.trim().length > 0;
|
|
198
|
-
}
|
|
199
|
-
//#endregion
|
|
200
|
-
export { LOCAL_RESOLUTION_PIN_RELATIVE_PATH, ensureLocalResolutionPinGitignore, readLocalResolutionPin, writeLocalResolutionPin };
|
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
import { CliError } from "../../shell/errors.js";
|
|
2
|
-
import { LOCAL_RESOLUTION_PIN_RELATIVE_PATH, readLocalResolutionPin } from "./local-pin.js";
|
|
3
|
-
import { formatCommandArgument } from "../../shell/command-arguments.js";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { Result, TaggedError, matchError } from "better-result";
|
|
7
|
-
//#region src/lib/project/resolution.ts
|
|
8
|
-
var ProjectNotFoundError = class extends TaggedError("ProjectNotFoundError")() {
|
|
9
|
-
constructor(projectRef, workspace) {
|
|
10
|
-
super({
|
|
11
|
-
message: `Project "${projectRef}" was not found in workspace "${workspace.name}".`,
|
|
12
|
-
projectRef,
|
|
13
|
-
workspace
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var ProjectAmbiguousError = class extends TaggedError("ProjectAmbiguousError")() {
|
|
18
|
-
constructor(projectRef, matches) {
|
|
19
|
-
super({
|
|
20
|
-
message: projectRef ? `Multiple projects matched "${projectRef}".` : "Multiple projects matched the current directory context.",
|
|
21
|
-
projectRef,
|
|
22
|
-
matches
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
var LocalStateStaleError = class extends TaggedError("LocalStateStaleError")() {
|
|
27
|
-
constructor() {
|
|
28
|
-
super({
|
|
29
|
-
message: `The target recorded in ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} is no longer available in the selected workspace.`,
|
|
30
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var LocalProjectWorkspaceMismatchError = class extends TaggedError("LocalProjectWorkspaceMismatchError")() {
|
|
35
|
-
constructor(options) {
|
|
36
|
-
super({
|
|
37
|
-
message: `${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} links this directory to project ${options.pinnedProjectId} in workspace ${options.pinnedWorkspaceId}, but the active workspace is "${options.activeWorkspace.name}" (${options.activeWorkspace.id}).`,
|
|
38
|
-
pinnedWorkspaceId: options.pinnedWorkspaceId,
|
|
39
|
-
pinnedProjectId: options.pinnedProjectId,
|
|
40
|
-
activeWorkspace: options.activeWorkspace
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
var ProjectSetupRequiredError = class extends TaggedError("ProjectSetupRequiredError")() {
|
|
45
|
-
constructor(options) {
|
|
46
|
-
const commandLabel = options.commandName ? `prisma-cli ${options.commandName}` : "this command";
|
|
47
|
-
super({
|
|
48
|
-
message: `This directory is not linked to a Prisma Project, and ${commandLabel} will not choose one from package or directory names.`,
|
|
49
|
-
commandName: options.commandName,
|
|
50
|
-
suggestion: options.suggestion
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
async function resolveProjectTarget(options) {
|
|
55
|
-
return Result.gen(async function* () {
|
|
56
|
-
const localPin = yield* Result.await(readImplicitLocalPin(options, { allowEnvProjectId: true }));
|
|
57
|
-
const projects = await options.listProjects();
|
|
58
|
-
const target = yield* Result.await(resolveBoundProjectTarget(options, projects, {
|
|
59
|
-
allowEnvProjectId: true,
|
|
60
|
-
localPin
|
|
61
|
-
}));
|
|
62
|
-
if (target) return Result.ok(target);
|
|
63
|
-
return Result.err(await projectSetupRequiredError({
|
|
64
|
-
cwd: options.context.runtime.cwd,
|
|
65
|
-
projects,
|
|
66
|
-
commandName: options.commandName,
|
|
67
|
-
signal: options.context.runtime.signal
|
|
68
|
-
}));
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
async function inspectProjectBinding(options) {
|
|
72
|
-
return Result.gen(async function* () {
|
|
73
|
-
const localPin = yield* Result.await(readImplicitLocalPin(options, { allowEnvProjectId: false }));
|
|
74
|
-
const projects = await options.listProjects();
|
|
75
|
-
const target = yield* Result.await(resolveBoundProjectTarget(options, projects, {
|
|
76
|
-
allowEnvProjectId: false,
|
|
77
|
-
localPin
|
|
78
|
-
}));
|
|
79
|
-
if (target) return Result.ok(target);
|
|
80
|
-
return Result.ok({
|
|
81
|
-
workspace: options.workspace,
|
|
82
|
-
project: null,
|
|
83
|
-
localBinding: { status: "not-linked" },
|
|
84
|
-
resolution: { projectSource: "unbound" },
|
|
85
|
-
...await buildProjectSetupSuggestion({
|
|
86
|
-
cwd: options.context.runtime.cwd,
|
|
87
|
-
projects,
|
|
88
|
-
commandName: options.commandName ?? "project show",
|
|
89
|
-
signal: options.context.runtime.signal
|
|
90
|
-
})
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
function projectNotFoundError(projectRef, workspace) {
|
|
95
|
-
return projectResolutionErrorToCliError(new ProjectNotFoundError(projectRef, workspace));
|
|
96
|
-
}
|
|
97
|
-
function projectNotFoundCliError(projectRef, workspace) {
|
|
98
|
-
return new CliError({
|
|
99
|
-
code: "PROJECT_NOT_FOUND",
|
|
100
|
-
domain: "project",
|
|
101
|
-
summary: "Project not found",
|
|
102
|
-
why: `The project "${projectRef}" does not exist in workspace "${workspace.name}" or is not accessible.`,
|
|
103
|
-
fix: "Pass a project id or name from prisma-cli project list.",
|
|
104
|
-
exitCode: 1,
|
|
105
|
-
nextSteps: ["prisma-cli project list"]
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function projectAmbiguousError(projectRef, matches) {
|
|
109
|
-
return projectResolutionErrorToCliError(new ProjectAmbiguousError(projectRef, matches));
|
|
110
|
-
}
|
|
111
|
-
function projectAmbiguousCliError(projectRef, matches) {
|
|
112
|
-
const firstMatch = matches[0];
|
|
113
|
-
const nextSteps = ["prisma-cli project list"];
|
|
114
|
-
if (firstMatch) nextSteps.push(`prisma-cli app deploy --project ${firstMatch.id}`);
|
|
115
|
-
return new CliError({
|
|
116
|
-
code: "PROJECT_AMBIGUOUS",
|
|
117
|
-
domain: "project",
|
|
118
|
-
summary: "Project resolution is ambiguous",
|
|
119
|
-
why: projectRef ? `Multiple projects matched "${projectRef}".` : "Multiple projects matched the current directory context.",
|
|
120
|
-
fix: "Pass --project <id-or-name> to choose the project explicitly.",
|
|
121
|
-
meta: { matches: matches.map((project) => ({
|
|
122
|
-
id: project.id,
|
|
123
|
-
name: project.name
|
|
124
|
-
})) },
|
|
125
|
-
exitCode: 1,
|
|
126
|
-
nextSteps
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function localStateStaleCliError() {
|
|
130
|
-
return new CliError({
|
|
131
|
-
code: "LOCAL_STATE_STALE",
|
|
132
|
-
domain: "project",
|
|
133
|
-
summary: "Local project binding is stale",
|
|
134
|
-
why: `The target recorded in ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} is no longer available in the selected workspace.`,
|
|
135
|
-
fix: `Delete ${LOCAL_RESOLUTION_PIN_RELATIVE_PATH}, then choose a Project explicitly.`,
|
|
136
|
-
meta: { pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH },
|
|
137
|
-
exitCode: 1,
|
|
138
|
-
nextSteps: ["prisma-cli project list", "prisma-cli project link <id-or-name>"]
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function localProjectWorkspaceMismatchError(options) {
|
|
142
|
-
return projectResolutionErrorToCliError(new LocalProjectWorkspaceMismatchError(options));
|
|
143
|
-
}
|
|
144
|
-
function localProjectWorkspaceMismatchCliError(options) {
|
|
145
|
-
return new CliError({
|
|
146
|
-
code: "LOCAL_PROJECT_WORKSPACE_MISMATCH",
|
|
147
|
-
domain: "project",
|
|
148
|
-
summary: "Project link uses another workspace",
|
|
149
|
-
why: `${LOCAL_RESOLUTION_PIN_RELATIVE_PATH} links this directory to project ${options.pinnedProjectId} in workspace ${options.pinnedWorkspaceId}, but your current CLI session is workspace "${options.activeWorkspace.name}" (${options.activeWorkspace.id}).`,
|
|
150
|
-
fix: "Switch to the linked workspace, or relink this directory to a project in the current workspace.",
|
|
151
|
-
meta: {
|
|
152
|
-
pinPath: LOCAL_RESOLUTION_PIN_RELATIVE_PATH,
|
|
153
|
-
pinnedWorkspaceId: options.pinnedWorkspaceId,
|
|
154
|
-
pinnedProjectId: options.pinnedProjectId,
|
|
155
|
-
activeWorkspaceId: options.activeWorkspace.id,
|
|
156
|
-
activeWorkspaceName: options.activeWorkspace.name
|
|
157
|
-
},
|
|
158
|
-
exitCode: 1,
|
|
159
|
-
nextSteps: [
|
|
160
|
-
`prisma-cli auth workspace use ${options.pinnedWorkspaceId}`,
|
|
161
|
-
"prisma-cli project list",
|
|
162
|
-
"prisma-cli project link <id-or-name>"
|
|
163
|
-
]
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Converts expected project-resolution variants to command-boundary CliErrors.
|
|
168
|
-
* `LocalResolutionPinReadAbortedError` and `UnhandledException` intentionally
|
|
169
|
-
* propagate as exceptions; callers such as `resolveProjectShowInRealMode`
|
|
170
|
-
* throw this helper's result, so passthrough variants should keep bubbling.
|
|
171
|
-
*/
|
|
172
|
-
function projectResolutionErrorToCliError(error) {
|
|
173
|
-
return matchError(error, {
|
|
174
|
-
ProjectNotFoundError: (error) => projectNotFoundCliError(error.projectRef, error.workspace),
|
|
175
|
-
ProjectAmbiguousError: (error) => projectAmbiguousCliError(error.projectRef, error.matches),
|
|
176
|
-
ProjectSetupRequiredError: (error) => projectSetupRequiredCliError(error),
|
|
177
|
-
LocalStateStaleError: () => localStateStaleCliError(),
|
|
178
|
-
LocalProjectWorkspaceMismatchError: (error) => localProjectWorkspaceMismatchCliError({
|
|
179
|
-
pinnedWorkspaceId: error.pinnedWorkspaceId,
|
|
180
|
-
pinnedProjectId: error.pinnedProjectId,
|
|
181
|
-
activeWorkspace: error.activeWorkspace
|
|
182
|
-
}),
|
|
183
|
-
LocalResolutionPinReadAbortedError: (error) => {
|
|
184
|
-
throw error;
|
|
185
|
-
},
|
|
186
|
-
UnhandledException: (error) => {
|
|
187
|
-
throw error;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
async function buildProjectSetupSuggestion(options) {
|
|
192
|
-
const suggestedName = await inferTargetName(options.cwd, options.signal);
|
|
193
|
-
const candidates = sortProjects(options.projects.filter((project) => projectMatchesSuggestedName(project, suggestedName.name))).map(toProjectSummary);
|
|
194
|
-
return {
|
|
195
|
-
suggestedProjectName: suggestedName.name,
|
|
196
|
-
suggestedProjectNameSource: suggestedName.source,
|
|
197
|
-
candidates,
|
|
198
|
-
recoveryCommands: buildProjectRecoveryCommands(options.commandName)
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
async function projectSetupRequiredError(options) {
|
|
202
|
-
const suggestion = await buildProjectSetupSuggestion(options);
|
|
203
|
-
return new ProjectSetupRequiredError({
|
|
204
|
-
commandName: options.commandName,
|
|
205
|
-
suggestion
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
function projectSetupRequiredCliError(error) {
|
|
209
|
-
const suggestion = error.suggestion;
|
|
210
|
-
return new CliError({
|
|
211
|
-
code: "PROJECT_SETUP_REQUIRED",
|
|
212
|
-
domain: "project",
|
|
213
|
-
summary: "Choose a Project before running this command",
|
|
214
|
-
why: error.message,
|
|
215
|
-
fix: "Link the directory to an existing Project, or pass --project <id-or-name> for this command.",
|
|
216
|
-
meta: { ...suggestion },
|
|
217
|
-
exitCode: 1,
|
|
218
|
-
nextSteps: ["prisma-cli project list", ...suggestion.recoveryCommands],
|
|
219
|
-
nextActions: buildProjectSetupNextActions({
|
|
220
|
-
commandName: error.commandName,
|
|
221
|
-
suggestedProjectName: suggestion.suggestedProjectName
|
|
222
|
-
})
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
function buildProjectSetupNextActions(options = {}) {
|
|
226
|
-
const recoveryCommands = buildProjectRecoveryCommands(options.commandName);
|
|
227
|
-
const linkCommand = recoveryCommands[0] ?? "prisma-cli project link <id-or-name>";
|
|
228
|
-
const retryCommand = recoveryCommands[1];
|
|
229
|
-
const actions = [{
|
|
230
|
-
kind: "user-choice",
|
|
231
|
-
journey: "project-setup",
|
|
232
|
-
label: "Ask the user whether to link an existing Project or create a new one",
|
|
233
|
-
commands: ["prisma-cli project list", ...recoveryCommands],
|
|
234
|
-
reason: options.reason ?? "This directory is not linked to a Prisma Project. Package and directory names are suggestions only, not a safe Project selection."
|
|
235
|
-
}, {
|
|
236
|
-
kind: "run-command",
|
|
237
|
-
journey: "project-setup",
|
|
238
|
-
label: "Link the chosen Project",
|
|
239
|
-
command: linkCommand,
|
|
240
|
-
reason: "Linking writes the durable local Project binding for this directory."
|
|
241
|
-
}];
|
|
242
|
-
const createCommand = options.createCommand ?? (options.suggestedProjectName ? `prisma-cli project create ${formatCommandArgument(options.suggestedProjectName)}` : void 0);
|
|
243
|
-
if (createCommand) actions.push({
|
|
244
|
-
kind: "run-command",
|
|
245
|
-
journey: "project-setup",
|
|
246
|
-
label: "Create and link a new Project",
|
|
247
|
-
command: createCommand,
|
|
248
|
-
reason: "Use this when the user wants a new Prisma Project instead of an existing one."
|
|
249
|
-
});
|
|
250
|
-
if (options.commandName) actions.push({
|
|
251
|
-
kind: "run-command",
|
|
252
|
-
journey: "recover",
|
|
253
|
-
label: "Retry with an explicit Project",
|
|
254
|
-
command: retryCommand ?? `prisma-cli ${options.commandName} --project <id-or-name>`
|
|
255
|
-
});
|
|
256
|
-
return actions;
|
|
257
|
-
}
|
|
258
|
-
async function readPackageName(cwd, signal) {
|
|
259
|
-
signal?.throwIfAborted();
|
|
260
|
-
try {
|
|
261
|
-
const raw = await readFile(path.join(cwd, "package.json"), {
|
|
262
|
-
encoding: "utf8",
|
|
263
|
-
signal
|
|
264
|
-
});
|
|
265
|
-
const parsed = JSON.parse(raw);
|
|
266
|
-
if (!parsed || typeof parsed !== "object") return null;
|
|
267
|
-
const packageName = "name" in parsed ? parsed.name : null;
|
|
268
|
-
return typeof packageName === "string" && packageName.trim().length > 0 ? packageName.trim() : null;
|
|
269
|
-
} catch (error) {
|
|
270
|
-
if (error.code === "ENOENT") return null;
|
|
271
|
-
if (error instanceof SyntaxError) return null;
|
|
272
|
-
throw error;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
async function inferTargetName(cwd, signal) {
|
|
276
|
-
const packageName = await readPackageName(cwd, signal);
|
|
277
|
-
if (packageName && isValidInferredTargetName(packageName)) return {
|
|
278
|
-
name: packageName,
|
|
279
|
-
source: "package-name"
|
|
280
|
-
};
|
|
281
|
-
return {
|
|
282
|
-
name: path.basename(cwd),
|
|
283
|
-
source: "directory-name"
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
function isValidInferredTargetName(value) {
|
|
287
|
-
return /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(value);
|
|
288
|
-
}
|
|
289
|
-
function sortProjects(projects) {
|
|
290
|
-
return projects.slice().sort((left, right) => left.name.localeCompare(right.name) || left.id.localeCompare(right.id));
|
|
291
|
-
}
|
|
292
|
-
function resolveExplicitProject(projectRef, projects, workspace) {
|
|
293
|
-
const matches = projects.filter((project) => project.id === projectRef || project.name === projectRef);
|
|
294
|
-
if (matches.length === 1) return Result.ok(matches[0]);
|
|
295
|
-
if (matches.length > 1) return Result.err(new ProjectAmbiguousError(projectRef, matches));
|
|
296
|
-
return Result.err(new ProjectNotFoundError(projectRef, workspace));
|
|
297
|
-
}
|
|
298
|
-
function projectMatchesSuggestedName(project, suggestedName) {
|
|
299
|
-
return project.id === suggestedName || project.name === suggestedName || project.slug === suggestedName;
|
|
300
|
-
}
|
|
301
|
-
async function resolveDurablePlatformMapping() {
|
|
302
|
-
return null;
|
|
303
|
-
}
|
|
304
|
-
async function resolveBoundProjectTarget(options, projects, settings) {
|
|
305
|
-
if (options.explicitProject) {
|
|
306
|
-
const projectResult = resolveExplicitProject(options.explicitProject, projects, options.workspace);
|
|
307
|
-
if (projectResult.isErr()) return Result.err(projectResult.error);
|
|
308
|
-
return Result.ok(resolvedTarget(options.workspace, projectResult.value, "explicit", {
|
|
309
|
-
targetName: options.explicitProject,
|
|
310
|
-
targetNameSource: "explicit"
|
|
311
|
-
}));
|
|
312
|
-
}
|
|
313
|
-
if (settings.allowEnvProjectId && options.envProjectId) {
|
|
314
|
-
const project = projects.find((candidate) => candidate.id === options.envProjectId);
|
|
315
|
-
if (!project) return Result.err(new ProjectNotFoundError(options.envProjectId, options.workspace));
|
|
316
|
-
return Result.ok(resolvedTarget(options.workspace, project, "env", {
|
|
317
|
-
targetName: options.envProjectId,
|
|
318
|
-
targetNameSource: "env"
|
|
319
|
-
}));
|
|
320
|
-
}
|
|
321
|
-
const localPin = settings.localPin;
|
|
322
|
-
if (!localPin) return Result.ok(null);
|
|
323
|
-
if (localPin.kind === "present") {
|
|
324
|
-
if (localPin.pin.workspaceId !== options.workspace.id) return Result.err(new LocalProjectWorkspaceMismatchError({
|
|
325
|
-
pinnedWorkspaceId: localPin.pin.workspaceId,
|
|
326
|
-
pinnedProjectId: localPin.pin.projectId,
|
|
327
|
-
activeWorkspace: options.workspace
|
|
328
|
-
}));
|
|
329
|
-
const project = projects.find((candidate) => candidate.id === localPin.pin.projectId);
|
|
330
|
-
if (!project) return Result.err(new LocalStateStaleError());
|
|
331
|
-
return Result.ok(resolvedTarget(options.workspace, project, "local-pin", {
|
|
332
|
-
targetName: project.name,
|
|
333
|
-
targetNameSource: "local-pin"
|
|
334
|
-
}));
|
|
335
|
-
}
|
|
336
|
-
const platformMapping = await resolveDurablePlatformMapping();
|
|
337
|
-
if (platformMapping && platformMapping.workspace.id === options.workspace.id) return Result.ok(resolvedTarget(options.workspace, platformMapping, "platform-mapping", {
|
|
338
|
-
targetName: platformMapping.name,
|
|
339
|
-
targetNameSource: "platform-mapping"
|
|
340
|
-
}));
|
|
341
|
-
return Result.ok(null);
|
|
342
|
-
}
|
|
343
|
-
async function readImplicitLocalPin(options, settings) {
|
|
344
|
-
if (options.explicitProject || settings.allowEnvProjectId && options.envProjectId) return Result.ok(null);
|
|
345
|
-
const localPinResult = await readLocalResolutionPin(options.projectDir ?? options.context.runtime.cwd, options.context.runtime.signal);
|
|
346
|
-
if (localPinResult.isErr()) return Result.err(localPinReadErrorToProjectError(localPinResult.error));
|
|
347
|
-
const localPin = localPinResult.value;
|
|
348
|
-
if (localPin.kind === "present" && localPin.pin.workspaceId !== options.workspace.id) return Result.err(new LocalProjectWorkspaceMismatchError({
|
|
349
|
-
pinnedWorkspaceId: localPin.pin.workspaceId,
|
|
350
|
-
pinnedProjectId: localPin.pin.projectId,
|
|
351
|
-
activeWorkspace: options.workspace
|
|
352
|
-
}));
|
|
353
|
-
return Result.ok(localPin);
|
|
354
|
-
}
|
|
355
|
-
function localPinReadErrorToProjectError(error) {
|
|
356
|
-
return matchError(error, {
|
|
357
|
-
LocalResolutionPinInvalidJsonError: () => new LocalStateStaleError(),
|
|
358
|
-
LocalResolutionPinInvalidShapeError: () => new LocalStateStaleError(),
|
|
359
|
-
LocalResolutionPinReadAbortedError: (error) => error,
|
|
360
|
-
UnhandledException: (error) => error
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
function resolvedTarget(workspace, project, projectSource, resolutionDetails) {
|
|
364
|
-
return {
|
|
365
|
-
workspace,
|
|
366
|
-
project: toProjectSummary(project),
|
|
367
|
-
resolution: {
|
|
368
|
-
projectSource,
|
|
369
|
-
...resolutionDetails
|
|
370
|
-
}
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
function buildProjectRecoveryCommands(commandName) {
|
|
374
|
-
const commands = ["prisma-cli project link <id-or-name>"];
|
|
375
|
-
if (commandName) commands.push(`prisma-cli ${commandName} --project <id-or-name>`);
|
|
376
|
-
return commands;
|
|
377
|
-
}
|
|
378
|
-
function toProjectSummary(project) {
|
|
379
|
-
return {
|
|
380
|
-
id: project.id,
|
|
381
|
-
name: project.name,
|
|
382
|
-
...project.url ? { url: project.url } : {}
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
//#endregion
|
|
386
|
-
export { buildProjectSetupNextActions, inferTargetName, inspectProjectBinding, localProjectWorkspaceMismatchError, projectAmbiguousError, projectNotFoundError, projectResolutionErrorToCliError, resolveDurablePlatformMapping, resolveProjectTarget, sortProjects };
|