@prisma/dev 0.0.1 → 0.0.3
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.d.ts +39 -0
- package/dist/index.js +2 -0
- package/package.json +13 -9
- package/dist/index.d.mts +0 -18
- package/dist/index.mjs +0 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface StartServerOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The port the Accelerate server will listen on.
|
|
4
|
+
*
|
|
5
|
+
* Defaults to `5433`.
|
|
6
|
+
*
|
|
7
|
+
* An error is thrown if the port is already in use.
|
|
8
|
+
*/
|
|
9
|
+
acceleratePort?: number;
|
|
10
|
+
/**
|
|
11
|
+
* The port the database server will listen on.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to `5432`.
|
|
14
|
+
*
|
|
15
|
+
* An error is thrown if the port is already in use.
|
|
16
|
+
*/
|
|
17
|
+
databasePort?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to enable debug logging.
|
|
20
|
+
*
|
|
21
|
+
* Defaults to `false`.
|
|
22
|
+
*/
|
|
23
|
+
debug?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface Server {
|
|
26
|
+
accelerate: {
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
database: {
|
|
31
|
+
connectionString: string;
|
|
32
|
+
};
|
|
33
|
+
ppg: {
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
declare function unstable_startServer(options?: StartServerOptions): Promise<Server>;
|
|
38
|
+
|
|
39
|
+
export { type Server, type StartServerOptions, unstable_startServer };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
+
import{createHash as g}from"crypto";import{createServer as S}from"http2";import{promisify as h}from"util";import{serve as w}from"@hono/node-server";import{Hono as p}from"hono/tiny";function d(){let e,a,o=new Promise((r,t)=>{e=r,a=t});return{fail:a,promise:o,succeed:e}}async function v(e,a,o){let r=new p;r.use(async(n,i)=>{n.set("db",a),n.set("debug",!!o),await i()}),r.route("/",f);let{fail:t,promise:s,succeed:l}=d(),c=w({createServer:S,fetch:r.fetch,port:e},()=>{l()});return c.on("error",n=>{if(typeof n=="object"&&"code"in n&&n.code==="EADDRINUSE")return t({portNotAvailable:e});console.error(n)}),await s,{async close(){await h(c.close.bind(c))()},port:e,url:`http://localhost:${e}`}}var u=new Map,f=new p;f.put("/:clientVersion/:schemaHash/schema",async e=>{let{req:a}=e,o=await a.text(),r=a.param("schemaHash");return o===u.get(r)?e.text(r):r!==y(o)?e.text("hashes do not match",500):(u.set(r,o),e.text(r))});function y(e){return g("sha256").update(e).digest("hex")}import{promisify as P}from"util";import{PGlite as D}from"@electric-sql/pglite";import{createServer as A,LogLevel as x}from"pglite-server";async function b(e,a){let o="default",r="postgres",t=new D({database:o,dataDir:"memory://",debug:a?5:void 0,username:r});await t.waitReady;let s=A(t,{keepAlive:!0,logLevel:a?x.Debug:void 0}),{fail:l,promise:c,succeed:n}=d();return s.on("error",i=>{if("code"in i&&i.code==="EADDRINUSE")return l(new Error(`Port ${e} is already in use. Provide a different \`dbport\` number and try again.`));console.error(i)}),s.listen(e,()=>n()),await c,{async close(){try{await P(s.close.bind(s))()}finally{await t.close()}},connectionString:`postgres://${r}@localhost:${e}/${o}`,database:o,port:e,username:r}}async function F(e){let{acceleratePort:a=5433,databasePort:o=5432,debug:r}=e||{},t=await b(o,r),s=await v(a,t);return{accelerate:{url:s.url},close:()=>l([s,t]),database:{connectionString:t.connectionString},ppg:{url:`prisma+postgres://localhost:${s.port}/?dbname=${t.database}&dbport=${t.port}&dbuser=${t.username}`}};async function l(c){let i=(await Promise.allSettled(c.map(m=>m.close()))).filter(m=>m.status==="rejected").map(m=>new Error(m.reason));if(i.length>0)throw new AggregateError(i,"Failed to close some servers")}}export{F as unstable_startServer};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/dev",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A local Prisma Postgres server for development and testing",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./dist/index.js",
|
|
6
7
|
"module": "./dist/index.js",
|
|
7
8
|
"types": "./dist/index.d.ts",
|
|
@@ -15,12 +16,6 @@
|
|
|
15
16
|
"default": "./dist/index.js"
|
|
16
17
|
}
|
|
17
18
|
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"build": "tsup",
|
|
20
|
-
"check:exports": "attw . --pack",
|
|
21
|
-
"lint": "eslint --fix .", "test": "",
|
|
22
|
-
"typecheck": "tsc --noEmit"
|
|
23
|
-
},
|
|
24
19
|
"keywords": [
|
|
25
20
|
"prisma",
|
|
26
21
|
"postgres",
|
|
@@ -41,6 +36,15 @@
|
|
|
41
36
|
"dependencies": {
|
|
42
37
|
"@electric-sql/pglite": "0.2.17",
|
|
43
38
|
"@hono/node-server": "1.14.1",
|
|
44
|
-
"hono": "4.7.8"
|
|
39
|
+
"hono": "4.7.8",
|
|
40
|
+
"pglite-server": "0.1.4"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"check:exports": "attw . --pack --profile esm-only",
|
|
45
|
+
"dev": "tsup --watch",
|
|
46
|
+
"lint": "eslint --fix .",
|
|
47
|
+
"test": "",
|
|
48
|
+
"typecheck": "tsc --noEmit"
|
|
45
49
|
}
|
|
46
|
-
}
|
|
50
|
+
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
interface StartServerOptions {
|
|
2
|
-
/**
|
|
3
|
-
* An abort signal to stop the server abruptly.
|
|
4
|
-
*/
|
|
5
|
-
abortSignal?: AbortSignal;
|
|
6
|
-
onStart?: (port: number) => void;
|
|
7
|
-
/**
|
|
8
|
-
* The port the server will listen on.
|
|
9
|
-
*
|
|
10
|
-
* Defaults to `5433`.
|
|
11
|
-
*
|
|
12
|
-
* An error is thrown if the port is already in use.
|
|
13
|
-
*/
|
|
14
|
-
port?: number;
|
|
15
|
-
}
|
|
16
|
-
declare function unstable_startServer(options?: StartServerOptions): Promise<void>;
|
|
17
|
-
|
|
18
|
-
export { type StartServerOptions, unstable_startServer };
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{createServer as s}from"http2";import{serve as S}from"@hono/node-server";import{Hono as p}from"hono/tiny";var m=new p,o=m;async function l(e){let{abortSignal:a,onStart:n,port:i=5433}=e||{};await new Promise((c,t)=>{a?.addEventListener("abort",()=>t(new Error("aborted")),{once:!0});try{S({createServer:s,fetch:o.fetch,port:i},r=>n?.(r.port))}catch(r){t(r)}})}export{l as unstable_startServer};
|