@mongosh/node-runtime-worker-thread 5.0.1 → 5.0.3
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 +1 -1
- package/dist/report.html +2 -2
- package/dist/serializer.d.ts +2 -2
- package/dist/serializer.js +13 -5
- package/dist/serializer.js.map +1 -1
- package/dist/worker-runtime.js +2 -2
- package/package.json +6 -6
- package/src/serializer.ts +13 -3
- package/src/worker-runtime.spec.ts +6 -1
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 r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,(()=>{return e={796(e,t,r){"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 n,o=r(653),i=(n=o)&&n.__esModule?n:{default:n};function s(e,t){var r=(t=t||{}).addListener||window.addEventListener,n=t.removeListener||window.removeEventListener,o=t.postMessage||window.postMessage,s=t.targetOrigin||"*",a=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)},u=void 0,l=new Promise((function(i,l){var f=function r(){var o=a.apply(null,arguments);if(o&&"postmsg-rpc/server"===o.sender&&o.id===t.id){if(n("message",r),o.err){var s=new Error("Unexpected error calling "+e);return Object.assign(s,o.err),l(s)}i(o.res)}};u=function(){n("message",f);var t=new Error("Canceled call to "+e);t.isCanceled=!0,l(t)},r("message",f),o(t,s)}));return l.cancel=function(){return u()},l}}},59(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(796);Object.defineProperty(t,"caller",{enumerable:!0,get:function(){return i(n).default}}),Object.defineProperty(t,"call",{enumerable:!0,get:function(){return n.call}});var o=r(808);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},808(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(r=r||{}).addListener||window.addEventListener,o=r.removeListener||window.removeEventListener,i=r.postMessage||window.postMessage,s=r.targetOrigin||"*",a=r.getMessageData||function(e){return e.data},u=r.isCallback||!1,l=function(){var r=a.apply(null,arguments);if(r&&"postmsg-rpc/client"===r.sender&&r.func===e){var n={sender:"postmsg-rpc/server",id:r.id},o=function(e){n.res=e,i(n,s)},l=function(e){n.err=Object.assign({message:e.message},e.output&&e.output.payload),i(n,s)};if(u)t.apply(null,r.args.concat((function(e,t){if(e)return l(e);o(t)})));else{var f=t.apply(null,r.args);Promise.resolve(f).then(o).catch(l)}}};return n("message",l),{close:function(){return o("message",l)}}}},653(e,t,r){"use strict";e.exports=r(829)},534(e,t,r){"use strict";var n,o,i,s=r(189),a="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function u(){i=!1}function l(e){if(e){if(e!==n){if(64!==e.length)throw new Error("Custom alphabet for shortid must be 64 unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,r){return t!==r.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be 64 unique characters. These characters were not unique: "+t.join(", "));n=e,u()}}else n!==a&&(n=a,u())}function f(){return i||(i=function(){n||l(a);for(var e,t=n.split(""),r=[],o=s.nextValue();t.length>0;)o=s.nextValue(),e=Math.floor(o*t.length),r.push(t.splice(e,1)[0]);return r.join("")}())}e.exports={get:function(){return n||a},characters:function(e){return l(e),n},seed:function(e){s.seed(e),o!==e&&(u(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},137(e,t,r){"use strict";var n,o,i=r(938);r(534),e.exports=function(e){var t="",r=Math.floor(.001*(Date.now()-1567752802062));return r===o?n++:(n=0,o=r),t+=i(7),t+=i(e),n>0&&(t+=i(n)),t+=i(r)}},938(e,t,r){"use strict";var n=r(534),o=r(109),i=r(795).customRandom;e.exports=function(e){for(var t,r=0,s="";!t;)s+=i(n.get(),1,o)(),t=e<Math.pow(16,r+1),r++;return s}},829(e,t,r){"use strict";var n=r(534),o=r(137),i=r(906),s=r(741)||0;function a(){return o(s)}e.exports=a,e.exports.generate=a,e.exports.seed=function(t){return n.seed(t),e.exports},e.exports.worker=function(t){return s=t,e.exports},e.exports.characters=function(e){return void 0!==e&&n.characters(e),n.shuffled()},e.exports.isValid=i},906(e,t,r){"use strict";var n=r(534);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+n.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},109(e,t,r){var n=r(795).random;e.exports=n},189(e){"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},741(e,t,r){"use strict";var n=r(907),o=0;!n.isMaster&&n.worker&&(o=n.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},783(e,t,r){"use strict";var n=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(r(928)),i=r(434),s=r(16),a=r(280),u=r(495),l=r(196),f=r(286),c=r(852);t.WorkerRuntime=class WorkerRuntime{constructor(e,t,r={},n={},s=new i.EventEmitter){this.evaluationListener=null,this.workerProcessPath=o.default.resolve(__dirname,"worker-runtime.js"),this.initOptions={uri:e,driverOptions:t,cliOptions:r,workerOptions:n},this.eventEmitter=s,this.initWorkerPromise=this.initWorker()}async initWorker(){const e=new Worker((0,s.pathToFileURL)(this.workerProcessPath).href,this.initOptions.workerOptions);await(async()=>{await Promise.race([(async()=>{let t;for(;[t]=await(0,i.once)(e,"message");)if("ready"===(null==t?void 0:t.data))return})(),(async()=>{const[t]=await(0,i.once)(e,"error");if(t)throw t.message=`Worker thread failed to start with error: ${t.message}`,t})()])})();const{interrupt:t}=(0,a.createCaller)(["interrupt"],e);let r=null;this.workerProcessRuntime=Object.assign((0,a.createCaller)(["init","evaluate","getCompletions","getShellPrompt","setEvaluationListener","interrupt"],e),{interrupt:()=>r?((0,l.interrupt)(r),!0):t()}),this.workerThreadEvaluationListener=new f.WorkerThreadEvaluationListener(this,e),(0,a.exposeAll)({onRunInterruptible(e){r=e}},e),this.workerProcessMongoshBus=new c.WorkerProcessMongoshBus(this.eventEmitter,e),await this.workerProcessRuntime.init(this.initOptions.uri,(0,u.serializeConnectOptions)(this.initOptions.driverOptions),this.initOptions.cliOptions),this.workerProcess=e}async evaluate(e){return await this.initWorkerPromise,(0,u.deserializeEvaluationResult)(await this.workerProcessRuntime.evaluate(e))}async getCompletions(e){return await this.initWorkerPromise,await this.workerProcessRuntime.getCompletions(e)}async getShellPrompt(){return await this.initWorkerPromise,await this.workerProcessRuntime.getShellPrompt()}setEvaluationListener(e){const t=this.evaluationListener;return this.evaluationListener=e,t}async terminate(){try{await this.initWorkerPromise}catch(e){}this.workerProcessRuntime&&this.workerProcessRuntime[a.cancel](),this.workerProcess&&this.workerProcess.terminate(),this.workerThreadEvaluationListener&&this.workerThreadEvaluationListener.terminate(),this.workerProcessMongoshBus&&this.workerProcessMongoshBus.terminate()}async interrupt(){return await this.initWorkerPromise,this.workerProcessRuntime.interrupt()}async waitForRuntimeToBeReady(){await this.initWorkerPromise}}},280(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.cancel=t.close=void 0,t.exposeAll=function(e,r){return Object.entries(e).forEach((([e,t])=>{const{close:s}=(0,n.expose)(e,(async(...e)=>{try{return{type:"Message",payload:await t(...e)}}catch(e){return{type:"Error",payload:(0,o.serializeError)(e)}}}),i(r));t.close=s})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,r,s={}){const a={},u=new Set;return e.forEach((e=>{const t=(0,n.caller)(e,i(r));a[e]=async(...r)=>{var n;const i="function"==typeof s[e]?null===(n=s[e])||void 0===n?void 0:n.call(s,...r):r,a=t(...i);u.add(a);const l=await a;if(u.delete(a),(f=l)&&"object"==typeof f&&"Error"===f.type)throw(0,o.deserializeError)(l.payload);var f;return l.payload}})),Object.defineProperty(a,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),a};const n=r(59),o=r(495);function i(e){return{addListener:e.addEventListener.bind(e),removeListener:e.removeEventListener.bind(e),postMessage:t=>e.postMessage(t),getMessageData(e){var t;return null!==(t=e.data)&&void 0!==t?t:e}}}t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel")},495(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.serializeError=i,t.deserializeError=s,t.serializeEvaluationResult=function({type:e,printable:t,source:r}){return"object"!=typeof(s=t)&&"function"!=typeof s||null===s?{type:e,printable:t,source:r}:function(e){return e&&e.name&&e.message&&e.stack}(t)?{type:"SerializedErrorResult",printable:i(t),source:r}:null===e?{type:"InspectResult",printable:(0,n.inspect)(t),source:r}:{type:"SerializedShellApiResult",printable:{origType:e,serializedValue:o.EJSON.serialize(t)}};var s},t.deserializeEvaluationResult=function({type:e,printable:t,source:r}){return"SerializedErrorResult"===e?{type:e,printable:s(t),source:r}:"SerializedShellApiResult"===e?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:r}:{type:e,printable:t,source:r}},t.serializeConnectOptions=function(e){var t;const r={...e};for(const e of a)(null===(t=r.autoEncryption)||void 0===t?void 0:t[e])&&(r.autoEncryption={...r.autoEncryption,[e]:o.EJSON.serialize(r.autoEncryption[e],{relaxed:!1})});return r},t.deserializeConnectOptions=function(e){var t;const r={...e};for(const e of a)(null===(t=r.autoEncryption)||void 0===t?void 0:t[e])&&(r.autoEncryption={...r.autoEncryption,[e]:o.EJSON.deserialize(r.autoEncryption[e],{relaxed:!1})});return r};const n=r(23),o=r(78);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").filter((t=>"function"!=typeof e[t])).reduce(((t,r)=>(t[r]=e[r],t)),{})}function s(e){return Object.assign(new Error,e)}const a=["schemaMap","encryptedFieldsMap"]},852(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerProcessMongoshBus=void 0;const n=r(280);t.WorkerProcessMongoshBus=class WorkerProcessMongoshBus{constructor(e,t){const r=(0,n.exposeAll)({emit(...t){e.emit(...t)},on(){throw new Error("Can't use `on` method on WorkerProcessMongoshBus")},once(){throw new Error("Can't use `once` method on WorkerProcessMongoshBus")}},t);this.exposedEmitter=r}terminate(){this.exposedEmitter[n.close]()}}},286(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerThreadEvaluationListener=void 0;const n=r(280),o=r(495);t.WorkerThreadEvaluationListener=class WorkerThreadEvaluationListener{constructor(e,t){this.exposedListener=(0,n.exposeAll)({onPrompt(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.onPrompt)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:""},onPrint(t){var r,n;return t=t.map(o.deserializeEvaluationResult),null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.onPrint)||void 0===n?void 0:n.call(r,t)},setConfig(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.setConfig)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:Promise.resolve("ignored")},resetConfig(t){var r,n,o;return null!==(o=null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.resetConfig)||void 0===n?void 0:n.call(r,t))&&void 0!==o?o:Promise.resolve("ignored")},validateConfig(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.validateConfig)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:Promise.resolve(null)},getConfig(t){var r,n;return null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.getConfig)||void 0===n?void 0:n.call(r,t)},listConfigOptions(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.listConfigOptions)||void 0===r?void 0:r.call(t)},onClearCommand(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.onClearCommand)||void 0===r?void 0:r.call(t)},onExit(t){var r,n,o;return null!==(o=null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.onExit)||void 0===n?void 0:n.call(r,t))&&void 0!==o?o:Promise.resolve()},getLogPath(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.getLogPath)||void 0===r?void 0:r.call(t)}},t)}terminate(){this.exposedListener[n.close]()}}},196(e){"use strict";e.exports=require("interruptor")},907(e){"use strict";e.exports=require("cluster")},982(e){"use strict";e.exports=require("crypto")},434(e){"use strict";e.exports=require("events")},928(e){"use strict";e.exports=require("path")},16(e){"use strict";e.exports=require("url")},23(e){"use strict";e.exports=require("util")},78(e,t){"use strict";const r=(()=>{const e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return t=>e.call(t)})();function n(e){return"Uint8Array"===r(e)}function o(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&("ArrayBuffer"===e[Symbol.toStringTag]||"SharedArrayBuffer"===e[Symbol.toStringTag])}function i(e){return e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)}function s(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&"Map"===e[Symbol.toStringTag]}function a(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function u(e,t){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?{$numberLong:`${t}`}:s(t)?Object.fromEntries(t):t))}const l=Symbol.for("@@mdb.bson.version"),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=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 7.x.x")}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}class BSONOffsetError extends BSONError{get name(){return"BSONOffsetError"}offset;constructor(e,t,r){super(`${e}. offset: ${t}`,r),this.offset=t}}let y,m;function w(e,t,r,n){if(n){y??=new TextDecoder("utf8",{fatal:!0});try{return y.decode(e.subarray(t,r))}catch(e){throw new BSONError("Invalid UTF-8 string in BSON document",{cause:e})}}return m??=new TextDecoder("utf8",{fatal:!1}),m.decode(e.subarray(t,r))}function B(e,t,r){if(0===e.length)return"";const n=r-t;if(0===n)return"";if(n>20)return null;if(1===n&&e[t]<128)return String.fromCharCode(e[t]);if(2===n&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(3===n&&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 n=t;n<r;n++){const t=e[n];if(t>127)return null;o.push(t)}return String.fromCharCode(...o)}function O(e){return N.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}function S(e){return crypto.getRandomValues(N.allocate(e))}const E=(()=>{const{crypto:e}=globalThis;return null!=e&&"function"==typeof e.getRandomValues?S:O})(),N={isUint8Array:n,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 the passed potentialBuffer.")},allocate:e=>Buffer.alloc(e),allocateUnsafe:e=>Buffer.allocUnsafe(e),compare:(e,t)=>N.toLocalBufferType(e).compare(t),concat:e=>Buffer.concat(e),copy:(e,t,r,n,o)=>N.toLocalBufferType(e).copy(t,r??0,n??0,o??e.length),equals:(e,t)=>N.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),fromUTF8:e=>Buffer.from(e,"utf8"),toBase64:e=>N.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>N.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>N.toLocalBufferType(e).toString("hex"),toUTF8(e,t,r,n){const o=r-t<=20?B(e,t,r):null;if(null!=o)return o;const i=N.toLocalBufferType(e).toString("utf8",t,r);if(n)for(let n=0;n<i.length;n++)if(65533===i.charCodeAt(n)){w(e,t,r,!0);break}return i},utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into(e,t,r){const n=function(e,t,r){if(0===t.length)return 0;if(t.length>25)return null;if(e.length-r<t.length)return null;for(let n=0,o=r;n<t.length;n++,o++){const r=t.charCodeAt(n);if(r>127)return null;e[o]=r}return t.length}(e,t,r);return null!=n?n:N.toLocalBufferType(e).write(t,r,void 0,"utf8")},randomBytes:E,swap32:e=>N.toLocalBufferType(e).swap32()};function L(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return I.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const v=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(I.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 L})(),x=/(\d|[a-f])/i,I={isUint8Array:n,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 passed potentialBuffer.")},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=>I.allocate(e),compare(e,t){if(e===t)return 0;const r=Math.min(e.length,t.length);for(let n=0;n<r;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.length<t.length?-1:e.length>t.length?1:0},concat(e){if(0===e.length)return I.allocate(0);let t=0;for(const r of e)t+=r.length;const r=I.allocate(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r},copy(e,t,r,n,o){if(void 0!==o&&o<0)throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${o}`);if(o=o??e.length,void 0!==n&&(n<0||n>o))throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${o}. Received ${n}`);if(n=n??0,void 0!==r&&r<0)throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${r}`);r=r??0;const i=e.subarray(n,o),s=Math.min(i.length,t.length-r);return s<=0?0:(t.set(i.subarray(0,s),r),s)},equals(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},fromNumberArray:e=>Uint8Array.from(e),fromBase64:e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))),fromUTF8:e=>(new TextEncoder).encode(e),toBase64:e=>btoa(I.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),r=[];for(let e=0;e<t.length;e+=2){const n=t[e],o=t[e+1];if(!x.test(n))break;if(!x.test(o))break;const i=Number.parseInt(`${n}${o}`,16);r.push(i)}return Uint8Array.from(r)},toHex:e=>Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join(""),toUTF8(e,t,r,n){const o=r-t<=20?B(e,t,r):null;return null!=o?o:w(e,t,r,n)},utf8ByteLength:e=>(new TextEncoder).encode(e).byteLength,encodeUTF8Into(e,t,r){const n=(new TextEncoder).encode(t);return e.set(n,r),n.byteLength},randomBytes:v,swap32(e){if(e.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2],i=e[t+3];e[t]=i,e[t+1]=o,e[t+2]=n,e[t+3]=r}return e}},_="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?N:I,U=Symbol.for("@@mdb.bson.type");class BSONValue{get[U](){return this._bsontype}get[l](){return 7}[Symbol.for("nodejs.util.inspect.custom")](e,t,r){return this.inspect(e,t,r)}}const T=new Float64Array(1),$=new Uint8Array(T.buffer,0,8);T[0]=-1;const R=0===$[7],j={isBigEndian:R,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)=>(BigInt(e[t+4]+256*e[t+5]+65536*e[t+6]+(e[t+7]<<24))<<32n)+BigInt(e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3]),getFloat64LE:R?(e,t)=>($[7]=e[t],$[6]=e[t+1],$[5]=e[t+2],$[4]=e[t+3],$[3]=e[t+4],$[2]=e[t+5],$[1]=e[t+6],$[0]=e[t+7],T[0]):(e,t)=>($[0]=e[t],$[1]=e[t+1],$[2]=e[t+2],$[3]=e[t+3],$[4]=e[t+4],$[5]=e[t+5],$[6]=e[t+6],$[7]=e[t+7],T[0]),setInt32BE:(e,t,r)=>(e[t+3]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t]=r,4),setInt32LE:(e,t,r)=>(e[t]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+3]=r,4),setBigInt64LE(e,t,r){const n=0xffffffffn;let o=Number(r&n);e[t]=o,o>>=8,e[t+1]=o,o>>=8,e[t+2]=o,o>>=8,e[t+3]=o;let i=Number(r>>32n&n);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:R?(e,t,r)=>(T[0]=r,e[t]=$[7],e[t+1]=$[6],e[t+2]=$[5],e[t+3]=$[4],e[t+4]=$[3],e[t+5]=$[2],e[t+6]=$[1],e[t+7]=$[0],8):(e,t,r)=>(T[0]=r,e[t]=$[0],e[t+1]=$[1],e[t+2]=$[2],e[t+3]=$[3],e[t+4]=$[4],e[t+5]=$[5],e[t+6]=$[6],e[t+7]=$[7],8)};class Binary extends BSONValue{get _bsontype(){return"Binary"}static BSON_BINARY_SUBTYPE_DEFAULT=0;static BUFFER_SIZE=256;static SUBTYPE_DEFAULT=0;static SUBTYPE_FUNCTION=1;static SUBTYPE_BYTE_ARRAY=2;static SUBTYPE_UUID_OLD=3;static SUBTYPE_UUID=4;static SUBTYPE_MD5=5;static SUBTYPE_ENCRYPTED=6;static SUBTYPE_COLUMN=7;static SUBTYPE_SENSITIVE=8;static SUBTYPE_VECTOR=9;static SUBTYPE_USER_DEFINED=128;static VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});buffer;sub_type;position;constructor(e,t){if(super(),null!=e&&"string"==typeof e&&!ArrayBuffer.isView(e)&&!o(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=_.allocate(Binary.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(e)?_.fromNumberArray(e):_.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=_.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=_.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(_.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){const r=e+(t=t&&t>0?t:this.position);return this.buffer.subarray(e,r>this.position?this.position:r)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return _.toBase64(this.buffer.subarray(0,this.position))}toString(e){return"hex"===e?_.toHex(this.buffer.subarray(0,this.position)):"base64"===e?_.toBase64(this.buffer.subarray(0,this.position)):_.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(e){e=e||{},this.sub_type===Binary.SUBTYPE_VECTOR&&A(this);const t=_.toBase64(this.buffer),r=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:1===r.length?"0"+r:r}:{$binary:{base64:t,subType:1===r.length?"0"+r:r}}}toUUID(){if(this.sub_type===Binary.SUBTYPE_UUID)return new UUID(this.buffer.subarray(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(_.fromHex(e),t)}static createFromBase64(e,t){return new Binary(_.fromBase64(e),t)}static fromExtendedJSON(e,t){let r,n;if(t=t||{},"$binary"in e?t.legacy&&"string"==typeof e.$binary&&"$type"in e?(n=e.$type?parseInt(e.$type,16):0,r=_.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(n=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=_.fromBase64(e.$binary.base64)):"$uuid"in e&&(n=4,r=UUID.bytesFromString(e.$uuid)),!r)throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return 4===n?new UUID(r):new Binary(r,n)}inspect(e,t,r){return r??=u,`Binary.createFromBase64(${r(_.toBase64(this.buffer.subarray(0,this.position)),t)}, ${r(this.sub_type,t)})`}toInt8Array(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.Int8)throw new BSONError("Binary datatype field is not Int8");return A(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.Float32)throw new BSONError("Binary datatype field is not Float32");A(this);const e=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return j.isBigEndian&&_.swap32(e),new Float32Array(e.buffer)}toPackedBits(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.PackedBit)throw new BSONError("Binary datatype field is not packed bit");return A(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.PackedBit)throw new BSONError("Binary datatype field is not packed bit");A(this);const e=8*(this.length()-2)-this.buffer[1],t=new Int8Array(e);for(let e=0;e<t.length;e++){const r=e/8|0,n=this.buffer[r+2]>>7-e%8&1;t[e]=n}return t}static fromInt8Array(e){const t=_.allocate(e.byteLength+2);t[0]=Binary.VECTOR_TYPE.Int8,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);t.set(r,2);const n=new this(t,this.SUBTYPE_VECTOR);return A(n),n}static fromFloat32Array(e){const t=_.allocate(e.byteLength+2);t[0]=Binary.VECTOR_TYPE.Float32,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);t.set(r,2),j.isBigEndian&&_.swap32(new Uint8Array(t.buffer,2));const n=new this(t,this.SUBTYPE_VECTOR);return A(n),n}static fromPackedBits(e,t=0){const r=_.allocate(e.byteLength+2);r[0]=Binary.VECTOR_TYPE.PackedBit,r[1]=t,r.set(e,2);const n=new this(r,this.SUBTYPE_VECTOR);return A(n),n}static fromBits(e){const t=e.length+7>>>3,r=new Uint8Array(t+2);r[0]=Binary.VECTOR_TYPE.PackedBit;const n=e.length%8;r[1]=0===n?0:8-n;for(let t=0;t<e.length;t++){const n=t>>>3,o=e[t];if(0!==o&&1!==o)throw new BSONError(`Invalid bit value at ${t}: must be 0 or 1, found ${e[t]}`);if(0===o)continue;const i=7-t%8;r[n+2]|=o<<i}return new this(r,Binary.SUBTYPE_VECTOR)}}function A(e){if(e.sub_type!==Binary.SUBTYPE_VECTOR)return;const t=e.position,r=e.buffer[0],n=e.buffer[1];if((r===Binary.VECTOR_TYPE.Float32||r===Binary.VECTOR_TYPE.Int8)&&0!==n)throw new BSONError("Invalid Vector: padding must be zero for int8 and float32 vectors");if(r===Binary.VECTOR_TYPE.Float32&&0!==t&&t-2!=0&&(t-2)%4!=0)throw new BSONError("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(r===Binary.VECTOR_TYPE.PackedBit&&0!==n&&2===t)throw new BSONError("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(r===Binary.VECTOR_TYPE.PackedBit&&n>7)throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${n}`)}const D=/^[0-9A-F]{32}$/i,P=/^[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=_.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=_.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,4)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[_.toHex(this.buffer.subarray(0,4)),_.toHex(this.buffer.subarray(4,6)),_.toHex(this.buffer.subarray(6,8)),_.toHex(this.buffer.subarray(8,10)),_.toHex(this.buffer.subarray(10,16))].join("-"):_.toHex(this.buffer)}toString(e){return"hex"===e?_.toHex(this.id):"base64"===e?_.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return _.equals(e.id,this.id);try{return _.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=_.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):n(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(_.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 _.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return D.test(e)||P.test(e)}inspect(e,t,r){return r??=u,`new UUID(${r(this.toHexString(),t)})`}}class Code extends BSONValue{get _bsontype(){return"Code"}code;scope;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,r){r??=u;let n=r(this.code,t);const o=n.includes("\n");return null!=this.scope&&(n+=`,${o?"\n":" "}${r(this.scope,t)}`),`new Code(${o?"\n":""}${n}${o&&null===this.scope?"\n":""})`}}function M(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"}collection;oid;db;fields;constructor(e,t,r,n){super();const o=e.split(".");2===o.length&&(r=o.shift(),e=o.shift()),this.collection=e,this.oid=t,this.db=r,this.fields=n||{}}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,r){r??=u;const n=[r(this.namespace,t),r(this.oid,t),...this.db?[r(this.db,t)]:[],...Object.keys(this.fields).length>0?[r(this.fields,t)]:[]];return n[1]=r===u?`new ObjectId(${n[1]})`:n[1],`new DBRef(${n.join(", ")})`}}function V(e){if(""===e)return e;let t=0;const r="-"===e[t],n="+"===e[t];(n||r)&&(t+=1);let o=!1;for(;t<e.length&&"0"===e[t];++t)o=!0;return o?`${r?"-":""}${e.length===t?"0":e.slice(t)}`:n?e.slice(1):e}let C;try{C=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 F=4294967296,k=0x10000000000000000,z=k/2,J={},Y={},q=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}high;low;unsigned;constructor(e=0,t,r){super();const n="boolean"==typeof t?t:Boolean(r),o="number"==typeof t?t:0,i="string"==typeof e?Long.fromString(e,n):"bigint"==typeof e?Long.fromBigInt(e,n):{low:0|e,high:0|o,unsigned:n};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static TWO_PWR_24=Long.fromInt(16777216);static MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0);static ZERO=Long.fromInt(0);static UZERO=Long.fromInt(0,!0);static ONE=Long.fromInt(1);static UONE=Long.fromInt(1,!0);static NEG_ONE=Long.fromInt(-1);static MAX_VALUE=Long.fromBits(-1,2147483647,!1);static MIN_VALUE=Long.fromBits(0,-2147483648,!1);static fromBits(e,t,r){return new Long(e,t,r)}static fromInt(e,t){let r,n,o;return t?(o=0<=(e>>>=0)&&e<256)&&(n=Y[e],n)?n:(r=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(Y[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=J[e],n)?n:(r=Long.fromBits(e,e<0?-1:0,!1),o&&(J[e]=r),r)}static fromNumber(e,t){if(isNaN(e))return t?Long.UZERO:Long.ZERO;if(t){if(e<0)return Long.UZERO;if(e>=k)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-z)return Long.MIN_VALUE;if(e+1>=z)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%F|0,e/F|0,t)}static fromBigInt(e,t){const r=0xffffffffn;return new Long(Number(e&r),Number(e>>32n&r),t)}static _fromString(e,t,r){if(0===e.length)throw new BSONError("empty string");if(r<2||36<r)throw new BSONError("radix");let n;if((n=e.indexOf("-"))>0)throw new BSONError("interior hyphen");if(0===n)return Long._fromString(e.substring(1),t,r).neg();const o=Long.fromNumber(Math.pow(r,8));let i=Long.ZERO;for(let t=0;t<e.length;t+=8){const n=Math.min(8,e.length-t),s=parseInt(e.substring(t,t+n),r);if(n<8){const e=Long.fromNumber(Math.pow(r,n));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,r){let n=!1;if("number"==typeof t?(r=t,t=!1):n=!!t,r??=10,e.trim()!==e)throw new BSONError(`Input: '${e}' contains leading and/or trailing whitespace`);if(!function(e,t){t=t??10;const r="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,t);return!new RegExp(`[^-+${r}]`,"i").test(e)&&e}(e,r))throw new BSONError(`Input: '${e}' contains invalid characters for radix: ${r}`);const o=V(e),i=Long._fromString(o,n,r);if(i.toString(r).toLowerCase()!==o.toLowerCase())throw new BSONError(`Input: ${e} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=r?`with radix: ${r}`:""}`);return i}static fromString(e,t,r){let n=!1;return"number"==typeof t?(r=t,t=!1):n=!!t,r??=10,"NaN"===e&&r<24||("Infinity"===e||"+Infinity"===e||"-Infinity"===e)&&r<35?Long.ZERO:Long._fromString(e,n,r)}static fromBytes(e,t,r){return r?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,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16;let u=0,l=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=n+a,l+=f>>>16,f&=65535,l+=r+s,u+=l>>>16,l&=65535,u+=t+i,u&=65535,Long.fromBits(f<<16|c,u<<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(),r=e.isNegative();return t&&!r?-1:!t&&r?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(C){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?C.div_u:C.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Long.UZERO:Long.ZERO;let t,r,n;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return Long.UZERO;if(e.gt(this.shru(1)))return Long.UONE;n=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:(r=this.sub(e.mul(t)),n=t.add(r.div(e)),n));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();n=Long.ZERO}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.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),a=s.mul(e);for(;a.isNegative()||a.gt(r);)t-=i,s=Long.fromNumber(t,this.unsigned),a=s.mul(e);s.isZero()&&(s=Long.ONE),n=n.add(s),r=r.sub(a)}return n}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&&!(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!(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return!(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)),C){const t=(this.unsigned?C.rem_u:C.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.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)),C){const t=C.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.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,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,u=65535&e.low;let l=0,f=0,c=0,h=0;return h+=o*u,c+=h>>>16,h&=65535,c+=n*u,f+=c>>>16,c&=65535,c+=o*a,f+=c>>>16,c&=65535,f+=r*u,l+=f>>>16,f&=65535,f+=n*a,l+=f>>>16,f&=65535,f+=o*s,l+=f>>>16,f&=65535,l+=t*u+r*a+n*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 r=this.low;return Long.fromBits(r>>>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)*F+(this.low>>>0):this.high*F+(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),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}const t=Long.fromNumber(Math.pow(e,6),this.unsigned);let r=this,n="";for(;;){const o=r.div(t);let i=(r.sub(o.mul(t)).toInt()>>>0).toString(e);if(r=o,r.isZero())return i+n;for(;i.length<6;)i="0"+i;n=""+i+n}}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:r=!1,relaxed:n=!0}={...t};if(e.$numberLong.length>20)throw new BSONError("$numberLong string is too long");if(!q.test(e.$numberLong))throw new BSONError(`$numberLong string "${e.$numberLong}" is in an invalid format`);if(r){const t=BigInt(e.$numberLong);return BigInt.asIntN(64,t)}const o=Long.fromString(e.$numberLong);return n?o.toNumber():o}inspect(e,t,r){return r??=u,`new Long(${r(this.toString(),t)}${this.unsigned?`, ${r(this.unsigned,t)}`:""})`}}const H=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,K=/^(\+|-)?(Infinity|inf)$/i,W=/^(\+|-)?NaN$/i,Z=6111,G=-6176,X=_.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Q=_.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ee=_.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),te=/^([-+])?(\d+)?$/;function re(e){return!isNaN(parseInt(e,10))}function ne(e){const t=Long.fromNumber(1e9);let r=Long.fromNumber(0);if(!(e.parts[0]||e.parts[1]||e.parts[2]||e.parts[3]))return{quotient:e,rem:r};for(let n=0;n<=3;n++)r=r.shiftLeft(32),r=r.add(new Long(e.parts[n],0)),e.parts[n]=r.div(t).low,r=r.modulo(t);return{quotient:e,rem:r}}function oe(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}bytes;constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!(e instanceof Uint8Array||n(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 r=!1,n=!1,o=!1,i=!1,s=0,a=0,u=0,l=0,f=0;const c=[0];let h=0,g=0,d=0,p=0,b=new Long(0,0),y=new Long(0,0),m=0,w=0;if(e.length>=7e3)throw new BSONError(e+" not a valid Decimal128 string");const B=e.match(H),O=e.match(K),S=e.match(W);if(!B&&!O&&!S||0===e.length)throw new BSONError(e+" not a valid Decimal128 string");if(B){const t=B[2],r=B[4],n=B[5],o=B[6];r&&void 0===o&&oe(e,"missing exponent power"),r&&void 0===t&&oe(e,"missing exponent base"),void 0===r&&(n||o)&&oe(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(n=!0,r="-"===e[w++]),!re(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(r?Q:ee);if("N"===e[w])return new Decimal128(X)}for(;re(e[w])||"."===e[w];)"."!==e[w]?(h<34&&("0"!==e[w]||i)&&(i||(f=a),i=!0,c[g++]=parseInt(e[w],10),h+=1),i&&(u+=1),o&&(l+=1),a+=1,w+=1):(o&&oe(e,"contains multiple periods"),o=!0,w+=1);if(o&&!a)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(te);if(!t||!t[2])return new Decimal128(X);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(X);if(h){if(d=h-1,s=u,1!==s)for(;"0"===e[f+s-1+Number(n)+Number(o)];)s-=1}else c[0]=0,u=1,h=1,s=0;for(p<=l&&l>p+16384?p=G:p-=l;p>Z;){if(d+=1,d>=34){if(0===s){p=Z;break}oe(e,"overflow")}p-=1}if(t.allowRounding){for(;p<G||h<u;){if(0===d&&s<h){p=G,s=0;break}if(h<u?u-=1:d-=1,p<Z)p+=1;else{if(c.join("").match(/^0+$/)){p=Z;break}oe(e,"overflow")}}if(d+1<s){let t=a;o&&(f+=1,t+=1),n&&(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 r=f+d+2;r<t;r++)if(parseInt(e[r],10)){s=1;break}}if(s){let e=d;for(;e>=0&&++c[e]>9;e--)if(c[e]=0,0===e){if(!(p<Z))return new Decimal128(r?Q:ee);p+=1,c[e]=1}}}}else{for(;p<G||h<u;){if(0===d){if(0===s){p=G;break}oe(e,"exponent underflow")}h<u?("0"!==e[u-1+Number(n)+Number(o)]&&0!==s&&oe(e,"inexact rounding"),u-=1):(0!==c[d]&&oe(e,"inexact rounding"),d-=1),p<Z?p+=1:oe(e,"overflow")}d+1<s&&(o&&(f+=1),n&&(f+=1),0!==parseInt(e[f+d+1],10)&&oe(e,"inexact rounding"))}if(b=Long.fromNumber(0),y=Long.fromNumber(0),0===s)b=Long.fromNumber(0),y=Long.fromNumber(0);else if(d<17){let e=0;for(y=Long.fromNumber(c[e++]),b=new Long(0,0);e<=d;e++)y=y.multiply(Long.fromNumber(10)),y=y.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(y=Long.fromNumber(c[e++]);e<=d;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(c[e]))}const E=function(e,t){if(!e&&!t)return{high:Long.fromNumber(0),low:Long.fromNumber(0)};const r=e.shiftRightUnsigned(32),n=new Long(e.getLowBits(),0),o=t.shiftRightUnsigned(32),i=new Long(t.getLowBits(),0);let s=r.multiply(o),a=r.multiply(i);const u=n.multiply(o);let l=n.multiply(i);return s=s.add(a.shiftRightUnsigned(32)),a=new Long(a.getLowBits(),0).add(u).add(l.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),l=a.shiftLeft(32).add(new Long(l.getLowBits(),0)),{high:s,low:l}}(b,Long.fromString("100000000000000000"));E.low=E.low.add(y),function(e,t){const r=e.high>>>0,n=t.high>>>0;return r<n||r===n&&e.low>>>0<t.low>>>0}(E.low,y)&&(E.high=E.high.add(Long.fromNumber(1))),m=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(m).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&m).shiftLeft(49)),N.high=N.high.or(E.high.and(Long.fromNumber(562949953421311)))),N.low=E.low,r&&(N.high=N.high.or(Long.fromString("9223372036854775808")));const L=_.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 r=new Array(36);for(let e=0;e<r.length;e++)r[e]=0;let n,o,i,s=0,a=!1,u={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,n=8+(d>>14&1)}else n=d>>14&7,e=d>>17&16383;const b=e-6176;if(u.parts[0]=(16383&d)+((15&n)<<14),u.parts[1]=g,u.parts[2]=h,u.parts[3]=c,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])a=!0;else for(i=3;i>=0;i--){let e=0;const t=ne(u);if(u=t.quotient,e=t.rem.low,e)for(o=8;o>=0;o--)r[9*i+o]=e%10,e=Math.floor(e/10)}if(a)t=1,r[s]=0;else for(t=36;!r[s];)t-=1,s+=1;const y=t-1+b;if(y>=34||y<=-7||b>0){if(t>34)return l.push("0"),b>0?l.push(`E+${b}`):b<0&&l.push(`E${b}`),l.join("");l.push(`${r[s++]}`),t-=1,t&&l.push(".");for(let e=0;e<t;e++)l.push(`${r[s++]}`);l.push("E"),y>0?l.push(`+${y}`):l.push(`${y}`)}else if(b>=0)for(let e=0;e<t;e++)l.push(`${r[s++]}`);else{let e=t+b;if(e>0)for(let t=0;t<e;t++)l.push(`${r[s++]}`);else l.push("0");for(l.push(".");e++<0;)l.push("0");for(let n=0;n<t-Math.max(e-1,0);n++)l.push(`${r[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,r){return r??=u,`new Decimal128(${r(this.toString(),t)})`}}class Double extends BSONValue{get _bsontype(){return"Double"}value;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 r=parseFloat(e.$numberDouble);return t&&t.relaxed?r:new Double(r)}inspect(e,t,r){return r??=u,`new Double(${r(this.value,t)})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}value;constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}static fromString(e){const t=V(e),r=Number(e);if(f<r)throw new BSONError(`Input: '${e}' is larger than the maximum value for Int32`);if(c>r)throw new BSONError(`Input: '${e}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(r))throw new BSONError(`Input: '${e}' is not a safe integer`);if(r.toString()!==t)throw new BSONError(`Input: '${e}' is not a valid Int32 string`);return new Int32(r)}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,r){return r??=u,`new Int32(${r(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()"}}let ie=null;const se=new WeakMap;class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}static index=Math.floor(16777215*Math.random());static cacheHexString;buffer;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?_.fromHex(e.toHexString()):e.id}else t=e;if(null==t)this.buffer=ObjectId.generate();else if(ArrayBuffer.isView(t)&&12===t.byteLength)this.buffer=_.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(!ObjectId.validateHexString(t))throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=_.fromHex(t),ObjectId.cacheHexString&&se.set(this,t)}}get id(){return this.buffer}set id(e){this.buffer=e,ObjectId.cacheHexString&&se.set(this,_.toHex(e))}static validateHexString(e){if(24!==e?.length)return!1;for(let t=0;t<24;t++){const r=e.charCodeAt(t);if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return!0}toHexString(){if(ObjectId.cacheHexString){const e=se.get(this);if(e)return e}const e=_.toHex(this.id);return ObjectId.cacheHexString&&se.set(this,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(),r=_.allocateUnsafe(12);return j.setInt32BE(r,0,e),null===ie&&(ie=_.randomBytes(5)),r[4]=ie[0],r[5]=ie[1],r[6]=ie[2],r[7]=ie[3],r[8]=ie[4],r[11]=255&t,r[10]=t>>8&255,r[9]=t>>16&255,r}toString(e){return"base64"===e?_.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]&&_.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(),r=this.toHexString();return"string"==typeof t&&t.toLowerCase()===r}return!1}getTimestamp(){const e=new Date,t=j.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=_.allocate(12);for(let e=11;e>=4;e--)t[e]=0;return j.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(_.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(_.fromBase64(e))}static isValid(e){if(null==e)return!1;if("string"==typeof e)return ObjectId.validateHexString(e);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)}isCached(){return ObjectId.cacheHexString&&se.has(this)}inspect(e,t,r){return r??=u,`new ObjectId(${r(this.toHexString(),t)})`}}function ae(e,t,r){let n=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)n+=ue(o.toString(),e[o],t,!0,r);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))n+=ue(o,e[o],t,!1,r)}return n}function ue(e,t,r=!1,n=!1,s=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+_.utf8ByteLength(e)+1+4+_.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=p&&t<=d&&t>=c&&t<=f?(null!=e?_.utf8ByteLength(e)+1:0)+5:(null!=e?_.utf8ByteLength(e)+1:0)+9;case"undefined":return n||!s?(null!=e?_.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?_.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&7!==t[l])throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||a(t))return(null!=e?_.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||o(t))return(null!=e?_.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?_.utf8ByteLength(e)+1:0)+1+4+4+_.utf8ByteLength(t.code.toString())+1+ae(t.scope,r,s):(null!=e?_.utf8ByteLength(e)+1:0)+1+4+_.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const r=t;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?_.utf8ByteLength(e)+1:0)+(r.position+1+4+1+4):(null!=e?_.utf8ByteLength(e)+1:0)+(r.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+_.utf8ByteLength(t.value)+4+1+1;if("DBRef"===t._bsontype){const n=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(n.$db=t.db),(null!=e?_.utf8ByteLength(e)+1:0)+1+ae(n,r,s)}return t instanceof RegExp||i(t)?(null!=e?_.utf8ByteLength(e)+1:0)+1+_.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?_.utf8ByteLength(e)+1:0)+1+_.utf8ByteLength(t.pattern)+1+_.utf8ByteLength(t.options)+1:(null!=e?_.utf8ByteLength(e)+1:0)+ae(t,r,s)+1;case"function":return r?(null!=e?_.utf8ByteLength(e)+1:0)+1+4+_.utf8ByteLength(t.toString())+1:0;case"bigint":return(null!=e?_.utf8ByteLength(e)+1:0)+9;case"symbol":return 0;default:throw new BSONError("Unrecognized JS type: "+typeof t)}}class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}pattern;options;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,r){const n=function(e){if(null!=e&&"object"==typeof e&&"stylize"in e&&"function"==typeof e.stylize)return e.stylize}(t)??(e=>e);return r??=u,`new BSONRegExp(${n(r(this.pattern),"regexp")}, ${n(r(this.options),"regexp")})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}value;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,r){return r??=u,`new BSONSymbol(${r(this.value,t)})`}}const le=Long;class Timestamp extends le{get _bsontype(){return"Timestamp"}get[U](){return"Timestamp"}static MAX_VALUE=Long.MAX_UNSIGNED_VALUE;get i(){return this.low>>>0}get t(){return this.high>>>0}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),r=Number(e.i);if(t<0||Number.isNaN(t))throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(r<0||Number.isNaN(r))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(r>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(r,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.t,i:this.i}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,r=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:r,i:t})}inspect(e,t,r){return r??=u,`new Timestamp({ t: ${r(this.t,t)}, i: ${r(this.i,t)} })`}}const fe=Long.fromNumber(d),ce=Long.fromNumber(p);function he(e,t,r){const n=(t=null==t?{}:t)&&t.index?t.index:0,o=j.getInt32LE(e,n);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+n>e.byteLength)throw new BSONError(`(bson size ${o} + options.index ${n} must be <= buffer length ${e.byteLength})`);if(0!==e[n+o-1])throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return de(e,n,t,r)}const ge=/^\$ref$|^\$id$|^\$db$/;function de(e,t,r,n=!1){const o=null==r.fieldsAsRaw?null:r.fieldsAsRaw,i=null!=r.raw&&r.raw,s="boolean"==typeof r.bsonRegExp&&r.bsonRegExp,a=r.promoteBuffers??!1,u=r.promoteLongs??!0,l=r.promoteValues??!0,f=r.useBigInt64??!1;if(f&&!l)throw new BSONError("Must either request bigint or Long for int64 deserialization");if(f&&!u)throw new BSONError("Must either request bigint or Long for int64 deserialization");let c,h,g=!0;const d=(null==r.validation?{utf8:!0}:r.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 b=j.getInt32LE(e,t);if(t+=4,b<5||b>e.length)throw new BSONError("corrupt bson message");const y=n?[]:{};let m=0,w=!n&&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 b=n?m++:_.toUTF8(e,t,p,!1);let B,O=!0;if(O=g||h?.has(b)?c:!c,!1!==w&&"$"===b[0]&&(w=ge.test(b)),t=p+1,2===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");B=_.toUTF8(e,t,t+r-1,O),t+=r}else if(7===d){const r=_.allocateUnsafe(12);for(let n=0;n<12;n++)r[n]=e[t+n];B=new ObjectId(r),t+=12}else if(16===d&&!1===l)B=new Int32(j.getInt32LE(e,t)),t+=4;else if(16===d)B=j.getInt32LE(e,t),t+=4;else if(1===d)B=j.getFloat64LE(e,t),t+=8,!1===l&&(B=new Double(B));else if(9===d){const r=j.getInt32LE(e,t),n=j.getInt32LE(e,t+4);t+=8,B=new Date(new Long(r,n).toNumber())}else if(8===d){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");B=1===e[t++]}else if(3===d){const n=t,o=j.getInt32LE(e,t);if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)B=e.subarray(t,t+o);else{let t=r;g||(t={...r,validation:{utf8:O}}),B=de(e,n,t,!1)}t+=o}else if(4===d){const n=t,i=j.getInt32LE(e,t);let s=r;const a=t+i;if(o&&o[b]&&(s={...r,raw:!0}),g||(s={...s,validation:{utf8:O}}),B=de(e,n,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==a)throw new BSONError("corrupted array bson")}else if(6===d)B=void 0;else if(10===d)B=null;else if(18===d)if(f)B=j.getBigInt64LE(e,t),t+=8;else{const r=j.getInt32LE(e,t),n=j.getInt32LE(e,t+4);t+=8;const o=new Long(r,n);B=u&&!0===l&&o.lessThanOrEqual(fe)&&o.greaterThanOrEqual(ce)?o.toNumber():o}else if(19===d){const r=_.allocateUnsafe(16);for(let n=0;n<16;n++)r[n]=e[t+n];t+=16,B=new Decimal128(r)}else if(5===d){let r=j.getInt32LE(e,t);t+=4;const n=r,o=e[t++];if(r<0)throw new BSONError("Negative binary type element size found");if(r>e.byteLength)throw new BSONError("Binary type size larger than document size");if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=j.getInt32LE(e,t),t+=4,r<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(r>n-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(r<n-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}a&&l?B=_.toLocalBufferType(e.subarray(t,t+r)):(B=new Binary(e.subarray(t,t+r),o),4===o&&UUID.isValid(B)&&(B=B.toUUID())),t+=r}else if(11===d&&!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 r=_.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 n=_.toUTF8(e,t,p,!1);t=p+1;const o=new Array(n.length);for(p=0;p<n.length;p++)switch(n[p]){case"m":o[p]="m";break;case"s":o[p]="g";break;case"i":o[p]="i"}B=new RegExp(r,o.join(""))}else if(11===d&&!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 r=_.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 n=_.toUTF8(e,t,p,!1);t=p+1,B=new BSONRegExp(r,n)}else if(14===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);B=l?n:new BSONSymbol(n),t+=r}else if(17===d)B=new Timestamp({i:j.getUint32LE(e,t),t:j.getUint32LE(e,t+4)}),t+=8;else if(255===d)B=new MinKey;else if(127===d)B=new MaxKey;else if(13===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);B=new Code(n),t+=r}else if(15===d){const n=j.getInt32LE(e,t);if(t+=4,n<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=j.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=_.toUTF8(e,t,t+o-1,O),s=t+=o,a=j.getInt32LE(e,t),u=de(e,s,r,!1);if(t+=a,n<8+a+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(n>8+a+o)throw new BSONError("code_w_scope total size is too long, clips outer document");B=new Code(i,u)}else{if(12!==d)throw new BSONError(`Detected unknown BSON type ${d.toString(16)} for fieldname "${b}"`);{const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);t+=r;const o=_.allocateUnsafe(12);for(let r=0;r<12;r++)o[r]=e[t+r];const i=new ObjectId(o);t+=12,B=new DBRef(n,i)}}"__proto__"===b?Object.defineProperty(y,b,{value:B,writable:!0,enumerable:!0,configurable:!0}):y[b]=B}if(b!==t-p){if(n)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!w)return y;if(M(y)){const e=Object.assign({},y);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(y.$ref,y.$id,y.$db,e)}return y}const pe=/\x00/,be=new Set(["$db","$ref","$id","$clusterTime"]);function ye(e,t,r,n){e[n++]=2,e[(n=n+_.encodeUTF8Into(e,t,n)+1)-1]=0;const o=_.encodeUTF8Into(e,r,n+4);return j.setInt32LE(e,n,o+1),n=n+4+o,e[n++]=0,n}function me(e,t,r,n){const o=!Object.is(r,-0)&&Number.isSafeInteger(r)&&r<=f&&r>=c?16:1;return e[n++]=o,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=16===o?j.setInt32LE(e,n,r):j.setFloat64LE(e,n,r)}function we(e,t,r,n){return e[n++]=18,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setBigInt64LE(e,n,r)}function Be(e,t,r,n){return e[n++]=10,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n}function Oe(e,t,r,n){return e[n++]=8,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=r?1:0,n}function Se(e,t,r,n){e[n++]=9,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=Long.fromNumber(r.getTime()),i=o.getLowBits(),s=o.getHighBits();return n+=j.setInt32LE(e,n,i),n+=j.setInt32LE(e,n,s)}function Ee(e,t,r,n){if(e[n++]=11,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,r.source&&null!=r.source.match(pe))throw new BSONError("value "+r.source+" must not contain null bytes");return n+=_.encodeUTF8Into(e,r.source,n),e[n++]=0,r.ignoreCase&&(e[n++]=105),r.global&&(e[n++]=115),r.multiline&&(e[n++]=109),e[n++]=0,n}function Ne(e,t,r,n){if(e[n++]=11,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,null!=r.pattern.match(pe))throw new BSONError("pattern "+r.pattern+" must not contain null bytes");n+=_.encodeUTF8Into(e,r.pattern,n),e[n++]=0;const o=r.options.split("").sort().join("");return n+=_.encodeUTF8Into(e,o,n),e[n++]=0,n}function Le(e,t,r,n){return null===r?e[n++]=10:"MinKey"===r._bsontype?e[n++]=255:e[n++]=127,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n}function ve(e,t,r,n){return e[n++]=7,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=r.serializeInto(e,n)}function xe(e,t,r,n){e[n++]=5,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.length;if(n+=j.setInt32LE(e,n,o),e[n++]=0,o<=16)for(let t=0;t<o;t++)e[n+t]=r[t];else e.set(r,n);return n+=o}function Ie(e,t,r,n,o,i,s,a,u){if(u.has(r))throw new BSONError("Cannot convert circular structure to BSON");u.add(r),e[n++]=Array.isArray(r)?4:3,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const l=Me(e,r,o,n,i+1,s,a,u);return u.delete(r),l}function _e(e,t,r,n){e[n++]=19,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;for(let t=0;t<16;t++)e[n+t]=r.bytes[t];return n+16}function Ue(e,t,r,n){e[n++]="Long"===r._bsontype?18:17,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.getLowBits(),i=r.getHighBits();return n+=j.setInt32LE(e,n,o),n+=j.setInt32LE(e,n,i)}function Te(e,t,r,n){return r=r.valueOf(),e[n++]=16,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setInt32LE(e,n,r)}function $e(e,t,r,n){return e[n++]=1,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setFloat64LE(e,n,r.value)}function Re(e,t,r,n){e[n++]=13,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.toString(),i=_.encodeUTF8Into(e,o,n+4)+1;return j.setInt32LE(e,n,i),n=n+4+i-1,e[n++]=0,n}function je(e,t,r,n,o=!1,i=0,s=!1,a=!0,u){if(r.scope&&"object"==typeof r.scope){e[n++]=15,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;let l=n;const f=r.code;n+=4;const c=_.encodeUTF8Into(e,f,n+4)+1;j.setInt32LE(e,n,c),e[n+4+c-1]=0,n=n+c+4;const h=Me(e,r.scope,o,n,i+1,s,a,u);n=h-1;const g=h-l;l+=j.setInt32LE(e,l,g),e[n++]=0}else{e[n++]=13,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.code.toString(),i=_.encodeUTF8Into(e,o,n+4)+1;j.setInt32LE(e,n,i),n=n+4+i-1,e[n++]=0}return n}function Ae(e,t,r,n){e[n++]=5,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.buffer;let i=r.position;if(r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),n+=j.setInt32LE(e,n,i),e[n++]=r.sub_type,r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,n+=j.setInt32LE(e,n,i)),r.sub_type===Binary.SUBTYPE_VECTOR&&A(r),i<=16)for(let t=0;t<i;t++)e[n+t]=o[t];else e.set(o,n);return n+=r.position}function De(e,t,r,n){e[n++]=14,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=_.encodeUTF8Into(e,r.value,n+4)+1;return j.setInt32LE(e,n,o),n=n+4+o-1,e[n++]=0,n}function Pe(e,t,r,n,o,i,s){e[n++]=3,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;let a=n,u={$ref:r.collection||r.namespace,$id:r.oid};null!=r.db&&(u.$db=r.db),u=Object.assign(u,r.fields);const l=Me(e,u,!1,n,o+1,i,!0,s),f=l-a;return a+=j.setInt32LE(e,n,f),l}function Me(e,t,r,u,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(a(t)||i(t)||n(t)||o(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");g=new Set}g.add(t);let d=u+4;if(Array.isArray(t))for(let o=0;o<t.length;o++){const s=`${o}`;let u=t[o];"function"==typeof u?.toBSON&&(u=u.toBSON());const p=typeof u;if(void 0===u)d=Be(e,s,0,d);else if(null===u)d=Be(e,s,0,d);else if("string"===p)d=ye(e,s,u,d);else if("number"===p)d=me(e,s,u,d);else if("bigint"===p)d=we(e,s,u,d);else if("boolean"===p)d=Oe(e,s,u,d);else if("object"===p&&null==u._bsontype)d=u instanceof Date||a(u)?Se(e,s,u,d):u instanceof Uint8Array||n(u)?xe(e,s,u,d):u instanceof RegExp||i(u)?Ee(e,s,u,d):Ie(e,s,u,d,r,f,c,h,g);else if("object"===p){if(7!==u[l])throw new BSONVersionError;if("ObjectId"===u._bsontype)d=ve(e,s,u,d);else if("Decimal128"===u._bsontype)d=_e(e,s,u,d);else if("Long"===u._bsontype||"Timestamp"===u._bsontype)d=Ue(e,s,u,d);else if("Double"===u._bsontype)d=$e(e,s,u,d);else if("Code"===u._bsontype)d=je(e,s,u,d,r,f,c,h,g);else if("Binary"===u._bsontype)d=Ae(e,s,u,d);else if("BSONSymbol"===u._bsontype)d=De(e,s,u,d);else if("DBRef"===u._bsontype)d=Pe(e,s,u,d,f,c,g);else if("BSONRegExp"===u._bsontype)d=Ne(e,s,u,d);else if("Int32"===u._bsontype)d=Te(e,s,u,d);else if("MinKey"===u._bsontype||"MaxKey"===u._bsontype)d=Le(e,s,u,d);else if(void 0!==u._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(u._bsontype)}`)}else"function"===p&&c&&(d=Re(e,s,u,d))}else if(t instanceof Map||s(t)){const o=t.entries();let s=!1;for(;!s;){const t=o.next();if(s=!!t.done,s)continue;const u=t.value?t.value[0]:void 0;let p=t.value?t.value[1]:void 0;"function"==typeof p?.toBSON&&(p=p.toBSON());const b=typeof p;if("string"==typeof u&&!be.has(u)){if(null!=u.match(pe))throw new BSONError("key "+u+" must not contain null bytes");if(r){if("$"===u[0])throw new BSONError("key "+u+" must not start with '$'");if(u.includes("."))throw new BSONError("key "+u+" must not contain '.'")}}if(void 0===p)!1===h&&(d=Be(e,u,0,d));else if(null===p)d=Be(e,u,0,d);else if("string"===b)d=ye(e,u,p,d);else if("number"===b)d=me(e,u,p,d);else if("bigint"===b)d=we(e,u,p,d);else if("boolean"===b)d=Oe(e,u,p,d);else if("object"===b&&null==p._bsontype)d=p instanceof Date||a(p)?Se(e,u,p,d):p instanceof Uint8Array||n(p)?xe(e,u,p,d):p instanceof RegExp||i(p)?Ee(e,u,p,d):Ie(e,u,p,d,r,f,c,h,g);else if("object"===b){if(7!==p[l])throw new BSONVersionError;if("ObjectId"===p._bsontype)d=ve(e,u,p,d);else if("Decimal128"===p._bsontype)d=_e(e,u,p,d);else if("Long"===p._bsontype||"Timestamp"===p._bsontype)d=Ue(e,u,p,d);else if("Double"===p._bsontype)d=$e(e,u,p,d);else if("Code"===p._bsontype)d=je(e,u,p,d,r,f,c,h,g);else if("Binary"===p._bsontype)d=Ae(e,u,p,d);else if("BSONSymbol"===p._bsontype)d=De(e,u,p,d);else if("DBRef"===p._bsontype)d=Pe(e,u,p,d,f,c,g);else if("BSONRegExp"===p._bsontype)d=Ne(e,u,p,d);else if("Int32"===p._bsontype)d=Te(e,u,p,d);else if("MinKey"===p._bsontype||"MaxKey"===p._bsontype)d=Le(e,u,p,d);else if(void 0!==p._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(p._bsontype)}`)}else"function"===b&&c&&(d=Re(e,u,p,d))}}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 o of Object.keys(t)){let s=t[o];"function"==typeof s?.toBSON&&(s=s.toBSON());const u=typeof s;if("string"==typeof o&&!be.has(o)){if(null!=o.match(pe))throw new BSONError("key "+o+" must not contain null bytes");if(r){if("$"===o[0])throw new BSONError("key "+o+" must not start with '$'");if(o.includes("."))throw new BSONError("key "+o+" must not contain '.'")}}if(void 0===s)!1===h&&(d=Be(e,o,0,d));else if(null===s)d=Be(e,o,0,d);else if("string"===u)d=ye(e,o,s,d);else if("number"===u)d=me(e,o,s,d);else if("bigint"===u)d=we(e,o,s,d);else if("boolean"===u)d=Oe(e,o,s,d);else if("object"===u&&null==s._bsontype)d=s instanceof Date||a(s)?Se(e,o,s,d):s instanceof Uint8Array||n(s)?xe(e,o,s,d):s instanceof RegExp||i(s)?Ee(e,o,s,d):Ie(e,o,s,d,r,f,c,h,g);else if("object"===u){if(7!==s[l])throw new BSONVersionError;if("ObjectId"===s._bsontype)d=ve(e,o,s,d);else if("Decimal128"===s._bsontype)d=_e(e,o,s,d);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)d=Ue(e,o,s,d);else if("Double"===s._bsontype)d=$e(e,o,s,d);else if("Code"===s._bsontype)d=je(e,o,s,d,r,f,c,h,g);else if("Binary"===s._bsontype)d=Ae(e,o,s,d);else if("BSONSymbol"===s._bsontype)d=De(e,o,s,d);else if("DBRef"===s._bsontype)d=Pe(e,o,s,d,f,c,g);else if("BSONRegExp"===s._bsontype)d=Ne(e,o,s,d);else if("Int32"===s._bsontype)d=Te(e,o,s,d);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)d=Le(e,o,s,d);else if(void 0!==s._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}else"function"===u&&c&&(d=Re(e,o,s,d))}}g.delete(t),e[d++]=0;const p=d-u;return u+=j.setInt32LE(e,u,p),d}const Ve={$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 Ce(e,t={}){if("number"==typeof e){const r=e<=f&&e>=c,n=e<=h&&e>=g;if(t.relaxed||t.legacy)return e;if(Number.isInteger(e)&&!Object.is(e,-0)){if(r)return new Int32(e);if(n)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 r=Object.keys(e).filter((t=>t.startsWith("$")&&null!=e[t]));for(let n=0;n<r.length;n++){const o=Ve[r[n]];if(o)return o.fromExtendedJSON(e,t)}if(null!=e.$date){const r=e.$date,n=new Date;if(t.legacy)if("number"==typeof r)n.setTime(r);else if("string"==typeof r)n.setTime(Date.parse(r));else{if("bigint"!=typeof r)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof r);n.setTime(Number(r))}else if("string"==typeof r)n.setTime(Date.parse(r));else if(Long.isLong(r))n.setTime(r.toNumber());else if("number"==typeof r&&t.relaxed)n.setTime(r);else{if("bigint"!=typeof r)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof r);n.setTime(Number(r))}return n}if(null!=e.$code){const t=Object.assign({},e);return e.$scope&&(t.$scope=Ce(e.$scope)),Code.fromExtendedJSON(e)}if(M(e)||e.$dbPointer){const t=e.$ref?e:e.$dbPointer;if(t instanceof DBRef)return t;const r=Object.keys(t).filter((e=>e.startsWith("$")));let n=!0;if(r.forEach((e=>{-1===["$ref","$id","$db"].indexOf(e)&&(n=!1)})),n)return DBRef.fromExtendedJSON(t)}return e}function Fe(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function ke(e,t){if(e instanceof Map||s(e)){const r=Object.create(null);for(const[t,n]of e){if("string"!=typeof t)throw new BSONError("Can only serialize maps with string keys");r[t]=n}return ke(r,t)}if(("object"==typeof e||"function"==typeof e)&&null!==e){const r=t.seenObjects.findIndex((t=>t.obj===e));if(-1!==r){const e=t.seenObjects.map((e=>e.propertyName)),n=e.slice(0,r).map((e=>`${e} -> `)).join(""),o=e[r],i=" -> "+e.slice(r+1,e.length-1).map((e=>`${e} -> `)).join(""),s=e[e.length-1],a=" ".repeat(n.length+o.length/2),u="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${n}${o}${i}${s}\n ${a}\\${u}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,r)=>{t.seenObjects.push({propertyName:`index ${r}`,obj:null});try{return ke(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return t.ignoreUndefined?void 0:null;if(e instanceof Date||a(e)){const r=e.getTime(),n=r>-1&&r<2534023188e5;return t.legacy?t.relaxed&&n?{$date:e.getTime()}:{$date:Fe(e)}:t.relaxed&&n?{$date:Fe(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 r=e.flags;if(void 0===r){const t=e.toString().match(/[gimuy]*$/);t&&(r=t[0])}return new BSONRegExp(e.source,r).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 r=e._bsontype;if(void 0===r){const r={};for(const n of Object.keys(e)){t.seenObjects.push({propertyName:n,obj:null});try{const o=ke(e[n],t);"__proto__"===n?Object.defineProperty(r,n,{value:o,writable:!0,enumerable:!0,configurable:!0}):r[n]=o}finally{t.seenObjects.pop()}}return r}if(null!=e&&"object"==typeof e&&"string"==typeof e._bsontype&&7!==e[l])throw new BSONVersionError;if(function(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"string"==typeof e._bsontype}(e)){let n=e;if("function"!=typeof n.toExtendedJSON){const t=ze[e._bsontype];if(!t)throw new BSONError("Unrecognized or invalid _bsontype: "+e._bsontype);n=t(n)}return"Code"===r&&n.scope?n=new Code(n.code,ke(n.scope,t)):"DBRef"===r&&n.oid&&(n=new DBRef(ke(n.collection,t),ke(n.oid,t),ke(n.db,t),ke(n.fields,t))),n.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof r)}(e,t):e}const ze={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 Je(e,t){const r={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 Ce(t,r)}))}function Ye(e,t,r,n){null!=r&&"object"==typeof r&&(n=r,r=0),null==t||"object"!=typeof t||Array.isArray(t)||(n=t,t=void 0,r=0);const o=ke(e,Object.assign({relaxed:!0,legacy:!1},n,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,r)}const qe=Object.create(null);qe.parse=Je,qe.stringify=Ye,qe.serialize=function(e,t){return t=t||{},JSON.parse(Ye(e,t))},qe.deserialize=function(e,t){return t=t||{},Je(JSON.stringify(e),t)},Object.freeze(qe);const He=1,Ke=2,We=3,Ze=4,Ge=5,Xe=6,Qe=7,et=8,tt=9,rt=10,nt=11,ot=12,it=13,st=14,at=15,ut=16,lt=17,ft=18,ct=19,ht=255,gt=127;function dt(e,t){try{return j.getNonnegativeInt32LE(e,t)}catch(e){throw new BSONOffsetError("BSON size cannot be negative",t,{cause:e})}}function pt(e,t){let r=t;for(;0!==e[r];r++);if(r===e.length-1)throw new BSONOffsetError("Null terminator not found",t);return r}const bt=Object.create(null);bt.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 r=dt(e,t);if(r>e.length-t)throw new BSONOffsetError(`Parsed documentSize (${r} bytes) does not match input length (${e.length} bytes)`,t);if(0!==e[t+r-1])throw new BSONOffsetError("BSON documents must end in 0x00",t+r);const n=[];let o=t+4;for(;o<=r+t;){const i=e[o];if(o+=1,0===i){if(o-t!==r)throw new BSONOffsetError("Invalid 0x00 type byte",o);break}const s=o,a=pt(e,o)-s;let u;if(o+=a+1,i===He||i===ft||i===tt||i===lt)u=8;else if(i===ut)u=4;else if(i===Qe)u=12;else if(i===ct)u=16;else if(i===et)u=1;else if(i===rt||i===Xe||i===gt||i===ht)u=0;else if(i===nt)u=pt(e,pt(e,o)+1)+1-o;else if(i===We||i===Ze||i===at)u=dt(e,o);else{if(i!==Ke&&i!==Ge&&i!==ot&&i!==it&&i!==st)throw new BSONOffsetError(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);u=dt(e,o)+4,i===Ge&&(u+=1),i===ot&&(u+=12)}if(u>r)throw new BSONOffsetError("value reports length larger than document",o);n.push([i,s,a,o,u]),o+=u}return n},bt.ByteUtils=_,bt.NumberUtils=j,Object.freeze(bt);const yt=17825792;let mt=_.allocate(yt);function wt(e){mt.length<e&&(mt=_.allocate(e))}function Bt(e,t={}){const r="boolean"==typeof t.checkKeys&&t.checkKeys,n="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,o="boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined,i="number"==typeof t.minInternalBufferSize?t.minInternalBufferSize:yt;mt.length<i&&(mt=_.allocate(i));const s=Me(mt,e,r,0,0,n,o,null),a=_.allocateUnsafe(s);return a.set(mt.subarray(0,s),0),a}function Ot(e,t,r={}){const n="boolean"==typeof r.checkKeys&&r.checkKeys,o="boolean"==typeof r.serializeFunctions&&r.serializeFunctions,i="boolean"!=typeof r.ignoreUndefined||r.ignoreUndefined,s="number"==typeof r.index?r.index:0,a=Me(mt,e,n,0,0,o,i,null);return t.set(mt.subarray(0,a),s),s+a-1}function St(e,t={}){return he(_.toLocalBufferType(e),t)}function Et(e,t={}){return ae(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function Nt(e,t,r,n,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),a=_.toLocalBufferType(e);let u=t;for(let e=0;e<r;e++){const t=j.getInt32LE(a,u);s.index=u,n[o+e]=he(a,s),u+=t}return u}var Lt=Object.freeze({__proto__:null,BSONError,BSONOffsetError,BSONRegExp,BSONRuntimeError,BSONSymbol,BSONType:b,BSONValue,BSONVersionError,Binary,ByteUtils:_,Code,DBRef,Decimal128,Double,EJSON:qe,Int32,Long,MaxKey,MinKey,NumberUtils:j,ObjectId,Timestamp,UUID,bsonType:U,calculateObjectSize:Et,deserialize:St,deserializeStream:Nt,onDemand:bt,serialize:Bt,serializeWithBufferAndIndex:Ot,setInternalBufferSize:wt});t.BSON=Lt,t.BSONError=BSONError,t.BSONOffsetError=BSONOffsetError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=b,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.ByteUtils=_,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=qe,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.NumberUtils=j,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.bsonType=U,t.calculateObjectSize=Et,t.deserialize=St,t.deserializeStream=Nt,t.onDemand=bt,t.serialize=Bt,t.serializeWithBufferAndIndex=Ot,t.setInternalBufferSize=wt},795(e,t,r){let n,o,i=r(982),{urlAlphabet:s}=r(29),a=e=>{!n||n.length<e?(n=Buffer.allocUnsafe(128*e),i.randomFillSync(n),o=0):o+e>n.length&&(i.randomFillSync(n),o=0),o+=e},u=e=>(a(e|=0),n.subarray(o-e,o)),l=(e,t,r)=>{let n=(2<<31-Math.clz32(e.length-1|1))-1,o=Math.ceil(1.6*n*t/e.length);return(i=t)=>{let s="";for(;;){let t=r(o),a=o;for(;a--;)if(s+=e[t[a]&n]||"",s.length===i)return s}}};e.exports={nanoid:(e=21)=>{a(e|=0);let t="";for(let r=o-e;r<o;r++)t+=s[63&n[r]];return t},customAlphabet:(e,t=21)=>l(e,t,u),customRandom:l,urlAlphabet:s,random:u}},29(e){e.exports={urlAlphabet:"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"}}},t={},function r(n){var o=t[n];if(void 0!==o){if(void 0!==o.error)throw o.error;return o.exports}var i=t[n]={exports:{}},s=!0;try{e[n].call(i.exports,i,i.exports,r),s=!1}finally{s&&delete t[n]}return i.exports}(783);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 r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(global,(()=>{return e={796(e,t,r){"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 n,o=r(653),i=(n=o)&&n.__esModule?n:{default:n};function s(e,t){var r=(t=t||{}).addListener||window.addEventListener,n=t.removeListener||window.removeEventListener,o=t.postMessage||window.postMessage,s=t.targetOrigin||"*",a=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)},u=void 0,l=new Promise((function(i,l){var f=function r(){var o=a.apply(null,arguments);if(o&&"postmsg-rpc/server"===o.sender&&o.id===t.id){if(n("message",r),o.err){var s=new Error("Unexpected error calling "+e);return Object.assign(s,o.err),l(s)}i(o.res)}};u=function(){n("message",f);var t=new Error("Canceled call to "+e);t.isCanceled=!0,l(t)},r("message",f),o(t,s)}));return l.cancel=function(){return u()},l}}},59(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(796);Object.defineProperty(t,"caller",{enumerable:!0,get:function(){return i(n).default}}),Object.defineProperty(t,"call",{enumerable:!0,get:function(){return n.call}});var o=r(808);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},808(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(r=r||{}).addListener||window.addEventListener,o=r.removeListener||window.removeEventListener,i=r.postMessage||window.postMessage,s=r.targetOrigin||"*",a=r.getMessageData||function(e){return e.data},u=r.isCallback||!1,l=function(){var r=a.apply(null,arguments);if(r&&"postmsg-rpc/client"===r.sender&&r.func===e){var n={sender:"postmsg-rpc/server",id:r.id},o=function(e){n.res=e,i(n,s)},l=function(e){n.err=Object.assign({message:e.message},e.output&&e.output.payload),i(n,s)};if(u)t.apply(null,r.args.concat((function(e,t){if(e)return l(e);o(t)})));else{var f=t.apply(null,r.args);Promise.resolve(f).then(o).catch(l)}}};return n("message",l),{close:function(){return o("message",l)}}}},653(e,t,r){"use strict";e.exports=r(829)},534(e,t,r){"use strict";var n,o,i,s=r(189),a="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function u(){i=!1}function l(e){if(e){if(e!==n){if(64!==e.length)throw new Error("Custom alphabet for shortid must be 64 unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,r){return t!==r.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be 64 unique characters. These characters were not unique: "+t.join(", "));n=e,u()}}else n!==a&&(n=a,u())}function f(){return i||(i=function(){n||l(a);for(var e,t=n.split(""),r=[],o=s.nextValue();t.length>0;)o=s.nextValue(),e=Math.floor(o*t.length),r.push(t.splice(e,1)[0]);return r.join("")}())}e.exports={get:function(){return n||a},characters:function(e){return l(e),n},seed:function(e){s.seed(e),o!==e&&(u(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},137(e,t,r){"use strict";var n,o,i=r(938);r(534),e.exports=function(e){var t="",r=Math.floor(.001*(Date.now()-1567752802062));return r===o?n++:(n=0,o=r),t+=i(7),t+=i(e),n>0&&(t+=i(n)),t+=i(r)}},938(e,t,r){"use strict";var n=r(534),o=r(109),i=r(795).customRandom;e.exports=function(e){for(var t,r=0,s="";!t;)s+=i(n.get(),1,o)(),t=e<Math.pow(16,r+1),r++;return s}},829(e,t,r){"use strict";var n=r(534),o=r(137),i=r(906),s=r(741)||0;function a(){return o(s)}e.exports=a,e.exports.generate=a,e.exports.seed=function(t){return n.seed(t),e.exports},e.exports.worker=function(t){return s=t,e.exports},e.exports.characters=function(e){return void 0!==e&&n.characters(e),n.shuffled()},e.exports.isValid=i},906(e,t,r){"use strict";var n=r(534);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+n.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},109(e,t,r){var n=r(795).random;e.exports=n},189(e){"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},741(e,t,r){"use strict";var n=r(907),o=0;!n.isMaster&&n.worker&&(o=n.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},783(e,t,r){"use strict";var n=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(r(928)),i=r(434),s=r(16),a=r(280),u=r(495),l=r(196),f=r(286),c=r(852);t.WorkerRuntime=class WorkerRuntime{constructor(e,t,r={},n={},s=new i.EventEmitter){this.evaluationListener=null,this.workerProcessPath=o.default.resolve(__dirname,"worker-runtime.js"),this.initOptions={uri:e,driverOptions:t,cliOptions:r,workerOptions:n},this.eventEmitter=s,this.initWorkerPromise=this.initWorker()}async initWorker(){const e=new Worker((0,s.pathToFileURL)(this.workerProcessPath).href,this.initOptions.workerOptions);await(async()=>{await Promise.race([(async()=>{let t;for(;[t]=await(0,i.once)(e,"message");)if("ready"===(null==t?void 0:t.data))return})(),(async()=>{const[t]=await(0,i.once)(e,"error");if(t)throw t.message=`Worker thread failed to start with error: ${t.message}`,t})()])})();const{interrupt:t}=(0,a.createCaller)(["interrupt"],e);let r=null;this.workerProcessRuntime=Object.assign((0,a.createCaller)(["init","evaluate","getCompletions","getShellPrompt","setEvaluationListener","interrupt"],e),{interrupt:()=>r?((0,l.interrupt)(r),!0):t()}),this.workerThreadEvaluationListener=new f.WorkerThreadEvaluationListener(this,e),(0,a.exposeAll)({onRunInterruptible(e){r=e}},e),this.workerProcessMongoshBus=new c.WorkerProcessMongoshBus(this.eventEmitter,e),await this.workerProcessRuntime.init(this.initOptions.uri,(0,u.serializeConnectOptions)(this.initOptions.driverOptions),this.initOptions.cliOptions),this.workerProcess=e}async evaluate(e){return await this.initWorkerPromise,(0,u.deserializeEvaluationResult)(await this.workerProcessRuntime.evaluate(e))}async getCompletions(e){return await this.initWorkerPromise,await this.workerProcessRuntime.getCompletions(e)}async getShellPrompt(){return await this.initWorkerPromise,await this.workerProcessRuntime.getShellPrompt()}setEvaluationListener(e){const t=this.evaluationListener;return this.evaluationListener=e,t}async terminate(){try{await this.initWorkerPromise}catch(e){}this.workerProcessRuntime&&this.workerProcessRuntime[a.cancel](),this.workerProcess&&this.workerProcess.terminate(),this.workerThreadEvaluationListener&&this.workerThreadEvaluationListener.terminate(),this.workerProcessMongoshBus&&this.workerProcessMongoshBus.terminate()}async interrupt(){return await this.initWorkerPromise,this.workerProcessRuntime.interrupt()}async waitForRuntimeToBeReady(){await this.initWorkerPromise}}},280(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.cancel=t.close=void 0,t.exposeAll=function(e,r){return Object.entries(e).forEach((([e,t])=>{const{close:s}=(0,n.expose)(e,(async(...e)=>{try{return{type:"Message",payload:await t(...e)}}catch(e){return{type:"Error",payload:(0,o.serializeError)(e)}}}),i(r));t.close=s})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,r,s={}){const a={},u=new Set;return e.forEach((e=>{const t=(0,n.caller)(e,i(r));a[e]=async(...r)=>{var n;const i="function"==typeof s[e]?null===(n=s[e])||void 0===n?void 0:n.call(s,...r):r,a=t(...i);u.add(a);const l=await a;if(u.delete(a),(f=l)&&"object"==typeof f&&"Error"===f.type)throw(0,o.deserializeError)(l.payload);var f;return l.payload}})),Object.defineProperty(a,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),a};const n=r(59),o=r(495);function i(e){return{addListener:e.addEventListener.bind(e),removeListener:e.removeEventListener.bind(e),postMessage:t=>e.postMessage(t),getMessageData(e){var t;return null!==(t=e.data)&&void 0!==t?t:e}}}t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel")},495(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.serializeError=i,t.deserializeError=s,t.serializeEvaluationResult=function({type:e,printable:t,source:r,constructionOptions:s}){return"object"!=typeof(a=t)&&"function"!=typeof a||null===a?{type:e,printable:t,source:r,constructionOptions:s}:function(e){return e&&e.name&&e.message&&e.stack}(t)?{type:"SerializedErrorResult",printable:i(t),source:r,constructionOptions:s}:null===e?{type:"InspectResult",printable:(0,n.inspect)(t),source:r}:{type:"SerializedShellApiResult",printable:{origType:e,serializedValue:o.EJSON.serialize(t),constructionOptions:s}};var a},t.deserializeEvaluationResult=function({type:e,printable:t,source:r,constructionOptions:n}){return"SerializedErrorResult"===e?{type:e,printable:s(t),source:r,constructionOptions:n}:"SerializedShellApiResult"===e?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:r,constructionOptions:n}:{type:e,printable:t,source:r,constructionOptions:n}},t.serializeConnectOptions=function(e){var t;const r={...e};for(const e of a)(null===(t=r.autoEncryption)||void 0===t?void 0:t[e])&&(r.autoEncryption={...r.autoEncryption,[e]:o.EJSON.serialize(r.autoEncryption[e],{relaxed:!1})});return r},t.deserializeConnectOptions=function(e){var t;const r={...e};for(const e of a)(null===(t=r.autoEncryption)||void 0===t?void 0:t[e])&&(r.autoEncryption={...r.autoEncryption,[e]:o.EJSON.deserialize(r.autoEncryption[e],{relaxed:!1})});return r};const n=r(23),o=r(78);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").filter((t=>"function"!=typeof e[t])).reduce(((t,r)=>(t[r]=e[r],t)),{})}function s(e){return Object.assign(new Error,e)}const a=["schemaMap","encryptedFieldsMap"]},852(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerProcessMongoshBus=void 0;const n=r(280);t.WorkerProcessMongoshBus=class WorkerProcessMongoshBus{constructor(e,t){const r=(0,n.exposeAll)({emit(...t){e.emit(...t)},on(){throw new Error("Can't use `on` method on WorkerProcessMongoshBus")},once(){throw new Error("Can't use `once` method on WorkerProcessMongoshBus")}},t);this.exposedEmitter=r}terminate(){this.exposedEmitter[n.close]()}}},286(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.WorkerThreadEvaluationListener=void 0;const n=r(280),o=r(495);t.WorkerThreadEvaluationListener=class WorkerThreadEvaluationListener{constructor(e,t){this.exposedListener=(0,n.exposeAll)({onPrompt(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.onPrompt)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:""},onPrint(t){var r,n;return t=t.map(o.deserializeEvaluationResult),null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.onPrint)||void 0===n?void 0:n.call(r,t)},setConfig(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.setConfig)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:Promise.resolve("ignored")},resetConfig(t){var r,n,o;return null!==(o=null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.resetConfig)||void 0===n?void 0:n.call(r,t))&&void 0!==o?o:Promise.resolve("ignored")},validateConfig(t,r){var n,o,i;return null!==(i=null===(o=null===(n=e.evaluationListener)||void 0===n?void 0:n.validateConfig)||void 0===o?void 0:o.call(n,t,r))&&void 0!==i?i:Promise.resolve(null)},getConfig(t){var r,n;return null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.getConfig)||void 0===n?void 0:n.call(r,t)},listConfigOptions(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.listConfigOptions)||void 0===r?void 0:r.call(t)},onClearCommand(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.onClearCommand)||void 0===r?void 0:r.call(t)},onExit(t){var r,n,o;return null!==(o=null===(n=null===(r=e.evaluationListener)||void 0===r?void 0:r.onExit)||void 0===n?void 0:n.call(r,t))&&void 0!==o?o:Promise.resolve()},getLogPath(){var t,r;return null===(r=null===(t=e.evaluationListener)||void 0===t?void 0:t.getLogPath)||void 0===r?void 0:r.call(t)}},t)}terminate(){this.exposedListener[n.close]()}}},196(e){"use strict";e.exports=require("interruptor")},907(e){"use strict";e.exports=require("cluster")},982(e){"use strict";e.exports=require("crypto")},434(e){"use strict";e.exports=require("events")},928(e){"use strict";e.exports=require("path")},16(e){"use strict";e.exports=require("url")},23(e){"use strict";e.exports=require("util")},78(e,t){"use strict";const r=(()=>{const e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return t=>e.call(t)})();function n(e){return"Uint8Array"===r(e)}function o(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&("ArrayBuffer"===e[Symbol.toStringTag]||"SharedArrayBuffer"===e[Symbol.toStringTag])}function i(e){return e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)}function s(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&"Map"===e[Symbol.toStringTag]}function a(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function u(e,t){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?{$numberLong:`${t}`}:s(t)?Object.fromEntries(t):t))}const l=Symbol.for("@@mdb.bson.version"),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=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 7.x.x")}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}class BSONOffsetError extends BSONError{get name(){return"BSONOffsetError"}offset;constructor(e,t,r){super(`${e}. offset: ${t}`,r),this.offset=t}}let y,m;function w(e,t,r,n){if(n){y??=new TextDecoder("utf8",{fatal:!0});try{return y.decode(e.subarray(t,r))}catch(e){throw new BSONError("Invalid UTF-8 string in BSON document",{cause:e})}}return m??=new TextDecoder("utf8",{fatal:!1}),m.decode(e.subarray(t,r))}function B(e,t,r){if(0===e.length)return"";const n=r-t;if(0===n)return"";if(n>20)return null;if(1===n&&e[t]<128)return String.fromCharCode(e[t]);if(2===n&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(3===n&&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 n=t;n<r;n++){const t=e[n];if(t>127)return null;o.push(t)}return String.fromCharCode(...o)}function O(e){return N.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}function S(e){return crypto.getRandomValues(N.allocate(e))}const E=(()=>{const{crypto:e}=globalThis;return null!=e&&"function"==typeof e.getRandomValues?S:O})(),N={isUint8Array:n,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 the passed potentialBuffer.")},allocate:e=>Buffer.alloc(e),allocateUnsafe:e=>Buffer.allocUnsafe(e),compare:(e,t)=>N.toLocalBufferType(e).compare(t),concat:e=>Buffer.concat(e),copy:(e,t,r,n,o)=>N.toLocalBufferType(e).copy(t,r??0,n??0,o??e.length),equals:(e,t)=>N.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),fromUTF8:e=>Buffer.from(e,"utf8"),toBase64:e=>N.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>N.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>N.toLocalBufferType(e).toString("hex"),toUTF8(e,t,r,n){const o=r-t<=20?B(e,t,r):null;if(null!=o)return o;const i=N.toLocalBufferType(e).toString("utf8",t,r);if(n)for(let n=0;n<i.length;n++)if(65533===i.charCodeAt(n)){w(e,t,r,!0);break}return i},utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into(e,t,r){const n=function(e,t,r){if(0===t.length)return 0;if(t.length>25)return null;if(e.length-r<t.length)return null;for(let n=0,o=r;n<t.length;n++,o++){const r=t.charCodeAt(n);if(r>127)return null;e[o]=r}return t.length}(e,t,r);return null!=n?n:N.toLocalBufferType(e).write(t,r,void 0,"utf8")},randomBytes:E,swap32:e=>N.toLocalBufferType(e).swap32()};function L(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return I.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const v=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(I.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 L})(),x=/(\d|[a-f])/i,I={isUint8Array:n,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 passed potentialBuffer.")},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=>I.allocate(e),compare(e,t){if(e===t)return 0;const r=Math.min(e.length,t.length);for(let n=0;n<r;n++){if(e[n]<t[n])return-1;if(e[n]>t[n])return 1}return e.length<t.length?-1:e.length>t.length?1:0},concat(e){if(0===e.length)return I.allocate(0);let t=0;for(const r of e)t+=r.length;const r=I.allocate(t);let n=0;for(const t of e)r.set(t,n),n+=t.length;return r},copy(e,t,r,n,o){if(void 0!==o&&o<0)throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${o}`);if(o=o??e.length,void 0!==n&&(n<0||n>o))throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${o}. Received ${n}`);if(n=n??0,void 0!==r&&r<0)throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${r}`);r=r??0;const i=e.subarray(n,o),s=Math.min(i.length,t.length-r);return s<=0?0:(t.set(i.subarray(0,s),r),s)},equals(e,t){if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},fromNumberArray:e=>Uint8Array.from(e),fromBase64:e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))),fromUTF8:e=>(new TextEncoder).encode(e),toBase64:e=>btoa(I.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),r=[];for(let e=0;e<t.length;e+=2){const n=t[e],o=t[e+1];if(!x.test(n))break;if(!x.test(o))break;const i=Number.parseInt(`${n}${o}`,16);r.push(i)}return Uint8Array.from(r)},toHex:e=>Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join(""),toUTF8(e,t,r,n){const o=r-t<=20?B(e,t,r):null;return null!=o?o:w(e,t,r,n)},utf8ByteLength:e=>(new TextEncoder).encode(e).byteLength,encodeUTF8Into(e,t,r){const n=(new TextEncoder).encode(t);return e.set(n,r),n.byteLength},randomBytes:v,swap32(e){if(e.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2],i=e[t+3];e[t]=i,e[t+1]=o,e[t+2]=n,e[t+3]=r}return e}},_="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?N:I,U=Symbol.for("@@mdb.bson.type");class BSONValue{get[U](){return this._bsontype}get[l](){return 7}[Symbol.for("nodejs.util.inspect.custom")](e,t,r){return this.inspect(e,t,r)}}const T=new Float64Array(1),$=new Uint8Array(T.buffer,0,8);T[0]=-1;const R=0===$[7],j={isBigEndian:R,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)=>(BigInt(e[t+4]+256*e[t+5]+65536*e[t+6]+(e[t+7]<<24))<<32n)+BigInt(e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3]),getFloat64LE:R?(e,t)=>($[7]=e[t],$[6]=e[t+1],$[5]=e[t+2],$[4]=e[t+3],$[3]=e[t+4],$[2]=e[t+5],$[1]=e[t+6],$[0]=e[t+7],T[0]):(e,t)=>($[0]=e[t],$[1]=e[t+1],$[2]=e[t+2],$[3]=e[t+3],$[4]=e[t+4],$[5]=e[t+5],$[6]=e[t+6],$[7]=e[t+7],T[0]),setInt32BE:(e,t,r)=>(e[t+3]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t]=r,4),setInt32LE:(e,t,r)=>(e[t]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+3]=r,4),setBigInt64LE(e,t,r){const n=0xffffffffn;let o=Number(r&n);e[t]=o,o>>=8,e[t+1]=o,o>>=8,e[t+2]=o,o>>=8,e[t+3]=o;let i=Number(r>>32n&n);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:R?(e,t,r)=>(T[0]=r,e[t]=$[7],e[t+1]=$[6],e[t+2]=$[5],e[t+3]=$[4],e[t+4]=$[3],e[t+5]=$[2],e[t+6]=$[1],e[t+7]=$[0],8):(e,t,r)=>(T[0]=r,e[t]=$[0],e[t+1]=$[1],e[t+2]=$[2],e[t+3]=$[3],e[t+4]=$[4],e[t+5]=$[5],e[t+6]=$[6],e[t+7]=$[7],8)};class Binary extends BSONValue{get _bsontype(){return"Binary"}static BSON_BINARY_SUBTYPE_DEFAULT=0;static BUFFER_SIZE=256;static SUBTYPE_DEFAULT=0;static SUBTYPE_FUNCTION=1;static SUBTYPE_BYTE_ARRAY=2;static SUBTYPE_UUID_OLD=3;static SUBTYPE_UUID=4;static SUBTYPE_MD5=5;static SUBTYPE_ENCRYPTED=6;static SUBTYPE_COLUMN=7;static SUBTYPE_SENSITIVE=8;static SUBTYPE_VECTOR=9;static SUBTYPE_USER_DEFINED=128;static VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});buffer;sub_type;position;constructor(e,t){if(super(),null!=e&&"string"==typeof e&&!ArrayBuffer.isView(e)&&!o(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=_.allocate(Binary.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(e)?_.fromNumberArray(e):_.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=_.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=_.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(_.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){const r=e+(t=t&&t>0?t:this.position);return this.buffer.subarray(e,r>this.position?this.position:r)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return _.toBase64(this.buffer.subarray(0,this.position))}toString(e){return"hex"===e?_.toHex(this.buffer.subarray(0,this.position)):"base64"===e?_.toBase64(this.buffer.subarray(0,this.position)):_.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(e){e=e||{},this.sub_type===Binary.SUBTYPE_VECTOR&&A(this);const t=_.toBase64(this.buffer),r=Number(this.sub_type).toString(16);return e.legacy?{$binary:t,$type:1===r.length?"0"+r:r}:{$binary:{base64:t,subType:1===r.length?"0"+r:r}}}toUUID(){if(this.sub_type===Binary.SUBTYPE_UUID)return new UUID(this.buffer.subarray(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(_.fromHex(e),t)}static createFromBase64(e,t){return new Binary(_.fromBase64(e),t)}static fromExtendedJSON(e,t){let r,n;if(t=t||{},"$binary"in e?t.legacy&&"string"==typeof e.$binary&&"$type"in e?(n=e.$type?parseInt(e.$type,16):0,r=_.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(n=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=_.fromBase64(e.$binary.base64)):"$uuid"in e&&(n=4,r=UUID.bytesFromString(e.$uuid)),!r)throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return 4===n?new UUID(r):new Binary(r,n)}inspect(e,t,r){return r??=u,`Binary.createFromBase64(${r(_.toBase64(this.buffer.subarray(0,this.position)),t)}, ${r(this.sub_type,t)})`}toInt8Array(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.Int8)throw new BSONError("Binary datatype field is not Int8");return A(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.Float32)throw new BSONError("Binary datatype field is not Float32");A(this);const e=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return j.isBigEndian&&_.swap32(e),new Float32Array(e.buffer)}toPackedBits(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.PackedBit)throw new BSONError("Binary datatype field is not packed bit");return A(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==Binary.SUBTYPE_VECTOR)throw new BSONError("Binary sub_type is not Vector");if(this.buffer[0]!==Binary.VECTOR_TYPE.PackedBit)throw new BSONError("Binary datatype field is not packed bit");A(this);const e=8*(this.length()-2)-this.buffer[1],t=new Int8Array(e);for(let e=0;e<t.length;e++){const r=e/8|0,n=this.buffer[r+2]>>7-e%8&1;t[e]=n}return t}static fromInt8Array(e){const t=_.allocate(e.byteLength+2);t[0]=Binary.VECTOR_TYPE.Int8,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);t.set(r,2);const n=new this(t,this.SUBTYPE_VECTOR);return A(n),n}static fromFloat32Array(e){const t=_.allocate(e.byteLength+2);t[0]=Binary.VECTOR_TYPE.Float32,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);t.set(r,2),j.isBigEndian&&_.swap32(new Uint8Array(t.buffer,2));const n=new this(t,this.SUBTYPE_VECTOR);return A(n),n}static fromPackedBits(e,t=0){const r=_.allocate(e.byteLength+2);r[0]=Binary.VECTOR_TYPE.PackedBit,r[1]=t,r.set(e,2);const n=new this(r,this.SUBTYPE_VECTOR);return A(n),n}static fromBits(e){const t=e.length+7>>>3,r=new Uint8Array(t+2);r[0]=Binary.VECTOR_TYPE.PackedBit;const n=e.length%8;r[1]=0===n?0:8-n;for(let t=0;t<e.length;t++){const n=t>>>3,o=e[t];if(0!==o&&1!==o)throw new BSONError(`Invalid bit value at ${t}: must be 0 or 1, found ${e[t]}`);if(0===o)continue;const i=7-t%8;r[n+2]|=o<<i}return new this(r,Binary.SUBTYPE_VECTOR)}}function A(e){if(e.sub_type!==Binary.SUBTYPE_VECTOR)return;const t=e.position,r=e.buffer[0],n=e.buffer[1];if((r===Binary.VECTOR_TYPE.Float32||r===Binary.VECTOR_TYPE.Int8)&&0!==n)throw new BSONError("Invalid Vector: padding must be zero for int8 and float32 vectors");if(r===Binary.VECTOR_TYPE.Float32&&0!==t&&t-2!=0&&(t-2)%4!=0)throw new BSONError("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(r===Binary.VECTOR_TYPE.PackedBit&&0!==n&&2===t)throw new BSONError("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(r===Binary.VECTOR_TYPE.PackedBit&&n>7)throw new BSONError(`Invalid Vector: padding must be a value between 0 and 7. found: ${n}`)}const D=/^[0-9A-F]{32}$/i,P=/^[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=_.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=_.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,4)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[_.toHex(this.buffer.subarray(0,4)),_.toHex(this.buffer.subarray(4,6)),_.toHex(this.buffer.subarray(6,8)),_.toHex(this.buffer.subarray(8,10)),_.toHex(this.buffer.subarray(10,16))].join("-"):_.toHex(this.buffer)}toString(e){return"hex"===e?_.toHex(this.id):"base64"===e?_.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return _.equals(e.id,this.id);try{return _.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=_.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):n(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(_.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 _.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return D.test(e)||P.test(e)}inspect(e,t,r){return r??=u,`new UUID(${r(this.toHexString(),t)})`}}class Code extends BSONValue{get _bsontype(){return"Code"}code;scope;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,r){r??=u;let n=r(this.code,t);const o=n.includes("\n");return null!=this.scope&&(n+=`,${o?"\n":" "}${r(this.scope,t)}`),`new Code(${o?"\n":""}${n}${o&&null===this.scope?"\n":""})`}}function M(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"}collection;oid;db;fields;constructor(e,t,r,n){super();const o=e.split(".");2===o.length&&(r=o.shift(),e=o.shift()),this.collection=e,this.oid=t,this.db=r,this.fields=n||{}}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,r){r??=u;const n=[r(this.namespace,t),r(this.oid,t),...this.db?[r(this.db,t)]:[],...Object.keys(this.fields).length>0?[r(this.fields,t)]:[]];return n[1]=r===u?`new ObjectId(${n[1]})`:n[1],`new DBRef(${n.join(", ")})`}}function V(e){if(""===e)return e;let t=0;const r="-"===e[t],n="+"===e[t];(n||r)&&(t+=1);let o=!1;for(;t<e.length&&"0"===e[t];++t)o=!0;return o?`${r?"-":""}${e.length===t?"0":e.slice(t)}`:n?e.slice(1):e}let C;try{C=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 F=4294967296,k=0x10000000000000000,z=k/2,J={},Y={},q=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}high;low;unsigned;constructor(e=0,t,r){super();const n="boolean"==typeof t?t:Boolean(r),o="number"==typeof t?t:0,i="string"==typeof e?Long.fromString(e,n):"bigint"==typeof e?Long.fromBigInt(e,n):{low:0|e,high:0|o,unsigned:n};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static TWO_PWR_24=Long.fromInt(16777216);static MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0);static ZERO=Long.fromInt(0);static UZERO=Long.fromInt(0,!0);static ONE=Long.fromInt(1);static UONE=Long.fromInt(1,!0);static NEG_ONE=Long.fromInt(-1);static MAX_VALUE=Long.fromBits(-1,2147483647,!1);static MIN_VALUE=Long.fromBits(0,-2147483648,!1);static fromBits(e,t,r){return new Long(e,t,r)}static fromInt(e,t){let r,n,o;return t?(o=0<=(e>>>=0)&&e<256)&&(n=Y[e],n)?n:(r=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(Y[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=J[e],n)?n:(r=Long.fromBits(e,e<0?-1:0,!1),o&&(J[e]=r),r)}static fromNumber(e,t){if(isNaN(e))return t?Long.UZERO:Long.ZERO;if(t){if(e<0)return Long.UZERO;if(e>=k)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-z)return Long.MIN_VALUE;if(e+1>=z)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%F|0,e/F|0,t)}static fromBigInt(e,t){const r=0xffffffffn;return new Long(Number(e&r),Number(e>>32n&r),t)}static _fromString(e,t,r){if(0===e.length)throw new BSONError("empty string");if(r<2||36<r)throw new BSONError("radix");let n;if((n=e.indexOf("-"))>0)throw new BSONError("interior hyphen");if(0===n)return Long._fromString(e.substring(1),t,r).neg();const o=Long.fromNumber(Math.pow(r,8));let i=Long.ZERO;for(let t=0;t<e.length;t+=8){const n=Math.min(8,e.length-t),s=parseInt(e.substring(t,t+n),r);if(n<8){const e=Long.fromNumber(Math.pow(r,n));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,r){let n=!1;if("number"==typeof t?(r=t,t=!1):n=!!t,r??=10,e.trim()!==e)throw new BSONError(`Input: '${e}' contains leading and/or trailing whitespace`);if(!function(e,t){t=t??10;const r="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,t);return!new RegExp(`[^-+${r}]`,"i").test(e)&&e}(e,r))throw new BSONError(`Input: '${e}' contains invalid characters for radix: ${r}`);const o=V(e),i=Long._fromString(o,n,r);if(i.toString(r).toLowerCase()!==o.toLowerCase())throw new BSONError(`Input: ${e} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=r?`with radix: ${r}`:""}`);return i}static fromString(e,t,r){let n=!1;return"number"==typeof t?(r=t,t=!1):n=!!t,r??=10,"NaN"===e&&r<24||("Infinity"===e||"+Infinity"===e||"-Infinity"===e)&&r<35?Long.ZERO:Long._fromString(e,n,r)}static fromBytes(e,t,r){return r?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,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16;let u=0,l=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=n+a,l+=f>>>16,f&=65535,l+=r+s,u+=l>>>16,l&=65535,u+=t+i,u&=65535,Long.fromBits(f<<16|c,u<<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(),r=e.isNegative();return t&&!r?-1:!t&&r?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(C){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?C.div_u:C.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?Long.UZERO:Long.ZERO;let t,r,n;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return Long.UZERO;if(e.gt(this.shru(1)))return Long.UONE;n=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:(r=this.sub(e.mul(t)),n=t.add(r.div(e)),n));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();n=Long.ZERO}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.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),a=s.mul(e);for(;a.isNegative()||a.gt(r);)t-=i,s=Long.fromNumber(t,this.unsigned),a=s.mul(e);s.isZero()&&(s=Long.ONE),n=n.add(s),r=r.sub(a)}return n}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&&!(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!(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return!(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)),C){const t=(this.unsigned?C.rem_u:C.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.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)),C){const t=C.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,C.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,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,u=65535&e.low;let l=0,f=0,c=0,h=0;return h+=o*u,c+=h>>>16,h&=65535,c+=n*u,f+=c>>>16,c&=65535,c+=o*a,f+=c>>>16,c&=65535,f+=r*u,l+=f>>>16,f&=65535,f+=n*a,l+=f>>>16,f&=65535,f+=o*s,l+=f>>>16,f&=65535,l+=t*u+r*a+n*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 r=this.low;return Long.fromBits(r>>>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)*F+(this.low>>>0):this.high*F+(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),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}const t=Long.fromNumber(Math.pow(e,6),this.unsigned);let r=this,n="";for(;;){const o=r.div(t);let i=(r.sub(o.mul(t)).toInt()>>>0).toString(e);if(r=o,r.isZero())return i+n;for(;i.length<6;)i="0"+i;n=""+i+n}}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:r=!1,relaxed:n=!0}={...t};if(e.$numberLong.length>20)throw new BSONError("$numberLong string is too long");if(!q.test(e.$numberLong))throw new BSONError(`$numberLong string "${e.$numberLong}" is in an invalid format`);if(r){const t=BigInt(e.$numberLong);return BigInt.asIntN(64,t)}const o=Long.fromString(e.$numberLong);return n?o.toNumber():o}inspect(e,t,r){return r??=u,`new Long(${r(this.toString(),t)}${this.unsigned?`, ${r(this.unsigned,t)}`:""})`}}const H=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,K=/^(\+|-)?(Infinity|inf)$/i,W=/^(\+|-)?NaN$/i,Z=6111,G=-6176,X=_.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Q=_.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ee=_.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),te=/^([-+])?(\d+)?$/;function re(e){return!isNaN(parseInt(e,10))}function ne(e){const t=Long.fromNumber(1e9);let r=Long.fromNumber(0);if(!(e.parts[0]||e.parts[1]||e.parts[2]||e.parts[3]))return{quotient:e,rem:r};for(let n=0;n<=3;n++)r=r.shiftLeft(32),r=r.add(new Long(e.parts[n],0)),e.parts[n]=r.div(t).low,r=r.modulo(t);return{quotient:e,rem:r}}function oe(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}bytes;constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!(e instanceof Uint8Array||n(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 r=!1,n=!1,o=!1,i=!1,s=0,a=0,u=0,l=0,f=0;const c=[0];let h=0,g=0,d=0,p=0,b=new Long(0,0),y=new Long(0,0),m=0,w=0;if(e.length>=7e3)throw new BSONError(e+" not a valid Decimal128 string");const B=e.match(H),O=e.match(K),S=e.match(W);if(!B&&!O&&!S||0===e.length)throw new BSONError(e+" not a valid Decimal128 string");if(B){const t=B[2],r=B[4],n=B[5],o=B[6];r&&void 0===o&&oe(e,"missing exponent power"),r&&void 0===t&&oe(e,"missing exponent base"),void 0===r&&(n||o)&&oe(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(n=!0,r="-"===e[w++]),!re(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(r?Q:ee);if("N"===e[w])return new Decimal128(X)}for(;re(e[w])||"."===e[w];)"."!==e[w]?(h<34&&("0"!==e[w]||i)&&(i||(f=a),i=!0,c[g++]=parseInt(e[w],10),h+=1),i&&(u+=1),o&&(l+=1),a+=1,w+=1):(o&&oe(e,"contains multiple periods"),o=!0,w+=1);if(o&&!a)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(te);if(!t||!t[2])return new Decimal128(X);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(X);if(h){if(d=h-1,s=u,1!==s)for(;"0"===e[f+s-1+Number(n)+Number(o)];)s-=1}else c[0]=0,u=1,h=1,s=0;for(p<=l&&l>p+16384?p=G:p-=l;p>Z;){if(d+=1,d>=34){if(0===s){p=Z;break}oe(e,"overflow")}p-=1}if(t.allowRounding){for(;p<G||h<u;){if(0===d&&s<h){p=G,s=0;break}if(h<u?u-=1:d-=1,p<Z)p+=1;else{if(c.join("").match(/^0+$/)){p=Z;break}oe(e,"overflow")}}if(d+1<s){let t=a;o&&(f+=1,t+=1),n&&(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 r=f+d+2;r<t;r++)if(parseInt(e[r],10)){s=1;break}}if(s){let e=d;for(;e>=0&&++c[e]>9;e--)if(c[e]=0,0===e){if(!(p<Z))return new Decimal128(r?Q:ee);p+=1,c[e]=1}}}}else{for(;p<G||h<u;){if(0===d){if(0===s){p=G;break}oe(e,"exponent underflow")}h<u?("0"!==e[u-1+Number(n)+Number(o)]&&0!==s&&oe(e,"inexact rounding"),u-=1):(0!==c[d]&&oe(e,"inexact rounding"),d-=1),p<Z?p+=1:oe(e,"overflow")}d+1<s&&(o&&(f+=1),n&&(f+=1),0!==parseInt(e[f+d+1],10)&&oe(e,"inexact rounding"))}if(b=Long.fromNumber(0),y=Long.fromNumber(0),0===s)b=Long.fromNumber(0),y=Long.fromNumber(0);else if(d<17){let e=0;for(y=Long.fromNumber(c[e++]),b=new Long(0,0);e<=d;e++)y=y.multiply(Long.fromNumber(10)),y=y.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(y=Long.fromNumber(c[e++]);e<=d;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(c[e]))}const E=function(e,t){if(!e&&!t)return{high:Long.fromNumber(0),low:Long.fromNumber(0)};const r=e.shiftRightUnsigned(32),n=new Long(e.getLowBits(),0),o=t.shiftRightUnsigned(32),i=new Long(t.getLowBits(),0);let s=r.multiply(o),a=r.multiply(i);const u=n.multiply(o);let l=n.multiply(i);return s=s.add(a.shiftRightUnsigned(32)),a=new Long(a.getLowBits(),0).add(u).add(l.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),l=a.shiftLeft(32).add(new Long(l.getLowBits(),0)),{high:s,low:l}}(b,Long.fromString("100000000000000000"));E.low=E.low.add(y),function(e,t){const r=e.high>>>0,n=t.high>>>0;return r<n||r===n&&e.low>>>0<t.low>>>0}(E.low,y)&&(E.high=E.high.add(Long.fromNumber(1))),m=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(m).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&m).shiftLeft(49)),N.high=N.high.or(E.high.and(Long.fromNumber(562949953421311)))),N.low=E.low,r&&(N.high=N.high.or(Long.fromString("9223372036854775808")));const L=_.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 r=new Array(36);for(let e=0;e<r.length;e++)r[e]=0;let n,o,i,s=0,a=!1,u={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,n=8+(d>>14&1)}else n=d>>14&7,e=d>>17&16383;const b=e-6176;if(u.parts[0]=(16383&d)+((15&n)<<14),u.parts[1]=g,u.parts[2]=h,u.parts[3]=c,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])a=!0;else for(i=3;i>=0;i--){let e=0;const t=ne(u);if(u=t.quotient,e=t.rem.low,e)for(o=8;o>=0;o--)r[9*i+o]=e%10,e=Math.floor(e/10)}if(a)t=1,r[s]=0;else for(t=36;!r[s];)t-=1,s+=1;const y=t-1+b;if(y>=34||y<=-7||b>0){if(t>34)return l.push("0"),b>0?l.push(`E+${b}`):b<0&&l.push(`E${b}`),l.join("");l.push(`${r[s++]}`),t-=1,t&&l.push(".");for(let e=0;e<t;e++)l.push(`${r[s++]}`);l.push("E"),y>0?l.push(`+${y}`):l.push(`${y}`)}else if(b>=0)for(let e=0;e<t;e++)l.push(`${r[s++]}`);else{let e=t+b;if(e>0)for(let t=0;t<e;t++)l.push(`${r[s++]}`);else l.push("0");for(l.push(".");e++<0;)l.push("0");for(let n=0;n<t-Math.max(e-1,0);n++)l.push(`${r[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,r){return r??=u,`new Decimal128(${r(this.toString(),t)})`}}class Double extends BSONValue{get _bsontype(){return"Double"}value;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 r=parseFloat(e.$numberDouble);return t&&t.relaxed?r:new Double(r)}inspect(e,t,r){return r??=u,`new Double(${r(this.value,t)})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}value;constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}static fromString(e){const t=V(e),r=Number(e);if(f<r)throw new BSONError(`Input: '${e}' is larger than the maximum value for Int32`);if(c>r)throw new BSONError(`Input: '${e}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(r))throw new BSONError(`Input: '${e}' is not a safe integer`);if(r.toString()!==t)throw new BSONError(`Input: '${e}' is not a valid Int32 string`);return new Int32(r)}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,r){return r??=u,`new Int32(${r(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()"}}let ie=null;const se=new WeakMap;class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}static index=Math.floor(16777215*Math.random());static cacheHexString;buffer;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?_.fromHex(e.toHexString()):e.id}else t=e;if(null==t)this.buffer=ObjectId.generate();else if(ArrayBuffer.isView(t)&&12===t.byteLength)this.buffer=_.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(!ObjectId.validateHexString(t))throw new BSONError("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=_.fromHex(t),ObjectId.cacheHexString&&se.set(this,t)}}get id(){return this.buffer}set id(e){this.buffer=e,ObjectId.cacheHexString&&se.set(this,_.toHex(e))}static validateHexString(e){if(24!==e?.length)return!1;for(let t=0;t<24;t++){const r=e.charCodeAt(t);if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return!0}toHexString(){if(ObjectId.cacheHexString){const e=se.get(this);if(e)return e}const e=_.toHex(this.id);return ObjectId.cacheHexString&&se.set(this,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(),r=_.allocateUnsafe(12);return j.setInt32BE(r,0,e),null===ie&&(ie=_.randomBytes(5)),r[4]=ie[0],r[5]=ie[1],r[6]=ie[2],r[7]=ie[3],r[8]=ie[4],r[11]=255&t,r[10]=t>>8&255,r[9]=t>>16&255,r}toString(e){return"base64"===e?_.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]&&_.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(),r=this.toHexString();return"string"==typeof t&&t.toLowerCase()===r}return!1}getTimestamp(){const e=new Date,t=j.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=_.allocate(12);for(let e=11;e>=4;e--)t[e]=0;return j.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(_.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(_.fromBase64(e))}static isValid(e){if(null==e)return!1;if("string"==typeof e)return ObjectId.validateHexString(e);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)}isCached(){return ObjectId.cacheHexString&&se.has(this)}inspect(e,t,r){return r??=u,`new ObjectId(${r(this.toHexString(),t)})`}}function ae(e,t,r){let n=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)n+=ue(o.toString(),e[o],t,!0,r);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))n+=ue(o,e[o],t,!1,r)}return n}function ue(e,t,r=!1,n=!1,s=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+_.utf8ByteLength(e)+1+4+_.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=p&&t<=d&&t>=c&&t<=f?(null!=e?_.utf8ByteLength(e)+1:0)+5:(null!=e?_.utf8ByteLength(e)+1:0)+9;case"undefined":return n||!s?(null!=e?_.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?_.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&7!==t[l])throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||a(t))return(null!=e?_.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||o(t))return(null!=e?_.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?_.utf8ByteLength(e)+1:0)+1+4+4+_.utf8ByteLength(t.code.toString())+1+ae(t.scope,r,s):(null!=e?_.utf8ByteLength(e)+1:0)+1+4+_.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const r=t;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?_.utf8ByteLength(e)+1:0)+(r.position+1+4+1+4):(null!=e?_.utf8ByteLength(e)+1:0)+(r.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?_.utf8ByteLength(e)+1:0)+_.utf8ByteLength(t.value)+4+1+1;if("DBRef"===t._bsontype){const n=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(n.$db=t.db),(null!=e?_.utf8ByteLength(e)+1:0)+1+ae(n,r,s)}return t instanceof RegExp||i(t)?(null!=e?_.utf8ByteLength(e)+1:0)+1+_.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?_.utf8ByteLength(e)+1:0)+1+_.utf8ByteLength(t.pattern)+1+_.utf8ByteLength(t.options)+1:(null!=e?_.utf8ByteLength(e)+1:0)+ae(t,r,s)+1;case"function":return r?(null!=e?_.utf8ByteLength(e)+1:0)+1+4+_.utf8ByteLength(t.toString())+1:0;case"bigint":return(null!=e?_.utf8ByteLength(e)+1:0)+9;case"symbol":return 0;default:throw new BSONError("Unrecognized JS type: "+typeof t)}}class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}pattern;options;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,r){const n=function(e){if(null!=e&&"object"==typeof e&&"stylize"in e&&"function"==typeof e.stylize)return e.stylize}(t)??(e=>e);return r??=u,`new BSONRegExp(${n(r(this.pattern),"regexp")}, ${n(r(this.options),"regexp")})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}value;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,r){return r??=u,`new BSONSymbol(${r(this.value,t)})`}}const le=Long;class Timestamp extends le{get _bsontype(){return"Timestamp"}get[U](){return"Timestamp"}static MAX_VALUE=Long.MAX_UNSIGNED_VALUE;get i(){return this.low>>>0}get t(){return this.high>>>0}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),r=Number(e.i);if(t<0||Number.isNaN(t))throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(r<0||Number.isNaN(r))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(r>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(r,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.t,i:this.i}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,r=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:r,i:t})}inspect(e,t,r){return r??=u,`new Timestamp({ t: ${r(this.t,t)}, i: ${r(this.i,t)} })`}}const fe=Long.fromNumber(d),ce=Long.fromNumber(p);function he(e,t,r){const n=(t=null==t?{}:t)&&t.index?t.index:0,o=j.getInt32LE(e,n);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+n>e.byteLength)throw new BSONError(`(bson size ${o} + options.index ${n} must be <= buffer length ${e.byteLength})`);if(0!==e[n+o-1])throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return de(e,n,t,r)}const ge=/^\$ref$|^\$id$|^\$db$/;function de(e,t,r,n=!1){const o=null==r.fieldsAsRaw?null:r.fieldsAsRaw,i=null!=r.raw&&r.raw,s="boolean"==typeof r.bsonRegExp&&r.bsonRegExp,a=r.promoteBuffers??!1,u=r.promoteLongs??!0,l=r.promoteValues??!0,f=r.useBigInt64??!1;if(f&&!l)throw new BSONError("Must either request bigint or Long for int64 deserialization");if(f&&!u)throw new BSONError("Must either request bigint or Long for int64 deserialization");let c,h,g=!0;const d=(null==r.validation?{utf8:!0}:r.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 b=j.getInt32LE(e,t);if(t+=4,b<5||b>e.length)throw new BSONError("corrupt bson message");const y=n?[]:{};let m=0,w=!n&&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 b=n?m++:_.toUTF8(e,t,p,!1);let B,O=!0;if(O=g||h?.has(b)?c:!c,!1!==w&&"$"===b[0]&&(w=ge.test(b)),t=p+1,2===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");B=_.toUTF8(e,t,t+r-1,O),t+=r}else if(7===d){const r=_.allocateUnsafe(12);for(let n=0;n<12;n++)r[n]=e[t+n];B=new ObjectId(r),t+=12}else if(16===d&&!1===l)B=new Int32(j.getInt32LE(e,t)),t+=4;else if(16===d)B=j.getInt32LE(e,t),t+=4;else if(1===d)B=j.getFloat64LE(e,t),t+=8,!1===l&&(B=new Double(B));else if(9===d){const r=j.getInt32LE(e,t),n=j.getInt32LE(e,t+4);t+=8,B=new Date(new Long(r,n).toNumber())}else if(8===d){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");B=1===e[t++]}else if(3===d){const n=t,o=j.getInt32LE(e,t);if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)B=e.subarray(t,t+o);else{let t=r;g||(t={...r,validation:{utf8:O}}),B=de(e,n,t,!1)}t+=o}else if(4===d){const n=t,i=j.getInt32LE(e,t);let s=r;const a=t+i;if(o&&o[b]&&(s={...r,raw:!0}),g||(s={...s,validation:{utf8:O}}),B=de(e,n,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==a)throw new BSONError("corrupted array bson")}else if(6===d)B=void 0;else if(10===d)B=null;else if(18===d)if(f)B=j.getBigInt64LE(e,t),t+=8;else{const r=j.getInt32LE(e,t),n=j.getInt32LE(e,t+4);t+=8;const o=new Long(r,n);B=u&&!0===l&&o.lessThanOrEqual(fe)&&o.greaterThanOrEqual(ce)?o.toNumber():o}else if(19===d){const r=_.allocateUnsafe(16);for(let n=0;n<16;n++)r[n]=e[t+n];t+=16,B=new Decimal128(r)}else if(5===d){let r=j.getInt32LE(e,t);t+=4;const n=r,o=e[t++];if(r<0)throw new BSONError("Negative binary type element size found");if(r>e.byteLength)throw new BSONError("Binary type size larger than document size");if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=j.getInt32LE(e,t),t+=4,r<0)throw new BSONError("Negative binary type element size found for subtype 0x02");if(r>n-4)throw new BSONError("Binary type with subtype 0x02 contains too long binary size");if(r<n-4)throw new BSONError("Binary type with subtype 0x02 contains too short binary size")}a&&l?B=_.toLocalBufferType(e.subarray(t,t+r)):(B=new Binary(e.subarray(t,t+r),o),4===o&&UUID.isValid(B)&&(B=B.toUUID())),t+=r}else if(11===d&&!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 r=_.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 n=_.toUTF8(e,t,p,!1);t=p+1;const o=new Array(n.length);for(p=0;p<n.length;p++)switch(n[p]){case"m":o[p]="m";break;case"s":o[p]="g";break;case"i":o[p]="i"}B=new RegExp(r,o.join(""))}else if(11===d&&!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 r=_.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 n=_.toUTF8(e,t,p,!1);t=p+1,B=new BSONRegExp(r,n)}else if(14===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);B=l?n:new BSONSymbol(n),t+=r}else if(17===d)B=new Timestamp({i:j.getUint32LE(e,t),t:j.getUint32LE(e,t+4)}),t+=8;else if(255===d)B=new MinKey;else if(127===d)B=new MaxKey;else if(13===d){const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);B=new Code(n),t+=r}else if(15===d){const n=j.getInt32LE(e,t);if(t+=4,n<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=j.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=_.toUTF8(e,t,t+o-1,O),s=t+=o,a=j.getInt32LE(e,t),u=de(e,s,r,!1);if(t+=a,n<8+a+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(n>8+a+o)throw new BSONError("code_w_scope total size is too long, clips outer document");B=new Code(i,u)}else{if(12!==d)throw new BSONError(`Detected unknown BSON type ${d.toString(16)} for fieldname "${b}"`);{const r=j.getInt32LE(e,t);if(t+=4,r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=_.toUTF8(e,t,t+r-1,O);t+=r;const o=_.allocateUnsafe(12);for(let r=0;r<12;r++)o[r]=e[t+r];const i=new ObjectId(o);t+=12,B=new DBRef(n,i)}}"__proto__"===b?Object.defineProperty(y,b,{value:B,writable:!0,enumerable:!0,configurable:!0}):y[b]=B}if(b!==t-p){if(n)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!w)return y;if(M(y)){const e=Object.assign({},y);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(y.$ref,y.$id,y.$db,e)}return y}const pe=/\x00/,be=new Set(["$db","$ref","$id","$clusterTime"]);function ye(e,t,r,n){e[n++]=2,e[(n=n+_.encodeUTF8Into(e,t,n)+1)-1]=0;const o=_.encodeUTF8Into(e,r,n+4);return j.setInt32LE(e,n,o+1),n=n+4+o,e[n++]=0,n}function me(e,t,r,n){const o=!Object.is(r,-0)&&Number.isSafeInteger(r)&&r<=f&&r>=c?16:1;return e[n++]=o,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=16===o?j.setInt32LE(e,n,r):j.setFloat64LE(e,n,r)}function we(e,t,r,n){return e[n++]=18,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setBigInt64LE(e,n,r)}function Be(e,t,r,n){return e[n++]=10,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n}function Oe(e,t,r,n){return e[n++]=8,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=r?1:0,n}function Se(e,t,r,n){e[n++]=9,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=Long.fromNumber(r.getTime()),i=o.getLowBits(),s=o.getHighBits();return n+=j.setInt32LE(e,n,i),n+=j.setInt32LE(e,n,s)}function Ee(e,t,r,n){if(e[n++]=11,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,r.source&&null!=r.source.match(pe))throw new BSONError("value "+r.source+" must not contain null bytes");return n+=_.encodeUTF8Into(e,r.source,n),e[n++]=0,r.ignoreCase&&(e[n++]=105),r.global&&(e[n++]=115),r.multiline&&(e[n++]=109),e[n++]=0,n}function Ne(e,t,r,n){if(e[n++]=11,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,null!=r.pattern.match(pe))throw new BSONError("pattern "+r.pattern+" must not contain null bytes");n+=_.encodeUTF8Into(e,r.pattern,n),e[n++]=0;const o=r.options.split("").sort().join("");return n+=_.encodeUTF8Into(e,o,n),e[n++]=0,n}function Le(e,t,r,n){return null===r?e[n++]=10:"MinKey"===r._bsontype?e[n++]=255:e[n++]=127,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n}function ve(e,t,r,n){return e[n++]=7,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=r.serializeInto(e,n)}function xe(e,t,r,n){e[n++]=5,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.length;if(n+=j.setInt32LE(e,n,o),e[n++]=0,o<=16)for(let t=0;t<o;t++)e[n+t]=r[t];else e.set(r,n);return n+=o}function Ie(e,t,r,n,o,i,s,a,u){if(u.has(r))throw new BSONError("Cannot convert circular structure to BSON");u.add(r),e[n++]=Array.isArray(r)?4:3,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const l=Me(e,r,o,n,i+1,s,a,u);return u.delete(r),l}function _e(e,t,r,n){e[n++]=19,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;for(let t=0;t<16;t++)e[n+t]=r.bytes[t];return n+16}function Ue(e,t,r,n){e[n++]="Long"===r._bsontype?18:17,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.getLowBits(),i=r.getHighBits();return n+=j.setInt32LE(e,n,o),n+=j.setInt32LE(e,n,i)}function Te(e,t,r,n){return r=r.valueOf(),e[n++]=16,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setInt32LE(e,n,r)}function $e(e,t,r,n){return e[n++]=1,n+=_.encodeUTF8Into(e,t,n),e[n++]=0,n+=j.setFloat64LE(e,n,r.value)}function Re(e,t,r,n){e[n++]=13,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.toString(),i=_.encodeUTF8Into(e,o,n+4)+1;return j.setInt32LE(e,n,i),n=n+4+i-1,e[n++]=0,n}function je(e,t,r,n,o=!1,i=0,s=!1,a=!0,u){if(r.scope&&"object"==typeof r.scope){e[n++]=15,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;let l=n;const f=r.code;n+=4;const c=_.encodeUTF8Into(e,f,n+4)+1;j.setInt32LE(e,n,c),e[n+4+c-1]=0,n=n+c+4;const h=Me(e,r.scope,o,n,i+1,s,a,u);n=h-1;const g=h-l;l+=j.setInt32LE(e,l,g),e[n++]=0}else{e[n++]=13,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.code.toString(),i=_.encodeUTF8Into(e,o,n+4)+1;j.setInt32LE(e,n,i),n=n+4+i-1,e[n++]=0}return n}function Ae(e,t,r,n){e[n++]=5,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.buffer;let i=r.position;if(r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),n+=j.setInt32LE(e,n,i),e[n++]=r.sub_type,r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,n+=j.setInt32LE(e,n,i)),r.sub_type===Binary.SUBTYPE_VECTOR&&A(r),i<=16)for(let t=0;t<i;t++)e[n+t]=o[t];else e.set(o,n);return n+=r.position}function De(e,t,r,n){e[n++]=14,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;const o=_.encodeUTF8Into(e,r.value,n+4)+1;return j.setInt32LE(e,n,o),n=n+4+o-1,e[n++]=0,n}function Pe(e,t,r,n,o,i,s){e[n++]=3,n+=_.encodeUTF8Into(e,t,n),e[n++]=0;let a=n,u={$ref:r.collection||r.namespace,$id:r.oid};null!=r.db&&(u.$db=r.db),u=Object.assign(u,r.fields);const l=Me(e,u,!1,n,o+1,i,!0,s),f=l-a;return a+=j.setInt32LE(e,n,f),l}function Me(e,t,r,u,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(a(t)||i(t)||n(t)||o(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");g=new Set}g.add(t);let d=u+4;if(Array.isArray(t))for(let o=0;o<t.length;o++){const s=`${o}`;let u=t[o];"function"==typeof u?.toBSON&&(u=u.toBSON());const p=typeof u;if(void 0===u)d=Be(e,s,0,d);else if(null===u)d=Be(e,s,0,d);else if("string"===p)d=ye(e,s,u,d);else if("number"===p)d=me(e,s,u,d);else if("bigint"===p)d=we(e,s,u,d);else if("boolean"===p)d=Oe(e,s,u,d);else if("object"===p&&null==u._bsontype)d=u instanceof Date||a(u)?Se(e,s,u,d):u instanceof Uint8Array||n(u)?xe(e,s,u,d):u instanceof RegExp||i(u)?Ee(e,s,u,d):Ie(e,s,u,d,r,f,c,h,g);else if("object"===p){if(7!==u[l])throw new BSONVersionError;if("ObjectId"===u._bsontype)d=ve(e,s,u,d);else if("Decimal128"===u._bsontype)d=_e(e,s,u,d);else if("Long"===u._bsontype||"Timestamp"===u._bsontype)d=Ue(e,s,u,d);else if("Double"===u._bsontype)d=$e(e,s,u,d);else if("Code"===u._bsontype)d=je(e,s,u,d,r,f,c,h,g);else if("Binary"===u._bsontype)d=Ae(e,s,u,d);else if("BSONSymbol"===u._bsontype)d=De(e,s,u,d);else if("DBRef"===u._bsontype)d=Pe(e,s,u,d,f,c,g);else if("BSONRegExp"===u._bsontype)d=Ne(e,s,u,d);else if("Int32"===u._bsontype)d=Te(e,s,u,d);else if("MinKey"===u._bsontype||"MaxKey"===u._bsontype)d=Le(e,s,u,d);else if(void 0!==u._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(u._bsontype)}`)}else"function"===p&&c&&(d=Re(e,s,u,d))}else if(t instanceof Map||s(t)){const o=t.entries();let s=!1;for(;!s;){const t=o.next();if(s=!!t.done,s)continue;const u=t.value?t.value[0]:void 0;let p=t.value?t.value[1]:void 0;"function"==typeof p?.toBSON&&(p=p.toBSON());const b=typeof p;if("string"==typeof u&&!be.has(u)){if(null!=u.match(pe))throw new BSONError("key "+u+" must not contain null bytes");if(r){if("$"===u[0])throw new BSONError("key "+u+" must not start with '$'");if(u.includes("."))throw new BSONError("key "+u+" must not contain '.'")}}if(void 0===p)!1===h&&(d=Be(e,u,0,d));else if(null===p)d=Be(e,u,0,d);else if("string"===b)d=ye(e,u,p,d);else if("number"===b)d=me(e,u,p,d);else if("bigint"===b)d=we(e,u,p,d);else if("boolean"===b)d=Oe(e,u,p,d);else if("object"===b&&null==p._bsontype)d=p instanceof Date||a(p)?Se(e,u,p,d):p instanceof Uint8Array||n(p)?xe(e,u,p,d):p instanceof RegExp||i(p)?Ee(e,u,p,d):Ie(e,u,p,d,r,f,c,h,g);else if("object"===b){if(7!==p[l])throw new BSONVersionError;if("ObjectId"===p._bsontype)d=ve(e,u,p,d);else if("Decimal128"===p._bsontype)d=_e(e,u,p,d);else if("Long"===p._bsontype||"Timestamp"===p._bsontype)d=Ue(e,u,p,d);else if("Double"===p._bsontype)d=$e(e,u,p,d);else if("Code"===p._bsontype)d=je(e,u,p,d,r,f,c,h,g);else if("Binary"===p._bsontype)d=Ae(e,u,p,d);else if("BSONSymbol"===p._bsontype)d=De(e,u,p,d);else if("DBRef"===p._bsontype)d=Pe(e,u,p,d,f,c,g);else if("BSONRegExp"===p._bsontype)d=Ne(e,u,p,d);else if("Int32"===p._bsontype)d=Te(e,u,p,d);else if("MinKey"===p._bsontype||"MaxKey"===p._bsontype)d=Le(e,u,p,d);else if(void 0!==p._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(p._bsontype)}`)}else"function"===b&&c&&(d=Re(e,u,p,d))}}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 o of Object.keys(t)){let s=t[o];"function"==typeof s?.toBSON&&(s=s.toBSON());const u=typeof s;if("string"==typeof o&&!be.has(o)){if(null!=o.match(pe))throw new BSONError("key "+o+" must not contain null bytes");if(r){if("$"===o[0])throw new BSONError("key "+o+" must not start with '$'");if(o.includes("."))throw new BSONError("key "+o+" must not contain '.'")}}if(void 0===s)!1===h&&(d=Be(e,o,0,d));else if(null===s)d=Be(e,o,0,d);else if("string"===u)d=ye(e,o,s,d);else if("number"===u)d=me(e,o,s,d);else if("bigint"===u)d=we(e,o,s,d);else if("boolean"===u)d=Oe(e,o,s,d);else if("object"===u&&null==s._bsontype)d=s instanceof Date||a(s)?Se(e,o,s,d):s instanceof Uint8Array||n(s)?xe(e,o,s,d):s instanceof RegExp||i(s)?Ee(e,o,s,d):Ie(e,o,s,d,r,f,c,h,g);else if("object"===u){if(7!==s[l])throw new BSONVersionError;if("ObjectId"===s._bsontype)d=ve(e,o,s,d);else if("Decimal128"===s._bsontype)d=_e(e,o,s,d);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)d=Ue(e,o,s,d);else if("Double"===s._bsontype)d=$e(e,o,s,d);else if("Code"===s._bsontype)d=je(e,o,s,d,r,f,c,h,g);else if("Binary"===s._bsontype)d=Ae(e,o,s,d);else if("BSONSymbol"===s._bsontype)d=De(e,o,s,d);else if("DBRef"===s._bsontype)d=Pe(e,o,s,d,f,c,g);else if("BSONRegExp"===s._bsontype)d=Ne(e,o,s,d);else if("Int32"===s._bsontype)d=Te(e,o,s,d);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)d=Le(e,o,s,d);else if(void 0!==s._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}else"function"===u&&c&&(d=Re(e,o,s,d))}}g.delete(t),e[d++]=0;const p=d-u;return u+=j.setInt32LE(e,u,p),d}const Ve={$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 Ce(e,t={}){if("number"==typeof e){const r=e<=f&&e>=c,n=e<=h&&e>=g;if(t.relaxed||t.legacy)return e;if(Number.isInteger(e)&&!Object.is(e,-0)){if(r)return new Int32(e);if(n)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 r=Object.keys(e).filter((t=>t.startsWith("$")&&null!=e[t]));for(let n=0;n<r.length;n++){const o=Ve[r[n]];if(o)return o.fromExtendedJSON(e,t)}if(null!=e.$date){const r=e.$date,n=new Date;if(t.legacy)if("number"==typeof r)n.setTime(r);else if("string"==typeof r)n.setTime(Date.parse(r));else{if("bigint"!=typeof r)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof r);n.setTime(Number(r))}else if("string"==typeof r)n.setTime(Date.parse(r));else if(Long.isLong(r))n.setTime(r.toNumber());else if("number"==typeof r&&t.relaxed)n.setTime(r);else{if("bigint"!=typeof r)throw new BSONRuntimeError("Unrecognized type for EJSON date: "+typeof r);n.setTime(Number(r))}return n}if(null!=e.$code){const t=Object.assign({},e);return e.$scope&&(t.$scope=Ce(e.$scope)),Code.fromExtendedJSON(e)}if(M(e)||e.$dbPointer){const t=e.$ref?e:e.$dbPointer;if(t instanceof DBRef)return t;const r=Object.keys(t).filter((e=>e.startsWith("$")));let n=!0;if(r.forEach((e=>{-1===["$ref","$id","$db"].indexOf(e)&&(n=!1)})),n)return DBRef.fromExtendedJSON(t)}return e}function Fe(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function ke(e,t){if(e instanceof Map||s(e)){const r=Object.create(null);for(const[t,n]of e){if("string"!=typeof t)throw new BSONError("Can only serialize maps with string keys");r[t]=n}return ke(r,t)}if(("object"==typeof e||"function"==typeof e)&&null!==e){const r=t.seenObjects.findIndex((t=>t.obj===e));if(-1!==r){const e=t.seenObjects.map((e=>e.propertyName)),n=e.slice(0,r).map((e=>`${e} -> `)).join(""),o=e[r],i=" -> "+e.slice(r+1,e.length-1).map((e=>`${e} -> `)).join(""),s=e[e.length-1],a=" ".repeat(n.length+o.length/2),u="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${n}${o}${i}${s}\n ${a}\\${u}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,r)=>{t.seenObjects.push({propertyName:`index ${r}`,obj:null});try{return ke(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return t.ignoreUndefined?void 0:null;if(e instanceof Date||a(e)){const r=e.getTime(),n=r>-1&&r<2534023188e5;return t.legacy?t.relaxed&&n?{$date:e.getTime()}:{$date:Fe(e)}:t.relaxed&&n?{$date:Fe(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 r=e.flags;if(void 0===r){const t=e.toString().match(/[gimuy]*$/);t&&(r=t[0])}return new BSONRegExp(e.source,r).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 r=e._bsontype;if(void 0===r){const r={};for(const n of Object.keys(e)){t.seenObjects.push({propertyName:n,obj:null});try{const o=ke(e[n],t);"__proto__"===n?Object.defineProperty(r,n,{value:o,writable:!0,enumerable:!0,configurable:!0}):r[n]=o}finally{t.seenObjects.pop()}}return r}if(null!=e&&"object"==typeof e&&"string"==typeof e._bsontype&&7!==e[l])throw new BSONVersionError;if(function(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"string"==typeof e._bsontype}(e)){let n=e;if("function"!=typeof n.toExtendedJSON){const t=ze[e._bsontype];if(!t)throw new BSONError("Unrecognized or invalid _bsontype: "+e._bsontype);n=t(n)}return"Code"===r&&n.scope?n=new Code(n.code,ke(n.scope,t)):"DBRef"===r&&n.oid&&(n=new DBRef(ke(n.collection,t),ke(n.oid,t),ke(n.db,t),ke(n.fields,t))),n.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof r)}(e,t):e}const ze={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 Je(e,t){const r={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 Ce(t,r)}))}function Ye(e,t,r,n){null!=r&&"object"==typeof r&&(n=r,r=0),null==t||"object"!=typeof t||Array.isArray(t)||(n=t,t=void 0,r=0);const o=ke(e,Object.assign({relaxed:!0,legacy:!1},n,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,r)}const qe=Object.create(null);qe.parse=Je,qe.stringify=Ye,qe.serialize=function(e,t){return t=t||{},JSON.parse(Ye(e,t))},qe.deserialize=function(e,t){return t=t||{},Je(JSON.stringify(e),t)},Object.freeze(qe);const He=1,Ke=2,We=3,Ze=4,Ge=5,Xe=6,Qe=7,et=8,tt=9,rt=10,nt=11,ot=12,it=13,st=14,at=15,ut=16,lt=17,ft=18,ct=19,ht=255,gt=127;function dt(e,t){try{return j.getNonnegativeInt32LE(e,t)}catch(e){throw new BSONOffsetError("BSON size cannot be negative",t,{cause:e})}}function pt(e,t){let r=t;for(;0!==e[r];r++);if(r===e.length-1)throw new BSONOffsetError("Null terminator not found",t);return r}const bt=Object.create(null);bt.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 r=dt(e,t);if(r>e.length-t)throw new BSONOffsetError(`Parsed documentSize (${r} bytes) does not match input length (${e.length} bytes)`,t);if(0!==e[t+r-1])throw new BSONOffsetError("BSON documents must end in 0x00",t+r);const n=[];let o=t+4;for(;o<=r+t;){const i=e[o];if(o+=1,0===i){if(o-t!==r)throw new BSONOffsetError("Invalid 0x00 type byte",o);break}const s=o,a=pt(e,o)-s;let u;if(o+=a+1,i===He||i===ft||i===tt||i===lt)u=8;else if(i===ut)u=4;else if(i===Qe)u=12;else if(i===ct)u=16;else if(i===et)u=1;else if(i===rt||i===Xe||i===gt||i===ht)u=0;else if(i===nt)u=pt(e,pt(e,o)+1)+1-o;else if(i===We||i===Ze||i===at)u=dt(e,o);else{if(i!==Ke&&i!==Ge&&i!==ot&&i!==it&&i!==st)throw new BSONOffsetError(`Invalid 0x${i.toString(16).padStart(2,"0")} type byte`,o);u=dt(e,o)+4,i===Ge&&(u+=1),i===ot&&(u+=12)}if(u>r)throw new BSONOffsetError("value reports length larger than document",o);n.push([i,s,a,o,u]),o+=u}return n},bt.ByteUtils=_,bt.NumberUtils=j,Object.freeze(bt);const yt=17825792;let mt=_.allocate(yt);function wt(e){mt.length<e&&(mt=_.allocate(e))}function Bt(e,t={}){const r="boolean"==typeof t.checkKeys&&t.checkKeys,n="boolean"==typeof t.serializeFunctions&&t.serializeFunctions,o="boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined,i="number"==typeof t.minInternalBufferSize?t.minInternalBufferSize:yt;mt.length<i&&(mt=_.allocate(i));const s=Me(mt,e,r,0,0,n,o,null),a=_.allocateUnsafe(s);return a.set(mt.subarray(0,s),0),a}function Ot(e,t,r={}){const n="boolean"==typeof r.checkKeys&&r.checkKeys,o="boolean"==typeof r.serializeFunctions&&r.serializeFunctions,i="boolean"!=typeof r.ignoreUndefined||r.ignoreUndefined,s="number"==typeof r.index?r.index:0,a=Me(mt,e,n,0,0,o,i,null);return t.set(mt.subarray(0,a),s),s+a-1}function St(e,t={}){return he(_.toLocalBufferType(e),t)}function Et(e,t={}){return ae(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function Nt(e,t,r,n,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),a=_.toLocalBufferType(e);let u=t;for(let e=0;e<r;e++){const t=j.getInt32LE(a,u);s.index=u,n[o+e]=he(a,s),u+=t}return u}var Lt=Object.freeze({__proto__:null,BSONError,BSONOffsetError,BSONRegExp,BSONRuntimeError,BSONSymbol,BSONType:b,BSONValue,BSONVersionError,Binary,ByteUtils:_,Code,DBRef,Decimal128,Double,EJSON:qe,Int32,Long,MaxKey,MinKey,NumberUtils:j,ObjectId,Timestamp,UUID,bsonType:U,calculateObjectSize:Et,deserialize:St,deserializeStream:Nt,onDemand:bt,serialize:Bt,serializeWithBufferAndIndex:Ot,setInternalBufferSize:wt});t.BSON=Lt,t.BSONError=BSONError,t.BSONOffsetError=BSONOffsetError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=b,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.ByteUtils=_,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=qe,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.NumberUtils=j,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.bsonType=U,t.calculateObjectSize=Et,t.deserialize=St,t.deserializeStream=Nt,t.onDemand=bt,t.serialize=Bt,t.serializeWithBufferAndIndex=Ot,t.setInternalBufferSize=wt},795(e,t,r){let n,o,i=r(982),{urlAlphabet:s}=r(29),a=e=>{!n||n.length<e?(n=Buffer.allocUnsafe(128*e),i.randomFillSync(n),o=0):o+e>n.length&&(i.randomFillSync(n),o=0),o+=e},u=e=>(a(e|=0),n.subarray(o-e,o)),l=(e,t,r)=>{let n=(2<<31-Math.clz32(e.length-1|1))-1,o=Math.ceil(1.6*n*t/e.length);return(i=t)=>{let s="";for(;;){let t=r(o),a=o;for(;a--;)if(s+=e[t[a]&n]||"",s.length===i)return s}}};e.exports={nanoid:(e=21)=>{a(e|=0);let t="";for(let r=o-e;r<o;r++)t+=s[63&n[r]];return t},customAlphabet:(e,t=21)=>l(e,t,u),customRandom:l,urlAlphabet:s,random:u}},29(e){e.exports={urlAlphabet:"useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"}}},t={},function r(n){var o=t[n];if(void 0!==o){if(void 0!==o.error)throw o.error;return o.exports}var i=t[n]={exports:{}},s=!0;try{e[n].call(i.exports,i,i.exports,r),s=!1}finally{s&&delete t[n]}return i.exports}(783);var e,t}));
|