@prisma/dev 0.0.0-dev.202505101939 → 0.0.0-dev.202505101946
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 +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{createSecureServer as Oe}from"http2";import{promisify as xe}from"util";import{serve as Be}from"@hono/node-server";import $e from"@prisma/get-platform";import{Hono as G}from"hono/tiny";import{HTTPException as Ve}from"hono/http-exception";import{object as Q,parse as W,pipe as Y,regex as Z,string as ee,url as te}from"valibot";var ne=/^(postgres|postgresql):\/\//,re=Q({databaseUrl:Y(ee(),te(),Z(ne))});function C(e){return
|
|
2
|
+
import{createSecureServer as Oe}from"http2";import{promisify as xe}from"util";import{serve as Be}from"@hono/node-server";import $e from"@prisma/get-platform";import{Hono as G}from"hono/tiny";import{HTTPException as Ve}from"hono/http-exception";import{object as Q,parse as W,pipe as Y,regex as Z,string as ee,url as te}from"valibot";var ne=/^(postgres|postgresql):\/\//,re=Q({databaseUrl:Y(ee(),te(),Z(ne))});function C(e){return Buffer.from(JSON.stringify(e),"utf8").toString("base64url")}function O(e){try{let t=Buffer.from(e,"base64url").toString("utf8");return W(re,JSON.parse(t))}catch{return null}}import{array as oe,literal as se,minLength as ie,object as ae,pipe as ce,safeParse as le,string as me,union as pe}from"valibot";var ue=ae({tags:pe([ce(oe(me()),ie(1)),se("all")])});async function x(e){let{output:t,success:n}=le(ue,await e.req.json());return n?t:e.text("Invalid input",400)}import{mkdir as we,readFile as k,writeFile as _}from"fs/promises";import{join as E}from"path";import{certificateFor as Se}from"@expo/devcert";import{chmod as de,stat as fe,writeFile as ge}from"fs/promises";import he from"env-paths";import{inflate as ye}from"pako";var b=he("prisma-dev").cache;function B(e,t){return`${b}/${e}/${t}`}async function f(e){try{return await fe(e),!0}catch(t){if(t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT")return!1;throw t}}async function $(e,t){let n=ye(e);await ge(t,n),await de(t,"755")}var H=E(b,"certs"),A=E(H,"tls.cert"),T=E(H,"tls.key");async function D(){if(await we(H,{recursive:!0}),await f(A)&&await f(T))return{cert:await k(A),key:await k(T)};let e=await Se("localhost");return await Promise.all([_(A,e.cert),_(T,e.key)]),{cert:e.cert,key:e.key}}import{spawn as Pe}from"child_process";import{once as ve}from"events";import{mkdir as be}from"fs/promises";import{join as Ae}from"path";function u(){let e,t,n=new Promise((r,o)=>{e=r,t=o});return{fail:t,promise:n,succeed:e}}var y=class e{static#n=new Map;#t;#e;constructor(t){this.#t=t,this.#e=null}static async get(t){let n=`${t.schemaHash}:${t.clientVersion}`;try{let r=e.#n.get(n);if(r)return r;let o=new e(t);return e.#n.set(n,o),await o.start(),o}finally{e.stopAll(n)}}static async stopAll(t){let r=(await Promise.allSettled(Array.from(e.#n.entries()).filter(([o])=>o!==t).map(async([o,s])=>{try{await s.stop()}finally{e.#n.delete(o)}}))).filter(o=>o.status==="rejected").map(o=>o.reason);if(r.length>0)throw new AggregateError(r,"Failed to stop engines")}async commitTransaction(t,n){return await this.#o(t,n,"commit")}async request(t,n){let{url:r}=await this.#e,o=this.#r(n),s=await fetch(r,{body:typeof t=="string"?t:JSON.stringify(t),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await d.fromResponse(s);return await s.text()}async rollbackTransaction(t,n){return await this.#o(t,n,"rollback")}async startTransaction(t,n){let{url:r}=await this.#e,o=this.#r(n),s=await fetch(`${r}/transaction/start`,{body:JSON.stringify(t),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await d.fromResponse(s);return await s.json()}async start(){if(this.#e!=null)return;let t=await this.#s(),n=Pe(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});n.stderr.setEncoding("utf8"),n.stdout.setEncoding("utf8");let{fail:r,promise:o,succeed:s}=u();this.#e=o;let a=i=>{let c=i.split(`
|
|
3
3
|
`).find(v=>v.includes("Started query engine http server"));if(!c)return;n.stdout.removeListener("data",a);let{fields:l}=JSON.parse(c);if(l==null)return r(new Error(`Unexpected data during initialization, "fields" are missing: ${i}`));let{ip:p,port:m}=l;if(p==null||m==null)return r(new Error(`This version of query-engine is not compatible with minippg, "ip" and "port" are missing in the startup log entry.
|
|
4
4
|
Received data: ${i}`));s({childProcess:n,url:`http://${p}:${m}`})};n.once("error",i=>{this.#e=null,r(new g(String(i)))}),n.once("exit",(i,c)=>{this.#e=null,r(new g(`Query Engine exited with code ${i} and signal ${c}`))}),n.stdout.on("data",a),n.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 ve(t,"exit"))}async#s(){let t=await this.#i(),n=B(this.#t.clientVersion,t);await be(n,{recursive:!0});let{platform:r}=this.#t.platform,o=r==="windows"?".exe":"",s=Ae(n,`query-engine-${r}${o}`);return await f(s)||await this.#a({commitHash:t,extension:o,engineBinaryPath:s}),s}async#i(){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 r=(await t.json()).dependencies?.["@prisma/engines-version"];if(!r)throw new Error("Couldn't find engines version in package.json");let o=r.split(".").at(-1);if(!o)throw new Error("Couldn't find commit hash in engines version");return o}async#a(t){let{commitHash:n,extension:r,engineBinaryPath:o}=t,{platform:s}=this.#t.platform,a=`https://binaries.prisma.sh/all_commits/${n}/${s}/query-engine${r}.gz`,i=await fetch(a);if(!i.ok)throw new Error(`Couldn't download engine. URL: ${a}, status code: ${i.status}`);await $(await i.arrayBuffer(),o)}#r(t){let n={};for(let[r,o]of Object.entries(t))o!=null&&(n[r]=o);return n}async#o(t,n,r){let{url:o}=await this.#e,s=this.#r(n),a=await fetch(`${o}/transaction/${t}/${r}`,{headers:{...s,"Content-Type":"application/json"},method:"POST"});if(!a.ok)throw await d.fromResponse(a);try{return await a.json()}catch{return{}}}};function w(e,t){return e instanceof g?t.json({EngineNotStarted:{reason:{EngineStartupError:{logs:[],msg:e.message}}}},500):e instanceof d?t.text(e.responseBody,e.statusCode):t.body(null,500)}var g=class extends Error{name="EngineStartError"},d=class e extends Error{constructor(n,r,o){super(`${n}: Query Engine response status ${r}, body: ${o}`);this.action=n;this.statusCode=r;this.responseBody=o}name="EngineHttpError";static async fromResponse(n){let r=new URL(n.url),o=await n.text();return new e(r.pathname,n.status,o)}};import{Buffer as L}from"buffer";function j(e){let t=e.req.param("schemaHash"),r=e.get("schemasByHash").get(t);return r==null?e.json({EngineNotStarted:{reason:"SchemaMissing"}},404):{schemaHash:t,schemas:r}}var Te=/datasource\s+db\s+[\w\s\d{="[\])(]+}/;function K(e,t){let n=L.from(e,"base64").toString("utf8"),r=`datasource db {
|
|
5
5
|
provider = "postgresql"
|