UNPKG

@shivamjha1288/logs-manager

Version:

A lightweight logging library for Express applications that supports both MongoDB and Kafka for log storage and streaming. Automatically logs API requests and provides functionality for manual logging.

1 lines 1.61 MB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("stream"),t=require("events"),r=require("util"),n=require("crypto"),o=require("fs"),i=require("http"),s=require("timers"),a=require("url"),u=require("dns"),c=require("os"),l=require("process"),h=require("zlib"),p=require("net"),d=require("fs/promises"),f=require("tls"),m=require("child_process"),y=require("timers/promises"),g=require("assert"),E=require("tty"),w=require("node:async_hooks");function A(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var b=A(e),O=A(t),C=A(r),S=A(n),_=A(o),v=A(i),T=A(s),I=A(a),D=A(u),M=A(c),B=A(l),N=A(h),F=A(p),P=A(d),R=A(f),x=A(m),$=A(y),k=A(g),j=A(E),L=A(w),U="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function V(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function q(e){if(Object.prototype.hasOwnProperty.call(e,"__esModule"))return e;var t=e.default;if("function"==typeof t){var r=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})})),r}var W,G,z={exports:{}},K={},H={},J={},Q={};function Y(){if(W)return Q;W=1;const e=(()=>{const e=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return t=>e.call(t)})();function t(t){return"Uint8Array"===e(t)}function r(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&("ArrayBuffer"===e[Symbol.toStringTag]||"SharedArrayBuffer"===e[Symbol.toStringTag])}function n(e){return e instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(e)}function o(e){return"object"==typeof e&&null!=e&&Symbol.toStringTag in e&&"Map"===e[Symbol.toStringTag]}function i(e){return e instanceof Date||"[object Date]"===Object.prototype.toString.call(e)}function s(e,t){return JSON.stringify(e,((e,t)=>"bigint"==typeof t?{$numberLong:`${t}`}:o(t)?Object.fromEntries(t):t))}const a=Symbol.for("@@mdb.bson.version"),u=2147483647,c=-2147483648,l=Math.pow(2,63)-1,h=-Math.pow(2,63),p=Math.pow(2,53),d=-Math.pow(2,53),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 m extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(e,t){super(e,t)}static isBSONError(e){return null!=e&&"object"==typeof e&&"bsonError"in e&&!0===e.bsonError&&"name"in e&&"message"in e&&"stack"in e}}class y extends m{get name(){return"BSONVersionError"}constructor(){super("Unsupported BSON version, bson types must be from bson 6.x.x")}}class g extends m{get name(){return"BSONRuntimeError"}constructor(e){super(e)}}class E extends m{get name(){return"BSONOffsetError"}constructor(e,t,r){super(`${e}. offset: ${t}`,r),this.offset=t}}let w,A;function b(e,t,r,n){if(n){w??=new TextDecoder("utf8",{fatal:!0});try{return w.decode(e.subarray(t,r))}catch(e){throw new m("Invalid UTF-8 string in BSON document",{cause:e})}}return A??=new TextDecoder("utf8",{fatal:!1}),A.decode(e.subarray(t,r))}function O(e,t,r){if(0===e.length)return"";const n=r-t;if(0===n)return"";if(n>20)return null;if(1===n&&e[t]<128)return String.fromCharCode(e[t]);if(2===n&&e[t]<128&&e[t+1]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1]);if(3===n&&e[t]<128&&e[t+1]<128&&e[t+2]<128)return String.fromCharCode(e[t])+String.fromCharCode(e[t+1])+String.fromCharCode(e[t+2]);const o=[];for(let n=t;n<r;n++){const t=e[n];if(t>127)return null;o.push(t)}return String.fromCharCode(...o)}function C(e){return _.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const S=(()=>{try{return require("crypto").randomBytes}catch{return C}})(),_={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 m("Cannot create Buffer from the passed potentialBuffer.")},allocate:e=>Buffer.alloc(e),allocateUnsafe:e=>Buffer.allocUnsafe(e),equals:(e,t)=>_.toLocalBufferType(e).equals(t),fromNumberArray:e=>Buffer.from(e),fromBase64:e=>Buffer.from(e,"base64"),toBase64:e=>_.toLocalBufferType(e).toString("base64"),fromISO88591:e=>Buffer.from(e,"binary"),toISO88591:e=>_.toLocalBufferType(e).toString("binary"),fromHex:e=>Buffer.from(e,"hex"),toHex:e=>_.toLocalBufferType(e).toString("hex"),toUTF8(e,t,r,n){const o=r-t<=20?O(e,t,r):null;if(null!=o)return o;const i=_.toLocalBufferType(e).toString("utf8",t,r);if(n)for(let n=0;n<i.length;n++)if(65533===i.charCodeAt(n)){b(e,t,r,!0);break}return i},utf8ByteLength:e=>Buffer.byteLength(e,"utf8"),encodeUTF8Into(e,t,r){const n=function(e,t,r){if(0===t.length)return 0;if(t.length>25)return null;if(e.length-r<t.length)return null;for(let n=0,o=r;n<t.length;n++,o++){const r=t.charCodeAt(n);if(r>127)return null;e[o]=r}return t.length}(e,t,r);return null!=n?n:_.toLocalBufferType(e).write(t,r,void 0,"utf8")},randomBytes:S,swap32:e=>_.toLocalBufferType(e).swap32()};function v(e){if(e<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${e}`);return D.fromNumberArray(Array.from({length:e},(()=>Math.floor(256*Math.random()))))}const T=(()=>{const{crypto:e}=globalThis;if(null!=e&&"function"==typeof e.getRandomValues)return t=>e.getRandomValues(D.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 v})(),I=/(\d|[a-f])/i,D={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 m("Cannot make a Uint8Array from passed potentialBuffer.")},allocate(e){if("number"!=typeof e)throw new TypeError(`The "size" argument must be of type number. Received ${String(e)}`);return new Uint8Array(e)},allocateUnsafe:e=>D.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=>Uint8Array.from(e),fromBase64:e=>Uint8Array.from(atob(e),(e=>e.charCodeAt(0))),toBase64:e=>btoa(D.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(!I.test(n))break;if(!I.test(o))break;const i=Number.parseInt(`${n}${o}`,16);r.push(i)}return Uint8Array.from(r)},toHex:e=>Array.from(e,(e=>e.toString(16).padStart(2,"0"))).join(""),toUTF8(e,t,r,n){const o=r-t<=20?O(e,t,r):null;return null!=o?o:b(e,t,r,n)},utf8ByteLength:e=>(new TextEncoder).encode(e).byteLength,encodeUTF8Into(e,t,r){const n=(new TextEncoder).encode(t);return e.set(n,r),n.byteLength},randomBytes:T,swap32(e){if(e.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e.length;t+=4){const r=e[t],n=e[t+1],o=e[t+2],i=e[t+3];e[t]=i,e[t+1]=o,e[t+2]=n,e[t+3]=r}return e}},M="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?_:D;class B{get[a](){return 6}[Symbol.for("nodejs.util.inspect.custom")](e,t,r){return this.inspect(e,t,r)}}const N=new Float64Array(1),F=new Uint8Array(N.buffer,0,8);N[0]=-1;const P=0===F[7],R={isBigEndian:P,getNonnegativeInt32LE(e,t){if(e[t+3]>127)throw new RangeError(`Size cannot be negative at offset: ${t}`);return e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24},getInt32LE:(e,t)=>e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24,getUint32LE:(e,t)=>e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3],getUint32BE:(e,t)=>e[t+3]+256*e[t+2]+65536*e[t+1]+16777216*e[t],getBigInt64LE(e,t){const r=BigInt(e[t+4]+256*e[t+5]+65536*e[t+6]+(e[t+7]<<24)),n=BigInt(e[t]+256*e[t+1]+65536*e[t+2]+16777216*e[t+3]);return(r<<BigInt(32))+n},getFloat64LE:P?(e,t)=>(F[7]=e[t],F[6]=e[t+1],F[5]=e[t+2],F[4]=e[t+3],F[3]=e[t+4],F[2]=e[t+5],F[1]=e[t+6],F[0]=e[t+7],N[0]):(e,t)=>(F[0]=e[t],F[1]=e[t+1],F[2]=e[t+2],F[3]=e[t+3],F[4]=e[t+4],F[5]=e[t+5],F[6]=e[t+6],F[7]=e[t+7],N[0]),setInt32BE:(e,t,r)=>(e[t+3]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t]=r,4),setInt32LE:(e,t,r)=>(e[t]=r,r>>>=8,e[t+1]=r,r>>>=8,e[t+2]=r,r>>>=8,e[t+3]=r,4),setBigInt64LE(e,t,r){const n=BigInt(4294967295);let o=Number(r&n);e[t]=o,o>>=8,e[t+1]=o,o>>=8,e[t+2]=o,o>>=8,e[t+3]=o;let i=Number(r>>BigInt(32)&n);return e[t+4]=i,i>>=8,e[t+5]=i,i>>=8,e[t+6]=i,i>>=8,e[t+7]=i,8},setFloat64LE:P?(e,t,r)=>(N[0]=r,e[t]=F[7],e[t+1]=F[6],e[t+2]=F[5],e[t+3]=F[4],e[t+4]=F[3],e[t+5]=F[2],e[t+6]=F[1],e[t+7]=F[0],8):(e,t,r)=>(N[0]=r,e[t]=F[0],e[t+1]=F[1],e[t+2]=F[2],e[t+3]=F[3],e[t+4]=F[4],e[t+5]=F[5],e[t+6]=F[6],e[t+7]=F[7],8)};class x extends B{get _bsontype(){return"Binary"}constructor(e,t){if(super(),null!=e&&"string"==typeof e&&!ArrayBuffer.isView(e)&&!r(e)&&!Array.isArray(e))throw new m("Binary can only be constructed from Uint8Array or number[]");this.sub_type=t??x.BSON_BINARY_SUBTYPE_DEFAULT,null==e?(this.buffer=M.allocate(x.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(e)?M.fromNumberArray(e):M.toLocalBufferType(e),this.position=this.buffer.byteLength)}put(e){if("string"==typeof e&&1!==e.length)throw new m("only accepts single character String");if("number"!=typeof e&&1!==e.length)throw new m("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 m("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=M.allocate(x.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=M.allocate(this.buffer.byteLength+e.length);t.set(this.buffer,0),this.buffer=t}if(ArrayBuffer.isView(e))this.buffer.set(M.toLocalBufferType(e),t),this.position=t+e.byteLength>this.position?t+e.length:this.position;else if("string"==typeof e)throw new m("input cannot be string")}read(e,t){const r=e+(t=t&&t>0?t:this.position);return this.buffer.subarray(e,r>this.position?this.position:r)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return M.toBase64(this.buffer.subarray(0,this.position))}toString(e){return"hex"===e?M.toHex(this.buffer.subarray(0,this.position)):"base64"===e?M.toBase64(this.buffer.subarray(0,this.position)):M.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(e){e=e||{},this.sub_type===x.SUBTYPE_VECTOR&&$(this);const t=M.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===x.SUBTYPE_UUID)return new L(this.buffer.subarray(0,this.position));throw new m(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${x.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(e,t){return new x(M.fromHex(e),t)}static createFromBase64(e,t){return new x(M.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=M.fromBase64(e.$binary)):"string"!=typeof e.$binary&&(n=e.$binary.subType?parseInt(e.$binary.subType,16):0,r=M.fromBase64(e.$binary.base64)):"$uuid"in e&&(n=4,r=L.bytesFromString(e.$uuid)),!r)throw new m(`Unexpected Binary Extended JSON format ${JSON.stringify(e)}`);return 4===n?new L(r):new x(r,n)}inspect(e,t,r){r??=s;return`Binary.createFromBase64(${r(M.toBase64(this.buffer.subarray(0,this.position)),t)}, ${r(this.sub_type,t)})`}toInt8Array(){if(this.sub_type!==x.SUBTYPE_VECTOR)throw new m("Binary sub_type is not Vector");if(this.buffer[0]!==x.VECTOR_TYPE.Int8)throw new m("Binary datatype field is not Int8");return new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==x.SUBTYPE_VECTOR)throw new m("Binary sub_type is not Vector");if(this.buffer[0]!==x.VECTOR_TYPE.Float32)throw new m("Binary datatype field is not Float32");const e=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return R.isBigEndian&&M.swap32(e),new Float32Array(e.buffer)}toPackedBits(){if(this.sub_type!==x.SUBTYPE_VECTOR)throw new m("Binary sub_type is not Vector");if(this.buffer[0]!==x.VECTOR_TYPE.PackedBit)throw new m("Binary datatype field is not packed bit");return new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==x.SUBTYPE_VECTOR)throw new m("Binary sub_type is not Vector");if(this.buffer[0]!==x.VECTOR_TYPE.PackedBit)throw new m("Binary datatype field is not packed bit");const e=8*(this.length()-2)-this.buffer[1],t=new Int8Array(e);for(let e=0;e<t.length;e++){const r=e/8|0,n=this.buffer[r+2]>>7-e%8&1;t[e]=n}return t}static fromInt8Array(e){const t=M.allocate(e.byteLength+2);t[0]=x.VECTOR_TYPE.Int8,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return t.set(r,2),new this(t,this.SUBTYPE_VECTOR)}static fromFloat32Array(e){const t=M.allocate(e.byteLength+2);t[0]=x.VECTOR_TYPE.Float32,t[1]=0;const r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return t.set(r,2),R.isBigEndian&&M.swap32(new Uint8Array(t.buffer,2)),new this(t,this.SUBTYPE_VECTOR)}static fromPackedBits(e,t=0){const r=M.allocate(e.byteLength+2);return r[0]=x.VECTOR_TYPE.PackedBit,r[1]=t,r.set(e,2),new this(r,this.SUBTYPE_VECTOR)}static fromBits(e){const t=e.length+7>>>3,r=new Uint8Array(t+2);r[0]=x.VECTOR_TYPE.PackedBit;const n=e.length%8;r[1]=0===n?0:8-n;for(let t=0;t<e.length;t++){const n=t>>>3,o=e[t];if(0!==o&&1!==o)throw new m(`Invalid bit value at ${t}: must be 0 or 1, found ${e[t]}`);if(0===o)continue;const i=7-t%8;r[n+2]|=o<<i}return new this(r,x.SUBTYPE_VECTOR)}}function $(e){if(e.sub_type!==x.SUBTYPE_VECTOR)return;const t=e.position,r=e.buffer[0],n=e.buffer[1];if((r===x.VECTOR_TYPE.Float32||r===x.VECTOR_TYPE.Int8)&&0!==n)throw new m("Invalid Vector: padding must be zero for int8 and float32 vectors");if(r===x.VECTOR_TYPE.PackedBit&&0!==n&&2===t)throw new m("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(r===x.VECTOR_TYPE.PackedBit&&n>7)throw new m(`Invalid Vector: padding must be a value between 0 and 7. found: ${n}`)}x.BSON_BINARY_SUBTYPE_DEFAULT=0,x.BUFFER_SIZE=256,x.SUBTYPE_DEFAULT=0,x.SUBTYPE_FUNCTION=1,x.SUBTYPE_BYTE_ARRAY=2,x.SUBTYPE_UUID_OLD=3,x.SUBTYPE_UUID=4,x.SUBTYPE_MD5=5,x.SUBTYPE_ENCRYPTED=6,x.SUBTYPE_COLUMN=7,x.SUBTYPE_SENSITIVE=8,x.SUBTYPE_VECTOR=9,x.SUBTYPE_USER_DEFINED=128,x.VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});const k=/^[0-9A-F]{32}$/i,j=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class L extends x{constructor(e){let t;if(null==e)t=L.generate();else if(e instanceof L)t=M.toLocalBufferType(new Uint8Array(e.buffer));else if(ArrayBuffer.isView(e)&&16===e.byteLength)t=M.toLocalBufferType(e);else{if("string"!=typeof e)throw new m("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=L.bytesFromString(e)}super(t,4)}get id(){return this.buffer}set id(e){this.buffer=e}toHexString(e=!0){return e?[M.toHex(this.buffer.subarray(0,4)),M.toHex(this.buffer.subarray(4,6)),M.toHex(this.buffer.subarray(6,8)),M.toHex(this.buffer.subarray(8,10)),M.toHex(this.buffer.subarray(10,16))].join("-"):M.toHex(this.buffer)}toString(e){return"hex"===e?M.toHex(this.id):"base64"===e?M.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(e){if(!e)return!1;if(e instanceof L)return M.equals(e.id,this.id);try{return M.equals(new L(e).id,this.id)}catch{return!1}}toBinary(){return new x(this.id,x.SUBTYPE_UUID)}static generate(){const e=M.randomBytes(16);return e[6]=15&e[6]|64,e[8]=63&e[8]|128,e}static isValid(e){return!!e&&("string"==typeof e?L.isValidUUIDString(e):t(e)?16===e.byteLength:"Binary"===e._bsontype&&e.sub_type===this.SUBTYPE_UUID&&16===e.buffer.byteLength)}static createFromHexString(e){const t=L.bytesFromString(e);return new L(t)}static createFromBase64(e){return new L(M.fromBase64(e))}static bytesFromString(e){if(!L.isValidUUIDString(e))throw new m("UUID string representation must be 32 hex digits or canonical hyphenated representation");return M.fromHex(e.replace(/-/g,""))}static isValidUUIDString(e){return k.test(e)||j.test(e)}inspect(e,t,r){return r??=s,`new UUID(${r(this.toHexString(),t)})`}}class U extends B{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 U(e.$code,e.$scope)}inspect(e,t,r){r??=s;let n=r(this.code,t);const o=n.includes("\n");null!=this.scope&&(n+=`,${o?"\n":" "}${r(this.scope,t)}`);return`new Code(${o?"\n":""}${n}${o&&null===this.scope?"\n":""})`}}function V(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 q extends B{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 q(e.$ref,e.$id,e.$db,t)}inspect(e,t,r){r??=s;const n=[r(this.namespace,t),r(this.oid,t),...this.db?[r(this.db,t)]:[],...Object.keys(this.fields).length>0?[r(this.fields,t)]:[]];return n[1]=r===s?`new ObjectId(${n[1]})`:n[1],`new DBRef(${n.join(", ")})`}}function G(e){if(""===e)return e;let t=0;const r="-"===e[t],n="+"===e[t];(n||r)&&(t+=1);let o=!1;for(;t<e.length&&"0"===e[t];++t)o=!0;return o?`${r?"-":""}${e.length===t?"0":e.slice(t)}`:n?e.slice(1):e}let 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 K=4294967296,H=0x10000000000000000,J=H/2,Y={},X={},Z=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class ee extends B{get _bsontype(){return"Long"}get __isLong__(){return!0}constructor(e=0,t,r){super();const n="boolean"==typeof t?t:Boolean(r),o="number"==typeof t?t:0,i="string"==typeof e?ee.fromString(e,n):"bigint"==typeof e?ee.fromBigInt(e,n):{low:0|e,high:0|o,unsigned:n};this.low=i.low,this.high=i.high,this.unsigned=i.unsigned}static fromBits(e,t,r){return new ee(e,t,r)}static fromInt(e,t){let r,n,o;return t?(o=0<=(e>>>=0)&&e<256)&&(n=X[e],n)?n:(r=ee.fromBits(e,(0|e)<0?-1:0,!0),o&&(X[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=Y[e],n)?n:(r=ee.fromBits(e,e<0?-1:0,!1),o&&(Y[e]=r),r)}static fromNumber(e,t){if(isNaN(e))return t?ee.UZERO:ee.ZERO;if(t){if(e<0)return ee.UZERO;if(e>=H)return ee.MAX_UNSIGNED_VALUE}else{if(e<=-0x8000000000000000)return ee.MIN_VALUE;if(e+1>=J)return ee.MAX_VALUE}return e<0?ee.fromNumber(-e,t).neg():ee.fromBits(e%K|0,e/K|0,t)}static fromBigInt(e,t){const r=BigInt(4294967295),n=BigInt(32);return new ee(Number(e&r),Number(e>>n&r),t)}static _fromString(e,t,r){if(0===e.length)throw new m("empty string");if(r<2||36<r)throw new m("radix");let n;if((n=e.indexOf("-"))>0)throw new m("interior hyphen");if(0===n)return ee._fromString(e.substring(1),t,r).neg();const o=ee.fromNumber(Math.pow(r,8));let i=ee.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=ee.fromNumber(Math.pow(r,n));i=i.mul(e).add(ee.fromNumber(s))}else i=i.mul(o),i=i.add(ee.fromNumber(s))}return i.unsigned=t,i}static fromStringStrict(e,t,r){let n=!1;if("number"==typeof t?(r=t,t=!1):n=!!t,r??=10,e.trim()!==e)throw new m(`Input: '${e}' contains leading and/or trailing whitespace`);if(!function(e,t){const r="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,t=t??10);return!new RegExp(`[^-+${r}]`,"i").test(e)&&e}(e,r))throw new m(`Input: '${e}' contains invalid characters for radix: ${r}`);const o=G(e),i=ee._fromString(o,n,r);if(i.toString(r).toLowerCase()!==o.toLowerCase())throw new m(`Input: ${e} is not representable as ${i.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=r?`with radix: ${r}`:""}`);return i}static fromString(e,t,r){let n=!1;return"number"==typeof t?(r=t,t=!1):n=!!t,r??=10,"NaN"===e&&r<24||("Infinity"===e||"+Infinity"===e||"-Infinity"===e)&&r<35?ee.ZERO:ee._fromString(e,n,r)}static fromBytes(e,t,r){return r?ee.fromBytesLE(e,t):ee.fromBytesBE(e,t)}static fromBytesLE(e,t){return new ee(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 ee(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?ee.fromNumber(e,t):"string"==typeof e?ee.fromString(e,t):ee.fromBits(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}add(e){ee.isLong(e)||(e=ee.fromValue(e));const t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16;let u=0,c=0,l=0,h=0;return h+=o+(65535&e.low),l+=h>>>16,h&=65535,l+=n+a,c+=l>>>16,l&=65535,c+=r+s,u+=c>>>16,c&=65535,u+=t+i,u&=65535,ee.fromBits(l<<16|h,u<<16|c,this.unsigned)}and(e){return ee.isLong(e)||(e=ee.fromValue(e)),ee.fromBits(this.low&e.low,this.high&e.high,this.unsigned)}compare(e){if(ee.isLong(e)||(e=ee.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(ee.isLong(e)||(e=ee.fromValue(e)),e.isZero())throw new m("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 ee.fromBits(t,z.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?ee.UZERO:ee.ZERO;let t,r,n;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return ee.UZERO;if(e.gt(this.shru(1)))return ee.UONE;n=ee.UZERO}else{if(this.eq(ee.MIN_VALUE)){if(e.eq(ee.ONE)||e.eq(ee.NEG_ONE))return ee.MIN_VALUE;if(e.eq(ee.MIN_VALUE))return ee.ONE;return t=this.shr(1).div(e).shl(1),t.eq(ee.ZERO)?e.isNegative()?ee.ONE:ee.NEG_ONE:(r=this.sub(e.mul(t)),n=t.add(r.div(e)),n)}if(e.eq(ee.MIN_VALUE))return this.unsigned?ee.UZERO:ee.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=ee.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=ee.fromNumber(t),a=s.mul(e);for(;a.isNegative()||a.gt(r);)t-=i,s=ee.fromNumber(t,this.unsigned),a=s.mul(e);s.isZero()&&(s=ee.ONE),n=n.add(s),r=r.sub(a)}return n}div(e){return this.divide(e)}equals(e){return ee.isLong(e)||(e=ee.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(ee.MIN_VALUE)?64:this.neg().getNumBitsAbs();const e=0!==this.high?this.high:this.low;let t;for(t=31;t>0&&!(e&1<<t);t--);return 0!==this.high?t+33:t+1}greaterThan(e){return this.comp(e)>0}gt(e){return this.greaterThan(e)}greaterThanOrEqual(e){return this.comp(e)>=0}gte(e){return this.greaterThanOrEqual(e)}ge(e){return this.greaterThanOrEqual(e)}isEven(){return!(1&this.low)}isNegative(){return!this.unsigned&&this.high<0}isOdd(){return!(1&~this.low)}isPositive(){return this.unsigned||this.high>=0}isZero(){return 0===this.high&&0===this.low}lessThan(e){return this.comp(e)<0}lt(e){return this.lessThan(e)}lessThanOrEqual(e){return this.comp(e)<=0}lte(e){return this.lessThanOrEqual(e)}modulo(e){if(ee.isLong(e)||(e=ee.fromValue(e)),z){const t=(this.unsigned?z.rem_u:z.rem_s)(this.low,this.high,e.low,e.high);return ee.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 ee.ZERO;if(ee.isLong(e)||(e=ee.fromValue(e)),z){const t=z.mul(this.low,this.high,e.low,e.high);return ee.fromBits(t,z.get_high(),this.unsigned)}if(e.isZero())return ee.ZERO;if(this.eq(ee.MIN_VALUE))return e.isOdd()?ee.MIN_VALUE:ee.ZERO;if(e.eq(ee.MIN_VALUE))return this.isOdd()?ee.MIN_VALUE:ee.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(ee.TWO_PWR_24)&&e.lt(ee.TWO_PWR_24))return ee.fromNumber(this.toNumber()*e.toNumber(),this.unsigned);const t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,u=65535&e.low;let c=0,l=0,h=0,p=0;return p+=o*u,h+=p>>>16,p&=65535,h+=n*u,l+=h>>>16,h&=65535,h+=o*a,l+=h>>>16,h&=65535,l+=r*u,c+=l>>>16,l&=65535,l+=n*a,c+=l>>>16,l&=65535,l+=o*s,c+=l>>>16,l&=65535,c+=t*u+r*a+n*s+o*i,c&=65535,ee.fromBits(h<<16|p,c<<16|l,this.unsigned)}mul(e){return this.multiply(e)}negate(){return!this.unsigned&&this.eq(ee.MIN_VALUE)?ee.MIN_VALUE:this.not().add(ee.ONE)}neg(){return this.negate()}not(){return ee.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 ee.isLong(e)||(e=ee.fromValue(e)),ee.fromBits(this.low|e.low,this.high|e.high,this.unsigned)}shiftLeft(e){return ee.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?ee.fromBits(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):ee.fromBits(0,this.low<<e-32,this.unsigned)}shl(e){return this.shiftLeft(e)}shiftRight(e){return ee.isLong(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?ee.fromBits(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):ee.fromBits(this.high>>e-32,this.high>=0?0:-1,this.unsigned)}shr(e){return this.shiftRight(e)}shiftRightUnsigned(e){if(ee.isLong(e)&&(e=e.toInt()),0===(e&=63))return this;{const t=this.high;if(e<32){const r=this.low;return ee.fromBits(r>>>e|t<<32-e,t>>>e,this.unsigned)}return 32===e?ee.fromBits(t,0,this.unsigned):ee.fromBits(t>>>e-32,0,this.unsigned)}}shr_u(e){return this.shiftRightUnsigned(e)}shru(e){return this.shiftRightUnsigned(e)}subtract(e){return ee.isLong(e)||(e=ee.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)*K+(this.low>>>0):this.high*K+(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?ee.fromBits(this.low,this.high,!1):this}toString(e){if((e=e||10)<2||36<e)throw new m("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(ee.MIN_VALUE)){const t=ee.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=ee.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:ee.fromBits(this.low,this.high,!0)}xor(e){return ee.isLong(e)||(e=ee.fromValue(e)),ee.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 m("$numberLong string is too long");if(!Z.test(e.$numberLong))throw new m(`$numberLong string "${e.$numberLong}" is in an invalid format`);if(r){const t=BigInt(e.$numberLong);return BigInt.asIntN(64,t)}const o=ee.fromString(e.$numberLong);return n?o.toNumber():o}inspect(e,t,r){r??=s;return`new Long(${r(this.toString(),t)}${this.unsigned?`, ${r(this.unsigned,t)}`:""})`}}ee.TWO_PWR_24=ee.fromInt(1<<24),ee.MAX_UNSIGNED_VALUE=ee.fromBits(-1,-1,!0),ee.ZERO=ee.fromInt(0),ee.UZERO=ee.fromInt(0,!0),ee.ONE=ee.fromInt(1),ee.UONE=ee.fromInt(1,!0),ee.NEG_ONE=ee.fromInt(-1),ee.MAX_VALUE=ee.fromBits(-1,2147483647,!1),ee.MIN_VALUE=ee.fromBits(0,-2147483648,!1);const te=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,re=/^(\+|-)?(Infinity|inf)$/i,ne=/^(\+|-)?NaN$/i,oe=6111,ie=-6176,se=M.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ae=M.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ue=M.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),ce=/^([-+])?(\d+)?$/;function le(e){return!isNaN(parseInt(e,10))}function he(e){const t=ee.fromNumber(1e9);let r=ee.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 ee(e.parts[n],0)),e.parts[n]=r.div(t).low,r=r.modulo(t);return{quotient:e,rem:r}}function pe(e,t){throw new m(`"${e}" is not a valid Decimal128 string - ${t}`)}class de extends B{get _bsontype(){return"Decimal128"}constructor(e){if(super(),"string"==typeof e)this.bytes=de.fromString(e).bytes;else{if(!(e instanceof Uint8Array||t(e)))throw new m("Decimal128 must take a Buffer or string");if(16!==e.byteLength)throw new m("Decimal128 must take a Buffer of 16 bytes");this.bytes=e}}static fromString(e){return de._fromString(e,{allowRounding:!1})}static fromStringWithRounding(e){return de._fromString(e,{allowRounding:!0})}static _fromString(e,t){let r=!1,n=!1,o=!1,i=!1,s=0,a=0,u=0,c=0,l=0;const h=[0];let p=0,d=0,f=0,y=0,g=new ee(0,0),E=new ee(0,0),w=0,A=0;if(e.length>=7e3)throw new m(e+" not a valid Decimal128 string");const b=e.match(te),O=e.match(re),C=e.match(ne);if(!b&&!O&&!C||0===e.length)throw new m(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&&pe(e,"missing exponent power"),r&&void 0===t&&pe(e,"missing exponent base"),void 0===r&&(n||o)&&pe(e,"missing e before exponent")}if("+"!==e[A]&&"-"!==e[A]||(n=!0,r="-"===e[A++]),!le(e[A])&&"."!==e[A]){if("i"===e[A]||"I"===e[A])return new de(r?ae:ue);if("N"===e[A])return new de(se)}for(;le(e[A])||"."===e[A];)"."!==e[A]?(p<34&&("0"!==e[A]||i)&&(i||(l=a),i=!0,h[d++]=parseInt(e[A],10),p+=1),i&&(u+=1),o&&(c+=1),a+=1,A+=1):(o&&pe(e,"contains multiple periods"),o=!0,A+=1);if(o&&!a)throw new m(e+" not a valid Decimal128 string");if("e"===e[A]||"E"===e[A]){const t=e.substr(++A).match(ce);if(!t||!t[2])return new de(se);y=parseInt(t[0],10),A+=t[0].length}if(e[A])return new de(se);if(p){if(f=p-1,s=u,1!==s)for(;"0"===e[l+s-1+Number(n)+Number(o)];)s-=1}else h[0]=0,u=1,p=1,s=0;for(y<=c&&c>y+16384?y=ie:y-=c;y>oe;){if(f+=1,f>=34){if(0===s){y=oe;break}pe(e,"overflow")}y-=1}if(t.allowRounding){for(;y<ie||p<u;){if(0===f&&s<p){y=ie,s=0;break}if(p<u?u-=1:f-=1,y<oe)y+=1;else{if(h.join("").match(/^0+$/)){y=oe;break}pe(e,"overflow")}}if(f+1<s){let t=a;o&&(l+=1,t+=1),n&&(l+=1,t+=1);const i=parseInt(e[l+f+1],10);let s=0;if(i>=5&&(s=1,5===i)){s=h[f]%2==1?1:0;for(let r=l+f+2;r<t;r++)if(parseInt(e[r],10)){s=1;break}}if(s){let e=f;for(;e>=0&&++h[e]>9;e--)if(h[e]=0,0===e){if(!(y<oe))return new de(r?ae:ue);y+=1,h[e]=1}}}}else{for(;y<ie||p<u;){if(0===f){if(0===s){y=ie;break}pe(e,"exponent underflow")}p<u?("0"!==e[u-1+Number(n)+Number(o)]&&0!==s&&pe(e,"inexact rounding"),u-=1):(0!==h[f]&&pe(e,"inexact rounding"),f-=1),y<oe?y+=1:pe(e,"overflow")}if(f+1<s){o&&(l+=1),n&&(l+=1);0!==parseInt(e[l+f+1],10)&&pe(e,"inexact rounding")}}if(g=ee.fromNumber(0),E=ee.fromNumber(0),0===s)g=ee.fromNumber(0),E=ee.fromNumber(0);else if(f<17){let e=0;for(E=ee.fromNumber(h[e++]),g=new ee(0,0);e<=f;e++)E=E.multiply(ee.fromNumber(10)),E=E.add(ee.fromNumber(h[e]))}else{let e=0;for(g=ee.fromNumber(h[e++]);e<=f-17;e++)g=g.multiply(ee.fromNumber(10)),g=g.add(ee.fromNumber(h[e]));for(E=ee.fromNumber(h[e++]);e<=f;e++)E=E.multiply(ee.fromNumber(10)),E=E.add(ee.fromNumber(h[e]))}const S=function(e,t){if(!e&&!t)return{high:ee.fromNumber(0),low:ee.fromNumber(0)};const r=e.shiftRightUnsigned(32),n=new ee(e.getLowBits(),0),o=t.shiftRightUnsigned(32),i=new ee(t.getLowBits(),0);let s=r.multiply(o),a=r.multiply(i);const u=n.multiply(o);let c=n.multiply(i);return s=s.add(a.shiftRightUnsigned(32)),a=new ee(a.getLowBits(),0).add(u).add(c.shiftRightUnsigned(32)),s=s.add(a.shiftRightUnsigned(32)),c=a.shiftLeft(32).add(new ee(c.getLowBits(),0)),{high:s,low:c}}(g,ee.fromString("100000000000000000"));S.low=S.low.add(E),function(e,t){const r=e.high>>>0,n=t.high>>>0;if(r<n)return!0;if(r===n&&e.low>>>0<t.low>>>0)return!0;return!1}(S.low,E)&&(S.high=S.high.add(ee.fromNumber(1))),w=y+6176;const _={low:ee.fromNumber(0),high:ee.fromNumber(0)};S.high.shiftRightUnsigned(49).and(ee.fromNumber(1)).equals(ee.fromNumber(1))?(_.high=_.high.or(ee.fromNumber(3).shiftLeft(61)),_.high=_.high.or(ee.fromNumber(w).and(ee.fromNumber(16383).shiftLeft(47))),_.high=_.high.or(S.high.and(ee.fromNumber(0x7fffffffffff)))):(_.high=_.high.or(ee.fromNumber(16383&w).shiftLeft(49)),_.high=_.high.or(S.high.and(ee.fromNumber(562949953421311)))),_.low=S.low,r&&(_.high=_.high.or(ee.fromString("9223372036854775808")));const v=M.allocateUnsafe(16);return A=0,v[A++]=255&_.low.low,v[A++]=_.low.low>>8&255,v[A++]=_.low.low>>16&255,v[A++]=_.low.low>>24&255,v[A++]=255&_.low.high,v[A++]=_.low.high>>8&255,v[A++]=_.low.high>>16&255,v[A++]=_.low.high>>24&255,v[A++]=255&_.high.low,v[A++]=_.high.low>>8&255,v[A++]=_.high.low>>16&255,v[A++]=_.high.low>>24&255,v[A++]=255&_.high.high,v[A++]=_.high.high>>8&255,v[A++]=_.high.high>>16&255,v[A++]=_.high.high>>24&255,new de(v)}toString(){let e,t=0;const r=new Array(36);for(let e=0;e<r.length;e++)r[e]=0;let n,o,i,s=0,a=!1,u={parts:[0,0,0,0]};const c=[];s=0;const l=this.bytes,h=l[s++]|l[s++]<<8|l[s++]<<16|l[s++]<<24,p=l[s++]|l[s++]<<8|l[s++]<<16|l[s++]<<24,d=l[s++]|l[s++]<<8|l[s++]<<16|l[s++]<<24,f=l[s++]|l[s++]<<8|l[s++]<<16|l[s++]<<24;s=0;({low:new ee(h,p),high:new ee(d,f)}).high.lessThan(ee.ZERO)&&c.push("-");const m=f>>26&31;if(m>>3==3){if(30===m)return c.join("")+"Infinity";if(31===m)return"NaN";e=f>>15&16383,n=8+(f>>14&1)}else n=f>>14&7,e=f>>17&16383;const y=e-6176;if(u.parts[0]=(16383&f)+((15&n)<<14),u.parts[1]=d,u.parts[2]=p,u.parts[3]=h,0===u.parts[0]&&0===u.parts[1]&&0===u.parts[2]&&0===u.parts[3])a=!0;else for(i=3;i>=0;i--){let e=0;const t=he(u);if(u=t.quotient,e=t.rem.low,e)for(o=8;o>=0;o--)r[9*i+o]=e%10,e=Math.floor(e/10)}if(a)t=1,r[s]=0;else for(t=36;!r[s];)t-=1,s+=1;const g=t-1+y;if(g>=34||g<=-7||y>0){if(t>34)return c.push("0"),y>0?c.push(`E+${y}`):y<0&&c.push(`E${y}`),c.join("");c.push(`${r[s++]}`),t-=1,t&&c.push(".");for(let e=0;e<t;e++)c.push(`${r[s++]}`);c.push("E"),g>0?c.push(`+${g}`):c.push(`${g}`)}else if(y>=0)for(let e=0;e<t;e++)c.push(`${r[s++]}`);else{let e=t+y;if(e>0)for(let t=0;t<e;t++)c.push(`${r[s++]}`);else c.push("0");for(c.push(".");e++<0;)c.push("0");for(let n=0;n<t-Math.max(e-1,0);n++)c.push(`${r[s++]}`)}return c.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(e){return de.fromString(e.$numberDecimal)}inspect(e,t,r){r??=s;return`new Decimal128(${r(this.toString(),t)})`}}class fe extends B{get _bsontype(){return"Double"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=+e}static fromString(e){const t=Number(e);if("NaN"===e)return new fe(NaN);if("Infinity"===e)return new fe(1/0);if("-Infinity"===e)return new fe(-1/0);if(!Number.isFinite(t))throw new m(`Input: ${e} is not representable as a Double`);if(e.trim()!==e)throw new m(`Input: '${e}' contains whitespace`);if(""===e)throw new m("Input is an empty string");if(/[^-0-9.+eE]/.test(e))throw new m(`Input: '${e}' is not in decimal or exponential notation`);return new fe(t)}valueOf(){return this.value}toJSON(){return this.value}toString(e){return this.value.toString(e)}toExtendedJSON(e){return e&&(e.legacy||e.relaxed&&isFinite(this.value))?this.value:Object.is(Math.sign(this.value),-0)?{$numberDouble:"-0.0"}:{$numberDouble:Number.isInteger(this.value)?this.value.toFixed(1):this.value.toString()}}static fromExtendedJSON(e,t){const r=parseFloat(e.$numberDouble);return t&&t.relaxed?r:new fe(r)}inspect(e,t,r){return r??=s,`new Double(${r(this.value,t)})`}}class me extends B{get _bsontype(){return"Int32"}constructor(e){super(),e instanceof Number&&(e=e.valueOf()),this.value=0|+e}static fromString(e){const t=G(e),r=Number(e);if(u<r)throw new m(`Input: '${e}' is larger than the maximum value for Int32`);if(c>r)throw new m(`Input: '${e}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(r))throw new m(`Input: '${e}' is not a safe integer`);if(r.toString()!==t)throw new m(`Input: '${e}' is not a valid Int32 string`);return new me(r)}valueOf(){return this.value}toString(e){return this.value.toString(e)}toJSON(){return this.value}toExtendedJSON(e){return e&&(e.relaxed||e.legacy)?this.value:{$numberInt:this.value.toString()}}static fromExtendedJSON(e,t){return t&&t.relaxed?parseInt(e.$numberInt,10):new me(e.$numberInt)}inspect(e,t,r){return r??=s,`new Int32(${r(this.value,t)})`}}class ye extends B{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new ye}inspect(){return"new MaxKey()"}}class ge extends B{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new ge}inspect(){return"new MinKey()"}}let Ee=null;const we=new WeakMap;class Ae extends B{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 m("Argument passed in must have an id that is of type string or Buffer");t="toHexString"in e&&"function"==typeof e.toHexString?M.fromHex(e.toHexString()):e.id}else t=e;if(null==t||"number"==typeof t)this.buffer=Ae.generate("number"==typeof t?t:void 0);else if(ArrayBuffer.isView(t)&&12===t.byteLength)this.buffer=M.toLocalBufferType(t);else{if("string"!=typeof t)throw new m("Argument passed in does not match the accepted types");if(!Ae.validateHexString(t))throw new m("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=M.fromHex(t),Ae.cacheHexString&&we.set(this,t)}}get id(){return this.buffer}set id(e){this.buffer=e,Ae.cacheHexString&&we.set(this,M.toHex(e))}static validateHexString(e){if(24!==e?.length)return!1;for(let t=0;t<24;t++){const r=e.charCodeAt(t);if(!(r>=48&&r<=57||r>=97&&r<=102||r>=65&&r<=70))return!1}return!0}toHexString(){if(Ae.cacheHexString){const e=we.get(this);if(e)return e}const e=M.toHex(this.id);return Ae.cacheHexString&&we.set(this,e),e}static getInc(){return Ae.index=(Ae.index+1)%16777215}static generate(e){"number"!=typeof e&&(e=Math.floor(Date.now()/1e3));const t=Ae.getInc(),r=M.allocateUnsafe(12);return R.setInt32BE(r,0,e),null===Ee&&(Ee=M.randomBytes(5)),r[4]=Ee[0],r[5]=Ee[1],r[6]=Ee[2],r[7]=Ee[3],r[8]=Ee[4],r[11]=255&t,r[10]=t>>8&255,r[9]=t>>16&255,r}toString(e){return"base64"===e?M.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(e){return null!=e&&"object"==typeof e&&"_bsontype"in e&&"ObjectId"===e._bsontype}equals(e){if(null==e)return!1;if(Ae.is(e))return this.buffer[11]===e.buffer[11]&&M.equals(this.buffer,e.buffer);if("string"==typeof e)return e.toLowerCase()===this.toHexString();if("object"==typeof e&&"function"==typeof e.toHexString){const t=e.toHexString(),r=this.toHexString();return"string"==typeof t&&t.toLowerCase()===r}return!1}getTimestamp(){const e=new Date,t=R.getUint32BE(this.buffer,0);return e.setTime(1e3*Math.floor(t)),e}static createPk(){return new Ae}serializeInto(e,t){return e[t]=this.buffer[0],e[t+1]=this.buffer[1],e[t+2]=this.buffer[2],e[t+3]=this.buffer[3],e[t+4]=this.buffer[4],e[t+5]=this.buffer[5],e[t+6]=this.buffer[6],e[t+7]=this.buffer[7],e[t+8]=this.buffer[8],e[t+9]=this.buffer[9],e[t+10]=this.buffer[10],e[t+11]=this.buffer[11],12}static createFromTime(e){const t=M.allocate(12);for(let e=11;e>=4;e--)t[e]=0;return R.setInt32BE(t,0,e),new Ae(t)}static createFromHexString(e){if(24!==e?.length)throw new m("hex string must be 24 characters");return new Ae(M.fromHex(e))}static createFromBase64(e){if(16!==e?.length)throw new m("base64 string must be 16 characters");return new Ae(M.fromBase64(e))}static isValid(e){if(null==e)return!1;if("string"==typeof e)return Ae.validateHexString(e);try{return new Ae(e),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(e){return new Ae(e.$oid)}isCached(){return Ae.cacheHexString&&we.has(this)}inspect(e,t,r){return r??=s,`new ObjectId(${r(this.toHexString(),t)})`}}function be(e,t,r){let n=5;if(Array.isArray(e))for(let o=0;o<e.length;o++)n+=Oe(o.toString(),e[o],t,!0,r);else{"function"==typeof e?.toBSON&&(e=e.toBSON());for(const o of Object.keys(e))n+=Oe(o,e[o],t,!1,r)}return n}function Oe(e,t,o=!1,s=!1,l=!1){switch("function"==typeof t?.toBSON&&(t=t.toBSON()),typeof t){case"string":return 1+M.utf8ByteLength(e)+1+4+M.utf8ByteLength(t)+1;case"number":return Math.floor(t)===t&&t>=d&&t<=p&&t>=c&&t<=u?(null!=e?M.utf8ByteLength(e)+1:0)+5:(null!=e?M.utf8ByteLength(e)+1:0)+9;case"undefined":return s||!l?(null!=e?M.utf8ByteLength(e)+1:0)+1:0;case"boolean":return(null!=e?M.utf8ByteLength(e)+1:0)+2;case"object":if(null!=t&&"string"==typeof t._bsontype&&6!==t[a])throw new y;if(null==t||"MinKey"===t._bsontype||"MaxKey"===t._bsontype)return(null!=e?M.utf8ByteLength(e)+1:0)+1;if("ObjectId"===t._bsontype)return(null!=e?M.utf8ByteLength(e)+1:0)+13;if(t instanceof Date||i(t))return(null!=e?M.utf8ByteLength(e)+1:0)+9;if(ArrayBuffer.isView(t)||t instanceof ArrayBuffer||r(t))return(null!=e?M.utf8ByteLength(e)+1:0)+6+t.byteLength;if("Long"===t._bsontype||"Double"===t._bsontype||"Timestamp"===t._bsontype)return(null!=e?M.utf8ByteLength(e)+1:0)+9;if("Decimal128"===t._bsontype)return(null!=e?M.utf8ByteLength(e)+1:0)+17;if("Code"===t._bsontype)return null!=t.scope&&Object.keys(t.scope).length>0?(null!=e?M.utf8ByteLength(e)+1:0)+1+4+4+M.utf8ByteLength(t.code.toString())+1+be(t.scope,o,l):(null!=e?M.utf8ByteLength(e)+1:0)+1+4+M.utf8ByteLength(t.code.toString())+1;if("Binary"===t._bsontype){const r=t;return r.sub_type===x.SUBTYPE_BYTE_ARRAY?(null!=e?M.utf8ByteLength(e)+1:0)+(r.position+1+4+1+4):(null!=e?M.utf8ByteLength(e)+1:0)+(r.position+1+4+1)}if("Symbol"===t._bsontype)return(null!=e?M.utf8ByteLength(e)+1:0)+M.utf8ByteLength(t.value)+4+1+1;if("DBRef"===t._bsontype){const r=Object.assign({$ref:t.collection,$id:t.oid},t.fields);return null!=t.db&&(r.$db=t.db),(null!=e?M.utf8ByteLength(e)+1:0)+1+be(r,o,l)}return t instanceof RegExp||n(t)?(null!=e?M.utf8ByteLength(e)+1:0)+1+M.utf8ByteLength(t.source)+1+(t.global?1:0)+(t.ignoreCase?1:0)+(t.multiline?1:0)+1:"BSONRegExp"===t._bsontype?(null!=e?M.utf8ByteLength(e)+1:0)+1+M.utf8ByteLength(t.pattern)+1+M.utf8ByteLength(t.options)+1:(null!=e?M.utf8ByteLength(e)+1:0)+be(t,o,l)+1;case"function":return o?(null!=e?M.utf8ByteLength(e)+1:0)+1+4+M.utf8ByteLength(t.toString())+1:0;case"bigint":return(null!=e?M.utf8ByteLength(e)+1:0)+9;case"symbol":return 0;default:throw new m("Unrecognized JS type: "+typeof t)}}Ae.index=Math.floor(16777215*Math.random());class Ce extends B{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 m(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new m(`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 m(`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 Ce(e.$regex,Ce.parseOptions(e.$options));if("BSONRegExp"===e.$regex._bsontype)return e}if("$regularExpression"in e)return new Ce(e.$regularExpression.pattern,Ce.parseOptions(e.$regularExpression.options));throw new m(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(e)}`)}inspect(e,t,r){const n=function(e){if(null!=e&&"object"==typeof e&&"stylize"in e&&"function"==typeof e.stylize)return e.stylize}(t)??(e=>e);r??=s;return`new BSONRegExp(${n(r(this.pattern),"regexp")}, ${n(r(this.options),"regexp")})`}}class Se extends B{get _bsontype(){return"BSONSymbol"}constructor(e){super(),this.value=e}valueOf(){return this.value}toString(){return this.value}toJSON(){return this.value}toExtendedJSON(){return{$symbol:this.value}}static fromExtendedJSON(e){return new Se(e.$symbol)}inspect(e,t,r){return r??=s,`new BSONSymbol(${r(this.value,t)})`}}const _e=ee;class ve extends _e{get _bsontype(){return"Timestamp"}get i(){return this.low>>>0}get t(){return this.high>>>0}constructor(e){if(null==e)super(0,0,!0);else if("bigint"==typeof e)super(e,!0);else if(ee.isLong(e))super(e.low,e.high,!0);else{if("object"!=typeof e||!("t"in e)||!("i"in e))throw new m("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 m("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 m("Timestamp constructed from { t, i } must provide i as a number");const t=Number(e.t),r=Number(e.i);if(t<0||Number.isNaN(t))throw new m("Timestamp constructed from { t, i } must provide a positive t");if(r<0||Number.isNaN(r))throw new m("Timestamp constructed from { t, i } must provide a positive i");if(t>4294967295)throw new m("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");if(r>4294967295)throw new m("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");super(r,t,!0)}}}toJSON(){return{$timestamp:this.toString()}}static fromInt(e){return new ve(ee.fromInt(e,!0))}static fromNumber(e){return new ve(ee.fromNumber(e,!0))}static fromBits(e,t){return new ve({i:e,t:t})}static fromString(e,t){return new ve(ee.fromString(e,!0,t))}toExtendedJSON(){return{$timestamp:{t:this.t,i:this.i}}}static fromExtendedJSON(e){const t=ee.isLong(e.$timestamp.i)?e.$timestamp.i.getLowBitsUnsigned():e.$timestamp.i,r=ee.isLong(e.$timestamp.t)?e.$timestamp.t.getLowBitsUnsigned():e.$timestamp.t;return new ve({t:r,i:t})}inspect(e,t,r){r??=s;return`new Timestamp({ t: ${r(this.t,t)}, i: ${r(this.i,t)} })`}}ve.MAX_VALUE=ee.MAX_UNSIGNED_VALUE;const Te=ee.fromNumber(p),Ie=ee.fromNumber(d);function De(e,t,r){const n=(t=null==t?{}:t)&&t.index?t.index:0,o=R.getInt32LE(e,n);if(o<5)throw new m(`bson size must be >= 5, is ${o}`);if(t.allowObjectSmallerThanBufferSize&&e.length<o)throw new m(`buffer length ${e.length} must be >= bson size ${o}`);if(!t.allowObjectSmallerThanBufferSize&&e.length!==o)throw new m(`buffer length ${e.length} must === bson size ${o}`);if(o+n>e.byteLength)throw new m(`(bson size ${o} + options.index ${n} must be <= buffer length ${e.byteLength}