create-db 1.0.6 ā 1.0.8-pr51-DC-4933-env-flag-17282129083.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/index.js +56 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -194,6 +194,7 @@ Options:
|
|
|
194
194
|
${chalk.yellow("--json, -j")} Output machine-readable JSON and exit
|
|
195
195
|
${chalk.yellow("--list-regions")} List available regions and exit
|
|
196
196
|
${chalk.yellow("--help, -h")} Show this help message
|
|
197
|
+
${chalk.yellow("--env, -e")} Outputs DATABASE_URL to the terminal
|
|
197
198
|
|
|
198
199
|
Examples:
|
|
199
200
|
${chalk.gray(`npx ${CLI_NAME} --region us-east-1`)}
|
|
@@ -215,12 +216,14 @@ async function parseArgs() {
|
|
|
215
216
|
"list-regions",
|
|
216
217
|
"interactive",
|
|
217
218
|
"json",
|
|
219
|
+
"env",
|
|
218
220
|
];
|
|
219
221
|
const shorthandMap = {
|
|
220
222
|
r: "region",
|
|
221
223
|
i: "interactive",
|
|
222
224
|
h: "help",
|
|
223
225
|
j: "json",
|
|
226
|
+
e: "env",
|
|
224
227
|
};
|
|
225
228
|
|
|
226
229
|
const exitWithError = (message) => {
|
|
@@ -293,6 +296,28 @@ async function parseArgs() {
|
|
|
293
296
|
return { flags };
|
|
294
297
|
}
|
|
295
298
|
|
|
299
|
+
function validateFlagCombinations(flags) {
|
|
300
|
+
const conflictingFlags = [
|
|
301
|
+
["env", "json"],
|
|
302
|
+
["list-regions", "env"],
|
|
303
|
+
["list-regions", "json"],
|
|
304
|
+
["list-regions", "interactive"],
|
|
305
|
+
["list-regions", "region"],
|
|
306
|
+
];
|
|
307
|
+
|
|
308
|
+
for (const [flag1, flag2] of conflictingFlags) {
|
|
309
|
+
if (flags[flag1] && flags[flag2]) {
|
|
310
|
+
console.error(
|
|
311
|
+
chalk.red.bold(
|
|
312
|
+
`\nā Error: Cannot use --${flag1} and --${flag2} together.\n`
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
console.error(chalk.gray("Use --help or -h to see available options.\n"));
|
|
316
|
+
process.exit(1);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
296
321
|
export async function getRegions(returnJson = false) {
|
|
297
322
|
const url = `${CREATE_DB_WORKER_URL}/regions`;
|
|
298
323
|
const res = await fetch(url);
|
|
@@ -389,9 +414,9 @@ async function promptForRegion(defaultRegion, userAgent) {
|
|
|
389
414
|
return region;
|
|
390
415
|
}
|
|
391
416
|
|
|
392
|
-
async function createDatabase(name, region, userAgent,
|
|
417
|
+
async function createDatabase(name, region, userAgent, silent = false) {
|
|
393
418
|
let s;
|
|
394
|
-
if (!
|
|
419
|
+
if (!silent) {
|
|
395
420
|
s = spinner();
|
|
396
421
|
s.start("Creating your database...");
|
|
397
422
|
}
|
|
@@ -407,7 +432,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
407
432
|
});
|
|
408
433
|
|
|
409
434
|
if (resp.status === 429) {
|
|
410
|
-
if (
|
|
435
|
+
if (silent) {
|
|
411
436
|
return {
|
|
412
437
|
error: "rate_limit_exceeded",
|
|
413
438
|
message:
|
|
@@ -439,7 +464,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
439
464
|
raw = await resp.text();
|
|
440
465
|
result = JSON.parse(raw);
|
|
441
466
|
} catch (e) {
|
|
442
|
-
if (
|
|
467
|
+
if (silent) {
|
|
443
468
|
return {
|
|
444
469
|
error: "invalid_json",
|
|
445
470
|
message: "Unexpected response from create service.",
|
|
@@ -488,7 +513,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
488
513
|
const claimUrl = `${CLAIM_DB_WORKER_URL}?projectID=${projectId}&utm_source=${userAgent}&utm_medium=cli`;
|
|
489
514
|
const expiryDate = new Date(Date.now() + 24 * 60 * 60 * 1000);
|
|
490
515
|
|
|
491
|
-
if (
|
|
516
|
+
if (silent && !result.error) {
|
|
492
517
|
const jsonResponse = {
|
|
493
518
|
connectionString: prismaConn,
|
|
494
519
|
directConnectionString: directConn,
|
|
@@ -507,7 +532,7 @@ async function createDatabase(name, region, userAgent, returnJson = false) {
|
|
|
507
532
|
}
|
|
508
533
|
|
|
509
534
|
if (result.error) {
|
|
510
|
-
if (
|
|
535
|
+
if (silent) {
|
|
511
536
|
return {
|
|
512
537
|
error: "api_error",
|
|
513
538
|
message: result.error.message || "Unknown error",
|
|
@@ -593,6 +618,8 @@ async function main() {
|
|
|
593
618
|
|
|
594
619
|
const { flags } = await parseArgs();
|
|
595
620
|
|
|
621
|
+
validateFlagCombinations(flags);
|
|
622
|
+
|
|
596
623
|
let userAgent;
|
|
597
624
|
const userEnvVars = readUserEnvFile();
|
|
598
625
|
if (userEnvVars.PRISMA_ACTOR_NAME && userEnvVars.PRISMA_ACTOR_PROJECT) {
|
|
@@ -670,6 +697,29 @@ async function main() {
|
|
|
670
697
|
}
|
|
671
698
|
}
|
|
672
699
|
|
|
700
|
+
if (flags.env) {
|
|
701
|
+
try {
|
|
702
|
+
if (chooseRegionPrompt) {
|
|
703
|
+
region = await promptForRegion(region, userAgent);
|
|
704
|
+
} else {
|
|
705
|
+
await validateRegion(region, true);
|
|
706
|
+
}
|
|
707
|
+
const result = await createDatabase(name, region, userAgent, true);
|
|
708
|
+
if (result.error) {
|
|
709
|
+
console.error(result.message || "Unknown error");
|
|
710
|
+
process.exit(1);
|
|
711
|
+
}
|
|
712
|
+
process.stdout.write(`DATABASE_URL="${result.directConnectionString}"`);
|
|
713
|
+
process.stderr.write(
|
|
714
|
+
"\n\n# Claim your database at: " + result.claimUrl
|
|
715
|
+
);
|
|
716
|
+
process.exit(0);
|
|
717
|
+
} catch (e) {
|
|
718
|
+
console.error(e?.message || String(e));
|
|
719
|
+
process.exit(1);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
673
723
|
intro(chalk.cyan.bold("š Creating a Prisma Postgres database"));
|
|
674
724
|
log.message(
|
|
675
725
|
chalk.white(`Provisioning a temporary database in ${region}...`)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-db",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8-pr51-DC-4933-env-flag-17282129083.0",
|
|
4
4
|
"description": "Instantly create a temporary Prisma Postgres database with one command, then claim and persist it in your Prisma Data Platform project when ready.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "",
|