@prisma/cli-init 0.0.0-dev.202505142356 → 0.0.3
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.
|
@@ -5,11 +5,11 @@ var __export = (target, all) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
// src/platform/_lib/utils.ts
|
|
8
|
-
import
|
|
8
|
+
import { getCommandWithExecutor, isError as isError2, link } from "@prisma/internals";
|
|
9
9
|
import { bold, green } from "kleur/colors";
|
|
10
10
|
|
|
11
11
|
// src/platform/_lib/cli/parameters.ts
|
|
12
|
-
import
|
|
12
|
+
import { arg, isError } from "@prisma/internals";
|
|
13
13
|
var getRequiredParameter = (args, names, environmentVariable) => {
|
|
14
14
|
const value = getOptionalParameter(args, names, environmentVariable);
|
|
15
15
|
if (value === void 0)
|
|
@@ -17,8 +17,8 @@ var getRequiredParameter = (args, names, environmentVariable) => {
|
|
|
17
17
|
return value;
|
|
18
18
|
};
|
|
19
19
|
function argOrThrow(argv, spec) {
|
|
20
|
-
const args =
|
|
21
|
-
if (
|
|
20
|
+
const args = arg(argv, spec);
|
|
21
|
+
if (isError(args))
|
|
22
22
|
throw args;
|
|
23
23
|
return args;
|
|
24
24
|
}
|
|
@@ -129,7 +129,7 @@ var platformParameters = {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
var ErrorPlatformUnauthorized = new Error(
|
|
132
|
-
`No platform credentials found. Run ${green(
|
|
132
|
+
`No platform credentials found. Run ${green(getCommandWithExecutor("prisma platform auth login --early-access"))} first. Alternatively you can provide a token via the \`--token\` or \`-t\` parameters, or set the 'PRISMA_TOKEN' environment variable with a token.`
|
|
133
133
|
// prettier-ignore
|
|
134
134
|
);
|
|
135
135
|
var getTokenOrThrow = async (args) => {
|
|
@@ -137,7 +137,7 @@ var getTokenOrThrow = async (args) => {
|
|
|
137
137
|
if (token)
|
|
138
138
|
return token;
|
|
139
139
|
const credentials = await credentialsFile.load();
|
|
140
|
-
if (
|
|
140
|
+
if (isError2(credentials))
|
|
141
141
|
throw credentials;
|
|
142
142
|
if (!credentials)
|
|
143
143
|
throw ErrorPlatformUnauthorized;
|
|
@@ -164,7 +164,7 @@ var poll = async (fn, until, waitMs, timeoutMs, message) => {
|
|
|
164
164
|
console.log(message);
|
|
165
165
|
result = await wait().then(fn);
|
|
166
166
|
}
|
|
167
|
-
if (
|
|
167
|
+
if (isError2(result))
|
|
168
168
|
throw result;
|
|
169
169
|
return result;
|
|
170
170
|
};
|
|
@@ -182,10 +182,10 @@ We created an initial ${green("schema.prisma")} file and a ${green(".env")} file
|
|
|
182
182
|
|
|
183
183
|
${bold("--- Next steps ---")}
|
|
184
184
|
|
|
185
|
-
Go to ${
|
|
185
|
+
Go to ${link("https://pris.ly/ppg-init")} for detailed instructions.
|
|
186
186
|
|
|
187
187
|
${bold("1. Define your database schema")}
|
|
188
|
-
Open the ${green("schema.prisma")} file and define your first models. Check the docs if you need inspiration: ${
|
|
188
|
+
Open the ${green("schema.prisma")} file and define your first models. Check the docs if you need inspiration: ${link(
|
|
189
189
|
"https://pris.ly/ppg-init"
|
|
190
190
|
)}.
|
|
191
191
|
|
|
@@ -198,10 +198,10 @@ View and edit your data locally by running this command:
|
|
|
198
198
|
${green("npx prisma studio")}
|
|
199
199
|
|
|
200
200
|
...or online in Console:
|
|
201
|
-
${
|
|
201
|
+
${link(`https://console.prisma.io/${workspaceId}/${projectId}/${environmentId}/studio`)}
|
|
202
202
|
|
|
203
203
|
${bold(`4. Send queries from your app`)}
|
|
204
|
-
To access your database from a JavaScript/TypeScript app, you need to use Prisma ORM. Go here for step-by-step instructions: ${
|
|
204
|
+
To access your database from a JavaScript/TypeScript app, you need to use Prisma ORM. Go here for step-by-step instructions: ${link(
|
|
205
205
|
"https://pris.ly/ppg-init"
|
|
206
206
|
)}
|
|
207
207
|
`;
|
|
@@ -216,7 +216,7 @@ ${green(databaseUrl)}
|
|
|
216
216
|
|
|
217
217
|
${bold("--- Next steps ---")}
|
|
218
218
|
|
|
219
|
-
Go to ${
|
|
219
|
+
Go to ${link("https://pris.ly/ppg-init")} for detailed instructions.
|
|
220
220
|
|
|
221
221
|
${bold("1. Install and use the Prisma Accelerate extension")}
|
|
222
222
|
Prisma Postgres requires the Prisma Accelerate extension for querying. If you haven't already installed it, install it in your project:
|
|
@@ -236,13 +236,13 @@ View and edit your data locally by running this command:
|
|
|
236
236
|
${green("npx prisma studio")}
|
|
237
237
|
|
|
238
238
|
...or online in Console:
|
|
239
|
-
${
|
|
239
|
+
${link(`https://console.prisma.io/${workspaceId}/${projectId}/${environmentId}/studio`)}
|
|
240
240
|
|
|
241
241
|
${bold(`4. Send queries from your app`)}
|
|
242
242
|
If you already have an existing app with Prisma ORM, you can now run it and it will send queries against your newly created Prisma Postgres instance.
|
|
243
243
|
|
|
244
244
|
${bold(`5. Learn more`)}
|
|
245
|
-
For more info, visit the Prisma Postgres docs: ${
|
|
245
|
+
For more info, visit the Prisma Postgres docs: ${link("https://pris.ly/ppg-docs")}
|
|
246
246
|
`;
|
|
247
247
|
return isExistingPrismaProject ? existingPrismaProjectOutput : newPrismaProjectOutput;
|
|
248
248
|
};
|
|
@@ -256,8 +256,7 @@ __export(__exports, {
|
|
|
256
256
|
});
|
|
257
257
|
|
|
258
258
|
// src/platform/_lib/cli/dispatchToSubCommand.ts
|
|
259
|
-
import
|
|
260
|
-
var { HelpError, link } = internals3;
|
|
259
|
+
import { HelpError, link as link2 } from "@prisma/internals";
|
|
261
260
|
var dispatchToSubCommand = async (commands, argv, config) => {
|
|
262
261
|
const commandName = argv[0];
|
|
263
262
|
if (!commandName)
|
|
@@ -267,7 +266,7 @@ var dispatchToSubCommand = async (commands, argv, config) => {
|
|
|
267
266
|
return new HelpError(`Unknown command or parameter "${commandName}"`);
|
|
268
267
|
const hasHelpFlag = Boolean(argv.find((it) => ["-h", "--help"].includes(it)));
|
|
269
268
|
if (hasHelpFlag)
|
|
270
|
-
return `Help output for this command will be available soon. In the meantime, visit ${
|
|
269
|
+
return `Help output for this command will be available soon. In the meantime, visit ${link2("https://pris.ly/cli/platform-docs")} for more information.`;
|
|
271
270
|
const result = await command.parse(argv.slice(1), config);
|
|
272
271
|
return result;
|
|
273
272
|
};
|
|
@@ -291,18 +290,15 @@ var createNamespace = () => {
|
|
|
291
290
|
var $ = createNamespace();
|
|
292
291
|
|
|
293
292
|
// src/platform/_lib/messages.ts
|
|
294
|
-
import
|
|
293
|
+
import { formatTable, mapObjectValues } from "@prisma/internals";
|
|
295
294
|
import { bold as bold2, dim, green as green2, white } from "kleur/colors";
|
|
296
295
|
var table = (object, renderersInput) => {
|
|
297
296
|
const renderers = {
|
|
298
297
|
key: renderersInput.key ?? dim,
|
|
299
298
|
// eslint-disable-next-line
|
|
300
|
-
values:
|
|
301
|
-
renderersInput.values ?? {},
|
|
302
|
-
(_) => _ === true ? id : _
|
|
303
|
-
)
|
|
299
|
+
values: mapObjectValues(renderersInput.values ?? {}, (_) => _ === true ? id : _)
|
|
304
300
|
};
|
|
305
|
-
return
|
|
301
|
+
return formatTable(
|
|
306
302
|
Object.entries(renderers.values).map(([propertyName, renderer]) => {
|
|
307
303
|
const valueRendered = renderer(object[propertyName]);
|
|
308
304
|
if (valueRendered === null)
|
|
@@ -341,19 +337,19 @@ import fetch, { Headers } from "node-fetch";
|
|
|
341
337
|
|
|
342
338
|
// src/platform/_lib/userAgent.ts
|
|
343
339
|
import Debug from "@prisma/debug";
|
|
344
|
-
import
|
|
340
|
+
import { isError as isError3 } from "@prisma/internals";
|
|
345
341
|
import * as Checkpoint from "checkpoint-client";
|
|
346
342
|
|
|
347
343
|
// package.json
|
|
348
|
-
var version = "0.0.
|
|
344
|
+
var version = "0.0.3";
|
|
349
345
|
|
|
350
346
|
// src/platform/_lib/userAgent.ts
|
|
351
347
|
var debug = Debug("prisma:cli:platform:_lib:userAgent");
|
|
352
348
|
var getUserAgent = async () => {
|
|
353
349
|
const signature = await Checkpoint.getSignature().catch(unknownToError);
|
|
354
|
-
if (
|
|
350
|
+
if (isError3(signature))
|
|
355
351
|
debug(`await checkpoint.getSignature() failed silently with ${signature.message}`);
|
|
356
|
-
const signatureString =
|
|
352
|
+
const signatureString = isError3(signature) ? "unknown" : signature;
|
|
357
353
|
return `prisma-cli-init/${version} (Signature: ${signatureString})`;
|
|
358
354
|
};
|
|
359
355
|
|
|
@@ -427,20 +423,20 @@ var Disable = class _Disable {
|
|
|
427
423
|
};
|
|
428
424
|
|
|
429
425
|
// src/platform/accelerate/enable.ts
|
|
430
|
-
import
|
|
426
|
+
import { arg as arg2, isError as isError4, link as link3 } from "@prisma/internals";
|
|
431
427
|
var Enable = class _Enable {
|
|
432
428
|
static new() {
|
|
433
429
|
return new _Enable();
|
|
434
430
|
}
|
|
435
431
|
async parse(argv, _config) {
|
|
436
|
-
const args =
|
|
432
|
+
const args = arg2(argv, {
|
|
437
433
|
...platformParameters.environment,
|
|
438
434
|
"--url": String,
|
|
439
435
|
// TODO rename to "serviceToken" in a future release.
|
|
440
436
|
"--apikey": Boolean,
|
|
441
437
|
"--region": String
|
|
442
438
|
});
|
|
443
|
-
if (
|
|
439
|
+
if (isError4(args))
|
|
444
440
|
return args;
|
|
445
441
|
const token = await getTokenOrThrow(args);
|
|
446
442
|
const environmentId = getRequiredParameterOrThrow(args, ["--environment", "-e"]);
|
|
@@ -511,7 +507,7 @@ var Enable = class _Enable {
|
|
|
511
507
|
}
|
|
512
508
|
}
|
|
513
509
|
});
|
|
514
|
-
const gettingStartedUrl =
|
|
510
|
+
const gettingStartedUrl = link3("https://pris.ly/d/accelerate-getting-started");
|
|
515
511
|
if (serviceTokenCreate) {
|
|
516
512
|
return messages.success(
|
|
517
513
|
`Accelerate enabled. Use this Accelerate connection string to authenticate requests:
|
|
@@ -546,7 +542,7 @@ var $2 = createNamespace();
|
|
|
546
542
|
// src/platform/auth/login.ts
|
|
547
543
|
import { select } from "@inquirer/prompts";
|
|
548
544
|
import Debug2 from "@prisma/debug";
|
|
549
|
-
import
|
|
545
|
+
import { arg as arg3, getCommandWithExecutor as getCommandWithExecutor2, isError as isError5, link as link4 } from "@prisma/internals";
|
|
550
546
|
import listen from "async-listen";
|
|
551
547
|
import http from "http";
|
|
552
548
|
import { green as green3 } from "kleur/colors";
|
|
@@ -557,27 +553,27 @@ var Login = class _Login {
|
|
|
557
553
|
return new _Login();
|
|
558
554
|
}
|
|
559
555
|
async parse(argv, _config) {
|
|
560
|
-
const args =
|
|
556
|
+
const args = arg3(argv, {
|
|
561
557
|
// internal optimize flag to track signup attribution
|
|
562
558
|
"--optimize": Boolean
|
|
563
559
|
});
|
|
564
|
-
if (
|
|
560
|
+
if (isError5(args))
|
|
565
561
|
return args;
|
|
566
562
|
if (args["--optimize"]) {
|
|
567
563
|
console.warn("The '--optimize' flag is deprecated. Use API keys instead.");
|
|
568
564
|
}
|
|
569
565
|
const credentials = await credentialsFile.load();
|
|
570
|
-
if (
|
|
566
|
+
if (isError5(credentials))
|
|
571
567
|
throw credentials;
|
|
572
568
|
if (credentials)
|
|
573
|
-
return `Already authenticated. Run ${green3(
|
|
569
|
+
return `Already authenticated. Run ${green3(getCommandWithExecutor2("prisma platform auth show --early-access"))} to see the current user.`;
|
|
574
570
|
console.info("Authenticating to Prisma Platform CLI via browser.\n");
|
|
575
571
|
const server = http.createServer();
|
|
576
572
|
const randomPort = 0;
|
|
577
573
|
const redirectUrl = await listen(server, randomPort, "127.0.0.1");
|
|
578
574
|
const loginUrl = await createLoginUrl({ connection: "github", redirectTo: redirectUrl.href });
|
|
579
575
|
console.info("Visit the following URL in your browser to authenticate:");
|
|
580
|
-
console.info(
|
|
576
|
+
console.info(link4(loginUrl.href));
|
|
581
577
|
const callbackResult = await Promise.all([
|
|
582
578
|
new Promise((resolve, reject) => {
|
|
583
579
|
server.once("request", (req, res) => {
|
|
@@ -617,11 +613,11 @@ var Login = class _Login {
|
|
|
617
613
|
}),
|
|
618
614
|
open(loginUrl.href)
|
|
619
615
|
]).then((results) => results[0]).catch(unknownToError);
|
|
620
|
-
if (
|
|
616
|
+
if (isError5(callbackResult))
|
|
621
617
|
throw new Error(`Authentication failed: ${callbackResult.message}`);
|
|
622
618
|
{
|
|
623
619
|
const writeResult = await credentialsFile.save({ token: callbackResult.token });
|
|
624
|
-
if (
|
|
620
|
+
if (isError5(writeResult))
|
|
625
621
|
throw new Error("Writing credentials to disk failed", { cause: writeResult });
|
|
626
622
|
}
|
|
627
623
|
return successMessage(`Authentication successful for ${callbackResult.user.email}`);
|
|
@@ -667,7 +663,7 @@ var loginOrSignup = async () => {
|
|
|
667
663
|
const redirectUrl = await listen(server, randomPort, "127.0.0.1");
|
|
668
664
|
const loginUrl = await createLoginUrl({ connection: providerAnswer, redirectTo: redirectUrl.href });
|
|
669
665
|
console.info("Visit the following URL in your browser to authenticate:");
|
|
670
|
-
console.info(
|
|
666
|
+
console.info(link4(loginUrl.href));
|
|
671
667
|
const callbackResult = await Promise.all([
|
|
672
668
|
new Promise((resolve, reject) => {
|
|
673
669
|
server.once("request", (req, res) => {
|
|
@@ -707,11 +703,11 @@ var loginOrSignup = async () => {
|
|
|
707
703
|
}),
|
|
708
704
|
open(loginUrl.href)
|
|
709
705
|
]).then((results) => results[0]).catch(unknownToError);
|
|
710
|
-
if (
|
|
706
|
+
if (isError5(callbackResult))
|
|
711
707
|
throw new Error(`Authentication failed: ${callbackResult.message}`);
|
|
712
708
|
{
|
|
713
709
|
const writeResult = await credentialsFile.save({ token: callbackResult.token });
|
|
714
|
-
if (
|
|
710
|
+
if (isError5(writeResult))
|
|
715
711
|
throw new Error("Writing credentials to disk failed", { cause: writeResult });
|
|
716
712
|
}
|
|
717
713
|
return {
|
|
@@ -722,11 +718,11 @@ var loginOrSignup = async () => {
|
|
|
722
718
|
};
|
|
723
719
|
|
|
724
720
|
// src/platform/auth/logout.ts
|
|
725
|
-
import
|
|
721
|
+
import { getCommandWithExecutor as getCommandWithExecutor3, isError as isError7 } from "@prisma/internals";
|
|
726
722
|
import { green as green4 } from "kleur/colors";
|
|
727
723
|
|
|
728
724
|
// src/platform/_lib/jwt.ts
|
|
729
|
-
import
|
|
725
|
+
import { isError as isError6 } from "@prisma/internals";
|
|
730
726
|
var decodeJwt = (jwt) => {
|
|
731
727
|
if (typeof jwt !== "string")
|
|
732
728
|
throw new Error("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
@@ -741,13 +737,13 @@ var decodeJwt = (jwt) => {
|
|
|
741
737
|
() => atob(payload),
|
|
742
738
|
() => new Error("Failed to base64 decode the payload.")
|
|
743
739
|
);
|
|
744
|
-
if (
|
|
740
|
+
if (isError6(decoded))
|
|
745
741
|
return decoded;
|
|
746
742
|
const result = tryCatch(
|
|
747
743
|
() => JSON.parse(decoded),
|
|
748
744
|
() => new Error("Failed to parse the decoded payload as JSON.")
|
|
749
745
|
);
|
|
750
|
-
if (
|
|
746
|
+
if (isError6(result))
|
|
751
747
|
return result;
|
|
752
748
|
if (!isObject(result))
|
|
753
749
|
throw new Error("Invalid JWT Claims Set.");
|
|
@@ -761,13 +757,13 @@ var Logout = class _Logout {
|
|
|
761
757
|
}
|
|
762
758
|
async parse() {
|
|
763
759
|
const credentials = await credentialsFile.load();
|
|
764
|
-
if (
|
|
760
|
+
if (isError7(credentials))
|
|
765
761
|
throw credentials;
|
|
766
762
|
if (!credentials)
|
|
767
|
-
return `You are not currently logged in. Run ${green4(
|
|
763
|
+
return `You are not currently logged in. Run ${green4(getCommandWithExecutor3("prisma platform auth login --early-access"))} to log in.`;
|
|
768
764
|
if (credentials.token) {
|
|
769
765
|
const jwt = decodeJwt(credentials.token);
|
|
770
|
-
if (!
|
|
766
|
+
if (!isError7(jwt) && jwt.jti) {
|
|
771
767
|
await requestOrThrow({
|
|
772
768
|
token: credentials.token,
|
|
773
769
|
body: {
|
|
@@ -906,16 +902,16 @@ var Create = class _Create {
|
|
|
906
902
|
};
|
|
907
903
|
|
|
908
904
|
// src/platform/environment/delete.ts
|
|
909
|
-
import
|
|
905
|
+
import { arg as arg4, isError as isError8 } from "@prisma/internals";
|
|
910
906
|
var Delete = class _Delete {
|
|
911
907
|
static new() {
|
|
912
908
|
return new _Delete();
|
|
913
909
|
}
|
|
914
910
|
async parse(argv, _config) {
|
|
915
|
-
const args =
|
|
911
|
+
const args = arg4(argv, {
|
|
916
912
|
...platformParameters.environment
|
|
917
913
|
});
|
|
918
|
-
if (
|
|
914
|
+
if (isError8(args))
|
|
919
915
|
return args;
|
|
920
916
|
const token = await getTokenOrThrow(args);
|
|
921
917
|
const environmentId = getRequiredParameterOrThrow(args, ["--environment", "-e"]);
|
|
@@ -952,16 +948,16 @@ var Delete = class _Delete {
|
|
|
952
948
|
};
|
|
953
949
|
|
|
954
950
|
// src/platform/environment/show.ts
|
|
955
|
-
import
|
|
951
|
+
import { arg as arg5, isError as isError9 } from "@prisma/internals";
|
|
956
952
|
var Show2 = class _Show {
|
|
957
953
|
static new() {
|
|
958
954
|
return new _Show();
|
|
959
955
|
}
|
|
960
956
|
async parse(argv, _config) {
|
|
961
|
-
const args =
|
|
957
|
+
const args = arg5(argv, {
|
|
962
958
|
...platformParameters.project
|
|
963
959
|
});
|
|
964
|
-
if (
|
|
960
|
+
if (isError9(args))
|
|
965
961
|
return args;
|
|
966
962
|
const token = await getTokenOrThrow(args);
|
|
967
963
|
const projectId = getRequiredParameterOrThrow(args, ["--project", "-p"]);
|
|
@@ -1117,16 +1113,16 @@ var createProjectOrThrow = async (input) => {
|
|
|
1117
1113
|
};
|
|
1118
1114
|
|
|
1119
1115
|
// src/platform/project/delete.ts
|
|
1120
|
-
import
|
|
1116
|
+
import { arg as arg6, isError as isError10 } from "@prisma/internals";
|
|
1121
1117
|
var Delete2 = class _Delete {
|
|
1122
1118
|
static new() {
|
|
1123
1119
|
return new _Delete();
|
|
1124
1120
|
}
|
|
1125
1121
|
async parse(argv, _config) {
|
|
1126
|
-
const args =
|
|
1122
|
+
const args = arg6(argv, {
|
|
1127
1123
|
...platformParameters.project
|
|
1128
1124
|
});
|
|
1129
|
-
if (
|
|
1125
|
+
if (isError10(args))
|
|
1130
1126
|
return args;
|
|
1131
1127
|
const token = await getTokenOrThrow(args);
|
|
1132
1128
|
const projectId = getRequiredParameterOrThrow(args, ["--project", "-p"]);
|
|
@@ -1163,16 +1159,16 @@ var Delete2 = class _Delete {
|
|
|
1163
1159
|
};
|
|
1164
1160
|
|
|
1165
1161
|
// src/platform/project/show.ts
|
|
1166
|
-
import
|
|
1162
|
+
import { arg as arg7, isError as isError11 } from "@prisma/internals";
|
|
1167
1163
|
var Show3 = class _Show {
|
|
1168
1164
|
static new() {
|
|
1169
1165
|
return new _Show();
|
|
1170
1166
|
}
|
|
1171
1167
|
async parse(argv, _config) {
|
|
1172
|
-
const args =
|
|
1168
|
+
const args = arg7(argv, {
|
|
1173
1169
|
...platformParameters.workspace
|
|
1174
1170
|
});
|
|
1175
|
-
if (
|
|
1171
|
+
if (isError11(args))
|
|
1176
1172
|
return args;
|
|
1177
1173
|
const token = await getTokenOrThrow(args);
|
|
1178
1174
|
const workspaceId = getRequiredParameterOrThrow(args, ["--workspace", "-w"]);
|
|
@@ -1333,7 +1329,7 @@ var Delete3 = class _Delete {
|
|
|
1333
1329
|
};
|
|
1334
1330
|
|
|
1335
1331
|
// src/platform/serviceToken/show.ts
|
|
1336
|
-
import
|
|
1332
|
+
import { arg as arg8, isError as isError12 } from "@prisma/internals";
|
|
1337
1333
|
var Show4 = class _Show {
|
|
1338
1334
|
constructor(legacy = false) {
|
|
1339
1335
|
this.legacy = legacy;
|
|
@@ -1342,10 +1338,10 @@ var Show4 = class _Show {
|
|
|
1342
1338
|
return new _Show(legacy);
|
|
1343
1339
|
}
|
|
1344
1340
|
async parse(argv, _config) {
|
|
1345
|
-
const args =
|
|
1341
|
+
const args = arg8(argv, {
|
|
1346
1342
|
...platformParameters.environment
|
|
1347
1343
|
});
|
|
1348
|
-
if (
|
|
1344
|
+
if (isError12(args))
|
|
1349
1345
|
return args;
|
|
1350
1346
|
const token = await getTokenOrThrow(args);
|
|
1351
1347
|
const environmentId = getRequiredParameterOrThrow(args, ["--environment", "-e"]);
|
package/dist/index.js
CHANGED
|
@@ -4,11 +4,24 @@ import {
|
|
|
4
4
|
printPpgInitOutput,
|
|
5
5
|
requestOrThrow,
|
|
6
6
|
successMessage
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VVHEUIBQ.js";
|
|
8
8
|
|
|
9
9
|
// src/Init.ts
|
|
10
10
|
import { confirm, input, select } from "@inquirer/prompts";
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
arg,
|
|
13
|
+
canConnectToDatabase,
|
|
14
|
+
checkUnsupportedDataProxy,
|
|
15
|
+
format,
|
|
16
|
+
getCommandWithExecutor,
|
|
17
|
+
HelpError,
|
|
18
|
+
isError,
|
|
19
|
+
link,
|
|
20
|
+
logger,
|
|
21
|
+
PRISMA_POSTGRES_PROTOCOL,
|
|
22
|
+
PRISMA_POSTGRES_PROVIDER,
|
|
23
|
+
protocolToConnectorType
|
|
24
|
+
} from "@prisma/internals";
|
|
12
25
|
import dotenv from "dotenv";
|
|
13
26
|
import { Schema as Shape } from "effect";
|
|
14
27
|
import fs2 from "fs";
|
|
@@ -170,7 +183,7 @@ var defaultPort = (datasourceProvider) => {
|
|
|
170
183
|
return 5432;
|
|
171
184
|
case "cockroachdb":
|
|
172
185
|
return 26257;
|
|
173
|
-
case
|
|
186
|
+
case PRISMA_POSTGRES_PROVIDER:
|
|
174
187
|
return null;
|
|
175
188
|
}
|
|
176
189
|
return void 0;
|
|
@@ -205,7 +218,7 @@ var Init = class _Init {
|
|
|
205
218
|
static new() {
|
|
206
219
|
return new _Init();
|
|
207
220
|
}
|
|
208
|
-
static help =
|
|
221
|
+
static help = format(`
|
|
209
222
|
Set up a new Prisma project
|
|
210
223
|
|
|
211
224
|
${bold2("Usage")}
|
|
@@ -250,7 +263,7 @@ var Init = class _Init {
|
|
|
250
263
|
${dim("$")} prisma init --with-model
|
|
251
264
|
`);
|
|
252
265
|
async parse(argv, _config) {
|
|
253
|
-
const args =
|
|
266
|
+
const args = arg(argv, {
|
|
254
267
|
"--help": Boolean,
|
|
255
268
|
"-h": "--help",
|
|
256
269
|
"--url": String,
|
|
@@ -266,10 +279,10 @@ var Init = class _Init {
|
|
|
266
279
|
"--prompt": String,
|
|
267
280
|
"--vibe": String
|
|
268
281
|
});
|
|
269
|
-
if (
|
|
282
|
+
if (isError(args) || args["--help"]) {
|
|
270
283
|
return this.help();
|
|
271
284
|
}
|
|
272
|
-
|
|
285
|
+
checkUnsupportedDataProxy({ cmd: "init", urls: [args["--url"]] });
|
|
273
286
|
const outputDirName = args._[0];
|
|
274
287
|
if (outputDirName) {
|
|
275
288
|
throw Error("The init command does not take any argument.");
|
|
@@ -309,7 +322,7 @@ var Init = class _Init {
|
|
|
309
322
|
},
|
|
310
323
|
async (input2) => {
|
|
311
324
|
const url2 = input2["--url"];
|
|
312
|
-
const canConnect = await
|
|
325
|
+
const canConnect = await canConnectToDatabase(url2);
|
|
313
326
|
if (canConnect !== true) {
|
|
314
327
|
const { code, message } = canConnect;
|
|
315
328
|
if (code !== "P1003") {
|
|
@@ -320,7 +333,7 @@ var Init = class _Init {
|
|
|
320
333
|
}
|
|
321
334
|
}
|
|
322
335
|
}
|
|
323
|
-
const datasourceProvider2 =
|
|
336
|
+
const datasourceProvider2 = protocolToConnectorType(`${url2.split(":")[0]}:`);
|
|
324
337
|
return { datasourceProvider: datasourceProvider2, url: url2 };
|
|
325
338
|
}
|
|
326
339
|
).otherwise(() => {
|
|
@@ -332,7 +345,7 @@ var Init = class _Init {
|
|
|
332
345
|
const generatorProvider = args["--generator-provider"];
|
|
333
346
|
const previewFeatures = args["--preview-feature"];
|
|
334
347
|
const output = args["--output"];
|
|
335
|
-
const isPpgCommand = args["--db"] || datasourceProvider ===
|
|
348
|
+
const isPpgCommand = args["--db"] || datasourceProvider === PRISMA_POSTGRES_PROVIDER || args["--prompt"] || args["--vibe"];
|
|
336
349
|
let prismaPostgresDatabaseUrl;
|
|
337
350
|
let workspaceId = ``;
|
|
338
351
|
let projectId = ``;
|
|
@@ -342,9 +355,9 @@ var Init = class _Init {
|
|
|
342
355
|
let generatedSchema;
|
|
343
356
|
let generatedName;
|
|
344
357
|
if (isPpgCommand) {
|
|
345
|
-
const PlatformCommands = await import("./_-
|
|
358
|
+
const PlatformCommands = await import("./_-26BQWV6Z.js");
|
|
346
359
|
const credentials = await credentialsFile.load();
|
|
347
|
-
if (
|
|
360
|
+
if (isError(credentials))
|
|
348
361
|
throw credentials;
|
|
349
362
|
if (!credentials) {
|
|
350
363
|
if (args["--non-interactive"]) {
|
|
@@ -434,7 +447,7 @@ var Init = class _Init {
|
|
|
434
447
|
environmentId: project.defaultEnvironment.id,
|
|
435
448
|
displayName: `database-setup-prismaPostgres-api-key`
|
|
436
449
|
});
|
|
437
|
-
prismaPostgresDatabaseUrl = `${
|
|
450
|
+
prismaPostgresDatabaseUrl = `${PRISMA_POSTGRES_PROTOCOL}//accelerate.prisma-data.net/?api_key=${serviceToken.value}`;
|
|
438
451
|
spinner.succeed(successMessage("Your Prisma Postgres database is ready \u2705"));
|
|
439
452
|
} catch (error) {
|
|
440
453
|
spinner.fail(error instanceof Error ? error.message : "Something went wrong");
|
|
@@ -533,12 +546,12 @@ var Init = class _Init {
|
|
|
533
546
|
steps.push(`Define models in the schema.prisma file.`);
|
|
534
547
|
} else {
|
|
535
548
|
steps.push(
|
|
536
|
-
`Run ${green(
|
|
549
|
+
`Run ${green(getCommandWithExecutor("prisma db pull"))} to turn your database schema into a Prisma schema.`
|
|
537
550
|
);
|
|
538
551
|
}
|
|
539
552
|
steps.push(
|
|
540
553
|
`Run ${green(
|
|
541
|
-
|
|
554
|
+
getCommandWithExecutor("prisma generate")
|
|
542
555
|
)} to generate the Prisma Client. You can then start querying your database.`
|
|
543
556
|
);
|
|
544
557
|
steps.push(
|
|
@@ -565,21 +578,21 @@ var Init = class _Init {
|
|
|
565
578
|
const defaultOutput = `
|
|
566
579
|
\u2714 Your Prisma schema was created at ${green("prisma/schema.prisma")}
|
|
567
580
|
You can now open it in your favorite editor.
|
|
568
|
-
${warnings.length > 0 &&
|
|
581
|
+
${warnings.length > 0 && logger.should.warn() ? `
|
|
569
582
|
${warnings.join("\n")}
|
|
570
583
|
` : ""}
|
|
571
584
|
Next steps:
|
|
572
585
|
${steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}
|
|
573
586
|
|
|
574
587
|
More information in our documentation:
|
|
575
|
-
${
|
|
588
|
+
${link("https://pris.ly/d/getting-started")}
|
|
576
589
|
`;
|
|
577
590
|
return isPpgCommand ? printPpgInitOutput({ databaseUrl: prismaPostgresDatabaseUrl, workspaceId, projectId, environmentId }) : defaultOutput;
|
|
578
591
|
}
|
|
579
592
|
// help message
|
|
580
593
|
help(error) {
|
|
581
594
|
if (error) {
|
|
582
|
-
return new
|
|
595
|
+
return new HelpError(`
|
|
583
596
|
${bold2(red2(`!`))} ${error}
|
|
584
597
|
${_Init.help}`);
|
|
585
598
|
}
|