@prisma/cli-init 0.0.0-dev.202512170051 → 0.0.0-dev.202512221327

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.
Files changed (2) hide show
  1. package/dist/index.js +58 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2461,8 +2461,16 @@ async function startDBServer(purpose, serverState) {
2461
2461
  console.debug(`[${purpose}][${channel}] ${payload}`);
2462
2462
  });
2463
2463
  }
2464
- const { PGLiteSocketServer } = await import("@electric-sql/pglite-socket");
2465
- const server = new PGLiteSocketServer({ db, debug: debug3, inspect: debug3, port });
2464
+ const { PGLiteSocketHandler, PGLiteSocketServer } = await import("@electric-sql/pglite-socket");
2465
+ const idleTimeout = purpose === "shadow_database" ? serverState.shadowDatabaseIdleTimeoutMillis : serverState.databaseIdleTimeoutMillis;
2466
+ applyIdleTimeout(idleTimeout, db, PGLiteSocketHandler);
2467
+ const server = new PGLiteSocketServer({
2468
+ connectionQueueTimeout: purpose === "shadow_database" ? serverState.shadowDatabaseConnectTimeoutMillis : serverState.databaseConnectTimeoutMillis,
2469
+ db,
2470
+ debug: debug3,
2471
+ inspect: debug3,
2472
+ port
2473
+ });
2466
2474
  if (debug3) {
2467
2475
  server.addEventListener("listening", (event) => {
2468
2476
  const { detail } = event;
@@ -2619,6 +2627,46 @@ async function getExtensions() {
2619
2627
  ]);
2620
2628
  return Object.assign({}, ...importedExtensions);
2621
2629
  }
2630
+ function applyIdleTimeout(idleTimeout, db, PGLiteSocketHandlerConstructor) {
2631
+ db.__IDLE_TIMEOUT__ = idleTimeout;
2632
+ if (PGLiteSocketHandlerConstructor.prototype.__ATTACH_OVERRIDDEN__) {
2633
+ return;
2634
+ }
2635
+ const originalAttach = PGLiteSocketHandlerConstructor.prototype.attach;
2636
+ PGLiteSocketHandlerConstructor.prototype.__ATTACH_OVERRIDDEN__ = true;
2637
+ PGLiteSocketHandlerConstructor.prototype.attach = async function(socket) {
2638
+ const result = await originalAttach.call(this, socket);
2639
+ if (!Number.isFinite(this.db.__IDLE_TIMEOUT__)) {
2640
+ return result;
2641
+ }
2642
+ let idleTimeoutId = null;
2643
+ const clearIdleTimeout = () => {
2644
+ if (idleTimeoutId != null) {
2645
+ clearTimeout(idleTimeoutId);
2646
+ idleTimeoutId = null;
2647
+ }
2648
+ };
2649
+ const resetIdleTimeout = () => {
2650
+ clearIdleTimeout();
2651
+ idleTimeoutId = setTimeout(
2652
+ () => this.detach(true),
2653
+ // @ts-expect-error shhhh!
2654
+ this.db.__IDLE_TIMEOUT__
2655
+ );
2656
+ };
2657
+ socket.on("error", () => {
2658
+ clearIdleTimeout();
2659
+ });
2660
+ socket.on("data", () => {
2661
+ resetIdleTimeout();
2662
+ });
2663
+ socket.on("close", () => {
2664
+ clearIdleTimeout();
2665
+ });
2666
+ resetIdleTimeout();
2667
+ return result;
2668
+ };
2669
+ }
2622
2670
  async function dumpDB(options) {
2623
2671
  const { dataDir, db, debug: debug3, destinationPath } = options;
2624
2672
  const pg = db || await getDB(dataDir, debug3);
@@ -2767,20 +2815,28 @@ var PRIVATE_INITIALIZE_SYMBOL = Symbol("initialize");
2767
2815
  var DEFAULT_NAME = "default";
2768
2816
  var ServerState = class {
2769
2817
  _databasePort;
2818
+ databaseConnectTimeoutMillis;
2819
+ databaseIdleTimeoutMillis;
2770
2820
  debug;
2771
2821
  dryRun;
2772
2822
  name;
2773
2823
  persistenceMode;
2774
2824
  pid;
2825
+ shadowDatabaseConnectTimeoutMillis;
2826
+ shadowDatabaseIdleTimeoutMillis;
2775
2827
  _port;
2776
2828
  _shadowDatabasePort;
2777
2829
  constructor(options) {
2778
2830
  this._databasePort = options.databasePort ?? NO_PORT;
2831
+ this.databaseConnectTimeoutMillis = options.databaseConnectTimeoutMillis ?? 6e4;
2832
+ this.databaseIdleTimeoutMillis = options.databaseIdleTimeoutMillis ?? Infinity;
2779
2833
  this.debug = options.debug ?? false;
2780
2834
  this.dryRun = options.dryRun ?? false;
2781
2835
  this.name = options.name ?? DEFAULT_NAME;
2782
2836
  this.persistenceMode = options.persistenceMode;
2783
2837
  this.pid = options.pid ?? y.pid;
2838
+ this.shadowDatabaseConnectTimeoutMillis = options.shadowDatabaseConnectTimeoutMillis ?? this.databaseConnectTimeoutMillis;
2839
+ this.shadowDatabaseIdleTimeoutMillis = options.shadowDatabaseIdleTimeoutMillis ?? this.databaseIdleTimeoutMillis;
2784
2840
  this._port = options.port ?? NO_PORT;
2785
2841
  this._shadowDatabasePort = options.shadowDatabasePort ?? NO_PORT;
2786
2842
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/cli-init",
3
- "version": "0.0.0-dev.202512170051",
3
+ "version": "0.0.0-dev.202512221327",
4
4
  "description": "Init CLI for Prisma",
5
5
  "type": "module",
6
6
  "sideEffects": false,