UNPKG

idmp

Version:

A lightweight TypeScript library for deduplicating and caching async function calls with automatic retries, designed for idempotent network requests in React and Node.js.

1,476 lines 90.1 kB
/*! idmp v0.0.0 | (c) github/haozi | MIT */ "use strict"; var __defProp = Object.defineProperty; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name); var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it); Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; function getDefaultExportFromCjs(x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; } function getAugmentedNamespace(n) { if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n; var f = n.default; if (typeof f == "function") { var a = function a2() { var isInstance = false; try { isInstance = this instanceof a2; } catch (e) { } if (isInstance) { return Reflect.construct(f, arguments, this.constructor); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, "__esModule", { value: true }); Object.keys(n).forEach(function(k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function() { return n[k]; } }); }); return a; } var fs$1 = {}; var universalify = {}; var hasRequiredUniversalify; function requireUniversalify() { if (hasRequiredUniversalify) return universalify; hasRequiredUniversalify = 1; universalify.fromCallback = function(fn) { return Object.defineProperty(function(...args) { if (typeof args[args.length - 1] === "function") fn.apply(this, args); else { return new Promise((resolve, reject) => { args.push((err, res) => err != null ? reject(err) : resolve(res)); fn.apply(this, args); }); } }, "name", { value: fn.name }); }; universalify.fromPromise = function(fn) { return Object.defineProperty(function(...args) { const cb = args[args.length - 1]; if (typeof cb !== "function") return fn.apply(this, args); else { args.pop(); fn.apply(this, args).then((r) => cb(null, r), cb); } }, "name", { value: fn.name }); }; return universalify; } const __viteBrowserExternal_fs = new Proxy({}, { get(_, key) { throw new Error(`Module "fs" has been externalized for browser compatibility. Cannot access "fs.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_fs$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_fs }, Symbol.toStringTag, { value: "Module" })); const require$$1$1 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_fs$1); const __viteBrowserExternal_constants = new Proxy({}, { get(_, key) { throw new Error(`Module "constants" has been externalized for browser compatibility. Cannot access "constants.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_constants$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_constants }, Symbol.toStringTag, { value: "Module" })); const require$$0$2 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_constants$1); var polyfills; var hasRequiredPolyfills; function requirePolyfills() { if (hasRequiredPolyfills) return polyfills; hasRequiredPolyfills = 1; var constants = require$$0$2; var origCwd = process.cwd; var cwd = null; var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform; process.cwd = function() { if (!cwd) cwd = origCwd.call(process); return cwd; }; try { process.cwd(); } catch (er) { } if (typeof process.chdir === "function") { var chdir = process.chdir; process.chdir = function(d) { cwd = null; chdir.call(process, d); }; if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir); } polyfills = patch; function patch(fs2) { if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) { patchLchmod(fs2); } if (!fs2.lutimes) { patchLutimes(fs2); } fs2.chown = chownFix(fs2.chown); fs2.fchown = chownFix(fs2.fchown); fs2.lchown = chownFix(fs2.lchown); fs2.chmod = chmodFix(fs2.chmod); fs2.fchmod = chmodFix(fs2.fchmod); fs2.lchmod = chmodFix(fs2.lchmod); fs2.chownSync = chownFixSync(fs2.chownSync); fs2.fchownSync = chownFixSync(fs2.fchownSync); fs2.lchownSync = chownFixSync(fs2.lchownSync); fs2.chmodSync = chmodFixSync(fs2.chmodSync); fs2.fchmodSync = chmodFixSync(fs2.fchmodSync); fs2.lchmodSync = chmodFixSync(fs2.lchmodSync); fs2.stat = statFix(fs2.stat); fs2.fstat = statFix(fs2.fstat); fs2.lstat = statFix(fs2.lstat); fs2.statSync = statFixSync(fs2.statSync); fs2.fstatSync = statFixSync(fs2.fstatSync); fs2.lstatSync = statFixSync(fs2.lstatSync); if (fs2.chmod && !fs2.lchmod) { fs2.lchmod = function(path2, mode, cb) { if (cb) process.nextTick(cb); }; fs2.lchmodSync = function() { }; } if (fs2.chown && !fs2.lchown) { fs2.lchown = function(path2, uid, gid, cb) { if (cb) process.nextTick(cb); }; fs2.lchownSync = function() { }; } if (platform === "win32") { fs2.rename = typeof fs2.rename !== "function" ? fs2.rename : function(fs$rename) { function rename(from, to, cb) { var start = Date.now(); var backoff = 0; fs$rename(from, to, function CB(er) { if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) { setTimeout(function() { fs2.stat(to, function(stater, st) { if (stater && stater.code === "ENOENT") fs$rename(from, to, CB); else cb(er); }); }, backoff); if (backoff < 100) backoff += 10; return; } if (cb) cb(er); }); } if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename); return rename; }(fs2.rename); } fs2.read = typeof fs2.read !== "function" ? fs2.read : function(fs$read) { function read(fd, buffer, offset, length, position, callback_) { var callback; if (callback_ && typeof callback_ === "function") { var eagCounter = 0; callback = function(er, _, __) { if (er && er.code === "EAGAIN" && eagCounter < 10) { eagCounter++; return fs$read.call(fs2, fd, buffer, offset, length, position, callback); } callback_.apply(this, arguments); }; } return fs$read.call(fs2, fd, buffer, offset, length, position, callback); } if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read); return read; }(fs2.read); fs2.readSync = typeof fs2.readSync !== "function" ? fs2.readSync : /* @__PURE__ */ function(fs$readSync) { return function(fd, buffer, offset, length, position) { var eagCounter = 0; while (true) { try { return fs$readSync.call(fs2, fd, buffer, offset, length, position); } catch (er) { if (er.code === "EAGAIN" && eagCounter < 10) { eagCounter++; continue; } throw er; } } }; }(fs2.readSync); function patchLchmod(fs3) { fs3.lchmod = function(path2, mode, callback) { fs3.open( path2, constants.O_WRONLY | constants.O_SYMLINK, mode, function(err, fd) { if (err) { if (callback) callback(err); return; } fs3.fchmod(fd, mode, function(err2) { fs3.close(fd, function(err22) { if (callback) callback(err2 || err22); }); }); } ); }; fs3.lchmodSync = function(path2, mode) { var fd = fs3.openSync(path2, constants.O_WRONLY | constants.O_SYMLINK, mode); var threw = true; var ret; try { ret = fs3.fchmodSync(fd, mode); threw = false; } finally { if (threw) { try { fs3.closeSync(fd); } catch (er) { } } else { fs3.closeSync(fd); } } return ret; }; } function patchLutimes(fs3) { if (constants.hasOwnProperty("O_SYMLINK") && fs3.futimes) { fs3.lutimes = function(path2, at, mt, cb) { fs3.open(path2, constants.O_SYMLINK, function(er, fd) { if (er) { if (cb) cb(er); return; } fs3.futimes(fd, at, mt, function(er2) { fs3.close(fd, function(er22) { if (cb) cb(er2 || er22); }); }); }); }; fs3.lutimesSync = function(path2, at, mt) { var fd = fs3.openSync(path2, constants.O_SYMLINK); var ret; var threw = true; try { ret = fs3.futimesSync(fd, at, mt); threw = false; } finally { if (threw) { try { fs3.closeSync(fd); } catch (er) { } } else { fs3.closeSync(fd); } } return ret; }; } else if (fs3.futimes) { fs3.lutimes = function(_a, _b, _c, cb) { if (cb) process.nextTick(cb); }; fs3.lutimesSync = function() { }; } } function chmodFix(orig) { if (!orig) return orig; return function(target, mode, cb) { return orig.call(fs2, target, mode, function(er) { if (chownErOk(er)) er = null; if (cb) cb.apply(this, arguments); }); }; } function chmodFixSync(orig) { if (!orig) return orig; return function(target, mode) { try { return orig.call(fs2, target, mode); } catch (er) { if (!chownErOk(er)) throw er; } }; } function chownFix(orig) { if (!orig) return orig; return function(target, uid, gid, cb) { return orig.call(fs2, target, uid, gid, function(er) { if (chownErOk(er)) er = null; if (cb) cb.apply(this, arguments); }); }; } function chownFixSync(orig) { if (!orig) return orig; return function(target, uid, gid) { try { return orig.call(fs2, target, uid, gid); } catch (er) { if (!chownErOk(er)) throw er; } }; } function statFix(orig) { if (!orig) return orig; return function(target, options, cb) { if (typeof options === "function") { cb = options; options = null; } function callback(er, stats) { if (stats) { if (stats.uid < 0) stats.uid += 4294967296; if (stats.gid < 0) stats.gid += 4294967296; } if (cb) cb.apply(this, arguments); } return options ? orig.call(fs2, target, options, callback) : orig.call(fs2, target, callback); }; } function statFixSync(orig) { if (!orig) return orig; return function(target, options) { var stats = options ? orig.call(fs2, target, options) : orig.call(fs2, target); if (stats) { if (stats.uid < 0) stats.uid += 4294967296; if (stats.gid < 0) stats.gid += 4294967296; } return stats; }; } function chownErOk(er) { if (!er) return true; if (er.code === "ENOSYS") return true; var nonroot = !process.getuid || process.getuid() !== 0; if (nonroot) { if (er.code === "EINVAL" || er.code === "EPERM") return true; } return false; } } return polyfills; } const __viteBrowserExternal_stream = new Proxy({}, { get(_, key) { throw new Error(`Module "stream" has been externalized for browser compatibility. Cannot access "stream.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_stream$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_stream }, Symbol.toStringTag, { value: "Module" })); const require$$0$1 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_stream$1); var legacyStreams; var hasRequiredLegacyStreams; function requireLegacyStreams() { if (hasRequiredLegacyStreams) return legacyStreams; hasRequiredLegacyStreams = 1; var Stream = require$$0$1.Stream; legacyStreams = legacy; function legacy(fs2) { return { ReadStream, WriteStream }; function ReadStream(path2, options) { if (!(this instanceof ReadStream)) return new ReadStream(path2, options); Stream.call(this); var self2 = this; this.path = path2; this.fd = null; this.readable = true; this.paused = false; this.flags = "r"; this.mode = 438; this.bufferSize = 64 * 1024; options = options || {}; var keys = Object.keys(options); for (var index = 0, length = keys.length; index < length; index++) { var key = keys[index]; this[key] = options[key]; } if (this.encoding) this.setEncoding(this.encoding); if (this.start !== void 0) { if ("number" !== typeof this.start) { throw TypeError("start must be a Number"); } if (this.end === void 0) { this.end = Infinity; } else if ("number" !== typeof this.end) { throw TypeError("end must be a Number"); } if (this.start > this.end) { throw new Error("start must be <= end"); } this.pos = this.start; } if (this.fd !== null) { process.nextTick(function() { self2._read(); }); return; } fs2.open(this.path, this.flags, this.mode, function(err, fd) { if (err) { self2.emit("error", err); self2.readable = false; return; } self2.fd = fd; self2.emit("open", fd); self2._read(); }); } function WriteStream(path2, options) { if (!(this instanceof WriteStream)) return new WriteStream(path2, options); Stream.call(this); this.path = path2; this.fd = null; this.writable = true; this.flags = "w"; this.encoding = "binary"; this.mode = 438; this.bytesWritten = 0; options = options || {}; var keys = Object.keys(options); for (var index = 0, length = keys.length; index < length; index++) { var key = keys[index]; this[key] = options[key]; } if (this.start !== void 0) { if ("number" !== typeof this.start) { throw TypeError("start must be a Number"); } if (this.start < 0) { throw new Error("start must be >= zero"); } this.pos = this.start; } this.busy = false; this._queue = []; if (this.fd === null) { this._open = fs2.open; this._queue.push([this._open, this.path, this.flags, this.mode, void 0]); this.flush(); } } } return legacyStreams; } var clone_1; var hasRequiredClone; function requireClone() { if (hasRequiredClone) return clone_1; hasRequiredClone = 1; clone_1 = clone; var getPrototypeOf = Object.getPrototypeOf || function(obj) { return obj.__proto__; }; function clone(obj) { if (obj === null || typeof obj !== "object") return obj; if (obj instanceof Object) var copy2 = { __proto__: getPrototypeOf(obj) }; else var copy2 = /* @__PURE__ */ Object.create(null); Object.getOwnPropertyNames(obj).forEach(function(key) { Object.defineProperty(copy2, key, Object.getOwnPropertyDescriptor(obj, key)); }); return copy2; } return clone_1; } const __viteBrowserExternal_util = new Proxy({}, { get(_, key) { throw new Error(`Module "util" has been externalized for browser compatibility. Cannot access "util.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_util$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_util }, Symbol.toStringTag, { value: "Module" })); const require$$4 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_util$1); const __viteBrowserExternal_assert = new Proxy({}, { get(_, key) { throw new Error(`Module "assert" has been externalized for browser compatibility. Cannot access "assert.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_assert$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_assert }, Symbol.toStringTag, { value: "Module" })); const require$$5 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_assert$1); var gracefulFs; var hasRequiredGracefulFs; function requireGracefulFs() { if (hasRequiredGracefulFs) return gracefulFs; hasRequiredGracefulFs = 1; var fs2 = require$$1$1; var polyfills2 = requirePolyfills(); var legacy = requireLegacyStreams(); var clone = requireClone(); var util = require$$4; var gracefulQueue; var previousSymbol; if (typeof Symbol === "function" && typeof Symbol.for === "function") { gracefulQueue = Symbol.for("graceful-fs.queue"); previousSymbol = Symbol.for("graceful-fs.previous"); } else { gracefulQueue = "___graceful-fs.queue"; previousSymbol = "___graceful-fs.previous"; } function noop2() { } function publishQueue(context, queue2) { Object.defineProperty(context, gracefulQueue, { get: function() { return queue2; } }); } var debug = noop2; if (util.debuglog) debug = util.debuglog("gfs4"); else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) debug = function() { var m = util.format.apply(util, arguments); m = "GFS4: " + m.split(/\n/).join("\nGFS4: "); console.error(m); }; if (!fs2[gracefulQueue]) { var queue = commonjsGlobal[gracefulQueue] || []; publishQueue(fs2, queue); fs2.close = function(fs$close) { function close(fd, cb) { return fs$close.call(fs2, fd, function(err) { if (!err) { resetQueue(); } if (typeof cb === "function") cb.apply(this, arguments); }); } Object.defineProperty(close, previousSymbol, { value: fs$close }); return close; }(fs2.close); fs2.closeSync = function(fs$closeSync) { function closeSync(fd) { fs$closeSync.apply(fs2, arguments); resetQueue(); } Object.defineProperty(closeSync, previousSymbol, { value: fs$closeSync }); return closeSync; }(fs2.closeSync); if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) { process.on("exit", function() { debug(fs2[gracefulQueue]); require$$5.equal(fs2[gracefulQueue].length, 0); }); } } if (!commonjsGlobal[gracefulQueue]) { publishQueue(commonjsGlobal, fs2[gracefulQueue]); } gracefulFs = patch(clone(fs2)); if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs2.__patched) { gracefulFs = patch(fs2); fs2.__patched = true; } function patch(fs3) { polyfills2(fs3); fs3.gracefulify = patch; fs3.createReadStream = createReadStream; fs3.createWriteStream = createWriteStream; var fs$readFile = fs3.readFile; fs3.readFile = readFile; function readFile(path2, options, cb) { if (typeof options === "function") cb = options, options = null; return go$readFile(path2, options, cb); function go$readFile(path3, options2, cb2, startTime) { return fs$readFile(path3, options2, function(err) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([go$readFile, [path3, options2, cb2], err, startTime || Date.now(), Date.now()]); else { if (typeof cb2 === "function") cb2.apply(this, arguments); } }); } } var fs$writeFile = fs3.writeFile; fs3.writeFile = writeFile; function writeFile(path2, data, options, cb) { if (typeof options === "function") cb = options, options = null; return go$writeFile(path2, data, options, cb); function go$writeFile(path3, data2, options2, cb2, startTime) { return fs$writeFile(path3, data2, options2, function(err) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([go$writeFile, [path3, data2, options2, cb2], err, startTime || Date.now(), Date.now()]); else { if (typeof cb2 === "function") cb2.apply(this, arguments); } }); } } var fs$appendFile = fs3.appendFile; if (fs$appendFile) fs3.appendFile = appendFile; function appendFile(path2, data, options, cb) { if (typeof options === "function") cb = options, options = null; return go$appendFile(path2, data, options, cb); function go$appendFile(path3, data2, options2, cb2, startTime) { return fs$appendFile(path3, data2, options2, function(err) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([go$appendFile, [path3, data2, options2, cb2], err, startTime || Date.now(), Date.now()]); else { if (typeof cb2 === "function") cb2.apply(this, arguments); } }); } } var fs$copyFile = fs3.copyFile; if (fs$copyFile) fs3.copyFile = copyFile; function copyFile(src, dest, flags, cb) { if (typeof flags === "function") { cb = flags; flags = 0; } return go$copyFile(src, dest, flags, cb); function go$copyFile(src2, dest2, flags2, cb2, startTime) { return fs$copyFile(src2, dest2, flags2, function(err) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]); else { if (typeof cb2 === "function") cb2.apply(this, arguments); } }); } } var fs$readdir = fs3.readdir; fs3.readdir = readdir; var noReaddirOptionVersions = /^v[0-5]\./; function readdir(path2, options, cb) { if (typeof options === "function") cb = options, options = null; var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path3, options2, cb2, startTime) { return fs$readdir(path3, fs$readdirCallback( path3, options2, cb2, startTime )); } : function go$readdir2(path3, options2, cb2, startTime) { return fs$readdir(path3, options2, fs$readdirCallback( path3, options2, cb2, startTime )); }; return go$readdir(path2, options, cb); function fs$readdirCallback(path3, options2, cb2, startTime) { return function(err, files) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([ go$readdir, [path3, options2, cb2], err, startTime || Date.now(), Date.now() ]); else { if (files && files.sort) files.sort(); if (typeof cb2 === "function") cb2.call(this, err, files); } }; } } if (process.version.substr(0, 4) === "v0.8") { var legStreams = legacy(fs3); ReadStream = legStreams.ReadStream; WriteStream = legStreams.WriteStream; } var fs$ReadStream = fs3.ReadStream; if (fs$ReadStream) { ReadStream.prototype = Object.create(fs$ReadStream.prototype); ReadStream.prototype.open = ReadStream$open; } var fs$WriteStream = fs3.WriteStream; if (fs$WriteStream) { WriteStream.prototype = Object.create(fs$WriteStream.prototype); WriteStream.prototype.open = WriteStream$open; } Object.defineProperty(fs3, "ReadStream", { get: function() { return ReadStream; }, set: function(val) { ReadStream = val; }, enumerable: true, configurable: true }); Object.defineProperty(fs3, "WriteStream", { get: function() { return WriteStream; }, set: function(val) { WriteStream = val; }, enumerable: true, configurable: true }); var FileReadStream = ReadStream; Object.defineProperty(fs3, "FileReadStream", { get: function() { return FileReadStream; }, set: function(val) { FileReadStream = val; }, enumerable: true, configurable: true }); var FileWriteStream = WriteStream; Object.defineProperty(fs3, "FileWriteStream", { get: function() { return FileWriteStream; }, set: function(val) { FileWriteStream = val; }, enumerable: true, configurable: true }); function ReadStream(path2, options) { if (this instanceof ReadStream) return fs$ReadStream.apply(this, arguments), this; else return ReadStream.apply(Object.create(ReadStream.prototype), arguments); } function ReadStream$open() { var that = this; open(that.path, that.flags, that.mode, function(err, fd) { if (err) { if (that.autoClose) that.destroy(); that.emit("error", err); } else { that.fd = fd; that.emit("open", fd); that.read(); } }); } function WriteStream(path2, options) { if (this instanceof WriteStream) return fs$WriteStream.apply(this, arguments), this; else return WriteStream.apply(Object.create(WriteStream.prototype), arguments); } function WriteStream$open() { var that = this; open(that.path, that.flags, that.mode, function(err, fd) { if (err) { that.destroy(); that.emit("error", err); } else { that.fd = fd; that.emit("open", fd); } }); } function createReadStream(path2, options) { return new fs3.ReadStream(path2, options); } function createWriteStream(path2, options) { return new fs3.WriteStream(path2, options); } var fs$open = fs3.open; fs3.open = open; function open(path2, flags, mode, cb) { if (typeof mode === "function") cb = mode, mode = null; return go$open(path2, flags, mode, cb); function go$open(path3, flags2, mode2, cb2, startTime) { return fs$open(path3, flags2, mode2, function(err, fd) { if (err && (err.code === "EMFILE" || err.code === "ENFILE")) enqueue([go$open, [path3, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]); else { if (typeof cb2 === "function") cb2.apply(this, arguments); } }); } } return fs3; } function enqueue(elem) { debug("ENQUEUE", elem[0].name, elem[1]); fs2[gracefulQueue].push(elem); retry(); } var retryTimer; function resetQueue() { var now = Date.now(); for (var i = 0; i < fs2[gracefulQueue].length; ++i) { if (fs2[gracefulQueue][i].length > 2) { fs2[gracefulQueue][i][3] = now; fs2[gracefulQueue][i][4] = now; } } retry(); } function retry() { clearTimeout(retryTimer); retryTimer = void 0; if (fs2[gracefulQueue].length === 0) return; var elem = fs2[gracefulQueue].shift(); var fn = elem[0]; var args = elem[1]; var err = elem[2]; var startTime = elem[3]; var lastTime = elem[4]; if (startTime === void 0) { debug("RETRY", fn.name, args); fn.apply(null, args); } else if (Date.now() - startTime >= 6e4) { debug("TIMEOUT", fn.name, args); var cb = args.pop(); if (typeof cb === "function") cb.call(null, err); } else { var sinceAttempt = Date.now() - lastTime; var sinceStart = Math.max(lastTime - startTime, 1); var desiredDelay = Math.min(sinceStart * 1.2, 100); if (sinceAttempt >= desiredDelay) { debug("RETRY", fn.name, args); fn.apply(null, args.concat([startTime])); } else { fs2[gracefulQueue].push(elem); } } if (retryTimer === void 0) { retryTimer = setTimeout(retry, 0); } } return gracefulFs; } var hasRequiredFs; function requireFs() { if (hasRequiredFs) return fs$1; hasRequiredFs = 1; (function(exports2) { const u = requireUniversalify().fromCallback; const fs2 = requireGracefulFs(); const api = [ "access", "appendFile", "chmod", "chown", "close", "copyFile", "cp", "fchmod", "fchown", "fdatasync", "fstat", "fsync", "ftruncate", "futimes", "glob", "lchmod", "lchown", "lutimes", "link", "lstat", "mkdir", "mkdtemp", "open", "opendir", "readdir", "readFile", "readlink", "realpath", "rename", "rm", "rmdir", "stat", "statfs", "symlink", "truncate", "unlink", "utimes", "writeFile" ].filter((key) => { return typeof fs2[key] === "function"; }); Object.assign(exports2, fs2); api.forEach((method) => { exports2[method] = u(fs2[method]); }); exports2.exists = function(filename, callback) { if (typeof callback === "function") { return fs2.exists(filename, callback); } return new Promise((resolve) => { return fs2.exists(filename, resolve); }); }; exports2.read = function(fd, buffer, offset, length, position, callback) { if (typeof callback === "function") { return fs2.read(fd, buffer, offset, length, position, callback); } return new Promise((resolve, reject) => { fs2.read(fd, buffer, offset, length, position, (err, bytesRead, buffer2) => { if (err) return reject(err); resolve({ bytesRead, buffer: buffer2 }); }); }); }; exports2.write = function(fd, buffer, ...args) { if (typeof args[args.length - 1] === "function") { return fs2.write(fd, buffer, ...args); } return new Promise((resolve, reject) => { fs2.write(fd, buffer, ...args, (err, bytesWritten, buffer2) => { if (err) return reject(err); resolve({ bytesWritten, buffer: buffer2 }); }); }); }; exports2.readv = function(fd, buffers, ...args) { if (typeof args[args.length - 1] === "function") { return fs2.readv(fd, buffers, ...args); } return new Promise((resolve, reject) => { fs2.readv(fd, buffers, ...args, (err, bytesRead, buffers2) => { if (err) return reject(err); resolve({ bytesRead, buffers: buffers2 }); }); }); }; exports2.writev = function(fd, buffers, ...args) { if (typeof args[args.length - 1] === "function") { return fs2.writev(fd, buffers, ...args); } return new Promise((resolve, reject) => { fs2.writev(fd, buffers, ...args, (err, bytesWritten, buffers2) => { if (err) return reject(err); resolve({ bytesWritten, buffers: buffers2 }); }); }); }; if (typeof fs2.realpath.native === "function") { exports2.realpath.native = u(fs2.realpath.native); } else { process.emitWarning( "fs.realpath.native is not a function. Is fs being monkey-patched?", "Warning", "fs-extra-WARN0003" ); } })(fs$1); return fs$1; } const __viteBrowserExternal_path = new Proxy({}, { get(_, key) { throw new Error(`Module "path" has been externalized for browser compatibility. Cannot access "path.${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`); } }); const __viteBrowserExternal_path$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: __viteBrowserExternal_path }, Symbol.toStringTag, { value: "Module" })); const require$$1 = /* @__PURE__ */ getAugmentedNamespace(__viteBrowserExternal_path$1); var makeDir = {}; var utils$1 = {}; var hasRequiredUtils$1; function requireUtils$1() { if (hasRequiredUtils$1) return utils$1; hasRequiredUtils$1 = 1; const path2 = require$$1; utils$1.checkPath = function checkPath(pth) { if (process.platform === "win32") { const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path2.parse(pth).root, "")); if (pathHasInvalidWinCharacters) { const error = new Error(`Path contains invalid characters: ${pth}`); error.code = "EINVAL"; throw error; } } }; return utils$1; } var hasRequiredMakeDir; function requireMakeDir() { if (hasRequiredMakeDir) return makeDir; hasRequiredMakeDir = 1; const fs2 = /* @__PURE__ */ requireFs(); const { checkPath } = /* @__PURE__ */ requireUtils$1(); const getMode = (options) => { const defaults = { mode: 511 }; if (typeof options === "number") return options; return __spreadValues(__spreadValues({}, defaults), options).mode; }; makeDir.makeDir = (dir, options) => __async(null, null, function* () { checkPath(dir); return fs2.mkdir(dir, { mode: getMode(options), recursive: true }); }); makeDir.makeDirSync = (dir, options) => { checkPath(dir); return fs2.mkdirSync(dir, { mode: getMode(options), recursive: true }); }; return makeDir; } var mkdirs; var hasRequiredMkdirs; function requireMkdirs() { if (hasRequiredMkdirs) return mkdirs; hasRequiredMkdirs = 1; const u = requireUniversalify().fromPromise; const { makeDir: _makeDir, makeDirSync } = /* @__PURE__ */ requireMakeDir(); const makeDir2 = u(_makeDir); mkdirs = { mkdirs: makeDir2, mkdirsSync: makeDirSync, // alias mkdirp: makeDir2, mkdirpSync: makeDirSync, ensureDir: makeDir2, ensureDirSync: makeDirSync }; return mkdirs; } var pathExists_1; var hasRequiredPathExists; function requirePathExists() { if (hasRequiredPathExists) return pathExists_1; hasRequiredPathExists = 1; const u = requireUniversalify().fromPromise; const fs2 = /* @__PURE__ */ requireFs(); function pathExists(path2) { return fs2.access(path2).then(() => true).catch(() => false); } pathExists_1 = { pathExists: u(pathExists), pathExistsSync: fs2.existsSync }; return pathExists_1; } var utimes; var hasRequiredUtimes; function requireUtimes() { if (hasRequiredUtimes) return utimes; hasRequiredUtimes = 1; const fs2 = /* @__PURE__ */ requireFs(); const u = requireUniversalify().fromPromise; function utimesMillis(path2, atime, mtime) { return __async(this, null, function* () { const fd = yield fs2.open(path2, "r+"); let closeErr = null; try { yield fs2.futimes(fd, atime, mtime); } finally { try { yield fs2.close(fd); } catch (e) { closeErr = e; } } if (closeErr) { throw closeErr; } }); } function utimesMillisSync(path2, atime, mtime) { const fd = fs2.openSync(path2, "r+"); fs2.futimesSync(fd, atime, mtime); return fs2.closeSync(fd); } utimes = { utimesMillis: u(utimesMillis), utimesMillisSync }; return utimes; } var stat; var hasRequiredStat; function requireStat() { if (hasRequiredStat) return stat; hasRequiredStat = 1; const fs2 = /* @__PURE__ */ requireFs(); const path2 = require$$1; const u = requireUniversalify().fromPromise; function getStats(src, dest, opts) { const statFunc = opts.dereference ? (file2) => fs2.stat(file2, { bigint: true }) : (file2) => fs2.lstat(file2, { bigint: true }); return Promise.all([ statFunc(src), statFunc(dest).catch((err) => { if (err.code === "ENOENT") return null; throw err; }) ]).then(([srcStat, destStat]) => ({ srcStat, destStat })); } function getStatsSync(src, dest, opts) { let destStat; const statFunc = opts.dereference ? (file2) => fs2.statSync(file2, { bigint: true }) : (file2) => fs2.lstatSync(file2, { bigint: true }); const srcStat = statFunc(src); try { destStat = statFunc(dest); } catch (err) { if (err.code === "ENOENT") return { srcStat, destStat: null }; throw err; } return { srcStat, destStat }; } function checkPaths(src, dest, funcName, opts) { return __async(this, null, function* () { const { srcStat, destStat } = yield getStats(src, dest, opts); if (destStat) { if (areIdentical(srcStat, destStat)) { const srcBaseName = path2.basename(src); const destBaseName = path2.basename(dest); if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) { return { srcStat, destStat, isChangingCase: true }; } throw new Error("Source and destination must not be the same."); } if (srcStat.isDirectory() && !destStat.isDirectory()) { throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`); } if (!srcStat.isDirectory() && destStat.isDirectory()) { throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`); } } if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { throw new Error(errMsg(src, dest, funcName)); } return { srcStat, destStat }; }); } function checkPathsSync(src, dest, funcName, opts) { const { srcStat, destStat } = getStatsSync(src, dest, opts); if (destStat) { if (areIdentical(srcStat, destStat)) { const srcBaseName = path2.basename(src); const destBaseName = path2.basename(dest); if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) { return { srcStat, destStat, isChangingCase: true }; } throw new Error("Source and destination must not be the same."); } if (srcStat.isDirectory() && !destStat.isDirectory()) { throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`); } if (!srcStat.isDirectory() && destStat.isDirectory()) { throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`); } } if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { throw new Error(errMsg(src, dest, funcName)); } return { srcStat, destStat }; } function checkParentPaths(src, srcStat, dest, funcName) { return __async(this, null, function* () { const srcParent = path2.resolve(path2.dirname(src)); const destParent = path2.resolve(path2.dirname(dest)); if (destParent === srcParent || destParent === path2.parse(destParent).root) return; let destStat; try { destStat = yield fs2.stat(destParent, { bigint: true }); } catch (err) { if (err.code === "ENOENT") return; throw err; } if (areIdentical(srcStat, destStat)) { throw new Error(errMsg(src, dest, funcName)); } return checkParentPaths(src, srcStat, destParent, funcName); }); } function checkParentPathsSync(src, srcStat, dest, funcName) { const srcParent = path2.resolve(path2.dirname(src)); const destParent = path2.resolve(path2.dirname(dest)); if (destParent === srcParent || destParent === path2.parse(destParent).root) return; let destStat; try { destStat = fs2.statSync(destParent, { bigint: true }); } catch (err) { if (err.code === "ENOENT") return; throw err; } if (areIdentical(srcStat, destStat)) { throw new Error(errMsg(src, dest, funcName)); } return checkParentPathsSync(src, srcStat, destParent, funcName); } function areIdentical(srcStat, destStat) { return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev; } function isSrcSubdir(src, dest) { const srcArr = path2.resolve(src).split(path2.sep).filter((i) => i); const destArr = path2.resolve(dest).split(path2.sep).filter((i) => i); return srcArr.every((cur, i) => destArr[i] === cur); } function errMsg(src, dest, funcName) { return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`; } stat = { // checkPaths checkPaths: u(checkPaths), checkPathsSync, // checkParent checkParentPaths: u(checkParentPaths), checkParentPathsSync, // Misc isSrcSubdir, areIdentical }; return stat; } var copy_1; var hasRequiredCopy$1; function requireCopy$1() { if (hasRequiredCopy$1) return copy_1; hasRequiredCopy$1 = 1; const fs2 = /* @__PURE__ */ requireFs(); const path2 = require$$1; const { mkdirs: mkdirs2 } = /* @__PURE__ */ requireMkdirs(); const { pathExists } = /* @__PURE__ */ requirePathExists(); const { utimesMillis } = /* @__PURE__ */ requireUtimes(); const stat2 = /* @__PURE__ */ requireStat(); function copy2(_0, _1) { return __async(this, arguments, function* (src, dest, opts = {}) { if (typeof opts === "function") { opts = { filter: opts }; } opts.clobber = "clobber" in opts ? !!opts.clobber : true; opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber; if (opts.preserveTimestamps && process.arch === "ia32") { process.emitWarning( "Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269", "Warning", "fs-extra-WARN0001" ); } const { srcStat, destStat } = yield stat2.checkPaths(src, dest, "copy", opts); yield stat2.checkParentPaths(src, srcStat, dest, "copy"); const include = yield runFilter(src, dest, opts); if (!include) return; const destParent = path2.dirname(dest); const dirExists = yield pathExists(destParent); if (!dirExists) { yield mkdirs2(destParent); } yield getStatsAndPerformCopy(destStat, src, dest, opts); }); } function runFilter(src, dest, opts) { return __async(this, null, function* () { if (!opts.filter) return true; return opts.filter(src, dest); }); } function getStatsAndPerformCopy(destStat, src, dest, opts) { return __async(this, null, function* () { const statFn = opts.dereference ? fs2.stat : fs2.lstat; const srcStat = yield statFn(src); if (srcStat.isDirectory()) return onDir(srcStat, destStat, src, dest, opts); if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) return onFile(srcStat, destStat, src, dest, opts); if (srcStat.isSymbolicLink()) return onLink(destStat, src, dest, opts); if (srcStat.isSocket()) throw new Error(`Cannot copy a socket file: ${src}`); if (srcStat.isFIFO()) throw new Error(`Cannot copy a FIFO pipe: ${src}`); throw new Error(`Unknown file: ${src}`); }); } function onFile(srcStat, destStat, src, dest, opts) { return __async(this, null, function* () { if (!destStat) return copyFile(srcStat, src, dest, opts); if (opts.overwrite) { yield fs2.unlink(dest); return copyFile(srcStat, src, dest, opts); } if (opts.errorOnExist) { throw new Error(`'${dest}' already exists`); } }); } function copyFile(srcStat, src, dest, opts) { return __async(this, null, function* () { yield fs2.copyFile(src, dest); if (opts.preserveTimestamps) { if (fileIsNotWritable(srcStat.mode)) { yield makeFileWritable(dest, srcStat.mode); } const updatedSrcStat = yield fs2.stat(src); yield utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime); } return fs2.chmod(dest, srcStat.mode); }); } function fileIsNotWritable(srcMode) { return (srcMode & 128) === 0; } function makeFileWritable(dest, srcMode) { return fs2.chmod(dest, srcMode | 128); } function onDir(srcStat, destStat, src, dest, opts) { return __async(this, null, function* () { if (!destStat) { yield fs2.mkdir(dest); } const promises = []; try { for (var iter = __forAwait(yield fs2.opendir(src)), more, temp, error; more = !(temp = yield iter.next()).done; more = false) { const item = temp.value; const srcItem = path2.join(src, item.name); const destItem = path2.join(dest, item.name); promises.push( runFilter(srcItem, destItem, opts).then((include) => { if (include) { return stat2.checkPaths(srcItem, destItem, "copy", opts).then(({ destStat: destStat2 }) => { return getStatsAndPerformCopy(destStat2, srcItem, destItem, opts); }); } }) ); } } catch (temp) { error = [temp]; } finally { try { more && (temp = iter.return) && (yield temp.call(iter)); } finally { if (error) throw error[0]; } } yield Promise.all(promises); if (!destStat) { yield fs2.chmod(dest, srcStat.mode); } }); } function onLink(destStat, src, dest, opts) { return __async(this, null, function* () { let resolvedSrc = yield fs2.readlink(src); if (opts.dereference) { resolvedSrc = path2.resolve(process.cwd(), resolvedSrc); } if (!destStat) { return fs2.symlink(resolvedSrc, dest); } let resolvedDest = null; try { resolvedDest = yield fs2.readlink(dest); } catch (e) { if (e.code === "EINVAL" || e.code === "UNKNOWN") return fs2.symlink(resolvedSrc, dest); throw e; } if (opts.dereference) { resolvedDest = path2.resolve(process.cwd(), resolvedDest); } if (stat2.isSrcSubdir(resolvedSrc, resolvedDest)) { throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`); } if (stat2.isSrcSubdir(resolvedDest, resolvedSrc)) { throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`); } yield fs2.unlink(dest); return fs2.symlink(resolvedSrc, dest); }); } copy_1 = copy2; return copy_1; } var copySync_1; var hasRequiredCopySync; function requireCopySync() { if (hasRequiredCopySync) return copySync_1; hasRequiredCopySync = 1; const fs2 = requireGracefulFs(); const path2 = require$$1; const mkdirsSync = requireMkdirs().mkdirsSync; const utimesMillisSync = requireUtimes().utimesMillisSync; const st