@prisma/dev 0.0.0-dev.202505261811 → 0.0.0-dev.202505262028
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-EVE556Q6.js +2 -0
- package/dist/daemon/client.d.ts +24 -0
- package/dist/daemon/client.js +2 -0
- package/dist/daemon/daemon.d.ts +2 -0
- package/dist/daemon/daemon.js +2 -0
- package/dist/index-CW1pktRs.d.ts +83 -0
- package/dist/index.d.ts +1 -83
- package/dist/index.js +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as url from 'url';
|
|
2
|
+
import { SockDaemonClient } from 'sock-daemon/client';
|
|
3
|
+
import { S as ServerOptions, a as Server } from '../index-CW1pktRs.js';
|
|
4
|
+
import { MessageBase } from 'sock-daemon/server';
|
|
5
|
+
|
|
6
|
+
type Kind = "START_SERVER" | "STOP_SERVER";
|
|
7
|
+
type RequestMessage = MessageBase & {
|
|
8
|
+
kind: Kind;
|
|
9
|
+
args?: unknown;
|
|
10
|
+
};
|
|
11
|
+
type ResponseMessage = MessageBase & {
|
|
12
|
+
kind: Kind;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
declare class MyServiceClient extends SockDaemonClient<RequestMessage, ResponseMessage> {
|
|
17
|
+
static get serviceName(): string;
|
|
18
|
+
static get daemonScript(): url.URL;
|
|
19
|
+
isResponse(msg: unknown): msg is ResponseMessage;
|
|
20
|
+
stopServer(): Promise<void>;
|
|
21
|
+
startServer(options: ServerOptions): Promise<Server>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { MyServiceClient };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as s}from"../chunk-EVE556Q6.js";import{SockDaemonClient as a}from"sock-daemon/client";var r=class extends a{static get serviceName(){return s}static get daemonScript(){return new URL("./daemon.js",import.meta.url)}isResponse(e){return super.isMessage(e)}async stopServer(){await super.request({kind:"STOP_SERVER"})}async startServer(e){let{result:t}=await super.request({kind:"START_SERVER",args:e});return t}};export{r as MyServiceClient};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{a as r}from"../chunk-EVE556Q6.js";import{SockDaemonServer as o}from"sock-daemon/server";var s=class extends o{isRequest(e){return super.isMessage(e)}static get serviceName(){return r}handle(e){return console.error("got request",e),Promise.resolve({id:e.id,kind:e.kind,result:null})}};var t=new s({});t.listen();
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
interface ServerOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The port the database server will listen on.
|
|
4
|
+
*
|
|
5
|
+
* Defaults to `51214`.
|
|
6
|
+
*
|
|
7
|
+
* An error is thrown if the port is already in use.
|
|
8
|
+
*/
|
|
9
|
+
databasePort?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to enable debug logging.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to `false`.
|
|
14
|
+
*/
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether to run the server in dry run mode.
|
|
18
|
+
*
|
|
19
|
+
* Defaults to `false`.
|
|
20
|
+
*/
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The name of the server.
|
|
24
|
+
*
|
|
25
|
+
* Defaults to `default`.
|
|
26
|
+
*/
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The persistence mode of the server.
|
|
30
|
+
*
|
|
31
|
+
* Default is `stateless`.
|
|
32
|
+
*/
|
|
33
|
+
persistenceMode?: PersistenceMode;
|
|
34
|
+
/**
|
|
35
|
+
* The port the server will listen on.
|
|
36
|
+
*
|
|
37
|
+
* Defaults to `51213`.
|
|
38
|
+
*
|
|
39
|
+
* An error is thrown if the port is already in use.
|
|
40
|
+
*/
|
|
41
|
+
port?: number;
|
|
42
|
+
/**
|
|
43
|
+
* The port the shadow database server will listen on.
|
|
44
|
+
*
|
|
45
|
+
* Defaults to `51215`.
|
|
46
|
+
*
|
|
47
|
+
* An error is thrown if the port is already in use.
|
|
48
|
+
*/
|
|
49
|
+
shadowDatabasePort?: number;
|
|
50
|
+
}
|
|
51
|
+
type PersistenceMode = "stateless" | "stateful";
|
|
52
|
+
|
|
53
|
+
type DBServerPurpose = "database" | "shadow_database";
|
|
54
|
+
|
|
55
|
+
declare const DEFAULT_DATABASE_PORT = 51214;
|
|
56
|
+
declare const DEFAULT_SERVER_PORT = 51213;
|
|
57
|
+
declare const DEFAULT_SHADOW_DATABASE_PORT = 51215;
|
|
58
|
+
type PortAssignableService = DBServerPurpose | "server";
|
|
59
|
+
declare class PortNotAvailableError extends Error {
|
|
60
|
+
port: number;
|
|
61
|
+
service: PortAssignableService;
|
|
62
|
+
name: string;
|
|
63
|
+
constructor(port: number, service: PortAssignableService);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface Server {
|
|
67
|
+
accelerate: {
|
|
68
|
+
url: string;
|
|
69
|
+
};
|
|
70
|
+
close(): Promise<void>;
|
|
71
|
+
database: {
|
|
72
|
+
connectionString: string;
|
|
73
|
+
};
|
|
74
|
+
ppg: {
|
|
75
|
+
url: string;
|
|
76
|
+
};
|
|
77
|
+
shadowDatabase: {
|
|
78
|
+
connectionString: string;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
declare function unstable_startServer(options?: ServerOptions): Promise<Server>;
|
|
82
|
+
|
|
83
|
+
export { DEFAULT_DATABASE_PORT as D, type PortAssignableService as P, type ServerOptions as S, type Server as a, DEFAULT_SERVER_PORT as b, DEFAULT_SHADOW_DATABASE_PORT as c, PortNotAvailableError as d, unstable_startServer as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,83 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* The port the database server will listen on.
|
|
4
|
-
*
|
|
5
|
-
* Defaults to `51214`.
|
|
6
|
-
*
|
|
7
|
-
* An error is thrown if the port is already in use.
|
|
8
|
-
*/
|
|
9
|
-
databasePort?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Whether to enable debug logging.
|
|
12
|
-
*
|
|
13
|
-
* Defaults to `false`.
|
|
14
|
-
*/
|
|
15
|
-
debug?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Whether to run the server in dry run mode.
|
|
18
|
-
*
|
|
19
|
-
* Defaults to `false`.
|
|
20
|
-
*/
|
|
21
|
-
dryRun?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* The name of the server.
|
|
24
|
-
*
|
|
25
|
-
* Defaults to `default`.
|
|
26
|
-
*/
|
|
27
|
-
name?: string;
|
|
28
|
-
/**
|
|
29
|
-
* The persistence mode of the server.
|
|
30
|
-
*
|
|
31
|
-
* Default is `stateless`.
|
|
32
|
-
*/
|
|
33
|
-
persistenceMode?: PersistenceMode;
|
|
34
|
-
/**
|
|
35
|
-
* The port the server will listen on.
|
|
36
|
-
*
|
|
37
|
-
* Defaults to `51213`.
|
|
38
|
-
*
|
|
39
|
-
* An error is thrown if the port is already in use.
|
|
40
|
-
*/
|
|
41
|
-
port?: number;
|
|
42
|
-
/**
|
|
43
|
-
* The port the shadow database server will listen on.
|
|
44
|
-
*
|
|
45
|
-
* Defaults to `51215`.
|
|
46
|
-
*
|
|
47
|
-
* An error is thrown if the port is already in use.
|
|
48
|
-
*/
|
|
49
|
-
shadowDatabasePort?: number;
|
|
50
|
-
}
|
|
51
|
-
type PersistenceMode = "stateless" | "stateful";
|
|
52
|
-
|
|
53
|
-
type DBServerPurpose = "database" | "shadow_database";
|
|
54
|
-
|
|
55
|
-
declare const DEFAULT_DATABASE_PORT = 51214;
|
|
56
|
-
declare const DEFAULT_SERVER_PORT = 51213;
|
|
57
|
-
declare const DEFAULT_SHADOW_DATABASE_PORT = 51215;
|
|
58
|
-
type PortAssignableService = DBServerPurpose | "server";
|
|
59
|
-
declare class PortNotAvailableError extends Error {
|
|
60
|
-
port: number;
|
|
61
|
-
service: PortAssignableService;
|
|
62
|
-
name: string;
|
|
63
|
-
constructor(port: number, service: PortAssignableService);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface Server {
|
|
67
|
-
accelerate: {
|
|
68
|
-
url: string;
|
|
69
|
-
};
|
|
70
|
-
close(): Promise<void>;
|
|
71
|
-
database: {
|
|
72
|
-
connectionString: string;
|
|
73
|
-
};
|
|
74
|
-
ppg: {
|
|
75
|
-
url: string;
|
|
76
|
-
};
|
|
77
|
-
shadowDatabase: {
|
|
78
|
-
connectionString: string;
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
declare function unstable_startServer(options?: ServerOptions): Promise<Server>;
|
|
82
|
-
|
|
83
|
-
export { DEFAULT_DATABASE_PORT, DEFAULT_SERVER_PORT, DEFAULT_SHADOW_DATABASE_PORT, type PortAssignableService, PortNotAvailableError, type Server, unstable_startServer };
|
|
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 './index-CW1pktRs.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
1
|
+
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
|
|
2
2
|
import{createServer as at}from"http";import{promisify as it}from"util";import{serve as ct}from"@hono/node-server";import dt from"@prisma/get-platform";import{logger as ut}from"hono/logger";import{Hono as fe}from"hono/tiny";import{validator as S}from"hono/validator";import{process as lt}from"std-env";import{HTTPException as E}from"hono/http-exception";import{object as we,optional as Se,parseJson as Pe,pipe as x,regex as U,safeParse as ve,string as I,url as q}from"valibot";var V=/^(postgres|postgresql):\/\//,Ee=x(I(),Pe(),we({databaseUrl:x(I(),q(),U(V)),shadowDatabaseUrl:Se(x(I(),q(),U(V)))}));function K(t){return Buffer.from(JSON.stringify(t),"utf8").toString("base64url")}function De(t){let e=Buffer.from(t,"base64url").toString("utf8"),{issues:r,output:n,success:o}=ve(Ee,e,{abortEarly:!0});return o?[null,n]:[r]}var g=(t,e)=>{let{authorization:r}=t;if(!r)throw new E(401,{message:"Missing API Key"});let[n,o="",s]=r.split(" ");if(n!=="Bearer"||s)throw new E(401,{message:"Invalid API Key"});let[a,i]=De(o);if(a)throw new E(401,{message:"Invalid API Key",cause:a.join(", ")});let{databaseUrl:c}=i;if(c!==e.var.db.connectionString)throw new E(401,{message:"Unauthorized"});return{decodedAPIKey:i}};import{array as Ae,literal as Te,minLength as Re,object as Oe,pipe as xe,safeParse as Ie,string as $e,union as ke}from"valibot";var _e=Oe({tags:ke([xe(Ae($e()),Re(1)),Te("all")])});async function G(t){let{output:e,success:r}=Ie(_e,await t.req.json(),{abortEarly:!0});return r?e:t.text("Invalid input",400)}import{spawn as Ke}from"child_process";import{once as Ge}from"events";import{mkdir as ze}from"fs/promises";import{join as Je}from"path";import{setTimeout as We}from"timers/promises";import{proxySignals as Qe}from"foreground-child/proxy-signals";import{process as Ye}from"std-env";import{createWriteStream as He,WriteStream as Be}from"fs";import{access as Le,chmod as Ce,constants as Me,readFile as Fe,stat as je,unlink as Ne,writeFile as Ue}from"fs/promises";import qe from"env-paths";import{inflate as Ve}from"pako";var z=qe("prisma-dev");function J(t,e){return`${z.cache}/engine/${t}/${e}`}function W(t){return`${z.data}/${t}`}async function D(t){try{return await Le(t,Me.F_OK),!0}catch(e){if(k(e))return!1;throw e}}async function Q(t,e){let r=Ve(t);await Ue(e,r),await Ce(e,"755")}async function Y(t,e){await t.stream().pipeTo(Be.toWeb(He(e,{encoding:"utf-8"})))}async function X(t){try{return await Ne(t),!0}catch{return!1}}async function $(t){try{return(await je(t)).mtimeMs}catch(e){if(k(e))return-1/0;throw e}}function k(t){return t!=null&&typeof t=="object"&&"code"in t&&t.code==="ENOENT"}async function Z(t){try{return await Fe(t,{encoding:"utf-8"})}catch(e){if(k(e))return null;throw e}}function A(){let t,e,r=new Promise((s,a)=>{t=s,e=a}),n=s=>{n=o=null,e(s)},o=s=>{o=n=null,t(s)};return{fail:s=>n?.(s),promise:r,succeed:s=>o?.(s)}}var{PRISMA_DEV_FORCE_ENGINE_DOWNLOAD:Xe,PRISMA_DEV_FORCE_NETWORK_DELAY_MS:ee}=Ye.env,y=class t{static#r=new Map;#e;#t;constructor(e){this.#e=e,this.#t=null}static async get(e){let r=`${e.schemaHash}:${e.clientVersion}`;try{let n=t.#r.get(r);if(n)return n;let o=new t(e);return t.#r.set(r,o),e.debug&&console.debug("starting engine...",e),await o.start(),e.debug&&console.debug("engine started!"),o}finally{t.stopAll(r)}}static async stopAll(e){let n=(await Promise.allSettled(Array.from(t.#r.entries()).filter(([o])=>o!==e).map(async([o,s])=>{try{await s.stop()}finally{t.#r.delete(o)}}))).filter(o=>o.status==="rejected").map(o=>o.reason);if(n.length>0)throw new AggregateError(n,"Failed to stop engines")}async commitTransaction(e,r){return await this.#i(e,r,"commit")}async request(e,r){let{url:n}=await this.#t,o=this.#n(r),s=await fetch(n,{body:typeof e=="string"?e:JSON.stringify(e),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await f.fromResponse(s);return await s.text()}async rollbackTransaction(e,r){return await this.#i(e,r,"rollback")}async startTransaction(e,r){let{url:n}=await this.#t,o=this.#n(r),s=await fetch(`${n}/transaction/start`,{body:JSON.stringify(e),headers:{...o,"Content-Type":"application/json"},method:"POST"});if(!s.ok)throw await f.fromResponse(s);return await s.json()}async start(){if(this.#t!=null)return;let{fail:e,promise:r,succeed:n}=A();this.#t=r;let o=await this.#s();this.#e.debug&&console.debug("spinning up engine at path...",o);let s=Ke(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});Qe(s),s.stderr.setEncoding("utf8"),s.stdout.setEncoding("utf8");let a=u=>{let m=u.split(`
|
|
3
3
|
`).find(ye=>ye.includes("Started query engine http server"));if(!m)return;s.stdout.removeListener("data",a);let{fields:p}=JSON.parse(m);if(p==null)return e(new Error(`Unexpected data during initialization, "fields" are missing: ${u}`));let{ip:l,port:N}=p;if(l==null||N==null)return e(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: ${u}`));n({childProcess:s,url:`http://${l}:${N}`})},i=u=>{this.#t=null,e(new w(String(u))),s.removeListener("exit",c),s.kill()};s.once("error",i);let c=(u,m)=>{this.#t=null,e(new w(`Query Engine exited with code ${u} and signal ${m}`))};s.once("exit",c),s.stdout.on("data",a),s.stderr.on("data",console.error),await this.#t}async stop(){if(this.#t==null)return;let{childProcess:e}=await this.#t;e.exitCode==null&&e.signalCode==null&&(e.kill(),await Ge(e,"exit"))}async#s(){this.#e.debug&&console.debug("getting engine commit hash...");let e=await this.#o();this.#e.debug&&console.debug("got engine commit hash",e);let r=J(this.#e.clientVersion,e);this.#e.debug&&console.debug("cache directory path",r),await ze(r,{recursive:!0});let{platform:n}=this.#e.platform,o=n==="windows"?".exe":"",s=Je(r,`query-engine-${n}${o}`);return this.#e.debug&&console.debug("engine binary path",s),(Xe==="1"||await D(s)===!1)&&await this.#a({commitHash:e,extension:o,engineBinaryPath:s}),s}async#o(){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 n=(await e.json()).devDependencies?.["@prisma/engines-version"];if(!n)throw new Error("Couldn't find engines version in package.json");let o=n.split(".").at(-1);if(!o)throw new Error("Couldn't find commit hash in engines version");return o}async#a(e){let{commitHash:r,extension:n,engineBinaryPath:o}=e,{binaryTarget:s}=this.#e.platform,a=`https://binaries.prisma.sh/all_commits/${r}/${s}/query-engine${n}.gz`;this.#e.debug&&console.debug("downloading engine from url",a);let i=await fetch(a);if(!i.ok)throw new Error(`Couldn't download engine. URL: ${a}, status code: ${i.status}`);ee&&await We(Number(ee)),await Q(await i.arrayBuffer(),o),this.#e.debug&&console.debug("engine downloaded and saved at",o)}#n(e){let r={};for(let[n,o]of Object.entries(e))o!=null&&(r[n]=o);return r}async#i(e,r,n){let{url:o}=await this.#t,s=this.#n(r),a=await fetch(`${o}/transaction/${e}/${n}`,{headers:{...s,"Content-Type":"application/json"},method:"POST"});if(!a.ok)throw await f.fromResponse(a);try{return await a.json()}catch{return{}}}};function T(t,e){return console.error(t),t instanceof w?e.json({EngineNotStarted:{reason:{EngineStartupError:{logs:[],msg:t.message}}}},500):t instanceof f?e.text(t.responseBody,t.statusCode):e.body(null,500)}var w=class extends Error{name="EngineStartError"},f=class t extends Error{constructor(r,n,o){super(`${r}: Query Engine response status ${n}, body: ${o}`);this.action=r;this.statusCode=n;this.responseBody=o}name="EngineHttpError";static async fromResponse(r){let n=new URL(r.url),o=await r.text();return new t(n.pathname,r.status,o)}};var te=51214,re=51213,ne=51215,h=class extends Error{constructor(r,n){super(`Port number \`${r}\` is not available for service ${n}.`);this.port=r;this.service=n}name="PortNotAvailableError"};import{Buffer as oe}from"buffer";var R=new Map;async function _(t){let r=new TextEncoder().encode(t),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}function se(t){let e=t.req.param("schemaHash"),r=R.get(e);return r==null?t.json({EngineNotStarted:{reason:"SchemaMissing"}},404):{schemaHash:e,schemas:r}}var Ze=/datasource\s+db\s+\{\s*provider\s*=\s*"postgres(!?ql)?"\s+url\s*=\s*.+\s*\}/;async function ae(t,e){let r=oe.from(t,"base64").toString("utf8"),n=`datasource db {
|
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.202505262028",
|
|
4
4
|
"description": "A local Prisma Postgres server for development and testing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"import": "./dist/index.js",
|
|
16
16
|
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./daemon/client": {
|
|
19
|
+
"types": "./dist/daemon/client.d.ts",
|
|
20
|
+
"import": "./dist/daemon/client.js",
|
|
21
|
+
"default": "./dist/daemon/client.js"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
24
|
"keywords": [
|
|
@@ -49,6 +54,7 @@
|
|
|
49
54
|
"pathe": "2.0.3",
|
|
50
55
|
"proper-lockfile": "4.1.2",
|
|
51
56
|
"read-last-lines-ts": "1.2.1",
|
|
57
|
+
"sock-daemon": "1.4.2",
|
|
52
58
|
"std-env": "3.9.0",
|
|
53
59
|
"valibot": "1.1.0"
|
|
54
60
|
},
|