@prisma/cli-init 0.0.0-dev.202512240027 → 0.0.0-dev.202512241337

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 = {};
@@ -2378,6 +2379,9 @@ function extractUsedPorts(name, servers) {
2378
2379
  }
2379
2380
  async function assertPickablePort(options) {
2380
2381
  const { debug: debug3, otherRequestedPorts, portKey, portsUsedByOtherServers, requestedPort } = options;
2382
+ if (requestedPort === ANY_PORT) {
2383
+ return;
2384
+ }
2381
2385
  if (requestedPort in portsUsedByOtherServers) {
2382
2386
  if (debug3) {
2383
2387
  console.error(`Port ${requestedPort} was requested for "${portKey}", but is already used by another server.`);
@@ -2493,7 +2497,9 @@ async function startDBServer(purpose, serverState) {
2493
2497
  }
2494
2498
  throw error;
2495
2499
  }
2496
- return getStartDBServerResult(purpose, serverState, { db, port, server });
2500
+ const actualPort = Number(server.getServerConn().split(":").at(1));
2501
+ serverState[purpose === "database" ? "databasePort" : "shadowDatabasePort"] = actualPort;
2502
+ return getStartDBServerResult(purpose, serverState, { db, port: actualPort, server });
2497
2503
  }
2498
2504
  function getStartDBServerResult(purpose, serverState, options) {
2499
2505
  const { debug: debug3 } = serverState;
@@ -2708,7 +2714,7 @@ async function startHTTPServer(dbServer, serverState) {
2708
2714
  if (serverState.dryRun) {
2709
2715
  return getStartHTTPServerResult(port, null);
2710
2716
  }
2711
- const app = await getApp(port, dbServer, serverState);
2717
+ const app = await getApp(dbServer, serverState);
2712
2718
  const { promise: waitReady, reject, resolve: resolve2 } = withResolvers();
2713
2719
  const { serve } = await import("@hono/node-server");
2714
2720
  const server = serve({ createServer: createServer2, fetch: app.fetch, overrideGlobalObjects: false, port }, resolve2);
@@ -2718,8 +2724,9 @@ async function startHTTPServer(dbServer, serverState) {
2718
2724
  }
2719
2725
  console.error("[Accelerate]", error);
2720
2726
  });
2721
- await waitReady;
2722
- return getStartHTTPServerResult(port, server);
2727
+ const { port: actualPort } = await waitReady;
2728
+ serverState.port = actualPort;
2729
+ return getStartHTTPServerResult(actualPort, server);
2723
2730
  }
2724
2731
  function getStartHTTPServerResult(port, server) {
2725
2732
  return {
@@ -2733,12 +2740,12 @@ function getStartHTTPServerResult(port, server) {
2733
2740
  url: `http://localhost:${port}`
2734
2741
  };
2735
2742
  }
2736
- async function getApp(port, dbServer, serverState) {
2743
+ async function getApp(dbServer, serverState) {
2737
2744
  const { debug: debug3 } = serverState;
2738
2745
  const [{ Hono }, { accelerateRoute }, { utilityRoute }] = await Promise.all([
2739
2746
  import("hono/tiny"),
2740
- import("./accelerate-5VID4BSA.js"),
2741
- import("./utility-QJR3G2JJ.js")
2747
+ import("./accelerate-J2NFNHM6.js"),
2748
+ import("./utility-GHLCRQFS.js")
2742
2749
  ]);
2743
2750
  const app = new Hono();
2744
2751
  const platform = await getPlatformModule.getPlatformInfo();
@@ -2753,12 +2760,11 @@ async function getApp(port, dbServer, serverState) {
2753
2760
  );
2754
2761
  }
2755
2762
  app.use("*", async (ctx, next) => {
2763
+ ctx.set("databaseDumpPath", serverState.databaseDumpPath);
2756
2764
  ctx.set("db", dbServer);
2757
2765
  ctx.set("debug", Boolean(debug3));
2766
+ ctx.set("name", serverState.name);
2758
2767
  ctx.set("platform", platform);
2759
- ctx.set("port", port);
2760
- ctx.set("protocol", "http");
2761
- ctx.set("serverState", serverState);
2762
2768
  ctx.set("shadowDBPort", serverState.shadowDatabasePort);
2763
2769
  return await next();
2764
2770
  });
@@ -2901,21 +2907,40 @@ ${JSON.stringify(issues, null, 2)}`);
2901
2907
  get databasePort() {
2902
2908
  return this._databasePort;
2903
2909
  }
2910
+ set databasePort(value) {
2911
+ this.#setPort("databasePort", value);
2912
+ }
2904
2913
  get port() {
2905
2914
  return this._port;
2906
2915
  }
2916
+ set port(value) {
2917
+ this.#setPort("port", value);
2918
+ }
2907
2919
  get shadowDatabasePort() {
2908
2920
  return this._shadowDatabasePort;
2909
2921
  }
2922
+ set shadowDatabasePort(value) {
2923
+ this.#setPort("shadowDatabasePort", value);
2924
+ }
2925
+ #setPort(kind, value) {
2926
+ if (value < 0 || !Number.isInteger(value)) {
2927
+ throw new Error(`Invalid port number: ${value}`);
2928
+ }
2929
+ const key = `_${kind}`;
2930
+ if (this[key] !== ANY_PORT && this[key] !== value) {
2931
+ throw new Error(`\`${kind}\` is already set to ${this[key]}, cannot change it to ${value}`);
2932
+ }
2933
+ this[key] = value;
2934
+ }
2910
2935
  };
2911
2936
  var StatelessServerState = class extends ServerState {
2912
2937
  constructor(options) {
2913
2938
  super({
2914
2939
  ...options,
2915
- databasePort: options?.databasePort,
2940
+ databasePort: options?.databasePort || ANY_PORT,
2916
2941
  persistenceMode: "stateless",
2917
- port: options?.port,
2918
- shadowDatabasePort: options?.shadowDatabasePort
2942
+ port: options?.port || ANY_PORT,
2943
+ shadowDatabasePort: options?.shadowDatabasePort || ANY_PORT
2919
2944
  });
2920
2945
  }
2921
2946
  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.202512240027",
3
+ "version": "0.0.0-dev.202512241337",
4
4
  "description": "Init CLI for Prisma",
5
5
  "type": "module",
6
6
  "sideEffects": false,