@prisma/dev 0.0.0-dev.202506210320 → 0.0.0-dev.202506211253

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.
@@ -1,3 +1,3 @@
1
- import{a as L,b as F,c as J,d as b,e as U}from"./chunk-LMPFMHCB.js";import{b as c,f as A,g as T,h as V,i as N}from"./chunk-EPFUMVT3.js";import{writeFile as X}from"fs/promises";import{join as l}from"pathe";import{check as ee,lock as te}from"proper-lockfile";import{process as _}from"std-env";import{integer as H,literal as re,minLength as se,minValue as q,number as G,object as g,optional as f,parseJson as ae,pipe as h,safeParse as oe,string as P,url as ne}from"valibot";import{setTimeout as Q}from"timers/promises";import{process as D}from"std-env";function w(r,e){if(r==null)return!1;try{return D.kill?.(r,0)??!0}catch(t){return e&&console.error(`Error checking if process with PID ${r} exists:`,t),!1}}async function j(r,e){if(!D.kill)return!1;try{D.kill(r,"SIGTERM")}catch(n){return e&&console.error(`Error killing process with PID ${r}:`,n),!1}let t=0;do{if(!w(r,e))return!0;await Q(100)}while(++t<100);throw new Error(`Failed to kill process with PID ${r} after multiple attempts.`)}var k=h(P(),ne()),B=g({connectionString:k,prismaORMConnectionString:f(k),terminalCommand:f(P())}),C=g({url:k}),y=h(G(),H(),q(1)),ie=g({database:B,http:C,ppg:C,shadowDatabase:B}),ue=g({databasePort:y,exports:f(ie),name:h(P(),se(1)),pid:f(h(G(),H(),q(0))),port:y,shadowDatabasePort:y,version:re("1")}),M=Symbol("initialize"),x="default",d=class{_databasePort;debug;dryRun;name;persistenceMode;pid;_port;_shadowDatabasePort;constructor(e){this._databasePort=e.databasePort??b,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??x,this.persistenceMode=e.persistenceMode,this.pid=e.pid??_.pid,this._port=e.port??b,this._shadowDatabasePort=e.shadowDatabasePort??b}static async createExclusively(e){let t=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new p(e):new E(e);return await t[M](),t}static async fromServerDump(e){let{debug:t,name:n=x}=e??{},a=c(n),o=p.getServerDumpPath(a),s=await A(o);if(s==null)return t&&console.debug(`[State] No server dump file found at: ${o}`),null;t&&(console.debug(`[State] server dump file found at "${o}":`),console.debug(s));let{issues:i,output:u,success:m}=oe(h(P(),ae(),ue),s);if(!m)throw t&&console.debug(`[State] Invalid server dump file at "${o}":
2
- ${JSON.stringify(i,null,2)}`),new Error(`Invalid Prisma Dev state for "${n}".`);return new p({databasePort:u.databasePort,debug:t,dryRun:!1,name:n,pid:u.pid,port:u.port,serverDump:u,shadowDatabasePort:u.shadowDatabasePort})}static async scan(e){let{debug:t,globs:n}=e??{},a=l(c(x),"..");t&&console.debug(`[State] scanning for server states in: ${a}`);let o=await V(a,n);return t&&console.debug(`[State] found server names: ${JSON.stringify(o)}`),await Promise.all(o.map(s=>O(s,e)))}get databasePort(){return this._databasePort}get port(){return this._port}get shadowDatabasePort(){return this._shadowDatabasePort}},E=class extends d{constructor(e){super({...e,databasePort:e?.databasePort??L,persistenceMode:"stateless",port:e?.port??F,shadowDatabasePort:e?.shadowDatabasePort??J})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[M](){}async close(){}async writeServerDump(){}},p=class r extends d{#t;#e;#a;#o;#r;#s=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=c(this.name),this.#t=l(this.#e,"db_dump.bak"),this.#a=l(this.#e,".pglite"),this.#r=e?.serverDump??null,this.#o=r.getServerDumpPath(this.#e)}static getServerDumpPath(e){return l(e,"server.json")}get databaseDumpPath(){return this.#t}get exports(){return this.#r?.exports}get pgliteDataDirPath(){return this.#a}async[M](){await T(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#s=await te(this.#e,{lockfilePath:l(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let e=await d.scan({debug:this.debug,onlyMetadata:!0}),t=await U({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort},servers:e});this._databasePort=t.databasePort,this._port=t.port,this._shadowDatabasePort=t.shadowDatabasePort,await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new R(this):e}}async close(){if(this.#s!=null)try{await this.#s(),this.#s=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async killProcess(){let{pid:e,status:t}=await O(this,{debug:this.debug});return e==null||t!=="running"&&t!=="starting_up"?!1:_.kill?.(e,"SIGTERM")||!1}async writeServerDump(e){this.#r={name:this.name,version:"1",pid:_.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await X(this.#o,`${JSON.stringify(this.#r,null,2)}
3
- `,{encoding:"utf-8"})}};async function ye(r,e){await ce(r,e);let t=c(typeof r=="string"?r:r.name);await N(t)}async function O(r,e){let{debug:t,onlyMetadata:n}=e||{},a=typeof r=="string"?r:r.name,o=typeof r!="string"?r:void 0,s={databasePort:o?.databasePort??-1,exports:o?.exports,name:a,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await d.fromServerDump({debug:t,name:a});if(!i)return t&&console.debug(`[State] no server state found for name: ${a}`),{...s,status:"no_such_server"};s.databasePort=i.databasePort,s.exports=i.exports,s.pid=i.pid,s.port=i.port,s.shadowDatabasePort=i.shadowDatabasePort;let{exports:u,pid:m}=i;if(n)return{...s,status:"unknown"};if(!w(m,t))return t&&console.debug(`[State] server state for "${a}" has no running process with PID: ${m}`),{...s,status:"not_running"};let I=c(a);try{if(!await ee(I,{lockfilePath:l(I,".lock")}))return t&&console.debug(`[State] server state for "${a}" is not locked, indicating it is not running.`),{...s,status:"starting_up"}}catch(z){t&&console.error(`[State] server state for "${a}" failed to check lock:`,z)}if(!u)return{...s,status:"starting_up"};let{http:Y}=u,{hc:Z}=await import("hono/client"),v=await Z(Y.url).health.$get();if(!v.ok)return t&&console.debug(`[State] server state for "${a}" is not live: ${JSON.stringify(v)}`),{...s,status:"not_running"};let S=await v.json();return S.name!==r?(t&&console.debug(`[State] server state for "${a}" has mismatched health response: ${JSON.stringify(S)}`),{...s,status:"unknown"}):(t&&console.debug(`[State] server state for "${r}" is live: ${JSON.stringify(S)}`),{...s,status:"running"})}catch(i){return t&&console.error(`[State] failed to get server status for "${a}":`,i),{...s,status:"error"}}}function de(r){let{status:e}=r;return e==="running"||e==="starting_up"}async function ce(r,e){let{pid:t,...n}=typeof r=="string"?await O(r,{debug:e}):r;return!de(n)||t==null?!1:await j(t,e)}var $=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A Prisma Dev server with the name "${e}" is already running.`)}},R=class extends ${#t;name="ServerAlreadyRunningError";constructor(e){super(e.name),this.#t=e}get server(){return d.fromServerDump({debug:this.#t.debug,name:this.#t.name})}};export{d as a,ye as b,O as c,de as d,ce as e,$ as f,R as g};
1
+ import{a as N,b as F,c as J,d as f,e as U}from"./chunk-LMPFMHCB.js";import{b as c,f as A,g as T,h as V,i as L}from"./chunk-EPFUMVT3.js";import{writeFile as X}from"fs/promises";import{join as l}from"pathe";import{check as ee,lock as te}from"proper-lockfile";import{process as _}from"std-env";import{integer as H,literal as re,minLength as se,minValue as G,number as q,object as P,optional as g,parseJson as ae,pipe as h,safeParse as oe,string as v,url as ne}from"valibot";import{setTimeout as Q}from"timers/promises";import{process as b}from"std-env";function y(r,e){if(r==null)return!1;try{return b.kill?.(r,0)??!0}catch(t){return e&&console.error(`Error checking if process with PID ${r} exists:`,t),!1}}async function j(r,e){if(!b.kill)return!1;try{b.kill(r,"SIGTERM")}catch(n){return e&&console.error(`Error killing process with PID ${r}:`,n),!1}let t=0;do{if(!y(r,e))return!0;await Q(100)}while(++t<50);try{return b.kill(r,"SIGKILL")}catch(n){return e&&console.error(`Error forcefully killing process with PID ${r}:`,n),!1}}var k=h(v(),ne()),B=P({connectionString:k,prismaORMConnectionString:g(k),terminalCommand:g(v())}),C=P({url:k}),w=h(q(),H(),G(1)),ie=P({database:B,http:C,ppg:C,shadowDatabase:B}),ue=P({databasePort:w,exports:g(ie),name:h(v(),se(1)),pid:g(h(q(),H(),G(0))),port:w,shadowDatabasePort:w,version:re("1")}),M=Symbol("initialize"),x="default",d=class{_databasePort;debug;dryRun;name;persistenceMode;pid;_port;_shadowDatabasePort;constructor(e){this._databasePort=e.databasePort??f,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??x,this.persistenceMode=e.persistenceMode,this.pid=e.pid??_.pid,this._port=e.port??f,this._shadowDatabasePort=e.shadowDatabasePort??f}static async createExclusively(e){let t=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new p(e):new E(e);return await t[M](),t}static async fromServerDump(e){let{debug:t,name:n=x}=e??{},a=c(n),o=p.getServerDumpPath(a),s=await A(o);if(s==null)return t&&console.debug(`[State] No server dump file found at: ${o}`),null;t&&(console.debug(`[State] server dump file found at "${o}":`),console.debug(s));let{issues:i,output:u,success:m}=oe(h(v(),ae(),ue),s);if(!m)throw t&&console.debug(`[State] Invalid server dump file at "${o}":
2
+ ${JSON.stringify(i,null,2)}`),new Error(`Invalid Prisma Dev state for "${n}".`);return new p({databasePort:u.databasePort,debug:t,dryRun:!1,name:n,pid:u.pid,port:u.port,serverDump:u,shadowDatabasePort:u.shadowDatabasePort})}static async scan(e){let{debug:t,globs:n}=e??{},a=l(c(x),"..");t&&console.debug(`[State] scanning for server states in: ${a}`);let o=await V(a,n);return t&&console.debug(`[State] found server names: ${JSON.stringify(o)}`),await Promise.all(o.map(s=>O(s,e)))}get databasePort(){return this._databasePort}get port(){return this._port}get shadowDatabasePort(){return this._shadowDatabasePort}},E=class extends d{constructor(e){super({...e,databasePort:e?.databasePort??N,persistenceMode:"stateless",port:e?.port??F,shadowDatabasePort:e?.shadowDatabasePort??J})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[M](){}async close(){}async writeServerDump(){}},p=class r extends d{#t;#e;#a;#o;#r;#s=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=c(this.name),this.#t=l(this.#e,"db_dump.bak"),this.#a=l(this.#e,".pglite"),this.#r=e?.serverDump??null,this.#o=r.getServerDumpPath(this.#e)}static getServerDumpPath(e){return l(e,"server.json")}get databaseDumpPath(){return this.#t}get exports(){return this.#r?.exports}get pgliteDataDirPath(){return this.#a}async[M](){await T(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#s=await te(this.#e,{lockfilePath:l(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let e=await d.scan({debug:this.debug,onlyMetadata:!0}),t=await U({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort},servers:e});this._databasePort=t.databasePort,this._port=t.port,this._shadowDatabasePort=t.shadowDatabasePort,await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new R(this):e}}async close(){if(this.#s!=null)try{await this.#s(),this.#s=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async killProcess(){let{pid:e,status:t}=await O(this,{debug:this.debug});return e==null||t!=="running"&&t!=="starting_up"?!1:_.kill?.(e,"SIGTERM")||!1}async writeServerDump(e){this.#r={name:this.name,version:"1",pid:_.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await X(this.#o,`${JSON.stringify(this.#r,null,2)}
3
+ `,{encoding:"utf-8"})}};async function we(r,e){await ce(r,e);let t=c(typeof r=="string"?r:r.name);await L(t)}async function O(r,e){let{debug:t,onlyMetadata:n}=e||{},a=typeof r=="string"?r:r.name,o=typeof r!="string"?r:void 0,s={databasePort:o?.databasePort??-1,exports:o?.exports,name:a,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await d.fromServerDump({debug:t,name:a});if(!i)return t&&console.debug(`[State] no server state found for name: ${a}`),{...s,status:"no_such_server"};s.databasePort=i.databasePort,s.exports=i.exports,s.pid=i.pid,s.port=i.port,s.shadowDatabasePort=i.shadowDatabasePort;let{exports:u,pid:m}=i;if(n)return{...s,status:"unknown"};if(!y(m,t))return t&&console.debug(`[State] server state for "${a}" has no running process with PID: ${m}`),{...s,status:"not_running"};let I=c(a);try{if(!await ee(I,{lockfilePath:l(I,".lock")}))return t&&console.debug(`[State] server state for "${a}" is not locked, indicating it is not running.`),{...s,status:"starting_up"}}catch(Z){t&&console.error(`[State] server state for "${a}" failed to check lock:`,Z)}if(!u)return{...s,status:"starting_up"};let{http:K}=u,{hc:Y}=await import("hono/client"),S=await Y(K.url).health.$get();if(!S.ok)return t&&console.debug(`[State] server state for "${a}" is not live: ${JSON.stringify(S)}`),{...s,status:"not_running"};let D=await S.json();return D.name!==r?(t&&console.debug(`[State] server state for "${a}" has mismatched health response: ${JSON.stringify(D)}`),{...s,status:"unknown"}):(t&&console.debug(`[State] server state for "${r}" is live: ${JSON.stringify(D)}`),{...s,status:"running"})}catch(i){return t&&console.error(`[State] failed to get server status for "${a}":`,i),{...s,status:"error"}}}function de(r){let{status:e}=r;return e==="running"||e==="starting_up"}async function ce(r,e){let{pid:t,...n}=typeof r=="string"?await O(r,{debug:e}):r;return!de(n)||t==null?!1:await j(t,e)}var $=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A Prisma Dev server with the name "${e}" is already running.`)}},R=class extends ${#t;name="ServerAlreadyRunningError";constructor(e){super(e.name),this.#t=e}get server(){return d.fromServerDump({debug:this.#t.debug,name:this.#t.name})}};export{d as a,we as b,O as c,de as d,ce as e,$ as f,R as g};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as f}from"./chunk-RBVZVBDC.js";import{a as w,g as R}from"./chunk-QBIB4IO4.js";import{a as h,b,c as A,f as d}from"./chunk-LMPFMHCB.js";import{a as u,c as v,d as g}from"./chunk-IKAJO6YD.js";import"./chunk-EPFUMVT3.js";import{createServer as D}from"http";import{promisify as O}from"util";import C from"@prisma/get-platform";async function P(a,e){let{port:r}=e;if(e.dryRun)return y(r,null);let t=await x(r,a,e),{promise:s,reject:S,resolve:c}=v(),{serve:i}=await import("@hono/node-server"),m=i({createServer:D,fetch:t.fetch,overrideGlobalObjects:!1,port:r},c);return m.on("error",o=>{if(typeof o=="object"&&"code"in o&&o.code==="EADDRINUSE")return S(new d(r));console.error("[Accelerate]",o)}),await s,y(r,m)}function y(a,e){return{async close(){e&&await Promise.allSettled([O(e.close.bind(e))(),g.stopAll()])},port:a,url:`http://localhost:${a}`}}async function x(a,e,r){let{debug:t}=r,[{Hono:s},{accelerateRoute:S},{utilityRoute:c}]=await Promise.all([import("hono/tiny"),import("./accelerate-BNHRWV24.js"),import("./utility-YJ4TFSMW.js")]),i=new s,m=await C.getPlatformInfo();if(t&&console.debug("[Accelerate] platform info: %s",JSON.stringify(m)),t){let{logger:n}=await import("hono/logger");i.use("*",n((...p)=>console.log("[Accelerate]",...p)))}i.use("*",async(n,p)=>(n.set("db",e),n.set("debug",!!t),n.set("platform",m),n.set("port",a),n.set("protocol","http"),n.set("serverState",r),n.set("shadowDBPort",r.shadowDatabasePort),await p()));let o=new s;return o.route("/",S),o.route("/",c),i.route("/",o),i}async function G(a){let e=await w.createExclusively(a),[r,t]=await Promise.all([f("database",e),f("shadow_database",e)]),s=await P(r,e),S=`prisma+postgres://localhost:${s.port}/?${new URLSearchParams({api_key:u({databaseUrl:r.prismaORMConnectionString,name:e.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`,c={database:{connectionString:r.connectionString,prismaORMConnectionString:r.prismaORMConnectionString,terminalCommand:r.terminalCommand},http:{url:s.url},ppg:{url:S},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}};return await e.writeServerDump(c),{...c,close:()=>i(e,[s,r,t]),name:e.name};async function i(m,o){let p=(await Promise.allSettled(o.map(l=>l.close()))).filter(l=>l.status==="rejected").map(l=>new Error(l.reason));try{await m.close()}catch(l){p.push(l)}if(p.length>0)throw new AggregateError(p,"Failed to close some servers")}}export{h as DEFAULT_DATABASE_PORT,b as DEFAULT_SERVER_PORT,A as DEFAULT_SHADOW_DATABASE_PORT,d as PortNotAvailableError,R as ServerAlreadyRunningError,G as unstable_startServer};
1
+ import{a as f}from"./chunk-RBVZVBDC.js";import{a as w,g as R}from"./chunk-7MX5FDD5.js";import{a as h,b,c as A,f as d}from"./chunk-LMPFMHCB.js";import{a as u,c as v,d as g}from"./chunk-IKAJO6YD.js";import"./chunk-EPFUMVT3.js";import{createServer as D}from"http";import{promisify as O}from"util";import C from"@prisma/get-platform";async function P(a,e){let{port:r}=e;if(e.dryRun)return y(r,null);let t=await x(r,a,e),{promise:s,reject:S,resolve:c}=v(),{serve:i}=await import("@hono/node-server"),m=i({createServer:D,fetch:t.fetch,overrideGlobalObjects:!1,port:r},c);return m.on("error",o=>{if(typeof o=="object"&&"code"in o&&o.code==="EADDRINUSE")return S(new d(r));console.error("[Accelerate]",o)}),await s,y(r,m)}function y(a,e){return{async close(){e&&await Promise.allSettled([O(e.close.bind(e))(),g.stopAll()])},port:a,url:`http://localhost:${a}`}}async function x(a,e,r){let{debug:t}=r,[{Hono:s},{accelerateRoute:S},{utilityRoute:c}]=await Promise.all([import("hono/tiny"),import("./accelerate-BNHRWV24.js"),import("./utility-YJ4TFSMW.js")]),i=new s,m=await C.getPlatformInfo();if(t&&console.debug("[Accelerate] platform info: %s",JSON.stringify(m)),t){let{logger:n}=await import("hono/logger");i.use("*",n((...p)=>console.log("[Accelerate]",...p)))}i.use("*",async(n,p)=>(n.set("db",e),n.set("debug",!!t),n.set("platform",m),n.set("port",a),n.set("protocol","http"),n.set("serverState",r),n.set("shadowDBPort",r.shadowDatabasePort),await p()));let o=new s;return o.route("/",S),o.route("/",c),i.route("/",o),i}async function G(a){let e=await w.createExclusively(a),[r,t]=await Promise.all([f("database",e),f("shadow_database",e)]),s=await P(r,e),S=`prisma+postgres://localhost:${s.port}/?${new URLSearchParams({api_key:u({databaseUrl:r.prismaORMConnectionString,name:e.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`,c={database:{connectionString:r.connectionString,prismaORMConnectionString:r.prismaORMConnectionString,terminalCommand:r.terminalCommand},http:{url:s.url},ppg:{url:S},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}};return await e.writeServerDump(c),{...c,close:()=>i(e,[s,r,t]),name:e.name};async function i(m,o){let p=(await Promise.allSettled(o.map(l=>l.close()))).filter(l=>l.status==="rejected").map(l=>new Error(l.reason));try{await m.close()}catch(l){p.push(l)}if(p.length>0)throw new AggregateError(p,"Failed to close some servers")}}export{h as DEFAULT_DATABASE_PORT,b as DEFAULT_SERVER_PORT,A as DEFAULT_SHADOW_DATABASE_PORT,d as PortNotAvailableError,R as ServerAlreadyRunningError,G as unstable_startServer};
package/dist/state.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var ye=Object.create;var x=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var xe=(t,e)=>{for(var r in e)x(t,r,{get:e[r],enumerable:!0})},Z=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Se(e))!De.call(t,a)&&a!==r&&x(t,a,{get:()=>e[a],enumerable:!(i=ve(e,a))||i.enumerable});return t};var w=(t,e,r)=>(r=t!=null?ye(we(t)):{},Z(e||!t||!t.__esModule?x(r,"default",{value:t,enumerable:!0}):r,t)),Oe=t=>Z(x({},"__esModule",{value:!0}),t);var Be={};xe(Be,{ServerAlreadyRunningError:()=>U,ServerState:()=>b,ServerStateAlreadyExistsError:()=>L,deleteServer:()=>Ue,getServerStatus:()=>I,isServerRunning:()=>he,killServer:()=>Pe});module.exports=Oe(Be);var me=require("fs/promises"),g=require("pathe"),B=require("proper-lockfile"),M=require("std-env"),o=require("valibot");var Q=require("fs"),l=require("fs/promises"),ee=require("util"),te=require("zlib");var d=w(require("path"),1),V=w(require("os"),1),O=w(require("process"),1),m=V.default.homedir(),q=V.default.tmpdir(),{env:y}=O.default,_e=t=>{let e=d.default.join(m,"Library");return{data:d.default.join(e,"Application Support",t),config:d.default.join(e,"Preferences",t),cache:d.default.join(e,"Caches",t),log:d.default.join(e,"Logs",t),temp:d.default.join(q,t)}},Te=t=>{let e=y.APPDATA||d.default.join(m,"AppData","Roaming"),r=y.LOCALAPPDATA||d.default.join(m,"AppData","Local");return{data:d.default.join(r,t,"Data"),config:d.default.join(e,t,"Config"),cache:d.default.join(r,t,"Cache"),log:d.default.join(r,t,"Log"),temp:d.default.join(q,t)}},$e=t=>{let e=d.default.basename(m);return{data:d.default.join(y.XDG_DATA_HOME||d.default.join(m,".local","share"),t),config:d.default.join(y.XDG_CONFIG_HOME||d.default.join(m,".config"),t),cache:d.default.join(y.XDG_CACHE_HOME||d.default.join(m,".cache"),t),log:d.default.join(y.XDG_STATE_HOME||d.default.join(m,".local","state"),t),temp:d.default.join(q,e,t)}};function C(t,{suffix:e="nodejs"}={}){if(typeof t!="string")throw new TypeError(`Expected a string, got ${typeof t}`);return e&&(t+=`-${e}`),O.default.platform==="darwin"?_e(t):O.default.platform==="win32"?Te(t):$e(t)}var re=w(require("zeptomatch"),1),ke=C("prisma-dev"),qe=(0,ee.promisify)(te.unzip);function v(t){return`${ke.data}/${t}`}function oe(t){return t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT"}async function se(t){try{return await(0,l.readFile)(t,{encoding:"utf-8"})}catch(e){if(oe(e))return null;throw e}}async function ae(t){await(0,l.mkdir)(t,{recursive:!0})}async function ne(t,e){try{return(await(0,l.readdir)(t,{withFileTypes:!0})).reduce((i,a)=>(a.isDirectory()&&!a.name.startsWith(".")&&(!e||(0,re.default)(e,a.name))&&i.push(a.name),i),[])}catch(r){if(oe(r))return[];throw r}}async function ie(t){await(0,l.rm)(t,{force:!0,recursive:!0})}var ce=require("timers/promises"),T=require("std-env");function G(t,e){if(t==null)return!1;try{return T.process.kill?.(t,0)??!0}catch(r){return e&&console.error(`Error checking if process with PID ${t} exists:`,r),!1}}async function ue(t,e){if(!T.process.kill)return!1;try{T.process.kill(t,"SIGTERM")}catch(i){return e&&console.error(`Error killing process with PID ${t}:`,i),!1}let r=0;do{if(!G(t,e))return!0;await(0,ce.setTimeout)(100)}while(++r<100);throw new Error(`Failed to kill process with PID ${t} after multiple attempts.`)}var P=require("get-port-please"),j=require("remeda"),k=51214,E=51213,A=51215,$=65535,h=-1/0;async function pe(t){let{debug:e,name:r,requestedPorts:i,servers:a}=t,{portsUsedByOtherServers:s,portsUsedByThisServerLastTime:n}=Re(r,a);e&&(console.debug(`ports used by other servers: ${Object.keys(s).join(", ")}`),console.debug(`ports used by "${r}" server last time: ${JSON.stringify(n)}`));let c={databasePort:h,port:h,shadowDatabasePort:h},u=["port","databasePort","shadowDatabasePort"];for(let p of u){let f=await Ee({debug:e,portKey:p,portsUsedByOtherServers:s,portsUsedByThisServerLastTime:n,requestedPorts:i})??await Ae({debug:e,pickedPorts:c,portKey:p,portsUsedByOtherServers:s,portsUsedByThisServerLastTime:n});e&&console.debug(`Got port for "${p}": ${f}`),c[p]=f}return e&&console.debug(`Picked ports: ${JSON.stringify(c)}`),c}async function Ee(t){let{debug:e,portKey:r,portsUsedByOtherServers:i,portsUsedByThisServerLastTime:a,requestedPorts:s}=t,{[r]:n,...c}=s;if(de(n))return await je({debug:e,otherRequestedPorts:c,portKey:r,portsUsedByOtherServers:i,requestedPort:n}),n;let u=a?.[r]??h;if(!de(u))return e&&console.debug(`No port specified for "${r}". Trying to pick a new port.`),null;let p=u in i;return p||Object.values(c).includes(u)?(e&&console.debug(`Port ${u} that was used last time for this server, ${p?"is also used by another server":"has been requested for another service"}. Trying to pick a new port.`),null):await(0,P.checkPort)(u)===!1?(e&&console.debug(`Port ${u}, that was used last time for this server, is not available. Trying to pick a new port.`),null):(e&&console.debug(`Using port ${u} for "${r}" as it was used last time and is available.`),u)}async function Ae(t){let{debug:e,pickedPorts:r,portKey:i,portsUsedByOtherServers:a,portsUsedByThisServerLastTime:s}=t,n=Math.max(k,E,A)+1,c=[...Object.values(r),...Object.keys(a).map(Number),...Object.values(s||{})],u=Math.min(Math.max(n,...c)+100,$),p=(0,j.difference)((0,j.range)(n,u),c),f={port:E,databasePort:k,shadowDatabasePort:A}[i];try{return await(0,P.getPort)({port:f in a||Object.values(r).includes(f)||Object.values(s||{}).includes(f)?void 0:f,ports:p})}catch(S){if(S instanceof Error&&S.name==="GetPortError"&&u+1<=$)return e&&console.debug(`Expanding port lookup to range [${u+1}, ${$}].`),await(0,P.getPort)({portRange:[u+1,$]});throw S}}function de(t){return t>=0}function Re(t,e){let r={},i;for(let a of e){let{databasePort:s,port:n,shadowDatabasePort:c}=a;if(a.name===t){i={databasePort:s,port:n,shadowDatabasePort:c};continue}r[s]=!0,r[n]=!0,r[c]=!0}return{portsUsedByOtherServers:r,portsUsedByThisServerLastTime:i}}async function je(t){let{debug:e,otherRequestedPorts:r,portKey:i,portsUsedByOtherServers:a,requestedPort:s}=t;if(s in a)throw e&&console.error(`Port ${s} was requested for "${i}", but is already used by another server.`),new J(s);if(Object.values(r).includes(s))throw e&&console.error(`Port ${s} was requested for "${i}", but also for another key.`),new H(s);if((0,P.isUnsafePort)(s))throw e&&console.error(`Port ${s} was requested for "${i}", but is unsafe.`),new R(s);if(await(0,P.checkPort)(s)===!1)throw e&&console.error(`Port ${s} was requested for "${i}", but is not available.`),new R(s)}var R=class extends Error{constructor(r){super(`Port \`${r}\` is not available.`);this.port=r}name="PortNotAvailableError"},H=class extends Error{constructor(r){super(`Port number \`${r}\` was requested twice. Please choose a different port for each service.`);this.port=r}name="PortRequestedTwiceError"},J=class extends Error{constructor(r){super(`Port number \`${r}\` belongs to another Prisma Dev server. Please choose a different port.`);this.port=r}name="PortBelongsToAnotherServerError"};var X=(0,o.pipe)((0,o.string)(),(0,o.url)()),le=(0,o.object)({connectionString:X,prismaORMConnectionString:(0,o.optional)(X),terminalCommand:(0,o.optional)((0,o.string)())}),fe=(0,o.object)({url:X}),K=(0,o.pipe)((0,o.number)(),(0,o.integer)(),(0,o.minValue)(1)),Me=(0,o.object)({database:le,http:fe,ppg:fe,shadowDatabase:le}),Le=(0,o.object)({databasePort:K,exports:(0,o.optional)(Me),name:(0,o.pipe)((0,o.string)(),(0,o.minLength)(1)),pid:(0,o.optional)((0,o.pipe)((0,o.number)(),(0,o.integer)(),(0,o.minValue)(0))),port:K,shadowDatabasePort:K,version:(0,o.literal)("1")}),Y=Symbol("initialize"),W="default",b=class{_databasePort;debug;dryRun;name;persistenceMode;pid;_port;_shadowDatabasePort;constructor(e){this._databasePort=e.databasePort??h,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??W,this.persistenceMode=e.persistenceMode,this.pid=e.pid??M.process.pid,this._port=e.port??h,this._shadowDatabasePort=e.shadowDatabasePort??h}static async createExclusively(e){let r=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new D(e):new z(e);return await r[Y](),r}static async fromServerDump(e){let{debug:r,name:i=W}=e??{},a=v(i),s=D.getServerDumpPath(a),n=await se(s);if(n==null)return r&&console.debug(`[State] No server dump file found at: ${s}`),null;r&&(console.debug(`[State] server dump file found at "${s}":`),console.debug(n));let{issues:c,output:u,success:p}=(0,o.safeParse)((0,o.pipe)((0,o.string)(),(0,o.parseJson)(),Le),n);if(!p)throw r&&console.debug(`[State] Invalid server dump file at "${s}":
2
- ${JSON.stringify(c,null,2)}`),new Error(`Invalid Prisma Dev state for "${i}".`);return new D({databasePort:u.databasePort,debug:r,dryRun:!1,name:i,pid:u.pid,port:u.port,serverDump:u,shadowDatabasePort:u.shadowDatabasePort})}static async scan(e){let{debug:r,globs:i}=e??{},a=(0,g.join)(v(W),"..");r&&console.debug(`[State] scanning for server states in: ${a}`);let s=await ne(a,i);return r&&console.debug(`[State] found server names: ${JSON.stringify(s)}`),await Promise.all(s.map(n=>I(n,e)))}get databasePort(){return this._databasePort}get port(){return this._port}get shadowDatabasePort(){return this._shadowDatabasePort}},z=class extends b{constructor(e){super({...e,databasePort:e?.databasePort??k,persistenceMode:"stateless",port:e?.port??E,shadowDatabasePort:e?.shadowDatabasePort??A})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[Y](){}async close(){}async writeServerDump(){}},D=class t extends b{#t;#e;#s;#a;#r;#o=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=v(this.name),this.#t=(0,g.join)(this.#e,"db_dump.bak"),this.#s=(0,g.join)(this.#e,".pglite"),this.#r=e?.serverDump??null,this.#a=t.getServerDumpPath(this.#e)}static getServerDumpPath(e){return(0,g.join)(e,"server.json")}get databaseDumpPath(){return this.#t}get exports(){return this.#r?.exports}get pgliteDataDirPath(){return this.#s}async[Y](){await ae(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#o=await(0,B.lock)(this.#e,{lockfilePath:(0,g.join)(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let e=await b.scan({debug:this.debug,onlyMetadata:!0}),r=await pe({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort},servers:e});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new U(this):e}}async close(){if(this.#o!=null)try{await this.#o(),this.#o=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async killProcess(){let{pid:e,status:r}=await I(this,{debug:this.debug});return e==null||r!=="running"&&r!=="starting_up"?!1:M.process.kill?.(e,"SIGTERM")||!1}async writeServerDump(e){this.#r={name:this.name,version:"1",pid:M.process.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await(0,me.writeFile)(this.#a,`${JSON.stringify(this.#r,null,2)}
3
- `,{encoding:"utf-8"})}};async function Ue(t,e){await Pe(t,e);let r=v(typeof t=="string"?t:t.name);await ie(r)}async function I(t,e){let{debug:r,onlyMetadata:i}=e||{},a=typeof t=="string"?t:t.name,s=typeof t!="string"?t:void 0,n={databasePort:s?.databasePort??-1,exports:s?.exports,name:a,pid:s?.pid,port:s?.port??-1,shadowDatabasePort:s?.shadowDatabasePort??-1,version:"1"};try{let c=s||await b.fromServerDump({debug:r,name:a});if(!c)return r&&console.debug(`[State] no server state found for name: ${a}`),{...n,status:"no_such_server"};n.databasePort=c.databasePort,n.exports=c.exports,n.pid=c.pid,n.port=c.port,n.shadowDatabasePort=c.shadowDatabasePort;let{exports:u,pid:p}=c;if(i)return{...n,status:"unknown"};if(!G(p,r))return r&&console.debug(`[State] server state for "${a}" has no running process with PID: ${p}`),{...n,status:"not_running"};let f=v(a);try{if(!await(0,B.check)(f,{lockfilePath:(0,g.join)(f,".lock")}))return r&&console.debug(`[State] server state for "${a}" is not locked, indicating it is not running.`),{...n,status:"starting_up"}}catch(ge){r&&console.error(`[State] server state for "${a}" failed to check lock:`,ge)}if(!u)return{...n,status:"starting_up"};let{http:S}=u,{hc:be}=await import("hono/client"),N=await be(S.url).health.$get();if(!N.ok)return r&&console.debug(`[State] server state for "${a}" is not live: ${JSON.stringify(N)}`),{...n,status:"not_running"};let F=await N.json();return F.name!==t?(r&&console.debug(`[State] server state for "${a}" has mismatched health response: ${JSON.stringify(F)}`),{...n,status:"unknown"}):(r&&console.debug(`[State] server state for "${t}" is live: ${JSON.stringify(F)}`),{...n,status:"running"})}catch(c){return r&&console.error(`[State] failed to get server status for "${a}":`,c),{...n,status:"error"}}}function he(t){let{status:e}=t;return e==="running"||e==="starting_up"}async function Pe(t,e){let{pid:r,...i}=typeof t=="string"?await I(t,{debug:e}):t;return!he(i)||r==null?!1:await ue(r,e)}var L=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A Prisma Dev server with the name "${e}" is already running.`)}},U=class extends L{#t;name="ServerAlreadyRunningError";constructor(e){super(e.name),this.#t=e}get server(){return b.fromServerDump({debug:this.#t.debug,name:this.#t.name})}};0&&(module.exports={ServerAlreadyRunningError,ServerState,ServerStateAlreadyExistsError,deleteServer,getServerStatus,isServerRunning,killServer});
1
+ "use strict";var ye=Object.create;var O=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var xe=(t,e)=>{for(var r in e)O(t,r,{get:e[r],enumerable:!0})},Z=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Se(e))!De.call(t,a)&&a!==r&&O(t,a,{get:()=>e[a],enumerable:!(n=ve(e,a))||n.enumerable});return t};var w=(t,e,r)=>(r=t!=null?ye(we(t)):{},Z(e||!t||!t.__esModule?O(r,"default",{value:t,enumerable:!0}):r,t)),Oe=t=>Z(O({},"__esModule",{value:!0}),t);var Be={};xe(Be,{ServerAlreadyRunningError:()=>U,ServerState:()=>b,ServerStateAlreadyExistsError:()=>L,deleteServer:()=>Ue,getServerStatus:()=>I,isServerRunning:()=>me,killServer:()=>Pe});module.exports=Oe(Be);var he=require("fs/promises"),g=require("pathe"),B=require("proper-lockfile"),M=require("std-env"),o=require("valibot");var Q=require("fs"),l=require("fs/promises"),ee=require("util"),te=require("zlib");var d=w(require("path"),1),V=w(require("os"),1),_=w(require("process"),1),h=V.default.homedir(),q=V.default.tmpdir(),{env:y}=_.default,_e=t=>{let e=d.default.join(h,"Library");return{data:d.default.join(e,"Application Support",t),config:d.default.join(e,"Preferences",t),cache:d.default.join(e,"Caches",t),log:d.default.join(e,"Logs",t),temp:d.default.join(q,t)}},Te=t=>{let e=y.APPDATA||d.default.join(h,"AppData","Roaming"),r=y.LOCALAPPDATA||d.default.join(h,"AppData","Local");return{data:d.default.join(r,t,"Data"),config:d.default.join(e,t,"Config"),cache:d.default.join(r,t,"Cache"),log:d.default.join(r,t,"Log"),temp:d.default.join(q,t)}},ke=t=>{let e=d.default.basename(h);return{data:d.default.join(y.XDG_DATA_HOME||d.default.join(h,".local","share"),t),config:d.default.join(y.XDG_CONFIG_HOME||d.default.join(h,".config"),t),cache:d.default.join(y.XDG_CACHE_HOME||d.default.join(h,".cache"),t),log:d.default.join(y.XDG_STATE_HOME||d.default.join(h,".local","state"),t),temp:d.default.join(q,e,t)}};function C(t,{suffix:e="nodejs"}={}){if(typeof t!="string")throw new TypeError(`Expected a string, got ${typeof t}`);return e&&(t+=`-${e}`),_.default.platform==="darwin"?_e(t):_.default.platform==="win32"?Te(t):ke(t)}var re=w(require("zeptomatch"),1),$e=C("prisma-dev"),qe=(0,ee.promisify)(te.unzip);function v(t){return`${$e.data}/${t}`}function oe(t){return t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT"}async function se(t){try{return await(0,l.readFile)(t,{encoding:"utf-8"})}catch(e){if(oe(e))return null;throw e}}async function ae(t){await(0,l.mkdir)(t,{recursive:!0})}async function ne(t,e){try{return(await(0,l.readdir)(t,{withFileTypes:!0})).reduce((n,a)=>(a.isDirectory()&&!a.name.startsWith(".")&&(!e||(0,re.default)(e,a.name))&&n.push(a.name),n),[])}catch(r){if(oe(r))return[];throw r}}async function ie(t){await(0,l.rm)(t,{force:!0,recursive:!0})}var ce=require("timers/promises"),D=require("std-env");function G(t,e){if(t==null)return!1;try{return D.process.kill?.(t,0)??!0}catch(r){return e&&console.error(`Error checking if process with PID ${t} exists:`,r),!1}}async function ue(t,e){if(!D.process.kill)return!1;try{D.process.kill(t,"SIGTERM")}catch(n){return e&&console.error(`Error killing process with PID ${t}:`,n),!1}let r=0;do{if(!G(t,e))return!0;await(0,ce.setTimeout)(100)}while(++r<50);try{return D.process.kill(t,"SIGKILL")}catch(n){return e&&console.error(`Error forcefully killing process with PID ${t}:`,n),!1}}var P=require("get-port-please"),j=require("remeda"),$=51214,E=51213,A=51215,k=65535,m=-1/0;async function pe(t){let{debug:e,name:r,requestedPorts:n,servers:a}=t,{portsUsedByOtherServers:s,portsUsedByThisServerLastTime:i}=Re(r,a);e&&(console.debug(`ports used by other servers: ${Object.keys(s).join(", ")}`),console.debug(`ports used by "${r}" server last time: ${JSON.stringify(i)}`));let c={databasePort:m,port:m,shadowDatabasePort:m},u=["port","databasePort","shadowDatabasePort"];for(let p of u){let f=await Ee({debug:e,portKey:p,portsUsedByOtherServers:s,portsUsedByThisServerLastTime:i,requestedPorts:n})??await Ae({debug:e,pickedPorts:c,portKey:p,portsUsedByOtherServers:s,portsUsedByThisServerLastTime:i});e&&console.debug(`Got port for "${p}": ${f}`),c[p]=f}return e&&console.debug(`Picked ports: ${JSON.stringify(c)}`),c}async function Ee(t){let{debug:e,portKey:r,portsUsedByOtherServers:n,portsUsedByThisServerLastTime:a,requestedPorts:s}=t,{[r]:i,...c}=s;if(de(i))return await je({debug:e,otherRequestedPorts:c,portKey:r,portsUsedByOtherServers:n,requestedPort:i}),i;let u=a?.[r]??m;if(!de(u))return e&&console.debug(`No port specified for "${r}". Trying to pick a new port.`),null;let p=u in n;return p||Object.values(c).includes(u)?(e&&console.debug(`Port ${u} that was used last time for this server, ${p?"is also used by another server":"has been requested for another service"}. Trying to pick a new port.`),null):await(0,P.checkPort)(u)===!1?(e&&console.debug(`Port ${u}, that was used last time for this server, is not available. Trying to pick a new port.`),null):(e&&console.debug(`Using port ${u} for "${r}" as it was used last time and is available.`),u)}async function Ae(t){let{debug:e,pickedPorts:r,portKey:n,portsUsedByOtherServers:a,portsUsedByThisServerLastTime:s}=t,i=Math.max($,E,A)+1,c=[...Object.values(r),...Object.keys(a).map(Number),...Object.values(s||{})],u=Math.min(Math.max(i,...c)+100,k),p=(0,j.difference)((0,j.range)(i,u),c),f={port:E,databasePort:$,shadowDatabasePort:A}[n];try{return await(0,P.getPort)({port:f in a||Object.values(r).includes(f)||Object.values(s||{}).includes(f)?void 0:f,ports:p})}catch(S){if(S instanceof Error&&S.name==="GetPortError"&&u+1<=k)return e&&console.debug(`Expanding port lookup to range [${u+1}, ${k}].`),await(0,P.getPort)({portRange:[u+1,k]});throw S}}function de(t){return t>=0}function Re(t,e){let r={},n;for(let a of e){let{databasePort:s,port:i,shadowDatabasePort:c}=a;if(a.name===t){n={databasePort:s,port:i,shadowDatabasePort:c};continue}r[s]=!0,r[i]=!0,r[c]=!0}return{portsUsedByOtherServers:r,portsUsedByThisServerLastTime:n}}async function je(t){let{debug:e,otherRequestedPorts:r,portKey:n,portsUsedByOtherServers:a,requestedPort:s}=t;if(s in a)throw e&&console.error(`Port ${s} was requested for "${n}", but is already used by another server.`),new K(s);if(Object.values(r).includes(s))throw e&&console.error(`Port ${s} was requested for "${n}", but also for another key.`),new H(s);if((0,P.isUnsafePort)(s))throw e&&console.error(`Port ${s} was requested for "${n}", but is unsafe.`),new R(s);if(await(0,P.checkPort)(s)===!1)throw e&&console.error(`Port ${s} was requested for "${n}", but is not available.`),new R(s)}var R=class extends Error{constructor(r){super(`Port \`${r}\` is not available.`);this.port=r}name="PortNotAvailableError"},H=class extends Error{constructor(r){super(`Port number \`${r}\` was requested twice. Please choose a different port for each service.`);this.port=r}name="PortRequestedTwiceError"},K=class extends Error{constructor(r){super(`Port number \`${r}\` belongs to another Prisma Dev server. Please choose a different port.`);this.port=r}name="PortBelongsToAnotherServerError"};var X=(0,o.pipe)((0,o.string)(),(0,o.url)()),le=(0,o.object)({connectionString:X,prismaORMConnectionString:(0,o.optional)(X),terminalCommand:(0,o.optional)((0,o.string)())}),fe=(0,o.object)({url:X}),J=(0,o.pipe)((0,o.number)(),(0,o.integer)(),(0,o.minValue)(1)),Me=(0,o.object)({database:le,http:fe,ppg:fe,shadowDatabase:le}),Le=(0,o.object)({databasePort:J,exports:(0,o.optional)(Me),name:(0,o.pipe)((0,o.string)(),(0,o.minLength)(1)),pid:(0,o.optional)((0,o.pipe)((0,o.number)(),(0,o.integer)(),(0,o.minValue)(0))),port:J,shadowDatabasePort:J,version:(0,o.literal)("1")}),Y=Symbol("initialize"),W="default",b=class{_databasePort;debug;dryRun;name;persistenceMode;pid;_port;_shadowDatabasePort;constructor(e){this._databasePort=e.databasePort??m,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??W,this.persistenceMode=e.persistenceMode,this.pid=e.pid??M.process.pid,this._port=e.port??m,this._shadowDatabasePort=e.shadowDatabasePort??m}static async createExclusively(e){let r=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new x(e):new z(e);return await r[Y](),r}static async fromServerDump(e){let{debug:r,name:n=W}=e??{},a=v(n),s=x.getServerDumpPath(a),i=await se(s);if(i==null)return r&&console.debug(`[State] No server dump file found at: ${s}`),null;r&&(console.debug(`[State] server dump file found at "${s}":`),console.debug(i));let{issues:c,output:u,success:p}=(0,o.safeParse)((0,o.pipe)((0,o.string)(),(0,o.parseJson)(),Le),i);if(!p)throw r&&console.debug(`[State] Invalid server dump file at "${s}":
2
+ ${JSON.stringify(c,null,2)}`),new Error(`Invalid Prisma Dev state for "${n}".`);return new x({databasePort:u.databasePort,debug:r,dryRun:!1,name:n,pid:u.pid,port:u.port,serverDump:u,shadowDatabasePort:u.shadowDatabasePort})}static async scan(e){let{debug:r,globs:n}=e??{},a=(0,g.join)(v(W),"..");r&&console.debug(`[State] scanning for server states in: ${a}`);let s=await ne(a,n);return r&&console.debug(`[State] found server names: ${JSON.stringify(s)}`),await Promise.all(s.map(i=>I(i,e)))}get databasePort(){return this._databasePort}get port(){return this._port}get shadowDatabasePort(){return this._shadowDatabasePort}},z=class extends b{constructor(e){super({...e,databasePort:e?.databasePort??$,persistenceMode:"stateless",port:e?.port??E,shadowDatabasePort:e?.shadowDatabasePort??A})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[Y](){}async close(){}async writeServerDump(){}},x=class t extends b{#t;#e;#s;#a;#r;#o=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=v(this.name),this.#t=(0,g.join)(this.#e,"db_dump.bak"),this.#s=(0,g.join)(this.#e,".pglite"),this.#r=e?.serverDump??null,this.#a=t.getServerDumpPath(this.#e)}static getServerDumpPath(e){return(0,g.join)(e,"server.json")}get databaseDumpPath(){return this.#t}get exports(){return this.#r?.exports}get pgliteDataDirPath(){return this.#s}async[Y](){await ae(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#o=await(0,B.lock)(this.#e,{lockfilePath:(0,g.join)(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let e=await b.scan({debug:this.debug,onlyMetadata:!0}),r=await pe({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort},servers:e});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new U(this):e}}async close(){if(this.#o!=null)try{await this.#o(),this.#o=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async killProcess(){let{pid:e,status:r}=await I(this,{debug:this.debug});return e==null||r!=="running"&&r!=="starting_up"?!1:M.process.kill?.(e,"SIGTERM")||!1}async writeServerDump(e){this.#r={name:this.name,version:"1",pid:M.process.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await(0,he.writeFile)(this.#a,`${JSON.stringify(this.#r,null,2)}
3
+ `,{encoding:"utf-8"})}};async function Ue(t,e){await Pe(t,e);let r=v(typeof t=="string"?t:t.name);await ie(r)}async function I(t,e){let{debug:r,onlyMetadata:n}=e||{},a=typeof t=="string"?t:t.name,s=typeof t!="string"?t:void 0,i={databasePort:s?.databasePort??-1,exports:s?.exports,name:a,pid:s?.pid,port:s?.port??-1,shadowDatabasePort:s?.shadowDatabasePort??-1,version:"1"};try{let c=s||await b.fromServerDump({debug:r,name:a});if(!c)return r&&console.debug(`[State] no server state found for name: ${a}`),{...i,status:"no_such_server"};i.databasePort=c.databasePort,i.exports=c.exports,i.pid=c.pid,i.port=c.port,i.shadowDatabasePort=c.shadowDatabasePort;let{exports:u,pid:p}=c;if(n)return{...i,status:"unknown"};if(!G(p,r))return r&&console.debug(`[State] server state for "${a}" has no running process with PID: ${p}`),{...i,status:"not_running"};let f=v(a);try{if(!await(0,B.check)(f,{lockfilePath:(0,g.join)(f,".lock")}))return r&&console.debug(`[State] server state for "${a}" is not locked, indicating it is not running.`),{...i,status:"starting_up"}}catch(ge){r&&console.error(`[State] server state for "${a}" failed to check lock:`,ge)}if(!u)return{...i,status:"starting_up"};let{http:S}=u,{hc:be}=await import("hono/client"),N=await be(S.url).health.$get();if(!N.ok)return r&&console.debug(`[State] server state for "${a}" is not live: ${JSON.stringify(N)}`),{...i,status:"not_running"};let F=await N.json();return F.name!==t?(r&&console.debug(`[State] server state for "${a}" has mismatched health response: ${JSON.stringify(F)}`),{...i,status:"unknown"}):(r&&console.debug(`[State] server state for "${t}" is live: ${JSON.stringify(F)}`),{...i,status:"running"})}catch(c){return r&&console.error(`[State] failed to get server status for "${a}":`,c),{...i,status:"error"}}}function me(t){let{status:e}=t;return e==="running"||e==="starting_up"}async function Pe(t,e){let{pid:r,...n}=typeof t=="string"?await I(t,{debug:e}):t;return!me(n)||r==null?!1:await ue(r,e)}var L=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A Prisma Dev server with the name "${e}" is already running.`)}},U=class extends L{#t;name="ServerAlreadyRunningError";constructor(e){super(e.name),this.#t=e}get server(){return b.fromServerDump({debug:this.#t.debug,name:this.#t.name})}};0&&(module.exports={ServerAlreadyRunningError,ServerState,ServerStateAlreadyExistsError,deleteServer,getServerStatus,isServerRunning,killServer});
package/dist/state.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d,e,f,g}from"./chunk-QBIB4IO4.js";import"./chunk-LMPFMHCB.js";import"./chunk-EPFUMVT3.js";export{g as ServerAlreadyRunningError,a as ServerState,f as ServerStateAlreadyExistsError,b as deleteServer,c as getServerStatus,d as isServerRunning,e as killServer};
1
+ import{a,b,c,d,e,f,g}from"./chunk-7MX5FDD5.js";import"./chunk-LMPFMHCB.js";import"./chunk-EPFUMVT3.js";export{g as ServerAlreadyRunningError,a as ServerState,f as ServerStateAlreadyExistsError,b as deleteServer,c as getServerStatus,d as isServerRunning,e as killServer};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/dev",
3
- "version": "0.0.0-dev.202506210320",
3
+ "version": "0.0.0-dev.202506211253",
4
4
  "description": "A local Prisma Postgres server for development and testing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",