{"version":3,"file":"rpc.MzXet3jl.mjs","names":[],"sources":["../../../../../../../../../../node_modules/vitest/dist/chunks/rpc.MzXet3jl.js"],"sourcesContent":["import { getSafeTimers } from '@vitest/utils/timers';\nimport { c as createBirpc } from './index.Chj8NDwU.js';\nimport { g as getWorkerState } from './utils.BX5Fg8C4.js';\n\n/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */\n/*\nThe MIT License (MIT)\n\nCopyright (c) 2014 Bob Lauer\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\nconst RealDate = Date;\nlet now = null;\nclass MockDate extends RealDate {\n\tconstructor(y, m, d, h, M, s, ms) {\n\t\tsuper();\n\t\tlet date;\n\t\tswitch (arguments.length) {\n\t\t\tcase 0:\n\t\t\t\tif (now !== null) date = new RealDate(now.valueOf());\n\t\t\t\telse date = new RealDate();\n\t\t\t\tbreak;\n\t\t\tcase 1:\n\t\t\t\tdate = new RealDate(y);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\td = typeof d === \"undefined\" ? 1 : d;\n\t\t\t\th = h || 0;\n\t\t\t\tM = M || 0;\n\t\t\t\ts = s || 0;\n\t\t\t\tms = ms || 0;\n\t\t\t\tdate = new RealDate(y, m, d, h, M, s, ms);\n\t\t\t\tbreak;\n\t\t}\n\t\tObject.setPrototypeOf(date, MockDate.prototype);\n\t\treturn date;\n\t}\n}\nMockDate.UTC = RealDate.UTC;\nMockDate.now = function() {\n\treturn new MockDate().valueOf();\n};\nMockDate.parse = function(dateString) {\n\treturn RealDate.parse(dateString);\n};\nMockDate.toString = function() {\n\treturn RealDate.toString();\n};\nfunction mockDate(date) {\n\tconst dateObj = new RealDate(date.valueOf());\n\tif (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);\n\t// @ts-expect-error global\n\tglobalThis.Date = MockDate;\n\tnow = dateObj.valueOf();\n}\nfunction resetDate() {\n\tglobalThis.Date = RealDate;\n}\n\nconst { get } = Reflect;\nfunction withSafeTimers(fn) {\n\tconst { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();\n\tconst currentSetTimeout = globalThis.setTimeout;\n\tconst currentClearTimeout = globalThis.clearTimeout;\n\tconst currentSetImmediate = globalThis.setImmediate;\n\tconst currentClearImmediate = globalThis.clearImmediate;\n\tconst currentNextTick = globalThis.process?.nextTick;\n\ttry {\n\t\tglobalThis.setTimeout = setTimeout;\n\t\tglobalThis.clearTimeout = clearTimeout;\n\t\tif (setImmediate) globalThis.setImmediate = setImmediate;\n\t\tif (clearImmediate) globalThis.clearImmediate = clearImmediate;\n\t\tif (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;\n\t\treturn fn();\n\t} finally {\n\t\tglobalThis.setTimeout = currentSetTimeout;\n\t\tglobalThis.clearTimeout = currentClearTimeout;\n\t\tglobalThis.setImmediate = currentSetImmediate;\n\t\tglobalThis.clearImmediate = currentClearImmediate;\n\t\tif (globalThis.process && nextTick) nextTick(() => {\n\t\t\tglobalThis.process.nextTick = currentNextTick;\n\t\t});\n\t}\n}\nconst promises = /* @__PURE__ */ new Set();\nasync function rpcDone() {\n\tif (!promises.size) return;\n\tconst awaitable = Array.from(promises);\n\treturn Promise.all(awaitable);\n}\nconst onCancelCallbacks = [];\nfunction onCancel(callback) {\n\tonCancelCallbacks.push(callback);\n}\nfunction createRuntimeRpc(options) {\n\treturn createSafeRpc(createBirpc({ async onCancel(reason) {\n\t\tawait Promise.all(onCancelCallbacks.map((fn) => fn(reason)));\n\t} }, {\n\t\teventNames: [\"onCancel\"],\n\t\ttimeout: -1,\n\t\t...options\n\t}));\n}\nfunction createSafeRpc(rpc) {\n\treturn new Proxy(rpc, { get(target, p, handler) {\n\t\t// keep $rejectPendingCalls as sync function\n\t\tif (p === \"$rejectPendingCalls\") return rpc.$rejectPendingCalls;\n\t\tconst sendCall = get(target, p, handler);\n\t\tconst safeSendCall = (...args) => withSafeTimers(async () => {\n\t\t\tconst result = sendCall(...args);\n\t\t\tpromises.add(result);\n\t\t\ttry {\n\t\t\t\treturn await result;\n\t\t\t} finally {\n\t\t\t\tpromises.delete(result);\n\t\t\t}\n\t\t});\n\t\tsafeSendCall.asEvent = sendCall.asEvent;\n\t\treturn safeSendCall;\n\t} });\n}\nfunction rpc() {\n\tconst { rpc } = getWorkerState();\n\treturn rpc;\n}\n\nexport { RealDate as R, rpcDone as a, resetDate as b, createRuntimeRpc as c, mockDate as m, onCancel as o, rpc as r };\n"],"x_google_ignoreList":[0],"mappings":";AA4BA,MAAM,WAAW;AACjB,IAAI,MAAM;AACV,IAAM,WAAN,MAAM,iBAAiB,SAAS;CAC/B,YAAY,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI;EACjC,MAAM;EACN,IAAI;EACJ,QAAQ,UAAU,QAAlB;GACC,KAAK;IACJ,IAAI,QAAQ,MAAM,OAAO,IAAI,SAAS,IAAI,QAAQ,CAAC;SAC9C,OAAO,IAAI,SAAS;IACzB;GACD,KAAK;IACJ,OAAO,IAAI,SAAS,CAAC;IACrB;GACD;IACC,IAAI,OAAO,MAAM,cAAc,IAAI;IACnC,IAAI,KAAK;IACT,IAAI,KAAK;IACT,IAAI,KAAK;IACT,KAAK,MAAM;IACX,OAAO,IAAI,SAAS,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,EAAE;IACxC;EACF;EACA,OAAO,eAAe,MAAM,SAAS,SAAS;EAC9C,OAAO;CACR;AACD;AACA,SAAS,MAAM,SAAS;AACxB,SAAS,MAAM,WAAW;CACzB,OAAO,IAAI,SAAS,CAAC,CAAC,QAAQ;AAC/B;AACA,SAAS,QAAQ,SAAS,YAAY;CACrC,OAAO,SAAS,MAAM,UAAU;AACjC;AACA,SAAS,WAAW,WAAW;CAC9B,OAAO,SAAS,SAAS;AAC1B;AACA,SAAS,SAAS,MAAM;CACvB,MAAM,UAAU,IAAI,SAAS,KAAK,QAAQ,CAAC;CAC3C,IAAI,OAAO,MAAM,QAAQ,QAAQ,CAAC,GAAG,MAAM,IAAI,UAAU,8CAA8C,MAAM;CAE7G,WAAW,OAAO;CAClB,MAAM,QAAQ,QAAQ;AACvB;AACA,SAAS,YAAY;CACpB,WAAW,OAAO;AACnB;AAEA,MAAM,EAAE,QAAQ"}