@prisma/dev 0.0.0-dev.202505090022 → 0.0.0-dev.202505090123
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{Buffer as
|
|
3
|
-
`).find(
|
|
4
|
-
Received data: ${i}`));o({childProcess:r,url:`http://${
|
|
2
|
+
import{Buffer as I}from"buffer";import{createSecureServer as ae}from"http2";import{promisify as ce}from"util";import{serve as le}from"@hono/node-server";import me from"@prisma/get-platform";import{Hono as L}from"hono/tiny";import{mkdir as X,readFile as $,writeFile as C}from"fs/promises";import{join as E}from"path";import{certificateFor as W}from"@expo/devcert";import{chmod as J,stat as G,writeFile as Q}from"fs/promises";import z from"env-paths";import{inflate as K}from"pako";var v=z("prisma-dev").cache;function T(e,t){return`${v}/${e}/${t}`}async function g(e){try{return await G(e),!0}catch(t){if(t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT")return!1;throw t}}async function H(e,t){let r=K(e);await Q(t,r),await J(t,"755")}var P=E(v,"certs"),S=E(P,"tls.cert"),b=E(P,"tls.key");async function B(){if(await X(P,{recursive:!0}),await g(S)&&await g(b))return{cert:await $(S),key:await $(b)};let e=await W("localhost");return await Promise.all([C(S,e.cert),C(b,e.key)]),{cert:e.cert,key:e.key}}import{spawn as Y}from"child_process";import{once as Z}from"events";import{mkdir as ee}from"fs/promises";import{join as te}from"path";function u(){let e,t,r=new Promise((s,n)=>{e=s,t=n});return{fail:t,promise:r,succeed:e}}var h=class e{static#r=new Map;#t;#e;constructor(t){this.#t=t,this.#e=null}static async get(t){let r=`${t.schemaHash}:${t.clientVersion}`;try{let s=e.#r.get(r);if(s)return s;let n=new e(t);return e.#r.set(r,n),await n.start(),n}finally{e.stopAll(r)}}static async stopAll(t){let s=(await Promise.allSettled(Array.from(e.#r.entries()).filter(([n])=>n!==t).map(async([n,o])=>{try{await o.stop()}finally{e.#r.delete(n)}}))).filter(n=>n.status==="rejected").map(n=>n.reason);if(s.length>0)throw new AggregateError(s,"Failed to stop engines")}async request(t,r){let{url:s}=await this.#e,n=await fetch(s,{body:t,headers:{...r,"Content-Type":"application/json"},method:"POST"});if(!n.ok)throw await d.fromResponse(n);return await n.text()}async startTransaction(t,r){let{url:s}=await this.#e,n=await fetch(`${s}/transaction/start`,{body:JSON.stringify(t),headers:{...r,"Content-Type":"application/json"},method:"POST"});if(!n.ok)throw await d.fromResponse(n);return await n.json()}async start(){if(this.#e!=null)return;let t=await this.#n(),r=Y(t,["--enable-raw-queries","--enable-telemetry-in-response","--port","0"],{env:{LOG_QUERIES:"y",PRISMA_DML:this.#t.base64Schema,QE_LOG_LEVEL:"TRACE",RUST_BACKTRACE:"1",RUST_LOG:"info"},stdio:["ignore","pipe","pipe"],windowsHide:!0});r.stderr.setEncoding("utf8"),r.stdout.setEncoding("utf8");let{fail:s,promise:n,succeed:o}=u();this.#e=n;let l=i=>{let m=i.split(`
|
|
3
|
+
`).find(w=>w.includes("Started query engine http server"));if(!m)return;r.stdout.removeListener("data",l);let{fields:c}=JSON.parse(m);if(c==null)return s(new Error(`Unexpected data during initialization, "fields" are missing: ${i}`));let{ip:a,port:p}=c;if(a==null||p==null)return s(new Error(`This version of query-engine is not compatible with minippg, "ip" and "port" are missing in the startup log entry.
|
|
4
|
+
Received data: ${i}`));o({childProcess:r,url:`http://${a}:${p}`})};r.once("error",i=>{this.#e=null,s(new f(String(i)))}),r.once("exit",(i,m)=>{this.#e=null,s(new f(`Query Engine exited with code ${i} and signal ${m}`))}),r.stdout.on("data",l),r.stderr.on("data",i=>{console.error(i)}),await this.#e}async stop(){if(this.#e==null)return;let{childProcess:t}=await this.#e;t.exitCode==null&&t.signalCode==null&&(t.kill(),await Z(t,"exit"))}async#n(){let t=await this.#s(),r=T(this.#t.clientVersion,t);await ee(r,{recursive:!0});let{platform:s}=this.#t.platform,n=s==="windows"?".exe":"",o=te(r,`query-engine-${s}${n}`);return await g(o)||await this.#o({commitHash:t,extension:n,engineBinaryPath:o}),o}async#s(){let t=await fetch(`https://registry.npmjs.org/@prisma/client/${this.#t.clientVersion}`);if(!t.ok)throw new Error(`Couldn't fetch package.json from npm registry, status code: ${t.status}`);let s=(await t.json()).dependencies?.["@prisma/engines-version"];if(!s)throw new Error("Couldn't find engines version in package.json");let n=s.split(".").at(-1);if(!n)throw new Error("Couldn't find commit hash in engines version");return n}async#o(t){let{commitHash:r,extension:s,engineBinaryPath:n}=t,{platform:o}=this.#t.platform,l=`https://binaries.prisma.sh/all_commits/${r}/${o}/query-engine${s}.gz`,i=await fetch(l);if(!i.ok)throw new Error(`Couldn't download engine. URL: ${l}, status code: ${i.status}`);await H(await i.arrayBuffer(),n)}},f=class extends Error{name="EngineStartError"},d=class e extends Error{constructor(r,s,n){super(`${r}: Query Engine response status ${s}, body: ${n}`);this.action=r;this.statusCode=s;this.responseBody=n}name="EngineHttpError";static async fromResponse(r){let s=new URL(r.url),n=await r.text();return new e(s.pathname,r.status,n)}};import{integer as O,looseObject as re,minValue as k,number as R,object as ne,pipe as x,safeParse as A,string as D,union as se}from"valibot";var oe=ne({isolation_level:D(),max_wait:x(R(),O(),k(0)),timeout:x(R(),O(),k(0))});async function j(e){let{output:t,success:r}=A(oe,await e.req.parseBody());return r?t:e.json({EngineNotStarted:{reason:"InvalidRequest"}},400)}var ie=re({id:se([D(),R()])});function q(e,t){let{output:r,success:s}=A(ie,e);return s?r:t.json({EngineMalfunction:{}},500)}async function _(e,t,r){let s=new L,n=await me.getPlatformInfo();r&&console.log("platform info: %s",JSON.stringify(n)),s.use(async(a,p)=>{a.set("db",t),a.set("debug",!!r),a.set("platform",n),a.set("port",e),a.set("protocol","http"),a.set("schemasByHash",new Map),await p()}),s.route("/",y);let o=await B(),{fail:l,promise:i,succeed:m}=u(),c=le({createServer:ae,fetch:s.fetch,port:e,serverOptions:{...o,allowHTTP1:!0}},()=>{m()});return c.on("error",a=>{if(typeof a=="object"&&"code"in a&&a.code==="EADDRINUSE")return l({portNotAvailable:e});console.error(a)}),await i,{async close(){await ce(c.close.bind(c))()},port:e,url:`http://localhost:${e}`}}var y=new L().basePath("/:clientVersion/:schemaHash");y.post("/graphql",async e=>{let{req:t}=e,r=V(e);if(r instanceof Response)return r;let s=t.param("clientVersion"),n=e.get("platform");try{let o=await h.get({base64Schema:r.schemas.override,clientVersion:s,platform:n,schemaHash:r.schemaHash}),l=await t.text(),i=t.header("traceparent"),m=t.header("X-capture-telemetry"),c=await o.request(l,{traceparent:i,xCaptureTelemetry:m});return e.text(c)}catch(o){return F(o,e)}});y.put("/schema",async e=>{let{req:t}=e,r=await t.text(),s=t.param("schemaHash"),n=e.get("schemasByHash");return r===n.get(s)?.original||n.set(s,{original:r,override:ue(r,e.get("db").connectionString)}),e.text(s)});y.post("/transaction/start",async e=>{let{req:t}=e,r=V(e);if(r instanceof Response)return r;let s=await j(e);if(s instanceof Response)return s;let{schemaHash:n}=r,o=t.param("clientVersion"),l=e.get("platform");try{let i=await h.get({base64Schema:r.schemas.override,clientVersion:o,platform:l,schemaHash:n}),m=t.header("traceparent"),c=t.header("X-capture-telemetry"),a=await i.startTransaction(s,{traceparent:m,"x-capture-telemetry":c}),p=q(a,e);if(p instanceof Response)return p;let{id:w}=p,M=e.get("port"),U=e.get("protocol");return e.json({...a,"data-proxy":{endpoint:`${U}://localhost:${M}/${o}/${n}/itx/${w}`}})}catch(i){return F(i,e)}});var pe=/datasource\s+db\s+[\w\s\d{="[\])(]+}/;function V(e){let t=e.req.param("schemaHash"),s=e.get("schemasByHash").get(t);return s==null?e.json({EngineNotStarted:{reason:"SchemaMissing"}},404):{schemaHash:t,schemas:s}}function ue(e,t){let r=I.from(e,"base64").toString("utf8"),s=`datasource db {
|
|
5
5
|
provider = "postgresql"
|
|
6
|
-
url = "${
|
|
7
|
-
}`,n=r.replace(
|
|
6
|
+
url = "${t}"
|
|
7
|
+
}`,n=r.replace(pe,s);return I.from(n,"utf8").toString("base64")}function F(e,t){return e instanceof f?t.json({EngineNotStarted:{reason:{EngineStartupError:{logs:[],msg:e.message}}}},500):e instanceof d?t.text(e.responseBody,e.statusCode):t.body(null,500)}import{promisify as fe}from"util";import{PGlite as de}from"@electric-sql/pglite";import{createServer as ge,LogLevel as he}from"pglite-server";async function N(e,t){let r="default",s="postgres",n=new de({database:r,dataDir:"memory://",debug:t?5:void 0,username:s});await n.waitReady;let o=ge(n,{keepAlive:!0,logLevel:t?he.Debug:void 0}),{fail:l,promise:i,succeed:m}=u();return o.on("error",c=>{if("code"in c&&c.code==="EADDRINUSE")return l(new Error(`Port ${e} is already in use. Provide a different \`dbport\` number and try again.`));console.error(c)}),o.listen(e,()=>m()),await i,{async close(){try{await fe(o.close.bind(o))()}finally{await n.close()}},connectionString:`postgres://${s}@localhost:${e}/${r}`,database:r,port:e,username:s}}async function et(e){let{acceleratePort:t=5433,databasePort:r=5432,debug:s}=e||{},n=await N(r,s),o=await _(t,n,s);return{accelerate:{url:o.url},close:()=>l([o,n]),database:{connectionString:n.connectionString},ppg:{url:`prisma+postgres://localhost:${o.port}/?dbname=${n.database}&dbport=${n.port}&dbuser=${n.username}`}};async function l(i){let c=(await Promise.allSettled(i.map(a=>a.close()))).filter(a=>a.status==="rejected").map(a=>new Error(a.reason));if(c.length>0)throw new AggregateError(c,"Failed to close some servers")}}export{et as unstable_startServer};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/dev",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
3
|
+
"version": "0.0.0-dev.202505090123",
|
|
4
4
|
"description": "A local Prisma Postgres server for development and testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@electric-sql/pglite": "0.2.17",
|
|
40
|
+
"@expo/devcert": "1.2.0",
|
|
40
41
|
"@hono/node-server": "1.14.1",
|
|
41
42
|
"@prisma/get-platform": "6.7.0",
|
|
42
43
|
"env-paths": "3.0.0",
|