@prisma/dev 0.0.0-dev.202506041726 → 0.0.0-dev.202506041810
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-J6GYW6XA.js → chunk-CLIITWV6.js} +1 -1
- package/dist/chunk-KSRPCQJC.js +2 -0
- package/dist/chunk-QENZ2XGZ.js +4 -0
- package/dist/daemon/client.d.ts +1 -1
- package/dist/{db-mXLGDv93.d.ts → db-9fHowc0q.d.ts} +23 -2
- package/dist/db.d.ts +1 -1
- package/dist/db.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/state.d.ts +1 -1
- package/dist/state.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-P55S57KT.js +0 -4
- package/dist/chunk-WYC7B6DS.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{e as l,
|
|
2
|
+
import{e as l,l as m}from"./chunk-KSRPCQJC.js";import{PGlite as g}from"@electric-sql/pglite";import{PGLiteSocketServer as D}from"@electric-sql/pglite-socket";import{pgDump as y}from"@electric-sql/pglite-tools/pg_dump";import{filename as w}from"pathe/utils";var a={connectionLimit:1,connectTimeout:0,database:"template1",maxIdleConnectionLifetime:0,password:"postgres",poolTimeout:0,socketTimeout:0,sslMode:"disable",username:"postgres"},P=`postgres://${a.username}:${a.password}@localhost`,S=new URLSearchParams({connection_limit:String(a.connectionLimit),connect_timeout:String(a.connectTimeout),max_idle_connection_lifetime:String(a.maxIdleConnectionLifetime),pool_timeout:String(a.poolTimeout),socket_timeout:String(a.socketTimeout),sslmode:a.sslMode});async function k(e,r){let c=e==="database"?r.databasePort:r.shadowDatabasePort;if(r.dryRun)return u(e,r,{db:null,port:c,server:null});let{debug:o}=r,s=await(e==="shadow_database"?p:b)(r.pgliteDataDirPath,o);o&&s.onNotification((t,n)=>{console.debug(`[${e}][${t}] ${n}`)});let d=new D({db:s,debug:o,inspect:o,port:c});o&&(d.addEventListener("listening",t=>{let{detail:n}=t;console.debug(`[${e}] server listening on ${JSON.stringify(n)}`)}),d.addEventListener("connection",t=>{let{clientAddress:n,clientPort:f}=t.detail;console.debug(`[${e}] client connected from ${n}:${f}`)}),d.addEventListener("error",t=>{let{detail:n}=t;console.error(`[${e}] server error:`,n)}));try{await d.start()}catch(t){throw t instanceof Error&&"code"in t&&t.code==="EADDRINUSE"?new m(c,e):t}return u(e,r,{db:s,port:c,server:d})}function u(e,r,c){let{debug:o}=r,{db:i,port:s,server:d}=c||{};return o&&console.debug(`[${e}] server started on port ${s}`),{...a,close:async()=>{let t=[];try{await d?.stop(),o&&console.debug(`[${e}] server stopped on port ${s}`)}catch(n){console.error(`[${e}] server stop error`,n),t.push(n)}if(e==="database")try{await i?.syncToFs(),o&&console.debug(`[${e}] synced to filesystem`)}catch(n){console.error(`[${e}] sync error`,n),t.push(n)}try{await i?.close(),o&&console.debug(`[${e}] closed`)}catch(n){console.error(`[${e}] close error`,n),t.push(n)}if(t.length>0)throw new AggregateError(t,`Failed to close ${e} properly`)},connectionString:v(s),dump:async t=>{e==="shadow_database"||!i||await $({db:i,debug:o,destinationPath:t})},port:s}}function v(e){return`${P}:${e}/${a.database}?${S.toString()}`}async function b(e,r){return await g.create({database:a.database,dataDir:e,debug:r?5:void 0,defaultDataTransferContainer:"file",relaxedDurability:!1,username:a.username})}async function p(e,r){return await g.create({database:a.database,dataDir:"memory://",debug:r?5:void 0,defaultDataTransferContainer:"file",relaxedDurability:!1,username:a.username})}async function $(e){let{dataDir:r,db:c,debug:o,destinationPath:i}=e,s=c||await b(r,o),d=await y({args:["--quote-all-identifiers","--schema-only"],fileName:i?w(i):void 0,pg:s});return i?(o&&console.debug(`[DB] Dumping database to ${i}`),await l(d,i)):(o&&console.debug("[DB] Dumping database to memory"),await d.text())}export{k as a,$ as b};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{createWriteStream as a,WriteStream as c}from"fs";import{access as u,chmod as p,constants as m,mkdir as f,readdir as l,readFile as g,writeFile as d}from"fs/promises";import x from"env-paths";import{inflate as y}from"pako";var o=x("prisma-dev");function D(r,e){return`${o.cache}/engine/${r}/${e}`}function E(r){return`${o.data}/${r}`}async function w(r){try{return await u(r,m.F_OK),!0}catch(e){if(n(e))return!1;throw e}}async function v(r,e){let t=y(r);await d(e,t),await p(e,"755")}async function F(r,e){await r.stream().pipeTo(c.toWeb(a(e,{encoding:"utf-8"})))}function n(r){return r!=null&&typeof r=="object"&&"code"in r&&r.code==="ENOENT"}async function b(r){try{return await g(r,{encoding:"utf-8"})}catch(e){if(n(e))return null;throw e}}async function S(r){await f(r,{recursive:!0})}async function _(r){try{return(await l(r,{withFileTypes:!0})).reduce((t,i)=>(i.isDirectory()&&!i.name.startsWith(".")&&t.push(i.name),t),[])}catch(e){if(n(e))return[];throw e}}var B=51214,R=51213,$=51215,s=class extends Error{constructor(t,i){super(`Port number \`${t}\` is not available for service ${i}.`);this.port=t;this.service=i}name="PortNotAvailableError"};export{D as a,E as b,w as c,v as d,F as e,b as f,S as g,_ as h,B as i,R as j,$ as k,s as l};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{b as c,f as w,g as x,h as O,i as $,j as E,k as _}from"./chunk-KSRPCQJC.js";import{writeFile as J}from"fs/promises";import{hc as U}from"hono/client";import{join as u}from"pathe";import{check as j,lock as B}from"proper-lockfile";import{process as m}from"std-env";import{integer as I,literal as H,minLength as C,minValue as T,number as V,object as f,optional as R,parseJson as Y,pipe as l,safeParse as Z,string as D,url as q}from"valibot";import{process as F}from"std-env";function k(r,e){if(r==null)return!1;try{return F.kill?.(r,0)??!0}catch(t){return e&&console.error(`Error checking if process with PID ${r} exists:`,t),!1}}var N=l(D(),q()),A=f({connectionString:N}),M=f({url:N}),g=l(V(),I(),T(1)),z=f({database:A,http:M,ppg:M,shadowDatabase:A}),K=f({databasePort:g,exports:R(z),name:l(D(),C(1)),pid:R(l(V(),I(),T(0))),port:g,shadowDatabasePort:g,version:H("1")}),y=Symbol("initialize"),v="default",h=class{databasePort;debug;dryRun;name;persistenceMode;pid;port;shadowDatabasePort;constructor(e){this.databasePort=e.databasePort??51214,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??v,this.persistenceMode=e.persistenceMode,this.pid=e.pid??m.pid,this.port=e.port??51213,this.shadowDatabasePort=e.shadowDatabasePort??51215}static async createExclusively(e){let t=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new p({...e,pid:m.pid}):new P(e);return await t[y](),t}static async fromServerDump(e){let{debug:t,name:s=v}=e??{},n=c(s),a=p.getServerDumpPath(n),i=await w(a);if(i==null)return t&&console.debug(`[State] No server dump file found at: ${a}`),null;t&&(console.debug(`[State] server dump file found at "${a}":`),console.debug(i));let{issues:b,output:o,success:d}=Z(l(D(),Y(),K),i);if(!d)throw t&&console.debug(`[State] Invalid server dump file at "${a}":
|
|
3
|
+
${JSON.stringify(b,null,2)}`),new Error(`Invalid Prisma Dev state for "${s}".`);return new p({databasePort:o.databasePort,debug:t,dryRun:!1,name:s,pid:o.pid,port:o.port,serverDump:o,shadowDatabasePort:o.shadowDatabasePort})}static async scan(e){let{debug:t}=e??{},s=u(c(v),"..");t&&console.debug(`[State] scanning for server states in: ${s}`);let n=await O(s);return t&&console.debug(`[State] found server names: ${JSON.stringify(n)}`),await Promise.all(n.map(a=>W(a,t)))}},P=class extends h{constructor(e){super({...e,persistenceMode:"stateless",pid:m.pid})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[y](){}async close(){}async writeServerDump(){}},p=class r extends h{#a;#e;#s;#o;#t;#r=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=c(this.name),this.#a=u(this.#e,"db_dump.bak"),this.#s=u(this.#e,".pglite"),this.#t=e.serverDump??null,this.#o=r.getServerDumpPath(this.#e)}static getServerDumpPath(e){return u(e,"server.json")}get databaseDumpPath(){return this.#a}get exports(){return this.#t?.exports}get pgliteDataDirPath(){return this.#s}async[y](){await x(this.#s),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#r=await B(this.#e,{lockfilePath:u(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`),await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new S(this.name):e}}async close(){if(this.#r!=null)try{await this.#r(),this.#r=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async writeServerDump(e){this.#t={name:this.name,version:"1",pid:m.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await J(this.#o,`${JSON.stringify(this.#t,null,2)}
|
|
4
|
+
`,{encoding:"utf-8"})}};async function W(r,e){let t={databasePort:-1,exports:void 0,name:r,pid:void 0,port:-1,shadowDatabasePort:-1,version:"1"};try{let s=await h.fromServerDump({debug:e,name:r});if(!s)return e&&console.debug(`[State] no server state found for name: ${r}`),{...t,status:"no_such_server"};t.databasePort=s.databasePort,t.exports=s.exports,t.pid=s.pid,t.port=s.port,t.shadowDatabasePort=s.shadowDatabasePort;let{exports:n,pid:a}=s;if(!k(a,e))return e&&console.debug(`[State] server state for "${r}" has no running process with PID: ${a}`),{...t,status:"not_running"};let i=c(r);try{if(!await j(i,{lockfilePath:u(i,".lock")}))return e&&console.debug(`[State] server state for "${r}" is not locked, indicating it is not running.`),{...t,status:"starting_up"}}catch(L){e&&console.error(`[State] server state for "${r}" failed to check lock:`,L)}if(!n)return{...t,status:"starting_up"};let{http:b}=n,o=await U(b.url).health.$get();if(!o.ok)return e&&console.debug(`[State] server state for "${r}" is not live: ${JSON.stringify(o)}`),{...t,status:"not_running"};let d=await o.json();return d.name!==r?(e&&console.debug(`[State] server state for "${r}" has mismatched health response: ${JSON.stringify(d)}`),{...t,status:"unknown"}):(e&&console.debug(`[State] server state for "${r}" is live: ${JSON.stringify(d)}`),{...t,status:"running"})}catch(s){return e&&console.error(`[State] failed to get server status for "${r}":`,s),{...t,status:"error"}}}var S=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A server with the name "${e}" is already running.`)}};export{h as a,S as b};
|
package/dist/daemon/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as url from 'url';
|
|
2
2
|
import { SockDaemonClient } from 'sock-daemon/client';
|
|
3
|
-
import { S as ServerOptions, a as Server } from '../db-
|
|
3
|
+
import { S as ServerOptions, a as Server } from '../db-9fHowc0q.js';
|
|
4
4
|
import { MessageBase } from 'sock-daemon/server';
|
|
5
5
|
import '@electric-sql/pglite';
|
|
6
6
|
import 'valibot';
|
|
@@ -108,6 +108,9 @@ interface ServerOptions {
|
|
|
108
108
|
}
|
|
109
109
|
type ResolvedServerOptions = Required<ServerOptions>;
|
|
110
110
|
type PersistenceMode = "stateless" | "stateful";
|
|
111
|
+
interface ScanOptions {
|
|
112
|
+
debug?: boolean;
|
|
113
|
+
}
|
|
111
114
|
declare const PRIVATE_INITIALIZE_SYMBOL: unique symbol;
|
|
112
115
|
declare abstract class ServerState implements ResolvedServerOptions {
|
|
113
116
|
readonly databasePort: number;
|
|
@@ -123,13 +126,31 @@ declare abstract class ServerState implements ResolvedServerOptions {
|
|
|
123
126
|
pid: number | undefined;
|
|
124
127
|
});
|
|
125
128
|
static createExclusively(options: ServerOptions | undefined): Promise<ServerState>;
|
|
126
|
-
static fromServerDump(options?: Pick<ServerOptions, "debug" | "name">): Promise<
|
|
129
|
+
static fromServerDump(options?: Pick<ServerOptions, "debug" | "name">): Promise<StatefulServerState | null>;
|
|
130
|
+
static scan(options?: ScanOptions): Promise<ServerStatusV1[]>;
|
|
127
131
|
abstract get databaseDumpPath(): string;
|
|
128
132
|
abstract get pgliteDataDirPath(): string;
|
|
129
133
|
abstract [PRIVATE_INITIALIZE_SYMBOL](): Promise<void>;
|
|
130
134
|
abstract close(): Promise<void>;
|
|
131
135
|
abstract writeServerDump(exports?: Omit<Server, "close">): Promise<void>;
|
|
132
136
|
}
|
|
137
|
+
declare class StatefulServerState extends ServerState {
|
|
138
|
+
#private;
|
|
139
|
+
constructor(options: Omit<ServerOptions, "persistenceMode"> & {
|
|
140
|
+
pid: number | undefined;
|
|
141
|
+
serverDump?: ServerDumpV1;
|
|
142
|
+
});
|
|
143
|
+
static getServerDumpPath(dataDirPath: string): string;
|
|
144
|
+
get databaseDumpPath(): string;
|
|
145
|
+
get exports(): Exports | undefined;
|
|
146
|
+
get pgliteDataDirPath(): string;
|
|
147
|
+
[PRIVATE_INITIALIZE_SYMBOL](): Promise<void>;
|
|
148
|
+
close(): Promise<void>;
|
|
149
|
+
writeServerDump(exports?: Exports): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
interface ServerStatusV1 extends ServerDumpV1 {
|
|
152
|
+
status: "running" | "starting_up" | "not_running" | "no_such_server" | "unknown" | "error";
|
|
153
|
+
}
|
|
133
154
|
declare class ServerStateAlreadyExistsError extends Error {
|
|
134
155
|
name: string;
|
|
135
156
|
constructor(name: string);
|
|
@@ -168,4 +189,4 @@ type DumpDBOptions<D extends string> = {
|
|
|
168
189
|
};
|
|
169
190
|
declare function dumpDB<D extends string = never>(options: DumpDBOptions<D>): Promise<[D] extends [never] ? string : void>;
|
|
170
191
|
|
|
171
|
-
export { DEFAULT_DATABASE_PORT as D, type Exports as E, type PortAssignableService as P, type ResolvedServerOptions as R, type ServerOptions as S, type Server as a, DEFAULT_SERVER_PORT as b, DEFAULT_SHADOW_DATABASE_PORT as c, PortNotAvailableError as d, type ServerDumpV1 as e, type PersistenceMode as f,
|
|
192
|
+
export { DEFAULT_DATABASE_PORT as D, type Exports as E, type PortAssignableService as P, type ResolvedServerOptions as R, type ServerOptions as S, type Server as a, DEFAULT_SERVER_PORT as b, DEFAULT_SHADOW_DATABASE_PORT as c, PortNotAvailableError as d, type ServerDumpV1 as e, type PersistenceMode as f, type ScanOptions as g, ServerState as h, type ServerStatusV1 as i, ServerStateAlreadyExistsError as j, type DBServer as k, type DBDump as l, type DBServerPurpose as m, type DumpDBOptions as n, dumpDB as o, startDBServer as s, unstable_startServer as u };
|
package/dist/db.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import '@electric-sql/pglite';
|
|
2
|
-
export {
|
|
2
|
+
export { l as DBDump, k as DBServer, m as DBServerPurpose, n as DumpDBOptions, o as dumpDB, s as startDBServer } from './db-9fHowc0q.js';
|
|
3
3
|
import 'valibot';
|
package/dist/db.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-CLIITWV6.js";import"./chunk-KSRPCQJC.js";export{b as dumpDB,a as startDBServer};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { D as DEFAULT_DATABASE_PORT, b as DEFAULT_SERVER_PORT, c as DEFAULT_SHADOW_DATABASE_PORT, P as PortAssignableService, d as PortNotAvailableError, a as Server, u as unstable_startServer } from './db-
|
|
1
|
+
export { D as DEFAULT_DATABASE_PORT, b as DEFAULT_SERVER_PORT, c as DEFAULT_SHADOW_DATABASE_PORT, P as PortAssignableService, d as PortNotAvailableError, a as Server, u as unstable_startServer } from './db-9fHowc0q.js';
|
|
2
2
|
import '@electric-sql/pglite';
|
|
3
3
|
import 'valibot';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as H}from"./chunk-
|
|
2
|
+
import{a as H}from"./chunk-CLIITWV6.js";import{a as L}from"./chunk-QENZ2XGZ.js";import{a as $,c as j,d as D,i as ze,j as Ge,k as Je,l as B}from"./chunk-KSRPCQJC.js";import{HTTPException as v}from"hono/http-exception";import{object as se,optional as ie,parseJson as ae,pipe as A,regex as q,safeParse as ce,string as I,url as N}from"valibot";var V=/^(postgres|postgresql):\/\//,pe=A(I(),ae(),se({databaseUrl:A(I(),N(),q(V)),shadowDatabaseUrl:ie(A(I(),N(),q(V)))}));function U(n){return Buffer.from(JSON.stringify(n),"utf8").toString("base64url")}function ue(n){let e=Buffer.from(n,"base64url").toString("utf8"),{issues:t,output:r,success:o}=ce(pe,e,{abortEarly:!0});return o?[null,r]:[t]}var d=(n,e)=>{let{authorization:t}=n;if(!t)throw new v(401,{message:"Missing API Key"});let[r,o="",s]=t.split(" ");if(r!=="Bearer"||s)throw new v(401,{message:"Invalid API Key"});let[i,a]=ue(o);if(i)throw new v(401,{message:"Invalid API Key",cause:i.join(", ")});let{databaseUrl:c}=a;if(c!==e.var.db.connectionString)throw new v(401,{message:"Wrong API Key; Check your Prisma schema's `provider.url` value (probably defined in `.env`'s `DATABASE_URL` environment variable) is aligned with `prisma dev`'s output"});return{decodedAPIKey:a}};import{createServer as Ve}from"http";import{promisify as Ue}from"util";import{serve as Ke}from"@hono/node-server";import Me from"@prisma/get-platform";function b(){let n,e,t=new Promise((s,i)=>{n=s,e=i}),r=s=>{r=o=null,e(s)},o=s=>{o=r=null,n(s)};return{promise:t,reject:s=>r?.(s),resolve:s=>o?.(s)}}import{logger as Qe}from"hono/logger";import{Hono as ne}from"hono/tiny";import{Hono as De}from"hono/tiny";import{validator as y}from"hono/validator";import{array as le,literal as me,minLength as de,object as ge,pipe as he,safeParse as fe,string as ye,union as we}from"valibot";var Se=ge({tags:we([he(le(ye()),de(1)),me("all")])});async function K(n){let{output:e,success:t}=fe(Se,await n.req.json(),{abortEarly:!0});return t?e:n.text("Invalid input",400)}import{spawn as ve}from"child_process";import{once as be}from"events";import{mkdir as Ee}from"fs/promises";import{join as Pe}from"path";import{setTimeout as Re}from"timers/promises";import{proxySignals as Te}from"foreground-child/proxy-signals";import{process as He}from"std-env";var{PRISMA_DEV_FORCE_ENGINE_BINARY_DOWNLOAD:Ae,PRISMA_DEV_FORCE_ENGINE_BINARY_PATH:Ie,PRISMA_DEV_FORCE_NETWORK_DELAY_MS:M}=He.env,h=class n{static#n=new Map;#e;#t;constructor(e){this.#e=e,this.#t=null}static async get(e){let{debug:t}=e,r=`${e.schemaHash}:${e.clientVersion}`;try{let o=n.#n.get(r);if(o)return o;let s=new n(e);return n.#n.set(r,s),t&&console.debug("[Query Engine] starting...",e),await s.start(),t&&console.debug("[Query Engine] started!"),s}finally{n.stopAll(r)}}static async stopAll(e){let r=(await Promise.allSettled(Array.from(n.#n.entries()).filter(([o])=>o!==e).map(async([o,s])=>{try{await s.stop()}finally{n.#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(e,t){return await this.#o(e,t,"commit")}async request(e,t){let{url:r}=await this.start(),o=this.#r(t),s=await fetch(r,{body:typeof e=="string"?e:JSON.stringify(e),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await g.fromResponse(s);return await s.text()}async rollbackTransaction(e,t){return await this.#o(e,t,"rollback")}async startTransaction(e,t){let{url:r}=await this.start(),o=this.#r(t),s=await fetch(`${r}/transaction/start`,{body:JSON.stringify(e),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await g.fromResponse(s);return await s.json()}async start(){if(this.#t!=null)return await this.#t;let{promise:e,reject:t,resolve:r}=b();this.#t=e;let o=Ie||await this.#s();this.#e.debug&&console.debug("[Query Engine] spinning up at path...",o);let s=ve(o,["--enable-raw-queries","--enable-telemetry-in-response","--port","0"],{env:{LOG_QUERIES:"y",PRISMA_DML:this.#e.base64Schema,QE_LOG_LEVEL:"TRACE",RUST_BACKTRACE:"1",RUST_LOG:"info"},stdio:["ignore","pipe","pipe"],windowsHide:!0});Te(s),s.stderr.setEncoding("utf8"),s.stdout.setEncoding("utf8");let i=p=>{let l=p.split(`
|
|
3
3
|
`).find(oe=>oe.includes("Started query engine http server"));if(!l)return;s.stdout.removeListener("data",i);let{fields:m}=JSON.parse(l);if(m==null)return t(new Error(`Unexpected data during initialization, "fields" are missing: ${p}`));let{ip:u,port:_}=m;if(u==null||_==null)return t(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: ${p}`));r({childProcess:s,url:`http://${u}:${_}`})},a=p=>{this.#t=null,t(new f(String(p))),s.removeListener("exit",c),s.kill()};s.once("error",a);let c=(p,l)=>{this.#t=null,t(new f(`Query Engine exited with code ${p} and signal ${l}`))};return s.once("exit",c),s.stdout.on("data",i),this.#e.debug&&(s.stderr.on("data",console.error.bind(console,"[Query Engine]")),s.stdout.on("data",console.debug.bind(console,"[Query Engine]"))),await this.#t}async stop(){if(this.#t==null)return;let{childProcess:e}=await this.#t;e.exitCode==null&&e.signalCode==null&&(this.#t=null,e.kill(),await be(e,"exit"))}async#s(){this.#e.debug&&console.debug("[Query Engine] getting engine commit hash...");let e=await this.#i();this.#e.debug&&console.debug("[Query Engine] got engine commit hash",e);let t=$(this.#e.clientVersion,e);this.#e.debug&&console.debug("[Query Engine] cache directory path",t),await Ee(t,{recursive:!0});let{platform:r}=this.#e.platform,o=r==="windows"?".exe":"",s=Pe(t,`query-engine-${r}${o}`);return this.#e.debug&&console.debug("[Query Engine] binary path",s),(Ae==="1"||await j(s)===!1)&&await this.#a({commitHash:e,extension:o,engineBinaryPath:s}),s}async#i(){let e=await fetch(`https://registry.npmjs.org/@prisma/client/${this.#e.clientVersion}`);if(!e.ok)throw new Error(`Couldn't fetch package.json from npm registry, status code: ${e.status}`);let r=(await e.json()).devDependencies?.["@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(e){let{commitHash:t,extension:r,engineBinaryPath:o}=e,{binaryTarget:s}=this.#e.platform,i=`https://binaries.prisma.sh/all_commits/${t}/${s}/query-engine${r}.gz`;this.#e.debug&&console.debug("[Query Engine] downloading engine from url",i);let a=await fetch(i);if(!a.ok)throw new Error(`Couldn't download engine. URL: ${i}, status code: ${a.status}`);M&&await Re(Number(M)),await D(await a.arrayBuffer(),o),this.#e.debug&&console.debug("[Query Engine] downloaded and saved at",o)}#r(e){let t={};for(let[r,o]of Object.entries(e))o!=null&&(t[r]=o);return t}async#o(e,t,r){let{url:o}=await this.#t,s=this.#r(t),i=await fetch(`${o}/transaction/${e}/${r}`,{headers:{...s,"Content-Type":"application/json"},method:"POST"});if(!i.ok)throw await g.fromResponse(i);try{return await i.json()}catch{return{}}}};function E(n,e){return console.error(n),n instanceof f?e.json({EngineNotStarted:{reason:{EngineStartupError:{logs:[],msg:n.message}}}},500):n instanceof g?e.text(n.responseBody,n.statusCode):e.body(null,500)}var f=class extends Error{name="EngineStartError"},g=class n extends Error{constructor(t,r,o){super(`${t}: Query Engine response status ${r}, body: ${o}`);this.action=t;this.statusCode=r;this.responseBody=o}name="EngineHttpError";static async fromResponse(t){let r=new URL(t.url),o=await t.text();return new n(r.pathname,t.status,o)}};import{Buffer as Q}from"buffer";var P=new Map;async function O(n){let t=new TextEncoder().encode(n),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(i=>i.toString(16).padStart(2,"0")).join("")}function F(n){let e=n.req.param("schemaHash"),t=P.get(e);return t==null?n.json({EngineNotStarted:{reason:"SchemaMissing"}},404):{schemaHash:e,schemas:t}}var Oe=/datasource\s+db\s+\{\s*provider\s*=\s*"postgres(!?ql)?"\s+url\s*=\s*.+\s*\}/;async function z(n,e){let t=Q.from(n,"base64").toString("utf8"),r=`datasource db {
|
|
5
5
|
provider = "postgresql"
|
package/dist/state.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import 'valibot';
|
|
2
|
-
export { E as Exports, f as PersistenceMode, R as ResolvedServerOptions, e as ServerDumpV1, S as ServerOptions,
|
|
2
|
+
export { E as Exports, f as PersistenceMode, R as ResolvedServerOptions, g as ScanOptions, e as ServerDumpV1, S as ServerOptions, h as ServerState, j as ServerStateAlreadyExistsError, i as ServerStatusV1 } from './db-9fHowc0q.js';
|
|
3
3
|
import '@electric-sql/pglite';
|
package/dist/state.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a,b}from"./chunk-
|
|
2
|
+
import{a,b}from"./chunk-QENZ2XGZ.js";import"./chunk-KSRPCQJC.js";export{a as ServerState,b as ServerStateAlreadyExistsError};
|
package/package.json
CHANGED
package/dist/chunk-P55S57KT.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as m,f as D,g as f,h as y,i as S}from"./chunk-WYC7B6DS.js";import{mkdir as k,writeFile as L}from"fs/promises";import{join as n}from"pathe";import{lock as V}from"proper-lockfile";import{process as d}from"std-env";import{integer as M,literal as F,minLength as N,minValue as x,number as R,object as p,optional as w,parseJson as U,pipe as a,safeParse as B,string as g,url as j}from"valibot";var I=a(g(),j()),O=p({connectionString:I}),E=p({url:I}),h=a(R(),M(),x(1)),J=p({database:O,http:E,ppg:E,shadowDatabase:O}),C=p({databasePort:h,exports:w(J),name:a(g(),N(1)),pid:w(a(R(),M(),x(0))),port:h,shadowDatabasePort:h,version:F("1")}),v=Symbol("initialize"),A="default",u=class{databasePort;debug;dryRun;name;persistenceMode;pid;port;shadowDatabasePort;constructor(e){this.databasePort=e.databasePort??51214,this.debug=e.debug??!1,this.dryRun=e.dryRun??!1,this.name=e.name??A,this.persistenceMode=e.persistenceMode,this.pid=e.pid??d.pid,this.port=e.port??51213,this.shadowDatabasePort=e.shadowDatabasePort??51215}static async createExclusively(e){let t=e?.dryRun!==!0&&e?.persistenceMode!=="stateless"?new s({...e,pid:d.pid}):new b(e);return await t[v](),t}static async fromServerDump(e){let{debug:t,name:c=A}=e??{},T=m(c),o=s.getServerDumpPath(T),l=await D(o);if(l==null)return t&&console.debug(`[State] No server dump file found at: ${o}`),null;t&&(console.debug(`[State] server dump file found at "${o}":`),console.debug(l));let{issues:_,output:r,success:$}=B(a(g(),U(),C),l);if(!$)throw t&&console.debug(`[State] Invalid server dump file at "${o}":
|
|
3
|
-
${JSON.stringify(_,null,2)}`),new Error(`Invalid Prisma Dev state for "${c}".`);return new s({databasePort:r.databasePort,debug:t,dryRun:!1,name:c,pid:r.pid,port:r.port,serverDump:r,shadowDatabasePort:r.shadowDatabasePort})}},b=class extends u{constructor(e){super({...e,persistenceMode:"stateless",pid:d.pid})}get databaseDumpPath(){return"<DUMP_PATH>"}get pgliteDataDirPath(){return"memory://"}async[v](){}async close(){}async writeServerDump(){}},s=class i extends u{#s;#e;#a;#i;#r;#t=null;constructor(e){super({...e,persistenceMode:"stateful"}),this.#e=m(this.name),this.#s=n(this.#e,"db_dump.bak"),this.#a=n(this.#e,".pglite"),this.#r=e.serverDump??null,this.#i=i.getServerDumpPath(this.#e)}static getServerDumpPath(e){return n(e,"server.json")}get databaseDumpPath(){return this.#s}get pgliteDataDirPath(){return this.#a}async[v](){await k(this.#e,{recursive:!0}),this.debug&&console.debug(`[State] using data directory: ${this.#e}`);try{this.#t=await V(this.#e,{lockfilePath:n(this.#e,".lock")}),this.debug&&console.debug(`[State] obtained lock on: ${this.#e}`),await this.writeServerDump()}catch(e){throw e instanceof Error&&"code"in e&&e.code==="ELOCKED"?new P(this.name):e}}async close(){if(this.#t!=null)try{await this.#t(),this.#t=null,this.debug&&console.debug(`[State] released lock on: ${this.#e}`)}catch(e){throw console.error(`[State] failed to release lock on: ${this.#e}`),e}}async writeServerDump(e){this.#r={name:this.name,version:"1",pid:d.pid,port:this.port,databasePort:this.databasePort,shadowDatabasePort:this.shadowDatabasePort,exports:e},await L(this.#i,`${JSON.stringify(this.#r,null,2)}
|
|
4
|
-
`,{encoding:"utf-8"})}},P=class extends Error{name="ServerStateAlreadyExistsError";constructor(e){super(`A server with the name "${e}" is already running.`)}};export{u as a,P as b};
|
package/dist/chunk-WYC7B6DS.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{createWriteStream as a,WriteStream as c}from"fs";import{access as u,chmod as p,constants as m,mkdir as P,readdir as A,readFile as f,writeFile as l}from"fs/promises";import g from"env-paths";import{inflate as d}from"pako";var i=g("prisma-dev");function D(r,e){return`${i.cache}/engine/${r}/${e}`}function E(r){return`${i.data}/${r}`}async function w(r){try{return await u(r,m.F_OK),!0}catch(e){if(n(e))return!1;throw e}}async function v(r,e){let t=d(r);await l(e,t),await p(e,"755")}async function F(r,e){await r.stream().pipeTo(c.toWeb(a(e,{encoding:"utf-8"})))}function n(r){return r!=null&&typeof r=="object"&&"code"in r&&r.code==="ENOENT"}async function b(r){try{return await f(r,{encoding:"utf-8"})}catch(e){if(n(e))return null;throw e}}var _=51214,O=51213,B=51215,o=class extends Error{constructor(t,s){super(`Port number \`${t}\` is not available for service ${s}.`);this.port=t;this.service=s}name="PortNotAvailableError"};export{D as a,E as b,w as c,v as d,F as e,b as f,_ as g,O as h,B as i,o as j};
|