@budibase/server
Version:
Budibase Web Server
5 lines • 70.3 kB
JavaScript
"use strict";var bson=(()=>{var At=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var fn=Object.getOwnPropertyNames;var ln=Object.prototype.hasOwnProperty;var cn=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var hn=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),gn=(e,t)=>{for(var r in t)At(e,r,{get:t[r],enumerable:!0})},un=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of fn(t))!ln.call(e,i)&&i!==r&&At(e,i,{get:()=>t[i],enumerable:!(n=on(t,i))||n.enumerable});return e};var an=e=>un(At({},"__esModule",{value:!0}),e);var le=hn(U=>{"use strict";function te(e){return["[object ArrayBuffer]","[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(e))}function ht(e){return Object.prototype.toString.call(e)==="[object Uint8Array]"}function gt(e){return Object.prototype.toString.call(e)==="[object RegExp]"}function ee(e){return Object.prototype.toString.call(e)==="[object Map]"}function ut(e){return Object.prototype.toString.call(e)==="[object Date]"}function F(e,t){return JSON.stringify(e,(r,n)=>typeof n=="bigint"?{$numberLong:`${n}`}:ee(n)?Object.fromEntries(n):n)}function mn(e){if(e!=null&&typeof e=="object"&&"stylize"in e&&typeof e.stylize=="function")return e.stylize}var rt=6,Bt=2147483647,Et=-2147483648,Te=Math.pow(2,63)-1,Le=-Math.pow(2,63),$e=Math.pow(2,53),Ae=-Math.pow(2,53),ne=1,Ue=2,re=3,_e=4,ie=5,yn=6,De=7,Re=8,ze=9,se=10,Tt=11,wn=12,oe=13,je=14,Me=15,St=16,xe=17,fe=18,Fe=19,Je=255,Ce=127,pn=0,Lt=4,Pe=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}),c=class extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(t,r){super(t,r)}static isBSONError(t){return t!=null&&typeof t=="object"&&"bsonError"in t&&t.bsonError===!0&&"name"in t&&"message"in t&&"stack"in t}},k=class extends c{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${rt}.x.x`)}},yt=class extends c{get name(){return"BSONRuntimeError"}constructor(t){super(t)}},C=class extends c{get name(){return"BSONOffsetError"}constructor(t,r,n){super(`${t}. offset: ${r}`,n),this.offset=r}},ce,he;function He(e,t,r,n){if(n){ce??=new TextDecoder("utf8",{fatal:!0});try{return ce.decode(e.subarray(t,r))}catch(i){throw new c("Invalid UTF-8 string in BSON document",{cause:i})}}return he??=new TextDecoder("utf8",{fatal:!1}),he.decode(e.subarray(t,r))}function Ve(e,t,r){if(e.length===0)return"";let n=r-t;if(n===0)return"";if(n>20)return null;if(n===1&&e[t]<128)return String.fromCharCode(e[t]);if(n===2&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(n===3&&e[t]<128&&e[t+1]<128&&e[t+2]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1])+String.fromCharCode(e[t+2]);let i=[];for(let o=t;o<r;o++){let h=e[o];if(h>127)return null;i.push(h)}return String.fromCharCode(...i)}function bn(e,t,r){if(t.length===0)return 0;if(t.length>25||e.length-r<t.length)return null;for(let n=0,i=r;n<t.length;n++,i++){let o=t.charCodeAt(n);if(o>127)return null;e[i]=o}return t.length}function Sn(e){return X.fromNumberArray(Array.from({length:e},()=>Math.floor(Math.random()*256)))}var Nn=(()=>{try{return cn("crypto").randomBytes}catch{return Sn}})(),X={toLocalBufferType(e){if(Buffer.isBuffer(e))return e;if(ArrayBuffer.isView(e))return Buffer.from(e.buffer,e.byteOffset,e.byteLength);let t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if(t==="ArrayBuffer"||t==="SharedArrayBuffer"||t==="[object ArrayBuffer]"||t==="[object SharedArrayBuffer]")return Buffer.from(e);throw new c(`Cannot create Buffer from ${String(e)}`)},allocate(e){return Buffer.alloc(e)},allocateUnsafe(e){return Buffer.allocUnsafe(e)},equals(e,t){return X.toLocalBufferType(e).equals(t)},fromNumberArray(e){return Buffer.from(e)},fromBase64(e){return Buffer.from(e,"base64")},toBase64(e){return X.toLocalBufferType(e).toString("base64")},fromISO88591(e){return Buffer.from(e,"binary")},toISO88591(e){return X.toLocalBufferType(e).toString("binary")},fromHex(e){return Buffer.from(e,"hex")},toHex(e){return X.toLocalBufferType(e).toString("hex")},toUTF8(e,t,r,n){let i=r-t<=20?Ve(e,t,r):null;if(i!=null)return i;let o=X.toLocalBufferType(e).toString("utf8",t,r);if(n){for(let h=0;h<o.length;h++)if(o.charCodeAt(h)===65533){He(e,t,r,!0);break}}return o},utf8ByteLength(e){return Buffer.byteLength(e,"utf8")},encodeUTF8Into(e,t,r){let n=bn(e,t,r);return n??X.toLocalBufferType(e).write(t,r,void 0,"utf8")},randomBytes:Nn};function Bn(){let{navigator:e}=globalThis;return typeof e=="object"&&e.product==="ReactNative"}function En(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return Nt.fromNumberArray(Array.from({length:e},()=>Math.floor(Math.random()*256)))}var On=(()=>{let{crypto:e}=globalThis;if(e!=null&&typeof e.getRandomValues=="function")return t=>e.getRandomValues(Nt.allocate(t));if(Bn()){let{console:t}=globalThis;t?.warn?.("BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.")}return En})(),ge=/(\d|[a-f])/i,Nt={toLocalBufferType(e){let t=e?.[Symbol.toStringTag]??Object.prototype.toString.call(e);if(t==="Uint8Array")return e;if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength));if(t==="ArrayBuffer"||t==="SharedArrayBuffer"||t==="[object ArrayBuffer]"||t==="[object SharedArrayBuffer]")return new Uint8Array(e);throw new c(`Cannot make a Uint8Array from ${String(e)}`)},allocate(e){if(typeof e!="number")throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},allocateUnsafe(e){return Nt.allocate(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){return Uint8Array.from(e)},fromBase64(e){return Uint8Array.from(atob(e),t=>t.charCodeAt(0))},toBase64(e){return btoa(Nt.toISO88591(e))},fromISO88591(e){return Uint8Array.from(e,t=>t.charCodeAt(0)&255)},toISO88591(e){return Array.from(Uint16Array.from(e),t=>String.fromCharCode(t)).join("")},fromHex(e){let t=e.length%2===0?e:e.slice(0,e.length-1),r=[];for(let n=0;n<t.length;n+=2){let i=t[n],o=t[n+1];if(!ge.test(i)||!ge.test(o))break;let h=Number.parseInt(`${i}${o}`,16);r.push(h)}return Uint8Array.from(r)},toHex(e){return Array.from(e,t=>t.toString(16).padStart(2,"0")).join("")},toUTF8(e,t,r,n){let i=r-t<=20?Ve(e,t,r):null;return i??He(e,t,r,n)},utf8ByteLength(e){return new TextEncoder().encode(e).byteLength},encodeUTF8Into(e,t,r){let n=new TextEncoder().encode(t);return e.set(n,r),n.byteLength},randomBytes:On},In=typeof Buffer=="function"&&Buffer.prototype?._isBuffer!==!0,l=In?X:Nt,x=class{get[Symbol.for("@@mdb.bson.version")](){return rt}[Symbol.for("nodejs.util.inspect.custom")](t,r,n){return this.inspect(t,r,n)}},_=class e extends x{get _bsontype(){return"Binary"}constructor(t,r){if(super(),t!=null&&typeof t=="string"&&!ArrayBuffer.isView(t)&&!te(t)&&!Array.isArray(t))throw new c("Binary can only be constructed from Uint8Array or number[]");this.sub_type=r??e.BSON_BINARY_SUBTYPE_DEFAULT,t==null?(this.buffer=l.allocate(e.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?l.fromNumberArray(t):l.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if(typeof t=="string"&&t.length!==1)throw new c("only accepts single character String");if(typeof t!="number"&&t.length!==1)throw new c("only accepts single character Uint8Array or Array");let r;if(typeof t=="string"?r=t.charCodeAt(0):typeof t=="number"?r=t:r=t[0],r<0||r>255)throw new c("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=r;else{let n=l.allocate(e.BUFFER_SIZE+this.buffer.length);n.set(this.buffer,0),this.buffer=n,this.buffer[this.position++]=r}}write(t,r){if(r=typeof r=="number"?r:this.position,this.buffer.byteLength<r+t.length){let n=l.allocate(this.buffer.byteLength+t.length);n.set(this.buffer,0),this.buffer=n}if(ArrayBuffer.isView(t))this.buffer.set(l.toLocalBufferType(t),r),this.position=r+t.byteLength>this.position?r+t.length:this.position;else if(typeof t=="string")throw new c("input cannot be string")}read(t,r){return r=r&&r>0?r:this.position,this.buffer.slice(t,t+r)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return l.toBase64(this.buffer.subarray(0,this.position))}toString(t){return t==="hex"?l.toHex(this.buffer.subarray(0,this.position)):t==="base64"?l.toBase64(this.buffer.subarray(0,this.position)):t==="utf8"||t==="utf-8"?l.toUTF8(this.buffer,0,this.position,!1):l.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{};let r=l.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:r,$type:n.length===1?"0"+n:n}:{$binary:{base64:r,subType:n.length===1?"0"+n:n}}}toUUID(){if(this.sub_type===e.SUBTYPE_UUID)return new Y(this.buffer.slice(0,this.position));throw new c(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${e.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,r){return new e(l.fromHex(t),r)}static createFromBase64(t,r){return new e(l.fromBase64(t),r)}static fromExtendedJSON(t,r){r=r||{};let n,i;if("$binary"in t?r.legacy&&typeof t.$binary=="string"&&"$type"in t?(i=t.$type?parseInt(t.$type,16):0,n=l.fromBase64(t.$binary)):typeof t.$binary!="string"&&(i=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=l.fromBase64(t.$binary.base64)):"$uuid"in t&&(i=4,n=Y.bytesFromString(t.$uuid)),!n)throw new c(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return i===Lt?new Y(n):new e(n,i)}inspect(t,r,n){n??=F;let i=l.toBase64(this.buffer.subarray(0,this.position)),o=n(i,r),h=n(this.sub_type,r);return`Binary.createFromBase64(${o}, ${h})`}};_.BSON_BINARY_SUBTYPE_DEFAULT=0;_.BUFFER_SIZE=256;_.SUBTYPE_DEFAULT=0;_.SUBTYPE_FUNCTION=1;_.SUBTYPE_BYTE_ARRAY=2;_.SUBTYPE_UUID_OLD=3;_.SUBTYPE_UUID=4;_.SUBTYPE_MD5=5;_.SUBTYPE_ENCRYPTED=6;_.SUBTYPE_COLUMN=7;_.SUBTYPE_SENSITIVE=8;_.SUBTYPE_USER_DEFINED=128;var Ut=16,dn=/^[0-9A-F]{32}$/i,Tn=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,Y=class e extends _{constructor(t){let r;if(t==null)r=e.generate();else if(t instanceof e)r=l.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&t.byteLength===Ut)r=l.toLocalBufferType(t);else if(typeof t=="string")r=e.bytesFromString(t);else throw new c("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).");super(r,Lt)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[l.toHex(this.buffer.subarray(0,4)),l.toHex(this.buffer.subarray(4,6)),l.toHex(this.buffer.subarray(6,8)),l.toHex(this.buffer.subarray(8,10)),l.toHex(this.buffer.subarray(10,16))].join("-"):l.toHex(this.buffer)}toString(t){return t==="hex"?l.toHex(this.id):t==="base64"?l.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof e)return l.equals(t.id,this.id);try{return l.equals(new e(t).id,this.id)}catch{return!1}}toBinary(){return new _(this.id,_.SUBTYPE_UUID)}static generate(){let t=l.randomBytes(Ut);return t[6]=t[6]&15|64,t[8]=t[8]&63|128,t}static isValid(t){return t?typeof t=="string"?e.isValidUUIDString(t):ht(t)?t.byteLength===Ut:t._bsontype==="Binary"&&t.sub_type===this.SUBTYPE_UUID&&t.buffer.byteLength===16:!1}static createFromHexString(t){let r=e.bytesFromString(t);return new e(r)}static createFromBase64(t){return new e(l.fromBase64(t))}static bytesFromString(t){if(!e.isValidUUIDString(t))throw new c("UUID string representation must be 32 hex digits or canonical hyphenated representation");return l.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return dn.test(t)||Tn.test(t)}inspect(t,r,n){return n??=F,`new UUID(${n(this.toHexString(),r)})`}},q=class e extends x{get _bsontype(){return"Code"}constructor(t,r){super(),this.code=t.toString(),this.scope=r??null}toJSON(){return this.scope!=null?{code:this.code,scope:this.scope}:{code:this.code}}toExtendedJSON(){return this.scope?{$code:this.code,$scope:this.scope}:{$code:this.code}}static fromExtendedJSON(t){return new e(t.$code,t.$scope)}inspect(t,r,n){n??=F;let i=n(this.code,r),o=i.includes(`
`);this.scope!=null&&(i+=`,${o?`
`:" "}${n(this.scope,r)}`);let h=o&&this.scope===null;return`new Code(${o?`
`:""}${i}${h?`
`:""})`}};function We(e){return e!=null&&typeof e=="object"&&"$id"in e&&e.$id!=null&&"$ref"in e&&typeof e.$ref=="string"&&(!("$db"in e)||"$db"in e&&typeof e.$db=="string")}var V=class e extends x{get _bsontype(){return"DBRef"}constructor(t,r,n,i){super();let o=t.split(".");o.length===2&&(n=o.shift(),t=o.shift()),this.collection=t,this.oid=r,this.db=n,this.fields=i||{}}get namespace(){return this.collection}set namespace(t){this.collection=t}toJSON(){let t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return this.db!=null&&(t.$db=this.db),t}toExtendedJSON(t){t=t||{};let r={$ref:this.collection,$id:this.oid};return t.legacy||(this.db&&(r.$db=this.db),r=Object.assign(r,this.fields)),r}static fromExtendedJSON(t){let r=Object.assign({},t);return delete r.$ref,delete r.$id,delete r.$db,new e(t.$ref,t.$id,t.$db,r)}inspect(t,r,n){n??=F;let i=[n(this.namespace,r),n(this.oid,r),...this.db?[n(this.db,r)]:[],...Object.keys(this.fields).length>0?[n(this.fields,r)]:[]];return i[1]=n===F?`new ObjectId(${i[1]})`:i[1],`new DBRef(${i.join(", ")})`}};function ke(e){if(e==="")return e;let t=0,r=e[t]==="-",n=e[t]==="+";(n||r)&&(t+=1);let i=!1;for(;t<e.length&&e[t]==="0";++t)i=!0;return i?`${r?"-":""}${e.length===t?"0":e.slice(t)}`:n?e.slice(1):e}function Ln(e,t){t=t??10;let r="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,t);return new RegExp(`[^-+${r}]`,"i").test(e)?!1:e}var J;try{J=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{}var ue=65536,$n=1<<24,at=ue*ue,Ye=at*at,ae=Ye/2,me={},ye={},An=20,Un=/^(\+?0|(\+|-)?[1-9][0-9]*)$/,y=class e extends x{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(t=0,r,n){super();let i=typeof r=="boolean"?r:!!n,o=typeof r=="number"?r:0,h=typeof t=="string"?e.fromString(t,i):typeof t=="bigint"?e.fromBigInt(t,i):{low:t|0,high:o|0,unsigned:i};this.low=h.low,this.high=h.high,this.unsigned=h.unsigned}static fromBits(t,r,n){return new e(t,r,n)}static fromInt(t,r){let n,i,o;return r?(t>>>=0,(o=0<=t&&t<256)&&(i=ye[t],i)?i:(n=e.fromBits(t,(t|0)<0?-1:0,!0),o&&(ye[t]=n),n)):(t|=0,(o=-128<=t&&t<128)&&(i=me[t],i)?i:(n=e.fromBits(t,t<0?-1:0,!1),o&&(me[t]=n),n))}static fromNumber(t,r){if(isNaN(t))return r?e.UZERO:e.ZERO;if(r){if(t<0)return e.UZERO;if(t>=Ye)return e.MAX_UNSIGNED_VALUE}else{if(t<=-ae)return e.MIN_VALUE;if(t+1>=ae)return e.MAX_VALUE}return t<0?e.fromNumber(-t,r).neg():e.fromBits(t%at|0,t/at|0,r)}static fromBigInt(t,r){let n=BigInt(4294967295),i=BigInt(32);return new e(Number(t&n),Number(t>>i&n),r)}static _fromString(t,r,n){if(t.length===0)throw new c("empty string");if(n<2||36<n)throw new c("radix");let i;if((i=t.indexOf("-"))>0)throw new c("interior hyphen");if(i===0)return e._fromString(t.substring(1),r,n).neg();let o=e.fromNumber(Math.pow(n,8)),h=e.ZERO;for(let u=0;u<t.length;u+=8){let s=Math.min(8,t.length-u),S=parseInt(t.substring(u,u+s),n);if(s<8){let a=e.fromNumber(Math.pow(n,s));h=h.mul(a).add(e.fromNumber(S))}else h=h.mul(o),h=h.add(e.fromNumber(S))}return h.unsigned=r,h}static fromStringStrict(t,r,n){let i=!1;if(typeof r=="number"?(n=r,r=!1):i=!!r,n??=10,t.trim()!==t)throw new c(`Input: '${t}' contains leading and/or trailing whitespace`);if(!Ln(t,n))throw new c(`Input: '${t}' contains invalid characters for radix: ${n}`);let o=ke(t),h=e._fromString(o,i,n);if(h.toString(n).toLowerCase()!==o.toLowerCase())throw new c(`Input: ${t} is not representable as ${h.unsigned?"an unsigned":"a signed"} 64-bit Long ${n!=null?`with radix: ${n}`:""}`);return h}static fromString(t,r,n){let i=!1;return typeof r=="number"?(n=r,r=!1):i=!!r,n??=10,t==="NaN"&&n<24||(t==="Infinity"||t==="+Infinity"||t==="-Infinity")&&n<35?e.ZERO:e._fromString(t,i,n)}static fromBytes(t,r,n){return n?e.fromBytesLE(t,r):e.fromBytesBE(t,r)}static fromBytesLE(t,r){return new e(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,r)}static fromBytesBE(t,r){return new e(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],r)}static isLong(t){return t!=null&&typeof t=="object"&&"__isLong__"in t&&t.__isLong__===!0}static fromValue(t,r){return typeof t=="number"?e.fromNumber(t,r):typeof t=="string"?e.fromString(t,r):e.fromBits(t.low,t.high,typeof r=="boolean"?r:t.unsigned)}add(t){e.isLong(t)||(t=e.fromValue(t));let r=this.high>>>16,n=this.high&65535,i=this.low>>>16,o=this.low&65535,h=t.high>>>16,u=t.high&65535,s=t.low>>>16,S=t.low&65535,a=0,f=0,g=0,p=0;return p+=o+S,g+=p>>>16,p&=65535,g+=i+s,f+=g>>>16,g&=65535,f+=n+u,a+=f>>>16,f&=65535,a+=r+h,a&=65535,e.fromBits(g<<16|p,a<<16|f,this.unsigned)}and(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(e.isLong(t)||(t=e.fromValue(t)),this.eq(t))return 0;let r=this.isNegative(),n=t.isNegative();return r&&!n?-1:!r&&n?1:this.unsigned?t.high>>>0>this.high>>>0||t.high===this.high&&t.low>>>0>this.low>>>0?-1:1:this.sub(t).isNegative()?-1:1}comp(t){return this.compare(t)}divide(t){if(e.isLong(t)||(t=e.fromValue(t)),t.isZero())throw new c("division by zero");if(J){if(!this.unsigned&&this.high===-2147483648&&t.low===-1&&t.high===-1)return this;let o=(this.unsigned?J.div_u:J.div_s)(this.low,this.high,t.low,t.high);return e.fromBits(o,J.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?e.UZERO:e.ZERO;let r,n,i;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return e.UZERO;if(t.gt(this.shru(1)))return e.UONE;i=e.UZERO}else{if(this.eq(e.MIN_VALUE))return t.eq(e.ONE)||t.eq(e.NEG_ONE)?e.MIN_VALUE:t.eq(e.MIN_VALUE)?e.ONE:(r=this.shr(1).div(t).shl(1),r.eq(e.ZERO)?t.isNegative()?e.ONE:e.NEG_ONE:(n=this.sub(t.mul(r)),i=r.add(n.div(t)),i));if(t.eq(e.MIN_VALUE))return this.unsigned?e.UZERO:e.ZERO;if(this.isNegative())return t.isNegative()?this.neg().div(t.neg()):this.neg().div(t).neg();if(t.isNegative())return this.div(t.neg()).neg();i=e.ZERO}for(n=this;n.gte(t);){r=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));let o=Math.ceil(Math.log(r)/Math.LN2),h=o<=48?1:Math.pow(2,o-48),u=e.fromNumber(r),s=u.mul(t);for(;s.isNegative()||s.gt(n);)r-=h,u=e.fromNumber(r,this.unsigned),s=u.mul(t);u.isZero()&&(u=e.ONE),i=i.add(u),n=n.sub(s)}return i}div(t){return this.divide(t)}equals(t){return e.isLong(t)||(t=e.fromValue(t)),this.unsigned!==t.unsigned&&this.high>>>31===1&&t.high>>>31===1?!1:this.high===t.high&&this.low===t.low}eq(t){return this.equals(t)}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(e.MIN_VALUE)?64:this.neg().getNumBitsAbs();let t=this.high!==0?this.high:this.low,r;for(r=31;r>0&&!(t&1<<r);r--);return this.high!==0?r+33:r+1}greaterThan(t){return this.comp(t)>0}gt(t){return this.greaterThan(t)}greaterThanOrEqual(t){return this.comp(t)>=0}gte(t){return this.greaterThanOrEqual(t)}ge(t){return this.greaterThanOrEqual(t)}isEven(){return(this.low&1)===0}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return(this.low&1)===1}isPositive(){return this.unsigned||this.high>=0}isZero(){return this.high===0&&this.low===0}lessThan(t){return this.comp(t)<0}lt(t){return this.lessThan(t)}lessThanOrEqual(t){return this.comp(t)<=0}lte(t){return this.lessThanOrEqual(t)}modulo(t){if(e.isLong(t)||(t=e.fromValue(t)),J){let r=(this.unsigned?J.rem_u:J.rem_s)(this.low,this.high,t.low,t.high);return e.fromBits(r,J.get_high(),this.unsigned)}return this.sub(this.div(t).mul(t))}mod(t){return this.modulo(t)}rem(t){return this.modulo(t)}multiply(t){if(this.isZero())return e.ZERO;if(e.isLong(t)||(t=e.fromValue(t)),J){let w=J.mul(this.low,this.high,t.low,t.high);return e.fromBits(w,J.get_high(),this.unsigned)}if(t.isZero())return e.ZERO;if(this.eq(e.MIN_VALUE))return t.isOdd()?e.MIN_VALUE:e.ZERO;if(t.eq(e.MIN_VALUE))return this.isOdd()?e.MIN_VALUE:e.ZERO;if(this.isNegative())return t.isNegative()?this.neg().mul(t.neg()):this.neg().mul(t).neg();if(t.isNegative())return this.mul(t.neg()).neg();if(this.lt(e.TWO_PWR_24)&&t.lt(e.TWO_PWR_24))return e.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);let r=this.high>>>16,n=this.high&65535,i=this.low>>>16,o=this.low&65535,h=t.high>>>16,u=t.high&65535,s=t.low>>>16,S=t.low&65535,a=0,f=0,g=0,p=0;return p+=o*S,g+=p>>>16,p&=65535,g+=i*S,f+=g>>>16,g&=65535,g+=o*s,f+=g>>>16,g&=65535,f+=n*S,a+=f>>>16,f&=65535,f+=i*s,a+=f>>>16,f&=65535,f+=o*u,a+=f>>>16,f&=65535,a+=r*S+n*s+i*u+o*h,a&=65535,e.fromBits(g<<16|p,a<<16|f,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(e.MIN_VALUE)?e.MIN_VALUE:this.not().add(e.ONE)}neg(){return this.negate()}not(){return e.fromBits(~this.low,~this.high,this.unsigned)}notEquals(t){return!this.equals(t)}neq(t){return this.notEquals(t)}ne(t){return this.notEquals(t)}or(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return e.isLong(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?e.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):e.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return e.isLong(t)&&(t=t.toInt()),(t&=63)===0?this:t<32?e.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):e.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(e.isLong(t)&&(t=t.toInt()),t&=63,t===0)return this;{let r=this.high;if(t<32){let n=this.low;return e.fromBits(n>>>t|r<<32-t,r>>>t,this.unsigned)}else return t===32?e.fromBits(r,0,this.unsigned):e.fromBits(r>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return e.isLong(t)||(t=e.fromValue(t)),this.add(t.neg())}sub(t){return this.subtract(t)}toInt(){return this.unsigned?this.low>>>0:this.low}toNumber(){return this.unsigned?(this.high>>>0)*at+(this.low>>>0):this.high*at+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(t){return t?this.toBytesLE():this.toBytesBE()}toBytesLE(){let t=this.high,r=this.low;return[r&255,r>>>8&255,r>>>16&255,r>>>24,t&255,t>>>8&255,t>>>16&255,t>>>24]}toBytesBE(){let t=this.high,r=this.low;return[t>>>24,t>>>16&255,t>>>8&255,t&255,r>>>24,r>>>16&255,r>>>8&255,r&255]}toSigned(){return this.unsigned?e.fromBits(this.low,this.high,!1):this}toString(t){if(t=t||10,t<2||36<t)throw new c("radix");if(this.isZero())return"0";if(this.isNegative())if(this.eq(e.MIN_VALUE)){let o=e.fromNumber(t),h=this.div(o),u=h.mul(o).sub(this);return h.toString(t)+u.toInt().toString(t)}else return"-"+this.neg().toString(t);let r=e.fromNumber(Math.pow(t,6),this.unsigned),n=this,i="";for(;;){let o=n.div(r),u=(n.sub(o.mul(r)).toInt()>>>0).toString(t);if(n=o,n.isZero())return u+i;for(;u.length<6;)u="0"+u;i=""+u+i}}toUnsigned(){return this.unsigned?this:e.fromBits(this.low,this.high,!0)}xor(t){return e.isLong(t)||(t=e.fromValue(t)),e.fromBits(this.low^t.low,this.high^t.high,this.unsigned)}eqz(){return this.isZero()}le(t){return this.lessThanOrEqual(t)}toExtendedJSON(t){return t&&t.relaxed?this.toNumber():{$numberLong:this.toString()}}static fromExtendedJSON(t,r){let{useBigInt64:n=!1,relaxed:i=!0}={...r};if(t.$numberLong.length>An)throw new c("$numberLong string is too long");if(!Un.test(t.$numberLong))throw new c(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){let h=BigInt(t.$numberLong);return BigInt.asIntN(64,h)}let o=e.fromString(t.$numberLong);return i?o.toNumber():o}inspect(t,r,n){n??=F;let i=n(this.toString(),r),o=this.unsigned?`, ${n(this.unsigned,r)}`:"";return`new Long(${i}${o})`}};y.TWO_PWR_24=y.fromInt($n);y.MAX_UNSIGNED_VALUE=y.fromBits(-1,-1,!0);y.ZERO=y.fromInt(0);y.UZERO=y.fromInt(0,!0);y.ONE=y.fromInt(1);y.UONE=y.fromInt(1,!0);y.NEG_ONE=y.fromInt(-1);y.MAX_VALUE=y.fromBits(-1,2147483647,!1);y.MIN_VALUE=y.fromBits(0,-2147483648,!1);var _n=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,Dn=/^(\+|-)?(Infinity|inf)$/i,Rn=/^(\+|-)?NaN$/i,ct=6111,pt=-6176,we=6176,pe=34,_t=l.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),be=l.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Se=l.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),zn=/^([-+])?(\d+)?$/,jn=31,Ne=16383,Mn=30,xn=31;function Be(e){return!isNaN(parseInt(e,10))}function Fn(e){let t=y.fromNumber(1e9),r=y.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 y(e.parts[n],0)),e.parts[n]=r.div(t).low,r=r.modulo(t);return{quotient:e,rem:r}}function Jn(e,t){if(!e&&!t)return{high:y.fromNumber(0),low:y.fromNumber(0)};let r=e.shiftRightUnsigned(32),n=new y(e.getLowBits(),0),i=t.shiftRightUnsigned(32),o=new y(t.getLowBits(),0),h=r.multiply(i),u=r.multiply(o),s=n.multiply(i),S=n.multiply(o);return h=h.add(u.shiftRightUnsigned(32)),u=new y(u.getLowBits(),0).add(s).add(S.shiftRightUnsigned(32)),h=h.add(u.shiftRightUnsigned(32)),S=u.shiftLeft(32).add(new y(S.getLowBits(),0)),{high:h,low:S}}function Cn(e,t){let r=e.high>>>0,n=t.high>>>0;if(r<n)return!0;if(r===n){let i=e.low>>>0,o=t.low>>>0;if(i<o)return!0}return!1}function H(e,t){throw new c(`"${e}" is not a valid Decimal128 string - ${t}`)}var it=class e extends x{get _bsontype(){return"Decimal128"}constructor(t){if(super(),typeof t=="string")this.bytes=e.fromString(t).bytes;else if(ht(t)){if(t.byteLength!==16)throw new c("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}else throw new c("Decimal128 must take a Buffer or string")}static fromString(t){return e._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return e._fromString(t,{allowRounding:!0})}static _fromString(t,r){let n=!1,i=!1,o=!1,h=!1,u=0,s=0,S=0,a=0,f=0,g=[0],p=0,w=0,I=0,D=0,M=new y(0,0),$=new y(0,0),P=0,b=0;if(t.length>=7e3)throw new c(""+t+" not a valid Decimal128 string");let R=t.match(_n),d=t.match(Dn),E=t.match(Rn);if(!R&&!d&&!E||t.length===0)throw new c(""+t+" not a valid Decimal128 string");if(R){let m=R[2],B=R[4],L=R[5],z=R[6];B&&z===void 0&&H(t,"missing exponent power"),B&&m===void 0&&H(t,"missing exponent base"),B===void 0&&(L||z)&&H(t,"missing e before exponent")}if((t[b]==="+"||t[b]==="-")&&(i=!0,n=t[b++]==="-"),!Be(t[b])&&t[b]!=="."){if(t[b]==="i"||t[b]==="I")return new e(n?be:Se);if(t[b]==="N")return new e(_t)}for(;Be(t[b])||t[b]===".";){if(t[b]==="."){o&&H(t,"contains multiple periods"),o=!0,b=b+1;continue}p<pe&&(t[b]!=="0"||h)&&(h||(f=s),h=!0,g[w++]=parseInt(t[b],10),p=p+1),h&&(S=S+1),o&&(a=a+1),s=s+1,b=b+1}if(o&&!s)throw new c(""+t+" not a valid Decimal128 string");if(t[b]==="e"||t[b]==="E"){let m=t.substr(++b).match(zn);if(!m||!m[2])return new e(_t);D=parseInt(m[0],10),b=b+m[0].length}if(t[b])return new e(_t);if(!p)g[0]=0,S=1,p=1,u=0;else if(I=p-1,u=S,u!==1)for(;t[f+u-1+Number(i)+Number(o)]==="0";)u=u-1;for(D<=a&&a>D+16384?D=pt:D=D-a;D>ct;){if(I=I+1,I>=pe){if(u===0){D=ct;break}H(t,"overflow")}D=D-1}if(r.allowRounding){for(;D<pt||p<S;){if(I===0&&u<p){D=pt,u=0;break}if(p<S?S=S-1:I=I-1,D<ct)D=D+1;else{if(g.join("").match(/^0+$/)){D=ct;break}H(t,"overflow")}}if(I+1<u){let m=s;o&&(f=f+1,m=m+1),i&&(f=f+1,m=m+1);let B=parseInt(t[f+I+1],10),L=0;if(B>=5&&(L=1,B===5)){L=g[I]%2===1?1:0;for(let z=f+I+2;z<m;z++)if(parseInt(t[z],10)){L=1;break}}if(L){let z=I;for(;z>=0&&++g[z]>9;z--)if(g[z]=0,z===0)if(D<ct)D=D+1,g[z]=1;else return new e(n?be:Se)}}}else{for(;D<pt||p<S;){if(I===0){if(u===0){D=pt;break}H(t,"exponent underflow")}p<S?(t[S-1+Number(i)+Number(o)]!=="0"&&u!==0&&H(t,"inexact rounding"),S=S-1):(g[I]!==0&&H(t,"inexact rounding"),I=I-1),D<ct?D=D+1:H(t,"overflow")}I+1<u&&(o&&(f=f+1),i&&(f=f+1),parseInt(t[f+I+1],10)!==0&&H(t,"inexact rounding"))}if(M=y.fromNumber(0),$=y.fromNumber(0),u===0)M=y.fromNumber(0),$=y.fromNumber(0);else if(I<17){let m=0;for($=y.fromNumber(g[m++]),M=new y(0,0);m<=I;m++)$=$.multiply(y.fromNumber(10)),$=$.add(y.fromNumber(g[m]))}else{let m=0;for(M=y.fromNumber(g[m++]);m<=I-17;m++)M=M.multiply(y.fromNumber(10)),M=M.add(y.fromNumber(g[m]));for($=y.fromNumber(g[m++]);m<=I;m++)$=$.multiply(y.fromNumber(10)),$=$.add(y.fromNumber(g[m]))}let j=Jn(M,y.fromString("100000000000000000"));j.low=j.low.add($),Cn(j.low,$)&&(j.high=j.high.add(y.fromNumber(1))),P=D+we;let T={low:y.fromNumber(0),high:y.fromNumber(0)};j.high.shiftRightUnsigned(49).and(y.fromNumber(1)).equals(y.fromNumber(1))?(T.high=T.high.or(y.fromNumber(3).shiftLeft(61)),T.high=T.high.or(y.fromNumber(P).and(y.fromNumber(16383).shiftLeft(47))),T.high=T.high.or(j.high.and(y.fromNumber(0x7fffffffffff)))):(T.high=T.high.or(y.fromNumber(P&16383).shiftLeft(49)),T.high=T.high.or(j.high.and(y.fromNumber(562949953421311)))),T.low=j.low,n&&(T.high=T.high.or(y.fromString("9223372036854775808")));let N=l.allocateUnsafe(16);return b=0,N[b++]=T.low.low&255,N[b++]=T.low.low>>8&255,N[b++]=T.low.low>>16&255,N[b++]=T.low.low>>24&255,N[b++]=T.low.high&255,N[b++]=T.low.high>>8&255,N[b++]=T.low.high>>16&255,N[b++]=T.low.high>>24&255,N[b++]=T.high.low&255,N[b++]=T.high.low>>8&255,N[b++]=T.high.low>>16&255,N[b++]=T.high.low>>24&255,N[b++]=T.high.high&255,N[b++]=T.high.high>>8&255,N[b++]=T.high.high>>16&255,N[b++]=T.high.high>>24&255,new e(N)}toString(){let t,r=0,n=new Array(36);for(let b=0;b<n.length;b++)n[b]=0;let i=0,o=!1,h,u={parts:[0,0,0,0]},s,S,a=[];i=0;let f=this.bytes,g=f[i++]|f[i++]<<8|f[i++]<<16|f[i++]<<24,p=f[i++]|f[i++]<<8|f[i++]<<16|f[i++]<<24,w=f[i++]|f[i++]<<8|f[i++]<<16|f[i++]<<24,I=f[i++]|f[i++]<<8|f[i++]<<16|f[i++]<<24;i=0,{low:new y(g,p),high:new y(w,I)}.high.lessThan(y.ZERO)&&a.push("-");let M=I>>26&jn;if(M>>3===3){if(M===Mn)return a.join("")+"Infinity";if(M===xn)return"NaN";t=I>>15&Ne,h=8+(I>>14&1)}else h=I>>14&7,t=I>>17&Ne;let $=t-we;if(u.parts[0]=(I&16383)+((h&15)<<14),u.parts[1]=w,u.parts[2]=p,u.parts[3]=g,u.parts[0]===0&&u.parts[1]===0&&u.parts[2]===0&&u.parts[3]===0)o=!0;else for(S=3;S>=0;S--){let b=0,R=Fn(u);if(u=R.quotient,b=R.rem.low,!!b)for(s=8;s>=0;s--)n[S*9+s]=b%10,b=Math.floor(b/10)}if(o)r=1,n[i]=0;else for(r=36;!n[i];)r=r-1,i=i+1;let P=r-1+$;if(P>=34||P<=-7||$>0){if(r>34)return a.push("0"),$>0?a.push(`E+${$}`):$<0&&a.push(`E${$}`),a.join("");a.push(`${n[i++]}`),r=r-1,r&&a.push(".");for(let b=0;b<r;b++)a.push(`${n[i++]}`);a.push("E"),P>0?a.push(`+${P}`):a.push(`${P}`)}else if($>=0)for(let b=0;b<r;b++)a.push(`${n[i++]}`);else{let b=r+$;if(b>0)for(let R=0;R<b;R++)a.push(`${n[i++]}`);else a.push("0");for(a.push(".");b++<0;)a.push("0");for(let R=0;R<r-Math.max(b-1,0);R++)a.push(`${n[i++]}`)}return a.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(t){return e.fromString(t.$numberDecimal)}inspect(t,r,n){return n??=F,`new Decimal128(${n(this.toString(),r)})`}},v=class e extends x{get _bsontype(){return"Double"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){let r=Number(t);if(t==="NaN")return new e(NaN);if(t==="Infinity")return new e(1/0);if(t==="-Infinity")return new e(-1/0);if(!Number.isFinite(r))throw new c(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new c(`Input: '${t}' contains whitespace`);if(t==="")throw new c("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new c(`Input: '${t}' is not in decimal or exponential notation`);return new e(r)}valueOf(){return this.value}toJSON(){return this.value}toString(t){return this.value.toString(t)}toExtendedJSON(t){return t&&(t.legacy||t.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(t,r){let n=parseFloat(t.$numberDouble);return r&&r.relaxed?n:new e(n)}inspect(t,r,n){return n??=F,`new Double(${n(this.value,r)})`}},tt=class e extends x{get _bsontype(){return"Int32"}constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t|0}static fromString(t){let r=ke(t),n=Number(t);if(Bt<n)throw new c(`Input: '${t}' is larger than the maximum value for Int32`);if(Et>n)throw new c(`Input: '${t}' is smaller than the minimum value for Int32`);if(Number.isSafeInteger(n)){if(n.toString()!==r)throw new c(`Input: '${t}' is not a valid Int32 string`)}else throw new c(`Input: '${t}' is not a safe integer`);return new e(n)}valueOf(){return this.value}toString(t){return this.value.toString(t)}toJSON(){return this.value}toExtendedJSON(t){return t&&(t.relaxed||t.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(t,r){return r&&r.relaxed?parseInt(t.$numberInt,10):new e(t.$numberInt)}inspect(t,r,n){return n??=F,`new Int32(${n(this.value,r)})`}},st=class e extends x{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new e}inspect(){return"new MaxKey()"}},ot=class e extends x{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new e}inspect(){return"new MinKey()"}},mt=new Float64Array(1),A=new Uint8Array(mt.buffer,0,8);mt[0]=-1;var Ee=A[7]===0,O={getNonnegativeInt32LE(e,t){if(e[t+3]>127)throw new RangeError(`Size cannot be negative at offset: ${t}`);return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},getInt32LE(e,t){return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},getUint32LE(e,t){return e[t]+e[t+1]*256+e[t+2]*65536+e[t+3]*16777216},getUint32BE(e,t){return e[t+3]+e[t+2]*256+e[t+1]*65536+e[t]*16777216},getBigInt64LE(e,t){let r=O.getUint32LE(e,t),n=O.getUint32LE(e,t+4);return(BigInt(n)<<BigInt(32))+BigInt(r)},getFloat64LE:Ee?(e,t)=>(A[7]=e[t],A[6]=e[t+1],A[5]=e[t+2],A[4]=e[t+3],A[3]=e[t+4],A[2]=e[t+5],A[1]=e[t+6],A[0]=e[t+7],mt[0]):(e,t)=>(A[0]=e[t],A[1]=e[t+1],A[2]=e[t+2],A[3]=e[t+3],A[4]=e[t+4],A[5]=e[t+5],A[6]=e[t+6],A[7]=e[t+7],mt[0]),setInt32BE(e,t,r){return e[t+3]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t]=r,4},setInt32LE(e,t,r){return e[t]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+3]=r,4},setBigInt64LE(e,t,r){let n=BigInt(4294967295),i=Number(r&n);e[t]=i,i>>=8,e[t+1]=i,i>>=8,e[t+2]=i,i>>=8,e[t+3]=i;let o=Number(r>>BigInt(32)&n);return e[t+4]=o,o>>=8,e[t+5]=o,o>>=8,e[t+6]=o,o>>=8,e[t+7]=o,8},setFloat64LE:Ee?(e,t,r)=>(mt[0]=r,e[t]=A[7],e[t+1]=A[6],e[t+2]=A[5],e[t+3]=A[4],e[t+4]=A[3],e[t+5]=A[2],e[t+6]=A[1],e[t+7]=A[0],8):(e,t,r)=>(mt[0]=r,e[t]=A[0],e[t+1]=A[1],e[t+2]=A[2],e[t+3]=A[3],e[t+4]=A[4],e[t+5]=A[5],e[t+6]=A[6],e[t+7]=A[7],8)},Pn=new RegExp("^[0-9a-fA-F]{24}$"),nt=null,Z=class e extends x{get _bsontype(){return"ObjectId"}constructor(t){super();let r;if(typeof t=="object"&&t&&"id"in t){if(typeof t.id!="string"&&!ArrayBuffer.isView(t.id))throw new c("Argument passed in must have an id that is of type string or Buffer");"toHexString"in t&&typeof t.toHexString=="function"?r=l.fromHex(t.toHexString()):r=t.id}else r=t;if(r==null||typeof r=="number")this.buffer=e.generate(typeof r=="number"?r:void 0);else if(ArrayBuffer.isView(r)&&r.byteLength===12)this.buffer=l.toLocalBufferType(r);else if(typeof r=="string")if(r.length===24&&Pn.test(r))this.buffer=l.fromHex(r);else throw new c("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");else throw new c("Argument passed in does not match the accepted types");e.cacheHexString&&(this.__id=l.toHex(this.id))}get id(){return this.buffer}set id(t){this.buffer=t,e.cacheHexString&&(this.__id=l.toHex(t))}toHexString(){if(e.cacheHexString&&this.__id)return this.__id;let t=l.toHex(this.id);return e.cacheHexString&&!this.__id&&(this.__id=t),t}static getInc(){return e.index=(e.index+1)%16777215}static generate(t){typeof t!="number"&&(t=Math.floor(Date.now()/1e3));let r=e.getInc(),n=l.allocateUnsafe(12);return O.setInt32BE(n,0,t),nt===null&&(nt=l.randomBytes(5)),n[4]=nt[0],n[5]=nt[1],n[6]=nt[2],n[7]=nt[3],n[8]=nt[4],n[11]=r&255,n[10]=r>>8&255,n[9]=r>>16&255,n}toString(t){return t==="base64"?l.toBase64(this.id):t==="hex"?this.toHexString():this.toHexString()}toJSON(){return this.toHexString()}static is(t){return t!=null&&typeof t=="object"&&"_bsontype"in t&&t._bsontype==="ObjectId"}equals(t){if(t==null)return!1;if(e.is(t))return this.buffer[11]===t.buffer[11]&&l.equals(this.buffer,t.buffer);if(typeof t=="string")return t.toLowerCase()===this.toHexString();if(typeof t=="object"&&typeof t.toHexString=="function"){let r=t.toHexString(),n=this.toHexString();return typeof r=="string"&&r.toLowerCase()===n}return!1}getTimestamp(){let t=new Date,r=O.getUint32BE(this.buffer,0);return t.setTime(Math.floor(r)*1e3),t}static createPk(){return new e}serializeInto(t,r){return t[r]=this.buffer[0],t[r+1]=this.buffer[1],t[r+2]=this.buffer[2],t[r+3]=this.buffer[3],t[r+4]=this.buffer[4],t[r+5]=this.buffer[5],t[r+6]=this.buffer[6],t[r+7]=this.buffer[7],t[r+8]=this.buffer[8],t[r+9]=this.buffer[9],t[r+10]=this.buffer[10],t[r+11]=this.buffer[11],12}static createFromTime(t){let r=l.allocate(12);for(let n=11;n>=4;n--)r[n]=0;return O.setInt32BE(r,0,t),new e(r)}static createFromHexString(t){if(t?.length!==24)throw new c("hex string must be 24 characters");return new e(l.fromHex(t))}static createFromBase64(t){if(t?.length!==16)throw new c("base64 string must be 16 characters");return new e(l.fromBase64(t))}static isValid(t){if(t==null)return!1;try{return new e(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new e(t.$oid)}inspect(t,r,n){return n??=F,`new ObjectId(${n(this.toHexString(),r)})`}};Z.index=Math.floor(Math.random()*16777215);function It(e,t,r){let n=5;if(Array.isArray(e))for(let i=0;i<e.length;i++)n+=Oe(i.toString(),e[i],t,!0,r);else{typeof e?.toBSON=="function"&&(e=e.toBSON());for(let i of Object.keys(e))n+=Oe(i,e[i],t,!1,r)}return n}function Oe(e,t,r=!1,n=!1,i=!1){switch(typeof t?.toBSON=="function"&&(t=t.toBSON()),typeof t){case"string":return 1+l.utf8ByteLength(e)+1+4+l.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=Ae&&t<=$e&&t>=Et&&t<=Bt?(e!=null?l.utf8ByteLength(e)+1:0)+5:(e!=null?l.utf8ByteLength(e)+1:0)+9;case"undefined":return n||!i?(e!=null?l.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(e!=null?l.utf8ByteLength(e)+1:0)+2;case"object":if(t!=null&&typeof t._bsontype=="string"&&t[Symbol.for("@@mdb.bson.version")]!==rt)throw new k;if(t==null||t._bsontype==="MinKey"||t._bsontype==="MaxKey")return(e!=null?l.utf8ByteLength(e)+1:0)+1;if(t._bsontype==="ObjectId")return(e!=null?l.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||ut(t))return(e!=null?l.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||te(t))return(e!=null?l.utf8ByteLength(e)+1:0)+6+t.byteLength;if(t._bsontype==="Long"||t._bsontype==="Double"||t._bsontype==="Timestamp")return(e!=null?l.utf8ByteLength(e)+1:0)+9;if(t._bsontype==="Decimal128")return(e!=null?l.utf8ByteLength(e)+1:0)+17;if(t._bsontype==="Code")return t.scope!=null&&Object.keys(t.scope).length>0?(e!=null?l.utf8ByteLength(e)+1:0)+1+4+4+l.utf8ByteLength(t.code.toString())+1+It(t.scope,r,i):(e!=null?l.utf8ByteLength(e)+1:0)+1+4+l.utf8ByteLength(t.code.toString())+1;if(t._bsontype==="Binary"){let o=t;return o.sub_type===_.SUBTYPE_BYTE_ARRAY?(e!=null?l.utf8ByteLength(e)+1:0)+(o.position+1+4+1+4):(e!=null?l.utf8ByteLength(e)+1:0)+(o.position+1+4+1)}else{if(t._bsontype==="Symbol")return(e!=null?l.utf8ByteLength(e)+1:0)+l.utf8ByteLength(t.value)+4+1+1;if(t._bsontype==="DBRef"){let o=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return t.db!=null&&(o.$db=t.db),(e!=null?l.utf8ByteLength(e)+1:0)+1+It(o,r,i)}else return t instanceof RegExp||gt(t)?(e!=null?l.utf8ByteLength(e)+1:0)+1+l.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:t._bsontype==="BSONRegExp"?(e!=null?l.utf8ByteLength(e)+1:0)+1+l.utf8ByteLength(t.pattern)+1+l.utf8ByteLength(t.options)+1:(e!=null?l.utf8ByteLength(e)+1:0)+It(t,r,i)+1}case"function":if(r)return(e!=null?l.utf8ByteLength(e)+1:0)+1+4+l.utf8ByteLength(t.toString())+1}return 0}function Hn(e){return e.split("").sort().join("")}var K=class e extends x{get _bsontype(){return"BSONRegExp"}constructor(t,r){if(super(),this.pattern=t,this.options=Hn(r??""),this.pattern.indexOf("\0")!==-1)throw new c(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(this.options.indexOf("\0")!==-1)throw new c(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let n=0;n<this.options.length;n++)if(!(this.options[n]==="i"||this.options[n]==="m"||this.options[n]==="x"||this.options[n]==="l"||this.options[n]==="s"||this.options[n]==="u"))throw new c(`The regular expression option [${this.options[n]}] is not supported`)}static parseOptions(t){return t?t.split("").sort().join(""):""}toExtendedJSON(t){return t=t||{},t.legacy?{$regex:this.pattern,$options:this.options}:{$regularExpression:{pattern:this.pattern,options:this.options}}}static fromExtendedJSON(t){if("$regex"in t)if(typeof t.$regex!="string"){if(t.$regex._bsontype==="BSONRegExp")return t}else return new e(t.$regex,e.parseOptions(t.$options));if("$regularExpression"in t)return new e(t.$regularExpression.pattern,e.parseOptions(t.$regularExpression.options));throw new c(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(t)}`)}inspect(t,r,n){let i=mn(r)??(u=>u);n??=F;let o=i(n(this.pattern),"regexp"),h=i(n(this.options),"regexp");return`new BSONRegExp(${o}, ${h})`}},ft=class e extends x{get _bsontype(){return"BSONSymbol"}constructor(t){super(),this.value=t}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(t){return new e(t.$symbol)}inspect(t,r,n){return n??=F,`new BSONSymbol(${n(this.value,r)})`}},Vn=y,et=class e extends Vn{get _bsontype(){return"Timestamp"}constructor(t){if(t==null)super(0,0,!0);else if(typeof t=="bigint")super(t,!0);else if(y.isLong(t))super(t.low,t.high,!0);else if(typeof t=="object"&&"t"in t&&"i"in t){if(typeof t.t!="number"&&(typeof t.t!="object"||t.t._bsontype!=="Int32"))throw new c("Timestamp constructed from { t, i } must provide t as a number");if(typeof t.i!="number"&&(typeof t.i!="object"||t.i._bsontype!=="Int32"))throw new c("Timestamp constructed from { t, i } must provide i as a number");let r=Number(t.t),n=Number(t.i);if(r<0||Number.isNaN(r))throw new c("Timestamp constructed from { t, i } must provide a positive t");if(n<0||Number.isNaN(n))throw new c("Timestamp constructed from { t, i } must provide a positive i");if(r>4294967295)throw new c("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(n>4294967295)throw new c("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(n,r,!0)}else throw new c("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }")}toJSON(){return{$timestamp:this.toString()}}static fromInt(t){return new e(y.fromInt(t,!0))}static fromNumber(t){return new e(y.fromNumber(t,!0))}static fromBits(t,r){return new e({i:t,t:r})}static fromString(t,r){return new e(y.fromString(t,!0,r))}toExtendedJSON(){return{$timestamp:{t:this.high>>>0,i:this.low>>>0}}}static fromExtendedJSON(t){let r=y.isLong(t.$timestamp.i)?t.$timestamp.i.getLowBitsUnsigned():t.$timestamp.i,n=y.isLong(t.$timestamp.t)?t.$timestamp.t.getLowBitsUnsigned():t.$timestamp.t;return new e({t:n,i:r})}inspect(t,r,n){n??=F;let i=n(this.high>>>0,r),o=n(this.low>>>0,r);return`new Timestamp({ t: ${i}, i: ${o} })`}};et.MAX_VALUE=y.MAX_UNSIGNED_VALUE;var Wn=y.fromNumber($e),kn=y.fromNumber(Ae);function qe(e,t,r){t=t??{};let n=t&&t.index?t.index:0,i=O.getInt32LE(e,n);if(i<5)throw new c(`bson size must be >= 5, is ${i}`);if(t.allowObjectSmallerThanBufferSize&&e.length<i)throw new c(`buffer length ${e.length} must be >= bson size ${i}`);if(!t.allowObjectSmallerThanBufferSize&&e.length!==i)throw new c(`buffer length ${e.length} must === bson size ${i}`);if(i+n>e.byteLength)throw new c(`(bson size ${i} + options.index ${n} must be <= buffer length ${e.byteLength})`);if(e[n+i-1]!==0)throw new c("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");return dt(e,n,t,r)}var Yn=/^\$ref$|^\$id$|^\$db$/;function dt(e,t,r,n=!1){let i=r.fieldsAsRaw==null?null:r.fieldsAsRaw,o=r.raw==null?!1:r.raw,h=typeof r.bsonRegExp=="boolean"?r.bsonRegExp:!1,u=r.promoteBuffers??!1,s=r.promoteLongs??!0,S=r.promoteValues??!0,a=r.useBigInt64??!1;if(a&&!S)throw new c("Must either request bigint or Long for int64 deserialization");if(a&&!s)throw new c("Must either request bigint or Long for int64 deserialization");let f=r.validation==null?{utf8:!0}:r.validation,g=!0,p,w,I=f.utf8;if(typeof I=="boolean")p=I;else{g=!1;let d=Object.keys(I).map(function(E){return I[E]});if(d.length===0)throw new c("UTF-8 validation setting cannot be empty");if(typeof d[0]!="boolean")throw new c("Invalid UTF-8 validation option, must specify boolean values");if(p=d[0],!d.every(E=>E===p))throw new c("Invalid UTF-8 validation option - keys must be all true or all false")}if(!g){w=new Set;for(let d of Object.keys(I))w.add(d)}let D=t;if(e.length<5)throw new c("corrupt bson message < 5 bytes long");let M=O.getInt32LE(e,t);if(t+=4,M<5||M>e.length)throw new c("corrupt bson message");let $=n?[]:{},P=0,b=!1,R=n?!1:null;for(;!b;){let d=e[t++];if(d===0)break;let E=t;for(;e[E]!==0&&E<e.length;)E++;if(E>=e.byteLength)throw new c("Bad BSON Document: illegal CString");let j=n?P++:l.toUTF8(e,t,E,!1),T=!0;g||w?.has(j)?T=p:T=!p,R!==!1&&j[0]==="$"&&(R=Yn.test(j));let N;if(t=E+1,d===Ue){let m=O.getInt32LE(e,t);if(t+=4,m<=0||m>e.length-t||e[t+m-1]!==0)throw new c("bad string length in bson");N=l.toUTF8(e,t,t+m-1,T),t=t+m}else if(d===De){let m=l.allocateUnsafe(12);for(let B=0;B<12;B++)m[B]=e[t+B];N=new Z(m),t=t+12}else if(d===St&&S===!1)N=new tt(O.getInt32LE(e,t)),t+=4;else if(d===St)N=O.getInt32LE(e,t),t+=4;else if(d===ne)N=O.getFloat64LE(e,t),t+=8,S===!1&&(N=new v(N));else if(d===ze){let m=O.getInt32LE(e,t),B=O.getInt32LE(e,t+4);t+=8,N=new Date(new y(m,B).toNumber())}else if(d===Re){if(e[t]!==0&&e[t]!==1)throw new c("illegal boolean type value");N=e[t++]===1}else if(d===re){let m=t,B=O.getInt32LE(e,t);if(B<=0||B>e.length-t)throw new c("bad embedded document length in bson");if(o)N=e.slice(t,t+B);else{let L=r;g||(L={...r,validation:{utf8:T}}),N=dt(e,m,L,!1)}t=t+B}else if(d===_e){let m=t,B=O.getInt32LE(e,t),L=r,z=t+B;if(i&&i[j]&&(L={...r,raw:!0}),g||(L={...L,validation:{utf8:T}}),N=dt(e,m,L,!0),t=t+B,e[t-1]!==0)throw new c("invalid array terminator byte");if(t!==z)throw new c("corrupted array bson")}else if(d===yn)N=void 0;else if(d===se)N=null;else if(d===fe)if(a)N=O.getBigInt64LE(e,t),t+=8;else{let m=O.getInt32LE(e,t),B=O.getInt32LE(e,t+4);t+=8;let L=new y(m,B);s&&S===!0?N=L.lessThanOrEqual(Wn)&&L.greaterThanOrEqual(kn)?L.toNumber():L:N=L}else if(d===Fe){let m=l.allocateUnsafe(16);for(let B=0;B<16;B++)m[B]=e[t+B];t=t+16,N=new it(m)}else if(d===ie){let m=O.getInt32LE(e,t);t+=4;let B=m,L=e[t++];if(m<0)throw new c("Negative binary type element size found");if(m>e.byteLength)throw new c("Binary type size larger than document size");if(e.slice!=null){if(L===_.SUBTYPE_BYTE_ARRAY){if(m=O.getInt32LE(e,t),t+=4,m<0)throw new c("Negative binary type element size found for subtype 0x02");if(m>B-4)throw new c("Binary type with subtype 0x02 contains too long binary size");if(m<B-4)throw new c("Binary type with subtype 0x02 contains too short binary size")}u&&S?N=l.toLocalBufferType(e.slice(t,t+m)):(N=new _(e.slice(t,t+m),L),L===Lt&&Y.isValid(N)&&(N=N.toUUID()))}else{if(L===_.SUBTYPE_BYTE_ARRAY){if(m=O.getInt32LE(e,t),t+=4,m<0)throw new c("Negative binary type element size found for subtype 0x02");if(m>B-4)throw new c("Binary type with subtype 0x02 contains too long binary size");if(m<B-4)throw new c("Binary type with subtype 0x02 contains too short binary size")}if(u&&S)for(N=l.allocateUnsafe(m),E=0;E<m;E++)N[E]=e[t+E];else N=new _(e.slice(t,t+m),L),L===Lt&&Y.isValid(N)&&(N=N.toUUID())}t=t+m}else if(d===Tt&&h===!1){for(E=t;e[E]!==0&&E<e.length;)E++;if(E>=e.length)throw new c("Bad BSON Document: illegal CString");let m=l.toUTF8(e,t,E,!1);for(t=E+1,E=t;e[E]!==0&&E<e.length;)E++;if(E>=e.length)throw new c("Bad BSON Document: illegal CString");let B=l.toUTF8(e,t,E,!1);t=E+1;let L=new Array(B.length);for(E=0;E<B.length;E++)switch(B[E]){case"m":L[E]="m";break;case"s":L[E]="g";break;case"i":L[E]="i";b