UNPKG

@prisma/cli-dev

Version:

Dev CLI for Prisma

31 lines (20 loc) • 7.7 kB
import { createRequire } from 'module'; const require = createRequire(import.meta.url); 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} `),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+=` `),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(` `),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} 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)}...${` `.repeat($+3)}`),b&&await _t(250)}function Ht(e){m.log(`\u{1F44B} Buh Bye! Your ${x} server ${a(e)} has been closed successfully. `)}function O(e){return`\u{1F50C} To connect to your local Prisma Postgres database via HTTP + Prisma ORM use the following connection string: ${A("\u{1F4C4} .env:")} ${T("DATABASE_URL",Wt(e.ppg.url))} \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 use the following connection strings: ${A("\u{1F4C4} .env:")} ${T("DATABASE_URL",E(e.database.prismaORMConnectionString))} ${T("SHADOW_DATABASE_URL",E(e.shadowDatabase.prismaORMConnectionString))} \u{1F418} You can also use the TCP ${a("DATABASE_URL")} with the ${a("pg")} or ${a("postgres.js")} JavaScript drivers! Set the maximum number of connections to ${a(1)}, connect timeout to ${a(0)} and 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};