@mongosh/node-runtime-worker-thread 1.8.2 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AUTHORS +2 -0
- package/dist/child-process-proxy.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/report.html +2 -2
- package/dist/serializer.d.ts +2 -2
- package/dist/serializer.js +1 -1
- package/dist/serializer.js.map +1 -1
- package/dist/worker-runtime.js +38 -38
- package/dist/worker-runtime.js.LICENSE.txt +251 -0
- package/dist/worker-runtime.js.map +1 -1
- package/package.json +7 -7
- package/src/child-process-proxy.spec.ts +2 -1
- package/src/index.spec.ts +22 -15
- package/src/index.ts +1 -1
- package/src/serializer.spec.ts +5 -0
- package/src/serializer.ts +3 -3
- package/src/worker-runtime.spec.ts +17 -16
- package/src/worker-runtime.ts +1 -1
package/AUTHORS
CHANGED
|
@@ -6,3 +6,5 @@ Maurizio Casimirri <maurizio.cas@gmail.com>
|
|
|
6
6
|
Alena Khineika <alena.khineika@gmail.com>
|
|
7
7
|
Leonardo Rossi <leonardo.rossi@gmail.com>
|
|
8
8
|
Le Roux Bodenstein <lerouxb@gmail.com>
|
|
9
|
+
Martin Rodriguez Reboredo <yakoyoku@gmail.com>
|
|
10
|
+
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
|
|
@@ -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={558:(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(130),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||"*",u=t.getMessageData||function(e){return e.data};return function(){var t={sender:"postmsg-rpc/client",id:(0,i.default)(),func:e,args:Array.from(arguments)},a=void 0,l=new Promise((function(i,l){var f=function r(){var o=u.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)}};a=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 a()},l}}},246:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(558);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(624);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},624:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(r=r||{}).addListener||window.addEventListener,o=r.removeListener||window.removeEventListener,i=r.postMessage||window.postMessage,s=r.targetOrigin||"*",u=r.getMessageData||function(e){return e.data},a=r.isCallback||!1,l=function(){var r=u.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(a)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)}}}},130:(e,t,r)=>{"use strict";e.exports=r(252)},173:(e,t,r)=>{"use strict";var n,o,i,s=r(514),u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function a(){i=!1}function l(e){if(e){if(e!==n){if(e.length!==u.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,r){return t!==r.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. These characters were not unique: "+t.join(", "));n=e,a()}}else n!==u&&(n=u,a())}function f(){return i||(i=function(){n||l(u);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||u},characters:function(e){return l(e),n},seed:function(e){s.seed(e),o!==e&&(a(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},89:(e,t,r)=>{"use strict";var n,o,i=r(943),s=(r(173),1567752802062),u=7;e.exports=function(e){var t="",r=Math.floor(.001*(Date.now()-s));return r===o?n++:(n=0,o=r),t+=i(u),t+=i(e),n>0&&(t+=i(n)),t+=i(r)}},943:(e,t,r)=>{"use strict";var n=r(173),o=r(908),i=r(137);e.exports=function(e){for(var t,r=0,s="";!t;)s+=i(o,n.get(),1),t=e<Math.pow(16,r+1),r++;return s}},252:(e,t,r)=>{"use strict";var n=r(173),o=r(89),i=r(56),s=r(696)||0;function u(){return o(s)}e.exports=u,e.exports.generate=u,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},56:(e,t,r)=>{"use strict";var n=r(173);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+n.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},908:(e,t,r)=>{e.exports=r(701)},514:e=>{"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},696:(e,t,r)=>{"use strict";var n=r(1),o=0;!n.isMaster&&n.worker&&(o=n.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},137:e=>{e.exports=function(e,t,r){for(var n=(2<<31-Math.clz32(t.length-1|1))-1,o=Math.ceil(1.6*n*r/t.length),i="";;)for(var s=e(o),u=o;u--;)if((i+=t[s[u]&n]||"").length===+r)return i}},701:(e,t,r)=>{var n=r(113);if(n.randomFillSync){var o={};e.exports=function(e){var t=o[e];return t||(t=Buffer.allocUnsafe(e),e<=255&&(o[e]=t)),n.randomFillSync(t)}}else e.exports=n.randomBytes},754:function(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});const o=r(361),i=r(267),s=n(r(17)),u=r(369),a=r(59),l=process.env.WORKER_RUNTIME_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING||s.default.resolve(__dirname,"worker-runtime.js"),f=new i.Worker(l,{env:i.SHARE_ENV}),c=(async()=>{await Promise.race([(async()=>{let e;for(;[e]=await(0,o.once)(f,"message");)if("ready"===e)return})(),(async()=>{const[e]=await(0,o.once)(f,"error");if(e)throw e.message=`Worker thread failed to start with the following error: ${e.message}`,e})()])})();process.setMaxListeners(25),f.setMaxListeners(25);let g=null;const{interrupt:h}=(0,u.createCaller)(["interrupt"],f),p=Object.assign((0,u.createCaller)(["init","evaluate","getCompletions","getShellPrompt"],f),{interrupt:()=>g?((0,a.interrupt)(g),!0):h()});Object.keys(p).forEach((e=>{var t;p[e]=(t=p[e],new Proxy(t,{apply:async(e,t,r)=>(await c,e.call(t,...Array.from(r)))}))})),(0,u.exposeAll)(p,process);const d=Object.assign((0,u.createCaller)(["onPrint","onPrompt","getConfig","setConfig","resetConfig","validateConfig","listConfigOptions","onClearCommand","onExit"],process),{onRunInterruptible(e){g=e}});(0,u.exposeAll)(d,f);const b=(0,u.createCaller)(["emit","on"],process);(0,u.exposeAll)(b,f),process.once("disconnect",(()=>process.exit())),process.nextTick((()=>{var e;null===(e=process.send)||void 0===e||e.call(process,"ready")}))},369:function(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.createCaller=t.exposeAll=t.cancel=t.close=t.removeTrailingUndefined=t.deserialize=t.serialize=void 0;const o=n(r(655)),i=r(246),s=r(568);function u(e){return`data:;base64,${o.default.serialize(e).toString("base64")}`}function a(e){return/^data:;base64,.+/.test(e)?o.default.deserialize(Buffer.from(e.replace("data:;base64,",""),"base64")):e}var l;function f(e){return e&&"object"==typeof e&&"id"in e&&"sender"in e}function c(e){return f(e)&&"postmsg-rpc/server"===e.sender}function g(e){return f(e)&&"postmsg-rpc/client"===e.sender}function h(e){if(Array.isArray(e))for(e=[...e];e.length>0&&void 0===e[e.length-1];)e.pop();return e}function p(e){return{addListener:e.on.bind(e),removeListener:e.off.bind(e),postMessage(t){if(g(t)&&Array.isArray(t.args)&&(t.args=u(h(t.args))),c(t))try{t.res=u(t.res)}catch(e){t.res=u({type:l.Error,payload:(0,s.serializeError)(e)})}return function(e,t){"postMessage"in e&&"function"==typeof e.postMessage&&e.postMessage(t),"send"in e&&"function"==typeof e.send&&e.send(t)}(e,t)},getMessageData:e=>(g(e)&&e.args&&"string"==typeof e.args&&(e.args=a(e.args)),c(e)&&"string"==typeof e.res&&(e.res=a(e.res)),e)}}t.serialize=u,t.deserialize=a,function(e){e[e.Message=0]="Message",e[e.Error=1]="Error"}(l||(l={})),t.removeTrailingUndefined=h,t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel"),t.exposeAll=function(e,r){return Object.entries(e).forEach((([e,t])=>{const{close:n}=(0,i.expose)(e,(async(...e)=>{try{return{type:l.Message,payload:await t(...e)}}catch(e){return{type:l.Error,payload:(0,s.serializeError)(e)}}}),p(r));t.close=n})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,r,n={}){const o={},u=new Set;return e.forEach((e=>{const t=(0,i.caller)(e,p(r));o[e]=async(...r)=>{var o;const i="function"==typeof n[e]?null===(o=n[e])||void 0===o?void 0:o.call(n,...r):r,a=t(...i);u.add(a);const f=await a;if(u.delete(a),(c=f)&&"object"==typeof c&&c.type===l.Error)throw(0,s.deserializeError)(f.payload);var c;return f.payload}})),Object.defineProperty(o,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),o}},568:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deserializeConnectOptions=t.serializeConnectOptions=t.deserializeEvaluationResult=t.serializeEvaluationResult=t.SerializedResultTypes=t.deserializeError=t.serializeError=void 0;const n=r(837),o=r(429);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").reduce(((t,r)=>(t[r]=e[r],t)),{})}function s(e){return Object.assign(new Error,e)}var u;t.serializeError=i,t.deserializeError=s,function(e){e.SerializedErrorResult="SerializedErrorResult",e.InspectResult="InspectResult",e.SerializedShellApiResult="SerializedShellApiResult"}(u=t.SerializedResultTypes||(t.SerializedResultTypes={})),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:u.SerializedErrorResult,printable:i(t),source:r}:null===e?{type:u.InspectResult,printable:(0,n.inspect)(t),source:r}:{type:u.SerializedShellApiResult,printable:{origType:e,serializedValue:o.EJSON.serialize(t)}};var s},t.deserializeEvaluationResult=function({type:e,printable:t,source:r}){return e===u.SerializedErrorResult?{type:e,printable:s(t),source:r}:e===u.SerializedShellApiResult?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:r}:{type:e,printable:t,source:r}};const a=["schemaMap","encryptedFieldsMap"];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}},59:e=>{"use strict";e.exports=require("interruptor")},1:e=>{"use strict";e.exports=require("cluster")},113:e=>{"use strict";e.exports=require("crypto")},361:e=>{"use strict";e.exports=require("events")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")},655:e=>{"use strict";e.exports=require("v8")},267:e=>{"use strict";e.exports=require("worker_threads")},429:(e,t,r)=>{"use strict";const n=5,o=2147483647,i=-2147483648,s=Math.pow(2,63)-1,u=-Math.pow(2,63),a=Math.pow(2,53),l=-Math.pow(2,53),f=1,c=2,g=3,h=4,p=5,d=6,b=7,y=8,m=9,w=10,B=11,S=12,O=13,N=14,E=15,x=16,L=17,_=18,v=19,I=255,U=127,$=0,j=4,T=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){super(e)}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 ${n}.0 or later`)}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}function D(e){return A.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const A={toLocalBufferType(e){if(Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength);const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return Buffer.from(e);throw new BSONError(`Cannot create Buffer from ${String(e)}`)},allocate:e=>Buffer.alloc(e),equals:(e,t)=>A.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),toBase64:e=>A.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>A.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>A.toLocalBufferType(e).toString("hex"),fromUTF8:e=>Buffer.from(e,"utf8"),toUTF8:e=>A.toLocalBufferType(e).toString("utf8"),utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into:(e,t,r)=>A.toLocalBufferType(e).write(t,r,void 0,"utf8"),randomBytes:(()=>{try{return r(113).randomBytes}catch{return D}})()};function R(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return F.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const M=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(F.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 R})(),z=/(\d|[a-f])/i,F={toLocalBufferType(e){const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("Uint8Array"===t)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return new Uint8Array(e);throw new BSONError(`Cannot make a Uint8Array from ${String(e)}`)},allocate(e){if("number"!=typeof e)throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},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))),toBase64:e=>btoa(F.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(!z.test(n))break;if(!z.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(""),fromUTF8:e=>(new TextEncoder).encode(e),toUTF8:e=>new TextDecoder("utf8",{fatal:!1}).decode(e),utf8ByteLength:e=>F.fromUTF8(e).byteLength,encodeUTF8Into(e,t,r){const n=F.fromUTF8(t);return e.set(n,r),n.byteLength},randomBytes:M},V="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?A:F;class BSONDataView extends DataView{static fromUint8Array(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}}const C=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i,J=e=>"string"==typeof e&&C.test(e),q=e=>{if(!J(e))throw new BSONError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');const t=e.replace(/-/g,"");return V.fromHex(t)};function H(e,t=!0){return t?[V.toHex(e.subarray(0,4)),V.toHex(e.subarray(4,6)),V.toHex(e.subarray(6,8)),V.toHex(e.subarray(8,10)),V.toHex(e.subarray(10,16))].join("-"):V.toHex(e)}function P(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function k(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function K(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function Y(e){return"[object Map]"===Object.prototype.toString.call(e)}function Z(e){return"[object Date]"===Object.prototype.toString.call(e)}class BSONValue{get[Symbol.for("@@mdb.bson.version")](){return n}}class Binary extends BSONValue{get _bsontype(){return"Binary"}constructor(e,t){if(super(),!(null==e||"string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Array.isArray(e)))throw new BSONError("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=t??Binary.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=V.allocate(Binary.BUFFER_SIZE),this.position=0):("string"==typeof e?this.buffer=V.fromISO88591(e):Array.isArray(e)?this.buffer=V.fromNumberArray(e):this.buffer=V.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=V.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=V.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(V.toLocalBufferType(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position;else if("string"==typeof e){const r=V.fromISO88591(e);this.buffer.set(r,t),this.position=t+e.length>this.position?t+e.length:this.position}}read(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)}value(e){return(e=!!e)&&this.buffer.length===this.position?this.buffer:e?this.buffer.slice(0,this.position):V.toISO88591(this.buffer.subarray(0,this.position))}length(){return this.position}toJSON(){return V.toBase64(this.buffer)}toString(e){return"hex"===e?V.toHex(this.buffer):"base64"===e?V.toBase64(this.buffer):V.toUTF8(this.buffer)}toExtendedJSON(e){e=e||{};const t=V.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.slice(0,this.position));throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(e,t){return new Binary(V.fromHex(e),t)}static createFromBase64(e,t){return new Binary(V.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=V.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(n=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=V.fromBase64(e.$binary.base64)):"$uuid"in e&&(n=4,r=q(e.$uuid)),!r)throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return n===j?new UUID(r):new Binary(r,n)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`Binary.createFromBase64("${V.toBase64(this.buffer.subarray(0,this.position))}", ${this.sub_type})`}}Binary.BSON_BINARY_SUBTYPE_DEFAULT=0,Binary.BUFFER_SIZE=256,Binary.SUBTYPE_DEFAULT=0,Binary.SUBTYPE_FUNCTION=1,Binary.SUBTYPE_BYTE_ARRAY=2,Binary.SUBTYPE_UUID_OLD=3,Binary.SUBTYPE_UUID=4,Binary.SUBTYPE_MD5=5,Binary.SUBTYPE_ENCRYPTED=6,Binary.SUBTYPE_COLUMN=7,Binary.SUBTYPE_USER_DEFINED=128;class UUID extends Binary{constructor(e){let t,r;if(null==e)t=UUID.generate();else if(e instanceof UUID)t=V.toLocalBufferType(new Uint8Array(e.buffer)),r=e.__id;else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=V.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=q(e)}super(t,j),this.__id=r}get id(){return this.buffer}set id(e){this.buffer=e,UUID.cacheHexString&&(this.__id=H(e))}toHexString(e=!0){if(UUID.cacheHexString&&this.__id)return this.__id;const t=H(this.id,e);return UUID.cacheHexString&&(this.__id=t),t}toString(e){return"hex"===e?V.toHex(this.id):"base64"===e?V.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return V.equals(e.id,this.id);try{return V.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=V.randomBytes(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}static isValid(e){return!!e&&(e instanceof UUID||("string"==typeof e?J(e):!!k(e)&&16===e.byteLength&&64==(240&e[6])&&128==(128&e[8])))}static createFromHexString(e){const t=q(e);return new UUID(t)}static createFromBase64(e){return new UUID(V.fromBase64(e))}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new UUID("${this.toHexString()}")`}}class Code extends BSONValue{get _bsontype(){return"Code"}constructor(e,t){super(),this.code=e.toString(),this.scope=t??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(e){return new Code(e.$code,e.$scope)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){const e=this.toJSON();return`new Code("${String(e.code)}"${null!=e.scope?`, ${JSON.stringify(e.scope)}`:""})`}}function W(e){return null!=e&&"object"==typeof e&&"$id"in e&&null!=e.$id&&"$ref"in e&&"string"==typeof e.$ref&&(!("$db"in e)||"$db"in e&&"string"==typeof e.$db)}class DBRef extends BSONValue{get _bsontype(){return"DBRef"}constructor(e,t,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)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){const e=void 0===this.oid||void 0===this.oid.toString?this.oid:this.oid.toString();return`new DBRef("${this.namespace}", new ObjectId("${String(e)}")${this.db?`, "${this.db}"`:""})`}}let G;try{G=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 X=4294967296,Q=0x10000000000000000,ee=Q/2,te={},re={},ne=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(e=0,t,r){super(),"bigint"==typeof e?Object.assign(this,Long.fromBigInt(e,!!t)):"string"==typeof e?Object.assign(this,Long.fromString(e,!!t)):(this.low=0|e,this.high=0|t,this.unsigned=!!r)}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=re[e],n)?n:(r=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(re[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=te[e],n)?n:(r=Long.fromBits(e,e<0?-1:0,!1),o&&(te[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>=Q)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-ee)return Long.MIN_VALUE;if(e+1>=ee)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%X|0,e/X|0,t)}static fromBigInt(e,t){return Long.fromString(e.toString(),t)}static fromString(e,t,r){if(0===e.length)throw new BSONError("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return Long.ZERO;if("number"==typeof t?(r=t,t=!1):t=!!t,(r=r||10)<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 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,u=e.low>>>16;let a=0,l=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=n+u,l+=f>>>16,f&=65535,l+=r+s,a+=l>>>16,l&=65535,a+=t+i,a&=65535,Long.fromBits(f<<16|c,a<<16|l,this.unsigned)}and(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low&e.low,this.high&e.high,this.unsigned)}compare(e){if(Long.isLong(e)||(e=Long.fromValue(e)),this.eq(e))return 0;const t=this.isNegative(),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(G){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?G.div_u:G.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,G.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),u=s.mul(e);for(;u.isNegative()||u.gt(r);)t-=i,s=Long.fromNumber(t,this.unsigned),u=s.mul(e);s.isZero()&&(s=Long.ONE),n=n.add(s),r=r.sub(u)}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&&0==(e&1<<t);t--);return 0!==this.high?t+33:t+1}greaterThan(e){return this.comp(e)>0}gt(e){return this.greaterThan(e)}greaterThanOrEqual(e){return this.comp(e)>=0}gte(e){return this.greaterThanOrEqual(e)}ge(e){return this.greaterThanOrEqual(e)}isEven(){return 0==(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return 1==(1&this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(e){return this.comp(e)<0}lt(e){return this.lessThan(e)}lessThanOrEqual(e){return this.comp(e)<=0}lte(e){return this.lessThanOrEqual(e)}modulo(e){if(Long.isLong(e)||(e=Long.fromValue(e)),G){const t=(this.unsigned?G.rem_u:G.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,G.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)),G){const t=G.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,G.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,u=e.low>>>16,a=65535&e.low;let l=0,f=0,c=0,g=0;return g+=o*a,c+=g>>>16,g&=65535,c+=n*a,f+=c>>>16,c&=65535,c+=o*u,f+=c>>>16,c&=65535,f+=r*a,l+=f>>>16,f&=65535,f+=n*u,l+=f>>>16,f&=65535,f+=o*s,l+=f>>>16,f&=65535,l+=t*a+r*u+n*s+o*i,l&=65535,Long.fromBits(c<<16|g,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)*X+(this.low>>>0):this.high*X+(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(!ne.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}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Long("${this.toString()}"${this.unsigned?", true":""})`}}Long.TWO_PWR_24=Long.fromInt(1<<24),Long.MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0),Long.ZERO=Long.fromInt(0),Long.UZERO=Long.fromInt(0,!0),Long.ONE=Long.fromInt(1),Long.UONE=Long.fromInt(1,!0),Long.NEG_ONE=Long.fromInt(-1),Long.MAX_VALUE=Long.fromBits(-1,2147483647,!1),Long.MIN_VALUE=Long.fromBits(0,-2147483648,!1);const oe=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,ie=/^(\+|-)?(Infinity|inf)$/i,se=/^(\+|-)?NaN$/i,ue=6111,ae=-6176,le=V.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),fe=V.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ce=V.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ge=/^([-+])?(\d+)?$/;function he(e){return!isNaN(parseInt(e,10))}function pe(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 de(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!k(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){let t=!1,r=!1,n=!1,o=0,i=0,s=0,u=0,a=0;const l=[0];let f=0,c=0,g=0,h=0,p=0,d=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(oe),S=e.match(ie),O=e.match(se);if(!B&&!S&&!O||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&&de(e,"missing exponent power"),r&&void 0===t&&de(e,"missing exponent base"),void 0===r&&(n||o)&&de(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(t="-"===e[w++]),!he(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(t?fe:ce);if("N"===e[w])return new Decimal128(le)}for(;he(e[w])||"."===e[w];)"."!==e[w]?(f<34&&("0"!==e[w]||n)&&(n||(a=i),n=!0,l[c++]=parseInt(e[w],10),f+=1),n&&(s+=1),r&&(u+=1),i+=1,w+=1):(r&&de(e,"contains multiple periods"),r=!0,w+=1);if(r&&!i)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(ge);if(!t||!t[2])return new Decimal128(le);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(le);if(g=0,f){if(h=f-1,o=s,1!==o)for(;0===l[a+o-1];)o-=1}else g=0,h=0,l[0]=0,s=1,f=1,o=0;for(p<=u&&u-p>16384?p=ae:p-=u;p>ue;){if(h+=1,h-g>34){if(l.join("").match(/^0+$/)){p=ue;break}de(e,"overflow")}p-=1}for(;p<ae||f<s;){if(0===h&&o<f){p=ae,o=0;break}if(f<s?s-=1:h-=1,p<ue)p+=1;else{if(l.join("").match(/^0+$/)){p=ue;break}de(e,"overflow")}}if(h-g+1<o){let n=i;r&&(a+=1,n+=1),t&&(a+=1,n+=1);const o=parseInt(e[a+h+1],10);let s=0;if(o>=5&&(s=1,5===o))for(s=l[h]%2==1?1:0,d=a+h+2;d<n;d++)if(parseInt(e[d],10)){s=1;break}if(s){let e=h;for(;e>=0;e--)if(++l[e]>9&&(l[e]=0,0===e)){if(!(p<ue))return new Decimal128(t?fe:ce);p+=1,l[e]=1}}}if(b=Long.fromNumber(0),y=Long.fromNumber(0),0===o)b=Long.fromNumber(0),y=Long.fromNumber(0);else if(h-g<17){let e=g;for(y=Long.fromNumber(l[e++]),b=new Long(0,0);e<=h;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(l[e]))}else{let e=g;for(b=Long.fromNumber(l[e++]);e<=h-17;e++)b=b.multiply(Long.fromNumber(10)),b=b.add(Long.fromNumber(l[e]));for(y=Long.fromNumber(l[e++]);e<=h;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(l[e]))}const N=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),u=r.multiply(i);const a=n.multiply(o);let l=n.multiply(i);return s=s.add(u.shiftRightUnsigned(32)),u=new Long(u.getLowBits(),0).add(a).add(l.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),l=u.shiftLeft(32).add(new Long(l.getLowBits(),0)),{high:s,low:l}}(b,Long.fromString("100000000000000000"));N.low=N.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}(N.low,y)&&(N.high=N.high.add(Long.fromNumber(1))),m=p+6176;const E={low:Long.fromNumber(0),high:Long.fromNumber(0)};N.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))?(E.high=E.high.or(Long.fromNumber(3).shiftLeft(61)),E.high=E.high.or(Long.fromNumber(m).and(Long.fromNumber(16383).shiftLeft(47))),E.high=E.high.or(N.high.and(Long.fromNumber(0x7fffffffffff)))):(E.high=E.high.or(Long.fromNumber(16383&m).shiftLeft(49)),E.high=E.high.or(N.high.and(Long.fromNumber(562949953421311)))),E.low=N.low,t&&(E.high=E.high.or(Long.fromString("9223372036854775808")));const x=V.allocate(16);return w=0,x[w++]=255&E.low.low,x[w++]=E.low.low>>8&255,x[w++]=E.low.low>>16&255,x[w++]=E.low.low>>24&255,x[w++]=255&E.low.high,x[w++]=E.low.high>>8&255,x[w++]=E.low.high>>16&255,x[w++]=E.low.high>>24&255,x[w++]=255&E.high.low,x[w++]=E.high.low>>8&255,x[w++]=E.high.low>>16&255,x[w++]=E.high.low>>24&255,x[w++]=255&E.high.high,x[w++]=E.high.high>>8&255,x[w++]=E.high.high>>16&255,x[w++]=E.high.high>>24&255,new Decimal128(x)}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,u=!1,a={parts:[0,0,0,0]};const l=[];s=0;const f=this.bytes,c=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,g=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,p=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new Long(c,g),new Long(h,p)).lessThan(Long.ZERO)&&l.push("-");const d=p>>26&31;if(d>>3==3){if(30===d)return l.join("")+"Infinity";if(31===d)return"NaN";e=p>>15&16383,n=8+(p>>14&1)}else n=p>>14&7,e=p>>17&16383;const b=e-6176;if(a.parts[0]=(16383&p)+((15&n)<<14),a.parts[1]=h,a.parts[2]=g,a.parts[3]=c,0===a.parts[0]&&0===a.parts[1]&&0===a.parts[2]&&0===a.parts[3])u=!0;else for(i=3;i>=0;i--){let e=0;const t=pe(a);if(a=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(u)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)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Decimal128("${this.toString()}")`}}class Double extends BSONValue{get _bsontype(){return"Double"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=+e}valueOf(){return this.value}toJSON(){return this.value}toString(e){return this.value.toString(e)}toExtendedJSON(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(e,t){const r=parseFloat(e.$numberDouble);return t&&t.relaxed?r:new Double(r)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Double(${this.toExtendedJSON().$numberDouble})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}valueOf(){return this.value}toString(e){return this.value.toString(e)}toJSON(){return this.value}toExtendedJSON(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new Int32(e.$numberInt)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Int32(${this.valueOf()})`}}class MaxKey extends BSONValue{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new MaxKey}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return"new MaxKey()"}}class MinKey extends BSONValue{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new MinKey}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return"new MinKey()"}}const be=new RegExp("^[0-9a-fA-F]{24}$");let ye=null;const me=Symbol("id");class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}constructor(e){let t;if(super(),"object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new BSONError("Argument passed in must have an id that is of type string or Buffer");t="toHexString"in e&&"function"==typeof e.toHexString?V.fromHex(e.toHexString()):e.id}else t=e;if(null==t||"number"==typeof t)this[me]=ObjectId.generate("number"==typeof t?t:void 0);else if(ArrayBuffer.isView(t)&&12===t.byteLength)this[me]=V.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(12===t.length){const e=V.fromUTF8(t);if(12!==e.byteLength)throw new BSONError("Argument passed in must be a string of 12 bytes");this[me]=e}else{if(24!==t.length||!be.test(t))throw new BSONError("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");this[me]=V.fromHex(t)}}ObjectId.cacheHexString&&(this.__id=V.toHex(this.id))}get id(){return this[me]}set id(e){this[me]=e,ObjectId.cacheHexString&&(this.__id=V.toHex(e))}toHexString(){if(ObjectId.cacheHexString&&this.__id)return this.__id;const e=V.toHex(this.id);return ObjectId.cacheHexString&&!this.__id&&(this.__id=e),e}static getInc(){return ObjectId.index=(ObjectId.index+1)%16777215}static generate(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));const t=ObjectId.getInc(),r=V.allocate(12);return BSONDataView.fromUint8Array(r).setUint32(0,e,!1),null===ye&&(ye=V.randomBytes(5)),r[4]=ye[0],r[5]=ye[1],r[6]=ye[2],r[7]=ye[3],r[8]=ye[4],r[11]=255&t,r[10]=t>>8&255,r[9]=t>>16&255,r}toString(e){return"base64"===e?V.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(null==e)return!1;if(e instanceof ObjectId)return this[me][11]===e[me][11]&&V.equals(this[me],e[me]);if("string"==typeof e&&ObjectId.isValid(e)&&12===e.length&&k(this.id))return V.equals(this.id,V.fromISO88591(e));if("string"==typeof e&&ObjectId.isValid(e)&&24===e.length)return e.toLowerCase()===this.toHexString();if("string"==typeof e&&ObjectId.isValid(e)&&12===e.length)return V.equals(V.fromUTF8(e),this.id);if("object"==typeof e&&"toHexString"in e&&"function"==typeof e.toHexString){const t=e.toHexString(),r=this.toHexString().toLowerCase();return"string"==typeof t&&t.toLowerCase()===r}return!1}getTimestamp(){const e=new Date,t=BSONDataView.fromUint8Array(this.id).getUint32(0,!1);return e.setTime(1e3*Math.floor(t)),e}static createPk(){return new ObjectId}static createFromTime(e){const t=V.fromNumberArray([0,0,0,0,0,0,0,0,0,0,0,0]);return BSONDataView.fromUint8Array(t).setUint32(0,e,!1),new ObjectId(t)}static createFromHexString(e){if(24!==e?.length)throw new BSONError("hex string must be 24 characters");return new ObjectId(V.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(V.fromBase64(e))}static isValid(e){if(null==e)return!1;try{return new ObjectId(e),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(e){return new ObjectId(e.$oid)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new ObjectId("${this.toHexString()}")`}}function we(e,t,r){let n=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)n+=Be(o.toString(),e[o],t,!0,r);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))n+=Be(o,e[o],t,!1,r)}return n}function Be(e,t,r=!1,s=!1,u=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+V.utf8ByteLength(e)+1+4+V.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=l&&t<=a&&t>=i&&t<=o?(null!=e?V.utf8ByteLength(e)+1:0)+5:(null!=e?V.utf8ByteLength(e)+1:0)+9;case"undefined":return s||!u?(null!=e?V.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?V.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&t[Symbol.for("@@mdb.bson.version")]!==n)throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?V.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?V.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||Z(t))return(null!=e?V.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||P(t))return(null!=e?V.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?V.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?V.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?V.utf8ByteLength(e)+1:0)+1+4+4+V.utf8ByteLength(t.code.toString())+1+we(t.scope,r,u):(null!=e?V.utf8ByteLength(e)+1:0)+1+4+V.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const r=t;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?V.utf8ByteLength(e)+1:0)+(r.position+1+4+1+4):(null!=e?V.utf8ByteLength(e)+1:0)+(r.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?V.utf8ByteLength(e)+1:0)+V.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?V.utf8ByteLength(e)+1:0)+1+we(n,r,u)}return t instanceof RegExp||K(t)?(null!=e?V.utf8ByteLength(e)+1:0)+1+V.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?V.utf8ByteLength(e)+1:0)+1+V.utf8ByteLength(t.pattern)+1+V.utf8ByteLength(t.options)+1:(null!=e?V.utf8ByteLength(e)+1:0)+we(t,r,u)+1;case"function":if(r)return(null!=e?V.utf8ByteLength(e)+1:0)+1+4+V.utf8ByteLength(t.toString())+1}return 0}ObjectId.index=Math.floor(16777215*Math.random());class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}constructor(e,t){if(super(),this.pattern=e,this.options=(t??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let e=0;e<this.options.length;e++)if("i"!==this.options[e]&&"m"!==this.options[e]&&"x"!==this.options[e]&&"l"!==this.options[e]&&"s"!==this.options[e]&&"u"!==this.options[e])throw new BSONError(`The regular expression option [${this.options[e]}] is not supported`)}static parseOptions(e){return e?e.split("").sort().join(""):""}toExtendedJSON(e){return(e=e||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(e){if("$regex"in e){if("string"==typeof e.$regex)return new BSONRegExp(e.$regex,BSONRegExp.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new BSONRegExp(e.$regularExpression.pattern,BSONRegExp.parseOptions(e.$regularExpression.options));throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(e)}`)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}constructor(e){super(),this.value=e}valueOf(){return this.value}toString(){return this.value}inspect(){return`new BSONSymbol("${this.value}")`}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(e){return new BSONSymbol(e.$symbol)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}}const Se=Long;class Timestamp extends Se{get _bsontype(){return"Timestamp"}constructor(e){if(null==e)super(0,0,!0);else if("bigint"==typeof e)super(e,!0);else if(Long.isLong(e))super(e.low,e.high,!0);else{if("object"!=typeof e||!("t"in e)||!("i"in e))throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");if("number"!=typeof e.t&&("object"!=typeof e.t||"Int32"!==e.t._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof e.i&&("object"!=typeof e.i||"Int32"!==e.i._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");if(e.t<0)throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(e.i<0)throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");if(e.t>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(e.i>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(e.i.valueOf(),e.t.valueOf(),!0)}}toJSON(){return{$timestamp:this.toString()}}static fromInt(e){return new Timestamp(Long.fromInt(e,!0))}static fromNumber(e){return new Timestamp(Long.fromNumber(e,!0))}static fromBits(e,t){return new Timestamp({i:e,t})}static fromString(e,t){return new Timestamp(Long.fromString(e,!0,t))}toExtendedJSON(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,r=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:r,i:t})}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`}}Timestamp.MAX_VALUE=Long.MAX_UNSIGNED_VALUE;const Oe=128,Ne=192,Ee=224,xe=240,Le=248,_e=192,ve=224,Ie=240,Ue=128;function $e(e,t,r){let n=0;for(let o=t;o<r;o+=1){const t=e[o];if(n){if((t&Ne)!==Ue)return!1;n-=1}else if(t&Oe)if((t&Ee)===_e)n=1;else if((t&xe)===ve)n=2;else{if((t&Le)!==Ie)return!1;n=3}}return!n}const je=Long.fromNumber(a),Te=Long.fromNumber(l);function De(e,t,r){const n=(t=null==t?{}:t)&&t.index?t.index:0,o=e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24;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 Re(e,n,t,r)}const Ae=/^\$ref$|^\$id$|^\$db$/;function Re(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,u=r.promoteBuffers??!1,a=r.promoteLongs??!0,l=r.promoteValues??!0,$=r.useBigInt64??!1;if($&&!l)throw new BSONError("Must either request bigint or Long for int64 deserialization");if($&&!a)throw new BSONError("Must either request bigint or Long for int64 deserialization");const T=null==r.validation?{utf8:!0}:r.validation;let D,A=!0;const R=new Set,M=T.utf8;if("boolean"==typeof M)D=M;else{A=!1;const e=Object.keys(M).map((function(e){return M[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(D=e[0],!e.every((e=>e===D)))throw new BSONError("Invalid UTF-8 validation option - keys must be all true or all false")}if(!A)for(const e of Object.keys(M))R.add(e);const z=t;if(e.length<5)throw new BSONError("corrupt bson message < 5 bytes long");const F=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(F<5||F>e.length)throw new BSONError("corrupt bson message");const C=n?[]:{};let J=0,q=!n&&null;const H=new DataView(e.buffer,e.byteOffset,e.byteLength);for(;;){const M=e[t++];if(0===M)break;let z=t;for(;0!==e[z]&&z<e.length;)z++;if(z>=e.byteLength)throw new BSONError("Bad BSON Document: illegal CString");const F=n?J++:V.toUTF8(e.subarray(t,z));let P,k=!0;if(k=A||R.has(F)?D:!D,!1!==q&&"$"===F[0]&&(q=Ae.test(F)),t=z+1,M===c){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");P=Me(e,t,t+r-1,k),t+=r}else if(M===b){const r=V.allocate(12);r.set(e.subarray(t,t+12)),P=new ObjectId(r),t+=12}else if(M===x&&!1===l)P=new Int32(e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24);else if(M===x)P=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;else if(M===f&&!1===l)P=new Double(H.getFloat64(t,!0)),t+=8;else if(M===f)P=H.getFloat64(t,!0),t+=8;else if(M===m){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;P=new Date(new Long(r,n).toNumber())}else if(M===y){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");P=1===e[t++]}else if(M===g){const n=t,o=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)P=e.slice(t,t+o);else{let t=r;A||(t={...r,validation:{utf8:k}}),P=Re(e,n,t,!1)}t+=o}else if(M===h){const n=t,i=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;let s=r;const u=t+i;if(o&&o[F]&&(s={...r,raw:!0}),A||(s={...s,validation:{utf8:k}}),P=Re(e,n,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==u)throw new BSONError("corrupted array bson")}else if(M===d)P=void 0;else if(M===w)P=null;else if(M===_){const r=BSONDataView.fromUint8Array(e.subarray(t,t+8)),n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,o=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,i=new Long(n,o);P=$?r.getBigInt64(0,!0):a&&!0===l&&i.lessThanOrEqual(je)&&i.greaterThanOrEqual(Te)?i.toNumber():i}else if(M===v){const r=V.allocate(16);r.set(e.subarray(t,t+16),0),t+=16,P=new Decimal128(r)}else if(M===p){let r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;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(null!=e.slice){if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,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")}u&&l?P=V.toLocalBufferType(e.slice(t,t+r)):(P=new Binary(e.slice(t,t+r),o),o===j&&(P=P.toUUID()))}else{const i=V.allocate(r);if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,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")}for(z=0;z<r;z++)i[z]=e[t+z];P=u&&l?i:o===j?new Binary(e.slice(t,t+r),o).toUUID():new Binary(e.slice(t,t+r),o)}t+=r}else if(M===B&&!1===s){for(z=t;0!==e[z]&&z<e.length;)z++;if(z>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=V.toUTF8(e.subarray(t,z));for(z=t=z+1;0!==e[z]&&z<e.length;)z++;if(z>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=V.toUTF8(e.subarray(t,z));t=z+1;const o=new Array(n.length);for(z=0;z<n.length;z++)switch(n[z]){case"m":o[z]="m";break;case"s":o[z]="g";break;case"i":o[z]="i"}P=new RegExp(r,o.join(""))}else if(M===B&&!0===s){for(z=t;0!==e[z]&&z<e.length;)z++;if(z>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=V.toUTF8(e.subarray(t,z));for(z=t=z+1;0!==e[z]&&z<e.length;)z++;if(z>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=V.toUTF8(e.subarray(t,z));t=z+1,P=new BSONRegExp(r,n)}else if(M===N){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=Me(e,t,t+r-1,k);P=l?n:new BSONSymbol(n),t+=r}else if(M===L){const r=e[t++]+256*e[t++]+65536*e[t++]+e[t++]*(1<<24),n=e[t++]+256*e[t++]+65536*e[t++]+e[t++]*(1<<24);P=new Timestamp({i:r,t:n})}else if(M===I)P=new MinKey;else if(M===U)P=new MaxKey;else if(M===O){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=Me(e,t,t+r-1,k);P=new Code(n),t+=r}else if(M===E){const n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(n<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(o<=0||o>e.length-t||0!==e[t+o-1])throw new BSONError("bad string length in bson");const i=Me(e,t,t+o-1,k),s=t+=o,u=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,a=Re(e,s,r,!1);if(t+=u,n<8+u+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(n>8+u+o)throw new BSONError("code_w_scope total size is too long, clips outer document");P=new Code(i,a)}else{if(M!==S)throw new BSONError(`Detected unknown BSON type ${M.toString(16)} for fieldname "${F}"`);{const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");if(null!=T&&T.utf8&&!$e(e,t,t+r-1))throw new BSONError("Invalid UTF-8 string in BSON document");const n=V.toUTF8(e.subarray(t,t+r-1));t+=r;const o=V.allocate(12);o.set(e.subarray(t,t+12),0);const i=new ObjectId(o);t+=12,P=new DBRef(n,i)}}"__proto__"===F?Object.defineProperty(C,F,{value:P,writable:!0,enumerable:!0,configurable:!0}):C[F]=P}if(F!==t-z){if(n)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!q)return C;if(W(C)){const e=Object.assign({},C);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(C.$ref,C.$id,C.$db,e)}return C}function Me(e,t,r,n){const o=V.toUTF8(e.subarray(t,r));if(n)for(let n=0;n<o.length;n++)if(65533===o.charCodeAt(n)){if(!$e(e,t,r))throw new BSONError("Invalid UTF-8 string in BSON document");break}return o}const ze=/\x00/,Fe=new Set(["$db","$ref","$id","$clusterTime"]);function Ve(e,t,r,n){e[n++]=c,e[(n=n+V.encodeUTF8Into(e,t,n)+1)-1]=0;const o=V.encodeUTF8Into(e,r,n+4);return e[n+3]=o+1>>24&255,e[n+2]=o+1>>16&255,e[n+1]=o+1>>8&255,e[n]=o+1&255,n=n+4+o,e[n++]=0,n}const Ce=new DataView(new ArrayBuffer(8),0,8),Je=new Uint8Array(Ce.buffer,0,4),qe=new Uint8Array(Ce.buffer,0,8);function He(e,t,r,n){const s=!Object.is(r,-0)&&Number.isSafeInteger(r)&&r<=o&&r>=i?x:f;s===x?Ce.setInt32(0,r,!0):Ce.setFloat64(0,r,!0);const u=s===x?Je:qe;return e[n++]=s,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,e.set(u,n),n+=u.byteLength}function Pe(e,t,r,n){return e[n++]=_,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,Ce.setBigInt64(0,r,!0),e.set(qe,n),n+=qe.byteLength}function ke(e,t,r,n){return e[n++]=w,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,n}function Ke(e,t,r,n){return e[n++]=y,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=r?1:0,n}function Ye(e,t,r,n){e[n++]=m,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=Long.fromNumber(r.getTime()),i=o.getLowBits(),s=o.getHighBits();return e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,e[n++]=255&s,e[n++]=s>>8&255,e[n++]=s>>16&255,e[n++]=s>>24&255,n}function Ze(e,t,r,n){if(e[n++]=B,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,r.source&&null!=r.source.match(ze))throw new BSONError("value "+r.source+" must not contain null bytes");return n+=V.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 We(e,t,r,n){if(e[n++]=B,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,null!=r.pattern.match(ze))throw new BSONError("pattern "+r.pattern+" must not contain null bytes");n+=V.encodeUTF8Into(e,r.pattern,n),e[n++]=0;const o=r.options.split("").sort().join("");return n+=V.encodeUTF8Into(e,o,n),e[n++]=0,n}function Ge(e,t,r,n){return null===r?e[n++]=w:"MinKey"===r._bsontype?e[n++]=I:e[n++]=U,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,n}function Xe(e,t,r,n){if(e[n++]=b,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,!k(r.id))throw new BSONError("object ["+JSON.stringify(r)+"] is not a valid ObjectId");return e.set(r.id.subarray(0,12),n),n+12}function Qe(e,t,r,n){e[n++]=p,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.length;return e[n++]=255&o,e[n++]=o>>8&255,e[n++]=o>>16&255,e[n++]=o>>24&255,e[n++]=$,e.set(r,n),n+=o}function et(e,t,r,n,o,i,s,u,a){if(a.has(r))throw new BSONError("Cannot convert circular structure to BSON");a.add(r),e[n++]=Array.isArray(r)?h:g,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const l=ft(e,r,o,n,i+1,s,u,a);return a.delete(r),l}function tt(e,t,r,n){return e[n++]=v,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,e.set(r.bytes.subarray(0,16),n),n+16}function rt(e,t,r,n){e[n++]="Long"===r._bsontype?_:L,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.getLowBits(),i=r.getHighBits();return e[n++]=255&o,e[n++]=o>>8&255,e[n++]=o>>16&255,e[n++]=o>>24&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,n}function nt(e,t,r,n){return r=r.valueOf(),e[n++]=x,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=r>>16&255,e[n++]=r>>24&255,n}function ot(e,t,r,n){return e[n++]=f,n+=V.encodeUTF8Into(e,t,n),e[n++]=0,Ce.setFloat64(0,r.value,!0),e.set(qe,n),n+=8}function it(e,t,r,n){e[n++]=O,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.toString(),i=V.encodeUTF8Into(e,o,n+4)+1;return e[n]=255&i,e[n+1]=i>>8&255,e[n+2]=i>>16&255,e[n+3]=i>>24&255,n=n+4+i-1,e[n++]=0,n}function st(e,t,r,n,o=!1,i=0,s=!1,u=!0,a){if(r.scope&&"object"==typeof r.scope){e[n++]=E,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;let l=n;const f=r.code;n+=4;const c=V.encodeUTF8Into(e,f,n+4)+1;e[n]=255&c,e[n+1]=c>>8&255,e[n+2]=c>>16&255,e[n+3]=c>>24&255,e[n+4+c-1]=0,n=n+c+4;const g=ft(e,r.scope,o,n,i+1,s,u,a);n=g-1;const h=g-l;e[l++]=255&h,e[l++]=h>>8&255,e[l++]=h>>16&255,e[l++]=h>>24&255,e[n++]=0}else{e[n++]=O,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.code.toString(),i=V.encodeUTF8Into(e,o,n+4)+1;e[n]=255&i,e[n+1]=i>>8&255,e[n+2]=i>>16&255,e[n+3]=i>>24&255,n=n+4+i-1,e[n++]=0}return n}function ut(e,t,r,n){e[n++]=p,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.buffer;let i=r.position;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,e[n++]=r.sub_type,r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255),e.set(o,n),n+=r.position}function at(e,t,r,n){e[n++]=N,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;const o=V.encodeUTF8Into(e,r.value,n+4)+1;return e[n]=255&o,e[n+1]=o>>8&255,e[n+2]=o>>16&255,e[n+3]=o>>24&255,n=n+4+o-1,e[n++]=0,n}function lt(e,t,r,n,o,i,s){e[n++]=g,n+=V.encodeUTF8Into(e,t,n),e[n++]=0;let u=n,a={$ref:r.collection||r.namespace,$id:r.oid};null!=r.db&&(a.$db=r.db),a=Object.assign(a,r.fields);const l=ft(e,a,!1,n,o+1,i,!0,s),f=l-u;return e[u++]=255&f,e[u++]=f>>8&255,e[u++]=f>>16&255,e[u++]=f>>24&255,l}function ft(e,t,r,o,i,s,u,a){if(null==a){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(Z(t)||K(t)||k(t)||P(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");a=new Set}a.add(t);let l=o+4;if(Array.isArray(t))for(let o=0;o<t.length;o++){const f=`${o}`;let c=t[o];if("function"==typeof c?.toBSON&&(c=c.toBSON()),"string"==typeof c)l=Ve(e,f,c,l);else if("number"==typeof c)l=He(e,f,c,l);else if("bigint"==typeof c)l=Pe(e,f,c,l);else if("boolean"==typeof c)l=Ke(e,f,c,l);else if(c instanceof Date||Z(c))l=Ye(e,f,c,l);else if(void 0===c)l=ke(e,f,0,l);else if(null===c)l=ke(e,f,0,l);else if(k(c))l=Qe(e,f,c,l);else if(c instanceof RegExp||K(c))l=Ze(e,f,c,l);else if("object"==typeof c&&null==c._bsontype)l=et(e,f,c,l,r,i,s,u,a);else{if("object"==typeof c&&c[Symbol.for("@@mdb.bson.version")]!==n)throw new BSONVersionError;if("ObjectId"===c._bsontype)l=Xe(e,f,c,l);else if("Decimal128"===c._bsontype)l=tt(e,f,c,l);else if("Long"===c._bsontype||"Timestamp"===c._bsontype)l=rt(e,f,c,l);else if("Double"===c._bsontype)l=ot(e,f,c,l);else if("function"==typeof c&&s)l=it(e,f,c,l);else if("Code"===c._bsontype)l=st(e,f,c,l,r,i,s,u,a);else if("Binary"===c._bsontype)l=ut(e,f,c,l);else if("BSONSymbol"===c._bsontype)l=at(e,f,c,l);else if("DBRef"===c._bsontype)l=lt(e,f,c,l,i,s,a);else if("BSONRegExp"===c._bsontype)l=We(e,f,c,l);else if("Int32"===c._bsontype)l=nt(e,f,c,l);else if("MinKey"===c._bsontype||"MaxKey"===c._bsontype)l=Ge(e,f,c,l);else if(void 0!==c._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(c._bsontype)}`)}}else if(t instanceof Map||Y(t)){const o=t.entries();let f=!1;for(;!f;){const t=o.next();if(f=!!t.done,f)continue;const c=t.value[0];let g=t.value[1];"function"==typeof g?.toBSON&&(g=g.toBSON());const h=typeof g;if("string"==typeof c&&!Fe.has(c)){if(null!=c.match(ze))throw new BSONError("key "+c+" must not contain null bytes");if(r){if("$"===c[0])throw new BSONError("key "+c+" must not start with '$'");if(~c.indexOf("."))throw new BSONError("key "+c+" must not contain '.'")}}if("string"===h)l=Ve(e,c,g,l);else if("number"===h)l=He(e,c,g,l);else if("bigint"===h)l=Pe(e,c,g,l);else if("boolean"===h)l=Ke(e,c,g,l);else if(g instanceof Date||Z(g))l=Ye(e,c,g,l);else if(null===g||void 0===g&&!1===u)l=ke(e,c,0,l);else if(k(g))l=Qe(e,c,g,l);else if(g instanceof RegExp||K(g))l=Ze(e,c,g,l);else if("object"===h&&null==g._bsontype)l=et(e,c,g,l,r,i,s,u,a);else{if("object"==typeof g&&g[Symbol.for("@@mdb.bson.version")]!==n)throw new BSONVersionError;if("ObjectId"===g._bsontype)l=Xe(e,c,g,l);else if("object"===h&&"Decimal128"===g._bsontype)l=tt(e,c,g,l);else if("Long"===g._bsontype||"Timestamp"===g._bsontype)l=rt(e,c,g,l);else if("Double"===g._bsontype)l=ot(e,c,g,l);else if("Code"===g._bsontype)l=st(e,c,g,l,r,i,s,u,a);else if("function"==typeof g&&s)l=it(e,c,g,l);else if("Binary"===g._bsontype)l=ut(e,c,g,l);else if("BSONSymbol"===g._bsontype)l=at(e,c,g,l);else if("DBRef"===g._bsontype)l=lt(e,c,g,l,i,s,a);else if("BSONRegExp"===g._bsontype)l=We(e,c,g,l);else if("Int32"===g._bsontype)l=nt(e,c,g,l);else if("MinKey"===g._bsontype||"MaxKey"===g._bsontype)l=Ge(e,c,g,l);else if(void 0!==g._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(g._bsontype)}`)}}}else{if("function"==typeof t?.toBSON&&null!=(t=t.toBSON())&&"object"!=typeof t)throw new BSONError("toBSON function did not return an object");for(const o of Object.keys(t)){let f=t[o];"function"==typeof f?.toBSON&&(f=f.toBSON());const c=typeof f;if("string"==typeof o&&!Fe.has(o)){if(null!=o.match(ze))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.indexOf("."))throw new BSONError("key "+o+" must not contain '.'")}}if("string"===c)l=Ve(e,o,f,l);else if("number"===c)l=He(e,o,f,l);else if("bigint"===c)l=Pe(e,o,f,l);else if("boolean"===c)l=Ke(e,o,f,l);else if(f instanceof Date||Z(f))l=Ye(e,o,f,l);else if(void 0===f)!1===u&&(l=ke(e,o,0,l));else if(null===f)l=ke(e,o,0,l);else if(k(f))l=Qe(e,o,f,l);else if(f instanceof RegExp||K(f))l=Ze(e,o,f,l);else if("object"===c&&null==f._bsontype)l=et(e,o,f,l,r,i,s,u,a);else{if("object"==typeof f&&f[Symbol.for("@@mdb.bson.version")]!==n)throw new BSONVersionError;if("ObjectId"===f._bsontype)l=Xe(e,o,f,l);else if("object"===c&&"Decimal128"===f._bsontype)l=tt(e,o,f,l);else if("Long"===f._bsontype||"Timestamp"===f._bsontype)l=rt(e,o,f,l);else if("Double"===f._bsontype)l=ot(e,o,f,l);else if("Code"===f._bsontype)l=st(e,o,f,l,r,i,s,u,a);else if("function"==typeof f&&s)l=it(e,o,f,l);else if("Binary"===f._bsontype)l=ut(e,o,f,l);else if("BSONSymbol"===f._bsontype)l=at(e,o,f,l);else if("DBRef"===f._bsontype)l=lt(e,o,f,l,i,s,a);else if("BSONRegExp"===f._bsontype)l=We(e,o,f,l);else if("Int32"===f._bsontype)l=nt(e,o,f,l);else if("MinKey"===f._bsontype||"MaxKey"===f._bsontype)l=Ge(e,o,f,l);else if(void 0!==f._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(f._bsontype)}`)}}}a.delete(t),e[l++]=0;const f=l-o;return e[o++]=255&f,e[o++]=f>>8&255,e[o++]=f>>16&255,e[o++]=f>>24&255,l}const ct={$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 gt(e,t={}){if("number"==typeof e){const r=e<=o&&e>=i,n=e<=s&&e>=u;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=ct[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=gt(e.$scope)),Code.fromExtendedJSON(e)}if(W(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 ht(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function pt(e,t){if(e instanceof Map||Y(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 pt(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],u=" ".repeat(n.length+o.length/2),a="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${n}${o}${i}${s}\n ${u}\\${a}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,r)=>{t.seenObjects.push({propertyName:`index ${r}`,obj:null});try{return pt(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return null;if(e instanceof Date||Z(e)){const r=e.getTime(),n=r>-1&&r<2534023188e5;return t.legacy?t.relaxed&&n?{$date:e.getTime()}:{$date:ht(e)}:t.relaxed&&n?{$date:ht(e)}:{$date:{$numberLong:e.getTime().toString()}}}if(!("number"!=typeof e||t.relaxed&&isFinite(e))){if(Number.isInteger(e)&&!Object.is(e,-0)){if(e>=i&&e<=o)return{$numberInt:e.toString()};if(e>=u&&e<=s)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||K(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=pt(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&&e[Symbol.for("@@mdb.bson.version")]!==n)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=dt[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,pt(n.scope,t)):"DBRef"===r&&n.oid&&(n=new DBRef(pt(n.collection,t),pt(n.oid,t),pt(n.db,t),pt(n.fields,t))),n.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof r)}(e,t):e}const dt={Binary:e=>new Binary(e.value(),e.sub_type),Code:e=>new Code(e.code,e.scope),DBRef:e=>new DBRef(e.collection||e.namespace,e.oid,e.db,e.fields),Decimal128:e=>new Decimal128(e.bytes),Double:e=>new Double(e.value),Int32:e=>new Int32(e.value),Long:e=>Long.fromBits(null!=e.low?e.low:e.low_,null!=e.low?e.high:e.high_,null!=e.low?e.unsigned:e.unsigned_),MaxKey:()=>new MaxKey,MinKey:()=>new MinKey,ObjectId:e=>new ObjectId(e),BSONRegExp:e=>new BSONRegExp(e.pattern,e.options),BSONSymbol:e=>new BSONSymbol(e.value),Timestamp:e=>Timestamp.fromBits(e.low,e.high)};function bt(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 gt(t,r)}))}function yt(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=pt(e,Object.assign({relaxed:!0,legacy:!1},n,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,r)}const mt=Object.create(null);mt.parse=bt,mt.stringify=yt,mt.serialize=function(e,t){return t=t||{},JSON.parse(yt(e,t))},mt.deserialize=function(e,t){return t=t||{},bt(JSON.stringify(e),t)},Object.freeze(mt);const wt=17825792;let Bt=V.allocate(wt);function St(e){Bt.length<e&&(Bt=V.allocate(e))}function Ot(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:wt;Bt.length<i&&(Bt=V.allocate(i));const s=ft(Bt,e,r,0,0,n,o,null),u=V.allocate(s);return u.set(Bt.subarray(0,s),0),u}function Nt(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,u=ft(Bt,e,n,0,0,o,i,null);return t.set(Bt.subarray(0,u),s),s+u-1}function Et(e,t={}){return De(V.toLocalBufferType(e),t)}function xt(e,t={}){return we(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function Lt(e,t,r,n,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),u=V.toLocalBufferType(e);let a=t;for(let e=0;e<r;e++){const t=u[a]|u[a+1]<<8|u[a+2]<<16|u[a+3]<<24;s.index=a,n[o+e]=De(u,s),a+=t}return a}var _t=Object.freeze({__proto__:null,Code,BSONSymbol,DBRef,Binary,ObjectId,UUID,Long,Timestamp,Double,Int32,MinKey,MaxKey,BSONRegExp,Decimal128,setInternalBufferSize:St,serialize:Ot,serializeWithBufferAndIndex:Nt,deserialize:Et,calculateObjectSize:xt,deserializeStream:Lt,BSONValue,BSONError,BSONVersionError,BSONRuntimeError,BSONType:T,EJSON:mt});t.BSON=_t,t.BSONError=BSONError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=T,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=mt,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.calculateObjectSize=xt,t.deserialize=Et,t.deserializeStream=Lt,t.serialize=Ot,t.serializeWithBufferAndIndex=Nt,t.setInternalBufferSize=St}},t={},function r(n){var o=t[n];if(void 0!==o)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}(754);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={558:(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(130),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||"*",u=t.getMessageData||function(e){return e.data};return function(){var t={sender:"postmsg-rpc/client",id:(0,i.default)(),func:e,args:Array.from(arguments)},a=void 0,l=new Promise((function(i,l){var f=function r(){var o=u.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)}};a=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 a()},l}}},246:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(558);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(624);function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"expose",{enumerable:!0,get:function(){return i(o).default}})},624:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(r=r||{}).addListener||window.addEventListener,o=r.removeListener||window.removeEventListener,i=r.postMessage||window.postMessage,s=r.targetOrigin||"*",u=r.getMessageData||function(e){return e.data},a=r.isCallback||!1,l=function(){var r=u.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(a)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)}}}},130:(e,t,r)=>{"use strict";e.exports=r(252)},173:(e,t,r)=>{"use strict";var n,o,i,s=r(514),u="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-";function a(){i=!1}function l(e){if(e){if(e!==n){if(e.length!==u.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter((function(e,t,r){return t!==r.lastIndexOf(e)}));if(t.length)throw new Error("Custom alphabet for shortid must be "+u.length+" unique characters. These characters were not unique: "+t.join(", "));n=e,a()}}else n!==u&&(n=u,a())}function f(){return i||(i=function(){n||l(u);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||u},characters:function(e){return l(e),n},seed:function(e){s.seed(e),o!==e&&(a(),o=e)},lookup:function(e){return f()[e]},shuffled:f}},89:(e,t,r)=>{"use strict";var n,o,i=r(943);r(173),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)}},943:(e,t,r)=>{"use strict";var n=r(173),o=r(908),i=r(137);e.exports=function(e){for(var t,r=0,s="";!t;)s+=i(o,n.get(),1),t=e<Math.pow(16,r+1),r++;return s}},252:(e,t,r)=>{"use strict";var n=r(173),o=r(89),i=r(56),s=r(696)||0;function u(){return o(s)}e.exports=u,e.exports.generate=u,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},56:(e,t,r)=>{"use strict";var n=r(173);e.exports=function(e){return!(!e||"string"!=typeof e||e.length<6||new RegExp("[^"+n.get().replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&")+"]").test(e))}},908:(e,t,r)=>{e.exports=r(701)},514:e=>{"use strict";var t=1;e.exports={nextValue:function(){return(t=(9301*t+49297)%233280)/233280},seed:function(e){t=e}}},696:(e,t,r)=>{"use strict";var n=r(1),o=0;!n.isMaster&&n.worker&&(o=n.worker.id),e.exports=parseInt(process.env.NODE_UNIQUE_ID||o,10)},137:e=>{e.exports=function(e,t,r){for(var n=(2<<31-Math.clz32(t.length-1|1))-1,o=Math.ceil(1.6*n*r/t.length),i="";;)for(var s=e(o),u=o;u--;)if((i+=t[s[u]&n]||"").length===+r)return i}},701:(e,t,r)=>{var n=r(113);if(n.randomFillSync){var o={};e.exports=function(e){var t=o[e];return t||(t=Buffer.allocUnsafe(e),e<=255&&(o[e]=t)),n.randomFillSync(t)}}else e.exports=n.randomBytes},754:function(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});const o=r(361),i=r(267),s=n(r(17)),u=r(369),a=r(59),l=process.env.WORKER_RUNTIME_SRC_PATH_DO_NOT_USE_THIS_EXCEPT_FOR_TESTING||s.default.resolve(__dirname,"worker-runtime.js"),f=new i.Worker(l,{env:i.SHARE_ENV}),c=(async()=>{await Promise.race([(async()=>{let e;for(;[e]=await(0,o.once)(f,"message");)if("ready"===e)return})(),(async()=>{const[e]=await(0,o.once)(f,"error");if(e)throw e.message=`Worker thread failed to start with the following error: ${e.message}`,e})()])})();process.setMaxListeners(25),f.setMaxListeners(25);let g=null;const{interrupt:h}=(0,u.createCaller)(["interrupt"],f),p=Object.assign((0,u.createCaller)(["init","evaluate","getCompletions","getShellPrompt"],f),{interrupt:()=>g?((0,a.interrupt)(g),!0):h()});Object.keys(p).forEach((e=>{var t;p[e]=(t=p[e],new Proxy(t,{apply:async(e,t,r)=>(await c,e.call(t,...Array.from(r)))}))})),(0,u.exposeAll)(p,process);const d=Object.assign((0,u.createCaller)(["onPrint","onPrompt","getConfig","setConfig","resetConfig","validateConfig","listConfigOptions","onClearCommand","onExit"],process),{onRunInterruptible(e){g=e}});(0,u.exposeAll)(d,f);const b=(0,u.createCaller)(["emit","on"],process);(0,u.exposeAll)(b,f),process.once("disconnect",(()=>process.exit())),process.nextTick((()=>{var e;null===(e=process.send)||void 0===e||e.call(process,"ready")}))},369:function(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.createCaller=t.exposeAll=t.cancel=t.close=t.removeTrailingUndefined=t.deserialize=t.serialize=void 0;const o=n(r(655)),i=r(246),s=r(568);function u(e){return`data:;base64,${o.default.serialize(e).toString("base64")}`}function a(e){return/^data:;base64,.+/.test(e)?o.default.deserialize(Buffer.from(e.replace("data:;base64,",""),"base64")):e}var l;function f(e){return e&&"object"==typeof e&&"id"in e&&"sender"in e}function c(e){return f(e)&&"postmsg-rpc/server"===e.sender}function g(e){return f(e)&&"postmsg-rpc/client"===e.sender}function h(e){if(Array.isArray(e))for(e=[...e];e.length>0&&void 0===e[e.length-1];)e.pop();return e}function p(e){return{addListener:e.on.bind(e),removeListener:e.off.bind(e),postMessage(t){if(g(t)&&Array.isArray(t.args)&&(t.args=u(h(t.args))),c(t))try{t.res=u(t.res)}catch(e){t.res=u({type:l.Error,payload:(0,s.serializeError)(e)})}return function(e,t){"postMessage"in e&&"function"==typeof e.postMessage&&e.postMessage(t),"send"in e&&"function"==typeof e.send&&e.send(t)}(e,t)},getMessageData:e=>(g(e)&&e.args&&"string"==typeof e.args&&(e.args=a(e.args)),c(e)&&"string"==typeof e.res&&(e.res=a(e.res)),e)}}t.serialize=u,t.deserialize=a,function(e){e[e.Message=0]="Message",e[e.Error=1]="Error"}(l||(l={})),t.removeTrailingUndefined=h,t.close=Symbol("@@rpc.close"),t.cancel=Symbol("@@rpc.cancel"),t.exposeAll=function(e,r){return Object.entries(e).forEach((([e,t])=>{const{close:n}=(0,i.expose)(e,(async(...e)=>{try{return{type:l.Message,payload:await t(...e)}}catch(e){return{type:l.Error,payload:(0,s.serializeError)(e)}}}),p(r));t.close=n})),Object.defineProperty(e,t.close,{enumerable:!1,value(){Object.values(e).forEach((e=>{e.close()}))}}),e},t.createCaller=function(e,r,n={}){const o={},u=new Set;return e.forEach((e=>{const t=(0,i.caller)(e,p(r));o[e]=async(...r)=>{var o;const i="function"==typeof n[e]?null===(o=n[e])||void 0===o?void 0:o.call(n,...r):r,a=t(...i);u.add(a);const f=await a;if(u.delete(a),(c=f)&&"object"==typeof c&&c.type===l.Error)throw(0,s.deserializeError)(f.payload);var c;return f.payload}})),Object.defineProperty(o,t.cancel,{enumerable:!1,value(){for(const e of u)e.cancel(),u.delete(e)}}),o}},568:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.deserializeConnectOptions=t.serializeConnectOptions=t.deserializeEvaluationResult=t.serializeEvaluationResult=t.SerializedResultTypes=t.deserializeError=t.serializeError=void 0;const n=r(837),o=r(429);function i(e){var t;return(t=e,Object.getOwnPropertyNames(t)).concat("name").reduce(((t,r)=>(t[r]=e[r],t)),{})}function s(e){return Object.assign(new Error,e)}var u;t.serializeError=i,t.deserializeError=s,function(e){e.SerializedErrorResult="SerializedErrorResult",e.InspectResult="InspectResult",e.SerializedShellApiResult="SerializedShellApiResult"}(u=t.SerializedResultTypes||(t.SerializedResultTypes={})),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:u.SerializedErrorResult,printable:i(t),source:r}:null===e?{type:u.InspectResult,printable:(0,n.inspect)(t),source:r}:{type:u.SerializedShellApiResult,printable:{origType:e,serializedValue:o.EJSON.serialize(t)}};var s},t.deserializeEvaluationResult=function({type:e,printable:t,source:r}){return e===u.SerializedErrorResult?{type:e,printable:s(t),source:r}:e===u.SerializedShellApiResult?{type:t.origType,printable:o.EJSON.deserialize(t.serializedValue),source:r}:{type:e,printable:t,source:r}};const a=["schemaMap","encryptedFieldsMap"];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}},59:e=>{"use strict";e.exports=require("interruptor")},1:e=>{"use strict";e.exports=require("cluster")},113:e=>{"use strict";e.exports=require("crypto")},361:e=>{"use strict";e.exports=require("events")},17:e=>{"use strict";e.exports=require("path")},837:e=>{"use strict";e.exports=require("util")},655:e=>{"use strict";e.exports=require("v8")},267:e=>{"use strict";e.exports=require("worker_threads")},429:(e,t,r)=>{"use strict";function n(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function o(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)}function i(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function s(e){return"[object Map]"===Object.prototype.toString.call(e)}function u(e){return"[object Date]"===Object.prototype.toString.call(e)}const a=5,l=2147483647,f=-2147483648,c=Math.pow(2,63)-1,g=-Math.pow(2,63),h=Math.pow(2,53),p=-Math.pow(2,53),d=1,b=2,y=3,m=4,w=5,S=6,B=7,O=8,N=9,E=10,L=11,x=12,_=13,U=14,v=15,I=16,$=17,j=18,T=19,D=255,A=127,R=0,M=4,F=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){super(e)}static isBSONError(e){return null!=e&&"object"==typeof e&&"bsonError"in e&&!0===e.bsonError&&"name"in e&&"message"in e&&"stack"in e}}class BSONVersionError extends BSONError{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${a}.0 or later`)}}class BSONRuntimeError extends BSONError{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}function z(e){return V.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const V={toLocalBufferType(e){if(Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength);const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return Buffer.from(e);throw new BSONError(`Cannot create Buffer from ${String(e)}`)},allocate:e=>Buffer.alloc(e),equals:(e,t)=>V.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),toBase64:e=>V.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>V.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>V.toLocalBufferType(e).toString("hex"),fromUTF8:e=>Buffer.from(e,"utf8"),toUTF8:e=>V.toLocalBufferType(e).toString("utf8"),utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into:(e,t,r)=>V.toLocalBufferType(e).write(t,r,void 0,"utf8"),randomBytes:(()=>{try{return r(113).randomBytes}catch{return z}})()};function C(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return H.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const J=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(H.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 C})(),q=/(\d|[a-f])/i,H={toLocalBufferType(e){const t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if("Uint8Array"===t)return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if("ArrayBuffer"===t||"SharedArrayBuffer"===t||"[object ArrayBuffer]"===t||"[object SharedArrayBuffer]"===t)return new Uint8Array(e);throw new BSONError(`Cannot make a Uint8Array from ${String(e)}`)},allocate(e){if("number"!=typeof e)throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},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))),toBase64:e=>btoa(H.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(!q.test(n))break;if(!q.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(""),fromUTF8:e=>(new TextEncoder).encode(e),toUTF8:e=>new TextDecoder("utf8",{fatal:!1}).decode(e),utf8ByteLength:e=>H.fromUTF8(e).byteLength,encodeUTF8Into(e,t,r){const n=H.fromUTF8(t);return e.set(n,r),n.byteLength},randomBytes:J},P="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?V:H;class BSONDataView extends DataView{static fromUint8Array(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}}class BSONValue{get[Symbol.for("@@mdb.bson.version")](){return a}}class Binary extends BSONValue{get _bsontype(){return"Binary"}constructor(e,t){if(super(),!(null==e||"string"==typeof e||ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Array.isArray(e)))throw new BSONError("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");this.sub_type=t??Binary.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=P.allocate(Binary.BUFFER_SIZE),this.position=0):("string"==typeof e?this.buffer=P.fromISO88591(e):Array.isArray(e)?this.buffer=P.fromNumberArray(e):this.buffer=P.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=P.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=P.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(P.toLocalBufferType(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position;else if("string"==typeof e){const r=P.fromISO88591(e);this.buffer.set(r,t),this.position=t+e.length>this.position?t+e.length:this.position}}read(e,t){return t=t&&t>0?t:this.position,this.buffer.slice(e,e+t)}value(e){return(e=!!e)&&this.buffer.length===this.position?this.buffer:e?this.buffer.slice(0,this.position):P.toISO88591(this.buffer.subarray(0,this.position))}length(){return this.position}toJSON(){return P.toBase64(this.buffer)}toString(e){return"hex"===e?P.toHex(this.buffer):"base64"===e?P.toBase64(this.buffer):P.toUTF8(this.buffer)}toExtendedJSON(e){e=e||{};const t=P.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.slice(0,this.position));throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Binary.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(e,t){return new Binary(P.fromHex(e),t)}static createFromBase64(e,t){return new Binary(P.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=P.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(n=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=P.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 n===M?new UUID(r):new Binary(r,n)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`Binary.createFromBase64("${P.toBase64(this.buffer.subarray(0,this.position))}", ${this.sub_type})`}}Binary.BSON_BINARY_SUBTYPE_DEFAULT=0,Binary.BUFFER_SIZE=256,Binary.SUBTYPE_DEFAULT=0,Binary.SUBTYPE_FUNCTION=1,Binary.SUBTYPE_BYTE_ARRAY=2,Binary.SUBTYPE_UUID_OLD=3,Binary.SUBTYPE_UUID=4,Binary.SUBTYPE_MD5=5,Binary.SUBTYPE_ENCRYPTED=6,Binary.SUBTYPE_COLUMN=7,Binary.SUBTYPE_USER_DEFINED=128;const k=/^[0-9A-F]{32}$/i,K=/^[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=P.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=P.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,M)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[P.toHex(this.buffer.subarray(0,4)),P.toHex(this.buffer.subarray(4,6)),P.toHex(this.buffer.subarray(6,8)),P.toHex(this.buffer.subarray(8,10)),P.toHex(this.buffer.subarray(10,16))].join("-"):P.toHex(this.buffer)}toString(e){return"hex"===e?P.toHex(this.id):"base64"===e?P.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof UUID)return P.equals(e.id,this.id);try{return P.equals(new UUID(e).id,this.id)}catch{return!1}}toBinary(){return new Binary(this.id,Binary.SUBTYPE_UUID)}static generate(){const e=P.randomBytes(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}static isValid(e){return!!e&&("string"==typeof e?UUID.isValidUUIDString(e):o(e)?16===e.byteLength:"Binary"===e._bsontype&&e.sub_type===this.SUBTYPE_UUID&&16===e.buffer.byteLength)}static createFromHexString(e){const t=UUID.bytesFromString(e);return new UUID(t)}static createFromBase64(e){return new UUID(P.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 P.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return k.test(e)||K.test(e)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new UUID("${this.toHexString()}")`}}UUID.cacheHexString=!1;class Code extends BSONValue{get _bsontype(){return"Code"}constructor(e,t){super(),this.code=e.toString(),this.scope=t??null}toJSON(){return null!=this.scope?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(e){return new Code(e.$code,e.$scope)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){const e=this.toJSON();return`new Code("${String(e.code)}"${null!=e.scope?`, ${JSON.stringify(e.scope)}`:""})`}}function Y(e){return null!=e&&"object"==typeof e&&"$id"in e&&null!=e.$id&&"$ref"in e&&"string"==typeof e.$ref&&(!("$db"in e)||"$db"in e&&"string"==typeof e.$db)}class DBRef extends BSONValue{get _bsontype(){return"DBRef"}constructor(e,t,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)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){const e=void 0===this.oid||void 0===this.oid.toString?this.oid:this.oid.toString();return`new DBRef("${this.namespace}", new ObjectId("${String(e)}")${this.db?`, "${this.db}"`:""})`}}let Z;try{Z=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 W=4294967296,G=0x10000000000000000,X=G/2,Q={},ee={},te=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class Long extends BSONValue{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(e=0,t,r){super(),"bigint"==typeof e?Object.assign(this,Long.fromBigInt(e,!!t)):"string"==typeof e?Object.assign(this,Long.fromString(e,!!t)):(this.low=0|e,this.high=0|t,this.unsigned=!!r)}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=ee[e],n)?n:(r=Long.fromBits(e,(0|e)<0?-1:0,!0),o&&(ee[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=Q[e],n)?n:(r=Long.fromBits(e,e<0?-1:0,!1),o&&(Q[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>=G)return Long.MAX_UNSIGNED_VALUE}else{if(e<=-X)return Long.MIN_VALUE;if(e+1>=X)return Long.MAX_VALUE}return e<0?Long.fromNumber(-e,t).neg():Long.fromBits(e%W|0,e/W|0,t)}static fromBigInt(e,t){return Long.fromString(e.toString(),t)}static fromString(e,t,r){if(0===e.length)throw new BSONError("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return Long.ZERO;if("number"==typeof t?(r=t,t=!1):t=!!t,(r=r||10)<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 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,u=e.low>>>16;let a=0,l=0,f=0,c=0;return c+=o+(65535&e.low),f+=c>>>16,c&=65535,f+=n+u,l+=f>>>16,f&=65535,l+=r+s,a+=l>>>16,l&=65535,a+=t+i,a&=65535,Long.fromBits(f<<16|c,a<<16|l,this.unsigned)}and(e){return Long.isLong(e)||(e=Long.fromValue(e)),Long.fromBits(this.low&e.low,this.high&e.high,this.unsigned)}compare(e){if(Long.isLong(e)||(e=Long.fromValue(e)),this.eq(e))return 0;const t=this.isNegative(),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(Z){if(!this.unsigned&&-2147483648===this.high&&-1===e.low&&-1===e.high)return this;const t=(this.unsigned?Z.div_u:Z.div_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,Z.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),u=s.mul(e);for(;u.isNegative()||u.gt(r);)t-=i,s=Long.fromNumber(t,this.unsigned),u=s.mul(e);s.isZero()&&(s=Long.ONE),n=n.add(s),r=r.sub(u)}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&&0==(e&1<<t);t--);return 0!==this.high?t+33:t+1}greaterThan(e){return this.comp(e)>0}gt(e){return this.greaterThan(e)}greaterThanOrEqual(e){return this.comp(e)>=0}gte(e){return this.greaterThanOrEqual(e)}ge(e){return this.greaterThanOrEqual(e)}isEven(){return 0==(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return 1==(1&this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(e){return this.comp(e)<0}lt(e){return this.lessThan(e)}lessThanOrEqual(e){return this.comp(e)<=0}lte(e){return this.lessThanOrEqual(e)}modulo(e){if(Long.isLong(e)||(e=Long.fromValue(e)),Z){const t=(this.unsigned?Z.rem_u:Z.rem_s)(this.low,this.high,e.low,e.high);return Long.fromBits(t,Z.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)),Z){const t=Z.mul(this.low,this.high,e.low,e.high);return Long.fromBits(t,Z.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,u=e.low>>>16,a=65535&e.low;let l=0,f=0,c=0,g=0;return g+=o*a,c+=g>>>16,g&=65535,c+=n*a,f+=c>>>16,c&=65535,c+=o*u,f+=c>>>16,c&=65535,f+=r*a,l+=f>>>16,f&=65535,f+=n*u,l+=f>>>16,f&=65535,f+=o*s,l+=f>>>16,f&=65535,l+=t*a+r*u+n*s+o*i,l&=65535,Long.fromBits(c<<16|g,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)*W+(this.low>>>0):this.high*W+(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(!te.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}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Long("${this.toString()}"${this.unsigned?", true":""})`}}Long.TWO_PWR_24=Long.fromInt(1<<24),Long.MAX_UNSIGNED_VALUE=Long.fromBits(-1,-1,!0),Long.ZERO=Long.fromInt(0),Long.UZERO=Long.fromInt(0,!0),Long.ONE=Long.fromInt(1),Long.UONE=Long.fromInt(1,!0),Long.NEG_ONE=Long.fromInt(-1),Long.MAX_VALUE=Long.fromBits(-1,2147483647,!1),Long.MIN_VALUE=Long.fromBits(0,-2147483648,!1);const re=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,ne=/^(\+|-)?(Infinity|inf)$/i,oe=/^(\+|-)?NaN$/i,ie=6111,se=-6176,ue=P.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ae=P.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),le=P.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),fe=/^([-+])?(\d+)?$/;function ce(e){return!isNaN(parseInt(e,10))}function ge(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 he(e,t){throw new BSONError(`"${e}" is not a valid Decimal128 string - ${t}`)}class Decimal128 extends BSONValue{get _bsontype(){return"Decimal128"}constructor(e){if(super(),"string"==typeof e)this.bytes=Decimal128.fromString(e).bytes;else{if(!o(e))throw new BSONError("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new BSONError("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}static fromString(e){let t=!1,r=!1,n=!1,o=0,i=0,s=0,u=0,a=0;const l=[0];let f=0,c=0,g=0,h=0,p=0,d=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 S=e.match(re),B=e.match(ne),O=e.match(oe);if(!S&&!B&&!O||0===e.length)throw new BSONError(e+" not a valid Decimal128 string");if(S){const t=S[2],r=S[4],n=S[5],o=S[6];r&&void 0===o&&he(e,"missing exponent power"),r&&void 0===t&&he(e,"missing exponent base"),void 0===r&&(n||o)&&he(e,"missing e before exponent")}if("+"!==e[w]&&"-"!==e[w]||(t="-"===e[w++]),!ce(e[w])&&"."!==e[w]){if("i"===e[w]||"I"===e[w])return new Decimal128(t?ae:le);if("N"===e[w])return new Decimal128(ue)}for(;ce(e[w])||"."===e[w];)"."!==e[w]?(f<34&&("0"!==e[w]||n)&&(n||(a=i),n=!0,l[c++]=parseInt(e[w],10),f+=1),n&&(s+=1),r&&(u+=1),i+=1,w+=1):(r&&he(e,"contains multiple periods"),r=!0,w+=1);if(r&&!i)throw new BSONError(e+" not a valid Decimal128 string");if("e"===e[w]||"E"===e[w]){const t=e.substr(++w).match(fe);if(!t||!t[2])return new Decimal128(ue);p=parseInt(t[0],10),w+=t[0].length}if(e[w])return new Decimal128(ue);if(g=0,f){if(h=f-1,o=s,1!==o)for(;0===l[a+o-1];)o-=1}else g=0,h=0,l[0]=0,s=1,f=1,o=0;for(p<=u&&u-p>16384?p=se:p-=u;p>ie;){if(h+=1,h-g>34){if(l.join("").match(/^0+$/)){p=ie;break}he(e,"overflow")}p-=1}for(;p<se||f<s;){if(0===h&&o<f){p=se,o=0;break}if(f<s?s-=1:h-=1,p<ie)p+=1;else{if(l.join("").match(/^0+$/)){p=ie;break}he(e,"overflow")}}if(h-g+1<o){let n=i;r&&(a+=1,n+=1),t&&(a+=1,n+=1);const o=parseInt(e[a+h+1],10);let s=0;if(o>=5&&(s=1,5===o))for(s=l[h]%2==1?1:0,d=a+h+2;d<n;d++)if(parseInt(e[d],10)){s=1;break}if(s){let e=h;for(;e>=0;e--)if(++l[e]>9&&(l[e]=0,0===e)){if(!(p<ie))return new Decimal128(t?ae:le);p+=1,l[e]=1}}}if(b=Long.fromNumber(0),y=Long.fromNumber(0),0===o)b=Long.fromNumber(0),y=Long.fromNumber(0);else if(h-g<17){let e=g;for(y=Long.fromNumber(l[e++]),b=new Long(0,0);e<=h;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(l[e]))}else{let e=g;for(b=Long.fromNumber(l[e++]);e<=h-17;e++)b=b.multiply(Long.fromNumber(10)),b=b.add(Long.fromNumber(l[e]));for(y=Long.fromNumber(l[e++]);e<=h;e++)y=y.multiply(Long.fromNumber(10)),y=y.add(Long.fromNumber(l[e]))}const N=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),u=r.multiply(i);const a=n.multiply(o);let l=n.multiply(i);return s=s.add(u.shiftRightUnsigned(32)),u=new Long(u.getLowBits(),0).add(a).add(l.shiftRightUnsigned(32)),s=s.add(u.shiftRightUnsigned(32)),l=u.shiftLeft(32).add(new Long(l.getLowBits(),0)),{high:s,low:l}}(b,Long.fromString("100000000000000000"));N.low=N.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}(N.low,y)&&(N.high=N.high.add(Long.fromNumber(1))),m=p+6176;const E={low:Long.fromNumber(0),high:Long.fromNumber(0)};N.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))?(E.high=E.high.or(Long.fromNumber(3).shiftLeft(61)),E.high=E.high.or(Long.fromNumber(m).and(Long.fromNumber(16383).shiftLeft(47))),E.high=E.high.or(N.high.and(Long.fromNumber(0x7fffffffffff)))):(E.high=E.high.or(Long.fromNumber(16383&m).shiftLeft(49)),E.high=E.high.or(N.high.and(Long.fromNumber(562949953421311)))),E.low=N.low,t&&(E.high=E.high.or(Long.fromString("9223372036854775808")));const L=P.allocate(16);return w=0,L[w++]=255&E.low.low,L[w++]=E.low.low>>8&255,L[w++]=E.low.low>>16&255,L[w++]=E.low.low>>24&255,L[w++]=255&E.low.high,L[w++]=E.low.high>>8&255,L[w++]=E.low.high>>16&255,L[w++]=E.low.high>>24&255,L[w++]=255&E.high.low,L[w++]=E.high.low>>8&255,L[w++]=E.high.low>>16&255,L[w++]=E.high.low>>24&255,L[w++]=255&E.high.high,L[w++]=E.high.high>>8&255,L[w++]=E.high.high>>16&255,L[w++]=E.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,u=!1,a={parts:[0,0,0,0]};const l=[];s=0;const f=this.bytes,c=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,g=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,h=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24,p=f[s++]|f[s++]<<8|f[s++]<<16|f[s++]<<24;s=0,(new Long(c,g),new Long(h,p)).lessThan(Long.ZERO)&&l.push("-");const d=p>>26&31;if(d>>3==3){if(30===d)return l.join("")+"Infinity";if(31===d)return"NaN";e=p>>15&16383,n=8+(p>>14&1)}else n=p>>14&7,e=p>>17&16383;const b=e-6176;if(a.parts[0]=(16383&p)+((15&n)<<14),a.parts[1]=h,a.parts[2]=g,a.parts[3]=c,0===a.parts[0]&&0===a.parts[1]&&0===a.parts[2]&&0===a.parts[3])u=!0;else for(i=3;i>=0;i--){let e=0;const t=ge(a);if(a=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(u)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)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Decimal128("${this.toString()}")`}}class Double extends BSONValue{get _bsontype(){return"Double"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=+e}valueOf(){return this.value}toJSON(){return this.value}toString(e){return this.value.toString(e)}toExtendedJSON(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(e,t){const r=parseFloat(e.$numberDouble);return t&&t.relaxed?r:new Double(r)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Double(${this.toExtendedJSON().$numberDouble})`}}class Int32 extends BSONValue{get _bsontype(){return"Int32"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}valueOf(){return this.value}toString(e){return this.value.toString(e)}toJSON(){return this.value}toExtendedJSON(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new Int32(e.$numberInt)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Int32(${this.valueOf()})`}}class MaxKey extends BSONValue{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new MaxKey}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return"new MaxKey()"}}class MinKey extends BSONValue{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new MinKey}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return"new MinKey()"}}const pe=new RegExp("^[0-9a-fA-F]{24}$");let de=null;const be=Symbol("id");class ObjectId extends BSONValue{get _bsontype(){return"ObjectId"}constructor(e){let t;if(super(),"object"==typeof e&&e&&"id"in e){if("string"!=typeof e.id&&!ArrayBuffer.isView(e.id))throw new BSONError("Argument passed in must have an id that is of type string or Buffer");t="toHexString"in e&&"function"==typeof e.toHexString?P.fromHex(e.toHexString()):e.id}else t=e;if(null==t||"number"==typeof t)this[be]=ObjectId.generate("number"==typeof t?t:void 0);else if(ArrayBuffer.isView(t)&&12===t.byteLength)this[be]=P.toLocalBufferType(t);else{if("string"!=typeof t)throw new BSONError("Argument passed in does not match the accepted types");if(12===t.length){const e=P.fromUTF8(t);if(12!==e.byteLength)throw new BSONError("Argument passed in must be a string of 12 bytes");this[be]=e}else{if(24!==t.length||!pe.test(t))throw new BSONError("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");this[be]=P.fromHex(t)}}ObjectId.cacheHexString&&(this.__id=P.toHex(this.id))}get id(){return this[be]}set id(e){this[be]=e,ObjectId.cacheHexString&&(this.__id=P.toHex(e))}toHexString(){if(ObjectId.cacheHexString&&this.__id)return this.__id;const e=P.toHex(this.id);return ObjectId.cacheHexString&&!this.__id&&(this.__id=e),e}static getInc(){return ObjectId.index=(ObjectId.index+1)%16777215}static generate(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));const t=ObjectId.getInc(),r=P.allocate(12);return BSONDataView.fromUint8Array(r).setUint32(0,e,!1),null===de&&(de=P.randomBytes(5)),r[4]=de[0],r[5]=de[1],r[6]=de[2],r[7]=de[3],r[8]=de[4],r[11]=255&t,r[10]=t>>8&255,r[9]=t>>16&255,r}toString(e){return"base64"===e?P.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(null==e)return!1;if(e instanceof ObjectId)return this[be][11]===e[be][11]&&P.equals(this[be],e[be]);if("string"==typeof e&&ObjectId.isValid(e)&&12===e.length&&o(this.id))return P.equals(this.id,P.fromISO88591(e));if("string"==typeof e&&ObjectId.isValid(e)&&24===e.length)return e.toLowerCase()===this.toHexString();if("string"==typeof e&&ObjectId.isValid(e)&&12===e.length)return P.equals(P.fromUTF8(e),this.id);if("object"==typeof e&&"toHexString"in e&&"function"==typeof e.toHexString){const t=e.toHexString(),r=this.toHexString().toLowerCase();return"string"==typeof t&&t.toLowerCase()===r}return!1}getTimestamp(){const e=new Date,t=BSONDataView.fromUint8Array(this.id).getUint32(0,!1);return e.setTime(1e3*Math.floor(t)),e}static createPk(){return new ObjectId}static createFromTime(e){const t=P.fromNumberArray([0,0,0,0,0,0,0,0,0,0,0,0]);return BSONDataView.fromUint8Array(t).setUint32(0,e,!1),new ObjectId(t)}static createFromHexString(e){if(24!==e?.length)throw new BSONError("hex string must be 24 characters");return new ObjectId(P.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new BSONError("base64 string must be 16 characters");return new ObjectId(P.fromBase64(e))}static isValid(e){if(null==e)return!1;try{return new ObjectId(e),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(e){return new ObjectId(e.$oid)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new ObjectId("${this.toHexString()}")`}}function ye(e,t,r){let n=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)n+=me(o.toString(),e[o],t,!0,r);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))n+=me(o,e[o],t,!1,r)}return n}function me(e,t,r=!1,o=!1,s=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+P.utf8ByteLength(e)+1+4+P.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=p&&t<=h&&t>=f&&t<=l?(null!=e?P.utf8ByteLength(e)+1:0)+5:(null!=e?P.utf8ByteLength(e)+1:0)+9;case"undefined":return o||!s?(null!=e?P.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?P.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&t[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?P.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?P.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||u(t))return(null!=e?P.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||n(t))return(null!=e?P.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?P.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?P.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?P.utf8ByteLength(e)+1:0)+1+4+4+P.utf8ByteLength(t.code.toString())+1+ye(t.scope,r,s):(null!=e?P.utf8ByteLength(e)+1:0)+1+4+P.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const r=t;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY?(null!=e?P.utf8ByteLength(e)+1:0)+(r.position+1+4+1+4):(null!=e?P.utf8ByteLength(e)+1:0)+(r.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?P.utf8ByteLength(e)+1:0)+P.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?P.utf8ByteLength(e)+1:0)+1+ye(n,r,s)}return t instanceof RegExp||i(t)?(null!=e?P.utf8ByteLength(e)+1:0)+1+P.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?P.utf8ByteLength(e)+1:0)+1+P.utf8ByteLength(t.pattern)+1+P.utf8ByteLength(t.options)+1:(null!=e?P.utf8ByteLength(e)+1:0)+ye(t,r,s)+1;case"function":if(r)return(null!=e?P.utf8ByteLength(e)+1:0)+1+4+P.utf8ByteLength(t.toString())+1}return 0}ObjectId.index=Math.floor(16777215*Math.random());class BSONRegExp extends BSONValue{get _bsontype(){return"BSONRegExp"}constructor(e,t){if(super(),this.pattern=e,this.options=(t??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let e=0;e<this.options.length;e++)if("i"!==this.options[e]&&"m"!==this.options[e]&&"x"!==this.options[e]&&"l"!==this.options[e]&&"s"!==this.options[e]&&"u"!==this.options[e])throw new BSONError(`The regular expression option [${this.options[e]}] is not supported`)}static parseOptions(e){return e?e.split("").sort().join(""):""}toExtendedJSON(e){return(e=e||{}).legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(e){if("$regex"in e){if("string"==typeof e.$regex)return new BSONRegExp(e.$regex,BSONRegExp.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new BSONRegExp(e.$regularExpression.pattern,BSONRegExp.parseOptions(e.$regularExpression.options));throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(e)}`)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`}}class BSONSymbol extends BSONValue{get _bsontype(){return"BSONSymbol"}constructor(e){super(),this.value=e}valueOf(){return this.value}toString(){return this.value}inspect(){return`new BSONSymbol("${this.value}")`}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(e){return new BSONSymbol(e.$symbol)}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}}const we=Long;class Timestamp extends we{get _bsontype(){return"Timestamp"}constructor(e){if(null==e)super(0,0,!0);else if("bigint"==typeof e)super(e,!0);else if(Long.isLong(e))super(e.low,e.high,!0);else{if("object"!=typeof e||!("t"in e)||!("i"in e))throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");if("number"!=typeof e.t&&("object"!=typeof e.t||"Int32"!==e.t._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");if("number"!=typeof e.i&&("object"!=typeof e.i||"Int32"!==e.i._bsontype))throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");if(e.t<0)throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");if(e.i<0)throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");if(e.t>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(e.i>4294967295)throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(e.i.valueOf(),e.t.valueOf(),!0)}}toJSON(){return{$timestamp:this.toString()}}static fromInt(e){return new Timestamp(Long.fromInt(e,!0))}static fromNumber(e){return new Timestamp(Long.fromNumber(e,!0))}static fromBits(e,t){return new Timestamp({i:e,t})}static fromString(e,t){return new Timestamp(Long.fromString(e,!0,t))}toExtendedJSON(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}}static fromExtendedJSON(e){const t=Long.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,r=Long.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new Timestamp({t:r,i:t})}[Symbol.for("nodejs.util.inspect.custom")](){return this.inspect()}inspect(){return`new Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`}}Timestamp.MAX_VALUE=Long.MAX_UNSIGNED_VALUE;const Se=128,Be=192,Oe=224,Ne=240,Ee=248,Le=192,xe=224,_e=240,Ue=128;function ve(e,t,r){let n=0;for(let o=t;o<r;o+=1){const t=e[o];if(n){if((t&Be)!==Ue)return!1;n-=1}else if(t&Se)if((t&Oe)===Le)n=1;else if((t&Ne)===xe)n=2;else{if((t&Ee)!==_e)return!1;n=3}}return!n}const Ie=Long.fromNumber(h),$e=Long.fromNumber(p);function je(e,t,r){const n=(t=null==t?{}:t)&&t.index?t.index:0,o=e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24;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 Te=/^\$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,u=r.promoteBuffers??!1,a=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&&!a)throw new BSONError("Must either request bigint or Long for int64 deserialization");const c=null==r.validation?{utf8:!0}:r.validation;let g,h=!0;const p=new Set,R=c.utf8;if("boolean"==typeof R)g=R;else{h=!1;const e=Object.keys(R).map((function(e){return R[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(g=e[0],!e.every((e=>e===g)))throw new BSONError("Invalid UTF-8 validation option - keys must be all true or all false")}if(!h)for(const e of Object.keys(R))p.add(e);const F=t;if(e.length<5)throw new BSONError("corrupt bson message < 5 bytes long");const z=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(z<5||z>e.length)throw new BSONError("corrupt bson message");const V=n?[]:{};let C=0,J=!n&&null;const q=new DataView(e.buffer,e.byteOffset,e.byteLength);for(;;){const R=e[t++];if(0===R)break;let F=t;for(;0!==e[F]&&F<e.length;)F++;if(F>=e.byteLength)throw new BSONError("Bad BSON Document: illegal CString");const z=n?C++:P.toUTF8(e.subarray(t,F));let H,k=!0;if(k=h||p.has(z)?g:!g,!1!==J&&"$"===z[0]&&(J=Te.test(z)),t=F+1,R===b){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");H=Ae(e,t,t+r-1,k),t+=r}else if(R===B){const r=P.allocate(12);r.set(e.subarray(t,t+12)),H=new ObjectId(r),t+=12}else if(R===I&&!1===l)H=new Int32(e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24);else if(R===I)H=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;else if(R===d&&!1===l)H=new Double(q.getFloat64(t,!0)),t+=8;else if(R===d)H=q.getFloat64(t,!0),t+=8;else if(R===N){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;H=new Date(new Long(r,n).toNumber())}else if(R===O){if(0!==e[t]&&1!==e[t])throw new BSONError("illegal boolean type value");H=1===e[t++]}else if(R===y){const n=t,o=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;if(o<=0||o>e.length-t)throw new BSONError("bad embedded document length in bson");if(i)H=e.slice(t,t+o);else{let t=r;h||(t={...r,validation:{utf8:k}}),H=De(e,n,t,!1)}t+=o}else if(R===m){const n=t,i=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24;let s=r;const u=t+i;if(o&&o[z]&&(s={...r,raw:!0}),h||(s={...s,validation:{utf8:k}}),H=De(e,n,s,!0),0!==e[(t+=i)-1])throw new BSONError("invalid array terminator byte");if(t!==u)throw new BSONError("corrupted array bson")}else if(R===S)H=void 0;else if(R===E)H=null;else if(R===j){const r=BSONDataView.fromUint8Array(e.subarray(t,t+8)),n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,o=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,i=new Long(n,o);H=f?r.getBigInt64(0,!0):a&&!0===l&&i.lessThanOrEqual(Ie)&&i.greaterThanOrEqual($e)?i.toNumber():i}else if(R===T){const r=P.allocate(16);r.set(e.subarray(t,t+16),0),t+=16,H=new Decimal128(r)}else if(R===w){let r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;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(null!=e.slice){if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,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")}u&&l?H=P.toLocalBufferType(e.slice(t,t+r)):(H=new Binary(e.slice(t,t+r),o),o===M&&UUID.isValid(H)&&(H=H.toUUID()))}else{const i=P.allocate(r);if(o===Binary.SUBTYPE_BYTE_ARRAY){if(r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24,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")}for(F=0;F<r;F++)i[F]=e[t+F];u&&l?H=i:(H=new Binary(e.slice(t,t+r),o),o===M&&UUID.isValid(H)&&(H=H.toUUID()))}t+=r}else if(R===L&&!1===s){for(F=t;0!==e[F]&&F<e.length;)F++;if(F>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=P.toUTF8(e.subarray(t,F));for(F=t=F+1;0!==e[F]&&F<e.length;)F++;if(F>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=P.toUTF8(e.subarray(t,F));t=F+1;const o=new Array(n.length);for(F=0;F<n.length;F++)switch(n[F]){case"m":o[F]="m";break;case"s":o[F]="g";break;case"i":o[F]="i"}H=new RegExp(r,o.join(""))}else if(R===L&&!0===s){for(F=t;0!==e[F]&&F<e.length;)F++;if(F>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const r=P.toUTF8(e.subarray(t,F));for(F=t=F+1;0!==e[F]&&F<e.length;)F++;if(F>=e.length)throw new BSONError("Bad BSON Document: illegal CString");const n=P.toUTF8(e.subarray(t,F));t=F+1,H=new BSONRegExp(r,n)}else if(R===U){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=Ae(e,t,t+r-1,k);H=l?n:new BSONSymbol(n),t+=r}else if(R===$){const r=e[t++]+256*e[t++]+65536*e[t++]+e[t++]*(1<<24),n=e[t++]+256*e[t++]+65536*e[t++]+e[t++]*(1<<24);H=new Timestamp({i:r,t:n})}else if(R===D)H=new MinKey;else if(R===A)H=new MaxKey;else if(R===_){const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");const n=Ae(e,t,t+r-1,k);H=new Code(n),t+=r}else if(R===v){const n=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(n<13)throw new BSONError("code_w_scope total size shorter minimum expected length");const o=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(o<=0||o>e.length-t||0!==e[t+o-1])throw new BSONError("bad string length in bson");const i=Ae(e,t,t+o-1,k),s=t+=o,u=e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,a=De(e,s,r,!1);if(t+=u,n<8+u+o)throw new BSONError("code_w_scope total size is too short, truncating scope");if(n>8+u+o)throw new BSONError("code_w_scope total size is too long, clips outer document");H=new Code(i,a)}else{if(R!==x)throw new BSONError(`Detected unknown BSON type ${R.toString(16)} for fieldname "${z}"`);{const r=e[t++]|e[t++]<<8|e[t++]<<16|e[t++]<<24;if(r<=0||r>e.length-t||0!==e[t+r-1])throw new BSONError("bad string length in bson");if(null!=c&&c.utf8&&!ve(e,t,t+r-1))throw new BSONError("Invalid UTF-8 string in BSON document");const n=P.toUTF8(e.subarray(t,t+r-1));t+=r;const o=P.allocate(12);o.set(e.subarray(t,t+12),0);const i=new ObjectId(o);t+=12,H=new DBRef(n,i)}}"__proto__"===z?Object.defineProperty(V,z,{value:H,writable:!0,enumerable:!0,configurable:!0}):V[z]=H}if(z!==t-F){if(n)throw new BSONError("corrupt array bson");throw new BSONError("corrupt object bson")}if(!J)return V;if(Y(V)){const e=Object.assign({},V);return delete e.$ref,delete e.$id,delete e.$db,new DBRef(V.$ref,V.$id,V.$db,e)}return V}function Ae(e,t,r,n){const o=P.toUTF8(e.subarray(t,r));if(n)for(let n=0;n<o.length;n++)if(65533===o.charCodeAt(n)){if(!ve(e,t,r))throw new BSONError("Invalid UTF-8 string in BSON document");break}return o}const Re=/\x00/,Me=new Set(["$db","$ref","$id","$clusterTime"]);function Fe(e,t,r,n){e[n++]=b,e[(n=n+P.encodeUTF8Into(e,t,n)+1)-1]=0;const o=P.encodeUTF8Into(e,r,n+4);return e[n+3]=o+1>>24&255,e[n+2]=o+1>>16&255,e[n+1]=o+1>>8&255,e[n]=o+1&255,n=n+4+o,e[n++]=0,n}const ze=new DataView(new ArrayBuffer(8),0,8),Ve=new Uint8Array(ze.buffer,0,4),Ce=new Uint8Array(ze.buffer,0,8);function Je(e,t,r,n){const o=!Object.is(r,-0)&&Number.isSafeInteger(r)&&r<=l&&r>=f?I:d;o===I?ze.setInt32(0,r,!0):ze.setFloat64(0,r,!0);const i=o===I?Ve:Ce;return e[n++]=o,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,e.set(i,n),n+=i.byteLength}function qe(e,t,r,n){return e[n++]=j,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,ze.setBigInt64(0,r,!0),e.set(Ce,n),n+=Ce.byteLength}function He(e,t,r,n){return e[n++]=E,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,n}function Pe(e,t,r,n){return e[n++]=O,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=r?1:0,n}function ke(e,t,r,n){e[n++]=N,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=Long.fromNumber(r.getTime()),i=o.getLowBits(),s=o.getHighBits();return e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,e[n++]=255&s,e[n++]=s>>8&255,e[n++]=s>>16&255,e[n++]=s>>24&255,n}function Ke(e,t,r,n){if(e[n++]=L,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,r.source&&null!=r.source.match(Re))throw new BSONError("value "+r.source+" must not contain null bytes");return n+=P.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 Ye(e,t,r,n){if(e[n++]=L,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,null!=r.pattern.match(Re))throw new BSONError("pattern "+r.pattern+" must not contain null bytes");n+=P.encodeUTF8Into(e,r.pattern,n),e[n++]=0;const o=r.options.split("").sort().join("");return n+=P.encodeUTF8Into(e,o,n),e[n++]=0,n}function Ze(e,t,r,n){return null===r?e[n++]=E:"MinKey"===r._bsontype?e[n++]=D:e[n++]=A,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,n}function We(e,t,r,n){if(e[n++]=B,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,!o(r.id))throw new BSONError("object ["+JSON.stringify(r)+"] is not a valid ObjectId");return e.set(r.id.subarray(0,12),n),n+12}function Ge(e,t,r,n){e[n++]=w,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.length;return e[n++]=255&o,e[n++]=o>>8&255,e[n++]=o>>16&255,e[n++]=o>>24&255,e[n++]=R,e.set(r,n),n+=o}function Xe(e,t,r,n,o,i,s,u,a){if(a.has(r))throw new BSONError("Cannot convert circular structure to BSON");a.add(r),e[n++]=Array.isArray(r)?m:y,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const l=at(e,r,o,n,i+1,s,u,a);return a.delete(r),l}function Qe(e,t,r,n){return e[n++]=T,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,e.set(r.bytes.subarray(0,16),n),n+16}function et(e,t,r,n){e[n++]="Long"===r._bsontype?j:$,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.getLowBits(),i=r.getHighBits();return e[n++]=255&o,e[n++]=o>>8&255,e[n++]=o>>16&255,e[n++]=o>>24&255,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,n}function tt(e,t,r,n){return r=r.valueOf(),e[n++]=I,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,e[n++]=255&r,e[n++]=r>>8&255,e[n++]=r>>16&255,e[n++]=r>>24&255,n}function rt(e,t,r,n){return e[n++]=d,n+=P.encodeUTF8Into(e,t,n),e[n++]=0,ze.setFloat64(0,r.value,!0),e.set(Ce,n),n+=8}function nt(e,t,r,n){e[n++]=_,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.toString(),i=P.encodeUTF8Into(e,o,n+4)+1;return e[n]=255&i,e[n+1]=i>>8&255,e[n+2]=i>>16&255,e[n+3]=i>>24&255,n=n+4+i-1,e[n++]=0,n}function ot(e,t,r,n,o=!1,i=0,s=!1,u=!0,a){if(r.scope&&"object"==typeof r.scope){e[n++]=v,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;let l=n;const f=r.code;n+=4;const c=P.encodeUTF8Into(e,f,n+4)+1;e[n]=255&c,e[n+1]=c>>8&255,e[n+2]=c>>16&255,e[n+3]=c>>24&255,e[n+4+c-1]=0,n=n+c+4;const g=at(e,r.scope,o,n,i+1,s,u,a);n=g-1;const h=g-l;e[l++]=255&h,e[l++]=h>>8&255,e[l++]=h>>16&255,e[l++]=h>>24&255,e[n++]=0}else{e[n++]=_,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.code.toString(),i=P.encodeUTF8Into(e,o,n+4)+1;e[n]=255&i,e[n+1]=i>>8&255,e[n+2]=i>>16&255,e[n+3]=i>>24&255,n=n+4+i-1,e[n++]=0}return n}function it(e,t,r,n){e[n++]=w,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=r.buffer;let i=r.position;return r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i+=4),e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255,e[n++]=r.sub_type,r.sub_type===Binary.SUBTYPE_BYTE_ARRAY&&(i-=4,e[n++]=255&i,e[n++]=i>>8&255,e[n++]=i>>16&255,e[n++]=i>>24&255),e.set(o,n),n+=r.position}function st(e,t,r,n){e[n++]=U,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;const o=P.encodeUTF8Into(e,r.value,n+4)+1;return e[n]=255&o,e[n+1]=o>>8&255,e[n+2]=o>>16&255,e[n+3]=o>>24&255,n=n+4+o-1,e[n++]=0,n}function ut(e,t,r,n,o,i,s){e[n++]=y,n+=P.encodeUTF8Into(e,t,n),e[n++]=0;let u=n,a={$ref:r.collection||r.namespace,$id:r.oid};null!=r.db&&(a.$db=r.db),a=Object.assign(a,r.fields);const l=at(e,a,!1,n,o+1,i,!0,s),f=l-u;return e[u++]=255&f,e[u++]=f>>8&255,e[u++]=f>>16&255,e[u++]=f>>24&255,l}function at(e,t,r,l,f,c,g,h){if(null==h){if(null==t)return e[0]=5,e[1]=0,e[2]=0,e[3]=0,e[4]=0,5;if(Array.isArray(t))throw new BSONError("serialize does not support an array as the root input");if("object"!=typeof t)throw new BSONError("serialize does not support non-object as the root input");if("_bsontype"in t&&"string"==typeof t._bsontype)throw new BSONError("BSON types cannot be serialized as a document");if(u(t)||i(t)||o(t)||n(t))throw new BSONError("date, regexp, typedarray, and arraybuffer cannot be BSON documents");h=new Set}h.add(t);let p=l+4;if(Array.isArray(t))for(let n=0;n<t.length;n++){const s=`${n}`;let l=t[n];if("function"==typeof l?.toBSON&&(l=l.toBSON()),"string"==typeof l)p=Fe(e,s,l,p);else if("number"==typeof l)p=Je(e,s,l,p);else if("bigint"==typeof l)p=qe(e,s,l,p);else if("boolean"==typeof l)p=Pe(e,s,l,p);else if(l instanceof Date||u(l))p=ke(e,s,l,p);else if(void 0===l)p=He(e,s,0,p);else if(null===l)p=He(e,s,0,p);else if(o(l))p=Ge(e,s,l,p);else if(l instanceof RegExp||i(l))p=Ke(e,s,l,p);else if("object"==typeof l&&null==l._bsontype)p=Xe(e,s,l,p,r,f,c,g,h);else{if("object"==typeof l&&l[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===l._bsontype)p=We(e,s,l,p);else if("Decimal128"===l._bsontype)p=Qe(e,s,l,p);else if("Long"===l._bsontype||"Timestamp"===l._bsontype)p=et(e,s,l,p);else if("Double"===l._bsontype)p=rt(e,s,l,p);else if("function"==typeof l&&c)p=nt(e,s,l,p);else if("Code"===l._bsontype)p=ot(e,s,l,p,r,f,c,g,h);else if("Binary"===l._bsontype)p=it(e,s,l,p);else if("BSONSymbol"===l._bsontype)p=st(e,s,l,p);else if("DBRef"===l._bsontype)p=ut(e,s,l,p,f,c,h);else if("BSONRegExp"===l._bsontype)p=Ye(e,s,l,p);else if("Int32"===l._bsontype)p=tt(e,s,l,p);else if("MinKey"===l._bsontype||"MaxKey"===l._bsontype)p=Ze(e,s,l,p);else if(void 0!==l._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(l._bsontype)}`)}}else if(t instanceof Map||s(t)){const n=t.entries();let s=!1;for(;!s;){const t=n.next();if(s=!!t.done,s)continue;const l=t.value[0];let d=t.value[1];"function"==typeof d?.toBSON&&(d=d.toBSON());const b=typeof d;if("string"==typeof l&&!Me.has(l)){if(null!=l.match(Re))throw new BSONError("key "+l+" must not contain null bytes");if(r){if("$"===l[0])throw new BSONError("key "+l+" must not start with '$'");if(~l.indexOf("."))throw new BSONError("key "+l+" must not contain '.'")}}if("string"===b)p=Fe(e,l,d,p);else if("number"===b)p=Je(e,l,d,p);else if("bigint"===b)p=qe(e,l,d,p);else if("boolean"===b)p=Pe(e,l,d,p);else if(d instanceof Date||u(d))p=ke(e,l,d,p);else if(null===d||void 0===d&&!1===g)p=He(e,l,0,p);else if(o(d))p=Ge(e,l,d,p);else if(d instanceof RegExp||i(d))p=Ke(e,l,d,p);else if("object"===b&&null==d._bsontype)p=Xe(e,l,d,p,r,f,c,g,h);else{if("object"==typeof d&&d[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===d._bsontype)p=We(e,l,d,p);else if("object"===b&&"Decimal128"===d._bsontype)p=Qe(e,l,d,p);else if("Long"===d._bsontype||"Timestamp"===d._bsontype)p=et(e,l,d,p);else if("Double"===d._bsontype)p=rt(e,l,d,p);else if("Code"===d._bsontype)p=ot(e,l,d,p,r,f,c,g,h);else if("function"==typeof d&&c)p=nt(e,l,d,p);else if("Binary"===d._bsontype)p=it(e,l,d,p);else if("BSONSymbol"===d._bsontype)p=st(e,l,d,p);else if("DBRef"===d._bsontype)p=ut(e,l,d,p,f,c,h);else if("BSONRegExp"===d._bsontype)p=Ye(e,l,d,p);else if("Int32"===d._bsontype)p=tt(e,l,d,p);else if("MinKey"===d._bsontype||"MaxKey"===d._bsontype)p=Ze(e,l,d,p);else if(void 0!==d._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(d._bsontype)}`)}}}else{if("function"==typeof t?.toBSON&&null!=(t=t.toBSON())&&"object"!=typeof t)throw new BSONError("toBSON function did not return an object");for(const n of Object.keys(t)){let s=t[n];"function"==typeof s?.toBSON&&(s=s.toBSON());const l=typeof s;if("string"==typeof n&&!Me.has(n)){if(null!=n.match(Re))throw new BSONError("key "+n+" must not contain null bytes");if(r){if("$"===n[0])throw new BSONError("key "+n+" must not start with '$'");if(~n.indexOf("."))throw new BSONError("key "+n+" must not contain '.'")}}if("string"===l)p=Fe(e,n,s,p);else if("number"===l)p=Je(e,n,s,p);else if("bigint"===l)p=qe(e,n,s,p);else if("boolean"===l)p=Pe(e,n,s,p);else if(s instanceof Date||u(s))p=ke(e,n,s,p);else if(void 0===s)!1===g&&(p=He(e,n,0,p));else if(null===s)p=He(e,n,0,p);else if(o(s))p=Ge(e,n,s,p);else if(s instanceof RegExp||i(s))p=Ke(e,n,s,p);else if("object"===l&&null==s._bsontype)p=Xe(e,n,s,p,r,f,c,g,h);else{if("object"==typeof s&&s[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if("ObjectId"===s._bsontype)p=We(e,n,s,p);else if("object"===l&&"Decimal128"===s._bsontype)p=Qe(e,n,s,p);else if("Long"===s._bsontype||"Timestamp"===s._bsontype)p=et(e,n,s,p);else if("Double"===s._bsontype)p=rt(e,n,s,p);else if("Code"===s._bsontype)p=ot(e,n,s,p,r,f,c,g,h);else if("function"==typeof s&&c)p=nt(e,n,s,p);else if("Binary"===s._bsontype)p=it(e,n,s,p);else if("BSONSymbol"===s._bsontype)p=st(e,n,s,p);else if("DBRef"===s._bsontype)p=ut(e,n,s,p,f,c,h);else if("BSONRegExp"===s._bsontype)p=Ye(e,n,s,p);else if("Int32"===s._bsontype)p=tt(e,n,s,p);else if("MinKey"===s._bsontype||"MaxKey"===s._bsontype)p=Ze(e,n,s,p);else if(void 0!==s._bsontype)throw new BSONError(`Unrecognized or invalid _bsontype: ${String(s._bsontype)}`)}}}h.delete(t),e[p++]=0;const d=p-l;return e[l++]=255&d,e[l++]=d>>8&255,e[l++]=d>>16&255,e[l++]=d>>24&255,p}const lt={$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 ft(e,t={}){if("number"==typeof e){const r=e<=l&&e>=f,n=e<=c&&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=lt[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=ft(e.$scope)),Code.fromExtendedJSON(e)}if(Y(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 ct(e){const t=e.toISOString();return 0!==e.getUTCMilliseconds()?t:t.slice(0,-5)+"Z"}function gt(e,t){if(e instanceof Map||s(e)){const 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 gt(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],u=" ".repeat(n.length+o.length/2),a="-".repeat(i.length+(o.length+s.length)/2-1);throw new BSONError(`Converting circular structure to EJSON:\n ${n}${o}${i}${s}\n ${u}\\${a}/`)}t.seenObjects[t.seenObjects.length-1].obj=e}if(Array.isArray(e))return function(e,t){return e.map(((e,r)=>{t.seenObjects.push({propertyName:`index ${r}`,obj:null});try{return gt(e,t)}finally{t.seenObjects.pop()}}))}(e,t);if(void 0===e)return null;if(e instanceof Date||u(e)){const r=e.getTime(),n=r>-1&&r<2534023188e5;return t.legacy?t.relaxed&&n?{$date:e.getTime()}:{$date:ct(e)}:t.relaxed&&n?{$date:ct(e)}:{$date:{$numberLong:e.getTime().toString()}}}if(!("number"!=typeof e||t.relaxed&&isFinite(e))){if(Number.isInteger(e)&&!Object.is(e,-0)){if(e>=f&&e<=l)return{$numberInt:e.toString()};if(e>=g&&e<=c)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=gt(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&&e[Symbol.for("@@mdb.bson.version")]!==a)throw new BSONVersionError;if(function(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"string"==typeof e._bsontype}(e)){let n=e;if("function"!=typeof n.toExtendedJSON){const t=ht[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,gt(n.scope,t)):"DBRef"===r&&n.oid&&(n=new DBRef(gt(n.collection,t),gt(n.oid,t),gt(n.db,t),gt(n.fields,t))),n.toExtendedJSON(t)}throw new BSONError("_bsontype must be a string, but was: "+typeof r)}(e,t):e}const ht={Binary:e=>new Binary(e.value(),e.sub_type),Code:e=>new Code(e.code,e.scope),DBRef:e=>new DBRef(e.collection||e.namespace,e.oid,e.db,e.fields),Decimal128:e=>new Decimal128(e.bytes),Double:e=>new Double(e.value),Int32:e=>new Int32(e.value),Long:e=>Long.fromBits(null!=e.low?e.low:e.low_,null!=e.low?e.high:e.high_,null!=e.low?e.unsigned:e.unsigned_),MaxKey:()=>new MaxKey,MinKey:()=>new MinKey,ObjectId:e=>new ObjectId(e),BSONRegExp:e=>new BSONRegExp(e.pattern,e.options),BSONSymbol:e=>new BSONSymbol(e.value),Timestamp:e=>Timestamp.fromBits(e.low,e.high)};function pt(e,t){const 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 ft(t,r)}))}function dt(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=gt(e,Object.assign({relaxed:!0,legacy:!1},n,{seenObjects:[{propertyName:"(root)",obj:null}]}));return JSON.stringify(o,t,r)}const bt=Object.create(null);bt.parse=pt,bt.stringify=dt,bt.serialize=function(e,t){return t=t||{},JSON.parse(dt(e,t))},bt.deserialize=function(e,t){return t=t||{},pt(JSON.stringify(e),t)},Object.freeze(bt);const yt=17825792;let mt=P.allocate(yt);function wt(e){mt.length<e&&(mt=P.allocate(e))}function St(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=P.allocate(i));const s=at(mt,e,r,0,0,n,o,null),u=P.allocate(s);return u.set(mt.subarray(0,s),0),u}function Bt(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,u=at(mt,e,n,0,0,o,i,null);return t.set(mt.subarray(0,u),s),s+u-1}function Ot(e,t={}){return je(P.toLocalBufferType(e),t)}function Nt(e,t={}){return ye(e,"boolean"==typeof(t=t||{}).serializeFunctions&&t.serializeFunctions,"boolean"!=typeof t.ignoreUndefined||t.ignoreUndefined)}function Et(e,t,r,n,o,i){const s=Object.assign({allowObjectSmallerThanBufferSize:!0,index:0},i),u=P.toLocalBufferType(e);let a=t;for(let e=0;e<r;e++){const t=u[a]|u[a+1]<<8|u[a+2]<<16|u[a+3]<<24;s.index=a,n[o+e]=je(u,s),a+=t}return a}var Lt=Object.freeze({__proto__:null,BSONError,BSONRegExp,BSONRuntimeError,BSONSymbol,BSONType:F,BSONValue,BSONVersionError,Binary,Code,DBRef,Decimal128,Double,EJSON:bt,Int32,Long,MaxKey,MinKey,ObjectId,Timestamp,UUID,calculateObjectSize:Nt,deserialize:Ot,deserializeStream:Et,serialize:St,serializeWithBufferAndIndex:Bt,setInternalBufferSize:wt});t.BSON=Lt,t.BSONError=BSONError,t.BSONRegExp=BSONRegExp,t.BSONRuntimeError=BSONRuntimeError,t.BSONSymbol=BSONSymbol,t.BSONType=F,t.BSONValue=BSONValue,t.BSONVersionError=BSONVersionError,t.Binary=Binary,t.Code=Code,t.DBRef=DBRef,t.Decimal128=Decimal128,t.Double=Double,t.EJSON=bt,t.Int32=Int32,t.Long=Long,t.MaxKey=MaxKey,t.MinKey=MinKey,t.ObjectId=ObjectId,t.Timestamp=Timestamp,t.UUID=UUID,t.calculateObjectSize=Nt,t.deserialize=Ot,t.deserializeStream=Et,t.serialize=St,t.serializeWithBufferAndIndex=Bt,t.setInternalBufferSize=wt}},t={},function r(n){var o=t[n];if(void 0!==o)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}(754);var e,t}));
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare class WorkerRuntime implements Runtime {
|
|
|
14
14
|
private childProcessRuntime;
|
|
15
15
|
private initWorkerPromise;
|
|
16
16
|
private childProcessProxySrcPath;
|
|
17
|
-
constructor(uri: string, driverOptions
|
|
17
|
+
constructor(uri: string, driverOptions: DevtoolsConnectOptions, cliOptions?: {
|
|
18
18
|
nodb?: boolean;
|
|
19
19
|
}, spawnOptions?: SpawnOptionsWithoutStdio, eventEmitter?: MongoshBus);
|
|
20
20
|
private initWorker;
|