@mongosh/node-runtime-worker-thread 2.2.4 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(global,(()=>{return e={558:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=s,t.call=function(e){return s(e).apply(null,[].slice.call(arguments,1))};var r,o=n(130),i=(r=o)&&r.__esModule?r:{default:r};function s(e,t){var n=(t=t||{}).addListener||window.addEventListener,r=t.removeListener||window.removeEventListener,o=t.postMessage||window.postMessage,s=t.targetOrigin||"*",u=t.getMessageData||function(e){return e.data};return function(){var t={sender:"postmsg-rpc/client",id:(0,i.default)(),func:e,args:Array.from(arguments)},l=void 0,a=new Promise((function(i,a){var f=function n(){var o=u.apply(null,arguments);if(o&&"postmsg-rpc/server"===o.sender&&o.id===t.id){if(r("message",n),o.err){var s=new Error("Unexpected error calling "+e);return Object.assign(s,o.err),a(s)}i(o.res)}};l=function(){r("message",f);var t=new Error("Canceled call to "+e);t.isCanceled=!0,a(t)},n("message",f),o(t,s)}));return a.cancel=function(){return l()},a}}},246:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(558);Object.defineProperty(t,"caller",{enumerable:!0,get:function(){return i(r).default}}),Object.defineProperty(t,"call",{enumerable:!0,get:function(){return r.call}});var o=n(624);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},624:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){var r=(n=n||{}).addListener||window.addEventListener,o=n.removeListener||window.removeEventListener,i=n.postMessage||window.postMessage,s=n.targetOrigin||"*",u=n.getMessageData||function(e){return e.data},l=n.isCallback||!1,a=function(){var n=u.apply(null,arguments);if(n&&"postmsg-rpc/client"===n.sender&&n.func===e){var r={sender:"postmsg-rpc/server",id:n.id},o=function(e){r.res=e,i(r,s)},a=function(e){r.err=Object.assign({message:e.message},e.output&&e.output.payload),i(r,s)};if(l)t.apply(null,n.args.concat((function(e,t){if(e)return a(e);o(t)})));else{var f=t.apply(null,n.args);Promise.resolve(f).then(o).catch(a)}}};return r("message",a),{close:function(){return o("message",a)}}}},130:(e,t,n)=>{"use strict";e.exports=n(252)},173:(e,t,n)=>{"use strict";var r,o,i,s=n(514),u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function l(){i=!1}function a(e){if(e){if(e!==r){if(e.length!==u.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,n){return t!==n.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. These characters were not unique: "+t.join(", "));r=e,l()}}else r!==u&&(r=u,l())}function f(){return i||(i=function(){r||a(u);for(var e,t=r.split(""),n=[],o=s.nextValue();t.length>0;)o=s.nextValue(),e=Math.floor(o*t.length),n.push(t.splice(e,1)[0]);return n.join("")}())}e.exports={get:function(){return r||u},characters:function(e){return a(e),r},seed:function(e){s.seed(e),o!==e&&(l(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},89:(e,t,n)=>{"use strict";var r,o,i=n(943);n(173),e.exports=function(e){var t="",n=Math.floor(.001*(Date.now()-1567752802062));return n===o?r++:(r=0,o=n),t+=i(7),t+=i(e),r>0&&(t+=i(r)),t+=i(n)}},943:(e,t,n)=>{"use strict";var r=n(173),o=n(908),i=n(137);e.exports=function(e){for(var t,n=0,s="";!t;)s+=i(o,r.get(),1),t=e<Math.pow(16,n+1),n++;return s}},252:(e,t,n)=>{"use strict";var r=n(173),o=n(89),i=n(56),s=n(696)||0;function u(){return o(s)}e.exports=u,e.exports.generate=u,e.exports.seed=function(t){return r.seed(t),e.exports},e.exports.worker=function(t){return s=t,e.exports},e.exports.characters=function(e){return void 0!==e&&r.characters(e),r.shuffled()},e.exports.isValid=i},56:(e,t,n)=>{"use strict";var r=n(173);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+r.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},908:(e,t,n)=>{e.exports=n(701)},514:e=>{"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},696:(e,t,n)=>{"use strict";var r=n(1),o=0;!r.isMaster&&r.worker&&(o=r.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},137:e=>{e.exports=function(e,t,n){for(var r=(2<<31-Math.clz32(t.length-1|1))-1,o=Math.ceil(1.6*r*n/t.length),i="";;)for(var s=e(o),u=o;u--;)if((i+=t[s[u]&r]||"").length===+n)return i}},701:(e,t,n)=>{var r=n(113);if(r.randomFillSync){var o={};e.exports=function(e){var t=o[e];return t||(t=Buffer.allocUnsafe(e),e<=255&&(o[e]=t)),r.randomFillSync(t)}}else e.exports=r.randomBytes},458:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChildProcessEvaluationListener=void 0;const r=n(369),o=n(568);t.ChildProcessEvaluationListener=class ChildProcessEvaluationListener{constructor(e,t){this.exposedListener=(0,r.exposeAll)({onPrompt(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.onPrompt)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:""},onPrint(t){var n,r;return t=t.map(o.deserializeEvaluationResult),null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.onPrint)||void 0===r?void 0:r.call(n,t)},setConfig(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.setConfig)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:Promise.resolve("ignored")},resetConfig(t){var n,r,o;return null!==(o=null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.resetConfig)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:Promise.resolve("ignored")},validateConfig(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.validateConfig)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:Promise.resolve(null)},getConfig(t){var n,r;return null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.getConfig)||void 0===r?void 0:r.call(n,t)},listConfigOptions(){var t,n;return null===(n=null===(t=e.evaluationListener)||void 0===t?void 0:t.listConfigOptions)||void 0===n?void 0:n.call(t)},onClearCommand(){var t,n;return null===(n=null===(t=e.evaluationListener)||void 0===t?void 0:t.onClearCommand)||void 0===n?void 0:n.call(t)},onExit(t){var n,r,o;return null!==(o=null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.onExit)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:Promise.resolve()}},t)}terminate(){this.exposedListener[r.close]()}}},517:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChildProcessMongoshBus=void 0;const r=n(369);t.ChildProcessMongoshBus=class ChildProcessMongoshBus{constructor(e,t){const n=(0,r.exposeAll)({emit(...t){e.emit(...t)},on(){throw new Error("Can't use `on` method on ChildProcessMongoshBus")},once(){throw new Error("Can't use `once` method on ChildProcessMongoshBus")}},t);this.exposedEmitter=n}terminate(){this.exposedEmitter[r.close]()}}},920:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerRuntime=void 0;const o=n(81),i=r(n(17)),s=n(361),u=n(859),l=n(369),a=n(458),f=n(568),c=n(517);t.WorkerRuntime=class WorkerRuntime{constructor(e,t,n={},r={},o=new s.EventEmitter){this.evaluationListener=null,this.childProcessProxySrcPath=process.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING||i.default.resolve(__dirname,"child-process-proxy.js"),this.initOptions={uri:e,driverOptions:t,cliOptions:n,spawnOptions:r},this.eventEmitter=o,this.initWorkerPromise=this.initWorker()}async initWorker(){var e,t,n;const{uri:r,driverOptions:i,cliOptions:u,spawnOptions:h}=this.initOptions;this.childProcess=(0,o.spawn)(process.execPath,[this.childProcessProxySrcPath],{stdio:["inherit","inherit","pipe","ipc"],...h});let g="";null===(n=null===(t=null===(e=this.childProcess)||void 0===e?void 0:e.stderr)||void 0===t?void 0:t.setEncoding("utf8"))||void 0===n||n.on("data",(e=>{g+=e})),await Promise.race([(async()=>{let e;for(;[e]=await(0,s.once)(this.childProcess,"message");)if("ready"===e)return})(),(async()=>{const[e]=await(0,s.once)(this.childProcess,"exit");if(e){let t=function(e){const[,t]=e.split(/^\s*\^\s*$/m).map((e=>e.trim()));if(t){const e=new Error,n=t.substring(0,t.search(/^\s*at/m))||t,[r,...o]=n.split(": ");return e.name=r,e.message=o.join(": ").trim(),e.stack=t,e}return null}(g);throw t?t.message=`Child process failed to start with the following error: ${t.message}`:t=new Error(`Worker runtime failed to start: child process exited with code ${e}`),t}})()]),this.childProcess.setMaxListeners(25),this.childProcessRuntime=(0,l.createCaller)(["init","evaluate","getCompletions","setEvaluationListener","getShellPrompt","interrupt"],this.childProcess),this.childProcessEvaluationListener=new a.ChildProcessEvaluationListener(this,this.childProcess),this.childProcessMongoshBus=new c.ChildProcessMongoshBus(this.eventEmitter,this.childProcess),await this.childProcessRuntime.init(r,(0,f.serializeConnectOptions)(i),u)}async evaluate(e){return await this.initWorkerPromise,(0,f.deserializeEvaluationResult)(await this.childProcessRuntime.evaluate(e))}async getCompletions(e){return await this.initWorkerPromise,await this.childProcessRuntime.getCompletions(e)}async getShellPrompt(){return await this.initWorkerPromise,await this.childProcessRuntime.getShellPrompt()}setEvaluationListener(e){const t=this.evaluationListener;return this.evaluationListener=e,t}async terminate(){try{await this.initWorkerPromise}catch(e){}await(0,u.kill)(this.childProcess),this.childProcessRuntime&&this.childProcessRuntime[l.cancel](),this.childProcessEvaluationListener&&this.childProcessEvaluationListener.terminate(),this.childProcessMongoshBus&&this.childProcessMongoshBus.terminate()}async interrupt(){return await this.initWorkerPromise,this.childProcessRuntime.interrupt()}async waitForRuntimeToBeReady(){await this.initWorkerPromise}}},369:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createCaller=t.exposeAll=t.cancel=t.close=t.removeTrailingUndefined=t.deserialize=t.serialize=void 0;const o=r(n(655)),i=n(246),s=n(568);function u(e){return`data:;base64,${o.default.serialize(e).toString("base64")}`}function l(e){return/^data:;base64,.+/.test(e)?o.default.deserialize(Buffer.from(e.replace("data:;base64,",""),"base64")):e}var a;function f(e){return e&&"object"==typeof e&&"id"in e&&"sender"in e}function c(e){return f(e)&&"postmsg-rpc/server"===e.sender}function h(e){return f(e)&&"postmsg-rpc/client"===e.sender}function g(e){if(Array.isArray(e))for(e=[...e];e.length>0&&void 0===e[e.length-1];)e.pop();return e}function d(e){return{addListener:e.on.bind(e),removeListener:e.off.bind(e),postMessage(t){if(h(t)&&Array.isArray(t.args)&&(t.args=u(g(t.args))),c(t))try{t.res=u(t.res)}catch(e){t.res=u({type:a.Error,payload:(0,s.serializeError)(e)})}return function(e,t){"postMessage"in e&&"function"==typeof e.postMessage&&e.postMessage(t),"send"in e&&"function"==typeof e.send&&e.send(t)}(e,t)},getMessageData:e=>(h(e)&&e.args&&"string"==typeof e.args&&(e.args=l(e.args)),c(e)&&"string"==typeof e.res&&(e.res=l(e.res)),e)}}t.serialize=u,t.deserialize=l,function(e){e[e.Message=0]="Message",e[e.Error=1]="Error"}(a||(a={})),t.removeTrailingUndefined=g,t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel"),t.exposeAll=function(e,n){return Object.entries(e).forEach((([e,t])=>{const{close:r}=(0,i.expose)(e,(async(...e)=>{try{return{type:a.Message,payload:await t(...e)}}catch(e){return{type:a.Error,payload:(0,s.serializeError)(e)}}}),d(n));t.close=r})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,n,r={}){const o={},u=new Set;return e.forEach((e=>{const t=(0,i.caller)(e,d(n));o[e]=async(...n)=>{var o;const i="function"==typeof r[e]?null===(o=r[e])||void 0===o?void 0:o.call(r,...n):n,l=t(...i);u.add(l);const f=await l;if(u.delete(l),(c=f)&&"object"==typeof c&&c.type===a.Error)throw(0,s.deserializeError)(f.payload);var c;return f.payload}})),Object.defineProperty(o,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),o}},568:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deserializeConnectOptions=t.serializeConnectOptions=t.deserializeEvaluationResult=t.serializeEvaluationResult=t.SerializedResultTypes=t.deserializeError=t.serializeError=void 0;const r=n(837),o=n(429);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").filter((t=>"function"!=typeof e[t])).reduce(((t,n)=>(t[n]=e[n],t)),{})}function s(e){return Object.assign(new Error,e)}var u;t.serializeError=i,t.deserializeError=s,function(e){e.SerializedErrorResult="SerializedErrorResult",e.InspectResult="InspectResult",e.SerializedShellApiResult="SerializedShellApiResult"}(u||(t.SerializedResultTypes=u={})),t.serializeEvaluationResult=function({type:e,printable:t,source:n}){return"object"!=typeof(s=t)&&"function"!=typeof s||null===s?{type:e,printable:t,source:n}:function(e){return e&&e.name&&e.message&&e.stack}(t)?{type:u.SerializedErrorResult,printable:i(t),source:n}:null===e?{type:u.InspectResult,printable:(0,r.inspect)(t),source:n}:{type:u.SerializedShellApiResult,printable:{origType:e,serializedValue:o.EJSON.serialize(t)}};var s},t.deserializeEvaluationResult=function({type:e,printable:t,source:n}){return e===u.SerializedErrorResult?{type:e,printable:s(t),source:n}:e===u.SerializedShellApiResult?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:n}:{type:e,printable:t,source:n}};const l=["schemaMap","encryptedFieldsMap"];t.serializeConnectOptions=function(e){var t;const n={...e};for(const e of l)(null===(t=n.autoEncryption)||void 0===t?void 0:t[e])&&(n.autoEncryption={...n.autoEncryption,[e]:o.EJSON.serialize(n.autoEncryption[e],{relaxed:!1})});return n},t.deserializeConnectOptions=function(e){var t;const n={...e};for(const e of l)(null===(t=n.autoEncryption)||void 0===t?void 0:t[e])&&(n.autoEncryption={...n.autoEncryption,[e]:o.EJSON.deserialize(n.autoEncryption[e],{relaxed:!1})});return n}},859:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.kill=void 0;const r=n(81),o=n(361);async function i(e,t="SIGTERM"){e.kill(t),null===e.exitCode&&null===e.signalCode&&await(0,o.once)(e,"exit")}t.kill=i,t.default=function(e,t={},n,o="inherit",s="inherit"){return new Promise(((u,l)=>{const a=Date.now().toString(32),f=(0,r.spawn)(process.execPath,{stdio:["pipe",o,s,"ipc"],...t});if(!f.stdin)return void i(f).then((()=>{l(new Error("Can't write src to the spawned process, missing stdin"))})).catch((e=>{l(e)}));let c;function h(){c&&clearTimeout(c),f.stdin&&f.stdin.off("error",d),f.off("message",p),f.off("exit",g)}function g(e){e&&e>0&&(h(),l(new Error("Child process exited with error before starting")))}async function d(e){h(),await i(f),l(e)}function p(e){e===a&&(h(),u(f))}f.on("message",p),f.on("exit",g),f.stdin.on("error",d),f.stdin.write(e),f.stdin.write(`;process.send(${JSON.stringify(a)})`),f.stdin.end(),c=void 0!==n?setTimeout((async function(){h(),await i(f),l(new Error("Timed out while waiting for child process to start"))}),n):null}))}},81:e=>{"use strict";e.exports=require("child_process")},1:e=>{"use strict";e.exports=require("cluster")},113:e=>{"use strict";e.exports=require("crypto")},361:e=>{"use strict";e.exports=require("events")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")},655:e=>{"use strict";e.exports=require("v8")},429:(e,t,n)=>{"use strict";function r(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function o(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function i(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function s(e){return"[object Map]"===Object.prototype.toString.call(e)}function u(e){return"[object Date]"===Object.prototype.toString.call(e)}function l(e,t){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?{$numberLong:`${t}`}:s(t)?Object.fromEntries(t):t))}const a=6,f=2147483647,c=-2147483648,h=Math.pow(2,63)-1,g=-Math.pow(2,63),d=Math.pow(2,53),p=-Math.pow(2,53),b=1,m=2,y=3,w=4,B=5,S=6,O=7,E=8,N=9,L=10,v=11,x=12,I=13,_=14,U=15,$=16,T=17,j=18,R=19,D=255,A=127,M=0,P=4,z=Object.freeze({double:1,string:2,object:3,array:4,binData:5,undefined:6,objectId:7,bool:8,date:9,null:10,regex:11,dbPointer:12,javascript:13,symbol:14,javascriptWithScope:15,int:16,timestamp:17,long:18,decimal:19,minKey:-1,maxKey:127});class BSONError extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(e,t){super(e,t)}static isBSONError(e){return null!=e&&"object"==typeof e&&"bsonError"in e&&!0===e.bsonError&&"name"in e&&"message"in e&&"stack"in e}}class BSONVersionError extends BSONError{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${a}.x.x`)}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}class BSONOffsetError extends BSONError{get name(){return"BSONOffsetError"}constructor(e,t){super(`${e}. offset: ${t}`),this.offset=t}}const C=128,F=192,V=224,k=240,J=248,q=192,H=224,K=240,Y=128;function Z(e,t,n){let r=0;for(let o=t;o<n;o+=1){const t=e[o];if(r){if((t&F)!==Y)return!1;r-=1}else if(t&C)if((t&V)===q)r=1;else if((t&k)===H)r=2;else{if((t&J)!==K)return!1;r=3}}return!r}function W(e,t,n){if(0===e.length)return"";const r=n-t;if(0===r)return"";if(r>20)return null;if(1===r&&e[t]<128)return String.fromCharCode(e[t]);if(2===r&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(3===r&&e[t]<128&&e[t+1]<128&&e[t+2]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1])+String.fromCharCode(e[t+2]);const o=[];for(let r=t;r<n;r++){const t=e[r];if(t>127)return null;o.push(t)}return String.fromCharCode(...o)}function G(e){return X.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const X={toLocalBufferType(e){if(Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength);const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return Buffer.from(e);throw new BSONError(`Cannot create Buffer from ${String(e)}`)},allocate:e=>Buffer.alloc(e),allocateUnsafe:e=>Buffer.allocUnsafe(e),equals:(e,t)=>X.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),toBase64:e=>X.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>X.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>X.toLocalBufferType(e).toString("hex"),toUTF8(e,t,n,r){const o=n-t<=20?W(e,t,n):null;if(null!=o)return o;const i=X.toLocalBufferType(e).toString("utf8",t,n);if(r)for(let r=0;r<i.length;r++)if(65533===i.charCodeAt(r)){if(!Z(e,t,n))throw new BSONError("Invalid UTF-8 string in BSON document");break}return i},utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into(e,t,n){const r=function(e,t,n){if(0===t.length)return 0;if(t.length>25)return null;if(e.length-n<t.length)return null;for(let r=0,o=n;r<t.length;r++,o++){const n=t.charCodeAt(r);if(n>127)return null;e[o]=n}return t.length}(e,t,n);return null!=r?r:X.toLocalBufferType(e).write(t,n,void 0,"utf8")},randomBytes:(()=>{try{return n(113).randomBytes}catch{return G}})()};function Q(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return ne.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const ee=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(ne.allocate(t));if(function(){const{navigator:e}=globalThis;return"object"==typeof e&&"ReactNative"===e.product}()){const{console:e}=globalThis;e?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.")}return Q})(),te=/(\d|[a-f])/i,ne={toLocalBufferType(e){const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("Uint8Array"===t)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return new Uint8Array(e);throw new BSONError(`Cannot make a Uint8Array from ${String(e)}`)},allocate(e){if("number"!=typeof e)throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},allocateUnsafe:e=>ne.allocate(e),equals(e,t){if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0},fromNumberArray:e=>Uint8Array.from(e),fromBase64:e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))),toBase64:e=>btoa(ne.toISO88591(e)),fromISO88591:e=>Uint8Array.from(e,(e=>255&e.charCodeAt(0))),toISO88591:e=>Array.from(Uint16Array.from(e),(e=>String.fromCharCode(e))).join(""),fromHex(e){const t=e.length%2==0?e:e.slice(0,e.length-1),n=[];for(let e=0;e<t.length;e+=2){const r=t[e],o=t[e+1];if(!te.test(r))break;if(!te.test(o))break;const i=Number.parseInt(`${r}${o}`,16);n.push(i)}return Uint8Array.from(n)},toHex:e=>Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join(""),toUTF8(e,t,n,r){const o=n-t<=20?W(e,t,n):null;if(null!=o)return o;if(r)try{return new TextDecoder("utf8",{fatal:r}).decode(e.slice(t,n))}catch(e){throw new BSONError("Invalid UTF-8 string in BSON document",{cause:e})}return new TextDecoder("utf8",{fatal:r}).decode(e.slice(t,n))},utf8ByteLength:e=>(new TextEncoder).encode(e).byteLength,encodeUTF8Into(e,t,n){const r=(new TextEncoder).encode(t);return e.set(r,n),r.byteLength},randomBytes:ee},re="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?X:ne;class BSONValue{get[Symbol.for("@@mdb.bson.version")](){return a}[Symbol.for("nodejs.util.inspect.custom")](e,t,n){return this.inspect(e,t,n)}}class Binary extends BSONValue{get _bsontype(){return"Binary"}constructor(e,t){if(super(),null!=e&&"string"==typeof e&&!ArrayBuffer.isView(e)&&!r(e)&&!Array.isArray(e))throw new BSONError("Binary can only be constructed from Uint8Array or number[]");this.sub_type=t??Binary.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=re.allocate(Binary.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(e)?re.fromNumberArray(e):re.toLocalBufferType(e),this.position=this.buffer.byteLength)}put(e){if("string"==typeof e&&1!==e.length)throw new BSONError("only accepts single character String");if("number"!=typeof e&&1!==e.length)throw new BSONError("only accepts single character Uint8Array or Array");let t;if(t="string"==typeof e?e.charCodeAt(0):"number"==typeof e?e:e[0],t<0||t>255)throw new BSONError("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=t;else{const e=re.allocate(Binary.BUFFER_SIZE+this.buffer.length);e.set(this.buffer,0),this.buffer=e,this.buffer[this.position++]=t}}write(e,t){if(t="number"==typeof t?t:this.position,this.buffer.byteLength<t+e.length){const t=re.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(re.toLocalBufferType(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position;else if("string"==typeof e)throw new BSONError("input cannot be string")}read(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return re.toBase64(this.buffer)}toString(e){return"hex"===e?re.toHex(this.buffer):"base64"===e?re.toBase64(this.buffer):re.toUTF8(this.buffer,0,this.buffer.byteLength,!1)}toExtendedJSON(e){e=e||{};const t=re.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:1===n.length?"0"+n:n}:{$binary:{base64:t,subType:1===n.length?"0"+n:n}}}toUUID(){if(this.sub_type===Binary.SUBTYPE_UUID)return new UUID(this.buffer.slice(0,this.position));throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(e,t){return new Binary(re.fromHex(e),t)}static createFromBase64(e,t){return new Binary(re.fromBase64(e),t)}static fromExtendedJSON(e,t){let n,r;if(t=t||{},"$binary"in e?t.legacy&&"string"==typeof e.$binary&&"$type"in e?(r=e.$type?parseInt(e.$type,16):0,n=re.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(r=e.$binary.subType?parseInt(e.$binary.subType,16):0,n=re.fromBase64(e.$binary.base64)):"$uuid"in e&&(r=4,n=UUID.bytesFromString(e.$uuid)),!n)throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return r===P?new UUID(n):new Binary(n,r)}inspect(e,t,n){return n??=l,`Binary.createFromBase64(${n(re.toBase64(this.buffer.subarray(0,this.position)),t)}, ${n(this.sub_type,t)})`}}Binary.BSON_BINARY_SUBTYPE_DEFAULT=0,Binary.BUFFER_SIZE=256,Binary.SUBTYPE_DEFAULT=0,Binary.SUBTYPE_FUNCTION=1,Binary.SUBTYPE_BYTE_ARRAY=2,Binary.SUBTYPE_UUID_OLD=3,Binary.SUBTYPE_UUID=4,Binary.SUBTYPE_MD5=5,Binary.SUBTYPE_ENCRYPTED=6,Binary.SUBTYPE_COLUMN=7,Binary.SUBTYPE_SENSITIVE=8,Binary.SUBTYPE_USER_DEFINED=128;const oe=/^[0-9A-F]{32}$/i,ie=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class UUID extends Binary{constructor(e){let t;if(null==e)t=UUID.generate();else if(e instanceof UUID)t=re.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=re.toLocalBufferType(e);else{if("string"!=typeof e)throw new BSONError("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");t=UUID.bytesFromString(e)}super(t,P)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[re.toHex(this.buffer.subarray(0,4)),re.toHex(this.buffer.subarray(4,6)),re.toHex(this.buffer.subarray(6,8)),re.toHex(this.buffer.subarray(8,10)),re.toHex(this.buffer.subarray(10,16))].join("-"):re.toHex(this.buffer)}toString(e){return"hex"===e?re.toHex(this.id):"base64"===e?re.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return re.equals(e.id,this.id);try{return re.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=re.randomBytes(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}static isValid(e){return!!e&&("string"==typeof e?UUID.isValidUUIDString(e):o(e)?16===e.byteLength:"Binary"===e._bsontype&&e.sub_type===this.SUBTYPE_UUID&&16===e.buffer.byteLength)}static createFromHexString(e){const t=UUID.bytesFromString(e);return new UUID(t)}static createFromBase64(e){return new UUID(re.fromBase64(e))}static bytesFromString(e){if(!UUID.isValidUUIDString(e))throw new BSONError("UUID string representation must be 32 hex digits or canonical hyphenated representation");return re.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return oe.test(e)||ie.test(e)}inspect(e,t,n){return n??=l,`new UUID(${n(this.toHexString(),t)})`}}class Code extends BSONValue{get _bsontype(){return"Code"}constructor(e,t){super(),this.code=e.toString(),this.scope=t??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(e){return new Code(e.$code,e.$scope)}inspect(e,t,n){n??=l;let r=n(this.code,t);const o=r.includes("\n");return null!=this.scope&&(r+=`,${o?"\n":" "}${n(this.scope,t)}`),`new Code(${o?"\n":""}${r}${o&&null===this.scope?"\n":""})`}}function se(e){return null!=e&&"object"==typeof e&&"$id"in e&&null!=e.$id&&"$ref"in e&&"string"==typeof e.$ref&&(!("$db"in e)||"$db"in e&&"string"==typeof e.$db)}class DBRef extends BSONValue{get _bsontype(){return"DBRef"}constructor(e,t,n,r){super();const o=e.split(".");2===o.length&&(n=o.shift(),e=o.shift()),this.collection=e,this.oid=t,this.db=n,this.fields=r||{}}get namespace(){return this.collection}set namespace(e){this.collection=e}toJSON(){const e=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(e.$db=this.db),e}toExtendedJSON(e){e=e||{};let t={$ref:this.collection,$id:this.oid};return e.legacy||(this.db&&(t.$db=this.db),t=Object.assign(t,this.fields)),t}static fromExtendedJSON(e){const t=Object.assign({},e);return delete t.$ref,delete t.$id,delete t.$db,new DBRef(e.$ref,e.$id,e.$db,t)}inspect(e,t,n){n??=l;const r=[n(this.namespace,t),n(this.oid,t),...this.db?[n(this.db,t)]:[],...Object.keys(this.fields).length>0?[n(this.fields,t)]:[]];return r[1]=n===l?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}let ue;try{ue=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}const le=4294967296,ae=0x10000000000000000,fe=ae/2,ce={},he={},ge=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(e=0,t,n){super(),"bigint"==typeof e?Object.assign(this,Long.fromBigInt(e,!!t)):"string"==typeof e?Object.assign(this,Long.fromString(e,!!t)):(this.low=0|e,this.high=0|t,this.unsigned=!!n)}static fromBits(e,t,n){return new Long(e,t,n)}static fromInt(e,t){let n,r,o;return t?(o=0<=(e>>>=0)&&e<256)&&(r=he[e],r)?r:(n=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(he[e]=n),n):(o=-128<=(e|=0)&&e<128)&&(r=ce[e],r)?r:(n=Long.fromBits(e,e<0?-1:0,!1),o&&(ce[e]=n),n)}static fromNumber(e,t){if(isNaN(e))return t?Long.UZERO:Long.ZERO;if(t){if(e<0)return Long.UZERO;if(e>=ae)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-fe)return Long.MIN_VALUE;if(e+1>=fe)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%le|0,e/le|0,t)}static fromBigInt(e,t){return Long.fromString(e.toString(),t)}static fromString(e,t,n){if(0===e.length)throw new BSONError("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return Long.ZERO;if("number"==typeof t?(n=t,t=!1):t=!!t,(n=n||10)<2||36<n)throw new BSONError("radix");let r;if((r=e.indexOf("-"))>0)throw new BSONError("interior hyphen");if(0===r)return Long.fromString(e.substring(1),t,n).neg();const o=Long.fromNumber(Math.pow(n,8));let i=Long.ZERO;for(let t=0;t<e.length;t+=8){const r=Math.min(8,e.length-t),s=parseInt(e.substring(t,t+r),n);if(r<8){const e=Long.fromNumber(Math.pow(n,r));i=i.mul(e).add(Long.fromNumber(s))}else i=i.mul(o),i=i.add(Long.fromNumber(s))}return i.unsigned=t,i}static fromBytes(e,t,n){return n?Long.fromBytesLE(e,t):Long.fromBytesBE(e,t)}static fromBytesLE(e,t){return new Long(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)}static fromBytesBE(e,t){return new Long(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)}static isLong(e){return null!=e&&"object"==typeof e&&"__isLong__"in e&&!0===e.__isLong__}static fromValue(e,t){return"number"==typeof e?Long.fromNumber(e,t):"string"==typeof e?Long.fromString(e,t):Long.fromBits(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}add(e){Long.isLong(e)||(e=Long.fromValue(e));const t=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,u=e.low>>>16;let l=0,a=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=r+u,a+=f>>>16,f&=65535,a+=n+s,l+=a>>>16,a&=65535,l+=t+i,l&=65535,Long.fromBits(f<<16|c,l<<16|a,this.unsigned)}and(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low&e.low,this.high&e.high,this.unsigned)}compare(e){if(Long.isLong(e)||(e=Long.fromValue(e)),this.eq(e))return 0;const t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1}comp(e){return this.compare(e)}divide(e){if(Long.isLong(e)||(e=Long.fromValue(e)),e.isZero())throw new BSONError("division by zero");if(ue){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?ue.div_u:ue.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,ue.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Long.UZERO:Long.ZERO;let t,n,r;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return Long.UZERO;if(e.gt(this.shru(1)))return Long.UONE;r=Long.UZERO}else{if(this.eq(Long.MIN_VALUE))return e.eq(Long.ONE)||e.eq(Long.NEG_ONE)?Long.MIN_VALUE:e.eq(Long.MIN_VALUE)?Long.ONE:(t=this.shr(1).div(e).shl(1),t.eq(Long.ZERO)?e.isNegative()?Long.ONE:Long.NEG_ONE:(n=this.sub(e.mul(t)),r=t.add(n.div(e)),r));if(e.eq(Long.MIN_VALUE))return this.unsigned?Long.UZERO:Long.ZERO;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=Long.ZERO}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));const o=Math.ceil(Math.log(t)/Math.LN2),i=o<=48?1:Math.pow(2,o-48);let s=Long.fromNumber(t),u=s.mul(e);for(;u.isNegative()||u.gt(n);)t-=i,s=Long.fromNumber(t,this.unsigned),u=s.mul(e);s.isZero()&&(s=Long.ONE),r=r.add(s),n=n.sub(u)}return r}div(e){return this.divide(e)}equals(e){return Long.isLong(e)||(e=Long.fromValue(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&this.high===e.high&&this.low===e.low}eq(e){return this.equals(e)}getHighBits(){return this.high}getHighBitsUnsigned(){return this.high>>>0}getLowBits(){return this.low}getLowBitsUnsigned(){return this.low>>>0}getNumBitsAbs(){if(this.isNegative())return this.eq(Long.MIN_VALUE)?64:this.neg().getNumBitsAbs();const e=0!==this.high?this.high:this.low;let t;for(t=31;t>0&&0==(e&1<<t);t--);return 0!==this.high?t+33:t+1}greaterThan(e){return this.comp(e)>0}gt(e){return this.greaterThan(e)}greaterThanOrEqual(e){return this.comp(e)>=0}gte(e){return this.greaterThanOrEqual(e)}ge(e){return this.greaterThanOrEqual(e)}isEven(){return 0==(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return 1==(1&this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(e){return this.comp(e)<0}lt(e){return this.lessThan(e)}lessThanOrEqual(e){return this.comp(e)<=0}lte(e){return this.lessThanOrEqual(e)}modulo(e){if(Long.isLong(e)||(e=Long.fromValue(e)),ue){const t=(this.unsigned?ue.rem_u:ue.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,ue.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))}mod(e){return this.modulo(e)}rem(e){return this.modulo(e)}multiply(e){if(this.isZero())return Long.ZERO;if(Long.isLong(e)||(e=Long.fromValue(e)),ue){const t=ue.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,ue.get_high(),this.unsigned)}if(e.isZero())return Long.ZERO;if(this.eq(Long.MIN_VALUE))return e.isOdd()?Long.MIN_VALUE:Long.ZERO;if(e.eq(Long.MIN_VALUE))return this.isOdd()?Long.MIN_VALUE:Long.ZERO;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(Long.TWO_PWR_24)&&e.lt(Long.TWO_PWR_24))return Long.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);const t=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,u=e.low>>>16,l=65535&e.low;let a=0,f=0,c=0,h=0;return h+=o*l,c+=h>>>16,h&=65535,c+=r*l,f+=c>>>16,c&=65535,c+=o*u,f+=c>>>16,c&=65535,f+=n*l,a+=f>>>16,f&=65535,f+=r*u,a+=f>>>16,f&=65535,f+=o*s,a+=f>>>16,f&=65535,a+=t*l+n*u+r*s+o*i,a&=65535,Long.fromBits(c<<16|h,a<<16|f,this.unsigned)}mul(e){return this.multiply(e)}negate(){return!this.unsigned&&this.eq(Long.MIN_VALUE)?Long.MIN_VALUE:this.not().add(Long.ONE)}neg(){return this.negate()}not(){return Long.fromBits(~this.low,~this.high,this.unsigned)}notEquals(e){return!this.equals(e)}neq(e){return this.notEquals(e)}ne(e){return this.notEquals(e)}or(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low|e.low,this.high|e.high,this.unsigned)}shiftLeft(e){return Long.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Long.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):Long.fromBits(0,this.low<<e-32,this.unsigned)}shl(e){return this.shiftLeft(e)}shiftRight(e){return Long.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Long.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):Long.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)}shr(e){return this.shiftRight(e)}shiftRightUnsigned(e){if(Long.isLong(e)&&(e=e.toInt()),0==(e&=63))return this;{const t=this.high;if(e<32){const n=this.low;return Long.fromBits(n>>>e|t<<32-e,t>>>e,this.unsigned)}return 32===e?Long.fromBits(t,0,this.unsigned):Long.fromBits(t>>>e-32,0,this.unsigned)}}shr_u(e){return this.shiftRightUnsigned(e)}shru(e){return this.shiftRightUnsigned(e)}subtract(e){return Long.isLong(e)||(e=Long.fromValue(e)),this.add(e.neg())}sub(e){return this.subtract(e)}toInt(){return this.unsigned?this.low>>>0:this.low}toNumber(){return this.unsigned?(this.high>>>0)*le+(this.low>>>0):this.high*le+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(e){return e?this.toBytesLE():this.toBytesBE()}toBytesLE(){const e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]}toBytesBE(){const e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]}toSigned(){return this.unsigned?Long.fromBits(this.low,this.high,!1):this}toString(e){if((e=e||10)<2||36<e)throw new BSONError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(Long.MIN_VALUE)){const t=Long.fromNumber(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}const t=Long.fromNumber(Math.pow(e,6),this.unsigned);let n=this,r="";for(;;){const o=n.div(t);let i=(n.sub(o.mul(t)).toInt()>>>0).toString(e);if(n=o,n.isZero())return i+r;for(;i.length<6;)i="0"+i;r=""+i+r}}toUnsigned(){return this.unsigned?this:Long.fromBits(this.low,this.high,!0)}xor(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low^e.low,this.high^e.high,this.unsigned)}eqz(){return this.isZero()}le(e){return this.lessThanOrEqual(e)}toExtendedJSON(e){return e&&e.relaxed?this.toNumber():{$numberLong:this.toString()}}static fromExtendedJSON(e,t){const{useBigInt64:n=!1,relaxed:r=!0}={...t};if(e.$numberLong.length>20)throw new BSONError("$numberLong string is too long");if(!ge.test(e.$numberLong))throw new BSONError(`$numberLong string "${e.$numberLong}" is in an invalid format`);if(n){const t=BigInt(e.$numberLong);return BigInt.asIntN(64,t)}const o=Long.fromString(e.$numberLong);return r?o.toNumber():o}inspect(e,t,n){return n??=l,`new Long(${n(this.toString(),t)}${this.unsigned?`, ${n(this.unsigned,t)}`:""})`}}Long.TWO_PWR_24=Long.fromInt(1<<24),Long.MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0),Long.ZERO=Long.fromInt(0),Long.UZERO=Long.fromInt(0,!0),Long.ONE=Long.fromInt(1),Long.UONE=Long.fromInt(1,!0),Long.NEG_ONE=Long.fromInt(-1),Long.MAX_VALUE=Long.fromBits(-1,2147483647,!1),Long.MIN_VALUE=Long.fromBits(0,-2147483648,!1);const de=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,pe=/^(\+|-)?(Infinity|inf)$/i,be=/^(\+|-)?NaN$/i,me=6111,ye=-6176,we=re.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Be=re.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Se=re.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Oe=/^([-+])?(\d+)?$/;function Ee(e){return!isNaN(parseInt(e,10))}function Ne(e){const t=Long.fromNumber(1e9);let n=Long.fromNumber(0);if(!(e.parts[0]||e.parts[1]||e.parts[2]||e.parts[3]))return{quotient:e,rem:n};for(let r=0;r<=3;r++)n=n.shiftLeft(32),n=n.add(new Long(e.parts[r],0)),e.parts[r]=n.div(t).low,n=n.modulo(t);return{quotient:e,rem:n}}function Le(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!o(e))throw new BSONError("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new BSONError("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}static fromString(e){return Decimal128._fromString(e,{allowRounding:!1})}static fromStringWithRounding(e){return Decimal128._fromString(e,{allowRounding:!0})}static _fromString(e,t){let n=!1,r=!1,o=!1,i=!1,s=0,u=0,l=0,a=0,f=0;const c=[0];let h=0,g=0,d=0,p=0,b=new Long(0,0),m=new Long(0,0),y=0,w=0;if(e.length>=7e3)throw new BSONError(e+" not a valid Decimal128 string");const B=e.match(de),S=e.match(pe),O=e.match(be);if(!B&&!S&&!O||0===e.length)throw new BSONError(e+" not a valid Decimal128 string");if(B){const t=B[2],n=B[4],r=B[5],o=B[6];n&&void 0===o&&Le(e,"missing exponent power"),n&&void 0===t&&Le(e,"missing exponent base"),void 0===n&&(r||o)&&Le(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(r=!0,n="-"===e[w++]),!Ee(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(n?Be:Se);if("N"===e[w])return new Decimal128(we)}for(;Ee(e[w])||"."===e[w];)"."!==e[w]?(h<34&&("0"!==e[w]||i)&&(i||(f=u),i=!0,c[g++]=parseInt(e[w],10),h+=1),i&&(l+=1),o&&(a+=1),u+=1,w+=1):(o&&Le(e,"contains multiple periods"),o=!0,w+=1);if(o&&!u)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(Oe);if(!t||!t[2])return new Decimal128(we);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(we);if(h){if(d=h-1,s=l,1!==s)for(;"0"===e[f+s-1+Number(r)+Number(o)];)s-=1}else c[0]=0,l=1,h=1,s=0;for(p<=a&&a>p+16384?p=ye:p-=a;p>me;){if(d+=1,d>=34){if(0===s){p=me;break}Le(e,"overflow")}p-=1}if(t.allowRounding){for(;p<ye||h<l;){if(0===d&&s<h){p=ye,s=0;break}if(h<l?l-=1:d-=1,p<me)p+=1;else{if(c.join("").match(/^0+$/)){p=me;break}Le(e,"overflow")}}if(d+1<s){let t=u;o&&(f+=1,t+=1),r&&(f+=1,t+=1);const i=parseInt(e[f+d+1],10);let s=0;if(i>=5&&(s=1,5===i)){s=c[d]%2==1?1:0;for(let n=f+d+2;n<t;n++)if(parseInt(e[n],10)){s=1;break}}if(s){let e=d;for(;e>=0&&++c[e]>9;e--)if(c[e]=0,0===e){if(!(p<me))return new Decimal128(n?Be:Se);p+=1,c[e]=1}}}}else{for(;p<ye||h<l;){if(0===d){if(0===s){p=ye;break}Le(e,"exponent underflow")}h<l?("0"!==e[l-1+Number(r)+Number(o)]&&0!==s&&Le(e,"inexact rounding"),l-=1):(0!==c[d]&&Le(e,"inexact rounding"),d-=1),p<me?p+=1:Le(e,"overflow")}d+1<s&&(o&&(f+=1),r&&(f+=1),0!==parseInt(e[f+d+1],10)&&Le(e,"inexact rounding"))}if(b=Long.fromNumber(0),m=Long.fromNumber(0),0===s)b=Long.fromNumber(0),m=Long.fromNumber(0);else if(d<17){let e=0;for(m=Long.fromNumber(c[e++]),b=new Long(0,0);e<=d;e++)m=m.multiply(Long.fromNumber(10)),m=m.add(Long.fromNumber(c[e]))}else{let e=0;for(b=Long.fromNumber(c[e++]);e<=d-17;e++)b=b.multiply(Long.fromNumber(10)),b=b.add(Long.fromNumber(c[e]));for(m=Long.fromNumber(c[e++]);e<=d;e++)m=m.multiply(Long.fromNumber(10)),m=m.add(Long.fromNumber(c[e]))}const E=function(e,t){if(!e&&!t)return{high:Long.fromNumber(0),low:Long.fromNumber(0)};const n=e.shiftRightUnsigned(32),r=new Long(e.getLowBits(),0),o=t.shiftRightUnsigned(32),i=new Long(t.getLowBits(),0);let s=n.multiply(o),u=n.multiply(i);const l=r.multiply(o);let a=r.multiply(i);return s=s.add(u.shiftRightUnsigned(32)),u=new Long(u.getLowBits(),0).add(l).add(a.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),a=u.shiftLeft(32).add(new Long(a.getLowBits(),0)),{high:s,low:a}}(b,Long.fromString("100000000000000000"));E.low=E.low.add(m),function(e,t){const n=e.high>>>0,r=t.high>>>0;return n<r||n===r&&e.low>>>0<t.low>>>0}(E.low,m)&&(E.high=E.high.add(Long.fromNumber(1))),y=p+6176;const N={low:Long.fromNumber(0),high:Long.fromNumber(0)};E.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))?(N.high=N.high.or(Long.fromNumber(3).shiftLeft(61)),N.high=N.high.or(Long.fromNumber(y).and(Long.fromNumber(16383).shiftLeft(47))),N.high=N.high.or(E.high.and(Long.fromNumber(0x7fffffffffff)))):(N.high=N.high.or(Long.fromNumber(16383&y).shiftLeft(49)),N.high=N.high.or(E.high.and(Long.fromNumber(562949953421311)))),N.low=E.low,n&&(N.high=N.high.or(Long.fromString("9223372036854775808")));const L=re.allocateUnsafe(16);return w=0,L[w++]=255&N.low.low,L[w++]=N.low.low>>8&255,L[w++]=N.low.low>>16&255,L[w++]=N.low.low>>24&255,L[w++]=255&N.low.high,L[w++]=N.low.high>>8&255,L[w++]=N.low.high>>16&255,L[w++]=N.low.high>>24&255,L[w++]=255&N.high.low,L[w++]=N.high.low>>8&255,L[w++]=N.high.low>>16&255,L[w++]=N.high.low>>24&255,L[w++]=255&N.high.high,L[w++]=N.high.high>>8&255,L[w++]=N.high.high>>16&255,L[w++]=N.high.high>>24&255,new Decimal128(L)}toString(){let e,t=0;const n=new Array(36);for(let e=0;e<n.length;e++)n[e]=0;let r,o,i,s=0,u=!1,l={parts:[0,0,0,0]};const a=[];s=0;const f=this.bytes,c=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,g=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,d=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new Long(c,h),new Long(g,d)).lessThan(Long.ZERO)&&a.push("-");const p=d>>26&31;if(p>>3==3){if(30===p)return a.join("")+"Infinity";if(31===p)return"NaN";e=d>>15&16383,r=8+(d>>14&1)}else r=d>>14&7,e=d>>17&16383;const b=e-6176;if(l.parts[0]=(16383&d)+((15&r)<<14),l.parts[1]=g,l.parts[2]=h,l.parts[3]=c,0===l.parts[0]&&0===l.parts[1]&&0===l.parts[2]&&0===l.parts[3])u=!0;else for(i=3;i>=0;i--){let e=0;const t=Ne(l);if(l=t.quotient,e=t.rem.low,e)for(o=8;o>=0;o--)n[9*i+o]=e%10,e=Math.floor(e/10)}if(u)t=1,n[s]=0;else for(t=36;!n[s];)t-=1,s+=1;const m=t-1+b;if(m>=34||m<=-7||b>0){if(t>34)return a.push("0"),b>0?a.push(`E+${b}`):b<0&&a.push(`E${b}`),a.join("");a.push(`${n[s++]}`),t-=1,t&&a.push(".");for(let e=0;e<t;e++)a.push(`${n[s++]}`);a.push("E"),m>0?a.push(`+${m}`):a.push(`${m}`)}else if(b>=0)for(let e=0;e<t;e++)a.push(`${n[s++]}`);else{let e=t+b;if(e>0)for(let t=0;t<e;t++)a.push(`${n[s++]}`);else a.push("0");for(a.push(".");e++<0;)a.push("0");for(let r=0;r<t-Math.max(e-1,0);r++)a.push(`${n[s++]}`)}return a.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(e){return Decimal128.fromString(e.$numberDecimal)}inspect(e,t,n){return n??=l,`new Decimal128(${n(this.toString(),t)})`}}class Double extends BSONValue{get _bsontype(){return"Double"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=+e}valueOf(){return this.value}toJSON(){return this.value}toString(e){return this.value.toString(e)}toExtendedJSON(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(e,t){const n=parseFloat(e.$numberDouble);return t&&t.relaxed?n:new Double(n)}inspect(e,t,n){return n??=l,`new Double(${n(this.value,t)})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}valueOf(){return this.value}toString(e){return this.value.toString(e)}toJSON(){return this.value}toExtendedJSON(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new Int32(e.$numberInt)}inspect(e,t,n){return n??=l,`new Int32(${n(this.value,t)})`}}class MaxKey extends BSONValue{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new MaxKey}inspect(){return"new MaxKey()"}}class MinKey extends BSONValue{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new MinKey}inspect(){return"new MinKey()"}}const ve=new Float64Array(1),xe=new Uint8Array(ve.buffer,0,8);ve[0]=-1;const Ie=0===xe[7],_e={getInt32LE:(e,t)=>e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,getUint32LE:(e,t)=>e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3],getUint32BE:(e,t)=>e[t+3]+256*e[t+2]+65536*e[t+1]+16777216*e[t],getBigInt64LE(e,t){const n=_e.getUint32LE(e,t),r=_e.getUint32LE(e,t+4);return(BigInt(r)<<BigInt(32))+BigInt(n)},getFloat64LE:Ie?(e,t)=>(xe[7]=e[t],xe[6]=e[t+1],xe[5]=e[t+2],xe[4]=e[t+3],xe[3]=e[t+4],xe[2]=e[t+5],xe[1]=e[t+6],xe[0]=e[t+7],ve[0]):(e,t)=>(xe[0]=e[t],xe[1]=e[t+1],xe[2]=e[t+2],xe[3]=e[t+3],xe[4]=e[t+4],xe[5]=e[t+5],xe[6]=e[t+6],xe[7]=e[t+7],ve[0]),setInt32BE:(e,t,n)=>(e[t+3]=n,n>>>=8,e[t+2]=n,n>>>=8,e[t+1]=n,n>>>=8,e[t]=n,4),setInt32LE:(e,t,n)=>(e[t]=n,n>>>=8,e[t+1]=n,n>>>=8,e[t+2]=n,n>>>=8,e[t+3]=n,4),setBigInt64LE(e,t,n){const r=BigInt(4294967295);let o=Number(n&r);e[t]=o,o>>=8,e[t+1]=o,o>>=8,e[t+2]=o,o>>=8,e[t+3]=o;let i=Number(n>>BigInt(32)&r);return e[t+4]=i,i>>=8,e[t+5]=i,i>>=8,e[t+6]=i,i>>=8,e[t+7]=i,8},setFloat64LE:Ie?(e,t,n)=>(ve[0]=n,e[t]=xe[7],e[t+1]=xe[6],e[t+2]=xe[5],e[t+3]=xe[4],e[t+4]=xe[3],e[t+5]=xe[2],e[t+6]=xe[1],e[t+7]=xe[0],8):(e,t,n)=>(ve[0]=n,e[t]=xe[0],e[t+1]=xe[1],e[t+2]=xe[2],e[t+3]=xe[3],e[t+4]=xe[4],e[t+5]=xe[5],e[t+6]=xe[6],e[t+7]=xe[7],8)},Ue=new RegExp("^[0-9a-fA-F]{24}$");let $e=null;class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}constructor(e){let t;if(super(),"object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new BSONError("Argument passed in must have an id that is of type string or Buffer");t="toHexString"in e&&"function"==typeof e.toHexString?re.fromHex(e.toHexString()):e.id}else t=e;if(null==t||"number"==typeof t)this.buffer=ObjectId.generate("number"==typeof t?t:void 0);else if(ArrayBuffer.isView(t)&&12===t.byteLength)this.buffer=re.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(24!==t.length||!Ue.test(t))throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=re.fromHex(t)}ObjectId.cacheHexString&&(this.__id=re.toHex(this.id))}get id(){return this.buffer}set id(e){this.buffer=e,ObjectId.cacheHexString&&(this.__id=re.toHex(e))}toHexString(){if(ObjectId.cacheHexString&&this.__id)return this.__id;const e=re.toHex(this.id);return ObjectId.cacheHexString&&!this.__id&&(this.__id=e),e}static getInc(){return ObjectId.index=(ObjectId.index+1)%16777215}static generate(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));const t=ObjectId.getInc(),n=re.allocateUnsafe(12);return _e.setInt32BE(n,0,e),null===$e&&($e=re.randomBytes(5)),n[4]=$e[0],n[5]=$e[1],n[6]=$e[2],n[7]=$e[3],n[8]=$e[4],n[11]=255&t,n[10]=t>>8&255,n[9]=t>>16&255,n}toString(e){return"base64"===e?re.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"ObjectId"===e._bsontype}equals(e){if(null==e)return!1;if(ObjectId.is(e))return this.buffer[11]===e.buffer[11]&&re.equals(this.buffer,e.buffer);if("string"==typeof e)return e.toLowerCase()===this.toHexString();if("object"==typeof e&&"function"==typeof e.toHexString){const t=e.toHexString(),n=this.toHexString();return"string"==typeof t&&t.toLowerCase()===n}return!1}getTimestamp(){const e=new Date,t=_e.getUint32BE(this.buffer,0);return e.setTime(1e3*Math.floor(t)),e}static createPk(){return new ObjectId}serializeInto(e,t){return e[t]=this.buffer[0],e[t+1]=this.buffer[1],e[t+2]=this.buffer[2],e[t+3]=this.buffer[3],e[t+4]=this.buffer[4],e[t+5]=this.buffer[5],e[t+6]=this.buffer[6],e[t+7]=this.buffer[7],e[t+8]=this.buffer[8],e[t+9]=this.buffer[9],e[t+10]=this.buffer[10],e[t+11]=this.buffer[11],12}static createFromTime(e){const t=re.allocate(12);for(let e=11;e>=4;e--)t[e]=0;return _e.setInt32BE(t,0,e),new ObjectId(t)}static createFromHexString(e){if(24!==e?.length)throw new BSONError("hex string must be 24 characters");return new ObjectId(re.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(re.fromBase64(e))}static isValid(e){if(null==e)return!1;try{return new ObjectId(e),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(e){return new ObjectId(e.$oid)}inspect(e,t,n){return n??=l,`new ObjectId(${n(this.toHexString(),t)})`}}function Te(e,t,n){let r=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)r+=je(o.toString(),e[o],t,!0,n);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))r+=je(o,e[o],t,!1,n)}return r}function je(e,t,n=!1,o=!1,s=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+re.utf8ByteLength(e)+1+4+re.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=p&&t<=d&&t>=c&&t<=f?(null!=e?re.utf8ByteLength(e)+1:0)+5:(null!=e?re.utf8ByteLength(e)+1:0)+9;case"undefined":return o||!s?(null!=e?re.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?re.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&t[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?re.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?re.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||u(t))return(null!=e?re.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||r(t))return(null!=e?re.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?re.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?re.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?re.utf8ByteLength(e)+1:0)+1+4+4+re.utf8ByteLength(t.code.toString())+1+Te(t.scope,n,s):(null!=e?re.utf8ByteLength(e)+1:0)+1+4+re.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const n=t;return n.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?re.utf8ByteLength(e)+1:0)+(n.position+1+4+1+4):(null!=e?re.utf8ByteLength(e)+1:0)+(n.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?re.utf8ByteLength(e)+1:0)+re.utf8ByteLength(t.value)+4+1+1;if("DBRef"===t._bsontype){const r=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(r.$db=t.db),(null!=e?re.utf8ByteLength(e)+1:0)+1+Te(r,n,s)}return t instanceof RegExp||i(t)?(null!=e?re.utf8ByteLength(e)+1:0)+1+re.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?re.utf8ByteLength(e)+1:0)+1+re.utf8ByteLength(t.pattern)+1+re.utf8ByteLength(t.options)+1:(null!=e?re.utf8ByteLength(e)+1:0)+Te(t,n,s)+1;case"function":if(n)return(null!=e?re.utf8ByteLength(e)+1:0)+1+4+re.utf8ByteLength(t.toString())+1}return 0}ObjectId.index=Math.floor(16777215*Math.random());class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}constructor(e,t){if(super(),this.pattern=e,this.options=(t??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let e=0;e<this.options.length;e++)if("i"!==this.options[e]&&"m"!==this.options[e]&&"x"!==this.options[e]&&"l"!==this.options[e]&&"s"!==this.options[e]&&"u"!==this.options[e])throw new BSONError(`The regular expression option [${this.options[e]}] is not supported`)}static parseOptions(e){return e?e.split("").sort().join(""):""}toExtendedJSON(e){return(e=e||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(e){if("$regex"in e){if("string"==typeof e.$regex)return new BSONRegExp(e.$regex,BSONRegExp.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new BSONRegExp(e.$regularExpression.pattern,BSONRegExp.parseOptions(e.$regularExpression.options));throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(e)}`)}inspect(e,t,n){const r=function(e){if(null!=e&&"object"==typeof e&&"stylize"in e&&"function"==typeof e.stylize)return e.stylize}(t)??(e=>e);return n??=l,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}constructor(e){super(),this.value=e}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(e){return new BSONSymbol(e.$symbol)}inspect(e,t,n){return n??=l,`new BSONSymbol(${n(this.value,t)})`}}const Re=Long;class Timestamp extends Re{get _bsontype(){return"Timestamp"}constructor(e){if(null==e)super(0,0,!0);else if("bigint"==typeof e)super(e,!0);else if(Long.isLong(e))super(e.low,e.high,!0);else{if("object"!=typeof e||!("t"in e)||!("i"in e))throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");{if("number"!=typeof e.t&&("object"!=typeof e.t||"Int32"!==e.t._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof e.i&&("object"!=typeof e.i||"Int32"!==e.i._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");const t=Number(e.t),n=Number(e.i);if(t<0||Number.isNaN(t))throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");if(t>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(n,t,!0)}}}toJSON(){return{$timestamp:this.toString()}}static fromInt(e){return new Timestamp(Long.fromInt(e,!0))}static fromNumber(e){return new Timestamp(Long.fromNumber(e,!0))}static fromBits(e,t){return new Timestamp({i:e,t})}static fromString(e,t){return new Timestamp(Long.fromString(e,!0,t))}toExtendedJSON(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,n=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:n,i:t})}inspect(e,t,n){return n??=l,`new Timestamp({ t: ${n(this.high>>>0,t)}, i: ${n(this.low>>>0,t)} })`}}Timestamp.MAX_VALUE=Long.MAX_UNSIGNED_VALUE;const De=Long.fromNumber(d),Ae=Long.fromNumber(p);function Me(e,t,n){const r=(t=null==t?{}:t)&&t.index?t.index:0,o=_e.getInt32LE(e,r);if(o<5)throw new BSONError(`bson size must be >= 5, is ${o}`);if(t.allowObjectSmallerThanBufferSize&&e.length<o)throw new BSONError(`buffer length ${e.length} must be >= bson size ${o}`);if(!t.allowObjectSmallerThanBufferSize&&e.length!==o)throw new BSONError(`buffer length ${e.length} must === bson size ${o}`);if(o+r>e.byteLength)throw new BSONError(`(bson size ${o} + options.index ${r} must be <= buffer length ${e.byteLength})`);if(0!==e[r+o-1])throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return ze(e,r,t,n)}const Pe=/^\$ref$|^\$id$|^\$db$/;function ze(e,t,n,r=!1){const o=null==n.fieldsAsRaw?null:n.fieldsAsRaw,i=null!=n.raw&&n.raw,s="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,u=n.promoteBuffers??!1,l=n.promoteLongs??!0,a=n.promoteValues??!0,f=n.useBigInt64??!1;if(f&&!a)throw new BSONError("Must either request bigint or Long for int64 deserialization");if(f&&!l)throw new BSONError("Must either request bigint or Long for int64 deserialization");const c=null==n.validation?{utf8:!0}:n.validation;let h,g,d=!0;const p=c.utf8;if("boolean"==typeof p)h=p;else{d=!1;const e=Object.keys(p).map((function(e){return p[e]}));if(0===e.length)throw new BSONError("UTF-8 validation setting cannot be empty");if("boolean"!=typeof e[0])throw new BSONError("Invalid UTF-8 validation option, must specify boolean values");if(h=e[0],!e.every((e=>e===h)))throw new BSONError("Invalid UTF-8 validation option - keys must be all true or all false")}if(!d){g=new Set;for(const e of Object.keys(p))g.add(e)}const M=t;if(e.length<5)throw new BSONError("corrupt bson message < 5 bytes long");const z=_e.getInt32LE(e,t);if(t+=4,z<5||z>e.length)throw new BSONError("corrupt bson message");const C=r?[]:{};let F=0,V=!r&&null;for(;;){const p=e[t++];if(0===p)break;let M=t;for(;0!==e[M]&&M<e.length;)M++;if(M>=e.byteLength)throw new BSONError("Bad BSON Document: illegal CString");const z=r?F++:re.toUTF8(e,t,M,!1);let k,J=!0;if(J=d||g?.has(z)?h:!h,!1!==V&&"$"===z[0]&&(V=Pe.test(z)),t=M+1,p===m){const n=_e.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");k=re.toUTF8(e,t,t+n-1,J),t+=n}else if(p===O){const n=re.allocateUnsafe(12);for(let r=0;r<12;r++)n[r]=e[t+r];k=new ObjectId(n),t+=12}else if(p===$&&!1===a)k=new Int32(_e.getInt32LE(e,t)),t+=4;else if(p===$)k=_e.getInt32LE(e,t),t+=4;else if(p===b)k=_e.getFloat64LE(e,t),t+=8,!1===a&&(k=new Double(k));else if(p===N){const n=_e.getInt32LE(e,t),r=_e.getInt32LE(e,t+4);t+=8,k=new Date(new Long(n,r).toNumber())}else if(p===E){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");k=1===e[t++]}else if(p===y){const r=t,o=_e.getInt32LE(e,t);if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)k=e.slice(t,t+o);else{let t=n;d||(t={...n,validation:{utf8:J}}),k=ze(e,r,t,!1)}t+=o}else if(p===w){const r=t,i=_e.getInt32LE(e,t);let s=n;const u=t+i;if(o&&o[z]&&(s={...n,raw:!0}),d||(s={...s,validation:{utf8:J}}),k=ze(e,r,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==u)throw new BSONError("corrupted array bson")}else if(p===S)k=void 0;else if(p===L)k=null;else if(p===j)if(f)k=_e.getBigInt64LE(e,t),t+=8;else{const n=_e.getInt32LE(e,t),r=_e.getInt32LE(e,t+4);t+=8;const o=new Long(n,r);k=l&&!0===a&&o.lessThanOrEqual(De)&&o.greaterThanOrEqual(Ae)?o.toNumber():o}else if(p===R){const n=re.allocateUnsafe(16);for(let r=0;r<16;r++)n[r]=e[t+r];t+=16,k=new Decimal128(n)}else if(p===B){let n=_e.getInt32LE(e,t);t+=4;const r=n,o=e[t++];if(n<0)throw new BSONError("Negative binary type element size found");if(n>e.byteLength)throw new BSONError("Binary type size larger than document size");if(null!=e.slice){if(o===Binary.SUBTYPE_BYTE_ARRAY){if(n=_e.getInt32LE(e,t),t+=4,n<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}u&&a?k=re.toLocalBufferType(e.slice(t,t+n)):(k=new Binary(e.slice(t,t+n),o),o===P&&UUID.isValid(k)&&(k=k.toUUID()))}else{if(o===Binary.SUBTYPE_BYTE_ARRAY){if(n=_e.getInt32LE(e,t),t+=4,n<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}if(u&&a)for(k=re.allocateUnsafe(n),M=0;M<n;M++)k[M]=e[t+M];else k=new Binary(e.slice(t,t+n),o),o===P&&UUID.isValid(k)&&(k=k.toUUID())}t+=n}else if(p===v&&!1===s){for(M=t;0!==e[M]&&M<e.length;)M++;if(M>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=re.toUTF8(e,t,M,!1);for(M=t=M+1;0!==e[M]&&M<e.length;)M++;if(M>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=re.toUTF8(e,t,M,!1);t=M+1;const o=new Array(r.length);for(M=0;M<r.length;M++)switch(r[M]){case"m":o[M]="m";break;case"s":o[M]="g";break;case"i":o[M]="i"}k=new RegExp(n,o.join(""))}else if(p===v&&!0===s){for(M=t;0!==e[M]&&M<e.length;)M++;if(M>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=re.toUTF8(e,t,M,!1);for(M=t=M+1;0!==e[M]&&M<e.length;)M++;if(M>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=re.toUTF8(e,t,M,!1);t=M+1,k=new BSONRegExp(n,r)}else if(p===_){const n=_e.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");const r=re.toUTF8(e,t,t+n-1,J);k=a?r:new BSONSymbol(r),t+=n}else if(p===T)k=new Timestamp({i:_e.getUint32LE(e,t),t:_e.getUint32LE(e,t+4)}),t+=8;else if(p===D)k=new MinKey;else if(p===A)k=new MaxKey;else if(p===I){const n=_e.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");const r=re.toUTF8(e,t,t+n-1,J);k=new Code(r),t+=n}else if(p===U){const r=_e.getInt32LE(e,t);if(t+=4,r<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=_e.getInt32LE(e,t);if(t+=4,o<=0||o>e.length-t||0!==e[t+o-1])throw new BSONError("bad string length in bson");const i=re.toUTF8(e,t,t+o-1,J),s=t+=o,u=_e.getInt32LE(e,t),l=ze(e,s,n,!1);if(t+=u,r<8+u+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(r>8+u+o)throw new BSONError("code_w_scope total size is too long, clips outer document");k=new Code(i,l)}else{if(p!==x)throw new BSONError(`Detected unknown BSON type ${p.toString(16)} for fieldname "${z}"`);{const n=_e.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");if(null!=c&&c.utf8&&!Z(e,t,t+n-1))throw new BSONError("Invalid UTF-8 string in BSON document");const r=re.toUTF8(e,t,t+n-1,!1);t+=n;const o=re.allocateUnsafe(12);for(let n=0;n<12;n++)o[n]=e[t+n];const i=new ObjectId(o);t+=12,k=new DBRef(r,i)}}"__proto__"===z?Object.defineProperty(C,z,{value:k,writable:!0,enumerable:!0,configurable:!0}):C[z]=k}if(z!==t-M){if(r)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!V)return C;if(se(C)){const e=Object.assign({},C);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(C.$ref,C.$id,C.$db,e)}return C}const Ce=/\x00/,Fe=new Set(["$db","$ref","$id","$clusterTime"]);function Ve(e,t,n,r){e[r++]=m,e[(r=r+re.encodeUTF8Into(e,t,r)+1)-1]=0;const o=re.encodeUTF8Into(e,n,r+4);return _e.setInt32LE(e,r,o+1),r=r+4+o,e[r++]=0,r}function ke(e,t,n,r){const o=!Object.is(n,-0)&&Number.isSafeInteger(n)&&n<=f&&n>=c?$:b;return e[r++]=o,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r+=o===$?_e.setInt32LE(e,r,n):_e.setFloat64LE(e,r,n)}function Je(e,t,n,r){return e[r++]=j,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r+=_e.setBigInt64LE(e,r,n)}function qe(e,t,n,r){return e[r++]=L,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r}function He(e,t,n,r){return e[r++]=E,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,e[r++]=n?1:0,r}function Ke(e,t,n,r){e[r++]=N,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=Long.fromNumber(n.getTime()),i=o.getLowBits(),s=o.getHighBits();return r+=_e.setInt32LE(e,r,i),r+=_e.setInt32LE(e,r,s)}function Ye(e,t,n,r){if(e[r++]=v,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,n.source&&null!=n.source.match(Ce))throw new BSONError("value "+n.source+" must not contain null bytes");return r+=re.encodeUTF8Into(e,n.source,r),e[r++]=0,n.ignoreCase&&(e[r++]=105),n.global&&(e[r++]=115),n.multiline&&(e[r++]=109),e[r++]=0,r}function Ze(e,t,n,r){if(e[r++]=v,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,null!=n.pattern.match(Ce))throw new BSONError("pattern "+n.pattern+" must not contain null bytes");r+=re.encodeUTF8Into(e,n.pattern,r),e[r++]=0;const o=n.options.split("").sort().join("");return r+=re.encodeUTF8Into(e,o,r),e[r++]=0,r}function We(e,t,n,r){return null===n?e[r++]=L:"MinKey"===n._bsontype?e[r++]=D:e[r++]=A,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r}function Ge(e,t,n,r){return e[r++]=O,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r+=n.serializeInto(e,r)}function Xe(e,t,n,r){e[r++]=B,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.length;if(r+=_e.setInt32LE(e,r,o),e[r++]=M,o<=16)for(let t=0;t<o;t++)e[r+t]=n[t];else e.set(n,r);return r+=o}function Qe(e,t,n,r,o,i,s,u,l){if(l.has(n))throw new BSONError("Cannot convert circular structure to BSON");l.add(n),e[r++]=Array.isArray(n)?w:y,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const a=at(e,n,o,r,i+1,s,u,l);return l.delete(n),a}function et(e,t,n,r){e[r++]=R,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;for(let t=0;t<16;t++)e[r+t]=n.bytes[t];return r+16}function tt(e,t,n,r){e[r++]="Long"===n._bsontype?j:T,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.getLowBits(),i=n.getHighBits();return r+=_e.setInt32LE(e,r,o),r+=_e.setInt32LE(e,r,i)}function nt(e,t,n,r){return n=n.valueOf(),e[r++]=$,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r+=_e.setInt32LE(e,r,n)}function rt(e,t,n,r){return e[r++]=b,r+=re.encodeUTF8Into(e,t,r),e[r++]=0,r+=_e.setFloat64LE(e,r,n.value)}function ot(e,t,n,r){e[r++]=I,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.toString(),i=re.encodeUTF8Into(e,o,r+4)+1;return _e.setInt32LE(e,r,i),r=r+4+i-1,e[r++]=0,r}function it(e,t,n,r,o=!1,i=0,s=!1,u=!0,l){if(n.scope&&"object"==typeof n.scope){e[r++]=U,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;let a=r;const f=n.code;r+=4;const c=re.encodeUTF8Into(e,f,r+4)+1;_e.setInt32LE(e,r,c),e[r+4+c-1]=0,r=r+c+4;const h=at(e,n.scope,o,r,i+1,s,u,l);r=h-1;const g=h-a;a+=_e.setInt32LE(e,a,g),e[r++]=0}else{e[r++]=I,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.code.toString(),i=re.encodeUTF8Into(e,o,r+4)+1;_e.setInt32LE(e,r,i),r=r+4+i-1,e[r++]=0}return r}function st(e,t,n,r){e[r++]=B,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.buffer;let i=n.position;if(n.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),r+=_e.setInt32LE(e,r,i),e[r++]=n.sub_type,n.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,r+=_e.setInt32LE(e,r,i)),i<=16)for(let t=0;t<i;t++)e[r+t]=o[t];else e.set(o,r);return r+=n.position}function ut(e,t,n,r){e[r++]=_,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;const o=re.encodeUTF8Into(e,n.value,r+4)+1;return _e.setInt32LE(e,r,o),r=r+4+o-1,e[r++]=0,r}function lt(e,t,n,r,o,i,s){e[r++]=y,r+=re.encodeUTF8Into(e,t,r),e[r++]=0;let u=r,l={$ref:n.collection||n.namespace,$id:n.oid};null!=n.db&&(l.$db=n.db),l=Object.assign(l,n.fields);const a=at(e,l,!1,r,o+1,i,!0,s),f=a-u;return u+=_e.setInt32LE(e,r,f),a}function at(e,t,n,l,f,c,h,g){if(null==g){if(null==t)return e[0]=5,e[1]=0,e[2]=0,e[3]=0,e[4]=0,5;if(Array.isArray(t))throw new BSONError("serialize does not support an array as the root input");if("object"!=typeof t)throw new BSONError("serialize does not support non-object as the root input");if("_bsontype"in t&&"string"==typeof t._bsontype)throw new BSONError("BSON types cannot be serialized as a document");if(u(t)||i(t)||o(t)||r(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");g=new Set}g.add(t);let d=l+4;if(Array.isArray(t))for(let r=0;r<t.length;r++){const s=`${r}`;let l=t[r];if("function"==typeof l?.toBSON&&(l=l.toBSON()),"string"==typeof l)d=Ve(e,s,l,d);else if("number"==typeof l)d=ke(e,s,l,d);else if("bigint"==typeof l)d=Je(e,s,l,d);else if("boolean"==typeof l)d=He(e,s,l,d);else if(l instanceof Date||u(l))d=Ke(e,s,l,d);else if(void 0===l)d=qe(e,s,0,d);else if(null===l)d=qe(e,s,0,d);else if(o(l))d=Xe(e,s,l,d);else if(l instanceof RegExp||i(l))d=Ye(e,s,l,d);else if("object"==typeof l&&null==l._bsontype)d=Qe(e,s,l,d,n,f,c,h,g);else{if("object"==typeof l&&l[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===l._bsontype)d=Ge(e,s,l,d);else if("Decimal128"===l._bsontype)d=et(e,s,l,d);else if("Long"===l._bsontype||"Timestamp"===l._bsontype)d=tt(e,s,l,d);else if("Double"===l._bsontype)d=rt(e,s,l,d);else if("function"==typeof l&&c)d=ot(e,s,l,d);else if("Code"===l._bsontype)d=it(e,s,l,d,n,f,c,h,g);else if("Binary"===l._bsontype)d=st(e,s,l,d);else if("BSONSymbol"===l._bsontype)d=ut(e,s,l,d);else if("DBRef"===l._bsontype)d=lt(e,s,l,d,f,c,g);else if("BSONRegExp"===l._bsontype)d=Ze(e,s,l,d);else if("Int32"===l._bsontype)d=nt(e,s,l,d);else if("MinKey"===l._bsontype||"MaxKey"===l._bsontype)d=We(e,s,l,d);else if(void 0!==l._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(l._bsontype)}`)}}else if(t instanceof Map||s(t)){const r=t.entries();let s=!1;for(;!s;){const t=r.next();if(s=!!t.done,s)continue;const l=t.value[0];let p=t.value[1];"function"==typeof p?.toBSON&&(p=p.toBSON());const b=typeof p;if("string"==typeof l&&!Fe.has(l)){if(null!=l.match(Ce))throw new BSONError("key "+l+" must not contain null bytes");if(n){if("$"===l[0])throw new BSONError("key "+l+" must not start with '$'");if(l.includes("."))throw new BSONError("key "+l+" must not contain '.'")}}if("string"===b)d=Ve(e,l,p,d);else if("number"===b)d=ke(e,l,p,d);else if("bigint"===b)d=Je(e,l,p,d);else if("boolean"===b)d=He(e,l,p,d);else if(p instanceof Date||u(p))d=Ke(e,l,p,d);else if(null===p||void 0===p&&!1===h)d=qe(e,l,0,d);else if(o(p))d=Xe(e,l,p,d);else if(p instanceof RegExp||i(p))d=Ye(e,l,p,d);else if("object"===b&&null==p._bsontype)d=Qe(e,l,p,d,n,f,c,h,g);else{if("object"==typeof p&&p[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===p._bsontype)d=Ge(e,l,p,d);else if("object"===b&&"Decimal128"===p._bsontype)d=et(e,l,p,d);else if("Long"===p._bsontype||"Timestamp"===p._bsontype)d=tt(e,l,p,d);else if("Double"===p._bsontype)d=rt(e,l,p,d);else if("Code"===p._bsontype)d=it(e,l,p,d,n,f,c,h,g);else if("function"==typeof p&&c)d=ot(e,l,p,d);else if("Binary"===p._bsontype)d=st(e,l,p,d);else if("BSONSymbol"===p._bsontype)d=ut(e,l,p,d);else if("DBRef"===p._bsontype)d=lt(e,l,p,d,f,c,g);else if("BSONRegExp"===p._bsontype)d=Ze(e,l,p,d);else if("Int32"===p._bsontype)d=nt(e,l,p,d);else if("MinKey"===p._bsontype||"MaxKey"===p._bsontype)d=We(e,l,p,d);else if(void 0!==p._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(p._bsontype)}`)}}}else{if("function"==typeof t?.toBSON&&null!=(t=t.toBSON())&&"object"!=typeof t)throw new BSONError("toBSON function did not return an object");for(const r of Object.keys(t)){let s=t[r];"function"==typeof s?.toBSON&&(s=s.toBSON());const l=typeof s;if("string"==typeof r&&!Fe.has(r)){if(null!=r.match(Ce))throw new BSONError("key "+r+" must not contain null bytes");if(n){if("$"===r[0])throw new BSONError("key "+r+" must not start with '$'");if(r.includes("."))throw new BSONError("key "+r+" must not contain '.'")}}if("string"===l)d=Ve(e,r,s,d);else if("number"===l)d=ke(e,r,s,d);else if("bigint"===l)d=Je(e,r,s,d);else if("boolean"===l)d=He(e,r,s,d);else if(s instanceof Date||u(s))d=Ke(e,r,s,d);else if(void 0===s)!1===h&&(d=qe(e,r,0,d));else if(null===s)d=qe(e,r,0,d);else if(o(s))d=Xe(e,r,s,d);else if(s instanceof RegExp||i(s))d=Ye(e,r,s,d);else if("object"===l&&null==s._bsontype)d=Qe(e,r,s,d,n,f,c,h,g);else{if("object"==typeof s&&s[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===s._bsontype)d=Ge(e,r,s,d);else if("object"===l&&"Decimal128"===s._bsontype)d=et(e,r,s,d);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)d=tt(e,r,s,d);else if("Double"===s._bsontype)d=rt(e,r,s,d);else if("Code"===s._bsontype)d=it(e,r,s,d,n,f,c,h,g);else if("function"==typeof s&&c)d=ot(e,r,s,d);else if("Binary"===s._bsontype)d=st(e,r,s,d);else if("BSONSymbol"===s._bsontype)d=ut(e,r,s,d);else if("DBRef"===s._bsontype)d=lt(e,r,s,d,f,c,g);else if("BSONRegExp"===s._bsontype)d=Ze(e,r,s,d);else if("Int32"===s._bsontype)d=nt(e,r,s,d);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)d=We(e,r,s,d);else if(void 0!==s._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}}}g.delete(t),e[d++]=0;const p=d-l;return l+=_e.setInt32LE(e,l,p),d}const ft={$oid:ObjectId,$binary:Binary,$uuid:Binary,$symbol:BSONSymbol,$numberInt:Int32,$numberDecimal:Decimal128,$numberDouble:Double,$numberLong:Long,$minKey:MinKey,$maxKey:MaxKey,$regex:BSONRegExp,$regularExpression:BSONRegExp,$timestamp:Timestamp};function ct(e,t={}){if("number"==typeof e){const n=e<=f&&e>=c,r=e<=h&&e>=g;if(t.relaxed||t.legacy)return e;if(Number.isInteger(e)&&!Object.is(e,-0)){if(n)return new Int32(e);if(r)return t.useBigInt64?BigInt(e):Long.fromNumber(e)}return new Double(e)}if(null==e||"object"!=typeof e)return e;if(e.$undefined)return null;const n=Object.keys(e).filter((t=>t.startsWith("$")&&null!=e[t]));for(let r=0;r<n.length;r++){const o=ft[n[r]];if(o)return o.fromExtendedJSON(e,t)}if(null!=e.$date){const n=e.$date,r=new Date;if(t.legacy)if("number"==typeof n)r.setTime(n);else if("string"==typeof n)r.setTime(Date.parse(n));else{if("bigint"!=typeof n)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}else if("string"==typeof n)r.setTime(Date.parse(n));else if(Long.isLong(n))r.setTime(n.toNumber());else if("number"==typeof n&&t.relaxed)r.setTime(n);else{if("bigint"!=typeof n)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}return r}if(null!=e.$code){const t=Object.assign({},e);return e.$scope&&(t.$scope=ct(e.$scope)),Code.fromExtendedJSON(e)}if(se(e)||e.$dbPointer){const t=e.$ref?e:e.$dbPointer;if(t instanceof DBRef)return t;const n=Object.keys(t).filter((e=>e.startsWith("$")));let r=!0;if(n.forEach((e=>{-1===["$ref","$id","$db"].indexOf(e)&&(r=!1)})),r)return DBRef.fromExtendedJSON(t)}return e}function ht(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function gt(e,t){if(e instanceof Map||s(e)){const n=Object.create(null);for(const[t,r]of e){if("string"!=typeof t)throw new BSONError("Can only serialize maps with string keys");n[t]=r}return gt(n,t)}if(("object"==typeof e||"function"==typeof e)&&null!==e){const n=t.seenObjects.findIndex((t=>t.obj===e));if(-1!==n){const e=t.seenObjects.map((e=>e.propertyName)),r=e.slice(0,n).map((e=>`${e} -> `)).join(""),o=e[n],i=" -> "+e.slice(n+1,e.length-1).map((e=>`${e} -> `)).join(""),s=e[e.length-1],u=" ".repeat(r.length+o.length/2),l="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${r}${o}${i}${s}\n ${u}\\${l}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,n)=>{t.seenObjects.push({propertyName:`index ${n}`,obj:null});try{return gt(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return null;if(e instanceof Date||u(e)){const n=e.getTime(),r=n>-1&&n<2534023188e5;return t.legacy?t.relaxed&&r?{$date:e.getTime()}:{$date:ht(e)}:t.relaxed&&r?{$date:ht(e)}:{$date:{$numberLong:e.getTime().toString()}}}if(!("number"!=typeof e||t.relaxed&&isFinite(e))){if(Number.isInteger(e)&&!Object.is(e,-0)){if(e>=c&&e<=f)return{$numberInt:e.toString()};if(e>=g&&e<=h)return{$numberLong:e.toString()}}return{$numberDouble:Object.is(e,-0)?"-0.0":e.toString()}}if("bigint"==typeof e)return t.relaxed?Number(BigInt.asIntN(64,e)):{$numberLong:BigInt.asIntN(64,e).toString()};if(e instanceof RegExp||i(e)){let n=e.flags;if(void 0===n){const t=e.toString().match(/[gimuy]*$/);t&&(n=t[0])}return new BSONRegExp(e.source,n).toExtendedJSON(t)}return null!=e&&"object"==typeof e?function(e,t){if(null==e||"object"!=typeof e)throw new BSONError("not an object instance");const n=e._bsontype;if(void 0===n){const n={};for(const r of Object.keys(e)){t.seenObjects.push({propertyName:r,obj:null});try{const o=gt(e[r],t);"__proto__"===r?Object.defineProperty(n,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):n[r]=o}finally{t.seenObjects.pop()}}return n}if(null!=e&&"object"==typeof e&&"string"==typeof e._bsontype&&e[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if(function(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"string"==typeof e._bsontype}(e)){let r=e;if("function"!=typeof r.toExtendedJSON){const t=dt[e._bsontype];if(!t)throw new BSONError("Unrecognized or invalid _bsontype: "+e._bsontype);r=t(r)}return"Code"===n&&r.scope?r=new Code(r.code,gt(r.scope,t)):"DBRef"===n&&r.oid&&(r=new DBRef(gt(r.collection,t),gt(r.oid,t),gt(r.db,t),gt(r.fields,t))),r.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof n)}(e,t):e}const dt={Binary:e=>new Binary(e.value(),e.sub_type),Code:e=>new Code(e.code,e.scope),DBRef:e=>new DBRef(e.collection||e.namespace,e.oid,e.db,e.fields),Decimal128:e=>new Decimal128(e.bytes),Double:e=>new Double(e.value),Int32:e=>new Int32(e.value),Long:e=>Long.fromBits(null!=e.low?e.low:e.low_,null!=e.low?e.high:e.high_,null!=e.low?e.unsigned:e.unsigned_),MaxKey:()=>new MaxKey,MinKey:()=>new MinKey,ObjectId:e=>new ObjectId(e),BSONRegExp:e=>new BSONRegExp(e.pattern,e.options),BSONSymbol:e=>new BSONSymbol(e.value),Timestamp:e=>Timestamp.fromBits(e.low,e.high)};function pt(e,t){const n={useBigInt64:t?.useBigInt64??!1,relaxed:t?.relaxed??!0,legacy:t?.legacy??!1};return JSON.parse(e,((e,t)=>{if(-1!==e.indexOf("\0"))throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(e)}`);return ct(t,n)}))}function bt(e,t,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==t||"object"!=typeof t||Array.isArray(t)||(r=t,t=void 0,n=0);const o=gt(e,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,n)}const mt=Object.create(null);function yt(e,t){if(e[t+3]>127)throw new BSONOffsetError("BSON size cannot be negative",t);return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24}function wt(e,t){let n=t;for(;0!==e[n];n++);if(n===e.length-1)throw new BSONOffsetError("Null terminator not found",t);return n}mt.parse=pt,mt.stringify=bt,mt.serialize=function(e,t){return t=t||{},JSON.parse(bt(e,t))},mt.deserialize=function(e,t){return t=t||{},pt(JSON.stringify(e),t)},Object.freeze(mt);const Bt=Object.create(null);Bt.parseToElements=function(e,t=0){if(e.length<5)throw new BSONOffsetError(`Input must be at least 5 bytes, got ${e.length} bytes`,t);const n=yt(e,t);if(n>e.length-t)throw new BSONOffsetError(`Parsed documentSize (${n} bytes) does not match input length (${e.length} bytes)`,t);if(0!==e[t+n-1])throw new BSONOffsetError("BSON documents must end in 0x00",t+n);const r=[];let o=t+4;for(;o<=n+t;){const i=e[o];if(o+=1,0===i){if(o-t!==n)throw new BSONOffsetError("Invalid 0x00 type byte",o);break}const s=o,u=wt(e,o)-s;let l;if(o+=u+1,1===i||18===i||9===i||17===i)l=8;else if(16===i)l=4;else if(7===i)l=12;else if(19===i)l=16;else if(8===i)l=1;else if(10===i||6===i||127===i||255===i)l=0;else if(11===i)l=wt(e,wt(e,o)+1)+1-o;else if(3===i||4===i||15===i)l=yt(e,o);else{if(2!==i&&5!==i&&12!==i&&13!==i&&14!==i)throw new BSONOffsetError(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);l=yt(e,o)+4,5===i&&(l+=1),12===i&&(l+=12)}if(l>n)throw new BSONOffsetError("value reports length larger than document",o);r.push([i,s,u,o,l]),o+=l}return r},Bt.BSONOffsetError=BSONOffsetError,Object.freeze(Bt);const St=17825792;let Ot=re.allocate(St);function Et(e){Ot.length<e&&(Ot=re.allocate(e))}function Nt(e,t={}){const n="boolean"==typeof t.checkKeys&&t.checkKeys,r="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,o="boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined,i="number"==typeof t.minInternalBufferSize?t.minInternalBufferSize:St;Ot.length<i&&(Ot=re.allocate(i));const s=at(Ot,e,n,0,0,r,o,null),u=re.allocateUnsafe(s);return u.set(Ot.subarray(0,s),0),u}function Lt(e,t,n={}){const r="boolean"==typeof n.checkKeys&&n.checkKeys,o="boolean"==typeof n.serializeFunctions&&n.serializeFunctions,i="boolean"!=typeof n.ignoreUndefined||n.ignoreUndefined,s="number"==typeof n.index?n.index:0,u=at(Ot,e,r,0,0,o,i,null);return t.set(Ot.subarray(0,u),s),s+u-1}function vt(e,t={}){return Me(re.toLocalBufferType(e),t)}function xt(e,t={}){return Te(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function It(e,t,n,r,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),u=re.toLocalBufferType(e);let l=t;for(let e=0;e<n;e++){const t=_e.getInt32LE(u,l);s.index=l,r[o+e]=Me(u,s),l+=t}return l}var _t=Object.freeze({__proto__:null,BSONError,BSONRegExp,BSONRuntimeError,BSONSymbol,BSONType:z,BSONValue,BSONVersionError,Binary,Code,DBRef,Decimal128,Double,EJSON:mt,Int32,Long,MaxKey,MinKey,ObjectId,Timestamp,UUID,calculateObjectSize:xt,deserialize:vt,deserializeStream:It,onDemand:Bt,serialize:Nt,serializeWithBufferAndIndex:Lt,setInternalBufferSize:Et});t.BSON=_t,t.BSONError=BSONError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=z,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=mt,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.calculateObjectSize=xt,t.deserialize=vt,t.deserializeStream=It,t.onDemand=Bt,t.serialize=Nt,t.serializeWithBufferAndIndex=Lt,t.setInternalBufferSize=Et}},t={},function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}},s=!0;try{e[r].call(i.exports,i,i.exports,n),s=!1}finally{s&&delete t[r]}return i.exports}(920);var e,t}));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(global,(()=>{return e={558:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=s,t.call=function(e){return s(e).apply(null,[].slice.call(arguments,1))};var r,o=n(130),i=(r=o)&&r.__esModule?r:{default:r};function s(e,t){var n=(t=t||{}).addListener||window.addEventListener,r=t.removeListener||window.removeEventListener,o=t.postMessage||window.postMessage,s=t.targetOrigin||"*",u=t.getMessageData||function(e){return e.data};return function(){var t={sender:"postmsg-rpc/client",id:(0,i.default)(),func:e,args:Array.from(arguments)},a=void 0,l=new Promise((function(i,l){var f=function n(){var o=u.apply(null,arguments);if(o&&"postmsg-rpc/server"===o.sender&&o.id===t.id){if(r("message",n),o.err){var s=new Error("Unexpected error calling "+e);return Object.assign(s,o.err),l(s)}i(o.res)}};a=function(){r("message",f);var t=new Error("Canceled call to "+e);t.isCanceled=!0,l(t)},n("message",f),o(t,s)}));return l.cancel=function(){return a()},l}}},246:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(558);Object.defineProperty(t,"caller",{enumerable:!0,get:function(){return i(r).default}}),Object.defineProperty(t,"call",{enumerable:!0,get:function(){return r.call}});var o=n(624);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},624:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,n){var r=(n=n||{}).addListener||window.addEventListener,o=n.removeListener||window.removeEventListener,i=n.postMessage||window.postMessage,s=n.targetOrigin||"*",u=n.getMessageData||function(e){return e.data},a=n.isCallback||!1,l=function(){var n=u.apply(null,arguments);if(n&&"postmsg-rpc/client"===n.sender&&n.func===e){var r={sender:"postmsg-rpc/server",id:n.id},o=function(e){r.res=e,i(r,s)},l=function(e){r.err=Object.assign({message:e.message},e.output&&e.output.payload),i(r,s)};if(a)t.apply(null,n.args.concat((function(e,t){if(e)return l(e);o(t)})));else{var f=t.apply(null,n.args);Promise.resolve(f).then(o).catch(l)}}};return r("message",l),{close:function(){return o("message",l)}}}},130:(e,t,n)=>{"use strict";e.exports=n(252)},173:(e,t,n)=>{"use strict";var r,o,i,s=n(514),u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function a(){i=!1}function l(e){if(e){if(e!==r){if(e.length!==u.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,n){return t!==n.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. These characters were not unique: "+t.join(", "));r=e,a()}}else r!==u&&(r=u,a())}function f(){return i||(i=function(){r||l(u);for(var e,t=r.split(""),n=[],o=s.nextValue();t.length>0;)o=s.nextValue(),e=Math.floor(o*t.length),n.push(t.splice(e,1)[0]);return n.join("")}())}e.exports={get:function(){return r||u},characters:function(e){return l(e),r},seed:function(e){s.seed(e),o!==e&&(a(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},89:(e,t,n)=>{"use strict";var r,o,i=n(943);n(173),e.exports=function(e){var t="",n=Math.floor(.001*(Date.now()-1567752802062));return n===o?r++:(r=0,o=n),t+=i(7),t+=i(e),r>0&&(t+=i(r)),t+=i(n)}},943:(e,t,n)=>{"use strict";var r=n(173),o=n(908),i=n(137);e.exports=function(e){for(var t,n=0,s="";!t;)s+=i(o,r.get(),1),t=e<Math.pow(16,n+1),n++;return s}},252:(e,t,n)=>{"use strict";var r=n(173),o=n(89),i=n(56),s=n(696)||0;function u(){return o(s)}e.exports=u,e.exports.generate=u,e.exports.seed=function(t){return r.seed(t),e.exports},e.exports.worker=function(t){return s=t,e.exports},e.exports.characters=function(e){return void 0!==e&&r.characters(e),r.shuffled()},e.exports.isValid=i},56:(e,t,n)=>{"use strict";var r=n(173);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+r.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},908:(e,t,n)=>{e.exports=n(701)},514:e=>{"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},696:(e,t,n)=>{"use strict";var r=n(1),o=0;!r.isMaster&&r.worker&&(o=r.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},137:e=>{e.exports=function(e,t,n){for(var r=(2<<31-Math.clz32(t.length-1|1))-1,o=Math.ceil(1.6*r*n/t.length),i="";;)for(var s=e(o),u=o;u--;)if((i+=t[s[u]&r]||"").length===+n)return i}},701:(e,t,n)=>{var r=n(113);if(r.randomFillSync){var o={};e.exports=function(e){var t=o[e];return t||(t=Buffer.allocUnsafe(e),e<=255&&(o[e]=t)),r.randomFillSync(t)}}else e.exports=r.randomBytes},458:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChildProcessEvaluationListener=void 0;const r=n(369),o=n(568);t.ChildProcessEvaluationListener=class ChildProcessEvaluationListener{constructor(e,t){this.exposedListener=(0,r.exposeAll)({onPrompt(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.onPrompt)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:""},onPrint(t){var n,r;return t=t.map(o.deserializeEvaluationResult),null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.onPrint)||void 0===r?void 0:r.call(n,t)},setConfig(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.setConfig)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:Promise.resolve("ignored")},resetConfig(t){var n,r,o;return null!==(o=null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.resetConfig)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:Promise.resolve("ignored")},validateConfig(t,n){var r,o,i;return null!==(i=null===(o=null===(r=e.evaluationListener)||void 0===r?void 0:r.validateConfig)||void 0===o?void 0:o.call(r,t,n))&&void 0!==i?i:Promise.resolve(null)},getConfig(t){var n,r;return null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.getConfig)||void 0===r?void 0:r.call(n,t)},listConfigOptions(){var t,n;return null===(n=null===(t=e.evaluationListener)||void 0===t?void 0:t.listConfigOptions)||void 0===n?void 0:n.call(t)},onClearCommand(){var t,n;return null===(n=null===(t=e.evaluationListener)||void 0===t?void 0:t.onClearCommand)||void 0===n?void 0:n.call(t)},onExit(t){var n,r,o;return null!==(o=null===(r=null===(n=e.evaluationListener)||void 0===n?void 0:n.onExit)||void 0===r?void 0:r.call(n,t))&&void 0!==o?o:Promise.resolve()}},t)}terminate(){this.exposedListener[r.close]()}}},517:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ChildProcessMongoshBus=void 0;const r=n(369);t.ChildProcessMongoshBus=class ChildProcessMongoshBus{constructor(e,t){const n=(0,r.exposeAll)({emit(...t){e.emit(...t)},on(){throw new Error("Can't use `on` method on ChildProcessMongoshBus")},once(){throw new Error("Can't use `once` method on ChildProcessMongoshBus")}},t);this.exposedEmitter=n}terminate(){this.exposedEmitter[r.close]()}}},920:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerRuntime=void 0;const o=n(81),i=r(n(17)),s=n(361),u=n(859),a=n(369),l=n(458),f=n(568),c=n(517);t.WorkerRuntime=class WorkerRuntime{constructor(e,t,n={},r={},o=new s.EventEmitter){this.evaluationListener=null,this.childProcessProxySrcPath=process.env.CHILD_PROCESS_PROXY_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING||i.default.resolve(__dirname,"child-process-proxy.js"),this.initOptions={uri:e,driverOptions:t,cliOptions:n,spawnOptions:r},this.eventEmitter=o,this.initWorkerPromise=this.initWorker()}async initWorker(){var e,t,n;const{uri:r,driverOptions:i,cliOptions:u,spawnOptions:h}=this.initOptions;this.childProcess=(0,o.spawn)(process.execPath,[this.childProcessProxySrcPath],{stdio:["inherit","inherit","pipe","ipc"],...h});let g="";null===(n=null===(t=null===(e=this.childProcess)||void 0===e?void 0:e.stderr)||void 0===t?void 0:t.setEncoding("utf8"))||void 0===n||n.on("data",(e=>{g+=e})),await Promise.race([(async()=>{let e;for(;[e]=await(0,s.once)(this.childProcess,"message");)if("ready"===e)return})(),(async()=>{const[e]=await(0,s.once)(this.childProcess,"exit");if(e){let t=function(e){const[,t]=e.split(/^\s*\^\s*$/m).map((e=>e.trim()));if(t){const e=new Error,n=t.substring(0,t.search(/^\s*at/m))||t,[r,...o]=n.split(": ");return e.name=r,e.message=o.join(": ").trim(),e.stack=t,e}return null}(g);throw t?t.message=`Child process failed to start with the following error: ${t.message}`:t=new Error(`Worker runtime failed to start: child process exited with code ${e}`),t}})()]),this.childProcess.setMaxListeners(25),this.childProcessRuntime=(0,a.createCaller)(["init","evaluate","getCompletions","setEvaluationListener","getShellPrompt","interrupt"],this.childProcess),this.childProcessEvaluationListener=new l.ChildProcessEvaluationListener(this,this.childProcess),this.childProcessMongoshBus=new c.ChildProcessMongoshBus(this.eventEmitter,this.childProcess),await this.childProcessRuntime.init(r,(0,f.serializeConnectOptions)(i),u)}async evaluate(e){return await this.initWorkerPromise,(0,f.deserializeEvaluationResult)(await this.childProcessRuntime.evaluate(e))}async getCompletions(e){return await this.initWorkerPromise,await this.childProcessRuntime.getCompletions(e)}async getShellPrompt(){return await this.initWorkerPromise,await this.childProcessRuntime.getShellPrompt()}setEvaluationListener(e){const t=this.evaluationListener;return this.evaluationListener=e,t}async terminate(){try{await this.initWorkerPromise}catch(e){}await(0,u.kill)(this.childProcess),this.childProcessRuntime&&this.childProcessRuntime[a.cancel](),this.childProcessEvaluationListener&&this.childProcessEvaluationListener.terminate(),this.childProcessMongoshBus&&this.childProcessMongoshBus.terminate()}async interrupt(){return await this.initWorkerPromise,this.childProcessRuntime.interrupt()}async waitForRuntimeToBeReady(){await this.initWorkerPromise}}},369:function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createCaller=t.exposeAll=t.cancel=t.close=t.removeTrailingUndefined=t.deserialize=t.serialize=void 0;const o=r(n(655)),i=n(246),s=n(568);function u(e){return`data:;base64,${o.default.serialize(e).toString("base64")}`}function a(e){return/^data:;base64,.+/.test(e)?o.default.deserialize(Buffer.from(e.replace("data:;base64,",""),"base64")):e}var l;function f(e){return e&&"object"==typeof e&&"id"in e&&"sender"in e}function c(e){return f(e)&&"postmsg-rpc/server"===e.sender}function h(e){return f(e)&&"postmsg-rpc/client"===e.sender}function g(e){if(Array.isArray(e))for(e=[...e];e.length>0&&void 0===e[e.length-1];)e.pop();return e}function d(e){return{addListener:e.on.bind(e),removeListener:e.off.bind(e),postMessage(t){if(h(t)&&Array.isArray(t.args)&&(t.args=u(g(t.args))),c(t))try{t.res=u(t.res)}catch(e){t.res=u({type:l.Error,payload:(0,s.serializeError)(e)})}return function(e,t){"postMessage"in e&&"function"==typeof e.postMessage&&e.postMessage(t),"send"in e&&"function"==typeof e.send&&e.send(t)}(e,t)},getMessageData:e=>(h(e)&&e.args&&"string"==typeof e.args&&(e.args=a(e.args)),c(e)&&"string"==typeof e.res&&(e.res=a(e.res)),e)}}t.serialize=u,t.deserialize=a,function(e){e[e.Message=0]="Message",e[e.Error=1]="Error"}(l||(l={})),t.removeTrailingUndefined=g,t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel"),t.exposeAll=function(e,n){return Object.entries(e).forEach((([e,t])=>{const{close:r}=(0,i.expose)(e,(async(...e)=>{try{return{type:l.Message,payload:await t(...e)}}catch(e){return{type:l.Error,payload:(0,s.serializeError)(e)}}}),d(n));t.close=r})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,n,r={}){const o={},u=new Set;return e.forEach((e=>{const t=(0,i.caller)(e,d(n));o[e]=async(...n)=>{var o;const i="function"==typeof r[e]?null===(o=r[e])||void 0===o?void 0:o.call(r,...n):n,a=t(...i);u.add(a);const f=await a;if(u.delete(a),(c=f)&&"object"==typeof c&&c.type===l.Error)throw(0,s.deserializeError)(f.payload);var c;return f.payload}})),Object.defineProperty(o,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),o}},568:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deserializeConnectOptions=t.serializeConnectOptions=t.deserializeEvaluationResult=t.serializeEvaluationResult=t.SerializedResultTypes=t.deserializeError=t.serializeError=void 0;const r=n(837),o=n(429);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").filter((t=>"function"!=typeof e[t])).reduce(((t,n)=>(t[n]=e[n],t)),{})}function s(e){return Object.assign(new Error,e)}var u;t.serializeError=i,t.deserializeError=s,function(e){e.SerializedErrorResult="SerializedErrorResult",e.InspectResult="InspectResult",e.SerializedShellApiResult="SerializedShellApiResult"}(u||(t.SerializedResultTypes=u={})),t.serializeEvaluationResult=function({type:e,printable:t,source:n}){return"object"!=typeof(s=t)&&"function"!=typeof s||null===s?{type:e,printable:t,source:n}:function(e){return e&&e.name&&e.message&&e.stack}(t)?{type:u.SerializedErrorResult,printable:i(t),source:n}:null===e?{type:u.InspectResult,printable:(0,r.inspect)(t),source:n}:{type:u.SerializedShellApiResult,printable:{origType:e,serializedValue:o.EJSON.serialize(t)}};var s},t.deserializeEvaluationResult=function({type:e,printable:t,source:n}){return e===u.SerializedErrorResult?{type:e,printable:s(t),source:n}:e===u.SerializedShellApiResult?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:n}:{type:e,printable:t,source:n}};const a=["schemaMap","encryptedFieldsMap"];t.serializeConnectOptions=function(e){var t;const n={...e};for(const e of a)(null===(t=n.autoEncryption)||void 0===t?void 0:t[e])&&(n.autoEncryption={...n.autoEncryption,[e]:o.EJSON.serialize(n.autoEncryption[e],{relaxed:!1})});return n},t.deserializeConnectOptions=function(e){var t;const n={...e};for(const e of a)(null===(t=n.autoEncryption)||void 0===t?void 0:t[e])&&(n.autoEncryption={...n.autoEncryption,[e]:o.EJSON.deserialize(n.autoEncryption[e],{relaxed:!1})});return n}},859:(e,t,n)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.kill=void 0;const r=n(81),o=n(361);async function i(e,t="SIGTERM"){e.kill(t),null===e.exitCode&&null===e.signalCode&&await(0,o.once)(e,"exit")}t.kill=i,t.default=function(e,t={},n,o="inherit",s="inherit"){return new Promise(((u,a)=>{const l=Date.now().toString(32),f=(0,r.spawn)(process.execPath,{stdio:["pipe",o,s,"ipc"],...t});if(!f.stdin)return void i(f).then((()=>{a(new Error("Can't write src to the spawned process, missing stdin"))})).catch((e=>{a(e)}));let c;function h(){c&&clearTimeout(c),f.stdin&&f.stdin.off("error",d),f.off("message",p),f.off("exit",g)}function g(e){e&&e>0&&(h(),a(new Error("Child process exited with error before starting")))}async function d(e){h(),await i(f),a(e)}function p(e){e===l&&(h(),u(f))}f.on("message",p),f.on("exit",g),f.stdin.on("error",d),f.stdin.write(e),f.stdin.write(`;process.send(${JSON.stringify(l)})`),f.stdin.end(),c=void 0!==n?setTimeout((async function(){h(),await i(f),a(new Error("Timed out while waiting for child process to start"))}),n):null}))}},81:e=>{"use strict";e.exports=require("child_process")},1:e=>{"use strict";e.exports=require("cluster")},113:e=>{"use strict";e.exports=require("crypto")},361:e=>{"use strict";e.exports=require("events")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")},655:e=>{"use strict";e.exports=require("v8")},429:(e,t,n)=>{"use strict";function r(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function o(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function i(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function s(e){return"[object Map]"===Object.prototype.toString.call(e)}function u(e){return"[object Date]"===Object.prototype.toString.call(e)}function a(e,t){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?{$numberLong:`${t}`}:s(t)?Object.fromEntries(t):t))}const l=6,f=2147483647,c=-2147483648,h=Math.pow(2,63)-1,g=-Math.pow(2,63),d=Math.pow(2,53),p=-Math.pow(2,53),m=1,b=2,y=3,w=4,B=5,S=6,O=7,E=8,N=9,L=10,v=11,x=12,I=13,_=14,$=15,U=16,T=17,j=18,R=19,D=255,A=127,M=0,P=4,z=Object.freeze({double:1,string:2,object:3,array:4,binData:5,undefined:6,objectId:7,bool:8,date:9,null:10,regex:11,dbPointer:12,javascript:13,symbol:14,javascriptWithScope:15,int:16,timestamp:17,long:18,decimal:19,minKey:-1,maxKey:127});class BSONError extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(e,t){super(e,t)}static isBSONError(e){return null!=e&&"object"==typeof e&&"bsonError"in e&&!0===e.bsonError&&"name"in e&&"message"in e&&"stack"in e}}class BSONVersionError extends BSONError{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${l}.x.x`)}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}class BSONOffsetError extends BSONError{get name(){return"BSONOffsetError"}constructor(e,t,n){super(`${e}. offset: ${t}`,n),this.offset=t}}let C,F;function V(e,t,n,r){if(r){C??=new TextDecoder("utf8",{fatal:!0});try{return C.decode(e.subarray(t,n))}catch(e){throw new BSONError("Invalid UTF-8 string in BSON document",{cause:e})}}return F??=new TextDecoder("utf8",{fatal:!1}),F.decode(e.subarray(t,n))}function k(e,t,n){if(0===e.length)return"";const r=n-t;if(0===r)return"";if(r>20)return null;if(1===r&&e[t]<128)return String.fromCharCode(e[t]);if(2===r&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(3===r&&e[t]<128&&e[t+1]<128&&e[t+2]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1])+String.fromCharCode(e[t+2]);const o=[];for(let r=t;r<n;r++){const t=e[r];if(t>127)return null;o.push(t)}return String.fromCharCode(...o)}function J(e){return q.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const q={toLocalBufferType(e){if(Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength);const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return Buffer.from(e);throw new BSONError(`Cannot create Buffer from ${String(e)}`)},allocate:e=>Buffer.alloc(e),allocateUnsafe:e=>Buffer.allocUnsafe(e),equals:(e,t)=>q.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),toBase64:e=>q.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>q.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>q.toLocalBufferType(e).toString("hex"),toUTF8(e,t,n,r){const o=n-t<=20?k(e,t,n):null;if(null!=o)return o;const i=q.toLocalBufferType(e).toString("utf8",t,n);if(r)for(let r=0;r<i.length;r++)if(65533===i.charCodeAt(r)){V(e,t,n,!0);break}return i},utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into(e,t,n){const r=function(e,t,n){if(0===t.length)return 0;if(t.length>25)return null;if(e.length-n<t.length)return null;for(let r=0,o=n;r<t.length;r++,o++){const n=t.charCodeAt(r);if(n>127)return null;e[o]=n}return t.length}(e,t,n);return null!=r?r:q.toLocalBufferType(e).write(t,n,void 0,"utf8")},randomBytes:(()=>{try{return n(113).randomBytes}catch{return J}})()};function H(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return Z.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const K=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(Z.allocate(t));if(function(){const{navigator:e}=globalThis;return"object"==typeof e&&"ReactNative"===e.product}()){const{console:e}=globalThis;e?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.")}return H})(),Y=/(\d|[a-f])/i,Z={toLocalBufferType(e){const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("Uint8Array"===t)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return new Uint8Array(e);throw new BSONError(`Cannot make a Uint8Array from ${String(e)}`)},allocate(e){if("number"!=typeof e)throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},allocateUnsafe:e=>Z.allocate(e),equals(e,t){if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0},fromNumberArray:e=>Uint8Array.from(e),fromBase64:e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))),toBase64:e=>btoa(Z.toISO88591(e)),fromISO88591:e=>Uint8Array.from(e,(e=>255&e.charCodeAt(0))),toISO88591:e=>Array.from(Uint16Array.from(e),(e=>String.fromCharCode(e))).join(""),fromHex(e){const t=e.length%2==0?e:e.slice(0,e.length-1),n=[];for(let e=0;e<t.length;e+=2){const r=t[e],o=t[e+1];if(!Y.test(r))break;if(!Y.test(o))break;const i=Number.parseInt(`${r}${o}`,16);n.push(i)}return Uint8Array.from(n)},toHex:e=>Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join(""),toUTF8(e,t,n,r){const o=n-t<=20?k(e,t,n):null;return null!=o?o:V(e,t,n,r)},utf8ByteLength:e=>(new TextEncoder).encode(e).byteLength,encodeUTF8Into(e,t,n){const r=(new TextEncoder).encode(t);return e.set(r,n),r.byteLength},randomBytes:K},W="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?q:Z;class BSONValue{get[Symbol.for("@@mdb.bson.version")](){return l}[Symbol.for("nodejs.util.inspect.custom")](e,t,n){return this.inspect(e,t,n)}}class Binary extends BSONValue{get _bsontype(){return"Binary"}constructor(e,t){if(super(),null!=e&&"string"==typeof e&&!ArrayBuffer.isView(e)&&!r(e)&&!Array.isArray(e))throw new BSONError("Binary can only be constructed from Uint8Array or number[]");this.sub_type=t??Binary.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=W.allocate(Binary.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(e)?W.fromNumberArray(e):W.toLocalBufferType(e),this.position=this.buffer.byteLength)}put(e){if("string"==typeof e&&1!==e.length)throw new BSONError("only accepts single character String");if("number"!=typeof e&&1!==e.length)throw new BSONError("only accepts single character Uint8Array or Array");let t;if(t="string"==typeof e?e.charCodeAt(0):"number"==typeof e?e:e[0],t<0||t>255)throw new BSONError("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=t;else{const e=W.allocate(Binary.BUFFER_SIZE+this.buffer.length);e.set(this.buffer,0),this.buffer=e,this.buffer[this.position++]=t}}write(e,t){if(t="number"==typeof t?t:this.position,this.buffer.byteLength<t+e.length){const t=W.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(W.toLocalBufferType(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position;else if("string"==typeof e)throw new BSONError("input cannot be string")}read(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return W.toBase64(this.buffer.subarray(0,this.position))}toString(e){return"hex"===e?W.toHex(this.buffer.subarray(0,this.position)):"base64"===e?W.toBase64(this.buffer.subarray(0,this.position)):W.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(e){e=e||{};const t=W.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:1===n.length?"0"+n:n}:{$binary:{base64:t,subType:1===n.length?"0"+n:n}}}toUUID(){if(this.sub_type===Binary.SUBTYPE_UUID)return new UUID(this.buffer.slice(0,this.position));throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(e,t){return new Binary(W.fromHex(e),t)}static createFromBase64(e,t){return new Binary(W.fromBase64(e),t)}static fromExtendedJSON(e,t){let n,r;if(t=t||{},"$binary"in e?t.legacy&&"string"==typeof e.$binary&&"$type"in e?(r=e.$type?parseInt(e.$type,16):0,n=W.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(r=e.$binary.subType?parseInt(e.$binary.subType,16):0,n=W.fromBase64(e.$binary.base64)):"$uuid"in e&&(r=4,n=UUID.bytesFromString(e.$uuid)),!n)throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return r===P?new UUID(n):new Binary(n,r)}inspect(e,t,n){return n??=a,`Binary.createFromBase64(${n(W.toBase64(this.buffer.subarray(0,this.position)),t)}, ${n(this.sub_type,t)})`}}Binary.BSON_BINARY_SUBTYPE_DEFAULT=0,Binary.BUFFER_SIZE=256,Binary.SUBTYPE_DEFAULT=0,Binary.SUBTYPE_FUNCTION=1,Binary.SUBTYPE_BYTE_ARRAY=2,Binary.SUBTYPE_UUID_OLD=3,Binary.SUBTYPE_UUID=4,Binary.SUBTYPE_MD5=5,Binary.SUBTYPE_ENCRYPTED=6,Binary.SUBTYPE_COLUMN=7,Binary.SUBTYPE_SENSITIVE=8,Binary.SUBTYPE_USER_DEFINED=128;const G=/^[0-9A-F]{32}$/i,X=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class UUID extends Binary{constructor(e){let t;if(null==e)t=UUID.generate();else if(e instanceof UUID)t=W.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=W.toLocalBufferType(e);else{if("string"!=typeof e)throw new BSONError("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");t=UUID.bytesFromString(e)}super(t,P)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[W.toHex(this.buffer.subarray(0,4)),W.toHex(this.buffer.subarray(4,6)),W.toHex(this.buffer.subarray(6,8)),W.toHex(this.buffer.subarray(8,10)),W.toHex(this.buffer.subarray(10,16))].join("-"):W.toHex(this.buffer)}toString(e){return"hex"===e?W.toHex(this.id):"base64"===e?W.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return W.equals(e.id,this.id);try{return W.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=W.randomBytes(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}static isValid(e){return!!e&&("string"==typeof e?UUID.isValidUUIDString(e):o(e)?16===e.byteLength:"Binary"===e._bsontype&&e.sub_type===this.SUBTYPE_UUID&&16===e.buffer.byteLength)}static createFromHexString(e){const t=UUID.bytesFromString(e);return new UUID(t)}static createFromBase64(e){return new UUID(W.fromBase64(e))}static bytesFromString(e){if(!UUID.isValidUUIDString(e))throw new BSONError("UUID string representation must be 32 hex digits or canonical hyphenated representation");return W.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return G.test(e)||X.test(e)}inspect(e,t,n){return n??=a,`new UUID(${n(this.toHexString(),t)})`}}class Code extends BSONValue{get _bsontype(){return"Code"}constructor(e,t){super(),this.code=e.toString(),this.scope=t??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(e){return new Code(e.$code,e.$scope)}inspect(e,t,n){n??=a;let r=n(this.code,t);const o=r.includes("\n");return null!=this.scope&&(r+=`,${o?"\n":" "}${n(this.scope,t)}`),`new Code(${o?"\n":""}${r}${o&&null===this.scope?"\n":""})`}}function Q(e){return null!=e&&"object"==typeof e&&"$id"in e&&null!=e.$id&&"$ref"in e&&"string"==typeof e.$ref&&(!("$db"in e)||"$db"in e&&"string"==typeof e.$db)}class DBRef extends BSONValue{get _bsontype(){return"DBRef"}constructor(e,t,n,r){super();const o=e.split(".");2===o.length&&(n=o.shift(),e=o.shift()),this.collection=e,this.oid=t,this.db=n,this.fields=r||{}}get namespace(){return this.collection}set namespace(e){this.collection=e}toJSON(){const e=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(e.$db=this.db),e}toExtendedJSON(e){e=e||{};let t={$ref:this.collection,$id:this.oid};return e.legacy||(this.db&&(t.$db=this.db),t=Object.assign(t,this.fields)),t}static fromExtendedJSON(e){const t=Object.assign({},e);return delete t.$ref,delete t.$id,delete t.$db,new DBRef(e.$ref,e.$id,e.$db,t)}inspect(e,t,n){n??=a;const r=[n(this.namespace,t),n(this.oid,t),...this.db?[n(this.db,t)]:[],...Object.keys(this.fields).length>0?[n(this.fields,t)]:[]];return r[1]=n===a?`new ObjectId(${r[1]})`:r[1],`new DBRef(${r.join(", ")})`}}function ee(e){if(""===e)return e;let t=0;const n="-"===e[t],r="+"===e[t];(r||n)&&(t+=1);let o=!1;for(;t<e.length&&"0"===e[t];++t)o=!0;return o?`${n?"-":""}${e.length===t?"0":e.slice(t)}`:r?e.slice(1):e}let te;try{te=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch{}const ne=4294967296,re=0x10000000000000000,oe=re/2,ie={},se={},ue=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(e=0,t,n){super(),"bigint"==typeof e?Object.assign(this,Long.fromBigInt(e,!!t)):"string"==typeof e?Object.assign(this,Long.fromString(e,!!t)):(this.low=0|e,this.high=0|t,this.unsigned=!!n)}static fromBits(e,t,n){return new Long(e,t,n)}static fromInt(e,t){let n,r,o;return t?(o=0<=(e>>>=0)&&e<256)&&(r=se[e],r)?r:(n=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(se[e]=n),n):(o=-128<=(e|=0)&&e<128)&&(r=ie[e],r)?r:(n=Long.fromBits(e,e<0?-1:0,!1),o&&(ie[e]=n),n)}static fromNumber(e,t){if(isNaN(e))return t?Long.UZERO:Long.ZERO;if(t){if(e<0)return Long.UZERO;if(e>=re)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-oe)return Long.MIN_VALUE;if(e+1>=oe)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%ne|0,e/ne|0,t)}static fromBigInt(e,t){return Long.fromString(e.toString(),t)}static _fromString(e,t,n){if(0===e.length)throw new BSONError("empty string");if(n<2||36<n)throw new BSONError("radix");let r;if((r=e.indexOf("-"))>0)throw new BSONError("interior hyphen");if(0===r)return Long._fromString(e.substring(1),t,n).neg();const o=Long.fromNumber(Math.pow(n,8));let i=Long.ZERO;for(let t=0;t<e.length;t+=8){const r=Math.min(8,e.length-t),s=parseInt(e.substring(t,t+r),n);if(r<8){const e=Long.fromNumber(Math.pow(n,r));i=i.mul(e).add(Long.fromNumber(s))}else i=i.mul(o),i=i.add(Long.fromNumber(s))}return i.unsigned=t,i}static fromStringStrict(e,t,n){let r=!1;if("number"==typeof t?(n=t,t=!1):r=!!t,n??=10,e.trim()!==e)throw new BSONError(`Input: '${e}' contains leading and/or trailing whitespace`);if(!function(e,t){t=t??10;const n="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,t);return!new RegExp(`[^-+${n}]`,"i").test(e)&&e}(e,n))throw new BSONError(`Input: '${e}' contains invalid characters for radix: ${n}`);const o=ee(e),i=Long._fromString(o,r,n);if(i.toString(n).toLowerCase()!==o.toLowerCase())throw new BSONError(`Input: ${e} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=n?`with radix: ${n}`:""}`);return i}static fromString(e,t,n){let r=!1;return"number"==typeof t?(n=t,t=!1):r=!!t,n??=10,"NaN"===e&&n<24||("Infinity"===e||"+Infinity"===e||"-Infinity"===e)&&n<35?Long.ZERO:Long._fromString(e,r,n)}static fromBytes(e,t,n){return n?Long.fromBytesLE(e,t):Long.fromBytesBE(e,t)}static fromBytesLE(e,t){return new Long(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)}static fromBytesBE(e,t){return new Long(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)}static isLong(e){return null!=e&&"object"==typeof e&&"__isLong__"in e&&!0===e.__isLong__}static fromValue(e,t){return"number"==typeof e?Long.fromNumber(e,t):"string"==typeof e?Long.fromString(e,t):Long.fromBits(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}add(e){Long.isLong(e)||(e=Long.fromValue(e));const t=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,u=e.low>>>16;let a=0,l=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=r+u,l+=f>>>16,f&=65535,l+=n+s,a+=l>>>16,l&=65535,a+=t+i,a&=65535,Long.fromBits(f<<16|c,a<<16|l,this.unsigned)}and(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low&e.low,this.high&e.high,this.unsigned)}compare(e){if(Long.isLong(e)||(e=Long.fromValue(e)),this.eq(e))return 0;const t=this.isNegative(),n=e.isNegative();return t&&!n?-1:!t&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1}comp(e){return this.compare(e)}divide(e){if(Long.isLong(e)||(e=Long.fromValue(e)),e.isZero())throw new BSONError("division by zero");if(te){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?te.div_u:te.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,te.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Long.UZERO:Long.ZERO;let t,n,r;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return Long.UZERO;if(e.gt(this.shru(1)))return Long.UONE;r=Long.UZERO}else{if(this.eq(Long.MIN_VALUE))return e.eq(Long.ONE)||e.eq(Long.NEG_ONE)?Long.MIN_VALUE:e.eq(Long.MIN_VALUE)?Long.ONE:(t=this.shr(1).div(e).shl(1),t.eq(Long.ZERO)?e.isNegative()?Long.ONE:Long.NEG_ONE:(n=this.sub(e.mul(t)),r=t.add(n.div(e)),r));if(e.eq(Long.MIN_VALUE))return this.unsigned?Long.UZERO:Long.ZERO;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=Long.ZERO}for(n=this;n.gte(e);){t=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));const o=Math.ceil(Math.log(t)/Math.LN2),i=o<=48?1:Math.pow(2,o-48);let s=Long.fromNumber(t),u=s.mul(e);for(;u.isNegative()||u.gt(n);)t-=i,s=Long.fromNumber(t,this.unsigned),u=s.mul(e);s.isZero()&&(s=Long.ONE),r=r.add(s),n=n.sub(u)}return r}div(e){return this.divide(e)}equals(e){return Long.isLong(e)||(e=Long.fromValue(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&this.high===e.high&&this.low===e.low}eq(e){return this.equals(e)}getHighBits(){return this.high}getHighBitsUnsigned(){return this.high>>>0}getLowBits(){return this.low}getLowBitsUnsigned(){return this.low>>>0}getNumBitsAbs(){if(this.isNegative())return this.eq(Long.MIN_VALUE)?64:this.neg().getNumBitsAbs();const e=0!==this.high?this.high:this.low;let t;for(t=31;t>0&&0==(e&1<<t);t--);return 0!==this.high?t+33:t+1}greaterThan(e){return this.comp(e)>0}gt(e){return this.greaterThan(e)}greaterThanOrEqual(e){return this.comp(e)>=0}gte(e){return this.greaterThanOrEqual(e)}ge(e){return this.greaterThanOrEqual(e)}isEven(){return 0==(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return 1==(1&this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(e){return this.comp(e)<0}lt(e){return this.lessThan(e)}lessThanOrEqual(e){return this.comp(e)<=0}lte(e){return this.lessThanOrEqual(e)}modulo(e){if(Long.isLong(e)||(e=Long.fromValue(e)),te){const t=(this.unsigned?te.rem_u:te.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,te.get_high(),this.unsigned)}return this.sub(this.div(e).mul(e))}mod(e){return this.modulo(e)}rem(e){return this.modulo(e)}multiply(e){if(this.isZero())return Long.ZERO;if(Long.isLong(e)||(e=Long.fromValue(e)),te){const t=te.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,te.get_high(),this.unsigned)}if(e.isZero())return Long.ZERO;if(this.eq(Long.MIN_VALUE))return e.isOdd()?Long.MIN_VALUE:Long.ZERO;if(e.eq(Long.MIN_VALUE))return this.isOdd()?Long.MIN_VALUE:Long.ZERO;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(Long.TWO_PWR_24)&&e.lt(Long.TWO_PWR_24))return Long.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);const t=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,u=e.low>>>16,a=65535&e.low;let l=0,f=0,c=0,h=0;return h+=o*a,c+=h>>>16,h&=65535,c+=r*a,f+=c>>>16,c&=65535,c+=o*u,f+=c>>>16,c&=65535,f+=n*a,l+=f>>>16,f&=65535,f+=r*u,l+=f>>>16,f&=65535,f+=o*s,l+=f>>>16,f&=65535,l+=t*a+n*u+r*s+o*i,l&=65535,Long.fromBits(c<<16|h,l<<16|f,this.unsigned)}mul(e){return this.multiply(e)}negate(){return!this.unsigned&&this.eq(Long.MIN_VALUE)?Long.MIN_VALUE:this.not().add(Long.ONE)}neg(){return this.negate()}not(){return Long.fromBits(~this.low,~this.high,this.unsigned)}notEquals(e){return!this.equals(e)}neq(e){return this.notEquals(e)}ne(e){return this.notEquals(e)}or(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low|e.low,this.high|e.high,this.unsigned)}shiftLeft(e){return Long.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Long.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):Long.fromBits(0,this.low<<e-32,this.unsigned)}shl(e){return this.shiftLeft(e)}shiftRight(e){return Long.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?Long.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):Long.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)}shr(e){return this.shiftRight(e)}shiftRightUnsigned(e){if(Long.isLong(e)&&(e=e.toInt()),0==(e&=63))return this;{const t=this.high;if(e<32){const n=this.low;return Long.fromBits(n>>>e|t<<32-e,t>>>e,this.unsigned)}return 32===e?Long.fromBits(t,0,this.unsigned):Long.fromBits(t>>>e-32,0,this.unsigned)}}shr_u(e){return this.shiftRightUnsigned(e)}shru(e){return this.shiftRightUnsigned(e)}subtract(e){return Long.isLong(e)||(e=Long.fromValue(e)),this.add(e.neg())}sub(e){return this.subtract(e)}toInt(){return this.unsigned?this.low>>>0:this.low}toNumber(){return this.unsigned?(this.high>>>0)*ne+(this.low>>>0):this.high*ne+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(e){return e?this.toBytesLE():this.toBytesBE()}toBytesLE(){const e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]}toBytesBE(){const e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]}toSigned(){return this.unsigned?Long.fromBits(this.low,this.high,!1):this}toString(e){if((e=e||10)<2||36<e)throw new BSONError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(Long.MIN_VALUE)){const t=Long.fromNumber(e),n=this.div(t),r=n.mul(t).sub(this);return n.toString(e)+r.toInt().toString(e)}return"-"+this.neg().toString(e)}const t=Long.fromNumber(Math.pow(e,6),this.unsigned);let n=this,r="";for(;;){const o=n.div(t);let i=(n.sub(o.mul(t)).toInt()>>>0).toString(e);if(n=o,n.isZero())return i+r;for(;i.length<6;)i="0"+i;r=""+i+r}}toUnsigned(){return this.unsigned?this:Long.fromBits(this.low,this.high,!0)}xor(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low^e.low,this.high^e.high,this.unsigned)}eqz(){return this.isZero()}le(e){return this.lessThanOrEqual(e)}toExtendedJSON(e){return e&&e.relaxed?this.toNumber():{$numberLong:this.toString()}}static fromExtendedJSON(e,t){const{useBigInt64:n=!1,relaxed:r=!0}={...t};if(e.$numberLong.length>20)throw new BSONError("$numberLong string is too long");if(!ue.test(e.$numberLong))throw new BSONError(`$numberLong string "${e.$numberLong}" is in an invalid format`);if(n){const t=BigInt(e.$numberLong);return BigInt.asIntN(64,t)}const o=Long.fromString(e.$numberLong);return r?o.toNumber():o}inspect(e,t,n){return n??=a,`new Long(${n(this.toString(),t)}${this.unsigned?`, ${n(this.unsigned,t)}`:""})`}}Long.TWO_PWR_24=Long.fromInt(1<<24),Long.MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0),Long.ZERO=Long.fromInt(0),Long.UZERO=Long.fromInt(0,!0),Long.ONE=Long.fromInt(1),Long.UONE=Long.fromInt(1,!0),Long.NEG_ONE=Long.fromInt(-1),Long.MAX_VALUE=Long.fromBits(-1,2147483647,!1),Long.MIN_VALUE=Long.fromBits(0,-2147483648,!1);const ae=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,le=/^(\+|-)?(Infinity|inf)$/i,fe=/^(\+|-)?NaN$/i,ce=6111,he=-6176,ge=W.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),de=W.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),pe=W.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),me=/^([-+])?(\d+)?$/;function be(e){return!isNaN(parseInt(e,10))}function ye(e){const t=Long.fromNumber(1e9);let n=Long.fromNumber(0);if(!(e.parts[0]||e.parts[1]||e.parts[2]||e.parts[3]))return{quotient:e,rem:n};for(let r=0;r<=3;r++)n=n.shiftLeft(32),n=n.add(new Long(e.parts[r],0)),e.parts[r]=n.div(t).low,n=n.modulo(t);return{quotient:e,rem:n}}function we(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!o(e))throw new BSONError("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new BSONError("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}static fromString(e){return Decimal128._fromString(e,{allowRounding:!1})}static fromStringWithRounding(e){return Decimal128._fromString(e,{allowRounding:!0})}static _fromString(e,t){let n=!1,r=!1,o=!1,i=!1,s=0,u=0,a=0,l=0,f=0;const c=[0];let h=0,g=0,d=0,p=0,m=new Long(0,0),b=new Long(0,0),y=0,w=0;if(e.length>=7e3)throw new BSONError(e+" not a valid Decimal128 string");const B=e.match(ae),S=e.match(le),O=e.match(fe);if(!B&&!S&&!O||0===e.length)throw new BSONError(e+" not a valid Decimal128 string");if(B){const t=B[2],n=B[4],r=B[5],o=B[6];n&&void 0===o&&we(e,"missing exponent power"),n&&void 0===t&&we(e,"missing exponent base"),void 0===n&&(r||o)&&we(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(r=!0,n="-"===e[w++]),!be(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(n?de:pe);if("N"===e[w])return new Decimal128(ge)}for(;be(e[w])||"."===e[w];)"."!==e[w]?(h<34&&("0"!==e[w]||i)&&(i||(f=u),i=!0,c[g++]=parseInt(e[w],10),h+=1),i&&(a+=1),o&&(l+=1),u+=1,w+=1):(o&&we(e,"contains multiple periods"),o=!0,w+=1);if(o&&!u)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(me);if(!t||!t[2])return new Decimal128(ge);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(ge);if(h){if(d=h-1,s=a,1!==s)for(;"0"===e[f+s-1+Number(r)+Number(o)];)s-=1}else c[0]=0,a=1,h=1,s=0;for(p<=l&&l>p+16384?p=he:p-=l;p>ce;){if(d+=1,d>=34){if(0===s){p=ce;break}we(e,"overflow")}p-=1}if(t.allowRounding){for(;p<he||h<a;){if(0===d&&s<h){p=he,s=0;break}if(h<a?a-=1:d-=1,p<ce)p+=1;else{if(c.join("").match(/^0+$/)){p=ce;break}we(e,"overflow")}}if(d+1<s){let t=u;o&&(f+=1,t+=1),r&&(f+=1,t+=1);const i=parseInt(e[f+d+1],10);let s=0;if(i>=5&&(s=1,5===i)){s=c[d]%2==1?1:0;for(let n=f+d+2;n<t;n++)if(parseInt(e[n],10)){s=1;break}}if(s){let e=d;for(;e>=0&&++c[e]>9;e--)if(c[e]=0,0===e){if(!(p<ce))return new Decimal128(n?de:pe);p+=1,c[e]=1}}}}else{for(;p<he||h<a;){if(0===d){if(0===s){p=he;break}we(e,"exponent underflow")}h<a?("0"!==e[a-1+Number(r)+Number(o)]&&0!==s&&we(e,"inexact rounding"),a-=1):(0!==c[d]&&we(e,"inexact rounding"),d-=1),p<ce?p+=1:we(e,"overflow")}d+1<s&&(o&&(f+=1),r&&(f+=1),0!==parseInt(e[f+d+1],10)&&we(e,"inexact rounding"))}if(m=Long.fromNumber(0),b=Long.fromNumber(0),0===s)m=Long.fromNumber(0),b=Long.fromNumber(0);else if(d<17){let e=0;for(b=Long.fromNumber(c[e++]),m=new Long(0,0);e<=d;e++)b=b.multiply(Long.fromNumber(10)),b=b.add(Long.fromNumber(c[e]))}else{let e=0;for(m=Long.fromNumber(c[e++]);e<=d-17;e++)m=m.multiply(Long.fromNumber(10)),m=m.add(Long.fromNumber(c[e]));for(b=Long.fromNumber(c[e++]);e<=d;e++)b=b.multiply(Long.fromNumber(10)),b=b.add(Long.fromNumber(c[e]))}const E=function(e,t){if(!e&&!t)return{high:Long.fromNumber(0),low:Long.fromNumber(0)};const n=e.shiftRightUnsigned(32),r=new Long(e.getLowBits(),0),o=t.shiftRightUnsigned(32),i=new Long(t.getLowBits(),0);let s=n.multiply(o),u=n.multiply(i);const a=r.multiply(o);let l=r.multiply(i);return s=s.add(u.shiftRightUnsigned(32)),u=new Long(u.getLowBits(),0).add(a).add(l.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),l=u.shiftLeft(32).add(new Long(l.getLowBits(),0)),{high:s,low:l}}(m,Long.fromString("100000000000000000"));E.low=E.low.add(b),function(e,t){const n=e.high>>>0,r=t.high>>>0;return n<r||n===r&&e.low>>>0<t.low>>>0}(E.low,b)&&(E.high=E.high.add(Long.fromNumber(1))),y=p+6176;const N={low:Long.fromNumber(0),high:Long.fromNumber(0)};E.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))?(N.high=N.high.or(Long.fromNumber(3).shiftLeft(61)),N.high=N.high.or(Long.fromNumber(y).and(Long.fromNumber(16383).shiftLeft(47))),N.high=N.high.or(E.high.and(Long.fromNumber(0x7fffffffffff)))):(N.high=N.high.or(Long.fromNumber(16383&y).shiftLeft(49)),N.high=N.high.or(E.high.and(Long.fromNumber(562949953421311)))),N.low=E.low,n&&(N.high=N.high.or(Long.fromString("9223372036854775808")));const L=W.allocateUnsafe(16);return w=0,L[w++]=255&N.low.low,L[w++]=N.low.low>>8&255,L[w++]=N.low.low>>16&255,L[w++]=N.low.low>>24&255,L[w++]=255&N.low.high,L[w++]=N.low.high>>8&255,L[w++]=N.low.high>>16&255,L[w++]=N.low.high>>24&255,L[w++]=255&N.high.low,L[w++]=N.high.low>>8&255,L[w++]=N.high.low>>16&255,L[w++]=N.high.low>>24&255,L[w++]=255&N.high.high,L[w++]=N.high.high>>8&255,L[w++]=N.high.high>>16&255,L[w++]=N.high.high>>24&255,new Decimal128(L)}toString(){let e,t=0;const n=new Array(36);for(let e=0;e<n.length;e++)n[e]=0;let r,o,i,s=0,u=!1,a={parts:[0,0,0,0]};const l=[];s=0;const f=this.bytes,c=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,g=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,d=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new Long(c,h),new Long(g,d)).lessThan(Long.ZERO)&&l.push("-");const p=d>>26&31;if(p>>3==3){if(30===p)return l.join("")+"Infinity";if(31===p)return"NaN";e=d>>15&16383,r=8+(d>>14&1)}else r=d>>14&7,e=d>>17&16383;const m=e-6176;if(a.parts[0]=(16383&d)+((15&r)<<14),a.parts[1]=g,a.parts[2]=h,a.parts[3]=c,0===a.parts[0]&&0===a.parts[1]&&0===a.parts[2]&&0===a.parts[3])u=!0;else for(i=3;i>=0;i--){let e=0;const t=ye(a);if(a=t.quotient,e=t.rem.low,e)for(o=8;o>=0;o--)n[9*i+o]=e%10,e=Math.floor(e/10)}if(u)t=1,n[s]=0;else for(t=36;!n[s];)t-=1,s+=1;const b=t-1+m;if(b>=34||b<=-7||m>0){if(t>34)return l.push("0"),m>0?l.push(`E+${m}`):m<0&&l.push(`E${m}`),l.join("");l.push(`${n[s++]}`),t-=1,t&&l.push(".");for(let e=0;e<t;e++)l.push(`${n[s++]}`);l.push("E"),b>0?l.push(`+${b}`):l.push(`${b}`)}else if(m>=0)for(let e=0;e<t;e++)l.push(`${n[s++]}`);else{let e=t+m;if(e>0)for(let t=0;t<e;t++)l.push(`${n[s++]}`);else l.push("0");for(l.push(".");e++<0;)l.push("0");for(let r=0;r<t-Math.max(e-1,0);r++)l.push(`${n[s++]}`)}return l.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(e){return Decimal128.fromString(e.$numberDecimal)}inspect(e,t,n){return n??=a,`new Decimal128(${n(this.toString(),t)})`}}class Double extends BSONValue{get _bsontype(){return"Double"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=+e}static fromString(e){const t=Number(e);if("NaN"===e)return new Double(NaN);if("Infinity"===e)return new Double(1/0);if("-Infinity"===e)return new Double(-1/0);if(!Number.isFinite(t))throw new BSONError(`Input: ${e} is not representable as a Double`);if(e.trim()!==e)throw new BSONError(`Input: '${e}' contains whitespace`);if(""===e)throw new BSONError("Input is an empty string");if(/[^-0-9.+eE]/.test(e))throw new BSONError(`Input: '${e}' is not in decimal or exponential notation`);return new Double(t)}valueOf(){return this.value}toJSON(){return this.value}toString(e){return this.value.toString(e)}toExtendedJSON(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(e,t){const n=parseFloat(e.$numberDouble);return t&&t.relaxed?n:new Double(n)}inspect(e,t,n){return n??=a,`new Double(${n(this.value,t)})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}static fromString(e){const t=ee(e),n=Number(e);if(f<n)throw new BSONError(`Input: '${e}' is larger than the maximum value for Int32`);if(c>n)throw new BSONError(`Input: '${e}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new BSONError(`Input: '${e}' is not a safe integer`);if(n.toString()!==t)throw new BSONError(`Input: '${e}' is not a valid Int32 string`);return new Int32(n)}valueOf(){return this.value}toString(e){return this.value.toString(e)}toJSON(){return this.value}toExtendedJSON(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new Int32(e.$numberInt)}inspect(e,t,n){return n??=a,`new Int32(${n(this.value,t)})`}}class MaxKey extends BSONValue{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new MaxKey}inspect(){return"new MaxKey()"}}class MinKey extends BSONValue{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new MinKey}inspect(){return"new MinKey()"}}const Be=new Float64Array(1),Se=new Uint8Array(Be.buffer,0,8);Be[0]=-1;const Oe=0===Se[7],Ee={getNonnegativeInt32LE(e,t){if(e[t+3]>127)throw new RangeError(`Size cannot be negative at offset: ${t}`);return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},getInt32LE:(e,t)=>e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,getUint32LE:(e,t)=>e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3],getUint32BE:(e,t)=>e[t+3]+256*e[t+2]+65536*e[t+1]+16777216*e[t],getBigInt64LE(e,t){const n=Ee.getUint32LE(e,t),r=Ee.getUint32LE(e,t+4);return(BigInt(r)<<BigInt(32))+BigInt(n)},getFloat64LE:Oe?(e,t)=>(Se[7]=e[t],Se[6]=e[t+1],Se[5]=e[t+2],Se[4]=e[t+3],Se[3]=e[t+4],Se[2]=e[t+5],Se[1]=e[t+6],Se[0]=e[t+7],Be[0]):(e,t)=>(Se[0]=e[t],Se[1]=e[t+1],Se[2]=e[t+2],Se[3]=e[t+3],Se[4]=e[t+4],Se[5]=e[t+5],Se[6]=e[t+6],Se[7]=e[t+7],Be[0]),setInt32BE:(e,t,n)=>(e[t+3]=n,n>>>=8,e[t+2]=n,n>>>=8,e[t+1]=n,n>>>=8,e[t]=n,4),setInt32LE:(e,t,n)=>(e[t]=n,n>>>=8,e[t+1]=n,n>>>=8,e[t+2]=n,n>>>=8,e[t+3]=n,4),setBigInt64LE(e,t,n){const r=BigInt(4294967295);let o=Number(n&r);e[t]=o,o>>=8,e[t+1]=o,o>>=8,e[t+2]=o,o>>=8,e[t+3]=o;let i=Number(n>>BigInt(32)&r);return e[t+4]=i,i>>=8,e[t+5]=i,i>>=8,e[t+6]=i,i>>=8,e[t+7]=i,8},setFloat64LE:Oe?(e,t,n)=>(Be[0]=n,e[t]=Se[7],e[t+1]=Se[6],e[t+2]=Se[5],e[t+3]=Se[4],e[t+4]=Se[3],e[t+5]=Se[2],e[t+6]=Se[1],e[t+7]=Se[0],8):(e,t,n)=>(Be[0]=n,e[t]=Se[0],e[t+1]=Se[1],e[t+2]=Se[2],e[t+3]=Se[3],e[t+4]=Se[4],e[t+5]=Se[5],e[t+6]=Se[6],e[t+7]=Se[7],8)},Ne=new RegExp("^[0-9a-fA-F]{24}$");let Le=null;class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}constructor(e){let t;if(super(),"object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new BSONError("Argument passed in must have an id that is of type string or Buffer");t="toHexString"in e&&"function"==typeof e.toHexString?W.fromHex(e.toHexString()):e.id}else t=e;if(null==t||"number"==typeof t)this.buffer=ObjectId.generate("number"==typeof t?t:void 0);else if(ArrayBuffer.isView(t)&&12===t.byteLength)this.buffer=W.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(24!==t.length||!Ne.test(t))throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=W.fromHex(t)}ObjectId.cacheHexString&&(this.__id=W.toHex(this.id))}get id(){return this.buffer}set id(e){this.buffer=e,ObjectId.cacheHexString&&(this.__id=W.toHex(e))}toHexString(){if(ObjectId.cacheHexString&&this.__id)return this.__id;const e=W.toHex(this.id);return ObjectId.cacheHexString&&!this.__id&&(this.__id=e),e}static getInc(){return ObjectId.index=(ObjectId.index+1)%16777215}static generate(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));const t=ObjectId.getInc(),n=W.allocateUnsafe(12);return Ee.setInt32BE(n,0,e),null===Le&&(Le=W.randomBytes(5)),n[4]=Le[0],n[5]=Le[1],n[6]=Le[2],n[7]=Le[3],n[8]=Le[4],n[11]=255&t,n[10]=t>>8&255,n[9]=t>>16&255,n}toString(e){return"base64"===e?W.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"ObjectId"===e._bsontype}equals(e){if(null==e)return!1;if(ObjectId.is(e))return this.buffer[11]===e.buffer[11]&&W.equals(this.buffer,e.buffer);if("string"==typeof e)return e.toLowerCase()===this.toHexString();if("object"==typeof e&&"function"==typeof e.toHexString){const t=e.toHexString(),n=this.toHexString();return"string"==typeof t&&t.toLowerCase()===n}return!1}getTimestamp(){const e=new Date,t=Ee.getUint32BE(this.buffer,0);return e.setTime(1e3*Math.floor(t)),e}static createPk(){return new ObjectId}serializeInto(e,t){return e[t]=this.buffer[0],e[t+1]=this.buffer[1],e[t+2]=this.buffer[2],e[t+3]=this.buffer[3],e[t+4]=this.buffer[4],e[t+5]=this.buffer[5],e[t+6]=this.buffer[6],e[t+7]=this.buffer[7],e[t+8]=this.buffer[8],e[t+9]=this.buffer[9],e[t+10]=this.buffer[10],e[t+11]=this.buffer[11],12}static createFromTime(e){const t=W.allocate(12);for(let e=11;e>=4;e--)t[e]=0;return Ee.setInt32BE(t,0,e),new ObjectId(t)}static createFromHexString(e){if(24!==e?.length)throw new BSONError("hex string must be 24 characters");return new ObjectId(W.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(W.fromBase64(e))}static isValid(e){if(null==e)return!1;try{return new ObjectId(e),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(e){return new ObjectId(e.$oid)}inspect(e,t,n){return n??=a,`new ObjectId(${n(this.toHexString(),t)})`}}function ve(e,t,n){let r=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)r+=xe(o.toString(),e[o],t,!0,n);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))r+=xe(o,e[o],t,!1,n)}return r}function xe(e,t,n=!1,o=!1,s=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+W.utf8ByteLength(e)+1+4+W.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=p&&t<=d&&t>=c&&t<=f?(null!=e?W.utf8ByteLength(e)+1:0)+5:(null!=e?W.utf8ByteLength(e)+1:0)+9;case"undefined":return o||!s?(null!=e?W.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?W.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&t[Symbol.for("@@mdb.bson.version")]!==l)throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?W.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?W.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||u(t))return(null!=e?W.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||r(t))return(null!=e?W.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?W.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?W.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?W.utf8ByteLength(e)+1:0)+1+4+4+W.utf8ByteLength(t.code.toString())+1+ve(t.scope,n,s):(null!=e?W.utf8ByteLength(e)+1:0)+1+4+W.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const n=t;return n.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?W.utf8ByteLength(e)+1:0)+(n.position+1+4+1+4):(null!=e?W.utf8ByteLength(e)+1:0)+(n.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?W.utf8ByteLength(e)+1:0)+W.utf8ByteLength(t.value)+4+1+1;if("DBRef"===t._bsontype){const r=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(r.$db=t.db),(null!=e?W.utf8ByteLength(e)+1:0)+1+ve(r,n,s)}return t instanceof RegExp||i(t)?(null!=e?W.utf8ByteLength(e)+1:0)+1+W.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?W.utf8ByteLength(e)+1:0)+1+W.utf8ByteLength(t.pattern)+1+W.utf8ByteLength(t.options)+1:(null!=e?W.utf8ByteLength(e)+1:0)+ve(t,n,s)+1;case"function":if(n)return(null!=e?W.utf8ByteLength(e)+1:0)+1+4+W.utf8ByteLength(t.toString())+1}return 0}ObjectId.index=Math.floor(16777215*Math.random());class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}constructor(e,t){if(super(),this.pattern=e,this.options=(t??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let e=0;e<this.options.length;e++)if("i"!==this.options[e]&&"m"!==this.options[e]&&"x"!==this.options[e]&&"l"!==this.options[e]&&"s"!==this.options[e]&&"u"!==this.options[e])throw new BSONError(`The regular expression option [${this.options[e]}] is not supported`)}static parseOptions(e){return e?e.split("").sort().join(""):""}toExtendedJSON(e){return(e=e||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(e){if("$regex"in e){if("string"==typeof e.$regex)return new BSONRegExp(e.$regex,BSONRegExp.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new BSONRegExp(e.$regularExpression.pattern,BSONRegExp.parseOptions(e.$regularExpression.options));throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(e)}`)}inspect(e,t,n){const r=function(e){if(null!=e&&"object"==typeof e&&"stylize"in e&&"function"==typeof e.stylize)return e.stylize}(t)??(e=>e);return n??=a,`new BSONRegExp(${r(n(this.pattern),"regexp")}, ${r(n(this.options),"regexp")})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}constructor(e){super(),this.value=e}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(e){return new BSONSymbol(e.$symbol)}inspect(e,t,n){return n??=a,`new BSONSymbol(${n(this.value,t)})`}}const Ie=Long;class Timestamp extends Ie{get _bsontype(){return"Timestamp"}constructor(e){if(null==e)super(0,0,!0);else if("bigint"==typeof e)super(e,!0);else if(Long.isLong(e))super(e.low,e.high,!0);else{if("object"!=typeof e||!("t"in e)||!("i"in e))throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");{if("number"!=typeof e.t&&("object"!=typeof e.t||"Int32"!==e.t._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof e.i&&("object"!=typeof e.i||"Int32"!==e.i._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");const t=Number(e.t),n=Number(e.i);if(t<0||Number.isNaN(t))throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");if(t>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(n,t,!0)}}}toJSON(){return{$timestamp:this.toString()}}static fromInt(e){return new Timestamp(Long.fromInt(e,!0))}static fromNumber(e){return new Timestamp(Long.fromNumber(e,!0))}static fromBits(e,t){return new Timestamp({i:e,t})}static fromString(e,t){return new Timestamp(Long.fromString(e,!0,t))}toExtendedJSON(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,n=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:n,i:t})}inspect(e,t,n){return n??=a,`new Timestamp({ t: ${n(this.high>>>0,t)}, i: ${n(this.low>>>0,t)} })`}}Timestamp.MAX_VALUE=Long.MAX_UNSIGNED_VALUE;const _e=Long.fromNumber(d),$e=Long.fromNumber(p);function Ue(e,t,n){const r=(t=null==t?{}:t)&&t.index?t.index:0,o=Ee.getInt32LE(e,r);if(o<5)throw new BSONError(`bson size must be >= 5, is ${o}`);if(t.allowObjectSmallerThanBufferSize&&e.length<o)throw new BSONError(`buffer length ${e.length} must be >= bson size ${o}`);if(!t.allowObjectSmallerThanBufferSize&&e.length!==o)throw new BSONError(`buffer length ${e.length} must === bson size ${o}`);if(o+r>e.byteLength)throw new BSONError(`(bson size ${o} + options.index ${r} must be <= buffer length ${e.byteLength})`);if(0!==e[r+o-1])throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return je(e,r,t,n)}const Te=/^\$ref$|^\$id$|^\$db$/;function je(e,t,n,r=!1){const o=null==n.fieldsAsRaw?null:n.fieldsAsRaw,i=null!=n.raw&&n.raw,s="boolean"==typeof n.bsonRegExp&&n.bsonRegExp,u=n.promoteBuffers??!1,a=n.promoteLongs??!0,l=n.promoteValues??!0,f=n.useBigInt64??!1;if(f&&!l)throw new BSONError("Must either request bigint or Long for int64 deserialization");if(f&&!a)throw new BSONError("Must either request bigint or Long for int64 deserialization");let c,h,g=!0;const d=(null==n.validation?{utf8:!0}:n.validation).utf8;if("boolean"==typeof d)c=d;else{g=!1;const e=Object.keys(d).map((function(e){return d[e]}));if(0===e.length)throw new BSONError("UTF-8 validation setting cannot be empty");if("boolean"!=typeof e[0])throw new BSONError("Invalid UTF-8 validation option, must specify boolean values");if(c=e[0],!e.every((e=>e===c)))throw new BSONError("Invalid UTF-8 validation option - keys must be all true or all false")}if(!g){h=new Set;for(const e of Object.keys(d))h.add(e)}const p=t;if(e.length<5)throw new BSONError("corrupt bson message < 5 bytes long");const M=Ee.getInt32LE(e,t);if(t+=4,M<5||M>e.length)throw new BSONError("corrupt bson message");const z=r?[]:{};let C=0,F=!r&&null;for(;;){const d=e[t++];if(0===d)break;let p=t;for(;0!==e[p]&&p<e.length;)p++;if(p>=e.byteLength)throw new BSONError("Bad BSON Document: illegal CString");const M=r?C++:W.toUTF8(e,t,p,!1);let V,k=!0;if(k=g||h?.has(M)?c:!c,!1!==F&&"$"===M[0]&&(F=Te.test(M)),t=p+1,d===b){const n=Ee.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");V=W.toUTF8(e,t,t+n-1,k),t+=n}else if(d===O){const n=W.allocateUnsafe(12);for(let r=0;r<12;r++)n[r]=e[t+r];V=new ObjectId(n),t+=12}else if(d===U&&!1===l)V=new Int32(Ee.getInt32LE(e,t)),t+=4;else if(d===U)V=Ee.getInt32LE(e,t),t+=4;else if(d===m)V=Ee.getFloat64LE(e,t),t+=8,!1===l&&(V=new Double(V));else if(d===N){const n=Ee.getInt32LE(e,t),r=Ee.getInt32LE(e,t+4);t+=8,V=new Date(new Long(n,r).toNumber())}else if(d===E){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");V=1===e[t++]}else if(d===y){const r=t,o=Ee.getInt32LE(e,t);if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)V=e.slice(t,t+o);else{let t=n;g||(t={...n,validation:{utf8:k}}),V=je(e,r,t,!1)}t+=o}else if(d===w){const r=t,i=Ee.getInt32LE(e,t);let s=n;const u=t+i;if(o&&o[M]&&(s={...n,raw:!0}),g||(s={...s,validation:{utf8:k}}),V=je(e,r,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==u)throw new BSONError("corrupted array bson")}else if(d===S)V=void 0;else if(d===L)V=null;else if(d===j)if(f)V=Ee.getBigInt64LE(e,t),t+=8;else{const n=Ee.getInt32LE(e,t),r=Ee.getInt32LE(e,t+4);t+=8;const o=new Long(n,r);V=a&&!0===l&&o.lessThanOrEqual(_e)&&o.greaterThanOrEqual($e)?o.toNumber():o}else if(d===R){const n=W.allocateUnsafe(16);for(let r=0;r<16;r++)n[r]=e[t+r];t+=16,V=new Decimal128(n)}else if(d===B){let n=Ee.getInt32LE(e,t);t+=4;const r=n,o=e[t++];if(n<0)throw new BSONError("Negative binary type element size found");if(n>e.byteLength)throw new BSONError("Binary type size larger than document size");if(null!=e.slice){if(o===Binary.SUBTYPE_BYTE_ARRAY){if(n=Ee.getInt32LE(e,t),t+=4,n<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}u&&l?V=W.toLocalBufferType(e.slice(t,t+n)):(V=new Binary(e.slice(t,t+n),o),o===P&&UUID.isValid(V)&&(V=V.toUUID()))}else{if(o===Binary.SUBTYPE_BYTE_ARRAY){if(n=Ee.getInt32LE(e,t),t+=4,n<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(n>r-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(n<r-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}if(u&&l)for(V=W.allocateUnsafe(n),p=0;p<n;p++)V[p]=e[t+p];else V=new Binary(e.slice(t,t+n),o),o===P&&UUID.isValid(V)&&(V=V.toUUID())}t+=n}else if(d===v&&!1===s){for(p=t;0!==e[p]&&p<e.length;)p++;if(p>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=W.toUTF8(e,t,p,!1);for(p=t=p+1;0!==e[p]&&p<e.length;)p++;if(p>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=W.toUTF8(e,t,p,!1);t=p+1;const o=new Array(r.length);for(p=0;p<r.length;p++)switch(r[p]){case"m":o[p]="m";break;case"s":o[p]="g";break;case"i":o[p]="i"}V=new RegExp(n,o.join(""))}else if(d===v&&!0===s){for(p=t;0!==e[p]&&p<e.length;)p++;if(p>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=W.toUTF8(e,t,p,!1);for(p=t=p+1;0!==e[p]&&p<e.length;)p++;if(p>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=W.toUTF8(e,t,p,!1);t=p+1,V=new BSONRegExp(n,r)}else if(d===_){const n=Ee.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");const r=W.toUTF8(e,t,t+n-1,k);V=l?r:new BSONSymbol(r),t+=n}else if(d===T)V=new Timestamp({i:Ee.getUint32LE(e,t),t:Ee.getUint32LE(e,t+4)}),t+=8;else if(d===D)V=new MinKey;else if(d===A)V=new MaxKey;else if(d===I){const n=Ee.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");const r=W.toUTF8(e,t,t+n-1,k);V=new Code(r),t+=n}else if(d===$){const r=Ee.getInt32LE(e,t);if(t+=4,r<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=Ee.getInt32LE(e,t);if(t+=4,o<=0||o>e.length-t||0!==e[t+o-1])throw new BSONError("bad string length in bson");const i=W.toUTF8(e,t,t+o-1,k),s=t+=o,u=Ee.getInt32LE(e,t),a=je(e,s,n,!1);if(t+=u,r<8+u+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(r>8+u+o)throw new BSONError("code_w_scope total size is too long, clips outer document");V=new Code(i,a)}else{if(d!==x)throw new BSONError(`Detected unknown BSON type ${d.toString(16)} for fieldname "${M}"`);{const n=Ee.getInt32LE(e,t);if(t+=4,n<=0||n>e.length-t||0!==e[t+n-1])throw new BSONError("bad string length in bson");const r=W.toUTF8(e,t,t+n-1,k);t+=n;const o=W.allocateUnsafe(12);for(let n=0;n<12;n++)o[n]=e[t+n];const i=new ObjectId(o);t+=12,V=new DBRef(r,i)}}"__proto__"===M?Object.defineProperty(z,M,{value:V,writable:!0,enumerable:!0,configurable:!0}):z[M]=V}if(M!==t-p){if(r)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!F)return z;if(Q(z)){const e=Object.assign({},z);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(z.$ref,z.$id,z.$db,e)}return z}const Re=/\x00/,De=new Set(["$db","$ref","$id","$clusterTime"]);function Ae(e,t,n,r){e[r++]=b,e[(r=r+W.encodeUTF8Into(e,t,r)+1)-1]=0;const o=W.encodeUTF8Into(e,n,r+4);return Ee.setInt32LE(e,r,o+1),r=r+4+o,e[r++]=0,r}function Me(e,t,n,r){const o=!Object.is(n,-0)&&Number.isSafeInteger(n)&&n<=f&&n>=c?U:m;return e[r++]=o,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r+=o===U?Ee.setInt32LE(e,r,n):Ee.setFloat64LE(e,r,n)}function Pe(e,t,n,r){return e[r++]=j,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r+=Ee.setBigInt64LE(e,r,n)}function ze(e,t,n,r){return e[r++]=L,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r}function Ce(e,t,n,r){return e[r++]=E,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,e[r++]=n?1:0,r}function Fe(e,t,n,r){e[r++]=N,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=Long.fromNumber(n.getTime()),i=o.getLowBits(),s=o.getHighBits();return r+=Ee.setInt32LE(e,r,i),r+=Ee.setInt32LE(e,r,s)}function Ve(e,t,n,r){if(e[r++]=v,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,n.source&&null!=n.source.match(Re))throw new BSONError("value "+n.source+" must not contain null bytes");return r+=W.encodeUTF8Into(e,n.source,r),e[r++]=0,n.ignoreCase&&(e[r++]=105),n.global&&(e[r++]=115),n.multiline&&(e[r++]=109),e[r++]=0,r}function ke(e,t,n,r){if(e[r++]=v,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,null!=n.pattern.match(Re))throw new BSONError("pattern "+n.pattern+" must not contain null bytes");r+=W.encodeUTF8Into(e,n.pattern,r),e[r++]=0;const o=n.options.split("").sort().join("");return r+=W.encodeUTF8Into(e,o,r),e[r++]=0,r}function Je(e,t,n,r){return null===n?e[r++]=L:"MinKey"===n._bsontype?e[r++]=D:e[r++]=A,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r}function qe(e,t,n,r){return e[r++]=O,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r+=n.serializeInto(e,r)}function He(e,t,n,r){e[r++]=B,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.length;if(r+=Ee.setInt32LE(e,r,o),e[r++]=M,o<=16)for(let t=0;t<o;t++)e[r+t]=n[t];else e.set(n,r);return r+=o}function Ke(e,t,n,r,o,i,s,u,a){if(a.has(n))throw new BSONError("Cannot convert circular structure to BSON");a.add(n),e[r++]=Array.isArray(n)?w:y,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const l=rt(e,n,o,r,i+1,s,u,a);return a.delete(n),l}function Ye(e,t,n,r){e[r++]=R,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;for(let t=0;t<16;t++)e[r+t]=n.bytes[t];return r+16}function Ze(e,t,n,r){e[r++]="Long"===n._bsontype?j:T,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.getLowBits(),i=n.getHighBits();return r+=Ee.setInt32LE(e,r,o),r+=Ee.setInt32LE(e,r,i)}function We(e,t,n,r){return n=n.valueOf(),e[r++]=U,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r+=Ee.setInt32LE(e,r,n)}function Ge(e,t,n,r){return e[r++]=m,r+=W.encodeUTF8Into(e,t,r),e[r++]=0,r+=Ee.setFloat64LE(e,r,n.value)}function Xe(e,t,n,r){e[r++]=I,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.toString(),i=W.encodeUTF8Into(e,o,r+4)+1;return Ee.setInt32LE(e,r,i),r=r+4+i-1,e[r++]=0,r}function Qe(e,t,n,r,o=!1,i=0,s=!1,u=!0,a){if(n.scope&&"object"==typeof n.scope){e[r++]=$,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;let l=r;const f=n.code;r+=4;const c=W.encodeUTF8Into(e,f,r+4)+1;Ee.setInt32LE(e,r,c),e[r+4+c-1]=0,r=r+c+4;const h=rt(e,n.scope,o,r,i+1,s,u,a);r=h-1;const g=h-l;l+=Ee.setInt32LE(e,l,g),e[r++]=0}else{e[r++]=I,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.code.toString(),i=W.encodeUTF8Into(e,o,r+4)+1;Ee.setInt32LE(e,r,i),r=r+4+i-1,e[r++]=0}return r}function et(e,t,n,r){e[r++]=B,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=n.buffer;let i=n.position;if(n.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),r+=Ee.setInt32LE(e,r,i),e[r++]=n.sub_type,n.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,r+=Ee.setInt32LE(e,r,i)),i<=16)for(let t=0;t<i;t++)e[r+t]=o[t];else e.set(o,r);return r+=n.position}function tt(e,t,n,r){e[r++]=_,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;const o=W.encodeUTF8Into(e,n.value,r+4)+1;return Ee.setInt32LE(e,r,o),r=r+4+o-1,e[r++]=0,r}function nt(e,t,n,r,o,i,s){e[r++]=y,r+=W.encodeUTF8Into(e,t,r),e[r++]=0;let u=r,a={$ref:n.collection||n.namespace,$id:n.oid};null!=n.db&&(a.$db=n.db),a=Object.assign(a,n.fields);const l=rt(e,a,!1,r,o+1,i,!0,s),f=l-u;return u+=Ee.setInt32LE(e,r,f),l}function rt(e,t,n,a,f,c,h,g){if(null==g){if(null==t)return e[0]=5,e[1]=0,e[2]=0,e[3]=0,e[4]=0,5;if(Array.isArray(t))throw new BSONError("serialize does not support an array as the root input");if("object"!=typeof t)throw new BSONError("serialize does not support non-object as the root input");if("_bsontype"in t&&"string"==typeof t._bsontype)throw new BSONError("BSON types cannot be serialized as a document");if(u(t)||i(t)||o(t)||r(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");g=new Set}g.add(t);let d=a+4;if(Array.isArray(t))for(let r=0;r<t.length;r++){const s=`${r}`;let a=t[r];if("function"==typeof a?.toBSON&&(a=a.toBSON()),"string"==typeof a)d=Ae(e,s,a,d);else if("number"==typeof a)d=Me(e,s,a,d);else if("bigint"==typeof a)d=Pe(e,s,a,d);else if("boolean"==typeof a)d=Ce(e,s,a,d);else if(a instanceof Date||u(a))d=Fe(e,s,a,d);else if(void 0===a)d=ze(e,s,0,d);else if(null===a)d=ze(e,s,0,d);else if(o(a))d=He(e,s,a,d);else if(a instanceof RegExp||i(a))d=Ve(e,s,a,d);else if("object"==typeof a&&null==a._bsontype)d=Ke(e,s,a,d,n,f,c,h,g);else{if("object"==typeof a&&a[Symbol.for("@@mdb.bson.version")]!==l)throw new BSONVersionError;if("ObjectId"===a._bsontype)d=qe(e,s,a,d);else if("Decimal128"===a._bsontype)d=Ye(e,s,a,d);else if("Long"===a._bsontype||"Timestamp"===a._bsontype)d=Ze(e,s,a,d);else if("Double"===a._bsontype)d=Ge(e,s,a,d);else if("function"==typeof a&&c)d=Xe(e,s,a,d);else if("Code"===a._bsontype)d=Qe(e,s,a,d,n,f,c,h,g);else if("Binary"===a._bsontype)d=et(e,s,a,d);else if("BSONSymbol"===a._bsontype)d=tt(e,s,a,d);else if("DBRef"===a._bsontype)d=nt(e,s,a,d,f,c,g);else if("BSONRegExp"===a._bsontype)d=ke(e,s,a,d);else if("Int32"===a._bsontype)d=We(e,s,a,d);else if("MinKey"===a._bsontype||"MaxKey"===a._bsontype)d=Je(e,s,a,d);else if(void 0!==a._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(a._bsontype)}`)}}else if(t instanceof Map||s(t)){const r=t.entries();let s=!1;for(;!s;){const t=r.next();if(s=!!t.done,s)continue;const a=t.value[0];let p=t.value[1];"function"==typeof p?.toBSON&&(p=p.toBSON());const m=typeof p;if("string"==typeof a&&!De.has(a)){if(null!=a.match(Re))throw new BSONError("key "+a+" must not contain null bytes");if(n){if("$"===a[0])throw new BSONError("key "+a+" must not start with '$'");if(a.includes("."))throw new BSONError("key "+a+" must not contain '.'")}}if("string"===m)d=Ae(e,a,p,d);else if("number"===m)d=Me(e,a,p,d);else if("bigint"===m)d=Pe(e,a,p,d);else if("boolean"===m)d=Ce(e,a,p,d);else if(p instanceof Date||u(p))d=Fe(e,a,p,d);else if(null===p||void 0===p&&!1===h)d=ze(e,a,0,d);else if(o(p))d=He(e,a,p,d);else if(p instanceof RegExp||i(p))d=Ve(e,a,p,d);else if("object"===m&&null==p._bsontype)d=Ke(e,a,p,d,n,f,c,h,g);else{if("object"==typeof p&&p[Symbol.for("@@mdb.bson.version")]!==l)throw new BSONVersionError;if("ObjectId"===p._bsontype)d=qe(e,a,p,d);else if("object"===m&&"Decimal128"===p._bsontype)d=Ye(e,a,p,d);else if("Long"===p._bsontype||"Timestamp"===p._bsontype)d=Ze(e,a,p,d);else if("Double"===p._bsontype)d=Ge(e,a,p,d);else if("Code"===p._bsontype)d=Qe(e,a,p,d,n,f,c,h,g);else if("function"==typeof p&&c)d=Xe(e,a,p,d);else if("Binary"===p._bsontype)d=et(e,a,p,d);else if("BSONSymbol"===p._bsontype)d=tt(e,a,p,d);else if("DBRef"===p._bsontype)d=nt(e,a,p,d,f,c,g);else if("BSONRegExp"===p._bsontype)d=ke(e,a,p,d);else if("Int32"===p._bsontype)d=We(e,a,p,d);else if("MinKey"===p._bsontype||"MaxKey"===p._bsontype)d=Je(e,a,p,d);else if(void 0!==p._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(p._bsontype)}`)}}}else{if("function"==typeof t?.toBSON&&null!=(t=t.toBSON())&&"object"!=typeof t)throw new BSONError("toBSON function did not return an object");for(const r of Object.keys(t)){let s=t[r];"function"==typeof s?.toBSON&&(s=s.toBSON());const a=typeof s;if("string"==typeof r&&!De.has(r)){if(null!=r.match(Re))throw new BSONError("key "+r+" must not contain null bytes");if(n){if("$"===r[0])throw new BSONError("key "+r+" must not start with '$'");if(r.includes("."))throw new BSONError("key "+r+" must not contain '.'")}}if("string"===a)d=Ae(e,r,s,d);else if("number"===a)d=Me(e,r,s,d);else if("bigint"===a)d=Pe(e,r,s,d);else if("boolean"===a)d=Ce(e,r,s,d);else if(s instanceof Date||u(s))d=Fe(e,r,s,d);else if(void 0===s)!1===h&&(d=ze(e,r,0,d));else if(null===s)d=ze(e,r,0,d);else if(o(s))d=He(e,r,s,d);else if(s instanceof RegExp||i(s))d=Ve(e,r,s,d);else if("object"===a&&null==s._bsontype)d=Ke(e,r,s,d,n,f,c,h,g);else{if("object"==typeof s&&s[Symbol.for("@@mdb.bson.version")]!==l)throw new BSONVersionError;if("ObjectId"===s._bsontype)d=qe(e,r,s,d);else if("object"===a&&"Decimal128"===s._bsontype)d=Ye(e,r,s,d);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)d=Ze(e,r,s,d);else if("Double"===s._bsontype)d=Ge(e,r,s,d);else if("Code"===s._bsontype)d=Qe(e,r,s,d,n,f,c,h,g);else if("function"==typeof s&&c)d=Xe(e,r,s,d);else if("Binary"===s._bsontype)d=et(e,r,s,d);else if("BSONSymbol"===s._bsontype)d=tt(e,r,s,d);else if("DBRef"===s._bsontype)d=nt(e,r,s,d,f,c,g);else if("BSONRegExp"===s._bsontype)d=ke(e,r,s,d);else if("Int32"===s._bsontype)d=We(e,r,s,d);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)d=Je(e,r,s,d);else if(void 0!==s._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}}}g.delete(t),e[d++]=0;const p=d-a;return a+=Ee.setInt32LE(e,a,p),d}const ot={$oid:ObjectId,$binary:Binary,$uuid:Binary,$symbol:BSONSymbol,$numberInt:Int32,$numberDecimal:Decimal128,$numberDouble:Double,$numberLong:Long,$minKey:MinKey,$maxKey:MaxKey,$regex:BSONRegExp,$regularExpression:BSONRegExp,$timestamp:Timestamp};function it(e,t={}){if("number"==typeof e){const n=e<=f&&e>=c,r=e<=h&&e>=g;if(t.relaxed||t.legacy)return e;if(Number.isInteger(e)&&!Object.is(e,-0)){if(n)return new Int32(e);if(r)return t.useBigInt64?BigInt(e):Long.fromNumber(e)}return new Double(e)}if(null==e||"object"!=typeof e)return e;if(e.$undefined)return null;const n=Object.keys(e).filter((t=>t.startsWith("$")&&null!=e[t]));for(let r=0;r<n.length;r++){const o=ot[n[r]];if(o)return o.fromExtendedJSON(e,t)}if(null!=e.$date){const n=e.$date,r=new Date;if(t.legacy)if("number"==typeof n)r.setTime(n);else if("string"==typeof n)r.setTime(Date.parse(n));else{if("bigint"!=typeof n)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}else if("string"==typeof n)r.setTime(Date.parse(n));else if(Long.isLong(n))r.setTime(n.toNumber());else if("number"==typeof n&&t.relaxed)r.setTime(n);else{if("bigint"!=typeof n)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof n);r.setTime(Number(n))}return r}if(null!=e.$code){const t=Object.assign({},e);return e.$scope&&(t.$scope=it(e.$scope)),Code.fromExtendedJSON(e)}if(Q(e)||e.$dbPointer){const t=e.$ref?e:e.$dbPointer;if(t instanceof DBRef)return t;const n=Object.keys(t).filter((e=>e.startsWith("$")));let r=!0;if(n.forEach((e=>{-1===["$ref","$id","$db"].indexOf(e)&&(r=!1)})),r)return DBRef.fromExtendedJSON(t)}return e}function st(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function ut(e,t){if(e instanceof Map||s(e)){const n=Object.create(null);for(const[t,r]of e){if("string"!=typeof t)throw new BSONError("Can only serialize maps with string keys");n[t]=r}return ut(n,t)}if(("object"==typeof e||"function"==typeof e)&&null!==e){const n=t.seenObjects.findIndex((t=>t.obj===e));if(-1!==n){const e=t.seenObjects.map((e=>e.propertyName)),r=e.slice(0,n).map((e=>`${e} -> `)).join(""),o=e[n],i=" -> "+e.slice(n+1,e.length-1).map((e=>`${e} -> `)).join(""),s=e[e.length-1],u=" ".repeat(r.length+o.length/2),a="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${r}${o}${i}${s}\n ${u}\\${a}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,n)=>{t.seenObjects.push({propertyName:`index ${n}`,obj:null});try{return ut(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return null;if(e instanceof Date||u(e)){const n=e.getTime(),r=n>-1&&n<2534023188e5;return t.legacy?t.relaxed&&r?{$date:e.getTime()}:{$date:st(e)}:t.relaxed&&r?{$date:st(e)}:{$date:{$numberLong:e.getTime().toString()}}}if(!("number"!=typeof e||t.relaxed&&isFinite(e))){if(Number.isInteger(e)&&!Object.is(e,-0)){if(e>=c&&e<=f)return{$numberInt:e.toString()};if(e>=g&&e<=h)return{$numberLong:e.toString()}}return{$numberDouble:Object.is(e,-0)?"-0.0":e.toString()}}if("bigint"==typeof e)return t.relaxed?Number(BigInt.asIntN(64,e)):{$numberLong:BigInt.asIntN(64,e).toString()};if(e instanceof RegExp||i(e)){let n=e.flags;if(void 0===n){const t=e.toString().match(/[gimuy]*$/);t&&(n=t[0])}return new BSONRegExp(e.source,n).toExtendedJSON(t)}return null!=e&&"object"==typeof e?function(e,t){if(null==e||"object"!=typeof e)throw new BSONError("not an object instance");const n=e._bsontype;if(void 0===n){const n={};for(const r of Object.keys(e)){t.seenObjects.push({propertyName:r,obj:null});try{const o=ut(e[r],t);"__proto__"===r?Object.defineProperty(n,r,{value:o,writable:!0,enumerable:!0,configurable:!0}):n[r]=o}finally{t.seenObjects.pop()}}return n}if(null!=e&&"object"==typeof e&&"string"==typeof e._bsontype&&e[Symbol.for("@@mdb.bson.version")]!==l)throw new BSONVersionError;if(function(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"string"==typeof e._bsontype}(e)){let r=e;if("function"!=typeof r.toExtendedJSON){const t=at[e._bsontype];if(!t)throw new BSONError("Unrecognized or invalid _bsontype: "+e._bsontype);r=t(r)}return"Code"===n&&r.scope?r=new Code(r.code,ut(r.scope,t)):"DBRef"===n&&r.oid&&(r=new DBRef(ut(r.collection,t),ut(r.oid,t),ut(r.db,t),ut(r.fields,t))),r.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof n)}(e,t):e}const at={Binary:e=>new Binary(e.value(),e.sub_type),Code:e=>new Code(e.code,e.scope),DBRef:e=>new DBRef(e.collection||e.namespace,e.oid,e.db,e.fields),Decimal128:e=>new Decimal128(e.bytes),Double:e=>new Double(e.value),Int32:e=>new Int32(e.value),Long:e=>Long.fromBits(null!=e.low?e.low:e.low_,null!=e.low?e.high:e.high_,null!=e.low?e.unsigned:e.unsigned_),MaxKey:()=>new MaxKey,MinKey:()=>new MinKey,ObjectId:e=>new ObjectId(e),BSONRegExp:e=>new BSONRegExp(e.pattern,e.options),BSONSymbol:e=>new BSONSymbol(e.value),Timestamp:e=>Timestamp.fromBits(e.low,e.high)};function lt(e,t){const n={useBigInt64:t?.useBigInt64??!1,relaxed:t?.relaxed??!0,legacy:t?.legacy??!1};return JSON.parse(e,((e,t)=>{if(-1!==e.indexOf("\0"))throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(e)}`);return it(t,n)}))}function ft(e,t,n,r){null!=n&&"object"==typeof n&&(r=n,n=0),null==t||"object"!=typeof t||Array.isArray(t)||(r=t,t=void 0,n=0);const o=ut(e,Object.assign({relaxed:!0,legacy:!1},r,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,n)}const ct=Object.create(null);function ht(e,t){try{return Ee.getNonnegativeInt32LE(e,t)}catch(e){throw new BSONOffsetError("BSON size cannot be negative",t,{cause:e})}}function gt(e,t){let n=t;for(;0!==e[n];n++);if(n===e.length-1)throw new BSONOffsetError("Null terminator not found",t);return n}ct.parse=lt,ct.stringify=ft,ct.serialize=function(e,t){return t=t||{},JSON.parse(ft(e,t))},ct.deserialize=function(e,t){return t=t||{},lt(JSON.stringify(e),t)},Object.freeze(ct);const dt=Object.create(null);dt.parseToElements=function(e,t=0){if(t??=0,e.length<5)throw new BSONOffsetError(`Input must be at least 5 bytes, got ${e.length} bytes`,t);const n=ht(e,t);if(n>e.length-t)throw new BSONOffsetError(`Parsed documentSize (${n} bytes) does not match input length (${e.length} bytes)`,t);if(0!==e[t+n-1])throw new BSONOffsetError("BSON documents must end in 0x00",t+n);const r=[];let o=t+4;for(;o<=n+t;){const i=e[o];if(o+=1,0===i){if(o-t!==n)throw new BSONOffsetError("Invalid 0x00 type byte",o);break}const s=o,u=gt(e,o)-s;let a;if(o+=u+1,1===i||18===i||9===i||17===i)a=8;else if(16===i)a=4;else if(7===i)a=12;else if(19===i)a=16;else if(8===i)a=1;else if(10===i||6===i||127===i||255===i)a=0;else if(11===i)a=gt(e,gt(e,o)+1)+1-o;else if(3===i||4===i||15===i)a=ht(e,o);else{if(2!==i&&5!==i&&12!==i&&13!==i&&14!==i)throw new BSONOffsetError(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);a=ht(e,o)+4,5===i&&(a+=1),12===i&&(a+=12)}if(a>n)throw new BSONOffsetError("value reports length larger than document",o);r.push([i,s,u,o,a]),o+=a}return r},dt.ByteUtils=W,dt.NumberUtils=Ee,Object.freeze(dt);const pt=17825792;let mt=W.allocate(pt);function bt(e){mt.length<e&&(mt=W.allocate(e))}function yt(e,t={}){const n="boolean"==typeof t.checkKeys&&t.checkKeys,r="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,o="boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined,i="number"==typeof t.minInternalBufferSize?t.minInternalBufferSize:pt;mt.length<i&&(mt=W.allocate(i));const s=rt(mt,e,n,0,0,r,o,null),u=W.allocateUnsafe(s);return u.set(mt.subarray(0,s),0),u}function wt(e,t,n={}){const r="boolean"==typeof n.checkKeys&&n.checkKeys,o="boolean"==typeof n.serializeFunctions&&n.serializeFunctions,i="boolean"!=typeof n.ignoreUndefined||n.ignoreUndefined,s="number"==typeof n.index?n.index:0,u=rt(mt,e,r,0,0,o,i,null);return t.set(mt.subarray(0,u),s),s+u-1}function Bt(e,t={}){return Ue(W.toLocalBufferType(e),t)}function St(e,t={}){return ve(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function Ot(e,t,n,r,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),u=W.toLocalBufferType(e);let a=t;for(let e=0;e<n;e++){const t=Ee.getInt32LE(u,a);s.index=a,r[o+e]=Ue(u,s),a+=t}return a}var Et=Object.freeze({__proto__:null,BSONError,BSONOffsetError,BSONRegExp,BSONRuntimeError,BSONSymbol,BSONType:z,BSONValue,BSONVersionError,Binary,Code,DBRef,Decimal128,Double,EJSON:ct,Int32,Long,MaxKey,MinKey,ObjectId,Timestamp,UUID,calculateObjectSize:St,deserialize:Bt,deserializeStream:Ot,onDemand:dt,serialize:yt,serializeWithBufferAndIndex:wt,setInternalBufferSize:bt});t.BSON=Et,t.BSONError=BSONError,t.BSONOffsetError=BSONOffsetError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=z,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=ct,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.calculateObjectSize=St,t.deserialize=Bt,t.deserializeStream=Ot,t.onDemand=dt,t.serialize=yt,t.serializeWithBufferAndIndex=wt,t.setInternalBufferSize=bt}},t={},function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}},s=!0;try{e[r].call(i.exports,i,i.exports,n),s=!1}finally{s&&delete t[r]}return i.exports}(920);var e,t}));