UNPKG

@kittycad/lib

Version:

Javascript library for KittyCAD API

1 lines 319 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@kittycad/oauth2-auth-code-pkce");try{if("undefined"==typeof fetch&&"undefined"!=typeof process&&process.versions?.node){new Function("m","return import(m)")("cross-fetch/polyfill").catch((()=>{}))}}catch{}function e(t,e){return`${t.replace(/\/+$/,"")}/${e.replace(/^\/+/,"")}`}function n(t){const e=new URLSearchParams;for(const[n,l]of Object.entries(t))if(void 0!==l)if(Array.isArray(l))for(const t of l)e.append(n,String(t));else e.append(n,String(l));const n=e.toString();return n?`?${n}`:""}function l(t){const e=new URLSearchParams;for(const[n,l]of Object.entries(t||{}))if(void 0!==l)if(Array.isArray(l))for(const t of l)e.append(n,String(t));else e.append(n,String(l));return e}try{if("undefined"!=typeof process&&process.versions?.node&&"win32"===process.platform){new Function("m","return import(m)")("win-ca")}}catch{}class i extends Error{constructor(t,e,n){super(n||e?.message||`HTTP ${t}`),this.name="ApiError",this.status=t,this.error_code=e?.error_code,this.request_id=e?.request_id,this.body=e}}async function o(t){if(t.ok)return;let e;try{e=await t.json()}catch{try{const n=await t.text();e=n?{message:n}:void 0}catch{e=void 0}}throw new i(t.status,e)}class c{started=!1;constructor(t,e,n="page_token"){this.fetchPage=t,this.baseParams={...e},this.tokenField=n}hasNext(){return!this.started||!!this.nextToken}reset(){this.started=!1,this.nextToken=void 0}async next(){if(this.started&&!this.nextToken)return[];const t={...this.baseParams};this.started&&this.nextToken&&(t[this.tokenField]=this.nextToken);const e=await this.fetchPage(t);return this.started=!0,this.nextToken=e?.next_page??null,e?.items??[]}}function s(t,e,n="page_token"){return new c(t,e,n)}async function a({client:t,id:e,limit:l,page_token:i,sort_by:c}){const s=`/users/${e}/api-calls`+n({limit:l,page_token:i,sort_by:c}),a=(t?.baseUrl||"https://api.zoo.dev")+s,d=t&&t.token||"",b={};d&&(b.Authorization=`Bearer ${d}`);const Z={method:"GET",headers:b},r=t?.fetch||fetch,m=await r(a,Z);await o(m);return await m.json()}async function d({client:t,limit:e,page_token:l,sort_by:i}){const c="/org/api-calls"+n({limit:e,page_token:l,sort_by:i}),s=(t?.baseUrl||"https://api.zoo.dev")+c,a=t&&t.token||"",d={};a&&(d.Authorization=`Bearer ${a}`);const b={method:"GET",headers:d},Z=t?.fetch||fetch,r=await Z(s,b);await o(r);return await r.json()}async function b({client:t,limit:e,page_token:l,sort_by:i}){const c="/user/api-calls"+n({limit:e,page_token:l,sort_by:i}),s=(t?.baseUrl||"https://api.zoo.dev")+c,a=t&&t.token||"",d={};a&&(d.Authorization=`Bearer ${a}`);const b={method:"GET",headers:d},Z=t?.fetch||fetch,r=await Z(s,b);await o(r);return await r.json()}async function Z({client:t,limit:e,page_token:l,sort_by:i}){const c="/user/api-tokens"+n({limit:e,page_token:l,sort_by:i}),s=(t?.baseUrl||"https://api.zoo.dev")+c,a=t&&t.token||"",d={};a&&(d.Authorization=`Bearer ${a}`);const b={method:"GET",headers:d},Z=t?.fetch||fetch,r=await Z(s,b);await o(r);return await r.json()}const r=(()=>{const t=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag).get;return e=>t.call(e)})();function m(t){return"Uint8Array"===r(t)}function u(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&("ArrayBuffer"===t[Symbol.toStringTag]||"SharedArrayBuffer"===t[Symbol.toStringTag])}function h(t){return t instanceof RegExp||"[object RegExp]"===Object.prototype.toString.call(t)}function p(t){return"object"==typeof t&&null!=t&&Symbol.toStringTag in t&&"Map"===t[Symbol.toStringTag]}function y(t){return t instanceof Date||"[object Date]"===Object.prototype.toString.call(t)}function X(t,e){return JSON.stringify(t,((t,e)=>"bigint"==typeof e?{$numberLong:`${e}`}:p(e)?Object.fromEntries(e):e))}const G=7,V=Symbol.for("@@mdb.bson.version"),W=2147483647,f=-2147483648,g=Math.pow(2,63)-1,Y=-Math.pow(2,63),I=Math.pow(2,53),R=-Math.pow(2,53),J=1,S=2,K=3,T=4,L=5,z=6,x=7,U=8,N=9,w=10,k=11,H=12,C=13,B=14,v=15,j=16,M=17,P=18,F=19,Q=255,O=127,E=0,_=4,D=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 A extends Error{get bsonError(){return!0}get name(){return"BSONError"}constructor(t,e){super(t,e)}static isBSONError(t){return null!=t&&"object"==typeof t&&"bsonError"in t&&!0===t.bsonError&&"name"in t&&"message"in t&&"stack"in t}}class $ extends A{get name(){return"BSONVersionError"}constructor(){super(`Unsupported BSON version, bson types must be from bson ${G}.x.x`)}}class q extends A{get name(){return"BSONRuntimeError"}constructor(t){super(t)}}class tt extends A{get name(){return"BSONOffsetError"}offset;constructor(t,e,n){super(`${t}. offset: ${e}`,n),this.offset=e}}let et,nt;function lt(t,e,n,l){if(l){et??=new TextDecoder("utf8",{fatal:!0});try{return et.decode(t.subarray(e,n))}catch(t){throw new A("Invalid UTF-8 string in BSON document",{cause:t})}}return nt??=new TextDecoder("utf8",{fatal:!1}),nt.decode(t.subarray(e,n))}function it(t,e,n){if(0===t.length)return"";const l=n-e;if(0===l)return"";if(l>20)return null;if(1===l&&t[e]<128)return String.fromCharCode(t[e]);if(2===l&&t[e]<128&&t[e+1]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1]);if(3===l&&t[e]<128&&t[e+1]<128&&t[e+2]<128)return String.fromCharCode(t[e])+String.fromCharCode(t[e+1])+String.fromCharCode(t[e+2]);const i=[];for(let l=e;l<n;l++){const e=t[l];if(e>127)return null;i.push(e)}return String.fromCharCode(...i)}function ot(t){return at.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}function ct(t){return crypto.getRandomValues(at.allocate(t))}const st=(()=>{const{crypto:t}=globalThis;return null!=t&&"function"==typeof t.getRandomValues?ct:ot})(),at={isUint8Array:m,toLocalBufferType(t){if(Buffer.isBuffer(t))return t;if(ArrayBuffer.isView(t))return Buffer.from(t.buffer,t.byteOffset,t.byteLength);const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return Buffer.from(t);throw new A("Cannot create Buffer from the passed potentialBuffer.")},allocate:t=>Buffer.alloc(t),allocateUnsafe:t=>Buffer.allocUnsafe(t),compare:(t,e)=>at.toLocalBufferType(t).compare(e),concat:t=>Buffer.concat(t),copy:(t,e,n,l,i)=>at.toLocalBufferType(t).copy(e,n??0,l??0,i??t.length),equals:(t,e)=>at.toLocalBufferType(t).equals(e),fromNumberArray:t=>Buffer.from(t),fromBase64:t=>Buffer.from(t,"base64"),fromUTF8:t=>Buffer.from(t,"utf8"),toBase64:t=>at.toLocalBufferType(t).toString("base64"),fromISO88591:t=>Buffer.from(t,"binary"),toISO88591:t=>at.toLocalBufferType(t).toString("binary"),fromHex:t=>Buffer.from(t,"hex"),toHex:t=>at.toLocalBufferType(t).toString("hex"),toUTF8(t,e,n,l){const i=n-e<=20?it(t,e,n):null;if(null!=i)return i;const o=at.toLocalBufferType(t).toString("utf8",e,n);if(l)for(let l=0;l<o.length;l++)if(65533===o.charCodeAt(l)){lt(t,e,n,!0);break}return o},utf8ByteLength:t=>Buffer.byteLength(t,"utf8"),encodeUTF8Into(t,e,n){const l=function(t,e,n){if(0===e.length)return 0;if(e.length>25)return null;if(t.length-n<e.length)return null;for(let l=0,i=n;l<e.length;l++,i++){const n=e.charCodeAt(l);if(n>127)return null;t[i]=n}return e.length}(t,e,n);return null!=l?l:at.toLocalBufferType(t).write(e,n,void 0,"utf8")},randomBytes:st,swap32:t=>at.toLocalBufferType(t).swap32()};function dt(t){if(t<0)throw new RangeError(`The argument 'byteLength' is invalid. Received ${t}`);return rt.fromNumberArray(Array.from({length:t},(()=>Math.floor(256*Math.random()))))}const bt=(()=>{const{crypto:t}=globalThis;if(null!=t&&"function"==typeof t.getRandomValues)return e=>t.getRandomValues(rt.allocate(e));if(function(){const{navigator:t}=globalThis;return"object"==typeof t&&"ReactNative"===t.product}()){const{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 dt})(),Zt=/(\d|[a-f])/i,rt={isUint8Array:m,toLocalBufferType(t){const e=t?.[Symbol.toStringTag]??Object.prototype.toString.call(t);if("Uint8Array"===e)return t;if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength));if("ArrayBuffer"===e||"SharedArrayBuffer"===e||"[object ArrayBuffer]"===e||"[object SharedArrayBuffer]"===e)return new Uint8Array(t);throw new A("Cannot make a Uint8Array from passed potentialBuffer.")},allocate(t){if("number"!=typeof t)throw new TypeError(`The "size" argument must be of type number. Received ${String(t)}`);return new Uint8Array(t)},allocateUnsafe:t=>rt.allocate(t),compare(t,e){if(t===e)return 0;const n=Math.min(t.length,e.length);for(let l=0;l<n;l++){if(t[l]<e[l])return-1;if(t[l]>e[l])return 1}return t.length<e.length?-1:t.length>e.length?1:0},concat(t){if(0===t.length)return rt.allocate(0);let e=0;for(const n of t)e+=n.length;const n=rt.allocate(e);let l=0;for(const e of t)n.set(e,l),l+=e.length;return n},copy(t,e,n,l,i){if(void 0!==i&&i<0)throw new RangeError(`The value of "sourceEnd" is out of range. It must be >= 0. Received ${i}`);if(i=i??t.length,void 0!==l&&(l<0||l>i))throw new RangeError(`The value of "sourceStart" is out of range. It must be >= 0 and <= ${i}. Received ${l}`);if(l=l??0,void 0!==n&&n<0)throw new RangeError(`The value of "targetStart" is out of range. It must be >= 0. Received ${n}`);n=n??0;const o=t.subarray(l,i),c=Math.min(o.length,e.length-n);return c<=0?0:(e.set(o.subarray(0,c),n),c)},equals(t,e){if(t.byteLength!==e.byteLength)return!1;for(let n=0;n<t.byteLength;n++)if(t[n]!==e[n])return!1;return!0},fromNumberArray:t=>Uint8Array.from(t),fromBase64:t=>Uint8Array.from(atob(t),(t=>t.charCodeAt(0))),fromUTF8:t=>(new TextEncoder).encode(t),toBase64:t=>btoa(rt.toISO88591(t)),fromISO88591:t=>Uint8Array.from(t,(t=>255&t.charCodeAt(0))),toISO88591:t=>Array.from(Uint16Array.from(t),(t=>String.fromCharCode(t))).join(""),fromHex(t){const e=t.length%2==0?t:t.slice(0,t.length-1),n=[];for(let t=0;t<e.length;t+=2){const l=e[t],i=e[t+1];if(!Zt.test(l))break;if(!Zt.test(i))break;const o=Number.parseInt(`${l}${i}`,16);n.push(o)}return Uint8Array.from(n)},toHex:t=>Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join(""),toUTF8(t,e,n,l){const i=n-e<=20?it(t,e,n):null;return null!=i?i:lt(t,e,n,l)},utf8ByteLength:t=>(new TextEncoder).encode(t).byteLength,encodeUTF8Into(t,e,n){const l=(new TextEncoder).encode(e);return t.set(l,n),l.byteLength},randomBytes:bt,swap32(t){if(t.length%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t.length;e+=4){const n=t[e],l=t[e+1],i=t[e+2],o=t[e+3];t[e]=o,t[e+1]=i,t[e+2]=l,t[e+3]=n}return t}},mt="function"==typeof Buffer&&!0!==Buffer.prototype?._isBuffer?at:rt,ut=Symbol.for("@@mdb.bson.type");class ht{get[ut](){return this._bsontype}get[V](){return G}[Symbol.for("nodejs.util.inspect.custom")](t,e,n){return this.inspect(t,e,n)}}const pt=new Float64Array(1),yt=new Uint8Array(pt.buffer,0,8);pt[0]=-1;const Xt=0===yt[7],Gt={isBigEndian:Xt,getNonnegativeInt32LE(t,e){if(t[e+3]>127)throw new RangeError(`Size cannot be negative at offset: ${e}`);return t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24},getInt32LE:(t,e)=>t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24,getUint32LE:(t,e)=>t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3],getUint32BE:(t,e)=>t[e+3]+256*t[e+2]+65536*t[e+1]+16777216*t[e],getBigInt64LE:(t,e)=>(BigInt(t[e+4]+256*t[e+5]+65536*t[e+6]+(t[e+7]<<24))<<32n)+BigInt(t[e]+256*t[e+1]+65536*t[e+2]+16777216*t[e+3]),getFloat64LE:Xt?(t,e)=>(yt[7]=t[e],yt[6]=t[e+1],yt[5]=t[e+2],yt[4]=t[e+3],yt[3]=t[e+4],yt[2]=t[e+5],yt[1]=t[e+6],yt[0]=t[e+7],pt[0]):(t,e)=>(yt[0]=t[e],yt[1]=t[e+1],yt[2]=t[e+2],yt[3]=t[e+3],yt[4]=t[e+4],yt[5]=t[e+5],yt[6]=t[e+6],yt[7]=t[e+7],pt[0]),setInt32BE:(t,e,n)=>(t[e+3]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e]=n,4),setInt32LE:(t,e,n)=>(t[e]=n,n>>>=8,t[e+1]=n,n>>>=8,t[e+2]=n,n>>>=8,t[e+3]=n,4),setBigInt64LE(t,e,n){const l=0xffffffffn;let i=Number(n&l);t[e]=i,i>>=8,t[e+1]=i,i>>=8,t[e+2]=i,i>>=8,t[e+3]=i;let o=Number(n>>32n&l);return t[e+4]=o,o>>=8,t[e+5]=o,o>>=8,t[e+6]=o,o>>=8,t[e+7]=o,8},setFloat64LE:Xt?(t,e,n)=>(pt[0]=n,t[e]=yt[7],t[e+1]=yt[6],t[e+2]=yt[5],t[e+3]=yt[4],t[e+4]=yt[3],t[e+5]=yt[2],t[e+6]=yt[1],t[e+7]=yt[0],8):(t,e,n)=>(pt[0]=n,t[e]=yt[0],t[e+1]=yt[1],t[e+2]=yt[2],t[e+3]=yt[3],t[e+4]=yt[4],t[e+5]=yt[5],t[e+6]=yt[6],t[e+7]=yt[7],8)};class Vt extends ht{get _bsontype(){return"Binary"}static BSON_BINARY_SUBTYPE_DEFAULT=0;static BUFFER_SIZE=256;static SUBTYPE_DEFAULT=0;static SUBTYPE_FUNCTION=1;static SUBTYPE_BYTE_ARRAY=2;static SUBTYPE_UUID_OLD=3;static SUBTYPE_UUID=4;static SUBTYPE_MD5=5;static SUBTYPE_ENCRYPTED=6;static SUBTYPE_COLUMN=7;static SUBTYPE_SENSITIVE=8;static SUBTYPE_VECTOR=9;static SUBTYPE_USER_DEFINED=128;static VECTOR_TYPE=Object.freeze({Int8:3,Float32:39,PackedBit:16});buffer;sub_type;position;constructor(t,e){if(super(),null!=t&&"string"==typeof t&&!ArrayBuffer.isView(t)&&!u(t)&&!Array.isArray(t))throw new A("Binary can only be constructed from Uint8Array or number[]");this.sub_type=e??Vt.BSON_BINARY_SUBTYPE_DEFAULT,null==t?(this.buffer=mt.allocate(Vt.BUFFER_SIZE),this.position=0):(this.buffer=Array.isArray(t)?mt.fromNumberArray(t):mt.toLocalBufferType(t),this.position=this.buffer.byteLength)}put(t){if("string"==typeof t&&1!==t.length)throw new A("only accepts single character String");if("number"!=typeof t&&1!==t.length)throw new A("only accepts single character Uint8Array or Array");let e;if(e="string"==typeof t?t.charCodeAt(0):"number"==typeof t?t:t[0],e<0||e>255)throw new A("only accepts number in a valid unsigned byte range 0-255");if(this.buffer.byteLength>this.position)this.buffer[this.position++]=e;else{const t=mt.allocate(Vt.BUFFER_SIZE+this.buffer.length);t.set(this.buffer,0),this.buffer=t,this.buffer[this.position++]=e}}write(t,e){if(e="number"==typeof e?e:this.position,this.buffer.byteLength<e+t.length){const e=mt.allocate(this.buffer.byteLength+t.length);e.set(this.buffer,0),this.buffer=e}if(ArrayBuffer.isView(t))this.buffer.set(mt.toLocalBufferType(t),e),this.position=e+t.byteLength>this.position?e+t.length:this.position;else if("string"==typeof t)throw new A("input cannot be string")}read(t,e){const n=t+(e=e&&e>0?e:this.position);return this.buffer.subarray(t,n>this.position?this.position:n)}value(){return this.buffer.length===this.position?this.buffer:this.buffer.subarray(0,this.position)}length(){return this.position}toJSON(){return mt.toBase64(this.buffer.subarray(0,this.position))}toString(t){return"hex"===t?mt.toHex(this.buffer.subarray(0,this.position)):"base64"===t?mt.toBase64(this.buffer.subarray(0,this.position)):mt.toUTF8(this.buffer,0,this.position,!1)}toExtendedJSON(t){t=t||{},this.sub_type===Vt.SUBTYPE_VECTOR&&Wt(this);const e=mt.toBase64(this.buffer),n=Number(this.sub_type).toString(16);return t.legacy?{$binary:e,$type:1===n.length?"0"+n:n}:{$binary:{base64:e,subType:1===n.length?"0"+n:n}}}toUUID(){if(this.sub_type===Vt.SUBTYPE_UUID)return new Yt(this.buffer.subarray(0,this.position));throw new A(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${Vt.SUBTYPE_UUID}" is currently supported.`)}static createFromHexString(t,e){return new Vt(mt.fromHex(t),e)}static createFromBase64(t,e){return new Vt(mt.fromBase64(t),e)}static fromExtendedJSON(t,e){let n,l;if(e=e||{},"$binary"in t?e.legacy&&"string"==typeof t.$binary&&"$type"in t?(l=t.$type?parseInt(t.$type,16):0,n=mt.fromBase64(t.$binary)):"string"!=typeof t.$binary&&(l=t.$binary.subType?parseInt(t.$binary.subType,16):0,n=mt.fromBase64(t.$binary.base64)):"$uuid"in t&&(l=4,n=Yt.bytesFromString(t.$uuid)),!n)throw new A(`Unexpected Binary Extended JSON format ${JSON.stringify(t)}`);return l===_?new Yt(n):new Vt(n,l)}inspect(t,e,n){n??=X;return`Binary.createFromBase64(${n(mt.toBase64(this.buffer.subarray(0,this.position)),e)}, ${n(this.sub_type,e)})`}toInt8Array(){if(this.sub_type!==Vt.SUBTYPE_VECTOR)throw new A("Binary sub_type is not Vector");if(this.buffer[0]!==Vt.VECTOR_TYPE.Int8)throw new A("Binary datatype field is not Int8");return Wt(this),new Int8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toFloat32Array(){if(this.sub_type!==Vt.SUBTYPE_VECTOR)throw new A("Binary sub_type is not Vector");if(this.buffer[0]!==Vt.VECTOR_TYPE.Float32)throw new A("Binary datatype field is not Float32");Wt(this);const t=new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position));return Gt.isBigEndian&&mt.swap32(t),new Float32Array(t.buffer)}toPackedBits(){if(this.sub_type!==Vt.SUBTYPE_VECTOR)throw new A("Binary sub_type is not Vector");if(this.buffer[0]!==Vt.VECTOR_TYPE.PackedBit)throw new A("Binary datatype field is not packed bit");return Wt(this),new Uint8Array(this.buffer.buffer.slice(this.buffer.byteOffset+2,this.buffer.byteOffset+this.position))}toBits(){if(this.sub_type!==Vt.SUBTYPE_VECTOR)throw new A("Binary sub_type is not Vector");if(this.buffer[0]!==Vt.VECTOR_TYPE.PackedBit)throw new A("Binary datatype field is not packed bit");Wt(this);const t=8*(this.length()-2)-this.buffer[1],e=new Int8Array(t);for(let t=0;t<e.length;t++){const n=t/8|0,l=this.buffer[n+2]>>7-t%8&1;e[t]=l}return e}static fromInt8Array(t){const e=mt.allocate(t.byteLength+2);e[0]=Vt.VECTOR_TYPE.Int8,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2);const l=new this(e,this.SUBTYPE_VECTOR);return Wt(l),l}static fromFloat32Array(t){const e=mt.allocate(t.byteLength+2);e[0]=Vt.VECTOR_TYPE.Float32,e[1]=0;const n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength);e.set(n,2),Gt.isBigEndian&&mt.swap32(new Uint8Array(e.buffer,2));const l=new this(e,this.SUBTYPE_VECTOR);return Wt(l),l}static fromPackedBits(t,e=0){const n=mt.allocate(t.byteLength+2);n[0]=Vt.VECTOR_TYPE.PackedBit,n[1]=e,n.set(t,2);const l=new this(n,this.SUBTYPE_VECTOR);return Wt(l),l}static fromBits(t){const e=t.length+7>>>3,n=new Uint8Array(e+2);n[0]=Vt.VECTOR_TYPE.PackedBit;const l=t.length%8;n[1]=0===l?0:8-l;for(let e=0;e<t.length;e++){const l=e>>>3,i=t[e];if(0!==i&&1!==i)throw new A(`Invalid bit value at ${e}: must be 0 or 1, found ${t[e]}`);if(0===i)continue;const o=7-e%8;n[l+2]|=i<<o}return new this(n,Vt.SUBTYPE_VECTOR)}}function Wt(t){if(t.sub_type!==Vt.SUBTYPE_VECTOR)return;const e=t.position,n=t.buffer[0],l=t.buffer[1];if((n===Vt.VECTOR_TYPE.Float32||n===Vt.VECTOR_TYPE.Int8)&&0!==l)throw new A("Invalid Vector: padding must be zero for int8 and float32 vectors");if(n===Vt.VECTOR_TYPE.Float32&&0!==e&&e-2!=0&&(e-2)%4!=0)throw new A("Invalid Vector: Float32 vector must contain a multiple of 4 bytes");if(n===Vt.VECTOR_TYPE.PackedBit&&0!==l&&2===e)throw new A("Invalid Vector: padding must be zero for packed bit vectors that are empty");if(n===Vt.VECTOR_TYPE.PackedBit&&l>7)throw new A(`Invalid Vector: padding must be a value between 0 and 7. found: ${l}`)}const ft=/^[0-9A-F]{32}$/i,gt=/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;class Yt extends Vt{constructor(t){let e;if(null==t)e=Yt.generate();else if(t instanceof Yt)e=mt.toLocalBufferType(new Uint8Array(t.buffer));else if(ArrayBuffer.isView(t)&&16===t.byteLength)e=mt.toLocalBufferType(t);else{if("string"!=typeof t)throw new A("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).");e=Yt.bytesFromString(t)}super(e,_)}get id(){return this.buffer}set id(t){this.buffer=t}toHexString(t=!0){return t?[mt.toHex(this.buffer.subarray(0,4)),mt.toHex(this.buffer.subarray(4,6)),mt.toHex(this.buffer.subarray(6,8)),mt.toHex(this.buffer.subarray(8,10)),mt.toHex(this.buffer.subarray(10,16))].join("-"):mt.toHex(this.buffer)}toString(t){return"hex"===t?mt.toHex(this.id):"base64"===t?mt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}equals(t){if(!t)return!1;if(t instanceof Yt)return mt.equals(t.id,this.id);try{return mt.equals(new Yt(t).id,this.id)}catch{return!1}}toBinary(){return new Vt(this.id,Vt.SUBTYPE_UUID)}static generate(){const t=mt.randomBytes(16);return t[6]=15&t[6]|64,t[8]=63&t[8]|128,t}static isValid(t){return!!t&&("string"==typeof t?Yt.isValidUUIDString(t):m(t)?16===t.byteLength:"Binary"===t._bsontype&&t.sub_type===this.SUBTYPE_UUID&&16===t.buffer.byteLength)}static createFromHexString(t){const e=Yt.bytesFromString(t);return new Yt(e)}static createFromBase64(t){return new Yt(mt.fromBase64(t))}static bytesFromString(t){if(!Yt.isValidUUIDString(t))throw new A("UUID string representation must be 32 hex digits or canonical hyphenated representation");return mt.fromHex(t.replace(/-/g,""))}static isValidUUIDString(t){return ft.test(t)||gt.test(t)}inspect(t,e,n){return n??=X,`new UUID(${n(this.toHexString(),e)})`}}class It extends ht{get _bsontype(){return"Code"}code;scope;constructor(t,e){super(),this.code=t.toString(),this.scope=e??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(t){return new It(t.$code,t.$scope)}inspect(t,e,n){n??=X;let l=n(this.code,e);const i=l.includes("\n");null!=this.scope&&(l+=`,${i?"\n":" "}${n(this.scope,e)}`);return`new Code(${i?"\n":""}${l}${i&&null===this.scope?"\n":""})`}}function Rt(t){return null!=t&&"object"==typeof t&&"$id"in t&&null!=t.$id&&"$ref"in t&&"string"==typeof t.$ref&&(!("$db"in t)||"$db"in t&&"string"==typeof t.$db)}class Jt extends ht{get _bsontype(){return"DBRef"}collection;oid;db;fields;constructor(t,e,n,l){super();const i=t.split(".");2===i.length&&(n=i.shift(),t=i.shift()),this.collection=t,this.oid=e,this.db=n,this.fields=l||{}}get namespace(){return this.collection}set namespace(t){this.collection=t}toJSON(){const t=Object.assign({$ref:this.collection,$id:this.oid},this.fields);return null!=this.db&&(t.$db=this.db),t}toExtendedJSON(t){t=t||{};let e={$ref:this.collection,$id:this.oid};return t.legacy||(this.db&&(e.$db=this.db),e=Object.assign(e,this.fields)),e}static fromExtendedJSON(t){const e=Object.assign({},t);return delete e.$ref,delete e.$id,delete e.$db,new Jt(t.$ref,t.$id,t.$db,e)}inspect(t,e,n){n??=X;const l=[n(this.namespace,e),n(this.oid,e),...this.db?[n(this.db,e)]:[],...Object.keys(this.fields).length>0?[n(this.fields,e)]:[]];return l[1]=n===X?`new ObjectId(${l[1]})`:l[1],`new DBRef(${l.join(", ")})`}}function St(t){if(""===t)return t;let e=0;const n="-"===t[e],l="+"===t[e];(l||n)&&(e+=1);let i=!1;for(;e<t.length&&"0"===t[e];++e)i=!0;return i?`${n?"-":""}${t.length===e?"0":t.slice(e)}`:l?t.slice(1):t}let Kt;try{Kt=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 Tt=4294967296,Lt=0x10000000000000000,zt=Lt/2,xt={},Ut={},Nt=/^(\+?0|(\+|-)?[1-9][0-9]*)$/;class wt extends ht{get _bsontype(){return"Long"}get __isLong__(){return!0}high;low;unsigned;constructor(t=0,e,n){super();const l="boolean"==typeof e?e:Boolean(n),i="number"==typeof e?e:0,o="string"==typeof t?wt.fromString(t,l):"bigint"==typeof t?wt.fromBigInt(t,l):{low:0|t,high:0|i,unsigned:l};this.low=o.low,this.high=o.high,this.unsigned=o.unsigned}static TWO_PWR_24=wt.fromInt(16777216);static MAX_UNSIGNED_VALUE=wt.fromBits(-1,-1,!0);static ZERO=wt.fromInt(0);static UZERO=wt.fromInt(0,!0);static ONE=wt.fromInt(1);static UONE=wt.fromInt(1,!0);static NEG_ONE=wt.fromInt(-1);static MAX_VALUE=wt.fromBits(-1,2147483647,!1);static MIN_VALUE=wt.fromBits(0,-2147483648,!1);static fromBits(t,e,n){return new wt(t,e,n)}static fromInt(t,e){let n,l,i;return e?(i=0<=(t>>>=0)&&t<256)&&(l=Ut[t],l)?l:(n=wt.fromBits(t,(0|t)<0?-1:0,!0),i&&(Ut[t]=n),n):(i=-128<=(t|=0)&&t<128)&&(l=xt[t],l)?l:(n=wt.fromBits(t,t<0?-1:0,!1),i&&(xt[t]=n),n)}static fromNumber(t,e){if(isNaN(t))return e?wt.UZERO:wt.ZERO;if(e){if(t<0)return wt.UZERO;if(t>=Lt)return wt.MAX_UNSIGNED_VALUE}else{if(t<=-zt)return wt.MIN_VALUE;if(t+1>=zt)return wt.MAX_VALUE}return t<0?wt.fromNumber(-t,e).neg():wt.fromBits(t%Tt|0,t/Tt|0,e)}static fromBigInt(t,e){const n=0xffffffffn;return new wt(Number(t&n),Number(t>>32n&n),e)}static _fromString(t,e,n){if(0===t.length)throw new A("empty string");if(n<2||36<n)throw new A("radix");let l;if((l=t.indexOf("-"))>0)throw new A("interior hyphen");if(0===l)return wt._fromString(t.substring(1),e,n).neg();const i=wt.fromNumber(Math.pow(n,8));let o=wt.ZERO;for(let e=0;e<t.length;e+=8){const l=Math.min(8,t.length-e),c=parseInt(t.substring(e,e+l),n);if(l<8){const t=wt.fromNumber(Math.pow(n,l));o=o.mul(t).add(wt.fromNumber(c))}else o=o.mul(i),o=o.add(wt.fromNumber(c))}return o.unsigned=e,o}static fromStringStrict(t,e,n){let l=!1;if("number"==typeof e?(n=e,e=!1):l=!!e,n??=10,t.trim()!==t)throw new A(`Input: '${t}' contains leading and/or trailing whitespace`);if(!function(t,e){const n="0123456789abcdefghijklmnopqrstuvwxyz".slice(0,e=e??10);return!new RegExp(`[^-+${n}]`,"i").test(t)&&t}(t,n))throw new A(`Input: '${t}' contains invalid characters for radix: ${n}`);const i=St(t),o=wt._fromString(i,l,n);if(o.toString(n).toLowerCase()!==i.toLowerCase())throw new A(`Input: ${t} is not representable as ${o.unsigned?"an unsigned":"a signed"} 64-bit Long ${null!=n?`with radix: ${n}`:""}`);return o}static fromString(t,e,n){let l=!1;return"number"==typeof e?(n=e,e=!1):l=!!e,n??=10,"NaN"===t&&n<24||("Infinity"===t||"+Infinity"===t||"-Infinity"===t)&&n<35?wt.ZERO:wt._fromString(t,l,n)}static fromBytes(t,e,n){return n?wt.fromBytesLE(t,e):wt.fromBytesBE(t,e)}static fromBytesLE(t,e){return new wt(t[0]|t[1]<<8|t[2]<<16|t[3]<<24,t[4]|t[5]<<8|t[6]<<16|t[7]<<24,e)}static fromBytesBE(t,e){return new wt(t[4]<<24|t[5]<<16|t[6]<<8|t[7],t[0]<<24|t[1]<<16|t[2]<<8|t[3],e)}static isLong(t){return null!=t&&"object"==typeof t&&"__isLong__"in t&&!0===t.__isLong__}static fromValue(t,e){return"number"==typeof t?wt.fromNumber(t,e):"string"==typeof t?wt.fromString(t,e):wt.fromBits(t.low,t.high,"boolean"==typeof e?e:t.unsigned)}add(t){wt.isLong(t)||(t=wt.fromValue(t));const e=this.high>>>16,n=65535&this.high,l=this.low>>>16,i=65535&this.low,o=t.high>>>16,c=65535&t.high,s=t.low>>>16;let a=0,d=0,b=0,Z=0;return Z+=i+(65535&t.low),b+=Z>>>16,Z&=65535,b+=l+s,d+=b>>>16,b&=65535,d+=n+c,a+=d>>>16,d&=65535,a+=e+o,a&=65535,wt.fromBits(b<<16|Z,a<<16|d,this.unsigned)}and(t){return wt.isLong(t)||(t=wt.fromValue(t)),wt.fromBits(this.low&t.low,this.high&t.high,this.unsigned)}compare(t){if(wt.isLong(t)||(t=wt.fromValue(t)),this.eq(t))return 0;const e=this.isNegative(),n=t.isNegative();return e&&!n?-1:!e&&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(wt.isLong(t)||(t=wt.fromValue(t)),t.isZero())throw new A("division by zero");if(Kt){if(!this.unsigned&&-2147483648===this.high&&-1===t.low&&-1===t.high)return this;const e=(this.unsigned?Kt.div_u:Kt.div_s)(this.low,this.high,t.low,t.high);return wt.fromBits(e,Kt.get_high(),this.unsigned)}if(this.isZero())return this.unsigned?wt.UZERO:wt.ZERO;let e,n,l;if(this.unsigned){if(t.unsigned||(t=t.toUnsigned()),t.gt(this))return wt.UZERO;if(t.gt(this.shru(1)))return wt.UONE;l=wt.UZERO}else{if(this.eq(wt.MIN_VALUE)){if(t.eq(wt.ONE)||t.eq(wt.NEG_ONE))return wt.MIN_VALUE;if(t.eq(wt.MIN_VALUE))return wt.ONE;return e=this.shr(1).div(t).shl(1),e.eq(wt.ZERO)?t.isNegative()?wt.ONE:wt.NEG_ONE:(n=this.sub(t.mul(e)),l=e.add(n.div(t)),l)}if(t.eq(wt.MIN_VALUE))return this.unsigned?wt.UZERO:wt.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();l=wt.ZERO}for(n=this;n.gte(t);){e=Math.max(1,Math.floor(n.toNumber()/t.toNumber()));const i=Math.ceil(Math.log(e)/Math.LN2),o=i<=48?1:Math.pow(2,i-48);let c=wt.fromNumber(e),s=c.mul(t);for(;s.isNegative()||s.gt(n);)e-=o,c=wt.fromNumber(e,this.unsigned),s=c.mul(t);c.isZero()&&(c=wt.ONE),l=l.add(c),n=n.sub(s)}return l}div(t){return this.divide(t)}equals(t){return wt.isLong(t)||(t=wt.fromValue(t)),(this.unsigned===t.unsigned||this.high>>>31!=1||t.high>>>31!=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(wt.MIN_VALUE)?64:this.neg().getNumBitsAbs();const t=0!==this.high?this.high:this.low;let e;for(e=31;e>0&&!(t&1<<e);e--);return 0!==this.high?e+33:e+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!(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(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(wt.isLong(t)||(t=wt.fromValue(t)),Kt){const e=(this.unsigned?Kt.rem_u:Kt.rem_s)(this.low,this.high,t.low,t.high);return wt.fromBits(e,Kt.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 wt.ZERO;if(wt.isLong(t)||(t=wt.fromValue(t)),Kt){const e=Kt.mul(this.low,this.high,t.low,t.high);return wt.fromBits(e,Kt.get_high(),this.unsigned)}if(t.isZero())return wt.ZERO;if(this.eq(wt.MIN_VALUE))return t.isOdd()?wt.MIN_VALUE:wt.ZERO;if(t.eq(wt.MIN_VALUE))return this.isOdd()?wt.MIN_VALUE:wt.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(wt.TWO_PWR_24)&&t.lt(wt.TWO_PWR_24))return wt.fromNumber(this.toNumber()*t.toNumber(),this.unsigned);const e=this.high>>>16,n=65535&this.high,l=this.low>>>16,i=65535&this.low,o=t.high>>>16,c=65535&t.high,s=t.low>>>16,a=65535&t.low;let d=0,b=0,Z=0,r=0;return r+=i*a,Z+=r>>>16,r&=65535,Z+=l*a,b+=Z>>>16,Z&=65535,Z+=i*s,b+=Z>>>16,Z&=65535,b+=n*a,d+=b>>>16,b&=65535,b+=l*s,d+=b>>>16,b&=65535,b+=i*c,d+=b>>>16,b&=65535,d+=e*a+n*s+l*c+i*o,d&=65535,wt.fromBits(Z<<16|r,d<<16|b,this.unsigned)}mul(t){return this.multiply(t)}negate(){return!this.unsigned&&this.eq(wt.MIN_VALUE)?wt.MIN_VALUE:this.not().add(wt.ONE)}neg(){return this.negate()}not(){return wt.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 wt.isLong(t)||(t=wt.fromValue(t)),wt.fromBits(this.low|t.low,this.high|t.high,this.unsigned)}shiftLeft(t){return wt.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?wt.fromBits(this.low<<t,this.high<<t|this.low>>>32-t,this.unsigned):wt.fromBits(0,this.low<<t-32,this.unsigned)}shl(t){return this.shiftLeft(t)}shiftRight(t){return wt.isLong(t)&&(t=t.toInt()),0==(t&=63)?this:t<32?wt.fromBits(this.low>>>t|this.high<<32-t,this.high>>t,this.unsigned):wt.fromBits(this.high>>t-32,this.high>=0?0:-1,this.unsigned)}shr(t){return this.shiftRight(t)}shiftRightUnsigned(t){if(wt.isLong(t)&&(t=t.toInt()),0===(t&=63))return this;{const e=this.high;if(t<32){const n=this.low;return wt.fromBits(n>>>t|e<<32-t,e>>>t,this.unsigned)}return 32===t?wt.fromBits(e,0,this.unsigned):wt.fromBits(e>>>t-32,0,this.unsigned)}}shr_u(t){return this.shiftRightUnsigned(t)}shru(t){return this.shiftRightUnsigned(t)}subtract(t){return wt.isLong(t)||(t=wt.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)*Tt+(this.low>>>0):this.high*Tt+(this.low>>>0)}toBigInt(){return BigInt(this.toString())}toBytes(t){return t?this.toBytesLE():this.toBytesBE()}toBytesLE(){const t=this.high,e=this.low;return[255&e,e>>>8&255,e>>>16&255,e>>>24,255&t,t>>>8&255,t>>>16&255,t>>>24]}toBytesBE(){const t=this.high,e=this.low;return[t>>>24,t>>>16&255,t>>>8&255,255&t,e>>>24,e>>>16&255,e>>>8&255,255&e]}toSigned(){return this.unsigned?wt.fromBits(this.low,this.high,!1):this}toString(t){if((t=t||10)<2||36<t)throw new A("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(wt.MIN_VALUE)){const e=wt.fromNumber(t),n=this.div(e),l=n.mul(e).sub(this);return n.toString(t)+l.toInt().toString(t)}return"-"+this.neg().toString(t)}const e=wt.fromNumber(Math.pow(t,6),this.unsigned);let n=this,l="";for(;;){const i=n.div(e);let o=(n.sub(i.mul(e)).toInt()>>>0).toString(t);if(n=i,n.isZero())return o+l;for(;o.length<6;)o="0"+o;l=""+o+l}}toUnsigned(){return this.unsigned?this:wt.fromBits(this.low,this.high,!0)}xor(t){return wt.isLong(t)||(t=wt.fromValue(t)),wt.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,e){const{useBigInt64:n=!1,relaxed:l=!0}={...e};if(t.$numberLong.length>20)throw new A("$numberLong string is too long");if(!Nt.test(t.$numberLong))throw new A(`$numberLong string "${t.$numberLong}" is in an invalid format`);if(n){const e=BigInt(t.$numberLong);return BigInt.asIntN(64,e)}const i=wt.fromString(t.$numberLong);return l?i.toNumber():i}inspect(t,e,n){n??=X;return`new Long(${n(this.toString(),e)}${this.unsigned?`, ${n(this.unsigned,e)}`:""})`}}const kt=/^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/,Ht=/^(\+|-)?(Infinity|inf)$/i,Ct=/^(\+|-)?NaN$/i,Bt=6111,vt=-6176,jt=mt.fromNumberArray([124,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Mt=mt.fromNumberArray([248,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Pt=mt.fromNumberArray([120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0].reverse()),Ft=/^([-+])?(\d+)?$/;function Qt(t){return!isNaN(parseInt(t,10))}function Ot(t){const e=wt.fromNumber(1e9);let n=wt.fromNumber(0);if(!(t.parts[0]||t.parts[1]||t.parts[2]||t.parts[3]))return{quotient:t,rem:n};for(let l=0;l<=3;l++)n=n.shiftLeft(32),n=n.add(new wt(t.parts[l],0)),t.parts[l]=n.div(e).low,n=n.modulo(e);return{quotient:t,rem:n}}function Et(t,e){throw new A(`"${t}" is not a valid Decimal128 string - ${e}`)}class _t extends ht{get _bsontype(){return"Decimal128"}bytes;constructor(t){if(super(),"string"==typeof t)this.bytes=_t.fromString(t).bytes;else{if(!(t instanceof Uint8Array||m(t)))throw new A("Decimal128 must take a Buffer or string");if(16!==t.byteLength)throw new A("Decimal128 must take a Buffer of 16 bytes");this.bytes=t}}static fromString(t){return _t._fromString(t,{allowRounding:!1})}static fromStringWithRounding(t){return _t._fromString(t,{allowRounding:!0})}static _fromString(t,e){let n=!1,l=!1,i=!1,o=!1,c=0,s=0,a=0,d=0,b=0;const Z=[0];let r=0,m=0,u=0,h=0,p=new wt(0,0),y=new wt(0,0),X=0,G=0;if(t.length>=7e3)throw new A(t+" not a valid Decimal128 string");const V=t.match(kt),W=t.match(Ht),f=t.match(Ct);if(!V&&!W&&!f||0===t.length)throw new A(t+" not a valid Decimal128 string");if(V){const e=V[2],n=V[4],l=V[5],i=V[6];n&&void 0===i&&Et(t,"missing exponent power"),n&&void 0===e&&Et(t,"missing exponent base"),void 0===n&&(l||i)&&Et(t,"missing e before exponent")}if("+"!==t[G]&&"-"!==t[G]||(l=!0,n="-"===t[G++]),!Qt(t[G])&&"."!==t[G]){if("i"===t[G]||"I"===t[G])return new _t(n?Mt:Pt);if("N"===t[G])return new _t(jt)}for(;Qt(t[G])||"."===t[G];)"."!==t[G]?(r<34&&("0"!==t[G]||o)&&(o||(b=s),o=!0,Z[m++]=parseInt(t[G],10),r+=1),o&&(a+=1),i&&(d+=1),s+=1,G+=1):(i&&Et(t,"contains multiple periods"),i=!0,G+=1);if(i&&!s)throw new A(t+" not a valid Decimal128 string");if("e"===t[G]||"E"===t[G]){const e=t.substr(++G).match(Ft);if(!e||!e[2])return new _t(jt);h=parseInt(e[0],10),G+=e[0].length}if(t[G])return new _t(jt);if(r){if(u=r-1,c=a,1!==c)for(;"0"===t[b+c-1+Number(l)+Number(i)];)c-=1}else Z[0]=0,a=1,r=1,c=0;for(h<=d&&d>h+16384?h=vt:h-=d;h>Bt;){if(u+=1,u>=34){if(0===c){h=Bt;break}Et(t,"overflow")}h-=1}if(e.allowRounding){for(;h<vt||r<a;){if(0===u&&c<r){h=vt,c=0;break}if(r<a?a-=1:u-=1,h<Bt)h+=1;else{if(Z.join("").match(/^0+$/)){h=Bt;break}Et(t,"overflow")}}if(u+1<c){let e=s;i&&(b+=1,e+=1),l&&(b+=1,e+=1);const o=parseInt(t[b+u+1],10);let c=0;if(o>=5&&(c=1,5===o)){c=Z[u]%2==1?1:0;for(let n=b+u+2;n<e;n++)if(parseInt(t[n],10)){c=1;break}}if(c){let t=u;for(;t>=0&&++Z[t]>9;t--)if(Z[t]=0,0===t){if(!(h<Bt))return new _t(n?Mt:Pt);h+=1,Z[t]=1}}}}else{for(;h<vt||r<a;){if(0===u){if(0===c){h=vt;break}Et(t,"exponent underflow")}r<a?("0"!==t[a-1+Number(l)+Number(i)]&&0!==c&&Et(t,"inexact rounding"),a-=1):(0!==Z[u]&&Et(t,"inexact rounding"),u-=1),h<Bt?h+=1:Et(t,"overflow")}if(u+1<c){i&&(b+=1),l&&(b+=1);0!==parseInt(t[b+u+1],10)&&Et(t,"inexact rounding")}}if(p=wt.fromNumber(0),y=wt.fromNumber(0),0===c)p=wt.fromNumber(0),y=wt.fromNumber(0);else if(u<17){let t=0;for(y=wt.fromNumber(Z[t++]),p=new wt(0,0);t<=u;t++)y=y.multiply(wt.fromNumber(10)),y=y.add(wt.fromNumber(Z[t]))}else{let t=0;for(p=wt.fromNumber(Z[t++]);t<=u-17;t++)p=p.multiply(wt.fromNumber(10)),p=p.add(wt.fromNumber(Z[t]));for(y=wt.fromNumber(Z[t++]);t<=u;t++)y=y.multiply(wt.fromNumber(10)),y=y.add(wt.fromNumber(Z[t]))}const g=function(t,e){if(!t&&!e)return{high:wt.fromNumber(0),low:wt.fromNumber(0)};const n=t.shiftRightUnsigned(32),l=new wt(t.getLowBits(),0),i=e.shiftRightUnsigned(32),o=new wt(e.getLowBits(),0);let c=n.multiply(i),s=n.multiply(o);const a=l.multiply(i);let d=l.multiply(o);return c=c.add(s.shiftRightUnsigned(32)),s=new wt(s.getLowBits(),0).add(a).add(d.shiftRightUnsigned(32)),c=c.add(s.shiftRightUnsigned(32)),d=s.shiftLeft(32).add(new wt(d.getLowBits(),0)),{high:c,low:d}}(p,wt.fromString("100000000000000000"));g.low=g.low.add(y),function(t,e){const n=t.high>>>0,l=e.high>>>0;if(n<l)return!0;if(n===l&&t.low>>>0<e.low>>>0)return!0;return!1}(g.low,y)&&(g.high=g.high.add(wt.fromNumber(1))),X=h+6176;const Y={low:wt.fromNumber(0),high:wt.fromNumber(0)};g.high.shiftRightUnsigned(49).and(wt.fromNumber(1)).equals(wt.fromNumber(1))?(Y.high=Y.high.or(wt.fromNumber(3).shiftLeft(61)),Y.high=Y.high.or(wt.fromNumber(X).and(wt.fromNumber(16383).shiftLeft(47))),Y.high=Y.high.or(g.high.and(wt.fromNumber(0x7fffffffffff)))):(Y.high=Y.high.or(wt.fromNumber(16383&X).shiftLeft(49)),Y.high=Y.high.or(g.high.and(wt.fromNumber(562949953421311)))),Y.low=g.low,n&&(Y.high=Y.high.or(wt.fromString("9223372036854775808")));const I=mt.allocateUnsafe(16);return G=0,I[G++]=255&Y.low.low,I[G++]=Y.low.low>>8&255,I[G++]=Y.low.low>>16&255,I[G++]=Y.low.low>>24&255,I[G++]=255&Y.low.high,I[G++]=Y.low.high>>8&255,I[G++]=Y.low.high>>16&255,I[G++]=Y.low.high>>24&255,I[G++]=255&Y.high.low,I[G++]=Y.high.low>>8&255,I[G++]=Y.high.low>>16&255,I[G++]=Y.high.low>>24&255,I[G++]=255&Y.high.high,I[G++]=Y.high.high>>8&255,I[G++]=Y.high.high>>16&255,I[G++]=Y.high.high>>24&255,new _t(I)}toString(){let t,e=0;const n=new Array(36);for(let t=0;t<n.length;t++)n[t]=0;let l,i,o,c=0,s=!1,a={parts:[0,0,0,0]};const d=[];c=0;const b=this.bytes,Z=b[c++]|b[c++]<<8|b[c++]<<16|b[c++]<<24,r=b[c++]|b[c++]<<8|b[c++]<<16|b[c++]<<24,m=b[c++]|b[c++]<<8|b[c++]<<16|b[c++]<<24,u=b[c++]|b[c++]<<8|b[c++]<<16|b[c++]<<24;c=0;({low:new wt(Z,r),high:new wt(m,u)}).high.lessThan(wt.ZERO)&&d.push("-");const h=u>>26&31;if(h>>3==3){if(30===h)return d.join("")+"Infinity";if(31===h)return"NaN";t=u>>15&16383,l=8+(u>>14&1)}else l=u>>14&7,t=u>>17&16383;const p=t-6176;if(a.parts[0]=(16383&u)+((15&l)<<14),a.parts[1]=m,a.parts[2]=r,a.parts[3]=Z,0===a.parts[0]&&0===a.parts[1]&&0===a.parts[2]&&0===a.parts[3])s=!0;else for(o=3;o>=0;o--){let t=0;const e=Ot(a);if(a=e.quotient,t=e.rem.low,t)for(i=8;i>=0;i--)n[9*o+i]=t%10,t=Math.floor(t/10)}if(s)e=1,n[c]=0;else for(e=36;!n[c];)e-=1,c+=1;const y=e-1+p;if(y>=34||y<=-7||p>0){if(e>34)return d.push("0"),p>0?d.push(`E+${p}`):p<0&&d.push(`E${p}`),d.join("");d.push(`${n[c++]}`),e-=1,e&&d.push(".");for(let t=0;t<e;t++)d.push(`${n[c++]}`);d.push("E"),y>0?d.push(`+${y}`):d.push(`${y}`)}else if(p>=0)for(let t=0;t<e;t++)d.push(`${n[c++]}`);else{let t=e+p;if(t>0)for(let e=0;e<t;e++)d.push(`${n[c++]}`);else d.push("0");for(d.push(".");t++<0;)d.push("0");for(let l=0;l<e-Math.max(t-1,0);l++)d.push(`${n[c++]}`)}return d.join("")}toJSON(){return{$numberDecimal:this.toString()}}toExtendedJSON(){return{$numberDecimal:this.toString()}}static fromExtendedJSON(t){return _t.fromString(t.$numberDecimal)}inspect(t,e,n){n??=X;return`new Decimal128(${n(this.toString(),e)})`}}class Dt extends ht{get _bsontype(){return"Double"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=+t}static fromString(t){const e=Number(t);if("NaN"===t)return new Dt(NaN);if("Infinity"===t)return new Dt(1/0);if("-Infinity"===t)return new Dt(-1/0);if(!Number.isFinite(e))throw new A(`Input: ${t} is not representable as a Double`);if(t.trim()!==t)throw new A(`Input: '${t}' contains whitespace`);if(""===t)throw new A("Input is an empty string");if(/[^-0-9.+eE]/.test(t))throw new A(`Input: '${t}' is not in decimal or exponential notation`);return new Dt(e)}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,e){const n=parseFloat(t.$numberDouble);return e&&e.relaxed?n:new Dt(n)}inspect(t,e,n){return n??=X,`new Double(${n(this.value,e)})`}}class At extends ht{get _bsontype(){return"Int32"}value;constructor(t){super(),t instanceof Number&&(t=t.valueOf()),this.value=0|+t}static fromString(t){const e=St(t),n=Number(t);if(W<n)throw new A(`Input: '${t}' is larger than the maximum value for Int32`);if(f>n)throw new A(`Input: '${t}' is smaller than the minimum value for Int32`);if(!Number.isSafeInteger(n))throw new A(`Input: '${t}' is not a safe integer`);if(n.toString()!==e)throw new A(`Input: '${t}' is not a valid Int32 string`);return new At(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,e){return e&&e.relaxed?parseInt(t.$numberInt,10):new At(t.$numberInt)}inspect(t,e,n){return n??=X,`new Int32(${n(this.value,e)})`}}class $t extends ht{get _bsontype(){return"MaxKey"}toExtendedJSON(){return{$maxKey:1}}static fromExtendedJSON(){return new $t}inspect(){return"new MaxKey()"}}class qt extends ht{get _bsontype(){return"MinKey"}toExtendedJSON(){return{$minKey:1}}static fromExtendedJSON(){return new qt}inspect(){return"new MinKey()"}}let te=null;const ee=new WeakMap;class ne extends ht{get _bsontype(){return"ObjectId"}static index=Math.floor(16777215*Math.random());static cacheHexString;buffer;constructor(t){let e;if(super(),"object"==typeof t&&t&&"id"in t){if("string"!=typeof t.id&&!ArrayBuffer.isView(t.id))throw new A("Argument passed in must have an id that is of type string or Buffer");e="toHexString"in t&&"function"==typeof t.toHexString?mt.fromHex(t.toHexString()):t.id}else e=t;if(null==e)this.buffer=ne.generate();else if(ArrayBuffer.isView(e)&&12===e.byteLength)this.buffer=mt.toLocalBufferType(e);else{if("string"!=typeof e)throw new A("Argument passed in does not match the accepted types");if(!ne.validateHexString(e))throw new A("input must be a 24 character hex string, 12 byte Uint8Array, or an integer");this.buffer=mt.fromHex(e),ne.cacheHexString&&ee.set(this,e)}}get id(){return this.buffer}set id(t){this.buffer=t,ne.cacheHexString&&ee.set(this,mt.toHex(t))}static validateHexString(t){if(24!==t?.length)return!1;for(let e=0;e<24;e++){const n=t.charCodeAt(e);if(!(n>=48&&n<=57||n>=97&&n<=102||n>=65&&n<=70))return!1}return!0}toHexString(){if(ne.cacheHexString){const t=ee.get(this);if(t)return t}const t=mt.toHex(this.id);return ne.cacheHexString&&ee.set(this,t),t}static getInc(){return ne.index=(ne.index+1)%16777215}static generate(t){"number"!=typeof t&&(t=Math.floor(Date.now()/1e3));const e=ne.getInc(),n=mt.allocateUnsafe(12);return Gt.setInt32BE(n,0,t),null===te&&(te=mt.randomBytes(5)),n[4]=te[0],n[5]=te[1],n[6]=te[2],n[7]=te[3],n[8]=te[4],n[11]=255&e,n[10]=e>>8&255,n[9]=e>>16&255,n}toString(t){return"base64"===t?mt.toBase64(this.id):this.toHexString()}toJSON(){return this.toHexString()}static is(t){return null!=t&&"object"==typeof t&&"_bsontype"in t&&"ObjectId"===t._bsontype}equals(t){if(null==t)return!1;if(ne.is(t))return this.buffer[11]===t.buffer[11]&&mt.equals(this.buffer,t.buffer);if("string"==typeof t)return t.toLowerCase()===this.toHexString();if("object"==typeof t&&"function"==typeof t.toHexString){const e=t.toHexString(),n=this.toHexString();return"string"==typeof e&&e.toLowerCase()===n}return!1}getTimestamp(){const t=new Date,e=Gt.getUint32BE(this.buffer,0);return t.setTime(1e3*Math.floor(e)),t}static createPk(){return new ne}serializeInto(t,e){return t[e]=this.buffer[0],t[e+1]=this.buffer[1],t[e+2]=this.buffer[2],t[e+3]=this.buffer[3],t[e+4]=this.buffer[4],t[e+5]=this.buffer[5],t[e+6]=this.buffer[6],t[e+7]=this.buffer[7],t[e+8]=this.buffer[8],t[e+9]=this.buffer[9],t[e+10]=this.buffer[10],t[e+11]=this.buffer[11],12}static createFromTime(t){const e=mt.allocate(12);for(let t=11;t>=4;t--)e[t]=0;return Gt.setInt32BE(e,0,t),new ne(e)}static createFromHexString(t){if(24!==t?.length)throw new A("hex string must be 24 characters");return new ne(mt.fromHex(t))}static createFromBase64(t){if(16!==t?.length)throw new A("base64 string must be 16 characters");return new ne(mt.fromBase64(t))}static isValid(t){if(null==t)return!1;if("string"==typeof t)return ne.validateHexString(t);try{return new ne(t),!0}catch{return!1}}toExtendedJSON(){return this.toHexString?{$oid:this.toHexString()}:{$oid:this.toString("hex")}}static fromExtendedJSON(t){return new ne(t.$oid)}isCached(){return ne.cacheHexString&&ee.has(this)}inspect(t,e,n){return n??=X,`new ObjectId(${n(this.toHexString(),e)})`}}function le(t,e,n){let l=5;if(Array.isArray(t))for(let i=0;i<t.length;i++)l+=ie(i.toString(),t[i],e,!0,n);else{"function"==typeof t?.toBSON&&(t=t.toBSON());for(const i of Object.keys(t))l+=ie(i,t[i],e,!1,n)}return l}function ie(t,e,n=!1,l=!1,i=!1){switch("function"==typeof e?.toBSON&&(e=e.toBSON()),typeof e){case"string":return 1+mt.utf8ByteLength(t)+1+4+mt.utf8ByteLength(e)+1;case"number":return Math.floor(e)===e&&e>=R&&e<=I&&e>=f&&e<=W?(null!=t?mt.utf8ByteLength(t)+1:0)+5:(null!=t?mt.utf8ByteLength(t)+1:0)+9;case"undefined":return l||!i?(null!=t?mt.utf8ByteLength(t)+1:0)+1:0;case"boolean":return(null!=t?mt.utf8ByteLength(t)+1:0)+2;case"object":if(null!=e&&"string"==typeof e._bsontype&&e[V]!==G)throw new $;if(null==e||"MinKey"===e._bsontype||"MaxKey"===e._bsontype)return(null!=t?mt.utf8ByteLength(t)+1:0)+1;if("ObjectId"===e._bsontype)return(null!=t?mt.utf8ByteLength(t)+1:0)+13;if(e instanceof Date||y(e))return(null!=t?mt.utf8ByteLength(t)+1:0)+9;if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||u(e))return(null!=t?mt.utf8ByteLength(t)+1:0)+6+e.byteLength;if("Long"===e._bsontype||"Double"===e._bsontype||"Timestamp"===e._bsontype)return(null!=t?mt.utf8ByteLength(t)+1:0)+9;if("Decimal128"===e._bsontype)return(null!=t?mt.utf8ByteLength(t)+1:0)+17;if("Code"===e._bsontype)return null!=e.scope&&Object.keys(e.scope).length>0?(null!=t?mt.utf8ByteLength(t)+1:0)+1+4+4+mt.utf8ByteLength(e.code.toString())+1+le(e.scope,n,i):(null!=t?mt.utf8ByteLength(t)+1:0)+1+4+mt.utf8ByteLength(e.code.toString())+1;if("Binary"===e._bsontype){const n=e;return n.sub_type===Vt.SUBTYPE_BYTE_ARRAY?(null!=t?mt.utf8ByteLength(t)+1:0)+(n.position+1+4+1+4):(null!=t?mt.utf8ByteLength(t)+1:0)+(n.position+1+4+1)}if("Symbol"===e._bsontype)return(null!=t?mt.utf8ByteLength(t)+1:0)+mt.utf8ByteLength(e.value)+4+1+1;if("DBRef"===e._bsontype){const l=Object.assign({$ref:e.collection,$id:e.oid},e.fields);return null!=e.db&&(l.$db=e.db),(null!=t?mt.utf8ByteLength(t)+1:0)+1+le(l,n,i)}return e instanceof RegExp||h(e)?(null!=t?mt.utf8ByteLength(t)+1:0)+1+mt.utf8ByteLength(e.source)+1+(e.global?1:0)+(e.ignoreCase?1:0)+(e.multiline?1:0)+1:"BSONRegExp"===e._bsontype?(null!=t?mt.utf8ByteLength(t)+1:0)+1+mt.utf8ByteLength(e.pattern)+1+mt.utf8ByteLength(e.options)+1:(null!=t?mt.utf8ByteLength(t)+1:0)+le(e,n,i)+1;case"function":return n?(null!=t?mt.utf8ByteLength(t)+1:0)+1+4+mt.utf8ByteLength(e.toString())+1:0;case"bigint":return(null!=t?mt.utf8ByteLength(t)+1:0)+9;case"symbol":return 0;default:throw new A("Unrecognized JS type: "+typeof e)}}class oe extends ht{get _bsontype(){return"BSONRegExp"}pattern;options;constructor(t,e){if(super(),this.pattern=t,this.options=(e??"").split("").sort().join(""),-1!==this.pattern.indexOf("\0"))throw new A(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);if(-1!==this.options.indexOf("\0"))throw new A(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);for(let t=0;t<this.options.length;t++)if("i"!==this.options[t]&&"m"!==this.options[t]&&"x"!==this.options[t]&&"l"!==this.options[t]&&"s"!==this.options[t]&&"u"!==this.options[t])throw new A(`The