@prisma/cli-dev 0.13.2 → 0.14.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.
@@ -0,0 +1,30 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{a as v,b as a,c as S,e as u,f as x,h as b,i as R,j as C}from"./chunk-SZYQ5TDI.js";import{b as g,c as w,d as m}from"./chunk-4QNO2WQL.js";import{b as G}from"./chunk-M6TFCQLD.js";import{fork as L}from"child_process";import{createRequire as U}from"module";import{ServerState as _}from"@prisma/dev/internal/state";var N=U(import.meta.url).resolve("@prisma/dev/internal/daemon");async function jt(e){let t,o,c=new Promise((i,p)=>{t=i,o=p}),s=typeof e=="string"?e:e.name,n=L(N,[s],{detached:!0,stdio:"ignore"});n.once("error",i=>{m.error(i)}),n.once("message",i=>{let{type:p}=i;if(p==="error")return o(i.error);if(p==="started")return t(i.server);o(`Unknown message type: "${p}"`)});try{return await c}catch(i){if(typeof i=="string"&&i.includes("is already running")){if(typeof e!="string")return{...e.exports,name:s};let p=await _.fromServerDump({name:s});if(!p)throw new Error(`Failed to retrieve the status of the running server "${s}".`);return{...p.exports,name:s}}throw i}finally{n.disconnect(),n.unref(),n.removeAllListeners()}}import{setTimeout as _t}from"timers/promises";import l from"process";import{stripVTControlCharacters as Ot}from"util";var h={};G(h,{bgBlack:()=>st,bgBlue:()=>lt,bgBlueBright:()=>wt,bgCyan:()=>mt,bgCyanBright:()=>Ct,bgGray:()=>dt,bgGreen:()=>ct,bgGreenBright:()=>$t,bgMagenta:()=>ht,bgMagentaBright:()=>Rt,bgRed:()=>at,bgRedBright:()=>Pt,bgWhite:()=>ut,bgWhiteBright:()=>Bt,bgYellow:()=>pt,bgYellowBright:()=>Tt,black:()=>z,blue:()=>et,blueBright:()=>xt,bold:()=>W,cyan:()=>ot,cyanBright:()=>bt,dim:()=>Y,gray:()=>it,green:()=>Z,greenBright:()=>ft,hidden:()=>K,inverse:()=>j,italic:()=>q,magenta:()=>rt,magentaBright:()=>St,overline:()=>Q,red:()=>J,redBright:()=>gt,reset:()=>V,strikethrough:()=>X,underline:()=>F,white:()=>nt,whiteBright:()=>yt,yellow:()=>tt,yellowBright:()=>vt});import k from"tty";var H=k?.WriteStream?.prototype?.hasColors?.()??!1,r=(e,t)=>{if(!H)return s=>s;let o=`\x1B[${e}m`,c=`\x1B[${t}m`;return s=>{let n=s+"",i=n.indexOf(c);if(i===-1)return o+n+c;let p=o,d=0;for(;i!==-1;)p+=n.slice(d,i)+o,d=i+c.length,i=n.indexOf(c,d);return p+=n.slice(d)+c,p}},V=r(0,0),W=r(1,22),Y=r(2,22),q=r(3,23),F=r(4,24),Q=r(53,55),j=r(7,27),K=r(8,28),X=r(9,29),z=r(30,39),J=r(31,39),Z=r(32,39),tt=r(33,39),et=r(34,39),rt=r(35,39),ot=r(36,39),nt=r(37,39),it=r(90,39),st=r(40,49),at=r(41,49),ct=r(42,49),pt=r(43,49),lt=r(44,49),ht=r(45,49),mt=r(46,49),ut=r(47,49),dt=r(100,49),gt=r(91,39),ft=r(92,39),vt=r(93,39),xt=r(94,39),St=r(95,39),bt=r(96,39),yt=r(97,39),Pt=r(101,49),$t=r(102,49),Tt=r(103,49),wt=r(104,49),Rt=r(105,49),Ct=r(106,49),Bt=r(107,49);var f=l.platform!=="win32"||!!l.env.WT_SESSION||l.env.TERM_PROGRAM==="vscode",It=e=>!!(e.isTTY&&l.env.TERM!=="dumb"&&!("CI"in l.env)),Et=h.blue(f?"\u2139":"i"),At=h.green(f?"\u2714":"\u221A"),Mt=h.yellow(f?"\u26A0":"\u203C"),Dt=h.red(f?"\u2716":"\xD7"),Gt={frames:f?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"],interval:80},y=class{#p;#l;#n=-1;#i;#r;#t;#s;#h=0;#o;#e;#d=0;#m=!1;constructor(t={}){let o=t.spinner??Gt;this.#p=o.frames,this.#l=o.interval,this.#r=t.text??"",this.#t=t.stream??l.stderr,this.#s=t.color??"cyan",this.#e=It(this.#t),this.#o=this.#b.bind(this)}start(t){return t&&(this.#r=t),this.isSpinning?this:(this.#m=!0,this.#f(),this.#c(),this.#x(),this.#e&&(this.#i=setInterval(()=>{this.#c()},this.#l)),this)}stop(t){return this.isSpinning?(this.#m=!1,this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#v(),this.clear(),this.#S(),t&&this.#t.write(`${t}
3
+ `),this):this}#a(t,o){return this.stop(`${t} ${o??this.#r}`)}success(t){return this.#a(At,t)}error(t){return this.#a(Dt,t)}warning(t){return this.#a(Mt,t)}info(t){return this.#a(Et,t)}get isSpinning(){return this.#m}get text(){return this.#r}set text(t){this.#r=t??"",this.#c()}get color(){return this.#s}set color(t){this.#s=t,this.#c()}clear(){if(!this.#e)return this;this.#t.cursorTo(0);for(let t=0;t<this.#h;t++)t>0&&this.#t.moveCursor(0,-1),this.#t.clearLine(1);return this.#h=0,this}#c(){let t=Date.now();(this.#n===-1||t-this.#d>=this.#l)&&(this.#n=++this.#n%this.#p.length,this.#d=t);let o=h[this.#s]??h.cyan,c=this.#p[this.#n],s=`${o(c)} ${this.#r}`;this.#e||(s+=`
4
+ `),this.clear(),this.#u(s),this.#e&&(this.#h=this.#g(s))}#u(t){this.#t.write(t)}#g(t){let o=this.#t.columns??80,c=Ot(t).split(`
5
+ `),s=0;for(let n of c)s+=Math.max(1,Math.ceil(n.length/o));return s}#f(){this.#e&&this.#u("\x1B[?25l")}#v(){this.#e&&this.#u("\x1B[?25h")}#x(){l.once("SIGINT",this.#o),l.once("SIGTERM",this.#o)}#S(){l.off("SIGINT",this.#o),l.off("SIGTERM",this.#o)}#b(t){this.isSpinning&&this.stop();let o=t==="SIGINT"?130:t==="SIGTERM"?143:1;l.exit(o)}};function P(e){return new y(e)}var Lt=[{value:"h",label:"print http url"},{value:"t",label:"print tcp urls"},{value:"q",label:"quit"}],$=6;function B(e){let t=new C({debug:e?.debug,options:Lt,render:Ut,signal:e?.abortSignal});return{clearPrompt(){v.stdout.moveCursor(0,-$),v.stdout.cursorTo(0),v.stdout.clearScreenDown()},prompt:t,respond:async o=>{if(R(o)||o==="q")return await e?.onQuit?.();await e?.onOption?.[o]?.()}}}function Ut(){let e=`${this.options.map(t=>`${g("inverse",` ${t.value} `)} ${t.label}`).join(" ")}`;return w(e,{style:{borderColor:"blackBright",borderStyle:"solid"},title:" \u25B3 press a key \u25B3 "})}function ge(e){let t=P();return{renderContent:Nt,renderIntro:()=>kt(e,t),renderOutro:()=>Promise.resolve(Ht(e)),spinner:t}}async function Nt(e){let{abortSignal:t,debug:o,isClosed:c,onQuit:s,server:n,spinner:i}=e;if(i.success(` Great Success! \u{1F609}\u{1F44D}
6
+
7
+ Your ${x} server ${a(n.name)} is ready and listening on ports ${Vt([new URL(n.http.url).port,new URL(n.database.connectionString).port,new URL(n.shadowDatabase.connectionString).port])}.`),!b){m.log(O(n)),m.log(I(n));return}for(;!c();){let{clearPrompt:p,prompt:d,respond:M}=B({abortSignal:t,debug:o,onOption:{h:()=>m.log(O(n)),t:()=>m.log(I(n))},onQuit:s}),D=await d.prompt();p(),t.aborted||await M(D)}}async function kt(e,t){t.start(` Starting ${x} server ${a(e)}...${`
8
+ `.repeat($+3)}`),b&&await _t(250)}function Ht(e){m.log(`\u{1F44B} Buh Bye!
9
+
10
+ Your ${x} server ${a(e)} has been closed successfully.
11
+ `)}function O(e){return`\u{1F50C} To connect to your local Prisma Postgres database via HTTP + Prisma ORM
12
+ use the following connection string:
13
+
14
+ ${A("\u{1F4C4} .env:")}
15
+
16
+ ${T("DATABASE_URL",Wt(e.ppg.url))}
17
+
18
+ \u2728 The ${a("api_key")} above does not contain any sensitive information.`}function I(e){return`\u{1F50C} To connect to your local Prisma Postgres database via TCP + Prisma ORM
19
+ use the following connection strings:
20
+
21
+ ${A("\u{1F4C4} .env:")}
22
+
23
+ ${T("DATABASE_URL",E(e.database.prismaORMConnectionString))}
24
+
25
+ ${T("SHADOW_DATABASE_URL",E(e.shadowDatabase.prismaORMConnectionString))}
26
+
27
+ \u{1F418} You can also use the TCP ${a("DATABASE_URL")} with the ${a("pg")} or ${a("postgres.js")} JavaScript drivers!
28
+
29
+ Set the maximum number of connections to ${a(1)}, connect timeout to ${a(0)} and
30
+ idle timeout to the smallest positive value supported.`}function Vt(e){if(e.length===0)return"";let t=[...e].map(Number).sort();return t.length>1&&t.every((o,c)=>c===0||o===t[c-1]+1)?`${a(t[0])}-${a(t.at(-1))}`:e.map(a).join(", ")}function T(e,t){return`${a(e)}="${t}"`}function Wt(e){return e=new URL(e),`${S(e.protocol)}//${a(e.hostname)}:${a(e.port)}${u(e.pathname)}${u(e.search)}`}function E(e){return e=new URL(e),`${S(e.protocol)}${u(`//${e.username}:${e.password}@`)}${a(e.hostname)}${u(":")}${a(e.port)}${u(e.pathname)}${u(e.search)}`}function A(e){return g("italic",g("dim",g("green",`# ${e}`)))}export{jt as a,ge as b,O as c,I as d,Vt as e};
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as R,d as E}from"./chunk-ZPUL6EAC.js";import{a as p,b as u,f as x}from"./chunk-SZYQ5TDI.js";import{a as y,d,e as P,f as C}from"./chunk-4QNO2WQL.js";import"./chunk-M6TFCQLD.js";import{startPrismaDevServer as H}from"@prisma/dev";function N(e){let o,r,t=new Promise((n,l)=>{o=n,r=l}),s=n=>{s=i=null,r(n),e?.onRejected?.(n),e?.onFulfilled?.()},i=n=>{i=s=null,o(n),e?.onResolved?.(n),e?.onFulfilled?.()};return{isFulfilled:()=>i===s,promise:t,reject:n=>s?.(n),resolve:n=>i?.(n)}}var I="0.13.2";var a={database:"db-port",server:"port",shadow_database:"shadow-db-port"},A={...C,[a.database]:{alias:"P",description:"Port number the database server will listen on.",required:!1,type:"string"},name:{alias:"n",default:"default",description:"Name of the server. Helps keep state isolated between different projects. Defaults to `default`.",required:!1,type:"string"},[a.server]:{alias:"p",description:"Main port number the Prisma Dev server will listen on.",required:!1,type:"string"},[a.shadow_database]:{description:"Port number the shadow database server will listen on.",required:!1,type:"string"}},j=/^[a-zA-Z0-9-_]+$/;function T(e){let{[a.server]:o,[a.database]:r,[a.shadow_database]:t,debug:s,name:i}=e.args,n=r?Number(r):void 0,l=o?Number(o):void 0,c=t?Number(t):void 0;return o&&Number.isNaN(l)?(console.error(`Invalid server port number provided. Please provide a valid port number in \`--${a.server}\`.`),process.exit(1)):r&&Number.isNaN(n)?(console.error(`Invalid database port number provided. Please provide a valid port number in \`--${a.database}\`.`),process.exit(1)):t&&Number.isNaN(c)?(console.error(`Invalid shadow database port number provided. Please provide a valid port number in \`--${a.shadow_database}\`.`),process.exit(1)):l!=null&&l===n?(console.error(`The server port and database port cannot be the same. Please provide different port numbers in \`--${a.server}\` and/or \`--${a.database}\`.`),process.exit(1)):n!=null&&n===c?(console.error(`The database port and shadow database port cannot be the same. Please provide different port numbers in \`--${a.database}\` and/or \`--${a.shadow_database}\`.`),process.exit(1)):l!=null&&l===c?(console.error(`The server port and shadow database port cannot be the same. Please provide different port numbers in \`--${a.server}\` and/or \`--${a.shadow_database}\`.`),process.exit(1)):j.test(i)?{databasePort:n,debug:s,name:i,serverPort:l,shadowDatabasePort:c}:(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 F,ServerAlreadyRunningError as L}from"@prisma/dev";async function f(e,o,r){if(e instanceof L)try{let s=await e.server;if(!s)return await f("Something went wrong, try again!",o,r);o.warning(` Skipped! \u{1F60C}
2
+ import{a as x,b as N,e as I}from"./chunk-FODIIZRP.js";import{a as l,b as f,f as E}from"./chunk-SZYQ5TDI.js";import{a as C,d,e as P,f as R}from"./chunk-4QNO2WQL.js";import"./chunk-M6TFCQLD.js";import{startPrismaDevServer as B}from"@prisma/dev";function A(e){let t,r,o=new Promise((s,p)=>{t=s,r=p}),n=s=>{n=i=null,r(s),e?.onRejected?.(s),e?.onFulfilled?.()},i=s=>{i=n=null,t(s),e?.onResolved?.(s),e?.onFulfilled?.()};return{isFulfilled:()=>i===n,promise:o,reject:s=>n?.(s),resolve:s=>i?.(s)}}var T="0.14.0";var a={database:"db-port",server:"port",shadow_database:"shadow-db-port"},O={...R,[a.database]:{alias:"P",description:"Port number the database server will listen on.",required:!1,type:"string"},detach:{alias:"d",description:"Run the server in the background.",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"},[a.server]:{alias:"p",description:"Main port number the Prisma Dev server will listen on.",required:!1,type:"string"},[a.shadow_database]:{description:"Port number the shadow database server will listen on.",required:!1,type:"string"}},L=/^[a-zA-Z0-9-_]+$/;function k(e){let{[a.server]:t,[a.database]:r,[a.shadow_database]:o,debug:n,detach:i,name:s}=e.args,p=r?Number(r):void 0,c=t?Number(t):void 0,u=o?Number(o):void 0;return t&&Number.isNaN(c)?(console.error(`Invalid server port number provided. Please provide a valid port number in \`--${a.server}\`.`),process.exit(1)):r&&Number.isNaN(p)?(console.error(`Invalid database port number provided. Please provide a valid port number in \`--${a.database}\`.`),process.exit(1)):o&&Number.isNaN(u)?(console.error(`Invalid shadow database port number provided. Please provide a valid port number in \`--${a.shadow_database}\`.`),process.exit(1)):c!=null&&c===p?(console.error(`The server port and database port cannot be the same. Please provide different port numbers in \`--${a.server}\` and/or \`--${a.database}\`.`),process.exit(1)):p!=null&&p===u?(console.error(`The database port and shadow database port cannot be the same. Please provide different port numbers in \`--${a.database}\` and/or \`--${a.shadow_database}\`.`),process.exit(1)):c!=null&&c===u?(console.error(`The server port and shadow database port cannot be the same. Please provide different port numbers in \`--${a.server}\` and/or \`--${a.shadow_database}\`.`),process.exit(1)):L.test(s)?{databasePort:p,debug:n,detach:i,name:s,serverPort:c,shadowDatabasePort:u}:(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 q,ServerAlreadyRunningError as H}from"@prisma/dev";async function v(e,t,r){if(e instanceof H)try{let n=await e.server;if(!n)return await v("Something went wrong, try again!",t,r);t.warning(` Skipped! \u{1F60C}
3
3
 
4
- Your ${x} server ${u(s.name)} is already running and listening on ports ${E([s.port,s.databasePort,s.shadowDatabasePort])}.
4
+ Your ${E} server ${f(n.name)} is already running and listening on ports ${I([n.port,n.databasePort,n.shadowDatabasePort])}.
5
5
 
6
- To start a different server, use the ${`${u("-n")}/${u("--name")}`} flag with another name.
7
- `);return}catch(s){return await f(s,o,r)}let{args:t}=r;throw d.error(e instanceof F?`Prisma Dev Error: port number \`${e.port}\` is already in use. Please pass a different port number in the \`--${t.port===String(e.port)?"port":t.databasePort===String(e.port)?"database":"shadow_database"}\` option.`:e),p.exitCode||=1,e}function O(e){p.on?.("uncaughtException",o=>{if("code"in o&&o.code==="ECONNRESET"){e?.debug&&d.error("uncaught ECONNRESET");return}e?.onError?.(o)})}function k(e){let o={shutdownAlreadyStarted:!1};p.once?.("SIGINT",_("SIGINT",e,o)),p.once?.("SIGTERM",_("SIGTERM",e,o))}function _(e,o,r){let{debug:t,onFailure:s,onSuccess:i,server:n}=o;return()=>{if(r.shutdownAlreadyStarted){t&&d.debug(`Received ${e} signal, ignoring.`);return}r.shutdownAlreadyStarted=!0,t&&d.debug(`${e} signal receieved.`),t&&d.log(`
6
+ To start a different server, use the ${`${f("-n")}/${f("--name")}`} flag with another name.
7
+ `);return}catch(n){return await v(n,t,r)}let{args:o}=r;throw d.error(e instanceof q?`Prisma Dev Error: port number \`${e.port}\` is already in use. Please pass a different port number in the \`--${o.port===String(e.port)?"port":o.databasePort===String(e.port)?"database":"shadow_database"}\` option.`:e),l.exitCode||=1,e}function _(e){l.on?.("uncaughtException",t=>{if("code"in t&&t.code==="ECONNRESET"){e?.debug&&d.error("uncaught ECONNRESET");return}e?.onError?.(t)})}function M(e){let t={shutdownAlreadyStarted:!1};l.once?.("SIGINT",$("SIGINT",e,t)),l.once?.("SIGTERM",$("SIGTERM",e,t))}function $(e,t,r){let{debug:o,onFailure:n,onSuccess:i,server:s}=t;return()=>{if(r.shutdownAlreadyStarted){o&&d.debug(`Received ${e} signal, ignoring.`);return}r.shutdownAlreadyStarted=!0,o&&d.debug(`${e} signal receieved.`),o&&d.log(`
8
8
  Closing Prisma Dev...
9
- `),p.exitCode=e==="SIGINT"?130:143,n.close().then(()=>{t&&d.debug("Prisma Dev server closed."),e==="SIGINT"&&(p.exitCode=0),i()}).catch(s)}}var q={description:"Spin up a local Prisma Postgres database",name:"prisma dev",version:I},v="\v",b={args:A,meta:q,run:async e=>{let{subCommands:o}=e.cmd,r=o?e.rawArgs.find(m=>!m.startsWith("-")):void 0;if(r&&r!==v&&r in o)return;let{debug:t,name:s,serverPort:i,...n}=T(e),{renderContent:l,renderIntro:c,renderOutro:$,spinner:h}=R(s);try{let m=await B({...n,debug:t,name:s,port:i,renderIntro:c}),g=new AbortController,{isFulfilled:M,promise:G,reject:w,resolve:S}=N({onFulfilled:()=>g.abort()});k({debug:t,onFailure:w,onSuccess:S,server:m}),O({debug:t,onError:w}),await l({abortSignal:g.signal,debug:t,isClosed:M,onQuit:async()=>{await m.close(),S()},server:m,spinner:h}),await G,await $(),p.exitCode||=0}catch(m){await f(m,h,e)}},setup(e){e.args.debug&&(d.level=y.debug),d.options.formatOptions.date=!1},subCommands:{[v]:{},ls:()=>import("./list-URPVLN6C.js").then(e=>e.ListCommand),rm:()=>import("./remove-LXPTJUNN.js").then(e=>e.RemoveCommand),start:()=>import("./start-M7MH244V.js").then(e=>e.StartCommand),stop:()=>import("./stop-LEO7ZSSO.js").then(e=>e.StopCommand)}};async function B(e){let{renderIntro:o,...r}=e,[,t]=await Promise.allSettled([e.renderIntro(),H({...r,persistenceMode:"stateful"})]);if(t.status==="rejected")throw t.reason;return t.value}async function be(e,o){let[r]=e;r==="-v"&&(e[0]="--version"),r&&!(r in b.subCommands)&&r!=="--help"&&r!=="-h"&&r!=="--version"&&r!=="-v"&&e.unshift(v),await P(b,{rawArgs:e})}export{be as run};
9
+ `),l.exitCode=e==="SIGINT"?130:143,s.close().then(()=>{o&&d.debug("Prisma Dev server closed."),e==="SIGINT"&&(l.exitCode=0),i()}).catch(n)}}var U={description:"Create and run a new server",name:"prisma dev",version:T},b="\v",h={args:O,meta:U,run:async e=>{let{subCommands:t}=e.cmd,r=t?e.rawArgs.find(m=>!m.startsWith("-")):void 0;if(r&&r!==b&&r in t)return;let{debug:o,detach:n,name:i,serverPort:s,...p}=k(e);if(n){let m=await x(i);return d.log(m.database.connectionString)}let{renderContent:c,renderIntro:u,renderOutro:G,spinner:g}=N(i);try{let m=await V({...p,debug:o,name:i,port:s,renderIntro:u}),w=new AbortController,{isFulfilled:D,promise:j,reject:S,resolve:y}=A({onFulfilled:()=>w.abort()});M({debug:o,onFailure:S,onSuccess:y,server:m}),_({debug:o,onError:S}),await c({abortSignal:w.signal,debug:o,isClosed:D,onQuit:async()=>{await m.close(),y()},server:m,spinner:g}),await j,await G(),l.exitCode||=0}catch(m){await v(m,g,e)}},setup(e){e.args.debug&&(d.level=C.debug),d.options.formatOptions.date=!1},subCommands:{[b]:{},ls:()=>import("./list-URPVLN6C.js").then(e=>e.ListCommand),rm:()=>import("./remove-LXPTJUNN.js").then(e=>e.RemoveCommand),start:()=>import("./start-5XKEVPIK.js").then(e=>e.StartCommand),stop:()=>import("./stop-LEO7ZSSO.js").then(e=>e.StopCommand)}};async function V(e){let{renderIntro:t,...r}=e,[,o]=await Promise.allSettled([e.renderIntro(),B({...r,persistenceMode:"stateful"})]);if(o.status==="rejected")throw o.reason;return o.value}async function we(e,t){let[r]=e;r==="-v"&&(e[0]="--version"),r&&!(r in h.subCommands)&&r!=="--help"&&r!=="-h"&&r!=="--version"&&r!=="-v"&&e.unshift(b),await P(h,{rawArgs:e})}export{we as run};
@@ -0,0 +1,13 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{a as m,c as u,d,e as S}from"./chunk-FODIIZRP.js";import{a as i}from"./chunk-FON2L4R6.js";import{b as f,f as r,g as p,h as c}from"./chunk-SZYQ5TDI.js";import{d as t,f as g}from"./chunk-4QNO2WQL.js";import"./chunk-M6TFCQLD.js";import{setTimeout as C}from"timers/promises";import{isServerRunning as $,ServerState as y}from"@prisma/dev/internal/state";var A={...g,name:{description:"Name(s)/pattern(s) of the server(s) to start",required:!0,type:"positional",valueHint:"glob"}},b={description:"Start one or more stopped servers",name:"start"},U={args:A,meta:b,run:async v=>{let{debug:T,name:h}=v.args,R=h.split(","),w=await y.scan({debug:T,globs:R}),s=[],a=[];for(let e of w)($(e)?a:s).push(e);if(a.length>0&&t.log(`\u{1F45F} The following ${r} servers are already running and won't be affected:
3
+
4
+ ${i(a)}
5
+ `),s.length===0)return t.log(`\u26A0\uFE0F No ${r} servers found to start.
6
+ `);t.log(`\u{1F56F}\uFE0F Starting the following ${r} servers:
7
+
8
+ ${i(s)}
9
+ `);let l=await Promise.allSettled(s.map(async e=>{let o=await m(e);return t.log(`\u{1F525} Started ${r} server ${f(o.name)}! Listening on ports ${S([new URL(o.http.url).port,new URL(o.database.connectionString).port,new URL(o.shadowDatabase.connectionString).port])}.`),o})),n=l.filter(e=>e.status==="fulfilled");if(n.length===1){let{value:e}=n[0];t.log(`
10
+ `),t.log(u(e)),c&&await C(1e3),t.log(`
11
+ `),t.log(d(e))}else n.length>1&&t.log(`
12
+
13
+ \u{1F4DC} Run ${p("ls")} to see all running ${r} servers and their URLs.`);n.length!==l.length&&(process.exitCode||=1),t.log("")}};export{U as StartCommand};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli-dev",
3
- "version": "0.13.2",
3
+ "version": "0.14.0",
4
4
  "description": "Dev CLI for Prisma",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,30 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as x,b as n,c as v,e as h,f as b,h as S,i as w,j as C}from"./chunk-SZYQ5TDI.js";import{b as m,c as R,d}from"./chunk-4QNO2WQL.js";import{b as _}from"./chunk-M6TFCQLD.js";import{setTimeout as Gt}from"timers/promises";import c from"process";import{stripVTControlCharacters as Rt}from"util";var p={};_(p,{bgBlack:()=>rt,bgBlue:()=>st,bgBlueBright:()=>yt,bgCyan:()=>ct,bgCyanBright:()=>$t,bgGray:()=>lt,bgGreen:()=>nt,bgGreenBright:()=>vt,bgMagenta:()=>at,bgMagentaBright:()=>Pt,bgRed:()=>ot,bgRedBright:()=>bt,bgWhite:()=>pt,bgWhiteBright:()=>Tt,bgYellow:()=>it,bgYellowBright:()=>St,black:()=>F,blue:()=>z,blueBright:()=>dt,bold:()=>N,cyan:()=>Z,cyanBright:()=>ft,dim:()=>H,gray:()=>et,green:()=>V,greenBright:()=>ut,hidden:()=>j,inverse:()=>Q,italic:()=>k,magenta:()=>J,magentaBright:()=>gt,overline:()=>Y,red:()=>K,redBright:()=>ht,reset:()=>D,strikethrough:()=>q,underline:()=>W,white:()=>tt,whiteBright:()=>xt,yellow:()=>X,yellowBright:()=>mt});import L from"tty";var U=L?.WriteStream?.prototype?.hasColors?.()??!1,r=(e,t)=>{if(!U)return a=>a;let o=`\x1B[${e}m`,s=`\x1B[${t}m`;return a=>{let i=a+"",l=i.indexOf(s);if(l===-1)return o+i+s;let g=o,u=0;for(;l!==-1;)g+=i.slice(u,l)+o,u=l+s.length,l=i.indexOf(s,u);return g+=i.slice(u)+s,g}},D=r(0,0),N=r(1,22),H=r(2,22),k=r(3,23),W=r(4,24),Y=r(53,55),Q=r(7,27),j=r(8,28),q=r(9,29),F=r(30,39),K=r(31,39),V=r(32,39),X=r(33,39),z=r(34,39),J=r(35,39),Z=r(36,39),tt=r(37,39),et=r(90,39),rt=r(40,49),ot=r(41,49),nt=r(42,49),it=r(43,49),st=r(44,49),at=r(45,49),ct=r(46,49),pt=r(47,49),lt=r(100,49),ht=r(91,39),ut=r(92,39),mt=r(93,39),dt=r(94,39),gt=r(95,39),ft=r(96,39),xt=r(97,39),bt=r(101,49),vt=r(102,49),St=r(103,49),yt=r(104,49),Pt=r(105,49),$t=r(106,49),Tt=r(107,49);var f=c.platform!=="win32"||!!c.env.WT_SESSION||c.env.TERM_PROGRAM==="vscode",wt=e=>!!(e.isTTY&&c.env.TERM!=="dumb"&&!("CI"in c.env)),Ct=p.blue(f?"\u2139":"i"),Bt=p.green(f?"\u2714":"\u221A"),Ot=p.yellow(f?"\u26A0":"\u203C"),It=p.red(f?"\u2716":"\xD7"),Et={frames:f?["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]:["-","\\","|","/"],interval:80},y=class{#p;#l;#n=-1;#i;#r;#t;#s;#h=0;#o;#e;#d=0;#u=!1;constructor(t={}){let o=t.spinner??Et;this.#p=o.frames,this.#l=o.interval,this.#r=t.text??"",this.#t=t.stream??c.stderr,this.#s=t.color??"cyan",this.#e=wt(this.#t),this.#o=this.#S.bind(this)}start(t){return t&&(this.#r=t),this.isSpinning?this:(this.#u=!0,this.#f(),this.#c(),this.#b(),this.#e&&(this.#i=setInterval(()=>{this.#c()},this.#l)),this)}stop(t){return this.isSpinning?(this.#u=!1,this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#x(),this.clear(),this.#v(),t&&this.#t.write(`${t}
3
- `),this):this}#a(t,o){return this.stop(`${t} ${o??this.#r}`)}success(t){return this.#a(Bt,t)}error(t){return this.#a(It,t)}warning(t){return this.#a(Ot,t)}info(t){return this.#a(Ct,t)}get isSpinning(){return this.#u}get text(){return this.#r}set text(t){this.#r=t??"",this.#c()}get color(){return this.#s}set color(t){this.#s=t,this.#c()}clear(){if(!this.#e)return this;this.#t.cursorTo(0);for(let t=0;t<this.#h;t++)t>0&&this.#t.moveCursor(0,-1),this.#t.clearLine(1);return this.#h=0,this}#c(){let t=Date.now();(this.#n===-1||t-this.#d>=this.#l)&&(this.#n=++this.#n%this.#p.length,this.#d=t);let o=p[this.#s]??p.cyan,s=this.#p[this.#n],a=`${o(s)} ${this.#r}`;this.#e||(a+=`
4
- `),this.clear(),this.#m(a),this.#e&&(this.#h=this.#g(a))}#m(t){this.#t.write(t)}#g(t){let o=this.#t.columns??80,s=Rt(t).split(`
5
- `),a=0;for(let i of s)a+=Math.max(1,Math.ceil(i.length/o));return a}#f(){this.#e&&this.#m("\x1B[?25l")}#x(){this.#e&&this.#m("\x1B[?25h")}#b(){c.once("SIGINT",this.#o),c.once("SIGTERM",this.#o)}#v(){c.off("SIGINT",this.#o),c.off("SIGTERM",this.#o)}#S(t){this.isSpinning&&this.stop();let o=t==="SIGINT"?130:t==="SIGTERM"?143:1;c.exit(o)}};function P(e){return new y(e)}var At=[{value:"h",label:"print http url"},{value:"t",label:"print tcp urls"},{value:"q",label:"quit"}],$=6;function B(e){let t=new C({debug:e?.debug,options:At,render:Mt,signal:e?.abortSignal});return{clearPrompt(){x.stdout.moveCursor(0,-$),x.stdout.cursorTo(0),x.stdout.clearScreenDown()},prompt:t,respond:async o=>{if(w(o)||o==="q")return await e?.onQuit?.();await e?.onOption?.[o]?.()}}}function Mt(){let e=`${this.options.map(t=>`${m("inverse",` ${t.value} `)} ${t.label}`).join(" ")}`;return R(e,{style:{borderColor:"blackBright",borderStyle:"solid"},title:" \u25B3 press a key \u25B3 "})}function ie(e){let t=P();return{renderContent:_t,renderIntro:()=>Lt(e,t),renderOutro:()=>Promise.resolve(Ut(e)),spinner:t}}async function _t(e){let{abortSignal:t,debug:o,isClosed:s,onQuit:a,server:i,spinner:l}=e;if(l.success(` Great Success! \u{1F609}\u{1F44D}
6
-
7
- Your ${b} server ${n(i.name)} is ready and listening on ports ${Dt([new URL(i.http.url).port,new URL(i.database.connectionString).port,new URL(i.shadowDatabase.connectionString).port])}.`),!S){d.log(O(i)),d.log(I(i));return}for(;!s();){let{clearPrompt:g,prompt:u,respond:M}=B({abortSignal:t,debug:o,onOption:{h:()=>d.log(O(i)),t:()=>d.log(I(i))},onQuit:a}),G=await u.prompt();g(),t.aborted||await M(G)}}async function Lt(e,t){t.start(` Starting ${b} server ${n(e)}...${`
8
- `.repeat($+3)}`),S&&await Gt(250)}function Ut(e){d.log(`\u{1F44B} Buh Bye!
9
-
10
- Your ${b} server ${n(e)} has been closed successfully.
11
- `)}function O(e){return`\u{1F50C} To connect to your local Prisma Postgres database via HTTP + Prisma ORM
12
- use the following connection string:
13
-
14
- ${A("\u{1F4C4} .env:")}
15
-
16
- ${T("DATABASE_URL",Nt(e.ppg.url))}
17
-
18
- \u2728 The ${n("api_key")} above does not contain any sensitive information.`}function I(e){return`\u{1F50C} To connect to your local Prisma Postgres database via TCP + Prisma ORM
19
- use the following connection strings:
20
-
21
- ${A("\u{1F4C4} .env:")}
22
-
23
- ${T("DATABASE_URL",E(e.database.prismaORMConnectionString))}
24
-
25
- ${T("SHADOW_DATABASE_URL",E(e.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!
28
-
29
- Set the maximum number of connections to ${n(1)}, connect timeout to ${n(0)} and
30
- idle timeout to the smallest positive value supported.`}function Dt(e){if(e.length===0)return"";let t=[...e].map(Number).sort();return t.length>1&&t.every((o,s)=>s===0||o===t[s-1]+1)?`${n(t[0])}-${n(t.at(-1))}`:e.map(n).join(", ")}function T(e,t){return`${n(e)}="${t}"`}function Nt(e){return e=new URL(e),`${v(e.protocol)}//${n(e.hostname)}:${n(e.port)}${h(e.pathname)}${h(e.search)}`}function E(e){return e=new URL(e),`${v(e.protocol)}${h(`//${e.username}:${e.password}@`)}${n(e.hostname)}${h(":")}${n(e.port)}${h(e.pathname)}${h(e.search)}`}function A(e){return m("italic",m("dim",m("green",`# ${e}`)))}export{ie as a,O as b,I as c,Dt as d};
@@ -1,13 +0,0 @@
1
- import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{b as S,c as y,d as h}from"./chunk-ZPUL6EAC.js";import{a as d}from"./chunk-FON2L4R6.js";import{b as u,f as n,g,h as v}from"./chunk-SZYQ5TDI.js";import{d as t,f as p}from"./chunk-4QNO2WQL.js";import"./chunk-M6TFCQLD.js";import{fork as w}from"child_process";import{createRequire as P}from"module";import{setTimeout as $}from"timers/promises";import{isServerRunning as C,ServerState as R}from"@prisma/dev/internal/state";var A={...p,name:{description:"Name(s)/pattern(s) of the server(s) to start",required:!0,type:"positional",valueHint:"glob"}},D={description:"Start servers",name:"start"},M=P(import.meta.url).resolve("@prisma/dev/internal/daemon"),H={args:A,meta:D,run:async a=>{let{debug:i,name:m}=a.args,c=m.split(","),s=await R.scan({debug:i,globs:c}),e=[],o=[];for(let r of s)(C(r)?o:e).push(r);if(o.length>0&&t.log(`\u{1F45F} The following ${n} servers are already running and won't be affected:
3
-
4
- ${d(o)}
5
- `),e.length===0)return t.log(`\u26A0\uFE0F No ${n} servers found to start.
6
- `);t.log(`\u{1F56F}\uFE0F Starting the following ${n} servers:
7
-
8
- ${d(e)}
9
- `);let l=await Promise.allSettled(e.map(async r=>{let T=await b(r);return t.log(`\u{1F525} Started ${n} server ${u(r.name)}! Listening on ports ${h([r.port,r.databasePort,r.shadowDatabasePort])}.`),T})),f=l.filter(r=>r.status==="fulfilled");if(f.length===1){let{value:r}=f[0];t.log(`
10
- `),t.log(S(r)),v&&await $(1e3),t.log(`
11
- `),t.log(y(r))}else f.length>1&&t.log(`
12
-
13
- \u{1F4DC} Run ${g("ls")} to see all running ${n} servers and their URLs.`);f.length!==l.length&&(process.exitCode||=1),t.log("")}};async function b(a){let i,m,c=new Promise((e,o)=>{i=e,m=o}),s=w(M,[a.name],{detached:!0,stdio:"ignore"});s.once("error",e=>{t.error(e)}),s.once("message",e=>{let{type:o}=e;if(o==="error"){let{error:l}=e;return l.includes("is already running")?i({...a.exports,name:a.name}):m(e.error)}if(o==="started")return i(e.server);m(`Unknown message type: "${o}"`)});try{return await c}finally{s.disconnect(),s.unref(),s.removeAllListeners()}}export{H as StartCommand};