bson.bundle.js 273 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976
  1. var BSON = (function (exports) {
  2. 'use strict';
  3. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  4. function createCommonjsModule(fn, module) {
  5. return module = { exports: {} }, fn(module, module.exports), module.exports;
  6. }
  7. var byteLength_1 = byteLength;
  8. var toByteArray_1 = toByteArray;
  9. var fromByteArray_1 = fromByteArray;
  10. var lookup = [];
  11. var revLookup = [];
  12. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  13. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  14. for (var i = 0, len = code.length; i < len; ++i) {
  15. lookup[i] = code[i];
  16. revLookup[code.charCodeAt(i)] = i;
  17. } // Support decoding URL-safe base64 strings, as Node.js does.
  18. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  19. revLookup['-'.charCodeAt(0)] = 62;
  20. revLookup['_'.charCodeAt(0)] = 63;
  21. function getLens(b64) {
  22. var len = b64.length;
  23. if (len % 4 > 0) {
  24. throw new Error('Invalid string. Length must be a multiple of 4');
  25. } // Trim off extra bytes after placeholder bytes are found
  26. // See: https://github.com/beatgammit/base64-js/issues/42
  27. var validLen = b64.indexOf('=');
  28. if (validLen === -1) validLen = len;
  29. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  30. return [validLen, placeHoldersLen];
  31. } // base64 is 4/3 + up to two characters of the original data
  32. function byteLength(b64) {
  33. var lens = getLens(b64);
  34. var validLen = lens[0];
  35. var placeHoldersLen = lens[1];
  36. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  37. }
  38. function _byteLength(b64, validLen, placeHoldersLen) {
  39. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  40. }
  41. function toByteArray(b64) {
  42. var tmp;
  43. var lens = getLens(b64);
  44. var validLen = lens[0];
  45. var placeHoldersLen = lens[1];
  46. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  47. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  48. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  49. for (var i = 0; i < len; i += 4) {
  50. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  51. arr[curByte++] = tmp >> 16 & 0xFF;
  52. arr[curByte++] = tmp >> 8 & 0xFF;
  53. arr[curByte++] = tmp & 0xFF;
  54. }
  55. if (placeHoldersLen === 2) {
  56. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  57. arr[curByte++] = tmp & 0xFF;
  58. }
  59. if (placeHoldersLen === 1) {
  60. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  61. arr[curByte++] = tmp >> 8 & 0xFF;
  62. arr[curByte++] = tmp & 0xFF;
  63. }
  64. return arr;
  65. }
  66. function tripletToBase64(num) {
  67. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  68. }
  69. function encodeChunk(uint8, start, end) {
  70. var tmp;
  71. var output = [];
  72. for (var i = start; i < end; i += 3) {
  73. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  74. output.push(tripletToBase64(tmp));
  75. }
  76. return output.join('');
  77. }
  78. function fromByteArray(uint8) {
  79. var tmp;
  80. var len = uint8.length;
  81. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  82. var parts = [];
  83. var maxChunkLength = 16383; // must be multiple of 3
  84. // go through the array every three bytes, we'll deal with trailing stuff later
  85. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  86. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  87. } // pad the end with zeros, but make sure to not forget the extra bytes
  88. if (extraBytes === 1) {
  89. tmp = uint8[len - 1];
  90. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  91. } else if (extraBytes === 2) {
  92. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  93. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  94. }
  95. return parts.join('');
  96. }
  97. var base64Js = {
  98. byteLength: byteLength_1,
  99. toByteArray: toByteArray_1,
  100. fromByteArray: fromByteArray_1
  101. };
  102. var read = function read(buffer, offset, isLE, mLen, nBytes) {
  103. var e, m;
  104. var eLen = nBytes * 8 - mLen - 1;
  105. var eMax = (1 << eLen) - 1;
  106. var eBias = eMax >> 1;
  107. var nBits = -7;
  108. var i = isLE ? nBytes - 1 : 0;
  109. var d = isLE ? -1 : 1;
  110. var s = buffer[offset + i];
  111. i += d;
  112. e = s & (1 << -nBits) - 1;
  113. s >>= -nBits;
  114. nBits += eLen;
  115. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  116. m = e & (1 << -nBits) - 1;
  117. e >>= -nBits;
  118. nBits += mLen;
  119. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  120. if (e === 0) {
  121. e = 1 - eBias;
  122. } else if (e === eMax) {
  123. return m ? NaN : (s ? -1 : 1) * Infinity;
  124. } else {
  125. m = m + Math.pow(2, mLen);
  126. e = e - eBias;
  127. }
  128. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  129. };
  130. var write = function write(buffer, value, offset, isLE, mLen, nBytes) {
  131. var e, m, c;
  132. var eLen = nBytes * 8 - mLen - 1;
  133. var eMax = (1 << eLen) - 1;
  134. var eBias = eMax >> 1;
  135. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  136. var i = isLE ? 0 : nBytes - 1;
  137. var d = isLE ? 1 : -1;
  138. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  139. value = Math.abs(value);
  140. if (isNaN(value) || value === Infinity) {
  141. m = isNaN(value) ? 1 : 0;
  142. e = eMax;
  143. } else {
  144. e = Math.floor(Math.log(value) / Math.LN2);
  145. if (value * (c = Math.pow(2, -e)) < 1) {
  146. e--;
  147. c *= 2;
  148. }
  149. if (e + eBias >= 1) {
  150. value += rt / c;
  151. } else {
  152. value += rt * Math.pow(2, 1 - eBias);
  153. }
  154. if (value * c >= 2) {
  155. e++;
  156. c /= 2;
  157. }
  158. if (e + eBias >= eMax) {
  159. m = 0;
  160. e = eMax;
  161. } else if (e + eBias >= 1) {
  162. m = (value * c - 1) * Math.pow(2, mLen);
  163. e = e + eBias;
  164. } else {
  165. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  166. e = 0;
  167. }
  168. }
  169. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  170. e = e << mLen | m;
  171. eLen += mLen;
  172. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  173. buffer[offset + i - d] |= s * 128;
  174. };
  175. var ieee754 = {
  176. read: read,
  177. write: write
  178. };
  179. var buffer = createCommonjsModule(function (module, exports) {
  180. exports.Buffer = Buffer;
  181. exports.SlowBuffer = SlowBuffer;
  182. exports.INSPECT_MAX_BYTES = 50;
  183. var K_MAX_LENGTH = 0x7fffffff;
  184. exports.kMaxLength = K_MAX_LENGTH;
  185. /**
  186. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  187. * === true Use Uint8Array implementation (fastest)
  188. * === false Print warning and recommend using `buffer` v4.x which has an Object
  189. * implementation (most compatible, even IE6)
  190. *
  191. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  192. * Opera 11.6+, iOS 4.2+.
  193. *
  194. * We report that the browser does not support typed arrays if the are not subclassable
  195. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  196. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  197. * for __proto__ and has a buggy typed array implementation.
  198. */
  199. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  200. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  201. console.error('This browser lacks typed array (Uint8Array) support which is required by ' + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.');
  202. }
  203. function typedArraySupport() {
  204. // Can typed array instances can be augmented?
  205. try {
  206. var arr = new Uint8Array(1);
  207. arr.__proto__ = {
  208. __proto__: Uint8Array.prototype,
  209. foo: function foo() {
  210. return 42;
  211. }
  212. };
  213. return arr.foo() === 42;
  214. } catch (e) {
  215. return false;
  216. }
  217. }
  218. Object.defineProperty(Buffer.prototype, 'parent', {
  219. get: function get() {
  220. if (!(this instanceof Buffer)) {
  221. return undefined;
  222. }
  223. return this.buffer;
  224. }
  225. });
  226. Object.defineProperty(Buffer.prototype, 'offset', {
  227. get: function get() {
  228. if (!(this instanceof Buffer)) {
  229. return undefined;
  230. }
  231. return this.byteOffset;
  232. }
  233. });
  234. function createBuffer(length) {
  235. if (length > K_MAX_LENGTH) {
  236. throw new RangeError('Invalid typed array length');
  237. } // Return an augmented `Uint8Array` instance
  238. var buf = new Uint8Array(length);
  239. buf.__proto__ = Buffer.prototype;
  240. return buf;
  241. }
  242. /**
  243. * The Buffer constructor returns instances of `Uint8Array` that have their
  244. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  245. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  246. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  247. * returns a single octet.
  248. *
  249. * The `Uint8Array` prototype remains unmodified.
  250. */
  251. function Buffer(arg, encodingOrOffset, length) {
  252. // Common case.
  253. if (typeof arg === 'number') {
  254. if (typeof encodingOrOffset === 'string') {
  255. throw new Error('If encoding is specified then the first argument must be a string');
  256. }
  257. return allocUnsafe(arg);
  258. }
  259. return from(arg, encodingOrOffset, length);
  260. } // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97
  261. if (typeof Symbol !== 'undefined' && Symbol.species && Buffer[Symbol.species] === Buffer) {
  262. Object.defineProperty(Buffer, Symbol.species, {
  263. value: null,
  264. configurable: true,
  265. enumerable: false,
  266. writable: false
  267. });
  268. }
  269. Buffer.poolSize = 8192; // not used by this implementation
  270. function from(value, encodingOrOffset, length) {
  271. if (typeof value === 'number') {
  272. throw new TypeError('"value" argument must not be a number');
  273. }
  274. if (isArrayBuffer(value) || value && isArrayBuffer(value.buffer)) {
  275. return fromArrayBuffer(value, encodingOrOffset, length);
  276. }
  277. if (typeof value === 'string') {
  278. return fromString(value, encodingOrOffset);
  279. }
  280. return fromObject(value);
  281. }
  282. /**
  283. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  284. * if value is a number.
  285. * Buffer.from(str[, encoding])
  286. * Buffer.from(array)
  287. * Buffer.from(buffer)
  288. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  289. **/
  290. Buffer.from = function (value, encodingOrOffset, length) {
  291. return from(value, encodingOrOffset, length);
  292. }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  293. // https://github.com/feross/buffer/pull/148
  294. Buffer.prototype.__proto__ = Uint8Array.prototype;
  295. Buffer.__proto__ = Uint8Array;
  296. function assertSize(size) {
  297. if (typeof size !== 'number') {
  298. throw new TypeError('"size" argument must be of type number');
  299. } else if (size < 0) {
  300. throw new RangeError('"size" argument must not be negative');
  301. }
  302. }
  303. function alloc(size, fill, encoding) {
  304. assertSize(size);
  305. if (size <= 0) {
  306. return createBuffer(size);
  307. }
  308. if (fill !== undefined) {
  309. // Only pay attention to encoding if it's a string. This
  310. // prevents accidentally sending in a number that would
  311. // be interpretted as a start offset.
  312. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  313. }
  314. return createBuffer(size);
  315. }
  316. /**
  317. * Creates a new filled Buffer instance.
  318. * alloc(size[, fill[, encoding]])
  319. **/
  320. Buffer.alloc = function (size, fill, encoding) {
  321. return alloc(size, fill, encoding);
  322. };
  323. function allocUnsafe(size) {
  324. assertSize(size);
  325. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  326. }
  327. /**
  328. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  329. * */
  330. Buffer.allocUnsafe = function (size) {
  331. return allocUnsafe(size);
  332. };
  333. /**
  334. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  335. */
  336. Buffer.allocUnsafeSlow = function (size) {
  337. return allocUnsafe(size);
  338. };
  339. function fromString(string, encoding) {
  340. if (typeof encoding !== 'string' || encoding === '') {
  341. encoding = 'utf8';
  342. }
  343. if (!Buffer.isEncoding(encoding)) {
  344. throw new TypeError('Unknown encoding: ' + encoding);
  345. }
  346. var length = byteLength(string, encoding) | 0;
  347. var buf = createBuffer(length);
  348. var actual = buf.write(string, encoding);
  349. if (actual !== length) {
  350. // Writing a hex string, for example, that contains invalid characters will
  351. // cause everything after the first invalid character to be ignored. (e.g.
  352. // 'abxxcd' will be treated as 'ab')
  353. buf = buf.slice(0, actual);
  354. }
  355. return buf;
  356. }
  357. function fromArrayLike(array) {
  358. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  359. var buf = createBuffer(length);
  360. for (var i = 0; i < length; i += 1) {
  361. buf[i] = array[i] & 255;
  362. }
  363. return buf;
  364. }
  365. function fromArrayBuffer(array, byteOffset, length) {
  366. if (byteOffset < 0 || array.byteLength < byteOffset) {
  367. throw new RangeError('"offset" is outside of buffer bounds');
  368. }
  369. if (array.byteLength < byteOffset + (length || 0)) {
  370. throw new RangeError('"length" is outside of buffer bounds');
  371. }
  372. var buf;
  373. if (byteOffset === undefined && length === undefined) {
  374. buf = new Uint8Array(array);
  375. } else if (length === undefined) {
  376. buf = new Uint8Array(array, byteOffset);
  377. } else {
  378. buf = new Uint8Array(array, byteOffset, length);
  379. } // Return an augmented `Uint8Array` instance
  380. buf.__proto__ = Buffer.prototype;
  381. return buf;
  382. }
  383. function fromObject(obj) {
  384. if (Buffer.isBuffer(obj)) {
  385. var len = checked(obj.length) | 0;
  386. var buf = createBuffer(len);
  387. if (buf.length === 0) {
  388. return buf;
  389. }
  390. obj.copy(buf, 0, 0, len);
  391. return buf;
  392. }
  393. if (obj) {
  394. if (ArrayBuffer.isView(obj) || 'length' in obj) {
  395. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  396. return createBuffer(0);
  397. }
  398. return fromArrayLike(obj);
  399. }
  400. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  401. return fromArrayLike(obj.data);
  402. }
  403. }
  404. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object.');
  405. }
  406. function checked(length) {
  407. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  408. // length is NaN (which is otherwise coerced to zero.)
  409. if (length >= K_MAX_LENGTH) {
  410. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  411. }
  412. return length | 0;
  413. }
  414. function SlowBuffer(length) {
  415. if (+length != length) {
  416. // eslint-disable-line eqeqeq
  417. length = 0;
  418. }
  419. return Buffer.alloc(+length);
  420. }
  421. Buffer.isBuffer = function isBuffer(b) {
  422. return b != null && b._isBuffer === true;
  423. };
  424. Buffer.compare = function compare(a, b) {
  425. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  426. throw new TypeError('Arguments must be Buffers');
  427. }
  428. if (a === b) return 0;
  429. var x = a.length;
  430. var y = b.length;
  431. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  432. if (a[i] !== b[i]) {
  433. x = a[i];
  434. y = b[i];
  435. break;
  436. }
  437. }
  438. if (x < y) return -1;
  439. if (y < x) return 1;
  440. return 0;
  441. };
  442. Buffer.isEncoding = function isEncoding(encoding) {
  443. switch (String(encoding).toLowerCase()) {
  444. case 'hex':
  445. case 'utf8':
  446. case 'utf-8':
  447. case 'ascii':
  448. case 'latin1':
  449. case 'binary':
  450. case 'base64':
  451. case 'ucs2':
  452. case 'ucs-2':
  453. case 'utf16le':
  454. case 'utf-16le':
  455. return true;
  456. default:
  457. return false;
  458. }
  459. };
  460. Buffer.concat = function concat(list, length) {
  461. if (!Array.isArray(list)) {
  462. throw new TypeError('"list" argument must be an Array of Buffers');
  463. }
  464. if (list.length === 0) {
  465. return Buffer.alloc(0);
  466. }
  467. var i;
  468. if (length === undefined) {
  469. length = 0;
  470. for (i = 0; i < list.length; ++i) {
  471. length += list[i].length;
  472. }
  473. }
  474. var buffer = Buffer.allocUnsafe(length);
  475. var pos = 0;
  476. for (i = 0; i < list.length; ++i) {
  477. var buf = list[i];
  478. if (ArrayBuffer.isView(buf)) {
  479. buf = Buffer.from(buf);
  480. }
  481. if (!Buffer.isBuffer(buf)) {
  482. throw new TypeError('"list" argument must be an Array of Buffers');
  483. }
  484. buf.copy(buffer, pos);
  485. pos += buf.length;
  486. }
  487. return buffer;
  488. };
  489. function byteLength(string, encoding) {
  490. if (Buffer.isBuffer(string)) {
  491. return string.length;
  492. }
  493. if (ArrayBuffer.isView(string) || isArrayBuffer(string)) {
  494. return string.byteLength;
  495. }
  496. if (typeof string !== 'string') {
  497. string = '' + string;
  498. }
  499. var len = string.length;
  500. if (len === 0) return 0; // Use a for loop to avoid recursion
  501. var loweredCase = false;
  502. for (;;) {
  503. switch (encoding) {
  504. case 'ascii':
  505. case 'latin1':
  506. case 'binary':
  507. return len;
  508. case 'utf8':
  509. case 'utf-8':
  510. case undefined:
  511. return utf8ToBytes(string).length;
  512. case 'ucs2':
  513. case 'ucs-2':
  514. case 'utf16le':
  515. case 'utf-16le':
  516. return len * 2;
  517. case 'hex':
  518. return len >>> 1;
  519. case 'base64':
  520. return base64ToBytes(string).length;
  521. default:
  522. if (loweredCase) return utf8ToBytes(string).length; // assume utf8
  523. encoding = ('' + encoding).toLowerCase();
  524. loweredCase = true;
  525. }
  526. }
  527. }
  528. Buffer.byteLength = byteLength;
  529. function slowToString(encoding, start, end) {
  530. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  531. // property of a typed array.
  532. // This behaves neither like String nor Uint8Array in that we set start/end
  533. // to their upper/lower bounds if the value passed is out of range.
  534. // undefined is handled specially as per ECMA-262 6th Edition,
  535. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  536. if (start === undefined || start < 0) {
  537. start = 0;
  538. } // Return early if start > this.length. Done here to prevent potential uint32
  539. // coercion fail below.
  540. if (start > this.length) {
  541. return '';
  542. }
  543. if (end === undefined || end > this.length) {
  544. end = this.length;
  545. }
  546. if (end <= 0) {
  547. return '';
  548. } // Force coersion to uint32. This will also coerce falsey/NaN values to 0.
  549. end >>>= 0;
  550. start >>>= 0;
  551. if (end <= start) {
  552. return '';
  553. }
  554. if (!encoding) encoding = 'utf8';
  555. while (true) {
  556. switch (encoding) {
  557. case 'hex':
  558. return hexSlice(this, start, end);
  559. case 'utf8':
  560. case 'utf-8':
  561. return utf8Slice(this, start, end);
  562. case 'ascii':
  563. return asciiSlice(this, start, end);
  564. case 'latin1':
  565. case 'binary':
  566. return latin1Slice(this, start, end);
  567. case 'base64':
  568. return base64Slice(this, start, end);
  569. case 'ucs2':
  570. case 'ucs-2':
  571. case 'utf16le':
  572. case 'utf-16le':
  573. return utf16leSlice(this, start, end);
  574. default:
  575. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  576. encoding = (encoding + '').toLowerCase();
  577. loweredCase = true;
  578. }
  579. }
  580. } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  581. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  582. // reliably in a browserify context because there could be multiple different
  583. // copies of the 'buffer' package in use. This method works even for Buffer
  584. // instances that were created from another copy of the `buffer` package.
  585. // See: https://github.com/feross/buffer/issues/154
  586. Buffer.prototype._isBuffer = true;
  587. function swap(b, n, m) {
  588. var i = b[n];
  589. b[n] = b[m];
  590. b[m] = i;
  591. }
  592. Buffer.prototype.swap16 = function swap16() {
  593. var len = this.length;
  594. if (len % 2 !== 0) {
  595. throw new RangeError('Buffer size must be a multiple of 16-bits');
  596. }
  597. for (var i = 0; i < len; i += 2) {
  598. swap(this, i, i + 1);
  599. }
  600. return this;
  601. };
  602. Buffer.prototype.swap32 = function swap32() {
  603. var len = this.length;
  604. if (len % 4 !== 0) {
  605. throw new RangeError('Buffer size must be a multiple of 32-bits');
  606. }
  607. for (var i = 0; i < len; i += 4) {
  608. swap(this, i, i + 3);
  609. swap(this, i + 1, i + 2);
  610. }
  611. return this;
  612. };
  613. Buffer.prototype.swap64 = function swap64() {
  614. var len = this.length;
  615. if (len % 8 !== 0) {
  616. throw new RangeError('Buffer size must be a multiple of 64-bits');
  617. }
  618. for (var i = 0; i < len; i += 8) {
  619. swap(this, i, i + 7);
  620. swap(this, i + 1, i + 6);
  621. swap(this, i + 2, i + 5);
  622. swap(this, i + 3, i + 4);
  623. }
  624. return this;
  625. };
  626. Buffer.prototype.toString = function toString() {
  627. var length = this.length;
  628. if (length === 0) return '';
  629. if (arguments.length === 0) return utf8Slice(this, 0, length);
  630. return slowToString.apply(this, arguments);
  631. };
  632. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  633. Buffer.prototype.equals = function equals(b) {
  634. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  635. if (this === b) return true;
  636. return Buffer.compare(this, b) === 0;
  637. };
  638. Buffer.prototype.inspect = function inspect() {
  639. var str = '';
  640. var max = exports.INSPECT_MAX_BYTES;
  641. if (this.length > 0) {
  642. str = this.toString('hex', 0, max).match(/.{2}/g).join(' ');
  643. if (this.length > max) str += ' ... ';
  644. }
  645. return '<Buffer ' + str + '>';
  646. };
  647. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  648. if (!Buffer.isBuffer(target)) {
  649. throw new TypeError('Argument must be a Buffer');
  650. }
  651. if (start === undefined) {
  652. start = 0;
  653. }
  654. if (end === undefined) {
  655. end = target ? target.length : 0;
  656. }
  657. if (thisStart === undefined) {
  658. thisStart = 0;
  659. }
  660. if (thisEnd === undefined) {
  661. thisEnd = this.length;
  662. }
  663. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  664. throw new RangeError('out of range index');
  665. }
  666. if (thisStart >= thisEnd && start >= end) {
  667. return 0;
  668. }
  669. if (thisStart >= thisEnd) {
  670. return -1;
  671. }
  672. if (start >= end) {
  673. return 1;
  674. }
  675. start >>>= 0;
  676. end >>>= 0;
  677. thisStart >>>= 0;
  678. thisEnd >>>= 0;
  679. if (this === target) return 0;
  680. var x = thisEnd - thisStart;
  681. var y = end - start;
  682. var len = Math.min(x, y);
  683. var thisCopy = this.slice(thisStart, thisEnd);
  684. var targetCopy = target.slice(start, end);
  685. for (var i = 0; i < len; ++i) {
  686. if (thisCopy[i] !== targetCopy[i]) {
  687. x = thisCopy[i];
  688. y = targetCopy[i];
  689. break;
  690. }
  691. }
  692. if (x < y) return -1;
  693. if (y < x) return 1;
  694. return 0;
  695. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  696. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  697. //
  698. // Arguments:
  699. // - buffer - a Buffer to search
  700. // - val - a string, Buffer, or number
  701. // - byteOffset - an index into `buffer`; will be clamped to an int32
  702. // - encoding - an optional encoding, relevant is val is a string
  703. // - dir - true for indexOf, false for lastIndexOf
  704. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  705. // Empty buffer means no match
  706. if (buffer.length === 0) return -1; // Normalize byteOffset
  707. if (typeof byteOffset === 'string') {
  708. encoding = byteOffset;
  709. byteOffset = 0;
  710. } else if (byteOffset > 0x7fffffff) {
  711. byteOffset = 0x7fffffff;
  712. } else if (byteOffset < -0x80000000) {
  713. byteOffset = -0x80000000;
  714. }
  715. byteOffset = +byteOffset; // Coerce to Number.
  716. if (numberIsNaN(byteOffset)) {
  717. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  718. byteOffset = dir ? 0 : buffer.length - 1;
  719. } // Normalize byteOffset: negative offsets start from the end of the buffer
  720. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  721. if (byteOffset >= buffer.length) {
  722. if (dir) return -1;else byteOffset = buffer.length - 1;
  723. } else if (byteOffset < 0) {
  724. if (dir) byteOffset = 0;else return -1;
  725. } // Normalize val
  726. if (typeof val === 'string') {
  727. val = Buffer.from(val, encoding);
  728. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  729. if (Buffer.isBuffer(val)) {
  730. // Special case: looking for empty string/buffer always fails
  731. if (val.length === 0) {
  732. return -1;
  733. }
  734. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  735. } else if (typeof val === 'number') {
  736. val = val & 0xFF; // Search for a byte value [0-255]
  737. if (typeof Uint8Array.prototype.indexOf === 'function') {
  738. if (dir) {
  739. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  740. } else {
  741. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  742. }
  743. }
  744. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  745. }
  746. throw new TypeError('val must be string, number or Buffer');
  747. }
  748. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  749. var indexSize = 1;
  750. var arrLength = arr.length;
  751. var valLength = val.length;
  752. if (encoding !== undefined) {
  753. encoding = String(encoding).toLowerCase();
  754. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  755. if (arr.length < 2 || val.length < 2) {
  756. return -1;
  757. }
  758. indexSize = 2;
  759. arrLength /= 2;
  760. valLength /= 2;
  761. byteOffset /= 2;
  762. }
  763. }
  764. function read(buf, i) {
  765. if (indexSize === 1) {
  766. return buf[i];
  767. } else {
  768. return buf.readUInt16BE(i * indexSize);
  769. }
  770. }
  771. var i;
  772. if (dir) {
  773. var foundIndex = -1;
  774. for (i = byteOffset; i < arrLength; i++) {
  775. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  776. if (foundIndex === -1) foundIndex = i;
  777. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  778. } else {
  779. if (foundIndex !== -1) i -= i - foundIndex;
  780. foundIndex = -1;
  781. }
  782. }
  783. } else {
  784. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  785. for (i = byteOffset; i >= 0; i--) {
  786. var found = true;
  787. for (var j = 0; j < valLength; j++) {
  788. if (read(arr, i + j) !== read(val, j)) {
  789. found = false;
  790. break;
  791. }
  792. }
  793. if (found) return i;
  794. }
  795. }
  796. return -1;
  797. }
  798. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  799. return this.indexOf(val, byteOffset, encoding) !== -1;
  800. };
  801. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  802. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  803. };
  804. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  805. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  806. };
  807. function hexWrite(buf, string, offset, length) {
  808. offset = Number(offset) || 0;
  809. var remaining = buf.length - offset;
  810. if (!length) {
  811. length = remaining;
  812. } else {
  813. length = Number(length);
  814. if (length > remaining) {
  815. length = remaining;
  816. }
  817. }
  818. var strLen = string.length;
  819. if (length > strLen / 2) {
  820. length = strLen / 2;
  821. }
  822. for (var i = 0; i < length; ++i) {
  823. var parsed = parseInt(string.substr(i * 2, 2), 16);
  824. if (numberIsNaN(parsed)) return i;
  825. buf[offset + i] = parsed;
  826. }
  827. return i;
  828. }
  829. function utf8Write(buf, string, offset, length) {
  830. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  831. }
  832. function asciiWrite(buf, string, offset, length) {
  833. return blitBuffer(asciiToBytes(string), buf, offset, length);
  834. }
  835. function latin1Write(buf, string, offset, length) {
  836. return asciiWrite(buf, string, offset, length);
  837. }
  838. function base64Write(buf, string, offset, length) {
  839. return blitBuffer(base64ToBytes(string), buf, offset, length);
  840. }
  841. function ucs2Write(buf, string, offset, length) {
  842. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  843. }
  844. Buffer.prototype.write = function write(string, offset, length, encoding) {
  845. // Buffer#write(string)
  846. if (offset === undefined) {
  847. encoding = 'utf8';
  848. length = this.length;
  849. offset = 0; // Buffer#write(string, encoding)
  850. } else if (length === undefined && typeof offset === 'string') {
  851. encoding = offset;
  852. length = this.length;
  853. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  854. } else if (isFinite(offset)) {
  855. offset = offset >>> 0;
  856. if (isFinite(length)) {
  857. length = length >>> 0;
  858. if (encoding === undefined) encoding = 'utf8';
  859. } else {
  860. encoding = length;
  861. length = undefined;
  862. }
  863. } else {
  864. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  865. }
  866. var remaining = this.length - offset;
  867. if (length === undefined || length > remaining) length = remaining;
  868. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  869. throw new RangeError('Attempt to write outside buffer bounds');
  870. }
  871. if (!encoding) encoding = 'utf8';
  872. var loweredCase = false;
  873. for (;;) {
  874. switch (encoding) {
  875. case 'hex':
  876. return hexWrite(this, string, offset, length);
  877. case 'utf8':
  878. case 'utf-8':
  879. return utf8Write(this, string, offset, length);
  880. case 'ascii':
  881. return asciiWrite(this, string, offset, length);
  882. case 'latin1':
  883. case 'binary':
  884. return latin1Write(this, string, offset, length);
  885. case 'base64':
  886. // Warning: maxLength not taken into account in base64Write
  887. return base64Write(this, string, offset, length);
  888. case 'ucs2':
  889. case 'ucs-2':
  890. case 'utf16le':
  891. case 'utf-16le':
  892. return ucs2Write(this, string, offset, length);
  893. default:
  894. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  895. encoding = ('' + encoding).toLowerCase();
  896. loweredCase = true;
  897. }
  898. }
  899. };
  900. Buffer.prototype.toJSON = function toJSON() {
  901. return {
  902. type: 'Buffer',
  903. data: Array.prototype.slice.call(this._arr || this, 0)
  904. };
  905. };
  906. function base64Slice(buf, start, end) {
  907. if (start === 0 && end === buf.length) {
  908. return base64Js.fromByteArray(buf);
  909. } else {
  910. return base64Js.fromByteArray(buf.slice(start, end));
  911. }
  912. }
  913. function utf8Slice(buf, start, end) {
  914. end = Math.min(buf.length, end);
  915. var res = [];
  916. var i = start;
  917. while (i < end) {
  918. var firstByte = buf[i];
  919. var codePoint = null;
  920. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  921. if (i + bytesPerSequence <= end) {
  922. var secondByte, thirdByte, fourthByte, tempCodePoint;
  923. switch (bytesPerSequence) {
  924. case 1:
  925. if (firstByte < 0x80) {
  926. codePoint = firstByte;
  927. }
  928. break;
  929. case 2:
  930. secondByte = buf[i + 1];
  931. if ((secondByte & 0xC0) === 0x80) {
  932. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  933. if (tempCodePoint > 0x7F) {
  934. codePoint = tempCodePoint;
  935. }
  936. }
  937. break;
  938. case 3:
  939. secondByte = buf[i + 1];
  940. thirdByte = buf[i + 2];
  941. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  942. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  943. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  944. codePoint = tempCodePoint;
  945. }
  946. }
  947. break;
  948. case 4:
  949. secondByte = buf[i + 1];
  950. thirdByte = buf[i + 2];
  951. fourthByte = buf[i + 3];
  952. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  953. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  954. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  955. codePoint = tempCodePoint;
  956. }
  957. }
  958. }
  959. }
  960. if (codePoint === null) {
  961. // we did not generate a valid codePoint so insert a
  962. // replacement char (U+FFFD) and advance only 1 byte
  963. codePoint = 0xFFFD;
  964. bytesPerSequence = 1;
  965. } else if (codePoint > 0xFFFF) {
  966. // encode to utf16 (surrogate pair dance)
  967. codePoint -= 0x10000;
  968. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  969. codePoint = 0xDC00 | codePoint & 0x3FF;
  970. }
  971. res.push(codePoint);
  972. i += bytesPerSequence;
  973. }
  974. return decodeCodePointsArray(res);
  975. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  976. // the lowest limit is Chrome, with 0x10000 args.
  977. // We go 1 magnitude less, for safety
  978. var MAX_ARGUMENTS_LENGTH = 0x1000;
  979. function decodeCodePointsArray(codePoints) {
  980. var len = codePoints.length;
  981. if (len <= MAX_ARGUMENTS_LENGTH) {
  982. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  983. } // Decode in chunks to avoid "call stack size exceeded".
  984. var res = '';
  985. var i = 0;
  986. while (i < len) {
  987. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  988. }
  989. return res;
  990. }
  991. function asciiSlice(buf, start, end) {
  992. var ret = '';
  993. end = Math.min(buf.length, end);
  994. for (var i = start; i < end; ++i) {
  995. ret += String.fromCharCode(buf[i] & 0x7F);
  996. }
  997. return ret;
  998. }
  999. function latin1Slice(buf, start, end) {
  1000. var ret = '';
  1001. end = Math.min(buf.length, end);
  1002. for (var i = start; i < end; ++i) {
  1003. ret += String.fromCharCode(buf[i]);
  1004. }
  1005. return ret;
  1006. }
  1007. function hexSlice(buf, start, end) {
  1008. var len = buf.length;
  1009. if (!start || start < 0) start = 0;
  1010. if (!end || end < 0 || end > len) end = len;
  1011. var out = '';
  1012. for (var i = start; i < end; ++i) {
  1013. out += toHex(buf[i]);
  1014. }
  1015. return out;
  1016. }
  1017. function utf16leSlice(buf, start, end) {
  1018. var bytes = buf.slice(start, end);
  1019. var res = '';
  1020. for (var i = 0; i < bytes.length; i += 2) {
  1021. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  1022. }
  1023. return res;
  1024. }
  1025. Buffer.prototype.slice = function slice(start, end) {
  1026. var len = this.length;
  1027. start = ~~start;
  1028. end = end === undefined ? len : ~~end;
  1029. if (start < 0) {
  1030. start += len;
  1031. if (start < 0) start = 0;
  1032. } else if (start > len) {
  1033. start = len;
  1034. }
  1035. if (end < 0) {
  1036. end += len;
  1037. if (end < 0) end = 0;
  1038. } else if (end > len) {
  1039. end = len;
  1040. }
  1041. if (end < start) end = start;
  1042. var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
  1043. newBuf.__proto__ = Buffer.prototype;
  1044. return newBuf;
  1045. };
  1046. /*
  1047. * Need to make sure that buffer isn't trying to write out of bounds.
  1048. */
  1049. function checkOffset(offset, ext, length) {
  1050. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  1051. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  1052. }
  1053. Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  1054. offset = offset >>> 0;
  1055. byteLength = byteLength >>> 0;
  1056. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1057. var val = this[offset];
  1058. var mul = 1;
  1059. var i = 0;
  1060. while (++i < byteLength && (mul *= 0x100)) {
  1061. val += this[offset + i] * mul;
  1062. }
  1063. return val;
  1064. };
  1065. Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  1066. offset = offset >>> 0;
  1067. byteLength = byteLength >>> 0;
  1068. if (!noAssert) {
  1069. checkOffset(offset, byteLength, this.length);
  1070. }
  1071. var val = this[offset + --byteLength];
  1072. var mul = 1;
  1073. while (byteLength > 0 && (mul *= 0x100)) {
  1074. val += this[offset + --byteLength] * mul;
  1075. }
  1076. return val;
  1077. };
  1078. Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  1079. offset = offset >>> 0;
  1080. if (!noAssert) checkOffset(offset, 1, this.length);
  1081. return this[offset];
  1082. };
  1083. Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  1084. offset = offset >>> 0;
  1085. if (!noAssert) checkOffset(offset, 2, this.length);
  1086. return this[offset] | this[offset + 1] << 8;
  1087. };
  1088. Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  1089. offset = offset >>> 0;
  1090. if (!noAssert) checkOffset(offset, 2, this.length);
  1091. return this[offset] << 8 | this[offset + 1];
  1092. };
  1093. Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  1094. offset = offset >>> 0;
  1095. if (!noAssert) checkOffset(offset, 4, this.length);
  1096. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  1097. };
  1098. Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  1099. offset = offset >>> 0;
  1100. if (!noAssert) checkOffset(offset, 4, this.length);
  1101. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  1102. };
  1103. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  1104. offset = offset >>> 0;
  1105. byteLength = byteLength >>> 0;
  1106. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1107. var val = this[offset];
  1108. var mul = 1;
  1109. var i = 0;
  1110. while (++i < byteLength && (mul *= 0x100)) {
  1111. val += this[offset + i] * mul;
  1112. }
  1113. mul *= 0x80;
  1114. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1115. return val;
  1116. };
  1117. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  1118. offset = offset >>> 0;
  1119. byteLength = byteLength >>> 0;
  1120. if (!noAssert) checkOffset(offset, byteLength, this.length);
  1121. var i = byteLength;
  1122. var mul = 1;
  1123. var val = this[offset + --i];
  1124. while (i > 0 && (mul *= 0x100)) {
  1125. val += this[offset + --i] * mul;
  1126. }
  1127. mul *= 0x80;
  1128. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  1129. return val;
  1130. };
  1131. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  1132. offset = offset >>> 0;
  1133. if (!noAssert) checkOffset(offset, 1, this.length);
  1134. if (!(this[offset] & 0x80)) return this[offset];
  1135. return (0xff - this[offset] + 1) * -1;
  1136. };
  1137. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  1138. offset = offset >>> 0;
  1139. if (!noAssert) checkOffset(offset, 2, this.length);
  1140. var val = this[offset] | this[offset + 1] << 8;
  1141. return val & 0x8000 ? val | 0xFFFF0000 : val;
  1142. };
  1143. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  1144. offset = offset >>> 0;
  1145. if (!noAssert) checkOffset(offset, 2, this.length);
  1146. var val = this[offset + 1] | this[offset] << 8;
  1147. return val & 0x8000 ? val | 0xFFFF0000 : val;
  1148. };
  1149. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  1150. offset = offset >>> 0;
  1151. if (!noAssert) checkOffset(offset, 4, this.length);
  1152. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  1153. };
  1154. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  1155. offset = offset >>> 0;
  1156. if (!noAssert) checkOffset(offset, 4, this.length);
  1157. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  1158. };
  1159. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  1160. offset = offset >>> 0;
  1161. if (!noAssert) checkOffset(offset, 4, this.length);
  1162. return ieee754.read(this, offset, true, 23, 4);
  1163. };
  1164. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  1165. offset = offset >>> 0;
  1166. if (!noAssert) checkOffset(offset, 4, this.length);
  1167. return ieee754.read(this, offset, false, 23, 4);
  1168. };
  1169. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  1170. offset = offset >>> 0;
  1171. if (!noAssert) checkOffset(offset, 8, this.length);
  1172. return ieee754.read(this, offset, true, 52, 8);
  1173. };
  1174. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  1175. offset = offset >>> 0;
  1176. if (!noAssert) checkOffset(offset, 8, this.length);
  1177. return ieee754.read(this, offset, false, 52, 8);
  1178. };
  1179. function checkInt(buf, value, offset, ext, max, min) {
  1180. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  1181. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  1182. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  1183. }
  1184. Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  1185. value = +value;
  1186. offset = offset >>> 0;
  1187. byteLength = byteLength >>> 0;
  1188. if (!noAssert) {
  1189. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  1190. checkInt(this, value, offset, byteLength, maxBytes, 0);
  1191. }
  1192. var mul = 1;
  1193. var i = 0;
  1194. this[offset] = value & 0xFF;
  1195. while (++i < byteLength && (mul *= 0x100)) {
  1196. this[offset + i] = value / mul & 0xFF;
  1197. }
  1198. return offset + byteLength;
  1199. };
  1200. Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  1201. value = +value;
  1202. offset = offset >>> 0;
  1203. byteLength = byteLength >>> 0;
  1204. if (!noAssert) {
  1205. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  1206. checkInt(this, value, offset, byteLength, maxBytes, 0);
  1207. }
  1208. var i = byteLength - 1;
  1209. var mul = 1;
  1210. this[offset + i] = value & 0xFF;
  1211. while (--i >= 0 && (mul *= 0x100)) {
  1212. this[offset + i] = value / mul & 0xFF;
  1213. }
  1214. return offset + byteLength;
  1215. };
  1216. Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  1217. value = +value;
  1218. offset = offset >>> 0;
  1219. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  1220. this[offset] = value & 0xff;
  1221. return offset + 1;
  1222. };
  1223. Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  1224. value = +value;
  1225. offset = offset >>> 0;
  1226. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  1227. this[offset] = value & 0xff;
  1228. this[offset + 1] = value >>> 8;
  1229. return offset + 2;
  1230. };
  1231. Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  1232. value = +value;
  1233. offset = offset >>> 0;
  1234. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  1235. this[offset] = value >>> 8;
  1236. this[offset + 1] = value & 0xff;
  1237. return offset + 2;
  1238. };
  1239. Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  1240. value = +value;
  1241. offset = offset >>> 0;
  1242. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  1243. this[offset + 3] = value >>> 24;
  1244. this[offset + 2] = value >>> 16;
  1245. this[offset + 1] = value >>> 8;
  1246. this[offset] = value & 0xff;
  1247. return offset + 4;
  1248. };
  1249. Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  1250. value = +value;
  1251. offset = offset >>> 0;
  1252. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  1253. this[offset] = value >>> 24;
  1254. this[offset + 1] = value >>> 16;
  1255. this[offset + 2] = value >>> 8;
  1256. this[offset + 3] = value & 0xff;
  1257. return offset + 4;
  1258. };
  1259. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  1260. value = +value;
  1261. offset = offset >>> 0;
  1262. if (!noAssert) {
  1263. var limit = Math.pow(2, 8 * byteLength - 1);
  1264. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  1265. }
  1266. var i = 0;
  1267. var mul = 1;
  1268. var sub = 0;
  1269. this[offset] = value & 0xFF;
  1270. while (++i < byteLength && (mul *= 0x100)) {
  1271. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  1272. sub = 1;
  1273. }
  1274. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  1275. }
  1276. return offset + byteLength;
  1277. };
  1278. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  1279. value = +value;
  1280. offset = offset >>> 0;
  1281. if (!noAssert) {
  1282. var limit = Math.pow(2, 8 * byteLength - 1);
  1283. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  1284. }
  1285. var i = byteLength - 1;
  1286. var mul = 1;
  1287. var sub = 0;
  1288. this[offset + i] = value & 0xFF;
  1289. while (--i >= 0 && (mul *= 0x100)) {
  1290. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  1291. sub = 1;
  1292. }
  1293. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  1294. }
  1295. return offset + byteLength;
  1296. };
  1297. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  1298. value = +value;
  1299. offset = offset >>> 0;
  1300. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  1301. if (value < 0) value = 0xff + value + 1;
  1302. this[offset] = value & 0xff;
  1303. return offset + 1;
  1304. };
  1305. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  1306. value = +value;
  1307. offset = offset >>> 0;
  1308. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  1309. this[offset] = value & 0xff;
  1310. this[offset + 1] = value >>> 8;
  1311. return offset + 2;
  1312. };
  1313. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  1314. value = +value;
  1315. offset = offset >>> 0;
  1316. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  1317. this[offset] = value >>> 8;
  1318. this[offset + 1] = value & 0xff;
  1319. return offset + 2;
  1320. };
  1321. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  1322. value = +value;
  1323. offset = offset >>> 0;
  1324. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  1325. this[offset] = value & 0xff;
  1326. this[offset + 1] = value >>> 8;
  1327. this[offset + 2] = value >>> 16;
  1328. this[offset + 3] = value >>> 24;
  1329. return offset + 4;
  1330. };
  1331. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  1332. value = +value;
  1333. offset = offset >>> 0;
  1334. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  1335. if (value < 0) value = 0xffffffff + value + 1;
  1336. this[offset] = value >>> 24;
  1337. this[offset + 1] = value >>> 16;
  1338. this[offset + 2] = value >>> 8;
  1339. this[offset + 3] = value & 0xff;
  1340. return offset + 4;
  1341. };
  1342. function checkIEEE754(buf, value, offset, ext, max, min) {
  1343. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  1344. if (offset < 0) throw new RangeError('Index out of range');
  1345. }
  1346. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  1347. value = +value;
  1348. offset = offset >>> 0;
  1349. if (!noAssert) {
  1350. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  1351. }
  1352. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  1353. return offset + 4;
  1354. }
  1355. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  1356. return writeFloat(this, value, offset, true, noAssert);
  1357. };
  1358. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  1359. return writeFloat(this, value, offset, false, noAssert);
  1360. };
  1361. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  1362. value = +value;
  1363. offset = offset >>> 0;
  1364. if (!noAssert) {
  1365. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  1366. }
  1367. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  1368. return offset + 8;
  1369. }
  1370. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  1371. return writeDouble(this, value, offset, true, noAssert);
  1372. };
  1373. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  1374. return writeDouble(this, value, offset, false, noAssert);
  1375. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  1376. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  1377. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  1378. if (!start) start = 0;
  1379. if (!end && end !== 0) end = this.length;
  1380. if (targetStart >= target.length) targetStart = target.length;
  1381. if (!targetStart) targetStart = 0;
  1382. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  1383. if (end === start) return 0;
  1384. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  1385. if (targetStart < 0) {
  1386. throw new RangeError('targetStart out of bounds');
  1387. }
  1388. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  1389. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  1390. if (end > this.length) end = this.length;
  1391. if (target.length - targetStart < end - start) {
  1392. end = target.length - targetStart + start;
  1393. }
  1394. var len = end - start;
  1395. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  1396. // Use built-in when available, missing from IE11
  1397. this.copyWithin(targetStart, start, end);
  1398. } else if (this === target && start < targetStart && targetStart < end) {
  1399. // descending copy from end
  1400. for (var i = len - 1; i >= 0; --i) {
  1401. target[i + targetStart] = this[i + start];
  1402. }
  1403. } else {
  1404. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  1405. }
  1406. return len;
  1407. }; // Usage:
  1408. // buffer.fill(number[, offset[, end]])
  1409. // buffer.fill(buffer[, offset[, end]])
  1410. // buffer.fill(string[, offset[, end]][, encoding])
  1411. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  1412. // Handle string cases:
  1413. if (typeof val === 'string') {
  1414. if (typeof start === 'string') {
  1415. encoding = start;
  1416. start = 0;
  1417. end = this.length;
  1418. } else if (typeof end === 'string') {
  1419. encoding = end;
  1420. end = this.length;
  1421. }
  1422. if (encoding !== undefined && typeof encoding !== 'string') {
  1423. throw new TypeError('encoding must be a string');
  1424. }
  1425. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  1426. throw new TypeError('Unknown encoding: ' + encoding);
  1427. }
  1428. if (val.length === 1) {
  1429. var code = val.charCodeAt(0);
  1430. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  1431. // Fast path: If `val` fits into a single byte, use that numeric value.
  1432. val = code;
  1433. }
  1434. }
  1435. } else if (typeof val === 'number') {
  1436. val = val & 255;
  1437. } // Invalid ranges are not set to a default, so can range check early.
  1438. if (start < 0 || this.length < start || this.length < end) {
  1439. throw new RangeError('Out of range index');
  1440. }
  1441. if (end <= start) {
  1442. return this;
  1443. }
  1444. start = start >>> 0;
  1445. end = end === undefined ? this.length : end >>> 0;
  1446. if (!val) val = 0;
  1447. var i;
  1448. if (typeof val === 'number') {
  1449. for (i = start; i < end; ++i) {
  1450. this[i] = val;
  1451. }
  1452. } else {
  1453. var bytes = Buffer.isBuffer(val) ? val : new Buffer(val, encoding);
  1454. var len = bytes.length;
  1455. if (len === 0) {
  1456. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  1457. }
  1458. for (i = 0; i < end - start; ++i) {
  1459. this[i + start] = bytes[i % len];
  1460. }
  1461. }
  1462. return this;
  1463. }; // HELPER FUNCTIONS
  1464. // ================
  1465. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  1466. function base64clean(str) {
  1467. // Node takes equal signs as end of the Base64 encoding
  1468. str = str.split('=')[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not
  1469. str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  1470. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  1471. while (str.length % 4 !== 0) {
  1472. str = str + '=';
  1473. }
  1474. return str;
  1475. }
  1476. function toHex(n) {
  1477. if (n < 16) return '0' + n.toString(16);
  1478. return n.toString(16);
  1479. }
  1480. function utf8ToBytes(string, units) {
  1481. units = units || Infinity;
  1482. var codePoint;
  1483. var length = string.length;
  1484. var leadSurrogate = null;
  1485. var bytes = [];
  1486. for (var i = 0; i < length; ++i) {
  1487. codePoint = string.charCodeAt(i); // is surrogate component
  1488. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  1489. // last char was a lead
  1490. if (!leadSurrogate) {
  1491. // no lead yet
  1492. if (codePoint > 0xDBFF) {
  1493. // unexpected trail
  1494. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  1495. continue;
  1496. } else if (i + 1 === length) {
  1497. // unpaired lead
  1498. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  1499. continue;
  1500. } // valid lead
  1501. leadSurrogate = codePoint;
  1502. continue;
  1503. } // 2 leads in a row
  1504. if (codePoint < 0xDC00) {
  1505. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  1506. leadSurrogate = codePoint;
  1507. continue;
  1508. } // valid surrogate pair
  1509. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  1510. } else if (leadSurrogate) {
  1511. // valid bmp char, but last char was a lead
  1512. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  1513. }
  1514. leadSurrogate = null; // encode utf8
  1515. if (codePoint < 0x80) {
  1516. if ((units -= 1) < 0) break;
  1517. bytes.push(codePoint);
  1518. } else if (codePoint < 0x800) {
  1519. if ((units -= 2) < 0) break;
  1520. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  1521. } else if (codePoint < 0x10000) {
  1522. if ((units -= 3) < 0) break;
  1523. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  1524. } else if (codePoint < 0x110000) {
  1525. if ((units -= 4) < 0) break;
  1526. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  1527. } else {
  1528. throw new Error('Invalid code point');
  1529. }
  1530. }
  1531. return bytes;
  1532. }
  1533. function asciiToBytes(str) {
  1534. var byteArray = [];
  1535. for (var i = 0; i < str.length; ++i) {
  1536. // Node's code seems to be doing this and not & 0x7F..
  1537. byteArray.push(str.charCodeAt(i) & 0xFF);
  1538. }
  1539. return byteArray;
  1540. }
  1541. function utf16leToBytes(str, units) {
  1542. var c, hi, lo;
  1543. var byteArray = [];
  1544. for (var i = 0; i < str.length; ++i) {
  1545. if ((units -= 2) < 0) break;
  1546. c = str.charCodeAt(i);
  1547. hi = c >> 8;
  1548. lo = c % 256;
  1549. byteArray.push(lo);
  1550. byteArray.push(hi);
  1551. }
  1552. return byteArray;
  1553. }
  1554. function base64ToBytes(str) {
  1555. return base64Js.toByteArray(base64clean(str));
  1556. }
  1557. function blitBuffer(src, dst, offset, length) {
  1558. for (var i = 0; i < length; ++i) {
  1559. if (i + offset >= dst.length || i >= src.length) break;
  1560. dst[i + offset] = src[i];
  1561. }
  1562. return i;
  1563. } // ArrayBuffers from another context (i.e. an iframe) do not pass the `instanceof` check
  1564. // but they should be treated as valid. See: https://github.com/feross/buffer/issues/166
  1565. function isArrayBuffer(obj) {
  1566. return obj instanceof ArrayBuffer || obj != null && obj.constructor != null && obj.constructor.name === 'ArrayBuffer' && typeof obj.byteLength === 'number';
  1567. }
  1568. function numberIsNaN(obj) {
  1569. return obj !== obj; // eslint-disable-line no-self-compare
  1570. }
  1571. });
  1572. var buffer_1 = buffer.Buffer;
  1573. var buffer_2 = buffer.SlowBuffer;
  1574. var buffer_3 = buffer.INSPECT_MAX_BYTES;
  1575. var buffer_4 = buffer.kMaxLength;
  1576. var map = createCommonjsModule(function (module) {
  1577. if (typeof commonjsGlobal.Map !== 'undefined') {
  1578. module.exports = commonjsGlobal.Map;
  1579. module.exports.Map = commonjsGlobal.Map;
  1580. } else {
  1581. // We will return a polyfill
  1582. var Map = function Map(array) {
  1583. this._keys = [];
  1584. this._values = {};
  1585. for (var i = 0; i < array.length; i++) {
  1586. if (array[i] == null) continue; // skip null and undefined
  1587. var entry = array[i];
  1588. var key = entry[0];
  1589. var value = entry[1]; // Add the key to the list of keys in order
  1590. this._keys.push(key); // Add the key and value to the values dictionary with a point
  1591. // to the location in the ordered keys list
  1592. this._values[key] = {
  1593. v: value,
  1594. i: this._keys.length - 1
  1595. };
  1596. }
  1597. };
  1598. Map.prototype.clear = function () {
  1599. this._keys = [];
  1600. this._values = {};
  1601. };
  1602. Map.prototype.delete = function (key) {
  1603. var value = this._values[key];
  1604. if (value == null) return false; // Delete entry
  1605. delete this._values[key]; // Remove the key from the ordered keys list
  1606. this._keys.splice(value.i, 1);
  1607. return true;
  1608. };
  1609. Map.prototype.entries = function () {
  1610. var self = this;
  1611. var index = 0;
  1612. return {
  1613. next: function next() {
  1614. var key = self._keys[index++];
  1615. return {
  1616. value: key !== undefined ? [key, self._values[key].v] : undefined,
  1617. done: key !== undefined ? false : true
  1618. };
  1619. }
  1620. };
  1621. };
  1622. Map.prototype.forEach = function (callback, self) {
  1623. self = self || this;
  1624. for (var i = 0; i < this._keys.length; i++) {
  1625. var key = this._keys[i]; // Call the forEach callback
  1626. callback.call(self, this._values[key].v, key, self);
  1627. }
  1628. };
  1629. Map.prototype.get = function (key) {
  1630. return this._values[key] ? this._values[key].v : undefined;
  1631. };
  1632. Map.prototype.has = function (key) {
  1633. return this._values[key] != null;
  1634. };
  1635. Map.prototype.keys = function () {
  1636. var self = this;
  1637. var index = 0;
  1638. return {
  1639. next: function next() {
  1640. var key = self._keys[index++];
  1641. return {
  1642. value: key !== undefined ? key : undefined,
  1643. done: key !== undefined ? false : true
  1644. };
  1645. }
  1646. };
  1647. };
  1648. Map.prototype.set = function (key, value) {
  1649. if (this._values[key]) {
  1650. this._values[key].v = value;
  1651. return this;
  1652. } // Add the key to the list of keys in order
  1653. this._keys.push(key); // Add the key and value to the values dictionary with a point
  1654. // to the location in the ordered keys list
  1655. this._values[key] = {
  1656. v: value,
  1657. i: this._keys.length - 1
  1658. };
  1659. return this;
  1660. };
  1661. Map.prototype.values = function () {
  1662. var self = this;
  1663. var index = 0;
  1664. return {
  1665. next: function next() {
  1666. var key = self._keys[index++];
  1667. return {
  1668. value: key !== undefined ? self._values[key].v : undefined,
  1669. done: key !== undefined ? false : true
  1670. };
  1671. }
  1672. };
  1673. }; // Last ismaster
  1674. Object.defineProperty(Map.prototype, 'size', {
  1675. enumerable: true,
  1676. get: function get() {
  1677. return this._keys.length;
  1678. }
  1679. });
  1680. module.exports = Map;
  1681. }
  1682. });
  1683. var map_1 = map.Map;
  1684. var long_1 = Long;
  1685. /**
  1686. * wasm optimizations, to do native i64 multiplication and divide
  1687. */
  1688. var wasm = null;
  1689. try {
  1690. wasm = 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;
  1691. } catch (e) {} // no wasm support :(
  1692. /**
  1693. * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
  1694. * See the from* functions below for more convenient ways of constructing Longs.
  1695. * @exports Long
  1696. * @class A Long class for representing a 64 bit two's-complement integer value.
  1697. * @param {number} low The low (signed) 32 bits of the long
  1698. * @param {number} high The high (signed) 32 bits of the long
  1699. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1700. * @constructor
  1701. */
  1702. function Long(low, high, unsigned) {
  1703. /**
  1704. * The low 32 bits as a signed value.
  1705. * @type {number}
  1706. */
  1707. this.low = low | 0;
  1708. /**
  1709. * The high 32 bits as a signed value.
  1710. * @type {number}
  1711. */
  1712. this.high = high | 0;
  1713. /**
  1714. * Whether unsigned or not.
  1715. * @type {boolean}
  1716. */
  1717. this.unsigned = !!unsigned;
  1718. } // The internal representation of a long is the two given signed, 32-bit values.
  1719. // We use 32-bit pieces because these are the size of integers on which
  1720. // Javascript performs bit-operations. For operations like addition and
  1721. // multiplication, we split each number into 16 bit pieces, which can easily be
  1722. // multiplied within Javascript's floating-point representation without overflow
  1723. // or change in sign.
  1724. //
  1725. // In the algorithms below, we frequently reduce the negative case to the
  1726. // positive case by negating the input(s) and then post-processing the result.
  1727. // Note that we must ALWAYS check specially whether those values are MIN_VALUE
  1728. // (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
  1729. // a positive number, it overflows back into a negative). Not handling this
  1730. // case would often result in infinite recursion.
  1731. //
  1732. // Common constant values ZERO, ONE, NEG_ONE, etc. are defined below the from*
  1733. // methods on which they depend.
  1734. /**
  1735. * An indicator used to reliably determine if an object is a Long or not.
  1736. * @type {boolean}
  1737. * @const
  1738. * @private
  1739. */
  1740. Long.prototype.__isLong__;
  1741. Object.defineProperty(Long.prototype, "__isLong__", {
  1742. value: true
  1743. });
  1744. /**
  1745. * @function
  1746. * @param {*} obj Object
  1747. * @returns {boolean}
  1748. * @inner
  1749. */
  1750. function isLong(obj) {
  1751. return (obj && obj["__isLong__"]) === true;
  1752. }
  1753. /**
  1754. * Tests if the specified object is a Long.
  1755. * @function
  1756. * @param {*} obj Object
  1757. * @returns {boolean}
  1758. */
  1759. Long.isLong = isLong;
  1760. /**
  1761. * A cache of the Long representations of small integer values.
  1762. * @type {!Object}
  1763. * @inner
  1764. */
  1765. var INT_CACHE = {};
  1766. /**
  1767. * A cache of the Long representations of small unsigned integer values.
  1768. * @type {!Object}
  1769. * @inner
  1770. */
  1771. var UINT_CACHE = {};
  1772. /**
  1773. * @param {number} value
  1774. * @param {boolean=} unsigned
  1775. * @returns {!Long}
  1776. * @inner
  1777. */
  1778. function fromInt(value, unsigned) {
  1779. var obj, cachedObj, cache;
  1780. if (unsigned) {
  1781. value >>>= 0;
  1782. if (cache = 0 <= value && value < 256) {
  1783. cachedObj = UINT_CACHE[value];
  1784. if (cachedObj) return cachedObj;
  1785. }
  1786. obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
  1787. if (cache) UINT_CACHE[value] = obj;
  1788. return obj;
  1789. } else {
  1790. value |= 0;
  1791. if (cache = -128 <= value && value < 128) {
  1792. cachedObj = INT_CACHE[value];
  1793. if (cachedObj) return cachedObj;
  1794. }
  1795. obj = fromBits(value, value < 0 ? -1 : 0, false);
  1796. if (cache) INT_CACHE[value] = obj;
  1797. return obj;
  1798. }
  1799. }
  1800. /**
  1801. * Returns a Long representing the given 32 bit integer value.
  1802. * @function
  1803. * @param {number} value The 32 bit integer in question
  1804. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1805. * @returns {!Long} The corresponding Long value
  1806. */
  1807. Long.fromInt = fromInt;
  1808. /**
  1809. * @param {number} value
  1810. * @param {boolean=} unsigned
  1811. * @returns {!Long}
  1812. * @inner
  1813. */
  1814. function fromNumber(value, unsigned) {
  1815. if (isNaN(value)) return unsigned ? UZERO : ZERO;
  1816. if (unsigned) {
  1817. if (value < 0) return UZERO;
  1818. if (value >= TWO_PWR_64_DBL) return MAX_UNSIGNED_VALUE;
  1819. } else {
  1820. if (value <= -TWO_PWR_63_DBL) return MIN_VALUE;
  1821. if (value + 1 >= TWO_PWR_63_DBL) return MAX_VALUE;
  1822. }
  1823. if (value < 0) return fromNumber(-value, unsigned).neg();
  1824. return fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
  1825. }
  1826. /**
  1827. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  1828. * @function
  1829. * @param {number} value The number in question
  1830. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1831. * @returns {!Long} The corresponding Long value
  1832. */
  1833. Long.fromNumber = fromNumber;
  1834. /**
  1835. * @param {number} lowBits
  1836. * @param {number} highBits
  1837. * @param {boolean=} unsigned
  1838. * @returns {!Long}
  1839. * @inner
  1840. */
  1841. function fromBits(lowBits, highBits, unsigned) {
  1842. return new Long(lowBits, highBits, unsigned);
  1843. }
  1844. /**
  1845. * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits. Each is
  1846. * assumed to use 32 bits.
  1847. * @function
  1848. * @param {number} lowBits The low 32 bits
  1849. * @param {number} highBits The high 32 bits
  1850. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1851. * @returns {!Long} The corresponding Long value
  1852. */
  1853. Long.fromBits = fromBits;
  1854. /**
  1855. * @function
  1856. * @param {number} base
  1857. * @param {number} exponent
  1858. * @returns {number}
  1859. * @inner
  1860. */
  1861. var pow_dbl = Math.pow; // Used 4 times (4*8 to 15+4)
  1862. /**
  1863. * @param {string} str
  1864. * @param {(boolean|number)=} unsigned
  1865. * @param {number=} radix
  1866. * @returns {!Long}
  1867. * @inner
  1868. */
  1869. function fromString(str, unsigned, radix) {
  1870. if (str.length === 0) throw Error('empty string');
  1871. if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity") return ZERO;
  1872. if (typeof unsigned === 'number') {
  1873. // For goog.math.long compatibility
  1874. radix = unsigned, unsigned = false;
  1875. } else {
  1876. unsigned = !!unsigned;
  1877. }
  1878. radix = radix || 10;
  1879. if (radix < 2 || 36 < radix) throw RangeError('radix');
  1880. var p;
  1881. if ((p = str.indexOf('-')) > 0) throw Error('interior hyphen');else if (p === 0) {
  1882. return fromString(str.substring(1), unsigned, radix).neg();
  1883. } // Do several (8) digits each time through the loop, so as to
  1884. // minimize the calls to the very expensive emulated div.
  1885. var radixToPower = fromNumber(pow_dbl(radix, 8));
  1886. var result = ZERO;
  1887. for (var i = 0; i < str.length; i += 8) {
  1888. var size = Math.min(8, str.length - i),
  1889. value = parseInt(str.substring(i, i + size), radix);
  1890. if (size < 8) {
  1891. var power = fromNumber(pow_dbl(radix, size));
  1892. result = result.mul(power).add(fromNumber(value));
  1893. } else {
  1894. result = result.mul(radixToPower);
  1895. result = result.add(fromNumber(value));
  1896. }
  1897. }
  1898. result.unsigned = unsigned;
  1899. return result;
  1900. }
  1901. /**
  1902. * Returns a Long representation of the given string, written using the specified radix.
  1903. * @function
  1904. * @param {string} str The textual representation of the Long
  1905. * @param {(boolean|number)=} unsigned Whether unsigned or not, defaults to signed
  1906. * @param {number=} radix The radix in which the text is written (2-36), defaults to 10
  1907. * @returns {!Long} The corresponding Long value
  1908. */
  1909. Long.fromString = fromString;
  1910. /**
  1911. * @function
  1912. * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val
  1913. * @param {boolean=} unsigned
  1914. * @returns {!Long}
  1915. * @inner
  1916. */
  1917. function fromValue(val, unsigned) {
  1918. if (typeof val === 'number') return fromNumber(val, unsigned);
  1919. if (typeof val === 'string') return fromString(val, unsigned); // Throws for non-objects, converts non-instanceof Long:
  1920. return fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
  1921. }
  1922. /**
  1923. * Converts the specified value to a Long using the appropriate from* function for its type.
  1924. * @function
  1925. * @param {!Long|number|string|!{low: number, high: number, unsigned: boolean}} val Value
  1926. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  1927. * @returns {!Long}
  1928. */
  1929. Long.fromValue = fromValue; // NOTE: the compiler should inline these constant values below and then remove these variables, so there should be
  1930. // no runtime penalty for these.
  1931. /**
  1932. * @type {number}
  1933. * @const
  1934. * @inner
  1935. */
  1936. var TWO_PWR_16_DBL = 1 << 16;
  1937. /**
  1938. * @type {number}
  1939. * @const
  1940. * @inner
  1941. */
  1942. var TWO_PWR_24_DBL = 1 << 24;
  1943. /**
  1944. * @type {number}
  1945. * @const
  1946. * @inner
  1947. */
  1948. var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
  1949. /**
  1950. * @type {number}
  1951. * @const
  1952. * @inner
  1953. */
  1954. var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
  1955. /**
  1956. * @type {number}
  1957. * @const
  1958. * @inner
  1959. */
  1960. var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
  1961. /**
  1962. * @type {!Long}
  1963. * @const
  1964. * @inner
  1965. */
  1966. var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
  1967. /**
  1968. * @type {!Long}
  1969. * @inner
  1970. */
  1971. var ZERO = fromInt(0);
  1972. /**
  1973. * Signed zero.
  1974. * @type {!Long}
  1975. */
  1976. Long.ZERO = ZERO;
  1977. /**
  1978. * @type {!Long}
  1979. * @inner
  1980. */
  1981. var UZERO = fromInt(0, true);
  1982. /**
  1983. * Unsigned zero.
  1984. * @type {!Long}
  1985. */
  1986. Long.UZERO = UZERO;
  1987. /**
  1988. * @type {!Long}
  1989. * @inner
  1990. */
  1991. var ONE = fromInt(1);
  1992. /**
  1993. * Signed one.
  1994. * @type {!Long}
  1995. */
  1996. Long.ONE = ONE;
  1997. /**
  1998. * @type {!Long}
  1999. * @inner
  2000. */
  2001. var UONE = fromInt(1, true);
  2002. /**
  2003. * Unsigned one.
  2004. * @type {!Long}
  2005. */
  2006. Long.UONE = UONE;
  2007. /**
  2008. * @type {!Long}
  2009. * @inner
  2010. */
  2011. var NEG_ONE = fromInt(-1);
  2012. /**
  2013. * Signed negative one.
  2014. * @type {!Long}
  2015. */
  2016. Long.NEG_ONE = NEG_ONE;
  2017. /**
  2018. * @type {!Long}
  2019. * @inner
  2020. */
  2021. var MAX_VALUE = fromBits(0xFFFFFFFF | 0, 0x7FFFFFFF | 0, false);
  2022. /**
  2023. * Maximum signed value.
  2024. * @type {!Long}
  2025. */
  2026. Long.MAX_VALUE = MAX_VALUE;
  2027. /**
  2028. * @type {!Long}
  2029. * @inner
  2030. */
  2031. var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF | 0, 0xFFFFFFFF | 0, true);
  2032. /**
  2033. * Maximum unsigned value.
  2034. * @type {!Long}
  2035. */
  2036. Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
  2037. /**
  2038. * @type {!Long}
  2039. * @inner
  2040. */
  2041. var MIN_VALUE = fromBits(0, 0x80000000 | 0, false);
  2042. /**
  2043. * Minimum signed value.
  2044. * @type {!Long}
  2045. */
  2046. Long.MIN_VALUE = MIN_VALUE;
  2047. /**
  2048. * @alias Long.prototype
  2049. * @inner
  2050. */
  2051. var LongPrototype = Long.prototype;
  2052. /**
  2053. * Converts the Long to a 32 bit integer, assuming it is a 32 bit integer.
  2054. * @returns {number}
  2055. */
  2056. LongPrototype.toInt = function toInt() {
  2057. return this.unsigned ? this.low >>> 0 : this.low;
  2058. };
  2059. /**
  2060. * Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa).
  2061. * @returns {number}
  2062. */
  2063. LongPrototype.toNumber = function toNumber() {
  2064. if (this.unsigned) return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
  2065. return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
  2066. };
  2067. /**
  2068. * Converts the Long to a string written in the specified radix.
  2069. * @param {number=} radix Radix (2-36), defaults to 10
  2070. * @returns {string}
  2071. * @override
  2072. * @throws {RangeError} If `radix` is out of range
  2073. */
  2074. LongPrototype.toString = function toString(radix) {
  2075. radix = radix || 10;
  2076. if (radix < 2 || 36 < radix) throw RangeError('radix');
  2077. if (this.isZero()) return '0';
  2078. if (this.isNegative()) {
  2079. // Unsigned Longs are never negative
  2080. if (this.eq(MIN_VALUE)) {
  2081. // We need to change the Long value before it can be negated, so we remove
  2082. // the bottom-most digit in this base and then recurse to do the rest.
  2083. var radixLong = fromNumber(radix),
  2084. div = this.div(radixLong),
  2085. rem1 = div.mul(radixLong).sub(this);
  2086. return div.toString(radix) + rem1.toInt().toString(radix);
  2087. } else return '-' + this.neg().toString(radix);
  2088. } // Do several (6) digits each time through the loop, so as to
  2089. // minimize the calls to the very expensive emulated div.
  2090. var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
  2091. rem = this;
  2092. var result = '';
  2093. while (true) {
  2094. var remDiv = rem.div(radixToPower),
  2095. intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
  2096. digits = intval.toString(radix);
  2097. rem = remDiv;
  2098. if (rem.isZero()) return digits + result;else {
  2099. while (digits.length < 6) {
  2100. digits = '0' + digits;
  2101. }
  2102. result = '' + digits + result;
  2103. }
  2104. }
  2105. };
  2106. /**
  2107. * Gets the high 32 bits as a signed integer.
  2108. * @returns {number} Signed high bits
  2109. */
  2110. LongPrototype.getHighBits = function getHighBits() {
  2111. return this.high;
  2112. };
  2113. /**
  2114. * Gets the high 32 bits as an unsigned integer.
  2115. * @returns {number} Unsigned high bits
  2116. */
  2117. LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
  2118. return this.high >>> 0;
  2119. };
  2120. /**
  2121. * Gets the low 32 bits as a signed integer.
  2122. * @returns {number} Signed low bits
  2123. */
  2124. LongPrototype.getLowBits = function getLowBits() {
  2125. return this.low;
  2126. };
  2127. /**
  2128. * Gets the low 32 bits as an unsigned integer.
  2129. * @returns {number} Unsigned low bits
  2130. */
  2131. LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
  2132. return this.low >>> 0;
  2133. };
  2134. /**
  2135. * Gets the number of bits needed to represent the absolute value of this Long.
  2136. * @returns {number}
  2137. */
  2138. LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
  2139. if (this.isNegative()) // Unsigned Longs are never negative
  2140. return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
  2141. var val = this.high != 0 ? this.high : this.low;
  2142. for (var bit = 31; bit > 0; bit--) {
  2143. if ((val & 1 << bit) != 0) break;
  2144. }
  2145. return this.high != 0 ? bit + 33 : bit + 1;
  2146. };
  2147. /**
  2148. * Tests if this Long's value equals zero.
  2149. * @returns {boolean}
  2150. */
  2151. LongPrototype.isZero = function isZero() {
  2152. return this.high === 0 && this.low === 0;
  2153. };
  2154. /**
  2155. * Tests if this Long's value equals zero. This is an alias of {@link Long#isZero}.
  2156. * @returns {boolean}
  2157. */
  2158. LongPrototype.eqz = LongPrototype.isZero;
  2159. /**
  2160. * Tests if this Long's value is negative.
  2161. * @returns {boolean}
  2162. */
  2163. LongPrototype.isNegative = function isNegative() {
  2164. return !this.unsigned && this.high < 0;
  2165. };
  2166. /**
  2167. * Tests if this Long's value is positive.
  2168. * @returns {boolean}
  2169. */
  2170. LongPrototype.isPositive = function isPositive() {
  2171. return this.unsigned || this.high >= 0;
  2172. };
  2173. /**
  2174. * Tests if this Long's value is odd.
  2175. * @returns {boolean}
  2176. */
  2177. LongPrototype.isOdd = function isOdd() {
  2178. return (this.low & 1) === 1;
  2179. };
  2180. /**
  2181. * Tests if this Long's value is even.
  2182. * @returns {boolean}
  2183. */
  2184. LongPrototype.isEven = function isEven() {
  2185. return (this.low & 1) === 0;
  2186. };
  2187. /**
  2188. * Tests if this Long's value equals the specified's.
  2189. * @param {!Long|number|string} other Other value
  2190. * @returns {boolean}
  2191. */
  2192. LongPrototype.equals = function equals(other) {
  2193. if (!isLong(other)) other = fromValue(other);
  2194. if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1) return false;
  2195. return this.high === other.high && this.low === other.low;
  2196. };
  2197. /**
  2198. * Tests if this Long's value equals the specified's. This is an alias of {@link Long#equals}.
  2199. * @function
  2200. * @param {!Long|number|string} other Other value
  2201. * @returns {boolean}
  2202. */
  2203. LongPrototype.eq = LongPrototype.equals;
  2204. /**
  2205. * Tests if this Long's value differs from the specified's.
  2206. * @param {!Long|number|string} other Other value
  2207. * @returns {boolean}
  2208. */
  2209. LongPrototype.notEquals = function notEquals(other) {
  2210. return !this.eq(
  2211. /* validates */
  2212. other);
  2213. };
  2214. /**
  2215. * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
  2216. * @function
  2217. * @param {!Long|number|string} other Other value
  2218. * @returns {boolean}
  2219. */
  2220. LongPrototype.neq = LongPrototype.notEquals;
  2221. /**
  2222. * Tests if this Long's value differs from the specified's. This is an alias of {@link Long#notEquals}.
  2223. * @function
  2224. * @param {!Long|number|string} other Other value
  2225. * @returns {boolean}
  2226. */
  2227. LongPrototype.ne = LongPrototype.notEquals;
  2228. /**
  2229. * Tests if this Long's value is less than the specified's.
  2230. * @param {!Long|number|string} other Other value
  2231. * @returns {boolean}
  2232. */
  2233. LongPrototype.lessThan = function lessThan(other) {
  2234. return this.comp(
  2235. /* validates */
  2236. other) < 0;
  2237. };
  2238. /**
  2239. * Tests if this Long's value is less than the specified's. This is an alias of {@link Long#lessThan}.
  2240. * @function
  2241. * @param {!Long|number|string} other Other value
  2242. * @returns {boolean}
  2243. */
  2244. LongPrototype.lt = LongPrototype.lessThan;
  2245. /**
  2246. * Tests if this Long's value is less than or equal the specified's.
  2247. * @param {!Long|number|string} other Other value
  2248. * @returns {boolean}
  2249. */
  2250. LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
  2251. return this.comp(
  2252. /* validates */
  2253. other) <= 0;
  2254. };
  2255. /**
  2256. * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
  2257. * @function
  2258. * @param {!Long|number|string} other Other value
  2259. * @returns {boolean}
  2260. */
  2261. LongPrototype.lte = LongPrototype.lessThanOrEqual;
  2262. /**
  2263. * Tests if this Long's value is less than or equal the specified's. This is an alias of {@link Long#lessThanOrEqual}.
  2264. * @function
  2265. * @param {!Long|number|string} other Other value
  2266. * @returns {boolean}
  2267. */
  2268. LongPrototype.le = LongPrototype.lessThanOrEqual;
  2269. /**
  2270. * Tests if this Long's value is greater than the specified's.
  2271. * @param {!Long|number|string} other Other value
  2272. * @returns {boolean}
  2273. */
  2274. LongPrototype.greaterThan = function greaterThan(other) {
  2275. return this.comp(
  2276. /* validates */
  2277. other) > 0;
  2278. };
  2279. /**
  2280. * Tests if this Long's value is greater than the specified's. This is an alias of {@link Long#greaterThan}.
  2281. * @function
  2282. * @param {!Long|number|string} other Other value
  2283. * @returns {boolean}
  2284. */
  2285. LongPrototype.gt = LongPrototype.greaterThan;
  2286. /**
  2287. * Tests if this Long's value is greater than or equal the specified's.
  2288. * @param {!Long|number|string} other Other value
  2289. * @returns {boolean}
  2290. */
  2291. LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
  2292. return this.comp(
  2293. /* validates */
  2294. other) >= 0;
  2295. };
  2296. /**
  2297. * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
  2298. * @function
  2299. * @param {!Long|number|string} other Other value
  2300. * @returns {boolean}
  2301. */
  2302. LongPrototype.gte = LongPrototype.greaterThanOrEqual;
  2303. /**
  2304. * Tests if this Long's value is greater than or equal the specified's. This is an alias of {@link Long#greaterThanOrEqual}.
  2305. * @function
  2306. * @param {!Long|number|string} other Other value
  2307. * @returns {boolean}
  2308. */
  2309. LongPrototype.ge = LongPrototype.greaterThanOrEqual;
  2310. /**
  2311. * Compares this Long's value with the specified's.
  2312. * @param {!Long|number|string} other Other value
  2313. * @returns {number} 0 if they are the same, 1 if the this is greater and -1
  2314. * if the given one is greater
  2315. */
  2316. LongPrototype.compare = function compare(other) {
  2317. if (!isLong(other)) other = fromValue(other);
  2318. if (this.eq(other)) return 0;
  2319. var thisNeg = this.isNegative(),
  2320. otherNeg = other.isNegative();
  2321. if (thisNeg && !otherNeg) return -1;
  2322. if (!thisNeg && otherNeg) return 1; // At this point the sign bits are the same
  2323. if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1; // Both are positive if at least one is unsigned
  2324. return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
  2325. };
  2326. /**
  2327. * Compares this Long's value with the specified's. This is an alias of {@link Long#compare}.
  2328. * @function
  2329. * @param {!Long|number|string} other Other value
  2330. * @returns {number} 0 if they are the same, 1 if the this is greater and -1
  2331. * if the given one is greater
  2332. */
  2333. LongPrototype.comp = LongPrototype.compare;
  2334. /**
  2335. * Negates this Long's value.
  2336. * @returns {!Long} Negated Long
  2337. */
  2338. LongPrototype.negate = function negate() {
  2339. if (!this.unsigned && this.eq(MIN_VALUE)) return MIN_VALUE;
  2340. return this.not().add(ONE);
  2341. };
  2342. /**
  2343. * Negates this Long's value. This is an alias of {@link Long#negate}.
  2344. * @function
  2345. * @returns {!Long} Negated Long
  2346. */
  2347. LongPrototype.neg = LongPrototype.negate;
  2348. /**
  2349. * Returns the sum of this and the specified Long.
  2350. * @param {!Long|number|string} addend Addend
  2351. * @returns {!Long} Sum
  2352. */
  2353. LongPrototype.add = function add(addend) {
  2354. if (!isLong(addend)) addend = fromValue(addend); // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
  2355. var a48 = this.high >>> 16;
  2356. var a32 = this.high & 0xFFFF;
  2357. var a16 = this.low >>> 16;
  2358. var a00 = this.low & 0xFFFF;
  2359. var b48 = addend.high >>> 16;
  2360. var b32 = addend.high & 0xFFFF;
  2361. var b16 = addend.low >>> 16;
  2362. var b00 = addend.low & 0xFFFF;
  2363. var c48 = 0,
  2364. c32 = 0,
  2365. c16 = 0,
  2366. c00 = 0;
  2367. c00 += a00 + b00;
  2368. c16 += c00 >>> 16;
  2369. c00 &= 0xFFFF;
  2370. c16 += a16 + b16;
  2371. c32 += c16 >>> 16;
  2372. c16 &= 0xFFFF;
  2373. c32 += a32 + b32;
  2374. c48 += c32 >>> 16;
  2375. c32 &= 0xFFFF;
  2376. c48 += a48 + b48;
  2377. c48 &= 0xFFFF;
  2378. return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  2379. };
  2380. /**
  2381. * Returns the difference of this and the specified Long.
  2382. * @param {!Long|number|string} subtrahend Subtrahend
  2383. * @returns {!Long} Difference
  2384. */
  2385. LongPrototype.subtract = function subtract(subtrahend) {
  2386. if (!isLong(subtrahend)) subtrahend = fromValue(subtrahend);
  2387. return this.add(subtrahend.neg());
  2388. };
  2389. /**
  2390. * Returns the difference of this and the specified Long. This is an alias of {@link Long#subtract}.
  2391. * @function
  2392. * @param {!Long|number|string} subtrahend Subtrahend
  2393. * @returns {!Long} Difference
  2394. */
  2395. LongPrototype.sub = LongPrototype.subtract;
  2396. /**
  2397. * Returns the product of this and the specified Long.
  2398. * @param {!Long|number|string} multiplier Multiplier
  2399. * @returns {!Long} Product
  2400. */
  2401. LongPrototype.multiply = function multiply(multiplier) {
  2402. if (this.isZero()) return ZERO;
  2403. if (!isLong(multiplier)) multiplier = fromValue(multiplier); // use wasm support if present
  2404. if (wasm) {
  2405. var low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
  2406. return fromBits(low, wasm.get_high(), this.unsigned);
  2407. }
  2408. if (multiplier.isZero()) return ZERO;
  2409. if (this.eq(MIN_VALUE)) return multiplier.isOdd() ? MIN_VALUE : ZERO;
  2410. if (multiplier.eq(MIN_VALUE)) return this.isOdd() ? MIN_VALUE : ZERO;
  2411. if (this.isNegative()) {
  2412. if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());else return this.neg().mul(multiplier).neg();
  2413. } else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg(); // If both longs are small, use float multiplication
  2414. if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24)) return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
  2415. // We can skip products that would overflow.
  2416. var a48 = this.high >>> 16;
  2417. var a32 = this.high & 0xFFFF;
  2418. var a16 = this.low >>> 16;
  2419. var a00 = this.low & 0xFFFF;
  2420. var b48 = multiplier.high >>> 16;
  2421. var b32 = multiplier.high & 0xFFFF;
  2422. var b16 = multiplier.low >>> 16;
  2423. var b00 = multiplier.low & 0xFFFF;
  2424. var c48 = 0,
  2425. c32 = 0,
  2426. c16 = 0,
  2427. c00 = 0;
  2428. c00 += a00 * b00;
  2429. c16 += c00 >>> 16;
  2430. c00 &= 0xFFFF;
  2431. c16 += a16 * b00;
  2432. c32 += c16 >>> 16;
  2433. c16 &= 0xFFFF;
  2434. c16 += a00 * b16;
  2435. c32 += c16 >>> 16;
  2436. c16 &= 0xFFFF;
  2437. c32 += a32 * b00;
  2438. c48 += c32 >>> 16;
  2439. c32 &= 0xFFFF;
  2440. c32 += a16 * b16;
  2441. c48 += c32 >>> 16;
  2442. c32 &= 0xFFFF;
  2443. c32 += a00 * b32;
  2444. c48 += c32 >>> 16;
  2445. c32 &= 0xFFFF;
  2446. c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
  2447. c48 &= 0xFFFF;
  2448. return fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  2449. };
  2450. /**
  2451. * Returns the product of this and the specified Long. This is an alias of {@link Long#multiply}.
  2452. * @function
  2453. * @param {!Long|number|string} multiplier Multiplier
  2454. * @returns {!Long} Product
  2455. */
  2456. LongPrototype.mul = LongPrototype.multiply;
  2457. /**
  2458. * Returns this Long divided by the specified. The result is signed if this Long is signed or
  2459. * unsigned if this Long is unsigned.
  2460. * @param {!Long|number|string} divisor Divisor
  2461. * @returns {!Long} Quotient
  2462. */
  2463. LongPrototype.divide = function divide(divisor) {
  2464. if (!isLong(divisor)) divisor = fromValue(divisor);
  2465. if (divisor.isZero()) throw Error('division by zero'); // use wasm support if present
  2466. if (wasm) {
  2467. // guard against signed division overflow: the largest
  2468. // negative number / -1 would be 1 larger than the largest
  2469. // positive number, due to two's complement.
  2470. if (!this.unsigned && this.high === -0x80000000 && divisor.low === -1 && divisor.high === -1) {
  2471. // be consistent with non-wasm code path
  2472. return this;
  2473. }
  2474. var low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
  2475. return fromBits(low, wasm.get_high(), this.unsigned);
  2476. }
  2477. if (this.isZero()) return this.unsigned ? UZERO : ZERO;
  2478. var approx, rem, res;
  2479. if (!this.unsigned) {
  2480. // This section is only relevant for signed longs and is derived from the
  2481. // closure library as a whole.
  2482. if (this.eq(MIN_VALUE)) {
  2483. if (divisor.eq(ONE) || divisor.eq(NEG_ONE)) return MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
  2484. else if (divisor.eq(MIN_VALUE)) return ONE;else {
  2485. // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
  2486. var halfThis = this.shr(1);
  2487. approx = halfThis.div(divisor).shl(1);
  2488. if (approx.eq(ZERO)) {
  2489. return divisor.isNegative() ? ONE : NEG_ONE;
  2490. } else {
  2491. rem = this.sub(divisor.mul(approx));
  2492. res = approx.add(rem.div(divisor));
  2493. return res;
  2494. }
  2495. }
  2496. } else if (divisor.eq(MIN_VALUE)) return this.unsigned ? UZERO : ZERO;
  2497. if (this.isNegative()) {
  2498. if (divisor.isNegative()) return this.neg().div(divisor.neg());
  2499. return this.neg().div(divisor).neg();
  2500. } else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
  2501. res = ZERO;
  2502. } else {
  2503. // The algorithm below has not been made for unsigned longs. It's therefore
  2504. // required to take special care of the MSB prior to running it.
  2505. if (!divisor.unsigned) divisor = divisor.toUnsigned();
  2506. if (divisor.gt(this)) return UZERO;
  2507. if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
  2508. return UONE;
  2509. res = UZERO;
  2510. } // Repeat the following until the remainder is less than other: find a
  2511. // floating-point that approximates remainder / other *from below*, add this
  2512. // into the result, and subtract it from the remainder. It is critical that
  2513. // the approximate value is less than or equal to the real value so that the
  2514. // remainder never becomes negative.
  2515. rem = this;
  2516. while (rem.gte(divisor)) {
  2517. // Approximate the result of division. This may be a little greater or
  2518. // smaller than the actual value.
  2519. approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber())); // We will tweak the approximate result by changing it in the 48-th digit or
  2520. // the smallest non-fractional digit, whichever is larger.
  2521. var log2 = Math.ceil(Math.log(approx) / Math.LN2),
  2522. delta = log2 <= 48 ? 1 : pow_dbl(2, log2 - 48),
  2523. // Decrease the approximation until it is smaller than the remainder. Note
  2524. // that if it is too large, the product overflows and is negative.
  2525. approxRes = fromNumber(approx),
  2526. approxRem = approxRes.mul(divisor);
  2527. while (approxRem.isNegative() || approxRem.gt(rem)) {
  2528. approx -= delta;
  2529. approxRes = fromNumber(approx, this.unsigned);
  2530. approxRem = approxRes.mul(divisor);
  2531. } // We know the answer can't be zero... and actually, zero would cause
  2532. // infinite recursion since we would make no progress.
  2533. if (approxRes.isZero()) approxRes = ONE;
  2534. res = res.add(approxRes);
  2535. rem = rem.sub(approxRem);
  2536. }
  2537. return res;
  2538. };
  2539. /**
  2540. * Returns this Long divided by the specified. This is an alias of {@link Long#divide}.
  2541. * @function
  2542. * @param {!Long|number|string} divisor Divisor
  2543. * @returns {!Long} Quotient
  2544. */
  2545. LongPrototype.div = LongPrototype.divide;
  2546. /**
  2547. * Returns this Long modulo the specified.
  2548. * @param {!Long|number|string} divisor Divisor
  2549. * @returns {!Long} Remainder
  2550. */
  2551. LongPrototype.modulo = function modulo(divisor) {
  2552. if (!isLong(divisor)) divisor = fromValue(divisor); // use wasm support if present
  2553. if (wasm) {
  2554. var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
  2555. return fromBits(low, wasm.get_high(), this.unsigned);
  2556. }
  2557. return this.sub(this.div(divisor).mul(divisor));
  2558. };
  2559. /**
  2560. * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
  2561. * @function
  2562. * @param {!Long|number|string} divisor Divisor
  2563. * @returns {!Long} Remainder
  2564. */
  2565. LongPrototype.mod = LongPrototype.modulo;
  2566. /**
  2567. * Returns this Long modulo the specified. This is an alias of {@link Long#modulo}.
  2568. * @function
  2569. * @param {!Long|number|string} divisor Divisor
  2570. * @returns {!Long} Remainder
  2571. */
  2572. LongPrototype.rem = LongPrototype.modulo;
  2573. /**
  2574. * Returns the bitwise NOT of this Long.
  2575. * @returns {!Long}
  2576. */
  2577. LongPrototype.not = function not() {
  2578. return fromBits(~this.low, ~this.high, this.unsigned);
  2579. };
  2580. /**
  2581. * Returns the bitwise AND of this Long and the specified.
  2582. * @param {!Long|number|string} other Other Long
  2583. * @returns {!Long}
  2584. */
  2585. LongPrototype.and = function and(other) {
  2586. if (!isLong(other)) other = fromValue(other);
  2587. return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
  2588. };
  2589. /**
  2590. * Returns the bitwise OR of this Long and the specified.
  2591. * @param {!Long|number|string} other Other Long
  2592. * @returns {!Long}
  2593. */
  2594. LongPrototype.or = function or(other) {
  2595. if (!isLong(other)) other = fromValue(other);
  2596. return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
  2597. };
  2598. /**
  2599. * Returns the bitwise XOR of this Long and the given one.
  2600. * @param {!Long|number|string} other Other Long
  2601. * @returns {!Long}
  2602. */
  2603. LongPrototype.xor = function xor(other) {
  2604. if (!isLong(other)) other = fromValue(other);
  2605. return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
  2606. };
  2607. /**
  2608. * Returns this Long with bits shifted to the left by the given amount.
  2609. * @param {number|!Long} numBits Number of bits
  2610. * @returns {!Long} Shifted Long
  2611. */
  2612. LongPrototype.shiftLeft = function shiftLeft(numBits) {
  2613. if (isLong(numBits)) numBits = numBits.toInt();
  2614. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);else return fromBits(0, this.low << numBits - 32, this.unsigned);
  2615. };
  2616. /**
  2617. * Returns this Long with bits shifted to the left by the given amount. This is an alias of {@link Long#shiftLeft}.
  2618. * @function
  2619. * @param {number|!Long} numBits Number of bits
  2620. * @returns {!Long} Shifted Long
  2621. */
  2622. LongPrototype.shl = LongPrototype.shiftLeft;
  2623. /**
  2624. * Returns this Long with bits arithmetically shifted to the right by the given amount.
  2625. * @param {number|!Long} numBits Number of bits
  2626. * @returns {!Long} Shifted Long
  2627. */
  2628. LongPrototype.shiftRight = function shiftRight(numBits) {
  2629. if (isLong(numBits)) numBits = numBits.toInt();
  2630. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);else return fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
  2631. };
  2632. /**
  2633. * Returns this Long with bits arithmetically shifted to the right by the given amount. This is an alias of {@link Long#shiftRight}.
  2634. * @function
  2635. * @param {number|!Long} numBits Number of bits
  2636. * @returns {!Long} Shifted Long
  2637. */
  2638. LongPrototype.shr = LongPrototype.shiftRight;
  2639. /**
  2640. * Returns this Long with bits logically shifted to the right by the given amount.
  2641. * @param {number|!Long} numBits Number of bits
  2642. * @returns {!Long} Shifted Long
  2643. */
  2644. LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
  2645. if (isLong(numBits)) numBits = numBits.toInt();
  2646. numBits &= 63;
  2647. if (numBits === 0) return this;else {
  2648. var high = this.high;
  2649. if (numBits < 32) {
  2650. var low = this.low;
  2651. return fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
  2652. } else if (numBits === 32) return fromBits(high, 0, this.unsigned);else return fromBits(high >>> numBits - 32, 0, this.unsigned);
  2653. }
  2654. };
  2655. /**
  2656. * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
  2657. * @function
  2658. * @param {number|!Long} numBits Number of bits
  2659. * @returns {!Long} Shifted Long
  2660. */
  2661. LongPrototype.shru = LongPrototype.shiftRightUnsigned;
  2662. /**
  2663. * Returns this Long with bits logically shifted to the right by the given amount. This is an alias of {@link Long#shiftRightUnsigned}.
  2664. * @function
  2665. * @param {number|!Long} numBits Number of bits
  2666. * @returns {!Long} Shifted Long
  2667. */
  2668. LongPrototype.shr_u = LongPrototype.shiftRightUnsigned;
  2669. /**
  2670. * Converts this Long to signed.
  2671. * @returns {!Long} Signed long
  2672. */
  2673. LongPrototype.toSigned = function toSigned() {
  2674. if (!this.unsigned) return this;
  2675. return fromBits(this.low, this.high, false);
  2676. };
  2677. /**
  2678. * Converts this Long to unsigned.
  2679. * @returns {!Long} Unsigned long
  2680. */
  2681. LongPrototype.toUnsigned = function toUnsigned() {
  2682. if (this.unsigned) return this;
  2683. return fromBits(this.low, this.high, true);
  2684. };
  2685. /**
  2686. * Converts this Long to its byte representation.
  2687. * @param {boolean=} le Whether little or big endian, defaults to big endian
  2688. * @returns {!Array.<number>} Byte representation
  2689. */
  2690. LongPrototype.toBytes = function toBytes(le) {
  2691. return le ? this.toBytesLE() : this.toBytesBE();
  2692. };
  2693. /**
  2694. * Converts this Long to its little endian byte representation.
  2695. * @returns {!Array.<number>} Little endian byte representation
  2696. */
  2697. LongPrototype.toBytesLE = function toBytesLE() {
  2698. var hi = this.high,
  2699. lo = this.low;
  2700. return [lo & 0xff, lo >>> 8 & 0xff, lo >>> 16 & 0xff, lo >>> 24, hi & 0xff, hi >>> 8 & 0xff, hi >>> 16 & 0xff, hi >>> 24];
  2701. };
  2702. /**
  2703. * Converts this Long to its big endian byte representation.
  2704. * @returns {!Array.<number>} Big endian byte representation
  2705. */
  2706. LongPrototype.toBytesBE = function toBytesBE() {
  2707. var hi = this.high,
  2708. lo = this.low;
  2709. return [hi >>> 24, hi >>> 16 & 0xff, hi >>> 8 & 0xff, hi & 0xff, lo >>> 24, lo >>> 16 & 0xff, lo >>> 8 & 0xff, lo & 0xff];
  2710. };
  2711. /**
  2712. * Creates a Long from its byte representation.
  2713. * @param {!Array.<number>} bytes Byte representation
  2714. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  2715. * @param {boolean=} le Whether little or big endian, defaults to big endian
  2716. * @returns {Long} The corresponding Long value
  2717. */
  2718. Long.fromBytes = function fromBytes(bytes, unsigned, le) {
  2719. return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
  2720. };
  2721. /**
  2722. * Creates a Long from its little endian byte representation.
  2723. * @param {!Array.<number>} bytes Little endian byte representation
  2724. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  2725. * @returns {Long} The corresponding Long value
  2726. */
  2727. Long.fromBytesLE = function fromBytesLE(bytes, unsigned) {
  2728. return new Long(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24, bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24, unsigned);
  2729. };
  2730. /**
  2731. * Creates a Long from its big endian byte representation.
  2732. * @param {!Array.<number>} bytes Big endian byte representation
  2733. * @param {boolean=} unsigned Whether unsigned or not, defaults to signed
  2734. * @returns {Long} The corresponding Long value
  2735. */
  2736. Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
  2737. return new Long(bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7], bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], unsigned);
  2738. };
  2739. /**
  2740. * @ignore
  2741. */
  2742. long_1.prototype.toExtendedJSON = function (options) {
  2743. if (options && options.relaxed) return this.toNumber();
  2744. return {
  2745. $numberLong: this.toString()
  2746. };
  2747. };
  2748. /**
  2749. * @ignore
  2750. */
  2751. long_1.fromExtendedJSON = function (doc, options) {
  2752. var result = long_1.fromString(doc.$numberLong);
  2753. return options && options.relaxed ? result.toNumber() : result;
  2754. };
  2755. Object.defineProperty(long_1.prototype, '_bsontype', {
  2756. value: 'Long'
  2757. });
  2758. var long_1$1 = long_1;
  2759. function _typeof(obj) {
  2760. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  2761. _typeof = function (obj) {
  2762. return typeof obj;
  2763. };
  2764. } else {
  2765. _typeof = function (obj) {
  2766. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  2767. };
  2768. }
  2769. return _typeof(obj);
  2770. }
  2771. function _classCallCheck(instance, Constructor) {
  2772. if (!(instance instanceof Constructor)) {
  2773. throw new TypeError("Cannot call a class as a function");
  2774. }
  2775. }
  2776. function _defineProperties(target, props) {
  2777. for (var i = 0; i < props.length; i++) {
  2778. var descriptor = props[i];
  2779. descriptor.enumerable = descriptor.enumerable || false;
  2780. descriptor.configurable = true;
  2781. if ("value" in descriptor) descriptor.writable = true;
  2782. Object.defineProperty(target, descriptor.key, descriptor);
  2783. }
  2784. }
  2785. function _createClass(Constructor, protoProps, staticProps) {
  2786. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  2787. if (staticProps) _defineProperties(Constructor, staticProps);
  2788. return Constructor;
  2789. }
  2790. function _inherits(subClass, superClass) {
  2791. if (typeof superClass !== "function" && superClass !== null) {
  2792. throw new TypeError("Super expression must either be null or a function");
  2793. }
  2794. subClass.prototype = Object.create(superClass && superClass.prototype, {
  2795. constructor: {
  2796. value: subClass,
  2797. writable: true,
  2798. configurable: true
  2799. }
  2800. });
  2801. if (superClass) _setPrototypeOf(subClass, superClass);
  2802. }
  2803. function _getPrototypeOf(o) {
  2804. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  2805. return o.__proto__ || Object.getPrototypeOf(o);
  2806. };
  2807. return _getPrototypeOf(o);
  2808. }
  2809. function _setPrototypeOf(o, p) {
  2810. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  2811. o.__proto__ = p;
  2812. return o;
  2813. };
  2814. return _setPrototypeOf(o, p);
  2815. }
  2816. function _assertThisInitialized(self) {
  2817. if (self === void 0) {
  2818. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  2819. }
  2820. return self;
  2821. }
  2822. function _possibleConstructorReturn(self, call) {
  2823. if (call && (typeof call === "object" || typeof call === "function")) {
  2824. return call;
  2825. }
  2826. return _assertThisInitialized(self);
  2827. }
  2828. var Double =
  2829. /*#__PURE__*/
  2830. function () {
  2831. /**
  2832. * Create a Double type
  2833. *
  2834. * @param {number} value the number we want to represent as a double.
  2835. * @return {Double}
  2836. */
  2837. function Double(value) {
  2838. _classCallCheck(this, Double);
  2839. this.value = value;
  2840. }
  2841. /**
  2842. * Access the number value.
  2843. *
  2844. * @method
  2845. * @return {number} returns the wrapped double number.
  2846. */
  2847. _createClass(Double, [{
  2848. key: "valueOf",
  2849. value: function valueOf() {
  2850. return this.value;
  2851. }
  2852. /**
  2853. * @ignore
  2854. */
  2855. }, {
  2856. key: "toJSON",
  2857. value: function toJSON() {
  2858. return this.value;
  2859. }
  2860. /**
  2861. * @ignore
  2862. */
  2863. }, {
  2864. key: "toExtendedJSON",
  2865. value: function toExtendedJSON(options) {
  2866. if (options && options.relaxed && isFinite(this.value)) return this.value;
  2867. return {
  2868. $numberDouble: this.value.toString()
  2869. };
  2870. }
  2871. /**
  2872. * @ignore
  2873. */
  2874. }], [{
  2875. key: "fromExtendedJSON",
  2876. value: function fromExtendedJSON(doc, options) {
  2877. return options && options.relaxed ? parseFloat(doc.$numberDouble) : new Double(parseFloat(doc.$numberDouble));
  2878. }
  2879. }]);
  2880. return Double;
  2881. }();
  2882. Object.defineProperty(Double.prototype, '_bsontype', {
  2883. value: 'Double'
  2884. });
  2885. var double_1 = Double;
  2886. /**
  2887. * @class
  2888. * @param {number} low the low (signed) 32 bits of the Timestamp.
  2889. * @param {number} high the high (signed) 32 bits of the Timestamp.
  2890. * @return {Timestamp}
  2891. */
  2892. var Timestamp =
  2893. /*#__PURE__*/
  2894. function (_Long) {
  2895. _inherits(Timestamp, _Long);
  2896. function Timestamp(low, high) {
  2897. var _this;
  2898. _classCallCheck(this, Timestamp);
  2899. if (low instanceof long_1$1) {
  2900. _this = _possibleConstructorReturn(this, _getPrototypeOf(Timestamp).call(this, low.low, low.high));
  2901. } else {
  2902. _this = _possibleConstructorReturn(this, _getPrototypeOf(Timestamp).call(this, low, high));
  2903. }
  2904. return _possibleConstructorReturn(_this);
  2905. }
  2906. /**
  2907. * Return the JSON value.
  2908. *
  2909. * @method
  2910. * @return {String} the JSON representation.
  2911. */
  2912. _createClass(Timestamp, [{
  2913. key: "toJSON",
  2914. value: function toJSON() {
  2915. return {
  2916. $timestamp: this.toString()
  2917. };
  2918. }
  2919. /**
  2920. * Returns a Timestamp represented by the given (32-bit) integer value.
  2921. *
  2922. * @method
  2923. * @param {number} value the 32-bit integer in question.
  2924. * @return {Timestamp} the timestamp.
  2925. */
  2926. }, {
  2927. key: "toExtendedJSON",
  2928. /**
  2929. * @ignore
  2930. */
  2931. value: function toExtendedJSON() {
  2932. return {
  2933. $timestamp: {
  2934. t: this.high,
  2935. i: this.low
  2936. }
  2937. };
  2938. }
  2939. /**
  2940. * @ignore
  2941. */
  2942. }], [{
  2943. key: "fromInt",
  2944. value: function fromInt(value) {
  2945. return new Timestamp(long_1$1.fromInt(value));
  2946. }
  2947. /**
  2948. * Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned.
  2949. *
  2950. * @method
  2951. * @param {number} value the number in question.
  2952. * @return {Timestamp} the timestamp.
  2953. */
  2954. }, {
  2955. key: "fromNumber",
  2956. value: function fromNumber(value) {
  2957. return new Timestamp(long_1$1.fromNumber(value));
  2958. }
  2959. /**
  2960. * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
  2961. *
  2962. * @method
  2963. * @param {number} lowBits the low 32-bits.
  2964. * @param {number} highBits the high 32-bits.
  2965. * @return {Timestamp} the timestamp.
  2966. */
  2967. }, {
  2968. key: "fromBits",
  2969. value: function fromBits(lowBits, highBits) {
  2970. return new Timestamp(lowBits, highBits);
  2971. }
  2972. /**
  2973. * Returns a Timestamp from the given string, optionally using the given radix.
  2974. *
  2975. * @method
  2976. * @param {String} str the textual representation of the Timestamp.
  2977. * @param {number} [opt_radix] the radix in which the text is written.
  2978. * @return {Timestamp} the timestamp.
  2979. */
  2980. }, {
  2981. key: "fromString",
  2982. value: function fromString(str, opt_radix) {
  2983. return new Timestamp(long_1$1.fromString(str, opt_radix));
  2984. }
  2985. }, {
  2986. key: "fromExtendedJSON",
  2987. value: function fromExtendedJSON(doc) {
  2988. return new Timestamp(doc.$timestamp.i, doc.$timestamp.t);
  2989. }
  2990. }]);
  2991. return Timestamp;
  2992. }(long_1$1);
  2993. Object.defineProperty(Timestamp.prototype, '_bsontype', {
  2994. value: 'Timestamp'
  2995. });
  2996. var timestamp = Timestamp;
  2997. var require$$0 = {};
  2998. /* global window */
  2999. /**
  3000. * Normalizes our expected stringified form of a function across versions of node
  3001. * @param {Function} fn The function to stringify
  3002. */
  3003. function normalizedFunctionString(fn) {
  3004. return fn.toString().replace('function(', 'function (');
  3005. }
  3006. function insecureRandomBytes(size) {
  3007. var result = new Uint8Array(size);
  3008. for (var i = 0; i < size; ++i) {
  3009. result[i] = Math.floor(Math.random() * 256);
  3010. }
  3011. return result;
  3012. }
  3013. var randomBytes = insecureRandomBytes;
  3014. if (typeof window !== 'undefined' && window.crypto && window.crypto.getRandomValues) {
  3015. randomBytes = function randomBytes(size) {
  3016. return window.crypto.getRandomValues(new Uint8Array(size));
  3017. };
  3018. } else {
  3019. try {
  3020. randomBytes = require$$0.randomBytes;
  3021. } catch (e) {} // keep the fallback
  3022. // NOTE: in transpiled cases the above require might return null/undefined
  3023. if (randomBytes == null) {
  3024. randomBytes = insecureRandomBytes;
  3025. }
  3026. }
  3027. var utils = {
  3028. normalizedFunctionString: normalizedFunctionString,
  3029. randomBytes: randomBytes
  3030. };
  3031. // shim for using process in browser
  3032. // based off https://github.com/defunctzombie/node-process/blob/master/browser.js
  3033. function defaultSetTimout() {
  3034. throw new Error('setTimeout has not been defined');
  3035. }
  3036. function defaultClearTimeout() {
  3037. throw new Error('clearTimeout has not been defined');
  3038. }
  3039. var cachedSetTimeout = defaultSetTimout;
  3040. var cachedClearTimeout = defaultClearTimeout;
  3041. if (typeof global.setTimeout === 'function') {
  3042. cachedSetTimeout = setTimeout;
  3043. }
  3044. if (typeof global.clearTimeout === 'function') {
  3045. cachedClearTimeout = clearTimeout;
  3046. }
  3047. function runTimeout(fun) {
  3048. if (cachedSetTimeout === setTimeout) {
  3049. //normal enviroments in sane situations
  3050. return setTimeout(fun, 0);
  3051. } // if setTimeout wasn't available but was latter defined
  3052. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  3053. cachedSetTimeout = setTimeout;
  3054. return setTimeout(fun, 0);
  3055. }
  3056. try {
  3057. // when when somebody has screwed with setTimeout but no I.E. maddness
  3058. return cachedSetTimeout(fun, 0);
  3059. } catch (e) {
  3060. try {
  3061. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3062. return cachedSetTimeout.call(null, fun, 0);
  3063. } catch (e) {
  3064. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  3065. return cachedSetTimeout.call(this, fun, 0);
  3066. }
  3067. }
  3068. }
  3069. function runClearTimeout(marker) {
  3070. if (cachedClearTimeout === clearTimeout) {
  3071. //normal enviroments in sane situations
  3072. return clearTimeout(marker);
  3073. } // if clearTimeout wasn't available but was latter defined
  3074. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  3075. cachedClearTimeout = clearTimeout;
  3076. return clearTimeout(marker);
  3077. }
  3078. try {
  3079. // when when somebody has screwed with setTimeout but no I.E. maddness
  3080. return cachedClearTimeout(marker);
  3081. } catch (e) {
  3082. try {
  3083. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  3084. return cachedClearTimeout.call(null, marker);
  3085. } catch (e) {
  3086. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  3087. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  3088. return cachedClearTimeout.call(this, marker);
  3089. }
  3090. }
  3091. }
  3092. var queue = [];
  3093. var draining = false;
  3094. var currentQueue;
  3095. var queueIndex = -1;
  3096. function cleanUpNextTick() {
  3097. if (!draining || !currentQueue) {
  3098. return;
  3099. }
  3100. draining = false;
  3101. if (currentQueue.length) {
  3102. queue = currentQueue.concat(queue);
  3103. } else {
  3104. queueIndex = -1;
  3105. }
  3106. if (queue.length) {
  3107. drainQueue();
  3108. }
  3109. }
  3110. function drainQueue() {
  3111. if (draining) {
  3112. return;
  3113. }
  3114. var timeout = runTimeout(cleanUpNextTick);
  3115. draining = true;
  3116. var len = queue.length;
  3117. while (len) {
  3118. currentQueue = queue;
  3119. queue = [];
  3120. while (++queueIndex < len) {
  3121. if (currentQueue) {
  3122. currentQueue[queueIndex].run();
  3123. }
  3124. }
  3125. queueIndex = -1;
  3126. len = queue.length;
  3127. }
  3128. currentQueue = null;
  3129. draining = false;
  3130. runClearTimeout(timeout);
  3131. }
  3132. function nextTick(fun) {
  3133. var args = new Array(arguments.length - 1);
  3134. if (arguments.length > 1) {
  3135. for (var i = 1; i < arguments.length; i++) {
  3136. args[i - 1] = arguments[i];
  3137. }
  3138. }
  3139. queue.push(new Item(fun, args));
  3140. if (queue.length === 1 && !draining) {
  3141. runTimeout(drainQueue);
  3142. }
  3143. } // v8 likes predictible objects
  3144. function Item(fun, array) {
  3145. this.fun = fun;
  3146. this.array = array;
  3147. }
  3148. Item.prototype.run = function () {
  3149. this.fun.apply(null, this.array);
  3150. };
  3151. var title = 'browser';
  3152. var platform = 'browser';
  3153. var browser = true;
  3154. var env = {};
  3155. var argv = [];
  3156. var version = ''; // empty string to avoid regexp issues
  3157. var versions = {};
  3158. var release = {};
  3159. var config = {};
  3160. function noop() {}
  3161. var on = noop;
  3162. var addListener = noop;
  3163. var once = noop;
  3164. var off = noop;
  3165. var removeListener = noop;
  3166. var removeAllListeners = noop;
  3167. var emit = noop;
  3168. function binding(name) {
  3169. throw new Error('process.binding is not supported');
  3170. }
  3171. function cwd() {
  3172. return '/';
  3173. }
  3174. function chdir(dir) {
  3175. throw new Error('process.chdir is not supported');
  3176. }
  3177. function umask() {
  3178. return 0;
  3179. } // from https://github.com/kumavis/browser-process-hrtime/blob/master/index.js
  3180. var performance = global.performance || {};
  3181. var performanceNow = performance.now || performance.mozNow || performance.msNow || performance.oNow || performance.webkitNow || function () {
  3182. return new Date().getTime();
  3183. }; // generate timestamp or delta
  3184. // see http://nodejs.org/api/process.html#process_process_hrtime
  3185. function hrtime(previousTimestamp) {
  3186. var clocktime = performanceNow.call(performance) * 1e-3;
  3187. var seconds = Math.floor(clocktime);
  3188. var nanoseconds = Math.floor(clocktime % 1 * 1e9);
  3189. if (previousTimestamp) {
  3190. seconds = seconds - previousTimestamp[0];
  3191. nanoseconds = nanoseconds - previousTimestamp[1];
  3192. if (nanoseconds < 0) {
  3193. seconds--;
  3194. nanoseconds += 1e9;
  3195. }
  3196. }
  3197. return [seconds, nanoseconds];
  3198. }
  3199. var startTime = new Date();
  3200. function uptime() {
  3201. var currentTime = new Date();
  3202. var dif = currentTime - startTime;
  3203. return dif / 1000;
  3204. }
  3205. var process = {
  3206. nextTick: nextTick,
  3207. title: title,
  3208. browser: browser,
  3209. env: env,
  3210. argv: argv,
  3211. version: version,
  3212. versions: versions,
  3213. on: on,
  3214. addListener: addListener,
  3215. once: once,
  3216. off: off,
  3217. removeListener: removeListener,
  3218. removeAllListeners: removeAllListeners,
  3219. emit: emit,
  3220. binding: binding,
  3221. cwd: cwd,
  3222. chdir: chdir,
  3223. umask: umask,
  3224. hrtime: hrtime,
  3225. platform: platform,
  3226. release: release,
  3227. config: config,
  3228. uptime: uptime
  3229. };
  3230. var inherits;
  3231. if (typeof Object.create === 'function') {
  3232. inherits = function inherits(ctor, superCtor) {
  3233. // implementation from standard node.js 'util' module
  3234. ctor.super_ = superCtor;
  3235. ctor.prototype = Object.create(superCtor.prototype, {
  3236. constructor: {
  3237. value: ctor,
  3238. enumerable: false,
  3239. writable: true,
  3240. configurable: true
  3241. }
  3242. });
  3243. };
  3244. } else {
  3245. inherits = function inherits(ctor, superCtor) {
  3246. ctor.super_ = superCtor;
  3247. var TempCtor = function TempCtor() {};
  3248. TempCtor.prototype = superCtor.prototype;
  3249. ctor.prototype = new TempCtor();
  3250. ctor.prototype.constructor = ctor;
  3251. };
  3252. }
  3253. var inherits$1 = inherits;
  3254. var formatRegExp = /%[sdj%]/g;
  3255. function format(f) {
  3256. if (!isString(f)) {
  3257. var objects = [];
  3258. for (var i = 0; i < arguments.length; i++) {
  3259. objects.push(inspect(arguments[i]));
  3260. }
  3261. return objects.join(' ');
  3262. }
  3263. var i = 1;
  3264. var args = arguments;
  3265. var len = args.length;
  3266. var str = String(f).replace(formatRegExp, function (x) {
  3267. if (x === '%%') return '%';
  3268. if (i >= len) return x;
  3269. switch (x) {
  3270. case '%s':
  3271. return String(args[i++]);
  3272. case '%d':
  3273. return Number(args[i++]);
  3274. case '%j':
  3275. try {
  3276. return JSON.stringify(args[i++]);
  3277. } catch (_) {
  3278. return '[Circular]';
  3279. }
  3280. default:
  3281. return x;
  3282. }
  3283. });
  3284. for (var x = args[i]; i < len; x = args[++i]) {
  3285. if (isNull(x) || !isObject(x)) {
  3286. str += ' ' + x;
  3287. } else {
  3288. str += ' ' + inspect(x);
  3289. }
  3290. }
  3291. return str;
  3292. }
  3293. // Returns a modified function which warns once by default.
  3294. // If --no-deprecation is set, then it is a no-op.
  3295. function deprecate(fn, msg) {
  3296. // Allow for deprecating things in the process of starting up.
  3297. if (isUndefined(global.process)) {
  3298. return function () {
  3299. return deprecate(fn, msg).apply(this, arguments);
  3300. };
  3301. }
  3302. var warned = false;
  3303. function deprecated() {
  3304. if (!warned) {
  3305. {
  3306. console.error(msg);
  3307. }
  3308. warned = true;
  3309. }
  3310. return fn.apply(this, arguments);
  3311. }
  3312. return deprecated;
  3313. }
  3314. var debugs = {};
  3315. var debugEnviron;
  3316. function debuglog(set) {
  3317. if (isUndefined(debugEnviron)) debugEnviron = process.env.NODE_DEBUG || '';
  3318. set = set.toUpperCase();
  3319. if (!debugs[set]) {
  3320. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  3321. var pid = 0;
  3322. debugs[set] = function () {
  3323. var msg = format.apply(null, arguments);
  3324. console.error('%s %d: %s', set, pid, msg);
  3325. };
  3326. } else {
  3327. debugs[set] = function () {};
  3328. }
  3329. }
  3330. return debugs[set];
  3331. }
  3332. /**
  3333. * Echos the value of a value. Trys to print the value out
  3334. * in the best way possible given the different types.
  3335. *
  3336. * @param {Object} obj The object to print out.
  3337. * @param {Object} opts Optional options object that alters the output.
  3338. */
  3339. /* legacy: obj, showHidden, depth, colors*/
  3340. function inspect(obj, opts) {
  3341. // default options
  3342. var ctx = {
  3343. seen: [],
  3344. stylize: stylizeNoColor
  3345. }; // legacy...
  3346. if (arguments.length >= 3) ctx.depth = arguments[2];
  3347. if (arguments.length >= 4) ctx.colors = arguments[3];
  3348. if (isBoolean(opts)) {
  3349. // legacy...
  3350. ctx.showHidden = opts;
  3351. } else if (opts) {
  3352. // got an "options" object
  3353. _extend(ctx, opts);
  3354. } // set default options
  3355. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  3356. if (isUndefined(ctx.depth)) ctx.depth = 2;
  3357. if (isUndefined(ctx.colors)) ctx.colors = false;
  3358. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  3359. if (ctx.colors) ctx.stylize = stylizeWithColor;
  3360. return formatValue(ctx, obj, ctx.depth);
  3361. } // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  3362. inspect.colors = {
  3363. 'bold': [1, 22],
  3364. 'italic': [3, 23],
  3365. 'underline': [4, 24],
  3366. 'inverse': [7, 27],
  3367. 'white': [37, 39],
  3368. 'grey': [90, 39],
  3369. 'black': [30, 39],
  3370. 'blue': [34, 39],
  3371. 'cyan': [36, 39],
  3372. 'green': [32, 39],
  3373. 'magenta': [35, 39],
  3374. 'red': [31, 39],
  3375. 'yellow': [33, 39]
  3376. }; // Don't use 'blue' not visible on cmd.exe
  3377. inspect.styles = {
  3378. 'special': 'cyan',
  3379. 'number': 'yellow',
  3380. 'boolean': 'yellow',
  3381. 'undefined': 'grey',
  3382. 'null': 'bold',
  3383. 'string': 'green',
  3384. 'date': 'magenta',
  3385. // "name": intentionally not styling
  3386. 'regexp': 'red'
  3387. };
  3388. function stylizeWithColor(str, styleType) {
  3389. var style = inspect.styles[styleType];
  3390. if (style) {
  3391. return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
  3392. } else {
  3393. return str;
  3394. }
  3395. }
  3396. function stylizeNoColor(str, styleType) {
  3397. return str;
  3398. }
  3399. function arrayToHash(array) {
  3400. var hash = {};
  3401. array.forEach(function (val, idx) {
  3402. hash[val] = true;
  3403. });
  3404. return hash;
  3405. }
  3406. function formatValue(ctx, value, recurseTimes) {
  3407. // Provide a hook for user-specified inspect functions.
  3408. // Check that value is an object with an inspect function on it
  3409. if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
  3410. value.inspect !== inspect && // Also filter out any prototype objects using the circular check.
  3411. !(value.constructor && value.constructor.prototype === value)) {
  3412. var ret = value.inspect(recurseTimes, ctx);
  3413. if (!isString(ret)) {
  3414. ret = formatValue(ctx, ret, recurseTimes);
  3415. }
  3416. return ret;
  3417. } // Primitive types cannot have properties
  3418. var primitive = formatPrimitive(ctx, value);
  3419. if (primitive) {
  3420. return primitive;
  3421. } // Look up the keys of the object.
  3422. var keys = Object.keys(value);
  3423. var visibleKeys = arrayToHash(keys);
  3424. if (ctx.showHidden) {
  3425. keys = Object.getOwnPropertyNames(value);
  3426. } // IE doesn't make error fields non-enumerable
  3427. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  3428. if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  3429. return formatError(value);
  3430. } // Some type of object without properties can be shortcutted.
  3431. if (keys.length === 0) {
  3432. if (isFunction(value)) {
  3433. var name = value.name ? ': ' + value.name : '';
  3434. return ctx.stylize('[Function' + name + ']', 'special');
  3435. }
  3436. if (isRegExp(value)) {
  3437. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3438. }
  3439. if (isDate(value)) {
  3440. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  3441. }
  3442. if (isError(value)) {
  3443. return formatError(value);
  3444. }
  3445. }
  3446. var base = '',
  3447. array = false,
  3448. braces = ['{', '}']; // Make Array say that they are Array
  3449. if (isArray(value)) {
  3450. array = true;
  3451. braces = ['[', ']'];
  3452. } // Make functions say that they are functions
  3453. if (isFunction(value)) {
  3454. var n = value.name ? ': ' + value.name : '';
  3455. base = ' [Function' + n + ']';
  3456. } // Make RegExps say that they are RegExps
  3457. if (isRegExp(value)) {
  3458. base = ' ' + RegExp.prototype.toString.call(value);
  3459. } // Make dates with properties first say the date
  3460. if (isDate(value)) {
  3461. base = ' ' + Date.prototype.toUTCString.call(value);
  3462. } // Make error with message first say the error
  3463. if (isError(value)) {
  3464. base = ' ' + formatError(value);
  3465. }
  3466. if (keys.length === 0 && (!array || value.length == 0)) {
  3467. return braces[0] + base + braces[1];
  3468. }
  3469. if (recurseTimes < 0) {
  3470. if (isRegExp(value)) {
  3471. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  3472. } else {
  3473. return ctx.stylize('[Object]', 'special');
  3474. }
  3475. }
  3476. ctx.seen.push(value);
  3477. var output;
  3478. if (array) {
  3479. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  3480. } else {
  3481. output = keys.map(function (key) {
  3482. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  3483. });
  3484. }
  3485. ctx.seen.pop();
  3486. return reduceToSingleString(output, base, braces);
  3487. }
  3488. function formatPrimitive(ctx, value) {
  3489. if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
  3490. if (isString(value)) {
  3491. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
  3492. return ctx.stylize(simple, 'string');
  3493. }
  3494. if (isNumber(value)) return ctx.stylize('' + value, 'number');
  3495. if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
  3496. if (isNull(value)) return ctx.stylize('null', 'null');
  3497. }
  3498. function formatError(value) {
  3499. return '[' + Error.prototype.toString.call(value) + ']';
  3500. }
  3501. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  3502. var output = [];
  3503. for (var i = 0, l = value.length; i < l; ++i) {
  3504. if (hasOwnProperty(value, String(i))) {
  3505. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
  3506. } else {
  3507. output.push('');
  3508. }
  3509. }
  3510. keys.forEach(function (key) {
  3511. if (!key.match(/^\d+$/)) {
  3512. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
  3513. }
  3514. });
  3515. return output;
  3516. }
  3517. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  3518. var name, str, desc;
  3519. desc = Object.getOwnPropertyDescriptor(value, key) || {
  3520. value: value[key]
  3521. };
  3522. if (desc.get) {
  3523. if (desc.set) {
  3524. str = ctx.stylize('[Getter/Setter]', 'special');
  3525. } else {
  3526. str = ctx.stylize('[Getter]', 'special');
  3527. }
  3528. } else {
  3529. if (desc.set) {
  3530. str = ctx.stylize('[Setter]', 'special');
  3531. }
  3532. }
  3533. if (!hasOwnProperty(visibleKeys, key)) {
  3534. name = '[' + key + ']';
  3535. }
  3536. if (!str) {
  3537. if (ctx.seen.indexOf(desc.value) < 0) {
  3538. if (isNull(recurseTimes)) {
  3539. str = formatValue(ctx, desc.value, null);
  3540. } else {
  3541. str = formatValue(ctx, desc.value, recurseTimes - 1);
  3542. }
  3543. if (str.indexOf('\n') > -1) {
  3544. if (array) {
  3545. str = str.split('\n').map(function (line) {
  3546. return ' ' + line;
  3547. }).join('\n').substr(2);
  3548. } else {
  3549. str = '\n' + str.split('\n').map(function (line) {
  3550. return ' ' + line;
  3551. }).join('\n');
  3552. }
  3553. }
  3554. } else {
  3555. str = ctx.stylize('[Circular]', 'special');
  3556. }
  3557. }
  3558. if (isUndefined(name)) {
  3559. if (array && key.match(/^\d+$/)) {
  3560. return str;
  3561. }
  3562. name = JSON.stringify('' + key);
  3563. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  3564. name = name.substr(1, name.length - 2);
  3565. name = ctx.stylize(name, 'name');
  3566. } else {
  3567. name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  3568. name = ctx.stylize(name, 'string');
  3569. }
  3570. }
  3571. return name + ': ' + str;
  3572. }
  3573. function reduceToSingleString(output, base, braces) {
  3574. var length = output.reduce(function (prev, cur) {
  3575. if (cur.indexOf('\n') >= 0) ;
  3576. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  3577. }, 0);
  3578. if (length > 60) {
  3579. return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
  3580. }
  3581. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  3582. } // NOTE: These type checking functions intentionally don't use `instanceof`
  3583. // because it is fragile and can be easily faked with `Object.create()`.
  3584. function isArray(ar) {
  3585. return Array.isArray(ar);
  3586. }
  3587. function isBoolean(arg) {
  3588. return typeof arg === 'boolean';
  3589. }
  3590. function isNull(arg) {
  3591. return arg === null;
  3592. }
  3593. function isNullOrUndefined(arg) {
  3594. return arg == null;
  3595. }
  3596. function isNumber(arg) {
  3597. return typeof arg === 'number';
  3598. }
  3599. function isString(arg) {
  3600. return typeof arg === 'string';
  3601. }
  3602. function isSymbol(arg) {
  3603. return _typeof(arg) === 'symbol';
  3604. }
  3605. function isUndefined(arg) {
  3606. return arg === void 0;
  3607. }
  3608. function isRegExp(re) {
  3609. return isObject(re) && objectToString(re) === '[object RegExp]';
  3610. }
  3611. function isObject(arg) {
  3612. return _typeof(arg) === 'object' && arg !== null;
  3613. }
  3614. function isDate(d) {
  3615. return isObject(d) && objectToString(d) === '[object Date]';
  3616. }
  3617. function isError(e) {
  3618. return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
  3619. }
  3620. function isFunction(arg) {
  3621. return typeof arg === 'function';
  3622. }
  3623. function isPrimitive(arg) {
  3624. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  3625. typeof arg === 'undefined';
  3626. }
  3627. function isBuffer(maybeBuf) {
  3628. return Buffer.isBuffer(maybeBuf);
  3629. }
  3630. function objectToString(o) {
  3631. return Object.prototype.toString.call(o);
  3632. }
  3633. function pad(n) {
  3634. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  3635. }
  3636. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
  3637. function timestamp$1() {
  3638. var d = new Date();
  3639. var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
  3640. return [d.getDate(), months[d.getMonth()], time].join(' ');
  3641. } // log is just a thin wrapper to console.log that prepends a timestamp
  3642. function log() {
  3643. console.log('%s - %s', timestamp$1(), format.apply(null, arguments));
  3644. }
  3645. function _extend(origin, add) {
  3646. // Don't do anything if add isn't an object
  3647. if (!add || !isObject(add)) return origin;
  3648. var keys = Object.keys(add);
  3649. var i = keys.length;
  3650. while (i--) {
  3651. origin[keys[i]] = add[keys[i]];
  3652. }
  3653. return origin;
  3654. }
  3655. function hasOwnProperty(obj, prop) {
  3656. return Object.prototype.hasOwnProperty.call(obj, prop);
  3657. }
  3658. var require$$2 = {
  3659. inherits: inherits$1,
  3660. _extend: _extend,
  3661. log: log,
  3662. isBuffer: isBuffer,
  3663. isPrimitive: isPrimitive,
  3664. isFunction: isFunction,
  3665. isError: isError,
  3666. isDate: isDate,
  3667. isObject: isObject,
  3668. isRegExp: isRegExp,
  3669. isUndefined: isUndefined,
  3670. isSymbol: isSymbol,
  3671. isString: isString,
  3672. isNumber: isNumber,
  3673. isNullOrUndefined: isNullOrUndefined,
  3674. isNull: isNull,
  3675. isBoolean: isBoolean,
  3676. isArray: isArray,
  3677. inspect: inspect,
  3678. deprecate: deprecate,
  3679. format: format,
  3680. debuglog: debuglog
  3681. };
  3682. var Buffer$1 = buffer.Buffer;
  3683. var randomBytes$1 = utils.randomBytes;
  3684. var deprecate$1 = require$$2.deprecate; // constants
  3685. var PROCESS_UNIQUE = randomBytes$1(5); // Regular expression that checks for hex value
  3686. var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
  3687. var hasBufferType = false; // Check if buffer exists
  3688. try {
  3689. if (Buffer$1 && Buffer$1.from) hasBufferType = true;
  3690. } catch (err) {
  3691. hasBufferType = false;
  3692. } // Precomputed hex table enables speedy hex string conversion
  3693. var hexTable = [];
  3694. for (var _i = 0; _i < 256; _i++) {
  3695. hexTable[_i] = (_i <= 15 ? '0' : '') + _i.toString(16);
  3696. } // Lookup tables
  3697. var decodeLookup = [];
  3698. var i$1 = 0;
  3699. while (i$1 < 10) {
  3700. decodeLookup[0x30 + i$1] = i$1++;
  3701. }
  3702. while (i$1 < 16) {
  3703. decodeLookup[0x41 - 10 + i$1] = decodeLookup[0x61 - 10 + i$1] = i$1++;
  3704. }
  3705. var _Buffer = Buffer$1;
  3706. function convertToHex(bytes) {
  3707. return bytes.toString('hex');
  3708. }
  3709. function makeObjectIdError(invalidString, index) {
  3710. var invalidCharacter = invalidString[index];
  3711. return new TypeError("ObjectId string \"".concat(invalidString, "\" contains invalid character \"").concat(invalidCharacter, "\" with character code (").concat(invalidString.charCodeAt(index), "). All character codes for a non-hex string must be less than 256."));
  3712. }
  3713. /**
  3714. * A class representation of the BSON ObjectId type.
  3715. */
  3716. var ObjectId =
  3717. /*#__PURE__*/
  3718. function () {
  3719. /**
  3720. * Create an ObjectId type
  3721. *
  3722. * @param {(string|number)} id Can be a 24 byte hex string, 12 byte binary string or a Number.
  3723. * @property {number} generationTime The generation time of this ObjectId instance
  3724. * @return {ObjectId} instance of ObjectId.
  3725. */
  3726. function ObjectId(id) {
  3727. _classCallCheck(this, ObjectId);
  3728. // Duck-typing to support ObjectId from different npm packages
  3729. if (id instanceof ObjectId) return id; // The most common usecase (blank id, new objectId instance)
  3730. if (id == null || typeof id === 'number') {
  3731. // Generate a new id
  3732. this.id = ObjectId.generate(id); // If we are caching the hex string
  3733. if (ObjectId.cacheHexString) this.__id = this.toString('hex'); // Return the object
  3734. return;
  3735. } // Check if the passed in id is valid
  3736. var valid = ObjectId.isValid(id); // Throw an error if it's not a valid setup
  3737. if (!valid && id != null) {
  3738. throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
  3739. } else if (valid && typeof id === 'string' && id.length === 24 && hasBufferType) {
  3740. return new ObjectId(Buffer$1.from(id, 'hex'));
  3741. } else if (valid && typeof id === 'string' && id.length === 24) {
  3742. return ObjectId.createFromHexString(id);
  3743. } else if (id != null && id.length === 12) {
  3744. // assume 12 byte string
  3745. this.id = id;
  3746. } else if (id != null && id.toHexString) {
  3747. // Duck-typing to support ObjectId from different npm packages
  3748. return id;
  3749. } else {
  3750. throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
  3751. }
  3752. if (ObjectId.cacheHexString) this.__id = this.toString('hex');
  3753. }
  3754. /**
  3755. * Return the ObjectId id as a 24 byte hex string representation
  3756. *
  3757. * @method
  3758. * @return {string} return the 24 byte hex string representation.
  3759. */
  3760. _createClass(ObjectId, [{
  3761. key: "toHexString",
  3762. value: function toHexString() {
  3763. if (ObjectId.cacheHexString && this.__id) return this.__id;
  3764. var hexString = '';
  3765. if (!this.id || !this.id.length) {
  3766. throw new TypeError('invalid ObjectId, ObjectId.id must be either a string or a Buffer, but is [' + JSON.stringify(this.id) + ']');
  3767. }
  3768. if (this.id instanceof _Buffer) {
  3769. hexString = convertToHex(this.id);
  3770. if (ObjectId.cacheHexString) this.__id = hexString;
  3771. return hexString;
  3772. }
  3773. for (var _i2 = 0; _i2 < this.id.length; _i2++) {
  3774. var hexChar = hexTable[this.id.charCodeAt(_i2)];
  3775. if (typeof hexChar !== 'string') {
  3776. throw makeObjectIdError(this.id, _i2);
  3777. }
  3778. hexString += hexChar;
  3779. }
  3780. if (ObjectId.cacheHexString) this.__id = hexString;
  3781. return hexString;
  3782. }
  3783. /**
  3784. * Update the ObjectId index used in generating new ObjectId's on the driver
  3785. *
  3786. * @method
  3787. * @return {number} returns next index value.
  3788. * @ignore
  3789. */
  3790. }, {
  3791. key: "toString",
  3792. /**
  3793. * Converts the id into a 24 byte hex string for printing
  3794. *
  3795. * @param {String} format The Buffer toString format parameter.
  3796. * @return {String} return the 24 byte hex string representation.
  3797. * @ignore
  3798. */
  3799. value: function toString(format) {
  3800. // Is the id a buffer then use the buffer toString method to return the format
  3801. if (this.id && this.id.copy) {
  3802. return this.id.toString(typeof format === 'string' ? format : 'hex');
  3803. }
  3804. return this.toHexString();
  3805. }
  3806. /**
  3807. * Converts to its JSON representation.
  3808. *
  3809. * @return {String} return the 24 byte hex string representation.
  3810. * @ignore
  3811. */
  3812. }, {
  3813. key: "toJSON",
  3814. value: function toJSON() {
  3815. return this.toHexString();
  3816. }
  3817. /**
  3818. * Compares the equality of this ObjectId with `otherID`.
  3819. *
  3820. * @method
  3821. * @param {object} otherID ObjectId instance to compare against.
  3822. * @return {boolean} the result of comparing two ObjectId's
  3823. */
  3824. }, {
  3825. key: "equals",
  3826. value: function equals(otherId) {
  3827. if (otherId instanceof ObjectId) {
  3828. return this.toString() === otherId.toString();
  3829. }
  3830. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12 && this.id instanceof _Buffer) {
  3831. return otherId === this.id.toString('binary');
  3832. }
  3833. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
  3834. return otherId.toLowerCase() === this.toHexString();
  3835. }
  3836. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
  3837. return otherId === this.id;
  3838. }
  3839. if (otherId != null && (otherId instanceof ObjectId || otherId.toHexString)) {
  3840. return otherId.toHexString() === this.toHexString();
  3841. }
  3842. return false;
  3843. }
  3844. /**
  3845. * Returns the generation date (accurate up to the second) that this ID was generated.
  3846. *
  3847. * @method
  3848. * @return {date} the generation date
  3849. */
  3850. }, {
  3851. key: "getTimestamp",
  3852. value: function getTimestamp() {
  3853. var timestamp = new Date();
  3854. var time = this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24;
  3855. timestamp.setTime(Math.floor(time) * 1000);
  3856. return timestamp;
  3857. }
  3858. /**
  3859. * @ignore
  3860. */
  3861. }, {
  3862. key: "toExtendedJSON",
  3863. /**
  3864. * @ignore
  3865. */
  3866. value: function toExtendedJSON() {
  3867. if (this.toHexString) return {
  3868. $oid: this.toHexString()
  3869. };
  3870. return {
  3871. $oid: this.toString('hex')
  3872. };
  3873. }
  3874. /**
  3875. * @ignore
  3876. */
  3877. }], [{
  3878. key: "getInc",
  3879. value: function getInc() {
  3880. return ObjectId.index = (ObjectId.index + 1) % 0xffffff;
  3881. }
  3882. /**
  3883. * Generate a 12 byte id buffer used in ObjectId's
  3884. *
  3885. * @method
  3886. * @param {number} [time] optional parameter allowing to pass in a second based timestamp.
  3887. * @return {Buffer} return the 12 byte id buffer string.
  3888. */
  3889. }, {
  3890. key: "generate",
  3891. value: function generate(time) {
  3892. if ('number' !== typeof time) {
  3893. time = ~~(Date.now() / 1000);
  3894. }
  3895. var inc = ObjectId.getInc();
  3896. var buffer$$1 = Buffer$1.alloc(12); // 4-byte timestamp
  3897. buffer$$1[3] = time & 0xff;
  3898. buffer$$1[2] = time >> 8 & 0xff;
  3899. buffer$$1[1] = time >> 16 & 0xff;
  3900. buffer$$1[0] = time >> 24 & 0xff; // 5-byte process unique
  3901. buffer$$1[4] = PROCESS_UNIQUE[0];
  3902. buffer$$1[5] = PROCESS_UNIQUE[1];
  3903. buffer$$1[6] = PROCESS_UNIQUE[2];
  3904. buffer$$1[7] = PROCESS_UNIQUE[3];
  3905. buffer$$1[8] = PROCESS_UNIQUE[4]; // 3-byte counter
  3906. buffer$$1[11] = inc & 0xff;
  3907. buffer$$1[10] = inc >> 8 & 0xff;
  3908. buffer$$1[9] = inc >> 16 & 0xff;
  3909. return buffer$$1;
  3910. }
  3911. }, {
  3912. key: "createPk",
  3913. value: function createPk() {
  3914. return new ObjectId();
  3915. }
  3916. /**
  3917. * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
  3918. *
  3919. * @method
  3920. * @param {number} time an integer number representing a number of seconds.
  3921. * @return {ObjectId} return the created ObjectId
  3922. */
  3923. }, {
  3924. key: "createFromTime",
  3925. value: function createFromTime(time) {
  3926. var buffer$$1 = Buffer$1.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // Encode time into first 4 bytes
  3927. buffer$$1[3] = time & 0xff;
  3928. buffer$$1[2] = time >> 8 & 0xff;
  3929. buffer$$1[1] = time >> 16 & 0xff;
  3930. buffer$$1[0] = time >> 24 & 0xff; // Return the new objectId
  3931. return new ObjectId(buffer$$1);
  3932. }
  3933. /**
  3934. * Creates an ObjectId from a hex string representation of an ObjectId.
  3935. *
  3936. * @method
  3937. * @param {string} hexString create a ObjectId from a passed in 24 byte hexstring.
  3938. * @return {ObjectId} return the created ObjectId
  3939. */
  3940. }, {
  3941. key: "createFromHexString",
  3942. value: function createFromHexString(string) {
  3943. // Throw an error if it's not a valid setup
  3944. if (typeof string === 'undefined' || string != null && string.length !== 24) {
  3945. throw new TypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
  3946. } // Use Buffer.from method if available
  3947. if (hasBufferType) return new ObjectId(Buffer$1.from(string, 'hex')); // Calculate lengths
  3948. var array = new _Buffer(12);
  3949. var n = 0;
  3950. var i = 0;
  3951. while (i < 24) {
  3952. array[n++] = decodeLookup[string.charCodeAt(i++)] << 4 | decodeLookup[string.charCodeAt(i++)];
  3953. }
  3954. return new ObjectId(array);
  3955. }
  3956. /**
  3957. * Checks if a value is a valid bson ObjectId
  3958. *
  3959. * @method
  3960. * @return {boolean} return true if the value is a valid bson ObjectId, return false otherwise.
  3961. */
  3962. }, {
  3963. key: "isValid",
  3964. value: function isValid(id) {
  3965. if (id == null) return false;
  3966. if (typeof id === 'number') {
  3967. return true;
  3968. }
  3969. if (typeof id === 'string') {
  3970. return id.length === 12 || id.length === 24 && checkForHexRegExp.test(id);
  3971. }
  3972. if (id instanceof ObjectId) {
  3973. return true;
  3974. }
  3975. if (id instanceof _Buffer && id.length === 12) {
  3976. return true;
  3977. } // Duck-Typing detection of ObjectId like objects
  3978. if (id.toHexString) {
  3979. return id.id.length === 12 || id.id.length === 24 && checkForHexRegExp.test(id.id);
  3980. }
  3981. return false;
  3982. }
  3983. }, {
  3984. key: "fromExtendedJSON",
  3985. value: function fromExtendedJSON(doc) {
  3986. return new ObjectId(doc.$oid);
  3987. }
  3988. }]);
  3989. return ObjectId;
  3990. }(); // Deprecated methods
  3991. ObjectId.get_inc = deprecate$1(function () {
  3992. return ObjectId.getInc();
  3993. }, 'Please use the static `ObjectId.getInc()` instead');
  3994. ObjectId.prototype.get_inc = deprecate$1(function () {
  3995. return ObjectId.getInc();
  3996. }, 'Please use the static `ObjectId.getInc()` instead');
  3997. ObjectId.prototype.getInc = deprecate$1(function () {
  3998. return ObjectId.getInc();
  3999. }, 'Please use the static `ObjectId.getInc()` instead');
  4000. ObjectId.prototype.generate = deprecate$1(function (time) {
  4001. return ObjectId.generate(time);
  4002. }, 'Please use the static `ObjectId.generate(time)` instead');
  4003. /**
  4004. * @ignore
  4005. */
  4006. Object.defineProperty(ObjectId.prototype, 'generationTime', {
  4007. enumerable: true,
  4008. get: function get() {
  4009. return this.id[3] | this.id[2] << 8 | this.id[1] << 16 | this.id[0] << 24;
  4010. },
  4011. set: function set(value) {
  4012. // Encode time into first 4 bytes
  4013. this.id[3] = value & 0xff;
  4014. this.id[2] = value >> 8 & 0xff;
  4015. this.id[1] = value >> 16 & 0xff;
  4016. this.id[0] = value >> 24 & 0xff;
  4017. }
  4018. });
  4019. /**
  4020. * Converts to a string representation of this Id.
  4021. *
  4022. * @return {String} return the 24 byte hex string representation.
  4023. * @ignore
  4024. */
  4025. ObjectId.prototype.inspect = ObjectId.prototype.toString;
  4026. /**
  4027. * @ignore
  4028. */
  4029. ObjectId.index = ~~(Math.random() * 0xffffff);
  4030. Object.defineProperty(ObjectId.prototype, '_bsontype', {
  4031. value: 'ObjectId'
  4032. });
  4033. var objectid = ObjectId;
  4034. function alphabetize(str) {
  4035. return str.split('').sort().join('');
  4036. }
  4037. /**
  4038. * A class representation of the BSON RegExp type.
  4039. */
  4040. var BSONRegExp =
  4041. /*#__PURE__*/
  4042. function () {
  4043. /**
  4044. * Create a RegExp type
  4045. *
  4046. * @param {string} pattern The regular expression pattern to match
  4047. * @param {string} options The regular expression options
  4048. */
  4049. function BSONRegExp(pattern, options) {
  4050. _classCallCheck(this, BSONRegExp);
  4051. // Execute
  4052. this.pattern = pattern || '';
  4053. this.options = options ? alphabetize(options) : ''; // Validate options
  4054. for (var i = 0; i < this.options.length; i++) {
  4055. if (!(this.options[i] === 'i' || this.options[i] === 'm' || this.options[i] === 'x' || this.options[i] === 'l' || this.options[i] === 's' || this.options[i] === 'u')) {
  4056. throw new Error("The regular expression option [".concat(this.options[i], "] is not supported"));
  4057. }
  4058. }
  4059. }
  4060. /**
  4061. * @ignore
  4062. */
  4063. _createClass(BSONRegExp, [{
  4064. key: "toExtendedJSON",
  4065. value: function toExtendedJSON() {
  4066. return {
  4067. $regularExpression: {
  4068. pattern: this.pattern,
  4069. options: this.options
  4070. }
  4071. };
  4072. }
  4073. /**
  4074. * @ignore
  4075. */
  4076. }], [{
  4077. key: "fromExtendedJSON",
  4078. value: function fromExtendedJSON(doc) {
  4079. return new BSONRegExp(doc.$regularExpression.pattern, doc.$regularExpression.options.split('').sort().join(''));
  4080. }
  4081. }]);
  4082. return BSONRegExp;
  4083. }();
  4084. Object.defineProperty(BSONRegExp.prototype, '_bsontype', {
  4085. value: 'BSONRegExp'
  4086. });
  4087. var regexp = BSONRegExp;
  4088. var BSONSymbol =
  4089. /*#__PURE__*/
  4090. function () {
  4091. /**
  4092. * Create a Symbol type
  4093. *
  4094. * @param {string} value the string representing the symbol.
  4095. */
  4096. function BSONSymbol(value) {
  4097. _classCallCheck(this, BSONSymbol);
  4098. this.value = value;
  4099. }
  4100. /**
  4101. * Access the wrapped string value.
  4102. *
  4103. * @method
  4104. * @return {String} returns the wrapped string.
  4105. */
  4106. _createClass(BSONSymbol, [{
  4107. key: "valueOf",
  4108. value: function valueOf() {
  4109. return this.value;
  4110. }
  4111. /**
  4112. * @ignore
  4113. */
  4114. }, {
  4115. key: "toString",
  4116. value: function toString() {
  4117. return this.value;
  4118. }
  4119. /**
  4120. * @ignore
  4121. */
  4122. }, {
  4123. key: "inspect",
  4124. value: function inspect() {
  4125. return this.value;
  4126. }
  4127. /**
  4128. * @ignore
  4129. */
  4130. }, {
  4131. key: "toJSON",
  4132. value: function toJSON() {
  4133. return this.value;
  4134. }
  4135. /**
  4136. * @ignore
  4137. */
  4138. }, {
  4139. key: "toExtendedJSON",
  4140. value: function toExtendedJSON() {
  4141. return {
  4142. $symbol: this.value
  4143. };
  4144. }
  4145. /**
  4146. * @ignore
  4147. */
  4148. }], [{
  4149. key: "fromExtendedJSON",
  4150. value: function fromExtendedJSON(doc) {
  4151. return new BSONSymbol(doc.$symbol);
  4152. }
  4153. }]);
  4154. return BSONSymbol;
  4155. }();
  4156. Object.defineProperty(BSONSymbol.prototype, '_bsontype', {
  4157. value: 'Symbol'
  4158. });
  4159. var symbol = BSONSymbol;
  4160. var Int32 =
  4161. /*#__PURE__*/
  4162. function () {
  4163. /**
  4164. * Create an Int32 type
  4165. *
  4166. * @param {number} value the number we want to represent as an int32.
  4167. * @return {Int32}
  4168. */
  4169. function Int32(value) {
  4170. _classCallCheck(this, Int32);
  4171. this.value = value;
  4172. }
  4173. /**
  4174. * Access the number value.
  4175. *
  4176. * @method
  4177. * @return {number} returns the wrapped int32 number.
  4178. */
  4179. _createClass(Int32, [{
  4180. key: "valueOf",
  4181. value: function valueOf() {
  4182. return this.value;
  4183. }
  4184. /**
  4185. * @ignore
  4186. */
  4187. }, {
  4188. key: "toJSON",
  4189. value: function toJSON() {
  4190. return this.value;
  4191. }
  4192. /**
  4193. * @ignore
  4194. */
  4195. }, {
  4196. key: "toExtendedJSON",
  4197. value: function toExtendedJSON(options) {
  4198. if (options && options.relaxed) return this.value;
  4199. return {
  4200. $numberInt: this.value.toString()
  4201. };
  4202. }
  4203. /**
  4204. * @ignore
  4205. */
  4206. }], [{
  4207. key: "fromExtendedJSON",
  4208. value: function fromExtendedJSON(doc, options) {
  4209. return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
  4210. }
  4211. }]);
  4212. return Int32;
  4213. }();
  4214. Object.defineProperty(Int32.prototype, '_bsontype', {
  4215. value: 'Int32'
  4216. });
  4217. var int_32 = Int32;
  4218. var Code =
  4219. /*#__PURE__*/
  4220. function () {
  4221. /**
  4222. * Create a Code type
  4223. *
  4224. * @param {(string|function)} code a string or function.
  4225. * @param {Object} [scope] an optional scope for the function.
  4226. * @return {Code}
  4227. */
  4228. function Code(code, scope) {
  4229. _classCallCheck(this, Code);
  4230. this.code = code;
  4231. this.scope = scope;
  4232. }
  4233. /**
  4234. * @ignore
  4235. */
  4236. _createClass(Code, [{
  4237. key: "toJSON",
  4238. value: function toJSON() {
  4239. return {
  4240. scope: this.scope,
  4241. code: this.code
  4242. };
  4243. }
  4244. /**
  4245. * @ignore
  4246. */
  4247. }, {
  4248. key: "toExtendedJSON",
  4249. value: function toExtendedJSON() {
  4250. if (this.scope) {
  4251. return {
  4252. $code: this.code,
  4253. $scope: this.scope
  4254. };
  4255. }
  4256. return {
  4257. $code: this.code
  4258. };
  4259. }
  4260. /**
  4261. * @ignore
  4262. */
  4263. }], [{
  4264. key: "fromExtendedJSON",
  4265. value: function fromExtendedJSON(doc) {
  4266. return new Code(doc.$code, doc.$scope);
  4267. }
  4268. }]);
  4269. return Code;
  4270. }();
  4271. Object.defineProperty(Code.prototype, '_bsontype', {
  4272. value: 'Code'
  4273. });
  4274. var code$1 = Code;
  4275. var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
  4276. var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
  4277. var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
  4278. var EXPONENT_MAX = 6111;
  4279. var EXPONENT_MIN = -6176;
  4280. var EXPONENT_BIAS = 6176;
  4281. var MAX_DIGITS = 34; // Nan value bits as 32 bit values (due to lack of longs)
  4282. var NAN_BUFFER = [0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].reverse(); // Infinity value bits 32 bit values (due to lack of longs)
  4283. var INF_NEGATIVE_BUFFER = [0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].reverse();
  4284. var INF_POSITIVE_BUFFER = [0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].reverse();
  4285. var EXPONENT_REGEX = /^([-+])?(\d+)?$/; // Detect if the value is a digit
  4286. function isDigit(value) {
  4287. return !isNaN(parseInt(value, 10));
  4288. } // Divide two uint128 values
  4289. function divideu128(value) {
  4290. var DIVISOR = long_1$1.fromNumber(1000 * 1000 * 1000);
  4291. var _rem = long_1$1.fromNumber(0);
  4292. if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
  4293. return {
  4294. quotient: value,
  4295. rem: _rem
  4296. };
  4297. }
  4298. for (var i = 0; i <= 3; i++) {
  4299. // Adjust remainder to match value of next dividend
  4300. _rem = _rem.shiftLeft(32); // Add the divided to _rem
  4301. _rem = _rem.add(new long_1$1(value.parts[i], 0));
  4302. value.parts[i] = _rem.div(DIVISOR).low;
  4303. _rem = _rem.modulo(DIVISOR);
  4304. }
  4305. return {
  4306. quotient: value,
  4307. rem: _rem
  4308. };
  4309. } // Multiply two Long values and return the 128 bit value
  4310. function multiply64x2(left, right) {
  4311. if (!left && !right) {
  4312. return {
  4313. high: long_1$1.fromNumber(0),
  4314. low: long_1$1.fromNumber(0)
  4315. };
  4316. }
  4317. var leftHigh = left.shiftRightUnsigned(32);
  4318. var leftLow = new long_1$1(left.getLowBits(), 0);
  4319. var rightHigh = right.shiftRightUnsigned(32);
  4320. var rightLow = new long_1$1(right.getLowBits(), 0);
  4321. var productHigh = leftHigh.multiply(rightHigh);
  4322. var productMid = leftHigh.multiply(rightLow);
  4323. var productMid2 = leftLow.multiply(rightHigh);
  4324. var productLow = leftLow.multiply(rightLow);
  4325. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  4326. productMid = new long_1$1(productMid.getLowBits(), 0).add(productMid2).add(productLow.shiftRightUnsigned(32));
  4327. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  4328. productLow = productMid.shiftLeft(32).add(new long_1$1(productLow.getLowBits(), 0)); // Return the 128 bit result
  4329. return {
  4330. high: productHigh,
  4331. low: productLow
  4332. };
  4333. }
  4334. function lessThan(left, right) {
  4335. // Make values unsigned
  4336. var uhleft = left.high >>> 0;
  4337. var uhright = right.high >>> 0; // Compare high bits first
  4338. if (uhleft < uhright) {
  4339. return true;
  4340. } else if (uhleft === uhright) {
  4341. var ulleft = left.low >>> 0;
  4342. var ulright = right.low >>> 0;
  4343. if (ulleft < ulright) return true;
  4344. }
  4345. return false;
  4346. }
  4347. function invalidErr(string, message) {
  4348. throw new TypeError("\"".concat(string, "\" is not a valid Decimal128 string - ").concat(message));
  4349. }
  4350. /**
  4351. * A class representation of the BSON Decimal128 type.
  4352. *
  4353. * @class
  4354. * @param {Buffer} bytes a buffer containing the raw Decimal128 bytes.
  4355. * @return {Double}
  4356. */
  4357. function Decimal128(bytes) {
  4358. this.bytes = bytes;
  4359. }
  4360. /**
  4361. * Create a Decimal128 instance from a string representation
  4362. *
  4363. * @method
  4364. * @param {string} string a numeric string representation.
  4365. * @return {Decimal128} returns a Decimal128 instance.
  4366. */
  4367. Decimal128.fromString = function (string) {
  4368. // Parse state tracking
  4369. var isNegative = false;
  4370. var sawRadix = false;
  4371. var foundNonZero = false; // Total number of significant digits (no leading or trailing zero)
  4372. var significantDigits = 0; // Total number of significand digits read
  4373. var nDigitsRead = 0; // Total number of digits (no leading zeros)
  4374. var nDigits = 0; // The number of the digits after radix
  4375. var radixPosition = 0; // The index of the first non-zero in *str*
  4376. var firstNonZero = 0; // Digits Array
  4377. var digits = [0]; // The number of digits in digits
  4378. var nDigitsStored = 0; // Insertion pointer for digits
  4379. var digitsInsert = 0; // The index of the first non-zero digit
  4380. var firstDigit = 0; // The index of the last digit
  4381. var lastDigit = 0; // Exponent
  4382. var exponent = 0; // loop index over array
  4383. var i = 0; // The high 17 digits of the significand
  4384. var significandHigh = [0, 0]; // The low 17 digits of the significand
  4385. var significandLow = [0, 0]; // The biased exponent
  4386. var biasedExponent = 0; // Read index
  4387. var index = 0; // Naively prevent against REDOS attacks.
  4388. // TODO: implementing a custom parsing for this, or refactoring the regex would yield
  4389. // further gains.
  4390. if (string.length >= 7000) {
  4391. throw new TypeError('' + string + ' not a valid Decimal128 string');
  4392. } // Results
  4393. var stringMatch = string.match(PARSE_STRING_REGEXP);
  4394. var infMatch = string.match(PARSE_INF_REGEXP);
  4395. var nanMatch = string.match(PARSE_NAN_REGEXP); // Validate the string
  4396. if (!stringMatch && !infMatch && !nanMatch || string.length === 0) {
  4397. throw new TypeError('' + string + ' not a valid Decimal128 string');
  4398. }
  4399. if (stringMatch) {
  4400. // full_match = stringMatch[0]
  4401. // sign = stringMatch[1]
  4402. var unsignedNumber = stringMatch[2]; // stringMatch[3] is undefined if a whole number (ex "1", 12")
  4403. // but defined if a number w/ decimal in it (ex "1.0, 12.2")
  4404. var e = stringMatch[4];
  4405. var expSign = stringMatch[5];
  4406. var expNumber = stringMatch[6]; // they provided e, but didn't give an exponent number. for ex "1e"
  4407. if (e && expNumber === undefined) invalidErr(string, 'missing exponent power'); // they provided e, but didn't give a number before it. for ex "e1"
  4408. if (e && unsignedNumber === undefined) invalidErr(string, 'missing exponent base');
  4409. if (e === undefined && (expSign || expNumber)) {
  4410. invalidErr(string, 'missing e before exponent');
  4411. }
  4412. } // Get the negative or positive sign
  4413. if (string[index] === '+' || string[index] === '-') {
  4414. isNegative = string[index++] === '-';
  4415. } // Check if user passed Infinity or NaN
  4416. if (!isDigit(string[index]) && string[index] !== '.') {
  4417. if (string[index] === 'i' || string[index] === 'I') {
  4418. return new Decimal128(Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
  4419. } else if (string[index] === 'N') {
  4420. return new Decimal128(Buffer.from(NAN_BUFFER));
  4421. }
  4422. } // Read all the digits
  4423. while (isDigit(string[index]) || string[index] === '.') {
  4424. if (string[index] === '.') {
  4425. if (sawRadix) invalidErr(string, 'contains multiple periods');
  4426. sawRadix = true;
  4427. index = index + 1;
  4428. continue;
  4429. }
  4430. if (nDigitsStored < 34) {
  4431. if (string[index] !== '0' || foundNonZero) {
  4432. if (!foundNonZero) {
  4433. firstNonZero = nDigitsRead;
  4434. }
  4435. foundNonZero = true; // Only store 34 digits
  4436. digits[digitsInsert++] = parseInt(string[index], 10);
  4437. nDigitsStored = nDigitsStored + 1;
  4438. }
  4439. }
  4440. if (foundNonZero) nDigits = nDigits + 1;
  4441. if (sawRadix) radixPosition = radixPosition + 1;
  4442. nDigitsRead = nDigitsRead + 1;
  4443. index = index + 1;
  4444. }
  4445. if (sawRadix && !nDigitsRead) throw new TypeError('' + string + ' not a valid Decimal128 string'); // Read exponent if exists
  4446. if (string[index] === 'e' || string[index] === 'E') {
  4447. // Read exponent digits
  4448. var match = string.substr(++index).match(EXPONENT_REGEX); // No digits read
  4449. if (!match || !match[2]) return new Decimal128(Buffer.from(NAN_BUFFER)); // Get exponent
  4450. exponent = parseInt(match[0], 10); // Adjust the index
  4451. index = index + match[0].length;
  4452. } // Return not a number
  4453. if (string[index]) return new Decimal128(Buffer.from(NAN_BUFFER)); // Done reading input
  4454. // Find first non-zero digit in digits
  4455. firstDigit = 0;
  4456. if (!nDigitsStored) {
  4457. firstDigit = 0;
  4458. lastDigit = 0;
  4459. digits[0] = 0;
  4460. nDigits = 1;
  4461. nDigitsStored = 1;
  4462. significantDigits = 0;
  4463. } else {
  4464. lastDigit = nDigitsStored - 1;
  4465. significantDigits = nDigits;
  4466. if (significantDigits !== 1) {
  4467. while (string[firstNonZero + significantDigits - 1] === '0') {
  4468. significantDigits = significantDigits - 1;
  4469. }
  4470. }
  4471. } // Normalization of exponent
  4472. // Correct exponent based on radix position, and shift significand as needed
  4473. // to represent user input
  4474. // Overflow prevention
  4475. if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) {
  4476. exponent = EXPONENT_MIN;
  4477. } else {
  4478. exponent = exponent - radixPosition;
  4479. } // Attempt to normalize the exponent
  4480. while (exponent > EXPONENT_MAX) {
  4481. // Shift exponent to significand and decrease
  4482. lastDigit = lastDigit + 1;
  4483. if (lastDigit - firstDigit > MAX_DIGITS) {
  4484. // Check if we have a zero then just hard clamp, otherwise fail
  4485. var digitsString = digits.join('');
  4486. if (digitsString.match(/^0+$/)) {
  4487. exponent = EXPONENT_MAX;
  4488. break;
  4489. }
  4490. invalidErr(string, 'overflow');
  4491. }
  4492. exponent = exponent - 1;
  4493. }
  4494. while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
  4495. // Shift last digit. can only do this if < significant digits than # stored.
  4496. if (lastDigit === 0 && significantDigits < nDigitsStored) {
  4497. exponent = EXPONENT_MIN;
  4498. significantDigits = 0;
  4499. break;
  4500. }
  4501. if (nDigitsStored < nDigits) {
  4502. // adjust to match digits not stored
  4503. nDigits = nDigits - 1;
  4504. } else {
  4505. // adjust to round
  4506. lastDigit = lastDigit - 1;
  4507. }
  4508. if (exponent < EXPONENT_MAX) {
  4509. exponent = exponent + 1;
  4510. } else {
  4511. // Check if we have a zero then just hard clamp, otherwise fail
  4512. var _digitsString = digits.join('');
  4513. if (_digitsString.match(/^0+$/)) {
  4514. exponent = EXPONENT_MAX;
  4515. break;
  4516. }
  4517. invalidErr(string, 'overflow');
  4518. }
  4519. } // Round
  4520. // We've normalized the exponent, but might still need to round.
  4521. if (lastDigit - firstDigit + 1 < significantDigits) {
  4522. var endOfString = nDigitsRead; // If we have seen a radix point, 'string' is 1 longer than we have
  4523. // documented with ndigits_read, so inc the position of the first nonzero
  4524. // digit and the position that digits are read to.
  4525. if (sawRadix) {
  4526. firstNonZero = firstNonZero + 1;
  4527. endOfString = endOfString + 1;
  4528. } // if negative, we need to increment again to account for - sign at start.
  4529. if (isNegative) {
  4530. firstNonZero = firstNonZero + 1;
  4531. endOfString = endOfString + 1;
  4532. }
  4533. var roundDigit = parseInt(string[firstNonZero + lastDigit + 1], 10);
  4534. var roundBit = 0;
  4535. if (roundDigit >= 5) {
  4536. roundBit = 1;
  4537. if (roundDigit === 5) {
  4538. roundBit = digits[lastDigit] % 2 === 1;
  4539. for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
  4540. if (parseInt(string[i], 10)) {
  4541. roundBit = 1;
  4542. break;
  4543. }
  4544. }
  4545. }
  4546. }
  4547. if (roundBit) {
  4548. var dIdx = lastDigit;
  4549. for (; dIdx >= 0; dIdx--) {
  4550. if (++digits[dIdx] > 9) {
  4551. digits[dIdx] = 0; // overflowed most significant digit
  4552. if (dIdx === 0) {
  4553. if (exponent < EXPONENT_MAX) {
  4554. exponent = exponent + 1;
  4555. digits[dIdx] = 1;
  4556. } else {
  4557. return new Decimal128(Buffer.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
  4558. }
  4559. }
  4560. }
  4561. }
  4562. }
  4563. } // Encode significand
  4564. // The high 17 digits of the significand
  4565. significandHigh = long_1$1.fromNumber(0); // The low 17 digits of the significand
  4566. significandLow = long_1$1.fromNumber(0); // read a zero
  4567. if (significantDigits === 0) {
  4568. significandHigh = long_1$1.fromNumber(0);
  4569. significandLow = long_1$1.fromNumber(0);
  4570. } else if (lastDigit - firstDigit < 17) {
  4571. var _dIdx = firstDigit;
  4572. significandLow = long_1$1.fromNumber(digits[_dIdx++]);
  4573. significandHigh = new long_1$1(0, 0);
  4574. for (; _dIdx <= lastDigit; _dIdx++) {
  4575. significandLow = significandLow.multiply(long_1$1.fromNumber(10));
  4576. significandLow = significandLow.add(long_1$1.fromNumber(digits[_dIdx]));
  4577. }
  4578. } else {
  4579. var _dIdx2 = firstDigit;
  4580. significandHigh = long_1$1.fromNumber(digits[_dIdx2++]);
  4581. for (; _dIdx2 <= lastDigit - 17; _dIdx2++) {
  4582. significandHigh = significandHigh.multiply(long_1$1.fromNumber(10));
  4583. significandHigh = significandHigh.add(long_1$1.fromNumber(digits[_dIdx2]));
  4584. }
  4585. significandLow = long_1$1.fromNumber(digits[_dIdx2++]);
  4586. for (; _dIdx2 <= lastDigit; _dIdx2++) {
  4587. significandLow = significandLow.multiply(long_1$1.fromNumber(10));
  4588. significandLow = significandLow.add(long_1$1.fromNumber(digits[_dIdx2]));
  4589. }
  4590. }
  4591. var significand = multiply64x2(significandHigh, long_1$1.fromString('100000000000000000'));
  4592. significand.low = significand.low.add(significandLow);
  4593. if (lessThan(significand.low, significandLow)) {
  4594. significand.high = significand.high.add(long_1$1.fromNumber(1));
  4595. } // Biased exponent
  4596. biasedExponent = exponent + EXPONENT_BIAS;
  4597. var dec = {
  4598. low: long_1$1.fromNumber(0),
  4599. high: long_1$1.fromNumber(0)
  4600. }; // Encode combination, exponent, and significand.
  4601. if (significand.high.shiftRightUnsigned(49).and(long_1$1.fromNumber(1)).equals(long_1$1.fromNumber(1))) {
  4602. // Encode '11' into bits 1 to 3
  4603. dec.high = dec.high.or(long_1$1.fromNumber(0x3).shiftLeft(61));
  4604. dec.high = dec.high.or(long_1$1.fromNumber(biasedExponent).and(long_1$1.fromNumber(0x3fff).shiftLeft(47)));
  4605. dec.high = dec.high.or(significand.high.and(long_1$1.fromNumber(0x7fffffffffff)));
  4606. } else {
  4607. dec.high = dec.high.or(long_1$1.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
  4608. dec.high = dec.high.or(significand.high.and(long_1$1.fromNumber(0x1ffffffffffff)));
  4609. }
  4610. dec.low = significand.low; // Encode sign
  4611. if (isNegative) {
  4612. dec.high = dec.high.or(long_1$1.fromString('9223372036854775808'));
  4613. } // Encode into a buffer
  4614. var buffer = Buffer.alloc(16);
  4615. index = 0; // Encode the low 64 bits of the decimal
  4616. // Encode low bits
  4617. buffer[index++] = dec.low.low & 0xff;
  4618. buffer[index++] = dec.low.low >> 8 & 0xff;
  4619. buffer[index++] = dec.low.low >> 16 & 0xff;
  4620. buffer[index++] = dec.low.low >> 24 & 0xff; // Encode high bits
  4621. buffer[index++] = dec.low.high & 0xff;
  4622. buffer[index++] = dec.low.high >> 8 & 0xff;
  4623. buffer[index++] = dec.low.high >> 16 & 0xff;
  4624. buffer[index++] = dec.low.high >> 24 & 0xff; // Encode the high 64 bits of the decimal
  4625. // Encode low bits
  4626. buffer[index++] = dec.high.low & 0xff;
  4627. buffer[index++] = dec.high.low >> 8 & 0xff;
  4628. buffer[index++] = dec.high.low >> 16 & 0xff;
  4629. buffer[index++] = dec.high.low >> 24 & 0xff; // Encode high bits
  4630. buffer[index++] = dec.high.high & 0xff;
  4631. buffer[index++] = dec.high.high >> 8 & 0xff;
  4632. buffer[index++] = dec.high.high >> 16 & 0xff;
  4633. buffer[index++] = dec.high.high >> 24 & 0xff; // Return the new Decimal128
  4634. return new Decimal128(buffer);
  4635. }; // Extract least significant 5 bits
  4636. var COMBINATION_MASK = 0x1f; // Extract least significant 14 bits
  4637. var EXPONENT_MASK = 0x3fff; // Value of combination field for Inf
  4638. var COMBINATION_INFINITY = 30; // Value of combination field for NaN
  4639. var COMBINATION_NAN = 31;
  4640. /**
  4641. * Create a string representation of the raw Decimal128 value
  4642. *
  4643. * @method
  4644. * @return {string} returns a Decimal128 string representation.
  4645. */
  4646. Decimal128.prototype.toString = function () {
  4647. // Note: bits in this routine are referred to starting at 0,
  4648. // from the sign bit, towards the coefficient.
  4649. // bits 0 - 31
  4650. var high; // bits 32 - 63
  4651. var midh; // bits 64 - 95
  4652. var midl; // bits 96 - 127
  4653. var low; // bits 1 - 5
  4654. var combination; // decoded biased exponent (14 bits)
  4655. var biased_exponent; // the number of significand digits
  4656. var significand_digits = 0; // the base-10 digits in the significand
  4657. var significand = new Array(36);
  4658. for (var i = 0; i < significand.length; i++) {
  4659. significand[i] = 0;
  4660. } // read pointer into significand
  4661. var index = 0; // unbiased exponent
  4662. var exponent; // the exponent if scientific notation is used
  4663. var scientific_exponent; // true if the number is zero
  4664. var is_zero = false; // the most signifcant significand bits (50-46)
  4665. var significand_msb; // temporary storage for significand decoding
  4666. var significand128 = {
  4667. parts: new Array(4)
  4668. }; // indexing variables
  4669. var j, k; // Output string
  4670. var string = []; // Unpack index
  4671. index = 0; // Buffer reference
  4672. var buffer = this.bytes; // Unpack the low 64bits into a long
  4673. low = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  4674. midl = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Unpack the high 64bits into a long
  4675. midh = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  4676. high = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Unpack index
  4677. index = 0; // Create the state of the decimal
  4678. var dec = {
  4679. low: new long_1$1(low, midl),
  4680. high: new long_1$1(midh, high)
  4681. };
  4682. if (dec.high.lessThan(long_1$1.ZERO)) {
  4683. string.push('-');
  4684. } // Decode combination field and exponent
  4685. combination = high >> 26 & COMBINATION_MASK;
  4686. if (combination >> 3 === 3) {
  4687. // Check for 'special' values
  4688. if (combination === COMBINATION_INFINITY) {
  4689. return string.join('') + 'Infinity';
  4690. } else if (combination === COMBINATION_NAN) {
  4691. return 'NaN';
  4692. } else {
  4693. biased_exponent = high >> 15 & EXPONENT_MASK;
  4694. significand_msb = 0x08 + (high >> 14 & 0x01);
  4695. }
  4696. } else {
  4697. significand_msb = high >> 14 & 0x07;
  4698. biased_exponent = high >> 17 & EXPONENT_MASK;
  4699. }
  4700. exponent = biased_exponent - EXPONENT_BIAS; // Create string of significand digits
  4701. // Convert the 114-bit binary number represented by
  4702. // (significand_high, significand_low) to at most 34 decimal
  4703. // digits through modulo and division.
  4704. significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14);
  4705. significand128.parts[1] = midh;
  4706. significand128.parts[2] = midl;
  4707. significand128.parts[3] = low;
  4708. if (significand128.parts[0] === 0 && significand128.parts[1] === 0 && significand128.parts[2] === 0 && significand128.parts[3] === 0) {
  4709. is_zero = true;
  4710. } else {
  4711. for (k = 3; k >= 0; k--) {
  4712. var least_digits = 0; // Peform the divide
  4713. var result = divideu128(significand128);
  4714. significand128 = result.quotient;
  4715. least_digits = result.rem.low; // We now have the 9 least significant digits (in base 2).
  4716. // Convert and output to string.
  4717. if (!least_digits) continue;
  4718. for (j = 8; j >= 0; j--) {
  4719. // significand[k * 9 + j] = Math.round(least_digits % 10);
  4720. significand[k * 9 + j] = least_digits % 10; // least_digits = Math.round(least_digits / 10);
  4721. least_digits = Math.floor(least_digits / 10);
  4722. }
  4723. }
  4724. } // Output format options:
  4725. // Scientific - [-]d.dddE(+/-)dd or [-]dE(+/-)dd
  4726. // Regular - ddd.ddd
  4727. if (is_zero) {
  4728. significand_digits = 1;
  4729. significand[index] = 0;
  4730. } else {
  4731. significand_digits = 36;
  4732. while (!significand[index]) {
  4733. significand_digits = significand_digits - 1;
  4734. index = index + 1;
  4735. }
  4736. }
  4737. scientific_exponent = significand_digits - 1 + exponent; // The scientific exponent checks are dictated by the string conversion
  4738. // specification and are somewhat arbitrary cutoffs.
  4739. //
  4740. // We must check exponent > 0, because if this is the case, the number
  4741. // has trailing zeros. However, we *cannot* output these trailing zeros,
  4742. // because doing so would change the precision of the value, and would
  4743. // change stored data if the string converted number is round tripped.
  4744. if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
  4745. // Scientific format
  4746. // if there are too many significant digits, we should just be treating numbers
  4747. // as + or - 0 and using the non-scientific exponent (this is for the "invalid
  4748. // representation should be treated as 0/-0" spec cases in decimal128-1.json)
  4749. if (significand_digits > 34) {
  4750. string.push(0);
  4751. if (exponent > 0) string.push('E+' + exponent);else if (exponent < 0) string.push('E' + exponent);
  4752. return string.join('');
  4753. }
  4754. string.push(significand[index++]);
  4755. significand_digits = significand_digits - 1;
  4756. if (significand_digits) {
  4757. string.push('.');
  4758. }
  4759. for (var _i = 0; _i < significand_digits; _i++) {
  4760. string.push(significand[index++]);
  4761. } // Exponent
  4762. string.push('E');
  4763. if (scientific_exponent > 0) {
  4764. string.push('+' + scientific_exponent);
  4765. } else {
  4766. string.push(scientific_exponent);
  4767. }
  4768. } else {
  4769. // Regular format with no decimal place
  4770. if (exponent >= 0) {
  4771. for (var _i2 = 0; _i2 < significand_digits; _i2++) {
  4772. string.push(significand[index++]);
  4773. }
  4774. } else {
  4775. var radix_position = significand_digits + exponent; // non-zero digits before radix
  4776. if (radix_position > 0) {
  4777. for (var _i3 = 0; _i3 < radix_position; _i3++) {
  4778. string.push(significand[index++]);
  4779. }
  4780. } else {
  4781. string.push('0');
  4782. }
  4783. string.push('.'); // add leading zeros after radix
  4784. while (radix_position++ < 0) {
  4785. string.push('0');
  4786. }
  4787. for (var _i4 = 0; _i4 < significand_digits - Math.max(radix_position - 1, 0); _i4++) {
  4788. string.push(significand[index++]);
  4789. }
  4790. }
  4791. }
  4792. return string.join('');
  4793. };
  4794. Decimal128.prototype.toJSON = function () {
  4795. return {
  4796. $numberDecimal: this.toString()
  4797. };
  4798. };
  4799. /**
  4800. * @ignore
  4801. */
  4802. Decimal128.prototype.toExtendedJSON = function () {
  4803. return {
  4804. $numberDecimal: this.toString()
  4805. };
  4806. };
  4807. /**
  4808. * @ignore
  4809. */
  4810. Decimal128.fromExtendedJSON = function (doc) {
  4811. return Decimal128.fromString(doc.$numberDecimal);
  4812. };
  4813. Object.defineProperty(Decimal128.prototype, '_bsontype', {
  4814. value: 'Decimal128'
  4815. });
  4816. var decimal128 = Decimal128;
  4817. var MinKey =
  4818. /*#__PURE__*/
  4819. function () {
  4820. /**
  4821. * Create a MinKey type
  4822. *
  4823. * @return {MinKey} A MinKey instance
  4824. */
  4825. function MinKey() {
  4826. _classCallCheck(this, MinKey);
  4827. }
  4828. /**
  4829. * @ignore
  4830. */
  4831. _createClass(MinKey, [{
  4832. key: "toExtendedJSON",
  4833. value: function toExtendedJSON() {
  4834. return {
  4835. $minKey: 1
  4836. };
  4837. }
  4838. /**
  4839. * @ignore
  4840. */
  4841. }], [{
  4842. key: "fromExtendedJSON",
  4843. value: function fromExtendedJSON() {
  4844. return new MinKey();
  4845. }
  4846. }]);
  4847. return MinKey;
  4848. }();
  4849. Object.defineProperty(MinKey.prototype, '_bsontype', {
  4850. value: 'MinKey'
  4851. });
  4852. var min_key = MinKey;
  4853. var MaxKey =
  4854. /*#__PURE__*/
  4855. function () {
  4856. /**
  4857. * Create a MaxKey type
  4858. *
  4859. * @return {MaxKey} A MaxKey instance
  4860. */
  4861. function MaxKey() {
  4862. _classCallCheck(this, MaxKey);
  4863. }
  4864. /**
  4865. * @ignore
  4866. */
  4867. _createClass(MaxKey, [{
  4868. key: "toExtendedJSON",
  4869. value: function toExtendedJSON() {
  4870. return {
  4871. $maxKey: 1
  4872. };
  4873. }
  4874. /**
  4875. * @ignore
  4876. */
  4877. }], [{
  4878. key: "fromExtendedJSON",
  4879. value: function fromExtendedJSON() {
  4880. return new MaxKey();
  4881. }
  4882. }]);
  4883. return MaxKey;
  4884. }();
  4885. Object.defineProperty(MaxKey.prototype, '_bsontype', {
  4886. value: 'MaxKey'
  4887. });
  4888. var max_key = MaxKey;
  4889. var DBRef =
  4890. /*#__PURE__*/
  4891. function () {
  4892. /**
  4893. * Create a DBRef type
  4894. *
  4895. * @param {string} collection the collection name.
  4896. * @param {ObjectId} oid the reference ObjectId.
  4897. * @param {string} [db] optional db name, if omitted the reference is local to the current db.
  4898. * @return {DBRef}
  4899. */
  4900. function DBRef(collection, oid, db, fields) {
  4901. _classCallCheck(this, DBRef);
  4902. // check if namespace has been provided
  4903. var parts = collection.split('.');
  4904. if (parts.length === 2) {
  4905. db = parts.shift();
  4906. collection = parts.shift();
  4907. }
  4908. this.collection = collection;
  4909. this.oid = oid;
  4910. this.db = db;
  4911. this.fields = fields || {};
  4912. }
  4913. /**
  4914. * @ignore
  4915. * @api private
  4916. */
  4917. _createClass(DBRef, [{
  4918. key: "toJSON",
  4919. value: function toJSON() {
  4920. var o = Object.assign({
  4921. $ref: this.collection,
  4922. $id: this.oid
  4923. }, this.fields);
  4924. if (this.db != null) o.$db = this.db;
  4925. return o;
  4926. }
  4927. /**
  4928. * @ignore
  4929. */
  4930. }, {
  4931. key: "toExtendedJSON",
  4932. value: function toExtendedJSON() {
  4933. var o = {
  4934. $ref: this.collection,
  4935. $id: this.oid
  4936. };
  4937. if (this.db) o.$db = this.db;
  4938. o = Object.assign(o, this.fields);
  4939. return o;
  4940. }
  4941. /**
  4942. * @ignore
  4943. */
  4944. }], [{
  4945. key: "fromExtendedJSON",
  4946. value: function fromExtendedJSON(doc) {
  4947. var copy = Object.assign({}, doc);
  4948. ['$ref', '$id', '$db'].forEach(function (k) {
  4949. return delete copy[k];
  4950. });
  4951. return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
  4952. }
  4953. }]);
  4954. return DBRef;
  4955. }();
  4956. Object.defineProperty(DBRef.prototype, '_bsontype', {
  4957. value: 'DBRef'
  4958. });
  4959. var db_ref = DBRef;
  4960. var Binary =
  4961. /*#__PURE__*/
  4962. function () {
  4963. /**
  4964. * Create a Binary type
  4965. *
  4966. * Sub types
  4967. * - **BSON.BSON_BINARY_SUBTYPE_DEFAULT**, default BSON type.
  4968. * - **BSON.BSON_BINARY_SUBTYPE_FUNCTION**, BSON function type.
  4969. * - **BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY**, BSON byte array type.
  4970. * - **BSON.BSON_BINARY_SUBTYPE_UUID**, BSON uuid type.
  4971. * - **BSON.BSON_BINARY_SUBTYPE_MD5**, BSON md5 type.
  4972. * - **BSON.BSON_BINARY_SUBTYPE_USER_DEFINED**, BSON user defined type.
  4973. *
  4974. * @param {Buffer} buffer a buffer object containing the binary data.
  4975. * @param {Number} [subType] the option binary type.
  4976. * @return {Binary}
  4977. */
  4978. function Binary(buffer, subType) {
  4979. _classCallCheck(this, Binary);
  4980. if (buffer != null && !(typeof buffer === 'string') && !Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array) && !Array.isArray(buffer)) {
  4981. throw new TypeError('only String, Buffer, Uint8Array or Array accepted');
  4982. }
  4983. this.sub_type = subType == null ? BSON_BINARY_SUBTYPE_DEFAULT : subType;
  4984. this.position = 0;
  4985. if (buffer != null && !(buffer instanceof Number)) {
  4986. // Only accept Buffer, Uint8Array or Arrays
  4987. if (typeof buffer === 'string') {
  4988. // Different ways of writing the length of the string for the different types
  4989. if (typeof Buffer !== 'undefined') {
  4990. this.buffer = Buffer.from(buffer);
  4991. } else if (typeof Uint8Array !== 'undefined' || Array.isArray(buffer)) {
  4992. this.buffer = writeStringToArray(buffer);
  4993. } else {
  4994. throw new TypeError('only String, Buffer, Uint8Array or Array accepted');
  4995. }
  4996. } else {
  4997. this.buffer = buffer;
  4998. }
  4999. this.position = buffer.length;
  5000. } else {
  5001. if (typeof Buffer !== 'undefined') {
  5002. this.buffer = Buffer.alloc(Binary.BUFFER_SIZE);
  5003. } else if (typeof Uint8Array !== 'undefined') {
  5004. this.buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE));
  5005. } else {
  5006. this.buffer = new Array(Binary.BUFFER_SIZE);
  5007. }
  5008. }
  5009. }
  5010. /**
  5011. * Updates this binary with byte_value.
  5012. *
  5013. * @method
  5014. * @param {string} byte_value a single byte we wish to write.
  5015. */
  5016. _createClass(Binary, [{
  5017. key: "put",
  5018. value: function put(byte_value) {
  5019. // If it's a string and a has more than one character throw an error
  5020. if (byte_value['length'] != null && typeof byte_value !== 'number' && byte_value.length !== 1) throw new TypeError('only accepts single character String, Uint8Array or Array');
  5021. if (typeof byte_value !== 'number' && byte_value < 0 || byte_value > 255) throw new TypeError('only accepts number in a valid unsigned byte range 0-255'); // Decode the byte value once
  5022. var decoded_byte = null;
  5023. if (typeof byte_value === 'string') {
  5024. decoded_byte = byte_value.charCodeAt(0);
  5025. } else if (byte_value['length'] != null) {
  5026. decoded_byte = byte_value[0];
  5027. } else {
  5028. decoded_byte = byte_value;
  5029. }
  5030. if (this.buffer.length > this.position) {
  5031. this.buffer[this.position++] = decoded_byte;
  5032. } else {
  5033. if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) {
  5034. // Create additional overflow buffer
  5035. var buffer = Buffer.alloc(Binary.BUFFER_SIZE + this.buffer.length); // Combine the two buffers together
  5036. this.buffer.copy(buffer, 0, 0, this.buffer.length);
  5037. this.buffer = buffer;
  5038. this.buffer[this.position++] = decoded_byte;
  5039. } else {
  5040. var _buffer = null; // Create a new buffer (typed or normal array)
  5041. if (isUint8Array(this.buffer)) {
  5042. _buffer = new Uint8Array(new ArrayBuffer(Binary.BUFFER_SIZE + this.buffer.length));
  5043. } else {
  5044. _buffer = new Array(Binary.BUFFER_SIZE + this.buffer.length);
  5045. } // We need to copy all the content to the new array
  5046. for (var i = 0; i < this.buffer.length; i++) {
  5047. _buffer[i] = this.buffer[i];
  5048. } // Reassign the buffer
  5049. this.buffer = _buffer; // Write the byte
  5050. this.buffer[this.position++] = decoded_byte;
  5051. }
  5052. }
  5053. }
  5054. /**
  5055. * Writes a buffer or string to the binary.
  5056. *
  5057. * @method
  5058. * @param {(Buffer|string)} string a string or buffer to be written to the Binary BSON object.
  5059. * @param {number} offset specify the binary of where to write the content.
  5060. * @return {null}
  5061. */
  5062. }, {
  5063. key: "write",
  5064. value: function write(string, offset) {
  5065. offset = typeof offset === 'number' ? offset : this.position; // If the buffer is to small let's extend the buffer
  5066. if (this.buffer.length < offset + string.length) {
  5067. var buffer = null; // If we are in node.js
  5068. if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) {
  5069. buffer = Buffer.alloc(this.buffer.length + string.length);
  5070. this.buffer.copy(buffer, 0, 0, this.buffer.length);
  5071. } else if (isUint8Array(this.buffer)) {
  5072. // Create a new buffer
  5073. buffer = new Uint8Array(new ArrayBuffer(this.buffer.length + string.length)); // Copy the content
  5074. for (var i = 0; i < this.position; i++) {
  5075. buffer[i] = this.buffer[i];
  5076. }
  5077. } // Assign the new buffer
  5078. this.buffer = buffer;
  5079. }
  5080. if (typeof Buffer !== 'undefined' && Buffer.isBuffer(string) && Buffer.isBuffer(this.buffer)) {
  5081. string.copy(this.buffer, offset, 0, string.length);
  5082. this.position = offset + string.length > this.position ? offset + string.length : this.position; // offset = string.length
  5083. } else if (typeof Buffer !== 'undefined' && typeof string === 'string' && Buffer.isBuffer(this.buffer)) {
  5084. this.buffer.write(string, offset, 'binary');
  5085. this.position = offset + string.length > this.position ? offset + string.length : this.position; // offset = string.length;
  5086. } else if (isUint8Array(string) || Array.isArray(string) && typeof string !== 'string') {
  5087. for (var _i = 0; _i < string.length; _i++) {
  5088. this.buffer[offset++] = string[_i];
  5089. }
  5090. this.position = offset > this.position ? offset : this.position;
  5091. } else if (typeof string === 'string') {
  5092. for (var _i2 = 0; _i2 < string.length; _i2++) {
  5093. this.buffer[offset++] = string.charCodeAt(_i2);
  5094. }
  5095. this.position = offset > this.position ? offset : this.position;
  5096. }
  5097. }
  5098. /**
  5099. * Reads **length** bytes starting at **position**.
  5100. *
  5101. * @method
  5102. * @param {number} position read from the given position in the Binary.
  5103. * @param {number} length the number of bytes to read.
  5104. * @return {Buffer}
  5105. */
  5106. }, {
  5107. key: "read",
  5108. value: function read(position, length) {
  5109. length = length && length > 0 ? length : this.position; // Let's return the data based on the type we have
  5110. if (this.buffer['slice']) {
  5111. return this.buffer.slice(position, position + length);
  5112. } // Create a buffer to keep the result
  5113. var buffer = typeof Uint8Array !== 'undefined' ? new Uint8Array(new ArrayBuffer(length)) : new Array(length);
  5114. for (var i = 0; i < length; i++) {
  5115. buffer[i] = this.buffer[position++];
  5116. } // Return the buffer
  5117. return buffer;
  5118. }
  5119. /**
  5120. * Returns the value of this binary as a string.
  5121. *
  5122. * @method
  5123. * @return {string}
  5124. */
  5125. }, {
  5126. key: "value",
  5127. value: function value(asRaw) {
  5128. asRaw = asRaw == null ? false : asRaw; // Optimize to serialize for the situation where the data == size of buffer
  5129. if (asRaw && typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer) && this.buffer.length === this.position) return this.buffer; // If it's a node.js buffer object
  5130. if (typeof Buffer !== 'undefined' && Buffer.isBuffer(this.buffer)) {
  5131. return asRaw ? this.buffer.slice(0, this.position) : this.buffer.toString('binary', 0, this.position);
  5132. } else {
  5133. if (asRaw) {
  5134. // we support the slice command use it
  5135. if (this.buffer['slice'] != null) {
  5136. return this.buffer.slice(0, this.position);
  5137. } else {
  5138. // Create a new buffer to copy content to
  5139. var newBuffer = isUint8Array(this.buffer) ? new Uint8Array(new ArrayBuffer(this.position)) : new Array(this.position); // Copy content
  5140. for (var i = 0; i < this.position; i++) {
  5141. newBuffer[i] = this.buffer[i];
  5142. } // Return the buffer
  5143. return newBuffer;
  5144. }
  5145. } else {
  5146. return convertArraytoUtf8BinaryString(this.buffer, 0, this.position);
  5147. }
  5148. }
  5149. }
  5150. /**
  5151. * Length.
  5152. *
  5153. * @method
  5154. * @return {number} the length of the binary.
  5155. */
  5156. }, {
  5157. key: "length",
  5158. value: function length() {
  5159. return this.position;
  5160. }
  5161. /**
  5162. * @ignore
  5163. */
  5164. }, {
  5165. key: "toJSON",
  5166. value: function toJSON() {
  5167. return this.buffer != null ? this.buffer.toString('base64') : '';
  5168. }
  5169. /**
  5170. * @ignore
  5171. */
  5172. }, {
  5173. key: "toString",
  5174. value: function toString(format) {
  5175. return this.buffer != null ? this.buffer.slice(0, this.position).toString(format) : '';
  5176. }
  5177. /**
  5178. * @ignore
  5179. */
  5180. }, {
  5181. key: "toExtendedJSON",
  5182. value: function toExtendedJSON() {
  5183. var base64String = Buffer.isBuffer(this.buffer) ? this.buffer.toString('base64') : Buffer.from(this.buffer).toString('base64');
  5184. var subType = Number(this.sub_type).toString(16);
  5185. return {
  5186. $binary: {
  5187. base64: base64String,
  5188. subType: subType.length === 1 ? '0' + subType : subType
  5189. }
  5190. };
  5191. }
  5192. /**
  5193. * @ignore
  5194. */
  5195. }], [{
  5196. key: "fromExtendedJSON",
  5197. value: function fromExtendedJSON(doc) {
  5198. var type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
  5199. var data = new Buffer(doc.$binary.base64, 'base64');
  5200. return new Binary(data, type);
  5201. }
  5202. }]);
  5203. return Binary;
  5204. }();
  5205. /**
  5206. * Binary default subtype
  5207. * @ignore
  5208. */
  5209. var BSON_BINARY_SUBTYPE_DEFAULT = 0;
  5210. function isUint8Array(obj) {
  5211. return Object.prototype.toString.call(obj) === '[object Uint8Array]';
  5212. }
  5213. /**
  5214. * @ignore
  5215. */
  5216. function writeStringToArray(data) {
  5217. // Create a buffer
  5218. var buffer = typeof Uint8Array !== 'undefined' ? new Uint8Array(new ArrayBuffer(data.length)) : new Array(data.length); // Write the content to the buffer
  5219. for (var i = 0; i < data.length; i++) {
  5220. buffer[i] = data.charCodeAt(i);
  5221. } // Write the string to the buffer
  5222. return buffer;
  5223. }
  5224. /**
  5225. * Convert Array ot Uint8Array to Binary String
  5226. *
  5227. * @ignore
  5228. */
  5229. function convertArraytoUtf8BinaryString(byteArray, startIndex, endIndex) {
  5230. var result = '';
  5231. for (var i = startIndex; i < endIndex; i++) {
  5232. result = result + String.fromCharCode(byteArray[i]);
  5233. }
  5234. return result;
  5235. }
  5236. Binary.BUFFER_SIZE = 256;
  5237. /**
  5238. * Default BSON type
  5239. *
  5240. * @classconstant SUBTYPE_DEFAULT
  5241. **/
  5242. Binary.SUBTYPE_DEFAULT = 0;
  5243. /**
  5244. * Function BSON type
  5245. *
  5246. * @classconstant SUBTYPE_DEFAULT
  5247. **/
  5248. Binary.SUBTYPE_FUNCTION = 1;
  5249. /**
  5250. * Byte Array BSON type
  5251. *
  5252. * @classconstant SUBTYPE_DEFAULT
  5253. **/
  5254. Binary.SUBTYPE_BYTE_ARRAY = 2;
  5255. /**
  5256. * OLD UUID BSON type
  5257. *
  5258. * @classconstant SUBTYPE_DEFAULT
  5259. **/
  5260. Binary.SUBTYPE_UUID_OLD = 3;
  5261. /**
  5262. * UUID BSON type
  5263. *
  5264. * @classconstant SUBTYPE_DEFAULT
  5265. **/
  5266. Binary.SUBTYPE_UUID = 4;
  5267. /**
  5268. * MD5 BSON type
  5269. *
  5270. * @classconstant SUBTYPE_DEFAULT
  5271. **/
  5272. Binary.SUBTYPE_MD5 = 5;
  5273. /**
  5274. * User BSON type
  5275. *
  5276. * @classconstant SUBTYPE_DEFAULT
  5277. **/
  5278. Binary.SUBTYPE_USER_DEFINED = 128;
  5279. Object.defineProperty(Binary.prototype, '_bsontype', {
  5280. value: 'Binary'
  5281. });
  5282. var binary = Binary;
  5283. var constants = {
  5284. // BSON MAX VALUES
  5285. BSON_INT32_MAX: 0x7fffffff,
  5286. BSON_INT32_MIN: -0x80000000,
  5287. BSON_INT64_MAX: Math.pow(2, 63) - 1,
  5288. BSON_INT64_MIN: -Math.pow(2, 63),
  5289. // JS MAX PRECISE VALUES
  5290. JS_INT_MAX: 0x20000000000000,
  5291. // Any integer up to 2^53 can be precisely represented by a double.
  5292. JS_INT_MIN: -0x20000000000000,
  5293. // Any integer down to -2^53 can be precisely represented by a double.
  5294. /**
  5295. * Number BSON Type
  5296. *
  5297. * @classconstant BSON_DATA_NUMBER
  5298. **/
  5299. BSON_DATA_NUMBER: 1,
  5300. /**
  5301. * String BSON Type
  5302. *
  5303. * @classconstant BSON_DATA_STRING
  5304. **/
  5305. BSON_DATA_STRING: 2,
  5306. /**
  5307. * Object BSON Type
  5308. *
  5309. * @classconstant BSON_DATA_OBJECT
  5310. **/
  5311. BSON_DATA_OBJECT: 3,
  5312. /**
  5313. * Array BSON Type
  5314. *
  5315. * @classconstant BSON_DATA_ARRAY
  5316. **/
  5317. BSON_DATA_ARRAY: 4,
  5318. /**
  5319. * Binary BSON Type
  5320. *
  5321. * @classconstant BSON_DATA_BINARY
  5322. **/
  5323. BSON_DATA_BINARY: 5,
  5324. /**
  5325. * Binary BSON Type
  5326. *
  5327. * @classconstant BSON_DATA_UNDEFINED
  5328. **/
  5329. BSON_DATA_UNDEFINED: 6,
  5330. /**
  5331. * ObjectId BSON Type
  5332. *
  5333. * @classconstant BSON_DATA_OID
  5334. **/
  5335. BSON_DATA_OID: 7,
  5336. /**
  5337. * Boolean BSON Type
  5338. *
  5339. * @classconstant BSON_DATA_BOOLEAN
  5340. **/
  5341. BSON_DATA_BOOLEAN: 8,
  5342. /**
  5343. * Date BSON Type
  5344. *
  5345. * @classconstant BSON_DATA_DATE
  5346. **/
  5347. BSON_DATA_DATE: 9,
  5348. /**
  5349. * null BSON Type
  5350. *
  5351. * @classconstant BSON_DATA_NULL
  5352. **/
  5353. BSON_DATA_NULL: 10,
  5354. /**
  5355. * RegExp BSON Type
  5356. *
  5357. * @classconstant BSON_DATA_REGEXP
  5358. **/
  5359. BSON_DATA_REGEXP: 11,
  5360. /**
  5361. * Code BSON Type
  5362. *
  5363. * @classconstant BSON_DATA_DBPOINTER
  5364. **/
  5365. BSON_DATA_DBPOINTER: 12,
  5366. /**
  5367. * Code BSON Type
  5368. *
  5369. * @classconstant BSON_DATA_CODE
  5370. **/
  5371. BSON_DATA_CODE: 13,
  5372. /**
  5373. * Symbol BSON Type
  5374. *
  5375. * @classconstant BSON_DATA_SYMBOL
  5376. **/
  5377. BSON_DATA_SYMBOL: 14,
  5378. /**
  5379. * Code with Scope BSON Type
  5380. *
  5381. * @classconstant BSON_DATA_CODE_W_SCOPE
  5382. **/
  5383. BSON_DATA_CODE_W_SCOPE: 15,
  5384. /**
  5385. * 32 bit Integer BSON Type
  5386. *
  5387. * @classconstant BSON_DATA_INT
  5388. **/
  5389. BSON_DATA_INT: 16,
  5390. /**
  5391. * Timestamp BSON Type
  5392. *
  5393. * @classconstant BSON_DATA_TIMESTAMP
  5394. **/
  5395. BSON_DATA_TIMESTAMP: 17,
  5396. /**
  5397. * Long BSON Type
  5398. *
  5399. * @classconstant BSON_DATA_LONG
  5400. **/
  5401. BSON_DATA_LONG: 18,
  5402. /**
  5403. * Long BSON Type
  5404. *
  5405. * @classconstant BSON_DATA_DECIMAL128
  5406. **/
  5407. BSON_DATA_DECIMAL128: 19,
  5408. /**
  5409. * MinKey BSON Type
  5410. *
  5411. * @classconstant BSON_DATA_MIN_KEY
  5412. **/
  5413. BSON_DATA_MIN_KEY: 0xff,
  5414. /**
  5415. * MaxKey BSON Type
  5416. *
  5417. * @classconstant BSON_DATA_MAX_KEY
  5418. **/
  5419. BSON_DATA_MAX_KEY: 0x7f,
  5420. /**
  5421. * Binary Default Type
  5422. *
  5423. * @classconstant BSON_BINARY_SUBTYPE_DEFAULT
  5424. **/
  5425. BSON_BINARY_SUBTYPE_DEFAULT: 0,
  5426. /**
  5427. * Binary Function Type
  5428. *
  5429. * @classconstant BSON_BINARY_SUBTYPE_FUNCTION
  5430. **/
  5431. BSON_BINARY_SUBTYPE_FUNCTION: 1,
  5432. /**
  5433. * Binary Byte Array Type
  5434. *
  5435. * @classconstant BSON_BINARY_SUBTYPE_BYTE_ARRAY
  5436. **/
  5437. BSON_BINARY_SUBTYPE_BYTE_ARRAY: 2,
  5438. /**
  5439. * Binary UUID Type
  5440. *
  5441. * @classconstant BSON_BINARY_SUBTYPE_UUID
  5442. **/
  5443. BSON_BINARY_SUBTYPE_UUID: 3,
  5444. /**
  5445. * Binary MD5 Type
  5446. *
  5447. * @classconstant BSON_BINARY_SUBTYPE_MD5
  5448. **/
  5449. BSON_BINARY_SUBTYPE_MD5: 4,
  5450. /**
  5451. * Binary User Defined Type
  5452. *
  5453. * @classconstant BSON_BINARY_SUBTYPE_USER_DEFINED
  5454. **/
  5455. BSON_BINARY_SUBTYPE_USER_DEFINED: 128
  5456. };
  5457. // const Map = require('./map');
  5458. /**
  5459. * @namespace EJSON
  5460. */
  5461. // all the types where we don't need to do any special processing and can just pass the EJSON
  5462. //straight to type.fromExtendedJSON
  5463. var keysToCodecs = {
  5464. $oid: objectid,
  5465. $binary: binary,
  5466. $symbol: symbol,
  5467. $numberInt: int_32,
  5468. $numberDecimal: decimal128,
  5469. $numberDouble: double_1,
  5470. $numberLong: long_1$1,
  5471. $minKey: min_key,
  5472. $maxKey: max_key,
  5473. $regularExpression: regexp,
  5474. $timestamp: timestamp
  5475. };
  5476. function deserializeValue(self, key, value, options) {
  5477. if (typeof value === 'number') {
  5478. if (options.relaxed) {
  5479. return value;
  5480. } // if it's an integer, should interpret as smallest BSON integer
  5481. // that can represent it exactly. (if out of range, interpret as double.)
  5482. if (Math.floor(value) === value) {
  5483. if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) return new int_32(value);
  5484. if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) return new long_1$1.fromNumber(value);
  5485. } // If the number is a non-integer or out of integer range, should interpret as BSON Double.
  5486. return new double_1(value);
  5487. } // from here on out we're looking for bson types, so bail if its not an object
  5488. if (value == null || _typeof(value) !== 'object') return value; // upgrade deprecated undefined to null
  5489. if (value.$undefined) return null;
  5490. var keys = Object.keys(value).filter(function (k) {
  5491. return k.startsWith('$') && value[k] != null;
  5492. });
  5493. for (var i = 0; i < keys.length; i++) {
  5494. var c = keysToCodecs[keys[i]];
  5495. if (c) return c.fromExtendedJSON(value, options);
  5496. }
  5497. if (value.$date != null) {
  5498. var d = value.$date;
  5499. var date = new Date();
  5500. if (typeof d === 'string') date.setTime(Date.parse(d));else if (d instanceof long_1$1) date.setTime(d.toNumber());else if (typeof d === 'number' && options.relaxed) date.setTime(d);
  5501. return date;
  5502. }
  5503. if (value.$code != null) {
  5504. var copy = Object.assign({}, value);
  5505. if (value.$scope) {
  5506. copy.$scope = deserializeValue(self, null, value.$scope);
  5507. }
  5508. return code$1.fromExtendedJSON(value);
  5509. }
  5510. if (value.$ref != null || value.$dbPointer != null) {
  5511. var v = value.$ref ? value : value.$dbPointer; // we run into this in a "degenerate EJSON" case (with $id and $ref order flipped)
  5512. // because of the order JSON.parse goes through the document
  5513. if (v instanceof db_ref) return v;
  5514. var dollarKeys = Object.keys(v).filter(function (k) {
  5515. return k.startsWith('$');
  5516. });
  5517. var valid = true;
  5518. dollarKeys.forEach(function (k) {
  5519. if (['$ref', '$id', '$db'].indexOf(k) === -1) valid = false;
  5520. }); // only make DBRef if $ keys are all valid
  5521. if (valid) return db_ref.fromExtendedJSON(v);
  5522. }
  5523. return value;
  5524. }
  5525. /**
  5526. * Parse an Extended JSON string, constructing the JavaScript value or object described by that
  5527. * string.
  5528. *
  5529. * @memberof EJSON
  5530. * @param {string} text
  5531. * @param {object} [options] Optional settings
  5532. * @param {boolean} [options.relaxed=true] Attempt to return native JS types where possible, rather than BSON types (if true)
  5533. * @return {object}
  5534. *
  5535. * @example
  5536. * const { EJSON } = require('bson');
  5537. * const text = '{ "int32": { "$numberInt": "10" } }';
  5538. *
  5539. * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
  5540. * console.log(EJSON.parse(text, { relaxed: false }));
  5541. *
  5542. * // prints { int32: 10 }
  5543. * console.log(EJSON.parse(text));
  5544. */
  5545. function parse(text, options) {
  5546. var _this = this;
  5547. options = Object.assign({}, {
  5548. relaxed: true
  5549. }, options); // relaxed implies not strict
  5550. if (typeof options.relaxed === 'boolean') options.strict = !options.relaxed;
  5551. if (typeof options.strict === 'boolean') options.relaxed = !options.strict;
  5552. return JSON.parse(text, function (key, value) {
  5553. return deserializeValue(_this, key, value, options);
  5554. });
  5555. } //
  5556. // Serializer
  5557. //
  5558. // MAX INT32 boundaries
  5559. var BSON_INT32_MAX = 0x7fffffff,
  5560. BSON_INT32_MIN = -0x80000000,
  5561. BSON_INT64_MAX = 0x7fffffffffffffff,
  5562. BSON_INT64_MIN = -0x8000000000000000;
  5563. /**
  5564. * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
  5565. * function is specified or optionally including only the specified properties if a replacer array
  5566. * is specified.
  5567. *
  5568. * @memberof EJSON
  5569. * @param {object} value The value to convert to extended JSON
  5570. * @param {function|array} [replacer] A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
  5571. * @param {string|number} [space] A String or Number object that's used to insert white space into the output JSON string for readability purposes.
  5572. * @param {object} [options] Optional settings
  5573. * @param {boolean} [options.relaxed=true] Enabled Extended JSON's `relaxed` mode
  5574. * @returns {string}
  5575. *
  5576. * @example
  5577. * const { EJSON } = require('bson');
  5578. * const Int32 = require('mongodb').Int32;
  5579. * const doc = { int32: new Int32(10) };
  5580. *
  5581. * // prints '{"int32":{"$numberInt":"10"}}'
  5582. * console.log(EJSON.stringify(doc, { relaxed: false }));
  5583. *
  5584. * // prints '{"int32":10}'
  5585. * console.log(EJSON.stringify(doc));
  5586. */
  5587. function stringify(value, replacer, space, options) {
  5588. if (space != null && _typeof(space) === 'object') options = space, space = 0;
  5589. if (replacer != null && _typeof(replacer) === 'object') options = replacer, replacer = null, space = 0;
  5590. options = Object.assign({}, {
  5591. relaxed: true
  5592. }, options);
  5593. var doc = Array.isArray(value) ? serializeArray(value, options) : serializeDocument(value, options);
  5594. return JSON.stringify(doc, replacer, space);
  5595. }
  5596. /**
  5597. * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
  5598. *
  5599. * @memberof EJSON
  5600. * @param {object} bson The object to serialize
  5601. * @param {object} [options] Optional settings passed to the `stringify` function
  5602. * @return {object}
  5603. */
  5604. function serialize(bson, options) {
  5605. options = options || {};
  5606. return JSON.parse(stringify(bson, options));
  5607. }
  5608. /**
  5609. * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
  5610. *
  5611. * @memberof EJSON
  5612. * @param {object} ejson The Extended JSON object to deserialize
  5613. * @param {object} [options] Optional settings passed to the parse method
  5614. * @return {object}
  5615. */
  5616. function deserialize(ejson, options) {
  5617. options = options || {};
  5618. return parse(JSON.stringify(ejson), options);
  5619. }
  5620. function serializeArray(array, options) {
  5621. return array.map(function (v) {
  5622. return serializeValue(v, options);
  5623. });
  5624. }
  5625. function getISOString(date) {
  5626. var isoStr = date.toISOString(); // we should only show milliseconds in timestamp if they're non-zero
  5627. return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
  5628. }
  5629. function serializeValue(value, options) {
  5630. if (Array.isArray(value)) return serializeArray(value, options);
  5631. if (value === undefined) return null;
  5632. if (value instanceof Date) {
  5633. var dateNum = value.getTime(),
  5634. // is it in year range 1970-9999?
  5635. inRange = dateNum > -1 && dateNum < 253402318800000;
  5636. return options.relaxed && inRange ? {
  5637. $date: getISOString(value)
  5638. } : {
  5639. $date: {
  5640. $numberLong: value.getTime().toString()
  5641. }
  5642. };
  5643. }
  5644. if (typeof value === 'number' && !options.relaxed) {
  5645. // it's an integer
  5646. if (Math.floor(value) === value) {
  5647. var int32Range = value >= BSON_INT32_MIN && value <= BSON_INT32_MAX,
  5648. int64Range = value >= BSON_INT64_MIN && value <= BSON_INT64_MAX; // interpret as being of the smallest BSON integer type that can represent the number exactly
  5649. if (int32Range) return {
  5650. $numberInt: value.toString()
  5651. };
  5652. if (int64Range) return {
  5653. $numberLong: value.toString()
  5654. };
  5655. }
  5656. return {
  5657. $numberDouble: value.toString()
  5658. };
  5659. }
  5660. if (value != null && _typeof(value) === 'object') return serializeDocument(value, options);
  5661. return value;
  5662. }
  5663. function serializeDocument(doc, options) {
  5664. if (doc == null || _typeof(doc) !== 'object') throw new Error('not an object instance'); // the document itself is a BSON type
  5665. if (doc._bsontype && typeof doc.toExtendedJSON === 'function') {
  5666. if (doc._bsontype === 'Code' && doc.scope) {
  5667. doc.scope = serializeDocument(doc.scope, options);
  5668. } else if (doc._bsontype === 'DBRef' && doc.oid) {
  5669. doc.oid = serializeDocument(doc.oid, options);
  5670. }
  5671. return doc.toExtendedJSON(options);
  5672. } // the document is an object with nested BSON types
  5673. var _doc = {};
  5674. for (var name in doc) {
  5675. var val = doc[name];
  5676. if (Array.isArray(val)) {
  5677. _doc[name] = serializeArray(val, options);
  5678. } else if (val != null && typeof val.toExtendedJSON === 'function') {
  5679. if (val._bsontype === 'Code' && val.scope) {
  5680. val.scope = serializeDocument(val.scope, options);
  5681. } else if (val._bsontype === 'DBRef' && val.oid) {
  5682. val.oid = serializeDocument(val.oid, options);
  5683. }
  5684. _doc[name] = val.toExtendedJSON(options);
  5685. } else if (val instanceof Date) {
  5686. _doc[name] = serializeValue(val, options);
  5687. } else if (val != null && _typeof(val) === 'object') {
  5688. _doc[name] = serializeDocument(val, options);
  5689. }
  5690. _doc[name] = serializeValue(val, options);
  5691. if (val instanceof RegExp) {
  5692. var flags = val.flags;
  5693. if (flags === undefined) {
  5694. flags = val.toString().match(/[gimuy]*$/)[0];
  5695. }
  5696. var rx = new regexp(val.source, flags);
  5697. _doc[name] = rx.toExtendedJSON();
  5698. }
  5699. }
  5700. return _doc;
  5701. }
  5702. var extended_json = {
  5703. parse: parse,
  5704. deserialize: deserialize,
  5705. serialize: serialize,
  5706. stringify: stringify
  5707. };
  5708. var FIRST_BIT = 0x80;
  5709. var FIRST_TWO_BITS = 0xc0;
  5710. var FIRST_THREE_BITS = 0xe0;
  5711. var FIRST_FOUR_BITS = 0xf0;
  5712. var FIRST_FIVE_BITS = 0xf8;
  5713. var TWO_BIT_CHAR = 0xc0;
  5714. var THREE_BIT_CHAR = 0xe0;
  5715. var FOUR_BIT_CHAR = 0xf0;
  5716. var CONTINUING_CHAR = 0x80;
  5717. /**
  5718. * Determines if the passed in bytes are valid utf8
  5719. * @param {Buffer|Uint8Array} bytes An array of 8-bit bytes. Must be indexable and have length property
  5720. * @param {Number} start The index to start validating
  5721. * @param {Number} end The index to end validating
  5722. * @returns {boolean} True if valid utf8
  5723. */
  5724. function validateUtf8(bytes, start, end) {
  5725. var continuation = 0;
  5726. for (var i = start; i < end; i += 1) {
  5727. var byte = bytes[i];
  5728. if (continuation) {
  5729. if ((byte & FIRST_TWO_BITS) !== CONTINUING_CHAR) {
  5730. return false;
  5731. }
  5732. continuation -= 1;
  5733. } else if (byte & FIRST_BIT) {
  5734. if ((byte & FIRST_THREE_BITS) === TWO_BIT_CHAR) {
  5735. continuation = 1;
  5736. } else if ((byte & FIRST_FOUR_BITS) === THREE_BIT_CHAR) {
  5737. continuation = 2;
  5738. } else if ((byte & FIRST_FIVE_BITS) === FOUR_BIT_CHAR) {
  5739. continuation = 3;
  5740. } else {
  5741. return false;
  5742. }
  5743. }
  5744. }
  5745. return !continuation;
  5746. }
  5747. var validateUtf8_1 = validateUtf8;
  5748. var validate_utf8 = {
  5749. validateUtf8: validateUtf8_1
  5750. };
  5751. var Buffer$2 = buffer.Buffer;
  5752. var validateUtf8$1 = validate_utf8.validateUtf8; // Internal long versions
  5753. var JS_INT_MAX_LONG = long_1$1.fromNumber(constants.JS_INT_MAX);
  5754. var JS_INT_MIN_LONG = long_1$1.fromNumber(constants.JS_INT_MIN);
  5755. var functionCache = {};
  5756. function deserialize$1(buffer$$1, options, isArray) {
  5757. options = options == null ? {} : options;
  5758. var index = options && options.index ? options.index : 0; // Read the document size
  5759. var size = buffer$$1[index] | buffer$$1[index + 1] << 8 | buffer$$1[index + 2] << 16 | buffer$$1[index + 3] << 24;
  5760. if (size < 5) {
  5761. throw new Error("bson size must be >= 5, is ".concat(size));
  5762. }
  5763. if (options.allowObjectSmallerThanBufferSize && buffer$$1.length < size) {
  5764. throw new Error("buffer length ".concat(buffer$$1.length, " must be >= bson size ").concat(size));
  5765. }
  5766. if (!options.allowObjectSmallerThanBufferSize && buffer$$1.length !== size) {
  5767. throw new Error("buffer length ".concat(buffer$$1.length, " must === bson size ").concat(size));
  5768. }
  5769. if (size + index > buffer$$1.length) {
  5770. throw new Error("(bson size ".concat(size, " + options.index ").concat(index, " must be <= buffer length ").concat(Buffer$2.byteLength(buffer$$1), ")"));
  5771. } // Illegal end value
  5772. if (buffer$$1[index + size - 1] !== 0) {
  5773. throw new Error("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
  5774. } // Start deserializtion
  5775. return deserializeObject(buffer$$1, index, options, isArray);
  5776. }
  5777. function deserializeObject(buffer$$1, index, options, isArray) {
  5778. var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions'];
  5779. var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions'];
  5780. var cacheFunctionsCrc32 = options['cacheFunctionsCrc32'] == null ? false : options['cacheFunctionsCrc32'];
  5781. if (!cacheFunctionsCrc32) var crc32 = null;
  5782. var fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; // Return raw bson buffer instead of parsing it
  5783. var raw = options['raw'] == null ? false : options['raw']; // Return BSONRegExp objects instead of native regular expressions
  5784. var bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; // Controls the promotion of values vs wrapper classes
  5785. var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers'];
  5786. var promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs'];
  5787. var promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; // Set the start index
  5788. var startIndex = index; // Validate that we have at least 4 bytes of buffer
  5789. if (buffer$$1.length < 5) throw new Error('corrupt bson message < 5 bytes long'); // Read the document size
  5790. var size = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24; // Ensure buffer is valid size
  5791. if (size < 5 || size > buffer$$1.length) throw new Error('corrupt bson message'); // Create holding object
  5792. var object = isArray ? [] : {}; // Used for arrays to skip having to perform utf8 decoding
  5793. var arrayIndex = 0;
  5794. var done = false; // While we have more left data left keep parsing
  5795. while (!done) {
  5796. // Read the type
  5797. var elementType = buffer$$1[index++]; // If we get a zero it's the last byte, exit
  5798. if (elementType === 0) break; // Get the start search index
  5799. var i = index; // Locate the end of the c string
  5800. while (buffer$$1[i] !== 0x00 && i < buffer$$1.length) {
  5801. i++;
  5802. } // If are at the end of the buffer there is a problem with the document
  5803. if (i >= Buffer$2.byteLength(buffer$$1)) throw new Error('Bad BSON Document: illegal CString');
  5804. var name = isArray ? arrayIndex++ : buffer$$1.toString('utf8', index, i);
  5805. index = i + 1;
  5806. if (elementType === constants.BSON_DATA_STRING) {
  5807. var stringSize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5808. if (stringSize <= 0 || stringSize > buffer$$1.length - index || buffer$$1[index + stringSize - 1] !== 0) throw new Error('bad string length in bson');
  5809. if (!validateUtf8$1(buffer$$1, index, index + stringSize - 1)) {
  5810. throw new Error('Invalid UTF-8 string in BSON document');
  5811. }
  5812. var s = buffer$$1.toString('utf8', index, index + stringSize - 1);
  5813. object[name] = s;
  5814. index = index + stringSize;
  5815. } else if (elementType === constants.BSON_DATA_OID) {
  5816. var oid = Buffer$2.alloc(12);
  5817. buffer$$1.copy(oid, 0, index, index + 12);
  5818. object[name] = new objectid(oid);
  5819. index = index + 12;
  5820. } else if (elementType === constants.BSON_DATA_INT && promoteValues === false) {
  5821. object[name] = new int_32(buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24);
  5822. } else if (elementType === constants.BSON_DATA_INT) {
  5823. object[name] = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5824. } else if (elementType === constants.BSON_DATA_NUMBER && promoteValues === false) {
  5825. object[name] = new double_1(buffer$$1.readDoubleLE(index));
  5826. index = index + 8;
  5827. } else if (elementType === constants.BSON_DATA_NUMBER) {
  5828. object[name] = buffer$$1.readDoubleLE(index);
  5829. index = index + 8;
  5830. } else if (elementType === constants.BSON_DATA_DATE) {
  5831. var lowBits = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5832. var highBits = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5833. object[name] = new Date(new long_1$1(lowBits, highBits).toNumber());
  5834. } else if (elementType === constants.BSON_DATA_BOOLEAN) {
  5835. if (buffer$$1[index] !== 0 && buffer$$1[index] !== 1) throw new Error('illegal boolean type value');
  5836. object[name] = buffer$$1[index++] === 1;
  5837. } else if (elementType === constants.BSON_DATA_OBJECT) {
  5838. var _index = index;
  5839. var objectSize = buffer$$1[index] | buffer$$1[index + 1] << 8 | buffer$$1[index + 2] << 16 | buffer$$1[index + 3] << 24;
  5840. if (objectSize <= 0 || objectSize > buffer$$1.length - index) throw new Error('bad embedded document length in bson'); // We have a raw value
  5841. if (raw) {
  5842. object[name] = buffer$$1.slice(index, index + objectSize);
  5843. } else {
  5844. object[name] = deserializeObject(buffer$$1, _index, options, false);
  5845. }
  5846. index = index + objectSize;
  5847. } else if (elementType === constants.BSON_DATA_ARRAY) {
  5848. var _index2 = index;
  5849. var _objectSize = buffer$$1[index] | buffer$$1[index + 1] << 8 | buffer$$1[index + 2] << 16 | buffer$$1[index + 3] << 24;
  5850. var arrayOptions = options; // Stop index
  5851. var stopIndex = index + _objectSize; // All elements of array to be returned as raw bson
  5852. if (fieldsAsRaw && fieldsAsRaw[name]) {
  5853. arrayOptions = {};
  5854. for (var n in options) {
  5855. arrayOptions[n] = options[n];
  5856. }
  5857. arrayOptions['raw'] = true;
  5858. }
  5859. object[name] = deserializeObject(buffer$$1, _index2, arrayOptions, true);
  5860. index = index + _objectSize;
  5861. if (buffer$$1[index - 1] !== 0) throw new Error('invalid array terminator byte');
  5862. if (index !== stopIndex) throw new Error('corrupted array bson');
  5863. } else if (elementType === constants.BSON_DATA_UNDEFINED) {
  5864. object[name] = undefined;
  5865. } else if (elementType === constants.BSON_DATA_NULL) {
  5866. object[name] = null;
  5867. } else if (elementType === constants.BSON_DATA_LONG) {
  5868. // Unpack the low and high bits
  5869. var _lowBits = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5870. var _highBits = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5871. var long = new long_1$1(_lowBits, _highBits); // Promote the long if possible
  5872. if (promoteLongs && promoteValues === true) {
  5873. object[name] = long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG) ? long.toNumber() : long;
  5874. } else {
  5875. object[name] = long;
  5876. }
  5877. } else if (elementType === constants.BSON_DATA_DECIMAL128) {
  5878. // Buffer to contain the decimal bytes
  5879. var bytes = Buffer$2.alloc(16); // Copy the next 16 bytes into the bytes buffer
  5880. buffer$$1.copy(bytes, 0, index, index + 16); // Update index
  5881. index = index + 16; // Assign the new Decimal128 value
  5882. var decimal128$$1 = new decimal128(bytes); // If we have an alternative mapper use that
  5883. object[name] = decimal128$$1.toObject ? decimal128$$1.toObject() : decimal128$$1;
  5884. } else if (elementType === constants.BSON_DATA_BINARY) {
  5885. var binarySize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5886. var totalBinarySize = binarySize;
  5887. var subType = buffer$$1[index++]; // Did we have a negative binary size, throw
  5888. if (binarySize < 0) throw new Error('Negative binary type element size found'); // Is the length longer than the document
  5889. if (binarySize > Buffer$2.byteLength(buffer$$1)) throw new Error('Binary type size larger than document size'); // Decode as raw Buffer object if options specifies it
  5890. if (buffer$$1['slice'] != null) {
  5891. // If we have subtype 2 skip the 4 bytes for the size
  5892. if (subType === binary.SUBTYPE_BYTE_ARRAY) {
  5893. binarySize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5894. if (binarySize < 0) throw new Error('Negative binary type element size found for subtype 0x02');
  5895. if (binarySize > totalBinarySize - 4) throw new Error('Binary type with subtype 0x02 contains to long binary size');
  5896. if (binarySize < totalBinarySize - 4) throw new Error('Binary type with subtype 0x02 contains to short binary size');
  5897. }
  5898. if (promoteBuffers && promoteValues) {
  5899. object[name] = buffer$$1.slice(index, index + binarySize);
  5900. } else {
  5901. object[name] = new binary(buffer$$1.slice(index, index + binarySize), subType);
  5902. }
  5903. } else {
  5904. var _buffer = typeof Uint8Array !== 'undefined' ? new Uint8Array(new ArrayBuffer(binarySize)) : new Array(binarySize); // If we have subtype 2 skip the 4 bytes for the size
  5905. if (subType === binary.SUBTYPE_BYTE_ARRAY) {
  5906. binarySize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5907. if (binarySize < 0) throw new Error('Negative binary type element size found for subtype 0x02');
  5908. if (binarySize > totalBinarySize - 4) throw new Error('Binary type with subtype 0x02 contains to long binary size');
  5909. if (binarySize < totalBinarySize - 4) throw new Error('Binary type with subtype 0x02 contains to short binary size');
  5910. } // Copy the data
  5911. for (i = 0; i < binarySize; i++) {
  5912. _buffer[i] = buffer$$1[index + i];
  5913. }
  5914. if (promoteBuffers && promoteValues) {
  5915. object[name] = _buffer;
  5916. } else {
  5917. object[name] = new binary(_buffer, subType);
  5918. }
  5919. } // Update the index
  5920. index = index + binarySize;
  5921. } else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === false) {
  5922. // Get the start search index
  5923. i = index; // Locate the end of the c string
  5924. while (buffer$$1[i] !== 0x00 && i < buffer$$1.length) {
  5925. i++;
  5926. } // If are at the end of the buffer there is a problem with the document
  5927. if (i >= buffer$$1.length) throw new Error('Bad BSON Document: illegal CString'); // Return the C string
  5928. var source = buffer$$1.toString('utf8', index, i); // Create the regexp
  5929. index = i + 1; // Get the start search index
  5930. i = index; // Locate the end of the c string
  5931. while (buffer$$1[i] !== 0x00 && i < buffer$$1.length) {
  5932. i++;
  5933. } // If are at the end of the buffer there is a problem with the document
  5934. if (i >= buffer$$1.length) throw new Error('Bad BSON Document: illegal CString'); // Return the C string
  5935. var regExpOptions = buffer$$1.toString('utf8', index, i);
  5936. index = i + 1; // For each option add the corresponding one for javascript
  5937. var optionsArray = new Array(regExpOptions.length); // Parse options
  5938. for (i = 0; i < regExpOptions.length; i++) {
  5939. switch (regExpOptions[i]) {
  5940. case 'm':
  5941. optionsArray[i] = 'm';
  5942. break;
  5943. case 's':
  5944. optionsArray[i] = 'g';
  5945. break;
  5946. case 'i':
  5947. optionsArray[i] = 'i';
  5948. break;
  5949. }
  5950. }
  5951. object[name] = new RegExp(source, optionsArray.join(''));
  5952. } else if (elementType === constants.BSON_DATA_REGEXP && bsonRegExp === true) {
  5953. // Get the start search index
  5954. i = index; // Locate the end of the c string
  5955. while (buffer$$1[i] !== 0x00 && i < buffer$$1.length) {
  5956. i++;
  5957. } // If are at the end of the buffer there is a problem with the document
  5958. if (i >= buffer$$1.length) throw new Error('Bad BSON Document: illegal CString'); // Return the C string
  5959. var _source = buffer$$1.toString('utf8', index, i);
  5960. index = i + 1; // Get the start search index
  5961. i = index; // Locate the end of the c string
  5962. while (buffer$$1[i] !== 0x00 && i < buffer$$1.length) {
  5963. i++;
  5964. } // If are at the end of the buffer there is a problem with the document
  5965. if (i >= buffer$$1.length) throw new Error('Bad BSON Document: illegal CString'); // Return the C string
  5966. var _regExpOptions = buffer$$1.toString('utf8', index, i);
  5967. index = i + 1; // Set the object
  5968. object[name] = new regexp(_source, _regExpOptions);
  5969. } else if (elementType === constants.BSON_DATA_SYMBOL) {
  5970. var _stringSize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5971. if (_stringSize <= 0 || _stringSize > buffer$$1.length - index || buffer$$1[index + _stringSize - 1] !== 0) throw new Error('bad string length in bson'); // symbol is deprecated - upgrade to string.
  5972. object[name] = buffer$$1.toString('utf8', index, index + _stringSize - 1);
  5973. index = index + _stringSize;
  5974. } else if (elementType === constants.BSON_DATA_TIMESTAMP) {
  5975. var _lowBits2 = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5976. var _highBits2 = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5977. object[name] = new timestamp(_lowBits2, _highBits2);
  5978. } else if (elementType === constants.BSON_DATA_MIN_KEY) {
  5979. object[name] = new min_key();
  5980. } else if (elementType === constants.BSON_DATA_MAX_KEY) {
  5981. object[name] = new max_key();
  5982. } else if (elementType === constants.BSON_DATA_CODE) {
  5983. var _stringSize2 = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24;
  5984. if (_stringSize2 <= 0 || _stringSize2 > buffer$$1.length - index || buffer$$1[index + _stringSize2 - 1] !== 0) throw new Error('bad string length in bson');
  5985. var functionString = buffer$$1.toString('utf8', index, index + _stringSize2 - 1); // If we are evaluating the functions
  5986. if (evalFunctions) {
  5987. // If we have cache enabled let's look for the md5 of the function in the cache
  5988. if (cacheFunctions) {
  5989. var hash = cacheFunctionsCrc32 ? crc32(functionString) : functionString; // Got to do this to avoid V8 deoptimizing the call due to finding eval
  5990. object[name] = isolateEvalWithHash(functionCache, hash, functionString, object);
  5991. } else {
  5992. object[name] = isolateEval(functionString);
  5993. }
  5994. } else {
  5995. object[name] = new code$1(functionString);
  5996. } // Update parse index position
  5997. index = index + _stringSize2;
  5998. } else if (elementType === constants.BSON_DATA_CODE_W_SCOPE) {
  5999. var totalSize = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24; // Element cannot be shorter than totalSize + stringSize + documentSize + terminator
  6000. if (totalSize < 4 + 4 + 4 + 1) {
  6001. throw new Error('code_w_scope total size shorter minimum expected length');
  6002. } // Get the code string size
  6003. var _stringSize3 = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24; // Check if we have a valid string
  6004. if (_stringSize3 <= 0 || _stringSize3 > buffer$$1.length - index || buffer$$1[index + _stringSize3 - 1] !== 0) throw new Error('bad string length in bson'); // Javascript function
  6005. var _functionString = buffer$$1.toString('utf8', index, index + _stringSize3 - 1); // Update parse index position
  6006. index = index + _stringSize3; // Parse the element
  6007. var _index3 = index; // Decode the size of the object document
  6008. var _objectSize2 = buffer$$1[index] | buffer$$1[index + 1] << 8 | buffer$$1[index + 2] << 16 | buffer$$1[index + 3] << 24; // Decode the scope object
  6009. var scopeObject = deserializeObject(buffer$$1, _index3, options, false); // Adjust the index
  6010. index = index + _objectSize2; // Check if field length is to short
  6011. if (totalSize < 4 + 4 + _objectSize2 + _stringSize3) {
  6012. throw new Error('code_w_scope total size is to short, truncating scope');
  6013. } // Check if totalSize field is to long
  6014. if (totalSize > 4 + 4 + _objectSize2 + _stringSize3) {
  6015. throw new Error('code_w_scope total size is to long, clips outer document');
  6016. } // If we are evaluating the functions
  6017. if (evalFunctions) {
  6018. // If we have cache enabled let's look for the md5 of the function in the cache
  6019. if (cacheFunctions) {
  6020. var _hash = cacheFunctionsCrc32 ? crc32(_functionString) : _functionString; // Got to do this to avoid V8 deoptimizing the call due to finding eval
  6021. object[name] = isolateEvalWithHash(functionCache, _hash, _functionString, object);
  6022. } else {
  6023. object[name] = isolateEval(_functionString);
  6024. }
  6025. object[name].scope = scopeObject;
  6026. } else {
  6027. object[name] = new code$1(_functionString, scopeObject);
  6028. }
  6029. } else if (elementType === constants.BSON_DATA_DBPOINTER) {
  6030. // Get the code string size
  6031. var _stringSize4 = buffer$$1[index++] | buffer$$1[index++] << 8 | buffer$$1[index++] << 16 | buffer$$1[index++] << 24; // Check if we have a valid string
  6032. if (_stringSize4 <= 0 || _stringSize4 > buffer$$1.length - index || buffer$$1[index + _stringSize4 - 1] !== 0) throw new Error('bad string length in bson'); // Namespace
  6033. if (!validateUtf8$1(buffer$$1, index, index + _stringSize4 - 1)) {
  6034. throw new Error('Invalid UTF-8 string in BSON document');
  6035. }
  6036. var namespace = buffer$$1.toString('utf8', index, index + _stringSize4 - 1); // Update parse index position
  6037. index = index + _stringSize4; // Read the oid
  6038. var oidBuffer = Buffer$2.alloc(12);
  6039. buffer$$1.copy(oidBuffer, 0, index, index + 12);
  6040. var _oid = new objectid(oidBuffer); // Update the index
  6041. index = index + 12; // Upgrade to DBRef type
  6042. object[name] = new db_ref(namespace, _oid);
  6043. } else {
  6044. throw new Error('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '", are you using the latest BSON parser?');
  6045. }
  6046. } // Check if the deserialization was against a valid array/object
  6047. if (size !== index - startIndex) {
  6048. if (isArray) throw new Error('corrupt array bson');
  6049. throw new Error('corrupt object bson');
  6050. } // check if object's $ keys are those of a DBRef
  6051. var dollarKeys = Object.keys(object).filter(function (k) {
  6052. return k.startsWith('$');
  6053. });
  6054. var valid = true;
  6055. dollarKeys.forEach(function (k) {
  6056. if (['$ref', '$id', '$db'].indexOf(k) === -1) valid = false;
  6057. }); // if a $key not in "$ref", "$id", "$db", don't make a DBRef
  6058. if (!valid) return object;
  6059. if (object['$id'] != null && object['$ref'] != null) {
  6060. var copy = Object.assign({}, object);
  6061. delete copy.$ref;
  6062. delete copy.$id;
  6063. delete copy.$db;
  6064. return new db_ref(object.$ref, object.$id, object.$db || null, copy);
  6065. }
  6066. return object;
  6067. }
  6068. /**
  6069. * Ensure eval is isolated.
  6070. *
  6071. * @ignore
  6072. * @api private
  6073. */
  6074. function isolateEvalWithHash(functionCache, hash, functionString, object) {
  6075. // Contains the value we are going to set
  6076. var value = null; // Check for cache hit, eval if missing and return cached function
  6077. if (functionCache[hash] == null) {
  6078. eval('value = ' + functionString);
  6079. functionCache[hash] = value;
  6080. } // Set the object
  6081. return functionCache[hash].bind(object);
  6082. }
  6083. /**
  6084. * Ensure eval is isolated.
  6085. *
  6086. * @ignore
  6087. * @api private
  6088. */
  6089. function isolateEval(functionString) {
  6090. // Contains the value we are going to set
  6091. var value = null; // Eval the function
  6092. eval('value = ' + functionString);
  6093. return value;
  6094. }
  6095. var deserializer = deserialize$1;
  6096. // All rights reserved.
  6097. //
  6098. // Redistribution and use in source and binary forms, with or without
  6099. // modification, are permitted provided that the following conditions are met:
  6100. //
  6101. // * Redistributions of source code must retain the above copyright notice,
  6102. // this list of conditions and the following disclaimer.
  6103. //
  6104. // * Redistributions in binary form must reproduce the above copyright notice,
  6105. // this list of conditions and the following disclaimer in the documentation
  6106. // and/or other materials provided with the distribution.
  6107. //
  6108. // * Neither the name of Fair Oaks Labs, Inc. nor the names of its contributors
  6109. // may be used to endorse or promote products derived from this software
  6110. // without specific prior written permission.
  6111. //
  6112. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  6113. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  6114. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  6115. // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  6116. // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  6117. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  6118. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  6119. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  6120. // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  6121. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  6122. // POSSIBILITY OF SUCH DAMAGE.
  6123. //
  6124. //
  6125. // Modifications to writeIEEE754 to support negative zeroes made by Brian White
  6126. function readIEEE754(buffer, offset, endian, mLen, nBytes) {
  6127. var e,
  6128. m,
  6129. bBE = endian === 'big',
  6130. eLen = nBytes * 8 - mLen - 1,
  6131. eMax = (1 << eLen) - 1,
  6132. eBias = eMax >> 1,
  6133. nBits = -7,
  6134. i = bBE ? 0 : nBytes - 1,
  6135. d = bBE ? 1 : -1,
  6136. s = buffer[offset + i];
  6137. i += d;
  6138. e = s & (1 << -nBits) - 1;
  6139. s >>= -nBits;
  6140. nBits += eLen;
  6141. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
  6142. }
  6143. m = e & (1 << -nBits) - 1;
  6144. e >>= -nBits;
  6145. nBits += mLen;
  6146. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
  6147. }
  6148. if (e === 0) {
  6149. e = 1 - eBias;
  6150. } else if (e === eMax) {
  6151. return m ? NaN : (s ? -1 : 1) * Infinity;
  6152. } else {
  6153. m = m + Math.pow(2, mLen);
  6154. e = e - eBias;
  6155. }
  6156. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  6157. }
  6158. function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
  6159. var e,
  6160. m,
  6161. c,
  6162. bBE = endian === 'big',
  6163. eLen = nBytes * 8 - mLen - 1,
  6164. eMax = (1 << eLen) - 1,
  6165. eBias = eMax >> 1,
  6166. rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0,
  6167. i = bBE ? nBytes - 1 : 0,
  6168. d = bBE ? -1 : 1,
  6169. s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  6170. value = Math.abs(value);
  6171. if (isNaN(value) || value === Infinity) {
  6172. m = isNaN(value) ? 1 : 0;
  6173. e = eMax;
  6174. } else {
  6175. e = Math.floor(Math.log(value) / Math.LN2);
  6176. if (value * (c = Math.pow(2, -e)) < 1) {
  6177. e--;
  6178. c *= 2;
  6179. }
  6180. if (e + eBias >= 1) {
  6181. value += rt / c;
  6182. } else {
  6183. value += rt * Math.pow(2, 1 - eBias);
  6184. }
  6185. if (value * c >= 2) {
  6186. e++;
  6187. c /= 2;
  6188. }
  6189. if (e + eBias >= eMax) {
  6190. m = 0;
  6191. e = eMax;
  6192. } else if (e + eBias >= 1) {
  6193. m = (value * c - 1) * Math.pow(2, mLen);
  6194. e = e + eBias;
  6195. } else {
  6196. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  6197. e = 0;
  6198. }
  6199. }
  6200. if (isNaN(value)) m = 0;
  6201. while (mLen >= 8) {
  6202. buffer[offset + i] = m & 0xff;
  6203. i += d;
  6204. m /= 256;
  6205. mLen -= 8;
  6206. }
  6207. e = e << mLen | m;
  6208. if (isNaN(value)) e += 8;
  6209. eLen += mLen;
  6210. while (eLen > 0) {
  6211. buffer[offset + i] = e & 0xff;
  6212. i += d;
  6213. e /= 256;
  6214. eLen -= 8;
  6215. }
  6216. buffer[offset + i - d] |= s * 128;
  6217. }
  6218. var float_parser = {
  6219. readIEEE754: readIEEE754,
  6220. writeIEEE754: writeIEEE754
  6221. };
  6222. var Buffer$3 = buffer.Buffer;
  6223. var writeIEEE754$1 = float_parser.writeIEEE754;
  6224. var normalizedFunctionString$1 = utils.normalizedFunctionString;
  6225. var regexp$1 = /\x00/; // eslint-disable-line no-control-regex
  6226. var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']); // To ensure that 0.4 of node works correctly
  6227. var isDate$1 = function isDate(d) {
  6228. return _typeof(d) === 'object' && Object.prototype.toString.call(d) === '[object Date]';
  6229. };
  6230. var isRegExp$1 = function isRegExp(d) {
  6231. return Object.prototype.toString.call(d) === '[object RegExp]';
  6232. };
  6233. function serializeString(buffer$$1, key, value, index, isArray) {
  6234. // Encode String type
  6235. buffer$$1[index++] = constants.BSON_DATA_STRING; // Number of written bytes
  6236. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6237. index = index + numberOfWrittenBytes + 1;
  6238. buffer$$1[index - 1] = 0; // Write the string
  6239. var size = buffer$$1.write(value, index + 4, 'utf8'); // Write the size of the string to buffer
  6240. buffer$$1[index + 3] = size + 1 >> 24 & 0xff;
  6241. buffer$$1[index + 2] = size + 1 >> 16 & 0xff;
  6242. buffer$$1[index + 1] = size + 1 >> 8 & 0xff;
  6243. buffer$$1[index] = size + 1 & 0xff; // Update index
  6244. index = index + 4 + size; // Write zero
  6245. buffer$$1[index++] = 0;
  6246. return index;
  6247. }
  6248. function serializeNumber(buffer$$1, key, value, index, isArray) {
  6249. // We have an integer value
  6250. if (Math.floor(value) === value && value >= constants.JS_INT_MIN && value <= constants.JS_INT_MAX) {
  6251. // If the value fits in 32 bits encode as int, if it fits in a double
  6252. // encode it as a double, otherwise long
  6253. if (value >= constants.BSON_INT32_MIN && value <= constants.BSON_INT32_MAX) {
  6254. // Set int type 32 bits or less
  6255. buffer$$1[index++] = constants.BSON_DATA_INT; // Number of written bytes
  6256. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6257. index = index + numberOfWrittenBytes;
  6258. buffer$$1[index++] = 0; // Write the int value
  6259. buffer$$1[index++] = value & 0xff;
  6260. buffer$$1[index++] = value >> 8 & 0xff;
  6261. buffer$$1[index++] = value >> 16 & 0xff;
  6262. buffer$$1[index++] = value >> 24 & 0xff;
  6263. } else if (value >= constants.JS_INT_MIN && value <= constants.JS_INT_MAX) {
  6264. // Encode as double
  6265. buffer$$1[index++] = constants.BSON_DATA_NUMBER; // Number of written bytes
  6266. var _numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6267. index = index + _numberOfWrittenBytes;
  6268. buffer$$1[index++] = 0; // Write float
  6269. writeIEEE754$1(buffer$$1, value, index, 'little', 52, 8); // Ajust index
  6270. index = index + 8;
  6271. } else {
  6272. // Set long type
  6273. buffer$$1[index++] = constants.BSON_DATA_LONG; // Number of written bytes
  6274. var _numberOfWrittenBytes2 = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6275. index = index + _numberOfWrittenBytes2;
  6276. buffer$$1[index++] = 0;
  6277. var longVal = long_1$1.fromNumber(value);
  6278. var lowBits = longVal.getLowBits();
  6279. var highBits = longVal.getHighBits(); // Encode low bits
  6280. buffer$$1[index++] = lowBits & 0xff;
  6281. buffer$$1[index++] = lowBits >> 8 & 0xff;
  6282. buffer$$1[index++] = lowBits >> 16 & 0xff;
  6283. buffer$$1[index++] = lowBits >> 24 & 0xff; // Encode high bits
  6284. buffer$$1[index++] = highBits & 0xff;
  6285. buffer$$1[index++] = highBits >> 8 & 0xff;
  6286. buffer$$1[index++] = highBits >> 16 & 0xff;
  6287. buffer$$1[index++] = highBits >> 24 & 0xff;
  6288. }
  6289. } else {
  6290. // Encode as double
  6291. buffer$$1[index++] = constants.BSON_DATA_NUMBER; // Number of written bytes
  6292. var _numberOfWrittenBytes3 = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6293. index = index + _numberOfWrittenBytes3;
  6294. buffer$$1[index++] = 0; // Write float
  6295. writeIEEE754$1(buffer$$1, value, index, 'little', 52, 8); // Ajust index
  6296. index = index + 8;
  6297. }
  6298. return index;
  6299. }
  6300. function serializeNull(buffer$$1, key, value, index, isArray) {
  6301. // Set long type
  6302. buffer$$1[index++] = constants.BSON_DATA_NULL; // Number of written bytes
  6303. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6304. index = index + numberOfWrittenBytes;
  6305. buffer$$1[index++] = 0;
  6306. return index;
  6307. }
  6308. function serializeBoolean(buffer$$1, key, value, index, isArray) {
  6309. // Write the type
  6310. buffer$$1[index++] = constants.BSON_DATA_BOOLEAN; // Number of written bytes
  6311. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6312. index = index + numberOfWrittenBytes;
  6313. buffer$$1[index++] = 0; // Encode the boolean value
  6314. buffer$$1[index++] = value ? 1 : 0;
  6315. return index;
  6316. }
  6317. function serializeDate(buffer$$1, key, value, index, isArray) {
  6318. // Write the type
  6319. buffer$$1[index++] = constants.BSON_DATA_DATE; // Number of written bytes
  6320. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6321. index = index + numberOfWrittenBytes;
  6322. buffer$$1[index++] = 0; // Write the date
  6323. var dateInMilis = long_1$1.fromNumber(value.getTime());
  6324. var lowBits = dateInMilis.getLowBits();
  6325. var highBits = dateInMilis.getHighBits(); // Encode low bits
  6326. buffer$$1[index++] = lowBits & 0xff;
  6327. buffer$$1[index++] = lowBits >> 8 & 0xff;
  6328. buffer$$1[index++] = lowBits >> 16 & 0xff;
  6329. buffer$$1[index++] = lowBits >> 24 & 0xff; // Encode high bits
  6330. buffer$$1[index++] = highBits & 0xff;
  6331. buffer$$1[index++] = highBits >> 8 & 0xff;
  6332. buffer$$1[index++] = highBits >> 16 & 0xff;
  6333. buffer$$1[index++] = highBits >> 24 & 0xff;
  6334. return index;
  6335. }
  6336. function serializeRegExp(buffer$$1, key, value, index, isArray) {
  6337. // Write the type
  6338. buffer$$1[index++] = constants.BSON_DATA_REGEXP; // Number of written bytes
  6339. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6340. index = index + numberOfWrittenBytes;
  6341. buffer$$1[index++] = 0;
  6342. if (value.source && value.source.match(regexp$1) != null) {
  6343. throw Error('value ' + value.source + ' must not contain null bytes');
  6344. } // Adjust the index
  6345. index = index + buffer$$1.write(value.source, index, 'utf8'); // Write zero
  6346. buffer$$1[index++] = 0x00; // Write the parameters
  6347. if (value.ignoreCase) buffer$$1[index++] = 0x69; // i
  6348. if (value.global) buffer$$1[index++] = 0x73; // s
  6349. if (value.multiline) buffer$$1[index++] = 0x6d; // m
  6350. // Add ending zero
  6351. buffer$$1[index++] = 0x00;
  6352. return index;
  6353. }
  6354. function serializeBSONRegExp(buffer$$1, key, value, index, isArray) {
  6355. // Write the type
  6356. buffer$$1[index++] = constants.BSON_DATA_REGEXP; // Number of written bytes
  6357. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6358. index = index + numberOfWrittenBytes;
  6359. buffer$$1[index++] = 0; // Check the pattern for 0 bytes
  6360. if (value.pattern.match(regexp$1) != null) {
  6361. // The BSON spec doesn't allow keys with null bytes because keys are
  6362. // null-terminated.
  6363. throw Error('pattern ' + value.pattern + ' must not contain null bytes');
  6364. } // Adjust the index
  6365. index = index + buffer$$1.write(value.pattern, index, 'utf8'); // Write zero
  6366. buffer$$1[index++] = 0x00; // Write the options
  6367. index = index + buffer$$1.write(value.options.split('').sort().join(''), index, 'utf8'); // Add ending zero
  6368. buffer$$1[index++] = 0x00;
  6369. return index;
  6370. }
  6371. function serializeMinMax(buffer$$1, key, value, index, isArray) {
  6372. // Write the type of either min or max key
  6373. if (value === null) {
  6374. buffer$$1[index++] = constants.BSON_DATA_NULL;
  6375. } else if (value instanceof min_key) {
  6376. buffer$$1[index++] = constants.BSON_DATA_MIN_KEY;
  6377. } else {
  6378. buffer$$1[index++] = constants.BSON_DATA_MAX_KEY;
  6379. } // Number of written bytes
  6380. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6381. index = index + numberOfWrittenBytes;
  6382. buffer$$1[index++] = 0;
  6383. return index;
  6384. }
  6385. function serializeObjectId(buffer$$1, key, value, index, isArray) {
  6386. // Write the type
  6387. buffer$$1[index++] = constants.BSON_DATA_OID; // Number of written bytes
  6388. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6389. index = index + numberOfWrittenBytes;
  6390. buffer$$1[index++] = 0; // Write the objectId into the shared buffer
  6391. if (typeof value.id === 'string') {
  6392. buffer$$1.write(value.id, index, 'binary');
  6393. } else if (value.id && value.id.copy) {
  6394. value.id.copy(buffer$$1, index, 0, 12);
  6395. } else {
  6396. throw new TypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
  6397. } // Ajust index
  6398. return index + 12;
  6399. }
  6400. function serializeBuffer(buffer$$1, key, value, index, isArray) {
  6401. // Write the type
  6402. buffer$$1[index++] = constants.BSON_DATA_BINARY; // Number of written bytes
  6403. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6404. index = index + numberOfWrittenBytes;
  6405. buffer$$1[index++] = 0; // Get size of the buffer (current write point)
  6406. var size = value.length; // Write the size of the string to buffer
  6407. buffer$$1[index++] = size & 0xff;
  6408. buffer$$1[index++] = size >> 8 & 0xff;
  6409. buffer$$1[index++] = size >> 16 & 0xff;
  6410. buffer$$1[index++] = size >> 24 & 0xff; // Write the default subtype
  6411. buffer$$1[index++] = constants.BSON_BINARY_SUBTYPE_DEFAULT; // Copy the content form the binary field to the buffer
  6412. value.copy(buffer$$1, index, 0, size); // Adjust the index
  6413. index = index + size;
  6414. return index;
  6415. }
  6416. function serializeObject(buffer$$1, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray, path) {
  6417. for (var i = 0; i < path.length; i++) {
  6418. if (path[i] === value) throw new Error('cyclic dependency detected');
  6419. } // Push value to stack
  6420. path.push(value); // Write the type
  6421. buffer$$1[index++] = Array.isArray(value) ? constants.BSON_DATA_ARRAY : constants.BSON_DATA_OBJECT; // Number of written bytes
  6422. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6423. index = index + numberOfWrittenBytes;
  6424. buffer$$1[index++] = 0;
  6425. var endIndex = serializeInto(buffer$$1, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path); // Pop stack
  6426. path.pop();
  6427. return endIndex;
  6428. }
  6429. function serializeDecimal128(buffer$$1, key, value, index, isArray) {
  6430. buffer$$1[index++] = constants.BSON_DATA_DECIMAL128; // Number of written bytes
  6431. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6432. index = index + numberOfWrittenBytes;
  6433. buffer$$1[index++] = 0; // Write the data from the value
  6434. value.bytes.copy(buffer$$1, index, 0, 16);
  6435. return index + 16;
  6436. }
  6437. function serializeLong(buffer$$1, key, value, index, isArray) {
  6438. // Write the type
  6439. buffer$$1[index++] = value._bsontype === 'Long' ? constants.BSON_DATA_LONG : constants.BSON_DATA_TIMESTAMP; // Number of written bytes
  6440. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6441. index = index + numberOfWrittenBytes;
  6442. buffer$$1[index++] = 0; // Write the date
  6443. var lowBits = value.getLowBits();
  6444. var highBits = value.getHighBits(); // Encode low bits
  6445. buffer$$1[index++] = lowBits & 0xff;
  6446. buffer$$1[index++] = lowBits >> 8 & 0xff;
  6447. buffer$$1[index++] = lowBits >> 16 & 0xff;
  6448. buffer$$1[index++] = lowBits >> 24 & 0xff; // Encode high bits
  6449. buffer$$1[index++] = highBits & 0xff;
  6450. buffer$$1[index++] = highBits >> 8 & 0xff;
  6451. buffer$$1[index++] = highBits >> 16 & 0xff;
  6452. buffer$$1[index++] = highBits >> 24 & 0xff;
  6453. return index;
  6454. }
  6455. function serializeInt32(buffer$$1, key, value, index, isArray) {
  6456. // Set int type 32 bits or less
  6457. buffer$$1[index++] = constants.BSON_DATA_INT; // Number of written bytes
  6458. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6459. index = index + numberOfWrittenBytes;
  6460. buffer$$1[index++] = 0; // Write the int value
  6461. buffer$$1[index++] = value & 0xff;
  6462. buffer$$1[index++] = value >> 8 & 0xff;
  6463. buffer$$1[index++] = value >> 16 & 0xff;
  6464. buffer$$1[index++] = value >> 24 & 0xff;
  6465. return index;
  6466. }
  6467. function serializeDouble(buffer$$1, key, value, index, isArray) {
  6468. // Encode as double
  6469. buffer$$1[index++] = constants.BSON_DATA_NUMBER; // Number of written bytes
  6470. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6471. index = index + numberOfWrittenBytes;
  6472. buffer$$1[index++] = 0; // Write float
  6473. writeIEEE754$1(buffer$$1, value.value, index, 'little', 52, 8); // Adjust index
  6474. index = index + 8;
  6475. return index;
  6476. }
  6477. function serializeFunction(buffer$$1, key, value, index, checkKeys, depth, isArray) {
  6478. buffer$$1[index++] = constants.BSON_DATA_CODE; // Number of written bytes
  6479. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6480. index = index + numberOfWrittenBytes;
  6481. buffer$$1[index++] = 0; // Function string
  6482. var functionString = normalizedFunctionString$1(value); // Write the string
  6483. var size = buffer$$1.write(functionString, index + 4, 'utf8') + 1; // Write the size of the string to buffer
  6484. buffer$$1[index] = size & 0xff;
  6485. buffer$$1[index + 1] = size >> 8 & 0xff;
  6486. buffer$$1[index + 2] = size >> 16 & 0xff;
  6487. buffer$$1[index + 3] = size >> 24 & 0xff; // Update index
  6488. index = index + 4 + size - 1; // Write zero
  6489. buffer$$1[index++] = 0;
  6490. return index;
  6491. }
  6492. function serializeCode(buffer$$1, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray) {
  6493. if (value.scope && _typeof(value.scope) === 'object') {
  6494. // Write the type
  6495. buffer$$1[index++] = constants.BSON_DATA_CODE_W_SCOPE; // Number of written bytes
  6496. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6497. index = index + numberOfWrittenBytes;
  6498. buffer$$1[index++] = 0; // Starting index
  6499. var startIndex = index; // Serialize the function
  6500. // Get the function string
  6501. var functionString = typeof value.code === 'string' ? value.code : value.code.toString(); // Index adjustment
  6502. index = index + 4; // Write string into buffer
  6503. var codeSize = buffer$$1.write(functionString, index + 4, 'utf8') + 1; // Write the size of the string to buffer
  6504. buffer$$1[index] = codeSize & 0xff;
  6505. buffer$$1[index + 1] = codeSize >> 8 & 0xff;
  6506. buffer$$1[index + 2] = codeSize >> 16 & 0xff;
  6507. buffer$$1[index + 3] = codeSize >> 24 & 0xff; // Write end 0
  6508. buffer$$1[index + 4 + codeSize - 1] = 0; // Write the
  6509. index = index + codeSize + 4; //
  6510. // Serialize the scope value
  6511. var endIndex = serializeInto(buffer$$1, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined);
  6512. index = endIndex - 1; // Writ the total
  6513. var totalSize = endIndex - startIndex; // Write the total size of the object
  6514. buffer$$1[startIndex++] = totalSize & 0xff;
  6515. buffer$$1[startIndex++] = totalSize >> 8 & 0xff;
  6516. buffer$$1[startIndex++] = totalSize >> 16 & 0xff;
  6517. buffer$$1[startIndex++] = totalSize >> 24 & 0xff; // Write trailing zero
  6518. buffer$$1[index++] = 0;
  6519. } else {
  6520. buffer$$1[index++] = constants.BSON_DATA_CODE; // Number of written bytes
  6521. var _numberOfWrittenBytes4 = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6522. index = index + _numberOfWrittenBytes4;
  6523. buffer$$1[index++] = 0; // Function string
  6524. var _functionString = value.code.toString(); // Write the string
  6525. var size = buffer$$1.write(_functionString, index + 4, 'utf8') + 1; // Write the size of the string to buffer
  6526. buffer$$1[index] = size & 0xff;
  6527. buffer$$1[index + 1] = size >> 8 & 0xff;
  6528. buffer$$1[index + 2] = size >> 16 & 0xff;
  6529. buffer$$1[index + 3] = size >> 24 & 0xff; // Update index
  6530. index = index + 4 + size - 1; // Write zero
  6531. buffer$$1[index++] = 0;
  6532. }
  6533. return index;
  6534. }
  6535. function serializeBinary(buffer$$1, key, value, index, isArray) {
  6536. // Write the type
  6537. buffer$$1[index++] = constants.BSON_DATA_BINARY; // Number of written bytes
  6538. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6539. index = index + numberOfWrittenBytes;
  6540. buffer$$1[index++] = 0; // Extract the buffer
  6541. var data = value.value(true); // Calculate size
  6542. var size = value.position; // Add the deprecated 02 type 4 bytes of size to total
  6543. if (value.sub_type === binary.SUBTYPE_BYTE_ARRAY) size = size + 4; // Write the size of the string to buffer
  6544. buffer$$1[index++] = size & 0xff;
  6545. buffer$$1[index++] = size >> 8 & 0xff;
  6546. buffer$$1[index++] = size >> 16 & 0xff;
  6547. buffer$$1[index++] = size >> 24 & 0xff; // Write the subtype to the buffer
  6548. buffer$$1[index++] = value.sub_type; // If we have binary type 2 the 4 first bytes are the size
  6549. if (value.sub_type === binary.SUBTYPE_BYTE_ARRAY) {
  6550. size = size - 4;
  6551. buffer$$1[index++] = size & 0xff;
  6552. buffer$$1[index++] = size >> 8 & 0xff;
  6553. buffer$$1[index++] = size >> 16 & 0xff;
  6554. buffer$$1[index++] = size >> 24 & 0xff;
  6555. } // Write the data to the object
  6556. data.copy(buffer$$1, index, 0, value.position); // Adjust the index
  6557. index = index + value.position;
  6558. return index;
  6559. }
  6560. function serializeSymbol(buffer$$1, key, value, index, isArray) {
  6561. // Write the type
  6562. buffer$$1[index++] = constants.BSON_DATA_SYMBOL; // Number of written bytes
  6563. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6564. index = index + numberOfWrittenBytes;
  6565. buffer$$1[index++] = 0; // Write the string
  6566. var size = buffer$$1.write(value.value, index + 4, 'utf8') + 1; // Write the size of the string to buffer
  6567. buffer$$1[index] = size & 0xff;
  6568. buffer$$1[index + 1] = size >> 8 & 0xff;
  6569. buffer$$1[index + 2] = size >> 16 & 0xff;
  6570. buffer$$1[index + 3] = size >> 24 & 0xff; // Update index
  6571. index = index + 4 + size - 1; // Write zero
  6572. buffer$$1[index++] = 0x00;
  6573. return index;
  6574. }
  6575. function serializeDBRef(buffer$$1, key, value, index, depth, serializeFunctions, isArray) {
  6576. // Write the type
  6577. buffer$$1[index++] = constants.BSON_DATA_OBJECT; // Number of written bytes
  6578. var numberOfWrittenBytes = !isArray ? buffer$$1.write(key, index, 'utf8') : buffer$$1.write(key, index, 'ascii'); // Encode the name
  6579. index = index + numberOfWrittenBytes;
  6580. buffer$$1[index++] = 0;
  6581. var startIndex = index;
  6582. var endIndex;
  6583. var output = {
  6584. $ref: value.collection,
  6585. $id: value.oid
  6586. };
  6587. if (value.db != null) output.$db = value.db;
  6588. output = Object.assign(output, value.fields);
  6589. endIndex = serializeInto(buffer$$1, output, false, index, depth + 1, serializeFunctions); // Calculate object size
  6590. var size = endIndex - startIndex; // Write the size
  6591. buffer$$1[startIndex++] = size & 0xff;
  6592. buffer$$1[startIndex++] = size >> 8 & 0xff;
  6593. buffer$$1[startIndex++] = size >> 16 & 0xff;
  6594. buffer$$1[startIndex++] = size >> 24 & 0xff; // Set index
  6595. return endIndex;
  6596. }
  6597. function serializeInto(buffer$$1, object, checkKeys, startingIndex, depth, serializeFunctions, ignoreUndefined, path) {
  6598. startingIndex = startingIndex || 0;
  6599. path = path || []; // Push the object to the path
  6600. path.push(object); // Start place to serialize into
  6601. var index = startingIndex + 4; // Special case isArray
  6602. if (Array.isArray(object)) {
  6603. // Get object keys
  6604. for (var i = 0; i < object.length; i++) {
  6605. var key = '' + i;
  6606. var value = object[i]; // Is there an override value
  6607. if (value && value.toBSON) {
  6608. if (typeof value.toBSON !== 'function') throw new TypeError('toBSON is not a function');
  6609. value = value.toBSON();
  6610. }
  6611. var type = _typeof(value);
  6612. if (type === 'string') {
  6613. index = serializeString(buffer$$1, key, value, index, true);
  6614. } else if (type === 'number') {
  6615. index = serializeNumber(buffer$$1, key, value, index, true);
  6616. } else if (type === 'boolean') {
  6617. index = serializeBoolean(buffer$$1, key, value, index, true);
  6618. } else if (value instanceof Date || isDate$1(value)) {
  6619. index = serializeDate(buffer$$1, key, value, index, true);
  6620. } else if (value === undefined) {
  6621. index = serializeNull(buffer$$1, key, value, index, true);
  6622. } else if (value === null) {
  6623. index = serializeNull(buffer$$1, key, value, index, true);
  6624. } else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
  6625. index = serializeObjectId(buffer$$1, key, value, index, true);
  6626. } else if (Buffer$3.isBuffer(value)) {
  6627. index = serializeBuffer(buffer$$1, key, value, index, true);
  6628. } else if (value instanceof RegExp || isRegExp$1(value)) {
  6629. index = serializeRegExp(buffer$$1, key, value, index, true);
  6630. } else if (type === 'object' && value['_bsontype'] == null) {
  6631. index = serializeObject(buffer$$1, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true, path);
  6632. } else if (type === 'object' && value['_bsontype'] === 'Decimal128') {
  6633. index = serializeDecimal128(buffer$$1, key, value, index, true);
  6634. } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') {
  6635. index = serializeLong(buffer$$1, key, value, index, true);
  6636. } else if (value['_bsontype'] === 'Double') {
  6637. index = serializeDouble(buffer$$1, key, value, index, true);
  6638. } else if (typeof value === 'function' && serializeFunctions) {
  6639. index = serializeFunction(buffer$$1, key, value, index, checkKeys, depth, serializeFunctions, true);
  6640. } else if (value['_bsontype'] === 'Code') {
  6641. index = serializeCode(buffer$$1, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true);
  6642. } else if (value['_bsontype'] === 'Binary') {
  6643. index = serializeBinary(buffer$$1, key, value, index, true);
  6644. } else if (value['_bsontype'] === 'Symbol') {
  6645. index = serializeSymbol(buffer$$1, key, value, index, true);
  6646. } else if (value['_bsontype'] === 'DBRef') {
  6647. index = serializeDBRef(buffer$$1, key, value, index, depth, serializeFunctions, true);
  6648. } else if (value['_bsontype'] === 'BSONRegExp') {
  6649. index = serializeBSONRegExp(buffer$$1, key, value, index, true);
  6650. } else if (value['_bsontype'] === 'Int32') {
  6651. index = serializeInt32(buffer$$1, key, value, index, true);
  6652. } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  6653. index = serializeMinMax(buffer$$1, key, value, index, true);
  6654. }
  6655. }
  6656. } else if (object instanceof map) {
  6657. var iterator = object.entries();
  6658. var done = false;
  6659. while (!done) {
  6660. // Unpack the next entry
  6661. var entry = iterator.next();
  6662. done = entry.done; // Are we done, then skip and terminate
  6663. if (done) continue; // Get the entry values
  6664. var _key = entry.value[0];
  6665. var _value = entry.value[1]; // Check the type of the value
  6666. var _type = _typeof(_value); // Check the key and throw error if it's illegal
  6667. if (typeof _key === 'string' && !ignoreKeys.has(_key)) {
  6668. if (_key.match(regexp$1) != null) {
  6669. // The BSON spec doesn't allow keys with null bytes because keys are
  6670. // null-terminated.
  6671. throw Error('key ' + _key + ' must not contain null bytes');
  6672. }
  6673. if (checkKeys) {
  6674. if ('$' === _key[0]) {
  6675. throw Error('key ' + _key + " must not start with '$'");
  6676. } else if (~_key.indexOf('.')) {
  6677. throw Error('key ' + _key + " must not contain '.'");
  6678. }
  6679. }
  6680. }
  6681. if (_type === 'string') {
  6682. index = serializeString(buffer$$1, _key, _value, index);
  6683. } else if (_type === 'number') {
  6684. index = serializeNumber(buffer$$1, _key, _value, index);
  6685. } else if (_type === 'boolean') {
  6686. index = serializeBoolean(buffer$$1, _key, _value, index);
  6687. } else if (_value instanceof Date || isDate$1(_value)) {
  6688. index = serializeDate(buffer$$1, _key, _value, index);
  6689. } else if (_value === null || _value === undefined && ignoreUndefined === false) {
  6690. index = serializeNull(buffer$$1, _key, _value, index);
  6691. } else if (_value['_bsontype'] === 'ObjectId' || _value['_bsontype'] === 'ObjectID') {
  6692. index = serializeObjectId(buffer$$1, _key, _value, index);
  6693. } else if (Buffer$3.isBuffer(_value)) {
  6694. index = serializeBuffer(buffer$$1, _key, _value, index);
  6695. } else if (_value instanceof RegExp || isRegExp$1(_value)) {
  6696. index = serializeRegExp(buffer$$1, _key, _value, index);
  6697. } else if (_type === 'object' && _value['_bsontype'] == null) {
  6698. index = serializeObject(buffer$$1, _key, _value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, false, path);
  6699. } else if (_type === 'object' && _value['_bsontype'] === 'Decimal128') {
  6700. index = serializeDecimal128(buffer$$1, _key, _value, index);
  6701. } else if (_value['_bsontype'] === 'Long' || _value['_bsontype'] === 'Timestamp') {
  6702. index = serializeLong(buffer$$1, _key, _value, index);
  6703. } else if (_value['_bsontype'] === 'Double') {
  6704. index = serializeDouble(buffer$$1, _key, _value, index);
  6705. } else if (_value['_bsontype'] === 'Code') {
  6706. index = serializeCode(buffer$$1, _key, _value, index, checkKeys, depth, serializeFunctions, ignoreUndefined);
  6707. } else if (typeof _value === 'function' && serializeFunctions) {
  6708. index = serializeFunction(buffer$$1, _key, _value, index, checkKeys, depth, serializeFunctions);
  6709. } else if (_value['_bsontype'] === 'Binary') {
  6710. index = serializeBinary(buffer$$1, _key, _value, index);
  6711. } else if (_value['_bsontype'] === 'Symbol') {
  6712. index = serializeSymbol(buffer$$1, _key, _value, index);
  6713. } else if (_value['_bsontype'] === 'DBRef') {
  6714. index = serializeDBRef(buffer$$1, _key, _value, index, depth, serializeFunctions);
  6715. } else if (_value['_bsontype'] === 'BSONRegExp') {
  6716. index = serializeBSONRegExp(buffer$$1, _key, _value, index);
  6717. } else if (_value['_bsontype'] === 'Int32') {
  6718. index = serializeInt32(buffer$$1, _key, _value, index);
  6719. } else if (_value['_bsontype'] === 'MinKey' || _value['_bsontype'] === 'MaxKey') {
  6720. index = serializeMinMax(buffer$$1, _key, _value, index);
  6721. }
  6722. }
  6723. } else {
  6724. // Did we provide a custom serialization method
  6725. if (object.toBSON) {
  6726. if (typeof object.toBSON !== 'function') throw new TypeError('toBSON is not a function');
  6727. object = object.toBSON();
  6728. if (object != null && _typeof(object) !== 'object') throw new TypeError('toBSON function did not return an object');
  6729. } // Iterate over all the keys
  6730. for (var _key2 in object) {
  6731. var _value2 = object[_key2]; // Is there an override value
  6732. if (_value2 && _value2.toBSON) {
  6733. if (typeof _value2.toBSON !== 'function') throw new TypeError('toBSON is not a function');
  6734. _value2 = _value2.toBSON();
  6735. } // Check the type of the value
  6736. var _type2 = _typeof(_value2); // Check the key and throw error if it's illegal
  6737. if (typeof _key2 === 'string' && !ignoreKeys.has(_key2)) {
  6738. if (_key2.match(regexp$1) != null) {
  6739. // The BSON spec doesn't allow keys with null bytes because keys are
  6740. // null-terminated.
  6741. throw Error('key ' + _key2 + ' must not contain null bytes');
  6742. }
  6743. if (checkKeys) {
  6744. if ('$' === _key2[0]) {
  6745. throw Error('key ' + _key2 + " must not start with '$'");
  6746. } else if (~_key2.indexOf('.')) {
  6747. throw Error('key ' + _key2 + " must not contain '.'");
  6748. }
  6749. }
  6750. }
  6751. if (_type2 === 'string') {
  6752. index = serializeString(buffer$$1, _key2, _value2, index);
  6753. } else if (_type2 === 'number') {
  6754. index = serializeNumber(buffer$$1, _key2, _value2, index);
  6755. } else if (_type2 === 'boolean') {
  6756. index = serializeBoolean(buffer$$1, _key2, _value2, index);
  6757. } else if (_value2 instanceof Date || isDate$1(_value2)) {
  6758. index = serializeDate(buffer$$1, _key2, _value2, index);
  6759. } else if (_value2 === undefined) {
  6760. if (ignoreUndefined === false) index = serializeNull(buffer$$1, _key2, _value2, index);
  6761. } else if (_value2 === null) {
  6762. index = serializeNull(buffer$$1, _key2, _value2, index);
  6763. } else if (_value2['_bsontype'] === 'ObjectId' || _value2['_bsontype'] === 'ObjectID') {
  6764. index = serializeObjectId(buffer$$1, _key2, _value2, index);
  6765. } else if (Buffer$3.isBuffer(_value2)) {
  6766. index = serializeBuffer(buffer$$1, _key2, _value2, index);
  6767. } else if (_value2 instanceof RegExp || isRegExp$1(_value2)) {
  6768. index = serializeRegExp(buffer$$1, _key2, _value2, index);
  6769. } else if (_type2 === 'object' && _value2['_bsontype'] == null) {
  6770. index = serializeObject(buffer$$1, _key2, _value2, index, checkKeys, depth, serializeFunctions, ignoreUndefined, false, path);
  6771. } else if (_type2 === 'object' && _value2['_bsontype'] === 'Decimal128') {
  6772. index = serializeDecimal128(buffer$$1, _key2, _value2, index);
  6773. } else if (_value2['_bsontype'] === 'Long' || _value2['_bsontype'] === 'Timestamp') {
  6774. index = serializeLong(buffer$$1, _key2, _value2, index);
  6775. } else if (_value2['_bsontype'] === 'Double') {
  6776. index = serializeDouble(buffer$$1, _key2, _value2, index);
  6777. } else if (_value2['_bsontype'] === 'Code') {
  6778. index = serializeCode(buffer$$1, _key2, _value2, index, checkKeys, depth, serializeFunctions, ignoreUndefined);
  6779. } else if (typeof _value2 === 'function' && serializeFunctions) {
  6780. index = serializeFunction(buffer$$1, _key2, _value2, index, checkKeys, depth, serializeFunctions);
  6781. } else if (_value2['_bsontype'] === 'Binary') {
  6782. index = serializeBinary(buffer$$1, _key2, _value2, index);
  6783. } else if (_value2['_bsontype'] === 'Symbol') {
  6784. index = serializeSymbol(buffer$$1, _key2, _value2, index);
  6785. } else if (_value2['_bsontype'] === 'DBRef') {
  6786. index = serializeDBRef(buffer$$1, _key2, _value2, index, depth, serializeFunctions);
  6787. } else if (_value2['_bsontype'] === 'BSONRegExp') {
  6788. index = serializeBSONRegExp(buffer$$1, _key2, _value2, index);
  6789. } else if (_value2['_bsontype'] === 'Int32') {
  6790. index = serializeInt32(buffer$$1, _key2, _value2, index);
  6791. } else if (_value2['_bsontype'] === 'MinKey' || _value2['_bsontype'] === 'MaxKey') {
  6792. index = serializeMinMax(buffer$$1, _key2, _value2, index);
  6793. }
  6794. }
  6795. } // Remove the path
  6796. path.pop(); // Final padding byte for object
  6797. buffer$$1[index++] = 0x00; // Final size
  6798. var size = index - startingIndex; // Write the size of the object
  6799. buffer$$1[startingIndex++] = size & 0xff;
  6800. buffer$$1[startingIndex++] = size >> 8 & 0xff;
  6801. buffer$$1[startingIndex++] = size >> 16 & 0xff;
  6802. buffer$$1[startingIndex++] = size >> 24 & 0xff;
  6803. return index;
  6804. }
  6805. var serializer = serializeInto;
  6806. var Buffer$4 = buffer.Buffer;
  6807. var normalizedFunctionString$2 = utils.normalizedFunctionString; // To ensure that 0.4 of node works correctly
  6808. function isDate$2(d) {
  6809. return _typeof(d) === 'object' && Object.prototype.toString.call(d) === '[object Date]';
  6810. }
  6811. function calculateObjectSize(object, serializeFunctions, ignoreUndefined) {
  6812. var totalLength = 4 + 1;
  6813. if (Array.isArray(object)) {
  6814. for (var i = 0; i < object.length; i++) {
  6815. totalLength += calculateElement(i.toString(), object[i], serializeFunctions, true, ignoreUndefined);
  6816. }
  6817. } else {
  6818. // If we have toBSON defined, override the current object
  6819. if (object.toBSON) {
  6820. object = object.toBSON();
  6821. } // Calculate size
  6822. for (var key in object) {
  6823. totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined);
  6824. }
  6825. }
  6826. return totalLength;
  6827. }
  6828. /**
  6829. * @ignore
  6830. * @api private
  6831. */
  6832. function calculateElement(name, value, serializeFunctions, isArray, ignoreUndefined) {
  6833. // If we have toBSON defined, override the current object
  6834. if (value && value.toBSON) {
  6835. value = value.toBSON();
  6836. }
  6837. switch (_typeof(value)) {
  6838. case 'string':
  6839. return 1 + Buffer$4.byteLength(name, 'utf8') + 1 + 4 + Buffer$4.byteLength(value, 'utf8') + 1;
  6840. case 'number':
  6841. if (Math.floor(value) === value && value >= constants.JS_INT_MIN && value <= constants.JS_INT_MAX) {
  6842. if (value >= constants.BSON_INT32_MIN && value <= constants.BSON_INT32_MAX) {
  6843. // 32 bit
  6844. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
  6845. } else {
  6846. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  6847. }
  6848. } else {
  6849. // 64 bit
  6850. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  6851. }
  6852. case 'undefined':
  6853. if (isArray || !ignoreUndefined) return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1;
  6854. return 0;
  6855. case 'boolean':
  6856. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
  6857. case 'object':
  6858. if (value == null || value instanceof min_key || value instanceof max_key || value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  6859. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1;
  6860. } else if (value instanceof objectid || value['_bsontype'] === 'ObjectId') {
  6861. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
  6862. } else if (value instanceof Date || isDate$2(value)) {
  6863. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  6864. } else if (typeof Buffer$4 !== 'undefined' && Buffer$4.isBuffer(value)) {
  6865. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.length;
  6866. } else if (value instanceof long_1$1 || value instanceof double_1 || value instanceof timestamp || value['_bsontype'] === 'Long' || value['_bsontype'] === 'Double' || value['_bsontype'] === 'Timestamp') {
  6867. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  6868. } else if (value instanceof decimal128 || value['_bsontype'] === 'Decimal128') {
  6869. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
  6870. } else if (value instanceof code$1 || value['_bsontype'] === 'Code') {
  6871. // Calculate size depending on the availability of a scope
  6872. if (value.scope != null && Object.keys(value.scope).length > 0) {
  6873. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + 4 + Buffer$4.byteLength(value.code.toString(), 'utf8') + 1 + calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined);
  6874. } else {
  6875. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + Buffer$4.byteLength(value.code.toString(), 'utf8') + 1;
  6876. }
  6877. } else if (value instanceof binary || value['_bsontype'] === 'Binary') {
  6878. // Check what kind of subtype we have
  6879. if (value.sub_type === binary.SUBTYPE_BYTE_ARRAY) {
  6880. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1 + 4);
  6881. } else {
  6882. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1);
  6883. }
  6884. } else if (value instanceof symbol || value['_bsontype'] === 'Symbol') {
  6885. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + Buffer$4.byteLength(value.value, 'utf8') + 4 + 1 + 1;
  6886. } else if (value instanceof db_ref || value['_bsontype'] === 'DBRef') {
  6887. // Set up correct object for serialization
  6888. var ordered_values = Object.assign({
  6889. $ref: value.collection,
  6890. $id: value.oid
  6891. }, value.fields); // Add db reference if it exists
  6892. if (value.db != null) {
  6893. ordered_values['$db'] = value.db;
  6894. }
  6895. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + calculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined);
  6896. } else if (value instanceof RegExp || Object.prototype.toString.call(value) === '[object RegExp]') {
  6897. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + Buffer$4.byteLength(value.source, 'utf8') + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
  6898. } else if (value instanceof regexp || value['_bsontype'] === 'BSONRegExp') {
  6899. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + Buffer$4.byteLength(value.pattern, 'utf8') + 1 + Buffer$4.byteLength(value.options, 'utf8') + 1;
  6900. } else {
  6901. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + calculateObjectSize(value, serializeFunctions, ignoreUndefined) + 1;
  6902. }
  6903. case 'function':
  6904. // WTF for 0.4.X where typeof /someregexp/ === 'function'
  6905. if (value instanceof RegExp || Object.prototype.toString.call(value) === '[object RegExp]' || String.call(value) === '[object RegExp]') {
  6906. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + Buffer$4.byteLength(value.source, 'utf8') + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
  6907. } else {
  6908. if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) {
  6909. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + 4 + Buffer$4.byteLength(normalizedFunctionString$2(value), 'utf8') + 1 + calculateObjectSize(value.scope, serializeFunctions, ignoreUndefined);
  6910. } else if (serializeFunctions) {
  6911. return (name != null ? Buffer$4.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + Buffer$4.byteLength(normalizedFunctionString$2(value), 'utf8') + 1;
  6912. }
  6913. }
  6914. }
  6915. return 0;
  6916. }
  6917. var calculate_size = calculateObjectSize;
  6918. var Buffer$5 = buffer.Buffer;
  6919. /**
  6920. * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer.
  6921. *
  6922. * @param {Buffer|Uint8Array} potentialBuffer The potential buffer
  6923. * @returns {Buffer} the input if potentialBuffer is a buffer, or a buffer that
  6924. * wraps a passed in Uint8Array
  6925. * @throws {TypeError} If anything other than a Buffer or Uint8Array is passed in
  6926. */
  6927. var ensure_buffer = function ensureBuffer(potentialBuffer) {
  6928. if (potentialBuffer instanceof Buffer$5) {
  6929. return potentialBuffer;
  6930. }
  6931. if (potentialBuffer instanceof Uint8Array) {
  6932. return Buffer$5.from(potentialBuffer.buffer);
  6933. }
  6934. throw new TypeError('Must use either Buffer or Uint8Array');
  6935. };
  6936. var Buffer$6 = buffer.Buffer; // Parts of the parser
  6937. /**
  6938. * @ignore
  6939. */
  6940. // Default Max Size
  6941. var MAXSIZE = 1024 * 1024 * 17; // Current Internal Temporary Serialization Buffer
  6942. var buffer$1 = Buffer$6.alloc(MAXSIZE);
  6943. /**
  6944. * Sets the size of the internal serialization buffer.
  6945. *
  6946. * @method
  6947. * @param {number} size The desired size for the internal serialization buffer
  6948. */
  6949. function setInternalBufferSize(size) {
  6950. // Resize the internal serialization buffer if needed
  6951. if (buffer$1.length < size) {
  6952. buffer$1 = Buffer$6.alloc(size);
  6953. }
  6954. }
  6955. /**
  6956. * Serialize a Javascript object.
  6957. *
  6958. * @param {Object} object the Javascript object to serialize.
  6959. * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid.
  6960. * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**.
  6961. * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**.
  6962. * @return {Buffer} returns the Buffer object containing the serialized object.
  6963. */
  6964. function serialize$1(object, options) {
  6965. options = options || {}; // Unpack the options
  6966. var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
  6967. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  6968. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  6969. var minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; // Resize the internal serialization buffer if needed
  6970. if (buffer$1.length < minInternalBufferSize) {
  6971. buffer$1 = Buffer$6.alloc(minInternalBufferSize);
  6972. } // Attempt to serialize
  6973. var serializationIndex = serializer(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []); // Create the final buffer
  6974. var finishedBuffer = Buffer$6.alloc(serializationIndex); // Copy into the finished buffer
  6975. buffer$1.copy(finishedBuffer, 0, 0, finishedBuffer.length); // Return the buffer
  6976. return finishedBuffer;
  6977. }
  6978. /**
  6979. * Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.
  6980. *
  6981. * @param {Object} object the Javascript object to serialize.
  6982. * @param {Buffer} buffer the Buffer you pre-allocated to store the serialized BSON object.
  6983. * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid.
  6984. * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**.
  6985. * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**.
  6986. * @param {Number} [options.index] the index in the buffer where we wish to start serializing into.
  6987. * @return {Number} returns the index pointing to the last written byte in the buffer.
  6988. */
  6989. function serializeWithBufferAndIndex(object, finalBuffer, options) {
  6990. options = options || {}; // Unpack the options
  6991. var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
  6992. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  6993. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  6994. var startIndex = typeof options.index === 'number' ? options.index : 0; // Attempt to serialize
  6995. var serializationIndex = serializer(buffer$1, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
  6996. buffer$1.copy(finalBuffer, startIndex, 0, serializationIndex); // Return the index
  6997. return startIndex + serializationIndex - 1;
  6998. }
  6999. /**
  7000. * Deserialize data as BSON.
  7001. *
  7002. * @param {Buffer} buffer the buffer containing the serialized set of BSON documents.
  7003. * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.
  7004. * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.
  7005. * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
  7006. * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
  7007. * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
  7008. * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
  7009. * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
  7010. * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
  7011. * @param {boolean} [options.allowObjectSmallerThanBufferSize=false] allows the buffer to be larger than the parsed BSON object
  7012. * @return {Object} returns the deserialized Javascript Object.
  7013. */
  7014. function deserialize$2(buffer$$1, options) {
  7015. buffer$$1 = ensure_buffer(buffer$$1);
  7016. return deserializer(buffer$$1, options);
  7017. }
  7018. /**
  7019. * Calculate the bson size for a passed in Javascript object.
  7020. *
  7021. * @param {Object} object the Javascript object to calculate the BSON byte size for.
  7022. * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**.
  7023. * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**.
  7024. * @return {Number} returns the number of bytes the BSON object will take up.
  7025. */
  7026. function calculateObjectSize$1(object, options) {
  7027. options = options || {};
  7028. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  7029. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  7030. return calculate_size(object, serializeFunctions, ignoreUndefined);
  7031. }
  7032. /**
  7033. * Deserialize stream data as BSON documents.
  7034. *
  7035. * @param {Buffer} data the buffer containing the serialized set of BSON documents.
  7036. * @param {Number} startIndex the start index in the data Buffer where the deserialization is to start.
  7037. * @param {Number} numberOfDocuments number of documents to deserialize.
  7038. * @param {Array} documents an array where to store the deserialized documents.
  7039. * @param {Number} docStartIndex the index in the documents array from where to start inserting documents.
  7040. * @param {Object} [options] additional options used for the deserialization.
  7041. * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized.
  7042. * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse.
  7043. * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function.
  7044. * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits
  7045. * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance.
  7046. * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types.
  7047. * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer.
  7048. * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances.
  7049. * @return {Number} returns the next index in the buffer after deserialization **x** numbers of documents.
  7050. */
  7051. function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
  7052. options = Object.assign({
  7053. allowObjectSmallerThanBufferSize: true
  7054. }, options);
  7055. data = ensure_buffer(data);
  7056. var index = startIndex; // Loop over all documents
  7057. for (var i = 0; i < numberOfDocuments; i++) {
  7058. // Find size of the document
  7059. var size = data[index] | data[index + 1] << 8 | data[index + 2] << 16 | data[index + 3] << 24; // Update options with index
  7060. options.index = index; // Parse the document at this point
  7061. documents[docStartIndex + i] = deserializer(data, options); // Adjust index by the document size
  7062. index = index + size;
  7063. } // Return object containing end index of parsing and list of documents
  7064. return index;
  7065. }
  7066. var bson = {
  7067. // constants
  7068. // NOTE: this is done this way because rollup can't resolve an `Object.assign`ed export
  7069. BSON_INT32_MAX: constants.BSON_INT32_MAX,
  7070. BSON_INT32_MIN: constants.BSON_INT32_MIN,
  7071. BSON_INT64_MAX: constants.BSON_INT64_MAX,
  7072. BSON_INT64_MIN: constants.BSON_INT64_MIN,
  7073. JS_INT_MAX: constants.JS_INT_MAX,
  7074. JS_INT_MIN: constants.JS_INT_MIN,
  7075. BSON_DATA_NUMBER: constants.BSON_DATA_NUMBER,
  7076. BSON_DATA_STRING: constants.BSON_DATA_STRING,
  7077. BSON_DATA_OBJECT: constants.BSON_DATA_OBJECT,
  7078. BSON_DATA_ARRAY: constants.BSON_DATA_ARRAY,
  7079. BSON_DATA_BINARY: constants.BSON_DATA_BINARY,
  7080. BSON_DATA_UNDEFINED: constants.BSON_DATA_UNDEFINED,
  7081. BSON_DATA_OID: constants.BSON_DATA_OID,
  7082. BSON_DATA_BOOLEAN: constants.BSON_DATA_BOOLEAN,
  7083. BSON_DATA_DATE: constants.BSON_DATA_DATE,
  7084. BSON_DATA_NULL: constants.BSON_DATA_NULL,
  7085. BSON_DATA_REGEXP: constants.BSON_DATA_REGEXP,
  7086. BSON_DATA_DBPOINTER: constants.BSON_DATA_DBPOINTER,
  7087. BSON_DATA_CODE: constants.BSON_DATA_CODE,
  7088. BSON_DATA_SYMBOL: constants.BSON_DATA_SYMBOL,
  7089. BSON_DATA_CODE_W_SCOPE: constants.BSON_DATA_CODE_W_SCOPE,
  7090. BSON_DATA_INT: constants.BSON_DATA_INT,
  7091. BSON_DATA_TIMESTAMP: constants.BSON_DATA_TIMESTAMP,
  7092. BSON_DATA_LONG: constants.BSON_DATA_LONG,
  7093. BSON_DATA_DECIMAL128: constants.BSON_DATA_DECIMAL128,
  7094. BSON_DATA_MIN_KEY: constants.BSON_DATA_MIN_KEY,
  7095. BSON_DATA_MAX_KEY: constants.BSON_DATA_MAX_KEY,
  7096. BSON_BINARY_SUBTYPE_DEFAULT: constants.BSON_BINARY_SUBTYPE_DEFAULT,
  7097. BSON_BINARY_SUBTYPE_FUNCTION: constants.BSON_BINARY_SUBTYPE_FUNCTION,
  7098. BSON_BINARY_SUBTYPE_BYTE_ARRAY: constants.BSON_BINARY_SUBTYPE_BYTE_ARRAY,
  7099. BSON_BINARY_SUBTYPE_UUID: constants.BSON_BINARY_SUBTYPE_UUID,
  7100. BSON_BINARY_SUBTYPE_MD5: constants.BSON_BINARY_SUBTYPE_MD5,
  7101. BSON_BINARY_SUBTYPE_USER_DEFINED: constants.BSON_BINARY_SUBTYPE_USER_DEFINED,
  7102. // wrapped types
  7103. Code: code$1,
  7104. Map: map,
  7105. BSONSymbol: symbol,
  7106. DBRef: db_ref,
  7107. Binary: binary,
  7108. ObjectId: objectid,
  7109. Long: long_1$1,
  7110. Timestamp: timestamp,
  7111. Double: double_1,
  7112. Int32: int_32,
  7113. MinKey: min_key,
  7114. MaxKey: max_key,
  7115. BSONRegExp: regexp,
  7116. Decimal128: decimal128,
  7117. // methods
  7118. serialize: serialize$1,
  7119. serializeWithBufferAndIndex: serializeWithBufferAndIndex,
  7120. deserialize: deserialize$2,
  7121. calculateObjectSize: calculateObjectSize$1,
  7122. deserializeStream: deserializeStream,
  7123. setInternalBufferSize: setInternalBufferSize,
  7124. // legacy support
  7125. ObjectID: objectid,
  7126. // Extended JSON
  7127. EJSON: extended_json
  7128. };
  7129. var bson_1 = bson.BSON_INT32_MAX;
  7130. var bson_2 = bson.BSON_INT32_MIN;
  7131. var bson_3 = bson.BSON_INT64_MAX;
  7132. var bson_4 = bson.BSON_INT64_MIN;
  7133. var bson_5 = bson.JS_INT_MAX;
  7134. var bson_6 = bson.JS_INT_MIN;
  7135. var bson_7 = bson.BSON_DATA_NUMBER;
  7136. var bson_8 = bson.BSON_DATA_STRING;
  7137. var bson_9 = bson.BSON_DATA_OBJECT;
  7138. var bson_10 = bson.BSON_DATA_ARRAY;
  7139. var bson_11 = bson.BSON_DATA_BINARY;
  7140. var bson_12 = bson.BSON_DATA_UNDEFINED;
  7141. var bson_13 = bson.BSON_DATA_OID;
  7142. var bson_14 = bson.BSON_DATA_BOOLEAN;
  7143. var bson_15 = bson.BSON_DATA_DATE;
  7144. var bson_16 = bson.BSON_DATA_NULL;
  7145. var bson_17 = bson.BSON_DATA_REGEXP;
  7146. var bson_18 = bson.BSON_DATA_DBPOINTER;
  7147. var bson_19 = bson.BSON_DATA_CODE;
  7148. var bson_20 = bson.BSON_DATA_SYMBOL;
  7149. var bson_21 = bson.BSON_DATA_CODE_W_SCOPE;
  7150. var bson_22 = bson.BSON_DATA_INT;
  7151. var bson_23 = bson.BSON_DATA_TIMESTAMP;
  7152. var bson_24 = bson.BSON_DATA_LONG;
  7153. var bson_25 = bson.BSON_DATA_DECIMAL128;
  7154. var bson_26 = bson.BSON_DATA_MIN_KEY;
  7155. var bson_27 = bson.BSON_DATA_MAX_KEY;
  7156. var bson_28 = bson.BSON_BINARY_SUBTYPE_DEFAULT;
  7157. var bson_29 = bson.BSON_BINARY_SUBTYPE_FUNCTION;
  7158. var bson_30 = bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY;
  7159. var bson_31 = bson.BSON_BINARY_SUBTYPE_UUID;
  7160. var bson_32 = bson.BSON_BINARY_SUBTYPE_MD5;
  7161. var bson_33 = bson.BSON_BINARY_SUBTYPE_USER_DEFINED;
  7162. var bson_34 = bson.Code;
  7163. var bson_35 = bson.BSONSymbol;
  7164. var bson_36 = bson.DBRef;
  7165. var bson_37 = bson.Binary;
  7166. var bson_38 = bson.ObjectId;
  7167. var bson_39 = bson.Long;
  7168. var bson_40 = bson.Timestamp;
  7169. var bson_41 = bson.Double;
  7170. var bson_42 = bson.Int32;
  7171. var bson_43 = bson.MinKey;
  7172. var bson_44 = bson.MaxKey;
  7173. var bson_45 = bson.BSONRegExp;
  7174. var bson_46 = bson.Decimal128;
  7175. var bson_47 = bson.serialize;
  7176. var bson_48 = bson.serializeWithBufferAndIndex;
  7177. var bson_49 = bson.deserialize;
  7178. var bson_50 = bson.calculateObjectSize;
  7179. var bson_51 = bson.deserializeStream;
  7180. var bson_52 = bson.setInternalBufferSize;
  7181. var bson_53 = bson.ObjectID;
  7182. var bson_54 = bson.EJSON;
  7183. exports.default = bson;
  7184. exports.BSON_INT32_MAX = bson_1;
  7185. exports.BSON_INT32_MIN = bson_2;
  7186. exports.BSON_INT64_MAX = bson_3;
  7187. exports.BSON_INT64_MIN = bson_4;
  7188. exports.JS_INT_MAX = bson_5;
  7189. exports.JS_INT_MIN = bson_6;
  7190. exports.BSON_DATA_NUMBER = bson_7;
  7191. exports.BSON_DATA_STRING = bson_8;
  7192. exports.BSON_DATA_OBJECT = bson_9;
  7193. exports.BSON_DATA_ARRAY = bson_10;
  7194. exports.BSON_DATA_BINARY = bson_11;
  7195. exports.BSON_DATA_UNDEFINED = bson_12;
  7196. exports.BSON_DATA_OID = bson_13;
  7197. exports.BSON_DATA_BOOLEAN = bson_14;
  7198. exports.BSON_DATA_DATE = bson_15;
  7199. exports.BSON_DATA_NULL = bson_16;
  7200. exports.BSON_DATA_REGEXP = bson_17;
  7201. exports.BSON_DATA_DBPOINTER = bson_18;
  7202. exports.BSON_DATA_CODE = bson_19;
  7203. exports.BSON_DATA_SYMBOL = bson_20;
  7204. exports.BSON_DATA_CODE_W_SCOPE = bson_21;
  7205. exports.BSON_DATA_INT = bson_22;
  7206. exports.BSON_DATA_TIMESTAMP = bson_23;
  7207. exports.BSON_DATA_LONG = bson_24;
  7208. exports.BSON_DATA_DECIMAL128 = bson_25;
  7209. exports.BSON_DATA_MIN_KEY = bson_26;
  7210. exports.BSON_DATA_MAX_KEY = bson_27;
  7211. exports.BSON_BINARY_SUBTYPE_DEFAULT = bson_28;
  7212. exports.BSON_BINARY_SUBTYPE_FUNCTION = bson_29;
  7213. exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = bson_30;
  7214. exports.BSON_BINARY_SUBTYPE_UUID = bson_31;
  7215. exports.BSON_BINARY_SUBTYPE_MD5 = bson_32;
  7216. exports.BSON_BINARY_SUBTYPE_USER_DEFINED = bson_33;
  7217. exports.Code = bson_34;
  7218. exports.BSONSymbol = bson_35;
  7219. exports.DBRef = bson_36;
  7220. exports.Binary = bson_37;
  7221. exports.ObjectId = bson_38;
  7222. exports.Long = bson_39;
  7223. exports.Timestamp = bson_40;
  7224. exports.Double = bson_41;
  7225. exports.Int32 = bson_42;
  7226. exports.MinKey = bson_43;
  7227. exports.MaxKey = bson_44;
  7228. exports.BSONRegExp = bson_45;
  7229. exports.Decimal128 = bson_46;
  7230. exports.serialize = bson_47;
  7231. exports.serializeWithBufferAndIndex = bson_48;
  7232. exports.deserialize = bson_49;
  7233. exports.calculateObjectSize = bson_50;
  7234. exports.deserializeStream = bson_51;
  7235. exports.setInternalBufferSize = bson_52;
  7236. exports.ObjectID = bson_53;
  7237. exports.EJSON = bson_54;
  7238. return exports;
  7239. }({}));