@prisma/cli-init 0.0.0-dev.202512170049 → 0.0.0-dev.202512221324
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.js +60 -3
- 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
|
|
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;
|
|
@@ -2558,7 +2566,7 @@ async function getDB(dataDir, debug3) {
|
|
|
2558
2566
|
}
|
|
2559
2567
|
async function getShadowDB(_dataDir, debug3) {
|
|
2560
2568
|
const { PGlite } = await import("@electric-sql/pglite");
|
|
2561
|
-
|
|
2569
|
+
const db = await PGlite.create({
|
|
2562
2570
|
database: BASE_PGLITE_OPTIONS.database,
|
|
2563
2571
|
dataDir: "memory://",
|
|
2564
2572
|
debug: debug3 ? 5 : void 0,
|
|
@@ -2566,6 +2574,7 @@ async function getShadowDB(_dataDir, debug3) {
|
|
|
2566
2574
|
relaxedDurability: false,
|
|
2567
2575
|
username: BASE_PGLITE_OPTIONS.username
|
|
2568
2576
|
});
|
|
2577
|
+
return db;
|
|
2569
2578
|
}
|
|
2570
2579
|
async function getExtensions() {
|
|
2571
2580
|
const importedExtensions = await Promise.all([
|
|
@@ -2619,6 +2628,46 @@ async function getExtensions() {
|
|
|
2619
2628
|
]);
|
|
2620
2629
|
return Object.assign({}, ...importedExtensions);
|
|
2621
2630
|
}
|
|
2631
|
+
function applyIdleTimeout(idleTimeout, db, PGLiteSocketHandlerConstructor) {
|
|
2632
|
+
db.__IDLE_TIMEOUT__ = idleTimeout;
|
|
2633
|
+
if (PGLiteSocketHandlerConstructor.prototype.__ATTACH_OVERRIDDEN__) {
|
|
2634
|
+
return;
|
|
2635
|
+
}
|
|
2636
|
+
const originalAttach = PGLiteSocketHandlerConstructor.prototype.attach;
|
|
2637
|
+
PGLiteSocketHandlerConstructor.prototype.__ATTACH_OVERRIDDEN__ = true;
|
|
2638
|
+
PGLiteSocketHandlerConstructor.prototype.attach = async function(socket) {
|
|
2639
|
+
const result = await originalAttach.call(this, socket);
|
|
2640
|
+
if (!Number.isFinite(this.db.__IDLE_TIMEOUT__)) {
|
|
2641
|
+
return result;
|
|
2642
|
+
}
|
|
2643
|
+
let idleTimeoutId = null;
|
|
2644
|
+
const clearIdleTimeout = () => {
|
|
2645
|
+
if (idleTimeoutId != null) {
|
|
2646
|
+
clearTimeout(idleTimeoutId);
|
|
2647
|
+
idleTimeoutId = null;
|
|
2648
|
+
}
|
|
2649
|
+
};
|
|
2650
|
+
const resetIdleTimeout = () => {
|
|
2651
|
+
clearIdleTimeout();
|
|
2652
|
+
idleTimeoutId = setTimeout(
|
|
2653
|
+
() => this.detach(true),
|
|
2654
|
+
// @ts-expect-error shhhh!
|
|
2655
|
+
this.db.__IDLE_TIMEOUT__
|
|
2656
|
+
);
|
|
2657
|
+
};
|
|
2658
|
+
socket.on("error", () => {
|
|
2659
|
+
clearIdleTimeout();
|
|
2660
|
+
});
|
|
2661
|
+
socket.on("data", () => {
|
|
2662
|
+
resetIdleTimeout();
|
|
2663
|
+
});
|
|
2664
|
+
socket.on("close", () => {
|
|
2665
|
+
clearIdleTimeout();
|
|
2666
|
+
});
|
|
2667
|
+
resetIdleTimeout();
|
|
2668
|
+
return result;
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2622
2671
|
async function dumpDB(options) {
|
|
2623
2672
|
const { dataDir, db, debug: debug3, destinationPath } = options;
|
|
2624
2673
|
const pg = db || await getDB(dataDir, debug3);
|
|
@@ -2767,20 +2816,28 @@ var PRIVATE_INITIALIZE_SYMBOL = Symbol("initialize");
|
|
|
2767
2816
|
var DEFAULT_NAME = "default";
|
|
2768
2817
|
var ServerState = class {
|
|
2769
2818
|
_databasePort;
|
|
2819
|
+
databaseConnectTimeoutMillis;
|
|
2820
|
+
databaseIdleTimeoutMillis;
|
|
2770
2821
|
debug;
|
|
2771
2822
|
dryRun;
|
|
2772
2823
|
name;
|
|
2773
2824
|
persistenceMode;
|
|
2774
2825
|
pid;
|
|
2826
|
+
shadowDatabaseConnectTimeoutMillis;
|
|
2827
|
+
shadowDatabaseIdleTimeoutMillis;
|
|
2775
2828
|
_port;
|
|
2776
2829
|
_shadowDatabasePort;
|
|
2777
2830
|
constructor(options) {
|
|
2778
2831
|
this._databasePort = options.databasePort ?? NO_PORT;
|
|
2832
|
+
this.databaseConnectTimeoutMillis = options.databaseConnectTimeoutMillis ?? 6e4;
|
|
2833
|
+
this.databaseIdleTimeoutMillis = options.databaseIdleTimeoutMillis ?? Infinity;
|
|
2779
2834
|
this.debug = options.debug ?? false;
|
|
2780
2835
|
this.dryRun = options.dryRun ?? false;
|
|
2781
2836
|
this.name = options.name ?? DEFAULT_NAME;
|
|
2782
2837
|
this.persistenceMode = options.persistenceMode;
|
|
2783
2838
|
this.pid = options.pid ?? y.pid;
|
|
2839
|
+
this.shadowDatabaseConnectTimeoutMillis = options.shadowDatabaseConnectTimeoutMillis ?? this.databaseConnectTimeoutMillis;
|
|
2840
|
+
this.shadowDatabaseIdleTimeoutMillis = options.shadowDatabaseIdleTimeoutMillis ?? this.databaseIdleTimeoutMillis;
|
|
2784
2841
|
this._port = options.port ?? NO_PORT;
|
|
2785
2842
|
this._shadowDatabasePort = options.shadowDatabasePort ?? NO_PORT;
|
|
2786
2843
|
}
|