@prisma/cli-dev 0.5.0 → 0.5.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.
- package/dist/index.js +12 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{runMain as
|
|
2
|
+
import{runMain as fe}from"citty";import{unstable_startServer as ae}from"@prisma/dev";import{defineCommand as de}from"citty";function _(e){let o,t,i=new Promise((r,p)=>{o=r,t=p}),a=r=>{a=l=null,t(r),e?.onRejected?.(r),e?.onFulfilled?.()},l=r=>{l=a=null,o(r),e?.onResolved?.(r),e?.onFulfilled?.()};return{isFulfilled:()=>l===a,promise:i,reject:r=>a?.(r),resolve:r=>l?.(r)}}import{consola as u,LogLevels as le}from"consola";import{hasTTY as ce,isCI as pe,process as V}from"std-env";import ue from"yocto-spinner";var O="0.5.1";import{DEFAULT_DATABASE_PORT as I,DEFAULT_SERVER_PORT as D,DEFAULT_SHADOW_DATABASE_PORT as N}from"@prisma/dev";var s={database:"db-port",server:"port",shadow_database:"shadow-db-port"},k={[s.database]:{alias:"P",description:`Port number the database server will listen on. Defaults to \`${I}\`.`,required:!1,type:"string"},debug:{default:!1,description:"Enable debug logging. Defaults to `false`.",required:!1,type:"boolean"},name:{alias:"n",default:"default",description:"Name of the server. Helps keep state isolated between different projects. Defaults to `default`.",required:!1,type:"string"},[s.server]:{alias:"p",description:`Main port number the Prisma Dev server will listen on. Defaults to \`${D}\`.`,required:!1,type:"string"},[s.shadow_database]:{description:`Port number the shadow database server will listen on. Defaults to \`${N}\`.`,required:!1,type:"string"}},J=/^[a-zA-Z0-9-_]+$/;function L(e){let{[s.server]:o,[s.database]:t,[s.shadow_database]:i,debug:a,name:l}=e.args,r=t?Number(t):I,p=o?Number(o):D,d=i?Number(i):N;return o&&isNaN(p)?(console.error(`Invalid server port number provided. Please provide a valid port number in \`--${s.server}\`.`),process.exit(1)):t&&isNaN(r)?(console.error(`Invalid database port number provided. Please provide a valid port number in \`--${s.database}\`.`),process.exit(1)):i&&isNaN(d)?(console.error(`Invalid shadow database port number provided. Please provide a valid port number in \`--${s.shadow_database}\`.`),process.exit(1)):p===r?(console.error(`The server port and database port cannot be the same. Please provide different port numbers in \`--${s.server}\` and/or \`--${s.database}\`.`),process.exit(1)):r===d?(console.error(`The database port and shadow database port cannot be the same. Please provide different port numbers in \`--${s.database}\` and/or \`--${s.shadow_database}\`.`),process.exit(1)):p===d?(console.error(`The server port and shadow database port cannot be the same. Please provide different port numbers in \`--${s.server}\` and/or \`--${s.shadow_database}\`.`),process.exit(1)):J.test(l)?{databasePort:r,debug:a,name:l,serverPort:p,shadowDatabasePort:d}:(console.error("Invalid name provided. The name can only contain letters, numbers, dashes, and underscores. Please provide a valid name in `--name`."),process.exit(1))}import{PortNotAvailableError as Z}from"@prisma/dev";function M(e){throw console.error(e instanceof Z?`Prisma Dev Error: port number \`${e.port}\` is already in use. Please pass a different port number in the \`--${s[e.service]}\` option.`:e),process.exitCode||=1,e}import{isCancel as ee,SelectKeyPrompt as oe}from"@clack/core";import{box as te,colorize as re}from"consola/utils";import{process as h}from"std-env";var ne=[{value:"q",label:"uit"},{value:"h",label:"ttp url"},{value:"t",label:"cp urls"}],P=4;function G(e){let o=new oe({options:ne,render:se,signal:e?.abortSignal});return{clearPrompt(){h.stdout.moveCursor(0,-P),h.stdout.cursorTo(0),h.stdout.clearScreenDown()},prompt:o,respond(t){if(ee(t)||t==="q"){e?.onQuit?.();return}e?.onOption?.[t]?.()}}}function se(){let e=`${this.options.map(o=>`[${re("cyan",o.value)}]${o.label}`).join(" ")}`;return te(e,{style:{borderColor:"blackBright",padding:0}})}import{colorize as c,stripAnsi as ie}from"consola/utils";import{process as B}from"std-env";var v=c("white",c("bgBlack"," prisma dev "));function U(e){if(e.length===0)return"";let o=[...e].sort();return o.length>1&&o.every((t,i)=>i===0||t===o[i-1]+1)?`${n(o[0])}-${n(o.at(-1))}`:e.map(n).join(", ")}function b(e,o){return c("bgBlack",`${n(e)}="${o}"`)}function j(e){return e=new URL(e),`${F(e.protocol)}//${n(e.hostname)}:${n(e.port)}${m(e.pathname)}${m(e.search)}`}function S(e){return e=new URL(e),`${F(e.protocol)}${m(`//${e.username}:${e.password}@`)}${n(e.hostname)}${m(":")}${n(e.port)}${m(e.pathname)}${m(e.search)}`}function n(e){return c("cyan",e)}function F(e){return c("magenta",e)}function m(e){return c("white",e)}function $(e){return c("italic",c("dim",c("greenBright",`# ${e}`)))}function w(e){return c("bgBlack",`${T()}
|
|
3
3
|
${e.split(`
|
|
4
|
-
`).map(o
|
|
4
|
+
`).map(o=>` ${o}${T(ie(o).length+1)}`).join(`
|
|
5
5
|
`)}
|
|
6
|
-
${
|
|
6
|
+
${T()}`)}function T(e=0){return e%=B.stdout.columns," ".repeat(B.stdout.columns-e)}function q(e){let o={shutdownAlreadyStarted:!1};process.once("SIGINT",H("SIGINT",e,o)),process.once("SIGTERM",H("SIGTERM",e,o))}function H(e,o,t){let{debug:i,onFailure:a,onSuccess:l,server:r}=o;return()=>{if(t.shutdownAlreadyStarted){i&&console.debug(`Received ${e} signal, ignoring.`);return}t.shutdownAlreadyStarted=!0,i&&console.debug(`${e} signal receieved.`),console.log(`
|
|
7
7
|
Closing Prisma Dev...
|
|
8
|
-
`),process.exitCode=e==="SIGINT"?130:143,r.close().then(()=>{i&&console.debug("Prisma Dev server closed."),e==="SIGINT"&&(process.exitCode=0),l()}).catch(a)}}var
|
|
8
|
+
`),process.exitCode=e==="SIGINT"?130:143,r.close().then(()=>{i&&console.debug("Prisma Dev server closed."),e==="SIGINT"&&(process.exitCode=0),l()}).catch(a)}}var me={description:"Spin up a local Prisma Postgres database",name:"dev",version:O},g="\v",y=de({args:k,meta:me,run:async e=>{let{subCommands:o}=e.cmd,t=o?e.rawArgs.find(d=>!d.startsWith("-")):void 0;if(t&&t!==g&&t in o)return;let{debug:i,name:a,serverPort:l,...r}=L(e),p=ue().start(` Starting ${v} server ${n(a)}...${`
|
|
9
|
+
`.repeat(P+3)}`);try{let d=await ae({...r,debug:i,name:a,persistenceMode:"stateful",port:l}),R=new AbortController,{isFulfilled:W,promise:X,reject:x,resolve:A}=_({onRejected:()=>R.abort()});q({debug:i,onFailure:x,onSuccess:A,server:d}),V.on?.("uncaughtException",f=>{if("code"in f&&f.code==="ECONNRESET"){i&&console.error("uncaught ECONNRESET from PGLite");return}x(f)}),p.success(` Great Success! \u{1F609}\u{1F44D}
|
|
9
10
|
|
|
10
|
-
Your ${v} server ${n(a)} is ready and listening on ports ${
|
|
11
|
+
Your ${v} server ${n(a)} is ready and listening on ports ${U([l,r.databasePort,r.shadowDatabasePort])}.`);let C=`\u{1F50C} To connect to your local Prisma Postgres database via HTTP + Prisma ORM
|
|
11
12
|
use the following connection string:
|
|
12
13
|
|
|
13
|
-
${w(
|
|
14
|
+
${w(`${$("\u{1F4C4} .env:")}
|
|
14
15
|
|
|
15
|
-
${b("DATABASE_URL",
|
|
16
|
+
${b("DATABASE_URL",j(d.ppg.url))}`)}
|
|
16
17
|
|
|
17
|
-
\u2728 The ${n("api_key")} above does not contain any sensitive information.`,
|
|
18
|
+
\u2728 The ${n("api_key")} above does not contain any sensitive information.`,E=`\u{1F50C} To connect to your local Prisma Postgres database via TCP + Prisma ORM
|
|
18
19
|
use the following connection strings:
|
|
19
20
|
|
|
20
|
-
${w(
|
|
21
|
+
${w(`${$("\u{1F4C4} .env:")}
|
|
21
22
|
|
|
22
23
|
${b("DATABASE_URL",S(d.database.prismaORMConnectionString))}
|
|
23
24
|
|
|
@@ -26,7 +27,7 @@ ${b("SHADOW_DATABASE_URL",S(d.shadowDatabase.prismaORMConnectionString))}`)}
|
|
|
26
27
|
\u{1F418} You can also use the TCP ${n("DATABASE_URL")} with the ${n("pg")} or ${n("postgres.js")} JavaScript drivers!
|
|
27
28
|
|
|
28
29
|
Set the maximum number of connections to ${n(1)}, connect timeout to ${n(0)} and
|
|
29
|
-
idle timeout to the smallest positive value supported.`;if(!ce
|
|
30
|
+
idle timeout to the smallest positive value supported.`;if(!pe&&ce)for(;!W();){let{clearPrompt:f,prompt:Y,respond:z}=G({abortSignal:R.signal,onOption:{h:()=>u.log(C),t:()=>u.log(E)},onQuit:A}),K=await Y.prompt();f(),z(K)}else u.log(C),u.log(E);await X,u.log(`\u{1F44B} Buh Bye!
|
|
30
31
|
|
|
31
32
|
Your ${v} server ${n(a)} has been closed successfully.
|
|
32
|
-
`),
|
|
33
|
+
`),V.exit?.(0)}catch(d){M(d)}},setup(e){e.args.debug&&(u.level=le.debug),u.options.formatOptions.date=!1},subCommands:{[g]:{},ls:()=>import("./list-4ABJMPY2.js").then(e=>e.ListCommand)}});async function Ve(e,o){let[t]=e;t==="-v"&&(e[0]="--version"),t&&!(t in y.subCommands)&&t!=="--help"&&t!=="-h"&&t!=="--version"&&t!=="-v"&&e.unshift(g),await fe(y,{rawArgs:e})}export{Ve as run};
|