@prisma/dev 0.0.0-dev.202505081610 → 0.0.0-dev.202505081713
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 +6 -1
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{
|
|
2
|
+
import{Buffer as v}from"buffer";import{createServer as T}from"http2";import{promisify as V}from"util";import{serve as L}from"@hono/node-server";import{getPlatformInfo as q}from"@prisma/get-platform";import{Hono as b}from"hono/tiny";import{spawn as B}from"child_process";import{once as H}from"events";import{chmod as A,mkdir as k,writeFile as C}from"fs/promises";import{join as D}from"path";import{inflate as O}from"pako";import{stat as $}from"fs/promises";import R from"env-paths";var x=R("prisma-dev").cache;function w(s,e){return`${x}/${s}/${e}`}async function y(s){try{return await $(s),!0}catch(e){if(e!=null&&typeof e=="object"&&"code"in e&&e.code==="ENOENT")return!1;throw e}}function p(){let s,e,r=new Promise((n,t)=>{s=n,e=t});return{fail:e,promise:r,succeed:s}}var u=class s{static#r=new Map;#t;#e;constructor(e){this.#t=e,this.#e=null}static async get(e){let r=`${e.schemaHash}:${e.clientVersion}`;try{let n=s.#r.get(r);if(n)return n;let t=new s(e);return s.#r.set(r,t),await t.start(),t}finally{s.stopAll(r)}}static async stopAll(e){let n=(await Promise.allSettled(Array.from(s.#r.entries()).filter(([t])=>t!==e).map(async([t,o])=>{try{await o.stop()}finally{s.#r.delete(t)}}))).filter(t=>t.status==="rejected").map(t=>t.reason);if(n.length>0)throw new AggregateError(n,"Failed to stop engines")}async request(e,r){let{url:n}=await this.#e,t=await fetch(n,{body:e,headers:{...r,"Content-Type":"application/json"},method:"POST"});if(!t.ok)throw await f.fromResponse(t);return await t.text()}async start(){if(this.#e!=null)return;let e=await this.#n(),r=B(e,["--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:n,promise:t,succeed:o}=p();this.#e=t;let l=i=>{let c=i.split(`
|
|
3
|
+
`).find(E=>E.includes("Started query engine http server"));if(!c)return;r.stdout.removeListener("data",l);let{fields:a}=JSON.parse(c);if(a==null)return n(new Error(`Unexpected data during initialization, "fields" are missing: ${i}`));let{ip:m,port:d}=a;if(m==null||d==null)return n(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://${m}:${d}`})};r.once("error",i=>{this.#e=null,n(new g(String(i)))}),r.once("exit",(i,c)=>{this.#e=null,n(new g(`Query Engine exited with code ${i} and signal ${c}`))}),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:e}=await this.#e;e.exitCode==null&&e.signalCode==null&&(e.kill(),await H(e,"exit"))}async#n(){let e=await this.#s(),r=w(this.#t.clientVersion,e);await k(r,{recursive:!0});let{platform:n}=this.#t.platform,t=n==="windows"?".exe":"",o=D(r,`query-engine-${n}${t}`);return await y(o)||await this.#o({commitHash:e,extension:t,engineBinaryPath:o}),o}async#s(){let e=await fetch(`https://registry.npmjs.org/@prisma/client/${this.#t.clientVersion}`);if(!e.ok)throw new Error(`Couldn't fetch package.json from npm registry, status code: ${e.status}`);let n=(await e.json()).dependencies?.["@prisma/engines-version"];if(!n)throw new Error("Couldn't find engines version in package.json");let t=n.split(".").at(-1);if(!t)throw new Error("Couldn't find commit hash in engines version");return t}async#o(e){let{commitHash:r,extension:n,engineBinaryPath:t}=e,{platform:o}=this.#t.platform,l=`https://binaries.prisma.sh/all_commits/${r}/${o}/query-engine${n}.gz`,i=await fetch(l);if(!i.ok)throw new Error(`Couldn't download engine. URL: ${l}, status code: ${i.status}`);let c=O(await i.arrayBuffer());await C(t,c),await A(t,"755")}},g=class extends Error{name="EngineStartError"},f=class s extends Error{constructor(r,n,t){super(`${r}: Query Engine response status ${n}, body: ${t}`);this.action=r;this.statusCode=n;this.responseBody=t}name="QueryEngineHttpError";static async fromResponse(r){return new s(new URL(r.url).pathname,r.status,await r.text())}};async function S(s,e,r){let n=new b,t=await q();n.use(async(a,m)=>{a.set("db",e),a.set("debug",!!r),a.set("platform",t),a.set("schemasByHash",new Map),await m()}),n.route("/",h);let{fail:o,promise:l,succeed:i}=p(),c=L({createServer:T,fetch:n.fetch,port:s},()=>{i()});return c.on("error",a=>{if(typeof a=="object"&&"code"in a&&a.code==="EADDRINUSE")return o({portNotAvailable:s});console.error(a)}),await l,{async close(){await V(c.close.bind(c))()},port:s,url:`http://localhost:${s}`}}var h=new b;h.put("/:clientVersion/:schemaHash/schema",async s=>{let{req:e}=s,r=await e.text(),n=e.param("schemaHash"),t=s.get("schemasByHash");return r===t.get(n)?.original||t.set(n,{original:r,override:I(r,s.get("db").connectionString)}),s.text(n)});h.post("/:clientVersion/:schemaHash/graphql",async s=>{let{req:e}=s,r=e.param("schemaHash"),t=s.get("schemasByHash").get(r);if(t==null)return s.json({EngineNotStarted:{reason:"SchemaMissing"}},404);let o=e.param("clientVersion"),l=s.get("platform"),i=await u.get({base64Schema:t.override,clientVersion:o,platform:l,schemaHash:r}),c=e.header("traceparent"),a=e.header("X-capture-telemetry"),m=await e.text(),d=await i.request(m,{traceparent:c,xCaptureTelemetry:a});throw console.log({results:d}),new Error("Not implemented")});var j=/datasource\s+db\s+[\w\s\d{="[\])(]+}/;function I(s,e){let r=v.from(s,"base64").toString("utf8"),n=`datasource db {
|
|
5
|
+
provider = "postgresql"
|
|
6
|
+
url = "${e}"
|
|
7
|
+
}`,t=r.replace(j,n);return v.from(t,"utf8").toString("base64")}import{promisify as N}from"util";import{PGlite as U}from"@electric-sql/pglite";import{createServer as M,LogLevel as F}from"pglite-server";async function P(s,e){let r="default",n="postgres",t=new U({database:r,dataDir:"memory://",debug:e?5:void 0,username:n});await t.waitReady;let o=M(t,{keepAlive:!0,logLevel:e?F.Debug:void 0}),{fail:l,promise:i,succeed:c}=p();return o.on("error",a=>{if("code"in a&&a.code==="EADDRINUSE")return l(new Error(`Port ${s} is already in use. Provide a different \`dbport\` number and try again.`));console.error(a)}),o.listen(s,()=>c()),await i,{async close(){try{await N(o.close.bind(o))()}finally{await t.close()}},connectionString:`postgres://${n}@localhost:${s}/${r}`,database:r,port:s,username:n}}async function ve(s){let{acceleratePort:e=5433,databasePort:r=5432,debug:n}=s||{},t=await P(r,n),o=await S(e,t,n);return{accelerate:{url:o.url},close:()=>l([o,t]),database:{connectionString:t.connectionString},ppg:{url:`prisma+postgres://localhost:${o.port}/?dbname=${t.database}&dbport=${t.port}&dbuser=${t.username}`}};async function l(i){let a=(await Promise.allSettled(i.map(m=>m.close()))).filter(m=>m.status==="rejected").map(m=>new Error(m.reason));if(a.length>0)throw new AggregateError(a,"Failed to close some servers")}}export{ve 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.202505081713",
|
|
4
4
|
"description": "A local Prisma Postgres server for development and testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@arethetypeswrong/cli": "0.17.4",
|
|
31
31
|
"@types/node": "22.3.0",
|
|
32
|
+
"@types/pako": "2.0.3",
|
|
33
|
+
"pkg-types": "2.1.0",
|
|
32
34
|
"tsup": "8.0.2",
|
|
33
35
|
"typescript": "5.8.3",
|
|
34
36
|
"vitest": "3.1.3"
|
|
@@ -36,7 +38,10 @@
|
|
|
36
38
|
"dependencies": {
|
|
37
39
|
"@electric-sql/pglite": "0.2.17",
|
|
38
40
|
"@hono/node-server": "1.14.1",
|
|
41
|
+
"@prisma/get-platform": "6.7.0",
|
|
42
|
+
"env-paths": "3.0.0",
|
|
39
43
|
"hono": "4.7.8",
|
|
44
|
+
"pako": "2.1.0",
|
|
40
45
|
"pglite-server": "0.1.4"
|
|
41
46
|
},
|
|
42
47
|
"scripts": {
|