@prisma/composer-cli 0.30.0 → 0.31.0-dev.1

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 (34) hide show
  1. package/dist/container-transport-HcvNOGZL-CIoZc7Rs.mjs +34 -0
  2. package/dist/container-transport-HcvNOGZL-CIoZc7Rs.mjs.map +1 -0
  3. package/dist/{dev-CqS1W82b-BF0YJc6a.mjs → dev-current-Bm7Yrsmt-TadtLg5x.mjs} +24 -5
  4. package/dist/dev-current-Bm7Yrsmt-TadtLg5x.mjs.map +1 -0
  5. package/dist/dist-j4X7U5yA.mjs +1788 -0
  6. package/dist/dist-j4X7U5yA.mjs.map +1 -0
  7. package/dist/{execute-deploy-destroy-D4UdieU1-C1P6X7uK.mjs → execute-deploy-destroy-BK4R2qCX-DU6ITsO0.mjs} +5 -4
  8. package/dist/execute-deploy-destroy-BK4R2qCX-DU6ITsO0.mjs.map +1 -0
  9. package/dist/execute-dev-current-nYH8EiKK-BcP2HhlW.mjs +126 -0
  10. package/dist/execute-dev-current-nYH8EiKK-BcP2HhlW.mjs.map +1 -0
  11. package/dist/{execute-dev-BSPnsEv--SNELmzE_.mjs → execute-dev-qKlYePGn-B3UnMfa5.mjs} +50 -65
  12. package/dist/execute-dev-qKlYePGn-B3UnMfa5.mjs.map +1 -0
  13. package/dist/{family-Dt7BgpVf-YyjGLli3.d.mts → family-BIyR33Uq-BEqJM2Vx.d.mts} +131 -29
  14. package/dist/family-BIyR33Uq-BEqJM2Vx.d.mts.map +1 -0
  15. package/dist/family.d.mts +47 -3
  16. package/dist/family.d.mts.map +1 -1
  17. package/dist/family.mjs +210 -9
  18. package/dist/family.mjs.map +1 -1
  19. package/dist/local-target-DZ6bu7Aj.mjs +48 -0
  20. package/dist/local-target-DZ6bu7Aj.mjs.map +1 -0
  21. package/dist/{container-transport-HcvNOGZL-ClGmzBIO.mjs → pipeline-Dpesfd2j-DKL3f1bj.mjs} +17 -39
  22. package/dist/pipeline-Dpesfd2j-DKL3f1bj.mjs.map +1 -0
  23. package/dist/testing.d.mts +7 -1
  24. package/dist/testing.d.mts.map +1 -1
  25. package/dist/testing.mjs +23 -2
  26. package/dist/testing.mjs.map +1 -1
  27. package/package.json +9 -5
  28. package/src/exports/family.ts +29 -0
  29. package/src/family/emulator-list.ts +112 -0
  30. package/dist/container-transport-HcvNOGZL-ClGmzBIO.mjs.map +0 -1
  31. package/dist/dev-CqS1W82b-BF0YJc6a.mjs.map +0 -1
  32. package/dist/execute-deploy-destroy-D4UdieU1-C1P6X7uK.mjs.map +0 -1
  33. package/dist/execute-dev-BSPnsEv--SNELmzE_.mjs.map +0 -1
  34. package/dist/family-Dt7BgpVf-YyjGLli3.d.mts.map +0 -1
@@ -0,0 +1,1788 @@
1
+ import { d as ok, l as CliStructuredError, u as notOk } from "./composer-config-CY9fET8H-CgnpfWc2.mjs";
2
+ import { createRequire } from "node:module";
3
+ import * as fs from "node:fs";
4
+ import * as path from "node:path";
5
+ import "node:url";
6
+ import "node:crypto";
7
+ import * as fs$1 from "node:fs/promises";
8
+ import * as os from "node:os";
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
10
+ var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
11
+ //#endregion
12
+ //#region ../../../node_modules/graceful-fs/polyfills.js
13
+ var require_polyfills = /* @__PURE__ */ __commonJSMin(((exports, module) => {
14
+ var constants = __require("constants");
15
+ var origCwd = process.cwd;
16
+ var cwd = null;
17
+ var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
18
+ process.cwd = function() {
19
+ if (!cwd) cwd = origCwd.call(process);
20
+ return cwd;
21
+ };
22
+ try {
23
+ process.cwd();
24
+ } catch (er) {}
25
+ if (typeof process.chdir === "function") {
26
+ var chdir = process.chdir;
27
+ process.chdir = function(d) {
28
+ cwd = null;
29
+ chdir.call(process, d);
30
+ };
31
+ if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
32
+ }
33
+ module.exports = patch;
34
+ function patch(fs) {
35
+ if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) patchLchmod(fs);
36
+ if (!fs.lutimes) patchLutimes(fs);
37
+ fs.chown = chownFix(fs.chown);
38
+ fs.fchown = chownFix(fs.fchown);
39
+ fs.lchown = chownFix(fs.lchown);
40
+ fs.chmod = chmodFix(fs.chmod);
41
+ fs.fchmod = chmodFix(fs.fchmod);
42
+ fs.lchmod = chmodFix(fs.lchmod);
43
+ fs.chownSync = chownFixSync(fs.chownSync);
44
+ fs.fchownSync = chownFixSync(fs.fchownSync);
45
+ fs.lchownSync = chownFixSync(fs.lchownSync);
46
+ fs.chmodSync = chmodFixSync(fs.chmodSync);
47
+ fs.fchmodSync = chmodFixSync(fs.fchmodSync);
48
+ fs.lchmodSync = chmodFixSync(fs.lchmodSync);
49
+ fs.stat = statFix(fs.stat);
50
+ fs.fstat = statFix(fs.fstat);
51
+ fs.lstat = statFix(fs.lstat);
52
+ fs.statSync = statFixSync(fs.statSync);
53
+ fs.fstatSync = statFixSync(fs.fstatSync);
54
+ fs.lstatSync = statFixSync(fs.lstatSync);
55
+ if (fs.chmod && !fs.lchmod) {
56
+ fs.lchmod = function(path, mode, cb) {
57
+ if (cb) process.nextTick(cb);
58
+ };
59
+ fs.lchmodSync = function() {};
60
+ }
61
+ if (fs.chown && !fs.lchown) {
62
+ fs.lchown = function(path, uid, gid, cb) {
63
+ if (cb) process.nextTick(cb);
64
+ };
65
+ fs.lchownSync = function() {};
66
+ }
67
+ if (platform === "win32") fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
68
+ function rename(from, to, cb) {
69
+ var start = Date.now();
70
+ var backoff = 0;
71
+ fs$rename(from, to, function CB(er) {
72
+ if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
73
+ setTimeout(function() {
74
+ fs.stat(to, function(stater, st) {
75
+ if (stater && stater.code === "ENOENT") fs$rename(from, to, CB);
76
+ else cb(er);
77
+ });
78
+ }, backoff);
79
+ if (backoff < 100) backoff += 10;
80
+ return;
81
+ }
82
+ if (cb) cb(er);
83
+ });
84
+ }
85
+ if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
86
+ return rename;
87
+ })(fs.rename);
88
+ fs.read = typeof fs.read !== "function" ? fs.read : (function(fs$read) {
89
+ function read(fd, buffer, offset, length, position, callback_) {
90
+ var callback;
91
+ if (callback_ && typeof callback_ === "function") {
92
+ var eagCounter = 0;
93
+ callback = function(er, _, __) {
94
+ if (er && er.code === "EAGAIN" && eagCounter < 10) {
95
+ eagCounter++;
96
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
97
+ }
98
+ callback_.apply(this, arguments);
99
+ };
100
+ }
101
+ return fs$read.call(fs, fd, buffer, offset, length, position, callback);
102
+ }
103
+ if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
104
+ return read;
105
+ })(fs.read);
106
+ fs.readSync = typeof fs.readSync !== "function" ? fs.readSync : (function(fs$readSync) {
107
+ return function(fd, buffer, offset, length, position) {
108
+ var eagCounter = 0;
109
+ while (true) try {
110
+ return fs$readSync.call(fs, fd, buffer, offset, length, position);
111
+ } catch (er) {
112
+ if (er.code === "EAGAIN" && eagCounter < 10) {
113
+ eagCounter++;
114
+ continue;
115
+ }
116
+ throw er;
117
+ }
118
+ };
119
+ })(fs.readSync);
120
+ function patchLchmod(fs) {
121
+ fs.lchmod = function(path, mode, callback) {
122
+ fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, mode, function(err, fd) {
123
+ if (err) {
124
+ if (callback) callback(err);
125
+ return;
126
+ }
127
+ fs.fchmod(fd, mode, function(err) {
128
+ fs.close(fd, function(err2) {
129
+ if (callback) callback(err || err2);
130
+ });
131
+ });
132
+ });
133
+ };
134
+ fs.lchmodSync = function(path, mode) {
135
+ var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
136
+ var threw = true;
137
+ var ret;
138
+ try {
139
+ ret = fs.fchmodSync(fd, mode);
140
+ threw = false;
141
+ } finally {
142
+ if (threw) try {
143
+ fs.closeSync(fd);
144
+ } catch (er) {}
145
+ else fs.closeSync(fd);
146
+ }
147
+ return ret;
148
+ };
149
+ }
150
+ function patchLutimes(fs) {
151
+ if (constants.hasOwnProperty("O_SYMLINK") && fs.futimes) {
152
+ fs.lutimes = function(path, at, mt, cb) {
153
+ fs.open(path, constants.O_SYMLINK, function(er, fd) {
154
+ if (er) {
155
+ if (cb) cb(er);
156
+ return;
157
+ }
158
+ fs.futimes(fd, at, mt, function(er) {
159
+ fs.close(fd, function(er2) {
160
+ if (cb) cb(er || er2);
161
+ });
162
+ });
163
+ });
164
+ };
165
+ fs.lutimesSync = function(path, at, mt) {
166
+ var fd = fs.openSync(path, constants.O_SYMLINK);
167
+ var ret;
168
+ var threw = true;
169
+ try {
170
+ ret = fs.futimesSync(fd, at, mt);
171
+ threw = false;
172
+ } finally {
173
+ if (threw) try {
174
+ fs.closeSync(fd);
175
+ } catch (er) {}
176
+ else fs.closeSync(fd);
177
+ }
178
+ return ret;
179
+ };
180
+ } else if (fs.futimes) {
181
+ fs.lutimes = function(_a, _b, _c, cb) {
182
+ if (cb) process.nextTick(cb);
183
+ };
184
+ fs.lutimesSync = function() {};
185
+ }
186
+ }
187
+ function chmodFix(orig) {
188
+ if (!orig) return orig;
189
+ return function(target, mode, cb) {
190
+ return orig.call(fs, target, mode, function(er) {
191
+ if (chownErOk(er)) er = null;
192
+ if (cb) cb.apply(this, arguments);
193
+ });
194
+ };
195
+ }
196
+ function chmodFixSync(orig) {
197
+ if (!orig) return orig;
198
+ return function(target, mode) {
199
+ try {
200
+ return orig.call(fs, target, mode);
201
+ } catch (er) {
202
+ if (!chownErOk(er)) throw er;
203
+ }
204
+ };
205
+ }
206
+ function chownFix(orig) {
207
+ if (!orig) return orig;
208
+ return function(target, uid, gid, cb) {
209
+ return orig.call(fs, target, uid, gid, function(er) {
210
+ if (chownErOk(er)) er = null;
211
+ if (cb) cb.apply(this, arguments);
212
+ });
213
+ };
214
+ }
215
+ function chownFixSync(orig) {
216
+ if (!orig) return orig;
217
+ return function(target, uid, gid) {
218
+ try {
219
+ return orig.call(fs, target, uid, gid);
220
+ } catch (er) {
221
+ if (!chownErOk(er)) throw er;
222
+ }
223
+ };
224
+ }
225
+ function statFix(orig) {
226
+ if (!orig) return orig;
227
+ return function(target, options, cb) {
228
+ if (typeof options === "function") {
229
+ cb = options;
230
+ options = null;
231
+ }
232
+ function callback(er, stats) {
233
+ if (stats) {
234
+ if (stats.uid < 0) stats.uid += 4294967296;
235
+ if (stats.gid < 0) stats.gid += 4294967296;
236
+ }
237
+ if (cb) cb.apply(this, arguments);
238
+ }
239
+ return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
240
+ };
241
+ }
242
+ function statFixSync(orig) {
243
+ if (!orig) return orig;
244
+ return function(target, options) {
245
+ var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
246
+ if (stats) {
247
+ if (stats.uid < 0) stats.uid += 4294967296;
248
+ if (stats.gid < 0) stats.gid += 4294967296;
249
+ }
250
+ return stats;
251
+ };
252
+ }
253
+ function chownErOk(er) {
254
+ if (!er) return true;
255
+ if (er.code === "ENOSYS") return true;
256
+ if (!process.getuid || process.getuid() !== 0) {
257
+ if (er.code === "EINVAL" || er.code === "EPERM") return true;
258
+ }
259
+ return false;
260
+ }
261
+ }
262
+ }));
263
+ //#endregion
264
+ //#region ../../../node_modules/graceful-fs/legacy-streams.js
265
+ var require_legacy_streams = /* @__PURE__ */ __commonJSMin(((exports, module) => {
266
+ var Stream = __require("stream").Stream;
267
+ module.exports = legacy;
268
+ function legacy(fs) {
269
+ return {
270
+ ReadStream,
271
+ WriteStream
272
+ };
273
+ function ReadStream(path, options) {
274
+ if (!(this instanceof ReadStream)) return new ReadStream(path, options);
275
+ Stream.call(this);
276
+ var self = this;
277
+ this.path = path;
278
+ this.fd = null;
279
+ this.readable = true;
280
+ this.paused = false;
281
+ this.flags = "r";
282
+ this.mode = 438;
283
+ this.bufferSize = 64 * 1024;
284
+ options = options || {};
285
+ var keys = Object.keys(options);
286
+ for (var index = 0, length = keys.length; index < length; index++) {
287
+ var key = keys[index];
288
+ this[key] = options[key];
289
+ }
290
+ if (this.encoding) this.setEncoding(this.encoding);
291
+ if (this.start !== void 0) {
292
+ if ("number" !== typeof this.start) throw TypeError("start must be a Number");
293
+ if (this.end === void 0) this.end = Infinity;
294
+ else if ("number" !== typeof this.end) throw TypeError("end must be a Number");
295
+ if (this.start > this.end) throw new Error("start must be <= end");
296
+ this.pos = this.start;
297
+ }
298
+ if (this.fd !== null) {
299
+ process.nextTick(function() {
300
+ self._read();
301
+ });
302
+ return;
303
+ }
304
+ fs.open(this.path, this.flags, this.mode, function(err, fd) {
305
+ if (err) {
306
+ self.emit("error", err);
307
+ self.readable = false;
308
+ return;
309
+ }
310
+ self.fd = fd;
311
+ self.emit("open", fd);
312
+ self._read();
313
+ });
314
+ }
315
+ function WriteStream(path, options) {
316
+ if (!(this instanceof WriteStream)) return new WriteStream(path, options);
317
+ Stream.call(this);
318
+ this.path = path;
319
+ this.fd = null;
320
+ this.writable = true;
321
+ this.flags = "w";
322
+ this.encoding = "binary";
323
+ this.mode = 438;
324
+ this.bytesWritten = 0;
325
+ options = options || {};
326
+ var keys = Object.keys(options);
327
+ for (var index = 0, length = keys.length; index < length; index++) {
328
+ var key = keys[index];
329
+ this[key] = options[key];
330
+ }
331
+ if (this.start !== void 0) {
332
+ if ("number" !== typeof this.start) throw TypeError("start must be a Number");
333
+ if (this.start < 0) throw new Error("start must be >= zero");
334
+ this.pos = this.start;
335
+ }
336
+ this.busy = false;
337
+ this._queue = [];
338
+ if (this.fd === null) {
339
+ this._open = fs.open;
340
+ this._queue.push([
341
+ this._open,
342
+ this.path,
343
+ this.flags,
344
+ this.mode,
345
+ void 0
346
+ ]);
347
+ this.flush();
348
+ }
349
+ }
350
+ }
351
+ }));
352
+ //#endregion
353
+ //#region ../../../node_modules/graceful-fs/clone.js
354
+ var require_clone = /* @__PURE__ */ __commonJSMin(((exports, module) => {
355
+ module.exports = clone;
356
+ var getPrototypeOf = Object.getPrototypeOf || function(obj) {
357
+ return obj.__proto__;
358
+ };
359
+ function clone(obj) {
360
+ if (obj === null || typeof obj !== "object") return obj;
361
+ if (obj instanceof Object) var copy = { __proto__: getPrototypeOf(obj) };
362
+ else var copy = Object.create(null);
363
+ Object.getOwnPropertyNames(obj).forEach(function(key) {
364
+ Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
365
+ });
366
+ return copy;
367
+ }
368
+ }));
369
+ //#endregion
370
+ //#region ../../../node_modules/graceful-fs/graceful-fs.js
371
+ var require_graceful_fs = /* @__PURE__ */ __commonJSMin(((exports, module) => {
372
+ var fs$2 = __require("fs");
373
+ var polyfills = require_polyfills();
374
+ var legacy = require_legacy_streams();
375
+ var clone = require_clone();
376
+ var util = __require("util");
377
+ /* istanbul ignore next - node 0.x polyfill */
378
+ var gracefulQueue;
379
+ var previousSymbol;
380
+ /* istanbul ignore else - node 0.x polyfill */
381
+ if (typeof Symbol === "function" && typeof Symbol.for === "function") {
382
+ gracefulQueue = Symbol.for("graceful-fs.queue");
383
+ previousSymbol = Symbol.for("graceful-fs.previous");
384
+ } else {
385
+ gracefulQueue = "___graceful-fs.queue";
386
+ previousSymbol = "___graceful-fs.previous";
387
+ }
388
+ function noop() {}
389
+ function publishQueue(context, queue) {
390
+ Object.defineProperty(context, gracefulQueue, { get: function() {
391
+ return queue;
392
+ } });
393
+ }
394
+ var debug = noop;
395
+ if (util.debuglog) debug = util.debuglog("gfs4");
396
+ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) debug = function() {
397
+ var m = util.format.apply(util, arguments);
398
+ m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
399
+ console.error(m);
400
+ };
401
+ if (!fs$2[gracefulQueue]) {
402
+ publishQueue(fs$2, global[gracefulQueue] || []);
403
+ fs$2.close = (function(fs$close) {
404
+ function close(fd, cb) {
405
+ return fs$close.call(fs$2, fd, function(err) {
406
+ if (!err) resetQueue();
407
+ if (typeof cb === "function") cb.apply(this, arguments);
408
+ });
409
+ }
410
+ Object.defineProperty(close, previousSymbol, { value: fs$close });
411
+ return close;
412
+ })(fs$2.close);
413
+ fs$2.closeSync = (function(fs$closeSync) {
414
+ function closeSync(fd) {
415
+ fs$closeSync.apply(fs$2, arguments);
416
+ resetQueue();
417
+ }
418
+ Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync });
419
+ return closeSync;
420
+ })(fs$2.closeSync);
421
+ if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) process.on("exit", function() {
422
+ debug(fs$2[gracefulQueue]);
423
+ __require("assert").equal(fs$2[gracefulQueue].length, 0);
424
+ });
425
+ }
426
+ if (!global[gracefulQueue]) publishQueue(global, fs$2[gracefulQueue]);
427
+ module.exports = patch(clone(fs$2));
428
+ if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs$2.__patched) {
429
+ module.exports = patch(fs$2);
430
+ fs$2.__patched = true;
431
+ }
432
+ function patch(fs) {
433
+ polyfills(fs);
434
+ fs.gracefulify = patch;
435
+ fs.createReadStream = createReadStream;
436
+ fs.createWriteStream = createWriteStream;
437
+ var fs$readFile = fs.readFile;
438
+ fs.readFile = readFile;
439
+ function readFile(path, options, cb) {
440
+ if (typeof options === "function") cb = options, options = null;
441
+ return go$readFile(path, options, cb);
442
+ function go$readFile(path, options, cb, startTime) {
443
+ return fs$readFile(path, options, function(err) {
444
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
445
+ go$readFile,
446
+ [
447
+ path,
448
+ options,
449
+ cb
450
+ ],
451
+ err,
452
+ startTime || Date.now(),
453
+ Date.now()
454
+ ]);
455
+ else if (typeof cb === "function") cb.apply(this, arguments);
456
+ });
457
+ }
458
+ }
459
+ var fs$writeFile = fs.writeFile;
460
+ fs.writeFile = writeFile;
461
+ function writeFile(path, data, options, cb) {
462
+ if (typeof options === "function") cb = options, options = null;
463
+ return go$writeFile(path, data, options, cb);
464
+ function go$writeFile(path, data, options, cb, startTime) {
465
+ return fs$writeFile(path, data, options, function(err) {
466
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
467
+ go$writeFile,
468
+ [
469
+ path,
470
+ data,
471
+ options,
472
+ cb
473
+ ],
474
+ err,
475
+ startTime || Date.now(),
476
+ Date.now()
477
+ ]);
478
+ else if (typeof cb === "function") cb.apply(this, arguments);
479
+ });
480
+ }
481
+ }
482
+ var fs$appendFile = fs.appendFile;
483
+ if (fs$appendFile) fs.appendFile = appendFile;
484
+ function appendFile(path, data, options, cb) {
485
+ if (typeof options === "function") cb = options, options = null;
486
+ return go$appendFile(path, data, options, cb);
487
+ function go$appendFile(path, data, options, cb, startTime) {
488
+ return fs$appendFile(path, data, options, function(err) {
489
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
490
+ go$appendFile,
491
+ [
492
+ path,
493
+ data,
494
+ options,
495
+ cb
496
+ ],
497
+ err,
498
+ startTime || Date.now(),
499
+ Date.now()
500
+ ]);
501
+ else if (typeof cb === "function") cb.apply(this, arguments);
502
+ });
503
+ }
504
+ }
505
+ var fs$copyFile = fs.copyFile;
506
+ if (fs$copyFile) fs.copyFile = copyFile;
507
+ function copyFile(src, dest, flags, cb) {
508
+ if (typeof flags === "function") {
509
+ cb = flags;
510
+ flags = 0;
511
+ }
512
+ return go$copyFile(src, dest, flags, cb);
513
+ function go$copyFile(src, dest, flags, cb, startTime) {
514
+ return fs$copyFile(src, dest, flags, function(err) {
515
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
516
+ go$copyFile,
517
+ [
518
+ src,
519
+ dest,
520
+ flags,
521
+ cb
522
+ ],
523
+ err,
524
+ startTime || Date.now(),
525
+ Date.now()
526
+ ]);
527
+ else if (typeof cb === "function") cb.apply(this, arguments);
528
+ });
529
+ }
530
+ }
531
+ var fs$readdir = fs.readdir;
532
+ fs.readdir = readdir;
533
+ var noReaddirOptionVersions = /^v[0-5]\./;
534
+ function readdir(path, options, cb) {
535
+ if (typeof options === "function") cb = options, options = null;
536
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir(path, options, cb, startTime) {
537
+ return fs$readdir(path, fs$readdirCallback(path, options, cb, startTime));
538
+ } : function go$readdir(path, options, cb, startTime) {
539
+ return fs$readdir(path, options, fs$readdirCallback(path, options, cb, startTime));
540
+ };
541
+ return go$readdir(path, options, cb);
542
+ function fs$readdirCallback(path, options, cb, startTime) {
543
+ return function(err, files) {
544
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
545
+ go$readdir,
546
+ [
547
+ path,
548
+ options,
549
+ cb
550
+ ],
551
+ err,
552
+ startTime || Date.now(),
553
+ Date.now()
554
+ ]);
555
+ else {
556
+ if (files && files.sort) files.sort();
557
+ if (typeof cb === "function") cb.call(this, err, files);
558
+ }
559
+ };
560
+ }
561
+ }
562
+ if (process.version.substr(0, 4) === "v0.8") {
563
+ var legStreams = legacy(fs);
564
+ ReadStream = legStreams.ReadStream;
565
+ WriteStream = legStreams.WriteStream;
566
+ }
567
+ var fs$ReadStream = fs.ReadStream;
568
+ if (fs$ReadStream) {
569
+ ReadStream.prototype = Object.create(fs$ReadStream.prototype);
570
+ ReadStream.prototype.open = ReadStream$open;
571
+ }
572
+ var fs$WriteStream = fs.WriteStream;
573
+ if (fs$WriteStream) {
574
+ WriteStream.prototype = Object.create(fs$WriteStream.prototype);
575
+ WriteStream.prototype.open = WriteStream$open;
576
+ }
577
+ Object.defineProperty(fs, "ReadStream", {
578
+ get: function() {
579
+ return ReadStream;
580
+ },
581
+ set: function(val) {
582
+ ReadStream = val;
583
+ },
584
+ enumerable: true,
585
+ configurable: true
586
+ });
587
+ Object.defineProperty(fs, "WriteStream", {
588
+ get: function() {
589
+ return WriteStream;
590
+ },
591
+ set: function(val) {
592
+ WriteStream = val;
593
+ },
594
+ enumerable: true,
595
+ configurable: true
596
+ });
597
+ var FileReadStream = ReadStream;
598
+ Object.defineProperty(fs, "FileReadStream", {
599
+ get: function() {
600
+ return FileReadStream;
601
+ },
602
+ set: function(val) {
603
+ FileReadStream = val;
604
+ },
605
+ enumerable: true,
606
+ configurable: true
607
+ });
608
+ var FileWriteStream = WriteStream;
609
+ Object.defineProperty(fs, "FileWriteStream", {
610
+ get: function() {
611
+ return FileWriteStream;
612
+ },
613
+ set: function(val) {
614
+ FileWriteStream = val;
615
+ },
616
+ enumerable: true,
617
+ configurable: true
618
+ });
619
+ function ReadStream(path, options) {
620
+ if (this instanceof ReadStream) return fs$ReadStream.apply(this, arguments), this;
621
+ else return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
622
+ }
623
+ function ReadStream$open() {
624
+ var that = this;
625
+ open(that.path, that.flags, that.mode, function(err, fd) {
626
+ if (err) {
627
+ if (that.autoClose) that.destroy();
628
+ that.emit("error", err);
629
+ } else {
630
+ that.fd = fd;
631
+ that.emit("open", fd);
632
+ that.read();
633
+ }
634
+ });
635
+ }
636
+ function WriteStream(path, options) {
637
+ if (this instanceof WriteStream) return fs$WriteStream.apply(this, arguments), this;
638
+ else return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
639
+ }
640
+ function WriteStream$open() {
641
+ var that = this;
642
+ open(that.path, that.flags, that.mode, function(err, fd) {
643
+ if (err) {
644
+ that.destroy();
645
+ that.emit("error", err);
646
+ } else {
647
+ that.fd = fd;
648
+ that.emit("open", fd);
649
+ }
650
+ });
651
+ }
652
+ function createReadStream(path, options) {
653
+ return new fs.ReadStream(path, options);
654
+ }
655
+ function createWriteStream(path, options) {
656
+ return new fs.WriteStream(path, options);
657
+ }
658
+ var fs$open = fs.open;
659
+ fs.open = open;
660
+ function open(path, flags, mode, cb) {
661
+ if (typeof mode === "function") cb = mode, mode = null;
662
+ return go$open(path, flags, mode, cb);
663
+ function go$open(path, flags, mode, cb, startTime) {
664
+ return fs$open(path, flags, mode, function(err, fd) {
665
+ if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([
666
+ go$open,
667
+ [
668
+ path,
669
+ flags,
670
+ mode,
671
+ cb
672
+ ],
673
+ err,
674
+ startTime || Date.now(),
675
+ Date.now()
676
+ ]);
677
+ else if (typeof cb === "function") cb.apply(this, arguments);
678
+ });
679
+ }
680
+ }
681
+ return fs;
682
+ }
683
+ function enqueue(elem) {
684
+ debug("ENQUEUE", elem[0].name, elem[1]);
685
+ fs$2[gracefulQueue].push(elem);
686
+ retry();
687
+ }
688
+ var retryTimer;
689
+ function resetQueue() {
690
+ var now = Date.now();
691
+ for (var i = 0; i < fs$2[gracefulQueue].length; ++i) if (fs$2[gracefulQueue][i].length > 2) {
692
+ fs$2[gracefulQueue][i][3] = now;
693
+ fs$2[gracefulQueue][i][4] = now;
694
+ }
695
+ retry();
696
+ }
697
+ function retry() {
698
+ clearTimeout(retryTimer);
699
+ retryTimer = void 0;
700
+ if (fs$2[gracefulQueue].length === 0) return;
701
+ var elem = fs$2[gracefulQueue].shift();
702
+ var fn = elem[0];
703
+ var args = elem[1];
704
+ var err = elem[2];
705
+ var startTime = elem[3];
706
+ var lastTime = elem[4];
707
+ if (startTime === void 0) {
708
+ debug("RETRY", fn.name, args);
709
+ fn.apply(null, args);
710
+ } else if (Date.now() - startTime >= 6e4) {
711
+ debug("TIMEOUT", fn.name, args);
712
+ var cb = args.pop();
713
+ if (typeof cb === "function") cb.call(null, err);
714
+ } else {
715
+ var sinceAttempt = Date.now() - lastTime;
716
+ var sinceStart = Math.max(lastTime - startTime, 1);
717
+ if (sinceAttempt >= Math.min(sinceStart * 1.2, 100)) {
718
+ debug("RETRY", fn.name, args);
719
+ fn.apply(null, args.concat([startTime]));
720
+ } else fs$2[gracefulQueue].push(elem);
721
+ }
722
+ if (retryTimer === void 0) retryTimer = setTimeout(retry, 0);
723
+ }
724
+ }));
725
+ //#endregion
726
+ //#region ../../../node_modules/retry/lib/retry_operation.js
727
+ var require_retry_operation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
728
+ function RetryOperation(timeouts, options) {
729
+ if (typeof options === "boolean") options = { forever: options };
730
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
731
+ this._timeouts = timeouts;
732
+ this._options = options || {};
733
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
734
+ this._fn = null;
735
+ this._errors = [];
736
+ this._attempts = 1;
737
+ this._operationTimeout = null;
738
+ this._operationTimeoutCb = null;
739
+ this._timeout = null;
740
+ this._operationStart = null;
741
+ if (this._options.forever) this._cachedTimeouts = this._timeouts.slice(0);
742
+ }
743
+ module.exports = RetryOperation;
744
+ RetryOperation.prototype.reset = function() {
745
+ this._attempts = 1;
746
+ this._timeouts = this._originalTimeouts;
747
+ };
748
+ RetryOperation.prototype.stop = function() {
749
+ if (this._timeout) clearTimeout(this._timeout);
750
+ this._timeouts = [];
751
+ this._cachedTimeouts = null;
752
+ };
753
+ RetryOperation.prototype.retry = function(err) {
754
+ if (this._timeout) clearTimeout(this._timeout);
755
+ if (!err) return false;
756
+ var currentTime = (/* @__PURE__ */ new Date()).getTime();
757
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
758
+ this._errors.unshift(/* @__PURE__ */ new Error("RetryOperation timeout occurred"));
759
+ return false;
760
+ }
761
+ this._errors.push(err);
762
+ var timeout = this._timeouts.shift();
763
+ if (timeout === void 0) if (this._cachedTimeouts) {
764
+ this._errors.splice(this._errors.length - 1, this._errors.length);
765
+ this._timeouts = this._cachedTimeouts.slice(0);
766
+ timeout = this._timeouts.shift();
767
+ } else return false;
768
+ var self = this;
769
+ var timer = setTimeout(function() {
770
+ self._attempts++;
771
+ if (self._operationTimeoutCb) {
772
+ self._timeout = setTimeout(function() {
773
+ self._operationTimeoutCb(self._attempts);
774
+ }, self._operationTimeout);
775
+ if (self._options.unref) self._timeout.unref();
776
+ }
777
+ self._fn(self._attempts);
778
+ }, timeout);
779
+ if (this._options.unref) timer.unref();
780
+ return true;
781
+ };
782
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
783
+ this._fn = fn;
784
+ if (timeoutOps) {
785
+ if (timeoutOps.timeout) this._operationTimeout = timeoutOps.timeout;
786
+ if (timeoutOps.cb) this._operationTimeoutCb = timeoutOps.cb;
787
+ }
788
+ var self = this;
789
+ if (this._operationTimeoutCb) this._timeout = setTimeout(function() {
790
+ self._operationTimeoutCb();
791
+ }, self._operationTimeout);
792
+ this._operationStart = (/* @__PURE__ */ new Date()).getTime();
793
+ this._fn(this._attempts);
794
+ };
795
+ RetryOperation.prototype.try = function(fn) {
796
+ console.log("Using RetryOperation.try() is deprecated");
797
+ this.attempt(fn);
798
+ };
799
+ RetryOperation.prototype.start = function(fn) {
800
+ console.log("Using RetryOperation.start() is deprecated");
801
+ this.attempt(fn);
802
+ };
803
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
804
+ RetryOperation.prototype.errors = function() {
805
+ return this._errors;
806
+ };
807
+ RetryOperation.prototype.attempts = function() {
808
+ return this._attempts;
809
+ };
810
+ RetryOperation.prototype.mainError = function() {
811
+ if (this._errors.length === 0) return null;
812
+ var counts = {};
813
+ var mainError = null;
814
+ var mainErrorCount = 0;
815
+ for (var i = 0; i < this._errors.length; i++) {
816
+ var error = this._errors[i];
817
+ var message = error.message;
818
+ var count = (counts[message] || 0) + 1;
819
+ counts[message] = count;
820
+ if (count >= mainErrorCount) {
821
+ mainError = error;
822
+ mainErrorCount = count;
823
+ }
824
+ }
825
+ return mainError;
826
+ };
827
+ }));
828
+ //#endregion
829
+ //#region ../../../node_modules/retry/lib/retry.js
830
+ var require_retry$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
831
+ var RetryOperation = require_retry_operation();
832
+ exports.operation = function(options) {
833
+ return new RetryOperation(exports.timeouts(options), {
834
+ forever: options && options.forever,
835
+ unref: options && options.unref,
836
+ maxRetryTime: options && options.maxRetryTime
837
+ });
838
+ };
839
+ exports.timeouts = function(options) {
840
+ if (options instanceof Array) return [].concat(options);
841
+ var opts = {
842
+ retries: 10,
843
+ factor: 2,
844
+ minTimeout: 1 * 1e3,
845
+ maxTimeout: Infinity,
846
+ randomize: false
847
+ };
848
+ for (var key in options) opts[key] = options[key];
849
+ if (opts.minTimeout > opts.maxTimeout) throw new Error("minTimeout is greater than maxTimeout");
850
+ var timeouts = [];
851
+ for (var i = 0; i < opts.retries; i++) timeouts.push(this.createTimeout(i, opts));
852
+ if (options && options.forever && !timeouts.length) timeouts.push(this.createTimeout(i, opts));
853
+ timeouts.sort(function(a, b) {
854
+ return a - b;
855
+ });
856
+ return timeouts;
857
+ };
858
+ exports.createTimeout = function(attempt, opts) {
859
+ var random = opts.randomize ? Math.random() + 1 : 1;
860
+ var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
861
+ timeout = Math.min(timeout, opts.maxTimeout);
862
+ return timeout;
863
+ };
864
+ exports.wrap = function(obj, options, methods) {
865
+ if (options instanceof Array) {
866
+ methods = options;
867
+ options = null;
868
+ }
869
+ if (!methods) {
870
+ methods = [];
871
+ for (var key in obj) if (typeof obj[key] === "function") methods.push(key);
872
+ }
873
+ for (var i = 0; i < methods.length; i++) {
874
+ var method = methods[i];
875
+ var original = obj[method];
876
+ obj[method] = function retryWrapper(original) {
877
+ var op = exports.operation(options);
878
+ var args = Array.prototype.slice.call(arguments, 1);
879
+ var callback = args.pop();
880
+ args.push(function(err) {
881
+ if (op.retry(err)) return;
882
+ if (err) arguments[0] = op.mainError();
883
+ callback.apply(this, arguments);
884
+ });
885
+ op.attempt(function() {
886
+ original.apply(obj, args);
887
+ });
888
+ }.bind(obj, original);
889
+ obj[method].options = options;
890
+ }
891
+ };
892
+ }));
893
+ //#endregion
894
+ //#region ../../../node_modules/retry/index.js
895
+ var require_retry = /* @__PURE__ */ __commonJSMin(((exports, module) => {
896
+ module.exports = require_retry$1();
897
+ }));
898
+ //#endregion
899
+ //#region ../../../node_modules/proper-lockfile/node_modules/signal-exit/signals.js
900
+ var require_signals = /* @__PURE__ */ __commonJSMin(((exports, module) => {
901
+ module.exports = [
902
+ "SIGABRT",
903
+ "SIGALRM",
904
+ "SIGHUP",
905
+ "SIGINT",
906
+ "SIGTERM"
907
+ ];
908
+ if (process.platform !== "win32") module.exports.push("SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
909
+ if (process.platform === "linux") module.exports.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT", "SIGUNUSED");
910
+ }));
911
+ //#endregion
912
+ //#region ../../../node_modules/proper-lockfile/node_modules/signal-exit/index.js
913
+ var require_signal_exit = /* @__PURE__ */ __commonJSMin(((exports, module) => {
914
+ var process = global.process;
915
+ const processOk = function(process) {
916
+ return process && typeof process === "object" && typeof process.removeListener === "function" && typeof process.emit === "function" && typeof process.reallyExit === "function" && typeof process.listeners === "function" && typeof process.kill === "function" && typeof process.pid === "number" && typeof process.on === "function";
917
+ };
918
+ /* istanbul ignore if */
919
+ if (!processOk(process)) module.exports = function() {
920
+ return function() {};
921
+ };
922
+ else {
923
+ var assert = __require("assert");
924
+ var signals = require_signals();
925
+ var isWin = /^win/i.test(process.platform);
926
+ var EE = __require("events");
927
+ /* istanbul ignore if */
928
+ if (typeof EE !== "function") EE = EE.EventEmitter;
929
+ var emitter;
930
+ if (process.__signal_exit_emitter__) emitter = process.__signal_exit_emitter__;
931
+ else {
932
+ emitter = process.__signal_exit_emitter__ = new EE();
933
+ emitter.count = 0;
934
+ emitter.emitted = {};
935
+ }
936
+ if (!emitter.infinite) {
937
+ emitter.setMaxListeners(Infinity);
938
+ emitter.infinite = true;
939
+ }
940
+ module.exports = function(cb, opts) {
941
+ /* istanbul ignore if */
942
+ if (!processOk(global.process)) return function() {};
943
+ assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
944
+ if (loaded === false) load();
945
+ var ev = "exit";
946
+ if (opts && opts.alwaysLast) ev = "afterexit";
947
+ var remove = function() {
948
+ emitter.removeListener(ev, cb);
949
+ if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) unload();
950
+ };
951
+ emitter.on(ev, cb);
952
+ return remove;
953
+ };
954
+ var unload = function unload() {
955
+ if (!loaded || !processOk(global.process)) return;
956
+ loaded = false;
957
+ signals.forEach(function(sig) {
958
+ try {
959
+ process.removeListener(sig, sigListeners[sig]);
960
+ } catch (er) {}
961
+ });
962
+ process.emit = originalProcessEmit;
963
+ process.reallyExit = originalProcessReallyExit;
964
+ emitter.count -= 1;
965
+ };
966
+ module.exports.unload = unload;
967
+ var emit = function emit(event, code, signal) {
968
+ /* istanbul ignore if */
969
+ if (emitter.emitted[event]) return;
970
+ emitter.emitted[event] = true;
971
+ emitter.emit(event, code, signal);
972
+ };
973
+ var sigListeners = {};
974
+ signals.forEach(function(sig) {
975
+ sigListeners[sig] = function listener() {
976
+ /* istanbul ignore if */
977
+ if (!processOk(global.process)) return;
978
+ if (process.listeners(sig).length === emitter.count) {
979
+ unload();
980
+ emit("exit", null, sig);
981
+ /* istanbul ignore next */
982
+ emit("afterexit", null, sig);
983
+ /* istanbul ignore next */
984
+ if (isWin && sig === "SIGHUP") sig = "SIGINT";
985
+ /* istanbul ignore next */
986
+ process.kill(process.pid, sig);
987
+ }
988
+ };
989
+ });
990
+ module.exports.signals = function() {
991
+ return signals;
992
+ };
993
+ var loaded = false;
994
+ var load = function load() {
995
+ if (loaded || !processOk(global.process)) return;
996
+ loaded = true;
997
+ emitter.count += 1;
998
+ signals = signals.filter(function(sig) {
999
+ try {
1000
+ process.on(sig, sigListeners[sig]);
1001
+ return true;
1002
+ } catch (er) {
1003
+ return false;
1004
+ }
1005
+ });
1006
+ process.emit = processEmit;
1007
+ process.reallyExit = processReallyExit;
1008
+ };
1009
+ module.exports.load = load;
1010
+ var originalProcessReallyExit = process.reallyExit;
1011
+ var processReallyExit = function processReallyExit(code) {
1012
+ /* istanbul ignore if */
1013
+ if (!processOk(global.process)) return;
1014
+ process.exitCode = code || 0;
1015
+ emit("exit", process.exitCode, null);
1016
+ /* istanbul ignore next */
1017
+ emit("afterexit", process.exitCode, null);
1018
+ /* istanbul ignore next */
1019
+ originalProcessReallyExit.call(process, process.exitCode);
1020
+ };
1021
+ var originalProcessEmit = process.emit;
1022
+ var processEmit = function processEmit(ev, arg) {
1023
+ if (ev === "exit" && processOk(global.process)) {
1024
+ /* istanbul ignore else */
1025
+ if (arg !== void 0) process.exitCode = arg;
1026
+ var ret = originalProcessEmit.apply(this, arguments);
1027
+ /* istanbul ignore next */
1028
+ emit("exit", process.exitCode, null);
1029
+ /* istanbul ignore next */
1030
+ emit("afterexit", process.exitCode, null);
1031
+ /* istanbul ignore next */
1032
+ return ret;
1033
+ } else return originalProcessEmit.apply(this, arguments);
1034
+ };
1035
+ }
1036
+ }));
1037
+ //#endregion
1038
+ //#region ../../../node_modules/proper-lockfile/lib/mtime-precision.js
1039
+ var require_mtime_precision = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1040
+ const cacheSymbol = Symbol();
1041
+ function probe(file, fs, callback) {
1042
+ const cachedPrecision = fs[cacheSymbol];
1043
+ if (cachedPrecision) return fs.stat(file, (err, stat) => {
1044
+ /* istanbul ignore if */
1045
+ if (err) return callback(err);
1046
+ callback(null, stat.mtime, cachedPrecision);
1047
+ });
1048
+ const mtime = /* @__PURE__ */ new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
1049
+ fs.utimes(file, mtime, mtime, (err) => {
1050
+ /* istanbul ignore if */
1051
+ if (err) return callback(err);
1052
+ fs.stat(file, (err, stat) => {
1053
+ /* istanbul ignore if */
1054
+ if (err) return callback(err);
1055
+ const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
1056
+ Object.defineProperty(fs, cacheSymbol, { value: precision });
1057
+ callback(null, stat.mtime, precision);
1058
+ });
1059
+ });
1060
+ }
1061
+ function getMtime(precision) {
1062
+ let now = Date.now();
1063
+ if (precision === "s") now = Math.ceil(now / 1e3) * 1e3;
1064
+ return new Date(now);
1065
+ }
1066
+ module.exports.probe = probe;
1067
+ module.exports.getMtime = getMtime;
1068
+ }));
1069
+ //#endregion
1070
+ //#region ../../../node_modules/proper-lockfile/lib/lockfile.js
1071
+ var require_lockfile = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1072
+ const path$1 = __require("path");
1073
+ const fs = require_graceful_fs();
1074
+ const retry = require_retry();
1075
+ const onExit = require_signal_exit();
1076
+ const mtimePrecision = require_mtime_precision();
1077
+ const locks = {};
1078
+ function getLockFile(file, options) {
1079
+ return options.lockfilePath || `${file}.lock`;
1080
+ }
1081
+ function resolveCanonicalPath(file, options, callback) {
1082
+ if (!options.realpath) return callback(null, path$1.resolve(file));
1083
+ options.fs.realpath(file, callback);
1084
+ }
1085
+ function acquireLock(file, options, callback) {
1086
+ const lockfilePath = getLockFile(file, options);
1087
+ options.fs.mkdir(lockfilePath, (err) => {
1088
+ if (!err) return mtimePrecision.probe(lockfilePath, options.fs, (err, mtime, mtimePrecision) => {
1089
+ /* istanbul ignore if */
1090
+ if (err) {
1091
+ options.fs.rmdir(lockfilePath, () => {});
1092
+ return callback(err);
1093
+ }
1094
+ callback(null, mtime, mtimePrecision);
1095
+ });
1096
+ if (err.code !== "EEXIST") return callback(err);
1097
+ if (options.stale <= 0) return callback(Object.assign(/* @__PURE__ */ new Error("Lock file is already being held"), {
1098
+ code: "ELOCKED",
1099
+ file
1100
+ }));
1101
+ options.fs.stat(lockfilePath, (err, stat) => {
1102
+ if (err) {
1103
+ if (err.code === "ENOENT") return acquireLock(file, {
1104
+ ...options,
1105
+ stale: 0
1106
+ }, callback);
1107
+ return callback(err);
1108
+ }
1109
+ if (!isLockStale(stat, options)) return callback(Object.assign(/* @__PURE__ */ new Error("Lock file is already being held"), {
1110
+ code: "ELOCKED",
1111
+ file
1112
+ }));
1113
+ removeLock(file, options, (err) => {
1114
+ if (err) return callback(err);
1115
+ acquireLock(file, {
1116
+ ...options,
1117
+ stale: 0
1118
+ }, callback);
1119
+ });
1120
+ });
1121
+ });
1122
+ }
1123
+ function isLockStale(stat, options) {
1124
+ return stat.mtime.getTime() < Date.now() - options.stale;
1125
+ }
1126
+ function removeLock(file, options, callback) {
1127
+ options.fs.rmdir(getLockFile(file, options), (err) => {
1128
+ if (err && err.code !== "ENOENT") return callback(err);
1129
+ callback();
1130
+ });
1131
+ }
1132
+ function updateLock(file, options) {
1133
+ const lock = locks[file];
1134
+ /* istanbul ignore if */
1135
+ if (lock.updateTimeout) return;
1136
+ lock.updateDelay = lock.updateDelay || options.update;
1137
+ lock.updateTimeout = setTimeout(() => {
1138
+ lock.updateTimeout = null;
1139
+ options.fs.stat(lock.lockfilePath, (err, stat) => {
1140
+ const isOverThreshold = lock.lastUpdate + options.stale < Date.now();
1141
+ if (err) {
1142
+ if (err.code === "ENOENT" || isOverThreshold) return setLockAsCompromised(file, lock, Object.assign(err, { code: "ECOMPROMISED" }));
1143
+ lock.updateDelay = 1e3;
1144
+ return updateLock(file, options);
1145
+ }
1146
+ if (!(lock.mtime.getTime() === stat.mtime.getTime())) return setLockAsCompromised(file, lock, Object.assign(/* @__PURE__ */ new Error("Unable to update lock within the stale threshold"), { code: "ECOMPROMISED" }));
1147
+ const mtime = mtimePrecision.getMtime(lock.mtimePrecision);
1148
+ options.fs.utimes(lock.lockfilePath, mtime, mtime, (err) => {
1149
+ const isOverThreshold = lock.lastUpdate + options.stale < Date.now();
1150
+ if (lock.released) return;
1151
+ if (err) {
1152
+ if (err.code === "ENOENT" || isOverThreshold) return setLockAsCompromised(file, lock, Object.assign(err, { code: "ECOMPROMISED" }));
1153
+ lock.updateDelay = 1e3;
1154
+ return updateLock(file, options);
1155
+ }
1156
+ lock.mtime = mtime;
1157
+ lock.lastUpdate = Date.now();
1158
+ lock.updateDelay = null;
1159
+ updateLock(file, options);
1160
+ });
1161
+ });
1162
+ }, lock.updateDelay);
1163
+ /* istanbul ignore else */
1164
+ if (lock.updateTimeout.unref) lock.updateTimeout.unref();
1165
+ }
1166
+ function setLockAsCompromised(file, lock, err) {
1167
+ lock.released = true;
1168
+ /* istanbul ignore if */
1169
+ if (lock.updateTimeout) clearTimeout(lock.updateTimeout);
1170
+ if (locks[file] === lock) delete locks[file];
1171
+ lock.options.onCompromised(err);
1172
+ }
1173
+ function lock(file, options, callback) {
1174
+ /* istanbul ignore next */
1175
+ options = {
1176
+ stale: 1e4,
1177
+ update: null,
1178
+ realpath: true,
1179
+ retries: 0,
1180
+ fs,
1181
+ onCompromised: (err) => {
1182
+ throw err;
1183
+ },
1184
+ ...options
1185
+ };
1186
+ options.retries = options.retries || 0;
1187
+ options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
1188
+ options.stale = Math.max(options.stale || 0, 2e3);
1189
+ options.update = options.update == null ? options.stale / 2 : options.update || 0;
1190
+ options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
1191
+ resolveCanonicalPath(file, options, (err, file) => {
1192
+ if (err) return callback(err);
1193
+ const operation = retry.operation(options.retries);
1194
+ operation.attempt(() => {
1195
+ acquireLock(file, options, (err, mtime, mtimePrecision) => {
1196
+ if (operation.retry(err)) return;
1197
+ if (err) return callback(operation.mainError());
1198
+ const lock = locks[file] = {
1199
+ lockfilePath: getLockFile(file, options),
1200
+ mtime,
1201
+ mtimePrecision,
1202
+ options,
1203
+ lastUpdate: Date.now()
1204
+ };
1205
+ updateLock(file, options);
1206
+ callback(null, (releasedCallback) => {
1207
+ if (lock.released) return releasedCallback && releasedCallback(Object.assign(/* @__PURE__ */ new Error("Lock is already released"), { code: "ERELEASED" }));
1208
+ unlock(file, {
1209
+ ...options,
1210
+ realpath: false
1211
+ }, releasedCallback);
1212
+ });
1213
+ });
1214
+ });
1215
+ });
1216
+ }
1217
+ function unlock(file, options, callback) {
1218
+ options = {
1219
+ fs,
1220
+ realpath: true,
1221
+ ...options
1222
+ };
1223
+ resolveCanonicalPath(file, options, (err, file) => {
1224
+ if (err) return callback(err);
1225
+ const lock = locks[file];
1226
+ if (!lock) return callback(Object.assign(/* @__PURE__ */ new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
1227
+ lock.updateTimeout && clearTimeout(lock.updateTimeout);
1228
+ lock.released = true;
1229
+ delete locks[file];
1230
+ removeLock(file, options, callback);
1231
+ });
1232
+ }
1233
+ function check(file, options, callback) {
1234
+ options = {
1235
+ stale: 1e4,
1236
+ realpath: true,
1237
+ fs,
1238
+ ...options
1239
+ };
1240
+ options.stale = Math.max(options.stale || 0, 2e3);
1241
+ resolveCanonicalPath(file, options, (err, file) => {
1242
+ if (err) return callback(err);
1243
+ options.fs.stat(getLockFile(file, options), (err, stat) => {
1244
+ if (err) return err.code === "ENOENT" ? callback(null, false) : callback(err);
1245
+ return callback(null, !isLockStale(stat, options));
1246
+ });
1247
+ });
1248
+ }
1249
+ function getLocks() {
1250
+ return locks;
1251
+ }
1252
+ /* istanbul ignore next */
1253
+ onExit(() => {
1254
+ for (const file in locks) {
1255
+ const options = locks[file].options;
1256
+ try {
1257
+ options.fs.rmdirSync(getLockFile(file, options));
1258
+ } catch (e) {}
1259
+ }
1260
+ });
1261
+ module.exports.lock = lock;
1262
+ module.exports.unlock = unlock;
1263
+ module.exports.check = check;
1264
+ module.exports.getLocks = getLocks;
1265
+ }));
1266
+ //#endregion
1267
+ //#region ../../../node_modules/proper-lockfile/lib/adapter.js
1268
+ var require_adapter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
1269
+ const fs = require_graceful_fs();
1270
+ function createSyncFs(fs) {
1271
+ const methods = [
1272
+ "mkdir",
1273
+ "realpath",
1274
+ "stat",
1275
+ "rmdir",
1276
+ "utimes"
1277
+ ];
1278
+ const newFs = { ...fs };
1279
+ methods.forEach((method) => {
1280
+ newFs[method] = (...args) => {
1281
+ const callback = args.pop();
1282
+ let ret;
1283
+ try {
1284
+ ret = fs[`${method}Sync`](...args);
1285
+ } catch (err) {
1286
+ return callback(err);
1287
+ }
1288
+ callback(null, ret);
1289
+ };
1290
+ });
1291
+ return newFs;
1292
+ }
1293
+ function toPromise(method) {
1294
+ return (...args) => new Promise((resolve, reject) => {
1295
+ args.push((err, result) => {
1296
+ if (err) reject(err);
1297
+ else resolve(result);
1298
+ });
1299
+ method(...args);
1300
+ });
1301
+ }
1302
+ function toSync(method) {
1303
+ return (...args) => {
1304
+ let err;
1305
+ let result;
1306
+ args.push((_err, _result) => {
1307
+ err = _err;
1308
+ result = _result;
1309
+ });
1310
+ method(...args);
1311
+ if (err) throw err;
1312
+ return result;
1313
+ };
1314
+ }
1315
+ function toSyncOptions(options) {
1316
+ options = { ...options };
1317
+ options.fs = createSyncFs(options.fs || fs);
1318
+ if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) throw Object.assign(/* @__PURE__ */ new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
1319
+ return options;
1320
+ }
1321
+ module.exports = {
1322
+ toPromise,
1323
+ toSync,
1324
+ toSyncOptions
1325
+ };
1326
+ }));
1327
+ (/* @__PURE__ */ __commonJSMin(((exports, module) => {
1328
+ const lockfile = require_lockfile();
1329
+ const { toPromise, toSync, toSyncOptions } = require_adapter();
1330
+ async function lock(file, options) {
1331
+ const release = await toPromise(lockfile.lock)(file, options);
1332
+ return toPromise(release);
1333
+ }
1334
+ function lockSync(file, options) {
1335
+ const release = toSync(lockfile.lock)(file, toSyncOptions(options));
1336
+ return toSync(release);
1337
+ }
1338
+ function unlock(file, options) {
1339
+ return toPromise(lockfile.unlock)(file, options);
1340
+ }
1341
+ function unlockSync(file, options) {
1342
+ return toSync(lockfile.unlock)(file, toSyncOptions(options));
1343
+ }
1344
+ function check(file, options) {
1345
+ return toPromise(lockfile.check)(file, options);
1346
+ }
1347
+ function checkSync(file, options) {
1348
+ return toSync(lockfile.check)(file, toSyncOptions(options));
1349
+ }
1350
+ module.exports = lock;
1351
+ module.exports.lock = lock;
1352
+ module.exports.unlock = unlock;
1353
+ module.exports.lockSync = lockSync;
1354
+ module.exports.unlockSync = unlockSync;
1355
+ module.exports.check = check;
1356
+ module.exports.checkSync = checkSync;
1357
+ })))();
1358
+ function isEnoent$1(err) {
1359
+ return err instanceof Error && "code" in err && err.code === "ENOENT";
1360
+ }
1361
+ /**
1362
+ * Reads and parses a JSON state file, narrowing the parsed value with
1363
+ * `isValid` (a real type predicate, not a cast — the file's shape is only
1364
+ * trustworthy because this daemon is its only writer, but a foreign or
1365
+ * corrupt file on disk must not be treated as valid state). `undefined` when
1366
+ * absent, unreadable, or shaped wrong.
1367
+ */
1368
+ async function readJsonFile(filePath, isValid) {
1369
+ let raw;
1370
+ try {
1371
+ raw = await fs$1.readFile(filePath, "utf8");
1372
+ } catch (err) {
1373
+ if (isEnoent$1(err)) return void 0;
1374
+ throw err;
1375
+ }
1376
+ let parsed;
1377
+ try {
1378
+ parsed = JSON.parse(raw);
1379
+ } catch {
1380
+ return;
1381
+ }
1382
+ return isValid(parsed) ? parsed : void 0;
1383
+ }
1384
+ function isErrnoException(err) {
1385
+ return err instanceof Error && "code" in err;
1386
+ }
1387
+ function isRegistryEntry$1(value) {
1388
+ return typeof value === "object" && value !== null && "pid" in value && typeof value.pid === "number" && "port" in value && typeof value.port === "number" && "version" in value && typeof value.version === "string" && "logPath" in value && typeof value.logPath === "string";
1389
+ }
1390
+ /** The environment variable that names the emulator registry root. */
1391
+ const EMULATORS_DIR_ENV = "PRISMA_COMPOSER_EMULATORS_DIR";
1392
+ /** `registryRoot`'s default: `$PRISMA_COMPOSER_EMULATORS_DIR` (an absolute path, normalised) when set, else `~/.prisma-composer/emulators/`. */
1393
+ function defaultRegistryRoot() {
1394
+ const dir = process.env[EMULATORS_DIR_ENV];
1395
+ if (dir === void 0 || dir === "") return path.join(os.homedir(), ".prisma-composer", "emulators");
1396
+ if (!path.isAbsolute(dir)) throw new CliStructuredError("DEV.EMULATORS_DIR_INVALID", `${EMULATORS_DIR_ENV} must be an absolute path; got "${dir}".`, {
1397
+ why: "Every process that starts or reaches the local emulators resolves this directory, and a relative path would name a different one in each working directory.",
1398
+ fix: `Set ${EMULATORS_DIR_ENV} to an absolute path (\`~\` is not expanded), or unset it to use ~/.prisma-composer/emulators.`,
1399
+ meta: {
1400
+ variable: EMULATORS_DIR_ENV,
1401
+ value: dir
1402
+ }
1403
+ });
1404
+ return path.resolve(dir);
1405
+ }
1406
+ /** `<registryRoot>/<name>.json`. */
1407
+ function registryFilePath(registryRoot, name) {
1408
+ return path.join(registryRoot, `${name}.json`);
1409
+ }
1410
+ /** `process.kill(pid, 0)` existence probe — true unless the pid is provably gone (ESRCH). */
1411
+ function isPidAlive(pid) {
1412
+ try {
1413
+ process.kill(pid, 0);
1414
+ return true;
1415
+ } catch (err) {
1416
+ if (isErrnoException(err) && err.code === "EPERM") return true;
1417
+ return false;
1418
+ }
1419
+ }
1420
+ async function readRegistryEntry(registryRoot, name) {
1421
+ return readJsonFile(registryFilePath(registryRoot, name), isRegistryEntry$1);
1422
+ }
1423
+ //#endregion
1424
+ //#region ../../1-prisma-cloud/0-lowering/dev-emulators/dist/index.mjs
1425
+ /**
1426
+ * Typed loopback clients for both emulator daemons (local-dev spec § 2),
1427
+ * resolving the running daemon's port from the registry. Used by the local
1428
+ * providers and the extension's `emulators`/`attach`/`teardown`
1429
+ * implementations, which never learn an emulator's HTTP API directly.
1430
+ */
1431
+ function notRunningError(name) {
1432
+ return /* @__PURE__ */ new Error(`the ${name} emulator is not running — \`prisma dev\` starts it via the extension's dev.emulators hook.`);
1433
+ }
1434
+ function isRegistryEntry(value) {
1435
+ return typeof value === "object" && value !== null && "pid" in value && typeof value.pid === "number" && "port" in value && typeof value.port === "number";
1436
+ }
1437
+ /** Synchronous resolve — reading a small local JSON file needs no await, and every consumer wants a ready-to-use client object, not a promise. */
1438
+ function resolveBaseUrl(name, opts) {
1439
+ const file = registryFilePath(opts.registryRoot ?? defaultRegistryRoot(), name);
1440
+ let raw;
1441
+ try {
1442
+ raw = fs.readFileSync(file, "utf8");
1443
+ } catch {
1444
+ throw notRunningError(name);
1445
+ }
1446
+ let parsed;
1447
+ try {
1448
+ parsed = JSON.parse(raw);
1449
+ } catch {
1450
+ throw notRunningError(name);
1451
+ }
1452
+ if (!isRegistryEntry(parsed) || !isPidAlive(parsed.pid)) throw notRunningError(name);
1453
+ return `http://127.0.0.1:${parsed.port}`;
1454
+ }
1455
+ const ADMIN_FETCH_ATTEMPTS = 3;
1456
+ const ADMIN_FETCH_RETRY_DELAY_MS = 150;
1457
+ /**
1458
+ * `fetch` for the loopback admin calls, retried on transient socket errors:
1459
+ * a keep-alive reuse race (the runtime re-uses a pooled connection the
1460
+ * daemon's HTTP server just closed idle — surfaces as "fetch failed" /
1461
+ * "other side closed") or a briefly overloaded daemon. A short blind retry is
1462
+ * safe only for an idempotent call; a call that is not, such as creating an
1463
+ * instance, passes `retry: false`, because the emulator may have handled the
1464
+ * first attempt. A caller-driven abort is never retried. When every attempt
1465
+ * fails to connect, it throws `DEV.EMULATOR_UNREACHABLE`; callers retry that
1466
+ * code and nothing else.
1467
+ */
1468
+ async function adminFetch(url, init, opts = {}) {
1469
+ const attempts = opts.retry === false ? 1 : ADMIN_FETCH_ATTEMPTS;
1470
+ let lastError;
1471
+ for (let attempt = 1; attempt <= attempts; attempt += 1) try {
1472
+ return await fetch(url, init);
1473
+ } catch (error) {
1474
+ if (init?.signal?.aborted === true) throw error;
1475
+ lastError = error;
1476
+ if (attempt < attempts) await new Promise((resolve) => setTimeout(resolve, ADMIN_FETCH_RETRY_DELAY_MS));
1477
+ }
1478
+ throw new CliStructuredError("DEV.EMULATOR_UNREACHABLE", `Could not connect to the local dev emulator at ${new URL(url).origin}: ${lastError instanceof Error ? lastError.message : String(lastError)}`, {
1479
+ why: "The emulator is registered and its process is alive, but it did not accept the connection.",
1480
+ fix: "Run the command again. If it keeps failing, end the emulator's process; the next `prisma dev` starts a new one.",
1481
+ meta: { url },
1482
+ cause: lastError
1483
+ });
1484
+ }
1485
+ async function expectOk(res) {
1486
+ if (!res.ok) {
1487
+ const body = await res.text();
1488
+ throw new Error(`request to the local dev emulator failed (${res.status}): ${body}`);
1489
+ }
1490
+ return res;
1491
+ }
1492
+ const INSTANCE_STATUSES = /* @__PURE__ */ new Set([
1493
+ "running",
1494
+ "backoff",
1495
+ "held",
1496
+ "stopped"
1497
+ ]);
1498
+ function isStringRecord(value) {
1499
+ return typeof value === "object" && value !== null && Object.values(value).every((v) => typeof v === "string");
1500
+ }
1501
+ function isServiceInstanceInfo(value) {
1502
+ return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" && "labels" in value && isStringRecord(value.labels) && "port" in value && typeof value.port === "number" && "url" in value && typeof value.url === "string" && "status" in value && typeof value.status === "string" && INSTANCE_STATUSES.has(value.status) && "logPath" in value && typeof value.logPath === "string";
1503
+ }
1504
+ function isServiceInstanceInfoArray(value) {
1505
+ return Array.isArray(value) && value.every(isServiceInstanceInfo);
1506
+ }
1507
+ function isHealthBody(value) {
1508
+ return typeof value === "object" && value !== null && "version" in value && typeof value.version === "string";
1509
+ }
1510
+ function instancePath(baseUrl, id) {
1511
+ return `${baseUrl}/instances/${encodeURIComponent(id)}`;
1512
+ }
1513
+ function postJson(body) {
1514
+ return {
1515
+ method: "POST",
1516
+ headers: { "content-type": "application/json" },
1517
+ body: JSON.stringify(body)
1518
+ };
1519
+ }
1520
+ function computeClient(opts = {}) {
1521
+ const baseUrl = resolveBaseUrl("compute", opts);
1522
+ return {
1523
+ baseUrl,
1524
+ async health() {
1525
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/health`))).json();
1526
+ if (!isHealthBody(body)) throw new Error("malformed /health response from the compute emulator");
1527
+ return body;
1528
+ },
1529
+ async createInstance(request) {
1530
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/instances`, postJson(request), { retry: false }))).json();
1531
+ if (!isServiceInstanceInfo(body)) throw new Error("malformed instance-create response from the compute emulator");
1532
+ return body;
1533
+ },
1534
+ async listInstances() {
1535
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/instances`))).json();
1536
+ if (!isServiceInstanceInfoArray(body)) throw new Error("malformed instances listing from the compute emulator");
1537
+ return body;
1538
+ },
1539
+ async getInstance(id) {
1540
+ const res = await adminFetch(instancePath(baseUrl, id));
1541
+ if (res.status === 404) return void 0;
1542
+ const body = await (await expectOk(res)).json();
1543
+ if (!isServiceInstanceInfo(body)) throw new Error("malformed instance response from the compute emulator");
1544
+ return body;
1545
+ },
1546
+ async putDeployment(id, deployment) {
1547
+ await expectOk(await adminFetch(`${instancePath(baseUrl, id)}/deployment`, {
1548
+ method: "PUT",
1549
+ headers: { "content-type": "application/json" },
1550
+ body: JSON.stringify(deployment)
1551
+ }));
1552
+ },
1553
+ async *followLogs(id, signal, opts) {
1554
+ const tail = opts?.tail !== void 0 ? `&tail=${String(Math.max(0, Math.trunc(opts.tail)))}` : "";
1555
+ const body = (await expectOk(await adminFetch(`${instancePath(baseUrl, id)}/logs?follow=1${tail}`, signal ? { signal } : void 0))).body;
1556
+ if (!body) return;
1557
+ const reader = body.getReader();
1558
+ const decoder = new TextDecoder();
1559
+ try {
1560
+ while (true) {
1561
+ const { done, value } = await reader.read();
1562
+ if (done) return;
1563
+ yield decoder.decode(value, { stream: true });
1564
+ }
1565
+ } finally {
1566
+ await reader.cancel().catch(() => void 0);
1567
+ }
1568
+ },
1569
+ async startInstances(ids) {
1570
+ await expectOk(await adminFetch(`${baseUrl}/instances/start`, postJson({ ids })));
1571
+ },
1572
+ async stopInstances(ids) {
1573
+ await expectOk(await adminFetch(`${baseUrl}/instances/stop`, postJson({ ids })));
1574
+ },
1575
+ async deleteInstance(id) {
1576
+ await expectOk(await adminFetch(instancePath(baseUrl, id), { method: "DELETE" }));
1577
+ }
1578
+ };
1579
+ }
1580
+ function isBucketInstanceInfo(value) {
1581
+ return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" && "labels" in value && isStringRecord(value.labels) && "dir" in value && typeof value.dir === "string";
1582
+ }
1583
+ function isBucketInstanceInfoArray(value) {
1584
+ return Array.isArray(value) && value.every(isBucketInstanceInfo);
1585
+ }
1586
+ function bucketsClient(opts = {}) {
1587
+ const baseUrl = resolveBaseUrl("buckets", opts);
1588
+ const adminUrl = `${baseUrl}/_pcdev/instances`;
1589
+ return {
1590
+ baseUrl,
1591
+ async health() {
1592
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/_pcdev/health`))).json();
1593
+ if (!isHealthBody(body)) throw new Error("malformed /_pcdev/health response from the buckets emulator");
1594
+ return body;
1595
+ },
1596
+ async createInstance(request) {
1597
+ const body = await (await expectOk(await adminFetch(adminUrl, postJson(request), { retry: false }))).json();
1598
+ if (!isBucketInstanceInfo(body)) throw new Error("malformed instance-create response from the buckets emulator");
1599
+ return body;
1600
+ },
1601
+ async listInstances() {
1602
+ const body = await (await expectOk(await adminFetch(adminUrl))).json();
1603
+ if (!isBucketInstanceInfoArray(body)) throw new Error("malformed instances listing from the buckets emulator");
1604
+ return body;
1605
+ },
1606
+ async getInstance(id) {
1607
+ const res = await adminFetch(instancePath(`${baseUrl}/_pcdev`, id));
1608
+ if (res.status === 404) return void 0;
1609
+ const body = await (await expectOk(res)).json();
1610
+ if (!isBucketInstanceInfo(body)) throw new Error("malformed instance response from the buckets emulator");
1611
+ return body;
1612
+ },
1613
+ async putCredentials(id, accessKeyId, secretAccessKey) {
1614
+ await expectOk(await adminFetch(`${instancePath(`${baseUrl}/_pcdev`, id)}/credentials`, {
1615
+ method: "PUT",
1616
+ headers: { "content-type": "application/json" },
1617
+ body: JSON.stringify({
1618
+ accessKeyId,
1619
+ secretAccessKey
1620
+ })
1621
+ }));
1622
+ },
1623
+ async deleteInstance(id) {
1624
+ await expectOk(await adminFetch(instancePath(`${baseUrl}/_pcdev`, id), { method: "DELETE" }));
1625
+ }
1626
+ };
1627
+ }
1628
+ function isDatabaseInstanceInfo(value) {
1629
+ return typeof value === "object" && value !== null && "id" in value && typeof value.id === "string" && "labels" in value && isStringRecord(value.labels) && "port" in value && typeof value.port === "number" && "url" in value && typeof value.url === "string" && "status" in value && (value.status === "running" || value.status === "stopped");
1630
+ }
1631
+ function isDatabaseInstanceInfoArray(value) {
1632
+ return Array.isArray(value) && value.every(isDatabaseInstanceInfo);
1633
+ }
1634
+ function postgresClient(opts = {}) {
1635
+ const baseUrl = resolveBaseUrl("postgres", opts);
1636
+ return {
1637
+ baseUrl,
1638
+ async health() {
1639
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/health`))).json();
1640
+ if (!isHealthBody(body)) throw new Error("malformed /health response from the postgres emulator");
1641
+ return body;
1642
+ },
1643
+ async createInstance(request) {
1644
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/instances`, postJson(request), { retry: false }))).json();
1645
+ if (!isDatabaseInstanceInfo(body)) throw new Error("malformed instance-create response from the postgres emulator");
1646
+ return body;
1647
+ },
1648
+ async listInstances() {
1649
+ const body = await (await expectOk(await adminFetch(`${baseUrl}/instances`))).json();
1650
+ if (!isDatabaseInstanceInfoArray(body)) throw new Error("malformed instances listing from the postgres emulator");
1651
+ return body;
1652
+ },
1653
+ async getInstance(id) {
1654
+ const res = await adminFetch(instancePath(baseUrl, id));
1655
+ if (res.status === 404) return void 0;
1656
+ const body = await (await expectOk(res)).json();
1657
+ if (!isDatabaseInstanceInfo(body)) throw new Error("malformed instance response from the postgres emulator");
1658
+ return body;
1659
+ },
1660
+ async startInstances(ids, prismaDevModulePath) {
1661
+ await expectOk(await adminFetch(`${baseUrl}/instances/start`, postJson({
1662
+ ids,
1663
+ prismaDevModulePath
1664
+ })));
1665
+ },
1666
+ async stopInstances(ids) {
1667
+ await expectOk(await adminFetch(`${baseUrl}/instances/stop`, postJson({ ids })));
1668
+ },
1669
+ async deleteInstance(id, prismaDevModulePath) {
1670
+ await expectOk(await adminFetch(instancePath(baseUrl, id), {
1671
+ method: "DELETE",
1672
+ ...prismaDevModulePath !== void 0 ? {
1673
+ headers: { "content-type": "application/json" },
1674
+ body: JSON.stringify({ prismaDevModulePath })
1675
+ } : {}
1676
+ }));
1677
+ }
1678
+ };
1679
+ }
1680
+ /**
1681
+ * Every local emulator on this machine and every instance on it — the
1682
+ * operation behind `prisma emulator list`. It needs no project: it reads the
1683
+ * emulators' registry and asks each running emulator for its instances.
1684
+ */
1685
+ const EMULATOR_KINDS = [
1686
+ "service",
1687
+ "database",
1688
+ "bucket"
1689
+ ];
1690
+ const DAEMON_OF = {
1691
+ service: "compute",
1692
+ database: "postgres",
1693
+ bucket: "buckets"
1694
+ };
1695
+ /** Whether the emulator for `kind` is registered with a live process. */
1696
+ async function isEmulatorRunning(kind, opts = {}) {
1697
+ const entry = await readRegistryEntry(opts.registryRoot ?? defaultRegistryRoot(), DAEMON_OF[kind]);
1698
+ return entry !== void 0 && isPidAlive(entry.pid);
1699
+ }
1700
+ function listerOf(kind, opts) {
1701
+ if (kind === "service") {
1702
+ const client = computeClient(opts);
1703
+ return {
1704
+ url: client.baseUrl,
1705
+ list: async () => (await client.listInstances()).map(({ id, url, status, labels }) => ({
1706
+ id,
1707
+ kind,
1708
+ url,
1709
+ state: status,
1710
+ labels
1711
+ }))
1712
+ };
1713
+ }
1714
+ if (kind === "database") {
1715
+ const client = postgresClient(opts);
1716
+ return {
1717
+ url: client.baseUrl,
1718
+ list: async () => (await client.listInstances()).map(({ id, url, status, labels }) => ({
1719
+ id,
1720
+ kind,
1721
+ url,
1722
+ state: status,
1723
+ labels
1724
+ }))
1725
+ };
1726
+ }
1727
+ const client = bucketsClient(opts);
1728
+ return {
1729
+ url: client.baseUrl,
1730
+ list: async () => (await client.listInstances()).map(({ id, labels }) => ({
1731
+ id,
1732
+ kind,
1733
+ url: `${client.baseUrl}/${id}`,
1734
+ state: "running",
1735
+ labels
1736
+ }))
1737
+ };
1738
+ }
1739
+ async function listingOf(kind, opts) {
1740
+ if (!await isEmulatorRunning(kind, opts)) return {
1741
+ kind,
1742
+ running: false,
1743
+ url: null,
1744
+ instances: [],
1745
+ error: null
1746
+ };
1747
+ const lister = listerOf(kind, opts);
1748
+ try {
1749
+ return {
1750
+ kind,
1751
+ running: true,
1752
+ url: lister.url,
1753
+ instances: await lister.list(),
1754
+ error: null
1755
+ };
1756
+ } catch (error) {
1757
+ const failure = CliStructuredError.is(error) ? error : new CliStructuredError("DEV.EMULATOR_FAILED", error instanceof Error ? error.message : String(error), { cause: error });
1758
+ return {
1759
+ kind,
1760
+ running: true,
1761
+ url: lister.url,
1762
+ instances: [],
1763
+ error: {
1764
+ code: failure.code,
1765
+ message: failure.message
1766
+ }
1767
+ };
1768
+ }
1769
+ }
1770
+ /**
1771
+ * Every emulator, whether it runs, and its instances. Nothing running is a
1772
+ * valid answer, and an emulator that cannot be listed is reported in its own
1773
+ * entry; only an invalid emulators directory fails the whole listing.
1774
+ */
1775
+ async function listEmulators(opts = {}) {
1776
+ try {
1777
+ const emulators = [];
1778
+ for (const kind of EMULATOR_KINDS) emulators.push(await listingOf(kind, opts));
1779
+ return ok({ emulators });
1780
+ } catch (error) {
1781
+ if (CliStructuredError.is(error)) return notOk(error);
1782
+ throw error;
1783
+ }
1784
+ }
1785
+ //#endregion
1786
+ export { listEmulators };
1787
+
1788
+ //# sourceMappingURL=dist-j4X7U5yA.mjs.map