@prisma/dev 0.24.10 → 0.24.12
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/{chunk-NR64I267.js → chunk-GMUOAEZU.js} +1 -1
- package/dist/daemon.cjs +1 -1
- package/dist/daemon.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as W,b as O,f as R}from"./chunk-PP43TGA5.js";import{a as C,b as I,c as $,d as T,e as f,f as M}from"./chunk-2XJK3IOI.js";import{h as x}from"./chunk-EDFHV3AK.js";import{a as N}from"./chunk-HQMJSXYT.js";import{d as q,j as g}from"./chunk-DWY47FQV.js";import{a as _}from"./chunk-3UF2MBYQ.js";import{createServer as ee}from"http";import{promisify as re}from"util";async function j(r,e){let{port:t}=e;if(e.dryRun)return U(t,null);let n=await te(r,e),{promise:s,reject:i,resolve:l}=N(),{serve:a}=await import("@hono/node-server"),o=a({createServer:ee,fetch:n.fetch,overrideGlobalObjects:!1,port:t},l);o.on("error",m=>{if(typeof m=="object"&&"code"in m&&m.code==="EADDRINUSE")return i(new x(t));console.error("[Accelerate]",m)});let{port:c}=await s;return e.port=c,U(c,o)}function U(r,e){return{async close(){if(!e)return;let{Engine:t}=await import("./engine-XP6YJ63T.js");await Promise.allSettled([re(e.close.bind(e))(),t.stopAll()])},port:r,url:`http://localhost:${r}`}}async function te(r,e){let{debug:t}=e,[{Hono:n},{accelerateRoute:s},{utilityRoute:i}]=await Promise.all([import("hono/tiny"),import("./accelerate-5FDEK4T6.js"),import("./utility-Q5A254LJ.js")]),l=new n;if(t){let{logger:o}=await import("hono/logger");l.use("*",o((...c)=>console.log("[Accelerate]",...c)))}l.use("*",async(o,c)=>(o.set("databaseDumpPath",e.databaseDumpPath),o.set("db",r),o.set("debug",!!t),o.set("name",e.name),o.set("shadowDBPort",e.shadowDatabasePort),await c()));let a=new n;return a.route("/",s),a.route("/",i),l.route("/",a),l}import{isDeepStrictEqual as F}from"util";var ne="application/json",w={connection:"close","content-type":ne},k={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{applicationName:{type:["string","null"]},durationMs:{type:"number"},groupKey:{type:["string","null"]},query:{type:"string"},queryId:{type:"string"},reads:{type:"number"},rowsReturned:{type:"number"},tables:{items:{type:"string"},type:"array"},timestamp:{format:"date-time",type:"string"}},required:["durationMs","query","queryId","reads","rowsReturned","tables","timestamp"],type:"object"},search:{aliases:{applicationName:"applicationName",groupKey:"groupKey",queryId:"queryId"},fields:{applicationName:{bindings:[{jsonPointer:"/applicationName",version:1}],exact:!0,exists:!0,kind:"keyword"},eventTime:{bindings:[{jsonPointer:"/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},groupKey:{bindings:[{jsonPointer:"/groupKey",version:1}],exact:!0,exists:!0,kind:"keyword"},queryId:{bindings:[{jsonPointer:"/queryId",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};function H(r){return{...r,snapshot:async e=>await se(r.url,e)}}async function L(r){let e={serverUrl:r.serverUrl,sqlitePath:r.sqlitePath,streamName:I,url:f(r.serverUrl,I)};await oe(e);let t=new A({debug:r.debug,streamUrl:e.url}),n=r.bridge.subscribe(s=>{t.enqueue(s)});return{close:async()=>{n(),await t.close()},experimental:e}}async function se(r,e){if(!r)return W();let t=await ae(r);return O(t,e)}async function ae(r){let e=await fetch(`${r}?offset=-1&format=json`,{headers:{connection:"close"}});if(!e.ok)throw new Error(`Failed to read ${r}: HTTP ${e.status}`);return await e.json()}var A=class{#t;#r;#e;constructor(e){this.#t=e.debug,this.#r=Promise.resolve(),this.#e=e.streamUrl}enqueue(e){e.length!==0&&(this.#r=this.#r.then(async()=>{await ce(this.#e,e),this.#t&&console.debug(`[streams] appended ${e.length} query insight record(s) to ${this.#e}`)}).catch(t=>{console.error("[streams] failed to ingest query insights into prisma-queries",t)}))}async close(){await this.#r}};async function oe(r){let e=await fetch(r.url,{headers:w,method:"PUT"});if(!e.ok)throw await b(e,`Failed to create ${r.streamName}`);let t=await le(r);if(ie(t,r.streamName))return;if(t.currentVersion>0)throw new Error(`Failed to install schema for ${r.streamName}: existing schema registry is incompatible and requires a lens migration`);let n=await fetch(`${r.url}/_schema`,{body:JSON.stringify(k),headers:w,method:"POST"});if(!n.ok)throw await b(n,`Failed to install schema for ${r.streamName}`)}function ie(r,e){if(r.currentVersion<=0||r.schema!==e)return!1;let t=r.schemas[String(r.currentVersion)];return F(t,k.schema)&&F(r.search,k.search)}async function le(r){let e=await fetch(`${r.url}/_schema`,{headers:w,method:"GET"});if(!e.ok)throw await b(e,`Failed to inspect schema for ${r.streamName}`);return await e.json()}async function ce(r,e){let t=await fetch(r,{body:JSON.stringify(e),headers:w,method:"POST"});if(!t.ok)throw await b(t,"Failed to append to prisma-queries")}async function b(r,e){let t=await r.text().catch(()=>"");return new Error(`${e}: HTTP ${r.status}${t?` ${t}`:""}`)}import{randomUUID as me}from"crypto";import{setTimeout as K}from"timers/promises";import{isDeepStrictEqual as V}from"util";import{process as ue}from"std-env";var pe="application/json",y={connection:"close","content-type":pe},de={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},Q={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function G(r){let{dbServer:e,debug:t,name:n,persistenceMode:s,port:i,queryInsightsBridge:l,walBridge:a}=r,o=s==="stateless",c=o?Re(n):n,m=T(c),P=!o&&await q(m);ue.env.DS_LOCAL_DATA_ROOT=$(),o&&await g(m);let u=await ge({debug:t,hadExistingStreamsData:P,name:c,port:i}),d={serverUrl:u.exports.http.url,sqlitePath:u.exports.sqlite.path,streamName:C,url:f(u.exports.http.url)};try{await fe(d);let p=await L({bridge:l,debug:t,serverUrl:u.exports.http.url,sqlitePath:u.exports.sqlite.path}),h=new D({dbServer:e,debug:t,streamUrl:d.url}),X=a.subscribe(Z=>{h.enqueue(Z)});return{close:async()=>{X(),await h.close(),await p.close(),await u.close(),await K(100),o&&await g(m)},experimental:d,experimentalQueryInsights:p.experimental}}catch(p){throw await u.close().catch(()=>{}),await K(100),o&&await g(m).catch(()=>{}),p}}var he=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function ge(r){let{debug:e,hadExistingStreamsData:t,name:n,port:s}=r,{startLocalDurableStreamsServer:i}=await import("@prisma/streams-local"),l=()=>i({hostname:"127.0.0.1",name:n,port:s});try{return await l()}catch(a){if(!t||!ye(a))throw a;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),e&&console.debug(`[streams] original durable streams startup error for "${n}"`,a),await g(T(n)),await l()}}function ye(r){return Se(r).map(t=>t.toLowerCase()).some(t=>he.some(n=>t.includes(n)))}function Se(r){let e=[],t=[r],n=new Set;for(;t.length>0;){let s=t.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){e.push(s);continue}if(s instanceof AggregateError)for(let i of s.errors)t.push(i);if(s instanceof Error){e.push(s.message);let i=s.cause;i!==void 0&&t.push(i)}}}return e}var D=class{#t;#r;#e;#n;#s;constructor(e){this.#t=e.dbServer,this.#r=e.debug,this.#e=Promise.resolve(),this.#n=e.streamUrl,this.#s=new Set}enqueue(e){e.length!==0&&(this.#e=this.#e.then(async()=>{let t=await this.#o(e);t.length!==0&&(await we(this.#n,t),this.#r&&console.debug(`[streams] appended ${t.length} state-protocol record(s) to ${this.#n}`))}).catch(t=>{console.error("[streams] failed to ingest WAL events into prisma-wal",t)}))}async close(){await this.#e}async#o(e){let t=[],n=new Date().toISOString();for(let s of e)t.push(...await this.#i(s,n));return t}async#i(e,t){let n=`${e.schema}.${e.table}`,s=await this.#t.getPrimaryKeyColumns(e.schema,e.table),i=J(e.record),l=J(e.oldRecord),a=this.#a(n,s,l),o=this.#a(n,s,i),c=e.txid===""?void 0:e.txid;return e.type==="insert"?i&&o?[{headers:{operation:"insert",timestamp:t,txid:c},key:o,old_value:null,type:n,value:i}]:[]:e.type==="delete"?l&&a?[{headers:{operation:"delete",timestamp:t,txid:c},key:a,old_value:l,type:n,value:null}]:[]:!i||!l||!a||!o?[]:a!==o?[{headers:{operation:"delete",timestamp:t,txid:c},key:a,old_value:l,type:n,value:null},{headers:{operation:"insert",timestamp:t,txid:c},key:o,old_value:null,type:n,value:i}]:[{headers:{operation:"update",timestamp:t,txid:c},key:o,old_value:l,type:n,value:i}]}#a(e,t,n){if(!n)return null;let s=be(n,t);return s||(this.#s.has(e)||(this.#s.add(e),console.warn(`[streams] falling back to full-row keys for ${e} because no primary key could be resolved`)),Pe(n))}};async function fe(r){let e=await fetch(r.url,{headers:y,method:"PUT"});if(!e.ok)throw await S(e,`Failed to create ${r.streamName}`);let t=await fetch(`${r.url}/_profile`,{body:JSON.stringify(de),headers:y,method:"POST"});if(!t.ok)throw await S(t,`Failed to configure ${r.streamName}`);let n=await ve(r);if(Ee(n,r.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${r.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${r.url}/_schema`,{body:JSON.stringify(Q),headers:y,method:"POST"});if(!s.ok)throw await S(s,`Failed to install schema for ${r.streamName}`)}async function ve(r){let e=await fetch(`${r.url}/_schema`,{headers:y,method:"GET"});if(!e.ok)throw await S(e,`Failed to inspect schema for ${r.streamName}`);return await e.json()}function Ee(r,e){if(r.currentVersion<=0||r.schema!==e)return!1;let t=r.schemas[String(r.currentVersion)];return V(t,Q.schema)&&V(r.search,Q.search)}async function we(r,e){let t=await fetch(r,{body:JSON.stringify(e),headers:y,method:"POST"});if(!t.ok)throw await S(t,"Failed to append to prisma-wal")}async function S(r,e){let t=await r.text().catch(()=>"");return new Error(`${e}: HTTP ${r.status}${t?` ${t}`:""}`)}function be(r,e){if(e.length===0)return null;let t=[];for(let n of e){if(!Object.prototype.hasOwnProperty.call(r,n))return null;let s=xe(r[n]);if(s==null)return null;t.push(e.length===1?s:`${n}=${s}`)}return t.join("|")}function Pe(r){return JSON.stringify(B(r))}function B(r){return Array.isArray(r)?r.map(e=>B(e)):r&&typeof r=="object"?Object.fromEntries(Object.entries(r).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,B(t)])):r}function J(r){return r?structuredClone(r):null}function xe(r){if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return r;if(typeof r=="number")return Number.isFinite(r)?String(r):null;if(typeof r=="bigint")return r.toString();if(typeof r=="boolean")return r?"true":"false";try{return JSON.stringify(r)}catch{return null}}function Re(r){return`${r}.${me().replaceAll("-","")}`}async function Y(r){let e=await M.createExclusively(r),t=null,n=null,s=null,i=null;try{[t,s]=await Promise.all([R("database",e),R("shadow_database",e)]);let l,a;e.dryRun?(l=Ae(),a=Qe(),i=De()):(l=await t.attachWalEventBridge(),a=await t.attachQueryInsightsBridge(),i=await G({dbServer:t,debug:e.debug,name:e.name,port:e.streamsPort,persistenceMode:e.persistenceMode,queryInsightsBridge:a,walBridge:l})),n=await j(t,e);let o=Ie(t,s,n,e);await e.writeServerDump(o,e.dryRun?{}:{queryInsights:i.experimentalQueryInsights,streams:i.experimental});let c=ke(l),m=H(i.experimentalQueryInsights),P=t,u=s,d=n,p=i,h=async()=>{c.close(),await z(e,[d,p,P,u])};return{close:h,dbServer:t,httpServer:n,server:{...o,close:h,experimental:{queryInsights:m,streams:i.experimental,wal:c.api},name:e.name},serverState:e,shadowDbServer:s,streamsServer:i,queryInsightsBridge:a,walBridge:l}}catch(l){return await Te(e,[n,i,t,s],l)}}function Ie(r,e,t,n){let s=`prisma+postgres://localhost:${t.port}/?${new URLSearchParams({api_key:_({databaseUrl:r.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:e.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:r.connectionString,prismaORMConnectionString:r.prismaORMConnectionString,terminalCommand:r.terminalCommand},http:{url:t.url},ppg:{url:s},shadowDatabase:{connectionString:e.prismaORMConnectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand}}}async function z(r,e){let n=(await Promise.allSettled(e.map(s=>s.close()))).filter(s=>s.status==="rejected").map(s=>new Error(s.reason));try{await r.close()}catch(s){n.push(s)}if(n.length>0)throw new AggregateError(n,"Failed to close some servers")}async function Te(r,e,t){try{await z(r,e.filter(n=>n!==null))}catch(n){throw new AggregateError([t,n],"Failed to start Prisma Dev server cleanly")}throw t}function ke(r){let e=new Set;return{api:{stream:()=>{let t=()=>{},n=Be(r,()=>{e.delete(t)});return t=()=>n.close(),e.add(t),n.stream},subscribe:t=>r.subscribe(t)},close:()=>{for(let t of[...e])t();e.clear()}}}function Ae(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Qe(){return{async close(){},subscribe(){return()=>{}}}}function De(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function Be(r,e){let t=[],n=!1,s=null,i=r.subscribe(a=>{if(!n){if(s){let o=s;s=null,o.resolve({done:!1,value:a});return}t.push(a)}}),l=()=>{if(!n&&(n=!0,i(),t.length=0,e(),s)){let a=s;s=null,a.resolve({done:!0,value:void 0})}};return{close:l,stream:{[Symbol.asyncIterator](){return this},next(){return t.length>0?Promise.resolve({done:!1,value:t.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((a,o)=>{s={reject:o,resolve:a}})},return(){return l(),Promise.resolve({done:!0,value:void 0})},throw(a){let o=s;return l(),o&&o.reject(a),Promise.reject(a instanceof Error?a:new Error(String(a)))}}}}async function _e(r){let{server:e}=await Y(r);return e}async function Sr(r){return await _e(r)}export{_e as a,Sr as b};
|
|
1
|
+
import{a as W,b as O,f as R}from"./chunk-PP43TGA5.js";import{a as C,b as I,c as $,d as T,e as f,f as M}from"./chunk-2XJK3IOI.js";import{h as x}from"./chunk-EDFHV3AK.js";import{a as N}from"./chunk-HQMJSXYT.js";import{d as q,j as g}from"./chunk-DWY47FQV.js";import{a as _}from"./chunk-3UF2MBYQ.js";import{createServer as ee}from"http";import{promisify as re}from"util";async function j(r,e){let{port:t}=e;if(e.dryRun)return U(t,null);let n=await te(r,e),{promise:s,reject:i,resolve:l}=N(),{serve:a}=await import("@hono/node-server"),o=a({createServer:ee,fetch:n.fetch,overrideGlobalObjects:!1,port:t},l);o.on("error",m=>{if(typeof m=="object"&&"code"in m&&m.code==="EADDRINUSE")return i(new x(t));console.error("[Accelerate]",m)});let{port:c}=await s;return e.port=c,U(c,o)}function U(r,e){return{async close(){if(!e)return;let{Engine:t}=await import("./engine-XP6YJ63T.js");await Promise.allSettled([re(e.close.bind(e))(),t.stopAll()])},port:r,url:`http://localhost:${r}`}}async function te(r,e){let{debug:t}=e,[{Hono:n},{accelerateRoute:s},{utilityRoute:i}]=await Promise.all([import("hono/tiny"),import("./accelerate-5FDEK4T6.js"),import("./utility-Q5A254LJ.js")]),l=new n;if(t){let{logger:o}=await import("hono/logger");l.use("*",o((...c)=>console.log("[Accelerate]",...c)))}l.use("*",async(o,c)=>(o.set("databaseDumpPath",e.databaseDumpPath),o.set("db",r),o.set("debug",!!t),o.set("name",e.name),o.set("shadowDBPort",e.shadowDatabasePort),await c()));let a=new n;return a.route("/",s),a.route("/",i),l.route("/",a),l}import{isDeepStrictEqual as F}from"util";var ne="application/json",w={connection:"close","content-type":ne},k={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{applicationName:{type:["string","null"]},durationMs:{type:"number"},groupKey:{type:["string","null"]},query:{type:"string"},queryId:{type:"string"},reads:{type:"number"},rowsReturned:{type:"number"},tables:{items:{type:"string"},type:"array"},timestamp:{format:"date-time",type:"string"}},required:["durationMs","query","queryId","reads","rowsReturned","tables","timestamp"],type:"object"},search:{aliases:{applicationName:"applicationName",groupKey:"groupKey",queryId:"queryId"},fields:{applicationName:{bindings:[{jsonPointer:"/applicationName",version:1}],exact:!0,exists:!0,kind:"keyword"},eventTime:{bindings:[{jsonPointer:"/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},groupKey:{bindings:[{jsonPointer:"/groupKey",version:1}],exact:!0,exists:!0,kind:"keyword"},queryId:{bindings:[{jsonPointer:"/queryId",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};function H(r){return{...r,snapshot:async e=>await se(r.url,e)}}async function L(r){let e={serverUrl:r.serverUrl,sqlitePath:r.sqlitePath,streamName:I,url:f(r.serverUrl,I)};await oe(e);let t=new A({debug:r.debug,streamUrl:e.url}),n=r.bridge.subscribe(s=>{t.enqueue(s)});return{close:async()=>{n(),await t.close()},experimental:e}}async function se(r,e){if(!r)return W();let t=await ae(r);return O(t,e)}async function ae(r){let e=await fetch(`${r}?offset=-1&format=json`,{headers:{connection:"close"}});if(!e.ok)throw new Error(`Failed to read ${r}: HTTP ${e.status}`);return await e.json()}var A=class{#t;#r;#e;constructor(e){this.#t=e.debug,this.#r=Promise.resolve(),this.#e=e.streamUrl}enqueue(e){e.length!==0&&(this.#r=this.#r.then(async()=>{await ce(this.#e,e),this.#t&&console.debug(`[streams] appended ${e.length} query insight record(s) to ${this.#e}`)}).catch(t=>{console.error("[streams] failed to ingest query insights into prisma-queries",t)}))}async close(){await this.#r}};async function oe(r){let e=await fetch(r.url,{headers:w,method:"PUT"});if(!e.ok)throw await b(e,`Failed to create ${r.streamName}`);let t=await le(r);if(ie(t,r.streamName))return;if(t.currentVersion>0)throw new Error(`Failed to install schema for ${r.streamName}: existing schema registry is incompatible and requires a lens migration`);let n=await fetch(`${r.url}/_schema`,{body:JSON.stringify(k),headers:w,method:"POST"});if(!n.ok)throw await b(n,`Failed to install schema for ${r.streamName}`)}function ie(r,e){if(r.currentVersion<=0||r.schema!==e)return!1;let t=r.schemas[String(r.currentVersion)];return F(t,k.schema)&&F(r.search,k.search)}async function le(r){let e=await fetch(`${r.url}/_schema`,{headers:w,method:"GET"});if(!e.ok)throw await b(e,`Failed to inspect schema for ${r.streamName}`);return await e.json()}async function ce(r,e){let t=await fetch(r,{body:JSON.stringify(e),headers:w,method:"POST"});if(!t.ok)throw await b(t,"Failed to append to prisma-queries")}async function b(r,e){let t=await r.text().catch(()=>"");return new Error(`${e}: HTTP ${r.status}${t?` ${t}`:""}`)}import{randomUUID as me}from"crypto";import{setTimeout as K}from"timers/promises";import{isDeepStrictEqual as V}from"util";import{process as ue}from"std-env";var pe="application/json",y={connection:"close","content-type":pe},de={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},Q={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function G(r){let{dbServer:e,debug:t,name:n,persistenceMode:s,port:i,queryInsightsBridge:l,walBridge:a}=r,o=s==="stateless",c=o?Re(n):n,m=T(c),P=!o&&await q(m);ue.env.DS_LOCAL_DATA_ROOT=$(),o&&await g(m);let u=await ge({debug:t,hadExistingStreamsData:P,name:c,port:i}),d={serverUrl:u.exports.http.url,sqlitePath:u.exports.sqlite.path,streamName:C,url:f(u.exports.http.url)};try{await fe(d);let p=await L({bridge:l,debug:t,serverUrl:u.exports.http.url,sqlitePath:u.exports.sqlite.path}),h=new D({dbServer:e,debug:t,streamUrl:d.url}),X=a.subscribe(Z=>{h.enqueue(Z)});return{close:async()=>{X(),await h.close(),await p.close(),await u.close(),await K(100),o&&await g(m)},experimental:d,experimentalQueryInsights:p.experimental}}catch(p){throw await u.close().catch(()=>{}),await K(100),o&&await g(m).catch(()=>{}),p}}var he=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function ge(r){let{debug:e,hadExistingStreamsData:t,name:n,port:s}=r,{startLocalDurableStreamsServer:i}=await import("@prisma/streams-local"),l=()=>i({hostname:"127.0.0.1",name:n,port:s});try{return await l()}catch(a){if(!t||!ye(a))throw a;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),e&&console.debug(`[streams] original durable streams startup error for "${n}"`,a),await g(T(n)),await l()}}function ye(r){return Se(r).map(t=>t.toLowerCase()).some(t=>he.some(n=>t.includes(n)))}function Se(r){let e=[],t=[r],n=new Set;for(;t.length>0;){let s=t.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){e.push(s);continue}if(s instanceof AggregateError)for(let i of s.errors)t.push(i);if(s instanceof Error){e.push(s.message);let i=s.cause;i!==void 0&&t.push(i)}}}return e}var D=class{#t;#r;#e;#n;#s;constructor(e){this.#t=e.dbServer,this.#r=e.debug,this.#e=Promise.resolve(),this.#n=e.streamUrl,this.#s=new Set}enqueue(e){e.length!==0&&(this.#e=this.#e.then(async()=>{let t=await this.#o(e);t.length!==0&&(await we(this.#n,t),this.#r&&console.debug(`[streams] appended ${t.length} state-protocol record(s) to ${this.#n}`))}).catch(t=>{console.error("[streams] failed to ingest WAL events into prisma-wal",t)}))}async close(){await this.#e}async#o(e){let t=[],n=new Date().toISOString();for(let s of e)t.push(...await this.#i(s,n));return t}async#i(e,t){let n=`${e.schema}.${e.table}`,s=await this.#t.getPrimaryKeyColumns(e.schema,e.table),i=J(e.record),l=J(e.oldRecord),a=this.#a(n,s,l),o=this.#a(n,s,i),c=e.txid===""?void 0:e.txid;return e.type==="insert"?i&&o?[{headers:{operation:"insert",timestamp:t,txid:c},key:o,old_value:null,type:n,value:i}]:[]:e.type==="delete"?l&&a?[{headers:{operation:"delete",timestamp:t,txid:c},key:a,old_value:l,type:n,value:null}]:[]:!i||!l||!a||!o?[]:a!==o?[{headers:{operation:"delete",timestamp:t,txid:c},key:a,old_value:l,type:n,value:null},{headers:{operation:"insert",timestamp:t,txid:c},key:o,old_value:null,type:n,value:i}]:[{headers:{operation:"update",timestamp:t,txid:c},key:o,old_value:l,type:n,value:i}]}#a(e,t,n){if(!n)return null;let s=be(n,t);return s||(this.#s.has(e)||(this.#s.add(e),console.warn(`[streams] falling back to full-row keys for ${e} because no primary key could be resolved`)),Pe(n))}};async function fe(r){let e=await fetch(r.url,{headers:y,method:"PUT"});if(!e.ok)throw await S(e,`Failed to create ${r.streamName}`);let t=await fetch(`${r.url}/_profile`,{body:JSON.stringify(de),headers:y,method:"POST"});if(!t.ok)throw await S(t,`Failed to configure ${r.streamName}`);let n=await ve(r);if(Ee(n,r.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${r.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${r.url}/_schema`,{body:JSON.stringify(Q),headers:y,method:"POST"});if(!s.ok)throw await S(s,`Failed to install schema for ${r.streamName}`)}async function ve(r){let e=await fetch(`${r.url}/_schema`,{headers:y,method:"GET"});if(!e.ok)throw await S(e,`Failed to inspect schema for ${r.streamName}`);return await e.json()}function Ee(r,e){if(r.currentVersion<=0||r.schema!==e)return!1;let t=r.schemas[String(r.currentVersion)];return V(t,Q.schema)&&V(r.search,Q.search)}async function we(r,e){let t=await fetch(r,{body:JSON.stringify(e),headers:y,method:"POST"});if(!t.ok)throw await S(t,"Failed to append to prisma-wal")}async function S(r,e){let t=await r.text().catch(()=>"");return new Error(`${e}: HTTP ${r.status}${t?` ${t}`:""}`)}function be(r,e){if(e.length===0)return null;let t=[];for(let n of e){if(!Object.prototype.hasOwnProperty.call(r,n))return null;let s=xe(r[n]);if(s==null)return null;t.push(e.length===1?s:`${n}=${s}`)}return t.join("|")}function Pe(r){return JSON.stringify(B(r))}function B(r){return Array.isArray(r)?r.map(e=>B(e)):r&&typeof r=="object"?Object.fromEntries(Object.entries(r).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,B(t)])):r}function J(r){return r?structuredClone(r):null}function xe(r){if(r===null)return"null";if(r===void 0)return"undefined";if(typeof r=="string")return r;if(typeof r=="number")return Number.isFinite(r)?String(r):null;if(typeof r=="bigint")return r.toString();if(typeof r=="boolean")return r?"true":"false";try{return JSON.stringify(r)}catch{return null}}function Re(r){return`${r}.${me().replaceAll("-","")}`}async function Y(r){let e=await M.createExclusively(r),t=null,n=null,s=null,i=null;try{[t,s]=await Promise.all([R("database",e),R("shadow_database",e)]);let l,a;e.dryRun?(l=Ae(),a=Qe(),i=De()):(l=await t.attachWalEventBridge(),a=await t.attachQueryInsightsBridge(),i=await G({dbServer:t,debug:e.debug,name:e.name,port:e.streamsPort,persistenceMode:e.persistenceMode,queryInsightsBridge:a,walBridge:l})),n=await j(t,e);let o=Ie(t,s,n,e);await e.writeServerDump(o,e.dryRun?{}:{queryInsights:i.experimentalQueryInsights,streams:i.experimental});let c=ke(l),m=H(i.experimentalQueryInsights),P=t,u=s,d=n,p=i,h=async()=>{c.close(),await z(e,[d,p,P,u])};return{close:h,dbServer:t,httpServer:n,server:{...o,close:h,experimental:{queryInsights:m,streams:i.experimental,wal:c.api},name:e.name},serverState:e,shadowDbServer:s,streamsServer:i,queryInsightsBridge:a,walBridge:l}}catch(l){return await Te(e,[n,i,t,s],l)}}function Ie(r,e,t,n){let s=`prisma+postgres://localhost:${t.port}/?${new URLSearchParams({api_key:_({databaseUrl:r.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:e.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:r.connectionString,prismaORMConnectionString:r.prismaORMConnectionString,terminalCommand:r.terminalCommand},http:{url:t.url},ppg:{url:s},shadowDatabase:{connectionString:e.prismaORMConnectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand}}}async function z(r,e){let t=[];for(let n of e)try{await n.close()}catch(s){t.push(s)}try{await r.close()}catch(n){t.push(n)}if(t.length>0)throw new AggregateError(t,"Failed to close some servers")}async function Te(r,e,t){try{await z(r,e.filter(n=>n!==null))}catch(n){throw new AggregateError([t,n],"Failed to start Prisma Dev server cleanly")}throw t}function ke(r){let e=new Set;return{api:{stream:()=>{let t=()=>{},n=Be(r,()=>{e.delete(t)});return t=()=>n.close(),e.add(t),n.stream},subscribe:t=>r.subscribe(t)},close:()=>{for(let t of[...e])t();e.clear()}}}function Ae(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Qe(){return{async close(){},subscribe(){return()=>{}}}}function De(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function Be(r,e){let t=[],n=!1,s=null,i=r.subscribe(a=>{if(!n){if(s){let o=s;s=null,o.resolve({done:!1,value:a});return}t.push(a)}}),l=()=>{if(!n&&(n=!0,i(),t.length=0,e(),s)){let a=s;s=null,a.resolve({done:!0,value:void 0})}};return{close:l,stream:{[Symbol.asyncIterator](){return this},next(){return t.length>0?Promise.resolve({done:!1,value:t.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((a,o)=>{s={reject:o,resolve:a}})},return(){return l(),Promise.resolve({done:!0,value:void 0})},throw(a){let o=s;return l(),o&&o.reject(a),Promise.reject(a instanceof Error?a:new Error(String(a)))}}}}async function _e(r){let{server:e}=await Y(r);return e}async function Sr(r){return await _e(r)}export{_e as a,Sr as b};
|
package/dist/daemon.cjs
CHANGED
|
@@ -118,4 +118,4 @@ Received data: ${l}`));n({childProcess:a,url:`http://${p}:${f}`})},c=l=>{this.#t
|
|
|
118
118
|
ORDER BY keys.ordinality
|
|
119
119
|
`);return n.map(s=>s.column_name)}function Sr(e){return`'${e.replaceAll("'","''")}'`}async function Gs(e){let{dataDir:t,db:r,debug:n,destinationPath:s}=e,o=r||await _r(t,n),{pgDump:a}=await import("@electric-sql/pglite-tools/pg_dump"),i=await a({args:["--schema-only","--no-owner"],fileName:s?(0,wr.filename)(s):void 0,pg:await o.clone()});return s?(n&&console.debug(`[DB] Dumping database to ${s}`),await Ft(i,s)):(n&&console.debug("[DB] Dumping database to memory"),await i.text())}m();var ln=require("http"),dn=require("util");rt();async function mn(e,t){let{port:r}=t;if(t.dryRun)return un(r,null);let n=await fo(e,t),{promise:s,reject:o,resolve:a}=Pe(),{serve:i}=await import("@hono/node-server"),c=i({createServer:ln.createServer,fetch:n.fetch,overrideGlobalObjects:!1,port:r},a);c.on("error",l=>{if(typeof l=="object"&&"code"in l&&l.code==="EADDRINUSE")return o(new D(r));console.error("[Accelerate]",l)});let{port:u}=await s;return t.port=u,un(u,c)}function un(e,t){return{async close(){if(!t)return;let{Engine:r}=await Promise.resolve().then(()=>(ot(),st));await Promise.allSettled([(0,dn.promisify)(t.close.bind(t))(),r.stopAll()])},port:e,url:`http://localhost:${e}`}}async function fo(e,t){let{debug:r}=t,[{Hono:n},{accelerateRoute:s},{utilityRoute:o}]=await Promise.all([import("hono/tiny"),Promise.resolve().then(()=>(nn(),rn)),Promise.resolve().then(()=>(cn(),an))]),a=new n;if(r){let{logger:c}=await import("hono/logger");a.use("*",c((...u)=>console.log("[Accelerate]",...u)))}a.use("*",async(c,u)=>(c.set("databaseDumpPath",t.databaseDumpPath),c.set("db",e),c.set("debug",!!r),c.set("name",t.name),c.set("shadowDBPort",t.shadowDatabasePort),await u()));let i=new n;return i.route("/",s),i.route("/",o),a.route("/",i),a}m();var St=require("util");m();var ft=require("pathe");K();var ht="prisma-wal",yt="prisma-queries";function bt(){return(0,ft.join)(le.data,"durable-streams")}function Re(e){return(0,ft.join)(bt(),e)}function xe(e,t=ht){return new URL(`/v1/stream/${encodeURIComponent(t)}`,e).toString()}var ho="application/json",Te={connection:"close","content-type":ho},Pt={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{applicationName:{type:["string","null"]},durationMs:{type:"number"},groupKey:{type:["string","null"]},query:{type:"string"},queryId:{type:"string"},reads:{type:"number"},rowsReturned:{type:"number"},tables:{items:{type:"string"},type:"array"},timestamp:{format:"date-time",type:"string"}},required:["durationMs","query","queryId","reads","rowsReturned","tables","timestamp"],type:"object"},search:{aliases:{applicationName:"applicationName",groupKey:"groupKey",queryId:"queryId"},fields:{applicationName:{bindings:[{jsonPointer:"/applicationName",version:1}],exact:!0,exists:!0,kind:"keyword"},eventTime:{bindings:[{jsonPointer:"/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},groupKey:{bindings:[{jsonPointer:"/groupKey",version:1}],exact:!0,exists:!0,kind:"keyword"},queryId:{bindings:[{jsonPointer:"/queryId",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};function pn(e){return{...e,snapshot:async t=>await yo(e.url,t)}}async function gn(e){let t={serverUrl:e.serverUrl,sqlitePath:e.sqlitePath,streamName:yt,url:xe(e.serverUrl,yt)};await So(t);let r=new wt({debug:e.debug,streamUrl:t.url}),n=e.bridge.subscribe(s=>{r.enqueue(s)});return{close:async()=>{n(),await r.close()},experimental:t}}async function yo(e,t){if(!e)return Jt();let r=await bo(e);return tr(r,t)}async function bo(e){let t=await fetch(`${e}?offset=-1&format=json`,{headers:{connection:"close"}});if(!t.ok)throw new Error(`Failed to read ${e}: HTTP ${t.status}`);return await t.json()}var wt=class{#r;#e;#t;constructor(t){this.#r=t.debug,this.#e=Promise.resolve(),this.#t=t.streamUrl}enqueue(t){t.length!==0&&(this.#e=this.#e.then(async()=>{await Eo(this.#t,t),this.#r&&console.debug(`[streams] appended ${t.length} query insight record(s) to ${this.#t}`)}).catch(r=>{console.error("[streams] failed to ingest query insights into prisma-queries",r)}))}async close(){await this.#e}};async function So(e){let t=await fetch(e.url,{headers:Te,method:"PUT"});if(!t.ok)throw await Ie(t,`Failed to create ${e.streamName}`);let r=await wo(e);if(Po(r,e.streamName))return;if(r.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let n=await fetch(`${e.url}/_schema`,{body:JSON.stringify(Pt),headers:Te,method:"POST"});if(!n.ok)throw await Ie(n,`Failed to install schema for ${e.streamName}`)}function Po(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,St.isDeepStrictEqual)(r,Pt.schema)&&(0,St.isDeepStrictEqual)(e.search,Pt.search)}async function wo(e){let t=await fetch(`${e.url}/_schema`,{headers:Te,method:"GET"});if(!t.ok)throw await Ie(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}async function Eo(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:Te,method:"POST"});if(!r.ok)throw await Ie(r,"Failed to append to prisma-queries")}async function Ie(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}m();var Pn=require("fs/promises"),W=require("pathe"),z=require("proper-lockfile"),Tt=require("std-env"),g=require("valibot");K();m();var vo=require("timers/promises"),fn=require("std-env");function hn(e,t){if(e==null)return!1;try{return fn.process.kill?.(e,0)??!0}catch(r){return t&&console.error(`Error checking if process with PID ${e} exists:`,r),!1}}var ne=(0,g.pipe)((0,g.string)(),(0,g.url)()),yn=(0,g.object)({connectionString:ne,prismaORMConnectionString:(0,g.optional)(ne),terminalCommand:(0,g.optional)((0,g.string)())}),bn=(0,g.object)({url:ne}),Sn=(0,g.object)({serverUrl:ne,sqlitePath:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),streamName:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),url:ne}),Ro=(0,g.object)({queryInsights:(0,g.optional)(Sn),streams:(0,g.optional)(Sn)}),Et=(0,g.pipe)((0,g.number)(),(0,g.integer)(),(0,g.minValue)(1)),xo=(0,g.object)({database:yn,http:bn,ppg:bn,shadowDatabase:yn}),To=(0,g.object)({databasePort:Et,experimental:(0,g.optional)(Ro),exports:(0,g.optional)(xo),name:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),pid:(0,g.optional)((0,g.pipe)((0,g.number)(),(0,g.integer)(),(0,g.minValue)(0))),port:Et,shadowDatabasePort:Et,version:(0,g.literal)("1")}),It=Symbol("initialize"),vt="default",Io=new Set(["durable-streams"]),A=class{_databasePort;databaseConnectTimeoutMillis;databaseIdleTimeoutMillis;debug;dryRun;name;persistenceMode;pid;shadowDatabaseConnectTimeoutMillis;shadowDatabaseIdleTimeoutMillis;_port;_shadowDatabasePort;_streamsPort;constructor(t){this._databasePort=t.databasePort??I,this.databaseConnectTimeoutMillis=t.databaseConnectTimeoutMillis??6e4,this.databaseIdleTimeoutMillis=t.databaseIdleTimeoutMillis??1/0,this.debug=t.debug??!1,this.dryRun=t.dryRun??!1,this.name=t.name??vt,this.persistenceMode=t.persistenceMode,this.pid=t.pid??Tt.process.pid,this.shadowDatabaseConnectTimeoutMillis=t.shadowDatabaseConnectTimeoutMillis??this.databaseConnectTimeoutMillis,this.shadowDatabaseIdleTimeoutMillis=t.shadowDatabaseIdleTimeoutMillis??this.databaseIdleTimeoutMillis,this._port=t.port??I,this._shadowDatabasePort=t.shadowDatabasePort??I,this._streamsPort=t.streamsPort??I}static async createExclusively(t){let r=t?.dryRun!==!0&&t?.persistenceMode==="stateful"?new re(t):new Rt(t);return await r[It](),r}static async fromServerDump(t){let{debug:r,name:n=vt}=t??{},s=Y(n),o=re.getServerDumpPath(s),a=await Wt(o);if(a==null)return r&&console.debug(`[State] No server dump file found at: ${o}`),null;r&&(console.debug(`[State] server dump file found at "${o}":`),console.debug(a));let{issues:i,output:c,success:u}=(0,g.safeParse)((0,g.pipe)((0,g.string)(),(0,g.parseJson)(),To),a);if(!u)throw r&&console.debug(`[State] Invalid server dump file at "${o}":
|
|
120
120
|
${JSON.stringify(i,null,2)}`),new Error(`Invalid Prisma Dev state for "${n}".`);return new re({databasePort:c.databasePort,debug:r,dryRun:!1,name:n,pid:c.pid,port:c.port,serverDump:c,shadowDatabasePort:c.shadowDatabasePort})}static async scan(t){let{debug:r,globs:n}=t??{},s=(0,W.join)(Y(vt),"..");r&&console.debug(`[State] scanning for server states in: ${s}`);let o=(await Ht(s,n)).filter(a=>!Io.has(a));return r&&console.debug(`[State] found server names: ${JSON.stringify(o)}`),await Promise.all(o.map(a=>Do(a,t)))}get databasePort(){return this._databasePort}set databasePort(t){this.#r("databasePort",t)}get port(){return this._port}set port(t){this.#r("port",t)}get shadowDatabasePort(){return this._shadowDatabasePort}get streamsPort(){return this._streamsPort}set shadowDatabasePort(t){this.#r("shadowDatabasePort",t)}#r(t,r){if(r<0||!Number.isInteger(r))throw new Error(`Invalid port number: ${r}`);let n=`_${t}`;if(this[n]!==q&&this[n]!==r)throw new Error(`\`${t}\` is already set to ${this[n]}, cannot change it to ${r}`);this[n]=r}},Rt=class extends A{constructor(t){super({...t,databasePort:t?.databasePort||q,persistenceMode:"stateless",port:t?.port||q,shadowDatabasePort:t?.shadowDatabasePort||q,streamsPort:t?.streamsPort||q})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[It](){let t;try{t=await A.scan({debug:this.debug,onlyMetadata:!0})}catch(n){this.debug&&console.warn("[State] failed to scan for existing servers, assuming filesystem does not exist or other reasons.",n),t=[]}let r=await Fe({debug:this.debug,name:this.dryRun?this.name:"",requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort,streamsPort:this.streamsPort},servers:t});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,this._streamsPort=r.streamsPort}async close(){}async writeServerDump(){}},re=class e extends A{#r;#e;#t;#s;#o;#a;#n;constructor(t){super({...t,persistenceMode:"stateful"}),this.#a=!1,this.#e=Y(this.name),this.#r=(0,W.join)(this.#e,"db_dump.bak"),this.#t=(0,W.join)(this.#e,".lock"),this.#s=(0,W.join)(this.#e,".pglite"),this.#n=t?.serverDump??null,this.#o=e.getServerDumpPath(this.#e)}static getServerDumpPath(t){return(0,W.join)(t,"server.json")}get databaseDumpPath(){return this.#r}get exports(){return this.#n?.exports}get experimental(){return this.#n?.experimental}get pgliteDataDirPath(){return this.#s}async[It](){await Gt(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{await(0,z.lock)(this.#e,{lockfilePath:this.#t}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let t=await A.scan({debug:this.debug,onlyMetadata:!0}),r=await Fe({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort,streamsPort:this.streamsPort},servers:t});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,this._streamsPort=r.streamsPort,await this.writeServerDump()}catch(t){throw t instanceof Error&&"code"in t&&t.code==="ELOCKED"?new De(this):t}}async close(){if(!this.#a)try{await(0,z.unlock)(this.#e,{lockfilePath:this.#t}),this.#a=!0,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(t){throw this.debug&&console.error(`[State] failed to release lock on: ${this.#e}`,t),t}}async writeServerDump(t,r){this.#n={name:this.name,version:"1",pid:Tt.process.pid,port:this.port,databasePort:this.databasePort,experimental:r,shadowDatabasePort:this.shadowDatabasePort,exports:t},await(0,Pn.writeFile)(this.#o,`${JSON.stringify(this.#n,null,2)}
|
|
121
|
-
`,{encoding:"utf-8"})}};async function Do(e,t){let{debug:r,onlyMetadata:n}=t||{},s=typeof e=="string"?e:e.name,o=typeof e!="string"?e:void 0,a={databasePort:o?.databasePort??-1,experimental:o?.experimental,exports:o?.exports,name:s,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await A.fromServerDump({debug:r,name:s});if(!i)return r&&console.debug(`[State] no server state found for name: ${s}`),{...a,status:"no_such_server"};a.databasePort=i.databasePort,a.experimental=i.experimental,a.exports=i.exports,a.pid=i.pid,a.port=i.port,a.shadowDatabasePort=i.shadowDatabasePort;let{exports:c,pid:u}=i;if(n)return{...a,status:"unknown"};if(!hn(u,r))return r&&console.debug(`[State] server state for "${s}" has no running process with PID: ${u}`),{...a,status:"not_running"};let l=Y(s);try{if(!await(0,z.check)(l,{lockfilePath:(0,W.join)(l,".lock")}))return r&&console.debug(`[State] server state for "${s}" is not locked, indicating it is not running.`),{...a,status:"not_running"}}catch(E){r&&console.error(`[State] server state for "${s}" failed to check lock:`,E)}if(!c)return{...a,status:"starting_up"};let{http:h}=c,{hc:d}=await import("hono/client"),p=await d(h.url).health.$get();if(!p.ok)return r&&console.debug(`[State] server state for "${s}" is not live: ${JSON.stringify(p)}`),{...a,status:"not_running"};let f=await p.json();return f.name!==e?(r&&console.debug(`[State] server state for "${s}" has mismatched health response: ${JSON.stringify(f)}`),{...a,status:"unknown"}):(r&&console.debug(`[State] server state for "${e}" is live: ${JSON.stringify(f)}`),{...a,status:"running"})}catch(i){return r&&console.error(`[State] failed to get server status for "${s}":`,i),{...a,status:"error"}}}var xt=class extends Error{name="ServerStateAlreadyExistsError";constructor(t){super(`A Prisma Dev server with the name "${t}" is already running.`)}},De=class extends xt{#r;name="ServerAlreadyRunningError";constructor(t){super(t.name),this.#r=t}get server(){return A.fromServerDump({debug:this.#r.debug,name:this.#r.name})}};m();var En=require("crypto"),Dt=require("timers/promises"),_t=require("util"),vn=require("std-env");K();var _o="application/json",se={connection:"close","content-type":_o},Ao={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},At={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function Rn(e){let{dbServer:t,debug:r,name:n,persistenceMode:s,port:o,queryInsightsBridge:a,walBridge:i}=e,c=s==="stateless",u=c?Fo(n):n,l=Re(u),h=!c&&await H(l);vn.process.env.DS_LOCAL_DATA_ROOT=bt(),c&&await j(l);let d=await Oo({debug:r,hadExistingStreamsData:h,name:u,port:o}),p={serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path,streamName:ht,url:xe(d.exports.http.url)};try{await Lo(p);let f=await gn({bridge:a,debug:r,serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path}),E=new Nt({dbServer:t,debug:r,streamUrl:p.url}),J=i.subscribe(_e=>{E.enqueue(_e)});return{close:async()=>{J(),await E.close(),await f.close(),await d.close(),await(0,Dt.setTimeout)(100),c&&await j(l)},experimental:p,experimentalQueryInsights:f.experimental}}catch(f){throw await d.close().catch(()=>{}),await(0,Dt.setTimeout)(100),c&&await j(l).catch(()=>{}),f}}var No=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function Oo(e){let{debug:t,hadExistingStreamsData:r,name:n,port:s}=e,{startLocalDurableStreamsServer:o}=await import("@prisma/streams-local"),a=()=>o({hostname:"127.0.0.1",name:n,port:s});try{return await a()}catch(i){if(!r||!Mo(i))throw i;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),t&&console.debug(`[streams] original durable streams startup error for "${n}"`,i),await j(Re(n)),await a()}}function Mo(e){return Bo(e).map(r=>r.toLowerCase()).some(r=>No.some(n=>r.includes(n)))}function Bo(e){let t=[],r=[e],n=new Set;for(;r.length>0;){let s=r.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){t.push(s);continue}if(s instanceof AggregateError)for(let o of s.errors)r.push(o);if(s instanceof Error){t.push(s.message);let o=s.cause;o!==void 0&&r.push(o)}}}return t}var Nt=class{#r;#e;#t;#s;#o;constructor(t){this.#r=t.dbServer,this.#e=t.debug,this.#t=Promise.resolve(),this.#s=t.streamUrl,this.#o=new Set}enqueue(t){t.length!==0&&(this.#t=this.#t.then(async()=>{let r=await this.#a(t);r.length!==0&&(await Co(this.#s,r),this.#e&&console.debug(`[streams] appended ${r.length} state-protocol record(s) to ${this.#s}`))}).catch(r=>{console.error("[streams] failed to ingest WAL events into prisma-wal",r)}))}async close(){await this.#t}async#a(t){let r=[],n=new Date().toISOString();for(let s of t)r.push(...await this.#n(s,n));return r}async#n(t,r){let n=`${t.schema}.${t.table}`,s=await this.#r.getPrimaryKeyColumns(t.schema,t.table),o=wn(t.record),a=wn(t.oldRecord),i=this.#i(n,s,a),c=this.#i(n,s,o),u=t.txid===""?void 0:t.txid;return t.type==="insert"?o&&c?[{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[]:t.type==="delete"?a&&i?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null}]:[]:!o||!a||!i||!c?[]:i!==c?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null},{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[{headers:{operation:"update",timestamp:r,txid:u},key:c,old_value:a,type:n,value:o}]}#i(t,r,n){if(!n)return null;let s=Uo(n,r);return s||(this.#o.has(t)||(this.#o.add(t),console.warn(`[streams] falling back to full-row keys for ${t} because no primary key could be resolved`)),Qo(n))}};async function Lo(e){let t=await fetch(e.url,{headers:se,method:"PUT"});if(!t.ok)throw await oe(t,`Failed to create ${e.streamName}`);let r=await fetch(`${e.url}/_profile`,{body:JSON.stringify(Ao),headers:se,method:"POST"});if(!r.ok)throw await oe(r,`Failed to configure ${e.streamName}`);let n=await $o(e);if(ko(n,e.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${e.url}/_schema`,{body:JSON.stringify(At),headers:se,method:"POST"});if(!s.ok)throw await oe(s,`Failed to install schema for ${e.streamName}`)}async function $o(e){let t=await fetch(`${e.url}/_schema`,{headers:se,method:"GET"});if(!t.ok)throw await oe(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}function ko(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,_t.isDeepStrictEqual)(r,At.schema)&&(0,_t.isDeepStrictEqual)(e.search,At.search)}async function Co(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:se,method:"POST"});if(!r.ok)throw await oe(r,"Failed to append to prisma-wal")}async function oe(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}function Uo(e,t){if(t.length===0)return null;let r=[];for(let n of t){if(!Object.prototype.hasOwnProperty.call(e,n))return null;let s=qo(e[n]);if(s==null)return null;r.push(t.length===1?s:`${n}=${s}`)}return r.join("|")}function Qo(e){return JSON.stringify(Ot(e))}function Ot(e){return Array.isArray(e)?e.map(t=>Ot(t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Ot(r)])):e}function wn(e){return e?structuredClone(e):null}function qo(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e=="bigint")return e.toString();if(typeof e=="boolean")return e?"true":"false";try{return JSON.stringify(e)}catch{return null}}function Fo(e){return`${e}.${(0,En.randomUUID)().replaceAll("-","")}`}async function xn(e){let t=await A.createExclusively(e),r=null,n=null,s=null,o=null;try{[r,s]=await Promise.all([tt("database",t),tt("shadow_database",t)]);let a,i;t.dryRun?(a=jo(),i=Ko(),o=Vo()):(a=await r.attachWalEventBridge(),i=await r.attachQueryInsightsBridge(),o=await Rn({dbServer:r,debug:t.debug,name:t.name,port:t.streamsPort,persistenceMode:t.persistenceMode,queryInsightsBridge:i,walBridge:a})),n=await mn(r,t);let c=Wo(r,s,n,t);await t.writeServerDump(c,t.dryRun?{}:{queryInsights:o.experimentalQueryInsights,streams:o.experimental});let u=Ho(a),l=pn(o.experimentalQueryInsights),h=r,d=s,p=n,f=o,E=async()=>{u.close(),await Tn(t,[p,f,h,d])};return{close:E,dbServer:r,httpServer:n,server:{...c,close:E,experimental:{queryInsights:l,streams:o.experimental,wal:u.api},name:t.name},serverState:t,shadowDbServer:s,streamsServer:o,queryInsightsBridge:i,walBridge:a}}catch(a){return await Go(t,[n,o,r,s],a)}}function Wo(e,t,r,n){let s=`prisma+postgres://localhost:${r.port}/?${new URLSearchParams({api_key:Lt({databaseUrl:e.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:e.connectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand},http:{url:r.url},ppg:{url:s},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}}}async function Tn(e,t){let n=(await Promise.allSettled(t.map(s=>s.close()))).filter(s=>s.status==="rejected").map(s=>new Error(s.reason));try{await e.close()}catch(s){n.push(s)}if(n.length>0)throw new AggregateError(n,"Failed to close some servers")}async function Go(e,t,r){try{await Tn(e,t.filter(n=>n!==null))}catch(n){throw new AggregateError([r,n],"Failed to start Prisma Dev server cleanly")}throw r}function Ho(e){let t=new Set;return{api:{stream:()=>{let r=()=>{},n=zo(e,()=>{t.delete(r)});return r=()=>n.close(),t.add(r),n.stream},subscribe:r=>e.subscribe(r)},close:()=>{for(let r of[...t])r();t.clear()}}}function jo(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Ko(){return{async close(){},subscribe(){return()=>{}}}}function Vo(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function zo(e,t){let r=[],n=!1,s=null,o=e.subscribe(i=>{if(!n){if(s){let c=s;s=null,c.resolve({done:!1,value:i});return}r.push(i)}}),a=()=>{if(!n&&(n=!0,o(),r.length=0,t(),s)){let i=s;s=null,i.resolve({done:!0,value:void 0})}};return{close:a,stream:{[Symbol.asyncIterator](){return this},next(){return r.length>0?Promise.resolve({done:!1,value:r.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((i,c)=>{s={reject:c,resolve:i}})},return(){return a(),Promise.resolve({done:!0,value:void 0})},throw(i){let c=s;return a(),c&&c.reject(i),Promise.reject(i instanceof Error?i:new Error(String(i)))}}}}async function In(e){let{server:t}=await xn(e);return t}var N;process.once("SIGTERM",()=>{console.log("SIGTERM received, shutting down..."),process.removeAllListeners("SIGINT"),process.exitCode=143,N?.close().finally(()=>process.exit())});process.once("SIGINT",()=>{console.log("SIGINT received, shutting down..."),process.removeAllListeners("SIGTERM"),process.exitCode=130,N?.close().finally(()=>process.exit())});async function Jo(){let[,,e]=process.argv;if(!e)return process.send?.({type:"error",error:'Missing "name" argument, server cannot be started'},void 0),process.exit(1);try{N=await In({debug:!0,persistenceMode:"stateful",name:e});let t=N.experimental.queryInsights,r={database:N.database,experimental:{queryInsights:{serverUrl:t.serverUrl,sqlitePath:t.sqlitePath,streamName:t.streamName,url:t.url},streams:N.experimental.streams},http:N.http,name:N.name,ppg:N.ppg,shadowDatabase:N.shadowDatabase};process.send?.({type:"started",server:r},void 0)}catch(t){console.error(t);let r=t instanceof Error?t.message:String(t);process.send?.({type:"error",error:r},void 0),await(0,Dn.setTimeout)(1e3),process.exit(1)}}Jo();
|
|
121
|
+
`,{encoding:"utf-8"})}};async function Do(e,t){let{debug:r,onlyMetadata:n}=t||{},s=typeof e=="string"?e:e.name,o=typeof e!="string"?e:void 0,a={databasePort:o?.databasePort??-1,experimental:o?.experimental,exports:o?.exports,name:s,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await A.fromServerDump({debug:r,name:s});if(!i)return r&&console.debug(`[State] no server state found for name: ${s}`),{...a,status:"no_such_server"};a.databasePort=i.databasePort,a.experimental=i.experimental,a.exports=i.exports,a.pid=i.pid,a.port=i.port,a.shadowDatabasePort=i.shadowDatabasePort;let{exports:c,pid:u}=i;if(n)return{...a,status:"unknown"};if(!hn(u,r))return r&&console.debug(`[State] server state for "${s}" has no running process with PID: ${u}`),{...a,status:"not_running"};let l=Y(s);try{if(!await(0,z.check)(l,{lockfilePath:(0,W.join)(l,".lock")}))return r&&console.debug(`[State] server state for "${s}" is not locked, indicating it is not running.`),{...a,status:"not_running"}}catch(E){r&&console.error(`[State] server state for "${s}" failed to check lock:`,E)}if(!c)return{...a,status:"starting_up"};let{http:h}=c,{hc:d}=await import("hono/client"),p=await d(h.url).health.$get();if(!p.ok)return r&&console.debug(`[State] server state for "${s}" is not live: ${JSON.stringify(p)}`),{...a,status:"not_running"};let f=await p.json();return f.name!==e?(r&&console.debug(`[State] server state for "${s}" has mismatched health response: ${JSON.stringify(f)}`),{...a,status:"unknown"}):(r&&console.debug(`[State] server state for "${e}" is live: ${JSON.stringify(f)}`),{...a,status:"running"})}catch(i){return r&&console.error(`[State] failed to get server status for "${s}":`,i),{...a,status:"error"}}}var xt=class extends Error{name="ServerStateAlreadyExistsError";constructor(t){super(`A Prisma Dev server with the name "${t}" is already running.`)}},De=class extends xt{#r;name="ServerAlreadyRunningError";constructor(t){super(t.name),this.#r=t}get server(){return A.fromServerDump({debug:this.#r.debug,name:this.#r.name})}};m();var En=require("crypto"),Dt=require("timers/promises"),_t=require("util"),vn=require("std-env");K();var _o="application/json",se={connection:"close","content-type":_o},Ao={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},At={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function Rn(e){let{dbServer:t,debug:r,name:n,persistenceMode:s,port:o,queryInsightsBridge:a,walBridge:i}=e,c=s==="stateless",u=c?Fo(n):n,l=Re(u),h=!c&&await H(l);vn.process.env.DS_LOCAL_DATA_ROOT=bt(),c&&await j(l);let d=await Oo({debug:r,hadExistingStreamsData:h,name:u,port:o}),p={serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path,streamName:ht,url:xe(d.exports.http.url)};try{await Lo(p);let f=await gn({bridge:a,debug:r,serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path}),E=new Nt({dbServer:t,debug:r,streamUrl:p.url}),J=i.subscribe(_e=>{E.enqueue(_e)});return{close:async()=>{J(),await E.close(),await f.close(),await d.close(),await(0,Dt.setTimeout)(100),c&&await j(l)},experimental:p,experimentalQueryInsights:f.experimental}}catch(f){throw await d.close().catch(()=>{}),await(0,Dt.setTimeout)(100),c&&await j(l).catch(()=>{}),f}}var No=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function Oo(e){let{debug:t,hadExistingStreamsData:r,name:n,port:s}=e,{startLocalDurableStreamsServer:o}=await import("@prisma/streams-local"),a=()=>o({hostname:"127.0.0.1",name:n,port:s});try{return await a()}catch(i){if(!r||!Mo(i))throw i;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),t&&console.debug(`[streams] original durable streams startup error for "${n}"`,i),await j(Re(n)),await a()}}function Mo(e){return Bo(e).map(r=>r.toLowerCase()).some(r=>No.some(n=>r.includes(n)))}function Bo(e){let t=[],r=[e],n=new Set;for(;r.length>0;){let s=r.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){t.push(s);continue}if(s instanceof AggregateError)for(let o of s.errors)r.push(o);if(s instanceof Error){t.push(s.message);let o=s.cause;o!==void 0&&r.push(o)}}}return t}var Nt=class{#r;#e;#t;#s;#o;constructor(t){this.#r=t.dbServer,this.#e=t.debug,this.#t=Promise.resolve(),this.#s=t.streamUrl,this.#o=new Set}enqueue(t){t.length!==0&&(this.#t=this.#t.then(async()=>{let r=await this.#a(t);r.length!==0&&(await Co(this.#s,r),this.#e&&console.debug(`[streams] appended ${r.length} state-protocol record(s) to ${this.#s}`))}).catch(r=>{console.error("[streams] failed to ingest WAL events into prisma-wal",r)}))}async close(){await this.#t}async#a(t){let r=[],n=new Date().toISOString();for(let s of t)r.push(...await this.#n(s,n));return r}async#n(t,r){let n=`${t.schema}.${t.table}`,s=await this.#r.getPrimaryKeyColumns(t.schema,t.table),o=wn(t.record),a=wn(t.oldRecord),i=this.#i(n,s,a),c=this.#i(n,s,o),u=t.txid===""?void 0:t.txid;return t.type==="insert"?o&&c?[{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[]:t.type==="delete"?a&&i?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null}]:[]:!o||!a||!i||!c?[]:i!==c?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null},{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[{headers:{operation:"update",timestamp:r,txid:u},key:c,old_value:a,type:n,value:o}]}#i(t,r,n){if(!n)return null;let s=Uo(n,r);return s||(this.#o.has(t)||(this.#o.add(t),console.warn(`[streams] falling back to full-row keys for ${t} because no primary key could be resolved`)),Qo(n))}};async function Lo(e){let t=await fetch(e.url,{headers:se,method:"PUT"});if(!t.ok)throw await oe(t,`Failed to create ${e.streamName}`);let r=await fetch(`${e.url}/_profile`,{body:JSON.stringify(Ao),headers:se,method:"POST"});if(!r.ok)throw await oe(r,`Failed to configure ${e.streamName}`);let n=await $o(e);if(ko(n,e.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${e.url}/_schema`,{body:JSON.stringify(At),headers:se,method:"POST"});if(!s.ok)throw await oe(s,`Failed to install schema for ${e.streamName}`)}async function $o(e){let t=await fetch(`${e.url}/_schema`,{headers:se,method:"GET"});if(!t.ok)throw await oe(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}function ko(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,_t.isDeepStrictEqual)(r,At.schema)&&(0,_t.isDeepStrictEqual)(e.search,At.search)}async function Co(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:se,method:"POST"});if(!r.ok)throw await oe(r,"Failed to append to prisma-wal")}async function oe(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}function Uo(e,t){if(t.length===0)return null;let r=[];for(let n of t){if(!Object.prototype.hasOwnProperty.call(e,n))return null;let s=qo(e[n]);if(s==null)return null;r.push(t.length===1?s:`${n}=${s}`)}return r.join("|")}function Qo(e){return JSON.stringify(Ot(e))}function Ot(e){return Array.isArray(e)?e.map(t=>Ot(t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Ot(r)])):e}function wn(e){return e?structuredClone(e):null}function qo(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e=="bigint")return e.toString();if(typeof e=="boolean")return e?"true":"false";try{return JSON.stringify(e)}catch{return null}}function Fo(e){return`${e}.${(0,En.randomUUID)().replaceAll("-","")}`}async function xn(e){let t=await A.createExclusively(e),r=null,n=null,s=null,o=null;try{[r,s]=await Promise.all([tt("database",t),tt("shadow_database",t)]);let a,i;t.dryRun?(a=jo(),i=Ko(),o=Vo()):(a=await r.attachWalEventBridge(),i=await r.attachQueryInsightsBridge(),o=await Rn({dbServer:r,debug:t.debug,name:t.name,port:t.streamsPort,persistenceMode:t.persistenceMode,queryInsightsBridge:i,walBridge:a})),n=await mn(r,t);let c=Wo(r,s,n,t);await t.writeServerDump(c,t.dryRun?{}:{queryInsights:o.experimentalQueryInsights,streams:o.experimental});let u=Ho(a),l=pn(o.experimentalQueryInsights),h=r,d=s,p=n,f=o,E=async()=>{u.close(),await Tn(t,[p,f,h,d])};return{close:E,dbServer:r,httpServer:n,server:{...c,close:E,experimental:{queryInsights:l,streams:o.experimental,wal:u.api},name:t.name},serverState:t,shadowDbServer:s,streamsServer:o,queryInsightsBridge:i,walBridge:a}}catch(a){return await Go(t,[n,o,r,s],a)}}function Wo(e,t,r,n){let s=`prisma+postgres://localhost:${r.port}/?${new URLSearchParams({api_key:Lt({databaseUrl:e.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:e.connectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand},http:{url:r.url},ppg:{url:s},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}}}async function Tn(e,t){let r=[];for(let n of t)try{await n.close()}catch(s){r.push(s)}try{await e.close()}catch(n){r.push(n)}if(r.length>0)throw new AggregateError(r,"Failed to close some servers")}async function Go(e,t,r){try{await Tn(e,t.filter(n=>n!==null))}catch(n){throw new AggregateError([r,n],"Failed to start Prisma Dev server cleanly")}throw r}function Ho(e){let t=new Set;return{api:{stream:()=>{let r=()=>{},n=zo(e,()=>{t.delete(r)});return r=()=>n.close(),t.add(r),n.stream},subscribe:r=>e.subscribe(r)},close:()=>{for(let r of[...t])r();t.clear()}}}function jo(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Ko(){return{async close(){},subscribe(){return()=>{}}}}function Vo(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function zo(e,t){let r=[],n=!1,s=null,o=e.subscribe(i=>{if(!n){if(s){let c=s;s=null,c.resolve({done:!1,value:i});return}r.push(i)}}),a=()=>{if(!n&&(n=!0,o(),r.length=0,t(),s)){let i=s;s=null,i.resolve({done:!0,value:void 0})}};return{close:a,stream:{[Symbol.asyncIterator](){return this},next(){return r.length>0?Promise.resolve({done:!1,value:r.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((i,c)=>{s={reject:c,resolve:i}})},return(){return a(),Promise.resolve({done:!0,value:void 0})},throw(i){let c=s;return a(),c&&c.reject(i),Promise.reject(i instanceof Error?i:new Error(String(i)))}}}}async function In(e){let{server:t}=await xn(e);return t}var N;process.once("SIGTERM",()=>{console.log("SIGTERM received, shutting down..."),process.removeAllListeners("SIGINT"),process.exitCode=143,N?.close().finally(()=>process.exit())});process.once("SIGINT",()=>{console.log("SIGINT received, shutting down..."),process.removeAllListeners("SIGTERM"),process.exitCode=130,N?.close().finally(()=>process.exit())});async function Jo(){let[,,e]=process.argv;if(!e)return process.send?.({type:"error",error:'Missing "name" argument, server cannot be started'},void 0),process.exit(1);try{N=await In({debug:!0,persistenceMode:"stateful",name:e});let t=N.experimental.queryInsights,r={database:N.database,experimental:{queryInsights:{serverUrl:t.serverUrl,sqlitePath:t.sqlitePath,streamName:t.streamName,url:t.url},streams:N.experimental.streams},http:N.http,name:N.name,ppg:N.ppg,shadowDatabase:N.shadowDatabase};process.send?.({type:"started",server:r},void 0)}catch(t){console.error(t);let r=t instanceof Error?t.message:String(t);process.send?.({type:"error",error:r},void 0),await(0,Dn.setTimeout)(1e3),process.exit(1)}}Jo();
|
package/dist/daemon.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-GMUOAEZU.js";import"./chunk-PP43TGA5.js";import"./chunk-KWCQYPJI.js";import"./chunk-2XJK3IOI.js";import"./chunk-EDFHV3AK.js";import"./chunk-HQMJSXYT.js";import"./chunk-DWY47FQV.js";import"./chunk-3UF2MBYQ.js";import{setTimeout as o}from"timers/promises";var e;process.once("SIGTERM",()=>{console.log("SIGTERM received, shutting down..."),process.removeAllListeners("SIGINT"),process.exitCode=143,e?.close().finally(()=>process.exit())});process.once("SIGINT",()=>{console.log("SIGINT received, shutting down..."),process.removeAllListeners("SIGTERM"),process.exitCode=130,e?.close().finally(()=>process.exit())});async function n(){let[,,t]=process.argv;if(!t)return process.send?.({type:"error",error:'Missing "name" argument, server cannot be started'},void 0),process.exit(1);try{e=await a({debug:!0,persistenceMode:"stateful",name:t});let r=e.experimental.queryInsights,s={database:e.database,experimental:{queryInsights:{serverUrl:r.serverUrl,sqlitePath:r.sqlitePath,streamName:r.streamName,url:r.url},streams:e.experimental.streams},http:e.http,name:e.name,ppg:e.ppg,shadowDatabase:e.shadowDatabase};process.send?.({type:"started",server:s},void 0)}catch(r){console.error(r);let s=r instanceof Error?r.message:String(r);process.send?.({type:"error",error:s},void 0),await o(1e3),process.exit(1)}}n();
|
package/dist/index.cjs
CHANGED
|
@@ -118,4 +118,4 @@ Received data: ${l}`));n({childProcess:a,url:`http://${m}:${f}`})},c=l=>{this.#t
|
|
|
118
118
|
ORDER BY keys.ordinality
|
|
119
119
|
`);return n.map(s=>s.column_name)}function Er(e){return`'${e.replaceAll("'","''")}'`}async function Hs(e){let{dataDir:t,db:r,debug:n,destinationPath:s}=e,o=r||await Nr(t,n),{pgDump:a}=await import("@electric-sql/pglite-tools/pg_dump"),i=await a({args:["--schema-only","--no-owner"],fileName:s?(0,Rr.filename)(s):void 0,pg:await o.clone()});return s?(n&&console.debug(`[DB] Dumping database to ${s}`),await Ft(i,s)):(n&&console.debug("[DB] Dumping database to memory"),await i.text())}p();var pn=require("http"),gn=require("util");rt();async function fn(e,t){let{port:r}=t;if(t.dryRun)return mn(r,null);let n=await fo(e,t),{promise:s,reject:o,resolve:a}=Re(),{serve:i}=await import("@hono/node-server"),c=i({createServer:pn.createServer,fetch:n.fetch,overrideGlobalObjects:!1,port:r},a);c.on("error",l=>{if(typeof l=="object"&&"code"in l&&l.code==="EADDRINUSE")return o(new _(r));console.error("[Accelerate]",l)});let{port:u}=await s;return t.port=u,mn(u,c)}function mn(e,t){return{async close(){if(!t)return;let{Engine:r}=await Promise.resolve().then(()=>(ot(),st));await Promise.allSettled([(0,gn.promisify)(t.close.bind(t))(),r.stopAll()])},port:e,url:`http://localhost:${e}`}}async function fo(e,t){let{debug:r}=t,[{Hono:n},{accelerateRoute:s},{utilityRoute:o}]=await Promise.all([import("hono/tiny"),Promise.resolve().then(()=>(an(),on)),Promise.resolve().then(()=>(dn(),ln))]),a=new n;if(r){let{logger:c}=await import("hono/logger");a.use("*",c((...u)=>console.log("[Accelerate]",...u)))}a.use("*",async(c,u)=>(c.set("databaseDumpPath",t.databaseDumpPath),c.set("db",e),c.set("debug",!!r),c.set("name",t.name),c.set("shadowDBPort",t.shadowDatabasePort),await u()));let i=new n;return i.route("/",s),i.route("/",o),a.route("/",i),a}p();var St=require("util");p();var ft=require("pathe");j();var ht="prisma-wal",yt="prisma-queries";function bt(){return(0,ft.join)(me.data,"durable-streams")}function De(e){return(0,ft.join)(bt(),e)}function _e(e,t=ht){return new URL(`/v1/stream/${encodeURIComponent(t)}`,e).toString()}var ho="application/json",Ae={connection:"close","content-type":ho},Pt={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{applicationName:{type:["string","null"]},durationMs:{type:"number"},groupKey:{type:["string","null"]},query:{type:"string"},queryId:{type:"string"},reads:{type:"number"},rowsReturned:{type:"number"},tables:{items:{type:"string"},type:"array"},timestamp:{format:"date-time",type:"string"}},required:["durationMs","query","queryId","reads","rowsReturned","tables","timestamp"],type:"object"},search:{aliases:{applicationName:"applicationName",groupKey:"groupKey",queryId:"queryId"},fields:{applicationName:{bindings:[{jsonPointer:"/applicationName",version:1}],exact:!0,exists:!0,kind:"keyword"},eventTime:{bindings:[{jsonPointer:"/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},groupKey:{bindings:[{jsonPointer:"/groupKey",version:1}],exact:!0,exists:!0,kind:"keyword"},queryId:{bindings:[{jsonPointer:"/queryId",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};function hn(e){return{...e,snapshot:async t=>await yo(e.url,t)}}async function yn(e){let t={serverUrl:e.serverUrl,sqlitePath:e.sqlitePath,streamName:yt,url:_e(e.serverUrl,yt)};await So(t);let r=new wt({debug:e.debug,streamUrl:t.url}),n=e.bridge.subscribe(s=>{r.enqueue(s)});return{close:async()=>{n(),await r.close()},experimental:t}}async function yo(e,t){if(!e)return Jt();let r=await bo(e);return tr(r,t)}async function bo(e){let t=await fetch(`${e}?offset=-1&format=json`,{headers:{connection:"close"}});if(!t.ok)throw new Error(`Failed to read ${e}: HTTP ${t.status}`);return await t.json()}var wt=class{#r;#e;#t;constructor(t){this.#r=t.debug,this.#e=Promise.resolve(),this.#t=t.streamUrl}enqueue(t){t.length!==0&&(this.#e=this.#e.then(async()=>{await Eo(this.#t,t),this.#r&&console.debug(`[streams] appended ${t.length} query insight record(s) to ${this.#t}`)}).catch(r=>{console.error("[streams] failed to ingest query insights into prisma-queries",r)}))}async close(){await this.#e}};async function So(e){let t=await fetch(e.url,{headers:Ae,method:"PUT"});if(!t.ok)throw await Oe(t,`Failed to create ${e.streamName}`);let r=await wo(e);if(Po(r,e.streamName))return;if(r.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let n=await fetch(`${e.url}/_schema`,{body:JSON.stringify(Pt),headers:Ae,method:"POST"});if(!n.ok)throw await Oe(n,`Failed to install schema for ${e.streamName}`)}function Po(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,St.isDeepStrictEqual)(r,Pt.schema)&&(0,St.isDeepStrictEqual)(e.search,Pt.search)}async function wo(e){let t=await fetch(`${e.url}/_schema`,{headers:Ae,method:"GET"});if(!t.ok)throw await Oe(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}async function Eo(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:Ae,method:"POST"});if(!r.ok)throw await Oe(r,"Failed to append to prisma-queries")}async function Oe(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}p();var vn=require("fs/promises"),F=require("pathe"),z=require("proper-lockfile"),Tt=require("std-env"),g=require("valibot");j();p();var vo=require("timers/promises"),bn=require("std-env");function Sn(e,t){if(e==null)return!1;try{return bn.process.kill?.(e,0)??!0}catch(r){return t&&console.error(`Error checking if process with PID ${e} exists:`,r),!1}}var oe=(0,g.pipe)((0,g.string)(),(0,g.url)()),Pn=(0,g.object)({connectionString:oe,prismaORMConnectionString:(0,g.optional)(oe),terminalCommand:(0,g.optional)((0,g.string)())}),wn=(0,g.object)({url:oe}),En=(0,g.object)({serverUrl:oe,sqlitePath:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),streamName:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),url:oe}),Ro=(0,g.object)({queryInsights:(0,g.optional)(En),streams:(0,g.optional)(En)}),Et=(0,g.pipe)((0,g.number)(),(0,g.integer)(),(0,g.minValue)(1)),xo=(0,g.object)({database:Pn,http:wn,ppg:wn,shadowDatabase:Pn}),To=(0,g.object)({databasePort:Et,experimental:(0,g.optional)(Ro),exports:(0,g.optional)(xo),name:(0,g.pipe)((0,g.string)(),(0,g.minLength)(1)),pid:(0,g.optional)((0,g.pipe)((0,g.number)(),(0,g.integer)(),(0,g.minValue)(0))),port:Et,shadowDatabasePort:Et,version:(0,g.literal)("1")}),It=Symbol("initialize"),vt="default",Io=new Set(["durable-streams"]),N=class{_databasePort;databaseConnectTimeoutMillis;databaseIdleTimeoutMillis;debug;dryRun;name;persistenceMode;pid;shadowDatabaseConnectTimeoutMillis;shadowDatabaseIdleTimeoutMillis;_port;_shadowDatabasePort;_streamsPort;constructor(t){this._databasePort=t.databasePort??I,this.databaseConnectTimeoutMillis=t.databaseConnectTimeoutMillis??6e4,this.databaseIdleTimeoutMillis=t.databaseIdleTimeoutMillis??1/0,this.debug=t.debug??!1,this.dryRun=t.dryRun??!1,this.name=t.name??vt,this.persistenceMode=t.persistenceMode,this.pid=t.pid??Tt.process.pid,this.shadowDatabaseConnectTimeoutMillis=t.shadowDatabaseConnectTimeoutMillis??this.databaseConnectTimeoutMillis,this.shadowDatabaseIdleTimeoutMillis=t.shadowDatabaseIdleTimeoutMillis??this.databaseIdleTimeoutMillis,this._port=t.port??I,this._shadowDatabasePort=t.shadowDatabasePort??I,this._streamsPort=t.streamsPort??I}static async createExclusively(t){let r=t?.dryRun!==!0&&t?.persistenceMode==="stateful"?new se(t):new Rt(t);return await r[It](),r}static async fromServerDump(t){let{debug:r,name:n=vt}=t??{},s=X(n),o=se.getServerDumpPath(s),a=await Wt(o);if(a==null)return r&&console.debug(`[State] No server dump file found at: ${o}`),null;r&&(console.debug(`[State] server dump file found at "${o}":`),console.debug(a));let{issues:i,output:c,success:u}=(0,g.safeParse)((0,g.pipe)((0,g.string)(),(0,g.parseJson)(),To),a);if(!u)throw r&&console.debug(`[State] Invalid server dump file at "${o}":
|
|
120
120
|
${JSON.stringify(i,null,2)}`),new Error(`Invalid Prisma Dev state for "${n}".`);return new se({databasePort:c.databasePort,debug:r,dryRun:!1,name:n,pid:c.pid,port:c.port,serverDump:c,shadowDatabasePort:c.shadowDatabasePort})}static async scan(t){let{debug:r,globs:n}=t??{},s=(0,F.join)(X(vt),"..");r&&console.debug(`[State] scanning for server states in: ${s}`);let o=(await Gt(s,n)).filter(a=>!Io.has(a));return r&&console.debug(`[State] found server names: ${JSON.stringify(o)}`),await Promise.all(o.map(a=>Do(a,t)))}get databasePort(){return this._databasePort}set databasePort(t){this.#r("databasePort",t)}get port(){return this._port}set port(t){this.#r("port",t)}get shadowDatabasePort(){return this._shadowDatabasePort}get streamsPort(){return this._streamsPort}set shadowDatabasePort(t){this.#r("shadowDatabasePort",t)}#r(t,r){if(r<0||!Number.isInteger(r))throw new Error(`Invalid port number: ${r}`);let n=`_${t}`;if(this[n]!==Q&&this[n]!==r)throw new Error(`\`${t}\` is already set to ${this[n]}, cannot change it to ${r}`);this[n]=r}},Rt=class extends N{constructor(t){super({...t,databasePort:t?.databasePort||Q,persistenceMode:"stateless",port:t?.port||Q,shadowDatabasePort:t?.shadowDatabasePort||Q,streamsPort:t?.streamsPort||Q})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[It](){let t;try{t=await N.scan({debug:this.debug,onlyMetadata:!0})}catch(n){this.debug&&console.warn("[State] failed to scan for existing servers, assuming filesystem does not exist or other reasons.",n),t=[]}let r=await qe({debug:this.debug,name:this.dryRun?this.name:"",requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort,streamsPort:this.streamsPort},servers:t});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,this._streamsPort=r.streamsPort}async close(){}async writeServerDump(){}},se=class e extends N{#r;#e;#t;#s;#o;#a;#n;constructor(t){super({...t,persistenceMode:"stateful"}),this.#a=!1,this.#e=X(this.name),this.#r=(0,F.join)(this.#e,"db_dump.bak"),this.#t=(0,F.join)(this.#e,".lock"),this.#s=(0,F.join)(this.#e,".pglite"),this.#n=t?.serverDump??null,this.#o=e.getServerDumpPath(this.#e)}static getServerDumpPath(t){return(0,F.join)(t,"server.json")}get databaseDumpPath(){return this.#r}get exports(){return this.#n?.exports}get experimental(){return this.#n?.experimental}get pgliteDataDirPath(){return this.#s}async[It](){await Ht(this.#e),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{await(0,z.lock)(this.#e,{lockfilePath:this.#t}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`);let t=await N.scan({debug:this.debug,onlyMetadata:!0}),r=await qe({debug:this.debug,name:this.name,requestedPorts:{databasePort:this.databasePort,port:this.port,shadowDatabasePort:this.shadowDatabasePort,streamsPort:this.streamsPort},servers:t});this._databasePort=r.databasePort,this._port=r.port,this._shadowDatabasePort=r.shadowDatabasePort,this._streamsPort=r.streamsPort,await this.writeServerDump()}catch(t){throw t instanceof Error&&"code"in t&&t.code==="ELOCKED"?new ae(this):t}}async close(){if(!this.#a)try{await(0,z.unlock)(this.#e,{lockfilePath:this.#t}),this.#a=!0,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(t){throw this.debug&&console.error(`[State] failed to release lock on: ${this.#e}`,t),t}}async writeServerDump(t,r){this.#n={name:this.name,version:"1",pid:Tt.process.pid,port:this.port,databasePort:this.databasePort,experimental:r,shadowDatabasePort:this.shadowDatabasePort,exports:t},await(0,vn.writeFile)(this.#o,`${JSON.stringify(this.#n,null,2)}
|
|
121
|
-
`,{encoding:"utf-8"})}};async function Do(e,t){let{debug:r,onlyMetadata:n}=t||{},s=typeof e=="string"?e:e.name,o=typeof e!="string"?e:void 0,a={databasePort:o?.databasePort??-1,experimental:o?.experimental,exports:o?.exports,name:s,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await N.fromServerDump({debug:r,name:s});if(!i)return r&&console.debug(`[State] no server state found for name: ${s}`),{...a,status:"no_such_server"};a.databasePort=i.databasePort,a.experimental=i.experimental,a.exports=i.exports,a.pid=i.pid,a.port=i.port,a.shadowDatabasePort=i.shadowDatabasePort;let{exports:c,pid:u}=i;if(n)return{...a,status:"unknown"};if(!Sn(u,r))return r&&console.debug(`[State] server state for "${s}" has no running process with PID: ${u}`),{...a,status:"not_running"};let l=X(s);try{if(!await(0,z.check)(l,{lockfilePath:(0,F.join)(l,".lock")}))return r&&console.debug(`[State] server state for "${s}" is not locked, indicating it is not running.`),{...a,status:"not_running"}}catch(E){r&&console.error(`[State] server state for "${s}" failed to check lock:`,E)}if(!c)return{...a,status:"starting_up"};let{http:h}=c,{hc:d}=await import("hono/client"),m=await d(h.url).health.$get();if(!m.ok)return r&&console.debug(`[State] server state for "${s}" is not live: ${JSON.stringify(m)}`),{...a,status:"not_running"};let f=await m.json();return f.name!==e?(r&&console.debug(`[State] server state for "${s}" has mismatched health response: ${JSON.stringify(f)}`),{...a,status:"unknown"}):(r&&console.debug(`[State] server state for "${e}" is live: ${JSON.stringify(f)}`),{...a,status:"running"})}catch(i){return r&&console.error(`[State] failed to get server status for "${s}":`,i),{...a,status:"error"}}}var xt=class extends Error{name="ServerStateAlreadyExistsError";constructor(t){super(`A Prisma Dev server with the name "${t}" is already running.`)}},ae=class extends xt{#r;name="ServerAlreadyRunningError";constructor(t){super(t.name),this.#r=t}get server(){return N.fromServerDump({debug:this.#r.debug,name:this.#r.name})}};p();var xn=require("crypto"),Dt=require("timers/promises"),_t=require("util"),Tn=require("std-env");j();var _o="application/json",ie={connection:"close","content-type":_o},Ao={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},At={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function In(e){let{dbServer:t,debug:r,name:n,persistenceMode:s,port:o,queryInsightsBridge:a,walBridge:i}=e,c=s==="stateless",u=c?Fo(n):n,l=De(u),h=!c&&await H(l);Tn.process.env.DS_LOCAL_DATA_ROOT=bt(),c&&await G(l);let d=await No({debug:r,hadExistingStreamsData:h,name:u,port:o}),m={serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path,streamName:ht,url:_e(d.exports.http.url)};try{await Lo(m);let f=await yn({bridge:a,debug:r,serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path}),E=new Ot({dbServer:t,debug:r,streamUrl:m.url}),J=i.subscribe(Ne=>{E.enqueue(Ne)});return{close:async()=>{J(),await E.close(),await f.close(),await d.close(),await(0,Dt.setTimeout)(100),c&&await G(l)},experimental:m,experimentalQueryInsights:f.experimental}}catch(f){throw await d.close().catch(()=>{}),await(0,Dt.setTimeout)(100),c&&await G(l).catch(()=>{}),f}}var Oo=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function No(e){let{debug:t,hadExistingStreamsData:r,name:n,port:s}=e,{startLocalDurableStreamsServer:o}=await import("@prisma/streams-local"),a=()=>o({hostname:"127.0.0.1",name:n,port:s});try{return await a()}catch(i){if(!r||!Bo(i))throw i;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),t&&console.debug(`[streams] original durable streams startup error for "${n}"`,i),await G(De(n)),await a()}}function Bo(e){return Mo(e).map(r=>r.toLowerCase()).some(r=>Oo.some(n=>r.includes(n)))}function Mo(e){let t=[],r=[e],n=new Set;for(;r.length>0;){let s=r.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){t.push(s);continue}if(s instanceof AggregateError)for(let o of s.errors)r.push(o);if(s instanceof Error){t.push(s.message);let o=s.cause;o!==void 0&&r.push(o)}}}return t}var Ot=class{#r;#e;#t;#s;#o;constructor(t){this.#r=t.dbServer,this.#e=t.debug,this.#t=Promise.resolve(),this.#s=t.streamUrl,this.#o=new Set}enqueue(t){t.length!==0&&(this.#t=this.#t.then(async()=>{let r=await this.#a(t);r.length!==0&&(await Co(this.#s,r),this.#e&&console.debug(`[streams] appended ${r.length} state-protocol record(s) to ${this.#s}`))}).catch(r=>{console.error("[streams] failed to ingest WAL events into prisma-wal",r)}))}async close(){await this.#t}async#a(t){let r=[],n=new Date().toISOString();for(let s of t)r.push(...await this.#n(s,n));return r}async#n(t,r){let n=`${t.schema}.${t.table}`,s=await this.#r.getPrimaryKeyColumns(t.schema,t.table),o=Rn(t.record),a=Rn(t.oldRecord),i=this.#i(n,s,a),c=this.#i(n,s,o),u=t.txid===""?void 0:t.txid;return t.type==="insert"?o&&c?[{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[]:t.type==="delete"?a&&i?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null}]:[]:!o||!a||!i||!c?[]:i!==c?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null},{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[{headers:{operation:"update",timestamp:r,txid:u},key:c,old_value:a,type:n,value:o}]}#i(t,r,n){if(!n)return null;let s=Uo(n,r);return s||(this.#o.has(t)||(this.#o.add(t),console.warn(`[streams] falling back to full-row keys for ${t} because no primary key could be resolved`)),Qo(n))}};async function Lo(e){let t=await fetch(e.url,{headers:ie,method:"PUT"});if(!t.ok)throw await ce(t,`Failed to create ${e.streamName}`);let r=await fetch(`${e.url}/_profile`,{body:JSON.stringify(Ao),headers:ie,method:"POST"});if(!r.ok)throw await ce(r,`Failed to configure ${e.streamName}`);let n=await $o(e);if(ko(n,e.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${e.url}/_schema`,{body:JSON.stringify(At),headers:ie,method:"POST"});if(!s.ok)throw await ce(s,`Failed to install schema for ${e.streamName}`)}async function $o(e){let t=await fetch(`${e.url}/_schema`,{headers:ie,method:"GET"});if(!t.ok)throw await ce(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}function ko(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,_t.isDeepStrictEqual)(r,At.schema)&&(0,_t.isDeepStrictEqual)(e.search,At.search)}async function Co(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:ie,method:"POST"});if(!r.ok)throw await ce(r,"Failed to append to prisma-wal")}async function ce(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}function Uo(e,t){if(t.length===0)return null;let r=[];for(let n of t){if(!Object.prototype.hasOwnProperty.call(e,n))return null;let s=qo(e[n]);if(s==null)return null;r.push(t.length===1?s:`${n}=${s}`)}return r.join("|")}function Qo(e){return JSON.stringify(Nt(e))}function Nt(e){return Array.isArray(e)?e.map(t=>Nt(t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Nt(r)])):e}function Rn(e){return e?structuredClone(e):null}function qo(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e=="bigint")return e.toString();if(typeof e=="boolean")return e?"true":"false";try{return JSON.stringify(e)}catch{return null}}function Fo(e){return`${e}.${(0,xn.randomUUID)().replaceAll("-","")}`}async function Dn(e){let t=await N.createExclusively(e),r=null,n=null,s=null,o=null;try{[r,s]=await Promise.all([tt("database",t),tt("shadow_database",t)]);let a,i;t.dryRun?(a=jo(),i=Ko(),o=Vo()):(a=await r.attachWalEventBridge(),i=await r.attachQueryInsightsBridge(),o=await In({dbServer:r,debug:t.debug,name:t.name,port:t.streamsPort,persistenceMode:t.persistenceMode,queryInsightsBridge:i,walBridge:a})),n=await fn(r,t);let c=Wo(r,s,n,t);await t.writeServerDump(c,t.dryRun?{}:{queryInsights:o.experimentalQueryInsights,streams:o.experimental});let u=Go(a),l=hn(o.experimentalQueryInsights),h=r,d=s,m=n,f=o,E=async()=>{u.close(),await _n(t,[m,f,h,d])};return{close:E,dbServer:r,httpServer:n,server:{...c,close:E,experimental:{queryInsights:l,streams:o.experimental,wal:u.api},name:t.name},serverState:t,shadowDbServer:s,streamsServer:o,queryInsightsBridge:i,walBridge:a}}catch(a){return await Ho(t,[n,o,r,s],a)}}function Wo(e,t,r,n){let s=`prisma+postgres://localhost:${r.port}/?${new URLSearchParams({api_key:Lt({databaseUrl:e.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:e.connectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand},http:{url:r.url},ppg:{url:s},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}}}async function _n(e,t){let n=(await Promise.allSettled(t.map(s=>s.close()))).filter(s=>s.status==="rejected").map(s=>new Error(s.reason));try{await e.close()}catch(s){n.push(s)}if(n.length>0)throw new AggregateError(n,"Failed to close some servers")}async function Ho(e,t,r){try{await _n(e,t.filter(n=>n!==null))}catch(n){throw new AggregateError([r,n],"Failed to start Prisma Dev server cleanly")}throw r}function Go(e){let t=new Set;return{api:{stream:()=>{let r=()=>{},n=zo(e,()=>{t.delete(r)});return r=()=>n.close(),t.add(r),n.stream},subscribe:r=>e.subscribe(r)},close:()=>{for(let r of[...t])r();t.clear()}}}function jo(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Ko(){return{async close(){},subscribe(){return()=>{}}}}function Vo(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function zo(e,t){let r=[],n=!1,s=null,o=e.subscribe(i=>{if(!n){if(s){let c=s;s=null,c.resolve({done:!1,value:i});return}r.push(i)}}),a=()=>{if(!n&&(n=!0,o(),r.length=0,t(),s)){let i=s;s=null,i.resolve({done:!0,value:void 0})}};return{close:a,stream:{[Symbol.asyncIterator](){return this},next(){return r.length>0?Promise.resolve({done:!1,value:r.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((i,c)=>{s={reject:c,resolve:i}})},return(){return a(),Promise.resolve({done:!0,value:void 0})},throw(i){let c=s;return a(),c&&c.reject(i),Promise.reject(i instanceof Error?i:new Error(String(i)))}}}}async function An(e){let{server:t}=await Dn(e);return t}async function Jo(e){return await An(e)}0&&(module.exports={DEFAULT_DATABASE_PORT,DEFAULT_SERVER_PORT,DEFAULT_SHADOW_DATABASE_PORT,DEFAULT_STREAMS_PORT,PortNotAvailableError,ServerAlreadyRunningError,copyPrismaDevRuntimeAssets,getPrismaDevRuntimeAssetManifest,startPrismaDevServer,unstable_startServer});
|
|
121
|
+
`,{encoding:"utf-8"})}};async function Do(e,t){let{debug:r,onlyMetadata:n}=t||{},s=typeof e=="string"?e:e.name,o=typeof e!="string"?e:void 0,a={databasePort:o?.databasePort??-1,experimental:o?.experimental,exports:o?.exports,name:s,pid:o?.pid,port:o?.port??-1,shadowDatabasePort:o?.shadowDatabasePort??-1,version:"1"};try{let i=o||await N.fromServerDump({debug:r,name:s});if(!i)return r&&console.debug(`[State] no server state found for name: ${s}`),{...a,status:"no_such_server"};a.databasePort=i.databasePort,a.experimental=i.experimental,a.exports=i.exports,a.pid=i.pid,a.port=i.port,a.shadowDatabasePort=i.shadowDatabasePort;let{exports:c,pid:u}=i;if(n)return{...a,status:"unknown"};if(!Sn(u,r))return r&&console.debug(`[State] server state for "${s}" has no running process with PID: ${u}`),{...a,status:"not_running"};let l=X(s);try{if(!await(0,z.check)(l,{lockfilePath:(0,F.join)(l,".lock")}))return r&&console.debug(`[State] server state for "${s}" is not locked, indicating it is not running.`),{...a,status:"not_running"}}catch(E){r&&console.error(`[State] server state for "${s}" failed to check lock:`,E)}if(!c)return{...a,status:"starting_up"};let{http:h}=c,{hc:d}=await import("hono/client"),m=await d(h.url).health.$get();if(!m.ok)return r&&console.debug(`[State] server state for "${s}" is not live: ${JSON.stringify(m)}`),{...a,status:"not_running"};let f=await m.json();return f.name!==e?(r&&console.debug(`[State] server state for "${s}" has mismatched health response: ${JSON.stringify(f)}`),{...a,status:"unknown"}):(r&&console.debug(`[State] server state for "${e}" is live: ${JSON.stringify(f)}`),{...a,status:"running"})}catch(i){return r&&console.error(`[State] failed to get server status for "${s}":`,i),{...a,status:"error"}}}var xt=class extends Error{name="ServerStateAlreadyExistsError";constructor(t){super(`A Prisma Dev server with the name "${t}" is already running.`)}},ae=class extends xt{#r;name="ServerAlreadyRunningError";constructor(t){super(t.name),this.#r=t}get server(){return N.fromServerDump({debug:this.#r.debug,name:this.#r.name})}};p();var xn=require("crypto"),Dt=require("timers/promises"),_t=require("util"),Tn=require("std-env");j();var _o="application/json",ie={connection:"close","content-type":_o},Ao={apiVersion:"durable.streams/profile/v1",profile:{kind:"state-protocol",touch:{enabled:!0,onMissingBefore:"coarse"}}},At={apiVersion:"durable.streams/schema-registry/v1",schema:{additionalProperties:!0,properties:{headers:{properties:{operation:{type:"string"},timestamp:{format:"date-time",type:"string"}},required:["timestamp","operation"],type:"object"},key:{type:"string"},type:{type:"string"}},required:["type","key","headers"],type:"object"},search:{aliases:{rowKey:"key",table:"type"},fields:{eventTime:{bindings:[{jsonPointer:"/headers/timestamp",version:1}],column:!0,exact:!0,exists:!0,kind:"date",sortable:!0},key:{bindings:[{jsonPointer:"/key",version:1}],exact:!0,exists:!0,kind:"keyword"},operation:{bindings:[{jsonPointer:"/headers/operation",version:1}],exact:!0,exists:!0,kind:"keyword"},type:{bindings:[{jsonPointer:"/type",version:1}],exact:!0,exists:!0,kind:"keyword"}},primaryTimestampField:"eventTime"}};async function In(e){let{dbServer:t,debug:r,name:n,persistenceMode:s,port:o,queryInsightsBridge:a,walBridge:i}=e,c=s==="stateless",u=c?Fo(n):n,l=De(u),h=!c&&await H(l);Tn.process.env.DS_LOCAL_DATA_ROOT=bt(),c&&await G(l);let d=await No({debug:r,hadExistingStreamsData:h,name:u,port:o}),m={serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path,streamName:ht,url:_e(d.exports.http.url)};try{await Lo(m);let f=await yn({bridge:a,debug:r,serverUrl:d.exports.http.url,sqlitePath:d.exports.sqlite.path}),E=new Ot({dbServer:t,debug:r,streamUrl:m.url}),J=i.subscribe(Ne=>{E.enqueue(Ne)});return{close:async()=>{J(),await E.close(),await f.close(),await d.close(),await(0,Dt.setTimeout)(100),c&&await G(l)},experimental:m,experimentalQueryInsights:f.experimental}}catch(f){throw await d.close().catch(()=>{}),await(0,Dt.setTimeout)(100),c&&await G(l).catch(()=>{}),f}}var Oo=["database disk image is malformed","duplicate column name:","file is not a database","malformed database schema","no such column:","no such table:","schema_version row missing after migration","unexpected schema version:"];async function No(e){let{debug:t,hadExistingStreamsData:r,name:n,port:s}=e,{startLocalDurableStreamsServer:o}=await import("@prisma/streams-local"),a=()=>o({hostname:"127.0.0.1",name:n,port:s});try{return await a()}catch(i){if(!r||!Bo(i))throw i;return console.warn(`[streams] resetting incompatible durable streams data for "${n}"`),t&&console.debug(`[streams] original durable streams startup error for "${n}"`,i),await G(De(n)),await a()}}function Bo(e){return Mo(e).map(r=>r.toLowerCase()).some(r=>Oo.some(n=>r.includes(n)))}function Mo(e){let t=[],r=[e],n=new Set;for(;r.length>0;){let s=r.shift();if(!(s==null||n.has(s))){if(n.add(s),typeof s=="string"){t.push(s);continue}if(s instanceof AggregateError)for(let o of s.errors)r.push(o);if(s instanceof Error){t.push(s.message);let o=s.cause;o!==void 0&&r.push(o)}}}return t}var Ot=class{#r;#e;#t;#s;#o;constructor(t){this.#r=t.dbServer,this.#e=t.debug,this.#t=Promise.resolve(),this.#s=t.streamUrl,this.#o=new Set}enqueue(t){t.length!==0&&(this.#t=this.#t.then(async()=>{let r=await this.#a(t);r.length!==0&&(await Co(this.#s,r),this.#e&&console.debug(`[streams] appended ${r.length} state-protocol record(s) to ${this.#s}`))}).catch(r=>{console.error("[streams] failed to ingest WAL events into prisma-wal",r)}))}async close(){await this.#t}async#a(t){let r=[],n=new Date().toISOString();for(let s of t)r.push(...await this.#n(s,n));return r}async#n(t,r){let n=`${t.schema}.${t.table}`,s=await this.#r.getPrimaryKeyColumns(t.schema,t.table),o=Rn(t.record),a=Rn(t.oldRecord),i=this.#i(n,s,a),c=this.#i(n,s,o),u=t.txid===""?void 0:t.txid;return t.type==="insert"?o&&c?[{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[]:t.type==="delete"?a&&i?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null}]:[]:!o||!a||!i||!c?[]:i!==c?[{headers:{operation:"delete",timestamp:r,txid:u},key:i,old_value:a,type:n,value:null},{headers:{operation:"insert",timestamp:r,txid:u},key:c,old_value:null,type:n,value:o}]:[{headers:{operation:"update",timestamp:r,txid:u},key:c,old_value:a,type:n,value:o}]}#i(t,r,n){if(!n)return null;let s=Uo(n,r);return s||(this.#o.has(t)||(this.#o.add(t),console.warn(`[streams] falling back to full-row keys for ${t} because no primary key could be resolved`)),Qo(n))}};async function Lo(e){let t=await fetch(e.url,{headers:ie,method:"PUT"});if(!t.ok)throw await ce(t,`Failed to create ${e.streamName}`);let r=await fetch(`${e.url}/_profile`,{body:JSON.stringify(Ao),headers:ie,method:"POST"});if(!r.ok)throw await ce(r,`Failed to configure ${e.streamName}`);let n=await $o(e);if(ko(n,e.streamName))return;if(n.currentVersion>0)throw new Error(`Failed to install schema for ${e.streamName}: existing schema registry is incompatible and requires a lens migration`);let s=await fetch(`${e.url}/_schema`,{body:JSON.stringify(At),headers:ie,method:"POST"});if(!s.ok)throw await ce(s,`Failed to install schema for ${e.streamName}`)}async function $o(e){let t=await fetch(`${e.url}/_schema`,{headers:ie,method:"GET"});if(!t.ok)throw await ce(t,`Failed to inspect schema for ${e.streamName}`);return await t.json()}function ko(e,t){if(e.currentVersion<=0||e.schema!==t)return!1;let r=e.schemas[String(e.currentVersion)];return(0,_t.isDeepStrictEqual)(r,At.schema)&&(0,_t.isDeepStrictEqual)(e.search,At.search)}async function Co(e,t){let r=await fetch(e,{body:JSON.stringify(t),headers:ie,method:"POST"});if(!r.ok)throw await ce(r,"Failed to append to prisma-wal")}async function ce(e,t){let r=await e.text().catch(()=>"");return new Error(`${t}: HTTP ${e.status}${r?` ${r}`:""}`)}function Uo(e,t){if(t.length===0)return null;let r=[];for(let n of t){if(!Object.prototype.hasOwnProperty.call(e,n))return null;let s=qo(e[n]);if(s==null)return null;r.push(t.length===1?s:`${n}=${s}`)}return r.join("|")}function Qo(e){return JSON.stringify(Nt(e))}function Nt(e){return Array.isArray(e)?e.map(t=>Nt(t)):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)).map(([t,r])=>[t,Nt(r)])):e}function Rn(e){return e?structuredClone(e):null}function qo(e){if(e===null)return"null";if(e===void 0)return"undefined";if(typeof e=="string")return e;if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e=="bigint")return e.toString();if(typeof e=="boolean")return e?"true":"false";try{return JSON.stringify(e)}catch{return null}}function Fo(e){return`${e}.${(0,xn.randomUUID)().replaceAll("-","")}`}async function Dn(e){let t=await N.createExclusively(e),r=null,n=null,s=null,o=null;try{[r,s]=await Promise.all([tt("database",t),tt("shadow_database",t)]);let a,i;t.dryRun?(a=jo(),i=Ko(),o=Vo()):(a=await r.attachWalEventBridge(),i=await r.attachQueryInsightsBridge(),o=await In({dbServer:r,debug:t.debug,name:t.name,port:t.streamsPort,persistenceMode:t.persistenceMode,queryInsightsBridge:i,walBridge:a})),n=await fn(r,t);let c=Wo(r,s,n,t);await t.writeServerDump(c,t.dryRun?{}:{queryInsights:o.experimentalQueryInsights,streams:o.experimental});let u=Go(a),l=hn(o.experimentalQueryInsights),h=r,d=s,m=n,f=o,E=async()=>{u.close(),await _n(t,[m,f,h,d])};return{close:E,dbServer:r,httpServer:n,server:{...c,close:E,experimental:{queryInsights:l,streams:o.experimental,wal:u.api},name:t.name},serverState:t,shadowDbServer:s,streamsServer:o,queryInsightsBridge:i,walBridge:a}}catch(a){return await Ho(t,[n,o,r,s],a)}}function Wo(e,t,r,n){let s=`prisma+postgres://localhost:${r.port}/?${new URLSearchParams({api_key:Lt({databaseUrl:e.prismaORMConnectionString,name:n.name,shadowDatabaseUrl:t.prismaORMConnectionString})}).toString()}`;return{database:{connectionString:e.connectionString,prismaORMConnectionString:e.prismaORMConnectionString,terminalCommand:e.terminalCommand},http:{url:r.url},ppg:{url:s},shadowDatabase:{connectionString:t.prismaORMConnectionString,prismaORMConnectionString:t.prismaORMConnectionString,terminalCommand:t.terminalCommand}}}async function _n(e,t){let r=[];for(let n of t)try{await n.close()}catch(s){r.push(s)}try{await e.close()}catch(n){r.push(n)}if(r.length>0)throw new AggregateError(r,"Failed to close some servers")}async function Ho(e,t,r){try{await _n(e,t.filter(n=>n!==null))}catch(n){throw new AggregateError([r,n],"Failed to start Prisma Dev server cleanly")}throw r}function Go(e){let t=new Set;return{api:{stream:()=>{let r=()=>{},n=zo(e,()=>{t.delete(r)});return r=()=>n.close(),t.add(r),n.stream},subscribe:r=>e.subscribe(r)},close:()=>{for(let r of[...t])r();t.clear()}}}function jo(){return{async close(){},async poll(){},subscribe(){return()=>{}}}}function Ko(){return{async close(){},subscribe(){return()=>{}}}}function Vo(){return{async close(){},experimental:{serverUrl:"",sqlitePath:"",streamName:"",url:""},experimentalQueryInsights:{serverUrl:"",sqlitePath:"",streamName:"",url:""}}}function zo(e,t){let r=[],n=!1,s=null,o=e.subscribe(i=>{if(!n){if(s){let c=s;s=null,c.resolve({done:!1,value:i});return}r.push(i)}}),a=()=>{if(!n&&(n=!0,o(),r.length=0,t(),s)){let i=s;s=null,i.resolve({done:!0,value:void 0})}};return{close:a,stream:{[Symbol.asyncIterator](){return this},next(){return r.length>0?Promise.resolve({done:!1,value:r.shift()}):n?Promise.resolve({done:!0,value:void 0}):new Promise((i,c)=>{s={reject:c,resolve:i}})},return(){return a(),Promise.resolve({done:!0,value:void 0})},throw(i){let c=s;return a(),c&&c.reject(i),Promise.reject(i instanceof Error?i:new Error(String(i)))}}}}async function An(e){let{server:t}=await Dn(e);return t}async function Jo(e){return await An(e)}0&&(module.exports={DEFAULT_DATABASE_PORT,DEFAULT_SERVER_PORT,DEFAULT_SHADOW_DATABASE_PORT,DEFAULT_STREAMS_PORT,PortNotAvailableError,ServerAlreadyRunningError,copyPrismaDevRuntimeAssets,getPrismaDevRuntimeAssetManifest,startPrismaDevServer,unstable_startServer});
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,b as j}from"./chunk-
|
|
1
|
+
import{a as i,b as j}from"./chunk-GMUOAEZU.js";import"./chunk-PP43TGA5.js";import{a as f,b as g}from"./chunk-KWCQYPJI.js";import{l as h}from"./chunk-2XJK3IOI.js";import{a,b,c,d,h as e}from"./chunk-EDFHV3AK.js";import"./chunk-HQMJSXYT.js";import"./chunk-DWY47FQV.js";import"./chunk-3UF2MBYQ.js";export{a as DEFAULT_DATABASE_PORT,b as DEFAULT_SERVER_PORT,c as DEFAULT_SHADOW_DATABASE_PORT,d as DEFAULT_STREAMS_PORT,e as PortNotAvailableError,h as ServerAlreadyRunningError,f as copyPrismaDevRuntimeAssets,g as getPrismaDevRuntimeAssetManifest,i as startPrismaDevServer,j as unstable_startServer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/dev",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.12",
|
|
4
4
|
"description": "A local Prisma Postgres server for development and testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Igal Klebanov <igalklebanov@gmail.com> (https://github.com/igalklebanov)",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@hono/node-server": "^1.19.14",
|
|
85
85
|
"@prisma/get-platform": "7.2.0",
|
|
86
86
|
"@prisma/query-plan-executor": "7.2.0",
|
|
87
|
-
"@prisma/streams-local": "0.1.
|
|
87
|
+
"@prisma/streams-local": "0.1.10",
|
|
88
88
|
"foreground-child": "3.3.1",
|
|
89
89
|
"get-port-please": "3.2.0",
|
|
90
90
|
"hono": "^4.12.23",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"init": "node ./scripts/generate-bun-runtime-assets.mjs",
|
|
104
104
|
"lint": "eslint --fix .",
|
|
105
105
|
"test": "node ./scripts/generate-bun-runtime-assets.mjs && vitest run",
|
|
106
|
+
"test:e2e": "node ./scripts/generate-bun-runtime-assets.mjs && vitest run e2e.test",
|
|
106
107
|
"typecheck": "node ./scripts/generate-bun-runtime-assets.mjs && tsc --noEmit"
|
|
107
108
|
}
|
|
108
109
|
}
|