@prisma/cli-init 0.0.0-dev.202512231634 → 0.0.0-dev.202512241311

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.
@@ -16,7 +16,7 @@ import {
16
16
  safeParse,
17
17
  string,
18
18
  union
19
- } from "./chunk-7WBH7PZA.js";
19
+ } from "./chunk-GPGSLSD4.js";
20
20
  import {
21
21
  __commonJS,
22
22
  __require,
@@ -138505,13 +138505,11 @@ schemafulRoute.post("/transaction/start", validator("header", apiKeyValidator),
138505
138505
  }
138506
138506
  const { id } = transaction;
138507
138507
  const clientVersion = req.param("clientVersion");
138508
- const port = ctx.get("port");
138509
- const protocol = ctx.get("protocol");
138510
138508
  const schemaHash = req.param("schemaHash");
138511
138509
  return ctx.json({
138512
138510
  ...response,
138513
138511
  "data-proxy": {
138514
- endpoint: `${protocol}://localhost:${port}/${clientVersion}/${schemaHash}/itx/${id}`
138512
+ endpoint: `${new URL(req.url).origin}/${clientVersion}/${schemaHash}/itx/${id}`
138515
138513
  }
138516
138514
  });
138517
138515
  } catch (error) {
@@ -636,22 +636,23 @@ var apiKeyValidator = async (value, ctx) => {
636
636
  throw new HTTPException(401, { message: "Invalid API Key", cause: issues.join(", ") });
637
637
  }
638
638
  const { databaseUrl, name, shadowDatabaseUrl } = decodedAPIKey;
639
- const { name: expectedName } = ctx.get("serverState");
639
+ const expectedName = ctx.get("name");
640
+ const port = new URL(ctx.req.url).port;
640
641
  if (!name) {
641
642
  throw new HTTPException(401, {
642
- message: `Wrong API Key; The Prisma Dev server running at port ${ctx.get("port")} requires an API Key from a newer version of \`prisma dev\`. Check the "${expectedName}" server's output for the updated \`DATABASE_URL\` value.`
643
+ message: `Wrong API Key; The Prisma Dev server running at port ${port} requires an API Key from a newer version of \`prisma dev\`. Check the "${expectedName}" server's output for the updated \`DATABASE_URL\` value.`
643
644
  });
644
645
  }
645
646
  if (name !== expectedName) {
646
647
  throw new HTTPException(401, {
647
- message: `Wrong API Key; The Prisma Dev server running at port ${ctx.get("port")} is named "${expectedName}", but the API Key is for "${name}"`
648
+ message: `Wrong API Key; The Prisma Dev server running at port ${port} is named "${expectedName}", but the API Key is for "${name}"`
648
649
  });
649
650
  }
650
- const { hostname, port } = new URL(databaseUrl);
651
- const { port: expectedPort } = ctx.get("db");
652
- const { hostname: shadowHostname, port: shadowPort } = new URL(shadowDatabaseUrl);
653
- const expectedShadowPort = ctx.get("shadowDBPort");
654
- if (hostname !== "localhost" || Number(port) !== expectedPort || shadowHostname !== "localhost" || Number(shadowPort) !== expectedShadowPort) {
651
+ const { hostname: dbHostname, port: dbPort } = new URL(databaseUrl);
652
+ const { port: expectedDBPort } = ctx.get("db");
653
+ const { hostname: shadowDBHostname, port: shadowDBPort } = new URL(shadowDatabaseUrl);
654
+ const expectedShadowDBPort = ctx.get("shadowDBPort");
655
+ if (dbHostname !== "localhost" || Number(dbPort) !== expectedDBPort || shadowDBHostname !== "localhost" || Number(shadowDBPort) !== expectedShadowDBPort) {
655
656
  throw new HTTPException(401, {
656
657
  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"
657
658
  });
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  url,
22
22
  withResolvers,
23
23
  y
24
- } from "./chunk-7WBH7PZA.js";
24
+ } from "./chunk-GPGSLSD4.js";
25
25
  import {
26
26
  __commonJS,
27
27
  __require,
@@ -2264,6 +2264,7 @@ var DEFAULT_DATABASE_PORT = 51214;
2264
2264
  var DEFAULT_SERVER_PORT = 51213;
2265
2265
  var DEFAULT_SHADOW_DATABASE_PORT = 51215;
2266
2266
  var MAX_PORT = 65535;
2267
+ var ANY_PORT = 0;
2267
2268
  var NO_PORT = -Infinity;
2268
2269
  async function pickPorts(options) {
2269
2270
  const { debug: debug3, name, requestedPorts, servers } = options;
@@ -2359,7 +2360,7 @@ async function tryAnyPort(options) {
2359
2360
  }
2360
2361
  }
2361
2362
  function isPortSpecified(port) {
2362
- return port >= 0;
2363
+ return Number.isFinite(port) && port >= 0;
2363
2364
  }
2364
2365
  function extractUsedPorts(name, servers) {
2365
2366
  const portsUsedByOtherServers = {};
@@ -2493,7 +2494,9 @@ async function startDBServer(purpose, serverState) {
2493
2494
  }
2494
2495
  throw error;
2495
2496
  }
2496
- return getStartDBServerResult(purpose, serverState, { db, port, server });
2497
+ const actualPort = Number(server.getServerConn().split(":").at(1));
2498
+ serverState[purpose === "database" ? "databasePort" : "shadowDatabasePort"] = actualPort;
2499
+ return getStartDBServerResult(purpose, serverState, { db, port: actualPort, server });
2497
2500
  }
2498
2501
  function getStartDBServerResult(purpose, serverState, options) {
2499
2502
  const { debug: debug3 } = serverState;
@@ -2708,7 +2711,7 @@ async function startHTTPServer(dbServer, serverState) {
2708
2711
  if (serverState.dryRun) {
2709
2712
  return getStartHTTPServerResult(port, null);
2710
2713
  }
2711
- const app = await getApp(port, dbServer, serverState);
2714
+ const app = await getApp(dbServer, serverState);
2712
2715
  const { promise: waitReady, reject, resolve: resolve2 } = withResolvers();
2713
2716
  const { serve } = await import("@hono/node-server");
2714
2717
  const server = serve({ createServer: createServer2, fetch: app.fetch, overrideGlobalObjects: false, port }, resolve2);
@@ -2718,8 +2721,9 @@ async function startHTTPServer(dbServer, serverState) {
2718
2721
  }
2719
2722
  console.error("[Accelerate]", error);
2720
2723
  });
2721
- await waitReady;
2722
- return getStartHTTPServerResult(port, server);
2724
+ const { port: actualPort } = await waitReady;
2725
+ serverState.port = actualPort;
2726
+ return getStartHTTPServerResult(actualPort, server);
2723
2727
  }
2724
2728
  function getStartHTTPServerResult(port, server) {
2725
2729
  return {
@@ -2733,12 +2737,12 @@ function getStartHTTPServerResult(port, server) {
2733
2737
  url: `http://localhost:${port}`
2734
2738
  };
2735
2739
  }
2736
- async function getApp(port, dbServer, serverState) {
2740
+ async function getApp(dbServer, serverState) {
2737
2741
  const { debug: debug3 } = serverState;
2738
2742
  const [{ Hono }, { accelerateRoute }, { utilityRoute }] = await Promise.all([
2739
2743
  import("hono/tiny"),
2740
- import("./accelerate-5VID4BSA.js"),
2741
- import("./utility-QJR3G2JJ.js")
2744
+ import("./accelerate-J2NFNHM6.js"),
2745
+ import("./utility-GHLCRQFS.js")
2742
2746
  ]);
2743
2747
  const app = new Hono();
2744
2748
  const platform = await getPlatformModule.getPlatformInfo();
@@ -2753,12 +2757,11 @@ async function getApp(port, dbServer, serverState) {
2753
2757
  );
2754
2758
  }
2755
2759
  app.use("*", async (ctx, next) => {
2760
+ ctx.set("databaseDumpPath", serverState.databaseDumpPath);
2756
2761
  ctx.set("db", dbServer);
2757
2762
  ctx.set("debug", Boolean(debug3));
2763
+ ctx.set("name", serverState.name);
2758
2764
  ctx.set("platform", platform);
2759
- ctx.set("port", port);
2760
- ctx.set("protocol", "http");
2761
- ctx.set("serverState", serverState);
2762
2765
  ctx.set("shadowDBPort", serverState.shadowDatabasePort);
2763
2766
  return await next();
2764
2767
  });
@@ -2901,21 +2904,40 @@ ${JSON.stringify(issues, null, 2)}`);
2901
2904
  get databasePort() {
2902
2905
  return this._databasePort;
2903
2906
  }
2907
+ set databasePort(value) {
2908
+ this.#setPort("databasePort", value);
2909
+ }
2904
2910
  get port() {
2905
2911
  return this._port;
2906
2912
  }
2913
+ set port(value) {
2914
+ this.#setPort("port", value);
2915
+ }
2907
2916
  get shadowDatabasePort() {
2908
2917
  return this._shadowDatabasePort;
2909
2918
  }
2919
+ set shadowDatabasePort(value) {
2920
+ this.#setPort("shadowDatabasePort", value);
2921
+ }
2922
+ #setPort(kind, value) {
2923
+ if (value < 0 || !Number.isInteger(value)) {
2924
+ throw new Error(`Invalid port number: ${value}`);
2925
+ }
2926
+ const key = `_${kind}`;
2927
+ if (this[key] !== ANY_PORT && this[key] !== value) {
2928
+ throw new Error(`\`${kind}\` is already set to ${this[key]}, cannot change it to ${value}`);
2929
+ }
2930
+ this[key] = value;
2931
+ }
2910
2932
  };
2911
2933
  var StatelessServerState = class extends ServerState {
2912
2934
  constructor(options) {
2913
2935
  super({
2914
2936
  ...options,
2915
- databasePort: options?.databasePort,
2937
+ databasePort: options?.databasePort || ANY_PORT,
2916
2938
  persistenceMode: "stateless",
2917
- port: options?.port,
2918
- shadowDatabasePort: options?.shadowDatabasePort
2939
+ port: options?.port || ANY_PORT,
2940
+ shadowDatabasePort: options?.shadowDatabasePort || ANY_PORT
2919
2941
  });
2920
2942
  }
2921
2943
  get databaseDumpPath() {
@@ -7,14 +7,12 @@ import { StatusCodes } from "http-status-codes";
7
7
  var utilityRoute = new Hono();
8
8
  utilityRoute.post("/database/dump", async (ctx) => {
9
9
  const db = ctx.get("db");
10
- const serverState = ctx.get("serverState");
11
- await db.dump(serverState.databaseDumpPath);
12
- return ctx.json({ dumpPath: serverState.databaseDumpPath }, StatusCodes.CREATED);
10
+ const databaseDumpPath = ctx.get("databaseDumpPath");
11
+ await db.dump(databaseDumpPath);
12
+ return ctx.json({ dumpPath: databaseDumpPath }, StatusCodes.CREATED);
13
13
  });
14
14
  var _healthRoute = utilityRoute.get("/health", (ctx) => {
15
- return ctx.json({
16
- name: ctx.get("serverState").name
17
- });
15
+ return ctx.json({ name: ctx.get("name") });
18
16
  });
19
17
  export {
20
18
  utilityRoute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli-init",
3
- "version": "0.0.0-dev.202512231634",
3
+ "version": "0.0.0-dev.202512241311",
4
4
  "description": "Init CLI for Prisma",
5
5
  "type": "module",
6
6
  "sideEffects": false,