browser.umd.js 1.9 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254512555125651257512585125951260512615126251263512645126551266512675126851269512705127151272512735127451275512765127751278512795128051281512825128351284512855128651287512885128951290512915129251293512945129551296512975129851299513005130151302513035130451305513065130751308513095131051311513125131351314513155131651317513185131951320513215132251323513245132551326513275132851329513305133151332513335133451335513365133751338513395134051341513425134351344513455134651347513485134951350513515135251353513545135551356513575135851359513605136151362513635136451365513665136751368513695137051371513725137351374513755137651377513785137951380513815138251383513845138551386513875138851389513905139151392513935139451395513965139751398513995140051401514025140351404514055140651407514085140951410514115141251413514145141551416514175141851419514205142151422514235142451425514265142751428514295143051431514325143351434514355143651437514385143951440514415144251443514445144551446514475144851449514505145151452514535145451455514565145751458514595146051461514625146351464514655146651467514685146951470514715147251473514745147551476514775147851479514805148151482514835148451485514865148751488514895149051491514925149351494514955149651497514985149951500515015150251503515045150551506515075150851509515105151151512515135151451515515165151751518515195152051521515225152351524515255152651527515285152951530515315153251533515345153551536515375153851539515405154151542515435154451545515465154751548515495155051551515525155351554515555155651557515585155951560515615156251563515645156551566515675156851569515705157151572515735157451575515765157751578515795158051581515825158351584515855158651587515885158951590515915159251593515945159551596515975159851599516005160151602516035160451605516065160751608516095161051611516125161351614516155161651617516185161951620516215162251623516245162551626516275162851629516305163151632516335163451635516365163751638516395164051641516425164351644516455164651647516485164951650516515165251653516545165551656516575165851659516605166151662516635166451665516665166751668516695167051671516725167351674516755167651677516785167951680516815168251683516845168551686516875168851689516905169151692516935169451695516965169751698516995170051701517025170351704517055170651707517085170951710517115171251713517145171551716517175171851719517205172151722517235172451725517265172751728517295173051731517325173351734517355173651737517385173951740517415174251743517445174551746517475174851749517505175151752517535175451755517565175751758517595176051761517625176351764517655176651767517685176951770517715177251773517745177551776517775177851779517805178151782517835178451785517865178751788517895179051791517925179351794517955179651797517985179951800518015180251803518045180551806518075180851809518105181151812518135181451815518165181751818518195182051821518225182351824518255182651827518285182951830518315183251833518345183551836518375183851839518405184151842518435184451845518465184751848518495185051851518525185351854518555185651857518585185951860518615186251863518645186551866518675186851869518705187151872518735187451875518765187751878518795188051881518825188351884518855188651887518885188951890518915189251893518945189551896518975189851899519005190151902519035190451905519065190751908519095191051911519125191351914519155191651917519185191951920519215192251923519245192551926519275192851929519305193151932519335193451935519365193751938519395194051941519425194351944519455194651947519485194951950519515195251953519545195551956519575195851959519605196151962519635196451965519665196751968519695197051971519725197351974519755197651977519785197951980519815198251983519845198551986519875198851989519905199151992519935199451995519965199751998519995200052001520025200352004520055200652007520085200952010520115201252013520145201552016520175201852019520205202152022520235202452025520265202752028520295203052031520325203352034520355203652037520385203952040520415204252043520445204552046520475204852049520505205152052520535205452055520565205752058520595206052061520625206352064520655206652067520685206952070520715207252073520745207552076520775207852079520805208152082520835208452085520865208752088520895209052091520925209352094520955209652097520985209952100521015210252103521045210552106521075210852109521105211152112521135211452115521165211752118521195212052121521225212352124521255212652127521285212952130521315213252133521345213552136521375213852139521405214152142521435214452145521465214752148521495215052151521525215352154521555215652157521585215952160521615216252163521645216552166521675216852169521705217152172521735217452175521765217752178521795218052181521825218352184521855218652187521885218952190521915219252193521945219552196521975219852199522005220152202522035220452205522065220752208522095221052211522125221352214522155221652217522185221952220522215222252223522245222552226522275222852229522305223152232522335223452235522365223752238522395224052241522425224352244522455224652247522485224952250522515225252253522545225552256522575225852259522605226152262522635226452265522665226752268522695227052271522725227352274522755227652277522785227952280522815228252283522845228552286522875228852289522905229152292522935229452295522965229752298522995230052301523025230352304523055230652307523085230952310523115231252313523145231552316523175231852319523205232152322523235232452325523265232752328523295233052331523325233352334523355233652337523385233952340523415234252343523445234552346523475234852349523505235152352523535235452355523565235752358523595236052361523625236352364523655236652367523685236952370523715237252373523745237552376523775237852379523805238152382523835238452385523865238752388523895239052391523925239352394523955239652397523985239952400524015240252403524045240552406524075240852409524105241152412524135241452415524165241752418524195242052421524225242352424524255242652427524285242952430524315243252433524345243552436524375243852439524405244152442524435244452445524465244752448524495245052451524525245352454524555245652457524585245952460524615246252463524645246552466524675246852469524705247152472524735247452475524765247752478524795248052481524825248352484524855248652487524885248952490524915249252493524945249552496524975249852499525005250152502525035250452505525065250752508525095251052511525125251352514525155251652517525185251952520525215252252523525245252552526525275252852529525305253152532525335253452535525365253752538525395254052541525425254352544525455254652547525485254952550525515255252553525545255552556525575255852559525605256152562525635256452565525665256752568525695257052571525725257352574525755257652577525785257952580525815258252583525845258552586525875258852589525905259152592525935259452595525965259752598525995260052601526025260352604526055260652607526085260952610526115261252613526145261552616526175261852619526205262152622526235262452625526265262752628526295263052631526325263352634526355263652637526385263952640526415264252643526445264552646526475264852649526505265152652526535265452655526565265752658526595266052661526625266352664526655266652667526685266952670526715267252673526745267552676526775267852679526805268152682526835268452685526865268752688526895269052691526925269352694526955269652697526985269952700527015270252703527045270552706527075270852709527105271152712527135271452715527165271752718527195272052721527225272352724527255272652727527285272952730527315273252733527345273552736527375273852739527405274152742527435274452745527465274752748527495275052751527525275352754527555275652757527585275952760527615276252763527645276552766527675276852769527705277152772527735277452775527765277752778527795278052781527825278352784527855278652787527885278952790527915279252793527945279552796527975279852799528005280152802528035280452805528065280752808528095281052811528125281352814528155281652817528185281952820528215282252823528245282552826528275282852829528305283152832528335283452835528365283752838528395284052841528425284352844528455284652847528485284952850528515285252853528545285552856528575285852859528605286152862528635286452865528665286752868528695287052871528725287352874528755287652877528785287952880528815288252883528845288552886528875288852889528905289152892528935289452895528965289752898528995290052901529025290352904529055290652907529085290952910529115291252913529145291552916529175291852919529205292152922529235292452925529265292752928529295293052931529325293352934529355293652937529385293952940529415294252943529445294552946529475294852949529505295152952529535295452955529565295752958529595296052961529625296352964529655296652967529685296952970529715297252973529745297552976529775297852979529805298152982529835298452985529865298752988529895299052991529925299352994529955299652997529985299953000530015300253003530045300553006530075300853009530105301153012530135301453015530165301753018530195302053021530225302353024530255302653027530285302953030530315303253033530345303553036530375303853039530405304153042530435304453045530465304753048530495305053051530525305353054530555305653057530585305953060530615306253063530645306553066530675306853069530705307153072530735307453075530765307753078530795308053081530825308353084530855308653087530885308953090530915309253093530945309553096530975309853099531005310153102531035310453105531065310753108531095311053111531125311353114531155311653117531185311953120531215312253123531245312553126531275312853129531305313153132531335313453135531365313753138531395314053141531425314353144531455314653147531485314953150531515315253153531545315553156531575315853159531605316153162531635316453165531665316753168531695317053171531725317353174531755317653177531785317953180531815318253183531845318553186531875318853189531905319153192531935319453195531965319753198531995320053201532025320353204532055320653207532085320953210532115321253213532145321553216532175321853219532205322153222532235322453225532265322753228532295323053231532325323353234532355323653237532385323953240532415324253243532445324553246532475324853249532505325153252532535325453255532565325753258532595326053261532625326353264532655326653267532685326953270532715327253273532745327553276532775327853279532805328153282532835328453285532865328753288532895329053291532925329353294532955329653297532985329953300533015330253303533045330553306533075330853309533105331153312533135331453315533165331753318533195332053321533225332353324533255332653327533285332953330533315333253333533345333553336533375333853339533405334153342533435334453345533465334753348533495335053351533525335353354533555335653357533585335953360533615336253363533645336553366533675336853369533705337153372533735337453375533765337753378533795338053381533825338353384533855338653387533885338953390533915339253393533945339553396533975339853399534005340153402534035340453405534065340753408534095341053411534125341353414534155341653417534185341953420534215342253423534245342553426534275342853429534305343153432534335343453435534365343753438534395344053441534425344353444534455344653447534485344953450534515345253453534545345553456534575345853459534605346153462534635346453465534665346753468534695347053471534725347353474534755347653477534785347953480534815348253483534845348553486534875348853489534905349153492534935349453495534965349753498534995350053501535025350353504535055350653507535085350953510535115351253513535145351553516535175351853519535205352153522535235352453525535265352753528535295353053531535325353353534535355353653537535385353953540535415354253543535445354553546535475354853549535505355153552535535355453555535565355753558535595356053561535625356353564535655356653567535685356953570535715357253573535745357553576535775357853579535805358153582535835358453585535865358753588535895359053591535925359353594535955359653597535985359953600536015360253603536045360553606536075360853609536105361153612536135361453615536165361753618536195362053621536225362353624536255362653627536285362953630536315363253633536345363553636536375363853639536405364153642536435364453645536465364753648536495365053651536525365353654536555365653657536585365953660536615366253663536645366553666536675366853669536705367153672536735367453675536765367753678536795368053681536825368353684536855368653687536885368953690536915369253693536945369553696536975369853699537005370153702537035370453705537065370753708537095371053711537125371353714537155371653717537185371953720537215372253723537245372553726537275372853729537305373153732537335373453735537365373753738537395374053741537425374353744537455374653747537485374953750537515375253753537545375553756537575375853759537605376153762537635376453765537665376753768537695377053771537725377353774537755377653777537785377953780537815378253783537845378553786537875378853789537905379153792537935379453795537965379753798537995380053801538025380353804538055380653807538085380953810538115381253813538145381553816538175381853819538205382153822538235382453825538265382753828538295383053831538325383353834538355383653837538385383953840538415384253843538445384553846538475384853849538505385153852538535385453855538565385753858538595386053861538625386353864538655386653867538685386953870538715387253873538745387553876538775387853879538805388153882538835388453885538865388753888538895389053891538925389353894538955389653897538985389953900539015390253903539045390553906539075390853909539105391153912539135391453915539165391753918539195392053921539225392353924539255392653927539285392953930539315393253933539345393553936539375393853939539405394153942539435394453945539465394753948539495395053951539525395353954539555395653957539585395953960539615396253963539645396553966539675396853969539705397153972539735397453975539765397753978539795398053981539825398353984539855398653987539885398953990539915399253993539945399553996539975399853999540005400154002540035400454005540065400754008540095401054011540125401354014540155401654017540185401954020540215402254023540245402554026540275402854029540305403154032540335403454035540365403754038540395404054041540425404354044540455404654047540485404954050540515405254053540545405554056540575405854059540605406154062540635406454065540665406754068540695407054071540725407354074540755407654077540785407954080540815408254083540845408554086540875408854089540905409154092540935409454095540965409754098540995410054101541025410354104541055410654107541085410954110541115411254113541145411554116541175411854119541205412154122541235412454125541265412754128541295413054131541325413354134541355413654137541385413954140541415414254143541445414554146541475414854149541505415154152541535415454155541565415754158541595416054161541625416354164541655416654167541685416954170541715417254173541745417554176541775417854179541805418154182541835418454185541865418754188541895419054191541925419354194541955419654197541985419954200542015420254203542045420554206542075420854209542105421154212542135421454215542165421754218542195422054221542225422354224542255422654227542285422954230542315423254233542345423554236542375423854239542405424154242542435424454245542465424754248542495425054251542525425354254542555425654257542585425954260542615426254263542645426554266542675426854269542705427154272542735427454275542765427754278542795428054281542825428354284542855428654287542885428954290542915429254293542945429554296542975429854299543005430154302543035430454305543065430754308543095431054311543125431354314543155431654317543185431954320543215432254323543245432554326543275432854329543305433154332543335433454335543365433754338543395434054341543425434354344543455434654347543485434954350543515435254353543545435554356543575435854359543605436154362543635436454365543665436754368543695437054371543725437354374543755437654377543785437954380543815438254383543845438554386543875438854389543905439154392543935439454395543965439754398543995440054401544025440354404544055440654407544085440954410544115441254413544145441554416544175441854419544205442154422544235442454425544265442754428544295443054431544325443354434544355443654437544385443954440544415444254443544445444554446544475444854449544505445154452544535445454455544565445754458544595446054461544625446354464544655446654467544685446954470544715447254473544745447554476544775447854479544805448154482544835448454485544865448754488544895449054491544925449354494544955449654497544985449954500545015450254503545045450554506545075450854509545105451154512545135451454515545165451754518545195452054521545225452354524545255452654527545285452954530545315453254533545345453554536545375453854539545405454154542545435454454545545465454754548545495455054551545525455354554545555455654557545585455954560545615456254563545645456554566545675456854569545705457154572545735457454575545765457754578545795458054581545825458354584545855458654587545885458954590545915459254593545945459554596545975459854599546005460154602546035460454605546065460754608546095461054611546125461354614546155461654617546185461954620546215462254623546245462554626546275462854629546305463154632546335463454635546365463754638546395464054641546425464354644546455464654647546485464954650546515465254653546545465554656546575465854659546605466154662546635466454665546665466754668546695467054671546725467354674546755467654677546785467954680546815468254683546845468554686546875468854689546905469154692546935469454695546965469754698546995470054701547025470354704547055470654707547085470954710547115471254713547145471554716547175471854719547205472154722547235472454725547265472754728547295473054731547325473354734547355473654737547385473954740547415474254743547445474554746547475474854749547505475154752547535475454755547565475754758547595476054761547625476354764547655476654767547685476954770547715477254773547745477554776547775477854779547805478154782547835478454785547865478754788547895479054791547925479354794547955479654797547985479954800548015480254803548045480554806548075480854809548105481154812548135481454815548165481754818548195482054821548225482354824548255482654827548285482954830548315483254833548345483554836548375483854839548405484154842548435484454845548465484754848548495485054851548525485354854548555485654857548585485954860548615486254863548645486554866548675486854869548705487154872548735487454875548765487754878548795488054881548825488354884548855488654887548885488954890548915489254893548945489554896548975489854899549005490154902549035490454905549065490754908549095491054911549125491354914549155491654917549185491954920549215492254923549245492554926549275492854929549305493154932549335493454935549365493754938549395494054941549425494354944549455494654947549485494954950549515495254953549545495554956549575495854959549605496154962549635496454965549665496754968549695497054971549725497354974549755497654977549785497954980549815498254983549845498554986549875498854989549905499154992549935499454995549965499754998549995500055001550025500355004550055500655007550085500955010550115501255013550145501555016550175501855019550205502155022550235502455025550265502755028550295503055031550325503355034550355503655037550385503955040550415504255043550445504555046550475504855049550505505155052550535505455055550565505755058550595506055061550625506355064550655506655067550685506955070550715507255073550745507555076550775507855079550805508155082550835508455085550865508755088550895509055091550925509355094550955509655097550985509955100551015510255103551045510555106551075510855109551105511155112551135511455115551165511755118551195512055121551225512355124551255512655127551285512955130551315513255133551345513555136551375513855139551405514155142551435514455145551465514755148551495515055151551525515355154551555515655157551585515955160551615516255163551645516555166551675516855169551705517155172551735517455175551765517755178551795518055181551825518355184551855518655187551885518955190551915519255193551945519555196551975519855199552005520155202552035520455205552065520755208552095521055211552125521355214552155521655217552185521955220552215522255223552245522555226552275522855229552305523155232552335523455235552365523755238552395524055241552425524355244552455524655247552485524955250552515525255253552545525555256552575525855259552605526155262552635526455265552665526755268552695527055271552725527355274552755527655277552785527955280552815528255283552845528555286552875528855289552905529155292552935529455295552965529755298552995530055301553025530355304553055530655307553085530955310553115531255313553145531555316553175531855319553205532155322553235532455325553265532755328553295533055331553325533355334553355533655337553385533955340553415534255343553445534555346553475534855349553505535155352553535535455355553565535755358553595536055361553625536355364553655536655367553685536955370553715537255373553745537555376553775537855379553805538155382553835538455385553865538755388553895539055391553925539355394553955539655397553985539955400554015540255403554045540555406554075540855409554105541155412554135541455415554165541755418554195542055421554225542355424554255542655427554285542955430554315543255433554345543555436554375543855439554405544155442554435544455445554465544755448554495545055451554525545355454554555545655457554585545955460554615546255463554645546555466554675546855469554705547155472554735547455475554765547755478554795548055481554825548355484554855548655487554885548955490554915549255493554945549555496554975549855499555005550155502555035550455505555065550755508555095551055511555125551355514555155551655517555185551955520555215552255523555245552555526555275552855529555305553155532555335553455535555365553755538555395554055541555425554355544555455554655547555485554955550555515555255553555545555555556555575555855559555605556155562555635556455565555665556755568555695557055571555725557355574555755557655577555785557955580555815558255583555845558555586555875558855589555905559155592555935559455595555965559755598555995560055601556025560355604556055560655607556085560955610556115561255613556145561555616556175561855619556205562155622556235562455625556265562755628556295563055631556325563355634556355563655637556385563955640556415564255643556445564555646556475564855649556505565155652556535565455655556565565755658556595566055661556625566355664556655566655667556685566955670556715567255673556745567555676556775567855679556805568155682556835568455685556865568755688556895569055691556925569355694556955569655697556985569955700557015570255703557045570555706557075570855709557105571155712557135571455715557165571755718557195572055721557225572355724557255572655727557285572955730557315573255733557345573555736557375573855739557405574155742557435574455745557465574755748557495575055751557525575355754557555575655757557585575955760557615576255763557645576555766557675576855769557705577155772557735577455775557765577755778557795578055781557825578355784557855578655787557885578955790557915579255793557945579555796557975579855799558005580155802558035580455805558065580755808558095581055811558125581355814558155581655817558185581955820558215582255823558245582555826558275582855829558305583155832558335583455835558365583755838558395584055841558425584355844558455584655847558485584955850558515585255853558545585555856558575585855859558605586155862558635586455865558665586755868558695587055871558725587355874558755587655877558785587955880558815588255883558845588555886558875588855889558905589155892558935589455895558965589755898558995590055901559025590355904559055590655907559085590955910559115591255913559145591555916559175591855919559205592155922559235592455925559265592755928559295593055931559325593355934559355593655937559385593955940559415594255943559445594555946559475594855949559505595155952559535595455955559565595755958559595596055961559625596355964559655596655967559685596955970559715597255973559745597555976559775597855979559805598155982559835598455985559865598755988559895599055991559925599355994559955599655997559985599956000560015600256003560045600556006560075600856009560105601156012560135601456015560165601756018560195602056021560225602356024560255602656027560285602956030560315603256033560345603556036560375603856039560405604156042560435604456045560465604756048560495605056051560525605356054560555605656057560585605956060560615606256063560645606556066560675606856069560705607156072560735607456075560765607756078560795608056081560825608356084560855608656087560885608956090560915609256093560945609556096560975609856099561005610156102561035610456105561065610756108561095611056111561125611356114561155611656117561185611956120561215612256123561245612556126561275612856129561305613156132561335613456135561365613756138561395614056141561425614356144561455614656147561485614956150561515615256153561545615556156561575615856159561605616156162561635616456165561665616756168561695617056171561725617356174561755617656177561785617956180561815618256183561845618556186561875618856189561905619156192561935619456195561965619756198561995620056201562025620356204562055620656207562085620956210562115621256213562145621556216562175621856219562205622156222562235622456225562265622756228562295623056231562325623356234562355623656237562385623956240562415624256243562445624556246562475624856249562505625156252562535625456255562565625756258562595626056261562625626356264562655626656267562685626956270562715627256273562745627556276562775627856279562805628156282562835628456285562865628756288562895629056291562925629356294562955629656297562985629956300563015630256303563045630556306563075630856309563105631156312563135631456315563165631756318563195632056321563225632356324563255632656327563285632956330563315633256333563345633556336563375633856339563405634156342563435634456345563465634756348563495635056351563525635356354563555635656357563585635956360563615636256363563645636556366563675636856369563705637156372563735637456375563765637756378563795638056381563825638356384563855638656387563885638956390563915639256393563945639556396563975639856399564005640156402564035640456405564065640756408564095641056411564125641356414564155641656417564185641956420564215642256423564245642556426564275642856429564305643156432564335643456435564365643756438564395644056441564425644356444564455644656447564485644956450564515645256453564545645556456564575645856459564605646156462564635646456465564665646756468564695647056471564725647356474564755647656477564785647956480564815648256483564845648556486564875648856489564905649156492564935649456495564965649756498564995650056501565025650356504565055650656507565085650956510565115651256513565145651556516565175651856519565205652156522565235652456525565265652756528565295653056531565325653356534565355653656537565385653956540565415654256543565445654556546565475654856549565505655156552565535655456555565565655756558565595656056561565625656356564565655656656567565685656956570565715657256573565745657556576565775657856579565805658156582565835658456585565865658756588565895659056591565925659356594565955659656597565985659956600566015660256603566045660556606566075660856609566105661156612566135661456615566165661756618566195662056621566225662356624566255662656627566285662956630566315663256633566345663556636566375663856639566405664156642566435664456645566465664756648566495665056651566525665356654566555665656657566585665956660566615666256663566645666556666566675666856669566705667156672566735667456675566765667756678566795668056681566825668356684566855668656687566885668956690566915669256693566945669556696566975669856699567005670156702567035670456705567065670756708567095671056711567125671356714567155671656717567185671956720567215672256723567245672556726567275672856729567305673156732567335673456735567365673756738567395674056741567425674356744567455674656747567485674956750567515675256753567545675556756567575675856759567605676156762567635676456765567665676756768567695677056771567725677356774567755677656777567785677956780567815678256783567845678556786567875678856789567905679156792567935679456795567965679756798567995680056801568025680356804568055680656807568085680956810568115681256813568145681556816568175681856819568205682156822568235682456825568265682756828568295683056831568325683356834568355683656837568385683956840568415684256843568445684556846568475684856849568505685156852568535685456855568565685756858568595686056861568625686356864568655686656867568685686956870568715687256873568745687556876568775687856879568805688156882568835688456885568865688756888568895689056891568925689356894568955689656897568985689956900569015690256903569045690556906569075690856909569105691156912569135691456915569165691756918569195692056921569225692356924569255692656927569285692956930569315693256933569345693556936569375693856939569405694156942569435694456945569465694756948569495695056951569525695356954569555695656957569585695956960569615696256963569645696556966569675696856969569705697156972569735697456975569765697756978569795698056981569825698356984569855698656987569885698956990569915699256993569945699556996569975699856999570005700157002570035700457005570065700757008570095701057011570125701357014570155701657017570185701957020570215702257023570245702557026570275702857029570305703157032570335703457035570365703757038570395704057041570425704357044570455704657047570485704957050570515705257053570545705557056570575705857059570605706157062570635706457065570665706757068570695707057071570725707357074570755707657077570785707957080570815708257083570845708557086570875708857089570905709157092570935709457095570965709757098570995710057101571025710357104571055710657107571085710957110571115711257113571145711557116571175711857119571205712157122571235712457125571265712757128571295713057131571325713357134571355713657137571385713957140571415714257143571445714557146571475714857149571505715157152571535715457155571565715757158571595716057161571625716357164571655716657167571685716957170571715717257173571745717557176571775717857179571805718157182571835718457185571865718757188571895719057191571925719357194571955719657197571985719957200572015720257203572045720557206572075720857209572105721157212572135721457215572165721757218572195722057221572225722357224572255722657227572285722957230572315723257233572345723557236572375723857239572405724157242572435724457245572465724757248572495725057251572525725357254572555725657257572585725957260572615726257263572645726557266572675726857269572705727157272572735727457275572765727757278572795728057281572825728357284572855728657287572885728957290572915729257293572945729557296572975729857299573005730157302573035730457305573065730757308573095731057311573125731357314573155731657317573185731957320573215732257323573245732557326573275732857329573305733157332573335733457335573365733757338573395734057341573425734357344573455734657347573485734957350573515735257353573545735557356573575735857359573605736157362573635736457365573665736757368573695737057371573725737357374573755737657377573785737957380573815738257383573845738557386573875738857389573905739157392573935739457395573965739757398573995740057401574025740357404574055740657407574085740957410574115741257413574145741557416574175741857419574205742157422574235742457425574265742757428574295743057431574325743357434574355743657437574385743957440574415744257443574445744557446574475744857449574505745157452574535745457455574565745757458574595746057461574625746357464574655746657467574685746957470574715747257473574745747557476574775747857479574805748157482574835748457485574865748757488574895749057491574925749357494574955749657497574985749957500575015750257503575045750557506575075750857509575105751157512575135751457515575165751757518575195752057521575225752357524575255752657527575285752957530575315753257533575345753557536575375753857539575405754157542575435754457545575465754757548575495755057551575525755357554575555755657557575585755957560575615756257563575645756557566575675756857569575705757157572575735757457575575765757757578575795758057581575825758357584575855758657587575885758957590575915759257593575945759557596575975759857599576005760157602576035760457605576065760757608576095761057611576125761357614576155761657617576185761957620576215762257623576245762557626576275762857629576305763157632576335763457635576365763757638576395764057641576425764357644576455764657647576485764957650576515765257653576545765557656576575765857659576605766157662576635766457665576665766757668576695767057671576725767357674576755767657677576785767957680576815768257683576845768557686576875768857689576905769157692576935769457695576965769757698576995770057701577025770357704577055770657707577085770957710577115771257713577145771557716577175771857719577205772157722577235772457725577265772757728577295773057731577325773357734577355773657737577385773957740577415774257743577445774557746577475774857749577505775157752577535775457755577565775757758577595776057761577625776357764577655776657767577685776957770577715777257773577745777557776577775777857779577805778157782577835778457785577865778757788577895779057791577925779357794577955779657797577985779957800578015780257803578045780557806578075780857809578105781157812578135781457815578165781757818578195782057821578225782357824578255782657827578285782957830578315783257833578345783557836578375783857839578405784157842578435784457845578465784757848578495785057851578525785357854578555785657857578585785957860578615786257863578645786557866578675786857869578705787157872578735787457875578765787757878578795788057881578825788357884578855788657887578885788957890578915789257893578945789557896578975789857899579005790157902579035790457905579065790757908579095791057911579125791357914579155791657917579185791957920579215792257923579245792557926579275792857929579305793157932579335793457935579365793757938579395794057941579425794357944579455794657947579485794957950579515795257953579545795557956579575795857959579605796157962579635796457965579665796757968579695797057971579725797357974579755797657977579785797957980579815798257983579845798557986579875798857989579905799157992579935799457995579965799757998579995800058001580025800358004580055800658007580085800958010580115801258013580145801558016580175801858019580205802158022580235802458025580265802758028580295803058031580325803358034580355803658037580385803958040580415804258043580445804558046580475804858049580505805158052580535805458055580565805758058580595806058061580625806358064580655806658067580685806958070580715807258073580745807558076580775807858079580805808158082580835808458085580865808758088580895809058091580925809358094580955809658097580985809958100581015810258103581045810558106581075810858109581105811158112581135811458115581165811758118581195812058121581225812358124581255812658127581285812958130581315813258133581345813558136581375813858139581405814158142581435814458145581465814758148581495815058151581525815358154581555815658157581585815958160581615816258163581645816558166581675816858169581705817158172581735817458175581765817758178581795818058181581825818358184581855818658187581885818958190581915819258193581945819558196581975819858199582005820158202582035820458205582065820758208582095821058211582125821358214582155821658217582185821958220582215822258223582245822558226582275822858229582305823158232582335823458235582365823758238582395824058241582425824358244582455824658247582485824958250582515825258253582545825558256582575825858259582605826158262582635826458265582665826758268582695827058271582725827358274582755827658277582785827958280582815828258283582845828558286582875828858289582905829158292582935829458295582965829758298582995830058301583025830358304583055830658307583085830958310583115831258313583145831558316583175831858319583205832158322583235832458325583265832758328583295833058331583325833358334583355833658337583385833958340583415834258343583445834558346583475834858349583505835158352583535835458355583565835758358583595836058361583625836358364583655836658367583685836958370583715837258373583745837558376583775837858379583805838158382583835838458385583865838758388583895839058391583925839358394583955839658397583985839958400584015840258403584045840558406584075840858409584105841158412584135841458415584165841758418584195842058421584225842358424584255842658427584285842958430584315843258433584345843558436584375843858439584405844158442584435844458445584465844758448584495845058451584525845358454584555845658457584585845958460584615846258463584645846558466584675846858469584705847158472584735847458475584765847758478584795848058481584825848358484584855848658487584885848958490584915849258493584945849558496584975849858499585005850158502585035850458505585065850758508585095851058511585125851358514585155851658517585185851958520585215852258523585245852558526585275852858529585305853158532585335853458535585365853758538585395854058541585425854358544585455854658547585485854958550585515855258553585545855558556585575855858559585605856158562585635856458565585665856758568585695857058571585725857358574585755857658577585785857958580585815858258583585845858558586585875858858589585905859158592585935859458595585965859758598585995860058601586025860358604586055860658607586085860958610586115861258613586145861558616586175861858619586205862158622586235862458625586265862758628586295863058631586325863358634586355863658637586385863958640586415864258643586445864558646586475864858649586505865158652586535865458655586565865758658586595866058661586625866358664586655866658667586685866958670586715867258673586745867558676586775867858679586805868158682586835868458685586865868758688586895869058691586925869358694586955869658697586985869958700587015870258703587045870558706587075870858709587105871158712587135871458715587165871758718587195872058721587225872358724587255872658727587285872958730587315873258733587345873558736587375873858739587405874158742587435874458745587465874758748587495875058751587525875358754587555875658757587585875958760587615876258763587645876558766587675876858769587705877158772587735877458775587765877758778587795878058781587825878358784587855878658787587885878958790587915879258793587945879558796587975879858799588005880158802588035880458805588065880758808588095881058811588125881358814588155881658817588185881958820588215882258823588245882558826588275882858829588305883158832588335883458835588365883758838588395884058841588425884358844588455884658847588485884958850588515885258853588545885558856588575885858859588605886158862588635886458865588665886758868588695887058871588725887358874588755887658877588785887958880588815888258883588845888558886588875888858889588905889158892588935889458895588965889758898588995890058901589025890358904589055890658907589085890958910589115891258913589145891558916589175891858919589205892158922589235892458925589265892758928589295893058931589325893358934589355893658937589385893958940589415894258943589445894558946589475894858949589505895158952589535895458955589565895758958589595896058961589625896358964589655896658967589685896958970589715897258973589745897558976589775897858979589805898158982589835898458985589865898758988589895899058991589925899358994589955899658997589985899959000590015900259003590045900559006590075900859009590105901159012590135901459015590165901759018590195902059021590225902359024590255902659027590285902959030590315903259033590345903559036590375903859039590405904159042590435904459045590465904759048590495905059051590525905359054590555905659057590585905959060590615906259063590645906559066590675906859069590705907159072590735907459075590765907759078590795908059081590825908359084590855908659087590885908959090590915909259093590945909559096590975909859099591005910159102591035910459105591065910759108591095911059111591125911359114591155911659117591185911959120591215912259123591245912559126591275912859129591305913159132591335913459135591365913759138591395914059141591425914359144591455914659147591485914959150591515915259153591545915559156591575915859159591605916159162591635916459165591665916759168591695917059171591725917359174591755917659177591785917959180591815918259183591845918559186591875918859189591905919159192591935919459195591965919759198591995920059201592025920359204592055920659207592085920959210592115921259213592145921559216592175921859219592205922159222592235922459225592265922759228592295923059231592325923359234592355923659237592385923959240592415924259243592445924559246592475924859249592505925159252592535925459255592565925759258592595926059261592625926359264592655926659267592685926959270592715927259273592745927559276592775927859279592805928159282592835928459285592865928759288592895929059291592925929359294592955929659297592985929959300593015930259303593045930559306593075930859309593105931159312593135931459315593165931759318593195932059321593225932359324593255932659327593285932959330593315933259333593345933559336593375933859339593405934159342593435934459345593465934759348593495935059351593525935359354593555935659357593585935959360593615936259363593645936559366593675936859369593705937159372593735937459375593765937759378593795938059381593825938359384593855938659387593885938959390593915939259393593945939559396593975939859399594005940159402594035940459405594065940759408594095941059411594125941359414594155941659417594185941959420594215942259423594245942559426594275942859429594305943159432594335943459435594365943759438594395944059441594425944359444594455944659447594485944959450594515945259453594545945559456594575945859459594605946159462594635946459465594665946759468594695947059471594725947359474594755947659477594785947959480594815948259483594845948559486594875948859489594905949159492594935949459495594965949759498594995950059501595025950359504595055950659507595085950959510595115951259513595145951559516595175951859519595205952159522595235952459525595265952759528595295953059531595325953359534595355953659537595385953959540595415954259543595445954559546595475954859549595505955159552595535955459555595565955759558595595956059561595625956359564595655956659567595685956959570595715957259573595745957559576595775957859579595805958159582595835958459585595865958759588595895959059591595925959359594595955959659597595985959959600596015960259603596045960559606596075960859609596105961159612596135961459615596165961759618596195962059621596225962359624596255962659627596285962959630596315963259633596345963559636596375963859639596405964159642596435964459645596465964759648596495965059651596525965359654596555965659657596585965959660596615966259663596645966559666596675966859669596705967159672596735967459675596765967759678596795968059681596825968359684596855968659687596885968959690596915969259693596945969559696596975969859699597005970159702597035970459705597065970759708597095971059711597125971359714597155971659717597185971959720597215972259723597245972559726597275972859729597305973159732597335973459735597365973759738597395974059741597425974359744597455974659747597485974959750597515975259753597545975559756597575975859759597605976159762597635976459765597665976759768597695977059771597725977359774597755977659777597785977959780597815978259783597845978559786597875978859789597905979159792597935979459795597965979759798597995980059801598025980359804598055980659807598085980959810598115981259813598145981559816598175981859819598205982159822598235982459825598265982759828598295983059831598325983359834598355983659837598385983959840598415984259843598445984559846598475984859849598505985159852598535985459855598565985759858598595986059861598625986359864598655986659867598685986959870598715987259873598745987559876598775987859879598805988159882598835988459885598865988759888598895989059891598925989359894598955989659897598985989959900599015990259903599045990559906599075990859909599105991159912599135991459915599165991759918599195992059921599225992359924599255992659927599285992959930599315993259933599345993559936599375993859939599405994159942599435994459945599465994759948599495995059951599525995359954599555995659957599585995959960599615996259963599645996559966599675996859969599705997159972599735997459975599765997759978599795998059981599825998359984599855998659987599885998959990599915999259993599945999559996599975999859999600006000160002600036000460005600066000760008600096001060011600126001360014600156001660017600186001960020600216002260023600246002560026600276002860029600306003160032600336003460035600366003760038600396004060041600426004360044600456004660047600486004960050600516005260053600546005560056600576005860059600606006160062600636006460065600666006760068600696007060071600726007360074600756007660077600786007960080600816008260083600846008560086600876008860089600906009160092600936009460095600966009760098600996010060101601026010360104601056010660107601086010960110601116011260113601146011560116601176011860119601206012160122601236012460125601266012760128601296013060131601326013360134601356013660137601386013960140601416014260143601446014560146601476014860149601506015160152601536015460155601566015760158601596016060161601626016360164601656016660167601686016960170601716017260173601746017560176601776017860179601806018160182601836018460185601866018760188601896019060191601926019360194601956019660197601986019960200602016020260203602046020560206602076020860209602106021160212602136021460215602166021760218602196022060221602226022360224602256022660227602286022960230602316023260233602346023560236602376023860239602406024160242602436024460245602466024760248602496025060251602526025360254602556025660257602586025960260602616026260263602646026560266602676026860269602706027160272602736027460275602766027760278602796028060281602826028360284602856028660287602886028960290602916029260293602946029560296602976029860299603006030160302603036030460305603066030760308603096031060311603126031360314603156031660317603186031960320603216032260323603246032560326603276032860329603306033160332603336033460335603366033760338603396034060341603426034360344603456034660347603486034960350603516035260353603546035560356603576035860359603606036160362603636036460365603666036760368603696037060371603726037360374603756037660377603786037960380603816038260383603846038560386603876038860389603906039160392603936039460395603966039760398603996040060401604026040360404604056040660407604086040960410604116041260413604146041560416604176041860419604206042160422604236042460425604266042760428604296043060431604326043360434604356043660437604386043960440604416044260443604446044560446604476044860449604506045160452604536045460455604566045760458604596046060461604626046360464604656046660467604686046960470604716047260473604746047560476604776047860479604806048160482604836048460485604866048760488604896049060491604926049360494604956049660497604986049960500605016050260503605046050560506605076050860509605106051160512605136051460515605166051760518605196052060521605226052360524605256052660527605286052960530605316053260533605346053560536605376053860539605406054160542605436054460545605466054760548605496055060551605526055360554605556055660557605586055960560605616056260563605646056560566605676056860569605706057160572605736057460575605766057760578605796058060581605826058360584605856058660587605886058960590605916059260593605946059560596605976059860599606006060160602606036060460605606066060760608606096061060611606126061360614606156061660617606186061960620606216062260623606246062560626606276062860629606306063160632606336063460635606366063760638606396064060641606426064360644606456064660647606486064960650606516065260653606546065560656606576065860659606606066160662606636066460665606666066760668606696067060671606726067360674606756067660677606786067960680606816068260683606846068560686606876068860689606906069160692606936069460695606966069760698606996070060701607026070360704607056070660707607086070960710607116071260713607146071560716607176071860719607206072160722607236072460725607266072760728607296073060731607326073360734607356073660737607386073960740607416074260743607446074560746607476074860749607506075160752607536075460755607566075760758607596076060761607626076360764607656076660767607686076960770607716077260773607746077560776607776077860779607806078160782607836078460785607866078760788607896079060791607926079360794607956079660797607986079960800608016080260803608046080560806608076080860809608106081160812608136081460815608166081760818608196082060821608226082360824608256082660827608286082960830608316083260833608346083560836608376083860839608406084160842608436084460845608466084760848608496085060851608526085360854608556085660857608586085960860608616086260863608646086560866608676086860869608706087160872608736087460875608766087760878608796088060881608826088360884608856088660887608886088960890608916089260893608946089560896608976089860899609006090160902609036090460905609066090760908609096091060911609126091360914609156091660917609186091960920609216092260923609246092560926609276092860929609306093160932609336093460935609366093760938609396094060941609426094360944609456094660947609486094960950609516095260953609546095560956609576095860959609606096160962609636096460965609666096760968609696097060971609726097360974609756097660977609786097960980609816098260983609846098560986609876098860989609906099160992609936099460995609966099760998609996100061001610026100361004610056100661007610086100961010610116101261013610146101561016610176101861019610206102161022610236102461025610266102761028610296103061031610326103361034610356103661037610386103961040610416104261043610446104561046610476104861049610506105161052610536105461055610566105761058610596106061061610626106361064610656106661067610686106961070610716107261073610746107561076610776107861079610806108161082610836108461085610866108761088610896109061091610926109361094610956109661097610986109961100611016110261103611046110561106611076110861109611106111161112611136111461115611166111761118611196112061121611226112361124611256112661127611286112961130611316113261133611346113561136611376113861139611406114161142611436114461145611466114761148611496115061151611526115361154611556115661157611586115961160611616116261163611646116561166611676116861169611706117161172611736117461175611766117761178611796118061181611826118361184611856118661187611886118961190611916119261193611946119561196611976119861199612006120161202612036120461205612066120761208612096121061211612126121361214612156121661217612186121961220612216122261223612246122561226612276122861229612306123161232612336123461235612366123761238612396124061241612426124361244612456124661247612486124961250612516125261253612546125561256612576125861259612606126161262612636126461265612666126761268612696127061271612726127361274612756127661277612786127961280612816128261283612846128561286612876128861289612906129161292612936129461295612966129761298612996130061301613026130361304613056130661307613086130961310613116131261313613146131561316613176131861319613206132161322613236132461325613266132761328613296133061331613326133361334613356133661337613386133961340613416134261343613446134561346613476134861349613506135161352613536135461355613566135761358613596136061361613626136361364613656136661367613686136961370613716137261373613746137561376613776137861379613806138161382613836138461385613866138761388613896139061391613926139361394613956139661397613986139961400614016140261403614046140561406614076140861409614106141161412614136141461415614166141761418614196142061421614226142361424614256142661427614286142961430614316143261433614346143561436614376143861439614406144161442614436144461445614466144761448614496145061451614526145361454614556145661457614586145961460614616146261463614646146561466614676146861469614706147161472614736147461475614766147761478614796148061481614826148361484614856148661487614886148961490614916149261493614946149561496614976149861499615006150161502615036150461505615066150761508615096151061511615126151361514615156151661517615186151961520615216152261523615246152561526615276152861529615306153161532615336153461535615366153761538615396154061541615426154361544615456154661547615486154961550615516155261553615546155561556615576155861559615606156161562615636156461565615666156761568615696157061571615726157361574615756157661577615786157961580615816158261583615846158561586615876158861589615906159161592615936159461595615966159761598615996160061601616026160361604616056160661607616086160961610616116161261613616146161561616616176161861619616206162161622616236162461625616266162761628616296163061631616326163361634616356163661637616386163961640616416164261643616446164561646616476164861649616506165161652616536165461655616566165761658616596166061661616626166361664616656166661667616686166961670616716167261673616746167561676616776167861679616806168161682616836168461685616866168761688616896169061691616926169361694616956169661697616986169961700617016170261703617046170561706617076170861709617106171161712617136171461715617166171761718617196172061721617226172361724617256172661727617286172961730617316173261733617346173561736617376173861739617406174161742617436174461745617466174761748617496175061751617526175361754617556175661757617586175961760617616176261763617646176561766617676176861769617706177161772617736177461775617766177761778617796178061781617826178361784617856178661787617886178961790617916179261793617946179561796617976179861799618006180161802618036180461805618066180761808618096181061811618126181361814618156181661817618186181961820618216182261823618246182561826618276182861829618306183161832618336183461835618366183761838618396184061841618426184361844618456184661847618486184961850618516185261853618546185561856618576185861859618606186161862618636186461865618666186761868618696187061871618726187361874618756187661877618786187961880618816188261883618846188561886618876188861889618906189161892618936189461895618966189761898618996190061901619026190361904619056190661907619086190961910619116191261913619146191561916619176191861919619206192161922619236192461925619266192761928619296193061931619326193361934619356193661937619386193961940619416194261943619446194561946619476194861949619506195161952619536195461955619566195761958619596196061961619626196361964619656196661967619686196961970619716197261973619746197561976619776197861979619806198161982619836198461985619866198761988619896199061991619926199361994619956199661997619986199962000620016200262003620046200562006620076200862009620106201162012620136201462015620166201762018620196202062021620226202362024620256202662027620286202962030620316203262033620346203562036620376203862039620406204162042620436204462045620466204762048620496205062051620526205362054620556205662057620586205962060620616206262063620646206562066620676206862069620706207162072620736207462075620766207762078620796208062081620826208362084620856208662087620886208962090620916209262093620946209562096620976209862099621006210162102621036210462105621066210762108621096211062111621126211362114621156211662117621186211962120621216212262123621246212562126621276212862129621306213162132621336213462135621366213762138621396214062141621426214362144621456214662147621486214962150621516215262153621546215562156621576215862159621606216162162621636216462165621666216762168621696217062171621726217362174621756217662177621786217962180621816218262183621846218562186621876218862189621906219162192621936219462195621966219762198621996220062201622026220362204622056220662207622086220962210622116221262213622146221562216622176221862219622206222162222622236222462225622266222762228622296223062231622326223362234622356223662237622386223962240622416224262243622446224562246622476224862249622506225162252622536225462255622566225762258622596226062261622626226362264622656226662267622686226962270622716227262273622746227562276622776227862279622806228162282622836228462285622866228762288622896229062291622926229362294622956229662297622986229962300623016230262303623046230562306623076230862309623106231162312623136231462315623166231762318623196232062321623226232362324623256232662327623286232962330623316233262333623346233562336623376233862339623406234162342623436234462345623466234762348623496235062351623526235362354623556235662357623586235962360623616236262363623646236562366623676236862369623706237162372623736237462375623766237762378623796238062381623826238362384623856238662387623886238962390623916239262393623946239562396623976239862399624006240162402624036240462405624066240762408624096241062411624126241362414624156241662417624186241962420624216242262423624246242562426624276242862429624306243162432624336243462435624366243762438624396244062441624426244362444624456244662447624486244962450624516245262453624546245562456624576245862459624606246162462624636246462465624666246762468624696247062471624726247362474624756247662477624786247962480624816248262483624846248562486624876248862489624906249162492624936249462495624966249762498624996250062501625026250362504625056250662507625086250962510625116251262513625146251562516625176251862519625206252162522625236252462525625266252762528625296253062531625326253362534625356253662537625386253962540625416254262543625446254562546625476254862549625506255162552625536255462555625566255762558625596256062561625626256362564625656256662567625686256962570625716257262573625746257562576625776257862579625806258162582625836258462585625866258762588625896259062591625926259362594625956259662597625986259962600626016260262603626046260562606626076260862609626106261162612626136261462615626166261762618626196262062621626226262362624626256262662627626286262962630626316263262633626346263562636626376263862639626406264162642626436264462645626466264762648626496265062651626526265362654626556265662657626586265962660626616266262663626646266562666626676266862669626706267162672626736267462675626766267762678626796268062681626826268362684626856268662687626886268962690626916269262693626946269562696626976269862699627006270162702627036270462705627066270762708627096271062711627126271362714627156271662717627186271962720627216272262723627246272562726627276272862729627306273162732627336273462735627366273762738627396274062741627426274362744627456274662747627486274962750627516275262753627546275562756627576275862759627606276162762627636276462765627666276762768627696277062771627726277362774627756277662777627786277962780627816278262783627846278562786627876278862789627906279162792627936279462795627966279762798627996280062801628026280362804628056280662807628086280962810628116281262813628146281562816628176281862819628206282162822628236282462825628266282762828628296283062831628326283362834628356283662837628386283962840628416284262843628446284562846628476284862849628506285162852628536285462855628566285762858628596286062861628626286362864628656286662867628686286962870628716287262873628746287562876628776287862879628806288162882628836288462885628866288762888628896289062891628926289362894628956289662897628986289962900629016290262903629046290562906629076290862909629106291162912629136291462915629166291762918629196292062921629226292362924629256292662927629286292962930629316293262933629346293562936629376293862939629406294162942629436294462945629466294762948629496295062951629526295362954629556295662957629586295962960629616296262963629646296562966629676296862969629706297162972629736297462975629766297762978629796298062981629826298362984629856298662987629886298962990629916299262993629946299562996629976299862999630006300163002630036300463005630066300763008630096301063011630126301363014630156301663017630186301963020630216302263023630246302563026630276302863029630306303163032630336303463035630366303763038630396304063041630426304363044630456304663047630486304963050630516305263053630546305563056630576305863059630606306163062630636306463065630666306763068630696307063071630726307363074630756307663077630786307963080630816308263083630846308563086630876308863089630906309163092630936309463095630966309763098630996310063101631026310363104631056310663107631086310963110631116311263113631146311563116631176311863119631206312163122631236312463125631266312763128631296313063131631326313363134631356313663137631386313963140631416314263143631446314563146631476314863149631506315163152631536315463155631566315763158631596316063161631626316363164631656316663167631686316963170631716317263173631746317563176631776317863179631806318163182631836318463185631866318763188631896319063191631926319363194631956319663197631986319963200632016320263203632046320563206632076320863209632106321163212632136321463215632166321763218632196322063221632226322363224632256322663227632286322963230632316323263233632346323563236632376323863239632406324163242632436324463245632466324763248632496325063251632526325363254632556325663257632586325963260632616326263263632646326563266632676326863269632706327163272632736327463275632766327763278632796328063281632826328363284632856328663287632886328963290632916329263293632946329563296632976329863299633006330163302633036330463305633066330763308633096331063311633126331363314633156331663317633186331963320633216332263323633246332563326633276332863329633306333163332633336333463335633366333763338633396334063341633426334363344633456334663347633486334963350633516335263353633546335563356633576335863359633606336163362633636336463365633666336763368633696337063371633726337363374633756337663377633786337963380633816338263383633846338563386633876338863389633906339163392633936339463395633966339763398633996340063401634026340363404634056340663407634086340963410634116341263413634146341563416634176341863419634206342163422634236342463425634266342763428634296343063431634326343363434634356343663437634386343963440634416344263443634446344563446634476344863449634506345163452634536345463455634566345763458634596346063461634626346363464634656346663467634686346963470634716347263473634746347563476634776347863479634806348163482634836348463485634866348763488634896349063491634926349363494634956349663497634986349963500635016350263503635046350563506635076350863509635106351163512635136351463515635166351763518635196352063521635226352363524635256352663527635286352963530635316353263533635346353563536635376353863539635406354163542635436354463545635466354763548635496355063551635526355363554635556355663557635586355963560635616356263563635646356563566635676356863569635706357163572635736357463575635766357763578635796358063581635826358363584635856358663587635886358963590635916359263593635946359563596635976359863599636006360163602636036360463605636066360763608636096361063611636126361363614636156361663617636186361963620636216362263623636246362563626636276362863629636306363163632636336363463635636366363763638636396364063641636426364363644636456364663647636486364963650636516365263653636546365563656636576365863659636606366163662636636366463665636666366763668636696367063671636726367363674636756367663677636786367963680636816368263683636846368563686636876368863689636906369163692636936369463695636966369763698636996370063701637026370363704637056370663707637086370963710637116371263713637146371563716637176371863719637206372163722637236372463725637266372763728637296373063731637326373363734637356373663737637386373963740637416374263743637446374563746637476374863749637506375163752637536375463755637566375763758637596376063761637626376363764637656376663767637686376963770637716377263773637746377563776637776377863779637806378163782637836378463785637866378763788637896379063791637926379363794637956379663797637986379963800638016380263803638046380563806638076380863809638106381163812638136381463815638166381763818638196382063821638226382363824638256382663827638286382963830638316383263833638346383563836638376383863839638406384163842638436384463845638466384763848638496385063851638526385363854638556385663857638586385963860638616386263863638646386563866638676386863869638706387163872638736387463875638766387763878638796388063881638826388363884638856388663887638886388963890638916389263893638946389563896638976389863899639006390163902639036390463905639066390763908639096391063911639126391363914639156391663917639186391963920639216392263923639246392563926639276392863929639306393163932639336393463935639366393763938639396394063941639426394363944639456394663947639486394963950639516395263953639546395563956639576395863959639606396163962639636396463965639666396763968639696397063971639726397363974639756397663977639786397963980639816398263983639846398563986639876398863989639906399163992639936399463995639966399763998639996400064001640026400364004640056400664007640086400964010640116401264013640146401564016640176401864019640206402164022640236402464025640266402764028640296403064031640326403364034640356403664037640386403964040640416404264043640446404564046640476404864049640506405164052640536405464055640566405764058640596406064061640626406364064640656406664067640686406964070640716407264073640746407564076640776407864079640806408164082640836408464085640866408764088640896409064091640926409364094640956409664097640986409964100641016410264103641046410564106641076410864109641106411164112641136411464115641166411764118641196412064121641226412364124641256412664127641286412964130641316413264133641346413564136641376413864139641406414164142641436414464145641466414764148641496415064151641526415364154641556415664157641586415964160641616416264163641646416564166641676416864169641706417164172641736417464175641766417764178641796418064181641826418364184641856418664187641886418964190641916419264193641946419564196641976419864199642006420164202642036420464205642066420764208642096421064211642126421364214642156421664217642186421964220642216422264223642246422564226642276422864229642306423164232642336423464235642366423764238642396424064241642426424364244642456424664247642486424964250642516425264253642546425564256642576425864259642606426164262642636426464265642666426764268642696427064271642726427364274642756427664277642786427964280642816428264283642846428564286642876428864289642906429164292642936429464295642966429764298642996430064301643026430364304643056430664307643086430964310643116431264313643146431564316643176431864319643206432164322643236432464325643266432764328643296433064331643326433364334643356433664337643386433964340643416434264343643446434564346643476434864349643506435164352643536435464355643566435764358643596436064361643626436364364643656436664367643686436964370643716437264373643746437564376643776437864379643806438164382643836438464385643866438764388643896439064391643926439364394643956439664397643986439964400644016440264403644046440564406644076440864409644106441164412644136441464415644166441764418644196442064421644226442364424644256442664427644286442964430644316443264433644346443564436644376443864439644406444164442644436444464445644466444764448644496445064451644526445364454644556445664457644586445964460644616446264463644646446564466644676446864469644706447164472644736447464475644766447764478644796448064481644826448364484644856448664487644886448964490644916449264493644946449564496644976449864499645006450164502645036450464505645066450764508645096451064511645126451364514645156451664517645186451964520645216452264523645246452564526645276452864529645306453164532645336453464535645366453764538645396454064541645426454364544645456454664547645486454964550645516455264553645546455564556645576455864559645606456164562645636456464565645666456764568645696457064571645726457364574645756457664577645786457964580645816458264583645846458564586645876458864589645906459164592645936459464595645966459764598645996460064601646026460364604646056460664607646086460964610646116461264613646146461564616646176461864619646206462164622646236462464625646266462764628646296463064631646326463364634646356463664637646386463964640646416464264643646446464564646646476464864649646506465164652646536465464655646566465764658646596466064661646626466364664646656466664667646686466964670646716467264673646746467564676646776467864679646806468164682646836468464685646866468764688646896469064691646926469364694646956469664697646986469964700647016470264703647046470564706647076470864709647106471164712647136471464715647166471764718647196472064721647226472364724647256472664727647286472964730647316473264733647346473564736647376473864739647406474164742647436474464745647466474764748647496475064751647526475364754647556475664757647586475964760647616476264763647646476564766647676476864769647706477164772647736477464775647766477764778647796478064781647826478364784647856478664787647886478964790647916479264793647946479564796647976479864799648006480164802648036480464805648066480764808648096481064811648126481364814648156481664817648186481964820648216482264823648246482564826648276482864829648306483164832648336483464835648366483764838648396484064841648426484364844648456484664847648486484964850648516485264853648546485564856648576485864859648606486164862648636486464865648666486764868648696487064871648726487364874648756487664877648786487964880648816488264883648846488564886648876488864889648906489164892648936489464895648966489764898648996490064901649026490364904649056490664907649086490964910649116491264913649146491564916649176491864919649206492164922649236492464925649266492764928649296493064931649326493364934649356493664937649386493964940649416494264943649446494564946649476494864949649506495164952649536495464955649566495764958649596496064961649626496364964649656496664967649686496964970649716497264973649746497564976649776497864979649806498164982649836498464985649866498764988649896499064991649926499364994649956499664997649986499965000650016500265003650046500565006650076500865009650106501165012650136501465015650166501765018650196502065021650226502365024650256502665027650286502965030650316503265033650346503565036650376503865039650406504165042650436504465045650466504765048650496505065051650526505365054650556505665057650586505965060650616506265063650646506565066650676506865069650706507165072650736507465075650766507765078650796508065081650826508365084650856508665087650886508965090650916509265093650946509565096650976509865099651006510165102651036510465105651066510765108651096511065111651126511365114651156511665117651186511965120651216512265123651246512565126651276512865129651306513165132651336513465135651366513765138651396514065141651426514365144651456514665147651486514965150651516515265153651546515565156651576515865159651606516165162651636516465165651666516765168651696517065171651726517365174651756517665177651786517965180651816518265183651846518565186651876518865189651906519165192651936519465195651966519765198651996520065201652026520365204652056520665207652086520965210652116521265213652146521565216652176521865219652206522165222652236522465225652266522765228652296523065231652326523365234652356523665237652386523965240652416524265243652446524565246652476524865249652506525165252652536525465255652566525765258652596526065261652626526365264652656526665267652686526965270652716527265273652746527565276652776527865279652806528165282652836528465285652866528765288652896529065291652926529365294652956529665297652986529965300653016530265303653046530565306653076530865309653106531165312653136531465315653166531765318653196532065321653226532365324653256532665327653286532965330653316533265333653346533565336653376533865339653406534165342653436534465345653466534765348653496535065351653526535365354653556535665357653586535965360653616536265363653646536565366653676536865369653706537165372653736537465375653766537765378653796538065381653826538365384653856538665387653886538965390653916539265393653946539565396653976539865399654006540165402654036540465405654066540765408654096541065411654126541365414654156541665417654186541965420654216542265423654246542565426654276542865429654306543165432654336543465435654366543765438654396544065441654426544365444654456544665447654486544965450654516545265453654546545565456654576545865459654606546165462654636546465465654666546765468654696547065471654726547365474654756547665477654786547965480654816548265483654846548565486654876548865489654906549165492654936549465495654966549765498654996550065501655026550365504655056550665507655086550965510655116551265513655146551565516655176551865519655206552165522655236552465525655266552765528655296553065531655326553365534655356553665537655386553965540655416554265543655446554565546655476554865549655506555165552655536555465555655566555765558655596556065561655626556365564655656556665567655686556965570655716557265573655746557565576655776557865579655806558165582655836558465585655866558765588655896559065591655926559365594655956559665597655986559965600656016560265603656046560565606656076560865609656106561165612656136561465615656166561765618656196562065621656226562365624656256562665627656286562965630656316563265633656346563565636656376563865639656406564165642656436564465645656466564765648656496565065651656526565365654656556565665657656586565965660656616566265663656646566565666656676566865669656706567165672656736567465675656766567765678656796568065681656826568365684656856568665687656886568965690656916569265693656946569565696656976569865699657006570165702657036570465705657066570765708657096571065711657126571365714657156571665717657186571965720657216572265723657246572565726657276572865729657306573165732657336573465735657366573765738657396574065741657426574365744657456574665747657486574965750657516575265753657546575565756657576575865759657606576165762657636576465765657666576765768657696577065771657726577365774657756577665777657786577965780657816578265783657846578565786657876578865789657906579165792657936579465795657966579765798657996580065801658026580365804658056580665807658086580965810658116581265813658146581565816658176581865819658206582165822658236582465825658266582765828658296583065831658326583365834658356583665837658386583965840658416584265843658446584565846658476584865849658506585165852658536585465855658566585765858658596586065861658626586365864658656586665867658686586965870658716587265873658746587565876658776587865879658806588165882658836588465885658866588765888658896589065891658926589365894658956589665897658986589965900659016590265903659046590565906659076590865909659106591165912659136591465915659166591765918659196592065921659226592365924659256592665927659286592965930659316593265933659346593565936659376593865939659406594165942659436594465945659466594765948659496595065951659526595365954659556595665957659586595965960659616596265963659646596565966659676596865969659706597165972659736597465975659766597765978659796598065981659826598365984659856598665987659886598965990659916599265993659946599565996659976599865999660006600166002660036600466005660066600766008660096601066011660126601366014660156601666017660186601966020660216602266023660246602566026660276602866029660306603166032660336603466035660366603766038660396604066041660426604366044660456604666047660486604966050660516605266053660546605566056660576605866059660606606166062660636606466065660666606766068660696607066071660726607366074660756607666077660786607966080660816608266083660846608566086660876608866089660906609166092660936609466095660966609766098660996610066101661026610366104661056610666107661086610966110661116611266113661146611566116661176611866119661206612166122661236612466125661266612766128661296613066131661326613366134661356613666137661386613966140661416614266143661446614566146661476614866149661506615166152661536615466155661566615766158661596616066161661626616366164661656616666167661686616966170661716617266173661746617566176661776617866179661806618166182661836618466185661866618766188661896619066191661926619366194661956619666197661986619966200662016620266203662046620566206662076620866209662106621166212662136621466215662166621766218662196622066221662226622366224662256622666227662286622966230662316623266233662346623566236662376623866239662406624166242662436624466245662466624766248662496625066251662526625366254662556625666257662586625966260662616626266263662646626566266662676626866269662706627166272662736627466275662766627766278662796628066281662826628366284662856628666287662886628966290662916629266293662946629566296662976629866299663006630166302663036630466305663066630766308663096631066311663126631366314663156631666317663186631966320663216632266323663246632566326663276632866329663306633166332663336633466335663366633766338663396634066341663426634366344663456634666347663486634966350663516635266353663546635566356663576635866359663606636166362663636636466365663666636766368663696637066371663726637366374663756637666377663786637966380663816638266383663846638566386663876638866389663906639166392663936639466395663966639766398663996640066401664026640366404664056640666407664086640966410664116641266413664146641566416664176641866419664206642166422664236642466425664266642766428664296643066431664326643366434664356643666437664386643966440664416644266443664446644566446664476644866449664506645166452664536645466455664566645766458664596646066461664626646366464664656646666467664686646966470664716647266473664746647566476664776647866479664806648166482664836648466485664866648766488664896649066491664926649366494664956649666497664986649966500665016650266503665046650566506665076650866509665106651166512665136651466515665166651766518665196652066521665226652366524665256652666527665286652966530665316653266533665346653566536665376653866539665406654166542665436654466545665466654766548665496655066551665526655366554665556655666557665586655966560665616656266563665646656566566665676656866569665706657166572665736657466575665766657766578665796658066581665826658366584665856658666587665886658966590665916659266593665946659566596665976659866599666006660166602666036660466605666066660766608666096661066611666126661366614666156661666617666186661966620666216662266623666246662566626666276662866629666306663166632666336663466635666366663766638666396664066641666426664366644666456664666647666486664966650666516665266653666546665566656666576665866659666606666166662666636666466665666666666766668666696667066671666726667366674666756667666677666786667966680666816668266683666846668566686666876668866689666906669166692666936669466695666966669766698666996670066701667026670366704667056670666707667086670966710667116671266713667146671566716667176671866719667206672166722667236672466725667266672766728667296673066731667326673366734667356673666737667386673966740667416674266743667446674566746667476674866749667506675166752667536675466755667566675766758667596676066761667626676366764667656676666767667686676966770667716677266773667746677566776667776677866779667806678166782667836678466785667866678766788667896679066791667926679366794667956679666797667986679966800668016680266803668046680566806668076680866809668106681166812668136681466815668166681766818668196682066821668226682366824668256682666827668286682966830668316683266833668346683566836668376683866839668406684166842668436684466845668466684766848668496685066851668526685366854668556685666857668586685966860668616686266863668646686566866668676686866869668706687166872668736687466875668766687766878668796688066881668826688366884668856688666887668886688966890668916689266893668946689566896668976689866899669006690166902669036690466905669066690766908669096691066911669126691366914669156691666917669186691966920669216692266923669246692566926669276692866929669306693166932669336693466935669366693766938669396694066941669426694366944669456694666947669486694966950669516695266953669546695566956669576695866959669606696166962669636696466965669666696766968669696697066971669726697366974669756697666977669786697966980669816698266983669846698566986669876698866989669906699166992669936699466995669966699766998669996700067001670026700367004670056700667007670086700967010670116701267013670146701567016670176701867019670206702167022670236702467025670266702767028670296703067031670326703367034670356703667037670386703967040670416704267043670446704567046670476704867049670506705167052670536705467055670566705767058670596706067061670626706367064670656706667067670686706967070670716707267073670746707567076670776707867079670806708167082670836708467085670866708767088670896709067091670926709367094670956709667097670986709967100671016710267103671046710567106671076710867109671106711167112671136711467115671166711767118671196712067121671226712367124671256712667127671286712967130671316713267133671346713567136671376713867139671406714167142671436714467145671466714767148671496715067151671526715367154671556715667157671586715967160671616716267163671646716567166671676716867169671706717167172671736717467175671766717767178671796718067181671826718367184671856718667187671886718967190671916719267193671946719567196671976719867199672006720167202672036720467205672066720767208672096721067211672126721367214672156721667217672186721967220672216722267223672246722567226672276722867229672306723167232672336723467235672366723767238672396724067241672426724367244672456724667247672486724967250672516725267253672546725567256672576725867259672606726167262672636726467265672666726767268672696727067271672726727367274672756727667277672786727967280672816728267283672846728567286672876728867289672906729167292672936729467295672966729767298672996730067301673026730367304673056730667307673086730967310673116731267313673146731567316673176731867319673206732167322673236732467325673266732767328673296733067331673326733367334673356733667337673386733967340673416734267343673446734567346673476734867349673506735167352673536735467355673566735767358673596736067361673626736367364673656736667367673686736967370673716737267373673746737567376673776737867379673806738167382673836738467385673866738767388673896739067391673926739367394673956739667397673986739967400674016740267403674046740567406674076740867409674106741167412674136741467415674166741767418674196742067421674226742367424674256742667427674286742967430674316743267433674346743567436674376743867439674406744167442674436744467445674466744767448674496745067451674526745367454674556745667457674586745967460674616746267463674646746567466674676746867469674706747167472674736747467475674766747767478674796748067481674826748367484674856748667487674886748967490674916749267493674946749567496674976749867499675006750167502675036750467505675066750767508675096751067511675126751367514675156751667517675186751967520675216752267523675246752567526675276752867529675306753167532675336753467535675366753767538675396754067541675426754367544675456754667547675486754967550675516755267553675546755567556675576755867559675606756167562675636756467565675666756767568675696757067571675726757367574675756757667577675786757967580675816758267583675846758567586675876758867589675906759167592675936759467595675966759767598675996760067601676026760367604676056760667607676086760967610676116761267613676146761567616676176761867619676206762167622676236762467625676266762767628676296763067631676326763367634676356763667637676386763967640676416764267643676446764567646676476764867649676506765167652676536765467655676566765767658676596766067661676626766367664676656766667667676686766967670676716767267673676746767567676676776767867679676806768167682676836768467685676866768767688676896769067691676926769367694676956769667697676986769967700677016770267703677046770567706677076770867709677106771167712677136771467715677166771767718677196772067721677226772367724677256772667727677286772967730677316773267733677346773567736677376773867739677406774167742677436774467745677466774767748677496775067751677526775367754677556775667757677586775967760677616776267763677646776567766677676776867769677706777167772677736777467775677766777767778677796778067781677826778367784677856778667787677886778967790677916779267793677946779567796677976779867799678006780167802678036780467805678066780767808678096781067811678126781367814678156781667817678186781967820678216782267823678246782567826678276782867829678306783167832678336783467835678366783767838678396784067841678426784367844678456784667847678486784967850678516785267853678546785567856678576785867859678606786167862678636786467865678666786767868678696787067871678726787367874678756787667877678786787967880678816788267883678846788567886678876788867889678906789167892678936789467895678966789767898678996790067901679026790367904679056790667907679086790967910679116791267913679146791567916679176791867919679206792167922679236792467925679266792767928679296793067931679326793367934679356793667937679386793967940679416794267943679446794567946679476794867949679506795167952679536795467955679566795767958679596796067961679626796367964679656796667967679686796967970679716797267973679746797567976679776797867979679806798167982679836798467985679866798767988679896799067991679926799367994679956799667997679986799968000680016800268003680046800568006680076800868009680106801168012680136801468015680166801768018680196802068021680226802368024680256802668027680286802968030680316803268033680346803568036680376803868039680406804168042680436804468045680466804768048680496805068051680526805368054680556805668057680586805968060680616806268063680646806568066680676806868069680706807168072680736807468075680766807768078680796808068081680826808368084680856808668087680886808968090680916809268093680946809568096680976809868099681006810168102681036810468105681066810768108681096811068111681126811368114681156811668117681186811968120681216812268123681246812568126681276812868129681306813168132681336813468135681366813768138681396814068141681426814368144681456814668147681486814968150681516815268153681546815568156681576815868159681606816168162681636816468165681666816768168681696817068171681726817368174681756817668177681786817968180681816818268183681846818568186681876818868189681906819168192681936819468195681966819768198681996820068201682026820368204682056820668207682086820968210682116821268213682146821568216682176821868219682206822168222682236822468225682266822768228682296823068231682326823368234682356823668237682386823968240682416824268243682446824568246682476824868249682506825168252682536825468255682566825768258682596826068261682626826368264682656826668267682686826968270682716827268273682746827568276682776827868279682806828168282682836828468285682866828768288682896829068291682926829368294682956829668297682986829968300683016830268303683046830568306683076830868309683106831168312683136831468315683166831768318683196832068321683226832368324683256832668327683286832968330683316833268333683346833568336683376833868339683406834168342683436834468345683466834768348683496835068351683526835368354683556835668357683586835968360683616836268363683646836568366683676836868369683706837168372683736837468375683766837768378683796838068381683826838368384683856838668387683886838968390683916839268393683946839568396683976839868399684006840168402684036840468405684066840768408684096841068411684126841368414684156841668417684186841968420684216842268423684246842568426684276842868429684306843168432684336843468435684366843768438684396844068441684426844368444684456844668447684486844968450684516845268453684546845568456684576845868459684606846168462684636846468465684666846768468684696847068471684726847368474684756847668477684786847968480684816848268483684846848568486684876848868489684906849168492684936849468495684966849768498684996850068501685026850368504685056850668507685086850968510685116851268513685146851568516685176851868519685206852168522685236852468525685266852768528685296853068531685326853368534685356853668537685386853968540685416854268543685446854568546685476854868549685506855168552685536855468555685566855768558685596856068561685626856368564685656856668567685686856968570685716857268573685746857568576685776857868579
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["mongoose"] = factory();
  8. else
  9. root["mongoose"] = factory();
  10. })(typeof self !== 'undefined' ? self : this, () => {
  11. return /******/ (() => { // webpackBootstrap
  12. /******/ var __webpack_modules__ = ({
  13. /***/ 5507:
  14. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15. "use strict";
  16. /**
  17. * Export lib/mongoose
  18. *
  19. */
  20. module.exports = __webpack_require__(1735);
  21. /***/ }),
  22. /***/ 1735:
  23. /***/ ((module, exports, __webpack_require__) => {
  24. "use strict";
  25. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  26. /* eslint-env browser */
  27. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  28. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  29. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  32. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  33. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  34. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  35. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  36. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  37. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  38. (__webpack_require__(9906).set)(__webpack_require__(6333));
  39. var DocumentProvider = __webpack_require__(4304);
  40. var PromiseProvider = __webpack_require__(6755);
  41. DocumentProvider.setBrowser(true);
  42. /**
  43. * The Mongoose [Promise](#promise_Promise) constructor.
  44. *
  45. * @method Promise
  46. * @api public
  47. */
  48. Object.defineProperty(exports, "Promise", ({
  49. get: function get() {
  50. return PromiseProvider.get();
  51. },
  52. set: function set(lib) {
  53. PromiseProvider.set(lib);
  54. }
  55. }));
  56. /**
  57. * Storage layer for mongoose promises
  58. *
  59. * @method PromiseProvider
  60. * @api public
  61. */
  62. exports.PromiseProvider = PromiseProvider;
  63. /**
  64. * The [MongooseError](#error_MongooseError) constructor.
  65. *
  66. * @method Error
  67. * @api public
  68. */
  69. exports.Error = __webpack_require__(4888);
  70. /**
  71. * The Mongoose [Schema](#schema_Schema) constructor
  72. *
  73. * #### Example:
  74. *
  75. * const mongoose = require('mongoose');
  76. * const Schema = mongoose.Schema;
  77. * const CatSchema = new Schema(..);
  78. *
  79. * @method Schema
  80. * @api public
  81. */
  82. exports.Schema = __webpack_require__(5506);
  83. /**
  84. * The various Mongoose Types.
  85. *
  86. * #### Example:
  87. *
  88. * const mongoose = require('mongoose');
  89. * const array = mongoose.Types.Array;
  90. *
  91. * #### Types:
  92. *
  93. * - [Array](/docs/schematypes.html#arrays)
  94. * - [Buffer](/docs/schematypes.html#buffers)
  95. * - [Embedded](/docs/schematypes.html#schemas)
  96. * - [DocumentArray](/docs/api/documentarraypath.html)
  97. * - [Decimal128](/docs/api.html#mongoose_Mongoose-Decimal128)
  98. * - [ObjectId](/docs/schematypes.html#objectids)
  99. * - [Map](/docs/schematypes.html#maps)
  100. * - [Subdocument](/docs/schematypes.html#schemas)
  101. *
  102. * Using this exposed access to the `ObjectId` type, we can construct ids on demand.
  103. *
  104. * const ObjectId = mongoose.Types.ObjectId;
  105. * const id1 = new ObjectId;
  106. *
  107. * @property Types
  108. * @api public
  109. */
  110. exports.Types = __webpack_require__(8941);
  111. /**
  112. * The Mongoose [VirtualType](#virtualtype_VirtualType) constructor
  113. *
  114. * @method VirtualType
  115. * @api public
  116. */
  117. exports.VirtualType = __webpack_require__(459);
  118. /**
  119. * The various Mongoose SchemaTypes.
  120. *
  121. * #### Note:
  122. *
  123. * _Alias of mongoose.Schema.Types for backwards compatibility._
  124. *
  125. * @property SchemaTypes
  126. * @see Schema.SchemaTypes #schema_Schema.Types
  127. * @api public
  128. */
  129. exports.SchemaType = __webpack_require__(4289);
  130. /**
  131. * Internal utils
  132. *
  133. * @property utils
  134. * @api private
  135. */
  136. exports.utils = __webpack_require__(6872);
  137. /**
  138. * The Mongoose browser [Document](/api/document.html) constructor.
  139. *
  140. * @method Document
  141. * @api public
  142. */
  143. exports.Document = DocumentProvider();
  144. /**
  145. * Return a new browser model. In the browser, a model is just
  146. * a simplified document with a schema - it does **not** have
  147. * functions like `findOne()`, etc.
  148. *
  149. * @method model
  150. * @api public
  151. * @param {String} name
  152. * @param {Schema} schema
  153. * @return Class
  154. */
  155. exports.model = function (name, schema) {
  156. var Model = /*#__PURE__*/function (_exports$Document) {
  157. _inherits(Model, _exports$Document);
  158. var _super = _createSuper(Model);
  159. function Model(obj, fields) {
  160. _classCallCheck(this, Model);
  161. return _super.call(this, obj, schema, fields);
  162. }
  163. return _createClass(Model);
  164. }(exports.Document);
  165. Model.modelName = name;
  166. return Model;
  167. };
  168. /*!
  169. * Module exports.
  170. */
  171. if (typeof window !== 'undefined') {
  172. window.mongoose = module.exports;
  173. window.Buffer = Buffer;
  174. }
  175. /***/ }),
  176. /***/ 3434:
  177. /***/ ((module, exports, __webpack_require__) => {
  178. "use strict";
  179. /*!
  180. * Module dependencies.
  181. */
  182. var NodeJSDocument = __webpack_require__(8727);
  183. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  184. var MongooseError = __webpack_require__(4888);
  185. var Schema = __webpack_require__(5506);
  186. var ObjectId = __webpack_require__(6079);
  187. var ValidationError = MongooseError.ValidationError;
  188. var applyHooks = __webpack_require__(8859);
  189. var isObject = __webpack_require__(5721);
  190. /**
  191. * Document constructor.
  192. *
  193. * @param {Object} obj the values to set
  194. * @param {Object} schema
  195. * @param {Object} [fields] optional object containing the fields which were selected in the query returning this document and any populated paths data
  196. * @param {Boolean} [skipId] bool, should we auto create an ObjectId _id
  197. * @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#events_class_events_eventemitter
  198. * @event `init`: Emitted on a document after it has was retrieved from the db and fully hydrated by Mongoose.
  199. * @event `save`: Emitted when the document is successfully saved
  200. * @api private
  201. */
  202. function Document(obj, schema, fields, skipId, skipInit) {
  203. if (!(this instanceof Document)) {
  204. return new Document(obj, schema, fields, skipId, skipInit);
  205. }
  206. if (isObject(schema) && !schema.instanceOfSchema) {
  207. schema = new Schema(schema);
  208. } // When creating EmbeddedDocument, it already has the schema and he doesn't need the _id
  209. schema = this.schema || schema; // Generate ObjectId if it is missing, but it requires a scheme
  210. if (!this.schema && schema.options._id) {
  211. obj = obj || {};
  212. if (obj._id === undefined) {
  213. obj._id = new ObjectId();
  214. }
  215. }
  216. if (!schema) {
  217. throw new MongooseError.MissingSchemaError();
  218. }
  219. this.$__setSchema(schema);
  220. NodeJSDocument.call(this, obj, fields, skipId, skipInit);
  221. applyHooks(this, schema, {
  222. decorateDoc: true
  223. }); // apply methods
  224. for (var m in schema.methods) {
  225. this[m] = schema.methods[m];
  226. } // apply statics
  227. for (var s in schema.statics) {
  228. this[s] = schema.statics[s];
  229. }
  230. }
  231. /*!
  232. * Inherit from the NodeJS document
  233. */
  234. Document.prototype = Object.create(NodeJSDocument.prototype);
  235. Document.prototype.constructor = Document;
  236. /*!
  237. * ignore
  238. */
  239. Document.events = new EventEmitter();
  240. /*!
  241. * Browser doc exposes the event emitter API
  242. */
  243. Document.$emitter = new EventEmitter();
  244. ['on', 'once', 'emit', 'listeners', 'removeListener', 'setMaxListeners', 'removeAllListeners', 'addListener'].forEach(function (emitterFn) {
  245. Document[emitterFn] = function () {
  246. return Document.$emitter[emitterFn].apply(Document.$emitter, arguments);
  247. };
  248. });
  249. /*!
  250. * Module exports.
  251. */
  252. Document.ValidationError = ValidationError;
  253. module.exports = exports = Document;
  254. /***/ }),
  255. /***/ 6787:
  256. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  257. "use strict";
  258. /*!
  259. * Module dependencies.
  260. */
  261. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  262. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  263. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  264. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  265. var CastError = __webpack_require__(1795);
  266. var StrictModeError = __webpack_require__(3328);
  267. var Types = __webpack_require__(5251);
  268. var cast$expr = __webpack_require__(9739);
  269. var castTextSearch = __webpack_require__(6495);
  270. var get = __webpack_require__(9981);
  271. var getConstructorName = __webpack_require__(1981);
  272. var getSchemaDiscriminatorByValue = __webpack_require__(2392);
  273. var isOperator = __webpack_require__(9627);
  274. var util = __webpack_require__(161);
  275. var isObject = __webpack_require__(5721);
  276. var isMongooseObject = __webpack_require__(6584);
  277. var ALLOWED_GEOWITHIN_GEOJSON_TYPES = ['Polygon', 'MultiPolygon'];
  278. /**
  279. * Handles internal casting for query filters.
  280. *
  281. * @param {Schema} schema
  282. * @param {Object} obj Object to cast
  283. * @param {Object} options the query options
  284. * @param {Query} context passed to setters
  285. * @api private
  286. */
  287. module.exports = function cast(schema, obj, options, context) {
  288. if (Array.isArray(obj)) {
  289. throw new Error('Query filter must be an object, got an array ', util.inspect(obj));
  290. }
  291. if (obj == null) {
  292. return obj;
  293. }
  294. if (schema != null && schema.discriminators != null && obj[schema.options.discriminatorKey] != null) {
  295. schema = getSchemaDiscriminatorByValue(schema, obj[schema.options.discriminatorKey]) || schema;
  296. }
  297. var paths = Object.keys(obj);
  298. var i = paths.length;
  299. var _keys;
  300. var any$conditionals;
  301. var schematype;
  302. var nested;
  303. var path;
  304. var type;
  305. var val;
  306. options = options || {};
  307. while (i--) {
  308. path = paths[i];
  309. val = obj[path];
  310. if (path === '$or' || path === '$nor' || path === '$and') {
  311. if (!Array.isArray(val)) {
  312. throw new CastError('Array', val, path);
  313. }
  314. for (var k = 0; k < val.length; ++k) {
  315. if (val[k] == null || _typeof(val[k]) !== 'object') {
  316. throw new CastError('Object', val[k], path + '.' + k);
  317. }
  318. val[k] = cast(schema, val[k], options, context);
  319. }
  320. } else if (path === '$where') {
  321. type = _typeof(val);
  322. if (type !== 'string' && type !== 'function') {
  323. throw new Error('Must have a string or function for $where');
  324. }
  325. if (type === 'function') {
  326. obj[path] = val.toString();
  327. }
  328. continue;
  329. } else if (path === '$expr') {
  330. val = cast$expr(val, schema);
  331. continue;
  332. } else if (path === '$elemMatch') {
  333. val = cast(schema, val, options, context);
  334. } else if (path === '$text') {
  335. val = castTextSearch(val, path);
  336. } else {
  337. if (!schema) {
  338. // no casting for Mixed types
  339. continue;
  340. }
  341. schematype = schema.path(path); // Check for embedded discriminator paths
  342. if (!schematype) {
  343. var split = path.split('.');
  344. var j = split.length;
  345. while (j--) {
  346. var pathFirstHalf = split.slice(0, j).join('.');
  347. var pathLastHalf = split.slice(j).join('.');
  348. var _schematype = schema.path(pathFirstHalf);
  349. var discriminatorKey = _schematype && _schematype.schema && _schematype.schema.options && _schematype.schema.options.discriminatorKey; // gh-6027: if we haven't found the schematype but this path is
  350. // underneath an embedded discriminator and the embedded discriminator
  351. // key is in the query, use the embedded discriminator schema
  352. if (_schematype != null && (_schematype.schema && _schematype.schema.discriminators) != null && discriminatorKey != null && pathLastHalf !== discriminatorKey) {
  353. var discriminatorVal = get(obj, pathFirstHalf + '.' + discriminatorKey);
  354. if (discriminatorVal != null) {
  355. schematype = _schematype.schema.discriminators[discriminatorVal].path(pathLastHalf);
  356. }
  357. }
  358. }
  359. }
  360. if (!schematype) {
  361. // Handle potential embedded array queries
  362. var _split = path.split('.');
  363. var _j = _split.length;
  364. var _pathFirstHalf = void 0;
  365. var _pathLastHalf = void 0;
  366. var remainingConds = void 0; // Find the part of the var path that is a path of the Schema
  367. while (_j--) {
  368. _pathFirstHalf = _split.slice(0, _j).join('.');
  369. schematype = schema.path(_pathFirstHalf);
  370. if (schematype) {
  371. break;
  372. }
  373. } // If a substring of the input path resolves to an actual real path...
  374. if (schematype) {
  375. // Apply the casting; similar code for $elemMatch in schema/array.js
  376. if (schematype.caster && schematype.caster.schema) {
  377. remainingConds = {};
  378. _pathLastHalf = _split.slice(_j).join('.');
  379. remainingConds[_pathLastHalf] = val;
  380. var ret = cast(schematype.caster.schema, remainingConds, options, context)[_pathLastHalf];
  381. if (ret === void 0) {
  382. delete obj[path];
  383. } else {
  384. obj[path] = ret;
  385. }
  386. } else {
  387. obj[path] = val;
  388. }
  389. continue;
  390. }
  391. if (isObject(val)) {
  392. // handle geo schemas that use object notation
  393. // { loc: { long: Number, lat: Number }
  394. var geo = '';
  395. if (val.$near) {
  396. geo = '$near';
  397. } else if (val.$nearSphere) {
  398. geo = '$nearSphere';
  399. } else if (val.$within) {
  400. geo = '$within';
  401. } else if (val.$geoIntersects) {
  402. geo = '$geoIntersects';
  403. } else if (val.$geoWithin) {
  404. geo = '$geoWithin';
  405. }
  406. if (geo) {
  407. var numbertype = new Types.Number('__QueryCasting__');
  408. var value = val[geo];
  409. if (val.$maxDistance != null) {
  410. val.$maxDistance = numbertype.castForQueryWrapper({
  411. val: val.$maxDistance,
  412. context: context
  413. });
  414. }
  415. if (val.$minDistance != null) {
  416. val.$minDistance = numbertype.castForQueryWrapper({
  417. val: val.$minDistance,
  418. context: context
  419. });
  420. }
  421. if (geo === '$within') {
  422. var withinType = value.$center || value.$centerSphere || value.$box || value.$polygon;
  423. if (!withinType) {
  424. throw new Error('Bad $within parameter: ' + JSON.stringify(val));
  425. }
  426. value = withinType;
  427. } else if (geo === '$near' && typeof value.type === 'string' && Array.isArray(value.coordinates)) {
  428. // geojson; cast the coordinates
  429. value = value.coordinates;
  430. } else if ((geo === '$near' || geo === '$nearSphere' || geo === '$geoIntersects') && value.$geometry && typeof value.$geometry.type === 'string' && Array.isArray(value.$geometry.coordinates)) {
  431. if (value.$maxDistance != null) {
  432. value.$maxDistance = numbertype.castForQueryWrapper({
  433. val: value.$maxDistance,
  434. context: context
  435. });
  436. }
  437. if (value.$minDistance != null) {
  438. value.$minDistance = numbertype.castForQueryWrapper({
  439. val: value.$minDistance,
  440. context: context
  441. });
  442. }
  443. if (isMongooseObject(value.$geometry)) {
  444. value.$geometry = value.$geometry.toObject({
  445. transform: false,
  446. virtuals: false
  447. });
  448. }
  449. value = value.$geometry.coordinates;
  450. } else if (geo === '$geoWithin') {
  451. if (value.$geometry) {
  452. if (isMongooseObject(value.$geometry)) {
  453. value.$geometry = value.$geometry.toObject({
  454. virtuals: false
  455. });
  456. }
  457. var geoWithinType = value.$geometry.type;
  458. if (ALLOWED_GEOWITHIN_GEOJSON_TYPES.indexOf(geoWithinType) === -1) {
  459. throw new Error('Invalid geoJSON type for $geoWithin "' + geoWithinType + '", must be "Polygon" or "MultiPolygon"');
  460. }
  461. value = value.$geometry.coordinates;
  462. } else {
  463. value = value.$box || value.$polygon || value.$center || value.$centerSphere;
  464. if (isMongooseObject(value)) {
  465. value = value.toObject({
  466. virtuals: false
  467. });
  468. }
  469. }
  470. }
  471. _cast(value, numbertype, context);
  472. continue;
  473. }
  474. }
  475. if (schema.nested[path]) {
  476. continue;
  477. }
  478. var strict = 'strict' in options ? options.strict : schema.options.strict;
  479. var strictQuery = 'strictQuery' in options ? options.strictQuery : 'strict' in options ? options.strict : 'strict' in schema._userProvidedOptions ? schema._userProvidedOptions.strict : schema.options.strictQuery;
  480. if (options.upsert && strict) {
  481. if (strict === 'throw') {
  482. throw new StrictModeError(path);
  483. }
  484. throw new StrictModeError(path, 'Path "' + path + '" is not in ' + 'schema, strict mode is `true`, and upsert is `true`.');
  485. }
  486. if (strictQuery === 'throw') {
  487. throw new StrictModeError(path, 'Path "' + path + '" is not in ' + 'schema and strictQuery is \'throw\'.');
  488. } else if (strictQuery) {
  489. delete obj[path];
  490. }
  491. } else if (val == null) {
  492. continue;
  493. } else if (getConstructorName(val) === 'Object') {
  494. any$conditionals = Object.keys(val).some(isOperator);
  495. if (!any$conditionals) {
  496. obj[path] = schematype.castForQueryWrapper({
  497. val: val,
  498. context: context
  499. });
  500. } else {
  501. var ks = Object.keys(val);
  502. var $cond = void 0;
  503. var _k = ks.length;
  504. while (_k--) {
  505. $cond = ks[_k];
  506. nested = val[$cond];
  507. if ($cond === '$not') {
  508. if (nested && schematype) {
  509. _keys = Object.keys(nested);
  510. if (_keys.length && isOperator(_keys[0])) {
  511. for (var key in nested) {
  512. nested[key] = schematype.castForQueryWrapper({
  513. $conditional: key,
  514. val: nested[key],
  515. context: context
  516. });
  517. }
  518. } else {
  519. val[$cond] = schematype.castForQueryWrapper({
  520. $conditional: $cond,
  521. val: nested,
  522. context: context
  523. });
  524. }
  525. continue;
  526. }
  527. } else {
  528. val[$cond] = schematype.castForQueryWrapper({
  529. $conditional: $cond,
  530. val: nested,
  531. context: context
  532. });
  533. }
  534. }
  535. }
  536. } else if (Array.isArray(val) && ['Buffer', 'Array'].indexOf(schematype.instance) === -1) {
  537. var casted = [];
  538. var valuesArray = val;
  539. var _iterator = _createForOfIteratorHelper(valuesArray),
  540. _step;
  541. try {
  542. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  543. var _val = _step.value;
  544. casted.push(schematype.castForQueryWrapper({
  545. val: _val,
  546. context: context
  547. }));
  548. }
  549. } catch (err) {
  550. _iterator.e(err);
  551. } finally {
  552. _iterator.f();
  553. }
  554. obj[path] = {
  555. $in: casted
  556. };
  557. } else {
  558. obj[path] = schematype.castForQueryWrapper({
  559. val: val,
  560. context: context
  561. });
  562. }
  563. }
  564. }
  565. return obj;
  566. };
  567. function _cast(val, numbertype, context) {
  568. if (Array.isArray(val)) {
  569. val.forEach(function (item, i) {
  570. if (Array.isArray(item) || isObject(item)) {
  571. return _cast(item, numbertype, context);
  572. }
  573. val[i] = numbertype.castForQueryWrapper({
  574. val: item,
  575. context: context
  576. });
  577. });
  578. } else {
  579. var nearKeys = Object.keys(val);
  580. var nearLen = nearKeys.length;
  581. while (nearLen--) {
  582. var nkey = nearKeys[nearLen];
  583. var item = val[nkey];
  584. if (Array.isArray(item) || isObject(item)) {
  585. _cast(item, numbertype, context);
  586. val[nkey] = item;
  587. } else {
  588. val[nkey] = numbertype.castForQuery({
  589. val: item,
  590. context: context
  591. });
  592. }
  593. }
  594. }
  595. }
  596. /***/ }),
  597. /***/ 6670:
  598. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  599. "use strict";
  600. var CastError = __webpack_require__(1795);
  601. /*!
  602. * Given a value, cast it to a boolean, or throw a `CastError` if the value
  603. * cannot be casted. `null` and `undefined` are considered valid.
  604. *
  605. * @param {Any} value
  606. * @param {String} [path] optional the path to set on the CastError
  607. * @return {Boolean|null|undefined}
  608. * @throws {CastError} if `value` is not one of the allowed values
  609. * @api private
  610. */
  611. module.exports = function castBoolean(value, path) {
  612. if (module.exports.convertToTrue.has(value)) {
  613. return true;
  614. }
  615. if (module.exports.convertToFalse.has(value)) {
  616. return false;
  617. }
  618. if (value == null) {
  619. return value;
  620. }
  621. throw new CastError('boolean', value, path);
  622. };
  623. module.exports.convertToTrue = new Set([true, 'true', 1, '1', 'yes']);
  624. module.exports.convertToFalse = new Set([false, 'false', 0, '0', 'no']);
  625. /***/ }),
  626. /***/ 195:
  627. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  628. "use strict";
  629. var assert = __webpack_require__(9373);
  630. module.exports = function castDate(value) {
  631. // Support empty string because of empty form values. Originally introduced
  632. // in https://github.com/Automattic/mongoose/commit/efc72a1898fc3c33a319d915b8c5463a22938dfe
  633. if (value == null || value === '') {
  634. return null;
  635. }
  636. if (value instanceof Date) {
  637. assert.ok(!isNaN(value.valueOf()));
  638. return value;
  639. }
  640. var date;
  641. assert.ok(typeof value !== 'boolean');
  642. if (value instanceof Number || typeof value === 'number') {
  643. date = new Date(value);
  644. } else if (typeof value === 'string' && !isNaN(Number(value)) && (Number(value) >= 275761 || Number(value) < -271820)) {
  645. // string representation of milliseconds take this path
  646. date = new Date(Number(value));
  647. } else if (typeof value.valueOf === 'function') {
  648. // support for moment.js. This is also the path strings will take because
  649. // strings have a `valueOf()`
  650. date = new Date(value.valueOf());
  651. } else {
  652. // fallback
  653. date = new Date(value);
  654. }
  655. if (!isNaN(date.valueOf())) {
  656. return date;
  657. }
  658. assert.ok(false);
  659. };
  660. /***/ }),
  661. /***/ 6209:
  662. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  663. "use strict";
  664. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  665. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  666. var Decimal128Type = __webpack_require__(5003);
  667. var assert = __webpack_require__(9373);
  668. module.exports = function castDecimal128(value) {
  669. if (value == null) {
  670. return value;
  671. }
  672. if (_typeof(value) === 'object' && typeof value.$numberDecimal === 'string') {
  673. return Decimal128Type.fromString(value.$numberDecimal);
  674. }
  675. if (value instanceof Decimal128Type) {
  676. return value;
  677. }
  678. if (typeof value === 'string') {
  679. return Decimal128Type.fromString(value);
  680. }
  681. if (Buffer.isBuffer(value)) {
  682. return new Decimal128Type(value);
  683. }
  684. if (typeof value === 'number') {
  685. return Decimal128Type.fromString(String(value));
  686. }
  687. if (typeof value.valueOf === 'function' && typeof value.valueOf() === 'string') {
  688. return Decimal128Type.fromString(value.valueOf());
  689. }
  690. assert.ok(false);
  691. };
  692. /***/ }),
  693. /***/ 3065:
  694. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  695. "use strict";
  696. var assert = __webpack_require__(9373);
  697. /*!
  698. * Given a value, cast it to a number, or throw an `Error` if the value
  699. * cannot be casted. `null` and `undefined` are considered valid.
  700. *
  701. * @param {Any} value
  702. * @return {Number}
  703. * @throws {Error} if `value` is not one of the allowed values
  704. * @api private
  705. */
  706. module.exports = function castNumber(val) {
  707. if (val == null) {
  708. return val;
  709. }
  710. if (val === '') {
  711. return null;
  712. }
  713. if (typeof val === 'string' || typeof val === 'boolean') {
  714. val = Number(val);
  715. }
  716. assert.ok(!isNaN(val));
  717. if (val instanceof Number) {
  718. return val.valueOf();
  719. }
  720. if (typeof val === 'number') {
  721. return val;
  722. }
  723. if (!Array.isArray(val) && typeof val.valueOf === 'function') {
  724. return Number(val.valueOf());
  725. }
  726. if (val.toString && !Array.isArray(val) && val.toString() == Number(val)) {
  727. return Number(val);
  728. }
  729. assert.ok(false);
  730. };
  731. /***/ }),
  732. /***/ 4731:
  733. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  734. "use strict";
  735. var isBsonType = __webpack_require__(1563);
  736. var ObjectId = (__webpack_require__(9906).get)().ObjectId;
  737. module.exports = function castObjectId(value) {
  738. if (value == null) {
  739. return value;
  740. }
  741. if (isBsonType(value, 'ObjectID')) {
  742. return value;
  743. }
  744. if (value._id) {
  745. if (isBsonType(value._id, 'ObjectID')) {
  746. return value._id;
  747. }
  748. if (value._id.toString instanceof Function) {
  749. return new ObjectId(value._id.toString());
  750. }
  751. }
  752. if (value.toString instanceof Function) {
  753. return new ObjectId(value.toString());
  754. }
  755. return new ObjectId(value);
  756. };
  757. /***/ }),
  758. /***/ 2417:
  759. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  760. "use strict";
  761. var CastError = __webpack_require__(1795);
  762. /*!
  763. * Given a value, cast it to a string, or throw a `CastError` if the value
  764. * cannot be casted. `null` and `undefined` are considered valid.
  765. *
  766. * @param {Any} value
  767. * @param {String} [path] optional the path to set on the CastError
  768. * @return {string|null|undefined}
  769. * @throws {CastError}
  770. * @api private
  771. */
  772. module.exports = function castString(value, path) {
  773. // If null or undefined
  774. if (value == null) {
  775. return value;
  776. } // handle documents being passed
  777. if (value._id && typeof value._id === 'string') {
  778. return value._id;
  779. } // Re: gh-647 and gh-3030, we're ok with casting using `toString()`
  780. // **unless** its the default Object.toString, because "[object Object]"
  781. // doesn't really qualify as useful data
  782. if (value.toString && value.toString !== Object.prototype.toString && !Array.isArray(value)) {
  783. return value.toString();
  784. }
  785. throw new CastError('string', value, path);
  786. };
  787. /***/ }),
  788. /***/ 8727:
  789. /***/ ((module, exports, __webpack_require__) => {
  790. "use strict";
  791. /*!
  792. * Module dependencies.
  793. */
  794. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
  795. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
  796. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  797. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  798. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  799. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  800. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  801. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  802. var InternalCache = __webpack_require__(6379);
  803. var MongooseError = __webpack_require__(4888);
  804. var MixedSchema = __webpack_require__(3861);
  805. var ObjectExpectedError = __webpack_require__(4107);
  806. var ObjectParameterError = __webpack_require__(900);
  807. var ParallelValidateError = __webpack_require__(7962);
  808. var Schema = __webpack_require__(5506);
  809. var StrictModeError = __webpack_require__(3328);
  810. var ValidationError = __webpack_require__(122);
  811. var ValidatorError = __webpack_require__(2037);
  812. var VirtualType = __webpack_require__(459);
  813. var $__hasIncludedChildren = __webpack_require__(7427);
  814. var promiseOrCallback = __webpack_require__(8486);
  815. var cleanModifiedSubpaths = __webpack_require__(4134);
  816. var compile = (__webpack_require__(8724)/* .compile */ .M);
  817. var defineKey = (__webpack_require__(8724)/* .defineKey */ .c);
  818. var flatten = (__webpack_require__(2829)/* .flatten */ .x);
  819. var flattenObjectWithDottedPaths = __webpack_require__(207);
  820. var get = __webpack_require__(9981);
  821. var getEmbeddedDiscriminatorPath = __webpack_require__(111);
  822. var getKeysInSchemaOrder = __webpack_require__(37);
  823. var handleSpreadDoc = __webpack_require__(719);
  824. var immediate = __webpack_require__(1490);
  825. var isDefiningProjection = __webpack_require__(2183);
  826. var isExclusive = __webpack_require__(9098);
  827. var inspect = (__webpack_require__(161).inspect);
  828. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  829. var markArraySubdocsPopulated = __webpack_require__(5837);
  830. var mpath = __webpack_require__(3564);
  831. var queryhelpers = __webpack_require__(2888);
  832. var utils = __webpack_require__(6872);
  833. var isPromise = __webpack_require__(5543);
  834. var clone = utils.clone;
  835. var deepEqual = utils.deepEqual;
  836. var isMongooseObject = utils.isMongooseObject;
  837. var arrayAtomicsBackupSymbol = (__webpack_require__(8770).arrayAtomicsBackupSymbol);
  838. var arrayAtomicsSymbol = (__webpack_require__(8770).arrayAtomicsSymbol);
  839. var documentArrayParent = (__webpack_require__(8770).documentArrayParent);
  840. var documentIsModified = (__webpack_require__(8770).documentIsModified);
  841. var documentModifiedPaths = (__webpack_require__(8770).documentModifiedPaths);
  842. var documentSchemaSymbol = (__webpack_require__(8770).documentSchemaSymbol);
  843. var getSymbol = (__webpack_require__(8770).getSymbol);
  844. var populateModelSymbol = (__webpack_require__(8770).populateModelSymbol);
  845. var scopeSymbol = (__webpack_require__(8770).scopeSymbol);
  846. var schemaMixedSymbol = (__webpack_require__(8107).schemaMixedSymbol);
  847. var parentPaths = __webpack_require__(251);
  848. var DocumentArray;
  849. var MongooseArray;
  850. var Embedded;
  851. var specialProperties = utils.specialProperties;
  852. /**
  853. * The core Mongoose document constructor. You should not call this directly,
  854. * the Mongoose [Model constructor](./api.html#Model) calls this for you.
  855. *
  856. * @param {Object} obj the values to set
  857. * @param {Object} [fields] optional object containing the fields which were selected in the query returning this document and any populated paths data
  858. * @param {Object} [options] various configuration options for the document
  859. * @param {Boolean} [options.defaults=true] if `false`, skip applying default values to this document.
  860. * @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#events_class_events_eventemitter
  861. * @event `init`: Emitted on a document after it has been retrieved from the db and fully hydrated by Mongoose.
  862. * @event `save`: Emitted when the document is successfully saved
  863. * @api private
  864. */
  865. function Document(obj, fields, skipId, options) {
  866. if (_typeof(skipId) === 'object' && skipId != null) {
  867. options = skipId;
  868. skipId = options.skipId;
  869. }
  870. options = Object.assign({}, options); // Support `browserDocument.js` syntax
  871. if (this.$__schema == null) {
  872. var _schema = utils.isObject(fields) && !fields.instanceOfSchema ? new Schema(fields) : fields;
  873. this.$__setSchema(_schema);
  874. fields = skipId;
  875. skipId = options;
  876. options = arguments[4] || {};
  877. }
  878. this.$__ = new InternalCache();
  879. this.$isNew = 'isNew' in options ? options.isNew : true;
  880. if (options.priorDoc != null) {
  881. this.$__.priorDoc = options.priorDoc;
  882. }
  883. if (skipId) {
  884. this.$__.skipId = skipId;
  885. }
  886. if (obj != null && _typeof(obj) !== 'object') {
  887. throw new ObjectParameterError(obj, 'obj', 'Document');
  888. }
  889. var defaults = true;
  890. if (options.defaults !== undefined) {
  891. this.$__.defaults = options.defaults;
  892. defaults = options.defaults;
  893. }
  894. var schema = this.$__schema;
  895. if (typeof fields === 'boolean' || fields === 'throw') {
  896. this.$__.strictMode = fields;
  897. fields = undefined;
  898. } else {
  899. this.$__.strictMode = schema.options.strict;
  900. if (fields != null) {
  901. this.$__.selected = fields;
  902. }
  903. }
  904. var requiredPaths = schema.requiredPaths(true);
  905. var _iterator = _createForOfIteratorHelper(requiredPaths),
  906. _step;
  907. try {
  908. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  909. var path = _step.value;
  910. this.$__.activePaths.require(path);
  911. }
  912. } catch (err) {
  913. _iterator.e(err);
  914. } finally {
  915. _iterator.f();
  916. }
  917. var exclude = null; // determine if this doc is a result of a query with
  918. // excluded fields
  919. if (utils.isPOJO(fields)) {
  920. exclude = isExclusive(fields);
  921. this.$__.fields = fields;
  922. this.$__.exclude = exclude;
  923. }
  924. var hasIncludedChildren = exclude === false && fields ? $__hasIncludedChildren(fields) : null;
  925. if (this._doc == null) {
  926. this.$__buildDoc(obj, fields, skipId, exclude, hasIncludedChildren, false); // By default, defaults get applied **before** setting initial values
  927. // Re: gh-6155
  928. if (defaults) {
  929. $__applyDefaults(this, fields, exclude, hasIncludedChildren, true, null);
  930. }
  931. }
  932. if (obj) {
  933. // Skip set hooks
  934. if (this.$__original_set) {
  935. this.$__original_set(obj, undefined, true, options);
  936. } else {
  937. this.$set(obj, undefined, true, options);
  938. }
  939. if (obj instanceof Document) {
  940. this.$isNew = obj.$isNew;
  941. }
  942. } // Function defaults get applied **after** setting initial values so they
  943. // see the full doc rather than an empty one, unless they opt out.
  944. // Re: gh-3781, gh-6155
  945. if (options.willInit && defaults) {
  946. if (options.skipDefaults) {
  947. this.$__.skipDefaults = options.skipDefaults;
  948. }
  949. } else if (defaults) {
  950. $__applyDefaults(this, fields, exclude, hasIncludedChildren, false, options.skipDefaults);
  951. }
  952. if (!this.$__.strictMode && obj) {
  953. var _this = this;
  954. var keys = Object.keys(this._doc);
  955. keys.forEach(function (key) {
  956. // Avoid methods, virtuals, existing fields, and `$` keys. The latter is to avoid overwriting
  957. // Mongoose internals.
  958. if (!(key in schema.tree) && !(key in schema.methods) && !(key in schema.virtuals) && !key.startsWith('$')) {
  959. defineKey({
  960. prop: key,
  961. subprops: null,
  962. prototype: _this
  963. });
  964. }
  965. });
  966. }
  967. applyQueue(this);
  968. }
  969. Object.defineProperty(Document.prototype, 'isNew', {
  970. get: function get() {
  971. return this.$isNew;
  972. },
  973. set: function set(value) {
  974. this.$isNew = value;
  975. }
  976. });
  977. Object.defineProperty(Document.prototype, 'errors', {
  978. get: function get() {
  979. return this.$errors;
  980. },
  981. set: function set(value) {
  982. this.$errors = value;
  983. }
  984. });
  985. /*!
  986. * Document exposes the NodeJS event emitter API, so you can use
  987. * `on`, `once`, etc.
  988. */
  989. utils.each(['on', 'once', 'emit', 'listeners', 'removeListener', 'setMaxListeners', 'removeAllListeners', 'addListener'], function (emitterFn) {
  990. Document.prototype[emitterFn] = function () {
  991. // Delay creating emitter until necessary because emitters take up a lot of memory,
  992. // especially for subdocuments.
  993. if (!this.$__.emitter) {
  994. if (emitterFn === 'emit') {
  995. return;
  996. }
  997. this.$__.emitter = new EventEmitter();
  998. this.$__.emitter.setMaxListeners(0);
  999. }
  1000. return this.$__.emitter[emitterFn].apply(this.$__.emitter, arguments);
  1001. };
  1002. Document.prototype["$".concat(emitterFn)] = Document.prototype[emitterFn];
  1003. });
  1004. Document.prototype.constructor = Document;
  1005. for (var i in EventEmitter.prototype) {
  1006. Document[i] = EventEmitter.prototype[i];
  1007. }
  1008. /**
  1009. * The document's internal schema.
  1010. *
  1011. * @api private
  1012. * @property schema
  1013. * @memberOf Document
  1014. * @instance
  1015. */
  1016. Document.prototype.$__schema;
  1017. /**
  1018. * The document's schema.
  1019. *
  1020. * @api public
  1021. * @property schema
  1022. * @memberOf Document
  1023. * @instance
  1024. */
  1025. Document.prototype.schema;
  1026. /**
  1027. * Empty object that you can use for storing properties on the document. This
  1028. * is handy for passing data to middleware without conflicting with Mongoose
  1029. * internals.
  1030. *
  1031. * #### Example:
  1032. *
  1033. * schema.pre('save', function() {
  1034. * // Mongoose will set `isNew` to `false` if `save()` succeeds
  1035. * this.$locals.wasNew = this.isNew;
  1036. * });
  1037. *
  1038. * schema.post('save', function() {
  1039. * // Prints true if `isNew` was set before `save()`
  1040. * console.log(this.$locals.wasNew);
  1041. * });
  1042. *
  1043. * @api public
  1044. * @property $locals
  1045. * @memberOf Document
  1046. * @instance
  1047. */
  1048. Object.defineProperty(Document.prototype, '$locals', {
  1049. configurable: false,
  1050. enumerable: false,
  1051. get: function get() {
  1052. if (this.$__.locals == null) {
  1053. this.$__.locals = {};
  1054. }
  1055. return this.$__.locals;
  1056. },
  1057. set: function set(v) {
  1058. this.$__.locals = v;
  1059. }
  1060. });
  1061. /**
  1062. * Boolean flag specifying if the document is new.
  1063. *
  1064. * @api public
  1065. * @property $isNew
  1066. * @memberOf Document
  1067. * @instance
  1068. */
  1069. Document.prototype.$isNew;
  1070. /**
  1071. * Boolean flag specifying if the document is new.
  1072. *
  1073. * @api public
  1074. * @property isNew
  1075. * @memberOf Document
  1076. * @instance
  1077. */
  1078. Document.prototype.isNew;
  1079. /**
  1080. * Set this property to add additional query filters when Mongoose saves this document and `isNew` is false.
  1081. *
  1082. * #### Example:
  1083. *
  1084. * // Make sure `save()` never updates a soft deleted document.
  1085. * schema.pre('save', function() {
  1086. * this.$where = { isDeleted: false };
  1087. * });
  1088. *
  1089. * @api public
  1090. * @property $where
  1091. * @memberOf Document
  1092. * @instance
  1093. */
  1094. Object.defineProperty(Document.prototype, '$where', {
  1095. configurable: false,
  1096. enumerable: false,
  1097. writable: true
  1098. });
  1099. /**
  1100. * The string version of this documents _id.
  1101. *
  1102. * #### Note:
  1103. *
  1104. * This getter exists on all documents by default. The getter can be disabled by setting the `id` [option](/docs/guide.html#id) of its `Schema` to false at construction time.
  1105. *
  1106. * new Schema({ name: String }, { id: false });
  1107. *
  1108. * @api public
  1109. * @see Schema options /docs/guide.html#options
  1110. * @property id
  1111. * @memberOf Document
  1112. * @instance
  1113. */
  1114. Document.prototype.id;
  1115. /**
  1116. * Hash containing current validation $errors.
  1117. *
  1118. * @api public
  1119. * @property $errors
  1120. * @memberOf Document
  1121. * @instance
  1122. */
  1123. Document.prototype.$errors;
  1124. /**
  1125. * Hash containing current validation errors.
  1126. *
  1127. * @api public
  1128. * @property errors
  1129. * @memberOf Document
  1130. * @instance
  1131. */
  1132. Document.prototype.errors;
  1133. /**
  1134. * A string containing the current operation that Mongoose is executing
  1135. * on this document. May be `null`, `'save'`, `'validate'`, or `'remove'`.
  1136. *
  1137. * #### Example:
  1138. *
  1139. * const doc = new Model({ name: 'test' });
  1140. * doc.$op; // null
  1141. *
  1142. * const promise = doc.save();
  1143. * doc.$op; // 'save'
  1144. *
  1145. * await promise;
  1146. * doc.$op; // null
  1147. *
  1148. * @api public
  1149. * @property $op
  1150. * @memberOf Document
  1151. * @instance
  1152. */
  1153. Object.defineProperty(Document.prototype, '$op', {
  1154. get: function get() {
  1155. return this.$__.op || null;
  1156. },
  1157. set: function set(value) {
  1158. this.$__.op = value;
  1159. }
  1160. });
  1161. /*!
  1162. * ignore
  1163. */
  1164. function $__applyDefaults(doc, fields, exclude, hasIncludedChildren, isBeforeSetters, pathsToSkip) {
  1165. var paths = Object.keys(doc.$__schema.paths);
  1166. var plen = paths.length;
  1167. for (var _i = 0; _i < plen; ++_i) {
  1168. var def = void 0;
  1169. var curPath = '';
  1170. var p = paths[_i];
  1171. if (p === '_id' && doc.$__.skipId) {
  1172. continue;
  1173. }
  1174. var type = doc.$__schema.paths[p];
  1175. var path = type.splitPath();
  1176. var len = path.length;
  1177. var included = false;
  1178. var doc_ = doc._doc;
  1179. for (var j = 0; j < len; ++j) {
  1180. if (doc_ == null) {
  1181. break;
  1182. }
  1183. var piece = path[j];
  1184. curPath += (!curPath.length ? '' : '.') + piece;
  1185. if (exclude === true) {
  1186. if (curPath in fields) {
  1187. break;
  1188. }
  1189. } else if (exclude === false && fields && !included) {
  1190. var hasSubpaths = type.$isSingleNested || type.$isMongooseDocumentArray;
  1191. if (curPath in fields || hasSubpaths && hasIncludedChildren != null && hasIncludedChildren[curPath]) {
  1192. included = true;
  1193. } else if (hasIncludedChildren != null && !hasIncludedChildren[curPath]) {
  1194. break;
  1195. }
  1196. }
  1197. if (j === len - 1) {
  1198. if (doc_[piece] !== void 0) {
  1199. break;
  1200. }
  1201. if (typeof type.defaultValue === 'function') {
  1202. if (!type.defaultValue.$runBeforeSetters && isBeforeSetters) {
  1203. break;
  1204. }
  1205. if (type.defaultValue.$runBeforeSetters && !isBeforeSetters) {
  1206. break;
  1207. }
  1208. } else if (!isBeforeSetters) {
  1209. // Non-function defaults should always run **before** setters
  1210. continue;
  1211. }
  1212. if (pathsToSkip && pathsToSkip[curPath]) {
  1213. break;
  1214. }
  1215. if (fields && exclude !== null) {
  1216. if (exclude === true) {
  1217. // apply defaults to all non-excluded fields
  1218. if (p in fields) {
  1219. continue;
  1220. }
  1221. try {
  1222. def = type.getDefault(doc, false);
  1223. } catch (err) {
  1224. doc.invalidate(p, err);
  1225. break;
  1226. }
  1227. if (typeof def !== 'undefined') {
  1228. doc_[piece] = def;
  1229. doc.$__.activePaths["default"](p);
  1230. }
  1231. } else if (included) {
  1232. // selected field
  1233. try {
  1234. def = type.getDefault(doc, false);
  1235. } catch (err) {
  1236. doc.invalidate(p, err);
  1237. break;
  1238. }
  1239. if (typeof def !== 'undefined') {
  1240. doc_[piece] = def;
  1241. doc.$__.activePaths["default"](p);
  1242. }
  1243. }
  1244. } else {
  1245. try {
  1246. def = type.getDefault(doc, false);
  1247. } catch (err) {
  1248. doc.invalidate(p, err);
  1249. break;
  1250. }
  1251. if (typeof def !== 'undefined') {
  1252. doc_[piece] = def;
  1253. doc.$__.activePaths["default"](p);
  1254. }
  1255. }
  1256. } else {
  1257. doc_ = doc_[piece];
  1258. }
  1259. }
  1260. }
  1261. }
  1262. /*!
  1263. * ignore
  1264. */
  1265. function $applyDefaultsToNested(val, path, doc) {
  1266. if (val == null) {
  1267. return;
  1268. }
  1269. flattenObjectWithDottedPaths(val);
  1270. var paths = Object.keys(doc.$__schema.paths);
  1271. var plen = paths.length;
  1272. var pathPieces = path.indexOf('.') === -1 ? [path] : path.split('.');
  1273. for (var _i2 = 0; _i2 < plen; ++_i2) {
  1274. var curPath = '';
  1275. var p = paths[_i2];
  1276. if (!p.startsWith(path + '.')) {
  1277. continue;
  1278. }
  1279. var type = doc.$__schema.paths[p];
  1280. var pieces = type.splitPath().slice(pathPieces.length);
  1281. var len = pieces.length;
  1282. if (type.defaultValue === void 0) {
  1283. continue;
  1284. }
  1285. var cur = val;
  1286. for (var j = 0; j < len; ++j) {
  1287. if (cur == null) {
  1288. break;
  1289. }
  1290. var piece = pieces[j];
  1291. if (j === len - 1) {
  1292. if (cur[piece] !== void 0) {
  1293. break;
  1294. }
  1295. try {
  1296. var def = type.getDefault(doc, false);
  1297. if (def !== void 0) {
  1298. cur[piece] = def;
  1299. }
  1300. } catch (err) {
  1301. doc.invalidate(path + '.' + curPath, err);
  1302. break;
  1303. }
  1304. break;
  1305. }
  1306. curPath += (!curPath.length ? '' : '.') + piece;
  1307. cur[piece] = cur[piece] || {};
  1308. cur = cur[piece];
  1309. }
  1310. }
  1311. }
  1312. /**
  1313. * Builds the default doc structure
  1314. *
  1315. * @param {Object} obj
  1316. * @param {Object} [fields]
  1317. * @param {Boolean} [skipId]
  1318. * @api private
  1319. * @method $__buildDoc
  1320. * @memberOf Document
  1321. * @instance
  1322. */
  1323. Document.prototype.$__buildDoc = function (obj, fields, skipId, exclude, hasIncludedChildren) {
  1324. var doc = {};
  1325. var paths = Object.keys(this.$__schema.paths). // Don't build up any paths that are underneath a map, we don't know
  1326. // what the keys will be
  1327. filter(function (p) {
  1328. return !p.includes('$*');
  1329. });
  1330. var plen = paths.length;
  1331. var ii = 0;
  1332. for (; ii < plen; ++ii) {
  1333. var p = paths[ii];
  1334. if (p === '_id') {
  1335. if (skipId) {
  1336. continue;
  1337. }
  1338. if (obj && '_id' in obj) {
  1339. continue;
  1340. }
  1341. }
  1342. var path = this.$__schema.paths[p].splitPath();
  1343. var len = path.length;
  1344. var last = len - 1;
  1345. var curPath = '';
  1346. var doc_ = doc;
  1347. var included = false;
  1348. for (var _i3 = 0; _i3 < len; ++_i3) {
  1349. var piece = path[_i3];
  1350. if (!curPath.length) {
  1351. curPath = piece;
  1352. } else {
  1353. curPath += '.' + piece;
  1354. } // support excluding intermediary levels
  1355. if (exclude === true) {
  1356. if (curPath in fields) {
  1357. break;
  1358. }
  1359. } else if (exclude === false && fields && !included) {
  1360. if (curPath in fields) {
  1361. included = true;
  1362. } else if (!hasIncludedChildren[curPath]) {
  1363. break;
  1364. }
  1365. }
  1366. if (_i3 < last) {
  1367. doc_ = doc_[piece] || (doc_[piece] = {});
  1368. }
  1369. }
  1370. }
  1371. this._doc = doc;
  1372. };
  1373. /*!
  1374. * Converts to POJO when you use the document for querying
  1375. */
  1376. Document.prototype.toBSON = function () {
  1377. return this.toObject(internalToObjectOptions);
  1378. };
  1379. /**
  1380. * Initializes the document without setters or marking anything modified.
  1381. *
  1382. * Called internally after a document is returned from mongodb. Normally,
  1383. * you do **not** need to call this function on your own.
  1384. *
  1385. * This function triggers `init` [middleware](/docs/middleware.html).
  1386. * Note that `init` hooks are [synchronous](/docs/middleware.html#synchronous).
  1387. *
  1388. * @param {Object} doc document returned by mongo
  1389. * @api public
  1390. * @memberOf Document
  1391. * @instance
  1392. */
  1393. Document.prototype.init = function (doc, opts, fn) {
  1394. if (typeof opts === 'function') {
  1395. fn = opts;
  1396. opts = null;
  1397. }
  1398. this.$__init(doc, opts);
  1399. if (fn) {
  1400. fn(null, this);
  1401. }
  1402. return this;
  1403. };
  1404. Document.prototype.$init = function () {
  1405. return this.constructor.prototype.init.apply(this, arguments);
  1406. };
  1407. Document.prototype.$__init = function (doc, opts) {
  1408. this.$isNew = false;
  1409. opts = opts || {}; // handle docs with populated paths
  1410. // If doc._id is not null or undefined
  1411. if (doc._id != null && opts.populated && opts.populated.length) {
  1412. var id = String(doc._id);
  1413. var _iterator2 = _createForOfIteratorHelper(opts.populated),
  1414. _step2;
  1415. try {
  1416. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  1417. var item = _step2.value;
  1418. if (item.isVirtual) {
  1419. this.$populated(item.path, utils.getValue(item.path, doc), item);
  1420. } else {
  1421. this.$populated(item.path, item._docs[id], item);
  1422. }
  1423. if (item._childDocs == null) {
  1424. continue;
  1425. }
  1426. var _iterator3 = _createForOfIteratorHelper(item._childDocs),
  1427. _step3;
  1428. try {
  1429. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  1430. var child = _step3.value;
  1431. if (child == null || child.$__ == null) {
  1432. continue;
  1433. }
  1434. child.$__.parent = this;
  1435. }
  1436. } catch (err) {
  1437. _iterator3.e(err);
  1438. } finally {
  1439. _iterator3.f();
  1440. }
  1441. item._childDocs = [];
  1442. }
  1443. } catch (err) {
  1444. _iterator2.e(err);
  1445. } finally {
  1446. _iterator2.f();
  1447. }
  1448. }
  1449. init(this, doc, this._doc, opts);
  1450. markArraySubdocsPopulated(this, opts.populated);
  1451. this.$emit('init', this);
  1452. this.constructor.emit('init', this);
  1453. var hasIncludedChildren = this.$__.exclude === false && this.$__.fields ? $__hasIncludedChildren(this.$__.fields) : null;
  1454. $__applyDefaults(this, this.$__.fields, this.$__.exclude, hasIncludedChildren, false, this.$__.skipDefaults);
  1455. return this;
  1456. };
  1457. /*!
  1458. * Init helper.
  1459. *
  1460. * @param {Object} self document instance
  1461. * @param {Object} obj raw mongodb doc
  1462. * @param {Object} doc object we are initializing
  1463. * @api private
  1464. */
  1465. function init(self, obj, doc, opts, prefix) {
  1466. prefix = prefix || '';
  1467. var keys = Object.keys(obj);
  1468. var len = keys.length;
  1469. var schemaType;
  1470. var path;
  1471. var i;
  1472. var index = 0;
  1473. var strict = self.$__.strictMode;
  1474. var docSchema = self.$__schema;
  1475. while (index < len) {
  1476. _init(index++);
  1477. }
  1478. function _init(index) {
  1479. i = keys[index];
  1480. path = prefix + i;
  1481. schemaType = docSchema.path(path); // Should still work if not a model-level discriminator, but should not be
  1482. // necessary. This is *only* to catch the case where we queried using the
  1483. // base model and the discriminated model has a projection
  1484. if (docSchema.$isRootDiscriminator && !self.$__isSelected(path)) {
  1485. return;
  1486. }
  1487. if (!schemaType && utils.isPOJO(obj[i])) {
  1488. // assume nested object
  1489. if (!doc[i]) {
  1490. doc[i] = {};
  1491. if (!strict && !(i in docSchema.tree) && !(i in docSchema.methods) && !(i in docSchema.virtuals)) {
  1492. self[i] = doc[i];
  1493. }
  1494. }
  1495. init(self, obj[i], doc[i], opts, path + '.');
  1496. } else if (!schemaType) {
  1497. doc[i] = obj[i];
  1498. if (!strict && !prefix) {
  1499. self[i] = obj[i];
  1500. }
  1501. } else {
  1502. // Retain order when overwriting defaults
  1503. if (doc.hasOwnProperty(i) && obj[i] !== void 0) {
  1504. delete doc[i];
  1505. }
  1506. if (obj[i] === null) {
  1507. doc[i] = schemaType._castNullish(null);
  1508. } else if (obj[i] !== undefined) {
  1509. var wasPopulated = obj[i].$__ == null ? null : obj[i].$__.wasPopulated;
  1510. if (schemaType && !wasPopulated) {
  1511. try {
  1512. doc[i] = schemaType.cast(obj[i], self, true);
  1513. } catch (e) {
  1514. self.invalidate(e.path, new ValidatorError({
  1515. path: e.path,
  1516. message: e.message,
  1517. type: 'cast',
  1518. value: e.value,
  1519. reason: e
  1520. }));
  1521. }
  1522. } else {
  1523. doc[i] = obj[i];
  1524. }
  1525. } // mark as hydrated
  1526. if (!self.$isModified(path)) {
  1527. self.$__.activePaths.init(path);
  1528. }
  1529. }
  1530. }
  1531. }
  1532. /**
  1533. * Sends an update command with this document `_id` as the query selector.
  1534. *
  1535. * #### Example:
  1536. *
  1537. * weirdCar.update({$inc: {wheels:1}}, { w: 1 }, callback);
  1538. *
  1539. * #### Valid options:
  1540. *
  1541. * - same as in [Model.update](#model_Model.update)
  1542. *
  1543. * @see Model.update #model_Model.update
  1544. * @param {Object} doc
  1545. * @param {Object} options
  1546. * @param {Function} callback
  1547. * @return {Query}
  1548. * @api public
  1549. * @memberOf Document
  1550. * @instance
  1551. */
  1552. Document.prototype.update = function update() {
  1553. var args = Array.prototype.slice.call(arguments);
  1554. args.unshift({
  1555. _id: this._id
  1556. });
  1557. var query = this.constructor.update.apply(this.constructor, args);
  1558. if (this.$session() != null) {
  1559. if (!('session' in query.options)) {
  1560. query.options.session = this.$session();
  1561. }
  1562. }
  1563. return query;
  1564. };
  1565. /**
  1566. * Sends an updateOne command with this document `_id` as the query selector.
  1567. *
  1568. * #### Example:
  1569. *
  1570. * weirdCar.updateOne({$inc: {wheels:1}}, { w: 1 }, callback);
  1571. *
  1572. * #### Valid options:
  1573. *
  1574. * - same as in [Model.updateOne](#model_Model.updateOne)
  1575. *
  1576. * @see Model.updateOne #model_Model.updateOne
  1577. * @param {Object} doc
  1578. * @param {Object} [options] optional see [`Query.prototype.setOptions()`](https://mongoosejs.com/docs/api.html#query_Query-setOptions)
  1579. * @param {Object} [options.lean] if truthy, mongoose will return the document as a plain JavaScript object rather than a mongoose document. See [`Query.lean()`](/docs/api.html#query_Query-lean) and the [Mongoose lean tutorial](/docs/tutorials/lean.html).
  1580. * @param {Boolean|String} [options.strict] overwrites the schema's [strict mode option](https://mongoosejs.com/docs/guide.html#strict)
  1581. * @param {Boolean} [options.timestamps=null] If set to `false` and [schema-level timestamps](/docs/guide.html#timestamps) are enabled, skip timestamps for this update. Note that this allows you to overwrite timestamps. Does nothing if schema-level timestamps are not set.
  1582. * @param {Function} callback
  1583. * @return {Query}
  1584. * @api public
  1585. * @memberOf Document
  1586. * @instance
  1587. */
  1588. Document.prototype.updateOne = function updateOne(doc, options, callback) {
  1589. var _this2 = this;
  1590. var query = this.constructor.updateOne({
  1591. _id: this._id
  1592. }, doc, options);
  1593. query.pre(function (cb) {
  1594. _this2.constructor._middleware.execPre('updateOne', _this2, [_this2], cb);
  1595. });
  1596. query.post(function (cb) {
  1597. _this2.constructor._middleware.execPost('updateOne', _this2, [_this2], {}, cb);
  1598. });
  1599. if (this.$session() != null) {
  1600. if (!('session' in query.options)) {
  1601. query.options.session = this.$session();
  1602. }
  1603. }
  1604. if (callback != null) {
  1605. return query.exec(callback);
  1606. }
  1607. return query;
  1608. };
  1609. /**
  1610. * Sends a replaceOne command with this document `_id` as the query selector.
  1611. *
  1612. * #### Valid options:
  1613. *
  1614. * - same as in [Model.replaceOne](https://mongoosejs.com/docs/api/model.html#model_Model.replaceOne)
  1615. *
  1616. * @see Model.replaceOne #model_Model.replaceOne
  1617. * @param {Object} doc
  1618. * @param {Object} options
  1619. * @param {Function} callback
  1620. * @return {Query}
  1621. * @api public
  1622. * @memberOf Document
  1623. * @instance
  1624. */
  1625. Document.prototype.replaceOne = function replaceOne() {
  1626. var args = Array.prototype.slice.call(arguments);
  1627. args.unshift({
  1628. _id: this._id
  1629. });
  1630. return this.constructor.replaceOne.apply(this.constructor, args);
  1631. };
  1632. /**
  1633. * Getter/setter around the session associated with this document. Used to
  1634. * automatically set `session` if you `save()` a doc that you got from a
  1635. * query with an associated session.
  1636. *
  1637. * #### Example:
  1638. *
  1639. * const session = MyModel.startSession();
  1640. * const doc = await MyModel.findOne().session(session);
  1641. * doc.$session() === session; // true
  1642. * doc.$session(null);
  1643. * doc.$session() === null; // true
  1644. *
  1645. * If this is a top-level document, setting the session propagates to all child
  1646. * docs.
  1647. *
  1648. * @param {ClientSession} [session] overwrite the current session
  1649. * @return {ClientSession}
  1650. * @method $session
  1651. * @api public
  1652. * @memberOf Document
  1653. */
  1654. Document.prototype.$session = function $session(session) {
  1655. if (arguments.length === 0) {
  1656. if (this.$__.session != null && this.$__.session.hasEnded) {
  1657. this.$__.session = null;
  1658. return null;
  1659. }
  1660. return this.$__.session;
  1661. }
  1662. if (session != null && session.hasEnded) {
  1663. throw new MongooseError('Cannot set a document\'s session to a session that has ended. Make sure you haven\'t ' + 'called `endSession()` on the session you are passing to `$session()`.');
  1664. }
  1665. if (session == null && this.$__.session == null) {
  1666. return;
  1667. }
  1668. this.$__.session = session;
  1669. if (!this.$isSubdocument) {
  1670. var subdocs = this.$getAllSubdocs();
  1671. var _iterator4 = _createForOfIteratorHelper(subdocs),
  1672. _step4;
  1673. try {
  1674. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  1675. var child = _step4.value;
  1676. child.$session(session);
  1677. }
  1678. } catch (err) {
  1679. _iterator4.e(err);
  1680. } finally {
  1681. _iterator4.f();
  1682. }
  1683. }
  1684. return session;
  1685. };
  1686. /**
  1687. * Overwrite all values in this document with the values of `obj`, except
  1688. * for immutable properties. Behaves similarly to `set()`, except for it
  1689. * unsets all properties that aren't in `obj`.
  1690. *
  1691. * @param {Object} obj the object to overwrite this document with
  1692. * @method overwrite
  1693. * @name overwrite
  1694. * @memberOf Document
  1695. * @instance
  1696. * @api public
  1697. */
  1698. Document.prototype.overwrite = function overwrite(obj) {
  1699. var keys = Array.from(new Set(Object.keys(this._doc).concat(Object.keys(obj))));
  1700. for (var _i4 = 0, _keys = keys; _i4 < _keys.length; _i4++) {
  1701. var key = _keys[_i4];
  1702. if (key === '_id') {
  1703. continue;
  1704. } // Explicitly skip version key
  1705. if (this.$__schema.options.versionKey && key === this.$__schema.options.versionKey) {
  1706. continue;
  1707. }
  1708. if (this.$__schema.options.discriminatorKey && key === this.$__schema.options.discriminatorKey) {
  1709. continue;
  1710. }
  1711. this.$set(key, obj[key]);
  1712. }
  1713. return this;
  1714. };
  1715. /**
  1716. * Alias for `set()`, used internally to avoid conflicts
  1717. *
  1718. * @param {String|Object} path path or object of key/vals to set
  1719. * @param {Any} val the value to set
  1720. * @param {Schema|String|Number|Buffer|*} [type] optionally specify a type for "on-the-fly" attributes
  1721. * @param {Object} [options] optionally specify options that modify the behavior of the set
  1722. * @param {Boolean} [options.merge=false] if true, setting a [nested path](/docs/subdocs.html#subdocuments-versus-nested-paths) will merge existing values rather than overwrite the whole object. So `doc.set('nested', { a: 1, b: 2 })` becomes `doc.set('nested.a', 1); doc.set('nested.b', 2);`
  1723. * @method $set
  1724. * @name $set
  1725. * @memberOf Document
  1726. * @instance
  1727. * @api public
  1728. */
  1729. Document.prototype.$set = function $set(path, val, type, options) {
  1730. var _this3 = this;
  1731. if (utils.isPOJO(type)) {
  1732. options = type;
  1733. type = undefined;
  1734. }
  1735. var merge = options && options.merge;
  1736. var adhoc = type && type !== true;
  1737. var constructing = type === true;
  1738. var adhocs;
  1739. var keys;
  1740. var i = 0;
  1741. var pathtype;
  1742. var key;
  1743. var prefix;
  1744. var strict = options && 'strict' in options ? options.strict : this.$__.strictMode;
  1745. if (adhoc) {
  1746. adhocs = this.$__.adhocPaths || (this.$__.adhocPaths = {});
  1747. adhocs[path] = this.$__schema.interpretAsType(path, type, this.$__schema.options);
  1748. }
  1749. if (path == null) {
  1750. var _ref = [val, path];
  1751. path = _ref[0];
  1752. val = _ref[1];
  1753. } else if (typeof path !== 'string') {
  1754. // new Document({ key: val })
  1755. if (path instanceof Document) {
  1756. if (path.$__isNested) {
  1757. path = path.toObject();
  1758. } else {
  1759. path = path._doc;
  1760. }
  1761. }
  1762. if (path == null) {
  1763. var _ref2 = [val, path];
  1764. path = _ref2[0];
  1765. val = _ref2[1];
  1766. }
  1767. prefix = val ? val + '.' : '';
  1768. keys = getKeysInSchemaOrder(this.$__schema, path);
  1769. var len = keys.length; // `_skipMinimizeTopLevel` is because we may have deleted the top-level
  1770. // nested key to ensure key order.
  1771. var _skipMinimizeTopLevel = options && options._skipMinimizeTopLevel || false;
  1772. if (len === 0 && _skipMinimizeTopLevel) {
  1773. delete options._skipMinimizeTopLevel;
  1774. if (val) {
  1775. this.$set(val, {});
  1776. }
  1777. return this;
  1778. }
  1779. for (var _i5 = 0; _i5 < len; ++_i5) {
  1780. key = keys[_i5];
  1781. var pathName = prefix + key;
  1782. pathtype = this.$__schema.pathType(pathName);
  1783. var valForKey = path[key]; // On initial set, delete any nested keys if we're going to overwrite
  1784. // them to ensure we keep the user's key order.
  1785. if (type === true && !prefix && valForKey != null && pathtype === 'nested' && this._doc[key] != null) {
  1786. delete this._doc[key]; // Make sure we set `{}` back even if we minimize re: gh-8565
  1787. options = Object.assign({}, options, {
  1788. _skipMinimizeTopLevel: true
  1789. });
  1790. } else {
  1791. // Make sure we set `{_skipMinimizeTopLevel: false}` if don't have overwrite: gh-10441
  1792. options = Object.assign({}, options, {
  1793. _skipMinimizeTopLevel: false
  1794. });
  1795. }
  1796. if (utils.isNonBuiltinObject(valForKey) && pathtype === 'nested') {
  1797. $applyDefaultsToNested(path[key], prefix + key, this);
  1798. this.$set(prefix + key, path[key], constructing, Object.assign({}, options, {
  1799. _skipMarkModified: true
  1800. }));
  1801. continue;
  1802. } else if (strict) {
  1803. // Don't overwrite defaults with undefined keys (gh-3981) (gh-9039)
  1804. if (constructing && path[key] === void 0 && this.$get(pathName) !== void 0) {
  1805. continue;
  1806. }
  1807. if (pathtype === 'adhocOrUndefined') {
  1808. pathtype = getEmbeddedDiscriminatorPath(this, pathName, {
  1809. typeOnly: true
  1810. });
  1811. }
  1812. if (pathtype === 'real' || pathtype === 'virtual') {
  1813. var p = path[key];
  1814. this.$set(prefix + key, p, constructing, options);
  1815. } else if (pathtype === 'nested' && path[key] instanceof Document) {
  1816. this.$set(prefix + key, path[key].toObject({
  1817. transform: false
  1818. }), constructing, options);
  1819. } else if (strict === 'throw') {
  1820. if (pathtype === 'nested') {
  1821. throw new ObjectExpectedError(key, path[key]);
  1822. } else {
  1823. throw new StrictModeError(key);
  1824. }
  1825. }
  1826. } else if (path[key] !== void 0) {
  1827. this.$set(prefix + key, path[key], constructing, options);
  1828. }
  1829. } // Ensure all properties are in correct order
  1830. var orderedDoc = {};
  1831. var orderedKeys = Object.keys(this.$__schema.tree);
  1832. for (var _i6 = 0, _len = orderedKeys.length; _i6 < _len; ++_i6) {
  1833. (key = orderedKeys[_i6]) && this._doc.hasOwnProperty(key) && (orderedDoc[key] = undefined);
  1834. }
  1835. this._doc = Object.assign(orderedDoc, this._doc);
  1836. return this;
  1837. }
  1838. var pathType = this.$__schema.pathType(path);
  1839. if (pathType === 'adhocOrUndefined') {
  1840. pathType = getEmbeddedDiscriminatorPath(this, path, {
  1841. typeOnly: true
  1842. });
  1843. } // Assume this is a Mongoose document that was copied into a POJO using
  1844. // `Object.assign()` or `{...doc}`
  1845. val = handleSpreadDoc(val); // if this doc is being constructed we should not trigger getters
  1846. var priorVal = function () {
  1847. if (_this3.$__.priorDoc != null) {
  1848. return _this3.$__.priorDoc.$__getValue(path);
  1849. }
  1850. if (constructing) {
  1851. return void 0;
  1852. }
  1853. return _this3.$__getValue(path);
  1854. }();
  1855. if (pathType === 'nested' && val) {
  1856. if (_typeof(val) === 'object' && val != null) {
  1857. if (val.$__ != null) {
  1858. val = val.toObject(internalToObjectOptions);
  1859. }
  1860. if (val == null) {
  1861. this.invalidate(path, new MongooseError.CastError('Object', val, path));
  1862. return this;
  1863. }
  1864. var hasInitialVal = this.$__.savedState != null && this.$__.savedState.hasOwnProperty(path);
  1865. if (this.$__.savedState != null && !this.$isNew && !this.$__.savedState.hasOwnProperty(path)) {
  1866. var initialVal = this.$__getValue(path);
  1867. this.$__.savedState[path] = initialVal;
  1868. var _keys3 = Object.keys(initialVal || {});
  1869. for (var _i7 = 0, _keys4 = _keys3; _i7 < _keys4.length; _i7++) {
  1870. var _key = _keys4[_i7];
  1871. this.$__.savedState[path + '.' + _key] = initialVal[_key];
  1872. }
  1873. }
  1874. if (!merge) {
  1875. this.$__setValue(path, null);
  1876. cleanModifiedSubpaths(this, path);
  1877. } else {
  1878. return this.$set(val, path, constructing);
  1879. }
  1880. var _keys2 = getKeysInSchemaOrder(this.$__schema, val, path);
  1881. this.$__setValue(path, {});
  1882. var _iterator5 = _createForOfIteratorHelper(_keys2),
  1883. _step5;
  1884. try {
  1885. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  1886. var _key2 = _step5.value;
  1887. this.$set(path + '.' + _key2, val[_key2], constructing, options);
  1888. }
  1889. } catch (err) {
  1890. _iterator5.e(err);
  1891. } finally {
  1892. _iterator5.f();
  1893. }
  1894. if (priorVal != null && utils.deepEqual(hasInitialVal ? this.$__.savedState[path] : priorVal, val)) {
  1895. this.unmarkModified(path);
  1896. } else {
  1897. this.markModified(path);
  1898. }
  1899. return this;
  1900. }
  1901. this.invalidate(path, new MongooseError.CastError('Object', val, path));
  1902. return this;
  1903. }
  1904. var schema;
  1905. var parts = path.indexOf('.') === -1 ? [path] : path.split('.'); // Might need to change path for top-level alias
  1906. if (typeof this.$__schema.aliases[parts[0]] === 'string') {
  1907. parts[0] = this.$__schema.aliases[parts[0]];
  1908. }
  1909. if (pathType === 'adhocOrUndefined' && strict) {
  1910. // check for roots that are Mixed types
  1911. var mixed;
  1912. for (i = 0; i < parts.length; ++i) {
  1913. var subpath = parts.slice(0, i + 1).join('.'); // If path is underneath a virtual, bypass everything and just set it.
  1914. if (i + 1 < parts.length && this.$__schema.pathType(subpath) === 'virtual') {
  1915. mpath.set(path, val, this);
  1916. return this;
  1917. }
  1918. schema = this.$__schema.path(subpath);
  1919. if (schema == null) {
  1920. continue;
  1921. }
  1922. if (schema instanceof MixedSchema) {
  1923. // allow changes to sub paths of mixed types
  1924. mixed = true;
  1925. break;
  1926. }
  1927. }
  1928. if (schema == null) {
  1929. // Check for embedded discriminators
  1930. schema = getEmbeddedDiscriminatorPath(this, path);
  1931. }
  1932. if (!mixed && !schema) {
  1933. if (strict === 'throw') {
  1934. throw new StrictModeError(path);
  1935. }
  1936. return this;
  1937. }
  1938. } else if (pathType === 'virtual') {
  1939. schema = this.$__schema.virtualpath(path);
  1940. schema.applySetters(val, this);
  1941. return this;
  1942. } else {
  1943. schema = this.$__path(path);
  1944. } // gh-4578, if setting a deeply nested path that doesn't exist yet, create it
  1945. var cur = this._doc;
  1946. var curPath = '';
  1947. for (i = 0; i < parts.length - 1; ++i) {
  1948. cur = cur[parts[i]];
  1949. curPath += (curPath.length !== 0 ? '.' : '') + parts[i];
  1950. if (!cur) {
  1951. this.$set(curPath, {}); // Hack re: gh-5800. If nested field is not selected, it probably exists
  1952. // so `MongoServerError: cannot use the part (nested of nested.num) to
  1953. // traverse the element ({nested: null})` is not likely. If user gets
  1954. // that error, its their fault for now. We should reconsider disallowing
  1955. // modifying not selected paths for 6.x
  1956. if (!this.$__isSelected(curPath)) {
  1957. this.unmarkModified(curPath);
  1958. }
  1959. cur = this.$__getValue(curPath);
  1960. }
  1961. }
  1962. var pathToMark; // When using the $set operator the path to the field must already exist.
  1963. // Else mongodb throws: "LEFT_SUBFIELD only supports Object"
  1964. if (parts.length <= 1) {
  1965. pathToMark = path;
  1966. } else {
  1967. var _len2 = parts.length;
  1968. for (i = 0; i < _len2; ++i) {
  1969. var _subpath = parts.slice(0, i + 1).join('.');
  1970. if (this.$get(_subpath, null, {
  1971. getters: false
  1972. }) === null) {
  1973. pathToMark = _subpath;
  1974. break;
  1975. }
  1976. }
  1977. if (!pathToMark) {
  1978. pathToMark = path;
  1979. }
  1980. }
  1981. if (!schema) {
  1982. this.$__set(pathToMark, path, options, constructing, parts, schema, val, priorVal);
  1983. if (pathType === 'nested' && val == null) {
  1984. cleanModifiedSubpaths(this, path);
  1985. }
  1986. return this;
  1987. } // If overwriting a subdocument path, make sure to clear out
  1988. // any errors _before_ setting, so new errors that happen
  1989. // get persisted. Re: #9080
  1990. if (schema.$isSingleNested || schema.$isMongooseArray) {
  1991. _markValidSubpaths(this, path);
  1992. }
  1993. if (val != null && merge && schema.$isSingleNested) {
  1994. if (val instanceof Document) {
  1995. val = val.toObject({
  1996. virtuals: false,
  1997. transform: false
  1998. });
  1999. }
  2000. var _keys5 = Object.keys(val);
  2001. for (var _i8 = 0, _keys6 = _keys5; _i8 < _keys6.length; _i8++) {
  2002. var _key3 = _keys6[_i8];
  2003. this.$set(path + '.' + _key3, val[_key3], constructing, options);
  2004. }
  2005. return this;
  2006. }
  2007. var shouldSet = true;
  2008. try {
  2009. // If the user is trying to set a ref path to a document with
  2010. // the correct model name, treat it as populated
  2011. var refMatches = function () {
  2012. if (schema.options == null) {
  2013. return false;
  2014. }
  2015. if (!(val instanceof Document)) {
  2016. return false;
  2017. }
  2018. var model = val.constructor; // Check ref
  2019. var ref = schema.options.ref;
  2020. if (ref != null && (ref === model.modelName || ref === model.baseModelName)) {
  2021. return true;
  2022. } // Check refPath
  2023. var refPath = schema.options.refPath;
  2024. if (refPath == null) {
  2025. return false;
  2026. }
  2027. var modelName = val.get(refPath);
  2028. return modelName === model.modelName || modelName === model.baseModelName;
  2029. }();
  2030. var didPopulate = false;
  2031. if (refMatches && val instanceof Document && (!val.$__.wasPopulated || utils.deepEqual(val.$__.wasPopulated.value, val._id))) {
  2032. var unpopulatedValue = schema && schema.$isSingleNested ? schema.cast(val, this) : val._id;
  2033. this.$populated(path, unpopulatedValue, _defineProperty({}, populateModelSymbol, val.constructor));
  2034. val.$__.wasPopulated = {
  2035. value: unpopulatedValue
  2036. };
  2037. didPopulate = true;
  2038. }
  2039. var popOpts;
  2040. var typeKey = this.$__schema.options.typeKey;
  2041. if (schema.options && Array.isArray(schema.options[typeKey]) && schema.options[typeKey].length && schema.options[typeKey][0].ref && _isManuallyPopulatedArray(val, schema.options[typeKey][0].ref)) {
  2042. popOpts = _defineProperty({}, populateModelSymbol, val[0].constructor);
  2043. this.$populated(path, val.map(function (v) {
  2044. return v._id;
  2045. }), popOpts);
  2046. var _iterator6 = _createForOfIteratorHelper(val),
  2047. _step6;
  2048. try {
  2049. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  2050. var doc = _step6.value;
  2051. doc.$__.wasPopulated = {
  2052. value: doc._id
  2053. };
  2054. }
  2055. } catch (err) {
  2056. _iterator6.e(err);
  2057. } finally {
  2058. _iterator6.f();
  2059. }
  2060. didPopulate = true;
  2061. }
  2062. if (this.$__schema.singleNestedPaths[path] == null && (!refMatches || !schema.$isSingleNested || !val.$__)) {
  2063. // If this path is underneath a single nested schema, we'll call the setter
  2064. // later in `$__set()` because we don't take `_doc` when we iterate through
  2065. // a single nested doc. That's to make sure we get the correct context.
  2066. // Otherwise we would double-call the setter, see gh-7196.
  2067. val = schema.applySetters(val, this, false, priorVal, options);
  2068. }
  2069. if (Array.isArray(val) && !Array.isArray(schema) && schema.$isMongooseDocumentArray && val.length !== 0 && val[0] != null && val[0].$__ != null && val[0].$__.populated != null) {
  2070. var populatedPaths = Object.keys(val[0].$__.populated);
  2071. var _loop = function _loop() {
  2072. var populatedPath = _populatedPaths[_i9];
  2073. _this3.$populated(path + '.' + populatedPath, val.map(function (v) {
  2074. return v.$populated(populatedPath);
  2075. }), val[0].$__.populated[populatedPath].options);
  2076. };
  2077. for (var _i9 = 0, _populatedPaths = populatedPaths; _i9 < _populatedPaths.length; _i9++) {
  2078. _loop();
  2079. }
  2080. didPopulate = true;
  2081. }
  2082. if (!didPopulate && this.$__.populated) {
  2083. // If this array partially contains populated documents, convert them
  2084. // all to ObjectIds re: #8443
  2085. if (Array.isArray(val) && this.$__.populated[path]) {
  2086. for (var _i10 = 0; _i10 < val.length; ++_i10) {
  2087. if (val[_i10] instanceof Document) {
  2088. val.set(_i10, val[_i10]._id, true);
  2089. }
  2090. }
  2091. }
  2092. delete this.$__.populated[path];
  2093. }
  2094. if (val != null && schema.$isSingleNested) {
  2095. _checkImmutableSubpaths(val, schema, priorVal);
  2096. }
  2097. this.$markValid(path);
  2098. } catch (e) {
  2099. if (e instanceof MongooseError.StrictModeError && e.isImmutableError) {
  2100. this.invalidate(path, e);
  2101. } else if (e instanceof MongooseError.CastError) {
  2102. this.invalidate(e.path, e);
  2103. if (e.$originalErrorPath) {
  2104. this.invalidate(path, new MongooseError.CastError(schema.instance, val, path, e.$originalErrorPath));
  2105. }
  2106. } else {
  2107. this.invalidate(path, new MongooseError.CastError(schema.instance, val, path, e));
  2108. }
  2109. shouldSet = false;
  2110. }
  2111. if (shouldSet) {
  2112. var savedState = null;
  2113. var savedStatePath = null;
  2114. if (!constructing) {
  2115. var _doc = this.$isSubdocument ? this.ownerDocument() : this;
  2116. savedState = _doc.$__.savedState;
  2117. savedStatePath = this.$isSubdocument ? this.$__.fullPath + '.' + path : path;
  2118. if (savedState != null) {
  2119. var firstDot = savedStatePath.indexOf('.');
  2120. var topLevelPath = firstDot === -1 ? savedStatePath : savedStatePath.slice(0, firstDot);
  2121. if (!savedState.hasOwnProperty(topLevelPath)) {
  2122. savedState[topLevelPath] = utils.clone(_doc.$__getValue(topLevelPath));
  2123. }
  2124. }
  2125. }
  2126. this.$__set(pathToMark, path, options, constructing, parts, schema, val, priorVal);
  2127. if (savedState != null && savedState.hasOwnProperty(savedStatePath) && utils.deepEqual(val, savedState[savedStatePath])) {
  2128. this.unmarkModified(path);
  2129. }
  2130. }
  2131. if (schema.$isSingleNested && (this.isDirectModified(path) || val == null)) {
  2132. cleanModifiedSubpaths(this, path);
  2133. }
  2134. return this;
  2135. };
  2136. /*!
  2137. * ignore
  2138. */
  2139. function _isManuallyPopulatedArray(val, ref) {
  2140. if (!Array.isArray(val)) {
  2141. return false;
  2142. }
  2143. if (val.length === 0) {
  2144. return false;
  2145. }
  2146. var _iterator7 = _createForOfIteratorHelper(val),
  2147. _step7;
  2148. try {
  2149. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  2150. var el = _step7.value;
  2151. if (!(el instanceof Document)) {
  2152. return false;
  2153. }
  2154. var modelName = el.constructor.modelName;
  2155. if (modelName == null) {
  2156. return false;
  2157. }
  2158. if (el.constructor.modelName != ref && el.constructor.baseModelName != ref) {
  2159. return false;
  2160. }
  2161. }
  2162. } catch (err) {
  2163. _iterator7.e(err);
  2164. } finally {
  2165. _iterator7.f();
  2166. }
  2167. return true;
  2168. }
  2169. /**
  2170. * Sets the value of a path, or many paths.
  2171. *
  2172. * #### Example:
  2173. *
  2174. * // path, value
  2175. * doc.set(path, value)
  2176. *
  2177. * // object
  2178. * doc.set({
  2179. * path : value
  2180. * , path2 : {
  2181. * path : value
  2182. * }
  2183. * })
  2184. *
  2185. * // on-the-fly cast to number
  2186. * doc.set(path, value, Number)
  2187. *
  2188. * // on-the-fly cast to string
  2189. * doc.set(path, value, String)
  2190. *
  2191. * // changing strict mode behavior
  2192. * doc.set(path, value, { strict: false });
  2193. *
  2194. * @param {String|Object} path path or object of key/vals to set
  2195. * @param {Any} val the value to set
  2196. * @param {Schema|String|Number|Buffer|*} [type] optionally specify a type for "on-the-fly" attributes
  2197. * @param {Object} [options] optionally specify options that modify the behavior of the set
  2198. * @api public
  2199. * @method set
  2200. * @memberOf Document
  2201. * @instance
  2202. */
  2203. Document.prototype.set = Document.prototype.$set;
  2204. /**
  2205. * Determine if we should mark this change as modified.
  2206. *
  2207. * @return {Boolean}
  2208. * @api private
  2209. * @method $__shouldModify
  2210. * @memberOf Document
  2211. * @instance
  2212. */
  2213. Document.prototype.$__shouldModify = function (pathToMark, path, options, constructing, parts, schema, val, priorVal) {
  2214. if (options && options._skipMarkModified) {
  2215. return false;
  2216. }
  2217. if (this.$isNew) {
  2218. return true;
  2219. } // Re: the note about gh-7196, `val` is the raw value without casting or
  2220. // setters if the full path is under a single nested subdoc because we don't
  2221. // want to double run setters. So don't set it as modified. See gh-7264.
  2222. if (this.$__schema.singleNestedPaths[path] != null) {
  2223. return false;
  2224. }
  2225. if (val === void 0 && !this.$__isSelected(path)) {
  2226. // when a path is not selected in a query, its initial
  2227. // value will be undefined.
  2228. return true;
  2229. }
  2230. if (val === void 0 && path in this.$__.activePaths.states["default"]) {
  2231. // we're just unsetting the default value which was never saved
  2232. return false;
  2233. } // gh-3992: if setting a populated field to a doc, don't mark modified
  2234. // if they have the same _id
  2235. if (this.$populated(path) && val instanceof Document && deepEqual(val._id, priorVal)) {
  2236. return false;
  2237. }
  2238. if (!deepEqual(val, priorVal || utils.getValue(path, this))) {
  2239. return true;
  2240. }
  2241. if (!constructing && val !== null && val !== undefined && path in this.$__.activePaths.states["default"] && deepEqual(val, schema.getDefault(this, constructing))) {
  2242. // a path with a default was $unset on the server
  2243. // and the user is setting it to the same value again
  2244. return true;
  2245. }
  2246. return false;
  2247. };
  2248. /**
  2249. * Handles the actual setting of the value and marking the path modified if appropriate.
  2250. *
  2251. * @api private
  2252. * @method $__set
  2253. * @memberOf Document
  2254. * @instance
  2255. */
  2256. Document.prototype.$__set = function (pathToMark, path, options, constructing, parts, schema, val, priorVal) {
  2257. Embedded = Embedded || __webpack_require__(1568);
  2258. var shouldModify = this.$__shouldModify(pathToMark, path, options, constructing, parts, schema, val, priorVal);
  2259. if (shouldModify) {
  2260. this.markModified(pathToMark); // handle directly setting arrays (gh-1126)
  2261. MongooseArray || (MongooseArray = __webpack_require__(1362));
  2262. if (val && utils.isMongooseArray(val)) {
  2263. val._registerAtomic('$set', val); // Update embedded document parent references (gh-5189)
  2264. if (utils.isMongooseDocumentArray(val)) {
  2265. val.forEach(function (item) {
  2266. item && item.__parentArray && (item.__parentArray = val);
  2267. });
  2268. }
  2269. }
  2270. } else if (Array.isArray(val) && Array.isArray(priorVal) && utils.isMongooseArray(val) && utils.isMongooseArray(priorVal)) {
  2271. val[arrayAtomicsSymbol] = priorVal[arrayAtomicsSymbol];
  2272. val[arrayAtomicsBackupSymbol] = priorVal[arrayAtomicsBackupSymbol];
  2273. if (utils.isMongooseDocumentArray(val)) {
  2274. val.forEach(function (doc) {
  2275. doc.isNew = false;
  2276. });
  2277. }
  2278. }
  2279. var obj = this._doc;
  2280. var i = 0;
  2281. var l = parts.length;
  2282. var cur = '';
  2283. for (; i < l; i++) {
  2284. var next = i + 1;
  2285. var last = next === l;
  2286. cur += cur ? '.' + parts[i] : parts[i];
  2287. if (specialProperties.has(parts[i])) {
  2288. return;
  2289. }
  2290. if (last) {
  2291. if (obj instanceof Map) {
  2292. obj.set(parts[i], val);
  2293. } else {
  2294. obj[parts[i]] = val;
  2295. }
  2296. } else {
  2297. if (utils.isPOJO(obj[parts[i]])) {
  2298. obj = obj[parts[i]];
  2299. } else if (obj[parts[i]] && obj[parts[i]] instanceof Embedded) {
  2300. obj = obj[parts[i]];
  2301. } else if (obj[parts[i]] && !Array.isArray(obj[parts[i]]) && obj[parts[i]].$isSingleNested) {
  2302. obj = obj[parts[i]];
  2303. } else if (obj[parts[i]] && Array.isArray(obj[parts[i]])) {
  2304. obj = obj[parts[i]];
  2305. } else {
  2306. obj[parts[i]] = obj[parts[i]] || {};
  2307. obj = obj[parts[i]];
  2308. }
  2309. }
  2310. }
  2311. };
  2312. /**
  2313. * Gets a raw value from a path (no getters)
  2314. *
  2315. * @param {String} path
  2316. * @api private
  2317. */
  2318. Document.prototype.$__getValue = function (path) {
  2319. return utils.getValue(path, this._doc);
  2320. };
  2321. /**
  2322. * Sets a raw value for a path (no casting, setters, transformations)
  2323. *
  2324. * @param {String} path
  2325. * @param {Object} value
  2326. * @api private
  2327. */
  2328. Document.prototype.$__setValue = function (path, val) {
  2329. utils.setValue(path, val, this._doc);
  2330. return this;
  2331. };
  2332. /**
  2333. * Returns the value of a path.
  2334. *
  2335. * #### Example
  2336. *
  2337. * // path
  2338. * doc.get('age') // 47
  2339. *
  2340. * // dynamic casting to a string
  2341. * doc.get('age', String) // "47"
  2342. *
  2343. * @param {String} path
  2344. * @param {Schema|String|Number|Buffer|*} [type] optionally specify a type for on-the-fly attributes
  2345. * @param {Object} [options]
  2346. * @param {Boolean} [options.virtuals=false] Apply virtuals before getting this path
  2347. * @param {Boolean} [options.getters=true] If false, skip applying getters and just get the raw value
  2348. * @api public
  2349. */
  2350. Document.prototype.get = function (path, type, options) {
  2351. var adhoc;
  2352. options = options || {};
  2353. if (type) {
  2354. adhoc = this.$__schema.interpretAsType(path, type, this.$__schema.options);
  2355. }
  2356. var schema = this.$__path(path);
  2357. if (schema == null) {
  2358. schema = this.$__schema.virtualpath(path);
  2359. }
  2360. if (schema instanceof MixedSchema) {
  2361. var virtual = this.$__schema.virtualpath(path);
  2362. if (virtual != null) {
  2363. schema = virtual;
  2364. }
  2365. }
  2366. var pieces = path.indexOf('.') === -1 ? [path] : path.split('.');
  2367. var obj = this._doc;
  2368. if (schema instanceof VirtualType) {
  2369. return schema.applyGetters(void 0, this);
  2370. } // Might need to change path for top-level alias
  2371. if (typeof this.$__schema.aliases[pieces[0]] === 'string') {
  2372. pieces[0] = this.$__schema.aliases[pieces[0]];
  2373. }
  2374. for (var _i11 = 0, l = pieces.length; _i11 < l; _i11++) {
  2375. if (obj && obj._doc) {
  2376. obj = obj._doc;
  2377. }
  2378. if (obj == null) {
  2379. obj = void 0;
  2380. } else if (obj instanceof Map) {
  2381. obj = obj.get(pieces[_i11], {
  2382. getters: false
  2383. });
  2384. } else if (_i11 === l - 1) {
  2385. obj = utils.getValue(pieces[_i11], obj);
  2386. } else {
  2387. obj = obj[pieces[_i11]];
  2388. }
  2389. }
  2390. if (adhoc) {
  2391. obj = adhoc.cast(obj);
  2392. }
  2393. if (schema != null && options.getters !== false) {
  2394. obj = schema.applyGetters(obj, this);
  2395. } else if (this.$__schema.nested[path] && options.virtuals) {
  2396. // Might need to apply virtuals if this is a nested path
  2397. return applyVirtuals(this, utils.clone(obj) || {}, {
  2398. path: path
  2399. });
  2400. }
  2401. return obj;
  2402. };
  2403. /*!
  2404. * ignore
  2405. */
  2406. Document.prototype[getSymbol] = Document.prototype.get;
  2407. Document.prototype.$get = Document.prototype.get;
  2408. /**
  2409. * Returns the schematype for the given `path`.
  2410. *
  2411. * @param {String} path
  2412. * @api private
  2413. * @method $__path
  2414. * @memberOf Document
  2415. * @instance
  2416. */
  2417. Document.prototype.$__path = function (path) {
  2418. var adhocs = this.$__.adhocPaths;
  2419. var adhocType = adhocs && adhocs.hasOwnProperty(path) ? adhocs[path] : null;
  2420. if (adhocType) {
  2421. return adhocType;
  2422. }
  2423. return this.$__schema.path(path);
  2424. };
  2425. /**
  2426. * Marks the path as having pending changes to write to the db.
  2427. *
  2428. * _Very helpful when using [Mixed](https://mongoosejs.com/docs/schematypes.html#mixed) types._
  2429. *
  2430. * #### Example:
  2431. *
  2432. * doc.mixed.type = 'changed';
  2433. * doc.markModified('mixed.type');
  2434. * doc.save() // changes to mixed.type are now persisted
  2435. *
  2436. * @param {String} path the path to mark modified
  2437. * @param {Document} [scope] the scope to run validators with
  2438. * @api public
  2439. */
  2440. Document.prototype.markModified = function (path, scope) {
  2441. this.$__.activePaths.modify(path);
  2442. if (scope != null && !this.$isSubdocument) {
  2443. this.$__.pathsToScopes = this.$__pathsToScopes || {};
  2444. this.$__.pathsToScopes[path] = scope;
  2445. }
  2446. };
  2447. /**
  2448. * Clears the modified state on the specified path.
  2449. *
  2450. * #### Example:
  2451. *
  2452. * doc.foo = 'bar';
  2453. * doc.unmarkModified('foo');
  2454. * doc.save(); // changes to foo will not be persisted
  2455. *
  2456. * @param {String} path the path to unmark modified
  2457. * @api public
  2458. */
  2459. Document.prototype.unmarkModified = function (path) {
  2460. this.$__.activePaths.init(path);
  2461. if (this.$__.pathsToScopes != null) {
  2462. delete this.$__.pathsToScopes[path];
  2463. }
  2464. };
  2465. /**
  2466. * Don't run validation on this path or persist changes to this path.
  2467. *
  2468. * #### Example:
  2469. *
  2470. * doc.foo = null;
  2471. * doc.$ignore('foo');
  2472. * doc.save(); // changes to foo will not be persisted and validators won't be run
  2473. *
  2474. * @memberOf Document
  2475. * @instance
  2476. * @method $ignore
  2477. * @param {String} path the path to ignore
  2478. * @api public
  2479. */
  2480. Document.prototype.$ignore = function (path) {
  2481. this.$__.activePaths.ignore(path);
  2482. };
  2483. /**
  2484. * Returns the list of paths that have been directly modified. A direct
  2485. * modified path is a path that you explicitly set, whether via `doc.foo = 'bar'`,
  2486. * `Object.assign(doc, { foo: 'bar' })`, or `doc.set('foo', 'bar')`.
  2487. *
  2488. * A path `a` may be in `modifiedPaths()` but not in `directModifiedPaths()`
  2489. * because a child of `a` was directly modified.
  2490. *
  2491. * #### Example
  2492. * const schema = new Schema({ foo: String, nested: { bar: String } });
  2493. * const Model = mongoose.model('Test', schema);
  2494. * await Model.create({ foo: 'original', nested: { bar: 'original' } });
  2495. *
  2496. * const doc = await Model.findOne();
  2497. * doc.nested.bar = 'modified';
  2498. * doc.directModifiedPaths(); // ['nested.bar']
  2499. * doc.modifiedPaths(); // ['nested', 'nested.bar']
  2500. *
  2501. * @return {Array}
  2502. * @api public
  2503. */
  2504. Document.prototype.directModifiedPaths = function () {
  2505. return Object.keys(this.$__.activePaths.states.modify);
  2506. };
  2507. /**
  2508. * Returns true if the given path is nullish or only contains empty objects.
  2509. * Useful for determining whether this subdoc will get stripped out by the
  2510. * [minimize option](/docs/guide.html#minimize).
  2511. *
  2512. * #### Example:
  2513. * const schema = new Schema({ nested: { foo: String } });
  2514. * const Model = mongoose.model('Test', schema);
  2515. * const doc = new Model({});
  2516. * doc.$isEmpty('nested'); // true
  2517. * doc.nested.$isEmpty(); // true
  2518. *
  2519. * doc.nested.foo = 'bar';
  2520. * doc.$isEmpty('nested'); // false
  2521. * doc.nested.$isEmpty(); // false
  2522. *
  2523. * @memberOf Document
  2524. * @instance
  2525. * @api public
  2526. * @method $isEmpty
  2527. * @return {Boolean}
  2528. */
  2529. Document.prototype.$isEmpty = function (path) {
  2530. var isEmptyOptions = {
  2531. minimize: true,
  2532. virtuals: false,
  2533. getters: false,
  2534. transform: false
  2535. };
  2536. if (arguments.length !== 0) {
  2537. var v = this.$get(path);
  2538. if (v == null) {
  2539. return true;
  2540. }
  2541. if (_typeof(v) !== 'object') {
  2542. return false;
  2543. }
  2544. if (utils.isPOJO(v)) {
  2545. return _isEmpty(v);
  2546. }
  2547. return Object.keys(v.toObject(isEmptyOptions)).length === 0;
  2548. }
  2549. return Object.keys(this.toObject(isEmptyOptions)).length === 0;
  2550. };
  2551. function _isEmpty(v) {
  2552. if (v == null) {
  2553. return true;
  2554. }
  2555. if (_typeof(v) !== 'object' || Array.isArray(v)) {
  2556. return false;
  2557. }
  2558. for (var _i12 = 0, _Object$keys = Object.keys(v); _i12 < _Object$keys.length; _i12++) {
  2559. var key = _Object$keys[_i12];
  2560. if (!_isEmpty(v[key])) {
  2561. return false;
  2562. }
  2563. }
  2564. return true;
  2565. }
  2566. /**
  2567. * Returns the list of paths that have been modified.
  2568. *
  2569. * @param {Object} [options]
  2570. * @param {Boolean} [options.includeChildren=false] if true, returns children of modified paths as well. For example, if false, the list of modified paths for `doc.colors = { primary: 'blue' };` will **not** contain `colors.primary`. If true, `modifiedPaths()` will return an array that contains `colors.primary`.
  2571. * @return {Array}
  2572. * @api public
  2573. */
  2574. Document.prototype.modifiedPaths = function (options) {
  2575. options = options || {};
  2576. var directModifiedPaths = Object.keys(this.$__.activePaths.states.modify);
  2577. var result = new Set();
  2578. var i = 0;
  2579. var j = 0;
  2580. var len = directModifiedPaths.length;
  2581. for (i = 0; i < len; ++i) {
  2582. var path = directModifiedPaths[i];
  2583. var parts = parentPaths(path);
  2584. var pLen = parts.length;
  2585. for (j = 0; j < pLen; ++j) {
  2586. result.add(parts[j]);
  2587. }
  2588. if (!options.includeChildren) {
  2589. continue;
  2590. }
  2591. var ii = 0;
  2592. var cur = this.$get(path);
  2593. if (_typeof(cur) === 'object' && cur !== null) {
  2594. if (cur._doc) {
  2595. cur = cur._doc;
  2596. }
  2597. var _len3 = cur.length;
  2598. if (Array.isArray(cur)) {
  2599. for (ii = 0; ii < _len3; ++ii) {
  2600. var subPath = path + '.' + ii;
  2601. if (!result.has(subPath)) {
  2602. result.add(subPath);
  2603. if (cur[ii] != null && cur[ii].$__) {
  2604. var modified = cur[ii].modifiedPaths();
  2605. var iii = 0;
  2606. var iiiLen = modified.length;
  2607. for (iii = 0; iii < iiiLen; ++iii) {
  2608. result.add(subPath + '.' + modified[iii]);
  2609. }
  2610. }
  2611. }
  2612. }
  2613. } else {
  2614. var keys = Object.keys(cur);
  2615. var _ii = 0;
  2616. var _len4 = keys.length;
  2617. for (_ii = 0; _ii < _len4; ++_ii) {
  2618. result.add(path + '.' + keys[_ii]);
  2619. }
  2620. }
  2621. }
  2622. }
  2623. return Array.from(result);
  2624. };
  2625. Document.prototype[documentModifiedPaths] = Document.prototype.modifiedPaths;
  2626. /**
  2627. * Returns true if any of the given paths is modified, else false. If no arguments, returns `true` if any path
  2628. * in this document is modified.
  2629. *
  2630. * If `path` is given, checks if a path or any full path containing `path` as part of its path chain has been modified.
  2631. *
  2632. * #### Example
  2633. *
  2634. * doc.set('documents.0.title', 'changed');
  2635. * doc.isModified() // true
  2636. * doc.isModified('documents') // true
  2637. * doc.isModified('documents.0.title') // true
  2638. * doc.isModified('documents otherProp') // true
  2639. * doc.isDirectModified('documents') // false
  2640. *
  2641. * @param {String} [path] optional
  2642. * @return {Boolean}
  2643. * @api public
  2644. */
  2645. Document.prototype.isModified = function (paths, modifiedPaths) {
  2646. if (paths) {
  2647. var directModifiedPaths = Object.keys(this.$__.activePaths.states.modify);
  2648. if (directModifiedPaths.length === 0) {
  2649. return false;
  2650. }
  2651. if (!Array.isArray(paths)) {
  2652. paths = paths.indexOf(' ') === -1 ? [paths] : paths.split(' ');
  2653. }
  2654. var modified = modifiedPaths || this[documentModifiedPaths]();
  2655. var isModifiedChild = paths.some(function (path) {
  2656. return !!~modified.indexOf(path);
  2657. });
  2658. return isModifiedChild || paths.some(function (path) {
  2659. return directModifiedPaths.some(function (mod) {
  2660. return mod === path || path.startsWith(mod + '.');
  2661. });
  2662. });
  2663. }
  2664. return this.$__.activePaths.some('modify');
  2665. };
  2666. Document.prototype.$isModified = Document.prototype.isModified;
  2667. Document.prototype[documentIsModified] = Document.prototype.isModified;
  2668. /**
  2669. * Checks if a path is set to its default.
  2670. *
  2671. * #### Example
  2672. *
  2673. * MyModel = mongoose.model('test', { name: { type: String, default: 'Val '} });
  2674. * const m = new MyModel();
  2675. * m.$isDefault('name'); // true
  2676. *
  2677. * @memberOf Document
  2678. * @instance
  2679. * @method $isDefault
  2680. * @param {String} [path]
  2681. * @return {Boolean}
  2682. * @api public
  2683. */
  2684. Document.prototype.$isDefault = function (path) {
  2685. var _this4 = this;
  2686. if (path == null) {
  2687. return this.$__.activePaths.some('default');
  2688. }
  2689. if (typeof path === 'string' && path.indexOf(' ') === -1) {
  2690. return this.$__.activePaths.states["default"].hasOwnProperty(path);
  2691. }
  2692. var paths = path;
  2693. if (!Array.isArray(paths)) {
  2694. paths = paths.split(' ');
  2695. }
  2696. return paths.some(function (path) {
  2697. return _this4.$__.activePaths.states["default"].hasOwnProperty(path);
  2698. });
  2699. };
  2700. /**
  2701. * Getter/setter, determines whether the document was removed or not.
  2702. *
  2703. * #### Example:
  2704. * const product = await product.remove();
  2705. * product.$isDeleted(); // true
  2706. * product.remove(); // no-op, doesn't send anything to the db
  2707. *
  2708. * product.$isDeleted(false);
  2709. * product.$isDeleted(); // false
  2710. * product.remove(); // will execute a remove against the db
  2711. *
  2712. *
  2713. * @param {Boolean} [val] optional, overrides whether mongoose thinks the doc is deleted
  2714. * @return {Boolean} whether mongoose thinks this doc is deleted.
  2715. * @method $isDeleted
  2716. * @memberOf Document
  2717. * @instance
  2718. * @api public
  2719. */
  2720. Document.prototype.$isDeleted = function (val) {
  2721. if (arguments.length === 0) {
  2722. return !!this.$__.isDeleted;
  2723. }
  2724. this.$__.isDeleted = !!val;
  2725. return this;
  2726. };
  2727. /**
  2728. * Returns true if `path` was directly set and modified, else false.
  2729. *
  2730. * #### Example
  2731. *
  2732. * doc.set('documents.0.title', 'changed');
  2733. * doc.isDirectModified('documents.0.title') // true
  2734. * doc.isDirectModified('documents') // false
  2735. *
  2736. * @param {String|Array<String>} path
  2737. * @return {Boolean}
  2738. * @api public
  2739. */
  2740. Document.prototype.isDirectModified = function (path) {
  2741. var _this5 = this;
  2742. if (path == null) {
  2743. return this.$__.activePaths.some('modify');
  2744. }
  2745. if (typeof path === 'string' && path.indexOf(' ') === -1) {
  2746. return this.$__.activePaths.states.modify.hasOwnProperty(path);
  2747. }
  2748. var paths = path;
  2749. if (!Array.isArray(paths)) {
  2750. paths = paths.split(' ');
  2751. }
  2752. return paths.some(function (path) {
  2753. return _this5.$__.activePaths.states.modify.hasOwnProperty(path);
  2754. });
  2755. };
  2756. /**
  2757. * Checks if `path` is in the `init` state, that is, it was set by `Document#init()` and not modified since.
  2758. *
  2759. * @param {String} path
  2760. * @return {Boolean}
  2761. * @api public
  2762. */
  2763. Document.prototype.isInit = function (path) {
  2764. var _this6 = this;
  2765. if (path == null) {
  2766. return this.$__.activePaths.some('init');
  2767. }
  2768. if (typeof path === 'string' && path.indexOf(' ') === -1) {
  2769. return this.$__.activePaths.states.init.hasOwnProperty(path);
  2770. }
  2771. var paths = path;
  2772. if (!Array.isArray(paths)) {
  2773. paths = paths.split(' ');
  2774. }
  2775. return paths.some(function (path) {
  2776. return _this6.$__.activePaths.states.init.hasOwnProperty(path);
  2777. });
  2778. };
  2779. /**
  2780. * Checks if `path` was selected in the source query which initialized this document.
  2781. *
  2782. * #### Example
  2783. *
  2784. * const doc = await Thing.findOne().select('name');
  2785. * doc.isSelected('name') // true
  2786. * doc.isSelected('age') // false
  2787. *
  2788. * @param {String|Array<String>} path
  2789. * @return {Boolean}
  2790. * @api public
  2791. */
  2792. Document.prototype.isSelected = function isSelected(path) {
  2793. var _this7 = this;
  2794. if (this.$__.selected == null) {
  2795. return true;
  2796. }
  2797. if (!path) {
  2798. return false;
  2799. }
  2800. if (path === '_id') {
  2801. return this.$__.selected._id !== 0;
  2802. }
  2803. if (path.indexOf(' ') !== -1) {
  2804. path = path.split(' ');
  2805. }
  2806. if (Array.isArray(path)) {
  2807. return path.some(function (p) {
  2808. return _this7.$__isSelected(p);
  2809. });
  2810. }
  2811. var paths = Object.keys(this.$__.selected);
  2812. var inclusive = null;
  2813. if (paths.length === 1 && paths[0] === '_id') {
  2814. // only _id was selected.
  2815. return this.$__.selected._id === 0;
  2816. }
  2817. for (var _i13 = 0, _paths = paths; _i13 < _paths.length; _i13++) {
  2818. var cur = _paths[_i13];
  2819. if (cur === '_id') {
  2820. continue;
  2821. }
  2822. if (!isDefiningProjection(this.$__.selected[cur])) {
  2823. continue;
  2824. }
  2825. inclusive = !!this.$__.selected[cur];
  2826. break;
  2827. }
  2828. if (inclusive === null) {
  2829. return true;
  2830. }
  2831. if (path in this.$__.selected) {
  2832. return inclusive;
  2833. }
  2834. var pathDot = path + '.';
  2835. for (var _i14 = 0, _paths2 = paths; _i14 < _paths2.length; _i14++) {
  2836. var _cur = _paths2[_i14];
  2837. if (_cur === '_id') {
  2838. continue;
  2839. }
  2840. if (_cur.startsWith(pathDot)) {
  2841. return inclusive || _cur !== pathDot;
  2842. }
  2843. if (pathDot.startsWith(_cur + '.')) {
  2844. return inclusive;
  2845. }
  2846. }
  2847. return !inclusive;
  2848. };
  2849. Document.prototype.$__isSelected = Document.prototype.isSelected;
  2850. /**
  2851. * Checks if `path` was explicitly selected. If no projection, always returns
  2852. * true.
  2853. *
  2854. * #### Example
  2855. *
  2856. * Thing.findOne().select('nested.name').exec(function (err, doc) {
  2857. * doc.isDirectSelected('nested.name') // true
  2858. * doc.isDirectSelected('nested.otherName') // false
  2859. * doc.isDirectSelected('nested') // false
  2860. * })
  2861. *
  2862. * @param {String} path
  2863. * @return {Boolean}
  2864. * @api public
  2865. */
  2866. Document.prototype.isDirectSelected = function isDirectSelected(path) {
  2867. var _this8 = this;
  2868. if (this.$__.selected == null) {
  2869. return true;
  2870. }
  2871. if (path === '_id') {
  2872. return this.$__.selected._id !== 0;
  2873. }
  2874. if (path.indexOf(' ') !== -1) {
  2875. path = path.split(' ');
  2876. }
  2877. if (Array.isArray(path)) {
  2878. return path.some(function (p) {
  2879. return _this8.isDirectSelected(p);
  2880. });
  2881. }
  2882. var paths = Object.keys(this.$__.selected);
  2883. var inclusive = null;
  2884. if (paths.length === 1 && paths[0] === '_id') {
  2885. // only _id was selected.
  2886. return this.$__.selected._id === 0;
  2887. }
  2888. for (var _i15 = 0, _paths3 = paths; _i15 < _paths3.length; _i15++) {
  2889. var cur = _paths3[_i15];
  2890. if (cur === '_id') {
  2891. continue;
  2892. }
  2893. if (!isDefiningProjection(this.$__.selected[cur])) {
  2894. continue;
  2895. }
  2896. inclusive = !!this.$__.selected[cur];
  2897. break;
  2898. }
  2899. if (inclusive === null) {
  2900. return true;
  2901. }
  2902. if (this.$__.selected.hasOwnProperty(path)) {
  2903. return inclusive;
  2904. }
  2905. return !inclusive;
  2906. };
  2907. /**
  2908. * Executes registered validation rules for this document.
  2909. *
  2910. * #### Note:
  2911. *
  2912. * This method is called `pre` save and if a validation rule is violated, [save](#model_Model-save) is aborted and the error is returned to your `callback`.
  2913. *
  2914. * #### Example:
  2915. *
  2916. * doc.validate(function (err) {
  2917. * if (err) handleError(err);
  2918. * else // validation passed
  2919. * });
  2920. *
  2921. * @param {Array|String} [pathsToValidate] list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list.
  2922. * @param {Object} [options] internal options
  2923. * @param {Boolean} [options.validateModifiedOnly=false] if `true` mongoose validates only modified paths.
  2924. * @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
  2925. * @param {Function} [callback] optional callback called after validation completes, passing an error if one occurred
  2926. * @return {Promise} Promise
  2927. * @api public
  2928. */
  2929. Document.prototype.validate = function (pathsToValidate, options, callback) {
  2930. var _this9 = this;
  2931. var parallelValidate;
  2932. this.$op = 'validate';
  2933. if (this.$isSubdocument != null) {// Skip parallel validate check for subdocuments
  2934. } else if (this.$__.validating) {
  2935. parallelValidate = new ParallelValidateError(this, {
  2936. parentStack: options && options.parentStack,
  2937. conflictStack: this.$__.validating.stack
  2938. });
  2939. } else {
  2940. this.$__.validating = new ParallelValidateError(this, {
  2941. parentStack: options && options.parentStack
  2942. });
  2943. }
  2944. if (arguments.length === 1) {
  2945. if (_typeof(arguments[0]) === 'object' && !Array.isArray(arguments[0])) {
  2946. options = arguments[0];
  2947. callback = null;
  2948. pathsToValidate = null;
  2949. } else if (typeof arguments[0] === 'function') {
  2950. callback = arguments[0];
  2951. options = null;
  2952. pathsToValidate = null;
  2953. }
  2954. } else if (typeof pathsToValidate === 'function') {
  2955. callback = pathsToValidate;
  2956. options = null;
  2957. pathsToValidate = null;
  2958. } else if (typeof options === 'function') {
  2959. callback = options;
  2960. options = pathsToValidate;
  2961. pathsToValidate = null;
  2962. }
  2963. if (options && typeof options.pathsToSkip === 'string') {
  2964. var isOnePathOnly = options.pathsToSkip.indexOf(' ') === -1;
  2965. options.pathsToSkip = isOnePathOnly ? [options.pathsToSkip] : options.pathsToSkip.split(' ');
  2966. }
  2967. return promiseOrCallback(callback, function (cb) {
  2968. if (parallelValidate != null) {
  2969. return cb(parallelValidate);
  2970. }
  2971. _this9.$__validate(pathsToValidate, options, function (error) {
  2972. _this9.$op = null;
  2973. _this9.$__.validating = null;
  2974. cb(error);
  2975. });
  2976. }, this.constructor.events);
  2977. };
  2978. Document.prototype.$validate = Document.prototype.validate;
  2979. /*!
  2980. * ignore
  2981. */
  2982. function _evaluateRequiredFunctions(doc) {
  2983. var requiredFields = Object.keys(doc.$__.activePaths.states.require);
  2984. var i = 0;
  2985. var len = requiredFields.length;
  2986. for (i = 0; i < len; ++i) {
  2987. var path = requiredFields[i];
  2988. var p = doc.$__schema.path(path);
  2989. if (p != null && typeof p.originalRequiredValue === 'function') {
  2990. doc.$__.cachedRequired = doc.$__.cachedRequired || {};
  2991. try {
  2992. doc.$__.cachedRequired[path] = p.originalRequiredValue.call(doc, doc);
  2993. } catch (err) {
  2994. doc.invalidate(path, err);
  2995. }
  2996. }
  2997. }
  2998. }
  2999. /*!
  3000. * ignore
  3001. */
  3002. function _getPathsToValidate(doc) {
  3003. var skipSchemaValidators = {};
  3004. _evaluateRequiredFunctions(doc); // only validate required fields when necessary
  3005. var paths = new Set(Object.keys(doc.$__.activePaths.states.require).filter(function (path) {
  3006. if (!doc.$__isSelected(path) && !doc.$isModified(path)) {
  3007. return false;
  3008. }
  3009. if (doc.$__.cachedRequired != null && path in doc.$__.cachedRequired) {
  3010. return doc.$__.cachedRequired[path];
  3011. }
  3012. return true;
  3013. }));
  3014. Object.keys(doc.$__.activePaths.states.init).forEach(addToPaths);
  3015. Object.keys(doc.$__.activePaths.states.modify).forEach(addToPaths);
  3016. Object.keys(doc.$__.activePaths.states["default"]).forEach(addToPaths);
  3017. function addToPaths(p) {
  3018. paths.add(p);
  3019. }
  3020. var subdocs = doc.$getAllSubdocs();
  3021. var modifiedPaths = doc.modifiedPaths();
  3022. var _iterator8 = _createForOfIteratorHelper(subdocs),
  3023. _step8;
  3024. try {
  3025. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  3026. var subdoc = _step8.value;
  3027. if (subdoc.$basePath) {
  3028. // Remove child paths for now, because we'll be validating the whole
  3029. // subdoc
  3030. var fullPathToSubdoc = subdoc.$__fullPathWithIndexes();
  3031. var _iterator13 = _createForOfIteratorHelper(paths),
  3032. _step13;
  3033. try {
  3034. for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
  3035. var p = _step13.value;
  3036. if (p == null || p.startsWith(fullPathToSubdoc + '.')) {
  3037. paths["delete"](p);
  3038. }
  3039. }
  3040. } catch (err) {
  3041. _iterator13.e(err);
  3042. } finally {
  3043. _iterator13.f();
  3044. }
  3045. if (doc.$isModified(fullPathToSubdoc, modifiedPaths) && !doc.isDirectModified(fullPathToSubdoc) && !doc.$isDefault(fullPathToSubdoc)) {
  3046. paths.add(fullPathToSubdoc);
  3047. skipSchemaValidators[fullPathToSubdoc] = true;
  3048. }
  3049. }
  3050. }
  3051. } catch (err) {
  3052. _iterator8.e(err);
  3053. } finally {
  3054. _iterator8.f();
  3055. }
  3056. var _iterator9 = _createForOfIteratorHelper(paths),
  3057. _step9;
  3058. try {
  3059. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  3060. var path = _step9.value;
  3061. var _pathType = doc.$__schema.path(path);
  3062. if (!_pathType) {
  3063. continue;
  3064. }
  3065. if (_pathType.$isMongooseDocumentArray) {
  3066. var _iterator14 = _createForOfIteratorHelper(paths),
  3067. _step14;
  3068. try {
  3069. for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
  3070. var _p = _step14.value;
  3071. if (_p == null || _p.startsWith(_pathType.path + '.')) {
  3072. paths["delete"](_p);
  3073. }
  3074. }
  3075. } catch (err) {
  3076. _iterator14.e(err);
  3077. } finally {
  3078. _iterator14.f();
  3079. }
  3080. } // Optimization: if primitive path with no validators, or array of primitives
  3081. // with no validators, skip validating this path entirely.
  3082. if (!_pathType.caster && _pathType.validators.length === 0) {
  3083. paths["delete"](path);
  3084. } else if (_pathType.$isMongooseArray && !_pathType.$isMongooseDocumentArray && // Skip document arrays...
  3085. !_pathType.$embeddedSchemaType.$isMongooseArray && // and arrays of arrays
  3086. _pathType.validators.length === 0 && // and arrays with top-level validators
  3087. _pathType.$embeddedSchemaType.validators.length === 0) {
  3088. paths["delete"](path);
  3089. }
  3090. } // from here on we're not removing items from paths
  3091. // gh-661: if a whole array is modified, make sure to run validation on all
  3092. // the children as well
  3093. } catch (err) {
  3094. _iterator9.e(err);
  3095. } finally {
  3096. _iterator9.f();
  3097. }
  3098. var _iterator10 = _createForOfIteratorHelper(paths),
  3099. _step10;
  3100. try {
  3101. for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
  3102. var _path2 = _step10.value;
  3103. var _pathType2 = doc.$__schema.path(_path2);
  3104. if (!_pathType2) {
  3105. continue;
  3106. }
  3107. if (!_pathType2.$isMongooseArray || // To avoid potential performance issues, skip doc arrays whose children
  3108. // are not required. `getPositionalPathType()` may be slow, so avoid
  3109. // it unless we have a case of #6364
  3110. !Array.isArray(_pathType2) && _pathType2.$isMongooseDocumentArray && !(_pathType2 && _pathType2.schemaOptions && _pathType2.schemaOptions.required)) {
  3111. continue;
  3112. } // gh-11380: optimization. If the array isn't a document array and there's no validators
  3113. // on the array type, there's no need to run validation on the individual array elements.
  3114. if (_pathType2.$isMongooseArray && !_pathType2.$isMongooseDocumentArray && // Skip document arrays...
  3115. !_pathType2.$embeddedSchemaType.$isMongooseArray && // and arrays of arrays
  3116. _pathType2.$embeddedSchemaType.validators.length === 0) {
  3117. continue;
  3118. }
  3119. var val = doc.$__getValue(_path2);
  3120. _pushNestedArrayPaths(val, paths, _path2);
  3121. }
  3122. } catch (err) {
  3123. _iterator10.e(err);
  3124. } finally {
  3125. _iterator10.f();
  3126. }
  3127. function _pushNestedArrayPaths(val, paths, path) {
  3128. if (val != null) {
  3129. var numElements = val.length;
  3130. for (var j = 0; j < numElements; ++j) {
  3131. if (Array.isArray(val[j])) {
  3132. _pushNestedArrayPaths(val[j], paths, path + '.' + j);
  3133. } else {
  3134. paths.add(path + '.' + j);
  3135. }
  3136. }
  3137. }
  3138. }
  3139. var flattenOptions = {
  3140. skipArrays: true
  3141. };
  3142. var _iterator11 = _createForOfIteratorHelper(paths),
  3143. _step11;
  3144. try {
  3145. for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
  3146. var pathToCheck = _step11.value;
  3147. if (doc.$__schema.nested[pathToCheck]) {
  3148. var _v = doc.$__getValue(pathToCheck);
  3149. if (isMongooseObject(_v)) {
  3150. _v = _v.toObject({
  3151. transform: false
  3152. });
  3153. }
  3154. var flat = flatten(_v, pathToCheck, flattenOptions, doc.$__schema);
  3155. Object.keys(flat).forEach(addToPaths);
  3156. }
  3157. }
  3158. } catch (err) {
  3159. _iterator11.e(err);
  3160. } finally {
  3161. _iterator11.f();
  3162. }
  3163. var _iterator12 = _createForOfIteratorHelper(paths),
  3164. _step12;
  3165. try {
  3166. for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
  3167. var _path3 = _step12.value;
  3168. // Single nested paths (paths embedded under single nested subdocs) will
  3169. // be validated on their own when we call `validate()` on the subdoc itself.
  3170. // Re: gh-8468
  3171. if (doc.$__schema.singleNestedPaths.hasOwnProperty(_path3)) {
  3172. paths["delete"](_path3);
  3173. continue;
  3174. }
  3175. var _pathType3 = doc.$__schema.path(_path3);
  3176. if (!_pathType3 || !_pathType3.$isSchemaMap) {
  3177. continue;
  3178. }
  3179. var _val = doc.$__getValue(_path3);
  3180. if (_val == null) {
  3181. continue;
  3182. }
  3183. var _iterator15 = _createForOfIteratorHelper(_val.keys()),
  3184. _step15;
  3185. try {
  3186. for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
  3187. var key = _step15.value;
  3188. paths.add(_path3 + '.' + key);
  3189. }
  3190. } catch (err) {
  3191. _iterator15.e(err);
  3192. } finally {
  3193. _iterator15.f();
  3194. }
  3195. }
  3196. } catch (err) {
  3197. _iterator12.e(err);
  3198. } finally {
  3199. _iterator12.f();
  3200. }
  3201. paths = Array.from(paths);
  3202. return [paths, skipSchemaValidators];
  3203. }
  3204. /*!
  3205. * ignore
  3206. */
  3207. Document.prototype.$__validate = function (pathsToValidate, options, callback) {
  3208. var _this10 = this;
  3209. if (typeof pathsToValidate === 'function') {
  3210. callback = pathsToValidate;
  3211. options = null;
  3212. pathsToValidate = null;
  3213. } else if (typeof options === 'function') {
  3214. callback = options;
  3215. options = null;
  3216. }
  3217. var hasValidateModifiedOnlyOption = options && _typeof(options) === 'object' && 'validateModifiedOnly' in options;
  3218. var pathsToSkip = options && options.pathsToSkip || null;
  3219. var shouldValidateModifiedOnly;
  3220. if (hasValidateModifiedOnlyOption) {
  3221. shouldValidateModifiedOnly = !!options.validateModifiedOnly;
  3222. } else {
  3223. shouldValidateModifiedOnly = this.$__schema.options.validateModifiedOnly;
  3224. }
  3225. var _this = this;
  3226. var _complete = function _complete() {
  3227. var validationError = _this10.$__.validationError;
  3228. _this10.$__.validationError = null;
  3229. _this10.$__.validating = null;
  3230. if (shouldValidateModifiedOnly && validationError != null) {
  3231. // Remove any validation errors that aren't from modified paths
  3232. var errors = Object.keys(validationError.errors);
  3233. for (var _i16 = 0, _errors = errors; _i16 < _errors.length; _i16++) {
  3234. var errPath = _errors[_i16];
  3235. if (!_this10.$isModified(errPath)) {
  3236. delete validationError.errors[errPath];
  3237. }
  3238. }
  3239. if (Object.keys(validationError.errors).length === 0) {
  3240. validationError = void 0;
  3241. }
  3242. }
  3243. _this10.$__.cachedRequired = {};
  3244. _this10.$emit('validate', _this);
  3245. _this10.constructor.emit('validate', _this);
  3246. if (validationError) {
  3247. for (var key in validationError.errors) {
  3248. // Make sure cast errors persist
  3249. if (!_this10[documentArrayParent] && validationError.errors[key] instanceof MongooseError.CastError) {
  3250. _this10.invalidate(key, validationError.errors[key]);
  3251. }
  3252. }
  3253. return validationError;
  3254. }
  3255. }; // only validate required fields when necessary
  3256. var pathDetails = _getPathsToValidate(this);
  3257. var paths = shouldValidateModifiedOnly ? pathDetails[0].filter(function (path) {
  3258. return _this10.$isModified(path);
  3259. }) : pathDetails[0];
  3260. var skipSchemaValidators = pathDetails[1];
  3261. if (typeof pathsToValidate === 'string') {
  3262. pathsToValidate = pathsToValidate.split(' ');
  3263. }
  3264. if (Array.isArray(pathsToValidate)) {
  3265. paths = _handlePathsToValidate(paths, pathsToValidate);
  3266. } else if (pathsToSkip) {
  3267. paths = _handlePathsToSkip(paths, pathsToSkip);
  3268. }
  3269. if (paths.length === 0) {
  3270. return immediate(function () {
  3271. var error = _complete();
  3272. if (error) {
  3273. return _this.$__schema.s.hooks.execPost('validate:error', _this, [_this], {
  3274. error: error
  3275. }, function (error) {
  3276. callback(error);
  3277. });
  3278. }
  3279. callback(null, _this);
  3280. });
  3281. }
  3282. var validated = {};
  3283. var total = 0;
  3284. var _iterator16 = _createForOfIteratorHelper(paths),
  3285. _step16;
  3286. try {
  3287. for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
  3288. var path = _step16.value;
  3289. validatePath(path);
  3290. }
  3291. } catch (err) {
  3292. _iterator16.e(err);
  3293. } finally {
  3294. _iterator16.f();
  3295. }
  3296. function validatePath(path) {
  3297. if (path == null || validated[path]) {
  3298. return;
  3299. }
  3300. validated[path] = true;
  3301. total++;
  3302. immediate(function () {
  3303. var schemaType = _this.$__schema.path(path);
  3304. if (!schemaType) {
  3305. return --total || complete();
  3306. } // If user marked as invalid or there was a cast error, don't validate
  3307. if (!_this.$isValid(path)) {
  3308. --total || complete();
  3309. return;
  3310. } // If setting a path under a mixed path, avoid using the mixed path validator (gh-10141)
  3311. if (schemaType[schemaMixedSymbol] != null && path !== schemaType.path) {
  3312. return --total || complete();
  3313. }
  3314. var val = _this.$__getValue(path); // If you `populate()` and get back a null value, required validators
  3315. // shouldn't fail (gh-8018). We should always fall back to the populated
  3316. // value.
  3317. var pop;
  3318. if (pop = _this.$populated(path)) {
  3319. val = pop;
  3320. } else if (val != null && val.$__ != null && val.$__.wasPopulated) {
  3321. // Array paths, like `somearray.1`, do not show up as populated with `$populated()`,
  3322. // so in that case pull out the document's id
  3323. val = val._id;
  3324. }
  3325. var scope = _this.$__.pathsToScopes != null && path in _this.$__.pathsToScopes ? _this.$__.pathsToScopes[path] : _this;
  3326. var doValidateOptions = {
  3327. skipSchemaValidators: skipSchemaValidators[path],
  3328. path: path,
  3329. validateModifiedOnly: shouldValidateModifiedOnly
  3330. };
  3331. schemaType.doValidate(val, function (err) {
  3332. if (err) {
  3333. var isSubdoc = schemaType.$isSingleNested || schemaType.$isArraySubdocument || schemaType.$isMongooseDocumentArray;
  3334. if (isSubdoc && err instanceof ValidationError) {
  3335. return --total || complete();
  3336. }
  3337. _this.invalidate(path, err, undefined, true);
  3338. }
  3339. --total || complete();
  3340. }, scope, doValidateOptions);
  3341. });
  3342. }
  3343. function complete() {
  3344. var error = _complete();
  3345. if (error) {
  3346. return _this.$__schema.s.hooks.execPost('validate:error', _this, [_this], {
  3347. error: error
  3348. }, function (error) {
  3349. callback(error);
  3350. });
  3351. }
  3352. callback(null, _this);
  3353. }
  3354. };
  3355. /*!
  3356. * ignore
  3357. */
  3358. function _handlePathsToValidate(paths, pathsToValidate) {
  3359. var _pathsToValidate = new Set(pathsToValidate);
  3360. var parentPaths = new Map([]);
  3361. var _iterator17 = _createForOfIteratorHelper(pathsToValidate),
  3362. _step17;
  3363. try {
  3364. for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
  3365. var path = _step17.value;
  3366. if (path.indexOf('.') === -1) {
  3367. continue;
  3368. }
  3369. var pieces = path.split('.');
  3370. var cur = pieces[0];
  3371. for (var _i17 = 1; _i17 < pieces.length; ++_i17) {
  3372. // Since we skip subpaths under single nested subdocs to
  3373. // avoid double validation, we need to add back the
  3374. // single nested subpath if the user asked for it (gh-8626)
  3375. parentPaths.set(cur, path);
  3376. cur = cur + '.' + pieces[_i17];
  3377. }
  3378. }
  3379. } catch (err) {
  3380. _iterator17.e(err);
  3381. } finally {
  3382. _iterator17.f();
  3383. }
  3384. var ret = [];
  3385. var _iterator18 = _createForOfIteratorHelper(paths),
  3386. _step18;
  3387. try {
  3388. for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
  3389. var _path4 = _step18.value;
  3390. if (_pathsToValidate.has(_path4)) {
  3391. ret.push(_path4);
  3392. } else if (parentPaths.has(_path4)) {
  3393. ret.push(parentPaths.get(_path4));
  3394. }
  3395. }
  3396. } catch (err) {
  3397. _iterator18.e(err);
  3398. } finally {
  3399. _iterator18.f();
  3400. }
  3401. return ret;
  3402. }
  3403. /*!
  3404. * ignore
  3405. */
  3406. function _handlePathsToSkip(paths, pathsToSkip) {
  3407. pathsToSkip = new Set(pathsToSkip);
  3408. paths = paths.filter(function (p) {
  3409. return !pathsToSkip.has(p);
  3410. });
  3411. return paths;
  3412. }
  3413. /**
  3414. * Executes registered validation rules (skipping asynchronous validators) for this document.
  3415. *
  3416. * #### Note:
  3417. *
  3418. * This method is useful if you need synchronous validation.
  3419. *
  3420. * #### Example:
  3421. *
  3422. * const err = doc.validateSync();
  3423. * if (err) {
  3424. * handleError(err);
  3425. * } else {
  3426. * // validation passed
  3427. * }
  3428. *
  3429. * @param {Array|string} pathsToValidate only validate the given paths
  3430. * @param {Object} [options] options for validation
  3431. * @param {Boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
  3432. * @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
  3433. * @return {ValidationError|undefined} ValidationError if there are errors during validation, or undefined if there is no error.
  3434. * @api public
  3435. */
  3436. Document.prototype.validateSync = function (pathsToValidate, options) {
  3437. var _this11 = this;
  3438. var _this = this;
  3439. if (arguments.length === 1 && _typeof(arguments[0]) === 'object' && !Array.isArray(arguments[0])) {
  3440. options = arguments[0];
  3441. pathsToValidate = null;
  3442. }
  3443. var hasValidateModifiedOnlyOption = options && _typeof(options) === 'object' && 'validateModifiedOnly' in options;
  3444. var shouldValidateModifiedOnly;
  3445. if (hasValidateModifiedOnlyOption) {
  3446. shouldValidateModifiedOnly = !!options.validateModifiedOnly;
  3447. } else {
  3448. shouldValidateModifiedOnly = this.$__schema.options.validateModifiedOnly;
  3449. }
  3450. var pathsToSkip = options && options.pathsToSkip;
  3451. if (typeof pathsToValidate === 'string') {
  3452. var isOnePathOnly = pathsToValidate.indexOf(' ') === -1;
  3453. pathsToValidate = isOnePathOnly ? [pathsToValidate] : pathsToValidate.split(' ');
  3454. } else if (typeof pathsToSkip === 'string' && pathsToSkip.indexOf(' ') !== -1) {
  3455. pathsToSkip = pathsToSkip.split(' ');
  3456. } // only validate required fields when necessary
  3457. var pathDetails = _getPathsToValidate(this);
  3458. var paths = shouldValidateModifiedOnly ? pathDetails[0].filter(function (path) {
  3459. return _this11.$isModified(path);
  3460. }) : pathDetails[0];
  3461. var skipSchemaValidators = pathDetails[1];
  3462. if (Array.isArray(pathsToValidate)) {
  3463. paths = _handlePathsToValidate(paths, pathsToValidate);
  3464. } else if (Array.isArray(pathsToSkip)) {
  3465. paths = _handlePathsToSkip(paths, pathsToSkip);
  3466. }
  3467. var validating = {};
  3468. for (var _i18 = 0, len = paths.length; _i18 < len; ++_i18) {
  3469. var path = paths[_i18];
  3470. if (validating[path]) {
  3471. continue;
  3472. }
  3473. validating[path] = true;
  3474. var p = _this.$__schema.path(path);
  3475. if (!p) {
  3476. continue;
  3477. }
  3478. if (!_this.$isValid(path)) {
  3479. continue;
  3480. }
  3481. var val = _this.$__getValue(path);
  3482. var _err = p.doValidateSync(val, _this, {
  3483. skipSchemaValidators: skipSchemaValidators[path],
  3484. path: path,
  3485. validateModifiedOnly: shouldValidateModifiedOnly
  3486. });
  3487. if (_err) {
  3488. var isSubdoc = p.$isSingleNested || p.$isArraySubdocument || p.$isMongooseDocumentArray;
  3489. if (isSubdoc && _err instanceof ValidationError) {
  3490. continue;
  3491. }
  3492. _this.invalidate(path, _err, undefined, true);
  3493. }
  3494. }
  3495. var err = _this.$__.validationError;
  3496. _this.$__.validationError = undefined;
  3497. _this.$emit('validate', _this);
  3498. _this.constructor.emit('validate', _this);
  3499. if (err) {
  3500. for (var key in err.errors) {
  3501. // Make sure cast errors persist
  3502. if (err.errors[key] instanceof MongooseError.CastError) {
  3503. _this.invalidate(key, err.errors[key]);
  3504. }
  3505. }
  3506. }
  3507. return err;
  3508. };
  3509. /**
  3510. * Marks a path as invalid, causing validation to fail.
  3511. *
  3512. * The `errorMsg` argument will become the message of the `ValidationError`.
  3513. *
  3514. * The `value` argument (if passed) will be available through the `ValidationError.value` property.
  3515. *
  3516. * doc.invalidate('size', 'must be less than 20', 14);
  3517. * doc.validate(function (err) {
  3518. * console.log(err)
  3519. * // prints
  3520. * { message: 'Validation failed',
  3521. * name: 'ValidationError',
  3522. * errors:
  3523. * { size:
  3524. * { message: 'must be less than 20',
  3525. * name: 'ValidatorError',
  3526. * path: 'size',
  3527. * type: 'user defined',
  3528. * value: 14 } } }
  3529. * })
  3530. *
  3531. * @param {String} path the field to invalidate. For array elements, use the `array.i.field` syntax, where `i` is the 0-based index in the array.
  3532. * @param {String|Error} errorMsg the error which states the reason `path` was invalid
  3533. * @param {Object|String|Number|any} value optional invalid value
  3534. * @param {String} [kind] optional `kind` property for the error
  3535. * @return {ValidationError} the current ValidationError, with all currently invalidated paths
  3536. * @api public
  3537. */
  3538. Document.prototype.invalidate = function (path, err, val, kind) {
  3539. if (!this.$__.validationError) {
  3540. this.$__.validationError = new ValidationError(this);
  3541. }
  3542. if (this.$__.validationError.errors[path]) {
  3543. return;
  3544. }
  3545. if (!err || typeof err === 'string') {
  3546. err = new ValidatorError({
  3547. path: path,
  3548. message: err,
  3549. type: kind || 'user defined',
  3550. value: val
  3551. });
  3552. }
  3553. if (this.$__.validationError === err) {
  3554. return this.$__.validationError;
  3555. }
  3556. this.$__.validationError.addError(path, err);
  3557. return this.$__.validationError;
  3558. };
  3559. /**
  3560. * Marks a path as valid, removing existing validation errors.
  3561. *
  3562. * @param {String} path the field to mark as valid
  3563. * @api public
  3564. * @memberOf Document
  3565. * @instance
  3566. * @method $markValid
  3567. */
  3568. Document.prototype.$markValid = function (path) {
  3569. if (!this.$__.validationError || !this.$__.validationError.errors[path]) {
  3570. return;
  3571. }
  3572. delete this.$__.validationError.errors[path];
  3573. if (Object.keys(this.$__.validationError.errors).length === 0) {
  3574. this.$__.validationError = null;
  3575. }
  3576. };
  3577. /*!
  3578. * ignore
  3579. */
  3580. function _markValidSubpaths(doc, path) {
  3581. if (!doc.$__.validationError) {
  3582. return;
  3583. }
  3584. var keys = Object.keys(doc.$__.validationError.errors);
  3585. for (var _i19 = 0, _keys7 = keys; _i19 < _keys7.length; _i19++) {
  3586. var key = _keys7[_i19];
  3587. if (key.startsWith(path + '.')) {
  3588. delete doc.$__.validationError.errors[key];
  3589. }
  3590. }
  3591. if (Object.keys(doc.$__.validationError.errors).length === 0) {
  3592. doc.$__.validationError = null;
  3593. }
  3594. }
  3595. /*!
  3596. * ignore
  3597. */
  3598. function _checkImmutableSubpaths(subdoc, schematype, priorVal) {
  3599. var schema = schematype.schema;
  3600. if (schema == null) {
  3601. return;
  3602. }
  3603. for (var _i20 = 0, _Object$keys2 = Object.keys(schema.paths); _i20 < _Object$keys2.length; _i20++) {
  3604. var key = _Object$keys2[_i20];
  3605. var path = schema.paths[key];
  3606. if (path.$immutableSetter == null) {
  3607. continue;
  3608. }
  3609. var oldVal = priorVal == null ? void 0 : priorVal.$__getValue(key); // Calling immutableSetter with `oldVal` even though it expects `newVal`
  3610. // is intentional. That's because `$immutableSetter` compares its param
  3611. // to the current value.
  3612. path.$immutableSetter.call(subdoc, oldVal);
  3613. }
  3614. }
  3615. /**
  3616. * Saves this document by inserting a new document into the database if [document.isNew](/docs/api.html#document_Document-isNew) is `true`,
  3617. * or sends an [updateOne](/docs/api.html#document_Document-updateOne) operation **only** with the modifications to the database, it does not replace the whole document in the latter case.
  3618. *
  3619. * #### Example:
  3620. *
  3621. * product.sold = Date.now();
  3622. * product = await product.save();
  3623. *
  3624. * If save is successful, the returned promise will fulfill with the document
  3625. * saved.
  3626. *
  3627. * #### Example:
  3628. *
  3629. * const newProduct = await product.save();
  3630. * newProduct === product; // true
  3631. *
  3632. * @param {Object} [options] options optional options
  3633. * @param {Session} [options.session=null] the [session](https://docs.mongodb.com/manual/reference/server-sessions/) associated with this save operation. If not specified, defaults to the [document's associated session](api.html#document_Document-$session).
  3634. * @param {Object} [options.safe] (DEPRECATED) overrides [schema's safe option](https://mongoosejs.com//docs/guide.html#safe). Use the `w` option instead.
  3635. * @param {Boolean} [options.validateBeforeSave] set to false to save without validating.
  3636. * @param {Boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
  3637. * @param {Number|String} [options.w] set the [write concern](https://docs.mongodb.com/manual/reference/write-concern/#w-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
  3638. * @param {Boolean} [options.j] set to true for MongoDB to wait until this `save()` has been [journaled before resolving the returned promise](https://docs.mongodb.com/manual/reference/write-concern/#j-option). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern)
  3639. * @param {Number} [options.wtimeout] sets a [timeout for the write concern](https://docs.mongodb.com/manual/reference/write-concern/#wtimeout). Overrides the [schema-level `writeConcern` option](/docs/guide.html#writeConcern).
  3640. * @param {Boolean} [options.checkKeys=true] the MongoDB driver prevents you from saving keys that start with '$' or contain '.' by default. Set this option to `false` to skip that check. See [restrictions on field names](https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names)
  3641. * @param {Boolean} [options.timestamps=true] if `false` and [timestamps](./guide.html#timestamps) are enabled, skip timestamps for this `save()`.
  3642. * @param {Function} [fn] optional callback
  3643. * @method save
  3644. * @memberOf Document
  3645. * @instance
  3646. * @throws {DocumentNotFoundError} if this [save updates an existing document](api.html#document_Document-isNew) but the document doesn't exist in the database. For example, you will get this error if the document is [deleted between when you retrieved the document and when you saved it](documents.html#updating).
  3647. * @return {Promise|undefined} Returns undefined if used with callback or a Promise otherwise.
  3648. * @api public
  3649. * @see middleware https://mongoosejs.com/docs/middleware.html
  3650. */
  3651. /**
  3652. * Checks if a path is invalid
  3653. *
  3654. * @param {String|Array<String>} path the field to check
  3655. * @method $isValid
  3656. * @memberOf Document
  3657. * @instance
  3658. * @api private
  3659. */
  3660. Document.prototype.$isValid = function (path) {
  3661. var _this12 = this;
  3662. if (this.$__.validationError == null || Object.keys(this.$__.validationError.errors).length === 0) {
  3663. return true;
  3664. }
  3665. if (path == null) {
  3666. return false;
  3667. }
  3668. if (path.indexOf(' ') !== -1) {
  3669. path = path.split(' ');
  3670. }
  3671. if (Array.isArray(path)) {
  3672. return path.some(function (p) {
  3673. return _this12.$__.validationError.errors[p] == null;
  3674. });
  3675. }
  3676. return this.$__.validationError.errors[path] == null;
  3677. };
  3678. /**
  3679. * Resets the internal modified state of this document.
  3680. *
  3681. * @api private
  3682. * @return {Document}
  3683. * @method $__reset
  3684. * @memberOf Document
  3685. * @instance
  3686. */
  3687. Document.prototype.$__reset = function reset() {
  3688. var _this = this; // Skip for subdocuments
  3689. var subdocs = this.$parent() === this ? this.$getAllSubdocs() : [];
  3690. var resetArrays = new Set();
  3691. var _iterator19 = _createForOfIteratorHelper(subdocs),
  3692. _step19;
  3693. try {
  3694. for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
  3695. var subdoc = _step19.value;
  3696. var fullPathWithIndexes = subdoc.$__fullPathWithIndexes();
  3697. if (this.isModified(fullPathWithIndexes) || isParentInit(fullPathWithIndexes)) {
  3698. subdoc.$__reset();
  3699. if (subdoc.$isDocumentArrayElement) {
  3700. if (!resetArrays.has(subdoc.parentArray())) {
  3701. var array = subdoc.parentArray();
  3702. this.$__.activePaths.clearPath(fullPathWithIndexes.replace(/\.\d+$/, '').slice(-subdoc.$basePath - 1));
  3703. array[arrayAtomicsBackupSymbol] = array[arrayAtomicsSymbol];
  3704. array[arrayAtomicsSymbol] = {};
  3705. resetArrays.add(array);
  3706. }
  3707. } else {
  3708. if (subdoc.$parent() === this) {
  3709. this.$__.activePaths.clearPath(subdoc.$basePath);
  3710. } else if (subdoc.$parent() != null && subdoc.$parent().$isSubdocument) {
  3711. // If map path underneath subdocument, may end up with a case where
  3712. // map path is modified but parent still needs to be reset. See gh-10295
  3713. subdoc.$parent().$__reset();
  3714. }
  3715. }
  3716. }
  3717. }
  3718. } catch (err) {
  3719. _iterator19.e(err);
  3720. } finally {
  3721. _iterator19.f();
  3722. }
  3723. function isParentInit(path) {
  3724. path = path.indexOf('.') === -1 ? [path] : path.split('.');
  3725. var cur = '';
  3726. for (var _i21 = 0; _i21 < path.length; ++_i21) {
  3727. cur += (cur.length ? '.' : '') + path[_i21];
  3728. if (_this.$__.activePaths[cur] === 'init') {
  3729. return true;
  3730. }
  3731. }
  3732. return false;
  3733. } // clear atomics
  3734. this.$__dirty().forEach(function (dirt) {
  3735. var type = dirt.value;
  3736. if (type && type[arrayAtomicsSymbol]) {
  3737. type[arrayAtomicsBackupSymbol] = type[arrayAtomicsSymbol];
  3738. type[arrayAtomicsSymbol] = {};
  3739. }
  3740. });
  3741. this.$__.backup = {};
  3742. this.$__.backup.activePaths = {
  3743. modify: Object.assign({}, this.$__.activePaths.states.modify),
  3744. "default": Object.assign({}, this.$__.activePaths.states["default"])
  3745. };
  3746. this.$__.backup.validationError = this.$__.validationError;
  3747. this.$__.backup.errors = this.$errors; // Clear 'dirty' cache
  3748. this.$__.activePaths.clear('modify');
  3749. this.$__.activePaths.clear('default');
  3750. this.$__.validationError = undefined;
  3751. this.$errors = undefined;
  3752. _this = this;
  3753. this.$__schema.requiredPaths().forEach(function (path) {
  3754. _this.$__.activePaths.require(path);
  3755. });
  3756. return this;
  3757. };
  3758. /*!
  3759. * ignore
  3760. */
  3761. Document.prototype.$__undoReset = function $__undoReset() {
  3762. if (this.$__.backup == null || this.$__.backup.activePaths == null) {
  3763. return;
  3764. }
  3765. this.$__.activePaths.states.modify = this.$__.backup.activePaths.modify;
  3766. this.$__.activePaths.states["default"] = this.$__.backup.activePaths["default"];
  3767. this.$__.validationError = this.$__.backup.validationError;
  3768. this.$errors = this.$__.backup.errors;
  3769. var _iterator20 = _createForOfIteratorHelper(this.$__dirty()),
  3770. _step20;
  3771. try {
  3772. for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
  3773. var dirt = _step20.value;
  3774. var type = dirt.value;
  3775. if (type && type[arrayAtomicsSymbol] && type[arrayAtomicsBackupSymbol]) {
  3776. type[arrayAtomicsSymbol] = type[arrayAtomicsBackupSymbol];
  3777. }
  3778. }
  3779. } catch (err) {
  3780. _iterator20.e(err);
  3781. } finally {
  3782. _iterator20.f();
  3783. }
  3784. var _iterator21 = _createForOfIteratorHelper(this.$getAllSubdocs()),
  3785. _step21;
  3786. try {
  3787. for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
  3788. var subdoc = _step21.value;
  3789. subdoc.$__undoReset();
  3790. }
  3791. } catch (err) {
  3792. _iterator21.e(err);
  3793. } finally {
  3794. _iterator21.f();
  3795. }
  3796. };
  3797. /**
  3798. * Returns this documents dirty paths / vals.
  3799. *
  3800. * @api private
  3801. * @method $__dirty
  3802. * @memberOf Document
  3803. * @instance
  3804. */
  3805. Document.prototype.$__dirty = function () {
  3806. var _this = this;
  3807. var all = this.$__.activePaths.map('modify', function (path) {
  3808. return {
  3809. path: path,
  3810. value: _this.$__getValue(path),
  3811. schema: _this.$__path(path)
  3812. };
  3813. }); // gh-2558: if we had to set a default and the value is not undefined,
  3814. // we have to save as well
  3815. all = all.concat(this.$__.activePaths.map('default', function (path) {
  3816. if (path === '_id' || _this.$__getValue(path) == null) {
  3817. return;
  3818. }
  3819. return {
  3820. path: path,
  3821. value: _this.$__getValue(path),
  3822. schema: _this.$__path(path)
  3823. };
  3824. }));
  3825. var allPaths = new Map(all.filter(function (el) {
  3826. return el != null;
  3827. }).map(function (el) {
  3828. return [el.path, el.value];
  3829. })); // Ignore "foo.a" if "foo" is dirty already.
  3830. var minimal = [];
  3831. all.forEach(function (item) {
  3832. if (!item) {
  3833. return;
  3834. }
  3835. var top = null;
  3836. var array = parentPaths(item.path);
  3837. for (var _i22 = 0; _i22 < array.length - 1; _i22++) {
  3838. if (allPaths.has(array[_i22])) {
  3839. top = allPaths.get(array[_i22]);
  3840. break;
  3841. }
  3842. }
  3843. if (top == null) {
  3844. minimal.push(item);
  3845. } else if (top != null && top[arrayAtomicsSymbol] != null && top.hasAtomics()) {
  3846. // special case for top level MongooseArrays
  3847. // the `top` array itself and a sub path of `top` are being set.
  3848. // the only way to honor all of both modifications is through a $set
  3849. // of entire array.
  3850. top[arrayAtomicsSymbol] = {};
  3851. top[arrayAtomicsSymbol].$set = top;
  3852. }
  3853. });
  3854. return minimal;
  3855. };
  3856. /**
  3857. * Assigns/compiles `schema` into this documents prototype.
  3858. *
  3859. * @param {Schema} schema
  3860. * @api private
  3861. * @method $__setSchema
  3862. * @memberOf Document
  3863. * @instance
  3864. */
  3865. Document.prototype.$__setSchema = function (schema) {
  3866. compile(schema.tree, this, undefined, schema.options); // Apply default getters if virtual doesn't have any (gh-6262)
  3867. for (var _i23 = 0, _Object$keys3 = Object.keys(schema.virtuals); _i23 < _Object$keys3.length; _i23++) {
  3868. var key = _Object$keys3[_i23];
  3869. schema.virtuals[key]._applyDefaultGetters();
  3870. }
  3871. if (schema.path('schema') == null) {
  3872. this.schema = schema;
  3873. }
  3874. this.$__schema = schema;
  3875. this[documentSchemaSymbol] = schema;
  3876. };
  3877. /**
  3878. * Get active path that were changed and are arrays
  3879. *
  3880. * @api private
  3881. * @method $__getArrayPathsToValidate
  3882. * @memberOf Document
  3883. * @instance
  3884. */
  3885. Document.prototype.$__getArrayPathsToValidate = function () {
  3886. DocumentArray || (DocumentArray = __webpack_require__(6077)); // validate all document arrays.
  3887. return this.$__.activePaths.map('init', 'modify', function (i) {
  3888. return this.$__getValue(i);
  3889. }.bind(this)).filter(function (val) {
  3890. return val && Array.isArray(val) && utils.isMongooseDocumentArray(val) && val.length;
  3891. }).reduce(function (seed, array) {
  3892. return seed.concat(array);
  3893. }, []).filter(function (doc) {
  3894. return doc;
  3895. });
  3896. };
  3897. /**
  3898. * Get all subdocs (by bfs)
  3899. *
  3900. * @api public
  3901. * @method $getAllSubdocs
  3902. * @memberOf Document
  3903. * @instance
  3904. */
  3905. Document.prototype.$getAllSubdocs = function () {
  3906. DocumentArray || (DocumentArray = __webpack_require__(6077));
  3907. Embedded = Embedded || __webpack_require__(1568);
  3908. function docReducer(doc, seed, path) {
  3909. var val = doc;
  3910. var isNested = false;
  3911. if (path) {
  3912. if (doc instanceof Document && doc[documentSchemaSymbol].paths[path]) {
  3913. val = doc._doc[path];
  3914. } else if (doc instanceof Document && doc[documentSchemaSymbol].nested[path]) {
  3915. val = doc._doc[path];
  3916. isNested = true;
  3917. } else {
  3918. val = doc[path];
  3919. }
  3920. }
  3921. if (val instanceof Embedded) {
  3922. seed.push(val);
  3923. } else if (val instanceof Map) {
  3924. seed = Array.from(val.keys()).reduce(function (seed, path) {
  3925. return docReducer(val.get(path), seed, null);
  3926. }, seed);
  3927. } else if (val && !Array.isArray(val) && val.$isSingleNested) {
  3928. seed = Object.keys(val._doc).reduce(function (seed, path) {
  3929. return docReducer(val, seed, path);
  3930. }, seed);
  3931. seed.push(val);
  3932. } else if (val && utils.isMongooseDocumentArray(val)) {
  3933. val.forEach(function _docReduce(doc) {
  3934. if (!doc || !doc._doc) {
  3935. return;
  3936. }
  3937. seed = Object.keys(doc._doc).reduce(function (seed, path) {
  3938. return docReducer(doc._doc, seed, path);
  3939. }, seed);
  3940. if (doc instanceof Embedded) {
  3941. seed.push(doc);
  3942. }
  3943. });
  3944. } else if (isNested && val != null) {
  3945. for (var _i24 = 0, _Object$keys4 = Object.keys(val); _i24 < _Object$keys4.length; _i24++) {
  3946. var _path5 = _Object$keys4[_i24];
  3947. docReducer(val, seed, _path5);
  3948. }
  3949. }
  3950. return seed;
  3951. }
  3952. var subDocs = [];
  3953. for (var _i25 = 0, _Object$keys5 = Object.keys(this._doc); _i25 < _Object$keys5.length; _i25++) {
  3954. var path = _Object$keys5[_i25];
  3955. docReducer(this, subDocs, path);
  3956. }
  3957. return subDocs;
  3958. };
  3959. /*!
  3960. * Runs queued functions
  3961. */
  3962. function applyQueue(doc) {
  3963. var q = doc.$__schema && doc.$__schema.callQueue;
  3964. if (!q.length) {
  3965. return;
  3966. }
  3967. var _iterator22 = _createForOfIteratorHelper(q),
  3968. _step22;
  3969. try {
  3970. for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
  3971. var pair = _step22.value;
  3972. if (pair[0] !== 'pre' && pair[0] !== 'post' && pair[0] !== 'on') {
  3973. doc[pair[0]].apply(doc, pair[1]);
  3974. }
  3975. }
  3976. } catch (err) {
  3977. _iterator22.e(err);
  3978. } finally {
  3979. _iterator22.f();
  3980. }
  3981. }
  3982. /*!
  3983. * ignore
  3984. */
  3985. Document.prototype.$__handleReject = function handleReject(err) {
  3986. // emit on the Model if listening
  3987. if (this.$listeners('error').length) {
  3988. this.$emit('error', err);
  3989. } else if (this.constructor.listeners && this.constructor.listeners('error').length) {
  3990. this.constructor.emit('error', err);
  3991. }
  3992. };
  3993. /**
  3994. * Internal helper for toObject() and toJSON() that doesn't manipulate options
  3995. *
  3996. * @api private
  3997. * @method $toObject
  3998. * @memberOf Document
  3999. * @instance
  4000. */
  4001. Document.prototype.$toObject = function (options, json) {
  4002. var defaultOptions = {
  4003. transform: true,
  4004. flattenDecimals: true
  4005. };
  4006. var path = json ? 'toJSON' : 'toObject';
  4007. var baseOptions = this.constructor && this.constructor.base && this.constructor.base.options && get(this.constructor.base.options, path) || {};
  4008. var schemaOptions = this.$__schema && this.$__schema.options || {}; // merge base default options with Schema's set default options if available.
  4009. // `clone` is necessary here because `utils.options` directly modifies the second input.
  4010. defaultOptions = utils.options(defaultOptions, clone(baseOptions));
  4011. defaultOptions = utils.options(defaultOptions, clone(schemaOptions[path] || {})); // If options do not exist or is not an object, set it to empty object
  4012. options = utils.isPOJO(options) ? _objectSpread({}, options) : {};
  4013. options._calledWithOptions = options._calledWithOptions || _objectSpread({}, options);
  4014. var _minimize;
  4015. if (options._calledWithOptions.minimize != null) {
  4016. _minimize = options.minimize;
  4017. } else if (defaultOptions.minimize != null) {
  4018. _minimize = defaultOptions.minimize;
  4019. } else {
  4020. _minimize = schemaOptions.minimize;
  4021. }
  4022. var flattenMaps;
  4023. if (options._calledWithOptions.flattenMaps != null) {
  4024. flattenMaps = options.flattenMaps;
  4025. } else if (defaultOptions.flattenMaps != null) {
  4026. flattenMaps = defaultOptions.flattenMaps;
  4027. } else {
  4028. flattenMaps = schemaOptions.flattenMaps;
  4029. } // The original options that will be passed to `clone()`. Important because
  4030. // `clone()` will recursively call `$toObject()` on embedded docs, so we
  4031. // need the original options the user passed in, plus `_isNested` and
  4032. // `_parentOptions` for checking whether we need to depopulate.
  4033. var cloneOptions = Object.assign({}, options, {
  4034. _isNested: true,
  4035. json: json,
  4036. minimize: _minimize,
  4037. flattenMaps: flattenMaps,
  4038. _seen: options && options._seen || new Map()
  4039. });
  4040. if (utils.hasUserDefinedProperty(options, 'getters')) {
  4041. cloneOptions.getters = options.getters;
  4042. }
  4043. if (utils.hasUserDefinedProperty(options, 'virtuals')) {
  4044. cloneOptions.virtuals = options.virtuals;
  4045. }
  4046. var depopulate = options.depopulate || options._parentOptions && options._parentOptions.depopulate || false; // _isNested will only be true if this is not the top level document, we
  4047. // should never depopulate the top-level document
  4048. if (depopulate && options._isNested && this.$__.wasPopulated) {
  4049. return clone(this.$__.wasPopulated.value || this._id, cloneOptions);
  4050. } // merge default options with input options.
  4051. options = utils.options(defaultOptions, options);
  4052. options._isNested = true;
  4053. options.json = json;
  4054. options.minimize = _minimize;
  4055. cloneOptions._parentOptions = options;
  4056. cloneOptions._skipSingleNestedGetters = true;
  4057. var gettersOptions = Object.assign({}, cloneOptions);
  4058. gettersOptions._skipSingleNestedGetters = false; // remember the root transform function
  4059. // to save it from being overwritten by sub-transform functions
  4060. var originalTransform = options.transform;
  4061. var ret = clone(this._doc, cloneOptions) || {};
  4062. if (options.getters) {
  4063. applyGetters(this, ret, gettersOptions);
  4064. if (options.minimize) {
  4065. ret = minimize(ret) || {};
  4066. }
  4067. }
  4068. if (options.virtuals || options.getters && options.virtuals !== false) {
  4069. applyVirtuals(this, ret, gettersOptions, options);
  4070. }
  4071. if (options.versionKey === false && this.$__schema.options.versionKey) {
  4072. delete ret[this.$__schema.options.versionKey];
  4073. }
  4074. var transform = options.transform; // In the case where a subdocument has its own transform function, we need to
  4075. // check and see if the parent has a transform (options.transform) and if the
  4076. // child schema has a transform (this.schema.options.toObject) In this case,
  4077. // we need to adjust options.transform to be the child schema's transform and
  4078. // not the parent schema's
  4079. if (transform) {
  4080. applySchemaTypeTransforms(this, ret);
  4081. }
  4082. if (options.useProjection) {
  4083. omitDeselectedFields(this, ret);
  4084. }
  4085. if (transform === true || schemaOptions.toObject && transform) {
  4086. var opts = options.json ? schemaOptions.toJSON : schemaOptions.toObject;
  4087. if (opts) {
  4088. transform = typeof options.transform === 'function' ? options.transform : opts.transform;
  4089. }
  4090. } else {
  4091. options.transform = originalTransform;
  4092. }
  4093. if (typeof transform === 'function') {
  4094. var xformed = transform(this, ret, options);
  4095. if (typeof xformed !== 'undefined') {
  4096. ret = xformed;
  4097. }
  4098. }
  4099. return ret;
  4100. };
  4101. /**
  4102. * Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)).
  4103. *
  4104. * Buffers are converted to instances of [mongodb.Binary](https://mongodb.github.com/node-mongodb-native/api-bson-generated/binary.html) for proper storage.
  4105. *
  4106. * #### Options:
  4107. *
  4108. * - `getters` apply all getters (path and virtual getters), defaults to false
  4109. * - `aliases` apply all aliases if `virtuals=true`, defaults to true
  4110. * - `virtuals` apply virtual getters (can override `getters` option), defaults to false
  4111. * - `minimize` remove empty objects, defaults to true
  4112. * - `transform` a transform function to apply to the resulting document before returning
  4113. * - `depopulate` depopulate any populated paths, replacing them with their original refs, defaults to false
  4114. * - `versionKey` whether to include the version key, defaults to true
  4115. * - `flattenMaps` convert Maps to POJOs. Useful if you want to JSON.stringify() the result of toObject(), defaults to false
  4116. * - `useProjection` set to `true` to omit fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has `select: false` in the schema.
  4117. *
  4118. * #### Getters/Virtuals
  4119. *
  4120. * Example of only applying path getters
  4121. *
  4122. * doc.toObject({ getters: true, virtuals: false })
  4123. *
  4124. * Example of only applying virtual getters
  4125. *
  4126. * doc.toObject({ virtuals: true })
  4127. *
  4128. * Example of applying both path and virtual getters
  4129. *
  4130. * doc.toObject({ getters: true })
  4131. *
  4132. * To apply these options to every document of your schema by default, set your [schemas](#schema_Schema) `toObject` option to the same argument.
  4133. *
  4134. * schema.set('toObject', { virtuals: true })
  4135. *
  4136. * #### Transform
  4137. *
  4138. * We may need to perform a transformation of the resulting object based on some criteria, say to remove some sensitive information or return a custom object. In this case we set the optional `transform` function.
  4139. *
  4140. * Transform functions receive three arguments
  4141. *
  4142. * function (doc, ret, options) {}
  4143. *
  4144. * - `doc` The mongoose document which is being converted
  4145. * - `ret` The plain object representation which has been converted
  4146. * - `options` The options in use (either schema options or the options passed inline)
  4147. *
  4148. * #### Example
  4149. *
  4150. * // specify the transform schema option
  4151. * if (!schema.options.toObject) schema.options.toObject = {};
  4152. * schema.options.toObject.transform = function (doc, ret, options) {
  4153. * // remove the _id of every document before returning the result
  4154. * delete ret._id;
  4155. * return ret;
  4156. * }
  4157. *
  4158. * // without the transformation in the schema
  4159. * doc.toObject(); // { _id: 'anId', name: 'Wreck-it Ralph' }
  4160. *
  4161. * // with the transformation
  4162. * doc.toObject(); // { name: 'Wreck-it Ralph' }
  4163. *
  4164. * With transformations we can do a lot more than remove properties. We can even return completely new customized objects:
  4165. *
  4166. * if (!schema.options.toObject) schema.options.toObject = {};
  4167. * schema.options.toObject.transform = function (doc, ret, options) {
  4168. * return { movie: ret.name }
  4169. * }
  4170. *
  4171. * // without the transformation in the schema
  4172. * doc.toObject(); // { _id: 'anId', name: 'Wreck-it Ralph' }
  4173. *
  4174. * // with the transformation
  4175. * doc.toObject(); // { movie: 'Wreck-it Ralph' }
  4176. *
  4177. * _Note: if a transform function returns `undefined`, the return value will be ignored._
  4178. *
  4179. * Transformations may also be applied inline, overridding any transform set in the options:
  4180. *
  4181. * function xform (doc, ret, options) {
  4182. * return { inline: ret.name, custom: true }
  4183. * }
  4184. *
  4185. * // pass the transform as an inline option
  4186. * doc.toObject({ transform: xform }); // { inline: 'Wreck-it Ralph', custom: true }
  4187. *
  4188. * If you want to skip transformations, use `transform: false`:
  4189. *
  4190. * schema.options.toObject.hide = '_id';
  4191. * schema.options.toObject.transform = function (doc, ret, options) {
  4192. * if (options.hide) {
  4193. * options.hide.split(' ').forEach(function (prop) {
  4194. * delete ret[prop];
  4195. * });
  4196. * }
  4197. * return ret;
  4198. * }
  4199. *
  4200. * const doc = new Doc({ _id: 'anId', secret: 47, name: 'Wreck-it Ralph' });
  4201. * doc.toObject(); // { secret: 47, name: 'Wreck-it Ralph' }
  4202. * doc.toObject({ hide: 'secret _id', transform: false });// { _id: 'anId', secret: 47, name: 'Wreck-it Ralph' }
  4203. * doc.toObject({ hide: 'secret _id', transform: true }); // { name: 'Wreck-it Ralph' }
  4204. *
  4205. * If you pass a transform in `toObject()` options, Mongoose will apply the transform
  4206. * to [subdocuments](/docs/subdocs.html) in addition to the top-level document.
  4207. * Similarly, `transform: false` skips transforms for all subdocuments.
  4208. * Note that this behavior is different for transforms defined in the schema:
  4209. * if you define a transform in `schema.options.toObject.transform`, that transform
  4210. * will **not** apply to subdocuments.
  4211. *
  4212. * const memberSchema = new Schema({ name: String, email: String });
  4213. * const groupSchema = new Schema({ members: [memberSchema], name: String, email });
  4214. * const Group = mongoose.model('Group', groupSchema);
  4215. *
  4216. * const doc = new Group({
  4217. * name: 'Engineering',
  4218. * email: 'dev@mongoosejs.io',
  4219. * members: [{ name: 'Val', email: 'val@mongoosejs.io' }]
  4220. * });
  4221. *
  4222. * // Removes `email` from both top-level document **and** array elements
  4223. * // { name: 'Engineering', members: [{ name: 'Val' }] }
  4224. * doc.toObject({ transform: (doc, ret) => { delete ret.email; return ret; } });
  4225. *
  4226. * Transforms, like all of these options, are also available for `toJSON`. See [this guide to `JSON.stringify()`](https://thecodebarbarian.com/the-80-20-guide-to-json-stringify-in-javascript.html) to learn why `toJSON()` and `toObject()` are separate functions.
  4227. *
  4228. * See [schema options](/docs/guide.html#toObject) for some more details.
  4229. *
  4230. * _During save, no custom options are applied to the document before being sent to the database._
  4231. *
  4232. * @param {Object} [options]
  4233. * @param {Boolean} [options.getters=false] if true, apply all getters, including virtuals
  4234. * @param {Boolean} [options.virtuals=false] if true, apply virtuals, including aliases. Use `{ getters: true, virtuals: false }` to just apply getters, not virtuals
  4235. * @param {Boolean} [options.aliases=true] if `options.virtuals = true`, you can set `options.aliases = false` to skip applying aliases. This option is a no-op if `options.virtuals = false`.
  4236. * @param {Boolean} [options.minimize=true] if true, omit any empty objects from the output
  4237. * @param {Function|null} [options.transform=null] if set, mongoose will call this function to allow you to transform the returned object
  4238. * @param {Boolean} [options.depopulate=false] if true, replace any conventionally populated paths with the original id in the output. Has no affect on virtual populated paths.
  4239. * @param {Boolean} [options.versionKey=true] if false, exclude the version key (`__v` by default) from the output
  4240. * @param {Boolean} [options.flattenMaps=false] if true, convert Maps to POJOs. Useful if you want to `JSON.stringify()` the result of `toObject()`.
  4241. * @param {Boolean} [options.useProjection=false] - If true, omits fields that are excluded in this document's projection. Unless you specified a projection, this will omit any field that has `select: false` in the schema.
  4242. * @return {Object} js object
  4243. * @see mongodb.Binary https://mongodb.github.com/node-mongodb-native/api-bson-generated/binary.html
  4244. * @api public
  4245. * @memberOf Document
  4246. * @instance
  4247. */
  4248. Document.prototype.toObject = function (options) {
  4249. return this.$toObject(options);
  4250. };
  4251. /*!
  4252. * Minimizes an object, removing undefined values and empty objects
  4253. *
  4254. * @param {Object} object to minimize
  4255. * @return {Object}
  4256. */
  4257. function minimize(obj) {
  4258. var keys = Object.keys(obj);
  4259. var i = keys.length;
  4260. var hasKeys;
  4261. var key;
  4262. var val;
  4263. while (i--) {
  4264. key = keys[i];
  4265. val = obj[key];
  4266. if (utils.isPOJO(val)) {
  4267. obj[key] = minimize(val);
  4268. }
  4269. if (undefined === obj[key]) {
  4270. delete obj[key];
  4271. continue;
  4272. }
  4273. hasKeys = true;
  4274. }
  4275. return hasKeys ? obj : undefined;
  4276. }
  4277. /*!
  4278. * Applies virtuals properties to `json`.
  4279. */
  4280. function applyVirtuals(self, json, options, toObjectOptions) {
  4281. var schema = self.$__schema;
  4282. var paths = Object.keys(schema.virtuals);
  4283. var i = paths.length;
  4284. var numPaths = i;
  4285. var path;
  4286. var assignPath;
  4287. var cur = self._doc;
  4288. var v;
  4289. var aliases = typeof (toObjectOptions && toObjectOptions.aliases) === 'boolean' ? toObjectOptions.aliases : true;
  4290. var virtualsToApply = null;
  4291. if (Array.isArray(options.virtuals)) {
  4292. virtualsToApply = new Set(options.virtuals);
  4293. } else if (options.virtuals && options.virtuals.pathsToSkip) {
  4294. virtualsToApply = new Set(paths);
  4295. for (var _i26 = 0; _i26 < options.virtuals.pathsToSkip.length; _i26++) {
  4296. if (virtualsToApply.has(options.virtuals.pathsToSkip[_i26])) {
  4297. virtualsToApply["delete"](options.virtuals.pathsToSkip[_i26]);
  4298. }
  4299. }
  4300. }
  4301. if (!cur) {
  4302. return json;
  4303. }
  4304. options = options || {};
  4305. for (i = 0; i < numPaths; ++i) {
  4306. path = paths[i];
  4307. if (virtualsToApply != null && !virtualsToApply.has(path)) {
  4308. continue;
  4309. } // Allow skipping aliases with `toObject({ virtuals: true, aliases: false })`
  4310. if (!aliases && schema.aliases.hasOwnProperty(path)) {
  4311. continue;
  4312. } // We may be applying virtuals to a nested object, for example if calling
  4313. // `doc.nestedProp.toJSON()`. If so, the path we assign to, `assignPath`,
  4314. // will be a trailing substring of the `path`.
  4315. assignPath = path;
  4316. if (options.path != null) {
  4317. if (!path.startsWith(options.path + '.')) {
  4318. continue;
  4319. }
  4320. assignPath = path.substring(options.path.length + 1);
  4321. }
  4322. var parts = assignPath.split('.');
  4323. v = clone(self.get(path), options);
  4324. if (v === void 0) {
  4325. continue;
  4326. }
  4327. var plen = parts.length;
  4328. cur = json;
  4329. for (var j = 0; j < plen - 1; ++j) {
  4330. cur[parts[j]] = cur[parts[j]] || {};
  4331. cur = cur[parts[j]];
  4332. }
  4333. cur[parts[plen - 1]] = v;
  4334. }
  4335. return json;
  4336. }
  4337. /*!
  4338. * Applies virtuals properties to `json`.
  4339. *
  4340. * @param {Document} self
  4341. * @param {Object} json
  4342. * @return {Object} `json`
  4343. */
  4344. function applyGetters(self, json, options) {
  4345. var schema = self.$__schema;
  4346. var paths = Object.keys(schema.paths);
  4347. var i = paths.length;
  4348. var path;
  4349. var cur = self._doc;
  4350. var v;
  4351. if (!cur) {
  4352. return json;
  4353. }
  4354. while (i--) {
  4355. path = paths[i];
  4356. var parts = path.split('.');
  4357. var plen = parts.length;
  4358. var last = plen - 1;
  4359. var branch = json;
  4360. var part = void 0;
  4361. cur = self._doc;
  4362. if (!self.$__isSelected(path)) {
  4363. continue;
  4364. }
  4365. for (var ii = 0; ii < plen; ++ii) {
  4366. part = parts[ii];
  4367. v = cur[part];
  4368. if (ii === last) {
  4369. var val = self.$get(path);
  4370. branch[part] = clone(val, options);
  4371. } else if (v == null) {
  4372. if (part in cur) {
  4373. branch[part] = v;
  4374. }
  4375. break;
  4376. } else {
  4377. branch = branch[part] || (branch[part] = {});
  4378. }
  4379. cur = v;
  4380. }
  4381. }
  4382. return json;
  4383. }
  4384. /*!
  4385. * Applies schema type transforms to `json`.
  4386. *
  4387. * @param {Document} self
  4388. * @param {Object} json
  4389. * @return {Object} `json`
  4390. */
  4391. function applySchemaTypeTransforms(self, json) {
  4392. var schema = self.$__schema;
  4393. var paths = Object.keys(schema.paths || {});
  4394. var cur = self._doc;
  4395. if (!cur) {
  4396. return json;
  4397. }
  4398. for (var _i27 = 0, _paths4 = paths; _i27 < _paths4.length; _i27++) {
  4399. var path = _paths4[_i27];
  4400. var schematype = schema.paths[path];
  4401. if (typeof schematype.options.transform === 'function') {
  4402. var val = self.$get(path);
  4403. if (val === undefined) {
  4404. continue;
  4405. }
  4406. var transformedValue = schematype.options.transform.call(self, val);
  4407. throwErrorIfPromise(path, transformedValue);
  4408. utils.setValue(path, transformedValue, json);
  4409. } else if (schematype.$embeddedSchemaType != null && typeof schematype.$embeddedSchemaType.options.transform === 'function') {
  4410. var _val2 = self.$get(path);
  4411. if (_val2 === undefined) {
  4412. continue;
  4413. }
  4414. var vals = [].concat(_val2);
  4415. var transform = schematype.$embeddedSchemaType.options.transform;
  4416. for (var _i28 = 0; _i28 < vals.length; ++_i28) {
  4417. var _transformedValue = transform.call(self, vals[_i28]);
  4418. vals[_i28] = _transformedValue;
  4419. throwErrorIfPromise(path, _transformedValue);
  4420. }
  4421. json[path] = vals;
  4422. }
  4423. }
  4424. return json;
  4425. }
  4426. function throwErrorIfPromise(path, transformedValue) {
  4427. if (isPromise(transformedValue)) {
  4428. throw new Error('`transform` function must be synchronous, but the transform on path `' + path + '` returned a promise.');
  4429. }
  4430. }
  4431. /*!
  4432. * ignore
  4433. */
  4434. function omitDeselectedFields(self, json) {
  4435. var schema = self.$__schema;
  4436. var paths = Object.keys(schema.paths || {});
  4437. var cur = self._doc;
  4438. if (!cur) {
  4439. return json;
  4440. }
  4441. var selected = self.$__.selected;
  4442. if (selected === void 0) {
  4443. selected = {};
  4444. queryhelpers.applyPaths(selected, schema);
  4445. }
  4446. if (selected == null || Object.keys(selected).length === 0) {
  4447. return json;
  4448. }
  4449. for (var _i29 = 0, _paths5 = paths; _i29 < _paths5.length; _i29++) {
  4450. var path = _paths5[_i29];
  4451. if (selected[path] != null && !selected[path]) {
  4452. delete json[path];
  4453. }
  4454. }
  4455. return json;
  4456. }
  4457. /**
  4458. * The return value of this method is used in calls to [`JSON.stringify(doc)`](https://thecodebarbarian.com/the-80-20-guide-to-json-stringify-in-javascript#the-tojson-function).
  4459. *
  4460. * This method accepts the same options as [Document#toObject](#document_Document-toObject). To apply the options to every document of your schema by default, set your [schemas](#schema_Schema) `toJSON` option to the same argument.
  4461. *
  4462. * schema.set('toJSON', { virtuals: true });
  4463. *
  4464. * There is one difference between `toJSON()` and `toObject()` options.
  4465. * When you call `toJSON()`, the [`flattenMaps` option](./document.html#document_Document-toObject) defaults to `true`, because `JSON.stringify()` doesn't convert maps to objects by default.
  4466. * When you call `toObject()`, the `flattenMaps` option is `false` by default.
  4467. *
  4468. * See [schema options](/docs/guide.html#toJSON) for more information on setting `toJSON` option defaults.
  4469. *
  4470. * @param {Object} options
  4471. * @param {Boolean} [options.flattenMaps=true] if true, convert Maps to [POJOs](https://masteringjs.io/tutorials/fundamentals/pojo). Useful if you want to `JSON.stringify()` the result.
  4472. * @return {Object}
  4473. * @see Document#toObject #document_Document-toObject
  4474. * @see JSON.stringify() in JavaScript https://thecodebarbarian.com/the-80-20-guide-to-json-stringify-in-javascript.html
  4475. * @api public
  4476. * @memberOf Document
  4477. * @instance
  4478. */
  4479. Document.prototype.toJSON = function (options) {
  4480. return this.$toObject(options, true);
  4481. };
  4482. Document.prototype.ownerDocument = function () {
  4483. return this;
  4484. };
  4485. /**
  4486. * If this document is a subdocument or populated document, returns the document's
  4487. * parent. Returns the original document if there is no parent.
  4488. *
  4489. * @api public
  4490. * @method parent
  4491. * @memberOf Document
  4492. * @instance
  4493. */
  4494. Document.prototype.parent = function () {
  4495. if (this.$isSubdocument || this.$__.wasPopulated) {
  4496. return this.$__.parent;
  4497. }
  4498. return this;
  4499. };
  4500. /**
  4501. * Alias for `parent()`. If this document is a subdocument or populated
  4502. * document, returns the document's parent. Returns `undefined` otherwise.
  4503. *
  4504. * @api public
  4505. * @method $parent
  4506. * @memberOf Document
  4507. * @instance
  4508. */
  4509. Document.prototype.$parent = Document.prototype.parent;
  4510. /**
  4511. * Helper for console.log
  4512. *
  4513. * @api public
  4514. * @method inspect
  4515. * @memberOf Document
  4516. * @instance
  4517. */
  4518. Document.prototype.inspect = function (options) {
  4519. var isPOJO = utils.isPOJO(options);
  4520. var opts;
  4521. if (isPOJO) {
  4522. opts = options;
  4523. opts.minimize = false;
  4524. }
  4525. var ret = this.toObject(opts);
  4526. if (ret == null) {
  4527. // If `toObject()` returns null, `this` is still an object, so if `inspect()`
  4528. // prints out null this can cause some serious confusion. See gh-7942.
  4529. return 'MongooseDocument { ' + ret + ' }';
  4530. }
  4531. return ret;
  4532. };
  4533. if (inspect.custom) {
  4534. /*!
  4535. * Avoid Node deprecation warning DEP0079
  4536. */
  4537. Document.prototype[inspect.custom] = Document.prototype.inspect;
  4538. }
  4539. /**
  4540. * Helper for console.log
  4541. *
  4542. * @api public
  4543. * @method toString
  4544. * @memberOf Document
  4545. * @instance
  4546. */
  4547. Document.prototype.toString = function () {
  4548. var ret = this.inspect();
  4549. if (typeof ret === 'string') {
  4550. return ret;
  4551. }
  4552. return inspect(ret);
  4553. };
  4554. /**
  4555. * Returns true if this document is equal to another document.
  4556. *
  4557. * Documents are considered equal when they have matching `_id`s, unless neither
  4558. * document has an `_id`, in which case this function falls back to using
  4559. * `deepEqual()`.
  4560. *
  4561. * @param {Document} doc a document to compare
  4562. * @return {Boolean}
  4563. * @api public
  4564. * @memberOf Document
  4565. * @instance
  4566. */
  4567. Document.prototype.equals = function (doc) {
  4568. if (!doc) {
  4569. return false;
  4570. }
  4571. var tid = this.$__getValue('_id');
  4572. var docid = doc.$__ != null ? doc.$__getValue('_id') : doc;
  4573. if (!tid && !docid) {
  4574. return deepEqual(this, doc);
  4575. }
  4576. return tid && tid.equals ? tid.equals(docid) : tid === docid;
  4577. };
  4578. /**
  4579. * Populates paths on an existing document.
  4580. *
  4581. * #### Example:
  4582. *
  4583. * await doc.populate([
  4584. * 'stories',
  4585. * { path: 'fans', sort: { name: -1 } }
  4586. * ]);
  4587. * doc.populated('stories'); // Array of ObjectIds
  4588. * doc.stories[0].title; // 'Casino Royale'
  4589. * doc.populated('fans'); // Array of ObjectIds
  4590. *
  4591. * await doc.populate('fans', '-email');
  4592. * doc.fans[0].email // not populated
  4593. *
  4594. * await doc.populate('author fans', '-email');
  4595. * doc.author.email // not populated
  4596. * doc.fans[0].email // not populated
  4597. *
  4598. * @param {String|Object|Array} path either the path to populate or an object specifying all parameters, or either an array of those
  4599. * @param {Object|String} [select] Field selection for the population query
  4600. * @param {Model} [model] The model you wish to use for population. If not specified, populate will look up the model by the name in the Schema's `ref` field.
  4601. * @param {Object} [match] Conditions for the population query
  4602. * @param {Object} [options] Options for the population query (sort, etc)
  4603. * @param {String} [options.path=null] The path to populate.
  4604. * @param {string|PopulateOptions} [options.populate=null] Recursively populate paths in the populated documents. See [deep populate docs](/docs/populate.html#deep-populate).
  4605. * @param {boolean} [options.retainNullValues=false] by default, Mongoose removes null and undefined values from populated arrays. Use this option to make `populate()` retain `null` and `undefined` array entries.
  4606. * @param {boolean} [options.getters=false] if true, Mongoose will call any getters defined on the `localField`. By default, Mongoose gets the raw value of `localField`. For example, you would need to set this option to `true` if you wanted to [add a `lowercase` getter to your `localField`](/docs/schematypes.html#schematype-options).
  4607. * @param {boolean} [options.clone=false] When you do `BlogPost.find().populate('author')`, blog posts with the same author will share 1 copy of an `author` doc. Enable this option to make Mongoose clone populated docs before assigning them.
  4608. * @param {Object|Function} [options.match=null] Add an additional filter to the populate query. Can be a filter object containing [MongoDB query syntax](https://docs.mongodb.com/manual/tutorial/query-documents/), or a function that returns a filter object.
  4609. * @param {Function} [options.transform=null] Function that Mongoose will call on every populated document that allows you to transform the populated document.
  4610. * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
  4611. * @param {Function} [callback] Callback
  4612. * @see population ./populate.html
  4613. * @see Query#select #query_Query-select
  4614. * @see Model.populate #model_Model.populate
  4615. * @memberOf Document
  4616. * @instance
  4617. * @return {Promise|null}
  4618. * @api public
  4619. */
  4620. Document.prototype.populate = function populate() {
  4621. var pop = {};
  4622. var args = Array.prototype.slice.call(arguments);
  4623. var fn;
  4624. if (args.length !== 0) {
  4625. if (typeof args[args.length - 1] === 'function') {
  4626. fn = args.pop();
  4627. } // use hash to remove duplicate paths
  4628. var res = utils.populate.apply(null, args);
  4629. var _iterator23 = _createForOfIteratorHelper(res),
  4630. _step23;
  4631. try {
  4632. for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
  4633. var populateOptions = _step23.value;
  4634. pop[populateOptions.path] = populateOptions;
  4635. }
  4636. } catch (err) {
  4637. _iterator23.e(err);
  4638. } finally {
  4639. _iterator23.f();
  4640. }
  4641. }
  4642. var paths = utils.object.vals(pop);
  4643. var topLevelModel = this.constructor;
  4644. if (this.$__isNested) {
  4645. topLevelModel = this.$__[scopeSymbol].constructor;
  4646. var nestedPath = this.$__.nestedPath;
  4647. paths.forEach(function (populateOptions) {
  4648. populateOptions.path = nestedPath + '.' + populateOptions.path;
  4649. });
  4650. } // Use `$session()` by default if the document has an associated session
  4651. // See gh-6754
  4652. if (this.$session() != null) {
  4653. var session = this.$session();
  4654. paths.forEach(function (path) {
  4655. if (path.options == null) {
  4656. path.options = {
  4657. session: session
  4658. };
  4659. return;
  4660. }
  4661. if (!('session' in path.options)) {
  4662. path.options.session = session;
  4663. }
  4664. });
  4665. }
  4666. paths.forEach(function (p) {
  4667. p._localModel = topLevelModel;
  4668. });
  4669. return topLevelModel.populate(this, paths, fn);
  4670. };
  4671. /**
  4672. * Gets all populated documents associated with this document.
  4673. *
  4674. * @api public
  4675. * @return {Array<Document>} array of populated documents. Empty array if there are no populated documents associated with this document.
  4676. * @memberOf Document
  4677. * @method $getPopulatedDocs
  4678. * @instance
  4679. */
  4680. Document.prototype.$getPopulatedDocs = function $getPopulatedDocs() {
  4681. var keys = [];
  4682. if (this.$__.populated != null) {
  4683. keys = keys.concat(Object.keys(this.$__.populated));
  4684. }
  4685. var result = [];
  4686. var _iterator24 = _createForOfIteratorHelper(keys),
  4687. _step24;
  4688. try {
  4689. for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
  4690. var key = _step24.value;
  4691. var value = this.$get(key);
  4692. if (Array.isArray(value)) {
  4693. result = result.concat(value);
  4694. } else if (value instanceof Document) {
  4695. result.push(value);
  4696. }
  4697. }
  4698. } catch (err) {
  4699. _iterator24.e(err);
  4700. } finally {
  4701. _iterator24.f();
  4702. }
  4703. return result;
  4704. };
  4705. /**
  4706. * Gets _id(s) used during population of the given `path`.
  4707. *
  4708. * #### Example:
  4709. *
  4710. * const doc = await Model.findOne().populate('author');
  4711. *
  4712. * console.log(doc.author.name); // Dr.Seuss
  4713. * console.log(doc.populated('author')); // '5144cf8050f071d979c118a7'
  4714. *
  4715. * If the path was not populated, returns `undefined`.
  4716. *
  4717. * @param {String} path
  4718. * @return {Array|ObjectId|Number|Buffer|String|undefined}
  4719. * @memberOf Document
  4720. * @instance
  4721. * @api public
  4722. */
  4723. Document.prototype.populated = function (path, val, options) {
  4724. // val and options are internal
  4725. if (val == null || val === true) {
  4726. if (!this.$__.populated) {
  4727. return undefined;
  4728. }
  4729. if (typeof path !== 'string') {
  4730. return undefined;
  4731. } // Map paths can be populated with either `path.$*` or just `path`
  4732. var _path = path.endsWith('.$*') ? path.replace(/\.\$\*$/, '') : path;
  4733. var v = this.$__.populated[_path];
  4734. if (v) {
  4735. return val === true ? v : v.value;
  4736. }
  4737. return undefined;
  4738. }
  4739. this.$__.populated || (this.$__.populated = {});
  4740. this.$__.populated[path] = {
  4741. value: val,
  4742. options: options
  4743. }; // If this was a nested populate, make sure each populated doc knows
  4744. // about its populated children (gh-7685)
  4745. var pieces = path.split('.');
  4746. for (var _i30 = 0; _i30 < pieces.length - 1; ++_i30) {
  4747. var subpath = pieces.slice(0, _i30 + 1).join('.');
  4748. var subdoc = this.$get(subpath);
  4749. if (subdoc != null && subdoc.$__ != null && this.$populated(subpath)) {
  4750. var rest = pieces.slice(_i30 + 1).join('.');
  4751. subdoc.$populated(rest, val, options); // No need to continue because the above recursion should take care of
  4752. // marking the rest of the docs as populated
  4753. break;
  4754. }
  4755. }
  4756. return val;
  4757. };
  4758. Document.prototype.$populated = Document.prototype.populated;
  4759. /**
  4760. * Throws an error if a given path is not populated
  4761. *
  4762. * #### Example:
  4763. *
  4764. * const doc = await Model.findOne().populate('author');
  4765. *
  4766. * doc.$assertPopulated('author'); // does not throw
  4767. * doc.$assertPopulated('other path'); // throws an error
  4768. *
  4769. *
  4770. * @param {String|Array<String>} path
  4771. * @return {Document} this
  4772. * @memberOf Document
  4773. * @method $assertPopulated
  4774. * @instance
  4775. * @api public
  4776. */
  4777. Document.prototype.$assertPopulated = function $assertPopulated(paths) {
  4778. var _this13 = this;
  4779. if (Array.isArray(paths)) {
  4780. paths.forEach(function (path) {
  4781. return _this13.$assertPopulated(path);
  4782. });
  4783. return this;
  4784. }
  4785. if (!this.$populated(paths)) {
  4786. throw new MongooseError("Expected path \"".concat(paths, "\" to be populated"));
  4787. }
  4788. return this;
  4789. };
  4790. /**
  4791. * Takes a populated field and returns it to its unpopulated state.
  4792. *
  4793. * #### Example:
  4794. *
  4795. * Model.findOne().populate('author').exec(function (err, doc) {
  4796. * console.log(doc.author.name); // Dr.Seuss
  4797. * console.log(doc.depopulate('author'));
  4798. * console.log(doc.author); // '5144cf8050f071d979c118a7'
  4799. * })
  4800. *
  4801. * If the path was not provided, then all populated fields are returned to their unpopulated state.
  4802. *
  4803. * @param {String} path
  4804. * @return {Document} this
  4805. * @see Document.populate #document_Document-populate
  4806. * @api public
  4807. * @memberOf Document
  4808. * @instance
  4809. */
  4810. Document.prototype.depopulate = function (path) {
  4811. if (typeof path === 'string') {
  4812. path = path.indexOf(' ') === -1 ? [path] : path.split(' ');
  4813. }
  4814. var populatedIds;
  4815. var virtualKeys = this.$$populatedVirtuals ? Object.keys(this.$$populatedVirtuals) : [];
  4816. var populated = this.$__ && this.$__.populated || {};
  4817. if (arguments.length === 0) {
  4818. // Depopulate all
  4819. var _iterator25 = _createForOfIteratorHelper(virtualKeys),
  4820. _step25;
  4821. try {
  4822. for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
  4823. var virtualKey = _step25.value;
  4824. delete this.$$populatedVirtuals[virtualKey];
  4825. delete this._doc[virtualKey];
  4826. delete populated[virtualKey];
  4827. }
  4828. } catch (err) {
  4829. _iterator25.e(err);
  4830. } finally {
  4831. _iterator25.f();
  4832. }
  4833. var keys = Object.keys(populated);
  4834. for (var _i31 = 0, _keys8 = keys; _i31 < _keys8.length; _i31++) {
  4835. var key = _keys8[_i31];
  4836. populatedIds = this.$populated(key);
  4837. if (!populatedIds) {
  4838. continue;
  4839. }
  4840. delete populated[key];
  4841. utils.setValue(key, populatedIds, this._doc);
  4842. }
  4843. return this;
  4844. }
  4845. var _iterator26 = _createForOfIteratorHelper(path),
  4846. _step26;
  4847. try {
  4848. for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
  4849. var singlePath = _step26.value;
  4850. populatedIds = this.$populated(singlePath);
  4851. delete populated[singlePath];
  4852. if (virtualKeys.indexOf(singlePath) !== -1) {
  4853. delete this.$$populatedVirtuals[singlePath];
  4854. delete this._doc[singlePath];
  4855. } else if (populatedIds) {
  4856. utils.setValue(singlePath, populatedIds, this._doc);
  4857. }
  4858. }
  4859. } catch (err) {
  4860. _iterator26.e(err);
  4861. } finally {
  4862. _iterator26.f();
  4863. }
  4864. return this;
  4865. };
  4866. /**
  4867. * Returns the full path to this document.
  4868. *
  4869. * @param {String} [path]
  4870. * @return {String}
  4871. * @api private
  4872. * @method $__fullPath
  4873. * @memberOf Document
  4874. * @instance
  4875. */
  4876. Document.prototype.$__fullPath = function (path) {
  4877. // overridden in SubDocuments
  4878. return path || '';
  4879. };
  4880. /**
  4881. * Returns the changes that happened to the document
  4882. * in the format that will be sent to MongoDB.
  4883. *
  4884. * #### Example:
  4885. *
  4886. * const userSchema = new Schema({
  4887. * name: String,
  4888. * age: Number,
  4889. * country: String
  4890. * });
  4891. * const User = mongoose.model('User', userSchema);
  4892. * const user = await User.create({
  4893. * name: 'Hafez',
  4894. * age: 25,
  4895. * country: 'Egypt'
  4896. * });
  4897. *
  4898. * // returns an empty object, no changes happened yet
  4899. * user.getChanges(); // { }
  4900. *
  4901. * user.country = undefined;
  4902. * user.age = 26;
  4903. *
  4904. * user.getChanges(); // { $set: { age: 26 }, { $unset: { country: 1 } } }
  4905. *
  4906. * await user.save();
  4907. *
  4908. * user.getChanges(); // { }
  4909. *
  4910. * Modifying the object that `getChanges()` returns does not affect the document's
  4911. * change tracking state. Even if you `delete user.getChanges().$set`, Mongoose
  4912. * will still send a `$set` to the server.
  4913. *
  4914. * @return {Object}
  4915. * @api public
  4916. * @method getChanges
  4917. * @memberOf Document
  4918. * @instance
  4919. */
  4920. Document.prototype.getChanges = function () {
  4921. var delta = this.$__delta();
  4922. var changes = delta ? delta[1] : {};
  4923. return changes;
  4924. };
  4925. /*!
  4926. * Module exports.
  4927. */
  4928. Document.ValidationError = ValidationError;
  4929. module.exports = exports = Document;
  4930. /***/ }),
  4931. /***/ 4304:
  4932. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  4933. "use strict";
  4934. /* eslint-env browser */
  4935. /*!
  4936. * Module dependencies.
  4937. */
  4938. var Document = __webpack_require__(8727);
  4939. var BrowserDocument = __webpack_require__(3434);
  4940. var isBrowser = false;
  4941. /**
  4942. * Returns the Document constructor for the current context
  4943. *
  4944. * @api private
  4945. */
  4946. module.exports = function () {
  4947. if (isBrowser) {
  4948. return BrowserDocument;
  4949. }
  4950. return Document;
  4951. };
  4952. /*!
  4953. * ignore
  4954. */
  4955. module.exports.setBrowser = function (flag) {
  4956. isBrowser = flag;
  4957. };
  4958. /***/ }),
  4959. /***/ 9906:
  4960. /***/ ((module) => {
  4961. "use strict";
  4962. /*!
  4963. * ignore
  4964. */
  4965. var driver = null;
  4966. module.exports.get = function () {
  4967. return driver;
  4968. };
  4969. module.exports.set = function (v) {
  4970. driver = v;
  4971. };
  4972. /***/ }),
  4973. /***/ 5427:
  4974. /***/ ((module) => {
  4975. "use strict";
  4976. /*!
  4977. * ignore
  4978. */
  4979. module.exports = function () {};
  4980. /***/ }),
  4981. /***/ 655:
  4982. /***/ ((module, exports, __webpack_require__) => {
  4983. "use strict";
  4984. /*!
  4985. * Module dependencies.
  4986. */
  4987. var Binary = (__webpack_require__(3873)/* .Binary */ .Kb);
  4988. /*!
  4989. * Module exports.
  4990. */
  4991. module.exports = exports = Binary;
  4992. /***/ }),
  4993. /***/ 4267:
  4994. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  4995. "use strict";
  4996. /*!
  4997. * ignore
  4998. */
  4999. module.exports = __webpack_require__(3873).Decimal128;
  5000. /***/ }),
  5001. /***/ 6333:
  5002. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  5003. "use strict";
  5004. /*!
  5005. * Module exports.
  5006. */
  5007. exports.Binary = __webpack_require__(655);
  5008. exports.Collection = function () {
  5009. throw new Error('Cannot create a collection from browser library');
  5010. };
  5011. exports.getConnection = function () {
  5012. return function () {
  5013. throw new Error('Cannot create a connection from browser library');
  5014. };
  5015. };
  5016. exports.Decimal128 = __webpack_require__(4267);
  5017. exports.ObjectId = __webpack_require__(7906);
  5018. exports.ReadPreference = __webpack_require__(5427);
  5019. /***/ }),
  5020. /***/ 7906:
  5021. /***/ ((module, exports, __webpack_require__) => {
  5022. "use strict";
  5023. /*!
  5024. * [node-mongodb-native](https://github.com/mongodb/node-mongodb-native) ObjectId
  5025. * @constructor NodeMongoDbObjectId
  5026. * @see ObjectId
  5027. */
  5028. var ObjectId = (__webpack_require__(3873)/* .ObjectID */ .t4);
  5029. /*!
  5030. * Getter for convenience with populate, see gh-6115
  5031. */
  5032. Object.defineProperty(ObjectId.prototype, '_id', {
  5033. enumerable: false,
  5034. configurable: true,
  5035. get: function get() {
  5036. return this;
  5037. }
  5038. });
  5039. /*!
  5040. * ignore
  5041. */
  5042. module.exports = exports = ObjectId;
  5043. /***/ }),
  5044. /***/ 1795:
  5045. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5046. "use strict";
  5047. /*!
  5048. * Module dependencies.
  5049. */
  5050. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5051. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5052. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5053. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5054. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5055. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5056. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5057. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5058. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5059. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5060. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5061. var MongooseError = __webpack_require__(5202);
  5062. var util = __webpack_require__(161);
  5063. /**
  5064. * Casting Error constructor.
  5065. *
  5066. * @param {String} type
  5067. * @param {String} value
  5068. * @inherits MongooseError
  5069. * @api private
  5070. */
  5071. var CastError = /*#__PURE__*/function (_MongooseError) {
  5072. _inherits(CastError, _MongooseError);
  5073. var _super = _createSuper(CastError);
  5074. function CastError(type, value, path, reason, schemaType) {
  5075. var _this;
  5076. _classCallCheck(this, CastError);
  5077. // If no args, assume we'll `init()` later.
  5078. if (arguments.length > 0) {
  5079. var stringValue = getStringValue(value);
  5080. var valueType = getValueType(value);
  5081. var messageFormat = getMessageFormat(schemaType);
  5082. var msg = formatMessage(null, type, stringValue, path, messageFormat, valueType, reason);
  5083. _this = _super.call(this, msg);
  5084. _this.init(type, value, path, reason, schemaType);
  5085. } else {
  5086. _this = _super.call(this, formatMessage());
  5087. }
  5088. return _possibleConstructorReturn(_this);
  5089. }
  5090. _createClass(CastError, [{
  5091. key: "toJSON",
  5092. value: function toJSON() {
  5093. return {
  5094. stringValue: this.stringValue,
  5095. valueType: this.valueType,
  5096. kind: this.kind,
  5097. value: this.value,
  5098. path: this.path,
  5099. reason: this.reason,
  5100. name: this.name,
  5101. message: this.message
  5102. };
  5103. }
  5104. /*!
  5105. * ignore
  5106. */
  5107. }, {
  5108. key: "init",
  5109. value: function init(type, value, path, reason, schemaType) {
  5110. this.stringValue = getStringValue(value);
  5111. this.messageFormat = getMessageFormat(schemaType);
  5112. this.kind = type;
  5113. this.value = value;
  5114. this.path = path;
  5115. this.reason = reason;
  5116. this.valueType = getValueType(value);
  5117. }
  5118. /*!
  5119. * ignore
  5120. * @param {Readonly<CastError>} other
  5121. */
  5122. }, {
  5123. key: "copy",
  5124. value: function copy(other) {
  5125. this.messageFormat = other.messageFormat;
  5126. this.stringValue = other.stringValue;
  5127. this.kind = other.kind;
  5128. this.value = other.value;
  5129. this.path = other.path;
  5130. this.reason = other.reason;
  5131. this.message = other.message;
  5132. this.valueType = other.valueType;
  5133. }
  5134. /*!
  5135. * ignore
  5136. */
  5137. }, {
  5138. key: "setModel",
  5139. value: function setModel(model) {
  5140. this.model = model;
  5141. this.message = formatMessage(model, this.kind, this.stringValue, this.path, this.messageFormat, this.valueType);
  5142. }
  5143. }]);
  5144. return CastError;
  5145. }(MongooseError);
  5146. Object.defineProperty(CastError.prototype, 'name', {
  5147. value: 'CastError'
  5148. });
  5149. function getStringValue(value) {
  5150. var stringValue = util.inspect(value);
  5151. stringValue = stringValue.replace(/^'|'$/g, '"');
  5152. if (!stringValue.startsWith('"')) {
  5153. stringValue = '"' + stringValue + '"';
  5154. }
  5155. return stringValue;
  5156. }
  5157. function getValueType(value) {
  5158. if (value == null) {
  5159. return '' + value;
  5160. }
  5161. var t = _typeof(value);
  5162. if (t !== 'object') {
  5163. return t;
  5164. }
  5165. if (typeof value.constructor !== 'function') {
  5166. return t;
  5167. }
  5168. return value.constructor.name;
  5169. }
  5170. function getMessageFormat(schemaType) {
  5171. var messageFormat = schemaType && schemaType.options && schemaType.options.cast || null;
  5172. if (typeof messageFormat === 'string') {
  5173. return messageFormat;
  5174. }
  5175. }
  5176. /*!
  5177. * ignore
  5178. */
  5179. function formatMessage(model, kind, stringValue, path, messageFormat, valueType, reason) {
  5180. if (messageFormat != null) {
  5181. var ret = messageFormat.replace('{KIND}', kind).replace('{VALUE}', stringValue).replace('{PATH}', path);
  5182. if (model != null) {
  5183. ret = ret.replace('{MODEL}', model.modelName);
  5184. }
  5185. return ret;
  5186. } else {
  5187. var valueTypeMsg = valueType ? ' (type ' + valueType + ')' : '';
  5188. var _ret = 'Cast to ' + kind + ' failed for value ' + stringValue + valueTypeMsg + ' at path "' + path + '"';
  5189. if (model != null) {
  5190. _ret += ' for model "' + model.modelName + '"';
  5191. }
  5192. if (reason != null && typeof reason.constructor === 'function' && reason.constructor.name !== 'AssertionError' && reason.constructor.name !== 'Error') {
  5193. _ret += ' because of "' + reason.constructor.name + '"';
  5194. }
  5195. return _ret;
  5196. }
  5197. }
  5198. /*!
  5199. * exports
  5200. */
  5201. module.exports = CastError;
  5202. /***/ }),
  5203. /***/ 6067:
  5204. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5205. "use strict";
  5206. /*!
  5207. * Module dependencies.
  5208. */
  5209. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5210. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5211. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5212. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5213. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5214. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5215. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5216. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5217. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5218. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5219. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5220. var MongooseError = __webpack_require__(4888);
  5221. var DivergentArrayError = /*#__PURE__*/function (_MongooseError) {
  5222. _inherits(DivergentArrayError, _MongooseError);
  5223. var _super = _createSuper(DivergentArrayError);
  5224. /*!
  5225. * DivergentArrayError constructor.
  5226. * @param {Array<String>} paths
  5227. */
  5228. function DivergentArrayError(paths) {
  5229. _classCallCheck(this, DivergentArrayError);
  5230. var msg = 'For your own good, using `document.save()` to update an array ' + 'which was selected using an $elemMatch projection OR ' + 'populated using skip, limit, query conditions, or exclusion of ' + 'the _id field when the operation results in a $pop or $set of ' + 'the entire array is not supported. The following ' + 'path(s) would have been modified unsafely:\n' + ' ' + paths.join('\n ') + '\n' + 'Use Model.update() to update these arrays instead.'; // TODO write up a docs page (FAQ) and link to it
  5231. return _super.call(this, msg);
  5232. }
  5233. return _createClass(DivergentArrayError);
  5234. }(MongooseError);
  5235. Object.defineProperty(DivergentArrayError.prototype, 'name', {
  5236. value: 'DivergentArrayError'
  5237. });
  5238. /*!
  5239. * exports
  5240. */
  5241. module.exports = DivergentArrayError;
  5242. /***/ }),
  5243. /***/ 4888:
  5244. /***/ ((module, exports, __webpack_require__) => {
  5245. "use strict";
  5246. /**
  5247. * MongooseError constructor. MongooseError is the base class for all
  5248. * Mongoose-specific errors.
  5249. *
  5250. * #### Example:
  5251. * const Model = mongoose.model('Test', new mongoose.Schema({ answer: Number }));
  5252. * const doc = new Model({ answer: 'not a number' });
  5253. * const err = doc.validateSync();
  5254. *
  5255. * err instanceof mongoose.Error.ValidationError; // true
  5256. *
  5257. * @constructor Error
  5258. * @param {String} msg Error message
  5259. * @inherits Error https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error
  5260. */
  5261. var MongooseError = __webpack_require__(5202);
  5262. /**
  5263. * The name of the error. The name uniquely identifies this Mongoose error. The
  5264. * possible values are:
  5265. *
  5266. * - `MongooseError`: general Mongoose error
  5267. * - `CastError`: Mongoose could not convert a value to the type defined in the schema path. May be in a `ValidationError` class' `errors` property.
  5268. * - `DisconnectedError`: This [connection](connections.html) timed out in trying to reconnect to MongoDB and will not successfully reconnect to MongoDB unless you explicitly reconnect.
  5269. * - `DivergentArrayError`: You attempted to `save()` an array that was modified after you loaded it with a `$elemMatch` or similar projection
  5270. * - `MissingSchemaError`: You tried to access a model with [`mongoose.model()`](api.html#mongoose_Mongoose-model) that was not defined
  5271. * - `DocumentNotFoundError`: The document you tried to [`save()`](api.html#document_Document-save) was not found
  5272. * - `ValidatorError`: error from an individual schema path's validator
  5273. * - `ValidationError`: error returned from [`validate()`](api.html#document_Document-validate) or [`validateSync()`](api.html#document_Document-validateSync). Contains zero or more `ValidatorError` instances in `.errors` property.
  5274. * - `MissingSchemaError`: You called `mongoose.Document()` without a schema
  5275. * - `ObjectExpectedError`: Thrown when you set a nested path to a non-object value with [strict mode set](guide.html#strict).
  5276. * - `ObjectParameterError`: Thrown when you pass a non-object value to a function which expects an object as a paramter
  5277. * - `OverwriteModelError`: Thrown when you call [`mongoose.model()`](api.html#mongoose_Mongoose-model) to re-define a model that was already defined.
  5278. * - `ParallelSaveError`: Thrown when you call [`save()`](api.html#model_Model-save) on a document when the same document instance is already saving.
  5279. * - `StrictModeError`: Thrown when you set a path that isn't the schema and [strict mode](guide.html#strict) is set to `throw`.
  5280. * - `VersionError`: Thrown when the [document is out of sync](guide.html#versionKey)
  5281. *
  5282. * @api public
  5283. * @property {String} name
  5284. * @memberOf Error
  5285. * @instance
  5286. */
  5287. /*!
  5288. * Module exports.
  5289. */
  5290. module.exports = exports = MongooseError;
  5291. /**
  5292. * The default built-in validator error messages.
  5293. *
  5294. * @see Error.messages #error_messages_MongooseError-messages
  5295. * @api public
  5296. * @memberOf Error
  5297. * @static messages
  5298. */
  5299. MongooseError.messages = __webpack_require__(983); // backward compat
  5300. MongooseError.Messages = MongooseError.messages;
  5301. /**
  5302. * An instance of this error class will be returned when `save()` fails
  5303. * because the underlying
  5304. * document was not found. The constructor takes one parameter, the
  5305. * conditions that mongoose passed to `update()` when trying to update
  5306. * the document.
  5307. *
  5308. * @api public
  5309. * @memberOf Error
  5310. * @static DocumentNotFoundError
  5311. */
  5312. MongooseError.DocumentNotFoundError = __webpack_require__(3640);
  5313. /**
  5314. * An instance of this error class will be returned when mongoose failed to
  5315. * cast a value.
  5316. *
  5317. * @api public
  5318. * @memberOf Error
  5319. * @static CastError
  5320. */
  5321. MongooseError.CastError = __webpack_require__(1795);
  5322. /**
  5323. * An instance of this error class will be returned when [validation](/docs/validation.html) failed.
  5324. * The `errors` property contains an object whose keys are the paths that failed and whose values are
  5325. * instances of CastError or ValidationError.
  5326. *
  5327. * @api public
  5328. * @memberOf Error
  5329. * @static ValidationError
  5330. */
  5331. MongooseError.ValidationError = __webpack_require__(122);
  5332. /**
  5333. * A `ValidationError` has a hash of `errors` that contain individual
  5334. * `ValidatorError` instances.
  5335. *
  5336. * #### Example:
  5337. *
  5338. * const schema = Schema({ name: { type: String, required: true } });
  5339. * const Model = mongoose.model('Test', schema);
  5340. * const doc = new Model({});
  5341. *
  5342. * // Top-level error is a ValidationError, **not** a ValidatorError
  5343. * const err = doc.validateSync();
  5344. * err instanceof mongoose.Error.ValidationError; // true
  5345. *
  5346. * // A ValidationError `err` has 0 or more ValidatorErrors keyed by the
  5347. * // path in the `err.errors` property.
  5348. * err.errors['name'] instanceof mongoose.Error.ValidatorError;
  5349. *
  5350. * err.errors['name'].kind; // 'required'
  5351. * err.errors['name'].path; // 'name'
  5352. * err.errors['name'].value; // undefined
  5353. *
  5354. * Instances of `ValidatorError` have the following properties:
  5355. *
  5356. * - `kind`: The validator's `type`, like `'required'` or `'regexp'`
  5357. * - `path`: The path that failed validation
  5358. * - `value`: The value that failed validation
  5359. *
  5360. * @api public
  5361. * @memberOf Error
  5362. * @static ValidatorError
  5363. */
  5364. MongooseError.ValidatorError = __webpack_require__(2037);
  5365. /**
  5366. * An instance of this error class will be returned when you call `save()` after
  5367. * the document in the database was changed in a potentially unsafe way. See
  5368. * the [`versionKey` option](/docs/guide.html#versionKey) for more information.
  5369. *
  5370. * @api public
  5371. * @memberOf Error
  5372. * @static VersionError
  5373. */
  5374. MongooseError.VersionError = __webpack_require__(8809);
  5375. /**
  5376. * An instance of this error class will be returned when you call `save()` multiple
  5377. * times on the same document in parallel. See the [FAQ](/docs/faq.html) for more
  5378. * information.
  5379. *
  5380. * @api public
  5381. * @memberOf Error
  5382. * @static ParallelSaveError
  5383. */
  5384. MongooseError.ParallelSaveError = __webpack_require__(5007);
  5385. /**
  5386. * Thrown when a model with the given name was already registered on the connection.
  5387. * See [the FAQ about `OverwriteModelError`](/docs/faq.html#overwrite-model-error).
  5388. *
  5389. * @api public
  5390. * @memberOf Error
  5391. * @static OverwriteModelError
  5392. */
  5393. MongooseError.OverwriteModelError = __webpack_require__(5676);
  5394. /**
  5395. * Thrown when you try to access a model that has not been registered yet
  5396. *
  5397. * @api public
  5398. * @memberOf Error
  5399. * @static MissingSchemaError
  5400. */
  5401. MongooseError.MissingSchemaError = __webpack_require__(1511);
  5402. /**
  5403. * Thrown when the MongoDB Node driver can't connect to a valid server
  5404. * to send an operation to.
  5405. *
  5406. * @api public
  5407. * @memberOf Error
  5408. * @static MongooseServerSelectionError
  5409. */
  5410. MongooseError.MongooseServerSelectionError = __webpack_require__(1870);
  5411. /**
  5412. * An instance of this error will be returned if you used an array projection
  5413. * and then modified the array in an unsafe way.
  5414. *
  5415. * @api public
  5416. * @memberOf Error
  5417. * @static DivergentArrayError
  5418. */
  5419. MongooseError.DivergentArrayError = __webpack_require__(6067);
  5420. /**
  5421. * Thrown when your try to pass values to model contrtuctor that
  5422. * were not specified in schema or change immutable properties when
  5423. * `strict` mode is `"throw"`
  5424. *
  5425. * @api public
  5426. * @memberOf Error
  5427. * @static StrictModeError
  5428. */
  5429. MongooseError.StrictModeError = __webpack_require__(3328);
  5430. /***/ }),
  5431. /***/ 983:
  5432. /***/ ((module, exports) => {
  5433. "use strict";
  5434. /**
  5435. * The default built-in validator error messages. These may be customized.
  5436. *
  5437. * // customize within each schema or globally like so
  5438. * const mongoose = require('mongoose');
  5439. * mongoose.Error.messages.String.enum = "Your custom message for {PATH}.";
  5440. *
  5441. * As you might have noticed, error messages support basic templating
  5442. *
  5443. * - `{PATH}` is replaced with the invalid document path
  5444. * - `{VALUE}` is replaced with the invalid value
  5445. * - `{TYPE}` is replaced with the validator type such as "regexp", "min", or "user defined"
  5446. * - `{MIN}` is replaced with the declared min value for the Number.min validator
  5447. * - `{MAX}` is replaced with the declared max value for the Number.max validator
  5448. *
  5449. * Click the "show code" link below to see all defaults.
  5450. *
  5451. * @static messages
  5452. * @receiver MongooseError
  5453. * @api public
  5454. */
  5455. var msg = module.exports = exports = {};
  5456. msg.DocumentNotFoundError = null;
  5457. msg.general = {};
  5458. msg.general["default"] = 'Validator failed for path `{PATH}` with value `{VALUE}`';
  5459. msg.general.required = 'Path `{PATH}` is required.';
  5460. msg.Number = {};
  5461. msg.Number.min = 'Path `{PATH}` ({VALUE}) is less than minimum allowed value ({MIN}).';
  5462. msg.Number.max = 'Path `{PATH}` ({VALUE}) is more than maximum allowed value ({MAX}).';
  5463. msg.Number["enum"] = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
  5464. msg.Date = {};
  5465. msg.Date.min = 'Path `{PATH}` ({VALUE}) is before minimum allowed value ({MIN}).';
  5466. msg.Date.max = 'Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).';
  5467. msg.String = {};
  5468. msg.String["enum"] = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
  5469. msg.String.match = 'Path `{PATH}` is invalid ({VALUE}).';
  5470. msg.String.minlength = 'Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).';
  5471. msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH}).';
  5472. /***/ }),
  5473. /***/ 1511:
  5474. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5475. "use strict";
  5476. /*!
  5477. * Module dependencies.
  5478. */
  5479. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5480. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5481. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5482. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5483. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5484. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5485. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5486. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5487. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5488. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5489. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5490. var MongooseError = __webpack_require__(4888);
  5491. var MissingSchemaError = /*#__PURE__*/function (_MongooseError) {
  5492. _inherits(MissingSchemaError, _MongooseError);
  5493. var _super = _createSuper(MissingSchemaError);
  5494. /*!
  5495. * MissingSchema Error constructor.
  5496. * @param {String} name
  5497. */
  5498. function MissingSchemaError(name) {
  5499. _classCallCheck(this, MissingSchemaError);
  5500. var msg = 'Schema hasn\'t been registered for model "' + name + '".\n' + 'Use mongoose.model(name, schema)';
  5501. return _super.call(this, msg);
  5502. }
  5503. return _createClass(MissingSchemaError);
  5504. }(MongooseError);
  5505. Object.defineProperty(MissingSchemaError.prototype, 'name', {
  5506. value: 'MissingSchemaError'
  5507. });
  5508. /*!
  5509. * exports
  5510. */
  5511. module.exports = MissingSchemaError;
  5512. /***/ }),
  5513. /***/ 5202:
  5514. /***/ ((module) => {
  5515. "use strict";
  5516. /*!
  5517. * ignore
  5518. */
  5519. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5520. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5521. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5522. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5523. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5524. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5525. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5526. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5527. function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
  5528. function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  5529. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5530. function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  5531. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5532. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5533. var MongooseError = /*#__PURE__*/function (_Error) {
  5534. _inherits(MongooseError, _Error);
  5535. var _super = _createSuper(MongooseError);
  5536. function MongooseError() {
  5537. _classCallCheck(this, MongooseError);
  5538. return _super.apply(this, arguments);
  5539. }
  5540. return _createClass(MongooseError);
  5541. }( /*#__PURE__*/_wrapNativeSuper(Error));
  5542. Object.defineProperty(MongooseError.prototype, 'name', {
  5543. value: 'MongooseError'
  5544. });
  5545. module.exports = MongooseError;
  5546. /***/ }),
  5547. /***/ 3640:
  5548. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5549. "use strict";
  5550. /*!
  5551. * Module dependencies.
  5552. */
  5553. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5554. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5555. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5556. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5557. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5558. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5559. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5560. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5561. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5562. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5563. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5564. var MongooseError = __webpack_require__(4888);
  5565. var util = __webpack_require__(161);
  5566. var DocumentNotFoundError = /*#__PURE__*/function (_MongooseError) {
  5567. _inherits(DocumentNotFoundError, _MongooseError);
  5568. var _super = _createSuper(DocumentNotFoundError);
  5569. /*!
  5570. * OverwriteModel Error constructor.
  5571. */
  5572. function DocumentNotFoundError(filter, model, numAffected, result) {
  5573. var _this;
  5574. _classCallCheck(this, DocumentNotFoundError);
  5575. var msg;
  5576. var messages = MongooseError.messages;
  5577. if (messages.DocumentNotFoundError != null) {
  5578. msg = typeof messages.DocumentNotFoundError === 'function' ? messages.DocumentNotFoundError(filter, model) : messages.DocumentNotFoundError;
  5579. } else {
  5580. msg = 'No document found for query "' + util.inspect(filter) + '" on model "' + model + '"';
  5581. }
  5582. _this = _super.call(this, msg);
  5583. _this.result = result;
  5584. _this.numAffected = numAffected;
  5585. _this.filter = filter; // Backwards compat
  5586. _this.query = filter;
  5587. return _this;
  5588. }
  5589. return _createClass(DocumentNotFoundError);
  5590. }(MongooseError);
  5591. Object.defineProperty(DocumentNotFoundError.prototype, 'name', {
  5592. value: 'DocumentNotFoundError'
  5593. });
  5594. /*!
  5595. * exports
  5596. */
  5597. module.exports = DocumentNotFoundError;
  5598. /***/ }),
  5599. /***/ 4107:
  5600. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5601. "use strict";
  5602. /*!
  5603. * Module dependencies.
  5604. */
  5605. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5606. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5607. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5608. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5609. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5610. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5611. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5612. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5613. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5614. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5615. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5616. var MongooseError = __webpack_require__(4888);
  5617. var ObjectExpectedError = /*#__PURE__*/function (_MongooseError) {
  5618. _inherits(ObjectExpectedError, _MongooseError);
  5619. var _super = _createSuper(ObjectExpectedError);
  5620. /**
  5621. * Strict mode error constructor
  5622. *
  5623. * @param {string} type
  5624. * @param {string} value
  5625. * @api private
  5626. */
  5627. function ObjectExpectedError(path, val) {
  5628. var _this;
  5629. _classCallCheck(this, ObjectExpectedError);
  5630. var typeDescription = Array.isArray(val) ? 'array' : 'primitive value';
  5631. _this = _super.call(this, 'Tried to set nested object field `' + path + "` to ".concat(typeDescription, " `") + val + '`');
  5632. _this.path = path;
  5633. return _this;
  5634. }
  5635. return _createClass(ObjectExpectedError);
  5636. }(MongooseError);
  5637. Object.defineProperty(ObjectExpectedError.prototype, 'name', {
  5638. value: 'ObjectExpectedError'
  5639. });
  5640. module.exports = ObjectExpectedError;
  5641. /***/ }),
  5642. /***/ 900:
  5643. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5644. "use strict";
  5645. /*!
  5646. * Module dependencies.
  5647. */
  5648. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5649. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5650. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5651. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5652. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5653. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5654. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5655. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5656. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5657. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5658. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5659. var MongooseError = __webpack_require__(4888);
  5660. var ObjectParameterError = /*#__PURE__*/function (_MongooseError) {
  5661. _inherits(ObjectParameterError, _MongooseError);
  5662. var _super = _createSuper(ObjectParameterError);
  5663. /**
  5664. * Constructor for errors that happen when a parameter that's expected to be
  5665. * an object isn't an object
  5666. *
  5667. * @param {Any} value
  5668. * @param {String} paramName
  5669. * @param {String} fnName
  5670. * @api private
  5671. */
  5672. function ObjectParameterError(value, paramName, fnName) {
  5673. _classCallCheck(this, ObjectParameterError);
  5674. return _super.call(this, 'Parameter "' + paramName + '" to ' + fnName + '() must be an object, got ' + value.toString());
  5675. }
  5676. return _createClass(ObjectParameterError);
  5677. }(MongooseError);
  5678. Object.defineProperty(ObjectParameterError.prototype, 'name', {
  5679. value: 'ObjectParameterError'
  5680. });
  5681. module.exports = ObjectParameterError;
  5682. /***/ }),
  5683. /***/ 5676:
  5684. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5685. "use strict";
  5686. /*!
  5687. * Module dependencies.
  5688. */
  5689. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5690. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5691. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5692. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5693. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5694. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5695. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5696. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5697. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5698. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5699. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5700. var MongooseError = __webpack_require__(4888);
  5701. var OverwriteModelError = /*#__PURE__*/function (_MongooseError) {
  5702. _inherits(OverwriteModelError, _MongooseError);
  5703. var _super = _createSuper(OverwriteModelError);
  5704. /*!
  5705. * OverwriteModel Error constructor.
  5706. * @param {String} name
  5707. */
  5708. function OverwriteModelError(name) {
  5709. _classCallCheck(this, OverwriteModelError);
  5710. return _super.call(this, 'Cannot overwrite `' + name + '` model once compiled.');
  5711. }
  5712. return _createClass(OverwriteModelError);
  5713. }(MongooseError);
  5714. Object.defineProperty(OverwriteModelError.prototype, 'name', {
  5715. value: 'OverwriteModelError'
  5716. });
  5717. /*!
  5718. * exports
  5719. */
  5720. module.exports = OverwriteModelError;
  5721. /***/ }),
  5722. /***/ 5007:
  5723. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5724. "use strict";
  5725. /*!
  5726. * Module dependencies.
  5727. */
  5728. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5729. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5730. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5731. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5732. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5733. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5734. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5735. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5736. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5737. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5738. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5739. var MongooseError = __webpack_require__(4888);
  5740. var ParallelSaveError = /*#__PURE__*/function (_MongooseError) {
  5741. _inherits(ParallelSaveError, _MongooseError);
  5742. var _super = _createSuper(ParallelSaveError);
  5743. /**
  5744. * ParallelSave Error constructor.
  5745. *
  5746. * @param {Document} doc
  5747. * @api private
  5748. */
  5749. function ParallelSaveError(doc) {
  5750. _classCallCheck(this, ParallelSaveError);
  5751. var msg = 'Can\'t save() the same doc multiple times in parallel. Document: ';
  5752. return _super.call(this, msg + doc._id);
  5753. }
  5754. return _createClass(ParallelSaveError);
  5755. }(MongooseError);
  5756. Object.defineProperty(ParallelSaveError.prototype, 'name', {
  5757. value: 'ParallelSaveError'
  5758. });
  5759. /*!
  5760. * exports
  5761. */
  5762. module.exports = ParallelSaveError;
  5763. /***/ }),
  5764. /***/ 7962:
  5765. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5766. "use strict";
  5767. /*!
  5768. * Module dependencies.
  5769. */
  5770. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5771. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5772. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5773. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5774. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5775. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5776. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5777. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5778. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5779. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5780. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5781. var MongooseError = __webpack_require__(5202);
  5782. var ParallelValidateError = /*#__PURE__*/function (_MongooseError) {
  5783. _inherits(ParallelValidateError, _MongooseError);
  5784. var _super = _createSuper(ParallelValidateError);
  5785. /**
  5786. * ParallelValidate Error constructor.
  5787. *
  5788. * @param {Document} doc
  5789. * @api private
  5790. */
  5791. function ParallelValidateError(doc) {
  5792. _classCallCheck(this, ParallelValidateError);
  5793. var msg = 'Can\'t validate() the same doc multiple times in parallel. Document: ';
  5794. return _super.call(this, msg + doc._id);
  5795. }
  5796. return _createClass(ParallelValidateError);
  5797. }(MongooseError);
  5798. Object.defineProperty(ParallelValidateError.prototype, 'name', {
  5799. value: 'ParallelValidateError'
  5800. });
  5801. /*!
  5802. * exports
  5803. */
  5804. module.exports = ParallelValidateError;
  5805. /***/ }),
  5806. /***/ 1870:
  5807. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5808. "use strict";
  5809. /*!
  5810. * Module dependencies.
  5811. */
  5812. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5813. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5814. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5815. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5816. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5817. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5818. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5819. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5820. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5821. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5822. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5823. var MongooseError = __webpack_require__(5202);
  5824. var allServersUnknown = __webpack_require__(5285);
  5825. var isAtlas = __webpack_require__(2082);
  5826. var isSSLError = __webpack_require__(3871);
  5827. /*!
  5828. * ignore
  5829. */
  5830. var atlasMessage = 'Could not connect to any servers in your MongoDB Atlas cluster. ' + 'One common reason is that you\'re trying to access the database from ' + 'an IP that isn\'t whitelisted. Make sure your current IP address is on your Atlas ' + 'cluster\'s IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/';
  5831. var sslMessage = 'Mongoose is connecting with SSL enabled, but the server is ' + 'not accepting SSL connections. Please ensure that the MongoDB server you are ' + 'connecting to is configured to accept SSL connections. Learn more: ' + 'https://mongoosejs.com/docs/tutorials/ssl.html';
  5832. var MongooseServerSelectionError = /*#__PURE__*/function (_MongooseError) {
  5833. _inherits(MongooseServerSelectionError, _MongooseError);
  5834. var _super = _createSuper(MongooseServerSelectionError);
  5835. function MongooseServerSelectionError() {
  5836. _classCallCheck(this, MongooseServerSelectionError);
  5837. return _super.apply(this, arguments);
  5838. }
  5839. _createClass(MongooseServerSelectionError, [{
  5840. key: "assimilateError",
  5841. value:
  5842. /**
  5843. * MongooseServerSelectionError constructor
  5844. *
  5845. * @api private
  5846. */
  5847. function assimilateError(err) {
  5848. var reason = err.reason; // Special message for a case that is likely due to IP whitelisting issues.
  5849. var isAtlasWhitelistError = isAtlas(reason) && allServersUnknown(reason) && err.message.indexOf('bad auth') === -1 && err.message.indexOf('Authentication failed') === -1;
  5850. if (isAtlasWhitelistError) {
  5851. this.message = atlasMessage;
  5852. } else if (isSSLError(reason)) {
  5853. this.message = sslMessage;
  5854. } else {
  5855. this.message = err.message;
  5856. }
  5857. for (var key in err) {
  5858. if (key !== 'name') {
  5859. this[key] = err[key];
  5860. }
  5861. }
  5862. return this;
  5863. }
  5864. }]);
  5865. return MongooseServerSelectionError;
  5866. }(MongooseError);
  5867. Object.defineProperty(MongooseServerSelectionError.prototype, 'name', {
  5868. value: 'MongooseServerSelectionError'
  5869. });
  5870. module.exports = MongooseServerSelectionError;
  5871. /***/ }),
  5872. /***/ 3328:
  5873. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5874. "use strict";
  5875. /*!
  5876. * Module dependencies.
  5877. */
  5878. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5879. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5880. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5881. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5882. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5883. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5884. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5885. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5886. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5887. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5888. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5889. var MongooseError = __webpack_require__(4888);
  5890. var StrictModeError = /*#__PURE__*/function (_MongooseError) {
  5891. _inherits(StrictModeError, _MongooseError);
  5892. var _super = _createSuper(StrictModeError);
  5893. /**
  5894. * Strict mode error constructor
  5895. *
  5896. * @param {String} path
  5897. * @param {String} [msg]
  5898. * @param {Boolean} [immutable]
  5899. * @inherits MongooseError
  5900. * @api private
  5901. */
  5902. function StrictModeError(path, msg, immutable) {
  5903. var _this;
  5904. _classCallCheck(this, StrictModeError);
  5905. msg = msg || 'Field `' + path + '` is not in schema and strict ' + 'mode is set to throw.';
  5906. _this = _super.call(this, msg);
  5907. _this.isImmutableError = !!immutable;
  5908. _this.path = path;
  5909. return _this;
  5910. }
  5911. return _createClass(StrictModeError);
  5912. }(MongooseError);
  5913. Object.defineProperty(StrictModeError.prototype, 'name', {
  5914. value: 'StrictModeError'
  5915. });
  5916. module.exports = StrictModeError;
  5917. /***/ }),
  5918. /***/ 122:
  5919. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  5920. "use strict";
  5921. /*!
  5922. * Module requirements
  5923. */
  5924. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  5925. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  5926. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5927. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  5928. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  5929. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  5930. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  5931. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  5932. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  5933. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  5934. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  5935. var MongooseError = __webpack_require__(5202);
  5936. var getConstructorName = __webpack_require__(1981);
  5937. var util = __webpack_require__(161);
  5938. var ValidationError = /*#__PURE__*/function (_MongooseError) {
  5939. _inherits(ValidationError, _MongooseError);
  5940. var _super = _createSuper(ValidationError);
  5941. /**
  5942. * Document Validation Error
  5943. *
  5944. * @api private
  5945. * @param {Document} [instance]
  5946. * @inherits MongooseError
  5947. */
  5948. function ValidationError(instance) {
  5949. var _this;
  5950. _classCallCheck(this, ValidationError);
  5951. var _message;
  5952. if (getConstructorName(instance) === 'model') {
  5953. _message = instance.constructor.modelName + ' validation failed';
  5954. } else {
  5955. _message = 'Validation failed';
  5956. }
  5957. _this = _super.call(this, _message);
  5958. _this.errors = {};
  5959. _this._message = _message;
  5960. if (instance) {
  5961. instance.$errors = _this.errors;
  5962. }
  5963. return _this;
  5964. }
  5965. /**
  5966. * Console.log helper
  5967. */
  5968. _createClass(ValidationError, [{
  5969. key: "toString",
  5970. value: function toString() {
  5971. return this.name + ': ' + _generateMessage(this);
  5972. }
  5973. /*!
  5974. * inspect helper
  5975. */
  5976. }, {
  5977. key: "inspect",
  5978. value: function inspect() {
  5979. return Object.assign(new Error(this.message), this);
  5980. }
  5981. /*!
  5982. * add message
  5983. */
  5984. }, {
  5985. key: "addError",
  5986. value: function addError(path, error) {
  5987. this.errors[path] = error;
  5988. this.message = this._message + ': ' + _generateMessage(this);
  5989. }
  5990. }]);
  5991. return ValidationError;
  5992. }(MongooseError);
  5993. if (util.inspect.custom) {
  5994. /*!
  5995. * Avoid Node deprecation warning DEP0079
  5996. */
  5997. ValidationError.prototype[util.inspect.custom] = ValidationError.prototype.inspect;
  5998. }
  5999. /*!
  6000. * Helper for JSON.stringify
  6001. * Ensure `name` and `message` show up in toJSON output re: gh-9847
  6002. */
  6003. Object.defineProperty(ValidationError.prototype, 'toJSON', {
  6004. enumerable: false,
  6005. writable: false,
  6006. configurable: true,
  6007. value: function value() {
  6008. return Object.assign({}, this, {
  6009. name: this.name,
  6010. message: this.message
  6011. });
  6012. }
  6013. });
  6014. Object.defineProperty(ValidationError.prototype, 'name', {
  6015. value: 'ValidationError'
  6016. });
  6017. /*!
  6018. * ignore
  6019. */
  6020. function _generateMessage(err) {
  6021. var keys = Object.keys(err.errors || {});
  6022. var len = keys.length;
  6023. var msgs = [];
  6024. var key;
  6025. for (var i = 0; i < len; ++i) {
  6026. key = keys[i];
  6027. if (err === err.errors[key]) {
  6028. continue;
  6029. }
  6030. msgs.push(key + ': ' + err.errors[key].message);
  6031. }
  6032. return msgs.join(', ');
  6033. }
  6034. /*!
  6035. * Module exports
  6036. */
  6037. module.exports = ValidationError;
  6038. /***/ }),
  6039. /***/ 2037:
  6040. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6041. "use strict";
  6042. /*!
  6043. * Module dependencies.
  6044. */
  6045. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6046. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6047. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6048. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  6049. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  6050. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6051. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6052. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  6053. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6054. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6055. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6056. var MongooseError = __webpack_require__(4888);
  6057. var ValidatorError = /*#__PURE__*/function (_MongooseError) {
  6058. _inherits(ValidatorError, _MongooseError);
  6059. var _super = _createSuper(ValidatorError);
  6060. /**
  6061. * Schema validator error
  6062. *
  6063. * @param {Object} properties
  6064. * @api private
  6065. */
  6066. function ValidatorError(properties) {
  6067. var _this;
  6068. _classCallCheck(this, ValidatorError);
  6069. var msg = properties.message;
  6070. if (!msg) {
  6071. msg = MongooseError.messages.general["default"];
  6072. }
  6073. var message = formatMessage(msg, properties);
  6074. _this = _super.call(this, message);
  6075. properties = Object.assign({}, properties, {
  6076. message: message
  6077. });
  6078. _this.properties = properties;
  6079. _this.kind = properties.type;
  6080. _this.path = properties.path;
  6081. _this.value = properties.value;
  6082. _this.reason = properties.reason;
  6083. return _this;
  6084. }
  6085. /*!
  6086. * toString helper
  6087. * TODO remove? This defaults to `${this.name}: ${this.message}`
  6088. */
  6089. _createClass(ValidatorError, [{
  6090. key: "toString",
  6091. value: function toString() {
  6092. return this.message;
  6093. }
  6094. /*!
  6095. * Ensure `name` and `message` show up in toJSON output re: gh-9296
  6096. */
  6097. }, {
  6098. key: "toJSON",
  6099. value: function toJSON() {
  6100. return Object.assign({
  6101. name: this.name,
  6102. message: this.message
  6103. }, this);
  6104. }
  6105. }]);
  6106. return ValidatorError;
  6107. }(MongooseError);
  6108. Object.defineProperty(ValidatorError.prototype, 'name', {
  6109. value: 'ValidatorError'
  6110. });
  6111. /*!
  6112. * The object used to define this validator. Not enumerable to hide
  6113. * it from `require('util').inspect()` output re: gh-3925
  6114. */
  6115. Object.defineProperty(ValidatorError.prototype, 'properties', {
  6116. enumerable: false,
  6117. writable: true,
  6118. value: null
  6119. }); // Exposed for testing
  6120. ValidatorError.prototype.formatMessage = formatMessage;
  6121. /*!
  6122. * Formats error messages
  6123. */
  6124. function formatMessage(msg, properties) {
  6125. if (typeof msg === 'function') {
  6126. return msg(properties);
  6127. }
  6128. var propertyNames = Object.keys(properties);
  6129. for (var _i = 0, _propertyNames = propertyNames; _i < _propertyNames.length; _i++) {
  6130. var propertyName = _propertyNames[_i];
  6131. if (propertyName === 'message') {
  6132. continue;
  6133. }
  6134. msg = msg.replace('{' + propertyName.toUpperCase() + '}', properties[propertyName]);
  6135. }
  6136. return msg;
  6137. }
  6138. /*!
  6139. * exports
  6140. */
  6141. module.exports = ValidatorError;
  6142. /***/ }),
  6143. /***/ 8809:
  6144. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6145. "use strict";
  6146. /*!
  6147. * Module dependencies.
  6148. */
  6149. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6150. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  6151. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  6152. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  6153. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  6154. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  6155. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6156. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  6157. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6158. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  6159. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  6160. var MongooseError = __webpack_require__(4888);
  6161. var VersionError = /*#__PURE__*/function (_MongooseError) {
  6162. _inherits(VersionError, _MongooseError);
  6163. var _super = _createSuper(VersionError);
  6164. /**
  6165. * Version Error constructor.
  6166. *
  6167. * @param {Document} doc
  6168. * @param {Number} currentVersion
  6169. * @param {Array<String>} modifiedPaths
  6170. * @api private
  6171. */
  6172. function VersionError(doc, currentVersion, modifiedPaths) {
  6173. var _this;
  6174. _classCallCheck(this, VersionError);
  6175. var modifiedPathsStr = modifiedPaths.join(', ');
  6176. _this = _super.call(this, 'No matching document found for id "' + doc._id + '" version ' + currentVersion + ' modifiedPaths "' + modifiedPathsStr + '"');
  6177. _this.version = currentVersion;
  6178. _this.modifiedPaths = modifiedPaths;
  6179. return _this;
  6180. }
  6181. return _createClass(VersionError);
  6182. }(MongooseError);
  6183. Object.defineProperty(VersionError.prototype, 'name', {
  6184. value: 'VersionError'
  6185. });
  6186. /*!
  6187. * exports
  6188. */
  6189. module.exports = VersionError;
  6190. /***/ }),
  6191. /***/ 6069:
  6192. /***/ ((module) => {
  6193. "use strict";
  6194. module.exports = arrayDepth;
  6195. function arrayDepth(arr) {
  6196. if (!Array.isArray(arr)) {
  6197. return {
  6198. min: 0,
  6199. max: 0,
  6200. containsNonArrayItem: true
  6201. };
  6202. }
  6203. if (arr.length === 0) {
  6204. return {
  6205. min: 1,
  6206. max: 1,
  6207. containsNonArrayItem: false
  6208. };
  6209. }
  6210. if (arr.length === 1 && !Array.isArray(arr[0])) {
  6211. return {
  6212. min: 1,
  6213. max: 1,
  6214. containsNonArrayItem: false
  6215. };
  6216. }
  6217. var res = arrayDepth(arr[0]);
  6218. for (var i = 1; i < arr.length; ++i) {
  6219. var _res = arrayDepth(arr[i]);
  6220. if (_res.min < res.min) {
  6221. res.min = _res.min;
  6222. }
  6223. if (_res.max > res.max) {
  6224. res.max = _res.max;
  6225. }
  6226. res.containsNonArrayItem = res.containsNonArrayItem || _res.containsNonArrayItem;
  6227. }
  6228. res.min = res.min + 1;
  6229. res.max = res.max + 1;
  6230. return res;
  6231. }
  6232. /***/ }),
  6233. /***/ 1973:
  6234. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6235. "use strict";
  6236. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6237. var Decimal = __webpack_require__(5003);
  6238. var ObjectId = __webpack_require__(6079);
  6239. var specialProperties = __webpack_require__(2862);
  6240. var isMongooseObject = __webpack_require__(6584);
  6241. var getFunctionName = __webpack_require__(6749);
  6242. var isBsonType = __webpack_require__(1563);
  6243. var isObject = __webpack_require__(5721);
  6244. var symbols = __webpack_require__(8770);
  6245. var trustedSymbol = (__webpack_require__(3636).trustedSymbol);
  6246. var utils = __webpack_require__(6872);
  6247. /*!
  6248. * Object clone with Mongoose natives support.
  6249. *
  6250. * If options.minimize is true, creates a minimal data object. Empty objects and undefined values will not be cloned. This makes the data payload sent to MongoDB as small as possible.
  6251. *
  6252. * Functions are never cloned.
  6253. *
  6254. * @param {Object} obj the object to clone
  6255. * @param {Object} options
  6256. * @param {Boolean} isArrayChild true if cloning immediately underneath an array. Special case for minimize.
  6257. * @return {Object} the cloned object
  6258. * @api private
  6259. */
  6260. function clone(obj, options, isArrayChild) {
  6261. if (obj == null) {
  6262. return obj;
  6263. }
  6264. if (Array.isArray(obj)) {
  6265. return cloneArray(utils.isMongooseArray(obj) ? obj.__array : obj, options);
  6266. }
  6267. if (isMongooseObject(obj)) {
  6268. // Single nested subdocs should apply getters later in `applyGetters()`
  6269. // when calling `toObject()`. See gh-7442, gh-8295
  6270. if (options && options._skipSingleNestedGetters && obj.$isSingleNested) {
  6271. options = Object.assign({}, options, {
  6272. getters: false
  6273. });
  6274. }
  6275. var isSingleNested = obj.$isSingleNested;
  6276. if (utils.isPOJO(obj) && obj.$__ != null && obj._doc != null) {
  6277. return obj._doc;
  6278. }
  6279. var ret;
  6280. if (options && options.json && typeof obj.toJSON === 'function') {
  6281. ret = obj.toJSON(options);
  6282. } else {
  6283. ret = obj.toObject(options);
  6284. }
  6285. if (options && options.minimize && isSingleNested && Object.keys(ret).length === 0) {
  6286. return undefined;
  6287. }
  6288. return ret;
  6289. }
  6290. var objConstructor = obj.constructor;
  6291. if (objConstructor) {
  6292. switch (getFunctionName(objConstructor)) {
  6293. case 'Object':
  6294. return cloneObject(obj, options, isArrayChild);
  6295. case 'Date':
  6296. return new objConstructor(+obj);
  6297. case 'RegExp':
  6298. return cloneRegExp(obj);
  6299. default:
  6300. // ignore
  6301. break;
  6302. }
  6303. }
  6304. if (isBsonType(obj, 'ObjectID')) {
  6305. return new ObjectId(obj.id);
  6306. }
  6307. if (isBsonType(obj, 'Decimal128')) {
  6308. if (options && options.flattenDecimals) {
  6309. return obj.toJSON();
  6310. }
  6311. return Decimal.fromString(obj.toString());
  6312. } // object created with Object.create(null)
  6313. if (!objConstructor && isObject(obj)) {
  6314. return cloneObject(obj, options, isArrayChild);
  6315. }
  6316. if (_typeof(obj) === 'object' && obj[symbols.schemaTypeSymbol]) {
  6317. return obj.clone();
  6318. } // If we're cloning this object to go into a MongoDB command,
  6319. // and there's a `toBSON()` function, assume this object will be
  6320. // stored as a primitive in MongoDB and doesn't need to be cloned.
  6321. if (options && options.bson && typeof obj.toBSON === 'function') {
  6322. return obj;
  6323. }
  6324. if (typeof obj.valueOf === 'function') {
  6325. return obj.valueOf();
  6326. }
  6327. return cloneObject(obj, options, isArrayChild);
  6328. }
  6329. module.exports = clone;
  6330. /*!
  6331. * ignore
  6332. */
  6333. function cloneObject(obj, options, isArrayChild) {
  6334. var minimize = options && options.minimize;
  6335. var omitUndefined = options && options.omitUndefined;
  6336. var seen = options && options._seen;
  6337. var ret = {};
  6338. var hasKeys;
  6339. if (seen && seen.has(obj)) {
  6340. return seen.get(obj);
  6341. } else if (seen) {
  6342. seen.set(obj, ret);
  6343. }
  6344. if (trustedSymbol in obj) {
  6345. ret[trustedSymbol] = obj[trustedSymbol];
  6346. }
  6347. var i = 0;
  6348. var key = '';
  6349. var keys = Object.keys(obj);
  6350. var len = keys.length;
  6351. for (i = 0; i < len; ++i) {
  6352. if (specialProperties.has(key = keys[i])) {
  6353. continue;
  6354. } // Don't pass `isArrayChild` down
  6355. var val = clone(obj[key], options, false);
  6356. if ((minimize === false || omitUndefined) && typeof val === 'undefined') {
  6357. delete ret[key];
  6358. } else if (minimize !== true || typeof val !== 'undefined') {
  6359. hasKeys || (hasKeys = true);
  6360. ret[key] = val;
  6361. }
  6362. }
  6363. return minimize && !isArrayChild ? hasKeys && ret : ret;
  6364. }
  6365. function cloneArray(arr, options) {
  6366. var i = 0;
  6367. var len = arr.length;
  6368. var ret = new Array(len);
  6369. for (i = 0; i < len; ++i) {
  6370. ret[i] = clone(arr[i], options, true);
  6371. }
  6372. return ret;
  6373. }
  6374. function cloneRegExp(regexp) {
  6375. var ret = new RegExp(regexp.source, regexp.flags);
  6376. if (ret.lastIndex !== regexp.lastIndex) {
  6377. ret.lastIndex = regexp.lastIndex;
  6378. }
  6379. return ret;
  6380. }
  6381. /***/ }),
  6382. /***/ 2829:
  6383. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6384. "use strict";
  6385. var __webpack_unused_export__;
  6386. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  6387. /*!
  6388. * Module dependencies.
  6389. */
  6390. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6391. var Binary = (__webpack_require__(9906).get)().Binary;
  6392. var isBsonType = __webpack_require__(1563);
  6393. var isMongooseObject = __webpack_require__(6584);
  6394. exports.x = flatten;
  6395. __webpack_unused_export__ = modifiedPaths;
  6396. /*!
  6397. * ignore
  6398. */
  6399. function flatten(update, path, options, schema) {
  6400. var keys;
  6401. if (update && isMongooseObject(update) && !Buffer.isBuffer(update)) {
  6402. keys = Object.keys(update.toObject({
  6403. transform: false,
  6404. virtuals: false
  6405. }) || {});
  6406. } else {
  6407. keys = Object.keys(update || {});
  6408. }
  6409. var numKeys = keys.length;
  6410. var result = {};
  6411. path = path ? path + '.' : '';
  6412. for (var i = 0; i < numKeys; ++i) {
  6413. var key = keys[i];
  6414. var val = update[key];
  6415. result[path + key] = val; // Avoid going into mixed paths if schema is specified
  6416. var keySchema = schema && schema.path && schema.path(path + key);
  6417. var isNested = schema && schema.nested && schema.nested[path + key];
  6418. if (keySchema && keySchema.instance === 'Mixed') continue;
  6419. if (shouldFlatten(val)) {
  6420. if (options && options.skipArrays && Array.isArray(val)) {
  6421. continue;
  6422. }
  6423. var flat = flatten(val, path + key, options, schema);
  6424. for (var k in flat) {
  6425. result[k] = flat[k];
  6426. }
  6427. if (Array.isArray(val)) {
  6428. result[path + key] = val;
  6429. }
  6430. }
  6431. if (isNested) {
  6432. var paths = Object.keys(schema.paths);
  6433. for (var _i = 0, _paths = paths; _i < _paths.length; _i++) {
  6434. var p = _paths[_i];
  6435. if (p.startsWith(path + key + '.') && !result.hasOwnProperty(p)) {
  6436. result[p] = void 0;
  6437. }
  6438. }
  6439. }
  6440. }
  6441. return result;
  6442. }
  6443. /*!
  6444. * ignore
  6445. */
  6446. function modifiedPaths(update, path, result) {
  6447. var keys = Object.keys(update || {});
  6448. var numKeys = keys.length;
  6449. result = result || {};
  6450. path = path ? path + '.' : '';
  6451. for (var i = 0; i < numKeys; ++i) {
  6452. var key = keys[i];
  6453. var val = update[key];
  6454. var _path = path + key;
  6455. result[_path] = true;
  6456. if (!Buffer.isBuffer(val) && isMongooseObject(val)) {
  6457. val = val.toObject({
  6458. transform: false,
  6459. virtuals: false
  6460. });
  6461. }
  6462. if (shouldFlatten(val)) {
  6463. modifiedPaths(val, path + key, result);
  6464. }
  6465. }
  6466. return result;
  6467. }
  6468. /*!
  6469. * ignore
  6470. */
  6471. function shouldFlatten(val) {
  6472. return val && _typeof(val) === 'object' && !(val instanceof Date) && !isBsonType(val, 'ObjectID') && (!Array.isArray(val) || val.length !== 0) && !(val instanceof Buffer) && !isBsonType(val, 'Decimal128') && !(val instanceof Binary);
  6473. }
  6474. /***/ }),
  6475. /***/ 2794:
  6476. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6477. "use strict";
  6478. var isBsonType = __webpack_require__(1563);
  6479. module.exports = function areDiscriminatorValuesEqual(a, b) {
  6480. if (typeof a === 'string' && typeof b === 'string') {
  6481. return a === b;
  6482. }
  6483. if (typeof a === 'number' && typeof b === 'number') {
  6484. return a === b;
  6485. }
  6486. if (isBsonType(a, 'ObjectID') && isBsonType(b, 'ObjectID')) {
  6487. return a.toString() === b.toString();
  6488. }
  6489. return false;
  6490. };
  6491. /***/ }),
  6492. /***/ 4531:
  6493. /***/ ((module) => {
  6494. "use strict";
  6495. module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
  6496. var userProjectedInPath = Object.keys(userProjection).reduce(function (cur, key) {
  6497. return cur || key.startsWith(path + '.');
  6498. }, false);
  6499. var _discriminatorKey = path + '.' + schema.options.discriminatorKey;
  6500. if (!userProjectedInPath && addedPaths.length === 1 && addedPaths[0] === _discriminatorKey) {
  6501. selected.splice(selected.indexOf(_discriminatorKey), 1);
  6502. }
  6503. };
  6504. /***/ }),
  6505. /***/ 8413:
  6506. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6507. "use strict";
  6508. var getDiscriminatorByValue = __webpack_require__(7291);
  6509. /*!
  6510. * Find the correct constructor, taking into account discriminators
  6511. */
  6512. module.exports = function getConstructor(Constructor, value) {
  6513. var discriminatorKey = Constructor.schema.options.discriminatorKey;
  6514. if (value != null && Constructor.discriminators && value[discriminatorKey] != null) {
  6515. if (Constructor.discriminators[value[discriminatorKey]]) {
  6516. Constructor = Constructor.discriminators[value[discriminatorKey]];
  6517. } else {
  6518. var constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
  6519. if (constructorByValue) {
  6520. Constructor = constructorByValue;
  6521. }
  6522. }
  6523. }
  6524. return Constructor;
  6525. };
  6526. /***/ }),
  6527. /***/ 7291:
  6528. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6529. "use strict";
  6530. var areDiscriminatorValuesEqual = __webpack_require__(2794);
  6531. /*!
  6532. * returns discriminator by discriminatorMapping.value
  6533. *
  6534. * @param {Model} model
  6535. * @param {string} value
  6536. */
  6537. module.exports = function getDiscriminatorByValue(discriminators, value) {
  6538. if (discriminators == null) {
  6539. return null;
  6540. }
  6541. for (var _i = 0, _Object$keys = Object.keys(discriminators); _i < _Object$keys.length; _i++) {
  6542. var name = _Object$keys[_i];
  6543. var it = discriminators[name];
  6544. if (it.schema && it.schema.discriminatorMapping && areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)) {
  6545. return it;
  6546. }
  6547. }
  6548. return null;
  6549. };
  6550. /***/ }),
  6551. /***/ 2392:
  6552. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6553. "use strict";
  6554. var areDiscriminatorValuesEqual = __webpack_require__(2794);
  6555. /*!
  6556. * returns discriminator by discriminatorMapping.value
  6557. *
  6558. * @param {Schema} schema
  6559. * @param {string} value
  6560. */
  6561. module.exports = function getSchemaDiscriminatorByValue(schema, value) {
  6562. if (schema == null || schema.discriminators == null) {
  6563. return null;
  6564. }
  6565. for (var _i = 0, _Object$keys = Object.keys(schema.discriminators); _i < _Object$keys.length; _i++) {
  6566. var key = _Object$keys[_i];
  6567. var discriminatorSchema = schema.discriminators[key];
  6568. if (discriminatorSchema.discriminatorMapping == null) {
  6569. continue;
  6570. }
  6571. if (areDiscriminatorValuesEqual(discriminatorSchema.discriminatorMapping.value, value)) {
  6572. return discriminatorSchema;
  6573. }
  6574. }
  6575. return null;
  6576. };
  6577. /***/ }),
  6578. /***/ 4134:
  6579. /***/ ((module) => {
  6580. "use strict";
  6581. /*!
  6582. * ignore
  6583. */
  6584. module.exports = function cleanModifiedSubpaths(doc, path, options) {
  6585. options = options || {};
  6586. var skipDocArrays = options.skipDocArrays;
  6587. var deleted = 0;
  6588. if (!doc) {
  6589. return deleted;
  6590. }
  6591. for (var _i = 0, _Object$keys = Object.keys(doc.$__.activePaths.states.modify); _i < _Object$keys.length; _i++) {
  6592. var modifiedPath = _Object$keys[_i];
  6593. if (skipDocArrays) {
  6594. var schemaType = doc.$__schema.path(modifiedPath);
  6595. if (schemaType && schemaType.$isMongooseDocumentArray) {
  6596. continue;
  6597. }
  6598. }
  6599. if (modifiedPath.startsWith(path + '.')) {
  6600. delete doc.$__.activePaths.states.modify[modifiedPath];
  6601. ++deleted;
  6602. if (doc.$isSubdocument) {
  6603. var owner = doc.ownerDocument();
  6604. var fullPath = doc.$__fullPath(modifiedPath);
  6605. delete owner.$__.activePaths.states.modify[fullPath];
  6606. }
  6607. }
  6608. }
  6609. return deleted;
  6610. };
  6611. /***/ }),
  6612. /***/ 8724:
  6613. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  6614. "use strict";
  6615. var documentSchemaSymbol = (__webpack_require__(8770).documentSchemaSymbol);
  6616. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  6617. var utils = __webpack_require__(6872);
  6618. var Document;
  6619. var getSymbol = (__webpack_require__(8770).getSymbol);
  6620. var scopeSymbol = (__webpack_require__(8770).scopeSymbol);
  6621. var isPOJO = utils.isPOJO;
  6622. /*!
  6623. * exports
  6624. */
  6625. exports.M = compile;
  6626. exports.c = defineKey;
  6627. /*!
  6628. * Compiles schemas.
  6629. */
  6630. function compile(tree, proto, prefix, options) {
  6631. Document = Document || __webpack_require__(8727);
  6632. var typeKey = options.typeKey;
  6633. for (var _i = 0, _Object$keys = Object.keys(tree); _i < _Object$keys.length; _i++) {
  6634. var key = _Object$keys[_i];
  6635. var limb = tree[key];
  6636. var hasSubprops = isPOJO(limb) && Object.keys(limb).length > 0 && (!limb[typeKey] || typeKey === 'type' && isPOJO(limb.type) && limb.type.type);
  6637. var subprops = hasSubprops ? limb : null;
  6638. defineKey({
  6639. prop: key,
  6640. subprops: subprops,
  6641. prototype: proto,
  6642. prefix: prefix,
  6643. options: options
  6644. });
  6645. }
  6646. }
  6647. /*!
  6648. * Defines the accessor named prop on the incoming prototype.
  6649. */
  6650. function defineKey(_ref) {
  6651. var prop = _ref.prop,
  6652. subprops = _ref.subprops,
  6653. prototype = _ref.prototype,
  6654. prefix = _ref.prefix,
  6655. options = _ref.options;
  6656. Document = Document || __webpack_require__(8727);
  6657. var path = (prefix ? prefix + '.' : '') + prop;
  6658. prefix = prefix || '';
  6659. if (subprops) {
  6660. Object.defineProperty(prototype, prop, {
  6661. enumerable: true,
  6662. configurable: true,
  6663. get: function get() {
  6664. var _this = this;
  6665. if (!this.$__.getters) {
  6666. this.$__.getters = {};
  6667. }
  6668. if (!this.$__.getters[path]) {
  6669. var nested = Object.create(Document.prototype, getOwnPropertyDescriptors(this)); // save scope for nested getters/setters
  6670. if (!prefix) {
  6671. nested.$__[scopeSymbol] = this;
  6672. }
  6673. nested.$__.nestedPath = path;
  6674. Object.defineProperty(nested, 'schema', {
  6675. enumerable: false,
  6676. configurable: true,
  6677. writable: false,
  6678. value: prototype.schema
  6679. });
  6680. Object.defineProperty(nested, '$__schema', {
  6681. enumerable: false,
  6682. configurable: true,
  6683. writable: false,
  6684. value: prototype.schema
  6685. });
  6686. Object.defineProperty(nested, documentSchemaSymbol, {
  6687. enumerable: false,
  6688. configurable: true,
  6689. writable: false,
  6690. value: prototype.schema
  6691. });
  6692. Object.defineProperty(nested, 'toObject', {
  6693. enumerable: false,
  6694. configurable: true,
  6695. writable: false,
  6696. value: function value() {
  6697. return utils.clone(_this.get(path, null, {
  6698. virtuals: this && this.schema && this.schema.options && this.schema.options.toObject && this.schema.options.toObject.virtuals || null
  6699. }));
  6700. }
  6701. });
  6702. Object.defineProperty(nested, '$__get', {
  6703. enumerable: false,
  6704. configurable: true,
  6705. writable: false,
  6706. value: function value() {
  6707. return _this.get(path, null, {
  6708. virtuals: this && this.schema && this.schema.options && this.schema.options.toObject && this.schema.options.toObject.virtuals || null
  6709. });
  6710. }
  6711. });
  6712. Object.defineProperty(nested, 'toJSON', {
  6713. enumerable: false,
  6714. configurable: true,
  6715. writable: false,
  6716. value: function value() {
  6717. return _this.get(path, null, {
  6718. virtuals: this && this.schema && this.schema.options && this.schema.options.toJSON && this.schema.options.toJSON.virtuals || null
  6719. });
  6720. }
  6721. });
  6722. Object.defineProperty(nested, '$__isNested', {
  6723. enumerable: false,
  6724. configurable: true,
  6725. writable: false,
  6726. value: true
  6727. });
  6728. var _isEmptyOptions = Object.freeze({
  6729. minimize: true,
  6730. virtuals: false,
  6731. getters: false,
  6732. transform: false
  6733. });
  6734. Object.defineProperty(nested, '$isEmpty', {
  6735. enumerable: false,
  6736. configurable: true,
  6737. writable: false,
  6738. value: function value() {
  6739. return Object.keys(this.get(path, null, _isEmptyOptions) || {}).length === 0;
  6740. }
  6741. });
  6742. Object.defineProperty(nested, '$__parent', {
  6743. enumerable: false,
  6744. configurable: true,
  6745. writable: false,
  6746. value: this
  6747. });
  6748. compile(subprops, nested, path, options);
  6749. this.$__.getters[path] = nested;
  6750. }
  6751. return this.$__.getters[path];
  6752. },
  6753. set: function set(v) {
  6754. if (v != null && v.$__isNested) {
  6755. // Convert top-level to POJO, but leave subdocs hydrated so `$set`
  6756. // can handle them. See gh-9293.
  6757. v = v.$__get();
  6758. } else if (v instanceof Document && !v.$__isNested) {
  6759. v = v.$toObject(internalToObjectOptions);
  6760. }
  6761. var doc = this.$__[scopeSymbol] || this;
  6762. doc.$set(path, v);
  6763. }
  6764. });
  6765. } else {
  6766. Object.defineProperty(prototype, prop, {
  6767. enumerable: true,
  6768. configurable: true,
  6769. get: function get() {
  6770. return this[getSymbol].call(this.$__[scopeSymbol] || this, path);
  6771. },
  6772. set: function set(v) {
  6773. this.$set.call(this.$__[scopeSymbol] || this, path, v);
  6774. }
  6775. });
  6776. }
  6777. } // gets descriptors for all properties of `object`
  6778. // makes all properties non-enumerable to match previous behavior to #2211
  6779. function getOwnPropertyDescriptors(object) {
  6780. var result = {};
  6781. Object.getOwnPropertyNames(object).forEach(function (key) {
  6782. var skip = ['isNew', '$__', '$errors', 'errors', '_doc', '$locals', '$op', '__parentArray', '__index', '$isDocumentArrayElement'].indexOf(key) === -1;
  6783. if (skip) {
  6784. return;
  6785. }
  6786. result[key] = Object.getOwnPropertyDescriptor(object, key);
  6787. result[key].enumerable = false;
  6788. });
  6789. return result;
  6790. }
  6791. /***/ }),
  6792. /***/ 111:
  6793. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6794. "use strict";
  6795. var get = __webpack_require__(9981);
  6796. var getSchemaDiscriminatorByValue = __webpack_require__(2392);
  6797. /*!
  6798. * Like `schema.path()`, except with a document, because impossible to
  6799. * determine path type without knowing the embedded discriminator key.
  6800. */
  6801. module.exports = function getEmbeddedDiscriminatorPath(doc, path, options) {
  6802. options = options || {};
  6803. var typeOnly = options.typeOnly;
  6804. var parts = path.indexOf('.') === -1 ? [path] : path.split('.');
  6805. var schemaType = null;
  6806. var type = 'adhocOrUndefined';
  6807. var schema = getSchemaDiscriminatorByValue(doc.schema, doc.get(doc.schema.options.discriminatorKey)) || doc.schema;
  6808. for (var i = 0; i < parts.length; ++i) {
  6809. var subpath = parts.slice(0, i + 1).join('.');
  6810. schemaType = schema.path(subpath);
  6811. if (schemaType == null) {
  6812. type = 'adhocOrUndefined';
  6813. continue;
  6814. }
  6815. if (schemaType.instance === 'Mixed') {
  6816. return typeOnly ? 'real' : schemaType;
  6817. }
  6818. type = schema.pathType(subpath);
  6819. if ((schemaType.$isSingleNested || schemaType.$isMongooseDocumentArrayElement) && schemaType.schema.discriminators != null) {
  6820. var discriminators = schemaType.schema.discriminators;
  6821. var discriminatorKey = doc.get(subpath + '.' + get(schemaType, 'schema.options.discriminatorKey'));
  6822. if (discriminatorKey == null || discriminators[discriminatorKey] == null) {
  6823. continue;
  6824. }
  6825. var rest = parts.slice(i + 1).join('.');
  6826. return getEmbeddedDiscriminatorPath(doc.get(subpath), rest, options);
  6827. }
  6828. } // Are we getting the whole schema or just the type, 'real', 'nested', etc.
  6829. return typeOnly ? type : schemaType;
  6830. };
  6831. /***/ }),
  6832. /***/ 719:
  6833. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  6834. "use strict";
  6835. function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
  6836. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
  6837. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  6838. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6839. var utils = __webpack_require__(6872);
  6840. var keysToSkip = new Set(['__index', '__parentArray', '_doc']);
  6841. /**
  6842. * Using spread operator on a Mongoose document gives you a
  6843. * POJO that has a tendency to cause infinite recursion. So
  6844. * we use this function on `set()` to prevent that.
  6845. */
  6846. module.exports = function handleSpreadDoc(v, includeExtraKeys) {
  6847. if (utils.isPOJO(v) && v.$__ != null && v._doc != null) {
  6848. if (includeExtraKeys) {
  6849. var extraKeys = {};
  6850. for (var _i = 0, _Object$keys = Object.keys(v); _i < _Object$keys.length; _i++) {
  6851. var key = _Object$keys[_i];
  6852. if (_typeof(key) === 'symbol') {
  6853. continue;
  6854. }
  6855. if (key[0] === '$') {
  6856. continue;
  6857. }
  6858. if (keysToSkip.has(key)) {
  6859. continue;
  6860. }
  6861. extraKeys[key] = v[key];
  6862. }
  6863. return _objectSpread(_objectSpread({}, v._doc), extraKeys);
  6864. }
  6865. return v._doc;
  6866. }
  6867. return v;
  6868. };
  6869. /***/ }),
  6870. /***/ 9981:
  6871. /***/ ((module) => {
  6872. "use strict";
  6873. /*!
  6874. * Simplified lodash.get to work around the annoying null quirk. See:
  6875. * https://github.com/lodash/lodash/issues/3659
  6876. */
  6877. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  6878. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  6879. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  6880. module.exports = function get(obj, path, def) {
  6881. var parts;
  6882. var isPathArray = false;
  6883. if (typeof path === 'string') {
  6884. if (path.indexOf('.') === -1) {
  6885. var _v = getProperty(obj, path);
  6886. if (_v == null) {
  6887. return def;
  6888. }
  6889. return _v;
  6890. }
  6891. parts = path.split('.');
  6892. } else {
  6893. isPathArray = true;
  6894. parts = path;
  6895. if (parts.length === 1) {
  6896. var _v2 = getProperty(obj, parts[0]);
  6897. if (_v2 == null) {
  6898. return def;
  6899. }
  6900. return _v2;
  6901. }
  6902. }
  6903. var rest = path;
  6904. var cur = obj;
  6905. var _iterator = _createForOfIteratorHelper(parts),
  6906. _step;
  6907. try {
  6908. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  6909. var part = _step.value;
  6910. if (cur == null) {
  6911. return def;
  6912. } // `lib/cast.js` depends on being able to get dotted paths in updates,
  6913. // like `{ $set: { 'a.b': 42 } }`
  6914. if (!isPathArray && cur[rest] != null) {
  6915. return cur[rest];
  6916. }
  6917. cur = getProperty(cur, part);
  6918. if (!isPathArray) {
  6919. rest = rest.substr(part.length + 1);
  6920. }
  6921. }
  6922. } catch (err) {
  6923. _iterator.e(err);
  6924. } finally {
  6925. _iterator.f();
  6926. }
  6927. return cur == null ? def : cur;
  6928. };
  6929. function getProperty(obj, prop) {
  6930. if (obj == null) {
  6931. return obj;
  6932. }
  6933. if (obj instanceof Map) {
  6934. return obj.get(prop);
  6935. }
  6936. return obj[prop];
  6937. }
  6938. /***/ }),
  6939. /***/ 1981:
  6940. /***/ ((module) => {
  6941. "use strict";
  6942. /*!
  6943. * If `val` is an object, returns constructor name, if possible. Otherwise returns undefined.
  6944. */
  6945. module.exports = function getConstructorName(val) {
  6946. if (val == null) {
  6947. return void 0;
  6948. }
  6949. if (typeof val.constructor !== 'function') {
  6950. return void 0;
  6951. }
  6952. return val.constructor.name;
  6953. };
  6954. /***/ }),
  6955. /***/ 6749:
  6956. /***/ ((module) => {
  6957. "use strict";
  6958. var functionNameRE = /^function\s*([^\s(]+)/;
  6959. module.exports = function (fn) {
  6960. return fn.name || (fn.toString().trim().match(functionNameRE) || [])[1];
  6961. };
  6962. /***/ }),
  6963. /***/ 1490:
  6964. /***/ ((module) => {
  6965. "use strict";
  6966. /*!
  6967. * Centralize this so we can more easily work around issues with people
  6968. * stubbing out `process.nextTick()` in tests using sinon:
  6969. * https://github.com/sinonjs/lolex#automatically-incrementing-mocked-time
  6970. * See gh-6074
  6971. */
  6972. var nextTick = typeof ({env:{}}) !== 'undefined' && typeof ({env:{}}).nextTick === 'function' ? ({env:{}}).nextTick.bind(({env:{}})) : function (cb) {
  6973. return setTimeout(cb, 0);
  6974. }; // Fallback for browser build
  6975. module.exports = function immediate(cb) {
  6976. return nextTick(cb);
  6977. };
  6978. /***/ }),
  6979. /***/ 1605:
  6980. /***/ ((module) => {
  6981. "use strict";
  6982. module.exports = function decorateDiscriminatorIndexOptions(schema, indexOptions) {
  6983. // If the model is a discriminator and has an index, add a
  6984. // partialFilterExpression by default so the index will only apply
  6985. // to that discriminator.
  6986. var discriminatorName = schema.discriminatorMapping && schema.discriminatorMapping.value;
  6987. if (discriminatorName && !('sparse' in indexOptions)) {
  6988. var discriminatorKey = schema.options.discriminatorKey;
  6989. indexOptions.partialFilterExpression = indexOptions.partialFilterExpression || {};
  6990. indexOptions.partialFilterExpression[discriminatorKey] = discriminatorName;
  6991. }
  6992. return indexOptions;
  6993. };
  6994. /***/ }),
  6995. /***/ 8857:
  6996. /***/ ((module) => {
  6997. "use strict";
  6998. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  6999. function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
  7000. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  7001. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  7002. var asyncFunctionPrototype = null; // try/catch for Babel compatibility, because Babel preset-env requires
  7003. // regenerator-runtime for async/await and we don't want to include that
  7004. // for a simple check.
  7005. try {
  7006. asyncFunctionPrototype = Object.getPrototypeOf( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
  7007. return _regeneratorRuntime().wrap(function _callee$(_context) {
  7008. while (1) {
  7009. switch (_context.prev = _context.next) {
  7010. case 0:
  7011. case "end":
  7012. return _context.stop();
  7013. }
  7014. }
  7015. }, _callee);
  7016. })));
  7017. } catch (err) {}
  7018. if (asyncFunctionPrototype == null) {
  7019. module.exports = function isAsyncFunction() {
  7020. return false;
  7021. };
  7022. } else {
  7023. module.exports = function isAsyncFunction(v) {
  7024. return typeof v === 'function' && Object.getPrototypeOf(v) === asyncFunctionPrototype;
  7025. };
  7026. }
  7027. /***/ }),
  7028. /***/ 1563:
  7029. /***/ ((module) => {
  7030. "use strict";
  7031. /*!
  7032. * Get the bson type, if it exists
  7033. */
  7034. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7035. function isBsonType(obj, typename) {
  7036. return _typeof(obj) === 'object' && obj !== null && obj._bsontype === typename;
  7037. }
  7038. module.exports = isBsonType;
  7039. /***/ }),
  7040. /***/ 6584:
  7041. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7042. "use strict";
  7043. var isMongooseArray = (__webpack_require__(7339).isMongooseArray);
  7044. /*!
  7045. * Returns if `v` is a mongoose object that has a `toObject()` method we can use.
  7046. *
  7047. * This is for compatibility with libs like Date.js which do foolish things to Natives.
  7048. *
  7049. * @param {any} v
  7050. * @api private
  7051. */
  7052. module.exports = function (v) {
  7053. return v != null && (isMongooseArray(v) || // Array or Document Array
  7054. v.$__ != null || // Document
  7055. v.isMongooseBuffer || // Buffer
  7056. v.$isMongooseMap // Map
  7057. );
  7058. };
  7059. /***/ }),
  7060. /***/ 5721:
  7061. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7062. "use strict";
  7063. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  7064. /*!
  7065. * Determines if `arg` is an object.
  7066. *
  7067. * @param {Object|Array|String|Function|RegExp|any} arg
  7068. * @api private
  7069. * @return {Boolean}
  7070. */
  7071. module.exports = function (arg) {
  7072. return Buffer.isBuffer(arg) || Object.prototype.toString.call(arg) === '[object Object]';
  7073. };
  7074. /***/ }),
  7075. /***/ 5543:
  7076. /***/ ((module) => {
  7077. "use strict";
  7078. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7079. function isPromise(val) {
  7080. return !!val && (_typeof(val) === 'object' || typeof val === 'function') && typeof val.then === 'function';
  7081. }
  7082. module.exports = isPromise;
  7083. /***/ }),
  7084. /***/ 9130:
  7085. /***/ ((module) => {
  7086. "use strict";
  7087. /*!
  7088. * Determines if `arg` is a flat object.
  7089. *
  7090. * @param {Object|Array|String|Function|RegExp|any} arg
  7091. * @api private
  7092. * @return {Boolean}
  7093. */
  7094. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7095. module.exports = function isSimpleValidator(obj) {
  7096. var keys = Object.keys(obj);
  7097. var result = true;
  7098. for (var i = 0, len = keys.length; i < len; ++i) {
  7099. if (_typeof(obj[keys[i]]) === 'object' && obj[keys[i]] !== null) {
  7100. result = false;
  7101. break;
  7102. }
  7103. }
  7104. return result;
  7105. };
  7106. /***/ }),
  7107. /***/ 8859:
  7108. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7109. "use strict";
  7110. var symbols = __webpack_require__(8107);
  7111. var promiseOrCallback = __webpack_require__(8486);
  7112. /*!
  7113. * ignore
  7114. */
  7115. module.exports = applyHooks;
  7116. /*!
  7117. * ignore
  7118. */
  7119. applyHooks.middlewareFunctions = ['deleteOne', 'save', 'validate', 'remove', 'updateOne', 'init'];
  7120. /*!
  7121. * Register hooks for this model
  7122. *
  7123. * @param {Model} model
  7124. * @param {Schema} schema
  7125. */
  7126. function applyHooks(model, schema, options) {
  7127. options = options || {};
  7128. var kareemOptions = {
  7129. useErrorHandlers: true,
  7130. numCallbackParams: 1,
  7131. nullResultByDefault: true,
  7132. contextParameter: true
  7133. };
  7134. var objToDecorate = options.decorateDoc ? model : model.prototype;
  7135. model.$appliedHooks = true;
  7136. for (var _i = 0, _Object$keys = Object.keys(schema.paths); _i < _Object$keys.length; _i++) {
  7137. var key = _Object$keys[_i];
  7138. var type = schema.paths[key];
  7139. var childModel = null;
  7140. if (type.$isSingleNested) {
  7141. childModel = type.caster;
  7142. } else if (type.$isMongooseDocumentArray) {
  7143. childModel = type.Constructor;
  7144. } else {
  7145. continue;
  7146. }
  7147. if (childModel.$appliedHooks) {
  7148. continue;
  7149. }
  7150. applyHooks(childModel, type.schema, options);
  7151. if (childModel.discriminators != null) {
  7152. var keys = Object.keys(childModel.discriminators);
  7153. for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
  7154. var _key = _keys[_i2];
  7155. applyHooks(childModel.discriminators[_key], childModel.discriminators[_key].schema, options);
  7156. }
  7157. }
  7158. } // Built-in hooks rely on hooking internal functions in order to support
  7159. // promises and make it so that `doc.save.toString()` provides meaningful
  7160. // information.
  7161. var middleware = schema.s.hooks.filter(function (hook) {
  7162. if (hook.name === 'updateOne' || hook.name === 'deleteOne') {
  7163. return !!hook['document'];
  7164. }
  7165. if (hook.name === 'remove' || hook.name === 'init') {
  7166. return hook['document'] == null || !!hook['document'];
  7167. }
  7168. if (hook.query != null || hook.document != null) {
  7169. return hook.document !== false;
  7170. }
  7171. return true;
  7172. }).filter(function (hook) {
  7173. // If user has overwritten the method, don't apply built-in middleware
  7174. if (schema.methods[hook.name]) {
  7175. return !hook.fn[symbols.builtInMiddleware];
  7176. }
  7177. return true;
  7178. });
  7179. model._middleware = middleware;
  7180. objToDecorate.$__originalValidate = objToDecorate.$__originalValidate || objToDecorate.$__validate;
  7181. for (var _i3 = 0, _arr = ['save', 'validate', 'remove', 'deleteOne']; _i3 < _arr.length; _i3++) {
  7182. var method = _arr[_i3];
  7183. var toWrap = method === 'validate' ? '$__originalValidate' : "$__".concat(method);
  7184. var wrapped = middleware.createWrapper(method, objToDecorate[toWrap], null, kareemOptions);
  7185. objToDecorate["$__".concat(method)] = wrapped;
  7186. }
  7187. objToDecorate.$__init = middleware.createWrapperSync('init', objToDecorate.$__init, null, kareemOptions); // Support hooks for custom methods
  7188. var customMethods = Object.keys(schema.methods);
  7189. var customMethodOptions = Object.assign({}, kareemOptions, {
  7190. // Only use `checkForPromise` for custom methods, because mongoose
  7191. // query thunks are not as consistent as I would like about returning
  7192. // a nullish value rather than the query. If a query thunk returns
  7193. // a query, `checkForPromise` causes infinite recursion
  7194. checkForPromise: true
  7195. });
  7196. var _loop = function _loop() {
  7197. var method = _customMethods[_i4];
  7198. if (!middleware.hasHooks(method)) {
  7199. // Don't wrap if there are no hooks for the custom method to avoid
  7200. // surprises. Also, `createWrapper()` enforces consistent async,
  7201. // so wrapping a sync method would break it.
  7202. return "continue";
  7203. }
  7204. var originalMethod = objToDecorate[method];
  7205. objToDecorate[method] = function () {
  7206. var _this = this;
  7207. var args = Array.prototype.slice.call(arguments);
  7208. var cb = args.slice(-1).pop();
  7209. var argsWithoutCallback = typeof cb === 'function' ? args.slice(0, args.length - 1) : args;
  7210. return promiseOrCallback(cb, function (callback) {
  7211. return _this["$__".concat(method)].apply(_this, argsWithoutCallback.concat([callback]));
  7212. }, model.events);
  7213. };
  7214. objToDecorate["$__".concat(method)] = middleware.createWrapper(method, originalMethod, null, customMethodOptions);
  7215. };
  7216. for (var _i4 = 0, _customMethods = customMethods; _i4 < _customMethods.length; _i4++) {
  7217. var _ret = _loop();
  7218. if (_ret === "continue") continue;
  7219. }
  7220. }
  7221. /***/ }),
  7222. /***/ 9181:
  7223. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7224. "use strict";
  7225. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  7226. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7227. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  7228. var Mixed = __webpack_require__(3861);
  7229. var defineKey = (__webpack_require__(8724)/* .defineKey */ .c);
  7230. var get = __webpack_require__(9981);
  7231. var utils = __webpack_require__(6872);
  7232. var CUSTOMIZABLE_DISCRIMINATOR_OPTIONS = {
  7233. toJSON: true,
  7234. toObject: true,
  7235. _id: true,
  7236. id: true
  7237. };
  7238. /*!
  7239. * ignore
  7240. */
  7241. module.exports = function discriminator(model, name, schema, tiedValue, applyPlugins) {
  7242. if (!(schema && schema.instanceOfSchema)) {
  7243. throw new Error('You must pass a valid discriminator Schema');
  7244. }
  7245. if (model.schema.discriminatorMapping && !model.schema.discriminatorMapping.isRoot) {
  7246. throw new Error('Discriminator "' + name + '" can only be a discriminator of the root model');
  7247. }
  7248. if (applyPlugins) {
  7249. var applyPluginsToDiscriminators = get(model.base, 'options.applyPluginsToDiscriminators', false); // Even if `applyPluginsToDiscriminators` isn't set, we should still apply
  7250. // global plugins to schemas embedded in the discriminator schema (gh-7370)
  7251. model.base._applyPlugins(schema, {
  7252. skipTopLevel: !applyPluginsToDiscriminators
  7253. });
  7254. }
  7255. var key = model.schema.options.discriminatorKey;
  7256. var existingPath = model.schema.path(key);
  7257. if (existingPath != null) {
  7258. if (!utils.hasUserDefinedProperty(existingPath.options, 'select')) {
  7259. existingPath.options.select = true;
  7260. }
  7261. existingPath.options.$skipDiscriminatorCheck = true;
  7262. } else {
  7263. var baseSchemaAddition = {};
  7264. baseSchemaAddition[key] = {
  7265. "default": void 0,
  7266. select: true,
  7267. $skipDiscriminatorCheck: true
  7268. };
  7269. baseSchemaAddition[key][model.schema.options.typeKey] = String;
  7270. model.schema.add(baseSchemaAddition);
  7271. defineKey({
  7272. prop: key,
  7273. prototype: model.prototype,
  7274. options: model.schema.options
  7275. });
  7276. }
  7277. if (schema.path(key) && schema.path(key).options.$skipDiscriminatorCheck !== true) {
  7278. throw new Error('Discriminator "' + name + '" cannot have field with name "' + key + '"');
  7279. }
  7280. var value = name;
  7281. if (typeof tiedValue === 'string' && tiedValue.length || tiedValue != null) {
  7282. value = tiedValue;
  7283. }
  7284. function merge(schema, baseSchema) {
  7285. // Retain original schema before merging base schema
  7286. schema._baseSchema = baseSchema;
  7287. if (baseSchema.paths._id && baseSchema.paths._id.options && !baseSchema.paths._id.options.auto) {
  7288. schema.remove('_id');
  7289. } // Find conflicting paths: if something is a path in the base schema
  7290. // and a nested path in the child schema, overwrite the base schema path.
  7291. // See gh-6076
  7292. var baseSchemaPaths = Object.keys(baseSchema.paths);
  7293. var conflictingPaths = [];
  7294. for (var _i = 0, _baseSchemaPaths = baseSchemaPaths; _i < _baseSchemaPaths.length; _i++) {
  7295. var path = _baseSchemaPaths[_i];
  7296. if (schema.nested[path]) {
  7297. conflictingPaths.push(path);
  7298. continue;
  7299. }
  7300. if (path.indexOf('.') === -1) {
  7301. continue;
  7302. }
  7303. var sp = path.split('.').slice(0, -1);
  7304. var cur = '';
  7305. var _iterator = _createForOfIteratorHelper(sp),
  7306. _step;
  7307. try {
  7308. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  7309. var piece = _step.value;
  7310. cur += (cur.length ? '.' : '') + piece;
  7311. if (schema.paths[cur] instanceof Mixed || schema.singleNestedPaths[cur] instanceof Mixed) {
  7312. conflictingPaths.push(path);
  7313. }
  7314. }
  7315. } catch (err) {
  7316. _iterator.e(err);
  7317. } finally {
  7318. _iterator.f();
  7319. }
  7320. }
  7321. utils.merge(schema, baseSchema, {
  7322. isDiscriminatorSchemaMerge: true,
  7323. omit: {
  7324. discriminators: true,
  7325. base: true,
  7326. _applyDiscriminators: true
  7327. },
  7328. omitNested: conflictingPaths.reduce(function (cur, path) {
  7329. cur['tree.' + path] = true;
  7330. return cur;
  7331. }, {})
  7332. }); // Clean up conflicting paths _after_ merging re: gh-6076
  7333. for (var _i2 = 0, _conflictingPaths = conflictingPaths; _i2 < _conflictingPaths.length; _i2++) {
  7334. var conflictingPath = _conflictingPaths[_i2];
  7335. delete schema.paths[conflictingPath];
  7336. } // Rebuild schema models because schemas may have been merged re: #7884
  7337. schema.childSchemas.forEach(function (obj) {
  7338. obj.model.prototype.$__setSchema(obj.schema);
  7339. });
  7340. var obj = {};
  7341. obj[key] = {
  7342. "default": value,
  7343. select: true,
  7344. set: function set(newName) {
  7345. if (newName === value || Array.isArray(value) && utils.deepEqual(newName, value)) {
  7346. return value;
  7347. }
  7348. throw new Error('Can\'t set discriminator key "' + key + '"');
  7349. },
  7350. $skipDiscriminatorCheck: true
  7351. };
  7352. obj[key][schema.options.typeKey] = existingPath ? existingPath.options[schema.options.typeKey] : String;
  7353. schema.add(obj);
  7354. schema.discriminatorMapping = {
  7355. key: key,
  7356. value: value,
  7357. isRoot: false
  7358. };
  7359. if (baseSchema.options.collection) {
  7360. schema.options.collection = baseSchema.options.collection;
  7361. }
  7362. var toJSON = schema.options.toJSON;
  7363. var toObject = schema.options.toObject;
  7364. var _id = schema.options._id;
  7365. var id = schema.options.id;
  7366. var keys = Object.keys(schema.options);
  7367. schema.options.discriminatorKey = baseSchema.options.discriminatorKey;
  7368. for (var _i3 = 0, _keys = keys; _i3 < _keys.length; _i3++) {
  7369. var _key = _keys[_i3];
  7370. if (!CUSTOMIZABLE_DISCRIMINATOR_OPTIONS[_key]) {
  7371. // Special case: compiling a model sets `pluralization = true` by default. Avoid throwing an error
  7372. // for that case. See gh-9238
  7373. if (_key === 'pluralization' && schema.options[_key] == true && baseSchema.options[_key] == null) {
  7374. continue;
  7375. }
  7376. if (!utils.deepEqual(schema.options[_key], baseSchema.options[_key])) {
  7377. throw new Error('Can\'t customize discriminator option ' + _key + ' (can only modify ' + Object.keys(CUSTOMIZABLE_DISCRIMINATOR_OPTIONS).join(', ') + ')');
  7378. }
  7379. }
  7380. }
  7381. schema.options = utils.clone(baseSchema.options);
  7382. if (toJSON) schema.options.toJSON = toJSON;
  7383. if (toObject) schema.options.toObject = toObject;
  7384. if (typeof _id !== 'undefined') {
  7385. schema.options._id = _id;
  7386. }
  7387. schema.options.id = id;
  7388. schema.s.hooks = model.schema.s.hooks.merge(schema.s.hooks);
  7389. schema.plugins = Array.prototype.slice.call(baseSchema.plugins);
  7390. schema.callQueue = baseSchema.callQueue.concat(schema.callQueue);
  7391. delete schema._requiredpaths; // reset just in case Schema#requiredPaths() was called on either schema
  7392. } // merges base schema into new discriminator schema and sets new type field.
  7393. merge(schema, model.schema);
  7394. if (!model.discriminators) {
  7395. model.discriminators = {};
  7396. }
  7397. if (!model.schema.discriminatorMapping) {
  7398. model.schema.discriminatorMapping = {
  7399. key: key,
  7400. value: null,
  7401. isRoot: true
  7402. };
  7403. }
  7404. if (!model.schema.discriminators) {
  7405. model.schema.discriminators = {};
  7406. }
  7407. model.schema.discriminators[name] = schema;
  7408. if (model.discriminators[name] && !schema.options.overwriteModels) {
  7409. throw new Error('Discriminator with name "' + name + '" already exists');
  7410. }
  7411. return schema;
  7412. };
  7413. /***/ }),
  7414. /***/ 207:
  7415. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7416. "use strict";
  7417. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7418. var MongooseError = __webpack_require__(5202);
  7419. var setDottedPath = __webpack_require__(2736);
  7420. var util = __webpack_require__(161);
  7421. /**
  7422. * Given an object that may contain dotted paths, flatten the paths out.
  7423. * For example: `flattenObjectWithDottedPaths({ a: { 'b.c': 42 } })` => `{ a: { b: { c: 42 } } }`
  7424. */
  7425. module.exports = function flattenObjectWithDottedPaths(obj) {
  7426. if (obj == null || _typeof(obj) !== 'object' || Array.isArray(obj)) {
  7427. return;
  7428. } // Avoid Mongoose docs
  7429. if (obj.$__) {
  7430. return;
  7431. }
  7432. var keys = Object.keys(obj);
  7433. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  7434. var key = _keys[_i];
  7435. var val = obj[key];
  7436. if (key.indexOf('.') !== -1) {
  7437. try {
  7438. delete obj[key];
  7439. setDottedPath(obj, key, val);
  7440. } catch (err) {
  7441. if (!(err instanceof TypeError)) {
  7442. throw err;
  7443. }
  7444. throw new MongooseError("Conflicting dotted paths when setting document path, key: \"".concat(key, "\", value: ").concat(util.inspect(val)));
  7445. }
  7446. continue;
  7447. }
  7448. flattenObjectWithDottedPaths(obj[key]);
  7449. }
  7450. };
  7451. /***/ }),
  7452. /***/ 251:
  7453. /***/ ((module) => {
  7454. "use strict";
  7455. var dotRE = /\./g;
  7456. module.exports = function parentPaths(path) {
  7457. if (path.indexOf('.') === -1) {
  7458. return [path];
  7459. }
  7460. var pieces = path.split(dotRE);
  7461. var len = pieces.length;
  7462. var ret = new Array(len);
  7463. var cur = '';
  7464. for (var i = 0; i < len; ++i) {
  7465. cur += cur.length !== 0 ? '.' + pieces[i] : pieces[i];
  7466. ret[i] = cur;
  7467. }
  7468. return ret;
  7469. };
  7470. /***/ }),
  7471. /***/ 2736:
  7472. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7473. "use strict";
  7474. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  7475. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7476. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  7477. var specialProperties = __webpack_require__(2862);
  7478. module.exports = function setDottedPath(obj, path, val) {
  7479. if (path.indexOf('.') === -1) {
  7480. if (specialProperties.has(path)) {
  7481. return;
  7482. }
  7483. obj[path] = val;
  7484. return;
  7485. }
  7486. var parts = path.split('.');
  7487. var last = parts.pop();
  7488. var cur = obj;
  7489. var _iterator = _createForOfIteratorHelper(parts),
  7490. _step;
  7491. try {
  7492. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  7493. var part = _step.value;
  7494. if (specialProperties.has(part)) {
  7495. continue;
  7496. }
  7497. if (cur[part] == null) {
  7498. cur[part] = {};
  7499. }
  7500. cur = cur[part];
  7501. }
  7502. } catch (err) {
  7503. _iterator.e(err);
  7504. } finally {
  7505. _iterator.f();
  7506. }
  7507. if (!specialProperties.has(last)) {
  7508. cur[last] = val;
  7509. }
  7510. };
  7511. /***/ }),
  7512. /***/ 5837:
  7513. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7514. "use strict";
  7515. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  7516. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  7517. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  7518. var utils = __webpack_require__(6872);
  7519. /*!
  7520. * If populating a path within a document array, make sure each
  7521. * subdoc within the array knows its subpaths are populated.
  7522. *
  7523. * #### Example:
  7524. * const doc = await Article.findOne().populate('comments.author');
  7525. * doc.comments[0].populated('author'); // Should be set
  7526. */
  7527. module.exports = function markArraySubdocsPopulated(doc, populated) {
  7528. if (doc._id == null || populated == null || populated.length === 0) {
  7529. return;
  7530. }
  7531. var id = String(doc._id);
  7532. var _iterator = _createForOfIteratorHelper(populated),
  7533. _step;
  7534. try {
  7535. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  7536. var item = _step.value;
  7537. if (item.isVirtual) {
  7538. continue;
  7539. }
  7540. var path = item.path;
  7541. var pieces = path.split('.');
  7542. for (var i = 0; i < pieces.length - 1; ++i) {
  7543. var subpath = pieces.slice(0, i + 1).join('.');
  7544. var rest = pieces.slice(i + 1).join('.');
  7545. var val = doc.get(subpath);
  7546. if (val == null) {
  7547. continue;
  7548. }
  7549. if (utils.isMongooseDocumentArray(val)) {
  7550. for (var j = 0; j < val.length; ++j) {
  7551. val[j].populated(rest, item._docs[id] == null ? void 0 : item._docs[id][j], item);
  7552. }
  7553. break;
  7554. }
  7555. }
  7556. }
  7557. } catch (err) {
  7558. _iterator.e(err);
  7559. } finally {
  7560. _iterator.f();
  7561. }
  7562. };
  7563. /***/ }),
  7564. /***/ 6870:
  7565. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7566. "use strict";
  7567. var MongooseError = __webpack_require__(5202);
  7568. var util = __webpack_require__(161);
  7569. module.exports = validateRef;
  7570. function validateRef(ref, path) {
  7571. if (typeof ref === 'string') {
  7572. return;
  7573. }
  7574. if (typeof ref === 'function') {
  7575. return;
  7576. }
  7577. throw new MongooseError('Invalid ref at path "' + path + '". Got ' + util.inspect(ref, {
  7578. depth: 0
  7579. }));
  7580. }
  7581. /***/ }),
  7582. /***/ 7427:
  7583. /***/ ((module) => {
  7584. "use strict";
  7585. /*!
  7586. * Creates an object that precomputes whether a given path has child fields in
  7587. * the projection.
  7588. *
  7589. * #### Example:
  7590. * const res = hasIncludedChildren({ 'a.b.c': 0 });
  7591. * res.a; // 1
  7592. * res['a.b']; // 1
  7593. * res['a.b.c']; // 1
  7594. * res['a.c']; // undefined
  7595. */
  7596. module.exports = function hasIncludedChildren(fields) {
  7597. var hasIncludedChildren = {};
  7598. var keys = Object.keys(fields);
  7599. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  7600. var key = _keys[_i];
  7601. if (key.indexOf('.') === -1) {
  7602. hasIncludedChildren[key] = 1;
  7603. continue;
  7604. }
  7605. var parts = key.split('.');
  7606. var c = parts[0];
  7607. for (var i = 0; i < parts.length; ++i) {
  7608. hasIncludedChildren[c] = 1;
  7609. if (i + 1 < parts.length) {
  7610. c = c + '.' + parts[i + 1];
  7611. }
  7612. }
  7613. }
  7614. return hasIncludedChildren;
  7615. };
  7616. /***/ }),
  7617. /***/ 2183:
  7618. /***/ ((module) => {
  7619. "use strict";
  7620. /*!
  7621. * ignore
  7622. */
  7623. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7624. module.exports = function isDefiningProjection(val) {
  7625. if (val == null) {
  7626. // `undefined` or `null` become exclusive projections
  7627. return true;
  7628. }
  7629. if (_typeof(val) === 'object') {
  7630. // Only cases where a value does **not** define whether the whole projection
  7631. // is inclusive or exclusive are `$meta` and `$slice`.
  7632. return !('$meta' in val) && !('$slice' in val);
  7633. }
  7634. return true;
  7635. };
  7636. /***/ }),
  7637. /***/ 9098:
  7638. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7639. "use strict";
  7640. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7641. var isDefiningProjection = __webpack_require__(2183);
  7642. /*!
  7643. * ignore
  7644. */
  7645. module.exports = function isExclusive(projection) {
  7646. if (projection == null) {
  7647. return null;
  7648. }
  7649. var keys = Object.keys(projection);
  7650. var ki = keys.length;
  7651. var exclude = null;
  7652. if (ki === 1 && keys[0] === '_id') {
  7653. exclude = !projection._id;
  7654. } else {
  7655. while (ki--) {
  7656. // Does this projection explicitly define inclusion/exclusion?
  7657. // Explicitly avoid `$meta` and `$slice`
  7658. var key = keys[ki];
  7659. if (key !== '_id' && isDefiningProjection(projection[key])) {
  7660. exclude = projection[key] != null && _typeof(projection[key]) === 'object' ? isExclusive(projection[key]) : !projection[key];
  7661. break;
  7662. }
  7663. }
  7664. }
  7665. return exclude;
  7666. };
  7667. /***/ }),
  7668. /***/ 8486:
  7669. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7670. "use strict";
  7671. var PromiseProvider = __webpack_require__(6755);
  7672. var immediate = __webpack_require__(1490);
  7673. var emittedSymbol = Symbol('mongoose:emitted');
  7674. module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
  7675. if (typeof callback === 'function') {
  7676. return fn(function (error) {
  7677. if (error != null) {
  7678. if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
  7679. error[emittedSymbol] = true;
  7680. ee.emit('error', error);
  7681. }
  7682. try {
  7683. callback(error);
  7684. } catch (error) {
  7685. return immediate(function () {
  7686. throw error;
  7687. });
  7688. }
  7689. return;
  7690. }
  7691. callback.apply(this, arguments);
  7692. });
  7693. }
  7694. Promise = Promise || PromiseProvider.get();
  7695. return new Promise(function (resolve, reject) {
  7696. fn(function (error, res) {
  7697. if (error != null) {
  7698. if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
  7699. error[emittedSymbol] = true;
  7700. ee.emit('error', error);
  7701. }
  7702. return reject(error);
  7703. }
  7704. if (arguments.length > 2) {
  7705. return resolve(Array.prototype.slice.call(arguments, 1));
  7706. }
  7707. resolve(res);
  7708. });
  7709. });
  7710. };
  7711. /***/ }),
  7712. /***/ 5130:
  7713. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7714. "use strict";
  7715. /*!
  7716. * ignore
  7717. */
  7718. module.exports = applyQueryMiddleware;
  7719. var validOps = __webpack_require__(9853);
  7720. /*!
  7721. * ignore
  7722. */
  7723. applyQueryMiddleware.middlewareFunctions = validOps.concat(['validate']);
  7724. /*!
  7725. * Apply query middleware
  7726. *
  7727. * @param {Query} query constructor
  7728. * @param {Model} model
  7729. */
  7730. function applyQueryMiddleware(Query, model) {
  7731. var kareemOptions = {
  7732. useErrorHandlers: true,
  7733. numCallbackParams: 1,
  7734. nullResultByDefault: true
  7735. };
  7736. var middleware = model.hooks.filter(function (hook) {
  7737. var contexts = _getContexts(hook);
  7738. if (hook.name === 'updateOne') {
  7739. return contexts.query == null || !!contexts.query;
  7740. }
  7741. if (hook.name === 'deleteOne') {
  7742. return !!contexts.query || Object.keys(contexts).length === 0;
  7743. }
  7744. if (hook.name === 'validate' || hook.name === 'remove') {
  7745. return !!contexts.query;
  7746. }
  7747. if (hook.query != null || hook.document != null) {
  7748. return !!hook.query;
  7749. }
  7750. return true;
  7751. }); // `update()` thunk has a different name because `_update` was already taken
  7752. Query.prototype._execUpdate = middleware.createWrapper('update', Query.prototype._execUpdate, null, kareemOptions); // `distinct()` thunk has a different name because `_distinct` was already taken
  7753. Query.prototype.__distinct = middleware.createWrapper('distinct', Query.prototype.__distinct, null, kareemOptions); // `validate()` doesn't have a thunk because it doesn't execute a query.
  7754. Query.prototype.validate = middleware.createWrapper('validate', Query.prototype.validate, null, kareemOptions);
  7755. applyQueryMiddleware.middlewareFunctions.filter(function (v) {
  7756. return v !== 'update' && v !== 'distinct' && v !== 'validate';
  7757. }).forEach(function (fn) {
  7758. Query.prototype["_".concat(fn)] = middleware.createWrapper(fn, Query.prototype["_".concat(fn)], null, kareemOptions);
  7759. });
  7760. }
  7761. function _getContexts(hook) {
  7762. var ret = {};
  7763. if (hook.hasOwnProperty('query')) {
  7764. ret.query = hook.query;
  7765. }
  7766. if (hook.hasOwnProperty('document')) {
  7767. ret.document = hook.document;
  7768. }
  7769. return ret;
  7770. }
  7771. /***/ }),
  7772. /***/ 9739:
  7773. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  7774. "use strict";
  7775. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  7776. var CastError = __webpack_require__(1795);
  7777. var StrictModeError = __webpack_require__(3328);
  7778. var castNumber = __webpack_require__(3065);
  7779. var booleanComparison = new Set(['$and', '$or']);
  7780. var comparisonOperator = new Set(['$cmp', '$eq', '$lt', '$lte', '$gt', '$gte']);
  7781. var arithmeticOperatorArray = new Set([// avoid casting '$add' or '$subtract', because expressions can be either number or date,
  7782. // and we don't have a good way of inferring which arguments should be numbers and which should
  7783. // be dates.
  7784. '$multiply', '$divide', '$log', '$mod', '$trunc', '$avg', '$max', '$min', '$stdDevPop', '$stdDevSamp', '$sum']);
  7785. var arithmeticOperatorNumber = new Set(['$abs', '$exp', '$ceil', '$floor', '$ln', '$log10', '$round', '$sqrt', '$sin', '$cos', '$tan', '$asin', '$acos', '$atan', '$atan2', '$asinh', '$acosh', '$atanh', '$sinh', '$cosh', '$tanh', '$degreesToRadians', '$radiansToDegrees']);
  7786. var arrayElementOperators = new Set(['$arrayElemAt', '$first', '$last']);
  7787. var dateOperators = new Set(['$year', '$month', '$week', '$dayOfMonth', '$dayOfYear', '$hour', '$minute', '$second', '$isoDayOfWeek', '$isoWeekYear', '$isoWeek', '$millisecond']);
  7788. var expressionOperator = new Set(['$not']);
  7789. module.exports = function cast$expr(val, schema, strictQuery) {
  7790. if (_typeof(val) !== 'object' || val === null) {
  7791. throw new Error('`$expr` must be an object');
  7792. }
  7793. return _castExpression(val, schema, strictQuery);
  7794. };
  7795. function _castExpression(val, schema, strictQuery) {
  7796. if (isPath(val)) {
  7797. // Assume path
  7798. return val;
  7799. }
  7800. if (val.$cond != null) {
  7801. if (Array.isArray(val.$cond)) {
  7802. val.$cond = val.$cond.map(function (expr) {
  7803. return _castExpression(expr, schema, strictQuery);
  7804. });
  7805. } else {
  7806. val.$cond["if"] = _castExpression(val.$cond["if"], schema, strictQuery);
  7807. val.$cond.then = _castExpression(val.$cond.then, schema, strictQuery);
  7808. val.$cond["else"] = _castExpression(val.$cond["else"], schema, strictQuery);
  7809. }
  7810. } else if (val.$ifNull != null) {
  7811. val.$ifNull.map(function (v) {
  7812. return _castExpression(v, schema, strictQuery);
  7813. });
  7814. } else if (val.$switch != null) {
  7815. val.branches.map(function (v) {
  7816. return _castExpression(v, schema, strictQuery);
  7817. });
  7818. val["default"] = _castExpression(val["default"], schema, strictQuery);
  7819. }
  7820. var keys = Object.keys(val);
  7821. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  7822. var key = _keys[_i];
  7823. if (booleanComparison.has(key)) {
  7824. val[key] = val[key].map(function (v) {
  7825. return _castExpression(v, schema, strictQuery);
  7826. });
  7827. } else if (comparisonOperator.has(key)) {
  7828. val[key] = castComparison(val[key], schema, strictQuery);
  7829. } else if (arithmeticOperatorArray.has(key)) {
  7830. val[key] = castArithmetic(val[key], schema, strictQuery);
  7831. } else if (arithmeticOperatorNumber.has(key)) {
  7832. val[key] = castNumberOperator(val[key], schema, strictQuery);
  7833. } else if (expressionOperator.has(key)) {
  7834. val[key] = _castExpression(val[key], schema, strictQuery);
  7835. }
  7836. }
  7837. if (val.$in) {
  7838. val.$in = castIn(val.$in, schema, strictQuery);
  7839. }
  7840. if (val.$size) {
  7841. val.$size = castNumberOperator(val.$size, schema, strictQuery);
  7842. }
  7843. _omitUndefined(val);
  7844. return val;
  7845. }
  7846. function _omitUndefined(val) {
  7847. var keys = Object.keys(val);
  7848. for (var i = 0, len = keys.length; i < len; ++i) {
  7849. val[keys[i]] === void 0 && delete val[keys[i]];
  7850. }
  7851. } // { $op: <number> }
  7852. function castNumberOperator(val) {
  7853. if (!isLiteral(val)) {
  7854. return val;
  7855. }
  7856. try {
  7857. return castNumber(val);
  7858. } catch (err) {
  7859. throw new CastError('Number', val);
  7860. }
  7861. }
  7862. function castIn(val, schema, strictQuery) {
  7863. var path = val[1];
  7864. if (!isPath(path)) {
  7865. return val;
  7866. }
  7867. var search = val[0];
  7868. var schematype = schema.path(path.slice(1));
  7869. if (schematype === null) {
  7870. if (strictQuery === false) {
  7871. return val;
  7872. } else if (strictQuery === 'throw') {
  7873. throw new StrictModeError('$in');
  7874. }
  7875. return void 0;
  7876. }
  7877. if (!schematype.$isMongooseArray) {
  7878. throw new Error('Path must be an array for $in');
  7879. }
  7880. return [schematype.$isMongooseDocumentArray ? schematype.$embeddedSchemaType.cast(search) : schematype.caster.cast(search), path];
  7881. } // { $op: [<number>, <number>] }
  7882. function castArithmetic(val) {
  7883. if (!Array.isArray(val)) {
  7884. if (!isLiteral(val)) {
  7885. return val;
  7886. }
  7887. try {
  7888. return castNumber(val);
  7889. } catch (err) {
  7890. throw new CastError('Number', val);
  7891. }
  7892. }
  7893. return val.map(function (v) {
  7894. if (!isLiteral(v)) {
  7895. return v;
  7896. }
  7897. try {
  7898. return castNumber(v);
  7899. } catch (err) {
  7900. throw new CastError('Number', v);
  7901. }
  7902. });
  7903. } // { $op: [expression, expression] }
  7904. function castComparison(val, schema, strictQuery) {
  7905. if (!Array.isArray(val) || val.length !== 2) {
  7906. throw new Error('Comparison operator must be an array of length 2');
  7907. }
  7908. val[0] = _castExpression(val[0], schema, strictQuery);
  7909. var lhs = val[0];
  7910. if (isLiteral(val[1])) {
  7911. var path = null;
  7912. var schematype = null;
  7913. var caster = null;
  7914. if (isPath(lhs)) {
  7915. path = lhs.slice(1);
  7916. schematype = schema.path(path);
  7917. } else if (_typeof(lhs) === 'object' && lhs != null) {
  7918. for (var _i2 = 0, _Object$keys = Object.keys(lhs); _i2 < _Object$keys.length; _i2++) {
  7919. var key = _Object$keys[_i2];
  7920. if (dateOperators.has(key) && isPath(lhs[key])) {
  7921. path = lhs[key].slice(1) + '.' + key;
  7922. caster = castNumber;
  7923. } else if (arrayElementOperators.has(key) && isPath(lhs[key])) {
  7924. path = lhs[key].slice(1) + '.' + key;
  7925. schematype = schema.path(lhs[key].slice(1));
  7926. if (schematype != null) {
  7927. if (schematype.$isMongooseDocumentArray) {
  7928. schematype = schematype.$embeddedSchemaType;
  7929. } else if (schematype.$isMongooseArray) {
  7930. schematype = schematype.caster;
  7931. }
  7932. }
  7933. }
  7934. }
  7935. }
  7936. var is$literal = _typeof(val[1]) === 'object' && val[1] != null && val[1].$literal != null;
  7937. if (schematype != null) {
  7938. if (is$literal) {
  7939. val[1] = {
  7940. $literal: schematype.cast(val[1].$literal)
  7941. };
  7942. } else {
  7943. val[1] = schematype.cast(val[1]);
  7944. }
  7945. } else if (caster != null) {
  7946. if (is$literal) {
  7947. try {
  7948. val[1] = {
  7949. $literal: caster(val[1].$literal)
  7950. };
  7951. } catch (err) {
  7952. throw new CastError(caster.name.replace(/^cast/, ''), val[1], path + '.$literal');
  7953. }
  7954. } else {
  7955. try {
  7956. val[1] = caster(val[1]);
  7957. } catch (err) {
  7958. throw new CastError(caster.name.replace(/^cast/, ''), val[1], path);
  7959. }
  7960. }
  7961. } else if (path != null && strictQuery === true) {
  7962. return void 0;
  7963. } else if (path != null && strictQuery === 'throw') {
  7964. throw new StrictModeError(path);
  7965. }
  7966. } else {
  7967. val[1] = _castExpression(val[1]);
  7968. }
  7969. return val;
  7970. }
  7971. function isPath(val) {
  7972. return typeof val === 'string' && val[0] === '$';
  7973. }
  7974. function isLiteral(val) {
  7975. if (typeof val === 'string' && val[0] === '$') {
  7976. return false;
  7977. }
  7978. if (_typeof(val) === 'object' && val !== null && Object.keys(val).find(function (key) {
  7979. return key[0] === '$';
  7980. })) {
  7981. // The `$literal` expression can make an object a literal
  7982. // https://docs.mongodb.com/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal
  7983. return val.$literal != null;
  7984. }
  7985. return true;
  7986. }
  7987. /***/ }),
  7988. /***/ 9627:
  7989. /***/ ((module) => {
  7990. "use strict";
  7991. var specialKeys = new Set(['$ref', '$id', '$db']);
  7992. module.exports = function isOperator(path) {
  7993. return path[0] === '$' && !specialKeys.has(path);
  7994. };
  7995. /***/ }),
  7996. /***/ 3636:
  7997. /***/ ((__unused_webpack_module, exports) => {
  7998. "use strict";
  7999. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  8000. var trustedSymbol = Symbol('mongoose#trustedSymbol');
  8001. exports.trustedSymbol = trustedSymbol;
  8002. exports.trusted = function trusted(obj) {
  8003. if (obj == null || _typeof(obj) !== 'object') {
  8004. return obj;
  8005. }
  8006. obj[trustedSymbol] = true;
  8007. return obj;
  8008. };
  8009. /***/ }),
  8010. /***/ 9853:
  8011. /***/ ((module) => {
  8012. "use strict";
  8013. module.exports = Object.freeze([// Read
  8014. 'count', 'countDocuments', 'distinct', 'estimatedDocumentCount', 'find', 'findOne', // Update
  8015. 'findOneAndReplace', 'findOneAndUpdate', 'replaceOne', 'update', 'updateMany', 'updateOne', // Delete
  8016. 'deleteMany', 'deleteOne', 'findOneAndDelete', 'findOneAndRemove', 'remove']);
  8017. /***/ }),
  8018. /***/ 4133:
  8019. /***/ ((module) => {
  8020. "use strict";
  8021. module.exports = function addAutoId(schema) {
  8022. var _obj = {
  8023. _id: {
  8024. auto: true
  8025. }
  8026. };
  8027. _obj._id[schema.options.typeKey] = 'ObjectId';
  8028. schema.add(_obj);
  8029. };
  8030. /***/ }),
  8031. /***/ 7658:
  8032. /***/ ((module) => {
  8033. "use strict";
  8034. /**
  8035. * For consistency's sake, we replace positional operator `$` and array filters
  8036. * `$[]` and `$[foo]` with `0` when looking up schema paths.
  8037. */
  8038. module.exports = function cleanPositionalOperators(path) {
  8039. return path.replace(/\.\$(\[[^\]]*\])?(?=\.)/g, '.0').replace(/\.\$(\[[^\]]*\])?$/g, '.0');
  8040. };
  8041. /***/ }),
  8042. /***/ 5379:
  8043. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8044. "use strict";
  8045. var get = __webpack_require__(9981);
  8046. var helperIsObject = __webpack_require__(5721);
  8047. var decorateDiscriminatorIndexOptions = __webpack_require__(1605);
  8048. /*!
  8049. * Gather all indexes defined in the schema, including single nested,
  8050. * document arrays, and embedded discriminators.
  8051. */
  8052. module.exports = function getIndexes(schema) {
  8053. var indexes = [];
  8054. var schemaStack = new WeakMap();
  8055. var indexTypes = schema.constructor.indexTypes;
  8056. var indexByName = new Map();
  8057. collectIndexes(schema);
  8058. return indexes;
  8059. function collectIndexes(schema, prefix, baseSchema) {
  8060. // Ignore infinitely nested schemas, if we've already seen this schema
  8061. // along this path there must be a cycle
  8062. if (schemaStack.has(schema)) {
  8063. return;
  8064. }
  8065. schemaStack.set(schema, true);
  8066. prefix = prefix || '';
  8067. var keys = Object.keys(schema.paths);
  8068. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  8069. var key = _keys[_i];
  8070. var path = schema.paths[key];
  8071. if (baseSchema != null && baseSchema.paths[key]) {
  8072. // If looking at an embedded discriminator schema, don't look at paths
  8073. // that the
  8074. continue;
  8075. }
  8076. if (path.$isMongooseDocumentArray || path.$isSingleNested) {
  8077. if (get(path, 'options.excludeIndexes') !== true && get(path, 'schemaOptions.excludeIndexes') !== true && get(path, 'schema.options.excludeIndexes') !== true) {
  8078. collectIndexes(path.schema, prefix + key + '.');
  8079. }
  8080. if (path.schema.discriminators != null) {
  8081. var discriminators = path.schema.discriminators;
  8082. var discriminatorKeys = Object.keys(discriminators);
  8083. for (var _i2 = 0, _discriminatorKeys = discriminatorKeys; _i2 < _discriminatorKeys.length; _i2++) {
  8084. var discriminatorKey = _discriminatorKeys[_i2];
  8085. collectIndexes(discriminators[discriminatorKey], prefix + key + '.', path.schema);
  8086. }
  8087. } // Retained to minimize risk of backwards breaking changes due to
  8088. // gh-6113
  8089. if (path.$isMongooseDocumentArray) {
  8090. continue;
  8091. }
  8092. }
  8093. var index = path._index || path.caster && path.caster._index;
  8094. if (index !== false && index !== null && index !== undefined) {
  8095. var field = {};
  8096. var isObject = helperIsObject(index);
  8097. var options = isObject ? index : {};
  8098. var type = typeof index === 'string' ? index : isObject ? index.type : false;
  8099. if (type && indexTypes.indexOf(type) !== -1) {
  8100. field[prefix + key] = type;
  8101. } else if (options.text) {
  8102. field[prefix + key] = 'text';
  8103. delete options.text;
  8104. } else {
  8105. var isDescendingIndex = Number(index) === -1;
  8106. field[prefix + key] = isDescendingIndex ? -1 : 1;
  8107. }
  8108. delete options.type;
  8109. if (!('background' in options)) {
  8110. options.background = true;
  8111. }
  8112. if (schema.options.autoIndex != null) {
  8113. options._autoIndex = schema.options.autoIndex;
  8114. }
  8115. var indexName = options && options.name;
  8116. if (typeof indexName === 'string') {
  8117. if (indexByName.has(indexName)) {
  8118. Object.assign(indexByName.get(indexName), field);
  8119. } else {
  8120. indexes.push([field, options]);
  8121. indexByName.set(indexName, field);
  8122. }
  8123. } else {
  8124. indexes.push([field, options]);
  8125. indexByName.set(indexName, field);
  8126. }
  8127. }
  8128. }
  8129. schemaStack["delete"](schema);
  8130. if (prefix) {
  8131. fixSubIndexPaths(schema, prefix);
  8132. } else {
  8133. schema._indexes.forEach(function (index) {
  8134. var options = index[1];
  8135. if (!('background' in options)) {
  8136. options.background = true;
  8137. }
  8138. decorateDiscriminatorIndexOptions(schema, options);
  8139. });
  8140. indexes = indexes.concat(schema._indexes);
  8141. }
  8142. }
  8143. /*!
  8144. * Checks for indexes added to subdocs using Schema.index().
  8145. * These indexes need their paths prefixed properly.
  8146. *
  8147. * schema._indexes = [ [indexObj, options], [indexObj, options] ..]
  8148. */
  8149. function fixSubIndexPaths(schema, prefix) {
  8150. var subindexes = schema._indexes;
  8151. var len = subindexes.length;
  8152. for (var i = 0; i < len; ++i) {
  8153. var indexObj = subindexes[i][0];
  8154. var indexOptions = subindexes[i][1];
  8155. var keys = Object.keys(indexObj);
  8156. var klen = keys.length;
  8157. var newindex = {}; // use forward iteration, order matters
  8158. for (var j = 0; j < klen; ++j) {
  8159. var key = keys[j];
  8160. newindex[prefix + key] = indexObj[key];
  8161. }
  8162. var newIndexOptions = Object.assign({}, indexOptions);
  8163. if (indexOptions != null && indexOptions.partialFilterExpression != null) {
  8164. newIndexOptions.partialFilterExpression = {};
  8165. var partialFilterExpression = indexOptions.partialFilterExpression;
  8166. for (var _i3 = 0, _Object$keys = Object.keys(partialFilterExpression); _i3 < _Object$keys.length; _i3++) {
  8167. var _key = _Object$keys[_i3];
  8168. newIndexOptions.partialFilterExpression[prefix + _key] = partialFilterExpression[_key];
  8169. }
  8170. }
  8171. indexes.push([newindex, newIndexOptions]);
  8172. }
  8173. }
  8174. };
  8175. /***/ }),
  8176. /***/ 37:
  8177. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8178. "use strict";
  8179. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  8180. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  8181. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  8182. var get = __webpack_require__(9981);
  8183. module.exports = function getKeysInSchemaOrder(schema, val, path) {
  8184. var schemaKeys = path != null ? Object.keys(get(schema.tree, path, {})) : Object.keys(schema.tree);
  8185. var valKeys = new Set(Object.keys(val));
  8186. var keys;
  8187. if (valKeys.size > 1) {
  8188. keys = new Set();
  8189. var _iterator = _createForOfIteratorHelper(schemaKeys),
  8190. _step;
  8191. try {
  8192. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  8193. var key = _step.value;
  8194. if (valKeys.has(key)) {
  8195. keys.add(key);
  8196. }
  8197. }
  8198. } catch (err) {
  8199. _iterator.e(err);
  8200. } finally {
  8201. _iterator.f();
  8202. }
  8203. var _iterator2 = _createForOfIteratorHelper(valKeys),
  8204. _step2;
  8205. try {
  8206. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  8207. var _key = _step2.value;
  8208. if (!keys.has(_key)) {
  8209. keys.add(_key);
  8210. }
  8211. }
  8212. } catch (err) {
  8213. _iterator2.e(err);
  8214. } finally {
  8215. _iterator2.f();
  8216. }
  8217. keys = Array.from(keys);
  8218. } else {
  8219. keys = Array.from(valKeys);
  8220. }
  8221. return keys;
  8222. };
  8223. /***/ }),
  8224. /***/ 9691:
  8225. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8226. "use strict";
  8227. var addAutoId = __webpack_require__(4133);
  8228. module.exports = function handleIdOption(schema, options) {
  8229. if (options == null || options._id == null) {
  8230. return schema;
  8231. }
  8232. schema = schema.clone();
  8233. if (!options._id) {
  8234. schema.remove('_id');
  8235. schema.options._id = false;
  8236. } else if (!schema.paths['_id']) {
  8237. addAutoId(schema);
  8238. schema.options._id = true;
  8239. }
  8240. return schema;
  8241. };
  8242. /***/ }),
  8243. /***/ 6370:
  8244. /***/ ((module) => {
  8245. "use strict";
  8246. module.exports = handleTimestampOption;
  8247. /*!
  8248. * ignore
  8249. */
  8250. function handleTimestampOption(arg, prop) {
  8251. if (arg == null) {
  8252. return null;
  8253. }
  8254. if (typeof arg === 'boolean') {
  8255. return prop;
  8256. }
  8257. if (typeof arg[prop] === 'boolean') {
  8258. return arg[prop] ? prop : null;
  8259. }
  8260. if (!(prop in arg)) {
  8261. return prop;
  8262. }
  8263. return arg[prop];
  8264. }
  8265. /***/ }),
  8266. /***/ 1879:
  8267. /***/ ((module) => {
  8268. "use strict";
  8269. /*!
  8270. * ignore
  8271. */
  8272. module.exports = function addIdGetter(schema) {
  8273. // ensure the documents receive an id getter unless disabled
  8274. var autoIdGetter = !schema.paths['id'] && schema.paths['_id'] && schema.options.id;
  8275. if (!autoIdGetter) {
  8276. return schema;
  8277. }
  8278. schema.virtual('id').get(idGetter);
  8279. return schema;
  8280. };
  8281. /*!
  8282. * Returns this documents _id cast to a string.
  8283. */
  8284. function idGetter() {
  8285. if (this._id != null) {
  8286. return String(this._id);
  8287. }
  8288. return null;
  8289. }
  8290. /***/ }),
  8291. /***/ 4913:
  8292. /***/ ((module) => {
  8293. "use strict";
  8294. module.exports = function merge(s1, s2, skipConflictingPaths) {
  8295. var paths = Object.keys(s2.tree);
  8296. var pathsToAdd = {};
  8297. for (var _i = 0, _paths = paths; _i < _paths.length; _i++) {
  8298. var key = _paths[_i];
  8299. if (skipConflictingPaths && (s1.paths[key] || s1.nested[key] || s1.singleNestedPaths[key])) {
  8300. continue;
  8301. }
  8302. pathsToAdd[key] = s2.tree[key];
  8303. }
  8304. s1.add(pathsToAdd);
  8305. s1.callQueue = s1.callQueue.concat(s2.callQueue);
  8306. s1.method(s2.methods);
  8307. s1["static"](s2.statics);
  8308. for (var query in s2.query) {
  8309. s1.query[query] = s2.query[query];
  8310. }
  8311. for (var virtual in s2.virtuals) {
  8312. s1.virtuals[virtual] = s2.virtuals[virtual].clone();
  8313. }
  8314. s1.s.hooks.merge(s2.s.hooks, false);
  8315. };
  8316. /***/ }),
  8317. /***/ 8828:
  8318. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8319. "use strict";
  8320. var StrictModeError = __webpack_require__(3328);
  8321. /*!
  8322. * ignore
  8323. */
  8324. module.exports = function (schematype) {
  8325. if (schematype.$immutable) {
  8326. schematype.$immutableSetter = createImmutableSetter(schematype.path, schematype.options.immutable);
  8327. schematype.set(schematype.$immutableSetter);
  8328. } else if (schematype.$immutableSetter) {
  8329. schematype.setters = schematype.setters.filter(function (fn) {
  8330. return fn !== schematype.$immutableSetter;
  8331. });
  8332. delete schematype.$immutableSetter;
  8333. }
  8334. };
  8335. function createImmutableSetter(path, immutable) {
  8336. return function immutableSetter(v, _priorVal, _doc, options) {
  8337. if (this == null || this.$__ == null) {
  8338. return v;
  8339. }
  8340. if (this.isNew) {
  8341. return v;
  8342. }
  8343. if (options && options.overwriteImmutable) {
  8344. return v;
  8345. }
  8346. var _immutable = typeof immutable === 'function' ? immutable.call(this, this) : immutable;
  8347. if (!_immutable) {
  8348. return v;
  8349. }
  8350. var _value = this.$__.priorDoc != null ? this.$__.priorDoc.$__getValue(path) : this.$__getValue(path);
  8351. if (this.$__.strictMode === 'throw' && v !== _value) {
  8352. throw new StrictModeError(path, 'Path `' + path + '` is immutable ' + 'and strict mode is set to throw.', true);
  8353. }
  8354. return _value;
  8355. };
  8356. }
  8357. /***/ }),
  8358. /***/ 2862:
  8359. /***/ ((module) => {
  8360. "use strict";
  8361. module.exports = new Set(['__proto__', 'constructor', 'prototype']);
  8362. /***/ }),
  8363. /***/ 8770:
  8364. /***/ ((__unused_webpack_module, exports) => {
  8365. "use strict";
  8366. exports.arrayAtomicsBackupSymbol = Symbol('mongoose#Array#atomicsBackup');
  8367. exports.arrayAtomicsSymbol = Symbol('mongoose#Array#_atomics');
  8368. exports.arrayParentSymbol = Symbol('mongoose#Array#_parent');
  8369. exports.arrayPathSymbol = Symbol('mongoose#Array#_path');
  8370. exports.arraySchemaSymbol = Symbol('mongoose#Array#_schema');
  8371. exports.documentArrayParent = Symbol('mongoose:documentArrayParent');
  8372. exports.documentIsSelected = Symbol('mongoose#Document#isSelected');
  8373. exports.documentIsModified = Symbol('mongoose#Document#isModified');
  8374. exports.documentModifiedPaths = Symbol('mongoose#Document#modifiedPaths');
  8375. exports.documentSchemaSymbol = Symbol('mongoose#Document#schema');
  8376. exports.getSymbol = Symbol('mongoose#Document#get');
  8377. exports.modelSymbol = Symbol('mongoose#Model');
  8378. exports.objectIdSymbol = Symbol('mongoose#ObjectId');
  8379. exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
  8380. exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
  8381. exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
  8382. exports.scopeSymbol = Symbol('mongoose#Document#scope');
  8383. exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
  8384. /***/ }),
  8385. /***/ 3767:
  8386. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8387. "use strict";
  8388. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8389. var applyTimestampsToChildren = __webpack_require__(4843);
  8390. var applyTimestampsToUpdate = __webpack_require__(6434);
  8391. var get = __webpack_require__(9981);
  8392. var handleTimestampOption = __webpack_require__(6370);
  8393. var symbols = __webpack_require__(8107);
  8394. module.exports = function setupTimestamps(schema, timestamps) {
  8395. var childHasTimestamp = schema.childSchemas.find(withTimestamp);
  8396. function withTimestamp(s) {
  8397. var ts = s.schema.options.timestamps;
  8398. return !!ts;
  8399. }
  8400. if (!timestamps && !childHasTimestamp) {
  8401. return;
  8402. }
  8403. var createdAt = handleTimestampOption(timestamps, 'createdAt');
  8404. var updatedAt = handleTimestampOption(timestamps, 'updatedAt');
  8405. var currentTime = timestamps != null && timestamps.hasOwnProperty('currentTime') ? timestamps.currentTime : null;
  8406. var schemaAdditions = {};
  8407. schema.$timestamps = {
  8408. createdAt: createdAt,
  8409. updatedAt: updatedAt
  8410. };
  8411. if (updatedAt && !schema.paths[updatedAt]) {
  8412. schemaAdditions[updatedAt] = Date;
  8413. }
  8414. if (createdAt && !schema.paths[createdAt]) {
  8415. var _schemaAdditions$crea;
  8416. var baseImmutableCreatedAt = schema.base.get('timestamps.createdAt.immutable');
  8417. var immutable = baseImmutableCreatedAt != null ? baseImmutableCreatedAt : true;
  8418. schemaAdditions[createdAt] = (_schemaAdditions$crea = {}, _defineProperty(_schemaAdditions$crea, schema.options.typeKey || 'type', Date), _defineProperty(_schemaAdditions$crea, "immutable", immutable), _schemaAdditions$crea);
  8419. }
  8420. schema.add(schemaAdditions);
  8421. schema.pre('save', function (next) {
  8422. var timestampOption = get(this, '$__.saveOptions.timestamps');
  8423. if (timestampOption === false) {
  8424. return next();
  8425. }
  8426. var skipUpdatedAt = timestampOption != null && timestampOption.updatedAt === false;
  8427. var skipCreatedAt = timestampOption != null && timestampOption.createdAt === false;
  8428. var defaultTimestamp = currentTime != null ? currentTime() : this.ownerDocument().constructor.base.now();
  8429. if (!skipCreatedAt && (this.isNew || this.$isSubdocument) && createdAt && !this.$__getValue(createdAt) && this.$__isSelected(createdAt)) {
  8430. this.$set(createdAt, defaultTimestamp, undefined, {
  8431. overwriteImmutable: true
  8432. });
  8433. }
  8434. if (!skipUpdatedAt && updatedAt && (this.isNew || this.$isModified())) {
  8435. var ts = defaultTimestamp;
  8436. if (this.isNew && createdAt != null) {
  8437. ts = this.$__getValue(createdAt);
  8438. }
  8439. this.$set(updatedAt, ts);
  8440. }
  8441. next();
  8442. });
  8443. schema.methods.initializeTimestamps = function () {
  8444. var ts = currentTime != null ? currentTime() : this.constructor.base.now();
  8445. if (createdAt && !this.get(createdAt)) {
  8446. this.$set(createdAt, ts);
  8447. }
  8448. if (updatedAt && !this.get(updatedAt)) {
  8449. this.$set(updatedAt, ts);
  8450. }
  8451. return this;
  8452. };
  8453. _setTimestampsOnUpdate[symbols.builtInMiddleware] = true;
  8454. var opts = {
  8455. query: true,
  8456. model: false
  8457. };
  8458. schema.pre('findOneAndReplace', opts, _setTimestampsOnUpdate);
  8459. schema.pre('findOneAndUpdate', opts, _setTimestampsOnUpdate);
  8460. schema.pre('replaceOne', opts, _setTimestampsOnUpdate);
  8461. schema.pre('update', opts, _setTimestampsOnUpdate);
  8462. schema.pre('updateOne', opts, _setTimestampsOnUpdate);
  8463. schema.pre('updateMany', opts, _setTimestampsOnUpdate);
  8464. function _setTimestampsOnUpdate(next) {
  8465. var now = currentTime != null ? currentTime() : this.model.base.now(); // Replacing with null update should still trigger timestamps
  8466. if (this.op === 'findOneAndReplace' && this.getUpdate() == null) {
  8467. this.setUpdate({});
  8468. }
  8469. applyTimestampsToUpdate(now, createdAt, updatedAt, this.getUpdate(), this.options, this.schema);
  8470. applyTimestampsToChildren(now, this.getUpdate(), this.model.schema);
  8471. next();
  8472. }
  8473. };
  8474. /***/ }),
  8475. /***/ 5285:
  8476. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8477. "use strict";
  8478. var getConstructorName = __webpack_require__(1981);
  8479. module.exports = function allServersUnknown(topologyDescription) {
  8480. if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
  8481. return false;
  8482. }
  8483. var servers = Array.from(topologyDescription.servers.values());
  8484. return servers.length > 0 && servers.every(function (server) {
  8485. return server.type === 'Unknown';
  8486. });
  8487. };
  8488. /***/ }),
  8489. /***/ 2082:
  8490. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8491. "use strict";
  8492. var getConstructorName = __webpack_require__(1981);
  8493. module.exports = function isAtlas(topologyDescription) {
  8494. if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
  8495. return false;
  8496. }
  8497. var hostnames = Array.from(topologyDescription.servers.keys());
  8498. if (hostnames.length === 0) {
  8499. return false;
  8500. }
  8501. for (var i = 0, il = hostnames.length; i < il; ++i) {
  8502. var url = new URL(hostnames[i]);
  8503. if (url.hostname.endsWith('.mongodb.net') === false || url.port !== '27017') {
  8504. return false;
  8505. }
  8506. }
  8507. return true;
  8508. };
  8509. /***/ }),
  8510. /***/ 3871:
  8511. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8512. "use strict";
  8513. var getConstructorName = __webpack_require__(1981);
  8514. var nonSSLMessage = 'Client network socket disconnected before secure TLS ' + 'connection was established';
  8515. module.exports = function isSSLError(topologyDescription) {
  8516. if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
  8517. return false;
  8518. }
  8519. var descriptions = Array.from(topologyDescription.servers.values());
  8520. return descriptions.length > 0 && descriptions.every(function (descr) {
  8521. return descr.error && descr.error.message.indexOf(nonSSLMessage) !== -1;
  8522. });
  8523. };
  8524. /***/ }),
  8525. /***/ 4843:
  8526. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8527. "use strict";
  8528. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  8529. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  8530. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  8531. var cleanPositionalOperators = __webpack_require__(7658);
  8532. var handleTimestampOption = __webpack_require__(6370);
  8533. module.exports = applyTimestampsToChildren;
  8534. /*!
  8535. * ignore
  8536. */
  8537. function applyTimestampsToChildren(now, update, schema) {
  8538. if (update == null) {
  8539. return;
  8540. }
  8541. var keys = Object.keys(update);
  8542. var hasDollarKey = keys.some(function (key) {
  8543. return key[0] === '$';
  8544. });
  8545. if (hasDollarKey) {
  8546. if (update.$push) {
  8547. _applyTimestampToUpdateOperator(update.$push);
  8548. }
  8549. if (update.$addToSet) {
  8550. _applyTimestampToUpdateOperator(update.$addToSet);
  8551. }
  8552. if (update.$set != null) {
  8553. var _keys = Object.keys(update.$set);
  8554. for (var _i = 0, _keys2 = _keys; _i < _keys2.length; _i++) {
  8555. var key = _keys2[_i];
  8556. applyTimestampsToUpdateKey(schema, key, update.$set, now);
  8557. }
  8558. }
  8559. if (update.$setOnInsert != null) {
  8560. var _keys3 = Object.keys(update.$setOnInsert);
  8561. for (var _i2 = 0, _keys4 = _keys3; _i2 < _keys4.length; _i2++) {
  8562. var _key = _keys4[_i2];
  8563. applyTimestampsToUpdateKey(schema, _key, update.$setOnInsert, now);
  8564. }
  8565. }
  8566. }
  8567. var updateKeys = Object.keys(update).filter(function (key) {
  8568. return key[0] !== '$';
  8569. });
  8570. var _iterator = _createForOfIteratorHelper(updateKeys),
  8571. _step;
  8572. try {
  8573. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  8574. var _key2 = _step.value;
  8575. applyTimestampsToUpdateKey(schema, _key2, update, now);
  8576. }
  8577. } catch (err) {
  8578. _iterator.e(err);
  8579. } finally {
  8580. _iterator.f();
  8581. }
  8582. function _applyTimestampToUpdateOperator(op) {
  8583. var _loop = function _loop() {
  8584. var key = _Object$keys[_i3];
  8585. var $path = schema.path(key.replace(/\.\$\./i, '.').replace(/.\$$/, ''));
  8586. if (op[key] && $path && $path.$isMongooseDocumentArray && $path.schema.options.timestamps) {
  8587. var timestamps = $path.schema.options.timestamps;
  8588. var createdAt = handleTimestampOption(timestamps, 'createdAt');
  8589. var updatedAt = handleTimestampOption(timestamps, 'updatedAt');
  8590. if (op[key].$each) {
  8591. op[key].$each.forEach(function (subdoc) {
  8592. if (updatedAt != null) {
  8593. subdoc[updatedAt] = now;
  8594. }
  8595. if (createdAt != null) {
  8596. subdoc[createdAt] = now;
  8597. }
  8598. applyTimestampsToChildren(now, subdoc, $path.schema);
  8599. });
  8600. } else {
  8601. if (updatedAt != null) {
  8602. op[key][updatedAt] = now;
  8603. }
  8604. if (createdAt != null) {
  8605. op[key][createdAt] = now;
  8606. }
  8607. applyTimestampsToChildren(now, op[key], $path.schema);
  8608. }
  8609. }
  8610. };
  8611. for (var _i3 = 0, _Object$keys = Object.keys(op); _i3 < _Object$keys.length; _i3++) {
  8612. _loop();
  8613. }
  8614. }
  8615. }
  8616. function applyTimestampsToDocumentArray(arr, schematype, now) {
  8617. var timestamps = schematype.schema.options.timestamps;
  8618. if (!timestamps) {
  8619. return;
  8620. }
  8621. var len = arr.length;
  8622. var createdAt = handleTimestampOption(timestamps, 'createdAt');
  8623. var updatedAt = handleTimestampOption(timestamps, 'updatedAt');
  8624. for (var i = 0; i < len; ++i) {
  8625. if (updatedAt != null) {
  8626. arr[i][updatedAt] = now;
  8627. }
  8628. if (createdAt != null) {
  8629. arr[i][createdAt] = now;
  8630. }
  8631. applyTimestampsToChildren(now, arr[i], schematype.schema);
  8632. }
  8633. }
  8634. function applyTimestampsToSingleNested(subdoc, schematype, now) {
  8635. var timestamps = schematype.schema.options.timestamps;
  8636. if (!timestamps) {
  8637. return;
  8638. }
  8639. var createdAt = handleTimestampOption(timestamps, 'createdAt');
  8640. var updatedAt = handleTimestampOption(timestamps, 'updatedAt');
  8641. if (updatedAt != null) {
  8642. subdoc[updatedAt] = now;
  8643. }
  8644. if (createdAt != null) {
  8645. subdoc[createdAt] = now;
  8646. }
  8647. applyTimestampsToChildren(now, subdoc, schematype.schema);
  8648. }
  8649. function applyTimestampsToUpdateKey(schema, key, update, now) {
  8650. // Replace positional operator `$` and array filters `$[]` and `$[.*]`
  8651. var keyToSearch = cleanPositionalOperators(key);
  8652. var path = schema.path(keyToSearch);
  8653. if (!path) {
  8654. return;
  8655. }
  8656. var parentSchemaTypes = [];
  8657. var pieces = keyToSearch.split('.');
  8658. for (var i = pieces.length - 1; i > 0; --i) {
  8659. var s = schema.path(pieces.slice(0, i).join('.'));
  8660. if (s != null && (s.$isMongooseDocumentArray || s.$isSingleNested)) {
  8661. parentSchemaTypes.push({
  8662. parentPath: key.split('.').slice(0, i).join('.'),
  8663. parentSchemaType: s
  8664. });
  8665. }
  8666. }
  8667. if (Array.isArray(update[key]) && path.$isMongooseDocumentArray) {
  8668. applyTimestampsToDocumentArray(update[key], path, now);
  8669. } else if (update[key] && path.$isSingleNested) {
  8670. applyTimestampsToSingleNested(update[key], path, now);
  8671. } else if (parentSchemaTypes.length > 0) {
  8672. var _iterator2 = _createForOfIteratorHelper(parentSchemaTypes),
  8673. _step2;
  8674. try {
  8675. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  8676. var item = _step2.value;
  8677. var parentPath = item.parentPath;
  8678. var parentSchemaType = item.parentSchemaType;
  8679. var timestamps = parentSchemaType.schema.options.timestamps;
  8680. var updatedAt = handleTimestampOption(timestamps, 'updatedAt');
  8681. if (!timestamps || updatedAt == null) {
  8682. continue;
  8683. }
  8684. if (parentSchemaType.$isSingleNested) {
  8685. // Single nested is easy
  8686. update[parentPath + '.' + updatedAt] = now;
  8687. } else if (parentSchemaType.$isMongooseDocumentArray) {
  8688. var childPath = key.substring(parentPath.length + 1);
  8689. if (/^\d+$/.test(childPath)) {
  8690. update[parentPath + '.' + childPath][updatedAt] = now;
  8691. continue;
  8692. }
  8693. var firstDot = childPath.indexOf('.');
  8694. childPath = firstDot !== -1 ? childPath.substring(0, firstDot) : childPath;
  8695. update[parentPath + '.' + childPath + '.' + updatedAt] = now;
  8696. }
  8697. }
  8698. } catch (err) {
  8699. _iterator2.e(err);
  8700. } finally {
  8701. _iterator2.f();
  8702. }
  8703. } else if (path.schema != null && path.schema != schema && update[key]) {
  8704. var _timestamps = path.schema.options.timestamps;
  8705. var createdAt = handleTimestampOption(_timestamps, 'createdAt');
  8706. var _updatedAt = handleTimestampOption(_timestamps, 'updatedAt');
  8707. if (!_timestamps) {
  8708. return;
  8709. }
  8710. if (_updatedAt != null) {
  8711. update[key][_updatedAt] = now;
  8712. }
  8713. if (createdAt != null) {
  8714. update[key][createdAt] = now;
  8715. }
  8716. }
  8717. }
  8718. /***/ }),
  8719. /***/ 6434:
  8720. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8721. "use strict";
  8722. /*!
  8723. * ignore
  8724. */
  8725. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8726. var get = __webpack_require__(9981);
  8727. module.exports = applyTimestampsToUpdate;
  8728. /*!
  8729. * ignore
  8730. */
  8731. function applyTimestampsToUpdate(now, createdAt, updatedAt, currentUpdate, options) {
  8732. var updates = currentUpdate;
  8733. var _updates = updates;
  8734. var overwrite = get(options, 'overwrite', false);
  8735. var timestamps = get(options, 'timestamps', true); // Support skipping timestamps at the query level, see gh-6980
  8736. if (!timestamps || updates == null) {
  8737. return currentUpdate;
  8738. }
  8739. var skipCreatedAt = timestamps != null && timestamps.createdAt === false;
  8740. var skipUpdatedAt = timestamps != null && timestamps.updatedAt === false;
  8741. if (overwrite) {
  8742. if (currentUpdate && currentUpdate.$set) {
  8743. currentUpdate = currentUpdate.$set;
  8744. updates.$set = {};
  8745. _updates = updates.$set;
  8746. }
  8747. if (!skipUpdatedAt && updatedAt && !currentUpdate[updatedAt]) {
  8748. _updates[updatedAt] = now;
  8749. }
  8750. if (!skipCreatedAt && createdAt && !currentUpdate[createdAt]) {
  8751. _updates[createdAt] = now;
  8752. }
  8753. return updates;
  8754. }
  8755. currentUpdate = currentUpdate || {};
  8756. if (Array.isArray(updates)) {
  8757. // Update with aggregation pipeline
  8758. updates.push({
  8759. $set: _defineProperty({}, updatedAt, now)
  8760. });
  8761. return updates;
  8762. }
  8763. updates.$set = updates.$set || {};
  8764. if (!skipUpdatedAt && updatedAt && (!currentUpdate.$currentDate || !currentUpdate.$currentDate[updatedAt])) {
  8765. var timestampSet = false;
  8766. if (updatedAt.indexOf('.') !== -1) {
  8767. var pieces = updatedAt.split('.');
  8768. for (var i = 1; i < pieces.length; ++i) {
  8769. var remnant = pieces.slice(-i).join('.');
  8770. var start = pieces.slice(0, -i).join('.');
  8771. if (currentUpdate[start] != null) {
  8772. currentUpdate[start][remnant] = now;
  8773. timestampSet = true;
  8774. break;
  8775. } else if (currentUpdate.$set && currentUpdate.$set[start]) {
  8776. currentUpdate.$set[start][remnant] = now;
  8777. timestampSet = true;
  8778. break;
  8779. }
  8780. }
  8781. }
  8782. if (!timestampSet) {
  8783. updates.$set[updatedAt] = now;
  8784. }
  8785. if (updates.hasOwnProperty(updatedAt)) {
  8786. delete updates[updatedAt];
  8787. }
  8788. }
  8789. if (!skipCreatedAt && createdAt) {
  8790. if (currentUpdate[createdAt]) {
  8791. delete currentUpdate[createdAt];
  8792. }
  8793. if (currentUpdate.$set && currentUpdate.$set[createdAt]) {
  8794. delete currentUpdate.$set[createdAt];
  8795. }
  8796. var _timestampSet = false;
  8797. if (createdAt.indexOf('.') !== -1) {
  8798. var _pieces = createdAt.split('.');
  8799. for (var _i = 1; _i < _pieces.length; ++_i) {
  8800. var _remnant = _pieces.slice(-_i).join('.');
  8801. var _start = _pieces.slice(0, -_i).join('.');
  8802. if (currentUpdate[_start] != null) {
  8803. currentUpdate[_start][_remnant] = now;
  8804. _timestampSet = true;
  8805. break;
  8806. } else if (currentUpdate.$set && currentUpdate.$set[_start]) {
  8807. currentUpdate.$set[_start][_remnant] = now;
  8808. _timestampSet = true;
  8809. break;
  8810. }
  8811. }
  8812. }
  8813. if (!_timestampSet) {
  8814. updates.$setOnInsert = updates.$setOnInsert || {};
  8815. updates.$setOnInsert[createdAt] = now;
  8816. }
  8817. }
  8818. if (Object.keys(updates.$set).length === 0) {
  8819. delete updates.$set;
  8820. }
  8821. return updates;
  8822. }
  8823. /***/ }),
  8824. /***/ 6379:
  8825. /***/ ((module, exports, __webpack_require__) => {
  8826. "use strict";
  8827. /*!
  8828. * Dependencies
  8829. */
  8830. var StateMachine = __webpack_require__(489);
  8831. var ActiveRoster = StateMachine.ctor('require', 'modify', 'init', 'default', 'ignore');
  8832. module.exports = exports = InternalCache;
  8833. function InternalCache() {
  8834. this.activePaths = new ActiveRoster();
  8835. }
  8836. InternalCache.prototype.fullPath = undefined;
  8837. InternalCache.prototype.strictMode = undefined;
  8838. InternalCache.prototype.selected = undefined;
  8839. InternalCache.prototype.shardval = undefined;
  8840. InternalCache.prototype.saveError = undefined;
  8841. InternalCache.prototype.validationError = undefined;
  8842. InternalCache.prototype.adhocPaths = undefined;
  8843. InternalCache.prototype.removing = undefined;
  8844. InternalCache.prototype.inserting = undefined;
  8845. InternalCache.prototype.saving = undefined;
  8846. InternalCache.prototype.version = undefined;
  8847. InternalCache.prototype._id = undefined;
  8848. InternalCache.prototype.ownerDocument = undefined;
  8849. InternalCache.prototype.populate = undefined; // what we want to populate in this doc
  8850. InternalCache.prototype.populated = undefined; // the _ids that have been populated
  8851. /**
  8852. * If `false`, this document was not the result of population.
  8853. * If `true`, this document is a populated doc underneath another doc
  8854. * If an object, this document is a populated doc and the `value` property of the
  8855. * object contains the original depopulated value.
  8856. */
  8857. InternalCache.prototype.wasPopulated = false;
  8858. InternalCache.prototype.scope = undefined;
  8859. InternalCache.prototype.session = null;
  8860. InternalCache.prototype.pathsToScopes = null;
  8861. InternalCache.prototype.cachedRequired = null;
  8862. /***/ }),
  8863. /***/ 4962:
  8864. /***/ ((__unused_webpack_module, exports) => {
  8865. "use strict";
  8866. /*!
  8867. * ignore
  8868. */
  8869. exports.h = {
  8870. transform: false,
  8871. virtuals: false,
  8872. getters: false,
  8873. _skipDepopulateTopLevel: true,
  8874. depopulate: true,
  8875. flattenDecimals: false,
  8876. useProjection: false
  8877. };
  8878. /***/ }),
  8879. /***/ 4034:
  8880. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8881. "use strict";
  8882. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  8883. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8884. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  8885. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8886. var clone = __webpack_require__(1973);
  8887. var PopulateOptions = /*#__PURE__*/_createClass(function PopulateOptions(obj) {
  8888. _classCallCheck(this, PopulateOptions);
  8889. this._docs = {};
  8890. this._childDocs = [];
  8891. if (obj == null) {
  8892. return;
  8893. }
  8894. obj = clone(obj);
  8895. Object.assign(this, obj);
  8896. if (_typeof(obj.subPopulate) === 'object') {
  8897. this.populate = obj.subPopulate;
  8898. }
  8899. if (obj.perDocumentLimit != null && obj.limit != null) {
  8900. throw new Error('Can not use `limit` and `perDocumentLimit` at the same time. Path: `' + obj.path + '`.');
  8901. }
  8902. });
  8903. /**
  8904. * The connection used to look up models by name. If not specified, Mongoose
  8905. * will default to using the connection associated with the model in
  8906. * `PopulateOptions#model`.
  8907. *
  8908. * @memberOf PopulateOptions
  8909. * @property {Connection} connection
  8910. * @api public
  8911. */
  8912. module.exports = PopulateOptions;
  8913. /***/ }),
  8914. /***/ 4756:
  8915. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8916. "use strict";
  8917. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  8918. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8919. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  8920. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8921. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8922. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8923. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8924. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  8925. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8926. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  8927. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8928. var SchemaTypeOptions = __webpack_require__(1764);
  8929. /**
  8930. * The options defined on an Array schematype.
  8931. *
  8932. * #### Example:
  8933. *
  8934. * const schema = new Schema({ tags: [String] });
  8935. * schema.path('tags').options; // SchemaArrayOptions instance
  8936. *
  8937. * @api public
  8938. * @inherits SchemaTypeOptions
  8939. * @constructor SchemaArrayOptions
  8940. */
  8941. var SchemaArrayOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  8942. _inherits(SchemaArrayOptions, _SchemaTypeOptions);
  8943. var _super = _createSuper(SchemaArrayOptions);
  8944. function SchemaArrayOptions() {
  8945. _classCallCheck(this, SchemaArrayOptions);
  8946. return _super.apply(this, arguments);
  8947. }
  8948. return _createClass(SchemaArrayOptions);
  8949. }(SchemaTypeOptions);
  8950. var opts = __webpack_require__(3439);
  8951. /**
  8952. * If this is an array of strings, an array of allowed values for this path.
  8953. * Throws an error if this array isn't an array of strings.
  8954. *
  8955. * @api public
  8956. * @property enum
  8957. * @memberOf SchemaArrayOptions
  8958. * @type Array
  8959. * @instance
  8960. */
  8961. Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
  8962. /**
  8963. * If set, specifies the type of this array's values. Equivalent to setting
  8964. * `type` to an array whose first element is `of`.
  8965. *
  8966. * #### Example:
  8967. *
  8968. * // `arr` is an array of numbers.
  8969. * new Schema({ arr: [Number] });
  8970. * // Equivalent way to define `arr` as an array of numbers
  8971. * new Schema({ arr: { type: Array, of: Number } });
  8972. *
  8973. * @api public
  8974. * @property of
  8975. * @memberOf SchemaArrayOptions
  8976. * @type Function|String
  8977. * @instance
  8978. */
  8979. Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
  8980. /*!
  8981. * ignore
  8982. */
  8983. module.exports = SchemaArrayOptions;
  8984. /***/ }),
  8985. /***/ 9586:
  8986. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  8987. "use strict";
  8988. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  8989. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  8990. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  8991. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  8992. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  8993. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8994. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  8995. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  8996. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8997. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  8998. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8999. var SchemaTypeOptions = __webpack_require__(1764);
  9000. /**
  9001. * The options defined on a Buffer schematype.
  9002. *
  9003. * #### Example:
  9004. *
  9005. * const schema = new Schema({ bitmap: Buffer });
  9006. * schema.path('bitmap').options; // SchemaBufferOptions instance
  9007. *
  9008. * @api public
  9009. * @inherits SchemaTypeOptions
  9010. * @constructor SchemaBufferOptions
  9011. */
  9012. var SchemaBufferOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9013. _inherits(SchemaBufferOptions, _SchemaTypeOptions);
  9014. var _super = _createSuper(SchemaBufferOptions);
  9015. function SchemaBufferOptions() {
  9016. _classCallCheck(this, SchemaBufferOptions);
  9017. return _super.apply(this, arguments);
  9018. }
  9019. return _createClass(SchemaBufferOptions);
  9020. }(SchemaTypeOptions);
  9021. var opts = __webpack_require__(3439);
  9022. /**
  9023. * Set the default subtype for this buffer.
  9024. *
  9025. * @api public
  9026. * @property subtype
  9027. * @memberOf SchemaBufferOptions
  9028. * @type Number
  9029. * @instance
  9030. */
  9031. Object.defineProperty(SchemaBufferOptions.prototype, 'subtype', opts);
  9032. /*!
  9033. * ignore
  9034. */
  9035. module.exports = SchemaBufferOptions;
  9036. /***/ }),
  9037. /***/ 2869:
  9038. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9039. "use strict";
  9040. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9041. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9042. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9043. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9044. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9045. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9046. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9047. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9048. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9049. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9050. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9051. var SchemaTypeOptions = __webpack_require__(1764);
  9052. /**
  9053. * The options defined on a Date schematype.
  9054. *
  9055. * #### Example:
  9056. *
  9057. * const schema = new Schema({ startedAt: Date });
  9058. * schema.path('startedAt').options; // SchemaDateOptions instance
  9059. *
  9060. * @api public
  9061. * @inherits SchemaTypeOptions
  9062. * @constructor SchemaDateOptions
  9063. */
  9064. var SchemaDateOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9065. _inherits(SchemaDateOptions, _SchemaTypeOptions);
  9066. var _super = _createSuper(SchemaDateOptions);
  9067. function SchemaDateOptions() {
  9068. _classCallCheck(this, SchemaDateOptions);
  9069. return _super.apply(this, arguments);
  9070. }
  9071. return _createClass(SchemaDateOptions);
  9072. }(SchemaTypeOptions);
  9073. var opts = __webpack_require__(3439);
  9074. /**
  9075. * If set, Mongoose adds a validator that checks that this path is after the
  9076. * given `min`.
  9077. *
  9078. * @api public
  9079. * @property min
  9080. * @memberOf SchemaDateOptions
  9081. * @type Date
  9082. * @instance
  9083. */
  9084. Object.defineProperty(SchemaDateOptions.prototype, 'min', opts);
  9085. /**
  9086. * If set, Mongoose adds a validator that checks that this path is before the
  9087. * given `max`.
  9088. *
  9089. * @api public
  9090. * @property max
  9091. * @memberOf SchemaDateOptions
  9092. * @type Date
  9093. * @instance
  9094. */
  9095. Object.defineProperty(SchemaDateOptions.prototype, 'max', opts);
  9096. /**
  9097. * If set, Mongoose creates a TTL index on this path.
  9098. *
  9099. * mongo TTL index `expireAfterSeconds` value will take 'expires' value expressed in seconds.
  9100. *
  9101. * #### Example:
  9102. *
  9103. * const schema = new Schema({ "expireAt": { type: Date, expires: 11 } });
  9104. * // if 'expireAt' is set, then document expires at expireAt + 11 seconds
  9105. *
  9106. * @api public
  9107. * @property expires
  9108. * @memberOf SchemaDateOptions
  9109. * @type Date
  9110. * @instance
  9111. */
  9112. Object.defineProperty(SchemaDateOptions.prototype, 'expires', opts);
  9113. /*!
  9114. * ignore
  9115. */
  9116. module.exports = SchemaDateOptions;
  9117. /***/ }),
  9118. /***/ 887:
  9119. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9120. "use strict";
  9121. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9122. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9123. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9124. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9125. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9126. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9127. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9128. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9129. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9130. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9131. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9132. var SchemaTypeOptions = __webpack_require__(1764);
  9133. /**
  9134. * The options defined on an Document Array schematype.
  9135. *
  9136. * #### Example:
  9137. *
  9138. * const schema = new Schema({ users: [{ name: string }] });
  9139. * schema.path('users').options; // SchemaDocumentArrayOptions instance
  9140. *
  9141. * @api public
  9142. * @inherits SchemaTypeOptions
  9143. * @constructor SchemaDocumentOptions
  9144. */
  9145. var SchemaDocumentArrayOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9146. _inherits(SchemaDocumentArrayOptions, _SchemaTypeOptions);
  9147. var _super = _createSuper(SchemaDocumentArrayOptions);
  9148. function SchemaDocumentArrayOptions() {
  9149. _classCallCheck(this, SchemaDocumentArrayOptions);
  9150. return _super.apply(this, arguments);
  9151. }
  9152. return _createClass(SchemaDocumentArrayOptions);
  9153. }(SchemaTypeOptions);
  9154. var opts = __webpack_require__(3439);
  9155. /**
  9156. * If `true`, Mongoose will skip building any indexes defined in this array's schema.
  9157. * If not set, Mongoose will build all indexes defined in this array's schema.
  9158. *
  9159. * #### Example:
  9160. *
  9161. * const childSchema = Schema({ name: { type: String, index: true } });
  9162. * // If `excludeIndexes` is `true`, Mongoose will skip building an index
  9163. * // on `arr.name`. Otherwise, Mongoose will build an index on `arr.name`.
  9164. * const parentSchema = Schema({
  9165. * arr: { type: [childSchema], excludeIndexes: true }
  9166. * });
  9167. *
  9168. * @api public
  9169. * @property excludeIndexes
  9170. * @memberOf SchemaDocumentArrayOptions
  9171. * @type Array
  9172. * @instance
  9173. */
  9174. Object.defineProperty(SchemaDocumentArrayOptions.prototype, 'excludeIndexes', opts);
  9175. /**
  9176. * If set, overwrites the child schema's `_id` option.
  9177. *
  9178. * #### Example:
  9179. *
  9180. * const childSchema = Schema({ name: String });
  9181. * const parentSchema = Schema({
  9182. * child: { type: childSchema, _id: false }
  9183. * });
  9184. * parentSchema.path('child').schema.options._id; // false
  9185. *
  9186. * @api public
  9187. * @property _id
  9188. * @memberOf SchemaDocumentArrayOptions
  9189. * @type Array
  9190. * @instance
  9191. */
  9192. Object.defineProperty(SchemaDocumentArrayOptions.prototype, '_id', opts);
  9193. /*!
  9194. * ignore
  9195. */
  9196. module.exports = SchemaDocumentArrayOptions;
  9197. /***/ }),
  9198. /***/ 8227:
  9199. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9200. "use strict";
  9201. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9202. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9203. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9204. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9205. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9206. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9207. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9208. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9209. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9210. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9211. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9212. var SchemaTypeOptions = __webpack_require__(1764);
  9213. /**
  9214. * The options defined on a Map schematype.
  9215. *
  9216. * #### Example:
  9217. *
  9218. * const schema = new Schema({ socialMediaHandles: { type: Map, of: String } });
  9219. * schema.path('socialMediaHandles').options; // SchemaMapOptions instance
  9220. *
  9221. * @api public
  9222. * @inherits SchemaTypeOptions
  9223. * @constructor SchemaMapOptions
  9224. */
  9225. var SchemaMapOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9226. _inherits(SchemaMapOptions, _SchemaTypeOptions);
  9227. var _super = _createSuper(SchemaMapOptions);
  9228. function SchemaMapOptions() {
  9229. _classCallCheck(this, SchemaMapOptions);
  9230. return _super.apply(this, arguments);
  9231. }
  9232. return _createClass(SchemaMapOptions);
  9233. }(SchemaTypeOptions);
  9234. var opts = __webpack_require__(3439);
  9235. /**
  9236. * If set, specifies the type of this map's values. Mongoose will cast
  9237. * this map's values to the given type.
  9238. *
  9239. * If not set, Mongoose will not cast the map's values.
  9240. *
  9241. * #### Example:
  9242. *
  9243. * // Mongoose will cast `socialMediaHandles` values to strings
  9244. * const schema = new Schema({ socialMediaHandles: { type: Map, of: String } });
  9245. * schema.path('socialMediaHandles').options.of; // String
  9246. *
  9247. * @api public
  9248. * @property of
  9249. * @memberOf SchemaMapOptions
  9250. * @type Function|string
  9251. * @instance
  9252. */
  9253. Object.defineProperty(SchemaMapOptions.prototype, 'of', opts);
  9254. module.exports = SchemaMapOptions;
  9255. /***/ }),
  9256. /***/ 8491:
  9257. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9258. "use strict";
  9259. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9260. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9261. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9262. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9263. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9264. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9265. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9266. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9267. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9268. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9269. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9270. var SchemaTypeOptions = __webpack_require__(1764);
  9271. /**
  9272. * The options defined on a Number schematype.
  9273. *
  9274. * #### Example:
  9275. *
  9276. * const schema = new Schema({ count: Number });
  9277. * schema.path('count').options; // SchemaNumberOptions instance
  9278. *
  9279. * @api public
  9280. * @inherits SchemaTypeOptions
  9281. * @constructor SchemaNumberOptions
  9282. */
  9283. var SchemaNumberOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9284. _inherits(SchemaNumberOptions, _SchemaTypeOptions);
  9285. var _super = _createSuper(SchemaNumberOptions);
  9286. function SchemaNumberOptions() {
  9287. _classCallCheck(this, SchemaNumberOptions);
  9288. return _super.apply(this, arguments);
  9289. }
  9290. return _createClass(SchemaNumberOptions);
  9291. }(SchemaTypeOptions);
  9292. var opts = __webpack_require__(3439);
  9293. /**
  9294. * If set, Mongoose adds a validator that checks that this path is at least the
  9295. * given `min`.
  9296. *
  9297. * @api public
  9298. * @property min
  9299. * @memberOf SchemaNumberOptions
  9300. * @type Number
  9301. * @instance
  9302. */
  9303. Object.defineProperty(SchemaNumberOptions.prototype, 'min', opts);
  9304. /**
  9305. * If set, Mongoose adds a validator that checks that this path is less than the
  9306. * given `max`.
  9307. *
  9308. * @api public
  9309. * @property max
  9310. * @memberOf SchemaNumberOptions
  9311. * @type Number
  9312. * @instance
  9313. */
  9314. Object.defineProperty(SchemaNumberOptions.prototype, 'max', opts);
  9315. /**
  9316. * If set, Mongoose adds a validator that checks that this path is strictly
  9317. * equal to one of the given values.
  9318. *
  9319. * #### Example:
  9320. * const schema = new Schema({
  9321. * favoritePrime: {
  9322. * type: Number,
  9323. * enum: [3, 5, 7]
  9324. * }
  9325. * });
  9326. * schema.path('favoritePrime').options.enum; // [3, 5, 7]
  9327. *
  9328. * @api public
  9329. * @property enum
  9330. * @memberOf SchemaNumberOptions
  9331. * @type Array
  9332. * @instance
  9333. */
  9334. Object.defineProperty(SchemaNumberOptions.prototype, 'enum', opts);
  9335. /**
  9336. * Sets default [populate options](/docs/populate.html#query-conditions).
  9337. *
  9338. * #### Example:
  9339. * const schema = new Schema({
  9340. * child: {
  9341. * type: Number,
  9342. * ref: 'Child',
  9343. * populate: { select: 'name' }
  9344. * }
  9345. * });
  9346. * const Parent = mongoose.model('Parent', schema);
  9347. *
  9348. * // Automatically adds `.select('name')`
  9349. * Parent.findOne().populate('child');
  9350. *
  9351. * @api public
  9352. * @property populate
  9353. * @memberOf SchemaNumberOptions
  9354. * @type Object
  9355. * @instance
  9356. */
  9357. Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
  9358. /*!
  9359. * ignore
  9360. */
  9361. module.exports = SchemaNumberOptions;
  9362. /***/ }),
  9363. /***/ 8172:
  9364. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9365. "use strict";
  9366. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9367. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9368. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9369. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9370. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9371. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9372. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9373. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9374. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9375. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9376. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9377. var SchemaTypeOptions = __webpack_require__(1764);
  9378. /**
  9379. * The options defined on an ObjectId schematype.
  9380. *
  9381. * #### Example:
  9382. *
  9383. * const schema = new Schema({ testId: mongoose.ObjectId });
  9384. * schema.path('testId').options; // SchemaObjectIdOptions instance
  9385. *
  9386. * @api public
  9387. * @inherits SchemaTypeOptions
  9388. * @constructor SchemaObjectIdOptions
  9389. */
  9390. var SchemaObjectIdOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9391. _inherits(SchemaObjectIdOptions, _SchemaTypeOptions);
  9392. var _super = _createSuper(SchemaObjectIdOptions);
  9393. function SchemaObjectIdOptions() {
  9394. _classCallCheck(this, SchemaObjectIdOptions);
  9395. return _super.apply(this, arguments);
  9396. }
  9397. return _createClass(SchemaObjectIdOptions);
  9398. }(SchemaTypeOptions);
  9399. var opts = __webpack_require__(3439);
  9400. /**
  9401. * If truthy, uses Mongoose's default built-in ObjectId path.
  9402. *
  9403. * @api public
  9404. * @property auto
  9405. * @memberOf SchemaObjectIdOptions
  9406. * @type Boolean
  9407. * @instance
  9408. */
  9409. Object.defineProperty(SchemaObjectIdOptions.prototype, 'auto', opts);
  9410. /**
  9411. * Sets default [populate options](/docs/populate.html#query-conditions).
  9412. *
  9413. * #### Example:
  9414. * const schema = new Schema({
  9415. * child: {
  9416. * type: 'ObjectId',
  9417. * ref: 'Child',
  9418. * populate: { select: 'name' }
  9419. * }
  9420. * });
  9421. * const Parent = mongoose.model('Parent', schema);
  9422. *
  9423. * // Automatically adds `.select('name')`
  9424. * Parent.findOne().populate('child');
  9425. *
  9426. * @api public
  9427. * @property populate
  9428. * @memberOf SchemaObjectIdOptions
  9429. * @type Object
  9430. * @instance
  9431. */
  9432. Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
  9433. /*!
  9434. * ignore
  9435. */
  9436. module.exports = SchemaObjectIdOptions;
  9437. /***/ }),
  9438. /***/ 3209:
  9439. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9440. "use strict";
  9441. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9442. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9443. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9444. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9445. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9446. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9447. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9448. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9449. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9450. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9451. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9452. var SchemaTypeOptions = __webpack_require__(1764);
  9453. /**
  9454. * The options defined on a string schematype.
  9455. *
  9456. * #### Example:
  9457. *
  9458. * const schema = new Schema({ name: String });
  9459. * schema.path('name').options; // SchemaStringOptions instance
  9460. *
  9461. * @api public
  9462. * @inherits SchemaTypeOptions
  9463. * @constructor SchemaStringOptions
  9464. */
  9465. var SchemaStringOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9466. _inherits(SchemaStringOptions, _SchemaTypeOptions);
  9467. var _super = _createSuper(SchemaStringOptions);
  9468. function SchemaStringOptions() {
  9469. _classCallCheck(this, SchemaStringOptions);
  9470. return _super.apply(this, arguments);
  9471. }
  9472. return _createClass(SchemaStringOptions);
  9473. }(SchemaTypeOptions);
  9474. var opts = __webpack_require__(3439);
  9475. /**
  9476. * Array of allowed values for this path
  9477. *
  9478. * @api public
  9479. * @property enum
  9480. * @memberOf SchemaStringOptions
  9481. * @type Array
  9482. * @instance
  9483. */
  9484. Object.defineProperty(SchemaStringOptions.prototype, 'enum', opts);
  9485. /**
  9486. * Attach a validator that succeeds if the data string matches the given regular
  9487. * expression, and fails otherwise.
  9488. *
  9489. * @api public
  9490. * @property match
  9491. * @memberOf SchemaStringOptions
  9492. * @type RegExp
  9493. * @instance
  9494. */
  9495. Object.defineProperty(SchemaStringOptions.prototype, 'match', opts);
  9496. /**
  9497. * If truthy, Mongoose will add a custom setter that lowercases this string
  9498. * using JavaScript's built-in `String#toLowerCase()`.
  9499. *
  9500. * @api public
  9501. * @property lowercase
  9502. * @memberOf SchemaStringOptions
  9503. * @type Boolean
  9504. * @instance
  9505. */
  9506. Object.defineProperty(SchemaStringOptions.prototype, 'lowercase', opts);
  9507. /**
  9508. * If truthy, Mongoose will add a custom setter that removes leading and trailing
  9509. * whitespace using [JavaScript's built-in `String#trim()`](https://masteringjs.io/tutorials/fundamentals/trim-string).
  9510. *
  9511. * @api public
  9512. * @property trim
  9513. * @memberOf SchemaStringOptions
  9514. * @type Boolean
  9515. * @instance
  9516. */
  9517. Object.defineProperty(SchemaStringOptions.prototype, 'trim', opts);
  9518. /**
  9519. * If truthy, Mongoose will add a custom setter that uppercases this string
  9520. * using JavaScript's built-in [`String#toUpperCase()`](https://masteringjs.io/tutorials/fundamentals/uppercase).
  9521. *
  9522. * @api public
  9523. * @property uppercase
  9524. * @memberOf SchemaStringOptions
  9525. * @type Boolean
  9526. * @instance
  9527. */
  9528. Object.defineProperty(SchemaStringOptions.prototype, 'uppercase', opts);
  9529. /**
  9530. * If set, Mongoose will add a custom validator that ensures the given
  9531. * string's `length` is at least the given number.
  9532. *
  9533. * Mongoose supports two different spellings for this option: `minLength` and `minlength`.
  9534. * `minLength` is the recommended way to specify this option, but Mongoose also supports
  9535. * `minlength` (lowercase "l").
  9536. *
  9537. * @api public
  9538. * @property minLength
  9539. * @memberOf SchemaStringOptions
  9540. * @type Number
  9541. * @instance
  9542. */
  9543. Object.defineProperty(SchemaStringOptions.prototype, 'minLength', opts);
  9544. Object.defineProperty(SchemaStringOptions.prototype, 'minlength', opts);
  9545. /**
  9546. * If set, Mongoose will add a custom validator that ensures the given
  9547. * string's `length` is at most the given number.
  9548. *
  9549. * Mongoose supports two different spellings for this option: `maxLength` and `maxlength`.
  9550. * `maxLength` is the recommended way to specify this option, but Mongoose also supports
  9551. * `maxlength` (lowercase "l").
  9552. *
  9553. * @api public
  9554. * @property maxLength
  9555. * @memberOf SchemaStringOptions
  9556. * @type Number
  9557. * @instance
  9558. */
  9559. Object.defineProperty(SchemaStringOptions.prototype, 'maxLength', opts);
  9560. Object.defineProperty(SchemaStringOptions.prototype, 'maxlength', opts);
  9561. /**
  9562. * Sets default [populate options](/docs/populate.html#query-conditions).
  9563. *
  9564. * @api public
  9565. * @property populate
  9566. * @memberOf SchemaStringOptions
  9567. * @type Object
  9568. * @instance
  9569. */
  9570. Object.defineProperty(SchemaStringOptions.prototype, 'populate', opts);
  9571. /*!
  9572. * ignore
  9573. */
  9574. module.exports = SchemaStringOptions;
  9575. /***/ }),
  9576. /***/ 5446:
  9577. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9578. "use strict";
  9579. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  9580. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9581. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9582. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9583. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  9584. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  9585. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9586. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  9587. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  9588. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  9589. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  9590. var SchemaTypeOptions = __webpack_require__(1764);
  9591. /**
  9592. * The options defined on a single nested schematype.
  9593. *
  9594. * #### Example:
  9595. *
  9596. * const schema = Schema({ child: Schema({ name: String }) });
  9597. * schema.path('child').options; // SchemaSubdocumentOptions instance
  9598. *
  9599. * @api public
  9600. * @inherits SchemaTypeOptions
  9601. * @constructor SchemaSubdocumentOptions
  9602. */
  9603. var SchemaSubdocumentOptions = /*#__PURE__*/function (_SchemaTypeOptions) {
  9604. _inherits(SchemaSubdocumentOptions, _SchemaTypeOptions);
  9605. var _super = _createSuper(SchemaSubdocumentOptions);
  9606. function SchemaSubdocumentOptions() {
  9607. _classCallCheck(this, SchemaSubdocumentOptions);
  9608. return _super.apply(this, arguments);
  9609. }
  9610. return _createClass(SchemaSubdocumentOptions);
  9611. }(SchemaTypeOptions);
  9612. var opts = __webpack_require__(3439);
  9613. /**
  9614. * If set, overwrites the child schema's `_id` option.
  9615. *
  9616. * #### Example:
  9617. *
  9618. * const childSchema = Schema({ name: String });
  9619. * const parentSchema = Schema({
  9620. * child: { type: childSchema, _id: false }
  9621. * });
  9622. * parentSchema.path('child').schema.options._id; // false
  9623. *
  9624. * @api public
  9625. * @property of
  9626. * @memberOf SchemaSubdocumentOptions
  9627. * @type Function|string
  9628. * @instance
  9629. */
  9630. Object.defineProperty(SchemaSubdocumentOptions.prototype, '_id', opts);
  9631. module.exports = SchemaSubdocumentOptions;
  9632. /***/ }),
  9633. /***/ 1764:
  9634. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9635. "use strict";
  9636. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9637. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9638. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9639. var clone = __webpack_require__(1973);
  9640. /**
  9641. * The options defined on a schematype.
  9642. *
  9643. * #### Example:
  9644. *
  9645. * const schema = new Schema({ name: String });
  9646. * schema.path('name').options instanceof mongoose.SchemaTypeOptions; // true
  9647. *
  9648. * @api public
  9649. * @constructor SchemaTypeOptions
  9650. */
  9651. var SchemaTypeOptions = /*#__PURE__*/_createClass(function SchemaTypeOptions(obj) {
  9652. _classCallCheck(this, SchemaTypeOptions);
  9653. if (obj == null) {
  9654. return this;
  9655. }
  9656. Object.assign(this, clone(obj));
  9657. });
  9658. var opts = __webpack_require__(3439);
  9659. /**
  9660. * The type to cast this path to.
  9661. *
  9662. * @api public
  9663. * @property type
  9664. * @memberOf SchemaTypeOptions
  9665. * @type Function|String|Object
  9666. * @instance
  9667. */
  9668. Object.defineProperty(SchemaTypeOptions.prototype, 'type', opts);
  9669. /**
  9670. * Function or object describing how to validate this schematype.
  9671. *
  9672. * @api public
  9673. * @property validate
  9674. * @memberOf SchemaTypeOptions
  9675. * @type Function|Object
  9676. * @instance
  9677. */
  9678. Object.defineProperty(SchemaTypeOptions.prototype, 'validate', opts);
  9679. /**
  9680. * Allows overriding casting logic for this individual path. If a string, the
  9681. * given string overwrites Mongoose's default cast error message.
  9682. *
  9683. * #### Example:
  9684. *
  9685. * const schema = new Schema({
  9686. * num: {
  9687. * type: Number,
  9688. * cast: '{VALUE} is not a valid number'
  9689. * }
  9690. * });
  9691. *
  9692. * // Throws 'CastError: "bad" is not a valid number'
  9693. * schema.path('num').cast('bad');
  9694. *
  9695. * const Model = mongoose.model('Test', schema);
  9696. * const doc = new Model({ num: 'fail' });
  9697. * const err = doc.validateSync();
  9698. *
  9699. * err.errors['num']; // 'CastError: "fail" is not a valid number'
  9700. *
  9701. * @api public
  9702. * @property cast
  9703. * @memberOf SchemaTypeOptions
  9704. * @type String
  9705. * @instance
  9706. */
  9707. Object.defineProperty(SchemaTypeOptions.prototype, 'cast', opts);
  9708. /**
  9709. * If true, attach a required validator to this path, which ensures this path
  9710. * cannot be set to a nullish value. If a function, Mongoose calls the
  9711. * function and only checks for nullish values if the function returns a truthy value.
  9712. *
  9713. * @api public
  9714. * @property required
  9715. * @memberOf SchemaTypeOptions
  9716. * @type Function|Boolean
  9717. * @instance
  9718. */
  9719. Object.defineProperty(SchemaTypeOptions.prototype, 'required', opts);
  9720. /**
  9721. * The default value for this path. If a function, Mongoose executes the function
  9722. * and uses the return value as the default.
  9723. *
  9724. * @api public
  9725. * @property default
  9726. * @memberOf SchemaTypeOptions
  9727. * @type Function|Any
  9728. * @instance
  9729. */
  9730. Object.defineProperty(SchemaTypeOptions.prototype, 'default', opts);
  9731. /**
  9732. * The model that `populate()` should use if populating this path.
  9733. *
  9734. * @api public
  9735. * @property ref
  9736. * @memberOf SchemaTypeOptions
  9737. * @type Function|String
  9738. * @instance
  9739. */
  9740. Object.defineProperty(SchemaTypeOptions.prototype, 'ref', opts);
  9741. /**
  9742. * The path in the document that `populate()` should use to find the model
  9743. * to use.
  9744. *
  9745. * @api public
  9746. * @property ref
  9747. * @memberOf SchemaTypeOptions
  9748. * @type Function|String
  9749. * @instance
  9750. */
  9751. Object.defineProperty(SchemaTypeOptions.prototype, 'refPath', opts);
  9752. /**
  9753. * Whether to include or exclude this path by default when loading documents
  9754. * using `find()`, `findOne()`, etc.
  9755. *
  9756. * @api public
  9757. * @property select
  9758. * @memberOf SchemaTypeOptions
  9759. * @type Boolean|Number
  9760. * @instance
  9761. */
  9762. Object.defineProperty(SchemaTypeOptions.prototype, 'select', opts);
  9763. /**
  9764. * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
  9765. * build an index on this path when the model is compiled.
  9766. *
  9767. * @api public
  9768. * @property index
  9769. * @memberOf SchemaTypeOptions
  9770. * @type Boolean|Number|Object
  9771. * @instance
  9772. */
  9773. Object.defineProperty(SchemaTypeOptions.prototype, 'index', opts);
  9774. /**
  9775. * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
  9776. * will build a unique index on this path when the
  9777. * model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
  9778. *
  9779. * @api public
  9780. * @property unique
  9781. * @memberOf SchemaTypeOptions
  9782. * @type Boolean|Number
  9783. * @instance
  9784. */
  9785. Object.defineProperty(SchemaTypeOptions.prototype, 'unique', opts);
  9786. /**
  9787. * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
  9788. * disallow changes to this path once the document
  9789. * is saved to the database for the first time. Read more about [immutability in Mongoose here](https://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
  9790. *
  9791. * @api public
  9792. * @property immutable
  9793. * @memberOf SchemaTypeOptions
  9794. * @type Function|Boolean
  9795. * @instance
  9796. */
  9797. Object.defineProperty(SchemaTypeOptions.prototype, 'immutable', opts);
  9798. /**
  9799. * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
  9800. * build a sparse index on this path.
  9801. *
  9802. * @api public
  9803. * @property sparse
  9804. * @memberOf SchemaTypeOptions
  9805. * @type Boolean|Number
  9806. * @instance
  9807. */
  9808. Object.defineProperty(SchemaTypeOptions.prototype, 'sparse', opts);
  9809. /**
  9810. * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
  9811. * will build a text index on this path.
  9812. *
  9813. * @api public
  9814. * @property text
  9815. * @memberOf SchemaTypeOptions
  9816. * @type Boolean|Number|Object
  9817. * @instance
  9818. */
  9819. Object.defineProperty(SchemaTypeOptions.prototype, 'text', opts);
  9820. /**
  9821. * Define a transform function for this individual schema type.
  9822. * Only called when calling `toJSON()` or `toObject()`.
  9823. *
  9824. * #### Example:
  9825. *
  9826. * const schema = Schema({
  9827. * myDate: {
  9828. * type: Date,
  9829. * transform: v => v.getFullYear()
  9830. * }
  9831. * });
  9832. * const Model = mongoose.model('Test', schema);
  9833. *
  9834. * const doc = new Model({ myDate: new Date('2019/06/01') });
  9835. * doc.myDate instanceof Date; // true
  9836. *
  9837. * const res = doc.toObject({ transform: true });
  9838. * res.myDate; // 2019
  9839. *
  9840. * @api public
  9841. * @property transform
  9842. * @memberOf SchemaTypeOptions
  9843. * @type Function
  9844. * @instance
  9845. */
  9846. Object.defineProperty(SchemaTypeOptions.prototype, 'transform', opts);
  9847. module.exports = SchemaTypeOptions;
  9848. /***/ }),
  9849. /***/ 1902:
  9850. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  9851. "use strict";
  9852. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  9853. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  9854. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9855. var opts = __webpack_require__(3439);
  9856. var VirtualOptions = /*#__PURE__*/_createClass(function VirtualOptions(obj) {
  9857. _classCallCheck(this, VirtualOptions);
  9858. Object.assign(this, obj);
  9859. if (obj != null && obj.options != null) {
  9860. this.options = Object.assign({}, obj.options);
  9861. }
  9862. });
  9863. /**
  9864. * Marks this virtual as a populate virtual, and specifies the model to
  9865. * use for populate.
  9866. *
  9867. * @api public
  9868. * @property ref
  9869. * @memberOf VirtualOptions
  9870. * @type String|Model|Function
  9871. * @instance
  9872. */
  9873. Object.defineProperty(VirtualOptions.prototype, 'ref', opts);
  9874. /**
  9875. * Marks this virtual as a populate virtual, and specifies the path that
  9876. * contains the name of the model to populate
  9877. *
  9878. * @api public
  9879. * @property refPath
  9880. * @memberOf VirtualOptions
  9881. * @type String|Function
  9882. * @instance
  9883. */
  9884. Object.defineProperty(VirtualOptions.prototype, 'refPath', opts);
  9885. /**
  9886. * The name of the property in the local model to match to `foreignField`
  9887. * in the foreign model.
  9888. *
  9889. * @api public
  9890. * @property localField
  9891. * @memberOf VirtualOptions
  9892. * @type String|Function
  9893. * @instance
  9894. */
  9895. Object.defineProperty(VirtualOptions.prototype, 'localField', opts);
  9896. /**
  9897. * The name of the property in the foreign model to match to `localField`
  9898. * in the local model.
  9899. *
  9900. * @api public
  9901. * @property foreignField
  9902. * @memberOf VirtualOptions
  9903. * @type String|Function
  9904. * @instance
  9905. */
  9906. Object.defineProperty(VirtualOptions.prototype, 'foreignField', opts);
  9907. /**
  9908. * Whether to populate this virtual as a single document (true) or an
  9909. * array of documents (false).
  9910. *
  9911. * @api public
  9912. * @property justOne
  9913. * @memberOf VirtualOptions
  9914. * @type Boolean
  9915. * @instance
  9916. */
  9917. Object.defineProperty(VirtualOptions.prototype, 'justOne', opts);
  9918. /**
  9919. * If true, populate just the number of documents where `localField`
  9920. * matches `foreignField`, as opposed to the documents themselves.
  9921. *
  9922. * If `count` is set, it overrides `justOne`.
  9923. *
  9924. * @api public
  9925. * @property count
  9926. * @memberOf VirtualOptions
  9927. * @type Boolean
  9928. * @instance
  9929. */
  9930. Object.defineProperty(VirtualOptions.prototype, 'count', opts);
  9931. /**
  9932. * Add an additional filter to populate, in addition to `localField`
  9933. * matches `foreignField`.
  9934. *
  9935. * @api public
  9936. * @property match
  9937. * @memberOf VirtualOptions
  9938. * @type Object|Function
  9939. * @instance
  9940. */
  9941. Object.defineProperty(VirtualOptions.prototype, 'match', opts);
  9942. /**
  9943. * Additional options to pass to the query used to `populate()`:
  9944. *
  9945. * - `sort`
  9946. * - `skip`
  9947. * - `limit`
  9948. *
  9949. * @api public
  9950. * @property options
  9951. * @memberOf VirtualOptions
  9952. * @type Object
  9953. * @instance
  9954. */
  9955. Object.defineProperty(VirtualOptions.prototype, 'options', opts);
  9956. /**
  9957. * If true, add a `skip` to the query used to `populate()`.
  9958. *
  9959. * @api public
  9960. * @property skip
  9961. * @memberOf VirtualOptions
  9962. * @type Number
  9963. * @instance
  9964. */
  9965. Object.defineProperty(VirtualOptions.prototype, 'skip', opts);
  9966. /**
  9967. * If true, add a `limit` to the query used to `populate()`.
  9968. *
  9969. * @api public
  9970. * @property limit
  9971. * @memberOf VirtualOptions
  9972. * @type Number
  9973. * @instance
  9974. */
  9975. Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
  9976. /**
  9977. * The `limit` option for `populate()` has [some unfortunate edge cases](/docs/populate.html#query-conditions)
  9978. * when working with multiple documents, like `.find().populate()`. The
  9979. * `perDocumentLimit` option makes `populate()` execute a separate query
  9980. * for each document returned from `find()` to ensure each document
  9981. * gets up to `perDocumentLimit` populated docs if possible.
  9982. *
  9983. * @api public
  9984. * @property perDocumentLimit
  9985. * @memberOf VirtualOptions
  9986. * @type Number
  9987. * @instance
  9988. */
  9989. Object.defineProperty(VirtualOptions.prototype, 'perDocumentLimit', opts);
  9990. module.exports = VirtualOptions;
  9991. /***/ }),
  9992. /***/ 3439:
  9993. /***/ ((module) => {
  9994. "use strict";
  9995. module.exports = Object.freeze({
  9996. enumerable: true,
  9997. configurable: true,
  9998. writable: true,
  9999. value: void 0
  10000. });
  10001. /***/ }),
  10002. /***/ 6755:
  10003. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  10004. "use strict";
  10005. /*!
  10006. * ignore
  10007. */
  10008. var assert = __webpack_require__(9373);
  10009. var mquery = __webpack_require__(5417);
  10010. /**
  10011. * Helper for multiplexing promise implementations
  10012. *
  10013. * @api private
  10014. */
  10015. var store = {
  10016. _promise: null
  10017. };
  10018. /**
  10019. * Get the current promise constructor
  10020. *
  10021. * @api private
  10022. */
  10023. store.get = function () {
  10024. return store._promise;
  10025. };
  10026. /**
  10027. * Set the current promise constructor
  10028. *
  10029. * @api private
  10030. */
  10031. store.set = function (lib) {
  10032. assert.ok(typeof lib === 'function', "mongoose.Promise must be a function, got ".concat(lib));
  10033. store._promise = lib;
  10034. mquery.Promise = lib;
  10035. };
  10036. /*!
  10037. * Use native promises by default
  10038. */
  10039. store.set(__webpack_require__.g.Promise);
  10040. module.exports = store;
  10041. /***/ }),
  10042. /***/ 2888:
  10043. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  10044. "use strict";
  10045. /*!
  10046. * Module dependencies
  10047. */
  10048. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  10049. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  10050. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  10051. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  10052. var checkEmbeddedDiscriminatorKeyProjection = __webpack_require__(4531);
  10053. var get = __webpack_require__(9981);
  10054. var getDiscriminatorByValue = __webpack_require__(7291);
  10055. var isDefiningProjection = __webpack_require__(2183);
  10056. var clone = __webpack_require__(1973);
  10057. /*!
  10058. * Prepare a set of path options for query population.
  10059. *
  10060. * @param {Query} query
  10061. * @param {Object} options
  10062. * @return {Array}
  10063. */
  10064. exports.preparePopulationOptions = function preparePopulationOptions(query, options) {
  10065. var _populate = query.options.populate;
  10066. var pop = Object.keys(_populate).reduce(function (vals, key) {
  10067. return vals.concat([_populate[key]]);
  10068. }, []); // lean options should trickle through all queries
  10069. if (options.lean != null) {
  10070. pop.filter(function (p) {
  10071. return (p && p.options && p.options.lean) == null;
  10072. }).forEach(makeLean(options.lean));
  10073. }
  10074. pop.forEach(function (opts) {
  10075. opts._localModel = query.model;
  10076. });
  10077. return pop;
  10078. };
  10079. /*!
  10080. * Prepare a set of path options for query population. This is the MongooseQuery
  10081. * version
  10082. *
  10083. * @param {Query} query
  10084. * @param {Object} options
  10085. * @return {Array}
  10086. */
  10087. exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query, options) {
  10088. var _populate = query._mongooseOptions.populate;
  10089. var pop = Object.keys(_populate).reduce(function (vals, key) {
  10090. return vals.concat([_populate[key]]);
  10091. }, []); // lean options should trickle through all queries
  10092. if (options.lean != null) {
  10093. pop.filter(function (p) {
  10094. return (p && p.options && p.options.lean) == null;
  10095. }).forEach(makeLean(options.lean));
  10096. }
  10097. var session = query && query.options && query.options.session || null;
  10098. if (session != null) {
  10099. pop.forEach(function (path) {
  10100. if (path.options == null) {
  10101. path.options = {
  10102. session: session
  10103. };
  10104. return;
  10105. }
  10106. if (!('session' in path.options)) {
  10107. path.options.session = session;
  10108. }
  10109. });
  10110. }
  10111. var projection = query._fieldsForExec();
  10112. pop.forEach(function (p) {
  10113. p._queryProjection = projection;
  10114. });
  10115. pop.forEach(function (opts) {
  10116. opts._localModel = query.model;
  10117. });
  10118. return pop;
  10119. };
  10120. /*!
  10121. * If the document is a mapped discriminator type, it returns a model instance for that type, otherwise,
  10122. * it returns an instance of the given model.
  10123. *
  10124. * @param {Model} model
  10125. * @param {Object} doc
  10126. * @param {Object} fields
  10127. *
  10128. * @return {Document}
  10129. */
  10130. exports.createModel = function createModel(model, doc, fields, userProvidedFields, options) {
  10131. model.hooks.execPreSync('createModel', doc);
  10132. var discriminatorMapping = model.schema ? model.schema.discriminatorMapping : null;
  10133. var key = discriminatorMapping && discriminatorMapping.isRoot ? discriminatorMapping.key : null;
  10134. var value = doc[key];
  10135. if (key && value && model.discriminators) {
  10136. var discriminator = model.discriminators[value] || getDiscriminatorByValue(model.discriminators, value);
  10137. if (discriminator) {
  10138. var _fields = clone(userProvidedFields);
  10139. exports.applyPaths(_fields, discriminator.schema);
  10140. return new discriminator(undefined, _fields, true);
  10141. }
  10142. }
  10143. var _opts = {
  10144. skipId: true,
  10145. isNew: false,
  10146. willInit: true
  10147. };
  10148. if (options != null && 'defaults' in options) {
  10149. _opts.defaults = options.defaults;
  10150. }
  10151. return new model(undefined, fields, _opts);
  10152. };
  10153. /*!
  10154. * ignore
  10155. */
  10156. exports.createModelAndInit = function createModelAndInit(model, doc, fields, userProvidedFields, options, populatedIds, callback) {
  10157. var initOpts = populatedIds ? {
  10158. populated: populatedIds
  10159. } : undefined;
  10160. var casted = exports.createModel(model, doc, fields, userProvidedFields, options);
  10161. try {
  10162. casted.$init(doc, initOpts, callback);
  10163. } catch (error) {
  10164. callback(error, casted);
  10165. }
  10166. };
  10167. /*!
  10168. * ignore
  10169. */
  10170. exports.applyPaths = function applyPaths(fields, schema) {
  10171. // determine if query is selecting or excluding fields
  10172. var exclude;
  10173. var keys;
  10174. var keyIndex;
  10175. if (fields) {
  10176. keys = Object.keys(fields);
  10177. keyIndex = keys.length;
  10178. while (keyIndex--) {
  10179. if (keys[keyIndex][0] === '+') {
  10180. continue;
  10181. }
  10182. var field = fields[keys[keyIndex]]; // Skip `$meta` and `$slice`
  10183. if (!isDefiningProjection(field)) {
  10184. continue;
  10185. }
  10186. exclude = !field;
  10187. break;
  10188. }
  10189. } // if selecting, apply default schematype select:true fields
  10190. // if excluding, apply schematype select:false fields
  10191. var selected = [];
  10192. var excluded = [];
  10193. var stack = [];
  10194. analyzeSchema(schema);
  10195. switch (exclude) {
  10196. case true:
  10197. var _iterator = _createForOfIteratorHelper(excluded),
  10198. _step;
  10199. try {
  10200. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  10201. var fieldName = _step.value;
  10202. fields[fieldName] = 0;
  10203. }
  10204. } catch (err) {
  10205. _iterator.e(err);
  10206. } finally {
  10207. _iterator.f();
  10208. }
  10209. break;
  10210. case false:
  10211. if (schema && schema.paths['_id'] && schema.paths['_id'].options && schema.paths['_id'].options.select === false) {
  10212. fields._id = 0;
  10213. }
  10214. var _iterator2 = _createForOfIteratorHelper(selected),
  10215. _step2;
  10216. try {
  10217. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  10218. var _fieldName = _step2.value;
  10219. fields[_fieldName] = fields[_fieldName] || 1;
  10220. }
  10221. } catch (err) {
  10222. _iterator2.e(err);
  10223. } finally {
  10224. _iterator2.f();
  10225. }
  10226. break;
  10227. case undefined:
  10228. if (fields == null) {
  10229. break;
  10230. } // Any leftover plus paths must in the schema, so delete them (gh-7017)
  10231. for (var _i = 0, _Object$keys = Object.keys(fields || {}); _i < _Object$keys.length; _i++) {
  10232. var key = _Object$keys[_i];
  10233. if (key.startsWith('+')) {
  10234. delete fields[key];
  10235. }
  10236. } // user didn't specify fields, implies returning all fields.
  10237. // only need to apply excluded fields and delete any plus paths
  10238. var _iterator3 = _createForOfIteratorHelper(excluded),
  10239. _step3;
  10240. try {
  10241. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  10242. var _fieldName2 = _step3.value;
  10243. if (fields[_fieldName2] != null) {
  10244. // Skip applying default projections to fields with non-defining
  10245. // projections, like `$slice`
  10246. continue;
  10247. }
  10248. fields[_fieldName2] = 0;
  10249. }
  10250. } catch (err) {
  10251. _iterator3.e(err);
  10252. } finally {
  10253. _iterator3.f();
  10254. }
  10255. break;
  10256. }
  10257. function analyzeSchema(schema, prefix) {
  10258. prefix || (prefix = ''); // avoid recursion
  10259. if (stack.indexOf(schema) !== -1) {
  10260. return [];
  10261. }
  10262. stack.push(schema);
  10263. var addedPaths = [];
  10264. schema.eachPath(function (path, type) {
  10265. if (prefix) path = prefix + '.' + path;
  10266. if (type.$isSchemaMap || path.endsWith('.$*')) {
  10267. return;
  10268. }
  10269. var addedPath = analyzePath(path, type); // arrays
  10270. if (addedPath == null && !Array.isArray(type) && type.$isMongooseArray && !type.$isMongooseDocumentArray) {
  10271. addedPath = analyzePath(path, type.caster);
  10272. }
  10273. if (addedPath != null) {
  10274. addedPaths.push(addedPath);
  10275. } // nested schemas
  10276. if (type.schema) {
  10277. var _addedPaths = analyzeSchema(type.schema, path); // Special case: if discriminator key is the only field that would
  10278. // be projected in, remove it.
  10279. if (exclude === false) {
  10280. checkEmbeddedDiscriminatorKeyProjection(fields, path, type.schema, selected, _addedPaths);
  10281. }
  10282. }
  10283. });
  10284. stack.pop();
  10285. return addedPaths;
  10286. }
  10287. function analyzePath(path, type) {
  10288. var plusPath = '+' + path;
  10289. var hasPlusPath = fields && plusPath in fields;
  10290. if (hasPlusPath) {
  10291. // forced inclusion
  10292. delete fields[plusPath];
  10293. }
  10294. if (typeof type.selected !== 'boolean') {
  10295. return;
  10296. } // If set to 0, we're explicitly excluding the discriminator key. Can't do this for all fields,
  10297. // because we have tests that assert that using `-path` to exclude schema-level `select: true`
  10298. // fields counts as an exclusive projection. See gh-11546
  10299. if (exclude && type.selected && path === schema.options.discriminatorKey && fields[path] != null && !fields[path]) {
  10300. delete fields[path];
  10301. return;
  10302. }
  10303. if (hasPlusPath) {
  10304. // forced inclusion
  10305. delete fields[plusPath]; // if there are other fields being included, add this one
  10306. // if no other included fields, leave this out (implied inclusion)
  10307. if (exclude === false && keys.length > 1 && !~keys.indexOf(path)) {
  10308. fields[path] = 1;
  10309. }
  10310. return;
  10311. } // check for parent exclusions
  10312. var pieces = path.split('.');
  10313. var cur = '';
  10314. for (var i = 0; i < pieces.length; ++i) {
  10315. cur += cur.length ? '.' + pieces[i] : pieces[i];
  10316. if (excluded.indexOf(cur) !== -1) {
  10317. return;
  10318. }
  10319. } // Special case: if user has included a parent path of a discriminator key,
  10320. // don't explicitly project in the discriminator key because that will
  10321. // project out everything else under the parent path
  10322. if (!exclude && (type && type.options && type.options.$skipDiscriminatorCheck || false)) {
  10323. var _cur = '';
  10324. for (var _i2 = 0; _i2 < pieces.length; ++_i2) {
  10325. _cur += (_cur.length === 0 ? '' : '.') + pieces[_i2];
  10326. var projection = get(fields, _cur, false) || get(fields, _cur + '.$', false);
  10327. if (projection && _typeof(projection) !== 'object') {
  10328. return;
  10329. }
  10330. }
  10331. }
  10332. (type.selected ? selected : excluded).push(path);
  10333. return path;
  10334. }
  10335. };
  10336. /*!
  10337. * Set each path query option to lean
  10338. *
  10339. * @param {Object} option
  10340. */
  10341. function makeLean(val) {
  10342. return function (option) {
  10343. option.options || (option.options = {});
  10344. if (val != null && Array.isArray(val.virtuals)) {
  10345. val = Object.assign({}, val);
  10346. val.virtuals = val.virtuals.filter(function (path) {
  10347. return typeof path === 'string' && path.startsWith(option.path + '.');
  10348. }).map(function (path) {
  10349. return path.slice(option.path.length + 1);
  10350. });
  10351. }
  10352. option.options.lean = val;
  10353. };
  10354. }
  10355. /***/ }),
  10356. /***/ 5506:
  10357. /***/ ((module, exports, __webpack_require__) => {
  10358. "use strict";
  10359. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  10360. /*!
  10361. * Module dependencies.
  10362. */
  10363. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  10364. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  10365. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  10366. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  10367. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  10368. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  10369. var Kareem = __webpack_require__(3138);
  10370. var MongooseError = __webpack_require__(5202);
  10371. var SchemaType = __webpack_require__(4289);
  10372. var SchemaTypeOptions = __webpack_require__(1764);
  10373. var VirtualOptions = __webpack_require__(1902);
  10374. var VirtualType = __webpack_require__(459);
  10375. var addAutoId = __webpack_require__(4133);
  10376. var get = __webpack_require__(9981);
  10377. var getConstructorName = __webpack_require__(1981);
  10378. var getIndexes = __webpack_require__(5379);
  10379. var idGetter = __webpack_require__(1879);
  10380. var merge = __webpack_require__(4913);
  10381. var mpath = __webpack_require__(3564);
  10382. var readPref = (__webpack_require__(9906).get)().ReadPreference;
  10383. var setupTimestamps = __webpack_require__(3767);
  10384. var utils = __webpack_require__(6872);
  10385. var validateRef = __webpack_require__(6870);
  10386. var util = __webpack_require__(161);
  10387. var MongooseTypes;
  10388. var queryHooks = (__webpack_require__(5130).middlewareFunctions);
  10389. var documentHooks = (__webpack_require__(8859).middlewareFunctions);
  10390. var hookNames = queryHooks.concat(documentHooks).reduce(function (s, hook) {
  10391. return s.add(hook);
  10392. }, new Set());
  10393. var isPOJO = utils.isPOJO;
  10394. var id = 0;
  10395. /**
  10396. * Schema constructor.
  10397. *
  10398. * #### Example:
  10399. *
  10400. * const child = new Schema({ name: String });
  10401. * const schema = new Schema({ name: String, age: Number, children: [child] });
  10402. * const Tree = mongoose.model('Tree', schema);
  10403. *
  10404. * // setting schema options
  10405. * new Schema({ name: String }, { _id: false, autoIndex: false })
  10406. *
  10407. * #### Options:
  10408. *
  10409. * - [autoIndex](/docs/guide.html#autoIndex): bool - defaults to null (which means use the connection's autoIndex option)
  10410. * - [autoCreate](/docs/guide.html#autoCreate): bool - defaults to null (which means use the connection's autoCreate option)
  10411. * - [bufferCommands](/docs/guide.html#bufferCommands): bool - defaults to true
  10412. * - [bufferTimeoutMS](/docs/guide.html#bufferTimeoutMS): number - defaults to 10000 (10 seconds). If `bufferCommands` is enabled, the amount of time Mongoose will wait for connectivity to be restablished before erroring out.
  10413. * - [capped](/docs/guide.html#capped): bool | number | object - defaults to false
  10414. * - [collection](/docs/guide.html#collection): string - no default
  10415. * - [discriminatorKey](/docs/guide.html#discriminatorKey): string - defaults to `__t`
  10416. * - [id](/docs/guide.html#id): bool - defaults to true
  10417. * - [_id](/docs/guide.html#_id): bool - defaults to true
  10418. * - [minimize](/docs/guide.html#minimize): bool - controls [document#toObject](#document_Document-toObject) behavior when called manually - defaults to true
  10419. * - [read](/docs/guide.html#read): string
  10420. * - [writeConcern](/docs/guide.html#writeConcern): object - defaults to null, use to override [the MongoDB server's default write concern settings](https://docs.mongodb.com/manual/reference/write-concern/)
  10421. * - [shardKey](/docs/guide.html#shardKey): object - defaults to `null`
  10422. * - [strict](/docs/guide.html#strict): bool - defaults to true
  10423. * - [strictQuery](/docs/guide.html#strictQuery): bool - defaults to false
  10424. * - [toJSON](/docs/guide.html#toJSON) - object - no default
  10425. * - [toObject](/docs/guide.html#toObject) - object - no default
  10426. * - [typeKey](/docs/guide.html#typeKey) - string - defaults to 'type'
  10427. * - [validateBeforeSave](/docs/guide.html#validateBeforeSave) - bool - defaults to `true`
  10428. * - [versionKey](/docs/guide.html#versionKey): string or object - defaults to "__v"
  10429. * - [optimisticConcurrency](/docs/guide.html#optimisticConcurrency): bool - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html).
  10430. * - [collation](/docs/guide.html#collation): object - defaults to null (which means use no collation)
  10431. * - [timeseries](/docs/guide.html#timeseries): object - defaults to null (which means this schema's collection won't be a timeseries collection)
  10432. * - [selectPopulatedPaths](/docs/guide.html#selectPopulatedPaths): boolean - defaults to `true`
  10433. * - [skipVersioning](/docs/guide.html#skipVersioning): object - paths to exclude from versioning
  10434. * - [timestamps](/docs/guide.html#timestamps): object or boolean - defaults to `false`. If true, Mongoose adds `createdAt` and `updatedAt` properties to your schema and manages those properties for you.
  10435. * - [pluginTags](/docs/guide.html#pluginTags): array of strings - defaults to `undefined`. If set and plugin called with `tags` option, will only apply that plugin to schemas with a matching tag.
  10436. *
  10437. * #### Options for Nested Schemas:
  10438. * - `excludeIndexes`: bool - defaults to `false`. If `true`, skip building indexes on this schema's paths.
  10439. *
  10440. * #### Note:
  10441. *
  10442. * _When nesting schemas, (`children` in the example above), always declare the child schema first before passing it into its parent._
  10443. *
  10444. * @param {Object|Schema|Array} [definition] Can be one of: object describing schema paths, or schema to copy, or array of objects and schemas
  10445. * @param {Object} [options]
  10446. * @inherits NodeJS EventEmitter https://nodejs.org/api/events.html#events_class_events_eventemitter
  10447. * @event `init`: Emitted after the schema is compiled into a `Model`.
  10448. * @api public
  10449. */
  10450. function Schema(obj, options) {
  10451. if (!(this instanceof Schema)) {
  10452. return new Schema(obj, options);
  10453. }
  10454. this.obj = obj;
  10455. this.paths = {};
  10456. this.aliases = {};
  10457. this.subpaths = {};
  10458. this.virtuals = {};
  10459. this.singleNestedPaths = {};
  10460. this.nested = {};
  10461. this.inherits = {};
  10462. this.callQueue = [];
  10463. this._indexes = [];
  10464. this.methods = options && options.methods || {};
  10465. this.methodOptions = {};
  10466. this.statics = options && options.statics || {};
  10467. this.tree = {};
  10468. this.query = options && options.query || {};
  10469. this.childSchemas = [];
  10470. this.plugins = []; // For internal debugging. Do not use this to try to save a schema in MDB.
  10471. this.$id = ++id;
  10472. this.mapPaths = [];
  10473. this.s = {
  10474. hooks: new Kareem()
  10475. };
  10476. this.options = this.defaultOptions(options); // build paths
  10477. if (Array.isArray(obj)) {
  10478. var _iterator = _createForOfIteratorHelper(obj),
  10479. _step;
  10480. try {
  10481. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  10482. var definition = _step.value;
  10483. this.add(definition);
  10484. }
  10485. } catch (err) {
  10486. _iterator.e(err);
  10487. } finally {
  10488. _iterator.f();
  10489. }
  10490. } else if (obj) {
  10491. this.add(obj);
  10492. } // check if _id's value is a subdocument (gh-2276)
  10493. var _idSubDoc = obj && obj._id && utils.isObject(obj._id); // ensure the documents get an auto _id unless disabled
  10494. var auto_id = !this.paths['_id'] && this.options._id && !_idSubDoc;
  10495. if (auto_id) {
  10496. addAutoId(this);
  10497. }
  10498. this.setupTimestamp(this.options.timestamps);
  10499. }
  10500. /*!
  10501. * Create virtual properties with alias field
  10502. */
  10503. function aliasFields(schema, paths) {
  10504. paths = paths || Object.keys(schema.paths);
  10505. var _iterator2 = _createForOfIteratorHelper(paths),
  10506. _step2;
  10507. try {
  10508. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  10509. var path = _step2.value;
  10510. var options = get(schema.paths[path], 'options');
  10511. if (options == null) {
  10512. continue;
  10513. }
  10514. var prop = schema.paths[path].path;
  10515. var alias = options.alias;
  10516. if (!alias) {
  10517. continue;
  10518. }
  10519. if (typeof alias !== 'string') {
  10520. throw new Error('Invalid value for alias option on ' + prop + ', got ' + alias);
  10521. }
  10522. schema.aliases[alias] = prop;
  10523. schema.virtual(alias).get(function (p) {
  10524. return function () {
  10525. if (typeof this.get === 'function') {
  10526. return this.get(p);
  10527. }
  10528. return this[p];
  10529. };
  10530. }(prop)).set(function (p) {
  10531. return function (v) {
  10532. return this.$set(p, v);
  10533. };
  10534. }(prop));
  10535. }
  10536. } catch (err) {
  10537. _iterator2.e(err);
  10538. } finally {
  10539. _iterator2.f();
  10540. }
  10541. }
  10542. /*!
  10543. * Inherit from EventEmitter.
  10544. */
  10545. Schema.prototype = Object.create(EventEmitter.prototype);
  10546. Schema.prototype.constructor = Schema;
  10547. Schema.prototype.instanceOfSchema = true;
  10548. /*!
  10549. * ignore
  10550. */
  10551. Object.defineProperty(Schema.prototype, '$schemaType', {
  10552. configurable: false,
  10553. enumerable: false,
  10554. writable: true
  10555. });
  10556. /**
  10557. * Array of child schemas (from document arrays and single nested subdocs)
  10558. * and their corresponding compiled models. Each element of the array is
  10559. * an object with 2 properties: `schema` and `model`.
  10560. *
  10561. * This property is typically only useful for plugin authors and advanced users.
  10562. * You do not need to interact with this property at all to use mongoose.
  10563. *
  10564. * @api public
  10565. * @property childSchemas
  10566. * @memberOf Schema
  10567. * @instance
  10568. */
  10569. Object.defineProperty(Schema.prototype, 'childSchemas', {
  10570. configurable: false,
  10571. enumerable: true,
  10572. writable: true
  10573. });
  10574. /**
  10575. * Object containing all virtuals defined on this schema.
  10576. * The objects' keys are the virtual paths and values are instances of `VirtualType`.
  10577. *
  10578. * This property is typically only useful for plugin authors and advanced users.
  10579. * You do not need to interact with this property at all to use mongoose.
  10580. *
  10581. * #### Example:
  10582. * const schema = new Schema({});
  10583. * schema.virtual('answer').get(() => 42);
  10584. *
  10585. * console.log(schema.virtuals); // { answer: VirtualType { path: 'answer', ... } }
  10586. * console.log(schema.virtuals['answer'].getters[0].call()); // 42
  10587. *
  10588. * @api public
  10589. * @property virtuals
  10590. * @memberOf Schema
  10591. * @instance
  10592. */
  10593. Object.defineProperty(Schema.prototype, 'virtuals', {
  10594. configurable: false,
  10595. enumerable: true,
  10596. writable: true
  10597. });
  10598. /**
  10599. * The original object passed to the schema constructor
  10600. *
  10601. * #### Example:
  10602. *
  10603. * const schema = new Schema({ a: String }).add({ b: String });
  10604. * schema.obj; // { a: String }
  10605. *
  10606. * @api public
  10607. * @property obj
  10608. * @memberOf Schema
  10609. * @instance
  10610. */
  10611. Schema.prototype.obj;
  10612. /**
  10613. * The paths defined on this schema. The keys are the top-level paths
  10614. * in this schema, and the values are instances of the SchemaType class.
  10615. *
  10616. * #### Example:
  10617. * const schema = new Schema({ name: String }, { _id: false });
  10618. * schema.paths; // { name: SchemaString { ... } }
  10619. *
  10620. * schema.add({ age: Number });
  10621. * schema.paths; // { name: SchemaString { ... }, age: SchemaNumber { ... } }
  10622. *
  10623. * @api public
  10624. * @property paths
  10625. * @memberOf Schema
  10626. * @instance
  10627. */
  10628. Schema.prototype.paths;
  10629. /**
  10630. * Schema as a tree
  10631. *
  10632. * #### Example:
  10633. * {
  10634. * '_id' : ObjectId
  10635. * , 'nested' : {
  10636. * 'key' : String
  10637. * }
  10638. * }
  10639. *
  10640. * @api private
  10641. * @property tree
  10642. * @memberOf Schema
  10643. * @instance
  10644. */
  10645. Schema.prototype.tree;
  10646. /**
  10647. * Returns a deep copy of the schema
  10648. *
  10649. * #### Example:
  10650. *
  10651. * const schema = new Schema({ name: String });
  10652. * const clone = schema.clone();
  10653. * clone === schema; // false
  10654. * clone.path('name'); // SchemaString { ... }
  10655. *
  10656. * @return {Schema} the cloned schema
  10657. * @api public
  10658. * @memberOf Schema
  10659. * @instance
  10660. */
  10661. Schema.prototype.clone = function () {
  10662. var _this2 = this;
  10663. var s = this._clone(); // Bubble up `init` for backwards compat
  10664. s.on('init', function (v) {
  10665. return _this2.emit('init', v);
  10666. });
  10667. return s;
  10668. };
  10669. /*!
  10670. * ignore
  10671. */
  10672. Schema.prototype._clone = function _clone(Constructor) {
  10673. Constructor = Constructor || (this.base == null ? Schema : this.base.Schema);
  10674. var s = new Constructor({}, this._userProvidedOptions);
  10675. s.base = this.base;
  10676. s.obj = this.obj;
  10677. s.options = utils.clone(this.options);
  10678. s.callQueue = this.callQueue.map(function (f) {
  10679. return f;
  10680. });
  10681. s.methods = utils.clone(this.methods);
  10682. s.methodOptions = utils.clone(this.methodOptions);
  10683. s.statics = utils.clone(this.statics);
  10684. s.query = utils.clone(this.query);
  10685. s.plugins = Array.prototype.slice.call(this.plugins);
  10686. s._indexes = utils.clone(this._indexes);
  10687. s.s.hooks = this.s.hooks.clone();
  10688. s.tree = utils.clone(this.tree);
  10689. s.paths = utils.clone(this.paths);
  10690. s.nested = utils.clone(this.nested);
  10691. s.subpaths = utils.clone(this.subpaths);
  10692. s.singleNestedPaths = utils.clone(this.singleNestedPaths);
  10693. s.childSchemas = gatherChildSchemas(s);
  10694. s.virtuals = utils.clone(this.virtuals);
  10695. s.$globalPluginsApplied = this.$globalPluginsApplied;
  10696. s.$isRootDiscriminator = this.$isRootDiscriminator;
  10697. s.$implicitlyCreated = this.$implicitlyCreated;
  10698. s.$id = ++id;
  10699. s.$originalSchemaId = this.$id;
  10700. s.mapPaths = [].concat(this.mapPaths);
  10701. if (this.discriminatorMapping != null) {
  10702. s.discriminatorMapping = Object.assign({}, this.discriminatorMapping);
  10703. }
  10704. if (this.discriminators != null) {
  10705. s.discriminators = Object.assign({}, this.discriminators);
  10706. }
  10707. if (this._applyDiscriminators != null) {
  10708. s._applyDiscriminators = Object.assign({}, this._applyDiscriminators);
  10709. }
  10710. s.aliases = Object.assign({}, this.aliases);
  10711. return s;
  10712. };
  10713. /**
  10714. * Returns a new schema that has the picked `paths` from this schema.
  10715. *
  10716. * This method is analagous to [Lodash's `pick()` function](https://lodash.com/docs/4.17.15#pick) for Mongoose schemas.
  10717. *
  10718. * #### Example:
  10719. *
  10720. * const schema = Schema({ name: String, age: Number });
  10721. * // Creates a new schema with the same `name` path as `schema`,
  10722. * // but no `age` path.
  10723. * const newSchema = schema.pick(['name']);
  10724. *
  10725. * newSchema.path('name'); // SchemaString { ... }
  10726. * newSchema.path('age'); // undefined
  10727. *
  10728. * @param {Array} paths list of paths to pick
  10729. * @param {Object} [options] options to pass to the schema constructor. Defaults to `this.options` if not set.
  10730. * @return {Schema}
  10731. * @api public
  10732. */
  10733. Schema.prototype.pick = function (paths, options) {
  10734. var newSchema = new Schema({}, options || this.options);
  10735. if (!Array.isArray(paths)) {
  10736. throw new MongooseError('Schema#pick() only accepts an array argument, ' + 'got "' + _typeof(paths) + '"');
  10737. }
  10738. var _iterator3 = _createForOfIteratorHelper(paths),
  10739. _step3;
  10740. try {
  10741. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  10742. var path = _step3.value;
  10743. if (this.nested[path]) {
  10744. newSchema.add(_defineProperty({}, path, get(this.tree, path)));
  10745. } else {
  10746. var schematype = this.path(path);
  10747. if (schematype == null) {
  10748. throw new MongooseError('Path `' + path + '` is not in the schema');
  10749. }
  10750. newSchema.add(_defineProperty({}, path, schematype));
  10751. }
  10752. }
  10753. } catch (err) {
  10754. _iterator3.e(err);
  10755. } finally {
  10756. _iterator3.f();
  10757. }
  10758. return newSchema;
  10759. };
  10760. /**
  10761. * Returns default options for this schema, merged with `options`.
  10762. *
  10763. * @param {Object} options
  10764. * @return {Object}
  10765. * @api private
  10766. */
  10767. Schema.prototype.defaultOptions = function (options) {
  10768. this._userProvidedOptions = options == null ? {} : utils.clone(options);
  10769. var baseOptions = this.base && this.base.options || {};
  10770. var strict = 'strict' in baseOptions ? baseOptions.strict : true;
  10771. options = utils.options({
  10772. strict: strict,
  10773. strictQuery: 'strict' in this._userProvidedOptions ? this._userProvidedOptions.strict : 'strictQuery' in baseOptions ? baseOptions.strictQuery : strict,
  10774. bufferCommands: true,
  10775. capped: false,
  10776. // { size, max, autoIndexId }
  10777. versionKey: '__v',
  10778. optimisticConcurrency: false,
  10779. minimize: true,
  10780. autoIndex: null,
  10781. discriminatorKey: '__t',
  10782. shardKey: null,
  10783. read: null,
  10784. validateBeforeSave: true,
  10785. // the following are only applied at construction time
  10786. _id: true,
  10787. id: true,
  10788. typeKey: 'type'
  10789. }, utils.clone(options));
  10790. if (options.read) {
  10791. options.read = readPref(options.read);
  10792. }
  10793. if (options.versionKey && typeof options.versionKey !== 'string') {
  10794. throw new MongooseError('`versionKey` must be falsy or string, got `' + _typeof(options.versionKey) + '`');
  10795. }
  10796. if (options.optimisticConcurrency && !options.versionKey) {
  10797. throw new MongooseError('Must set `versionKey` if using `optimisticConcurrency`');
  10798. }
  10799. return options;
  10800. };
  10801. /**
  10802. * Inherit a Schema by applying a discriminator on an existing Schema.
  10803. *
  10804. *
  10805. * ####Example:
  10806. *
  10807. * const options = { discriminatorKey: 'kind' };
  10808. *
  10809. * const eventSchema = new mongoose.Schema({ time: Date }, options);
  10810. * const Event = mongoose.model('Event', eventSchema);
  10811. *
  10812. * // ClickedLinkEvent is a special type of Event that has
  10813. * // a URL.
  10814. * const ClickedLinkEvent = Event.discriminator('ClickedLink',
  10815. * new mongoose.Schema({ url: String }, options));
  10816. *
  10817. * // When you create a generic event, it can't have a URL field...
  10818. * const genericEvent = new Event({ time: Date.now(), url: 'google.com' });
  10819. * assert.ok(!genericEvent.url);
  10820. * // But a ClickedLinkEvent can
  10821. * const clickedEvent = new ClickedLinkEvent({ time: Date.now(), url: 'google.com' });
  10822. * assert.ok(clickedEvent.url);
  10823. *
  10824. * @param {String} name the name of the discriminator
  10825. * @param {Schema} schema the Schema of the discriminated Schema
  10826. * @return {Schema} the Schema instance
  10827. * @api public
  10828. */
  10829. Schema.prototype.discriminator = function (name, schema) {
  10830. this._applyDiscriminators = Object.assign(this._applyDiscriminators || {}, _defineProperty({}, name, schema));
  10831. return this;
  10832. };
  10833. /**
  10834. * Adds key path / schema type pairs to this schema.
  10835. *
  10836. * #### Example:
  10837. *
  10838. * const ToySchema = new Schema();
  10839. * ToySchema.add({ name: 'string', color: 'string', price: 'number' });
  10840. *
  10841. * const TurboManSchema = new Schema();
  10842. * // You can also `add()` another schema and copy over all paths, virtuals,
  10843. * // getters, setters, indexes, methods, and statics.
  10844. * TurboManSchema.add(ToySchema).add({ year: Number });
  10845. *
  10846. * @param {Object|Schema} obj plain object with paths to add, or another schema
  10847. * @param {String} [prefix] path to prefix the newly added paths with
  10848. * @return {Schema} the Schema instance
  10849. * @api public
  10850. */
  10851. Schema.prototype.add = function add(obj, prefix) {
  10852. if (obj instanceof Schema || obj != null && obj.instanceOfSchema) {
  10853. merge(this, obj);
  10854. return this;
  10855. } // Special case: setting top-level `_id` to false should convert to disabling
  10856. // the `_id` option. This behavior never worked before 5.4.11 but numerous
  10857. // codebases use it (see gh-7516, gh-7512).
  10858. if (obj._id === false && prefix == null) {
  10859. this.options._id = false;
  10860. }
  10861. prefix = prefix || ''; // avoid prototype pollution
  10862. if (prefix === '__proto__.' || prefix === 'constructor.' || prefix === 'prototype.') {
  10863. return this;
  10864. }
  10865. var keys = Object.keys(obj);
  10866. var typeKey = this.options.typeKey;
  10867. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  10868. var key = _keys[_i];
  10869. var fullPath = prefix + key;
  10870. var val = obj[key];
  10871. if (val == null) {
  10872. throw new TypeError('Invalid value for schema path `' + fullPath + '`, got value "' + val + '"');
  10873. } // Retain `_id: false` but don't set it as a path, re: gh-8274.
  10874. if (key === '_id' && val === false) {
  10875. continue;
  10876. }
  10877. if (val instanceof VirtualType || (val.constructor && val.constructor.name || null) === 'VirtualType') {
  10878. this.virtual(val);
  10879. continue;
  10880. }
  10881. if (Array.isArray(val) && val.length === 1 && val[0] == null) {
  10882. throw new TypeError('Invalid value for schema Array path `' + fullPath + '`, got value "' + val[0] + '"');
  10883. }
  10884. if (!(isPOJO(val) || val instanceof SchemaTypeOptions)) {
  10885. // Special-case: Non-options definitely a path so leaf at this node
  10886. // Examples: Schema instances, SchemaType instances
  10887. if (prefix) {
  10888. this.nested[prefix.substring(0, prefix.length - 1)] = true;
  10889. }
  10890. this.path(prefix + key, val);
  10891. if (val[0] != null && !val[0].instanceOfSchema && utils.isPOJO(val[0].discriminators)) {
  10892. var schemaType = this.path(prefix + key);
  10893. for (var _key in val[0].discriminators) {
  10894. schemaType.discriminator(_key, val[0].discriminators[_key]);
  10895. }
  10896. } else if (val[0] != null && val[0].instanceOfSchema && utils.isPOJO(val[0]._applyDiscriminators)) {
  10897. var applyDiscriminators = val[0]._applyDiscriminators || [];
  10898. var _schemaType2 = this.path(prefix + key);
  10899. for (var disc in applyDiscriminators) {
  10900. _schemaType2.discriminator(disc, applyDiscriminators[disc]);
  10901. }
  10902. } else if (val != null && val.instanceOfSchema && utils.isPOJO(val._applyDiscriminators)) {
  10903. var _applyDiscriminators = val._applyDiscriminators || [];
  10904. var _schemaType3 = this.path(prefix + key);
  10905. for (var _disc in _applyDiscriminators) {
  10906. _schemaType3.discriminator(_disc, _applyDiscriminators[_disc]);
  10907. }
  10908. }
  10909. } else if (Object.keys(val).length < 1) {
  10910. // Special-case: {} always interpreted as Mixed path so leaf at this node
  10911. if (prefix) {
  10912. this.nested[prefix.substring(0, prefix.length - 1)] = true;
  10913. }
  10914. this.path(fullPath, val); // mixed type
  10915. } else if (!val[typeKey] || typeKey === 'type' && isPOJO(val.type) && val.type.type) {
  10916. // Special-case: POJO with no bona-fide type key - interpret as tree of deep paths so recurse
  10917. // nested object `{ last: { name: String } }`. Avoid functions with `.type` re: #10807 because
  10918. // NestJS sometimes adds `Date.type`.
  10919. this.nested[fullPath] = true;
  10920. this.add(val, fullPath + '.');
  10921. } else {
  10922. // There IS a bona-fide type key that may also be a POJO
  10923. var _typeDef = val[typeKey];
  10924. if (isPOJO(_typeDef) && Object.keys(_typeDef).length > 0) {
  10925. // If a POJO is the value of a type key, make it a subdocument
  10926. if (prefix) {
  10927. this.nested[prefix.substring(0, prefix.length - 1)] = true;
  10928. }
  10929. var _schema = new Schema(_typeDef);
  10930. var schemaWrappedPath = Object.assign({}, val, {
  10931. type: _schema
  10932. });
  10933. this.path(prefix + key, schemaWrappedPath);
  10934. } else {
  10935. // Either the type is non-POJO or we interpret it as Mixed anyway
  10936. if (prefix) {
  10937. this.nested[prefix.substring(0, prefix.length - 1)] = true;
  10938. }
  10939. this.path(prefix + key, val);
  10940. if (val != null && !val.instanceOfSchema && utils.isPOJO(val.discriminators)) {
  10941. var _schemaType4 = this.path(prefix + key);
  10942. for (var _key2 in val.discriminators) {
  10943. _schemaType4.discriminator(_key2, val.discriminators[_key2]);
  10944. }
  10945. }
  10946. }
  10947. }
  10948. }
  10949. var addedKeys = Object.keys(obj).map(function (key) {
  10950. return prefix ? prefix + key : key;
  10951. });
  10952. aliasFields(this, addedKeys);
  10953. return this;
  10954. };
  10955. /**
  10956. * Remove an index by name or index specification.
  10957. *
  10958. * removeIndex only removes indexes from your schema object. Does **not** affect the indexes
  10959. * in MongoDB.
  10960. *
  10961. * ####Example:
  10962. *
  10963. * const ToySchema = new Schema({ name: String, color: String, price: Number });
  10964. *
  10965. * // Add a new index on { name, color }
  10966. * ToySchema.index({ name: 1, color: 1 });
  10967. *
  10968. * // Remove index on { name, color }
  10969. * // Keep in mind that order matters! `removeIndex({ color: 1, name: 1 })` won't remove the index
  10970. * ToySchema.removeIndex({ name: 1, color: 1 });
  10971. *
  10972. * // Add an index with a custom name
  10973. * ToySchema.index({ color: 1 }, { name: 'my custom index name' });
  10974. * // Remove index by name
  10975. * ToySchema.removeIndex('my custom index name');
  10976. *
  10977. * @param {Object|string} index name or index specification
  10978. * @return {Schema} the Schema instance
  10979. * @api public
  10980. */
  10981. Schema.prototype.removeIndex = function removeIndex(index) {
  10982. if (arguments.length > 1) {
  10983. throw new Error('removeIndex() takes only 1 argument');
  10984. }
  10985. if (_typeof(index) !== 'object' && typeof index !== 'string') {
  10986. throw new Error('removeIndex() may only take either an object or a string as an argument');
  10987. }
  10988. if (_typeof(index) === 'object') {
  10989. for (var i = this._indexes.length - 1; i >= 0; --i) {
  10990. if (util.isDeepStrictEqual(this._indexes[i][0], index)) {
  10991. this._indexes.splice(i, 1);
  10992. }
  10993. }
  10994. } else {
  10995. for (var _i2 = this._indexes.length - 1; _i2 >= 0; --_i2) {
  10996. if (this._indexes[_i2][1] != null && this._indexes[_i2][1].name === index) {
  10997. this._indexes.splice(_i2, 1);
  10998. }
  10999. }
  11000. }
  11001. return this;
  11002. };
  11003. /**
  11004. * Remove all indexes from this schema.
  11005. *
  11006. * clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
  11007. * in MongoDB.
  11008. *
  11009. * ####Example:
  11010. *
  11011. * const ToySchema = new Schema({ name: String, color: String, price: Number });
  11012. * ToySchema.index({ name: 1 });
  11013. * ToySchema.index({ color: 1 });
  11014. *
  11015. * // Remove all indexes on this schema
  11016. * ToySchema.clearIndexes();
  11017. *
  11018. * ToySchema.indexes(); // []
  11019. *
  11020. * @return {Schema} the Schema instance
  11021. * @api public
  11022. */
  11023. Schema.prototype.clearIndexes = function clearIndexes() {
  11024. this._indexes.length = 0;
  11025. return this;
  11026. };
  11027. /**
  11028. * Reserved document keys.
  11029. *
  11030. * Keys in this object are names that are warned in schema declarations
  11031. * because they have the potential to break Mongoose/ Mongoose plugins functionality. If you create a schema
  11032. * using `new Schema()` with one of these property names, Mongoose will log a warning.
  11033. *
  11034. * - _posts
  11035. * - _pres
  11036. * - collection
  11037. * - emit
  11038. * - errors
  11039. * - get
  11040. * - init
  11041. * - isModified
  11042. * - isNew
  11043. * - listeners
  11044. * - modelName
  11045. * - on
  11046. * - once
  11047. * - populated
  11048. * - prototype
  11049. * - remove
  11050. * - removeListener
  11051. * - save
  11052. * - schema
  11053. * - toObject
  11054. * - validate
  11055. *
  11056. * _NOTE:_ Use of these terms as method names is permitted, but play at your own risk, as they may be existing mongoose document methods you are stomping on.
  11057. *
  11058. * const schema = new Schema(..);
  11059. * schema.methods.init = function () {} // potentially breaking
  11060. */
  11061. Schema.reserved = Object.create(null);
  11062. Schema.prototype.reserved = Schema.reserved;
  11063. var reserved = Schema.reserved; // Core object
  11064. reserved['prototype'] = // EventEmitter
  11065. reserved.emit = reserved.listeners = reserved.removeListener = // document properties and functions
  11066. reserved.collection = reserved.errors = reserved.get = reserved.init = reserved.isModified = reserved.isNew = reserved.populated = reserved.remove = reserved.save = reserved.toObject = reserved.validate = 1;
  11067. reserved.collection = 1;
  11068. /**
  11069. * Gets/sets schema paths.
  11070. *
  11071. * Sets a path (if arity 2)
  11072. * Gets a path (if arity 1)
  11073. *
  11074. * #### Example
  11075. *
  11076. * schema.path('name') // returns a SchemaType
  11077. * schema.path('name', Number) // changes the schemaType of `name` to Number
  11078. *
  11079. * @param {String} path
  11080. * @param {Object} constructor
  11081. * @api public
  11082. */
  11083. Schema.prototype.path = function (path, obj) {
  11084. // Convert to '.$' to check subpaths re: gh-6405
  11085. var cleanPath = _pathToPositionalSyntax(path);
  11086. if (obj === undefined) {
  11087. var schematype = _getPath(this, path, cleanPath);
  11088. if (schematype != null) {
  11089. return schematype;
  11090. } // Look for maps
  11091. var mapPath = getMapPath(this, path);
  11092. if (mapPath != null) {
  11093. return mapPath;
  11094. } // Look if a parent of this path is mixed
  11095. schematype = this.hasMixedParent(cleanPath);
  11096. if (schematype != null) {
  11097. return schematype;
  11098. } // subpaths?
  11099. return /\.\d+\.?.*$/.test(path) ? getPositionalPath(this, path) : undefined;
  11100. } // some path names conflict with document methods
  11101. var firstPieceOfPath = path.split('.')[0];
  11102. if (reserved[firstPieceOfPath] && !this.options.supressReservedKeysWarning) {
  11103. var errorMessage = "`".concat(firstPieceOfPath, "` is a reserved schema pathname and may break some functionality. ") + 'You are allowed to use it, but use at your own risk. ' + 'To disable this warning pass `supressReservedKeysWarning` as a schema option.';
  11104. utils.warn(errorMessage);
  11105. }
  11106. if (_typeof(obj) === 'object' && utils.hasUserDefinedProperty(obj, 'ref')) {
  11107. validateRef(obj.ref, path);
  11108. } // update the tree
  11109. var subpaths = path.split(/\./);
  11110. var last = subpaths.pop();
  11111. var branch = this.tree;
  11112. var fullPath = '';
  11113. var _iterator4 = _createForOfIteratorHelper(subpaths),
  11114. _step4;
  11115. try {
  11116. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  11117. var sub = _step4.value;
  11118. fullPath = fullPath += (fullPath.length > 0 ? '.' : '') + sub;
  11119. if (!branch[sub]) {
  11120. this.nested[fullPath] = true;
  11121. branch[sub] = {};
  11122. }
  11123. if (_typeof(branch[sub]) !== 'object') {
  11124. var msg = 'Cannot set nested path `' + path + '`. ' + 'Parent path `' + fullPath + '` already set to type ' + branch[sub].name + '.';
  11125. throw new Error(msg);
  11126. }
  11127. branch = branch[sub];
  11128. }
  11129. } catch (err) {
  11130. _iterator4.e(err);
  11131. } finally {
  11132. _iterator4.f();
  11133. }
  11134. branch[last] = utils.clone(obj);
  11135. this.paths[path] = this.interpretAsType(path, obj, this.options);
  11136. var schemaType = this.paths[path];
  11137. if (schemaType.$isSchemaMap) {
  11138. // Maps can have arbitrary keys, so `$*` is internal shorthand for "any key"
  11139. // The '$' is to imply this path should never be stored in MongoDB so we
  11140. // can easily build a regexp out of this path, and '*' to imply "any key."
  11141. var _mapPath = path + '.$*';
  11142. this.paths[_mapPath] = schemaType.$__schemaType;
  11143. this.mapPaths.push(this.paths[_mapPath]);
  11144. }
  11145. if (schemaType.$isSingleNested) {
  11146. for (var _i3 = 0, _Object$keys = Object.keys(schemaType.schema.paths); _i3 < _Object$keys.length; _i3++) {
  11147. var key = _Object$keys[_i3];
  11148. this.singleNestedPaths[path + '.' + key] = schemaType.schema.paths[key];
  11149. }
  11150. for (var _i4 = 0, _Object$keys2 = Object.keys(schemaType.schema.singleNestedPaths); _i4 < _Object$keys2.length; _i4++) {
  11151. var _key3 = _Object$keys2[_i4];
  11152. this.singleNestedPaths[path + '.' + _key3] = schemaType.schema.singleNestedPaths[_key3];
  11153. }
  11154. for (var _i5 = 0, _Object$keys3 = Object.keys(schemaType.schema.subpaths); _i5 < _Object$keys3.length; _i5++) {
  11155. var _key4 = _Object$keys3[_i5];
  11156. this.singleNestedPaths[path + '.' + _key4] = schemaType.schema.subpaths[_key4];
  11157. }
  11158. for (var _i6 = 0, _Object$keys4 = Object.keys(schemaType.schema.nested); _i6 < _Object$keys4.length; _i6++) {
  11159. var _key5 = _Object$keys4[_i6];
  11160. this.singleNestedPaths[path + '.' + _key5] = 'nested';
  11161. }
  11162. Object.defineProperty(schemaType.schema, 'base', {
  11163. configurable: true,
  11164. enumerable: false,
  11165. writable: false,
  11166. value: this.base
  11167. });
  11168. schemaType.caster.base = this.base;
  11169. this.childSchemas.push({
  11170. schema: schemaType.schema,
  11171. model: schemaType.caster
  11172. });
  11173. } else if (schemaType.$isMongooseDocumentArray) {
  11174. Object.defineProperty(schemaType.schema, 'base', {
  11175. configurable: true,
  11176. enumerable: false,
  11177. writable: false,
  11178. value: this.base
  11179. });
  11180. schemaType.casterConstructor.base = this.base;
  11181. this.childSchemas.push({
  11182. schema: schemaType.schema,
  11183. model: schemaType.casterConstructor
  11184. });
  11185. }
  11186. if (schemaType.$isMongooseArray && schemaType.caster instanceof SchemaType) {
  11187. var arrayPath = path;
  11188. var _schemaType = schemaType;
  11189. var toAdd = [];
  11190. while (_schemaType.$isMongooseArray) {
  11191. arrayPath = arrayPath + '.$'; // Skip arrays of document arrays
  11192. if (_schemaType.$isMongooseDocumentArray) {
  11193. _schemaType.$embeddedSchemaType._arrayPath = arrayPath;
  11194. _schemaType.$embeddedSchemaType._arrayParentPath = path;
  11195. _schemaType = _schemaType.$embeddedSchemaType.clone();
  11196. } else {
  11197. _schemaType.caster._arrayPath = arrayPath;
  11198. _schemaType.caster._arrayParentPath = path;
  11199. _schemaType = _schemaType.caster.clone();
  11200. }
  11201. _schemaType.path = arrayPath;
  11202. toAdd.push(_schemaType);
  11203. }
  11204. for (var _i7 = 0, _toAdd = toAdd; _i7 < _toAdd.length; _i7++) {
  11205. var _schemaType5 = _toAdd[_i7];
  11206. this.subpaths[_schemaType5.path] = _schemaType5;
  11207. }
  11208. }
  11209. if (schemaType.$isMongooseDocumentArray) {
  11210. for (var _i8 = 0, _Object$keys5 = Object.keys(schemaType.schema.paths); _i8 < _Object$keys5.length; _i8++) {
  11211. var _key6 = _Object$keys5[_i8];
  11212. var _schemaType6 = schemaType.schema.paths[_key6];
  11213. this.subpaths[path + '.' + _key6] = _schemaType6;
  11214. if (_typeof(_schemaType6) === 'object' && _schemaType6 != null) {
  11215. _schemaType6.$isUnderneathDocArray = true;
  11216. }
  11217. }
  11218. for (var _i9 = 0, _Object$keys6 = Object.keys(schemaType.schema.subpaths); _i9 < _Object$keys6.length; _i9++) {
  11219. var _key7 = _Object$keys6[_i9];
  11220. var _schemaType7 = schemaType.schema.subpaths[_key7];
  11221. this.subpaths[path + '.' + _key7] = _schemaType7;
  11222. if (_typeof(_schemaType7) === 'object' && _schemaType7 != null) {
  11223. _schemaType7.$isUnderneathDocArray = true;
  11224. }
  11225. }
  11226. for (var _i10 = 0, _Object$keys7 = Object.keys(schemaType.schema.singleNestedPaths); _i10 < _Object$keys7.length; _i10++) {
  11227. var _key8 = _Object$keys7[_i10];
  11228. var _schemaType8 = schemaType.schema.singleNestedPaths[_key8];
  11229. this.subpaths[path + '.' + _key8] = _schemaType8;
  11230. if (_typeof(_schemaType8) === 'object' && _schemaType8 != null) {
  11231. _schemaType8.$isUnderneathDocArray = true;
  11232. }
  11233. }
  11234. }
  11235. return this;
  11236. };
  11237. /*!
  11238. * ignore
  11239. */
  11240. function gatherChildSchemas(schema) {
  11241. var childSchemas = [];
  11242. for (var _i11 = 0, _Object$keys8 = Object.keys(schema.paths); _i11 < _Object$keys8.length; _i11++) {
  11243. var path = _Object$keys8[_i11];
  11244. var schematype = schema.paths[path];
  11245. if (schematype.$isMongooseDocumentArray || schematype.$isSingleNested) {
  11246. childSchemas.push({
  11247. schema: schematype.schema,
  11248. model: schematype.caster
  11249. });
  11250. }
  11251. }
  11252. return childSchemas;
  11253. }
  11254. /*!
  11255. * ignore
  11256. */
  11257. function _getPath(schema, path, cleanPath) {
  11258. if (schema.paths.hasOwnProperty(path)) {
  11259. return schema.paths[path];
  11260. }
  11261. if (schema.subpaths.hasOwnProperty(cleanPath)) {
  11262. return schema.subpaths[cleanPath];
  11263. }
  11264. if (schema.singleNestedPaths.hasOwnProperty(cleanPath) && _typeof(schema.singleNestedPaths[cleanPath]) === 'object') {
  11265. return schema.singleNestedPaths[cleanPath];
  11266. }
  11267. return null;
  11268. }
  11269. /*!
  11270. * ignore
  11271. */
  11272. function _pathToPositionalSyntax(path) {
  11273. if (!/\.\d+/.test(path)) {
  11274. return path;
  11275. }
  11276. return path.replace(/\.\d+\./g, '.$.').replace(/\.\d+$/, '.$');
  11277. }
  11278. /*!
  11279. * ignore
  11280. */
  11281. function getMapPath(schema, path) {
  11282. if (schema.mapPaths.length === 0) {
  11283. return null;
  11284. }
  11285. var _iterator5 = _createForOfIteratorHelper(schema.mapPaths),
  11286. _step5;
  11287. try {
  11288. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  11289. var val = _step5.value;
  11290. var _path = val.path;
  11291. var re = new RegExp('^' + _path.replace(/\.\$\*/g, '\\.[^.]+') + '$');
  11292. if (re.test(path)) {
  11293. return schema.paths[_path];
  11294. }
  11295. }
  11296. } catch (err) {
  11297. _iterator5.e(err);
  11298. } finally {
  11299. _iterator5.f();
  11300. }
  11301. return null;
  11302. }
  11303. /**
  11304. * The Mongoose instance this schema is associated with
  11305. *
  11306. * @property base
  11307. * @api private
  11308. */
  11309. Object.defineProperty(Schema.prototype, 'base', {
  11310. configurable: true,
  11311. enumerable: false,
  11312. writable: true,
  11313. value: null
  11314. });
  11315. /**
  11316. * Converts type arguments into Mongoose Types.
  11317. *
  11318. * @param {String} path
  11319. * @param {Object} obj constructor
  11320. * @api private
  11321. */
  11322. Schema.prototype.interpretAsType = function (path, obj, options) {
  11323. if (obj instanceof SchemaType) {
  11324. if (obj.path === path) {
  11325. return obj;
  11326. }
  11327. var clone = obj.clone();
  11328. clone.path = path;
  11329. return clone;
  11330. } // If this schema has an associated Mongoose object, use the Mongoose object's
  11331. // copy of SchemaTypes re: gh-7158 gh-6933
  11332. var MongooseTypes = this.base != null ? this.base.Schema.Types : Schema.Types;
  11333. if (!utils.isPOJO(obj) && !(obj instanceof SchemaTypeOptions)) {
  11334. var constructorName = utils.getFunctionName(obj.constructor);
  11335. if (constructorName !== 'Object') {
  11336. var oldObj = obj;
  11337. obj = {};
  11338. obj[options.typeKey] = oldObj;
  11339. }
  11340. } // Get the type making sure to allow keys named "type"
  11341. // and default to mixed if not specified.
  11342. // { type: { type: String, default: 'freshcut' } }
  11343. var type = obj[options.typeKey] && (obj[options.typeKey] instanceof Function || options.typeKey !== 'type' || !obj.type.type) ? obj[options.typeKey] : {};
  11344. var name;
  11345. if (utils.isPOJO(type) || type === 'mixed') {
  11346. return new MongooseTypes.Mixed(path, obj);
  11347. }
  11348. if (Array.isArray(type) || type === Array || type === 'array' || type === MongooseTypes.Array) {
  11349. // if it was specified through { type } look for `cast`
  11350. var cast = type === Array || type === 'array' ? obj.cast || obj.of : type[0]; // new Schema({ path: [new Schema({ ... })] })
  11351. if (cast && cast.instanceOfSchema) {
  11352. if (!(cast instanceof Schema)) {
  11353. throw new TypeError('Schema for array path `' + path + '` is from a different copy of the Mongoose module. ' + 'Please make sure you\'re using the same version ' + 'of Mongoose everywhere with `npm list mongoose`. If you are still ' + 'getting this error, please add `new Schema()` around the path: ' + "".concat(path, ": new Schema(...)"));
  11354. }
  11355. return new MongooseTypes.DocumentArray(path, cast, obj);
  11356. }
  11357. if (cast && cast[options.typeKey] && cast[options.typeKey].instanceOfSchema) {
  11358. if (!(cast[options.typeKey] instanceof Schema)) {
  11359. throw new TypeError('Schema for array path `' + path + '` is from a different copy of the Mongoose module. ' + 'Please make sure you\'re using the same version ' + 'of Mongoose everywhere with `npm list mongoose`. If you are still ' + 'getting this error, please add `new Schema()` around the path: ' + "".concat(path, ": new Schema(...)"));
  11360. }
  11361. return new MongooseTypes.DocumentArray(path, cast[options.typeKey], obj, cast);
  11362. }
  11363. if (Array.isArray(cast)) {
  11364. return new MongooseTypes.Array(path, this.interpretAsType(path, cast, options), obj);
  11365. } // Handle both `new Schema({ arr: [{ subpath: String }] })` and `new Schema({ arr: [{ type: { subpath: string } }] })`
  11366. var castFromTypeKey = cast != null && cast[options.typeKey] && (options.typeKey !== 'type' || !cast.type.type) ? cast[options.typeKey] : cast;
  11367. if (typeof cast === 'string') {
  11368. cast = MongooseTypes[cast.charAt(0).toUpperCase() + cast.substring(1)];
  11369. } else if (utils.isPOJO(castFromTypeKey)) {
  11370. if (Object.keys(castFromTypeKey).length) {
  11371. // The `minimize` and `typeKey` options propagate to child schemas
  11372. // declared inline, like `{ arr: [{ val: { $type: String } }] }`.
  11373. // See gh-3560
  11374. var childSchemaOptions = {
  11375. minimize: options.minimize
  11376. };
  11377. if (options.typeKey) {
  11378. childSchemaOptions.typeKey = options.typeKey;
  11379. } // propagate 'strict' option to child schema
  11380. if (options.hasOwnProperty('strict')) {
  11381. childSchemaOptions.strict = options.strict;
  11382. }
  11383. if (this._userProvidedOptions.hasOwnProperty('_id')) {
  11384. childSchemaOptions._id = this._userProvidedOptions._id;
  11385. } else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
  11386. childSchemaOptions._id = Schema.Types.DocumentArray.defaultOptions._id;
  11387. }
  11388. var childSchema = new Schema(castFromTypeKey, childSchemaOptions);
  11389. childSchema.$implicitlyCreated = true;
  11390. return new MongooseTypes.DocumentArray(path, childSchema, obj);
  11391. } else {
  11392. // Special case: empty object becomes mixed
  11393. return new MongooseTypes.Array(path, MongooseTypes.Mixed, obj);
  11394. }
  11395. }
  11396. if (cast) {
  11397. type = cast[options.typeKey] && (options.typeKey !== 'type' || !cast.type.type) ? cast[options.typeKey] : cast;
  11398. if (Array.isArray(type)) {
  11399. return new MongooseTypes.Array(path, this.interpretAsType(path, type, options), obj);
  11400. }
  11401. name = typeof type === 'string' ? type : type.schemaName || utils.getFunctionName(type); // For Jest 26+, see #10296
  11402. if (name === 'ClockDate') {
  11403. name = 'Date';
  11404. }
  11405. if (name === void 0) {
  11406. throw new TypeError('Invalid schema configuration: ' + "Could not determine the embedded type for array `".concat(path, "`. ") + 'See https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');
  11407. }
  11408. if (!MongooseTypes.hasOwnProperty(name)) {
  11409. throw new TypeError('Invalid schema configuration: ' + "`".concat(name, "` is not a valid type within the array `").concat(path, "`.") + 'See https://bit.ly/mongoose-schematypes for a list of valid schema types.');
  11410. }
  11411. }
  11412. return new MongooseTypes.Array(path, cast || MongooseTypes.Mixed, obj, options);
  11413. }
  11414. if (type && type.instanceOfSchema) {
  11415. return new MongooseTypes.Subdocument(type, path, obj);
  11416. }
  11417. if (Buffer.isBuffer(type)) {
  11418. name = 'Buffer';
  11419. } else if (typeof type === 'function' || _typeof(type) === 'object') {
  11420. name = type.schemaName || utils.getFunctionName(type);
  11421. } else {
  11422. name = type == null ? '' + type : type.toString();
  11423. }
  11424. if (name) {
  11425. name = name.charAt(0).toUpperCase() + name.substring(1);
  11426. } // Special case re: gh-7049 because the bson `ObjectID` class' capitalization
  11427. // doesn't line up with Mongoose's.
  11428. if (name === 'ObjectID') {
  11429. name = 'ObjectId';
  11430. } // For Jest 26+, see #10296
  11431. if (name === 'ClockDate') {
  11432. name = 'Date';
  11433. }
  11434. if (name === void 0) {
  11435. throw new TypeError("Invalid schema configuration: `".concat(path, "` schematype definition is ") + 'invalid. See ' + 'https://mongoosejs.com/docs/guide.html#definition for more info on supported schema syntaxes.');
  11436. }
  11437. if (MongooseTypes[name] == null) {
  11438. throw new TypeError("Invalid schema configuration: `".concat(name, "` is not ") + "a valid type at path `".concat(path, "`. See ") + 'https://bit.ly/mongoose-schematypes for a list of valid schema types.');
  11439. }
  11440. var schemaType = new MongooseTypes[name](path, obj);
  11441. if (schemaType.$isSchemaMap) {
  11442. createMapNestedSchemaType(this, schemaType, path, obj, options);
  11443. }
  11444. return schemaType;
  11445. };
  11446. /*!
  11447. * ignore
  11448. */
  11449. function createMapNestedSchemaType(schema, schemaType, path, obj, options) {
  11450. var mapPath = path + '.$*';
  11451. var _mapType = {
  11452. type: {}
  11453. };
  11454. if (utils.hasUserDefinedProperty(obj, 'of')) {
  11455. var isInlineSchema = utils.isPOJO(obj.of) && Object.keys(obj.of).length > 0 && !utils.hasUserDefinedProperty(obj.of, schema.options.typeKey);
  11456. if (isInlineSchema) {
  11457. _mapType = _defineProperty({}, schema.options.typeKey, new Schema(obj.of));
  11458. } else if (utils.isPOJO(obj.of)) {
  11459. _mapType = Object.assign({}, obj.of);
  11460. } else {
  11461. _mapType = _defineProperty({}, schema.options.typeKey, obj.of);
  11462. }
  11463. if (_mapType[schema.options.typeKey] && _mapType[schema.options.typeKey].instanceOfSchema) {
  11464. var subdocumentSchema = _mapType[schema.options.typeKey];
  11465. subdocumentSchema.eachPath(function (subpath, type) {
  11466. if (type.options.select === true || type.options.select === false) {
  11467. throw new MongooseError('Cannot use schema-level projections (`select: true` or `select: false`) within maps at path "' + path + '.' + subpath + '"');
  11468. }
  11469. });
  11470. }
  11471. if (utils.hasUserDefinedProperty(obj, 'ref')) {
  11472. _mapType.ref = obj.ref;
  11473. }
  11474. }
  11475. schemaType.$__schemaType = schema.interpretAsType(mapPath, _mapType, options);
  11476. }
  11477. /**
  11478. * Iterates the schemas paths similar to Array#forEach.
  11479. *
  11480. * The callback is passed the pathname and the schemaType instance.
  11481. *
  11482. * #### Example:
  11483. *
  11484. * const userSchema = new Schema({ name: String, registeredAt: Date });
  11485. * userSchema.eachPath((pathname, schematype) => {
  11486. * // Prints twice:
  11487. * // name SchemaString { ... }
  11488. * // registeredAt SchemaDate { ... }
  11489. * console.log(pathname, schematype);
  11490. * });
  11491. *
  11492. * @param {Function} fn callback function
  11493. * @return {Schema} this
  11494. * @api public
  11495. */
  11496. Schema.prototype.eachPath = function (fn) {
  11497. var keys = Object.keys(this.paths);
  11498. var len = keys.length;
  11499. for (var i = 0; i < len; ++i) {
  11500. fn(keys[i], this.paths[keys[i]]);
  11501. }
  11502. return this;
  11503. };
  11504. /**
  11505. * Returns an Array of path strings that are required by this schema.
  11506. *
  11507. * #### Example:
  11508. * const s = new Schema({
  11509. * name: { type: String, required: true },
  11510. * age: { type: String, required: true },
  11511. * notes: String
  11512. * });
  11513. * s.requiredPaths(); // [ 'age', 'name' ]
  11514. *
  11515. * @api public
  11516. * @param {Boolean} invalidate refresh the cache
  11517. * @return {Array}
  11518. */
  11519. Schema.prototype.requiredPaths = function requiredPaths(invalidate) {
  11520. if (this._requiredpaths && !invalidate) {
  11521. return this._requiredpaths;
  11522. }
  11523. var paths = Object.keys(this.paths);
  11524. var i = paths.length;
  11525. var ret = [];
  11526. while (i--) {
  11527. var path = paths[i];
  11528. if (this.paths[path].isRequired) {
  11529. ret.push(path);
  11530. }
  11531. }
  11532. this._requiredpaths = ret;
  11533. return this._requiredpaths;
  11534. };
  11535. /**
  11536. * Returns indexes from fields and schema-level indexes (cached).
  11537. *
  11538. * @api private
  11539. * @return {Array}
  11540. */
  11541. Schema.prototype.indexedPaths = function indexedPaths() {
  11542. if (this._indexedpaths) {
  11543. return this._indexedpaths;
  11544. }
  11545. this._indexedpaths = this.indexes();
  11546. return this._indexedpaths;
  11547. };
  11548. /**
  11549. * Returns the pathType of `path` for this schema.
  11550. *
  11551. * Given a path, returns whether it is a real, virtual, nested, or ad-hoc/undefined path.
  11552. *
  11553. * #### Example:
  11554. * const s = new Schema({ name: String, nested: { foo: String } });
  11555. * s.virtual('foo').get(() => 42);
  11556. * s.pathType('name'); // "real"
  11557. * s.pathType('nested'); // "nested"
  11558. * s.pathType('foo'); // "virtual"
  11559. * s.pathType('fail'); // "adhocOrUndefined"
  11560. *
  11561. * @param {String} path
  11562. * @return {String}
  11563. * @api public
  11564. */
  11565. Schema.prototype.pathType = function (path) {
  11566. // Convert to '.$' to check subpaths re: gh-6405
  11567. var cleanPath = _pathToPositionalSyntax(path);
  11568. if (this.paths.hasOwnProperty(path)) {
  11569. return 'real';
  11570. }
  11571. if (this.virtuals.hasOwnProperty(path)) {
  11572. return 'virtual';
  11573. }
  11574. if (this.nested.hasOwnProperty(path)) {
  11575. return 'nested';
  11576. }
  11577. if (this.subpaths.hasOwnProperty(cleanPath) || this.subpaths.hasOwnProperty(path)) {
  11578. return 'real';
  11579. }
  11580. var singleNestedPath = this.singleNestedPaths.hasOwnProperty(cleanPath) || this.singleNestedPaths.hasOwnProperty(path);
  11581. if (singleNestedPath) {
  11582. return singleNestedPath === 'nested' ? 'nested' : 'real';
  11583. } // Look for maps
  11584. var mapPath = getMapPath(this, path);
  11585. if (mapPath != null) {
  11586. return 'real';
  11587. }
  11588. if (/\.\d+\.|\.\d+$/.test(path)) {
  11589. return getPositionalPathType(this, path);
  11590. }
  11591. return 'adhocOrUndefined';
  11592. };
  11593. /**
  11594. * Returns true iff this path is a child of a mixed schema.
  11595. *
  11596. * @param {String} path
  11597. * @return {Boolean}
  11598. * @api private
  11599. */
  11600. Schema.prototype.hasMixedParent = function (path) {
  11601. var subpaths = path.split(/\./g);
  11602. path = '';
  11603. for (var i = 0; i < subpaths.length; ++i) {
  11604. path = i > 0 ? path + '.' + subpaths[i] : subpaths[i];
  11605. if (this.paths.hasOwnProperty(path) && this.paths[path] instanceof MongooseTypes.Mixed) {
  11606. return this.paths[path];
  11607. }
  11608. }
  11609. return null;
  11610. };
  11611. /**
  11612. * Setup updatedAt and createdAt timestamps to documents if enabled
  11613. *
  11614. * @param {Boolean|Object} timestamps timestamps options
  11615. * @api private
  11616. */
  11617. Schema.prototype.setupTimestamp = function (timestamps) {
  11618. return setupTimestamps(this, timestamps);
  11619. };
  11620. /*!
  11621. * ignore. Deprecated re: #6405
  11622. */
  11623. function getPositionalPathType(self, path) {
  11624. var subpaths = path.split(/\.(\d+)\.|\.(\d+)$/).filter(Boolean);
  11625. if (subpaths.length < 2) {
  11626. return self.paths.hasOwnProperty(subpaths[0]) ? self.paths[subpaths[0]] : 'adhocOrUndefined';
  11627. }
  11628. var val = self.path(subpaths[0]);
  11629. var isNested = false;
  11630. if (!val) {
  11631. return 'adhocOrUndefined';
  11632. }
  11633. var last = subpaths.length - 1;
  11634. for (var i = 1; i < subpaths.length; ++i) {
  11635. isNested = false;
  11636. var subpath = subpaths[i];
  11637. if (i === last && val && !/\D/.test(subpath)) {
  11638. if (val.$isMongooseDocumentArray) {
  11639. val = val.$embeddedSchemaType;
  11640. } else if (val instanceof MongooseTypes.Array) {
  11641. // StringSchema, NumberSchema, etc
  11642. val = val.caster;
  11643. } else {
  11644. val = undefined;
  11645. }
  11646. break;
  11647. } // ignore if its just a position segment: path.0.subpath
  11648. if (!/\D/.test(subpath)) {
  11649. // Nested array
  11650. if (val instanceof MongooseTypes.Array && i !== last) {
  11651. val = val.caster;
  11652. }
  11653. continue;
  11654. }
  11655. if (!(val && val.schema)) {
  11656. val = undefined;
  11657. break;
  11658. }
  11659. var type = val.schema.pathType(subpath);
  11660. isNested = type === 'nested';
  11661. val = val.schema.path(subpath);
  11662. }
  11663. self.subpaths[path] = val;
  11664. if (val) {
  11665. return 'real';
  11666. }
  11667. if (isNested) {
  11668. return 'nested';
  11669. }
  11670. return 'adhocOrUndefined';
  11671. }
  11672. /*!
  11673. * ignore
  11674. */
  11675. function getPositionalPath(self, path) {
  11676. getPositionalPathType(self, path);
  11677. return self.subpaths[path];
  11678. }
  11679. /**
  11680. * Adds a method call to the queue.
  11681. *
  11682. * #### Example:
  11683. *
  11684. * schema.methods.print = function() { console.log(this); };
  11685. * schema.queue('print', []); // Print the doc every one is instantiated
  11686. *
  11687. * const Model = mongoose.model('Test', schema);
  11688. * new Model({ name: 'test' }); // Prints '{"_id": ..., "name": "test" }'
  11689. *
  11690. * @param {String} name name of the document method to call later
  11691. * @param {Array} args arguments to pass to the method
  11692. * @api public
  11693. */
  11694. Schema.prototype.queue = function (name, args) {
  11695. this.callQueue.push([name, args]);
  11696. return this;
  11697. };
  11698. /**
  11699. * Defines a pre hook for the model.
  11700. *
  11701. * #### Example
  11702. *
  11703. * const toySchema = new Schema({ name: String, created: Date });
  11704. *
  11705. * toySchema.pre('save', function(next) {
  11706. * if (!this.created) this.created = new Date;
  11707. * next();
  11708. * });
  11709. *
  11710. * toySchema.pre('validate', function(next) {
  11711. * if (this.name !== 'Woody') this.name = 'Woody';
  11712. * next();
  11713. * });
  11714. *
  11715. * // Equivalent to calling `pre()` on `find`, `findOne`, `findOneAndUpdate`.
  11716. * toySchema.pre(/^find/, function(next) {
  11717. * console.log(this.getFilter());
  11718. * });
  11719. *
  11720. * // Equivalent to calling `pre()` on `updateOne`, `findOneAndUpdate`.
  11721. * toySchema.pre(['updateOne', 'findOneAndUpdate'], function(next) {
  11722. * console.log(this.getFilter());
  11723. * });
  11724. *
  11725. * toySchema.pre('deleteOne', function() {
  11726. * // Runs when you call `Toy.deleteOne()`
  11727. * });
  11728. *
  11729. * toySchema.pre('deleteOne', { document: true }, function() {
  11730. * // Runs when you call `doc.deleteOne()`
  11731. * });
  11732. *
  11733. * @param {String|RegExp} The method name or regular expression to match method name
  11734. * @param {Object} [options]
  11735. * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware. For example, set `options.document` to `true` to apply this hook to `Document#deleteOne()` rather than `Query#deleteOne()`.
  11736. * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
  11737. * @param {Function} callback
  11738. * @api public
  11739. */
  11740. Schema.prototype.pre = function (name) {
  11741. if (name instanceof RegExp) {
  11742. var remainingArgs = Array.prototype.slice.call(arguments, 1);
  11743. var _iterator6 = _createForOfIteratorHelper(hookNames),
  11744. _step6;
  11745. try {
  11746. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  11747. var fn = _step6.value;
  11748. if (name.test(fn)) {
  11749. this.pre.apply(this, [fn].concat(remainingArgs));
  11750. }
  11751. }
  11752. } catch (err) {
  11753. _iterator6.e(err);
  11754. } finally {
  11755. _iterator6.f();
  11756. }
  11757. return this;
  11758. }
  11759. if (Array.isArray(name)) {
  11760. var _remainingArgs = Array.prototype.slice.call(arguments, 1);
  11761. var _iterator7 = _createForOfIteratorHelper(name),
  11762. _step7;
  11763. try {
  11764. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  11765. var el = _step7.value;
  11766. this.pre.apply(this, [el].concat(_remainingArgs));
  11767. }
  11768. } catch (err) {
  11769. _iterator7.e(err);
  11770. } finally {
  11771. _iterator7.f();
  11772. }
  11773. return this;
  11774. }
  11775. this.s.hooks.pre.apply(this.s.hooks, arguments);
  11776. return this;
  11777. };
  11778. /**
  11779. * Defines a post hook for the document
  11780. *
  11781. * const schema = new Schema(..);
  11782. * schema.post('save', function (doc) {
  11783. * console.log('this fired after a document was saved');
  11784. * });
  11785. *
  11786. * schema.post('find', function(docs) {
  11787. * console.log('this fired after you ran a find query');
  11788. * });
  11789. *
  11790. * schema.post(/Many$/, function(res) {
  11791. * console.log('this fired after you ran `updateMany()` or `deleteMany()`');
  11792. * });
  11793. *
  11794. * const Model = mongoose.model('Model', schema);
  11795. *
  11796. * const m = new Model(..);
  11797. * m.save(function(err) {
  11798. * console.log('this fires after the `post` hook');
  11799. * });
  11800. *
  11801. * m.find(function(err, docs) {
  11802. * console.log('this fires after the post find hook');
  11803. * });
  11804. *
  11805. * @param {String|RegExp} The method name or regular expression to match method name
  11806. * @param {Object} [options]
  11807. * @param {Boolean} [options.document] If `name` is a hook for both document and query middleware, set to `true` to run on document middleware.
  11808. * @param {Boolean} [options.query] If `name` is a hook for both document and query middleware, set to `true` to run on query middleware.
  11809. * @param {Function} fn callback
  11810. * @see middleware https://mongoosejs.com/docs/middleware.html
  11811. * @see kareem https://npmjs.org/package/kareem
  11812. * @api public
  11813. */
  11814. Schema.prototype.post = function (name) {
  11815. if (name instanceof RegExp) {
  11816. var remainingArgs = Array.prototype.slice.call(arguments, 1);
  11817. var _iterator8 = _createForOfIteratorHelper(hookNames),
  11818. _step8;
  11819. try {
  11820. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  11821. var fn = _step8.value;
  11822. if (name.test(fn)) {
  11823. this.post.apply(this, [fn].concat(remainingArgs));
  11824. }
  11825. }
  11826. } catch (err) {
  11827. _iterator8.e(err);
  11828. } finally {
  11829. _iterator8.f();
  11830. }
  11831. return this;
  11832. }
  11833. if (Array.isArray(name)) {
  11834. var _remainingArgs2 = Array.prototype.slice.call(arguments, 1);
  11835. var _iterator9 = _createForOfIteratorHelper(name),
  11836. _step9;
  11837. try {
  11838. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  11839. var el = _step9.value;
  11840. this.post.apply(this, [el].concat(_remainingArgs2));
  11841. }
  11842. } catch (err) {
  11843. _iterator9.e(err);
  11844. } finally {
  11845. _iterator9.f();
  11846. }
  11847. return this;
  11848. }
  11849. this.s.hooks.post.apply(this.s.hooks, arguments);
  11850. return this;
  11851. };
  11852. /**
  11853. * Registers a plugin for this schema.
  11854. *
  11855. * #### Example:
  11856. *
  11857. * const s = new Schema({ name: String });
  11858. * s.plugin(schema => console.log(schema.path('name').path));
  11859. * mongoose.model('Test', s); // Prints 'name'
  11860. *
  11861. * @param {Function} plugin callback
  11862. * @param {Object} [opts]
  11863. * @see plugins
  11864. * @api public
  11865. */
  11866. Schema.prototype.plugin = function (fn, opts) {
  11867. if (typeof fn !== 'function') {
  11868. throw new Error('First param to `schema.plugin()` must be a function, ' + 'got "' + _typeof(fn) + '"');
  11869. }
  11870. if (opts && opts.deduplicate) {
  11871. var _iterator10 = _createForOfIteratorHelper(this.plugins),
  11872. _step10;
  11873. try {
  11874. for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
  11875. var plugin = _step10.value;
  11876. if (plugin.fn === fn) {
  11877. return this;
  11878. }
  11879. }
  11880. } catch (err) {
  11881. _iterator10.e(err);
  11882. } finally {
  11883. _iterator10.f();
  11884. }
  11885. }
  11886. this.plugins.push({
  11887. fn: fn,
  11888. opts: opts
  11889. });
  11890. fn(this, opts);
  11891. return this;
  11892. };
  11893. /**
  11894. * Adds an instance method to documents constructed from Models compiled from this schema.
  11895. *
  11896. * #### Example
  11897. *
  11898. * const schema = kittySchema = new Schema(..);
  11899. *
  11900. * schema.method('meow', function () {
  11901. * console.log('meeeeeoooooooooooow');
  11902. * })
  11903. *
  11904. * const Kitty = mongoose.model('Kitty', schema);
  11905. *
  11906. * const fizz = new Kitty;
  11907. * fizz.meow(); // meeeeeooooooooooooow
  11908. *
  11909. * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as methods.
  11910. *
  11911. * schema.method({
  11912. * purr: function () {}
  11913. * , scratch: function () {}
  11914. * });
  11915. *
  11916. * // later
  11917. * fizz.purr();
  11918. * fizz.scratch();
  11919. *
  11920. * NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](/docs/guide.html#methods)
  11921. *
  11922. * @param {String|Object} method name
  11923. * @param {Function} [fn]
  11924. * @api public
  11925. */
  11926. Schema.prototype.method = function (name, fn, options) {
  11927. if (typeof name !== 'string') {
  11928. for (var i in name) {
  11929. this.methods[i] = name[i];
  11930. this.methodOptions[i] = utils.clone(options);
  11931. }
  11932. } else {
  11933. this.methods[name] = fn;
  11934. this.methodOptions[name] = utils.clone(options);
  11935. }
  11936. return this;
  11937. };
  11938. /**
  11939. * Adds static "class" methods to Models compiled from this schema.
  11940. *
  11941. * #### Example
  11942. *
  11943. * const schema = new Schema(..);
  11944. * // Equivalent to `schema.statics.findByName = function(name) {}`;
  11945. * schema.static('findByName', function(name) {
  11946. * return this.find({ name: name });
  11947. * });
  11948. *
  11949. * const Drink = mongoose.model('Drink', schema);
  11950. * await Drink.findByName('LaCroix');
  11951. *
  11952. * If a hash of name/fn pairs is passed as the only argument, each name/fn pair will be added as statics.
  11953. *
  11954. * @param {String|Object} name
  11955. * @param {Function} [fn]
  11956. * @api public
  11957. * @see Statics /docs/guide.html#statics
  11958. */
  11959. Schema.prototype["static"] = function (name, fn) {
  11960. if (typeof name !== 'string') {
  11961. for (var i in name) {
  11962. this.statics[i] = name[i];
  11963. }
  11964. } else {
  11965. this.statics[name] = fn;
  11966. }
  11967. return this;
  11968. };
  11969. /**
  11970. * Defines an index (most likely compound) for this schema.
  11971. *
  11972. * #### Example
  11973. *
  11974. * schema.index({ first: 1, last: -1 })
  11975. *
  11976. * @param {Object} fields
  11977. * @param {Object} [options] Options to pass to [MongoDB driver's `createIndex()` function](https://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#createIndex)
  11978. * @param {String | number} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
  11979. * @api public
  11980. */
  11981. Schema.prototype.index = function (fields, options) {
  11982. fields || (fields = {});
  11983. options || (options = {});
  11984. if (options.expires) {
  11985. utils.expires(options);
  11986. }
  11987. this._indexes.push([fields, options]);
  11988. return this;
  11989. };
  11990. /**
  11991. * Sets a schema option.
  11992. *
  11993. * #### Example
  11994. *
  11995. * schema.set('strict'); // 'true' by default
  11996. * schema.set('strict', false); // Sets 'strict' to false
  11997. * schema.set('strict'); // 'false'
  11998. *
  11999. * @param {String} key option name
  12000. * @param {Object} [value] if not passed, the current option value is returned
  12001. * @see Schema ./
  12002. * @api public
  12003. */
  12004. Schema.prototype.set = function (key, value, _tags) {
  12005. if (arguments.length === 1) {
  12006. return this.options[key];
  12007. }
  12008. switch (key) {
  12009. case 'read':
  12010. this.options[key] = readPref(value, _tags);
  12011. this._userProvidedOptions[key] = this.options[key];
  12012. break;
  12013. case 'timestamps':
  12014. this.setupTimestamp(value);
  12015. this.options[key] = value;
  12016. this._userProvidedOptions[key] = this.options[key];
  12017. break;
  12018. case '_id':
  12019. this.options[key] = value;
  12020. this._userProvidedOptions[key] = this.options[key];
  12021. if (value && !this.paths['_id']) {
  12022. addAutoId(this);
  12023. } else if (!value && this.paths['_id'] != null && this.paths['_id'].auto) {
  12024. this.remove('_id');
  12025. }
  12026. break;
  12027. default:
  12028. this.options[key] = value;
  12029. this._userProvidedOptions[key] = this.options[key];
  12030. break;
  12031. }
  12032. return this;
  12033. };
  12034. /**
  12035. * Gets a schema option.
  12036. *
  12037. * #### Example:
  12038. *
  12039. * schema.get('strict'); // true
  12040. * schema.set('strict', false);
  12041. * schema.get('strict'); // false
  12042. *
  12043. * @param {String} key option name
  12044. * @api public
  12045. * @return {Any} the option's value
  12046. */
  12047. Schema.prototype.get = function (key) {
  12048. return this.options[key];
  12049. };
  12050. /**
  12051. * The allowed index types
  12052. *
  12053. * @receiver Schema
  12054. * @static indexTypes
  12055. * @api public
  12056. */
  12057. var indexTypes = '2d 2dsphere hashed text'.split(' ');
  12058. Object.defineProperty(Schema, 'indexTypes', {
  12059. get: function get() {
  12060. return indexTypes;
  12061. },
  12062. set: function set() {
  12063. throw new Error('Cannot overwrite Schema.indexTypes');
  12064. }
  12065. });
  12066. /**
  12067. * Returns a list of indexes that this schema declares, via `schema.index()` or by `index: true` in a path's options.
  12068. * Indexes are expressed as an array `[spec, options]`.
  12069. *
  12070. * #### Example:
  12071. *
  12072. * const userSchema = new Schema({
  12073. * email: { type: String, required: true, unique: true },
  12074. * registeredAt: { type: Date, index: true }
  12075. * });
  12076. *
  12077. * // [ [ { email: 1 }, { unique: true, background: true } ],
  12078. * // [ { registeredAt: 1 }, { background: true } ] ]
  12079. * userSchema.indexes();
  12080. *
  12081. * [Plugins](/docs/plugins.html) can use the return value of this function to modify a schema's indexes.
  12082. * For example, the below plugin makes every index unique by default.
  12083. *
  12084. * function myPlugin(schema) {
  12085. * for (const index of schema.indexes()) {
  12086. * if (index[1].unique === undefined) {
  12087. * index[1].unique = true;
  12088. * }
  12089. * }
  12090. * }
  12091. *
  12092. * @api public
  12093. * @return {Array} list of indexes defined in the schema
  12094. */
  12095. Schema.prototype.indexes = function () {
  12096. return getIndexes(this);
  12097. };
  12098. /**
  12099. * Creates a virtual type with the given name.
  12100. *
  12101. * @param {String} name
  12102. * @param {Object} [options]
  12103. * @param {String|Model} [options.ref] model name or model instance. Marks this as a [populate virtual](/docs/populate.html#populate-virtuals).
  12104. * @param {String|Function} [options.localField] Required for populate virtuals. See [populate virtual docs](/docs/populate.html#populate-virtuals) for more information.
  12105. * @param {String|Function} [options.foreignField] Required for populate virtuals. See [populate virtual docs](/docs/populate.html#populate-virtuals) for more information.
  12106. * @param {Boolean|Function} [options.justOne=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), will be a single doc or `null`. Otherwise, the populate virtual will be an array.
  12107. * @param {Boolean} [options.count=false] Only works with populate virtuals. If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), this populate virtual will contain the number of documents rather than the documents themselves when you `populate()`.
  12108. * @param {Function|null} [options.get=null] Adds a [getter](/docs/tutorials/getters-setters.html) to this virtual to transform the populated doc.
  12109. * @return {VirtualType}
  12110. */
  12111. Schema.prototype.virtual = function (name, options) {
  12112. if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') {
  12113. return this.virtual(name.path, name.options);
  12114. }
  12115. options = new VirtualOptions(options);
  12116. if (utils.hasUserDefinedProperty(options, ['ref', 'refPath'])) {
  12117. if (options.localField == null) {
  12118. throw new Error('Reference virtuals require `localField` option');
  12119. }
  12120. if (options.foreignField == null) {
  12121. throw new Error('Reference virtuals require `foreignField` option');
  12122. }
  12123. this.pre('init', function (obj) {
  12124. if (mpath.has(name, obj)) {
  12125. var _v = mpath.get(name, obj);
  12126. if (!this.$$populatedVirtuals) {
  12127. this.$$populatedVirtuals = {};
  12128. }
  12129. if (options.justOne || options.count) {
  12130. this.$$populatedVirtuals[name] = Array.isArray(_v) ? _v[0] : _v;
  12131. } else {
  12132. this.$$populatedVirtuals[name] = Array.isArray(_v) ? _v : _v == null ? [] : [_v];
  12133. }
  12134. mpath.unset(name, obj);
  12135. }
  12136. });
  12137. var virtual = this.virtual(name);
  12138. virtual.options = options;
  12139. virtual.set(function (_v) {
  12140. if (!this.$$populatedVirtuals) {
  12141. this.$$populatedVirtuals = {};
  12142. }
  12143. if (options.justOne || options.count) {
  12144. this.$$populatedVirtuals[name] = Array.isArray(_v) ? _v[0] : _v;
  12145. if (_typeof(this.$$populatedVirtuals[name]) !== 'object') {
  12146. this.$$populatedVirtuals[name] = options.count ? _v : null;
  12147. }
  12148. } else {
  12149. this.$$populatedVirtuals[name] = Array.isArray(_v) ? _v : _v == null ? [] : [_v];
  12150. this.$$populatedVirtuals[name] = this.$$populatedVirtuals[name].filter(function (doc) {
  12151. return doc && _typeof(doc) === 'object';
  12152. });
  12153. }
  12154. });
  12155. if (typeof options.get === 'function') {
  12156. virtual.get(options.get);
  12157. } // Workaround for gh-8198: if virtual is under document array, make a fake
  12158. // virtual. See gh-8210
  12159. var _parts = name.split('.');
  12160. var cur = _parts[0];
  12161. for (var i = 0; i < _parts.length - 1; ++i) {
  12162. if (this.paths[cur] != null && this.paths[cur].$isMongooseDocumentArray) {
  12163. var remnant = _parts.slice(i + 1).join('.');
  12164. this.paths[cur].schema.virtual(remnant, options);
  12165. break;
  12166. }
  12167. cur += '.' + _parts[i + 1];
  12168. }
  12169. return virtual;
  12170. }
  12171. var virtuals = this.virtuals;
  12172. var parts = name.split('.');
  12173. if (this.pathType(name) === 'real') {
  12174. throw new Error('Virtual path "' + name + '"' + ' conflicts with a real path in the schema');
  12175. }
  12176. virtuals[name] = parts.reduce(function (mem, part, i) {
  12177. mem[part] || (mem[part] = i === parts.length - 1 ? new VirtualType(options, name) : {});
  12178. return mem[part];
  12179. }, this.tree);
  12180. return virtuals[name];
  12181. };
  12182. /**
  12183. * Returns the virtual type with the given `name`.
  12184. *
  12185. * @param {String} name
  12186. * @return {VirtualType}
  12187. */
  12188. Schema.prototype.virtualpath = function (name) {
  12189. return this.virtuals.hasOwnProperty(name) ? this.virtuals[name] : null;
  12190. };
  12191. /**
  12192. * Removes the given `path` (or [`paths`]).
  12193. *
  12194. * #### Example:
  12195. *
  12196. * const schema = new Schema({ name: String, age: Number });
  12197. * schema.remove('name');
  12198. * schema.path('name'); // Undefined
  12199. * schema.path('age'); // SchemaNumber { ... }
  12200. *
  12201. * @param {String|Array} path
  12202. * @return {Schema} the Schema instance
  12203. * @api public
  12204. */
  12205. Schema.prototype.remove = function (path) {
  12206. if (typeof path === 'string') {
  12207. path = [path];
  12208. }
  12209. if (Array.isArray(path)) {
  12210. path.forEach(function (name) {
  12211. if (this.path(name) == null && !this.nested[name]) {
  12212. return;
  12213. }
  12214. if (this.nested[name]) {
  12215. var allKeys = Object.keys(this.paths).concat(Object.keys(this.nested));
  12216. var _iterator11 = _createForOfIteratorHelper(allKeys),
  12217. _step11;
  12218. try {
  12219. for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
  12220. var _path2 = _step11.value;
  12221. if (_path2.startsWith(name + '.')) {
  12222. delete this.paths[_path2];
  12223. delete this.nested[_path2];
  12224. _deletePath(this, _path2);
  12225. }
  12226. }
  12227. } catch (err) {
  12228. _iterator11.e(err);
  12229. } finally {
  12230. _iterator11.f();
  12231. }
  12232. delete this.nested[name];
  12233. _deletePath(this, name);
  12234. return;
  12235. }
  12236. delete this.paths[name];
  12237. _deletePath(this, name);
  12238. }, this);
  12239. }
  12240. return this;
  12241. };
  12242. /*!
  12243. * ignore
  12244. */
  12245. function _deletePath(schema, name) {
  12246. var pieces = name.split('.');
  12247. var last = pieces.pop();
  12248. var branch = schema.tree;
  12249. var _iterator12 = _createForOfIteratorHelper(pieces),
  12250. _step12;
  12251. try {
  12252. for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
  12253. var piece = _step12.value;
  12254. branch = branch[piece];
  12255. }
  12256. } catch (err) {
  12257. _iterator12.e(err);
  12258. } finally {
  12259. _iterator12.f();
  12260. }
  12261. delete branch[last];
  12262. }
  12263. /**
  12264. * Loads an ES6 class into a schema. Maps [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) + [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get), [static methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static),
  12265. * and [instance methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Class_body_and_method_definitions)
  12266. * to schema [virtuals](/docs/guide.html#virtuals),
  12267. * [statics](/docs/guide.html#statics), and
  12268. * [methods](/docs/guide.html#methods).
  12269. *
  12270. * #### Example:
  12271. *
  12272. * ```javascript
  12273. * const md5 = require('md5');
  12274. * const userSchema = new Schema({ email: String });
  12275. * class UserClass {
  12276. * // `gravatarImage` becomes a virtual
  12277. * get gravatarImage() {
  12278. * const hash = md5(this.email.toLowerCase());
  12279. * return `https://www.gravatar.com/avatar/${hash}`;
  12280. * }
  12281. *
  12282. * // `getProfileUrl()` becomes a document method
  12283. * getProfileUrl() {
  12284. * return `https://mysite.com/${this.email}`;
  12285. * }
  12286. *
  12287. * // `findByEmail()` becomes a static
  12288. * static findByEmail(email) {
  12289. * return this.findOne({ email });
  12290. * }
  12291. * }
  12292. *
  12293. * // `schema` will now have a `gravatarImage` virtual, a `getProfileUrl()` method,
  12294. * // and a `findByEmail()` static
  12295. * userSchema.loadClass(UserClass);
  12296. * ```
  12297. *
  12298. * @param {Function} model
  12299. * @param {Boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
  12300. */
  12301. Schema.prototype.loadClass = function (model, virtualsOnly) {
  12302. if (model === Object.prototype || model === Function.prototype || model.prototype.hasOwnProperty('$isMongooseModelPrototype')) {
  12303. return this;
  12304. }
  12305. this.loadClass(Object.getPrototypeOf(model), virtualsOnly); // Add static methods
  12306. if (!virtualsOnly) {
  12307. Object.getOwnPropertyNames(model).forEach(function (name) {
  12308. if (name.match(/^(length|name|prototype|constructor|__proto__)$/)) {
  12309. return;
  12310. }
  12311. var prop = Object.getOwnPropertyDescriptor(model, name);
  12312. if (prop.hasOwnProperty('value')) {
  12313. this["static"](name, prop.value);
  12314. }
  12315. }, this);
  12316. } // Add methods and virtuals
  12317. Object.getOwnPropertyNames(model.prototype).forEach(function (name) {
  12318. if (name.match(/^(constructor)$/)) {
  12319. return;
  12320. }
  12321. var method = Object.getOwnPropertyDescriptor(model.prototype, name);
  12322. if (!virtualsOnly) {
  12323. if (typeof method.value === 'function') {
  12324. this.method(name, method.value);
  12325. }
  12326. }
  12327. if (typeof method.get === 'function') {
  12328. if (this.virtuals[name]) {
  12329. this.virtuals[name].getters = [];
  12330. }
  12331. this.virtual(name).get(method.get);
  12332. }
  12333. if (typeof method.set === 'function') {
  12334. if (this.virtuals[name]) {
  12335. this.virtuals[name].setters = [];
  12336. }
  12337. this.virtual(name).set(method.set);
  12338. }
  12339. }, this);
  12340. return this;
  12341. };
  12342. /*!
  12343. * ignore
  12344. */
  12345. Schema.prototype._getSchema = function (path) {
  12346. var _this = this;
  12347. var pathschema = _this.path(path);
  12348. var resultPath = [];
  12349. if (pathschema) {
  12350. pathschema.$fullPath = path;
  12351. return pathschema;
  12352. }
  12353. function search(parts, schema) {
  12354. var p = parts.length + 1;
  12355. var foundschema;
  12356. var trypath;
  12357. while (p--) {
  12358. trypath = parts.slice(0, p).join('.');
  12359. foundschema = schema.path(trypath);
  12360. if (foundschema) {
  12361. resultPath.push(trypath);
  12362. if (foundschema.caster) {
  12363. // array of Mixed?
  12364. if (foundschema.caster instanceof MongooseTypes.Mixed) {
  12365. foundschema.caster.$fullPath = resultPath.join('.');
  12366. return foundschema.caster;
  12367. } // Now that we found the array, we need to check if there
  12368. // are remaining document paths to look up for casting.
  12369. // Also we need to handle array.$.path since schema.path
  12370. // doesn't work for that.
  12371. // If there is no foundschema.schema we are dealing with
  12372. // a path like array.$
  12373. if (p !== parts.length) {
  12374. if (foundschema.schema) {
  12375. var ret = void 0;
  12376. if (parts[p] === '$' || isArrayFilter(parts[p])) {
  12377. if (p + 1 === parts.length) {
  12378. // comments.$
  12379. return foundschema;
  12380. } // comments.$.comments.$.title
  12381. ret = search(parts.slice(p + 1), foundschema.schema);
  12382. if (ret) {
  12383. ret.$isUnderneathDocArray = ret.$isUnderneathDocArray || !foundschema.schema.$isSingleNested;
  12384. }
  12385. return ret;
  12386. } // this is the last path of the selector
  12387. ret = search(parts.slice(p), foundschema.schema);
  12388. if (ret) {
  12389. ret.$isUnderneathDocArray = ret.$isUnderneathDocArray || !foundschema.schema.$isSingleNested;
  12390. }
  12391. return ret;
  12392. }
  12393. }
  12394. } else if (foundschema.$isSchemaMap) {
  12395. if (p >= parts.length) {
  12396. return foundschema;
  12397. } // Any path in the map will be an instance of the map's embedded schematype
  12398. if (p + 1 >= parts.length) {
  12399. return foundschema.$__schemaType;
  12400. }
  12401. var _ret = search(parts.slice(p + 1), foundschema.$__schemaType.schema);
  12402. return _ret;
  12403. }
  12404. foundschema.$fullPath = resultPath.join('.');
  12405. return foundschema;
  12406. }
  12407. }
  12408. } // look for arrays
  12409. var parts = path.split('.');
  12410. for (var i = 0; i < parts.length; ++i) {
  12411. if (parts[i] === '$' || isArrayFilter(parts[i])) {
  12412. // Re: gh-5628, because `schema.path()` doesn't take $ into account.
  12413. parts[i] = '0';
  12414. }
  12415. }
  12416. return search(parts, _this);
  12417. };
  12418. /*!
  12419. * ignore
  12420. */
  12421. Schema.prototype._getPathType = function (path) {
  12422. var _this = this;
  12423. var pathschema = _this.path(path);
  12424. if (pathschema) {
  12425. return 'real';
  12426. }
  12427. function search(parts, schema) {
  12428. var p = parts.length + 1,
  12429. foundschema,
  12430. trypath;
  12431. while (p--) {
  12432. trypath = parts.slice(0, p).join('.');
  12433. foundschema = schema.path(trypath);
  12434. if (foundschema) {
  12435. if (foundschema.caster) {
  12436. // array of Mixed?
  12437. if (foundschema.caster instanceof MongooseTypes.Mixed) {
  12438. return {
  12439. schema: foundschema,
  12440. pathType: 'mixed'
  12441. };
  12442. } // Now that we found the array, we need to check if there
  12443. // are remaining document paths to look up for casting.
  12444. // Also we need to handle array.$.path since schema.path
  12445. // doesn't work for that.
  12446. // If there is no foundschema.schema we are dealing with
  12447. // a path like array.$
  12448. if (p !== parts.length && foundschema.schema) {
  12449. if (parts[p] === '$' || isArrayFilter(parts[p])) {
  12450. if (p === parts.length - 1) {
  12451. return {
  12452. schema: foundschema,
  12453. pathType: 'nested'
  12454. };
  12455. } // comments.$.comments.$.title
  12456. return search(parts.slice(p + 1), foundschema.schema);
  12457. } // this is the last path of the selector
  12458. return search(parts.slice(p), foundschema.schema);
  12459. }
  12460. return {
  12461. schema: foundschema,
  12462. pathType: foundschema.$isSingleNested ? 'nested' : 'array'
  12463. };
  12464. }
  12465. return {
  12466. schema: foundschema,
  12467. pathType: 'real'
  12468. };
  12469. } else if (p === parts.length && schema.nested[trypath]) {
  12470. return {
  12471. schema: schema,
  12472. pathType: 'nested'
  12473. };
  12474. }
  12475. }
  12476. return {
  12477. schema: foundschema || schema,
  12478. pathType: 'undefined'
  12479. };
  12480. } // look for arrays
  12481. return search(path.split('.'), _this);
  12482. };
  12483. /*!
  12484. * ignore
  12485. */
  12486. function isArrayFilter(piece) {
  12487. return piece.startsWith('$[') && piece.endsWith(']');
  12488. }
  12489. /*!
  12490. * Called by `compile()` _right before_ compiling. Good for making any changes to
  12491. * the schema that should respect options set by plugins, like `id`
  12492. */
  12493. Schema.prototype._preCompile = function _preCompile() {
  12494. idGetter(this);
  12495. };
  12496. /*!
  12497. * Module exports.
  12498. */
  12499. module.exports = exports = Schema; // require down here because of reference issues
  12500. /**
  12501. * The various built-in Mongoose Schema Types.
  12502. *
  12503. * #### Example:
  12504. *
  12505. * const mongoose = require('mongoose');
  12506. * const ObjectId = mongoose.Schema.Types.ObjectId;
  12507. *
  12508. * #### Types:
  12509. *
  12510. * - [String](/docs/schematypes.html#strings)
  12511. * - [Number](/docs/schematypes.html#numbers)
  12512. * - [Boolean](/docs/schematypes.html#booleans) | Bool
  12513. * - [Array](/docs/schematypes.html#arrays)
  12514. * - [Buffer](/docs/schematypes.html#buffers)
  12515. * - [Date](/docs/schematypes.html#dates)
  12516. * - [ObjectId](/docs/schematypes.html#objectids) | Oid
  12517. * - [Mixed](/docs/schematypes.html#mixed)
  12518. *
  12519. * Using this exposed access to the `Mixed` SchemaType, we can use them in our schema.
  12520. *
  12521. * const Mixed = mongoose.Schema.Types.Mixed;
  12522. * new mongoose.Schema({ _user: Mixed })
  12523. *
  12524. * @api public
  12525. */
  12526. Schema.Types = MongooseTypes = __webpack_require__(5251);
  12527. /*!
  12528. * ignore
  12529. */
  12530. exports.ObjectId = MongooseTypes.ObjectId;
  12531. /***/ }),
  12532. /***/ 3617:
  12533. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  12534. "use strict";
  12535. /*!
  12536. * Module dependencies.
  12537. */
  12538. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  12539. var CastError = __webpack_require__(1795);
  12540. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  12541. var ObjectExpectedError = __webpack_require__(4107);
  12542. var SchemaSubdocumentOptions = __webpack_require__(5446);
  12543. var SchemaType = __webpack_require__(4289);
  12544. var $exists = __webpack_require__(8702);
  12545. var castToNumber = (__webpack_require__(1521)/* .castToNumber */ .W);
  12546. var discriminator = __webpack_require__(9181);
  12547. var geospatial = __webpack_require__(5008);
  12548. var getConstructor = __webpack_require__(8413);
  12549. var handleIdOption = __webpack_require__(9691);
  12550. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  12551. var utils = __webpack_require__(6872);
  12552. var Subdocument;
  12553. module.exports = SubdocumentPath;
  12554. /**
  12555. * Single nested subdocument SchemaType constructor.
  12556. *
  12557. * @param {Schema} schema
  12558. * @param {String} path
  12559. * @param {Object} options
  12560. * @inherits SchemaType
  12561. * @api public
  12562. */
  12563. function SubdocumentPath(schema, path, options) {
  12564. var schemaTypeIdOption = SubdocumentPath.defaultOptions && SubdocumentPath.defaultOptions._id;
  12565. if (schemaTypeIdOption != null) {
  12566. options = options || {};
  12567. options._id = schemaTypeIdOption;
  12568. }
  12569. schema = handleIdOption(schema, options);
  12570. this.caster = _createConstructor(schema);
  12571. this.caster.path = path;
  12572. this.caster.prototype.$basePath = path;
  12573. this.schema = schema;
  12574. this.$isSingleNested = true;
  12575. SchemaType.call(this, path, options, 'Embedded');
  12576. }
  12577. /*!
  12578. * ignore
  12579. */
  12580. SubdocumentPath.prototype = Object.create(SchemaType.prototype);
  12581. SubdocumentPath.prototype.constructor = SubdocumentPath;
  12582. SubdocumentPath.prototype.OptionsConstructor = SchemaSubdocumentOptions;
  12583. /*!
  12584. * ignore
  12585. */
  12586. function _createConstructor(schema, baseClass) {
  12587. // lazy load
  12588. Subdocument || (Subdocument = __webpack_require__(2591));
  12589. var _embedded = function SingleNested(value, path, parent) {
  12590. this.$__parent = parent;
  12591. Subdocument.apply(this, arguments);
  12592. if (parent == null) {
  12593. return;
  12594. }
  12595. this.$session(parent.$session());
  12596. };
  12597. schema._preCompile();
  12598. var proto = baseClass != null ? baseClass.prototype : Subdocument.prototype;
  12599. _embedded.prototype = Object.create(proto);
  12600. _embedded.prototype.$__setSchema(schema);
  12601. _embedded.prototype.constructor = _embedded;
  12602. _embedded.schema = schema;
  12603. _embedded.$isSingleNested = true;
  12604. _embedded.events = new EventEmitter();
  12605. _embedded.prototype.toBSON = function () {
  12606. return this.toObject(internalToObjectOptions);
  12607. }; // apply methods
  12608. for (var i in schema.methods) {
  12609. _embedded.prototype[i] = schema.methods[i];
  12610. } // apply statics
  12611. for (var _i in schema.statics) {
  12612. _embedded[_i] = schema.statics[_i];
  12613. }
  12614. for (var _i2 in EventEmitter.prototype) {
  12615. _embedded[_i2] = EventEmitter.prototype[_i2];
  12616. }
  12617. return _embedded;
  12618. }
  12619. /*!
  12620. * Special case for when users use a common location schema to represent
  12621. * locations for use with $geoWithin.
  12622. * https://docs.mongodb.org/manual/reference/operator/query/geoWithin/
  12623. *
  12624. * @param {Object} val
  12625. * @api private
  12626. */
  12627. SubdocumentPath.prototype.$conditionalHandlers.$geoWithin = function handle$geoWithin(val) {
  12628. return {
  12629. $geometry: this.castForQuery(val.$geometry)
  12630. };
  12631. };
  12632. /*!
  12633. * ignore
  12634. */
  12635. SubdocumentPath.prototype.$conditionalHandlers.$near = SubdocumentPath.prototype.$conditionalHandlers.$nearSphere = geospatial.cast$near;
  12636. SubdocumentPath.prototype.$conditionalHandlers.$within = SubdocumentPath.prototype.$conditionalHandlers.$geoWithin = geospatial.cast$within;
  12637. SubdocumentPath.prototype.$conditionalHandlers.$geoIntersects = geospatial.cast$geoIntersects;
  12638. SubdocumentPath.prototype.$conditionalHandlers.$minDistance = castToNumber;
  12639. SubdocumentPath.prototype.$conditionalHandlers.$maxDistance = castToNumber;
  12640. SubdocumentPath.prototype.$conditionalHandlers.$exists = $exists;
  12641. /**
  12642. * Casts contents
  12643. *
  12644. * @param {Object} value
  12645. * @api private
  12646. */
  12647. SubdocumentPath.prototype.cast = function (val, doc, init, priorVal, options) {
  12648. if (val && val.$isSingleNested && val.parent === doc) {
  12649. return val;
  12650. }
  12651. if (val != null && (_typeof(val) !== 'object' || Array.isArray(val))) {
  12652. throw new ObjectExpectedError(this.path, val);
  12653. }
  12654. var Constructor = getConstructor(this.caster, val);
  12655. var subdoc; // Only pull relevant selected paths and pull out the base path
  12656. var parentSelected = doc && doc.$__ && doc.$__.selected || {};
  12657. var path = this.path;
  12658. var selected = Object.keys(parentSelected).reduce(function (obj, key) {
  12659. if (key.startsWith(path + '.')) {
  12660. obj = obj || {};
  12661. obj[key.substring(path.length + 1)] = parentSelected[key];
  12662. }
  12663. return obj;
  12664. }, null);
  12665. options = Object.assign({}, options, {
  12666. priorDoc: priorVal
  12667. });
  12668. if (init) {
  12669. subdoc = new Constructor(void 0, selected, doc);
  12670. subdoc.$init(val);
  12671. } else {
  12672. if (Object.keys(val).length === 0) {
  12673. return new Constructor({}, selected, doc, undefined, options);
  12674. }
  12675. return new Constructor(val, selected, doc, undefined, options);
  12676. }
  12677. return subdoc;
  12678. };
  12679. /**
  12680. * Casts contents for query
  12681. *
  12682. * @param {string} [$conditional] optional query operator (like `$eq` or `$in`)
  12683. * @param {any} value
  12684. * @api private
  12685. */
  12686. SubdocumentPath.prototype.castForQuery = function ($conditional, val, options) {
  12687. var handler;
  12688. if (arguments.length === 2) {
  12689. handler = this.$conditionalHandlers[$conditional];
  12690. if (!handler) {
  12691. throw new Error('Can\'t use ' + $conditional);
  12692. }
  12693. return handler.call(this, val);
  12694. }
  12695. val = $conditional;
  12696. if (val == null) {
  12697. return val;
  12698. }
  12699. if (this.options.runSetters) {
  12700. val = this._applySetters(val);
  12701. }
  12702. var Constructor = getConstructor(this.caster, val);
  12703. var overrideStrict = options != null && options.strict != null ? options.strict : void 0;
  12704. try {
  12705. val = new Constructor(val, overrideStrict);
  12706. } catch (error) {
  12707. // Make sure we always wrap in a CastError (gh-6803)
  12708. if (!(error instanceof CastError)) {
  12709. throw new CastError('Embedded', val, this.path, error, this);
  12710. }
  12711. throw error;
  12712. }
  12713. return val;
  12714. };
  12715. /**
  12716. * Async validation on this single nested doc.
  12717. *
  12718. * @api private
  12719. */
  12720. SubdocumentPath.prototype.doValidate = function (value, fn, scope, options) {
  12721. var Constructor = getConstructor(this.caster, value);
  12722. if (value && !(value instanceof Constructor)) {
  12723. value = new Constructor(value, null, scope != null && scope.$__ != null ? scope : null);
  12724. }
  12725. if (options && options.skipSchemaValidators) {
  12726. if (!value) {
  12727. return fn(null);
  12728. }
  12729. return value.validate(fn);
  12730. }
  12731. SchemaType.prototype.doValidate.call(this, value, function (error) {
  12732. if (error) {
  12733. return fn(error);
  12734. }
  12735. if (!value) {
  12736. return fn(null);
  12737. }
  12738. value.validate(fn);
  12739. }, scope, options);
  12740. };
  12741. /**
  12742. * Synchronously validate this single nested doc
  12743. *
  12744. * @api private
  12745. */
  12746. SubdocumentPath.prototype.doValidateSync = function (value, scope, options) {
  12747. if (!options || !options.skipSchemaValidators) {
  12748. var schemaTypeError = SchemaType.prototype.doValidateSync.call(this, value, scope);
  12749. if (schemaTypeError) {
  12750. return schemaTypeError;
  12751. }
  12752. }
  12753. if (!value) {
  12754. return;
  12755. }
  12756. return value.validateSync();
  12757. };
  12758. /**
  12759. * Adds a discriminator to this single nested subdocument.
  12760. *
  12761. * #### Example:
  12762. * const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
  12763. * const schema = Schema({ shape: shapeSchema });
  12764. *
  12765. * const singleNestedPath = parentSchema.path('shape');
  12766. * singleNestedPath.discriminator('Circle', Schema({ radius: Number }));
  12767. *
  12768. * @param {String} name
  12769. * @param {Schema} schema fields to add to the schema for instances of this sub-class
  12770. * @param {Object|string} [options] If string, same as `options.value`.
  12771. * @param {String} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
  12772. * @param {Boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
  12773. * @return {Function} the constructor Mongoose will use for creating instances of this discriminator model
  12774. * @see discriminators /docs/discriminators.html
  12775. * @api public
  12776. */
  12777. SubdocumentPath.prototype.discriminator = function (name, schema, options) {
  12778. options = options || {};
  12779. var value = utils.isPOJO(options) ? options.value : options;
  12780. var clone = typeof options.clone === 'boolean' ? options.clone : true;
  12781. if (schema.instanceOfSchema && clone) {
  12782. schema = schema.clone();
  12783. }
  12784. schema = discriminator(this.caster, name, schema, value);
  12785. this.caster.discriminators[name] = _createConstructor(schema, this.caster);
  12786. return this.caster.discriminators[name];
  12787. };
  12788. /**
  12789. * Sets a default option for all SubdocumentPath instances.
  12790. *
  12791. * #### Example:
  12792. *
  12793. * // Make all numbers have option `min` equal to 0.
  12794. * mongoose.Schema.Embedded.set('required', true);
  12795. *
  12796. * @param {String} option - The option you'd like to set the value for
  12797. * @param {*} value - value for option
  12798. * @return {undefined}
  12799. * @function set
  12800. * @static
  12801. * @api public
  12802. */
  12803. SubdocumentPath.defaultOptions = {};
  12804. SubdocumentPath.set = SchemaType.set;
  12805. /*!
  12806. * ignore
  12807. */
  12808. SubdocumentPath.prototype.clone = function () {
  12809. var options = Object.assign({}, this.options);
  12810. var schematype = new this.constructor(this.schema, this.path, options);
  12811. schematype.validators = this.validators.slice();
  12812. if (this.requiredValidator !== undefined) {
  12813. schematype.requiredValidator = this.requiredValidator;
  12814. }
  12815. schematype.caster.discriminators = Object.assign({}, this.caster.discriminators);
  12816. return schematype;
  12817. };
  12818. /***/ }),
  12819. /***/ 94:
  12820. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  12821. "use strict";
  12822. /*!
  12823. * Module dependencies.
  12824. */
  12825. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  12826. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  12827. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  12828. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  12829. var $exists = __webpack_require__(8702);
  12830. var $type = __webpack_require__(3053);
  12831. var MongooseError = __webpack_require__(5202);
  12832. var SchemaArrayOptions = __webpack_require__(4756);
  12833. var SchemaType = __webpack_require__(4289);
  12834. var CastError = SchemaType.CastError;
  12835. var Mixed = __webpack_require__(3861);
  12836. var arrayDepth = __webpack_require__(6069);
  12837. var cast = __webpack_require__(6787);
  12838. var isOperator = __webpack_require__(9627);
  12839. var util = __webpack_require__(161);
  12840. var utils = __webpack_require__(6872);
  12841. var castToNumber = (__webpack_require__(1521)/* .castToNumber */ .W);
  12842. var geospatial = __webpack_require__(5008);
  12843. var getDiscriminatorByValue = __webpack_require__(7291);
  12844. var MongooseArray;
  12845. var EmbeddedDoc;
  12846. var isNestedArraySymbol = Symbol('mongoose#isNestedArray');
  12847. var emptyOpts = Object.freeze({});
  12848. /**
  12849. * Array SchemaType constructor
  12850. *
  12851. * @param {String} key
  12852. * @param {SchemaType} cast
  12853. * @param {Object} options
  12854. * @param {Object} schemaOptions
  12855. * @inherits SchemaType
  12856. * @api public
  12857. */
  12858. function SchemaArray(key, cast, options, schemaOptions) {
  12859. // lazy load
  12860. EmbeddedDoc || (EmbeddedDoc = (__webpack_require__(8941).Embedded));
  12861. var typeKey = 'type';
  12862. if (schemaOptions && schemaOptions.typeKey) {
  12863. typeKey = schemaOptions.typeKey;
  12864. }
  12865. this.schemaOptions = schemaOptions;
  12866. if (cast) {
  12867. var castOptions = {};
  12868. if (utils.isPOJO(cast)) {
  12869. if (cast[typeKey]) {
  12870. // support { type: Woot }
  12871. castOptions = utils.clone(cast); // do not alter user arguments
  12872. delete castOptions[typeKey];
  12873. cast = cast[typeKey];
  12874. } else {
  12875. cast = Mixed;
  12876. }
  12877. }
  12878. if (options != null && options.ref != null && castOptions.ref == null) {
  12879. castOptions.ref = options.ref;
  12880. }
  12881. if (cast === Object) {
  12882. cast = Mixed;
  12883. } // support { type: 'String' }
  12884. var name = typeof cast === 'string' ? cast : utils.getFunctionName(cast);
  12885. var Types = __webpack_require__(5251);
  12886. var caster = Types.hasOwnProperty(name) ? Types[name] : cast;
  12887. this.casterConstructor = caster;
  12888. if (this.casterConstructor instanceof SchemaArray) {
  12889. this.casterConstructor[isNestedArraySymbol] = true;
  12890. }
  12891. if (typeof caster === 'function' && !caster.$isArraySubdocument && !caster.$isSchemaMap) {
  12892. var path = this.caster instanceof EmbeddedDoc ? null : key;
  12893. this.caster = new caster(path, castOptions);
  12894. } else {
  12895. this.caster = caster;
  12896. if (!(this.caster instanceof EmbeddedDoc)) {
  12897. this.caster.path = key;
  12898. }
  12899. }
  12900. this.$embeddedSchemaType = this.caster;
  12901. }
  12902. this.$isMongooseArray = true;
  12903. SchemaType.call(this, key, options, 'Array');
  12904. var defaultArr;
  12905. var fn;
  12906. if (this.defaultValue != null) {
  12907. defaultArr = this.defaultValue;
  12908. fn = typeof defaultArr === 'function';
  12909. }
  12910. if (!('defaultValue' in this) || this.defaultValue !== void 0) {
  12911. var defaultFn = function defaultFn() {
  12912. // Leave it up to `cast()` to convert the array
  12913. return fn ? defaultArr.call(this) : defaultArr != null ? [].concat(defaultArr) : [];
  12914. };
  12915. defaultFn.$runBeforeSetters = !fn;
  12916. this["default"](defaultFn);
  12917. }
  12918. }
  12919. /**
  12920. * This schema type's name, to defend against minifiers that mangle
  12921. * function names.
  12922. *
  12923. * @api public
  12924. */
  12925. SchemaArray.schemaName = 'Array';
  12926. /**
  12927. * Options for all arrays.
  12928. *
  12929. * - `castNonArrays`: `true` by default. If `false`, Mongoose will throw a CastError when a value isn't an array. If `true`, Mongoose will wrap the provided value in an array before casting.
  12930. *
  12931. * @static options
  12932. * @api public
  12933. */
  12934. SchemaArray.options = {
  12935. castNonArrays: true
  12936. };
  12937. /*!
  12938. * ignore
  12939. */
  12940. SchemaArray.defaultOptions = {};
  12941. /**
  12942. * Sets a default option for all Array instances.
  12943. *
  12944. * #### Example:
  12945. *
  12946. * // Make all Array instances have `required` of true by default.
  12947. * mongoose.Schema.Array.set('required', true);
  12948. *
  12949. * const User = mongoose.model('User', new Schema({ test: Array }));
  12950. * new User({ }).validateSync().errors.test.message; // Path `test` is required.
  12951. *
  12952. * @param {String} option - The option you'd like to set the value for
  12953. * @param {*} value - value for option
  12954. * @return {undefined}
  12955. * @function set
  12956. * @api public
  12957. */
  12958. SchemaArray.set = SchemaType.set;
  12959. /*!
  12960. * Inherits from SchemaType.
  12961. */
  12962. SchemaArray.prototype = Object.create(SchemaType.prototype);
  12963. SchemaArray.prototype.constructor = SchemaArray;
  12964. SchemaArray.prototype.OptionsConstructor = SchemaArrayOptions;
  12965. /*!
  12966. * ignore
  12967. */
  12968. SchemaArray._checkRequired = SchemaType.prototype.checkRequired;
  12969. /**
  12970. * Override the function the required validator uses to check whether an array
  12971. * passes the `required` check.
  12972. *
  12973. * #### Example:
  12974. *
  12975. * // Require non-empty array to pass `required` check
  12976. * mongoose.Schema.Types.Array.checkRequired(v => Array.isArray(v) && v.length);
  12977. *
  12978. * const M = mongoose.model({ arr: { type: Array, required: true } });
  12979. * new M({ arr: [] }).validateSync(); // `null`, validation fails!
  12980. *
  12981. * @param {Function} fn
  12982. * @return {Function}
  12983. * @function checkRequired
  12984. * @api public
  12985. */
  12986. SchemaArray.checkRequired = SchemaType.checkRequired;
  12987. /**
  12988. * Check if the given value satisfies the `required` validator.
  12989. *
  12990. * @param {Any} value
  12991. * @param {Document} doc
  12992. * @return {Boolean}
  12993. * @api public
  12994. */
  12995. SchemaArray.prototype.checkRequired = function checkRequired(value, doc) {
  12996. if (_typeof(value) === 'object' && SchemaType._isRef(this, value, doc, true)) {
  12997. return !!value;
  12998. } // `require('util').inherits()` does **not** copy static properties, and
  12999. // plugins like mongoose-float use `inherits()` for pre-ES6.
  13000. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : SchemaArray.checkRequired();
  13001. return _checkRequired(value);
  13002. };
  13003. /**
  13004. * Adds an enum validator if this is an array of strings or numbers. Equivalent to
  13005. * `SchemaString.prototype.enum()` or `SchemaNumber.prototype.enum()`
  13006. *
  13007. * @param {String|Object} [args...] enumeration values
  13008. * @return {SchemaArray} this
  13009. */
  13010. SchemaArray.prototype["enum"] = function () {
  13011. var arr = this;
  13012. while (true) {
  13013. var instance = arr && arr.caster && arr.caster.instance;
  13014. if (instance === 'Array') {
  13015. arr = arr.caster;
  13016. continue;
  13017. }
  13018. if (instance !== 'String' && instance !== 'Number') {
  13019. throw new Error('`enum` can only be set on an array of strings or numbers ' + ', not ' + instance);
  13020. }
  13021. break;
  13022. }
  13023. var enumArray = arguments;
  13024. if (!Array.isArray(arguments) && utils.isObject(arguments)) {
  13025. enumArray = utils.object.vals(enumArray);
  13026. }
  13027. arr.caster["enum"].apply(arr.caster, enumArray);
  13028. return this;
  13029. };
  13030. /**
  13031. * Overrides the getters application for the population special-case
  13032. *
  13033. * @param {Object} value
  13034. * @param {Object} scope
  13035. * @api private
  13036. */
  13037. SchemaArray.prototype.applyGetters = function (value, scope) {
  13038. if (scope != null && scope.$__ != null && scope.$populated(this.path)) {
  13039. // means the object id was populated
  13040. return value;
  13041. }
  13042. var ret = SchemaType.prototype.applyGetters.call(this, value, scope);
  13043. if (Array.isArray(ret)) {
  13044. var rawValue = utils.isMongooseArray(ret) ? ret.__array : ret;
  13045. var len = rawValue.length;
  13046. for (var i = 0; i < len; ++i) {
  13047. rawValue[i] = this.caster.applyGetters(rawValue[i], scope);
  13048. }
  13049. }
  13050. return ret;
  13051. };
  13052. SchemaArray.prototype._applySetters = function (value, scope, init, priorVal) {
  13053. if (this.casterConstructor.$isMongooseArray && SchemaArray.options.castNonArrays && !this[isNestedArraySymbol]) {
  13054. // Check nesting levels and wrap in array if necessary
  13055. var depth = 0;
  13056. var arr = this;
  13057. while (arr != null && arr.$isMongooseArray && !arr.$isMongooseDocumentArray) {
  13058. ++depth;
  13059. arr = arr.casterConstructor;
  13060. } // No need to wrap empty arrays
  13061. if (value != null && value.length !== 0) {
  13062. var valueDepth = arrayDepth(value);
  13063. if (valueDepth.min === valueDepth.max && valueDepth.max < depth && valueDepth.containsNonArrayItem) {
  13064. for (var i = valueDepth.max; i < depth; ++i) {
  13065. value = [value];
  13066. }
  13067. }
  13068. }
  13069. }
  13070. return SchemaType.prototype._applySetters.call(this, value, scope, init, priorVal);
  13071. };
  13072. /**
  13073. * Casts values for set().
  13074. *
  13075. * @param {Object} value
  13076. * @param {Document} doc document that triggers the casting
  13077. * @param {Boolean} init whether this is an initialization cast
  13078. * @api private
  13079. */
  13080. SchemaArray.prototype.cast = function (value, doc, init, prev, options) {
  13081. // lazy load
  13082. MongooseArray || (MongooseArray = (__webpack_require__(8941).Array));
  13083. var i;
  13084. var l;
  13085. if (Array.isArray(value)) {
  13086. var len = value.length;
  13087. if (!len && doc) {
  13088. var indexes = doc.schema.indexedPaths();
  13089. var arrayPath = this.path;
  13090. for (i = 0, l = indexes.length; i < l; ++i) {
  13091. var pathIndex = indexes[i][0][arrayPath];
  13092. if (pathIndex === '2dsphere' || pathIndex === '2d') {
  13093. return;
  13094. }
  13095. } // Special case: if this index is on the parent of what looks like
  13096. // GeoJSON, skip setting the default to empty array re: #1668, #3233
  13097. var arrayGeojsonPath = this.path.endsWith('.coordinates') ? this.path.substring(0, this.path.lastIndexOf('.')) : null;
  13098. if (arrayGeojsonPath != null) {
  13099. for (i = 0, l = indexes.length; i < l; ++i) {
  13100. var _pathIndex = indexes[i][0][arrayGeojsonPath];
  13101. if (_pathIndex === '2dsphere') {
  13102. return;
  13103. }
  13104. }
  13105. }
  13106. }
  13107. options = options || emptyOpts;
  13108. var rawValue = utils.isMongooseArray(value) ? value.__array : value;
  13109. value = MongooseArray(rawValue, options.path || this._arrayPath || this.path, doc, this);
  13110. rawValue = value.__array;
  13111. if (init && doc != null && doc.$__ != null && doc.$populated(this.path)) {
  13112. return value;
  13113. }
  13114. var caster = this.caster;
  13115. var isMongooseArray = caster.$isMongooseArray;
  13116. if (caster && this.casterConstructor !== Mixed) {
  13117. try {
  13118. var _len = rawValue.length;
  13119. for (i = 0; i < _len; i++) {
  13120. var opts = {}; // Perf: creating `arrayPath` is expensive for large arrays.
  13121. // We only need `arrayPath` if this is a nested array, so
  13122. // skip if possible.
  13123. if (isMongooseArray) {
  13124. if (options.arrayPath != null) {
  13125. opts.arrayPathIndex = i;
  13126. } else if (caster._arrayParentPath != null) {
  13127. opts.arrayPathIndex = i;
  13128. }
  13129. }
  13130. rawValue[i] = caster.applySetters(rawValue[i], doc, init, void 0, opts);
  13131. }
  13132. } catch (e) {
  13133. // rethrow
  13134. throw new CastError('[' + e.kind + ']', util.inspect(value), this.path + '.' + i, e, this);
  13135. }
  13136. }
  13137. return value;
  13138. }
  13139. if (init || SchemaArray.options.castNonArrays) {
  13140. // gh-2442: if we're loading this from the db and its not an array, mark
  13141. // the whole array as modified.
  13142. if (!!doc && !!init) {
  13143. doc.markModified(this.path);
  13144. }
  13145. return this.cast([value], doc, init);
  13146. }
  13147. throw new CastError('Array', util.inspect(value), this.path, null, this);
  13148. };
  13149. /*!
  13150. * ignore
  13151. */
  13152. SchemaArray.prototype._castForPopulate = function _castForPopulate(value, doc) {
  13153. // lazy load
  13154. MongooseArray || (MongooseArray = (__webpack_require__(8941).Array));
  13155. if (Array.isArray(value)) {
  13156. var i;
  13157. var rawValue = value.__array ? value.__array : value;
  13158. var len = rawValue.length;
  13159. var caster = this.caster;
  13160. if (caster && this.casterConstructor !== Mixed) {
  13161. try {
  13162. for (i = 0; i < len; i++) {
  13163. var opts = {}; // Perf: creating `arrayPath` is expensive for large arrays.
  13164. // We only need `arrayPath` if this is a nested array, so
  13165. // skip if possible.
  13166. if (caster.$isMongooseArray && caster._arrayParentPath != null) {
  13167. opts.arrayPathIndex = i;
  13168. }
  13169. rawValue[i] = caster.cast(rawValue[i], doc, false, void 0, opts);
  13170. }
  13171. } catch (e) {
  13172. // rethrow
  13173. throw new CastError('[' + e.kind + ']', util.inspect(value), this.path + '.' + i, e, this);
  13174. }
  13175. }
  13176. return value;
  13177. }
  13178. throw new CastError('Array', util.inspect(value), this.path, null, this);
  13179. };
  13180. SchemaArray.prototype.$toObject = SchemaArray.prototype.toObject;
  13181. /*!
  13182. * Ignore
  13183. */
  13184. SchemaArray.prototype.discriminator = function (name, schema) {
  13185. var arr = this;
  13186. while (arr.$isMongooseArray && !arr.$isMongooseDocumentArray) {
  13187. arr = arr.casterConstructor;
  13188. if (arr == null || typeof arr === 'function') {
  13189. throw new MongooseError('You can only add an embedded discriminator on ' + 'a document array, ' + this.path + ' is a plain array');
  13190. }
  13191. }
  13192. return arr.discriminator(name, schema);
  13193. };
  13194. /*!
  13195. * ignore
  13196. */
  13197. SchemaArray.prototype.clone = function () {
  13198. var options = Object.assign({}, this.options);
  13199. var schematype = new this.constructor(this.path, this.caster, options, this.schemaOptions);
  13200. schematype.validators = this.validators.slice();
  13201. if (this.requiredValidator !== undefined) {
  13202. schematype.requiredValidator = this.requiredValidator;
  13203. }
  13204. return schematype;
  13205. };
  13206. /**
  13207. * Casts values for queries.
  13208. *
  13209. * @param {String} $conditional
  13210. * @param {any} [value]
  13211. * @api private
  13212. */
  13213. SchemaArray.prototype.castForQuery = function ($conditional, value) {
  13214. var _this = this;
  13215. var handler;
  13216. var val;
  13217. if (arguments.length === 2) {
  13218. handler = this.$conditionalHandlers[$conditional];
  13219. if (!handler) {
  13220. throw new Error('Can\'t use ' + $conditional + ' with Array.');
  13221. }
  13222. val = handler.call(this, value);
  13223. } else {
  13224. val = $conditional;
  13225. var Constructor = this.casterConstructor;
  13226. if (val && Constructor.discriminators && Constructor.schema && Constructor.schema.options && Constructor.schema.options.discriminatorKey) {
  13227. if (typeof val[Constructor.schema.options.discriminatorKey] === 'string' && Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]]) {
  13228. Constructor = Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]];
  13229. } else {
  13230. var constructorByValue = getDiscriminatorByValue(Constructor.discriminators, val[Constructor.schema.options.discriminatorKey]);
  13231. if (constructorByValue) {
  13232. Constructor = constructorByValue;
  13233. }
  13234. }
  13235. }
  13236. var proto = this.casterConstructor.prototype;
  13237. var method = proto && (proto.castForQuery || proto.cast);
  13238. if (!method && Constructor.castForQuery) {
  13239. method = Constructor.castForQuery;
  13240. }
  13241. var caster = this.caster;
  13242. if (Array.isArray(val)) {
  13243. this.setters.reverse().forEach(function (setter) {
  13244. val = setter.call(_this, val, _this);
  13245. });
  13246. val = val.map(function (v) {
  13247. if (utils.isObject(v) && v.$elemMatch) {
  13248. return v;
  13249. }
  13250. if (method) {
  13251. v = method.call(caster, v);
  13252. return v;
  13253. }
  13254. if (v != null) {
  13255. v = new Constructor(v);
  13256. return v;
  13257. }
  13258. return v;
  13259. });
  13260. } else if (method) {
  13261. val = method.call(caster, val);
  13262. } else if (val != null) {
  13263. val = new Constructor(val);
  13264. }
  13265. }
  13266. return val;
  13267. };
  13268. function cast$all(val) {
  13269. if (!Array.isArray(val)) {
  13270. val = [val];
  13271. }
  13272. val = val.map(function (v) {
  13273. if (!utils.isObject(v)) {
  13274. return v;
  13275. }
  13276. if (v.$elemMatch != null) {
  13277. return {
  13278. $elemMatch: cast(this.casterConstructor.schema, v.$elemMatch)
  13279. };
  13280. }
  13281. var o = {};
  13282. o[this.path] = v;
  13283. return cast(this.casterConstructor.schema, o)[this.path];
  13284. }, this);
  13285. return this.castForQuery(val);
  13286. }
  13287. function cast$elemMatch(val) {
  13288. var keys = Object.keys(val);
  13289. var numKeys = keys.length;
  13290. for (var i = 0; i < numKeys; ++i) {
  13291. var key = keys[i];
  13292. var value = val[key];
  13293. if (isOperator(key) && value != null) {
  13294. val[key] = this.castForQuery(key, value);
  13295. }
  13296. } // Is this an embedded discriminator and is the discriminator key set?
  13297. // If so, use the discriminator schema. See gh-7449
  13298. var discriminatorKey = this && this.casterConstructor && this.casterConstructor.schema && this.casterConstructor.schema.options && this.casterConstructor.schema.options.discriminatorKey;
  13299. var discriminators = this && this.casterConstructor && this.casterConstructor.schema && this.casterConstructor.schema.discriminators || {};
  13300. if (discriminatorKey != null && val[discriminatorKey] != null && discriminators[val[discriminatorKey]] != null) {
  13301. return cast(discriminators[val[discriminatorKey]], val);
  13302. }
  13303. return cast(this.casterConstructor.schema, val);
  13304. }
  13305. var handle = SchemaArray.prototype.$conditionalHandlers = {};
  13306. handle.$all = cast$all;
  13307. handle.$options = String;
  13308. handle.$elemMatch = cast$elemMatch;
  13309. handle.$geoIntersects = geospatial.cast$geoIntersects;
  13310. handle.$or = createLogicalQueryOperatorHandler('$or');
  13311. handle.$and = createLogicalQueryOperatorHandler('$and');
  13312. handle.$nor = createLogicalQueryOperatorHandler('$nor');
  13313. function createLogicalQueryOperatorHandler(op) {
  13314. return function logicalQueryOperatorHandler(val) {
  13315. if (!Array.isArray(val)) {
  13316. throw new TypeError('conditional ' + op + ' requires an array');
  13317. }
  13318. var ret = [];
  13319. var _iterator = _createForOfIteratorHelper(val),
  13320. _step;
  13321. try {
  13322. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  13323. var obj = _step.value;
  13324. ret.push(cast(this.casterConstructor.schema, obj));
  13325. }
  13326. } catch (err) {
  13327. _iterator.e(err);
  13328. } finally {
  13329. _iterator.f();
  13330. }
  13331. return ret;
  13332. };
  13333. }
  13334. handle.$near = handle.$nearSphere = geospatial.cast$near;
  13335. handle.$within = handle.$geoWithin = geospatial.cast$within;
  13336. handle.$size = handle.$minDistance = handle.$maxDistance = castToNumber;
  13337. handle.$exists = $exists;
  13338. handle.$type = $type;
  13339. handle.$eq = handle.$gt = handle.$gte = handle.$lt = handle.$lte = handle.$ne = handle.$not = handle.$regex = SchemaArray.prototype.castForQuery; // `$in` is special because you can also include an empty array in the query
  13340. // like `$in: [1, []]`, see gh-5913
  13341. handle.$nin = SchemaType.prototype.$conditionalHandlers.$nin;
  13342. handle.$in = SchemaType.prototype.$conditionalHandlers.$in;
  13343. /*!
  13344. * Module exports.
  13345. */
  13346. module.exports = SchemaArray;
  13347. /***/ }),
  13348. /***/ 6470:
  13349. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  13350. "use strict";
  13351. /*!
  13352. * Module dependencies.
  13353. */
  13354. var CastError = __webpack_require__(1795);
  13355. var SchemaType = __webpack_require__(4289);
  13356. var castBoolean = __webpack_require__(6670);
  13357. var utils = __webpack_require__(6872);
  13358. /**
  13359. * Boolean SchemaType constructor.
  13360. *
  13361. * @param {String} path
  13362. * @param {Object} options
  13363. * @inherits SchemaType
  13364. * @api public
  13365. */
  13366. function SchemaBoolean(path, options) {
  13367. SchemaType.call(this, path, options, 'Boolean');
  13368. }
  13369. /**
  13370. * This schema type's name, to defend against minifiers that mangle
  13371. * function names.
  13372. *
  13373. * @api public
  13374. */
  13375. SchemaBoolean.schemaName = 'Boolean';
  13376. SchemaBoolean.defaultOptions = {};
  13377. /*!
  13378. * Inherits from SchemaType.
  13379. */
  13380. SchemaBoolean.prototype = Object.create(SchemaType.prototype);
  13381. SchemaBoolean.prototype.constructor = SchemaBoolean;
  13382. /*!
  13383. * ignore
  13384. */
  13385. SchemaBoolean._cast = castBoolean;
  13386. /**
  13387. * Sets a default option for all Boolean instances.
  13388. *
  13389. * #### Example:
  13390. *
  13391. * // Make all booleans have `default` of false.
  13392. * mongoose.Schema.Boolean.set('default', false);
  13393. *
  13394. * const Order = mongoose.model('Order', new Schema({ isPaid: Boolean }));
  13395. * new Order({ }).isPaid; // false
  13396. *
  13397. * @param {String} option - The option you'd like to set the value for
  13398. * @param {*} value - value for option
  13399. * @return {undefined}
  13400. * @function set
  13401. * @static
  13402. * @api public
  13403. */
  13404. SchemaBoolean.set = SchemaType.set;
  13405. /**
  13406. * Get/set the function used to cast arbitrary values to booleans.
  13407. *
  13408. * #### Example:
  13409. *
  13410. * // Make Mongoose cast empty string '' to false.
  13411. * const original = mongoose.Schema.Boolean.cast();
  13412. * mongoose.Schema.Boolean.cast(v => {
  13413. * if (v === '') {
  13414. * return false;
  13415. * }
  13416. * return original(v);
  13417. * });
  13418. *
  13419. * // Or disable casting entirely
  13420. * mongoose.Schema.Boolean.cast(false);
  13421. *
  13422. * @param {Function} caster
  13423. * @return {Function}
  13424. * @function get
  13425. * @static
  13426. * @api public
  13427. */
  13428. SchemaBoolean.cast = function cast(caster) {
  13429. if (arguments.length === 0) {
  13430. return this._cast;
  13431. }
  13432. if (caster === false) {
  13433. caster = this._defaultCaster;
  13434. }
  13435. this._cast = caster;
  13436. return this._cast;
  13437. };
  13438. /*!
  13439. * ignore
  13440. */
  13441. SchemaBoolean._defaultCaster = function (v) {
  13442. if (v != null && typeof v !== 'boolean') {
  13443. throw new Error();
  13444. }
  13445. return v;
  13446. };
  13447. /*!
  13448. * ignore
  13449. */
  13450. SchemaBoolean._checkRequired = function (v) {
  13451. return v === true || v === false;
  13452. };
  13453. /**
  13454. * Override the function the required validator uses to check whether a boolean
  13455. * passes the `required` check.
  13456. *
  13457. * @param {Function} fn
  13458. * @return {Function}
  13459. * @function checkRequired
  13460. * @static
  13461. * @api public
  13462. */
  13463. SchemaBoolean.checkRequired = SchemaType.checkRequired;
  13464. /**
  13465. * Check if the given value satisfies a required validator. For a boolean
  13466. * to satisfy a required validator, it must be strictly equal to true or to
  13467. * false.
  13468. *
  13469. * @param {Any} value
  13470. * @return {Boolean}
  13471. * @api public
  13472. */
  13473. SchemaBoolean.prototype.checkRequired = function (value) {
  13474. return this.constructor._checkRequired(value);
  13475. };
  13476. /**
  13477. * Configure which values get casted to `true`.
  13478. *
  13479. * #### Example:
  13480. *
  13481. * const M = mongoose.model('Test', new Schema({ b: Boolean }));
  13482. * new M({ b: 'affirmative' }).b; // undefined
  13483. * mongoose.Schema.Boolean.convertToTrue.add('affirmative');
  13484. * new M({ b: 'affirmative' }).b; // true
  13485. *
  13486. * @property convertToTrue
  13487. * @type Set
  13488. * @api public
  13489. */
  13490. Object.defineProperty(SchemaBoolean, 'convertToTrue', {
  13491. get: function get() {
  13492. return castBoolean.convertToTrue;
  13493. },
  13494. set: function set(v) {
  13495. castBoolean.convertToTrue = v;
  13496. }
  13497. });
  13498. /**
  13499. * Configure which values get casted to `false`.
  13500. *
  13501. * #### Example:
  13502. *
  13503. * const M = mongoose.model('Test', new Schema({ b: Boolean }));
  13504. * new M({ b: 'nay' }).b; // undefined
  13505. * mongoose.Schema.Types.Boolean.convertToFalse.add('nay');
  13506. * new M({ b: 'nay' }).b; // false
  13507. *
  13508. * @property convertToFalse
  13509. * @type Set
  13510. * @api public
  13511. */
  13512. Object.defineProperty(SchemaBoolean, 'convertToFalse', {
  13513. get: function get() {
  13514. return castBoolean.convertToFalse;
  13515. },
  13516. set: function set(v) {
  13517. castBoolean.convertToFalse = v;
  13518. }
  13519. });
  13520. /**
  13521. * Casts to boolean
  13522. *
  13523. * @param {Object} value
  13524. * @param {Object} model - this value is optional
  13525. * @api private
  13526. */
  13527. SchemaBoolean.prototype.cast = function (value) {
  13528. var castBoolean;
  13529. if (typeof this._castFunction === 'function') {
  13530. castBoolean = this._castFunction;
  13531. } else if (typeof this.constructor.cast === 'function') {
  13532. castBoolean = this.constructor.cast();
  13533. } else {
  13534. castBoolean = SchemaBoolean.cast();
  13535. }
  13536. try {
  13537. return castBoolean(value);
  13538. } catch (error) {
  13539. throw new CastError('Boolean', value, this.path, error, this);
  13540. }
  13541. };
  13542. SchemaBoolean.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {});
  13543. /**
  13544. * Casts contents for queries.
  13545. *
  13546. * @param {String} $conditional
  13547. * @param {any} val
  13548. * @api private
  13549. */
  13550. SchemaBoolean.prototype.castForQuery = function ($conditional, val) {
  13551. var handler;
  13552. if (arguments.length === 2) {
  13553. handler = SchemaBoolean.$conditionalHandlers[$conditional];
  13554. if (handler) {
  13555. return handler.call(this, val);
  13556. }
  13557. return this._castForQuery(val);
  13558. }
  13559. return this._castForQuery($conditional);
  13560. };
  13561. /**
  13562. *
  13563. * @api private
  13564. */
  13565. SchemaBoolean.prototype._castNullish = function _castNullish(v) {
  13566. if (typeof v === 'undefined') {
  13567. return v;
  13568. }
  13569. var castBoolean = typeof this.constructor.cast === 'function' ? this.constructor.cast() : SchemaBoolean.cast();
  13570. if (castBoolean == null) {
  13571. return v;
  13572. }
  13573. if (castBoolean.convertToFalse instanceof Set && castBoolean.convertToFalse.has(v)) {
  13574. return false;
  13575. }
  13576. if (castBoolean.convertToTrue instanceof Set && castBoolean.convertToTrue.has(v)) {
  13577. return true;
  13578. }
  13579. return v;
  13580. };
  13581. /*!
  13582. * Module exports.
  13583. */
  13584. module.exports = SchemaBoolean;
  13585. /***/ }),
  13586. /***/ 8800:
  13587. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  13588. "use strict";
  13589. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  13590. /*!
  13591. * Module dependencies.
  13592. */
  13593. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  13594. var MongooseBuffer = __webpack_require__(4051);
  13595. var SchemaBufferOptions = __webpack_require__(9586);
  13596. var SchemaType = __webpack_require__(4289);
  13597. var handleBitwiseOperator = __webpack_require__(4282);
  13598. var utils = __webpack_require__(6872);
  13599. var Binary = MongooseBuffer.Binary;
  13600. var CastError = SchemaType.CastError;
  13601. /**
  13602. * Buffer SchemaType constructor
  13603. *
  13604. * @param {String} key
  13605. * @param {Object} options
  13606. * @inherits SchemaType
  13607. * @api public
  13608. */
  13609. function SchemaBuffer(key, options) {
  13610. SchemaType.call(this, key, options, 'Buffer');
  13611. }
  13612. /**
  13613. * This schema type's name, to defend against minifiers that mangle
  13614. * function names.
  13615. *
  13616. * @api public
  13617. */
  13618. SchemaBuffer.schemaName = 'Buffer';
  13619. SchemaBuffer.defaultOptions = {};
  13620. /*!
  13621. * Inherits from SchemaType.
  13622. */
  13623. SchemaBuffer.prototype = Object.create(SchemaType.prototype);
  13624. SchemaBuffer.prototype.constructor = SchemaBuffer;
  13625. SchemaBuffer.prototype.OptionsConstructor = SchemaBufferOptions;
  13626. /*!
  13627. * ignore
  13628. */
  13629. SchemaBuffer._checkRequired = function (v) {
  13630. return !!(v && v.length);
  13631. };
  13632. /**
  13633. * Sets a default option for all Buffer instances.
  13634. *
  13635. * #### Example:
  13636. *
  13637. * // Make all buffers have `required` of true by default.
  13638. * mongoose.Schema.Buffer.set('required', true);
  13639. *
  13640. * const User = mongoose.model('User', new Schema({ test: Buffer }));
  13641. * new User({ }).validateSync().errors.test.message; // Path `test` is required.
  13642. *
  13643. * @param {String} option - The option you'd like to set the value for
  13644. * @param {*} value - value for option
  13645. * @return {undefined}
  13646. * @function set
  13647. * @static
  13648. * @api public
  13649. */
  13650. SchemaBuffer.set = SchemaType.set;
  13651. /**
  13652. * Override the function the required validator uses to check whether a string
  13653. * passes the `required` check.
  13654. *
  13655. * #### Example:
  13656. *
  13657. * // Allow empty strings to pass `required` check
  13658. * mongoose.Schema.Types.String.checkRequired(v => v != null);
  13659. *
  13660. * const M = mongoose.model({ buf: { type: Buffer, required: true } });
  13661. * new M({ buf: Buffer.from('') }).validateSync(); // validation passes!
  13662. *
  13663. * @param {Function} fn
  13664. * @return {Function}
  13665. * @function checkRequired
  13666. * @static
  13667. * @api public
  13668. */
  13669. SchemaBuffer.checkRequired = SchemaType.checkRequired;
  13670. /**
  13671. * Check if the given value satisfies a required validator. To satisfy a
  13672. * required validator, a buffer must not be null or undefined and have
  13673. * non-zero length.
  13674. *
  13675. * @param {Any} value
  13676. * @param {Document} doc
  13677. * @return {Boolean}
  13678. * @api public
  13679. */
  13680. SchemaBuffer.prototype.checkRequired = function (value, doc) {
  13681. if (SchemaType._isRef(this, value, doc, true)) {
  13682. return !!value;
  13683. }
  13684. return this.constructor._checkRequired(value);
  13685. };
  13686. /**
  13687. * Casts contents
  13688. *
  13689. * @param {Object} value
  13690. * @param {Document} doc document that triggers the casting
  13691. * @param {Boolean} init
  13692. * @api private
  13693. */
  13694. SchemaBuffer.prototype.cast = function (value, doc, init) {
  13695. var ret;
  13696. if (SchemaType._isRef(this, value, doc, init)) {
  13697. if (value && value.isMongooseBuffer) {
  13698. return value;
  13699. }
  13700. if (Buffer.isBuffer(value)) {
  13701. if (!value || !value.isMongooseBuffer) {
  13702. value = new MongooseBuffer(value, [this.path, doc]);
  13703. if (this.options.subtype != null) {
  13704. value._subtype = this.options.subtype;
  13705. }
  13706. }
  13707. return value;
  13708. }
  13709. if (value instanceof Binary) {
  13710. ret = new MongooseBuffer(value.value(true), [this.path, doc]);
  13711. if (typeof value.sub_type !== 'number') {
  13712. throw new CastError('Buffer', value, this.path, null, this);
  13713. }
  13714. ret._subtype = value.sub_type;
  13715. return ret;
  13716. }
  13717. if (value == null || utils.isNonBuiltinObject(value)) {
  13718. return this._castRef(value, doc, init);
  13719. }
  13720. } // documents
  13721. if (value && value._id) {
  13722. value = value._id;
  13723. }
  13724. if (value && value.isMongooseBuffer) {
  13725. return value;
  13726. }
  13727. if (Buffer.isBuffer(value)) {
  13728. if (!value || !value.isMongooseBuffer) {
  13729. value = new MongooseBuffer(value, [this.path, doc]);
  13730. if (this.options.subtype != null) {
  13731. value._subtype = this.options.subtype;
  13732. }
  13733. }
  13734. return value;
  13735. }
  13736. if (value instanceof Binary) {
  13737. ret = new MongooseBuffer(value.value(true), [this.path, doc]);
  13738. if (typeof value.sub_type !== 'number') {
  13739. throw new CastError('Buffer', value, this.path, null, this);
  13740. }
  13741. ret._subtype = value.sub_type;
  13742. return ret;
  13743. }
  13744. if (value === null) {
  13745. return value;
  13746. }
  13747. var type = _typeof(value);
  13748. if (type === 'string' || type === 'number' || Array.isArray(value) || type === 'object' && value.type === 'Buffer' && Array.isArray(value.data) // gh-6863
  13749. ) {
  13750. if (type === 'number') {
  13751. value = [value];
  13752. }
  13753. ret = new MongooseBuffer(value, [this.path, doc]);
  13754. if (this.options.subtype != null) {
  13755. ret._subtype = this.options.subtype;
  13756. }
  13757. return ret;
  13758. }
  13759. throw new CastError('Buffer', value, this.path, null, this);
  13760. };
  13761. /**
  13762. * Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/)
  13763. * for this buffer. You can find a [list of allowed subtypes here](https://api.mongodb.com/python/current/api/bson/binary.html).
  13764. *
  13765. * #### Example:
  13766. *
  13767. * const s = new Schema({ uuid: { type: Buffer, subtype: 4 });
  13768. * const M = db.model('M', s);
  13769. * const m = new M({ uuid: 'test string' });
  13770. * m.uuid._subtype; // 4
  13771. *
  13772. * @param {Number} subtype the default subtype
  13773. * @return {SchemaType} this
  13774. * @api public
  13775. */
  13776. SchemaBuffer.prototype.subtype = function (subtype) {
  13777. this.options.subtype = subtype;
  13778. return this;
  13779. };
  13780. /*!
  13781. * ignore
  13782. */
  13783. function handleSingle(val) {
  13784. return this.castForQuery(val);
  13785. }
  13786. SchemaBuffer.prototype.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  13787. $bitsAllClear: handleBitwiseOperator,
  13788. $bitsAnyClear: handleBitwiseOperator,
  13789. $bitsAllSet: handleBitwiseOperator,
  13790. $bitsAnySet: handleBitwiseOperator,
  13791. $gt: handleSingle,
  13792. $gte: handleSingle,
  13793. $lt: handleSingle,
  13794. $lte: handleSingle
  13795. });
  13796. /**
  13797. * Casts contents for queries.
  13798. *
  13799. * @param {String} $conditional
  13800. * @param {any} [value]
  13801. * @api private
  13802. */
  13803. SchemaBuffer.prototype.castForQuery = function ($conditional, val) {
  13804. var handler;
  13805. if (arguments.length === 2) {
  13806. handler = this.$conditionalHandlers[$conditional];
  13807. if (!handler) {
  13808. throw new Error('Can\'t use ' + $conditional + ' with Buffer.');
  13809. }
  13810. return handler.call(this, val);
  13811. }
  13812. val = $conditional;
  13813. var casted = this._castForQuery(val);
  13814. return casted ? casted.toObject({
  13815. transform: false,
  13816. virtuals: false
  13817. }) : casted;
  13818. };
  13819. /*!
  13820. * Module exports.
  13821. */
  13822. module.exports = SchemaBuffer;
  13823. /***/ }),
  13824. /***/ 6535:
  13825. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  13826. "use strict";
  13827. /*!
  13828. * Module requirements.
  13829. */
  13830. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  13831. var MongooseError = __webpack_require__(4888);
  13832. var SchemaDateOptions = __webpack_require__(2869);
  13833. var SchemaType = __webpack_require__(4289);
  13834. var castDate = __webpack_require__(195);
  13835. var getConstructorName = __webpack_require__(1981);
  13836. var utils = __webpack_require__(6872);
  13837. var CastError = SchemaType.CastError;
  13838. /**
  13839. * Date SchemaType constructor.
  13840. *
  13841. * @param {String} key
  13842. * @param {Object} options
  13843. * @inherits SchemaType
  13844. * @api public
  13845. */
  13846. function SchemaDate(key, options) {
  13847. SchemaType.call(this, key, options, 'Date');
  13848. }
  13849. /**
  13850. * This schema type's name, to defend against minifiers that mangle
  13851. * function names.
  13852. *
  13853. * @api public
  13854. */
  13855. SchemaDate.schemaName = 'Date';
  13856. SchemaDate.defaultOptions = {};
  13857. /*!
  13858. * Inherits from SchemaType.
  13859. */
  13860. SchemaDate.prototype = Object.create(SchemaType.prototype);
  13861. SchemaDate.prototype.constructor = SchemaDate;
  13862. SchemaDate.prototype.OptionsConstructor = SchemaDateOptions;
  13863. /*!
  13864. * ignore
  13865. */
  13866. SchemaDate._cast = castDate;
  13867. /**
  13868. * Sets a default option for all Date instances.
  13869. *
  13870. * #### Example:
  13871. *
  13872. * // Make all dates have `required` of true by default.
  13873. * mongoose.Schema.Date.set('required', true);
  13874. *
  13875. * const User = mongoose.model('User', new Schema({ test: Date }));
  13876. * new User({ }).validateSync().errors.test.message; // Path `test` is required.
  13877. *
  13878. * @param {String} option - The option you'd like to set the value for
  13879. * @param {*} value - value for option
  13880. * @return {undefined}
  13881. * @function set
  13882. * @static
  13883. * @api public
  13884. */
  13885. SchemaDate.set = SchemaType.set;
  13886. /**
  13887. * Get/set the function used to cast arbitrary values to dates.
  13888. *
  13889. * #### Example:
  13890. *
  13891. * // Mongoose converts empty string '' into `null` for date types. You
  13892. * // can create a custom caster to disable it.
  13893. * const original = mongoose.Schema.Types.Date.cast();
  13894. * mongoose.Schema.Types.Date.cast(v => {
  13895. * assert.ok(v !== '');
  13896. * return original(v);
  13897. * });
  13898. *
  13899. * // Or disable casting entirely
  13900. * mongoose.Schema.Types.Date.cast(false);
  13901. *
  13902. * @param {Function} caster
  13903. * @return {Function}
  13904. * @function get
  13905. * @static
  13906. * @api public
  13907. */
  13908. SchemaDate.cast = function cast(caster) {
  13909. if (arguments.length === 0) {
  13910. return this._cast;
  13911. }
  13912. if (caster === false) {
  13913. caster = this._defaultCaster;
  13914. }
  13915. this._cast = caster;
  13916. return this._cast;
  13917. };
  13918. /*!
  13919. * ignore
  13920. */
  13921. SchemaDate._defaultCaster = function (v) {
  13922. if (v != null && !(v instanceof Date)) {
  13923. throw new Error();
  13924. }
  13925. return v;
  13926. };
  13927. /**
  13928. * Declares a TTL index (rounded to the nearest second) for _Date_ types only.
  13929. *
  13930. * This sets the `expireAfterSeconds` index option available in MongoDB >= 2.1.2.
  13931. * This index type is only compatible with Date types.
  13932. *
  13933. * #### Example:
  13934. *
  13935. * // expire in 24 hours
  13936. * new Schema({ createdAt: { type: Date, expires: 60*60*24 }});
  13937. *
  13938. * `expires` utilizes the `ms` module from [guille](https://github.com/guille/) allowing us to use a friendlier syntax:
  13939. *
  13940. * #### Example:
  13941. *
  13942. * // expire in 24 hours
  13943. * new Schema({ createdAt: { type: Date, expires: '24h' }});
  13944. *
  13945. * // expire in 1.5 hours
  13946. * new Schema({ createdAt: { type: Date, expires: '1.5h' }});
  13947. *
  13948. * // expire in 7 days
  13949. * const schema = new Schema({ createdAt: Date });
  13950. * schema.path('createdAt').expires('7d');
  13951. *
  13952. * @param {Number|String} when
  13953. * @added 3.0.0
  13954. * @return {SchemaType} this
  13955. * @api public
  13956. */
  13957. SchemaDate.prototype.expires = function (when) {
  13958. if (getConstructorName(this._index) !== 'Object') {
  13959. this._index = {};
  13960. }
  13961. this._index.expires = when;
  13962. utils.expires(this._index);
  13963. return this;
  13964. };
  13965. /*!
  13966. * ignore
  13967. */
  13968. SchemaDate._checkRequired = function (v) {
  13969. return v instanceof Date;
  13970. };
  13971. /**
  13972. * Override the function the required validator uses to check whether a string
  13973. * passes the `required` check.
  13974. *
  13975. * #### Example:
  13976. *
  13977. * // Allow empty strings to pass `required` check
  13978. * mongoose.Schema.Types.String.checkRequired(v => v != null);
  13979. *
  13980. * const M = mongoose.model({ str: { type: String, required: true } });
  13981. * new M({ str: '' }).validateSync(); // `null`, validation passes!
  13982. *
  13983. * @param {Function} fn
  13984. * @return {Function}
  13985. * @function checkRequired
  13986. * @static
  13987. * @api public
  13988. */
  13989. SchemaDate.checkRequired = SchemaType.checkRequired;
  13990. /**
  13991. * Check if the given value satisfies a required validator. To satisfy
  13992. * a required validator, the given value must be an instance of `Date`.
  13993. *
  13994. * @param {Any} value
  13995. * @param {Document} doc
  13996. * @return {Boolean}
  13997. * @api public
  13998. */
  13999. SchemaDate.prototype.checkRequired = function (value, doc) {
  14000. if (_typeof(value) === 'object' && SchemaType._isRef(this, value, doc, true)) {
  14001. return value != null;
  14002. } // `require('util').inherits()` does **not** copy static properties, and
  14003. // plugins like mongoose-float use `inherits()` for pre-ES6.
  14004. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : SchemaDate.checkRequired();
  14005. return _checkRequired(value);
  14006. };
  14007. /**
  14008. * Sets a minimum date validator.
  14009. *
  14010. * #### Example:
  14011. *
  14012. * const s = new Schema({ d: { type: Date, min: Date('1970-01-01') })
  14013. * const M = db.model('M', s)
  14014. * const m = new M({ d: Date('1969-12-31') })
  14015. * m.save(function (err) {
  14016. * console.error(err) // validator error
  14017. * m.d = Date('2014-12-08');
  14018. * m.save() // success
  14019. * })
  14020. *
  14021. * // custom error messages
  14022. * // We can also use the special {MIN} token which will be replaced with the invalid value
  14023. * const min = [Date('1970-01-01'), 'The value of path `{PATH}` ({VALUE}) is beneath the limit ({MIN}).'];
  14024. * const schema = new Schema({ d: { type: Date, min: min })
  14025. * const M = mongoose.model('M', schema);
  14026. * const s= new M({ d: Date('1969-12-31') });
  14027. * s.validate(function (err) {
  14028. * console.log(String(err)) // ValidationError: The value of path `d` (1969-12-31) is before the limit (1970-01-01).
  14029. * })
  14030. *
  14031. * @param {Date} value minimum date
  14032. * @param {String} [message] optional custom error message
  14033. * @return {SchemaType} this
  14034. * @see Customized Error Messages #error_messages_MongooseError-messages
  14035. * @api public
  14036. */
  14037. SchemaDate.prototype.min = function (value, message) {
  14038. if (this.minValidator) {
  14039. this.validators = this.validators.filter(function (v) {
  14040. return v.validator !== this.minValidator;
  14041. }, this);
  14042. }
  14043. if (value) {
  14044. var msg = message || MongooseError.messages.Date.min;
  14045. if (typeof msg === 'string') {
  14046. msg = msg.replace(/{MIN}/, value === Date.now ? 'Date.now()' : value.toString());
  14047. }
  14048. var _this = this;
  14049. this.validators.push({
  14050. validator: this.minValidator = function (val) {
  14051. var _value = value;
  14052. if (typeof value === 'function' && value !== Date.now) {
  14053. _value = _value.call(this);
  14054. }
  14055. var min = _value === Date.now ? _value() : _this.cast(_value);
  14056. return val === null || val.valueOf() >= min.valueOf();
  14057. },
  14058. message: msg,
  14059. type: 'min',
  14060. min: value
  14061. });
  14062. }
  14063. return this;
  14064. };
  14065. /**
  14066. * Sets a maximum date validator.
  14067. *
  14068. * #### Example:
  14069. *
  14070. * const s = new Schema({ d: { type: Date, max: Date('2014-01-01') })
  14071. * const M = db.model('M', s)
  14072. * const m = new M({ d: Date('2014-12-08') })
  14073. * m.save(function (err) {
  14074. * console.error(err) // validator error
  14075. * m.d = Date('2013-12-31');
  14076. * m.save() // success
  14077. * })
  14078. *
  14079. * // custom error messages
  14080. * // We can also use the special {MAX} token which will be replaced with the invalid value
  14081. * const max = [Date('2014-01-01'), 'The value of path `{PATH}` ({VALUE}) exceeds the limit ({MAX}).'];
  14082. * const schema = new Schema({ d: { type: Date, max: max })
  14083. * const M = mongoose.model('M', schema);
  14084. * const s= new M({ d: Date('2014-12-08') });
  14085. * s.validate(function (err) {
  14086. * console.log(String(err)) // ValidationError: The value of path `d` (2014-12-08) exceeds the limit (2014-01-01).
  14087. * })
  14088. *
  14089. * @param {Date} maximum date
  14090. * @param {String} [message] optional custom error message
  14091. * @return {SchemaType} this
  14092. * @see Customized Error Messages #error_messages_MongooseError-messages
  14093. * @api public
  14094. */
  14095. SchemaDate.prototype.max = function (value, message) {
  14096. if (this.maxValidator) {
  14097. this.validators = this.validators.filter(function (v) {
  14098. return v.validator !== this.maxValidator;
  14099. }, this);
  14100. }
  14101. if (value) {
  14102. var msg = message || MongooseError.messages.Date.max;
  14103. if (typeof msg === 'string') {
  14104. msg = msg.replace(/{MAX}/, value === Date.now ? 'Date.now()' : value.toString());
  14105. }
  14106. var _this = this;
  14107. this.validators.push({
  14108. validator: this.maxValidator = function (val) {
  14109. var _value = value;
  14110. if (typeof _value === 'function' && _value !== Date.now) {
  14111. _value = _value.call(this);
  14112. }
  14113. var max = _value === Date.now ? _value() : _this.cast(_value);
  14114. return val === null || val.valueOf() <= max.valueOf();
  14115. },
  14116. message: msg,
  14117. type: 'max',
  14118. max: value
  14119. });
  14120. }
  14121. return this;
  14122. };
  14123. /**
  14124. * Casts to date
  14125. *
  14126. * @param {Object} value to cast
  14127. * @api private
  14128. */
  14129. SchemaDate.prototype.cast = function (value) {
  14130. var castDate;
  14131. if (typeof this._castFunction === 'function') {
  14132. castDate = this._castFunction;
  14133. } else if (typeof this.constructor.cast === 'function') {
  14134. castDate = this.constructor.cast();
  14135. } else {
  14136. castDate = SchemaDate.cast();
  14137. }
  14138. try {
  14139. return castDate(value);
  14140. } catch (error) {
  14141. throw new CastError('date', value, this.path, error, this);
  14142. }
  14143. };
  14144. /*!
  14145. * Date Query casting.
  14146. *
  14147. * @api private
  14148. */
  14149. function handleSingle(val) {
  14150. return this.cast(val);
  14151. }
  14152. SchemaDate.prototype.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  14153. $gt: handleSingle,
  14154. $gte: handleSingle,
  14155. $lt: handleSingle,
  14156. $lte: handleSingle
  14157. });
  14158. /**
  14159. * Casts contents for queries.
  14160. *
  14161. * @param {String} $conditional
  14162. * @param {any} [value]
  14163. * @api private
  14164. */
  14165. SchemaDate.prototype.castForQuery = function ($conditional, val) {
  14166. if (arguments.length !== 2) {
  14167. return this._castForQuery($conditional);
  14168. }
  14169. var handler = this.$conditionalHandlers[$conditional];
  14170. if (!handler) {
  14171. throw new Error('Can\'t use ' + $conditional + ' with Date.');
  14172. }
  14173. return handler.call(this, val);
  14174. };
  14175. /*!
  14176. * Module exports.
  14177. */
  14178. module.exports = SchemaDate;
  14179. /***/ }),
  14180. /***/ 6621:
  14181. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  14182. "use strict";
  14183. /*!
  14184. * Module dependencies.
  14185. */
  14186. var SchemaType = __webpack_require__(4289);
  14187. var CastError = SchemaType.CastError;
  14188. var castDecimal128 = __webpack_require__(6209);
  14189. var utils = __webpack_require__(6872);
  14190. var isBsonType = __webpack_require__(1563);
  14191. /**
  14192. * Decimal128 SchemaType constructor.
  14193. *
  14194. * @param {String} key
  14195. * @param {Object} options
  14196. * @inherits SchemaType
  14197. * @api public
  14198. */
  14199. function Decimal128(key, options) {
  14200. SchemaType.call(this, key, options, 'Decimal128');
  14201. }
  14202. /**
  14203. * This schema type's name, to defend against minifiers that mangle
  14204. * function names.
  14205. *
  14206. * @api public
  14207. */
  14208. Decimal128.schemaName = 'Decimal128';
  14209. Decimal128.defaultOptions = {};
  14210. /*!
  14211. * Inherits from SchemaType.
  14212. */
  14213. Decimal128.prototype = Object.create(SchemaType.prototype);
  14214. Decimal128.prototype.constructor = Decimal128;
  14215. /*!
  14216. * ignore
  14217. */
  14218. Decimal128._cast = castDecimal128;
  14219. /**
  14220. * Sets a default option for all Decimal128 instances.
  14221. *
  14222. * #### Example:
  14223. *
  14224. * // Make all decimal 128s have `required` of true by default.
  14225. * mongoose.Schema.Decimal128.set('required', true);
  14226. *
  14227. * const User = mongoose.model('User', new Schema({ test: mongoose.Decimal128 }));
  14228. * new User({ }).validateSync().errors.test.message; // Path `test` is required.
  14229. *
  14230. * @param {String} option - The option you'd like to set the value for
  14231. * @param {*} value - value for option
  14232. * @return {undefined}
  14233. * @function set
  14234. * @static
  14235. * @api public
  14236. */
  14237. Decimal128.set = SchemaType.set;
  14238. /**
  14239. * Get/set the function used to cast arbitrary values to decimals.
  14240. *
  14241. * #### Example:
  14242. *
  14243. * // Make Mongoose only refuse to cast numbers as decimal128
  14244. * const original = mongoose.Schema.Types.Decimal128.cast();
  14245. * mongoose.Decimal128.cast(v => {
  14246. * assert.ok(typeof v !== 'number');
  14247. * return original(v);
  14248. * });
  14249. *
  14250. * // Or disable casting entirely
  14251. * mongoose.Decimal128.cast(false);
  14252. *
  14253. * @param {Function} [caster]
  14254. * @return {Function}
  14255. * @function get
  14256. * @static
  14257. * @api public
  14258. */
  14259. Decimal128.cast = function cast(caster) {
  14260. if (arguments.length === 0) {
  14261. return this._cast;
  14262. }
  14263. if (caster === false) {
  14264. caster = this._defaultCaster;
  14265. }
  14266. this._cast = caster;
  14267. return this._cast;
  14268. };
  14269. /*!
  14270. * ignore
  14271. */
  14272. Decimal128._defaultCaster = function (v) {
  14273. if (v != null && !isBsonType(v, 'Decimal128')) {
  14274. throw new Error();
  14275. }
  14276. return v;
  14277. };
  14278. /*!
  14279. * ignore
  14280. */
  14281. Decimal128._checkRequired = function (v) {
  14282. return isBsonType(v, 'Decimal128');
  14283. };
  14284. /**
  14285. * Override the function the required validator uses to check whether a string
  14286. * passes the `required` check.
  14287. *
  14288. * @param {Function} fn
  14289. * @return {Function}
  14290. * @function checkRequired
  14291. * @static
  14292. * @api public
  14293. */
  14294. Decimal128.checkRequired = SchemaType.checkRequired;
  14295. /**
  14296. * Check if the given value satisfies a required validator.
  14297. *
  14298. * @param {Any} value
  14299. * @param {Document} doc
  14300. * @return {Boolean}
  14301. * @api public
  14302. */
  14303. Decimal128.prototype.checkRequired = function checkRequired(value, doc) {
  14304. if (SchemaType._isRef(this, value, doc, true)) {
  14305. return !!value;
  14306. } // `require('util').inherits()` does **not** copy static properties, and
  14307. // plugins like mongoose-float use `inherits()` for pre-ES6.
  14308. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : Decimal128.checkRequired();
  14309. return _checkRequired(value);
  14310. };
  14311. /**
  14312. * Casts to Decimal128
  14313. *
  14314. * @param {Object} value
  14315. * @param {Object} doc
  14316. * @param {Boolean} init whether this is an initialization cast
  14317. * @api private
  14318. */
  14319. Decimal128.prototype.cast = function (value, doc, init) {
  14320. if (SchemaType._isRef(this, value, doc, init)) {
  14321. if (isBsonType(value, 'Decimal128')) {
  14322. return value;
  14323. }
  14324. return this._castRef(value, doc, init);
  14325. }
  14326. var castDecimal128;
  14327. if (typeof this._castFunction === 'function') {
  14328. castDecimal128 = this._castFunction;
  14329. } else if (typeof this.constructor.cast === 'function') {
  14330. castDecimal128 = this.constructor.cast();
  14331. } else {
  14332. castDecimal128 = Decimal128.cast();
  14333. }
  14334. try {
  14335. return castDecimal128(value);
  14336. } catch (error) {
  14337. throw new CastError('Decimal128', value, this.path, error, this);
  14338. }
  14339. };
  14340. /*!
  14341. * ignore
  14342. */
  14343. function handleSingle(val) {
  14344. return this.cast(val);
  14345. }
  14346. Decimal128.prototype.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  14347. $gt: handleSingle,
  14348. $gte: handleSingle,
  14349. $lt: handleSingle,
  14350. $lte: handleSingle
  14351. });
  14352. /*!
  14353. * Module exports.
  14354. */
  14355. module.exports = Decimal128;
  14356. /***/ }),
  14357. /***/ 4504:
  14358. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  14359. "use strict";
  14360. /*!
  14361. * Module dependencies.
  14362. */
  14363. var ArrayType = __webpack_require__(94);
  14364. var CastError = __webpack_require__(1795);
  14365. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  14366. var SchemaDocumentArrayOptions = __webpack_require__(887);
  14367. var SchemaType = __webpack_require__(4289);
  14368. var SubdocumentPath = __webpack_require__(3617);
  14369. var discriminator = __webpack_require__(9181);
  14370. var handleIdOption = __webpack_require__(9691);
  14371. var handleSpreadDoc = __webpack_require__(719);
  14372. var utils = __webpack_require__(6872);
  14373. var getConstructor = __webpack_require__(8413);
  14374. var arrayAtomicsSymbol = (__webpack_require__(8770).arrayAtomicsSymbol);
  14375. var arrayPathSymbol = (__webpack_require__(8770).arrayPathSymbol);
  14376. var documentArrayParent = (__webpack_require__(8770).documentArrayParent);
  14377. var MongooseDocumentArray;
  14378. var Subdocument;
  14379. /**
  14380. * SubdocsArray SchemaType constructor
  14381. *
  14382. * @param {String} key
  14383. * @param {Schema} schema
  14384. * @param {Object} options
  14385. * @param {Object} schemaOptions
  14386. * @inherits SchemaArray
  14387. * @api public
  14388. */
  14389. function DocumentArrayPath(key, schema, options, schemaOptions) {
  14390. if (schemaOptions != null && schemaOptions._id != null) {
  14391. schema = handleIdOption(schema, schemaOptions);
  14392. } else if (options != null && options._id != null) {
  14393. schema = handleIdOption(schema, options);
  14394. }
  14395. var EmbeddedDocument = _createConstructor(schema, options);
  14396. EmbeddedDocument.prototype.$basePath = key;
  14397. ArrayType.call(this, key, EmbeddedDocument, options);
  14398. this.schema = schema;
  14399. this.schemaOptions = schemaOptions || {};
  14400. this.$isMongooseDocumentArray = true;
  14401. this.Constructor = EmbeddedDocument;
  14402. EmbeddedDocument.base = schema.base;
  14403. var fn = this.defaultValue;
  14404. if (!('defaultValue' in this) || fn !== void 0) {
  14405. this["default"](function () {
  14406. var arr = fn.call(this);
  14407. if (arr != null && !Array.isArray(arr)) {
  14408. arr = [arr];
  14409. } // Leave it up to `cast()` to convert this to a documentarray
  14410. return arr;
  14411. });
  14412. }
  14413. var parentSchemaType = this;
  14414. this.$embeddedSchemaType = new SchemaType(key + '.$', {
  14415. required: this && this.schemaOptions && this.schemaOptions.required || false
  14416. });
  14417. this.$embeddedSchemaType.cast = function (value, doc, init) {
  14418. return parentSchemaType.cast(value, doc, init)[0];
  14419. };
  14420. this.$embeddedSchemaType.doValidate = function (value, fn, scope, options) {
  14421. var Constructor = getConstructor(this.caster, value);
  14422. if (value && !(value instanceof Constructor)) {
  14423. value = new Constructor(value, scope, null, null, options && options.index != null ? options.index : null);
  14424. }
  14425. return SubdocumentPath.prototype.doValidate.call(this, value, fn, scope, options);
  14426. };
  14427. this.$embeddedSchemaType.$isMongooseDocumentArrayElement = true;
  14428. this.$embeddedSchemaType.caster = this.Constructor;
  14429. this.$embeddedSchemaType.schema = this.schema;
  14430. }
  14431. /**
  14432. * This schema type's name, to defend against minifiers that mangle
  14433. * function names.
  14434. *
  14435. * @api public
  14436. */
  14437. DocumentArrayPath.schemaName = 'DocumentArray';
  14438. /**
  14439. * Options for all document arrays.
  14440. *
  14441. * - `castNonArrays`: `true` by default. If `false`, Mongoose will throw a CastError when a value isn't an array. If `true`, Mongoose will wrap the provided value in an array before casting.
  14442. *
  14443. * @api public
  14444. */
  14445. DocumentArrayPath.options = {
  14446. castNonArrays: true
  14447. };
  14448. /*!
  14449. * Inherits from ArrayType.
  14450. */
  14451. DocumentArrayPath.prototype = Object.create(ArrayType.prototype);
  14452. DocumentArrayPath.prototype.constructor = DocumentArrayPath;
  14453. DocumentArrayPath.prototype.OptionsConstructor = SchemaDocumentArrayOptions;
  14454. /*!
  14455. * Ignore
  14456. */
  14457. function _createConstructor(schema, options, baseClass) {
  14458. Subdocument || (Subdocument = __webpack_require__(1568)); // compile an embedded document for this schema
  14459. function EmbeddedDocument(_value, parentArray) {
  14460. Subdocument.apply(this, arguments);
  14461. if (parentArray == null || parentArray.getArrayParent() == null) {
  14462. return;
  14463. }
  14464. this.$session(parentArray.getArrayParent().$session());
  14465. }
  14466. schema._preCompile();
  14467. var proto = baseClass != null ? baseClass.prototype : Subdocument.prototype;
  14468. EmbeddedDocument.prototype = Object.create(proto);
  14469. EmbeddedDocument.prototype.$__setSchema(schema);
  14470. EmbeddedDocument.schema = schema;
  14471. EmbeddedDocument.prototype.constructor = EmbeddedDocument;
  14472. EmbeddedDocument.$isArraySubdocument = true;
  14473. EmbeddedDocument.events = new EventEmitter(); // apply methods
  14474. for (var i in schema.methods) {
  14475. EmbeddedDocument.prototype[i] = schema.methods[i];
  14476. } // apply statics
  14477. for (var _i in schema.statics) {
  14478. EmbeddedDocument[_i] = schema.statics[_i];
  14479. }
  14480. for (var _i2 in EventEmitter.prototype) {
  14481. EmbeddedDocument[_i2] = EventEmitter.prototype[_i2];
  14482. }
  14483. EmbeddedDocument.options = options;
  14484. return EmbeddedDocument;
  14485. }
  14486. /**
  14487. * Adds a discriminator to this document array.
  14488. *
  14489. * #### Example:
  14490. * const shapeSchema = Schema({ name: String }, { discriminatorKey: 'kind' });
  14491. * const schema = Schema({ shapes: [shapeSchema] });
  14492. *
  14493. * const docArrayPath = parentSchema.path('shapes');
  14494. * docArrayPath.discriminator('Circle', Schema({ radius: Number }));
  14495. *
  14496. * @param {String} name
  14497. * @param {Schema} schema fields to add to the schema for instances of this sub-class
  14498. * @param {Object|string} [options] If string, same as `options.value`.
  14499. * @param {String} [options.value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
  14500. * @param {Boolean} [options.clone=true] By default, `discriminator()` clones the given `schema`. Set to `false` to skip cloning.
  14501. * @see discriminators /docs/discriminators.html
  14502. * @return {Function} the constructor Mongoose will use for creating instances of this discriminator model
  14503. * @api public
  14504. */
  14505. DocumentArrayPath.prototype.discriminator = function (name, schema, options) {
  14506. if (typeof name === 'function') {
  14507. name = utils.getFunctionName(name);
  14508. }
  14509. options = options || {};
  14510. var tiedValue = utils.isPOJO(options) ? options.value : options;
  14511. var clone = typeof options.clone === 'boolean' ? options.clone : true;
  14512. if (schema.instanceOfSchema && clone) {
  14513. schema = schema.clone();
  14514. }
  14515. schema = discriminator(this.casterConstructor, name, schema, tiedValue);
  14516. var EmbeddedDocument = _createConstructor(schema, null, this.casterConstructor);
  14517. EmbeddedDocument.baseCasterConstructor = this.casterConstructor;
  14518. try {
  14519. Object.defineProperty(EmbeddedDocument, 'name', {
  14520. value: name
  14521. });
  14522. } catch (error) {// Ignore error, only happens on old versions of node
  14523. }
  14524. this.casterConstructor.discriminators[name] = EmbeddedDocument;
  14525. return this.casterConstructor.discriminators[name];
  14526. };
  14527. /**
  14528. * Performs local validations first, then validations on each embedded doc
  14529. *
  14530. * @api private
  14531. */
  14532. DocumentArrayPath.prototype.doValidate = function (array, fn, scope, options) {
  14533. // lazy load
  14534. MongooseDocumentArray || (MongooseDocumentArray = __webpack_require__(6077));
  14535. var _this = this;
  14536. try {
  14537. SchemaType.prototype.doValidate.call(this, array, cb, scope);
  14538. } catch (err) {
  14539. return fn(err);
  14540. }
  14541. function cb(err) {
  14542. if (err) {
  14543. return fn(err);
  14544. }
  14545. var count = array && array.length;
  14546. var error;
  14547. if (!count) {
  14548. return fn();
  14549. }
  14550. if (options && options.updateValidator) {
  14551. return fn();
  14552. }
  14553. if (!utils.isMongooseDocumentArray(array)) {
  14554. array = new MongooseDocumentArray(array, _this.path, scope);
  14555. } // handle sparse arrays, do not use array.forEach which does not
  14556. // iterate over sparse elements yet reports array.length including
  14557. // them :(
  14558. function callback(err) {
  14559. if (err != null) {
  14560. error = err;
  14561. }
  14562. --count || fn(error);
  14563. }
  14564. for (var i = 0, len = count; i < len; ++i) {
  14565. // sidestep sparse entries
  14566. var doc = array[i];
  14567. if (doc == null) {
  14568. --count || fn(error);
  14569. continue;
  14570. } // If you set the array index directly, the doc might not yet be
  14571. // a full fledged mongoose subdoc, so make it into one.
  14572. if (!(doc instanceof Subdocument)) {
  14573. var Constructor = getConstructor(_this.casterConstructor, array[i]);
  14574. doc = array[i] = new Constructor(doc, array, undefined, undefined, i);
  14575. }
  14576. if (options != null && options.validateModifiedOnly && !doc.$isModified()) {
  14577. --count || fn(error);
  14578. continue;
  14579. }
  14580. doc.$__validate(callback);
  14581. }
  14582. }
  14583. };
  14584. /**
  14585. * Performs local validations first, then validations on each embedded doc.
  14586. *
  14587. * #### Note:
  14588. *
  14589. * This method ignores the asynchronous validators.
  14590. *
  14591. * @return {MongooseError|undefined}
  14592. * @api private
  14593. */
  14594. DocumentArrayPath.prototype.doValidateSync = function (array, scope, options) {
  14595. var schemaTypeError = SchemaType.prototype.doValidateSync.call(this, array, scope);
  14596. if (schemaTypeError != null) {
  14597. return schemaTypeError;
  14598. }
  14599. var count = array && array.length;
  14600. var resultError = null;
  14601. if (!count) {
  14602. return;
  14603. } // handle sparse arrays, do not use array.forEach which does not
  14604. // iterate over sparse elements yet reports array.length including
  14605. // them :(
  14606. for (var i = 0, len = count; i < len; ++i) {
  14607. // sidestep sparse entries
  14608. var doc = array[i];
  14609. if (!doc) {
  14610. continue;
  14611. } // If you set the array index directly, the doc might not yet be
  14612. // a full fledged mongoose subdoc, so make it into one.
  14613. if (!(doc instanceof Subdocument)) {
  14614. var Constructor = getConstructor(this.casterConstructor, array[i]);
  14615. doc = array[i] = new Constructor(doc, array, undefined, undefined, i);
  14616. }
  14617. if (options != null && options.validateModifiedOnly && !doc.$isModified()) {
  14618. continue;
  14619. }
  14620. var subdocValidateError = doc.validateSync();
  14621. if (subdocValidateError && resultError == null) {
  14622. resultError = subdocValidateError;
  14623. }
  14624. }
  14625. return resultError;
  14626. };
  14627. /*!
  14628. * ignore
  14629. */
  14630. DocumentArrayPath.prototype.getDefault = function (scope) {
  14631. var ret = typeof this.defaultValue === 'function' ? this.defaultValue.call(scope) : this.defaultValue;
  14632. if (ret == null) {
  14633. return ret;
  14634. } // lazy load
  14635. MongooseDocumentArray || (MongooseDocumentArray = __webpack_require__(6077));
  14636. if (!Array.isArray(ret)) {
  14637. ret = [ret];
  14638. }
  14639. ret = new MongooseDocumentArray(ret, this.path, scope);
  14640. for (var i = 0; i < ret.length; ++i) {
  14641. var Constructor = getConstructor(this.casterConstructor, ret[i]);
  14642. var _subdoc = new Constructor({}, ret, undefined, undefined, i);
  14643. _subdoc.$init(ret[i]);
  14644. _subdoc.isNew = true; // Make sure all paths in the subdoc are set to `default` instead
  14645. // of `init` since we used `init`.
  14646. Object.assign(_subdoc.$__.activePaths["default"], _subdoc.$__.activePaths.init);
  14647. _subdoc.$__.activePaths.init = {};
  14648. ret[i] = _subdoc;
  14649. }
  14650. return ret;
  14651. };
  14652. var _toObjectOptions = Object.freeze({
  14653. transform: false,
  14654. virtuals: false
  14655. });
  14656. var initDocumentOptions = Object.freeze({
  14657. skipId: true,
  14658. willInit: true
  14659. });
  14660. /**
  14661. * Casts contents
  14662. *
  14663. * @param {Object} value
  14664. * @param {Document} document that triggers the casting
  14665. * @api private
  14666. */
  14667. DocumentArrayPath.prototype.cast = function (value, doc, init, prev, options) {
  14668. // lazy load
  14669. MongooseDocumentArray || (MongooseDocumentArray = __webpack_require__(6077)); // Skip casting if `value` is the same as the previous value, no need to cast. See gh-9266
  14670. if (value != null && value[arrayPathSymbol] != null && value === prev) {
  14671. return value;
  14672. }
  14673. var selected;
  14674. var subdoc;
  14675. options = options || {};
  14676. if (!Array.isArray(value)) {
  14677. if (!init && !DocumentArrayPath.options.castNonArrays) {
  14678. throw new CastError('DocumentArray', value, this.path, null, this);
  14679. } // gh-2442 mark whole array as modified if we're initializing a doc from
  14680. // the db and the path isn't an array in the document
  14681. if (!!doc && init) {
  14682. doc.markModified(this.path);
  14683. }
  14684. return this.cast([value], doc, init, prev, options);
  14685. } // We need to create a new array, otherwise change tracking will
  14686. // update the old doc (gh-4449)
  14687. if (!options.skipDocumentArrayCast || utils.isMongooseDocumentArray(value)) {
  14688. value = new MongooseDocumentArray(value, this.path, doc);
  14689. }
  14690. if (prev != null) {
  14691. value[arrayAtomicsSymbol] = prev[arrayAtomicsSymbol] || {};
  14692. }
  14693. if (options.arrayPathIndex != null) {
  14694. value[arrayPathSymbol] = this.path + '.' + options.arrayPathIndex;
  14695. }
  14696. var rawArray = utils.isMongooseDocumentArray(value) ? value.__array : value;
  14697. var len = rawArray.length;
  14698. for (var i = 0; i < len; ++i) {
  14699. if (!rawArray[i]) {
  14700. continue;
  14701. }
  14702. var Constructor = getConstructor(this.casterConstructor, rawArray[i]); // Check if the document has a different schema (re gh-3701)
  14703. if (rawArray[i].$__ != null && !(rawArray[i] instanceof Constructor)) {
  14704. var spreadDoc = handleSpreadDoc(rawArray[i], true);
  14705. if (rawArray[i] !== spreadDoc) {
  14706. rawArray[i] = spreadDoc;
  14707. } else {
  14708. rawArray[i] = rawArray[i].toObject({
  14709. transform: false,
  14710. // Special case: if different model, but same schema, apply virtuals
  14711. // re: gh-7898
  14712. virtuals: rawArray[i].schema === Constructor.schema
  14713. });
  14714. }
  14715. }
  14716. if (rawArray[i] instanceof Subdocument) {
  14717. if (rawArray[i][documentArrayParent] !== doc) {
  14718. if (init) {
  14719. var _subdoc2 = new Constructor(null, value, initDocumentOptions, selected, i);
  14720. rawArray[i] = _subdoc2.$init(rawArray[i]);
  14721. } else {
  14722. var _subdoc3 = new Constructor(rawArray[i], value, undefined, undefined, i);
  14723. rawArray[i] = _subdoc3;
  14724. }
  14725. } // Might not have the correct index yet, so ensure it does.
  14726. if (rawArray[i].__index == null) {
  14727. rawArray[i].$setIndex(i);
  14728. }
  14729. } else if (rawArray[i] != null) {
  14730. if (init) {
  14731. if (doc) {
  14732. selected || (selected = scopePaths(this, doc.$__.selected, init));
  14733. } else {
  14734. selected = true;
  14735. }
  14736. subdoc = new Constructor(null, value, initDocumentOptions, selected, i);
  14737. rawArray[i] = subdoc.$init(rawArray[i]);
  14738. } else {
  14739. if (prev && typeof prev.id === 'function') {
  14740. subdoc = prev.id(rawArray[i]._id);
  14741. }
  14742. if (prev && subdoc && utils.deepEqual(subdoc.toObject(_toObjectOptions), rawArray[i])) {
  14743. // handle resetting doc with existing id and same data
  14744. subdoc.set(rawArray[i]); // if set() is hooked it will have no return value
  14745. // see gh-746
  14746. rawArray[i] = subdoc;
  14747. } else {
  14748. try {
  14749. subdoc = new Constructor(rawArray[i], value, undefined, undefined, i); // if set() is hooked it will have no return value
  14750. // see gh-746
  14751. rawArray[i] = subdoc;
  14752. } catch (error) {
  14753. throw new CastError('embedded', rawArray[i], value[arrayPathSymbol], error, this);
  14754. }
  14755. }
  14756. }
  14757. }
  14758. }
  14759. return value;
  14760. };
  14761. /*!
  14762. * ignore
  14763. */
  14764. DocumentArrayPath.prototype.clone = function () {
  14765. var options = Object.assign({}, this.options);
  14766. var schematype = new this.constructor(this.path, this.schema, options, this.schemaOptions);
  14767. schematype.validators = this.validators.slice();
  14768. if (this.requiredValidator !== undefined) {
  14769. schematype.requiredValidator = this.requiredValidator;
  14770. }
  14771. schematype.Constructor.discriminators = Object.assign({}, this.Constructor.discriminators);
  14772. return schematype;
  14773. };
  14774. /*!
  14775. * ignore
  14776. */
  14777. DocumentArrayPath.prototype.applyGetters = function (value, scope) {
  14778. return SchemaType.prototype.applyGetters.call(this, value, scope);
  14779. };
  14780. /*!
  14781. * Scopes paths selected in a query to this array.
  14782. * Necessary for proper default application of subdocument values.
  14783. *
  14784. * @param {DocumentArrayPath} array - the array to scope `fields` paths
  14785. * @param {Object|undefined} fields - the root fields selected in the query
  14786. * @param {Boolean|undefined} init - if we are being created part of a query result
  14787. */
  14788. function scopePaths(array, fields, init) {
  14789. if (!(init && fields)) {
  14790. return undefined;
  14791. }
  14792. var path = array.path + '.';
  14793. var keys = Object.keys(fields);
  14794. var i = keys.length;
  14795. var selected = {};
  14796. var hasKeys;
  14797. var key;
  14798. var sub;
  14799. while (i--) {
  14800. key = keys[i];
  14801. if (key.startsWith(path)) {
  14802. sub = key.substring(path.length);
  14803. if (sub === '$') {
  14804. continue;
  14805. }
  14806. if (sub.startsWith('$.')) {
  14807. sub = sub.substring(2);
  14808. }
  14809. hasKeys || (hasKeys = true);
  14810. selected[sub] = fields[key];
  14811. }
  14812. }
  14813. return hasKeys && selected || undefined;
  14814. }
  14815. /**
  14816. * Sets a default option for all DocumentArray instances.
  14817. *
  14818. * #### Example:
  14819. *
  14820. * // Make all numbers have option `min` equal to 0.
  14821. * mongoose.Schema.DocumentArray.set('_id', false);
  14822. *
  14823. * @param {String} option - The option you'd like to set the value for
  14824. * @param {*} value - value for option
  14825. * @return {undefined}
  14826. * @function set
  14827. * @static
  14828. * @api public
  14829. */
  14830. DocumentArrayPath.defaultOptions = {};
  14831. DocumentArrayPath.set = SchemaType.set;
  14832. /*!
  14833. * Module exports.
  14834. */
  14835. module.exports = DocumentArrayPath;
  14836. /***/ }),
  14837. /***/ 5251:
  14838. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  14839. "use strict";
  14840. /*!
  14841. * Module exports.
  14842. */
  14843. exports.String = __webpack_require__(6542);
  14844. exports.Number = __webpack_require__(1751);
  14845. exports.Boolean = __webpack_require__(6470);
  14846. exports.DocumentArray = __webpack_require__(4504);
  14847. exports.Subdocument = __webpack_require__(3617);
  14848. exports.Array = __webpack_require__(94);
  14849. exports.Buffer = __webpack_require__(8800);
  14850. exports.Date = __webpack_require__(6535);
  14851. exports.ObjectId = __webpack_require__(7116);
  14852. exports.Mixed = __webpack_require__(3861);
  14853. exports.Decimal128 = exports.Decimal = __webpack_require__(6621);
  14854. exports.Map = __webpack_require__(71); // alias
  14855. exports.Oid = exports.ObjectId;
  14856. exports.Object = exports.Mixed;
  14857. exports.Bool = exports.Boolean;
  14858. exports.ObjectID = exports.ObjectId;
  14859. /***/ }),
  14860. /***/ 71:
  14861. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  14862. "use strict";
  14863. /*!
  14864. * ignore
  14865. */
  14866. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  14867. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  14868. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  14869. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  14870. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14871. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  14872. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  14873. function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
  14874. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  14875. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  14876. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  14877. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14878. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  14879. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  14880. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  14881. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  14882. var MongooseMap = __webpack_require__(3828);
  14883. var SchemaMapOptions = __webpack_require__(8227);
  14884. var SchemaType = __webpack_require__(4289);
  14885. /*!
  14886. * ignore
  14887. */
  14888. var Map = /*#__PURE__*/function (_SchemaType) {
  14889. _inherits(Map, _SchemaType);
  14890. var _super = _createSuper(Map);
  14891. function Map(key, options) {
  14892. var _this;
  14893. _classCallCheck(this, Map);
  14894. _this = _super.call(this, key, options, 'Map');
  14895. _this.$isSchemaMap = true;
  14896. return _this;
  14897. }
  14898. _createClass(Map, [{
  14899. key: "set",
  14900. value: function set(option, value) {
  14901. return SchemaType.set(option, value);
  14902. }
  14903. }, {
  14904. key: "cast",
  14905. value: function cast(val, doc, init) {
  14906. if (val instanceof MongooseMap) {
  14907. return val;
  14908. }
  14909. var path = this.path;
  14910. if (init) {
  14911. var map = new MongooseMap({}, path, doc, this.$__schemaType);
  14912. if (val instanceof __webpack_require__.g.Map) {
  14913. var _iterator = _createForOfIteratorHelper(val.keys()),
  14914. _step;
  14915. try {
  14916. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  14917. var key = _step.value;
  14918. var _val = val.get(key);
  14919. if (_val == null) {
  14920. _val = map.$__schemaType._castNullish(_val);
  14921. } else {
  14922. _val = map.$__schemaType.cast(_val, doc, true, null, {
  14923. path: path + '.' + key
  14924. });
  14925. }
  14926. map.$init(key, _val);
  14927. }
  14928. } catch (err) {
  14929. _iterator.e(err);
  14930. } finally {
  14931. _iterator.f();
  14932. }
  14933. } else {
  14934. for (var _i = 0, _Object$keys = Object.keys(val); _i < _Object$keys.length; _i++) {
  14935. var _key = _Object$keys[_i];
  14936. var _val2 = val[_key];
  14937. if (_val2 == null) {
  14938. _val2 = map.$__schemaType._castNullish(_val2);
  14939. } else {
  14940. _val2 = map.$__schemaType.cast(_val2, doc, true, null, {
  14941. path: path + '.' + _key
  14942. });
  14943. }
  14944. map.$init(_key, _val2);
  14945. }
  14946. }
  14947. return map;
  14948. }
  14949. return new MongooseMap(val, path, doc, this.$__schemaType);
  14950. }
  14951. }, {
  14952. key: "clone",
  14953. value: function clone() {
  14954. var schematype = _get(_getPrototypeOf(Map.prototype), "clone", this).call(this);
  14955. if (this.$__schemaType != null) {
  14956. schematype.$__schemaType = this.$__schemaType.clone();
  14957. }
  14958. return schematype;
  14959. }
  14960. }]);
  14961. return Map;
  14962. }(SchemaType);
  14963. /**
  14964. * This schema type's name, to defend against minifiers that mangle
  14965. * function names.
  14966. *
  14967. * @api public
  14968. */
  14969. Map.schemaName = 'Map';
  14970. Map.prototype.OptionsConstructor = SchemaMapOptions;
  14971. Map.defaultOptions = {};
  14972. module.exports = Map;
  14973. /***/ }),
  14974. /***/ 3861:
  14975. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  14976. "use strict";
  14977. /*!
  14978. * Module dependencies.
  14979. */
  14980. var SchemaType = __webpack_require__(4289);
  14981. var symbols = __webpack_require__(8107);
  14982. var isObject = __webpack_require__(5721);
  14983. var utils = __webpack_require__(6872);
  14984. /**
  14985. * Mixed SchemaType constructor.
  14986. *
  14987. * @param {String} path
  14988. * @param {Object} options
  14989. * @inherits SchemaType
  14990. * @api public
  14991. */
  14992. function Mixed(path, options) {
  14993. if (options && options["default"]) {
  14994. var def = options["default"];
  14995. if (Array.isArray(def) && def.length === 0) {
  14996. // make sure empty array defaults are handled
  14997. options["default"] = Array;
  14998. } else if (!options.shared && isObject(def) && Object.keys(def).length === 0) {
  14999. // prevent odd "shared" objects between documents
  15000. options["default"] = function () {
  15001. return {};
  15002. };
  15003. }
  15004. }
  15005. SchemaType.call(this, path, options, 'Mixed');
  15006. this[symbols.schemaMixedSymbol] = true;
  15007. }
  15008. /**
  15009. * This schema type's name, to defend against minifiers that mangle
  15010. * function names.
  15011. *
  15012. * @api public
  15013. */
  15014. Mixed.schemaName = 'Mixed';
  15015. Mixed.defaultOptions = {};
  15016. /*!
  15017. * Inherits from SchemaType.
  15018. */
  15019. Mixed.prototype = Object.create(SchemaType.prototype);
  15020. Mixed.prototype.constructor = Mixed;
  15021. /**
  15022. * Attaches a getter for all Mixed paths.
  15023. *
  15024. * #### Example:
  15025. *
  15026. * // Hide the 'hidden' path
  15027. * mongoose.Schema.Mixed.get(v => Object.assign({}, v, { hidden: null }));
  15028. *
  15029. * const Model = mongoose.model('Test', new Schema({ test: {} }));
  15030. * new Model({ test: { hidden: 'Secret!' } }).test.hidden; // null
  15031. *
  15032. * @param {Function} getter
  15033. * @return {this}
  15034. * @function get
  15035. * @static
  15036. * @api public
  15037. */
  15038. Mixed.get = SchemaType.get;
  15039. /**
  15040. * Sets a default option for all Mixed instances.
  15041. *
  15042. * #### Example:
  15043. *
  15044. * // Make all mixed instances have `required` of true by default.
  15045. * mongoose.Schema.Mixed.set('required', true);
  15046. *
  15047. * const User = mongoose.model('User', new Schema({ test: mongoose.Mixed }));
  15048. * new User({ }).validateSync().errors.test.message; // Path `test` is required.
  15049. *
  15050. * @param {String} option - The option you'd like to set the value for
  15051. * @param {*} value - value for option
  15052. * @return {undefined}
  15053. * @function set
  15054. * @static
  15055. * @api public
  15056. */
  15057. Mixed.set = SchemaType.set;
  15058. /**
  15059. * Casts `val` for Mixed.
  15060. *
  15061. * _this is a no-op_
  15062. *
  15063. * @param {Object} value to cast
  15064. * @api private
  15065. */
  15066. Mixed.prototype.cast = function (val) {
  15067. if (val instanceof Error) {
  15068. return utils.errorToPOJO(val);
  15069. }
  15070. return val;
  15071. };
  15072. /**
  15073. * Casts contents for queries.
  15074. *
  15075. * @param {String} $cond
  15076. * @param {any} [val]
  15077. * @api private
  15078. */
  15079. Mixed.prototype.castForQuery = function ($cond, val) {
  15080. if (arguments.length === 2) {
  15081. return val;
  15082. }
  15083. return $cond;
  15084. };
  15085. /*!
  15086. * Module exports.
  15087. */
  15088. module.exports = Mixed;
  15089. /***/ }),
  15090. /***/ 1751:
  15091. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15092. "use strict";
  15093. /*!
  15094. * Module requirements.
  15095. */
  15096. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  15097. var MongooseError = __webpack_require__(4888);
  15098. var SchemaNumberOptions = __webpack_require__(8491);
  15099. var SchemaType = __webpack_require__(4289);
  15100. var castNumber = __webpack_require__(3065);
  15101. var handleBitwiseOperator = __webpack_require__(4282);
  15102. var utils = __webpack_require__(6872);
  15103. var CastError = SchemaType.CastError;
  15104. /**
  15105. * Number SchemaType constructor.
  15106. *
  15107. * @param {String} key
  15108. * @param {Object} options
  15109. * @inherits SchemaType
  15110. * @api public
  15111. */
  15112. function SchemaNumber(key, options) {
  15113. SchemaType.call(this, key, options, 'Number');
  15114. }
  15115. /**
  15116. * Attaches a getter for all Number instances.
  15117. *
  15118. * #### Example:
  15119. *
  15120. * // Make all numbers round down
  15121. * mongoose.Number.get(function(v) { return Math.floor(v); });
  15122. *
  15123. * const Model = mongoose.model('Test', new Schema({ test: Number }));
  15124. * new Model({ test: 3.14 }).test; // 3
  15125. *
  15126. * @param {Function} getter
  15127. * @return {this}
  15128. * @function get
  15129. * @static
  15130. * @api public
  15131. */
  15132. SchemaNumber.get = SchemaType.get;
  15133. /**
  15134. * Sets a default option for all Number instances.
  15135. *
  15136. * #### Example:
  15137. *
  15138. * // Make all numbers have option `min` equal to 0.
  15139. * mongoose.Schema.Number.set('min', 0);
  15140. *
  15141. * const Order = mongoose.model('Order', new Schema({ amount: Number }));
  15142. * new Order({ amount: -10 }).validateSync().errors.amount.message; // Path `amount` must be larger than 0.
  15143. *
  15144. * @param {String} option - The option you'd like to set the value for
  15145. * @param {*} value - value for option
  15146. * @return {undefined}
  15147. * @function set
  15148. * @static
  15149. * @api public
  15150. */
  15151. SchemaNumber.set = SchemaType.set;
  15152. /*!
  15153. * ignore
  15154. */
  15155. SchemaNumber._cast = castNumber;
  15156. /**
  15157. * Get/set the function used to cast arbitrary values to numbers.
  15158. *
  15159. * #### Example:
  15160. *
  15161. * // Make Mongoose cast empty strings '' to 0 for paths declared as numbers
  15162. * const original = mongoose.Number.cast();
  15163. * mongoose.Number.cast(v => {
  15164. * if (v === '') { return 0; }
  15165. * return original(v);
  15166. * });
  15167. *
  15168. * // Or disable casting entirely
  15169. * mongoose.Number.cast(false);
  15170. *
  15171. * @param {Function} caster
  15172. * @return {Function}
  15173. * @function get
  15174. * @static
  15175. * @api public
  15176. */
  15177. SchemaNumber.cast = function cast(caster) {
  15178. if (arguments.length === 0) {
  15179. return this._cast;
  15180. }
  15181. if (caster === false) {
  15182. caster = this._defaultCaster;
  15183. }
  15184. this._cast = caster;
  15185. return this._cast;
  15186. };
  15187. /*!
  15188. * ignore
  15189. */
  15190. SchemaNumber._defaultCaster = function (v) {
  15191. if (typeof v !== 'number') {
  15192. throw new Error();
  15193. }
  15194. return v;
  15195. };
  15196. /**
  15197. * This schema type's name, to defend against minifiers that mangle
  15198. * function names.
  15199. *
  15200. * @api public
  15201. */
  15202. SchemaNumber.schemaName = 'Number';
  15203. SchemaNumber.defaultOptions = {};
  15204. /*!
  15205. * Inherits from SchemaType.
  15206. */
  15207. SchemaNumber.prototype = Object.create(SchemaType.prototype);
  15208. SchemaNumber.prototype.constructor = SchemaNumber;
  15209. SchemaNumber.prototype.OptionsConstructor = SchemaNumberOptions;
  15210. /*!
  15211. * ignore
  15212. */
  15213. SchemaNumber._checkRequired = function (v) {
  15214. return typeof v === 'number' || v instanceof Number;
  15215. };
  15216. /**
  15217. * Override the function the required validator uses to check whether a string
  15218. * passes the `required` check.
  15219. *
  15220. * @param {Function} fn
  15221. * @return {Function}
  15222. * @function checkRequired
  15223. * @static
  15224. * @api public
  15225. */
  15226. SchemaNumber.checkRequired = SchemaType.checkRequired;
  15227. /**
  15228. * Check if the given value satisfies a required validator.
  15229. *
  15230. * @param {Any} value
  15231. * @param {Document} doc
  15232. * @return {Boolean}
  15233. * @api public
  15234. */
  15235. SchemaNumber.prototype.checkRequired = function checkRequired(value, doc) {
  15236. if (_typeof(value) === 'object' && SchemaType._isRef(this, value, doc, true)) {
  15237. return value != null;
  15238. } // `require('util').inherits()` does **not** copy static properties, and
  15239. // plugins like mongoose-float use `inherits()` for pre-ES6.
  15240. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : SchemaNumber.checkRequired();
  15241. return _checkRequired(value);
  15242. };
  15243. /**
  15244. * Sets a minimum number validator.
  15245. *
  15246. * #### Example:
  15247. *
  15248. * const s = new Schema({ n: { type: Number, min: 10 })
  15249. * const M = db.model('M', s)
  15250. * const m = new M({ n: 9 })
  15251. * m.save(function (err) {
  15252. * console.error(err) // validator error
  15253. * m.n = 10;
  15254. * m.save() // success
  15255. * })
  15256. *
  15257. * // custom error messages
  15258. * // We can also use the special {MIN} token which will be replaced with the invalid value
  15259. * const min = [10, 'The value of path `{PATH}` ({VALUE}) is beneath the limit ({MIN}).'];
  15260. * const schema = new Schema({ n: { type: Number, min: min })
  15261. * const M = mongoose.model('Measurement', schema);
  15262. * const s= new M({ n: 4 });
  15263. * s.validate(function (err) {
  15264. * console.log(String(err)) // ValidationError: The value of path `n` (4) is beneath the limit (10).
  15265. * })
  15266. *
  15267. * @param {Number} value minimum number
  15268. * @param {String} [message] optional custom error message
  15269. * @return {SchemaType} this
  15270. * @see Customized Error Messages #error_messages_MongooseError-messages
  15271. * @api public
  15272. */
  15273. SchemaNumber.prototype.min = function (value, message) {
  15274. if (this.minValidator) {
  15275. this.validators = this.validators.filter(function (v) {
  15276. return v.validator !== this.minValidator;
  15277. }, this);
  15278. }
  15279. if (value !== null && value !== undefined) {
  15280. var msg = message || MongooseError.messages.Number.min;
  15281. msg = msg.replace(/{MIN}/, value);
  15282. this.validators.push({
  15283. validator: this.minValidator = function (v) {
  15284. return v == null || v >= value;
  15285. },
  15286. message: msg,
  15287. type: 'min',
  15288. min: value
  15289. });
  15290. }
  15291. return this;
  15292. };
  15293. /**
  15294. * Sets a maximum number validator.
  15295. *
  15296. * #### Example:
  15297. *
  15298. * const s = new Schema({ n: { type: Number, max: 10 })
  15299. * const M = db.model('M', s)
  15300. * const m = new M({ n: 11 })
  15301. * m.save(function (err) {
  15302. * console.error(err) // validator error
  15303. * m.n = 10;
  15304. * m.save() // success
  15305. * })
  15306. *
  15307. * // custom error messages
  15308. * // We can also use the special {MAX} token which will be replaced with the invalid value
  15309. * const max = [10, 'The value of path `{PATH}` ({VALUE}) exceeds the limit ({MAX}).'];
  15310. * const schema = new Schema({ n: { type: Number, max: max })
  15311. * const M = mongoose.model('Measurement', schema);
  15312. * const s= new M({ n: 4 });
  15313. * s.validate(function (err) {
  15314. * console.log(String(err)) // ValidationError: The value of path `n` (4) exceeds the limit (10).
  15315. * })
  15316. *
  15317. * @param {Number} maximum number
  15318. * @param {String} [message] optional custom error message
  15319. * @return {SchemaType} this
  15320. * @see Customized Error Messages #error_messages_MongooseError-messages
  15321. * @api public
  15322. */
  15323. SchemaNumber.prototype.max = function (value, message) {
  15324. if (this.maxValidator) {
  15325. this.validators = this.validators.filter(function (v) {
  15326. return v.validator !== this.maxValidator;
  15327. }, this);
  15328. }
  15329. if (value !== null && value !== undefined) {
  15330. var msg = message || MongooseError.messages.Number.max;
  15331. msg = msg.replace(/{MAX}/, value);
  15332. this.validators.push({
  15333. validator: this.maxValidator = function (v) {
  15334. return v == null || v <= value;
  15335. },
  15336. message: msg,
  15337. type: 'max',
  15338. max: value
  15339. });
  15340. }
  15341. return this;
  15342. };
  15343. /**
  15344. * Sets a enum validator
  15345. *
  15346. * #### Example:
  15347. *
  15348. * const s = new Schema({ n: { type: Number, enum: [1, 2, 3] });
  15349. * const M = db.model('M', s);
  15350. *
  15351. * const m = new M({ n: 4 });
  15352. * await m.save(); // throws validation error
  15353. *
  15354. * m.n = 3;
  15355. * await m.save(); // succeeds
  15356. *
  15357. * @param {Array} values allowed values
  15358. * @param {String} [message] optional custom error message
  15359. * @return {SchemaType} this
  15360. * @see Customized Error Messages #error_messages_MongooseError-messages
  15361. * @api public
  15362. */
  15363. SchemaNumber.prototype["enum"] = function (values, message) {
  15364. if (this.enumValidator) {
  15365. this.validators = this.validators.filter(function (v) {
  15366. return v.validator !== this.enumValidator;
  15367. }, this);
  15368. }
  15369. if (!Array.isArray(values)) {
  15370. var isObjectSyntax = utils.isPOJO(values) && values.values != null;
  15371. if (isObjectSyntax) {
  15372. message = values.message;
  15373. values = values.values;
  15374. } else if (typeof values === 'number') {
  15375. values = Array.prototype.slice.call(arguments);
  15376. message = null;
  15377. }
  15378. if (utils.isPOJO(values)) {
  15379. values = Object.values(values);
  15380. }
  15381. message = message || MongooseError.messages.Number["enum"];
  15382. }
  15383. message = message == null ? MongooseError.messages.Number["enum"] : message;
  15384. this.enumValidator = function (v) {
  15385. return v == null || values.indexOf(v) !== -1;
  15386. };
  15387. this.validators.push({
  15388. validator: this.enumValidator,
  15389. message: message,
  15390. type: 'enum',
  15391. enumValues: values
  15392. });
  15393. return this;
  15394. };
  15395. /**
  15396. * Casts to number
  15397. *
  15398. * @param {Object} value value to cast
  15399. * @param {Document} doc document that triggers the casting
  15400. * @param {Boolean} init
  15401. * @api private
  15402. */
  15403. SchemaNumber.prototype.cast = function (value, doc, init) {
  15404. if (typeof value !== 'number' && SchemaType._isRef(this, value, doc, init)) {
  15405. if (value == null || utils.isNonBuiltinObject(value)) {
  15406. return this._castRef(value, doc, init);
  15407. }
  15408. }
  15409. var val = value && typeof value._id !== 'undefined' ? value._id : // documents
  15410. value;
  15411. var castNumber;
  15412. if (typeof this._castFunction === 'function') {
  15413. castNumber = this._castFunction;
  15414. } else if (typeof this.constructor.cast === 'function') {
  15415. castNumber = this.constructor.cast();
  15416. } else {
  15417. castNumber = SchemaNumber.cast();
  15418. }
  15419. try {
  15420. return castNumber(val);
  15421. } catch (err) {
  15422. throw new CastError('Number', val, this.path, err, this);
  15423. }
  15424. };
  15425. /*!
  15426. * ignore
  15427. */
  15428. function handleSingle(val) {
  15429. return this.cast(val);
  15430. }
  15431. function handleArray(val) {
  15432. var _this = this;
  15433. if (!Array.isArray(val)) {
  15434. return [this.cast(val)];
  15435. }
  15436. return val.map(function (m) {
  15437. return _this.cast(m);
  15438. });
  15439. }
  15440. SchemaNumber.prototype.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  15441. $bitsAllClear: handleBitwiseOperator,
  15442. $bitsAnyClear: handleBitwiseOperator,
  15443. $bitsAllSet: handleBitwiseOperator,
  15444. $bitsAnySet: handleBitwiseOperator,
  15445. $gt: handleSingle,
  15446. $gte: handleSingle,
  15447. $lt: handleSingle,
  15448. $lte: handleSingle,
  15449. $mod: handleArray
  15450. });
  15451. /**
  15452. * Casts contents for queries.
  15453. *
  15454. * @param {String} $conditional
  15455. * @param {any} [value]
  15456. * @api private
  15457. */
  15458. SchemaNumber.prototype.castForQuery = function ($conditional, val) {
  15459. var handler;
  15460. if (arguments.length === 2) {
  15461. handler = this.$conditionalHandlers[$conditional];
  15462. if (!handler) {
  15463. throw new CastError('number', val, this.path, null, this);
  15464. }
  15465. return handler.call(this, val);
  15466. }
  15467. val = this._castForQuery($conditional);
  15468. return val;
  15469. };
  15470. /*!
  15471. * Module exports.
  15472. */
  15473. module.exports = SchemaNumber;
  15474. /***/ }),
  15475. /***/ 7116:
  15476. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15477. "use strict";
  15478. /*!
  15479. * Module dependencies.
  15480. */
  15481. var SchemaObjectIdOptions = __webpack_require__(8172);
  15482. var SchemaType = __webpack_require__(4289);
  15483. var castObjectId = __webpack_require__(4731);
  15484. var getConstructorName = __webpack_require__(1981);
  15485. var oid = __webpack_require__(6079);
  15486. var isBsonType = __webpack_require__(1563);
  15487. var utils = __webpack_require__(6872);
  15488. var CastError = SchemaType.CastError;
  15489. var Document;
  15490. /**
  15491. * ObjectId SchemaType constructor.
  15492. *
  15493. * @param {String} key
  15494. * @param {Object} options
  15495. * @inherits SchemaType
  15496. * @api public
  15497. */
  15498. function ObjectId(key, options) {
  15499. var isKeyHexStr = typeof key === 'string' && key.length === 24 && /^[a-f0-9]+$/i.test(key);
  15500. var suppressWarning = options && options.suppressWarning;
  15501. if ((isKeyHexStr || typeof key === 'undefined') && !suppressWarning) {
  15502. utils.warn('mongoose: To create a new ObjectId please try ' + '`Mongoose.Types.ObjectId` instead of using ' + '`Mongoose.Schema.ObjectId`. Set the `suppressWarning` option if ' + 'you\'re trying to create a hex char path in your schema.');
  15503. }
  15504. SchemaType.call(this, key, options, 'ObjectID');
  15505. }
  15506. /**
  15507. * This schema type's name, to defend against minifiers that mangle
  15508. * function names.
  15509. *
  15510. * @api public
  15511. */
  15512. ObjectId.schemaName = 'ObjectId';
  15513. ObjectId.defaultOptions = {};
  15514. /*!
  15515. * Inherits from SchemaType.
  15516. */
  15517. ObjectId.prototype = Object.create(SchemaType.prototype);
  15518. ObjectId.prototype.constructor = ObjectId;
  15519. ObjectId.prototype.OptionsConstructor = SchemaObjectIdOptions;
  15520. /**
  15521. * Attaches a getter for all ObjectId instances
  15522. *
  15523. * #### Example:
  15524. *
  15525. * // Always convert to string when getting an ObjectId
  15526. * mongoose.ObjectId.get(v => v.toString());
  15527. *
  15528. * const Model = mongoose.model('Test', new Schema({}));
  15529. * typeof (new Model({})._id); // 'string'
  15530. *
  15531. * @param {Function} getter
  15532. * @return {this}
  15533. * @function get
  15534. * @static
  15535. * @api public
  15536. */
  15537. ObjectId.get = SchemaType.get;
  15538. /**
  15539. * Sets a default option for all ObjectId instances.
  15540. *
  15541. * #### Example:
  15542. *
  15543. * // Make all object ids have option `required` equal to true.
  15544. * mongoose.Schema.ObjectId.set('required', true);
  15545. *
  15546. * const Order = mongoose.model('Order', new Schema({ userId: ObjectId }));
  15547. * new Order({ }).validateSync().errors.userId.message; // Path `userId` is required.
  15548. *
  15549. * @param {String} option - The option you'd like to set the value for
  15550. * @param {*} value - value for option
  15551. * @return {undefined}
  15552. * @function set
  15553. * @static
  15554. * @api public
  15555. */
  15556. ObjectId.set = SchemaType.set;
  15557. /**
  15558. * Adds an auto-generated ObjectId default if turnOn is true.
  15559. * @param {Boolean} turnOn auto generated ObjectId defaults
  15560. * @api public
  15561. * @return {SchemaType} this
  15562. */
  15563. ObjectId.prototype.auto = function (turnOn) {
  15564. if (turnOn) {
  15565. this["default"](defaultId);
  15566. this.set(resetId);
  15567. }
  15568. return this;
  15569. };
  15570. /*!
  15571. * ignore
  15572. */
  15573. ObjectId._checkRequired = function (v) {
  15574. return isBsonType(v, 'ObjectID');
  15575. };
  15576. /*!
  15577. * ignore
  15578. */
  15579. ObjectId._cast = castObjectId;
  15580. /**
  15581. * Get/set the function used to cast arbitrary values to objectids.
  15582. *
  15583. * #### Example:
  15584. *
  15585. * // Make Mongoose only try to cast length 24 strings. By default, any 12
  15586. * // char string is a valid ObjectId.
  15587. * const original = mongoose.ObjectId.cast();
  15588. * mongoose.ObjectId.cast(v => {
  15589. * assert.ok(typeof v !== 'string' || v.length === 24);
  15590. * return original(v);
  15591. * });
  15592. *
  15593. * // Or disable casting entirely
  15594. * mongoose.ObjectId.cast(false);
  15595. *
  15596. * @param {Function} caster
  15597. * @return {Function}
  15598. * @function get
  15599. * @static
  15600. * @api public
  15601. */
  15602. ObjectId.cast = function cast(caster) {
  15603. if (arguments.length === 0) {
  15604. return this._cast;
  15605. }
  15606. if (caster === false) {
  15607. caster = this._defaultCaster;
  15608. }
  15609. this._cast = caster;
  15610. return this._cast;
  15611. };
  15612. /*!
  15613. * ignore
  15614. */
  15615. ObjectId._defaultCaster = function (v) {
  15616. if (!isBsonType(v, 'ObjectID')) {
  15617. throw new Error(v + ' is not an instance of ObjectId');
  15618. }
  15619. return v;
  15620. };
  15621. /**
  15622. * Override the function the required validator uses to check whether a string
  15623. * passes the `required` check.
  15624. *
  15625. * #### Example:
  15626. *
  15627. * // Allow empty strings to pass `required` check
  15628. * mongoose.Schema.Types.String.checkRequired(v => v != null);
  15629. *
  15630. * const M = mongoose.model({ str: { type: String, required: true } });
  15631. * new M({ str: '' }).validateSync(); // `null`, validation passes!
  15632. *
  15633. * @param {Function} fn
  15634. * @return {Function}
  15635. * @function checkRequired
  15636. * @static
  15637. * @api public
  15638. */
  15639. ObjectId.checkRequired = SchemaType.checkRequired;
  15640. /**
  15641. * Check if the given value satisfies a required validator.
  15642. *
  15643. * @param {Any} value
  15644. * @param {Document} doc
  15645. * @return {Boolean}
  15646. * @api public
  15647. */
  15648. ObjectId.prototype.checkRequired = function checkRequired(value, doc) {
  15649. if (SchemaType._isRef(this, value, doc, true)) {
  15650. return !!value;
  15651. } // `require('util').inherits()` does **not** copy static properties, and
  15652. // plugins like mongoose-float use `inherits()` for pre-ES6.
  15653. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : ObjectId.checkRequired();
  15654. return _checkRequired(value);
  15655. };
  15656. /**
  15657. * Casts to ObjectId
  15658. *
  15659. * @param {Object} value
  15660. * @param {Object} doc
  15661. * @param {Boolean} init whether this is an initialization cast
  15662. * @api private
  15663. */
  15664. ObjectId.prototype.cast = function (value, doc, init) {
  15665. if (!isBsonType(value, 'ObjectID') && SchemaType._isRef(this, value, doc, init)) {
  15666. // wait! we may need to cast this to a document
  15667. if ((getConstructorName(value) || '').toLowerCase() === 'objectid') {
  15668. return new oid(value.toHexString());
  15669. }
  15670. if (value == null || utils.isNonBuiltinObject(value)) {
  15671. return this._castRef(value, doc, init);
  15672. }
  15673. }
  15674. var castObjectId;
  15675. if (typeof this._castFunction === 'function') {
  15676. castObjectId = this._castFunction;
  15677. } else if (typeof this.constructor.cast === 'function') {
  15678. castObjectId = this.constructor.cast();
  15679. } else {
  15680. castObjectId = ObjectId.cast();
  15681. }
  15682. try {
  15683. return castObjectId(value);
  15684. } catch (error) {
  15685. throw new CastError('ObjectId', value, this.path, error, this);
  15686. }
  15687. };
  15688. /*!
  15689. * ignore
  15690. */
  15691. function handleSingle(val) {
  15692. return this.cast(val);
  15693. }
  15694. ObjectId.prototype.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  15695. $gt: handleSingle,
  15696. $gte: handleSingle,
  15697. $lt: handleSingle,
  15698. $lte: handleSingle
  15699. });
  15700. /*!
  15701. * ignore
  15702. */
  15703. function defaultId() {
  15704. return new oid();
  15705. }
  15706. defaultId.$runBeforeSetters = true;
  15707. function resetId(v) {
  15708. Document || (Document = __webpack_require__(8727));
  15709. if (this instanceof Document) {
  15710. if (v === void 0) {
  15711. var _v = new oid();
  15712. return _v;
  15713. }
  15714. }
  15715. return v;
  15716. }
  15717. /*!
  15718. * Module exports.
  15719. */
  15720. module.exports = ObjectId;
  15721. /***/ }),
  15722. /***/ 4282:
  15723. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15724. "use strict";
  15725. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  15726. /*!
  15727. * Module requirements.
  15728. */
  15729. var CastError = __webpack_require__(1795);
  15730. /*!
  15731. * ignore
  15732. */
  15733. function handleBitwiseOperator(val) {
  15734. var _this = this;
  15735. if (Array.isArray(val)) {
  15736. return val.map(function (v) {
  15737. return _castNumber(_this.path, v);
  15738. });
  15739. } else if (Buffer.isBuffer(val)) {
  15740. return val;
  15741. } // Assume trying to cast to number
  15742. return _castNumber(_this.path, val);
  15743. }
  15744. /*!
  15745. * ignore
  15746. */
  15747. function _castNumber(path, num) {
  15748. var v = Number(num);
  15749. if (isNaN(v)) {
  15750. throw new CastError('number', num, path);
  15751. }
  15752. return v;
  15753. }
  15754. module.exports = handleBitwiseOperator;
  15755. /***/ }),
  15756. /***/ 8702:
  15757. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15758. "use strict";
  15759. var castBoolean = __webpack_require__(6670);
  15760. /*!
  15761. * ignore
  15762. */
  15763. module.exports = function (val) {
  15764. var path = this != null ? this.path : null;
  15765. return castBoolean(val, path);
  15766. };
  15767. /***/ }),
  15768. /***/ 5008:
  15769. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15770. "use strict";
  15771. /*!
  15772. * Module requirements.
  15773. */
  15774. var castArraysOfNumbers = (__webpack_require__(1521)/* .castArraysOfNumbers */ .i);
  15775. var castToNumber = (__webpack_require__(1521)/* .castToNumber */ .W);
  15776. /*!
  15777. * ignore
  15778. */
  15779. exports.cast$geoIntersects = cast$geoIntersects;
  15780. exports.cast$near = cast$near;
  15781. exports.cast$within = cast$within;
  15782. function cast$near(val) {
  15783. var SchemaArray = __webpack_require__(94);
  15784. if (Array.isArray(val)) {
  15785. castArraysOfNumbers(val, this);
  15786. return val;
  15787. }
  15788. _castMinMaxDistance(this, val);
  15789. if (val && val.$geometry) {
  15790. return cast$geometry(val, this);
  15791. }
  15792. if (!Array.isArray(val)) {
  15793. throw new TypeError('$near must be either an array or an object ' + 'with a $geometry property');
  15794. }
  15795. return SchemaArray.prototype.castForQuery.call(this, val);
  15796. }
  15797. function cast$geometry(val, self) {
  15798. switch (val.$geometry.type) {
  15799. case 'Polygon':
  15800. case 'LineString':
  15801. case 'Point':
  15802. castArraysOfNumbers(val.$geometry.coordinates, self);
  15803. break;
  15804. default:
  15805. // ignore unknowns
  15806. break;
  15807. }
  15808. _castMinMaxDistance(self, val);
  15809. return val;
  15810. }
  15811. function cast$within(val) {
  15812. var _this = this;
  15813. _castMinMaxDistance(this, val);
  15814. if (val.$box || val.$polygon) {
  15815. var type = val.$box ? '$box' : '$polygon';
  15816. val[type].forEach(function (arr) {
  15817. if (!Array.isArray(arr)) {
  15818. var msg = 'Invalid $within $box argument. ' + 'Expected an array, received ' + arr;
  15819. throw new TypeError(msg);
  15820. }
  15821. arr.forEach(function (v, i) {
  15822. arr[i] = castToNumber.call(_this, v);
  15823. });
  15824. });
  15825. } else if (val.$center || val.$centerSphere) {
  15826. var _type = val.$center ? '$center' : '$centerSphere';
  15827. val[_type].forEach(function (item, i) {
  15828. if (Array.isArray(item)) {
  15829. item.forEach(function (v, j) {
  15830. item[j] = castToNumber.call(_this, v);
  15831. });
  15832. } else {
  15833. val[_type][i] = castToNumber.call(_this, item);
  15834. }
  15835. });
  15836. } else if (val.$geometry) {
  15837. cast$geometry(val, this);
  15838. }
  15839. return val;
  15840. }
  15841. function cast$geoIntersects(val) {
  15842. var geo = val.$geometry;
  15843. if (!geo) {
  15844. return;
  15845. }
  15846. cast$geometry(val, this);
  15847. return val;
  15848. }
  15849. function _castMinMaxDistance(self, val) {
  15850. if (val.$maxDistance) {
  15851. val.$maxDistance = castToNumber.call(self, val.$maxDistance);
  15852. }
  15853. if (val.$minDistance) {
  15854. val.$minDistance = castToNumber.call(self, val.$minDistance);
  15855. }
  15856. }
  15857. /***/ }),
  15858. /***/ 1521:
  15859. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  15860. "use strict";
  15861. /*!
  15862. * Module requirements.
  15863. */
  15864. var SchemaNumber = __webpack_require__(1751);
  15865. /*!
  15866. * @ignore
  15867. */
  15868. exports.W = castToNumber;
  15869. exports.i = castArraysOfNumbers;
  15870. /*!
  15871. * @ignore
  15872. */
  15873. function castToNumber(val) {
  15874. return SchemaNumber.cast()(val);
  15875. }
  15876. function castArraysOfNumbers(arr, self) {
  15877. arr.forEach(function (v, i) {
  15878. if (Array.isArray(v)) {
  15879. castArraysOfNumbers(v, self);
  15880. } else {
  15881. arr[i] = castToNumber.call(self, v);
  15882. }
  15883. });
  15884. }
  15885. /***/ }),
  15886. /***/ 6495:
  15887. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15888. "use strict";
  15889. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  15890. var CastError = __webpack_require__(1795);
  15891. var castBoolean = __webpack_require__(6670);
  15892. var castString = __webpack_require__(2417);
  15893. /*!
  15894. * Casts val to an object suitable for `$text`. Throws an error if the object
  15895. * can't be casted.
  15896. *
  15897. * @param {Any} val value to cast
  15898. * @param {String} [path] path to associate with any errors that occured
  15899. * @return {Object} casted object
  15900. * @see https://docs.mongodb.com/manual/reference/operator/query/text/
  15901. * @api private
  15902. */
  15903. module.exports = function (val, path) {
  15904. if (val == null || _typeof(val) !== 'object') {
  15905. throw new CastError('$text', val, path);
  15906. }
  15907. if (val.$search != null) {
  15908. val.$search = castString(val.$search, path + '.$search');
  15909. }
  15910. if (val.$language != null) {
  15911. val.$language = castString(val.$language, path + '.$language');
  15912. }
  15913. if (val.$caseSensitive != null) {
  15914. val.$caseSensitive = castBoolean(val.$caseSensitive, path + '.$castSensitive');
  15915. }
  15916. if (val.$diacriticSensitive != null) {
  15917. val.$diacriticSensitive = castBoolean(val.$diacriticSensitive, path + '.$diacriticSensitive');
  15918. }
  15919. return val;
  15920. };
  15921. /***/ }),
  15922. /***/ 3053:
  15923. /***/ ((module) => {
  15924. "use strict";
  15925. /*!
  15926. * ignore
  15927. */
  15928. module.exports = function (val) {
  15929. if (Array.isArray(val)) {
  15930. if (!val.every(function (v) {
  15931. return typeof v === 'number' || typeof v === 'string';
  15932. })) {
  15933. throw new Error('$type array values must be strings or numbers');
  15934. }
  15935. return val;
  15936. }
  15937. if (typeof val !== 'number' && typeof val !== 'string') {
  15938. throw new Error('$type parameter must be number, string, or array of numbers and strings');
  15939. }
  15940. return val;
  15941. };
  15942. /***/ }),
  15943. /***/ 6542:
  15944. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  15945. "use strict";
  15946. /*!
  15947. * Module dependencies.
  15948. */
  15949. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  15950. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  15951. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  15952. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  15953. var SchemaType = __webpack_require__(4289);
  15954. var MongooseError = __webpack_require__(4888);
  15955. var SchemaStringOptions = __webpack_require__(3209);
  15956. var castString = __webpack_require__(2417);
  15957. var utils = __webpack_require__(6872);
  15958. var isBsonType = __webpack_require__(1563);
  15959. var CastError = SchemaType.CastError;
  15960. /**
  15961. * String SchemaType constructor.
  15962. *
  15963. * @param {String} key
  15964. * @param {Object} options
  15965. * @inherits SchemaType
  15966. * @api public
  15967. */
  15968. function SchemaString(key, options) {
  15969. this.enumValues = [];
  15970. this.regExp = null;
  15971. SchemaType.call(this, key, options, 'String');
  15972. }
  15973. /**
  15974. * This schema type's name, to defend against minifiers that mangle
  15975. * function names.
  15976. *
  15977. * @api public
  15978. */
  15979. SchemaString.schemaName = 'String';
  15980. SchemaString.defaultOptions = {};
  15981. /*!
  15982. * Inherits from SchemaType.
  15983. */
  15984. SchemaString.prototype = Object.create(SchemaType.prototype);
  15985. SchemaString.prototype.constructor = SchemaString;
  15986. Object.defineProperty(SchemaString.prototype, 'OptionsConstructor', {
  15987. configurable: false,
  15988. enumerable: false,
  15989. writable: false,
  15990. value: SchemaStringOptions
  15991. });
  15992. /*!
  15993. * ignore
  15994. */
  15995. SchemaString._cast = castString;
  15996. /**
  15997. * Get/set the function used to cast arbitrary values to strings.
  15998. *
  15999. * #### Example:
  16000. *
  16001. * // Throw an error if you pass in an object. Normally, Mongoose allows
  16002. * // objects with custom `toString()` functions.
  16003. * const original = mongoose.Schema.Types.String.cast();
  16004. * mongoose.Schema.Types.String.cast(v => {
  16005. * assert.ok(v == null || typeof v !== 'object');
  16006. * return original(v);
  16007. * });
  16008. *
  16009. * // Or disable casting entirely
  16010. * mongoose.Schema.Types.String.cast(false);
  16011. *
  16012. * @param {Function} caster
  16013. * @return {Function}
  16014. * @function get
  16015. * @static
  16016. * @api public
  16017. */
  16018. SchemaString.cast = function cast(caster) {
  16019. if (arguments.length === 0) {
  16020. return this._cast;
  16021. }
  16022. if (caster === false) {
  16023. caster = this._defaultCaster;
  16024. }
  16025. this._cast = caster;
  16026. return this._cast;
  16027. };
  16028. /*!
  16029. * ignore
  16030. */
  16031. SchemaString._defaultCaster = function (v) {
  16032. if (v != null && typeof v !== 'string') {
  16033. throw new Error();
  16034. }
  16035. return v;
  16036. };
  16037. /**
  16038. * Attaches a getter for all String instances.
  16039. *
  16040. * #### Example:
  16041. *
  16042. * // Make all numbers round down
  16043. * mongoose.Schema.String.get(v => v.toLowerCase());
  16044. *
  16045. * const Model = mongoose.model('Test', new Schema({ test: String }));
  16046. * new Model({ test: 'FOO' }).test; // 'foo'
  16047. *
  16048. * @param {Function} getter
  16049. * @return {this}
  16050. * @function get
  16051. * @static
  16052. * @api public
  16053. */
  16054. SchemaString.get = SchemaType.get;
  16055. /**
  16056. * Sets a default option for all String instances.
  16057. *
  16058. * #### Example:
  16059. *
  16060. * // Make all strings have option `trim` equal to true.
  16061. * mongoose.Schema.String.set('trim', true);
  16062. *
  16063. * const User = mongoose.model('User', new Schema({ name: String }));
  16064. * new User({ name: ' John Doe ' }).name; // 'John Doe'
  16065. *
  16066. * @param {String} option - The option you'd like to set the value for
  16067. * @param {*} value - value for option
  16068. * @return {undefined}
  16069. * @function set
  16070. * @static
  16071. * @api public
  16072. */
  16073. SchemaString.set = SchemaType.set;
  16074. /*!
  16075. * ignore
  16076. */
  16077. SchemaString._checkRequired = function (v) {
  16078. return (v instanceof String || typeof v === 'string') && v.length;
  16079. };
  16080. /**
  16081. * Override the function the required validator uses to check whether a string
  16082. * passes the `required` check.
  16083. *
  16084. * #### Example:
  16085. *
  16086. * // Allow empty strings to pass `required` check
  16087. * mongoose.Schema.Types.String.checkRequired(v => v != null);
  16088. *
  16089. * const M = mongoose.model({ str: { type: String, required: true } });
  16090. * new M({ str: '' }).validateSync(); // `null`, validation passes!
  16091. *
  16092. * @param {Function} fn
  16093. * @return {Function}
  16094. * @function checkRequired
  16095. * @static
  16096. * @api public
  16097. */
  16098. SchemaString.checkRequired = SchemaType.checkRequired;
  16099. /**
  16100. * Adds an enum validator
  16101. *
  16102. * #### Example:
  16103. *
  16104. * const states = ['opening', 'open', 'closing', 'closed']
  16105. * const s = new Schema({ state: { type: String, enum: states }})
  16106. * const M = db.model('M', s)
  16107. * const m = new M({ state: 'invalid' })
  16108. * m.save(function (err) {
  16109. * console.error(String(err)) // ValidationError: `invalid` is not a valid enum value for path `state`.
  16110. * m.state = 'open'
  16111. * m.save(callback) // success
  16112. * })
  16113. *
  16114. * // or with custom error messages
  16115. * const enum = {
  16116. * values: ['opening', 'open', 'closing', 'closed'],
  16117. * message: 'enum validator failed for path `{PATH}` with value `{VALUE}`'
  16118. * }
  16119. * const s = new Schema({ state: { type: String, enum: enum })
  16120. * const M = db.model('M', s)
  16121. * const m = new M({ state: 'invalid' })
  16122. * m.save(function (err) {
  16123. * console.error(String(err)) // ValidationError: enum validator failed for path `state` with value `invalid`
  16124. * m.state = 'open'
  16125. * m.save(callback) // success
  16126. * })
  16127. *
  16128. * @param {String|Object} [args...] enumeration values
  16129. * @return {SchemaType} this
  16130. * @see Customized Error Messages #error_messages_MongooseError-messages
  16131. * @api public
  16132. */
  16133. SchemaString.prototype["enum"] = function () {
  16134. if (this.enumValidator) {
  16135. this.validators = this.validators.filter(function (v) {
  16136. return v.validator !== this.enumValidator;
  16137. }, this);
  16138. this.enumValidator = false;
  16139. }
  16140. if (arguments[0] === void 0 || arguments[0] === false) {
  16141. return this;
  16142. }
  16143. var values;
  16144. var errorMessage;
  16145. if (utils.isObject(arguments[0])) {
  16146. if (Array.isArray(arguments[0].values)) {
  16147. values = arguments[0].values;
  16148. errorMessage = arguments[0].message;
  16149. } else {
  16150. values = utils.object.vals(arguments[0]);
  16151. errorMessage = MongooseError.messages.String["enum"];
  16152. }
  16153. } else {
  16154. values = arguments;
  16155. errorMessage = MongooseError.messages.String["enum"];
  16156. }
  16157. var _iterator = _createForOfIteratorHelper(values),
  16158. _step;
  16159. try {
  16160. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  16161. var value = _step.value;
  16162. if (value !== undefined) {
  16163. this.enumValues.push(this.cast(value));
  16164. }
  16165. }
  16166. } catch (err) {
  16167. _iterator.e(err);
  16168. } finally {
  16169. _iterator.f();
  16170. }
  16171. var vals = this.enumValues;
  16172. this.enumValidator = function (v) {
  16173. return undefined === v || ~vals.indexOf(v);
  16174. };
  16175. this.validators.push({
  16176. validator: this.enumValidator,
  16177. message: errorMessage,
  16178. type: 'enum',
  16179. enumValues: vals
  16180. });
  16181. return this;
  16182. };
  16183. /**
  16184. * Adds a lowercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
  16185. *
  16186. * #### Example:
  16187. *
  16188. * const s = new Schema({ email: { type: String, lowercase: true }})
  16189. * const M = db.model('M', s);
  16190. * const m = new M({ email: 'SomeEmail@example.COM' });
  16191. * console.log(m.email) // someemail@example.com
  16192. * M.find({ email: 'SomeEmail@example.com' }); // Queries by 'someemail@example.com'
  16193. *
  16194. * Note that `lowercase` does **not** affect regular expression queries:
  16195. *
  16196. * #### Example:
  16197. * // Still queries for documents whose `email` matches the regular
  16198. * // expression /SomeEmail/. Mongoose does **not** convert the RegExp
  16199. * // to lowercase.
  16200. * M.find({ email: /SomeEmail/ });
  16201. *
  16202. * @api public
  16203. * @return {SchemaType} this
  16204. */
  16205. SchemaString.prototype.lowercase = function (shouldApply) {
  16206. var _this2 = this;
  16207. if (arguments.length > 0 && !shouldApply) {
  16208. return this;
  16209. }
  16210. return this.set(function (v) {
  16211. if (typeof v !== 'string') {
  16212. v = _this2.cast(v);
  16213. }
  16214. if (v) {
  16215. return v.toLowerCase();
  16216. }
  16217. return v;
  16218. });
  16219. };
  16220. /**
  16221. * Adds an uppercase [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
  16222. *
  16223. * #### Example:
  16224. *
  16225. * const s = new Schema({ caps: { type: String, uppercase: true }})
  16226. * const M = db.model('M', s);
  16227. * const m = new M({ caps: 'an example' });
  16228. * console.log(m.caps) // AN EXAMPLE
  16229. * M.find({ caps: 'an example' }) // Matches documents where caps = 'AN EXAMPLE'
  16230. *
  16231. * Note that `uppercase` does **not** affect regular expression queries:
  16232. *
  16233. * #### Example:
  16234. * // Mongoose does **not** convert the RegExp to uppercase.
  16235. * M.find({ email: /an example/ });
  16236. *
  16237. * @api public
  16238. * @return {SchemaType} this
  16239. */
  16240. SchemaString.prototype.uppercase = function (shouldApply) {
  16241. var _this3 = this;
  16242. if (arguments.length > 0 && !shouldApply) {
  16243. return this;
  16244. }
  16245. return this.set(function (v) {
  16246. if (typeof v !== 'string') {
  16247. v = _this3.cast(v);
  16248. }
  16249. if (v) {
  16250. return v.toUpperCase();
  16251. }
  16252. return v;
  16253. });
  16254. };
  16255. /**
  16256. * Adds a trim [setter](https://mongoosejs.com/docs/api.html#schematype_SchemaType-set).
  16257. *
  16258. * The string value will be [trimmed](https://masteringjs.io/tutorials/fundamentals/trim-string) when set.
  16259. *
  16260. * #### Example:
  16261. *
  16262. * const s = new Schema({ name: { type: String, trim: true }});
  16263. * const M = db.model('M', s);
  16264. * const string = ' some name ';
  16265. * console.log(string.length); // 11
  16266. * const m = new M({ name: string });
  16267. * console.log(m.name.length); // 9
  16268. *
  16269. * // Equivalent to `findOne({ name: string.trim() })`
  16270. * M.findOne({ name: string });
  16271. *
  16272. * Note that `trim` does **not** affect regular expression queries:
  16273. *
  16274. * #### Example:
  16275. * // Mongoose does **not** trim whitespace from the RegExp.
  16276. * M.find({ name: / some name / });
  16277. *
  16278. * @api public
  16279. * @return {SchemaType} this
  16280. */
  16281. SchemaString.prototype.trim = function (shouldTrim) {
  16282. var _this4 = this;
  16283. if (arguments.length > 0 && !shouldTrim) {
  16284. return this;
  16285. }
  16286. return this.set(function (v) {
  16287. if (typeof v !== 'string') {
  16288. v = _this4.cast(v);
  16289. }
  16290. if (v) {
  16291. return v.trim();
  16292. }
  16293. return v;
  16294. });
  16295. };
  16296. /**
  16297. * Sets a minimum length validator.
  16298. *
  16299. * #### Example:
  16300. *
  16301. * const schema = new Schema({ postalCode: { type: String, minlength: 5 })
  16302. * const Address = db.model('Address', schema)
  16303. * const address = new Address({ postalCode: '9512' })
  16304. * address.save(function (err) {
  16305. * console.error(err) // validator error
  16306. * address.postalCode = '95125';
  16307. * address.save() // success
  16308. * })
  16309. *
  16310. * // custom error messages
  16311. * // We can also use the special {MINLENGTH} token which will be replaced with the minimum allowed length
  16312. * const minlength = [5, 'The value of path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).'];
  16313. * const schema = new Schema({ postalCode: { type: String, minlength: minlength })
  16314. * const Address = mongoose.model('Address', schema);
  16315. * const address = new Address({ postalCode: '9512' });
  16316. * address.validate(function (err) {
  16317. * console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512`) is shorter than the minimum length (5).
  16318. * })
  16319. *
  16320. * @param {Number} value minimum string length
  16321. * @param {String} [message] optional custom error message
  16322. * @return {SchemaType} this
  16323. * @see Customized Error Messages #error_messages_MongooseError-messages
  16324. * @api public
  16325. */
  16326. SchemaString.prototype.minlength = function (value, message) {
  16327. if (this.minlengthValidator) {
  16328. this.validators = this.validators.filter(function (v) {
  16329. return v.validator !== this.minlengthValidator;
  16330. }, this);
  16331. }
  16332. if (value !== null && value !== undefined) {
  16333. var msg = message || MongooseError.messages.String.minlength;
  16334. msg = msg.replace(/{MINLENGTH}/, value);
  16335. this.validators.push({
  16336. validator: this.minlengthValidator = function (v) {
  16337. return v === null || v.length >= value;
  16338. },
  16339. message: msg,
  16340. type: 'minlength',
  16341. minlength: value
  16342. });
  16343. }
  16344. return this;
  16345. };
  16346. SchemaString.prototype.minLength = SchemaString.prototype.minlength;
  16347. /**
  16348. * Sets a maximum length validator.
  16349. *
  16350. * #### Example:
  16351. *
  16352. * const schema = new Schema({ postalCode: { type: String, maxlength: 9 })
  16353. * const Address = db.model('Address', schema)
  16354. * const address = new Address({ postalCode: '9512512345' })
  16355. * address.save(function (err) {
  16356. * console.error(err) // validator error
  16357. * address.postalCode = '95125';
  16358. * address.save() // success
  16359. * })
  16360. *
  16361. * // custom error messages
  16362. * // We can also use the special {MAXLENGTH} token which will be replaced with the maximum allowed length
  16363. * const maxlength = [9, 'The value of path `{PATH}` (`{VALUE}`) exceeds the maximum allowed length ({MAXLENGTH}).'];
  16364. * const schema = new Schema({ postalCode: { type: String, maxlength: maxlength })
  16365. * const Address = mongoose.model('Address', schema);
  16366. * const address = new Address({ postalCode: '9512512345' });
  16367. * address.validate(function (err) {
  16368. * console.log(String(err)) // ValidationError: The value of path `postalCode` (`9512512345`) exceeds the maximum allowed length (9).
  16369. * })
  16370. *
  16371. * @param {Number} value maximum string length
  16372. * @param {String} [message] optional custom error message
  16373. * @return {SchemaType} this
  16374. * @see Customized Error Messages #error_messages_MongooseError-messages
  16375. * @api public
  16376. */
  16377. SchemaString.prototype.maxlength = function (value, message) {
  16378. if (this.maxlengthValidator) {
  16379. this.validators = this.validators.filter(function (v) {
  16380. return v.validator !== this.maxlengthValidator;
  16381. }, this);
  16382. }
  16383. if (value !== null && value !== undefined) {
  16384. var msg = message || MongooseError.messages.String.maxlength;
  16385. msg = msg.replace(/{MAXLENGTH}/, value);
  16386. this.validators.push({
  16387. validator: this.maxlengthValidator = function (v) {
  16388. return v === null || v.length <= value;
  16389. },
  16390. message: msg,
  16391. type: 'maxlength',
  16392. maxlength: value
  16393. });
  16394. }
  16395. return this;
  16396. };
  16397. SchemaString.prototype.maxLength = SchemaString.prototype.maxlength;
  16398. /**
  16399. * Sets a regexp validator.
  16400. *
  16401. * Any value that does not pass `regExp`.test(val) will fail validation.
  16402. *
  16403. * #### Example:
  16404. *
  16405. * const s = new Schema({ name: { type: String, match: /^a/ }})
  16406. * const M = db.model('M', s)
  16407. * const m = new M({ name: 'I am invalid' })
  16408. * m.validate(function (err) {
  16409. * console.error(String(err)) // "ValidationError: Path `name` is invalid (I am invalid)."
  16410. * m.name = 'apples'
  16411. * m.validate(function (err) {
  16412. * assert.ok(err) // success
  16413. * })
  16414. * })
  16415. *
  16416. * // using a custom error message
  16417. * const match = [ /\.html$/, "That file doesn't end in .html ({VALUE})" ];
  16418. * const s = new Schema({ file: { type: String, match: match }})
  16419. * const M = db.model('M', s);
  16420. * const m = new M({ file: 'invalid' });
  16421. * m.validate(function (err) {
  16422. * console.log(String(err)) // "ValidationError: That file doesn't end in .html (invalid)"
  16423. * })
  16424. *
  16425. * Empty strings, `undefined`, and `null` values always pass the match validator. If you require these values, enable the `required` validator also.
  16426. *
  16427. * const s = new Schema({ name: { type: String, match: /^a/, required: true }})
  16428. *
  16429. * @param {RegExp} regExp regular expression to test against
  16430. * @param {String} [message] optional custom error message
  16431. * @return {SchemaType} this
  16432. * @see Customized Error Messages #error_messages_MongooseError-messages
  16433. * @api public
  16434. */
  16435. SchemaString.prototype.match = function match(regExp, message) {
  16436. // yes, we allow multiple match validators
  16437. var msg = message || MongooseError.messages.String.match;
  16438. var matchValidator = function matchValidator(v) {
  16439. if (!regExp) {
  16440. return false;
  16441. } // In case RegExp happens to have `/g` flag set, we need to reset the
  16442. // `lastIndex`, otherwise `match` will intermittently fail.
  16443. regExp.lastIndex = 0;
  16444. var ret = v != null && v !== '' ? regExp.test(v) : true;
  16445. return ret;
  16446. };
  16447. this.validators.push({
  16448. validator: matchValidator,
  16449. message: msg,
  16450. type: 'regexp',
  16451. regexp: regExp
  16452. });
  16453. return this;
  16454. };
  16455. /**
  16456. * Check if the given value satisfies the `required` validator. The value is
  16457. * considered valid if it is a string (that is, not `null` or `undefined`) and
  16458. * has positive length. The `required` validator **will** fail for empty
  16459. * strings.
  16460. *
  16461. * @param {Any} value
  16462. * @param {Document} doc
  16463. * @return {Boolean}
  16464. * @api public
  16465. */
  16466. SchemaString.prototype.checkRequired = function checkRequired(value, doc) {
  16467. if (_typeof(value) === 'object' && SchemaType._isRef(this, value, doc, true)) {
  16468. return value != null;
  16469. } // `require('util').inherits()` does **not** copy static properties, and
  16470. // plugins like mongoose-float use `inherits()` for pre-ES6.
  16471. var _checkRequired = typeof this.constructor.checkRequired === 'function' ? this.constructor.checkRequired() : SchemaString.checkRequired();
  16472. return _checkRequired(value);
  16473. };
  16474. /**
  16475. * Casts to String
  16476. *
  16477. * @api private
  16478. */
  16479. SchemaString.prototype.cast = function (value, doc, init) {
  16480. if (typeof value !== 'string' && SchemaType._isRef(this, value, doc, init)) {
  16481. return this._castRef(value, doc, init);
  16482. }
  16483. var castString;
  16484. if (typeof this._castFunction === 'function') {
  16485. castString = this._castFunction;
  16486. } else if (typeof this.constructor.cast === 'function') {
  16487. castString = this.constructor.cast();
  16488. } else {
  16489. castString = SchemaString.cast();
  16490. }
  16491. try {
  16492. return castString(value);
  16493. } catch (error) {
  16494. throw new CastError('string', value, this.path, null, this);
  16495. }
  16496. };
  16497. /*!
  16498. * ignore
  16499. */
  16500. function handleSingle(val) {
  16501. return this.castForQuery(val);
  16502. }
  16503. /*!
  16504. * ignore
  16505. */
  16506. function handleArray(val) {
  16507. var _this = this;
  16508. if (!Array.isArray(val)) {
  16509. return [this.castForQuery(val)];
  16510. }
  16511. return val.map(function (m) {
  16512. return _this.castForQuery(m);
  16513. });
  16514. }
  16515. /*!
  16516. * ignore
  16517. */
  16518. function handleSingleNoSetters(val) {
  16519. if (val == null) {
  16520. return this._castNullish(val);
  16521. }
  16522. return this.cast(val, this);
  16523. }
  16524. var $conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, {
  16525. $all: handleArray,
  16526. $gt: handleSingle,
  16527. $gte: handleSingle,
  16528. $lt: handleSingle,
  16529. $lte: handleSingle,
  16530. $options: handleSingleNoSetters,
  16531. $regex: function handle$regex(val) {
  16532. if (Object.prototype.toString.call(val) === '[object RegExp]') {
  16533. return val;
  16534. }
  16535. return handleSingleNoSetters.call(this, val);
  16536. },
  16537. $not: handleSingle
  16538. });
  16539. Object.defineProperty(SchemaString.prototype, '$conditionalHandlers', {
  16540. configurable: false,
  16541. enumerable: false,
  16542. writable: false,
  16543. value: Object.freeze($conditionalHandlers)
  16544. });
  16545. /**
  16546. * Casts contents for queries.
  16547. *
  16548. * @param {String} $conditional
  16549. * @param {any} [val]
  16550. * @api private
  16551. */
  16552. SchemaString.prototype.castForQuery = function ($conditional, val) {
  16553. var handler;
  16554. if (arguments.length === 2) {
  16555. handler = this.$conditionalHandlers[$conditional];
  16556. if (!handler) {
  16557. throw new Error('Can\'t use ' + $conditional + ' with String.');
  16558. }
  16559. return handler.call(this, val);
  16560. }
  16561. val = $conditional;
  16562. if (Object.prototype.toString.call(val) === '[object RegExp]' || isBsonType(val, 'BSONRegExp')) {
  16563. return val;
  16564. }
  16565. return this._castForQuery(val);
  16566. };
  16567. /*!
  16568. * Module exports.
  16569. */
  16570. module.exports = SchemaString;
  16571. /***/ }),
  16572. /***/ 8107:
  16573. /***/ ((__unused_webpack_module, exports) => {
  16574. "use strict";
  16575. exports.schemaMixedSymbol = Symbol["for"]('mongoose:schema_mixed');
  16576. exports.builtInMiddleware = Symbol["for"]('mongoose:built-in-middleware');
  16577. /***/ }),
  16578. /***/ 4289:
  16579. /***/ ((module, exports, __webpack_require__) => {
  16580. "use strict";
  16581. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  16582. /*!
  16583. * Module dependencies.
  16584. */
  16585. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  16586. var MongooseError = __webpack_require__(4888);
  16587. var SchemaTypeOptions = __webpack_require__(1764);
  16588. var $exists = __webpack_require__(8702);
  16589. var $type = __webpack_require__(3053);
  16590. var handleImmutable = __webpack_require__(8828);
  16591. var isAsyncFunction = __webpack_require__(8857);
  16592. var isSimpleValidator = __webpack_require__(9130);
  16593. var immediate = __webpack_require__(1490);
  16594. var schemaTypeSymbol = (__webpack_require__(8770).schemaTypeSymbol);
  16595. var utils = __webpack_require__(6872);
  16596. var validatorErrorSymbol = (__webpack_require__(8770).validatorErrorSymbol);
  16597. var documentIsModified = (__webpack_require__(8770).documentIsModified);
  16598. var populateModelSymbol = (__webpack_require__(8770).populateModelSymbol);
  16599. var CastError = MongooseError.CastError;
  16600. var ValidatorError = MongooseError.ValidatorError;
  16601. var setOptionsForDefaults = {
  16602. _skipMarkModified: true
  16603. };
  16604. /**
  16605. * SchemaType constructor. Do **not** instantiate `SchemaType` directly.
  16606. * Mongoose converts your schema paths into SchemaTypes automatically.
  16607. *
  16608. * #### Example:
  16609. *
  16610. * const schema = new Schema({ name: String });
  16611. * schema.path('name') instanceof SchemaType; // true
  16612. *
  16613. * @param {String} path
  16614. * @param {SchemaTypeOptions} [options] See [SchemaTypeOptions docs](/docs/api/schematypeoptions.html)
  16615. * @param {String} [instance]
  16616. * @api public
  16617. */
  16618. function SchemaType(path, options, instance) {
  16619. this[schemaTypeSymbol] = true;
  16620. this.path = path;
  16621. this.instance = instance;
  16622. this.validators = [];
  16623. this.getters = this.constructor.hasOwnProperty('getters') ? this.constructor.getters.slice() : [];
  16624. this.setters = [];
  16625. this.splitPath();
  16626. options = options || {};
  16627. var defaultOptions = this.constructor.defaultOptions || {};
  16628. var defaultOptionsKeys = Object.keys(defaultOptions);
  16629. for (var _i = 0, _defaultOptionsKeys = defaultOptionsKeys; _i < _defaultOptionsKeys.length; _i++) {
  16630. var option = _defaultOptionsKeys[_i];
  16631. if (defaultOptions.hasOwnProperty(option) && !options.hasOwnProperty(option)) {
  16632. options[option] = defaultOptions[option];
  16633. }
  16634. }
  16635. if (options.select == null) {
  16636. delete options.select;
  16637. }
  16638. var Options = this.OptionsConstructor || SchemaTypeOptions;
  16639. this.options = new Options(options);
  16640. this._index = null;
  16641. if (utils.hasUserDefinedProperty(this.options, 'immutable')) {
  16642. this.$immutable = this.options.immutable;
  16643. handleImmutable(this);
  16644. }
  16645. var keys = Object.keys(this.options);
  16646. for (var _i2 = 0, _keys = keys; _i2 < _keys.length; _i2++) {
  16647. var prop = _keys[_i2];
  16648. if (prop === 'cast') {
  16649. this.castFunction(this.options[prop]);
  16650. continue;
  16651. }
  16652. if (utils.hasUserDefinedProperty(this.options, prop) && typeof this[prop] === 'function') {
  16653. // { unique: true, index: true }
  16654. if (prop === 'index' && this._index) {
  16655. if (options.index === false) {
  16656. var index = this._index;
  16657. if (_typeof(index) === 'object' && index != null) {
  16658. if (index.unique) {
  16659. throw new Error('Path "' + this.path + '" may not have `index` ' + 'set to false and `unique` set to true');
  16660. }
  16661. if (index.sparse) {
  16662. throw new Error('Path "' + this.path + '" may not have `index` ' + 'set to false and `sparse` set to true');
  16663. }
  16664. }
  16665. this._index = false;
  16666. }
  16667. continue;
  16668. }
  16669. var val = options[prop]; // Special case so we don't screw up array defaults, see gh-5780
  16670. if (prop === 'default') {
  16671. this["default"](val);
  16672. continue;
  16673. }
  16674. var opts = Array.isArray(val) ? val : [val];
  16675. this[prop].apply(this, opts);
  16676. }
  16677. }
  16678. Object.defineProperty(this, '$$context', {
  16679. enumerable: false,
  16680. configurable: false,
  16681. writable: true,
  16682. value: null
  16683. });
  16684. }
  16685. /*!
  16686. * The class that Mongoose uses internally to instantiate this SchemaType's `options` property.
  16687. */
  16688. SchemaType.prototype.OptionsConstructor = SchemaTypeOptions;
  16689. /**
  16690. * The path to this SchemaType in a Schema.
  16691. *
  16692. * #### Example:
  16693. * const schema = new Schema({ name: String });
  16694. * schema.path('name').path; // 'name'
  16695. *
  16696. * @property path
  16697. * @api public
  16698. * @memberOf SchemaType
  16699. */
  16700. SchemaType.prototype.path;
  16701. /**
  16702. * The validators that Mongoose should run to validate properties at this SchemaType's path.
  16703. *
  16704. * #### Example:
  16705. * const schema = new Schema({ name: { type: String, required: true } });
  16706. * schema.path('name').validators.length; // 1, the `required` validator
  16707. *
  16708. * @property validators
  16709. * @api public
  16710. * @memberOf SchemaType
  16711. */
  16712. SchemaType.prototype.validators;
  16713. /**
  16714. * True if this SchemaType has a required validator. False otherwise.
  16715. *
  16716. * #### Example:
  16717. * const schema = new Schema({ name: { type: String, required: true } });
  16718. * schema.path('name').isRequired; // true
  16719. *
  16720. * schema.path('name').required(false);
  16721. * schema.path('name').isRequired; // false
  16722. *
  16723. * @property isRequired
  16724. * @api public
  16725. * @memberOf SchemaType
  16726. */
  16727. SchemaType.prototype.validators;
  16728. /*!
  16729. * ignore
  16730. */
  16731. SchemaType.prototype.splitPath = function () {
  16732. if (this._presplitPath != null) {
  16733. return this._presplitPath;
  16734. }
  16735. if (this.path == null) {
  16736. return undefined;
  16737. }
  16738. this._presplitPath = this.path.indexOf('.') === -1 ? [this.path] : this.path.split('.');
  16739. return this._presplitPath;
  16740. };
  16741. /**
  16742. * Get/set the function used to cast arbitrary values to this type.
  16743. *
  16744. * #### Example:
  16745. *
  16746. * // Disallow `null` for numbers, and don't try to cast any values to
  16747. * // numbers, so even strings like '123' will cause a CastError.
  16748. * mongoose.Number.cast(function(v) {
  16749. * assert.ok(v === undefined || typeof v === 'number');
  16750. * return v;
  16751. * });
  16752. *
  16753. * @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
  16754. * @return {Function}
  16755. * @static
  16756. * @receiver SchemaType
  16757. * @function cast
  16758. * @api public
  16759. */
  16760. SchemaType.cast = function cast(caster) {
  16761. if (arguments.length === 0) {
  16762. return this._cast;
  16763. }
  16764. if (caster === false) {
  16765. caster = function caster(v) {
  16766. return v;
  16767. };
  16768. }
  16769. this._cast = caster;
  16770. return this._cast;
  16771. };
  16772. /**
  16773. * Get/set the function used to cast arbitrary values to this particular schematype instance.
  16774. * Overrides `SchemaType.cast()`.
  16775. *
  16776. * #### Example:
  16777. *
  16778. * // Disallow `null` for numbers, and don't try to cast any values to
  16779. * // numbers, so even strings like '123' will cause a CastError.
  16780. * const number = new mongoose.Number('mypath', {});
  16781. * number.cast(function(v) {
  16782. * assert.ok(v === undefined || typeof v === 'number');
  16783. * return v;
  16784. * });
  16785. *
  16786. * @param {Function|false} caster Function that casts arbitrary values to this type, or throws an error if casting failed
  16787. * @return {Function}
  16788. * @static
  16789. * @receiver SchemaType
  16790. * @function cast
  16791. * @api public
  16792. */
  16793. SchemaType.prototype.castFunction = function castFunction(caster) {
  16794. if (arguments.length === 0) {
  16795. return this._castFunction;
  16796. }
  16797. if (caster === false) {
  16798. caster = this.constructor._defaultCaster || function (v) {
  16799. return v;
  16800. };
  16801. }
  16802. this._castFunction = caster;
  16803. return this._castFunction;
  16804. };
  16805. /**
  16806. * The function that Mongoose calls to cast arbitrary values to this SchemaType.
  16807. *
  16808. * @param {Object} value value to cast
  16809. * @param {Document} doc document that triggers the casting
  16810. * @param {Boolean} init
  16811. * @api public
  16812. */
  16813. SchemaType.prototype.cast = function cast() {
  16814. throw new Error('Base SchemaType class does not implement a `cast()` function');
  16815. };
  16816. /**
  16817. * Sets a default option for this schema type.
  16818. *
  16819. * #### Example:
  16820. *
  16821. * // Make all strings be trimmed by default
  16822. * mongoose.SchemaTypes.String.set('trim', true);
  16823. *
  16824. * @param {String} option The name of the option you'd like to set (e.g. trim, lowercase, etc...)
  16825. * @param {*} value The value of the option you'd like to set.
  16826. * @return {void}
  16827. * @static
  16828. * @receiver SchemaType
  16829. * @function set
  16830. * @api public
  16831. */
  16832. SchemaType.set = function set(option, value) {
  16833. if (!this.hasOwnProperty('defaultOptions')) {
  16834. this.defaultOptions = Object.assign({}, this.defaultOptions);
  16835. }
  16836. this.defaultOptions[option] = value;
  16837. };
  16838. /**
  16839. * Attaches a getter for all instances of this schema type.
  16840. *
  16841. * #### Example:
  16842. *
  16843. * // Make all numbers round down
  16844. * mongoose.Number.get(function(v) { return Math.floor(v); });
  16845. *
  16846. * @param {Function} getter
  16847. * @return {this}
  16848. * @static
  16849. * @receiver SchemaType
  16850. * @function get
  16851. * @api public
  16852. */
  16853. SchemaType.get = function (getter) {
  16854. this.getters = this.hasOwnProperty('getters') ? this.getters : [];
  16855. this.getters.push(getter);
  16856. };
  16857. /**
  16858. * Sets a default value for this SchemaType.
  16859. *
  16860. * #### Example:
  16861. *
  16862. * const schema = new Schema({ n: { type: Number, default: 10 })
  16863. * const M = db.model('M', schema)
  16864. * const m = new M;
  16865. * console.log(m.n) // 10
  16866. *
  16867. * Defaults can be either `functions` which return the value to use as the default or the literal value itself. Either way, the value will be cast based on its schema type before being set during document creation.
  16868. *
  16869. * #### Example:
  16870. *
  16871. * // values are cast:
  16872. * const schema = new Schema({ aNumber: { type: Number, default: 4.815162342 }})
  16873. * const M = db.model('M', schema)
  16874. * const m = new M;
  16875. * console.log(m.aNumber) // 4.815162342
  16876. *
  16877. * // default unique objects for Mixed types:
  16878. * const schema = new Schema({ mixed: Schema.Types.Mixed });
  16879. * schema.path('mixed').default(function () {
  16880. * return {};
  16881. * });
  16882. *
  16883. * // if we don't use a function to return object literals for Mixed defaults,
  16884. * // each document will receive a reference to the same object literal creating
  16885. * // a "shared" object instance:
  16886. * const schema = new Schema({ mixed: Schema.Types.Mixed });
  16887. * schema.path('mixed').default({});
  16888. * const M = db.model('M', schema);
  16889. * const m1 = new M;
  16890. * m1.mixed.added = 1;
  16891. * console.log(m1.mixed); // { added: 1 }
  16892. * const m2 = new M;
  16893. * console.log(m2.mixed); // { added: 1 }
  16894. *
  16895. * @param {Function|any} val the default value
  16896. * @return {defaultValue}
  16897. * @api public
  16898. */
  16899. SchemaType.prototype["default"] = function (val) {
  16900. if (arguments.length === 1) {
  16901. if (val === void 0) {
  16902. this.defaultValue = void 0;
  16903. return void 0;
  16904. }
  16905. if (val != null && val.instanceOfSchema) {
  16906. throw new MongooseError('Cannot set default value of path `' + this.path + '` to a mongoose Schema instance.');
  16907. }
  16908. this.defaultValue = val;
  16909. return this.defaultValue;
  16910. } else if (arguments.length > 1) {
  16911. this.defaultValue = Array.prototype.slice.call(arguments);
  16912. }
  16913. return this.defaultValue;
  16914. };
  16915. /**
  16916. * Declares the index options for this schematype.
  16917. *
  16918. * #### Example:
  16919. *
  16920. * const s = new Schema({ name: { type: String, index: true })
  16921. * const s = new Schema({ loc: { type: [Number], index: 'hashed' })
  16922. * const s = new Schema({ loc: { type: [Number], index: '2d', sparse: true })
  16923. * const s = new Schema({ loc: { type: [Number], index: { type: '2dsphere', sparse: true }})
  16924. * const s = new Schema({ date: { type: Date, index: { unique: true, expires: '1d' }})
  16925. * s.path('my.path').index(true);
  16926. * s.path('my.date').index({ expires: 60 });
  16927. * s.path('my.path').index({ unique: true, sparse: true });
  16928. *
  16929. * #### Note:
  16930. *
  16931. * _Indexes are created [in the background](https://docs.mongodb.com/manual/core/index-creation/#index-creation-background)
  16932. * by default. If `background` is set to `false`, MongoDB will not execute any
  16933. * read/write operations you send until the index build.
  16934. * Specify `background: false` to override Mongoose's default._
  16935. *
  16936. * @param {Object|Boolean|String} options
  16937. * @return {SchemaType} this
  16938. * @api public
  16939. */
  16940. SchemaType.prototype.index = function (options) {
  16941. this._index = options;
  16942. utils.expires(this._index);
  16943. return this;
  16944. };
  16945. /**
  16946. * Declares an unique index.
  16947. *
  16948. * #### Example:
  16949. *
  16950. * const s = new Schema({ name: { type: String, unique: true }});
  16951. * s.path('name').index({ unique: true });
  16952. *
  16953. * _NOTE: violating the constraint returns an `E11000` error from MongoDB when saving, not a Mongoose validation error._
  16954. *
  16955. * @param {Boolean} bool
  16956. * @return {SchemaType} this
  16957. * @api public
  16958. */
  16959. SchemaType.prototype.unique = function (bool) {
  16960. if (this._index === false) {
  16961. if (!bool) {
  16962. return;
  16963. }
  16964. throw new Error('Path "' + this.path + '" may not have `index` set to ' + 'false and `unique` set to true');
  16965. }
  16966. if (!this.options.hasOwnProperty('index') && bool === false) {
  16967. return this;
  16968. }
  16969. if (this._index == null || this._index === true) {
  16970. this._index = {};
  16971. } else if (typeof this._index === 'string') {
  16972. this._index = {
  16973. type: this._index
  16974. };
  16975. }
  16976. this._index.unique = bool;
  16977. return this;
  16978. };
  16979. /**
  16980. * Declares a full text index.
  16981. *
  16982. * ### Example:
  16983. *
  16984. * const s = new Schema({name : {type: String, text : true })
  16985. * s.path('name').index({text : true});
  16986. * @param {Boolean} bool
  16987. * @return {SchemaType} this
  16988. * @api public
  16989. */
  16990. SchemaType.prototype.text = function (bool) {
  16991. if (this._index === false) {
  16992. if (!bool) {
  16993. return;
  16994. }
  16995. throw new Error('Path "' + this.path + '" may not have `index` set to ' + 'false and `text` set to true');
  16996. }
  16997. if (!this.options.hasOwnProperty('index') && bool === false) {
  16998. return this;
  16999. }
  17000. if (this._index === null || this._index === undefined || typeof this._index === 'boolean') {
  17001. this._index = {};
  17002. } else if (typeof this._index === 'string') {
  17003. this._index = {
  17004. type: this._index
  17005. };
  17006. }
  17007. this._index.text = bool;
  17008. return this;
  17009. };
  17010. /**
  17011. * Declares a sparse index.
  17012. *
  17013. * #### Example:
  17014. *
  17015. * const s = new Schema({ name: { type: String, sparse: true } });
  17016. * s.path('name').index({ sparse: true });
  17017. *
  17018. * @param {Boolean} bool
  17019. * @return {SchemaType} this
  17020. * @api public
  17021. */
  17022. SchemaType.prototype.sparse = function (bool) {
  17023. if (this._index === false) {
  17024. if (!bool) {
  17025. return;
  17026. }
  17027. throw new Error('Path "' + this.path + '" may not have `index` set to ' + 'false and `sparse` set to true');
  17028. }
  17029. if (!this.options.hasOwnProperty('index') && bool === false) {
  17030. return this;
  17031. }
  17032. if (this._index == null || typeof this._index === 'boolean') {
  17033. this._index = {};
  17034. } else if (typeof this._index === 'string') {
  17035. this._index = {
  17036. type: this._index
  17037. };
  17038. }
  17039. this._index.sparse = bool;
  17040. return this;
  17041. };
  17042. /**
  17043. * Defines this path as immutable. Mongoose prevents you from changing
  17044. * immutable paths unless the parent document has [`isNew: true`](/docs/api.html#document_Document-isNew).
  17045. *
  17046. * #### Example:
  17047. *
  17048. * const schema = new Schema({
  17049. * name: { type: String, immutable: true },
  17050. * age: Number
  17051. * });
  17052. * const Model = mongoose.model('Test', schema);
  17053. *
  17054. * await Model.create({ name: 'test' });
  17055. * const doc = await Model.findOne();
  17056. *
  17057. * doc.isNew; // false
  17058. * doc.name = 'new name';
  17059. * doc.name; // 'test', because `name` is immutable
  17060. *
  17061. * Mongoose also prevents changing immutable properties using `updateOne()`
  17062. * and `updateMany()` based on [strict mode](/docs/guide.html#strict).
  17063. *
  17064. * #### Example:
  17065. *
  17066. * // Mongoose will strip out the `name` update, because `name` is immutable
  17067. * Model.updateOne({}, { $set: { name: 'test2' }, $inc: { age: 1 } });
  17068. *
  17069. * // If `strict` is set to 'throw', Mongoose will throw an error if you
  17070. * // update `name`
  17071. * const err = await Model.updateOne({}, { name: 'test2' }, { strict: 'throw' }).
  17072. * then(() => null, err => err);
  17073. * err.name; // StrictModeError
  17074. *
  17075. * // If `strict` is `false`, Mongoose allows updating `name` even though
  17076. * // the property is immutable.
  17077. * Model.updateOne({}, { name: 'test2' }, { strict: false });
  17078. *
  17079. * @param {Boolean} bool
  17080. * @return {SchemaType} this
  17081. * @see isNew /docs/api.html#document_Document-isNew
  17082. * @api public
  17083. */
  17084. SchemaType.prototype.immutable = function (bool) {
  17085. this.$immutable = bool;
  17086. handleImmutable(this);
  17087. return this;
  17088. };
  17089. /**
  17090. * Defines a custom function for transforming this path when converting a document to JSON.
  17091. *
  17092. * Mongoose calls this function with one parameter: the current `value` of the path. Mongoose
  17093. * then uses the return value in the JSON output.
  17094. *
  17095. * #### Example:
  17096. *
  17097. * const schema = new Schema({
  17098. * date: { type: Date, transform: v => v.getFullYear() }
  17099. * });
  17100. * const Model = mongoose.model('Test', schema);
  17101. *
  17102. * await Model.create({ date: new Date('2016-06-01') });
  17103. * const doc = await Model.findOne();
  17104. *
  17105. * doc.date instanceof Date; // true
  17106. *
  17107. * doc.toJSON().date; // 2016 as a number
  17108. * JSON.stringify(doc); // '{"_id":...,"date":2016}'
  17109. *
  17110. * @param {Function} fn
  17111. * @return {SchemaType} this
  17112. * @api public
  17113. */
  17114. SchemaType.prototype.transform = function (fn) {
  17115. this.options.transform = fn;
  17116. return this;
  17117. };
  17118. /**
  17119. * Adds a setter to this schematype.
  17120. *
  17121. * #### Example:
  17122. *
  17123. * ```javascript
  17124. * function capitalize (val) {
  17125. * if (typeof val !== 'string') val = '';
  17126. * return val.charAt(0).toUpperCase() + val.substring(1);
  17127. * }
  17128. *
  17129. * // defining within the schema
  17130. * const s = new Schema({ name: { type: String, set: capitalize }});
  17131. *
  17132. * // or with the SchemaType
  17133. * const s = new Schema({ name: String })
  17134. * s.path('name').set(capitalize);
  17135. * ```
  17136. *
  17137. * Setters allow you to transform the data before it gets to the raw mongodb
  17138. * document or query.
  17139. *
  17140. * Suppose you are implementing user registration for a website. Users provide
  17141. * an email and password, which gets saved to mongodb. The email is a string
  17142. * that you will want to normalize to lower case, in order to avoid one email
  17143. * having more than one account -- e.g., otherwise, avenue@q.com can be registered for 2 accounts via avenue@q.com and AvEnUe@Q.CoM.
  17144. *
  17145. * You can set up email lower case normalization easily via a Mongoose setter.
  17146. *
  17147. * ```javascript
  17148. * function toLower(v) {
  17149. * return v.toLowerCase();
  17150. * }
  17151. *
  17152. * const UserSchema = new Schema({
  17153. * email: { type: String, set: toLower }
  17154. * });
  17155. *
  17156. * const User = db.model('User', UserSchema);
  17157. *
  17158. * const user = new User({email: 'AVENUE@Q.COM'});
  17159. * console.log(user.email); // 'avenue@q.com'
  17160. *
  17161. * // or
  17162. * const user = new User();
  17163. * user.email = 'Avenue@Q.com';
  17164. * console.log(user.email); // 'avenue@q.com'
  17165. * User.updateOne({ _id: _id }, { $set: { email: 'AVENUE@Q.COM' } }); // update to 'avenue@q.com'
  17166. * ```
  17167. *
  17168. * As you can see above, setters allow you to transform the data before it
  17169. * stored in MongoDB, or before executing a query.
  17170. *
  17171. * _NOTE: we could have also just used the built-in `lowercase: true` SchemaType option instead of defining our own function._
  17172. *
  17173. * ```javascript
  17174. * new Schema({ email: { type: String, lowercase: true }})
  17175. * ```
  17176. *
  17177. * Setters are also passed a second argument, the schematype on which the setter was defined. This allows for tailored behavior based on options passed in the schema.
  17178. *
  17179. * ```javascript
  17180. * function inspector (val, priorValue, schematype) {
  17181. * if (schematype.options.required) {
  17182. * return schematype.path + ' is required';
  17183. * } else {
  17184. * return val;
  17185. * }
  17186. * }
  17187. *
  17188. * const VirusSchema = new Schema({
  17189. * name: { type: String, required: true, set: inspector },
  17190. * taxonomy: { type: String, set: inspector }
  17191. * })
  17192. *
  17193. * const Virus = db.model('Virus', VirusSchema);
  17194. * const v = new Virus({ name: 'Parvoviridae', taxonomy: 'Parvovirinae' });
  17195. *
  17196. * console.log(v.name); // name is required
  17197. * console.log(v.taxonomy); // Parvovirinae
  17198. * ```
  17199. *
  17200. * You can also use setters to modify other properties on the document. If
  17201. * you're setting a property `name` on a document, the setter will run with
  17202. * `this` as the document. Be careful, in mongoose 5 setters will also run
  17203. * when querying by `name` with `this` as the query.
  17204. *
  17205. * ```javascript
  17206. * const nameSchema = new Schema({ name: String, keywords: [String] });
  17207. * nameSchema.path('name').set(function(v) {
  17208. * // Need to check if `this` is a document, because in mongoose 5
  17209. * // setters will also run on queries, in which case `this` will be a
  17210. * // mongoose query object.
  17211. * if (this instanceof Document && v != null) {
  17212. * this.keywords = v.split(' ');
  17213. * }
  17214. * return v;
  17215. * });
  17216. * ```
  17217. *
  17218. * @param {Function} fn
  17219. * @return {SchemaType} this
  17220. * @api public
  17221. */
  17222. SchemaType.prototype.set = function (fn) {
  17223. if (typeof fn !== 'function') {
  17224. throw new TypeError('A setter must be a function.');
  17225. }
  17226. this.setters.push(fn);
  17227. return this;
  17228. };
  17229. /**
  17230. * Adds a getter to this schematype.
  17231. *
  17232. * #### Example:
  17233. *
  17234. * function dob (val) {
  17235. * if (!val) return val;
  17236. * return (val.getMonth() + 1) + "/" + val.getDate() + "/" + val.getFullYear();
  17237. * }
  17238. *
  17239. * // defining within the schema
  17240. * const s = new Schema({ born: { type: Date, get: dob })
  17241. *
  17242. * // or by retreiving its SchemaType
  17243. * const s = new Schema({ born: Date })
  17244. * s.path('born').get(dob)
  17245. *
  17246. * Getters allow you to transform the representation of the data as it travels from the raw mongodb document to the value that you see.
  17247. *
  17248. * Suppose you are storing credit card numbers and you want to hide everything except the last 4 digits to the mongoose user. You can do so by defining a getter in the following way:
  17249. *
  17250. * function obfuscate (cc) {
  17251. * return '****-****-****-' + cc.slice(cc.length-4, cc.length);
  17252. * }
  17253. *
  17254. * const AccountSchema = new Schema({
  17255. * creditCardNumber: { type: String, get: obfuscate }
  17256. * });
  17257. *
  17258. * const Account = db.model('Account', AccountSchema);
  17259. *
  17260. * Account.findById(id, function (err, found) {
  17261. * console.log(found.creditCardNumber); // '****-****-****-1234'
  17262. * });
  17263. *
  17264. * Getters are also passed a second argument, the schematype on which the getter was defined. This allows for tailored behavior based on options passed in the schema.
  17265. *
  17266. * function inspector (val, priorValue, schematype) {
  17267. * if (schematype.options.required) {
  17268. * return schematype.path + ' is required';
  17269. * } else {
  17270. * return schematype.path + ' is not';
  17271. * }
  17272. * }
  17273. *
  17274. * const VirusSchema = new Schema({
  17275. * name: { type: String, required: true, get: inspector },
  17276. * taxonomy: { type: String, get: inspector }
  17277. * })
  17278. *
  17279. * const Virus = db.model('Virus', VirusSchema);
  17280. *
  17281. * Virus.findById(id, function (err, virus) {
  17282. * console.log(virus.name); // name is required
  17283. * console.log(virus.taxonomy); // taxonomy is not
  17284. * })
  17285. *
  17286. * @param {Function} fn
  17287. * @return {SchemaType} this
  17288. * @api public
  17289. */
  17290. SchemaType.prototype.get = function (fn) {
  17291. if (typeof fn !== 'function') {
  17292. throw new TypeError('A getter must be a function.');
  17293. }
  17294. this.getters.push(fn);
  17295. return this;
  17296. };
  17297. /**
  17298. * Adds validator(s) for this document path.
  17299. *
  17300. * Validators always receive the value to validate as their first argument and
  17301. * must return `Boolean`. Returning `false` or throwing an error means
  17302. * validation failed.
  17303. *
  17304. * The error message argument is optional. If not passed, the [default generic error message template](#error_messages_MongooseError-messages) will be used.
  17305. *
  17306. * #### Examples:
  17307. *
  17308. * // make sure every value is equal to "something"
  17309. * function validator (val) {
  17310. * return val === 'something';
  17311. * }
  17312. * new Schema({ name: { type: String, validate: validator }});
  17313. *
  17314. * // with a custom error message
  17315. *
  17316. * const custom = [validator, 'Uh oh, {PATH} does not equal "something".']
  17317. * new Schema({ name: { type: String, validate: custom }});
  17318. *
  17319. * // adding many validators at a time
  17320. *
  17321. * const many = [
  17322. * { validator: validator, msg: 'uh oh' }
  17323. * , { validator: anotherValidator, msg: 'failed' }
  17324. * ]
  17325. * new Schema({ name: { type: String, validate: many }});
  17326. *
  17327. * // or utilizing SchemaType methods directly:
  17328. *
  17329. * const schema = new Schema({ name: 'string' });
  17330. * schema.path('name').validate(validator, 'validation of `{PATH}` failed with value `{VALUE}`');
  17331. *
  17332. * #### Error message templates:
  17333. *
  17334. * From the examples above, you may have noticed that error messages support
  17335. * basic templating. There are a few other template keywords besides `{PATH}`
  17336. * and `{VALUE}` too. To find out more, details are available
  17337. * [here](#error_messages_MongooseError.messages).
  17338. *
  17339. * If Mongoose's built-in error message templating isn't enough, Mongoose
  17340. * supports setting the `message` property to a function.
  17341. *
  17342. * schema.path('name').validate({
  17343. * validator: function(v) { return v.length > 5; },
  17344. * // `errors['name']` will be "name must have length 5, got 'foo'"
  17345. * message: function(props) {
  17346. * return `${props.path} must have length 5, got '${props.value}'`;
  17347. * }
  17348. * });
  17349. *
  17350. * To bypass Mongoose's error messages and just copy the error message that
  17351. * the validator throws, do this:
  17352. *
  17353. * schema.path('name').validate({
  17354. * validator: function() { throw new Error('Oops!'); },
  17355. * // `errors['name']` will be "Oops!"
  17356. * message: function(props) { return props.reason.message; }
  17357. * });
  17358. *
  17359. * #### Asynchronous validation:
  17360. *
  17361. * Mongoose supports validators that return a promise. A validator that returns
  17362. * a promise is called an _async validator_. Async validators run in
  17363. * parallel, and `validate()` will wait until all async validators have settled.
  17364. *
  17365. * schema.path('name').validate({
  17366. * validator: function (value) {
  17367. * return new Promise(function (resolve, reject) {
  17368. * resolve(false); // validation failed
  17369. * });
  17370. * }
  17371. * });
  17372. *
  17373. * You might use asynchronous validators to retreive other documents from the database to validate against or to meet other I/O bound validation needs.
  17374. *
  17375. * Validation occurs `pre('save')` or whenever you manually execute [document#validate](#document_Document-validate).
  17376. *
  17377. * If validation fails during `pre('save')` and no callback was passed to receive the error, an `error` event will be emitted on your Models associated db [connection](#connection_Connection), passing the validation error object along.
  17378. *
  17379. * const conn = mongoose.createConnection(..);
  17380. * conn.on('error', handleError);
  17381. *
  17382. * const Product = conn.model('Product', yourSchema);
  17383. * const dvd = new Product(..);
  17384. * dvd.save(); // emits error on the `conn` above
  17385. *
  17386. * If you want to handle these errors at the Model level, add an `error`
  17387. * listener to your Model as shown below.
  17388. *
  17389. * // registering an error listener on the Model lets us handle errors more locally
  17390. * Product.on('error', handleError);
  17391. *
  17392. * @param {RegExp|Function|Object} obj validator function, or hash describing options
  17393. * @param {Function} [obj.validator] validator function. If the validator function returns `undefined` or a truthy value, validation succeeds. If it returns [falsy](https://masteringjs.io/tutorials/fundamentals/falsy) (except `undefined`) or throws an error, validation fails.
  17394. * @param {String|Function} [obj.message] optional error message. If function, should return the error message as a string
  17395. * @param {Boolean} [obj.propsParameter=false] If true, Mongoose will pass the validator properties object (with the `validator` function, `message`, etc.) as the 2nd arg to the validator function. This is disabled by default because many validators [rely on positional args](https://github.com/chriso/validator.js#validators), so turning this on may cause unpredictable behavior in external validators.
  17396. * @param {String|Function} [errorMsg] optional error message. If function, should return the error message as a string
  17397. * @param {String} [type] optional validator type
  17398. * @return {SchemaType} this
  17399. * @api public
  17400. */
  17401. SchemaType.prototype.validate = function (obj, message, type) {
  17402. if (typeof obj === 'function' || obj && utils.getFunctionName(obj.constructor) === 'RegExp') {
  17403. var properties;
  17404. if (typeof message === 'function') {
  17405. properties = {
  17406. validator: obj,
  17407. message: message
  17408. };
  17409. properties.type = type || 'user defined';
  17410. } else if (message instanceof Object && !type) {
  17411. properties = isSimpleValidator(message) ? Object.assign({}, message) : utils.clone(message);
  17412. if (!properties.message) {
  17413. properties.message = properties.msg;
  17414. }
  17415. properties.validator = obj;
  17416. properties.type = properties.type || 'user defined';
  17417. } else {
  17418. if (message == null) {
  17419. message = MongooseError.messages.general["default"];
  17420. }
  17421. if (!type) {
  17422. type = 'user defined';
  17423. }
  17424. properties = {
  17425. message: message,
  17426. type: type,
  17427. validator: obj
  17428. };
  17429. }
  17430. this.validators.push(properties);
  17431. return this;
  17432. }
  17433. var i;
  17434. var length;
  17435. var arg;
  17436. for (i = 0, length = arguments.length; i < length; i++) {
  17437. arg = arguments[i];
  17438. if (!utils.isPOJO(arg)) {
  17439. var msg = 'Invalid validator. Received (' + _typeof(arg) + ') ' + arg + '. See https://mongoosejs.com/docs/api.html#schematype_SchemaType-validate';
  17440. throw new Error(msg);
  17441. }
  17442. this.validate(arg.validator, arg);
  17443. }
  17444. return this;
  17445. };
  17446. /**
  17447. * Adds a required validator to this SchemaType. The validator gets added
  17448. * to the front of this SchemaType's validators array using `unshift()`.
  17449. *
  17450. * #### Example:
  17451. *
  17452. * const s = new Schema({ born: { type: Date, required: true })
  17453. *
  17454. * // or with custom error message
  17455. *
  17456. * const s = new Schema({ born: { type: Date, required: '{PATH} is required!' })
  17457. *
  17458. * // or with a function
  17459. *
  17460. * const s = new Schema({
  17461. * userId: ObjectId,
  17462. * username: {
  17463. * type: String,
  17464. * required: function() { return this.userId != null; }
  17465. * }
  17466. * })
  17467. *
  17468. * // or with a function and a custom message
  17469. * const s = new Schema({
  17470. * userId: ObjectId,
  17471. * username: {
  17472. * type: String,
  17473. * required: [
  17474. * function() { return this.userId != null; },
  17475. * 'username is required if id is specified'
  17476. * ]
  17477. * }
  17478. * })
  17479. *
  17480. * // or through the path API
  17481. *
  17482. * s.path('name').required(true);
  17483. *
  17484. * // with custom error messaging
  17485. *
  17486. * s.path('name').required(true, 'grrr :( ');
  17487. *
  17488. * // or make a path conditionally required based on a function
  17489. * const isOver18 = function() { return this.age >= 18; };
  17490. * s.path('voterRegistrationId').required(isOver18);
  17491. *
  17492. * The required validator uses the SchemaType's `checkRequired` function to
  17493. * determine whether a given value satisfies the required validator. By default,
  17494. * a value satisfies the required validator if `val != null` (that is, if
  17495. * the value is not null nor undefined). However, most built-in mongoose schema
  17496. * types override the default `checkRequired` function:
  17497. *
  17498. * @param {Boolean|Function|Object} required enable/disable the validator, or function that returns required boolean, or options object
  17499. * @param {Boolean|Function} [options.isRequired] enable/disable the validator, or function that returns required boolean
  17500. * @param {Function} [options.ErrorConstructor] custom error constructor. The constructor receives 1 parameter, an object containing the validator properties.
  17501. * @param {String} [message] optional custom error message
  17502. * @return {SchemaType} this
  17503. * @see Customized Error Messages #error_messages_MongooseError-messages
  17504. * @see SchemaArray#checkRequired #schema_array_SchemaArray.checkRequired
  17505. * @see SchemaBoolean#checkRequired #schema_boolean_SchemaBoolean-checkRequired
  17506. * @see SchemaBuffer#checkRequired #schema_buffer_SchemaBuffer.schemaName
  17507. * @see SchemaNumber#checkRequired #schema_number_SchemaNumber-min
  17508. * @see SchemaObjectId#checkRequired #schema_objectid_ObjectId-auto
  17509. * @see SchemaString#checkRequired #schema_string_SchemaString-checkRequired
  17510. * @api public
  17511. */
  17512. SchemaType.prototype.required = function (required, message) {
  17513. var customOptions = {};
  17514. if (arguments.length > 0 && required == null) {
  17515. this.validators = this.validators.filter(function (v) {
  17516. return v.validator !== this.requiredValidator;
  17517. }, this);
  17518. this.isRequired = false;
  17519. delete this.originalRequiredValue;
  17520. return this;
  17521. }
  17522. if (_typeof(required) === 'object') {
  17523. customOptions = required;
  17524. message = customOptions.message || message;
  17525. required = required.isRequired;
  17526. }
  17527. if (required === false) {
  17528. this.validators = this.validators.filter(function (v) {
  17529. return v.validator !== this.requiredValidator;
  17530. }, this);
  17531. this.isRequired = false;
  17532. delete this.originalRequiredValue;
  17533. return this;
  17534. }
  17535. var _this = this;
  17536. this.isRequired = true;
  17537. this.requiredValidator = function (v) {
  17538. var cachedRequired = this && this.$__ && this.$__.cachedRequired; // no validation when this path wasn't selected in the query.
  17539. if (cachedRequired != null && !this.$__isSelected(_this.path) && !this[documentIsModified](_this.path)) {
  17540. return true;
  17541. } // `$cachedRequired` gets set in `_evaluateRequiredFunctions()` so we
  17542. // don't call required functions multiple times in one validate call
  17543. // See gh-6801
  17544. if (cachedRequired != null && _this.path in cachedRequired) {
  17545. var res = cachedRequired[_this.path] ? _this.checkRequired(v, this) : true;
  17546. delete cachedRequired[_this.path];
  17547. return res;
  17548. } else if (typeof required === 'function') {
  17549. return required.apply(this) ? _this.checkRequired(v, this) : true;
  17550. }
  17551. return _this.checkRequired(v, this);
  17552. };
  17553. this.originalRequiredValue = required;
  17554. if (typeof required === 'string') {
  17555. message = required;
  17556. required = undefined;
  17557. }
  17558. var msg = message || MongooseError.messages.general.required;
  17559. this.validators.unshift(Object.assign({}, customOptions, {
  17560. validator: this.requiredValidator,
  17561. message: msg,
  17562. type: 'required'
  17563. }));
  17564. return this;
  17565. };
  17566. /**
  17567. * Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html)
  17568. * looks at to determine the foreign collection it should query.
  17569. *
  17570. * #### Example:
  17571. * const userSchema = new Schema({ name: String });
  17572. * const User = mongoose.model('User', userSchema);
  17573. *
  17574. * const postSchema = new Schema({ user: mongoose.ObjectId });
  17575. * postSchema.path('user').ref('User'); // Can set ref to a model name
  17576. * postSchema.path('user').ref(User); // Or a model class
  17577. * postSchema.path('user').ref(() => 'User'); // Or a function that returns the model name
  17578. * postSchema.path('user').ref(() => User); // Or a function that returns the model class
  17579. *
  17580. * // Or you can just declare the `ref` inline in your schema
  17581. * const postSchema2 = new Schema({
  17582. * user: { type: mongoose.ObjectId, ref: User }
  17583. * });
  17584. *
  17585. * @param {String|Model|Function} ref either a model name, a [Model](https://mongoosejs.com/docs/models.html), or a function that returns a model name or model.
  17586. * @return {SchemaType} this
  17587. * @api public
  17588. */
  17589. SchemaType.prototype.ref = function (ref) {
  17590. this.options.ref = ref;
  17591. return this;
  17592. };
  17593. /**
  17594. * Gets the default value
  17595. *
  17596. * @param {Object} scope the scope which callback are executed
  17597. * @param {Boolean} init
  17598. * @api private
  17599. */
  17600. SchemaType.prototype.getDefault = function (scope, init) {
  17601. var ret;
  17602. if (typeof this.defaultValue === 'function') {
  17603. if (this.defaultValue === Date.now || this.defaultValue === Array || this.defaultValue.name.toLowerCase() === 'objectid') {
  17604. ret = this.defaultValue.call(scope);
  17605. } else {
  17606. ret = this.defaultValue.call(scope, scope);
  17607. }
  17608. } else {
  17609. ret = this.defaultValue;
  17610. }
  17611. if (ret !== null && ret !== undefined) {
  17612. if (_typeof(ret) === 'object' && (!this.options || !this.options.shared)) {
  17613. ret = utils.clone(ret);
  17614. }
  17615. var casted = this.applySetters(ret, scope, init, undefined, setOptionsForDefaults);
  17616. if (casted && !Array.isArray(casted) && casted.$isSingleNested) {
  17617. casted.$__parent = scope;
  17618. }
  17619. return casted;
  17620. }
  17621. return ret;
  17622. };
  17623. /*!
  17624. * Applies setters without casting
  17625. *
  17626. * @api private
  17627. */
  17628. SchemaType.prototype._applySetters = function (value, scope, init, priorVal, options) {
  17629. var v = value;
  17630. if (init) {
  17631. return v;
  17632. }
  17633. var setters = this.setters;
  17634. for (var i = setters.length - 1; i >= 0; i--) {
  17635. v = setters[i].call(scope, v, priorVal, this, options);
  17636. }
  17637. return v;
  17638. };
  17639. /*!
  17640. * ignore
  17641. */
  17642. SchemaType.prototype._castNullish = function _castNullish(v) {
  17643. return v;
  17644. };
  17645. /**
  17646. * Applies setters
  17647. *
  17648. * @param {Object} value
  17649. * @param {Object} scope
  17650. * @param {Boolean} init
  17651. * @api private
  17652. */
  17653. SchemaType.prototype.applySetters = function (value, scope, init, priorVal, options) {
  17654. var v = this._applySetters(value, scope, init, priorVal, options);
  17655. if (v == null) {
  17656. return this._castNullish(v);
  17657. } // do not cast until all setters are applied #665
  17658. v = this.cast(v, scope, init, priorVal, options);
  17659. return v;
  17660. };
  17661. /**
  17662. * Applies getters to a value
  17663. *
  17664. * @param {Object} value
  17665. * @param {Object} scope
  17666. * @api private
  17667. */
  17668. SchemaType.prototype.applyGetters = function (value, scope) {
  17669. var v = value;
  17670. var getters = this.getters;
  17671. var len = getters.length;
  17672. if (len === 0) {
  17673. return v;
  17674. }
  17675. for (var i = 0; i < len; ++i) {
  17676. v = getters[i].call(scope, v, this);
  17677. }
  17678. return v;
  17679. };
  17680. /**
  17681. * Sets default `select()` behavior for this path.
  17682. *
  17683. * Set to `true` if this path should always be included in the results, `false` if it should be excluded by default. This setting can be overridden at the query level.
  17684. *
  17685. * #### Example:
  17686. *
  17687. * T = db.model('T', new Schema({ x: { type: String, select: true }}));
  17688. * T.find(..); // field x will always be selected ..
  17689. * // .. unless overridden;
  17690. * T.find().select('-x').exec(callback);
  17691. *
  17692. * @param {Boolean} val
  17693. * @return {SchemaType} this
  17694. * @api public
  17695. */
  17696. SchemaType.prototype.select = function select(val) {
  17697. this.selected = !!val;
  17698. return this;
  17699. };
  17700. /**
  17701. * Performs a validation of `value` using the validators declared for this SchemaType.
  17702. *
  17703. * @param {any} value
  17704. * @param {Function} callback
  17705. * @param {Object} scope
  17706. * @api private
  17707. */
  17708. SchemaType.prototype.doValidate = function (value, fn, scope, options) {
  17709. var _this2 = this;
  17710. var err = false;
  17711. var path = this.path; // Avoid non-object `validators`
  17712. var validators = this.validators.filter(function (v) {
  17713. return _typeof(v) === 'object' && v !== null;
  17714. });
  17715. var count = validators.length;
  17716. if (!count) {
  17717. return fn(null);
  17718. }
  17719. var _loop = function _loop(i, len) {
  17720. if (err) {
  17721. return "break";
  17722. }
  17723. var v = validators[i];
  17724. var validator = v.validator;
  17725. var ok = void 0;
  17726. var validatorProperties = isSimpleValidator(v) ? Object.assign({}, v) : utils.clone(v);
  17727. validatorProperties.path = options && options.path ? options.path : path;
  17728. validatorProperties.value = value;
  17729. if (validator instanceof RegExp) {
  17730. validate(validator.test(value), validatorProperties);
  17731. return "continue";
  17732. }
  17733. if (typeof validator !== 'function') {
  17734. return "continue";
  17735. }
  17736. if (value === undefined && validator !== _this2.requiredValidator) {
  17737. validate(true, validatorProperties);
  17738. return "continue";
  17739. }
  17740. try {
  17741. if (validatorProperties.propsParameter) {
  17742. ok = validator.call(scope, value, validatorProperties);
  17743. } else {
  17744. ok = validator.call(scope, value);
  17745. }
  17746. } catch (error) {
  17747. ok = false;
  17748. validatorProperties.reason = error;
  17749. if (error.message) {
  17750. validatorProperties.message = error.message;
  17751. }
  17752. }
  17753. if (ok != null && typeof ok.then === 'function') {
  17754. ok.then(function (ok) {
  17755. validate(ok, validatorProperties);
  17756. }, function (error) {
  17757. validatorProperties.reason = error;
  17758. validatorProperties.message = error.message;
  17759. ok = false;
  17760. validate(ok, validatorProperties);
  17761. });
  17762. } else {
  17763. validate(ok, validatorProperties);
  17764. }
  17765. };
  17766. for (var i = 0, len = validators.length; i < len; ++i) {
  17767. var _ret = _loop(i, len);
  17768. if (_ret === "break") break;
  17769. if (_ret === "continue") continue;
  17770. }
  17771. function validate(ok, validatorProperties) {
  17772. if (err) {
  17773. return;
  17774. }
  17775. if (ok === undefined || ok) {
  17776. if (--count <= 0) {
  17777. immediate(function () {
  17778. fn(null);
  17779. });
  17780. }
  17781. } else {
  17782. var ErrorConstructor = validatorProperties.ErrorConstructor || ValidatorError;
  17783. err = new ErrorConstructor(validatorProperties);
  17784. err[validatorErrorSymbol] = true;
  17785. immediate(function () {
  17786. fn(err);
  17787. });
  17788. }
  17789. }
  17790. };
  17791. function _validate(ok, validatorProperties) {
  17792. if (ok !== undefined && !ok) {
  17793. var ErrorConstructor = validatorProperties.ErrorConstructor || ValidatorError;
  17794. var err = new ErrorConstructor(validatorProperties);
  17795. err[validatorErrorSymbol] = true;
  17796. return err;
  17797. }
  17798. }
  17799. /**
  17800. * Performs a validation of `value` using the validators declared for this SchemaType.
  17801. *
  17802. * #### Note:
  17803. *
  17804. * This method ignores the asynchronous validators.
  17805. *
  17806. * @param {any} value
  17807. * @param {Object} scope
  17808. * @return {MongooseError|undefined}
  17809. * @api private
  17810. */
  17811. SchemaType.prototype.doValidateSync = function (value, scope, options) {
  17812. var path = this.path;
  17813. var count = this.validators.length;
  17814. if (!count) {
  17815. return null;
  17816. }
  17817. var validators = this.validators;
  17818. if (value === void 0) {
  17819. if (this.validators.length !== 0 && this.validators[0].type === 'required') {
  17820. validators = [this.validators[0]];
  17821. } else {
  17822. return null;
  17823. }
  17824. }
  17825. var err = null;
  17826. var i = 0;
  17827. var len = validators.length;
  17828. for (i = 0; i < len; ++i) {
  17829. var v = validators[i];
  17830. if (v === null || _typeof(v) !== 'object') {
  17831. continue;
  17832. }
  17833. var validator = v.validator;
  17834. var validatorProperties = isSimpleValidator(v) ? Object.assign({}, v) : utils.clone(v);
  17835. validatorProperties.path = options && options.path ? options.path : path;
  17836. validatorProperties.value = value;
  17837. var ok = false; // Skip any explicit async validators. Validators that return a promise
  17838. // will still run, but won't trigger any errors.
  17839. if (isAsyncFunction(validator)) {
  17840. continue;
  17841. }
  17842. if (validator instanceof RegExp) {
  17843. err = _validate(validator.test(value), validatorProperties);
  17844. continue;
  17845. }
  17846. if (typeof validator !== 'function') {
  17847. continue;
  17848. }
  17849. try {
  17850. if (validatorProperties.propsParameter) {
  17851. ok = validator.call(scope, value, validatorProperties);
  17852. } else {
  17853. ok = validator.call(scope, value);
  17854. }
  17855. } catch (error) {
  17856. ok = false;
  17857. validatorProperties.reason = error;
  17858. } // Skip any validators that return a promise, we can't handle those
  17859. // synchronously
  17860. if (ok != null && typeof ok.then === 'function') {
  17861. continue;
  17862. }
  17863. err = _validate(ok, validatorProperties);
  17864. if (err) {
  17865. break;
  17866. }
  17867. }
  17868. return err;
  17869. };
  17870. /**
  17871. * Determines if value is a valid Reference.
  17872. *
  17873. * @param {SchemaType} self
  17874. * @param {Object} value
  17875. * @param {Document} doc
  17876. * @param {Boolean} init
  17877. * @return {Boolean}
  17878. * @api private
  17879. */
  17880. SchemaType._isRef = function (self, value, doc, init) {
  17881. // fast path
  17882. var ref = init && self.options && (self.options.ref || self.options.refPath);
  17883. if (!ref && doc && doc.$__ != null) {
  17884. // checks for
  17885. // - this populated with adhoc model and no ref was set in schema OR
  17886. // - setting / pushing values after population
  17887. var path = doc.$__fullPath(self.path, true);
  17888. var owner = doc.ownerDocument();
  17889. ref = path != null && owner.$populated(path) || doc.$populated(self.path);
  17890. }
  17891. if (ref) {
  17892. if (value == null) {
  17893. return true;
  17894. }
  17895. if (!Buffer.isBuffer(value) && // buffers are objects too
  17896. value._bsontype !== 'Binary' // raw binary value from the db
  17897. && utils.isObject(value) // might have deselected _id in population query
  17898. ) {
  17899. return true;
  17900. }
  17901. return init;
  17902. }
  17903. return false;
  17904. };
  17905. /*!
  17906. * ignore
  17907. */
  17908. SchemaType.prototype._castRef = function _castRef(value, doc, init) {
  17909. if (value == null) {
  17910. return value;
  17911. }
  17912. if (value.$__ != null) {
  17913. value.$__.wasPopulated = value.$__.wasPopulated || true;
  17914. return value;
  17915. } // setting a populated path
  17916. if (Buffer.isBuffer(value) || !utils.isObject(value)) {
  17917. if (init) {
  17918. return value;
  17919. }
  17920. throw new CastError(this.instance, value, this.path, null, this);
  17921. } // Handle the case where user directly sets a populated
  17922. // path to a plain object; cast to the Model used in
  17923. // the population query.
  17924. var path = doc.$__fullPath(this.path, true);
  17925. var owner = doc.ownerDocument();
  17926. var pop = owner.$populated(path, true);
  17927. var ret = value;
  17928. if (!doc.$__.populated || !doc.$__.populated[path] || !doc.$__.populated[path].options || !doc.$__.populated[path].options.options || !doc.$__.populated[path].options.options.lean) {
  17929. ret = new pop.options[populateModelSymbol](value);
  17930. ret.$__.wasPopulated = true;
  17931. }
  17932. return ret;
  17933. };
  17934. /*!
  17935. * ignore
  17936. */
  17937. function handleSingle(val) {
  17938. return this.castForQuery(val);
  17939. }
  17940. /*!
  17941. * ignore
  17942. */
  17943. function handleArray(val) {
  17944. var _this = this;
  17945. if (!Array.isArray(val)) {
  17946. return [this.castForQuery(val)];
  17947. }
  17948. return val.map(function (m) {
  17949. return _this.castForQuery(m);
  17950. });
  17951. }
  17952. /*!
  17953. * Just like handleArray, except also allows `[]` because surprisingly
  17954. * `$in: [1, []]` works fine
  17955. */
  17956. function handle$in(val) {
  17957. var _this = this;
  17958. if (!Array.isArray(val)) {
  17959. return [this.castForQuery(val)];
  17960. }
  17961. return val.map(function (m) {
  17962. if (Array.isArray(m) && m.length === 0) {
  17963. return m;
  17964. }
  17965. return _this.castForQuery(m);
  17966. });
  17967. }
  17968. /*!
  17969. * ignore
  17970. */
  17971. SchemaType.prototype.$conditionalHandlers = {
  17972. $all: handleArray,
  17973. $eq: handleSingle,
  17974. $in: handle$in,
  17975. $ne: handleSingle,
  17976. $nin: handle$in,
  17977. $exists: $exists,
  17978. $type: $type
  17979. };
  17980. /*!
  17981. * Wraps `castForQuery` to handle context
  17982. */
  17983. SchemaType.prototype.castForQueryWrapper = function (params) {
  17984. this.$$context = params.context;
  17985. if ('$conditional' in params) {
  17986. var _ret2 = this.castForQuery(params.$conditional, params.val);
  17987. this.$$context = null;
  17988. return _ret2;
  17989. }
  17990. if (params.$skipQueryCastForUpdate || params.$applySetters) {
  17991. var _ret3 = this._castForQuery(params.val);
  17992. this.$$context = null;
  17993. return _ret3;
  17994. }
  17995. var ret = this.castForQuery(params.val);
  17996. this.$$context = null;
  17997. return ret;
  17998. };
  17999. /**
  18000. * Cast the given value with the given optional query operator.
  18001. *
  18002. * @param {String} [$conditional] query operator, like `$eq` or `$in`
  18003. * @param {any} val
  18004. * @api private
  18005. */
  18006. SchemaType.prototype.castForQuery = function ($conditional, val) {
  18007. var handler;
  18008. if (arguments.length === 2) {
  18009. handler = this.$conditionalHandlers[$conditional];
  18010. if (!handler) {
  18011. throw new Error('Can\'t use ' + $conditional);
  18012. }
  18013. return handler.call(this, val);
  18014. }
  18015. val = $conditional;
  18016. return this._castForQuery(val);
  18017. };
  18018. /*!
  18019. * Internal switch for runSetters
  18020. *
  18021. * @api private
  18022. */
  18023. SchemaType.prototype._castForQuery = function (val) {
  18024. return this.applySetters(val, this.$$context);
  18025. };
  18026. /**
  18027. * Override the function the required validator uses to check whether a value
  18028. * passes the `required` check. Override this on the individual SchemaType.
  18029. *
  18030. * #### Example:
  18031. *
  18032. * // Use this to allow empty strings to pass the `required` validator
  18033. * mongoose.Schema.Types.String.checkRequired(v => typeof v === 'string');
  18034. *
  18035. * @param {Function} fn
  18036. * @return {Function}
  18037. * @static
  18038. * @receiver SchemaType
  18039. * @function checkRequired
  18040. * @api public
  18041. */
  18042. SchemaType.checkRequired = function (fn) {
  18043. if (arguments.length !== 0) {
  18044. this._checkRequired = fn;
  18045. }
  18046. return this._checkRequired;
  18047. };
  18048. /**
  18049. * Default check for if this path satisfies the `required` validator.
  18050. *
  18051. * @param {any} val
  18052. * @api private
  18053. */
  18054. SchemaType.prototype.checkRequired = function (val) {
  18055. return val != null;
  18056. };
  18057. /*!
  18058. * ignore
  18059. */
  18060. SchemaType.prototype.clone = function () {
  18061. var options = Object.assign({}, this.options);
  18062. var schematype = new this.constructor(this.path, options, this.instance);
  18063. schematype.validators = this.validators.slice();
  18064. if (this.requiredValidator !== undefined) schematype.requiredValidator = this.requiredValidator;
  18065. if (this.defaultValue !== undefined) schematype.defaultValue = this.defaultValue;
  18066. if (this.$immutable !== undefined && this.options.immutable === undefined) {
  18067. schematype.$immutable = this.$immutable;
  18068. handleImmutable(schematype);
  18069. }
  18070. if (this._index !== undefined) schematype._index = this._index;
  18071. if (this.selected !== undefined) schematype.selected = this.selected;
  18072. if (this.isRequired !== undefined) schematype.isRequired = this.isRequired;
  18073. if (this.originalRequiredValue !== undefined) schematype.originalRequiredValue = this.originalRequiredValue;
  18074. schematype.getters = this.getters.slice();
  18075. schematype.setters = this.setters.slice();
  18076. return schematype;
  18077. };
  18078. /*!
  18079. * Module exports.
  18080. */
  18081. module.exports = exports = SchemaType;
  18082. exports.CastError = CastError;
  18083. exports.ValidatorError = ValidatorError;
  18084. /***/ }),
  18085. /***/ 489:
  18086. /***/ ((module, exports, __webpack_require__) => {
  18087. "use strict";
  18088. /*!
  18089. * Module dependencies.
  18090. */
  18091. var utils = __webpack_require__(6872); // eslint-disable-line no-unused-vars
  18092. /*!
  18093. * StateMachine represents a minimal `interface` for the
  18094. * constructors it builds via StateMachine.ctor(...).
  18095. *
  18096. * @api private
  18097. */
  18098. var StateMachine = module.exports = exports = function StateMachine() {};
  18099. /*!
  18100. * StateMachine.ctor('state1', 'state2', ...)
  18101. * A factory method for subclassing StateMachine.
  18102. * The arguments are a list of states. For each state,
  18103. * the constructor's prototype gets state transition
  18104. * methods named after each state. These transition methods
  18105. * place their path argument into the given state.
  18106. *
  18107. * @param {String} state
  18108. * @param {String} [state]
  18109. * @return {Function} subclass constructor
  18110. * @private
  18111. */
  18112. StateMachine.ctor = function () {
  18113. var states = Array.prototype.slice.call(arguments);
  18114. var ctor = function ctor() {
  18115. StateMachine.apply(this, arguments);
  18116. this.paths = {};
  18117. this.states = {};
  18118. this.stateNames = states;
  18119. var i = states.length,
  18120. state;
  18121. while (i--) {
  18122. state = states[i];
  18123. this.states[state] = {};
  18124. }
  18125. };
  18126. ctor.prototype = new StateMachine();
  18127. states.forEach(function (state) {
  18128. // Changes the `path`'s state to `state`.
  18129. ctor.prototype[state] = function (path) {
  18130. this._changeState(path, state);
  18131. };
  18132. });
  18133. return ctor;
  18134. };
  18135. /*!
  18136. * This function is wrapped by the state change functions:
  18137. *
  18138. * - `require(path)`
  18139. * - `modify(path)`
  18140. * - `init(path)`
  18141. *
  18142. * @api private
  18143. */
  18144. StateMachine.prototype._changeState = function _changeState(path, nextState) {
  18145. var prevBucket = this.states[this.paths[path]];
  18146. if (prevBucket) delete prevBucket[path];
  18147. this.paths[path] = nextState;
  18148. this.states[nextState][path] = true;
  18149. };
  18150. /*!
  18151. * ignore
  18152. */
  18153. StateMachine.prototype.clear = function clear(state) {
  18154. var keys = Object.keys(this.states[state]);
  18155. var i = keys.length;
  18156. var path;
  18157. while (i--) {
  18158. path = keys[i];
  18159. delete this.states[state][path];
  18160. delete this.paths[path];
  18161. }
  18162. };
  18163. /*!
  18164. * ignore
  18165. */
  18166. StateMachine.prototype.clearPath = function clearPath(path) {
  18167. var state = this.paths[path];
  18168. if (!state) {
  18169. return;
  18170. }
  18171. delete this.paths[path];
  18172. delete this.states[state][path];
  18173. };
  18174. /*!
  18175. * Checks to see if at least one path is in the states passed in via `arguments`
  18176. * e.g., this.some('required', 'inited')
  18177. *
  18178. * @param {String} state that we want to check for.
  18179. * @private
  18180. */
  18181. StateMachine.prototype.some = function some() {
  18182. var _this = this;
  18183. var what = arguments.length ? arguments : this.stateNames;
  18184. return Array.prototype.some.call(what, function (state) {
  18185. return Object.keys(_this.states[state]).length;
  18186. });
  18187. };
  18188. /*!
  18189. * This function builds the functions that get assigned to `forEach` and `map`,
  18190. * since both of those methods share a lot of the same logic.
  18191. *
  18192. * @param {String} iterMethod is either 'forEach' or 'map'
  18193. * @return {Function}
  18194. * @api private
  18195. */
  18196. StateMachine.prototype._iter = function _iter(iterMethod) {
  18197. return function () {
  18198. var states = Array.prototype.slice.call(arguments);
  18199. var callback = states.pop();
  18200. if (!states.length) states = this.stateNames;
  18201. var _this = this;
  18202. var paths = states.reduce(function (paths, state) {
  18203. return paths.concat(Object.keys(_this.states[state]));
  18204. }, []);
  18205. return paths[iterMethod](function (path, i, paths) {
  18206. return callback(path, i, paths);
  18207. });
  18208. };
  18209. };
  18210. /*!
  18211. * Iterates over the paths that belong to one of the parameter states.
  18212. *
  18213. * The function profile can look like:
  18214. * this.forEach(state1, fn); // iterates over all paths in state1
  18215. * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
  18216. * this.forEach(fn); // iterates over all paths in all states
  18217. *
  18218. * @param {String} [state]
  18219. * @param {String} [state]
  18220. * @param {Function} callback
  18221. * @private
  18222. */
  18223. StateMachine.prototype.forEach = function forEach() {
  18224. this.forEach = this._iter('forEach');
  18225. return this.forEach.apply(this, arguments);
  18226. };
  18227. /*!
  18228. * Maps over the paths that belong to one of the parameter states.
  18229. *
  18230. * The function profile can look like:
  18231. * this.forEach(state1, fn); // iterates over all paths in state1
  18232. * this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
  18233. * this.forEach(fn); // iterates over all paths in all states
  18234. *
  18235. * @param {String} [state]
  18236. * @param {String} [state]
  18237. * @param {Function} callback
  18238. * @return {Array}
  18239. * @private
  18240. */
  18241. StateMachine.prototype.map = function map() {
  18242. this.map = this._iter('map');
  18243. return this.map.apply(this, arguments);
  18244. };
  18245. /***/ }),
  18246. /***/ 1568:
  18247. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  18248. "use strict";
  18249. /*!
  18250. * Module dependencies.
  18251. */
  18252. var EventEmitter = (__webpack_require__(9620).EventEmitter);
  18253. var Subdocument = __webpack_require__(2591);
  18254. var utils = __webpack_require__(6872);
  18255. var documentArrayParent = (__webpack_require__(8770).documentArrayParent);
  18256. /*!
  18257. * A constructor.
  18258. *
  18259. * @param {Object} obj js object returned from the db
  18260. * @param {MongooseDocumentArray} parentArr the parent array of this document
  18261. * @param {Boolean} skipId
  18262. * @inherits Document
  18263. * @api private
  18264. */
  18265. function ArraySubdocument(obj, parentArr, skipId, fields, index) {
  18266. if (utils.isMongooseDocumentArray(parentArr)) {
  18267. this.__parentArray = parentArr;
  18268. this[documentArrayParent] = parentArr.$parent();
  18269. } else {
  18270. this.__parentArray = undefined;
  18271. this[documentArrayParent] = undefined;
  18272. }
  18273. this.$setIndex(index);
  18274. this.$__parent = this[documentArrayParent];
  18275. Subdocument.call(this, obj, fields, this[documentArrayParent], skipId, {
  18276. isNew: true
  18277. });
  18278. }
  18279. /*!
  18280. * Inherit from Subdocument
  18281. */
  18282. ArraySubdocument.prototype = Object.create(Subdocument.prototype);
  18283. ArraySubdocument.prototype.constructor = ArraySubdocument;
  18284. Object.defineProperty(ArraySubdocument.prototype, '$isSingleNested', {
  18285. configurable: false,
  18286. writable: false,
  18287. value: false
  18288. });
  18289. Object.defineProperty(ArraySubdocument.prototype, '$isDocumentArrayElement', {
  18290. configurable: false,
  18291. writable: false,
  18292. value: true
  18293. });
  18294. for (var i in EventEmitter.prototype) {
  18295. ArraySubdocument[i] = EventEmitter.prototype[i];
  18296. }
  18297. /*!
  18298. * ignore
  18299. */
  18300. ArraySubdocument.prototype.$setIndex = function (index) {
  18301. this.__index = index;
  18302. if (this.$__ != null && this.$__.validationError != null) {
  18303. var keys = Object.keys(this.$__.validationError.errors);
  18304. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  18305. var key = _keys[_i];
  18306. this.invalidate(key, this.$__.validationError.errors[key]);
  18307. }
  18308. }
  18309. };
  18310. /*!
  18311. * ignore
  18312. */
  18313. ArraySubdocument.prototype.populate = function () {
  18314. throw new Error('Mongoose does not support calling populate() on nested ' + 'docs. Instead of `doc.arr[0].populate("path")`, use ' + '`doc.populate("arr.0.path")`');
  18315. };
  18316. /*!
  18317. * ignore
  18318. */
  18319. ArraySubdocument.prototype.$__removeFromParent = function () {
  18320. var _id = this._doc._id;
  18321. if (!_id) {
  18322. throw new Error('For your own good, Mongoose does not know ' + 'how to remove an ArraySubdocument that has no _id');
  18323. }
  18324. this.__parentArray.pull({
  18325. _id: _id
  18326. });
  18327. };
  18328. /**
  18329. * Returns the full path to this document. If optional `path` is passed, it is appended to the full path.
  18330. *
  18331. * @param {String} [path]
  18332. * @param {Boolean} [skipIndex] Skip adding the array index. For example `arr.foo` instead of `arr.0.foo`.
  18333. * @return {String}
  18334. * @api private
  18335. * @method $__fullPath
  18336. * @memberOf ArraySubdocument
  18337. * @instance
  18338. */
  18339. ArraySubdocument.prototype.$__fullPath = function (path, skipIndex) {
  18340. if (this.__index == null) {
  18341. return null;
  18342. }
  18343. if (!this.$__.fullPath) {
  18344. this.ownerDocument();
  18345. }
  18346. if (skipIndex) {
  18347. return path ? this.$__.fullPath + '.' + path : this.$__.fullPath;
  18348. }
  18349. return path ? this.$__.fullPath + '.' + this.__index + '.' + path : this.$__.fullPath + '.' + this.__index;
  18350. };
  18351. /*!
  18352. * Given a path relative to this document, return the path relative
  18353. * to the top-level document.
  18354. */
  18355. ArraySubdocument.prototype.$__pathRelativeToParent = function (path, skipIndex) {
  18356. if (this.__index == null) {
  18357. return null;
  18358. }
  18359. if (skipIndex) {
  18360. return path == null ? this.__parentArray.$path() : this.__parentArray.$path() + '.' + path;
  18361. }
  18362. if (path == null) {
  18363. return this.__parentArray.$path() + '.' + this.__index;
  18364. }
  18365. return this.__parentArray.$path() + '.' + this.__index + '.' + path;
  18366. };
  18367. /*!
  18368. * Returns this sub-documents parent document.
  18369. */
  18370. ArraySubdocument.prototype.$parent = function () {
  18371. return this[documentArrayParent];
  18372. };
  18373. /**
  18374. * Returns this subdocument's parent array.
  18375. *
  18376. * #### Example:
  18377. *
  18378. * const Test = mongoose.model('Test', new Schema({
  18379. * docArr: [{ name: String }]
  18380. * }));
  18381. * const doc = new Test({ docArr: [{ name: 'test subdoc' }] });
  18382. *
  18383. * doc.docArr[0].parentArray() === doc.docArr; // true
  18384. *
  18385. * @api public
  18386. * @method parentArray
  18387. * @returns DocumentArray
  18388. */
  18389. ArraySubdocument.prototype.parentArray = function () {
  18390. return this.__parentArray;
  18391. };
  18392. /*!
  18393. * Module exports.
  18394. */
  18395. module.exports = ArraySubdocument;
  18396. /***/ }),
  18397. /***/ 6077:
  18398. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  18399. "use strict";
  18400. /*!
  18401. * Module dependencies.
  18402. */
  18403. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  18404. var ArrayMethods = __webpack_require__(8075);
  18405. var DocumentArrayMethods = __webpack_require__(9261);
  18406. var Document = __webpack_require__(8727);
  18407. var arrayAtomicsSymbol = (__webpack_require__(8770).arrayAtomicsSymbol);
  18408. var arrayAtomicsBackupSymbol = (__webpack_require__(8770).arrayAtomicsBackupSymbol);
  18409. var arrayParentSymbol = (__webpack_require__(8770).arrayParentSymbol);
  18410. var arrayPathSymbol = (__webpack_require__(8770).arrayPathSymbol);
  18411. var arraySchemaSymbol = (__webpack_require__(8770).arraySchemaSymbol);
  18412. var _basePush = Array.prototype.push;
  18413. var numberRE = /^\d+$/;
  18414. /**
  18415. * DocumentArray constructor
  18416. *
  18417. * @param {Array} values
  18418. * @param {String} path the path to this array
  18419. * @param {Document} doc parent document
  18420. * @api private
  18421. * @return {MongooseDocumentArray}
  18422. * @inherits MongooseArray
  18423. * @see https://bit.ly/f6CnZU
  18424. */
  18425. function MongooseDocumentArray(values, path, doc) {
  18426. var _internals;
  18427. var __array = [];
  18428. var internals = (_internals = {}, _defineProperty(_internals, arrayAtomicsSymbol, {}), _defineProperty(_internals, arrayAtomicsBackupSymbol, void 0), _defineProperty(_internals, arrayPathSymbol, path), _defineProperty(_internals, arraySchemaSymbol, void 0), _defineProperty(_internals, arrayParentSymbol, void 0), _internals);
  18429. if (Array.isArray(values)) {
  18430. if (values[arrayPathSymbol] === path && values[arrayParentSymbol] === doc) {
  18431. internals[arrayAtomicsSymbol] = Object.assign({}, values[arrayAtomicsSymbol]);
  18432. }
  18433. values.forEach(function (v) {
  18434. _basePush.call(__array, v);
  18435. });
  18436. }
  18437. internals[arrayPathSymbol] = path;
  18438. internals.__array = __array; // Because doc comes from the context of another function, doc === global
  18439. // can happen if there was a null somewhere up the chain (see #3020 && #3034)
  18440. // RB Jun 17, 2015 updated to check for presence of expected paths instead
  18441. // to make more proof against unusual node environments
  18442. if (doc && doc instanceof Document) {
  18443. internals[arrayParentSymbol] = doc;
  18444. internals[arraySchemaSymbol] = doc.schema.path(path); // `schema.path()` doesn't drill into nested arrays properly yet, see
  18445. // gh-6398, gh-6602. This is a workaround because nested arrays are
  18446. // always plain non-document arrays, so once you get to a document array
  18447. // nesting is done. Matryoshka code.
  18448. while (internals[arraySchemaSymbol] != null && internals[arraySchemaSymbol].$isMongooseArray && !internals[arraySchemaSymbol].$isMongooseDocumentArray) {
  18449. internals[arraySchemaSymbol] = internals[arraySchemaSymbol].casterConstructor;
  18450. }
  18451. }
  18452. var proxy = new Proxy(__array, {
  18453. get: function get(target, prop) {
  18454. if (prop === 'isMongooseArray' || prop === 'isMongooseArrayProxy' || prop === 'isMongooseDocumentArray' || prop === 'isMongooseDocumentArrayProxy') {
  18455. return true;
  18456. }
  18457. if (internals.hasOwnProperty(prop)) {
  18458. return internals[prop];
  18459. }
  18460. if (DocumentArrayMethods.hasOwnProperty(prop)) {
  18461. return DocumentArrayMethods[prop];
  18462. }
  18463. if (ArrayMethods.hasOwnProperty(prop)) {
  18464. return ArrayMethods[prop];
  18465. }
  18466. return __array[prop];
  18467. },
  18468. set: function set(target, prop, value) {
  18469. if (typeof prop === 'string' && numberRE.test(prop)) {
  18470. DocumentArrayMethods.set.call(proxy, prop, value, false);
  18471. } else if (internals.hasOwnProperty(prop)) {
  18472. internals[prop] = value;
  18473. } else {
  18474. __array[prop] = value;
  18475. }
  18476. return true;
  18477. }
  18478. });
  18479. return proxy;
  18480. }
  18481. /*!
  18482. * Module exports.
  18483. */
  18484. module.exports = MongooseDocumentArray;
  18485. /***/ }),
  18486. /***/ 1255:
  18487. /***/ ((__unused_webpack_module, exports) => {
  18488. "use strict";
  18489. exports.isMongooseDocumentArray = function (mongooseDocumentArray) {
  18490. return Array.isArray(mongooseDocumentArray) && mongooseDocumentArray.isMongooseDocumentArray;
  18491. };
  18492. /***/ }),
  18493. /***/ 9261:
  18494. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  18495. "use strict";
  18496. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  18497. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  18498. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  18499. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  18500. var ArrayMethods = __webpack_require__(8075);
  18501. var Document = __webpack_require__(8727);
  18502. var castObjectId = __webpack_require__(4731);
  18503. var getDiscriminatorByValue = __webpack_require__(7291);
  18504. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  18505. var utils = __webpack_require__(6872);
  18506. var isBsonType = __webpack_require__(1563);
  18507. var arrayParentSymbol = (__webpack_require__(8770).arrayParentSymbol);
  18508. var arrayPathSymbol = (__webpack_require__(8770).arrayPathSymbol);
  18509. var arraySchemaSymbol = (__webpack_require__(8770).arraySchemaSymbol);
  18510. var documentArrayParent = (__webpack_require__(8770).documentArrayParent);
  18511. var methods = {
  18512. /*!
  18513. * ignore
  18514. */
  18515. toBSON: function toBSON() {
  18516. return this.toObject(internalToObjectOptions);
  18517. },
  18518. /*!
  18519. * ignore
  18520. */
  18521. getArrayParent: function getArrayParent() {
  18522. return this[arrayParentSymbol];
  18523. },
  18524. /**
  18525. * Overrides MongooseArray#cast
  18526. *
  18527. * @method _cast
  18528. * @api private
  18529. * @receiver MongooseDocumentArray
  18530. */
  18531. _cast: function _cast(value, index) {
  18532. if (this[arraySchemaSymbol] == null) {
  18533. return value;
  18534. }
  18535. var Constructor = this[arraySchemaSymbol].casterConstructor;
  18536. var isInstance = Constructor.$isMongooseDocumentArray ? utils.isMongooseDocumentArray(value) : value instanceof Constructor;
  18537. if (isInstance || // Hack re: #5001, see #5005
  18538. value && value.constructor && value.constructor.baseCasterConstructor === Constructor) {
  18539. if (!(value[documentArrayParent] && value.__parentArray)) {
  18540. // value may have been created using array.create()
  18541. value[documentArrayParent] = this[arrayParentSymbol];
  18542. value.__parentArray = this;
  18543. }
  18544. value.$setIndex(index);
  18545. return value;
  18546. }
  18547. if (value === undefined || value === null) {
  18548. return null;
  18549. } // handle cast('string') or cast(ObjectId) etc.
  18550. // only objects are permitted so we can safely assume that
  18551. // non-objects are to be interpreted as _id
  18552. if (Buffer.isBuffer(value) || isBsonType(value, 'ObjectID') || !utils.isObject(value)) {
  18553. value = {
  18554. _id: value
  18555. };
  18556. }
  18557. if (value && Constructor.discriminators && Constructor.schema && Constructor.schema.options && Constructor.schema.options.discriminatorKey) {
  18558. if (typeof value[Constructor.schema.options.discriminatorKey] === 'string' && Constructor.discriminators[value[Constructor.schema.options.discriminatorKey]]) {
  18559. Constructor = Constructor.discriminators[value[Constructor.schema.options.discriminatorKey]];
  18560. } else {
  18561. var constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[Constructor.schema.options.discriminatorKey]);
  18562. if (constructorByValue) {
  18563. Constructor = constructorByValue;
  18564. }
  18565. }
  18566. }
  18567. if (Constructor.$isMongooseDocumentArray) {
  18568. return Constructor.cast(value, this, undefined, undefined, index);
  18569. }
  18570. var ret = new Constructor(value, this, undefined, undefined, index);
  18571. ret.isNew = true;
  18572. return ret;
  18573. },
  18574. /**
  18575. * Searches array items for the first document with a matching _id.
  18576. *
  18577. * #### Example:
  18578. *
  18579. * const embeddedDoc = m.array.id(some_id);
  18580. *
  18581. * @return {EmbeddedDocument|null} the subdocument or null if not found.
  18582. * @param {ObjectId|String|Number|Buffer} id
  18583. * @TODO cast to the _id based on schema for proper comparison
  18584. * @method id
  18585. * @api public
  18586. * @memberOf MongooseDocumentArray
  18587. */
  18588. id: function id(_id2) {
  18589. var casted;
  18590. var sid;
  18591. var _id;
  18592. try {
  18593. casted = castObjectId(_id2).toString();
  18594. } catch (e) {
  18595. casted = null;
  18596. }
  18597. var _iterator = _createForOfIteratorHelper(this),
  18598. _step;
  18599. try {
  18600. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  18601. var val = _step.value;
  18602. if (!val) {
  18603. continue;
  18604. }
  18605. _id = val.get('_id');
  18606. if (_id === null || typeof _id === 'undefined') {
  18607. continue;
  18608. } else if (_id instanceof Document) {
  18609. sid || (sid = String(_id2));
  18610. if (sid == _id._id) {
  18611. return val;
  18612. }
  18613. } else if (!isBsonType(_id2, 'ObjectID') && !isBsonType(_id, 'ObjectID')) {
  18614. if (_id2 == _id || utils.deepEqual(_id2, _id)) {
  18615. return val;
  18616. }
  18617. } else if (casted == _id) {
  18618. return val;
  18619. }
  18620. }
  18621. } catch (err) {
  18622. _iterator.e(err);
  18623. } finally {
  18624. _iterator.f();
  18625. }
  18626. return null;
  18627. },
  18628. /**
  18629. * Returns a native js Array of plain js objects
  18630. *
  18631. * #### Note:
  18632. *
  18633. * _Each sub-document is converted to a plain object by calling its `#toObject` method._
  18634. *
  18635. * @param {Object} [options] optional options to pass to each documents `toObject` method call during conversion
  18636. * @return {Array}
  18637. * @method toObject
  18638. * @api public
  18639. * @memberOf MongooseDocumentArray
  18640. */
  18641. toObject: function toObject(options) {
  18642. // `[].concat` coerces the return value into a vanilla JS array, rather
  18643. // than a Mongoose array.
  18644. return [].concat(this.map(function (doc) {
  18645. if (doc == null) {
  18646. return null;
  18647. }
  18648. if (typeof doc.toObject !== 'function') {
  18649. return doc;
  18650. }
  18651. return doc.toObject(options);
  18652. }));
  18653. },
  18654. $toObject: function $toObject() {
  18655. return this.constructor.prototype.toObject.apply(this, arguments);
  18656. },
  18657. /**
  18658. * Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
  18659. *
  18660. * @param {Object} [args...]
  18661. * @api public
  18662. * @method push
  18663. * @memberOf MongooseDocumentArray
  18664. */
  18665. push: function push() {
  18666. var ret = ArrayMethods.push.apply(this, arguments);
  18667. _updateParentPopulated(this);
  18668. return ret;
  18669. },
  18670. /**
  18671. * Pulls items from the array atomically.
  18672. *
  18673. * @param {Object} [args...]
  18674. * @api public
  18675. * @method pull
  18676. * @memberOf MongooseDocumentArray
  18677. */
  18678. pull: function pull() {
  18679. var ret = ArrayMethods.pull.apply(this, arguments);
  18680. _updateParentPopulated(this);
  18681. return ret;
  18682. },
  18683. /*!
  18684. * Wraps [`Array#shift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
  18685. */
  18686. shift: function shift() {
  18687. var ret = ArrayMethods.shift.apply(this, arguments);
  18688. _updateParentPopulated(this);
  18689. return ret;
  18690. },
  18691. /*!
  18692. * Wraps [`Array#splice`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) with proper change tracking and casting.
  18693. */
  18694. splice: function splice() {
  18695. var ret = ArrayMethods.splice.apply(this, arguments);
  18696. _updateParentPopulated(this);
  18697. return ret;
  18698. },
  18699. /**
  18700. * Helper for console.log
  18701. *
  18702. * @method inspect
  18703. * @api public
  18704. * @memberOf MongooseDocumentArray
  18705. */
  18706. inspect: function inspect() {
  18707. return this.toObject();
  18708. },
  18709. /**
  18710. * Creates a subdocument casted to this schema.
  18711. *
  18712. * This is the same subdocument constructor used for casting.
  18713. *
  18714. * @param {Object} obj the value to cast to this arrays SubDocument schema
  18715. * @method create
  18716. * @api public
  18717. * @memberOf MongooseDocumentArray
  18718. */
  18719. create: function create(obj) {
  18720. var Constructor = this[arraySchemaSymbol].casterConstructor;
  18721. if (obj && Constructor.discriminators && Constructor.schema && Constructor.schema.options && Constructor.schema.options.discriminatorKey) {
  18722. if (typeof obj[Constructor.schema.options.discriminatorKey] === 'string' && Constructor.discriminators[obj[Constructor.schema.options.discriminatorKey]]) {
  18723. Constructor = Constructor.discriminators[obj[Constructor.schema.options.discriminatorKey]];
  18724. } else {
  18725. var constructorByValue = getDiscriminatorByValue(Constructor.discriminators, obj[Constructor.schema.options.discriminatorKey]);
  18726. if (constructorByValue) {
  18727. Constructor = constructorByValue;
  18728. }
  18729. }
  18730. }
  18731. return new Constructor(obj, this);
  18732. },
  18733. /*!
  18734. * ignore
  18735. */
  18736. notify: function notify(event) {
  18737. var _this = this;
  18738. return function notify(val, _arr) {
  18739. _arr = _arr || _this;
  18740. var i = _arr.length;
  18741. while (i--) {
  18742. if (_arr[i] == null) {
  18743. continue;
  18744. }
  18745. switch (event) {
  18746. // only swap for save event for now, we may change this to all event types later
  18747. case 'save':
  18748. val = _this[i];
  18749. break;
  18750. default:
  18751. // NO-OP
  18752. break;
  18753. }
  18754. if (utils.isMongooseArray(_arr[i])) {
  18755. notify(val, _arr[i]);
  18756. } else if (_arr[i]) {
  18757. _arr[i].emit(event, val);
  18758. }
  18759. }
  18760. };
  18761. },
  18762. set: function set(i, val, skipModified) {
  18763. var arr = this.__array;
  18764. if (skipModified) {
  18765. arr[i] = val;
  18766. return this;
  18767. }
  18768. var value = methods._cast.call(this, val, i);
  18769. methods._markModified.call(this, i);
  18770. arr[i] = value;
  18771. return this;
  18772. },
  18773. _markModified: function _markModified(elem, embeddedPath) {
  18774. var parent = this[arrayParentSymbol];
  18775. var dirtyPath;
  18776. if (parent) {
  18777. dirtyPath = this[arrayPathSymbol];
  18778. if (arguments.length) {
  18779. if (embeddedPath != null) {
  18780. // an embedded doc bubbled up the change
  18781. var index = elem.__index;
  18782. dirtyPath = dirtyPath + '.' + index + '.' + embeddedPath;
  18783. } else {
  18784. // directly set an index
  18785. dirtyPath = dirtyPath + '.' + elem;
  18786. }
  18787. }
  18788. if (dirtyPath != null && dirtyPath.endsWith('.$')) {
  18789. return this;
  18790. }
  18791. parent.markModified(dirtyPath, arguments.length !== 0 ? elem : parent);
  18792. }
  18793. return this;
  18794. }
  18795. };
  18796. module.exports = methods;
  18797. /*!
  18798. * If this is a document array, each element may contain single
  18799. * populated paths, so we need to modify the top-level document's
  18800. * populated cache. See gh-8247, gh-8265.
  18801. */
  18802. function _updateParentPopulated(arr) {
  18803. var parent = arr[arrayParentSymbol];
  18804. if (!parent || parent.$__.populated == null) return;
  18805. var populatedPaths = Object.keys(parent.$__.populated).filter(function (p) {
  18806. return p.startsWith(arr[arrayPathSymbol] + '.');
  18807. });
  18808. var _iterator2 = _createForOfIteratorHelper(populatedPaths),
  18809. _step2;
  18810. try {
  18811. var _loop = function _loop() {
  18812. var path = _step2.value;
  18813. var remnant = path.slice((arr[arrayPathSymbol] + '.').length);
  18814. if (!Array.isArray(parent.$__.populated[path].value)) {
  18815. return "continue";
  18816. }
  18817. parent.$__.populated[path].value = arr.map(function (val) {
  18818. return val.$populated(remnant);
  18819. });
  18820. };
  18821. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  18822. var _ret = _loop();
  18823. if (_ret === "continue") continue;
  18824. }
  18825. } catch (err) {
  18826. _iterator2.e(err);
  18827. } finally {
  18828. _iterator2.f();
  18829. }
  18830. }
  18831. /***/ }),
  18832. /***/ 1362:
  18833. /***/ ((module, exports, __webpack_require__) => {
  18834. "use strict";
  18835. /*!
  18836. * Module dependencies.
  18837. */
  18838. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  18839. var Document = __webpack_require__(8727);
  18840. var mongooseArrayMethods = __webpack_require__(8075);
  18841. var arrayAtomicsSymbol = (__webpack_require__(8770).arrayAtomicsSymbol);
  18842. var arrayAtomicsBackupSymbol = (__webpack_require__(8770).arrayAtomicsBackupSymbol);
  18843. var arrayParentSymbol = (__webpack_require__(8770).arrayParentSymbol);
  18844. var arrayPathSymbol = (__webpack_require__(8770).arrayPathSymbol);
  18845. var arraySchemaSymbol = (__webpack_require__(8770).arraySchemaSymbol);
  18846. /**
  18847. * Mongoose Array constructor.
  18848. *
  18849. * #### Note:
  18850. *
  18851. * _Values always have to be passed to the constructor to initialize, otherwise `MongooseArray#push` will mark the array as modified._
  18852. *
  18853. * @param {Array} values
  18854. * @param {String} path
  18855. * @param {Document} doc parent document
  18856. * @api private
  18857. * @inherits Array
  18858. * @see https://bit.ly/f6CnZU
  18859. */
  18860. var _basePush = Array.prototype.push;
  18861. var numberRE = /^\d+$/;
  18862. function MongooseArray(values, path, doc, schematype) {
  18863. var _internals;
  18864. var __array;
  18865. if (Array.isArray(values)) {
  18866. var len = values.length; // Perf optimizations for small arrays: much faster to use `...` than `for` + `push`,
  18867. // but large arrays may cause stack overflows. And for arrays of length 0/1, just
  18868. // modifying the array is faster. Seems small, but adds up when you have a document
  18869. // with thousands of nested arrays.
  18870. if (len === 0) {
  18871. __array = new Array();
  18872. } else if (len === 1) {
  18873. __array = new Array(1);
  18874. __array[0] = values[0];
  18875. } else if (len < 10000) {
  18876. __array = new Array();
  18877. _basePush.apply(__array, values);
  18878. } else {
  18879. __array = new Array();
  18880. for (var i = 0; i < len; ++i) {
  18881. _basePush.call(__array, values[i]);
  18882. }
  18883. }
  18884. } else {
  18885. __array = [];
  18886. }
  18887. var internals = (_internals = {}, _defineProperty(_internals, arrayAtomicsSymbol, {}), _defineProperty(_internals, arrayAtomicsBackupSymbol, void 0), _defineProperty(_internals, arrayPathSymbol, path), _defineProperty(_internals, arraySchemaSymbol, schematype), _defineProperty(_internals, arrayParentSymbol, void 0), _defineProperty(_internals, "isMongooseArray", true), _defineProperty(_internals, "isMongooseArrayProxy", true), _defineProperty(_internals, "__array", __array), _internals);
  18888. if (values && values[arrayAtomicsSymbol] != null) {
  18889. internals[arrayAtomicsSymbol] = values[arrayAtomicsSymbol];
  18890. } // Because doc comes from the context of another function, doc === global
  18891. // can happen if there was a null somewhere up the chain (see #3020)
  18892. // RB Jun 17, 2015 updated to check for presence of expected paths instead
  18893. // to make more proof against unusual node environments
  18894. if (doc != null && doc instanceof Document) {
  18895. internals[arrayParentSymbol] = doc;
  18896. internals[arraySchemaSymbol] = schematype || doc.schema.path(path);
  18897. }
  18898. var proxy = new Proxy(__array, {
  18899. get: function get(target, prop) {
  18900. if (internals.hasOwnProperty(prop)) {
  18901. return internals[prop];
  18902. }
  18903. if (mongooseArrayMethods.hasOwnProperty(prop)) {
  18904. return mongooseArrayMethods[prop];
  18905. }
  18906. return __array[prop];
  18907. },
  18908. set: function set(target, prop, value) {
  18909. if (typeof prop === 'string' && numberRE.test(prop)) {
  18910. mongooseArrayMethods.set.call(proxy, prop, value, false);
  18911. } else if (internals.hasOwnProperty(prop)) {
  18912. internals[prop] = value;
  18913. } else {
  18914. __array[prop] = value;
  18915. }
  18916. return true;
  18917. }
  18918. });
  18919. return proxy;
  18920. }
  18921. /*!
  18922. * Module exports.
  18923. */
  18924. module.exports = exports = MongooseArray;
  18925. /***/ }),
  18926. /***/ 7339:
  18927. /***/ ((__unused_webpack_module, exports) => {
  18928. "use strict";
  18929. exports.isMongooseArray = function (mongooseArray) {
  18930. return Array.isArray(mongooseArray) && mongooseArray.isMongooseArray;
  18931. };
  18932. /***/ }),
  18933. /***/ 8075:
  18934. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  18935. "use strict";
  18936. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  18937. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  18938. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  18939. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  18940. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  18941. var Document = __webpack_require__(8727);
  18942. var ArraySubdocument = __webpack_require__(1568);
  18943. var MongooseError = __webpack_require__(5202);
  18944. var cleanModifiedSubpaths = __webpack_require__(4134);
  18945. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  18946. var utils = __webpack_require__(6872);
  18947. var isBsonType = __webpack_require__(1563);
  18948. var arrayAtomicsSymbol = (__webpack_require__(8770).arrayAtomicsSymbol);
  18949. var arrayParentSymbol = (__webpack_require__(8770).arrayParentSymbol);
  18950. var arrayPathSymbol = (__webpack_require__(8770).arrayPathSymbol);
  18951. var arraySchemaSymbol = (__webpack_require__(8770).arraySchemaSymbol);
  18952. var populateModelSymbol = (__webpack_require__(8770).populateModelSymbol);
  18953. var slicedSymbol = Symbol('mongoose#Array#sliced');
  18954. var _basePush = Array.prototype.push;
  18955. /*!
  18956. * ignore
  18957. */
  18958. var methods = {
  18959. /**
  18960. * Depopulates stored atomic operation values as necessary for direct insertion to MongoDB.
  18961. *
  18962. * If no atomics exist, we return all array values after conversion.
  18963. *
  18964. * @return {Array}
  18965. * @method $__getAtomics
  18966. * @memberOf MongooseArray
  18967. * @instance
  18968. * @api private
  18969. */
  18970. $__getAtomics: function $__getAtomics() {
  18971. var ret = [];
  18972. var keys = Object.keys(this[arrayAtomicsSymbol] || {});
  18973. var i = keys.length;
  18974. var opts = Object.assign({}, internalToObjectOptions, {
  18975. _isNested: true
  18976. });
  18977. if (i === 0) {
  18978. ret[0] = ['$set', this.toObject(opts)];
  18979. return ret;
  18980. }
  18981. while (i--) {
  18982. var op = keys[i];
  18983. var val = this[arrayAtomicsSymbol][op]; // the atomic values which are arrays are not MongooseArrays. we
  18984. // need to convert their elements as if they were MongooseArrays
  18985. // to handle populated arrays versus DocumentArrays properly.
  18986. if (utils.isMongooseObject(val)) {
  18987. val = val.toObject(opts);
  18988. } else if (Array.isArray(val)) {
  18989. val = this.toObject.call(val, opts);
  18990. } else if (val != null && Array.isArray(val.$each)) {
  18991. val.$each = this.toObject.call(val.$each, opts);
  18992. } else if (val != null && typeof val.valueOf === 'function') {
  18993. val = val.valueOf();
  18994. }
  18995. if (op === '$addToSet') {
  18996. val = {
  18997. $each: val
  18998. };
  18999. }
  19000. ret.push([op, val]);
  19001. }
  19002. return ret;
  19003. },
  19004. /*!
  19005. * ignore
  19006. */
  19007. $atomics: function $atomics() {
  19008. return this[arrayAtomicsSymbol];
  19009. },
  19010. /*!
  19011. * ignore
  19012. */
  19013. $parent: function $parent() {
  19014. return this[arrayParentSymbol];
  19015. },
  19016. /*!
  19017. * ignore
  19018. */
  19019. $path: function $path() {
  19020. return this[arrayPathSymbol];
  19021. },
  19022. /**
  19023. * Atomically shifts the array at most one time per document `save()`.
  19024. *
  19025. * #### Note:
  19026. *
  19027. * _Calling this multiple times on an array before saving sends the same command as calling it once._
  19028. * _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
  19029. *
  19030. * doc.array = [1,2,3];
  19031. *
  19032. * const shifted = doc.array.$shift();
  19033. * console.log(shifted); // 1
  19034. * console.log(doc.array); // [2,3]
  19035. *
  19036. * // no affect
  19037. * shifted = doc.array.$shift();
  19038. * console.log(doc.array); // [2,3]
  19039. *
  19040. * doc.save(function (err) {
  19041. * if (err) return handleError(err);
  19042. *
  19043. * // we saved, now $shift works again
  19044. * shifted = doc.array.$shift();
  19045. * console.log(shifted ); // 2
  19046. * console.log(doc.array); // [3]
  19047. * })
  19048. *
  19049. * @api public
  19050. * @memberOf MongooseArray
  19051. * @instance
  19052. * @method $shift
  19053. * @see mongodb https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop
  19054. */
  19055. $shift: function $shift() {
  19056. this._registerAtomic('$pop', -1);
  19057. this._markModified(); // only allow shifting once
  19058. if (this._shifted) {
  19059. return;
  19060. }
  19061. this._shifted = true;
  19062. return [].shift.call(this);
  19063. },
  19064. /**
  19065. * Pops the array atomically at most one time per document `save()`.
  19066. *
  19067. * #### NOTE:
  19068. *
  19069. * _Calling this multiple times on an array before saving sends the same command as calling it once._
  19070. * _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
  19071. *
  19072. * doc.array = [1,2,3];
  19073. *
  19074. * const popped = doc.array.$pop();
  19075. * console.log(popped); // 3
  19076. * console.log(doc.array); // [1,2]
  19077. *
  19078. * // no affect
  19079. * popped = doc.array.$pop();
  19080. * console.log(doc.array); // [1,2]
  19081. *
  19082. * doc.save(function (err) {
  19083. * if (err) return handleError(err);
  19084. *
  19085. * // we saved, now $pop works again
  19086. * popped = doc.array.$pop();
  19087. * console.log(popped); // 2
  19088. * console.log(doc.array); // [1]
  19089. * })
  19090. *
  19091. * @api public
  19092. * @method $pop
  19093. * @memberOf MongooseArray
  19094. * @instance
  19095. * @see mongodb https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop
  19096. * @method $pop
  19097. * @memberOf MongooseArray
  19098. */
  19099. $pop: function $pop() {
  19100. this._registerAtomic('$pop', 1);
  19101. this._markModified(); // only allow popping once
  19102. if (this._popped) {
  19103. return;
  19104. }
  19105. this._popped = true;
  19106. return [].pop.call(this);
  19107. },
  19108. /*!
  19109. * ignore
  19110. */
  19111. $schema: function $schema() {
  19112. return this[arraySchemaSymbol];
  19113. },
  19114. /**
  19115. * Casts a member based on this arrays schema.
  19116. *
  19117. * @param {any} value
  19118. * @return value the casted value
  19119. * @method _cast
  19120. * @api private
  19121. * @memberOf MongooseArray
  19122. */
  19123. _cast: function _cast(value) {
  19124. var populated = false;
  19125. var Model;
  19126. var parent = this[arrayParentSymbol];
  19127. if (parent) {
  19128. populated = parent.$populated(this[arrayPathSymbol], true);
  19129. }
  19130. if (populated && value !== null && value !== undefined) {
  19131. // cast to the populated Models schema
  19132. Model = populated.options[populateModelSymbol]; // only objects are permitted so we can safely assume that
  19133. // non-objects are to be interpreted as _id
  19134. if (Buffer.isBuffer(value) || isBsonType(value, 'ObjectID') || !utils.isObject(value)) {
  19135. value = {
  19136. _id: value
  19137. };
  19138. } // gh-2399
  19139. // we should cast model only when it's not a discriminator
  19140. var isDisc = value.schema && value.schema.discriminatorMapping && value.schema.discriminatorMapping.key !== undefined;
  19141. if (!isDisc) {
  19142. value = new Model(value);
  19143. }
  19144. return this[arraySchemaSymbol].caster.applySetters(value, parent, true);
  19145. }
  19146. return this[arraySchemaSymbol].caster.applySetters(value, parent, false);
  19147. },
  19148. /**
  19149. * Internal helper for .map()
  19150. *
  19151. * @api private
  19152. * @return {Number}
  19153. * @method _mapCast
  19154. * @memberOf MongooseArray
  19155. */
  19156. _mapCast: function _mapCast(val, index) {
  19157. return this._cast(val, this.length + index);
  19158. },
  19159. /**
  19160. * Marks this array as modified.
  19161. *
  19162. * If it bubbles up from an embedded document change, then it takes the following arguments (otherwise, takes 0 arguments)
  19163. *
  19164. * @param {ArraySubdocument} subdoc the embedded doc that invoked this method on the Array
  19165. * @param {String} embeddedPath the path which changed in the subdoc
  19166. * @method _markModified
  19167. * @api private
  19168. * @memberOf MongooseArray
  19169. */
  19170. _markModified: function _markModified(elem) {
  19171. var parent = this[arrayParentSymbol];
  19172. var dirtyPath;
  19173. if (parent) {
  19174. dirtyPath = this[arrayPathSymbol];
  19175. if (arguments.length) {
  19176. dirtyPath = dirtyPath + '.' + elem;
  19177. }
  19178. if (dirtyPath != null && dirtyPath.endsWith('.$')) {
  19179. return this;
  19180. }
  19181. parent.markModified(dirtyPath, arguments.length !== 0 ? elem : parent);
  19182. }
  19183. return this;
  19184. },
  19185. /**
  19186. * Register an atomic operation with the parent.
  19187. *
  19188. * @param {Array} op operation
  19189. * @param {any} val
  19190. * @method _registerAtomic
  19191. * @api private
  19192. * @memberOf MongooseArray
  19193. */
  19194. _registerAtomic: function _registerAtomic(op, val) {
  19195. if (this[slicedSymbol]) {
  19196. return;
  19197. }
  19198. if (op === '$set') {
  19199. // $set takes precedence over all other ops.
  19200. // mark entire array modified.
  19201. this[arrayAtomicsSymbol] = {
  19202. $set: val
  19203. };
  19204. cleanModifiedSubpaths(this[arrayParentSymbol], this[arrayPathSymbol]);
  19205. this._markModified();
  19206. return this;
  19207. }
  19208. var atomics = this[arrayAtomicsSymbol]; // reset pop/shift after save
  19209. if (op === '$pop' && !('$pop' in atomics)) {
  19210. var _this = this;
  19211. this[arrayParentSymbol].once('save', function () {
  19212. _this._popped = _this._shifted = null;
  19213. });
  19214. } // check for impossible $atomic combos (Mongo denies more than one
  19215. // $atomic op on a single path
  19216. if (atomics.$set || Object.keys(atomics).length && !(op in atomics)) {
  19217. // a different op was previously registered.
  19218. // save the entire thing.
  19219. this[arrayAtomicsSymbol] = {
  19220. $set: this
  19221. };
  19222. return this;
  19223. }
  19224. var selector;
  19225. if (op === '$pullAll' || op === '$addToSet') {
  19226. atomics[op] || (atomics[op] = []);
  19227. atomics[op] = atomics[op].concat(val);
  19228. } else if (op === '$pullDocs') {
  19229. var pullOp = atomics['$pull'] || (atomics['$pull'] = {});
  19230. if (val[0] instanceof ArraySubdocument) {
  19231. selector = pullOp['$or'] || (pullOp['$or'] = []);
  19232. Array.prototype.push.apply(selector, val.map(function (v) {
  19233. return v.toObject({
  19234. transform: false,
  19235. virtuals: false
  19236. });
  19237. }));
  19238. } else {
  19239. selector = pullOp['_id'] || (pullOp['_id'] = {
  19240. $in: []
  19241. });
  19242. selector['$in'] = selector['$in'].concat(val);
  19243. }
  19244. } else if (op === '$push') {
  19245. atomics.$push = atomics.$push || {
  19246. $each: []
  19247. };
  19248. if (val != null && utils.hasUserDefinedProperty(val, '$each')) {
  19249. atomics.$push = val;
  19250. } else {
  19251. atomics.$push.$each = atomics.$push.$each.concat(val);
  19252. }
  19253. } else {
  19254. atomics[op] = val;
  19255. }
  19256. return this;
  19257. },
  19258. /**
  19259. * Adds values to the array if not already present.
  19260. *
  19261. * #### Example:
  19262. *
  19263. * console.log(doc.array) // [2,3,4]
  19264. * const added = doc.array.addToSet(4,5);
  19265. * console.log(doc.array) // [2,3,4,5]
  19266. * console.log(added) // [5]
  19267. *
  19268. * @param {any} [args...]
  19269. * @return {Array} the values that were added
  19270. * @memberOf MongooseArray
  19271. * @api public
  19272. * @method addToSet
  19273. */
  19274. addToSet: function addToSet() {
  19275. _checkManualPopulation(this, arguments);
  19276. var values = [].map.call(arguments, this._mapCast, this);
  19277. values = this[arraySchemaSymbol].applySetters(values, this[arrayParentSymbol]);
  19278. var added = [];
  19279. var type = '';
  19280. if (values[0] instanceof ArraySubdocument) {
  19281. type = 'doc';
  19282. } else if (values[0] instanceof Date) {
  19283. type = 'date';
  19284. }
  19285. var rawValues = utils.isMongooseArray(values) ? values.__array : this;
  19286. var rawArray = utils.isMongooseArray(this) ? this.__array : this;
  19287. rawValues.forEach(function (v) {
  19288. var found;
  19289. var val = +v;
  19290. switch (type) {
  19291. case 'doc':
  19292. found = this.some(function (doc) {
  19293. return doc.equals(v);
  19294. });
  19295. break;
  19296. case 'date':
  19297. found = this.some(function (d) {
  19298. return +d === val;
  19299. });
  19300. break;
  19301. default:
  19302. found = ~this.indexOf(v);
  19303. }
  19304. if (!found) {
  19305. this._markModified();
  19306. rawArray.push(v);
  19307. this._registerAtomic('$addToSet', v);
  19308. [].push.call(added, v);
  19309. }
  19310. }, this);
  19311. return added;
  19312. },
  19313. /**
  19314. * Returns the number of pending atomic operations to send to the db for this array.
  19315. *
  19316. * @api private
  19317. * @return {Number}
  19318. * @method hasAtomics
  19319. * @memberOf MongooseArray
  19320. */
  19321. hasAtomics: function hasAtomics() {
  19322. if (!utils.isPOJO(this[arrayAtomicsSymbol])) {
  19323. return 0;
  19324. }
  19325. return Object.keys(this[arrayAtomicsSymbol]).length;
  19326. },
  19327. /**
  19328. * Return whether or not the `obj` is included in the array.
  19329. *
  19330. * @param {Object} obj the item to check
  19331. * @param {Number} fromIndex
  19332. * @return {Boolean}
  19333. * @api public
  19334. * @method includes
  19335. * @memberOf MongooseArray
  19336. */
  19337. includes: function includes(obj, fromIndex) {
  19338. var ret = this.indexOf(obj, fromIndex);
  19339. return ret !== -1;
  19340. },
  19341. /**
  19342. * Return the index of `obj` or `-1` if not found.
  19343. *
  19344. * @param {Object} obj the item to look for
  19345. * @param {Number} fromIndex
  19346. * @return {Number}
  19347. * @api public
  19348. * @method indexOf
  19349. * @memberOf MongooseArray
  19350. */
  19351. indexOf: function indexOf(obj, fromIndex) {
  19352. if (isBsonType(obj, 'ObjectID')) {
  19353. obj = obj.toString();
  19354. }
  19355. fromIndex = fromIndex == null ? 0 : fromIndex;
  19356. var len = this.length;
  19357. for (var i = fromIndex; i < len; ++i) {
  19358. if (obj == this[i]) {
  19359. return i;
  19360. }
  19361. }
  19362. return -1;
  19363. },
  19364. /**
  19365. * Helper for console.log
  19366. *
  19367. * @api public
  19368. * @method inspect
  19369. * @memberOf MongooseArray
  19370. */
  19371. inspect: function inspect() {
  19372. return JSON.stringify(this);
  19373. },
  19374. /**
  19375. * Pushes items to the array non-atomically.
  19376. *
  19377. * #### Note:
  19378. *
  19379. * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
  19380. *
  19381. * @param {any} [args...]
  19382. * @api public
  19383. * @method nonAtomicPush
  19384. * @memberOf MongooseArray
  19385. */
  19386. nonAtomicPush: function nonAtomicPush() {
  19387. var values = [].map.call(arguments, this._mapCast, this);
  19388. this._markModified();
  19389. var ret = [].push.apply(this, values);
  19390. this._registerAtomic('$set', this);
  19391. return ret;
  19392. },
  19393. /**
  19394. * Wraps [`Array#pop`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/pop) with proper change tracking.
  19395. *
  19396. * #### Note:
  19397. *
  19398. * _marks the entire array as modified which will pass the entire thing to $set potentially overwriting any changes that happen between when you retrieved the object and when you save it._
  19399. *
  19400. * @see MongooseArray#$pop #types_array_MongooseArray-%24pop
  19401. * @api public
  19402. * @method pop
  19403. * @memberOf MongooseArray
  19404. */
  19405. pop: function pop() {
  19406. this._markModified();
  19407. var ret = [].pop.call(this);
  19408. this._registerAtomic('$set', this);
  19409. return ret;
  19410. },
  19411. /**
  19412. * Pulls items from the array atomically. Equality is determined by casting
  19413. * the provided value to an embedded document and comparing using
  19414. * [the `Document.equals()` function.](/docs/api.html#document_Document-equals)
  19415. *
  19416. * #### Examples:
  19417. *
  19418. * doc.array.pull(ObjectId)
  19419. * doc.array.pull({ _id: 'someId' })
  19420. * doc.array.pull(36)
  19421. * doc.array.pull('tag 1', 'tag 2')
  19422. *
  19423. * To remove a document from a subdocument array we may pass an object with a matching `_id`.
  19424. *
  19425. * doc.subdocs.push({ _id: 4815162342 })
  19426. * doc.subdocs.pull({ _id: 4815162342 }) // removed
  19427. *
  19428. * Or we may passing the _id directly and let mongoose take care of it.
  19429. *
  19430. * doc.subdocs.push({ _id: 4815162342 })
  19431. * doc.subdocs.pull(4815162342); // works
  19432. *
  19433. * The first pull call will result in a atomic operation on the database, if pull is called repeatedly without saving the document, a $set operation is used on the complete array instead, overwriting possible changes that happened on the database in the meantime.
  19434. *
  19435. * @param {any} [args...]
  19436. * @see mongodb https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pull
  19437. * @api public
  19438. * @method pull
  19439. * @memberOf MongooseArray
  19440. */
  19441. pull: function pull() {
  19442. var values = [].map.call(arguments, this._cast, this);
  19443. var cur = this[arrayParentSymbol].get(this[arrayPathSymbol]);
  19444. var i = cur.length;
  19445. var mem;
  19446. this._markModified();
  19447. while (i--) {
  19448. mem = cur[i];
  19449. if (mem instanceof Document) {
  19450. var some = values.some(function (v) {
  19451. return mem.equals(v);
  19452. });
  19453. if (some) {
  19454. [].splice.call(cur, i, 1);
  19455. }
  19456. } else if (~cur.indexOf.call(values, mem)) {
  19457. [].splice.call(cur, i, 1);
  19458. }
  19459. }
  19460. if (values[0] instanceof ArraySubdocument) {
  19461. this._registerAtomic('$pullDocs', values.map(function (v) {
  19462. return v.$__getValue('_id') || v;
  19463. }));
  19464. } else {
  19465. this._registerAtomic('$pullAll', values);
  19466. } // Might have modified child paths and then pulled, like
  19467. // `doc.children[1].name = 'test';` followed by
  19468. // `doc.children.remove(doc.children[0]);`. In this case we fall back
  19469. // to a `$set` on the whole array. See #3511
  19470. if (cleanModifiedSubpaths(this[arrayParentSymbol], this[arrayPathSymbol]) > 0) {
  19471. this._registerAtomic('$set', this);
  19472. }
  19473. return this;
  19474. },
  19475. /**
  19476. * Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
  19477. *
  19478. * #### Example:
  19479. *
  19480. * const schema = Schema({ nums: [Number] });
  19481. * const Model = mongoose.model('Test', schema);
  19482. *
  19483. * const doc = await Model.create({ nums: [3, 4] });
  19484. * doc.nums.push(5); // Add 5 to the end of the array
  19485. * await doc.save();
  19486. *
  19487. * // You can also pass an object with `$each` as the
  19488. * // first parameter to use MongoDB's `$position`
  19489. * doc.nums.push({
  19490. * $each: [1, 2],
  19491. * $position: 0
  19492. * });
  19493. * doc.nums; // [1, 2, 3, 4, 5]
  19494. *
  19495. * @param {Object} [args...]
  19496. * @api public
  19497. * @method push
  19498. * @memberOf MongooseArray
  19499. */
  19500. push: function push() {
  19501. var values = arguments;
  19502. var atomic = values;
  19503. var isOverwrite = values[0] != null && utils.hasUserDefinedProperty(values[0], '$each');
  19504. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19505. if (isOverwrite) {
  19506. atomic = values[0];
  19507. values = values[0].$each;
  19508. }
  19509. if (this[arraySchemaSymbol] == null) {
  19510. return _basePush.apply(this, values);
  19511. }
  19512. _checkManualPopulation(this, values);
  19513. var parent = this[arrayParentSymbol];
  19514. values = [].map.call(values, this._mapCast, this);
  19515. values = this[arraySchemaSymbol].applySetters(values, parent, undefined, undefined, {
  19516. skipDocumentArrayCast: true
  19517. });
  19518. var ret;
  19519. var atomics = this[arrayAtomicsSymbol];
  19520. this._markModified();
  19521. if (isOverwrite) {
  19522. atomic.$each = values;
  19523. if ((atomics.$push && atomics.$push.$each && atomics.$push.$each.length || 0) !== 0 && atomics.$push.$position != atomic.$position) {
  19524. throw new MongooseError('Cannot call `Array#push()` multiple times ' + 'with different `$position`');
  19525. }
  19526. if (atomic.$position != null) {
  19527. [].splice.apply(arr, [atomic.$position, 0].concat(values));
  19528. ret = this.length;
  19529. } else {
  19530. ret = [].push.apply(arr, values);
  19531. }
  19532. } else {
  19533. if ((atomics.$push && atomics.$push.$each && atomics.$push.$each.length || 0) !== 0 && atomics.$push.$position != null) {
  19534. throw new MongooseError('Cannot call `Array#push()` multiple times ' + 'with different `$position`');
  19535. }
  19536. atomic = values;
  19537. ret = [].push.apply(arr, values);
  19538. }
  19539. this._registerAtomic('$push', atomic);
  19540. return ret;
  19541. },
  19542. /**
  19543. * Alias of [pull](#mongoosearray_MongooseArray-pull)
  19544. *
  19545. * @see MongooseArray#pull #types_array_MongooseArray-pull
  19546. * @see mongodb https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pull
  19547. * @api public
  19548. * @memberOf MongooseArray
  19549. * @instance
  19550. * @method remove
  19551. */
  19552. remove: function remove() {
  19553. return this.pull.apply(this, arguments);
  19554. },
  19555. /**
  19556. * Sets the casted `val` at index `i` and marks the array modified.
  19557. *
  19558. * #### Example:
  19559. *
  19560. * // given documents based on the following
  19561. * const Doc = mongoose.model('Doc', new Schema({ array: [Number] }));
  19562. *
  19563. * const doc = new Doc({ array: [2,3,4] })
  19564. *
  19565. * console.log(doc.array) // [2,3,4]
  19566. *
  19567. * doc.array.set(1,"5");
  19568. * console.log(doc.array); // [2,5,4] // properly cast to number
  19569. * doc.save() // the change is saved
  19570. *
  19571. * // VS not using array#set
  19572. * doc.array[1] = "5";
  19573. * console.log(doc.array); // [2,"5",4] // no casting
  19574. * doc.save() // change is not saved
  19575. *
  19576. * @return {Array} this
  19577. * @api public
  19578. * @method set
  19579. * @memberOf MongooseArray
  19580. */
  19581. set: function set(i, val, skipModified) {
  19582. var arr = this.__array;
  19583. if (skipModified) {
  19584. arr[i] = val;
  19585. return this;
  19586. }
  19587. var value = methods._cast.call(this, val, i);
  19588. methods._markModified.call(this, i);
  19589. arr[i] = value;
  19590. return this;
  19591. },
  19592. /**
  19593. * Wraps [`Array#shift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
  19594. *
  19595. * #### Example:
  19596. *
  19597. * doc.array = [2,3];
  19598. * const res = doc.array.shift();
  19599. * console.log(res) // 2
  19600. * console.log(doc.array) // [3]
  19601. *
  19602. * #### Note:
  19603. *
  19604. * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
  19605. *
  19606. * @api public
  19607. * @method shift
  19608. * @memberOf MongooseArray
  19609. */
  19610. shift: function shift() {
  19611. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19612. this._markModified();
  19613. var ret = [].shift.call(arr);
  19614. this._registerAtomic('$set', this);
  19615. return ret;
  19616. },
  19617. /**
  19618. * Wraps [`Array#sort`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort) with proper change tracking.
  19619. *
  19620. * #### Note:
  19621. *
  19622. * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
  19623. *
  19624. * @api public
  19625. * @method sort
  19626. * @memberOf MongooseArray
  19627. * @see https://masteringjs.io/tutorials/fundamentals/array-sort
  19628. */
  19629. sort: function sort() {
  19630. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19631. var ret = [].sort.apply(arr, arguments);
  19632. this._registerAtomic('$set', this);
  19633. return ret;
  19634. },
  19635. /**
  19636. * Wraps [`Array#splice`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) with proper change tracking and casting.
  19637. *
  19638. * #### Note:
  19639. *
  19640. * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
  19641. *
  19642. * @api public
  19643. * @method splice
  19644. * @memberOf MongooseArray
  19645. * @see https://masteringjs.io/tutorials/fundamentals/array-splice
  19646. */
  19647. splice: function splice() {
  19648. var ret;
  19649. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19650. _checkManualPopulation(this, Array.prototype.slice.call(arguments, 2));
  19651. if (arguments.length) {
  19652. var vals;
  19653. if (this[arraySchemaSymbol] == null) {
  19654. vals = arguments;
  19655. } else {
  19656. vals = [];
  19657. for (var i = 0; i < arguments.length; ++i) {
  19658. vals[i] = i < 2 ? arguments[i] : this._cast(arguments[i], arguments[0] + (i - 2));
  19659. }
  19660. }
  19661. ret = [].splice.apply(arr, vals);
  19662. this._registerAtomic('$set', this);
  19663. }
  19664. return ret;
  19665. },
  19666. /*!
  19667. * ignore
  19668. */
  19669. toBSON: function toBSON() {
  19670. return this.toObject(internalToObjectOptions);
  19671. },
  19672. /**
  19673. * Returns a native js Array.
  19674. *
  19675. * @param {Object} options
  19676. * @return {Array}
  19677. * @api public
  19678. * @method toObject
  19679. * @memberOf MongooseArray
  19680. */
  19681. toObject: function toObject(options) {
  19682. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19683. if (options && options.depopulate) {
  19684. options = utils.clone(options);
  19685. options._isNested = true; // Ensure return value is a vanilla array, because in Node.js 6+ `map()`
  19686. // is smart enough to use the inherited array's constructor.
  19687. return [].concat(arr).map(function (doc) {
  19688. return doc instanceof Document ? doc.toObject(options) : doc;
  19689. });
  19690. }
  19691. return [].concat(arr);
  19692. },
  19693. $toObject: function $toObject() {
  19694. return this.constructor.prototype.toObject.apply(this, arguments);
  19695. },
  19696. /**
  19697. * Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
  19698. *
  19699. * #### Note:
  19700. *
  19701. * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwriting any changes that happen between when you retrieved the object and when you save it._
  19702. *
  19703. * @api public
  19704. * @method unshift
  19705. * @memberOf MongooseArray
  19706. */
  19707. unshift: function unshift() {
  19708. _checkManualPopulation(this, arguments);
  19709. var values;
  19710. if (this[arraySchemaSymbol] == null) {
  19711. values = arguments;
  19712. } else {
  19713. values = [].map.call(arguments, this._cast, this);
  19714. values = this[arraySchemaSymbol].applySetters(values, this[arrayParentSymbol]);
  19715. }
  19716. var arr = utils.isMongooseArray(this) ? this.__array : this;
  19717. this._markModified();
  19718. [].unshift.apply(arr, values);
  19719. this._registerAtomic('$set', this);
  19720. return this.length;
  19721. }
  19722. };
  19723. /*!
  19724. * ignore
  19725. */
  19726. function _isAllSubdocs(docs, ref) {
  19727. if (!ref) {
  19728. return false;
  19729. }
  19730. var _iterator = _createForOfIteratorHelper(docs),
  19731. _step;
  19732. try {
  19733. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  19734. var arg = _step.value;
  19735. if (arg == null) {
  19736. return false;
  19737. }
  19738. var model = arg.constructor;
  19739. if (!(arg instanceof Document) || model.modelName !== ref && model.baseModelName !== ref) {
  19740. return false;
  19741. }
  19742. }
  19743. } catch (err) {
  19744. _iterator.e(err);
  19745. } finally {
  19746. _iterator.f();
  19747. }
  19748. return true;
  19749. }
  19750. /*!
  19751. * ignore
  19752. */
  19753. function _checkManualPopulation(arr, docs) {
  19754. var ref = arr == null ? null : arr[arraySchemaSymbol] && arr[arraySchemaSymbol].caster && arr[arraySchemaSymbol].caster.options && arr[arraySchemaSymbol].caster.options.ref || null;
  19755. if (arr.length === 0 && docs.length !== 0) {
  19756. if (_isAllSubdocs(docs, ref)) {
  19757. arr[arrayParentSymbol].$populated(arr[arrayPathSymbol], [], _defineProperty({}, populateModelSymbol, docs[0].constructor));
  19758. }
  19759. }
  19760. }
  19761. var returnVanillaArrayMethods = ['filter', 'flat', 'flatMap', 'map', 'slice'];
  19762. var _loop = function _loop() {
  19763. var method = _returnVanillaArrayMe[_i];
  19764. if (Array.prototype[method] == null) {
  19765. return "continue";
  19766. }
  19767. methods[method] = function () {
  19768. var _arr = utils.isMongooseArray(this) ? this.__array : this;
  19769. var arr = [].concat(_arr);
  19770. return arr[method].apply(arr, arguments);
  19771. };
  19772. };
  19773. for (var _i = 0, _returnVanillaArrayMe = returnVanillaArrayMethods; _i < _returnVanillaArrayMe.length; _i++) {
  19774. var _ret = _loop();
  19775. if (_ret === "continue") continue;
  19776. }
  19777. module.exports = methods;
  19778. /***/ }),
  19779. /***/ 4051:
  19780. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  19781. "use strict";
  19782. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  19783. /*!
  19784. * Module dependencies.
  19785. */
  19786. var Binary = (__webpack_require__(9906).get)().Binary;
  19787. var utils = __webpack_require__(6872);
  19788. /**
  19789. * Mongoose Buffer constructor.
  19790. *
  19791. * Values always have to be passed to the constructor to initialize.
  19792. *
  19793. * @param {Buffer} value
  19794. * @param {String} encode
  19795. * @param {Number} offset
  19796. * @api private
  19797. * @inherits Buffer
  19798. * @see https://bit.ly/f6CnZU
  19799. */
  19800. function MongooseBuffer(value, encode, offset) {
  19801. var val = value;
  19802. if (value == null) {
  19803. val = 0;
  19804. }
  19805. var encoding;
  19806. var path;
  19807. var doc;
  19808. if (Array.isArray(encode)) {
  19809. // internal casting
  19810. path = encode[0];
  19811. doc = encode[1];
  19812. } else {
  19813. encoding = encode;
  19814. }
  19815. var buf;
  19816. if (typeof val === 'number' || val instanceof Number) {
  19817. buf = Buffer.alloc(val);
  19818. } else {
  19819. // string, array or object { type: 'Buffer', data: [...] }
  19820. buf = Buffer.from(val, encoding, offset);
  19821. }
  19822. utils.decorate(buf, MongooseBuffer.mixin);
  19823. buf.isMongooseBuffer = true; // make sure these internal props don't show up in Object.keys()
  19824. buf[MongooseBuffer.pathSymbol] = path;
  19825. buf[parentSymbol] = doc;
  19826. buf._subtype = 0;
  19827. return buf;
  19828. }
  19829. var pathSymbol = Symbol["for"]('mongoose#Buffer#_path');
  19830. var parentSymbol = Symbol["for"]('mongoose#Buffer#_parent');
  19831. MongooseBuffer.pathSymbol = pathSymbol;
  19832. /*!
  19833. * Inherit from Buffer.
  19834. */
  19835. MongooseBuffer.mixin = {
  19836. /**
  19837. * Default subtype for the Binary representing this Buffer
  19838. *
  19839. * @api private
  19840. * @property _subtype
  19841. * @receiver MongooseBuffer
  19842. */
  19843. _subtype: undefined,
  19844. /**
  19845. * Marks this buffer as modified.
  19846. *
  19847. * @api private
  19848. * @method _markModified
  19849. * @receiver MongooseBuffer
  19850. */
  19851. _markModified: function _markModified() {
  19852. var parent = this[parentSymbol];
  19853. if (parent) {
  19854. parent.markModified(this[MongooseBuffer.pathSymbol]);
  19855. }
  19856. return this;
  19857. },
  19858. /**
  19859. * Writes the buffer.
  19860. *
  19861. * @api public
  19862. * @method write
  19863. * @receiver MongooseBuffer
  19864. */
  19865. write: function write() {
  19866. var written = Buffer.prototype.write.apply(this, arguments);
  19867. if (written > 0) {
  19868. this._markModified();
  19869. }
  19870. return written;
  19871. },
  19872. /**
  19873. * Copies the buffer.
  19874. *
  19875. * #### Note:
  19876. *
  19877. * `Buffer#copy` does not mark `target` as modified so you must copy from a `MongooseBuffer` for it to work as expected. This is a work around since `copy` modifies the target, not this.
  19878. *
  19879. * @return {Number} The number of bytes copied.
  19880. * @param {Buffer} target
  19881. * @method copy
  19882. * @receiver MongooseBuffer
  19883. */
  19884. copy: function copy(target) {
  19885. var ret = Buffer.prototype.copy.apply(this, arguments);
  19886. if (target && target.isMongooseBuffer) {
  19887. target._markModified();
  19888. }
  19889. return ret;
  19890. }
  19891. };
  19892. /*!
  19893. * Compile other Buffer methods marking this buffer as modified.
  19894. */
  19895. ( // node < 0.5
  19896. 'writeUInt8 writeUInt16 writeUInt32 writeInt8 writeInt16 writeInt32 ' + 'writeFloat writeDouble fill ' + 'utf8Write binaryWrite asciiWrite set ' + // node >= 0.5
  19897. 'writeUInt16LE writeUInt16BE writeUInt32LE writeUInt32BE ' + 'writeInt16LE writeInt16BE writeInt32LE writeInt32BE ' + 'writeFloatLE writeFloatBE writeDoubleLE writeDoubleBE').split(' ').forEach(function (method) {
  19898. if (!Buffer.prototype[method]) {
  19899. return;
  19900. }
  19901. MongooseBuffer.mixin[method] = function () {
  19902. var ret = Buffer.prototype[method].apply(this, arguments);
  19903. this._markModified();
  19904. return ret;
  19905. };
  19906. });
  19907. /**
  19908. * Converts this buffer to its Binary type representation.
  19909. *
  19910. * ####SubTypes:
  19911. *
  19912. * const bson = require('bson')
  19913. * bson.BSON_BINARY_SUBTYPE_DEFAULT
  19914. * bson.BSON_BINARY_SUBTYPE_FUNCTION
  19915. * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
  19916. * bson.BSON_BINARY_SUBTYPE_UUID
  19917. * bson.BSON_BINARY_SUBTYPE_MD5
  19918. * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
  19919. *
  19920. * doc.buffer.toObject(bson.BSON_BINARY_SUBTYPE_USER_DEFINED);
  19921. *
  19922. * @see https://bsonspec.org/#/specification
  19923. * @param {Hex} [subtype]
  19924. * @return {Binary}
  19925. * @api public
  19926. * @method toObject
  19927. * @receiver MongooseBuffer
  19928. */
  19929. MongooseBuffer.mixin.toObject = function (options) {
  19930. var subtype = typeof options === 'number' ? options : this._subtype || 0;
  19931. return new Binary(Buffer.from(this), subtype);
  19932. };
  19933. MongooseBuffer.mixin.$toObject = MongooseBuffer.mixin.toObject;
  19934. /**
  19935. * Converts this buffer for storage in MongoDB, including subtype
  19936. *
  19937. * @return {Binary}
  19938. * @api public
  19939. * @method toBSON
  19940. * @receiver MongooseBuffer
  19941. */
  19942. MongooseBuffer.mixin.toBSON = function () {
  19943. return new Binary(this, this._subtype || 0);
  19944. };
  19945. /**
  19946. * Determines if this buffer is equals to `other` buffer
  19947. *
  19948. * @param {Buffer} other
  19949. * @return {Boolean}
  19950. * @method equals
  19951. * @receiver MongooseBuffer
  19952. */
  19953. MongooseBuffer.mixin.equals = function (other) {
  19954. if (!Buffer.isBuffer(other)) {
  19955. return false;
  19956. }
  19957. if (this.length !== other.length) {
  19958. return false;
  19959. }
  19960. for (var i = 0; i < this.length; ++i) {
  19961. if (this[i] !== other[i]) {
  19962. return false;
  19963. }
  19964. }
  19965. return true;
  19966. };
  19967. /**
  19968. * Sets the subtype option and marks the buffer modified.
  19969. *
  19970. * ####SubTypes:
  19971. *
  19972. * const bson = require('bson')
  19973. * bson.BSON_BINARY_SUBTYPE_DEFAULT
  19974. * bson.BSON_BINARY_SUBTYPE_FUNCTION
  19975. * bson.BSON_BINARY_SUBTYPE_BYTE_ARRAY
  19976. * bson.BSON_BINARY_SUBTYPE_UUID
  19977. * bson.BSON_BINARY_SUBTYPE_MD5
  19978. * bson.BSON_BINARY_SUBTYPE_USER_DEFINED
  19979. *
  19980. * doc.buffer.subtype(bson.BSON_BINARY_SUBTYPE_UUID);
  19981. *
  19982. * @see https://bsonspec.org/#/specification
  19983. * @param {Hex} subtype
  19984. * @api public
  19985. * @method subtype
  19986. * @receiver MongooseBuffer
  19987. */
  19988. MongooseBuffer.mixin.subtype = function (subtype) {
  19989. if (typeof subtype !== 'number') {
  19990. throw new TypeError('Invalid subtype. Expected a number');
  19991. }
  19992. if (this._subtype !== subtype) {
  19993. this._markModified();
  19994. }
  19995. this._subtype = subtype;
  19996. };
  19997. /*!
  19998. * Module exports.
  19999. */
  20000. MongooseBuffer.Binary = Binary;
  20001. module.exports = MongooseBuffer;
  20002. /***/ }),
  20003. /***/ 5003:
  20004. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  20005. "use strict";
  20006. /**
  20007. * ObjectId type constructor
  20008. *
  20009. * #### Example
  20010. *
  20011. * const id = new mongoose.Types.ObjectId;
  20012. *
  20013. * @constructor ObjectId
  20014. */
  20015. module.exports = (__webpack_require__(9906).get)().Decimal128;
  20016. /***/ }),
  20017. /***/ 8941:
  20018. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20019. "use strict";
  20020. /*!
  20021. * Module exports.
  20022. */
  20023. exports.Array = __webpack_require__(1362);
  20024. exports.Buffer = __webpack_require__(4051);
  20025. exports.Document = // @deprecate
  20026. exports.Embedded = __webpack_require__(1568);
  20027. exports.DocumentArray = __webpack_require__(6077);
  20028. exports.Decimal128 = __webpack_require__(5003);
  20029. exports.ObjectId = __webpack_require__(6079);
  20030. exports.Map = __webpack_require__(3828);
  20031. exports.Subdocument = __webpack_require__(2591);
  20032. /***/ }),
  20033. /***/ 3828:
  20034. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  20035. "use strict";
  20036. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  20037. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  20038. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  20039. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  20040. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  20041. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  20042. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  20043. function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
  20044. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  20045. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  20046. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  20047. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  20048. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  20049. function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
  20050. function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  20051. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  20052. function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
  20053. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  20054. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  20055. var Mixed = __webpack_require__(3861);
  20056. var clone = __webpack_require__(1973);
  20057. var deepEqual = (__webpack_require__(6872).deepEqual);
  20058. var getConstructorName = __webpack_require__(1981);
  20059. var handleSpreadDoc = __webpack_require__(719);
  20060. var util = __webpack_require__(161);
  20061. var specialProperties = __webpack_require__(2862);
  20062. var isBsonType = __webpack_require__(1563);
  20063. var populateModelSymbol = (__webpack_require__(8770).populateModelSymbol);
  20064. /*!
  20065. * ignore
  20066. */
  20067. var MongooseMap = /*#__PURE__*/function (_Map) {
  20068. _inherits(MongooseMap, _Map);
  20069. var _super = _createSuper(MongooseMap);
  20070. function MongooseMap(v, path, doc, schemaType) {
  20071. var _this;
  20072. _classCallCheck(this, MongooseMap);
  20073. if (getConstructorName(v) === 'Object') {
  20074. v = Object.keys(v).reduce(function (arr, key) {
  20075. return arr.concat([[key, v[key]]]);
  20076. }, []);
  20077. }
  20078. _this = _super.call(this, v);
  20079. _this.$__parent = doc != null && doc.$__ != null ? doc : null;
  20080. _this.$__path = path;
  20081. _this.$__schemaType = schemaType == null ? new Mixed(path) : schemaType;
  20082. _this.$__runDeferred();
  20083. return _this;
  20084. }
  20085. _createClass(MongooseMap, [{
  20086. key: "$init",
  20087. value: function $init(key, value) {
  20088. checkValidKey(key);
  20089. _get(_getPrototypeOf(MongooseMap.prototype), "set", this).call(this, key, value);
  20090. if (value != null && value.$isSingleNested) {
  20091. value.$basePath = this.$__path + '.' + key;
  20092. }
  20093. }
  20094. }, {
  20095. key: "$__set",
  20096. value: function $__set(key, value) {
  20097. _get(_getPrototypeOf(MongooseMap.prototype), "set", this).call(this, key, value);
  20098. }
  20099. }, {
  20100. key: "get",
  20101. value: function get(key, options) {
  20102. if (isBsonType(key, 'ObjectID')) {
  20103. key = key.toString();
  20104. }
  20105. options = options || {};
  20106. if (options.getters === false) {
  20107. return _get(_getPrototypeOf(MongooseMap.prototype), "get", this).call(this, key);
  20108. }
  20109. return this.$__schemaType.applyGetters(_get(_getPrototypeOf(MongooseMap.prototype), "get", this).call(this, key), this.$__parent);
  20110. }
  20111. }, {
  20112. key: "set",
  20113. value: function set(key, value) {
  20114. if (isBsonType(key, 'ObjectID')) {
  20115. key = key.toString();
  20116. }
  20117. checkValidKey(key);
  20118. value = handleSpreadDoc(value); // Weird, but because you can't assign to `this` before calling `super()`
  20119. // you can't get access to `$__schemaType` to cast in the initial call to
  20120. // `set()` from the `super()` constructor.
  20121. if (this.$__schemaType == null) {
  20122. this.$__deferred = this.$__deferred || [];
  20123. this.$__deferred.push({
  20124. key: key,
  20125. value: value
  20126. });
  20127. return;
  20128. }
  20129. var fullPath = this.$__path + '.' + key;
  20130. var populated = this.$__parent != null && this.$__parent.$__ ? this.$__parent.$populated(fullPath) || this.$__parent.$populated(this.$__path) : null;
  20131. var priorVal = this.get(key);
  20132. if (populated != null) {
  20133. if (value.$__ == null) {
  20134. value = new populated.options[populateModelSymbol](value);
  20135. }
  20136. value.$__.wasPopulated = {
  20137. value: populated.value
  20138. };
  20139. } else {
  20140. try {
  20141. value = this.$__schemaType.applySetters(value, this.$__parent, false, this.get(key), {
  20142. path: fullPath
  20143. });
  20144. } catch (error) {
  20145. if (this.$__parent != null && this.$__parent.$__ != null) {
  20146. this.$__parent.invalidate(fullPath, error);
  20147. return;
  20148. }
  20149. throw error;
  20150. }
  20151. }
  20152. _get(_getPrototypeOf(MongooseMap.prototype), "set", this).call(this, key, value);
  20153. if (value != null && value.$isSingleNested) {
  20154. value.$basePath = this.$__path + '.' + key;
  20155. }
  20156. var parent = this.$__parent;
  20157. if (parent != null && parent.$__ != null && !deepEqual(value, priorVal)) {
  20158. parent.markModified(this.$__path + '.' + key);
  20159. }
  20160. }
  20161. }, {
  20162. key: "clear",
  20163. value: function clear() {
  20164. _get(_getPrototypeOf(MongooseMap.prototype), "clear", this).call(this);
  20165. var parent = this.$__parent;
  20166. if (parent != null) {
  20167. parent.markModified(this.$__path);
  20168. }
  20169. }
  20170. }, {
  20171. key: "delete",
  20172. value: function _delete(key) {
  20173. if (isBsonType(key, 'ObjectID')) {
  20174. key = key.toString();
  20175. }
  20176. this.set(key, undefined);
  20177. _get(_getPrototypeOf(MongooseMap.prototype), "delete", this).call(this, key);
  20178. }
  20179. }, {
  20180. key: "toBSON",
  20181. value: function toBSON() {
  20182. return new Map(this);
  20183. }
  20184. }, {
  20185. key: "toObject",
  20186. value: function toObject(options) {
  20187. if (options && options.flattenMaps) {
  20188. var ret = {};
  20189. var keys = this.keys();
  20190. var _iterator = _createForOfIteratorHelper(keys),
  20191. _step;
  20192. try {
  20193. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  20194. var key = _step.value;
  20195. ret[key] = clone(this.get(key), options);
  20196. }
  20197. } catch (err) {
  20198. _iterator.e(err);
  20199. } finally {
  20200. _iterator.f();
  20201. }
  20202. return ret;
  20203. }
  20204. return new Map(this);
  20205. }
  20206. }, {
  20207. key: "$toObject",
  20208. value: function $toObject() {
  20209. return this.constructor.prototype.toObject.apply(this, arguments);
  20210. }
  20211. }, {
  20212. key: "toJSON",
  20213. value: function toJSON(options) {
  20214. if (typeof (options && options.flattenMaps) === 'boolean' ? options.flattenMaps : true) {
  20215. var ret = {};
  20216. var keys = this.keys();
  20217. var _iterator2 = _createForOfIteratorHelper(keys),
  20218. _step2;
  20219. try {
  20220. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  20221. var key = _step2.value;
  20222. ret[key] = clone(this.get(key), options);
  20223. }
  20224. } catch (err) {
  20225. _iterator2.e(err);
  20226. } finally {
  20227. _iterator2.f();
  20228. }
  20229. return ret;
  20230. }
  20231. return new Map(this);
  20232. }
  20233. }, {
  20234. key: "inspect",
  20235. value: function inspect() {
  20236. return new Map(this);
  20237. }
  20238. }, {
  20239. key: "$__runDeferred",
  20240. value: function $__runDeferred() {
  20241. if (!this.$__deferred) {
  20242. return;
  20243. }
  20244. var _iterator3 = _createForOfIteratorHelper(this.$__deferred),
  20245. _step3;
  20246. try {
  20247. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  20248. var keyValueObject = _step3.value;
  20249. this.set(keyValueObject.key, keyValueObject.value);
  20250. }
  20251. } catch (err) {
  20252. _iterator3.e(err);
  20253. } finally {
  20254. _iterator3.f();
  20255. }
  20256. this.$__deferred = null;
  20257. }
  20258. }]);
  20259. return MongooseMap;
  20260. }( /*#__PURE__*/_wrapNativeSuper(Map));
  20261. if (util.inspect.custom) {
  20262. Object.defineProperty(MongooseMap.prototype, util.inspect.custom, {
  20263. enumerable: false,
  20264. writable: false,
  20265. configurable: false,
  20266. value: MongooseMap.prototype.inspect
  20267. });
  20268. }
  20269. Object.defineProperty(MongooseMap.prototype, '$__set', {
  20270. enumerable: false,
  20271. writable: true,
  20272. configurable: false
  20273. });
  20274. Object.defineProperty(MongooseMap.prototype, '$__parent', {
  20275. enumerable: false,
  20276. writable: true,
  20277. configurable: false
  20278. });
  20279. Object.defineProperty(MongooseMap.prototype, '$__path', {
  20280. enumerable: false,
  20281. writable: true,
  20282. configurable: false
  20283. });
  20284. Object.defineProperty(MongooseMap.prototype, '$__schemaType', {
  20285. enumerable: false,
  20286. writable: true,
  20287. configurable: false
  20288. });
  20289. Object.defineProperty(MongooseMap.prototype, '$isMongooseMap', {
  20290. enumerable: false,
  20291. writable: false,
  20292. configurable: false,
  20293. value: true
  20294. });
  20295. Object.defineProperty(MongooseMap.prototype, '$__deferredCalls', {
  20296. enumerable: false,
  20297. writable: false,
  20298. configurable: false,
  20299. value: true
  20300. });
  20301. /*!
  20302. * Since maps are stored as objects under the hood, keys must be strings
  20303. * and can't contain any invalid characters
  20304. */
  20305. function checkValidKey(key) {
  20306. var keyType = _typeof(key);
  20307. if (keyType !== 'string') {
  20308. throw new TypeError("Mongoose maps only support string keys, got ".concat(keyType));
  20309. }
  20310. if (key.startsWith('$')) {
  20311. throw new Error("Mongoose maps do not support keys that start with \"$\", got \"".concat(key, "\""));
  20312. }
  20313. if (key.includes('.')) {
  20314. throw new Error("Mongoose maps do not support keys that contain \".\", got \"".concat(key, "\""));
  20315. }
  20316. if (specialProperties.has(key)) {
  20317. throw new Error("Mongoose maps do not support reserved key name \"".concat(key, "\""));
  20318. }
  20319. }
  20320. module.exports = MongooseMap;
  20321. /***/ }),
  20322. /***/ 6079:
  20323. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  20324. "use strict";
  20325. /**
  20326. * ObjectId type constructor
  20327. *
  20328. * #### Example
  20329. *
  20330. * const id = new mongoose.Types.ObjectId;
  20331. *
  20332. * @constructor ObjectId
  20333. */
  20334. var ObjectId = (__webpack_require__(9906).get)().ObjectId;
  20335. var objectIdSymbol = (__webpack_require__(8770).objectIdSymbol);
  20336. /*!
  20337. * Getter for convenience with populate, see gh-6115
  20338. */
  20339. Object.defineProperty(ObjectId.prototype, '_id', {
  20340. enumerable: false,
  20341. configurable: true,
  20342. get: function get() {
  20343. return this;
  20344. }
  20345. });
  20346. /*!
  20347. * Convenience `valueOf()` to allow comparing ObjectIds using double equals re: gh-7299
  20348. */
  20349. if (!ObjectId.prototype.hasOwnProperty('valueOf')) {
  20350. ObjectId.prototype.valueOf = function objectIdValueOf() {
  20351. return this.toString();
  20352. };
  20353. }
  20354. ObjectId.prototype[objectIdSymbol] = true;
  20355. module.exports = ObjectId;
  20356. /***/ }),
  20357. /***/ 2591:
  20358. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  20359. "use strict";
  20360. var Document = __webpack_require__(8727);
  20361. var immediate = __webpack_require__(1490);
  20362. var internalToObjectOptions = (__webpack_require__(4962)/* .internalToObjectOptions */ .h);
  20363. var promiseOrCallback = __webpack_require__(8486);
  20364. var util = __webpack_require__(161);
  20365. var utils = __webpack_require__(6872);
  20366. module.exports = Subdocument;
  20367. /**
  20368. * Subdocument constructor.
  20369. *
  20370. * @inherits Document
  20371. * @api private
  20372. */
  20373. function Subdocument(value, fields, parent, skipId, options) {
  20374. if (parent != null) {
  20375. // If setting a nested path, should copy isNew from parent re: gh-7048
  20376. var parentOptions = {
  20377. isNew: parent.isNew
  20378. };
  20379. if ('defaults' in parent.$__) {
  20380. parentOptions.defaults = parent.$__.defaults;
  20381. }
  20382. options = Object.assign(parentOptions, options);
  20383. }
  20384. if (options != null && options.path != null) {
  20385. this.$basePath = options.path;
  20386. }
  20387. Document.call(this, value, fields, skipId, options);
  20388. delete this.$__.priorDoc;
  20389. }
  20390. Subdocument.prototype = Object.create(Document.prototype);
  20391. Object.defineProperty(Subdocument.prototype, '$isSubdocument', {
  20392. configurable: false,
  20393. writable: false,
  20394. value: true
  20395. });
  20396. Object.defineProperty(Subdocument.prototype, '$isSingleNested', {
  20397. configurable: false,
  20398. writable: false,
  20399. value: true
  20400. });
  20401. /*!
  20402. * ignore
  20403. */
  20404. Subdocument.prototype.toBSON = function () {
  20405. return this.toObject(internalToObjectOptions);
  20406. };
  20407. /**
  20408. * Used as a stub for middleware
  20409. *
  20410. * #### Note:
  20411. *
  20412. * _This is a no-op. Does not actually save the doc to the db._
  20413. *
  20414. * @param {Function} [fn]
  20415. * @return {Promise} resolved Promise
  20416. * @api private
  20417. */
  20418. Subdocument.prototype.save = function (options, fn) {
  20419. var _this = this;
  20420. if (typeof options === 'function') {
  20421. fn = options;
  20422. options = {};
  20423. }
  20424. options = options || {};
  20425. if (!options.suppressWarning) {
  20426. utils.warn('mongoose: calling `save()` on a subdoc does **not** save ' + 'the document to MongoDB, it only runs save middleware. ' + 'Use `subdoc.save({ suppressWarning: true })` to hide this warning ' + 'if you\'re sure this behavior is right for your app.');
  20427. }
  20428. return promiseOrCallback(fn, function (cb) {
  20429. _this.$__save(cb);
  20430. });
  20431. };
  20432. /*!
  20433. * Given a path relative to this document, return the path relative
  20434. * to the top-level document.
  20435. */
  20436. Subdocument.prototype.$__fullPath = function (path) {
  20437. if (!this.$__.fullPath) {
  20438. this.ownerDocument();
  20439. }
  20440. return path ? this.$__.fullPath + '.' + path : this.$__.fullPath;
  20441. };
  20442. /*!
  20443. * Given a path relative to this document, return the path relative
  20444. * to the top-level document.
  20445. */
  20446. Subdocument.prototype.$__pathRelativeToParent = function (p) {
  20447. if (p == null) {
  20448. return this.$basePath;
  20449. }
  20450. return [this.$basePath, p].join('.');
  20451. };
  20452. /**
  20453. * Used as a stub for middleware
  20454. *
  20455. * #### Note:
  20456. *
  20457. * _This is a no-op. Does not actually save the doc to the db._
  20458. *
  20459. * @param {Function} [fn]
  20460. * @method $__save
  20461. * @api private
  20462. */
  20463. Subdocument.prototype.$__save = function (fn) {
  20464. var _this2 = this;
  20465. return immediate(function () {
  20466. return fn(null, _this2);
  20467. });
  20468. };
  20469. /*!
  20470. * ignore
  20471. */
  20472. Subdocument.prototype.$isValid = function (path) {
  20473. var parent = this.$parent();
  20474. var fullPath = this.$__pathRelativeToParent(path);
  20475. if (parent != null && fullPath != null) {
  20476. return parent.$isValid(fullPath);
  20477. }
  20478. return Document.prototype.$isValid.call(this, path);
  20479. };
  20480. /*!
  20481. * ignore
  20482. */
  20483. Subdocument.prototype.markModified = function (path) {
  20484. Document.prototype.markModified.call(this, path);
  20485. var parent = this.$parent();
  20486. var fullPath = this.$__pathRelativeToParent(path);
  20487. if (parent == null || fullPath == null) {
  20488. return;
  20489. }
  20490. var myPath = this.$__pathRelativeToParent().replace(/\.$/, '');
  20491. if (parent.isDirectModified(myPath) || this.isNew) {
  20492. return;
  20493. }
  20494. this.$__parent.markModified(fullPath, this);
  20495. };
  20496. /*!
  20497. * ignore
  20498. */
  20499. Subdocument.prototype.isModified = function (paths, modifiedPaths) {
  20500. var _this3 = this;
  20501. var parent = this.$parent();
  20502. if (parent != null) {
  20503. if (Array.isArray(paths) || typeof paths === 'string') {
  20504. paths = Array.isArray(paths) ? paths : paths.split(' ');
  20505. paths = paths.map(function (p) {
  20506. return _this3.$__pathRelativeToParent(p);
  20507. }).filter(function (p) {
  20508. return p != null;
  20509. });
  20510. } else if (!paths) {
  20511. paths = this.$__pathRelativeToParent();
  20512. }
  20513. return parent.$isModified(paths, modifiedPaths);
  20514. }
  20515. return Document.prototype.isModified.call(this, paths, modifiedPaths);
  20516. };
  20517. /**
  20518. * Marks a path as valid, removing existing validation errors.
  20519. *
  20520. * @param {String} path the field to mark as valid
  20521. * @api private
  20522. * @method $markValid
  20523. * @receiver Subdocument
  20524. */
  20525. Subdocument.prototype.$markValid = function (path) {
  20526. Document.prototype.$markValid.call(this, path);
  20527. var parent = this.$parent();
  20528. var fullPath = this.$__pathRelativeToParent(path);
  20529. if (parent != null && fullPath != null) {
  20530. parent.$markValid(fullPath);
  20531. }
  20532. };
  20533. /*!
  20534. * ignore
  20535. */
  20536. Subdocument.prototype.invalidate = function (path, err, val) {
  20537. Document.prototype.invalidate.call(this, path, err, val);
  20538. var parent = this.$parent();
  20539. var fullPath = this.$__pathRelativeToParent(path);
  20540. if (parent != null && fullPath != null) {
  20541. parent.invalidate(fullPath, err, val);
  20542. } else if (err.kind === 'cast' || err.name === 'CastError' || fullPath == null) {
  20543. throw err;
  20544. }
  20545. return this.ownerDocument().$__.validationError;
  20546. };
  20547. /*!
  20548. * ignore
  20549. */
  20550. Subdocument.prototype.$ignore = function (path) {
  20551. Document.prototype.$ignore.call(this, path);
  20552. var parent = this.$parent();
  20553. var fullPath = this.$__pathRelativeToParent(path);
  20554. if (parent != null && fullPath != null) {
  20555. parent.$ignore(fullPath);
  20556. }
  20557. };
  20558. /**
  20559. * Returns the top level document of this sub-document.
  20560. *
  20561. * @return {Document}
  20562. */
  20563. Subdocument.prototype.ownerDocument = function () {
  20564. if (this.$__.ownerDocument) {
  20565. return this.$__.ownerDocument;
  20566. }
  20567. var parent = this; // eslint-disable-line consistent-this
  20568. var paths = [];
  20569. var seenDocs = new Set([parent]);
  20570. while (true) {
  20571. if (typeof parent.$__pathRelativeToParent !== 'function') {
  20572. break;
  20573. }
  20574. paths.unshift(parent.$__pathRelativeToParent(void 0, true));
  20575. var _parent = parent.$parent();
  20576. if (_parent == null) {
  20577. break;
  20578. }
  20579. parent = _parent;
  20580. if (seenDocs.has(parent)) {
  20581. throw new Error('Infinite subdocument loop: subdoc with _id ' + parent._id + ' is a parent of itself');
  20582. }
  20583. seenDocs.add(parent);
  20584. }
  20585. this.$__.fullPath = paths.join('.');
  20586. this.$__.ownerDocument = parent;
  20587. return this.$__.ownerDocument;
  20588. };
  20589. /*!
  20590. * ignore
  20591. */
  20592. Subdocument.prototype.$__fullPathWithIndexes = function () {
  20593. var parent = this; // eslint-disable-line consistent-this
  20594. var paths = [];
  20595. var seenDocs = new Set([parent]);
  20596. while (true) {
  20597. if (typeof parent.$__pathRelativeToParent !== 'function') {
  20598. break;
  20599. }
  20600. paths.unshift(parent.$__pathRelativeToParent(void 0, false));
  20601. var _parent = parent.$parent();
  20602. if (_parent == null) {
  20603. break;
  20604. }
  20605. parent = _parent;
  20606. if (seenDocs.has(parent)) {
  20607. throw new Error('Infinite subdocument loop: subdoc with _id ' + parent._id + ' is a parent of itself');
  20608. }
  20609. seenDocs.add(parent);
  20610. }
  20611. return paths.join('.');
  20612. };
  20613. /**
  20614. * Returns this sub-documents parent document.
  20615. *
  20616. * @api public
  20617. */
  20618. Subdocument.prototype.parent = function () {
  20619. return this.$__parent;
  20620. };
  20621. /**
  20622. * Returns this sub-documents parent document.
  20623. *
  20624. * @api public
  20625. * @method $parent
  20626. */
  20627. Subdocument.prototype.$parent = Subdocument.prototype.parent;
  20628. /*!
  20629. * no-op for hooks
  20630. */
  20631. Subdocument.prototype.$__remove = function (cb) {
  20632. if (cb == null) {
  20633. return;
  20634. }
  20635. return cb(null, this);
  20636. };
  20637. Subdocument.prototype.$__removeFromParent = function () {
  20638. this.$__parent.set(this.$basePath, null);
  20639. };
  20640. /**
  20641. * Null-out this subdoc
  20642. *
  20643. * @param {Object} [options]
  20644. * @param {Function} [callback] optional callback for compatibility with Document.prototype.remove
  20645. */
  20646. Subdocument.prototype.remove = function (options, callback) {
  20647. if (typeof options === 'function') {
  20648. callback = options;
  20649. options = null;
  20650. }
  20651. registerRemoveListener(this); // If removing entire doc, no need to remove subdoc
  20652. if (!options || !options.noop) {
  20653. this.$__removeFromParent();
  20654. }
  20655. return this.$__remove(callback);
  20656. };
  20657. /*!
  20658. * ignore
  20659. */
  20660. Subdocument.prototype.populate = function () {
  20661. throw new Error('Mongoose does not support calling populate() on nested ' + 'docs. Instead of `doc.nested.populate("path")`, use ' + '`doc.populate("nested.path")`');
  20662. };
  20663. /**
  20664. * Helper for console.log
  20665. *
  20666. * @api public
  20667. */
  20668. Subdocument.prototype.inspect = function () {
  20669. return this.toObject({
  20670. transform: false,
  20671. virtuals: false,
  20672. flattenDecimals: false
  20673. });
  20674. };
  20675. if (util.inspect.custom) {
  20676. /*!
  20677. * Avoid Node deprecation warning DEP0079
  20678. */
  20679. Subdocument.prototype[util.inspect.custom] = Subdocument.prototype.inspect;
  20680. }
  20681. /*!
  20682. * Registers remove event listeners for triggering
  20683. * on subdocuments.
  20684. *
  20685. * @param {Subdocument} sub
  20686. * @api private
  20687. */
  20688. function registerRemoveListener(sub) {
  20689. var owner = sub.ownerDocument();
  20690. function emitRemove() {
  20691. owner.$removeListener('save', emitRemove);
  20692. owner.$removeListener('remove', emitRemove);
  20693. sub.emit('remove', sub);
  20694. sub.constructor.emit('remove', sub);
  20695. owner = sub = null;
  20696. }
  20697. owner.$on('save', emitRemove);
  20698. owner.$on('remove', emitRemove);
  20699. }
  20700. /***/ }),
  20701. /***/ 6872:
  20702. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  20703. "use strict";
  20704. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  20705. /*!
  20706. * Module dependencies.
  20707. */
  20708. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  20709. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  20710. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  20711. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  20712. var ms = __webpack_require__(2068);
  20713. var mpath = __webpack_require__(3564);
  20714. var ObjectId = __webpack_require__(6079);
  20715. var PopulateOptions = __webpack_require__(4034);
  20716. var clone = __webpack_require__(1973);
  20717. var immediate = __webpack_require__(1490);
  20718. var isObject = __webpack_require__(5721);
  20719. var isMongooseArray = __webpack_require__(7339);
  20720. var isMongooseDocumentArray = __webpack_require__(1255);
  20721. var isBsonType = __webpack_require__(1563);
  20722. var getFunctionName = __webpack_require__(6749);
  20723. var isMongooseObject = __webpack_require__(6584);
  20724. var promiseOrCallback = __webpack_require__(8486);
  20725. var schemaMerge = __webpack_require__(4913);
  20726. var specialProperties = __webpack_require__(2862);
  20727. var _require = __webpack_require__(3636),
  20728. trustedSymbol = _require.trustedSymbol;
  20729. var Document;
  20730. exports.specialProperties = specialProperties;
  20731. exports.isMongooseArray = isMongooseArray.isMongooseArray;
  20732. exports.isMongooseDocumentArray = isMongooseDocumentArray.isMongooseDocumentArray;
  20733. exports.registerMongooseArray = isMongooseArray.registerMongooseArray;
  20734. exports.registerMongooseDocumentArray = isMongooseDocumentArray.registerMongooseDocumentArray;
  20735. /*!
  20736. * Produces a collection name from model `name`. By default, just returns
  20737. * the model name
  20738. *
  20739. * @param {String} name a model name
  20740. * @param {Function} pluralize function that pluralizes the collection name
  20741. * @return {String} a collection name
  20742. * @api private
  20743. */
  20744. exports.toCollectionName = function (name, pluralize) {
  20745. if (name === 'system.profile') {
  20746. return name;
  20747. }
  20748. if (name === 'system.indexes') {
  20749. return name;
  20750. }
  20751. if (typeof pluralize === 'function') {
  20752. return pluralize(name);
  20753. }
  20754. return name;
  20755. };
  20756. /*!
  20757. * Determines if `a` and `b` are deep equal.
  20758. *
  20759. * Modified from node/lib/assert.js
  20760. *
  20761. * @param {any} a a value to compare to `b`
  20762. * @param {any} b a value to compare to `a`
  20763. * @return {Boolean}
  20764. * @api private
  20765. */
  20766. exports.deepEqual = function deepEqual(a, b) {
  20767. if (a === b) {
  20768. return true;
  20769. }
  20770. if (_typeof(a) !== 'object' || _typeof(b) !== 'object') {
  20771. return a === b;
  20772. }
  20773. if (a instanceof Date && b instanceof Date) {
  20774. return a.getTime() === b.getTime();
  20775. }
  20776. if (isBsonType(a, 'ObjectID') && isBsonType(b, 'ObjectID') || isBsonType(a, 'Decimal128') && isBsonType(b, 'Decimal128')) {
  20777. return a.toString() === b.toString();
  20778. }
  20779. if (a instanceof RegExp && b instanceof RegExp) {
  20780. return a.source === b.source && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline && a.global === b.global && a.dotAll === b.dotAll && a.unicode === b.unicode && a.sticky === b.sticky && a.hasIndices === b.hasIndices;
  20781. }
  20782. if (a == null || b == null) {
  20783. return false;
  20784. }
  20785. if (a.prototype !== b.prototype) {
  20786. return false;
  20787. }
  20788. if (a instanceof Map || b instanceof Map) {
  20789. if (!(a instanceof Map) || !(b instanceof Map)) {
  20790. return false;
  20791. }
  20792. return deepEqual(Array.from(a.keys()), Array.from(b.keys())) && deepEqual(Array.from(a.values()), Array.from(b.values()));
  20793. } // Handle MongooseNumbers
  20794. if (a instanceof Number && b instanceof Number) {
  20795. return a.valueOf() === b.valueOf();
  20796. }
  20797. if (Buffer.isBuffer(a)) {
  20798. return exports.buffer.areEqual(a, b);
  20799. }
  20800. if (Array.isArray(a) || Array.isArray(b)) {
  20801. if (!Array.isArray(a) || !Array.isArray(b)) {
  20802. return false;
  20803. }
  20804. var len = a.length;
  20805. if (len !== b.length) {
  20806. return false;
  20807. }
  20808. for (var i = 0; i < len; ++i) {
  20809. if (!deepEqual(a[i], b[i])) {
  20810. return false;
  20811. }
  20812. }
  20813. return true;
  20814. }
  20815. if (a.$__ != null) {
  20816. a = a._doc;
  20817. } else if (isMongooseObject(a)) {
  20818. a = a.toObject();
  20819. }
  20820. if (b.$__ != null) {
  20821. b = b._doc;
  20822. } else if (isMongooseObject(b)) {
  20823. b = b.toObject();
  20824. }
  20825. var ka = Object.keys(a);
  20826. var kb = Object.keys(b);
  20827. var kaLength = ka.length; // having the same number of owned properties (keys incorporates
  20828. // hasOwnProperty)
  20829. if (kaLength !== kb.length) {
  20830. return false;
  20831. } // ~~~cheap key test
  20832. for (var _i = kaLength - 1; _i >= 0; _i--) {
  20833. if (ka[_i] !== kb[_i]) {
  20834. return false;
  20835. }
  20836. } // equivalent values for every corresponding key, and
  20837. // ~~~possibly expensive deep test
  20838. for (var _i2 = 0, _ka = ka; _i2 < _ka.length; _i2++) {
  20839. var key = _ka[_i2];
  20840. if (!deepEqual(a[key], b[key])) {
  20841. return false;
  20842. }
  20843. }
  20844. return true;
  20845. };
  20846. /*!
  20847. * Get the last element of an array
  20848. */
  20849. exports.last = function (arr) {
  20850. if (arr.length > 0) {
  20851. return arr[arr.length - 1];
  20852. }
  20853. return void 0;
  20854. };
  20855. exports.clone = clone;
  20856. /*!
  20857. * ignore
  20858. */
  20859. exports.promiseOrCallback = promiseOrCallback;
  20860. /*!
  20861. * ignore
  20862. */
  20863. exports.cloneArrays = function cloneArrays(arr) {
  20864. if (!Array.isArray(arr)) {
  20865. return arr;
  20866. }
  20867. return arr.map(function (el) {
  20868. return exports.cloneArrays(el);
  20869. });
  20870. };
  20871. /*!
  20872. * ignore
  20873. */
  20874. exports.omit = function omit(obj, keys) {
  20875. if (keys == null) {
  20876. return Object.assign({}, obj);
  20877. }
  20878. if (!Array.isArray(keys)) {
  20879. keys = [keys];
  20880. }
  20881. var ret = Object.assign({}, obj);
  20882. var _iterator = _createForOfIteratorHelper(keys),
  20883. _step;
  20884. try {
  20885. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  20886. var key = _step.value;
  20887. delete ret[key];
  20888. }
  20889. } catch (err) {
  20890. _iterator.e(err);
  20891. } finally {
  20892. _iterator.f();
  20893. }
  20894. return ret;
  20895. };
  20896. /*!
  20897. * Shallow copies defaults into options.
  20898. *
  20899. * @param {Object} defaults
  20900. * @param {Object} options
  20901. * @return {Object} the merged object
  20902. * @api private
  20903. */
  20904. exports.options = function (defaults, options) {
  20905. var keys = Object.keys(defaults);
  20906. var i = keys.length;
  20907. var k;
  20908. options = options || {};
  20909. while (i--) {
  20910. k = keys[i];
  20911. if (!(k in options)) {
  20912. options[k] = defaults[k];
  20913. }
  20914. }
  20915. return options;
  20916. };
  20917. /*!
  20918. * Merges `from` into `to` without overwriting existing properties.
  20919. *
  20920. * @param {Object} to
  20921. * @param {Object} from
  20922. * @api private
  20923. */
  20924. exports.merge = function merge(to, from, options, path) {
  20925. options = options || {};
  20926. var keys = Object.keys(from);
  20927. var i = 0;
  20928. var len = keys.length;
  20929. var key;
  20930. if (from[trustedSymbol]) {
  20931. to[trustedSymbol] = from[trustedSymbol];
  20932. }
  20933. path = path || '';
  20934. var omitNested = options.omitNested || {};
  20935. while (i < len) {
  20936. key = keys[i++];
  20937. if (options.omit && options.omit[key]) {
  20938. continue;
  20939. }
  20940. if (omitNested[path]) {
  20941. continue;
  20942. }
  20943. if (specialProperties.has(key)) {
  20944. continue;
  20945. }
  20946. if (to[key] == null) {
  20947. to[key] = from[key];
  20948. } else if (exports.isObject(from[key])) {
  20949. if (!exports.isObject(to[key])) {
  20950. to[key] = {};
  20951. }
  20952. if (from[key] != null) {
  20953. // Skip merging schemas if we're creating a discriminator schema and
  20954. // base schema has a given path as a single nested but discriminator schema
  20955. // has the path as a document array, or vice versa (gh-9534)
  20956. if (options.isDiscriminatorSchemaMerge && from[key].$isSingleNested && to[key].$isMongooseDocumentArray || from[key].$isMongooseDocumentArray && to[key].$isSingleNested) {
  20957. continue;
  20958. } else if (from[key].instanceOfSchema) {
  20959. if (to[key].instanceOfSchema) {
  20960. schemaMerge(to[key], from[key].clone(), options.isDiscriminatorSchemaMerge);
  20961. } else {
  20962. to[key] = from[key].clone();
  20963. }
  20964. continue;
  20965. } else if (isBsonType(from[key], 'ObjectID')) {
  20966. to[key] = new ObjectId(from[key]);
  20967. continue;
  20968. }
  20969. }
  20970. merge(to[key], from[key], options, path ? path + '.' + key : key);
  20971. } else if (options.overwrite) {
  20972. to[key] = from[key];
  20973. }
  20974. }
  20975. };
  20976. /*!
  20977. * Applies toObject recursively.
  20978. *
  20979. * @param {Document|Array|Object} obj
  20980. * @return {Object}
  20981. * @api private
  20982. */
  20983. exports.toObject = function toObject(obj) {
  20984. Document || (Document = __webpack_require__(8727));
  20985. var ret;
  20986. if (obj == null) {
  20987. return obj;
  20988. }
  20989. if (obj instanceof Document) {
  20990. return obj.toObject();
  20991. }
  20992. if (Array.isArray(obj)) {
  20993. ret = [];
  20994. var _iterator2 = _createForOfIteratorHelper(obj),
  20995. _step2;
  20996. try {
  20997. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  20998. var doc = _step2.value;
  20999. ret.push(toObject(doc));
  21000. }
  21001. } catch (err) {
  21002. _iterator2.e(err);
  21003. } finally {
  21004. _iterator2.f();
  21005. }
  21006. return ret;
  21007. }
  21008. if (exports.isPOJO(obj)) {
  21009. ret = {};
  21010. if (obj[trustedSymbol]) {
  21011. ret[trustedSymbol] = obj[trustedSymbol];
  21012. }
  21013. for (var _i3 = 0, _Object$keys = Object.keys(obj); _i3 < _Object$keys.length; _i3++) {
  21014. var k = _Object$keys[_i3];
  21015. if (specialProperties.has(k)) {
  21016. continue;
  21017. }
  21018. ret[k] = toObject(obj[k]);
  21019. }
  21020. return ret;
  21021. }
  21022. return obj;
  21023. };
  21024. exports.isObject = isObject;
  21025. /*!
  21026. * Determines if `arg` is a plain old JavaScript object (POJO). Specifically,
  21027. * `arg` must be an object but not an instance of any special class, like String,
  21028. * ObjectId, etc.
  21029. *
  21030. * `Object.getPrototypeOf()` is part of ES5: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf
  21031. *
  21032. * @param {Object|Array|String|Function|RegExp|any} arg
  21033. * @api private
  21034. * @return {Boolean}
  21035. */
  21036. exports.isPOJO = function isPOJO(arg) {
  21037. if (arg == null || _typeof(arg) !== 'object') {
  21038. return false;
  21039. }
  21040. var proto = Object.getPrototypeOf(arg); // Prototype may be null if you used `Object.create(null)`
  21041. // Checking `proto`'s constructor is safe because `getPrototypeOf()`
  21042. // explicitly crosses the boundary from object data to object metadata
  21043. return !proto || proto.constructor.name === 'Object';
  21044. };
  21045. /*!
  21046. * Determines if `arg` is an object that isn't an instance of a built-in value
  21047. * class, like Array, Buffer, ObjectId, etc.
  21048. */
  21049. exports.isNonBuiltinObject = function isNonBuiltinObject(val) {
  21050. return _typeof(val) === 'object' && !exports.isNativeObject(val) && !exports.isMongooseType(val) && val != null;
  21051. };
  21052. /*!
  21053. * Determines if `obj` is a built-in object like an array, date, boolean,
  21054. * etc.
  21055. */
  21056. exports.isNativeObject = function (arg) {
  21057. return Array.isArray(arg) || arg instanceof Date || arg instanceof Boolean || arg instanceof Number || arg instanceof String;
  21058. };
  21059. /*!
  21060. * Determines if `val` is an object that has no own keys
  21061. */
  21062. exports.isEmptyObject = function (val) {
  21063. return val != null && _typeof(val) === 'object' && Object.keys(val).length === 0;
  21064. };
  21065. /*!
  21066. * Search if `obj` or any POJOs nested underneath `obj` has a property named
  21067. * `key`
  21068. */
  21069. exports.hasKey = function hasKey(obj, key) {
  21070. var props = Object.keys(obj);
  21071. for (var _i4 = 0, _props = props; _i4 < _props.length; _i4++) {
  21072. var prop = _props[_i4];
  21073. if (prop === key) {
  21074. return true;
  21075. }
  21076. if (exports.isPOJO(obj[prop]) && exports.hasKey(obj[prop], key)) {
  21077. return true;
  21078. }
  21079. }
  21080. return false;
  21081. };
  21082. /*!
  21083. * process.nextTick helper.
  21084. *
  21085. * Wraps `callback` in a try/catch + nextTick.
  21086. *
  21087. * node-mongodb-native has a habit of state corruption when an error is immediately thrown from within a collection callback.
  21088. *
  21089. * @param {Function} callback
  21090. * @api private
  21091. */
  21092. exports.tick = function tick(callback) {
  21093. if (typeof callback !== 'function') {
  21094. return;
  21095. }
  21096. return function () {
  21097. try {
  21098. callback.apply(this, arguments);
  21099. } catch (err) {
  21100. // only nextTick on err to get out of
  21101. // the event loop and avoid state corruption.
  21102. immediate(function () {
  21103. throw err;
  21104. });
  21105. }
  21106. };
  21107. };
  21108. /*!
  21109. * Returns true if `v` is an object that can be serialized as a primitive in
  21110. * MongoDB
  21111. */
  21112. exports.isMongooseType = function (v) {
  21113. return isBsonType(v, 'ObjectID') || isBsonType(v, 'Decimal128') || v instanceof Buffer;
  21114. };
  21115. exports.isMongooseObject = isMongooseObject;
  21116. /*!
  21117. * Converts `expires` options of index objects to `expiresAfterSeconds` options for MongoDB.
  21118. *
  21119. * @param {Object} object
  21120. * @api private
  21121. */
  21122. exports.expires = function expires(object) {
  21123. if (!(object && object.constructor.name === 'Object')) {
  21124. return;
  21125. }
  21126. if (!('expires' in object)) {
  21127. return;
  21128. }
  21129. object.expireAfterSeconds = typeof object.expires !== 'string' ? object.expires : Math.round(ms(object.expires) / 1000);
  21130. delete object.expires;
  21131. };
  21132. /*!
  21133. * populate helper
  21134. */
  21135. exports.populate = function populate(path, select, model, match, options, subPopulate, justOne, count) {
  21136. // might have passed an object specifying all arguments
  21137. var obj = null;
  21138. if (arguments.length === 1) {
  21139. if (path instanceof PopulateOptions) {
  21140. // If reusing old populate docs, avoid reusing `_docs` because that may
  21141. // lead to bugs and memory leaks. See gh-11641
  21142. path._docs = [];
  21143. path._childDocs = [];
  21144. return [path];
  21145. }
  21146. if (Array.isArray(path)) {
  21147. var singles = makeSingles(path);
  21148. return singles.map(function (o) {
  21149. return exports.populate(o)[0];
  21150. });
  21151. }
  21152. if (exports.isObject(path)) {
  21153. obj = Object.assign({}, path);
  21154. } else {
  21155. obj = {
  21156. path: path
  21157. };
  21158. }
  21159. } else if (_typeof(model) === 'object') {
  21160. obj = {
  21161. path: path,
  21162. select: select,
  21163. match: model,
  21164. options: match
  21165. };
  21166. } else {
  21167. obj = {
  21168. path: path,
  21169. select: select,
  21170. model: model,
  21171. match: match,
  21172. options: options,
  21173. populate: subPopulate,
  21174. justOne: justOne,
  21175. count: count
  21176. };
  21177. }
  21178. if (typeof obj.path !== 'string') {
  21179. throw new TypeError('utils.populate: invalid path. Expected string. Got typeof `' + _typeof(path) + '`');
  21180. }
  21181. return _populateObj(obj); // The order of select/conditions args is opposite Model.find but
  21182. // necessary to keep backward compatibility (select could be
  21183. // an array, string, or object literal).
  21184. function makeSingles(arr) {
  21185. var ret = [];
  21186. arr.forEach(function (obj) {
  21187. if (/[\s]/.test(obj.path)) {
  21188. var paths = obj.path.split(' ');
  21189. paths.forEach(function (p) {
  21190. var copy = Object.assign({}, obj);
  21191. copy.path = p;
  21192. ret.push(copy);
  21193. });
  21194. } else {
  21195. ret.push(obj);
  21196. }
  21197. });
  21198. return ret;
  21199. }
  21200. };
  21201. function _populateObj(obj) {
  21202. if (Array.isArray(obj.populate)) {
  21203. var _ret = [];
  21204. obj.populate.forEach(function (obj) {
  21205. if (/[\s]/.test(obj.path)) {
  21206. var copy = Object.assign({}, obj);
  21207. var _paths = copy.path.split(' ');
  21208. _paths.forEach(function (p) {
  21209. copy.path = p;
  21210. _ret.push(exports.populate(copy)[0]);
  21211. });
  21212. } else {
  21213. _ret.push(exports.populate(obj)[0]);
  21214. }
  21215. });
  21216. obj.populate = exports.populate(_ret);
  21217. } else if (obj.populate != null && _typeof(obj.populate) === 'object') {
  21218. obj.populate = exports.populate(obj.populate);
  21219. }
  21220. var ret = [];
  21221. var paths = obj.path.split(' ');
  21222. if (obj.options != null) {
  21223. obj.options = exports.clone(obj.options);
  21224. }
  21225. var _iterator3 = _createForOfIteratorHelper(paths),
  21226. _step3;
  21227. try {
  21228. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  21229. var path = _step3.value;
  21230. ret.push(new PopulateOptions(Object.assign({}, obj, {
  21231. path: path
  21232. })));
  21233. }
  21234. } catch (err) {
  21235. _iterator3.e(err);
  21236. } finally {
  21237. _iterator3.f();
  21238. }
  21239. return ret;
  21240. }
  21241. /*!
  21242. * Return the value of `obj` at the given `path`.
  21243. *
  21244. * @param {String} path
  21245. * @param {Object} obj
  21246. */
  21247. exports.getValue = function (path, obj, map) {
  21248. return mpath.get(path, obj, '_doc', map);
  21249. };
  21250. /*!
  21251. * Sets the value of `obj` at the given `path`.
  21252. *
  21253. * @param {String} path
  21254. * @param {Anything} val
  21255. * @param {Object} obj
  21256. */
  21257. exports.setValue = function (path, val, obj, map, _copying) {
  21258. mpath.set(path, val, obj, '_doc', map, _copying);
  21259. };
  21260. /*!
  21261. * Returns an array of values from object `o`.
  21262. *
  21263. * @param {Object} o
  21264. * @return {Array}
  21265. * @private
  21266. */
  21267. exports.object = {};
  21268. exports.object.vals = function vals(o) {
  21269. var keys = Object.keys(o);
  21270. var i = keys.length;
  21271. var ret = [];
  21272. while (i--) {
  21273. ret.push(o[keys[i]]);
  21274. }
  21275. return ret;
  21276. };
  21277. /*!
  21278. * @see exports.options
  21279. */
  21280. exports.object.shallowCopy = exports.options;
  21281. /*!
  21282. * Safer helper for hasOwnProperty checks
  21283. *
  21284. * @param {Object} obj
  21285. * @param {String} prop
  21286. */
  21287. var hop = Object.prototype.hasOwnProperty;
  21288. exports.object.hasOwnProperty = function (obj, prop) {
  21289. return hop.call(obj, prop);
  21290. };
  21291. /*!
  21292. * Determine if `val` is null or undefined
  21293. *
  21294. * @return {Boolean}
  21295. */
  21296. exports.isNullOrUndefined = function (val) {
  21297. return val === null || val === undefined;
  21298. };
  21299. /*!
  21300. * ignore
  21301. */
  21302. exports.array = {};
  21303. /*!
  21304. * Flattens an array.
  21305. *
  21306. * [ 1, [ 2, 3, [4] ]] -> [1,2,3,4]
  21307. *
  21308. * @param {Array} arr
  21309. * @param {Function} [filter] If passed, will be invoked with each item in the array. If `filter` returns a falsy value, the item will not be included in the results.
  21310. * @return {Array}
  21311. * @private
  21312. */
  21313. exports.array.flatten = function flatten(arr, filter, ret) {
  21314. ret || (ret = []);
  21315. arr.forEach(function (item) {
  21316. if (Array.isArray(item)) {
  21317. flatten(item, filter, ret);
  21318. } else {
  21319. if (!filter || filter(item)) {
  21320. ret.push(item);
  21321. }
  21322. }
  21323. });
  21324. return ret;
  21325. };
  21326. /*!
  21327. * ignore
  21328. */
  21329. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  21330. exports.hasUserDefinedProperty = function (obj, key) {
  21331. if (obj == null) {
  21332. return false;
  21333. }
  21334. if (Array.isArray(key)) {
  21335. var _iterator4 = _createForOfIteratorHelper(key),
  21336. _step4;
  21337. try {
  21338. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  21339. var k = _step4.value;
  21340. if (exports.hasUserDefinedProperty(obj, k)) {
  21341. return true;
  21342. }
  21343. }
  21344. } catch (err) {
  21345. _iterator4.e(err);
  21346. } finally {
  21347. _iterator4.f();
  21348. }
  21349. return false;
  21350. }
  21351. if (_hasOwnProperty.call(obj, key)) {
  21352. return true;
  21353. }
  21354. if (_typeof(obj) === 'object' && key in obj) {
  21355. var v = obj[key];
  21356. return v !== Object.prototype[key] && v !== Array.prototype[key];
  21357. }
  21358. return false;
  21359. };
  21360. /*!
  21361. * ignore
  21362. */
  21363. var MAX_ARRAY_INDEX = Math.pow(2, 32) - 1;
  21364. exports.isArrayIndex = function (val) {
  21365. if (typeof val === 'number') {
  21366. return val >= 0 && val <= MAX_ARRAY_INDEX;
  21367. }
  21368. if (typeof val === 'string') {
  21369. if (!/^\d+$/.test(val)) {
  21370. return false;
  21371. }
  21372. val = +val;
  21373. return val >= 0 && val <= MAX_ARRAY_INDEX;
  21374. }
  21375. return false;
  21376. };
  21377. /*!
  21378. * Removes duplicate values from an array
  21379. *
  21380. * [1, 2, 3, 3, 5] => [1, 2, 3, 5]
  21381. * [ ObjectId("550988ba0c19d57f697dc45e"), ObjectId("550988ba0c19d57f697dc45e") ]
  21382. * => [ObjectId("550988ba0c19d57f697dc45e")]
  21383. *
  21384. * @param {Array} arr
  21385. * @return {Array}
  21386. * @private
  21387. */
  21388. exports.array.unique = function (arr) {
  21389. var primitives = new Set();
  21390. var ids = new Set();
  21391. var ret = [];
  21392. var _iterator5 = _createForOfIteratorHelper(arr),
  21393. _step5;
  21394. try {
  21395. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  21396. var item = _step5.value;
  21397. if (typeof item === 'number' || typeof item === 'string' || item == null) {
  21398. if (primitives.has(item)) {
  21399. continue;
  21400. }
  21401. ret.push(item);
  21402. primitives.add(item);
  21403. } else if (isBsonType(item, 'ObjectID')) {
  21404. if (ids.has(item.toString())) {
  21405. continue;
  21406. }
  21407. ret.push(item);
  21408. ids.add(item.toString());
  21409. } else {
  21410. ret.push(item);
  21411. }
  21412. }
  21413. } catch (err) {
  21414. _iterator5.e(err);
  21415. } finally {
  21416. _iterator5.f();
  21417. }
  21418. return ret;
  21419. };
  21420. /*!
  21421. * Determines if two buffers are equal.
  21422. *
  21423. * @param {Buffer} a
  21424. * @param {Object} b
  21425. */
  21426. exports.buffer = {};
  21427. exports.buffer.areEqual = function (a, b) {
  21428. if (!Buffer.isBuffer(a)) {
  21429. return false;
  21430. }
  21431. if (!Buffer.isBuffer(b)) {
  21432. return false;
  21433. }
  21434. if (a.length !== b.length) {
  21435. return false;
  21436. }
  21437. for (var i = 0, len = a.length; i < len; ++i) {
  21438. if (a[i] !== b[i]) {
  21439. return false;
  21440. }
  21441. }
  21442. return true;
  21443. };
  21444. exports.getFunctionName = getFunctionName;
  21445. /*!
  21446. * Decorate buffers
  21447. */
  21448. exports.decorate = function (destination, source) {
  21449. for (var key in source) {
  21450. if (specialProperties.has(key)) {
  21451. continue;
  21452. }
  21453. destination[key] = source[key];
  21454. }
  21455. };
  21456. /**
  21457. * merges to with a copy of from
  21458. *
  21459. * @param {Object} to
  21460. * @param {Object} fromObj
  21461. * @api private
  21462. */
  21463. exports.mergeClone = function (to, fromObj) {
  21464. if (isMongooseObject(fromObj)) {
  21465. fromObj = fromObj.toObject({
  21466. transform: false,
  21467. virtuals: false,
  21468. depopulate: true,
  21469. getters: false,
  21470. flattenDecimals: false
  21471. });
  21472. }
  21473. var keys = Object.keys(fromObj);
  21474. var len = keys.length;
  21475. var i = 0;
  21476. var key;
  21477. while (i < len) {
  21478. key = keys[i++];
  21479. if (specialProperties.has(key)) {
  21480. continue;
  21481. }
  21482. if (typeof to[key] === 'undefined') {
  21483. to[key] = exports.clone(fromObj[key], {
  21484. transform: false,
  21485. virtuals: false,
  21486. depopulate: true,
  21487. getters: false,
  21488. flattenDecimals: false
  21489. });
  21490. } else {
  21491. var val = fromObj[key];
  21492. if (val != null && val.valueOf && !(val instanceof Date)) {
  21493. val = val.valueOf();
  21494. }
  21495. if (exports.isObject(val)) {
  21496. var obj = val;
  21497. if (isMongooseObject(val) && !val.isMongooseBuffer) {
  21498. obj = obj.toObject({
  21499. transform: false,
  21500. virtuals: false,
  21501. depopulate: true,
  21502. getters: false,
  21503. flattenDecimals: false
  21504. });
  21505. }
  21506. if (val.isMongooseBuffer) {
  21507. obj = Buffer.from(obj);
  21508. }
  21509. exports.mergeClone(to[key], obj);
  21510. } else {
  21511. to[key] = exports.clone(val, {
  21512. flattenDecimals: false
  21513. });
  21514. }
  21515. }
  21516. }
  21517. };
  21518. /**
  21519. * Executes a function on each element of an array (like _.each)
  21520. *
  21521. * @param {Array} arr
  21522. * @param {Function} fn
  21523. * @api private
  21524. */
  21525. exports.each = function (arr, fn) {
  21526. var _iterator6 = _createForOfIteratorHelper(arr),
  21527. _step6;
  21528. try {
  21529. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  21530. var item = _step6.value;
  21531. fn(item);
  21532. }
  21533. } catch (err) {
  21534. _iterator6.e(err);
  21535. } finally {
  21536. _iterator6.f();
  21537. }
  21538. };
  21539. /*!
  21540. * ignore
  21541. */
  21542. exports.getOption = function (name) {
  21543. var sources = Array.prototype.slice.call(arguments, 1);
  21544. var _iterator7 = _createForOfIteratorHelper(sources),
  21545. _step7;
  21546. try {
  21547. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  21548. var source = _step7.value;
  21549. if (source == null) {
  21550. continue;
  21551. }
  21552. if (source[name] != null) {
  21553. return source[name];
  21554. }
  21555. }
  21556. } catch (err) {
  21557. _iterator7.e(err);
  21558. } finally {
  21559. _iterator7.f();
  21560. }
  21561. return null;
  21562. };
  21563. /*!
  21564. * ignore
  21565. */
  21566. exports.noop = function () {};
  21567. exports.errorToPOJO = function errorToPOJO(error) {
  21568. var isError = error instanceof Error;
  21569. if (!isError) {
  21570. throw new Error('`error` must be `instanceof Error`.');
  21571. }
  21572. var ret = {};
  21573. var _iterator8 = _createForOfIteratorHelper(Object.getOwnPropertyNames(error)),
  21574. _step8;
  21575. try {
  21576. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  21577. var properyName = _step8.value;
  21578. ret[properyName] = error[properyName];
  21579. }
  21580. } catch (err) {
  21581. _iterator8.e(err);
  21582. } finally {
  21583. _iterator8.f();
  21584. }
  21585. return ret;
  21586. };
  21587. /*!
  21588. * ignore
  21589. */
  21590. exports.warn = function warn(message) {
  21591. return ({env:{}}).emitWarning(message, {
  21592. code: 'MONGOOSE'
  21593. });
  21594. };
  21595. /***/ }),
  21596. /***/ 459:
  21597. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  21598. "use strict";
  21599. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  21600. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  21601. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  21602. var utils = __webpack_require__(6872);
  21603. /**
  21604. * VirtualType constructor
  21605. *
  21606. * This is what mongoose uses to define virtual attributes via `Schema.prototype.virtual`.
  21607. *
  21608. * #### Example:
  21609. *
  21610. * const fullname = schema.virtual('fullname');
  21611. * fullname instanceof mongoose.VirtualType // true
  21612. *
  21613. * @param {Object} options
  21614. * @param {string|function} [options.ref] if `ref` is not nullish, this becomes a [populated virtual](/docs/populate.html#populate-virtuals)
  21615. * @param {string|function} [options.localField] the local field to populate on if this is a populated virtual.
  21616. * @param {string|function} [options.foreignField] the foreign field to populate on if this is a populated virtual.
  21617. * @param {boolean} [options.justOne=false] by default, a populated virtual is an array. If you set `justOne`, the populated virtual will be a single doc or `null`.
  21618. * @param {boolean} [options.getters=false] if you set this to `true`, Mongoose will call any custom getters you defined on this virtual
  21619. * @param {boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](./api.html#query_Query-countDocuments)
  21620. * @param {Object|Function} [options.match=null] add an extra match condition to `populate()`
  21621. * @param {Number} [options.limit=null] add a default `limit` to the `populate()` query
  21622. * @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
  21623. * @param {Number} [options.perDocumentLimit=null] For legacy reasons, `limit` with `populate()` may give incorrect results because it only executes a single query for every document being populated. If you set `perDocumentLimit`, Mongoose will ensure correct `limit` per document by executing a separate query for each document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })` will execute 2 additional queries if `.find()` returns 2 documents.
  21624. * @param {Object} [options.options=null] Additional options like `limit` and `lean`.
  21625. * @param {string} name
  21626. * @api public
  21627. */
  21628. function VirtualType(options, name) {
  21629. this.path = name;
  21630. this.getters = [];
  21631. this.setters = [];
  21632. this.options = Object.assign({}, options);
  21633. }
  21634. /**
  21635. * If no getters/getters, add a default
  21636. *
  21637. * @param {Function} fn
  21638. * @return {VirtualType} this
  21639. * @api private
  21640. */
  21641. VirtualType.prototype._applyDefaultGetters = function () {
  21642. if (this.getters.length > 0 || this.setters.length > 0) {
  21643. return;
  21644. }
  21645. var path = this.path;
  21646. var internalProperty = '$' + path;
  21647. this.getters.push(function () {
  21648. return this[internalProperty];
  21649. });
  21650. this.setters.push(function (v) {
  21651. this[internalProperty] = v;
  21652. });
  21653. };
  21654. /*!
  21655. * ignore
  21656. */
  21657. VirtualType.prototype.clone = function () {
  21658. var clone = new VirtualType(this.options, this.path);
  21659. clone.getters = [].concat(this.getters);
  21660. clone.setters = [].concat(this.setters);
  21661. return clone;
  21662. };
  21663. /**
  21664. * Adds a custom getter to this virtual.
  21665. *
  21666. * Mongoose calls the getter function with the below 3 parameters.
  21667. *
  21668. * - `value`: the value returned by the previous getter. If there is only one getter, `value` will be `undefined`.
  21669. * - `virtual`: the virtual object you called `.get()` on
  21670. * - `doc`: the document this virtual is attached to. Equivalent to `this`.
  21671. *
  21672. * #### Example:
  21673. *
  21674. * const virtual = schema.virtual('fullname');
  21675. * virtual.get(function(value, virtual, doc) {
  21676. * return this.name.first + ' ' + this.name.last;
  21677. * });
  21678. *
  21679. * @param {Function(Any, VirtualType, Document)} fn
  21680. * @return {VirtualType} this
  21681. * @api public
  21682. */
  21683. VirtualType.prototype.get = function (fn) {
  21684. this.getters.push(fn);
  21685. return this;
  21686. };
  21687. /**
  21688. * Adds a custom setter to this virtual.
  21689. *
  21690. * Mongoose calls the setter function with the below 3 parameters.
  21691. *
  21692. * - `value`: the value being set
  21693. * - `virtual`: the virtual object you're calling `.set()` on
  21694. * - `doc`: the document this virtual is attached to. Equivalent to `this`.
  21695. *
  21696. * #### Example:
  21697. *
  21698. * const virtual = schema.virtual('fullname');
  21699. * virtual.set(function(value, virtual, doc) {
  21700. * const parts = value.split(' ');
  21701. * this.name.first = parts[0];
  21702. * this.name.last = parts[1];
  21703. * });
  21704. *
  21705. * const Model = mongoose.model('Test', schema);
  21706. * const doc = new Model();
  21707. * // Calls the setter with `value = 'Jean-Luc Picard'`
  21708. * doc.fullname = 'Jean-Luc Picard';
  21709. * doc.name.first; // 'Jean-Luc'
  21710. * doc.name.last; // 'Picard'
  21711. *
  21712. * @param {Function(Any, VirtualType, Document)} fn
  21713. * @return {VirtualType} this
  21714. * @api public
  21715. */
  21716. VirtualType.prototype.set = function (fn) {
  21717. this.setters.push(fn);
  21718. return this;
  21719. };
  21720. /**
  21721. * Applies getters to `value`.
  21722. *
  21723. * @param {Object} value
  21724. * @param {Document} doc The document this virtual is attached to
  21725. * @return {any} the value after applying all getters
  21726. * @api public
  21727. */
  21728. VirtualType.prototype.applyGetters = function (value, doc) {
  21729. if (utils.hasUserDefinedProperty(this.options, ['ref', 'refPath']) && doc.$$populatedVirtuals && doc.$$populatedVirtuals.hasOwnProperty(this.path)) {
  21730. value = doc.$$populatedVirtuals[this.path];
  21731. }
  21732. var v = value;
  21733. var _iterator = _createForOfIteratorHelper(this.getters),
  21734. _step;
  21735. try {
  21736. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  21737. var getter = _step.value;
  21738. v = getter.call(doc, v, this, doc);
  21739. }
  21740. } catch (err) {
  21741. _iterator.e(err);
  21742. } finally {
  21743. _iterator.f();
  21744. }
  21745. return v;
  21746. };
  21747. /**
  21748. * Applies setters to `value`.
  21749. *
  21750. * @param {Object} value
  21751. * @param {Document} doc
  21752. * @return {any} the value after applying all setters
  21753. * @api public
  21754. */
  21755. VirtualType.prototype.applySetters = function (value, doc) {
  21756. var v = value;
  21757. var _iterator2 = _createForOfIteratorHelper(this.setters),
  21758. _step2;
  21759. try {
  21760. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  21761. var setter = _step2.value;
  21762. v = setter.call(doc, v, this, doc);
  21763. }
  21764. } catch (err) {
  21765. _iterator2.e(err);
  21766. } finally {
  21767. _iterator2.f();
  21768. }
  21769. return v;
  21770. };
  21771. /*!
  21772. * exports
  21773. */
  21774. module.exports = VirtualType;
  21775. /***/ }),
  21776. /***/ 7406:
  21777. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21778. "use strict";
  21779. var asn1 = exports;
  21780. asn1.bignum = __webpack_require__(6781);
  21781. asn1.define = (__webpack_require__(8721).define);
  21782. asn1.base = __webpack_require__(6002);
  21783. asn1.constants = __webpack_require__(4319);
  21784. asn1.decoders = __webpack_require__(4049);
  21785. asn1.encoders = __webpack_require__(6860);
  21786. /***/ }),
  21787. /***/ 8721:
  21788. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21789. "use strict";
  21790. var encoders = __webpack_require__(6860);
  21791. var decoders = __webpack_require__(4049);
  21792. var inherits = __webpack_require__(376);
  21793. var api = exports;
  21794. api.define = function define(name, body) {
  21795. return new Entity(name, body);
  21796. };
  21797. function Entity(name, body) {
  21798. this.name = name;
  21799. this.body = body;
  21800. this.decoders = {};
  21801. this.encoders = {};
  21802. }
  21803. Entity.prototype._createNamed = function createNamed(Base) {
  21804. var name = this.name;
  21805. function Generated(entity) {
  21806. this._initNamed(entity, name);
  21807. }
  21808. inherits(Generated, Base);
  21809. Generated.prototype._initNamed = function _initNamed(entity, name) {
  21810. Base.call(this, entity, name);
  21811. };
  21812. return new Generated(this);
  21813. };
  21814. Entity.prototype._getDecoder = function _getDecoder(enc) {
  21815. enc = enc || 'der'; // Lazily create decoder
  21816. if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]);
  21817. return this.decoders[enc];
  21818. };
  21819. Entity.prototype.decode = function decode(data, enc, options) {
  21820. return this._getDecoder(enc).decode(data, options);
  21821. };
  21822. Entity.prototype._getEncoder = function _getEncoder(enc) {
  21823. enc = enc || 'der'; // Lazily create encoder
  21824. if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]);
  21825. return this.encoders[enc];
  21826. };
  21827. Entity.prototype.encode = function encode(data, enc,
  21828. /* internal */
  21829. reporter) {
  21830. return this._getEncoder(enc).encode(data, reporter);
  21831. };
  21832. /***/ }),
  21833. /***/ 4989:
  21834. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21835. "use strict";
  21836. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  21837. var inherits = __webpack_require__(376);
  21838. var Reporter = (__webpack_require__(1269)/* .Reporter */ .b);
  21839. var Buffer = (__webpack_require__(8723).Buffer);
  21840. function DecoderBuffer(base, options) {
  21841. Reporter.call(this, options);
  21842. if (!Buffer.isBuffer(base)) {
  21843. this.error('Input not Buffer');
  21844. return;
  21845. }
  21846. this.base = base;
  21847. this.offset = 0;
  21848. this.length = base.length;
  21849. }
  21850. inherits(DecoderBuffer, Reporter);
  21851. exports.C = DecoderBuffer;
  21852. DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) {
  21853. if (data instanceof DecoderBuffer) {
  21854. return true;
  21855. } // Or accept compatible API
  21856. var isCompatible = _typeof(data) === 'object' && Buffer.isBuffer(data.base) && data.constructor.name === 'DecoderBuffer' && typeof data.offset === 'number' && typeof data.length === 'number' && typeof data.save === 'function' && typeof data.restore === 'function' && typeof data.isEmpty === 'function' && typeof data.readUInt8 === 'function' && typeof data.skip === 'function' && typeof data.raw === 'function';
  21857. return isCompatible;
  21858. };
  21859. DecoderBuffer.prototype.save = function save() {
  21860. return {
  21861. offset: this.offset,
  21862. reporter: Reporter.prototype.save.call(this)
  21863. };
  21864. };
  21865. DecoderBuffer.prototype.restore = function restore(save) {
  21866. // Return skipped data
  21867. var res = new DecoderBuffer(this.base);
  21868. res.offset = save.offset;
  21869. res.length = this.offset;
  21870. this.offset = save.offset;
  21871. Reporter.prototype.restore.call(this, save.reporter);
  21872. return res;
  21873. };
  21874. DecoderBuffer.prototype.isEmpty = function isEmpty() {
  21875. return this.offset === this.length;
  21876. };
  21877. DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) {
  21878. if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || 'DecoderBuffer overrun');
  21879. };
  21880. DecoderBuffer.prototype.skip = function skip(bytes, fail) {
  21881. if (!(this.offset + bytes <= this.length)) return this.error(fail || 'DecoderBuffer overrun');
  21882. var res = new DecoderBuffer(this.base); // Share reporter state
  21883. res._reporterState = this._reporterState;
  21884. res.offset = this.offset;
  21885. res.length = this.offset + bytes;
  21886. this.offset += bytes;
  21887. return res;
  21888. };
  21889. DecoderBuffer.prototype.raw = function raw(save) {
  21890. return this.base.slice(save ? save.offset : this.offset, this.length);
  21891. };
  21892. function EncoderBuffer(value, reporter) {
  21893. if (Array.isArray(value)) {
  21894. this.length = 0;
  21895. this.value = value.map(function (item) {
  21896. if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter);
  21897. this.length += item.length;
  21898. return item;
  21899. }, this);
  21900. } else if (typeof value === 'number') {
  21901. if (!(0 <= value && value <= 0xff)) return reporter.error('non-byte EncoderBuffer value');
  21902. this.value = value;
  21903. this.length = 1;
  21904. } else if (typeof value === 'string') {
  21905. this.value = value;
  21906. this.length = Buffer.byteLength(value);
  21907. } else if (Buffer.isBuffer(value)) {
  21908. this.value = value;
  21909. this.length = value.length;
  21910. } else {
  21911. return reporter.error('Unsupported type: ' + _typeof(value));
  21912. }
  21913. }
  21914. exports.R = EncoderBuffer;
  21915. EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) {
  21916. if (data instanceof EncoderBuffer) {
  21917. return true;
  21918. } // Or accept compatible API
  21919. var isCompatible = _typeof(data) === 'object' && data.constructor.name === 'EncoderBuffer' && typeof data.length === 'number' && typeof data.join === 'function';
  21920. return isCompatible;
  21921. };
  21922. EncoderBuffer.prototype.join = function join(out, offset) {
  21923. if (!out) out = Buffer.alloc(this.length);
  21924. if (!offset) offset = 0;
  21925. if (this.length === 0) return out;
  21926. if (Array.isArray(this.value)) {
  21927. this.value.forEach(function (item) {
  21928. item.join(out, offset);
  21929. offset += item.length;
  21930. });
  21931. } else {
  21932. if (typeof this.value === 'number') out[offset] = this.value;else if (typeof this.value === 'string') out.write(this.value, offset);else if (Buffer.isBuffer(this.value)) this.value.copy(out, offset);
  21933. offset += this.length;
  21934. }
  21935. return out;
  21936. };
  21937. /***/ }),
  21938. /***/ 6002:
  21939. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  21940. "use strict";
  21941. var base = exports;
  21942. base.Reporter = (__webpack_require__(1269)/* .Reporter */ .b);
  21943. base.DecoderBuffer = (__webpack_require__(4989)/* .DecoderBuffer */ .C);
  21944. base.EncoderBuffer = (__webpack_require__(4989)/* .EncoderBuffer */ .R);
  21945. base.Node = __webpack_require__(3304);
  21946. /***/ }),
  21947. /***/ 3304:
  21948. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  21949. "use strict";
  21950. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  21951. var Reporter = (__webpack_require__(1269)/* .Reporter */ .b);
  21952. var EncoderBuffer = (__webpack_require__(4989)/* .EncoderBuffer */ .R);
  21953. var DecoderBuffer = (__webpack_require__(4989)/* .DecoderBuffer */ .C);
  21954. var assert = __webpack_require__(1130); // Supported tags
  21955. var tags = ['seq', 'seqof', 'set', 'setof', 'objid', 'bool', 'gentime', 'utctime', 'null_', 'enum', 'int', 'objDesc', 'bitstr', 'bmpstr', 'charstr', 'genstr', 'graphstr', 'ia5str', 'iso646str', 'numstr', 'octstr', 'printstr', 't61str', 'unistr', 'utf8str', 'videostr']; // Public methods list
  21956. var methods = ['key', 'obj', 'use', 'optional', 'explicit', 'implicit', 'def', 'choice', 'any', 'contains'].concat(tags); // Overrided methods list
  21957. var overrided = ['_peekTag', '_decodeTag', '_use', '_decodeStr', '_decodeObjid', '_decodeTime', '_decodeNull', '_decodeInt', '_decodeBool', '_decodeList', '_encodeComposite', '_encodeStr', '_encodeObjid', '_encodeTime', '_encodeNull', '_encodeInt', '_encodeBool'];
  21958. function Node(enc, parent, name) {
  21959. var state = {};
  21960. this._baseState = state;
  21961. state.name = name;
  21962. state.enc = enc;
  21963. state.parent = parent || null;
  21964. state.children = null; // State
  21965. state.tag = null;
  21966. state.args = null;
  21967. state.reverseArgs = null;
  21968. state.choice = null;
  21969. state.optional = false;
  21970. state.any = false;
  21971. state.obj = false;
  21972. state.use = null;
  21973. state.useDecoder = null;
  21974. state.key = null;
  21975. state['default'] = null;
  21976. state.explicit = null;
  21977. state.implicit = null;
  21978. state.contains = null; // Should create new instance on each method
  21979. if (!state.parent) {
  21980. state.children = [];
  21981. this._wrap();
  21982. }
  21983. }
  21984. module.exports = Node;
  21985. var stateProps = ['enc', 'parent', 'children', 'tag', 'args', 'reverseArgs', 'choice', 'optional', 'any', 'obj', 'use', 'alteredUse', 'key', 'default', 'explicit', 'implicit', 'contains'];
  21986. Node.prototype.clone = function clone() {
  21987. var state = this._baseState;
  21988. var cstate = {};
  21989. stateProps.forEach(function (prop) {
  21990. cstate[prop] = state[prop];
  21991. });
  21992. var res = new this.constructor(cstate.parent);
  21993. res._baseState = cstate;
  21994. return res;
  21995. };
  21996. Node.prototype._wrap = function wrap() {
  21997. var state = this._baseState;
  21998. methods.forEach(function (method) {
  21999. this[method] = function _wrappedMethod() {
  22000. var clone = new this.constructor(this);
  22001. state.children.push(clone);
  22002. return clone[method].apply(clone, arguments);
  22003. };
  22004. }, this);
  22005. };
  22006. Node.prototype._init = function init(body) {
  22007. var state = this._baseState;
  22008. assert(state.parent === null);
  22009. body.call(this); // Filter children
  22010. state.children = state.children.filter(function (child) {
  22011. return child._baseState.parent === this;
  22012. }, this);
  22013. assert.equal(state.children.length, 1, 'Root node can have only one child');
  22014. };
  22015. Node.prototype._useArgs = function useArgs(args) {
  22016. var state = this._baseState; // Filter children and args
  22017. var children = args.filter(function (arg) {
  22018. return arg instanceof this.constructor;
  22019. }, this);
  22020. args = args.filter(function (arg) {
  22021. return !(arg instanceof this.constructor);
  22022. }, this);
  22023. if (children.length !== 0) {
  22024. assert(state.children === null);
  22025. state.children = children; // Replace parent to maintain backward link
  22026. children.forEach(function (child) {
  22027. child._baseState.parent = this;
  22028. }, this);
  22029. }
  22030. if (args.length !== 0) {
  22031. assert(state.args === null);
  22032. state.args = args;
  22033. state.reverseArgs = args.map(function (arg) {
  22034. if (_typeof(arg) !== 'object' || arg.constructor !== Object) return arg;
  22035. var res = {};
  22036. Object.keys(arg).forEach(function (key) {
  22037. if (key == (key | 0)) key |= 0;
  22038. var value = arg[key];
  22039. res[value] = key;
  22040. });
  22041. return res;
  22042. });
  22043. }
  22044. }; //
  22045. // Overrided methods
  22046. //
  22047. overrided.forEach(function (method) {
  22048. Node.prototype[method] = function _overrided() {
  22049. var state = this._baseState;
  22050. throw new Error(method + ' not implemented for encoding: ' + state.enc);
  22051. };
  22052. }); //
  22053. // Public methods
  22054. //
  22055. tags.forEach(function (tag) {
  22056. Node.prototype[tag] = function _tagMethod() {
  22057. var state = this._baseState;
  22058. var args = Array.prototype.slice.call(arguments);
  22059. assert(state.tag === null);
  22060. state.tag = tag;
  22061. this._useArgs(args);
  22062. return this;
  22063. };
  22064. });
  22065. Node.prototype.use = function use(item) {
  22066. assert(item);
  22067. var state = this._baseState;
  22068. assert(state.use === null);
  22069. state.use = item;
  22070. return this;
  22071. };
  22072. Node.prototype.optional = function optional() {
  22073. var state = this._baseState;
  22074. state.optional = true;
  22075. return this;
  22076. };
  22077. Node.prototype.def = function def(val) {
  22078. var state = this._baseState;
  22079. assert(state['default'] === null);
  22080. state['default'] = val;
  22081. state.optional = true;
  22082. return this;
  22083. };
  22084. Node.prototype.explicit = function explicit(num) {
  22085. var state = this._baseState;
  22086. assert(state.explicit === null && state.implicit === null);
  22087. state.explicit = num;
  22088. return this;
  22089. };
  22090. Node.prototype.implicit = function implicit(num) {
  22091. var state = this._baseState;
  22092. assert(state.explicit === null && state.implicit === null);
  22093. state.implicit = num;
  22094. return this;
  22095. };
  22096. Node.prototype.obj = function obj() {
  22097. var state = this._baseState;
  22098. var args = Array.prototype.slice.call(arguments);
  22099. state.obj = true;
  22100. if (args.length !== 0) this._useArgs(args);
  22101. return this;
  22102. };
  22103. Node.prototype.key = function key(newKey) {
  22104. var state = this._baseState;
  22105. assert(state.key === null);
  22106. state.key = newKey;
  22107. return this;
  22108. };
  22109. Node.prototype.any = function any() {
  22110. var state = this._baseState;
  22111. state.any = true;
  22112. return this;
  22113. };
  22114. Node.prototype.choice = function choice(obj) {
  22115. var state = this._baseState;
  22116. assert(state.choice === null);
  22117. state.choice = obj;
  22118. this._useArgs(Object.keys(obj).map(function (key) {
  22119. return obj[key];
  22120. }));
  22121. return this;
  22122. };
  22123. Node.prototype.contains = function contains(item) {
  22124. var state = this._baseState;
  22125. assert(state.use === null);
  22126. state.contains = item;
  22127. return this;
  22128. }; //
  22129. // Decoding
  22130. //
  22131. Node.prototype._decode = function decode(input, options) {
  22132. var state = this._baseState; // Decode root node
  22133. if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options));
  22134. var result = state['default'];
  22135. var present = true;
  22136. var prevKey = null;
  22137. if (state.key !== null) prevKey = input.enterKey(state.key); // Check if tag is there
  22138. if (state.optional) {
  22139. var tag = null;
  22140. if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag;
  22141. if (tag === null && !state.any) {
  22142. // Trial and Error
  22143. var save = input.save();
  22144. try {
  22145. if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options);
  22146. present = true;
  22147. } catch (e) {
  22148. present = false;
  22149. }
  22150. input.restore(save);
  22151. } else {
  22152. present = this._peekTag(input, tag, state.any);
  22153. if (input.isError(present)) return present;
  22154. }
  22155. } // Push object on stack
  22156. var prevObj;
  22157. if (state.obj && present) prevObj = input.enterObject();
  22158. if (present) {
  22159. // Unwrap explicit values
  22160. if (state.explicit !== null) {
  22161. var explicit = this._decodeTag(input, state.explicit);
  22162. if (input.isError(explicit)) return explicit;
  22163. input = explicit;
  22164. }
  22165. var start = input.offset; // Unwrap implicit and normal values
  22166. if (state.use === null && state.choice === null) {
  22167. var _save;
  22168. if (state.any) _save = input.save();
  22169. var body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any);
  22170. if (input.isError(body)) return body;
  22171. if (state.any) result = input.raw(_save);else input = body;
  22172. }
  22173. if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, 'tagged');
  22174. if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, 'content'); // Select proper method for tag
  22175. if (state.any) {// no-op
  22176. } else if (state.choice === null) {
  22177. result = this._decodeGeneric(state.tag, input, options);
  22178. } else {
  22179. result = this._decodeChoice(input, options);
  22180. }
  22181. if (input.isError(result)) return result; // Decode children
  22182. if (!state.any && state.choice === null && state.children !== null) {
  22183. state.children.forEach(function decodeChildren(child) {
  22184. // NOTE: We are ignoring errors here, to let parser continue with other
  22185. // parts of encoded data
  22186. child._decode(input, options);
  22187. });
  22188. } // Decode contained/encoded by schema, only in bit or octet strings
  22189. if (state.contains && (state.tag === 'octstr' || state.tag === 'bitstr')) {
  22190. var data = new DecoderBuffer(result);
  22191. result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options);
  22192. }
  22193. } // Pop object
  22194. if (state.obj && present) result = input.leaveObject(prevObj); // Set key
  22195. if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey);
  22196. return result;
  22197. };
  22198. Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) {
  22199. var state = this._baseState;
  22200. if (tag === 'seq' || tag === 'set') return null;
  22201. if (tag === 'seqof' || tag === 'setof') return this._decodeList(input, tag, state.args[0], options);else if (/str$/.test(tag)) return this._decodeStr(input, tag, options);else if (tag === 'objid' && state.args) return this._decodeObjid(input, state.args[0], state.args[1], options);else if (tag === 'objid') return this._decodeObjid(input, null, null, options);else if (tag === 'gentime' || tag === 'utctime') return this._decodeTime(input, tag, options);else if (tag === 'null_') return this._decodeNull(input, options);else if (tag === 'bool') return this._decodeBool(input, options);else if (tag === 'objDesc') return this._decodeStr(input, tag, options);else if (tag === 'int' || tag === 'enum') return this._decodeInt(input, state.args && state.args[0], options);
  22202. if (state.use !== null) {
  22203. return this._getUse(state.use, input._reporterState.obj)._decode(input, options);
  22204. } else {
  22205. return input.error('unknown tag: ' + tag);
  22206. }
  22207. };
  22208. Node.prototype._getUse = function _getUse(entity, obj) {
  22209. var state = this._baseState; // Create altered use decoder if implicit is set
  22210. state.useDecoder = this._use(entity, obj);
  22211. assert(state.useDecoder._baseState.parent === null);
  22212. state.useDecoder = state.useDecoder._baseState.children[0];
  22213. if (state.implicit !== state.useDecoder._baseState.implicit) {
  22214. state.useDecoder = state.useDecoder.clone();
  22215. state.useDecoder._baseState.implicit = state.implicit;
  22216. }
  22217. return state.useDecoder;
  22218. };
  22219. Node.prototype._decodeChoice = function decodeChoice(input, options) {
  22220. var state = this._baseState;
  22221. var result = null;
  22222. var match = false;
  22223. Object.keys(state.choice).some(function (key) {
  22224. var save = input.save();
  22225. var node = state.choice[key];
  22226. try {
  22227. var value = node._decode(input, options);
  22228. if (input.isError(value)) return false;
  22229. result = {
  22230. type: key,
  22231. value: value
  22232. };
  22233. match = true;
  22234. } catch (e) {
  22235. input.restore(save);
  22236. return false;
  22237. }
  22238. return true;
  22239. }, this);
  22240. if (!match) return input.error('Choice not matched');
  22241. return result;
  22242. }; //
  22243. // Encoding
  22244. //
  22245. Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) {
  22246. return new EncoderBuffer(data, this.reporter);
  22247. };
  22248. Node.prototype._encode = function encode(data, reporter, parent) {
  22249. var state = this._baseState;
  22250. if (state['default'] !== null && state['default'] === data) return;
  22251. var result = this._encodeValue(data, reporter, parent);
  22252. if (result === undefined) return;
  22253. if (this._skipDefault(result, reporter, parent)) return;
  22254. return result;
  22255. };
  22256. Node.prototype._encodeValue = function encode(data, reporter, parent) {
  22257. var state = this._baseState; // Decode root node
  22258. if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter());
  22259. var result = null; // Set reporter to share it with a child class
  22260. this.reporter = reporter; // Check if data is there
  22261. if (state.optional && data === undefined) {
  22262. if (state['default'] !== null) data = state['default'];else return;
  22263. } // Encode children first
  22264. var content = null;
  22265. var primitive = false;
  22266. if (state.any) {
  22267. // Anything that was given is translated to buffer
  22268. result = this._createEncoderBuffer(data);
  22269. } else if (state.choice) {
  22270. result = this._encodeChoice(data, reporter);
  22271. } else if (state.contains) {
  22272. content = this._getUse(state.contains, parent)._encode(data, reporter);
  22273. primitive = true;
  22274. } else if (state.children) {
  22275. content = state.children.map(function (child) {
  22276. if (child._baseState.tag === 'null_') return child._encode(null, reporter, data);
  22277. if (child._baseState.key === null) return reporter.error('Child should have a key');
  22278. var prevKey = reporter.enterKey(child._baseState.key);
  22279. if (_typeof(data) !== 'object') return reporter.error('Child expected, but input is not object');
  22280. var res = child._encode(data[child._baseState.key], reporter, data);
  22281. reporter.leaveKey(prevKey);
  22282. return res;
  22283. }, this).filter(function (child) {
  22284. return child;
  22285. });
  22286. content = this._createEncoderBuffer(content);
  22287. } else {
  22288. if (state.tag === 'seqof' || state.tag === 'setof') {
  22289. // TODO(indutny): this should be thrown on DSL level
  22290. if (!(state.args && state.args.length === 1)) return reporter.error('Too many args for : ' + state.tag);
  22291. if (!Array.isArray(data)) return reporter.error('seqof/setof, but data is not Array');
  22292. var child = this.clone();
  22293. child._baseState.implicit = null;
  22294. content = this._createEncoderBuffer(data.map(function (item) {
  22295. var state = this._baseState;
  22296. return this._getUse(state.args[0], data)._encode(item, reporter);
  22297. }, child));
  22298. } else if (state.use !== null) {
  22299. result = this._getUse(state.use, parent)._encode(data, reporter);
  22300. } else {
  22301. content = this._encodePrimitive(state.tag, data);
  22302. primitive = true;
  22303. }
  22304. } // Encode data itself
  22305. if (!state.any && state.choice === null) {
  22306. var tag = state.implicit !== null ? state.implicit : state.tag;
  22307. var cls = state.implicit === null ? 'universal' : 'context';
  22308. if (tag === null) {
  22309. if (state.use === null) reporter.error('Tag could be omitted only for .use()');
  22310. } else {
  22311. if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content);
  22312. }
  22313. } // Wrap in explicit
  22314. if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, 'context', result);
  22315. return result;
  22316. };
  22317. Node.prototype._encodeChoice = function encodeChoice(data, reporter) {
  22318. var state = this._baseState;
  22319. var node = state.choice[data.type];
  22320. if (!node) {
  22321. assert(false, data.type + ' not found in ' + JSON.stringify(Object.keys(state.choice)));
  22322. }
  22323. return node._encode(data.value, reporter);
  22324. };
  22325. Node.prototype._encodePrimitive = function encodePrimitive(tag, data) {
  22326. var state = this._baseState;
  22327. if (/str$/.test(tag)) return this._encodeStr(data, tag);else if (tag === 'objid' && state.args) return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);else if (tag === 'objid') return this._encodeObjid(data, null, null);else if (tag === 'gentime' || tag === 'utctime') return this._encodeTime(data, tag);else if (tag === 'null_') return this._encodeNull();else if (tag === 'int' || tag === 'enum') return this._encodeInt(data, state.args && state.reverseArgs[0]);else if (tag === 'bool') return this._encodeBool(data);else if (tag === 'objDesc') return this._encodeStr(data, tag);else throw new Error('Unsupported tag: ' + tag);
  22328. };
  22329. Node.prototype._isNumstr = function isNumstr(str) {
  22330. return /^[0-9 ]*$/.test(str);
  22331. };
  22332. Node.prototype._isPrintstr = function isPrintstr(str) {
  22333. return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str);
  22334. };
  22335. /***/ }),
  22336. /***/ 1269:
  22337. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22338. "use strict";
  22339. var inherits = __webpack_require__(376);
  22340. function Reporter(options) {
  22341. this._reporterState = {
  22342. obj: null,
  22343. path: [],
  22344. options: options || {},
  22345. errors: []
  22346. };
  22347. }
  22348. exports.b = Reporter;
  22349. Reporter.prototype.isError = function isError(obj) {
  22350. return obj instanceof ReporterError;
  22351. };
  22352. Reporter.prototype.save = function save() {
  22353. var state = this._reporterState;
  22354. return {
  22355. obj: state.obj,
  22356. pathLen: state.path.length
  22357. };
  22358. };
  22359. Reporter.prototype.restore = function restore(data) {
  22360. var state = this._reporterState;
  22361. state.obj = data.obj;
  22362. state.path = state.path.slice(0, data.pathLen);
  22363. };
  22364. Reporter.prototype.enterKey = function enterKey(key) {
  22365. return this._reporterState.path.push(key);
  22366. };
  22367. Reporter.prototype.exitKey = function exitKey(index) {
  22368. var state = this._reporterState;
  22369. state.path = state.path.slice(0, index - 1);
  22370. };
  22371. Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
  22372. var state = this._reporterState;
  22373. this.exitKey(index);
  22374. if (state.obj !== null) state.obj[key] = value;
  22375. };
  22376. Reporter.prototype.path = function path() {
  22377. return this._reporterState.path.join('/');
  22378. };
  22379. Reporter.prototype.enterObject = function enterObject() {
  22380. var state = this._reporterState;
  22381. var prev = state.obj;
  22382. state.obj = {};
  22383. return prev;
  22384. };
  22385. Reporter.prototype.leaveObject = function leaveObject(prev) {
  22386. var state = this._reporterState;
  22387. var now = state.obj;
  22388. state.obj = prev;
  22389. return now;
  22390. };
  22391. Reporter.prototype.error = function error(msg) {
  22392. var err;
  22393. var state = this._reporterState;
  22394. var inherited = msg instanceof ReporterError;
  22395. if (inherited) {
  22396. err = msg;
  22397. } else {
  22398. err = new ReporterError(state.path.map(function (elem) {
  22399. return '[' + JSON.stringify(elem) + ']';
  22400. }).join(''), msg.message || msg, msg.stack);
  22401. }
  22402. if (!state.options.partial) throw err;
  22403. if (!inherited) state.errors.push(err);
  22404. return err;
  22405. };
  22406. Reporter.prototype.wrapResult = function wrapResult(result) {
  22407. var state = this._reporterState;
  22408. if (!state.options.partial) return result;
  22409. return {
  22410. result: this.isError(result) ? null : result,
  22411. errors: state.errors
  22412. };
  22413. };
  22414. function ReporterError(path, msg) {
  22415. this.path = path;
  22416. this.rethrow(msg);
  22417. }
  22418. inherits(ReporterError, Error);
  22419. ReporterError.prototype.rethrow = function rethrow(msg) {
  22420. this.message = msg + ' at: ' + (this.path || '(shallow)');
  22421. if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError);
  22422. if (!this.stack) {
  22423. try {
  22424. // IE only adds stack when thrown
  22425. throw new Error(this.message);
  22426. } catch (e) {
  22427. this.stack = e.stack;
  22428. }
  22429. }
  22430. return this;
  22431. };
  22432. /***/ }),
  22433. /***/ 2007:
  22434. /***/ ((__unused_webpack_module, exports) => {
  22435. "use strict";
  22436. // Helper
  22437. function reverse(map) {
  22438. var res = {};
  22439. Object.keys(map).forEach(function (key) {
  22440. // Convert key to integer if it is stringified
  22441. if ((key | 0) == key) key = key | 0;
  22442. var value = map[key];
  22443. res[value] = key;
  22444. });
  22445. return res;
  22446. }
  22447. exports.tagClass = {
  22448. 0: 'universal',
  22449. 1: 'application',
  22450. 2: 'context',
  22451. 3: 'private'
  22452. };
  22453. exports.tagClassByName = reverse(exports.tagClass);
  22454. exports.tag = {
  22455. 0x00: 'end',
  22456. 0x01: 'bool',
  22457. 0x02: 'int',
  22458. 0x03: 'bitstr',
  22459. 0x04: 'octstr',
  22460. 0x05: 'null_',
  22461. 0x06: 'objid',
  22462. 0x07: 'objDesc',
  22463. 0x08: 'external',
  22464. 0x09: 'real',
  22465. 0x0a: 'enum',
  22466. 0x0b: 'embed',
  22467. 0x0c: 'utf8str',
  22468. 0x0d: 'relativeOid',
  22469. 0x10: 'seq',
  22470. 0x11: 'set',
  22471. 0x12: 'numstr',
  22472. 0x13: 'printstr',
  22473. 0x14: 't61str',
  22474. 0x15: 'videostr',
  22475. 0x16: 'ia5str',
  22476. 0x17: 'utctime',
  22477. 0x18: 'gentime',
  22478. 0x19: 'graphstr',
  22479. 0x1a: 'iso646str',
  22480. 0x1b: 'genstr',
  22481. 0x1c: 'unistr',
  22482. 0x1d: 'charstr',
  22483. 0x1e: 'bmpstr'
  22484. };
  22485. exports.tagByName = reverse(exports.tag);
  22486. /***/ }),
  22487. /***/ 4319:
  22488. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22489. "use strict";
  22490. var constants = exports; // Helper
  22491. constants._reverse = function reverse(map) {
  22492. var res = {};
  22493. Object.keys(map).forEach(function (key) {
  22494. // Convert key to integer if it is stringified
  22495. if ((key | 0) == key) key = key | 0;
  22496. var value = map[key];
  22497. res[value] = key;
  22498. });
  22499. return res;
  22500. };
  22501. constants.der = __webpack_require__(2007);
  22502. /***/ }),
  22503. /***/ 4201:
  22504. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  22505. "use strict";
  22506. var inherits = __webpack_require__(376);
  22507. var bignum = __webpack_require__(6781);
  22508. var DecoderBuffer = (__webpack_require__(4989)/* .DecoderBuffer */ .C);
  22509. var Node = __webpack_require__(3304); // Import DER constants
  22510. var der = __webpack_require__(2007);
  22511. function DERDecoder(entity) {
  22512. this.enc = 'der';
  22513. this.name = entity.name;
  22514. this.entity = entity; // Construct base tree
  22515. this.tree = new DERNode();
  22516. this.tree._init(entity.body);
  22517. }
  22518. module.exports = DERDecoder;
  22519. DERDecoder.prototype.decode = function decode(data, options) {
  22520. if (!DecoderBuffer.isDecoderBuffer(data)) {
  22521. data = new DecoderBuffer(data, options);
  22522. }
  22523. return this.tree._decode(data, options);
  22524. }; // Tree methods
  22525. function DERNode(parent) {
  22526. Node.call(this, 'der', parent);
  22527. }
  22528. inherits(DERNode, Node);
  22529. DERNode.prototype._peekTag = function peekTag(buffer, tag, any) {
  22530. if (buffer.isEmpty()) return false;
  22531. var state = buffer.save();
  22532. var decodedTag = derDecodeTag(buffer, 'Failed to peek tag: "' + tag + '"');
  22533. if (buffer.isError(decodedTag)) return decodedTag;
  22534. buffer.restore(state);
  22535. return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + 'of' === tag || any;
  22536. };
  22537. DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) {
  22538. var decodedTag = derDecodeTag(buffer, 'Failed to decode tag of "' + tag + '"');
  22539. if (buffer.isError(decodedTag)) return decodedTag;
  22540. var len = derDecodeLen(buffer, decodedTag.primitive, 'Failed to get length of "' + tag + '"'); // Failure
  22541. if (buffer.isError(len)) return len;
  22542. if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + 'of' !== tag) {
  22543. return buffer.error('Failed to match tag: "' + tag + '"');
  22544. }
  22545. if (decodedTag.primitive || len !== null) return buffer.skip(len, 'Failed to match body of: "' + tag + '"'); // Indefinite length... find END tag
  22546. var state = buffer.save();
  22547. var res = this._skipUntilEnd(buffer, 'Failed to skip indefinite length body: "' + this.tag + '"');
  22548. if (buffer.isError(res)) return res;
  22549. len = buffer.offset - state.offset;
  22550. buffer.restore(state);
  22551. return buffer.skip(len, 'Failed to match body of: "' + tag + '"');
  22552. };
  22553. DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) {
  22554. for (;;) {
  22555. var tag = derDecodeTag(buffer, fail);
  22556. if (buffer.isError(tag)) return tag;
  22557. var len = derDecodeLen(buffer, tag.primitive, fail);
  22558. if (buffer.isError(len)) return len;
  22559. var res = void 0;
  22560. if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); // Failure
  22561. if (buffer.isError(res)) return res;
  22562. if (tag.tagStr === 'end') break;
  22563. }
  22564. };
  22565. DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) {
  22566. var result = [];
  22567. while (!buffer.isEmpty()) {
  22568. var possibleEnd = this._peekTag(buffer, 'end');
  22569. if (buffer.isError(possibleEnd)) return possibleEnd;
  22570. var res = decoder.decode(buffer, 'der', options);
  22571. if (buffer.isError(res) && possibleEnd) break;
  22572. result.push(res);
  22573. }
  22574. return result;
  22575. };
  22576. DERNode.prototype._decodeStr = function decodeStr(buffer, tag) {
  22577. if (tag === 'bitstr') {
  22578. var unused = buffer.readUInt8();
  22579. if (buffer.isError(unused)) return unused;
  22580. return {
  22581. unused: unused,
  22582. data: buffer.raw()
  22583. };
  22584. } else if (tag === 'bmpstr') {
  22585. var raw = buffer.raw();
  22586. if (raw.length % 2 === 1) return buffer.error('Decoding of string type: bmpstr length mismatch');
  22587. var str = '';
  22588. for (var i = 0; i < raw.length / 2; i++) {
  22589. str += String.fromCharCode(raw.readUInt16BE(i * 2));
  22590. }
  22591. return str;
  22592. } else if (tag === 'numstr') {
  22593. var numstr = buffer.raw().toString('ascii');
  22594. if (!this._isNumstr(numstr)) {
  22595. return buffer.error('Decoding of string type: ' + 'numstr unsupported characters');
  22596. }
  22597. return numstr;
  22598. } else if (tag === 'octstr') {
  22599. return buffer.raw();
  22600. } else if (tag === 'objDesc') {
  22601. return buffer.raw();
  22602. } else if (tag === 'printstr') {
  22603. var printstr = buffer.raw().toString('ascii');
  22604. if (!this._isPrintstr(printstr)) {
  22605. return buffer.error('Decoding of string type: ' + 'printstr unsupported characters');
  22606. }
  22607. return printstr;
  22608. } else if (/str$/.test(tag)) {
  22609. return buffer.raw().toString();
  22610. } else {
  22611. return buffer.error('Decoding of string type: ' + tag + ' unsupported');
  22612. }
  22613. };
  22614. DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) {
  22615. var result;
  22616. var identifiers = [];
  22617. var ident = 0;
  22618. var subident = 0;
  22619. while (!buffer.isEmpty()) {
  22620. subident = buffer.readUInt8();
  22621. ident <<= 7;
  22622. ident |= subident & 0x7f;
  22623. if ((subident & 0x80) === 0) {
  22624. identifiers.push(ident);
  22625. ident = 0;
  22626. }
  22627. }
  22628. if (subident & 0x80) identifiers.push(ident);
  22629. var first = identifiers[0] / 40 | 0;
  22630. var second = identifiers[0] % 40;
  22631. if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1));
  22632. if (values) {
  22633. var tmp = values[result.join(' ')];
  22634. if (tmp === undefined) tmp = values[result.join('.')];
  22635. if (tmp !== undefined) result = tmp;
  22636. }
  22637. return result;
  22638. };
  22639. DERNode.prototype._decodeTime = function decodeTime(buffer, tag) {
  22640. var str = buffer.raw().toString();
  22641. var year;
  22642. var mon;
  22643. var day;
  22644. var hour;
  22645. var min;
  22646. var sec;
  22647. if (tag === 'gentime') {
  22648. year = str.slice(0, 4) | 0;
  22649. mon = str.slice(4, 6) | 0;
  22650. day = str.slice(6, 8) | 0;
  22651. hour = str.slice(8, 10) | 0;
  22652. min = str.slice(10, 12) | 0;
  22653. sec = str.slice(12, 14) | 0;
  22654. } else if (tag === 'utctime') {
  22655. year = str.slice(0, 2) | 0;
  22656. mon = str.slice(2, 4) | 0;
  22657. day = str.slice(4, 6) | 0;
  22658. hour = str.slice(6, 8) | 0;
  22659. min = str.slice(8, 10) | 0;
  22660. sec = str.slice(10, 12) | 0;
  22661. if (year < 70) year = 2000 + year;else year = 1900 + year;
  22662. } else {
  22663. return buffer.error('Decoding ' + tag + ' time is not supported yet');
  22664. }
  22665. return Date.UTC(year, mon - 1, day, hour, min, sec, 0);
  22666. };
  22667. DERNode.prototype._decodeNull = function decodeNull() {
  22668. return null;
  22669. };
  22670. DERNode.prototype._decodeBool = function decodeBool(buffer) {
  22671. var res = buffer.readUInt8();
  22672. if (buffer.isError(res)) return res;else return res !== 0;
  22673. };
  22674. DERNode.prototype._decodeInt = function decodeInt(buffer, values) {
  22675. // Bigint, return as it is (assume big endian)
  22676. var raw = buffer.raw();
  22677. var res = new bignum(raw);
  22678. if (values) res = values[res.toString(10)] || res;
  22679. return res;
  22680. };
  22681. DERNode.prototype._use = function use(entity, obj) {
  22682. if (typeof entity === 'function') entity = entity(obj);
  22683. return entity._getDecoder('der').tree;
  22684. }; // Utility methods
  22685. function derDecodeTag(buf, fail) {
  22686. var tag = buf.readUInt8(fail);
  22687. if (buf.isError(tag)) return tag;
  22688. var cls = der.tagClass[tag >> 6];
  22689. var primitive = (tag & 0x20) === 0; // Multi-octet tag - load
  22690. if ((tag & 0x1f) === 0x1f) {
  22691. var oct = tag;
  22692. tag = 0;
  22693. while ((oct & 0x80) === 0x80) {
  22694. oct = buf.readUInt8(fail);
  22695. if (buf.isError(oct)) return oct;
  22696. tag <<= 7;
  22697. tag |= oct & 0x7f;
  22698. }
  22699. } else {
  22700. tag &= 0x1f;
  22701. }
  22702. var tagStr = der.tag[tag];
  22703. return {
  22704. cls: cls,
  22705. primitive: primitive,
  22706. tag: tag,
  22707. tagStr: tagStr
  22708. };
  22709. }
  22710. function derDecodeLen(buf, primitive, fail) {
  22711. var len = buf.readUInt8(fail);
  22712. if (buf.isError(len)) return len; // Indefinite form
  22713. if (!primitive && len === 0x80) return null; // Definite form
  22714. if ((len & 0x80) === 0) {
  22715. // Short form
  22716. return len;
  22717. } // Long form
  22718. var num = len & 0x7f;
  22719. if (num > 4) return buf.error('length octect is too long');
  22720. len = 0;
  22721. for (var i = 0; i < num; i++) {
  22722. len <<= 8;
  22723. var j = buf.readUInt8(fail);
  22724. if (buf.isError(j)) return j;
  22725. len |= j;
  22726. }
  22727. return len;
  22728. }
  22729. /***/ }),
  22730. /***/ 4049:
  22731. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22732. "use strict";
  22733. var decoders = exports;
  22734. decoders.der = __webpack_require__(4201);
  22735. decoders.pem = __webpack_require__(618);
  22736. /***/ }),
  22737. /***/ 618:
  22738. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  22739. "use strict";
  22740. var inherits = __webpack_require__(376);
  22741. var Buffer = (__webpack_require__(8723).Buffer);
  22742. var DERDecoder = __webpack_require__(4201);
  22743. function PEMDecoder(entity) {
  22744. DERDecoder.call(this, entity);
  22745. this.enc = 'pem';
  22746. }
  22747. inherits(PEMDecoder, DERDecoder);
  22748. module.exports = PEMDecoder;
  22749. PEMDecoder.prototype.decode = function decode(data, options) {
  22750. var lines = data.toString().split(/[\r\n]+/g);
  22751. var label = options.label.toUpperCase();
  22752. var re = /^-----(BEGIN|END) ([^-]+)-----$/;
  22753. var start = -1;
  22754. var end = -1;
  22755. for (var i = 0; i < lines.length; i++) {
  22756. var match = lines[i].match(re);
  22757. if (match === null) continue;
  22758. if (match[2] !== label) continue;
  22759. if (start === -1) {
  22760. if (match[1] !== 'BEGIN') break;
  22761. start = i;
  22762. } else {
  22763. if (match[1] !== 'END') break;
  22764. end = i;
  22765. break;
  22766. }
  22767. }
  22768. if (start === -1 || end === -1) throw new Error('PEM section not found for: ' + label);
  22769. var base64 = lines.slice(start + 1, end).join(''); // Remove excessive symbols
  22770. base64.replace(/[^a-z0-9+/=]+/gi, '');
  22771. var input = Buffer.from(base64, 'base64');
  22772. return DERDecoder.prototype.decode.call(this, input, options);
  22773. };
  22774. /***/ }),
  22775. /***/ 1889:
  22776. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  22777. "use strict";
  22778. var inherits = __webpack_require__(376);
  22779. var Buffer = (__webpack_require__(8723).Buffer);
  22780. var Node = __webpack_require__(3304); // Import DER constants
  22781. var der = __webpack_require__(2007);
  22782. function DEREncoder(entity) {
  22783. this.enc = 'der';
  22784. this.name = entity.name;
  22785. this.entity = entity; // Construct base tree
  22786. this.tree = new DERNode();
  22787. this.tree._init(entity.body);
  22788. }
  22789. module.exports = DEREncoder;
  22790. DEREncoder.prototype.encode = function encode(data, reporter) {
  22791. return this.tree._encode(data, reporter).join();
  22792. }; // Tree methods
  22793. function DERNode(parent) {
  22794. Node.call(this, 'der', parent);
  22795. }
  22796. inherits(DERNode, Node);
  22797. DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) {
  22798. var encodedTag = encodeTag(tag, primitive, cls, this.reporter); // Short form
  22799. if (content.length < 0x80) {
  22800. var _header = Buffer.alloc(2);
  22801. _header[0] = encodedTag;
  22802. _header[1] = content.length;
  22803. return this._createEncoderBuffer([_header, content]);
  22804. } // Long form
  22805. // Count octets required to store length
  22806. var lenOctets = 1;
  22807. for (var i = content.length; i >= 0x100; i >>= 8) {
  22808. lenOctets++;
  22809. }
  22810. var header = Buffer.alloc(1 + 1 + lenOctets);
  22811. header[0] = encodedTag;
  22812. header[1] = 0x80 | lenOctets;
  22813. for (var _i = 1 + lenOctets, j = content.length; j > 0; _i--, j >>= 8) {
  22814. header[_i] = j & 0xff;
  22815. }
  22816. return this._createEncoderBuffer([header, content]);
  22817. };
  22818. DERNode.prototype._encodeStr = function encodeStr(str, tag) {
  22819. if (tag === 'bitstr') {
  22820. return this._createEncoderBuffer([str.unused | 0, str.data]);
  22821. } else if (tag === 'bmpstr') {
  22822. var buf = Buffer.alloc(str.length * 2);
  22823. for (var i = 0; i < str.length; i++) {
  22824. buf.writeUInt16BE(str.charCodeAt(i), i * 2);
  22825. }
  22826. return this._createEncoderBuffer(buf);
  22827. } else if (tag === 'numstr') {
  22828. if (!this._isNumstr(str)) {
  22829. return this.reporter.error('Encoding of string type: numstr supports ' + 'only digits and space');
  22830. }
  22831. return this._createEncoderBuffer(str);
  22832. } else if (tag === 'printstr') {
  22833. if (!this._isPrintstr(str)) {
  22834. return this.reporter.error('Encoding of string type: printstr supports ' + 'only latin upper and lower case letters, ' + 'digits, space, apostrophe, left and rigth ' + 'parenthesis, plus sign, comma, hyphen, ' + 'dot, slash, colon, equal sign, ' + 'question mark');
  22835. }
  22836. return this._createEncoderBuffer(str);
  22837. } else if (/str$/.test(tag)) {
  22838. return this._createEncoderBuffer(str);
  22839. } else if (tag === 'objDesc') {
  22840. return this._createEncoderBuffer(str);
  22841. } else {
  22842. return this.reporter.error('Encoding of string type: ' + tag + ' unsupported');
  22843. }
  22844. };
  22845. DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) {
  22846. if (typeof id === 'string') {
  22847. if (!values) return this.reporter.error('string objid given, but no values map found');
  22848. if (!values.hasOwnProperty(id)) return this.reporter.error('objid not found in values map');
  22849. id = values[id].split(/[\s.]+/g);
  22850. for (var i = 0; i < id.length; i++) {
  22851. id[i] |= 0;
  22852. }
  22853. } else if (Array.isArray(id)) {
  22854. id = id.slice();
  22855. for (var _i2 = 0; _i2 < id.length; _i2++) {
  22856. id[_i2] |= 0;
  22857. }
  22858. }
  22859. if (!Array.isArray(id)) {
  22860. return this.reporter.error('objid() should be either array or string, ' + 'got: ' + JSON.stringify(id));
  22861. }
  22862. if (!relative) {
  22863. if (id[1] >= 40) return this.reporter.error('Second objid identifier OOB');
  22864. id.splice(0, 2, id[0] * 40 + id[1]);
  22865. } // Count number of octets
  22866. var size = 0;
  22867. for (var _i3 = 0; _i3 < id.length; _i3++) {
  22868. var ident = id[_i3];
  22869. for (size++; ident >= 0x80; ident >>= 7) {
  22870. size++;
  22871. }
  22872. }
  22873. var objid = Buffer.alloc(size);
  22874. var offset = objid.length - 1;
  22875. for (var _i4 = id.length - 1; _i4 >= 0; _i4--) {
  22876. var _ident = id[_i4];
  22877. objid[offset--] = _ident & 0x7f;
  22878. while ((_ident >>= 7) > 0) {
  22879. objid[offset--] = 0x80 | _ident & 0x7f;
  22880. }
  22881. }
  22882. return this._createEncoderBuffer(objid);
  22883. };
  22884. function two(num) {
  22885. if (num < 10) return '0' + num;else return num;
  22886. }
  22887. DERNode.prototype._encodeTime = function encodeTime(time, tag) {
  22888. var str;
  22889. var date = new Date(time);
  22890. if (tag === 'gentime') {
  22891. str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  22892. } else if (tag === 'utctime') {
  22893. str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), 'Z'].join('');
  22894. } else {
  22895. this.reporter.error('Encoding ' + tag + ' time is not supported yet');
  22896. }
  22897. return this._encodeStr(str, 'octstr');
  22898. };
  22899. DERNode.prototype._encodeNull = function encodeNull() {
  22900. return this._createEncoderBuffer('');
  22901. };
  22902. DERNode.prototype._encodeInt = function encodeInt(num, values) {
  22903. if (typeof num === 'string') {
  22904. if (!values) return this.reporter.error('String int or enum given, but no values map');
  22905. if (!values.hasOwnProperty(num)) {
  22906. return this.reporter.error('Values map doesn\'t contain: ' + JSON.stringify(num));
  22907. }
  22908. num = values[num];
  22909. } // Bignum, assume big endian
  22910. if (typeof num !== 'number' && !Buffer.isBuffer(num)) {
  22911. var numArray = num.toArray();
  22912. if (!num.sign && numArray[0] & 0x80) {
  22913. numArray.unshift(0);
  22914. }
  22915. num = Buffer.from(numArray);
  22916. }
  22917. if (Buffer.isBuffer(num)) {
  22918. var _size = num.length;
  22919. if (num.length === 0) _size++;
  22920. var _out = Buffer.alloc(_size);
  22921. num.copy(_out);
  22922. if (num.length === 0) _out[0] = 0;
  22923. return this._createEncoderBuffer(_out);
  22924. }
  22925. if (num < 0x80) return this._createEncoderBuffer(num);
  22926. if (num < 0x100) return this._createEncoderBuffer([0, num]);
  22927. var size = 1;
  22928. for (var i = num; i >= 0x100; i >>= 8) {
  22929. size++;
  22930. }
  22931. var out = new Array(size);
  22932. for (var _i5 = out.length - 1; _i5 >= 0; _i5--) {
  22933. out[_i5] = num & 0xff;
  22934. num >>= 8;
  22935. }
  22936. if (out[0] & 0x80) {
  22937. out.unshift(0);
  22938. }
  22939. return this._createEncoderBuffer(Buffer.from(out));
  22940. };
  22941. DERNode.prototype._encodeBool = function encodeBool(value) {
  22942. return this._createEncoderBuffer(value ? 0xff : 0);
  22943. };
  22944. DERNode.prototype._use = function use(entity, obj) {
  22945. if (typeof entity === 'function') entity = entity(obj);
  22946. return entity._getEncoder('der').tree;
  22947. };
  22948. DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) {
  22949. var state = this._baseState;
  22950. var i;
  22951. if (state['default'] === null) return false;
  22952. var data = dataBuffer.join();
  22953. if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state['default'], reporter, parent).join();
  22954. if (data.length !== state.defaultBuffer.length) return false;
  22955. for (i = 0; i < data.length; i++) {
  22956. if (data[i] !== state.defaultBuffer[i]) return false;
  22957. }
  22958. return true;
  22959. }; // Utility methods
  22960. function encodeTag(tag, primitive, cls, reporter) {
  22961. var res;
  22962. if (tag === 'seqof') tag = 'seq';else if (tag === 'setof') tag = 'set';
  22963. if (der.tagByName.hasOwnProperty(tag)) res = der.tagByName[tag];else if (typeof tag === 'number' && (tag | 0) === tag) res = tag;else return reporter.error('Unknown tag: ' + tag);
  22964. if (res >= 0x1f) return reporter.error('Multi-octet tag encoding unsupported');
  22965. if (!primitive) res |= 0x20;
  22966. res |= der.tagClassByName[cls || 'universal'] << 6;
  22967. return res;
  22968. }
  22969. /***/ }),
  22970. /***/ 6860:
  22971. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  22972. "use strict";
  22973. var encoders = exports;
  22974. encoders.der = __webpack_require__(1889);
  22975. encoders.pem = __webpack_require__(1610);
  22976. /***/ }),
  22977. /***/ 1610:
  22978. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  22979. "use strict";
  22980. var inherits = __webpack_require__(376);
  22981. var DEREncoder = __webpack_require__(1889);
  22982. function PEMEncoder(entity) {
  22983. DEREncoder.call(this, entity);
  22984. this.enc = 'pem';
  22985. }
  22986. inherits(PEMEncoder, DEREncoder);
  22987. module.exports = PEMEncoder;
  22988. PEMEncoder.prototype.encode = function encode(data, options) {
  22989. var buf = DEREncoder.prototype.encode.call(this, data);
  22990. var p = buf.toString('base64');
  22991. var out = ['-----BEGIN ' + options.label + '-----'];
  22992. for (var i = 0; i < p.length; i += 64) {
  22993. out.push(p.slice(i, i + 64));
  22994. }
  22995. out.push('-----END ' + options.label + '-----');
  22996. return out.join('\n');
  22997. };
  22998. /***/ }),
  22999. /***/ 9373:
  23000. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  23001. "use strict";
  23002. // Currently in sync with Node.js lib/assert.js
  23003. // https://github.com/nodejs/node/commit/2a51ae424a513ec9a6aa3466baa0cc1d55dd4f3b
  23004. // Originally from narwhal.js (http://narwhaljs.org)
  23005. // Copyright (c) 2009 Thomas Robinson <280north.com>
  23006. //
  23007. // Permission is hereby granted, free of charge, to any person obtaining a copy
  23008. // of this software and associated documentation files (the 'Software'), to
  23009. // deal in the Software without restriction, including without limitation the
  23010. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  23011. // sell copies of the Software, and to permit persons to whom the Software is
  23012. // furnished to do so, subject to the following conditions:
  23013. //
  23014. // The above copyright notice and this permission notice shall be included in
  23015. // all copies or substantial portions of the Software.
  23016. //
  23017. // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23018. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23019. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23020. // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  23021. // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23022. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23023. function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
  23024. function _typeof(obj) {
  23025. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  23026. _typeof = function _typeof(obj) {
  23027. return _typeof2(obj);
  23028. };
  23029. } else {
  23030. _typeof = function _typeof(obj) {
  23031. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  23032. };
  23033. }
  23034. return _typeof(obj);
  23035. }
  23036. function _classCallCheck(instance, Constructor) {
  23037. if (!(instance instanceof Constructor)) {
  23038. throw new TypeError("Cannot call a class as a function");
  23039. }
  23040. }
  23041. var _require = __webpack_require__(9978),
  23042. _require$codes = _require.codes,
  23043. ERR_AMBIGUOUS_ARGUMENT = _require$codes.ERR_AMBIGUOUS_ARGUMENT,
  23044. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  23045. ERR_INVALID_ARG_VALUE = _require$codes.ERR_INVALID_ARG_VALUE,
  23046. ERR_INVALID_RETURN_VALUE = _require$codes.ERR_INVALID_RETURN_VALUE,
  23047. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS;
  23048. var AssertionError = __webpack_require__(1935);
  23049. var _require2 = __webpack_require__(161),
  23050. inspect = _require2.inspect;
  23051. var _require$types = (__webpack_require__(161).types),
  23052. isPromise = _require$types.isPromise,
  23053. isRegExp = _require$types.isRegExp;
  23054. var objectAssign = Object.assign ? Object.assign : (__webpack_require__(8028).assign);
  23055. var objectIs = Object.is ? Object.is : __webpack_require__(4710);
  23056. var errorCache = new Map();
  23057. var isDeepEqual;
  23058. var isDeepStrictEqual;
  23059. var parseExpressionAt;
  23060. var findNodeAround;
  23061. var decoder;
  23062. function lazyLoadComparison() {
  23063. var comparison = __webpack_require__(9015);
  23064. isDeepEqual = comparison.isDeepEqual;
  23065. isDeepStrictEqual = comparison.isDeepStrictEqual;
  23066. } // Escape control characters but not \n and \t to keep the line breaks and
  23067. // indentation intact.
  23068. // eslint-disable-next-line no-control-regex
  23069. var escapeSequencesRegExp = /[\x00-\x08\x0b\x0c\x0e-\x1f]/g;
  23070. var meta = (/* unused pure expression or super */ null && (["\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005", "\\u0006", "\\u0007", '\\b', '', '', "\\u000b", '\\f', '', "\\u000e", "\\u000f", "\\u0010", "\\u0011", "\\u0012", "\\u0013", "\\u0014", "\\u0015", "\\u0016", "\\u0017", "\\u0018", "\\u0019", "\\u001a", "\\u001b", "\\u001c", "\\u001d", "\\u001e", "\\u001f"]));
  23071. var escapeFn = function escapeFn(str) {
  23072. return meta[str.charCodeAt(0)];
  23073. };
  23074. var warned = false; // The assert module provides functions that throw
  23075. // AssertionError's when particular conditions are not met. The
  23076. // assert module must conform to the following interface.
  23077. var assert = module.exports = ok;
  23078. var NO_EXCEPTION_SENTINEL = {}; // All of the following functions must throw an AssertionError
  23079. // when a corresponding condition is not met, with a message that
  23080. // may be undefined if not provided. All assertion methods provide
  23081. // both the actual and expected values to the assertion error for
  23082. // display purposes.
  23083. function innerFail(obj) {
  23084. if (obj.message instanceof Error) throw obj.message;
  23085. throw new AssertionError(obj);
  23086. }
  23087. function fail(actual, expected, message, operator, stackStartFn) {
  23088. var argsLen = arguments.length;
  23089. var internalMessage;
  23090. if (argsLen === 0) {
  23091. internalMessage = 'Failed';
  23092. } else if (argsLen === 1) {
  23093. message = actual;
  23094. actual = undefined;
  23095. } else {
  23096. if (warned === false) {
  23097. warned = true;
  23098. var warn = ({env:{}}).emitWarning ? ({env:{}}).emitWarning : console.warn.bind(console);
  23099. warn('assert.fail() with more than one argument is deprecated. ' + 'Please use assert.strictEqual() instead or only pass a message.', 'DeprecationWarning', 'DEP0094');
  23100. }
  23101. if (argsLen === 2) operator = '!=';
  23102. }
  23103. if (message instanceof Error) throw message;
  23104. var errArgs = {
  23105. actual: actual,
  23106. expected: expected,
  23107. operator: operator === undefined ? 'fail' : operator,
  23108. stackStartFn: stackStartFn || fail
  23109. };
  23110. if (message !== undefined) {
  23111. errArgs.message = message;
  23112. }
  23113. var err = new AssertionError(errArgs);
  23114. if (internalMessage) {
  23115. err.message = internalMessage;
  23116. err.generatedMessage = true;
  23117. }
  23118. throw err;
  23119. }
  23120. assert.fail = fail; // The AssertionError is defined in internal/error.
  23121. assert.AssertionError = AssertionError;
  23122. function innerOk(fn, argLen, value, message) {
  23123. if (!value) {
  23124. var generatedMessage = false;
  23125. if (argLen === 0) {
  23126. generatedMessage = true;
  23127. message = 'No value argument passed to `assert.ok()`';
  23128. } else if (message instanceof Error) {
  23129. throw message;
  23130. }
  23131. var err = new AssertionError({
  23132. actual: value,
  23133. expected: true,
  23134. message: message,
  23135. operator: '==',
  23136. stackStartFn: fn
  23137. });
  23138. err.generatedMessage = generatedMessage;
  23139. throw err;
  23140. }
  23141. } // Pure assertion tests whether a value is truthy, as determined
  23142. // by !!value.
  23143. function ok() {
  23144. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  23145. args[_key] = arguments[_key];
  23146. }
  23147. innerOk.apply(void 0, [ok, args.length].concat(args));
  23148. }
  23149. assert.ok = ok; // The equality assertion tests shallow, coercive equality with ==.
  23150. /* eslint-disable no-restricted-properties */
  23151. assert.equal = function equal(actual, expected, message) {
  23152. if (arguments.length < 2) {
  23153. throw new ERR_MISSING_ARGS('actual', 'expected');
  23154. } // eslint-disable-next-line eqeqeq
  23155. if (actual != expected) {
  23156. innerFail({
  23157. actual: actual,
  23158. expected: expected,
  23159. message: message,
  23160. operator: '==',
  23161. stackStartFn: equal
  23162. });
  23163. }
  23164. }; // The non-equality assertion tests for whether two objects are not
  23165. // equal with !=.
  23166. assert.notEqual = function notEqual(actual, expected, message) {
  23167. if (arguments.length < 2) {
  23168. throw new ERR_MISSING_ARGS('actual', 'expected');
  23169. } // eslint-disable-next-line eqeqeq
  23170. if (actual == expected) {
  23171. innerFail({
  23172. actual: actual,
  23173. expected: expected,
  23174. message: message,
  23175. operator: '!=',
  23176. stackStartFn: notEqual
  23177. });
  23178. }
  23179. }; // The equivalence assertion tests a deep equality relation.
  23180. assert.deepEqual = function deepEqual(actual, expected, message) {
  23181. if (arguments.length < 2) {
  23182. throw new ERR_MISSING_ARGS('actual', 'expected');
  23183. }
  23184. if (isDeepEqual === undefined) lazyLoadComparison();
  23185. if (!isDeepEqual(actual, expected)) {
  23186. innerFail({
  23187. actual: actual,
  23188. expected: expected,
  23189. message: message,
  23190. operator: 'deepEqual',
  23191. stackStartFn: deepEqual
  23192. });
  23193. }
  23194. }; // The non-equivalence assertion tests for any deep inequality.
  23195. assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
  23196. if (arguments.length < 2) {
  23197. throw new ERR_MISSING_ARGS('actual', 'expected');
  23198. }
  23199. if (isDeepEqual === undefined) lazyLoadComparison();
  23200. if (isDeepEqual(actual, expected)) {
  23201. innerFail({
  23202. actual: actual,
  23203. expected: expected,
  23204. message: message,
  23205. operator: 'notDeepEqual',
  23206. stackStartFn: notDeepEqual
  23207. });
  23208. }
  23209. };
  23210. /* eslint-enable */
  23211. assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
  23212. if (arguments.length < 2) {
  23213. throw new ERR_MISSING_ARGS('actual', 'expected');
  23214. }
  23215. if (isDeepEqual === undefined) lazyLoadComparison();
  23216. if (!isDeepStrictEqual(actual, expected)) {
  23217. innerFail({
  23218. actual: actual,
  23219. expected: expected,
  23220. message: message,
  23221. operator: 'deepStrictEqual',
  23222. stackStartFn: deepStrictEqual
  23223. });
  23224. }
  23225. };
  23226. assert.notDeepStrictEqual = notDeepStrictEqual;
  23227. function notDeepStrictEqual(actual, expected, message) {
  23228. if (arguments.length < 2) {
  23229. throw new ERR_MISSING_ARGS('actual', 'expected');
  23230. }
  23231. if (isDeepEqual === undefined) lazyLoadComparison();
  23232. if (isDeepStrictEqual(actual, expected)) {
  23233. innerFail({
  23234. actual: actual,
  23235. expected: expected,
  23236. message: message,
  23237. operator: 'notDeepStrictEqual',
  23238. stackStartFn: notDeepStrictEqual
  23239. });
  23240. }
  23241. }
  23242. assert.strictEqual = function strictEqual(actual, expected, message) {
  23243. if (arguments.length < 2) {
  23244. throw new ERR_MISSING_ARGS('actual', 'expected');
  23245. }
  23246. if (!objectIs(actual, expected)) {
  23247. innerFail({
  23248. actual: actual,
  23249. expected: expected,
  23250. message: message,
  23251. operator: 'strictEqual',
  23252. stackStartFn: strictEqual
  23253. });
  23254. }
  23255. };
  23256. assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
  23257. if (arguments.length < 2) {
  23258. throw new ERR_MISSING_ARGS('actual', 'expected');
  23259. }
  23260. if (objectIs(actual, expected)) {
  23261. innerFail({
  23262. actual: actual,
  23263. expected: expected,
  23264. message: message,
  23265. operator: 'notStrictEqual',
  23266. stackStartFn: notStrictEqual
  23267. });
  23268. }
  23269. };
  23270. var Comparison = function Comparison(obj, keys, actual) {
  23271. var _this = this;
  23272. _classCallCheck(this, Comparison);
  23273. keys.forEach(function (key) {
  23274. if (key in obj) {
  23275. if (actual !== undefined && typeof actual[key] === 'string' && isRegExp(obj[key]) && obj[key].test(actual[key])) {
  23276. _this[key] = actual[key];
  23277. } else {
  23278. _this[key] = obj[key];
  23279. }
  23280. }
  23281. });
  23282. };
  23283. function compareExceptionKey(actual, expected, key, message, keys, fn) {
  23284. if (!(key in actual) || !isDeepStrictEqual(actual[key], expected[key])) {
  23285. if (!message) {
  23286. // Create placeholder objects to create a nice output.
  23287. var a = new Comparison(actual, keys);
  23288. var b = new Comparison(expected, keys, actual);
  23289. var err = new AssertionError({
  23290. actual: a,
  23291. expected: b,
  23292. operator: 'deepStrictEqual',
  23293. stackStartFn: fn
  23294. });
  23295. err.actual = actual;
  23296. err.expected = expected;
  23297. err.operator = fn.name;
  23298. throw err;
  23299. }
  23300. innerFail({
  23301. actual: actual,
  23302. expected: expected,
  23303. message: message,
  23304. operator: fn.name,
  23305. stackStartFn: fn
  23306. });
  23307. }
  23308. }
  23309. function expectedException(actual, expected, msg, fn) {
  23310. if (typeof expected !== 'function') {
  23311. if (isRegExp(expected)) return expected.test(actual); // assert.doesNotThrow does not accept objects.
  23312. if (arguments.length === 2) {
  23313. throw new ERR_INVALID_ARG_TYPE('expected', ['Function', 'RegExp'], expected);
  23314. } // Handle primitives properly.
  23315. if (_typeof(actual) !== 'object' || actual === null) {
  23316. var err = new AssertionError({
  23317. actual: actual,
  23318. expected: expected,
  23319. message: msg,
  23320. operator: 'deepStrictEqual',
  23321. stackStartFn: fn
  23322. });
  23323. err.operator = fn.name;
  23324. throw err;
  23325. }
  23326. var keys = Object.keys(expected); // Special handle errors to make sure the name and the message are compared
  23327. // as well.
  23328. if (expected instanceof Error) {
  23329. keys.push('name', 'message');
  23330. } else if (keys.length === 0) {
  23331. throw new ERR_INVALID_ARG_VALUE('error', expected, 'may not be an empty object');
  23332. }
  23333. if (isDeepEqual === undefined) lazyLoadComparison();
  23334. keys.forEach(function (key) {
  23335. if (typeof actual[key] === 'string' && isRegExp(expected[key]) && expected[key].test(actual[key])) {
  23336. return;
  23337. }
  23338. compareExceptionKey(actual, expected, key, msg, keys, fn);
  23339. });
  23340. return true;
  23341. } // Guard instanceof against arrow functions as they don't have a prototype.
  23342. if (expected.prototype !== undefined && actual instanceof expected) {
  23343. return true;
  23344. }
  23345. if (Error.isPrototypeOf(expected)) {
  23346. return false;
  23347. }
  23348. return expected.call({}, actual) === true;
  23349. }
  23350. function getActual(fn) {
  23351. if (typeof fn !== 'function') {
  23352. throw new ERR_INVALID_ARG_TYPE('fn', 'Function', fn);
  23353. }
  23354. try {
  23355. fn();
  23356. } catch (e) {
  23357. return e;
  23358. }
  23359. return NO_EXCEPTION_SENTINEL;
  23360. }
  23361. function checkIsPromise(obj) {
  23362. // Accept native ES6 promises and promises that are implemented in a similar
  23363. // way. Do not accept thenables that use a function as `obj` and that have no
  23364. // `catch` handler.
  23365. // TODO: thenables are checked up until they have the correct methods,
  23366. // but according to documentation, the `then` method should receive
  23367. // the `fulfill` and `reject` arguments as well or it may be never resolved.
  23368. return isPromise(obj) || obj !== null && _typeof(obj) === 'object' && typeof obj.then === 'function' && typeof obj["catch"] === 'function';
  23369. }
  23370. function waitForActual(promiseFn) {
  23371. return Promise.resolve().then(function () {
  23372. var resultPromise;
  23373. if (typeof promiseFn === 'function') {
  23374. // Return a rejected promise if `promiseFn` throws synchronously.
  23375. resultPromise = promiseFn(); // Fail in case no promise is returned.
  23376. if (!checkIsPromise(resultPromise)) {
  23377. throw new ERR_INVALID_RETURN_VALUE('instance of Promise', 'promiseFn', resultPromise);
  23378. }
  23379. } else if (checkIsPromise(promiseFn)) {
  23380. resultPromise = promiseFn;
  23381. } else {
  23382. throw new ERR_INVALID_ARG_TYPE('promiseFn', ['Function', 'Promise'], promiseFn);
  23383. }
  23384. return Promise.resolve().then(function () {
  23385. return resultPromise;
  23386. }).then(function () {
  23387. return NO_EXCEPTION_SENTINEL;
  23388. })["catch"](function (e) {
  23389. return e;
  23390. });
  23391. });
  23392. }
  23393. function expectsError(stackStartFn, actual, error, message) {
  23394. if (typeof error === 'string') {
  23395. if (arguments.length === 4) {
  23396. throw new ERR_INVALID_ARG_TYPE('error', ['Object', 'Error', 'Function', 'RegExp'], error);
  23397. }
  23398. if (_typeof(actual) === 'object' && actual !== null) {
  23399. if (actual.message === error) {
  23400. throw new ERR_AMBIGUOUS_ARGUMENT('error/message', "The error message \"".concat(actual.message, "\" is identical to the message."));
  23401. }
  23402. } else if (actual === error) {
  23403. throw new ERR_AMBIGUOUS_ARGUMENT('error/message', "The error \"".concat(actual, "\" is identical to the message."));
  23404. }
  23405. message = error;
  23406. error = undefined;
  23407. } else if (error != null && _typeof(error) !== 'object' && typeof error !== 'function') {
  23408. throw new ERR_INVALID_ARG_TYPE('error', ['Object', 'Error', 'Function', 'RegExp'], error);
  23409. }
  23410. if (actual === NO_EXCEPTION_SENTINEL) {
  23411. var details = '';
  23412. if (error && error.name) {
  23413. details += " (".concat(error.name, ")");
  23414. }
  23415. details += message ? ": ".concat(message) : '.';
  23416. var fnType = stackStartFn.name === 'rejects' ? 'rejection' : 'exception';
  23417. innerFail({
  23418. actual: undefined,
  23419. expected: error,
  23420. operator: stackStartFn.name,
  23421. message: "Missing expected ".concat(fnType).concat(details),
  23422. stackStartFn: stackStartFn
  23423. });
  23424. }
  23425. if (error && !expectedException(actual, error, message, stackStartFn)) {
  23426. throw actual;
  23427. }
  23428. }
  23429. function expectsNoError(stackStartFn, actual, error, message) {
  23430. if (actual === NO_EXCEPTION_SENTINEL) return;
  23431. if (typeof error === 'string') {
  23432. message = error;
  23433. error = undefined;
  23434. }
  23435. if (!error || expectedException(actual, error)) {
  23436. var details = message ? ": ".concat(message) : '.';
  23437. var fnType = stackStartFn.name === 'doesNotReject' ? 'rejection' : 'exception';
  23438. innerFail({
  23439. actual: actual,
  23440. expected: error,
  23441. operator: stackStartFn.name,
  23442. message: "Got unwanted ".concat(fnType).concat(details, "\n") + "Actual message: \"".concat(actual && actual.message, "\""),
  23443. stackStartFn: stackStartFn
  23444. });
  23445. }
  23446. throw actual;
  23447. }
  23448. assert["throws"] = function _throws(promiseFn) {
  23449. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  23450. args[_key2 - 1] = arguments[_key2];
  23451. }
  23452. expectsError.apply(void 0, [_throws, getActual(promiseFn)].concat(args));
  23453. };
  23454. assert.rejects = function rejects(promiseFn) {
  23455. for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
  23456. args[_key3 - 1] = arguments[_key3];
  23457. }
  23458. return waitForActual(promiseFn).then(function (result) {
  23459. return expectsError.apply(void 0, [rejects, result].concat(args));
  23460. });
  23461. };
  23462. assert.doesNotThrow = function doesNotThrow(fn) {
  23463. for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
  23464. args[_key4 - 1] = arguments[_key4];
  23465. }
  23466. expectsNoError.apply(void 0, [doesNotThrow, getActual(fn)].concat(args));
  23467. };
  23468. assert.doesNotReject = function doesNotReject(fn) {
  23469. for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
  23470. args[_key5 - 1] = arguments[_key5];
  23471. }
  23472. return waitForActual(fn).then(function (result) {
  23473. return expectsNoError.apply(void 0, [doesNotReject, result].concat(args));
  23474. });
  23475. };
  23476. assert.ifError = function ifError(err) {
  23477. if (err !== null && err !== undefined) {
  23478. var message = 'ifError got unwanted exception: ';
  23479. if (_typeof(err) === 'object' && typeof err.message === 'string') {
  23480. if (err.message.length === 0 && err.constructor) {
  23481. message += err.constructor.name;
  23482. } else {
  23483. message += err.message;
  23484. }
  23485. } else {
  23486. message += inspect(err);
  23487. }
  23488. var newErr = new AssertionError({
  23489. actual: err,
  23490. expected: null,
  23491. operator: 'ifError',
  23492. message: message,
  23493. stackStartFn: ifError
  23494. }); // Make sure we actually have a stack trace!
  23495. var origStack = err.stack;
  23496. if (typeof origStack === 'string') {
  23497. // This will remove any duplicated frames from the error frames taken
  23498. // from within `ifError` and add the original error frames to the newly
  23499. // created ones.
  23500. var tmp2 = origStack.split('\n');
  23501. tmp2.shift(); // Filter all frames existing in err.stack.
  23502. var tmp1 = newErr.stack.split('\n');
  23503. for (var i = 0; i < tmp2.length; i++) {
  23504. // Find the first occurrence of the frame.
  23505. var pos = tmp1.indexOf(tmp2[i]);
  23506. if (pos !== -1) {
  23507. // Only keep new frames.
  23508. tmp1 = tmp1.slice(0, pos);
  23509. break;
  23510. }
  23511. }
  23512. newErr.stack = "".concat(tmp1.join('\n'), "\n").concat(tmp2.join('\n'));
  23513. }
  23514. throw newErr;
  23515. }
  23516. }; // Expose a strict only variant of assert
  23517. function strict() {
  23518. for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  23519. args[_key6] = arguments[_key6];
  23520. }
  23521. innerOk.apply(void 0, [strict, args.length].concat(args));
  23522. }
  23523. assert.strict = objectAssign(strict, assert, {
  23524. equal: assert.strictEqual,
  23525. deepEqual: assert.deepStrictEqual,
  23526. notEqual: assert.notStrictEqual,
  23527. notDeepEqual: assert.notDeepStrictEqual
  23528. });
  23529. assert.strict.strict = assert.strict;
  23530. /***/ }),
  23531. /***/ 1935:
  23532. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  23533. "use strict";
  23534. // Currently in sync with Node.js lib/internal/assert/assertion_error.js
  23535. // https://github.com/nodejs/node/commit/0817840f775032169ddd70c85ac059f18ffcc81c
  23536. function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
  23537. function _objectSpread(target) {
  23538. for (var i = 1; i < arguments.length; i++) {
  23539. var source = arguments[i] != null ? arguments[i] : {};
  23540. var ownKeys = Object.keys(source);
  23541. if (typeof Object.getOwnPropertySymbols === 'function') {
  23542. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  23543. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  23544. }));
  23545. }
  23546. ownKeys.forEach(function (key) {
  23547. _defineProperty(target, key, source[key]);
  23548. });
  23549. }
  23550. return target;
  23551. }
  23552. function _defineProperty(obj, key, value) {
  23553. if (key in obj) {
  23554. Object.defineProperty(obj, key, {
  23555. value: value,
  23556. enumerable: true,
  23557. configurable: true,
  23558. writable: true
  23559. });
  23560. } else {
  23561. obj[key] = value;
  23562. }
  23563. return obj;
  23564. }
  23565. function _classCallCheck(instance, Constructor) {
  23566. if (!(instance instanceof Constructor)) {
  23567. throw new TypeError("Cannot call a class as a function");
  23568. }
  23569. }
  23570. function _defineProperties(target, props) {
  23571. for (var i = 0; i < props.length; i++) {
  23572. var descriptor = props[i];
  23573. descriptor.enumerable = descriptor.enumerable || false;
  23574. descriptor.configurable = true;
  23575. if ("value" in descriptor) descriptor.writable = true;
  23576. Object.defineProperty(target, descriptor.key, descriptor);
  23577. }
  23578. }
  23579. function _createClass(Constructor, protoProps, staticProps) {
  23580. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  23581. if (staticProps) _defineProperties(Constructor, staticProps);
  23582. return Constructor;
  23583. }
  23584. function _possibleConstructorReturn(self, call) {
  23585. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  23586. return call;
  23587. }
  23588. return _assertThisInitialized(self);
  23589. }
  23590. function _assertThisInitialized(self) {
  23591. if (self === void 0) {
  23592. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  23593. }
  23594. return self;
  23595. }
  23596. function _inherits(subClass, superClass) {
  23597. if (typeof superClass !== "function" && superClass !== null) {
  23598. throw new TypeError("Super expression must either be null or a function");
  23599. }
  23600. subClass.prototype = Object.create(superClass && superClass.prototype, {
  23601. constructor: {
  23602. value: subClass,
  23603. writable: true,
  23604. configurable: true
  23605. }
  23606. });
  23607. if (superClass) _setPrototypeOf(subClass, superClass);
  23608. }
  23609. function _wrapNativeSuper(Class) {
  23610. var _cache = typeof Map === "function" ? new Map() : undefined;
  23611. _wrapNativeSuper = function _wrapNativeSuper(Class) {
  23612. if (Class === null || !_isNativeFunction(Class)) return Class;
  23613. if (typeof Class !== "function") {
  23614. throw new TypeError("Super expression must either be null or a function");
  23615. }
  23616. if (typeof _cache !== "undefined") {
  23617. if (_cache.has(Class)) return _cache.get(Class);
  23618. _cache.set(Class, Wrapper);
  23619. }
  23620. function Wrapper() {
  23621. return _construct(Class, arguments, _getPrototypeOf(this).constructor);
  23622. }
  23623. Wrapper.prototype = Object.create(Class.prototype, {
  23624. constructor: {
  23625. value: Wrapper,
  23626. enumerable: false,
  23627. writable: true,
  23628. configurable: true
  23629. }
  23630. });
  23631. return _setPrototypeOf(Wrapper, Class);
  23632. };
  23633. return _wrapNativeSuper(Class);
  23634. }
  23635. function isNativeReflectConstruct() {
  23636. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  23637. if (Reflect.construct.sham) return false;
  23638. if (typeof Proxy === "function") return true;
  23639. try {
  23640. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  23641. return true;
  23642. } catch (e) {
  23643. return false;
  23644. }
  23645. }
  23646. function _construct(Parent, args, Class) {
  23647. if (isNativeReflectConstruct()) {
  23648. _construct = Reflect.construct;
  23649. } else {
  23650. _construct = function _construct(Parent, args, Class) {
  23651. var a = [null];
  23652. a.push.apply(a, args);
  23653. var Constructor = Function.bind.apply(Parent, a);
  23654. var instance = new Constructor();
  23655. if (Class) _setPrototypeOf(instance, Class.prototype);
  23656. return instance;
  23657. };
  23658. }
  23659. return _construct.apply(null, arguments);
  23660. }
  23661. function _isNativeFunction(fn) {
  23662. return Function.toString.call(fn).indexOf("[native code]") !== -1;
  23663. }
  23664. function _setPrototypeOf(o, p) {
  23665. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  23666. o.__proto__ = p;
  23667. return o;
  23668. };
  23669. return _setPrototypeOf(o, p);
  23670. }
  23671. function _getPrototypeOf(o) {
  23672. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  23673. return o.__proto__ || Object.getPrototypeOf(o);
  23674. };
  23675. return _getPrototypeOf(o);
  23676. }
  23677. function _typeof(obj) {
  23678. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  23679. _typeof = function _typeof(obj) {
  23680. return _typeof2(obj);
  23681. };
  23682. } else {
  23683. _typeof = function _typeof(obj) {
  23684. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  23685. };
  23686. }
  23687. return _typeof(obj);
  23688. }
  23689. var _require = __webpack_require__(161),
  23690. inspect = _require.inspect;
  23691. var _require2 = __webpack_require__(9978),
  23692. ERR_INVALID_ARG_TYPE = _require2.codes.ERR_INVALID_ARG_TYPE; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  23693. function endsWith(str, search, this_len) {
  23694. if (this_len === undefined || this_len > str.length) {
  23695. this_len = str.length;
  23696. }
  23697. return str.substring(this_len - search.length, this_len) === search;
  23698. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat
  23699. function repeat(str, count) {
  23700. count = Math.floor(count);
  23701. if (str.length == 0 || count == 0) return '';
  23702. var maxCount = str.length * count;
  23703. count = Math.floor(Math.log(count) / Math.log(2));
  23704. while (count) {
  23705. str += str;
  23706. count--;
  23707. }
  23708. str += str.substring(0, maxCount - str.length);
  23709. return str;
  23710. }
  23711. var blue = '';
  23712. var green = '';
  23713. var red = '';
  23714. var white = '';
  23715. var kReadableOperator = {
  23716. deepStrictEqual: 'Expected values to be strictly deep-equal:',
  23717. strictEqual: 'Expected values to be strictly equal:',
  23718. strictEqualObject: 'Expected "actual" to be reference-equal to "expected":',
  23719. deepEqual: 'Expected values to be loosely deep-equal:',
  23720. equal: 'Expected values to be loosely equal:',
  23721. notDeepStrictEqual: 'Expected "actual" not to be strictly deep-equal to:',
  23722. notStrictEqual: 'Expected "actual" to be strictly unequal to:',
  23723. notStrictEqualObject: 'Expected "actual" not to be reference-equal to "expected":',
  23724. notDeepEqual: 'Expected "actual" not to be loosely deep-equal to:',
  23725. notEqual: 'Expected "actual" to be loosely unequal to:',
  23726. notIdentical: 'Values identical but not reference-equal:'
  23727. }; // Comparing short primitives should just show === / !== instead of using the
  23728. // diff.
  23729. var kMaxShortLength = 10;
  23730. function copyError(source) {
  23731. var keys = Object.keys(source);
  23732. var target = Object.create(Object.getPrototypeOf(source));
  23733. keys.forEach(function (key) {
  23734. target[key] = source[key];
  23735. });
  23736. Object.defineProperty(target, 'message', {
  23737. value: source.message
  23738. });
  23739. return target;
  23740. }
  23741. function inspectValue(val) {
  23742. // The util.inspect default values could be changed. This makes sure the
  23743. // error messages contain the necessary information nevertheless.
  23744. return inspect(val, {
  23745. compact: false,
  23746. customInspect: false,
  23747. depth: 1000,
  23748. maxArrayLength: Infinity,
  23749. // Assert compares only enumerable properties (with a few exceptions).
  23750. showHidden: false,
  23751. // Having a long line as error is better than wrapping the line for
  23752. // comparison for now.
  23753. // TODO(BridgeAR): `breakLength` should be limited as soon as soon as we
  23754. // have meta information about the inspected properties (i.e., know where
  23755. // in what line the property starts and ends).
  23756. breakLength: Infinity,
  23757. // Assert does not detect proxies currently.
  23758. showProxy: false,
  23759. sorted: true,
  23760. // Inspect getters as we also check them when comparing entries.
  23761. getters: true
  23762. });
  23763. }
  23764. function createErrDiff(actual, expected, operator) {
  23765. var other = '';
  23766. var res = '';
  23767. var lastPos = 0;
  23768. var end = '';
  23769. var skipped = false;
  23770. var actualInspected = inspectValue(actual);
  23771. var actualLines = actualInspected.split('\n');
  23772. var expectedLines = inspectValue(expected).split('\n');
  23773. var i = 0;
  23774. var indicator = ''; // In case both values are objects explicitly mark them as not reference equal
  23775. // for the `strictEqual` operator.
  23776. if (operator === 'strictEqual' && _typeof(actual) === 'object' && _typeof(expected) === 'object' && actual !== null && expected !== null) {
  23777. operator = 'strictEqualObject';
  23778. } // If "actual" and "expected" fit on a single line and they are not strictly
  23779. // equal, check further special handling.
  23780. if (actualLines.length === 1 && expectedLines.length === 1 && actualLines[0] !== expectedLines[0]) {
  23781. var inputLength = actualLines[0].length + expectedLines[0].length; // If the character length of "actual" and "expected" together is less than
  23782. // kMaxShortLength and if neither is an object and at least one of them is
  23783. // not `zero`, use the strict equal comparison to visualize the output.
  23784. if (inputLength <= kMaxShortLength) {
  23785. if ((_typeof(actual) !== 'object' || actual === null) && (_typeof(expected) !== 'object' || expected === null) && (actual !== 0 || expected !== 0)) {
  23786. // -0 === +0
  23787. return "".concat(kReadableOperator[operator], "\n\n") + "".concat(actualLines[0], " !== ").concat(expectedLines[0], "\n");
  23788. }
  23789. } else if (operator !== 'strictEqualObject') {
  23790. // If the stderr is a tty and the input length is lower than the current
  23791. // columns per line, add a mismatch indicator below the output. If it is
  23792. // not a tty, use a default value of 80 characters.
  23793. var maxLength = ({env:{}}).stderr && ({env:{}}).stderr.isTTY ? ({env:{}}).stderr.columns : 80;
  23794. if (inputLength < maxLength) {
  23795. while (actualLines[0][i] === expectedLines[0][i]) {
  23796. i++;
  23797. } // Ignore the first characters.
  23798. if (i > 2) {
  23799. // Add position indicator for the first mismatch in case it is a
  23800. // single line and the input length is less than the column length.
  23801. indicator = "\n ".concat(repeat(' ', i), "^");
  23802. i = 0;
  23803. }
  23804. }
  23805. }
  23806. } // Remove all ending lines that match (this optimizes the output for
  23807. // readability by reducing the number of total changed lines).
  23808. var a = actualLines[actualLines.length - 1];
  23809. var b = expectedLines[expectedLines.length - 1];
  23810. while (a === b) {
  23811. if (i++ < 2) {
  23812. end = "\n ".concat(a).concat(end);
  23813. } else {
  23814. other = a;
  23815. }
  23816. actualLines.pop();
  23817. expectedLines.pop();
  23818. if (actualLines.length === 0 || expectedLines.length === 0) break;
  23819. a = actualLines[actualLines.length - 1];
  23820. b = expectedLines[expectedLines.length - 1];
  23821. }
  23822. var maxLines = Math.max(actualLines.length, expectedLines.length); // Strict equal with identical objects that are not identical by reference.
  23823. // E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() })
  23824. if (maxLines === 0) {
  23825. // We have to get the result again. The lines were all removed before.
  23826. var _actualLines = actualInspected.split('\n'); // Only remove lines in case it makes sense to collapse those.
  23827. // TODO: Accept env to always show the full error.
  23828. if (_actualLines.length > 30) {
  23829. _actualLines[26] = "".concat(blue, "...").concat(white);
  23830. while (_actualLines.length > 27) {
  23831. _actualLines.pop();
  23832. }
  23833. }
  23834. return "".concat(kReadableOperator.notIdentical, "\n\n").concat(_actualLines.join('\n'), "\n");
  23835. }
  23836. if (i > 3) {
  23837. end = "\n".concat(blue, "...").concat(white).concat(end);
  23838. skipped = true;
  23839. }
  23840. if (other !== '') {
  23841. end = "\n ".concat(other).concat(end);
  23842. other = '';
  23843. }
  23844. var printedLines = 0;
  23845. var msg = kReadableOperator[operator] + "\n".concat(green, "+ actual").concat(white, " ").concat(red, "- expected").concat(white);
  23846. var skippedMsg = " ".concat(blue, "...").concat(white, " Lines skipped");
  23847. for (i = 0; i < maxLines; i++) {
  23848. // Only extra expected lines exist
  23849. var cur = i - lastPos;
  23850. if (actualLines.length < i + 1) {
  23851. // If the last diverging line is more than one line above and the
  23852. // current line is at least line three, add some of the former lines and
  23853. // also add dots to indicate skipped entries.
  23854. if (cur > 1 && i > 2) {
  23855. if (cur > 4) {
  23856. res += "\n".concat(blue, "...").concat(white);
  23857. skipped = true;
  23858. } else if (cur > 3) {
  23859. res += "\n ".concat(expectedLines[i - 2]);
  23860. printedLines++;
  23861. }
  23862. res += "\n ".concat(expectedLines[i - 1]);
  23863. printedLines++;
  23864. } // Mark the current line as the last diverging one.
  23865. lastPos = i; // Add the expected line to the cache.
  23866. other += "\n".concat(red, "-").concat(white, " ").concat(expectedLines[i]);
  23867. printedLines++; // Only extra actual lines exist
  23868. } else if (expectedLines.length < i + 1) {
  23869. // If the last diverging line is more than one line above and the
  23870. // current line is at least line three, add some of the former lines and
  23871. // also add dots to indicate skipped entries.
  23872. if (cur > 1 && i > 2) {
  23873. if (cur > 4) {
  23874. res += "\n".concat(blue, "...").concat(white);
  23875. skipped = true;
  23876. } else if (cur > 3) {
  23877. res += "\n ".concat(actualLines[i - 2]);
  23878. printedLines++;
  23879. }
  23880. res += "\n ".concat(actualLines[i - 1]);
  23881. printedLines++;
  23882. } // Mark the current line as the last diverging one.
  23883. lastPos = i; // Add the actual line to the result.
  23884. res += "\n".concat(green, "+").concat(white, " ").concat(actualLines[i]);
  23885. printedLines++; // Lines diverge
  23886. } else {
  23887. var expectedLine = expectedLines[i];
  23888. var actualLine = actualLines[i]; // If the lines diverge, specifically check for lines that only diverge by
  23889. // a trailing comma. In that case it is actually identical and we should
  23890. // mark it as such.
  23891. var divergingLines = actualLine !== expectedLine && (!endsWith(actualLine, ',') || actualLine.slice(0, -1) !== expectedLine); // If the expected line has a trailing comma but is otherwise identical,
  23892. // add a comma at the end of the actual line. Otherwise the output could
  23893. // look weird as in:
  23894. //
  23895. // [
  23896. // 1 // No comma at the end!
  23897. // + 2
  23898. // ]
  23899. //
  23900. if (divergingLines && endsWith(expectedLine, ',') && expectedLine.slice(0, -1) === actualLine) {
  23901. divergingLines = false;
  23902. actualLine += ',';
  23903. }
  23904. if (divergingLines) {
  23905. // If the last diverging line is more than one line above and the
  23906. // current line is at least line three, add some of the former lines and
  23907. // also add dots to indicate skipped entries.
  23908. if (cur > 1 && i > 2) {
  23909. if (cur > 4) {
  23910. res += "\n".concat(blue, "...").concat(white);
  23911. skipped = true;
  23912. } else if (cur > 3) {
  23913. res += "\n ".concat(actualLines[i - 2]);
  23914. printedLines++;
  23915. }
  23916. res += "\n ".concat(actualLines[i - 1]);
  23917. printedLines++;
  23918. } // Mark the current line as the last diverging one.
  23919. lastPos = i; // Add the actual line to the result and cache the expected diverging
  23920. // line so consecutive diverging lines show up as +++--- and not +-+-+-.
  23921. res += "\n".concat(green, "+").concat(white, " ").concat(actualLine);
  23922. other += "\n".concat(red, "-").concat(white, " ").concat(expectedLine);
  23923. printedLines += 2; // Lines are identical
  23924. } else {
  23925. // Add all cached information to the result before adding other things
  23926. // and reset the cache.
  23927. res += other;
  23928. other = ''; // If the last diverging line is exactly one line above or if it is the
  23929. // very first line, add the line to the result.
  23930. if (cur === 1 || i === 0) {
  23931. res += "\n ".concat(actualLine);
  23932. printedLines++;
  23933. }
  23934. }
  23935. } // Inspected object to big (Show ~20 rows max)
  23936. if (printedLines > 20 && i < maxLines - 2) {
  23937. return "".concat(msg).concat(skippedMsg, "\n").concat(res, "\n").concat(blue, "...").concat(white).concat(other, "\n") + "".concat(blue, "...").concat(white);
  23938. }
  23939. }
  23940. return "".concat(msg).concat(skipped ? skippedMsg : '', "\n").concat(res).concat(other).concat(end).concat(indicator);
  23941. }
  23942. var AssertionError = /*#__PURE__*/function (_Error) {
  23943. _inherits(AssertionError, _Error);
  23944. function AssertionError(options) {
  23945. var _this;
  23946. _classCallCheck(this, AssertionError);
  23947. if (_typeof(options) !== 'object' || options === null) {
  23948. throw new ERR_INVALID_ARG_TYPE('options', 'Object', options);
  23949. }
  23950. var message = options.message,
  23951. operator = options.operator,
  23952. stackStartFn = options.stackStartFn;
  23953. var actual = options.actual,
  23954. expected = options.expected;
  23955. var limit = Error.stackTraceLimit;
  23956. Error.stackTraceLimit = 0;
  23957. if (message != null) {
  23958. _this = _possibleConstructorReturn(this, _getPrototypeOf(AssertionError).call(this, String(message)));
  23959. } else {
  23960. if (({env:{}}).stderr && ({env:{}}).stderr.isTTY) {
  23961. // Reset on each call to make sure we handle dynamically set environment
  23962. // variables correct.
  23963. if (({env:{}}).stderr && ({env:{}}).stderr.getColorDepth && ({env:{}}).stderr.getColorDepth() !== 1) {
  23964. blue = "\x1B[34m";
  23965. green = "\x1B[32m";
  23966. white = "\x1B[39m";
  23967. red = "\x1B[31m";
  23968. } else {
  23969. blue = '';
  23970. green = '';
  23971. white = '';
  23972. red = '';
  23973. }
  23974. } // Prevent the error stack from being visible by duplicating the error
  23975. // in a very close way to the original in case both sides are actually
  23976. // instances of Error.
  23977. if (_typeof(actual) === 'object' && actual !== null && _typeof(expected) === 'object' && expected !== null && 'stack' in actual && actual instanceof Error && 'stack' in expected && expected instanceof Error) {
  23978. actual = copyError(actual);
  23979. expected = copyError(expected);
  23980. }
  23981. if (operator === 'deepStrictEqual' || operator === 'strictEqual') {
  23982. _this = _possibleConstructorReturn(this, _getPrototypeOf(AssertionError).call(this, createErrDiff(actual, expected, operator)));
  23983. } else if (operator === 'notDeepStrictEqual' || operator === 'notStrictEqual') {
  23984. // In case the objects are equal but the operator requires unequal, show
  23985. // the first object and say A equals B
  23986. var base = kReadableOperator[operator];
  23987. var res = inspectValue(actual).split('\n'); // In case "actual" is an object, it should not be reference equal.
  23988. if (operator === 'notStrictEqual' && _typeof(actual) === 'object' && actual !== null) {
  23989. base = kReadableOperator.notStrictEqualObject;
  23990. } // Only remove lines in case it makes sense to collapse those.
  23991. // TODO: Accept env to always show the full error.
  23992. if (res.length > 30) {
  23993. res[26] = "".concat(blue, "...").concat(white);
  23994. while (res.length > 27) {
  23995. res.pop();
  23996. }
  23997. } // Only print a single input.
  23998. if (res.length === 1) {
  23999. _this = _possibleConstructorReturn(this, _getPrototypeOf(AssertionError).call(this, "".concat(base, " ").concat(res[0])));
  24000. } else {
  24001. _this = _possibleConstructorReturn(this, _getPrototypeOf(AssertionError).call(this, "".concat(base, "\n\n").concat(res.join('\n'), "\n")));
  24002. }
  24003. } else {
  24004. var _res = inspectValue(actual);
  24005. var other = '';
  24006. var knownOperators = kReadableOperator[operator];
  24007. if (operator === 'notDeepEqual' || operator === 'notEqual') {
  24008. _res = "".concat(kReadableOperator[operator], "\n\n").concat(_res);
  24009. if (_res.length > 1024) {
  24010. _res = "".concat(_res.slice(0, 1021), "...");
  24011. }
  24012. } else {
  24013. other = "".concat(inspectValue(expected));
  24014. if (_res.length > 512) {
  24015. _res = "".concat(_res.slice(0, 509), "...");
  24016. }
  24017. if (other.length > 512) {
  24018. other = "".concat(other.slice(0, 509), "...");
  24019. }
  24020. if (operator === 'deepEqual' || operator === 'equal') {
  24021. _res = "".concat(knownOperators, "\n\n").concat(_res, "\n\nshould equal\n\n");
  24022. } else {
  24023. other = " ".concat(operator, " ").concat(other);
  24024. }
  24025. }
  24026. _this = _possibleConstructorReturn(this, _getPrototypeOf(AssertionError).call(this, "".concat(_res).concat(other)));
  24027. }
  24028. }
  24029. Error.stackTraceLimit = limit;
  24030. _this.generatedMessage = !message;
  24031. Object.defineProperty(_assertThisInitialized(_this), 'name', {
  24032. value: 'AssertionError [ERR_ASSERTION]',
  24033. enumerable: false,
  24034. writable: true,
  24035. configurable: true
  24036. });
  24037. _this.code = 'ERR_ASSERTION';
  24038. _this.actual = actual;
  24039. _this.expected = expected;
  24040. _this.operator = operator;
  24041. if (Error.captureStackTrace) {
  24042. // eslint-disable-next-line no-restricted-syntax
  24043. Error.captureStackTrace(_assertThisInitialized(_this), stackStartFn);
  24044. } // Create error message including the error code in the name.
  24045. _this.stack; // Reset the name.
  24046. _this.name = 'AssertionError';
  24047. return _possibleConstructorReturn(_this);
  24048. }
  24049. _createClass(AssertionError, [{
  24050. key: "toString",
  24051. value: function toString() {
  24052. return "".concat(this.name, " [").concat(this.code, "]: ").concat(this.message);
  24053. }
  24054. }, {
  24055. key: inspect.custom,
  24056. value: function value(recurseTimes, ctx) {
  24057. // This limits the `actual` and `expected` property default inspection to
  24058. // the minimum depth. Otherwise those values would be too verbose compared
  24059. // to the actual error message which contains a combined view of these two
  24060. // input values.
  24061. return inspect(this, _objectSpread({}, ctx, {
  24062. customInspect: false,
  24063. depth: 0
  24064. }));
  24065. }
  24066. }]);
  24067. return AssertionError;
  24068. }(_wrapNativeSuper(Error));
  24069. module.exports = AssertionError;
  24070. /***/ }),
  24071. /***/ 9978:
  24072. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  24073. "use strict";
  24074. // Currently in sync with Node.js lib/internal/errors.js
  24075. // https://github.com/nodejs/node/commit/3b044962c48fe313905877a96b5d0894a5404f6f
  24076. /* eslint node-core/documented-errors: "error" */
  24077. /* eslint node-core/alphabetize-errors: "error" */
  24078. /* eslint node-core/prefer-util-format-errors: "error" */
  24079. // The whole point behind this internal module is to allow Node.js to no
  24080. // longer be forced to treat every error message change as a semver-major
  24081. // change. The NodeError classes here all expose a `code` property whose
  24082. // value statically and permanently identifies the error. While the error
  24083. // message may change, the code should not.
  24084. function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
  24085. function _typeof(obj) {
  24086. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  24087. _typeof = function _typeof(obj) {
  24088. return _typeof2(obj);
  24089. };
  24090. } else {
  24091. _typeof = function _typeof(obj) {
  24092. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  24093. };
  24094. }
  24095. return _typeof(obj);
  24096. }
  24097. function _classCallCheck(instance, Constructor) {
  24098. if (!(instance instanceof Constructor)) {
  24099. throw new TypeError("Cannot call a class as a function");
  24100. }
  24101. }
  24102. function _possibleConstructorReturn(self, call) {
  24103. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  24104. return call;
  24105. }
  24106. return _assertThisInitialized(self);
  24107. }
  24108. function _assertThisInitialized(self) {
  24109. if (self === void 0) {
  24110. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  24111. }
  24112. return self;
  24113. }
  24114. function _getPrototypeOf(o) {
  24115. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  24116. return o.__proto__ || Object.getPrototypeOf(o);
  24117. };
  24118. return _getPrototypeOf(o);
  24119. }
  24120. function _inherits(subClass, superClass) {
  24121. if (typeof superClass !== "function" && superClass !== null) {
  24122. throw new TypeError("Super expression must either be null or a function");
  24123. }
  24124. subClass.prototype = Object.create(superClass && superClass.prototype, {
  24125. constructor: {
  24126. value: subClass,
  24127. writable: true,
  24128. configurable: true
  24129. }
  24130. });
  24131. if (superClass) _setPrototypeOf(subClass, superClass);
  24132. }
  24133. function _setPrototypeOf(o, p) {
  24134. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  24135. o.__proto__ = p;
  24136. return o;
  24137. };
  24138. return _setPrototypeOf(o, p);
  24139. }
  24140. var codes = {}; // Lazy loaded
  24141. var assert;
  24142. var util;
  24143. function createErrorType(code, message, Base) {
  24144. if (!Base) {
  24145. Base = Error;
  24146. }
  24147. function getMessage(arg1, arg2, arg3) {
  24148. if (typeof message === 'string') {
  24149. return message;
  24150. } else {
  24151. return message(arg1, arg2, arg3);
  24152. }
  24153. }
  24154. var NodeError = /*#__PURE__*/function (_Base) {
  24155. _inherits(NodeError, _Base);
  24156. function NodeError(arg1, arg2, arg3) {
  24157. var _this;
  24158. _classCallCheck(this, NodeError);
  24159. _this = _possibleConstructorReturn(this, _getPrototypeOf(NodeError).call(this, getMessage(arg1, arg2, arg3)));
  24160. _this.code = code;
  24161. return _this;
  24162. }
  24163. return NodeError;
  24164. }(Base);
  24165. codes[code] = NodeError;
  24166. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  24167. function oneOf(expected, thing) {
  24168. if (Array.isArray(expected)) {
  24169. var len = expected.length;
  24170. expected = expected.map(function (i) {
  24171. return String(i);
  24172. });
  24173. if (len > 2) {
  24174. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  24175. } else if (len === 2) {
  24176. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  24177. } else {
  24178. return "of ".concat(thing, " ").concat(expected[0]);
  24179. }
  24180. } else {
  24181. return "of ".concat(thing, " ").concat(String(expected));
  24182. }
  24183. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  24184. function startsWith(str, search, pos) {
  24185. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  24186. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  24187. function endsWith(str, search, this_len) {
  24188. if (this_len === undefined || this_len > str.length) {
  24189. this_len = str.length;
  24190. }
  24191. return str.substring(this_len - search.length, this_len) === search;
  24192. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  24193. function includes(str, search, start) {
  24194. if (typeof start !== 'number') {
  24195. start = 0;
  24196. }
  24197. if (start + search.length > str.length) {
  24198. return false;
  24199. } else {
  24200. return str.indexOf(search, start) !== -1;
  24201. }
  24202. }
  24203. createErrorType('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);
  24204. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  24205. if (assert === undefined) assert = __webpack_require__(9373);
  24206. assert(typeof name === 'string', "'name' must be a string"); // determiner: 'must be' or 'must not be'
  24207. var determiner;
  24208. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  24209. determiner = 'must not be';
  24210. expected = expected.replace(/^not /, '');
  24211. } else {
  24212. determiner = 'must be';
  24213. }
  24214. var msg;
  24215. if (endsWith(name, ' argument')) {
  24216. // For cases like 'first argument'
  24217. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  24218. } else {
  24219. var type = includes(name, '.') ? 'property' : 'argument';
  24220. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  24221. } // TODO(BridgeAR): Improve the output by showing `null` and similar.
  24222. msg += ". Received type ".concat(_typeof(actual));
  24223. return msg;
  24224. }, TypeError);
  24225. createErrorType('ERR_INVALID_ARG_VALUE', function (name, value) {
  24226. var reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'is invalid';
  24227. if (util === undefined) util = __webpack_require__(161);
  24228. var inspected = util.inspect(value);
  24229. if (inspected.length > 128) {
  24230. inspected = "".concat(inspected.slice(0, 128), "...");
  24231. }
  24232. return "The argument '".concat(name, "' ").concat(reason, ". Received ").concat(inspected);
  24233. }, TypeError, RangeError);
  24234. createErrorType('ERR_INVALID_RETURN_VALUE', function (input, name, value) {
  24235. var type;
  24236. if (value && value.constructor && value.constructor.name) {
  24237. type = "instance of ".concat(value.constructor.name);
  24238. } else {
  24239. type = "type ".concat(_typeof(value));
  24240. }
  24241. return "Expected ".concat(input, " to be returned from the \"").concat(name, "\"") + " function but got ".concat(type, ".");
  24242. }, TypeError);
  24243. createErrorType('ERR_MISSING_ARGS', function () {
  24244. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  24245. args[_key] = arguments[_key];
  24246. }
  24247. if (assert === undefined) assert = __webpack_require__(9373);
  24248. assert(args.length > 0, 'At least one arg needs to be specified');
  24249. var msg = 'The ';
  24250. var len = args.length;
  24251. args = args.map(function (a) {
  24252. return "\"".concat(a, "\"");
  24253. });
  24254. switch (len) {
  24255. case 1:
  24256. msg += "".concat(args[0], " argument");
  24257. break;
  24258. case 2:
  24259. msg += "".concat(args[0], " and ").concat(args[1], " arguments");
  24260. break;
  24261. default:
  24262. msg += args.slice(0, len - 1).join(', ');
  24263. msg += ", and ".concat(args[len - 1], " arguments");
  24264. break;
  24265. }
  24266. return "".concat(msg, " must be specified");
  24267. }, TypeError);
  24268. module.exports.codes = codes;
  24269. /***/ }),
  24270. /***/ 9015:
  24271. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  24272. "use strict";
  24273. // Currently in sync with Node.js lib/internal/util/comparisons.js
  24274. // https://github.com/nodejs/node/commit/112cc7c27551254aa2b17098fb774867f05ed0d9
  24275. function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof2(obj); }
  24276. function _slicedToArray(arr, i) {
  24277. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  24278. }
  24279. function _nonIterableRest() {
  24280. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  24281. }
  24282. function _iterableToArrayLimit(arr, i) {
  24283. var _arr = [];
  24284. var _n = true;
  24285. var _d = false;
  24286. var _e = undefined;
  24287. try {
  24288. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  24289. _arr.push(_s.value);
  24290. if (i && _arr.length === i) break;
  24291. }
  24292. } catch (err) {
  24293. _d = true;
  24294. _e = err;
  24295. } finally {
  24296. try {
  24297. if (!_n && _i["return"] != null) _i["return"]();
  24298. } finally {
  24299. if (_d) throw _e;
  24300. }
  24301. }
  24302. return _arr;
  24303. }
  24304. function _arrayWithHoles(arr) {
  24305. if (Array.isArray(arr)) return arr;
  24306. }
  24307. function _typeof(obj) {
  24308. if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
  24309. _typeof = function _typeof(obj) {
  24310. return _typeof2(obj);
  24311. };
  24312. } else {
  24313. _typeof = function _typeof(obj) {
  24314. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
  24315. };
  24316. }
  24317. return _typeof(obj);
  24318. }
  24319. var regexFlagsSupported = /a/g.flags !== undefined;
  24320. var arrayFromSet = function arrayFromSet(set) {
  24321. var array = [];
  24322. set.forEach(function (value) {
  24323. return array.push(value);
  24324. });
  24325. return array;
  24326. };
  24327. var arrayFromMap = function arrayFromMap(map) {
  24328. var array = [];
  24329. map.forEach(function (value, key) {
  24330. return array.push([key, value]);
  24331. });
  24332. return array;
  24333. };
  24334. var objectIs = Object.is ? Object.is : __webpack_require__(4710);
  24335. var objectGetOwnPropertySymbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols : function () {
  24336. return [];
  24337. };
  24338. var numberIsNaN = Number.isNaN ? Number.isNaN : __webpack_require__(2191);
  24339. function uncurryThis(f) {
  24340. return f.call.bind(f);
  24341. }
  24342. var hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty);
  24343. var propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable);
  24344. var objectToString = uncurryThis(Object.prototype.toString);
  24345. var _require$types = (__webpack_require__(161).types),
  24346. isAnyArrayBuffer = _require$types.isAnyArrayBuffer,
  24347. isArrayBufferView = _require$types.isArrayBufferView,
  24348. isDate = _require$types.isDate,
  24349. isMap = _require$types.isMap,
  24350. isRegExp = _require$types.isRegExp,
  24351. isSet = _require$types.isSet,
  24352. isNativeError = _require$types.isNativeError,
  24353. isBoxedPrimitive = _require$types.isBoxedPrimitive,
  24354. isNumberObject = _require$types.isNumberObject,
  24355. isStringObject = _require$types.isStringObject,
  24356. isBooleanObject = _require$types.isBooleanObject,
  24357. isBigIntObject = _require$types.isBigIntObject,
  24358. isSymbolObject = _require$types.isSymbolObject,
  24359. isFloat32Array = _require$types.isFloat32Array,
  24360. isFloat64Array = _require$types.isFloat64Array;
  24361. function isNonIndex(key) {
  24362. if (key.length === 0 || key.length > 10) return true;
  24363. for (var i = 0; i < key.length; i++) {
  24364. var code = key.charCodeAt(i);
  24365. if (code < 48 || code > 57) return true;
  24366. } // The maximum size for an array is 2 ** 32 -1.
  24367. return key.length === 10 && key >= Math.pow(2, 32);
  24368. }
  24369. function getOwnNonIndexProperties(value) {
  24370. return Object.keys(value).filter(isNonIndex).concat(objectGetOwnPropertySymbols(value).filter(Object.prototype.propertyIsEnumerable.bind(value)));
  24371. } // Taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js
  24372. // original notice:
  24373. /*!
  24374. * The buffer module from node.js, for the browser.
  24375. *
  24376. * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
  24377. * @license MIT
  24378. */
  24379. function compare(a, b) {
  24380. if (a === b) {
  24381. return 0;
  24382. }
  24383. var x = a.length;
  24384. var y = b.length;
  24385. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  24386. if (a[i] !== b[i]) {
  24387. x = a[i];
  24388. y = b[i];
  24389. break;
  24390. }
  24391. }
  24392. if (x < y) {
  24393. return -1;
  24394. }
  24395. if (y < x) {
  24396. return 1;
  24397. }
  24398. return 0;
  24399. }
  24400. var ONLY_ENUMERABLE = undefined;
  24401. var kStrict = true;
  24402. var kLoose = false;
  24403. var kNoIterator = 0;
  24404. var kIsArray = 1;
  24405. var kIsSet = 2;
  24406. var kIsMap = 3; // Check if they have the same source and flags
  24407. function areSimilarRegExps(a, b) {
  24408. return regexFlagsSupported ? a.source === b.source && a.flags === b.flags : RegExp.prototype.toString.call(a) === RegExp.prototype.toString.call(b);
  24409. }
  24410. function areSimilarFloatArrays(a, b) {
  24411. if (a.byteLength !== b.byteLength) {
  24412. return false;
  24413. }
  24414. for (var offset = 0; offset < a.byteLength; offset++) {
  24415. if (a[offset] !== b[offset]) {
  24416. return false;
  24417. }
  24418. }
  24419. return true;
  24420. }
  24421. function areSimilarTypedArrays(a, b) {
  24422. if (a.byteLength !== b.byteLength) {
  24423. return false;
  24424. }
  24425. return compare(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)) === 0;
  24426. }
  24427. function areEqualArrayBuffers(buf1, buf2) {
  24428. return buf1.byteLength === buf2.byteLength && compare(new Uint8Array(buf1), new Uint8Array(buf2)) === 0;
  24429. }
  24430. function isEqualBoxedPrimitive(val1, val2) {
  24431. if (isNumberObject(val1)) {
  24432. return isNumberObject(val2) && objectIs(Number.prototype.valueOf.call(val1), Number.prototype.valueOf.call(val2));
  24433. }
  24434. if (isStringObject(val1)) {
  24435. return isStringObject(val2) && String.prototype.valueOf.call(val1) === String.prototype.valueOf.call(val2);
  24436. }
  24437. if (isBooleanObject(val1)) {
  24438. return isBooleanObject(val2) && Boolean.prototype.valueOf.call(val1) === Boolean.prototype.valueOf.call(val2);
  24439. }
  24440. if (isBigIntObject(val1)) {
  24441. return isBigIntObject(val2) && BigInt.prototype.valueOf.call(val1) === BigInt.prototype.valueOf.call(val2);
  24442. }
  24443. return isSymbolObject(val2) && Symbol.prototype.valueOf.call(val1) === Symbol.prototype.valueOf.call(val2);
  24444. } // Notes: Type tags are historical [[Class]] properties that can be set by
  24445. // FunctionTemplate::SetClassName() in C++ or Symbol.toStringTag in JS
  24446. // and retrieved using Object.prototype.toString.call(obj) in JS
  24447. // See https://tc39.github.io/ecma262/#sec-object.prototype.tostring
  24448. // for a list of tags pre-defined in the spec.
  24449. // There are some unspecified tags in the wild too (e.g. typed array tags).
  24450. // Since tags can be altered, they only serve fast failures
  24451. //
  24452. // Typed arrays and buffers are checked by comparing the content in their
  24453. // underlying ArrayBuffer. This optimization requires that it's
  24454. // reasonable to interpret their underlying memory in the same way,
  24455. // which is checked by comparing their type tags.
  24456. // (e.g. a Uint8Array and a Uint16Array with the same memory content
  24457. // could still be different because they will be interpreted differently).
  24458. //
  24459. // For strict comparison, objects should have
  24460. // a) The same built-in type tags
  24461. // b) The same prototypes.
  24462. function innerDeepEqual(val1, val2, strict, memos) {
  24463. // All identical values are equivalent, as determined by ===.
  24464. if (val1 === val2) {
  24465. if (val1 !== 0) return true;
  24466. return strict ? objectIs(val1, val2) : true;
  24467. } // Check more closely if val1 and val2 are equal.
  24468. if (strict) {
  24469. if (_typeof(val1) !== 'object') {
  24470. return typeof val1 === 'number' && numberIsNaN(val1) && numberIsNaN(val2);
  24471. }
  24472. if (_typeof(val2) !== 'object' || val1 === null || val2 === null) {
  24473. return false;
  24474. }
  24475. if (Object.getPrototypeOf(val1) !== Object.getPrototypeOf(val2)) {
  24476. return false;
  24477. }
  24478. } else {
  24479. if (val1 === null || _typeof(val1) !== 'object') {
  24480. if (val2 === null || _typeof(val2) !== 'object') {
  24481. // eslint-disable-next-line eqeqeq
  24482. return val1 == val2;
  24483. }
  24484. return false;
  24485. }
  24486. if (val2 === null || _typeof(val2) !== 'object') {
  24487. return false;
  24488. }
  24489. }
  24490. var val1Tag = objectToString(val1);
  24491. var val2Tag = objectToString(val2);
  24492. if (val1Tag !== val2Tag) {
  24493. return false;
  24494. }
  24495. if (Array.isArray(val1)) {
  24496. // Check for sparse arrays and general fast path
  24497. if (val1.length !== val2.length) {
  24498. return false;
  24499. }
  24500. var keys1 = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
  24501. var keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
  24502. if (keys1.length !== keys2.length) {
  24503. return false;
  24504. }
  24505. return keyCheck(val1, val2, strict, memos, kIsArray, keys1);
  24506. } // [browserify] This triggers on certain types in IE (Map/Set) so we don't
  24507. // wan't to early return out of the rest of the checks. However we can check
  24508. // if the second value is one of these values and the first isn't.
  24509. if (val1Tag === '[object Object]') {
  24510. // return keyCheck(val1, val2, strict, memos, kNoIterator);
  24511. if (!isMap(val1) && isMap(val2) || !isSet(val1) && isSet(val2)) {
  24512. return false;
  24513. }
  24514. }
  24515. if (isDate(val1)) {
  24516. if (!isDate(val2) || Date.prototype.getTime.call(val1) !== Date.prototype.getTime.call(val2)) {
  24517. return false;
  24518. }
  24519. } else if (isRegExp(val1)) {
  24520. if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) {
  24521. return false;
  24522. }
  24523. } else if (isNativeError(val1) || val1 instanceof Error) {
  24524. // Do not compare the stack as it might differ even though the error itself
  24525. // is otherwise identical.
  24526. if (val1.message !== val2.message || val1.name !== val2.name) {
  24527. return false;
  24528. }
  24529. } else if (isArrayBufferView(val1)) {
  24530. if (!strict && (isFloat32Array(val1) || isFloat64Array(val1))) {
  24531. if (!areSimilarFloatArrays(val1, val2)) {
  24532. return false;
  24533. }
  24534. } else if (!areSimilarTypedArrays(val1, val2)) {
  24535. return false;
  24536. } // Buffer.compare returns true, so val1.length === val2.length. If they both
  24537. // only contain numeric keys, we don't need to exam further than checking
  24538. // the symbols.
  24539. var _keys = getOwnNonIndexProperties(val1, ONLY_ENUMERABLE);
  24540. var _keys2 = getOwnNonIndexProperties(val2, ONLY_ENUMERABLE);
  24541. if (_keys.length !== _keys2.length) {
  24542. return false;
  24543. }
  24544. return keyCheck(val1, val2, strict, memos, kNoIterator, _keys);
  24545. } else if (isSet(val1)) {
  24546. if (!isSet(val2) || val1.size !== val2.size) {
  24547. return false;
  24548. }
  24549. return keyCheck(val1, val2, strict, memos, kIsSet);
  24550. } else if (isMap(val1)) {
  24551. if (!isMap(val2) || val1.size !== val2.size) {
  24552. return false;
  24553. }
  24554. return keyCheck(val1, val2, strict, memos, kIsMap);
  24555. } else if (isAnyArrayBuffer(val1)) {
  24556. if (!areEqualArrayBuffers(val1, val2)) {
  24557. return false;
  24558. }
  24559. } else if (isBoxedPrimitive(val1) && !isEqualBoxedPrimitive(val1, val2)) {
  24560. return false;
  24561. }
  24562. return keyCheck(val1, val2, strict, memos, kNoIterator);
  24563. }
  24564. function getEnumerables(val, keys) {
  24565. return keys.filter(function (k) {
  24566. return propertyIsEnumerable(val, k);
  24567. });
  24568. }
  24569. function keyCheck(val1, val2, strict, memos, iterationType, aKeys) {
  24570. // For all remaining Object pairs, including Array, objects and Maps,
  24571. // equivalence is determined by having:
  24572. // a) The same number of owned enumerable properties
  24573. // b) The same set of keys/indexes (although not necessarily the same order)
  24574. // c) Equivalent values for every corresponding key/index
  24575. // d) For Sets and Maps, equal contents
  24576. // Note: this accounts for both named and indexed properties on Arrays.
  24577. if (arguments.length === 5) {
  24578. aKeys = Object.keys(val1);
  24579. var bKeys = Object.keys(val2); // The pair must have the same number of owned properties.
  24580. if (aKeys.length !== bKeys.length) {
  24581. return false;
  24582. }
  24583. } // Cheap key test
  24584. var i = 0;
  24585. for (; i < aKeys.length; i++) {
  24586. if (!hasOwnProperty(val2, aKeys[i])) {
  24587. return false;
  24588. }
  24589. }
  24590. if (strict && arguments.length === 5) {
  24591. var symbolKeysA = objectGetOwnPropertySymbols(val1);
  24592. if (symbolKeysA.length !== 0) {
  24593. var count = 0;
  24594. for (i = 0; i < symbolKeysA.length; i++) {
  24595. var key = symbolKeysA[i];
  24596. if (propertyIsEnumerable(val1, key)) {
  24597. if (!propertyIsEnumerable(val2, key)) {
  24598. return false;
  24599. }
  24600. aKeys.push(key);
  24601. count++;
  24602. } else if (propertyIsEnumerable(val2, key)) {
  24603. return false;
  24604. }
  24605. }
  24606. var symbolKeysB = objectGetOwnPropertySymbols(val2);
  24607. if (symbolKeysA.length !== symbolKeysB.length && getEnumerables(val2, symbolKeysB).length !== count) {
  24608. return false;
  24609. }
  24610. } else {
  24611. var _symbolKeysB = objectGetOwnPropertySymbols(val2);
  24612. if (_symbolKeysB.length !== 0 && getEnumerables(val2, _symbolKeysB).length !== 0) {
  24613. return false;
  24614. }
  24615. }
  24616. }
  24617. if (aKeys.length === 0 && (iterationType === kNoIterator || iterationType === kIsArray && val1.length === 0 || val1.size === 0)) {
  24618. return true;
  24619. } // Use memos to handle cycles.
  24620. if (memos === undefined) {
  24621. memos = {
  24622. val1: new Map(),
  24623. val2: new Map(),
  24624. position: 0
  24625. };
  24626. } else {
  24627. // We prevent up to two map.has(x) calls by directly retrieving the value
  24628. // and checking for undefined. The map can only contain numbers, so it is
  24629. // safe to check for undefined only.
  24630. var val2MemoA = memos.val1.get(val1);
  24631. if (val2MemoA !== undefined) {
  24632. var val2MemoB = memos.val2.get(val2);
  24633. if (val2MemoB !== undefined) {
  24634. return val2MemoA === val2MemoB;
  24635. }
  24636. }
  24637. memos.position++;
  24638. }
  24639. memos.val1.set(val1, memos.position);
  24640. memos.val2.set(val2, memos.position);
  24641. var areEq = objEquiv(val1, val2, strict, aKeys, memos, iterationType);
  24642. memos.val1["delete"](val1);
  24643. memos.val2["delete"](val2);
  24644. return areEq;
  24645. }
  24646. function setHasEqualElement(set, val1, strict, memo) {
  24647. // Go looking.
  24648. var setValues = arrayFromSet(set);
  24649. for (var i = 0; i < setValues.length; i++) {
  24650. var val2 = setValues[i];
  24651. if (innerDeepEqual(val1, val2, strict, memo)) {
  24652. // Remove the matching element to make sure we do not check that again.
  24653. set["delete"](val2);
  24654. return true;
  24655. }
  24656. }
  24657. return false;
  24658. } // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using
  24659. // Sadly it is not possible to detect corresponding values properly in case the
  24660. // type is a string, number, bigint or boolean. The reason is that those values
  24661. // can match lots of different string values (e.g., 1n == '+00001').
  24662. function findLooseMatchingPrimitives(prim) {
  24663. switch (_typeof(prim)) {
  24664. case 'undefined':
  24665. return null;
  24666. case 'object':
  24667. // Only pass in null as object!
  24668. return undefined;
  24669. case 'symbol':
  24670. return false;
  24671. case 'string':
  24672. prim = +prim;
  24673. // Loose equal entries exist only if the string is possible to convert to
  24674. // a regular number and not NaN.
  24675. // Fall through
  24676. case 'number':
  24677. if (numberIsNaN(prim)) {
  24678. return false;
  24679. }
  24680. }
  24681. return true;
  24682. }
  24683. function setMightHaveLoosePrim(a, b, prim) {
  24684. var altValue = findLooseMatchingPrimitives(prim);
  24685. if (altValue != null) return altValue;
  24686. return b.has(altValue) && !a.has(altValue);
  24687. }
  24688. function mapMightHaveLoosePrim(a, b, prim, item, memo) {
  24689. var altValue = findLooseMatchingPrimitives(prim);
  24690. if (altValue != null) {
  24691. return altValue;
  24692. }
  24693. var curB = b.get(altValue);
  24694. if (curB === undefined && !b.has(altValue) || !innerDeepEqual(item, curB, false, memo)) {
  24695. return false;
  24696. }
  24697. return !a.has(altValue) && innerDeepEqual(item, curB, false, memo);
  24698. }
  24699. function setEquiv(a, b, strict, memo) {
  24700. // This is a lazily initiated Set of entries which have to be compared
  24701. // pairwise.
  24702. var set = null;
  24703. var aValues = arrayFromSet(a);
  24704. for (var i = 0; i < aValues.length; i++) {
  24705. var val = aValues[i]; // Note: Checking for the objects first improves the performance for object
  24706. // heavy sets but it is a minor slow down for primitives. As they are fast
  24707. // to check this improves the worst case scenario instead.
  24708. if (_typeof(val) === 'object' && val !== null) {
  24709. if (set === null) {
  24710. set = new Set();
  24711. } // If the specified value doesn't exist in the second set its an not null
  24712. // object (or non strict only: a not matching primitive) we'll need to go
  24713. // hunting for something thats deep-(strict-)equal to it. To make this
  24714. // O(n log n) complexity we have to copy these values in a new set first.
  24715. set.add(val);
  24716. } else if (!b.has(val)) {
  24717. if (strict) return false; // Fast path to detect missing string, symbol, undefined and null values.
  24718. if (!setMightHaveLoosePrim(a, b, val)) {
  24719. return false;
  24720. }
  24721. if (set === null) {
  24722. set = new Set();
  24723. }
  24724. set.add(val);
  24725. }
  24726. }
  24727. if (set !== null) {
  24728. var bValues = arrayFromSet(b);
  24729. for (var _i = 0; _i < bValues.length; _i++) {
  24730. var _val = bValues[_i]; // We have to check if a primitive value is already
  24731. // matching and only if it's not, go hunting for it.
  24732. if (_typeof(_val) === 'object' && _val !== null) {
  24733. if (!setHasEqualElement(set, _val, strict, memo)) return false;
  24734. } else if (!strict && !a.has(_val) && !setHasEqualElement(set, _val, strict, memo)) {
  24735. return false;
  24736. }
  24737. }
  24738. return set.size === 0;
  24739. }
  24740. return true;
  24741. }
  24742. function mapHasEqualEntry(set, map, key1, item1, strict, memo) {
  24743. // To be able to handle cases like:
  24744. // Map([[{}, 'a'], [{}, 'b']]) vs Map([[{}, 'b'], [{}, 'a']])
  24745. // ... we need to consider *all* matching keys, not just the first we find.
  24746. var setValues = arrayFromSet(set);
  24747. for (var i = 0; i < setValues.length; i++) {
  24748. var key2 = setValues[i];
  24749. if (innerDeepEqual(key1, key2, strict, memo) && innerDeepEqual(item1, map.get(key2), strict, memo)) {
  24750. set["delete"](key2);
  24751. return true;
  24752. }
  24753. }
  24754. return false;
  24755. }
  24756. function mapEquiv(a, b, strict, memo) {
  24757. var set = null;
  24758. var aEntries = arrayFromMap(a);
  24759. for (var i = 0; i < aEntries.length; i++) {
  24760. var _aEntries$i = _slicedToArray(aEntries[i], 2),
  24761. key = _aEntries$i[0],
  24762. item1 = _aEntries$i[1];
  24763. if (_typeof(key) === 'object' && key !== null) {
  24764. if (set === null) {
  24765. set = new Set();
  24766. }
  24767. set.add(key);
  24768. } else {
  24769. // By directly retrieving the value we prevent another b.has(key) check in
  24770. // almost all possible cases.
  24771. var item2 = b.get(key);
  24772. if (item2 === undefined && !b.has(key) || !innerDeepEqual(item1, item2, strict, memo)) {
  24773. if (strict) return false; // Fast path to detect missing string, symbol, undefined and null
  24774. // keys.
  24775. if (!mapMightHaveLoosePrim(a, b, key, item1, memo)) return false;
  24776. if (set === null) {
  24777. set = new Set();
  24778. }
  24779. set.add(key);
  24780. }
  24781. }
  24782. }
  24783. if (set !== null) {
  24784. var bEntries = arrayFromMap(b);
  24785. for (var _i2 = 0; _i2 < bEntries.length; _i2++) {
  24786. var _bEntries$_i = _slicedToArray(bEntries[_i2], 2),
  24787. key = _bEntries$_i[0],
  24788. item = _bEntries$_i[1];
  24789. if (_typeof(key) === 'object' && key !== null) {
  24790. if (!mapHasEqualEntry(set, a, key, item, strict, memo)) return false;
  24791. } else if (!strict && (!a.has(key) || !innerDeepEqual(a.get(key), item, false, memo)) && !mapHasEqualEntry(set, a, key, item, false, memo)) {
  24792. return false;
  24793. }
  24794. }
  24795. return set.size === 0;
  24796. }
  24797. return true;
  24798. }
  24799. function objEquiv(a, b, strict, keys, memos, iterationType) {
  24800. // Sets and maps don't have their entries accessible via normal object
  24801. // properties.
  24802. var i = 0;
  24803. if (iterationType === kIsSet) {
  24804. if (!setEquiv(a, b, strict, memos)) {
  24805. return false;
  24806. }
  24807. } else if (iterationType === kIsMap) {
  24808. if (!mapEquiv(a, b, strict, memos)) {
  24809. return false;
  24810. }
  24811. } else if (iterationType === kIsArray) {
  24812. for (; i < a.length; i++) {
  24813. if (hasOwnProperty(a, i)) {
  24814. if (!hasOwnProperty(b, i) || !innerDeepEqual(a[i], b[i], strict, memos)) {
  24815. return false;
  24816. }
  24817. } else if (hasOwnProperty(b, i)) {
  24818. return false;
  24819. } else {
  24820. // Array is sparse.
  24821. var keysA = Object.keys(a);
  24822. for (; i < keysA.length; i++) {
  24823. var key = keysA[i];
  24824. if (!hasOwnProperty(b, key) || !innerDeepEqual(a[key], b[key], strict, memos)) {
  24825. return false;
  24826. }
  24827. }
  24828. if (keysA.length !== Object.keys(b).length) {
  24829. return false;
  24830. }
  24831. return true;
  24832. }
  24833. }
  24834. } // The pair must have equivalent values for every corresponding key.
  24835. // Possibly expensive deep test:
  24836. for (i = 0; i < keys.length; i++) {
  24837. var _key = keys[i];
  24838. if (!innerDeepEqual(a[_key], b[_key], strict, memos)) {
  24839. return false;
  24840. }
  24841. }
  24842. return true;
  24843. }
  24844. function isDeepEqual(val1, val2) {
  24845. return innerDeepEqual(val1, val2, kLoose);
  24846. }
  24847. function isDeepStrictEqual(val1, val2) {
  24848. return innerDeepEqual(val1, val2, kStrict);
  24849. }
  24850. module.exports = {
  24851. isDeepEqual: isDeepEqual,
  24852. isDeepStrictEqual: isDeepStrictEqual
  24853. };
  24854. /***/ }),
  24855. /***/ 7943:
  24856. /***/ ((__unused_webpack_module, exports) => {
  24857. "use strict";
  24858. exports.byteLength = byteLength;
  24859. exports.toByteArray = toByteArray;
  24860. exports.fromByteArray = fromByteArray;
  24861. var lookup = [];
  24862. var revLookup = [];
  24863. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  24864. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  24865. for (var i = 0, len = code.length; i < len; ++i) {
  24866. lookup[i] = code[i];
  24867. revLookup[code.charCodeAt(i)] = i;
  24868. } // Support decoding URL-safe base64 strings, as Node.js does.
  24869. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  24870. revLookup['-'.charCodeAt(0)] = 62;
  24871. revLookup['_'.charCodeAt(0)] = 63;
  24872. function getLens(b64) {
  24873. var len = b64.length;
  24874. if (len % 4 > 0) {
  24875. throw new Error('Invalid string. Length must be a multiple of 4');
  24876. } // Trim off extra bytes after placeholder bytes are found
  24877. // See: https://github.com/beatgammit/base64-js/issues/42
  24878. var validLen = b64.indexOf('=');
  24879. if (validLen === -1) validLen = len;
  24880. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  24881. return [validLen, placeHoldersLen];
  24882. } // base64 is 4/3 + up to two characters of the original data
  24883. function byteLength(b64) {
  24884. var lens = getLens(b64);
  24885. var validLen = lens[0];
  24886. var placeHoldersLen = lens[1];
  24887. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  24888. }
  24889. function _byteLength(b64, validLen, placeHoldersLen) {
  24890. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  24891. }
  24892. function toByteArray(b64) {
  24893. var tmp;
  24894. var lens = getLens(b64);
  24895. var validLen = lens[0];
  24896. var placeHoldersLen = lens[1];
  24897. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  24898. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  24899. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  24900. var i;
  24901. for (i = 0; i < len; i += 4) {
  24902. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  24903. arr[curByte++] = tmp >> 16 & 0xFF;
  24904. arr[curByte++] = tmp >> 8 & 0xFF;
  24905. arr[curByte++] = tmp & 0xFF;
  24906. }
  24907. if (placeHoldersLen === 2) {
  24908. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  24909. arr[curByte++] = tmp & 0xFF;
  24910. }
  24911. if (placeHoldersLen === 1) {
  24912. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  24913. arr[curByte++] = tmp >> 8 & 0xFF;
  24914. arr[curByte++] = tmp & 0xFF;
  24915. }
  24916. return arr;
  24917. }
  24918. function tripletToBase64(num) {
  24919. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  24920. }
  24921. function encodeChunk(uint8, start, end) {
  24922. var tmp;
  24923. var output = [];
  24924. for (var i = start; i < end; i += 3) {
  24925. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  24926. output.push(tripletToBase64(tmp));
  24927. }
  24928. return output.join('');
  24929. }
  24930. function fromByteArray(uint8) {
  24931. var tmp;
  24932. var len = uint8.length;
  24933. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  24934. var parts = [];
  24935. var maxChunkLength = 16383; // must be multiple of 3
  24936. // go through the array every three bytes, we'll deal with trailing stuff later
  24937. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  24938. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  24939. } // pad the end with zeros, but make sure to not forget the extra bytes
  24940. if (extraBytes === 1) {
  24941. tmp = uint8[len - 1];
  24942. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  24943. } else if (extraBytes === 2) {
  24944. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  24945. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  24946. }
  24947. return parts.join('');
  24948. }
  24949. /***/ }),
  24950. /***/ 6781:
  24951. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  24952. /* module decorator */ module = __webpack_require__.nmd(module);
  24953. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  24954. (function (module, exports) {
  24955. 'use strict'; // Utils
  24956. function assert(val, msg) {
  24957. if (!val) throw new Error(msg || 'Assertion failed');
  24958. } // Could use `inherits` module, but don't want to move from single file
  24959. // architecture yet.
  24960. function inherits(ctor, superCtor) {
  24961. ctor.super_ = superCtor;
  24962. var TempCtor = function TempCtor() {};
  24963. TempCtor.prototype = superCtor.prototype;
  24964. ctor.prototype = new TempCtor();
  24965. ctor.prototype.constructor = ctor;
  24966. } // BN
  24967. function BN(number, base, endian) {
  24968. if (BN.isBN(number)) {
  24969. return number;
  24970. }
  24971. this.negative = 0;
  24972. this.words = null;
  24973. this.length = 0; // Reduction context
  24974. this.red = null;
  24975. if (number !== null) {
  24976. if (base === 'le' || base === 'be') {
  24977. endian = base;
  24978. base = 10;
  24979. }
  24980. this._init(number || 0, base || 10, endian || 'be');
  24981. }
  24982. }
  24983. if (_typeof(module) === 'object') {
  24984. module.exports = BN;
  24985. } else {
  24986. exports.BN = BN;
  24987. }
  24988. BN.BN = BN;
  24989. BN.wordSize = 26;
  24990. var Buffer;
  24991. try {
  24992. if (typeof window !== 'undefined' && typeof window.Buffer !== 'undefined') {
  24993. Buffer = window.Buffer;
  24994. } else {
  24995. Buffer = (__webpack_require__(6601).Buffer);
  24996. }
  24997. } catch (e) {}
  24998. BN.isBN = function isBN(num) {
  24999. if (num instanceof BN) {
  25000. return true;
  25001. }
  25002. return num !== null && _typeof(num) === 'object' && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
  25003. };
  25004. BN.max = function max(left, right) {
  25005. if (left.cmp(right) > 0) return left;
  25006. return right;
  25007. };
  25008. BN.min = function min(left, right) {
  25009. if (left.cmp(right) < 0) return left;
  25010. return right;
  25011. };
  25012. BN.prototype._init = function init(number, base, endian) {
  25013. if (typeof number === 'number') {
  25014. return this._initNumber(number, base, endian);
  25015. }
  25016. if (_typeof(number) === 'object') {
  25017. return this._initArray(number, base, endian);
  25018. }
  25019. if (base === 'hex') {
  25020. base = 16;
  25021. }
  25022. assert(base === (base | 0) && base >= 2 && base <= 36);
  25023. number = number.toString().replace(/\s+/g, '');
  25024. var start = 0;
  25025. if (number[0] === '-') {
  25026. start++;
  25027. this.negative = 1;
  25028. }
  25029. if (start < number.length) {
  25030. if (base === 16) {
  25031. this._parseHex(number, start, endian);
  25032. } else {
  25033. this._parseBase(number, base, start);
  25034. if (endian === 'le') {
  25035. this._initArray(this.toArray(), base, endian);
  25036. }
  25037. }
  25038. }
  25039. };
  25040. BN.prototype._initNumber = function _initNumber(number, base, endian) {
  25041. if (number < 0) {
  25042. this.negative = 1;
  25043. number = -number;
  25044. }
  25045. if (number < 0x4000000) {
  25046. this.words = [number & 0x3ffffff];
  25047. this.length = 1;
  25048. } else if (number < 0x10000000000000) {
  25049. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff];
  25050. this.length = 2;
  25051. } else {
  25052. assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
  25053. this.words = [number & 0x3ffffff, number / 0x4000000 & 0x3ffffff, 1];
  25054. this.length = 3;
  25055. }
  25056. if (endian !== 'le') return; // Reverse the bytes
  25057. this._initArray(this.toArray(), base, endian);
  25058. };
  25059. BN.prototype._initArray = function _initArray(number, base, endian) {
  25060. // Perhaps a Uint8Array
  25061. assert(typeof number.length === 'number');
  25062. if (number.length <= 0) {
  25063. this.words = [0];
  25064. this.length = 1;
  25065. return this;
  25066. }
  25067. this.length = Math.ceil(number.length / 3);
  25068. this.words = new Array(this.length);
  25069. for (var i = 0; i < this.length; i++) {
  25070. this.words[i] = 0;
  25071. }
  25072. var j, w;
  25073. var off = 0;
  25074. if (endian === 'be') {
  25075. for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
  25076. w = number[i] | number[i - 1] << 8 | number[i - 2] << 16;
  25077. this.words[j] |= w << off & 0x3ffffff;
  25078. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  25079. off += 24;
  25080. if (off >= 26) {
  25081. off -= 26;
  25082. j++;
  25083. }
  25084. }
  25085. } else if (endian === 'le') {
  25086. for (i = 0, j = 0; i < number.length; i += 3) {
  25087. w = number[i] | number[i + 1] << 8 | number[i + 2] << 16;
  25088. this.words[j] |= w << off & 0x3ffffff;
  25089. this.words[j + 1] = w >>> 26 - off & 0x3ffffff;
  25090. off += 24;
  25091. if (off >= 26) {
  25092. off -= 26;
  25093. j++;
  25094. }
  25095. }
  25096. }
  25097. return this._strip();
  25098. };
  25099. function parseHex4Bits(string, index) {
  25100. var c = string.charCodeAt(index); // '0' - '9'
  25101. if (c >= 48 && c <= 57) {
  25102. return c - 48; // 'A' - 'F'
  25103. } else if (c >= 65 && c <= 70) {
  25104. return c - 55; // 'a' - 'f'
  25105. } else if (c >= 97 && c <= 102) {
  25106. return c - 87;
  25107. } else {
  25108. assert(false, 'Invalid character in ' + string);
  25109. }
  25110. }
  25111. function parseHexByte(string, lowerBound, index) {
  25112. var r = parseHex4Bits(string, index);
  25113. if (index - 1 >= lowerBound) {
  25114. r |= parseHex4Bits(string, index - 1) << 4;
  25115. }
  25116. return r;
  25117. }
  25118. BN.prototype._parseHex = function _parseHex(number, start, endian) {
  25119. // Create possibly bigger array to ensure that it fits the number
  25120. this.length = Math.ceil((number.length - start) / 6);
  25121. this.words = new Array(this.length);
  25122. for (var i = 0; i < this.length; i++) {
  25123. this.words[i] = 0;
  25124. } // 24-bits chunks
  25125. var off = 0;
  25126. var j = 0;
  25127. var w;
  25128. if (endian === 'be') {
  25129. for (i = number.length - 1; i >= start; i -= 2) {
  25130. w = parseHexByte(number, start, i) << off;
  25131. this.words[j] |= w & 0x3ffffff;
  25132. if (off >= 18) {
  25133. off -= 18;
  25134. j += 1;
  25135. this.words[j] |= w >>> 26;
  25136. } else {
  25137. off += 8;
  25138. }
  25139. }
  25140. } else {
  25141. var parseLength = number.length - start;
  25142. for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) {
  25143. w = parseHexByte(number, start, i) << off;
  25144. this.words[j] |= w & 0x3ffffff;
  25145. if (off >= 18) {
  25146. off -= 18;
  25147. j += 1;
  25148. this.words[j] |= w >>> 26;
  25149. } else {
  25150. off += 8;
  25151. }
  25152. }
  25153. }
  25154. this._strip();
  25155. };
  25156. function parseBase(str, start, end, mul) {
  25157. var r = 0;
  25158. var b = 0;
  25159. var len = Math.min(str.length, end);
  25160. for (var i = start; i < len; i++) {
  25161. var c = str.charCodeAt(i) - 48;
  25162. r *= mul; // 'a'
  25163. if (c >= 49) {
  25164. b = c - 49 + 0xa; // 'A'
  25165. } else if (c >= 17) {
  25166. b = c - 17 + 0xa; // '0' - '9'
  25167. } else {
  25168. b = c;
  25169. }
  25170. assert(c >= 0 && b < mul, 'Invalid character');
  25171. r += b;
  25172. }
  25173. return r;
  25174. }
  25175. BN.prototype._parseBase = function _parseBase(number, base, start) {
  25176. // Initialize as zero
  25177. this.words = [0];
  25178. this.length = 1; // Find length of limb in base
  25179. for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
  25180. limbLen++;
  25181. }
  25182. limbLen--;
  25183. limbPow = limbPow / base | 0;
  25184. var total = number.length - start;
  25185. var mod = total % limbLen;
  25186. var end = Math.min(total, total - mod) + start;
  25187. var word = 0;
  25188. for (var i = start; i < end; i += limbLen) {
  25189. word = parseBase(number, i, i + limbLen, base);
  25190. this.imuln(limbPow);
  25191. if (this.words[0] + word < 0x4000000) {
  25192. this.words[0] += word;
  25193. } else {
  25194. this._iaddn(word);
  25195. }
  25196. }
  25197. if (mod !== 0) {
  25198. var pow = 1;
  25199. word = parseBase(number, i, number.length, base);
  25200. for (i = 0; i < mod; i++) {
  25201. pow *= base;
  25202. }
  25203. this.imuln(pow);
  25204. if (this.words[0] + word < 0x4000000) {
  25205. this.words[0] += word;
  25206. } else {
  25207. this._iaddn(word);
  25208. }
  25209. }
  25210. this._strip();
  25211. };
  25212. BN.prototype.copy = function copy(dest) {
  25213. dest.words = new Array(this.length);
  25214. for (var i = 0; i < this.length; i++) {
  25215. dest.words[i] = this.words[i];
  25216. }
  25217. dest.length = this.length;
  25218. dest.negative = this.negative;
  25219. dest.red = this.red;
  25220. };
  25221. function move(dest, src) {
  25222. dest.words = src.words;
  25223. dest.length = src.length;
  25224. dest.negative = src.negative;
  25225. dest.red = src.red;
  25226. }
  25227. BN.prototype._move = function _move(dest) {
  25228. move(dest, this);
  25229. };
  25230. BN.prototype.clone = function clone() {
  25231. var r = new BN(null);
  25232. this.copy(r);
  25233. return r;
  25234. };
  25235. BN.prototype._expand = function _expand(size) {
  25236. while (this.length < size) {
  25237. this.words[this.length++] = 0;
  25238. }
  25239. return this;
  25240. }; // Remove leading `0` from `this`
  25241. BN.prototype._strip = function strip() {
  25242. while (this.length > 1 && this.words[this.length - 1] === 0) {
  25243. this.length--;
  25244. }
  25245. return this._normSign();
  25246. };
  25247. BN.prototype._normSign = function _normSign() {
  25248. // -0 = 0
  25249. if (this.length === 1 && this.words[0] === 0) {
  25250. this.negative = 0;
  25251. }
  25252. return this;
  25253. }; // Check Symbol.for because not everywhere where Symbol defined
  25254. // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility
  25255. if (typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function') {
  25256. try {
  25257. BN.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = inspect;
  25258. } catch (e) {
  25259. BN.prototype.inspect = inspect;
  25260. }
  25261. } else {
  25262. BN.prototype.inspect = inspect;
  25263. }
  25264. function inspect() {
  25265. return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>';
  25266. }
  25267. /*
  25268. var zeros = [];
  25269. var groupSizes = [];
  25270. var groupBases = [];
  25271. var s = '';
  25272. var i = -1;
  25273. while (++i < BN.wordSize) {
  25274. zeros[i] = s;
  25275. s += '0';
  25276. }
  25277. groupSizes[0] = 0;
  25278. groupSizes[1] = 0;
  25279. groupBases[0] = 0;
  25280. groupBases[1] = 0;
  25281. var base = 2 - 1;
  25282. while (++base < 36 + 1) {
  25283. var groupSize = 0;
  25284. var groupBase = 1;
  25285. while (groupBase < (1 << BN.wordSize) / base) {
  25286. groupBase *= base;
  25287. groupSize += 1;
  25288. }
  25289. groupSizes[base] = groupSize;
  25290. groupBases[base] = groupBase;
  25291. }
  25292. */
  25293. var zeros = ['', '0', '00', '000', '0000', '00000', '000000', '0000000', '00000000', '000000000', '0000000000', '00000000000', '000000000000', '0000000000000', '00000000000000', '000000000000000', '0000000000000000', '00000000000000000', '000000000000000000', '0000000000000000000', '00000000000000000000', '000000000000000000000', '0000000000000000000000', '00000000000000000000000', '000000000000000000000000', '0000000000000000000000000'];
  25294. var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5];
  25295. var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176];
  25296. BN.prototype.toString = function toString(base, padding) {
  25297. base = base || 10;
  25298. padding = padding | 0 || 1;
  25299. var out;
  25300. if (base === 16 || base === 'hex') {
  25301. out = '';
  25302. var off = 0;
  25303. var carry = 0;
  25304. for (var i = 0; i < this.length; i++) {
  25305. var w = this.words[i];
  25306. var word = ((w << off | carry) & 0xffffff).toString(16);
  25307. carry = w >>> 24 - off & 0xffffff;
  25308. off += 2;
  25309. if (off >= 26) {
  25310. off -= 26;
  25311. i--;
  25312. }
  25313. if (carry !== 0 || i !== this.length - 1) {
  25314. out = zeros[6 - word.length] + word + out;
  25315. } else {
  25316. out = word + out;
  25317. }
  25318. }
  25319. if (carry !== 0) {
  25320. out = carry.toString(16) + out;
  25321. }
  25322. while (out.length % padding !== 0) {
  25323. out = '0' + out;
  25324. }
  25325. if (this.negative !== 0) {
  25326. out = '-' + out;
  25327. }
  25328. return out;
  25329. }
  25330. if (base === (base | 0) && base >= 2 && base <= 36) {
  25331. // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
  25332. var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize);
  25333. var groupBase = groupBases[base];
  25334. out = '';
  25335. var c = this.clone();
  25336. c.negative = 0;
  25337. while (!c.isZero()) {
  25338. var r = c.modrn(groupBase).toString(base);
  25339. c = c.idivn(groupBase);
  25340. if (!c.isZero()) {
  25341. out = zeros[groupSize - r.length] + r + out;
  25342. } else {
  25343. out = r + out;
  25344. }
  25345. }
  25346. if (this.isZero()) {
  25347. out = '0' + out;
  25348. }
  25349. while (out.length % padding !== 0) {
  25350. out = '0' + out;
  25351. }
  25352. if (this.negative !== 0) {
  25353. out = '-' + out;
  25354. }
  25355. return out;
  25356. }
  25357. assert(false, 'Base should be between 2 and 36');
  25358. };
  25359. BN.prototype.toNumber = function toNumber() {
  25360. var ret = this.words[0];
  25361. if (this.length === 2) {
  25362. ret += this.words[1] * 0x4000000;
  25363. } else if (this.length === 3 && this.words[2] === 0x01) {
  25364. // NOTE: at this stage it is known that the top bit is set
  25365. ret += 0x10000000000000 + this.words[1] * 0x4000000;
  25366. } else if (this.length > 2) {
  25367. assert(false, 'Number can only safely store up to 53 bits');
  25368. }
  25369. return this.negative !== 0 ? -ret : ret;
  25370. };
  25371. BN.prototype.toJSON = function toJSON() {
  25372. return this.toString(16, 2);
  25373. };
  25374. if (Buffer) {
  25375. BN.prototype.toBuffer = function toBuffer(endian, length) {
  25376. return this.toArrayLike(Buffer, endian, length);
  25377. };
  25378. }
  25379. BN.prototype.toArray = function toArray(endian, length) {
  25380. return this.toArrayLike(Array, endian, length);
  25381. };
  25382. var allocate = function allocate(ArrayType, size) {
  25383. if (ArrayType.allocUnsafe) {
  25384. return ArrayType.allocUnsafe(size);
  25385. }
  25386. return new ArrayType(size);
  25387. };
  25388. BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) {
  25389. this._strip();
  25390. var byteLength = this.byteLength();
  25391. var reqLength = length || Math.max(1, byteLength);
  25392. assert(byteLength <= reqLength, 'byte array longer than desired length');
  25393. assert(reqLength > 0, 'Requested array length <= 0');
  25394. var res = allocate(ArrayType, reqLength);
  25395. var postfix = endian === 'le' ? 'LE' : 'BE';
  25396. this['_toArrayLike' + postfix](res, byteLength);
  25397. return res;
  25398. };
  25399. BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) {
  25400. var position = 0;
  25401. var carry = 0;
  25402. for (var i = 0, shift = 0; i < this.length; i++) {
  25403. var word = this.words[i] << shift | carry;
  25404. res[position++] = word & 0xff;
  25405. if (position < res.length) {
  25406. res[position++] = word >> 8 & 0xff;
  25407. }
  25408. if (position < res.length) {
  25409. res[position++] = word >> 16 & 0xff;
  25410. }
  25411. if (shift === 6) {
  25412. if (position < res.length) {
  25413. res[position++] = word >> 24 & 0xff;
  25414. }
  25415. carry = 0;
  25416. shift = 0;
  25417. } else {
  25418. carry = word >>> 24;
  25419. shift += 2;
  25420. }
  25421. }
  25422. if (position < res.length) {
  25423. res[position++] = carry;
  25424. while (position < res.length) {
  25425. res[position++] = 0;
  25426. }
  25427. }
  25428. };
  25429. BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) {
  25430. var position = res.length - 1;
  25431. var carry = 0;
  25432. for (var i = 0, shift = 0; i < this.length; i++) {
  25433. var word = this.words[i] << shift | carry;
  25434. res[position--] = word & 0xff;
  25435. if (position >= 0) {
  25436. res[position--] = word >> 8 & 0xff;
  25437. }
  25438. if (position >= 0) {
  25439. res[position--] = word >> 16 & 0xff;
  25440. }
  25441. if (shift === 6) {
  25442. if (position >= 0) {
  25443. res[position--] = word >> 24 & 0xff;
  25444. }
  25445. carry = 0;
  25446. shift = 0;
  25447. } else {
  25448. carry = word >>> 24;
  25449. shift += 2;
  25450. }
  25451. }
  25452. if (position >= 0) {
  25453. res[position--] = carry;
  25454. while (position >= 0) {
  25455. res[position--] = 0;
  25456. }
  25457. }
  25458. };
  25459. if (Math.clz32) {
  25460. BN.prototype._countBits = function _countBits(w) {
  25461. return 32 - Math.clz32(w);
  25462. };
  25463. } else {
  25464. BN.prototype._countBits = function _countBits(w) {
  25465. var t = w;
  25466. var r = 0;
  25467. if (t >= 0x1000) {
  25468. r += 13;
  25469. t >>>= 13;
  25470. }
  25471. if (t >= 0x40) {
  25472. r += 7;
  25473. t >>>= 7;
  25474. }
  25475. if (t >= 0x8) {
  25476. r += 4;
  25477. t >>>= 4;
  25478. }
  25479. if (t >= 0x02) {
  25480. r += 2;
  25481. t >>>= 2;
  25482. }
  25483. return r + t;
  25484. };
  25485. }
  25486. BN.prototype._zeroBits = function _zeroBits(w) {
  25487. // Short-cut
  25488. if (w === 0) return 26;
  25489. var t = w;
  25490. var r = 0;
  25491. if ((t & 0x1fff) === 0) {
  25492. r += 13;
  25493. t >>>= 13;
  25494. }
  25495. if ((t & 0x7f) === 0) {
  25496. r += 7;
  25497. t >>>= 7;
  25498. }
  25499. if ((t & 0xf) === 0) {
  25500. r += 4;
  25501. t >>>= 4;
  25502. }
  25503. if ((t & 0x3) === 0) {
  25504. r += 2;
  25505. t >>>= 2;
  25506. }
  25507. if ((t & 0x1) === 0) {
  25508. r++;
  25509. }
  25510. return r;
  25511. }; // Return number of used bits in a BN
  25512. BN.prototype.bitLength = function bitLength() {
  25513. var w = this.words[this.length - 1];
  25514. var hi = this._countBits(w);
  25515. return (this.length - 1) * 26 + hi;
  25516. };
  25517. function toBitArray(num) {
  25518. var w = new Array(num.bitLength());
  25519. for (var bit = 0; bit < w.length; bit++) {
  25520. var off = bit / 26 | 0;
  25521. var wbit = bit % 26;
  25522. w[bit] = num.words[off] >>> wbit & 0x01;
  25523. }
  25524. return w;
  25525. } // Number of trailing zero bits
  25526. BN.prototype.zeroBits = function zeroBits() {
  25527. if (this.isZero()) return 0;
  25528. var r = 0;
  25529. for (var i = 0; i < this.length; i++) {
  25530. var b = this._zeroBits(this.words[i]);
  25531. r += b;
  25532. if (b !== 26) break;
  25533. }
  25534. return r;
  25535. };
  25536. BN.prototype.byteLength = function byteLength() {
  25537. return Math.ceil(this.bitLength() / 8);
  25538. };
  25539. BN.prototype.toTwos = function toTwos(width) {
  25540. if (this.negative !== 0) {
  25541. return this.abs().inotn(width).iaddn(1);
  25542. }
  25543. return this.clone();
  25544. };
  25545. BN.prototype.fromTwos = function fromTwos(width) {
  25546. if (this.testn(width - 1)) {
  25547. return this.notn(width).iaddn(1).ineg();
  25548. }
  25549. return this.clone();
  25550. };
  25551. BN.prototype.isNeg = function isNeg() {
  25552. return this.negative !== 0;
  25553. }; // Return negative clone of `this`
  25554. BN.prototype.neg = function neg() {
  25555. return this.clone().ineg();
  25556. };
  25557. BN.prototype.ineg = function ineg() {
  25558. if (!this.isZero()) {
  25559. this.negative ^= 1;
  25560. }
  25561. return this;
  25562. }; // Or `num` with `this` in-place
  25563. BN.prototype.iuor = function iuor(num) {
  25564. while (this.length < num.length) {
  25565. this.words[this.length++] = 0;
  25566. }
  25567. for (var i = 0; i < num.length; i++) {
  25568. this.words[i] = this.words[i] | num.words[i];
  25569. }
  25570. return this._strip();
  25571. };
  25572. BN.prototype.ior = function ior(num) {
  25573. assert((this.negative | num.negative) === 0);
  25574. return this.iuor(num);
  25575. }; // Or `num` with `this`
  25576. BN.prototype.or = function or(num) {
  25577. if (this.length > num.length) return this.clone().ior(num);
  25578. return num.clone().ior(this);
  25579. };
  25580. BN.prototype.uor = function uor(num) {
  25581. if (this.length > num.length) return this.clone().iuor(num);
  25582. return num.clone().iuor(this);
  25583. }; // And `num` with `this` in-place
  25584. BN.prototype.iuand = function iuand(num) {
  25585. // b = min-length(num, this)
  25586. var b;
  25587. if (this.length > num.length) {
  25588. b = num;
  25589. } else {
  25590. b = this;
  25591. }
  25592. for (var i = 0; i < b.length; i++) {
  25593. this.words[i] = this.words[i] & num.words[i];
  25594. }
  25595. this.length = b.length;
  25596. return this._strip();
  25597. };
  25598. BN.prototype.iand = function iand(num) {
  25599. assert((this.negative | num.negative) === 0);
  25600. return this.iuand(num);
  25601. }; // And `num` with `this`
  25602. BN.prototype.and = function and(num) {
  25603. if (this.length > num.length) return this.clone().iand(num);
  25604. return num.clone().iand(this);
  25605. };
  25606. BN.prototype.uand = function uand(num) {
  25607. if (this.length > num.length) return this.clone().iuand(num);
  25608. return num.clone().iuand(this);
  25609. }; // Xor `num` with `this` in-place
  25610. BN.prototype.iuxor = function iuxor(num) {
  25611. // a.length > b.length
  25612. var a;
  25613. var b;
  25614. if (this.length > num.length) {
  25615. a = this;
  25616. b = num;
  25617. } else {
  25618. a = num;
  25619. b = this;
  25620. }
  25621. for (var i = 0; i < b.length; i++) {
  25622. this.words[i] = a.words[i] ^ b.words[i];
  25623. }
  25624. if (this !== a) {
  25625. for (; i < a.length; i++) {
  25626. this.words[i] = a.words[i];
  25627. }
  25628. }
  25629. this.length = a.length;
  25630. return this._strip();
  25631. };
  25632. BN.prototype.ixor = function ixor(num) {
  25633. assert((this.negative | num.negative) === 0);
  25634. return this.iuxor(num);
  25635. }; // Xor `num` with `this`
  25636. BN.prototype.xor = function xor(num) {
  25637. if (this.length > num.length) return this.clone().ixor(num);
  25638. return num.clone().ixor(this);
  25639. };
  25640. BN.prototype.uxor = function uxor(num) {
  25641. if (this.length > num.length) return this.clone().iuxor(num);
  25642. return num.clone().iuxor(this);
  25643. }; // Not ``this`` with ``width`` bitwidth
  25644. BN.prototype.inotn = function inotn(width) {
  25645. assert(typeof width === 'number' && width >= 0);
  25646. var bytesNeeded = Math.ceil(width / 26) | 0;
  25647. var bitsLeft = width % 26; // Extend the buffer with leading zeroes
  25648. this._expand(bytesNeeded);
  25649. if (bitsLeft > 0) {
  25650. bytesNeeded--;
  25651. } // Handle complete words
  25652. for (var i = 0; i < bytesNeeded; i++) {
  25653. this.words[i] = ~this.words[i] & 0x3ffffff;
  25654. } // Handle the residue
  25655. if (bitsLeft > 0) {
  25656. this.words[i] = ~this.words[i] & 0x3ffffff >> 26 - bitsLeft;
  25657. } // And remove leading zeroes
  25658. return this._strip();
  25659. };
  25660. BN.prototype.notn = function notn(width) {
  25661. return this.clone().inotn(width);
  25662. }; // Set `bit` of `this`
  25663. BN.prototype.setn = function setn(bit, val) {
  25664. assert(typeof bit === 'number' && bit >= 0);
  25665. var off = bit / 26 | 0;
  25666. var wbit = bit % 26;
  25667. this._expand(off + 1);
  25668. if (val) {
  25669. this.words[off] = this.words[off] | 1 << wbit;
  25670. } else {
  25671. this.words[off] = this.words[off] & ~(1 << wbit);
  25672. }
  25673. return this._strip();
  25674. }; // Add `num` to `this` in-place
  25675. BN.prototype.iadd = function iadd(num) {
  25676. var r; // negative + positive
  25677. if (this.negative !== 0 && num.negative === 0) {
  25678. this.negative = 0;
  25679. r = this.isub(num);
  25680. this.negative ^= 1;
  25681. return this._normSign(); // positive + negative
  25682. } else if (this.negative === 0 && num.negative !== 0) {
  25683. num.negative = 0;
  25684. r = this.isub(num);
  25685. num.negative = 1;
  25686. return r._normSign();
  25687. } // a.length > b.length
  25688. var a, b;
  25689. if (this.length > num.length) {
  25690. a = this;
  25691. b = num;
  25692. } else {
  25693. a = num;
  25694. b = this;
  25695. }
  25696. var carry = 0;
  25697. for (var i = 0; i < b.length; i++) {
  25698. r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
  25699. this.words[i] = r & 0x3ffffff;
  25700. carry = r >>> 26;
  25701. }
  25702. for (; carry !== 0 && i < a.length; i++) {
  25703. r = (a.words[i] | 0) + carry;
  25704. this.words[i] = r & 0x3ffffff;
  25705. carry = r >>> 26;
  25706. }
  25707. this.length = a.length;
  25708. if (carry !== 0) {
  25709. this.words[this.length] = carry;
  25710. this.length++; // Copy the rest of the words
  25711. } else if (a !== this) {
  25712. for (; i < a.length; i++) {
  25713. this.words[i] = a.words[i];
  25714. }
  25715. }
  25716. return this;
  25717. }; // Add `num` to `this`
  25718. BN.prototype.add = function add(num) {
  25719. var res;
  25720. if (num.negative !== 0 && this.negative === 0) {
  25721. num.negative = 0;
  25722. res = this.sub(num);
  25723. num.negative ^= 1;
  25724. return res;
  25725. } else if (num.negative === 0 && this.negative !== 0) {
  25726. this.negative = 0;
  25727. res = num.sub(this);
  25728. this.negative = 1;
  25729. return res;
  25730. }
  25731. if (this.length > num.length) return this.clone().iadd(num);
  25732. return num.clone().iadd(this);
  25733. }; // Subtract `num` from `this` in-place
  25734. BN.prototype.isub = function isub(num) {
  25735. // this - (-num) = this + num
  25736. if (num.negative !== 0) {
  25737. num.negative = 0;
  25738. var r = this.iadd(num);
  25739. num.negative = 1;
  25740. return r._normSign(); // -this - num = -(this + num)
  25741. } else if (this.negative !== 0) {
  25742. this.negative = 0;
  25743. this.iadd(num);
  25744. this.negative = 1;
  25745. return this._normSign();
  25746. } // At this point both numbers are positive
  25747. var cmp = this.cmp(num); // Optimization - zeroify
  25748. if (cmp === 0) {
  25749. this.negative = 0;
  25750. this.length = 1;
  25751. this.words[0] = 0;
  25752. return this;
  25753. } // a > b
  25754. var a, b;
  25755. if (cmp > 0) {
  25756. a = this;
  25757. b = num;
  25758. } else {
  25759. a = num;
  25760. b = this;
  25761. }
  25762. var carry = 0;
  25763. for (var i = 0; i < b.length; i++) {
  25764. r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
  25765. carry = r >> 26;
  25766. this.words[i] = r & 0x3ffffff;
  25767. }
  25768. for (; carry !== 0 && i < a.length; i++) {
  25769. r = (a.words[i] | 0) + carry;
  25770. carry = r >> 26;
  25771. this.words[i] = r & 0x3ffffff;
  25772. } // Copy rest of the words
  25773. if (carry === 0 && i < a.length && a !== this) {
  25774. for (; i < a.length; i++) {
  25775. this.words[i] = a.words[i];
  25776. }
  25777. }
  25778. this.length = Math.max(this.length, i);
  25779. if (a !== this) {
  25780. this.negative = 1;
  25781. }
  25782. return this._strip();
  25783. }; // Subtract `num` from `this`
  25784. BN.prototype.sub = function sub(num) {
  25785. return this.clone().isub(num);
  25786. };
  25787. function smallMulTo(self, num, out) {
  25788. out.negative = num.negative ^ self.negative;
  25789. var len = self.length + num.length | 0;
  25790. out.length = len;
  25791. len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity)
  25792. var a = self.words[0] | 0;
  25793. var b = num.words[0] | 0;
  25794. var r = a * b;
  25795. var lo = r & 0x3ffffff;
  25796. var carry = r / 0x4000000 | 0;
  25797. out.words[0] = lo;
  25798. for (var k = 1; k < len; k++) {
  25799. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  25800. // note that ncarry could be >= 0x3ffffff
  25801. var ncarry = carry >>> 26;
  25802. var rword = carry & 0x3ffffff;
  25803. var maxJ = Math.min(k, num.length - 1);
  25804. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  25805. var i = k - j | 0;
  25806. a = self.words[i] | 0;
  25807. b = num.words[j] | 0;
  25808. r = a * b + rword;
  25809. ncarry += r / 0x4000000 | 0;
  25810. rword = r & 0x3ffffff;
  25811. }
  25812. out.words[k] = rword | 0;
  25813. carry = ncarry | 0;
  25814. }
  25815. if (carry !== 0) {
  25816. out.words[k] = carry | 0;
  25817. } else {
  25818. out.length--;
  25819. }
  25820. return out._strip();
  25821. } // TODO(indutny): it may be reasonable to omit it for users who don't need
  25822. // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
  25823. // multiplication (like elliptic secp256k1).
  25824. var comb10MulTo = function comb10MulTo(self, num, out) {
  25825. var a = self.words;
  25826. var b = num.words;
  25827. var o = out.words;
  25828. var c = 0;
  25829. var lo;
  25830. var mid;
  25831. var hi;
  25832. var a0 = a[0] | 0;
  25833. var al0 = a0 & 0x1fff;
  25834. var ah0 = a0 >>> 13;
  25835. var a1 = a[1] | 0;
  25836. var al1 = a1 & 0x1fff;
  25837. var ah1 = a1 >>> 13;
  25838. var a2 = a[2] | 0;
  25839. var al2 = a2 & 0x1fff;
  25840. var ah2 = a2 >>> 13;
  25841. var a3 = a[3] | 0;
  25842. var al3 = a3 & 0x1fff;
  25843. var ah3 = a3 >>> 13;
  25844. var a4 = a[4] | 0;
  25845. var al4 = a4 & 0x1fff;
  25846. var ah4 = a4 >>> 13;
  25847. var a5 = a[5] | 0;
  25848. var al5 = a5 & 0x1fff;
  25849. var ah5 = a5 >>> 13;
  25850. var a6 = a[6] | 0;
  25851. var al6 = a6 & 0x1fff;
  25852. var ah6 = a6 >>> 13;
  25853. var a7 = a[7] | 0;
  25854. var al7 = a7 & 0x1fff;
  25855. var ah7 = a7 >>> 13;
  25856. var a8 = a[8] | 0;
  25857. var al8 = a8 & 0x1fff;
  25858. var ah8 = a8 >>> 13;
  25859. var a9 = a[9] | 0;
  25860. var al9 = a9 & 0x1fff;
  25861. var ah9 = a9 >>> 13;
  25862. var b0 = b[0] | 0;
  25863. var bl0 = b0 & 0x1fff;
  25864. var bh0 = b0 >>> 13;
  25865. var b1 = b[1] | 0;
  25866. var bl1 = b1 & 0x1fff;
  25867. var bh1 = b1 >>> 13;
  25868. var b2 = b[2] | 0;
  25869. var bl2 = b2 & 0x1fff;
  25870. var bh2 = b2 >>> 13;
  25871. var b3 = b[3] | 0;
  25872. var bl3 = b3 & 0x1fff;
  25873. var bh3 = b3 >>> 13;
  25874. var b4 = b[4] | 0;
  25875. var bl4 = b4 & 0x1fff;
  25876. var bh4 = b4 >>> 13;
  25877. var b5 = b[5] | 0;
  25878. var bl5 = b5 & 0x1fff;
  25879. var bh5 = b5 >>> 13;
  25880. var b6 = b[6] | 0;
  25881. var bl6 = b6 & 0x1fff;
  25882. var bh6 = b6 >>> 13;
  25883. var b7 = b[7] | 0;
  25884. var bl7 = b7 & 0x1fff;
  25885. var bh7 = b7 >>> 13;
  25886. var b8 = b[8] | 0;
  25887. var bl8 = b8 & 0x1fff;
  25888. var bh8 = b8 >>> 13;
  25889. var b9 = b[9] | 0;
  25890. var bl9 = b9 & 0x1fff;
  25891. var bh9 = b9 >>> 13;
  25892. out.negative = self.negative ^ num.negative;
  25893. out.length = 19;
  25894. /* k = 0 */
  25895. lo = Math.imul(al0, bl0);
  25896. mid = Math.imul(al0, bh0);
  25897. mid = mid + Math.imul(ah0, bl0) | 0;
  25898. hi = Math.imul(ah0, bh0);
  25899. var w0 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  25900. c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0;
  25901. w0 &= 0x3ffffff;
  25902. /* k = 1 */
  25903. lo = Math.imul(al1, bl0);
  25904. mid = Math.imul(al1, bh0);
  25905. mid = mid + Math.imul(ah1, bl0) | 0;
  25906. hi = Math.imul(ah1, bh0);
  25907. lo = lo + Math.imul(al0, bl1) | 0;
  25908. mid = mid + Math.imul(al0, bh1) | 0;
  25909. mid = mid + Math.imul(ah0, bl1) | 0;
  25910. hi = hi + Math.imul(ah0, bh1) | 0;
  25911. var w1 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  25912. c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0;
  25913. w1 &= 0x3ffffff;
  25914. /* k = 2 */
  25915. lo = Math.imul(al2, bl0);
  25916. mid = Math.imul(al2, bh0);
  25917. mid = mid + Math.imul(ah2, bl0) | 0;
  25918. hi = Math.imul(ah2, bh0);
  25919. lo = lo + Math.imul(al1, bl1) | 0;
  25920. mid = mid + Math.imul(al1, bh1) | 0;
  25921. mid = mid + Math.imul(ah1, bl1) | 0;
  25922. hi = hi + Math.imul(ah1, bh1) | 0;
  25923. lo = lo + Math.imul(al0, bl2) | 0;
  25924. mid = mid + Math.imul(al0, bh2) | 0;
  25925. mid = mid + Math.imul(ah0, bl2) | 0;
  25926. hi = hi + Math.imul(ah0, bh2) | 0;
  25927. var w2 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  25928. c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0;
  25929. w2 &= 0x3ffffff;
  25930. /* k = 3 */
  25931. lo = Math.imul(al3, bl0);
  25932. mid = Math.imul(al3, bh0);
  25933. mid = mid + Math.imul(ah3, bl0) | 0;
  25934. hi = Math.imul(ah3, bh0);
  25935. lo = lo + Math.imul(al2, bl1) | 0;
  25936. mid = mid + Math.imul(al2, bh1) | 0;
  25937. mid = mid + Math.imul(ah2, bl1) | 0;
  25938. hi = hi + Math.imul(ah2, bh1) | 0;
  25939. lo = lo + Math.imul(al1, bl2) | 0;
  25940. mid = mid + Math.imul(al1, bh2) | 0;
  25941. mid = mid + Math.imul(ah1, bl2) | 0;
  25942. hi = hi + Math.imul(ah1, bh2) | 0;
  25943. lo = lo + Math.imul(al0, bl3) | 0;
  25944. mid = mid + Math.imul(al0, bh3) | 0;
  25945. mid = mid + Math.imul(ah0, bl3) | 0;
  25946. hi = hi + Math.imul(ah0, bh3) | 0;
  25947. var w3 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  25948. c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0;
  25949. w3 &= 0x3ffffff;
  25950. /* k = 4 */
  25951. lo = Math.imul(al4, bl0);
  25952. mid = Math.imul(al4, bh0);
  25953. mid = mid + Math.imul(ah4, bl0) | 0;
  25954. hi = Math.imul(ah4, bh0);
  25955. lo = lo + Math.imul(al3, bl1) | 0;
  25956. mid = mid + Math.imul(al3, bh1) | 0;
  25957. mid = mid + Math.imul(ah3, bl1) | 0;
  25958. hi = hi + Math.imul(ah3, bh1) | 0;
  25959. lo = lo + Math.imul(al2, bl2) | 0;
  25960. mid = mid + Math.imul(al2, bh2) | 0;
  25961. mid = mid + Math.imul(ah2, bl2) | 0;
  25962. hi = hi + Math.imul(ah2, bh2) | 0;
  25963. lo = lo + Math.imul(al1, bl3) | 0;
  25964. mid = mid + Math.imul(al1, bh3) | 0;
  25965. mid = mid + Math.imul(ah1, bl3) | 0;
  25966. hi = hi + Math.imul(ah1, bh3) | 0;
  25967. lo = lo + Math.imul(al0, bl4) | 0;
  25968. mid = mid + Math.imul(al0, bh4) | 0;
  25969. mid = mid + Math.imul(ah0, bl4) | 0;
  25970. hi = hi + Math.imul(ah0, bh4) | 0;
  25971. var w4 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  25972. c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0;
  25973. w4 &= 0x3ffffff;
  25974. /* k = 5 */
  25975. lo = Math.imul(al5, bl0);
  25976. mid = Math.imul(al5, bh0);
  25977. mid = mid + Math.imul(ah5, bl0) | 0;
  25978. hi = Math.imul(ah5, bh0);
  25979. lo = lo + Math.imul(al4, bl1) | 0;
  25980. mid = mid + Math.imul(al4, bh1) | 0;
  25981. mid = mid + Math.imul(ah4, bl1) | 0;
  25982. hi = hi + Math.imul(ah4, bh1) | 0;
  25983. lo = lo + Math.imul(al3, bl2) | 0;
  25984. mid = mid + Math.imul(al3, bh2) | 0;
  25985. mid = mid + Math.imul(ah3, bl2) | 0;
  25986. hi = hi + Math.imul(ah3, bh2) | 0;
  25987. lo = lo + Math.imul(al2, bl3) | 0;
  25988. mid = mid + Math.imul(al2, bh3) | 0;
  25989. mid = mid + Math.imul(ah2, bl3) | 0;
  25990. hi = hi + Math.imul(ah2, bh3) | 0;
  25991. lo = lo + Math.imul(al1, bl4) | 0;
  25992. mid = mid + Math.imul(al1, bh4) | 0;
  25993. mid = mid + Math.imul(ah1, bl4) | 0;
  25994. hi = hi + Math.imul(ah1, bh4) | 0;
  25995. lo = lo + Math.imul(al0, bl5) | 0;
  25996. mid = mid + Math.imul(al0, bh5) | 0;
  25997. mid = mid + Math.imul(ah0, bl5) | 0;
  25998. hi = hi + Math.imul(ah0, bh5) | 0;
  25999. var w5 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26000. c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0;
  26001. w5 &= 0x3ffffff;
  26002. /* k = 6 */
  26003. lo = Math.imul(al6, bl0);
  26004. mid = Math.imul(al6, bh0);
  26005. mid = mid + Math.imul(ah6, bl0) | 0;
  26006. hi = Math.imul(ah6, bh0);
  26007. lo = lo + Math.imul(al5, bl1) | 0;
  26008. mid = mid + Math.imul(al5, bh1) | 0;
  26009. mid = mid + Math.imul(ah5, bl1) | 0;
  26010. hi = hi + Math.imul(ah5, bh1) | 0;
  26011. lo = lo + Math.imul(al4, bl2) | 0;
  26012. mid = mid + Math.imul(al4, bh2) | 0;
  26013. mid = mid + Math.imul(ah4, bl2) | 0;
  26014. hi = hi + Math.imul(ah4, bh2) | 0;
  26015. lo = lo + Math.imul(al3, bl3) | 0;
  26016. mid = mid + Math.imul(al3, bh3) | 0;
  26017. mid = mid + Math.imul(ah3, bl3) | 0;
  26018. hi = hi + Math.imul(ah3, bh3) | 0;
  26019. lo = lo + Math.imul(al2, bl4) | 0;
  26020. mid = mid + Math.imul(al2, bh4) | 0;
  26021. mid = mid + Math.imul(ah2, bl4) | 0;
  26022. hi = hi + Math.imul(ah2, bh4) | 0;
  26023. lo = lo + Math.imul(al1, bl5) | 0;
  26024. mid = mid + Math.imul(al1, bh5) | 0;
  26025. mid = mid + Math.imul(ah1, bl5) | 0;
  26026. hi = hi + Math.imul(ah1, bh5) | 0;
  26027. lo = lo + Math.imul(al0, bl6) | 0;
  26028. mid = mid + Math.imul(al0, bh6) | 0;
  26029. mid = mid + Math.imul(ah0, bl6) | 0;
  26030. hi = hi + Math.imul(ah0, bh6) | 0;
  26031. var w6 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26032. c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0;
  26033. w6 &= 0x3ffffff;
  26034. /* k = 7 */
  26035. lo = Math.imul(al7, bl0);
  26036. mid = Math.imul(al7, bh0);
  26037. mid = mid + Math.imul(ah7, bl0) | 0;
  26038. hi = Math.imul(ah7, bh0);
  26039. lo = lo + Math.imul(al6, bl1) | 0;
  26040. mid = mid + Math.imul(al6, bh1) | 0;
  26041. mid = mid + Math.imul(ah6, bl1) | 0;
  26042. hi = hi + Math.imul(ah6, bh1) | 0;
  26043. lo = lo + Math.imul(al5, bl2) | 0;
  26044. mid = mid + Math.imul(al5, bh2) | 0;
  26045. mid = mid + Math.imul(ah5, bl2) | 0;
  26046. hi = hi + Math.imul(ah5, bh2) | 0;
  26047. lo = lo + Math.imul(al4, bl3) | 0;
  26048. mid = mid + Math.imul(al4, bh3) | 0;
  26049. mid = mid + Math.imul(ah4, bl3) | 0;
  26050. hi = hi + Math.imul(ah4, bh3) | 0;
  26051. lo = lo + Math.imul(al3, bl4) | 0;
  26052. mid = mid + Math.imul(al3, bh4) | 0;
  26053. mid = mid + Math.imul(ah3, bl4) | 0;
  26054. hi = hi + Math.imul(ah3, bh4) | 0;
  26055. lo = lo + Math.imul(al2, bl5) | 0;
  26056. mid = mid + Math.imul(al2, bh5) | 0;
  26057. mid = mid + Math.imul(ah2, bl5) | 0;
  26058. hi = hi + Math.imul(ah2, bh5) | 0;
  26059. lo = lo + Math.imul(al1, bl6) | 0;
  26060. mid = mid + Math.imul(al1, bh6) | 0;
  26061. mid = mid + Math.imul(ah1, bl6) | 0;
  26062. hi = hi + Math.imul(ah1, bh6) | 0;
  26063. lo = lo + Math.imul(al0, bl7) | 0;
  26064. mid = mid + Math.imul(al0, bh7) | 0;
  26065. mid = mid + Math.imul(ah0, bl7) | 0;
  26066. hi = hi + Math.imul(ah0, bh7) | 0;
  26067. var w7 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26068. c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0;
  26069. w7 &= 0x3ffffff;
  26070. /* k = 8 */
  26071. lo = Math.imul(al8, bl0);
  26072. mid = Math.imul(al8, bh0);
  26073. mid = mid + Math.imul(ah8, bl0) | 0;
  26074. hi = Math.imul(ah8, bh0);
  26075. lo = lo + Math.imul(al7, bl1) | 0;
  26076. mid = mid + Math.imul(al7, bh1) | 0;
  26077. mid = mid + Math.imul(ah7, bl1) | 0;
  26078. hi = hi + Math.imul(ah7, bh1) | 0;
  26079. lo = lo + Math.imul(al6, bl2) | 0;
  26080. mid = mid + Math.imul(al6, bh2) | 0;
  26081. mid = mid + Math.imul(ah6, bl2) | 0;
  26082. hi = hi + Math.imul(ah6, bh2) | 0;
  26083. lo = lo + Math.imul(al5, bl3) | 0;
  26084. mid = mid + Math.imul(al5, bh3) | 0;
  26085. mid = mid + Math.imul(ah5, bl3) | 0;
  26086. hi = hi + Math.imul(ah5, bh3) | 0;
  26087. lo = lo + Math.imul(al4, bl4) | 0;
  26088. mid = mid + Math.imul(al4, bh4) | 0;
  26089. mid = mid + Math.imul(ah4, bl4) | 0;
  26090. hi = hi + Math.imul(ah4, bh4) | 0;
  26091. lo = lo + Math.imul(al3, bl5) | 0;
  26092. mid = mid + Math.imul(al3, bh5) | 0;
  26093. mid = mid + Math.imul(ah3, bl5) | 0;
  26094. hi = hi + Math.imul(ah3, bh5) | 0;
  26095. lo = lo + Math.imul(al2, bl6) | 0;
  26096. mid = mid + Math.imul(al2, bh6) | 0;
  26097. mid = mid + Math.imul(ah2, bl6) | 0;
  26098. hi = hi + Math.imul(ah2, bh6) | 0;
  26099. lo = lo + Math.imul(al1, bl7) | 0;
  26100. mid = mid + Math.imul(al1, bh7) | 0;
  26101. mid = mid + Math.imul(ah1, bl7) | 0;
  26102. hi = hi + Math.imul(ah1, bh7) | 0;
  26103. lo = lo + Math.imul(al0, bl8) | 0;
  26104. mid = mid + Math.imul(al0, bh8) | 0;
  26105. mid = mid + Math.imul(ah0, bl8) | 0;
  26106. hi = hi + Math.imul(ah0, bh8) | 0;
  26107. var w8 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26108. c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0;
  26109. w8 &= 0x3ffffff;
  26110. /* k = 9 */
  26111. lo = Math.imul(al9, bl0);
  26112. mid = Math.imul(al9, bh0);
  26113. mid = mid + Math.imul(ah9, bl0) | 0;
  26114. hi = Math.imul(ah9, bh0);
  26115. lo = lo + Math.imul(al8, bl1) | 0;
  26116. mid = mid + Math.imul(al8, bh1) | 0;
  26117. mid = mid + Math.imul(ah8, bl1) | 0;
  26118. hi = hi + Math.imul(ah8, bh1) | 0;
  26119. lo = lo + Math.imul(al7, bl2) | 0;
  26120. mid = mid + Math.imul(al7, bh2) | 0;
  26121. mid = mid + Math.imul(ah7, bl2) | 0;
  26122. hi = hi + Math.imul(ah7, bh2) | 0;
  26123. lo = lo + Math.imul(al6, bl3) | 0;
  26124. mid = mid + Math.imul(al6, bh3) | 0;
  26125. mid = mid + Math.imul(ah6, bl3) | 0;
  26126. hi = hi + Math.imul(ah6, bh3) | 0;
  26127. lo = lo + Math.imul(al5, bl4) | 0;
  26128. mid = mid + Math.imul(al5, bh4) | 0;
  26129. mid = mid + Math.imul(ah5, bl4) | 0;
  26130. hi = hi + Math.imul(ah5, bh4) | 0;
  26131. lo = lo + Math.imul(al4, bl5) | 0;
  26132. mid = mid + Math.imul(al4, bh5) | 0;
  26133. mid = mid + Math.imul(ah4, bl5) | 0;
  26134. hi = hi + Math.imul(ah4, bh5) | 0;
  26135. lo = lo + Math.imul(al3, bl6) | 0;
  26136. mid = mid + Math.imul(al3, bh6) | 0;
  26137. mid = mid + Math.imul(ah3, bl6) | 0;
  26138. hi = hi + Math.imul(ah3, bh6) | 0;
  26139. lo = lo + Math.imul(al2, bl7) | 0;
  26140. mid = mid + Math.imul(al2, bh7) | 0;
  26141. mid = mid + Math.imul(ah2, bl7) | 0;
  26142. hi = hi + Math.imul(ah2, bh7) | 0;
  26143. lo = lo + Math.imul(al1, bl8) | 0;
  26144. mid = mid + Math.imul(al1, bh8) | 0;
  26145. mid = mid + Math.imul(ah1, bl8) | 0;
  26146. hi = hi + Math.imul(ah1, bh8) | 0;
  26147. lo = lo + Math.imul(al0, bl9) | 0;
  26148. mid = mid + Math.imul(al0, bh9) | 0;
  26149. mid = mid + Math.imul(ah0, bl9) | 0;
  26150. hi = hi + Math.imul(ah0, bh9) | 0;
  26151. var w9 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26152. c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0;
  26153. w9 &= 0x3ffffff;
  26154. /* k = 10 */
  26155. lo = Math.imul(al9, bl1);
  26156. mid = Math.imul(al9, bh1);
  26157. mid = mid + Math.imul(ah9, bl1) | 0;
  26158. hi = Math.imul(ah9, bh1);
  26159. lo = lo + Math.imul(al8, bl2) | 0;
  26160. mid = mid + Math.imul(al8, bh2) | 0;
  26161. mid = mid + Math.imul(ah8, bl2) | 0;
  26162. hi = hi + Math.imul(ah8, bh2) | 0;
  26163. lo = lo + Math.imul(al7, bl3) | 0;
  26164. mid = mid + Math.imul(al7, bh3) | 0;
  26165. mid = mid + Math.imul(ah7, bl3) | 0;
  26166. hi = hi + Math.imul(ah7, bh3) | 0;
  26167. lo = lo + Math.imul(al6, bl4) | 0;
  26168. mid = mid + Math.imul(al6, bh4) | 0;
  26169. mid = mid + Math.imul(ah6, bl4) | 0;
  26170. hi = hi + Math.imul(ah6, bh4) | 0;
  26171. lo = lo + Math.imul(al5, bl5) | 0;
  26172. mid = mid + Math.imul(al5, bh5) | 0;
  26173. mid = mid + Math.imul(ah5, bl5) | 0;
  26174. hi = hi + Math.imul(ah5, bh5) | 0;
  26175. lo = lo + Math.imul(al4, bl6) | 0;
  26176. mid = mid + Math.imul(al4, bh6) | 0;
  26177. mid = mid + Math.imul(ah4, bl6) | 0;
  26178. hi = hi + Math.imul(ah4, bh6) | 0;
  26179. lo = lo + Math.imul(al3, bl7) | 0;
  26180. mid = mid + Math.imul(al3, bh7) | 0;
  26181. mid = mid + Math.imul(ah3, bl7) | 0;
  26182. hi = hi + Math.imul(ah3, bh7) | 0;
  26183. lo = lo + Math.imul(al2, bl8) | 0;
  26184. mid = mid + Math.imul(al2, bh8) | 0;
  26185. mid = mid + Math.imul(ah2, bl8) | 0;
  26186. hi = hi + Math.imul(ah2, bh8) | 0;
  26187. lo = lo + Math.imul(al1, bl9) | 0;
  26188. mid = mid + Math.imul(al1, bh9) | 0;
  26189. mid = mid + Math.imul(ah1, bl9) | 0;
  26190. hi = hi + Math.imul(ah1, bh9) | 0;
  26191. var w10 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26192. c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0;
  26193. w10 &= 0x3ffffff;
  26194. /* k = 11 */
  26195. lo = Math.imul(al9, bl2);
  26196. mid = Math.imul(al9, bh2);
  26197. mid = mid + Math.imul(ah9, bl2) | 0;
  26198. hi = Math.imul(ah9, bh2);
  26199. lo = lo + Math.imul(al8, bl3) | 0;
  26200. mid = mid + Math.imul(al8, bh3) | 0;
  26201. mid = mid + Math.imul(ah8, bl3) | 0;
  26202. hi = hi + Math.imul(ah8, bh3) | 0;
  26203. lo = lo + Math.imul(al7, bl4) | 0;
  26204. mid = mid + Math.imul(al7, bh4) | 0;
  26205. mid = mid + Math.imul(ah7, bl4) | 0;
  26206. hi = hi + Math.imul(ah7, bh4) | 0;
  26207. lo = lo + Math.imul(al6, bl5) | 0;
  26208. mid = mid + Math.imul(al6, bh5) | 0;
  26209. mid = mid + Math.imul(ah6, bl5) | 0;
  26210. hi = hi + Math.imul(ah6, bh5) | 0;
  26211. lo = lo + Math.imul(al5, bl6) | 0;
  26212. mid = mid + Math.imul(al5, bh6) | 0;
  26213. mid = mid + Math.imul(ah5, bl6) | 0;
  26214. hi = hi + Math.imul(ah5, bh6) | 0;
  26215. lo = lo + Math.imul(al4, bl7) | 0;
  26216. mid = mid + Math.imul(al4, bh7) | 0;
  26217. mid = mid + Math.imul(ah4, bl7) | 0;
  26218. hi = hi + Math.imul(ah4, bh7) | 0;
  26219. lo = lo + Math.imul(al3, bl8) | 0;
  26220. mid = mid + Math.imul(al3, bh8) | 0;
  26221. mid = mid + Math.imul(ah3, bl8) | 0;
  26222. hi = hi + Math.imul(ah3, bh8) | 0;
  26223. lo = lo + Math.imul(al2, bl9) | 0;
  26224. mid = mid + Math.imul(al2, bh9) | 0;
  26225. mid = mid + Math.imul(ah2, bl9) | 0;
  26226. hi = hi + Math.imul(ah2, bh9) | 0;
  26227. var w11 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26228. c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0;
  26229. w11 &= 0x3ffffff;
  26230. /* k = 12 */
  26231. lo = Math.imul(al9, bl3);
  26232. mid = Math.imul(al9, bh3);
  26233. mid = mid + Math.imul(ah9, bl3) | 0;
  26234. hi = Math.imul(ah9, bh3);
  26235. lo = lo + Math.imul(al8, bl4) | 0;
  26236. mid = mid + Math.imul(al8, bh4) | 0;
  26237. mid = mid + Math.imul(ah8, bl4) | 0;
  26238. hi = hi + Math.imul(ah8, bh4) | 0;
  26239. lo = lo + Math.imul(al7, bl5) | 0;
  26240. mid = mid + Math.imul(al7, bh5) | 0;
  26241. mid = mid + Math.imul(ah7, bl5) | 0;
  26242. hi = hi + Math.imul(ah7, bh5) | 0;
  26243. lo = lo + Math.imul(al6, bl6) | 0;
  26244. mid = mid + Math.imul(al6, bh6) | 0;
  26245. mid = mid + Math.imul(ah6, bl6) | 0;
  26246. hi = hi + Math.imul(ah6, bh6) | 0;
  26247. lo = lo + Math.imul(al5, bl7) | 0;
  26248. mid = mid + Math.imul(al5, bh7) | 0;
  26249. mid = mid + Math.imul(ah5, bl7) | 0;
  26250. hi = hi + Math.imul(ah5, bh7) | 0;
  26251. lo = lo + Math.imul(al4, bl8) | 0;
  26252. mid = mid + Math.imul(al4, bh8) | 0;
  26253. mid = mid + Math.imul(ah4, bl8) | 0;
  26254. hi = hi + Math.imul(ah4, bh8) | 0;
  26255. lo = lo + Math.imul(al3, bl9) | 0;
  26256. mid = mid + Math.imul(al3, bh9) | 0;
  26257. mid = mid + Math.imul(ah3, bl9) | 0;
  26258. hi = hi + Math.imul(ah3, bh9) | 0;
  26259. var w12 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26260. c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0;
  26261. w12 &= 0x3ffffff;
  26262. /* k = 13 */
  26263. lo = Math.imul(al9, bl4);
  26264. mid = Math.imul(al9, bh4);
  26265. mid = mid + Math.imul(ah9, bl4) | 0;
  26266. hi = Math.imul(ah9, bh4);
  26267. lo = lo + Math.imul(al8, bl5) | 0;
  26268. mid = mid + Math.imul(al8, bh5) | 0;
  26269. mid = mid + Math.imul(ah8, bl5) | 0;
  26270. hi = hi + Math.imul(ah8, bh5) | 0;
  26271. lo = lo + Math.imul(al7, bl6) | 0;
  26272. mid = mid + Math.imul(al7, bh6) | 0;
  26273. mid = mid + Math.imul(ah7, bl6) | 0;
  26274. hi = hi + Math.imul(ah7, bh6) | 0;
  26275. lo = lo + Math.imul(al6, bl7) | 0;
  26276. mid = mid + Math.imul(al6, bh7) | 0;
  26277. mid = mid + Math.imul(ah6, bl7) | 0;
  26278. hi = hi + Math.imul(ah6, bh7) | 0;
  26279. lo = lo + Math.imul(al5, bl8) | 0;
  26280. mid = mid + Math.imul(al5, bh8) | 0;
  26281. mid = mid + Math.imul(ah5, bl8) | 0;
  26282. hi = hi + Math.imul(ah5, bh8) | 0;
  26283. lo = lo + Math.imul(al4, bl9) | 0;
  26284. mid = mid + Math.imul(al4, bh9) | 0;
  26285. mid = mid + Math.imul(ah4, bl9) | 0;
  26286. hi = hi + Math.imul(ah4, bh9) | 0;
  26287. var w13 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26288. c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0;
  26289. w13 &= 0x3ffffff;
  26290. /* k = 14 */
  26291. lo = Math.imul(al9, bl5);
  26292. mid = Math.imul(al9, bh5);
  26293. mid = mid + Math.imul(ah9, bl5) | 0;
  26294. hi = Math.imul(ah9, bh5);
  26295. lo = lo + Math.imul(al8, bl6) | 0;
  26296. mid = mid + Math.imul(al8, bh6) | 0;
  26297. mid = mid + Math.imul(ah8, bl6) | 0;
  26298. hi = hi + Math.imul(ah8, bh6) | 0;
  26299. lo = lo + Math.imul(al7, bl7) | 0;
  26300. mid = mid + Math.imul(al7, bh7) | 0;
  26301. mid = mid + Math.imul(ah7, bl7) | 0;
  26302. hi = hi + Math.imul(ah7, bh7) | 0;
  26303. lo = lo + Math.imul(al6, bl8) | 0;
  26304. mid = mid + Math.imul(al6, bh8) | 0;
  26305. mid = mid + Math.imul(ah6, bl8) | 0;
  26306. hi = hi + Math.imul(ah6, bh8) | 0;
  26307. lo = lo + Math.imul(al5, bl9) | 0;
  26308. mid = mid + Math.imul(al5, bh9) | 0;
  26309. mid = mid + Math.imul(ah5, bl9) | 0;
  26310. hi = hi + Math.imul(ah5, bh9) | 0;
  26311. var w14 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26312. c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0;
  26313. w14 &= 0x3ffffff;
  26314. /* k = 15 */
  26315. lo = Math.imul(al9, bl6);
  26316. mid = Math.imul(al9, bh6);
  26317. mid = mid + Math.imul(ah9, bl6) | 0;
  26318. hi = Math.imul(ah9, bh6);
  26319. lo = lo + Math.imul(al8, bl7) | 0;
  26320. mid = mid + Math.imul(al8, bh7) | 0;
  26321. mid = mid + Math.imul(ah8, bl7) | 0;
  26322. hi = hi + Math.imul(ah8, bh7) | 0;
  26323. lo = lo + Math.imul(al7, bl8) | 0;
  26324. mid = mid + Math.imul(al7, bh8) | 0;
  26325. mid = mid + Math.imul(ah7, bl8) | 0;
  26326. hi = hi + Math.imul(ah7, bh8) | 0;
  26327. lo = lo + Math.imul(al6, bl9) | 0;
  26328. mid = mid + Math.imul(al6, bh9) | 0;
  26329. mid = mid + Math.imul(ah6, bl9) | 0;
  26330. hi = hi + Math.imul(ah6, bh9) | 0;
  26331. var w15 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26332. c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0;
  26333. w15 &= 0x3ffffff;
  26334. /* k = 16 */
  26335. lo = Math.imul(al9, bl7);
  26336. mid = Math.imul(al9, bh7);
  26337. mid = mid + Math.imul(ah9, bl7) | 0;
  26338. hi = Math.imul(ah9, bh7);
  26339. lo = lo + Math.imul(al8, bl8) | 0;
  26340. mid = mid + Math.imul(al8, bh8) | 0;
  26341. mid = mid + Math.imul(ah8, bl8) | 0;
  26342. hi = hi + Math.imul(ah8, bh8) | 0;
  26343. lo = lo + Math.imul(al7, bl9) | 0;
  26344. mid = mid + Math.imul(al7, bh9) | 0;
  26345. mid = mid + Math.imul(ah7, bl9) | 0;
  26346. hi = hi + Math.imul(ah7, bh9) | 0;
  26347. var w16 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26348. c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0;
  26349. w16 &= 0x3ffffff;
  26350. /* k = 17 */
  26351. lo = Math.imul(al9, bl8);
  26352. mid = Math.imul(al9, bh8);
  26353. mid = mid + Math.imul(ah9, bl8) | 0;
  26354. hi = Math.imul(ah9, bh8);
  26355. lo = lo + Math.imul(al8, bl9) | 0;
  26356. mid = mid + Math.imul(al8, bh9) | 0;
  26357. mid = mid + Math.imul(ah8, bl9) | 0;
  26358. hi = hi + Math.imul(ah8, bh9) | 0;
  26359. var w17 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26360. c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0;
  26361. w17 &= 0x3ffffff;
  26362. /* k = 18 */
  26363. lo = Math.imul(al9, bl9);
  26364. mid = Math.imul(al9, bh9);
  26365. mid = mid + Math.imul(ah9, bl9) | 0;
  26366. hi = Math.imul(ah9, bh9);
  26367. var w18 = (c + lo | 0) + ((mid & 0x1fff) << 13) | 0;
  26368. c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0;
  26369. w18 &= 0x3ffffff;
  26370. o[0] = w0;
  26371. o[1] = w1;
  26372. o[2] = w2;
  26373. o[3] = w3;
  26374. o[4] = w4;
  26375. o[5] = w5;
  26376. o[6] = w6;
  26377. o[7] = w7;
  26378. o[8] = w8;
  26379. o[9] = w9;
  26380. o[10] = w10;
  26381. o[11] = w11;
  26382. o[12] = w12;
  26383. o[13] = w13;
  26384. o[14] = w14;
  26385. o[15] = w15;
  26386. o[16] = w16;
  26387. o[17] = w17;
  26388. o[18] = w18;
  26389. if (c !== 0) {
  26390. o[19] = c;
  26391. out.length++;
  26392. }
  26393. return out;
  26394. }; // Polyfill comb
  26395. if (!Math.imul) {
  26396. comb10MulTo = smallMulTo;
  26397. }
  26398. function bigMulTo(self, num, out) {
  26399. out.negative = num.negative ^ self.negative;
  26400. out.length = self.length + num.length;
  26401. var carry = 0;
  26402. var hncarry = 0;
  26403. for (var k = 0; k < out.length - 1; k++) {
  26404. // Sum all words with the same `i + j = k` and accumulate `ncarry`,
  26405. // note that ncarry could be >= 0x3ffffff
  26406. var ncarry = hncarry;
  26407. hncarry = 0;
  26408. var rword = carry & 0x3ffffff;
  26409. var maxJ = Math.min(k, num.length - 1);
  26410. for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
  26411. var i = k - j;
  26412. var a = self.words[i] | 0;
  26413. var b = num.words[j] | 0;
  26414. var r = a * b;
  26415. var lo = r & 0x3ffffff;
  26416. ncarry = ncarry + (r / 0x4000000 | 0) | 0;
  26417. lo = lo + rword | 0;
  26418. rword = lo & 0x3ffffff;
  26419. ncarry = ncarry + (lo >>> 26) | 0;
  26420. hncarry += ncarry >>> 26;
  26421. ncarry &= 0x3ffffff;
  26422. }
  26423. out.words[k] = rword;
  26424. carry = ncarry;
  26425. ncarry = hncarry;
  26426. }
  26427. if (carry !== 0) {
  26428. out.words[k] = carry;
  26429. } else {
  26430. out.length--;
  26431. }
  26432. return out._strip();
  26433. }
  26434. function jumboMulTo(self, num, out) {
  26435. // Temporary disable, see https://github.com/indutny/bn.js/issues/211
  26436. // var fftm = new FFTM();
  26437. // return fftm.mulp(self, num, out);
  26438. return bigMulTo(self, num, out);
  26439. }
  26440. BN.prototype.mulTo = function mulTo(num, out) {
  26441. var res;
  26442. var len = this.length + num.length;
  26443. if (this.length === 10 && num.length === 10) {
  26444. res = comb10MulTo(this, num, out);
  26445. } else if (len < 63) {
  26446. res = smallMulTo(this, num, out);
  26447. } else if (len < 1024) {
  26448. res = bigMulTo(this, num, out);
  26449. } else {
  26450. res = jumboMulTo(this, num, out);
  26451. }
  26452. return res;
  26453. }; // Cooley-Tukey algorithm for FFT
  26454. // slightly revisited to rely on looping instead of recursion
  26455. function FFTM(x, y) {
  26456. this.x = x;
  26457. this.y = y;
  26458. }
  26459. FFTM.prototype.makeRBT = function makeRBT(N) {
  26460. var t = new Array(N);
  26461. var l = BN.prototype._countBits(N) - 1;
  26462. for (var i = 0; i < N; i++) {
  26463. t[i] = this.revBin(i, l, N);
  26464. }
  26465. return t;
  26466. }; // Returns binary-reversed representation of `x`
  26467. FFTM.prototype.revBin = function revBin(x, l, N) {
  26468. if (x === 0 || x === N - 1) return x;
  26469. var rb = 0;
  26470. for (var i = 0; i < l; i++) {
  26471. rb |= (x & 1) << l - i - 1;
  26472. x >>= 1;
  26473. }
  26474. return rb;
  26475. }; // Performs "tweedling" phase, therefore 'emulating'
  26476. // behaviour of the recursive algorithm
  26477. FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) {
  26478. for (var i = 0; i < N; i++) {
  26479. rtws[i] = rws[rbt[i]];
  26480. itws[i] = iws[rbt[i]];
  26481. }
  26482. };
  26483. FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) {
  26484. this.permute(rbt, rws, iws, rtws, itws, N);
  26485. for (var s = 1; s < N; s <<= 1) {
  26486. var l = s << 1;
  26487. var rtwdf = Math.cos(2 * Math.PI / l);
  26488. var itwdf = Math.sin(2 * Math.PI / l);
  26489. for (var p = 0; p < N; p += l) {
  26490. var rtwdf_ = rtwdf;
  26491. var itwdf_ = itwdf;
  26492. for (var j = 0; j < s; j++) {
  26493. var re = rtws[p + j];
  26494. var ie = itws[p + j];
  26495. var ro = rtws[p + j + s];
  26496. var io = itws[p + j + s];
  26497. var rx = rtwdf_ * ro - itwdf_ * io;
  26498. io = rtwdf_ * io + itwdf_ * ro;
  26499. ro = rx;
  26500. rtws[p + j] = re + ro;
  26501. itws[p + j] = ie + io;
  26502. rtws[p + j + s] = re - ro;
  26503. itws[p + j + s] = ie - io;
  26504. /* jshint maxdepth : false */
  26505. if (j !== l) {
  26506. rx = rtwdf * rtwdf_ - itwdf * itwdf_;
  26507. itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
  26508. rtwdf_ = rx;
  26509. }
  26510. }
  26511. }
  26512. }
  26513. };
  26514. FFTM.prototype.guessLen13b = function guessLen13b(n, m) {
  26515. var N = Math.max(m, n) | 1;
  26516. var odd = N & 1;
  26517. var i = 0;
  26518. for (N = N / 2 | 0; N; N = N >>> 1) {
  26519. i++;
  26520. }
  26521. return 1 << i + 1 + odd;
  26522. };
  26523. FFTM.prototype.conjugate = function conjugate(rws, iws, N) {
  26524. if (N <= 1) return;
  26525. for (var i = 0; i < N / 2; i++) {
  26526. var t = rws[i];
  26527. rws[i] = rws[N - i - 1];
  26528. rws[N - i - 1] = t;
  26529. t = iws[i];
  26530. iws[i] = -iws[N - i - 1];
  26531. iws[N - i - 1] = -t;
  26532. }
  26533. };
  26534. FFTM.prototype.normalize13b = function normalize13b(ws, N) {
  26535. var carry = 0;
  26536. for (var i = 0; i < N / 2; i++) {
  26537. var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + Math.round(ws[2 * i] / N) + carry;
  26538. ws[i] = w & 0x3ffffff;
  26539. if (w < 0x4000000) {
  26540. carry = 0;
  26541. } else {
  26542. carry = w / 0x4000000 | 0;
  26543. }
  26544. }
  26545. return ws;
  26546. };
  26547. FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) {
  26548. var carry = 0;
  26549. for (var i = 0; i < len; i++) {
  26550. carry = carry + (ws[i] | 0);
  26551. rws[2 * i] = carry & 0x1fff;
  26552. carry = carry >>> 13;
  26553. rws[2 * i + 1] = carry & 0x1fff;
  26554. carry = carry >>> 13;
  26555. } // Pad with zeroes
  26556. for (i = 2 * len; i < N; ++i) {
  26557. rws[i] = 0;
  26558. }
  26559. assert(carry === 0);
  26560. assert((carry & ~0x1fff) === 0);
  26561. };
  26562. FFTM.prototype.stub = function stub(N) {
  26563. var ph = new Array(N);
  26564. for (var i = 0; i < N; i++) {
  26565. ph[i] = 0;
  26566. }
  26567. return ph;
  26568. };
  26569. FFTM.prototype.mulp = function mulp(x, y, out) {
  26570. var N = 2 * this.guessLen13b(x.length, y.length);
  26571. var rbt = this.makeRBT(N);
  26572. var _ = this.stub(N);
  26573. var rws = new Array(N);
  26574. var rwst = new Array(N);
  26575. var iwst = new Array(N);
  26576. var nrws = new Array(N);
  26577. var nrwst = new Array(N);
  26578. var niwst = new Array(N);
  26579. var rmws = out.words;
  26580. rmws.length = N;
  26581. this.convert13b(x.words, x.length, rws, N);
  26582. this.convert13b(y.words, y.length, nrws, N);
  26583. this.transform(rws, _, rwst, iwst, N, rbt);
  26584. this.transform(nrws, _, nrwst, niwst, N, rbt);
  26585. for (var i = 0; i < N; i++) {
  26586. var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
  26587. iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
  26588. rwst[i] = rx;
  26589. }
  26590. this.conjugate(rwst, iwst, N);
  26591. this.transform(rwst, iwst, rmws, _, N, rbt);
  26592. this.conjugate(rmws, _, N);
  26593. this.normalize13b(rmws, N);
  26594. out.negative = x.negative ^ y.negative;
  26595. out.length = x.length + y.length;
  26596. return out._strip();
  26597. }; // Multiply `this` by `num`
  26598. BN.prototype.mul = function mul(num) {
  26599. var out = new BN(null);
  26600. out.words = new Array(this.length + num.length);
  26601. return this.mulTo(num, out);
  26602. }; // Multiply employing FFT
  26603. BN.prototype.mulf = function mulf(num) {
  26604. var out = new BN(null);
  26605. out.words = new Array(this.length + num.length);
  26606. return jumboMulTo(this, num, out);
  26607. }; // In-place Multiplication
  26608. BN.prototype.imul = function imul(num) {
  26609. return this.clone().mulTo(num, this);
  26610. };
  26611. BN.prototype.imuln = function imuln(num) {
  26612. var isNegNum = num < 0;
  26613. if (isNegNum) num = -num;
  26614. assert(typeof num === 'number');
  26615. assert(num < 0x4000000); // Carry
  26616. var carry = 0;
  26617. for (var i = 0; i < this.length; i++) {
  26618. var w = (this.words[i] | 0) * num;
  26619. var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
  26620. carry >>= 26;
  26621. carry += w / 0x4000000 | 0; // NOTE: lo is 27bit maximum
  26622. carry += lo >>> 26;
  26623. this.words[i] = lo & 0x3ffffff;
  26624. }
  26625. if (carry !== 0) {
  26626. this.words[i] = carry;
  26627. this.length++;
  26628. }
  26629. return isNegNum ? this.ineg() : this;
  26630. };
  26631. BN.prototype.muln = function muln(num) {
  26632. return this.clone().imuln(num);
  26633. }; // `this` * `this`
  26634. BN.prototype.sqr = function sqr() {
  26635. return this.mul(this);
  26636. }; // `this` * `this` in-place
  26637. BN.prototype.isqr = function isqr() {
  26638. return this.imul(this.clone());
  26639. }; // Math.pow(`this`, `num`)
  26640. BN.prototype.pow = function pow(num) {
  26641. var w = toBitArray(num);
  26642. if (w.length === 0) return new BN(1); // Skip leading zeroes
  26643. var res = this;
  26644. for (var i = 0; i < w.length; i++, res = res.sqr()) {
  26645. if (w[i] !== 0) break;
  26646. }
  26647. if (++i < w.length) {
  26648. for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
  26649. if (w[i] === 0) continue;
  26650. res = res.mul(q);
  26651. }
  26652. }
  26653. return res;
  26654. }; // Shift-left in-place
  26655. BN.prototype.iushln = function iushln(bits) {
  26656. assert(typeof bits === 'number' && bits >= 0);
  26657. var r = bits % 26;
  26658. var s = (bits - r) / 26;
  26659. var carryMask = 0x3ffffff >>> 26 - r << 26 - r;
  26660. var i;
  26661. if (r !== 0) {
  26662. var carry = 0;
  26663. for (i = 0; i < this.length; i++) {
  26664. var newCarry = this.words[i] & carryMask;
  26665. var c = (this.words[i] | 0) - newCarry << r;
  26666. this.words[i] = c | carry;
  26667. carry = newCarry >>> 26 - r;
  26668. }
  26669. if (carry) {
  26670. this.words[i] = carry;
  26671. this.length++;
  26672. }
  26673. }
  26674. if (s !== 0) {
  26675. for (i = this.length - 1; i >= 0; i--) {
  26676. this.words[i + s] = this.words[i];
  26677. }
  26678. for (i = 0; i < s; i++) {
  26679. this.words[i] = 0;
  26680. }
  26681. this.length += s;
  26682. }
  26683. return this._strip();
  26684. };
  26685. BN.prototype.ishln = function ishln(bits) {
  26686. // TODO(indutny): implement me
  26687. assert(this.negative === 0);
  26688. return this.iushln(bits);
  26689. }; // Shift-right in-place
  26690. // NOTE: `hint` is a lowest bit before trailing zeroes
  26691. // NOTE: if `extended` is present - it will be filled with destroyed bits
  26692. BN.prototype.iushrn = function iushrn(bits, hint, extended) {
  26693. assert(typeof bits === 'number' && bits >= 0);
  26694. var h;
  26695. if (hint) {
  26696. h = (hint - hint % 26) / 26;
  26697. } else {
  26698. h = 0;
  26699. }
  26700. var r = bits % 26;
  26701. var s = Math.min((bits - r) / 26, this.length);
  26702. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  26703. var maskedWords = extended;
  26704. h -= s;
  26705. h = Math.max(0, h); // Extended mode, copy masked part
  26706. if (maskedWords) {
  26707. for (var i = 0; i < s; i++) {
  26708. maskedWords.words[i] = this.words[i];
  26709. }
  26710. maskedWords.length = s;
  26711. }
  26712. if (s === 0) {// No-op, we should not move anything at all
  26713. } else if (this.length > s) {
  26714. this.length -= s;
  26715. for (i = 0; i < this.length; i++) {
  26716. this.words[i] = this.words[i + s];
  26717. }
  26718. } else {
  26719. this.words[0] = 0;
  26720. this.length = 1;
  26721. }
  26722. var carry = 0;
  26723. for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
  26724. var word = this.words[i] | 0;
  26725. this.words[i] = carry << 26 - r | word >>> r;
  26726. carry = word & mask;
  26727. } // Push carried bits as a mask
  26728. if (maskedWords && carry !== 0) {
  26729. maskedWords.words[maskedWords.length++] = carry;
  26730. }
  26731. if (this.length === 0) {
  26732. this.words[0] = 0;
  26733. this.length = 1;
  26734. }
  26735. return this._strip();
  26736. };
  26737. BN.prototype.ishrn = function ishrn(bits, hint, extended) {
  26738. // TODO(indutny): implement me
  26739. assert(this.negative === 0);
  26740. return this.iushrn(bits, hint, extended);
  26741. }; // Shift-left
  26742. BN.prototype.shln = function shln(bits) {
  26743. return this.clone().ishln(bits);
  26744. };
  26745. BN.prototype.ushln = function ushln(bits) {
  26746. return this.clone().iushln(bits);
  26747. }; // Shift-right
  26748. BN.prototype.shrn = function shrn(bits) {
  26749. return this.clone().ishrn(bits);
  26750. };
  26751. BN.prototype.ushrn = function ushrn(bits) {
  26752. return this.clone().iushrn(bits);
  26753. }; // Test if n bit is set
  26754. BN.prototype.testn = function testn(bit) {
  26755. assert(typeof bit === 'number' && bit >= 0);
  26756. var r = bit % 26;
  26757. var s = (bit - r) / 26;
  26758. var q = 1 << r; // Fast case: bit is much higher than all existing words
  26759. if (this.length <= s) return false; // Check bit and return
  26760. var w = this.words[s];
  26761. return !!(w & q);
  26762. }; // Return only lowers bits of number (in-place)
  26763. BN.prototype.imaskn = function imaskn(bits) {
  26764. assert(typeof bits === 'number' && bits >= 0);
  26765. var r = bits % 26;
  26766. var s = (bits - r) / 26;
  26767. assert(this.negative === 0, 'imaskn works only with positive numbers');
  26768. if (this.length <= s) {
  26769. return this;
  26770. }
  26771. if (r !== 0) {
  26772. s++;
  26773. }
  26774. this.length = Math.min(s, this.length);
  26775. if (r !== 0) {
  26776. var mask = 0x3ffffff ^ 0x3ffffff >>> r << r;
  26777. this.words[this.length - 1] &= mask;
  26778. }
  26779. return this._strip();
  26780. }; // Return only lowers bits of number
  26781. BN.prototype.maskn = function maskn(bits) {
  26782. return this.clone().imaskn(bits);
  26783. }; // Add plain number `num` to `this`
  26784. BN.prototype.iaddn = function iaddn(num) {
  26785. assert(typeof num === 'number');
  26786. assert(num < 0x4000000);
  26787. if (num < 0) return this.isubn(-num); // Possible sign change
  26788. if (this.negative !== 0) {
  26789. if (this.length === 1 && (this.words[0] | 0) <= num) {
  26790. this.words[0] = num - (this.words[0] | 0);
  26791. this.negative = 0;
  26792. return this;
  26793. }
  26794. this.negative = 0;
  26795. this.isubn(num);
  26796. this.negative = 1;
  26797. return this;
  26798. } // Add without checks
  26799. return this._iaddn(num);
  26800. };
  26801. BN.prototype._iaddn = function _iaddn(num) {
  26802. this.words[0] += num; // Carry
  26803. for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
  26804. this.words[i] -= 0x4000000;
  26805. if (i === this.length - 1) {
  26806. this.words[i + 1] = 1;
  26807. } else {
  26808. this.words[i + 1]++;
  26809. }
  26810. }
  26811. this.length = Math.max(this.length, i + 1);
  26812. return this;
  26813. }; // Subtract plain number `num` from `this`
  26814. BN.prototype.isubn = function isubn(num) {
  26815. assert(typeof num === 'number');
  26816. assert(num < 0x4000000);
  26817. if (num < 0) return this.iaddn(-num);
  26818. if (this.negative !== 0) {
  26819. this.negative = 0;
  26820. this.iaddn(num);
  26821. this.negative = 1;
  26822. return this;
  26823. }
  26824. this.words[0] -= num;
  26825. if (this.length === 1 && this.words[0] < 0) {
  26826. this.words[0] = -this.words[0];
  26827. this.negative = 1;
  26828. } else {
  26829. // Carry
  26830. for (var i = 0; i < this.length && this.words[i] < 0; i++) {
  26831. this.words[i] += 0x4000000;
  26832. this.words[i + 1] -= 1;
  26833. }
  26834. }
  26835. return this._strip();
  26836. };
  26837. BN.prototype.addn = function addn(num) {
  26838. return this.clone().iaddn(num);
  26839. };
  26840. BN.prototype.subn = function subn(num) {
  26841. return this.clone().isubn(num);
  26842. };
  26843. BN.prototype.iabs = function iabs() {
  26844. this.negative = 0;
  26845. return this;
  26846. };
  26847. BN.prototype.abs = function abs() {
  26848. return this.clone().iabs();
  26849. };
  26850. BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) {
  26851. var len = num.length + shift;
  26852. var i;
  26853. this._expand(len);
  26854. var w;
  26855. var carry = 0;
  26856. for (i = 0; i < num.length; i++) {
  26857. w = (this.words[i + shift] | 0) + carry;
  26858. var right = (num.words[i] | 0) * mul;
  26859. w -= right & 0x3ffffff;
  26860. carry = (w >> 26) - (right / 0x4000000 | 0);
  26861. this.words[i + shift] = w & 0x3ffffff;
  26862. }
  26863. for (; i < this.length - shift; i++) {
  26864. w = (this.words[i + shift] | 0) + carry;
  26865. carry = w >> 26;
  26866. this.words[i + shift] = w & 0x3ffffff;
  26867. }
  26868. if (carry === 0) return this._strip(); // Subtraction overflow
  26869. assert(carry === -1);
  26870. carry = 0;
  26871. for (i = 0; i < this.length; i++) {
  26872. w = -(this.words[i] | 0) + carry;
  26873. carry = w >> 26;
  26874. this.words[i] = w & 0x3ffffff;
  26875. }
  26876. this.negative = 1;
  26877. return this._strip();
  26878. };
  26879. BN.prototype._wordDiv = function _wordDiv(num, mode) {
  26880. var shift = this.length - num.length;
  26881. var a = this.clone();
  26882. var b = num; // Normalize
  26883. var bhi = b.words[b.length - 1] | 0;
  26884. var bhiBits = this._countBits(bhi);
  26885. shift = 26 - bhiBits;
  26886. if (shift !== 0) {
  26887. b = b.ushln(shift);
  26888. a.iushln(shift);
  26889. bhi = b.words[b.length - 1] | 0;
  26890. } // Initialize quotient
  26891. var m = a.length - b.length;
  26892. var q;
  26893. if (mode !== 'mod') {
  26894. q = new BN(null);
  26895. q.length = m + 1;
  26896. q.words = new Array(q.length);
  26897. for (var i = 0; i < q.length; i++) {
  26898. q.words[i] = 0;
  26899. }
  26900. }
  26901. var diff = a.clone()._ishlnsubmul(b, 1, m);
  26902. if (diff.negative === 0) {
  26903. a = diff;
  26904. if (q) {
  26905. q.words[m] = 1;
  26906. }
  26907. }
  26908. for (var j = m - 1; j >= 0; j--) {
  26909. var qj = (a.words[b.length + j] | 0) * 0x4000000 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
  26910. // (0x7ffffff)
  26911. qj = Math.min(qj / bhi | 0, 0x3ffffff);
  26912. a._ishlnsubmul(b, qj, j);
  26913. while (a.negative !== 0) {
  26914. qj--;
  26915. a.negative = 0;
  26916. a._ishlnsubmul(b, 1, j);
  26917. if (!a.isZero()) {
  26918. a.negative ^= 1;
  26919. }
  26920. }
  26921. if (q) {
  26922. q.words[j] = qj;
  26923. }
  26924. }
  26925. if (q) {
  26926. q._strip();
  26927. }
  26928. a._strip(); // Denormalize
  26929. if (mode !== 'div' && shift !== 0) {
  26930. a.iushrn(shift);
  26931. }
  26932. return {
  26933. div: q || null,
  26934. mod: a
  26935. };
  26936. }; // NOTE: 1) `mode` can be set to `mod` to request mod only,
  26937. // to `div` to request div only, or be absent to
  26938. // request both div & mod
  26939. // 2) `positive` is true if unsigned mod is requested
  26940. BN.prototype.divmod = function divmod(num, mode, positive) {
  26941. assert(!num.isZero());
  26942. if (this.isZero()) {
  26943. return {
  26944. div: new BN(0),
  26945. mod: new BN(0)
  26946. };
  26947. }
  26948. var div, mod, res;
  26949. if (this.negative !== 0 && num.negative === 0) {
  26950. res = this.neg().divmod(num, mode);
  26951. if (mode !== 'mod') {
  26952. div = res.div.neg();
  26953. }
  26954. if (mode !== 'div') {
  26955. mod = res.mod.neg();
  26956. if (positive && mod.negative !== 0) {
  26957. mod.iadd(num);
  26958. }
  26959. }
  26960. return {
  26961. div: div,
  26962. mod: mod
  26963. };
  26964. }
  26965. if (this.negative === 0 && num.negative !== 0) {
  26966. res = this.divmod(num.neg(), mode);
  26967. if (mode !== 'mod') {
  26968. div = res.div.neg();
  26969. }
  26970. return {
  26971. div: div,
  26972. mod: res.mod
  26973. };
  26974. }
  26975. if ((this.negative & num.negative) !== 0) {
  26976. res = this.neg().divmod(num.neg(), mode);
  26977. if (mode !== 'div') {
  26978. mod = res.mod.neg();
  26979. if (positive && mod.negative !== 0) {
  26980. mod.isub(num);
  26981. }
  26982. }
  26983. return {
  26984. div: res.div,
  26985. mod: mod
  26986. };
  26987. } // Both numbers are positive at this point
  26988. // Strip both numbers to approximate shift value
  26989. if (num.length > this.length || this.cmp(num) < 0) {
  26990. return {
  26991. div: new BN(0),
  26992. mod: this
  26993. };
  26994. } // Very short reduction
  26995. if (num.length === 1) {
  26996. if (mode === 'div') {
  26997. return {
  26998. div: this.divn(num.words[0]),
  26999. mod: null
  27000. };
  27001. }
  27002. if (mode === 'mod') {
  27003. return {
  27004. div: null,
  27005. mod: new BN(this.modrn(num.words[0]))
  27006. };
  27007. }
  27008. return {
  27009. div: this.divn(num.words[0]),
  27010. mod: new BN(this.modrn(num.words[0]))
  27011. };
  27012. }
  27013. return this._wordDiv(num, mode);
  27014. }; // Find `this` / `num`
  27015. BN.prototype.div = function div(num) {
  27016. return this.divmod(num, 'div', false).div;
  27017. }; // Find `this` % `num`
  27018. BN.prototype.mod = function mod(num) {
  27019. return this.divmod(num, 'mod', false).mod;
  27020. };
  27021. BN.prototype.umod = function umod(num) {
  27022. return this.divmod(num, 'mod', true).mod;
  27023. }; // Find Round(`this` / `num`)
  27024. BN.prototype.divRound = function divRound(num) {
  27025. var dm = this.divmod(num); // Fast case - exact division
  27026. if (dm.mod.isZero()) return dm.div;
  27027. var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
  27028. var half = num.ushrn(1);
  27029. var r2 = num.andln(1);
  27030. var cmp = mod.cmp(half); // Round down
  27031. if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up
  27032. return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
  27033. };
  27034. BN.prototype.modrn = function modrn(num) {
  27035. var isNegNum = num < 0;
  27036. if (isNegNum) num = -num;
  27037. assert(num <= 0x3ffffff);
  27038. var p = (1 << 26) % num;
  27039. var acc = 0;
  27040. for (var i = this.length - 1; i >= 0; i--) {
  27041. acc = (p * acc + (this.words[i] | 0)) % num;
  27042. }
  27043. return isNegNum ? -acc : acc;
  27044. }; // WARNING: DEPRECATED
  27045. BN.prototype.modn = function modn(num) {
  27046. return this.modrn(num);
  27047. }; // In-place division by number
  27048. BN.prototype.idivn = function idivn(num) {
  27049. var isNegNum = num < 0;
  27050. if (isNegNum) num = -num;
  27051. assert(num <= 0x3ffffff);
  27052. var carry = 0;
  27053. for (var i = this.length - 1; i >= 0; i--) {
  27054. var w = (this.words[i] | 0) + carry * 0x4000000;
  27055. this.words[i] = w / num | 0;
  27056. carry = w % num;
  27057. }
  27058. this._strip();
  27059. return isNegNum ? this.ineg() : this;
  27060. };
  27061. BN.prototype.divn = function divn(num) {
  27062. return this.clone().idivn(num);
  27063. };
  27064. BN.prototype.egcd = function egcd(p) {
  27065. assert(p.negative === 0);
  27066. assert(!p.isZero());
  27067. var x = this;
  27068. var y = p.clone();
  27069. if (x.negative !== 0) {
  27070. x = x.umod(p);
  27071. } else {
  27072. x = x.clone();
  27073. } // A * x + B * y = x
  27074. var A = new BN(1);
  27075. var B = new BN(0); // C * x + D * y = y
  27076. var C = new BN(0);
  27077. var D = new BN(1);
  27078. var g = 0;
  27079. while (x.isEven() && y.isEven()) {
  27080. x.iushrn(1);
  27081. y.iushrn(1);
  27082. ++g;
  27083. }
  27084. var yp = y.clone();
  27085. var xp = x.clone();
  27086. while (!x.isZero()) {
  27087. for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  27088. ;
  27089. }
  27090. if (i > 0) {
  27091. x.iushrn(i);
  27092. while (i-- > 0) {
  27093. if (A.isOdd() || B.isOdd()) {
  27094. A.iadd(yp);
  27095. B.isub(xp);
  27096. }
  27097. A.iushrn(1);
  27098. B.iushrn(1);
  27099. }
  27100. }
  27101. for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  27102. ;
  27103. }
  27104. if (j > 0) {
  27105. y.iushrn(j);
  27106. while (j-- > 0) {
  27107. if (C.isOdd() || D.isOdd()) {
  27108. C.iadd(yp);
  27109. D.isub(xp);
  27110. }
  27111. C.iushrn(1);
  27112. D.iushrn(1);
  27113. }
  27114. }
  27115. if (x.cmp(y) >= 0) {
  27116. x.isub(y);
  27117. A.isub(C);
  27118. B.isub(D);
  27119. } else {
  27120. y.isub(x);
  27121. C.isub(A);
  27122. D.isub(B);
  27123. }
  27124. }
  27125. return {
  27126. a: C,
  27127. b: D,
  27128. gcd: y.iushln(g)
  27129. };
  27130. }; // This is reduced incarnation of the binary EEA
  27131. // above, designated to invert members of the
  27132. // _prime_ fields F(p) at a maximal speed
  27133. BN.prototype._invmp = function _invmp(p) {
  27134. assert(p.negative === 0);
  27135. assert(!p.isZero());
  27136. var a = this;
  27137. var b = p.clone();
  27138. if (a.negative !== 0) {
  27139. a = a.umod(p);
  27140. } else {
  27141. a = a.clone();
  27142. }
  27143. var x1 = new BN(1);
  27144. var x2 = new BN(0);
  27145. var delta = b.clone();
  27146. while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
  27147. for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1) {
  27148. ;
  27149. }
  27150. if (i > 0) {
  27151. a.iushrn(i);
  27152. while (i-- > 0) {
  27153. if (x1.isOdd()) {
  27154. x1.iadd(delta);
  27155. }
  27156. x1.iushrn(1);
  27157. }
  27158. }
  27159. for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1) {
  27160. ;
  27161. }
  27162. if (j > 0) {
  27163. b.iushrn(j);
  27164. while (j-- > 0) {
  27165. if (x2.isOdd()) {
  27166. x2.iadd(delta);
  27167. }
  27168. x2.iushrn(1);
  27169. }
  27170. }
  27171. if (a.cmp(b) >= 0) {
  27172. a.isub(b);
  27173. x1.isub(x2);
  27174. } else {
  27175. b.isub(a);
  27176. x2.isub(x1);
  27177. }
  27178. }
  27179. var res;
  27180. if (a.cmpn(1) === 0) {
  27181. res = x1;
  27182. } else {
  27183. res = x2;
  27184. }
  27185. if (res.cmpn(0) < 0) {
  27186. res.iadd(p);
  27187. }
  27188. return res;
  27189. };
  27190. BN.prototype.gcd = function gcd(num) {
  27191. if (this.isZero()) return num.abs();
  27192. if (num.isZero()) return this.abs();
  27193. var a = this.clone();
  27194. var b = num.clone();
  27195. a.negative = 0;
  27196. b.negative = 0; // Remove common factor of two
  27197. for (var shift = 0; a.isEven() && b.isEven(); shift++) {
  27198. a.iushrn(1);
  27199. b.iushrn(1);
  27200. }
  27201. do {
  27202. while (a.isEven()) {
  27203. a.iushrn(1);
  27204. }
  27205. while (b.isEven()) {
  27206. b.iushrn(1);
  27207. }
  27208. var r = a.cmp(b);
  27209. if (r < 0) {
  27210. // Swap `a` and `b` to make `a` always bigger than `b`
  27211. var t = a;
  27212. a = b;
  27213. b = t;
  27214. } else if (r === 0 || b.cmpn(1) === 0) {
  27215. break;
  27216. }
  27217. a.isub(b);
  27218. } while (true);
  27219. return b.iushln(shift);
  27220. }; // Invert number in the field F(num)
  27221. BN.prototype.invm = function invm(num) {
  27222. return this.egcd(num).a.umod(num);
  27223. };
  27224. BN.prototype.isEven = function isEven() {
  27225. return (this.words[0] & 1) === 0;
  27226. };
  27227. BN.prototype.isOdd = function isOdd() {
  27228. return (this.words[0] & 1) === 1;
  27229. }; // And first word and num
  27230. BN.prototype.andln = function andln(num) {
  27231. return this.words[0] & num;
  27232. }; // Increment at the bit position in-line
  27233. BN.prototype.bincn = function bincn(bit) {
  27234. assert(typeof bit === 'number');
  27235. var r = bit % 26;
  27236. var s = (bit - r) / 26;
  27237. var q = 1 << r; // Fast case: bit is much higher than all existing words
  27238. if (this.length <= s) {
  27239. this._expand(s + 1);
  27240. this.words[s] |= q;
  27241. return this;
  27242. } // Add bit and propagate, if needed
  27243. var carry = q;
  27244. for (var i = s; carry !== 0 && i < this.length; i++) {
  27245. var w = this.words[i] | 0;
  27246. w += carry;
  27247. carry = w >>> 26;
  27248. w &= 0x3ffffff;
  27249. this.words[i] = w;
  27250. }
  27251. if (carry !== 0) {
  27252. this.words[i] = carry;
  27253. this.length++;
  27254. }
  27255. return this;
  27256. };
  27257. BN.prototype.isZero = function isZero() {
  27258. return this.length === 1 && this.words[0] === 0;
  27259. };
  27260. BN.prototype.cmpn = function cmpn(num) {
  27261. var negative = num < 0;
  27262. if (this.negative !== 0 && !negative) return -1;
  27263. if (this.negative === 0 && negative) return 1;
  27264. this._strip();
  27265. var res;
  27266. if (this.length > 1) {
  27267. res = 1;
  27268. } else {
  27269. if (negative) {
  27270. num = -num;
  27271. }
  27272. assert(num <= 0x3ffffff, 'Number is too big');
  27273. var w = this.words[0] | 0;
  27274. res = w === num ? 0 : w < num ? -1 : 1;
  27275. }
  27276. if (this.negative !== 0) return -res | 0;
  27277. return res;
  27278. }; // Compare two numbers and return:
  27279. // 1 - if `this` > `num`
  27280. // 0 - if `this` == `num`
  27281. // -1 - if `this` < `num`
  27282. BN.prototype.cmp = function cmp(num) {
  27283. if (this.negative !== 0 && num.negative === 0) return -1;
  27284. if (this.negative === 0 && num.negative !== 0) return 1;
  27285. var res = this.ucmp(num);
  27286. if (this.negative !== 0) return -res | 0;
  27287. return res;
  27288. }; // Unsigned comparison
  27289. BN.prototype.ucmp = function ucmp(num) {
  27290. // At this point both numbers have the same sign
  27291. if (this.length > num.length) return 1;
  27292. if (this.length < num.length) return -1;
  27293. var res = 0;
  27294. for (var i = this.length - 1; i >= 0; i--) {
  27295. var a = this.words[i] | 0;
  27296. var b = num.words[i] | 0;
  27297. if (a === b) continue;
  27298. if (a < b) {
  27299. res = -1;
  27300. } else if (a > b) {
  27301. res = 1;
  27302. }
  27303. break;
  27304. }
  27305. return res;
  27306. };
  27307. BN.prototype.gtn = function gtn(num) {
  27308. return this.cmpn(num) === 1;
  27309. };
  27310. BN.prototype.gt = function gt(num) {
  27311. return this.cmp(num) === 1;
  27312. };
  27313. BN.prototype.gten = function gten(num) {
  27314. return this.cmpn(num) >= 0;
  27315. };
  27316. BN.prototype.gte = function gte(num) {
  27317. return this.cmp(num) >= 0;
  27318. };
  27319. BN.prototype.ltn = function ltn(num) {
  27320. return this.cmpn(num) === -1;
  27321. };
  27322. BN.prototype.lt = function lt(num) {
  27323. return this.cmp(num) === -1;
  27324. };
  27325. BN.prototype.lten = function lten(num) {
  27326. return this.cmpn(num) <= 0;
  27327. };
  27328. BN.prototype.lte = function lte(num) {
  27329. return this.cmp(num) <= 0;
  27330. };
  27331. BN.prototype.eqn = function eqn(num) {
  27332. return this.cmpn(num) === 0;
  27333. };
  27334. BN.prototype.eq = function eq(num) {
  27335. return this.cmp(num) === 0;
  27336. }; //
  27337. // A reduce context, could be using montgomery or something better, depending
  27338. // on the `m` itself.
  27339. //
  27340. BN.red = function red(num) {
  27341. return new Red(num);
  27342. };
  27343. BN.prototype.toRed = function toRed(ctx) {
  27344. assert(!this.red, 'Already a number in reduction context');
  27345. assert(this.negative === 0, 'red works only with positives');
  27346. return ctx.convertTo(this)._forceRed(ctx);
  27347. };
  27348. BN.prototype.fromRed = function fromRed() {
  27349. assert(this.red, 'fromRed works only with numbers in reduction context');
  27350. return this.red.convertFrom(this);
  27351. };
  27352. BN.prototype._forceRed = function _forceRed(ctx) {
  27353. this.red = ctx;
  27354. return this;
  27355. };
  27356. BN.prototype.forceRed = function forceRed(ctx) {
  27357. assert(!this.red, 'Already a number in reduction context');
  27358. return this._forceRed(ctx);
  27359. };
  27360. BN.prototype.redAdd = function redAdd(num) {
  27361. assert(this.red, 'redAdd works only with red numbers');
  27362. return this.red.add(this, num);
  27363. };
  27364. BN.prototype.redIAdd = function redIAdd(num) {
  27365. assert(this.red, 'redIAdd works only with red numbers');
  27366. return this.red.iadd(this, num);
  27367. };
  27368. BN.prototype.redSub = function redSub(num) {
  27369. assert(this.red, 'redSub works only with red numbers');
  27370. return this.red.sub(this, num);
  27371. };
  27372. BN.prototype.redISub = function redISub(num) {
  27373. assert(this.red, 'redISub works only with red numbers');
  27374. return this.red.isub(this, num);
  27375. };
  27376. BN.prototype.redShl = function redShl(num) {
  27377. assert(this.red, 'redShl works only with red numbers');
  27378. return this.red.shl(this, num);
  27379. };
  27380. BN.prototype.redMul = function redMul(num) {
  27381. assert(this.red, 'redMul works only with red numbers');
  27382. this.red._verify2(this, num);
  27383. return this.red.mul(this, num);
  27384. };
  27385. BN.prototype.redIMul = function redIMul(num) {
  27386. assert(this.red, 'redMul works only with red numbers');
  27387. this.red._verify2(this, num);
  27388. return this.red.imul(this, num);
  27389. };
  27390. BN.prototype.redSqr = function redSqr() {
  27391. assert(this.red, 'redSqr works only with red numbers');
  27392. this.red._verify1(this);
  27393. return this.red.sqr(this);
  27394. };
  27395. BN.prototype.redISqr = function redISqr() {
  27396. assert(this.red, 'redISqr works only with red numbers');
  27397. this.red._verify1(this);
  27398. return this.red.isqr(this);
  27399. }; // Square root over p
  27400. BN.prototype.redSqrt = function redSqrt() {
  27401. assert(this.red, 'redSqrt works only with red numbers');
  27402. this.red._verify1(this);
  27403. return this.red.sqrt(this);
  27404. };
  27405. BN.prototype.redInvm = function redInvm() {
  27406. assert(this.red, 'redInvm works only with red numbers');
  27407. this.red._verify1(this);
  27408. return this.red.invm(this);
  27409. }; // Return negative clone of `this` % `red modulo`
  27410. BN.prototype.redNeg = function redNeg() {
  27411. assert(this.red, 'redNeg works only with red numbers');
  27412. this.red._verify1(this);
  27413. return this.red.neg(this);
  27414. };
  27415. BN.prototype.redPow = function redPow(num) {
  27416. assert(this.red && !num.red, 'redPow(normalNum)');
  27417. this.red._verify1(this);
  27418. return this.red.pow(this, num);
  27419. }; // Prime numbers with efficient reduction
  27420. var primes = {
  27421. k256: null,
  27422. p224: null,
  27423. p192: null,
  27424. p25519: null
  27425. }; // Pseudo-Mersenne prime
  27426. function MPrime(name, p) {
  27427. // P = 2 ^ N - K
  27428. this.name = name;
  27429. this.p = new BN(p, 16);
  27430. this.n = this.p.bitLength();
  27431. this.k = new BN(1).iushln(this.n).isub(this.p);
  27432. this.tmp = this._tmp();
  27433. }
  27434. MPrime.prototype._tmp = function _tmp() {
  27435. var tmp = new BN(null);
  27436. tmp.words = new Array(Math.ceil(this.n / 13));
  27437. return tmp;
  27438. };
  27439. MPrime.prototype.ireduce = function ireduce(num) {
  27440. // Assumes that `num` is less than `P^2`
  27441. // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
  27442. var r = num;
  27443. var rlen;
  27444. do {
  27445. this.split(r, this.tmp);
  27446. r = this.imulK(r);
  27447. r = r.iadd(this.tmp);
  27448. rlen = r.bitLength();
  27449. } while (rlen > this.n);
  27450. var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
  27451. if (cmp === 0) {
  27452. r.words[0] = 0;
  27453. r.length = 1;
  27454. } else if (cmp > 0) {
  27455. r.isub(this.p);
  27456. } else {
  27457. if (r.strip !== undefined) {
  27458. // r is a BN v4 instance
  27459. r.strip();
  27460. } else {
  27461. // r is a BN v5 instance
  27462. r._strip();
  27463. }
  27464. }
  27465. return r;
  27466. };
  27467. MPrime.prototype.split = function split(input, out) {
  27468. input.iushrn(this.n, 0, out);
  27469. };
  27470. MPrime.prototype.imulK = function imulK(num) {
  27471. return num.imul(this.k);
  27472. };
  27473. function K256() {
  27474. MPrime.call(this, 'k256', 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
  27475. }
  27476. inherits(K256, MPrime);
  27477. K256.prototype.split = function split(input, output) {
  27478. // 256 = 9 * 26 + 22
  27479. var mask = 0x3fffff;
  27480. var outLen = Math.min(input.length, 9);
  27481. for (var i = 0; i < outLen; i++) {
  27482. output.words[i] = input.words[i];
  27483. }
  27484. output.length = outLen;
  27485. if (input.length <= 9) {
  27486. input.words[0] = 0;
  27487. input.length = 1;
  27488. return;
  27489. } // Shift by 9 limbs
  27490. var prev = input.words[9];
  27491. output.words[output.length++] = prev & mask;
  27492. for (i = 10; i < input.length; i++) {
  27493. var next = input.words[i] | 0;
  27494. input.words[i - 10] = (next & mask) << 4 | prev >>> 22;
  27495. prev = next;
  27496. }
  27497. prev >>>= 22;
  27498. input.words[i - 10] = prev;
  27499. if (prev === 0 && input.length > 10) {
  27500. input.length -= 10;
  27501. } else {
  27502. input.length -= 9;
  27503. }
  27504. };
  27505. K256.prototype.imulK = function imulK(num) {
  27506. // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
  27507. num.words[num.length] = 0;
  27508. num.words[num.length + 1] = 0;
  27509. num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
  27510. var lo = 0;
  27511. for (var i = 0; i < num.length; i++) {
  27512. var w = num.words[i] | 0;
  27513. lo += w * 0x3d1;
  27514. num.words[i] = lo & 0x3ffffff;
  27515. lo = w * 0x40 + (lo / 0x4000000 | 0);
  27516. } // Fast length reduction
  27517. if (num.words[num.length - 1] === 0) {
  27518. num.length--;
  27519. if (num.words[num.length - 1] === 0) {
  27520. num.length--;
  27521. }
  27522. }
  27523. return num;
  27524. };
  27525. function P224() {
  27526. MPrime.call(this, 'p224', 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
  27527. }
  27528. inherits(P224, MPrime);
  27529. function P192() {
  27530. MPrime.call(this, 'p192', 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
  27531. }
  27532. inherits(P192, MPrime);
  27533. function P25519() {
  27534. // 2 ^ 255 - 19
  27535. MPrime.call(this, '25519', '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
  27536. }
  27537. inherits(P25519, MPrime);
  27538. P25519.prototype.imulK = function imulK(num) {
  27539. // K = 0x13
  27540. var carry = 0;
  27541. for (var i = 0; i < num.length; i++) {
  27542. var hi = (num.words[i] | 0) * 0x13 + carry;
  27543. var lo = hi & 0x3ffffff;
  27544. hi >>>= 26;
  27545. num.words[i] = lo;
  27546. carry = hi;
  27547. }
  27548. if (carry !== 0) {
  27549. num.words[num.length++] = carry;
  27550. }
  27551. return num;
  27552. }; // Exported mostly for testing purposes, use plain name instead
  27553. BN._prime = function prime(name) {
  27554. // Cached version of prime
  27555. if (primes[name]) return primes[name];
  27556. var prime;
  27557. if (name === 'k256') {
  27558. prime = new K256();
  27559. } else if (name === 'p224') {
  27560. prime = new P224();
  27561. } else if (name === 'p192') {
  27562. prime = new P192();
  27563. } else if (name === 'p25519') {
  27564. prime = new P25519();
  27565. } else {
  27566. throw new Error('Unknown prime ' + name);
  27567. }
  27568. primes[name] = prime;
  27569. return prime;
  27570. }; //
  27571. // Base reduction engine
  27572. //
  27573. function Red(m) {
  27574. if (typeof m === 'string') {
  27575. var prime = BN._prime(m);
  27576. this.m = prime.p;
  27577. this.prime = prime;
  27578. } else {
  27579. assert(m.gtn(1), 'modulus must be greater than 1');
  27580. this.m = m;
  27581. this.prime = null;
  27582. }
  27583. }
  27584. Red.prototype._verify1 = function _verify1(a) {
  27585. assert(a.negative === 0, 'red works only with positives');
  27586. assert(a.red, 'red works only with red numbers');
  27587. };
  27588. Red.prototype._verify2 = function _verify2(a, b) {
  27589. assert((a.negative | b.negative) === 0, 'red works only with positives');
  27590. assert(a.red && a.red === b.red, 'red works only with red numbers');
  27591. };
  27592. Red.prototype.imod = function imod(a) {
  27593. if (this.prime) return this.prime.ireduce(a)._forceRed(this);
  27594. move(a, a.umod(this.m)._forceRed(this));
  27595. return a;
  27596. };
  27597. Red.prototype.neg = function neg(a) {
  27598. if (a.isZero()) {
  27599. return a.clone();
  27600. }
  27601. return this.m.sub(a)._forceRed(this);
  27602. };
  27603. Red.prototype.add = function add(a, b) {
  27604. this._verify2(a, b);
  27605. var res = a.add(b);
  27606. if (res.cmp(this.m) >= 0) {
  27607. res.isub(this.m);
  27608. }
  27609. return res._forceRed(this);
  27610. };
  27611. Red.prototype.iadd = function iadd(a, b) {
  27612. this._verify2(a, b);
  27613. var res = a.iadd(b);
  27614. if (res.cmp(this.m) >= 0) {
  27615. res.isub(this.m);
  27616. }
  27617. return res;
  27618. };
  27619. Red.prototype.sub = function sub(a, b) {
  27620. this._verify2(a, b);
  27621. var res = a.sub(b);
  27622. if (res.cmpn(0) < 0) {
  27623. res.iadd(this.m);
  27624. }
  27625. return res._forceRed(this);
  27626. };
  27627. Red.prototype.isub = function isub(a, b) {
  27628. this._verify2(a, b);
  27629. var res = a.isub(b);
  27630. if (res.cmpn(0) < 0) {
  27631. res.iadd(this.m);
  27632. }
  27633. return res;
  27634. };
  27635. Red.prototype.shl = function shl(a, num) {
  27636. this._verify1(a);
  27637. return this.imod(a.ushln(num));
  27638. };
  27639. Red.prototype.imul = function imul(a, b) {
  27640. this._verify2(a, b);
  27641. return this.imod(a.imul(b));
  27642. };
  27643. Red.prototype.mul = function mul(a, b) {
  27644. this._verify2(a, b);
  27645. return this.imod(a.mul(b));
  27646. };
  27647. Red.prototype.isqr = function isqr(a) {
  27648. return this.imul(a, a.clone());
  27649. };
  27650. Red.prototype.sqr = function sqr(a) {
  27651. return this.mul(a, a);
  27652. };
  27653. Red.prototype.sqrt = function sqrt(a) {
  27654. if (a.isZero()) return a.clone();
  27655. var mod3 = this.m.andln(3);
  27656. assert(mod3 % 2 === 1); // Fast case
  27657. if (mod3 === 3) {
  27658. var pow = this.m.add(new BN(1)).iushrn(2);
  27659. return this.pow(a, pow);
  27660. } // Tonelli-Shanks algorithm (Totally unoptimized and slow)
  27661. //
  27662. // Find Q and S, that Q * 2 ^ S = (P - 1)
  27663. var q = this.m.subn(1);
  27664. var s = 0;
  27665. while (!q.isZero() && q.andln(1) === 0) {
  27666. s++;
  27667. q.iushrn(1);
  27668. }
  27669. assert(!q.isZero());
  27670. var one = new BN(1).toRed(this);
  27671. var nOne = one.redNeg(); // Find quadratic non-residue
  27672. // NOTE: Max is such because of generalized Riemann hypothesis.
  27673. var lpow = this.m.subn(1).iushrn(1);
  27674. var z = this.m.bitLength();
  27675. z = new BN(2 * z * z).toRed(this);
  27676. while (this.pow(z, lpow).cmp(nOne) !== 0) {
  27677. z.redIAdd(nOne);
  27678. }
  27679. var c = this.pow(z, q);
  27680. var r = this.pow(a, q.addn(1).iushrn(1));
  27681. var t = this.pow(a, q);
  27682. var m = s;
  27683. while (t.cmp(one) !== 0) {
  27684. var tmp = t;
  27685. for (var i = 0; tmp.cmp(one) !== 0; i++) {
  27686. tmp = tmp.redSqr();
  27687. }
  27688. assert(i < m);
  27689. var b = this.pow(c, new BN(1).iushln(m - i - 1));
  27690. r = r.redMul(b);
  27691. c = b.redSqr();
  27692. t = t.redMul(c);
  27693. m = i;
  27694. }
  27695. return r;
  27696. };
  27697. Red.prototype.invm = function invm(a) {
  27698. var inv = a._invmp(this.m);
  27699. if (inv.negative !== 0) {
  27700. inv.negative = 0;
  27701. return this.imod(inv).redNeg();
  27702. } else {
  27703. return this.imod(inv);
  27704. }
  27705. };
  27706. Red.prototype.pow = function pow(a, num) {
  27707. if (num.isZero()) return new BN(1).toRed(this);
  27708. if (num.cmpn(1) === 0) return a.clone();
  27709. var windowSize = 4;
  27710. var wnd = new Array(1 << windowSize);
  27711. wnd[0] = new BN(1).toRed(this);
  27712. wnd[1] = a;
  27713. for (var i = 2; i < wnd.length; i++) {
  27714. wnd[i] = this.mul(wnd[i - 1], a);
  27715. }
  27716. var res = wnd[0];
  27717. var current = 0;
  27718. var currentLen = 0;
  27719. var start = num.bitLength() % 26;
  27720. if (start === 0) {
  27721. start = 26;
  27722. }
  27723. for (i = num.length - 1; i >= 0; i--) {
  27724. var word = num.words[i];
  27725. for (var j = start - 1; j >= 0; j--) {
  27726. var bit = word >> j & 1;
  27727. if (res !== wnd[0]) {
  27728. res = this.sqr(res);
  27729. }
  27730. if (bit === 0 && current === 0) {
  27731. currentLen = 0;
  27732. continue;
  27733. }
  27734. current <<= 1;
  27735. current |= bit;
  27736. currentLen++;
  27737. if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
  27738. res = this.mul(res, wnd[current]);
  27739. currentLen = 0;
  27740. current = 0;
  27741. }
  27742. start = 26;
  27743. }
  27744. return res;
  27745. };
  27746. Red.prototype.convertTo = function convertTo(num) {
  27747. var r = num.umod(this.m);
  27748. return r === num ? r.clone() : r;
  27749. };
  27750. Red.prototype.convertFrom = function convertFrom(num) {
  27751. var res = num.clone();
  27752. res.red = null;
  27753. return res;
  27754. }; //
  27755. // Montgomery method engine
  27756. //
  27757. BN.mont = function mont(num) {
  27758. return new Mont(num);
  27759. };
  27760. function Mont(m) {
  27761. Red.call(this, m);
  27762. this.shift = this.m.bitLength();
  27763. if (this.shift % 26 !== 0) {
  27764. this.shift += 26 - this.shift % 26;
  27765. }
  27766. this.r = new BN(1).iushln(this.shift);
  27767. this.r2 = this.imod(this.r.sqr());
  27768. this.rinv = this.r._invmp(this.m);
  27769. this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
  27770. this.minv = this.minv.umod(this.r);
  27771. this.minv = this.r.sub(this.minv);
  27772. }
  27773. inherits(Mont, Red);
  27774. Mont.prototype.convertTo = function convertTo(num) {
  27775. return this.imod(num.ushln(this.shift));
  27776. };
  27777. Mont.prototype.convertFrom = function convertFrom(num) {
  27778. var r = this.imod(num.mul(this.rinv));
  27779. r.red = null;
  27780. return r;
  27781. };
  27782. Mont.prototype.imul = function imul(a, b) {
  27783. if (a.isZero() || b.isZero()) {
  27784. a.words[0] = 0;
  27785. a.length = 1;
  27786. return a;
  27787. }
  27788. var t = a.imul(b);
  27789. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  27790. var u = t.isub(c).iushrn(this.shift);
  27791. var res = u;
  27792. if (u.cmp(this.m) >= 0) {
  27793. res = u.isub(this.m);
  27794. } else if (u.cmpn(0) < 0) {
  27795. res = u.iadd(this.m);
  27796. }
  27797. return res._forceRed(this);
  27798. };
  27799. Mont.prototype.mul = function mul(a, b) {
  27800. if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
  27801. var t = a.mul(b);
  27802. var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
  27803. var u = t.isub(c).iushrn(this.shift);
  27804. var res = u;
  27805. if (u.cmp(this.m) >= 0) {
  27806. res = u.isub(this.m);
  27807. } else if (u.cmpn(0) < 0) {
  27808. res = u.iadd(this.m);
  27809. }
  27810. return res._forceRed(this);
  27811. };
  27812. Mont.prototype.invm = function invm(a) {
  27813. // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
  27814. var res = this.imod(a._invmp(this.m).mul(this.r2));
  27815. return res._forceRed(this);
  27816. };
  27817. })( false || module, this);
  27818. /***/ }),
  27819. /***/ 7179:
  27820. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  27821. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  27822. var r;
  27823. module.exports = function rand(len) {
  27824. if (!r) r = new Rand(null);
  27825. return r.generate(len);
  27826. };
  27827. function Rand(rand) {
  27828. this.rand = rand;
  27829. }
  27830. module.exports.Rand = Rand;
  27831. Rand.prototype.generate = function generate(len) {
  27832. return this._rand(len);
  27833. }; // Emulate crypto API using randy
  27834. Rand.prototype._rand = function _rand(n) {
  27835. if (this.rand.getBytes) return this.rand.getBytes(n);
  27836. var res = new Uint8Array(n);
  27837. for (var i = 0; i < res.length; i++) {
  27838. res[i] = this.rand.getByte();
  27839. }
  27840. return res;
  27841. };
  27842. if ((typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object') {
  27843. if (self.crypto && self.crypto.getRandomValues) {
  27844. // Modern browsers
  27845. Rand.prototype._rand = function _rand(n) {
  27846. var arr = new Uint8Array(n);
  27847. self.crypto.getRandomValues(arr);
  27848. return arr;
  27849. };
  27850. } else if (self.msCrypto && self.msCrypto.getRandomValues) {
  27851. // IE
  27852. Rand.prototype._rand = function _rand(n) {
  27853. var arr = new Uint8Array(n);
  27854. self.msCrypto.getRandomValues(arr);
  27855. return arr;
  27856. }; // Safari's WebWorkers do not have `crypto`
  27857. } else if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') {
  27858. // Old junk
  27859. Rand.prototype._rand = function () {
  27860. throw new Error('Not implemented yet');
  27861. };
  27862. }
  27863. } else {
  27864. // Node.js or Web worker with no crypto support
  27865. try {
  27866. var crypto = __webpack_require__(9214);
  27867. if (typeof crypto.randomBytes !== 'function') throw new Error('Not supported');
  27868. Rand.prototype._rand = function _rand(n) {
  27869. return crypto.randomBytes(n);
  27870. };
  27871. } catch (e) {}
  27872. }
  27873. /***/ }),
  27874. /***/ 7463:
  27875. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  27876. // based on the aes implimentation in triple sec
  27877. // https://github.com/keybase/triplesec
  27878. // which is in turn based on the one from crypto-js
  27879. // https://code.google.com/p/crypto-js/
  27880. var Buffer = (__webpack_require__(9047).Buffer);
  27881. function asUInt32Array(buf) {
  27882. if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf);
  27883. var len = buf.length / 4 | 0;
  27884. var out = new Array(len);
  27885. for (var i = 0; i < len; i++) {
  27886. out[i] = buf.readUInt32BE(i * 4);
  27887. }
  27888. return out;
  27889. }
  27890. function scrubVec(v) {
  27891. for (var i = 0; i < v.length; v++) {
  27892. v[i] = 0;
  27893. }
  27894. }
  27895. function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) {
  27896. var SUB_MIX0 = SUB_MIX[0];
  27897. var SUB_MIX1 = SUB_MIX[1];
  27898. var SUB_MIX2 = SUB_MIX[2];
  27899. var SUB_MIX3 = SUB_MIX[3];
  27900. var s0 = M[0] ^ keySchedule[0];
  27901. var s1 = M[1] ^ keySchedule[1];
  27902. var s2 = M[2] ^ keySchedule[2];
  27903. var s3 = M[3] ^ keySchedule[3];
  27904. var t0, t1, t2, t3;
  27905. var ksRow = 4;
  27906. for (var round = 1; round < nRounds; round++) {
  27907. t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 0xff] ^ SUB_MIX2[s2 >>> 8 & 0xff] ^ SUB_MIX3[s3 & 0xff] ^ keySchedule[ksRow++];
  27908. t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 0xff] ^ SUB_MIX2[s3 >>> 8 & 0xff] ^ SUB_MIX3[s0 & 0xff] ^ keySchedule[ksRow++];
  27909. t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 0xff] ^ SUB_MIX2[s0 >>> 8 & 0xff] ^ SUB_MIX3[s1 & 0xff] ^ keySchedule[ksRow++];
  27910. t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 0xff] ^ SUB_MIX2[s1 >>> 8 & 0xff] ^ SUB_MIX3[s2 & 0xff] ^ keySchedule[ksRow++];
  27911. s0 = t0;
  27912. s1 = t1;
  27913. s2 = t2;
  27914. s3 = t3;
  27915. }
  27916. t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 0xff] << 16 | SBOX[s2 >>> 8 & 0xff] << 8 | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++];
  27917. t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 0xff] << 16 | SBOX[s3 >>> 8 & 0xff] << 8 | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++];
  27918. t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 0xff] << 16 | SBOX[s0 >>> 8 & 0xff] << 8 | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++];
  27919. t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 0xff] << 16 | SBOX[s1 >>> 8 & 0xff] << 8 | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++];
  27920. t0 = t0 >>> 0;
  27921. t1 = t1 >>> 0;
  27922. t2 = t2 >>> 0;
  27923. t3 = t3 >>> 0;
  27924. return [t0, t1, t2, t3];
  27925. } // AES constants
  27926. var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
  27927. var G = function () {
  27928. // Compute double table
  27929. var d = new Array(256);
  27930. for (var j = 0; j < 256; j++) {
  27931. if (j < 128) {
  27932. d[j] = j << 1;
  27933. } else {
  27934. d[j] = j << 1 ^ 0x11b;
  27935. }
  27936. }
  27937. var SBOX = [];
  27938. var INV_SBOX = [];
  27939. var SUB_MIX = [[], [], [], []];
  27940. var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8)
  27941. var x = 0;
  27942. var xi = 0;
  27943. for (var i = 0; i < 256; ++i) {
  27944. // Compute sbox
  27945. var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4;
  27946. sx = sx >>> 8 ^ sx & 0xff ^ 0x63;
  27947. SBOX[x] = sx;
  27948. INV_SBOX[sx] = x; // Compute multiplication
  27949. var x2 = d[x];
  27950. var x4 = d[x2];
  27951. var x8 = d[x4]; // Compute sub bytes, mix columns tables
  27952. var t = d[sx] * 0x101 ^ sx * 0x1010100;
  27953. SUB_MIX[0][x] = t << 24 | t >>> 8;
  27954. SUB_MIX[1][x] = t << 16 | t >>> 16;
  27955. SUB_MIX[2][x] = t << 8 | t >>> 24;
  27956. SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables
  27957. t = x8 * 0x1010101 ^ x4 * 0x10001 ^ x2 * 0x101 ^ x * 0x1010100;
  27958. INV_SUB_MIX[0][sx] = t << 24 | t >>> 8;
  27959. INV_SUB_MIX[1][sx] = t << 16 | t >>> 16;
  27960. INV_SUB_MIX[2][sx] = t << 8 | t >>> 24;
  27961. INV_SUB_MIX[3][sx] = t;
  27962. if (x === 0) {
  27963. x = xi = 1;
  27964. } else {
  27965. x = x2 ^ d[d[d[x8 ^ x2]]];
  27966. xi ^= d[d[xi]];
  27967. }
  27968. }
  27969. return {
  27970. SBOX: SBOX,
  27971. INV_SBOX: INV_SBOX,
  27972. SUB_MIX: SUB_MIX,
  27973. INV_SUB_MIX: INV_SUB_MIX
  27974. };
  27975. }();
  27976. function AES(key) {
  27977. this._key = asUInt32Array(key);
  27978. this._reset();
  27979. }
  27980. AES.blockSize = 4 * 4;
  27981. AES.keySize = 256 / 8;
  27982. AES.prototype.blockSize = AES.blockSize;
  27983. AES.prototype.keySize = AES.keySize;
  27984. AES.prototype._reset = function () {
  27985. var keyWords = this._key;
  27986. var keySize = keyWords.length;
  27987. var nRounds = keySize + 6;
  27988. var ksRows = (nRounds + 1) * 4;
  27989. var keySchedule = [];
  27990. for (var k = 0; k < keySize; k++) {
  27991. keySchedule[k] = keyWords[k];
  27992. }
  27993. for (k = keySize; k < ksRows; k++) {
  27994. var t = keySchedule[k - 1];
  27995. if (k % keySize === 0) {
  27996. t = t << 8 | t >>> 24;
  27997. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  27998. t ^= RCON[k / keySize | 0] << 24;
  27999. } else if (keySize > 6 && k % keySize === 4) {
  28000. t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 0xff] << 16 | G.SBOX[t >>> 8 & 0xff] << 8 | G.SBOX[t & 0xff];
  28001. }
  28002. keySchedule[k] = keySchedule[k - keySize] ^ t;
  28003. }
  28004. var invKeySchedule = [];
  28005. for (var ik = 0; ik < ksRows; ik++) {
  28006. var ksR = ksRows - ik;
  28007. var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)];
  28008. if (ik < 4 || ksR <= 4) {
  28009. invKeySchedule[ik] = tt;
  28010. } else {
  28011. invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 0xff]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 0xff]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 0xff]];
  28012. }
  28013. }
  28014. this._nRounds = nRounds;
  28015. this._keySchedule = keySchedule;
  28016. this._invKeySchedule = invKeySchedule;
  28017. };
  28018. AES.prototype.encryptBlockRaw = function (M) {
  28019. M = asUInt32Array(M);
  28020. return cryptBlock(M, this._keySchedule, G.SUB_MIX, G.SBOX, this._nRounds);
  28021. };
  28022. AES.prototype.encryptBlock = function (M) {
  28023. var out = this.encryptBlockRaw(M);
  28024. var buf = Buffer.allocUnsafe(16);
  28025. buf.writeUInt32BE(out[0], 0);
  28026. buf.writeUInt32BE(out[1], 4);
  28027. buf.writeUInt32BE(out[2], 8);
  28028. buf.writeUInt32BE(out[3], 12);
  28029. return buf;
  28030. };
  28031. AES.prototype.decryptBlock = function (M) {
  28032. M = asUInt32Array(M); // swap
  28033. var m1 = M[1];
  28034. M[1] = M[3];
  28035. M[3] = m1;
  28036. var out = cryptBlock(M, this._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, this._nRounds);
  28037. var buf = Buffer.allocUnsafe(16);
  28038. buf.writeUInt32BE(out[0], 0);
  28039. buf.writeUInt32BE(out[3], 4);
  28040. buf.writeUInt32BE(out[2], 8);
  28041. buf.writeUInt32BE(out[1], 12);
  28042. return buf;
  28043. };
  28044. AES.prototype.scrub = function () {
  28045. scrubVec(this._keySchedule);
  28046. scrubVec(this._invKeySchedule);
  28047. scrubVec(this._key);
  28048. };
  28049. module.exports.AES = AES;
  28050. /***/ }),
  28051. /***/ 3499:
  28052. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28053. var aes = __webpack_require__(7463);
  28054. var Buffer = (__webpack_require__(9047).Buffer);
  28055. var Transform = __webpack_require__(8842);
  28056. var inherits = __webpack_require__(376);
  28057. var GHASH = __webpack_require__(1225);
  28058. var xor = __webpack_require__(5176);
  28059. var incr32 = __webpack_require__(4001);
  28060. function xorTest(a, b) {
  28061. var out = 0;
  28062. if (a.length !== b.length) out++;
  28063. var len = Math.min(a.length, b.length);
  28064. for (var i = 0; i < len; ++i) {
  28065. out += a[i] ^ b[i];
  28066. }
  28067. return out;
  28068. }
  28069. function calcIv(self, iv, ck) {
  28070. if (iv.length === 12) {
  28071. self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]);
  28072. return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]);
  28073. }
  28074. var ghash = new GHASH(ck);
  28075. var len = iv.length;
  28076. var toPad = len % 16;
  28077. ghash.update(iv);
  28078. if (toPad) {
  28079. toPad = 16 - toPad;
  28080. ghash.update(Buffer.alloc(toPad, 0));
  28081. }
  28082. ghash.update(Buffer.alloc(8, 0));
  28083. var ivBits = len * 8;
  28084. var tail = Buffer.alloc(8);
  28085. tail.writeUIntBE(ivBits, 0, 8);
  28086. ghash.update(tail);
  28087. self._finID = ghash.state;
  28088. var out = Buffer.from(self._finID);
  28089. incr32(out);
  28090. return out;
  28091. }
  28092. function StreamCipher(mode, key, iv, decrypt) {
  28093. Transform.call(this);
  28094. var h = Buffer.alloc(4, 0);
  28095. this._cipher = new aes.AES(key);
  28096. var ck = this._cipher.encryptBlock(h);
  28097. this._ghash = new GHASH(ck);
  28098. iv = calcIv(this, iv, ck);
  28099. this._prev = Buffer.from(iv);
  28100. this._cache = Buffer.allocUnsafe(0);
  28101. this._secCache = Buffer.allocUnsafe(0);
  28102. this._decrypt = decrypt;
  28103. this._alen = 0;
  28104. this._len = 0;
  28105. this._mode = mode;
  28106. this._authTag = null;
  28107. this._called = false;
  28108. }
  28109. inherits(StreamCipher, Transform);
  28110. StreamCipher.prototype._update = function (chunk) {
  28111. if (!this._called && this._alen) {
  28112. var rump = 16 - this._alen % 16;
  28113. if (rump < 16) {
  28114. rump = Buffer.alloc(rump, 0);
  28115. this._ghash.update(rump);
  28116. }
  28117. }
  28118. this._called = true;
  28119. var out = this._mode.encrypt(this, chunk);
  28120. if (this._decrypt) {
  28121. this._ghash.update(chunk);
  28122. } else {
  28123. this._ghash.update(out);
  28124. }
  28125. this._len += chunk.length;
  28126. return out;
  28127. };
  28128. StreamCipher.prototype._final = function () {
  28129. if (this._decrypt && !this._authTag) throw new Error('Unsupported state or unable to authenticate data');
  28130. var tag = xor(this._ghash["final"](this._alen * 8, this._len * 8), this._cipher.encryptBlock(this._finID));
  28131. if (this._decrypt && xorTest(tag, this._authTag)) throw new Error('Unsupported state or unable to authenticate data');
  28132. this._authTag = tag;
  28133. this._cipher.scrub();
  28134. };
  28135. StreamCipher.prototype.getAuthTag = function getAuthTag() {
  28136. if (this._decrypt || !Buffer.isBuffer(this._authTag)) throw new Error('Attempting to get auth tag in unsupported state');
  28137. return this._authTag;
  28138. };
  28139. StreamCipher.prototype.setAuthTag = function setAuthTag(tag) {
  28140. if (!this._decrypt) throw new Error('Attempting to set auth tag in unsupported state');
  28141. this._authTag = tag;
  28142. };
  28143. StreamCipher.prototype.setAAD = function setAAD(buf) {
  28144. if (this._called) throw new Error('Attempting to set AAD in unsupported state');
  28145. this._ghash.update(buf);
  28146. this._alen += buf.length;
  28147. };
  28148. module.exports = StreamCipher;
  28149. /***/ }),
  28150. /***/ 4881:
  28151. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28152. var ciphers = __webpack_require__(8613);
  28153. var deciphers = __webpack_require__(7909);
  28154. var modes = __webpack_require__(4946);
  28155. function getCiphers() {
  28156. return Object.keys(modes);
  28157. }
  28158. exports.createCipher = exports.Cipher = ciphers.createCipher;
  28159. exports.createCipheriv = exports.Cipheriv = ciphers.createCipheriv;
  28160. exports.createDecipher = exports.Decipher = deciphers.createDecipher;
  28161. exports.createDecipheriv = exports.Decipheriv = deciphers.createDecipheriv;
  28162. exports.listCiphers = exports.getCiphers = getCiphers;
  28163. /***/ }),
  28164. /***/ 7909:
  28165. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28166. var AuthCipher = __webpack_require__(3499);
  28167. var Buffer = (__webpack_require__(9047).Buffer);
  28168. var MODES = __webpack_require__(6572);
  28169. var StreamCipher = __webpack_require__(7188);
  28170. var Transform = __webpack_require__(8842);
  28171. var aes = __webpack_require__(7463);
  28172. var ebtk = __webpack_require__(1248);
  28173. var inherits = __webpack_require__(376);
  28174. function Decipher(mode, key, iv) {
  28175. Transform.call(this);
  28176. this._cache = new Splitter();
  28177. this._last = void 0;
  28178. this._cipher = new aes.AES(key);
  28179. this._prev = Buffer.from(iv);
  28180. this._mode = mode;
  28181. this._autopadding = true;
  28182. }
  28183. inherits(Decipher, Transform);
  28184. Decipher.prototype._update = function (data) {
  28185. this._cache.add(data);
  28186. var chunk;
  28187. var thing;
  28188. var out = [];
  28189. while (chunk = this._cache.get(this._autopadding)) {
  28190. thing = this._mode.decrypt(this, chunk);
  28191. out.push(thing);
  28192. }
  28193. return Buffer.concat(out);
  28194. };
  28195. Decipher.prototype._final = function () {
  28196. var chunk = this._cache.flush();
  28197. if (this._autopadding) {
  28198. return unpad(this._mode.decrypt(this, chunk));
  28199. } else if (chunk) {
  28200. throw new Error('data not multiple of block length');
  28201. }
  28202. };
  28203. Decipher.prototype.setAutoPadding = function (setTo) {
  28204. this._autopadding = !!setTo;
  28205. return this;
  28206. };
  28207. function Splitter() {
  28208. this.cache = Buffer.allocUnsafe(0);
  28209. }
  28210. Splitter.prototype.add = function (data) {
  28211. this.cache = Buffer.concat([this.cache, data]);
  28212. };
  28213. Splitter.prototype.get = function (autoPadding) {
  28214. var out;
  28215. if (autoPadding) {
  28216. if (this.cache.length > 16) {
  28217. out = this.cache.slice(0, 16);
  28218. this.cache = this.cache.slice(16);
  28219. return out;
  28220. }
  28221. } else {
  28222. if (this.cache.length >= 16) {
  28223. out = this.cache.slice(0, 16);
  28224. this.cache = this.cache.slice(16);
  28225. return out;
  28226. }
  28227. }
  28228. return null;
  28229. };
  28230. Splitter.prototype.flush = function () {
  28231. if (this.cache.length) return this.cache;
  28232. };
  28233. function unpad(last) {
  28234. var padded = last[15];
  28235. if (padded < 1 || padded > 16) {
  28236. throw new Error('unable to decrypt data');
  28237. }
  28238. var i = -1;
  28239. while (++i < padded) {
  28240. if (last[i + (16 - padded)] !== padded) {
  28241. throw new Error('unable to decrypt data');
  28242. }
  28243. }
  28244. if (padded === 16) return;
  28245. return last.slice(0, 16 - padded);
  28246. }
  28247. function createDecipheriv(suite, password, iv) {
  28248. var config = MODES[suite.toLowerCase()];
  28249. if (!config) throw new TypeError('invalid suite type');
  28250. if (typeof iv === 'string') iv = Buffer.from(iv);
  28251. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  28252. if (typeof password === 'string') password = Buffer.from(password);
  28253. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  28254. if (config.type === 'stream') {
  28255. return new StreamCipher(config.module, password, iv, true);
  28256. } else if (config.type === 'auth') {
  28257. return new AuthCipher(config.module, password, iv, true);
  28258. }
  28259. return new Decipher(config.module, password, iv);
  28260. }
  28261. function createDecipher(suite, password) {
  28262. var config = MODES[suite.toLowerCase()];
  28263. if (!config) throw new TypeError('invalid suite type');
  28264. var keys = ebtk(password, false, config.key, config.iv);
  28265. return createDecipheriv(suite, keys.key, keys.iv);
  28266. }
  28267. exports.createDecipher = createDecipher;
  28268. exports.createDecipheriv = createDecipheriv;
  28269. /***/ }),
  28270. /***/ 8613:
  28271. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28272. var MODES = __webpack_require__(6572);
  28273. var AuthCipher = __webpack_require__(3499);
  28274. var Buffer = (__webpack_require__(9047).Buffer);
  28275. var StreamCipher = __webpack_require__(7188);
  28276. var Transform = __webpack_require__(8842);
  28277. var aes = __webpack_require__(7463);
  28278. var ebtk = __webpack_require__(1248);
  28279. var inherits = __webpack_require__(376);
  28280. function Cipher(mode, key, iv) {
  28281. Transform.call(this);
  28282. this._cache = new Splitter();
  28283. this._cipher = new aes.AES(key);
  28284. this._prev = Buffer.from(iv);
  28285. this._mode = mode;
  28286. this._autopadding = true;
  28287. }
  28288. inherits(Cipher, Transform);
  28289. Cipher.prototype._update = function (data) {
  28290. this._cache.add(data);
  28291. var chunk;
  28292. var thing;
  28293. var out = [];
  28294. while (chunk = this._cache.get()) {
  28295. thing = this._mode.encrypt(this, chunk);
  28296. out.push(thing);
  28297. }
  28298. return Buffer.concat(out);
  28299. };
  28300. var PADDING = Buffer.alloc(16, 0x10);
  28301. Cipher.prototype._final = function () {
  28302. var chunk = this._cache.flush();
  28303. if (this._autopadding) {
  28304. chunk = this._mode.encrypt(this, chunk);
  28305. this._cipher.scrub();
  28306. return chunk;
  28307. }
  28308. if (!chunk.equals(PADDING)) {
  28309. this._cipher.scrub();
  28310. throw new Error('data not multiple of block length');
  28311. }
  28312. };
  28313. Cipher.prototype.setAutoPadding = function (setTo) {
  28314. this._autopadding = !!setTo;
  28315. return this;
  28316. };
  28317. function Splitter() {
  28318. this.cache = Buffer.allocUnsafe(0);
  28319. }
  28320. Splitter.prototype.add = function (data) {
  28321. this.cache = Buffer.concat([this.cache, data]);
  28322. };
  28323. Splitter.prototype.get = function () {
  28324. if (this.cache.length > 15) {
  28325. var out = this.cache.slice(0, 16);
  28326. this.cache = this.cache.slice(16);
  28327. return out;
  28328. }
  28329. return null;
  28330. };
  28331. Splitter.prototype.flush = function () {
  28332. var len = 16 - this.cache.length;
  28333. var padBuff = Buffer.allocUnsafe(len);
  28334. var i = -1;
  28335. while (++i < len) {
  28336. padBuff.writeUInt8(len, i);
  28337. }
  28338. return Buffer.concat([this.cache, padBuff]);
  28339. };
  28340. function createCipheriv(suite, password, iv) {
  28341. var config = MODES[suite.toLowerCase()];
  28342. if (!config) throw new TypeError('invalid suite type');
  28343. if (typeof password === 'string') password = Buffer.from(password);
  28344. if (password.length !== config.key / 8) throw new TypeError('invalid key length ' + password.length);
  28345. if (typeof iv === 'string') iv = Buffer.from(iv);
  28346. if (config.mode !== 'GCM' && iv.length !== config.iv) throw new TypeError('invalid iv length ' + iv.length);
  28347. if (config.type === 'stream') {
  28348. return new StreamCipher(config.module, password, iv);
  28349. } else if (config.type === 'auth') {
  28350. return new AuthCipher(config.module, password, iv);
  28351. }
  28352. return new Cipher(config.module, password, iv);
  28353. }
  28354. function createCipher(suite, password) {
  28355. var config = MODES[suite.toLowerCase()];
  28356. if (!config) throw new TypeError('invalid suite type');
  28357. var keys = ebtk(password, false, config.key, config.iv);
  28358. return createCipheriv(suite, keys.key, keys.iv);
  28359. }
  28360. exports.createCipheriv = createCipheriv;
  28361. exports.createCipher = createCipher;
  28362. /***/ }),
  28363. /***/ 1225:
  28364. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28365. var Buffer = (__webpack_require__(9047).Buffer);
  28366. var ZEROES = Buffer.alloc(16, 0);
  28367. function toArray(buf) {
  28368. return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)];
  28369. }
  28370. function fromArray(out) {
  28371. var buf = Buffer.allocUnsafe(16);
  28372. buf.writeUInt32BE(out[0] >>> 0, 0);
  28373. buf.writeUInt32BE(out[1] >>> 0, 4);
  28374. buf.writeUInt32BE(out[2] >>> 0, 8);
  28375. buf.writeUInt32BE(out[3] >>> 0, 12);
  28376. return buf;
  28377. }
  28378. function GHASH(key) {
  28379. this.h = key;
  28380. this.state = Buffer.alloc(16, 0);
  28381. this.cache = Buffer.allocUnsafe(0);
  28382. } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html
  28383. // by Juho Vähä-Herttua
  28384. GHASH.prototype.ghash = function (block) {
  28385. var i = -1;
  28386. while (++i < block.length) {
  28387. this.state[i] ^= block[i];
  28388. }
  28389. this._multiply();
  28390. };
  28391. GHASH.prototype._multiply = function () {
  28392. var Vi = toArray(this.h);
  28393. var Zi = [0, 0, 0, 0];
  28394. var j, xi, lsbVi;
  28395. var i = -1;
  28396. while (++i < 128) {
  28397. xi = (this.state[~~(i / 8)] & 1 << 7 - i % 8) !== 0;
  28398. if (xi) {
  28399. // Z_i+1 = Z_i ^ V_i
  28400. Zi[0] ^= Vi[0];
  28401. Zi[1] ^= Vi[1];
  28402. Zi[2] ^= Vi[2];
  28403. Zi[3] ^= Vi[3];
  28404. } // Store the value of LSB(V_i)
  28405. lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1
  28406. for (j = 3; j > 0; j--) {
  28407. Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31;
  28408. }
  28409. Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R
  28410. if (lsbVi) {
  28411. Vi[0] = Vi[0] ^ 0xe1 << 24;
  28412. }
  28413. }
  28414. this.state = fromArray(Zi);
  28415. };
  28416. GHASH.prototype.update = function (buf) {
  28417. this.cache = Buffer.concat([this.cache, buf]);
  28418. var chunk;
  28419. while (this.cache.length >= 16) {
  28420. chunk = this.cache.slice(0, 16);
  28421. this.cache = this.cache.slice(16);
  28422. this.ghash(chunk);
  28423. }
  28424. };
  28425. GHASH.prototype["final"] = function (abl, bl) {
  28426. if (this.cache.length) {
  28427. this.ghash(Buffer.concat([this.cache, ZEROES], 16));
  28428. }
  28429. this.ghash(fromArray([0, abl, 0, bl]));
  28430. return this.state;
  28431. };
  28432. module.exports = GHASH;
  28433. /***/ }),
  28434. /***/ 4001:
  28435. /***/ ((module) => {
  28436. function incr32(iv) {
  28437. var len = iv.length;
  28438. var item;
  28439. while (len--) {
  28440. item = iv.readUInt8(len);
  28441. if (item === 255) {
  28442. iv.writeUInt8(0, len);
  28443. } else {
  28444. item++;
  28445. iv.writeUInt8(item, len);
  28446. break;
  28447. }
  28448. }
  28449. }
  28450. module.exports = incr32;
  28451. /***/ }),
  28452. /***/ 9628:
  28453. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28454. var xor = __webpack_require__(5176);
  28455. exports.encrypt = function (self, block) {
  28456. var data = xor(block, self._prev);
  28457. self._prev = self._cipher.encryptBlock(data);
  28458. return self._prev;
  28459. };
  28460. exports.decrypt = function (self, block) {
  28461. var pad = self._prev;
  28462. self._prev = block;
  28463. var out = self._cipher.decryptBlock(block);
  28464. return xor(out, pad);
  28465. };
  28466. /***/ }),
  28467. /***/ 6674:
  28468. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28469. var Buffer = (__webpack_require__(9047).Buffer);
  28470. var xor = __webpack_require__(5176);
  28471. function encryptStart(self, data, decrypt) {
  28472. var len = data.length;
  28473. var out = xor(data, self._cache);
  28474. self._cache = self._cache.slice(len);
  28475. self._prev = Buffer.concat([self._prev, decrypt ? data : out]);
  28476. return out;
  28477. }
  28478. exports.encrypt = function (self, data, decrypt) {
  28479. var out = Buffer.allocUnsafe(0);
  28480. var len;
  28481. while (data.length) {
  28482. if (self._cache.length === 0) {
  28483. self._cache = self._cipher.encryptBlock(self._prev);
  28484. self._prev = Buffer.allocUnsafe(0);
  28485. }
  28486. if (self._cache.length <= data.length) {
  28487. len = self._cache.length;
  28488. out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]);
  28489. data = data.slice(len);
  28490. } else {
  28491. out = Buffer.concat([out, encryptStart(self, data, decrypt)]);
  28492. break;
  28493. }
  28494. }
  28495. return out;
  28496. };
  28497. /***/ }),
  28498. /***/ 9971:
  28499. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28500. var Buffer = (__webpack_require__(9047).Buffer);
  28501. function encryptByte(self, byteParam, decrypt) {
  28502. var pad;
  28503. var i = -1;
  28504. var len = 8;
  28505. var out = 0;
  28506. var bit, value;
  28507. while (++i < len) {
  28508. pad = self._cipher.encryptBlock(self._prev);
  28509. bit = byteParam & 1 << 7 - i ? 0x80 : 0;
  28510. value = pad[0] ^ bit;
  28511. out += (value & 0x80) >> i % 8;
  28512. self._prev = shiftIn(self._prev, decrypt ? bit : value);
  28513. }
  28514. return out;
  28515. }
  28516. function shiftIn(buffer, value) {
  28517. var len = buffer.length;
  28518. var i = -1;
  28519. var out = Buffer.allocUnsafe(buffer.length);
  28520. buffer = Buffer.concat([buffer, Buffer.from([value])]);
  28521. while (++i < len) {
  28522. out[i] = buffer[i] << 1 | buffer[i + 1] >> 7;
  28523. }
  28524. return out;
  28525. }
  28526. exports.encrypt = function (self, chunk, decrypt) {
  28527. var len = chunk.length;
  28528. var out = Buffer.allocUnsafe(len);
  28529. var i = -1;
  28530. while (++i < len) {
  28531. out[i] = encryptByte(self, chunk[i], decrypt);
  28532. }
  28533. return out;
  28534. };
  28535. /***/ }),
  28536. /***/ 8194:
  28537. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28538. var Buffer = (__webpack_require__(9047).Buffer);
  28539. function encryptByte(self, byteParam, decrypt) {
  28540. var pad = self._cipher.encryptBlock(self._prev);
  28541. var out = pad[0] ^ byteParam;
  28542. self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]);
  28543. return out;
  28544. }
  28545. exports.encrypt = function (self, chunk, decrypt) {
  28546. var len = chunk.length;
  28547. var out = Buffer.allocUnsafe(len);
  28548. var i = -1;
  28549. while (++i < len) {
  28550. out[i] = encryptByte(self, chunk[i], decrypt);
  28551. }
  28552. return out;
  28553. };
  28554. /***/ }),
  28555. /***/ 8871:
  28556. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28557. var xor = __webpack_require__(5176);
  28558. var Buffer = (__webpack_require__(9047).Buffer);
  28559. var incr32 = __webpack_require__(4001);
  28560. function getBlock(self) {
  28561. var out = self._cipher.encryptBlockRaw(self._prev);
  28562. incr32(self._prev);
  28563. return out;
  28564. }
  28565. var blockSize = 16;
  28566. exports.encrypt = function (self, chunk) {
  28567. var chunkNum = Math.ceil(chunk.length / blockSize);
  28568. var start = self._cache.length;
  28569. self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]);
  28570. for (var i = 0; i < chunkNum; i++) {
  28571. var out = getBlock(self);
  28572. var offset = start + i * blockSize;
  28573. self._cache.writeUInt32BE(out[0], offset + 0);
  28574. self._cache.writeUInt32BE(out[1], offset + 4);
  28575. self._cache.writeUInt32BE(out[2], offset + 8);
  28576. self._cache.writeUInt32BE(out[3], offset + 12);
  28577. }
  28578. var pad = self._cache.slice(0, chunk.length);
  28579. self._cache = self._cache.slice(chunk.length);
  28580. return xor(chunk, pad);
  28581. };
  28582. /***/ }),
  28583. /***/ 8972:
  28584. /***/ ((__unused_webpack_module, exports) => {
  28585. exports.encrypt = function (self, block) {
  28586. return self._cipher.encryptBlock(block);
  28587. };
  28588. exports.decrypt = function (self, block) {
  28589. return self._cipher.decryptBlock(block);
  28590. };
  28591. /***/ }),
  28592. /***/ 6572:
  28593. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28594. var modeModules = {
  28595. ECB: __webpack_require__(8972),
  28596. CBC: __webpack_require__(9628),
  28597. CFB: __webpack_require__(6674),
  28598. CFB8: __webpack_require__(8194),
  28599. CFB1: __webpack_require__(9971),
  28600. OFB: __webpack_require__(2343),
  28601. CTR: __webpack_require__(8871),
  28602. GCM: __webpack_require__(8871)
  28603. };
  28604. var modes = __webpack_require__(4946);
  28605. for (var key in modes) {
  28606. modes[key].module = modeModules[modes[key].mode];
  28607. }
  28608. module.exports = modes;
  28609. /***/ }),
  28610. /***/ 2343:
  28611. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28612. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  28613. var xor = __webpack_require__(5176);
  28614. function getBlock(self) {
  28615. self._prev = self._cipher.encryptBlock(self._prev);
  28616. return self._prev;
  28617. }
  28618. exports.encrypt = function (self, chunk) {
  28619. while (self._cache.length < chunk.length) {
  28620. self._cache = Buffer.concat([self._cache, getBlock(self)]);
  28621. }
  28622. var pad = self._cache.slice(0, chunk.length);
  28623. self._cache = self._cache.slice(chunk.length);
  28624. return xor(chunk, pad);
  28625. };
  28626. /***/ }),
  28627. /***/ 7188:
  28628. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28629. var aes = __webpack_require__(7463);
  28630. var Buffer = (__webpack_require__(9047).Buffer);
  28631. var Transform = __webpack_require__(8842);
  28632. var inherits = __webpack_require__(376);
  28633. function StreamCipher(mode, key, iv, decrypt) {
  28634. Transform.call(this);
  28635. this._cipher = new aes.AES(key);
  28636. this._prev = Buffer.from(iv);
  28637. this._cache = Buffer.allocUnsafe(0);
  28638. this._secCache = Buffer.allocUnsafe(0);
  28639. this._decrypt = decrypt;
  28640. this._mode = mode;
  28641. }
  28642. inherits(StreamCipher, Transform);
  28643. StreamCipher.prototype._update = function (chunk) {
  28644. return this._mode.encrypt(this, chunk, this._decrypt);
  28645. };
  28646. StreamCipher.prototype._final = function () {
  28647. this._cipher.scrub();
  28648. };
  28649. module.exports = StreamCipher;
  28650. /***/ }),
  28651. /***/ 5972:
  28652. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  28653. var DES = __webpack_require__(7729);
  28654. var aes = __webpack_require__(4881);
  28655. var aesModes = __webpack_require__(6572);
  28656. var desModes = __webpack_require__(3519);
  28657. var ebtk = __webpack_require__(1248);
  28658. function createCipher(suite, password) {
  28659. suite = suite.toLowerCase();
  28660. var keyLen, ivLen;
  28661. if (aesModes[suite]) {
  28662. keyLen = aesModes[suite].key;
  28663. ivLen = aesModes[suite].iv;
  28664. } else if (desModes[suite]) {
  28665. keyLen = desModes[suite].key * 8;
  28666. ivLen = desModes[suite].iv;
  28667. } else {
  28668. throw new TypeError('invalid suite type');
  28669. }
  28670. var keys = ebtk(password, false, keyLen, ivLen);
  28671. return createCipheriv(suite, keys.key, keys.iv);
  28672. }
  28673. function createDecipher(suite, password) {
  28674. suite = suite.toLowerCase();
  28675. var keyLen, ivLen;
  28676. if (aesModes[suite]) {
  28677. keyLen = aesModes[suite].key;
  28678. ivLen = aesModes[suite].iv;
  28679. } else if (desModes[suite]) {
  28680. keyLen = desModes[suite].key * 8;
  28681. ivLen = desModes[suite].iv;
  28682. } else {
  28683. throw new TypeError('invalid suite type');
  28684. }
  28685. var keys = ebtk(password, false, keyLen, ivLen);
  28686. return createDecipheriv(suite, keys.key, keys.iv);
  28687. }
  28688. function createCipheriv(suite, key, iv) {
  28689. suite = suite.toLowerCase();
  28690. if (aesModes[suite]) return aes.createCipheriv(suite, key, iv);
  28691. if (desModes[suite]) return new DES({
  28692. key: key,
  28693. iv: iv,
  28694. mode: suite
  28695. });
  28696. throw new TypeError('invalid suite type');
  28697. }
  28698. function createDecipheriv(suite, key, iv) {
  28699. suite = suite.toLowerCase();
  28700. if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv);
  28701. if (desModes[suite]) return new DES({
  28702. key: key,
  28703. iv: iv,
  28704. mode: suite,
  28705. decrypt: true
  28706. });
  28707. throw new TypeError('invalid suite type');
  28708. }
  28709. function getCiphers() {
  28710. return Object.keys(desModes).concat(aes.getCiphers());
  28711. }
  28712. exports.createCipher = exports.Cipher = createCipher;
  28713. exports.createCipheriv = exports.Cipheriv = createCipheriv;
  28714. exports.createDecipher = exports.Decipher = createDecipher;
  28715. exports.createDecipheriv = exports.Decipheriv = createDecipheriv;
  28716. exports.listCiphers = exports.getCiphers = getCiphers;
  28717. /***/ }),
  28718. /***/ 7729:
  28719. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28720. var CipherBase = __webpack_require__(8842);
  28721. var des = __webpack_require__(167);
  28722. var inherits = __webpack_require__(376);
  28723. var Buffer = (__webpack_require__(9047).Buffer);
  28724. var modes = {
  28725. 'des-ede3-cbc': des.CBC.instantiate(des.EDE),
  28726. 'des-ede3': des.EDE,
  28727. 'des-ede-cbc': des.CBC.instantiate(des.EDE),
  28728. 'des-ede': des.EDE,
  28729. 'des-cbc': des.CBC.instantiate(des.DES),
  28730. 'des-ecb': des.DES
  28731. };
  28732. modes.des = modes['des-cbc'];
  28733. modes.des3 = modes['des-ede3-cbc'];
  28734. module.exports = DES;
  28735. inherits(DES, CipherBase);
  28736. function DES(opts) {
  28737. CipherBase.call(this);
  28738. var modeName = opts.mode.toLowerCase();
  28739. var mode = modes[modeName];
  28740. var type;
  28741. if (opts.decrypt) {
  28742. type = 'decrypt';
  28743. } else {
  28744. type = 'encrypt';
  28745. }
  28746. var key = opts.key;
  28747. if (!Buffer.isBuffer(key)) {
  28748. key = Buffer.from(key);
  28749. }
  28750. if (modeName === 'des-ede' || modeName === 'des-ede-cbc') {
  28751. key = Buffer.concat([key, key.slice(0, 8)]);
  28752. }
  28753. var iv = opts.iv;
  28754. if (!Buffer.isBuffer(iv)) {
  28755. iv = Buffer.from(iv);
  28756. }
  28757. this._des = mode.create({
  28758. key: key,
  28759. iv: iv,
  28760. type: type
  28761. });
  28762. }
  28763. DES.prototype._update = function (data) {
  28764. return Buffer.from(this._des.update(data));
  28765. };
  28766. DES.prototype._final = function () {
  28767. return Buffer.from(this._des["final"]());
  28768. };
  28769. /***/ }),
  28770. /***/ 3519:
  28771. /***/ ((__unused_webpack_module, exports) => {
  28772. exports["des-ecb"] = {
  28773. key: 8,
  28774. iv: 0
  28775. };
  28776. exports["des-cbc"] = exports.des = {
  28777. key: 8,
  28778. iv: 8
  28779. };
  28780. exports["des-ede3-cbc"] = exports.des3 = {
  28781. key: 24,
  28782. iv: 8
  28783. };
  28784. exports["des-ede3"] = {
  28785. key: 24,
  28786. iv: 0
  28787. };
  28788. exports["des-ede-cbc"] = {
  28789. key: 16,
  28790. iv: 8
  28791. };
  28792. exports["des-ede"] = {
  28793. key: 16,
  28794. iv: 0
  28795. };
  28796. /***/ }),
  28797. /***/ 4364:
  28798. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28799. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  28800. var BN = __webpack_require__(6781);
  28801. var randomBytes = __webpack_require__(5760);
  28802. function blind(priv) {
  28803. var r = getr(priv);
  28804. var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed();
  28805. return {
  28806. blinder: blinder,
  28807. unblinder: r.invm(priv.modulus)
  28808. };
  28809. }
  28810. function getr(priv) {
  28811. var len = priv.modulus.byteLength();
  28812. var r;
  28813. do {
  28814. r = new BN(randomBytes(len));
  28815. } while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2));
  28816. return r;
  28817. }
  28818. function crt(msg, priv) {
  28819. var blinds = blind(priv);
  28820. var len = priv.modulus.byteLength();
  28821. var blinded = new BN(msg).mul(blinds.blinder).umod(priv.modulus);
  28822. var c1 = blinded.toRed(BN.mont(priv.prime1));
  28823. var c2 = blinded.toRed(BN.mont(priv.prime2));
  28824. var qinv = priv.coefficient;
  28825. var p = priv.prime1;
  28826. var q = priv.prime2;
  28827. var m1 = c1.redPow(priv.exponent1).fromRed();
  28828. var m2 = c2.redPow(priv.exponent2).fromRed();
  28829. var h = m1.isub(m2).imul(qinv).umod(p).imul(q);
  28830. return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer, 'be', len);
  28831. }
  28832. crt.getr = getr;
  28833. module.exports = crt;
  28834. /***/ }),
  28835. /***/ 3363:
  28836. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28837. module.exports = __webpack_require__(5207);
  28838. /***/ }),
  28839. /***/ 1022:
  28840. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28841. var Buffer = (__webpack_require__(3173).Buffer);
  28842. var createHash = __webpack_require__(8339);
  28843. var stream = __webpack_require__(8237);
  28844. var inherits = __webpack_require__(376);
  28845. var sign = __webpack_require__(1437);
  28846. var verify = __webpack_require__(1113);
  28847. var algorithms = __webpack_require__(5207);
  28848. Object.keys(algorithms).forEach(function (key) {
  28849. algorithms[key].id = Buffer.from(algorithms[key].id, 'hex');
  28850. algorithms[key.toLowerCase()] = algorithms[key];
  28851. });
  28852. function Sign(algorithm) {
  28853. stream.Writable.call(this);
  28854. var data = algorithms[algorithm];
  28855. if (!data) throw new Error('Unknown message digest');
  28856. this._hashType = data.hash;
  28857. this._hash = createHash(data.hash);
  28858. this._tag = data.id;
  28859. this._signType = data.sign;
  28860. }
  28861. inherits(Sign, stream.Writable);
  28862. Sign.prototype._write = function _write(data, _, done) {
  28863. this._hash.update(data);
  28864. done();
  28865. };
  28866. Sign.prototype.update = function update(data, enc) {
  28867. if (typeof data === 'string') data = Buffer.from(data, enc);
  28868. this._hash.update(data);
  28869. return this;
  28870. };
  28871. Sign.prototype.sign = function signMethod(key, enc) {
  28872. this.end();
  28873. var hash = this._hash.digest();
  28874. var sig = sign(hash, key, this._hashType, this._signType, this._tag);
  28875. return enc ? sig.toString(enc) : sig;
  28876. };
  28877. function Verify(algorithm) {
  28878. stream.Writable.call(this);
  28879. var data = algorithms[algorithm];
  28880. if (!data) throw new Error('Unknown message digest');
  28881. this._hash = createHash(data.hash);
  28882. this._tag = data.id;
  28883. this._signType = data.sign;
  28884. }
  28885. inherits(Verify, stream.Writable);
  28886. Verify.prototype._write = function _write(data, _, done) {
  28887. this._hash.update(data);
  28888. done();
  28889. };
  28890. Verify.prototype.update = function update(data, enc) {
  28891. if (typeof data === 'string') data = Buffer.from(data, enc);
  28892. this._hash.update(data);
  28893. return this;
  28894. };
  28895. Verify.prototype.verify = function verifyMethod(key, sig, enc) {
  28896. if (typeof sig === 'string') sig = Buffer.from(sig, enc);
  28897. this.end();
  28898. var hash = this._hash.digest();
  28899. return verify(sig, hash, key, this._signType, this._tag);
  28900. };
  28901. function createSign(algorithm) {
  28902. return new Sign(algorithm);
  28903. }
  28904. function createVerify(algorithm) {
  28905. return new Verify(algorithm);
  28906. }
  28907. module.exports = {
  28908. Sign: createSign,
  28909. Verify: createVerify,
  28910. createSign: createSign,
  28911. createVerify: createVerify
  28912. };
  28913. /***/ }),
  28914. /***/ 1437:
  28915. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  28916. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  28917. var Buffer = (__webpack_require__(3173).Buffer);
  28918. var createHmac = __webpack_require__(8736);
  28919. var crt = __webpack_require__(4364);
  28920. var EC = (__webpack_require__(8333).ec);
  28921. var BN = __webpack_require__(6781);
  28922. var parseKeys = __webpack_require__(2914);
  28923. var curves = __webpack_require__(1308);
  28924. function sign(hash, key, hashType, signType, tag) {
  28925. var priv = parseKeys(key);
  28926. if (priv.curve) {
  28927. // rsa keys can be interpreted as ecdsa ones in openssl
  28928. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  28929. return ecSign(hash, priv);
  28930. } else if (priv.type === 'dsa') {
  28931. if (signType !== 'dsa') throw new Error('wrong private key type');
  28932. return dsaSign(hash, priv, hashType);
  28933. } else {
  28934. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong private key type');
  28935. }
  28936. hash = Buffer.concat([tag, hash]);
  28937. var len = priv.modulus.byteLength();
  28938. var pad = [0, 1];
  28939. while (hash.length + pad.length + 1 < len) {
  28940. pad.push(0xff);
  28941. }
  28942. pad.push(0x00);
  28943. var i = -1;
  28944. while (++i < hash.length) {
  28945. pad.push(hash[i]);
  28946. }
  28947. var out = crt(pad, priv);
  28948. return out;
  28949. }
  28950. function ecSign(hash, priv) {
  28951. var curveId = curves[priv.curve.join('.')];
  28952. if (!curveId) throw new Error('unknown curve ' + priv.curve.join('.'));
  28953. var curve = new EC(curveId);
  28954. var key = curve.keyFromPrivate(priv.privateKey);
  28955. var out = key.sign(hash);
  28956. return Buffer.from(out.toDER());
  28957. }
  28958. function dsaSign(hash, priv, algo) {
  28959. var x = priv.params.priv_key;
  28960. var p = priv.params.p;
  28961. var q = priv.params.q;
  28962. var g = priv.params.g;
  28963. var r = new BN(0);
  28964. var k;
  28965. var H = bits2int(hash, q).mod(q);
  28966. var s = false;
  28967. var kv = getKey(x, q, hash, algo);
  28968. while (s === false) {
  28969. k = makeKey(q, kv, algo);
  28970. r = makeR(g, k, p, q);
  28971. s = k.invm(q).imul(H.add(x.mul(r))).mod(q);
  28972. if (s.cmpn(0) === 0) {
  28973. s = false;
  28974. r = new BN(0);
  28975. }
  28976. }
  28977. return toDER(r, s);
  28978. }
  28979. function toDER(r, s) {
  28980. r = r.toArray();
  28981. s = s.toArray(); // Pad values
  28982. if (r[0] & 0x80) r = [0].concat(r);
  28983. if (s[0] & 0x80) s = [0].concat(s);
  28984. var total = r.length + s.length + 4;
  28985. var res = [0x30, total, 0x02, r.length];
  28986. res = res.concat(r, [0x02, s.length], s);
  28987. return Buffer.from(res);
  28988. }
  28989. function getKey(x, q, hash, algo) {
  28990. x = Buffer.from(x.toArray());
  28991. if (x.length < q.byteLength()) {
  28992. var zeros = Buffer.alloc(q.byteLength() - x.length);
  28993. x = Buffer.concat([zeros, x]);
  28994. }
  28995. var hlen = hash.length;
  28996. var hbits = bits2octets(hash, q);
  28997. var v = Buffer.alloc(hlen);
  28998. v.fill(1);
  28999. var k = Buffer.alloc(hlen);
  29000. k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest();
  29001. v = createHmac(algo, k).update(v).digest();
  29002. k = createHmac(algo, k).update(v).update(Buffer.from([1])).update(x).update(hbits).digest();
  29003. v = createHmac(algo, k).update(v).digest();
  29004. return {
  29005. k: k,
  29006. v: v
  29007. };
  29008. }
  29009. function bits2int(obits, q) {
  29010. var bits = new BN(obits);
  29011. var shift = (obits.length << 3) - q.bitLength();
  29012. if (shift > 0) bits.ishrn(shift);
  29013. return bits;
  29014. }
  29015. function bits2octets(bits, q) {
  29016. bits = bits2int(bits, q);
  29017. bits = bits.mod(q);
  29018. var out = Buffer.from(bits.toArray());
  29019. if (out.length < q.byteLength()) {
  29020. var zeros = Buffer.alloc(q.byteLength() - out.length);
  29021. out = Buffer.concat([zeros, out]);
  29022. }
  29023. return out;
  29024. }
  29025. function makeKey(q, kv, algo) {
  29026. var t;
  29027. var k;
  29028. do {
  29029. t = Buffer.alloc(0);
  29030. while (t.length * 8 < q.bitLength()) {
  29031. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  29032. t = Buffer.concat([t, kv.v]);
  29033. }
  29034. k = bits2int(t, q);
  29035. kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest();
  29036. kv.v = createHmac(algo, kv.k).update(kv.v).digest();
  29037. } while (k.cmp(q) !== -1);
  29038. return k;
  29039. }
  29040. function makeR(g, k, p, q) {
  29041. return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q);
  29042. }
  29043. module.exports = sign;
  29044. module.exports.getKey = getKey;
  29045. module.exports.makeKey = makeKey;
  29046. /***/ }),
  29047. /***/ 1113:
  29048. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  29049. // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js
  29050. var Buffer = (__webpack_require__(3173).Buffer);
  29051. var BN = __webpack_require__(6781);
  29052. var EC = (__webpack_require__(8333).ec);
  29053. var parseKeys = __webpack_require__(2914);
  29054. var curves = __webpack_require__(1308);
  29055. function verify(sig, hash, key, signType, tag) {
  29056. var pub = parseKeys(key);
  29057. if (pub.type === 'ec') {
  29058. // rsa keys can be interpreted as ecdsa ones in openssl
  29059. if (signType !== 'ecdsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  29060. return ecVerify(sig, hash, pub);
  29061. } else if (pub.type === 'dsa') {
  29062. if (signType !== 'dsa') throw new Error('wrong public key type');
  29063. return dsaVerify(sig, hash, pub);
  29064. } else {
  29065. if (signType !== 'rsa' && signType !== 'ecdsa/rsa') throw new Error('wrong public key type');
  29066. }
  29067. hash = Buffer.concat([tag, hash]);
  29068. var len = pub.modulus.byteLength();
  29069. var pad = [1];
  29070. var padNum = 0;
  29071. while (hash.length + pad.length + 2 < len) {
  29072. pad.push(0xff);
  29073. padNum++;
  29074. }
  29075. pad.push(0x00);
  29076. var i = -1;
  29077. while (++i < hash.length) {
  29078. pad.push(hash[i]);
  29079. }
  29080. pad = Buffer.from(pad);
  29081. var red = BN.mont(pub.modulus);
  29082. sig = new BN(sig).toRed(red);
  29083. sig = sig.redPow(new BN(pub.publicExponent));
  29084. sig = Buffer.from(sig.fromRed().toArray());
  29085. var out = padNum < 8 ? 1 : 0;
  29086. len = Math.min(sig.length, pad.length);
  29087. if (sig.length !== pad.length) out = 1;
  29088. i = -1;
  29089. while (++i < len) {
  29090. out |= sig[i] ^ pad[i];
  29091. }
  29092. return out === 0;
  29093. }
  29094. function ecVerify(sig, hash, pub) {
  29095. var curveId = curves[pub.data.algorithm.curve.join('.')];
  29096. if (!curveId) throw new Error('unknown curve ' + pub.data.algorithm.curve.join('.'));
  29097. var curve = new EC(curveId);
  29098. var pubkey = pub.data.subjectPrivateKey.data;
  29099. return curve.verify(hash, sig, pubkey);
  29100. }
  29101. function dsaVerify(sig, hash, pub) {
  29102. var p = pub.data.p;
  29103. var q = pub.data.q;
  29104. var g = pub.data.g;
  29105. var y = pub.data.pub_key;
  29106. var unpacked = parseKeys.signature.decode(sig, 'der');
  29107. var s = unpacked.s;
  29108. var r = unpacked.r;
  29109. checkValue(s, q);
  29110. checkValue(r, q);
  29111. var montp = BN.mont(p);
  29112. var w = s.invm(q);
  29113. var v = g.toRed(montp).redPow(new BN(hash).mul(w).mod(q)).fromRed().mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed()).mod(p).mod(q);
  29114. return v.cmp(r) === 0;
  29115. }
  29116. function checkValue(b, q) {
  29117. if (b.cmpn(0) <= 0) throw new Error('invalid sig');
  29118. if (b.cmp(q) >= q) throw new Error('invalid sig');
  29119. }
  29120. module.exports = verify;
  29121. /***/ }),
  29122. /***/ 3173:
  29123. /***/ ((module, exports, __webpack_require__) => {
  29124. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  29125. /* eslint-disable node/no-deprecated-api */
  29126. var buffer = __webpack_require__(365);
  29127. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  29128. function copyProps(src, dst) {
  29129. for (var key in src) {
  29130. dst[key] = src[key];
  29131. }
  29132. }
  29133. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  29134. module.exports = buffer;
  29135. } else {
  29136. // Copy properties from require('buffer')
  29137. copyProps(buffer, exports);
  29138. exports.Buffer = SafeBuffer;
  29139. }
  29140. function SafeBuffer(arg, encodingOrOffset, length) {
  29141. return Buffer(arg, encodingOrOffset, length);
  29142. }
  29143. SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer
  29144. copyProps(Buffer, SafeBuffer);
  29145. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  29146. if (typeof arg === 'number') {
  29147. throw new TypeError('Argument must not be a number');
  29148. }
  29149. return Buffer(arg, encodingOrOffset, length);
  29150. };
  29151. SafeBuffer.alloc = function (size, fill, encoding) {
  29152. if (typeof size !== 'number') {
  29153. throw new TypeError('Argument must be a number');
  29154. }
  29155. var buf = Buffer(size);
  29156. if (fill !== undefined) {
  29157. if (typeof encoding === 'string') {
  29158. buf.fill(fill, encoding);
  29159. } else {
  29160. buf.fill(fill);
  29161. }
  29162. } else {
  29163. buf.fill(0);
  29164. }
  29165. return buf;
  29166. };
  29167. SafeBuffer.allocUnsafe = function (size) {
  29168. if (typeof size !== 'number') {
  29169. throw new TypeError('Argument must be a number');
  29170. }
  29171. return Buffer(size);
  29172. };
  29173. SafeBuffer.allocUnsafeSlow = function (size) {
  29174. if (typeof size !== 'number') {
  29175. throw new TypeError('Argument must be a number');
  29176. }
  29177. return buffer.SlowBuffer(size);
  29178. };
  29179. /***/ }),
  29180. /***/ 3873:
  29181. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  29182. "use strict";
  29183. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  29184. /* harmony export */ "Decimal128": () => (/* binding */ _Decimal),
  29185. /* harmony export */ "Kb": () => (/* binding */ _Binary),
  29186. /* harmony export */ "t4": () => (/* binding */ _ObjectId)
  29187. /* harmony export */ });
  29188. /* unused harmony exports BSONError, BSONRegExp, BSONSymbol, BSONTypeError, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_COLUMN, BSON_BINARY_SUBTYPE_DEFAULT, BSON_BINARY_SUBTYPE_ENCRYPTED, BSON_BINARY_SUBTYPE_FUNCTION, BSON_BINARY_SUBTYPE_MD5, BSON_BINARY_SUBTYPE_USER_DEFINED, BSON_BINARY_SUBTYPE_UUID, BSON_BINARY_SUBTYPE_UUID_NEW, BSON_DATA_ARRAY, BSON_DATA_BINARY, BSON_DATA_BOOLEAN, BSON_DATA_CODE, BSON_DATA_CODE_W_SCOPE, BSON_DATA_DATE, BSON_DATA_DBPOINTER, BSON_DATA_DECIMAL128, BSON_DATA_INT, BSON_DATA_LONG, BSON_DATA_MAX_KEY, BSON_DATA_MIN_KEY, BSON_DATA_NULL, BSON_DATA_NUMBER, BSON_DATA_OBJECT, BSON_DATA_OID, BSON_DATA_REGEXP, BSON_DATA_STRING, BSON_DATA_SYMBOL, BSON_DATA_TIMESTAMP, BSON_DATA_UNDEFINED, BSON_INT32_MAX, BSON_INT32_MIN, BSON_INT64_MAX, BSON_INT64_MIN, Code, DBRef, Double, EJSON, Int32, Long, LongWithoutOverridesClass, Map, MaxKey, MinKey, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize */
  29189. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  29190. function createCommonjsModule(fn, module) {
  29191. return module = {
  29192. exports: {}
  29193. }, fn(module, module.exports), module.exports;
  29194. }
  29195. var byteLength_1 = byteLength;
  29196. var toByteArray_1 = toByteArray;
  29197. var fromByteArray_1 = fromByteArray;
  29198. var lookup = [];
  29199. var revLookup = [];
  29200. var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
  29201. var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
  29202. for (var i = 0, len = code.length; i < len; ++i) {
  29203. lookup[i] = code[i];
  29204. revLookup[code.charCodeAt(i)] = i;
  29205. } // Support decoding URL-safe base64 strings, as Node.js does.
  29206. // See: https://en.wikipedia.org/wiki/Base64#URL_applications
  29207. revLookup['-'.charCodeAt(0)] = 62;
  29208. revLookup['_'.charCodeAt(0)] = 63;
  29209. function getLens(b64) {
  29210. var len = b64.length;
  29211. if (len % 4 > 0) {
  29212. throw new Error('Invalid string. Length must be a multiple of 4');
  29213. } // Trim off extra bytes after placeholder bytes are found
  29214. // See: https://github.com/beatgammit/base64-js/issues/42
  29215. var validLen = b64.indexOf('=');
  29216. if (validLen === -1) validLen = len;
  29217. var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
  29218. return [validLen, placeHoldersLen];
  29219. } // base64 is 4/3 + up to two characters of the original data
  29220. function byteLength(b64) {
  29221. var lens = getLens(b64);
  29222. var validLen = lens[0];
  29223. var placeHoldersLen = lens[1];
  29224. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  29225. }
  29226. function _byteLength(b64, validLen, placeHoldersLen) {
  29227. return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
  29228. }
  29229. function toByteArray(b64) {
  29230. var tmp;
  29231. var lens = getLens(b64);
  29232. var validLen = lens[0];
  29233. var placeHoldersLen = lens[1];
  29234. var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
  29235. var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars
  29236. var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
  29237. var i;
  29238. for (i = 0; i < len; i += 4) {
  29239. tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
  29240. arr[curByte++] = tmp >> 16 & 0xFF;
  29241. arr[curByte++] = tmp >> 8 & 0xFF;
  29242. arr[curByte++] = tmp & 0xFF;
  29243. }
  29244. if (placeHoldersLen === 2) {
  29245. tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
  29246. arr[curByte++] = tmp & 0xFF;
  29247. }
  29248. if (placeHoldersLen === 1) {
  29249. tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
  29250. arr[curByte++] = tmp >> 8 & 0xFF;
  29251. arr[curByte++] = tmp & 0xFF;
  29252. }
  29253. return arr;
  29254. }
  29255. function tripletToBase64(num) {
  29256. return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
  29257. }
  29258. function encodeChunk(uint8, start, end) {
  29259. var tmp;
  29260. var output = [];
  29261. for (var i = start; i < end; i += 3) {
  29262. tmp = (uint8[i] << 16 & 0xFF0000) + (uint8[i + 1] << 8 & 0xFF00) + (uint8[i + 2] & 0xFF);
  29263. output.push(tripletToBase64(tmp));
  29264. }
  29265. return output.join('');
  29266. }
  29267. function fromByteArray(uint8) {
  29268. var tmp;
  29269. var len = uint8.length;
  29270. var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
  29271. var parts = [];
  29272. var maxChunkLength = 16383; // must be multiple of 3
  29273. // go through the array every three bytes, we'll deal with trailing stuff later
  29274. for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
  29275. parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength));
  29276. } // pad the end with zeros, but make sure to not forget the extra bytes
  29277. if (extraBytes === 1) {
  29278. tmp = uint8[len - 1];
  29279. parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 0x3F] + '==');
  29280. } else if (extraBytes === 2) {
  29281. tmp = (uint8[len - 2] << 8) + uint8[len - 1];
  29282. parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 0x3F] + lookup[tmp << 2 & 0x3F] + '=');
  29283. }
  29284. return parts.join('');
  29285. }
  29286. var base64Js = {
  29287. byteLength: byteLength_1,
  29288. toByteArray: toByteArray_1,
  29289. fromByteArray: fromByteArray_1
  29290. };
  29291. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  29292. var read = function read(buffer, offset, isLE, mLen, nBytes) {
  29293. var e, m;
  29294. var eLen = nBytes * 8 - mLen - 1;
  29295. var eMax = (1 << eLen) - 1;
  29296. var eBias = eMax >> 1;
  29297. var nBits = -7;
  29298. var i = isLE ? nBytes - 1 : 0;
  29299. var d = isLE ? -1 : 1;
  29300. var s = buffer[offset + i];
  29301. i += d;
  29302. e = s & (1 << -nBits) - 1;
  29303. s >>= -nBits;
  29304. nBits += eLen;
  29305. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  29306. m = e & (1 << -nBits) - 1;
  29307. e >>= -nBits;
  29308. nBits += mLen;
  29309. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  29310. if (e === 0) {
  29311. e = 1 - eBias;
  29312. } else if (e === eMax) {
  29313. return m ? NaN : (s ? -1 : 1) * Infinity;
  29314. } else {
  29315. m = m + Math.pow(2, mLen);
  29316. e = e - eBias;
  29317. }
  29318. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  29319. };
  29320. var write = function write(buffer, value, offset, isLE, mLen, nBytes) {
  29321. var e, m, c;
  29322. var eLen = nBytes * 8 - mLen - 1;
  29323. var eMax = (1 << eLen) - 1;
  29324. var eBias = eMax >> 1;
  29325. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  29326. var i = isLE ? 0 : nBytes - 1;
  29327. var d = isLE ? 1 : -1;
  29328. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  29329. value = Math.abs(value);
  29330. if (isNaN(value) || value === Infinity) {
  29331. m = isNaN(value) ? 1 : 0;
  29332. e = eMax;
  29333. } else {
  29334. e = Math.floor(Math.log(value) / Math.LN2);
  29335. if (value * (c = Math.pow(2, -e)) < 1) {
  29336. e--;
  29337. c *= 2;
  29338. }
  29339. if (e + eBias >= 1) {
  29340. value += rt / c;
  29341. } else {
  29342. value += rt * Math.pow(2, 1 - eBias);
  29343. }
  29344. if (value * c >= 2) {
  29345. e++;
  29346. c /= 2;
  29347. }
  29348. if (e + eBias >= eMax) {
  29349. m = 0;
  29350. e = eMax;
  29351. } else if (e + eBias >= 1) {
  29352. m = (value * c - 1) * Math.pow(2, mLen);
  29353. e = e + eBias;
  29354. } else {
  29355. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  29356. e = 0;
  29357. }
  29358. }
  29359. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  29360. e = e << mLen | m;
  29361. eLen += mLen;
  29362. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  29363. buffer[offset + i - d] |= s * 128;
  29364. };
  29365. var ieee754 = {
  29366. read: read,
  29367. write: write
  29368. };
  29369. var buffer$1 = createCommonjsModule(function (module, exports) {
  29370. var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' ? // eslint-disable-line dot-notation
  29371. Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
  29372. : null;
  29373. exports.Buffer = Buffer;
  29374. exports.SlowBuffer = SlowBuffer;
  29375. exports.INSPECT_MAX_BYTES = 50;
  29376. var K_MAX_LENGTH = 0x7fffffff;
  29377. exports.kMaxLength = K_MAX_LENGTH;
  29378. /**
  29379. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  29380. * === true Use Uint8Array implementation (fastest)
  29381. * === false Print warning and recommend using `buffer` v4.x which has an Object
  29382. * implementation (most compatible, even IE6)
  29383. *
  29384. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  29385. * Opera 11.6+, iOS 4.2+.
  29386. *
  29387. * We report that the browser does not support typed arrays if the are not subclassable
  29388. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  29389. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  29390. * for __proto__ and has a buggy typed array implementation.
  29391. */
  29392. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  29393. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  29394. 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.');
  29395. }
  29396. function typedArraySupport() {
  29397. // Can typed array instances can be augmented?
  29398. try {
  29399. var arr = new Uint8Array(1);
  29400. var proto = {
  29401. foo: function foo() {
  29402. return 42;
  29403. }
  29404. };
  29405. Object.setPrototypeOf(proto, Uint8Array.prototype);
  29406. Object.setPrototypeOf(arr, proto);
  29407. return arr.foo() === 42;
  29408. } catch (e) {
  29409. return false;
  29410. }
  29411. }
  29412. Object.defineProperty(Buffer.prototype, 'parent', {
  29413. enumerable: true,
  29414. get: function get() {
  29415. if (!Buffer.isBuffer(this)) return undefined;
  29416. return this.buffer;
  29417. }
  29418. });
  29419. Object.defineProperty(Buffer.prototype, 'offset', {
  29420. enumerable: true,
  29421. get: function get() {
  29422. if (!Buffer.isBuffer(this)) return undefined;
  29423. return this.byteOffset;
  29424. }
  29425. });
  29426. function createBuffer(length) {
  29427. if (length > K_MAX_LENGTH) {
  29428. throw new RangeError('The value "' + length + '" is invalid for option "size"');
  29429. } // Return an augmented `Uint8Array` instance
  29430. var buf = new Uint8Array(length);
  29431. Object.setPrototypeOf(buf, Buffer.prototype);
  29432. return buf;
  29433. }
  29434. /**
  29435. * The Buffer constructor returns instances of `Uint8Array` that have their
  29436. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  29437. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  29438. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  29439. * returns a single octet.
  29440. *
  29441. * The `Uint8Array` prototype remains unmodified.
  29442. */
  29443. function Buffer(arg, encodingOrOffset, length) {
  29444. // Common case.
  29445. if (typeof arg === 'number') {
  29446. if (typeof encodingOrOffset === 'string') {
  29447. throw new TypeError('The "string" argument must be of type string. Received type number');
  29448. }
  29449. return allocUnsafe(arg);
  29450. }
  29451. return from(arg, encodingOrOffset, length);
  29452. }
  29453. Buffer.poolSize = 8192; // not used by this implementation
  29454. function from(value, encodingOrOffset, length) {
  29455. if (typeof value === 'string') {
  29456. return fromString(value, encodingOrOffset);
  29457. }
  29458. if (ArrayBuffer.isView(value)) {
  29459. return fromArrayView(value);
  29460. }
  29461. if (value == null) {
  29462. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + babelHelpers["typeof"](value));
  29463. }
  29464. if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
  29465. return fromArrayBuffer(value, encodingOrOffset, length);
  29466. }
  29467. if (typeof SharedArrayBuffer !== 'undefined' && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
  29468. return fromArrayBuffer(value, encodingOrOffset, length);
  29469. }
  29470. if (typeof value === 'number') {
  29471. throw new TypeError('The "value" argument must not be of type number. Received type number');
  29472. }
  29473. var valueOf = value.valueOf && value.valueOf();
  29474. if (valueOf != null && valueOf !== value) {
  29475. return Buffer.from(valueOf, encodingOrOffset, length);
  29476. }
  29477. var b = fromObject(value);
  29478. if (b) return b;
  29479. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') {
  29480. return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
  29481. }
  29482. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + babelHelpers["typeof"](value));
  29483. }
  29484. /**
  29485. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  29486. * if value is a number.
  29487. * Buffer.from(str[, encoding])
  29488. * Buffer.from(array)
  29489. * Buffer.from(buffer)
  29490. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  29491. **/
  29492. Buffer.from = function (value, encodingOrOffset, length) {
  29493. return from(value, encodingOrOffset, length);
  29494. }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  29495. // https://github.com/feross/buffer/pull/148
  29496. Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
  29497. Object.setPrototypeOf(Buffer, Uint8Array);
  29498. function assertSize(size) {
  29499. if (typeof size !== 'number') {
  29500. throw new TypeError('"size" argument must be of type number');
  29501. } else if (size < 0) {
  29502. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  29503. }
  29504. }
  29505. function alloc(size, fill, encoding) {
  29506. assertSize(size);
  29507. if (size <= 0) {
  29508. return createBuffer(size);
  29509. }
  29510. if (fill !== undefined) {
  29511. // Only pay attention to encoding if it's a string. This
  29512. // prevents accidentally sending in a number that would
  29513. // be interpreted as a start offset.
  29514. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  29515. }
  29516. return createBuffer(size);
  29517. }
  29518. /**
  29519. * Creates a new filled Buffer instance.
  29520. * alloc(size[, fill[, encoding]])
  29521. **/
  29522. Buffer.alloc = function (size, fill, encoding) {
  29523. return alloc(size, fill, encoding);
  29524. };
  29525. function allocUnsafe(size) {
  29526. assertSize(size);
  29527. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  29528. }
  29529. /**
  29530. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  29531. * */
  29532. Buffer.allocUnsafe = function (size) {
  29533. return allocUnsafe(size);
  29534. };
  29535. /**
  29536. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  29537. */
  29538. Buffer.allocUnsafeSlow = function (size) {
  29539. return allocUnsafe(size);
  29540. };
  29541. function fromString(string, encoding) {
  29542. if (typeof encoding !== 'string' || encoding === '') {
  29543. encoding = 'utf8';
  29544. }
  29545. if (!Buffer.isEncoding(encoding)) {
  29546. throw new TypeError('Unknown encoding: ' + encoding);
  29547. }
  29548. var length = byteLength(string, encoding) | 0;
  29549. var buf = createBuffer(length);
  29550. var actual = buf.write(string, encoding);
  29551. if (actual !== length) {
  29552. // Writing a hex string, for example, that contains invalid characters will
  29553. // cause everything after the first invalid character to be ignored. (e.g.
  29554. // 'abxxcd' will be treated as 'ab')
  29555. buf = buf.slice(0, actual);
  29556. }
  29557. return buf;
  29558. }
  29559. function fromArrayLike(array) {
  29560. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  29561. var buf = createBuffer(length);
  29562. for (var i = 0; i < length; i += 1) {
  29563. buf[i] = array[i] & 255;
  29564. }
  29565. return buf;
  29566. }
  29567. function fromArrayView(arrayView) {
  29568. if (isInstance(arrayView, Uint8Array)) {
  29569. var copy = new Uint8Array(arrayView);
  29570. return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
  29571. }
  29572. return fromArrayLike(arrayView);
  29573. }
  29574. function fromArrayBuffer(array, byteOffset, length) {
  29575. if (byteOffset < 0 || array.byteLength < byteOffset) {
  29576. throw new RangeError('"offset" is outside of buffer bounds');
  29577. }
  29578. if (array.byteLength < byteOffset + (length || 0)) {
  29579. throw new RangeError('"length" is outside of buffer bounds');
  29580. }
  29581. var buf;
  29582. if (byteOffset === undefined && length === undefined) {
  29583. buf = new Uint8Array(array);
  29584. } else if (length === undefined) {
  29585. buf = new Uint8Array(array, byteOffset);
  29586. } else {
  29587. buf = new Uint8Array(array, byteOffset, length);
  29588. } // Return an augmented `Uint8Array` instance
  29589. Object.setPrototypeOf(buf, Buffer.prototype);
  29590. return buf;
  29591. }
  29592. function fromObject(obj) {
  29593. if (Buffer.isBuffer(obj)) {
  29594. var len = checked(obj.length) | 0;
  29595. var buf = createBuffer(len);
  29596. if (buf.length === 0) {
  29597. return buf;
  29598. }
  29599. obj.copy(buf, 0, 0, len);
  29600. return buf;
  29601. }
  29602. if (obj.length !== undefined) {
  29603. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  29604. return createBuffer(0);
  29605. }
  29606. return fromArrayLike(obj);
  29607. }
  29608. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  29609. return fromArrayLike(obj.data);
  29610. }
  29611. }
  29612. function checked(length) {
  29613. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  29614. // length is NaN (which is otherwise coerced to zero.)
  29615. if (length >= K_MAX_LENGTH) {
  29616. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  29617. }
  29618. return length | 0;
  29619. }
  29620. function SlowBuffer(length) {
  29621. if (+length != length) {
  29622. // eslint-disable-line eqeqeq
  29623. length = 0;
  29624. }
  29625. return Buffer.alloc(+length);
  29626. }
  29627. Buffer.isBuffer = function isBuffer(b) {
  29628. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  29629. };
  29630. Buffer.compare = function compare(a, b) {
  29631. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  29632. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  29633. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  29634. throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
  29635. }
  29636. if (a === b) return 0;
  29637. var x = a.length;
  29638. var y = b.length;
  29639. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  29640. if (a[i] !== b[i]) {
  29641. x = a[i];
  29642. y = b[i];
  29643. break;
  29644. }
  29645. }
  29646. if (x < y) return -1;
  29647. if (y < x) return 1;
  29648. return 0;
  29649. };
  29650. Buffer.isEncoding = function isEncoding(encoding) {
  29651. switch (String(encoding).toLowerCase()) {
  29652. case 'hex':
  29653. case 'utf8':
  29654. case 'utf-8':
  29655. case 'ascii':
  29656. case 'latin1':
  29657. case 'binary':
  29658. case 'base64':
  29659. case 'ucs2':
  29660. case 'ucs-2':
  29661. case 'utf16le':
  29662. case 'utf-16le':
  29663. return true;
  29664. default:
  29665. return false;
  29666. }
  29667. };
  29668. Buffer.concat = function concat(list, length) {
  29669. if (!Array.isArray(list)) {
  29670. throw new TypeError('"list" argument must be an Array of Buffers');
  29671. }
  29672. if (list.length === 0) {
  29673. return Buffer.alloc(0);
  29674. }
  29675. var i;
  29676. if (length === undefined) {
  29677. length = 0;
  29678. for (i = 0; i < list.length; ++i) {
  29679. length += list[i].length;
  29680. }
  29681. }
  29682. var buffer = Buffer.allocUnsafe(length);
  29683. var pos = 0;
  29684. for (i = 0; i < list.length; ++i) {
  29685. var buf = list[i];
  29686. if (isInstance(buf, Uint8Array)) {
  29687. if (pos + buf.length > buffer.length) {
  29688. Buffer.from(buf).copy(buffer, pos);
  29689. } else {
  29690. Uint8Array.prototype.set.call(buffer, buf, pos);
  29691. }
  29692. } else if (!Buffer.isBuffer(buf)) {
  29693. throw new TypeError('"list" argument must be an Array of Buffers');
  29694. } else {
  29695. buf.copy(buffer, pos);
  29696. }
  29697. pos += buf.length;
  29698. }
  29699. return buffer;
  29700. };
  29701. function byteLength(string, encoding) {
  29702. if (Buffer.isBuffer(string)) {
  29703. return string.length;
  29704. }
  29705. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  29706. return string.byteLength;
  29707. }
  29708. if (typeof string !== 'string') {
  29709. throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + babelHelpers["typeof"](string));
  29710. }
  29711. var len = string.length;
  29712. var mustMatch = arguments.length > 2 && arguments[2] === true;
  29713. if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion
  29714. var loweredCase = false;
  29715. for (;;) {
  29716. switch (encoding) {
  29717. case 'ascii':
  29718. case 'latin1':
  29719. case 'binary':
  29720. return len;
  29721. case 'utf8':
  29722. case 'utf-8':
  29723. return utf8ToBytes(string).length;
  29724. case 'ucs2':
  29725. case 'ucs-2':
  29726. case 'utf16le':
  29727. case 'utf-16le':
  29728. return len * 2;
  29729. case 'hex':
  29730. return len >>> 1;
  29731. case 'base64':
  29732. return base64ToBytes(string).length;
  29733. default:
  29734. if (loweredCase) {
  29735. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  29736. }
  29737. encoding = ('' + encoding).toLowerCase();
  29738. loweredCase = true;
  29739. }
  29740. }
  29741. }
  29742. Buffer.byteLength = byteLength;
  29743. function slowToString(encoding, start, end) {
  29744. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  29745. // property of a typed array.
  29746. // This behaves neither like String nor Uint8Array in that we set start/end
  29747. // to their upper/lower bounds if the value passed is out of range.
  29748. // undefined is handled specially as per ECMA-262 6th Edition,
  29749. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  29750. if (start === undefined || start < 0) {
  29751. start = 0;
  29752. } // Return early if start > this.length. Done here to prevent potential uint32
  29753. // coercion fail below.
  29754. if (start > this.length) {
  29755. return '';
  29756. }
  29757. if (end === undefined || end > this.length) {
  29758. end = this.length;
  29759. }
  29760. if (end <= 0) {
  29761. return '';
  29762. } // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
  29763. end >>>= 0;
  29764. start >>>= 0;
  29765. if (end <= start) {
  29766. return '';
  29767. }
  29768. if (!encoding) encoding = 'utf8';
  29769. while (true) {
  29770. switch (encoding) {
  29771. case 'hex':
  29772. return hexSlice(this, start, end);
  29773. case 'utf8':
  29774. case 'utf-8':
  29775. return utf8Slice(this, start, end);
  29776. case 'ascii':
  29777. return asciiSlice(this, start, end);
  29778. case 'latin1':
  29779. case 'binary':
  29780. return latin1Slice(this, start, end);
  29781. case 'base64':
  29782. return base64Slice(this, start, end);
  29783. case 'ucs2':
  29784. case 'ucs-2':
  29785. case 'utf16le':
  29786. case 'utf-16le':
  29787. return utf16leSlice(this, start, end);
  29788. default:
  29789. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  29790. encoding = (encoding + '').toLowerCase();
  29791. loweredCase = true;
  29792. }
  29793. }
  29794. } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  29795. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  29796. // reliably in a browserify context because there could be multiple different
  29797. // copies of the 'buffer' package in use. This method works even for Buffer
  29798. // instances that were created from another copy of the `buffer` package.
  29799. // See: https://github.com/feross/buffer/issues/154
  29800. Buffer.prototype._isBuffer = true;
  29801. function swap(b, n, m) {
  29802. var i = b[n];
  29803. b[n] = b[m];
  29804. b[m] = i;
  29805. }
  29806. Buffer.prototype.swap16 = function swap16() {
  29807. var len = this.length;
  29808. if (len % 2 !== 0) {
  29809. throw new RangeError('Buffer size must be a multiple of 16-bits');
  29810. }
  29811. for (var i = 0; i < len; i += 2) {
  29812. swap(this, i, i + 1);
  29813. }
  29814. return this;
  29815. };
  29816. Buffer.prototype.swap32 = function swap32() {
  29817. var len = this.length;
  29818. if (len % 4 !== 0) {
  29819. throw new RangeError('Buffer size must be a multiple of 32-bits');
  29820. }
  29821. for (var i = 0; i < len; i += 4) {
  29822. swap(this, i, i + 3);
  29823. swap(this, i + 1, i + 2);
  29824. }
  29825. return this;
  29826. };
  29827. Buffer.prototype.swap64 = function swap64() {
  29828. var len = this.length;
  29829. if (len % 8 !== 0) {
  29830. throw new RangeError('Buffer size must be a multiple of 64-bits');
  29831. }
  29832. for (var i = 0; i < len; i += 8) {
  29833. swap(this, i, i + 7);
  29834. swap(this, i + 1, i + 6);
  29835. swap(this, i + 2, i + 5);
  29836. swap(this, i + 3, i + 4);
  29837. }
  29838. return this;
  29839. };
  29840. Buffer.prototype.toString = function toString() {
  29841. var length = this.length;
  29842. if (length === 0) return '';
  29843. if (arguments.length === 0) return utf8Slice(this, 0, length);
  29844. return slowToString.apply(this, arguments);
  29845. };
  29846. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  29847. Buffer.prototype.equals = function equals(b) {
  29848. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  29849. if (this === b) return true;
  29850. return Buffer.compare(this, b) === 0;
  29851. };
  29852. Buffer.prototype.inspect = function inspect() {
  29853. var str = '';
  29854. var max = exports.INSPECT_MAX_BYTES;
  29855. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
  29856. if (this.length > max) str += ' ... ';
  29857. return '<Buffer ' + str + '>';
  29858. };
  29859. if (customInspectSymbol) {
  29860. Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
  29861. }
  29862. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  29863. if (isInstance(target, Uint8Array)) {
  29864. target = Buffer.from(target, target.offset, target.byteLength);
  29865. }
  29866. if (!Buffer.isBuffer(target)) {
  29867. throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + babelHelpers["typeof"](target));
  29868. }
  29869. if (start === undefined) {
  29870. start = 0;
  29871. }
  29872. if (end === undefined) {
  29873. end = target ? target.length : 0;
  29874. }
  29875. if (thisStart === undefined) {
  29876. thisStart = 0;
  29877. }
  29878. if (thisEnd === undefined) {
  29879. thisEnd = this.length;
  29880. }
  29881. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  29882. throw new RangeError('out of range index');
  29883. }
  29884. if (thisStart >= thisEnd && start >= end) {
  29885. return 0;
  29886. }
  29887. if (thisStart >= thisEnd) {
  29888. return -1;
  29889. }
  29890. if (start >= end) {
  29891. return 1;
  29892. }
  29893. start >>>= 0;
  29894. end >>>= 0;
  29895. thisStart >>>= 0;
  29896. thisEnd >>>= 0;
  29897. if (this === target) return 0;
  29898. var x = thisEnd - thisStart;
  29899. var y = end - start;
  29900. var len = Math.min(x, y);
  29901. var thisCopy = this.slice(thisStart, thisEnd);
  29902. var targetCopy = target.slice(start, end);
  29903. for (var i = 0; i < len; ++i) {
  29904. if (thisCopy[i] !== targetCopy[i]) {
  29905. x = thisCopy[i];
  29906. y = targetCopy[i];
  29907. break;
  29908. }
  29909. }
  29910. if (x < y) return -1;
  29911. if (y < x) return 1;
  29912. return 0;
  29913. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  29914. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  29915. //
  29916. // Arguments:
  29917. // - buffer - a Buffer to search
  29918. // - val - a string, Buffer, or number
  29919. // - byteOffset - an index into `buffer`; will be clamped to an int32
  29920. // - encoding - an optional encoding, relevant is val is a string
  29921. // - dir - true for indexOf, false for lastIndexOf
  29922. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  29923. // Empty buffer means no match
  29924. if (buffer.length === 0) return -1; // Normalize byteOffset
  29925. if (typeof byteOffset === 'string') {
  29926. encoding = byteOffset;
  29927. byteOffset = 0;
  29928. } else if (byteOffset > 0x7fffffff) {
  29929. byteOffset = 0x7fffffff;
  29930. } else if (byteOffset < -0x80000000) {
  29931. byteOffset = -0x80000000;
  29932. }
  29933. byteOffset = +byteOffset; // Coerce to Number.
  29934. if (numberIsNaN(byteOffset)) {
  29935. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  29936. byteOffset = dir ? 0 : buffer.length - 1;
  29937. } // Normalize byteOffset: negative offsets start from the end of the buffer
  29938. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  29939. if (byteOffset >= buffer.length) {
  29940. if (dir) return -1;else byteOffset = buffer.length - 1;
  29941. } else if (byteOffset < 0) {
  29942. if (dir) byteOffset = 0;else return -1;
  29943. } // Normalize val
  29944. if (typeof val === 'string') {
  29945. val = Buffer.from(val, encoding);
  29946. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  29947. if (Buffer.isBuffer(val)) {
  29948. // Special case: looking for empty string/buffer always fails
  29949. if (val.length === 0) {
  29950. return -1;
  29951. }
  29952. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  29953. } else if (typeof val === 'number') {
  29954. val = val & 0xFF; // Search for a byte value [0-255]
  29955. if (typeof Uint8Array.prototype.indexOf === 'function') {
  29956. if (dir) {
  29957. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  29958. } else {
  29959. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  29960. }
  29961. }
  29962. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  29963. }
  29964. throw new TypeError('val must be string, number or Buffer');
  29965. }
  29966. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  29967. var indexSize = 1;
  29968. var arrLength = arr.length;
  29969. var valLength = val.length;
  29970. if (encoding !== undefined) {
  29971. encoding = String(encoding).toLowerCase();
  29972. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  29973. if (arr.length < 2 || val.length < 2) {
  29974. return -1;
  29975. }
  29976. indexSize = 2;
  29977. arrLength /= 2;
  29978. valLength /= 2;
  29979. byteOffset /= 2;
  29980. }
  29981. }
  29982. function read(buf, i) {
  29983. if (indexSize === 1) {
  29984. return buf[i];
  29985. } else {
  29986. return buf.readUInt16BE(i * indexSize);
  29987. }
  29988. }
  29989. var i;
  29990. if (dir) {
  29991. var foundIndex = -1;
  29992. for (i = byteOffset; i < arrLength; i++) {
  29993. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  29994. if (foundIndex === -1) foundIndex = i;
  29995. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  29996. } else {
  29997. if (foundIndex !== -1) i -= i - foundIndex;
  29998. foundIndex = -1;
  29999. }
  30000. }
  30001. } else {
  30002. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  30003. for (i = byteOffset; i >= 0; i--) {
  30004. var found = true;
  30005. for (var j = 0; j < valLength; j++) {
  30006. if (read(arr, i + j) !== read(val, j)) {
  30007. found = false;
  30008. break;
  30009. }
  30010. }
  30011. if (found) return i;
  30012. }
  30013. }
  30014. return -1;
  30015. }
  30016. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  30017. return this.indexOf(val, byteOffset, encoding) !== -1;
  30018. };
  30019. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  30020. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  30021. };
  30022. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  30023. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  30024. };
  30025. function hexWrite(buf, string, offset, length) {
  30026. offset = Number(offset) || 0;
  30027. var remaining = buf.length - offset;
  30028. if (!length) {
  30029. length = remaining;
  30030. } else {
  30031. length = Number(length);
  30032. if (length > remaining) {
  30033. length = remaining;
  30034. }
  30035. }
  30036. var strLen = string.length;
  30037. if (length > strLen / 2) {
  30038. length = strLen / 2;
  30039. }
  30040. for (var i = 0; i < length; ++i) {
  30041. var parsed = parseInt(string.substr(i * 2, 2), 16);
  30042. if (numberIsNaN(parsed)) return i;
  30043. buf[offset + i] = parsed;
  30044. }
  30045. return i;
  30046. }
  30047. function utf8Write(buf, string, offset, length) {
  30048. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  30049. }
  30050. function asciiWrite(buf, string, offset, length) {
  30051. return blitBuffer(asciiToBytes(string), buf, offset, length);
  30052. }
  30053. function base64Write(buf, string, offset, length) {
  30054. return blitBuffer(base64ToBytes(string), buf, offset, length);
  30055. }
  30056. function ucs2Write(buf, string, offset, length) {
  30057. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  30058. }
  30059. Buffer.prototype.write = function write(string, offset, length, encoding) {
  30060. // Buffer#write(string)
  30061. if (offset === undefined) {
  30062. encoding = 'utf8';
  30063. length = this.length;
  30064. offset = 0; // Buffer#write(string, encoding)
  30065. } else if (length === undefined && typeof offset === 'string') {
  30066. encoding = offset;
  30067. length = this.length;
  30068. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  30069. } else if (isFinite(offset)) {
  30070. offset = offset >>> 0;
  30071. if (isFinite(length)) {
  30072. length = length >>> 0;
  30073. if (encoding === undefined) encoding = 'utf8';
  30074. } else {
  30075. encoding = length;
  30076. length = undefined;
  30077. }
  30078. } else {
  30079. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  30080. }
  30081. var remaining = this.length - offset;
  30082. if (length === undefined || length > remaining) length = remaining;
  30083. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  30084. throw new RangeError('Attempt to write outside buffer bounds');
  30085. }
  30086. if (!encoding) encoding = 'utf8';
  30087. var loweredCase = false;
  30088. for (;;) {
  30089. switch (encoding) {
  30090. case 'hex':
  30091. return hexWrite(this, string, offset, length);
  30092. case 'utf8':
  30093. case 'utf-8':
  30094. return utf8Write(this, string, offset, length);
  30095. case 'ascii':
  30096. case 'latin1':
  30097. case 'binary':
  30098. return asciiWrite(this, string, offset, length);
  30099. case 'base64':
  30100. // Warning: maxLength not taken into account in base64Write
  30101. return base64Write(this, string, offset, length);
  30102. case 'ucs2':
  30103. case 'ucs-2':
  30104. case 'utf16le':
  30105. case 'utf-16le':
  30106. return ucs2Write(this, string, offset, length);
  30107. default:
  30108. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  30109. encoding = ('' + encoding).toLowerCase();
  30110. loweredCase = true;
  30111. }
  30112. }
  30113. };
  30114. Buffer.prototype.toJSON = function toJSON() {
  30115. return {
  30116. type: 'Buffer',
  30117. data: Array.prototype.slice.call(this._arr || this, 0)
  30118. };
  30119. };
  30120. function base64Slice(buf, start, end) {
  30121. if (start === 0 && end === buf.length) {
  30122. return base64Js.fromByteArray(buf);
  30123. } else {
  30124. return base64Js.fromByteArray(buf.slice(start, end));
  30125. }
  30126. }
  30127. function utf8Slice(buf, start, end) {
  30128. end = Math.min(buf.length, end);
  30129. var res = [];
  30130. var i = start;
  30131. while (i < end) {
  30132. var firstByte = buf[i];
  30133. var codePoint = null;
  30134. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  30135. if (i + bytesPerSequence <= end) {
  30136. var secondByte, thirdByte, fourthByte, tempCodePoint;
  30137. switch (bytesPerSequence) {
  30138. case 1:
  30139. if (firstByte < 0x80) {
  30140. codePoint = firstByte;
  30141. }
  30142. break;
  30143. case 2:
  30144. secondByte = buf[i + 1];
  30145. if ((secondByte & 0xC0) === 0x80) {
  30146. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  30147. if (tempCodePoint > 0x7F) {
  30148. codePoint = tempCodePoint;
  30149. }
  30150. }
  30151. break;
  30152. case 3:
  30153. secondByte = buf[i + 1];
  30154. thirdByte = buf[i + 2];
  30155. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  30156. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  30157. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  30158. codePoint = tempCodePoint;
  30159. }
  30160. }
  30161. break;
  30162. case 4:
  30163. secondByte = buf[i + 1];
  30164. thirdByte = buf[i + 2];
  30165. fourthByte = buf[i + 3];
  30166. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  30167. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  30168. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  30169. codePoint = tempCodePoint;
  30170. }
  30171. }
  30172. }
  30173. }
  30174. if (codePoint === null) {
  30175. // we did not generate a valid codePoint so insert a
  30176. // replacement char (U+FFFD) and advance only 1 byte
  30177. codePoint = 0xFFFD;
  30178. bytesPerSequence = 1;
  30179. } else if (codePoint > 0xFFFF) {
  30180. // encode to utf16 (surrogate pair dance)
  30181. codePoint -= 0x10000;
  30182. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  30183. codePoint = 0xDC00 | codePoint & 0x3FF;
  30184. }
  30185. res.push(codePoint);
  30186. i += bytesPerSequence;
  30187. }
  30188. return decodeCodePointsArray(res);
  30189. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  30190. // the lowest limit is Chrome, with 0x10000 args.
  30191. // We go 1 magnitude less, for safety
  30192. var MAX_ARGUMENTS_LENGTH = 0x1000;
  30193. function decodeCodePointsArray(codePoints) {
  30194. var len = codePoints.length;
  30195. if (len <= MAX_ARGUMENTS_LENGTH) {
  30196. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  30197. } // Decode in chunks to avoid "call stack size exceeded".
  30198. var res = '';
  30199. var i = 0;
  30200. while (i < len) {
  30201. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  30202. }
  30203. return res;
  30204. }
  30205. function asciiSlice(buf, start, end) {
  30206. var ret = '';
  30207. end = Math.min(buf.length, end);
  30208. for (var i = start; i < end; ++i) {
  30209. ret += String.fromCharCode(buf[i] & 0x7F);
  30210. }
  30211. return ret;
  30212. }
  30213. function latin1Slice(buf, start, end) {
  30214. var ret = '';
  30215. end = Math.min(buf.length, end);
  30216. for (var i = start; i < end; ++i) {
  30217. ret += String.fromCharCode(buf[i]);
  30218. }
  30219. return ret;
  30220. }
  30221. function hexSlice(buf, start, end) {
  30222. var len = buf.length;
  30223. if (!start || start < 0) start = 0;
  30224. if (!end || end < 0 || end > len) end = len;
  30225. var out = '';
  30226. for (var i = start; i < end; ++i) {
  30227. out += hexSliceLookupTable[buf[i]];
  30228. }
  30229. return out;
  30230. }
  30231. function utf16leSlice(buf, start, end) {
  30232. var bytes = buf.slice(start, end);
  30233. var res = ''; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
  30234. for (var i = 0; i < bytes.length - 1; i += 2) {
  30235. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  30236. }
  30237. return res;
  30238. }
  30239. Buffer.prototype.slice = function slice(start, end) {
  30240. var len = this.length;
  30241. start = ~~start;
  30242. end = end === undefined ? len : ~~end;
  30243. if (start < 0) {
  30244. start += len;
  30245. if (start < 0) start = 0;
  30246. } else if (start > len) {
  30247. start = len;
  30248. }
  30249. if (end < 0) {
  30250. end += len;
  30251. if (end < 0) end = 0;
  30252. } else if (end > len) {
  30253. end = len;
  30254. }
  30255. if (end < start) end = start;
  30256. var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
  30257. Object.setPrototypeOf(newBuf, Buffer.prototype);
  30258. return newBuf;
  30259. };
  30260. /*
  30261. * Need to make sure that buffer isn't trying to write out of bounds.
  30262. */
  30263. function checkOffset(offset, ext, length) {
  30264. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  30265. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  30266. }
  30267. Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  30268. offset = offset >>> 0;
  30269. byteLength = byteLength >>> 0;
  30270. if (!noAssert) checkOffset(offset, byteLength, this.length);
  30271. var val = this[offset];
  30272. var mul = 1;
  30273. var i = 0;
  30274. while (++i < byteLength && (mul *= 0x100)) {
  30275. val += this[offset + i] * mul;
  30276. }
  30277. return val;
  30278. };
  30279. Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  30280. offset = offset >>> 0;
  30281. byteLength = byteLength >>> 0;
  30282. if (!noAssert) {
  30283. checkOffset(offset, byteLength, this.length);
  30284. }
  30285. var val = this[offset + --byteLength];
  30286. var mul = 1;
  30287. while (byteLength > 0 && (mul *= 0x100)) {
  30288. val += this[offset + --byteLength] * mul;
  30289. }
  30290. return val;
  30291. };
  30292. Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  30293. offset = offset >>> 0;
  30294. if (!noAssert) checkOffset(offset, 1, this.length);
  30295. return this[offset];
  30296. };
  30297. Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  30298. offset = offset >>> 0;
  30299. if (!noAssert) checkOffset(offset, 2, this.length);
  30300. return this[offset] | this[offset + 1] << 8;
  30301. };
  30302. Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  30303. offset = offset >>> 0;
  30304. if (!noAssert) checkOffset(offset, 2, this.length);
  30305. return this[offset] << 8 | this[offset + 1];
  30306. };
  30307. Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  30308. offset = offset >>> 0;
  30309. if (!noAssert) checkOffset(offset, 4, this.length);
  30310. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  30311. };
  30312. Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  30313. offset = offset >>> 0;
  30314. if (!noAssert) checkOffset(offset, 4, this.length);
  30315. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  30316. };
  30317. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  30318. offset = offset >>> 0;
  30319. byteLength = byteLength >>> 0;
  30320. if (!noAssert) checkOffset(offset, byteLength, this.length);
  30321. var val = this[offset];
  30322. var mul = 1;
  30323. var i = 0;
  30324. while (++i < byteLength && (mul *= 0x100)) {
  30325. val += this[offset + i] * mul;
  30326. }
  30327. mul *= 0x80;
  30328. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  30329. return val;
  30330. };
  30331. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  30332. offset = offset >>> 0;
  30333. byteLength = byteLength >>> 0;
  30334. if (!noAssert) checkOffset(offset, byteLength, this.length);
  30335. var i = byteLength;
  30336. var mul = 1;
  30337. var val = this[offset + --i];
  30338. while (i > 0 && (mul *= 0x100)) {
  30339. val += this[offset + --i] * mul;
  30340. }
  30341. mul *= 0x80;
  30342. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  30343. return val;
  30344. };
  30345. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  30346. offset = offset >>> 0;
  30347. if (!noAssert) checkOffset(offset, 1, this.length);
  30348. if (!(this[offset] & 0x80)) return this[offset];
  30349. return (0xff - this[offset] + 1) * -1;
  30350. };
  30351. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  30352. offset = offset >>> 0;
  30353. if (!noAssert) checkOffset(offset, 2, this.length);
  30354. var val = this[offset] | this[offset + 1] << 8;
  30355. return val & 0x8000 ? val | 0xFFFF0000 : val;
  30356. };
  30357. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  30358. offset = offset >>> 0;
  30359. if (!noAssert) checkOffset(offset, 2, this.length);
  30360. var val = this[offset + 1] | this[offset] << 8;
  30361. return val & 0x8000 ? val | 0xFFFF0000 : val;
  30362. };
  30363. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  30364. offset = offset >>> 0;
  30365. if (!noAssert) checkOffset(offset, 4, this.length);
  30366. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  30367. };
  30368. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  30369. offset = offset >>> 0;
  30370. if (!noAssert) checkOffset(offset, 4, this.length);
  30371. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  30372. };
  30373. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  30374. offset = offset >>> 0;
  30375. if (!noAssert) checkOffset(offset, 4, this.length);
  30376. return ieee754.read(this, offset, true, 23, 4);
  30377. };
  30378. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  30379. offset = offset >>> 0;
  30380. if (!noAssert) checkOffset(offset, 4, this.length);
  30381. return ieee754.read(this, offset, false, 23, 4);
  30382. };
  30383. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  30384. offset = offset >>> 0;
  30385. if (!noAssert) checkOffset(offset, 8, this.length);
  30386. return ieee754.read(this, offset, true, 52, 8);
  30387. };
  30388. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  30389. offset = offset >>> 0;
  30390. if (!noAssert) checkOffset(offset, 8, this.length);
  30391. return ieee754.read(this, offset, false, 52, 8);
  30392. };
  30393. function checkInt(buf, value, offset, ext, max, min) {
  30394. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  30395. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  30396. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  30397. }
  30398. Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  30399. value = +value;
  30400. offset = offset >>> 0;
  30401. byteLength = byteLength >>> 0;
  30402. if (!noAssert) {
  30403. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  30404. checkInt(this, value, offset, byteLength, maxBytes, 0);
  30405. }
  30406. var mul = 1;
  30407. var i = 0;
  30408. this[offset] = value & 0xFF;
  30409. while (++i < byteLength && (mul *= 0x100)) {
  30410. this[offset + i] = value / mul & 0xFF;
  30411. }
  30412. return offset + byteLength;
  30413. };
  30414. Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  30415. value = +value;
  30416. offset = offset >>> 0;
  30417. byteLength = byteLength >>> 0;
  30418. if (!noAssert) {
  30419. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  30420. checkInt(this, value, offset, byteLength, maxBytes, 0);
  30421. }
  30422. var i = byteLength - 1;
  30423. var mul = 1;
  30424. this[offset + i] = value & 0xFF;
  30425. while (--i >= 0 && (mul *= 0x100)) {
  30426. this[offset + i] = value / mul & 0xFF;
  30427. }
  30428. return offset + byteLength;
  30429. };
  30430. Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  30431. value = +value;
  30432. offset = offset >>> 0;
  30433. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  30434. this[offset] = value & 0xff;
  30435. return offset + 1;
  30436. };
  30437. Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  30438. value = +value;
  30439. offset = offset >>> 0;
  30440. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  30441. this[offset] = value & 0xff;
  30442. this[offset + 1] = value >>> 8;
  30443. return offset + 2;
  30444. };
  30445. Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  30446. value = +value;
  30447. offset = offset >>> 0;
  30448. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  30449. this[offset] = value >>> 8;
  30450. this[offset + 1] = value & 0xff;
  30451. return offset + 2;
  30452. };
  30453. Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  30454. value = +value;
  30455. offset = offset >>> 0;
  30456. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  30457. this[offset + 3] = value >>> 24;
  30458. this[offset + 2] = value >>> 16;
  30459. this[offset + 1] = value >>> 8;
  30460. this[offset] = value & 0xff;
  30461. return offset + 4;
  30462. };
  30463. Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  30464. value = +value;
  30465. offset = offset >>> 0;
  30466. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  30467. this[offset] = value >>> 24;
  30468. this[offset + 1] = value >>> 16;
  30469. this[offset + 2] = value >>> 8;
  30470. this[offset + 3] = value & 0xff;
  30471. return offset + 4;
  30472. };
  30473. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  30474. value = +value;
  30475. offset = offset >>> 0;
  30476. if (!noAssert) {
  30477. var limit = Math.pow(2, 8 * byteLength - 1);
  30478. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  30479. }
  30480. var i = 0;
  30481. var mul = 1;
  30482. var sub = 0;
  30483. this[offset] = value & 0xFF;
  30484. while (++i < byteLength && (mul *= 0x100)) {
  30485. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  30486. sub = 1;
  30487. }
  30488. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  30489. }
  30490. return offset + byteLength;
  30491. };
  30492. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  30493. value = +value;
  30494. offset = offset >>> 0;
  30495. if (!noAssert) {
  30496. var limit = Math.pow(2, 8 * byteLength - 1);
  30497. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  30498. }
  30499. var i = byteLength - 1;
  30500. var mul = 1;
  30501. var sub = 0;
  30502. this[offset + i] = value & 0xFF;
  30503. while (--i >= 0 && (mul *= 0x100)) {
  30504. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  30505. sub = 1;
  30506. }
  30507. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  30508. }
  30509. return offset + byteLength;
  30510. };
  30511. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  30512. value = +value;
  30513. offset = offset >>> 0;
  30514. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  30515. if (value < 0) value = 0xff + value + 1;
  30516. this[offset] = value & 0xff;
  30517. return offset + 1;
  30518. };
  30519. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  30520. value = +value;
  30521. offset = offset >>> 0;
  30522. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  30523. this[offset] = value & 0xff;
  30524. this[offset + 1] = value >>> 8;
  30525. return offset + 2;
  30526. };
  30527. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  30528. value = +value;
  30529. offset = offset >>> 0;
  30530. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  30531. this[offset] = value >>> 8;
  30532. this[offset + 1] = value & 0xff;
  30533. return offset + 2;
  30534. };
  30535. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  30536. value = +value;
  30537. offset = offset >>> 0;
  30538. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  30539. this[offset] = value & 0xff;
  30540. this[offset + 1] = value >>> 8;
  30541. this[offset + 2] = value >>> 16;
  30542. this[offset + 3] = value >>> 24;
  30543. return offset + 4;
  30544. };
  30545. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  30546. value = +value;
  30547. offset = offset >>> 0;
  30548. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  30549. if (value < 0) value = 0xffffffff + value + 1;
  30550. this[offset] = value >>> 24;
  30551. this[offset + 1] = value >>> 16;
  30552. this[offset + 2] = value >>> 8;
  30553. this[offset + 3] = value & 0xff;
  30554. return offset + 4;
  30555. };
  30556. function checkIEEE754(buf, value, offset, ext, max, min) {
  30557. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  30558. if (offset < 0) throw new RangeError('Index out of range');
  30559. }
  30560. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  30561. value = +value;
  30562. offset = offset >>> 0;
  30563. if (!noAssert) {
  30564. checkIEEE754(buf, value, offset, 4);
  30565. }
  30566. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  30567. return offset + 4;
  30568. }
  30569. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  30570. return writeFloat(this, value, offset, true, noAssert);
  30571. };
  30572. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  30573. return writeFloat(this, value, offset, false, noAssert);
  30574. };
  30575. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  30576. value = +value;
  30577. offset = offset >>> 0;
  30578. if (!noAssert) {
  30579. checkIEEE754(buf, value, offset, 8);
  30580. }
  30581. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  30582. return offset + 8;
  30583. }
  30584. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  30585. return writeDouble(this, value, offset, true, noAssert);
  30586. };
  30587. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  30588. return writeDouble(this, value, offset, false, noAssert);
  30589. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  30590. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  30591. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  30592. if (!start) start = 0;
  30593. if (!end && end !== 0) end = this.length;
  30594. if (targetStart >= target.length) targetStart = target.length;
  30595. if (!targetStart) targetStart = 0;
  30596. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  30597. if (end === start) return 0;
  30598. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  30599. if (targetStart < 0) {
  30600. throw new RangeError('targetStart out of bounds');
  30601. }
  30602. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  30603. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  30604. if (end > this.length) end = this.length;
  30605. if (target.length - targetStart < end - start) {
  30606. end = target.length - targetStart + start;
  30607. }
  30608. var len = end - start;
  30609. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  30610. // Use built-in when available, missing from IE11
  30611. this.copyWithin(targetStart, start, end);
  30612. } else {
  30613. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  30614. }
  30615. return len;
  30616. }; // Usage:
  30617. // buffer.fill(number[, offset[, end]])
  30618. // buffer.fill(buffer[, offset[, end]])
  30619. // buffer.fill(string[, offset[, end]][, encoding])
  30620. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  30621. // Handle string cases:
  30622. if (typeof val === 'string') {
  30623. if (typeof start === 'string') {
  30624. encoding = start;
  30625. start = 0;
  30626. end = this.length;
  30627. } else if (typeof end === 'string') {
  30628. encoding = end;
  30629. end = this.length;
  30630. }
  30631. if (encoding !== undefined && typeof encoding !== 'string') {
  30632. throw new TypeError('encoding must be a string');
  30633. }
  30634. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  30635. throw new TypeError('Unknown encoding: ' + encoding);
  30636. }
  30637. if (val.length === 1) {
  30638. var code = val.charCodeAt(0);
  30639. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  30640. // Fast path: If `val` fits into a single byte, use that numeric value.
  30641. val = code;
  30642. }
  30643. }
  30644. } else if (typeof val === 'number') {
  30645. val = val & 255;
  30646. } else if (typeof val === 'boolean') {
  30647. val = Number(val);
  30648. } // Invalid ranges are not set to a default, so can range check early.
  30649. if (start < 0 || this.length < start || this.length < end) {
  30650. throw new RangeError('Out of range index');
  30651. }
  30652. if (end <= start) {
  30653. return this;
  30654. }
  30655. start = start >>> 0;
  30656. end = end === undefined ? this.length : end >>> 0;
  30657. if (!val) val = 0;
  30658. var i;
  30659. if (typeof val === 'number') {
  30660. for (i = start; i < end; ++i) {
  30661. this[i] = val;
  30662. }
  30663. } else {
  30664. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  30665. var len = bytes.length;
  30666. if (len === 0) {
  30667. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  30668. }
  30669. for (i = 0; i < end - start; ++i) {
  30670. this[i + start] = bytes[i % len];
  30671. }
  30672. }
  30673. return this;
  30674. }; // HELPER FUNCTIONS
  30675. // ================
  30676. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  30677. function base64clean(str) {
  30678. // Node takes equal signs as end of the Base64 encoding
  30679. str = str.split('=')[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not
  30680. str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  30681. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  30682. while (str.length % 4 !== 0) {
  30683. str = str + '=';
  30684. }
  30685. return str;
  30686. }
  30687. function utf8ToBytes(string, units) {
  30688. units = units || Infinity;
  30689. var codePoint;
  30690. var length = string.length;
  30691. var leadSurrogate = null;
  30692. var bytes = [];
  30693. for (var i = 0; i < length; ++i) {
  30694. codePoint = string.charCodeAt(i); // is surrogate component
  30695. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  30696. // last char was a lead
  30697. if (!leadSurrogate) {
  30698. // no lead yet
  30699. if (codePoint > 0xDBFF) {
  30700. // unexpected trail
  30701. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  30702. continue;
  30703. } else if (i + 1 === length) {
  30704. // unpaired lead
  30705. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  30706. continue;
  30707. } // valid lead
  30708. leadSurrogate = codePoint;
  30709. continue;
  30710. } // 2 leads in a row
  30711. if (codePoint < 0xDC00) {
  30712. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  30713. leadSurrogate = codePoint;
  30714. continue;
  30715. } // valid surrogate pair
  30716. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  30717. } else if (leadSurrogate) {
  30718. // valid bmp char, but last char was a lead
  30719. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  30720. }
  30721. leadSurrogate = null; // encode utf8
  30722. if (codePoint < 0x80) {
  30723. if ((units -= 1) < 0) break;
  30724. bytes.push(codePoint);
  30725. } else if (codePoint < 0x800) {
  30726. if ((units -= 2) < 0) break;
  30727. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  30728. } else if (codePoint < 0x10000) {
  30729. if ((units -= 3) < 0) break;
  30730. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  30731. } else if (codePoint < 0x110000) {
  30732. if ((units -= 4) < 0) break;
  30733. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  30734. } else {
  30735. throw new Error('Invalid code point');
  30736. }
  30737. }
  30738. return bytes;
  30739. }
  30740. function asciiToBytes(str) {
  30741. var byteArray = [];
  30742. for (var i = 0; i < str.length; ++i) {
  30743. // Node's code seems to be doing this and not & 0x7F..
  30744. byteArray.push(str.charCodeAt(i) & 0xFF);
  30745. }
  30746. return byteArray;
  30747. }
  30748. function utf16leToBytes(str, units) {
  30749. var c, hi, lo;
  30750. var byteArray = [];
  30751. for (var i = 0; i < str.length; ++i) {
  30752. if ((units -= 2) < 0) break;
  30753. c = str.charCodeAt(i);
  30754. hi = c >> 8;
  30755. lo = c % 256;
  30756. byteArray.push(lo);
  30757. byteArray.push(hi);
  30758. }
  30759. return byteArray;
  30760. }
  30761. function base64ToBytes(str) {
  30762. return base64Js.toByteArray(base64clean(str));
  30763. }
  30764. function blitBuffer(src, dst, offset, length) {
  30765. for (var i = 0; i < length; ++i) {
  30766. if (i + offset >= dst.length || i >= src.length) break;
  30767. dst[i + offset] = src[i];
  30768. }
  30769. return i;
  30770. } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  30771. // the `instanceof` check but they should be treated as of that type.
  30772. // See: https://github.com/feross/buffer/issues/166
  30773. function isInstance(obj, type) {
  30774. return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
  30775. }
  30776. function numberIsNaN(obj) {
  30777. // For IE11 support
  30778. return obj !== obj; // eslint-disable-line no-self-compare
  30779. } // Create lookup table for `toString('hex')`
  30780. // See: https://github.com/feross/buffer/issues/219
  30781. var hexSliceLookupTable = function () {
  30782. var alphabet = '0123456789abcdef';
  30783. var table = new Array(256);
  30784. for (var i = 0; i < 16; ++i) {
  30785. var i16 = i * 16;
  30786. for (var j = 0; j < 16; ++j) {
  30787. table[i16 + j] = alphabet[i] + alphabet[j];
  30788. }
  30789. }
  30790. return table;
  30791. }();
  30792. });
  30793. var buffer_1 = buffer$1.Buffer;
  30794. buffer$1.SlowBuffer;
  30795. buffer$1.INSPECT_MAX_BYTES;
  30796. buffer$1.kMaxLength;
  30797. /*! *****************************************************************************
  30798. Copyright (c) Microsoft Corporation.
  30799. Permission to use, copy, modify, and/or distribute this software for any
  30800. purpose with or without fee is hereby granted.
  30801. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  30802. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  30803. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  30804. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  30805. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  30806. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  30807. PERFORMANCE OF THIS SOFTWARE.
  30808. ***************************************************************************** */
  30809. /* global Reflect, Promise */
  30810. var _extendStatics = function extendStatics(d, b) {
  30811. _extendStatics = Object.setPrototypeOf || {
  30812. __proto__: []
  30813. } instanceof Array && function (d, b) {
  30814. d.__proto__ = b;
  30815. } || function (d, b) {
  30816. for (var p in b) {
  30817. if (b.hasOwnProperty(p)) d[p] = b[p];
  30818. }
  30819. };
  30820. return _extendStatics(d, b);
  30821. };
  30822. function __extends(d, b) {
  30823. _extendStatics(d, b);
  30824. function __() {
  30825. this.constructor = d;
  30826. }
  30827. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  30828. }
  30829. var _assign = function __assign() {
  30830. _assign = Object.assign || function __assign(t) {
  30831. for (var s, i = 1, n = arguments.length; i < n; i++) {
  30832. s = arguments[i];
  30833. for (var p in s) {
  30834. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  30835. }
  30836. }
  30837. return t;
  30838. };
  30839. return _assign.apply(this, arguments);
  30840. };
  30841. /** @public */
  30842. var BSONError =
  30843. /** @class */
  30844. function (_super) {
  30845. __extends(BSONError, _super);
  30846. function BSONError(message) {
  30847. var _this = _super.call(this, message) || this;
  30848. Object.setPrototypeOf(_this, BSONError.prototype);
  30849. return _this;
  30850. }
  30851. Object.defineProperty(BSONError.prototype, "name", {
  30852. get: function get() {
  30853. return 'BSONError';
  30854. },
  30855. enumerable: false,
  30856. configurable: true
  30857. });
  30858. return BSONError;
  30859. }(Error);
  30860. /** @public */
  30861. var BSONTypeError =
  30862. /** @class */
  30863. function (_super) {
  30864. __extends(BSONTypeError, _super);
  30865. function BSONTypeError(message) {
  30866. var _this = _super.call(this, message) || this;
  30867. Object.setPrototypeOf(_this, BSONTypeError.prototype);
  30868. return _this;
  30869. }
  30870. Object.defineProperty(BSONTypeError.prototype, "name", {
  30871. get: function get() {
  30872. return 'BSONTypeError';
  30873. },
  30874. enumerable: false,
  30875. configurable: true
  30876. });
  30877. return BSONTypeError;
  30878. }(TypeError);
  30879. function checkForMath(potentialGlobal) {
  30880. // eslint-disable-next-line eqeqeq
  30881. return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
  30882. } // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  30883. function getGlobal() {
  30884. // eslint-disable-next-line no-undef
  30885. return checkForMath((typeof globalThis === "undefined" ? "undefined" : _typeof(globalThis)) === 'object' && globalThis) || checkForMath((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window) || checkForMath((typeof self === "undefined" ? "undefined" : _typeof(self)) === 'object' && self) || checkForMath((typeof __webpack_require__.g === "undefined" ? "undefined" : _typeof(__webpack_require__.g)) === 'object' && __webpack_require__.g) || Function('return this')();
  30886. }
  30887. /**
  30888. * Normalizes our expected stringified form of a function across versions of node
  30889. * @param fn - The function to stringify
  30890. */
  30891. function normalizedFunctionString(fn) {
  30892. return fn.toString().replace('function(', 'function (');
  30893. }
  30894. function isReactNative() {
  30895. var g = getGlobal();
  30896. return _typeof(g.navigator) === 'object' && g.navigator.product === 'ReactNative';
  30897. }
  30898. var insecureRandomBytes = function insecureRandomBytes(size) {
  30899. var insecureWarning = isReactNative() ? 'BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.' : 'BSON: No cryptographic implementation for random bytes present, falling back to a less secure implementation.';
  30900. console.warn(insecureWarning);
  30901. var result = buffer_1.alloc(size);
  30902. for (var i = 0; i < size; ++i) {
  30903. result[i] = Math.floor(Math.random() * 256);
  30904. }
  30905. return result;
  30906. };
  30907. var detectRandomBytes = function detectRandomBytes() {
  30908. if (typeof window !== 'undefined') {
  30909. // browser crypto implementation(s)
  30910. var target_1 = window.crypto || window.msCrypto; // allow for IE11
  30911. if (target_1 && target_1.getRandomValues) {
  30912. return function (size) {
  30913. return target_1.getRandomValues(buffer_1.alloc(size));
  30914. };
  30915. }
  30916. }
  30917. if (typeof __webpack_require__.g !== 'undefined' && __webpack_require__.g.crypto && __webpack_require__.g.crypto.getRandomValues) {
  30918. // allow for RN packages such as https://www.npmjs.com/package/react-native-get-random-values to populate global
  30919. return function (size) {
  30920. return __webpack_require__.g.crypto.getRandomValues(buffer_1.alloc(size));
  30921. };
  30922. }
  30923. var requiredRandomBytes;
  30924. try {
  30925. // eslint-disable-next-line @typescript-eslint/no-var-requires
  30926. requiredRandomBytes = (__webpack_require__(462)/* .randomBytes */ .O6);
  30927. } catch (e) {// keep the fallback
  30928. } // NOTE: in transpiled cases the above require might return null/undefined
  30929. return requiredRandomBytes || insecureRandomBytes;
  30930. };
  30931. var randomBytes = detectRandomBytes();
  30932. function isAnyArrayBuffer(value) {
  30933. return ['[object ArrayBuffer]', '[object SharedArrayBuffer]'].includes(Object.prototype.toString.call(value));
  30934. }
  30935. function isUint8Array(value) {
  30936. return Object.prototype.toString.call(value) === '[object Uint8Array]';
  30937. }
  30938. function isBigInt64Array(value) {
  30939. return Object.prototype.toString.call(value) === '[object BigInt64Array]';
  30940. }
  30941. function isBigUInt64Array(value) {
  30942. return Object.prototype.toString.call(value) === '[object BigUint64Array]';
  30943. }
  30944. function isRegExp(d) {
  30945. return Object.prototype.toString.call(d) === '[object RegExp]';
  30946. }
  30947. function isMap(d) {
  30948. return Object.prototype.toString.call(d) === '[object Map]';
  30949. } // To ensure that 0.4 of node works correctly
  30950. function isDate(d) {
  30951. return isObjectLike(d) && Object.prototype.toString.call(d) === '[object Date]';
  30952. }
  30953. /**
  30954. * @internal
  30955. * this is to solve the `'someKey' in x` problem where x is unknown.
  30956. * https://github.com/typescript-eslint/typescript-eslint/issues/1071#issuecomment-541955753
  30957. */
  30958. function isObjectLike(candidate) {
  30959. return _typeof(candidate) === 'object' && candidate !== null;
  30960. }
  30961. function deprecate(fn, message) {
  30962. var warned = false;
  30963. function deprecated() {
  30964. var args = [];
  30965. for (var _i = 0; _i < arguments.length; _i++) {
  30966. args[_i] = arguments[_i];
  30967. }
  30968. if (!warned) {
  30969. console.warn(message);
  30970. warned = true;
  30971. }
  30972. return fn.apply(this, args);
  30973. }
  30974. return deprecated;
  30975. }
  30976. /**
  30977. * Makes sure that, if a Uint8Array is passed in, it is wrapped in a Buffer.
  30978. *
  30979. * @param potentialBuffer - The potential buffer
  30980. * @returns Buffer the input if potentialBuffer is a buffer, or a buffer that
  30981. * wraps a passed in Uint8Array
  30982. * @throws BSONTypeError If anything other than a Buffer or Uint8Array is passed in
  30983. */
  30984. function ensureBuffer(potentialBuffer) {
  30985. if (ArrayBuffer.isView(potentialBuffer)) {
  30986. return buffer_1.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
  30987. }
  30988. if (isAnyArrayBuffer(potentialBuffer)) {
  30989. return buffer_1.from(potentialBuffer);
  30990. }
  30991. throw new BSONTypeError('Must use either Buffer or TypedArray');
  30992. } // Validation regex for v4 uuid (validates with or without dashes)
  30993. var VALIDATION_REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i;
  30994. var uuidValidateString = function uuidValidateString(str) {
  30995. return typeof str === 'string' && VALIDATION_REGEX.test(str);
  30996. };
  30997. var uuidHexStringToBuffer = function uuidHexStringToBuffer(hexString) {
  30998. if (!uuidValidateString(hexString)) {
  30999. throw new BSONTypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
  31000. }
  31001. var sanitizedHexString = hexString.replace(/-/g, '');
  31002. return buffer_1.from(sanitizedHexString, 'hex');
  31003. };
  31004. var bufferToUuidHexString = function bufferToUuidHexString(buffer, includeDashes) {
  31005. if (includeDashes === void 0) {
  31006. includeDashes = true;
  31007. }
  31008. return includeDashes ? buffer.toString('hex', 0, 4) + '-' + buffer.toString('hex', 4, 6) + '-' + buffer.toString('hex', 6, 8) + '-' + buffer.toString('hex', 8, 10) + '-' + buffer.toString('hex', 10, 16) : buffer.toString('hex');
  31009. };
  31010. var BYTE_LENGTH = 16;
  31011. var kId$1 = Symbol('id');
  31012. /**
  31013. * A class representation of the BSON UUID type.
  31014. * @public
  31015. */
  31016. var UUID =
  31017. /** @class */
  31018. function () {
  31019. /**
  31020. * Create an UUID type
  31021. *
  31022. * @param input - Can be a 32 or 36 character hex string (dashes excluded/included) or a 16 byte binary Buffer.
  31023. */
  31024. function UUID(input) {
  31025. if (typeof input === 'undefined') {
  31026. // The most common use case (blank id, new UUID() instance)
  31027. this.id = UUID.generate();
  31028. } else if (input instanceof UUID) {
  31029. this[kId$1] = buffer_1.from(input.id);
  31030. this.__id = input.__id;
  31031. } else if (ArrayBuffer.isView(input) && input.byteLength === BYTE_LENGTH) {
  31032. this.id = ensureBuffer(input);
  31033. } else if (typeof input === 'string') {
  31034. this.id = uuidHexStringToBuffer(input);
  31035. } else {
  31036. throw new BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
  31037. }
  31038. }
  31039. Object.defineProperty(UUID.prototype, "id", {
  31040. /**
  31041. * The UUID bytes
  31042. * @readonly
  31043. */
  31044. get: function get() {
  31045. return this[kId$1];
  31046. },
  31047. set: function set(value) {
  31048. this[kId$1] = value;
  31049. if (UUID.cacheHexString) {
  31050. this.__id = bufferToUuidHexString(value);
  31051. }
  31052. },
  31053. enumerable: false,
  31054. configurable: true
  31055. });
  31056. /**
  31057. * Generate a 16 byte uuid v4 buffer used in UUIDs
  31058. */
  31059. /**
  31060. * Returns the UUID id as a 32 or 36 character hex string representation, excluding/including dashes (defaults to 36 character dash separated)
  31061. * @param includeDashes - should the string exclude dash-separators.
  31062. * */
  31063. UUID.prototype.toHexString = function (includeDashes) {
  31064. if (includeDashes === void 0) {
  31065. includeDashes = true;
  31066. }
  31067. if (UUID.cacheHexString && this.__id) {
  31068. return this.__id;
  31069. }
  31070. var uuidHexString = bufferToUuidHexString(this.id, includeDashes);
  31071. if (UUID.cacheHexString) {
  31072. this.__id = uuidHexString;
  31073. }
  31074. return uuidHexString;
  31075. };
  31076. /**
  31077. * Converts the id into a 36 character (dashes included) hex string, unless a encoding is specified.
  31078. */
  31079. UUID.prototype.toString = function (encoding) {
  31080. return encoding ? this.id.toString(encoding) : this.toHexString();
  31081. };
  31082. /**
  31083. * Converts the id into its JSON string representation.
  31084. * A 36 character (dashes included) hex string in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  31085. */
  31086. UUID.prototype.toJSON = function () {
  31087. return this.toHexString();
  31088. };
  31089. /**
  31090. * Compares the equality of this UUID with `otherID`.
  31091. *
  31092. * @param otherId - UUID instance to compare against.
  31093. */
  31094. UUID.prototype.equals = function (otherId) {
  31095. if (!otherId) {
  31096. return false;
  31097. }
  31098. if (otherId instanceof UUID) {
  31099. return otherId.id.equals(this.id);
  31100. }
  31101. try {
  31102. return new UUID(otherId).id.equals(this.id);
  31103. } catch (_a) {
  31104. return false;
  31105. }
  31106. };
  31107. /**
  31108. * Creates a Binary instance from the current UUID.
  31109. */
  31110. UUID.prototype.toBinary = function () {
  31111. return new _Binary(this.id, _Binary.SUBTYPE_UUID);
  31112. };
  31113. /**
  31114. * Generates a populated buffer containing a v4 uuid
  31115. */
  31116. UUID.generate = function () {
  31117. var bytes = randomBytes(BYTE_LENGTH); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  31118. // Kindly borrowed from https://github.com/uuidjs/uuid/blob/master/src/v4.js
  31119. bytes[6] = bytes[6] & 0x0f | 0x40;
  31120. bytes[8] = bytes[8] & 0x3f | 0x80;
  31121. return buffer_1.from(bytes);
  31122. };
  31123. /**
  31124. * Checks if a value is a valid bson UUID
  31125. * @param input - UUID, string or Buffer to validate.
  31126. */
  31127. UUID.isValid = function (input) {
  31128. if (!input) {
  31129. return false;
  31130. }
  31131. if (input instanceof UUID) {
  31132. return true;
  31133. }
  31134. if (typeof input === 'string') {
  31135. return uuidValidateString(input);
  31136. }
  31137. if (isUint8Array(input)) {
  31138. // check for length & uuid version (https://tools.ietf.org/html/rfc4122#section-4.1.3)
  31139. if (input.length !== BYTE_LENGTH) {
  31140. return false;
  31141. }
  31142. try {
  31143. // get this byte as hex: xxxxxxxx-xxxx-XXxx-xxxx-xxxxxxxxxxxx
  31144. // check first part as uuid version: xxxxxxxx-xxxx-Xxxx-xxxx-xxxxxxxxxxxx
  31145. return parseInt(input[6].toString(16)[0], 10) === _Binary.SUBTYPE_UUID;
  31146. } catch (_a) {
  31147. return false;
  31148. }
  31149. }
  31150. return false;
  31151. };
  31152. /**
  31153. * Creates an UUID from a hex string representation of an UUID.
  31154. * @param hexString - 32 or 36 character hex string (dashes excluded/included).
  31155. */
  31156. UUID.createFromHexString = function (hexString) {
  31157. var buffer = uuidHexStringToBuffer(hexString);
  31158. return new UUID(buffer);
  31159. };
  31160. /**
  31161. * Converts to a string representation of this Id.
  31162. *
  31163. * @returns return the 36 character hex string representation.
  31164. * @internal
  31165. */
  31166. UUID.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  31167. return this.inspect();
  31168. };
  31169. UUID.prototype.inspect = function () {
  31170. return "new UUID(\"" + this.toHexString() + "\")";
  31171. };
  31172. return UUID;
  31173. }();
  31174. Object.defineProperty(UUID.prototype, '_bsontype', {
  31175. value: 'UUID'
  31176. });
  31177. /**
  31178. * A class representation of the BSON Binary type.
  31179. * @public
  31180. * @category BSONType
  31181. */
  31182. var _Binary =
  31183. /** @class */
  31184. function () {
  31185. /**
  31186. * @param buffer - a buffer object containing the binary data.
  31187. * @param subType - the option binary type.
  31188. */
  31189. function Binary(buffer, subType) {
  31190. if (!(this instanceof Binary)) return new Binary(buffer, subType);
  31191. if (!(buffer == null) && !(typeof buffer === 'string') && !ArrayBuffer.isView(buffer) && !(buffer instanceof ArrayBuffer) && !Array.isArray(buffer)) {
  31192. throw new BSONTypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
  31193. }
  31194. this.sub_type = subType !== null && subType !== void 0 ? subType : Binary.BSON_BINARY_SUBTYPE_DEFAULT;
  31195. if (buffer == null) {
  31196. // create an empty binary buffer
  31197. this.buffer = buffer_1.alloc(Binary.BUFFER_SIZE);
  31198. this.position = 0;
  31199. } else {
  31200. if (typeof buffer === 'string') {
  31201. // string
  31202. this.buffer = buffer_1.from(buffer, 'binary');
  31203. } else if (Array.isArray(buffer)) {
  31204. // number[]
  31205. this.buffer = buffer_1.from(buffer);
  31206. } else {
  31207. // Buffer | TypedArray | ArrayBuffer
  31208. this.buffer = ensureBuffer(buffer);
  31209. }
  31210. this.position = this.buffer.byteLength;
  31211. }
  31212. }
  31213. /**
  31214. * Updates this binary with byte_value.
  31215. *
  31216. * @param byteValue - a single byte we wish to write.
  31217. */
  31218. Binary.prototype.put = function (byteValue) {
  31219. // If it's a string and a has more than one character throw an error
  31220. if (typeof byteValue === 'string' && byteValue.length !== 1) {
  31221. throw new BSONTypeError('only accepts single character String');
  31222. } else if (typeof byteValue !== 'number' && byteValue.length !== 1) throw new BSONTypeError('only accepts single character Uint8Array or Array'); // Decode the byte value once
  31223. var decodedByte;
  31224. if (typeof byteValue === 'string') {
  31225. decodedByte = byteValue.charCodeAt(0);
  31226. } else if (typeof byteValue === 'number') {
  31227. decodedByte = byteValue;
  31228. } else {
  31229. decodedByte = byteValue[0];
  31230. }
  31231. if (decodedByte < 0 || decodedByte > 255) {
  31232. throw new BSONTypeError('only accepts number in a valid unsigned byte range 0-255');
  31233. }
  31234. if (this.buffer.length > this.position) {
  31235. this.buffer[this.position++] = decodedByte;
  31236. } else {
  31237. var buffer = buffer_1.alloc(Binary.BUFFER_SIZE + this.buffer.length); // Combine the two buffers together
  31238. this.buffer.copy(buffer, 0, 0, this.buffer.length);
  31239. this.buffer = buffer;
  31240. this.buffer[this.position++] = decodedByte;
  31241. }
  31242. };
  31243. /**
  31244. * Writes a buffer or string to the binary.
  31245. *
  31246. * @param sequence - a string or buffer to be written to the Binary BSON object.
  31247. * @param offset - specify the binary of where to write the content.
  31248. */
  31249. Binary.prototype.write = function (sequence, offset) {
  31250. offset = typeof offset === 'number' ? offset : this.position; // If the buffer is to small let's extend the buffer
  31251. if (this.buffer.length < offset + sequence.length) {
  31252. var buffer = buffer_1.alloc(this.buffer.length + sequence.length);
  31253. this.buffer.copy(buffer, 0, 0, this.buffer.length); // Assign the new buffer
  31254. this.buffer = buffer;
  31255. }
  31256. if (ArrayBuffer.isView(sequence)) {
  31257. this.buffer.set(ensureBuffer(sequence), offset);
  31258. this.position = offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
  31259. } else if (typeof sequence === 'string') {
  31260. this.buffer.write(sequence, offset, sequence.length, 'binary');
  31261. this.position = offset + sequence.length > this.position ? offset + sequence.length : this.position;
  31262. }
  31263. };
  31264. /**
  31265. * Reads **length** bytes starting at **position**.
  31266. *
  31267. * @param position - read from the given position in the Binary.
  31268. * @param length - the number of bytes to read.
  31269. */
  31270. Binary.prototype.read = function (position, length) {
  31271. length = length && length > 0 ? length : this.position; // Let's return the data based on the type we have
  31272. return this.buffer.slice(position, position + length);
  31273. };
  31274. /**
  31275. * Returns the value of this binary as a string.
  31276. * @param asRaw - Will skip converting to a string
  31277. * @remarks
  31278. * This is handy when calling this function conditionally for some key value pairs and not others
  31279. */
  31280. Binary.prototype.value = function (asRaw) {
  31281. asRaw = !!asRaw; // Optimize to serialize for the situation where the data == size of buffer
  31282. if (asRaw && this.buffer.length === this.position) {
  31283. return this.buffer;
  31284. } // If it's a node.js buffer object
  31285. if (asRaw) {
  31286. return this.buffer.slice(0, this.position);
  31287. }
  31288. return this.buffer.toString('binary', 0, this.position);
  31289. };
  31290. /** the length of the binary sequence */
  31291. Binary.prototype.length = function () {
  31292. return this.position;
  31293. };
  31294. Binary.prototype.toJSON = function () {
  31295. return this.buffer.toString('base64');
  31296. };
  31297. Binary.prototype.toString = function (format) {
  31298. return this.buffer.toString(format);
  31299. };
  31300. /** @internal */
  31301. Binary.prototype.toExtendedJSON = function (options) {
  31302. options = options || {};
  31303. var base64String = this.buffer.toString('base64');
  31304. var subType = Number(this.sub_type).toString(16);
  31305. if (options.legacy) {
  31306. return {
  31307. $binary: base64String,
  31308. $type: subType.length === 1 ? '0' + subType : subType
  31309. };
  31310. }
  31311. return {
  31312. $binary: {
  31313. base64: base64String,
  31314. subType: subType.length === 1 ? '0' + subType : subType
  31315. }
  31316. };
  31317. };
  31318. Binary.prototype.toUUID = function () {
  31319. if (this.sub_type === Binary.SUBTYPE_UUID) {
  31320. return new UUID(this.buffer.slice(0, this.position));
  31321. }
  31322. throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
  31323. };
  31324. /** @internal */
  31325. Binary.fromExtendedJSON = function (doc, options) {
  31326. options = options || {};
  31327. var data;
  31328. var type;
  31329. if ('$binary' in doc) {
  31330. if (options.legacy && typeof doc.$binary === 'string' && '$type' in doc) {
  31331. type = doc.$type ? parseInt(doc.$type, 16) : 0;
  31332. data = buffer_1.from(doc.$binary, 'base64');
  31333. } else {
  31334. if (typeof doc.$binary !== 'string') {
  31335. type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
  31336. data = buffer_1.from(doc.$binary.base64, 'base64');
  31337. }
  31338. }
  31339. } else if ('$uuid' in doc) {
  31340. type = 4;
  31341. data = uuidHexStringToBuffer(doc.$uuid);
  31342. }
  31343. if (!data) {
  31344. throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
  31345. }
  31346. return new Binary(data, type);
  31347. };
  31348. /** @internal */
  31349. Binary.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  31350. return this.inspect();
  31351. };
  31352. Binary.prototype.inspect = function () {
  31353. var asBuffer = this.value(true);
  31354. return "new Binary(Buffer.from(\"" + asBuffer.toString('hex') + "\", \"hex\"), " + this.sub_type + ")";
  31355. };
  31356. /**
  31357. * Binary default subtype
  31358. * @internal
  31359. */
  31360. Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
  31361. /** Initial buffer default size */
  31362. Binary.BUFFER_SIZE = 256;
  31363. /** Default BSON type */
  31364. Binary.SUBTYPE_DEFAULT = 0;
  31365. /** Function BSON type */
  31366. Binary.SUBTYPE_FUNCTION = 1;
  31367. /** Byte Array BSON type */
  31368. Binary.SUBTYPE_BYTE_ARRAY = 2;
  31369. /** Deprecated UUID BSON type @deprecated Please use SUBTYPE_UUID */
  31370. Binary.SUBTYPE_UUID_OLD = 3;
  31371. /** UUID BSON type */
  31372. Binary.SUBTYPE_UUID = 4;
  31373. /** MD5 BSON type */
  31374. Binary.SUBTYPE_MD5 = 5;
  31375. /** Encrypted BSON type */
  31376. Binary.SUBTYPE_ENCRYPTED = 6;
  31377. /** Column BSON type */
  31378. Binary.SUBTYPE_COLUMN = 7;
  31379. /** User BSON type */
  31380. Binary.SUBTYPE_USER_DEFINED = 128;
  31381. return Binary;
  31382. }();
  31383. Object.defineProperty(_Binary.prototype, '_bsontype', {
  31384. value: 'Binary'
  31385. });
  31386. /**
  31387. * A class representation of the BSON Code type.
  31388. * @public
  31389. * @category BSONType
  31390. */
  31391. var _Code =
  31392. /** @class */
  31393. function () {
  31394. /**
  31395. * @param code - a string or function.
  31396. * @param scope - an optional scope for the function.
  31397. */
  31398. function Code(code, scope) {
  31399. if (!(this instanceof Code)) return new Code(code, scope);
  31400. this.code = code;
  31401. this.scope = scope;
  31402. }
  31403. Code.prototype.toJSON = function () {
  31404. return {
  31405. code: this.code,
  31406. scope: this.scope
  31407. };
  31408. };
  31409. /** @internal */
  31410. Code.prototype.toExtendedJSON = function () {
  31411. if (this.scope) {
  31412. return {
  31413. $code: this.code,
  31414. $scope: this.scope
  31415. };
  31416. }
  31417. return {
  31418. $code: this.code
  31419. };
  31420. };
  31421. /** @internal */
  31422. Code.fromExtendedJSON = function (doc) {
  31423. return new Code(doc.$code, doc.$scope);
  31424. };
  31425. /** @internal */
  31426. Code.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  31427. return this.inspect();
  31428. };
  31429. Code.prototype.inspect = function () {
  31430. var codeJson = this.toJSON();
  31431. return "new Code(\"" + codeJson.code + "\"" + (codeJson.scope ? ", " + JSON.stringify(codeJson.scope) : '') + ")";
  31432. };
  31433. return Code;
  31434. }();
  31435. Object.defineProperty(_Code.prototype, '_bsontype', {
  31436. value: 'Code'
  31437. });
  31438. /** @internal */
  31439. function isDBRefLike(value) {
  31440. return isObjectLike(value) && value.$id != null && typeof value.$ref === 'string' && (value.$db == null || typeof value.$db === 'string');
  31441. }
  31442. /**
  31443. * A class representation of the BSON DBRef type.
  31444. * @public
  31445. * @category BSONType
  31446. */
  31447. var _DBRef =
  31448. /** @class */
  31449. function () {
  31450. /**
  31451. * @param collection - the collection name.
  31452. * @param oid - the reference ObjectId.
  31453. * @param db - optional db name, if omitted the reference is local to the current db.
  31454. */
  31455. function DBRef(collection, oid, db, fields) {
  31456. if (!(this instanceof DBRef)) return new DBRef(collection, oid, db, fields); // check if namespace has been provided
  31457. var parts = collection.split('.');
  31458. if (parts.length === 2) {
  31459. db = parts.shift(); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  31460. collection = parts.shift();
  31461. }
  31462. this.collection = collection;
  31463. this.oid = oid;
  31464. this.db = db;
  31465. this.fields = fields || {};
  31466. }
  31467. Object.defineProperty(DBRef.prototype, "namespace", {
  31468. // Property provided for compatibility with the 1.x parser
  31469. // the 1.x parser used a "namespace" property, while 4.x uses "collection"
  31470. /** @internal */
  31471. get: function get() {
  31472. return this.collection;
  31473. },
  31474. set: function set(value) {
  31475. this.collection = value;
  31476. },
  31477. enumerable: false,
  31478. configurable: true
  31479. });
  31480. DBRef.prototype.toJSON = function () {
  31481. var o = Object.assign({
  31482. $ref: this.collection,
  31483. $id: this.oid
  31484. }, this.fields);
  31485. if (this.db != null) o.$db = this.db;
  31486. return o;
  31487. };
  31488. /** @internal */
  31489. DBRef.prototype.toExtendedJSON = function (options) {
  31490. options = options || {};
  31491. var o = {
  31492. $ref: this.collection,
  31493. $id: this.oid
  31494. };
  31495. if (options.legacy) {
  31496. return o;
  31497. }
  31498. if (this.db) o.$db = this.db;
  31499. o = Object.assign(o, this.fields);
  31500. return o;
  31501. };
  31502. /** @internal */
  31503. DBRef.fromExtendedJSON = function (doc) {
  31504. var copy = Object.assign({}, doc);
  31505. delete copy.$ref;
  31506. delete copy.$id;
  31507. delete copy.$db;
  31508. return new DBRef(doc.$ref, doc.$id, doc.$db, copy);
  31509. };
  31510. /** @internal */
  31511. DBRef.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  31512. return this.inspect();
  31513. };
  31514. DBRef.prototype.inspect = function () {
  31515. // NOTE: if OID is an ObjectId class it will just print the oid string.
  31516. var oid = this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
  31517. return "new DBRef(\"" + this.namespace + "\", new ObjectId(\"" + oid + "\")" + (this.db ? ", \"" + this.db + "\"" : '') + ")";
  31518. };
  31519. return DBRef;
  31520. }();
  31521. Object.defineProperty(_DBRef.prototype, '_bsontype', {
  31522. value: 'DBRef'
  31523. });
  31524. /**
  31525. * wasm optimizations, to do native i64 multiplication and divide
  31526. */
  31527. var wasm = undefined;
  31528. try {
  31529. wasm = new WebAssembly.Instance(new WebAssembly.Module( // prettier-ignore
  31530. 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;
  31531. } catch (_a) {// no wasm support
  31532. }
  31533. var TWO_PWR_16_DBL = 1 << 16;
  31534. var TWO_PWR_24_DBL = 1 << 24;
  31535. var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
  31536. var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
  31537. var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
  31538. /** A cache of the Long representations of small integer values. */
  31539. var INT_CACHE = {};
  31540. /** A cache of the Long representations of small unsigned integer values. */
  31541. var UINT_CACHE = {};
  31542. /**
  31543. * A class representing a 64-bit integer
  31544. * @public
  31545. * @category BSONType
  31546. * @remarks
  31547. * The internal representation of a long is the two given signed, 32-bit values.
  31548. * We use 32-bit pieces because these are the size of integers on which
  31549. * Javascript performs bit-operations. For operations like addition and
  31550. * multiplication, we split each number into 16 bit pieces, which can easily be
  31551. * multiplied within Javascript's floating-point representation without overflow
  31552. * or change in sign.
  31553. * In the algorithms below, we frequently reduce the negative case to the
  31554. * positive case by negating the input(s) and then post-processing the result.
  31555. * Note that we must ALWAYS check specially whether those values are MIN_VALUE
  31556. * (-2^63) because -MIN_VALUE == MIN_VALUE (since 2^63 cannot be represented as
  31557. * a positive number, it overflows back into a negative). Not handling this
  31558. * case would often result in infinite recursion.
  31559. * Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
  31560. */
  31561. var _Long =
  31562. /** @class */
  31563. function () {
  31564. /**
  31565. * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
  31566. * See the from* functions below for more convenient ways of constructing Longs.
  31567. *
  31568. * Acceptable signatures are:
  31569. * - Long(low, high, unsigned?)
  31570. * - Long(bigint, unsigned?)
  31571. * - Long(string, unsigned?)
  31572. *
  31573. * @param low - The low (signed) 32 bits of the long
  31574. * @param high - The high (signed) 32 bits of the long
  31575. * @param unsigned - Whether unsigned or not, defaults to signed
  31576. */
  31577. function Long(low, high, unsigned) {
  31578. if (low === void 0) {
  31579. low = 0;
  31580. }
  31581. if (!(this instanceof Long)) return new Long(low, high, unsigned);
  31582. if (typeof low === 'bigint') {
  31583. Object.assign(this, Long.fromBigInt(low, !!high));
  31584. } else if (typeof low === 'string') {
  31585. Object.assign(this, Long.fromString(low, !!high));
  31586. } else {
  31587. this.low = low | 0;
  31588. this.high = high | 0;
  31589. this.unsigned = !!unsigned;
  31590. }
  31591. Object.defineProperty(this, '__isLong__', {
  31592. value: true,
  31593. configurable: false,
  31594. writable: false,
  31595. enumerable: false
  31596. });
  31597. }
  31598. /**
  31599. * Returns a Long representing the 64 bit integer that comes by concatenating the given low and high bits.
  31600. * Each is assumed to use 32 bits.
  31601. * @param lowBits - The low 32 bits
  31602. * @param highBits - The high 32 bits
  31603. * @param unsigned - Whether unsigned or not, defaults to signed
  31604. * @returns The corresponding Long value
  31605. */
  31606. Long.fromBits = function (lowBits, highBits, unsigned) {
  31607. return new Long(lowBits, highBits, unsigned);
  31608. };
  31609. /**
  31610. * Returns a Long representing the given 32 bit integer value.
  31611. * @param value - The 32 bit integer in question
  31612. * @param unsigned - Whether unsigned or not, defaults to signed
  31613. * @returns The corresponding Long value
  31614. */
  31615. Long.fromInt = function (value, unsigned) {
  31616. var obj, cachedObj, cache;
  31617. if (unsigned) {
  31618. value >>>= 0;
  31619. if (cache = 0 <= value && value < 256) {
  31620. cachedObj = UINT_CACHE[value];
  31621. if (cachedObj) return cachedObj;
  31622. }
  31623. obj = Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
  31624. if (cache) UINT_CACHE[value] = obj;
  31625. return obj;
  31626. } else {
  31627. value |= 0;
  31628. if (cache = -128 <= value && value < 128) {
  31629. cachedObj = INT_CACHE[value];
  31630. if (cachedObj) return cachedObj;
  31631. }
  31632. obj = Long.fromBits(value, value < 0 ? -1 : 0, false);
  31633. if (cache) INT_CACHE[value] = obj;
  31634. return obj;
  31635. }
  31636. };
  31637. /**
  31638. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  31639. * @param value - The number in question
  31640. * @param unsigned - Whether unsigned or not, defaults to signed
  31641. * @returns The corresponding Long value
  31642. */
  31643. Long.fromNumber = function (value, unsigned) {
  31644. if (isNaN(value)) return unsigned ? Long.UZERO : Long.ZERO;
  31645. if (unsigned) {
  31646. if (value < 0) return Long.UZERO;
  31647. if (value >= TWO_PWR_64_DBL) return Long.MAX_UNSIGNED_VALUE;
  31648. } else {
  31649. if (value <= -TWO_PWR_63_DBL) return Long.MIN_VALUE;
  31650. if (value + 1 >= TWO_PWR_63_DBL) return Long.MAX_VALUE;
  31651. }
  31652. if (value < 0) return Long.fromNumber(-value, unsigned).neg();
  31653. return Long.fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
  31654. };
  31655. /**
  31656. * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
  31657. * @param value - The number in question
  31658. * @param unsigned - Whether unsigned or not, defaults to signed
  31659. * @returns The corresponding Long value
  31660. */
  31661. Long.fromBigInt = function (value, unsigned) {
  31662. return Long.fromString(value.toString(), unsigned);
  31663. };
  31664. /**
  31665. * Returns a Long representation of the given string, written using the specified radix.
  31666. * @param str - The textual representation of the Long
  31667. * @param unsigned - Whether unsigned or not, defaults to signed
  31668. * @param radix - The radix in which the text is written (2-36), defaults to 10
  31669. * @returns The corresponding Long value
  31670. */
  31671. Long.fromString = function (str, unsigned, radix) {
  31672. if (str.length === 0) throw Error('empty string');
  31673. if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity') return Long.ZERO;
  31674. if (typeof unsigned === 'number') {
  31675. // For goog.math.long compatibility
  31676. radix = unsigned, unsigned = false;
  31677. } else {
  31678. unsigned = !!unsigned;
  31679. }
  31680. radix = radix || 10;
  31681. if (radix < 2 || 36 < radix) throw RangeError('radix');
  31682. var p;
  31683. if ((p = str.indexOf('-')) > 0) throw Error('interior hyphen');else if (p === 0) {
  31684. return Long.fromString(str.substring(1), unsigned, radix).neg();
  31685. } // Do several (8) digits each time through the loop, so as to
  31686. // minimize the calls to the very expensive emulated div.
  31687. var radixToPower = Long.fromNumber(Math.pow(radix, 8));
  31688. var result = Long.ZERO;
  31689. for (var i = 0; i < str.length; i += 8) {
  31690. var size = Math.min(8, str.length - i),
  31691. value = parseInt(str.substring(i, i + size), radix);
  31692. if (size < 8) {
  31693. var power = Long.fromNumber(Math.pow(radix, size));
  31694. result = result.mul(power).add(Long.fromNumber(value));
  31695. } else {
  31696. result = result.mul(radixToPower);
  31697. result = result.add(Long.fromNumber(value));
  31698. }
  31699. }
  31700. result.unsigned = unsigned;
  31701. return result;
  31702. };
  31703. /**
  31704. * Creates a Long from its byte representation.
  31705. * @param bytes - Byte representation
  31706. * @param unsigned - Whether unsigned or not, defaults to signed
  31707. * @param le - Whether little or big endian, defaults to big endian
  31708. * @returns The corresponding Long value
  31709. */
  31710. Long.fromBytes = function (bytes, unsigned, le) {
  31711. return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
  31712. };
  31713. /**
  31714. * Creates a Long from its little endian byte representation.
  31715. * @param bytes - Little endian byte representation
  31716. * @param unsigned - Whether unsigned or not, defaults to signed
  31717. * @returns The corresponding Long value
  31718. */
  31719. Long.fromBytesLE = function (bytes, unsigned) {
  31720. 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);
  31721. };
  31722. /**
  31723. * Creates a Long from its big endian byte representation.
  31724. * @param bytes - Big endian byte representation
  31725. * @param unsigned - Whether unsigned or not, defaults to signed
  31726. * @returns The corresponding Long value
  31727. */
  31728. Long.fromBytesBE = function (bytes, unsigned) {
  31729. 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);
  31730. };
  31731. /**
  31732. * Tests if the specified object is a Long.
  31733. */
  31734. // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
  31735. Long.isLong = function (value) {
  31736. return isObjectLike(value) && value['__isLong__'] === true;
  31737. };
  31738. /**
  31739. * Converts the specified value to a Long.
  31740. * @param unsigned - Whether unsigned or not, defaults to signed
  31741. */
  31742. Long.fromValue = function (val, unsigned) {
  31743. if (typeof val === 'number') return Long.fromNumber(val, unsigned);
  31744. if (typeof val === 'string') return Long.fromString(val, unsigned); // Throws for non-objects, converts non-instanceof Long:
  31745. return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
  31746. };
  31747. /** Returns the sum of this and the specified Long. */
  31748. Long.prototype.add = function (addend) {
  31749. if (!Long.isLong(addend)) addend = Long.fromValue(addend); // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
  31750. var a48 = this.high >>> 16;
  31751. var a32 = this.high & 0xffff;
  31752. var a16 = this.low >>> 16;
  31753. var a00 = this.low & 0xffff;
  31754. var b48 = addend.high >>> 16;
  31755. var b32 = addend.high & 0xffff;
  31756. var b16 = addend.low >>> 16;
  31757. var b00 = addend.low & 0xffff;
  31758. var c48 = 0,
  31759. c32 = 0,
  31760. c16 = 0,
  31761. c00 = 0;
  31762. c00 += a00 + b00;
  31763. c16 += c00 >>> 16;
  31764. c00 &= 0xffff;
  31765. c16 += a16 + b16;
  31766. c32 += c16 >>> 16;
  31767. c16 &= 0xffff;
  31768. c32 += a32 + b32;
  31769. c48 += c32 >>> 16;
  31770. c32 &= 0xffff;
  31771. c48 += a48 + b48;
  31772. c48 &= 0xffff;
  31773. return Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  31774. };
  31775. /**
  31776. * Returns the sum of this and the specified Long.
  31777. * @returns Sum
  31778. */
  31779. Long.prototype.and = function (other) {
  31780. if (!Long.isLong(other)) other = Long.fromValue(other);
  31781. return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
  31782. };
  31783. /**
  31784. * Compares this Long's value with the specified's.
  31785. * @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
  31786. */
  31787. Long.prototype.compare = function (other) {
  31788. if (!Long.isLong(other)) other = Long.fromValue(other);
  31789. if (this.eq(other)) return 0;
  31790. var thisNeg = this.isNegative(),
  31791. otherNeg = other.isNegative();
  31792. if (thisNeg && !otherNeg) return -1;
  31793. if (!thisNeg && otherNeg) return 1; // At this point the sign bits are the same
  31794. if (!this.unsigned) return this.sub(other).isNegative() ? -1 : 1; // Both are positive if at least one is unsigned
  31795. return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
  31796. };
  31797. /** This is an alias of {@link Long.compare} */
  31798. Long.prototype.comp = function (other) {
  31799. return this.compare(other);
  31800. };
  31801. /**
  31802. * Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
  31803. * @returns Quotient
  31804. */
  31805. Long.prototype.divide = function (divisor) {
  31806. if (!Long.isLong(divisor)) divisor = Long.fromValue(divisor);
  31807. if (divisor.isZero()) throw Error('division by zero'); // use wasm support if present
  31808. if (wasm) {
  31809. // guard against signed division overflow: the largest
  31810. // negative number / -1 would be 1 larger than the largest
  31811. // positive number, due to two's complement.
  31812. if (!this.unsigned && this.high === -0x80000000 && divisor.low === -1 && divisor.high === -1) {
  31813. // be consistent with non-wasm code path
  31814. return this;
  31815. }
  31816. var low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
  31817. return Long.fromBits(low, wasm.get_high(), this.unsigned);
  31818. }
  31819. if (this.isZero()) return this.unsigned ? Long.UZERO : Long.ZERO;
  31820. var approx, rem, res;
  31821. if (!this.unsigned) {
  31822. // This section is only relevant for signed longs and is derived from the
  31823. // closure library as a whole.
  31824. if (this.eq(Long.MIN_VALUE)) {
  31825. if (divisor.eq(Long.ONE) || divisor.eq(Long.NEG_ONE)) return Long.MIN_VALUE; // recall that -MIN_VALUE == MIN_VALUE
  31826. else if (divisor.eq(Long.MIN_VALUE)) return Long.ONE;else {
  31827. // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
  31828. var halfThis = this.shr(1);
  31829. approx = halfThis.div(divisor).shl(1);
  31830. if (approx.eq(Long.ZERO)) {
  31831. return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
  31832. } else {
  31833. rem = this.sub(divisor.mul(approx));
  31834. res = approx.add(rem.div(divisor));
  31835. return res;
  31836. }
  31837. }
  31838. } else if (divisor.eq(Long.MIN_VALUE)) return this.unsigned ? Long.UZERO : Long.ZERO;
  31839. if (this.isNegative()) {
  31840. if (divisor.isNegative()) return this.neg().div(divisor.neg());
  31841. return this.neg().div(divisor).neg();
  31842. } else if (divisor.isNegative()) return this.div(divisor.neg()).neg();
  31843. res = Long.ZERO;
  31844. } else {
  31845. // The algorithm below has not been made for unsigned longs. It's therefore
  31846. // required to take special care of the MSB prior to running it.
  31847. if (!divisor.unsigned) divisor = divisor.toUnsigned();
  31848. if (divisor.gt(this)) return Long.UZERO;
  31849. if (divisor.gt(this.shru(1))) // 15 >>> 1 = 7 ; with divisor = 8 ; true
  31850. return Long.UONE;
  31851. res = Long.UZERO;
  31852. } // Repeat the following until the remainder is less than other: find a
  31853. // floating-point that approximates remainder / other *from below*, add this
  31854. // into the result, and subtract it from the remainder. It is critical that
  31855. // the approximate value is less than or equal to the real value so that the
  31856. // remainder never becomes negative.
  31857. rem = this;
  31858. while (rem.gte(divisor)) {
  31859. // Approximate the result of division. This may be a little greater or
  31860. // smaller than the actual value.
  31861. 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
  31862. // the smallest non-fractional digit, whichever is larger.
  31863. var log2 = Math.ceil(Math.log(approx) / Math.LN2);
  31864. var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48); // Decrease the approximation until it is smaller than the remainder. Note
  31865. // that if it is too large, the product overflows and is negative.
  31866. var approxRes = Long.fromNumber(approx);
  31867. var approxRem = approxRes.mul(divisor);
  31868. while (approxRem.isNegative() || approxRem.gt(rem)) {
  31869. approx -= delta;
  31870. approxRes = Long.fromNumber(approx, this.unsigned);
  31871. approxRem = approxRes.mul(divisor);
  31872. } // We know the answer can't be zero... and actually, zero would cause
  31873. // infinite recursion since we would make no progress.
  31874. if (approxRes.isZero()) approxRes = Long.ONE;
  31875. res = res.add(approxRes);
  31876. rem = rem.sub(approxRem);
  31877. }
  31878. return res;
  31879. };
  31880. /**This is an alias of {@link Long.divide} */
  31881. Long.prototype.div = function (divisor) {
  31882. return this.divide(divisor);
  31883. };
  31884. /**
  31885. * Tests if this Long's value equals the specified's.
  31886. * @param other - Other value
  31887. */
  31888. Long.prototype.equals = function (other) {
  31889. if (!Long.isLong(other)) other = Long.fromValue(other);
  31890. if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1) return false;
  31891. return this.high === other.high && this.low === other.low;
  31892. };
  31893. /** This is an alias of {@link Long.equals} */
  31894. Long.prototype.eq = function (other) {
  31895. return this.equals(other);
  31896. };
  31897. /** Gets the high 32 bits as a signed integer. */
  31898. Long.prototype.getHighBits = function () {
  31899. return this.high;
  31900. };
  31901. /** Gets the high 32 bits as an unsigned integer. */
  31902. Long.prototype.getHighBitsUnsigned = function () {
  31903. return this.high >>> 0;
  31904. };
  31905. /** Gets the low 32 bits as a signed integer. */
  31906. Long.prototype.getLowBits = function () {
  31907. return this.low;
  31908. };
  31909. /** Gets the low 32 bits as an unsigned integer. */
  31910. Long.prototype.getLowBitsUnsigned = function () {
  31911. return this.low >>> 0;
  31912. };
  31913. /** Gets the number of bits needed to represent the absolute value of this Long. */
  31914. Long.prototype.getNumBitsAbs = function () {
  31915. if (this.isNegative()) {
  31916. // Unsigned Longs are never negative
  31917. return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
  31918. }
  31919. var val = this.high !== 0 ? this.high : this.low;
  31920. var bit;
  31921. for (bit = 31; bit > 0; bit--) {
  31922. if ((val & 1 << bit) !== 0) break;
  31923. }
  31924. return this.high !== 0 ? bit + 33 : bit + 1;
  31925. };
  31926. /** Tests if this Long's value is greater than the specified's. */
  31927. Long.prototype.greaterThan = function (other) {
  31928. return this.comp(other) > 0;
  31929. };
  31930. /** This is an alias of {@link Long.greaterThan} */
  31931. Long.prototype.gt = function (other) {
  31932. return this.greaterThan(other);
  31933. };
  31934. /** Tests if this Long's value is greater than or equal the specified's. */
  31935. Long.prototype.greaterThanOrEqual = function (other) {
  31936. return this.comp(other) >= 0;
  31937. };
  31938. /** This is an alias of {@link Long.greaterThanOrEqual} */
  31939. Long.prototype.gte = function (other) {
  31940. return this.greaterThanOrEqual(other);
  31941. };
  31942. /** This is an alias of {@link Long.greaterThanOrEqual} */
  31943. Long.prototype.ge = function (other) {
  31944. return this.greaterThanOrEqual(other);
  31945. };
  31946. /** Tests if this Long's value is even. */
  31947. Long.prototype.isEven = function () {
  31948. return (this.low & 1) === 0;
  31949. };
  31950. /** Tests if this Long's value is negative. */
  31951. Long.prototype.isNegative = function () {
  31952. return !this.unsigned && this.high < 0;
  31953. };
  31954. /** Tests if this Long's value is odd. */
  31955. Long.prototype.isOdd = function () {
  31956. return (this.low & 1) === 1;
  31957. };
  31958. /** Tests if this Long's value is positive. */
  31959. Long.prototype.isPositive = function () {
  31960. return this.unsigned || this.high >= 0;
  31961. };
  31962. /** Tests if this Long's value equals zero. */
  31963. Long.prototype.isZero = function () {
  31964. return this.high === 0 && this.low === 0;
  31965. };
  31966. /** Tests if this Long's value is less than the specified's. */
  31967. Long.prototype.lessThan = function (other) {
  31968. return this.comp(other) < 0;
  31969. };
  31970. /** This is an alias of {@link Long#lessThan}. */
  31971. Long.prototype.lt = function (other) {
  31972. return this.lessThan(other);
  31973. };
  31974. /** Tests if this Long's value is less than or equal the specified's. */
  31975. Long.prototype.lessThanOrEqual = function (other) {
  31976. return this.comp(other) <= 0;
  31977. };
  31978. /** This is an alias of {@link Long.lessThanOrEqual} */
  31979. Long.prototype.lte = function (other) {
  31980. return this.lessThanOrEqual(other);
  31981. };
  31982. /** Returns this Long modulo the specified. */
  31983. Long.prototype.modulo = function (divisor) {
  31984. if (!Long.isLong(divisor)) divisor = Long.fromValue(divisor); // use wasm support if present
  31985. if (wasm) {
  31986. var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
  31987. return Long.fromBits(low, wasm.get_high(), this.unsigned);
  31988. }
  31989. return this.sub(this.div(divisor).mul(divisor));
  31990. };
  31991. /** This is an alias of {@link Long.modulo} */
  31992. Long.prototype.mod = function (divisor) {
  31993. return this.modulo(divisor);
  31994. };
  31995. /** This is an alias of {@link Long.modulo} */
  31996. Long.prototype.rem = function (divisor) {
  31997. return this.modulo(divisor);
  31998. };
  31999. /**
  32000. * Returns the product of this and the specified Long.
  32001. * @param multiplier - Multiplier
  32002. * @returns Product
  32003. */
  32004. Long.prototype.multiply = function (multiplier) {
  32005. if (this.isZero()) return Long.ZERO;
  32006. if (!Long.isLong(multiplier)) multiplier = Long.fromValue(multiplier); // use wasm support if present
  32007. if (wasm) {
  32008. var low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
  32009. return Long.fromBits(low, wasm.get_high(), this.unsigned);
  32010. }
  32011. if (multiplier.isZero()) return Long.ZERO;
  32012. if (this.eq(Long.MIN_VALUE)) return multiplier.isOdd() ? Long.MIN_VALUE : Long.ZERO;
  32013. if (multiplier.eq(Long.MIN_VALUE)) return this.isOdd() ? Long.MIN_VALUE : Long.ZERO;
  32014. if (this.isNegative()) {
  32015. if (multiplier.isNegative()) return this.neg().mul(multiplier.neg());else return this.neg().mul(multiplier).neg();
  32016. } else if (multiplier.isNegative()) return this.mul(multiplier.neg()).neg(); // If both longs are small, use float multiplication
  32017. if (this.lt(Long.TWO_PWR_24) && multiplier.lt(Long.TWO_PWR_24)) return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned); // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
  32018. // We can skip products that would overflow.
  32019. var a48 = this.high >>> 16;
  32020. var a32 = this.high & 0xffff;
  32021. var a16 = this.low >>> 16;
  32022. var a00 = this.low & 0xffff;
  32023. var b48 = multiplier.high >>> 16;
  32024. var b32 = multiplier.high & 0xffff;
  32025. var b16 = multiplier.low >>> 16;
  32026. var b00 = multiplier.low & 0xffff;
  32027. var c48 = 0,
  32028. c32 = 0,
  32029. c16 = 0,
  32030. c00 = 0;
  32031. c00 += a00 * b00;
  32032. c16 += c00 >>> 16;
  32033. c00 &= 0xffff;
  32034. c16 += a16 * b00;
  32035. c32 += c16 >>> 16;
  32036. c16 &= 0xffff;
  32037. c16 += a00 * b16;
  32038. c32 += c16 >>> 16;
  32039. c16 &= 0xffff;
  32040. c32 += a32 * b00;
  32041. c48 += c32 >>> 16;
  32042. c32 &= 0xffff;
  32043. c32 += a16 * b16;
  32044. c48 += c32 >>> 16;
  32045. c32 &= 0xffff;
  32046. c32 += a00 * b32;
  32047. c48 += c32 >>> 16;
  32048. c32 &= 0xffff;
  32049. c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
  32050. c48 &= 0xffff;
  32051. return Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  32052. };
  32053. /** This is an alias of {@link Long.multiply} */
  32054. Long.prototype.mul = function (multiplier) {
  32055. return this.multiply(multiplier);
  32056. };
  32057. /** Returns the Negation of this Long's value. */
  32058. Long.prototype.negate = function () {
  32059. if (!this.unsigned && this.eq(Long.MIN_VALUE)) return Long.MIN_VALUE;
  32060. return this.not().add(Long.ONE);
  32061. };
  32062. /** This is an alias of {@link Long.negate} */
  32063. Long.prototype.neg = function () {
  32064. return this.negate();
  32065. };
  32066. /** Returns the bitwise NOT of this Long. */
  32067. Long.prototype.not = function () {
  32068. return Long.fromBits(~this.low, ~this.high, this.unsigned);
  32069. };
  32070. /** Tests if this Long's value differs from the specified's. */
  32071. Long.prototype.notEquals = function (other) {
  32072. return !this.equals(other);
  32073. };
  32074. /** This is an alias of {@link Long.notEquals} */
  32075. Long.prototype.neq = function (other) {
  32076. return this.notEquals(other);
  32077. };
  32078. /** This is an alias of {@link Long.notEquals} */
  32079. Long.prototype.ne = function (other) {
  32080. return this.notEquals(other);
  32081. };
  32082. /**
  32083. * Returns the bitwise OR of this Long and the specified.
  32084. */
  32085. Long.prototype.or = function (other) {
  32086. if (!Long.isLong(other)) other = Long.fromValue(other);
  32087. return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
  32088. };
  32089. /**
  32090. * Returns this Long with bits shifted to the left by the given amount.
  32091. * @param numBits - Number of bits
  32092. * @returns Shifted Long
  32093. */
  32094. Long.prototype.shiftLeft = function (numBits) {
  32095. if (Long.isLong(numBits)) numBits = numBits.toInt();
  32096. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return Long.fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);else return Long.fromBits(0, this.low << numBits - 32, this.unsigned);
  32097. };
  32098. /** This is an alias of {@link Long.shiftLeft} */
  32099. Long.prototype.shl = function (numBits) {
  32100. return this.shiftLeft(numBits);
  32101. };
  32102. /**
  32103. * Returns this Long with bits arithmetically shifted to the right by the given amount.
  32104. * @param numBits - Number of bits
  32105. * @returns Shifted Long
  32106. */
  32107. Long.prototype.shiftRight = function (numBits) {
  32108. if (Long.isLong(numBits)) numBits = numBits.toInt();
  32109. if ((numBits &= 63) === 0) return this;else if (numBits < 32) return Long.fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);else return Long.fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
  32110. };
  32111. /** This is an alias of {@link Long.shiftRight} */
  32112. Long.prototype.shr = function (numBits) {
  32113. return this.shiftRight(numBits);
  32114. };
  32115. /**
  32116. * Returns this Long with bits logically shifted to the right by the given amount.
  32117. * @param numBits - Number of bits
  32118. * @returns Shifted Long
  32119. */
  32120. Long.prototype.shiftRightUnsigned = function (numBits) {
  32121. if (Long.isLong(numBits)) numBits = numBits.toInt();
  32122. numBits &= 63;
  32123. if (numBits === 0) return this;else {
  32124. var high = this.high;
  32125. if (numBits < 32) {
  32126. var low = this.low;
  32127. return Long.fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
  32128. } else if (numBits === 32) return Long.fromBits(high, 0, this.unsigned);else return Long.fromBits(high >>> numBits - 32, 0, this.unsigned);
  32129. }
  32130. };
  32131. /** This is an alias of {@link Long.shiftRightUnsigned} */
  32132. Long.prototype.shr_u = function (numBits) {
  32133. return this.shiftRightUnsigned(numBits);
  32134. };
  32135. /** This is an alias of {@link Long.shiftRightUnsigned} */
  32136. Long.prototype.shru = function (numBits) {
  32137. return this.shiftRightUnsigned(numBits);
  32138. };
  32139. /**
  32140. * Returns the difference of this and the specified Long.
  32141. * @param subtrahend - Subtrahend
  32142. * @returns Difference
  32143. */
  32144. Long.prototype.subtract = function (subtrahend) {
  32145. if (!Long.isLong(subtrahend)) subtrahend = Long.fromValue(subtrahend);
  32146. return this.add(subtrahend.neg());
  32147. };
  32148. /** This is an alias of {@link Long.subtract} */
  32149. Long.prototype.sub = function (subtrahend) {
  32150. return this.subtract(subtrahend);
  32151. };
  32152. /** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
  32153. Long.prototype.toInt = function () {
  32154. return this.unsigned ? this.low >>> 0 : this.low;
  32155. };
  32156. /** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */
  32157. Long.prototype.toNumber = function () {
  32158. if (this.unsigned) return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
  32159. return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
  32160. };
  32161. /** Converts the Long to a BigInt (arbitrary precision). */
  32162. Long.prototype.toBigInt = function () {
  32163. return BigInt(this.toString());
  32164. };
  32165. /**
  32166. * Converts this Long to its byte representation.
  32167. * @param le - Whether little or big endian, defaults to big endian
  32168. * @returns Byte representation
  32169. */
  32170. Long.prototype.toBytes = function (le) {
  32171. return le ? this.toBytesLE() : this.toBytesBE();
  32172. };
  32173. /**
  32174. * Converts this Long to its little endian byte representation.
  32175. * @returns Little endian byte representation
  32176. */
  32177. Long.prototype.toBytesLE = function () {
  32178. var hi = this.high,
  32179. lo = this.low;
  32180. return [lo & 0xff, lo >>> 8 & 0xff, lo >>> 16 & 0xff, lo >>> 24, hi & 0xff, hi >>> 8 & 0xff, hi >>> 16 & 0xff, hi >>> 24];
  32181. };
  32182. /**
  32183. * Converts this Long to its big endian byte representation.
  32184. * @returns Big endian byte representation
  32185. */
  32186. Long.prototype.toBytesBE = function () {
  32187. var hi = this.high,
  32188. lo = this.low;
  32189. return [hi >>> 24, hi >>> 16 & 0xff, hi >>> 8 & 0xff, hi & 0xff, lo >>> 24, lo >>> 16 & 0xff, lo >>> 8 & 0xff, lo & 0xff];
  32190. };
  32191. /**
  32192. * Converts this Long to signed.
  32193. */
  32194. Long.prototype.toSigned = function () {
  32195. if (!this.unsigned) return this;
  32196. return Long.fromBits(this.low, this.high, false);
  32197. };
  32198. /**
  32199. * Converts the Long to a string written in the specified radix.
  32200. * @param radix - Radix (2-36), defaults to 10
  32201. * @throws RangeError If `radix` is out of range
  32202. */
  32203. Long.prototype.toString = function (radix) {
  32204. radix = radix || 10;
  32205. if (radix < 2 || 36 < radix) throw RangeError('radix');
  32206. if (this.isZero()) return '0';
  32207. if (this.isNegative()) {
  32208. // Unsigned Longs are never negative
  32209. if (this.eq(Long.MIN_VALUE)) {
  32210. // We need to change the Long value before it can be negated, so we remove
  32211. // the bottom-most digit in this base and then recurse to do the rest.
  32212. var radixLong = Long.fromNumber(radix),
  32213. div = this.div(radixLong),
  32214. rem1 = div.mul(radixLong).sub(this);
  32215. return div.toString(radix) + rem1.toInt().toString(radix);
  32216. } else return '-' + this.neg().toString(radix);
  32217. } // Do several (6) digits each time through the loop, so as to
  32218. // minimize the calls to the very expensive emulated div.
  32219. var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned); // eslint-disable-next-line @typescript-eslint/no-this-alias
  32220. var rem = this;
  32221. var result = ''; // eslint-disable-next-line no-constant-condition
  32222. while (true) {
  32223. var remDiv = rem.div(radixToPower);
  32224. var intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
  32225. var digits = intval.toString(radix);
  32226. rem = remDiv;
  32227. if (rem.isZero()) {
  32228. return digits + result;
  32229. } else {
  32230. while (digits.length < 6) {
  32231. digits = '0' + digits;
  32232. }
  32233. result = '' + digits + result;
  32234. }
  32235. }
  32236. };
  32237. /** Converts this Long to unsigned. */
  32238. Long.prototype.toUnsigned = function () {
  32239. if (this.unsigned) return this;
  32240. return Long.fromBits(this.low, this.high, true);
  32241. };
  32242. /** Returns the bitwise XOR of this Long and the given one. */
  32243. Long.prototype.xor = function (other) {
  32244. if (!Long.isLong(other)) other = Long.fromValue(other);
  32245. return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
  32246. };
  32247. /** This is an alias of {@link Long.isZero} */
  32248. Long.prototype.eqz = function () {
  32249. return this.isZero();
  32250. };
  32251. /** This is an alias of {@link Long.lessThanOrEqual} */
  32252. Long.prototype.le = function (other) {
  32253. return this.lessThanOrEqual(other);
  32254. };
  32255. /*
  32256. ****************************************************************
  32257. * BSON SPECIFIC ADDITIONS *
  32258. ****************************************************************
  32259. */
  32260. Long.prototype.toExtendedJSON = function (options) {
  32261. if (options && options.relaxed) return this.toNumber();
  32262. return {
  32263. $numberLong: this.toString()
  32264. };
  32265. };
  32266. Long.fromExtendedJSON = function (doc, options) {
  32267. var result = Long.fromString(doc.$numberLong);
  32268. return options && options.relaxed ? result.toNumber() : result;
  32269. };
  32270. /** @internal */
  32271. Long.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  32272. return this.inspect();
  32273. };
  32274. Long.prototype.inspect = function () {
  32275. return "new Long(\"" + this.toString() + "\"" + (this.unsigned ? ', true' : '') + ")";
  32276. };
  32277. Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
  32278. /** Maximum unsigned value. */
  32279. Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
  32280. /** Signed zero */
  32281. Long.ZERO = Long.fromInt(0);
  32282. /** Unsigned zero. */
  32283. Long.UZERO = Long.fromInt(0, true);
  32284. /** Signed one. */
  32285. Long.ONE = Long.fromInt(1);
  32286. /** Unsigned one. */
  32287. Long.UONE = Long.fromInt(1, true);
  32288. /** Signed negative one. */
  32289. Long.NEG_ONE = Long.fromInt(-1);
  32290. /** Maximum signed value. */
  32291. Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
  32292. /** Minimum signed value. */
  32293. Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
  32294. return Long;
  32295. }();
  32296. Object.defineProperty(_Long.prototype, '__isLong__', {
  32297. value: true
  32298. });
  32299. Object.defineProperty(_Long.prototype, '_bsontype', {
  32300. value: 'Long'
  32301. });
  32302. var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
  32303. var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
  32304. var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
  32305. var EXPONENT_MAX = 6111;
  32306. var EXPONENT_MIN = -6176;
  32307. var EXPONENT_BIAS = 6176;
  32308. var MAX_DIGITS = 34; // Nan value bits as 32 bit values (due to lack of longs)
  32309. 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)
  32310. var INF_NEGATIVE_BUFFER = [0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].reverse();
  32311. var INF_POSITIVE_BUFFER = [0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00].reverse();
  32312. var EXPONENT_REGEX = /^([-+])?(\d+)?$/; // Extract least significant 5 bits
  32313. var COMBINATION_MASK = 0x1f; // Extract least significant 14 bits
  32314. var EXPONENT_MASK = 0x3fff; // Value of combination field for Inf
  32315. var COMBINATION_INFINITY = 30; // Value of combination field for NaN
  32316. var COMBINATION_NAN = 31; // Detect if the value is a digit
  32317. function isDigit(value) {
  32318. return !isNaN(parseInt(value, 10));
  32319. } // Divide two uint128 values
  32320. function divideu128(value) {
  32321. var DIVISOR = _Long.fromNumber(1000 * 1000 * 1000);
  32322. var _rem = _Long.fromNumber(0);
  32323. if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
  32324. return {
  32325. quotient: value,
  32326. rem: _rem
  32327. };
  32328. }
  32329. for (var i = 0; i <= 3; i++) {
  32330. // Adjust remainder to match value of next dividend
  32331. _rem = _rem.shiftLeft(32); // Add the divided to _rem
  32332. _rem = _rem.add(new _Long(value.parts[i], 0));
  32333. value.parts[i] = _rem.div(DIVISOR).low;
  32334. _rem = _rem.modulo(DIVISOR);
  32335. }
  32336. return {
  32337. quotient: value,
  32338. rem: _rem
  32339. };
  32340. } // Multiply two Long values and return the 128 bit value
  32341. function multiply64x2(left, right) {
  32342. if (!left && !right) {
  32343. return {
  32344. high: _Long.fromNumber(0),
  32345. low: _Long.fromNumber(0)
  32346. };
  32347. }
  32348. var leftHigh = left.shiftRightUnsigned(32);
  32349. var leftLow = new _Long(left.getLowBits(), 0);
  32350. var rightHigh = right.shiftRightUnsigned(32);
  32351. var rightLow = new _Long(right.getLowBits(), 0);
  32352. var productHigh = leftHigh.multiply(rightHigh);
  32353. var productMid = leftHigh.multiply(rightLow);
  32354. var productMid2 = leftLow.multiply(rightHigh);
  32355. var productLow = leftLow.multiply(rightLow);
  32356. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  32357. productMid = new _Long(productMid.getLowBits(), 0).add(productMid2).add(productLow.shiftRightUnsigned(32));
  32358. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  32359. productLow = productMid.shiftLeft(32).add(new _Long(productLow.getLowBits(), 0)); // Return the 128 bit result
  32360. return {
  32361. high: productHigh,
  32362. low: productLow
  32363. };
  32364. }
  32365. function lessThan(left, right) {
  32366. // Make values unsigned
  32367. var uhleft = left.high >>> 0;
  32368. var uhright = right.high >>> 0; // Compare high bits first
  32369. if (uhleft < uhright) {
  32370. return true;
  32371. } else if (uhleft === uhright) {
  32372. var ulleft = left.low >>> 0;
  32373. var ulright = right.low >>> 0;
  32374. if (ulleft < ulright) return true;
  32375. }
  32376. return false;
  32377. }
  32378. function invalidErr(string, message) {
  32379. throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
  32380. }
  32381. /**
  32382. * A class representation of the BSON Decimal128 type.
  32383. * @public
  32384. * @category BSONType
  32385. */
  32386. var _Decimal =
  32387. /** @class */
  32388. function () {
  32389. /**
  32390. * @param bytes - a buffer containing the raw Decimal128 bytes in little endian order,
  32391. * or a string representation as returned by .toString()
  32392. */
  32393. function Decimal128(bytes) {
  32394. if (!(this instanceof Decimal128)) return new Decimal128(bytes);
  32395. if (typeof bytes === 'string') {
  32396. this.bytes = Decimal128.fromString(bytes).bytes;
  32397. } else if (isUint8Array(bytes)) {
  32398. if (bytes.byteLength !== 16) {
  32399. throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
  32400. }
  32401. this.bytes = bytes;
  32402. } else {
  32403. throw new BSONTypeError('Decimal128 must take a Buffer or string');
  32404. }
  32405. }
  32406. /**
  32407. * Create a Decimal128 instance from a string representation
  32408. *
  32409. * @param representation - a numeric string representation.
  32410. */
  32411. Decimal128.fromString = function (representation) {
  32412. // Parse state tracking
  32413. var isNegative = false;
  32414. var sawRadix = false;
  32415. var foundNonZero = false; // Total number of significant digits (no leading or trailing zero)
  32416. var significantDigits = 0; // Total number of significand digits read
  32417. var nDigitsRead = 0; // Total number of digits (no leading zeros)
  32418. var nDigits = 0; // The number of the digits after radix
  32419. var radixPosition = 0; // The index of the first non-zero in *str*
  32420. var firstNonZero = 0; // Digits Array
  32421. var digits = [0]; // The number of digits in digits
  32422. var nDigitsStored = 0; // Insertion pointer for digits
  32423. var digitsInsert = 0; // The index of the first non-zero digit
  32424. var firstDigit = 0; // The index of the last digit
  32425. var lastDigit = 0; // Exponent
  32426. var exponent = 0; // loop index over array
  32427. var i = 0; // The high 17 digits of the significand
  32428. var significandHigh = new _Long(0, 0); // The low 17 digits of the significand
  32429. var significandLow = new _Long(0, 0); // The biased exponent
  32430. var biasedExponent = 0; // Read index
  32431. var index = 0; // Naively prevent against REDOS attacks.
  32432. // TODO: implementing a custom parsing for this, or refactoring the regex would yield
  32433. // further gains.
  32434. if (representation.length >= 7000) {
  32435. throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
  32436. } // Results
  32437. var stringMatch = representation.match(PARSE_STRING_REGEXP);
  32438. var infMatch = representation.match(PARSE_INF_REGEXP);
  32439. var nanMatch = representation.match(PARSE_NAN_REGEXP); // Validate the string
  32440. if (!stringMatch && !infMatch && !nanMatch || representation.length === 0) {
  32441. throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
  32442. }
  32443. if (stringMatch) {
  32444. // full_match = stringMatch[0]
  32445. // sign = stringMatch[1]
  32446. var unsignedNumber = stringMatch[2]; // stringMatch[3] is undefined if a whole number (ex "1", 12")
  32447. // but defined if a number w/ decimal in it (ex "1.0, 12.2")
  32448. var e = stringMatch[4];
  32449. var expSign = stringMatch[5];
  32450. var expNumber = stringMatch[6]; // they provided e, but didn't give an exponent number. for ex "1e"
  32451. if (e && expNumber === undefined) invalidErr(representation, 'missing exponent power'); // they provided e, but didn't give a number before it. for ex "e1"
  32452. if (e && unsignedNumber === undefined) invalidErr(representation, 'missing exponent base');
  32453. if (e === undefined && (expSign || expNumber)) {
  32454. invalidErr(representation, 'missing e before exponent');
  32455. }
  32456. } // Get the negative or positive sign
  32457. if (representation[index] === '+' || representation[index] === '-') {
  32458. isNegative = representation[index++] === '-';
  32459. } // Check if user passed Infinity or NaN
  32460. if (!isDigit(representation[index]) && representation[index] !== '.') {
  32461. if (representation[index] === 'i' || representation[index] === 'I') {
  32462. return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
  32463. } else if (representation[index] === 'N') {
  32464. return new Decimal128(buffer_1.from(NAN_BUFFER));
  32465. }
  32466. } // Read all the digits
  32467. while (isDigit(representation[index]) || representation[index] === '.') {
  32468. if (representation[index] === '.') {
  32469. if (sawRadix) invalidErr(representation, 'contains multiple periods');
  32470. sawRadix = true;
  32471. index = index + 1;
  32472. continue;
  32473. }
  32474. if (nDigitsStored < 34) {
  32475. if (representation[index] !== '0' || foundNonZero) {
  32476. if (!foundNonZero) {
  32477. firstNonZero = nDigitsRead;
  32478. }
  32479. foundNonZero = true; // Only store 34 digits
  32480. digits[digitsInsert++] = parseInt(representation[index], 10);
  32481. nDigitsStored = nDigitsStored + 1;
  32482. }
  32483. }
  32484. if (foundNonZero) nDigits = nDigits + 1;
  32485. if (sawRadix) radixPosition = radixPosition + 1;
  32486. nDigitsRead = nDigitsRead + 1;
  32487. index = index + 1;
  32488. }
  32489. if (sawRadix && !nDigitsRead) throw new BSONTypeError('' + representation + ' not a valid Decimal128 string'); // Read exponent if exists
  32490. if (representation[index] === 'e' || representation[index] === 'E') {
  32491. // Read exponent digits
  32492. var match = representation.substr(++index).match(EXPONENT_REGEX); // No digits read
  32493. if (!match || !match[2]) return new Decimal128(buffer_1.from(NAN_BUFFER)); // Get exponent
  32494. exponent = parseInt(match[0], 10); // Adjust the index
  32495. index = index + match[0].length;
  32496. } // Return not a number
  32497. if (representation[index]) return new Decimal128(buffer_1.from(NAN_BUFFER)); // Done reading input
  32498. // Find first non-zero digit in digits
  32499. firstDigit = 0;
  32500. if (!nDigitsStored) {
  32501. firstDigit = 0;
  32502. lastDigit = 0;
  32503. digits[0] = 0;
  32504. nDigits = 1;
  32505. nDigitsStored = 1;
  32506. significantDigits = 0;
  32507. } else {
  32508. lastDigit = nDigitsStored - 1;
  32509. significantDigits = nDigits;
  32510. if (significantDigits !== 1) {
  32511. while (digits[firstNonZero + significantDigits - 1] === 0) {
  32512. significantDigits = significantDigits - 1;
  32513. }
  32514. }
  32515. } // Normalization of exponent
  32516. // Correct exponent based on radix position, and shift significand as needed
  32517. // to represent user input
  32518. // Overflow prevention
  32519. if (exponent <= radixPosition && radixPosition - exponent > 1 << 14) {
  32520. exponent = EXPONENT_MIN;
  32521. } else {
  32522. exponent = exponent - radixPosition;
  32523. } // Attempt to normalize the exponent
  32524. while (exponent > EXPONENT_MAX) {
  32525. // Shift exponent to significand and decrease
  32526. lastDigit = lastDigit + 1;
  32527. if (lastDigit - firstDigit > MAX_DIGITS) {
  32528. // Check if we have a zero then just hard clamp, otherwise fail
  32529. var digitsString = digits.join('');
  32530. if (digitsString.match(/^0+$/)) {
  32531. exponent = EXPONENT_MAX;
  32532. break;
  32533. }
  32534. invalidErr(representation, 'overflow');
  32535. }
  32536. exponent = exponent - 1;
  32537. }
  32538. while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
  32539. // Shift last digit. can only do this if < significant digits than # stored.
  32540. if (lastDigit === 0 && significantDigits < nDigitsStored) {
  32541. exponent = EXPONENT_MIN;
  32542. significantDigits = 0;
  32543. break;
  32544. }
  32545. if (nDigitsStored < nDigits) {
  32546. // adjust to match digits not stored
  32547. nDigits = nDigits - 1;
  32548. } else {
  32549. // adjust to round
  32550. lastDigit = lastDigit - 1;
  32551. }
  32552. if (exponent < EXPONENT_MAX) {
  32553. exponent = exponent + 1;
  32554. } else {
  32555. // Check if we have a zero then just hard clamp, otherwise fail
  32556. var digitsString = digits.join('');
  32557. if (digitsString.match(/^0+$/)) {
  32558. exponent = EXPONENT_MAX;
  32559. break;
  32560. }
  32561. invalidErr(representation, 'overflow');
  32562. }
  32563. } // Round
  32564. // We've normalized the exponent, but might still need to round.
  32565. if (lastDigit - firstDigit + 1 < significantDigits) {
  32566. var endOfString = nDigitsRead; // If we have seen a radix point, 'string' is 1 longer than we have
  32567. // documented with ndigits_read, so inc the position of the first nonzero
  32568. // digit and the position that digits are read to.
  32569. if (sawRadix) {
  32570. firstNonZero = firstNonZero + 1;
  32571. endOfString = endOfString + 1;
  32572. } // if negative, we need to increment again to account for - sign at start.
  32573. if (isNegative) {
  32574. firstNonZero = firstNonZero + 1;
  32575. endOfString = endOfString + 1;
  32576. }
  32577. var roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
  32578. var roundBit = 0;
  32579. if (roundDigit >= 5) {
  32580. roundBit = 1;
  32581. if (roundDigit === 5) {
  32582. roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
  32583. for (i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
  32584. if (parseInt(representation[i], 10)) {
  32585. roundBit = 1;
  32586. break;
  32587. }
  32588. }
  32589. }
  32590. }
  32591. if (roundBit) {
  32592. var dIdx = lastDigit;
  32593. for (; dIdx >= 0; dIdx--) {
  32594. if (++digits[dIdx] > 9) {
  32595. digits[dIdx] = 0; // overflowed most significant digit
  32596. if (dIdx === 0) {
  32597. if (exponent < EXPONENT_MAX) {
  32598. exponent = exponent + 1;
  32599. digits[dIdx] = 1;
  32600. } else {
  32601. return new Decimal128(buffer_1.from(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER));
  32602. }
  32603. }
  32604. }
  32605. }
  32606. }
  32607. } // Encode significand
  32608. // The high 17 digits of the significand
  32609. significandHigh = _Long.fromNumber(0); // The low 17 digits of the significand
  32610. significandLow = _Long.fromNumber(0); // read a zero
  32611. if (significantDigits === 0) {
  32612. significandHigh = _Long.fromNumber(0);
  32613. significandLow = _Long.fromNumber(0);
  32614. } else if (lastDigit - firstDigit < 17) {
  32615. var dIdx = firstDigit;
  32616. significandLow = _Long.fromNumber(digits[dIdx++]);
  32617. significandHigh = new _Long(0, 0);
  32618. for (; dIdx <= lastDigit; dIdx++) {
  32619. significandLow = significandLow.multiply(_Long.fromNumber(10));
  32620. significandLow = significandLow.add(_Long.fromNumber(digits[dIdx]));
  32621. }
  32622. } else {
  32623. var dIdx = firstDigit;
  32624. significandHigh = _Long.fromNumber(digits[dIdx++]);
  32625. for (; dIdx <= lastDigit - 17; dIdx++) {
  32626. significandHigh = significandHigh.multiply(_Long.fromNumber(10));
  32627. significandHigh = significandHigh.add(_Long.fromNumber(digits[dIdx]));
  32628. }
  32629. significandLow = _Long.fromNumber(digits[dIdx++]);
  32630. for (; dIdx <= lastDigit; dIdx++) {
  32631. significandLow = significandLow.multiply(_Long.fromNumber(10));
  32632. significandLow = significandLow.add(_Long.fromNumber(digits[dIdx]));
  32633. }
  32634. }
  32635. var significand = multiply64x2(significandHigh, _Long.fromString('100000000000000000'));
  32636. significand.low = significand.low.add(significandLow);
  32637. if (lessThan(significand.low, significandLow)) {
  32638. significand.high = significand.high.add(_Long.fromNumber(1));
  32639. } // Biased exponent
  32640. biasedExponent = exponent + EXPONENT_BIAS;
  32641. var dec = {
  32642. low: _Long.fromNumber(0),
  32643. high: _Long.fromNumber(0)
  32644. }; // Encode combination, exponent, and significand.
  32645. if (significand.high.shiftRightUnsigned(49).and(_Long.fromNumber(1)).equals(_Long.fromNumber(1))) {
  32646. // Encode '11' into bits 1 to 3
  32647. dec.high = dec.high.or(_Long.fromNumber(0x3).shiftLeft(61));
  32648. dec.high = dec.high.or(_Long.fromNumber(biasedExponent).and(_Long.fromNumber(0x3fff).shiftLeft(47)));
  32649. dec.high = dec.high.or(significand.high.and(_Long.fromNumber(0x7fffffffffff)));
  32650. } else {
  32651. dec.high = dec.high.or(_Long.fromNumber(biasedExponent & 0x3fff).shiftLeft(49));
  32652. dec.high = dec.high.or(significand.high.and(_Long.fromNumber(0x1ffffffffffff)));
  32653. }
  32654. dec.low = significand.low; // Encode sign
  32655. if (isNegative) {
  32656. dec.high = dec.high.or(_Long.fromString('9223372036854775808'));
  32657. } // Encode into a buffer
  32658. var buffer = buffer_1.alloc(16);
  32659. index = 0; // Encode the low 64 bits of the decimal
  32660. // Encode low bits
  32661. buffer[index++] = dec.low.low & 0xff;
  32662. buffer[index++] = dec.low.low >> 8 & 0xff;
  32663. buffer[index++] = dec.low.low >> 16 & 0xff;
  32664. buffer[index++] = dec.low.low >> 24 & 0xff; // Encode high bits
  32665. buffer[index++] = dec.low.high & 0xff;
  32666. buffer[index++] = dec.low.high >> 8 & 0xff;
  32667. buffer[index++] = dec.low.high >> 16 & 0xff;
  32668. buffer[index++] = dec.low.high >> 24 & 0xff; // Encode the high 64 bits of the decimal
  32669. // Encode low bits
  32670. buffer[index++] = dec.high.low & 0xff;
  32671. buffer[index++] = dec.high.low >> 8 & 0xff;
  32672. buffer[index++] = dec.high.low >> 16 & 0xff;
  32673. buffer[index++] = dec.high.low >> 24 & 0xff; // Encode high bits
  32674. buffer[index++] = dec.high.high & 0xff;
  32675. buffer[index++] = dec.high.high >> 8 & 0xff;
  32676. buffer[index++] = dec.high.high >> 16 & 0xff;
  32677. buffer[index++] = dec.high.high >> 24 & 0xff; // Return the new Decimal128
  32678. return new Decimal128(buffer);
  32679. };
  32680. /** Create a string representation of the raw Decimal128 value */
  32681. Decimal128.prototype.toString = function () {
  32682. // Note: bits in this routine are referred to starting at 0,
  32683. // from the sign bit, towards the coefficient.
  32684. // decoded biased exponent (14 bits)
  32685. var biased_exponent; // the number of significand digits
  32686. var significand_digits = 0; // the base-10 digits in the significand
  32687. var significand = new Array(36);
  32688. for (var i = 0; i < significand.length; i++) {
  32689. significand[i] = 0;
  32690. } // read pointer into significand
  32691. var index = 0; // true if the number is zero
  32692. var is_zero = false; // the most significant significand bits (50-46)
  32693. var significand_msb; // temporary storage for significand decoding
  32694. var significand128 = {
  32695. parts: [0, 0, 0, 0]
  32696. }; // indexing variables
  32697. var j, k; // Output string
  32698. var string = []; // Unpack index
  32699. index = 0; // Buffer reference
  32700. var buffer = this.bytes; // Unpack the low 64bits into a long
  32701. // bits 96 - 127
  32702. var low = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // bits 64 - 95
  32703. var midl = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Unpack the high 64bits into a long
  32704. // bits 32 - 63
  32705. var midh = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // bits 0 - 31
  32706. var high = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Unpack index
  32707. index = 0; // Create the state of the decimal
  32708. var dec = {
  32709. low: new _Long(low, midl),
  32710. high: new _Long(midh, high)
  32711. };
  32712. if (dec.high.lessThan(_Long.ZERO)) {
  32713. string.push('-');
  32714. } // Decode combination field and exponent
  32715. // bits 1 - 5
  32716. var combination = high >> 26 & COMBINATION_MASK;
  32717. if (combination >> 3 === 3) {
  32718. // Check for 'special' values
  32719. if (combination === COMBINATION_INFINITY) {
  32720. return string.join('') + 'Infinity';
  32721. } else if (combination === COMBINATION_NAN) {
  32722. return 'NaN';
  32723. } else {
  32724. biased_exponent = high >> 15 & EXPONENT_MASK;
  32725. significand_msb = 0x08 + (high >> 14 & 0x01);
  32726. }
  32727. } else {
  32728. significand_msb = high >> 14 & 0x07;
  32729. biased_exponent = high >> 17 & EXPONENT_MASK;
  32730. } // unbiased exponent
  32731. var exponent = biased_exponent - EXPONENT_BIAS; // Create string of significand digits
  32732. // Convert the 114-bit binary number represented by
  32733. // (significand_high, significand_low) to at most 34 decimal
  32734. // digits through modulo and division.
  32735. significand128.parts[0] = (high & 0x3fff) + ((significand_msb & 0xf) << 14);
  32736. significand128.parts[1] = midh;
  32737. significand128.parts[2] = midl;
  32738. significand128.parts[3] = low;
  32739. if (significand128.parts[0] === 0 && significand128.parts[1] === 0 && significand128.parts[2] === 0 && significand128.parts[3] === 0) {
  32740. is_zero = true;
  32741. } else {
  32742. for (k = 3; k >= 0; k--) {
  32743. var least_digits = 0; // Perform the divide
  32744. var result = divideu128(significand128);
  32745. significand128 = result.quotient;
  32746. least_digits = result.rem.low; // We now have the 9 least significant digits (in base 2).
  32747. // Convert and output to string.
  32748. if (!least_digits) continue;
  32749. for (j = 8; j >= 0; j--) {
  32750. // significand[k * 9 + j] = Math.round(least_digits % 10);
  32751. significand[k * 9 + j] = least_digits % 10; // least_digits = Math.round(least_digits / 10);
  32752. least_digits = Math.floor(least_digits / 10);
  32753. }
  32754. }
  32755. } // Output format options:
  32756. // Scientific - [-]d.dddE(+/-)dd or [-]dE(+/-)dd
  32757. // Regular - ddd.ddd
  32758. if (is_zero) {
  32759. significand_digits = 1;
  32760. significand[index] = 0;
  32761. } else {
  32762. significand_digits = 36;
  32763. while (!significand[index]) {
  32764. significand_digits = significand_digits - 1;
  32765. index = index + 1;
  32766. }
  32767. } // the exponent if scientific notation is used
  32768. var scientific_exponent = significand_digits - 1 + exponent; // The scientific exponent checks are dictated by the string conversion
  32769. // specification and are somewhat arbitrary cutoffs.
  32770. //
  32771. // We must check exponent > 0, because if this is the case, the number
  32772. // has trailing zeros. However, we *cannot* output these trailing zeros,
  32773. // because doing so would change the precision of the value, and would
  32774. // change stored data if the string converted number is round tripped.
  32775. if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
  32776. // Scientific format
  32777. // if there are too many significant digits, we should just be treating numbers
  32778. // as + or - 0 and using the non-scientific exponent (this is for the "invalid
  32779. // representation should be treated as 0/-0" spec cases in decimal128-1.json)
  32780. if (significand_digits > 34) {
  32781. string.push("" + 0);
  32782. if (exponent > 0) string.push('E+' + exponent);else if (exponent < 0) string.push('E' + exponent);
  32783. return string.join('');
  32784. }
  32785. string.push("" + significand[index++]);
  32786. significand_digits = significand_digits - 1;
  32787. if (significand_digits) {
  32788. string.push('.');
  32789. }
  32790. for (var i = 0; i < significand_digits; i++) {
  32791. string.push("" + significand[index++]);
  32792. } // Exponent
  32793. string.push('E');
  32794. if (scientific_exponent > 0) {
  32795. string.push('+' + scientific_exponent);
  32796. } else {
  32797. string.push("" + scientific_exponent);
  32798. }
  32799. } else {
  32800. // Regular format with no decimal place
  32801. if (exponent >= 0) {
  32802. for (var i = 0; i < significand_digits; i++) {
  32803. string.push("" + significand[index++]);
  32804. }
  32805. } else {
  32806. var radix_position = significand_digits + exponent; // non-zero digits before radix
  32807. if (radix_position > 0) {
  32808. for (var i = 0; i < radix_position; i++) {
  32809. string.push("" + significand[index++]);
  32810. }
  32811. } else {
  32812. string.push('0');
  32813. }
  32814. string.push('.'); // add leading zeros after radix
  32815. while (radix_position++ < 0) {
  32816. string.push('0');
  32817. }
  32818. for (var i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
  32819. string.push("" + significand[index++]);
  32820. }
  32821. }
  32822. }
  32823. return string.join('');
  32824. };
  32825. Decimal128.prototype.toJSON = function () {
  32826. return {
  32827. $numberDecimal: this.toString()
  32828. };
  32829. };
  32830. /** @internal */
  32831. Decimal128.prototype.toExtendedJSON = function () {
  32832. return {
  32833. $numberDecimal: this.toString()
  32834. };
  32835. };
  32836. /** @internal */
  32837. Decimal128.fromExtendedJSON = function (doc) {
  32838. return Decimal128.fromString(doc.$numberDecimal);
  32839. };
  32840. /** @internal */
  32841. Decimal128.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  32842. return this.inspect();
  32843. };
  32844. Decimal128.prototype.inspect = function () {
  32845. return "new Decimal128(\"" + this.toString() + "\")";
  32846. };
  32847. return Decimal128;
  32848. }();
  32849. Object.defineProperty(_Decimal.prototype, '_bsontype', {
  32850. value: 'Decimal128'
  32851. });
  32852. /**
  32853. * A class representation of the BSON Double type.
  32854. * @public
  32855. * @category BSONType
  32856. */
  32857. var _Double =
  32858. /** @class */
  32859. function () {
  32860. /**
  32861. * Create a Double type
  32862. *
  32863. * @param value - the number we want to represent as a double.
  32864. */
  32865. function Double(value) {
  32866. if (!(this instanceof Double)) return new Double(value);
  32867. if (value instanceof Number) {
  32868. value = value.valueOf();
  32869. }
  32870. this.value = +value;
  32871. }
  32872. /**
  32873. * Access the number value.
  32874. *
  32875. * @returns returns the wrapped double number.
  32876. */
  32877. Double.prototype.valueOf = function () {
  32878. return this.value;
  32879. };
  32880. Double.prototype.toJSON = function () {
  32881. return this.value;
  32882. };
  32883. Double.prototype.toString = function (radix) {
  32884. return this.value.toString(radix);
  32885. };
  32886. /** @internal */
  32887. Double.prototype.toExtendedJSON = function (options) {
  32888. if (options && (options.legacy || options.relaxed && isFinite(this.value))) {
  32889. return this.value;
  32890. } // NOTE: JavaScript has +0 and -0, apparently to model limit calculations. If a user
  32891. // explicitly provided `-0` then we need to ensure the sign makes it into the output
  32892. if (Object.is(Math.sign(this.value), -0)) {
  32893. return {
  32894. $numberDouble: "-" + this.value.toFixed(1)
  32895. };
  32896. }
  32897. var $numberDouble;
  32898. if (Number.isInteger(this.value)) {
  32899. $numberDouble = this.value.toFixed(1);
  32900. if ($numberDouble.length >= 13) {
  32901. $numberDouble = this.value.toExponential(13).toUpperCase();
  32902. }
  32903. } else {
  32904. $numberDouble = this.value.toString();
  32905. }
  32906. return {
  32907. $numberDouble: $numberDouble
  32908. };
  32909. };
  32910. /** @internal */
  32911. Double.fromExtendedJSON = function (doc, options) {
  32912. var doubleValue = parseFloat(doc.$numberDouble);
  32913. return options && options.relaxed ? doubleValue : new Double(doubleValue);
  32914. };
  32915. /** @internal */
  32916. Double.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  32917. return this.inspect();
  32918. };
  32919. Double.prototype.inspect = function () {
  32920. var eJSON = this.toExtendedJSON();
  32921. return "new Double(" + eJSON.$numberDouble + ")";
  32922. };
  32923. return Double;
  32924. }();
  32925. Object.defineProperty(_Double.prototype, '_bsontype', {
  32926. value: 'Double'
  32927. });
  32928. /**
  32929. * A class representation of a BSON Int32 type.
  32930. * @public
  32931. * @category BSONType
  32932. */
  32933. var _Int =
  32934. /** @class */
  32935. function () {
  32936. /**
  32937. * Create an Int32 type
  32938. *
  32939. * @param value - the number we want to represent as an int32.
  32940. */
  32941. function Int32(value) {
  32942. if (!(this instanceof Int32)) return new Int32(value);
  32943. if (value instanceof Number) {
  32944. value = value.valueOf();
  32945. }
  32946. this.value = +value | 0;
  32947. }
  32948. /**
  32949. * Access the number value.
  32950. *
  32951. * @returns returns the wrapped int32 number.
  32952. */
  32953. Int32.prototype.valueOf = function () {
  32954. return this.value;
  32955. };
  32956. Int32.prototype.toString = function (radix) {
  32957. return this.value.toString(radix);
  32958. };
  32959. Int32.prototype.toJSON = function () {
  32960. return this.value;
  32961. };
  32962. /** @internal */
  32963. Int32.prototype.toExtendedJSON = function (options) {
  32964. if (options && (options.relaxed || options.legacy)) return this.value;
  32965. return {
  32966. $numberInt: this.value.toString()
  32967. };
  32968. };
  32969. /** @internal */
  32970. Int32.fromExtendedJSON = function (doc, options) {
  32971. return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new Int32(doc.$numberInt);
  32972. };
  32973. /** @internal */
  32974. Int32.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  32975. return this.inspect();
  32976. };
  32977. Int32.prototype.inspect = function () {
  32978. return "new Int32(" + this.valueOf() + ")";
  32979. };
  32980. return Int32;
  32981. }();
  32982. Object.defineProperty(_Int.prototype, '_bsontype', {
  32983. value: 'Int32'
  32984. });
  32985. /**
  32986. * A class representation of the BSON MaxKey type.
  32987. * @public
  32988. * @category BSONType
  32989. */
  32990. var _MaxKey =
  32991. /** @class */
  32992. function () {
  32993. function MaxKey() {
  32994. if (!(this instanceof MaxKey)) return new MaxKey();
  32995. }
  32996. /** @internal */
  32997. MaxKey.prototype.toExtendedJSON = function () {
  32998. return {
  32999. $maxKey: 1
  33000. };
  33001. };
  33002. /** @internal */
  33003. MaxKey.fromExtendedJSON = function () {
  33004. return new MaxKey();
  33005. };
  33006. /** @internal */
  33007. MaxKey.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  33008. return this.inspect();
  33009. };
  33010. MaxKey.prototype.inspect = function () {
  33011. return 'new MaxKey()';
  33012. };
  33013. return MaxKey;
  33014. }();
  33015. Object.defineProperty(_MaxKey.prototype, '_bsontype', {
  33016. value: 'MaxKey'
  33017. });
  33018. /**
  33019. * A class representation of the BSON MinKey type.
  33020. * @public
  33021. * @category BSONType
  33022. */
  33023. var _MinKey =
  33024. /** @class */
  33025. function () {
  33026. function MinKey() {
  33027. if (!(this instanceof MinKey)) return new MinKey();
  33028. }
  33029. /** @internal */
  33030. MinKey.prototype.toExtendedJSON = function () {
  33031. return {
  33032. $minKey: 1
  33033. };
  33034. };
  33035. /** @internal */
  33036. MinKey.fromExtendedJSON = function () {
  33037. return new MinKey();
  33038. };
  33039. /** @internal */
  33040. MinKey.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  33041. return this.inspect();
  33042. };
  33043. MinKey.prototype.inspect = function () {
  33044. return 'new MinKey()';
  33045. };
  33046. return MinKey;
  33047. }();
  33048. Object.defineProperty(_MinKey.prototype, '_bsontype', {
  33049. value: 'MinKey'
  33050. }); // Regular expression that checks for hex value
  33051. var checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$'); // Unique sequence for the current process (initialized on first use)
  33052. var PROCESS_UNIQUE = null;
  33053. var kId = Symbol('id');
  33054. /**
  33055. * A class representation of the BSON ObjectId type.
  33056. * @public
  33057. * @category BSONType
  33058. */
  33059. var _ObjectId =
  33060. /** @class */
  33061. function () {
  33062. /**
  33063. * Create an ObjectId type
  33064. *
  33065. * @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
  33066. */
  33067. function ObjectId(inputId) {
  33068. if (!(this instanceof ObjectId)) return new ObjectId(inputId); // workingId is set based on type of input and whether valid id exists for the input
  33069. var workingId;
  33070. if (_typeof(inputId) === 'object' && inputId && 'id' in inputId) {
  33071. if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
  33072. throw new BSONTypeError('Argument passed in must have an id that is of type string or Buffer');
  33073. }
  33074. if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
  33075. workingId = buffer_1.from(inputId.toHexString(), 'hex');
  33076. } else {
  33077. workingId = inputId.id;
  33078. }
  33079. } else {
  33080. workingId = inputId;
  33081. } // the following cases use workingId to construct an ObjectId
  33082. if (workingId == null || typeof workingId === 'number') {
  33083. // The most common use case (blank id, new objectId instance)
  33084. // Generate a new id
  33085. this[kId] = ObjectId.generate(typeof workingId === 'number' ? workingId : undefined);
  33086. } else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
  33087. // If intstanceof matches we can escape calling ensure buffer in Node.js environments
  33088. this[kId] = workingId instanceof buffer_1 ? workingId : ensureBuffer(workingId);
  33089. } else if (typeof workingId === 'string') {
  33090. if (workingId.length === 12) {
  33091. var bytes = buffer_1.from(workingId);
  33092. if (bytes.byteLength === 12) {
  33093. this[kId] = bytes;
  33094. } else {
  33095. throw new BSONTypeError('Argument passed in must be a string of 12 bytes');
  33096. }
  33097. } else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
  33098. this[kId] = buffer_1.from(workingId, 'hex');
  33099. } else {
  33100. throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
  33101. }
  33102. } else {
  33103. throw new BSONTypeError('Argument passed in does not match the accepted types');
  33104. } // If we are caching the hex string
  33105. if (ObjectId.cacheHexString) {
  33106. this.__id = this.id.toString('hex');
  33107. }
  33108. }
  33109. Object.defineProperty(ObjectId.prototype, "id", {
  33110. /**
  33111. * The ObjectId bytes
  33112. * @readonly
  33113. */
  33114. get: function get() {
  33115. return this[kId];
  33116. },
  33117. set: function set(value) {
  33118. this[kId] = value;
  33119. if (ObjectId.cacheHexString) {
  33120. this.__id = value.toString('hex');
  33121. }
  33122. },
  33123. enumerable: false,
  33124. configurable: true
  33125. });
  33126. Object.defineProperty(ObjectId.prototype, "generationTime", {
  33127. /**
  33128. * The generation time of this ObjectId instance
  33129. * @deprecated Please use getTimestamp / createFromTime which returns an int32 epoch
  33130. */
  33131. get: function get() {
  33132. return this.id.readInt32BE(0);
  33133. },
  33134. set: function set(value) {
  33135. // Encode time into first 4 bytes
  33136. this.id.writeUInt32BE(value, 0);
  33137. },
  33138. enumerable: false,
  33139. configurable: true
  33140. });
  33141. /** Returns the ObjectId id as a 24 character hex string representation */
  33142. ObjectId.prototype.toHexString = function () {
  33143. if (ObjectId.cacheHexString && this.__id) {
  33144. return this.__id;
  33145. }
  33146. var hexString = this.id.toString('hex');
  33147. if (ObjectId.cacheHexString && !this.__id) {
  33148. this.__id = hexString;
  33149. }
  33150. return hexString;
  33151. };
  33152. /**
  33153. * Update the ObjectId index
  33154. * @privateRemarks
  33155. * Used in generating new ObjectId's on the driver
  33156. * @internal
  33157. */
  33158. ObjectId.getInc = function () {
  33159. return ObjectId.index = (ObjectId.index + 1) % 0xffffff;
  33160. };
  33161. /**
  33162. * Generate a 12 byte id buffer used in ObjectId's
  33163. *
  33164. * @param time - pass in a second based timestamp.
  33165. */
  33166. ObjectId.generate = function (time) {
  33167. if ('number' !== typeof time) {
  33168. time = Math.floor(Date.now() / 1000);
  33169. }
  33170. var inc = ObjectId.getInc();
  33171. var buffer = buffer_1.alloc(12); // 4-byte timestamp
  33172. buffer.writeUInt32BE(time, 0); // set PROCESS_UNIQUE if yet not initialized
  33173. if (PROCESS_UNIQUE === null) {
  33174. PROCESS_UNIQUE = randomBytes(5);
  33175. } // 5-byte process unique
  33176. buffer[4] = PROCESS_UNIQUE[0];
  33177. buffer[5] = PROCESS_UNIQUE[1];
  33178. buffer[6] = PROCESS_UNIQUE[2];
  33179. buffer[7] = PROCESS_UNIQUE[3];
  33180. buffer[8] = PROCESS_UNIQUE[4]; // 3-byte counter
  33181. buffer[11] = inc & 0xff;
  33182. buffer[10] = inc >> 8 & 0xff;
  33183. buffer[9] = inc >> 16 & 0xff;
  33184. return buffer;
  33185. };
  33186. /**
  33187. * Converts the id into a 24 character hex string for printing
  33188. *
  33189. * @param format - The Buffer toString format parameter.
  33190. */
  33191. ObjectId.prototype.toString = function (format) {
  33192. // Is the id a buffer then use the buffer toString method to return the format
  33193. if (format) return this.id.toString(format);
  33194. return this.toHexString();
  33195. };
  33196. /** Converts to its JSON the 24 character hex string representation. */
  33197. ObjectId.prototype.toJSON = function () {
  33198. return this.toHexString();
  33199. };
  33200. /**
  33201. * Compares the equality of this ObjectId with `otherID`.
  33202. *
  33203. * @param otherId - ObjectId instance to compare against.
  33204. */
  33205. ObjectId.prototype.equals = function (otherId) {
  33206. if (otherId === undefined || otherId === null) {
  33207. return false;
  33208. }
  33209. if (otherId instanceof ObjectId) {
  33210. return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
  33211. }
  33212. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12 && isUint8Array(this.id)) {
  33213. return otherId === buffer_1.prototype.toString.call(this.id, 'latin1');
  33214. }
  33215. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 24) {
  33216. return otherId.toLowerCase() === this.toHexString();
  33217. }
  33218. if (typeof otherId === 'string' && ObjectId.isValid(otherId) && otherId.length === 12) {
  33219. return buffer_1.from(otherId).equals(this.id);
  33220. }
  33221. if (_typeof(otherId) === 'object' && 'toHexString' in otherId && typeof otherId.toHexString === 'function') {
  33222. var otherIdString = otherId.toHexString();
  33223. var thisIdString = this.toHexString().toLowerCase();
  33224. return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
  33225. }
  33226. return false;
  33227. };
  33228. /** Returns the generation date (accurate up to the second) that this ID was generated. */
  33229. ObjectId.prototype.getTimestamp = function () {
  33230. var timestamp = new Date();
  33231. var time = this.id.readUInt32BE(0);
  33232. timestamp.setTime(Math.floor(time) * 1000);
  33233. return timestamp;
  33234. };
  33235. /** @internal */
  33236. ObjectId.createPk = function () {
  33237. return new ObjectId();
  33238. };
  33239. /**
  33240. * Creates an ObjectId from a second based number, with the rest of the ObjectId zeroed out. Used for comparisons or sorting the ObjectId.
  33241. *
  33242. * @param time - an integer number representing a number of seconds.
  33243. */
  33244. ObjectId.createFromTime = function (time) {
  33245. var buffer = buffer_1.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); // Encode time into first 4 bytes
  33246. buffer.writeUInt32BE(time, 0); // Return the new objectId
  33247. return new ObjectId(buffer);
  33248. };
  33249. /**
  33250. * Creates an ObjectId from a hex string representation of an ObjectId.
  33251. *
  33252. * @param hexString - create a ObjectId from a passed in 24 character hexstring.
  33253. */
  33254. ObjectId.createFromHexString = function (hexString) {
  33255. // Throw an error if it's not a valid setup
  33256. if (typeof hexString === 'undefined' || hexString != null && hexString.length !== 24) {
  33257. throw new BSONTypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
  33258. }
  33259. return new ObjectId(buffer_1.from(hexString, 'hex'));
  33260. };
  33261. /**
  33262. * Checks if a value is a valid bson ObjectId
  33263. *
  33264. * @param id - ObjectId instance to validate.
  33265. */
  33266. ObjectId.isValid = function (id) {
  33267. if (id == null) return false;
  33268. try {
  33269. new ObjectId(id);
  33270. return true;
  33271. } catch (_a) {
  33272. return false;
  33273. }
  33274. };
  33275. /** @internal */
  33276. ObjectId.prototype.toExtendedJSON = function () {
  33277. if (this.toHexString) return {
  33278. $oid: this.toHexString()
  33279. };
  33280. return {
  33281. $oid: this.toString('hex')
  33282. };
  33283. };
  33284. /** @internal */
  33285. ObjectId.fromExtendedJSON = function (doc) {
  33286. return new ObjectId(doc.$oid);
  33287. };
  33288. /**
  33289. * Converts to a string representation of this Id.
  33290. *
  33291. * @returns return the 24 character hex string representation.
  33292. * @internal
  33293. */
  33294. ObjectId.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  33295. return this.inspect();
  33296. };
  33297. ObjectId.prototype.inspect = function () {
  33298. return "new ObjectId(\"" + this.toHexString() + "\")";
  33299. };
  33300. /** @internal */
  33301. ObjectId.index = Math.floor(Math.random() * 0xffffff);
  33302. return ObjectId;
  33303. }(); // Deprecated methods
  33304. Object.defineProperty(_ObjectId.prototype, 'generate', {
  33305. value: deprecate(function (time) {
  33306. return _ObjectId.generate(time);
  33307. }, 'Please use the static `ObjectId.generate(time)` instead')
  33308. });
  33309. Object.defineProperty(_ObjectId.prototype, 'getInc', {
  33310. value: deprecate(function () {
  33311. return _ObjectId.getInc();
  33312. }, 'Please use the static `ObjectId.getInc()` instead')
  33313. });
  33314. Object.defineProperty(_ObjectId.prototype, 'get_inc', {
  33315. value: deprecate(function () {
  33316. return _ObjectId.getInc();
  33317. }, 'Please use the static `ObjectId.getInc()` instead')
  33318. });
  33319. Object.defineProperty(_ObjectId, 'get_inc', {
  33320. value: deprecate(function () {
  33321. return _ObjectId.getInc();
  33322. }, 'Please use the static `ObjectId.getInc()` instead')
  33323. });
  33324. Object.defineProperty(_ObjectId.prototype, '_bsontype', {
  33325. value: 'ObjectID'
  33326. });
  33327. function alphabetize(str) {
  33328. return str.split('').sort().join('');
  33329. }
  33330. /**
  33331. * A class representation of the BSON RegExp type.
  33332. * @public
  33333. * @category BSONType
  33334. */
  33335. var _BSONRegExp =
  33336. /** @class */
  33337. function () {
  33338. /**
  33339. * @param pattern - The regular expression pattern to match
  33340. * @param options - The regular expression options
  33341. */
  33342. function BSONRegExp(pattern, options) {
  33343. if (!(this instanceof BSONRegExp)) return new BSONRegExp(pattern, options);
  33344. this.pattern = pattern;
  33345. this.options = alphabetize(options !== null && options !== void 0 ? options : '');
  33346. if (this.pattern.indexOf('\x00') !== -1) {
  33347. throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
  33348. }
  33349. if (this.options.indexOf('\x00') !== -1) {
  33350. throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
  33351. } // Validate options
  33352. for (var i = 0; i < this.options.length; i++) {
  33353. 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')) {
  33354. throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
  33355. }
  33356. }
  33357. }
  33358. BSONRegExp.parseOptions = function (options) {
  33359. return options ? options.split('').sort().join('') : '';
  33360. };
  33361. /** @internal */
  33362. BSONRegExp.prototype.toExtendedJSON = function (options) {
  33363. options = options || {};
  33364. if (options.legacy) {
  33365. return {
  33366. $regex: this.pattern,
  33367. $options: this.options
  33368. };
  33369. }
  33370. return {
  33371. $regularExpression: {
  33372. pattern: this.pattern,
  33373. options: this.options
  33374. }
  33375. };
  33376. };
  33377. /** @internal */
  33378. BSONRegExp.fromExtendedJSON = function (doc) {
  33379. if ('$regex' in doc) {
  33380. if (typeof doc.$regex !== 'string') {
  33381. // This is for $regex query operators that have extended json values.
  33382. if (doc.$regex._bsontype === 'BSONRegExp') {
  33383. return doc;
  33384. }
  33385. } else {
  33386. return new BSONRegExp(doc.$regex, BSONRegExp.parseOptions(doc.$options));
  33387. }
  33388. }
  33389. if ('$regularExpression' in doc) {
  33390. return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
  33391. }
  33392. throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
  33393. };
  33394. return BSONRegExp;
  33395. }();
  33396. Object.defineProperty(_BSONRegExp.prototype, '_bsontype', {
  33397. value: 'BSONRegExp'
  33398. });
  33399. /**
  33400. * A class representation of the BSON Symbol type.
  33401. * @public
  33402. * @category BSONType
  33403. */
  33404. var BSONSymbol =
  33405. /** @class */
  33406. function () {
  33407. /**
  33408. * @param value - the string representing the symbol.
  33409. */
  33410. function BSONSymbol(value) {
  33411. if (!(this instanceof BSONSymbol)) return new BSONSymbol(value);
  33412. this.value = value;
  33413. }
  33414. /** Access the wrapped string value. */
  33415. BSONSymbol.prototype.valueOf = function () {
  33416. return this.value;
  33417. };
  33418. BSONSymbol.prototype.toString = function () {
  33419. return this.value;
  33420. };
  33421. /** @internal */
  33422. BSONSymbol.prototype.inspect = function () {
  33423. return "new BSONSymbol(\"" + this.value + "\")";
  33424. };
  33425. BSONSymbol.prototype.toJSON = function () {
  33426. return this.value;
  33427. };
  33428. /** @internal */
  33429. BSONSymbol.prototype.toExtendedJSON = function () {
  33430. return {
  33431. $symbol: this.value
  33432. };
  33433. };
  33434. /** @internal */
  33435. BSONSymbol.fromExtendedJSON = function (doc) {
  33436. return new BSONSymbol(doc.$symbol);
  33437. };
  33438. /** @internal */
  33439. BSONSymbol.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  33440. return this.inspect();
  33441. };
  33442. return BSONSymbol;
  33443. }();
  33444. Object.defineProperty(BSONSymbol.prototype, '_bsontype', {
  33445. value: 'Symbol'
  33446. });
  33447. /** @public */
  33448. var LongWithoutOverridesClass = _Long;
  33449. /**
  33450. * @public
  33451. * @category BSONType
  33452. * */
  33453. var _Timestamp =
  33454. /** @class */
  33455. function (_super) {
  33456. __extends(Timestamp, _super);
  33457. function Timestamp(low, high) {
  33458. var _this = this; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  33459. ///@ts-expect-error
  33460. if (!(_this instanceof Timestamp)) return new Timestamp(low, high);
  33461. if (_Long.isLong(low)) {
  33462. _this = _super.call(this, low.low, low.high, true) || this;
  33463. } else if (isObjectLike(low) && typeof low.t !== 'undefined' && typeof low.i !== 'undefined') {
  33464. _this = _super.call(this, low.i, low.t, true) || this;
  33465. } else {
  33466. _this = _super.call(this, low, high, true) || this;
  33467. }
  33468. Object.defineProperty(_this, '_bsontype', {
  33469. value: 'Timestamp',
  33470. writable: false,
  33471. configurable: false,
  33472. enumerable: false
  33473. });
  33474. return _this;
  33475. }
  33476. Timestamp.prototype.toJSON = function () {
  33477. return {
  33478. $timestamp: this.toString()
  33479. };
  33480. };
  33481. /** Returns a Timestamp represented by the given (32-bit) integer value. */
  33482. Timestamp.fromInt = function (value) {
  33483. return new Timestamp(_Long.fromInt(value, true));
  33484. };
  33485. /** Returns a Timestamp representing the given number value, provided that it is a finite number. Otherwise, zero is returned. */
  33486. Timestamp.fromNumber = function (value) {
  33487. return new Timestamp(_Long.fromNumber(value, true));
  33488. };
  33489. /**
  33490. * Returns a Timestamp for the given high and low bits. Each is assumed to use 32 bits.
  33491. *
  33492. * @param lowBits - the low 32-bits.
  33493. * @param highBits - the high 32-bits.
  33494. */
  33495. Timestamp.fromBits = function (lowBits, highBits) {
  33496. return new Timestamp(lowBits, highBits);
  33497. };
  33498. /**
  33499. * Returns a Timestamp from the given string, optionally using the given radix.
  33500. *
  33501. * @param str - the textual representation of the Timestamp.
  33502. * @param optRadix - the radix in which the text is written.
  33503. */
  33504. Timestamp.fromString = function (str, optRadix) {
  33505. return new Timestamp(_Long.fromString(str, true, optRadix));
  33506. };
  33507. /** @internal */
  33508. Timestamp.prototype.toExtendedJSON = function () {
  33509. return {
  33510. $timestamp: {
  33511. t: this.high >>> 0,
  33512. i: this.low >>> 0
  33513. }
  33514. };
  33515. };
  33516. /** @internal */
  33517. Timestamp.fromExtendedJSON = function (doc) {
  33518. return new Timestamp(doc.$timestamp);
  33519. };
  33520. /** @internal */
  33521. Timestamp.prototype[Symbol["for"]('nodejs.util.inspect.custom')] = function () {
  33522. return this.inspect();
  33523. };
  33524. Timestamp.prototype.inspect = function () {
  33525. return "new Timestamp({ t: " + this.getHighBits() + ", i: " + this.getLowBits() + " })";
  33526. };
  33527. Timestamp.MAX_VALUE = _Long.MAX_UNSIGNED_VALUE;
  33528. return Timestamp;
  33529. }(LongWithoutOverridesClass);
  33530. function isBSONType(value) {
  33531. return isObjectLike(value) && Reflect.has(value, '_bsontype') && typeof value._bsontype === 'string';
  33532. } // INT32 boundaries
  33533. var BSON_INT32_MAX$1 = 0x7fffffff;
  33534. var BSON_INT32_MIN$1 = -0x80000000; // INT64 boundaries
  33535. var BSON_INT64_MAX$1 = 0x7fffffffffffffff;
  33536. var BSON_INT64_MIN$1 = -0x8000000000000000; // all the types where we don't need to do any special processing and can just pass the EJSON
  33537. //straight to type.fromExtendedJSON
  33538. var keysToCodecs = {
  33539. $oid: _ObjectId,
  33540. $binary: _Binary,
  33541. $uuid: _Binary,
  33542. $symbol: BSONSymbol,
  33543. $numberInt: _Int,
  33544. $numberDecimal: _Decimal,
  33545. $numberDouble: _Double,
  33546. $numberLong: _Long,
  33547. $minKey: _MinKey,
  33548. $maxKey: _MaxKey,
  33549. $regex: _BSONRegExp,
  33550. $regularExpression: _BSONRegExp,
  33551. $timestamp: _Timestamp
  33552. }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33553. function deserializeValue(value, options) {
  33554. if (options === void 0) {
  33555. options = {};
  33556. }
  33557. if (typeof value === 'number') {
  33558. if (options.relaxed || options.legacy) {
  33559. return value;
  33560. } // if it's an integer, should interpret as smallest BSON integer
  33561. // that can represent it exactly. (if out of range, interpret as double.)
  33562. if (Math.floor(value) === value) {
  33563. if (value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1) return new _Int(value);
  33564. if (value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1) return _Long.fromNumber(value);
  33565. } // If the number is a non-integer or out of integer range, should interpret as BSON Double.
  33566. return new _Double(value);
  33567. } // from here on out we're looking for bson types, so bail if its not an object
  33568. if (value == null || _typeof(value) !== 'object') return value; // upgrade deprecated undefined to null
  33569. if (value.$undefined) return null;
  33570. var keys = Object.keys(value).filter(function (k) {
  33571. return k.startsWith('$') && value[k] != null;
  33572. });
  33573. for (var i = 0; i < keys.length; i++) {
  33574. var c = keysToCodecs[keys[i]];
  33575. if (c) return c.fromExtendedJSON(value, options);
  33576. }
  33577. if (value.$date != null) {
  33578. var d = value.$date;
  33579. var date = new Date();
  33580. if (options.legacy) {
  33581. if (typeof d === 'number') date.setTime(d);else if (typeof d === 'string') date.setTime(Date.parse(d));
  33582. } else {
  33583. if (typeof d === 'string') date.setTime(Date.parse(d));else if (_Long.isLong(d)) date.setTime(d.toNumber());else if (typeof d === 'number' && options.relaxed) date.setTime(d);
  33584. }
  33585. return date;
  33586. }
  33587. if (value.$code != null) {
  33588. var copy = Object.assign({}, value);
  33589. if (value.$scope) {
  33590. copy.$scope = deserializeValue(value.$scope);
  33591. }
  33592. return _Code.fromExtendedJSON(value);
  33593. }
  33594. if (isDBRefLike(value) || value.$dbPointer) {
  33595. var v = value.$ref ? value : value.$dbPointer; // we run into this in a "degenerate EJSON" case (with $id and $ref order flipped)
  33596. // because of the order JSON.parse goes through the document
  33597. if (v instanceof _DBRef) return v;
  33598. var dollarKeys = Object.keys(v).filter(function (k) {
  33599. return k.startsWith('$');
  33600. });
  33601. var valid_1 = true;
  33602. dollarKeys.forEach(function (k) {
  33603. if (['$ref', '$id', '$db'].indexOf(k) === -1) valid_1 = false;
  33604. }); // only make DBRef if $ keys are all valid
  33605. if (valid_1) return _DBRef.fromExtendedJSON(v);
  33606. }
  33607. return value;
  33608. } // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33609. function serializeArray(array, options) {
  33610. return array.map(function (v, index) {
  33611. options.seenObjects.push({
  33612. propertyName: "index " + index,
  33613. obj: null
  33614. });
  33615. try {
  33616. return serializeValue(v, options);
  33617. } finally {
  33618. options.seenObjects.pop();
  33619. }
  33620. });
  33621. }
  33622. function getISOString(date) {
  33623. var isoStr = date.toISOString(); // we should only show milliseconds in timestamp if they're non-zero
  33624. return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
  33625. } // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33626. function serializeValue(value, options) {
  33627. if ((_typeof(value) === 'object' || typeof value === 'function') && value !== null) {
  33628. var index = options.seenObjects.findIndex(function (entry) {
  33629. return entry.obj === value;
  33630. });
  33631. if (index !== -1) {
  33632. var props = options.seenObjects.map(function (entry) {
  33633. return entry.propertyName;
  33634. });
  33635. var leadingPart = props.slice(0, index).map(function (prop) {
  33636. return prop + " -> ";
  33637. }).join('');
  33638. var alreadySeen = props[index];
  33639. var circularPart = ' -> ' + props.slice(index + 1, props.length - 1).map(function (prop) {
  33640. return prop + " -> ";
  33641. }).join('');
  33642. var current = props[props.length - 1];
  33643. var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
  33644. var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
  33645. throw new BSONTypeError('Converting circular structure to EJSON:\n' + (" " + leadingPart + alreadySeen + circularPart + current + "\n") + (" " + leadingSpace + "\\" + dashes + "/"));
  33646. }
  33647. options.seenObjects[options.seenObjects.length - 1].obj = value;
  33648. }
  33649. if (Array.isArray(value)) return serializeArray(value, options);
  33650. if (value === undefined) return null;
  33651. if (value instanceof Date || isDate(value)) {
  33652. var dateNum = value.getTime(),
  33653. // is it in year range 1970-9999?
  33654. inRange = dateNum > -1 && dateNum < 253402318800000;
  33655. if (options.legacy) {
  33656. return options.relaxed && inRange ? {
  33657. $date: value.getTime()
  33658. } : {
  33659. $date: getISOString(value)
  33660. };
  33661. }
  33662. return options.relaxed && inRange ? {
  33663. $date: getISOString(value)
  33664. } : {
  33665. $date: {
  33666. $numberLong: value.getTime().toString()
  33667. }
  33668. };
  33669. }
  33670. if (typeof value === 'number' && (!options.relaxed || !isFinite(value))) {
  33671. // it's an integer
  33672. if (Math.floor(value) === value) {
  33673. var int32Range = value >= BSON_INT32_MIN$1 && value <= BSON_INT32_MAX$1,
  33674. int64Range = value >= BSON_INT64_MIN$1 && value <= BSON_INT64_MAX$1; // interpret as being of the smallest BSON integer type that can represent the number exactly
  33675. if (int32Range) return {
  33676. $numberInt: value.toString()
  33677. };
  33678. if (int64Range) return {
  33679. $numberLong: value.toString()
  33680. };
  33681. }
  33682. return {
  33683. $numberDouble: value.toString()
  33684. };
  33685. }
  33686. if (value instanceof RegExp || isRegExp(value)) {
  33687. var flags = value.flags;
  33688. if (flags === undefined) {
  33689. var match = value.toString().match(/[gimuy]*$/);
  33690. if (match) {
  33691. flags = match[0];
  33692. }
  33693. }
  33694. var rx = new _BSONRegExp(value.source, flags);
  33695. return rx.toExtendedJSON(options);
  33696. }
  33697. if (value != null && _typeof(value) === 'object') return serializeDocument(value, options);
  33698. return value;
  33699. }
  33700. var BSON_TYPE_MAPPINGS = {
  33701. Binary: function Binary(o) {
  33702. return new _Binary(o.value(), o.sub_type);
  33703. },
  33704. Code: function Code(o) {
  33705. return new _Code(o.code, o.scope);
  33706. },
  33707. DBRef: function DBRef(o) {
  33708. return new _DBRef(o.collection || o.namespace, o.oid, o.db, o.fields);
  33709. },
  33710. Decimal128: function Decimal128(o) {
  33711. return new _Decimal(o.bytes);
  33712. },
  33713. Double: function Double(o) {
  33714. return new _Double(o.value);
  33715. },
  33716. Int32: function Int32(o) {
  33717. return new _Int(o.value);
  33718. },
  33719. Long: function Long(o) {
  33720. return _Long.fromBits( // underscore variants for 1.x backwards compatibility
  33721. o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_);
  33722. },
  33723. MaxKey: function MaxKey() {
  33724. return new _MaxKey();
  33725. },
  33726. MinKey: function MinKey() {
  33727. return new _MinKey();
  33728. },
  33729. ObjectID: function ObjectID(o) {
  33730. return new _ObjectId(o);
  33731. },
  33732. ObjectId: function ObjectId(o) {
  33733. return new _ObjectId(o);
  33734. },
  33735. BSONRegExp: function BSONRegExp(o) {
  33736. return new _BSONRegExp(o.pattern, o.options);
  33737. },
  33738. Symbol: function Symbol(o) {
  33739. return new BSONSymbol(o.value);
  33740. },
  33741. Timestamp: function Timestamp(o) {
  33742. return _Timestamp.fromBits(o.low, o.high);
  33743. }
  33744. }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33745. function serializeDocument(doc, options) {
  33746. if (doc == null || _typeof(doc) !== 'object') throw new BSONError('not an object instance');
  33747. var bsontype = doc._bsontype;
  33748. if (typeof bsontype === 'undefined') {
  33749. // It's a regular object. Recursively serialize its property values.
  33750. var _doc = {};
  33751. for (var name in doc) {
  33752. options.seenObjects.push({
  33753. propertyName: name,
  33754. obj: null
  33755. });
  33756. try {
  33757. _doc[name] = serializeValue(doc[name], options);
  33758. } finally {
  33759. options.seenObjects.pop();
  33760. }
  33761. }
  33762. return _doc;
  33763. } else if (isBSONType(doc)) {
  33764. // the "document" is really just a BSON type object
  33765. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33766. var outDoc = doc;
  33767. if (typeof outDoc.toExtendedJSON !== 'function') {
  33768. // There's no EJSON serialization function on the object. It's probably an
  33769. // object created by a previous version of this library (or another library)
  33770. // that's duck-typing objects to look like they were generated by this library).
  33771. // Copy the object into this library's version of that type.
  33772. var mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
  33773. if (!mapper) {
  33774. throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
  33775. }
  33776. outDoc = mapper(outDoc);
  33777. } // Two BSON types may have nested objects that may need to be serialized too
  33778. if (bsontype === 'Code' && outDoc.scope) {
  33779. outDoc = new _Code(outDoc.code, serializeValue(outDoc.scope, options));
  33780. } else if (bsontype === 'DBRef' && outDoc.oid) {
  33781. outDoc = new _DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
  33782. }
  33783. return outDoc.toExtendedJSON(options);
  33784. } else {
  33785. throw new BSONError('_bsontype must be a string, but was: ' + _typeof(bsontype));
  33786. }
  33787. }
  33788. /**
  33789. * EJSON parse / stringify API
  33790. * @public
  33791. */
  33792. // the namespace here is used to emulate `export * as EJSON from '...'`
  33793. // which as of now (sept 2020) api-extractor does not support
  33794. // eslint-disable-next-line @typescript-eslint/no-namespace
  33795. var EJSON;
  33796. (function (EJSON) {
  33797. /**
  33798. * Parse an Extended JSON string, constructing the JavaScript value or object described by that
  33799. * string.
  33800. *
  33801. * @example
  33802. * ```js
  33803. * const { EJSON } = require('bson');
  33804. * const text = '{ "int32": { "$numberInt": "10" } }';
  33805. *
  33806. * // prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
  33807. * console.log(EJSON.parse(text, { relaxed: false }));
  33808. *
  33809. * // prints { int32: 10 }
  33810. * console.log(EJSON.parse(text));
  33811. * ```
  33812. */
  33813. function parse(text, options) {
  33814. var finalOptions = Object.assign({}, {
  33815. relaxed: true,
  33816. legacy: false
  33817. }, options); // relaxed implies not strict
  33818. if (typeof finalOptions.relaxed === 'boolean') finalOptions.strict = !finalOptions.relaxed;
  33819. if (typeof finalOptions.strict === 'boolean') finalOptions.relaxed = !finalOptions.strict;
  33820. return JSON.parse(text, function (key, value) {
  33821. if (key.indexOf('\x00') !== -1) {
  33822. throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
  33823. }
  33824. return deserializeValue(value, finalOptions);
  33825. });
  33826. }
  33827. EJSON.parse = parse;
  33828. /**
  33829. * Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer
  33830. * function is specified or optionally including only the specified properties if a replacer array
  33831. * is specified.
  33832. *
  33833. * @param value - The value to convert to extended JSON
  33834. * @param 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
  33835. * @param space - A String or Number object that's used to insert white space into the output JSON string for readability purposes.
  33836. * @param options - Optional settings
  33837. *
  33838. * @example
  33839. * ```js
  33840. * const { EJSON } = require('bson');
  33841. * const Int32 = require('mongodb').Int32;
  33842. * const doc = { int32: new Int32(10) };
  33843. *
  33844. * // prints '{"int32":{"$numberInt":"10"}}'
  33845. * console.log(EJSON.stringify(doc, { relaxed: false }));
  33846. *
  33847. * // prints '{"int32":10}'
  33848. * console.log(EJSON.stringify(doc));
  33849. * ```
  33850. */
  33851. function stringify(value, // eslint-disable-next-line @typescript-eslint/no-explicit-any
  33852. replacer, space, options) {
  33853. if (space != null && _typeof(space) === 'object') {
  33854. options = space;
  33855. space = 0;
  33856. }
  33857. if (replacer != null && _typeof(replacer) === 'object' && !Array.isArray(replacer)) {
  33858. options = replacer;
  33859. replacer = undefined;
  33860. space = 0;
  33861. }
  33862. var serializeOptions = Object.assign({
  33863. relaxed: true,
  33864. legacy: false
  33865. }, options, {
  33866. seenObjects: [{
  33867. propertyName: '(root)',
  33868. obj: null
  33869. }]
  33870. });
  33871. var doc = serializeValue(value, serializeOptions);
  33872. return JSON.stringify(doc, replacer, space);
  33873. }
  33874. EJSON.stringify = stringify;
  33875. /**
  33876. * Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.
  33877. *
  33878. * @param value - The object to serialize
  33879. * @param options - Optional settings passed to the `stringify` function
  33880. */
  33881. function serialize(value, options) {
  33882. options = options || {};
  33883. return JSON.parse(stringify(value, options));
  33884. }
  33885. EJSON.serialize = serialize;
  33886. /**
  33887. * Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types
  33888. *
  33889. * @param ejson - The Extended JSON object to deserialize
  33890. * @param options - Optional settings passed to the parse method
  33891. */
  33892. function deserialize(ejson, options) {
  33893. options = options || {};
  33894. return parse(JSON.stringify(ejson), options);
  33895. }
  33896. EJSON.deserialize = deserialize;
  33897. })(EJSON || (EJSON = {}));
  33898. /* eslint-disable @typescript-eslint/no-explicit-any */
  33899. /** @public */
  33900. var bsonMap;
  33901. var bsonGlobal = getGlobal();
  33902. if (bsonGlobal.Map) {
  33903. bsonMap = bsonGlobal.Map;
  33904. } else {
  33905. // We will return a polyfill
  33906. bsonMap =
  33907. /** @class */
  33908. function () {
  33909. function Map(array) {
  33910. if (array === void 0) {
  33911. array = [];
  33912. }
  33913. this._keys = [];
  33914. this._values = {};
  33915. for (var i = 0; i < array.length; i++) {
  33916. if (array[i] == null) continue; // skip null and undefined
  33917. var entry = array[i];
  33918. var key = entry[0];
  33919. var value = entry[1]; // Add the key to the list of keys in order
  33920. this._keys.push(key); // Add the key and value to the values dictionary with a point
  33921. // to the location in the ordered keys list
  33922. this._values[key] = {
  33923. v: value,
  33924. i: this._keys.length - 1
  33925. };
  33926. }
  33927. }
  33928. Map.prototype.clear = function () {
  33929. this._keys = [];
  33930. this._values = {};
  33931. };
  33932. Map.prototype["delete"] = function (key) {
  33933. var value = this._values[key];
  33934. if (value == null) return false; // Delete entry
  33935. delete this._values[key]; // Remove the key from the ordered keys list
  33936. this._keys.splice(value.i, 1);
  33937. return true;
  33938. };
  33939. Map.prototype.entries = function () {
  33940. var _this = this;
  33941. var index = 0;
  33942. return {
  33943. next: function next() {
  33944. var key = _this._keys[index++];
  33945. return {
  33946. value: key !== undefined ? [key, _this._values[key].v] : undefined,
  33947. done: key !== undefined ? false : true
  33948. };
  33949. }
  33950. };
  33951. };
  33952. Map.prototype.forEach = function (callback, self) {
  33953. self = self || this;
  33954. for (var i = 0; i < this._keys.length; i++) {
  33955. var key = this._keys[i]; // Call the forEach callback
  33956. callback.call(self, this._values[key].v, key, self);
  33957. }
  33958. };
  33959. Map.prototype.get = function (key) {
  33960. return this._values[key] ? this._values[key].v : undefined;
  33961. };
  33962. Map.prototype.has = function (key) {
  33963. return this._values[key] != null;
  33964. };
  33965. Map.prototype.keys = function () {
  33966. var _this = this;
  33967. var index = 0;
  33968. return {
  33969. next: function next() {
  33970. var key = _this._keys[index++];
  33971. return {
  33972. value: key !== undefined ? key : undefined,
  33973. done: key !== undefined ? false : true
  33974. };
  33975. }
  33976. };
  33977. };
  33978. Map.prototype.set = function (key, value) {
  33979. if (this._values[key]) {
  33980. this._values[key].v = value;
  33981. return this;
  33982. } // Add the key to the list of keys in order
  33983. this._keys.push(key); // Add the key and value to the values dictionary with a point
  33984. // to the location in the ordered keys list
  33985. this._values[key] = {
  33986. v: value,
  33987. i: this._keys.length - 1
  33988. };
  33989. return this;
  33990. };
  33991. Map.prototype.values = function () {
  33992. var _this = this;
  33993. var index = 0;
  33994. return {
  33995. next: function next() {
  33996. var key = _this._keys[index++];
  33997. return {
  33998. value: key !== undefined ? _this._values[key].v : undefined,
  33999. done: key !== undefined ? false : true
  34000. };
  34001. }
  34002. };
  34003. };
  34004. Object.defineProperty(Map.prototype, "size", {
  34005. get: function get() {
  34006. return this._keys.length;
  34007. },
  34008. enumerable: false,
  34009. configurable: true
  34010. });
  34011. return Map;
  34012. }();
  34013. }
  34014. /** @internal */
  34015. var BSON_INT32_MAX = 0x7fffffff;
  34016. /** @internal */
  34017. var BSON_INT32_MIN = -0x80000000;
  34018. /** @internal */
  34019. var BSON_INT64_MAX = Math.pow(2, 63) - 1;
  34020. /** @internal */
  34021. var BSON_INT64_MIN = -Math.pow(2, 63);
  34022. /**
  34023. * Any integer up to 2^53 can be precisely represented by a double.
  34024. * @internal
  34025. */
  34026. var JS_INT_MAX = Math.pow(2, 53);
  34027. /**
  34028. * Any integer down to -2^53 can be precisely represented by a double.
  34029. * @internal
  34030. */
  34031. var JS_INT_MIN = -Math.pow(2, 53);
  34032. /** Number BSON Type @internal */
  34033. var BSON_DATA_NUMBER = 1;
  34034. /** String BSON Type @internal */
  34035. var BSON_DATA_STRING = 2;
  34036. /** Object BSON Type @internal */
  34037. var BSON_DATA_OBJECT = 3;
  34038. /** Array BSON Type @internal */
  34039. var BSON_DATA_ARRAY = 4;
  34040. /** Binary BSON Type @internal */
  34041. var BSON_DATA_BINARY = 5;
  34042. /** Binary BSON Type @internal */
  34043. var BSON_DATA_UNDEFINED = 6;
  34044. /** ObjectId BSON Type @internal */
  34045. var BSON_DATA_OID = 7;
  34046. /** Boolean BSON Type @internal */
  34047. var BSON_DATA_BOOLEAN = 8;
  34048. /** Date BSON Type @internal */
  34049. var BSON_DATA_DATE = 9;
  34050. /** null BSON Type @internal */
  34051. var BSON_DATA_NULL = 10;
  34052. /** RegExp BSON Type @internal */
  34053. var BSON_DATA_REGEXP = 11;
  34054. /** Code BSON Type @internal */
  34055. var BSON_DATA_DBPOINTER = 12;
  34056. /** Code BSON Type @internal */
  34057. var BSON_DATA_CODE = 13;
  34058. /** Symbol BSON Type @internal */
  34059. var BSON_DATA_SYMBOL = 14;
  34060. /** Code with Scope BSON Type @internal */
  34061. var BSON_DATA_CODE_W_SCOPE = 15;
  34062. /** 32 bit Integer BSON Type @internal */
  34063. var BSON_DATA_INT = 16;
  34064. /** Timestamp BSON Type @internal */
  34065. var BSON_DATA_TIMESTAMP = 17;
  34066. /** Long BSON Type @internal */
  34067. var BSON_DATA_LONG = 18;
  34068. /** Decimal128 BSON Type @internal */
  34069. var BSON_DATA_DECIMAL128 = 19;
  34070. /** MinKey BSON Type @internal */
  34071. var BSON_DATA_MIN_KEY = 0xff;
  34072. /** MaxKey BSON Type @internal */
  34073. var BSON_DATA_MAX_KEY = 0x7f;
  34074. /** Binary Default Type @internal */
  34075. var BSON_BINARY_SUBTYPE_DEFAULT = 0;
  34076. /** Binary Function Type @internal */
  34077. var BSON_BINARY_SUBTYPE_FUNCTION = 1;
  34078. /** Binary Byte Array Type @internal */
  34079. var BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
  34080. /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
  34081. var BSON_BINARY_SUBTYPE_UUID = 3;
  34082. /** Binary UUID Type @internal */
  34083. var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
  34084. /** Binary MD5 Type @internal */
  34085. var BSON_BINARY_SUBTYPE_MD5 = 5;
  34086. /** Encrypted BSON type @internal */
  34087. var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
  34088. /** Column BSON type @internal */
  34089. var BSON_BINARY_SUBTYPE_COLUMN = 7;
  34090. /** Binary User Defined Type @internal */
  34091. var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
  34092. function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
  34093. var totalLength = 4 + 1;
  34094. if (Array.isArray(object)) {
  34095. for (var i = 0; i < object.length; i++) {
  34096. totalLength += calculateElement(i.toString(), object[i], serializeFunctions, true, ignoreUndefined);
  34097. }
  34098. } else {
  34099. // If we have toBSON defined, override the current object
  34100. if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
  34101. object = object.toBSON();
  34102. } // Calculate size
  34103. for (var key in object) {
  34104. totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined);
  34105. }
  34106. }
  34107. return totalLength;
  34108. }
  34109. /** @internal */
  34110. function calculateElement(name, // eslint-disable-next-line @typescript-eslint/no-explicit-any
  34111. value, serializeFunctions, isArray, ignoreUndefined) {
  34112. if (serializeFunctions === void 0) {
  34113. serializeFunctions = false;
  34114. }
  34115. if (isArray === void 0) {
  34116. isArray = false;
  34117. }
  34118. if (ignoreUndefined === void 0) {
  34119. ignoreUndefined = false;
  34120. } // If we have toBSON defined, override the current object
  34121. if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
  34122. value = value.toBSON();
  34123. }
  34124. switch (_typeof(value)) {
  34125. case 'string':
  34126. return 1 + buffer_1.byteLength(name, 'utf8') + 1 + 4 + buffer_1.byteLength(value, 'utf8') + 1;
  34127. case 'number':
  34128. if (Math.floor(value) === value && value >= JS_INT_MIN && value <= JS_INT_MAX) {
  34129. if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
  34130. // 32 bit
  34131. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (4 + 1);
  34132. } else {
  34133. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  34134. }
  34135. } else {
  34136. // 64 bit
  34137. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  34138. }
  34139. case 'undefined':
  34140. if (isArray || !ignoreUndefined) return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
  34141. return 0;
  34142. case 'boolean':
  34143. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 1);
  34144. case 'object':
  34145. if (value == null || value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  34146. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1;
  34147. } else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
  34148. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (12 + 1);
  34149. } else if (value instanceof Date || isDate(value)) {
  34150. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  34151. } else if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isAnyArrayBuffer(value)) {
  34152. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (1 + 4 + 1) + value.byteLength;
  34153. } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Double' || value['_bsontype'] === 'Timestamp') {
  34154. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (8 + 1);
  34155. } else if (value['_bsontype'] === 'Decimal128') {
  34156. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (16 + 1);
  34157. } else if (value['_bsontype'] === 'Code') {
  34158. // Calculate size depending on the availability of a scope
  34159. if (value.scope != null && Object.keys(value.scope).length > 0) {
  34160. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + 4 + buffer_1.byteLength(value.code.toString(), 'utf8') + 1 + calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined);
  34161. } else {
  34162. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + buffer_1.byteLength(value.code.toString(), 'utf8') + 1;
  34163. }
  34164. } else if (value['_bsontype'] === 'Binary') {
  34165. // Check what kind of subtype we have
  34166. if (value.sub_type === _Binary.SUBTYPE_BYTE_ARRAY) {
  34167. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1 + 4);
  34168. } else {
  34169. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1);
  34170. }
  34171. } else if (value['_bsontype'] === 'Symbol') {
  34172. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + buffer_1.byteLength(value.value, 'utf8') + 4 + 1 + 1;
  34173. } else if (value['_bsontype'] === 'DBRef') {
  34174. // Set up correct object for serialization
  34175. var ordered_values = Object.assign({
  34176. $ref: value.collection,
  34177. $id: value.oid
  34178. }, value.fields); // Add db reference if it exists
  34179. if (value.db != null) {
  34180. ordered_values['$db'] = value.db;
  34181. }
  34182. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + calculateObjectSize$1(ordered_values, serializeFunctions, ignoreUndefined);
  34183. } else if (value instanceof RegExp || isRegExp(value)) {
  34184. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + buffer_1.byteLength(value.source, 'utf8') + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
  34185. } else if (value['_bsontype'] === 'BSONRegExp') {
  34186. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + buffer_1.byteLength(value.pattern, 'utf8') + 1 + buffer_1.byteLength(value.options, 'utf8') + 1;
  34187. } else {
  34188. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + calculateObjectSize$1(value, serializeFunctions, ignoreUndefined) + 1;
  34189. }
  34190. case 'function':
  34191. // WTF for 0.4.X where typeof /someregexp/ === 'function'
  34192. if (value instanceof RegExp || isRegExp(value) || String.call(value) === '[object RegExp]') {
  34193. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + buffer_1.byteLength(value.source, 'utf8') + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
  34194. } else {
  34195. if (serializeFunctions && value.scope != null && Object.keys(value.scope).length > 0) {
  34196. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + 4 + buffer_1.byteLength(normalizedFunctionString(value), 'utf8') + 1 + calculateObjectSize$1(value.scope, serializeFunctions, ignoreUndefined);
  34197. } else if (serializeFunctions) {
  34198. return (name != null ? buffer_1.byteLength(name, 'utf8') + 1 : 0) + 1 + 4 + buffer_1.byteLength(normalizedFunctionString(value), 'utf8') + 1;
  34199. }
  34200. }
  34201. }
  34202. return 0;
  34203. }
  34204. var FIRST_BIT = 0x80;
  34205. var FIRST_TWO_BITS = 0xc0;
  34206. var FIRST_THREE_BITS = 0xe0;
  34207. var FIRST_FOUR_BITS = 0xf0;
  34208. var FIRST_FIVE_BITS = 0xf8;
  34209. var TWO_BIT_CHAR = 0xc0;
  34210. var THREE_BIT_CHAR = 0xe0;
  34211. var FOUR_BIT_CHAR = 0xf0;
  34212. var CONTINUING_CHAR = 0x80;
  34213. /**
  34214. * Determines if the passed in bytes are valid utf8
  34215. * @param bytes - An array of 8-bit bytes. Must be indexable and have length property
  34216. * @param start - The index to start validating
  34217. * @param end - The index to end validating
  34218. */
  34219. function validateUtf8(bytes, start, end) {
  34220. var continuation = 0;
  34221. for (var i = start; i < end; i += 1) {
  34222. var _byte = bytes[i];
  34223. if (continuation) {
  34224. if ((_byte & FIRST_TWO_BITS) !== CONTINUING_CHAR) {
  34225. return false;
  34226. }
  34227. continuation -= 1;
  34228. } else if (_byte & FIRST_BIT) {
  34229. if ((_byte & FIRST_THREE_BITS) === TWO_BIT_CHAR) {
  34230. continuation = 1;
  34231. } else if ((_byte & FIRST_FOUR_BITS) === THREE_BIT_CHAR) {
  34232. continuation = 2;
  34233. } else if ((_byte & FIRST_FIVE_BITS) === FOUR_BIT_CHAR) {
  34234. continuation = 3;
  34235. } else {
  34236. return false;
  34237. }
  34238. }
  34239. }
  34240. return !continuation;
  34241. } // Internal long versions
  34242. var JS_INT_MAX_LONG = _Long.fromNumber(JS_INT_MAX);
  34243. var JS_INT_MIN_LONG = _Long.fromNumber(JS_INT_MIN);
  34244. var functionCache = {};
  34245. function deserialize$1(buffer, options, isArray) {
  34246. options = options == null ? {} : options;
  34247. var index = options && options.index ? options.index : 0; // Read the document size
  34248. var size = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
  34249. if (size < 5) {
  34250. throw new BSONError("bson size must be >= 5, is " + size);
  34251. }
  34252. if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
  34253. throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
  34254. }
  34255. if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
  34256. throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
  34257. }
  34258. if (size + index > buffer.byteLength) {
  34259. throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
  34260. } // Illegal end value
  34261. if (buffer[index + size - 1] !== 0) {
  34262. throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
  34263. } // Start deserializtion
  34264. return deserializeObject(buffer, index, options, isArray);
  34265. }
  34266. var allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
  34267. function deserializeObject(buffer, index, options, isArray) {
  34268. if (isArray === void 0) {
  34269. isArray = false;
  34270. }
  34271. var evalFunctions = options['evalFunctions'] == null ? false : options['evalFunctions'];
  34272. var cacheFunctions = options['cacheFunctions'] == null ? false : options['cacheFunctions'];
  34273. var fieldsAsRaw = options['fieldsAsRaw'] == null ? null : options['fieldsAsRaw']; // Return raw bson buffer instead of parsing it
  34274. var raw = options['raw'] == null ? false : options['raw']; // Return BSONRegExp objects instead of native regular expressions
  34275. var bsonRegExp = typeof options['bsonRegExp'] === 'boolean' ? options['bsonRegExp'] : false; // Controls the promotion of values vs wrapper classes
  34276. var promoteBuffers = options['promoteBuffers'] == null ? false : options['promoteBuffers'];
  34277. var promoteLongs = options['promoteLongs'] == null ? true : options['promoteLongs'];
  34278. var promoteValues = options['promoteValues'] == null ? true : options['promoteValues']; // Ensures default validation option if none given
  34279. var validation = options.validation == null ? {
  34280. utf8: true
  34281. } : options.validation; // Shows if global utf-8 validation is enabled or disabled
  34282. var globalUTFValidation = true; // Reflects utf-8 validation setting regardless of global or specific key validation
  34283. var validationSetting; // Set of keys either to enable or disable validation on
  34284. var utf8KeysSet = new Set(); // Check for boolean uniformity and empty validation option
  34285. var utf8ValidatedKeys = validation.utf8;
  34286. if (typeof utf8ValidatedKeys === 'boolean') {
  34287. validationSetting = utf8ValidatedKeys;
  34288. } else {
  34289. globalUTFValidation = false;
  34290. var utf8ValidationValues = Object.keys(utf8ValidatedKeys).map(function (key) {
  34291. return utf8ValidatedKeys[key];
  34292. });
  34293. if (utf8ValidationValues.length === 0) {
  34294. throw new BSONError('UTF-8 validation setting cannot be empty');
  34295. }
  34296. if (typeof utf8ValidationValues[0] !== 'boolean') {
  34297. throw new BSONError('Invalid UTF-8 validation option, must specify boolean values');
  34298. }
  34299. validationSetting = utf8ValidationValues[0]; // Ensures boolean uniformity in utf-8 validation (all true or all false)
  34300. if (!utf8ValidationValues.every(function (item) {
  34301. return item === validationSetting;
  34302. })) {
  34303. throw new BSONError('Invalid UTF-8 validation option - keys must be all true or all false');
  34304. }
  34305. } // Add keys to set that will either be validated or not based on validationSetting
  34306. if (!globalUTFValidation) {
  34307. for (var _i = 0, _a = Object.keys(utf8ValidatedKeys); _i < _a.length; _i++) {
  34308. var key = _a[_i];
  34309. utf8KeysSet.add(key);
  34310. }
  34311. } // Set the start index
  34312. var startIndex = index; // Validate that we have at least 4 bytes of buffer
  34313. if (buffer.length < 5) throw new BSONError('corrupt bson message < 5 bytes long'); // Read the document size
  34314. var size = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Ensure buffer is valid size
  34315. if (size < 5 || size > buffer.length) throw new BSONError('corrupt bson message'); // Create holding object
  34316. var object = isArray ? [] : {}; // Used for arrays to skip having to perform utf8 decoding
  34317. var arrayIndex = 0;
  34318. var done = false;
  34319. var isPossibleDBRef = isArray ? false : null; // While we have more left data left keep parsing
  34320. while (!done) {
  34321. // Read the type
  34322. var elementType = buffer[index++]; // If we get a zero it's the last byte, exit
  34323. if (elementType === 0) break; // Get the start search index
  34324. var i = index; // Locate the end of the c string
  34325. while (buffer[i] !== 0x00 && i < buffer.length) {
  34326. i++;
  34327. } // If are at the end of the buffer there is a problem with the document
  34328. if (i >= buffer.byteLength) throw new BSONError('Bad BSON Document: illegal CString'); // Represents the key
  34329. var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i); // shouldValidateKey is true if the key should be validated, false otherwise
  34330. var shouldValidateKey = true;
  34331. if (globalUTFValidation || utf8KeysSet.has(name)) {
  34332. shouldValidateKey = validationSetting;
  34333. } else {
  34334. shouldValidateKey = !validationSetting;
  34335. }
  34336. if (isPossibleDBRef !== false && name[0] === '$') {
  34337. isPossibleDBRef = allowedDBRefKeys.test(name);
  34338. }
  34339. var value = void 0;
  34340. index = i + 1;
  34341. if (elementType === BSON_DATA_STRING) {
  34342. var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34343. if (stringSize <= 0 || stringSize > buffer.length - index || buffer[index + stringSize - 1] !== 0) {
  34344. throw new BSONError('bad string length in bson');
  34345. }
  34346. value = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey);
  34347. index = index + stringSize;
  34348. } else if (elementType === BSON_DATA_OID) {
  34349. var oid = buffer_1.alloc(12);
  34350. buffer.copy(oid, 0, index, index + 12);
  34351. value = new _ObjectId(oid);
  34352. index = index + 12;
  34353. } else if (elementType === BSON_DATA_INT && promoteValues === false) {
  34354. value = new _Int(buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24);
  34355. } else if (elementType === BSON_DATA_INT) {
  34356. value = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34357. } else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
  34358. value = new _Double(buffer.readDoubleLE(index));
  34359. index = index + 8;
  34360. } else if (elementType === BSON_DATA_NUMBER) {
  34361. value = buffer.readDoubleLE(index);
  34362. index = index + 8;
  34363. } else if (elementType === BSON_DATA_DATE) {
  34364. var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34365. var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34366. value = new Date(new _Long(lowBits, highBits).toNumber());
  34367. } else if (elementType === BSON_DATA_BOOLEAN) {
  34368. if (buffer[index] !== 0 && buffer[index] !== 1) throw new BSONError('illegal boolean type value');
  34369. value = buffer[index++] === 1;
  34370. } else if (elementType === BSON_DATA_OBJECT) {
  34371. var _index = index;
  34372. var objectSize = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
  34373. if (objectSize <= 0 || objectSize > buffer.length - index) throw new BSONError('bad embedded document length in bson'); // We have a raw value
  34374. if (raw) {
  34375. value = buffer.slice(index, index + objectSize);
  34376. } else {
  34377. var objectOptions = options;
  34378. if (!globalUTFValidation) {
  34379. objectOptions = _assign(_assign({}, options), {
  34380. validation: {
  34381. utf8: shouldValidateKey
  34382. }
  34383. });
  34384. }
  34385. value = deserializeObject(buffer, _index, objectOptions, false);
  34386. }
  34387. index = index + objectSize;
  34388. } else if (elementType === BSON_DATA_ARRAY) {
  34389. var _index = index;
  34390. var objectSize = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24;
  34391. var arrayOptions = options; // Stop index
  34392. var stopIndex = index + objectSize; // All elements of array to be returned as raw bson
  34393. if (fieldsAsRaw && fieldsAsRaw[name]) {
  34394. arrayOptions = {};
  34395. for (var n in options) {
  34396. arrayOptions[n] = options[n];
  34397. }
  34398. arrayOptions['raw'] = true;
  34399. }
  34400. if (!globalUTFValidation) {
  34401. arrayOptions = _assign(_assign({}, arrayOptions), {
  34402. validation: {
  34403. utf8: shouldValidateKey
  34404. }
  34405. });
  34406. }
  34407. value = deserializeObject(buffer, _index, arrayOptions, true);
  34408. index = index + objectSize;
  34409. if (buffer[index - 1] !== 0) throw new BSONError('invalid array terminator byte');
  34410. if (index !== stopIndex) throw new BSONError('corrupted array bson');
  34411. } else if (elementType === BSON_DATA_UNDEFINED) {
  34412. value = undefined;
  34413. } else if (elementType === BSON_DATA_NULL) {
  34414. value = null;
  34415. } else if (elementType === BSON_DATA_LONG) {
  34416. // Unpack the low and high bits
  34417. var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34418. var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34419. var _long = new _Long(lowBits, highBits); // Promote the long if possible
  34420. if (promoteLongs && promoteValues === true) {
  34421. value = _long.lessThanOrEqual(JS_INT_MAX_LONG) && _long.greaterThanOrEqual(JS_INT_MIN_LONG) ? _long.toNumber() : _long;
  34422. } else {
  34423. value = _long;
  34424. }
  34425. } else if (elementType === BSON_DATA_DECIMAL128) {
  34426. // Buffer to contain the decimal bytes
  34427. var bytes = buffer_1.alloc(16); // Copy the next 16 bytes into the bytes buffer
  34428. buffer.copy(bytes, 0, index, index + 16); // Update index
  34429. index = index + 16; // Assign the new Decimal128 value
  34430. var decimal128 = new _Decimal(bytes); // If we have an alternative mapper use that
  34431. if ('toObject' in decimal128 && typeof decimal128.toObject === 'function') {
  34432. value = decimal128.toObject();
  34433. } else {
  34434. value = decimal128;
  34435. }
  34436. } else if (elementType === BSON_DATA_BINARY) {
  34437. var binarySize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34438. var totalBinarySize = binarySize;
  34439. var subType = buffer[index++]; // Did we have a negative binary size, throw
  34440. if (binarySize < 0) throw new BSONError('Negative binary type element size found'); // Is the length longer than the document
  34441. if (binarySize > buffer.byteLength) throw new BSONError('Binary type size larger than document size'); // Decode as raw Buffer object if options specifies it
  34442. if (buffer['slice'] != null) {
  34443. // If we have subtype 2 skip the 4 bytes for the size
  34444. if (subType === _Binary.SUBTYPE_BYTE_ARRAY) {
  34445. binarySize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34446. if (binarySize < 0) throw new BSONError('Negative binary type element size found for subtype 0x02');
  34447. if (binarySize > totalBinarySize - 4) throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
  34448. if (binarySize < totalBinarySize - 4) throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
  34449. }
  34450. if (promoteBuffers && promoteValues) {
  34451. value = buffer.slice(index, index + binarySize);
  34452. } else {
  34453. value = new _Binary(buffer.slice(index, index + binarySize), subType);
  34454. }
  34455. } else {
  34456. var _buffer = buffer_1.alloc(binarySize); // If we have subtype 2 skip the 4 bytes for the size
  34457. if (subType === _Binary.SUBTYPE_BYTE_ARRAY) {
  34458. binarySize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34459. if (binarySize < 0) throw new BSONError('Negative binary type element size found for subtype 0x02');
  34460. if (binarySize > totalBinarySize - 4) throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
  34461. if (binarySize < totalBinarySize - 4) throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
  34462. } // Copy the data
  34463. for (i = 0; i < binarySize; i++) {
  34464. _buffer[i] = buffer[index + i];
  34465. }
  34466. if (promoteBuffers && promoteValues) {
  34467. value = _buffer;
  34468. } else {
  34469. value = new _Binary(_buffer, subType);
  34470. }
  34471. } // Update the index
  34472. index = index + binarySize;
  34473. } else if (elementType === BSON_DATA_REGEXP && bsonRegExp === false) {
  34474. // Get the start search index
  34475. i = index; // Locate the end of the c string
  34476. while (buffer[i] !== 0x00 && i < buffer.length) {
  34477. i++;
  34478. } // If are at the end of the buffer there is a problem with the document
  34479. if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString'); // Return the C string
  34480. var source = buffer.toString('utf8', index, i); // Create the regexp
  34481. index = i + 1; // Get the start search index
  34482. i = index; // Locate the end of the c string
  34483. while (buffer[i] !== 0x00 && i < buffer.length) {
  34484. i++;
  34485. } // If are at the end of the buffer there is a problem with the document
  34486. if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString'); // Return the C string
  34487. var regExpOptions = buffer.toString('utf8', index, i);
  34488. index = i + 1; // For each option add the corresponding one for javascript
  34489. var optionsArray = new Array(regExpOptions.length); // Parse options
  34490. for (i = 0; i < regExpOptions.length; i++) {
  34491. switch (regExpOptions[i]) {
  34492. case 'm':
  34493. optionsArray[i] = 'm';
  34494. break;
  34495. case 's':
  34496. optionsArray[i] = 'g';
  34497. break;
  34498. case 'i':
  34499. optionsArray[i] = 'i';
  34500. break;
  34501. }
  34502. }
  34503. value = new RegExp(source, optionsArray.join(''));
  34504. } else if (elementType === BSON_DATA_REGEXP && bsonRegExp === true) {
  34505. // Get the start search index
  34506. i = index; // Locate the end of the c string
  34507. while (buffer[i] !== 0x00 && i < buffer.length) {
  34508. i++;
  34509. } // If are at the end of the buffer there is a problem with the document
  34510. if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString'); // Return the C string
  34511. var source = buffer.toString('utf8', index, i);
  34512. index = i + 1; // Get the start search index
  34513. i = index; // Locate the end of the c string
  34514. while (buffer[i] !== 0x00 && i < buffer.length) {
  34515. i++;
  34516. } // If are at the end of the buffer there is a problem with the document
  34517. if (i >= buffer.length) throw new BSONError('Bad BSON Document: illegal CString'); // Return the C string
  34518. var regExpOptions = buffer.toString('utf8', index, i);
  34519. index = i + 1; // Set the object
  34520. value = new _BSONRegExp(source, regExpOptions);
  34521. } else if (elementType === BSON_DATA_SYMBOL) {
  34522. var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34523. if (stringSize <= 0 || stringSize > buffer.length - index || buffer[index + stringSize - 1] !== 0) {
  34524. throw new BSONError('bad string length in bson');
  34525. }
  34526. var symbol = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey);
  34527. value = promoteValues ? symbol : new BSONSymbol(symbol);
  34528. index = index + stringSize;
  34529. } else if (elementType === BSON_DATA_TIMESTAMP) {
  34530. var lowBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34531. var highBits = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34532. value = new _Timestamp(lowBits, highBits);
  34533. } else if (elementType === BSON_DATA_MIN_KEY) {
  34534. value = new _MinKey();
  34535. } else if (elementType === BSON_DATA_MAX_KEY) {
  34536. value = new _MaxKey();
  34537. } else if (elementType === BSON_DATA_CODE) {
  34538. var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24;
  34539. if (stringSize <= 0 || stringSize > buffer.length - index || buffer[index + stringSize - 1] !== 0) {
  34540. throw new BSONError('bad string length in bson');
  34541. }
  34542. var functionString = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey); // If we are evaluating the functions
  34543. if (evalFunctions) {
  34544. // If we have cache enabled let's look for the md5 of the function in the cache
  34545. if (cacheFunctions) {
  34546. // Got to do this to avoid V8 deoptimizing the call due to finding eval
  34547. value = isolateEval(functionString, functionCache, object);
  34548. } else {
  34549. value = isolateEval(functionString);
  34550. }
  34551. } else {
  34552. value = new _Code(functionString);
  34553. } // Update parse index position
  34554. index = index + stringSize;
  34555. } else if (elementType === BSON_DATA_CODE_W_SCOPE) {
  34556. var totalSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Element cannot be shorter than totalSize + stringSize + documentSize + terminator
  34557. if (totalSize < 4 + 4 + 4 + 1) {
  34558. throw new BSONError('code_w_scope total size shorter minimum expected length');
  34559. } // Get the code string size
  34560. var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Check if we have a valid string
  34561. if (stringSize <= 0 || stringSize > buffer.length - index || buffer[index + stringSize - 1] !== 0) {
  34562. throw new BSONError('bad string length in bson');
  34563. } // Javascript function
  34564. var functionString = getValidatedString(buffer, index, index + stringSize - 1, shouldValidateKey); // Update parse index position
  34565. index = index + stringSize; // Parse the element
  34566. var _index = index; // Decode the size of the object document
  34567. var objectSize = buffer[index] | buffer[index + 1] << 8 | buffer[index + 2] << 16 | buffer[index + 3] << 24; // Decode the scope object
  34568. var scopeObject = deserializeObject(buffer, _index, options, false); // Adjust the index
  34569. index = index + objectSize; // Check if field length is too short
  34570. if (totalSize < 4 + 4 + objectSize + stringSize) {
  34571. throw new BSONError('code_w_scope total size is too short, truncating scope');
  34572. } // Check if totalSize field is too long
  34573. if (totalSize > 4 + 4 + objectSize + stringSize) {
  34574. throw new BSONError('code_w_scope total size is too long, clips outer document');
  34575. } // If we are evaluating the functions
  34576. if (evalFunctions) {
  34577. // If we have cache enabled let's look for the md5 of the function in the cache
  34578. if (cacheFunctions) {
  34579. // Got to do this to avoid V8 deoptimizing the call due to finding eval
  34580. value = isolateEval(functionString, functionCache, object);
  34581. } else {
  34582. value = isolateEval(functionString);
  34583. }
  34584. value.scope = scopeObject;
  34585. } else {
  34586. value = new _Code(functionString, scopeObject);
  34587. }
  34588. } else if (elementType === BSON_DATA_DBPOINTER) {
  34589. // Get the code string size
  34590. var stringSize = buffer[index++] | buffer[index++] << 8 | buffer[index++] << 16 | buffer[index++] << 24; // Check if we have a valid string
  34591. if (stringSize <= 0 || stringSize > buffer.length - index || buffer[index + stringSize - 1] !== 0) throw new BSONError('bad string length in bson'); // Namespace
  34592. if (validation != null && validation.utf8) {
  34593. if (!validateUtf8(buffer, index, index + stringSize - 1)) {
  34594. throw new BSONError('Invalid UTF-8 string in BSON document');
  34595. }
  34596. }
  34597. var namespace = buffer.toString('utf8', index, index + stringSize - 1); // Update parse index position
  34598. index = index + stringSize; // Read the oid
  34599. var oidBuffer = buffer_1.alloc(12);
  34600. buffer.copy(oidBuffer, 0, index, index + 12);
  34601. var oid = new _ObjectId(oidBuffer); // Update the index
  34602. index = index + 12; // Upgrade to DBRef type
  34603. value = new _DBRef(namespace, oid);
  34604. } else {
  34605. throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
  34606. }
  34607. if (name === '__proto__') {
  34608. Object.defineProperty(object, name, {
  34609. value: value,
  34610. writable: true,
  34611. enumerable: true,
  34612. configurable: true
  34613. });
  34614. } else {
  34615. object[name] = value;
  34616. }
  34617. } // Check if the deserialization was against a valid array/object
  34618. if (size !== index - startIndex) {
  34619. if (isArray) throw new BSONError('corrupt array bson');
  34620. throw new BSONError('corrupt object bson');
  34621. } // if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef
  34622. if (!isPossibleDBRef) return object;
  34623. if (isDBRefLike(object)) {
  34624. var copy = Object.assign({}, object);
  34625. delete copy.$ref;
  34626. delete copy.$id;
  34627. delete copy.$db;
  34628. return new _DBRef(object.$ref, object.$id, object.$db, copy);
  34629. }
  34630. return object;
  34631. }
  34632. /**
  34633. * Ensure eval is isolated, store the result in functionCache.
  34634. *
  34635. * @internal
  34636. */
  34637. function isolateEval(functionString, functionCache, object) {
  34638. if (!functionCache) return new Function(functionString); // Check for cache hit, eval if missing and return cached function
  34639. if (functionCache[functionString] == null) {
  34640. functionCache[functionString] = new Function(functionString);
  34641. } // Set the object
  34642. return functionCache[functionString].bind(object);
  34643. }
  34644. function getValidatedString(buffer, start, end, shouldValidateUtf8) {
  34645. var value = buffer.toString('utf8', start, end); // if utf8 validation is on, do the check
  34646. if (shouldValidateUtf8) {
  34647. for (var i = 0; i < value.length; i++) {
  34648. if (value.charCodeAt(i) === 0xfffd) {
  34649. if (!validateUtf8(buffer, start, end)) {
  34650. throw new BSONError('Invalid UTF-8 string in BSON document');
  34651. }
  34652. break;
  34653. }
  34654. }
  34655. }
  34656. return value;
  34657. } // Copyright (c) 2008, Fair Oaks Labs, Inc.
  34658. function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
  34659. var e;
  34660. var m;
  34661. var c;
  34662. var bBE = endian === 'big';
  34663. var eLen = nBytes * 8 - mLen - 1;
  34664. var eMax = (1 << eLen) - 1;
  34665. var eBias = eMax >> 1;
  34666. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  34667. var i = bBE ? nBytes - 1 : 0;
  34668. var d = bBE ? -1 : 1;
  34669. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  34670. value = Math.abs(value);
  34671. if (isNaN(value) || value === Infinity) {
  34672. m = isNaN(value) ? 1 : 0;
  34673. e = eMax;
  34674. } else {
  34675. e = Math.floor(Math.log(value) / Math.LN2);
  34676. if (value * (c = Math.pow(2, -e)) < 1) {
  34677. e--;
  34678. c *= 2;
  34679. }
  34680. if (e + eBias >= 1) {
  34681. value += rt / c;
  34682. } else {
  34683. value += rt * Math.pow(2, 1 - eBias);
  34684. }
  34685. if (value * c >= 2) {
  34686. e++;
  34687. c /= 2;
  34688. }
  34689. if (e + eBias >= eMax) {
  34690. m = 0;
  34691. e = eMax;
  34692. } else if (e + eBias >= 1) {
  34693. m = (value * c - 1) * Math.pow(2, mLen);
  34694. e = e + eBias;
  34695. } else {
  34696. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  34697. e = 0;
  34698. }
  34699. }
  34700. if (isNaN(value)) m = 0;
  34701. while (mLen >= 8) {
  34702. buffer[offset + i] = m & 0xff;
  34703. i += d;
  34704. m /= 256;
  34705. mLen -= 8;
  34706. }
  34707. e = e << mLen | m;
  34708. if (isNaN(value)) e += 8;
  34709. eLen += mLen;
  34710. while (eLen > 0) {
  34711. buffer[offset + i] = e & 0xff;
  34712. i += d;
  34713. e /= 256;
  34714. eLen -= 8;
  34715. }
  34716. buffer[offset + i - d] |= s * 128;
  34717. }
  34718. var regexp = /\x00/; // eslint-disable-line no-control-regex
  34719. var ignoreKeys = new Set(['$db', '$ref', '$id', '$clusterTime']);
  34720. /*
  34721. * isArray indicates if we are writing to a BSON array (type 0x04)
  34722. * which forces the "key" which really an array index as a string to be written as ascii
  34723. * This will catch any errors in index as a string generation
  34724. */
  34725. function serializeString(buffer, key, value, index, isArray) {
  34726. // Encode String type
  34727. buffer[index++] = BSON_DATA_STRING; // Number of written bytes
  34728. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34729. index = index + numberOfWrittenBytes + 1;
  34730. buffer[index - 1] = 0; // Write the string
  34731. var size = buffer.write(value, index + 4, undefined, 'utf8'); // Write the size of the string to buffer
  34732. buffer[index + 3] = size + 1 >> 24 & 0xff;
  34733. buffer[index + 2] = size + 1 >> 16 & 0xff;
  34734. buffer[index + 1] = size + 1 >> 8 & 0xff;
  34735. buffer[index] = size + 1 & 0xff; // Update index
  34736. index = index + 4 + size; // Write zero
  34737. buffer[index++] = 0;
  34738. return index;
  34739. }
  34740. function serializeNumber(buffer, key, value, index, isArray) {
  34741. // We have an integer value
  34742. // TODO(NODE-2529): Add support for big int
  34743. if (Number.isInteger(value) && value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
  34744. // If the value fits in 32 bits encode as int32
  34745. // Set int type 32 bits or less
  34746. buffer[index++] = BSON_DATA_INT; // Number of written bytes
  34747. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34748. index = index + numberOfWrittenBytes;
  34749. buffer[index++] = 0; // Write the int value
  34750. buffer[index++] = value & 0xff;
  34751. buffer[index++] = value >> 8 & 0xff;
  34752. buffer[index++] = value >> 16 & 0xff;
  34753. buffer[index++] = value >> 24 & 0xff;
  34754. } else {
  34755. // Encode as double
  34756. buffer[index++] = BSON_DATA_NUMBER; // Number of written bytes
  34757. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34758. index = index + numberOfWrittenBytes;
  34759. buffer[index++] = 0; // Write float
  34760. writeIEEE754(buffer, value, index, 'little', 52, 8); // Adjust index
  34761. index = index + 8;
  34762. }
  34763. return index;
  34764. }
  34765. function serializeNull(buffer, key, _, index, isArray) {
  34766. // Set long type
  34767. buffer[index++] = BSON_DATA_NULL; // Number of written bytes
  34768. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34769. index = index + numberOfWrittenBytes;
  34770. buffer[index++] = 0;
  34771. return index;
  34772. }
  34773. function serializeBoolean(buffer, key, value, index, isArray) {
  34774. // Write the type
  34775. buffer[index++] = BSON_DATA_BOOLEAN; // Number of written bytes
  34776. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34777. index = index + numberOfWrittenBytes;
  34778. buffer[index++] = 0; // Encode the boolean value
  34779. buffer[index++] = value ? 1 : 0;
  34780. return index;
  34781. }
  34782. function serializeDate(buffer, key, value, index, isArray) {
  34783. // Write the type
  34784. buffer[index++] = BSON_DATA_DATE; // Number of written bytes
  34785. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34786. index = index + numberOfWrittenBytes;
  34787. buffer[index++] = 0; // Write the date
  34788. var dateInMilis = _Long.fromNumber(value.getTime());
  34789. var lowBits = dateInMilis.getLowBits();
  34790. var highBits = dateInMilis.getHighBits(); // Encode low bits
  34791. buffer[index++] = lowBits & 0xff;
  34792. buffer[index++] = lowBits >> 8 & 0xff;
  34793. buffer[index++] = lowBits >> 16 & 0xff;
  34794. buffer[index++] = lowBits >> 24 & 0xff; // Encode high bits
  34795. buffer[index++] = highBits & 0xff;
  34796. buffer[index++] = highBits >> 8 & 0xff;
  34797. buffer[index++] = highBits >> 16 & 0xff;
  34798. buffer[index++] = highBits >> 24 & 0xff;
  34799. return index;
  34800. }
  34801. function serializeRegExp(buffer, key, value, index, isArray) {
  34802. // Write the type
  34803. buffer[index++] = BSON_DATA_REGEXP; // Number of written bytes
  34804. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34805. index = index + numberOfWrittenBytes;
  34806. buffer[index++] = 0;
  34807. if (value.source && value.source.match(regexp) != null) {
  34808. throw Error('value ' + value.source + ' must not contain null bytes');
  34809. } // Adjust the index
  34810. index = index + buffer.write(value.source, index, undefined, 'utf8'); // Write zero
  34811. buffer[index++] = 0x00; // Write the parameters
  34812. if (value.ignoreCase) buffer[index++] = 0x69; // i
  34813. if (value.global) buffer[index++] = 0x73; // s
  34814. if (value.multiline) buffer[index++] = 0x6d; // m
  34815. // Add ending zero
  34816. buffer[index++] = 0x00;
  34817. return index;
  34818. }
  34819. function serializeBSONRegExp(buffer, key, value, index, isArray) {
  34820. // Write the type
  34821. buffer[index++] = BSON_DATA_REGEXP; // Number of written bytes
  34822. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34823. index = index + numberOfWrittenBytes;
  34824. buffer[index++] = 0; // Check the pattern for 0 bytes
  34825. if (value.pattern.match(regexp) != null) {
  34826. // The BSON spec doesn't allow keys with null bytes because keys are
  34827. // null-terminated.
  34828. throw Error('pattern ' + value.pattern + ' must not contain null bytes');
  34829. } // Adjust the index
  34830. index = index + buffer.write(value.pattern, index, undefined, 'utf8'); // Write zero
  34831. buffer[index++] = 0x00; // Write the options
  34832. index = index + buffer.write(value.options.split('').sort().join(''), index, undefined, 'utf8'); // Add ending zero
  34833. buffer[index++] = 0x00;
  34834. return index;
  34835. }
  34836. function serializeMinMax(buffer, key, value, index, isArray) {
  34837. // Write the type of either min or max key
  34838. if (value === null) {
  34839. buffer[index++] = BSON_DATA_NULL;
  34840. } else if (value._bsontype === 'MinKey') {
  34841. buffer[index++] = BSON_DATA_MIN_KEY;
  34842. } else {
  34843. buffer[index++] = BSON_DATA_MAX_KEY;
  34844. } // Number of written bytes
  34845. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34846. index = index + numberOfWrittenBytes;
  34847. buffer[index++] = 0;
  34848. return index;
  34849. }
  34850. function serializeObjectId(buffer, key, value, index, isArray) {
  34851. // Write the type
  34852. buffer[index++] = BSON_DATA_OID; // Number of written bytes
  34853. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34854. index = index + numberOfWrittenBytes;
  34855. buffer[index++] = 0; // Write the objectId into the shared buffer
  34856. if (typeof value.id === 'string') {
  34857. buffer.write(value.id, index, undefined, 'binary');
  34858. } else if (isUint8Array(value.id)) {
  34859. // Use the standard JS methods here because buffer.copy() is buggy with the
  34860. // browser polyfill
  34861. buffer.set(value.id.subarray(0, 12), index);
  34862. } else {
  34863. throw new BSONTypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
  34864. } // Adjust index
  34865. return index + 12;
  34866. }
  34867. function serializeBuffer(buffer, key, value, index, isArray) {
  34868. // Write the type
  34869. buffer[index++] = BSON_DATA_BINARY; // Number of written bytes
  34870. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34871. index = index + numberOfWrittenBytes;
  34872. buffer[index++] = 0; // Get size of the buffer (current write point)
  34873. var size = value.length; // Write the size of the string to buffer
  34874. buffer[index++] = size & 0xff;
  34875. buffer[index++] = size >> 8 & 0xff;
  34876. buffer[index++] = size >> 16 & 0xff;
  34877. buffer[index++] = size >> 24 & 0xff; // Write the default subtype
  34878. buffer[index++] = BSON_BINARY_SUBTYPE_DEFAULT; // Copy the content form the binary field to the buffer
  34879. buffer.set(ensureBuffer(value), index); // Adjust the index
  34880. index = index + size;
  34881. return index;
  34882. }
  34883. function serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray, path) {
  34884. if (checkKeys === void 0) {
  34885. checkKeys = false;
  34886. }
  34887. if (depth === void 0) {
  34888. depth = 0;
  34889. }
  34890. if (serializeFunctions === void 0) {
  34891. serializeFunctions = false;
  34892. }
  34893. if (ignoreUndefined === void 0) {
  34894. ignoreUndefined = true;
  34895. }
  34896. if (isArray === void 0) {
  34897. isArray = false;
  34898. }
  34899. if (path === void 0) {
  34900. path = [];
  34901. }
  34902. for (var i = 0; i < path.length; i++) {
  34903. if (path[i] === value) throw new BSONError('cyclic dependency detected');
  34904. } // Push value to stack
  34905. path.push(value); // Write the type
  34906. buffer[index++] = Array.isArray(value) ? BSON_DATA_ARRAY : BSON_DATA_OBJECT; // Number of written bytes
  34907. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34908. index = index + numberOfWrittenBytes;
  34909. buffer[index++] = 0;
  34910. var endIndex = serializeInto(buffer, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path); // Pop stack
  34911. path.pop();
  34912. return endIndex;
  34913. }
  34914. function serializeDecimal128(buffer, key, value, index, isArray) {
  34915. buffer[index++] = BSON_DATA_DECIMAL128; // Number of written bytes
  34916. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34917. index = index + numberOfWrittenBytes;
  34918. buffer[index++] = 0; // Write the data from the value
  34919. // Prefer the standard JS methods because their typechecking is not buggy,
  34920. // unlike the `buffer` polyfill's.
  34921. buffer.set(value.bytes.subarray(0, 16), index);
  34922. return index + 16;
  34923. }
  34924. function serializeLong(buffer, key, value, index, isArray) {
  34925. // Write the type
  34926. buffer[index++] = value._bsontype === 'Long' ? BSON_DATA_LONG : BSON_DATA_TIMESTAMP; // Number of written bytes
  34927. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34928. index = index + numberOfWrittenBytes;
  34929. buffer[index++] = 0; // Write the date
  34930. var lowBits = value.getLowBits();
  34931. var highBits = value.getHighBits(); // Encode low bits
  34932. buffer[index++] = lowBits & 0xff;
  34933. buffer[index++] = lowBits >> 8 & 0xff;
  34934. buffer[index++] = lowBits >> 16 & 0xff;
  34935. buffer[index++] = lowBits >> 24 & 0xff; // Encode high bits
  34936. buffer[index++] = highBits & 0xff;
  34937. buffer[index++] = highBits >> 8 & 0xff;
  34938. buffer[index++] = highBits >> 16 & 0xff;
  34939. buffer[index++] = highBits >> 24 & 0xff;
  34940. return index;
  34941. }
  34942. function serializeInt32(buffer, key, value, index, isArray) {
  34943. value = value.valueOf(); // Set int type 32 bits or less
  34944. buffer[index++] = BSON_DATA_INT; // Number of written bytes
  34945. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34946. index = index + numberOfWrittenBytes;
  34947. buffer[index++] = 0; // Write the int value
  34948. buffer[index++] = value & 0xff;
  34949. buffer[index++] = value >> 8 & 0xff;
  34950. buffer[index++] = value >> 16 & 0xff;
  34951. buffer[index++] = value >> 24 & 0xff;
  34952. return index;
  34953. }
  34954. function serializeDouble(buffer, key, value, index, isArray) {
  34955. // Encode as double
  34956. buffer[index++] = BSON_DATA_NUMBER; // Number of written bytes
  34957. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34958. index = index + numberOfWrittenBytes;
  34959. buffer[index++] = 0; // Write float
  34960. writeIEEE754(buffer, value.value, index, 'little', 52, 8); // Adjust index
  34961. index = index + 8;
  34962. return index;
  34963. }
  34964. function serializeFunction(buffer, key, value, index, _checkKeys, _depth, isArray) {
  34965. buffer[index++] = BSON_DATA_CODE; // Number of written bytes
  34966. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34967. index = index + numberOfWrittenBytes;
  34968. buffer[index++] = 0; // Function string
  34969. var functionString = normalizedFunctionString(value); // Write the string
  34970. var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; // Write the size of the string to buffer
  34971. buffer[index] = size & 0xff;
  34972. buffer[index + 1] = size >> 8 & 0xff;
  34973. buffer[index + 2] = size >> 16 & 0xff;
  34974. buffer[index + 3] = size >> 24 & 0xff; // Update index
  34975. index = index + 4 + size - 1; // Write zero
  34976. buffer[index++] = 0;
  34977. return index;
  34978. }
  34979. function serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, isArray) {
  34980. if (checkKeys === void 0) {
  34981. checkKeys = false;
  34982. }
  34983. if (depth === void 0) {
  34984. depth = 0;
  34985. }
  34986. if (serializeFunctions === void 0) {
  34987. serializeFunctions = false;
  34988. }
  34989. if (ignoreUndefined === void 0) {
  34990. ignoreUndefined = true;
  34991. }
  34992. if (isArray === void 0) {
  34993. isArray = false;
  34994. }
  34995. if (value.scope && _typeof(value.scope) === 'object') {
  34996. // Write the type
  34997. buffer[index++] = BSON_DATA_CODE_W_SCOPE; // Number of written bytes
  34998. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  34999. index = index + numberOfWrittenBytes;
  35000. buffer[index++] = 0; // Starting index
  35001. var startIndex = index; // Serialize the function
  35002. // Get the function string
  35003. var functionString = typeof value.code === 'string' ? value.code : value.code.toString(); // Index adjustment
  35004. index = index + 4; // Write string into buffer
  35005. var codeSize = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; // Write the size of the string to buffer
  35006. buffer[index] = codeSize & 0xff;
  35007. buffer[index + 1] = codeSize >> 8 & 0xff;
  35008. buffer[index + 2] = codeSize >> 16 & 0xff;
  35009. buffer[index + 3] = codeSize >> 24 & 0xff; // Write end 0
  35010. buffer[index + 4 + codeSize - 1] = 0; // Write the
  35011. index = index + codeSize + 4; //
  35012. // Serialize the scope value
  35013. var endIndex = serializeInto(buffer, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined);
  35014. index = endIndex - 1; // Writ the total
  35015. var totalSize = endIndex - startIndex; // Write the total size of the object
  35016. buffer[startIndex++] = totalSize & 0xff;
  35017. buffer[startIndex++] = totalSize >> 8 & 0xff;
  35018. buffer[startIndex++] = totalSize >> 16 & 0xff;
  35019. buffer[startIndex++] = totalSize >> 24 & 0xff; // Write trailing zero
  35020. buffer[index++] = 0;
  35021. } else {
  35022. buffer[index++] = BSON_DATA_CODE; // Number of written bytes
  35023. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  35024. index = index + numberOfWrittenBytes;
  35025. buffer[index++] = 0; // Function string
  35026. var functionString = value.code.toString(); // Write the string
  35027. var size = buffer.write(functionString, index + 4, undefined, 'utf8') + 1; // Write the size of the string to buffer
  35028. buffer[index] = size & 0xff;
  35029. buffer[index + 1] = size >> 8 & 0xff;
  35030. buffer[index + 2] = size >> 16 & 0xff;
  35031. buffer[index + 3] = size >> 24 & 0xff; // Update index
  35032. index = index + 4 + size - 1; // Write zero
  35033. buffer[index++] = 0;
  35034. }
  35035. return index;
  35036. }
  35037. function serializeBinary(buffer, key, value, index, isArray) {
  35038. // Write the type
  35039. buffer[index++] = BSON_DATA_BINARY; // Number of written bytes
  35040. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  35041. index = index + numberOfWrittenBytes;
  35042. buffer[index++] = 0; // Extract the buffer
  35043. var data = value.value(true); // Calculate size
  35044. var size = value.position; // Add the deprecated 02 type 4 bytes of size to total
  35045. if (value.sub_type === _Binary.SUBTYPE_BYTE_ARRAY) size = size + 4; // Write the size of the string to buffer
  35046. buffer[index++] = size & 0xff;
  35047. buffer[index++] = size >> 8 & 0xff;
  35048. buffer[index++] = size >> 16 & 0xff;
  35049. buffer[index++] = size >> 24 & 0xff; // Write the subtype to the buffer
  35050. buffer[index++] = value.sub_type; // If we have binary type 2 the 4 first bytes are the size
  35051. if (value.sub_type === _Binary.SUBTYPE_BYTE_ARRAY) {
  35052. size = size - 4;
  35053. buffer[index++] = size & 0xff;
  35054. buffer[index++] = size >> 8 & 0xff;
  35055. buffer[index++] = size >> 16 & 0xff;
  35056. buffer[index++] = size >> 24 & 0xff;
  35057. } // Write the data to the object
  35058. buffer.set(data, index); // Adjust the index
  35059. index = index + value.position;
  35060. return index;
  35061. }
  35062. function serializeSymbol(buffer, key, value, index, isArray) {
  35063. // Write the type
  35064. buffer[index++] = BSON_DATA_SYMBOL; // Number of written bytes
  35065. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  35066. index = index + numberOfWrittenBytes;
  35067. buffer[index++] = 0; // Write the string
  35068. var size = buffer.write(value.value, index + 4, undefined, 'utf8') + 1; // Write the size of the string to buffer
  35069. buffer[index] = size & 0xff;
  35070. buffer[index + 1] = size >> 8 & 0xff;
  35071. buffer[index + 2] = size >> 16 & 0xff;
  35072. buffer[index + 3] = size >> 24 & 0xff; // Update index
  35073. index = index + 4 + size - 1; // Write zero
  35074. buffer[index++] = 0x00;
  35075. return index;
  35076. }
  35077. function serializeDBRef(buffer, key, value, index, depth, serializeFunctions, isArray) {
  35078. // Write the type
  35079. buffer[index++] = BSON_DATA_OBJECT; // Number of written bytes
  35080. var numberOfWrittenBytes = !isArray ? buffer.write(key, index, undefined, 'utf8') : buffer.write(key, index, undefined, 'ascii'); // Encode the name
  35081. index = index + numberOfWrittenBytes;
  35082. buffer[index++] = 0;
  35083. var startIndex = index;
  35084. var output = {
  35085. $ref: value.collection || value.namespace,
  35086. $id: value.oid
  35087. };
  35088. if (value.db != null) {
  35089. output.$db = value.db;
  35090. }
  35091. output = Object.assign(output, value.fields);
  35092. var endIndex = serializeInto(buffer, output, false, index, depth + 1, serializeFunctions); // Calculate object size
  35093. var size = endIndex - startIndex; // Write the size
  35094. buffer[startIndex++] = size & 0xff;
  35095. buffer[startIndex++] = size >> 8 & 0xff;
  35096. buffer[startIndex++] = size >> 16 & 0xff;
  35097. buffer[startIndex++] = size >> 24 & 0xff; // Set index
  35098. return endIndex;
  35099. }
  35100. function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializeFunctions, ignoreUndefined, path) {
  35101. if (checkKeys === void 0) {
  35102. checkKeys = false;
  35103. }
  35104. if (startingIndex === void 0) {
  35105. startingIndex = 0;
  35106. }
  35107. if (depth === void 0) {
  35108. depth = 0;
  35109. }
  35110. if (serializeFunctions === void 0) {
  35111. serializeFunctions = false;
  35112. }
  35113. if (ignoreUndefined === void 0) {
  35114. ignoreUndefined = true;
  35115. }
  35116. if (path === void 0) {
  35117. path = [];
  35118. }
  35119. startingIndex = startingIndex || 0;
  35120. path = path || []; // Push the object to the path
  35121. path.push(object); // Start place to serialize into
  35122. var index = startingIndex + 4; // Special case isArray
  35123. if (Array.isArray(object)) {
  35124. // Get object keys
  35125. for (var i = 0; i < object.length; i++) {
  35126. var key = '' + i;
  35127. var value = object[i]; // Is there an override value
  35128. if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
  35129. value = value.toBSON();
  35130. }
  35131. if (typeof value === 'string') {
  35132. index = serializeString(buffer, key, value, index, true);
  35133. } else if (typeof value === 'number') {
  35134. index = serializeNumber(buffer, key, value, index, true);
  35135. } else if (typeof value === 'bigint') {
  35136. throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
  35137. } else if (typeof value === 'boolean') {
  35138. index = serializeBoolean(buffer, key, value, index, true);
  35139. } else if (value instanceof Date || isDate(value)) {
  35140. index = serializeDate(buffer, key, value, index, true);
  35141. } else if (value === undefined) {
  35142. index = serializeNull(buffer, key, value, index, true);
  35143. } else if (value === null) {
  35144. index = serializeNull(buffer, key, value, index, true);
  35145. } else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
  35146. index = serializeObjectId(buffer, key, value, index, true);
  35147. } else if (isUint8Array(value)) {
  35148. index = serializeBuffer(buffer, key, value, index, true);
  35149. } else if (value instanceof RegExp || isRegExp(value)) {
  35150. index = serializeRegExp(buffer, key, value, index, true);
  35151. } else if (_typeof(value) === 'object' && value['_bsontype'] == null) {
  35152. index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true, path);
  35153. } else if (_typeof(value) === 'object' && isBSONType(value) && value._bsontype === 'Decimal128') {
  35154. index = serializeDecimal128(buffer, key, value, index, true);
  35155. } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') {
  35156. index = serializeLong(buffer, key, value, index, true);
  35157. } else if (value['_bsontype'] === 'Double') {
  35158. index = serializeDouble(buffer, key, value, index, true);
  35159. } else if (typeof value === 'function' && serializeFunctions) {
  35160. index = serializeFunction(buffer, key, value, index, checkKeys, depth, true);
  35161. } else if (value['_bsontype'] === 'Code') {
  35162. index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, true);
  35163. } else if (value['_bsontype'] === 'Binary') {
  35164. index = serializeBinary(buffer, key, value, index, true);
  35165. } else if (value['_bsontype'] === 'Symbol') {
  35166. index = serializeSymbol(buffer, key, value, index, true);
  35167. } else if (value['_bsontype'] === 'DBRef') {
  35168. index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, true);
  35169. } else if (value['_bsontype'] === 'BSONRegExp') {
  35170. index = serializeBSONRegExp(buffer, key, value, index, true);
  35171. } else if (value['_bsontype'] === 'Int32') {
  35172. index = serializeInt32(buffer, key, value, index, true);
  35173. } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  35174. index = serializeMinMax(buffer, key, value, index, true);
  35175. } else if (typeof value['_bsontype'] !== 'undefined') {
  35176. throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
  35177. }
  35178. }
  35179. } else if (object instanceof bsonMap || isMap(object)) {
  35180. var iterator = object.entries();
  35181. var done = false;
  35182. while (!done) {
  35183. // Unpack the next entry
  35184. var entry = iterator.next();
  35185. done = !!entry.done; // Are we done, then skip and terminate
  35186. if (done) continue; // Get the entry values
  35187. var key = entry.value[0];
  35188. var value = entry.value[1]; // Check the type of the value
  35189. var type = _typeof(value); // Check the key and throw error if it's illegal
  35190. if (typeof key === 'string' && !ignoreKeys.has(key)) {
  35191. if (key.match(regexp) != null) {
  35192. // The BSON spec doesn't allow keys with null bytes because keys are
  35193. // null-terminated.
  35194. throw Error('key ' + key + ' must not contain null bytes');
  35195. }
  35196. if (checkKeys) {
  35197. if ('$' === key[0]) {
  35198. throw Error('key ' + key + " must not start with '$'");
  35199. } else if (~key.indexOf('.')) {
  35200. throw Error('key ' + key + " must not contain '.'");
  35201. }
  35202. }
  35203. }
  35204. if (type === 'string') {
  35205. index = serializeString(buffer, key, value, index);
  35206. } else if (type === 'number') {
  35207. index = serializeNumber(buffer, key, value, index);
  35208. } else if (type === 'bigint' || isBigInt64Array(value) || isBigUInt64Array(value)) {
  35209. throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
  35210. } else if (type === 'boolean') {
  35211. index = serializeBoolean(buffer, key, value, index);
  35212. } else if (value instanceof Date || isDate(value)) {
  35213. index = serializeDate(buffer, key, value, index);
  35214. } else if (value === null || value === undefined && ignoreUndefined === false) {
  35215. index = serializeNull(buffer, key, value, index);
  35216. } else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
  35217. index = serializeObjectId(buffer, key, value, index);
  35218. } else if (isUint8Array(value)) {
  35219. index = serializeBuffer(buffer, key, value, index);
  35220. } else if (value instanceof RegExp || isRegExp(value)) {
  35221. index = serializeRegExp(buffer, key, value, index);
  35222. } else if (type === 'object' && value['_bsontype'] == null) {
  35223. index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, false, path);
  35224. } else if (type === 'object' && value['_bsontype'] === 'Decimal128') {
  35225. index = serializeDecimal128(buffer, key, value, index);
  35226. } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') {
  35227. index = serializeLong(buffer, key, value, index);
  35228. } else if (value['_bsontype'] === 'Double') {
  35229. index = serializeDouble(buffer, key, value, index);
  35230. } else if (value['_bsontype'] === 'Code') {
  35231. index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined);
  35232. } else if (typeof value === 'function' && serializeFunctions) {
  35233. index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions);
  35234. } else if (value['_bsontype'] === 'Binary') {
  35235. index = serializeBinary(buffer, key, value, index);
  35236. } else if (value['_bsontype'] === 'Symbol') {
  35237. index = serializeSymbol(buffer, key, value, index);
  35238. } else if (value['_bsontype'] === 'DBRef') {
  35239. index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions);
  35240. } else if (value['_bsontype'] === 'BSONRegExp') {
  35241. index = serializeBSONRegExp(buffer, key, value, index);
  35242. } else if (value['_bsontype'] === 'Int32') {
  35243. index = serializeInt32(buffer, key, value, index);
  35244. } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  35245. index = serializeMinMax(buffer, key, value, index);
  35246. } else if (typeof value['_bsontype'] !== 'undefined') {
  35247. throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
  35248. }
  35249. }
  35250. } else {
  35251. if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
  35252. // Provided a custom serialization method
  35253. object = object.toBSON();
  35254. if (object != null && _typeof(object) !== 'object') {
  35255. throw new BSONTypeError('toBSON function did not return an object');
  35256. }
  35257. } // Iterate over all the keys
  35258. for (var key in object) {
  35259. var value = object[key]; // Is there an override value
  35260. if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
  35261. value = value.toBSON();
  35262. } // Check the type of the value
  35263. var type = _typeof(value); // Check the key and throw error if it's illegal
  35264. if (typeof key === 'string' && !ignoreKeys.has(key)) {
  35265. if (key.match(regexp) != null) {
  35266. // The BSON spec doesn't allow keys with null bytes because keys are
  35267. // null-terminated.
  35268. throw Error('key ' + key + ' must not contain null bytes');
  35269. }
  35270. if (checkKeys) {
  35271. if ('$' === key[0]) {
  35272. throw Error('key ' + key + " must not start with '$'");
  35273. } else if (~key.indexOf('.')) {
  35274. throw Error('key ' + key + " must not contain '.'");
  35275. }
  35276. }
  35277. }
  35278. if (type === 'string') {
  35279. index = serializeString(buffer, key, value, index);
  35280. } else if (type === 'number') {
  35281. index = serializeNumber(buffer, key, value, index);
  35282. } else if (type === 'bigint') {
  35283. throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
  35284. } else if (type === 'boolean') {
  35285. index = serializeBoolean(buffer, key, value, index);
  35286. } else if (value instanceof Date || isDate(value)) {
  35287. index = serializeDate(buffer, key, value, index);
  35288. } else if (value === undefined) {
  35289. if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
  35290. } else if (value === null) {
  35291. index = serializeNull(buffer, key, value, index);
  35292. } else if (value['_bsontype'] === 'ObjectId' || value['_bsontype'] === 'ObjectID') {
  35293. index = serializeObjectId(buffer, key, value, index);
  35294. } else if (isUint8Array(value)) {
  35295. index = serializeBuffer(buffer, key, value, index);
  35296. } else if (value instanceof RegExp || isRegExp(value)) {
  35297. index = serializeRegExp(buffer, key, value, index);
  35298. } else if (type === 'object' && value['_bsontype'] == null) {
  35299. index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, false, path);
  35300. } else if (type === 'object' && value['_bsontype'] === 'Decimal128') {
  35301. index = serializeDecimal128(buffer, key, value, index);
  35302. } else if (value['_bsontype'] === 'Long' || value['_bsontype'] === 'Timestamp') {
  35303. index = serializeLong(buffer, key, value, index);
  35304. } else if (value['_bsontype'] === 'Double') {
  35305. index = serializeDouble(buffer, key, value, index);
  35306. } else if (value['_bsontype'] === 'Code') {
  35307. index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined);
  35308. } else if (typeof value === 'function' && serializeFunctions) {
  35309. index = serializeFunction(buffer, key, value, index, checkKeys, depth, serializeFunctions);
  35310. } else if (value['_bsontype'] === 'Binary') {
  35311. index = serializeBinary(buffer, key, value, index);
  35312. } else if (value['_bsontype'] === 'Symbol') {
  35313. index = serializeSymbol(buffer, key, value, index);
  35314. } else if (value['_bsontype'] === 'DBRef') {
  35315. index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions);
  35316. } else if (value['_bsontype'] === 'BSONRegExp') {
  35317. index = serializeBSONRegExp(buffer, key, value, index);
  35318. } else if (value['_bsontype'] === 'Int32') {
  35319. index = serializeInt32(buffer, key, value, index);
  35320. } else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
  35321. index = serializeMinMax(buffer, key, value, index);
  35322. } else if (typeof value['_bsontype'] !== 'undefined') {
  35323. throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
  35324. }
  35325. }
  35326. } // Remove the path
  35327. path.pop(); // Final padding byte for object
  35328. buffer[index++] = 0x00; // Final size
  35329. var size = index - startingIndex; // Write the size of the object
  35330. buffer[startingIndex++] = size & 0xff;
  35331. buffer[startingIndex++] = size >> 8 & 0xff;
  35332. buffer[startingIndex++] = size >> 16 & 0xff;
  35333. buffer[startingIndex++] = size >> 24 & 0xff;
  35334. return index;
  35335. }
  35336. /** @internal */
  35337. // Default Max Size
  35338. var MAXSIZE = 1024 * 1024 * 17; // Current Internal Temporary Serialization Buffer
  35339. var buffer = buffer_1.alloc(MAXSIZE);
  35340. /**
  35341. * Sets the size of the internal serialization buffer.
  35342. *
  35343. * @param size - The desired size for the internal serialization buffer
  35344. * @public
  35345. */
  35346. function setInternalBufferSize(size) {
  35347. // Resize the internal serialization buffer if needed
  35348. if (buffer.length < size) {
  35349. buffer = buffer_1.alloc(size);
  35350. }
  35351. }
  35352. /**
  35353. * Serialize a Javascript object.
  35354. *
  35355. * @param object - the Javascript object to serialize.
  35356. * @returns Buffer object containing the serialized object.
  35357. * @public
  35358. */
  35359. function serialize(object, options) {
  35360. if (options === void 0) {
  35361. options = {};
  35362. } // Unpack the options
  35363. var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
  35364. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  35365. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  35366. var minInternalBufferSize = typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE; // Resize the internal serialization buffer if needed
  35367. if (buffer.length < minInternalBufferSize) {
  35368. buffer = buffer_1.alloc(minInternalBufferSize);
  35369. } // Attempt to serialize
  35370. var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, []); // Create the final buffer
  35371. var finishedBuffer = buffer_1.alloc(serializationIndex); // Copy into the finished buffer
  35372. buffer.copy(finishedBuffer, 0, 0, finishedBuffer.length); // Return the buffer
  35373. return finishedBuffer;
  35374. }
  35375. /**
  35376. * Serialize a Javascript object using a predefined Buffer and index into the buffer,
  35377. * useful when pre-allocating the space for serialization.
  35378. *
  35379. * @param object - the Javascript object to serialize.
  35380. * @param finalBuffer - the Buffer you pre-allocated to store the serialized BSON object.
  35381. * @returns the index pointing to the last written byte in the buffer.
  35382. * @public
  35383. */
  35384. function serializeWithBufferAndIndex(object, finalBuffer, options) {
  35385. if (options === void 0) {
  35386. options = {};
  35387. } // Unpack the options
  35388. var checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
  35389. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  35390. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  35391. var startIndex = typeof options.index === 'number' ? options.index : 0; // Attempt to serialize
  35392. var serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined);
  35393. buffer.copy(finalBuffer, startIndex, 0, serializationIndex); // Return the index
  35394. return startIndex + serializationIndex - 1;
  35395. }
  35396. /**
  35397. * Deserialize data as BSON.
  35398. *
  35399. * @param buffer - the buffer containing the serialized set of BSON documents.
  35400. * @returns returns the deserialized Javascript Object.
  35401. * @public
  35402. */
  35403. function deserialize(buffer, options) {
  35404. if (options === void 0) {
  35405. options = {};
  35406. }
  35407. return deserialize$1(buffer instanceof buffer_1 ? buffer : ensureBuffer(buffer), options);
  35408. }
  35409. /**
  35410. * Calculate the bson size for a passed in Javascript object.
  35411. *
  35412. * @param object - the Javascript object to calculate the BSON byte size for
  35413. * @returns size of BSON object in bytes
  35414. * @public
  35415. */
  35416. function calculateObjectSize(object, options) {
  35417. if (options === void 0) {
  35418. options = {};
  35419. }
  35420. options = options || {};
  35421. var serializeFunctions = typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
  35422. var ignoreUndefined = typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
  35423. return calculateObjectSize$1(object, serializeFunctions, ignoreUndefined);
  35424. }
  35425. /**
  35426. * Deserialize stream data as BSON documents.
  35427. *
  35428. * @param data - the buffer containing the serialized set of BSON documents.
  35429. * @param startIndex - the start index in the data Buffer where the deserialization is to start.
  35430. * @param numberOfDocuments - number of documents to deserialize.
  35431. * @param documents - an array where to store the deserialized documents.
  35432. * @param docStartIndex - the index in the documents array from where to start inserting documents.
  35433. * @param options - additional options used for the deserialization.
  35434. * @returns next index in the buffer after deserialization **x** numbers of documents.
  35435. * @public
  35436. */
  35437. function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
  35438. var internalOptions = Object.assign({
  35439. allowObjectSmallerThanBufferSize: true,
  35440. index: 0
  35441. }, options);
  35442. var bufferData = ensureBuffer(data);
  35443. var index = startIndex; // Loop over all documents
  35444. for (var i = 0; i < numberOfDocuments; i++) {
  35445. // Find size of the document
  35446. var size = bufferData[index] | bufferData[index + 1] << 8 | bufferData[index + 2] << 16 | bufferData[index + 3] << 24; // Update options with index
  35447. internalOptions.index = index; // Parse the document at this point
  35448. documents[docStartIndex + i] = deserialize$1(bufferData, internalOptions); // Adjust index by the document size
  35449. index = index + size;
  35450. } // Return object containing end index of parsing and list of documents
  35451. return index;
  35452. }
  35453. /**
  35454. * BSON default export
  35455. * @deprecated Please use named exports
  35456. * @privateRemarks
  35457. * We want to someday deprecate the default export,
  35458. * so none of the new TS types are being exported on the default
  35459. * @public
  35460. */
  35461. var BSON = {
  35462. Binary: _Binary,
  35463. Code: _Code,
  35464. DBRef: _DBRef,
  35465. Decimal128: _Decimal,
  35466. Double: _Double,
  35467. Int32: _Int,
  35468. Long: _Long,
  35469. UUID: UUID,
  35470. Map: bsonMap,
  35471. MaxKey: _MaxKey,
  35472. MinKey: _MinKey,
  35473. ObjectId: _ObjectId,
  35474. ObjectID: _ObjectId,
  35475. BSONRegExp: _BSONRegExp,
  35476. BSONSymbol: BSONSymbol,
  35477. Timestamp: _Timestamp,
  35478. EJSON: EJSON,
  35479. setInternalBufferSize: setInternalBufferSize,
  35480. serialize: serialize,
  35481. serializeWithBufferAndIndex: serializeWithBufferAndIndex,
  35482. deserialize: deserialize,
  35483. calculateObjectSize: calculateObjectSize,
  35484. deserializeStream: deserializeStream,
  35485. BSONError: BSONError,
  35486. BSONTypeError: BSONTypeError
  35487. };
  35488. /* unused harmony default export */ var __WEBPACK_DEFAULT_EXPORT__ = ((/* unused pure expression or super */ null && (BSON)));
  35489. /***/ }),
  35490. /***/ 5176:
  35491. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  35492. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  35493. module.exports = function xor(a, b) {
  35494. var length = Math.min(a.length, b.length);
  35495. var buffer = new Buffer(length);
  35496. for (var i = 0; i < length; ++i) {
  35497. buffer[i] = a[i] ^ b[i];
  35498. }
  35499. return buffer;
  35500. };
  35501. /***/ }),
  35502. /***/ 365:
  35503. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  35504. "use strict";
  35505. /*!
  35506. * The buffer module from node.js, for the browser.
  35507. *
  35508. * @author Feross Aboukhadijeh <https://feross.org>
  35509. * @license MIT
  35510. */
  35511. /* eslint-disable no-proto */
  35512. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  35513. var base64 = __webpack_require__(7943);
  35514. var ieee754 = __webpack_require__(8405);
  35515. var customInspectSymbol = typeof Symbol === 'function' && typeof Symbol['for'] === 'function' // eslint-disable-line dot-notation
  35516. ? Symbol['for']('nodejs.util.inspect.custom') // eslint-disable-line dot-notation
  35517. : null;
  35518. exports.Buffer = Buffer;
  35519. exports.SlowBuffer = SlowBuffer;
  35520. exports.INSPECT_MAX_BYTES = 50;
  35521. var K_MAX_LENGTH = 0x7fffffff;
  35522. exports.kMaxLength = K_MAX_LENGTH;
  35523. /**
  35524. * If `Buffer.TYPED_ARRAY_SUPPORT`:
  35525. * === true Use Uint8Array implementation (fastest)
  35526. * === false Print warning and recommend using `buffer` v4.x which has an Object
  35527. * implementation (most compatible, even IE6)
  35528. *
  35529. * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
  35530. * Opera 11.6+, iOS 4.2+.
  35531. *
  35532. * We report that the browser does not support typed arrays if the are not subclassable
  35533. * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array`
  35534. * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support
  35535. * for __proto__ and has a buggy typed array implementation.
  35536. */
  35537. Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport();
  35538. if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && typeof console.error === 'function') {
  35539. 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.');
  35540. }
  35541. function typedArraySupport() {
  35542. // Can typed array instances can be augmented?
  35543. try {
  35544. var arr = new Uint8Array(1);
  35545. var proto = {
  35546. foo: function foo() {
  35547. return 42;
  35548. }
  35549. };
  35550. Object.setPrototypeOf(proto, Uint8Array.prototype);
  35551. Object.setPrototypeOf(arr, proto);
  35552. return arr.foo() === 42;
  35553. } catch (e) {
  35554. return false;
  35555. }
  35556. }
  35557. Object.defineProperty(Buffer.prototype, 'parent', {
  35558. enumerable: true,
  35559. get: function get() {
  35560. if (!Buffer.isBuffer(this)) return undefined;
  35561. return this.buffer;
  35562. }
  35563. });
  35564. Object.defineProperty(Buffer.prototype, 'offset', {
  35565. enumerable: true,
  35566. get: function get() {
  35567. if (!Buffer.isBuffer(this)) return undefined;
  35568. return this.byteOffset;
  35569. }
  35570. });
  35571. function createBuffer(length) {
  35572. if (length > K_MAX_LENGTH) {
  35573. throw new RangeError('The value "' + length + '" is invalid for option "size"');
  35574. } // Return an augmented `Uint8Array` instance
  35575. var buf = new Uint8Array(length);
  35576. Object.setPrototypeOf(buf, Buffer.prototype);
  35577. return buf;
  35578. }
  35579. /**
  35580. * The Buffer constructor returns instances of `Uint8Array` that have their
  35581. * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of
  35582. * `Uint8Array`, so the returned instances will have all the node `Buffer` methods
  35583. * and the `Uint8Array` methods. Square bracket notation works as expected -- it
  35584. * returns a single octet.
  35585. *
  35586. * The `Uint8Array` prototype remains unmodified.
  35587. */
  35588. function Buffer(arg, encodingOrOffset, length) {
  35589. // Common case.
  35590. if (typeof arg === 'number') {
  35591. if (typeof encodingOrOffset === 'string') {
  35592. throw new TypeError('The "string" argument must be of type string. Received type number');
  35593. }
  35594. return allocUnsafe(arg);
  35595. }
  35596. return from(arg, encodingOrOffset, length);
  35597. }
  35598. Buffer.poolSize = 8192; // not used by this implementation
  35599. function from(value, encodingOrOffset, length) {
  35600. if (typeof value === 'string') {
  35601. return fromString(value, encodingOrOffset);
  35602. }
  35603. if (ArrayBuffer.isView(value)) {
  35604. return fromArrayView(value);
  35605. }
  35606. if (value == null) {
  35607. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  35608. }
  35609. if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) {
  35610. return fromArrayBuffer(value, encodingOrOffset, length);
  35611. }
  35612. if (typeof SharedArrayBuffer !== 'undefined' && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) {
  35613. return fromArrayBuffer(value, encodingOrOffset, length);
  35614. }
  35615. if (typeof value === 'number') {
  35616. throw new TypeError('The "value" argument must not be of type number. Received type number');
  35617. }
  35618. var valueOf = value.valueOf && value.valueOf();
  35619. if (valueOf != null && valueOf !== value) {
  35620. return Buffer.from(valueOf, encodingOrOffset, length);
  35621. }
  35622. var b = fromObject(value);
  35623. if (b) return b;
  35624. if (typeof Symbol !== 'undefined' && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === 'function') {
  35625. return Buffer.from(value[Symbol.toPrimitive]('string'), encodingOrOffset, length);
  35626. }
  35627. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + 'or Array-like Object. Received type ' + _typeof(value));
  35628. }
  35629. /**
  35630. * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError
  35631. * if value is a number.
  35632. * Buffer.from(str[, encoding])
  35633. * Buffer.from(array)
  35634. * Buffer.from(buffer)
  35635. * Buffer.from(arrayBuffer[, byteOffset[, length]])
  35636. **/
  35637. Buffer.from = function (value, encodingOrOffset, length) {
  35638. return from(value, encodingOrOffset, length);
  35639. }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug:
  35640. // https://github.com/feross/buffer/pull/148
  35641. Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype);
  35642. Object.setPrototypeOf(Buffer, Uint8Array);
  35643. function assertSize(size) {
  35644. if (typeof size !== 'number') {
  35645. throw new TypeError('"size" argument must be of type number');
  35646. } else if (size < 0) {
  35647. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  35648. }
  35649. }
  35650. function alloc(size, fill, encoding) {
  35651. assertSize(size);
  35652. if (size <= 0) {
  35653. return createBuffer(size);
  35654. }
  35655. if (fill !== undefined) {
  35656. // Only pay attention to encoding if it's a string. This
  35657. // prevents accidentally sending in a number that would
  35658. // be interpreted as a start offset.
  35659. return typeof encoding === 'string' ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill);
  35660. }
  35661. return createBuffer(size);
  35662. }
  35663. /**
  35664. * Creates a new filled Buffer instance.
  35665. * alloc(size[, fill[, encoding]])
  35666. **/
  35667. Buffer.alloc = function (size, fill, encoding) {
  35668. return alloc(size, fill, encoding);
  35669. };
  35670. function allocUnsafe(size) {
  35671. assertSize(size);
  35672. return createBuffer(size < 0 ? 0 : checked(size) | 0);
  35673. }
  35674. /**
  35675. * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance.
  35676. * */
  35677. Buffer.allocUnsafe = function (size) {
  35678. return allocUnsafe(size);
  35679. };
  35680. /**
  35681. * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance.
  35682. */
  35683. Buffer.allocUnsafeSlow = function (size) {
  35684. return allocUnsafe(size);
  35685. };
  35686. function fromString(string, encoding) {
  35687. if (typeof encoding !== 'string' || encoding === '') {
  35688. encoding = 'utf8';
  35689. }
  35690. if (!Buffer.isEncoding(encoding)) {
  35691. throw new TypeError('Unknown encoding: ' + encoding);
  35692. }
  35693. var length = byteLength(string, encoding) | 0;
  35694. var buf = createBuffer(length);
  35695. var actual = buf.write(string, encoding);
  35696. if (actual !== length) {
  35697. // Writing a hex string, for example, that contains invalid characters will
  35698. // cause everything after the first invalid character to be ignored. (e.g.
  35699. // 'abxxcd' will be treated as 'ab')
  35700. buf = buf.slice(0, actual);
  35701. }
  35702. return buf;
  35703. }
  35704. function fromArrayLike(array) {
  35705. var length = array.length < 0 ? 0 : checked(array.length) | 0;
  35706. var buf = createBuffer(length);
  35707. for (var i = 0; i < length; i += 1) {
  35708. buf[i] = array[i] & 255;
  35709. }
  35710. return buf;
  35711. }
  35712. function fromArrayView(arrayView) {
  35713. if (isInstance(arrayView, Uint8Array)) {
  35714. var copy = new Uint8Array(arrayView);
  35715. return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength);
  35716. }
  35717. return fromArrayLike(arrayView);
  35718. }
  35719. function fromArrayBuffer(array, byteOffset, length) {
  35720. if (byteOffset < 0 || array.byteLength < byteOffset) {
  35721. throw new RangeError('"offset" is outside of buffer bounds');
  35722. }
  35723. if (array.byteLength < byteOffset + (length || 0)) {
  35724. throw new RangeError('"length" is outside of buffer bounds');
  35725. }
  35726. var buf;
  35727. if (byteOffset === undefined && length === undefined) {
  35728. buf = new Uint8Array(array);
  35729. } else if (length === undefined) {
  35730. buf = new Uint8Array(array, byteOffset);
  35731. } else {
  35732. buf = new Uint8Array(array, byteOffset, length);
  35733. } // Return an augmented `Uint8Array` instance
  35734. Object.setPrototypeOf(buf, Buffer.prototype);
  35735. return buf;
  35736. }
  35737. function fromObject(obj) {
  35738. if (Buffer.isBuffer(obj)) {
  35739. var len = checked(obj.length) | 0;
  35740. var buf = createBuffer(len);
  35741. if (buf.length === 0) {
  35742. return buf;
  35743. }
  35744. obj.copy(buf, 0, 0, len);
  35745. return buf;
  35746. }
  35747. if (obj.length !== undefined) {
  35748. if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) {
  35749. return createBuffer(0);
  35750. }
  35751. return fromArrayLike(obj);
  35752. }
  35753. if (obj.type === 'Buffer' && Array.isArray(obj.data)) {
  35754. return fromArrayLike(obj.data);
  35755. }
  35756. }
  35757. function checked(length) {
  35758. // Note: cannot use `length < K_MAX_LENGTH` here because that fails when
  35759. // length is NaN (which is otherwise coerced to zero.)
  35760. if (length >= K_MAX_LENGTH) {
  35761. throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes');
  35762. }
  35763. return length | 0;
  35764. }
  35765. function SlowBuffer(length) {
  35766. if (+length != length) {
  35767. // eslint-disable-line eqeqeq
  35768. length = 0;
  35769. }
  35770. return Buffer.alloc(+length);
  35771. }
  35772. Buffer.isBuffer = function isBuffer(b) {
  35773. return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false
  35774. };
  35775. Buffer.compare = function compare(a, b) {
  35776. if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength);
  35777. if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength);
  35778. if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
  35779. throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');
  35780. }
  35781. if (a === b) return 0;
  35782. var x = a.length;
  35783. var y = b.length;
  35784. for (var i = 0, len = Math.min(x, y); i < len; ++i) {
  35785. if (a[i] !== b[i]) {
  35786. x = a[i];
  35787. y = b[i];
  35788. break;
  35789. }
  35790. }
  35791. if (x < y) return -1;
  35792. if (y < x) return 1;
  35793. return 0;
  35794. };
  35795. Buffer.isEncoding = function isEncoding(encoding) {
  35796. switch (String(encoding).toLowerCase()) {
  35797. case 'hex':
  35798. case 'utf8':
  35799. case 'utf-8':
  35800. case 'ascii':
  35801. case 'latin1':
  35802. case 'binary':
  35803. case 'base64':
  35804. case 'ucs2':
  35805. case 'ucs-2':
  35806. case 'utf16le':
  35807. case 'utf-16le':
  35808. return true;
  35809. default:
  35810. return false;
  35811. }
  35812. };
  35813. Buffer.concat = function concat(list, length) {
  35814. if (!Array.isArray(list)) {
  35815. throw new TypeError('"list" argument must be an Array of Buffers');
  35816. }
  35817. if (list.length === 0) {
  35818. return Buffer.alloc(0);
  35819. }
  35820. var i;
  35821. if (length === undefined) {
  35822. length = 0;
  35823. for (i = 0; i < list.length; ++i) {
  35824. length += list[i].length;
  35825. }
  35826. }
  35827. var buffer = Buffer.allocUnsafe(length);
  35828. var pos = 0;
  35829. for (i = 0; i < list.length; ++i) {
  35830. var buf = list[i];
  35831. if (isInstance(buf, Uint8Array)) {
  35832. if (pos + buf.length > buffer.length) {
  35833. Buffer.from(buf).copy(buffer, pos);
  35834. } else {
  35835. Uint8Array.prototype.set.call(buffer, buf, pos);
  35836. }
  35837. } else if (!Buffer.isBuffer(buf)) {
  35838. throw new TypeError('"list" argument must be an Array of Buffers');
  35839. } else {
  35840. buf.copy(buffer, pos);
  35841. }
  35842. pos += buf.length;
  35843. }
  35844. return buffer;
  35845. };
  35846. function byteLength(string, encoding) {
  35847. if (Buffer.isBuffer(string)) {
  35848. return string.length;
  35849. }
  35850. if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) {
  35851. return string.byteLength;
  35852. }
  35853. if (typeof string !== 'string') {
  35854. throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + 'Received type ' + _typeof(string));
  35855. }
  35856. var len = string.length;
  35857. var mustMatch = arguments.length > 2 && arguments[2] === true;
  35858. if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion
  35859. var loweredCase = false;
  35860. for (;;) {
  35861. switch (encoding) {
  35862. case 'ascii':
  35863. case 'latin1':
  35864. case 'binary':
  35865. return len;
  35866. case 'utf8':
  35867. case 'utf-8':
  35868. return utf8ToBytes(string).length;
  35869. case 'ucs2':
  35870. case 'ucs-2':
  35871. case 'utf16le':
  35872. case 'utf-16le':
  35873. return len * 2;
  35874. case 'hex':
  35875. return len >>> 1;
  35876. case 'base64':
  35877. return base64ToBytes(string).length;
  35878. default:
  35879. if (loweredCase) {
  35880. return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8
  35881. }
  35882. encoding = ('' + encoding).toLowerCase();
  35883. loweredCase = true;
  35884. }
  35885. }
  35886. }
  35887. Buffer.byteLength = byteLength;
  35888. function slowToString(encoding, start, end) {
  35889. var loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only
  35890. // property of a typed array.
  35891. // This behaves neither like String nor Uint8Array in that we set start/end
  35892. // to their upper/lower bounds if the value passed is out of range.
  35893. // undefined is handled specially as per ECMA-262 6th Edition,
  35894. // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization.
  35895. if (start === undefined || start < 0) {
  35896. start = 0;
  35897. } // Return early if start > this.length. Done here to prevent potential uint32
  35898. // coercion fail below.
  35899. if (start > this.length) {
  35900. return '';
  35901. }
  35902. if (end === undefined || end > this.length) {
  35903. end = this.length;
  35904. }
  35905. if (end <= 0) {
  35906. return '';
  35907. } // Force coercion to uint32. This will also coerce falsey/NaN values to 0.
  35908. end >>>= 0;
  35909. start >>>= 0;
  35910. if (end <= start) {
  35911. return '';
  35912. }
  35913. if (!encoding) encoding = 'utf8';
  35914. while (true) {
  35915. switch (encoding) {
  35916. case 'hex':
  35917. return hexSlice(this, start, end);
  35918. case 'utf8':
  35919. case 'utf-8':
  35920. return utf8Slice(this, start, end);
  35921. case 'ascii':
  35922. return asciiSlice(this, start, end);
  35923. case 'latin1':
  35924. case 'binary':
  35925. return latin1Slice(this, start, end);
  35926. case 'base64':
  35927. return base64Slice(this, start, end);
  35928. case 'ucs2':
  35929. case 'ucs-2':
  35930. case 'utf16le':
  35931. case 'utf-16le':
  35932. return utf16leSlice(this, start, end);
  35933. default:
  35934. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  35935. encoding = (encoding + '').toLowerCase();
  35936. loweredCase = true;
  35937. }
  35938. }
  35939. } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package)
  35940. // to detect a Buffer instance. It's not possible to use `instanceof Buffer`
  35941. // reliably in a browserify context because there could be multiple different
  35942. // copies of the 'buffer' package in use. This method works even for Buffer
  35943. // instances that were created from another copy of the `buffer` package.
  35944. // See: https://github.com/feross/buffer/issues/154
  35945. Buffer.prototype._isBuffer = true;
  35946. function swap(b, n, m) {
  35947. var i = b[n];
  35948. b[n] = b[m];
  35949. b[m] = i;
  35950. }
  35951. Buffer.prototype.swap16 = function swap16() {
  35952. var len = this.length;
  35953. if (len % 2 !== 0) {
  35954. throw new RangeError('Buffer size must be a multiple of 16-bits');
  35955. }
  35956. for (var i = 0; i < len; i += 2) {
  35957. swap(this, i, i + 1);
  35958. }
  35959. return this;
  35960. };
  35961. Buffer.prototype.swap32 = function swap32() {
  35962. var len = this.length;
  35963. if (len % 4 !== 0) {
  35964. throw new RangeError('Buffer size must be a multiple of 32-bits');
  35965. }
  35966. for (var i = 0; i < len; i += 4) {
  35967. swap(this, i, i + 3);
  35968. swap(this, i + 1, i + 2);
  35969. }
  35970. return this;
  35971. };
  35972. Buffer.prototype.swap64 = function swap64() {
  35973. var len = this.length;
  35974. if (len % 8 !== 0) {
  35975. throw new RangeError('Buffer size must be a multiple of 64-bits');
  35976. }
  35977. for (var i = 0; i < len; i += 8) {
  35978. swap(this, i, i + 7);
  35979. swap(this, i + 1, i + 6);
  35980. swap(this, i + 2, i + 5);
  35981. swap(this, i + 3, i + 4);
  35982. }
  35983. return this;
  35984. };
  35985. Buffer.prototype.toString = function toString() {
  35986. var length = this.length;
  35987. if (length === 0) return '';
  35988. if (arguments.length === 0) return utf8Slice(this, 0, length);
  35989. return slowToString.apply(this, arguments);
  35990. };
  35991. Buffer.prototype.toLocaleString = Buffer.prototype.toString;
  35992. Buffer.prototype.equals = function equals(b) {
  35993. if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer');
  35994. if (this === b) return true;
  35995. return Buffer.compare(this, b) === 0;
  35996. };
  35997. Buffer.prototype.inspect = function inspect() {
  35998. var str = '';
  35999. var max = exports.INSPECT_MAX_BYTES;
  36000. str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim();
  36001. if (this.length > max) str += ' ... ';
  36002. return '<Buffer ' + str + '>';
  36003. };
  36004. if (customInspectSymbol) {
  36005. Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect;
  36006. }
  36007. Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) {
  36008. if (isInstance(target, Uint8Array)) {
  36009. target = Buffer.from(target, target.offset, target.byteLength);
  36010. }
  36011. if (!Buffer.isBuffer(target)) {
  36012. throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. ' + 'Received type ' + _typeof(target));
  36013. }
  36014. if (start === undefined) {
  36015. start = 0;
  36016. }
  36017. if (end === undefined) {
  36018. end = target ? target.length : 0;
  36019. }
  36020. if (thisStart === undefined) {
  36021. thisStart = 0;
  36022. }
  36023. if (thisEnd === undefined) {
  36024. thisEnd = this.length;
  36025. }
  36026. if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) {
  36027. throw new RangeError('out of range index');
  36028. }
  36029. if (thisStart >= thisEnd && start >= end) {
  36030. return 0;
  36031. }
  36032. if (thisStart >= thisEnd) {
  36033. return -1;
  36034. }
  36035. if (start >= end) {
  36036. return 1;
  36037. }
  36038. start >>>= 0;
  36039. end >>>= 0;
  36040. thisStart >>>= 0;
  36041. thisEnd >>>= 0;
  36042. if (this === target) return 0;
  36043. var x = thisEnd - thisStart;
  36044. var y = end - start;
  36045. var len = Math.min(x, y);
  36046. var thisCopy = this.slice(thisStart, thisEnd);
  36047. var targetCopy = target.slice(start, end);
  36048. for (var i = 0; i < len; ++i) {
  36049. if (thisCopy[i] !== targetCopy[i]) {
  36050. x = thisCopy[i];
  36051. y = targetCopy[i];
  36052. break;
  36053. }
  36054. }
  36055. if (x < y) return -1;
  36056. if (y < x) return 1;
  36057. return 0;
  36058. }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`,
  36059. // OR the last index of `val` in `buffer` at offset <= `byteOffset`.
  36060. //
  36061. // Arguments:
  36062. // - buffer - a Buffer to search
  36063. // - val - a string, Buffer, or number
  36064. // - byteOffset - an index into `buffer`; will be clamped to an int32
  36065. // - encoding - an optional encoding, relevant is val is a string
  36066. // - dir - true for indexOf, false for lastIndexOf
  36067. function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) {
  36068. // Empty buffer means no match
  36069. if (buffer.length === 0) return -1; // Normalize byteOffset
  36070. if (typeof byteOffset === 'string') {
  36071. encoding = byteOffset;
  36072. byteOffset = 0;
  36073. } else if (byteOffset > 0x7fffffff) {
  36074. byteOffset = 0x7fffffff;
  36075. } else if (byteOffset < -0x80000000) {
  36076. byteOffset = -0x80000000;
  36077. }
  36078. byteOffset = +byteOffset; // Coerce to Number.
  36079. if (numberIsNaN(byteOffset)) {
  36080. // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer
  36081. byteOffset = dir ? 0 : buffer.length - 1;
  36082. } // Normalize byteOffset: negative offsets start from the end of the buffer
  36083. if (byteOffset < 0) byteOffset = buffer.length + byteOffset;
  36084. if (byteOffset >= buffer.length) {
  36085. if (dir) return -1;else byteOffset = buffer.length - 1;
  36086. } else if (byteOffset < 0) {
  36087. if (dir) byteOffset = 0;else return -1;
  36088. } // Normalize val
  36089. if (typeof val === 'string') {
  36090. val = Buffer.from(val, encoding);
  36091. } // Finally, search either indexOf (if dir is true) or lastIndexOf
  36092. if (Buffer.isBuffer(val)) {
  36093. // Special case: looking for empty string/buffer always fails
  36094. if (val.length === 0) {
  36095. return -1;
  36096. }
  36097. return arrayIndexOf(buffer, val, byteOffset, encoding, dir);
  36098. } else if (typeof val === 'number') {
  36099. val = val & 0xFF; // Search for a byte value [0-255]
  36100. if (typeof Uint8Array.prototype.indexOf === 'function') {
  36101. if (dir) {
  36102. return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset);
  36103. } else {
  36104. return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset);
  36105. }
  36106. }
  36107. return arrayIndexOf(buffer, [val], byteOffset, encoding, dir);
  36108. }
  36109. throw new TypeError('val must be string, number or Buffer');
  36110. }
  36111. function arrayIndexOf(arr, val, byteOffset, encoding, dir) {
  36112. var indexSize = 1;
  36113. var arrLength = arr.length;
  36114. var valLength = val.length;
  36115. if (encoding !== undefined) {
  36116. encoding = String(encoding).toLowerCase();
  36117. if (encoding === 'ucs2' || encoding === 'ucs-2' || encoding === 'utf16le' || encoding === 'utf-16le') {
  36118. if (arr.length < 2 || val.length < 2) {
  36119. return -1;
  36120. }
  36121. indexSize = 2;
  36122. arrLength /= 2;
  36123. valLength /= 2;
  36124. byteOffset /= 2;
  36125. }
  36126. }
  36127. function read(buf, i) {
  36128. if (indexSize === 1) {
  36129. return buf[i];
  36130. } else {
  36131. return buf.readUInt16BE(i * indexSize);
  36132. }
  36133. }
  36134. var i;
  36135. if (dir) {
  36136. var foundIndex = -1;
  36137. for (i = byteOffset; i < arrLength; i++) {
  36138. if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) {
  36139. if (foundIndex === -1) foundIndex = i;
  36140. if (i - foundIndex + 1 === valLength) return foundIndex * indexSize;
  36141. } else {
  36142. if (foundIndex !== -1) i -= i - foundIndex;
  36143. foundIndex = -1;
  36144. }
  36145. }
  36146. } else {
  36147. if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength;
  36148. for (i = byteOffset; i >= 0; i--) {
  36149. var found = true;
  36150. for (var j = 0; j < valLength; j++) {
  36151. if (read(arr, i + j) !== read(val, j)) {
  36152. found = false;
  36153. break;
  36154. }
  36155. }
  36156. if (found) return i;
  36157. }
  36158. }
  36159. return -1;
  36160. }
  36161. Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
  36162. return this.indexOf(val, byteOffset, encoding) !== -1;
  36163. };
  36164. Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
  36165. return bidirectionalIndexOf(this, val, byteOffset, encoding, true);
  36166. };
  36167. Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) {
  36168. return bidirectionalIndexOf(this, val, byteOffset, encoding, false);
  36169. };
  36170. function hexWrite(buf, string, offset, length) {
  36171. offset = Number(offset) || 0;
  36172. var remaining = buf.length - offset;
  36173. if (!length) {
  36174. length = remaining;
  36175. } else {
  36176. length = Number(length);
  36177. if (length > remaining) {
  36178. length = remaining;
  36179. }
  36180. }
  36181. var strLen = string.length;
  36182. if (length > strLen / 2) {
  36183. length = strLen / 2;
  36184. }
  36185. for (var i = 0; i < length; ++i) {
  36186. var parsed = parseInt(string.substr(i * 2, 2), 16);
  36187. if (numberIsNaN(parsed)) return i;
  36188. buf[offset + i] = parsed;
  36189. }
  36190. return i;
  36191. }
  36192. function utf8Write(buf, string, offset, length) {
  36193. return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length);
  36194. }
  36195. function asciiWrite(buf, string, offset, length) {
  36196. return blitBuffer(asciiToBytes(string), buf, offset, length);
  36197. }
  36198. function base64Write(buf, string, offset, length) {
  36199. return blitBuffer(base64ToBytes(string), buf, offset, length);
  36200. }
  36201. function ucs2Write(buf, string, offset, length) {
  36202. return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length);
  36203. }
  36204. Buffer.prototype.write = function write(string, offset, length, encoding) {
  36205. // Buffer#write(string)
  36206. if (offset === undefined) {
  36207. encoding = 'utf8';
  36208. length = this.length;
  36209. offset = 0; // Buffer#write(string, encoding)
  36210. } else if (length === undefined && typeof offset === 'string') {
  36211. encoding = offset;
  36212. length = this.length;
  36213. offset = 0; // Buffer#write(string, offset[, length][, encoding])
  36214. } else if (isFinite(offset)) {
  36215. offset = offset >>> 0;
  36216. if (isFinite(length)) {
  36217. length = length >>> 0;
  36218. if (encoding === undefined) encoding = 'utf8';
  36219. } else {
  36220. encoding = length;
  36221. length = undefined;
  36222. }
  36223. } else {
  36224. throw new Error('Buffer.write(string, encoding, offset[, length]) is no longer supported');
  36225. }
  36226. var remaining = this.length - offset;
  36227. if (length === undefined || length > remaining) length = remaining;
  36228. if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) {
  36229. throw new RangeError('Attempt to write outside buffer bounds');
  36230. }
  36231. if (!encoding) encoding = 'utf8';
  36232. var loweredCase = false;
  36233. for (;;) {
  36234. switch (encoding) {
  36235. case 'hex':
  36236. return hexWrite(this, string, offset, length);
  36237. case 'utf8':
  36238. case 'utf-8':
  36239. return utf8Write(this, string, offset, length);
  36240. case 'ascii':
  36241. case 'latin1':
  36242. case 'binary':
  36243. return asciiWrite(this, string, offset, length);
  36244. case 'base64':
  36245. // Warning: maxLength not taken into account in base64Write
  36246. return base64Write(this, string, offset, length);
  36247. case 'ucs2':
  36248. case 'ucs-2':
  36249. case 'utf16le':
  36250. case 'utf-16le':
  36251. return ucs2Write(this, string, offset, length);
  36252. default:
  36253. if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding);
  36254. encoding = ('' + encoding).toLowerCase();
  36255. loweredCase = true;
  36256. }
  36257. }
  36258. };
  36259. Buffer.prototype.toJSON = function toJSON() {
  36260. return {
  36261. type: 'Buffer',
  36262. data: Array.prototype.slice.call(this._arr || this, 0)
  36263. };
  36264. };
  36265. function base64Slice(buf, start, end) {
  36266. if (start === 0 && end === buf.length) {
  36267. return base64.fromByteArray(buf);
  36268. } else {
  36269. return base64.fromByteArray(buf.slice(start, end));
  36270. }
  36271. }
  36272. function utf8Slice(buf, start, end) {
  36273. end = Math.min(buf.length, end);
  36274. var res = [];
  36275. var i = start;
  36276. while (i < end) {
  36277. var firstByte = buf[i];
  36278. var codePoint = null;
  36279. var bytesPerSequence = firstByte > 0xEF ? 4 : firstByte > 0xDF ? 3 : firstByte > 0xBF ? 2 : 1;
  36280. if (i + bytesPerSequence <= end) {
  36281. var secondByte, thirdByte, fourthByte, tempCodePoint;
  36282. switch (bytesPerSequence) {
  36283. case 1:
  36284. if (firstByte < 0x80) {
  36285. codePoint = firstByte;
  36286. }
  36287. break;
  36288. case 2:
  36289. secondByte = buf[i + 1];
  36290. if ((secondByte & 0xC0) === 0x80) {
  36291. tempCodePoint = (firstByte & 0x1F) << 0x6 | secondByte & 0x3F;
  36292. if (tempCodePoint > 0x7F) {
  36293. codePoint = tempCodePoint;
  36294. }
  36295. }
  36296. break;
  36297. case 3:
  36298. secondByte = buf[i + 1];
  36299. thirdByte = buf[i + 2];
  36300. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
  36301. tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | thirdByte & 0x3F;
  36302. if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
  36303. codePoint = tempCodePoint;
  36304. }
  36305. }
  36306. break;
  36307. case 4:
  36308. secondByte = buf[i + 1];
  36309. thirdByte = buf[i + 2];
  36310. fourthByte = buf[i + 3];
  36311. if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
  36312. tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | fourthByte & 0x3F;
  36313. if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
  36314. codePoint = tempCodePoint;
  36315. }
  36316. }
  36317. }
  36318. }
  36319. if (codePoint === null) {
  36320. // we did not generate a valid codePoint so insert a
  36321. // replacement char (U+FFFD) and advance only 1 byte
  36322. codePoint = 0xFFFD;
  36323. bytesPerSequence = 1;
  36324. } else if (codePoint > 0xFFFF) {
  36325. // encode to utf16 (surrogate pair dance)
  36326. codePoint -= 0x10000;
  36327. res.push(codePoint >>> 10 & 0x3FF | 0xD800);
  36328. codePoint = 0xDC00 | codePoint & 0x3FF;
  36329. }
  36330. res.push(codePoint);
  36331. i += bytesPerSequence;
  36332. }
  36333. return decodeCodePointsArray(res);
  36334. } // Based on http://stackoverflow.com/a/22747272/680742, the browser with
  36335. // the lowest limit is Chrome, with 0x10000 args.
  36336. // We go 1 magnitude less, for safety
  36337. var MAX_ARGUMENTS_LENGTH = 0x1000;
  36338. function decodeCodePointsArray(codePoints) {
  36339. var len = codePoints.length;
  36340. if (len <= MAX_ARGUMENTS_LENGTH) {
  36341. return String.fromCharCode.apply(String, codePoints); // avoid extra slice()
  36342. } // Decode in chunks to avoid "call stack size exceeded".
  36343. var res = '';
  36344. var i = 0;
  36345. while (i < len) {
  36346. res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH));
  36347. }
  36348. return res;
  36349. }
  36350. function asciiSlice(buf, start, end) {
  36351. var ret = '';
  36352. end = Math.min(buf.length, end);
  36353. for (var i = start; i < end; ++i) {
  36354. ret += String.fromCharCode(buf[i] & 0x7F);
  36355. }
  36356. return ret;
  36357. }
  36358. function latin1Slice(buf, start, end) {
  36359. var ret = '';
  36360. end = Math.min(buf.length, end);
  36361. for (var i = start; i < end; ++i) {
  36362. ret += String.fromCharCode(buf[i]);
  36363. }
  36364. return ret;
  36365. }
  36366. function hexSlice(buf, start, end) {
  36367. var len = buf.length;
  36368. if (!start || start < 0) start = 0;
  36369. if (!end || end < 0 || end > len) end = len;
  36370. var out = '';
  36371. for (var i = start; i < end; ++i) {
  36372. out += hexSliceLookupTable[buf[i]];
  36373. }
  36374. return out;
  36375. }
  36376. function utf16leSlice(buf, start, end) {
  36377. var bytes = buf.slice(start, end);
  36378. var res = ''; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js)
  36379. for (var i = 0; i < bytes.length - 1; i += 2) {
  36380. res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256);
  36381. }
  36382. return res;
  36383. }
  36384. Buffer.prototype.slice = function slice(start, end) {
  36385. var len = this.length;
  36386. start = ~~start;
  36387. end = end === undefined ? len : ~~end;
  36388. if (start < 0) {
  36389. start += len;
  36390. if (start < 0) start = 0;
  36391. } else if (start > len) {
  36392. start = len;
  36393. }
  36394. if (end < 0) {
  36395. end += len;
  36396. if (end < 0) end = 0;
  36397. } else if (end > len) {
  36398. end = len;
  36399. }
  36400. if (end < start) end = start;
  36401. var newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance
  36402. Object.setPrototypeOf(newBuf, Buffer.prototype);
  36403. return newBuf;
  36404. };
  36405. /*
  36406. * Need to make sure that buffer isn't trying to write out of bounds.
  36407. */
  36408. function checkOffset(offset, ext, length) {
  36409. if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint');
  36410. if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length');
  36411. }
  36412. Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) {
  36413. offset = offset >>> 0;
  36414. byteLength = byteLength >>> 0;
  36415. if (!noAssert) checkOffset(offset, byteLength, this.length);
  36416. var val = this[offset];
  36417. var mul = 1;
  36418. var i = 0;
  36419. while (++i < byteLength && (mul *= 0x100)) {
  36420. val += this[offset + i] * mul;
  36421. }
  36422. return val;
  36423. };
  36424. Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) {
  36425. offset = offset >>> 0;
  36426. byteLength = byteLength >>> 0;
  36427. if (!noAssert) {
  36428. checkOffset(offset, byteLength, this.length);
  36429. }
  36430. var val = this[offset + --byteLength];
  36431. var mul = 1;
  36432. while (byteLength > 0 && (mul *= 0x100)) {
  36433. val += this[offset + --byteLength] * mul;
  36434. }
  36435. return val;
  36436. };
  36437. Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) {
  36438. offset = offset >>> 0;
  36439. if (!noAssert) checkOffset(offset, 1, this.length);
  36440. return this[offset];
  36441. };
  36442. Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) {
  36443. offset = offset >>> 0;
  36444. if (!noAssert) checkOffset(offset, 2, this.length);
  36445. return this[offset] | this[offset + 1] << 8;
  36446. };
  36447. Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) {
  36448. offset = offset >>> 0;
  36449. if (!noAssert) checkOffset(offset, 2, this.length);
  36450. return this[offset] << 8 | this[offset + 1];
  36451. };
  36452. Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) {
  36453. offset = offset >>> 0;
  36454. if (!noAssert) checkOffset(offset, 4, this.length);
  36455. return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 0x1000000;
  36456. };
  36457. Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) {
  36458. offset = offset >>> 0;
  36459. if (!noAssert) checkOffset(offset, 4, this.length);
  36460. return this[offset] * 0x1000000 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]);
  36461. };
  36462. Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) {
  36463. offset = offset >>> 0;
  36464. byteLength = byteLength >>> 0;
  36465. if (!noAssert) checkOffset(offset, byteLength, this.length);
  36466. var val = this[offset];
  36467. var mul = 1;
  36468. var i = 0;
  36469. while (++i < byteLength && (mul *= 0x100)) {
  36470. val += this[offset + i] * mul;
  36471. }
  36472. mul *= 0x80;
  36473. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  36474. return val;
  36475. };
  36476. Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) {
  36477. offset = offset >>> 0;
  36478. byteLength = byteLength >>> 0;
  36479. if (!noAssert) checkOffset(offset, byteLength, this.length);
  36480. var i = byteLength;
  36481. var mul = 1;
  36482. var val = this[offset + --i];
  36483. while (i > 0 && (mul *= 0x100)) {
  36484. val += this[offset + --i] * mul;
  36485. }
  36486. mul *= 0x80;
  36487. if (val >= mul) val -= Math.pow(2, 8 * byteLength);
  36488. return val;
  36489. };
  36490. Buffer.prototype.readInt8 = function readInt8(offset, noAssert) {
  36491. offset = offset >>> 0;
  36492. if (!noAssert) checkOffset(offset, 1, this.length);
  36493. if (!(this[offset] & 0x80)) return this[offset];
  36494. return (0xff - this[offset] + 1) * -1;
  36495. };
  36496. Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) {
  36497. offset = offset >>> 0;
  36498. if (!noAssert) checkOffset(offset, 2, this.length);
  36499. var val = this[offset] | this[offset + 1] << 8;
  36500. return val & 0x8000 ? val | 0xFFFF0000 : val;
  36501. };
  36502. Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) {
  36503. offset = offset >>> 0;
  36504. if (!noAssert) checkOffset(offset, 2, this.length);
  36505. var val = this[offset + 1] | this[offset] << 8;
  36506. return val & 0x8000 ? val | 0xFFFF0000 : val;
  36507. };
  36508. Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) {
  36509. offset = offset >>> 0;
  36510. if (!noAssert) checkOffset(offset, 4, this.length);
  36511. return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24;
  36512. };
  36513. Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) {
  36514. offset = offset >>> 0;
  36515. if (!noAssert) checkOffset(offset, 4, this.length);
  36516. return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3];
  36517. };
  36518. Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) {
  36519. offset = offset >>> 0;
  36520. if (!noAssert) checkOffset(offset, 4, this.length);
  36521. return ieee754.read(this, offset, true, 23, 4);
  36522. };
  36523. Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) {
  36524. offset = offset >>> 0;
  36525. if (!noAssert) checkOffset(offset, 4, this.length);
  36526. return ieee754.read(this, offset, false, 23, 4);
  36527. };
  36528. Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) {
  36529. offset = offset >>> 0;
  36530. if (!noAssert) checkOffset(offset, 8, this.length);
  36531. return ieee754.read(this, offset, true, 52, 8);
  36532. };
  36533. Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) {
  36534. offset = offset >>> 0;
  36535. if (!noAssert) checkOffset(offset, 8, this.length);
  36536. return ieee754.read(this, offset, false, 52, 8);
  36537. };
  36538. function checkInt(buf, value, offset, ext, max, min) {
  36539. if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance');
  36540. if (value > max || value < min) throw new RangeError('"value" argument is out of bounds');
  36541. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  36542. }
  36543. Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) {
  36544. value = +value;
  36545. offset = offset >>> 0;
  36546. byteLength = byteLength >>> 0;
  36547. if (!noAssert) {
  36548. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  36549. checkInt(this, value, offset, byteLength, maxBytes, 0);
  36550. }
  36551. var mul = 1;
  36552. var i = 0;
  36553. this[offset] = value & 0xFF;
  36554. while (++i < byteLength && (mul *= 0x100)) {
  36555. this[offset + i] = value / mul & 0xFF;
  36556. }
  36557. return offset + byteLength;
  36558. };
  36559. Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) {
  36560. value = +value;
  36561. offset = offset >>> 0;
  36562. byteLength = byteLength >>> 0;
  36563. if (!noAssert) {
  36564. var maxBytes = Math.pow(2, 8 * byteLength) - 1;
  36565. checkInt(this, value, offset, byteLength, maxBytes, 0);
  36566. }
  36567. var i = byteLength - 1;
  36568. var mul = 1;
  36569. this[offset + i] = value & 0xFF;
  36570. while (--i >= 0 && (mul *= 0x100)) {
  36571. this[offset + i] = value / mul & 0xFF;
  36572. }
  36573. return offset + byteLength;
  36574. };
  36575. Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) {
  36576. value = +value;
  36577. offset = offset >>> 0;
  36578. if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0);
  36579. this[offset] = value & 0xff;
  36580. return offset + 1;
  36581. };
  36582. Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) {
  36583. value = +value;
  36584. offset = offset >>> 0;
  36585. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  36586. this[offset] = value & 0xff;
  36587. this[offset + 1] = value >>> 8;
  36588. return offset + 2;
  36589. };
  36590. Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) {
  36591. value = +value;
  36592. offset = offset >>> 0;
  36593. if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0);
  36594. this[offset] = value >>> 8;
  36595. this[offset + 1] = value & 0xff;
  36596. return offset + 2;
  36597. };
  36598. Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) {
  36599. value = +value;
  36600. offset = offset >>> 0;
  36601. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  36602. this[offset + 3] = value >>> 24;
  36603. this[offset + 2] = value >>> 16;
  36604. this[offset + 1] = value >>> 8;
  36605. this[offset] = value & 0xff;
  36606. return offset + 4;
  36607. };
  36608. Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) {
  36609. value = +value;
  36610. offset = offset >>> 0;
  36611. if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0);
  36612. this[offset] = value >>> 24;
  36613. this[offset + 1] = value >>> 16;
  36614. this[offset + 2] = value >>> 8;
  36615. this[offset + 3] = value & 0xff;
  36616. return offset + 4;
  36617. };
  36618. Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) {
  36619. value = +value;
  36620. offset = offset >>> 0;
  36621. if (!noAssert) {
  36622. var limit = Math.pow(2, 8 * byteLength - 1);
  36623. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  36624. }
  36625. var i = 0;
  36626. var mul = 1;
  36627. var sub = 0;
  36628. this[offset] = value & 0xFF;
  36629. while (++i < byteLength && (mul *= 0x100)) {
  36630. if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) {
  36631. sub = 1;
  36632. }
  36633. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  36634. }
  36635. return offset + byteLength;
  36636. };
  36637. Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) {
  36638. value = +value;
  36639. offset = offset >>> 0;
  36640. if (!noAssert) {
  36641. var limit = Math.pow(2, 8 * byteLength - 1);
  36642. checkInt(this, value, offset, byteLength, limit - 1, -limit);
  36643. }
  36644. var i = byteLength - 1;
  36645. var mul = 1;
  36646. var sub = 0;
  36647. this[offset + i] = value & 0xFF;
  36648. while (--i >= 0 && (mul *= 0x100)) {
  36649. if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) {
  36650. sub = 1;
  36651. }
  36652. this[offset + i] = (value / mul >> 0) - sub & 0xFF;
  36653. }
  36654. return offset + byteLength;
  36655. };
  36656. Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) {
  36657. value = +value;
  36658. offset = offset >>> 0;
  36659. if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80);
  36660. if (value < 0) value = 0xff + value + 1;
  36661. this[offset] = value & 0xff;
  36662. return offset + 1;
  36663. };
  36664. Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) {
  36665. value = +value;
  36666. offset = offset >>> 0;
  36667. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  36668. this[offset] = value & 0xff;
  36669. this[offset + 1] = value >>> 8;
  36670. return offset + 2;
  36671. };
  36672. Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) {
  36673. value = +value;
  36674. offset = offset >>> 0;
  36675. if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000);
  36676. this[offset] = value >>> 8;
  36677. this[offset + 1] = value & 0xff;
  36678. return offset + 2;
  36679. };
  36680. Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) {
  36681. value = +value;
  36682. offset = offset >>> 0;
  36683. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  36684. this[offset] = value & 0xff;
  36685. this[offset + 1] = value >>> 8;
  36686. this[offset + 2] = value >>> 16;
  36687. this[offset + 3] = value >>> 24;
  36688. return offset + 4;
  36689. };
  36690. Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) {
  36691. value = +value;
  36692. offset = offset >>> 0;
  36693. if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000);
  36694. if (value < 0) value = 0xffffffff + value + 1;
  36695. this[offset] = value >>> 24;
  36696. this[offset + 1] = value >>> 16;
  36697. this[offset + 2] = value >>> 8;
  36698. this[offset + 3] = value & 0xff;
  36699. return offset + 4;
  36700. };
  36701. function checkIEEE754(buf, value, offset, ext, max, min) {
  36702. if (offset + ext > buf.length) throw new RangeError('Index out of range');
  36703. if (offset < 0) throw new RangeError('Index out of range');
  36704. }
  36705. function writeFloat(buf, value, offset, littleEndian, noAssert) {
  36706. value = +value;
  36707. offset = offset >>> 0;
  36708. if (!noAssert) {
  36709. checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38);
  36710. }
  36711. ieee754.write(buf, value, offset, littleEndian, 23, 4);
  36712. return offset + 4;
  36713. }
  36714. Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) {
  36715. return writeFloat(this, value, offset, true, noAssert);
  36716. };
  36717. Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) {
  36718. return writeFloat(this, value, offset, false, noAssert);
  36719. };
  36720. function writeDouble(buf, value, offset, littleEndian, noAssert) {
  36721. value = +value;
  36722. offset = offset >>> 0;
  36723. if (!noAssert) {
  36724. checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308);
  36725. }
  36726. ieee754.write(buf, value, offset, littleEndian, 52, 8);
  36727. return offset + 8;
  36728. }
  36729. Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) {
  36730. return writeDouble(this, value, offset, true, noAssert);
  36731. };
  36732. Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) {
  36733. return writeDouble(this, value, offset, false, noAssert);
  36734. }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
  36735. Buffer.prototype.copy = function copy(target, targetStart, start, end) {
  36736. if (!Buffer.isBuffer(target)) throw new TypeError('argument should be a Buffer');
  36737. if (!start) start = 0;
  36738. if (!end && end !== 0) end = this.length;
  36739. if (targetStart >= target.length) targetStart = target.length;
  36740. if (!targetStart) targetStart = 0;
  36741. if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done
  36742. if (end === start) return 0;
  36743. if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions
  36744. if (targetStart < 0) {
  36745. throw new RangeError('targetStart out of bounds');
  36746. }
  36747. if (start < 0 || start >= this.length) throw new RangeError('Index out of range');
  36748. if (end < 0) throw new RangeError('sourceEnd out of bounds'); // Are we oob?
  36749. if (end > this.length) end = this.length;
  36750. if (target.length - targetStart < end - start) {
  36751. end = target.length - targetStart + start;
  36752. }
  36753. var len = end - start;
  36754. if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') {
  36755. // Use built-in when available, missing from IE11
  36756. this.copyWithin(targetStart, start, end);
  36757. } else {
  36758. Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart);
  36759. }
  36760. return len;
  36761. }; // Usage:
  36762. // buffer.fill(number[, offset[, end]])
  36763. // buffer.fill(buffer[, offset[, end]])
  36764. // buffer.fill(string[, offset[, end]][, encoding])
  36765. Buffer.prototype.fill = function fill(val, start, end, encoding) {
  36766. // Handle string cases:
  36767. if (typeof val === 'string') {
  36768. if (typeof start === 'string') {
  36769. encoding = start;
  36770. start = 0;
  36771. end = this.length;
  36772. } else if (typeof end === 'string') {
  36773. encoding = end;
  36774. end = this.length;
  36775. }
  36776. if (encoding !== undefined && typeof encoding !== 'string') {
  36777. throw new TypeError('encoding must be a string');
  36778. }
  36779. if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
  36780. throw new TypeError('Unknown encoding: ' + encoding);
  36781. }
  36782. if (val.length === 1) {
  36783. var code = val.charCodeAt(0);
  36784. if (encoding === 'utf8' && code < 128 || encoding === 'latin1') {
  36785. // Fast path: If `val` fits into a single byte, use that numeric value.
  36786. val = code;
  36787. }
  36788. }
  36789. } else if (typeof val === 'number') {
  36790. val = val & 255;
  36791. } else if (typeof val === 'boolean') {
  36792. val = Number(val);
  36793. } // Invalid ranges are not set to a default, so can range check early.
  36794. if (start < 0 || this.length < start || this.length < end) {
  36795. throw new RangeError('Out of range index');
  36796. }
  36797. if (end <= start) {
  36798. return this;
  36799. }
  36800. start = start >>> 0;
  36801. end = end === undefined ? this.length : end >>> 0;
  36802. if (!val) val = 0;
  36803. var i;
  36804. if (typeof val === 'number') {
  36805. for (i = start; i < end; ++i) {
  36806. this[i] = val;
  36807. }
  36808. } else {
  36809. var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding);
  36810. var len = bytes.length;
  36811. if (len === 0) {
  36812. throw new TypeError('The value "' + val + '" is invalid for argument "value"');
  36813. }
  36814. for (i = 0; i < end - start; ++i) {
  36815. this[i + start] = bytes[i % len];
  36816. }
  36817. }
  36818. return this;
  36819. }; // HELPER FUNCTIONS
  36820. // ================
  36821. var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
  36822. function base64clean(str) {
  36823. // Node takes equal signs as end of the Base64 encoding
  36824. str = str.split('=')[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not
  36825. str = str.trim().replace(INVALID_BASE64_RE, ''); // Node converts strings with length < 2 to ''
  36826. if (str.length < 2) return ''; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
  36827. while (str.length % 4 !== 0) {
  36828. str = str + '=';
  36829. }
  36830. return str;
  36831. }
  36832. function utf8ToBytes(string, units) {
  36833. units = units || Infinity;
  36834. var codePoint;
  36835. var length = string.length;
  36836. var leadSurrogate = null;
  36837. var bytes = [];
  36838. for (var i = 0; i < length; ++i) {
  36839. codePoint = string.charCodeAt(i); // is surrogate component
  36840. if (codePoint > 0xD7FF && codePoint < 0xE000) {
  36841. // last char was a lead
  36842. if (!leadSurrogate) {
  36843. // no lead yet
  36844. if (codePoint > 0xDBFF) {
  36845. // unexpected trail
  36846. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  36847. continue;
  36848. } else if (i + 1 === length) {
  36849. // unpaired lead
  36850. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  36851. continue;
  36852. } // valid lead
  36853. leadSurrogate = codePoint;
  36854. continue;
  36855. } // 2 leads in a row
  36856. if (codePoint < 0xDC00) {
  36857. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  36858. leadSurrogate = codePoint;
  36859. continue;
  36860. } // valid surrogate pair
  36861. codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000;
  36862. } else if (leadSurrogate) {
  36863. // valid bmp char, but last char was a lead
  36864. if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD);
  36865. }
  36866. leadSurrogate = null; // encode utf8
  36867. if (codePoint < 0x80) {
  36868. if ((units -= 1) < 0) break;
  36869. bytes.push(codePoint);
  36870. } else if (codePoint < 0x800) {
  36871. if ((units -= 2) < 0) break;
  36872. bytes.push(codePoint >> 0x6 | 0xC0, codePoint & 0x3F | 0x80);
  36873. } else if (codePoint < 0x10000) {
  36874. if ((units -= 3) < 0) break;
  36875. bytes.push(codePoint >> 0xC | 0xE0, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  36876. } else if (codePoint < 0x110000) {
  36877. if ((units -= 4) < 0) break;
  36878. bytes.push(codePoint >> 0x12 | 0xF0, codePoint >> 0xC & 0x3F | 0x80, codePoint >> 0x6 & 0x3F | 0x80, codePoint & 0x3F | 0x80);
  36879. } else {
  36880. throw new Error('Invalid code point');
  36881. }
  36882. }
  36883. return bytes;
  36884. }
  36885. function asciiToBytes(str) {
  36886. var byteArray = [];
  36887. for (var i = 0; i < str.length; ++i) {
  36888. // Node's code seems to be doing this and not & 0x7F..
  36889. byteArray.push(str.charCodeAt(i) & 0xFF);
  36890. }
  36891. return byteArray;
  36892. }
  36893. function utf16leToBytes(str, units) {
  36894. var c, hi, lo;
  36895. var byteArray = [];
  36896. for (var i = 0; i < str.length; ++i) {
  36897. if ((units -= 2) < 0) break;
  36898. c = str.charCodeAt(i);
  36899. hi = c >> 8;
  36900. lo = c % 256;
  36901. byteArray.push(lo);
  36902. byteArray.push(hi);
  36903. }
  36904. return byteArray;
  36905. }
  36906. function base64ToBytes(str) {
  36907. return base64.toByteArray(base64clean(str));
  36908. }
  36909. function blitBuffer(src, dst, offset, length) {
  36910. for (var i = 0; i < length; ++i) {
  36911. if (i + offset >= dst.length || i >= src.length) break;
  36912. dst[i + offset] = src[i];
  36913. }
  36914. return i;
  36915. } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass
  36916. // the `instanceof` check but they should be treated as of that type.
  36917. // See: https://github.com/feross/buffer/issues/166
  36918. function isInstance(obj, type) {
  36919. return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name;
  36920. }
  36921. function numberIsNaN(obj) {
  36922. // For IE11 support
  36923. return obj !== obj; // eslint-disable-line no-self-compare
  36924. } // Create lookup table for `toString('hex')`
  36925. // See: https://github.com/feross/buffer/issues/219
  36926. var hexSliceLookupTable = function () {
  36927. var alphabet = '0123456789abcdef';
  36928. var table = new Array(256);
  36929. for (var i = 0; i < 16; ++i) {
  36930. var i16 = i * 16;
  36931. for (var j = 0; j < 16; ++j) {
  36932. table[i16 + j] = alphabet[i] + alphabet[j];
  36933. }
  36934. }
  36935. return table;
  36936. }();
  36937. /***/ }),
  36938. /***/ 8780:
  36939. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  36940. "use strict";
  36941. var GetIntrinsic = __webpack_require__(6893);
  36942. var callBind = __webpack_require__(3862);
  36943. var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf'));
  36944. module.exports = function callBoundIntrinsic(name, allowMissing) {
  36945. var intrinsic = GetIntrinsic(name, !!allowMissing);
  36946. if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
  36947. return callBind(intrinsic);
  36948. }
  36949. return intrinsic;
  36950. };
  36951. /***/ }),
  36952. /***/ 3862:
  36953. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  36954. "use strict";
  36955. var bind = __webpack_require__(5246);
  36956. var GetIntrinsic = __webpack_require__(6893);
  36957. var $apply = GetIntrinsic('%Function.prototype.apply%');
  36958. var $call = GetIntrinsic('%Function.prototype.call%');
  36959. var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
  36960. var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
  36961. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  36962. var $max = GetIntrinsic('%Math.max%');
  36963. if ($defineProperty) {
  36964. try {
  36965. $defineProperty({}, 'a', {
  36966. value: 1
  36967. });
  36968. } catch (e) {
  36969. // IE 8 has a broken defineProperty
  36970. $defineProperty = null;
  36971. }
  36972. }
  36973. module.exports = function callBind(originalFunction) {
  36974. var func = $reflectApply(bind, $call, arguments);
  36975. if ($gOPD && $defineProperty) {
  36976. var desc = $gOPD(func, 'length');
  36977. if (desc.configurable) {
  36978. // original length, plus the receiver, minus any additional arguments (after the receiver)
  36979. $defineProperty(func, 'length', {
  36980. value: 1 + $max(0, originalFunction.length - (arguments.length - 1))
  36981. });
  36982. }
  36983. }
  36984. return func;
  36985. };
  36986. var applyBind = function applyBind() {
  36987. return $reflectApply(bind, $apply, arguments);
  36988. };
  36989. if ($defineProperty) {
  36990. $defineProperty(module.exports, 'apply', {
  36991. value: applyBind
  36992. });
  36993. } else {
  36994. module.exports.apply = applyBind;
  36995. }
  36996. /***/ }),
  36997. /***/ 8842:
  36998. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  36999. var Buffer = (__webpack_require__(9047).Buffer);
  37000. var Transform = (__webpack_require__(4723).Transform);
  37001. var StringDecoder = (__webpack_require__(113)/* .StringDecoder */ .s);
  37002. var inherits = __webpack_require__(376);
  37003. function CipherBase(hashMode) {
  37004. Transform.call(this);
  37005. this.hashMode = typeof hashMode === 'string';
  37006. if (this.hashMode) {
  37007. this[hashMode] = this._finalOrDigest;
  37008. } else {
  37009. this["final"] = this._finalOrDigest;
  37010. }
  37011. if (this._final) {
  37012. this.__final = this._final;
  37013. this._final = null;
  37014. }
  37015. this._decoder = null;
  37016. this._encoding = null;
  37017. }
  37018. inherits(CipherBase, Transform);
  37019. CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
  37020. if (typeof data === 'string') {
  37021. data = Buffer.from(data, inputEnc);
  37022. }
  37023. var outData = this._update(data);
  37024. if (this.hashMode) return this;
  37025. if (outputEnc) {
  37026. outData = this._toString(outData, outputEnc);
  37027. }
  37028. return outData;
  37029. };
  37030. CipherBase.prototype.setAutoPadding = function () {};
  37031. CipherBase.prototype.getAuthTag = function () {
  37032. throw new Error('trying to get auth tag in unsupported state');
  37033. };
  37034. CipherBase.prototype.setAuthTag = function () {
  37035. throw new Error('trying to set auth tag in unsupported state');
  37036. };
  37037. CipherBase.prototype.setAAD = function () {
  37038. throw new Error('trying to set aad in unsupported state');
  37039. };
  37040. CipherBase.prototype._transform = function (data, _, next) {
  37041. var err;
  37042. try {
  37043. if (this.hashMode) {
  37044. this._update(data);
  37045. } else {
  37046. this.push(this._update(data));
  37047. }
  37048. } catch (e) {
  37049. err = e;
  37050. } finally {
  37051. next(err);
  37052. }
  37053. };
  37054. CipherBase.prototype._flush = function (done) {
  37055. var err;
  37056. try {
  37057. this.push(this.__final());
  37058. } catch (e) {
  37059. err = e;
  37060. }
  37061. done(err);
  37062. };
  37063. CipherBase.prototype._finalOrDigest = function (outputEnc) {
  37064. var outData = this.__final() || Buffer.alloc(0);
  37065. if (outputEnc) {
  37066. outData = this._toString(outData, outputEnc, true);
  37067. }
  37068. return outData;
  37069. };
  37070. CipherBase.prototype._toString = function (value, enc, fin) {
  37071. if (!this._decoder) {
  37072. this._decoder = new StringDecoder(enc);
  37073. this._encoding = enc;
  37074. }
  37075. if (this._encoding !== enc) throw new Error('can\'t switch encodings');
  37076. var out = this._decoder.write(value);
  37077. if (fin) {
  37078. out += this._decoder.end();
  37079. }
  37080. return out;
  37081. };
  37082. module.exports = CipherBase;
  37083. /***/ }),
  37084. /***/ 4637:
  37085. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37086. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  37087. var elliptic = __webpack_require__(8333);
  37088. var BN = __webpack_require__(6781);
  37089. module.exports = function createECDH(curve) {
  37090. return new ECDH(curve);
  37091. };
  37092. var aliases = {
  37093. secp256k1: {
  37094. name: 'secp256k1',
  37095. byteLength: 32
  37096. },
  37097. secp224r1: {
  37098. name: 'p224',
  37099. byteLength: 28
  37100. },
  37101. prime256v1: {
  37102. name: 'p256',
  37103. byteLength: 32
  37104. },
  37105. prime192v1: {
  37106. name: 'p192',
  37107. byteLength: 24
  37108. },
  37109. ed25519: {
  37110. name: 'ed25519',
  37111. byteLength: 32
  37112. },
  37113. secp384r1: {
  37114. name: 'p384',
  37115. byteLength: 48
  37116. },
  37117. secp521r1: {
  37118. name: 'p521',
  37119. byteLength: 66
  37120. }
  37121. };
  37122. aliases.p224 = aliases.secp224r1;
  37123. aliases.p256 = aliases.secp256r1 = aliases.prime256v1;
  37124. aliases.p192 = aliases.secp192r1 = aliases.prime192v1;
  37125. aliases.p384 = aliases.secp384r1;
  37126. aliases.p521 = aliases.secp521r1;
  37127. function ECDH(curve) {
  37128. this.curveType = aliases[curve];
  37129. if (!this.curveType) {
  37130. this.curveType = {
  37131. name: curve
  37132. };
  37133. }
  37134. this.curve = new elliptic.ec(this.curveType.name); // eslint-disable-line new-cap
  37135. this.keys = void 0;
  37136. }
  37137. ECDH.prototype.generateKeys = function (enc, format) {
  37138. this.keys = this.curve.genKeyPair();
  37139. return this.getPublicKey(enc, format);
  37140. };
  37141. ECDH.prototype.computeSecret = function (other, inenc, enc) {
  37142. inenc = inenc || 'utf8';
  37143. if (!Buffer.isBuffer(other)) {
  37144. other = new Buffer(other, inenc);
  37145. }
  37146. var otherPub = this.curve.keyFromPublic(other).getPublic();
  37147. var out = otherPub.mul(this.keys.getPrivate()).getX();
  37148. return formatReturnValue(out, enc, this.curveType.byteLength);
  37149. };
  37150. ECDH.prototype.getPublicKey = function (enc, format) {
  37151. var key = this.keys.getPublic(format === 'compressed', true);
  37152. if (format === 'hybrid') {
  37153. if (key[key.length - 1] % 2) {
  37154. key[0] = 7;
  37155. } else {
  37156. key[0] = 6;
  37157. }
  37158. }
  37159. return formatReturnValue(key, enc);
  37160. };
  37161. ECDH.prototype.getPrivateKey = function (enc) {
  37162. return formatReturnValue(this.keys.getPrivate(), enc);
  37163. };
  37164. ECDH.prototype.setPublicKey = function (pub, enc) {
  37165. enc = enc || 'utf8';
  37166. if (!Buffer.isBuffer(pub)) {
  37167. pub = new Buffer(pub, enc);
  37168. }
  37169. this.keys._importPublic(pub);
  37170. return this;
  37171. };
  37172. ECDH.prototype.setPrivateKey = function (priv, enc) {
  37173. enc = enc || 'utf8';
  37174. if (!Buffer.isBuffer(priv)) {
  37175. priv = new Buffer(priv, enc);
  37176. }
  37177. var _priv = new BN(priv);
  37178. _priv = _priv.toString(16);
  37179. this.keys = this.curve.genKeyPair();
  37180. this.keys._importPrivate(_priv);
  37181. return this;
  37182. };
  37183. function formatReturnValue(bn, enc, len) {
  37184. if (!Array.isArray(bn)) {
  37185. bn = bn.toArray();
  37186. }
  37187. var buf = new Buffer(bn);
  37188. if (len && buf.length < len) {
  37189. var zeros = new Buffer(len - buf.length);
  37190. zeros.fill(0);
  37191. buf = Buffer.concat([zeros, buf]);
  37192. }
  37193. if (!enc) {
  37194. return buf;
  37195. } else {
  37196. return buf.toString(enc);
  37197. }
  37198. }
  37199. /***/ }),
  37200. /***/ 8339:
  37201. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37202. "use strict";
  37203. var inherits = __webpack_require__(376);
  37204. var MD5 = __webpack_require__(722);
  37205. var RIPEMD160 = __webpack_require__(8100);
  37206. var sha = __webpack_require__(1806);
  37207. var Base = __webpack_require__(8842);
  37208. function Hash(hash) {
  37209. Base.call(this, 'digest');
  37210. this._hash = hash;
  37211. }
  37212. inherits(Hash, Base);
  37213. Hash.prototype._update = function (data) {
  37214. this._hash.update(data);
  37215. };
  37216. Hash.prototype._final = function () {
  37217. return this._hash.digest();
  37218. };
  37219. module.exports = function createHash(alg) {
  37220. alg = alg.toLowerCase();
  37221. if (alg === 'md5') return new MD5();
  37222. if (alg === 'rmd160' || alg === 'ripemd160') return new RIPEMD160();
  37223. return new Hash(sha(alg));
  37224. };
  37225. /***/ }),
  37226. /***/ 3277:
  37227. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37228. var MD5 = __webpack_require__(722);
  37229. module.exports = function (buffer) {
  37230. return new MD5().update(buffer).digest();
  37231. };
  37232. /***/ }),
  37233. /***/ 8736:
  37234. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37235. "use strict";
  37236. var inherits = __webpack_require__(376);
  37237. var Legacy = __webpack_require__(2912);
  37238. var Base = __webpack_require__(8842);
  37239. var Buffer = (__webpack_require__(9047).Buffer);
  37240. var md5 = __webpack_require__(3277);
  37241. var RIPEMD160 = __webpack_require__(8100);
  37242. var sha = __webpack_require__(1806);
  37243. var ZEROS = Buffer.alloc(128);
  37244. function Hmac(alg, key) {
  37245. Base.call(this, 'digest');
  37246. if (typeof key === 'string') {
  37247. key = Buffer.from(key);
  37248. }
  37249. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  37250. this._alg = alg;
  37251. this._key = key;
  37252. if (key.length > blocksize) {
  37253. var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  37254. key = hash.update(key).digest();
  37255. } else if (key.length < blocksize) {
  37256. key = Buffer.concat([key, ZEROS], blocksize);
  37257. }
  37258. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  37259. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  37260. for (var i = 0; i < blocksize; i++) {
  37261. ipad[i] = key[i] ^ 0x36;
  37262. opad[i] = key[i] ^ 0x5C;
  37263. }
  37264. this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg);
  37265. this._hash.update(ipad);
  37266. }
  37267. inherits(Hmac, Base);
  37268. Hmac.prototype._update = function (data) {
  37269. this._hash.update(data);
  37270. };
  37271. Hmac.prototype._final = function () {
  37272. var h = this._hash.digest();
  37273. var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg);
  37274. return hash.update(this._opad).update(h).digest();
  37275. };
  37276. module.exports = function createHmac(alg, key) {
  37277. alg = alg.toLowerCase();
  37278. if (alg === 'rmd160' || alg === 'ripemd160') {
  37279. return new Hmac('rmd160', key);
  37280. }
  37281. if (alg === 'md5') {
  37282. return new Legacy(md5, key);
  37283. }
  37284. return new Hmac(alg, key);
  37285. };
  37286. /***/ }),
  37287. /***/ 2912:
  37288. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37289. "use strict";
  37290. var inherits = __webpack_require__(376);
  37291. var Buffer = (__webpack_require__(9047).Buffer);
  37292. var Base = __webpack_require__(8842);
  37293. var ZEROS = Buffer.alloc(128);
  37294. var blocksize = 64;
  37295. function Hmac(alg, key) {
  37296. Base.call(this, 'digest');
  37297. if (typeof key === 'string') {
  37298. key = Buffer.from(key);
  37299. }
  37300. this._alg = alg;
  37301. this._key = key;
  37302. if (key.length > blocksize) {
  37303. key = alg(key);
  37304. } else if (key.length < blocksize) {
  37305. key = Buffer.concat([key, ZEROS], blocksize);
  37306. }
  37307. var ipad = this._ipad = Buffer.allocUnsafe(blocksize);
  37308. var opad = this._opad = Buffer.allocUnsafe(blocksize);
  37309. for (var i = 0; i < blocksize; i++) {
  37310. ipad[i] = key[i] ^ 0x36;
  37311. opad[i] = key[i] ^ 0x5C;
  37312. }
  37313. this._hash = [ipad];
  37314. }
  37315. inherits(Hmac, Base);
  37316. Hmac.prototype._update = function (data) {
  37317. this._hash.push(data);
  37318. };
  37319. Hmac.prototype._final = function () {
  37320. var h = this._alg(Buffer.concat(this._hash));
  37321. return this._alg(Buffer.concat([this._opad, h]));
  37322. };
  37323. module.exports = Hmac;
  37324. /***/ }),
  37325. /***/ 462:
  37326. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  37327. "use strict";
  37328. var __webpack_unused_export__;
  37329. exports.O6 = __webpack_unused_export__ = __webpack_unused_export__ = /* unused reexport */ __webpack_require__(5760);
  37330. __webpack_unused_export__ = /* unused reexport */ __webpack_require__(8339);
  37331. __webpack_unused_export__ = /* unused reexport */ __webpack_require__(8736);
  37332. var algos = __webpack_require__(3363);
  37333. var algoKeys = Object.keys(algos);
  37334. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys);
  37335. __webpack_unused_export__ = function () {
  37336. return hashes;
  37337. };
  37338. var p = __webpack_require__(9379);
  37339. __webpack_unused_export__ = p.pbkdf2;
  37340. __webpack_unused_export__ = p.pbkdf2Sync;
  37341. var aes = __webpack_require__(5972);
  37342. __webpack_unused_export__ = aes.Cipher;
  37343. __webpack_unused_export__ = aes.createCipher;
  37344. __webpack_unused_export__ = aes.Cipheriv;
  37345. __webpack_unused_export__ = aes.createCipheriv;
  37346. __webpack_unused_export__ = aes.Decipher;
  37347. __webpack_unused_export__ = aes.createDecipher;
  37348. __webpack_unused_export__ = aes.Decipheriv;
  37349. __webpack_unused_export__ = aes.createDecipheriv;
  37350. __webpack_unused_export__ = aes.getCiphers;
  37351. __webpack_unused_export__ = aes.listCiphers;
  37352. var dh = __webpack_require__(1822);
  37353. __webpack_unused_export__ = dh.DiffieHellmanGroup;
  37354. __webpack_unused_export__ = dh.createDiffieHellmanGroup;
  37355. __webpack_unused_export__ = dh.getDiffieHellman;
  37356. __webpack_unused_export__ = dh.createDiffieHellman;
  37357. __webpack_unused_export__ = dh.DiffieHellman;
  37358. var sign = __webpack_require__(1022);
  37359. __webpack_unused_export__ = sign.createSign;
  37360. __webpack_unused_export__ = sign.Sign;
  37361. __webpack_unused_export__ = sign.createVerify;
  37362. __webpack_unused_export__ = sign.Verify;
  37363. /* unused reexport */ __webpack_require__(4637);
  37364. var publicEncrypt = __webpack_require__(2368);
  37365. __webpack_unused_export__ = publicEncrypt.publicEncrypt;
  37366. __webpack_unused_export__ = publicEncrypt.privateEncrypt;
  37367. __webpack_unused_export__ = publicEncrypt.publicDecrypt;
  37368. __webpack_unused_export__ = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api.
  37369. // ;[
  37370. // 'createCredentials'
  37371. // ].forEach(function (name) {
  37372. // exports[name] = function () {
  37373. // throw new Error([
  37374. // 'sorry, ' + name + ' is not implemented yet',
  37375. // 'we accept pull requests',
  37376. // 'https://github.com/crypto-browserify/crypto-browserify'
  37377. // ].join('\n'))
  37378. // }
  37379. // })
  37380. var rf = __webpack_require__(9301);
  37381. __webpack_unused_export__ = rf.randomFill;
  37382. __webpack_unused_export__ = rf.randomFillSync;
  37383. __webpack_unused_export__ = function () {
  37384. throw new Error(['sorry, createCredentials is not implemented yet', 'we accept pull requests', 'https://github.com/crypto-browserify/crypto-browserify'].join('\n'));
  37385. };
  37386. __webpack_unused_export__ = {
  37387. 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
  37388. 'DH_CHECK_P_NOT_PRIME': 1,
  37389. 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
  37390. 'DH_NOT_SUITABLE_GENERATOR': 8,
  37391. 'NPN_ENABLED': 1,
  37392. 'ALPN_ENABLED': 1,
  37393. 'RSA_PKCS1_PADDING': 1,
  37394. 'RSA_SSLV23_PADDING': 2,
  37395. 'RSA_NO_PADDING': 3,
  37396. 'RSA_PKCS1_OAEP_PADDING': 4,
  37397. 'RSA_X931_PADDING': 5,
  37398. 'RSA_PKCS1_PSS_PADDING': 6,
  37399. 'POINT_CONVERSION_COMPRESSED': 2,
  37400. 'POINT_CONVERSION_UNCOMPRESSED': 4,
  37401. 'POINT_CONVERSION_HYBRID': 6
  37402. };
  37403. /***/ }),
  37404. /***/ 5509:
  37405. /***/ ((module) => {
  37406. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  37407. /**
  37408. * Helpers.
  37409. */
  37410. var s = 1000;
  37411. var m = s * 60;
  37412. var h = m * 60;
  37413. var d = h * 24;
  37414. var w = d * 7;
  37415. var y = d * 365.25;
  37416. /**
  37417. * Parse or format the given `val`.
  37418. *
  37419. * Options:
  37420. *
  37421. * - `long` verbose formatting [false]
  37422. *
  37423. * @param {String|Number} val
  37424. * @param {Object} [options]
  37425. * @throws {Error} throw an error if val is not a non-empty string or a number
  37426. * @return {String|Number}
  37427. * @api public
  37428. */
  37429. module.exports = function (val, options) {
  37430. options = options || {};
  37431. var type = _typeof(val);
  37432. if (type === 'string' && val.length > 0) {
  37433. return parse(val);
  37434. } else if (type === 'number' && isFinite(val)) {
  37435. return options["long"] ? fmtLong(val) : fmtShort(val);
  37436. }
  37437. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
  37438. };
  37439. /**
  37440. * Parse the given `str` and return milliseconds.
  37441. *
  37442. * @param {String} str
  37443. * @return {Number}
  37444. * @api private
  37445. */
  37446. function parse(str) {
  37447. str = String(str);
  37448. if (str.length > 100) {
  37449. return;
  37450. }
  37451. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
  37452. if (!match) {
  37453. return;
  37454. }
  37455. var n = parseFloat(match[1]);
  37456. var type = (match[2] || 'ms').toLowerCase();
  37457. switch (type) {
  37458. case 'years':
  37459. case 'year':
  37460. case 'yrs':
  37461. case 'yr':
  37462. case 'y':
  37463. return n * y;
  37464. case 'weeks':
  37465. case 'week':
  37466. case 'w':
  37467. return n * w;
  37468. case 'days':
  37469. case 'day':
  37470. case 'd':
  37471. return n * d;
  37472. case 'hours':
  37473. case 'hour':
  37474. case 'hrs':
  37475. case 'hr':
  37476. case 'h':
  37477. return n * h;
  37478. case 'minutes':
  37479. case 'minute':
  37480. case 'mins':
  37481. case 'min':
  37482. case 'm':
  37483. return n * m;
  37484. case 'seconds':
  37485. case 'second':
  37486. case 'secs':
  37487. case 'sec':
  37488. case 's':
  37489. return n * s;
  37490. case 'milliseconds':
  37491. case 'millisecond':
  37492. case 'msecs':
  37493. case 'msec':
  37494. case 'ms':
  37495. return n;
  37496. default:
  37497. return undefined;
  37498. }
  37499. }
  37500. /**
  37501. * Short format for `ms`.
  37502. *
  37503. * @param {Number} ms
  37504. * @return {String}
  37505. * @api private
  37506. */
  37507. function fmtShort(ms) {
  37508. var msAbs = Math.abs(ms);
  37509. if (msAbs >= d) {
  37510. return Math.round(ms / d) + 'd';
  37511. }
  37512. if (msAbs >= h) {
  37513. return Math.round(ms / h) + 'h';
  37514. }
  37515. if (msAbs >= m) {
  37516. return Math.round(ms / m) + 'm';
  37517. }
  37518. if (msAbs >= s) {
  37519. return Math.round(ms / s) + 's';
  37520. }
  37521. return ms + 'ms';
  37522. }
  37523. /**
  37524. * Long format for `ms`.
  37525. *
  37526. * @param {Number} ms
  37527. * @return {String}
  37528. * @api private
  37529. */
  37530. function fmtLong(ms) {
  37531. var msAbs = Math.abs(ms);
  37532. if (msAbs >= d) {
  37533. return plural(ms, msAbs, d, 'day');
  37534. }
  37535. if (msAbs >= h) {
  37536. return plural(ms, msAbs, h, 'hour');
  37537. }
  37538. if (msAbs >= m) {
  37539. return plural(ms, msAbs, m, 'minute');
  37540. }
  37541. if (msAbs >= s) {
  37542. return plural(ms, msAbs, s, 'second');
  37543. }
  37544. return ms + ' ms';
  37545. }
  37546. /**
  37547. * Pluralization helper.
  37548. */
  37549. function plural(ms, msAbs, n, name) {
  37550. var isPlural = msAbs >= n * 1.5;
  37551. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  37552. }
  37553. /***/ }),
  37554. /***/ 8801:
  37555. /***/ ((module, exports, __webpack_require__) => {
  37556. /* eslint-env browser */
  37557. /**
  37558. * This is the web browser implementation of `debug()`.
  37559. */
  37560. exports.formatArgs = formatArgs;
  37561. exports.save = save;
  37562. exports.load = load;
  37563. exports.useColors = useColors;
  37564. exports.storage = localstorage();
  37565. exports.destroy = function () {
  37566. var warned = false;
  37567. return function () {
  37568. if (!warned) {
  37569. warned = true;
  37570. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  37571. }
  37572. };
  37573. }();
  37574. /**
  37575. * Colors.
  37576. */
  37577. exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
  37578. /**
  37579. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  37580. * and the Firebug extension (any Firefox version) are known
  37581. * to support "%c" CSS customizations.
  37582. *
  37583. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  37584. */
  37585. // eslint-disable-next-line complexity
  37586. function useColors() {
  37587. // NB: In an Electron preload script, document will be defined but not fully
  37588. // initialized. Since we know we're in Chrome, we'll just detect this case
  37589. // explicitly
  37590. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  37591. return true;
  37592. } // Internet Explorer and Edge do not support colors.
  37593. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  37594. return false;
  37595. } // Is webkit? http://stackoverflow.com/a/16459606/376773
  37596. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  37597. return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
  37598. typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
  37599. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  37600. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
  37601. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  37602. }
  37603. /**
  37604. * Colorize log arguments if enabled.
  37605. *
  37606. * @api public
  37607. */
  37608. function formatArgs(args) {
  37609. args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
  37610. if (!this.useColors) {
  37611. return;
  37612. }
  37613. var c = 'color: ' + this.color;
  37614. args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
  37615. // arguments passed either before or after the %c, so we need to
  37616. // figure out the correct index to insert the CSS into
  37617. var index = 0;
  37618. var lastC = 0;
  37619. args[0].replace(/%[a-zA-Z%]/g, function (match) {
  37620. if (match === '%%') {
  37621. return;
  37622. }
  37623. index++;
  37624. if (match === '%c') {
  37625. // We only are interested in the *last* %c
  37626. // (the user may have provided their own)
  37627. lastC = index;
  37628. }
  37629. });
  37630. args.splice(lastC, 0, c);
  37631. }
  37632. /**
  37633. * Invokes `console.debug()` when available.
  37634. * No-op when `console.debug` is not a "function".
  37635. * If `console.debug` is not available, falls back
  37636. * to `console.log`.
  37637. *
  37638. * @api public
  37639. */
  37640. exports.log = console.debug || console.log || function () {};
  37641. /**
  37642. * Save `namespaces`.
  37643. *
  37644. * @param {String} namespaces
  37645. * @api private
  37646. */
  37647. function save(namespaces) {
  37648. try {
  37649. if (namespaces) {
  37650. exports.storage.setItem('debug', namespaces);
  37651. } else {
  37652. exports.storage.removeItem('debug');
  37653. }
  37654. } catch (error) {// Swallow
  37655. // XXX (@Qix-) should we be logging these?
  37656. }
  37657. }
  37658. /**
  37659. * Load `namespaces`.
  37660. *
  37661. * @return {String} returns the previously persisted debug modes
  37662. * @api private
  37663. */
  37664. function load() {
  37665. var r;
  37666. try {
  37667. r = exports.storage.getItem('debug');
  37668. } catch (error) {// Swallow
  37669. // XXX (@Qix-) should we be logging these?
  37670. } // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  37671. if (!r && typeof ({env:{}}) !== 'undefined' && 'env' in ({env:{}})) {
  37672. r = ({env:{}}).env.DEBUG;
  37673. }
  37674. return r;
  37675. }
  37676. /**
  37677. * Localstorage attempts to return the localstorage.
  37678. *
  37679. * This is necessary because safari throws
  37680. * when a user disables cookies/localstorage
  37681. * and you attempt to access it.
  37682. *
  37683. * @return {LocalStorage}
  37684. * @api private
  37685. */
  37686. function localstorage() {
  37687. try {
  37688. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  37689. // The Browser also has localStorage in the global context.
  37690. return localStorage;
  37691. } catch (error) {// Swallow
  37692. // XXX (@Qix-) should we be logging these?
  37693. }
  37694. }
  37695. module.exports = __webpack_require__(5331)(exports);
  37696. var formatters = module.exports.formatters;
  37697. /**
  37698. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  37699. */
  37700. formatters.j = function (v) {
  37701. try {
  37702. return JSON.stringify(v);
  37703. } catch (error) {
  37704. return '[UnexpectedJSONParseError]: ' + error.message;
  37705. }
  37706. };
  37707. /***/ }),
  37708. /***/ 5331:
  37709. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37710. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  37711. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  37712. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  37713. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  37714. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  37715. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  37716. /**
  37717. * This is the common logic for both the Node.js and web browser
  37718. * implementations of `debug()`.
  37719. */
  37720. function setup(env) {
  37721. createDebug.debug = createDebug;
  37722. createDebug["default"] = createDebug;
  37723. createDebug.coerce = coerce;
  37724. createDebug.disable = disable;
  37725. createDebug.enable = enable;
  37726. createDebug.enabled = enabled;
  37727. createDebug.humanize = __webpack_require__(5509);
  37728. createDebug.destroy = destroy;
  37729. Object.keys(env).forEach(function (key) {
  37730. createDebug[key] = env[key];
  37731. });
  37732. /**
  37733. * The currently active debug mode names, and names to skip.
  37734. */
  37735. createDebug.names = [];
  37736. createDebug.skips = [];
  37737. /**
  37738. * Map of special "%n" handling functions, for the debug "format" argument.
  37739. *
  37740. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  37741. */
  37742. createDebug.formatters = {};
  37743. /**
  37744. * Selects a color for a debug namespace
  37745. * @param {String} namespace The namespace string for the debug instance to be colored
  37746. * @return {Number|String} An ANSI color code for the given namespace
  37747. * @api private
  37748. */
  37749. function selectColor(namespace) {
  37750. var hash = 0;
  37751. for (var i = 0; i < namespace.length; i++) {
  37752. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  37753. hash |= 0; // Convert to 32bit integer
  37754. }
  37755. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  37756. }
  37757. createDebug.selectColor = selectColor;
  37758. /**
  37759. * Create a debugger with the given `namespace`.
  37760. *
  37761. * @param {String} namespace
  37762. * @return {Function}
  37763. * @api public
  37764. */
  37765. function createDebug(namespace) {
  37766. var prevTime;
  37767. var enableOverride = null;
  37768. var namespacesCache;
  37769. var enabledCache;
  37770. function debug() {
  37771. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  37772. args[_key] = arguments[_key];
  37773. }
  37774. // Disabled?
  37775. if (!debug.enabled) {
  37776. return;
  37777. }
  37778. var self = debug; // Set `diff` timestamp
  37779. var curr = Number(new Date());
  37780. var ms = curr - (prevTime || curr);
  37781. self.diff = ms;
  37782. self.prev = prevTime;
  37783. self.curr = curr;
  37784. prevTime = curr;
  37785. args[0] = createDebug.coerce(args[0]);
  37786. if (typeof args[0] !== 'string') {
  37787. // Anything else let's inspect with %O
  37788. args.unshift('%O');
  37789. } // Apply any `formatters` transformations
  37790. var index = 0;
  37791. args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
  37792. // If we encounter an escaped % then don't increase the array index
  37793. if (match === '%%') {
  37794. return '%';
  37795. }
  37796. index++;
  37797. var formatter = createDebug.formatters[format];
  37798. if (typeof formatter === 'function') {
  37799. var val = args[index];
  37800. match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
  37801. args.splice(index, 1);
  37802. index--;
  37803. }
  37804. return match;
  37805. }); // Apply env-specific formatting (colors, etc.)
  37806. createDebug.formatArgs.call(self, args);
  37807. var logFn = self.log || createDebug.log;
  37808. logFn.apply(self, args);
  37809. }
  37810. debug.namespace = namespace;
  37811. debug.useColors = createDebug.useColors();
  37812. debug.color = createDebug.selectColor(namespace);
  37813. debug.extend = extend;
  37814. debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
  37815. Object.defineProperty(debug, 'enabled', {
  37816. enumerable: true,
  37817. configurable: false,
  37818. get: function get() {
  37819. if (enableOverride !== null) {
  37820. return enableOverride;
  37821. }
  37822. if (namespacesCache !== createDebug.namespaces) {
  37823. namespacesCache = createDebug.namespaces;
  37824. enabledCache = createDebug.enabled(namespace);
  37825. }
  37826. return enabledCache;
  37827. },
  37828. set: function set(v) {
  37829. enableOverride = v;
  37830. }
  37831. }); // Env-specific initialization logic for debug instances
  37832. if (typeof createDebug.init === 'function') {
  37833. createDebug.init(debug);
  37834. }
  37835. return debug;
  37836. }
  37837. function extend(namespace, delimiter) {
  37838. var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  37839. newDebug.log = this.log;
  37840. return newDebug;
  37841. }
  37842. /**
  37843. * Enables a debug mode by namespaces. This can include modes
  37844. * separated by a colon and wildcards.
  37845. *
  37846. * @param {String} namespaces
  37847. * @api public
  37848. */
  37849. function enable(namespaces) {
  37850. createDebug.save(namespaces);
  37851. createDebug.namespaces = namespaces;
  37852. createDebug.names = [];
  37853. createDebug.skips = [];
  37854. var i;
  37855. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  37856. var len = split.length;
  37857. for (i = 0; i < len; i++) {
  37858. if (!split[i]) {
  37859. // ignore empty strings
  37860. continue;
  37861. }
  37862. namespaces = split[i].replace(/\*/g, '.*?');
  37863. if (namespaces[0] === '-') {
  37864. createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
  37865. } else {
  37866. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  37867. }
  37868. }
  37869. }
  37870. /**
  37871. * Disable debug output.
  37872. *
  37873. * @return {String} namespaces
  37874. * @api public
  37875. */
  37876. function disable() {
  37877. var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
  37878. return '-' + namespace;
  37879. }))).join(',');
  37880. createDebug.enable('');
  37881. return namespaces;
  37882. }
  37883. /**
  37884. * Returns true if the given mode name is enabled, false otherwise.
  37885. *
  37886. * @param {String} name
  37887. * @return {Boolean}
  37888. * @api public
  37889. */
  37890. function enabled(name) {
  37891. if (name[name.length - 1] === '*') {
  37892. return true;
  37893. }
  37894. var i;
  37895. var len;
  37896. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  37897. if (createDebug.skips[i].test(name)) {
  37898. return false;
  37899. }
  37900. }
  37901. for (i = 0, len = createDebug.names.length; i < len; i++) {
  37902. if (createDebug.names[i].test(name)) {
  37903. return true;
  37904. }
  37905. }
  37906. return false;
  37907. }
  37908. /**
  37909. * Convert regexp to namespace
  37910. *
  37911. * @param {RegExp} regxep
  37912. * @return {String} namespace
  37913. * @api private
  37914. */
  37915. function toNamespace(regexp) {
  37916. return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
  37917. }
  37918. /**
  37919. * Coerce `val`.
  37920. *
  37921. * @param {Mixed} val
  37922. * @return {Mixed}
  37923. * @api private
  37924. */
  37925. function coerce(val) {
  37926. if (val instanceof Error) {
  37927. return val.stack || val.message;
  37928. }
  37929. return val;
  37930. }
  37931. /**
  37932. * XXX DO NOT USE. This is a temporary stub function.
  37933. * XXX It WILL be removed in the next major release.
  37934. */
  37935. function destroy() {
  37936. console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
  37937. }
  37938. createDebug.enable(createDebug.load());
  37939. return createDebug;
  37940. }
  37941. module.exports = setup;
  37942. /***/ }),
  37943. /***/ 7921:
  37944. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  37945. "use strict";
  37946. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  37947. var keys = __webpack_require__(3818);
  37948. var hasSymbols = typeof Symbol === 'function' && _typeof(Symbol('foo')) === 'symbol';
  37949. var toStr = Object.prototype.toString;
  37950. var concat = Array.prototype.concat;
  37951. var origDefineProperty = Object.defineProperty;
  37952. var isFunction = function isFunction(fn) {
  37953. return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
  37954. };
  37955. var hasPropertyDescriptors = __webpack_require__(2579)();
  37956. var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
  37957. var defineProperty = function defineProperty(object, name, value, predicate) {
  37958. if (name in object && (!isFunction(predicate) || !predicate())) {
  37959. return;
  37960. }
  37961. if (supportsDescriptors) {
  37962. origDefineProperty(object, name, {
  37963. configurable: true,
  37964. enumerable: false,
  37965. value: value,
  37966. writable: true
  37967. });
  37968. } else {
  37969. object[name] = value; // eslint-disable-line no-param-reassign
  37970. }
  37971. };
  37972. var defineProperties = function defineProperties(object, map) {
  37973. var predicates = arguments.length > 2 ? arguments[2] : {};
  37974. var props = keys(map);
  37975. if (hasSymbols) {
  37976. props = concat.call(props, Object.getOwnPropertySymbols(map));
  37977. }
  37978. for (var i = 0; i < props.length; i += 1) {
  37979. defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
  37980. }
  37981. };
  37982. defineProperties.supportsDescriptors = !!supportsDescriptors;
  37983. module.exports = defineProperties;
  37984. /***/ }),
  37985. /***/ 167:
  37986. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  37987. "use strict";
  37988. exports.utils = __webpack_require__(5061);
  37989. exports.Cipher = __webpack_require__(7499);
  37990. exports.DES = __webpack_require__(9484);
  37991. exports.CBC = __webpack_require__(8254);
  37992. exports.EDE = __webpack_require__(5573);
  37993. /***/ }),
  37994. /***/ 8254:
  37995. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  37996. "use strict";
  37997. var assert = __webpack_require__(1130);
  37998. var inherits = __webpack_require__(376);
  37999. var proto = {};
  38000. function CBCState(iv) {
  38001. assert.equal(iv.length, 8, 'Invalid IV length');
  38002. this.iv = new Array(8);
  38003. for (var i = 0; i < this.iv.length; i++) {
  38004. this.iv[i] = iv[i];
  38005. }
  38006. }
  38007. function instantiate(Base) {
  38008. function CBC(options) {
  38009. Base.call(this, options);
  38010. this._cbcInit();
  38011. }
  38012. inherits(CBC, Base);
  38013. var keys = Object.keys(proto);
  38014. for (var i = 0; i < keys.length; i++) {
  38015. var key = keys[i];
  38016. CBC.prototype[key] = proto[key];
  38017. }
  38018. CBC.create = function create(options) {
  38019. return new CBC(options);
  38020. };
  38021. return CBC;
  38022. }
  38023. exports.instantiate = instantiate;
  38024. proto._cbcInit = function _cbcInit() {
  38025. var state = new CBCState(this.options.iv);
  38026. this._cbcState = state;
  38027. };
  38028. proto._update = function _update(inp, inOff, out, outOff) {
  38029. var state = this._cbcState;
  38030. var superProto = this.constructor.super_.prototype;
  38031. var iv = state.iv;
  38032. if (this.type === 'encrypt') {
  38033. for (var i = 0; i < this.blockSize; i++) {
  38034. iv[i] ^= inp[inOff + i];
  38035. }
  38036. superProto._update.call(this, iv, 0, out, outOff);
  38037. for (var i = 0; i < this.blockSize; i++) {
  38038. iv[i] = out[outOff + i];
  38039. }
  38040. } else {
  38041. superProto._update.call(this, inp, inOff, out, outOff);
  38042. for (var i = 0; i < this.blockSize; i++) {
  38043. out[outOff + i] ^= iv[i];
  38044. }
  38045. for (var i = 0; i < this.blockSize; i++) {
  38046. iv[i] = inp[inOff + i];
  38047. }
  38048. }
  38049. };
  38050. /***/ }),
  38051. /***/ 7499:
  38052. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38053. "use strict";
  38054. var assert = __webpack_require__(1130);
  38055. function Cipher(options) {
  38056. this.options = options;
  38057. this.type = this.options.type;
  38058. this.blockSize = 8;
  38059. this._init();
  38060. this.buffer = new Array(this.blockSize);
  38061. this.bufferOff = 0;
  38062. }
  38063. module.exports = Cipher;
  38064. Cipher.prototype._init = function _init() {// Might be overrided
  38065. };
  38066. Cipher.prototype.update = function update(data) {
  38067. if (data.length === 0) return [];
  38068. if (this.type === 'decrypt') return this._updateDecrypt(data);else return this._updateEncrypt(data);
  38069. };
  38070. Cipher.prototype._buffer = function _buffer(data, off) {
  38071. // Append data to buffer
  38072. var min = Math.min(this.buffer.length - this.bufferOff, data.length - off);
  38073. for (var i = 0; i < min; i++) {
  38074. this.buffer[this.bufferOff + i] = data[off + i];
  38075. }
  38076. this.bufferOff += min; // Shift next
  38077. return min;
  38078. };
  38079. Cipher.prototype._flushBuffer = function _flushBuffer(out, off) {
  38080. this._update(this.buffer, 0, out, off);
  38081. this.bufferOff = 0;
  38082. return this.blockSize;
  38083. };
  38084. Cipher.prototype._updateEncrypt = function _updateEncrypt(data) {
  38085. var inputOff = 0;
  38086. var outputOff = 0;
  38087. var count = (this.bufferOff + data.length) / this.blockSize | 0;
  38088. var out = new Array(count * this.blockSize);
  38089. if (this.bufferOff !== 0) {
  38090. inputOff += this._buffer(data, inputOff);
  38091. if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff);
  38092. } // Write blocks
  38093. var max = data.length - (data.length - inputOff) % this.blockSize;
  38094. for (; inputOff < max; inputOff += this.blockSize) {
  38095. this._update(data, inputOff, out, outputOff);
  38096. outputOff += this.blockSize;
  38097. } // Queue rest
  38098. for (; inputOff < data.length; inputOff++, this.bufferOff++) {
  38099. this.buffer[this.bufferOff] = data[inputOff];
  38100. }
  38101. return out;
  38102. };
  38103. Cipher.prototype._updateDecrypt = function _updateDecrypt(data) {
  38104. var inputOff = 0;
  38105. var outputOff = 0;
  38106. var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1;
  38107. var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal
  38108. for (; count > 0; count--) {
  38109. inputOff += this._buffer(data, inputOff);
  38110. outputOff += this._flushBuffer(out, outputOff);
  38111. } // Buffer rest of the input
  38112. inputOff += this._buffer(data, inputOff);
  38113. return out;
  38114. };
  38115. Cipher.prototype["final"] = function _final(buffer) {
  38116. var first;
  38117. if (buffer) first = this.update(buffer);
  38118. var last;
  38119. if (this.type === 'encrypt') last = this._finalEncrypt();else last = this._finalDecrypt();
  38120. if (first) return first.concat(last);else return last;
  38121. };
  38122. Cipher.prototype._pad = function _pad(buffer, off) {
  38123. if (off === 0) return false;
  38124. while (off < buffer.length) {
  38125. buffer[off++] = 0;
  38126. }
  38127. return true;
  38128. };
  38129. Cipher.prototype._finalEncrypt = function _finalEncrypt() {
  38130. if (!this._pad(this.buffer, this.bufferOff)) return [];
  38131. var out = new Array(this.blockSize);
  38132. this._update(this.buffer, 0, out, 0);
  38133. return out;
  38134. };
  38135. Cipher.prototype._unpad = function _unpad(buffer) {
  38136. return buffer;
  38137. };
  38138. Cipher.prototype._finalDecrypt = function _finalDecrypt() {
  38139. assert.equal(this.bufferOff, this.blockSize, 'Not enough data to decrypt');
  38140. var out = new Array(this.blockSize);
  38141. this._flushBuffer(out, 0);
  38142. return this._unpad(out);
  38143. };
  38144. /***/ }),
  38145. /***/ 9484:
  38146. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38147. "use strict";
  38148. var assert = __webpack_require__(1130);
  38149. var inherits = __webpack_require__(376);
  38150. var utils = __webpack_require__(5061);
  38151. var Cipher = __webpack_require__(7499);
  38152. function DESState() {
  38153. this.tmp = new Array(2);
  38154. this.keys = null;
  38155. }
  38156. function DES(options) {
  38157. Cipher.call(this, options);
  38158. var state = new DESState();
  38159. this._desState = state;
  38160. this.deriveKeys(state, options.key);
  38161. }
  38162. inherits(DES, Cipher);
  38163. module.exports = DES;
  38164. DES.create = function create(options) {
  38165. return new DES(options);
  38166. };
  38167. var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1];
  38168. DES.prototype.deriveKeys = function deriveKeys(state, key) {
  38169. state.keys = new Array(16 * 2);
  38170. assert.equal(key.length, this.blockSize, 'Invalid key length');
  38171. var kL = utils.readUInt32BE(key, 0);
  38172. var kR = utils.readUInt32BE(key, 4);
  38173. utils.pc1(kL, kR, state.tmp, 0);
  38174. kL = state.tmp[0];
  38175. kR = state.tmp[1];
  38176. for (var i = 0; i < state.keys.length; i += 2) {
  38177. var shift = shiftTable[i >>> 1];
  38178. kL = utils.r28shl(kL, shift);
  38179. kR = utils.r28shl(kR, shift);
  38180. utils.pc2(kL, kR, state.keys, i);
  38181. }
  38182. };
  38183. DES.prototype._update = function _update(inp, inOff, out, outOff) {
  38184. var state = this._desState;
  38185. var l = utils.readUInt32BE(inp, inOff);
  38186. var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation
  38187. utils.ip(l, r, state.tmp, 0);
  38188. l = state.tmp[0];
  38189. r = state.tmp[1];
  38190. if (this.type === 'encrypt') this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0);
  38191. l = state.tmp[0];
  38192. r = state.tmp[1];
  38193. utils.writeUInt32BE(out, l, outOff);
  38194. utils.writeUInt32BE(out, r, outOff + 4);
  38195. };
  38196. DES.prototype._pad = function _pad(buffer, off) {
  38197. var value = buffer.length - off;
  38198. for (var i = off; i < buffer.length; i++) {
  38199. buffer[i] = value;
  38200. }
  38201. return true;
  38202. };
  38203. DES.prototype._unpad = function _unpad(buffer) {
  38204. var pad = buffer[buffer.length - 1];
  38205. for (var i = buffer.length - pad; i < buffer.length; i++) {
  38206. assert.equal(buffer[i], pad);
  38207. }
  38208. return buffer.slice(0, buffer.length - pad);
  38209. };
  38210. DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) {
  38211. var l = lStart;
  38212. var r = rStart; // Apply f() x16 times
  38213. for (var i = 0; i < state.keys.length; i += 2) {
  38214. var keyL = state.keys[i];
  38215. var keyR = state.keys[i + 1]; // f(r, k)
  38216. utils.expand(r, state.tmp, 0);
  38217. keyL ^= state.tmp[0];
  38218. keyR ^= state.tmp[1];
  38219. var s = utils.substitute(keyL, keyR);
  38220. var f = utils.permute(s);
  38221. var t = r;
  38222. r = (l ^ f) >>> 0;
  38223. l = t;
  38224. } // Reverse Initial Permutation
  38225. utils.rip(r, l, out, off);
  38226. };
  38227. DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) {
  38228. var l = rStart;
  38229. var r = lStart; // Apply f() x16 times
  38230. for (var i = state.keys.length - 2; i >= 0; i -= 2) {
  38231. var keyL = state.keys[i];
  38232. var keyR = state.keys[i + 1]; // f(r, k)
  38233. utils.expand(l, state.tmp, 0);
  38234. keyL ^= state.tmp[0];
  38235. keyR ^= state.tmp[1];
  38236. var s = utils.substitute(keyL, keyR);
  38237. var f = utils.permute(s);
  38238. var t = l;
  38239. l = (r ^ f) >>> 0;
  38240. r = t;
  38241. } // Reverse Initial Permutation
  38242. utils.rip(l, r, out, off);
  38243. };
  38244. /***/ }),
  38245. /***/ 5573:
  38246. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38247. "use strict";
  38248. var assert = __webpack_require__(1130);
  38249. var inherits = __webpack_require__(376);
  38250. var Cipher = __webpack_require__(7499);
  38251. var DES = __webpack_require__(9484);
  38252. function EDEState(type, key) {
  38253. assert.equal(key.length, 24, 'Invalid key length');
  38254. var k1 = key.slice(0, 8);
  38255. var k2 = key.slice(8, 16);
  38256. var k3 = key.slice(16, 24);
  38257. if (type === 'encrypt') {
  38258. this.ciphers = [DES.create({
  38259. type: 'encrypt',
  38260. key: k1
  38261. }), DES.create({
  38262. type: 'decrypt',
  38263. key: k2
  38264. }), DES.create({
  38265. type: 'encrypt',
  38266. key: k3
  38267. })];
  38268. } else {
  38269. this.ciphers = [DES.create({
  38270. type: 'decrypt',
  38271. key: k3
  38272. }), DES.create({
  38273. type: 'encrypt',
  38274. key: k2
  38275. }), DES.create({
  38276. type: 'decrypt',
  38277. key: k1
  38278. })];
  38279. }
  38280. }
  38281. function EDE(options) {
  38282. Cipher.call(this, options);
  38283. var state = new EDEState(this.type, this.options.key);
  38284. this._edeState = state;
  38285. }
  38286. inherits(EDE, Cipher);
  38287. module.exports = EDE;
  38288. EDE.create = function create(options) {
  38289. return new EDE(options);
  38290. };
  38291. EDE.prototype._update = function _update(inp, inOff, out, outOff) {
  38292. var state = this._edeState;
  38293. state.ciphers[0]._update(inp, inOff, out, outOff);
  38294. state.ciphers[1]._update(out, outOff, out, outOff);
  38295. state.ciphers[2]._update(out, outOff, out, outOff);
  38296. };
  38297. EDE.prototype._pad = DES.prototype._pad;
  38298. EDE.prototype._unpad = DES.prototype._unpad;
  38299. /***/ }),
  38300. /***/ 5061:
  38301. /***/ ((__unused_webpack_module, exports) => {
  38302. "use strict";
  38303. exports.readUInt32BE = function readUInt32BE(bytes, off) {
  38304. var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off];
  38305. return res >>> 0;
  38306. };
  38307. exports.writeUInt32BE = function writeUInt32BE(bytes, value, off) {
  38308. bytes[0 + off] = value >>> 24;
  38309. bytes[1 + off] = value >>> 16 & 0xff;
  38310. bytes[2 + off] = value >>> 8 & 0xff;
  38311. bytes[3 + off] = value & 0xff;
  38312. };
  38313. exports.ip = function ip(inL, inR, out, off) {
  38314. var outL = 0;
  38315. var outR = 0;
  38316. for (var i = 6; i >= 0; i -= 2) {
  38317. for (var j = 0; j <= 24; j += 8) {
  38318. outL <<= 1;
  38319. outL |= inR >>> j + i & 1;
  38320. }
  38321. for (var j = 0; j <= 24; j += 8) {
  38322. outL <<= 1;
  38323. outL |= inL >>> j + i & 1;
  38324. }
  38325. }
  38326. for (var i = 6; i >= 0; i -= 2) {
  38327. for (var j = 1; j <= 25; j += 8) {
  38328. outR <<= 1;
  38329. outR |= inR >>> j + i & 1;
  38330. }
  38331. for (var j = 1; j <= 25; j += 8) {
  38332. outR <<= 1;
  38333. outR |= inL >>> j + i & 1;
  38334. }
  38335. }
  38336. out[off + 0] = outL >>> 0;
  38337. out[off + 1] = outR >>> 0;
  38338. };
  38339. exports.rip = function rip(inL, inR, out, off) {
  38340. var outL = 0;
  38341. var outR = 0;
  38342. for (var i = 0; i < 4; i++) {
  38343. for (var j = 24; j >= 0; j -= 8) {
  38344. outL <<= 1;
  38345. outL |= inR >>> j + i & 1;
  38346. outL <<= 1;
  38347. outL |= inL >>> j + i & 1;
  38348. }
  38349. }
  38350. for (var i = 4; i < 8; i++) {
  38351. for (var j = 24; j >= 0; j -= 8) {
  38352. outR <<= 1;
  38353. outR |= inR >>> j + i & 1;
  38354. outR <<= 1;
  38355. outR |= inL >>> j + i & 1;
  38356. }
  38357. }
  38358. out[off + 0] = outL >>> 0;
  38359. out[off + 1] = outR >>> 0;
  38360. };
  38361. exports.pc1 = function pc1(inL, inR, out, off) {
  38362. var outL = 0;
  38363. var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63
  38364. // 6, 14, 22, 30, 39, 47, 55, 63
  38365. // 5, 13, 21, 29, 39, 47, 55, 63
  38366. // 4, 12, 20, 28
  38367. for (var i = 7; i >= 5; i--) {
  38368. for (var j = 0; j <= 24; j += 8) {
  38369. outL <<= 1;
  38370. outL |= inR >> j + i & 1;
  38371. }
  38372. for (var j = 0; j <= 24; j += 8) {
  38373. outL <<= 1;
  38374. outL |= inL >> j + i & 1;
  38375. }
  38376. }
  38377. for (var j = 0; j <= 24; j += 8) {
  38378. outL <<= 1;
  38379. outL |= inR >> j + i & 1;
  38380. } // 1, 9, 17, 25, 33, 41, 49, 57
  38381. // 2, 10, 18, 26, 34, 42, 50, 58
  38382. // 3, 11, 19, 27, 35, 43, 51, 59
  38383. // 36, 44, 52, 60
  38384. for (var i = 1; i <= 3; i++) {
  38385. for (var j = 0; j <= 24; j += 8) {
  38386. outR <<= 1;
  38387. outR |= inR >> j + i & 1;
  38388. }
  38389. for (var j = 0; j <= 24; j += 8) {
  38390. outR <<= 1;
  38391. outR |= inL >> j + i & 1;
  38392. }
  38393. }
  38394. for (var j = 0; j <= 24; j += 8) {
  38395. outR <<= 1;
  38396. outR |= inL >> j + i & 1;
  38397. }
  38398. out[off + 0] = outL >>> 0;
  38399. out[off + 1] = outR >>> 0;
  38400. };
  38401. exports.r28shl = function r28shl(num, shift) {
  38402. return num << shift & 0xfffffff | num >>> 28 - shift;
  38403. };
  38404. var pc2table = [// inL => outL
  38405. 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR
  38406. 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24];
  38407. exports.pc2 = function pc2(inL, inR, out, off) {
  38408. var outL = 0;
  38409. var outR = 0;
  38410. var len = pc2table.length >>> 1;
  38411. for (var i = 0; i < len; i++) {
  38412. outL <<= 1;
  38413. outL |= inL >>> pc2table[i] & 0x1;
  38414. }
  38415. for (var i = len; i < pc2table.length; i++) {
  38416. outR <<= 1;
  38417. outR |= inR >>> pc2table[i] & 0x1;
  38418. }
  38419. out[off + 0] = outL >>> 0;
  38420. out[off + 1] = outR >>> 0;
  38421. };
  38422. exports.expand = function expand(r, out, off) {
  38423. var outL = 0;
  38424. var outR = 0;
  38425. outL = (r & 1) << 5 | r >>> 27;
  38426. for (var i = 23; i >= 15; i -= 4) {
  38427. outL <<= 6;
  38428. outL |= r >>> i & 0x3f;
  38429. }
  38430. for (var i = 11; i >= 3; i -= 4) {
  38431. outR |= r >>> i & 0x3f;
  38432. outR <<= 6;
  38433. }
  38434. outR |= (r & 0x1f) << 1 | r >>> 31;
  38435. out[off + 0] = outL >>> 0;
  38436. out[off + 1] = outR >>> 0;
  38437. };
  38438. var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11];
  38439. exports.substitute = function substitute(inL, inR) {
  38440. var out = 0;
  38441. for (var i = 0; i < 4; i++) {
  38442. var b = inL >>> 18 - i * 6 & 0x3f;
  38443. var sb = sTable[i * 0x40 + b];
  38444. out <<= 4;
  38445. out |= sb;
  38446. }
  38447. for (var i = 0; i < 4; i++) {
  38448. var b = inR >>> 18 - i * 6 & 0x3f;
  38449. var sb = sTable[4 * 0x40 + i * 0x40 + b];
  38450. out <<= 4;
  38451. out |= sb;
  38452. }
  38453. return out >>> 0;
  38454. };
  38455. var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7];
  38456. exports.permute = function permute(num) {
  38457. var out = 0;
  38458. for (var i = 0; i < permuteTable.length; i++) {
  38459. out <<= 1;
  38460. out |= num >>> permuteTable[i] & 0x1;
  38461. }
  38462. return out >>> 0;
  38463. };
  38464. exports.padSplit = function padSplit(num, size, group) {
  38465. var str = num.toString(2);
  38466. while (str.length < size) {
  38467. str = '0' + str;
  38468. }
  38469. var out = [];
  38470. for (var i = 0; i < size; i += group) {
  38471. out.push(str.slice(i, i + group));
  38472. }
  38473. return out.join(' ');
  38474. };
  38475. /***/ }),
  38476. /***/ 1822:
  38477. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  38478. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  38479. var generatePrime = __webpack_require__(2227);
  38480. var primes = __webpack_require__(9799);
  38481. var DH = __webpack_require__(6951);
  38482. function getDiffieHellman(mod) {
  38483. var prime = new Buffer(primes[mod].prime, 'hex');
  38484. var gen = new Buffer(primes[mod].gen, 'hex');
  38485. return new DH(prime, gen);
  38486. }
  38487. var ENCODINGS = {
  38488. 'binary': true,
  38489. 'hex': true,
  38490. 'base64': true
  38491. };
  38492. function createDiffieHellman(prime, enc, generator, genc) {
  38493. if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) {
  38494. return createDiffieHellman(prime, 'binary', enc, generator);
  38495. }
  38496. enc = enc || 'binary';
  38497. genc = genc || 'binary';
  38498. generator = generator || new Buffer([2]);
  38499. if (!Buffer.isBuffer(generator)) {
  38500. generator = new Buffer(generator, genc);
  38501. }
  38502. if (typeof prime === 'number') {
  38503. return new DH(generatePrime(prime, generator), generator, true);
  38504. }
  38505. if (!Buffer.isBuffer(prime)) {
  38506. prime = new Buffer(prime, enc);
  38507. }
  38508. return new DH(prime, generator, true);
  38509. }
  38510. exports.DiffieHellmanGroup = exports.createDiffieHellmanGroup = exports.getDiffieHellman = getDiffieHellman;
  38511. exports.createDiffieHellman = exports.DiffieHellman = createDiffieHellman;
  38512. /***/ }),
  38513. /***/ 6951:
  38514. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38515. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  38516. var BN = __webpack_require__(6781);
  38517. var MillerRabin = __webpack_require__(9318);
  38518. var millerRabin = new MillerRabin();
  38519. var TWENTYFOUR = new BN(24);
  38520. var ELEVEN = new BN(11);
  38521. var TEN = new BN(10);
  38522. var THREE = new BN(3);
  38523. var SEVEN = new BN(7);
  38524. var primes = __webpack_require__(2227);
  38525. var randomBytes = __webpack_require__(5760);
  38526. module.exports = DH;
  38527. function setPublicKey(pub, enc) {
  38528. enc = enc || 'utf8';
  38529. if (!Buffer.isBuffer(pub)) {
  38530. pub = new Buffer(pub, enc);
  38531. }
  38532. this._pub = new BN(pub);
  38533. return this;
  38534. }
  38535. function setPrivateKey(priv, enc) {
  38536. enc = enc || 'utf8';
  38537. if (!Buffer.isBuffer(priv)) {
  38538. priv = new Buffer(priv, enc);
  38539. }
  38540. this._priv = new BN(priv);
  38541. return this;
  38542. }
  38543. var primeCache = {};
  38544. function checkPrime(prime, generator) {
  38545. var gen = generator.toString('hex');
  38546. var hex = [gen, prime.toString(16)].join('_');
  38547. if (hex in primeCache) {
  38548. return primeCache[hex];
  38549. }
  38550. var error = 0;
  38551. if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) {
  38552. //not a prime so +1
  38553. error += 1;
  38554. if (gen === '02' || gen === '05') {
  38555. // we'd be able to check the generator
  38556. // it would fail so +8
  38557. error += 8;
  38558. } else {
  38559. //we wouldn't be able to test the generator
  38560. // so +4
  38561. error += 4;
  38562. }
  38563. primeCache[hex] = error;
  38564. return error;
  38565. }
  38566. if (!millerRabin.test(prime.shrn(1))) {
  38567. //not a safe prime
  38568. error += 2;
  38569. }
  38570. var rem;
  38571. switch (gen) {
  38572. case '02':
  38573. if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) {
  38574. // unsuidable generator
  38575. error += 8;
  38576. }
  38577. break;
  38578. case '05':
  38579. rem = prime.mod(TEN);
  38580. if (rem.cmp(THREE) && rem.cmp(SEVEN)) {
  38581. // prime mod 10 needs to equal 3 or 7
  38582. error += 8;
  38583. }
  38584. break;
  38585. default:
  38586. error += 4;
  38587. }
  38588. primeCache[hex] = error;
  38589. return error;
  38590. }
  38591. function DH(prime, generator, malleable) {
  38592. this.setGenerator(generator);
  38593. this.__prime = new BN(prime);
  38594. this._prime = BN.mont(this.__prime);
  38595. this._primeLen = prime.length;
  38596. this._pub = undefined;
  38597. this._priv = undefined;
  38598. this._primeCode = undefined;
  38599. if (malleable) {
  38600. this.setPublicKey = setPublicKey;
  38601. this.setPrivateKey = setPrivateKey;
  38602. } else {
  38603. this._primeCode = 8;
  38604. }
  38605. }
  38606. Object.defineProperty(DH.prototype, 'verifyError', {
  38607. enumerable: true,
  38608. get: function get() {
  38609. if (typeof this._primeCode !== 'number') {
  38610. this._primeCode = checkPrime(this.__prime, this.__gen);
  38611. }
  38612. return this._primeCode;
  38613. }
  38614. });
  38615. DH.prototype.generateKeys = function () {
  38616. if (!this._priv) {
  38617. this._priv = new BN(randomBytes(this._primeLen));
  38618. }
  38619. this._pub = this._gen.toRed(this._prime).redPow(this._priv).fromRed();
  38620. return this.getPublicKey();
  38621. };
  38622. DH.prototype.computeSecret = function (other) {
  38623. other = new BN(other);
  38624. other = other.toRed(this._prime);
  38625. var secret = other.redPow(this._priv).fromRed();
  38626. var out = new Buffer(secret.toArray());
  38627. var prime = this.getPrime();
  38628. if (out.length < prime.length) {
  38629. var front = new Buffer(prime.length - out.length);
  38630. front.fill(0);
  38631. out = Buffer.concat([front, out]);
  38632. }
  38633. return out;
  38634. };
  38635. DH.prototype.getPublicKey = function getPublicKey(enc) {
  38636. return formatReturnValue(this._pub, enc);
  38637. };
  38638. DH.prototype.getPrivateKey = function getPrivateKey(enc) {
  38639. return formatReturnValue(this._priv, enc);
  38640. };
  38641. DH.prototype.getPrime = function (enc) {
  38642. return formatReturnValue(this.__prime, enc);
  38643. };
  38644. DH.prototype.getGenerator = function (enc) {
  38645. return formatReturnValue(this._gen, enc);
  38646. };
  38647. DH.prototype.setGenerator = function (gen, enc) {
  38648. enc = enc || 'utf8';
  38649. if (!Buffer.isBuffer(gen)) {
  38650. gen = new Buffer(gen, enc);
  38651. }
  38652. this.__gen = gen;
  38653. this._gen = new BN(gen);
  38654. return this;
  38655. };
  38656. function formatReturnValue(bn, enc) {
  38657. var buf = new Buffer(bn.toArray());
  38658. if (!enc) {
  38659. return buf;
  38660. } else {
  38661. return buf.toString(enc);
  38662. }
  38663. }
  38664. /***/ }),
  38665. /***/ 2227:
  38666. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38667. var randomBytes = __webpack_require__(5760);
  38668. module.exports = findPrime;
  38669. findPrime.simpleSieve = simpleSieve;
  38670. findPrime.fermatTest = fermatTest;
  38671. var BN = __webpack_require__(6781);
  38672. var TWENTYFOUR = new BN(24);
  38673. var MillerRabin = __webpack_require__(9318);
  38674. var millerRabin = new MillerRabin();
  38675. var ONE = new BN(1);
  38676. var TWO = new BN(2);
  38677. var FIVE = new BN(5);
  38678. var SIXTEEN = new BN(16);
  38679. var EIGHT = new BN(8);
  38680. var TEN = new BN(10);
  38681. var THREE = new BN(3);
  38682. var SEVEN = new BN(7);
  38683. var ELEVEN = new BN(11);
  38684. var FOUR = new BN(4);
  38685. var TWELVE = new BN(12);
  38686. var primes = null;
  38687. function _getPrimes() {
  38688. if (primes !== null) return primes;
  38689. var limit = 0x100000;
  38690. var res = [];
  38691. res[0] = 2;
  38692. for (var i = 1, k = 3; k < limit; k += 2) {
  38693. var sqrt = Math.ceil(Math.sqrt(k));
  38694. for (var j = 0; j < i && res[j] <= sqrt; j++) {
  38695. if (k % res[j] === 0) break;
  38696. }
  38697. if (i !== j && res[j] <= sqrt) continue;
  38698. res[i++] = k;
  38699. }
  38700. primes = res;
  38701. return res;
  38702. }
  38703. function simpleSieve(p) {
  38704. var primes = _getPrimes();
  38705. for (var i = 0; i < primes.length; i++) {
  38706. if (p.modn(primes[i]) === 0) {
  38707. if (p.cmpn(primes[i]) === 0) {
  38708. return true;
  38709. } else {
  38710. return false;
  38711. }
  38712. }
  38713. }
  38714. return true;
  38715. }
  38716. function fermatTest(p) {
  38717. var red = BN.mont(p);
  38718. return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0;
  38719. }
  38720. function findPrime(bits, gen) {
  38721. if (bits < 16) {
  38722. // this is what openssl does
  38723. if (gen === 2 || gen === 5) {
  38724. return new BN([0x8c, 0x7b]);
  38725. } else {
  38726. return new BN([0x8c, 0x27]);
  38727. }
  38728. }
  38729. gen = new BN(gen);
  38730. var num, n2;
  38731. while (true) {
  38732. num = new BN(randomBytes(Math.ceil(bits / 8)));
  38733. while (num.bitLength() > bits) {
  38734. num.ishrn(1);
  38735. }
  38736. if (num.isEven()) {
  38737. num.iadd(ONE);
  38738. }
  38739. if (!num.testn(1)) {
  38740. num.iadd(TWO);
  38741. }
  38742. if (!gen.cmp(TWO)) {
  38743. while (num.mod(TWENTYFOUR).cmp(ELEVEN)) {
  38744. num.iadd(FOUR);
  38745. }
  38746. } else if (!gen.cmp(FIVE)) {
  38747. while (num.mod(TEN).cmp(THREE)) {
  38748. num.iadd(FOUR);
  38749. }
  38750. }
  38751. n2 = num.shrn(1);
  38752. if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) {
  38753. return num;
  38754. }
  38755. }
  38756. }
  38757. /***/ }),
  38758. /***/ 8333:
  38759. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  38760. "use strict";
  38761. var elliptic = exports;
  38762. elliptic.version = (__webpack_require__(8597)/* .version */ .i8);
  38763. elliptic.utils = __webpack_require__(7891);
  38764. elliptic.rand = __webpack_require__(7179);
  38765. elliptic.curve = __webpack_require__(4720);
  38766. elliptic.curves = __webpack_require__(1478); // Protocols
  38767. elliptic.ec = __webpack_require__(5806);
  38768. elliptic.eddsa = __webpack_require__(8318);
  38769. /***/ }),
  38770. /***/ 9952:
  38771. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  38772. "use strict";
  38773. var BN = __webpack_require__(6781);
  38774. var utils = __webpack_require__(7891);
  38775. var getNAF = utils.getNAF;
  38776. var getJSF = utils.getJSF;
  38777. var assert = utils.assert;
  38778. function BaseCurve(type, conf) {
  38779. this.type = type;
  38780. this.p = new BN(conf.p, 16); // Use Montgomery, when there is no fast reduction for the prime
  38781. this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); // Useful for many curves
  38782. this.zero = new BN(0).toRed(this.red);
  38783. this.one = new BN(1).toRed(this.red);
  38784. this.two = new BN(2).toRed(this.red); // Curve configuration, optional
  38785. this.n = conf.n && new BN(conf.n, 16);
  38786. this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); // Temporary arrays
  38787. this._wnafT1 = new Array(4);
  38788. this._wnafT2 = new Array(4);
  38789. this._wnafT3 = new Array(4);
  38790. this._wnafT4 = new Array(4);
  38791. this._bitLength = this.n ? this.n.bitLength() : 0; // Generalized Greg Maxwell's trick
  38792. var adjustCount = this.n && this.p.div(this.n);
  38793. if (!adjustCount || adjustCount.cmpn(100) > 0) {
  38794. this.redN = null;
  38795. } else {
  38796. this._maxwellTrick = true;
  38797. this.redN = this.n.toRed(this.red);
  38798. }
  38799. }
  38800. module.exports = BaseCurve;
  38801. BaseCurve.prototype.point = function point() {
  38802. throw new Error('Not implemented');
  38803. };
  38804. BaseCurve.prototype.validate = function validate() {
  38805. throw new Error('Not implemented');
  38806. };
  38807. BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
  38808. assert(p.precomputed);
  38809. var doubles = p._getDoubles();
  38810. var naf = getNAF(k, 1, this._bitLength);
  38811. var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1);
  38812. I /= 3; // Translate into more windowed form
  38813. var repr = [];
  38814. var j;
  38815. var nafW;
  38816. for (j = 0; j < naf.length; j += doubles.step) {
  38817. nafW = 0;
  38818. for (var l = j + doubles.step - 1; l >= j; l--) {
  38819. nafW = (nafW << 1) + naf[l];
  38820. }
  38821. repr.push(nafW);
  38822. }
  38823. var a = this.jpoint(null, null, null);
  38824. var b = this.jpoint(null, null, null);
  38825. for (var i = I; i > 0; i--) {
  38826. for (j = 0; j < repr.length; j++) {
  38827. nafW = repr[j];
  38828. if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg());
  38829. }
  38830. a = a.add(b);
  38831. }
  38832. return a.toP();
  38833. };
  38834. BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
  38835. var w = 4; // Precompute window
  38836. var nafPoints = p._getNAFPoints(w);
  38837. w = nafPoints.wnd;
  38838. var wnd = nafPoints.points; // Get NAF form
  38839. var naf = getNAF(k, w, this._bitLength); // Add `this`*(N+1) for every w-NAF index
  38840. var acc = this.jpoint(null, null, null);
  38841. for (var i = naf.length - 1; i >= 0; i--) {
  38842. // Count zeroes
  38843. for (var l = 0; i >= 0 && naf[i] === 0; i--) {
  38844. l++;
  38845. }
  38846. if (i >= 0) l++;
  38847. acc = acc.dblp(l);
  38848. if (i < 0) break;
  38849. var z = naf[i];
  38850. assert(z !== 0);
  38851. if (p.type === 'affine') {
  38852. // J +- P
  38853. if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg());
  38854. } else {
  38855. // J +- J
  38856. if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg());
  38857. }
  38858. }
  38859. return p.type === 'affine' ? acc.toP() : acc;
  38860. };
  38861. BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
  38862. var wndWidth = this._wnafT1;
  38863. var wnd = this._wnafT2;
  38864. var naf = this._wnafT3; // Fill all arrays
  38865. var max = 0;
  38866. var i;
  38867. var j;
  38868. var p;
  38869. for (i = 0; i < len; i++) {
  38870. p = points[i];
  38871. var nafPoints = p._getNAFPoints(defW);
  38872. wndWidth[i] = nafPoints.wnd;
  38873. wnd[i] = nafPoints.points;
  38874. } // Comb small window NAFs
  38875. for (i = len - 1; i >= 1; i -= 2) {
  38876. var a = i - 1;
  38877. var b = i;
  38878. if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
  38879. naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength);
  38880. naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength);
  38881. max = Math.max(naf[a].length, max);
  38882. max = Math.max(naf[b].length, max);
  38883. continue;
  38884. }
  38885. var comb = [points[a],
  38886. /* 1 */
  38887. null,
  38888. /* 3 */
  38889. null,
  38890. /* 5 */
  38891. points[b]
  38892. /* 7 */
  38893. ]; // Try to avoid Projective points, if possible
  38894. if (points[a].y.cmp(points[b].y) === 0) {
  38895. comb[1] = points[a].add(points[b]);
  38896. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  38897. } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
  38898. comb[1] = points[a].toJ().mixedAdd(points[b]);
  38899. comb[2] = points[a].add(points[b].neg());
  38900. } else {
  38901. comb[1] = points[a].toJ().mixedAdd(points[b]);
  38902. comb[2] = points[a].toJ().mixedAdd(points[b].neg());
  38903. }
  38904. var index = [-3,
  38905. /* -1 -1 */
  38906. -1,
  38907. /* -1 0 */
  38908. -5,
  38909. /* -1 1 */
  38910. -7,
  38911. /* 0 -1 */
  38912. 0,
  38913. /* 0 0 */
  38914. 7,
  38915. /* 0 1 */
  38916. 5,
  38917. /* 1 -1 */
  38918. 1,
  38919. /* 1 0 */
  38920. 3
  38921. /* 1 1 */
  38922. ];
  38923. var jsf = getJSF(coeffs[a], coeffs[b]);
  38924. max = Math.max(jsf[0].length, max);
  38925. naf[a] = new Array(max);
  38926. naf[b] = new Array(max);
  38927. for (j = 0; j < max; j++) {
  38928. var ja = jsf[0][j] | 0;
  38929. var jb = jsf[1][j] | 0;
  38930. naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
  38931. naf[b][j] = 0;
  38932. wnd[a] = comb;
  38933. }
  38934. }
  38935. var acc = this.jpoint(null, null, null);
  38936. var tmp = this._wnafT4;
  38937. for (i = max; i >= 0; i--) {
  38938. var k = 0;
  38939. while (i >= 0) {
  38940. var zero = true;
  38941. for (j = 0; j < len; j++) {
  38942. tmp[j] = naf[j][i] | 0;
  38943. if (tmp[j] !== 0) zero = false;
  38944. }
  38945. if (!zero) break;
  38946. k++;
  38947. i--;
  38948. }
  38949. if (i >= 0) k++;
  38950. acc = acc.dblp(k);
  38951. if (i < 0) break;
  38952. for (j = 0; j < len; j++) {
  38953. var z = tmp[j];
  38954. p;
  38955. if (z === 0) continue;else if (z > 0) p = wnd[j][z - 1 >> 1];else if (z < 0) p = wnd[j][-z - 1 >> 1].neg();
  38956. if (p.type === 'affine') acc = acc.mixedAdd(p);else acc = acc.add(p);
  38957. }
  38958. } // Zeroify references
  38959. for (i = 0; i < len; i++) {
  38960. wnd[i] = null;
  38961. }
  38962. if (jacobianResult) return acc;else return acc.toP();
  38963. };
  38964. function BasePoint(curve, type) {
  38965. this.curve = curve;
  38966. this.type = type;
  38967. this.precomputed = null;
  38968. }
  38969. BaseCurve.BasePoint = BasePoint;
  38970. BasePoint.prototype.eq = function
  38971. /*other*/
  38972. eq() {
  38973. throw new Error('Not implemented');
  38974. };
  38975. BasePoint.prototype.validate = function validate() {
  38976. return this.curve.validate(this);
  38977. };
  38978. BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  38979. bytes = utils.toArray(bytes, enc);
  38980. var len = this.p.byteLength(); // uncompressed, hybrid-odd, hybrid-even
  38981. if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) && bytes.length - 1 === 2 * len) {
  38982. if (bytes[0] === 0x06) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 0x07) assert(bytes[bytes.length - 1] % 2 === 1);
  38983. var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len));
  38984. return res;
  38985. } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) && bytes.length - 1 === len) {
  38986. return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
  38987. }
  38988. throw new Error('Unknown point format');
  38989. };
  38990. BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
  38991. return this.encode(enc, true);
  38992. };
  38993. BasePoint.prototype._encode = function _encode(compact) {
  38994. var len = this.curve.p.byteLength();
  38995. var x = this.getX().toArray('be', len);
  38996. if (compact) return [this.getY().isEven() ? 0x02 : 0x03].concat(x);
  38997. return [0x04].concat(x, this.getY().toArray('be', len));
  38998. };
  38999. BasePoint.prototype.encode = function encode(enc, compact) {
  39000. return utils.encode(this._encode(compact), enc);
  39001. };
  39002. BasePoint.prototype.precompute = function precompute(power) {
  39003. if (this.precomputed) return this;
  39004. var precomputed = {
  39005. doubles: null,
  39006. naf: null,
  39007. beta: null
  39008. };
  39009. precomputed.naf = this._getNAFPoints(8);
  39010. precomputed.doubles = this._getDoubles(4, power);
  39011. precomputed.beta = this._getBeta();
  39012. this.precomputed = precomputed;
  39013. return this;
  39014. };
  39015. BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
  39016. if (!this.precomputed) return false;
  39017. var doubles = this.precomputed.doubles;
  39018. if (!doubles) return false;
  39019. return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
  39020. };
  39021. BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
  39022. if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles;
  39023. var doubles = [this];
  39024. var acc = this;
  39025. for (var i = 0; i < power; i += step) {
  39026. for (var j = 0; j < step; j++) {
  39027. acc = acc.dbl();
  39028. }
  39029. doubles.push(acc);
  39030. }
  39031. return {
  39032. step: step,
  39033. points: doubles
  39034. };
  39035. };
  39036. BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
  39037. if (this.precomputed && this.precomputed.naf) return this.precomputed.naf;
  39038. var res = [this];
  39039. var max = (1 << wnd) - 1;
  39040. var dbl = max === 1 ? null : this.dbl();
  39041. for (var i = 1; i < max; i++) {
  39042. res[i] = res[i - 1].add(dbl);
  39043. }
  39044. return {
  39045. wnd: wnd,
  39046. points: res
  39047. };
  39048. };
  39049. BasePoint.prototype._getBeta = function _getBeta() {
  39050. return null;
  39051. };
  39052. BasePoint.prototype.dblp = function dblp(k) {
  39053. var r = this;
  39054. for (var i = 0; i < k; i++) {
  39055. r = r.dbl();
  39056. }
  39057. return r;
  39058. };
  39059. /***/ }),
  39060. /***/ 5970:
  39061. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  39062. "use strict";
  39063. var utils = __webpack_require__(7891);
  39064. var BN = __webpack_require__(6781);
  39065. var inherits = __webpack_require__(376);
  39066. var Base = __webpack_require__(9952);
  39067. var assert = utils.assert;
  39068. function EdwardsCurve(conf) {
  39069. // NOTE: Important as we are creating point in Base.call()
  39070. this.twisted = (conf.a | 0) !== 1;
  39071. this.mOneA = this.twisted && (conf.a | 0) === -1;
  39072. this.extended = this.mOneA;
  39073. Base.call(this, 'edwards', conf);
  39074. this.a = new BN(conf.a, 16).umod(this.red.m);
  39075. this.a = this.a.toRed(this.red);
  39076. this.c = new BN(conf.c, 16).toRed(this.red);
  39077. this.c2 = this.c.redSqr();
  39078. this.d = new BN(conf.d, 16).toRed(this.red);
  39079. this.dd = this.d.redAdd(this.d);
  39080. assert(!this.twisted || this.c.fromRed().cmpn(1) === 0);
  39081. this.oneC = (conf.c | 0) === 1;
  39082. }
  39083. inherits(EdwardsCurve, Base);
  39084. module.exports = EdwardsCurve;
  39085. EdwardsCurve.prototype._mulA = function _mulA(num) {
  39086. if (this.mOneA) return num.redNeg();else return this.a.redMul(num);
  39087. };
  39088. EdwardsCurve.prototype._mulC = function _mulC(num) {
  39089. if (this.oneC) return num;else return this.c.redMul(num);
  39090. }; // Just for compatibility with Short curve
  39091. EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
  39092. return this.point(x, y, z, t);
  39093. };
  39094. EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
  39095. x = new BN(x, 16);
  39096. if (!x.red) x = x.toRed(this.red);
  39097. var x2 = x.redSqr();
  39098. var rhs = this.c2.redSub(this.a.redMul(x2));
  39099. var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
  39100. var y2 = rhs.redMul(lhs.redInvm());
  39101. var y = y2.redSqrt();
  39102. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point');
  39103. var isOdd = y.fromRed().isOdd();
  39104. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  39105. return this.point(x, y);
  39106. };
  39107. EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
  39108. y = new BN(y, 16);
  39109. if (!y.red) y = y.toRed(this.red); // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
  39110. var y2 = y.redSqr();
  39111. var lhs = y2.redSub(this.c2);
  39112. var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
  39113. var x2 = lhs.redMul(rhs.redInvm());
  39114. if (x2.cmp(this.zero) === 0) {
  39115. if (odd) throw new Error('invalid point');else return this.point(this.zero, y);
  39116. }
  39117. var x = x2.redSqrt();
  39118. if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error('invalid point');
  39119. if (x.fromRed().isOdd() !== odd) x = x.redNeg();
  39120. return this.point(x, y);
  39121. };
  39122. EdwardsCurve.prototype.validate = function validate(point) {
  39123. if (point.isInfinity()) return true; // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
  39124. point.normalize();
  39125. var x2 = point.x.redSqr();
  39126. var y2 = point.y.redSqr();
  39127. var lhs = x2.redMul(this.a).redAdd(y2);
  39128. var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
  39129. return lhs.cmp(rhs) === 0;
  39130. };
  39131. function Point(curve, x, y, z, t) {
  39132. Base.BasePoint.call(this, curve, 'projective');
  39133. if (x === null && y === null && z === null) {
  39134. this.x = this.curve.zero;
  39135. this.y = this.curve.one;
  39136. this.z = this.curve.one;
  39137. this.t = this.curve.zero;
  39138. this.zOne = true;
  39139. } else {
  39140. this.x = new BN(x, 16);
  39141. this.y = new BN(y, 16);
  39142. this.z = z ? new BN(z, 16) : this.curve.one;
  39143. this.t = t && new BN(t, 16);
  39144. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  39145. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  39146. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  39147. if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red);
  39148. this.zOne = this.z === this.curve.one; // Use extended coordinates
  39149. if (this.curve.extended && !this.t) {
  39150. this.t = this.x.redMul(this.y);
  39151. if (!this.zOne) this.t = this.t.redMul(this.z.redInvm());
  39152. }
  39153. }
  39154. }
  39155. inherits(Point, Base.BasePoint);
  39156. EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  39157. return Point.fromJSON(this, obj);
  39158. };
  39159. EdwardsCurve.prototype.point = function point(x, y, z, t) {
  39160. return new Point(this, x, y, z, t);
  39161. };
  39162. Point.fromJSON = function fromJSON(curve, obj) {
  39163. return new Point(curve, obj[0], obj[1], obj[2]);
  39164. };
  39165. Point.prototype.inspect = function inspect() {
  39166. if (this.isInfinity()) return '<EC Point Infinity>';
  39167. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  39168. };
  39169. Point.prototype.isInfinity = function isInfinity() {
  39170. // XXX This code assumes that zero is always zero in red
  39171. return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0);
  39172. };
  39173. Point.prototype._extDbl = function _extDbl() {
  39174. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  39175. // #doubling-dbl-2008-hwcd
  39176. // 4M + 4S
  39177. // A = X1^2
  39178. var a = this.x.redSqr(); // B = Y1^2
  39179. var b = this.y.redSqr(); // C = 2 * Z1^2
  39180. var c = this.z.redSqr();
  39181. c = c.redIAdd(c); // D = a * A
  39182. var d = this.curve._mulA(a); // E = (X1 + Y1)^2 - A - B
  39183. var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); // G = D + B
  39184. var g = d.redAdd(b); // F = G - C
  39185. var f = g.redSub(c); // H = D - B
  39186. var h = d.redSub(b); // X3 = E * F
  39187. var nx = e.redMul(f); // Y3 = G * H
  39188. var ny = g.redMul(h); // T3 = E * H
  39189. var nt = e.redMul(h); // Z3 = F * G
  39190. var nz = f.redMul(g);
  39191. return this.curve.point(nx, ny, nz, nt);
  39192. };
  39193. Point.prototype._projDbl = function _projDbl() {
  39194. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  39195. // #doubling-dbl-2008-bbjlp
  39196. // #doubling-dbl-2007-bl
  39197. // and others
  39198. // Generally 3M + 4S or 2M + 4S
  39199. // B = (X1 + Y1)^2
  39200. var b = this.x.redAdd(this.y).redSqr(); // C = X1^2
  39201. var c = this.x.redSqr(); // D = Y1^2
  39202. var d = this.y.redSqr();
  39203. var nx;
  39204. var ny;
  39205. var nz;
  39206. var e;
  39207. var h;
  39208. var j;
  39209. if (this.curve.twisted) {
  39210. // E = a * C
  39211. e = this.curve._mulA(c); // F = E + D
  39212. var f = e.redAdd(d);
  39213. if (this.zOne) {
  39214. // X3 = (B - C - D) * (F - 2)
  39215. nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); // Y3 = F * (E - D)
  39216. ny = f.redMul(e.redSub(d)); // Z3 = F^2 - 2 * F
  39217. nz = f.redSqr().redSub(f).redSub(f);
  39218. } else {
  39219. // H = Z1^2
  39220. h = this.z.redSqr(); // J = F - 2 * H
  39221. j = f.redSub(h).redISub(h); // X3 = (B-C-D)*J
  39222. nx = b.redSub(c).redISub(d).redMul(j); // Y3 = F * (E - D)
  39223. ny = f.redMul(e.redSub(d)); // Z3 = F * J
  39224. nz = f.redMul(j);
  39225. }
  39226. } else {
  39227. // E = C + D
  39228. e = c.redAdd(d); // H = (c * Z1)^2
  39229. h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H
  39230. j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J
  39231. nx = this.curve._mulC(b.redISub(e)).redMul(j); // Y3 = c * E * (C - D)
  39232. ny = this.curve._mulC(e).redMul(c.redISub(d)); // Z3 = E * J
  39233. nz = e.redMul(j);
  39234. }
  39235. return this.curve.point(nx, ny, nz);
  39236. };
  39237. Point.prototype.dbl = function dbl() {
  39238. if (this.isInfinity()) return this; // Double in extended coordinates
  39239. if (this.curve.extended) return this._extDbl();else return this._projDbl();
  39240. };
  39241. Point.prototype._extAdd = function _extAdd(p) {
  39242. // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
  39243. // #addition-add-2008-hwcd-3
  39244. // 8M
  39245. // A = (Y1 - X1) * (Y2 - X2)
  39246. var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); // B = (Y1 + X1) * (Y2 + X2)
  39247. var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); // C = T1 * k * T2
  39248. var c = this.t.redMul(this.curve.dd).redMul(p.t); // D = Z1 * 2 * Z2
  39249. var d = this.z.redMul(p.z.redAdd(p.z)); // E = B - A
  39250. var e = b.redSub(a); // F = D - C
  39251. var f = d.redSub(c); // G = D + C
  39252. var g = d.redAdd(c); // H = B + A
  39253. var h = b.redAdd(a); // X3 = E * F
  39254. var nx = e.redMul(f); // Y3 = G * H
  39255. var ny = g.redMul(h); // T3 = E * H
  39256. var nt = e.redMul(h); // Z3 = F * G
  39257. var nz = f.redMul(g);
  39258. return this.curve.point(nx, ny, nz, nt);
  39259. };
  39260. Point.prototype._projAdd = function _projAdd(p) {
  39261. // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
  39262. // #addition-add-2008-bbjlp
  39263. // #addition-add-2007-bl
  39264. // 10M + 1S
  39265. // A = Z1 * Z2
  39266. var a = this.z.redMul(p.z); // B = A^2
  39267. var b = a.redSqr(); // C = X1 * X2
  39268. var c = this.x.redMul(p.x); // D = Y1 * Y2
  39269. var d = this.y.redMul(p.y); // E = d * C * D
  39270. var e = this.curve.d.redMul(c).redMul(d); // F = B - E
  39271. var f = b.redSub(e); // G = B + E
  39272. var g = b.redAdd(e); // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
  39273. var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
  39274. var nx = a.redMul(f).redMul(tmp);
  39275. var ny;
  39276. var nz;
  39277. if (this.curve.twisted) {
  39278. // Y3 = A * G * (D - a * C)
  39279. ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); // Z3 = F * G
  39280. nz = f.redMul(g);
  39281. } else {
  39282. // Y3 = A * G * (D - C)
  39283. ny = a.redMul(g).redMul(d.redSub(c)); // Z3 = c * F * G
  39284. nz = this.curve._mulC(f).redMul(g);
  39285. }
  39286. return this.curve.point(nx, ny, nz);
  39287. };
  39288. Point.prototype.add = function add(p) {
  39289. if (this.isInfinity()) return p;
  39290. if (p.isInfinity()) return this;
  39291. if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p);
  39292. };
  39293. Point.prototype.mul = function mul(k) {
  39294. if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k);
  39295. };
  39296. Point.prototype.mulAdd = function mulAdd(k1, p, k2) {
  39297. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false);
  39298. };
  39299. Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
  39300. return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true);
  39301. };
  39302. Point.prototype.normalize = function normalize() {
  39303. if (this.zOne) return this; // Normalize coordinates
  39304. var zi = this.z.redInvm();
  39305. this.x = this.x.redMul(zi);
  39306. this.y = this.y.redMul(zi);
  39307. if (this.t) this.t = this.t.redMul(zi);
  39308. this.z = this.curve.one;
  39309. this.zOne = true;
  39310. return this;
  39311. };
  39312. Point.prototype.neg = function neg() {
  39313. return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg());
  39314. };
  39315. Point.prototype.getX = function getX() {
  39316. this.normalize();
  39317. return this.x.fromRed();
  39318. };
  39319. Point.prototype.getY = function getY() {
  39320. this.normalize();
  39321. return this.y.fromRed();
  39322. };
  39323. Point.prototype.eq = function eq(other) {
  39324. return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0;
  39325. };
  39326. Point.prototype.eqXToP = function eqXToP(x) {
  39327. var rx = x.toRed(this.curve.red).redMul(this.z);
  39328. if (this.x.cmp(rx) === 0) return true;
  39329. var xc = x.clone();
  39330. var t = this.curve.redN.redMul(this.z);
  39331. for (;;) {
  39332. xc.iadd(this.curve.n);
  39333. if (xc.cmp(this.curve.p) >= 0) return false;
  39334. rx.redIAdd(t);
  39335. if (this.x.cmp(rx) === 0) return true;
  39336. }
  39337. }; // Compatibility with BaseCurve
  39338. Point.prototype.toP = Point.prototype.normalize;
  39339. Point.prototype.mixedAdd = Point.prototype.add;
  39340. /***/ }),
  39341. /***/ 4720:
  39342. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  39343. "use strict";
  39344. var curve = exports;
  39345. curve.base = __webpack_require__(9952);
  39346. curve["short"] = __webpack_require__(1585);
  39347. curve.mont = __webpack_require__(6773);
  39348. curve.edwards = __webpack_require__(5970);
  39349. /***/ }),
  39350. /***/ 6773:
  39351. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  39352. "use strict";
  39353. var BN = __webpack_require__(6781);
  39354. var inherits = __webpack_require__(376);
  39355. var Base = __webpack_require__(9952);
  39356. var utils = __webpack_require__(7891);
  39357. function MontCurve(conf) {
  39358. Base.call(this, 'mont', conf);
  39359. this.a = new BN(conf.a, 16).toRed(this.red);
  39360. this.b = new BN(conf.b, 16).toRed(this.red);
  39361. this.i4 = new BN(4).toRed(this.red).redInvm();
  39362. this.two = new BN(2).toRed(this.red);
  39363. this.a24 = this.i4.redMul(this.a.redAdd(this.two));
  39364. }
  39365. inherits(MontCurve, Base);
  39366. module.exports = MontCurve;
  39367. MontCurve.prototype.validate = function validate(point) {
  39368. var x = point.normalize().x;
  39369. var x2 = x.redSqr();
  39370. var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
  39371. var y = rhs.redSqrt();
  39372. return y.redSqr().cmp(rhs) === 0;
  39373. };
  39374. function Point(curve, x, z) {
  39375. Base.BasePoint.call(this, curve, 'projective');
  39376. if (x === null && z === null) {
  39377. this.x = this.curve.one;
  39378. this.z = this.curve.zero;
  39379. } else {
  39380. this.x = new BN(x, 16);
  39381. this.z = new BN(z, 16);
  39382. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  39383. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  39384. }
  39385. }
  39386. inherits(Point, Base.BasePoint);
  39387. MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
  39388. return this.point(utils.toArray(bytes, enc), 1);
  39389. };
  39390. MontCurve.prototype.point = function point(x, z) {
  39391. return new Point(this, x, z);
  39392. };
  39393. MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
  39394. return Point.fromJSON(this, obj);
  39395. };
  39396. Point.prototype.precompute = function precompute() {// No-op
  39397. };
  39398. Point.prototype._encode = function _encode() {
  39399. return this.getX().toArray('be', this.curve.p.byteLength());
  39400. };
  39401. Point.fromJSON = function fromJSON(curve, obj) {
  39402. return new Point(curve, obj[0], obj[1] || curve.one);
  39403. };
  39404. Point.prototype.inspect = function inspect() {
  39405. if (this.isInfinity()) return '<EC Point Infinity>';
  39406. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' z: ' + this.z.fromRed().toString(16, 2) + '>';
  39407. };
  39408. Point.prototype.isInfinity = function isInfinity() {
  39409. // XXX This code assumes that zero is always zero in red
  39410. return this.z.cmpn(0) === 0;
  39411. };
  39412. Point.prototype.dbl = function dbl() {
  39413. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
  39414. // 2M + 2S + 4A
  39415. // A = X1 + Z1
  39416. var a = this.x.redAdd(this.z); // AA = A^2
  39417. var aa = a.redSqr(); // B = X1 - Z1
  39418. var b = this.x.redSub(this.z); // BB = B^2
  39419. var bb = b.redSqr(); // C = AA - BB
  39420. var c = aa.redSub(bb); // X3 = AA * BB
  39421. var nx = aa.redMul(bb); // Z3 = C * (BB + A24 * C)
  39422. var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
  39423. return this.curve.point(nx, nz);
  39424. };
  39425. Point.prototype.add = function add() {
  39426. throw new Error('Not supported on Montgomery curve');
  39427. };
  39428. Point.prototype.diffAdd = function diffAdd(p, diff) {
  39429. // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
  39430. // 4M + 2S + 6A
  39431. // A = X2 + Z2
  39432. var a = this.x.redAdd(this.z); // B = X2 - Z2
  39433. var b = this.x.redSub(this.z); // C = X3 + Z3
  39434. var c = p.x.redAdd(p.z); // D = X3 - Z3
  39435. var d = p.x.redSub(p.z); // DA = D * A
  39436. var da = d.redMul(a); // CB = C * B
  39437. var cb = c.redMul(b); // X5 = Z1 * (DA + CB)^2
  39438. var nx = diff.z.redMul(da.redAdd(cb).redSqr()); // Z5 = X1 * (DA - CB)^2
  39439. var nz = diff.x.redMul(da.redISub(cb).redSqr());
  39440. return this.curve.point(nx, nz);
  39441. };
  39442. Point.prototype.mul = function mul(k) {
  39443. var t = k.clone();
  39444. var a = this; // (N / 2) * Q + Q
  39445. var b = this.curve.point(null, null); // (N / 2) * Q
  39446. var c = this; // Q
  39447. for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) {
  39448. bits.push(t.andln(1));
  39449. }
  39450. for (var i = bits.length - 1; i >= 0; i--) {
  39451. if (bits[i] === 0) {
  39452. // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
  39453. a = a.diffAdd(b, c); // N * Q = 2 * ((N / 2) * Q + Q))
  39454. b = b.dbl();
  39455. } else {
  39456. // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
  39457. b = a.diffAdd(b, c); // N * Q + Q = 2 * ((N / 2) * Q + Q)
  39458. a = a.dbl();
  39459. }
  39460. }
  39461. return b;
  39462. };
  39463. Point.prototype.mulAdd = function mulAdd() {
  39464. throw new Error('Not supported on Montgomery curve');
  39465. };
  39466. Point.prototype.jumlAdd = function jumlAdd() {
  39467. throw new Error('Not supported on Montgomery curve');
  39468. };
  39469. Point.prototype.eq = function eq(other) {
  39470. return this.getX().cmp(other.getX()) === 0;
  39471. };
  39472. Point.prototype.normalize = function normalize() {
  39473. this.x = this.x.redMul(this.z.redInvm());
  39474. this.z = this.curve.one;
  39475. return this;
  39476. };
  39477. Point.prototype.getX = function getX() {
  39478. // Normalize coordinates
  39479. this.normalize();
  39480. return this.x.fromRed();
  39481. };
  39482. /***/ }),
  39483. /***/ 1585:
  39484. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  39485. "use strict";
  39486. var utils = __webpack_require__(7891);
  39487. var BN = __webpack_require__(6781);
  39488. var inherits = __webpack_require__(376);
  39489. var Base = __webpack_require__(9952);
  39490. var assert = utils.assert;
  39491. function ShortCurve(conf) {
  39492. Base.call(this, 'short', conf);
  39493. this.a = new BN(conf.a, 16).toRed(this.red);
  39494. this.b = new BN(conf.b, 16).toRed(this.red);
  39495. this.tinv = this.two.redInvm();
  39496. this.zeroA = this.a.fromRed().cmpn(0) === 0;
  39497. this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; // If the curve is endomorphic, precalculate beta and lambda
  39498. this.endo = this._getEndomorphism(conf);
  39499. this._endoWnafT1 = new Array(4);
  39500. this._endoWnafT2 = new Array(4);
  39501. }
  39502. inherits(ShortCurve, Base);
  39503. module.exports = ShortCurve;
  39504. ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
  39505. // No efficient endomorphism
  39506. if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; // Compute beta and lambda, that lambda * P = (beta * Px; Py)
  39507. var beta;
  39508. var lambda;
  39509. if (conf.beta) {
  39510. beta = new BN(conf.beta, 16).toRed(this.red);
  39511. } else {
  39512. var betas = this._getEndoRoots(this.p); // Choose the smallest beta
  39513. beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
  39514. beta = beta.toRed(this.red);
  39515. }
  39516. if (conf.lambda) {
  39517. lambda = new BN(conf.lambda, 16);
  39518. } else {
  39519. // Choose the lambda that is matching selected beta
  39520. var lambdas = this._getEndoRoots(this.n);
  39521. if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
  39522. lambda = lambdas[0];
  39523. } else {
  39524. lambda = lambdas[1];
  39525. assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
  39526. }
  39527. } // Get basis vectors, used for balanced length-two representation
  39528. var basis;
  39529. if (conf.basis) {
  39530. basis = conf.basis.map(function (vec) {
  39531. return {
  39532. a: new BN(vec.a, 16),
  39533. b: new BN(vec.b, 16)
  39534. };
  39535. });
  39536. } else {
  39537. basis = this._getEndoBasis(lambda);
  39538. }
  39539. return {
  39540. beta: beta,
  39541. lambda: lambda,
  39542. basis: basis
  39543. };
  39544. };
  39545. ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
  39546. // Find roots of for x^2 + x + 1 in F
  39547. // Root = (-1 +- Sqrt(-3)) / 2
  39548. //
  39549. var red = num === this.p ? this.red : BN.mont(num);
  39550. var tinv = new BN(2).toRed(red).redInvm();
  39551. var ntinv = tinv.redNeg();
  39552. var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);
  39553. var l1 = ntinv.redAdd(s).fromRed();
  39554. var l2 = ntinv.redSub(s).fromRed();
  39555. return [l1, l2];
  39556. };
  39557. ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
  39558. // aprxSqrt >= sqrt(this.n)
  39559. var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); // 3.74
  39560. // Run EGCD, until r(L + 1) < aprxSqrt
  39561. var u = lambda;
  39562. var v = this.n.clone();
  39563. var x1 = new BN(1);
  39564. var y1 = new BN(0);
  39565. var x2 = new BN(0);
  39566. var y2 = new BN(1); // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
  39567. var a0;
  39568. var b0; // First vector
  39569. var a1;
  39570. var b1; // Second vector
  39571. var a2;
  39572. var b2;
  39573. var prevR;
  39574. var i = 0;
  39575. var r;
  39576. var x;
  39577. while (u.cmpn(0) !== 0) {
  39578. var q = v.div(u);
  39579. r = v.sub(q.mul(u));
  39580. x = x2.sub(q.mul(x1));
  39581. var y = y2.sub(q.mul(y1));
  39582. if (!a1 && r.cmp(aprxSqrt) < 0) {
  39583. a0 = prevR.neg();
  39584. b0 = x1;
  39585. a1 = r.neg();
  39586. b1 = x;
  39587. } else if (a1 && ++i === 2) {
  39588. break;
  39589. }
  39590. prevR = r;
  39591. v = u;
  39592. u = r;
  39593. x2 = x1;
  39594. x1 = x;
  39595. y2 = y1;
  39596. y1 = y;
  39597. }
  39598. a2 = r.neg();
  39599. b2 = x;
  39600. var len1 = a1.sqr().add(b1.sqr());
  39601. var len2 = a2.sqr().add(b2.sqr());
  39602. if (len2.cmp(len1) >= 0) {
  39603. a2 = a0;
  39604. b2 = b0;
  39605. } // Normalize signs
  39606. if (a1.negative) {
  39607. a1 = a1.neg();
  39608. b1 = b1.neg();
  39609. }
  39610. if (a2.negative) {
  39611. a2 = a2.neg();
  39612. b2 = b2.neg();
  39613. }
  39614. return [{
  39615. a: a1,
  39616. b: b1
  39617. }, {
  39618. a: a2,
  39619. b: b2
  39620. }];
  39621. };
  39622. ShortCurve.prototype._endoSplit = function _endoSplit(k) {
  39623. var basis = this.endo.basis;
  39624. var v1 = basis[0];
  39625. var v2 = basis[1];
  39626. var c1 = v2.b.mul(k).divRound(this.n);
  39627. var c2 = v1.b.neg().mul(k).divRound(this.n);
  39628. var p1 = c1.mul(v1.a);
  39629. var p2 = c2.mul(v2.a);
  39630. var q1 = c1.mul(v1.b);
  39631. var q2 = c2.mul(v2.b); // Calculate answer
  39632. var k1 = k.sub(p1).sub(p2);
  39633. var k2 = q1.add(q2).neg();
  39634. return {
  39635. k1: k1,
  39636. k2: k2
  39637. };
  39638. };
  39639. ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
  39640. x = new BN(x, 16);
  39641. if (!x.red) x = x.toRed(this.red);
  39642. var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
  39643. var y = y2.redSqrt();
  39644. if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error('invalid point'); // XXX Is there any way to tell if the number is odd without converting it
  39645. // to non-red form?
  39646. var isOdd = y.fromRed().isOdd();
  39647. if (odd && !isOdd || !odd && isOdd) y = y.redNeg();
  39648. return this.point(x, y);
  39649. };
  39650. ShortCurve.prototype.validate = function validate(point) {
  39651. if (point.inf) return true;
  39652. var x = point.x;
  39653. var y = point.y;
  39654. var ax = this.a.redMul(x);
  39655. var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
  39656. return y.redSqr().redISub(rhs).cmpn(0) === 0;
  39657. };
  39658. ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) {
  39659. var npoints = this._endoWnafT1;
  39660. var ncoeffs = this._endoWnafT2;
  39661. for (var i = 0; i < points.length; i++) {
  39662. var split = this._endoSplit(coeffs[i]);
  39663. var p = points[i];
  39664. var beta = p._getBeta();
  39665. if (split.k1.negative) {
  39666. split.k1.ineg();
  39667. p = p.neg(true);
  39668. }
  39669. if (split.k2.negative) {
  39670. split.k2.ineg();
  39671. beta = beta.neg(true);
  39672. }
  39673. npoints[i * 2] = p;
  39674. npoints[i * 2 + 1] = beta;
  39675. ncoeffs[i * 2] = split.k1;
  39676. ncoeffs[i * 2 + 1] = split.k2;
  39677. }
  39678. var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); // Clean-up references to points and coefficients
  39679. for (var j = 0; j < i * 2; j++) {
  39680. npoints[j] = null;
  39681. ncoeffs[j] = null;
  39682. }
  39683. return res;
  39684. };
  39685. function Point(curve, x, y, isRed) {
  39686. Base.BasePoint.call(this, curve, 'affine');
  39687. if (x === null && y === null) {
  39688. this.x = null;
  39689. this.y = null;
  39690. this.inf = true;
  39691. } else {
  39692. this.x = new BN(x, 16);
  39693. this.y = new BN(y, 16); // Force redgomery representation when loading from JSON
  39694. if (isRed) {
  39695. this.x.forceRed(this.curve.red);
  39696. this.y.forceRed(this.curve.red);
  39697. }
  39698. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  39699. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  39700. this.inf = false;
  39701. }
  39702. }
  39703. inherits(Point, Base.BasePoint);
  39704. ShortCurve.prototype.point = function point(x, y, isRed) {
  39705. return new Point(this, x, y, isRed);
  39706. };
  39707. ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
  39708. return Point.fromJSON(this, obj, red);
  39709. };
  39710. Point.prototype._getBeta = function _getBeta() {
  39711. if (!this.curve.endo) return;
  39712. var pre = this.precomputed;
  39713. if (pre && pre.beta) return pre.beta;
  39714. var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
  39715. if (pre) {
  39716. var curve = this.curve;
  39717. var endoMul = function endoMul(p) {
  39718. return curve.point(p.x.redMul(curve.endo.beta), p.y);
  39719. };
  39720. pre.beta = beta;
  39721. beta.precomputed = {
  39722. beta: null,
  39723. naf: pre.naf && {
  39724. wnd: pre.naf.wnd,
  39725. points: pre.naf.points.map(endoMul)
  39726. },
  39727. doubles: pre.doubles && {
  39728. step: pre.doubles.step,
  39729. points: pre.doubles.points.map(endoMul)
  39730. }
  39731. };
  39732. }
  39733. return beta;
  39734. };
  39735. Point.prototype.toJSON = function toJSON() {
  39736. if (!this.precomputed) return [this.x, this.y];
  39737. return [this.x, this.y, this.precomputed && {
  39738. doubles: this.precomputed.doubles && {
  39739. step: this.precomputed.doubles.step,
  39740. points: this.precomputed.doubles.points.slice(1)
  39741. },
  39742. naf: this.precomputed.naf && {
  39743. wnd: this.precomputed.naf.wnd,
  39744. points: this.precomputed.naf.points.slice(1)
  39745. }
  39746. }];
  39747. };
  39748. Point.fromJSON = function fromJSON(curve, obj, red) {
  39749. if (typeof obj === 'string') obj = JSON.parse(obj);
  39750. var res = curve.point(obj[0], obj[1], red);
  39751. if (!obj[2]) return res;
  39752. function obj2point(obj) {
  39753. return curve.point(obj[0], obj[1], red);
  39754. }
  39755. var pre = obj[2];
  39756. res.precomputed = {
  39757. beta: null,
  39758. doubles: pre.doubles && {
  39759. step: pre.doubles.step,
  39760. points: [res].concat(pre.doubles.points.map(obj2point))
  39761. },
  39762. naf: pre.naf && {
  39763. wnd: pre.naf.wnd,
  39764. points: [res].concat(pre.naf.points.map(obj2point))
  39765. }
  39766. };
  39767. return res;
  39768. };
  39769. Point.prototype.inspect = function inspect() {
  39770. if (this.isInfinity()) return '<EC Point Infinity>';
  39771. return '<EC Point x: ' + this.x.fromRed().toString(16, 2) + ' y: ' + this.y.fromRed().toString(16, 2) + '>';
  39772. };
  39773. Point.prototype.isInfinity = function isInfinity() {
  39774. return this.inf;
  39775. };
  39776. Point.prototype.add = function add(p) {
  39777. // O + P = P
  39778. if (this.inf) return p; // P + O = P
  39779. if (p.inf) return this; // P + P = 2P
  39780. if (this.eq(p)) return this.dbl(); // P + (-P) = O
  39781. if (this.neg().eq(p)) return this.curve.point(null, null); // P + Q = O
  39782. if (this.x.cmp(p.x) === 0) return this.curve.point(null, null);
  39783. var c = this.y.redSub(p.y);
  39784. if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm());
  39785. var nx = c.redSqr().redISub(this.x).redISub(p.x);
  39786. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  39787. return this.curve.point(nx, ny);
  39788. };
  39789. Point.prototype.dbl = function dbl() {
  39790. if (this.inf) return this; // 2P = O
  39791. var ys1 = this.y.redAdd(this.y);
  39792. if (ys1.cmpn(0) === 0) return this.curve.point(null, null);
  39793. var a = this.curve.a;
  39794. var x2 = this.x.redSqr();
  39795. var dyinv = ys1.redInvm();
  39796. var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
  39797. var nx = c.redSqr().redISub(this.x.redAdd(this.x));
  39798. var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
  39799. return this.curve.point(nx, ny);
  39800. };
  39801. Point.prototype.getX = function getX() {
  39802. return this.x.fromRed();
  39803. };
  39804. Point.prototype.getY = function getY() {
  39805. return this.y.fromRed();
  39806. };
  39807. Point.prototype.mul = function mul(k) {
  39808. k = new BN(k, 16);
  39809. if (this.isInfinity()) return this;else if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else if (this.curve.endo) return this.curve._endoWnafMulAdd([this], [k]);else return this.curve._wnafMul(this, k);
  39810. };
  39811. Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
  39812. var points = [this, p2];
  39813. var coeffs = [k1, k2];
  39814. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2);
  39815. };
  39816. Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
  39817. var points = [this, p2];
  39818. var coeffs = [k1, k2];
  39819. if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
  39820. };
  39821. Point.prototype.eq = function eq(p) {
  39822. return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
  39823. };
  39824. Point.prototype.neg = function neg(_precompute) {
  39825. if (this.inf) return this;
  39826. var res = this.curve.point(this.x, this.y.redNeg());
  39827. if (_precompute && this.precomputed) {
  39828. var pre = this.precomputed;
  39829. var negate = function negate(p) {
  39830. return p.neg();
  39831. };
  39832. res.precomputed = {
  39833. naf: pre.naf && {
  39834. wnd: pre.naf.wnd,
  39835. points: pre.naf.points.map(negate)
  39836. },
  39837. doubles: pre.doubles && {
  39838. step: pre.doubles.step,
  39839. points: pre.doubles.points.map(negate)
  39840. }
  39841. };
  39842. }
  39843. return res;
  39844. };
  39845. Point.prototype.toJ = function toJ() {
  39846. if (this.inf) return this.curve.jpoint(null, null, null);
  39847. var res = this.curve.jpoint(this.x, this.y, this.curve.one);
  39848. return res;
  39849. };
  39850. function JPoint(curve, x, y, z) {
  39851. Base.BasePoint.call(this, curve, 'jacobian');
  39852. if (x === null && y === null && z === null) {
  39853. this.x = this.curve.one;
  39854. this.y = this.curve.one;
  39855. this.z = new BN(0);
  39856. } else {
  39857. this.x = new BN(x, 16);
  39858. this.y = new BN(y, 16);
  39859. this.z = new BN(z, 16);
  39860. }
  39861. if (!this.x.red) this.x = this.x.toRed(this.curve.red);
  39862. if (!this.y.red) this.y = this.y.toRed(this.curve.red);
  39863. if (!this.z.red) this.z = this.z.toRed(this.curve.red);
  39864. this.zOne = this.z === this.curve.one;
  39865. }
  39866. inherits(JPoint, Base.BasePoint);
  39867. ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
  39868. return new JPoint(this, x, y, z);
  39869. };
  39870. JPoint.prototype.toP = function toP() {
  39871. if (this.isInfinity()) return this.curve.point(null, null);
  39872. var zinv = this.z.redInvm();
  39873. var zinv2 = zinv.redSqr();
  39874. var ax = this.x.redMul(zinv2);
  39875. var ay = this.y.redMul(zinv2).redMul(zinv);
  39876. return this.curve.point(ax, ay);
  39877. };
  39878. JPoint.prototype.neg = function neg() {
  39879. return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
  39880. };
  39881. JPoint.prototype.add = function add(p) {
  39882. // O + P = P
  39883. if (this.isInfinity()) return p; // P + O = P
  39884. if (p.isInfinity()) return this; // 12M + 4S + 7A
  39885. var pz2 = p.z.redSqr();
  39886. var z2 = this.z.redSqr();
  39887. var u1 = this.x.redMul(pz2);
  39888. var u2 = p.x.redMul(z2);
  39889. var s1 = this.y.redMul(pz2.redMul(p.z));
  39890. var s2 = p.y.redMul(z2.redMul(this.z));
  39891. var h = u1.redSub(u2);
  39892. var r = s1.redSub(s2);
  39893. if (h.cmpn(0) === 0) {
  39894. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  39895. }
  39896. var h2 = h.redSqr();
  39897. var h3 = h2.redMul(h);
  39898. var v = u1.redMul(h2);
  39899. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  39900. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  39901. var nz = this.z.redMul(p.z).redMul(h);
  39902. return this.curve.jpoint(nx, ny, nz);
  39903. };
  39904. JPoint.prototype.mixedAdd = function mixedAdd(p) {
  39905. // O + P = P
  39906. if (this.isInfinity()) return p.toJ(); // P + O = P
  39907. if (p.isInfinity()) return this; // 8M + 3S + 7A
  39908. var z2 = this.z.redSqr();
  39909. var u1 = this.x;
  39910. var u2 = p.x.redMul(z2);
  39911. var s1 = this.y;
  39912. var s2 = p.y.redMul(z2).redMul(this.z);
  39913. var h = u1.redSub(u2);
  39914. var r = s1.redSub(s2);
  39915. if (h.cmpn(0) === 0) {
  39916. if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl();
  39917. }
  39918. var h2 = h.redSqr();
  39919. var h3 = h2.redMul(h);
  39920. var v = u1.redMul(h2);
  39921. var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
  39922. var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
  39923. var nz = this.z.redMul(h);
  39924. return this.curve.jpoint(nx, ny, nz);
  39925. };
  39926. JPoint.prototype.dblp = function dblp(pow) {
  39927. if (pow === 0) return this;
  39928. if (this.isInfinity()) return this;
  39929. if (!pow) return this.dbl();
  39930. var i;
  39931. if (this.curve.zeroA || this.curve.threeA) {
  39932. var r = this;
  39933. for (i = 0; i < pow; i++) {
  39934. r = r.dbl();
  39935. }
  39936. return r;
  39937. } // 1M + 2S + 1A + N * (4S + 5M + 8A)
  39938. // N = 1 => 6M + 6S + 9A
  39939. var a = this.curve.a;
  39940. var tinv = this.curve.tinv;
  39941. var jx = this.x;
  39942. var jy = this.y;
  39943. var jz = this.z;
  39944. var jz4 = jz.redSqr().redSqr(); // Reuse results
  39945. var jyd = jy.redAdd(jy);
  39946. for (i = 0; i < pow; i++) {
  39947. var jx2 = jx.redSqr();
  39948. var jyd2 = jyd.redSqr();
  39949. var jyd4 = jyd2.redSqr();
  39950. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  39951. var t1 = jx.redMul(jyd2);
  39952. var nx = c.redSqr().redISub(t1.redAdd(t1));
  39953. var t2 = t1.redISub(nx);
  39954. var dny = c.redMul(t2);
  39955. dny = dny.redIAdd(dny).redISub(jyd4);
  39956. var nz = jyd.redMul(jz);
  39957. if (i + 1 < pow) jz4 = jz4.redMul(jyd4);
  39958. jx = nx;
  39959. jz = nz;
  39960. jyd = dny;
  39961. }
  39962. return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
  39963. };
  39964. JPoint.prototype.dbl = function dbl() {
  39965. if (this.isInfinity()) return this;
  39966. if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl();
  39967. };
  39968. JPoint.prototype._zeroDbl = function _zeroDbl() {
  39969. var nx;
  39970. var ny;
  39971. var nz; // Z = 1
  39972. if (this.zOne) {
  39973. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  39974. // #doubling-mdbl-2007-bl
  39975. // 1M + 5S + 14A
  39976. // XX = X1^2
  39977. var xx = this.x.redSqr(); // YY = Y1^2
  39978. var yy = this.y.redSqr(); // YYYY = YY^2
  39979. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  39980. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  39981. s = s.redIAdd(s); // M = 3 * XX + a; a = 0
  39982. var m = xx.redAdd(xx).redIAdd(xx); // T = M ^ 2 - 2*S
  39983. var t = m.redSqr().redISub(s).redISub(s); // 8 * YYYY
  39984. var yyyy8 = yyyy.redIAdd(yyyy);
  39985. yyyy8 = yyyy8.redIAdd(yyyy8);
  39986. yyyy8 = yyyy8.redIAdd(yyyy8); // X3 = T
  39987. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  39988. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2*Y1
  39989. nz = this.y.redAdd(this.y);
  39990. } else {
  39991. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
  39992. // #doubling-dbl-2009-l
  39993. // 2M + 5S + 13A
  39994. // A = X1^2
  39995. var a = this.x.redSqr(); // B = Y1^2
  39996. var b = this.y.redSqr(); // C = B^2
  39997. var c = b.redSqr(); // D = 2 * ((X1 + B)^2 - A - C)
  39998. var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
  39999. d = d.redIAdd(d); // E = 3 * A
  40000. var e = a.redAdd(a).redIAdd(a); // F = E^2
  40001. var f = e.redSqr(); // 8 * C
  40002. var c8 = c.redIAdd(c);
  40003. c8 = c8.redIAdd(c8);
  40004. c8 = c8.redIAdd(c8); // X3 = F - 2 * D
  40005. nx = f.redISub(d).redISub(d); // Y3 = E * (D - X3) - 8 * C
  40006. ny = e.redMul(d.redISub(nx)).redISub(c8); // Z3 = 2 * Y1 * Z1
  40007. nz = this.y.redMul(this.z);
  40008. nz = nz.redIAdd(nz);
  40009. }
  40010. return this.curve.jpoint(nx, ny, nz);
  40011. };
  40012. JPoint.prototype._threeDbl = function _threeDbl() {
  40013. var nx;
  40014. var ny;
  40015. var nz; // Z = 1
  40016. if (this.zOne) {
  40017. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
  40018. // #doubling-mdbl-2007-bl
  40019. // 1M + 5S + 15A
  40020. // XX = X1^2
  40021. var xx = this.x.redSqr(); // YY = Y1^2
  40022. var yy = this.y.redSqr(); // YYYY = YY^2
  40023. var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY)
  40024. var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  40025. s = s.redIAdd(s); // M = 3 * XX + a
  40026. var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); // T = M^2 - 2 * S
  40027. var t = m.redSqr().redISub(s).redISub(s); // X3 = T
  40028. nx = t; // Y3 = M * (S - T) - 8 * YYYY
  40029. var yyyy8 = yyyy.redIAdd(yyyy);
  40030. yyyy8 = yyyy8.redIAdd(yyyy8);
  40031. yyyy8 = yyyy8.redIAdd(yyyy8);
  40032. ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2 * Y1
  40033. nz = this.y.redAdd(this.y);
  40034. } else {
  40035. // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
  40036. // 3M + 5S
  40037. // delta = Z1^2
  40038. var delta = this.z.redSqr(); // gamma = Y1^2
  40039. var gamma = this.y.redSqr(); // beta = X1 * gamma
  40040. var beta = this.x.redMul(gamma); // alpha = 3 * (X1 - delta) * (X1 + delta)
  40041. var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
  40042. alpha = alpha.redAdd(alpha).redIAdd(alpha); // X3 = alpha^2 - 8 * beta
  40043. var beta4 = beta.redIAdd(beta);
  40044. beta4 = beta4.redIAdd(beta4);
  40045. var beta8 = beta4.redAdd(beta4);
  40046. nx = alpha.redSqr().redISub(beta8); // Z3 = (Y1 + Z1)^2 - gamma - delta
  40047. nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
  40048. var ggamma8 = gamma.redSqr();
  40049. ggamma8 = ggamma8.redIAdd(ggamma8);
  40050. ggamma8 = ggamma8.redIAdd(ggamma8);
  40051. ggamma8 = ggamma8.redIAdd(ggamma8);
  40052. ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
  40053. }
  40054. return this.curve.jpoint(nx, ny, nz);
  40055. };
  40056. JPoint.prototype._dbl = function _dbl() {
  40057. var a = this.curve.a; // 4M + 6S + 10A
  40058. var jx = this.x;
  40059. var jy = this.y;
  40060. var jz = this.z;
  40061. var jz4 = jz.redSqr().redSqr();
  40062. var jx2 = jx.redSqr();
  40063. var jy2 = jy.redSqr();
  40064. var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
  40065. var jxd4 = jx.redAdd(jx);
  40066. jxd4 = jxd4.redIAdd(jxd4);
  40067. var t1 = jxd4.redMul(jy2);
  40068. var nx = c.redSqr().redISub(t1.redAdd(t1));
  40069. var t2 = t1.redISub(nx);
  40070. var jyd8 = jy2.redSqr();
  40071. jyd8 = jyd8.redIAdd(jyd8);
  40072. jyd8 = jyd8.redIAdd(jyd8);
  40073. jyd8 = jyd8.redIAdd(jyd8);
  40074. var ny = c.redMul(t2).redISub(jyd8);
  40075. var nz = jy.redAdd(jy).redMul(jz);
  40076. return this.curve.jpoint(nx, ny, nz);
  40077. };
  40078. JPoint.prototype.trpl = function trpl() {
  40079. if (!this.curve.zeroA) return this.dbl().add(this); // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
  40080. // 5M + 10S + ...
  40081. // XX = X1^2
  40082. var xx = this.x.redSqr(); // YY = Y1^2
  40083. var yy = this.y.redSqr(); // ZZ = Z1^2
  40084. var zz = this.z.redSqr(); // YYYY = YY^2
  40085. var yyyy = yy.redSqr(); // M = 3 * XX + a * ZZ2; a = 0
  40086. var m = xx.redAdd(xx).redIAdd(xx); // MM = M^2
  40087. var mm = m.redSqr(); // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
  40088. var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
  40089. e = e.redIAdd(e);
  40090. e = e.redAdd(e).redIAdd(e);
  40091. e = e.redISub(mm); // EE = E^2
  40092. var ee = e.redSqr(); // T = 16*YYYY
  40093. var t = yyyy.redIAdd(yyyy);
  40094. t = t.redIAdd(t);
  40095. t = t.redIAdd(t);
  40096. t = t.redIAdd(t); // U = (M + E)^2 - MM - EE - T
  40097. var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); // X3 = 4 * (X1 * EE - 4 * YY * U)
  40098. var yyu4 = yy.redMul(u);
  40099. yyu4 = yyu4.redIAdd(yyu4);
  40100. yyu4 = yyu4.redIAdd(yyu4);
  40101. var nx = this.x.redMul(ee).redISub(yyu4);
  40102. nx = nx.redIAdd(nx);
  40103. nx = nx.redIAdd(nx); // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
  40104. var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
  40105. ny = ny.redIAdd(ny);
  40106. ny = ny.redIAdd(ny);
  40107. ny = ny.redIAdd(ny); // Z3 = (Z1 + E)^2 - ZZ - EE
  40108. var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
  40109. return this.curve.jpoint(nx, ny, nz);
  40110. };
  40111. JPoint.prototype.mul = function mul(k, kbase) {
  40112. k = new BN(k, kbase);
  40113. return this.curve._wnafMul(this, k);
  40114. };
  40115. JPoint.prototype.eq = function eq(p) {
  40116. if (p.type === 'affine') return this.eq(p.toJ());
  40117. if (this === p) return true; // x1 * z2^2 == x2 * z1^2
  40118. var z2 = this.z.redSqr();
  40119. var pz2 = p.z.redSqr();
  40120. if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; // y1 * z2^3 == y2 * z1^3
  40121. var z3 = z2.redMul(this.z);
  40122. var pz3 = pz2.redMul(p.z);
  40123. return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
  40124. };
  40125. JPoint.prototype.eqXToP = function eqXToP(x) {
  40126. var zs = this.z.redSqr();
  40127. var rx = x.toRed(this.curve.red).redMul(zs);
  40128. if (this.x.cmp(rx) === 0) return true;
  40129. var xc = x.clone();
  40130. var t = this.curve.redN.redMul(zs);
  40131. for (;;) {
  40132. xc.iadd(this.curve.n);
  40133. if (xc.cmp(this.curve.p) >= 0) return false;
  40134. rx.redIAdd(t);
  40135. if (this.x.cmp(rx) === 0) return true;
  40136. }
  40137. };
  40138. JPoint.prototype.inspect = function inspect() {
  40139. if (this.isInfinity()) return '<EC JPoint Infinity>';
  40140. return '<EC JPoint x: ' + this.x.toString(16, 2) + ' y: ' + this.y.toString(16, 2) + ' z: ' + this.z.toString(16, 2) + '>';
  40141. };
  40142. JPoint.prototype.isInfinity = function isInfinity() {
  40143. // XXX This code assumes that zero is always zero in red
  40144. return this.z.cmpn(0) === 0;
  40145. };
  40146. /***/ }),
  40147. /***/ 1478:
  40148. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  40149. "use strict";
  40150. var curves = exports;
  40151. var hash = __webpack_require__(3192);
  40152. var curve = __webpack_require__(4720);
  40153. var utils = __webpack_require__(7891);
  40154. var assert = utils.assert;
  40155. function PresetCurve(options) {
  40156. if (options.type === 'short') this.curve = new curve["short"](options);else if (options.type === 'edwards') this.curve = new curve.edwards(options);else this.curve = new curve.mont(options);
  40157. this.g = this.curve.g;
  40158. this.n = this.curve.n;
  40159. this.hash = options.hash;
  40160. assert(this.g.validate(), 'Invalid curve');
  40161. assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, G*N != O');
  40162. }
  40163. curves.PresetCurve = PresetCurve;
  40164. function defineCurve(name, options) {
  40165. Object.defineProperty(curves, name, {
  40166. configurable: true,
  40167. enumerable: true,
  40168. get: function get() {
  40169. var curve = new PresetCurve(options);
  40170. Object.defineProperty(curves, name, {
  40171. configurable: true,
  40172. enumerable: true,
  40173. value: curve
  40174. });
  40175. return curve;
  40176. }
  40177. });
  40178. }
  40179. defineCurve('p192', {
  40180. type: 'short',
  40181. prime: 'p192',
  40182. p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
  40183. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
  40184. b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
  40185. n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
  40186. hash: hash.sha256,
  40187. gRed: false,
  40188. g: ['188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012', '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811']
  40189. });
  40190. defineCurve('p224', {
  40191. type: 'short',
  40192. prime: 'p224',
  40193. p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
  40194. a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
  40195. b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
  40196. n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
  40197. hash: hash.sha256,
  40198. gRed: false,
  40199. g: ['b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21', 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34']
  40200. });
  40201. defineCurve('p256', {
  40202. type: 'short',
  40203. prime: null,
  40204. p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
  40205. a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
  40206. b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
  40207. n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
  40208. hash: hash.sha256,
  40209. gRed: false,
  40210. g: ['6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296', '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5']
  40211. });
  40212. defineCurve('p384', {
  40213. type: 'short',
  40214. prime: null,
  40215. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 ffffffff',
  40216. a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'fffffffe ffffffff 00000000 00000000 fffffffc',
  40217. b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' + '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
  40218. n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' + 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
  40219. hash: hash.sha384,
  40220. gRed: false,
  40221. g: ['aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' + '5502f25d bf55296c 3a545e38 72760ab7', '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' + '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f']
  40222. });
  40223. defineCurve('p521', {
  40224. type: 'short',
  40225. prime: null,
  40226. p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff',
  40227. a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff ffffffff ffffffff fffffffc',
  40228. b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' + '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' + '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
  40229. n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' + 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' + 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
  40230. hash: hash.sha512,
  40231. gRed: false,
  40232. g: ['000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' + '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' + 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66', '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' + '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' + '3fad0761 353c7086 a272c240 88be9476 9fd16650']
  40233. });
  40234. defineCurve('curve25519', {
  40235. type: 'mont',
  40236. prime: 'p25519',
  40237. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  40238. a: '76d06',
  40239. b: '1',
  40240. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  40241. hash: hash.sha256,
  40242. gRed: false,
  40243. g: ['9']
  40244. });
  40245. defineCurve('ed25519', {
  40246. type: 'edwards',
  40247. prime: 'p25519',
  40248. p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
  40249. a: '-1',
  40250. c: '1',
  40251. // -121665 * (121666^(-1)) (mod P)
  40252. d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
  40253. n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
  40254. hash: hash.sha256,
  40255. gRed: false,
  40256. g: ['216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a', // 4/5
  40257. '6666666666666666666666666666666666666666666666666666666666666658']
  40258. });
  40259. var pre;
  40260. try {
  40261. pre = __webpack_require__(8948);
  40262. } catch (e) {
  40263. pre = undefined;
  40264. }
  40265. defineCurve('secp256k1', {
  40266. type: 'short',
  40267. prime: 'k256',
  40268. p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
  40269. a: '0',
  40270. b: '7',
  40271. n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
  40272. h: '1',
  40273. hash: hash.sha256,
  40274. // Precomputed endomorphism
  40275. beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
  40276. lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
  40277. basis: [{
  40278. a: '3086d221a7d46bcde86c90e49284eb15',
  40279. b: '-e4437ed6010e88286f547fa90abfe4c3'
  40280. }, {
  40281. a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
  40282. b: '3086d221a7d46bcde86c90e49284eb15'
  40283. }],
  40284. gRed: false,
  40285. g: ['79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8', pre]
  40286. });
  40287. /***/ }),
  40288. /***/ 5806:
  40289. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40290. "use strict";
  40291. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  40292. var BN = __webpack_require__(6781);
  40293. var HmacDRBG = __webpack_require__(9742);
  40294. var utils = __webpack_require__(7891);
  40295. var curves = __webpack_require__(1478);
  40296. var rand = __webpack_require__(7179);
  40297. var assert = utils.assert;
  40298. var KeyPair = __webpack_require__(3598);
  40299. var Signature = __webpack_require__(5206);
  40300. function EC(options) {
  40301. if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)`
  40302. if (typeof options === 'string') {
  40303. assert(Object.prototype.hasOwnProperty.call(curves, options), 'Unknown curve ' + options);
  40304. options = curves[options];
  40305. } // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
  40306. if (options instanceof curves.PresetCurve) options = {
  40307. curve: options
  40308. };
  40309. this.curve = options.curve.curve;
  40310. this.n = this.curve.n;
  40311. this.nh = this.n.ushrn(1);
  40312. this.g = this.curve.g; // Point on curve
  40313. this.g = options.curve.g;
  40314. this.g.precompute(options.curve.n.bitLength() + 1); // Hash for function for DRBG
  40315. this.hash = options.hash || options.curve.hash;
  40316. }
  40317. module.exports = EC;
  40318. EC.prototype.keyPair = function keyPair(options) {
  40319. return new KeyPair(this, options);
  40320. };
  40321. EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
  40322. return KeyPair.fromPrivate(this, priv, enc);
  40323. };
  40324. EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
  40325. return KeyPair.fromPublic(this, pub, enc);
  40326. };
  40327. EC.prototype.genKeyPair = function genKeyPair(options) {
  40328. if (!options) options = {}; // Instantiate Hmac_DRBG
  40329. var drbg = new HmacDRBG({
  40330. hash: this.hash,
  40331. pers: options.pers,
  40332. persEnc: options.persEnc || 'utf8',
  40333. entropy: options.entropy || rand(this.hash.hmacStrength),
  40334. entropyEnc: options.entropy && options.entropyEnc || 'utf8',
  40335. nonce: this.n.toArray()
  40336. });
  40337. var bytes = this.n.byteLength();
  40338. var ns2 = this.n.sub(new BN(2));
  40339. for (;;) {
  40340. var priv = new BN(drbg.generate(bytes));
  40341. if (priv.cmp(ns2) > 0) continue;
  40342. priv.iaddn(1);
  40343. return this.keyFromPrivate(priv);
  40344. }
  40345. };
  40346. EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) {
  40347. var delta = msg.byteLength() * 8 - this.n.bitLength();
  40348. if (delta > 0) msg = msg.ushrn(delta);
  40349. if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg;
  40350. };
  40351. EC.prototype.sign = function sign(msg, key, enc, options) {
  40352. if (_typeof(enc) === 'object') {
  40353. options = enc;
  40354. enc = null;
  40355. }
  40356. if (!options) options = {};
  40357. key = this.keyFromPrivate(key, enc);
  40358. msg = this._truncateToN(new BN(msg, 16)); // Zero-extend key to provide enough entropy
  40359. var bytes = this.n.byteLength();
  40360. var bkey = key.getPrivate().toArray('be', bytes); // Zero-extend nonce to have the same byte size as N
  40361. var nonce = msg.toArray('be', bytes); // Instantiate Hmac_DRBG
  40362. var drbg = new HmacDRBG({
  40363. hash: this.hash,
  40364. entropy: bkey,
  40365. nonce: nonce,
  40366. pers: options.pers,
  40367. persEnc: options.persEnc || 'utf8'
  40368. }); // Number of bytes to generate
  40369. var ns1 = this.n.sub(new BN(1));
  40370. for (var iter = 0;; iter++) {
  40371. var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength()));
  40372. k = this._truncateToN(k, true);
  40373. if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) continue;
  40374. var kp = this.g.mul(k);
  40375. if (kp.isInfinity()) continue;
  40376. var kpX = kp.getX();
  40377. var r = kpX.umod(this.n);
  40378. if (r.cmpn(0) === 0) continue;
  40379. var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));
  40380. s = s.umod(this.n);
  40381. if (s.cmpn(0) === 0) continue;
  40382. var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); // Use complement of `s`, if it is > `n / 2`
  40383. if (options.canonical && s.cmp(this.nh) > 0) {
  40384. s = this.n.sub(s);
  40385. recoveryParam ^= 1;
  40386. }
  40387. return new Signature({
  40388. r: r,
  40389. s: s,
  40390. recoveryParam: recoveryParam
  40391. });
  40392. }
  40393. };
  40394. EC.prototype.verify = function verify(msg, signature, key, enc) {
  40395. msg = this._truncateToN(new BN(msg, 16));
  40396. key = this.keyFromPublic(key, enc);
  40397. signature = new Signature(signature, 'hex'); // Perform primitive values validation
  40398. var r = signature.r;
  40399. var s = signature.s;
  40400. if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false;
  40401. if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; // Validate signature
  40402. var sinv = s.invm(this.n);
  40403. var u1 = sinv.mul(msg).umod(this.n);
  40404. var u2 = sinv.mul(r).umod(this.n);
  40405. var p;
  40406. if (!this.curve._maxwellTrick) {
  40407. p = this.g.mulAdd(u1, key.getPublic(), u2);
  40408. if (p.isInfinity()) return false;
  40409. return p.getX().umod(this.n).cmp(r) === 0;
  40410. } // NOTE: Greg Maxwell's trick, inspired by:
  40411. // https://git.io/vad3K
  40412. p = this.g.jmulAdd(u1, key.getPublic(), u2);
  40413. if (p.isInfinity()) return false; // Compare `p.x` of Jacobian point with `r`,
  40414. // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the
  40415. // inverse of `p.z^2`
  40416. return p.eqXToP(r);
  40417. };
  40418. EC.prototype.recoverPubKey = function (msg, signature, j, enc) {
  40419. assert((3 & j) === j, 'The recovery param is more than two bits');
  40420. signature = new Signature(signature, enc);
  40421. var n = this.n;
  40422. var e = new BN(msg);
  40423. var r = signature.r;
  40424. var s = signature.s; // A set LSB signifies that the y-coordinate is odd
  40425. var isYOdd = j & 1;
  40426. var isSecondKey = j >> 1;
  40427. if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error('Unable to find sencond key candinate'); // 1.1. Let x = r + jn.
  40428. if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd);
  40429. var rInv = signature.r.invm(n);
  40430. var s1 = n.sub(e).mul(rInv).umod(n);
  40431. var s2 = s.mul(rInv).umod(n); // 1.6.1 Compute Q = r^-1 (sR - eG)
  40432. // Q = r^-1 (sR + -eG)
  40433. return this.g.mulAdd(s1, r, s2);
  40434. };
  40435. EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) {
  40436. signature = new Signature(signature, enc);
  40437. if (signature.recoveryParam !== null) return signature.recoveryParam;
  40438. for (var i = 0; i < 4; i++) {
  40439. var Qprime;
  40440. try {
  40441. Qprime = this.recoverPubKey(e, signature, i);
  40442. } catch (e) {
  40443. continue;
  40444. }
  40445. if (Qprime.eq(Q)) return i;
  40446. }
  40447. throw new Error('Unable to find valid recovery factor');
  40448. };
  40449. /***/ }),
  40450. /***/ 3598:
  40451. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40452. "use strict";
  40453. var BN = __webpack_require__(6781);
  40454. var utils = __webpack_require__(7891);
  40455. var assert = utils.assert;
  40456. function KeyPair(ec, options) {
  40457. this.ec = ec;
  40458. this.priv = null;
  40459. this.pub = null; // KeyPair(ec, { priv: ..., pub: ... })
  40460. if (options.priv) this._importPrivate(options.priv, options.privEnc);
  40461. if (options.pub) this._importPublic(options.pub, options.pubEnc);
  40462. }
  40463. module.exports = KeyPair;
  40464. KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
  40465. if (pub instanceof KeyPair) return pub;
  40466. return new KeyPair(ec, {
  40467. pub: pub,
  40468. pubEnc: enc
  40469. });
  40470. };
  40471. KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
  40472. if (priv instanceof KeyPair) return priv;
  40473. return new KeyPair(ec, {
  40474. priv: priv,
  40475. privEnc: enc
  40476. });
  40477. };
  40478. KeyPair.prototype.validate = function validate() {
  40479. var pub = this.getPublic();
  40480. if (pub.isInfinity()) return {
  40481. result: false,
  40482. reason: 'Invalid public key'
  40483. };
  40484. if (!pub.validate()) return {
  40485. result: false,
  40486. reason: 'Public key is not a point'
  40487. };
  40488. if (!pub.mul(this.ec.curve.n).isInfinity()) return {
  40489. result: false,
  40490. reason: 'Public key * N != O'
  40491. };
  40492. return {
  40493. result: true,
  40494. reason: null
  40495. };
  40496. };
  40497. KeyPair.prototype.getPublic = function getPublic(compact, enc) {
  40498. // compact is optional argument
  40499. if (typeof compact === 'string') {
  40500. enc = compact;
  40501. compact = null;
  40502. }
  40503. if (!this.pub) this.pub = this.ec.g.mul(this.priv);
  40504. if (!enc) return this.pub;
  40505. return this.pub.encode(enc, compact);
  40506. };
  40507. KeyPair.prototype.getPrivate = function getPrivate(enc) {
  40508. if (enc === 'hex') return this.priv.toString(16, 2);else return this.priv;
  40509. };
  40510. KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
  40511. this.priv = new BN(key, enc || 16); // Ensure that the priv won't be bigger than n, otherwise we may fail
  40512. // in fixed multiplication method
  40513. this.priv = this.priv.umod(this.ec.curve.n);
  40514. };
  40515. KeyPair.prototype._importPublic = function _importPublic(key, enc) {
  40516. if (key.x || key.y) {
  40517. // Montgomery points only have an `x` coordinate.
  40518. // Weierstrass/Edwards points on the other hand have both `x` and
  40519. // `y` coordinates.
  40520. if (this.ec.curve.type === 'mont') {
  40521. assert(key.x, 'Need x coordinate');
  40522. } else if (this.ec.curve.type === 'short' || this.ec.curve.type === 'edwards') {
  40523. assert(key.x && key.y, 'Need both x and y coordinate');
  40524. }
  40525. this.pub = this.ec.curve.point(key.x, key.y);
  40526. return;
  40527. }
  40528. this.pub = this.ec.curve.decodePoint(key, enc);
  40529. }; // ECDH
  40530. KeyPair.prototype.derive = function derive(pub) {
  40531. if (!pub.validate()) {
  40532. assert(pub.validate(), 'public point not validated');
  40533. }
  40534. return pub.mul(this.priv).getX();
  40535. }; // ECDSA
  40536. KeyPair.prototype.sign = function sign(msg, enc, options) {
  40537. return this.ec.sign(msg, this, enc, options);
  40538. };
  40539. KeyPair.prototype.verify = function verify(msg, signature) {
  40540. return this.ec.verify(msg, signature, this);
  40541. };
  40542. KeyPair.prototype.inspect = function inspect() {
  40543. return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) + ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
  40544. };
  40545. /***/ }),
  40546. /***/ 5206:
  40547. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40548. "use strict";
  40549. var BN = __webpack_require__(6781);
  40550. var utils = __webpack_require__(7891);
  40551. var assert = utils.assert;
  40552. function Signature(options, enc) {
  40553. if (options instanceof Signature) return options;
  40554. if (this._importDER(options, enc)) return;
  40555. assert(options.r && options.s, 'Signature without r or s');
  40556. this.r = new BN(options.r, 16);
  40557. this.s = new BN(options.s, 16);
  40558. if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam;
  40559. }
  40560. module.exports = Signature;
  40561. function Position() {
  40562. this.place = 0;
  40563. }
  40564. function getLength(buf, p) {
  40565. var initial = buf[p.place++];
  40566. if (!(initial & 0x80)) {
  40567. return initial;
  40568. }
  40569. var octetLen = initial & 0xf; // Indefinite length or overflow
  40570. if (octetLen === 0 || octetLen > 4) {
  40571. return false;
  40572. }
  40573. var val = 0;
  40574. for (var i = 0, off = p.place; i < octetLen; i++, off++) {
  40575. val <<= 8;
  40576. val |= buf[off];
  40577. val >>>= 0;
  40578. } // Leading zeroes
  40579. if (val <= 0x7f) {
  40580. return false;
  40581. }
  40582. p.place = off;
  40583. return val;
  40584. }
  40585. function rmPadding(buf) {
  40586. var i = 0;
  40587. var len = buf.length - 1;
  40588. while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
  40589. i++;
  40590. }
  40591. if (i === 0) {
  40592. return buf;
  40593. }
  40594. return buf.slice(i);
  40595. }
  40596. Signature.prototype._importDER = function _importDER(data, enc) {
  40597. data = utils.toArray(data, enc);
  40598. var p = new Position();
  40599. if (data[p.place++] !== 0x30) {
  40600. return false;
  40601. }
  40602. var len = getLength(data, p);
  40603. if (len === false) {
  40604. return false;
  40605. }
  40606. if (len + p.place !== data.length) {
  40607. return false;
  40608. }
  40609. if (data[p.place++] !== 0x02) {
  40610. return false;
  40611. }
  40612. var rlen = getLength(data, p);
  40613. if (rlen === false) {
  40614. return false;
  40615. }
  40616. var r = data.slice(p.place, rlen + p.place);
  40617. p.place += rlen;
  40618. if (data[p.place++] !== 0x02) {
  40619. return false;
  40620. }
  40621. var slen = getLength(data, p);
  40622. if (slen === false) {
  40623. return false;
  40624. }
  40625. if (data.length !== slen + p.place) {
  40626. return false;
  40627. }
  40628. var s = data.slice(p.place, slen + p.place);
  40629. if (r[0] === 0) {
  40630. if (r[1] & 0x80) {
  40631. r = r.slice(1);
  40632. } else {
  40633. // Leading zeroes
  40634. return false;
  40635. }
  40636. }
  40637. if (s[0] === 0) {
  40638. if (s[1] & 0x80) {
  40639. s = s.slice(1);
  40640. } else {
  40641. // Leading zeroes
  40642. return false;
  40643. }
  40644. }
  40645. this.r = new BN(r);
  40646. this.s = new BN(s);
  40647. this.recoveryParam = null;
  40648. return true;
  40649. };
  40650. function constructLength(arr, len) {
  40651. if (len < 0x80) {
  40652. arr.push(len);
  40653. return;
  40654. }
  40655. var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
  40656. arr.push(octets | 0x80);
  40657. while (--octets) {
  40658. arr.push(len >>> (octets << 3) & 0xff);
  40659. }
  40660. arr.push(len);
  40661. }
  40662. Signature.prototype.toDER = function toDER(enc) {
  40663. var r = this.r.toArray();
  40664. var s = this.s.toArray(); // Pad values
  40665. if (r[0] & 0x80) r = [0].concat(r); // Pad values
  40666. if (s[0] & 0x80) s = [0].concat(s);
  40667. r = rmPadding(r);
  40668. s = rmPadding(s);
  40669. while (!s[0] && !(s[1] & 0x80)) {
  40670. s = s.slice(1);
  40671. }
  40672. var arr = [0x02];
  40673. constructLength(arr, r.length);
  40674. arr = arr.concat(r);
  40675. arr.push(0x02);
  40676. constructLength(arr, s.length);
  40677. var backHalf = arr.concat(s);
  40678. var res = [0x30];
  40679. constructLength(res, backHalf.length);
  40680. res = res.concat(backHalf);
  40681. return utils.encode(res, enc);
  40682. };
  40683. /***/ }),
  40684. /***/ 8318:
  40685. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40686. "use strict";
  40687. var hash = __webpack_require__(3192);
  40688. var curves = __webpack_require__(1478);
  40689. var utils = __webpack_require__(7891);
  40690. var assert = utils.assert;
  40691. var parseBytes = utils.parseBytes;
  40692. var KeyPair = __webpack_require__(9371);
  40693. var Signature = __webpack_require__(2214);
  40694. function EDDSA(curve) {
  40695. assert(curve === 'ed25519', 'only tested with ed25519 so far');
  40696. if (!(this instanceof EDDSA)) return new EDDSA(curve);
  40697. curve = curves[curve].curve;
  40698. this.curve = curve;
  40699. this.g = curve.g;
  40700. this.g.precompute(curve.n.bitLength() + 1);
  40701. this.pointClass = curve.point().constructor;
  40702. this.encodingLength = Math.ceil(curve.n.bitLength() / 8);
  40703. this.hash = hash.sha512;
  40704. }
  40705. module.exports = EDDSA;
  40706. /**
  40707. * @param {Array|String} message - message bytes
  40708. * @param {Array|String|KeyPair} secret - secret bytes or a keypair
  40709. * @returns {Signature} - signature
  40710. */
  40711. EDDSA.prototype.sign = function sign(message, secret) {
  40712. message = parseBytes(message);
  40713. var key = this.keyFromSecret(secret);
  40714. var r = this.hashInt(key.messagePrefix(), message);
  40715. var R = this.g.mul(r);
  40716. var Rencoded = this.encodePoint(R);
  40717. var s_ = this.hashInt(Rencoded, key.pubBytes(), message).mul(key.priv());
  40718. var S = r.add(s_).umod(this.curve.n);
  40719. return this.makeSignature({
  40720. R: R,
  40721. S: S,
  40722. Rencoded: Rencoded
  40723. });
  40724. };
  40725. /**
  40726. * @param {Array} message - message bytes
  40727. * @param {Array|String|Signature} sig - sig bytes
  40728. * @param {Array|String|Point|KeyPair} pub - public key
  40729. * @returns {Boolean} - true if public key matches sig of message
  40730. */
  40731. EDDSA.prototype.verify = function verify(message, sig, pub) {
  40732. message = parseBytes(message);
  40733. sig = this.makeSignature(sig);
  40734. var key = this.keyFromPublic(pub);
  40735. var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message);
  40736. var SG = this.g.mul(sig.S());
  40737. var RplusAh = sig.R().add(key.pub().mul(h));
  40738. return RplusAh.eq(SG);
  40739. };
  40740. EDDSA.prototype.hashInt = function hashInt() {
  40741. var hash = this.hash();
  40742. for (var i = 0; i < arguments.length; i++) {
  40743. hash.update(arguments[i]);
  40744. }
  40745. return utils.intFromLE(hash.digest()).umod(this.curve.n);
  40746. };
  40747. EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) {
  40748. return KeyPair.fromPublic(this, pub);
  40749. };
  40750. EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) {
  40751. return KeyPair.fromSecret(this, secret);
  40752. };
  40753. EDDSA.prototype.makeSignature = function makeSignature(sig) {
  40754. if (sig instanceof Signature) return sig;
  40755. return new Signature(this, sig);
  40756. };
  40757. /**
  40758. * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2
  40759. *
  40760. * EDDSA defines methods for encoding and decoding points and integers. These are
  40761. * helper convenience methods, that pass along to utility functions implied
  40762. * parameters.
  40763. *
  40764. */
  40765. EDDSA.prototype.encodePoint = function encodePoint(point) {
  40766. var enc = point.getY().toArray('le', this.encodingLength);
  40767. enc[this.encodingLength - 1] |= point.getX().isOdd() ? 0x80 : 0;
  40768. return enc;
  40769. };
  40770. EDDSA.prototype.decodePoint = function decodePoint(bytes) {
  40771. bytes = utils.parseBytes(bytes);
  40772. var lastIx = bytes.length - 1;
  40773. var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~0x80);
  40774. var xIsOdd = (bytes[lastIx] & 0x80) !== 0;
  40775. var y = utils.intFromLE(normed);
  40776. return this.curve.pointFromY(y, xIsOdd);
  40777. };
  40778. EDDSA.prototype.encodeInt = function encodeInt(num) {
  40779. return num.toArray('le', this.encodingLength);
  40780. };
  40781. EDDSA.prototype.decodeInt = function decodeInt(bytes) {
  40782. return utils.intFromLE(bytes);
  40783. };
  40784. EDDSA.prototype.isPoint = function isPoint(val) {
  40785. return val instanceof this.pointClass;
  40786. };
  40787. /***/ }),
  40788. /***/ 9371:
  40789. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40790. "use strict";
  40791. var utils = __webpack_require__(7891);
  40792. var assert = utils.assert;
  40793. var parseBytes = utils.parseBytes;
  40794. var cachedProperty = utils.cachedProperty;
  40795. /**
  40796. * @param {EDDSA} eddsa - instance
  40797. * @param {Object} params - public/private key parameters
  40798. *
  40799. * @param {Array<Byte>} [params.secret] - secret seed bytes
  40800. * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms)
  40801. * @param {Array<Byte>} [params.pub] - public key point encoded as bytes
  40802. *
  40803. */
  40804. function KeyPair(eddsa, params) {
  40805. this.eddsa = eddsa;
  40806. this._secret = parseBytes(params.secret);
  40807. if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub);
  40808. }
  40809. KeyPair.fromPublic = function fromPublic(eddsa, pub) {
  40810. if (pub instanceof KeyPair) return pub;
  40811. return new KeyPair(eddsa, {
  40812. pub: pub
  40813. });
  40814. };
  40815. KeyPair.fromSecret = function fromSecret(eddsa, secret) {
  40816. if (secret instanceof KeyPair) return secret;
  40817. return new KeyPair(eddsa, {
  40818. secret: secret
  40819. });
  40820. };
  40821. KeyPair.prototype.secret = function secret() {
  40822. return this._secret;
  40823. };
  40824. cachedProperty(KeyPair, 'pubBytes', function pubBytes() {
  40825. return this.eddsa.encodePoint(this.pub());
  40826. });
  40827. cachedProperty(KeyPair, 'pub', function pub() {
  40828. if (this._pubBytes) return this.eddsa.decodePoint(this._pubBytes);
  40829. return this.eddsa.g.mul(this.priv());
  40830. });
  40831. cachedProperty(KeyPair, 'privBytes', function privBytes() {
  40832. var eddsa = this.eddsa;
  40833. var hash = this.hash();
  40834. var lastIx = eddsa.encodingLength - 1;
  40835. var a = hash.slice(0, eddsa.encodingLength);
  40836. a[0] &= 248;
  40837. a[lastIx] &= 127;
  40838. a[lastIx] |= 64;
  40839. return a;
  40840. });
  40841. cachedProperty(KeyPair, 'priv', function priv() {
  40842. return this.eddsa.decodeInt(this.privBytes());
  40843. });
  40844. cachedProperty(KeyPair, 'hash', function hash() {
  40845. return this.eddsa.hash().update(this.secret()).digest();
  40846. });
  40847. cachedProperty(KeyPair, 'messagePrefix', function messagePrefix() {
  40848. return this.hash().slice(this.eddsa.encodingLength);
  40849. });
  40850. KeyPair.prototype.sign = function sign(message) {
  40851. assert(this._secret, 'KeyPair can only verify');
  40852. return this.eddsa.sign(message, this);
  40853. };
  40854. KeyPair.prototype.verify = function verify(message, sig) {
  40855. return this.eddsa.verify(message, sig, this);
  40856. };
  40857. KeyPair.prototype.getSecret = function getSecret(enc) {
  40858. assert(this._secret, 'KeyPair is public only');
  40859. return utils.encode(this.secret(), enc);
  40860. };
  40861. KeyPair.prototype.getPublic = function getPublic(enc) {
  40862. return utils.encode(this.pubBytes(), enc);
  40863. };
  40864. module.exports = KeyPair;
  40865. /***/ }),
  40866. /***/ 2214:
  40867. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  40868. "use strict";
  40869. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  40870. var BN = __webpack_require__(6781);
  40871. var utils = __webpack_require__(7891);
  40872. var assert = utils.assert;
  40873. var cachedProperty = utils.cachedProperty;
  40874. var parseBytes = utils.parseBytes;
  40875. /**
  40876. * @param {EDDSA} eddsa - eddsa instance
  40877. * @param {Array<Bytes>|Object} sig -
  40878. * @param {Array<Bytes>|Point} [sig.R] - R point as Point or bytes
  40879. * @param {Array<Bytes>|bn} [sig.S] - S scalar as bn or bytes
  40880. * @param {Array<Bytes>} [sig.Rencoded] - R point encoded
  40881. * @param {Array<Bytes>} [sig.Sencoded] - S scalar encoded
  40882. */
  40883. function Signature(eddsa, sig) {
  40884. this.eddsa = eddsa;
  40885. if (_typeof(sig) !== 'object') sig = parseBytes(sig);
  40886. if (Array.isArray(sig)) {
  40887. sig = {
  40888. R: sig.slice(0, eddsa.encodingLength),
  40889. S: sig.slice(eddsa.encodingLength)
  40890. };
  40891. }
  40892. assert(sig.R && sig.S, 'Signature without R or S');
  40893. if (eddsa.isPoint(sig.R)) this._R = sig.R;
  40894. if (sig.S instanceof BN) this._S = sig.S;
  40895. this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded;
  40896. this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded;
  40897. }
  40898. cachedProperty(Signature, 'S', function S() {
  40899. return this.eddsa.decodeInt(this.Sencoded());
  40900. });
  40901. cachedProperty(Signature, 'R', function R() {
  40902. return this.eddsa.decodePoint(this.Rencoded());
  40903. });
  40904. cachedProperty(Signature, 'Rencoded', function Rencoded() {
  40905. return this.eddsa.encodePoint(this.R());
  40906. });
  40907. cachedProperty(Signature, 'Sencoded', function Sencoded() {
  40908. return this.eddsa.encodeInt(this.S());
  40909. });
  40910. Signature.prototype.toBytes = function toBytes() {
  40911. return this.Rencoded().concat(this.Sencoded());
  40912. };
  40913. Signature.prototype.toHex = function toHex() {
  40914. return utils.encode(this.toBytes(), 'hex').toUpperCase();
  40915. };
  40916. module.exports = Signature;
  40917. /***/ }),
  40918. /***/ 8948:
  40919. /***/ ((module) => {
  40920. module.exports = {
  40921. doubles: {
  40922. step: 4,
  40923. points: [['e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a', 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'], ['8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508', '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'], ['175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739', 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'], ['363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640', '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'], ['8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c', '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'], ['723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda', '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'], ['eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa', '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'], ['100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0', 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'], ['e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d', '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'], ['feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d', 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'], ['da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1', '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'], ['53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0', '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'], ['8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047', '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'], ['385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862', '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'], ['6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7', '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'], ['3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd', '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'], ['85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83', '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'], ['948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a', '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'], ['6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8', 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'], ['e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d', '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'], ['e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725', '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'], ['213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754', '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'], ['4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c', '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'], ['fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6', '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'], ['76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39', 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'], ['c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891', '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'], ['d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b', 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'], ['b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03', '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'], ['e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d', 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'], ['a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070', '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'], ['90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4', 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'], ['8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da', '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'], ['e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11', '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'], ['8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e', 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'], ['e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41', '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'], ['b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef', '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'], ['d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8', 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'], ['324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d', '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'], ['4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96', '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'], ['9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd', 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'], ['6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5', '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'], ['a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266', '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'], ['7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71', '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'], ['928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac', 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'], ['85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751', '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'], ['ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e', '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'], ['827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241', 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'], ['eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3', 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'], ['e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f', '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'], ['1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19', 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'], ['146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be', 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'], ['fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9', '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'], ['da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2', '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'], ['a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13', '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'], ['174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c', 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'], ['959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba', '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'], ['d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151', 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'], ['64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073', 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'], ['8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458', '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'], ['13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b', '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'], ['bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366', 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'], ['8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa', '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'], ['8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0', '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'], ['dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787', '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'], ['f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e', 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82']]
  40924. },
  40925. naf: {
  40926. wnd: 7,
  40927. points: [['f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9', '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'], ['2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4', 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'], ['5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc', '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'], ['acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe', 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'], ['774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb', 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'], ['f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8', 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'], ['d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e', '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'], ['defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34', '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'], ['2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c', '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'], ['352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5', '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'], ['2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f', '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'], ['9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714', '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'], ['daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729', 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'], ['c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db', '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'], ['6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4', 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'], ['1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5', 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'], ['605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479', '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'], ['62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d', '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'], ['80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f', '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'], ['7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb', 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'], ['d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9', 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'], ['49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963', '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'], ['77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74', '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'], ['f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530', 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'], ['463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b', '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'], ['f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247', 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'], ['caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1', 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'], ['2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120', '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'], ['7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435', '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'], ['754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18', '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'], ['e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8', '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'], ['186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb', '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'], ['df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f', '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'], ['5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143', 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'], ['290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba', 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'], ['af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45', 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'], ['766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a', '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'], ['59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e', 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'], ['f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8', 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'], ['7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c', '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'], ['948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519', 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'], ['7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab', '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'], ['3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca', 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'], ['d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf', '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'], ['1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610', '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'], ['733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4', 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'], ['15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c', 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'], ['a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940', 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'], ['e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980', 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'], ['311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3', '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'], ['34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf', '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'], ['f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63', '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'], ['d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448', 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'], ['32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf', '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'], ['7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5', '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'], ['ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6', '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'], ['16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5', '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'], ['eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99', 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'], ['78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51', 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'], ['494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5', '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'], ['a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5', '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'], ['c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997', '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'], ['841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881', '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'], ['5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5', '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'], ['36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66', 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'], ['336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726', 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'], ['8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede', '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'], ['1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94', '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'], ['85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31', '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'], ['29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51', 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'], ['a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252', 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'], ['4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5', 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'], ['d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b', '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'], ['ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4', '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'], ['af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f', '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'], ['e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889', '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'], ['591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246', 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'], ['11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984', '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'], ['3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a', 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'], ['cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030', 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'], ['c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197', '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'], ['c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593', 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'], ['a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef', '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'], ['347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38', '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'], ['da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a', '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'], ['c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111', '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'], ['4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502', '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'], ['3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea', 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'], ['cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26', '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'], ['b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986', '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'], ['d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e', '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'], ['48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4', '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'], ['dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda', 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'], ['6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859', 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'], ['e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f', 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'], ['eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c', '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'], ['13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942', 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'], ['ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a', '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'], ['b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80', '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'], ['ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d', '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'], ['8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1', 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'], ['52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63', 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'], ['e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352', '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'], ['7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193', 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'], ['5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00', '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'], ['32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58', 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'], ['e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7', 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'], ['8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8', 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'], ['4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e', '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'], ['3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d', 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'], ['674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b', '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'], ['d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f', 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'], ['30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6', '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'], ['be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297', '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'], ['93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a', '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'], ['b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c', 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'], ['d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52', '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'], ['d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb', 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'], ['463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065', 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'], ['7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917', '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'], ['74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9', 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'], ['30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3', '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'], ['9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57', '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'], ['176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66', 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'], ['75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8', '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'], ['809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721', '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'], ['1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180', '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9']]
  40928. }
  40929. };
  40930. /***/ }),
  40931. /***/ 7891:
  40932. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  40933. "use strict";
  40934. var utils = exports;
  40935. var BN = __webpack_require__(6781);
  40936. var minAssert = __webpack_require__(1130);
  40937. var minUtils = __webpack_require__(5522);
  40938. utils.assert = minAssert;
  40939. utils.toArray = minUtils.toArray;
  40940. utils.zero2 = minUtils.zero2;
  40941. utils.toHex = minUtils.toHex;
  40942. utils.encode = minUtils.encode; // Represent num in a w-NAF form
  40943. function getNAF(num, w, bits) {
  40944. var naf = new Array(Math.max(num.bitLength(), bits) + 1);
  40945. naf.fill(0);
  40946. var ws = 1 << w + 1;
  40947. var k = num.clone();
  40948. for (var i = 0; i < naf.length; i++) {
  40949. var z;
  40950. var mod = k.andln(ws - 1);
  40951. if (k.isOdd()) {
  40952. if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod;
  40953. k.isubn(z);
  40954. } else {
  40955. z = 0;
  40956. }
  40957. naf[i] = z;
  40958. k.iushrn(1);
  40959. }
  40960. return naf;
  40961. }
  40962. utils.getNAF = getNAF; // Represent k1, k2 in a Joint Sparse Form
  40963. function getJSF(k1, k2) {
  40964. var jsf = [[], []];
  40965. k1 = k1.clone();
  40966. k2 = k2.clone();
  40967. var d1 = 0;
  40968. var d2 = 0;
  40969. var m8;
  40970. while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
  40971. // First phase
  40972. var m14 = k1.andln(3) + d1 & 3;
  40973. var m24 = k2.andln(3) + d2 & 3;
  40974. if (m14 === 3) m14 = -1;
  40975. if (m24 === 3) m24 = -1;
  40976. var u1;
  40977. if ((m14 & 1) === 0) {
  40978. u1 = 0;
  40979. } else {
  40980. m8 = k1.andln(7) + d1 & 7;
  40981. if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14;
  40982. }
  40983. jsf[0].push(u1);
  40984. var u2;
  40985. if ((m24 & 1) === 0) {
  40986. u2 = 0;
  40987. } else {
  40988. m8 = k2.andln(7) + d2 & 7;
  40989. if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24;
  40990. }
  40991. jsf[1].push(u2); // Second phase
  40992. if (2 * d1 === u1 + 1) d1 = 1 - d1;
  40993. if (2 * d2 === u2 + 1) d2 = 1 - d2;
  40994. k1.iushrn(1);
  40995. k2.iushrn(1);
  40996. }
  40997. return jsf;
  40998. }
  40999. utils.getJSF = getJSF;
  41000. function cachedProperty(obj, name, computer) {
  41001. var key = '_' + name;
  41002. obj.prototype[name] = function cachedProperty() {
  41003. return this[key] !== undefined ? this[key] : this[key] = computer.call(this);
  41004. };
  41005. }
  41006. utils.cachedProperty = cachedProperty;
  41007. function parseBytes(bytes) {
  41008. return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') : bytes;
  41009. }
  41010. utils.parseBytes = parseBytes;
  41011. function intFromLE(bytes) {
  41012. return new BN(bytes, 'hex', 'le');
  41013. }
  41014. utils.intFromLE = intFromLE;
  41015. /***/ }),
  41016. /***/ 8028:
  41017. /***/ ((module) => {
  41018. "use strict";
  41019. /**
  41020. * Code refactored from Mozilla Developer Network:
  41021. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  41022. */
  41023. function assign(target, firstSource) {
  41024. if (target === undefined || target === null) {
  41025. throw new TypeError('Cannot convert first argument to object');
  41026. }
  41027. var to = Object(target);
  41028. for (var i = 1; i < arguments.length; i++) {
  41029. var nextSource = arguments[i];
  41030. if (nextSource === undefined || nextSource === null) {
  41031. continue;
  41032. }
  41033. var keysArray = Object.keys(Object(nextSource));
  41034. for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
  41035. var nextKey = keysArray[nextIndex];
  41036. var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
  41037. if (desc !== undefined && desc.enumerable) {
  41038. to[nextKey] = nextSource[nextKey];
  41039. }
  41040. }
  41041. }
  41042. return to;
  41043. }
  41044. function polyfill() {
  41045. if (!Object.assign) {
  41046. Object.defineProperty(Object, 'assign', {
  41047. enumerable: false,
  41048. configurable: true,
  41049. writable: true,
  41050. value: assign
  41051. });
  41052. }
  41053. }
  41054. module.exports = {
  41055. assign: assign,
  41056. polyfill: polyfill
  41057. };
  41058. /***/ }),
  41059. /***/ 9620:
  41060. /***/ ((module) => {
  41061. "use strict";
  41062. // Copyright Joyent, Inc. and other Node contributors.
  41063. //
  41064. // Permission is hereby granted, free of charge, to any person obtaining a
  41065. // copy of this software and associated documentation files (the
  41066. // "Software"), to deal in the Software without restriction, including
  41067. // without limitation the rights to use, copy, modify, merge, publish,
  41068. // distribute, sublicense, and/or sell copies of the Software, and to permit
  41069. // persons to whom the Software is furnished to do so, subject to the
  41070. // following conditions:
  41071. //
  41072. // The above copyright notice and this permission notice shall be included
  41073. // in all copies or substantial portions of the Software.
  41074. //
  41075. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  41076. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  41077. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  41078. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  41079. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  41080. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  41081. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  41082. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  41083. var R = (typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === 'object' ? Reflect : null;
  41084. var ReflectApply = R && typeof R.apply === 'function' ? R.apply : function ReflectApply(target, receiver, args) {
  41085. return Function.prototype.apply.call(target, receiver, args);
  41086. };
  41087. var ReflectOwnKeys;
  41088. if (R && typeof R.ownKeys === 'function') {
  41089. ReflectOwnKeys = R.ownKeys;
  41090. } else if (Object.getOwnPropertySymbols) {
  41091. ReflectOwnKeys = function ReflectOwnKeys(target) {
  41092. return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
  41093. };
  41094. } else {
  41095. ReflectOwnKeys = function ReflectOwnKeys(target) {
  41096. return Object.getOwnPropertyNames(target);
  41097. };
  41098. }
  41099. function ProcessEmitWarning(warning) {
  41100. if (console && console.warn) console.warn(warning);
  41101. }
  41102. var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
  41103. return value !== value;
  41104. };
  41105. function EventEmitter() {
  41106. EventEmitter.init.call(this);
  41107. }
  41108. module.exports = EventEmitter;
  41109. module.exports.once = once; // Backwards-compat with node 0.10.x
  41110. EventEmitter.EventEmitter = EventEmitter;
  41111. EventEmitter.prototype._events = undefined;
  41112. EventEmitter.prototype._eventsCount = 0;
  41113. EventEmitter.prototype._maxListeners = undefined; // By default EventEmitters will print a warning if more than 10 listeners are
  41114. // added to it. This is a useful default which helps finding memory leaks.
  41115. var defaultMaxListeners = 10;
  41116. function checkListener(listener) {
  41117. if (typeof listener !== 'function') {
  41118. throw new TypeError('The "listener" argument must be of type Function. Received type ' + _typeof(listener));
  41119. }
  41120. }
  41121. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  41122. enumerable: true,
  41123. get: function get() {
  41124. return defaultMaxListeners;
  41125. },
  41126. set: function set(arg) {
  41127. if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
  41128. throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
  41129. }
  41130. defaultMaxListeners = arg;
  41131. }
  41132. });
  41133. EventEmitter.init = function () {
  41134. if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) {
  41135. this._events = Object.create(null);
  41136. this._eventsCount = 0;
  41137. }
  41138. this._maxListeners = this._maxListeners || undefined;
  41139. }; // Obviously not all Emitters should be limited to 10. This function allows
  41140. // that to be increased. Set to zero for unlimited.
  41141. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  41142. if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
  41143. throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
  41144. }
  41145. this._maxListeners = n;
  41146. return this;
  41147. };
  41148. function _getMaxListeners(that) {
  41149. if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners;
  41150. return that._maxListeners;
  41151. }
  41152. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  41153. return _getMaxListeners(this);
  41154. };
  41155. EventEmitter.prototype.emit = function emit(type) {
  41156. var args = [];
  41157. for (var i = 1; i < arguments.length; i++) {
  41158. args.push(arguments[i]);
  41159. }
  41160. var doError = type === 'error';
  41161. var events = this._events;
  41162. if (events !== undefined) doError = doError && events.error === undefined;else if (!doError) return false; // If there is no 'error' event listener then throw.
  41163. if (doError) {
  41164. var er;
  41165. if (args.length > 0) er = args[0];
  41166. if (er instanceof Error) {
  41167. // Note: The comments on the `throw` lines are intentional, they show
  41168. // up in Node's output if this results in an unhandled exception.
  41169. throw er; // Unhandled 'error' event
  41170. } // At least give some kind of context to the user
  41171. var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
  41172. err.context = er;
  41173. throw err; // Unhandled 'error' event
  41174. }
  41175. var handler = events[type];
  41176. if (handler === undefined) return false;
  41177. if (typeof handler === 'function') {
  41178. ReflectApply(handler, this, args);
  41179. } else {
  41180. var len = handler.length;
  41181. var listeners = arrayClone(handler, len);
  41182. for (var i = 0; i < len; ++i) {
  41183. ReflectApply(listeners[i], this, args);
  41184. }
  41185. }
  41186. return true;
  41187. };
  41188. function _addListener(target, type, listener, prepend) {
  41189. var m;
  41190. var events;
  41191. var existing;
  41192. checkListener(listener);
  41193. events = target._events;
  41194. if (events === undefined) {
  41195. events = target._events = Object.create(null);
  41196. target._eventsCount = 0;
  41197. } else {
  41198. // To avoid recursion in the case that type === "newListener"! Before
  41199. // adding it to the listeners, first emit "newListener".
  41200. if (events.newListener !== undefined) {
  41201. target.emit('newListener', type, listener.listener ? listener.listener : listener); // Re-assign `events` because a newListener handler could have caused the
  41202. // this._events to be assigned to a new object
  41203. events = target._events;
  41204. }
  41205. existing = events[type];
  41206. }
  41207. if (existing === undefined) {
  41208. // Optimize the case of one listener. Don't need the extra array object.
  41209. existing = events[type] = listener;
  41210. ++target._eventsCount;
  41211. } else {
  41212. if (typeof existing === 'function') {
  41213. // Adding the second element, need to change to array.
  41214. existing = events[type] = prepend ? [listener, existing] : [existing, listener]; // If we've already got an array, just append.
  41215. } else if (prepend) {
  41216. existing.unshift(listener);
  41217. } else {
  41218. existing.push(listener);
  41219. } // Check for listener leak
  41220. m = _getMaxListeners(target);
  41221. if (m > 0 && existing.length > m && !existing.warned) {
  41222. existing.warned = true; // No error code for this since it is a Warning
  41223. // eslint-disable-next-line no-restricted-syntax
  41224. var w = new Error('Possible EventEmitter memory leak detected. ' + existing.length + ' ' + String(type) + ' listeners ' + 'added. Use emitter.setMaxListeners() to ' + 'increase limit');
  41225. w.name = 'MaxListenersExceededWarning';
  41226. w.emitter = target;
  41227. w.type = type;
  41228. w.count = existing.length;
  41229. ProcessEmitWarning(w);
  41230. }
  41231. }
  41232. return target;
  41233. }
  41234. EventEmitter.prototype.addListener = function addListener(type, listener) {
  41235. return _addListener(this, type, listener, false);
  41236. };
  41237. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  41238. EventEmitter.prototype.prependListener = function prependListener(type, listener) {
  41239. return _addListener(this, type, listener, true);
  41240. };
  41241. function onceWrapper() {
  41242. if (!this.fired) {
  41243. this.target.removeListener(this.type, this.wrapFn);
  41244. this.fired = true;
  41245. if (arguments.length === 0) return this.listener.call(this.target);
  41246. return this.listener.apply(this.target, arguments);
  41247. }
  41248. }
  41249. function _onceWrap(target, type, listener) {
  41250. var state = {
  41251. fired: false,
  41252. wrapFn: undefined,
  41253. target: target,
  41254. type: type,
  41255. listener: listener
  41256. };
  41257. var wrapped = onceWrapper.bind(state);
  41258. wrapped.listener = listener;
  41259. state.wrapFn = wrapped;
  41260. return wrapped;
  41261. }
  41262. EventEmitter.prototype.once = function once(type, listener) {
  41263. checkListener(listener);
  41264. this.on(type, _onceWrap(this, type, listener));
  41265. return this;
  41266. };
  41267. EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) {
  41268. checkListener(listener);
  41269. this.prependListener(type, _onceWrap(this, type, listener));
  41270. return this;
  41271. }; // Emits a 'removeListener' event if and only if the listener was removed.
  41272. EventEmitter.prototype.removeListener = function removeListener(type, listener) {
  41273. var list, events, position, i, originalListener;
  41274. checkListener(listener);
  41275. events = this._events;
  41276. if (events === undefined) return this;
  41277. list = events[type];
  41278. if (list === undefined) return this;
  41279. if (list === listener || list.listener === listener) {
  41280. if (--this._eventsCount === 0) this._events = Object.create(null);else {
  41281. delete events[type];
  41282. if (events.removeListener) this.emit('removeListener', type, list.listener || listener);
  41283. }
  41284. } else if (typeof list !== 'function') {
  41285. position = -1;
  41286. for (i = list.length - 1; i >= 0; i--) {
  41287. if (list[i] === listener || list[i].listener === listener) {
  41288. originalListener = list[i].listener;
  41289. position = i;
  41290. break;
  41291. }
  41292. }
  41293. if (position < 0) return this;
  41294. if (position === 0) list.shift();else {
  41295. spliceOne(list, position);
  41296. }
  41297. if (list.length === 1) events[type] = list[0];
  41298. if (events.removeListener !== undefined) this.emit('removeListener', type, originalListener || listener);
  41299. }
  41300. return this;
  41301. };
  41302. EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
  41303. EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) {
  41304. var listeners, events, i;
  41305. events = this._events;
  41306. if (events === undefined) return this; // not listening for removeListener, no need to emit
  41307. if (events.removeListener === undefined) {
  41308. if (arguments.length === 0) {
  41309. this._events = Object.create(null);
  41310. this._eventsCount = 0;
  41311. } else if (events[type] !== undefined) {
  41312. if (--this._eventsCount === 0) this._events = Object.create(null);else delete events[type];
  41313. }
  41314. return this;
  41315. } // emit removeListener for all listeners on all events
  41316. if (arguments.length === 0) {
  41317. var keys = Object.keys(events);
  41318. var key;
  41319. for (i = 0; i < keys.length; ++i) {
  41320. key = keys[i];
  41321. if (key === 'removeListener') continue;
  41322. this.removeAllListeners(key);
  41323. }
  41324. this.removeAllListeners('removeListener');
  41325. this._events = Object.create(null);
  41326. this._eventsCount = 0;
  41327. return this;
  41328. }
  41329. listeners = events[type];
  41330. if (typeof listeners === 'function') {
  41331. this.removeListener(type, listeners);
  41332. } else if (listeners !== undefined) {
  41333. // LIFO order
  41334. for (i = listeners.length - 1; i >= 0; i--) {
  41335. this.removeListener(type, listeners[i]);
  41336. }
  41337. }
  41338. return this;
  41339. };
  41340. function _listeners(target, type, unwrap) {
  41341. var events = target._events;
  41342. if (events === undefined) return [];
  41343. var evlistener = events[type];
  41344. if (evlistener === undefined) return [];
  41345. if (typeof evlistener === 'function') return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  41346. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  41347. }
  41348. EventEmitter.prototype.listeners = function listeners(type) {
  41349. return _listeners(this, type, true);
  41350. };
  41351. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  41352. return _listeners(this, type, false);
  41353. };
  41354. EventEmitter.listenerCount = function (emitter, type) {
  41355. if (typeof emitter.listenerCount === 'function') {
  41356. return emitter.listenerCount(type);
  41357. } else {
  41358. return listenerCount.call(emitter, type);
  41359. }
  41360. };
  41361. EventEmitter.prototype.listenerCount = listenerCount;
  41362. function listenerCount(type) {
  41363. var events = this._events;
  41364. if (events !== undefined) {
  41365. var evlistener = events[type];
  41366. if (typeof evlistener === 'function') {
  41367. return 1;
  41368. } else if (evlistener !== undefined) {
  41369. return evlistener.length;
  41370. }
  41371. }
  41372. return 0;
  41373. }
  41374. EventEmitter.prototype.eventNames = function eventNames() {
  41375. return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
  41376. };
  41377. function arrayClone(arr, n) {
  41378. var copy = new Array(n);
  41379. for (var i = 0; i < n; ++i) {
  41380. copy[i] = arr[i];
  41381. }
  41382. return copy;
  41383. }
  41384. function spliceOne(list, index) {
  41385. for (; index + 1 < list.length; index++) {
  41386. list[index] = list[index + 1];
  41387. }
  41388. list.pop();
  41389. }
  41390. function unwrapListeners(arr) {
  41391. var ret = new Array(arr.length);
  41392. for (var i = 0; i < ret.length; ++i) {
  41393. ret[i] = arr[i].listener || arr[i];
  41394. }
  41395. return ret;
  41396. }
  41397. function once(emitter, name) {
  41398. return new Promise(function (resolve, reject) {
  41399. function errorListener(err) {
  41400. emitter.removeListener(name, resolver);
  41401. reject(err);
  41402. }
  41403. function resolver() {
  41404. if (typeof emitter.removeListener === 'function') {
  41405. emitter.removeListener('error', errorListener);
  41406. }
  41407. resolve([].slice.call(arguments));
  41408. }
  41409. ;
  41410. eventTargetAgnosticAddListener(emitter, name, resolver, {
  41411. once: true
  41412. });
  41413. if (name !== 'error') {
  41414. addErrorHandlerIfEventEmitter(emitter, errorListener, {
  41415. once: true
  41416. });
  41417. }
  41418. });
  41419. }
  41420. function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
  41421. if (typeof emitter.on === 'function') {
  41422. eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
  41423. }
  41424. }
  41425. function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
  41426. if (typeof emitter.on === 'function') {
  41427. if (flags.once) {
  41428. emitter.once(name, listener);
  41429. } else {
  41430. emitter.on(name, listener);
  41431. }
  41432. } else if (typeof emitter.addEventListener === 'function') {
  41433. // EventTarget does not have `error` event semantics like Node
  41434. // EventEmitters, we do not listen for `error` events here.
  41435. emitter.addEventListener(name, function wrapListener(arg) {
  41436. // IE does not have builtin `{ once: true }` support so we
  41437. // have to do it manually.
  41438. if (flags.once) {
  41439. emitter.removeEventListener(name, wrapListener);
  41440. }
  41441. listener(arg);
  41442. });
  41443. } else {
  41444. throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + _typeof(emitter));
  41445. }
  41446. }
  41447. /***/ }),
  41448. /***/ 1248:
  41449. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41450. var Buffer = (__webpack_require__(9047).Buffer);
  41451. var MD5 = __webpack_require__(722);
  41452. /* eslint-disable camelcase */
  41453. function EVP_BytesToKey(password, salt, keyBits, ivLen) {
  41454. if (!Buffer.isBuffer(password)) password = Buffer.from(password, 'binary');
  41455. if (salt) {
  41456. if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, 'binary');
  41457. if (salt.length !== 8) throw new RangeError('salt should be Buffer with 8 byte length');
  41458. }
  41459. var keyLen = keyBits / 8;
  41460. var key = Buffer.alloc(keyLen);
  41461. var iv = Buffer.alloc(ivLen || 0);
  41462. var tmp = Buffer.alloc(0);
  41463. while (keyLen > 0 || ivLen > 0) {
  41464. var hash = new MD5();
  41465. hash.update(tmp);
  41466. hash.update(password);
  41467. if (salt) hash.update(salt);
  41468. tmp = hash.digest();
  41469. var used = 0;
  41470. if (keyLen > 0) {
  41471. var keyStart = key.length - keyLen;
  41472. used = Math.min(keyLen, tmp.length);
  41473. tmp.copy(key, keyStart, 0, used);
  41474. keyLen -= used;
  41475. }
  41476. if (used < tmp.length && ivLen > 0) {
  41477. var ivStart = iv.length - ivLen;
  41478. var length = Math.min(ivLen, tmp.length - used);
  41479. tmp.copy(iv, ivStart, used, used + length);
  41480. ivLen -= length;
  41481. }
  41482. }
  41483. tmp.fill(0);
  41484. return {
  41485. key: key,
  41486. iv: iv
  41487. };
  41488. }
  41489. module.exports = EVP_BytesToKey;
  41490. /***/ }),
  41491. /***/ 5337:
  41492. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41493. "use strict";
  41494. var isCallable = __webpack_require__(8625);
  41495. var toStr = Object.prototype.toString;
  41496. var hasOwnProperty = Object.prototype.hasOwnProperty;
  41497. var forEachArray = function forEachArray(array, iterator, receiver) {
  41498. for (var i = 0, len = array.length; i < len; i++) {
  41499. if (hasOwnProperty.call(array, i)) {
  41500. if (receiver == null) {
  41501. iterator(array[i], i, array);
  41502. } else {
  41503. iterator.call(receiver, array[i], i, array);
  41504. }
  41505. }
  41506. }
  41507. };
  41508. var forEachString = function forEachString(string, iterator, receiver) {
  41509. for (var i = 0, len = string.length; i < len; i++) {
  41510. // no such thing as a sparse string.
  41511. if (receiver == null) {
  41512. iterator(string.charAt(i), i, string);
  41513. } else {
  41514. iterator.call(receiver, string.charAt(i), i, string);
  41515. }
  41516. }
  41517. };
  41518. var forEachObject = function forEachObject(object, iterator, receiver) {
  41519. for (var k in object) {
  41520. if (hasOwnProperty.call(object, k)) {
  41521. if (receiver == null) {
  41522. iterator(object[k], k, object);
  41523. } else {
  41524. iterator.call(receiver, object[k], k, object);
  41525. }
  41526. }
  41527. }
  41528. };
  41529. var forEach = function forEach(list, iterator, thisArg) {
  41530. if (!isCallable(iterator)) {
  41531. throw new TypeError('iterator must be a function');
  41532. }
  41533. var receiver;
  41534. if (arguments.length >= 3) {
  41535. receiver = thisArg;
  41536. }
  41537. if (toStr.call(list) === '[object Array]') {
  41538. forEachArray(list, iterator, receiver);
  41539. } else if (typeof list === 'string') {
  41540. forEachString(list, iterator, receiver);
  41541. } else {
  41542. forEachObject(list, iterator, receiver);
  41543. }
  41544. };
  41545. module.exports = forEach;
  41546. /***/ }),
  41547. /***/ 5929:
  41548. /***/ ((module) => {
  41549. "use strict";
  41550. /* eslint no-invalid-this: 1 */
  41551. var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
  41552. var slice = Array.prototype.slice;
  41553. var toStr = Object.prototype.toString;
  41554. var funcType = '[object Function]';
  41555. module.exports = function bind(that) {
  41556. var target = this;
  41557. if (typeof target !== 'function' || toStr.call(target) !== funcType) {
  41558. throw new TypeError(ERROR_MESSAGE + target);
  41559. }
  41560. var args = slice.call(arguments, 1);
  41561. var bound;
  41562. var binder = function binder() {
  41563. if (this instanceof bound) {
  41564. var result = target.apply(this, args.concat(slice.call(arguments)));
  41565. if (Object(result) === result) {
  41566. return result;
  41567. }
  41568. return this;
  41569. } else {
  41570. return target.apply(that, args.concat(slice.call(arguments)));
  41571. }
  41572. };
  41573. var boundLength = Math.max(0, target.length - args.length);
  41574. var boundArgs = [];
  41575. for (var i = 0; i < boundLength; i++) {
  41576. boundArgs.push('$' + i);
  41577. }
  41578. bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
  41579. if (target.prototype) {
  41580. var Empty = function Empty() {};
  41581. Empty.prototype = target.prototype;
  41582. bound.prototype = new Empty();
  41583. Empty.prototype = null;
  41584. }
  41585. return bound;
  41586. };
  41587. /***/ }),
  41588. /***/ 5246:
  41589. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41590. "use strict";
  41591. var implementation = __webpack_require__(5929);
  41592. module.exports = Function.prototype.bind || implementation;
  41593. /***/ }),
  41594. /***/ 6893:
  41595. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41596. "use strict";
  41597. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  41598. var undefined;
  41599. var $SyntaxError = SyntaxError;
  41600. var $Function = Function;
  41601. var $TypeError = TypeError; // eslint-disable-next-line consistent-return
  41602. var getEvalledConstructor = function getEvalledConstructor(expressionSyntax) {
  41603. try {
  41604. return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
  41605. } catch (e) {}
  41606. };
  41607. var $gOPD = Object.getOwnPropertyDescriptor;
  41608. if ($gOPD) {
  41609. try {
  41610. $gOPD({}, '');
  41611. } catch (e) {
  41612. $gOPD = null; // this is IE 8, which has a broken gOPD
  41613. }
  41614. }
  41615. var throwTypeError = function throwTypeError() {
  41616. throw new $TypeError();
  41617. };
  41618. var ThrowTypeError = $gOPD ? function () {
  41619. try {
  41620. // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
  41621. arguments.callee; // IE 8 does not throw here
  41622. return throwTypeError;
  41623. } catch (calleeThrows) {
  41624. try {
  41625. // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
  41626. return $gOPD(arguments, 'callee').get;
  41627. } catch (gOPDthrows) {
  41628. return throwTypeError;
  41629. }
  41630. }
  41631. }() : throwTypeError;
  41632. var hasSymbols = __webpack_require__(5990)();
  41633. var getProto = Object.getPrototypeOf || function (x) {
  41634. return x.__proto__;
  41635. }; // eslint-disable-line no-proto
  41636. var needsEval = {};
  41637. var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array);
  41638. var INTRINSICS = {
  41639. '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError,
  41640. '%Array%': Array,
  41641. '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer,
  41642. '%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined,
  41643. '%AsyncFromSyncIteratorPrototype%': undefined,
  41644. '%AsyncFunction%': needsEval,
  41645. '%AsyncGenerator%': needsEval,
  41646. '%AsyncGeneratorFunction%': needsEval,
  41647. '%AsyncIteratorPrototype%': needsEval,
  41648. '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics,
  41649. '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt,
  41650. '%Boolean%': Boolean,
  41651. '%DataView%': typeof DataView === 'undefined' ? undefined : DataView,
  41652. '%Date%': Date,
  41653. '%decodeURI%': decodeURI,
  41654. '%decodeURIComponent%': decodeURIComponent,
  41655. '%encodeURI%': encodeURI,
  41656. '%encodeURIComponent%': encodeURIComponent,
  41657. '%Error%': Error,
  41658. '%eval%': eval,
  41659. // eslint-disable-line no-eval
  41660. '%EvalError%': EvalError,
  41661. '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array,
  41662. '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array,
  41663. '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry,
  41664. '%Function%': $Function,
  41665. '%GeneratorFunction%': needsEval,
  41666. '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array,
  41667. '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array,
  41668. '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array,
  41669. '%isFinite%': isFinite,
  41670. '%isNaN%': isNaN,
  41671. '%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined,
  41672. '%JSON%': (typeof JSON === "undefined" ? "undefined" : _typeof(JSON)) === 'object' ? JSON : undefined,
  41673. '%Map%': typeof Map === 'undefined' ? undefined : Map,
  41674. '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()),
  41675. '%Math%': Math,
  41676. '%Number%': Number,
  41677. '%Object%': Object,
  41678. '%parseFloat%': parseFloat,
  41679. '%parseInt%': parseInt,
  41680. '%Promise%': typeof Promise === 'undefined' ? undefined : Promise,
  41681. '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy,
  41682. '%RangeError%': RangeError,
  41683. '%ReferenceError%': ReferenceError,
  41684. '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect,
  41685. '%RegExp%': RegExp,
  41686. '%Set%': typeof Set === 'undefined' ? undefined : Set,
  41687. '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()),
  41688. '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer,
  41689. '%String%': String,
  41690. '%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined,
  41691. '%Symbol%': hasSymbols ? Symbol : undefined,
  41692. '%SyntaxError%': $SyntaxError,
  41693. '%ThrowTypeError%': ThrowTypeError,
  41694. '%TypedArray%': TypedArray,
  41695. '%TypeError%': $TypeError,
  41696. '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array,
  41697. '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray,
  41698. '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array,
  41699. '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array,
  41700. '%URIError%': URIError,
  41701. '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap,
  41702. '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef,
  41703. '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet
  41704. };
  41705. var doEval = function doEval(name) {
  41706. var value;
  41707. if (name === '%AsyncFunction%') {
  41708. value = getEvalledConstructor('async function () {}');
  41709. } else if (name === '%GeneratorFunction%') {
  41710. value = getEvalledConstructor('function* () {}');
  41711. } else if (name === '%AsyncGeneratorFunction%') {
  41712. value = getEvalledConstructor('async function* () {}');
  41713. } else if (name === '%AsyncGenerator%') {
  41714. var fn = doEval('%AsyncGeneratorFunction%');
  41715. if (fn) {
  41716. value = fn.prototype;
  41717. }
  41718. } else if (name === '%AsyncIteratorPrototype%') {
  41719. var gen = doEval('%AsyncGenerator%');
  41720. if (gen) {
  41721. value = getProto(gen.prototype);
  41722. }
  41723. }
  41724. INTRINSICS[name] = value;
  41725. return value;
  41726. };
  41727. var LEGACY_ALIASES = {
  41728. '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
  41729. '%ArrayPrototype%': ['Array', 'prototype'],
  41730. '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
  41731. '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
  41732. '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
  41733. '%ArrayProto_values%': ['Array', 'prototype', 'values'],
  41734. '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
  41735. '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
  41736. '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
  41737. '%BooleanPrototype%': ['Boolean', 'prototype'],
  41738. '%DataViewPrototype%': ['DataView', 'prototype'],
  41739. '%DatePrototype%': ['Date', 'prototype'],
  41740. '%ErrorPrototype%': ['Error', 'prototype'],
  41741. '%EvalErrorPrototype%': ['EvalError', 'prototype'],
  41742. '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
  41743. '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
  41744. '%FunctionPrototype%': ['Function', 'prototype'],
  41745. '%Generator%': ['GeneratorFunction', 'prototype'],
  41746. '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
  41747. '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
  41748. '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
  41749. '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
  41750. '%JSONParse%': ['JSON', 'parse'],
  41751. '%JSONStringify%': ['JSON', 'stringify'],
  41752. '%MapPrototype%': ['Map', 'prototype'],
  41753. '%NumberPrototype%': ['Number', 'prototype'],
  41754. '%ObjectPrototype%': ['Object', 'prototype'],
  41755. '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
  41756. '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
  41757. '%PromisePrototype%': ['Promise', 'prototype'],
  41758. '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
  41759. '%Promise_all%': ['Promise', 'all'],
  41760. '%Promise_reject%': ['Promise', 'reject'],
  41761. '%Promise_resolve%': ['Promise', 'resolve'],
  41762. '%RangeErrorPrototype%': ['RangeError', 'prototype'],
  41763. '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
  41764. '%RegExpPrototype%': ['RegExp', 'prototype'],
  41765. '%SetPrototype%': ['Set', 'prototype'],
  41766. '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
  41767. '%StringPrototype%': ['String', 'prototype'],
  41768. '%SymbolPrototype%': ['Symbol', 'prototype'],
  41769. '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
  41770. '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
  41771. '%TypeErrorPrototype%': ['TypeError', 'prototype'],
  41772. '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
  41773. '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
  41774. '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
  41775. '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
  41776. '%URIErrorPrototype%': ['URIError', 'prototype'],
  41777. '%WeakMapPrototype%': ['WeakMap', 'prototype'],
  41778. '%WeakSetPrototype%': ['WeakSet', 'prototype']
  41779. };
  41780. var bind = __webpack_require__(5246);
  41781. var hasOwn = __webpack_require__(7751);
  41782. var $concat = bind.call(Function.call, Array.prototype.concat);
  41783. var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
  41784. var $replace = bind.call(Function.call, String.prototype.replace);
  41785. var $strSlice = bind.call(Function.call, String.prototype.slice);
  41786. var $exec = bind.call(Function.call, RegExp.prototype.exec);
  41787. /* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
  41788. var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
  41789. var reEscapeChar = /\\(\\)?/g;
  41790. /** Used to match backslashes in property paths. */
  41791. var stringToPath = function stringToPath(string) {
  41792. var first = $strSlice(string, 0, 1);
  41793. var last = $strSlice(string, -1);
  41794. if (first === '%' && last !== '%') {
  41795. throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
  41796. } else if (last === '%' && first !== '%') {
  41797. throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
  41798. }
  41799. var result = [];
  41800. $replace(string, rePropName, function (match, number, quote, subString) {
  41801. result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
  41802. });
  41803. return result;
  41804. };
  41805. /* end adaptation */
  41806. var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
  41807. var intrinsicName = name;
  41808. var alias;
  41809. if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
  41810. alias = LEGACY_ALIASES[intrinsicName];
  41811. intrinsicName = '%' + alias[0] + '%';
  41812. }
  41813. if (hasOwn(INTRINSICS, intrinsicName)) {
  41814. var value = INTRINSICS[intrinsicName];
  41815. if (value === needsEval) {
  41816. value = doEval(intrinsicName);
  41817. }
  41818. if (typeof value === 'undefined' && !allowMissing) {
  41819. throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
  41820. }
  41821. return {
  41822. alias: alias,
  41823. name: intrinsicName,
  41824. value: value
  41825. };
  41826. }
  41827. throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
  41828. };
  41829. module.exports = function GetIntrinsic(name, allowMissing) {
  41830. if (typeof name !== 'string' || name.length === 0) {
  41831. throw new $TypeError('intrinsic name must be a non-empty string');
  41832. }
  41833. if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
  41834. throw new $TypeError('"allowMissing" argument must be a boolean');
  41835. }
  41836. if ($exec(/^%?[^%]*%?$/g, name) === null) {
  41837. throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
  41838. }
  41839. var parts = stringToPath(name);
  41840. var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
  41841. var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
  41842. var intrinsicRealName = intrinsic.name;
  41843. var value = intrinsic.value;
  41844. var skipFurtherCaching = false;
  41845. var alias = intrinsic.alias;
  41846. if (alias) {
  41847. intrinsicBaseName = alias[0];
  41848. $spliceApply(parts, $concat([0, 1], alias));
  41849. }
  41850. for (var i = 1, isOwn = true; i < parts.length; i += 1) {
  41851. var part = parts[i];
  41852. var first = $strSlice(part, 0, 1);
  41853. var last = $strSlice(part, -1);
  41854. if ((first === '"' || first === "'" || first === '`' || last === '"' || last === "'" || last === '`') && first !== last) {
  41855. throw new $SyntaxError('property names with quotes must have matching quotes');
  41856. }
  41857. if (part === 'constructor' || !isOwn) {
  41858. skipFurtherCaching = true;
  41859. }
  41860. intrinsicBaseName += '.' + part;
  41861. intrinsicRealName = '%' + intrinsicBaseName + '%';
  41862. if (hasOwn(INTRINSICS, intrinsicRealName)) {
  41863. value = INTRINSICS[intrinsicRealName];
  41864. } else if (value != null) {
  41865. if (!(part in value)) {
  41866. if (!allowMissing) {
  41867. throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
  41868. }
  41869. return void undefined;
  41870. }
  41871. if ($gOPD && i + 1 >= parts.length) {
  41872. var desc = $gOPD(value, part);
  41873. isOwn = !!desc; // By convention, when a data property is converted to an accessor
  41874. // property to emulate a data property that does not suffer from
  41875. // the override mistake, that accessor's getter is marked with
  41876. // an `originalValue` property. Here, when we detect this, we
  41877. // uphold the illusion by pretending to see that original data
  41878. // property, i.e., returning the value rather than the getter
  41879. // itself.
  41880. if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
  41881. value = desc.get;
  41882. } else {
  41883. value = value[part];
  41884. }
  41885. } else {
  41886. isOwn = hasOwn(value, part);
  41887. value = value[part];
  41888. }
  41889. if (isOwn && !skipFurtherCaching) {
  41890. INTRINSICS[intrinsicRealName] = value;
  41891. }
  41892. }
  41893. }
  41894. return value;
  41895. };
  41896. /***/ }),
  41897. /***/ 2579:
  41898. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41899. "use strict";
  41900. var GetIntrinsic = __webpack_require__(6893);
  41901. var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
  41902. var hasPropertyDescriptors = function hasPropertyDescriptors() {
  41903. if ($defineProperty) {
  41904. try {
  41905. $defineProperty({}, 'a', {
  41906. value: 1
  41907. });
  41908. return true;
  41909. } catch (e) {
  41910. // IE 8 has a broken defineProperty
  41911. return false;
  41912. }
  41913. }
  41914. return false;
  41915. };
  41916. hasPropertyDescriptors.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
  41917. // node v0.6 has a bug where array lengths can be Set but not Defined
  41918. if (!hasPropertyDescriptors()) {
  41919. return null;
  41920. }
  41921. try {
  41922. return $defineProperty([], 'length', {
  41923. value: 1
  41924. }).length !== 1;
  41925. } catch (e) {
  41926. // In Firefox 4-22, defining length on an array throws an exception.
  41927. return true;
  41928. }
  41929. };
  41930. module.exports = hasPropertyDescriptors;
  41931. /***/ }),
  41932. /***/ 5990:
  41933. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  41934. "use strict";
  41935. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  41936. var origSymbol = typeof Symbol !== 'undefined' && Symbol;
  41937. var hasSymbolSham = __webpack_require__(3031);
  41938. module.exports = function hasNativeSymbols() {
  41939. if (typeof origSymbol !== 'function') {
  41940. return false;
  41941. }
  41942. if (typeof Symbol !== 'function') {
  41943. return false;
  41944. }
  41945. if (_typeof(origSymbol('foo')) !== 'symbol') {
  41946. return false;
  41947. }
  41948. if (_typeof(Symbol('bar')) !== 'symbol') {
  41949. return false;
  41950. }
  41951. return hasSymbolSham();
  41952. };
  41953. /***/ }),
  41954. /***/ 3031:
  41955. /***/ ((module) => {
  41956. "use strict";
  41957. /* eslint complexity: [2, 18], max-statements: [2, 33] */
  41958. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  41959. module.exports = function hasSymbols() {
  41960. if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') {
  41961. return false;
  41962. }
  41963. if (_typeof(Symbol.iterator) === 'symbol') {
  41964. return true;
  41965. }
  41966. var obj = {};
  41967. var sym = Symbol('test');
  41968. var symObj = Object(sym);
  41969. if (typeof sym === 'string') {
  41970. return false;
  41971. }
  41972. if (Object.prototype.toString.call(sym) !== '[object Symbol]') {
  41973. return false;
  41974. }
  41975. if (Object.prototype.toString.call(symObj) !== '[object Symbol]') {
  41976. return false;
  41977. } // temp disabled per https://github.com/ljharb/object.assign/issues/17
  41978. // if (sym instanceof Symbol) { return false; }
  41979. // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
  41980. // if (!(symObj instanceof Symbol)) { return false; }
  41981. // if (typeof Symbol.prototype.toString !== 'function') { return false; }
  41982. // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
  41983. var symVal = 42;
  41984. obj[sym] = symVal;
  41985. for (sym in obj) {
  41986. return false;
  41987. } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
  41988. if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) {
  41989. return false;
  41990. }
  41991. if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) {
  41992. return false;
  41993. }
  41994. var syms = Object.getOwnPropertySymbols(obj);
  41995. if (syms.length !== 1 || syms[0] !== sym) {
  41996. return false;
  41997. }
  41998. if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) {
  41999. return false;
  42000. }
  42001. if (typeof Object.getOwnPropertyDescriptor === 'function') {
  42002. var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
  42003. if (descriptor.value !== symVal || descriptor.enumerable !== true) {
  42004. return false;
  42005. }
  42006. }
  42007. return true;
  42008. };
  42009. /***/ }),
  42010. /***/ 5994:
  42011. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42012. "use strict";
  42013. var hasSymbols = __webpack_require__(3031);
  42014. module.exports = function hasToStringTagShams() {
  42015. return hasSymbols() && !!Symbol.toStringTag;
  42016. };
  42017. /***/ }),
  42018. /***/ 7751:
  42019. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42020. "use strict";
  42021. var bind = __webpack_require__(5246);
  42022. module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty);
  42023. /***/ }),
  42024. /***/ 5125:
  42025. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42026. "use strict";
  42027. var Buffer = (__webpack_require__(1066).Buffer);
  42028. var Transform = (__webpack_require__(8237).Transform);
  42029. var inherits = __webpack_require__(376);
  42030. function throwIfNotStringOrBuffer(val, prefix) {
  42031. if (!Buffer.isBuffer(val) && typeof val !== 'string') {
  42032. throw new TypeError(prefix + ' must be a string or a buffer');
  42033. }
  42034. }
  42035. function HashBase(blockSize) {
  42036. Transform.call(this);
  42037. this._block = Buffer.allocUnsafe(blockSize);
  42038. this._blockSize = blockSize;
  42039. this._blockOffset = 0;
  42040. this._length = [0, 0, 0, 0];
  42041. this._finalized = false;
  42042. }
  42043. inherits(HashBase, Transform);
  42044. HashBase.prototype._transform = function (chunk, encoding, callback) {
  42045. var error = null;
  42046. try {
  42047. this.update(chunk, encoding);
  42048. } catch (err) {
  42049. error = err;
  42050. }
  42051. callback(error);
  42052. };
  42053. HashBase.prototype._flush = function (callback) {
  42054. var error = null;
  42055. try {
  42056. this.push(this.digest());
  42057. } catch (err) {
  42058. error = err;
  42059. }
  42060. callback(error);
  42061. };
  42062. HashBase.prototype.update = function (data, encoding) {
  42063. throwIfNotStringOrBuffer(data, 'Data');
  42064. if (this._finalized) throw new Error('Digest already called');
  42065. if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data
  42066. var block = this._block;
  42067. var offset = 0;
  42068. while (this._blockOffset + data.length - offset >= this._blockSize) {
  42069. for (var i = this._blockOffset; i < this._blockSize;) {
  42070. block[i++] = data[offset++];
  42071. }
  42072. this._update();
  42073. this._blockOffset = 0;
  42074. }
  42075. while (offset < data.length) {
  42076. block[this._blockOffset++] = data[offset++];
  42077. } // update length
  42078. for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
  42079. this._length[j] += carry;
  42080. carry = this._length[j] / 0x0100000000 | 0;
  42081. if (carry > 0) this._length[j] -= 0x0100000000 * carry;
  42082. }
  42083. return this;
  42084. };
  42085. HashBase.prototype._update = function () {
  42086. throw new Error('_update is not implemented');
  42087. };
  42088. HashBase.prototype.digest = function (encoding) {
  42089. if (this._finalized) throw new Error('Digest already called');
  42090. this._finalized = true;
  42091. var digest = this._digest();
  42092. if (encoding !== undefined) digest = digest.toString(encoding); // reset state
  42093. this._block.fill(0);
  42094. this._blockOffset = 0;
  42095. for (var i = 0; i < 4; ++i) {
  42096. this._length[i] = 0;
  42097. }
  42098. return digest;
  42099. };
  42100. HashBase.prototype._digest = function () {
  42101. throw new Error('_digest is not implemented');
  42102. };
  42103. module.exports = HashBase;
  42104. /***/ }),
  42105. /***/ 1066:
  42106. /***/ ((module, exports, __webpack_require__) => {
  42107. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  42108. /* eslint-disable node/no-deprecated-api */
  42109. var buffer = __webpack_require__(365);
  42110. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  42111. function copyProps(src, dst) {
  42112. for (var key in src) {
  42113. dst[key] = src[key];
  42114. }
  42115. }
  42116. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  42117. module.exports = buffer;
  42118. } else {
  42119. // Copy properties from require('buffer')
  42120. copyProps(buffer, exports);
  42121. exports.Buffer = SafeBuffer;
  42122. }
  42123. function SafeBuffer(arg, encodingOrOffset, length) {
  42124. return Buffer(arg, encodingOrOffset, length);
  42125. }
  42126. SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer
  42127. copyProps(Buffer, SafeBuffer);
  42128. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  42129. if (typeof arg === 'number') {
  42130. throw new TypeError('Argument must not be a number');
  42131. }
  42132. return Buffer(arg, encodingOrOffset, length);
  42133. };
  42134. SafeBuffer.alloc = function (size, fill, encoding) {
  42135. if (typeof size !== 'number') {
  42136. throw new TypeError('Argument must be a number');
  42137. }
  42138. var buf = Buffer(size);
  42139. if (fill !== undefined) {
  42140. if (typeof encoding === 'string') {
  42141. buf.fill(fill, encoding);
  42142. } else {
  42143. buf.fill(fill);
  42144. }
  42145. } else {
  42146. buf.fill(0);
  42147. }
  42148. return buf;
  42149. };
  42150. SafeBuffer.allocUnsafe = function (size) {
  42151. if (typeof size !== 'number') {
  42152. throw new TypeError('Argument must be a number');
  42153. }
  42154. return Buffer(size);
  42155. };
  42156. SafeBuffer.allocUnsafeSlow = function (size) {
  42157. if (typeof size !== 'number') {
  42158. throw new TypeError('Argument must be a number');
  42159. }
  42160. return buffer.SlowBuffer(size);
  42161. };
  42162. /***/ }),
  42163. /***/ 3192:
  42164. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42165. var hash = exports;
  42166. hash.utils = __webpack_require__(8244);
  42167. hash.common = __webpack_require__(5386);
  42168. hash.sha = __webpack_require__(2507);
  42169. hash.ripemd = __webpack_require__(9993);
  42170. hash.hmac = __webpack_require__(8534); // Proxy hash functions to the main object
  42171. hash.sha1 = hash.sha.sha1;
  42172. hash.sha256 = hash.sha.sha256;
  42173. hash.sha224 = hash.sha.sha224;
  42174. hash.sha384 = hash.sha.sha384;
  42175. hash.sha512 = hash.sha.sha512;
  42176. hash.ripemd160 = hash.ripemd.ripemd160;
  42177. /***/ }),
  42178. /***/ 5386:
  42179. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42180. "use strict";
  42181. var utils = __webpack_require__(8244);
  42182. var assert = __webpack_require__(1130);
  42183. function BlockHash() {
  42184. this.pending = null;
  42185. this.pendingTotal = 0;
  42186. this.blockSize = this.constructor.blockSize;
  42187. this.outSize = this.constructor.outSize;
  42188. this.hmacStrength = this.constructor.hmacStrength;
  42189. this.padLength = this.constructor.padLength / 8;
  42190. this.endian = 'big';
  42191. this._delta8 = this.blockSize / 8;
  42192. this._delta32 = this.blockSize / 32;
  42193. }
  42194. exports.BlockHash = BlockHash;
  42195. BlockHash.prototype.update = function update(msg, enc) {
  42196. // Convert message to array, pad it, and join into 32bit blocks
  42197. msg = utils.toArray(msg, enc);
  42198. if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg);
  42199. this.pendingTotal += msg.length; // Enough data, try updating
  42200. if (this.pending.length >= this._delta8) {
  42201. msg = this.pending; // Process pending data in blocks
  42202. var r = msg.length % this._delta8;
  42203. this.pending = msg.slice(msg.length - r, msg.length);
  42204. if (this.pending.length === 0) this.pending = null;
  42205. msg = utils.join32(msg, 0, msg.length - r, this.endian);
  42206. for (var i = 0; i < msg.length; i += this._delta32) {
  42207. this._update(msg, i, i + this._delta32);
  42208. }
  42209. }
  42210. return this;
  42211. };
  42212. BlockHash.prototype.digest = function digest(enc) {
  42213. this.update(this._pad());
  42214. assert(this.pending === null);
  42215. return this._digest(enc);
  42216. };
  42217. BlockHash.prototype._pad = function pad() {
  42218. var len = this.pendingTotal;
  42219. var bytes = this._delta8;
  42220. var k = bytes - (len + this.padLength) % bytes;
  42221. var res = new Array(k + this.padLength);
  42222. res[0] = 0x80;
  42223. for (var i = 1; i < k; i++) {
  42224. res[i] = 0;
  42225. } // Append length
  42226. len <<= 3;
  42227. if (this.endian === 'big') {
  42228. for (var t = 8; t < this.padLength; t++) {
  42229. res[i++] = 0;
  42230. }
  42231. res[i++] = 0;
  42232. res[i++] = 0;
  42233. res[i++] = 0;
  42234. res[i++] = 0;
  42235. res[i++] = len >>> 24 & 0xff;
  42236. res[i++] = len >>> 16 & 0xff;
  42237. res[i++] = len >>> 8 & 0xff;
  42238. res[i++] = len & 0xff;
  42239. } else {
  42240. res[i++] = len & 0xff;
  42241. res[i++] = len >>> 8 & 0xff;
  42242. res[i++] = len >>> 16 & 0xff;
  42243. res[i++] = len >>> 24 & 0xff;
  42244. res[i++] = 0;
  42245. res[i++] = 0;
  42246. res[i++] = 0;
  42247. res[i++] = 0;
  42248. for (t = 8; t < this.padLength; t++) {
  42249. res[i++] = 0;
  42250. }
  42251. }
  42252. return res;
  42253. };
  42254. /***/ }),
  42255. /***/ 8534:
  42256. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42257. "use strict";
  42258. var utils = __webpack_require__(8244);
  42259. var assert = __webpack_require__(1130);
  42260. function Hmac(hash, key, enc) {
  42261. if (!(this instanceof Hmac)) return new Hmac(hash, key, enc);
  42262. this.Hash = hash;
  42263. this.blockSize = hash.blockSize / 8;
  42264. this.outSize = hash.outSize / 8;
  42265. this.inner = null;
  42266. this.outer = null;
  42267. this._init(utils.toArray(key, enc));
  42268. }
  42269. module.exports = Hmac;
  42270. Hmac.prototype._init = function init(key) {
  42271. // Shorten key, if needed
  42272. if (key.length > this.blockSize) key = new this.Hash().update(key).digest();
  42273. assert(key.length <= this.blockSize); // Add padding to key
  42274. for (var i = key.length; i < this.blockSize; i++) {
  42275. key.push(0);
  42276. }
  42277. for (i = 0; i < key.length; i++) {
  42278. key[i] ^= 0x36;
  42279. }
  42280. this.inner = new this.Hash().update(key); // 0x36 ^ 0x5c = 0x6a
  42281. for (i = 0; i < key.length; i++) {
  42282. key[i] ^= 0x6a;
  42283. }
  42284. this.outer = new this.Hash().update(key);
  42285. };
  42286. Hmac.prototype.update = function update(msg, enc) {
  42287. this.inner.update(msg, enc);
  42288. return this;
  42289. };
  42290. Hmac.prototype.digest = function digest(enc) {
  42291. this.outer.update(this.inner.digest());
  42292. return this.outer.digest(enc);
  42293. };
  42294. /***/ }),
  42295. /***/ 9993:
  42296. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42297. "use strict";
  42298. var utils = __webpack_require__(8244);
  42299. var common = __webpack_require__(5386);
  42300. var rotl32 = utils.rotl32;
  42301. var sum32 = utils.sum32;
  42302. var sum32_3 = utils.sum32_3;
  42303. var sum32_4 = utils.sum32_4;
  42304. var BlockHash = common.BlockHash;
  42305. function RIPEMD160() {
  42306. if (!(this instanceof RIPEMD160)) return new RIPEMD160();
  42307. BlockHash.call(this);
  42308. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  42309. this.endian = 'little';
  42310. }
  42311. utils.inherits(RIPEMD160, BlockHash);
  42312. exports.ripemd160 = RIPEMD160;
  42313. RIPEMD160.blockSize = 512;
  42314. RIPEMD160.outSize = 160;
  42315. RIPEMD160.hmacStrength = 192;
  42316. RIPEMD160.padLength = 64;
  42317. RIPEMD160.prototype._update = function update(msg, start) {
  42318. var A = this.h[0];
  42319. var B = this.h[1];
  42320. var C = this.h[2];
  42321. var D = this.h[3];
  42322. var E = this.h[4];
  42323. var Ah = A;
  42324. var Bh = B;
  42325. var Ch = C;
  42326. var Dh = D;
  42327. var Eh = E;
  42328. for (var j = 0; j < 80; j++) {
  42329. var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E);
  42330. A = E;
  42331. E = D;
  42332. D = rotl32(C, 10);
  42333. C = B;
  42334. B = T;
  42335. T = sum32(rotl32(sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh);
  42336. Ah = Eh;
  42337. Eh = Dh;
  42338. Dh = rotl32(Ch, 10);
  42339. Ch = Bh;
  42340. Bh = T;
  42341. }
  42342. T = sum32_3(this.h[1], C, Dh);
  42343. this.h[1] = sum32_3(this.h[2], D, Eh);
  42344. this.h[2] = sum32_3(this.h[3], E, Ah);
  42345. this.h[3] = sum32_3(this.h[4], A, Bh);
  42346. this.h[4] = sum32_3(this.h[0], B, Ch);
  42347. this.h[0] = T;
  42348. };
  42349. RIPEMD160.prototype._digest = function digest(enc) {
  42350. if (enc === 'hex') return utils.toHex32(this.h, 'little');else return utils.split32(this.h, 'little');
  42351. };
  42352. function f(j, x, y, z) {
  42353. if (j <= 15) return x ^ y ^ z;else if (j <= 31) return x & y | ~x & z;else if (j <= 47) return (x | ~y) ^ z;else if (j <= 63) return x & z | y & ~z;else return x ^ (y | ~z);
  42354. }
  42355. function K(j) {
  42356. if (j <= 15) return 0x00000000;else if (j <= 31) return 0x5a827999;else if (j <= 47) return 0x6ed9eba1;else if (j <= 63) return 0x8f1bbcdc;else return 0xa953fd4e;
  42357. }
  42358. function Kh(j) {
  42359. if (j <= 15) return 0x50a28be6;else if (j <= 31) return 0x5c4dd124;else if (j <= 47) return 0x6d703ef3;else if (j <= 63) return 0x7a6d76e9;else return 0x00000000;
  42360. }
  42361. var r = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
  42362. var rh = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
  42363. var s = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6];
  42364. var sh = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11];
  42365. /***/ }),
  42366. /***/ 2507:
  42367. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42368. "use strict";
  42369. exports.sha1 = __webpack_require__(9382);
  42370. exports.sha224 = __webpack_require__(5123);
  42371. exports.sha256 = __webpack_require__(4032);
  42372. exports.sha384 = __webpack_require__(1364);
  42373. exports.sha512 = __webpack_require__(2161);
  42374. /***/ }),
  42375. /***/ 9382:
  42376. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42377. "use strict";
  42378. var utils = __webpack_require__(8244);
  42379. var common = __webpack_require__(5386);
  42380. var shaCommon = __webpack_require__(8355);
  42381. var rotl32 = utils.rotl32;
  42382. var sum32 = utils.sum32;
  42383. var sum32_5 = utils.sum32_5;
  42384. var ft_1 = shaCommon.ft_1;
  42385. var BlockHash = common.BlockHash;
  42386. var sha1_K = [0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6];
  42387. function SHA1() {
  42388. if (!(this instanceof SHA1)) return new SHA1();
  42389. BlockHash.call(this);
  42390. this.h = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
  42391. this.W = new Array(80);
  42392. }
  42393. utils.inherits(SHA1, BlockHash);
  42394. module.exports = SHA1;
  42395. SHA1.blockSize = 512;
  42396. SHA1.outSize = 160;
  42397. SHA1.hmacStrength = 80;
  42398. SHA1.padLength = 64;
  42399. SHA1.prototype._update = function _update(msg, start) {
  42400. var W = this.W;
  42401. for (var i = 0; i < 16; i++) {
  42402. W[i] = msg[start + i];
  42403. }
  42404. for (; i < W.length; i++) {
  42405. W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  42406. }
  42407. var a = this.h[0];
  42408. var b = this.h[1];
  42409. var c = this.h[2];
  42410. var d = this.h[3];
  42411. var e = this.h[4];
  42412. for (i = 0; i < W.length; i++) {
  42413. var s = ~~(i / 20);
  42414. var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
  42415. e = d;
  42416. d = c;
  42417. c = rotl32(b, 30);
  42418. b = a;
  42419. a = t;
  42420. }
  42421. this.h[0] = sum32(this.h[0], a);
  42422. this.h[1] = sum32(this.h[1], b);
  42423. this.h[2] = sum32(this.h[2], c);
  42424. this.h[3] = sum32(this.h[3], d);
  42425. this.h[4] = sum32(this.h[4], e);
  42426. };
  42427. SHA1.prototype._digest = function digest(enc) {
  42428. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  42429. };
  42430. /***/ }),
  42431. /***/ 5123:
  42432. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42433. "use strict";
  42434. var utils = __webpack_require__(8244);
  42435. var SHA256 = __webpack_require__(4032);
  42436. function SHA224() {
  42437. if (!(this instanceof SHA224)) return new SHA224();
  42438. SHA256.call(this);
  42439. this.h = [0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4];
  42440. }
  42441. utils.inherits(SHA224, SHA256);
  42442. module.exports = SHA224;
  42443. SHA224.blockSize = 512;
  42444. SHA224.outSize = 224;
  42445. SHA224.hmacStrength = 192;
  42446. SHA224.padLength = 64;
  42447. SHA224.prototype._digest = function digest(enc) {
  42448. // Just truncate output
  42449. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 7), 'big');else return utils.split32(this.h.slice(0, 7), 'big');
  42450. };
  42451. /***/ }),
  42452. /***/ 4032:
  42453. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42454. "use strict";
  42455. var utils = __webpack_require__(8244);
  42456. var common = __webpack_require__(5386);
  42457. var shaCommon = __webpack_require__(8355);
  42458. var assert = __webpack_require__(1130);
  42459. var sum32 = utils.sum32;
  42460. var sum32_4 = utils.sum32_4;
  42461. var sum32_5 = utils.sum32_5;
  42462. var ch32 = shaCommon.ch32;
  42463. var maj32 = shaCommon.maj32;
  42464. var s0_256 = shaCommon.s0_256;
  42465. var s1_256 = shaCommon.s1_256;
  42466. var g0_256 = shaCommon.g0_256;
  42467. var g1_256 = shaCommon.g1_256;
  42468. var BlockHash = common.BlockHash;
  42469. var sha256_K = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  42470. function SHA256() {
  42471. if (!(this instanceof SHA256)) return new SHA256();
  42472. BlockHash.call(this);
  42473. this.h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19];
  42474. this.k = sha256_K;
  42475. this.W = new Array(64);
  42476. }
  42477. utils.inherits(SHA256, BlockHash);
  42478. module.exports = SHA256;
  42479. SHA256.blockSize = 512;
  42480. SHA256.outSize = 256;
  42481. SHA256.hmacStrength = 192;
  42482. SHA256.padLength = 64;
  42483. SHA256.prototype._update = function _update(msg, start) {
  42484. var W = this.W;
  42485. for (var i = 0; i < 16; i++) {
  42486. W[i] = msg[start + i];
  42487. }
  42488. for (; i < W.length; i++) {
  42489. W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
  42490. }
  42491. var a = this.h[0];
  42492. var b = this.h[1];
  42493. var c = this.h[2];
  42494. var d = this.h[3];
  42495. var e = this.h[4];
  42496. var f = this.h[5];
  42497. var g = this.h[6];
  42498. var h = this.h[7];
  42499. assert(this.k.length === W.length);
  42500. for (i = 0; i < W.length; i++) {
  42501. var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
  42502. var T2 = sum32(s0_256(a), maj32(a, b, c));
  42503. h = g;
  42504. g = f;
  42505. f = e;
  42506. e = sum32(d, T1);
  42507. d = c;
  42508. c = b;
  42509. b = a;
  42510. a = sum32(T1, T2);
  42511. }
  42512. this.h[0] = sum32(this.h[0], a);
  42513. this.h[1] = sum32(this.h[1], b);
  42514. this.h[2] = sum32(this.h[2], c);
  42515. this.h[3] = sum32(this.h[3], d);
  42516. this.h[4] = sum32(this.h[4], e);
  42517. this.h[5] = sum32(this.h[5], f);
  42518. this.h[6] = sum32(this.h[6], g);
  42519. this.h[7] = sum32(this.h[7], h);
  42520. };
  42521. SHA256.prototype._digest = function digest(enc) {
  42522. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  42523. };
  42524. /***/ }),
  42525. /***/ 1364:
  42526. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42527. "use strict";
  42528. var utils = __webpack_require__(8244);
  42529. var SHA512 = __webpack_require__(2161);
  42530. function SHA384() {
  42531. if (!(this instanceof SHA384)) return new SHA384();
  42532. SHA512.call(this);
  42533. this.h = [0xcbbb9d5d, 0xc1059ed8, 0x629a292a, 0x367cd507, 0x9159015a, 0x3070dd17, 0x152fecd8, 0xf70e5939, 0x67332667, 0xffc00b31, 0x8eb44a87, 0x68581511, 0xdb0c2e0d, 0x64f98fa7, 0x47b5481d, 0xbefa4fa4];
  42534. }
  42535. utils.inherits(SHA384, SHA512);
  42536. module.exports = SHA384;
  42537. SHA384.blockSize = 1024;
  42538. SHA384.outSize = 384;
  42539. SHA384.hmacStrength = 192;
  42540. SHA384.padLength = 128;
  42541. SHA384.prototype._digest = function digest(enc) {
  42542. if (enc === 'hex') return utils.toHex32(this.h.slice(0, 12), 'big');else return utils.split32(this.h.slice(0, 12), 'big');
  42543. };
  42544. /***/ }),
  42545. /***/ 2161:
  42546. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  42547. "use strict";
  42548. var utils = __webpack_require__(8244);
  42549. var common = __webpack_require__(5386);
  42550. var assert = __webpack_require__(1130);
  42551. var rotr64_hi = utils.rotr64_hi;
  42552. var rotr64_lo = utils.rotr64_lo;
  42553. var shr64_hi = utils.shr64_hi;
  42554. var shr64_lo = utils.shr64_lo;
  42555. var sum64 = utils.sum64;
  42556. var sum64_hi = utils.sum64_hi;
  42557. var sum64_lo = utils.sum64_lo;
  42558. var sum64_4_hi = utils.sum64_4_hi;
  42559. var sum64_4_lo = utils.sum64_4_lo;
  42560. var sum64_5_hi = utils.sum64_5_hi;
  42561. var sum64_5_lo = utils.sum64_5_lo;
  42562. var BlockHash = common.BlockHash;
  42563. var sha512_K = [0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817];
  42564. function SHA512() {
  42565. if (!(this instanceof SHA512)) return new SHA512();
  42566. BlockHash.call(this);
  42567. this.h = [0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179];
  42568. this.k = sha512_K;
  42569. this.W = new Array(160);
  42570. }
  42571. utils.inherits(SHA512, BlockHash);
  42572. module.exports = SHA512;
  42573. SHA512.blockSize = 1024;
  42574. SHA512.outSize = 512;
  42575. SHA512.hmacStrength = 192;
  42576. SHA512.padLength = 128;
  42577. SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
  42578. var W = this.W; // 32 x 32bit words
  42579. for (var i = 0; i < 32; i++) {
  42580. W[i] = msg[start + i];
  42581. }
  42582. for (; i < W.length; i += 2) {
  42583. var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
  42584. var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
  42585. var c1_hi = W[i - 14]; // i - 7
  42586. var c1_lo = W[i - 13];
  42587. var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
  42588. var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
  42589. var c3_hi = W[i - 32]; // i - 16
  42590. var c3_lo = W[i - 31];
  42591. W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  42592. W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo);
  42593. }
  42594. };
  42595. SHA512.prototype._update = function _update(msg, start) {
  42596. this._prepareBlock(msg, start);
  42597. var W = this.W;
  42598. var ah = this.h[0];
  42599. var al = this.h[1];
  42600. var bh = this.h[2];
  42601. var bl = this.h[3];
  42602. var ch = this.h[4];
  42603. var cl = this.h[5];
  42604. var dh = this.h[6];
  42605. var dl = this.h[7];
  42606. var eh = this.h[8];
  42607. var el = this.h[9];
  42608. var fh = this.h[10];
  42609. var fl = this.h[11];
  42610. var gh = this.h[12];
  42611. var gl = this.h[13];
  42612. var hh = this.h[14];
  42613. var hl = this.h[15];
  42614. assert(this.k.length === W.length);
  42615. for (var i = 0; i < W.length; i += 2) {
  42616. var c0_hi = hh;
  42617. var c0_lo = hl;
  42618. var c1_hi = s1_512_hi(eh, el);
  42619. var c1_lo = s1_512_lo(eh, el);
  42620. var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
  42621. var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
  42622. var c3_hi = this.k[i];
  42623. var c3_lo = this.k[i + 1];
  42624. var c4_hi = W[i];
  42625. var c4_lo = W[i + 1];
  42626. var T1_hi = sum64_5_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
  42627. var T1_lo = sum64_5_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo);
  42628. c0_hi = s0_512_hi(ah, al);
  42629. c0_lo = s0_512_lo(ah, al);
  42630. c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
  42631. c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
  42632. var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
  42633. var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
  42634. hh = gh;
  42635. hl = gl;
  42636. gh = fh;
  42637. gl = fl;
  42638. fh = eh;
  42639. fl = el;
  42640. eh = sum64_hi(dh, dl, T1_hi, T1_lo);
  42641. el = sum64_lo(dl, dl, T1_hi, T1_lo);
  42642. dh = ch;
  42643. dl = cl;
  42644. ch = bh;
  42645. cl = bl;
  42646. bh = ah;
  42647. bl = al;
  42648. ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
  42649. al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
  42650. }
  42651. sum64(this.h, 0, ah, al);
  42652. sum64(this.h, 2, bh, bl);
  42653. sum64(this.h, 4, ch, cl);
  42654. sum64(this.h, 6, dh, dl);
  42655. sum64(this.h, 8, eh, el);
  42656. sum64(this.h, 10, fh, fl);
  42657. sum64(this.h, 12, gh, gl);
  42658. sum64(this.h, 14, hh, hl);
  42659. };
  42660. SHA512.prototype._digest = function digest(enc) {
  42661. if (enc === 'hex') return utils.toHex32(this.h, 'big');else return utils.split32(this.h, 'big');
  42662. };
  42663. function ch64_hi(xh, xl, yh, yl, zh) {
  42664. var r = xh & yh ^ ~xh & zh;
  42665. if (r < 0) r += 0x100000000;
  42666. return r;
  42667. }
  42668. function ch64_lo(xh, xl, yh, yl, zh, zl) {
  42669. var r = xl & yl ^ ~xl & zl;
  42670. if (r < 0) r += 0x100000000;
  42671. return r;
  42672. }
  42673. function maj64_hi(xh, xl, yh, yl, zh) {
  42674. var r = xh & yh ^ xh & zh ^ yh & zh;
  42675. if (r < 0) r += 0x100000000;
  42676. return r;
  42677. }
  42678. function maj64_lo(xh, xl, yh, yl, zh, zl) {
  42679. var r = xl & yl ^ xl & zl ^ yl & zl;
  42680. if (r < 0) r += 0x100000000;
  42681. return r;
  42682. }
  42683. function s0_512_hi(xh, xl) {
  42684. var c0_hi = rotr64_hi(xh, xl, 28);
  42685. var c1_hi = rotr64_hi(xl, xh, 2); // 34
  42686. var c2_hi = rotr64_hi(xl, xh, 7); // 39
  42687. var r = c0_hi ^ c1_hi ^ c2_hi;
  42688. if (r < 0) r += 0x100000000;
  42689. return r;
  42690. }
  42691. function s0_512_lo(xh, xl) {
  42692. var c0_lo = rotr64_lo(xh, xl, 28);
  42693. var c1_lo = rotr64_lo(xl, xh, 2); // 34
  42694. var c2_lo = rotr64_lo(xl, xh, 7); // 39
  42695. var r = c0_lo ^ c1_lo ^ c2_lo;
  42696. if (r < 0) r += 0x100000000;
  42697. return r;
  42698. }
  42699. function s1_512_hi(xh, xl) {
  42700. var c0_hi = rotr64_hi(xh, xl, 14);
  42701. var c1_hi = rotr64_hi(xh, xl, 18);
  42702. var c2_hi = rotr64_hi(xl, xh, 9); // 41
  42703. var r = c0_hi ^ c1_hi ^ c2_hi;
  42704. if (r < 0) r += 0x100000000;
  42705. return r;
  42706. }
  42707. function s1_512_lo(xh, xl) {
  42708. var c0_lo = rotr64_lo(xh, xl, 14);
  42709. var c1_lo = rotr64_lo(xh, xl, 18);
  42710. var c2_lo = rotr64_lo(xl, xh, 9); // 41
  42711. var r = c0_lo ^ c1_lo ^ c2_lo;
  42712. if (r < 0) r += 0x100000000;
  42713. return r;
  42714. }
  42715. function g0_512_hi(xh, xl) {
  42716. var c0_hi = rotr64_hi(xh, xl, 1);
  42717. var c1_hi = rotr64_hi(xh, xl, 8);
  42718. var c2_hi = shr64_hi(xh, xl, 7);
  42719. var r = c0_hi ^ c1_hi ^ c2_hi;
  42720. if (r < 0) r += 0x100000000;
  42721. return r;
  42722. }
  42723. function g0_512_lo(xh, xl) {
  42724. var c0_lo = rotr64_lo(xh, xl, 1);
  42725. var c1_lo = rotr64_lo(xh, xl, 8);
  42726. var c2_lo = shr64_lo(xh, xl, 7);
  42727. var r = c0_lo ^ c1_lo ^ c2_lo;
  42728. if (r < 0) r += 0x100000000;
  42729. return r;
  42730. }
  42731. function g1_512_hi(xh, xl) {
  42732. var c0_hi = rotr64_hi(xh, xl, 19);
  42733. var c1_hi = rotr64_hi(xl, xh, 29); // 61
  42734. var c2_hi = shr64_hi(xh, xl, 6);
  42735. var r = c0_hi ^ c1_hi ^ c2_hi;
  42736. if (r < 0) r += 0x100000000;
  42737. return r;
  42738. }
  42739. function g1_512_lo(xh, xl) {
  42740. var c0_lo = rotr64_lo(xh, xl, 19);
  42741. var c1_lo = rotr64_lo(xl, xh, 29); // 61
  42742. var c2_lo = shr64_lo(xh, xl, 6);
  42743. var r = c0_lo ^ c1_lo ^ c2_lo;
  42744. if (r < 0) r += 0x100000000;
  42745. return r;
  42746. }
  42747. /***/ }),
  42748. /***/ 8355:
  42749. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42750. "use strict";
  42751. var utils = __webpack_require__(8244);
  42752. var rotr32 = utils.rotr32;
  42753. function ft_1(s, x, y, z) {
  42754. if (s === 0) return ch32(x, y, z);
  42755. if (s === 1 || s === 3) return p32(x, y, z);
  42756. if (s === 2) return maj32(x, y, z);
  42757. }
  42758. exports.ft_1 = ft_1;
  42759. function ch32(x, y, z) {
  42760. return x & y ^ ~x & z;
  42761. }
  42762. exports.ch32 = ch32;
  42763. function maj32(x, y, z) {
  42764. return x & y ^ x & z ^ y & z;
  42765. }
  42766. exports.maj32 = maj32;
  42767. function p32(x, y, z) {
  42768. return x ^ y ^ z;
  42769. }
  42770. exports.p32 = p32;
  42771. function s0_256(x) {
  42772. return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
  42773. }
  42774. exports.s0_256 = s0_256;
  42775. function s1_256(x) {
  42776. return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
  42777. }
  42778. exports.s1_256 = s1_256;
  42779. function g0_256(x) {
  42780. return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
  42781. }
  42782. exports.g0_256 = g0_256;
  42783. function g1_256(x) {
  42784. return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
  42785. }
  42786. exports.g1_256 = g1_256;
  42787. /***/ }),
  42788. /***/ 8244:
  42789. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  42790. "use strict";
  42791. var assert = __webpack_require__(1130);
  42792. var inherits = __webpack_require__(376);
  42793. exports.inherits = inherits;
  42794. function isSurrogatePair(msg, i) {
  42795. if ((msg.charCodeAt(i) & 0xFC00) !== 0xD800) {
  42796. return false;
  42797. }
  42798. if (i < 0 || i + 1 >= msg.length) {
  42799. return false;
  42800. }
  42801. return (msg.charCodeAt(i + 1) & 0xFC00) === 0xDC00;
  42802. }
  42803. function toArray(msg, enc) {
  42804. if (Array.isArray(msg)) return msg.slice();
  42805. if (!msg) return [];
  42806. var res = [];
  42807. if (typeof msg === 'string') {
  42808. if (!enc) {
  42809. // Inspired by stringToUtf8ByteArray() in closure-library by Google
  42810. // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143
  42811. // Apache License 2.0
  42812. // https://github.com/google/closure-library/blob/master/LICENSE
  42813. var p = 0;
  42814. for (var i = 0; i < msg.length; i++) {
  42815. var c = msg.charCodeAt(i);
  42816. if (c < 128) {
  42817. res[p++] = c;
  42818. } else if (c < 2048) {
  42819. res[p++] = c >> 6 | 192;
  42820. res[p++] = c & 63 | 128;
  42821. } else if (isSurrogatePair(msg, i)) {
  42822. c = 0x10000 + ((c & 0x03FF) << 10) + (msg.charCodeAt(++i) & 0x03FF);
  42823. res[p++] = c >> 18 | 240;
  42824. res[p++] = c >> 12 & 63 | 128;
  42825. res[p++] = c >> 6 & 63 | 128;
  42826. res[p++] = c & 63 | 128;
  42827. } else {
  42828. res[p++] = c >> 12 | 224;
  42829. res[p++] = c >> 6 & 63 | 128;
  42830. res[p++] = c & 63 | 128;
  42831. }
  42832. }
  42833. } else if (enc === 'hex') {
  42834. msg = msg.replace(/[^a-z0-9]+/ig, '');
  42835. if (msg.length % 2 !== 0) msg = '0' + msg;
  42836. for (i = 0; i < msg.length; i += 2) {
  42837. res.push(parseInt(msg[i] + msg[i + 1], 16));
  42838. }
  42839. }
  42840. } else {
  42841. for (i = 0; i < msg.length; i++) {
  42842. res[i] = msg[i] | 0;
  42843. }
  42844. }
  42845. return res;
  42846. }
  42847. exports.toArray = toArray;
  42848. function toHex(msg) {
  42849. var res = '';
  42850. for (var i = 0; i < msg.length; i++) {
  42851. res += zero2(msg[i].toString(16));
  42852. }
  42853. return res;
  42854. }
  42855. exports.toHex = toHex;
  42856. function htonl(w) {
  42857. var res = w >>> 24 | w >>> 8 & 0xff00 | w << 8 & 0xff0000 | (w & 0xff) << 24;
  42858. return res >>> 0;
  42859. }
  42860. exports.htonl = htonl;
  42861. function toHex32(msg, endian) {
  42862. var res = '';
  42863. for (var i = 0; i < msg.length; i++) {
  42864. var w = msg[i];
  42865. if (endian === 'little') w = htonl(w);
  42866. res += zero8(w.toString(16));
  42867. }
  42868. return res;
  42869. }
  42870. exports.toHex32 = toHex32;
  42871. function zero2(word) {
  42872. if (word.length === 1) return '0' + word;else return word;
  42873. }
  42874. exports.zero2 = zero2;
  42875. function zero8(word) {
  42876. if (word.length === 7) return '0' + word;else if (word.length === 6) return '00' + word;else if (word.length === 5) return '000' + word;else if (word.length === 4) return '0000' + word;else if (word.length === 3) return '00000' + word;else if (word.length === 2) return '000000' + word;else if (word.length === 1) return '0000000' + word;else return word;
  42877. }
  42878. exports.zero8 = zero8;
  42879. function join32(msg, start, end, endian) {
  42880. var len = end - start;
  42881. assert(len % 4 === 0);
  42882. var res = new Array(len / 4);
  42883. for (var i = 0, k = start; i < res.length; i++, k += 4) {
  42884. var w;
  42885. if (endian === 'big') w = msg[k] << 24 | msg[k + 1] << 16 | msg[k + 2] << 8 | msg[k + 3];else w = msg[k + 3] << 24 | msg[k + 2] << 16 | msg[k + 1] << 8 | msg[k];
  42886. res[i] = w >>> 0;
  42887. }
  42888. return res;
  42889. }
  42890. exports.join32 = join32;
  42891. function split32(msg, endian) {
  42892. var res = new Array(msg.length * 4);
  42893. for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
  42894. var m = msg[i];
  42895. if (endian === 'big') {
  42896. res[k] = m >>> 24;
  42897. res[k + 1] = m >>> 16 & 0xff;
  42898. res[k + 2] = m >>> 8 & 0xff;
  42899. res[k + 3] = m & 0xff;
  42900. } else {
  42901. res[k + 3] = m >>> 24;
  42902. res[k + 2] = m >>> 16 & 0xff;
  42903. res[k + 1] = m >>> 8 & 0xff;
  42904. res[k] = m & 0xff;
  42905. }
  42906. }
  42907. return res;
  42908. }
  42909. exports.split32 = split32;
  42910. function rotr32(w, b) {
  42911. return w >>> b | w << 32 - b;
  42912. }
  42913. exports.rotr32 = rotr32;
  42914. function rotl32(w, b) {
  42915. return w << b | w >>> 32 - b;
  42916. }
  42917. exports.rotl32 = rotl32;
  42918. function sum32(a, b) {
  42919. return a + b >>> 0;
  42920. }
  42921. exports.sum32 = sum32;
  42922. function sum32_3(a, b, c) {
  42923. return a + b + c >>> 0;
  42924. }
  42925. exports.sum32_3 = sum32_3;
  42926. function sum32_4(a, b, c, d) {
  42927. return a + b + c + d >>> 0;
  42928. }
  42929. exports.sum32_4 = sum32_4;
  42930. function sum32_5(a, b, c, d, e) {
  42931. return a + b + c + d + e >>> 0;
  42932. }
  42933. exports.sum32_5 = sum32_5;
  42934. function sum64(buf, pos, ah, al) {
  42935. var bh = buf[pos];
  42936. var bl = buf[pos + 1];
  42937. var lo = al + bl >>> 0;
  42938. var hi = (lo < al ? 1 : 0) + ah + bh;
  42939. buf[pos] = hi >>> 0;
  42940. buf[pos + 1] = lo;
  42941. }
  42942. exports.sum64 = sum64;
  42943. function sum64_hi(ah, al, bh, bl) {
  42944. var lo = al + bl >>> 0;
  42945. var hi = (lo < al ? 1 : 0) + ah + bh;
  42946. return hi >>> 0;
  42947. }
  42948. exports.sum64_hi = sum64_hi;
  42949. function sum64_lo(ah, al, bh, bl) {
  42950. var lo = al + bl;
  42951. return lo >>> 0;
  42952. }
  42953. exports.sum64_lo = sum64_lo;
  42954. function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
  42955. var carry = 0;
  42956. var lo = al;
  42957. lo = lo + bl >>> 0;
  42958. carry += lo < al ? 1 : 0;
  42959. lo = lo + cl >>> 0;
  42960. carry += lo < cl ? 1 : 0;
  42961. lo = lo + dl >>> 0;
  42962. carry += lo < dl ? 1 : 0;
  42963. var hi = ah + bh + ch + dh + carry;
  42964. return hi >>> 0;
  42965. }
  42966. exports.sum64_4_hi = sum64_4_hi;
  42967. function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
  42968. var lo = al + bl + cl + dl;
  42969. return lo >>> 0;
  42970. }
  42971. exports.sum64_4_lo = sum64_4_lo;
  42972. function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  42973. var carry = 0;
  42974. var lo = al;
  42975. lo = lo + bl >>> 0;
  42976. carry += lo < al ? 1 : 0;
  42977. lo = lo + cl >>> 0;
  42978. carry += lo < cl ? 1 : 0;
  42979. lo = lo + dl >>> 0;
  42980. carry += lo < dl ? 1 : 0;
  42981. lo = lo + el >>> 0;
  42982. carry += lo < el ? 1 : 0;
  42983. var hi = ah + bh + ch + dh + eh + carry;
  42984. return hi >>> 0;
  42985. }
  42986. exports.sum64_5_hi = sum64_5_hi;
  42987. function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
  42988. var lo = al + bl + cl + dl + el;
  42989. return lo >>> 0;
  42990. }
  42991. exports.sum64_5_lo = sum64_5_lo;
  42992. function rotr64_hi(ah, al, num) {
  42993. var r = al << 32 - num | ah >>> num;
  42994. return r >>> 0;
  42995. }
  42996. exports.rotr64_hi = rotr64_hi;
  42997. function rotr64_lo(ah, al, num) {
  42998. var r = ah << 32 - num | al >>> num;
  42999. return r >>> 0;
  43000. }
  43001. exports.rotr64_lo = rotr64_lo;
  43002. function shr64_hi(ah, al, num) {
  43003. return ah >>> num;
  43004. }
  43005. exports.shr64_hi = shr64_hi;
  43006. function shr64_lo(ah, al, num) {
  43007. var r = ah << 32 - num | al >>> num;
  43008. return r >>> 0;
  43009. }
  43010. exports.shr64_lo = shr64_lo;
  43011. /***/ }),
  43012. /***/ 9742:
  43013. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43014. "use strict";
  43015. var hash = __webpack_require__(3192);
  43016. var utils = __webpack_require__(5522);
  43017. var assert = __webpack_require__(1130);
  43018. function HmacDRBG(options) {
  43019. if (!(this instanceof HmacDRBG)) return new HmacDRBG(options);
  43020. this.hash = options.hash;
  43021. this.predResist = !!options.predResist;
  43022. this.outLen = this.hash.outSize;
  43023. this.minEntropy = options.minEntropy || this.hash.hmacStrength;
  43024. this._reseed = null;
  43025. this.reseedInterval = null;
  43026. this.K = null;
  43027. this.V = null;
  43028. var entropy = utils.toArray(options.entropy, options.entropyEnc || 'hex');
  43029. var nonce = utils.toArray(options.nonce, options.nonceEnc || 'hex');
  43030. var pers = utils.toArray(options.pers, options.persEnc || 'hex');
  43031. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  43032. this._init(entropy, nonce, pers);
  43033. }
  43034. module.exports = HmacDRBG;
  43035. HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
  43036. var seed = entropy.concat(nonce).concat(pers);
  43037. this.K = new Array(this.outLen / 8);
  43038. this.V = new Array(this.outLen / 8);
  43039. for (var i = 0; i < this.V.length; i++) {
  43040. this.K[i] = 0x00;
  43041. this.V[i] = 0x01;
  43042. }
  43043. this._update(seed);
  43044. this._reseed = 1;
  43045. this.reseedInterval = 0x1000000000000; // 2^48
  43046. };
  43047. HmacDRBG.prototype._hmac = function hmac() {
  43048. return new hash.hmac(this.hash, this.K);
  43049. };
  43050. HmacDRBG.prototype._update = function update(seed) {
  43051. var kmac = this._hmac().update(this.V).update([0x00]);
  43052. if (seed) kmac = kmac.update(seed);
  43053. this.K = kmac.digest();
  43054. this.V = this._hmac().update(this.V).digest();
  43055. if (!seed) return;
  43056. this.K = this._hmac().update(this.V).update([0x01]).update(seed).digest();
  43057. this.V = this._hmac().update(this.V).digest();
  43058. };
  43059. HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
  43060. // Optional entropy enc
  43061. if (typeof entropyEnc !== 'string') {
  43062. addEnc = add;
  43063. add = entropyEnc;
  43064. entropyEnc = null;
  43065. }
  43066. entropy = utils.toArray(entropy, entropyEnc);
  43067. add = utils.toArray(add, addEnc);
  43068. assert(entropy.length >= this.minEntropy / 8, 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
  43069. this._update(entropy.concat(add || []));
  43070. this._reseed = 1;
  43071. };
  43072. HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
  43073. if (this._reseed > this.reseedInterval) throw new Error('Reseed is required'); // Optional encoding
  43074. if (typeof enc !== 'string') {
  43075. addEnc = add;
  43076. add = enc;
  43077. enc = null;
  43078. } // Optional additional data
  43079. if (add) {
  43080. add = utils.toArray(add, addEnc || 'hex');
  43081. this._update(add);
  43082. }
  43083. var temp = [];
  43084. while (temp.length < len) {
  43085. this.V = this._hmac().update(this.V).digest();
  43086. temp = temp.concat(this.V);
  43087. }
  43088. var res = temp.slice(0, len);
  43089. this._update(add);
  43090. this._reseed++;
  43091. return utils.encode(res, enc);
  43092. };
  43093. /***/ }),
  43094. /***/ 8405:
  43095. /***/ ((__unused_webpack_module, exports) => {
  43096. /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
  43097. exports.read = function (buffer, offset, isLE, mLen, nBytes) {
  43098. var e, m;
  43099. var eLen = nBytes * 8 - mLen - 1;
  43100. var eMax = (1 << eLen) - 1;
  43101. var eBias = eMax >> 1;
  43102. var nBits = -7;
  43103. var i = isLE ? nBytes - 1 : 0;
  43104. var d = isLE ? -1 : 1;
  43105. var s = buffer[offset + i];
  43106. i += d;
  43107. e = s & (1 << -nBits) - 1;
  43108. s >>= -nBits;
  43109. nBits += eLen;
  43110. for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  43111. m = e & (1 << -nBits) - 1;
  43112. e >>= -nBits;
  43113. nBits += mLen;
  43114. for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
  43115. if (e === 0) {
  43116. e = 1 - eBias;
  43117. } else if (e === eMax) {
  43118. return m ? NaN : (s ? -1 : 1) * Infinity;
  43119. } else {
  43120. m = m + Math.pow(2, mLen);
  43121. e = e - eBias;
  43122. }
  43123. return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
  43124. };
  43125. exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
  43126. var e, m, c;
  43127. var eLen = nBytes * 8 - mLen - 1;
  43128. var eMax = (1 << eLen) - 1;
  43129. var eBias = eMax >> 1;
  43130. var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
  43131. var i = isLE ? 0 : nBytes - 1;
  43132. var d = isLE ? 1 : -1;
  43133. var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
  43134. value = Math.abs(value);
  43135. if (isNaN(value) || value === Infinity) {
  43136. m = isNaN(value) ? 1 : 0;
  43137. e = eMax;
  43138. } else {
  43139. e = Math.floor(Math.log(value) / Math.LN2);
  43140. if (value * (c = Math.pow(2, -e)) < 1) {
  43141. e--;
  43142. c *= 2;
  43143. }
  43144. if (e + eBias >= 1) {
  43145. value += rt / c;
  43146. } else {
  43147. value += rt * Math.pow(2, 1 - eBias);
  43148. }
  43149. if (value * c >= 2) {
  43150. e++;
  43151. c /= 2;
  43152. }
  43153. if (e + eBias >= eMax) {
  43154. m = 0;
  43155. e = eMax;
  43156. } else if (e + eBias >= 1) {
  43157. m = (value * c - 1) * Math.pow(2, mLen);
  43158. e = e + eBias;
  43159. } else {
  43160. m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
  43161. e = 0;
  43162. }
  43163. }
  43164. for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
  43165. e = e << mLen | m;
  43166. eLen += mLen;
  43167. for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
  43168. buffer[offset + i - d] |= s * 128;
  43169. };
  43170. /***/ }),
  43171. /***/ 376:
  43172. /***/ ((module) => {
  43173. if (typeof Object.create === 'function') {
  43174. // implementation from standard node.js 'util' module
  43175. module.exports = function inherits(ctor, superCtor) {
  43176. if (superCtor) {
  43177. ctor.super_ = superCtor;
  43178. ctor.prototype = Object.create(superCtor.prototype, {
  43179. constructor: {
  43180. value: ctor,
  43181. enumerable: false,
  43182. writable: true,
  43183. configurable: true
  43184. }
  43185. });
  43186. }
  43187. };
  43188. } else {
  43189. // old school shim for old browsers
  43190. module.exports = function inherits(ctor, superCtor) {
  43191. if (superCtor) {
  43192. ctor.super_ = superCtor;
  43193. var TempCtor = function TempCtor() {};
  43194. TempCtor.prototype = superCtor.prototype;
  43195. ctor.prototype = new TempCtor();
  43196. ctor.prototype.constructor = ctor;
  43197. }
  43198. };
  43199. }
  43200. /***/ }),
  43201. /***/ 2755:
  43202. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43203. "use strict";
  43204. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  43205. var hasToStringTag = __webpack_require__(5994)();
  43206. var callBound = __webpack_require__(8780);
  43207. var $toString = callBound('Object.prototype.toString');
  43208. var isStandardArguments = function isArguments(value) {
  43209. if (hasToStringTag && value && _typeof(value) === 'object' && Symbol.toStringTag in value) {
  43210. return false;
  43211. }
  43212. return $toString(value) === '[object Arguments]';
  43213. };
  43214. var isLegacyArguments = function isArguments(value) {
  43215. if (isStandardArguments(value)) {
  43216. return true;
  43217. }
  43218. return value !== null && _typeof(value) === 'object' && typeof value.length === 'number' && value.length >= 0 && $toString(value) !== '[object Array]' && $toString(value.callee) === '[object Function]';
  43219. };
  43220. var supportsStandardArguments = function () {
  43221. return isStandardArguments(arguments);
  43222. }();
  43223. isStandardArguments.isLegacyArguments = isLegacyArguments; // for tests
  43224. module.exports = supportsStandardArguments ? isStandardArguments : isLegacyArguments;
  43225. /***/ }),
  43226. /***/ 8625:
  43227. /***/ ((module) => {
  43228. "use strict";
  43229. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  43230. var fnToStr = Function.prototype.toString;
  43231. var reflectApply = (typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === 'object' && Reflect !== null && Reflect.apply;
  43232. var badArrayLike;
  43233. var isCallableMarker;
  43234. if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {
  43235. try {
  43236. badArrayLike = Object.defineProperty({}, 'length', {
  43237. get: function get() {
  43238. throw isCallableMarker;
  43239. }
  43240. });
  43241. isCallableMarker = {}; // eslint-disable-next-line no-throw-literal
  43242. reflectApply(function () {
  43243. throw 42;
  43244. }, null, badArrayLike);
  43245. } catch (_) {
  43246. if (_ !== isCallableMarker) {
  43247. reflectApply = null;
  43248. }
  43249. }
  43250. } else {
  43251. reflectApply = null;
  43252. }
  43253. var constructorRegex = /^\s*class\b/;
  43254. var isES6ClassFn = function isES6ClassFunction(value) {
  43255. try {
  43256. var fnStr = fnToStr.call(value);
  43257. return constructorRegex.test(fnStr);
  43258. } catch (e) {
  43259. return false; // not a function
  43260. }
  43261. };
  43262. var tryFunctionObject = function tryFunctionToStr(value) {
  43263. try {
  43264. if (isES6ClassFn(value)) {
  43265. return false;
  43266. }
  43267. fnToStr.call(value);
  43268. return true;
  43269. } catch (e) {
  43270. return false;
  43271. }
  43272. };
  43273. var toStr = Object.prototype.toString;
  43274. var fnClass = '[object Function]';
  43275. var genClass = '[object GeneratorFunction]';
  43276. var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag; // better: use `has-tostringtag`
  43277. /* globals document: false */
  43278. var documentDotAll = (typeof document === "undefined" ? "undefined" : _typeof(document)) === 'object' && typeof document.all === 'undefined' && document.all !== undefined ? document.all : {};
  43279. module.exports = reflectApply ? function isCallable(value) {
  43280. if (value === documentDotAll) {
  43281. return true;
  43282. }
  43283. if (!value) {
  43284. return false;
  43285. }
  43286. if (typeof value !== 'function' && _typeof(value) !== 'object') {
  43287. return false;
  43288. }
  43289. if (typeof value === 'function' && !value.prototype) {
  43290. return true;
  43291. }
  43292. try {
  43293. reflectApply(value, null, badArrayLike);
  43294. } catch (e) {
  43295. if (e !== isCallableMarker) {
  43296. return false;
  43297. }
  43298. }
  43299. return !isES6ClassFn(value);
  43300. } : function isCallable(value) {
  43301. if (value === documentDotAll) {
  43302. return true;
  43303. }
  43304. if (!value) {
  43305. return false;
  43306. }
  43307. if (typeof value !== 'function' && _typeof(value) !== 'object') {
  43308. return false;
  43309. }
  43310. if (typeof value === 'function' && !value.prototype) {
  43311. return true;
  43312. }
  43313. if (hasToStringTag) {
  43314. return tryFunctionObject(value);
  43315. }
  43316. if (isES6ClassFn(value)) {
  43317. return false;
  43318. }
  43319. var strClass = toStr.call(value);
  43320. return strClass === fnClass || strClass === genClass;
  43321. };
  43322. /***/ }),
  43323. /***/ 6738:
  43324. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43325. "use strict";
  43326. var toStr = Object.prototype.toString;
  43327. var fnToStr = Function.prototype.toString;
  43328. var isFnRegex = /^\s*(?:function)?\*/;
  43329. var hasToStringTag = __webpack_require__(5994)();
  43330. var getProto = Object.getPrototypeOf;
  43331. var getGeneratorFunc = function getGeneratorFunc() {
  43332. // eslint-disable-line consistent-return
  43333. if (!hasToStringTag) {
  43334. return false;
  43335. }
  43336. try {
  43337. return Function('return function*() {}')();
  43338. } catch (e) {}
  43339. };
  43340. var GeneratorFunction;
  43341. module.exports = function isGeneratorFunction(fn) {
  43342. if (typeof fn !== 'function') {
  43343. return false;
  43344. }
  43345. if (isFnRegex.test(fnToStr.call(fn))) {
  43346. return true;
  43347. }
  43348. if (!hasToStringTag) {
  43349. var str = toStr.call(fn);
  43350. return str === '[object GeneratorFunction]';
  43351. }
  43352. if (!getProto) {
  43353. return false;
  43354. }
  43355. if (typeof GeneratorFunction === 'undefined') {
  43356. var generatorFunc = getGeneratorFunc();
  43357. GeneratorFunction = generatorFunc ? getProto(generatorFunc) : false;
  43358. }
  43359. return getProto(fn) === GeneratorFunction;
  43360. };
  43361. /***/ }),
  43362. /***/ 2703:
  43363. /***/ ((module) => {
  43364. "use strict";
  43365. /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */
  43366. module.exports = function isNaN(value) {
  43367. return value !== value;
  43368. };
  43369. /***/ }),
  43370. /***/ 2191:
  43371. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43372. "use strict";
  43373. var callBind = __webpack_require__(3862);
  43374. var define = __webpack_require__(7921);
  43375. var implementation = __webpack_require__(2703);
  43376. var getPolyfill = __webpack_require__(4828);
  43377. var shim = __webpack_require__(2568);
  43378. var polyfill = callBind(getPolyfill(), Number);
  43379. /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */
  43380. define(polyfill, {
  43381. getPolyfill: getPolyfill,
  43382. implementation: implementation,
  43383. shim: shim
  43384. });
  43385. module.exports = polyfill;
  43386. /***/ }),
  43387. /***/ 4828:
  43388. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43389. "use strict";
  43390. var implementation = __webpack_require__(2703);
  43391. module.exports = function getPolyfill() {
  43392. if (Number.isNaN && Number.isNaN(NaN) && !Number.isNaN('a')) {
  43393. return Number.isNaN;
  43394. }
  43395. return implementation;
  43396. };
  43397. /***/ }),
  43398. /***/ 2568:
  43399. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43400. "use strict";
  43401. var define = __webpack_require__(7921);
  43402. var getPolyfill = __webpack_require__(4828);
  43403. /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */
  43404. module.exports = function shimNumberIsNaN() {
  43405. var polyfill = getPolyfill();
  43406. define(Number, {
  43407. isNaN: polyfill
  43408. }, {
  43409. isNaN: function testIsNaN() {
  43410. return Number.isNaN !== polyfill;
  43411. }
  43412. });
  43413. return polyfill;
  43414. };
  43415. /***/ }),
  43416. /***/ 7913:
  43417. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  43418. "use strict";
  43419. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  43420. var forEach = __webpack_require__(5337);
  43421. var availableTypedArrays = __webpack_require__(6461);
  43422. var callBound = __webpack_require__(8780);
  43423. var $toString = callBound('Object.prototype.toString');
  43424. var hasToStringTag = __webpack_require__(5994)();
  43425. var g = typeof globalThis === 'undefined' ? __webpack_require__.g : globalThis;
  43426. var typedArrays = availableTypedArrays();
  43427. var $indexOf = callBound('Array.prototype.indexOf', true) || function indexOf(array, value) {
  43428. for (var i = 0; i < array.length; i += 1) {
  43429. if (array[i] === value) {
  43430. return i;
  43431. }
  43432. }
  43433. return -1;
  43434. };
  43435. var $slice = callBound('String.prototype.slice');
  43436. var toStrTags = {};
  43437. var gOPD = __webpack_require__(3999);
  43438. var getPrototypeOf = Object.getPrototypeOf; // require('getprototypeof');
  43439. if (hasToStringTag && gOPD && getPrototypeOf) {
  43440. forEach(typedArrays, function (typedArray) {
  43441. var arr = new g[typedArray]();
  43442. if (Symbol.toStringTag in arr) {
  43443. var proto = getPrototypeOf(arr);
  43444. var descriptor = gOPD(proto, Symbol.toStringTag);
  43445. if (!descriptor) {
  43446. var superProto = getPrototypeOf(proto);
  43447. descriptor = gOPD(superProto, Symbol.toStringTag);
  43448. }
  43449. toStrTags[typedArray] = descriptor.get;
  43450. }
  43451. });
  43452. }
  43453. var tryTypedArrays = function tryAllTypedArrays(value) {
  43454. var anyTrue = false;
  43455. forEach(toStrTags, function (getter, typedArray) {
  43456. if (!anyTrue) {
  43457. try {
  43458. anyTrue = getter.call(value) === typedArray;
  43459. } catch (e) {
  43460. /**/
  43461. }
  43462. }
  43463. });
  43464. return anyTrue;
  43465. };
  43466. module.exports = function isTypedArray(value) {
  43467. if (!value || _typeof(value) !== 'object') {
  43468. return false;
  43469. }
  43470. if (!hasToStringTag || !(Symbol.toStringTag in value)) {
  43471. var tag = $slice($toString(value), 8, -1);
  43472. return $indexOf(typedArrays, tag) > -1;
  43473. }
  43474. if (!gOPD) {
  43475. return false;
  43476. }
  43477. return tryTypedArrays(value);
  43478. };
  43479. /***/ }),
  43480. /***/ 3138:
  43481. /***/ ((module) => {
  43482. "use strict";
  43483. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  43484. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  43485. function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  43486. function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  43487. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  43488. function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
  43489. function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  43490. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  43491. function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
  43492. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  43493. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  43494. function Kareem() {
  43495. this._pres = new Map();
  43496. this._posts = new Map();
  43497. }
  43498. Kareem.skipWrappedFunction = function skipWrappedFunction() {
  43499. if (!(this instanceof Kareem.skipWrappedFunction)) {
  43500. return _construct(Kareem.skipWrappedFunction, Array.prototype.slice.call(arguments));
  43501. }
  43502. this.args = Array.prototype.slice.call(arguments);
  43503. };
  43504. Kareem.overwriteResult = function overwriteResult() {
  43505. if (!(this instanceof Kareem.overwriteResult)) {
  43506. return _construct(Kareem.overwriteResult, Array.prototype.slice.call(arguments));
  43507. }
  43508. this.args = Array.prototype.slice.call(arguments);
  43509. };
  43510. Kareem.prototype.execPre = function (name, context, args, callback) {
  43511. if (arguments.length === 3) {
  43512. callback = args;
  43513. args = [];
  43514. }
  43515. var pres = this._pres.get(name) || [];
  43516. var numPres = pres.length;
  43517. var numAsyncPres = pres.numAsync || 0;
  43518. var currentPre = 0;
  43519. var asyncPresLeft = numAsyncPres;
  43520. var done = false;
  43521. var $args = args;
  43522. var shouldSkipWrappedFunction = null;
  43523. if (!numPres) {
  43524. return nextTick(function () {
  43525. callback(null);
  43526. });
  43527. }
  43528. var next = function next() {
  43529. if (currentPre >= numPres) {
  43530. return;
  43531. }
  43532. var pre = pres[currentPre];
  43533. if (pre.isAsync) {
  43534. var args = [decorateNextFn(_next), decorateNextFn(function (error) {
  43535. if (error) {
  43536. if (done) {
  43537. return;
  43538. }
  43539. if (error instanceof Kareem.skipWrappedFunction) {
  43540. shouldSkipWrappedFunction = error;
  43541. } else {
  43542. done = true;
  43543. return callback(error);
  43544. }
  43545. }
  43546. if (--asyncPresLeft === 0 && currentPre >= numPres) {
  43547. return callback(shouldSkipWrappedFunction);
  43548. }
  43549. })];
  43550. callMiddlewareFunction(pre.fn, context, args, args[0]);
  43551. } else if (pre.fn.length > 0) {
  43552. var args = [decorateNextFn(_next)];
  43553. var _args = arguments.length >= 2 ? arguments : [null].concat($args);
  43554. for (var i = 1; i < _args.length; ++i) {
  43555. args.push(_args[i]);
  43556. }
  43557. callMiddlewareFunction(pre.fn, context, args, args[0]);
  43558. } else {
  43559. var maybePromiseLike = null;
  43560. try {
  43561. maybePromiseLike = pre.fn.call(context);
  43562. } catch (err) {
  43563. if (err != null) {
  43564. return callback(err);
  43565. }
  43566. }
  43567. if (isPromiseLike(maybePromiseLike)) {
  43568. maybePromiseLike.then(function () {
  43569. return _next();
  43570. }, function (err) {
  43571. return _next(err);
  43572. });
  43573. } else {
  43574. if (++currentPre >= numPres) {
  43575. if (asyncPresLeft > 0) {
  43576. // Leave parallel hooks to run
  43577. return;
  43578. } else {
  43579. return nextTick(function () {
  43580. callback(shouldSkipWrappedFunction);
  43581. });
  43582. }
  43583. }
  43584. next();
  43585. }
  43586. }
  43587. };
  43588. next.apply(null, [null].concat(args));
  43589. function _next(error) {
  43590. if (error) {
  43591. if (done) {
  43592. return;
  43593. }
  43594. if (error instanceof Kareem.skipWrappedFunction) {
  43595. shouldSkipWrappedFunction = error;
  43596. } else {
  43597. done = true;
  43598. return callback(error);
  43599. }
  43600. }
  43601. if (++currentPre >= numPres) {
  43602. if (asyncPresLeft > 0) {
  43603. // Leave parallel hooks to run
  43604. return;
  43605. } else {
  43606. return callback(shouldSkipWrappedFunction);
  43607. }
  43608. }
  43609. next.apply(context, arguments);
  43610. }
  43611. };
  43612. Kareem.prototype.execPreSync = function (name, context, args) {
  43613. var pres = this._pres.get(name) || [];
  43614. var numPres = pres.length;
  43615. for (var i = 0; i < numPres; ++i) {
  43616. pres[i].fn.apply(context, args || []);
  43617. }
  43618. };
  43619. Kareem.prototype.execPost = function (name, context, args, options, callback) {
  43620. if (arguments.length < 5) {
  43621. callback = options;
  43622. options = null;
  43623. }
  43624. var posts = this._posts.get(name) || [];
  43625. var numPosts = posts.length;
  43626. var currentPost = 0;
  43627. var firstError = null;
  43628. if (options && options.error) {
  43629. firstError = options.error;
  43630. }
  43631. if (!numPosts) {
  43632. return nextTick(function () {
  43633. callback.apply(null, [firstError].concat(args));
  43634. });
  43635. }
  43636. var next = function next() {
  43637. var post = posts[currentPost].fn;
  43638. var numArgs = 0;
  43639. var argLength = args.length;
  43640. var newArgs = [];
  43641. for (var i = 0; i < argLength; ++i) {
  43642. numArgs += args[i] && args[i]._kareemIgnore ? 0 : 1;
  43643. if (!args[i] || !args[i]._kareemIgnore) {
  43644. newArgs.push(args[i]);
  43645. }
  43646. }
  43647. if (firstError) {
  43648. if (post.length === numArgs + 2) {
  43649. var _cb = decorateNextFn(function (error) {
  43650. if (error) {
  43651. if (error instanceof Kareem.overwriteResult) {
  43652. args = error.args;
  43653. if (++currentPost >= numPosts) {
  43654. return callback.call(null, firstError);
  43655. }
  43656. return next();
  43657. }
  43658. firstError = error;
  43659. }
  43660. if (++currentPost >= numPosts) {
  43661. return callback.call(null, firstError);
  43662. }
  43663. next();
  43664. });
  43665. callMiddlewareFunction(post, context, [firstError].concat(newArgs).concat([_cb]), _cb);
  43666. } else {
  43667. if (++currentPost >= numPosts) {
  43668. return callback.call(null, firstError);
  43669. }
  43670. next();
  43671. }
  43672. } else {
  43673. var _cb2 = decorateNextFn(function (error) {
  43674. if (error) {
  43675. if (error instanceof Kareem.overwriteResult) {
  43676. args = error.args;
  43677. if (++currentPost >= numPosts) {
  43678. return callback.apply(null, [null].concat(args));
  43679. }
  43680. return next();
  43681. }
  43682. firstError = error;
  43683. return next();
  43684. }
  43685. if (++currentPost >= numPosts) {
  43686. return callback.apply(null, [null].concat(args));
  43687. }
  43688. next();
  43689. });
  43690. if (post.length === numArgs + 2) {
  43691. // Skip error handlers if no error
  43692. if (++currentPost >= numPosts) {
  43693. return callback.apply(null, [null].concat(args));
  43694. }
  43695. return next();
  43696. }
  43697. if (post.length === numArgs + 1) {
  43698. callMiddlewareFunction(post, context, newArgs.concat([_cb2]), _cb2);
  43699. } else {
  43700. var error;
  43701. var maybePromiseLike;
  43702. try {
  43703. maybePromiseLike = post.apply(context, newArgs);
  43704. } catch (err) {
  43705. error = err;
  43706. firstError = err;
  43707. }
  43708. if (isPromiseLike(maybePromiseLike)) {
  43709. return maybePromiseLike.then(function (res) {
  43710. _cb2(res instanceof Kareem.overwriteResult ? res : null);
  43711. }, function (err) {
  43712. return _cb2(err);
  43713. });
  43714. }
  43715. if (maybePromiseLike instanceof Kareem.overwriteResult) {
  43716. args = maybePromiseLike.args;
  43717. }
  43718. if (++currentPost >= numPosts) {
  43719. return callback.apply(null, [error].concat(args));
  43720. }
  43721. next();
  43722. }
  43723. }
  43724. };
  43725. next();
  43726. };
  43727. Kareem.prototype.execPostSync = function (name, context, args) {
  43728. var posts = this._posts.get(name) || [];
  43729. var numPosts = posts.length;
  43730. for (var i = 0; i < numPosts; ++i) {
  43731. var res = posts[i].fn.apply(context, args || []);
  43732. if (res instanceof Kareem.overwriteResult) {
  43733. args = res.args;
  43734. }
  43735. }
  43736. return args;
  43737. };
  43738. Kareem.prototype.createWrapperSync = function (name, fn) {
  43739. var kareem = this;
  43740. return function syncWrapper() {
  43741. kareem.execPreSync(name, this, arguments);
  43742. var toReturn = fn.apply(this, arguments);
  43743. var result = kareem.execPostSync(name, this, [toReturn]);
  43744. return result[0];
  43745. };
  43746. };
  43747. function _handleWrapError(instance, error, name, context, args, options, callback) {
  43748. if (options.useErrorHandlers) {
  43749. return instance.execPost(name, context, args, {
  43750. error: error
  43751. }, function (error) {
  43752. return typeof callback === 'function' && callback(error);
  43753. });
  43754. } else {
  43755. return typeof callback === 'function' && callback(error);
  43756. }
  43757. }
  43758. Kareem.prototype.wrap = function (name, fn, context, args, options) {
  43759. var lastArg = args.length > 0 ? args[args.length - 1] : null;
  43760. var argsWithoutCb = Array.from(args);
  43761. typeof lastArg === 'function' && argsWithoutCb.pop();
  43762. var _this = this;
  43763. options = options || {};
  43764. var checkForPromise = options.checkForPromise;
  43765. this.execPre(name, context, args, function (error) {
  43766. if (error && !(error instanceof Kareem.skipWrappedFunction)) {
  43767. var numCallbackParams = options.numCallbackParams || 0;
  43768. var errorArgs = options.contextParameter ? [context] : [];
  43769. for (var i = errorArgs.length; i < numCallbackParams; ++i) {
  43770. errorArgs.push(null);
  43771. }
  43772. return _handleWrapError(_this, error, name, context, errorArgs, options, lastArg);
  43773. }
  43774. var numParameters = fn.length;
  43775. var ret;
  43776. if (error instanceof Kareem.skipWrappedFunction) {
  43777. ret = error.args[0];
  43778. return _cb.apply(void 0, [null].concat(_toConsumableArray(error.args)));
  43779. } else {
  43780. try {
  43781. ret = fn.apply(context, argsWithoutCb.concat(_cb));
  43782. } catch (err) {
  43783. return _cb(err);
  43784. }
  43785. }
  43786. if (checkForPromise) {
  43787. if (isPromiseLike(ret)) {
  43788. // Thenable, use it
  43789. return ret.then(function (res) {
  43790. return _cb(null, res);
  43791. }, function (err) {
  43792. return _cb(err);
  43793. });
  43794. } // If `fn()` doesn't have a callback argument and doesn't return a
  43795. // promise, assume it is sync
  43796. if (numParameters < argsWithoutCb.length + 1) {
  43797. return _cb(null, ret);
  43798. }
  43799. }
  43800. function _cb() {
  43801. var argsWithoutError = Array.from(arguments);
  43802. argsWithoutError.shift();
  43803. if (options.nullResultByDefault && argsWithoutError.length === 0) {
  43804. argsWithoutError.push(null);
  43805. }
  43806. if (arguments[0]) {
  43807. // Assume error
  43808. return _handleWrapError(_this, arguments[0], name, context, argsWithoutError, options, lastArg);
  43809. } else {
  43810. _this.execPost(name, context, argsWithoutError, function () {
  43811. if (lastArg === null) {
  43812. return;
  43813. }
  43814. arguments[0] ? lastArg(arguments[0]) : lastArg.apply(context, arguments);
  43815. });
  43816. }
  43817. }
  43818. });
  43819. };
  43820. Kareem.prototype.filter = function (fn) {
  43821. var _this2 = this;
  43822. var clone = this.clone();
  43823. var pres = Array.from(clone._pres.keys());
  43824. var _loop = function _loop() {
  43825. var name = _pres[_i];
  43826. var hooks = _this2._pres.get(name).map(function (h) {
  43827. return Object.assign({}, h, {
  43828. name: name
  43829. });
  43830. }).filter(fn);
  43831. if (hooks.length === 0) {
  43832. clone._pres["delete"](name);
  43833. return "continue";
  43834. }
  43835. hooks.numAsync = hooks.filter(function (h) {
  43836. return h.isAsync;
  43837. }).length;
  43838. clone._pres.set(name, hooks);
  43839. };
  43840. for (var _i = 0, _pres = pres; _i < _pres.length; _i++) {
  43841. var _ret = _loop();
  43842. if (_ret === "continue") continue;
  43843. }
  43844. var posts = Array.from(clone._posts.keys());
  43845. var _loop2 = function _loop2() {
  43846. var name = _posts[_i2];
  43847. var hooks = _this2._posts.get(name).map(function (h) {
  43848. return Object.assign({}, h, {
  43849. name: name
  43850. });
  43851. }).filter(fn);
  43852. if (hooks.length === 0) {
  43853. clone._posts["delete"](name);
  43854. return "continue";
  43855. }
  43856. clone._posts.set(name, hooks);
  43857. };
  43858. for (var _i2 = 0, _posts = posts; _i2 < _posts.length; _i2++) {
  43859. var _ret2 = _loop2();
  43860. if (_ret2 === "continue") continue;
  43861. }
  43862. return clone;
  43863. };
  43864. Kareem.prototype.hasHooks = function (name) {
  43865. return this._pres.has(name) || this._posts.has(name);
  43866. };
  43867. Kareem.prototype.createWrapper = function (name, fn, context, options) {
  43868. var _this = this;
  43869. if (!this.hasHooks(name)) {
  43870. // Fast path: if there's no hooks for this function, just return the
  43871. // function wrapped in a nextTick()
  43872. return function () {
  43873. var _arguments = arguments,
  43874. _this3 = this;
  43875. nextTick(function () {
  43876. return fn.apply(_this3, _arguments);
  43877. });
  43878. };
  43879. }
  43880. return function () {
  43881. var _context = context || this;
  43882. _this.wrap(name, fn, _context, Array.from(arguments), options);
  43883. };
  43884. };
  43885. Kareem.prototype.pre = function (name, isAsync, fn, error, unshift) {
  43886. var options = {};
  43887. if (_typeof(isAsync) === 'object' && isAsync !== null) {
  43888. options = isAsync;
  43889. isAsync = options.isAsync;
  43890. } else if (typeof arguments[1] !== 'boolean') {
  43891. fn = isAsync;
  43892. isAsync = false;
  43893. }
  43894. var pres = this._pres.get(name) || [];
  43895. this._pres.set(name, pres);
  43896. if (isAsync) {
  43897. pres.numAsync = pres.numAsync || 0;
  43898. ++pres.numAsync;
  43899. }
  43900. if (typeof fn !== 'function') {
  43901. throw new Error('pre() requires a function, got "' + _typeof(fn) + '"');
  43902. }
  43903. if (unshift) {
  43904. pres.unshift(Object.assign({}, options, {
  43905. fn: fn,
  43906. isAsync: isAsync
  43907. }));
  43908. } else {
  43909. pres.push(Object.assign({}, options, {
  43910. fn: fn,
  43911. isAsync: isAsync
  43912. }));
  43913. }
  43914. return this;
  43915. };
  43916. Kareem.prototype.post = function (name, options, fn, unshift) {
  43917. var hooks = this._posts.get(name) || [];
  43918. if (typeof options === 'function') {
  43919. unshift = !!fn;
  43920. fn = options;
  43921. options = {};
  43922. }
  43923. if (typeof fn !== 'function') {
  43924. throw new Error('post() requires a function, got "' + _typeof(fn) + '"');
  43925. }
  43926. if (unshift) {
  43927. hooks.unshift(Object.assign({}, options, {
  43928. fn: fn
  43929. }));
  43930. } else {
  43931. hooks.push(Object.assign({}, options, {
  43932. fn: fn
  43933. }));
  43934. }
  43935. this._posts.set(name, hooks);
  43936. return this;
  43937. };
  43938. Kareem.prototype.clone = function () {
  43939. var n = new Kareem();
  43940. var _iterator = _createForOfIteratorHelper(this._pres.keys()),
  43941. _step;
  43942. try {
  43943. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  43944. var key = _step.value;
  43945. var clone = this._pres.get(key).slice();
  43946. clone.numAsync = this._pres.get(key).numAsync;
  43947. n._pres.set(key, clone);
  43948. }
  43949. } catch (err) {
  43950. _iterator.e(err);
  43951. } finally {
  43952. _iterator.f();
  43953. }
  43954. var _iterator2 = _createForOfIteratorHelper(this._posts.keys()),
  43955. _step2;
  43956. try {
  43957. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  43958. var _key = _step2.value;
  43959. n._posts.set(_key, this._posts.get(_key).slice());
  43960. }
  43961. } catch (err) {
  43962. _iterator2.e(err);
  43963. } finally {
  43964. _iterator2.f();
  43965. }
  43966. return n;
  43967. };
  43968. Kareem.prototype.merge = function (other, clone) {
  43969. clone = arguments.length === 1 ? true : clone;
  43970. var ret = clone ? this.clone() : this;
  43971. var _iterator3 = _createForOfIteratorHelper(other._pres.keys()),
  43972. _step3;
  43973. try {
  43974. var _loop3 = function _loop3() {
  43975. var key = _step3.value;
  43976. var sourcePres = ret._pres.get(key) || [];
  43977. var deduplicated = other._pres.get(key). // Deduplicate based on `fn`
  43978. filter(function (p) {
  43979. return sourcePres.map(function (_p) {
  43980. return _p.fn;
  43981. }).indexOf(p.fn) === -1;
  43982. });
  43983. var combined = sourcePres.concat(deduplicated);
  43984. combined.numAsync = sourcePres.numAsync || 0;
  43985. combined.numAsync += deduplicated.filter(function (p) {
  43986. return p.isAsync;
  43987. }).length;
  43988. ret._pres.set(key, combined);
  43989. };
  43990. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  43991. _loop3();
  43992. }
  43993. } catch (err) {
  43994. _iterator3.e(err);
  43995. } finally {
  43996. _iterator3.f();
  43997. }
  43998. var _iterator4 = _createForOfIteratorHelper(other._posts.keys()),
  43999. _step4;
  44000. try {
  44001. var _loop4 = function _loop4() {
  44002. var key = _step4.value;
  44003. var sourcePosts = ret._posts.get(key) || [];
  44004. var deduplicated = other._posts.get(key).filter(function (p) {
  44005. return sourcePosts.indexOf(p) === -1;
  44006. });
  44007. ret._posts.set(key, sourcePosts.concat(deduplicated));
  44008. };
  44009. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  44010. _loop4();
  44011. }
  44012. } catch (err) {
  44013. _iterator4.e(err);
  44014. } finally {
  44015. _iterator4.f();
  44016. }
  44017. return ret;
  44018. };
  44019. function callMiddlewareFunction(fn, context, args, next) {
  44020. var maybePromiseLike;
  44021. try {
  44022. maybePromiseLike = fn.apply(context, args);
  44023. } catch (error) {
  44024. return next(error);
  44025. }
  44026. if (isPromiseLike(maybePromiseLike)) {
  44027. maybePromiseLike.then(function () {
  44028. return next();
  44029. }, function (err) {
  44030. return next(err);
  44031. });
  44032. }
  44033. }
  44034. function isPromiseLike(v) {
  44035. return _typeof(v) === 'object' && v !== null && typeof v.then === 'function';
  44036. }
  44037. function decorateNextFn(fn) {
  44038. var called = false;
  44039. var _this = this;
  44040. return function () {
  44041. var _arguments2 = arguments;
  44042. // Ensure this function can only be called once
  44043. if (called) {
  44044. return;
  44045. }
  44046. called = true; // Make sure to clear the stack so try/catch doesn't catch errors
  44047. // in subsequent middleware
  44048. return nextTick(function () {
  44049. return fn.apply(_this, _arguments2);
  44050. });
  44051. };
  44052. }
  44053. var nextTick = (typeof ({env:{}}) === "undefined" ? "undefined" : _typeof(({env:{}}))) === 'object' && ({env:{}}) !== null && ({env:{}}).nextTick || function nextTick(cb) {
  44054. setTimeout(cb, 0);
  44055. };
  44056. module.exports = Kareem;
  44057. /***/ }),
  44058. /***/ 722:
  44059. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  44060. "use strict";
  44061. var inherits = __webpack_require__(376);
  44062. var HashBase = __webpack_require__(5125);
  44063. var Buffer = (__webpack_require__(9047).Buffer);
  44064. var ARRAY16 = new Array(16);
  44065. function MD5() {
  44066. HashBase.call(this, 64); // state
  44067. this._a = 0x67452301;
  44068. this._b = 0xefcdab89;
  44069. this._c = 0x98badcfe;
  44070. this._d = 0x10325476;
  44071. }
  44072. inherits(MD5, HashBase);
  44073. MD5.prototype._update = function () {
  44074. var M = ARRAY16;
  44075. for (var i = 0; i < 16; ++i) {
  44076. M[i] = this._block.readInt32LE(i * 4);
  44077. }
  44078. var a = this._a;
  44079. var b = this._b;
  44080. var c = this._c;
  44081. var d = this._d;
  44082. a = fnF(a, b, c, d, M[0], 0xd76aa478, 7);
  44083. d = fnF(d, a, b, c, M[1], 0xe8c7b756, 12);
  44084. c = fnF(c, d, a, b, M[2], 0x242070db, 17);
  44085. b = fnF(b, c, d, a, M[3], 0xc1bdceee, 22);
  44086. a = fnF(a, b, c, d, M[4], 0xf57c0faf, 7);
  44087. d = fnF(d, a, b, c, M[5], 0x4787c62a, 12);
  44088. c = fnF(c, d, a, b, M[6], 0xa8304613, 17);
  44089. b = fnF(b, c, d, a, M[7], 0xfd469501, 22);
  44090. a = fnF(a, b, c, d, M[8], 0x698098d8, 7);
  44091. d = fnF(d, a, b, c, M[9], 0x8b44f7af, 12);
  44092. c = fnF(c, d, a, b, M[10], 0xffff5bb1, 17);
  44093. b = fnF(b, c, d, a, M[11], 0x895cd7be, 22);
  44094. a = fnF(a, b, c, d, M[12], 0x6b901122, 7);
  44095. d = fnF(d, a, b, c, M[13], 0xfd987193, 12);
  44096. c = fnF(c, d, a, b, M[14], 0xa679438e, 17);
  44097. b = fnF(b, c, d, a, M[15], 0x49b40821, 22);
  44098. a = fnG(a, b, c, d, M[1], 0xf61e2562, 5);
  44099. d = fnG(d, a, b, c, M[6], 0xc040b340, 9);
  44100. c = fnG(c, d, a, b, M[11], 0x265e5a51, 14);
  44101. b = fnG(b, c, d, a, M[0], 0xe9b6c7aa, 20);
  44102. a = fnG(a, b, c, d, M[5], 0xd62f105d, 5);
  44103. d = fnG(d, a, b, c, M[10], 0x02441453, 9);
  44104. c = fnG(c, d, a, b, M[15], 0xd8a1e681, 14);
  44105. b = fnG(b, c, d, a, M[4], 0xe7d3fbc8, 20);
  44106. a = fnG(a, b, c, d, M[9], 0x21e1cde6, 5);
  44107. d = fnG(d, a, b, c, M[14], 0xc33707d6, 9);
  44108. c = fnG(c, d, a, b, M[3], 0xf4d50d87, 14);
  44109. b = fnG(b, c, d, a, M[8], 0x455a14ed, 20);
  44110. a = fnG(a, b, c, d, M[13], 0xa9e3e905, 5);
  44111. d = fnG(d, a, b, c, M[2], 0xfcefa3f8, 9);
  44112. c = fnG(c, d, a, b, M[7], 0x676f02d9, 14);
  44113. b = fnG(b, c, d, a, M[12], 0x8d2a4c8a, 20);
  44114. a = fnH(a, b, c, d, M[5], 0xfffa3942, 4);
  44115. d = fnH(d, a, b, c, M[8], 0x8771f681, 11);
  44116. c = fnH(c, d, a, b, M[11], 0x6d9d6122, 16);
  44117. b = fnH(b, c, d, a, M[14], 0xfde5380c, 23);
  44118. a = fnH(a, b, c, d, M[1], 0xa4beea44, 4);
  44119. d = fnH(d, a, b, c, M[4], 0x4bdecfa9, 11);
  44120. c = fnH(c, d, a, b, M[7], 0xf6bb4b60, 16);
  44121. b = fnH(b, c, d, a, M[10], 0xbebfbc70, 23);
  44122. a = fnH(a, b, c, d, M[13], 0x289b7ec6, 4);
  44123. d = fnH(d, a, b, c, M[0], 0xeaa127fa, 11);
  44124. c = fnH(c, d, a, b, M[3], 0xd4ef3085, 16);
  44125. b = fnH(b, c, d, a, M[6], 0x04881d05, 23);
  44126. a = fnH(a, b, c, d, M[9], 0xd9d4d039, 4);
  44127. d = fnH(d, a, b, c, M[12], 0xe6db99e5, 11);
  44128. c = fnH(c, d, a, b, M[15], 0x1fa27cf8, 16);
  44129. b = fnH(b, c, d, a, M[2], 0xc4ac5665, 23);
  44130. a = fnI(a, b, c, d, M[0], 0xf4292244, 6);
  44131. d = fnI(d, a, b, c, M[7], 0x432aff97, 10);
  44132. c = fnI(c, d, a, b, M[14], 0xab9423a7, 15);
  44133. b = fnI(b, c, d, a, M[5], 0xfc93a039, 21);
  44134. a = fnI(a, b, c, d, M[12], 0x655b59c3, 6);
  44135. d = fnI(d, a, b, c, M[3], 0x8f0ccc92, 10);
  44136. c = fnI(c, d, a, b, M[10], 0xffeff47d, 15);
  44137. b = fnI(b, c, d, a, M[1], 0x85845dd1, 21);
  44138. a = fnI(a, b, c, d, M[8], 0x6fa87e4f, 6);
  44139. d = fnI(d, a, b, c, M[15], 0xfe2ce6e0, 10);
  44140. c = fnI(c, d, a, b, M[6], 0xa3014314, 15);
  44141. b = fnI(b, c, d, a, M[13], 0x4e0811a1, 21);
  44142. a = fnI(a, b, c, d, M[4], 0xf7537e82, 6);
  44143. d = fnI(d, a, b, c, M[11], 0xbd3af235, 10);
  44144. c = fnI(c, d, a, b, M[2], 0x2ad7d2bb, 15);
  44145. b = fnI(b, c, d, a, M[9], 0xeb86d391, 21);
  44146. this._a = this._a + a | 0;
  44147. this._b = this._b + b | 0;
  44148. this._c = this._c + c | 0;
  44149. this._d = this._d + d | 0;
  44150. };
  44151. MD5.prototype._digest = function () {
  44152. // create padding and handle blocks
  44153. this._block[this._blockOffset++] = 0x80;
  44154. if (this._blockOffset > 56) {
  44155. this._block.fill(0, this._blockOffset, 64);
  44156. this._update();
  44157. this._blockOffset = 0;
  44158. }
  44159. this._block.fill(0, this._blockOffset, 56);
  44160. this._block.writeUInt32LE(this._length[0], 56);
  44161. this._block.writeUInt32LE(this._length[1], 60);
  44162. this._update(); // produce result
  44163. var buffer = Buffer.allocUnsafe(16);
  44164. buffer.writeInt32LE(this._a, 0);
  44165. buffer.writeInt32LE(this._b, 4);
  44166. buffer.writeInt32LE(this._c, 8);
  44167. buffer.writeInt32LE(this._d, 12);
  44168. return buffer;
  44169. };
  44170. function rotl(x, n) {
  44171. return x << n | x >>> 32 - n;
  44172. }
  44173. function fnF(a, b, c, d, m, k, s) {
  44174. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0;
  44175. }
  44176. function fnG(a, b, c, d, m, k, s) {
  44177. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0;
  44178. }
  44179. function fnH(a, b, c, d, m, k, s) {
  44180. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0;
  44181. }
  44182. function fnI(a, b, c, d, m, k, s) {
  44183. return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0;
  44184. }
  44185. module.exports = MD5;
  44186. /***/ }),
  44187. /***/ 9318:
  44188. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  44189. var bn = __webpack_require__(6781);
  44190. var brorand = __webpack_require__(7179);
  44191. function MillerRabin(rand) {
  44192. this.rand = rand || new brorand.Rand();
  44193. }
  44194. module.exports = MillerRabin;
  44195. MillerRabin.create = function create(rand) {
  44196. return new MillerRabin(rand);
  44197. };
  44198. MillerRabin.prototype._randbelow = function _randbelow(n) {
  44199. var len = n.bitLength();
  44200. var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found.
  44201. // This ensures that 0..n-1 have an equal probability of being selected.
  44202. do {
  44203. var a = new bn(this.rand.generate(min_bytes));
  44204. } while (a.cmp(n) >= 0);
  44205. return a;
  44206. };
  44207. MillerRabin.prototype._randrange = function _randrange(start, stop) {
  44208. // Generate a random number greater than or equal to start and less than stop.
  44209. var size = stop.sub(start);
  44210. return start.add(this._randbelow(size));
  44211. };
  44212. MillerRabin.prototype.test = function test(n, k, cb) {
  44213. var len = n.bitLength();
  44214. var red = bn.mont(n);
  44215. var rone = new bn(1).toRed(red);
  44216. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  44217. var n1 = n.subn(1);
  44218. for (var s = 0; !n1.testn(s); s++) {}
  44219. var d = n.shrn(s);
  44220. var rn1 = n1.toRed(red);
  44221. var prime = true;
  44222. for (; k > 0; k--) {
  44223. var a = this._randrange(new bn(2), n1);
  44224. if (cb) cb(a);
  44225. var x = a.toRed(red).redPow(d);
  44226. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  44227. for (var i = 1; i < s; i++) {
  44228. x = x.redSqr();
  44229. if (x.cmp(rone) === 0) return false;
  44230. if (x.cmp(rn1) === 0) break;
  44231. }
  44232. if (i === s) return false;
  44233. }
  44234. return prime;
  44235. };
  44236. MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
  44237. var len = n.bitLength();
  44238. var red = bn.mont(n);
  44239. var rone = new bn(1).toRed(red);
  44240. if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d;
  44241. var n1 = n.subn(1);
  44242. for (var s = 0; !n1.testn(s); s++) {}
  44243. var d = n.shrn(s);
  44244. var rn1 = n1.toRed(red);
  44245. for (; k > 0; k--) {
  44246. var a = this._randrange(new bn(2), n1);
  44247. var g = n.gcd(a);
  44248. if (g.cmpn(1) !== 0) return g;
  44249. var x = a.toRed(red).redPow(d);
  44250. if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue;
  44251. for (var i = 1; i < s; i++) {
  44252. x = x.redSqr();
  44253. if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n);
  44254. if (x.cmp(rn1) === 0) break;
  44255. }
  44256. if (i === s) {
  44257. x = x.redSqr();
  44258. return x.fromRed().subn(1).gcd(n);
  44259. }
  44260. }
  44261. return false;
  44262. };
  44263. /***/ }),
  44264. /***/ 1130:
  44265. /***/ ((module) => {
  44266. module.exports = assert;
  44267. function assert(val, msg) {
  44268. if (!val) throw new Error(msg || 'Assertion failed');
  44269. }
  44270. assert.equal = function assertEqual(l, r, msg) {
  44271. if (l != r) throw new Error(msg || 'Assertion failed: ' + l + ' != ' + r);
  44272. };
  44273. /***/ }),
  44274. /***/ 5522:
  44275. /***/ ((__unused_webpack_module, exports) => {
  44276. "use strict";
  44277. var utils = exports;
  44278. function toArray(msg, enc) {
  44279. if (Array.isArray(msg)) return msg.slice();
  44280. if (!msg) return [];
  44281. var res = [];
  44282. if (typeof msg !== 'string') {
  44283. for (var i = 0; i < msg.length; i++) {
  44284. res[i] = msg[i] | 0;
  44285. }
  44286. return res;
  44287. }
  44288. if (enc === 'hex') {
  44289. msg = msg.replace(/[^a-z0-9]+/ig, '');
  44290. if (msg.length % 2 !== 0) msg = '0' + msg;
  44291. for (var i = 0; i < msg.length; i += 2) {
  44292. res.push(parseInt(msg[i] + msg[i + 1], 16));
  44293. }
  44294. } else {
  44295. for (var i = 0; i < msg.length; i++) {
  44296. var c = msg.charCodeAt(i);
  44297. var hi = c >> 8;
  44298. var lo = c & 0xff;
  44299. if (hi) res.push(hi, lo);else res.push(lo);
  44300. }
  44301. }
  44302. return res;
  44303. }
  44304. utils.toArray = toArray;
  44305. function zero2(word) {
  44306. if (word.length === 1) return '0' + word;else return word;
  44307. }
  44308. utils.zero2 = zero2;
  44309. function toHex(msg) {
  44310. var res = '';
  44311. for (var i = 0; i < msg.length; i++) {
  44312. res += zero2(msg[i].toString(16));
  44313. }
  44314. return res;
  44315. }
  44316. utils.toHex = toHex;
  44317. utils.encode = function encode(arr, enc) {
  44318. if (enc === 'hex') return toHex(arr);else return arr;
  44319. };
  44320. /***/ }),
  44321. /***/ 3564:
  44322. /***/ ((module, exports, __webpack_require__) => {
  44323. "use strict";
  44324. module.exports = exports = __webpack_require__(8424);
  44325. /***/ }),
  44326. /***/ 8424:
  44327. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  44328. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  44329. /* eslint strict:off */
  44330. /* eslint no-var: off */
  44331. /* eslint no-redeclare: off */
  44332. var stringToParts = __webpack_require__(7355); // These properties are special and can open client libraries to security
  44333. // issues
  44334. var ignoreProperties = ['__proto__', 'constructor', 'prototype'];
  44335. /**
  44336. * Returns the value of object `o` at the given `path`.
  44337. *
  44338. * ####Example:
  44339. *
  44340. * var obj = {
  44341. * comments: [
  44342. * { title: 'exciting!', _doc: { title: 'great!' }}
  44343. * , { title: 'number dos' }
  44344. * ]
  44345. * }
  44346. *
  44347. * mpath.get('comments.0.title', o) // 'exciting!'
  44348. * mpath.get('comments.0.title', o, '_doc') // 'great!'
  44349. * mpath.get('comments.title', o) // ['exciting!', 'number dos']
  44350. *
  44351. * // summary
  44352. * mpath.get(path, o)
  44353. * mpath.get(path, o, special)
  44354. * mpath.get(path, o, map)
  44355. * mpath.get(path, o, special, map)
  44356. *
  44357. * @param {String} path
  44358. * @param {Object} o
  44359. * @param {String} [special] When this property name is present on any object in the path, walking will continue on the value of this property.
  44360. * @param {Function} [map] Optional function which receives each individual found value. The value returned from `map` is used in the original values place.
  44361. */
  44362. exports.get = function (path, o, special, map) {
  44363. var lookup;
  44364. if ('function' == typeof special) {
  44365. if (special.length < 2) {
  44366. map = special;
  44367. special = undefined;
  44368. } else {
  44369. lookup = special;
  44370. special = undefined;
  44371. }
  44372. }
  44373. map || (map = K);
  44374. var parts = 'string' == typeof path ? stringToParts(path) : path;
  44375. if (!Array.isArray(parts)) {
  44376. throw new TypeError('Invalid `path`. Must be either string or array');
  44377. }
  44378. var obj = o,
  44379. part;
  44380. for (var i = 0; i < parts.length; ++i) {
  44381. part = parts[i];
  44382. if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
  44383. throw new TypeError('Each segment of path to `get()` must be a string or number, got ' + _typeof(parts[i]));
  44384. }
  44385. if (Array.isArray(obj) && !/^\d+$/.test(part)) {
  44386. // reading a property from the array items
  44387. var paths = parts.slice(i); // Need to `concat()` to avoid `map()` calling a constructor of an array
  44388. // subclass
  44389. return [].concat(obj).map(function (item) {
  44390. return item ? exports.get(paths, item, special || lookup, map) : map(undefined);
  44391. });
  44392. }
  44393. if (lookup) {
  44394. obj = lookup(obj, part);
  44395. } else {
  44396. var _from = special && obj[special] ? obj[special] : obj;
  44397. obj = _from instanceof Map ? _from.get(part) : _from[part];
  44398. }
  44399. if (!obj) return map(obj);
  44400. }
  44401. return map(obj);
  44402. };
  44403. /**
  44404. * Returns true if `in` returns true for every piece of the path
  44405. *
  44406. * @param {String} path
  44407. * @param {Object} o
  44408. */
  44409. exports.has = function (path, o) {
  44410. var parts = typeof path === 'string' ? stringToParts(path) : path;
  44411. if (!Array.isArray(parts)) {
  44412. throw new TypeError('Invalid `path`. Must be either string or array');
  44413. }
  44414. var len = parts.length;
  44415. var cur = o;
  44416. for (var i = 0; i < len; ++i) {
  44417. if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
  44418. throw new TypeError('Each segment of path to `has()` must be a string or number, got ' + _typeof(parts[i]));
  44419. }
  44420. if (cur == null || _typeof(cur) !== 'object' || !(parts[i] in cur)) {
  44421. return false;
  44422. }
  44423. cur = cur[parts[i]];
  44424. }
  44425. return true;
  44426. };
  44427. /**
  44428. * Deletes the last piece of `path`
  44429. *
  44430. * @param {String} path
  44431. * @param {Object} o
  44432. */
  44433. exports.unset = function (path, o) {
  44434. var parts = typeof path === 'string' ? stringToParts(path) : path;
  44435. if (!Array.isArray(parts)) {
  44436. throw new TypeError('Invalid `path`. Must be either string or array');
  44437. }
  44438. var len = parts.length;
  44439. var cur = o;
  44440. for (var i = 0; i < len; ++i) {
  44441. if (cur == null || _typeof(cur) !== 'object' || !(parts[i] in cur)) {
  44442. return false;
  44443. }
  44444. if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
  44445. throw new TypeError('Each segment of path to `unset()` must be a string or number, got ' + _typeof(parts[i]));
  44446. } // Disallow any updates to __proto__ or special properties.
  44447. if (ignoreProperties.indexOf(parts[i]) !== -1) {
  44448. return false;
  44449. }
  44450. if (i === len - 1) {
  44451. delete cur[parts[i]];
  44452. return true;
  44453. }
  44454. cur = cur instanceof Map ? cur.get(parts[i]) : cur[parts[i]];
  44455. }
  44456. return true;
  44457. };
  44458. /**
  44459. * Sets the `val` at the given `path` of object `o`.
  44460. *
  44461. * @param {String} path
  44462. * @param {Anything} val
  44463. * @param {Object} o
  44464. * @param {String} [special] When this property name is present on any object in the path, walking will continue on the value of this property.
  44465. * @param {Function} [map] Optional function which is passed each individual value before setting it. The value returned from `map` is used in the original values place.
  44466. */
  44467. exports.set = function (path, val, o, special, map, _copying) {
  44468. var lookup;
  44469. if ('function' == typeof special) {
  44470. if (special.length < 2) {
  44471. map = special;
  44472. special = undefined;
  44473. } else {
  44474. lookup = special;
  44475. special = undefined;
  44476. }
  44477. }
  44478. map || (map = K);
  44479. var parts = 'string' == typeof path ? stringToParts(path) : path;
  44480. if (!Array.isArray(parts)) {
  44481. throw new TypeError('Invalid `path`. Must be either string or array');
  44482. }
  44483. if (null == o) return;
  44484. for (var i = 0; i < parts.length; ++i) {
  44485. if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
  44486. throw new TypeError('Each segment of path to `set()` must be a string or number, got ' + _typeof(parts[i]));
  44487. } // Silently ignore any updates to `__proto__`, these are potentially
  44488. // dangerous if using mpath with unsanitized data.
  44489. if (ignoreProperties.indexOf(parts[i]) !== -1) {
  44490. return;
  44491. }
  44492. } // the existance of $ in a path tells us if the user desires
  44493. // the copying of an array instead of setting each value of
  44494. // the array to the one by one to matching positions of the
  44495. // current array. Unless the user explicitly opted out by passing
  44496. // false, see Automattic/mongoose#6273
  44497. var copy = _copying || /\$/.test(path) && _copying !== false,
  44498. obj = o,
  44499. part;
  44500. for (var i = 0, len = parts.length - 1; i < len; ++i) {
  44501. part = parts[i];
  44502. if ('$' == part) {
  44503. if (i == len - 1) {
  44504. break;
  44505. } else {
  44506. continue;
  44507. }
  44508. }
  44509. if (Array.isArray(obj) && !/^\d+$/.test(part)) {
  44510. var paths = parts.slice(i);
  44511. if (!copy && Array.isArray(val)) {
  44512. for (var j = 0; j < obj.length && j < val.length; ++j) {
  44513. // assignment of single values of array
  44514. exports.set(paths, val[j], obj[j], special || lookup, map, copy);
  44515. }
  44516. } else {
  44517. for (var j = 0; j < obj.length; ++j) {
  44518. // assignment of entire value
  44519. exports.set(paths, val, obj[j], special || lookup, map, copy);
  44520. }
  44521. }
  44522. return;
  44523. }
  44524. if (lookup) {
  44525. obj = lookup(obj, part);
  44526. } else {
  44527. var _to = special && obj[special] ? obj[special] : obj;
  44528. obj = _to instanceof Map ? _to.get(part) : _to[part];
  44529. }
  44530. if (!obj) return;
  44531. } // process the last property of the path
  44532. part = parts[len]; // use the special property if exists
  44533. if (special && obj[special]) {
  44534. obj = obj[special];
  44535. } // set the value on the last branch
  44536. if (Array.isArray(obj) && !/^\d+$/.test(part)) {
  44537. if (!copy && Array.isArray(val)) {
  44538. _setArray(obj, val, part, lookup, special, map);
  44539. } else {
  44540. for (var j = 0; j < obj.length; ++j) {
  44541. var item = obj[j];
  44542. if (item) {
  44543. if (lookup) {
  44544. lookup(item, part, map(val));
  44545. } else {
  44546. if (item[special]) item = item[special];
  44547. item[part] = map(val);
  44548. }
  44549. }
  44550. }
  44551. }
  44552. } else {
  44553. if (lookup) {
  44554. lookup(obj, part, map(val));
  44555. } else if (obj instanceof Map) {
  44556. obj.set(part, map(val));
  44557. } else {
  44558. obj[part] = map(val);
  44559. }
  44560. }
  44561. };
  44562. /*!
  44563. * Split a string path into components delimited by '.' or
  44564. * '[\d+]'
  44565. *
  44566. * #### Example:
  44567. * stringToParts('foo[0].bar.1'); // ['foo', '0', 'bar', '1']
  44568. */
  44569. exports.stringToParts = stringToParts;
  44570. /*!
  44571. * Recursively set nested arrays
  44572. */
  44573. function _setArray(obj, val, part, lookup, special, map) {
  44574. for (var item, j = 0; j < obj.length && j < val.length; ++j) {
  44575. item = obj[j];
  44576. if (Array.isArray(item) && Array.isArray(val[j])) {
  44577. _setArray(item, val[j], part, lookup, special, map);
  44578. } else if (item) {
  44579. if (lookup) {
  44580. lookup(item, part, map(val[j]));
  44581. } else {
  44582. if (item[special]) item = item[special];
  44583. item[part] = map(val[j]);
  44584. }
  44585. }
  44586. }
  44587. }
  44588. /*!
  44589. * Returns the value passed to it.
  44590. */
  44591. function K(v) {
  44592. return v;
  44593. }
  44594. /***/ }),
  44595. /***/ 7355:
  44596. /***/ ((module) => {
  44597. "use strict";
  44598. module.exports = function stringToParts(str) {
  44599. var result = [];
  44600. var curPropertyName = '';
  44601. var state = 'DEFAULT';
  44602. for (var i = 0; i < str.length; ++i) {
  44603. // Fall back to treating as property name rather than bracket notation if
  44604. // square brackets contains something other than a number.
  44605. if (state === 'IN_SQUARE_BRACKETS' && !/\d/.test(str[i]) && str[i] !== ']') {
  44606. state = 'DEFAULT';
  44607. curPropertyName = result[result.length - 1] + '[' + curPropertyName;
  44608. result.splice(result.length - 1, 1);
  44609. }
  44610. if (str[i] === '[') {
  44611. if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
  44612. result.push(curPropertyName);
  44613. curPropertyName = '';
  44614. }
  44615. state = 'IN_SQUARE_BRACKETS';
  44616. } else if (str[i] === ']') {
  44617. if (state === 'IN_SQUARE_BRACKETS') {
  44618. state = 'IMMEDIATELY_AFTER_SQUARE_BRACKETS';
  44619. result.push(curPropertyName);
  44620. curPropertyName = '';
  44621. } else {
  44622. state = 'DEFAULT';
  44623. curPropertyName += str[i];
  44624. }
  44625. } else if (str[i] === '.') {
  44626. if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
  44627. result.push(curPropertyName);
  44628. curPropertyName = '';
  44629. }
  44630. state = 'DEFAULT';
  44631. } else {
  44632. curPropertyName += str[i];
  44633. }
  44634. }
  44635. if (state !== 'IMMEDIATELY_AFTER_SQUARE_BRACKETS') {
  44636. result.push(curPropertyName);
  44637. }
  44638. return result;
  44639. };
  44640. /***/ }),
  44641. /***/ 3231:
  44642. /***/ ((module, exports) => {
  44643. "use strict";
  44644. /**
  44645. * methods a collection must implement
  44646. */
  44647. var methods = ['find', 'findOne', 'update', 'updateMany', 'updateOne', 'replaceOne', 'remove', 'count', 'distinct', 'findOneAndDelete', 'findOneAndUpdate', 'aggregate', 'findCursor', 'deleteOne', 'deleteMany'];
  44648. /**
  44649. * Collection base class from which implementations inherit
  44650. */
  44651. function Collection() {}
  44652. for (var i = 0, len = methods.length; i < len; ++i) {
  44653. var method = methods[i];
  44654. Collection.prototype[method] = notImplemented(method);
  44655. }
  44656. module.exports = exports = Collection;
  44657. Collection.methods = methods;
  44658. /**
  44659. * creates a function which throws an implementation error
  44660. */
  44661. function notImplemented(method) {
  44662. return function () {
  44663. throw new Error('collection.' + method + ' not implemented');
  44664. };
  44665. }
  44666. /***/ }),
  44667. /***/ 8514:
  44668. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  44669. "use strict";
  44670. var env = __webpack_require__(3669);
  44671. if ('unknown' == env.type) {
  44672. throw new Error('Unknown environment');
  44673. }
  44674. module.exports = env.isNode ? __webpack_require__(1186) : env.isMongo ? __webpack_require__(3231) : __webpack_require__(3231);
  44675. /***/ }),
  44676. /***/ 1186:
  44677. /***/ ((module, exports, __webpack_require__) => {
  44678. "use strict";
  44679. /**
  44680. * Module dependencies
  44681. */
  44682. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  44683. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  44684. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  44685. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  44686. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  44687. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  44688. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  44689. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  44690. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  44691. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  44692. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  44693. var Collection = __webpack_require__(3231);
  44694. var NodeCollection = /*#__PURE__*/function (_Collection) {
  44695. _inherits(NodeCollection, _Collection);
  44696. var _super = _createSuper(NodeCollection);
  44697. function NodeCollection(col) {
  44698. var _this;
  44699. _classCallCheck(this, NodeCollection);
  44700. _this = _super.call(this);
  44701. _this.collection = col;
  44702. _this.collectionName = col.collectionName;
  44703. return _this;
  44704. }
  44705. /**
  44706. * find(match, options, function(err, docs))
  44707. */
  44708. _createClass(NodeCollection, [{
  44709. key: "find",
  44710. value: function find(match, options, cb) {
  44711. var cursor = this.collection.find(match, options);
  44712. try {
  44713. cursor.toArray(cb);
  44714. } catch (error) {
  44715. cb(error);
  44716. }
  44717. }
  44718. /**
  44719. * findOne(match, options, function(err, doc))
  44720. */
  44721. }, {
  44722. key: "findOne",
  44723. value: function findOne(match, options, cb) {
  44724. this.collection.findOne(match, options, cb);
  44725. }
  44726. /**
  44727. * count(match, options, function(err, count))
  44728. */
  44729. }, {
  44730. key: "count",
  44731. value: function count(match, options, cb) {
  44732. this.collection.count(match, options, cb);
  44733. }
  44734. /**
  44735. * distinct(prop, match, options, function(err, count))
  44736. */
  44737. }, {
  44738. key: "distinct",
  44739. value: function distinct(prop, match, options, cb) {
  44740. this.collection.distinct(prop, match, options, cb);
  44741. }
  44742. /**
  44743. * update(match, update, options, function(err[, result]))
  44744. */
  44745. }, {
  44746. key: "update",
  44747. value: function update(match, _update, options, cb) {
  44748. this.collection.update(match, _update, options, cb);
  44749. }
  44750. /**
  44751. * update(match, update, options, function(err[, result]))
  44752. */
  44753. }, {
  44754. key: "updateMany",
  44755. value: function updateMany(match, update, options, cb) {
  44756. this.collection.updateMany(match, update, options, cb);
  44757. }
  44758. /**
  44759. * update(match, update, options, function(err[, result]))
  44760. */
  44761. }, {
  44762. key: "updateOne",
  44763. value: function updateOne(match, update, options, cb) {
  44764. this.collection.updateOne(match, update, options, cb);
  44765. }
  44766. /**
  44767. * replaceOne(match, update, options, function(err[, result]))
  44768. */
  44769. }, {
  44770. key: "replaceOne",
  44771. value: function replaceOne(match, update, options, cb) {
  44772. this.collection.replaceOne(match, update, options, cb);
  44773. }
  44774. /**
  44775. * deleteOne(match, options, function(err[, result])
  44776. */
  44777. }, {
  44778. key: "deleteOne",
  44779. value: function deleteOne(match, options, cb) {
  44780. this.collection.deleteOne(match, options, cb);
  44781. }
  44782. /**
  44783. * deleteMany(match, options, function(err[, result])
  44784. */
  44785. }, {
  44786. key: "deleteMany",
  44787. value: function deleteMany(match, options, cb) {
  44788. this.collection.deleteMany(match, options, cb);
  44789. }
  44790. /**
  44791. * remove(match, options, function(err[, result])
  44792. */
  44793. }, {
  44794. key: "remove",
  44795. value: function remove(match, options, cb) {
  44796. this.collection.remove(match, options, cb);
  44797. }
  44798. /**
  44799. * findOneAndDelete(match, options, function(err[, result])
  44800. */
  44801. }, {
  44802. key: "findOneAndDelete",
  44803. value: function findOneAndDelete(match, options, cb) {
  44804. this.collection.findOneAndDelete(match, options, cb);
  44805. }
  44806. /**
  44807. * findOneAndUpdate(match, update, options, function(err[, result])
  44808. */
  44809. }, {
  44810. key: "findOneAndUpdate",
  44811. value: function findOneAndUpdate(match, update, options, cb) {
  44812. this.collection.findOneAndUpdate(match, update, options, cb);
  44813. }
  44814. /**
  44815. * var cursor = findCursor(match, options)
  44816. */
  44817. }, {
  44818. key: "findCursor",
  44819. value: function findCursor(match, options) {
  44820. return this.collection.find(match, options);
  44821. }
  44822. /**
  44823. * aggregation(operators..., function(err, doc))
  44824. * TODO
  44825. */
  44826. }]);
  44827. return NodeCollection;
  44828. }(Collection);
  44829. /**
  44830. * Expose
  44831. */
  44832. module.exports = exports = NodeCollection;
  44833. /***/ }),
  44834. /***/ 3669:
  44835. /***/ ((module, exports, __webpack_require__) => {
  44836. "use strict";
  44837. /* module decorator */ module = __webpack_require__.nmd(module);
  44838. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  44839. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  44840. exports.isNode = 'undefined' != typeof ({env:{}}) && 'object' == ( false ? 0 : _typeof(module)) && 'object' == (typeof __webpack_require__.g === "undefined" ? "undefined" : _typeof(__webpack_require__.g)) && 'function' == typeof Buffer && ({env:{}}).argv;
  44841. exports.isMongo = !exports.isNode && 'function' == typeof printjson && 'function' == typeof ObjectId && 'function' == typeof rs && 'function' == typeof sh;
  44842. exports.isBrowser = !exports.isNode && !exports.isMongo && 'undefined' != typeof window;
  44843. exports.type = exports.isNode ? 'node' : exports.isMongo ? 'mongo' : exports.isBrowser ? 'browser' : 'unknown';
  44844. /***/ }),
  44845. /***/ 5417:
  44846. /***/ ((module, exports, __webpack_require__) => {
  44847. "use strict";
  44848. /**
  44849. * Dependencies
  44850. */
  44851. function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
  44852. function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  44853. function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  44854. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  44855. var assert = __webpack_require__(9373);
  44856. var util = __webpack_require__(161);
  44857. var utils = __webpack_require__(728);
  44858. var debug = __webpack_require__(8801)('mquery');
  44859. /**
  44860. * Query constructor used for building queries.
  44861. *
  44862. * ####Example:
  44863. *
  44864. * var query = new Query({ name: 'mquery' });
  44865. * query.setOptions({ collection: moduleCollection })
  44866. * query.where('age').gte(21).exec(callback);
  44867. *
  44868. * @param {Object} [criteria]
  44869. * @param {Object} [options]
  44870. * @api public
  44871. */
  44872. function Query(criteria, options) {
  44873. if (!(this instanceof Query)) return new Query(criteria, options);
  44874. var proto = this.constructor.prototype;
  44875. this.op = proto.op || undefined;
  44876. this.options = Object.assign({}, proto.options);
  44877. this._conditions = proto._conditions ? utils.clone(proto._conditions) : {};
  44878. this._fields = proto._fields ? utils.clone(proto._fields) : undefined;
  44879. this._update = proto._update ? utils.clone(proto._update) : undefined;
  44880. this._path = proto._path || undefined;
  44881. this._distinct = proto._distinct || undefined;
  44882. this._collection = proto._collection || undefined;
  44883. this._traceFunction = proto._traceFunction || undefined;
  44884. if (options) {
  44885. this.setOptions(options);
  44886. }
  44887. if (criteria) {
  44888. if (criteria.find && criteria.remove && criteria.update) {
  44889. // quack quack!
  44890. this.collection(criteria);
  44891. } else {
  44892. this.find(criteria);
  44893. }
  44894. }
  44895. }
  44896. /**
  44897. * This is a parameter that the user can set which determines if mquery
  44898. * uses $within or $geoWithin for queries. It defaults to true which
  44899. * means $geoWithin will be used. If using MongoDB < 2.4 you should
  44900. * set this to false.
  44901. *
  44902. * @api public
  44903. * @property use$geoWithin
  44904. */
  44905. var $withinCmd = '$geoWithin';
  44906. Object.defineProperty(Query, 'use$geoWithin', {
  44907. get: function get() {
  44908. return $withinCmd == '$geoWithin';
  44909. },
  44910. set: function set(v) {
  44911. if (true === v) {
  44912. // mongodb >= 2.4
  44913. $withinCmd = '$geoWithin';
  44914. } else {
  44915. $withinCmd = '$within';
  44916. }
  44917. }
  44918. });
  44919. /**
  44920. * Converts this query to a constructor function with all arguments and options retained.
  44921. *
  44922. * ####Example
  44923. *
  44924. * // Create a query that will read documents with a "video" category from
  44925. * // `aCollection` on the primary node in the replica-set unless it is down,
  44926. * // in which case we'll read from a secondary node.
  44927. * var query = mquery({ category: 'video' })
  44928. * query.setOptions({ collection: aCollection, read: 'primaryPreferred' });
  44929. *
  44930. * // create a constructor based off these settings
  44931. * var Video = query.toConstructor();
  44932. *
  44933. * // Video is now a subclass of mquery() and works the same way but with the
  44934. * // default query parameters and options set.
  44935. *
  44936. * // run a query with the previous settings but filter for movies with names
  44937. * // that start with "Life".
  44938. * Video().where({ name: /^Life/ }).exec(cb);
  44939. *
  44940. * @return {Query} new Query
  44941. * @api public
  44942. */
  44943. Query.prototype.toConstructor = function toConstructor() {
  44944. function CustomQuery(criteria, options) {
  44945. if (!(this instanceof CustomQuery)) return new CustomQuery(criteria, options);
  44946. Query.call(this, criteria, options);
  44947. }
  44948. utils.inherits(CustomQuery, Query); // set inherited defaults
  44949. var p = CustomQuery.prototype;
  44950. p.options = {};
  44951. p.setOptions(this.options);
  44952. p.op = this.op;
  44953. p._conditions = utils.clone(this._conditions);
  44954. p._fields = utils.clone(this._fields);
  44955. p._update = utils.clone(this._update);
  44956. p._path = this._path;
  44957. p._distinct = this._distinct;
  44958. p._collection = this._collection;
  44959. p._traceFunction = this._traceFunction;
  44960. return CustomQuery;
  44961. };
  44962. /**
  44963. * Sets query options.
  44964. *
  44965. * ####Options:
  44966. *
  44967. * - [tailable](http://www.mongodb.org/display/DOCS/Tailable+Cursors) *
  44968. * - [sort](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Bsort(\)%7D%7D) *
  44969. * - [limit](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Blimit%28%29%7D%7D) *
  44970. * - [skip](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Bskip%28%29%7D%7D) *
  44971. * - [maxScan](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24maxScan) *
  44972. * - [maxTime](http://docs.mongodb.org/manual/reference/operator/meta/maxTimeMS/#op._S_maxTimeMS) *
  44973. * - [batchSize](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7BbatchSize%28%29%7D%7D) *
  44974. * - [comment](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24comment) *
  44975. * - [snapshot](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Bsnapshot%28%29%7D%7D) *
  44976. * - [hint](http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24hint) *
  44977. * - [slaveOk](http://docs.mongodb.org/manual/applications/replication/#read-preference) *
  44978. * - [safe](http://www.mongodb.org/display/DOCS/getLastError+Command)
  44979. * - collection the collection to query against
  44980. *
  44981. * _* denotes a query helper method is also available_
  44982. *
  44983. * @param {Object} options
  44984. * @api public
  44985. */
  44986. Query.prototype.setOptions = function (options) {
  44987. if (!(options && utils.isObject(options))) return this; // set arbitrary options
  44988. var methods = utils.keys(options);
  44989. var method;
  44990. for (var i = 0; i < methods.length; ++i) {
  44991. method = methods[i]; // use methods if exist (safer option manipulation)
  44992. if ('function' == typeof this[method]) {
  44993. var args = Array.isArray(options[method]) ? options[method] : [options[method]];
  44994. this[method].apply(this, args);
  44995. } else {
  44996. this.options[method] = options[method];
  44997. }
  44998. }
  44999. return this;
  45000. };
  45001. /**
  45002. * Sets this Querys collection.
  45003. *
  45004. * @param {Collection} coll
  45005. * @return {Query} this
  45006. */
  45007. Query.prototype.collection = function collection(coll) {
  45008. this._collection = new Query.Collection(coll);
  45009. return this;
  45010. };
  45011. /**
  45012. * Adds a collation to this op (MongoDB 3.4 and up)
  45013. *
  45014. * ####Example
  45015. *
  45016. * query.find().collation({ locale: "en_US", strength: 1 })
  45017. *
  45018. * @param {Object} value
  45019. * @return {Query} this
  45020. * @see MongoDB docs https://docs.mongodb.com/manual/reference/method/cursor.collation/#cursor.collation
  45021. * @api public
  45022. */
  45023. Query.prototype.collation = function (value) {
  45024. this.options.collation = value;
  45025. return this;
  45026. };
  45027. /**
  45028. * Specifies a `$where` condition
  45029. *
  45030. * Use `$where` when you need to select documents using a JavaScript expression.
  45031. *
  45032. * ####Example
  45033. *
  45034. * query.$where('this.comments.length > 10 || this.name.length > 5')
  45035. *
  45036. * query.$where(function () {
  45037. * return this.comments.length > 10 || this.name.length > 5;
  45038. * })
  45039. *
  45040. * @param {String|Function} js javascript string or function
  45041. * @return {Query} this
  45042. * @memberOf Query
  45043. * @method $where
  45044. * @api public
  45045. */
  45046. Query.prototype.$where = function (js) {
  45047. this._conditions.$where = js;
  45048. return this;
  45049. };
  45050. /**
  45051. * Specifies a `path` for use with chaining.
  45052. *
  45053. * ####Example
  45054. *
  45055. * // instead of writing:
  45056. * User.find({age: {$gte: 21, $lte: 65}}, callback);
  45057. *
  45058. * // we can instead write:
  45059. * User.where('age').gte(21).lte(65);
  45060. *
  45061. * // passing query conditions is permitted
  45062. * User.find().where({ name: 'vonderful' })
  45063. *
  45064. * // chaining
  45065. * User
  45066. * .where('age').gte(21).lte(65)
  45067. * .where('name', /^vonderful/i)
  45068. * .where('friends').slice(10)
  45069. * .exec(callback)
  45070. *
  45071. * @param {String} [path]
  45072. * @param {Object} [val]
  45073. * @return {Query} this
  45074. * @api public
  45075. */
  45076. Query.prototype.where = function () {
  45077. if (!arguments.length) return this;
  45078. if (!this.op) this.op = 'find';
  45079. var type = _typeof(arguments[0]);
  45080. if ('string' == type) {
  45081. this._path = arguments[0];
  45082. if (2 === arguments.length) {
  45083. this._conditions[this._path] = arguments[1];
  45084. }
  45085. return this;
  45086. }
  45087. if ('object' == type && !Array.isArray(arguments[0])) {
  45088. return this.merge(arguments[0]);
  45089. }
  45090. throw new TypeError('path must be a string or object');
  45091. };
  45092. /**
  45093. * Specifies the complementary comparison value for paths specified with `where()`
  45094. *
  45095. * ####Example
  45096. *
  45097. * User.where('age').equals(49);
  45098. *
  45099. * // is the same as
  45100. *
  45101. * User.where('age', 49);
  45102. *
  45103. * @param {Object} val
  45104. * @return {Query} this
  45105. * @api public
  45106. */
  45107. Query.prototype.equals = function equals(val) {
  45108. this._ensurePath('equals');
  45109. var path = this._path;
  45110. this._conditions[path] = val;
  45111. return this;
  45112. };
  45113. /**
  45114. * Specifies the complementary comparison value for paths specified with `where()`
  45115. * This is alias of `equals`
  45116. *
  45117. * ####Example
  45118. *
  45119. * User.where('age').eq(49);
  45120. *
  45121. * // is the same as
  45122. *
  45123. * User.shere('age').equals(49);
  45124. *
  45125. * // is the same as
  45126. *
  45127. * User.where('age', 49);
  45128. *
  45129. * @param {Object} val
  45130. * @return {Query} this
  45131. * @api public
  45132. */
  45133. Query.prototype.eq = function eq(val) {
  45134. this._ensurePath('eq');
  45135. var path = this._path;
  45136. this._conditions[path] = val;
  45137. return this;
  45138. };
  45139. /**
  45140. * Specifies arguments for an `$or` condition.
  45141. *
  45142. * ####Example
  45143. *
  45144. * query.or([{ color: 'red' }, { status: 'emergency' }])
  45145. *
  45146. * @param {Array} array array of conditions
  45147. * @return {Query} this
  45148. * @api public
  45149. */
  45150. Query.prototype.or = function or(array) {
  45151. var or = this._conditions.$or || (this._conditions.$or = []);
  45152. if (!Array.isArray(array)) array = [array];
  45153. or.push.apply(or, array);
  45154. return this;
  45155. };
  45156. /**
  45157. * Specifies arguments for a `$nor` condition.
  45158. *
  45159. * ####Example
  45160. *
  45161. * query.nor([{ color: 'green' }, { status: 'ok' }])
  45162. *
  45163. * @param {Array} array array of conditions
  45164. * @return {Query} this
  45165. * @api public
  45166. */
  45167. Query.prototype.nor = function nor(array) {
  45168. var nor = this._conditions.$nor || (this._conditions.$nor = []);
  45169. if (!Array.isArray(array)) array = [array];
  45170. nor.push.apply(nor, array);
  45171. return this;
  45172. };
  45173. /**
  45174. * Specifies arguments for a `$and` condition.
  45175. *
  45176. * ####Example
  45177. *
  45178. * query.and([{ color: 'green' }, { status: 'ok' }])
  45179. *
  45180. * @see $and http://docs.mongodb.org/manual/reference/operator/and/
  45181. * @param {Array} array array of conditions
  45182. * @return {Query} this
  45183. * @api public
  45184. */
  45185. Query.prototype.and = function and(array) {
  45186. var and = this._conditions.$and || (this._conditions.$and = []);
  45187. if (!Array.isArray(array)) array = [array];
  45188. and.push.apply(and, array);
  45189. return this;
  45190. };
  45191. /**
  45192. * Specifies a $gt query condition.
  45193. *
  45194. * When called with one argument, the most recent path passed to `where()` is used.
  45195. *
  45196. * ####Example
  45197. *
  45198. * Thing.find().where('age').gt(21)
  45199. *
  45200. * // or
  45201. * Thing.find().gt('age', 21)
  45202. *
  45203. * @method gt
  45204. * @memberOf Query
  45205. * @param {String} [path]
  45206. * @param {Number} val
  45207. * @api public
  45208. */
  45209. /**
  45210. * Specifies a $gte query condition.
  45211. *
  45212. * When called with one argument, the most recent path passed to `where()` is used.
  45213. *
  45214. * @method gte
  45215. * @memberOf Query
  45216. * @param {String} [path]
  45217. * @param {Number} val
  45218. * @api public
  45219. */
  45220. /**
  45221. * Specifies a $lt query condition.
  45222. *
  45223. * When called with one argument, the most recent path passed to `where()` is used.
  45224. *
  45225. * @method lt
  45226. * @memberOf Query
  45227. * @param {String} [path]
  45228. * @param {Number} val
  45229. * @api public
  45230. */
  45231. /**
  45232. * Specifies a $lte query condition.
  45233. *
  45234. * When called with one argument, the most recent path passed to `where()` is used.
  45235. *
  45236. * @method lte
  45237. * @memberOf Query
  45238. * @param {String} [path]
  45239. * @param {Number} val
  45240. * @api public
  45241. */
  45242. /**
  45243. * Specifies a $ne query condition.
  45244. *
  45245. * When called with one argument, the most recent path passed to `where()` is used.
  45246. *
  45247. * @method ne
  45248. * @memberOf Query
  45249. * @param {String} [path]
  45250. * @param {Number} val
  45251. * @api public
  45252. */
  45253. /**
  45254. * Specifies an $in query condition.
  45255. *
  45256. * When called with one argument, the most recent path passed to `where()` is used.
  45257. *
  45258. * @method in
  45259. * @memberOf Query
  45260. * @param {String} [path]
  45261. * @param {Number} val
  45262. * @api public
  45263. */
  45264. /**
  45265. * Specifies an $nin query condition.
  45266. *
  45267. * When called with one argument, the most recent path passed to `where()` is used.
  45268. *
  45269. * @method nin
  45270. * @memberOf Query
  45271. * @param {String} [path]
  45272. * @param {Number} val
  45273. * @api public
  45274. */
  45275. /**
  45276. * Specifies an $all query condition.
  45277. *
  45278. * When called with one argument, the most recent path passed to `where()` is used.
  45279. *
  45280. * @method all
  45281. * @memberOf Query
  45282. * @param {String} [path]
  45283. * @param {Number} val
  45284. * @api public
  45285. */
  45286. /**
  45287. * Specifies a $size query condition.
  45288. *
  45289. * When called with one argument, the most recent path passed to `where()` is used.
  45290. *
  45291. * @method size
  45292. * @memberOf Query
  45293. * @param {String} [path]
  45294. * @param {Number} val
  45295. * @api public
  45296. */
  45297. /**
  45298. * Specifies a $regex query condition.
  45299. *
  45300. * When called with one argument, the most recent path passed to `where()` is used.
  45301. *
  45302. * @method regex
  45303. * @memberOf Query
  45304. * @param {String} [path]
  45305. * @param {String|RegExp} val
  45306. * @api public
  45307. */
  45308. /**
  45309. * Specifies a $maxDistance query condition.
  45310. *
  45311. * When called with one argument, the most recent path passed to `where()` is used.
  45312. *
  45313. * @method maxDistance
  45314. * @memberOf Query
  45315. * @param {String} [path]
  45316. * @param {Number} val
  45317. * @api public
  45318. */
  45319. /*!
  45320. * gt, gte, lt, lte, ne, in, nin, all, regex, size, maxDistance
  45321. *
  45322. * Thing.where('type').nin(array)
  45323. */
  45324. 'gt gte lt lte ne in nin all regex size maxDistance minDistance'.split(' ').forEach(function ($conditional) {
  45325. Query.prototype[$conditional] = function () {
  45326. var path, val;
  45327. if (1 === arguments.length) {
  45328. this._ensurePath($conditional);
  45329. val = arguments[0];
  45330. path = this._path;
  45331. } else {
  45332. val = arguments[1];
  45333. path = arguments[0];
  45334. }
  45335. var conds = this._conditions[path] === null || _typeof(this._conditions[path]) === 'object' ? this._conditions[path] : this._conditions[path] = {};
  45336. conds['$' + $conditional] = val;
  45337. return this;
  45338. };
  45339. });
  45340. /**
  45341. * Specifies a `$mod` condition
  45342. *
  45343. * @param {String} [path]
  45344. * @param {Number} val
  45345. * @return {Query} this
  45346. * @api public
  45347. */
  45348. Query.prototype.mod = function () {
  45349. var val, path;
  45350. if (1 === arguments.length) {
  45351. this._ensurePath('mod');
  45352. val = arguments[0];
  45353. path = this._path;
  45354. } else if (2 === arguments.length && !Array.isArray(arguments[1])) {
  45355. this._ensurePath('mod');
  45356. val = [arguments[0], arguments[1]];
  45357. path = this._path;
  45358. } else if (3 === arguments.length) {
  45359. val = [arguments[1], arguments[2]];
  45360. path = arguments[0];
  45361. } else {
  45362. val = arguments[1];
  45363. path = arguments[0];
  45364. }
  45365. var conds = this._conditions[path] || (this._conditions[path] = {});
  45366. conds.$mod = val;
  45367. return this;
  45368. };
  45369. /**
  45370. * Specifies an `$exists` condition
  45371. *
  45372. * ####Example
  45373. *
  45374. * // { name: { $exists: true }}
  45375. * Thing.where('name').exists()
  45376. * Thing.where('name').exists(true)
  45377. * Thing.find().exists('name')
  45378. *
  45379. * // { name: { $exists: false }}
  45380. * Thing.where('name').exists(false);
  45381. * Thing.find().exists('name', false);
  45382. *
  45383. * @param {String} [path]
  45384. * @param {Number} val
  45385. * @return {Query} this
  45386. * @api public
  45387. */
  45388. Query.prototype.exists = function () {
  45389. var path, val;
  45390. if (0 === arguments.length) {
  45391. this._ensurePath('exists');
  45392. path = this._path;
  45393. val = true;
  45394. } else if (1 === arguments.length) {
  45395. if ('boolean' === typeof arguments[0]) {
  45396. this._ensurePath('exists');
  45397. path = this._path;
  45398. val = arguments[0];
  45399. } else {
  45400. path = arguments[0];
  45401. val = true;
  45402. }
  45403. } else if (2 === arguments.length) {
  45404. path = arguments[0];
  45405. val = arguments[1];
  45406. }
  45407. var conds = this._conditions[path] || (this._conditions[path] = {});
  45408. conds.$exists = val;
  45409. return this;
  45410. };
  45411. /**
  45412. * Specifies an `$elemMatch` condition
  45413. *
  45414. * ####Example
  45415. *
  45416. * query.elemMatch('comment', { author: 'autobot', votes: {$gte: 5}})
  45417. *
  45418. * query.where('comment').elemMatch({ author: 'autobot', votes: {$gte: 5}})
  45419. *
  45420. * query.elemMatch('comment', function (elem) {
  45421. * elem.where('author').equals('autobot');
  45422. * elem.where('votes').gte(5);
  45423. * })
  45424. *
  45425. * query.where('comment').elemMatch(function (elem) {
  45426. * elem.where({ author: 'autobot' });
  45427. * elem.where('votes').gte(5);
  45428. * })
  45429. *
  45430. * @param {String|Object|Function} path
  45431. * @param {Object|Function} criteria
  45432. * @return {Query} this
  45433. * @api public
  45434. */
  45435. Query.prototype.elemMatch = function () {
  45436. if (null == arguments[0]) throw new TypeError('Invalid argument');
  45437. var fn, path, criteria;
  45438. if ('function' === typeof arguments[0]) {
  45439. this._ensurePath('elemMatch');
  45440. path = this._path;
  45441. fn = arguments[0];
  45442. } else if (utils.isObject(arguments[0])) {
  45443. this._ensurePath('elemMatch');
  45444. path = this._path;
  45445. criteria = arguments[0];
  45446. } else if ('function' === typeof arguments[1]) {
  45447. path = arguments[0];
  45448. fn = arguments[1];
  45449. } else if (arguments[1] && utils.isObject(arguments[1])) {
  45450. path = arguments[0];
  45451. criteria = arguments[1];
  45452. } else {
  45453. throw new TypeError('Invalid argument');
  45454. }
  45455. if (fn) {
  45456. criteria = new Query();
  45457. fn(criteria);
  45458. criteria = criteria._conditions;
  45459. }
  45460. var conds = this._conditions[path] || (this._conditions[path] = {});
  45461. conds.$elemMatch = criteria;
  45462. return this;
  45463. }; // Spatial queries
  45464. /**
  45465. * Sugar for geo-spatial queries.
  45466. *
  45467. * ####Example
  45468. *
  45469. * query.within().box()
  45470. * query.within().circle()
  45471. * query.within().geometry()
  45472. *
  45473. * query.where('loc').within({ center: [50,50], radius: 10, unique: true, spherical: true });
  45474. * query.where('loc').within({ box: [[40.73, -73.9], [40.7, -73.988]] });
  45475. * query.where('loc').within({ polygon: [[],[],[],[]] });
  45476. *
  45477. * query.where('loc').within([], [], []) // polygon
  45478. * query.where('loc').within([], []) // box
  45479. * query.where('loc').within({ type: 'LineString', coordinates: [...] }); // geometry
  45480. *
  45481. * ####NOTE:
  45482. *
  45483. * Must be used after `where()`.
  45484. *
  45485. * @memberOf Query
  45486. * @return {Query} this
  45487. * @api public
  45488. */
  45489. Query.prototype.within = function within() {
  45490. // opinionated, must be used after where
  45491. this._ensurePath('within');
  45492. this._geoComparison = $withinCmd;
  45493. if (0 === arguments.length) {
  45494. return this;
  45495. }
  45496. if (2 === arguments.length) {
  45497. return this.box.apply(this, arguments);
  45498. } else if (2 < arguments.length) {
  45499. return this.polygon.apply(this, arguments);
  45500. }
  45501. var area = arguments[0];
  45502. if (!area) throw new TypeError('Invalid argument');
  45503. if (area.center) return this.circle(area);
  45504. if (area.box) return this.box.apply(this, area.box);
  45505. if (area.polygon) return this.polygon.apply(this, area.polygon);
  45506. if (area.type && area.coordinates) return this.geometry(area);
  45507. throw new TypeError('Invalid argument');
  45508. };
  45509. /**
  45510. * Specifies a $box condition
  45511. *
  45512. * ####Example
  45513. *
  45514. * var lowerLeft = [40.73083, -73.99756]
  45515. * var upperRight= [40.741404, -73.988135]
  45516. *
  45517. * query.where('loc').within().box(lowerLeft, upperRight)
  45518. * query.box('loc', lowerLeft, upperRight )
  45519. *
  45520. * @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  45521. * @see Query#within #query_Query-within
  45522. * @param {String} path
  45523. * @param {Object} val
  45524. * @return {Query} this
  45525. * @api public
  45526. */
  45527. Query.prototype.box = function () {
  45528. var path, box;
  45529. if (3 === arguments.length) {
  45530. // box('loc', [], [])
  45531. path = arguments[0];
  45532. box = [arguments[1], arguments[2]];
  45533. } else if (2 === arguments.length) {
  45534. // box([], [])
  45535. this._ensurePath('box');
  45536. path = this._path;
  45537. box = [arguments[0], arguments[1]];
  45538. } else {
  45539. throw new TypeError('Invalid argument');
  45540. }
  45541. var conds = this._conditions[path] || (this._conditions[path] = {});
  45542. conds[this._geoComparison || $withinCmd] = {
  45543. $box: box
  45544. };
  45545. return this;
  45546. };
  45547. /**
  45548. * Specifies a $polygon condition
  45549. *
  45550. * ####Example
  45551. *
  45552. * query.where('loc').within().polygon([10,20], [13, 25], [7,15])
  45553. * query.polygon('loc', [10,20], [13, 25], [7,15])
  45554. *
  45555. * @param {String|Array} [path]
  45556. * @param {Array|Object} [val]
  45557. * @return {Query} this
  45558. * @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  45559. * @api public
  45560. */
  45561. Query.prototype.polygon = function () {
  45562. var val, path;
  45563. if ('string' == typeof arguments[0]) {
  45564. // polygon('loc', [],[],[])
  45565. val = Array.from(arguments);
  45566. path = val.shift();
  45567. } else {
  45568. // polygon([],[],[])
  45569. this._ensurePath('polygon');
  45570. path = this._path;
  45571. val = Array.from(arguments);
  45572. }
  45573. var conds = this._conditions[path] || (this._conditions[path] = {});
  45574. conds[this._geoComparison || $withinCmd] = {
  45575. $polygon: val
  45576. };
  45577. return this;
  45578. };
  45579. /**
  45580. * Specifies a $center or $centerSphere condition.
  45581. *
  45582. * ####Example
  45583. *
  45584. * var area = { center: [50, 50], radius: 10, unique: true }
  45585. * query.where('loc').within().circle(area)
  45586. * query.center('loc', area);
  45587. *
  45588. * // for spherical calculations
  45589. * var area = { center: [50, 50], radius: 10, unique: true, spherical: true }
  45590. * query.where('loc').within().circle(area)
  45591. * query.center('loc', area);
  45592. *
  45593. * @param {String} [path]
  45594. * @param {Object} area
  45595. * @return {Query} this
  45596. * @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  45597. * @api public
  45598. */
  45599. Query.prototype.circle = function () {
  45600. var path, val;
  45601. if (1 === arguments.length) {
  45602. this._ensurePath('circle');
  45603. path = this._path;
  45604. val = arguments[0];
  45605. } else if (2 === arguments.length) {
  45606. path = arguments[0];
  45607. val = arguments[1];
  45608. } else {
  45609. throw new TypeError('Invalid argument');
  45610. }
  45611. if (!('radius' in val && val.center)) throw new Error('center and radius are required');
  45612. var conds = this._conditions[path] || (this._conditions[path] = {});
  45613. var type = val.spherical ? '$centerSphere' : '$center';
  45614. var wKey = this._geoComparison || $withinCmd;
  45615. conds[wKey] = {};
  45616. conds[wKey][type] = [val.center, val.radius];
  45617. if ('unique' in val) conds[wKey].$uniqueDocs = !!val.unique;
  45618. return this;
  45619. };
  45620. /**
  45621. * Specifies a `$near` or `$nearSphere` condition
  45622. *
  45623. * These operators return documents sorted by distance.
  45624. *
  45625. * ####Example
  45626. *
  45627. * query.where('loc').near({ center: [10, 10] });
  45628. * query.where('loc').near({ center: [10, 10], maxDistance: 5 });
  45629. * query.where('loc').near({ center: [10, 10], maxDistance: 5, spherical: true });
  45630. * query.near('loc', { center: [10, 10], maxDistance: 5 });
  45631. * query.near({ center: { type: 'Point', coordinates: [..] }})
  45632. * query.near().geometry({ type: 'Point', coordinates: [..] })
  45633. *
  45634. * @param {String} [path]
  45635. * @param {Object} val
  45636. * @return {Query} this
  45637. * @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  45638. * @api public
  45639. */
  45640. Query.prototype.near = function near() {
  45641. var path, val;
  45642. this._geoComparison = '$near';
  45643. if (0 === arguments.length) {
  45644. return this;
  45645. } else if (1 === arguments.length) {
  45646. this._ensurePath('near');
  45647. path = this._path;
  45648. val = arguments[0];
  45649. } else if (2 === arguments.length) {
  45650. path = arguments[0];
  45651. val = arguments[1];
  45652. } else {
  45653. throw new TypeError('Invalid argument');
  45654. }
  45655. if (!val.center) {
  45656. throw new Error('center is required');
  45657. }
  45658. var conds = this._conditions[path] || (this._conditions[path] = {});
  45659. var type = val.spherical ? '$nearSphere' : '$near'; // center could be a GeoJSON object or an Array
  45660. if (Array.isArray(val.center)) {
  45661. conds[type] = val.center;
  45662. var radius = 'maxDistance' in val ? val.maxDistance : null;
  45663. if (null != radius) {
  45664. conds.$maxDistance = radius;
  45665. }
  45666. if (null != val.minDistance) {
  45667. conds.$minDistance = val.minDistance;
  45668. }
  45669. } else {
  45670. // GeoJSON?
  45671. if (val.center.type != 'Point' || !Array.isArray(val.center.coordinates)) {
  45672. throw new Error(util.format('Invalid GeoJSON specified for %s', type));
  45673. }
  45674. conds[type] = {
  45675. $geometry: val.center
  45676. }; // MongoDB 2.6 insists on maxDistance being in $near / $nearSphere
  45677. if ('maxDistance' in val) {
  45678. conds[type]['$maxDistance'] = val.maxDistance;
  45679. }
  45680. if ('minDistance' in val) {
  45681. conds[type]['$minDistance'] = val.minDistance;
  45682. }
  45683. }
  45684. return this;
  45685. };
  45686. /**
  45687. * Declares an intersects query for `geometry()`.
  45688. *
  45689. * ####Example
  45690. *
  45691. * query.where('path').intersects().geometry({
  45692. * type: 'LineString'
  45693. * , coordinates: [[180.0, 11.0], [180, 9.0]]
  45694. * })
  45695. *
  45696. * query.where('path').intersects({
  45697. * type: 'LineString'
  45698. * , coordinates: [[180.0, 11.0], [180, 9.0]]
  45699. * })
  45700. *
  45701. * @param {Object} [arg]
  45702. * @return {Query} this
  45703. * @api public
  45704. */
  45705. Query.prototype.intersects = function intersects() {
  45706. // opinionated, must be used after where
  45707. this._ensurePath('intersects');
  45708. this._geoComparison = '$geoIntersects';
  45709. if (0 === arguments.length) {
  45710. return this;
  45711. }
  45712. var area = arguments[0];
  45713. if (null != area && area.type && area.coordinates) return this.geometry(area);
  45714. throw new TypeError('Invalid argument');
  45715. };
  45716. /**
  45717. * Specifies a `$geometry` condition
  45718. *
  45719. * ####Example
  45720. *
  45721. * var polyA = [[[ 10, 20 ], [ 10, 40 ], [ 30, 40 ], [ 30, 20 ]]]
  45722. * query.where('loc').within().geometry({ type: 'Polygon', coordinates: polyA })
  45723. *
  45724. * // or
  45725. * var polyB = [[ 0, 0 ], [ 1, 1 ]]
  45726. * query.where('loc').within().geometry({ type: 'LineString', coordinates: polyB })
  45727. *
  45728. * // or
  45729. * var polyC = [ 0, 0 ]
  45730. * query.where('loc').within().geometry({ type: 'Point', coordinates: polyC })
  45731. *
  45732. * // or
  45733. * query.where('loc').intersects().geometry({ type: 'Point', coordinates: polyC })
  45734. *
  45735. * ####NOTE:
  45736. *
  45737. * `geometry()` **must** come after either `intersects()` or `within()`.
  45738. *
  45739. * The `object` argument must contain `type` and `coordinates` properties.
  45740. * - type {String}
  45741. * - coordinates {Array}
  45742. *
  45743. * The most recent path passed to `where()` is used.
  45744. *
  45745. * @param {Object} object Must contain a `type` property which is a String and a `coordinates` property which is an Array. See the examples.
  45746. * @return {Query} this
  45747. * @see http://docs.mongodb.org/manual/release-notes/2.4/#new-geospatial-indexes-with-geojson-and-improved-spherical-geometry
  45748. * @see http://www.mongodb.org/display/DOCS/Geospatial+Indexing
  45749. * @see $geometry http://docs.mongodb.org/manual/reference/operator/geometry/
  45750. * @api public
  45751. */
  45752. Query.prototype.geometry = function geometry() {
  45753. if (!('$within' == this._geoComparison || '$geoWithin' == this._geoComparison || '$near' == this._geoComparison || '$geoIntersects' == this._geoComparison)) {
  45754. throw new Error('geometry() must come after `within()`, `intersects()`, or `near()');
  45755. }
  45756. var val, path;
  45757. if (1 === arguments.length) {
  45758. this._ensurePath('geometry');
  45759. path = this._path;
  45760. val = arguments[0];
  45761. } else {
  45762. throw new TypeError('Invalid argument');
  45763. }
  45764. if (!(val.type && Array.isArray(val.coordinates))) {
  45765. throw new TypeError('Invalid argument');
  45766. }
  45767. var conds = this._conditions[path] || (this._conditions[path] = {});
  45768. conds[this._geoComparison] = {
  45769. $geometry: val
  45770. };
  45771. return this;
  45772. }; // end spatial
  45773. /**
  45774. * Specifies which document fields to include or exclude
  45775. *
  45776. * ####String syntax
  45777. *
  45778. * When passing a string, prefixing a path with `-` will flag that path as excluded. When a path does not have the `-` prefix, it is included.
  45779. *
  45780. * ####Example
  45781. *
  45782. * // include a and b, exclude c
  45783. * query.select('a b -c');
  45784. *
  45785. * // or you may use object notation, useful when
  45786. * // you have keys already prefixed with a "-"
  45787. * query.select({a: 1, b: 1, c: 0});
  45788. *
  45789. * ####Note
  45790. *
  45791. * Cannot be used with `distinct()`
  45792. *
  45793. * @param {Object|String} arg
  45794. * @return {Query} this
  45795. * @see SchemaType
  45796. * @api public
  45797. */
  45798. Query.prototype.select = function select() {
  45799. var arg = arguments[0];
  45800. if (!arg) return this;
  45801. if (arguments.length !== 1) {
  45802. throw new Error('Invalid select: select only takes 1 argument');
  45803. }
  45804. this._validate('select');
  45805. var fields = this._fields || (this._fields = {});
  45806. var type = _typeof(arg);
  45807. var i, len;
  45808. if (('string' == type || utils.isArgumentsObject(arg)) && 'number' == typeof arg.length || Array.isArray(arg)) {
  45809. if ('string' == type) arg = arg.split(/\s+/);
  45810. for (i = 0, len = arg.length; i < len; ++i) {
  45811. var field = arg[i];
  45812. if (!field) continue;
  45813. var include = '-' == field[0] ? 0 : 1;
  45814. if (include === 0) field = field.substring(1);
  45815. fields[field] = include;
  45816. }
  45817. return this;
  45818. }
  45819. if (utils.isObject(arg)) {
  45820. var keys = utils.keys(arg);
  45821. for (i = 0; i < keys.length; ++i) {
  45822. fields[keys[i]] = arg[keys[i]];
  45823. }
  45824. return this;
  45825. }
  45826. throw new TypeError('Invalid select() argument. Must be string or object.');
  45827. };
  45828. /**
  45829. * Specifies a $slice condition for a `path`
  45830. *
  45831. * ####Example
  45832. *
  45833. * query.slice('comments', 5)
  45834. * query.slice('comments', -5)
  45835. * query.slice('comments', [10, 5])
  45836. * query.where('comments').slice(5)
  45837. * query.where('comments').slice([-10, 5])
  45838. *
  45839. * @param {String} [path]
  45840. * @param {Number} val number/range of elements to slice
  45841. * @return {Query} this
  45842. * @see mongodb http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields#RetrievingaSubsetofFields-RetrievingaSubrangeofArrayElements
  45843. * @api public
  45844. */
  45845. Query.prototype.slice = function () {
  45846. if (0 === arguments.length) return this;
  45847. this._validate('slice');
  45848. var path, val;
  45849. if (1 === arguments.length) {
  45850. var arg = arguments[0];
  45851. if (_typeof(arg) === 'object' && !Array.isArray(arg)) {
  45852. var keys = Object.keys(arg);
  45853. var numKeys = keys.length;
  45854. for (var i = 0; i < numKeys; ++i) {
  45855. this.slice(keys[i], arg[keys[i]]);
  45856. }
  45857. return this;
  45858. }
  45859. this._ensurePath('slice');
  45860. path = this._path;
  45861. val = arguments[0];
  45862. } else if (2 === arguments.length) {
  45863. if ('number' === typeof arguments[0]) {
  45864. this._ensurePath('slice');
  45865. path = this._path;
  45866. val = [arguments[0], arguments[1]];
  45867. } else {
  45868. path = arguments[0];
  45869. val = arguments[1];
  45870. }
  45871. } else if (3 === arguments.length) {
  45872. path = arguments[0];
  45873. val = [arguments[1], arguments[2]];
  45874. }
  45875. var myFields = this._fields || (this._fields = {});
  45876. myFields[path] = {
  45877. $slice: val
  45878. };
  45879. return this;
  45880. };
  45881. /**
  45882. * Sets the sort order
  45883. *
  45884. * If an object is passed, values allowed are 'asc', 'desc', 'ascending', 'descending', 1, and -1.
  45885. *
  45886. * If a string is passed, it must be a space delimited list of path names. The sort order of each path is ascending unless the path name is prefixed with `-` which will be treated as descending.
  45887. *
  45888. * ####Example
  45889. *
  45890. * // these are equivalent
  45891. * query.sort({ field: 'asc', test: -1 });
  45892. * query.sort('field -test');
  45893. * query.sort([['field', 1], ['test', -1]]);
  45894. *
  45895. * ####Note
  45896. *
  45897. * - The array syntax `.sort([['field', 1], ['test', -1]])` can only be used with [mongodb driver >= 2.0.46](https://github.com/mongodb/node-mongodb-native/blob/2.1/HISTORY.md#2046-2015-10-15).
  45898. * - Cannot be used with `distinct()`
  45899. *
  45900. * @param {Object|String|Array} arg
  45901. * @return {Query} this
  45902. * @api public
  45903. */
  45904. Query.prototype.sort = function (arg) {
  45905. if (!arg) return this;
  45906. var i, len, field;
  45907. this._validate('sort');
  45908. var type = _typeof(arg); // .sort([['field', 1], ['test', -1]])
  45909. if (Array.isArray(arg)) {
  45910. len = arg.length;
  45911. for (i = 0; i < arg.length; ++i) {
  45912. if (!Array.isArray(arg[i])) {
  45913. throw new Error('Invalid sort() argument, must be array of arrays');
  45914. }
  45915. _pushArr(this.options, arg[i][0], arg[i][1]);
  45916. }
  45917. return this;
  45918. } // .sort('field -test')
  45919. if (1 === arguments.length && 'string' == type) {
  45920. arg = arg.split(/\s+/);
  45921. len = arg.length;
  45922. for (i = 0; i < len; ++i) {
  45923. field = arg[i];
  45924. if (!field) continue;
  45925. var ascend = '-' == field[0] ? -1 : 1;
  45926. if (ascend === -1) field = field.substring(1);
  45927. push(this.options, field, ascend);
  45928. }
  45929. return this;
  45930. } // .sort({ field: 1, test: -1 })
  45931. if (utils.isObject(arg)) {
  45932. var keys = utils.keys(arg);
  45933. for (i = 0; i < keys.length; ++i) {
  45934. field = keys[i];
  45935. push(this.options, field, arg[field]);
  45936. }
  45937. return this;
  45938. }
  45939. if (typeof Map !== 'undefined' && arg instanceof Map) {
  45940. _pushMap(this.options, arg);
  45941. return this;
  45942. }
  45943. throw new TypeError('Invalid sort() argument. Must be a string, object, or array.');
  45944. };
  45945. /*!
  45946. * @ignore
  45947. */
  45948. var _validSortValue = {
  45949. 1: 1,
  45950. '-1': -1,
  45951. asc: 1,
  45952. ascending: 1,
  45953. desc: -1,
  45954. descending: -1
  45955. };
  45956. function push(opts, field, value) {
  45957. if (Array.isArray(opts.sort)) {
  45958. throw new TypeError('Can\'t mix sort syntaxes. Use either array or object:' + '\n- `.sort([[\'field\', 1], [\'test\', -1]])`' + '\n- `.sort({ field: 1, test: -1 })`');
  45959. }
  45960. var s;
  45961. if (value && value.$meta) {
  45962. s = opts.sort || (opts.sort = {});
  45963. s[field] = {
  45964. $meta: value.$meta
  45965. };
  45966. return;
  45967. }
  45968. s = opts.sort || (opts.sort = {});
  45969. var val = String(value || 1).toLowerCase();
  45970. val = _validSortValue[val];
  45971. if (!val) throw new TypeError('Invalid sort value: { ' + field + ': ' + value + ' }');
  45972. s[field] = val;
  45973. }
  45974. function _pushArr(opts, field, value) {
  45975. opts.sort = opts.sort || [];
  45976. if (!Array.isArray(opts.sort)) {
  45977. throw new TypeError('Can\'t mix sort syntaxes. Use either array or object:' + '\n- `.sort([[\'field\', 1], [\'test\', -1]])`' + '\n- `.sort({ field: 1, test: -1 })`');
  45978. }
  45979. var val = String(value || 1).toLowerCase();
  45980. val = _validSortValue[val];
  45981. if (!val) throw new TypeError('Invalid sort value: [ ' + field + ', ' + value + ' ]');
  45982. opts.sort.push([field, val]);
  45983. }
  45984. function _pushMap(opts, map) {
  45985. opts.sort = opts.sort || new Map();
  45986. if (!(opts.sort instanceof Map)) {
  45987. throw new TypeError('Can\'t mix sort syntaxes. Use either array or ' + 'object or map consistently');
  45988. }
  45989. map.forEach(function (value, key) {
  45990. var val = String(value || 1).toLowerCase();
  45991. val = _validSortValue[val];
  45992. if (!val) throw new TypeError('Invalid sort value: < ' + key + ': ' + value + ' >');
  45993. opts.sort.set(key, val);
  45994. });
  45995. }
  45996. /**
  45997. * Specifies the limit option.
  45998. *
  45999. * ####Example
  46000. *
  46001. * query.limit(20)
  46002. *
  46003. * ####Note
  46004. *
  46005. * Cannot be used with `distinct()`
  46006. *
  46007. * @method limit
  46008. * @memberOf Query
  46009. * @param {Number} val
  46010. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Blimit%28%29%7D%7D
  46011. * @api public
  46012. */
  46013. /**
  46014. * Specifies the skip option.
  46015. *
  46016. * ####Example
  46017. *
  46018. * query.skip(100).limit(20)
  46019. *
  46020. * ####Note
  46021. *
  46022. * Cannot be used with `distinct()`
  46023. *
  46024. * @method skip
  46025. * @memberOf Query
  46026. * @param {Number} val
  46027. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Bskip%28%29%7D%7D
  46028. * @api public
  46029. */
  46030. /**
  46031. * Specifies the maxScan option.
  46032. *
  46033. * ####Example
  46034. *
  46035. * query.maxScan(100)
  46036. *
  46037. * ####Note
  46038. *
  46039. * Cannot be used with `distinct()`
  46040. *
  46041. * @method maxScan
  46042. * @memberOf Query
  46043. * @param {Number} val
  46044. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24maxScan
  46045. * @api public
  46046. */
  46047. /**
  46048. * Specifies the batchSize option.
  46049. *
  46050. * ####Example
  46051. *
  46052. * query.batchSize(100)
  46053. *
  46054. * ####Note
  46055. *
  46056. * Cannot be used with `distinct()`
  46057. *
  46058. * @method batchSize
  46059. * @memberOf Query
  46060. * @param {Number} val
  46061. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7BbatchSize%28%29%7D%7D
  46062. * @api public
  46063. */
  46064. /**
  46065. * Specifies the `comment` option.
  46066. *
  46067. * ####Example
  46068. *
  46069. * query.comment('login query')
  46070. *
  46071. * ####Note
  46072. *
  46073. * Cannot be used with `distinct()`
  46074. *
  46075. * @method comment
  46076. * @memberOf Query
  46077. * @param {Number} val
  46078. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24comment
  46079. * @api public
  46080. */
  46081. /*!
  46082. * limit, skip, maxScan, batchSize, comment
  46083. *
  46084. * Sets these associated options.
  46085. *
  46086. * query.comment('feed query');
  46087. */
  46088. ['limit', 'skip', 'maxScan', 'batchSize', 'comment'].forEach(function (method) {
  46089. Query.prototype[method] = function (v) {
  46090. this._validate(method);
  46091. this.options[method] = v;
  46092. return this;
  46093. };
  46094. });
  46095. /**
  46096. * Specifies the maxTimeMS option.
  46097. *
  46098. * ####Example
  46099. *
  46100. * query.maxTime(100)
  46101. * query.maxTimeMS(100)
  46102. *
  46103. * @method maxTime
  46104. * @memberOf Query
  46105. * @param {Number} ms
  46106. * @see mongodb http://docs.mongodb.org/manual/reference/operator/meta/maxTimeMS/#op._S_maxTimeMS
  46107. * @api public
  46108. */
  46109. Query.prototype.maxTime = Query.prototype.maxTimeMS = function (ms) {
  46110. this._validate('maxTime');
  46111. this.options.maxTimeMS = ms;
  46112. return this;
  46113. };
  46114. /**
  46115. * Specifies this query as a `snapshot` query.
  46116. *
  46117. * ####Example
  46118. *
  46119. * mquery().snapshot() // true
  46120. * mquery().snapshot(true)
  46121. * mquery().snapshot(false)
  46122. *
  46123. * ####Note
  46124. *
  46125. * Cannot be used with `distinct()`
  46126. *
  46127. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Bsnapshot%28%29%7D%7D
  46128. * @return {Query} this
  46129. * @api public
  46130. */
  46131. Query.prototype.snapshot = function () {
  46132. this._validate('snapshot');
  46133. this.options.snapshot = arguments.length ? !!arguments[0] : true;
  46134. return this;
  46135. };
  46136. /**
  46137. * Sets query hints.
  46138. *
  46139. * ####Example
  46140. *
  46141. * query.hint({ indexA: 1, indexB: -1});
  46142. * query.hint('indexA_1_indexB_1');
  46143. *
  46144. * ####Note
  46145. *
  46146. * Cannot be used with `distinct()`
  46147. *
  46148. * @param {Object|string} val a hint object or the index name
  46149. * @return {Query} this
  46150. * @see mongodb http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24hint
  46151. * @api public
  46152. */
  46153. Query.prototype.hint = function () {
  46154. if (0 === arguments.length) return this;
  46155. this._validate('hint');
  46156. var arg = arguments[0];
  46157. if (utils.isObject(arg)) {
  46158. var hint = this.options.hint || (this.options.hint = {}); // must keep object keys in order so don't use Object.keys()
  46159. for (var k in arg) {
  46160. hint[k] = arg[k];
  46161. }
  46162. return this;
  46163. }
  46164. if (typeof arg === 'string') {
  46165. this.options.hint = arg;
  46166. return this;
  46167. }
  46168. throw new TypeError('Invalid hint. ' + arg);
  46169. };
  46170. /**
  46171. * Requests acknowledgement that this operation has been persisted to MongoDB's
  46172. * on-disk journal.
  46173. * This option is only valid for operations that write to the database:
  46174. *
  46175. * - `deleteOne()`
  46176. * - `deleteMany()`
  46177. * - `findOneAndDelete()`
  46178. * - `findOneAndUpdate()`
  46179. * - `remove()`
  46180. * - `update()`
  46181. * - `updateOne()`
  46182. * - `updateMany()`
  46183. *
  46184. * Defaults to the `j` value if it is specified in writeConcern options
  46185. *
  46186. * ####Example:
  46187. *
  46188. * mquery().w(2).j(true).wtimeout(2000);
  46189. *
  46190. * @method j
  46191. * @memberOf Query
  46192. * @instance
  46193. * @param {boolean} val
  46194. * @see mongodb https://docs.mongodb.com/manual/reference/write-concern/#j-option
  46195. * @return {Query} this
  46196. * @api public
  46197. */
  46198. Query.prototype.j = function j(val) {
  46199. this.options.j = val;
  46200. return this;
  46201. };
  46202. /**
  46203. * Sets the slaveOk option. _Deprecated_ in MongoDB 2.2 in favor of read preferences.
  46204. *
  46205. * ####Example:
  46206. *
  46207. * query.slaveOk() // true
  46208. * query.slaveOk(true)
  46209. * query.slaveOk(false)
  46210. *
  46211. * @deprecated use read() preferences instead if on mongodb >= 2.2
  46212. * @param {Boolean} v defaults to true
  46213. * @see mongodb http://docs.mongodb.org/manual/applications/replication/#read-preference
  46214. * @see read()
  46215. * @return {Query} this
  46216. * @api public
  46217. */
  46218. Query.prototype.slaveOk = function (v) {
  46219. this.options.slaveOk = arguments.length ? !!v : true;
  46220. return this;
  46221. };
  46222. /**
  46223. * Sets the readPreference option for the query.
  46224. *
  46225. * ####Example:
  46226. *
  46227. * new Query().read('primary')
  46228. * new Query().read('p') // same as primary
  46229. *
  46230. * new Query().read('primaryPreferred')
  46231. * new Query().read('pp') // same as primaryPreferred
  46232. *
  46233. * new Query().read('secondary')
  46234. * new Query().read('s') // same as secondary
  46235. *
  46236. * new Query().read('secondaryPreferred')
  46237. * new Query().read('sp') // same as secondaryPreferred
  46238. *
  46239. * new Query().read('nearest')
  46240. * new Query().read('n') // same as nearest
  46241. *
  46242. * // you can also use mongodb.ReadPreference class to also specify tags
  46243. * new Query().read(mongodb.ReadPreference('secondary', [{ dc:'sf', s: 1 },{ dc:'ma', s: 2 }]))
  46244. *
  46245. * new Query().setReadPreference('primary') // alias of .read()
  46246. *
  46247. * ####Preferences:
  46248. *
  46249. * primary - (default) Read from primary only. Operations will produce an error if primary is unavailable. Cannot be combined with tags.
  46250. * secondary Read from secondary if available, otherwise error.
  46251. * primaryPreferred Read from primary if available, otherwise a secondary.
  46252. * secondaryPreferred Read from a secondary if available, otherwise read from the primary.
  46253. * nearest All operations read from among the nearest candidates, but unlike other modes, this option will include both the primary and all secondaries in the random selection.
  46254. *
  46255. * Aliases
  46256. *
  46257. * p primary
  46258. * pp primaryPreferred
  46259. * s secondary
  46260. * sp secondaryPreferred
  46261. * n nearest
  46262. *
  46263. * Read more about how to use read preferences [here](http://docs.mongodb.org/manual/applications/replication/#read-preference) and [here](http://mongodb.github.com/node-mongodb-native/driver-articles/anintroductionto1_1and2_2.html#read-preferences).
  46264. *
  46265. * @param {String|ReadPreference} pref one of the listed preference options or their aliases
  46266. * @see mongodb http://docs.mongodb.org/manual/applications/replication/#read-preference
  46267. * @see driver http://mongodb.github.com/node-mongodb-native/driver-articles/anintroductionto1_1and2_2.html#read-preferences
  46268. * @return {Query} this
  46269. * @api public
  46270. */
  46271. Query.prototype.read = Query.prototype.setReadPreference = function (pref) {
  46272. if (arguments.length > 1 && !Query.prototype.read.deprecationWarningIssued) {
  46273. console.error('Deprecation warning: \'tags\' argument is not supported anymore in Query.read() method. Please use mongodb.ReadPreference object instead.');
  46274. Query.prototype.read.deprecationWarningIssued = true;
  46275. }
  46276. this.options.readPreference = utils.readPref(pref);
  46277. return this;
  46278. };
  46279. /**
  46280. * Sets the readConcern option for the query.
  46281. *
  46282. * ####Example:
  46283. *
  46284. * new Query().readConcern('local')
  46285. * new Query().readConcern('l') // same as local
  46286. *
  46287. * new Query().readConcern('available')
  46288. * new Query().readConcern('a') // same as available
  46289. *
  46290. * new Query().readConcern('majority')
  46291. * new Query().readConcern('m') // same as majority
  46292. *
  46293. * new Query().readConcern('linearizable')
  46294. * new Query().readConcern('lz') // same as linearizable
  46295. *
  46296. * new Query().readConcern('snapshot')
  46297. * new Query().readConcern('s') // same as snapshot
  46298. *
  46299. * new Query().r('s') // r is alias of readConcern
  46300. *
  46301. *
  46302. * ####Read Concern Level:
  46303. *
  46304. * local MongoDB 3.2+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
  46305. * available MongoDB 3.6+ The query returns from the instance with no guarantee guarantee that the data has been written to a majority of the replica set members (i.e. may be rolled back).
  46306. * majority MongoDB 3.2+ The query returns the data that has been acknowledged by a majority of the replica set members. The documents returned by the read operation are durable, even in the event of failure.
  46307. * linearizable MongoDB 3.4+ The query returns data that reflects all successful majority-acknowledged writes that completed prior to the start of the read operation. The query may wait for concurrently executing writes to propagate to a majority of replica set members before returning results.
  46308. * snapshot MongoDB 4.0+ Only available for operations within multi-document transactions. Upon transaction commit with write concern "majority", the transaction operations are guaranteed to have read from a snapshot of majority-committed data.
  46309. *
  46310. *
  46311. * Aliases
  46312. *
  46313. * l local
  46314. * a available
  46315. * m majority
  46316. * lz linearizable
  46317. * s snapshot
  46318. *
  46319. * Read more about how to use read concern [here](https://docs.mongodb.com/manual/reference/read-concern/).
  46320. *
  46321. * @param {String} level one of the listed read concern level or their aliases
  46322. * @see mongodb https://docs.mongodb.com/manual/reference/read-concern/
  46323. * @return {Query} this
  46324. * @api public
  46325. */
  46326. Query.prototype.readConcern = Query.prototype.r = function (level) {
  46327. this.options.readConcern = utils.readConcern(level);
  46328. return this;
  46329. };
  46330. /**
  46331. * Sets tailable option.
  46332. *
  46333. * ####Example
  46334. *
  46335. * query.tailable() <== true
  46336. * query.tailable(true)
  46337. * query.tailable(false)
  46338. *
  46339. * ####Note
  46340. *
  46341. * Cannot be used with `distinct()`
  46342. *
  46343. * @param {Boolean} v defaults to true
  46344. * @see mongodb http://www.mongodb.org/display/DOCS/Tailable+Cursors
  46345. * @api public
  46346. */
  46347. Query.prototype.tailable = function () {
  46348. this._validate('tailable');
  46349. this.options.tailable = arguments.length ? !!arguments[0] : true;
  46350. return this;
  46351. };
  46352. /**
  46353. * Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
  46354. * that must acknowledge this write before this write is considered successful.
  46355. * This option is only valid for operations that write to the database:
  46356. *
  46357. * - `deleteOne()`
  46358. * - `deleteMany()`
  46359. * - `findOneAndDelete()`
  46360. * - `findOneAndUpdate()`
  46361. * - `remove()`
  46362. * - `update()`
  46363. * - `updateOne()`
  46364. * - `updateMany()`
  46365. *
  46366. * Defaults to the `w` value if it is specified in writeConcern options
  46367. *
  46368. * ####Example:
  46369. *
  46370. * mquery().writeConcern(0)
  46371. * mquery().writeConcern(1)
  46372. * mquery().writeConcern({ w: 1, j: true, wtimeout: 2000 })
  46373. * mquery().writeConcern('majority')
  46374. * mquery().writeConcern('m') // same as majority
  46375. * mquery().writeConcern('tagSetName') // if the tag set is 'm', use .writeConcern({ w: 'm' }) instead
  46376. * mquery().w(1) // w is alias of writeConcern
  46377. *
  46378. * @method writeConcern
  46379. * @memberOf Query
  46380. * @instance
  46381. * @param {String|number|object} concern 0 for fire-and-forget, 1 for acknowledged by one server, 'majority' for majority of the replica set, or [any of the more advanced options](https://docs.mongodb.com/manual/reference/write-concern/#w-option).
  46382. * @see mongodb https://docs.mongodb.com/manual/reference/write-concern/#w-option
  46383. * @return {Query} this
  46384. * @api public
  46385. */
  46386. Query.prototype.writeConcern = Query.prototype.w = function writeConcern(concern) {
  46387. if ('object' === _typeof(concern)) {
  46388. if ('undefined' !== typeof concern.j) this.options.j = concern.j;
  46389. if ('undefined' !== typeof concern.w) this.options.w = concern.w;
  46390. if ('undefined' !== typeof concern.wtimeout) this.options.wtimeout = concern.wtimeout;
  46391. } else {
  46392. this.options.w = 'm' === concern ? 'majority' : concern;
  46393. }
  46394. return this;
  46395. };
  46396. /**
  46397. * Specifies a time limit, in milliseconds, for the write concern.
  46398. * If `ms > 1`, it is maximum amount of time to wait for this write
  46399. * to propagate through the replica set before this operation fails.
  46400. * The default is `0`, which means no timeout.
  46401. *
  46402. * This option is only valid for operations that write to the database:
  46403. *
  46404. * - `deleteOne()`
  46405. * - `deleteMany()`
  46406. * - `findOneAndDelete()`
  46407. * - `findOneAndUpdate()`
  46408. * - `remove()`
  46409. * - `update()`
  46410. * - `updateOne()`
  46411. * - `updateMany()`
  46412. *
  46413. * Defaults to `wtimeout` value if it is specified in writeConcern
  46414. *
  46415. * ####Example:
  46416. *
  46417. * mquery().w(2).j(true).wtimeout(2000)
  46418. *
  46419. * @method wtimeout
  46420. * @memberOf Query
  46421. * @instance
  46422. * @param {number} ms number of milliseconds to wait
  46423. * @see mongodb https://docs.mongodb.com/manual/reference/write-concern/#wtimeout
  46424. * @return {Query} this
  46425. * @api public
  46426. */
  46427. Query.prototype.wtimeout = Query.prototype.wTimeout = function wtimeout(ms) {
  46428. this.options.wtimeout = ms;
  46429. return this;
  46430. };
  46431. /**
  46432. * Merges another Query or conditions object into this one.
  46433. *
  46434. * When a Query is passed, conditions, field selection and options are merged.
  46435. *
  46436. * @param {Query|Object} source
  46437. * @return {Query} this
  46438. */
  46439. Query.prototype.merge = function (source) {
  46440. if (!source) return this;
  46441. if (!Query.canMerge(source)) throw new TypeError('Invalid argument. Expected instanceof mquery or plain object');
  46442. if (source instanceof Query) {
  46443. // if source has a feature, apply it to ourselves
  46444. if (source._conditions) {
  46445. utils.merge(this._conditions, source._conditions);
  46446. }
  46447. if (source._fields) {
  46448. this._fields || (this._fields = {});
  46449. utils.merge(this._fields, source._fields);
  46450. }
  46451. if (source.options) {
  46452. this.options || (this.options = {});
  46453. utils.merge(this.options, source.options);
  46454. }
  46455. if (source._update) {
  46456. this._update || (this._update = {});
  46457. utils.mergeClone(this._update, source._update);
  46458. }
  46459. if (source._distinct) {
  46460. this._distinct = source._distinct;
  46461. }
  46462. return this;
  46463. } // plain object
  46464. utils.merge(this._conditions, source);
  46465. return this;
  46466. };
  46467. /**
  46468. * Finds documents.
  46469. *
  46470. * Passing a `callback` executes the query.
  46471. *
  46472. * ####Example
  46473. *
  46474. * query.find()
  46475. * query.find(callback)
  46476. * query.find({ name: 'Burning Lights' }, callback)
  46477. *
  46478. * @param {Object} [criteria] mongodb selector
  46479. * @param {Function} [callback]
  46480. * @return {Query} this
  46481. * @api public
  46482. */
  46483. Query.prototype.find = function (criteria, callback) {
  46484. this.op = 'find';
  46485. if ('function' === typeof criteria) {
  46486. callback = criteria;
  46487. criteria = undefined;
  46488. } else if (Query.canMerge(criteria)) {
  46489. this.merge(criteria);
  46490. }
  46491. if (!callback) return this;
  46492. var conds = this._conditions;
  46493. var options = this._optionsForExec();
  46494. if (this.$useProjection) {
  46495. options.projection = this._fieldsForExec();
  46496. } else {
  46497. options.fields = this._fieldsForExec();
  46498. }
  46499. debug('find', this._collection.collectionName, conds, options);
  46500. callback = this._wrapCallback('find', callback, {
  46501. conditions: conds,
  46502. options: options
  46503. });
  46504. this._collection.find(conds, options, utils.tick(callback));
  46505. return this;
  46506. };
  46507. /**
  46508. * Returns the query cursor
  46509. *
  46510. * ####Examples
  46511. *
  46512. * query.find().cursor();
  46513. * query.cursor({ name: 'Burning Lights' });
  46514. *
  46515. * @param {Object} [criteria] mongodb selector
  46516. * @return {Object} cursor
  46517. * @api public
  46518. */
  46519. Query.prototype.cursor = function cursor(criteria) {
  46520. if (this.op) {
  46521. if (this.op !== 'find') {
  46522. throw new TypeError('.cursor only support .find method');
  46523. }
  46524. } else {
  46525. this.find(criteria);
  46526. }
  46527. var conds = this._conditions;
  46528. var options = this._optionsForExec();
  46529. if (this.$useProjection) {
  46530. options.projection = this._fieldsForExec();
  46531. } else {
  46532. options.fields = this._fieldsForExec();
  46533. }
  46534. debug('findCursor', this._collection.collectionName, conds, options);
  46535. return this._collection.findCursor(conds, options);
  46536. };
  46537. /**
  46538. * Executes the query as a findOne() operation.
  46539. *
  46540. * Passing a `callback` executes the query.
  46541. *
  46542. * ####Example
  46543. *
  46544. * query.findOne().where('name', /^Burning/);
  46545. *
  46546. * query.findOne({ name: /^Burning/ })
  46547. *
  46548. * query.findOne({ name: /^Burning/ }, callback); // executes
  46549. *
  46550. * query.findOne(function (err, doc) {
  46551. * if (err) return handleError(err);
  46552. * if (doc) {
  46553. * // doc may be null if no document matched
  46554. *
  46555. * }
  46556. * });
  46557. *
  46558. * @param {Object|Query} [criteria] mongodb selector
  46559. * @param {Function} [callback]
  46560. * @return {Query} this
  46561. * @api public
  46562. */
  46563. Query.prototype.findOne = function (criteria, callback) {
  46564. this.op = 'findOne';
  46565. if ('function' === typeof criteria) {
  46566. callback = criteria;
  46567. criteria = undefined;
  46568. } else if (Query.canMerge(criteria)) {
  46569. this.merge(criteria);
  46570. }
  46571. if (!callback) return this;
  46572. var conds = this._conditions;
  46573. var options = this._optionsForExec();
  46574. if (this.$useProjection) {
  46575. options.projection = this._fieldsForExec();
  46576. } else {
  46577. options.fields = this._fieldsForExec();
  46578. }
  46579. debug('findOne', this._collection.collectionName, conds, options);
  46580. callback = this._wrapCallback('findOne', callback, {
  46581. conditions: conds,
  46582. options: options
  46583. });
  46584. this._collection.findOne(conds, options, utils.tick(callback));
  46585. return this;
  46586. };
  46587. /**
  46588. * Exectues the query as a count() operation.
  46589. *
  46590. * Passing a `callback` executes the query.
  46591. *
  46592. * ####Example
  46593. *
  46594. * query.count().where('color', 'black').exec(callback);
  46595. *
  46596. * query.count({ color: 'black' }).count(callback)
  46597. *
  46598. * query.count({ color: 'black' }, callback)
  46599. *
  46600. * query.where('color', 'black').count(function (err, count) {
  46601. * if (err) return handleError(err);
  46602. * console.log('there are %d kittens', count);
  46603. * })
  46604. *
  46605. * @param {Object} [criteria] mongodb selector
  46606. * @param {Function} [callback]
  46607. * @return {Query} this
  46608. * @see mongodb http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Count
  46609. * @api public
  46610. */
  46611. Query.prototype.count = function (criteria, callback) {
  46612. this.op = 'count';
  46613. this._validate();
  46614. if ('function' === typeof criteria) {
  46615. callback = criteria;
  46616. criteria = undefined;
  46617. } else if (Query.canMerge(criteria)) {
  46618. this.merge(criteria);
  46619. }
  46620. if (!callback) return this;
  46621. var conds = this._conditions,
  46622. options = this._optionsForExec();
  46623. debug('count', this._collection.collectionName, conds, options);
  46624. callback = this._wrapCallback('count', callback, {
  46625. conditions: conds,
  46626. options: options
  46627. });
  46628. this._collection.count(conds, options, utils.tick(callback));
  46629. return this;
  46630. };
  46631. /**
  46632. * Declares or executes a distinct() operation.
  46633. *
  46634. * Passing a `callback` executes the query.
  46635. *
  46636. * ####Example
  46637. *
  46638. * distinct(criteria, field, fn)
  46639. * distinct(criteria, field)
  46640. * distinct(field, fn)
  46641. * distinct(field)
  46642. * distinct(fn)
  46643. * distinct()
  46644. *
  46645. * @param {Object|Query} [criteria]
  46646. * @param {String} [field]
  46647. * @param {Function} [callback]
  46648. * @return {Query} this
  46649. * @see mongodb http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Distinct
  46650. * @api public
  46651. */
  46652. Query.prototype.distinct = function (criteria, field, callback) {
  46653. this.op = 'distinct';
  46654. this._validate();
  46655. if (!callback) {
  46656. switch (_typeof(field)) {
  46657. case 'function':
  46658. callback = field;
  46659. if ('string' == typeof criteria) {
  46660. field = criteria;
  46661. criteria = undefined;
  46662. }
  46663. break;
  46664. case 'undefined':
  46665. case 'string':
  46666. break;
  46667. default:
  46668. throw new TypeError('Invalid `field` argument. Must be string or function');
  46669. }
  46670. switch (_typeof(criteria)) {
  46671. case 'function':
  46672. callback = criteria;
  46673. criteria = field = undefined;
  46674. break;
  46675. case 'string':
  46676. field = criteria;
  46677. criteria = undefined;
  46678. break;
  46679. }
  46680. }
  46681. if ('string' == typeof field) {
  46682. this._distinct = field;
  46683. }
  46684. if (Query.canMerge(criteria)) {
  46685. this.merge(criteria);
  46686. }
  46687. if (!callback) {
  46688. return this;
  46689. }
  46690. if (!this._distinct) {
  46691. throw new Error('No value for `distinct` has been declared');
  46692. }
  46693. var conds = this._conditions,
  46694. options = this._optionsForExec();
  46695. debug('distinct', this._collection.collectionName, conds, options);
  46696. callback = this._wrapCallback('distinct', callback, {
  46697. conditions: conds,
  46698. options: options
  46699. });
  46700. this._collection.distinct(this._distinct, conds, options, utils.tick(callback));
  46701. return this;
  46702. };
  46703. /**
  46704. * Declare and/or execute this query as an update() operation. By default,
  46705. * `update()` only modifies the _first_ document that matches `criteria`.
  46706. *
  46707. * _All paths passed that are not $atomic operations will become $set ops._
  46708. *
  46709. * ####Example
  46710. *
  46711. * mquery({ _id: id }).update({ title: 'words' }, ...)
  46712. *
  46713. * becomes
  46714. *
  46715. * collection.update({ _id: id }, { $set: { title: 'words' }}, ...)
  46716. *
  46717. * ####Note
  46718. *
  46719. * Passing an empty object `{}` as the doc will result in a no-op unless the `overwrite` option is passed. Without the `overwrite` option set, the update operation will be ignored and the callback executed without sending the command to MongoDB so as to prevent accidently overwritting documents in the collection.
  46720. *
  46721. * ####Note
  46722. *
  46723. * The operation is only executed when a callback is passed. To force execution without a callback (which would be an unsafe write), we must first call update() and then execute it by using the `exec()` method.
  46724. *
  46725. * var q = mquery(collection).where({ _id: id });
  46726. * q.update({ $set: { name: 'bob' }}).update(); // not executed
  46727. *
  46728. * var q = mquery(collection).where({ _id: id });
  46729. * q.update({ $set: { name: 'bob' }}).exec(); // executed as unsafe
  46730. *
  46731. * // keys that are not $atomic ops become $set.
  46732. * // this executes the same command as the previous example.
  46733. * q.update({ name: 'bob' }).where({ _id: id }).exec();
  46734. *
  46735. * var q = mquery(collection).update(); // not executed
  46736. *
  46737. * // overwriting with empty docs
  46738. * var q.where({ _id: id }).setOptions({ overwrite: true })
  46739. * q.update({ }, callback); // executes
  46740. *
  46741. * // multi update with overwrite to empty doc
  46742. * var q = mquery(collection).where({ _id: id });
  46743. * q.setOptions({ multi: true, overwrite: true })
  46744. * q.update({ });
  46745. * q.update(callback); // executed
  46746. *
  46747. * // multi updates
  46748. * mquery()
  46749. * .collection(coll)
  46750. * .update({ name: /^match/ }, { $set: { arr: [] }}, { multi: true }, callback)
  46751. * // more multi updates
  46752. * mquery({ })
  46753. * .collection(coll)
  46754. * .setOptions({ multi: true })
  46755. * .update({ $set: { arr: [] }}, callback)
  46756. *
  46757. * // single update by default
  46758. * mquery({ email: 'address@example.com' })
  46759. * .collection(coll)
  46760. * .update({ $inc: { counter: 1 }}, callback)
  46761. *
  46762. * // summary
  46763. * update(criteria, doc, opts, cb) // executes
  46764. * update(criteria, doc, opts)
  46765. * update(criteria, doc, cb) // executes
  46766. * update(criteria, doc)
  46767. * update(doc, cb) // executes
  46768. * update(doc)
  46769. * update(cb) // executes
  46770. * update(true) // executes (unsafe write)
  46771. * update()
  46772. *
  46773. * @param {Object} [criteria]
  46774. * @param {Object} [doc] the update command
  46775. * @param {Object} [options]
  46776. * @param {Function} [callback]
  46777. * @return {Query} this
  46778. * @api public
  46779. */
  46780. Query.prototype.update = function update(criteria, doc, options, callback) {
  46781. var force;
  46782. switch (arguments.length) {
  46783. case 3:
  46784. if ('function' == typeof options) {
  46785. callback = options;
  46786. options = undefined;
  46787. }
  46788. break;
  46789. case 2:
  46790. if ('function' == typeof doc) {
  46791. callback = doc;
  46792. doc = criteria;
  46793. criteria = undefined;
  46794. }
  46795. break;
  46796. case 1:
  46797. switch (_typeof(criteria)) {
  46798. case 'function':
  46799. callback = criteria;
  46800. criteria = options = doc = undefined;
  46801. break;
  46802. case 'boolean':
  46803. // execution with no callback (unsafe write)
  46804. force = criteria;
  46805. criteria = undefined;
  46806. break;
  46807. default:
  46808. doc = criteria;
  46809. criteria = options = undefined;
  46810. break;
  46811. }
  46812. }
  46813. return _update(this, 'update', criteria, doc, options, force, callback);
  46814. };
  46815. /**
  46816. * Declare and/or execute this query as an `updateMany()` operation. Identical
  46817. * to `update()` except `updateMany()` will update _all_ documents that match
  46818. * `criteria`, rather than just the first one.
  46819. *
  46820. * _All paths passed that are not $atomic operations will become $set ops._
  46821. *
  46822. * ####Example
  46823. *
  46824. * // Update every document whose `title` contains 'test'
  46825. * mquery().updateMany({ title: /test/ }, { year: 2017 })
  46826. *
  46827. * @param {Object} [criteria]
  46828. * @param {Object} [doc] the update command
  46829. * @param {Object} [options]
  46830. * @param {Function} [callback]
  46831. * @return {Query} this
  46832. * @api public
  46833. */
  46834. Query.prototype.updateMany = function updateMany(criteria, doc, options, callback) {
  46835. var force;
  46836. switch (arguments.length) {
  46837. case 3:
  46838. if ('function' == typeof options) {
  46839. callback = options;
  46840. options = undefined;
  46841. }
  46842. break;
  46843. case 2:
  46844. if ('function' == typeof doc) {
  46845. callback = doc;
  46846. doc = criteria;
  46847. criteria = undefined;
  46848. }
  46849. break;
  46850. case 1:
  46851. switch (_typeof(criteria)) {
  46852. case 'function':
  46853. callback = criteria;
  46854. criteria = options = doc = undefined;
  46855. break;
  46856. case 'boolean':
  46857. // execution with no callback (unsafe write)
  46858. force = criteria;
  46859. criteria = undefined;
  46860. break;
  46861. default:
  46862. doc = criteria;
  46863. criteria = options = undefined;
  46864. break;
  46865. }
  46866. }
  46867. return _update(this, 'updateMany', criteria, doc, options, force, callback);
  46868. };
  46869. /**
  46870. * Declare and/or execute this query as an `updateOne()` operation. Identical
  46871. * to `update()` except `updateOne()` will _always_ update just one document,
  46872. * regardless of the `multi` option.
  46873. *
  46874. * _All paths passed that are not $atomic operations will become $set ops._
  46875. *
  46876. * ####Example
  46877. *
  46878. * // Update the first document whose `title` contains 'test'
  46879. * mquery().updateMany({ title: /test/ }, { year: 2017 })
  46880. *
  46881. * @param {Object} [criteria]
  46882. * @param {Object} [doc] the update command
  46883. * @param {Object} [options]
  46884. * @param {Function} [callback]
  46885. * @return {Query} this
  46886. * @api public
  46887. */
  46888. Query.prototype.updateOne = function updateOne(criteria, doc, options, callback) {
  46889. var force;
  46890. switch (arguments.length) {
  46891. case 3:
  46892. if ('function' == typeof options) {
  46893. callback = options;
  46894. options = undefined;
  46895. }
  46896. break;
  46897. case 2:
  46898. if ('function' == typeof doc) {
  46899. callback = doc;
  46900. doc = criteria;
  46901. criteria = undefined;
  46902. }
  46903. break;
  46904. case 1:
  46905. switch (_typeof(criteria)) {
  46906. case 'function':
  46907. callback = criteria;
  46908. criteria = options = doc = undefined;
  46909. break;
  46910. case 'boolean':
  46911. // execution with no callback (unsafe write)
  46912. force = criteria;
  46913. criteria = undefined;
  46914. break;
  46915. default:
  46916. doc = criteria;
  46917. criteria = options = undefined;
  46918. break;
  46919. }
  46920. }
  46921. return _update(this, 'updateOne', criteria, doc, options, force, callback);
  46922. };
  46923. /**
  46924. * Declare and/or execute this query as an `replaceOne()` operation. Similar
  46925. * to `updateOne()`, except `replaceOne()` is not allowed to use atomic
  46926. * modifiers (`$set`, `$push`, etc.). Calling `replaceOne()` will always
  46927. * replace the existing doc.
  46928. *
  46929. * ####Example
  46930. *
  46931. * // Replace the document with `_id` 1 with `{ _id: 1, year: 2017 }`
  46932. * mquery().replaceOne({ _id: 1 }, { year: 2017 })
  46933. *
  46934. * @param {Object} [criteria]
  46935. * @param {Object} [doc] the update command
  46936. * @param {Object} [options]
  46937. * @param {Function} [callback]
  46938. * @return {Query} this
  46939. * @api public
  46940. */
  46941. Query.prototype.replaceOne = function replaceOne(criteria, doc, options, callback) {
  46942. var force;
  46943. switch (arguments.length) {
  46944. case 3:
  46945. if ('function' == typeof options) {
  46946. callback = options;
  46947. options = undefined;
  46948. }
  46949. break;
  46950. case 2:
  46951. if ('function' == typeof doc) {
  46952. callback = doc;
  46953. doc = criteria;
  46954. criteria = undefined;
  46955. }
  46956. break;
  46957. case 1:
  46958. switch (_typeof(criteria)) {
  46959. case 'function':
  46960. callback = criteria;
  46961. criteria = options = doc = undefined;
  46962. break;
  46963. case 'boolean':
  46964. // execution with no callback (unsafe write)
  46965. force = criteria;
  46966. criteria = undefined;
  46967. break;
  46968. default:
  46969. doc = criteria;
  46970. criteria = options = undefined;
  46971. break;
  46972. }
  46973. }
  46974. this.setOptions({
  46975. overwrite: true
  46976. });
  46977. return _update(this, 'replaceOne', criteria, doc, options, force, callback);
  46978. };
  46979. /*!
  46980. * Internal helper for update, updateMany, updateOne
  46981. */
  46982. function _update(query, op, criteria, doc, options, force, callback) {
  46983. query.op = op;
  46984. if (Query.canMerge(criteria)) {
  46985. query.merge(criteria);
  46986. }
  46987. if (doc) {
  46988. query._mergeUpdate(doc);
  46989. }
  46990. if (utils.isObject(options)) {
  46991. // { overwrite: true }
  46992. query.setOptions(options);
  46993. } // we are done if we don't have callback and they are
  46994. // not forcing an unsafe write.
  46995. if (!(force || callback)) {
  46996. return query;
  46997. }
  46998. if (!query._update || !query.options.overwrite && 0 === utils.keys(query._update).length) {
  46999. callback && utils.soon(callback.bind(null, null, 0));
  47000. return query;
  47001. }
  47002. options = query._optionsForExec();
  47003. if (!callback) options.safe = false;
  47004. criteria = query._conditions;
  47005. doc = query._updateForExec();
  47006. debug('update', query._collection.collectionName, criteria, doc, options);
  47007. callback = query._wrapCallback(op, callback, {
  47008. conditions: criteria,
  47009. doc: doc,
  47010. options: options
  47011. });
  47012. query._collection[op](criteria, doc, options, utils.tick(callback));
  47013. return query;
  47014. }
  47015. /**
  47016. * Declare and/or execute this query as a remove() operation.
  47017. *
  47018. * ####Example
  47019. *
  47020. * mquery(collection).remove({ artist: 'Anne Murray' }, callback)
  47021. *
  47022. * ####Note
  47023. *
  47024. * The operation is only executed when a callback is passed. To force execution without a callback (which would be an unsafe write), we must first call remove() and then execute it by using the `exec()` method.
  47025. *
  47026. * // not executed
  47027. * var query = mquery(collection).remove({ name: 'Anne Murray' })
  47028. *
  47029. * // executed
  47030. * mquery(collection).remove({ name: 'Anne Murray' }, callback)
  47031. * mquery(collection).remove({ name: 'Anne Murray' }).remove(callback)
  47032. *
  47033. * // executed without a callback (unsafe write)
  47034. * query.exec()
  47035. *
  47036. * // summary
  47037. * query.remove(conds, fn); // executes
  47038. * query.remove(conds)
  47039. * query.remove(fn) // executes
  47040. * query.remove()
  47041. *
  47042. * @param {Object|Query} [criteria] mongodb selector
  47043. * @param {Function} [callback]
  47044. * @return {Query} this
  47045. * @api public
  47046. */
  47047. Query.prototype.remove = function (criteria, callback) {
  47048. this.op = 'remove';
  47049. var force;
  47050. if ('function' === typeof criteria) {
  47051. callback = criteria;
  47052. criteria = undefined;
  47053. } else if (Query.canMerge(criteria)) {
  47054. this.merge(criteria);
  47055. } else if (true === criteria) {
  47056. force = criteria;
  47057. criteria = undefined;
  47058. }
  47059. if (!(force || callback)) return this;
  47060. var options = this._optionsForExec();
  47061. if (!callback) options.safe = false;
  47062. var conds = this._conditions;
  47063. debug('remove', this._collection.collectionName, conds, options);
  47064. callback = this._wrapCallback('remove', callback, {
  47065. conditions: conds,
  47066. options: options
  47067. });
  47068. this._collection.remove(conds, options, utils.tick(callback));
  47069. return this;
  47070. };
  47071. /**
  47072. * Declare and/or execute this query as a `deleteOne()` operation. Behaves like
  47073. * `remove()`, except for ignores the `justOne` option and always deletes at
  47074. * most one document.
  47075. *
  47076. * ####Example
  47077. *
  47078. * mquery(collection).deleteOne({ artist: 'Anne Murray' }, callback)
  47079. *
  47080. * @param {Object|Query} [criteria] mongodb selector
  47081. * @param {Function} [callback]
  47082. * @return {Query} this
  47083. * @api public
  47084. */
  47085. Query.prototype.deleteOne = function (criteria, callback) {
  47086. this.op = 'deleteOne';
  47087. var force;
  47088. if ('function' === typeof criteria) {
  47089. callback = criteria;
  47090. criteria = undefined;
  47091. } else if (Query.canMerge(criteria)) {
  47092. this.merge(criteria);
  47093. } else if (true === criteria) {
  47094. force = criteria;
  47095. criteria = undefined;
  47096. }
  47097. if (!(force || callback)) return this;
  47098. var options = this._optionsForExec();
  47099. if (!callback) options.safe = false;
  47100. delete options.justOne;
  47101. var conds = this._conditions;
  47102. debug('deleteOne', this._collection.collectionName, conds, options);
  47103. callback = this._wrapCallback('deleteOne', callback, {
  47104. conditions: conds,
  47105. options: options
  47106. });
  47107. this._collection.deleteOne(conds, options, utils.tick(callback));
  47108. return this;
  47109. };
  47110. /**
  47111. * Declare and/or execute this query as a `deleteMany()` operation. Behaves like
  47112. * `remove()`, except for ignores the `justOne` option and always deletes
  47113. * _every_ document that matches `criteria`.
  47114. *
  47115. * ####Example
  47116. *
  47117. * mquery(collection).deleteMany({ artist: 'Anne Murray' }, callback)
  47118. *
  47119. * @param {Object|Query} [criteria] mongodb selector
  47120. * @param {Function} [callback]
  47121. * @return {Query} this
  47122. * @api public
  47123. */
  47124. Query.prototype.deleteMany = function (criteria, callback) {
  47125. this.op = 'deleteMany';
  47126. var force;
  47127. if ('function' === typeof criteria) {
  47128. callback = criteria;
  47129. criteria = undefined;
  47130. } else if (Query.canMerge(criteria)) {
  47131. this.merge(criteria);
  47132. } else if (true === criteria) {
  47133. force = criteria;
  47134. criteria = undefined;
  47135. }
  47136. if (!(force || callback)) return this;
  47137. var options = this._optionsForExec();
  47138. if (!callback) options.safe = false;
  47139. delete options.justOne;
  47140. var conds = this._conditions;
  47141. debug('deleteOne', this._collection.collectionName, conds, options);
  47142. callback = this._wrapCallback('deleteOne', callback, {
  47143. conditions: conds,
  47144. options: options
  47145. });
  47146. this._collection.deleteMany(conds, options, utils.tick(callback));
  47147. return this;
  47148. };
  47149. /**
  47150. * Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) update command.
  47151. *
  47152. * Finds a matching document, updates it according to the `update` arg, passing any `options`, and returns the found document (if any) to the callback. The query executes immediately if `callback` is passed.
  47153. *
  47154. * ####Available options
  47155. *
  47156. * - `new`: bool - true to return the modified document rather than the original. defaults to true
  47157. * - `upsert`: bool - creates the object if it doesn't exist. defaults to false.
  47158. * - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
  47159. *
  47160. * ####Examples
  47161. *
  47162. * query.findOneAndUpdate(conditions, update, options, callback) // executes
  47163. * query.findOneAndUpdate(conditions, update, options) // returns Query
  47164. * query.findOneAndUpdate(conditions, update, callback) // executes
  47165. * query.findOneAndUpdate(conditions, update) // returns Query
  47166. * query.findOneAndUpdate(update, callback) // returns Query
  47167. * query.findOneAndUpdate(update) // returns Query
  47168. * query.findOneAndUpdate(callback) // executes
  47169. * query.findOneAndUpdate() // returns Query
  47170. *
  47171. * @param {Object|Query} [query]
  47172. * @param {Object} [doc]
  47173. * @param {Object} [options]
  47174. * @param {Function} [callback]
  47175. * @see mongodb http://www.mongodb.org/display/DOCS/findAndModify+Command
  47176. * @return {Query} this
  47177. * @api public
  47178. */
  47179. Query.prototype.findOneAndUpdate = function (criteria, doc, options, callback) {
  47180. this.op = 'findOneAndUpdate';
  47181. this._validate();
  47182. switch (arguments.length) {
  47183. case 3:
  47184. if ('function' == typeof options) {
  47185. callback = options;
  47186. options = {};
  47187. }
  47188. break;
  47189. case 2:
  47190. if ('function' == typeof doc) {
  47191. callback = doc;
  47192. doc = criteria;
  47193. criteria = undefined;
  47194. }
  47195. options = undefined;
  47196. break;
  47197. case 1:
  47198. if ('function' == typeof criteria) {
  47199. callback = criteria;
  47200. criteria = options = doc = undefined;
  47201. } else {
  47202. doc = criteria;
  47203. criteria = options = undefined;
  47204. }
  47205. }
  47206. if (Query.canMerge(criteria)) {
  47207. this.merge(criteria);
  47208. } // apply doc
  47209. if (doc) {
  47210. this._mergeUpdate(doc);
  47211. }
  47212. options && this.setOptions(options);
  47213. if (!callback) return this;
  47214. var conds = this._conditions;
  47215. var update = this._updateForExec();
  47216. options = this._optionsForExec();
  47217. return this._collection.findOneAndUpdate(conds, update, options, utils.tick(callback));
  47218. };
  47219. /**
  47220. * Issues a mongodb [findAndModify](http://www.mongodb.org/display/DOCS/findAndModify+Command) remove command.
  47221. *
  47222. * Finds a matching document, removes it, passing the found document (if any) to the callback. Executes immediately if `callback` is passed.
  47223. *
  47224. * ####Available options
  47225. *
  47226. * - `sort`: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
  47227. *
  47228. * ####Examples
  47229. *
  47230. * A.where().findOneAndRemove(conditions, options, callback) // executes
  47231. * A.where().findOneAndRemove(conditions, options) // return Query
  47232. * A.where().findOneAndRemove(conditions, callback) // executes
  47233. * A.where().findOneAndRemove(conditions) // returns Query
  47234. * A.where().findOneAndRemove(callback) // executes
  47235. * A.where().findOneAndRemove() // returns Query
  47236. * A.where().findOneAndDelete() // alias of .findOneAndRemove()
  47237. *
  47238. * @param {Object} [conditions]
  47239. * @param {Object} [options]
  47240. * @param {Function} [callback]
  47241. * @return {Query} this
  47242. * @see mongodb http://www.mongodb.org/display/DOCS/findAndModify+Command
  47243. * @api public
  47244. */
  47245. Query.prototype.findOneAndRemove = Query.prototype.findOneAndDelete = function (conditions, options, callback) {
  47246. this.op = 'findOneAndRemove';
  47247. this._validate();
  47248. if ('function' == typeof options) {
  47249. callback = options;
  47250. options = undefined;
  47251. } else if ('function' == typeof conditions) {
  47252. callback = conditions;
  47253. conditions = undefined;
  47254. } // apply conditions
  47255. if (Query.canMerge(conditions)) {
  47256. this.merge(conditions);
  47257. } // apply options
  47258. options && this.setOptions(options);
  47259. if (!callback) return this;
  47260. options = this._optionsForExec();
  47261. var conds = this._conditions;
  47262. return this._collection.findOneAndDelete(conds, options, utils.tick(callback));
  47263. };
  47264. /**
  47265. * Wrap callback to add tracing
  47266. *
  47267. * @param {Function} callback
  47268. * @param {Object} [queryInfo]
  47269. * @api private
  47270. */
  47271. Query.prototype._wrapCallback = function (method, callback, queryInfo) {
  47272. var traceFunction = this._traceFunction || Query.traceFunction;
  47273. if (traceFunction) {
  47274. queryInfo.collectionName = this._collection.collectionName;
  47275. var traceCallback = traceFunction && traceFunction.call(null, method, queryInfo, this);
  47276. var startTime = new Date().getTime();
  47277. return function wrapperCallback(err, result) {
  47278. if (traceCallback) {
  47279. var millis = new Date().getTime() - startTime;
  47280. traceCallback.call(null, err, result, millis);
  47281. }
  47282. if (callback) {
  47283. callback.apply(null, arguments);
  47284. }
  47285. };
  47286. }
  47287. return callback;
  47288. };
  47289. /**
  47290. * Add trace function that gets called when the query is executed.
  47291. * The function will be called with (method, queryInfo, query) and
  47292. * should return a callback function which will be called
  47293. * with (err, result, millis) when the query is complete.
  47294. *
  47295. * queryInfo is an object containing: {
  47296. * collectionName: <name of the collection>,
  47297. * conditions: <query criteria>,
  47298. * options: <comment, fields, readPreference, etc>,
  47299. * doc: [document to update, if applicable]
  47300. * }
  47301. *
  47302. * NOTE: Does not trace stream queries.
  47303. *
  47304. * @param {Function} traceFunction
  47305. * @return {Query} this
  47306. * @api public
  47307. */
  47308. Query.prototype.setTraceFunction = function (traceFunction) {
  47309. this._traceFunction = traceFunction;
  47310. return this;
  47311. };
  47312. /**
  47313. * Executes the query
  47314. *
  47315. * ####Examples
  47316. *
  47317. * query.exec();
  47318. * query.exec(callback);
  47319. * query.exec('update');
  47320. * query.exec('find', callback);
  47321. *
  47322. * @param {String|Function} [operation]
  47323. * @param {Function} [callback]
  47324. * @api public
  47325. */
  47326. Query.prototype.exec = function exec(op, callback) {
  47327. switch (_typeof(op)) {
  47328. case 'function':
  47329. callback = op;
  47330. op = null;
  47331. break;
  47332. case 'string':
  47333. this.op = op;
  47334. break;
  47335. }
  47336. assert.ok(this.op, 'Missing query type: (find, update, etc)');
  47337. if ('update' == this.op || 'remove' == this.op) {
  47338. callback || (callback = true);
  47339. }
  47340. var _this = this;
  47341. if ('function' == typeof callback) {
  47342. this[this.op](callback);
  47343. } else {
  47344. return new Query.Promise(function (success, error) {
  47345. _this[_this.op](function (err, val) {
  47346. if (err) error(err);else success(val);
  47347. success = error = null;
  47348. });
  47349. });
  47350. }
  47351. };
  47352. /**
  47353. * Returns a thunk which when called runs this.exec()
  47354. *
  47355. * The thunk receives a callback function which will be
  47356. * passed to `this.exec()`
  47357. *
  47358. * @return {Function}
  47359. * @api public
  47360. */
  47361. Query.prototype.thunk = function () {
  47362. var _this = this;
  47363. return function (cb) {
  47364. _this.exec(cb);
  47365. };
  47366. };
  47367. /**
  47368. * Executes the query returning a `Promise` which will be
  47369. * resolved with either the doc(s) or rejected with the error.
  47370. *
  47371. * @param {Function} [resolve]
  47372. * @param {Function} [reject]
  47373. * @return {Promise}
  47374. * @api public
  47375. */
  47376. Query.prototype.then = function (resolve, reject) {
  47377. var _this = this;
  47378. var promise = new Query.Promise(function (success, error) {
  47379. _this.exec(function (err, val) {
  47380. if (err) error(err);else success(val);
  47381. success = error = null;
  47382. });
  47383. });
  47384. return promise.then(resolve, reject);
  47385. };
  47386. /**
  47387. * Returns a cursor for the given `find` query.
  47388. *
  47389. * @throws Error if operation is not a find
  47390. * @returns {Cursor} MongoDB driver cursor
  47391. */
  47392. Query.prototype.cursor = function () {
  47393. if ('find' != this.op) throw new Error('cursor() is only available for find');
  47394. var conds = this._conditions;
  47395. var options = this._optionsForExec();
  47396. if (this.$useProjection) {
  47397. options.projection = this._fieldsForExec();
  47398. } else {
  47399. options.fields = this._fieldsForExec();
  47400. }
  47401. debug('cursor', this._collection.collectionName, conds, options);
  47402. return this._collection.findCursor(conds, options);
  47403. };
  47404. /**
  47405. * Determines if field selection has been made.
  47406. *
  47407. * @return {Boolean}
  47408. * @api public
  47409. */
  47410. Query.prototype.selected = function selected() {
  47411. return !!(this._fields && Object.keys(this._fields).length > 0);
  47412. };
  47413. /**
  47414. * Determines if inclusive field selection has been made.
  47415. *
  47416. * query.selectedInclusively() // false
  47417. * query.select('name')
  47418. * query.selectedInclusively() // true
  47419. * query.selectedExlusively() // false
  47420. *
  47421. * @returns {Boolean}
  47422. */
  47423. Query.prototype.selectedInclusively = function selectedInclusively() {
  47424. if (!this._fields) return false;
  47425. var keys = Object.keys(this._fields);
  47426. if (0 === keys.length) return false;
  47427. for (var i = 0; i < keys.length; ++i) {
  47428. var key = keys[i];
  47429. if (0 === this._fields[key]) return false;
  47430. if (this._fields[key] && _typeof(this._fields[key]) === 'object' && this._fields[key].$meta) {
  47431. return false;
  47432. }
  47433. }
  47434. return true;
  47435. };
  47436. /**
  47437. * Determines if exclusive field selection has been made.
  47438. *
  47439. * query.selectedExlusively() // false
  47440. * query.select('-name')
  47441. * query.selectedExlusively() // true
  47442. * query.selectedInclusively() // false
  47443. *
  47444. * @returns {Boolean}
  47445. */
  47446. Query.prototype.selectedExclusively = function selectedExclusively() {
  47447. if (!this._fields) return false;
  47448. var keys = Object.keys(this._fields);
  47449. if (0 === keys.length) return false;
  47450. for (var i = 0; i < keys.length; ++i) {
  47451. var key = keys[i];
  47452. if (0 === this._fields[key]) return true;
  47453. }
  47454. return false;
  47455. };
  47456. /**
  47457. * Merges `doc` with the current update object.
  47458. *
  47459. * @param {Object} doc
  47460. */
  47461. Query.prototype._mergeUpdate = function (doc) {
  47462. if (!this._update) this._update = {};
  47463. if (doc instanceof Query) {
  47464. if (doc._update) {
  47465. utils.mergeClone(this._update, doc._update);
  47466. }
  47467. } else {
  47468. utils.mergeClone(this._update, doc);
  47469. }
  47470. };
  47471. /**
  47472. * Returns default options.
  47473. *
  47474. * @return {Object}
  47475. * @api private
  47476. */
  47477. Query.prototype._optionsForExec = function () {
  47478. var options = utils.clone(this.options);
  47479. return options;
  47480. };
  47481. /**
  47482. * Returns fields selection for this query.
  47483. *
  47484. * @return {Object}
  47485. * @api private
  47486. */
  47487. Query.prototype._fieldsForExec = function () {
  47488. return utils.clone(this._fields);
  47489. };
  47490. /**
  47491. * Return an update document with corrected $set operations.
  47492. *
  47493. * @api private
  47494. */
  47495. Query.prototype._updateForExec = function () {
  47496. var update = utils.clone(this._update);
  47497. var ops = utils.keys(update);
  47498. var ret = {};
  47499. var _iterator = _createForOfIteratorHelper(ops),
  47500. _step;
  47501. try {
  47502. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  47503. var op = _step.value;
  47504. if (this.options.overwrite) {
  47505. ret[op] = update[op];
  47506. continue;
  47507. }
  47508. if ('$' !== op[0]) {
  47509. // fix up $set sugar
  47510. if (!ret.$set) {
  47511. if (update.$set) {
  47512. ret.$set = update.$set;
  47513. } else {
  47514. ret.$set = {};
  47515. }
  47516. }
  47517. ret.$set[op] = update[op];
  47518. if (!~ops.indexOf('$set')) ops.push('$set');
  47519. } else if ('$set' === op) {
  47520. if (!ret.$set) {
  47521. ret[op] = update[op];
  47522. }
  47523. } else {
  47524. ret[op] = update[op];
  47525. }
  47526. }
  47527. } catch (err) {
  47528. _iterator.e(err);
  47529. } finally {
  47530. _iterator.f();
  47531. }
  47532. this._compiledUpdate = ret;
  47533. return ret;
  47534. };
  47535. /**
  47536. * Make sure _path is set.
  47537. *
  47538. * @parmam {String} method
  47539. */
  47540. Query.prototype._ensurePath = function (method) {
  47541. if (!this._path) {
  47542. var msg = method + '() must be used after where() ' + 'when called with these arguments';
  47543. throw new Error(msg);
  47544. }
  47545. };
  47546. /*!
  47547. * Permissions
  47548. */
  47549. Query.permissions = __webpack_require__(6477);
  47550. Query._isPermitted = function (a, b) {
  47551. var denied = Query.permissions[b];
  47552. if (!denied) return true;
  47553. return true !== denied[a];
  47554. };
  47555. Query.prototype._validate = function (action) {
  47556. var fail;
  47557. var validator;
  47558. if (undefined === action) {
  47559. validator = Query.permissions[this.op];
  47560. if ('function' != typeof validator) return true;
  47561. fail = validator(this);
  47562. } else if (!Query._isPermitted(action, this.op)) {
  47563. fail = action;
  47564. }
  47565. if (fail) {
  47566. throw new Error(fail + ' cannot be used with ' + this.op);
  47567. }
  47568. };
  47569. /**
  47570. * Determines if `conds` can be merged using `mquery().merge()`
  47571. *
  47572. * @param {Object} conds
  47573. * @return {Boolean}
  47574. */
  47575. Query.canMerge = function (conds) {
  47576. return conds instanceof Query || utils.isObject(conds);
  47577. };
  47578. /**
  47579. * Set a trace function that will get called whenever a
  47580. * query is executed.
  47581. *
  47582. * See `setTraceFunction()` for details.
  47583. *
  47584. * @param {Object} conds
  47585. * @return {Boolean}
  47586. */
  47587. Query.setGlobalTraceFunction = function (traceFunction) {
  47588. Query.traceFunction = traceFunction;
  47589. };
  47590. /*!
  47591. * Exports.
  47592. */
  47593. Query.utils = utils;
  47594. Query.env = __webpack_require__(3669);
  47595. Query.Collection = __webpack_require__(8514);
  47596. Query.BaseCollection = __webpack_require__(3231);
  47597. Query.Promise = Promise;
  47598. module.exports = exports = Query; // TODO
  47599. // test utils
  47600. /***/ }),
  47601. /***/ 6477:
  47602. /***/ ((__unused_webpack_module, exports) => {
  47603. "use strict";
  47604. var denied = exports;
  47605. denied.distinct = function (self) {
  47606. if (self._fields && Object.keys(self._fields).length > 0) {
  47607. return 'field selection and slice';
  47608. }
  47609. var keys = Object.keys(denied.distinct);
  47610. var err;
  47611. keys.every(function (option) {
  47612. if (self.options[option]) {
  47613. err = option;
  47614. return false;
  47615. }
  47616. return true;
  47617. });
  47618. return err;
  47619. };
  47620. denied.distinct.select = denied.distinct.slice = denied.distinct.sort = denied.distinct.limit = denied.distinct.skip = denied.distinct.batchSize = denied.distinct.maxScan = denied.distinct.snapshot = denied.distinct.hint = denied.distinct.tailable = true; // aggregation integration
  47621. denied.findOneAndUpdate = denied.findOneAndRemove = function (self) {
  47622. var keys = Object.keys(denied.findOneAndUpdate);
  47623. var err;
  47624. keys.every(function (option) {
  47625. if (self.options[option]) {
  47626. err = option;
  47627. return false;
  47628. }
  47629. return true;
  47630. });
  47631. return err;
  47632. };
  47633. denied.findOneAndUpdate.limit = denied.findOneAndUpdate.skip = denied.findOneAndUpdate.batchSize = denied.findOneAndUpdate.maxScan = denied.findOneAndUpdate.snapshot = denied.findOneAndUpdate.tailable = true;
  47634. denied.count = function (self) {
  47635. if (self._fields && Object.keys(self._fields).length > 0) {
  47636. return 'field selection and slice';
  47637. }
  47638. var keys = Object.keys(denied.count);
  47639. var err;
  47640. keys.every(function (option) {
  47641. if (self.options[option]) {
  47642. err = option;
  47643. return false;
  47644. }
  47645. return true;
  47646. });
  47647. return err;
  47648. };
  47649. denied.count.slice = denied.count.batchSize = denied.count.maxScan = denied.count.snapshot = denied.count.tailable = true;
  47650. /***/ }),
  47651. /***/ 728:
  47652. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  47653. "use strict";
  47654. /* provided dependency */ var Buffer = __webpack_require__(365)["Buffer"];
  47655. /*!
  47656. * Module dependencies.
  47657. */
  47658. var specialProperties = ['__proto__', 'constructor', 'prototype'];
  47659. /**
  47660. * Clones objects
  47661. *
  47662. * @param {Object} obj the object to clone
  47663. * @param {Object} options
  47664. * @return {Object} the cloned object
  47665. * @api private
  47666. */
  47667. var clone = exports.clone = function clone(obj, options) {
  47668. if (obj === undefined || obj === null) return obj;
  47669. if (Array.isArray(obj)) return exports.cloneArray(obj, options);
  47670. if (obj.constructor) {
  47671. if (/ObjectI[dD]$/.test(obj.constructor.name)) {
  47672. return 'function' == typeof obj.clone ? obj.clone() : new obj.constructor(obj.id);
  47673. }
  47674. if (obj.constructor.name === 'ReadPreference') {
  47675. return new obj.constructor(obj.mode, clone(obj.tags, options));
  47676. }
  47677. if ('Binary' == obj._bsontype && obj.buffer && obj.value) {
  47678. return 'function' == typeof obj.clone ? obj.clone() : new obj.constructor(obj.value(true), obj.sub_type);
  47679. }
  47680. if ('Date' === obj.constructor.name || 'Function' === obj.constructor.name) return new obj.constructor(+obj);
  47681. if ('RegExp' === obj.constructor.name) return new RegExp(obj);
  47682. if ('Buffer' === obj.constructor.name) return Buffer.from(obj);
  47683. }
  47684. if (isObject(obj)) return exports.cloneObject(obj, options);
  47685. if (obj.valueOf) return obj.valueOf();
  47686. };
  47687. /*!
  47688. * ignore
  47689. */
  47690. exports.cloneObject = function cloneObject(obj, options) {
  47691. var minimize = options && options.minimize,
  47692. ret = {},
  47693. keys = Object.keys(obj),
  47694. len = keys.length;
  47695. var hasKeys = false,
  47696. val,
  47697. k = '',
  47698. i = 0;
  47699. for (i = 0; i < len; ++i) {
  47700. k = keys[i]; // Not technically prototype pollution because this wouldn't merge properties
  47701. // onto `Object.prototype`, but avoid properties like __proto__ as a precaution.
  47702. if (specialProperties.indexOf(k) !== -1) {
  47703. continue;
  47704. }
  47705. val = clone(obj[k], options);
  47706. if (!minimize || 'undefined' !== typeof val) {
  47707. hasKeys || (hasKeys = true);
  47708. ret[k] = val;
  47709. }
  47710. }
  47711. return minimize ? hasKeys && ret : ret;
  47712. };
  47713. exports.cloneArray = function cloneArray(arr, options) {
  47714. var ret = [],
  47715. l = arr.length;
  47716. var i = 0;
  47717. for (; i < l; i++) {
  47718. ret.push(clone(arr[i], options));
  47719. }
  47720. return ret;
  47721. };
  47722. /**
  47723. * process.nextTick helper.
  47724. *
  47725. * Wraps the given `callback` in a try/catch. If an error is
  47726. * caught it will be thrown on nextTick.
  47727. *
  47728. * node-mongodb-native had a habit of state corruption when
  47729. * an error was immediately thrown from within a collection
  47730. * method (find, update, etc) callback.
  47731. *
  47732. * @param {Function} [callback]
  47733. * @api private
  47734. */
  47735. exports.tick = function tick(callback) {
  47736. if ('function' !== typeof callback) return;
  47737. return function () {
  47738. // callbacks should always be fired on the next
  47739. // turn of the event loop. A side benefit is
  47740. // errors thrown from executing the callback
  47741. // will not cause drivers state to be corrupted
  47742. // which has historically been a problem.
  47743. var args = arguments;
  47744. soon(function () {
  47745. callback.apply(this, args);
  47746. });
  47747. };
  47748. };
  47749. /**
  47750. * Merges `from` into `to` without overwriting existing properties.
  47751. *
  47752. * @param {Object} to
  47753. * @param {Object} from
  47754. * @api private
  47755. */
  47756. exports.merge = function merge(to, from) {
  47757. var keys = Object.keys(from);
  47758. for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
  47759. var key = _keys[_i];
  47760. if (specialProperties.indexOf(key) !== -1) {
  47761. continue;
  47762. }
  47763. if ('undefined' === typeof to[key]) {
  47764. to[key] = from[key];
  47765. } else {
  47766. if (exports.isObject(from[key])) {
  47767. merge(to[key], from[key]);
  47768. } else {
  47769. to[key] = from[key];
  47770. }
  47771. }
  47772. }
  47773. };
  47774. /**
  47775. * Same as merge but clones the assigned values.
  47776. *
  47777. * @param {Object} to
  47778. * @param {Object} from
  47779. * @api private
  47780. */
  47781. exports.mergeClone = function mergeClone(to, from) {
  47782. var keys = Object.keys(from);
  47783. for (var _i2 = 0, _keys2 = keys; _i2 < _keys2.length; _i2++) {
  47784. var key = _keys2[_i2];
  47785. if (specialProperties.indexOf(key) !== -1) {
  47786. continue;
  47787. }
  47788. if ('undefined' === typeof to[key]) {
  47789. to[key] = clone(from[key]);
  47790. } else {
  47791. if (exports.isObject(from[key])) {
  47792. mergeClone(to[key], from[key]);
  47793. } else {
  47794. to[key] = clone(from[key]);
  47795. }
  47796. }
  47797. }
  47798. };
  47799. /**
  47800. * Read pref helper (mongo 2.2 drivers support this)
  47801. *
  47802. * Allows using aliases instead of full preference names:
  47803. *
  47804. * p primary
  47805. * pp primaryPreferred
  47806. * s secondary
  47807. * sp secondaryPreferred
  47808. * n nearest
  47809. *
  47810. * @param {String} pref
  47811. */
  47812. exports.readPref = function readPref(pref) {
  47813. switch (pref) {
  47814. case 'p':
  47815. pref = 'primary';
  47816. break;
  47817. case 'pp':
  47818. pref = 'primaryPreferred';
  47819. break;
  47820. case 's':
  47821. pref = 'secondary';
  47822. break;
  47823. case 'sp':
  47824. pref = 'secondaryPreferred';
  47825. break;
  47826. case 'n':
  47827. pref = 'nearest';
  47828. break;
  47829. }
  47830. return pref;
  47831. };
  47832. /**
  47833. * Read Concern helper (mongo 3.2 drivers support this)
  47834. *
  47835. * Allows using string to specify read concern level:
  47836. *
  47837. * local 3.2+
  47838. * available 3.6+
  47839. * majority 3.2+
  47840. * linearizable 3.4+
  47841. * snapshot 4.0+
  47842. *
  47843. * @param {String|Object} concern
  47844. */
  47845. exports.readConcern = function readConcern(concern) {
  47846. if ('string' === typeof concern) {
  47847. switch (concern) {
  47848. case 'l':
  47849. concern = 'local';
  47850. break;
  47851. case 'a':
  47852. concern = 'available';
  47853. break;
  47854. case 'm':
  47855. concern = 'majority';
  47856. break;
  47857. case 'lz':
  47858. concern = 'linearizable';
  47859. break;
  47860. case 's':
  47861. concern = 'snapshot';
  47862. break;
  47863. }
  47864. concern = {
  47865. level: concern
  47866. };
  47867. }
  47868. return concern;
  47869. };
  47870. /**
  47871. * Object.prototype.toString.call helper
  47872. */
  47873. var _toString = Object.prototype.toString;
  47874. exports.toString = function (arg) {
  47875. return _toString.call(arg);
  47876. };
  47877. /**
  47878. * Determines if `arg` is an object.
  47879. *
  47880. * @param {Object|Array|String|Function|RegExp|any} arg
  47881. * @return {Boolean}
  47882. */
  47883. var isObject = exports.isObject = function (arg) {
  47884. return '[object Object]' == exports.toString(arg);
  47885. };
  47886. /**
  47887. * Object.keys helper
  47888. */
  47889. exports.keys = Object.keys;
  47890. /**
  47891. * Basic Object.create polyfill.
  47892. * Only one argument is supported.
  47893. *
  47894. * Based on https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create
  47895. */
  47896. exports.create = 'function' == typeof Object.create ? Object.create : create;
  47897. function create(proto) {
  47898. if (arguments.length > 1) {
  47899. throw new Error('Adding properties is not supported');
  47900. }
  47901. function F() {}
  47902. F.prototype = proto;
  47903. return new F();
  47904. }
  47905. /**
  47906. * inheritance
  47907. */
  47908. exports.inherits = function (ctor, superCtor) {
  47909. ctor.prototype = exports.create(superCtor.prototype);
  47910. ctor.prototype.constructor = ctor;
  47911. };
  47912. /**
  47913. * nextTick helper
  47914. * compat with node 0.10 which behaves differently than previous versions
  47915. */
  47916. var soon = exports.soon = 'function' == typeof setImmediate ? setImmediate : ({env:{}}).nextTick;
  47917. /**
  47918. * Check if this object is an arguments object
  47919. *
  47920. * @param {Any} v
  47921. * @return {Boolean}
  47922. */
  47923. exports.isArgumentsObject = function (v) {
  47924. return Object.prototype.toString.call(v) === '[object Arguments]';
  47925. };
  47926. /***/ }),
  47927. /***/ 2068:
  47928. /***/ ((module) => {
  47929. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  47930. /**
  47931. * Helpers.
  47932. */
  47933. var s = 1000;
  47934. var m = s * 60;
  47935. var h = m * 60;
  47936. var d = h * 24;
  47937. var w = d * 7;
  47938. var y = d * 365.25;
  47939. /**
  47940. * Parse or format the given `val`.
  47941. *
  47942. * Options:
  47943. *
  47944. * - `long` verbose formatting [false]
  47945. *
  47946. * @param {String|Number} val
  47947. * @param {Object} [options]
  47948. * @throws {Error} throw an error if val is not a non-empty string or a number
  47949. * @return {String|Number}
  47950. * @api public
  47951. */
  47952. module.exports = function (val, options) {
  47953. options = options || {};
  47954. var type = _typeof(val);
  47955. if (type === 'string' && val.length > 0) {
  47956. return parse(val);
  47957. } else if (type === 'number' && isFinite(val)) {
  47958. return options["long"] ? fmtLong(val) : fmtShort(val);
  47959. }
  47960. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
  47961. };
  47962. /**
  47963. * Parse the given `str` and return milliseconds.
  47964. *
  47965. * @param {String} str
  47966. * @return {Number}
  47967. * @api private
  47968. */
  47969. function parse(str) {
  47970. str = String(str);
  47971. if (str.length > 100) {
  47972. return;
  47973. }
  47974. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
  47975. if (!match) {
  47976. return;
  47977. }
  47978. var n = parseFloat(match[1]);
  47979. var type = (match[2] || 'ms').toLowerCase();
  47980. switch (type) {
  47981. case 'years':
  47982. case 'year':
  47983. case 'yrs':
  47984. case 'yr':
  47985. case 'y':
  47986. return n * y;
  47987. case 'weeks':
  47988. case 'week':
  47989. case 'w':
  47990. return n * w;
  47991. case 'days':
  47992. case 'day':
  47993. case 'd':
  47994. return n * d;
  47995. case 'hours':
  47996. case 'hour':
  47997. case 'hrs':
  47998. case 'hr':
  47999. case 'h':
  48000. return n * h;
  48001. case 'minutes':
  48002. case 'minute':
  48003. case 'mins':
  48004. case 'min':
  48005. case 'm':
  48006. return n * m;
  48007. case 'seconds':
  48008. case 'second':
  48009. case 'secs':
  48010. case 'sec':
  48011. case 's':
  48012. return n * s;
  48013. case 'milliseconds':
  48014. case 'millisecond':
  48015. case 'msecs':
  48016. case 'msec':
  48017. case 'ms':
  48018. return n;
  48019. default:
  48020. return undefined;
  48021. }
  48022. }
  48023. /**
  48024. * Short format for `ms`.
  48025. *
  48026. * @param {Number} ms
  48027. * @return {String}
  48028. * @api private
  48029. */
  48030. function fmtShort(ms) {
  48031. var msAbs = Math.abs(ms);
  48032. if (msAbs >= d) {
  48033. return Math.round(ms / d) + 'd';
  48034. }
  48035. if (msAbs >= h) {
  48036. return Math.round(ms / h) + 'h';
  48037. }
  48038. if (msAbs >= m) {
  48039. return Math.round(ms / m) + 'm';
  48040. }
  48041. if (msAbs >= s) {
  48042. return Math.round(ms / s) + 's';
  48043. }
  48044. return ms + 'ms';
  48045. }
  48046. /**
  48047. * Long format for `ms`.
  48048. *
  48049. * @param {Number} ms
  48050. * @return {String}
  48051. * @api private
  48052. */
  48053. function fmtLong(ms) {
  48054. var msAbs = Math.abs(ms);
  48055. if (msAbs >= d) {
  48056. return plural(ms, msAbs, d, 'day');
  48057. }
  48058. if (msAbs >= h) {
  48059. return plural(ms, msAbs, h, 'hour');
  48060. }
  48061. if (msAbs >= m) {
  48062. return plural(ms, msAbs, m, 'minute');
  48063. }
  48064. if (msAbs >= s) {
  48065. return plural(ms, msAbs, s, 'second');
  48066. }
  48067. return ms + ' ms';
  48068. }
  48069. /**
  48070. * Pluralization helper.
  48071. */
  48072. function plural(ms, msAbs, n, name) {
  48073. var isPlural = msAbs >= n * 1.5;
  48074. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  48075. }
  48076. /***/ }),
  48077. /***/ 692:
  48078. /***/ ((module) => {
  48079. "use strict";
  48080. var numberIsNaN = function numberIsNaN(value) {
  48081. return value !== value;
  48082. };
  48083. module.exports = function is(a, b) {
  48084. if (a === 0 && b === 0) {
  48085. return 1 / a === 1 / b;
  48086. }
  48087. if (a === b) {
  48088. return true;
  48089. }
  48090. if (numberIsNaN(a) && numberIsNaN(b)) {
  48091. return true;
  48092. }
  48093. return false;
  48094. };
  48095. /***/ }),
  48096. /***/ 4710:
  48097. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48098. "use strict";
  48099. var define = __webpack_require__(7921);
  48100. var callBind = __webpack_require__(3862);
  48101. var implementation = __webpack_require__(692);
  48102. var getPolyfill = __webpack_require__(9292);
  48103. var shim = __webpack_require__(9228);
  48104. var polyfill = callBind(getPolyfill(), Object);
  48105. define(polyfill, {
  48106. getPolyfill: getPolyfill,
  48107. implementation: implementation,
  48108. shim: shim
  48109. });
  48110. module.exports = polyfill;
  48111. /***/ }),
  48112. /***/ 9292:
  48113. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48114. "use strict";
  48115. var implementation = __webpack_require__(692);
  48116. module.exports = function getPolyfill() {
  48117. return typeof Object.is === 'function' ? Object.is : implementation;
  48118. };
  48119. /***/ }),
  48120. /***/ 9228:
  48121. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48122. "use strict";
  48123. var getPolyfill = __webpack_require__(9292);
  48124. var define = __webpack_require__(7921);
  48125. module.exports = function shimObjectIs() {
  48126. var polyfill = getPolyfill();
  48127. define(Object, {
  48128. is: polyfill
  48129. }, {
  48130. is: function testObjectIs() {
  48131. return Object.is !== polyfill;
  48132. }
  48133. });
  48134. return polyfill;
  48135. };
  48136. /***/ }),
  48137. /***/ 6164:
  48138. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48139. "use strict";
  48140. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  48141. var keysShim;
  48142. if (!Object.keys) {
  48143. // modified from https://github.com/es-shims/es5-shim
  48144. var has = Object.prototype.hasOwnProperty;
  48145. var toStr = Object.prototype.toString;
  48146. var isArgs = __webpack_require__(5184); // eslint-disable-line global-require
  48147. var isEnumerable = Object.prototype.propertyIsEnumerable;
  48148. var hasDontEnumBug = !isEnumerable.call({
  48149. toString: null
  48150. }, 'toString');
  48151. var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
  48152. var dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'];
  48153. var equalsConstructorPrototype = function equalsConstructorPrototype(o) {
  48154. var ctor = o.constructor;
  48155. return ctor && ctor.prototype === o;
  48156. };
  48157. var excludedKeys = {
  48158. $applicationCache: true,
  48159. $console: true,
  48160. $external: true,
  48161. $frame: true,
  48162. $frameElement: true,
  48163. $frames: true,
  48164. $innerHeight: true,
  48165. $innerWidth: true,
  48166. $onmozfullscreenchange: true,
  48167. $onmozfullscreenerror: true,
  48168. $outerHeight: true,
  48169. $outerWidth: true,
  48170. $pageXOffset: true,
  48171. $pageYOffset: true,
  48172. $parent: true,
  48173. $scrollLeft: true,
  48174. $scrollTop: true,
  48175. $scrollX: true,
  48176. $scrollY: true,
  48177. $self: true,
  48178. $webkitIndexedDB: true,
  48179. $webkitStorageInfo: true,
  48180. $window: true
  48181. };
  48182. var hasAutomationEqualityBug = function () {
  48183. /* global window */
  48184. if (typeof window === 'undefined') {
  48185. return false;
  48186. }
  48187. for (var k in window) {
  48188. try {
  48189. if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && _typeof(window[k]) === 'object') {
  48190. try {
  48191. equalsConstructorPrototype(window[k]);
  48192. } catch (e) {
  48193. return true;
  48194. }
  48195. }
  48196. } catch (e) {
  48197. return true;
  48198. }
  48199. }
  48200. return false;
  48201. }();
  48202. var equalsConstructorPrototypeIfNotBuggy = function equalsConstructorPrototypeIfNotBuggy(o) {
  48203. /* global window */
  48204. if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
  48205. return equalsConstructorPrototype(o);
  48206. }
  48207. try {
  48208. return equalsConstructorPrototype(o);
  48209. } catch (e) {
  48210. return false;
  48211. }
  48212. };
  48213. keysShim = function keys(object) {
  48214. var isObject = object !== null && _typeof(object) === 'object';
  48215. var isFunction = toStr.call(object) === '[object Function]';
  48216. var isArguments = isArgs(object);
  48217. var isString = isObject && toStr.call(object) === '[object String]';
  48218. var theKeys = [];
  48219. if (!isObject && !isFunction && !isArguments) {
  48220. throw new TypeError('Object.keys called on a non-object');
  48221. }
  48222. var skipProto = hasProtoEnumBug && isFunction;
  48223. if (isString && object.length > 0 && !has.call(object, 0)) {
  48224. for (var i = 0; i < object.length; ++i) {
  48225. theKeys.push(String(i));
  48226. }
  48227. }
  48228. if (isArguments && object.length > 0) {
  48229. for (var j = 0; j < object.length; ++j) {
  48230. theKeys.push(String(j));
  48231. }
  48232. } else {
  48233. for (var name in object) {
  48234. if (!(skipProto && name === 'prototype') && has.call(object, name)) {
  48235. theKeys.push(String(name));
  48236. }
  48237. }
  48238. }
  48239. if (hasDontEnumBug) {
  48240. var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
  48241. for (var k = 0; k < dontEnums.length; ++k) {
  48242. if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
  48243. theKeys.push(dontEnums[k]);
  48244. }
  48245. }
  48246. }
  48247. return theKeys;
  48248. };
  48249. }
  48250. module.exports = keysShim;
  48251. /***/ }),
  48252. /***/ 3818:
  48253. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48254. "use strict";
  48255. var slice = Array.prototype.slice;
  48256. var isArgs = __webpack_require__(5184);
  48257. var origKeys = Object.keys;
  48258. var keysShim = origKeys ? function keys(o) {
  48259. return origKeys(o);
  48260. } : __webpack_require__(6164);
  48261. var originalKeys = Object.keys;
  48262. keysShim.shim = function shimObjectKeys() {
  48263. if (Object.keys) {
  48264. var keysWorksWithArguments = function () {
  48265. // Safari 5.0 bug
  48266. var args = Object.keys(arguments);
  48267. return args && args.length === arguments.length;
  48268. }(1, 2);
  48269. if (!keysWorksWithArguments) {
  48270. Object.keys = function keys(object) {
  48271. // eslint-disable-line func-name-matching
  48272. if (isArgs(object)) {
  48273. return originalKeys(slice.call(object));
  48274. }
  48275. return originalKeys(object);
  48276. };
  48277. }
  48278. } else {
  48279. Object.keys = keysShim;
  48280. }
  48281. return Object.keys || keysShim;
  48282. };
  48283. module.exports = keysShim;
  48284. /***/ }),
  48285. /***/ 5184:
  48286. /***/ ((module) => {
  48287. "use strict";
  48288. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  48289. var toStr = Object.prototype.toString;
  48290. module.exports = function isArguments(value) {
  48291. var str = toStr.call(value);
  48292. var isArgs = str === '[object Arguments]';
  48293. if (!isArgs) {
  48294. isArgs = str !== '[object Array]' && value !== null && _typeof(value) === 'object' && typeof value.length === 'number' && value.length >= 0 && toStr.call(value.callee) === '[object Function]';
  48295. }
  48296. return isArgs;
  48297. };
  48298. /***/ }),
  48299. /***/ 7061:
  48300. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  48301. "use strict";
  48302. // from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
  48303. // Fedor, you are amazing.
  48304. var asn1 = __webpack_require__(7406);
  48305. exports.certificate = __webpack_require__(458);
  48306. var RSAPrivateKey = asn1.define('RSAPrivateKey', function () {
  48307. this.seq().obj(this.key('version')["int"](), this.key('modulus')["int"](), this.key('publicExponent')["int"](), this.key('privateExponent')["int"](), this.key('prime1')["int"](), this.key('prime2')["int"](), this.key('exponent1')["int"](), this.key('exponent2')["int"](), this.key('coefficient')["int"]());
  48308. });
  48309. exports.RSAPrivateKey = RSAPrivateKey;
  48310. var RSAPublicKey = asn1.define('RSAPublicKey', function () {
  48311. this.seq().obj(this.key('modulus')["int"](), this.key('publicExponent')["int"]());
  48312. });
  48313. exports.RSAPublicKey = RSAPublicKey;
  48314. var PublicKey = asn1.define('SubjectPublicKeyInfo', function () {
  48315. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  48316. });
  48317. exports.PublicKey = PublicKey;
  48318. var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function () {
  48319. this.seq().obj(this.key('algorithm').objid(), this.key('none').null_().optional(), this.key('curve').objid().optional(), this.key('params').seq().obj(this.key('p')["int"](), this.key('q')["int"](), this.key('g')["int"]()).optional());
  48320. });
  48321. var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function () {
  48322. this.seq().obj(this.key('version')["int"](), this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPrivateKey').octstr());
  48323. });
  48324. exports.PrivateKey = PrivateKeyInfo;
  48325. var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function () {
  48326. this.seq().obj(this.key('algorithm').seq().obj(this.key('id').objid(), this.key('decrypt').seq().obj(this.key('kde').seq().obj(this.key('id').objid(), this.key('kdeparams').seq().obj(this.key('salt').octstr(), this.key('iters')["int"]())), this.key('cipher').seq().obj(this.key('algo').objid(), this.key('iv').octstr()))), this.key('subjectPrivateKey').octstr());
  48327. });
  48328. exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo;
  48329. var DSAPrivateKey = asn1.define('DSAPrivateKey', function () {
  48330. this.seq().obj(this.key('version')["int"](), this.key('p')["int"](), this.key('q')["int"](), this.key('g')["int"](), this.key('pub_key')["int"](), this.key('priv_key')["int"]());
  48331. });
  48332. exports.DSAPrivateKey = DSAPrivateKey;
  48333. exports.DSAparam = asn1.define('DSAparam', function () {
  48334. this["int"]();
  48335. });
  48336. var ECPrivateKey = asn1.define('ECPrivateKey', function () {
  48337. this.seq().obj(this.key('version')["int"](), this.key('privateKey').octstr(), this.key('parameters').optional().explicit(0).use(ECParameters), this.key('publicKey').optional().explicit(1).bitstr());
  48338. });
  48339. exports.ECPrivateKey = ECPrivateKey;
  48340. var ECParameters = asn1.define('ECParameters', function () {
  48341. this.choice({
  48342. namedCurve: this.objid()
  48343. });
  48344. });
  48345. exports.signature = asn1.define('signature', function () {
  48346. this.seq().obj(this.key('r')["int"](), this.key('s')["int"]());
  48347. });
  48348. /***/ }),
  48349. /***/ 458:
  48350. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48351. "use strict";
  48352. // from https://github.com/Rantanen/node-dtls/blob/25a7dc861bda38cfeac93a723500eea4f0ac2e86/Certificate.js
  48353. // thanks to @Rantanen
  48354. var asn = __webpack_require__(7406);
  48355. var Time = asn.define('Time', function () {
  48356. this.choice({
  48357. utcTime: this.utctime(),
  48358. generalTime: this.gentime()
  48359. });
  48360. });
  48361. var AttributeTypeValue = asn.define('AttributeTypeValue', function () {
  48362. this.seq().obj(this.key('type').objid(), this.key('value').any());
  48363. });
  48364. var AlgorithmIdentifier = asn.define('AlgorithmIdentifier', function () {
  48365. this.seq().obj(this.key('algorithm').objid(), this.key('parameters').optional(), this.key('curve').objid().optional());
  48366. });
  48367. var SubjectPublicKeyInfo = asn.define('SubjectPublicKeyInfo', function () {
  48368. this.seq().obj(this.key('algorithm').use(AlgorithmIdentifier), this.key('subjectPublicKey').bitstr());
  48369. });
  48370. var RelativeDistinguishedName = asn.define('RelativeDistinguishedName', function () {
  48371. this.setof(AttributeTypeValue);
  48372. });
  48373. var RDNSequence = asn.define('RDNSequence', function () {
  48374. this.seqof(RelativeDistinguishedName);
  48375. });
  48376. var Name = asn.define('Name', function () {
  48377. this.choice({
  48378. rdnSequence: this.use(RDNSequence)
  48379. });
  48380. });
  48381. var Validity = asn.define('Validity', function () {
  48382. this.seq().obj(this.key('notBefore').use(Time), this.key('notAfter').use(Time));
  48383. });
  48384. var Extension = asn.define('Extension', function () {
  48385. this.seq().obj(this.key('extnID').objid(), this.key('critical').bool().def(false), this.key('extnValue').octstr());
  48386. });
  48387. var TBSCertificate = asn.define('TBSCertificate', function () {
  48388. this.seq().obj(this.key('version').explicit(0)["int"]().optional(), this.key('serialNumber')["int"](), this.key('signature').use(AlgorithmIdentifier), this.key('issuer').use(Name), this.key('validity').use(Validity), this.key('subject').use(Name), this.key('subjectPublicKeyInfo').use(SubjectPublicKeyInfo), this.key('issuerUniqueID').implicit(1).bitstr().optional(), this.key('subjectUniqueID').implicit(2).bitstr().optional(), this.key('extensions').explicit(3).seqof(Extension).optional());
  48389. });
  48390. var X509Certificate = asn.define('X509Certificate', function () {
  48391. this.seq().obj(this.key('tbsCertificate').use(TBSCertificate), this.key('signatureAlgorithm').use(AlgorithmIdentifier), this.key('signatureValue').bitstr());
  48392. });
  48393. module.exports = X509Certificate;
  48394. /***/ }),
  48395. /***/ 1120:
  48396. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48397. // adapted from https://github.com/apatil/pemstrip
  48398. var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m;
  48399. var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m;
  48400. var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m;
  48401. var evp = __webpack_require__(1248);
  48402. var ciphers = __webpack_require__(4881);
  48403. var Buffer = (__webpack_require__(9047).Buffer);
  48404. module.exports = function (okey, password) {
  48405. var key = okey.toString();
  48406. var match = key.match(findProc);
  48407. var decrypted;
  48408. if (!match) {
  48409. var match2 = key.match(fullRegex);
  48410. decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ''), 'base64');
  48411. } else {
  48412. var suite = 'aes' + match[1];
  48413. var iv = Buffer.from(match[2], 'hex');
  48414. var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ''), 'base64');
  48415. var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key;
  48416. var out = [];
  48417. var cipher = ciphers.createDecipheriv(suite, cipherKey, iv);
  48418. out.push(cipher.update(cipherText));
  48419. out.push(cipher["final"]());
  48420. decrypted = Buffer.concat(out);
  48421. }
  48422. var tag = key.match(startRegex)[1];
  48423. return {
  48424. tag: tag,
  48425. data: decrypted
  48426. };
  48427. };
  48428. /***/ }),
  48429. /***/ 2914:
  48430. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48431. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  48432. var asn1 = __webpack_require__(7061);
  48433. var aesid = __webpack_require__(2562);
  48434. var fixProc = __webpack_require__(1120);
  48435. var ciphers = __webpack_require__(4881);
  48436. var compat = __webpack_require__(9379);
  48437. var Buffer = (__webpack_require__(9047).Buffer);
  48438. module.exports = parseKeys;
  48439. function parseKeys(buffer) {
  48440. var password;
  48441. if (_typeof(buffer) === 'object' && !Buffer.isBuffer(buffer)) {
  48442. password = buffer.passphrase;
  48443. buffer = buffer.key;
  48444. }
  48445. if (typeof buffer === 'string') {
  48446. buffer = Buffer.from(buffer);
  48447. }
  48448. var stripped = fixProc(buffer, password);
  48449. var type = stripped.tag;
  48450. var data = stripped.data;
  48451. var subtype, ndata;
  48452. switch (type) {
  48453. case 'CERTIFICATE':
  48454. ndata = asn1.certificate.decode(data, 'der').tbsCertificate.subjectPublicKeyInfo;
  48455. // falls through
  48456. case 'PUBLIC KEY':
  48457. if (!ndata) {
  48458. ndata = asn1.PublicKey.decode(data, 'der');
  48459. }
  48460. subtype = ndata.algorithm.algorithm.join('.');
  48461. switch (subtype) {
  48462. case '1.2.840.113549.1.1.1':
  48463. return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, 'der');
  48464. case '1.2.840.10045.2.1':
  48465. ndata.subjectPrivateKey = ndata.subjectPublicKey;
  48466. return {
  48467. type: 'ec',
  48468. data: ndata
  48469. };
  48470. case '1.2.840.10040.4.1':
  48471. ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, 'der');
  48472. return {
  48473. type: 'dsa',
  48474. data: ndata.algorithm.params
  48475. };
  48476. default:
  48477. throw new Error('unknown key id ' + subtype);
  48478. }
  48479. // throw new Error('unknown key type ' + type)
  48480. case 'ENCRYPTED PRIVATE KEY':
  48481. data = asn1.EncryptedPrivateKey.decode(data, 'der');
  48482. data = decrypt(data, password);
  48483. // falls through
  48484. case 'PRIVATE KEY':
  48485. ndata = asn1.PrivateKey.decode(data, 'der');
  48486. subtype = ndata.algorithm.algorithm.join('.');
  48487. switch (subtype) {
  48488. case '1.2.840.113549.1.1.1':
  48489. return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, 'der');
  48490. case '1.2.840.10045.2.1':
  48491. return {
  48492. curve: ndata.algorithm.curve,
  48493. privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, 'der').privateKey
  48494. };
  48495. case '1.2.840.10040.4.1':
  48496. ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, 'der');
  48497. return {
  48498. type: 'dsa',
  48499. params: ndata.algorithm.params
  48500. };
  48501. default:
  48502. throw new Error('unknown key id ' + subtype);
  48503. }
  48504. // throw new Error('unknown key type ' + type)
  48505. case 'RSA PUBLIC KEY':
  48506. return asn1.RSAPublicKey.decode(data, 'der');
  48507. case 'RSA PRIVATE KEY':
  48508. return asn1.RSAPrivateKey.decode(data, 'der');
  48509. case 'DSA PRIVATE KEY':
  48510. return {
  48511. type: 'dsa',
  48512. params: asn1.DSAPrivateKey.decode(data, 'der')
  48513. };
  48514. case 'EC PRIVATE KEY':
  48515. data = asn1.ECPrivateKey.decode(data, 'der');
  48516. return {
  48517. curve: data.parameters.value,
  48518. privateKey: data.privateKey
  48519. };
  48520. default:
  48521. throw new Error('unknown key type ' + type);
  48522. }
  48523. }
  48524. parseKeys.signature = asn1.signature;
  48525. function decrypt(data, password) {
  48526. var salt = data.algorithm.decrypt.kde.kdeparams.salt;
  48527. var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10);
  48528. var algo = aesid[data.algorithm.decrypt.cipher.algo.join('.')];
  48529. var iv = data.algorithm.decrypt.cipher.iv;
  48530. var cipherText = data.subjectPrivateKey;
  48531. var keylen = parseInt(algo.split('-')[1], 10) / 8;
  48532. var key = compat.pbkdf2Sync(password, salt, iters, keylen, 'sha1');
  48533. var cipher = ciphers.createDecipheriv(algo, key, iv);
  48534. var out = [];
  48535. out.push(cipher.update(cipherText));
  48536. out.push(cipher["final"]());
  48537. return Buffer.concat(out);
  48538. }
  48539. /***/ }),
  48540. /***/ 9379:
  48541. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  48542. exports.pbkdf2 = __webpack_require__(8099);
  48543. exports.pbkdf2Sync = __webpack_require__(3180);
  48544. /***/ }),
  48545. /***/ 8099:
  48546. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48547. var Buffer = (__webpack_require__(9047).Buffer);
  48548. var checkParameters = __webpack_require__(2042);
  48549. var defaultEncoding = __webpack_require__(8994);
  48550. var sync = __webpack_require__(3180);
  48551. var toBuffer = __webpack_require__(7238);
  48552. var ZERO_BUF;
  48553. var subtle = __webpack_require__.g.crypto && __webpack_require__.g.crypto.subtle;
  48554. var toBrowser = {
  48555. sha: 'SHA-1',
  48556. 'sha-1': 'SHA-1',
  48557. sha1: 'SHA-1',
  48558. sha256: 'SHA-256',
  48559. 'sha-256': 'SHA-256',
  48560. sha384: 'SHA-384',
  48561. 'sha-384': 'SHA-384',
  48562. 'sha-512': 'SHA-512',
  48563. sha512: 'SHA-512'
  48564. };
  48565. var checks = [];
  48566. function checkNative(algo) {
  48567. if (__webpack_require__.g.process && !__webpack_require__.g.process.browser) {
  48568. return Promise.resolve(false);
  48569. }
  48570. if (!subtle || !subtle.importKey || !subtle.deriveBits) {
  48571. return Promise.resolve(false);
  48572. }
  48573. if (checks[algo] !== undefined) {
  48574. return checks[algo];
  48575. }
  48576. ZERO_BUF = ZERO_BUF || Buffer.alloc(8);
  48577. var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () {
  48578. return true;
  48579. })["catch"](function () {
  48580. return false;
  48581. });
  48582. checks[algo] = prom;
  48583. return prom;
  48584. }
  48585. var nextTick;
  48586. function getNextTick() {
  48587. if (nextTick) {
  48588. return nextTick;
  48589. }
  48590. if (__webpack_require__.g.process && __webpack_require__.g.process.nextTick) {
  48591. nextTick = __webpack_require__.g.process.nextTick;
  48592. } else if (__webpack_require__.g.queueMicrotask) {
  48593. nextTick = __webpack_require__.g.queueMicrotask;
  48594. } else if (__webpack_require__.g.setImmediate) {
  48595. nextTick = __webpack_require__.g.setImmediate;
  48596. } else {
  48597. nextTick = __webpack_require__.g.setTimeout;
  48598. }
  48599. return nextTick;
  48600. }
  48601. function browserPbkdf2(password, salt, iterations, length, algo) {
  48602. return subtle.importKey('raw', password, {
  48603. name: 'PBKDF2'
  48604. }, false, ['deriveBits']).then(function (key) {
  48605. return subtle.deriveBits({
  48606. name: 'PBKDF2',
  48607. salt: salt,
  48608. iterations: iterations,
  48609. hash: {
  48610. name: algo
  48611. }
  48612. }, key, length << 3);
  48613. }).then(function (res) {
  48614. return Buffer.from(res);
  48615. });
  48616. }
  48617. function resolvePromise(promise, callback) {
  48618. promise.then(function (out) {
  48619. getNextTick()(function () {
  48620. callback(null, out);
  48621. });
  48622. }, function (e) {
  48623. getNextTick()(function () {
  48624. callback(e);
  48625. });
  48626. });
  48627. }
  48628. module.exports = function (password, salt, iterations, keylen, digest, callback) {
  48629. if (typeof digest === 'function') {
  48630. callback = digest;
  48631. digest = undefined;
  48632. }
  48633. digest = digest || 'sha1';
  48634. var algo = toBrowser[digest.toLowerCase()];
  48635. if (!algo || typeof __webpack_require__.g.Promise !== 'function') {
  48636. getNextTick()(function () {
  48637. var out;
  48638. try {
  48639. out = sync(password, salt, iterations, keylen, digest);
  48640. } catch (e) {
  48641. return callback(e);
  48642. }
  48643. callback(null, out);
  48644. });
  48645. return;
  48646. }
  48647. checkParameters(iterations, keylen);
  48648. password = toBuffer(password, defaultEncoding, 'Password');
  48649. salt = toBuffer(salt, defaultEncoding, 'Salt');
  48650. if (typeof callback !== 'function') throw new Error('No callback provided to pbkdf2');
  48651. resolvePromise(checkNative(algo).then(function (resp) {
  48652. if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo);
  48653. return sync(password, salt, iterations, keylen, digest);
  48654. }), callback);
  48655. };
  48656. /***/ }),
  48657. /***/ 8994:
  48658. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48659. var defaultEncoding;
  48660. /* istanbul ignore next */
  48661. if (__webpack_require__.g.process && __webpack_require__.g.process.browser) {
  48662. defaultEncoding = 'utf-8';
  48663. } else if (__webpack_require__.g.process && __webpack_require__.g.process.version) {
  48664. var pVersionMajor = parseInt(({env:{}}).version.split('.')[0].slice(1), 10);
  48665. defaultEncoding = pVersionMajor >= 6 ? 'utf-8' : 'binary';
  48666. } else {
  48667. defaultEncoding = 'utf-8';
  48668. }
  48669. module.exports = defaultEncoding;
  48670. /***/ }),
  48671. /***/ 2042:
  48672. /***/ ((module) => {
  48673. var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs
  48674. module.exports = function (iterations, keylen) {
  48675. if (typeof iterations !== 'number') {
  48676. throw new TypeError('Iterations not a number');
  48677. }
  48678. if (iterations < 0) {
  48679. throw new TypeError('Bad iterations');
  48680. }
  48681. if (typeof keylen !== 'number') {
  48682. throw new TypeError('Key length not a number');
  48683. }
  48684. if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) {
  48685. /* eslint no-self-compare: 0 */
  48686. throw new TypeError('Bad key length');
  48687. }
  48688. };
  48689. /***/ }),
  48690. /***/ 3180:
  48691. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48692. var md5 = __webpack_require__(3277);
  48693. var RIPEMD160 = __webpack_require__(8100);
  48694. var sha = __webpack_require__(1806);
  48695. var Buffer = (__webpack_require__(9047).Buffer);
  48696. var checkParameters = __webpack_require__(2042);
  48697. var defaultEncoding = __webpack_require__(8994);
  48698. var toBuffer = __webpack_require__(7238);
  48699. var ZEROS = Buffer.alloc(128);
  48700. var sizes = {
  48701. md5: 16,
  48702. sha1: 20,
  48703. sha224: 28,
  48704. sha256: 32,
  48705. sha384: 48,
  48706. sha512: 64,
  48707. rmd160: 20,
  48708. ripemd160: 20
  48709. };
  48710. function Hmac(alg, key, saltLen) {
  48711. var hash = getDigest(alg);
  48712. var blocksize = alg === 'sha512' || alg === 'sha384' ? 128 : 64;
  48713. if (key.length > blocksize) {
  48714. key = hash(key);
  48715. } else if (key.length < blocksize) {
  48716. key = Buffer.concat([key, ZEROS], blocksize);
  48717. }
  48718. var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  48719. var opad = Buffer.allocUnsafe(blocksize + sizes[alg]);
  48720. for (var i = 0; i < blocksize; i++) {
  48721. ipad[i] = key[i] ^ 0x36;
  48722. opad[i] = key[i] ^ 0x5C;
  48723. }
  48724. var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4);
  48725. ipad.copy(ipad1, 0, 0, blocksize);
  48726. this.ipad1 = ipad1;
  48727. this.ipad2 = ipad;
  48728. this.opad = opad;
  48729. this.alg = alg;
  48730. this.blocksize = blocksize;
  48731. this.hash = hash;
  48732. this.size = sizes[alg];
  48733. }
  48734. Hmac.prototype.run = function (data, ipad) {
  48735. data.copy(ipad, this.blocksize);
  48736. var h = this.hash(ipad);
  48737. h.copy(this.opad, this.blocksize);
  48738. return this.hash(this.opad);
  48739. };
  48740. function getDigest(alg) {
  48741. function shaFunc(data) {
  48742. return sha(alg).update(data).digest();
  48743. }
  48744. function rmd160Func(data) {
  48745. return new RIPEMD160().update(data).digest();
  48746. }
  48747. if (alg === 'rmd160' || alg === 'ripemd160') return rmd160Func;
  48748. if (alg === 'md5') return md5;
  48749. return shaFunc;
  48750. }
  48751. function pbkdf2(password, salt, iterations, keylen, digest) {
  48752. checkParameters(iterations, keylen);
  48753. password = toBuffer(password, defaultEncoding, 'Password');
  48754. salt = toBuffer(salt, defaultEncoding, 'Salt');
  48755. digest = digest || 'sha1';
  48756. var hmac = new Hmac(digest, password, salt.length);
  48757. var DK = Buffer.allocUnsafe(keylen);
  48758. var block1 = Buffer.allocUnsafe(salt.length + 4);
  48759. salt.copy(block1, 0, 0, salt.length);
  48760. var destPos = 0;
  48761. var hLen = sizes[digest];
  48762. var l = Math.ceil(keylen / hLen);
  48763. for (var i = 1; i <= l; i++) {
  48764. block1.writeUInt32BE(i, salt.length);
  48765. var T = hmac.run(block1, hmac.ipad1);
  48766. var U = T;
  48767. for (var j = 1; j < iterations; j++) {
  48768. U = hmac.run(U, hmac.ipad2);
  48769. for (var k = 0; k < hLen; k++) {
  48770. T[k] ^= U[k];
  48771. }
  48772. }
  48773. T.copy(DK, destPos);
  48774. destPos += hLen;
  48775. }
  48776. return DK;
  48777. }
  48778. module.exports = pbkdf2;
  48779. /***/ }),
  48780. /***/ 7238:
  48781. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48782. var Buffer = (__webpack_require__(9047).Buffer);
  48783. module.exports = function (thing, encoding, name) {
  48784. if (Buffer.isBuffer(thing)) {
  48785. return thing;
  48786. } else if (typeof thing === 'string') {
  48787. return Buffer.from(thing, encoding);
  48788. } else if (ArrayBuffer.isView(thing)) {
  48789. return Buffer.from(thing.buffer);
  48790. } else {
  48791. throw new TypeError(name + ' must be a string, a Buffer, a typed array or a DataView');
  48792. }
  48793. };
  48794. /***/ }),
  48795. /***/ 2368:
  48796. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  48797. exports.publicEncrypt = __webpack_require__(2385);
  48798. exports.privateDecrypt = __webpack_require__(8752);
  48799. exports.privateEncrypt = function privateEncrypt(key, buf) {
  48800. return exports.publicEncrypt(key, buf, true);
  48801. };
  48802. exports.publicDecrypt = function publicDecrypt(key, buf) {
  48803. return exports.privateDecrypt(key, buf, true);
  48804. };
  48805. /***/ }),
  48806. /***/ 4075:
  48807. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48808. var createHash = __webpack_require__(8339);
  48809. var Buffer = (__webpack_require__(9047).Buffer);
  48810. module.exports = function (seed, len) {
  48811. var t = Buffer.alloc(0);
  48812. var i = 0;
  48813. var c;
  48814. while (t.length < len) {
  48815. c = i2ops(i++);
  48816. t = Buffer.concat([t, createHash('sha1').update(seed).update(c).digest()]);
  48817. }
  48818. return t.slice(0, len);
  48819. };
  48820. function i2ops(c) {
  48821. var out = Buffer.allocUnsafe(4);
  48822. out.writeUInt32BE(c, 0);
  48823. return out;
  48824. }
  48825. /***/ }),
  48826. /***/ 8752:
  48827. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48828. var parseKeys = __webpack_require__(2914);
  48829. var mgf = __webpack_require__(4075);
  48830. var xor = __webpack_require__(782);
  48831. var BN = __webpack_require__(6781);
  48832. var crt = __webpack_require__(4364);
  48833. var createHash = __webpack_require__(8339);
  48834. var withPublic = __webpack_require__(1675);
  48835. var Buffer = (__webpack_require__(9047).Buffer);
  48836. module.exports = function privateDecrypt(privateKey, enc, reverse) {
  48837. var padding;
  48838. if (privateKey.padding) {
  48839. padding = privateKey.padding;
  48840. } else if (reverse) {
  48841. padding = 1;
  48842. } else {
  48843. padding = 4;
  48844. }
  48845. var key = parseKeys(privateKey);
  48846. var k = key.modulus.byteLength();
  48847. if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) {
  48848. throw new Error('decryption error');
  48849. }
  48850. var msg;
  48851. if (reverse) {
  48852. msg = withPublic(new BN(enc), key);
  48853. } else {
  48854. msg = crt(enc, key);
  48855. }
  48856. var zBuffer = Buffer.alloc(k - msg.length);
  48857. msg = Buffer.concat([zBuffer, msg], k);
  48858. if (padding === 4) {
  48859. return oaep(key, msg);
  48860. } else if (padding === 1) {
  48861. return pkcs1(key, msg, reverse);
  48862. } else if (padding === 3) {
  48863. return msg;
  48864. } else {
  48865. throw new Error('unknown padding');
  48866. }
  48867. };
  48868. function oaep(key, msg) {
  48869. var k = key.modulus.byteLength();
  48870. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  48871. var hLen = iHash.length;
  48872. if (msg[0] !== 0) {
  48873. throw new Error('decryption error');
  48874. }
  48875. var maskedSeed = msg.slice(1, hLen + 1);
  48876. var maskedDb = msg.slice(hLen + 1);
  48877. var seed = xor(maskedSeed, mgf(maskedDb, hLen));
  48878. var db = xor(maskedDb, mgf(seed, k - hLen - 1));
  48879. if (compare(iHash, db.slice(0, hLen))) {
  48880. throw new Error('decryption error');
  48881. }
  48882. var i = hLen;
  48883. while (db[i] === 0) {
  48884. i++;
  48885. }
  48886. if (db[i++] !== 1) {
  48887. throw new Error('decryption error');
  48888. }
  48889. return db.slice(i);
  48890. }
  48891. function pkcs1(key, msg, reverse) {
  48892. var p1 = msg.slice(0, 2);
  48893. var i = 2;
  48894. var status = 0;
  48895. while (msg[i++] !== 0) {
  48896. if (i >= msg.length) {
  48897. status++;
  48898. break;
  48899. }
  48900. }
  48901. var ps = msg.slice(2, i - 1);
  48902. if (p1.toString('hex') !== '0002' && !reverse || p1.toString('hex') !== '0001' && reverse) {
  48903. status++;
  48904. }
  48905. if (ps.length < 8) {
  48906. status++;
  48907. }
  48908. if (status) {
  48909. throw new Error('decryption error');
  48910. }
  48911. return msg.slice(i);
  48912. }
  48913. function compare(a, b) {
  48914. a = Buffer.from(a);
  48915. b = Buffer.from(b);
  48916. var dif = 0;
  48917. var len = a.length;
  48918. if (a.length !== b.length) {
  48919. dif++;
  48920. len = Math.min(a.length, b.length);
  48921. }
  48922. var i = -1;
  48923. while (++i < len) {
  48924. dif += a[i] ^ b[i];
  48925. }
  48926. return dif;
  48927. }
  48928. /***/ }),
  48929. /***/ 2385:
  48930. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  48931. var parseKeys = __webpack_require__(2914);
  48932. var randomBytes = __webpack_require__(5760);
  48933. var createHash = __webpack_require__(8339);
  48934. var mgf = __webpack_require__(4075);
  48935. var xor = __webpack_require__(782);
  48936. var BN = __webpack_require__(6781);
  48937. var withPublic = __webpack_require__(1675);
  48938. var crt = __webpack_require__(4364);
  48939. var Buffer = (__webpack_require__(9047).Buffer);
  48940. module.exports = function publicEncrypt(publicKey, msg, reverse) {
  48941. var padding;
  48942. if (publicKey.padding) {
  48943. padding = publicKey.padding;
  48944. } else if (reverse) {
  48945. padding = 1;
  48946. } else {
  48947. padding = 4;
  48948. }
  48949. var key = parseKeys(publicKey);
  48950. var paddedMsg;
  48951. if (padding === 4) {
  48952. paddedMsg = oaep(key, msg);
  48953. } else if (padding === 1) {
  48954. paddedMsg = pkcs1(key, msg, reverse);
  48955. } else if (padding === 3) {
  48956. paddedMsg = new BN(msg);
  48957. if (paddedMsg.cmp(key.modulus) >= 0) {
  48958. throw new Error('data too long for modulus');
  48959. }
  48960. } else {
  48961. throw new Error('unknown padding');
  48962. }
  48963. if (reverse) {
  48964. return crt(paddedMsg, key);
  48965. } else {
  48966. return withPublic(paddedMsg, key);
  48967. }
  48968. };
  48969. function oaep(key, msg) {
  48970. var k = key.modulus.byteLength();
  48971. var mLen = msg.length;
  48972. var iHash = createHash('sha1').update(Buffer.alloc(0)).digest();
  48973. var hLen = iHash.length;
  48974. var hLen2 = 2 * hLen;
  48975. if (mLen > k - hLen2 - 2) {
  48976. throw new Error('message too long');
  48977. }
  48978. var ps = Buffer.alloc(k - mLen - hLen2 - 2);
  48979. var dblen = k - hLen - 1;
  48980. var seed = randomBytes(hLen);
  48981. var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen));
  48982. var maskedSeed = xor(seed, mgf(maskedDb, hLen));
  48983. return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k));
  48984. }
  48985. function pkcs1(key, msg, reverse) {
  48986. var mLen = msg.length;
  48987. var k = key.modulus.byteLength();
  48988. if (mLen > k - 11) {
  48989. throw new Error('message too long');
  48990. }
  48991. var ps;
  48992. if (reverse) {
  48993. ps = Buffer.alloc(k - mLen - 3, 0xff);
  48994. } else {
  48995. ps = nonZero(k - mLen - 3);
  48996. }
  48997. return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k));
  48998. }
  48999. function nonZero(len) {
  49000. var out = Buffer.allocUnsafe(len);
  49001. var i = 0;
  49002. var cache = randomBytes(len * 2);
  49003. var cur = 0;
  49004. var num;
  49005. while (i < len) {
  49006. if (cur === cache.length) {
  49007. cache = randomBytes(len * 2);
  49008. cur = 0;
  49009. }
  49010. num = cache[cur++];
  49011. if (num) {
  49012. out[i++] = num;
  49013. }
  49014. }
  49015. return out;
  49016. }
  49017. /***/ }),
  49018. /***/ 1675:
  49019. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  49020. var BN = __webpack_require__(6781);
  49021. var Buffer = (__webpack_require__(9047).Buffer);
  49022. function withPublic(paddedMsg, key) {
  49023. return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray());
  49024. }
  49025. module.exports = withPublic;
  49026. /***/ }),
  49027. /***/ 782:
  49028. /***/ ((module) => {
  49029. module.exports = function xor(a, b) {
  49030. var len = a.length;
  49031. var i = -1;
  49032. while (++i < len) {
  49033. a[i] ^= b[i];
  49034. }
  49035. return a;
  49036. };
  49037. /***/ }),
  49038. /***/ 5760:
  49039. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  49040. "use strict";
  49041. // limit of Crypto.getRandomValues()
  49042. // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
  49043. var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes
  49044. // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48
  49045. var MAX_UINT32 = 4294967295;
  49046. function oldBrowser() {
  49047. throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11');
  49048. }
  49049. var Buffer = (__webpack_require__(9047).Buffer);
  49050. var crypto = __webpack_require__.g.crypto || __webpack_require__.g.msCrypto;
  49051. if (crypto && crypto.getRandomValues) {
  49052. module.exports = randomBytes;
  49053. } else {
  49054. module.exports = oldBrowser;
  49055. }
  49056. function randomBytes(size, cb) {
  49057. // phantomjs needs to throw
  49058. if (size > MAX_UINT32) throw new RangeError('requested too many random bytes');
  49059. var bytes = Buffer.allocUnsafe(size);
  49060. if (size > 0) {
  49061. // getRandomValues fails on IE if size == 0
  49062. if (size > MAX_BYTES) {
  49063. // this is the max bytes crypto.getRandomValues
  49064. // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
  49065. for (var generated = 0; generated < size; generated += MAX_BYTES) {
  49066. // buffer.slice automatically checks if the end is past the end of
  49067. // the buffer so we don't have to here
  49068. crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
  49069. }
  49070. } else {
  49071. crypto.getRandomValues(bytes);
  49072. }
  49073. }
  49074. if (typeof cb === 'function') {
  49075. return ({env:{}}).nextTick(function () {
  49076. cb(null, bytes);
  49077. });
  49078. }
  49079. return bytes;
  49080. }
  49081. /***/ }),
  49082. /***/ 9301:
  49083. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  49084. "use strict";
  49085. function oldBrowser() {
  49086. throw new Error('secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11');
  49087. }
  49088. var safeBuffer = __webpack_require__(9047);
  49089. var randombytes = __webpack_require__(5760);
  49090. var Buffer = safeBuffer.Buffer;
  49091. var kBufferMaxLength = safeBuffer.kMaxLength;
  49092. var crypto = __webpack_require__.g.crypto || __webpack_require__.g.msCrypto;
  49093. var kMaxUint32 = Math.pow(2, 32) - 1;
  49094. function assertOffset(offset, length) {
  49095. if (typeof offset !== 'number' || offset !== offset) {
  49096. // eslint-disable-line no-self-compare
  49097. throw new TypeError('offset must be a number');
  49098. }
  49099. if (offset > kMaxUint32 || offset < 0) {
  49100. throw new TypeError('offset must be a uint32');
  49101. }
  49102. if (offset > kBufferMaxLength || offset > length) {
  49103. throw new RangeError('offset out of range');
  49104. }
  49105. }
  49106. function assertSize(size, offset, length) {
  49107. if (typeof size !== 'number' || size !== size) {
  49108. // eslint-disable-line no-self-compare
  49109. throw new TypeError('size must be a number');
  49110. }
  49111. if (size > kMaxUint32 || size < 0) {
  49112. throw new TypeError('size must be a uint32');
  49113. }
  49114. if (size + offset > length || size > kBufferMaxLength) {
  49115. throw new RangeError('buffer too small');
  49116. }
  49117. }
  49118. if (crypto && crypto.getRandomValues || !({env:{}}).browser) {
  49119. exports.randomFill = randomFill;
  49120. exports.randomFillSync = randomFillSync;
  49121. } else {
  49122. exports.randomFill = oldBrowser;
  49123. exports.randomFillSync = oldBrowser;
  49124. }
  49125. function randomFill(buf, offset, size, cb) {
  49126. if (!Buffer.isBuffer(buf) && !(buf instanceof __webpack_require__.g.Uint8Array)) {
  49127. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  49128. }
  49129. if (typeof offset === 'function') {
  49130. cb = offset;
  49131. offset = 0;
  49132. size = buf.length;
  49133. } else if (typeof size === 'function') {
  49134. cb = size;
  49135. size = buf.length - offset;
  49136. } else if (typeof cb !== 'function') {
  49137. throw new TypeError('"cb" argument must be a function');
  49138. }
  49139. assertOffset(offset, buf.length);
  49140. assertSize(size, offset, buf.length);
  49141. return actualFill(buf, offset, size, cb);
  49142. }
  49143. function actualFill(buf, offset, size, cb) {
  49144. if (({env:{}}).browser) {
  49145. var ourBuf = buf.buffer;
  49146. var uint = new Uint8Array(ourBuf, offset, size);
  49147. crypto.getRandomValues(uint);
  49148. if (cb) {
  49149. ({env:{}}).nextTick(function () {
  49150. cb(null, buf);
  49151. });
  49152. return;
  49153. }
  49154. return buf;
  49155. }
  49156. if (cb) {
  49157. randombytes(size, function (err, bytes) {
  49158. if (err) {
  49159. return cb(err);
  49160. }
  49161. bytes.copy(buf, offset);
  49162. cb(null, buf);
  49163. });
  49164. return;
  49165. }
  49166. var bytes = randombytes(size);
  49167. bytes.copy(buf, offset);
  49168. return buf;
  49169. }
  49170. function randomFillSync(buf, offset, size) {
  49171. if (typeof offset === 'undefined') {
  49172. offset = 0;
  49173. }
  49174. if (!Buffer.isBuffer(buf) && !(buf instanceof __webpack_require__.g.Uint8Array)) {
  49175. throw new TypeError('"buf" argument must be a Buffer or Uint8Array');
  49176. }
  49177. assertOffset(offset, buf.length);
  49178. if (size === undefined) size = buf.length - offset;
  49179. assertSize(size, offset, buf.length);
  49180. return actualFill(buf, offset, size);
  49181. }
  49182. /***/ }),
  49183. /***/ 5613:
  49184. /***/ ((module) => {
  49185. "use strict";
  49186. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  49187. function _inheritsLoose(subClass, superClass) {
  49188. subClass.prototype = Object.create(superClass.prototype);
  49189. subClass.prototype.constructor = subClass;
  49190. subClass.__proto__ = superClass;
  49191. }
  49192. var codes = {};
  49193. function createErrorType(code, message, Base) {
  49194. if (!Base) {
  49195. Base = Error;
  49196. }
  49197. function getMessage(arg1, arg2, arg3) {
  49198. if (typeof message === 'string') {
  49199. return message;
  49200. } else {
  49201. return message(arg1, arg2, arg3);
  49202. }
  49203. }
  49204. var NodeError = /*#__PURE__*/function (_Base) {
  49205. _inheritsLoose(NodeError, _Base);
  49206. function NodeError(arg1, arg2, arg3) {
  49207. return _Base.call(this, getMessage(arg1, arg2, arg3)) || this;
  49208. }
  49209. return NodeError;
  49210. }(Base);
  49211. NodeError.prototype.name = Base.name;
  49212. NodeError.prototype.code = code;
  49213. codes[code] = NodeError;
  49214. } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js
  49215. function oneOf(expected, thing) {
  49216. if (Array.isArray(expected)) {
  49217. var len = expected.length;
  49218. expected = expected.map(function (i) {
  49219. return String(i);
  49220. });
  49221. if (len > 2) {
  49222. return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(', '), ", or ") + expected[len - 1];
  49223. } else if (len === 2) {
  49224. return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]);
  49225. } else {
  49226. return "of ".concat(thing, " ").concat(expected[0]);
  49227. }
  49228. } else {
  49229. return "of ".concat(thing, " ").concat(String(expected));
  49230. }
  49231. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
  49232. function startsWith(str, search, pos) {
  49233. return str.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
  49234. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
  49235. function endsWith(str, search, this_len) {
  49236. if (this_len === undefined || this_len > str.length) {
  49237. this_len = str.length;
  49238. }
  49239. return str.substring(this_len - search.length, this_len) === search;
  49240. } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
  49241. function includes(str, search, start) {
  49242. if (typeof start !== 'number') {
  49243. start = 0;
  49244. }
  49245. if (start + search.length > str.length) {
  49246. return false;
  49247. } else {
  49248. return str.indexOf(search, start) !== -1;
  49249. }
  49250. }
  49251. createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) {
  49252. return 'The value "' + value + '" is invalid for option "' + name + '"';
  49253. }, TypeError);
  49254. createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
  49255. // determiner: 'must be' or 'must not be'
  49256. var determiner;
  49257. if (typeof expected === 'string' && startsWith(expected, 'not ')) {
  49258. determiner = 'must not be';
  49259. expected = expected.replace(/^not /, '');
  49260. } else {
  49261. determiner = 'must be';
  49262. }
  49263. var msg;
  49264. if (endsWith(name, ' argument')) {
  49265. // For cases like 'first argument'
  49266. msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  49267. } else {
  49268. var type = includes(name, '.') ? 'property' : 'argument';
  49269. msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, 'type'));
  49270. }
  49271. msg += ". Received type ".concat(_typeof(actual));
  49272. return msg;
  49273. }, TypeError);
  49274. createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF');
  49275. createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) {
  49276. return 'The ' + name + ' method is not implemented';
  49277. });
  49278. createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'Premature close');
  49279. createErrorType('ERR_STREAM_DESTROYED', function (name) {
  49280. return 'Cannot call ' + name + ' after a stream was destroyed';
  49281. });
  49282. createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times');
  49283. createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable');
  49284. createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end');
  49285. createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError);
  49286. createErrorType('ERR_UNKNOWN_ENCODING', function (arg) {
  49287. return 'Unknown encoding: ' + arg;
  49288. }, TypeError);
  49289. createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event');
  49290. module.exports.q = codes;
  49291. /***/ }),
  49292. /***/ 4611:
  49293. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  49294. "use strict";
  49295. // Copyright Joyent, Inc. and other Node contributors.
  49296. //
  49297. // Permission is hereby granted, free of charge, to any person obtaining a
  49298. // copy of this software and associated documentation files (the
  49299. // "Software"), to deal in the Software without restriction, including
  49300. // without limitation the rights to use, copy, modify, merge, publish,
  49301. // distribute, sublicense, and/or sell copies of the Software, and to permit
  49302. // persons to whom the Software is furnished to do so, subject to the
  49303. // following conditions:
  49304. //
  49305. // The above copyright notice and this permission notice shall be included
  49306. // in all copies or substantial portions of the Software.
  49307. //
  49308. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  49309. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  49310. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  49311. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  49312. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  49313. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  49314. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  49315. // a duplex stream is just a stream that is both readable and writable.
  49316. // Since JS doesn't have multiple prototypal inheritance, this class
  49317. // prototypally inherits from Readable, and then parasitically from
  49318. // Writable.
  49319. /*<replacement>*/
  49320. var objectKeys = Object.keys || function (obj) {
  49321. var keys = [];
  49322. for (var key in obj) {
  49323. keys.push(key);
  49324. }
  49325. return keys;
  49326. };
  49327. /*</replacement>*/
  49328. module.exports = Duplex;
  49329. var Readable = __webpack_require__(6751);
  49330. var Writable = __webpack_require__(679);
  49331. __webpack_require__(376)(Duplex, Readable);
  49332. {
  49333. // Allow the keys array to be GC'ed.
  49334. var keys = objectKeys(Writable.prototype);
  49335. for (var v = 0; v < keys.length; v++) {
  49336. var method = keys[v];
  49337. if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
  49338. }
  49339. }
  49340. function Duplex(options) {
  49341. if (!(this instanceof Duplex)) return new Duplex(options);
  49342. Readable.call(this, options);
  49343. Writable.call(this, options);
  49344. this.allowHalfOpen = true;
  49345. if (options) {
  49346. if (options.readable === false) this.readable = false;
  49347. if (options.writable === false) this.writable = false;
  49348. if (options.allowHalfOpen === false) {
  49349. this.allowHalfOpen = false;
  49350. this.once('end', onend);
  49351. }
  49352. }
  49353. }
  49354. Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
  49355. // making it explicit this property is not enumerable
  49356. // because otherwise some prototype manipulation in
  49357. // userland will fail
  49358. enumerable: false,
  49359. get: function get() {
  49360. return this._writableState.highWaterMark;
  49361. }
  49362. });
  49363. Object.defineProperty(Duplex.prototype, 'writableBuffer', {
  49364. // making it explicit this property is not enumerable
  49365. // because otherwise some prototype manipulation in
  49366. // userland will fail
  49367. enumerable: false,
  49368. get: function get() {
  49369. return this._writableState && this._writableState.getBuffer();
  49370. }
  49371. });
  49372. Object.defineProperty(Duplex.prototype, 'writableLength', {
  49373. // making it explicit this property is not enumerable
  49374. // because otherwise some prototype manipulation in
  49375. // userland will fail
  49376. enumerable: false,
  49377. get: function get() {
  49378. return this._writableState.length;
  49379. }
  49380. }); // the no-half-open enforcer
  49381. function onend() {
  49382. // If the writable side ended, then we're ok.
  49383. if (this._writableState.ended) return; // no more data can be written.
  49384. // But allow more writes to happen in this tick.
  49385. ({env:{}}).nextTick(onEndNT, this);
  49386. }
  49387. function onEndNT(self) {
  49388. self.end();
  49389. }
  49390. Object.defineProperty(Duplex.prototype, 'destroyed', {
  49391. // making it explicit this property is not enumerable
  49392. // because otherwise some prototype manipulation in
  49393. // userland will fail
  49394. enumerable: false,
  49395. get: function get() {
  49396. if (this._readableState === undefined || this._writableState === undefined) {
  49397. return false;
  49398. }
  49399. return this._readableState.destroyed && this._writableState.destroyed;
  49400. },
  49401. set: function set(value) {
  49402. // we ignore the value if the stream
  49403. // has not been initialized yet
  49404. if (this._readableState === undefined || this._writableState === undefined) {
  49405. return;
  49406. } // backward compatibility, the user is explicitly
  49407. // managing destroyed
  49408. this._readableState.destroyed = value;
  49409. this._writableState.destroyed = value;
  49410. }
  49411. });
  49412. /***/ }),
  49413. /***/ 3684:
  49414. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  49415. "use strict";
  49416. // Copyright Joyent, Inc. and other Node contributors.
  49417. //
  49418. // Permission is hereby granted, free of charge, to any person obtaining a
  49419. // copy of this software and associated documentation files (the
  49420. // "Software"), to deal in the Software without restriction, including
  49421. // without limitation the rights to use, copy, modify, merge, publish,
  49422. // distribute, sublicense, and/or sell copies of the Software, and to permit
  49423. // persons to whom the Software is furnished to do so, subject to the
  49424. // following conditions:
  49425. //
  49426. // The above copyright notice and this permission notice shall be included
  49427. // in all copies or substantial portions of the Software.
  49428. //
  49429. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  49430. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  49431. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  49432. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  49433. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  49434. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  49435. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  49436. // a passthrough stream.
  49437. // basically just the most minimal sort of Transform stream.
  49438. // Every written chunk gets output as-is.
  49439. module.exports = PassThrough;
  49440. var Transform = __webpack_require__(4951);
  49441. __webpack_require__(376)(PassThrough, Transform);
  49442. function PassThrough(options) {
  49443. if (!(this instanceof PassThrough)) return new PassThrough(options);
  49444. Transform.call(this, options);
  49445. }
  49446. PassThrough.prototype._transform = function (chunk, encoding, cb) {
  49447. cb(null, chunk);
  49448. };
  49449. /***/ }),
  49450. /***/ 6751:
  49451. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  49452. "use strict";
  49453. // Copyright Joyent, Inc. and other Node contributors.
  49454. //
  49455. // Permission is hereby granted, free of charge, to any person obtaining a
  49456. // copy of this software and associated documentation files (the
  49457. // "Software"), to deal in the Software without restriction, including
  49458. // without limitation the rights to use, copy, modify, merge, publish,
  49459. // distribute, sublicense, and/or sell copies of the Software, and to permit
  49460. // persons to whom the Software is furnished to do so, subject to the
  49461. // following conditions:
  49462. //
  49463. // The above copyright notice and this permission notice shall be included
  49464. // in all copies or substantial portions of the Software.
  49465. //
  49466. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  49467. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  49468. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  49469. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  49470. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  49471. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  49472. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  49473. module.exports = Readable;
  49474. /*<replacement>*/
  49475. var Duplex;
  49476. /*</replacement>*/
  49477. Readable.ReadableState = ReadableState;
  49478. /*<replacement>*/
  49479. var EE = (__webpack_require__(9620).EventEmitter);
  49480. var EElistenerCount = function EElistenerCount(emitter, type) {
  49481. return emitter.listeners(type).length;
  49482. };
  49483. /*</replacement>*/
  49484. /*<replacement>*/
  49485. var Stream = __webpack_require__(6054);
  49486. /*</replacement>*/
  49487. var Buffer = (__webpack_require__(365).Buffer);
  49488. var OurUint8Array = __webpack_require__.g.Uint8Array || function () {};
  49489. function _uint8ArrayToBuffer(chunk) {
  49490. return Buffer.from(chunk);
  49491. }
  49492. function _isUint8Array(obj) {
  49493. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  49494. }
  49495. /*<replacement>*/
  49496. var debugUtil = __webpack_require__(4616);
  49497. var debug;
  49498. if (debugUtil && debugUtil.debuglog) {
  49499. debug = debugUtil.debuglog('stream');
  49500. } else {
  49501. debug = function debug() {};
  49502. }
  49503. /*</replacement>*/
  49504. var BufferList = __webpack_require__(1843);
  49505. var destroyImpl = __webpack_require__(4798);
  49506. var _require = __webpack_require__(6876),
  49507. getHighWaterMark = _require.getHighWaterMark;
  49508. var _require$codes = (__webpack_require__(5613)/* .codes */ .q),
  49509. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  49510. ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF,
  49511. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  49512. ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance.
  49513. var StringDecoder;
  49514. var createReadableStreamAsyncIterator;
  49515. var from;
  49516. __webpack_require__(376)(Readable, Stream);
  49517. var errorOrDestroy = destroyImpl.errorOrDestroy;
  49518. var kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume'];
  49519. function prependListener(emitter, event, fn) {
  49520. // Sadly this is not cacheable as some libraries bundle their own
  49521. // event emitter implementation with them.
  49522. if (typeof emitter.prependListener === 'function') return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any
  49523. // userland ones. NEVER DO THIS. This is here only because this code needs
  49524. // to continue to work with older versions of Node.js that do not include
  49525. // the prependListener() method. The goal is to eventually remove this hack.
  49526. if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]];
  49527. }
  49528. function ReadableState(options, stream, isDuplex) {
  49529. Duplex = Duplex || __webpack_require__(4611);
  49530. options = options || {}; // Duplex streams are both readable and writable, but share
  49531. // the same options object.
  49532. // However, some cases require setting options to different
  49533. // values for the readable and the writable sides of the duplex stream.
  49534. // These options can be provided separately as readableXXX and writableXXX.
  49535. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to
  49536. // make all the buffer merging and length checks go away
  49537. this.objectMode = !!options.objectMode;
  49538. if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer
  49539. // Note: 0 is a valid value, means "don't call _read preemptively ever"
  49540. this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex); // A linked list is used to store data chunks instead of an array because the
  49541. // linked list can remove elements from the beginning faster than
  49542. // array.shift()
  49543. this.buffer = new BufferList();
  49544. this.length = 0;
  49545. this.pipes = null;
  49546. this.pipesCount = 0;
  49547. this.flowing = null;
  49548. this.ended = false;
  49549. this.endEmitted = false;
  49550. this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted
  49551. // immediately, or on a later tick. We set this to true at first, because
  49552. // any actions that shouldn't happen until "later" should generally also
  49553. // not happen before the first read call.
  49554. this.sync = true; // whenever we return null, then we set a flag to say
  49555. // that we're awaiting a 'readable' event emission.
  49556. this.needReadable = false;
  49557. this.emittedReadable = false;
  49558. this.readableListening = false;
  49559. this.resumeScheduled = false;
  49560. this.paused = true; // Should close be emitted on destroy. Defaults to true.
  49561. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish')
  49562. this.autoDestroy = !!options.autoDestroy; // has it been destroyed
  49563. this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string
  49564. // encoding is 'binary' so we have to make this configurable.
  49565. // Everything else in the universe uses 'utf8', though.
  49566. this.defaultEncoding = options.defaultEncoding || 'utf8'; // the number of writers that are awaiting a drain event in .pipe()s
  49567. this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled
  49568. this.readingMore = false;
  49569. this.decoder = null;
  49570. this.encoding = null;
  49571. if (options.encoding) {
  49572. if (!StringDecoder) StringDecoder = (__webpack_require__(113)/* .StringDecoder */ .s);
  49573. this.decoder = new StringDecoder(options.encoding);
  49574. this.encoding = options.encoding;
  49575. }
  49576. }
  49577. function Readable(options) {
  49578. Duplex = Duplex || __webpack_require__(4611);
  49579. if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside
  49580. // the ReadableState constructor, at least with V8 6.5
  49581. var isDuplex = this instanceof Duplex;
  49582. this._readableState = new ReadableState(options, this, isDuplex); // legacy
  49583. this.readable = true;
  49584. if (options) {
  49585. if (typeof options.read === 'function') this._read = options.read;
  49586. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  49587. }
  49588. Stream.call(this);
  49589. }
  49590. Object.defineProperty(Readable.prototype, 'destroyed', {
  49591. // making it explicit this property is not enumerable
  49592. // because otherwise some prototype manipulation in
  49593. // userland will fail
  49594. enumerable: false,
  49595. get: function get() {
  49596. if (this._readableState === undefined) {
  49597. return false;
  49598. }
  49599. return this._readableState.destroyed;
  49600. },
  49601. set: function set(value) {
  49602. // we ignore the value if the stream
  49603. // has not been initialized yet
  49604. if (!this._readableState) {
  49605. return;
  49606. } // backward compatibility, the user is explicitly
  49607. // managing destroyed
  49608. this._readableState.destroyed = value;
  49609. }
  49610. });
  49611. Readable.prototype.destroy = destroyImpl.destroy;
  49612. Readable.prototype._undestroy = destroyImpl.undestroy;
  49613. Readable.prototype._destroy = function (err, cb) {
  49614. cb(err);
  49615. }; // Manually shove something into the read() buffer.
  49616. // This returns true if the highWaterMark has not been hit yet,
  49617. // similar to how Writable.write() returns true if you should
  49618. // write() some more.
  49619. Readable.prototype.push = function (chunk, encoding) {
  49620. var state = this._readableState;
  49621. var skipChunkCheck;
  49622. if (!state.objectMode) {
  49623. if (typeof chunk === 'string') {
  49624. encoding = encoding || state.defaultEncoding;
  49625. if (encoding !== state.encoding) {
  49626. chunk = Buffer.from(chunk, encoding);
  49627. encoding = '';
  49628. }
  49629. skipChunkCheck = true;
  49630. }
  49631. } else {
  49632. skipChunkCheck = true;
  49633. }
  49634. return readableAddChunk(this, chunk, encoding, false, skipChunkCheck);
  49635. }; // Unshift should *always* be something directly out of read()
  49636. Readable.prototype.unshift = function (chunk) {
  49637. return readableAddChunk(this, chunk, null, true, false);
  49638. };
  49639. function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
  49640. debug('readableAddChunk', chunk);
  49641. var state = stream._readableState;
  49642. if (chunk === null) {
  49643. state.reading = false;
  49644. onEofChunk(stream, state);
  49645. } else {
  49646. var er;
  49647. if (!skipChunkCheck) er = chunkInvalid(state, chunk);
  49648. if (er) {
  49649. errorOrDestroy(stream, er);
  49650. } else if (state.objectMode || chunk && chunk.length > 0) {
  49651. if (typeof chunk !== 'string' && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) {
  49652. chunk = _uint8ArrayToBuffer(chunk);
  49653. }
  49654. if (addToFront) {
  49655. if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true);
  49656. } else if (state.ended) {
  49657. errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
  49658. } else if (state.destroyed) {
  49659. return false;
  49660. } else {
  49661. state.reading = false;
  49662. if (state.decoder && !encoding) {
  49663. chunk = state.decoder.write(chunk);
  49664. if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state);
  49665. } else {
  49666. addChunk(stream, state, chunk, false);
  49667. }
  49668. }
  49669. } else if (!addToFront) {
  49670. state.reading = false;
  49671. maybeReadMore(stream, state);
  49672. }
  49673. } // We can push more data if we are below the highWaterMark.
  49674. // Also, if we have no data yet, we can stand some more bytes.
  49675. // This is to work around cases where hwm=0, such as the repl.
  49676. return !state.ended && (state.length < state.highWaterMark || state.length === 0);
  49677. }
  49678. function addChunk(stream, state, chunk, addToFront) {
  49679. if (state.flowing && state.length === 0 && !state.sync) {
  49680. state.awaitDrain = 0;
  49681. stream.emit('data', chunk);
  49682. } else {
  49683. // update the buffer info.
  49684. state.length += state.objectMode ? 1 : chunk.length;
  49685. if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk);
  49686. if (state.needReadable) emitReadable(stream);
  49687. }
  49688. maybeReadMore(stream, state);
  49689. }
  49690. function chunkInvalid(state, chunk) {
  49691. var er;
  49692. if (!_isUint8Array(chunk) && typeof chunk !== 'string' && chunk !== undefined && !state.objectMode) {
  49693. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer', 'Uint8Array'], chunk);
  49694. }
  49695. return er;
  49696. }
  49697. Readable.prototype.isPaused = function () {
  49698. return this._readableState.flowing === false;
  49699. }; // backwards compatibility.
  49700. Readable.prototype.setEncoding = function (enc) {
  49701. if (!StringDecoder) StringDecoder = (__webpack_require__(113)/* .StringDecoder */ .s);
  49702. var decoder = new StringDecoder(enc);
  49703. this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8
  49704. this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers:
  49705. var p = this._readableState.buffer.head;
  49706. var content = '';
  49707. while (p !== null) {
  49708. content += decoder.write(p.data);
  49709. p = p.next;
  49710. }
  49711. this._readableState.buffer.clear();
  49712. if (content !== '') this._readableState.buffer.push(content);
  49713. this._readableState.length = content.length;
  49714. return this;
  49715. }; // Don't raise the hwm > 1GB
  49716. var MAX_HWM = 0x40000000;
  49717. function computeNewHighWaterMark(n) {
  49718. if (n >= MAX_HWM) {
  49719. // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE.
  49720. n = MAX_HWM;
  49721. } else {
  49722. // Get the next highest power of 2 to prevent increasing hwm excessively in
  49723. // tiny amounts
  49724. n--;
  49725. n |= n >>> 1;
  49726. n |= n >>> 2;
  49727. n |= n >>> 4;
  49728. n |= n >>> 8;
  49729. n |= n >>> 16;
  49730. n++;
  49731. }
  49732. return n;
  49733. } // This function is designed to be inlinable, so please take care when making
  49734. // changes to the function body.
  49735. function howMuchToRead(n, state) {
  49736. if (n <= 0 || state.length === 0 && state.ended) return 0;
  49737. if (state.objectMode) return 1;
  49738. if (n !== n) {
  49739. // Only flow one buffer at a time
  49740. if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length;
  49741. } // If we're asking for more than the current hwm, then raise the hwm.
  49742. if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n);
  49743. if (n <= state.length) return n; // Don't have enough
  49744. if (!state.ended) {
  49745. state.needReadable = true;
  49746. return 0;
  49747. }
  49748. return state.length;
  49749. } // you can override either this method, or the async _read(n) below.
  49750. Readable.prototype.read = function (n) {
  49751. debug('read', n);
  49752. n = parseInt(n, 10);
  49753. var state = this._readableState;
  49754. var nOrig = n;
  49755. if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we
  49756. // already have a bunch of data in the buffer, then just trigger
  49757. // the 'readable' event and move on.
  49758. if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) {
  49759. debug('read: emitReadable', state.length, state.ended);
  49760. if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this);
  49761. return null;
  49762. }
  49763. n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up.
  49764. if (n === 0 && state.ended) {
  49765. if (state.length === 0) endReadable(this);
  49766. return null;
  49767. } // All the actual chunk generation logic needs to be
  49768. // *below* the call to _read. The reason is that in certain
  49769. // synthetic stream cases, such as passthrough streams, _read
  49770. // may be a completely synchronous operation which may change
  49771. // the state of the read buffer, providing enough data when
  49772. // before there was *not* enough.
  49773. //
  49774. // So, the steps are:
  49775. // 1. Figure out what the state of things will be after we do
  49776. // a read from the buffer.
  49777. //
  49778. // 2. If that resulting state will trigger a _read, then call _read.
  49779. // Note that this may be asynchronous, or synchronous. Yes, it is
  49780. // deeply ugly to write APIs this way, but that still doesn't mean
  49781. // that the Readable class should behave improperly, as streams are
  49782. // designed to be sync/async agnostic.
  49783. // Take note if the _read call is sync or async (ie, if the read call
  49784. // has returned yet), so that we know whether or not it's safe to emit
  49785. // 'readable' etc.
  49786. //
  49787. // 3. Actually pull the requested chunks out of the buffer and return.
  49788. // if we need a readable event, then we need to do some reading.
  49789. var doRead = state.needReadable;
  49790. debug('need readable', doRead); // if we currently have less than the highWaterMark, then also read some
  49791. if (state.length === 0 || state.length - n < state.highWaterMark) {
  49792. doRead = true;
  49793. debug('length less than watermark', doRead);
  49794. } // however, if we've ended, then there's no point, and if we're already
  49795. // reading, then it's unnecessary.
  49796. if (state.ended || state.reading) {
  49797. doRead = false;
  49798. debug('reading or ended', doRead);
  49799. } else if (doRead) {
  49800. debug('do read');
  49801. state.reading = true;
  49802. state.sync = true; // if the length is currently zero, then we *need* a readable event.
  49803. if (state.length === 0) state.needReadable = true; // call internal read method
  49804. this._read(state.highWaterMark);
  49805. state.sync = false; // If _read pushed data synchronously, then `reading` will be false,
  49806. // and we need to re-evaluate how much data we can return to the user.
  49807. if (!state.reading) n = howMuchToRead(nOrig, state);
  49808. }
  49809. var ret;
  49810. if (n > 0) ret = fromList(n, state);else ret = null;
  49811. if (ret === null) {
  49812. state.needReadable = state.length <= state.highWaterMark;
  49813. n = 0;
  49814. } else {
  49815. state.length -= n;
  49816. state.awaitDrain = 0;
  49817. }
  49818. if (state.length === 0) {
  49819. // If we have nothing in the buffer, then we want to know
  49820. // as soon as we *do* get something into the buffer.
  49821. if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick.
  49822. if (nOrig !== n && state.ended) endReadable(this);
  49823. }
  49824. if (ret !== null) this.emit('data', ret);
  49825. return ret;
  49826. };
  49827. function onEofChunk(stream, state) {
  49828. debug('onEofChunk');
  49829. if (state.ended) return;
  49830. if (state.decoder) {
  49831. var chunk = state.decoder.end();
  49832. if (chunk && chunk.length) {
  49833. state.buffer.push(chunk);
  49834. state.length += state.objectMode ? 1 : chunk.length;
  49835. }
  49836. }
  49837. state.ended = true;
  49838. if (state.sync) {
  49839. // if we are sync, wait until next tick to emit the data.
  49840. // Otherwise we risk emitting data in the flow()
  49841. // the readable code triggers during a read() call
  49842. emitReadable(stream);
  49843. } else {
  49844. // emit 'readable' now to make sure it gets picked up.
  49845. state.needReadable = false;
  49846. if (!state.emittedReadable) {
  49847. state.emittedReadable = true;
  49848. emitReadable_(stream);
  49849. }
  49850. }
  49851. } // Don't emit readable right away in sync mode, because this can trigger
  49852. // another read() call => stack overflow. This way, it might trigger
  49853. // a nextTick recursion warning, but that's not so bad.
  49854. function emitReadable(stream) {
  49855. var state = stream._readableState;
  49856. debug('emitReadable', state.needReadable, state.emittedReadable);
  49857. state.needReadable = false;
  49858. if (!state.emittedReadable) {
  49859. debug('emitReadable', state.flowing);
  49860. state.emittedReadable = true;
  49861. ({env:{}}).nextTick(emitReadable_, stream);
  49862. }
  49863. }
  49864. function emitReadable_(stream) {
  49865. var state = stream._readableState;
  49866. debug('emitReadable_', state.destroyed, state.length, state.ended);
  49867. if (!state.destroyed && (state.length || state.ended)) {
  49868. stream.emit('readable');
  49869. state.emittedReadable = false;
  49870. } // The stream needs another readable event if
  49871. // 1. It is not flowing, as the flow mechanism will take
  49872. // care of it.
  49873. // 2. It is not ended.
  49874. // 3. It is below the highWaterMark, so we can schedule
  49875. // another readable later.
  49876. state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark;
  49877. flow(stream);
  49878. } // at this point, the user has presumably seen the 'readable' event,
  49879. // and called read() to consume some data. that may have triggered
  49880. // in turn another _read(n) call, in which case reading = true if
  49881. // it's in progress.
  49882. // However, if we're not ended, or reading, and the length < hwm,
  49883. // then go ahead and try to read some more preemptively.
  49884. function maybeReadMore(stream, state) {
  49885. if (!state.readingMore) {
  49886. state.readingMore = true;
  49887. ({env:{}}).nextTick(maybeReadMore_, stream, state);
  49888. }
  49889. }
  49890. function maybeReadMore_(stream, state) {
  49891. // Attempt to read more data if we should.
  49892. //
  49893. // The conditions for reading more data are (one of):
  49894. // - Not enough data buffered (state.length < state.highWaterMark). The loop
  49895. // is responsible for filling the buffer with enough data if such data
  49896. // is available. If highWaterMark is 0 and we are not in the flowing mode
  49897. // we should _not_ attempt to buffer any extra data. We'll get more data
  49898. // when the stream consumer calls read() instead.
  49899. // - No data in the buffer, and the stream is in flowing mode. In this mode
  49900. // the loop below is responsible for ensuring read() is called. Failing to
  49901. // call read here would abort the flow and there's no other mechanism for
  49902. // continuing the flow if the stream consumer has just subscribed to the
  49903. // 'data' event.
  49904. //
  49905. // In addition to the above conditions to keep reading data, the following
  49906. // conditions prevent the data from being read:
  49907. // - The stream has ended (state.ended).
  49908. // - There is already a pending 'read' operation (state.reading). This is a
  49909. // case where the the stream has called the implementation defined _read()
  49910. // method, but they are processing the call asynchronously and have _not_
  49911. // called push() with new data. In this case we skip performing more
  49912. // read()s. The execution ends in this method again after the _read() ends
  49913. // up calling push() with more data.
  49914. while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) {
  49915. var len = state.length;
  49916. debug('maybeReadMore read 0');
  49917. stream.read(0);
  49918. if (len === state.length) // didn't get any data, stop spinning.
  49919. break;
  49920. }
  49921. state.readingMore = false;
  49922. } // abstract method. to be overridden in specific implementation classes.
  49923. // call cb(er, data) where data is <= n in length.
  49924. // for virtual (non-string, non-buffer) streams, "length" is somewhat
  49925. // arbitrary, and perhaps not very meaningful.
  49926. Readable.prototype._read = function (n) {
  49927. errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED('_read()'));
  49928. };
  49929. Readable.prototype.pipe = function (dest, pipeOpts) {
  49930. var src = this;
  49931. var state = this._readableState;
  49932. switch (state.pipesCount) {
  49933. case 0:
  49934. state.pipes = dest;
  49935. break;
  49936. case 1:
  49937. state.pipes = [state.pipes, dest];
  49938. break;
  49939. default:
  49940. state.pipes.push(dest);
  49941. break;
  49942. }
  49943. state.pipesCount += 1;
  49944. debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
  49945. var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== ({env:{}}).stdout && dest !== ({env:{}}).stderr;
  49946. var endFn = doEnd ? onend : unpipe;
  49947. if (state.endEmitted) ({env:{}}).nextTick(endFn);else src.once('end', endFn);
  49948. dest.on('unpipe', onunpipe);
  49949. function onunpipe(readable, unpipeInfo) {
  49950. debug('onunpipe');
  49951. if (readable === src) {
  49952. if (unpipeInfo && unpipeInfo.hasUnpiped === false) {
  49953. unpipeInfo.hasUnpiped = true;
  49954. cleanup();
  49955. }
  49956. }
  49957. }
  49958. function onend() {
  49959. debug('onend');
  49960. dest.end();
  49961. } // when the dest drains, it reduces the awaitDrain counter
  49962. // on the source. This would be more elegant with a .once()
  49963. // handler in flow(), but adding and removing repeatedly is
  49964. // too slow.
  49965. var ondrain = pipeOnDrain(src);
  49966. dest.on('drain', ondrain);
  49967. var cleanedUp = false;
  49968. function cleanup() {
  49969. debug('cleanup'); // cleanup event handlers once the pipe is broken
  49970. dest.removeListener('close', onclose);
  49971. dest.removeListener('finish', onfinish);
  49972. dest.removeListener('drain', ondrain);
  49973. dest.removeListener('error', onerror);
  49974. dest.removeListener('unpipe', onunpipe);
  49975. src.removeListener('end', onend);
  49976. src.removeListener('end', unpipe);
  49977. src.removeListener('data', ondata);
  49978. cleanedUp = true; // if the reader is waiting for a drain event from this
  49979. // specific writer, then it would cause it to never start
  49980. // flowing again.
  49981. // So, if this is awaiting a drain, then we just call it now.
  49982. // If we don't know, then assume that we are waiting for one.
  49983. if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain();
  49984. }
  49985. src.on('data', ondata);
  49986. function ondata(chunk) {
  49987. debug('ondata');
  49988. var ret = dest.write(chunk);
  49989. debug('dest.write', ret);
  49990. if (ret === false) {
  49991. // If the user unpiped during `dest.write()`, it is possible
  49992. // to get stuck in a permanently paused state if that write
  49993. // also returned false.
  49994. // => Check whether `dest` is still a piping destination.
  49995. if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) {
  49996. debug('false write response, pause', state.awaitDrain);
  49997. state.awaitDrain++;
  49998. }
  49999. src.pause();
  50000. }
  50001. } // if the dest has an error, then stop piping into it.
  50002. // however, don't suppress the throwing behavior for this.
  50003. function onerror(er) {
  50004. debug('onerror', er);
  50005. unpipe();
  50006. dest.removeListener('error', onerror);
  50007. if (EElistenerCount(dest, 'error') === 0) errorOrDestroy(dest, er);
  50008. } // Make sure our error handler is attached before userland ones.
  50009. prependListener(dest, 'error', onerror); // Both close and finish should trigger unpipe, but only once.
  50010. function onclose() {
  50011. dest.removeListener('finish', onfinish);
  50012. unpipe();
  50013. }
  50014. dest.once('close', onclose);
  50015. function onfinish() {
  50016. debug('onfinish');
  50017. dest.removeListener('close', onclose);
  50018. unpipe();
  50019. }
  50020. dest.once('finish', onfinish);
  50021. function unpipe() {
  50022. debug('unpipe');
  50023. src.unpipe(dest);
  50024. } // tell the dest that it's being piped to
  50025. dest.emit('pipe', src); // start the flow if it hasn't been started already.
  50026. if (!state.flowing) {
  50027. debug('pipe resume');
  50028. src.resume();
  50029. }
  50030. return dest;
  50031. };
  50032. function pipeOnDrain(src) {
  50033. return function pipeOnDrainFunctionResult() {
  50034. var state = src._readableState;
  50035. debug('pipeOnDrain', state.awaitDrain);
  50036. if (state.awaitDrain) state.awaitDrain--;
  50037. if (state.awaitDrain === 0 && EElistenerCount(src, 'data')) {
  50038. state.flowing = true;
  50039. flow(src);
  50040. }
  50041. };
  50042. }
  50043. Readable.prototype.unpipe = function (dest) {
  50044. var state = this._readableState;
  50045. var unpipeInfo = {
  50046. hasUnpiped: false
  50047. }; // if we're not piping anywhere, then do nothing.
  50048. if (state.pipesCount === 0) return this; // just one destination. most common case.
  50049. if (state.pipesCount === 1) {
  50050. // passed in one, but it's not the right one.
  50051. if (dest && dest !== state.pipes) return this;
  50052. if (!dest) dest = state.pipes; // got a match.
  50053. state.pipes = null;
  50054. state.pipesCount = 0;
  50055. state.flowing = false;
  50056. if (dest) dest.emit('unpipe', this, unpipeInfo);
  50057. return this;
  50058. } // slow case. multiple pipe destinations.
  50059. if (!dest) {
  50060. // remove all.
  50061. var dests = state.pipes;
  50062. var len = state.pipesCount;
  50063. state.pipes = null;
  50064. state.pipesCount = 0;
  50065. state.flowing = false;
  50066. for (var i = 0; i < len; i++) {
  50067. dests[i].emit('unpipe', this, {
  50068. hasUnpiped: false
  50069. });
  50070. }
  50071. return this;
  50072. } // try to find the right one.
  50073. var index = indexOf(state.pipes, dest);
  50074. if (index === -1) return this;
  50075. state.pipes.splice(index, 1);
  50076. state.pipesCount -= 1;
  50077. if (state.pipesCount === 1) state.pipes = state.pipes[0];
  50078. dest.emit('unpipe', this, unpipeInfo);
  50079. return this;
  50080. }; // set up data events if they are asked for
  50081. // Ensure readable listeners eventually get something
  50082. Readable.prototype.on = function (ev, fn) {
  50083. var res = Stream.prototype.on.call(this, ev, fn);
  50084. var state = this._readableState;
  50085. if (ev === 'data') {
  50086. // update readableListening so that resume() may be a no-op
  50087. // a few lines down. This is needed to support once('readable').
  50088. state.readableListening = this.listenerCount('readable') > 0; // Try start flowing on next tick if stream isn't explicitly paused
  50089. if (state.flowing !== false) this.resume();
  50090. } else if (ev === 'readable') {
  50091. if (!state.endEmitted && !state.readableListening) {
  50092. state.readableListening = state.needReadable = true;
  50093. state.flowing = false;
  50094. state.emittedReadable = false;
  50095. debug('on readable', state.length, state.reading);
  50096. if (state.length) {
  50097. emitReadable(this);
  50098. } else if (!state.reading) {
  50099. ({env:{}}).nextTick(nReadingNextTick, this);
  50100. }
  50101. }
  50102. }
  50103. return res;
  50104. };
  50105. Readable.prototype.addListener = Readable.prototype.on;
  50106. Readable.prototype.removeListener = function (ev, fn) {
  50107. var res = Stream.prototype.removeListener.call(this, ev, fn);
  50108. if (ev === 'readable') {
  50109. // We need to check if there is someone still listening to
  50110. // readable and reset the state. However this needs to happen
  50111. // after readable has been emitted but before I/O (nextTick) to
  50112. // support once('readable', fn) cycles. This means that calling
  50113. // resume within the same tick will have no
  50114. // effect.
  50115. ({env:{}}).nextTick(updateReadableListening, this);
  50116. }
  50117. return res;
  50118. };
  50119. Readable.prototype.removeAllListeners = function (ev) {
  50120. var res = Stream.prototype.removeAllListeners.apply(this, arguments);
  50121. if (ev === 'readable' || ev === undefined) {
  50122. // We need to check if there is someone still listening to
  50123. // readable and reset the state. However this needs to happen
  50124. // after readable has been emitted but before I/O (nextTick) to
  50125. // support once('readable', fn) cycles. This means that calling
  50126. // resume within the same tick will have no
  50127. // effect.
  50128. ({env:{}}).nextTick(updateReadableListening, this);
  50129. }
  50130. return res;
  50131. };
  50132. function updateReadableListening(self) {
  50133. var state = self._readableState;
  50134. state.readableListening = self.listenerCount('readable') > 0;
  50135. if (state.resumeScheduled && !state.paused) {
  50136. // flowing needs to be set to true now, otherwise
  50137. // the upcoming resume will not flow.
  50138. state.flowing = true; // crude way to check if we should resume
  50139. } else if (self.listenerCount('data') > 0) {
  50140. self.resume();
  50141. }
  50142. }
  50143. function nReadingNextTick(self) {
  50144. debug('readable nexttick read 0');
  50145. self.read(0);
  50146. } // pause() and resume() are remnants of the legacy readable stream API
  50147. // If the user uses them, then switch into old mode.
  50148. Readable.prototype.resume = function () {
  50149. var state = this._readableState;
  50150. if (!state.flowing) {
  50151. debug('resume'); // we flow only if there is no one listening
  50152. // for readable, but we still have to call
  50153. // resume()
  50154. state.flowing = !state.readableListening;
  50155. resume(this, state);
  50156. }
  50157. state.paused = false;
  50158. return this;
  50159. };
  50160. function resume(stream, state) {
  50161. if (!state.resumeScheduled) {
  50162. state.resumeScheduled = true;
  50163. ({env:{}}).nextTick(resume_, stream, state);
  50164. }
  50165. }
  50166. function resume_(stream, state) {
  50167. debug('resume', state.reading);
  50168. if (!state.reading) {
  50169. stream.read(0);
  50170. }
  50171. state.resumeScheduled = false;
  50172. stream.emit('resume');
  50173. flow(stream);
  50174. if (state.flowing && !state.reading) stream.read(0);
  50175. }
  50176. Readable.prototype.pause = function () {
  50177. debug('call pause flowing=%j', this._readableState.flowing);
  50178. if (this._readableState.flowing !== false) {
  50179. debug('pause');
  50180. this._readableState.flowing = false;
  50181. this.emit('pause');
  50182. }
  50183. this._readableState.paused = true;
  50184. return this;
  50185. };
  50186. function flow(stream) {
  50187. var state = stream._readableState;
  50188. debug('flow', state.flowing);
  50189. while (state.flowing && stream.read() !== null) {
  50190. ;
  50191. }
  50192. } // wrap an old-style stream as the async data source.
  50193. // This is *not* part of the readable stream interface.
  50194. // It is an ugly unfortunate mess of history.
  50195. Readable.prototype.wrap = function (stream) {
  50196. var _this = this;
  50197. var state = this._readableState;
  50198. var paused = false;
  50199. stream.on('end', function () {
  50200. debug('wrapped end');
  50201. if (state.decoder && !state.ended) {
  50202. var chunk = state.decoder.end();
  50203. if (chunk && chunk.length) _this.push(chunk);
  50204. }
  50205. _this.push(null);
  50206. });
  50207. stream.on('data', function (chunk) {
  50208. debug('wrapped data');
  50209. if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode
  50210. if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return;
  50211. var ret = _this.push(chunk);
  50212. if (!ret) {
  50213. paused = true;
  50214. stream.pause();
  50215. }
  50216. }); // proxy all the other methods.
  50217. // important when wrapping filters and duplexes.
  50218. for (var i in stream) {
  50219. if (this[i] === undefined && typeof stream[i] === 'function') {
  50220. this[i] = function methodWrap(method) {
  50221. return function methodWrapReturnFunction() {
  50222. return stream[method].apply(stream, arguments);
  50223. };
  50224. }(i);
  50225. }
  50226. } // proxy certain important events.
  50227. for (var n = 0; n < kProxyEvents.length; n++) {
  50228. stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
  50229. } // when we try to consume some more bytes, simply unpause the
  50230. // underlying stream.
  50231. this._read = function (n) {
  50232. debug('wrapped _read', n);
  50233. if (paused) {
  50234. paused = false;
  50235. stream.resume();
  50236. }
  50237. };
  50238. return this;
  50239. };
  50240. if (typeof Symbol === 'function') {
  50241. Readable.prototype[Symbol.asyncIterator] = function () {
  50242. if (createReadableStreamAsyncIterator === undefined) {
  50243. createReadableStreamAsyncIterator = __webpack_require__(7673);
  50244. }
  50245. return createReadableStreamAsyncIterator(this);
  50246. };
  50247. }
  50248. Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
  50249. // making it explicit this property is not enumerable
  50250. // because otherwise some prototype manipulation in
  50251. // userland will fail
  50252. enumerable: false,
  50253. get: function get() {
  50254. return this._readableState.highWaterMark;
  50255. }
  50256. });
  50257. Object.defineProperty(Readable.prototype, 'readableBuffer', {
  50258. // making it explicit this property is not enumerable
  50259. // because otherwise some prototype manipulation in
  50260. // userland will fail
  50261. enumerable: false,
  50262. get: function get() {
  50263. return this._readableState && this._readableState.buffer;
  50264. }
  50265. });
  50266. Object.defineProperty(Readable.prototype, 'readableFlowing', {
  50267. // making it explicit this property is not enumerable
  50268. // because otherwise some prototype manipulation in
  50269. // userland will fail
  50270. enumerable: false,
  50271. get: function get() {
  50272. return this._readableState.flowing;
  50273. },
  50274. set: function set(state) {
  50275. if (this._readableState) {
  50276. this._readableState.flowing = state;
  50277. }
  50278. }
  50279. }); // exposed for testing purposes only.
  50280. Readable._fromList = fromList;
  50281. Object.defineProperty(Readable.prototype, 'readableLength', {
  50282. // making it explicit this property is not enumerable
  50283. // because otherwise some prototype manipulation in
  50284. // userland will fail
  50285. enumerable: false,
  50286. get: function get() {
  50287. return this._readableState.length;
  50288. }
  50289. }); // Pluck off n bytes from an array of buffers.
  50290. // Length is the combined lengths of all the buffers in the list.
  50291. // This function is designed to be inlinable, so please take care when making
  50292. // changes to the function body.
  50293. function fromList(n, state) {
  50294. // nothing buffered
  50295. if (state.length === 0) return null;
  50296. var ret;
  50297. if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) {
  50298. // read it all, truncate the list
  50299. if (state.decoder) ret = state.buffer.join('');else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length);
  50300. state.buffer.clear();
  50301. } else {
  50302. // read part of list
  50303. ret = state.buffer.consume(n, state.decoder);
  50304. }
  50305. return ret;
  50306. }
  50307. function endReadable(stream) {
  50308. var state = stream._readableState;
  50309. debug('endReadable', state.endEmitted);
  50310. if (!state.endEmitted) {
  50311. state.ended = true;
  50312. ({env:{}}).nextTick(endReadableNT, state, stream);
  50313. }
  50314. }
  50315. function endReadableNT(state, stream) {
  50316. debug('endReadableNT', state.endEmitted, state.length); // Check that we didn't get one last unshift.
  50317. if (!state.endEmitted && state.length === 0) {
  50318. state.endEmitted = true;
  50319. stream.readable = false;
  50320. stream.emit('end');
  50321. if (state.autoDestroy) {
  50322. // In case of duplex streams we need a way to detect
  50323. // if the writable side is ready for autoDestroy as well
  50324. var wState = stream._writableState;
  50325. if (!wState || wState.autoDestroy && wState.finished) {
  50326. stream.destroy();
  50327. }
  50328. }
  50329. }
  50330. }
  50331. if (typeof Symbol === 'function') {
  50332. Readable.from = function (iterable, opts) {
  50333. if (from === undefined) {
  50334. from = __webpack_require__(3799);
  50335. }
  50336. return from(Readable, iterable, opts);
  50337. };
  50338. }
  50339. function indexOf(xs, x) {
  50340. for (var i = 0, l = xs.length; i < l; i++) {
  50341. if (xs[i] === x) return i;
  50342. }
  50343. return -1;
  50344. }
  50345. /***/ }),
  50346. /***/ 4951:
  50347. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  50348. "use strict";
  50349. // Copyright Joyent, Inc. and other Node contributors.
  50350. //
  50351. // Permission is hereby granted, free of charge, to any person obtaining a
  50352. // copy of this software and associated documentation files (the
  50353. // "Software"), to deal in the Software without restriction, including
  50354. // without limitation the rights to use, copy, modify, merge, publish,
  50355. // distribute, sublicense, and/or sell copies of the Software, and to permit
  50356. // persons to whom the Software is furnished to do so, subject to the
  50357. // following conditions:
  50358. //
  50359. // The above copyright notice and this permission notice shall be included
  50360. // in all copies or substantial portions of the Software.
  50361. //
  50362. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  50363. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  50364. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  50365. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  50366. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  50367. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  50368. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  50369. // a transform stream is a readable/writable stream where you do
  50370. // something with the data. Sometimes it's called a "filter",
  50371. // but that's not a great name for it, since that implies a thing where
  50372. // some bits pass through, and others are simply ignored. (That would
  50373. // be a valid example of a transform, of course.)
  50374. //
  50375. // While the output is causally related to the input, it's not a
  50376. // necessarily symmetric or synchronous transformation. For example,
  50377. // a zlib stream might take multiple plain-text writes(), and then
  50378. // emit a single compressed chunk some time in the future.
  50379. //
  50380. // Here's how this works:
  50381. //
  50382. // The Transform stream has all the aspects of the readable and writable
  50383. // stream classes. When you write(chunk), that calls _write(chunk,cb)
  50384. // internally, and returns false if there's a lot of pending writes
  50385. // buffered up. When you call read(), that calls _read(n) until
  50386. // there's enough pending readable data buffered up.
  50387. //
  50388. // In a transform stream, the written data is placed in a buffer. When
  50389. // _read(n) is called, it transforms the queued up data, calling the
  50390. // buffered _write cb's as it consumes chunks. If consuming a single
  50391. // written chunk would result in multiple output chunks, then the first
  50392. // outputted bit calls the readcb, and subsequent chunks just go into
  50393. // the read buffer, and will cause it to emit 'readable' if necessary.
  50394. //
  50395. // This way, back-pressure is actually determined by the reading side,
  50396. // since _read has to be called to start processing a new chunk. However,
  50397. // a pathological inflate type of transform can cause excessive buffering
  50398. // here. For example, imagine a stream where every byte of input is
  50399. // interpreted as an integer from 0-255, and then results in that many
  50400. // bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
  50401. // 1kb of data being output. In this case, you could write a very small
  50402. // amount of input, and end up with a very large amount of output. In
  50403. // such a pathological inflating mechanism, there'd be no way to tell
  50404. // the system to stop doing the transform. A single 4MB write could
  50405. // cause the system to run out of memory.
  50406. //
  50407. // However, even in such a pathological case, only a single written chunk
  50408. // would be consumed, and then the rest would wait (un-transformed) until
  50409. // the results of the previous transformed chunk were consumed.
  50410. module.exports = Transform;
  50411. var _require$codes = (__webpack_require__(5613)/* .codes */ .q),
  50412. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  50413. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  50414. ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING,
  50415. ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0;
  50416. var Duplex = __webpack_require__(4611);
  50417. __webpack_require__(376)(Transform, Duplex);
  50418. function afterTransform(er, data) {
  50419. var ts = this._transformState;
  50420. ts.transforming = false;
  50421. var cb = ts.writecb;
  50422. if (cb === null) {
  50423. return this.emit('error', new ERR_MULTIPLE_CALLBACK());
  50424. }
  50425. ts.writechunk = null;
  50426. ts.writecb = null;
  50427. if (data != null) // single equals check for both `null` and `undefined`
  50428. this.push(data);
  50429. cb(er);
  50430. var rs = this._readableState;
  50431. rs.reading = false;
  50432. if (rs.needReadable || rs.length < rs.highWaterMark) {
  50433. this._read(rs.highWaterMark);
  50434. }
  50435. }
  50436. function Transform(options) {
  50437. if (!(this instanceof Transform)) return new Transform(options);
  50438. Duplex.call(this, options);
  50439. this._transformState = {
  50440. afterTransform: afterTransform.bind(this),
  50441. needTransform: false,
  50442. transforming: false,
  50443. writecb: null,
  50444. writechunk: null,
  50445. writeencoding: null
  50446. }; // start out asking for a readable event once data is transformed.
  50447. this._readableState.needReadable = true; // we have implemented the _read method, and done the other things
  50448. // that Readable wants before the first _read call, so unset the
  50449. // sync guard flag.
  50450. this._readableState.sync = false;
  50451. if (options) {
  50452. if (typeof options.transform === 'function') this._transform = options.transform;
  50453. if (typeof options.flush === 'function') this._flush = options.flush;
  50454. } // When the writable side finishes, then flush out anything remaining.
  50455. this.on('prefinish', prefinish);
  50456. }
  50457. function prefinish() {
  50458. var _this = this;
  50459. if (typeof this._flush === 'function' && !this._readableState.destroyed) {
  50460. this._flush(function (er, data) {
  50461. done(_this, er, data);
  50462. });
  50463. } else {
  50464. done(this, null, null);
  50465. }
  50466. }
  50467. Transform.prototype.push = function (chunk, encoding) {
  50468. this._transformState.needTransform = false;
  50469. return Duplex.prototype.push.call(this, chunk, encoding);
  50470. }; // This is the part where you do stuff!
  50471. // override this function in implementation classes.
  50472. // 'chunk' is an input chunk.
  50473. //
  50474. // Call `push(newChunk)` to pass along transformed output
  50475. // to the readable side. You may call 'push' zero or more times.
  50476. //
  50477. // Call `cb(err)` when you are done with this chunk. If you pass
  50478. // an error, then that'll put the hurt on the whole operation. If you
  50479. // never call cb(), then you'll never get another chunk.
  50480. Transform.prototype._transform = function (chunk, encoding, cb) {
  50481. cb(new ERR_METHOD_NOT_IMPLEMENTED('_transform()'));
  50482. };
  50483. Transform.prototype._write = function (chunk, encoding, cb) {
  50484. var ts = this._transformState;
  50485. ts.writecb = cb;
  50486. ts.writechunk = chunk;
  50487. ts.writeencoding = encoding;
  50488. if (!ts.transforming) {
  50489. var rs = this._readableState;
  50490. if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark);
  50491. }
  50492. }; // Doesn't matter what the args are here.
  50493. // _transform does all the work.
  50494. // That we got here means that the readable side wants more data.
  50495. Transform.prototype._read = function (n) {
  50496. var ts = this._transformState;
  50497. if (ts.writechunk !== null && !ts.transforming) {
  50498. ts.transforming = true;
  50499. this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
  50500. } else {
  50501. // mark that we need a transform, so that any data that comes in
  50502. // will get processed, now that we've asked for it.
  50503. ts.needTransform = true;
  50504. }
  50505. };
  50506. Transform.prototype._destroy = function (err, cb) {
  50507. Duplex.prototype._destroy.call(this, err, function (err2) {
  50508. cb(err2);
  50509. });
  50510. };
  50511. function done(stream, er, data) {
  50512. if (er) return stream.emit('error', er);
  50513. if (data != null) // single equals check for both `null` and `undefined`
  50514. stream.push(data); // TODO(BridgeAR): Write a test for these two error cases
  50515. // if there's nothing in the write buffer, then that means
  50516. // that nothing more will ever be provided
  50517. if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0();
  50518. if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING();
  50519. return stream.push(null);
  50520. }
  50521. /***/ }),
  50522. /***/ 679:
  50523. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  50524. "use strict";
  50525. // Copyright Joyent, Inc. and other Node contributors.
  50526. //
  50527. // Permission is hereby granted, free of charge, to any person obtaining a
  50528. // copy of this software and associated documentation files (the
  50529. // "Software"), to deal in the Software without restriction, including
  50530. // without limitation the rights to use, copy, modify, merge, publish,
  50531. // distribute, sublicense, and/or sell copies of the Software, and to permit
  50532. // persons to whom the Software is furnished to do so, subject to the
  50533. // following conditions:
  50534. //
  50535. // The above copyright notice and this permission notice shall be included
  50536. // in all copies or substantial portions of the Software.
  50537. //
  50538. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  50539. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  50540. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  50541. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  50542. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  50543. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  50544. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  50545. // A bit simpler than readable streams.
  50546. // Implement an async ._write(chunk, encoding, cb), and it'll handle all
  50547. // the drain event emission and buffering.
  50548. module.exports = Writable;
  50549. /* <replacement> */
  50550. function WriteReq(chunk, encoding, cb) {
  50551. this.chunk = chunk;
  50552. this.encoding = encoding;
  50553. this.callback = cb;
  50554. this.next = null;
  50555. } // It seems a linked list but it is not
  50556. // there will be only 2 of these for each stream
  50557. function CorkedRequest(state) {
  50558. var _this = this;
  50559. this.next = null;
  50560. this.entry = null;
  50561. this.finish = function () {
  50562. onCorkedFinish(_this, state);
  50563. };
  50564. }
  50565. /* </replacement> */
  50566. /*<replacement>*/
  50567. var Duplex;
  50568. /*</replacement>*/
  50569. Writable.WritableState = WritableState;
  50570. /*<replacement>*/
  50571. var internalUtil = {
  50572. deprecate: __webpack_require__(8016)
  50573. };
  50574. /*</replacement>*/
  50575. /*<replacement>*/
  50576. var Stream = __webpack_require__(6054);
  50577. /*</replacement>*/
  50578. var Buffer = (__webpack_require__(365).Buffer);
  50579. var OurUint8Array = __webpack_require__.g.Uint8Array || function () {};
  50580. function _uint8ArrayToBuffer(chunk) {
  50581. return Buffer.from(chunk);
  50582. }
  50583. function _isUint8Array(obj) {
  50584. return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
  50585. }
  50586. var destroyImpl = __webpack_require__(4798);
  50587. var _require = __webpack_require__(6876),
  50588. getHighWaterMark = _require.getHighWaterMark;
  50589. var _require$codes = (__webpack_require__(5613)/* .codes */ .q),
  50590. ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
  50591. ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
  50592. ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
  50593. ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
  50594. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
  50595. ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
  50596. ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
  50597. ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
  50598. var errorOrDestroy = destroyImpl.errorOrDestroy;
  50599. __webpack_require__(376)(Writable, Stream);
  50600. function nop() {}
  50601. function WritableState(options, stream, isDuplex) {
  50602. Duplex = Duplex || __webpack_require__(4611);
  50603. options = options || {}; // Duplex streams are both readable and writable, but share
  50604. // the same options object.
  50605. // However, some cases require setting options to different
  50606. // values for the readable and the writable sides of the duplex stream,
  50607. // e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
  50608. if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream
  50609. // contains buffers or objects.
  50610. this.objectMode = !!options.objectMode;
  50611. if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false
  50612. // Note: 0 is a valid value, means that we always return false if
  50613. // the entire buffer is not flushed immediately on write()
  50614. this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex); // if _final has been called
  50615. this.finalCalled = false; // drain event flag.
  50616. this.needDrain = false; // at the start of calling end()
  50617. this.ending = false; // when end() has been called, and returned
  50618. this.ended = false; // when 'finish' is emitted
  50619. this.finished = false; // has it been destroyed
  50620. this.destroyed = false; // should we decode strings into buffers before passing to _write?
  50621. // this is here so that some node-core streams can optimize string
  50622. // handling at a lower level.
  50623. var noDecode = options.decodeStrings === false;
  50624. this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string
  50625. // encoding is 'binary' so we have to make this configurable.
  50626. // Everything else in the universe uses 'utf8', though.
  50627. this.defaultEncoding = options.defaultEncoding || 'utf8'; // not an actual buffer we keep track of, but a measurement
  50628. // of how much we're waiting to get pushed to some underlying
  50629. // socket or file.
  50630. this.length = 0; // a flag to see when we're in the middle of a write.
  50631. this.writing = false; // when true all writes will be buffered until .uncork() call
  50632. this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately,
  50633. // or on a later tick. We set this to true at first, because any
  50634. // actions that shouldn't happen until "later" should generally also
  50635. // not happen before the first write call.
  50636. this.sync = true; // a flag to know if we're processing previously buffered items, which
  50637. // may call the _write() callback in the same tick, so that we don't
  50638. // end up in an overlapped onwrite situation.
  50639. this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb)
  50640. this.onwrite = function (er) {
  50641. onwrite(stream, er);
  50642. }; // the callback that the user supplies to write(chunk,encoding,cb)
  50643. this.writecb = null; // the amount that is being written when _write is called.
  50644. this.writelen = 0;
  50645. this.bufferedRequest = null;
  50646. this.lastBufferedRequest = null; // number of pending user-supplied write callbacks
  50647. // this must be 0 before 'finish' can be emitted
  50648. this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs
  50649. // This is relevant for synchronous Transform streams
  50650. this.prefinished = false; // True if the error was already emitted and should not be thrown again
  50651. this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true.
  50652. this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end')
  50653. this.autoDestroy = !!options.autoDestroy; // count buffered requests
  50654. this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always
  50655. // one allocated and free to use, and we maintain at most two
  50656. this.corkedRequestsFree = new CorkedRequest(this);
  50657. }
  50658. WritableState.prototype.getBuffer = function getBuffer() {
  50659. var current = this.bufferedRequest;
  50660. var out = [];
  50661. while (current) {
  50662. out.push(current);
  50663. current = current.next;
  50664. }
  50665. return out;
  50666. };
  50667. (function () {
  50668. try {
  50669. Object.defineProperty(WritableState.prototype, 'buffer', {
  50670. get: internalUtil.deprecate(function writableStateBufferGetter() {
  50671. return this.getBuffer();
  50672. }, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
  50673. });
  50674. } catch (_) {}
  50675. })(); // Test _writableState for inheritance to account for Duplex streams,
  50676. // whose prototype chain only points to Readable.
  50677. var realHasInstance;
  50678. if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
  50679. realHasInstance = Function.prototype[Symbol.hasInstance];
  50680. Object.defineProperty(Writable, Symbol.hasInstance, {
  50681. value: function value(object) {
  50682. if (realHasInstance.call(this, object)) return true;
  50683. if (this !== Writable) return false;
  50684. return object && object._writableState instanceof WritableState;
  50685. }
  50686. });
  50687. } else {
  50688. realHasInstance = function realHasInstance(object) {
  50689. return object instanceof this;
  50690. };
  50691. }
  50692. function Writable(options) {
  50693. Duplex = Duplex || __webpack_require__(4611); // Writable ctor is applied to Duplexes, too.
  50694. // `realHasInstance` is necessary because using plain `instanceof`
  50695. // would return false, as no `_writableState` property is attached.
  50696. // Trying to use the custom `instanceof` for Writable here will also break the
  50697. // Node.js LazyTransform implementation, which has a non-trivial getter for
  50698. // `_writableState` that would lead to infinite recursion.
  50699. // Checking for a Stream.Duplex instance is faster here instead of inside
  50700. // the WritableState constructor, at least with V8 6.5
  50701. var isDuplex = this instanceof Duplex;
  50702. if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
  50703. this._writableState = new WritableState(options, this, isDuplex); // legacy.
  50704. this.writable = true;
  50705. if (options) {
  50706. if (typeof options.write === 'function') this._write = options.write;
  50707. if (typeof options.writev === 'function') this._writev = options.writev;
  50708. if (typeof options.destroy === 'function') this._destroy = options.destroy;
  50709. if (typeof options["final"] === 'function') this._final = options["final"];
  50710. }
  50711. Stream.call(this);
  50712. } // Otherwise people can pipe Writable streams, which is just wrong.
  50713. Writable.prototype.pipe = function () {
  50714. errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
  50715. };
  50716. function writeAfterEnd(stream, cb) {
  50717. var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb
  50718. errorOrDestroy(stream, er);
  50719. ({env:{}}).nextTick(cb, er);
  50720. } // Checks that a user-supplied chunk is valid, especially for the particular
  50721. // mode the stream is in. Currently this means that `null` is never accepted
  50722. // and undefined/non-string values are only allowed in object mode.
  50723. function validChunk(stream, state, chunk, cb) {
  50724. var er;
  50725. if (chunk === null) {
  50726. er = new ERR_STREAM_NULL_VALUES();
  50727. } else if (typeof chunk !== 'string' && !state.objectMode) {
  50728. er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
  50729. }
  50730. if (er) {
  50731. errorOrDestroy(stream, er);
  50732. ({env:{}}).nextTick(cb, er);
  50733. return false;
  50734. }
  50735. return true;
  50736. }
  50737. Writable.prototype.write = function (chunk, encoding, cb) {
  50738. var state = this._writableState;
  50739. var ret = false;
  50740. var isBuf = !state.objectMode && _isUint8Array(chunk);
  50741. if (isBuf && !Buffer.isBuffer(chunk)) {
  50742. chunk = _uint8ArrayToBuffer(chunk);
  50743. }
  50744. if (typeof encoding === 'function') {
  50745. cb = encoding;
  50746. encoding = null;
  50747. }
  50748. if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
  50749. if (typeof cb !== 'function') cb = nop;
  50750. if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
  50751. state.pendingcb++;
  50752. ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
  50753. }
  50754. return ret;
  50755. };
  50756. Writable.prototype.cork = function () {
  50757. this._writableState.corked++;
  50758. };
  50759. Writable.prototype.uncork = function () {
  50760. var state = this._writableState;
  50761. if (state.corked) {
  50762. state.corked--;
  50763. if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
  50764. }
  50765. };
  50766. Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
  50767. // node::ParseEncoding() requires lower case.
  50768. if (typeof encoding === 'string') encoding = encoding.toLowerCase();
  50769. if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
  50770. this._writableState.defaultEncoding = encoding;
  50771. return this;
  50772. };
  50773. Object.defineProperty(Writable.prototype, 'writableBuffer', {
  50774. // making it explicit this property is not enumerable
  50775. // because otherwise some prototype manipulation in
  50776. // userland will fail
  50777. enumerable: false,
  50778. get: function get() {
  50779. return this._writableState && this._writableState.getBuffer();
  50780. }
  50781. });
  50782. function decodeChunk(state, chunk, encoding) {
  50783. if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
  50784. chunk = Buffer.from(chunk, encoding);
  50785. }
  50786. return chunk;
  50787. }
  50788. Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
  50789. // making it explicit this property is not enumerable
  50790. // because otherwise some prototype manipulation in
  50791. // userland will fail
  50792. enumerable: false,
  50793. get: function get() {
  50794. return this._writableState.highWaterMark;
  50795. }
  50796. }); // if we're already writing something, then just put this
  50797. // in the queue, and wait our turn. Otherwise, call _write
  50798. // If we return false, then we need a drain event, so set that flag.
  50799. function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
  50800. if (!isBuf) {
  50801. var newChunk = decodeChunk(state, chunk, encoding);
  50802. if (chunk !== newChunk) {
  50803. isBuf = true;
  50804. encoding = 'buffer';
  50805. chunk = newChunk;
  50806. }
  50807. }
  50808. var len = state.objectMode ? 1 : chunk.length;
  50809. state.length += len;
  50810. var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false.
  50811. if (!ret) state.needDrain = true;
  50812. if (state.writing || state.corked) {
  50813. var last = state.lastBufferedRequest;
  50814. state.lastBufferedRequest = {
  50815. chunk: chunk,
  50816. encoding: encoding,
  50817. isBuf: isBuf,
  50818. callback: cb,
  50819. next: null
  50820. };
  50821. if (last) {
  50822. last.next = state.lastBufferedRequest;
  50823. } else {
  50824. state.bufferedRequest = state.lastBufferedRequest;
  50825. }
  50826. state.bufferedRequestCount += 1;
  50827. } else {
  50828. doWrite(stream, state, false, len, chunk, encoding, cb);
  50829. }
  50830. return ret;
  50831. }
  50832. function doWrite(stream, state, writev, len, chunk, encoding, cb) {
  50833. state.writelen = len;
  50834. state.writecb = cb;
  50835. state.writing = true;
  50836. state.sync = true;
  50837. if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
  50838. state.sync = false;
  50839. }
  50840. function onwriteError(stream, state, sync, er, cb) {
  50841. --state.pendingcb;
  50842. if (sync) {
  50843. // defer the callback if we are being called synchronously
  50844. // to avoid piling up things on the stack
  50845. ({env:{}}).nextTick(cb, er); // this can emit finish, and it will always happen
  50846. // after error
  50847. ({env:{}}).nextTick(finishMaybe, stream, state);
  50848. stream._writableState.errorEmitted = true;
  50849. errorOrDestroy(stream, er);
  50850. } else {
  50851. // the caller expect this to happen before if
  50852. // it is async
  50853. cb(er);
  50854. stream._writableState.errorEmitted = true;
  50855. errorOrDestroy(stream, er); // this can emit finish, but finish must
  50856. // always follow error
  50857. finishMaybe(stream, state);
  50858. }
  50859. }
  50860. function onwriteStateUpdate(state) {
  50861. state.writing = false;
  50862. state.writecb = null;
  50863. state.length -= state.writelen;
  50864. state.writelen = 0;
  50865. }
  50866. function onwrite(stream, er) {
  50867. var state = stream._writableState;
  50868. var sync = state.sync;
  50869. var cb = state.writecb;
  50870. if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
  50871. onwriteStateUpdate(state);
  50872. if (er) onwriteError(stream, state, sync, er, cb);else {
  50873. // Check if we're actually ready to finish, but don't emit yet
  50874. var finished = needFinish(state) || stream.destroyed;
  50875. if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
  50876. clearBuffer(stream, state);
  50877. }
  50878. if (sync) {
  50879. ({env:{}}).nextTick(afterWrite, stream, state, finished, cb);
  50880. } else {
  50881. afterWrite(stream, state, finished, cb);
  50882. }
  50883. }
  50884. }
  50885. function afterWrite(stream, state, finished, cb) {
  50886. if (!finished) onwriteDrain(stream, state);
  50887. state.pendingcb--;
  50888. cb();
  50889. finishMaybe(stream, state);
  50890. } // Must force callback to be called on nextTick, so that we don't
  50891. // emit 'drain' before the write() consumer gets the 'false' return
  50892. // value, and has a chance to attach a 'drain' listener.
  50893. function onwriteDrain(stream, state) {
  50894. if (state.length === 0 && state.needDrain) {
  50895. state.needDrain = false;
  50896. stream.emit('drain');
  50897. }
  50898. } // if there's something in the buffer waiting, then process it
  50899. function clearBuffer(stream, state) {
  50900. state.bufferProcessing = true;
  50901. var entry = state.bufferedRequest;
  50902. if (stream._writev && entry && entry.next) {
  50903. // Fast case, write everything using _writev()
  50904. var l = state.bufferedRequestCount;
  50905. var buffer = new Array(l);
  50906. var holder = state.corkedRequestsFree;
  50907. holder.entry = entry;
  50908. var count = 0;
  50909. var allBuffers = true;
  50910. while (entry) {
  50911. buffer[count] = entry;
  50912. if (!entry.isBuf) allBuffers = false;
  50913. entry = entry.next;
  50914. count += 1;
  50915. }
  50916. buffer.allBuffers = allBuffers;
  50917. doWrite(stream, state, true, state.length, buffer, '', holder.finish); // doWrite is almost always async, defer these to save a bit of time
  50918. // as the hot path ends with doWrite
  50919. state.pendingcb++;
  50920. state.lastBufferedRequest = null;
  50921. if (holder.next) {
  50922. state.corkedRequestsFree = holder.next;
  50923. holder.next = null;
  50924. } else {
  50925. state.corkedRequestsFree = new CorkedRequest(state);
  50926. }
  50927. state.bufferedRequestCount = 0;
  50928. } else {
  50929. // Slow case, write chunks one-by-one
  50930. while (entry) {
  50931. var chunk = entry.chunk;
  50932. var encoding = entry.encoding;
  50933. var cb = entry.callback;
  50934. var len = state.objectMode ? 1 : chunk.length;
  50935. doWrite(stream, state, false, len, chunk, encoding, cb);
  50936. entry = entry.next;
  50937. state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then
  50938. // it means that we need to wait until it does.
  50939. // also, that means that the chunk and cb are currently
  50940. // being processed, so move the buffer counter past them.
  50941. if (state.writing) {
  50942. break;
  50943. }
  50944. }
  50945. if (entry === null) state.lastBufferedRequest = null;
  50946. }
  50947. state.bufferedRequest = entry;
  50948. state.bufferProcessing = false;
  50949. }
  50950. Writable.prototype._write = function (chunk, encoding, cb) {
  50951. cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
  50952. };
  50953. Writable.prototype._writev = null;
  50954. Writable.prototype.end = function (chunk, encoding, cb) {
  50955. var state = this._writableState;
  50956. if (typeof chunk === 'function') {
  50957. cb = chunk;
  50958. chunk = null;
  50959. encoding = null;
  50960. } else if (typeof encoding === 'function') {
  50961. cb = encoding;
  50962. encoding = null;
  50963. }
  50964. if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks
  50965. if (state.corked) {
  50966. state.corked = 1;
  50967. this.uncork();
  50968. } // ignore unnecessary end() calls.
  50969. if (!state.ending) endWritable(this, state, cb);
  50970. return this;
  50971. };
  50972. Object.defineProperty(Writable.prototype, 'writableLength', {
  50973. // making it explicit this property is not enumerable
  50974. // because otherwise some prototype manipulation in
  50975. // userland will fail
  50976. enumerable: false,
  50977. get: function get() {
  50978. return this._writableState.length;
  50979. }
  50980. });
  50981. function needFinish(state) {
  50982. return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
  50983. }
  50984. function callFinal(stream, state) {
  50985. stream._final(function (err) {
  50986. state.pendingcb--;
  50987. if (err) {
  50988. errorOrDestroy(stream, err);
  50989. }
  50990. state.prefinished = true;
  50991. stream.emit('prefinish');
  50992. finishMaybe(stream, state);
  50993. });
  50994. }
  50995. function prefinish(stream, state) {
  50996. if (!state.prefinished && !state.finalCalled) {
  50997. if (typeof stream._final === 'function' && !state.destroyed) {
  50998. state.pendingcb++;
  50999. state.finalCalled = true;
  51000. ({env:{}}).nextTick(callFinal, stream, state);
  51001. } else {
  51002. state.prefinished = true;
  51003. stream.emit('prefinish');
  51004. }
  51005. }
  51006. }
  51007. function finishMaybe(stream, state) {
  51008. var need = needFinish(state);
  51009. if (need) {
  51010. prefinish(stream, state);
  51011. if (state.pendingcb === 0) {
  51012. state.finished = true;
  51013. stream.emit('finish');
  51014. if (state.autoDestroy) {
  51015. // In case of duplex streams we need a way to detect
  51016. // if the readable side is ready for autoDestroy as well
  51017. var rState = stream._readableState;
  51018. if (!rState || rState.autoDestroy && rState.endEmitted) {
  51019. stream.destroy();
  51020. }
  51021. }
  51022. }
  51023. }
  51024. return need;
  51025. }
  51026. function endWritable(stream, state, cb) {
  51027. state.ending = true;
  51028. finishMaybe(stream, state);
  51029. if (cb) {
  51030. if (state.finished) ({env:{}}).nextTick(cb);else stream.once('finish', cb);
  51031. }
  51032. state.ended = true;
  51033. stream.writable = false;
  51034. }
  51035. function onCorkedFinish(corkReq, state, err) {
  51036. var entry = corkReq.entry;
  51037. corkReq.entry = null;
  51038. while (entry) {
  51039. var cb = entry.callback;
  51040. state.pendingcb--;
  51041. cb(err);
  51042. entry = entry.next;
  51043. } // reuse the free corkReq.
  51044. state.corkedRequestsFree.next = corkReq;
  51045. }
  51046. Object.defineProperty(Writable.prototype, 'destroyed', {
  51047. // making it explicit this property is not enumerable
  51048. // because otherwise some prototype manipulation in
  51049. // userland will fail
  51050. enumerable: false,
  51051. get: function get() {
  51052. if (this._writableState === undefined) {
  51053. return false;
  51054. }
  51055. return this._writableState.destroyed;
  51056. },
  51057. set: function set(value) {
  51058. // we ignore the value if the stream
  51059. // has not been initialized yet
  51060. if (!this._writableState) {
  51061. return;
  51062. } // backward compatibility, the user is explicitly
  51063. // managing destroyed
  51064. this._writableState.destroyed = value;
  51065. }
  51066. });
  51067. Writable.prototype.destroy = destroyImpl.destroy;
  51068. Writable.prototype._undestroy = destroyImpl.undestroy;
  51069. Writable.prototype._destroy = function (err, cb) {
  51070. cb(err);
  51071. };
  51072. /***/ }),
  51073. /***/ 7673:
  51074. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51075. "use strict";
  51076. var _Object$setPrototypeO;
  51077. function _defineProperty(obj, key, value) {
  51078. if (key in obj) {
  51079. Object.defineProperty(obj, key, {
  51080. value: value,
  51081. enumerable: true,
  51082. configurable: true,
  51083. writable: true
  51084. });
  51085. } else {
  51086. obj[key] = value;
  51087. }
  51088. return obj;
  51089. }
  51090. var finished = __webpack_require__(8820);
  51091. var kLastResolve = Symbol('lastResolve');
  51092. var kLastReject = Symbol('lastReject');
  51093. var kError = Symbol('error');
  51094. var kEnded = Symbol('ended');
  51095. var kLastPromise = Symbol('lastPromise');
  51096. var kHandlePromise = Symbol('handlePromise');
  51097. var kStream = Symbol('stream');
  51098. function createIterResult(value, done) {
  51099. return {
  51100. value: value,
  51101. done: done
  51102. };
  51103. }
  51104. function readAndResolve(iter) {
  51105. var resolve = iter[kLastResolve];
  51106. if (resolve !== null) {
  51107. var data = iter[kStream].read(); // we defer if data is null
  51108. // we can be expecting either 'end' or
  51109. // 'error'
  51110. if (data !== null) {
  51111. iter[kLastPromise] = null;
  51112. iter[kLastResolve] = null;
  51113. iter[kLastReject] = null;
  51114. resolve(createIterResult(data, false));
  51115. }
  51116. }
  51117. }
  51118. function onReadable(iter) {
  51119. // we wait for the next tick, because it might
  51120. // emit an error with process.nextTick
  51121. ({env:{}}).nextTick(readAndResolve, iter);
  51122. }
  51123. function wrapForNext(lastPromise, iter) {
  51124. return function (resolve, reject) {
  51125. lastPromise.then(function () {
  51126. if (iter[kEnded]) {
  51127. resolve(createIterResult(undefined, true));
  51128. return;
  51129. }
  51130. iter[kHandlePromise](resolve, reject);
  51131. }, reject);
  51132. };
  51133. }
  51134. var AsyncIteratorPrototype = Object.getPrototypeOf(function () {});
  51135. var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = {
  51136. get stream() {
  51137. return this[kStream];
  51138. },
  51139. next: function next() {
  51140. var _this = this; // if we have detected an error in the meanwhile
  51141. // reject straight away
  51142. var error = this[kError];
  51143. if (error !== null) {
  51144. return Promise.reject(error);
  51145. }
  51146. if (this[kEnded]) {
  51147. return Promise.resolve(createIterResult(undefined, true));
  51148. }
  51149. if (this[kStream].destroyed) {
  51150. // We need to defer via nextTick because if .destroy(err) is
  51151. // called, the error will be emitted via nextTick, and
  51152. // we cannot guarantee that there is no error lingering around
  51153. // waiting to be emitted.
  51154. return new Promise(function (resolve, reject) {
  51155. ({env:{}}).nextTick(function () {
  51156. if (_this[kError]) {
  51157. reject(_this[kError]);
  51158. } else {
  51159. resolve(createIterResult(undefined, true));
  51160. }
  51161. });
  51162. });
  51163. } // if we have multiple next() calls
  51164. // we will wait for the previous Promise to finish
  51165. // this logic is optimized to support for await loops,
  51166. // where next() is only called once at a time
  51167. var lastPromise = this[kLastPromise];
  51168. var promise;
  51169. if (lastPromise) {
  51170. promise = new Promise(wrapForNext(lastPromise, this));
  51171. } else {
  51172. // fast path needed to support multiple this.push()
  51173. // without triggering the next() queue
  51174. var data = this[kStream].read();
  51175. if (data !== null) {
  51176. return Promise.resolve(createIterResult(data, false));
  51177. }
  51178. promise = new Promise(this[kHandlePromise]);
  51179. }
  51180. this[kLastPromise] = promise;
  51181. return promise;
  51182. }
  51183. }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () {
  51184. return this;
  51185. }), _defineProperty(_Object$setPrototypeO, "return", function _return() {
  51186. var _this2 = this; // destroy(err, cb) is a private API
  51187. // we can guarantee we have that here, because we control the
  51188. // Readable class this is attached to
  51189. return new Promise(function (resolve, reject) {
  51190. _this2[kStream].destroy(null, function (err) {
  51191. if (err) {
  51192. reject(err);
  51193. return;
  51194. }
  51195. resolve(createIterResult(undefined, true));
  51196. });
  51197. });
  51198. }), _Object$setPrototypeO), AsyncIteratorPrototype);
  51199. var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) {
  51200. var _Object$create;
  51201. var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, {
  51202. value: stream,
  51203. writable: true
  51204. }), _defineProperty(_Object$create, kLastResolve, {
  51205. value: null,
  51206. writable: true
  51207. }), _defineProperty(_Object$create, kLastReject, {
  51208. value: null,
  51209. writable: true
  51210. }), _defineProperty(_Object$create, kError, {
  51211. value: null,
  51212. writable: true
  51213. }), _defineProperty(_Object$create, kEnded, {
  51214. value: stream._readableState.endEmitted,
  51215. writable: true
  51216. }), _defineProperty(_Object$create, kHandlePromise, {
  51217. value: function value(resolve, reject) {
  51218. var data = iterator[kStream].read();
  51219. if (data) {
  51220. iterator[kLastPromise] = null;
  51221. iterator[kLastResolve] = null;
  51222. iterator[kLastReject] = null;
  51223. resolve(createIterResult(data, false));
  51224. } else {
  51225. iterator[kLastResolve] = resolve;
  51226. iterator[kLastReject] = reject;
  51227. }
  51228. },
  51229. writable: true
  51230. }), _Object$create));
  51231. iterator[kLastPromise] = null;
  51232. finished(stream, function (err) {
  51233. if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
  51234. var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise
  51235. // returned by next() and store the error
  51236. if (reject !== null) {
  51237. iterator[kLastPromise] = null;
  51238. iterator[kLastResolve] = null;
  51239. iterator[kLastReject] = null;
  51240. reject(err);
  51241. }
  51242. iterator[kError] = err;
  51243. return;
  51244. }
  51245. var resolve = iterator[kLastResolve];
  51246. if (resolve !== null) {
  51247. iterator[kLastPromise] = null;
  51248. iterator[kLastResolve] = null;
  51249. iterator[kLastReject] = null;
  51250. resolve(createIterResult(undefined, true));
  51251. }
  51252. iterator[kEnded] = true;
  51253. });
  51254. stream.on('readable', onReadable.bind(null, iterator));
  51255. return iterator;
  51256. };
  51257. module.exports = createReadableStreamAsyncIterator;
  51258. /***/ }),
  51259. /***/ 1843:
  51260. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51261. "use strict";
  51262. function ownKeys(object, enumerableOnly) {
  51263. var keys = Object.keys(object);
  51264. if (Object.getOwnPropertySymbols) {
  51265. var symbols = Object.getOwnPropertySymbols(object);
  51266. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  51267. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  51268. });
  51269. keys.push.apply(keys, symbols);
  51270. }
  51271. return keys;
  51272. }
  51273. function _objectSpread(target) {
  51274. for (var i = 1; i < arguments.length; i++) {
  51275. var source = arguments[i] != null ? arguments[i] : {};
  51276. if (i % 2) {
  51277. ownKeys(Object(source), true).forEach(function (key) {
  51278. _defineProperty(target, key, source[key]);
  51279. });
  51280. } else if (Object.getOwnPropertyDescriptors) {
  51281. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  51282. } else {
  51283. ownKeys(Object(source)).forEach(function (key) {
  51284. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  51285. });
  51286. }
  51287. }
  51288. return target;
  51289. }
  51290. function _defineProperty(obj, key, value) {
  51291. if (key in obj) {
  51292. Object.defineProperty(obj, key, {
  51293. value: value,
  51294. enumerable: true,
  51295. configurable: true,
  51296. writable: true
  51297. });
  51298. } else {
  51299. obj[key] = value;
  51300. }
  51301. return obj;
  51302. }
  51303. function _classCallCheck(instance, Constructor) {
  51304. if (!(instance instanceof Constructor)) {
  51305. throw new TypeError("Cannot call a class as a function");
  51306. }
  51307. }
  51308. function _defineProperties(target, props) {
  51309. for (var i = 0; i < props.length; i++) {
  51310. var descriptor = props[i];
  51311. descriptor.enumerable = descriptor.enumerable || false;
  51312. descriptor.configurable = true;
  51313. if ("value" in descriptor) descriptor.writable = true;
  51314. Object.defineProperty(target, descriptor.key, descriptor);
  51315. }
  51316. }
  51317. function _createClass(Constructor, protoProps, staticProps) {
  51318. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  51319. if (staticProps) _defineProperties(Constructor, staticProps);
  51320. return Constructor;
  51321. }
  51322. var _require = __webpack_require__(365),
  51323. Buffer = _require.Buffer;
  51324. var _require2 = __webpack_require__(2361),
  51325. inspect = _require2.inspect;
  51326. var custom = inspect && inspect.custom || 'inspect';
  51327. function copyBuffer(src, target, offset) {
  51328. Buffer.prototype.copy.call(src, target, offset);
  51329. }
  51330. module.exports = /*#__PURE__*/function () {
  51331. function BufferList() {
  51332. _classCallCheck(this, BufferList);
  51333. this.head = null;
  51334. this.tail = null;
  51335. this.length = 0;
  51336. }
  51337. _createClass(BufferList, [{
  51338. key: "push",
  51339. value: function push(v) {
  51340. var entry = {
  51341. data: v,
  51342. next: null
  51343. };
  51344. if (this.length > 0) this.tail.next = entry;else this.head = entry;
  51345. this.tail = entry;
  51346. ++this.length;
  51347. }
  51348. }, {
  51349. key: "unshift",
  51350. value: function unshift(v) {
  51351. var entry = {
  51352. data: v,
  51353. next: this.head
  51354. };
  51355. if (this.length === 0) this.tail = entry;
  51356. this.head = entry;
  51357. ++this.length;
  51358. }
  51359. }, {
  51360. key: "shift",
  51361. value: function shift() {
  51362. if (this.length === 0) return;
  51363. var ret = this.head.data;
  51364. if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next;
  51365. --this.length;
  51366. return ret;
  51367. }
  51368. }, {
  51369. key: "clear",
  51370. value: function clear() {
  51371. this.head = this.tail = null;
  51372. this.length = 0;
  51373. }
  51374. }, {
  51375. key: "join",
  51376. value: function join(s) {
  51377. if (this.length === 0) return '';
  51378. var p = this.head;
  51379. var ret = '' + p.data;
  51380. while (p = p.next) {
  51381. ret += s + p.data;
  51382. }
  51383. return ret;
  51384. }
  51385. }, {
  51386. key: "concat",
  51387. value: function concat(n) {
  51388. if (this.length === 0) return Buffer.alloc(0);
  51389. var ret = Buffer.allocUnsafe(n >>> 0);
  51390. var p = this.head;
  51391. var i = 0;
  51392. while (p) {
  51393. copyBuffer(p.data, ret, i);
  51394. i += p.data.length;
  51395. p = p.next;
  51396. }
  51397. return ret;
  51398. } // Consumes a specified amount of bytes or characters from the buffered data.
  51399. }, {
  51400. key: "consume",
  51401. value: function consume(n, hasStrings) {
  51402. var ret;
  51403. if (n < this.head.data.length) {
  51404. // `slice` is the same for buffers and strings.
  51405. ret = this.head.data.slice(0, n);
  51406. this.head.data = this.head.data.slice(n);
  51407. } else if (n === this.head.data.length) {
  51408. // First chunk is a perfect match.
  51409. ret = this.shift();
  51410. } else {
  51411. // Result spans more than one buffer.
  51412. ret = hasStrings ? this._getString(n) : this._getBuffer(n);
  51413. }
  51414. return ret;
  51415. }
  51416. }, {
  51417. key: "first",
  51418. value: function first() {
  51419. return this.head.data;
  51420. } // Consumes a specified amount of characters from the buffered data.
  51421. }, {
  51422. key: "_getString",
  51423. value: function _getString(n) {
  51424. var p = this.head;
  51425. var c = 1;
  51426. var ret = p.data;
  51427. n -= ret.length;
  51428. while (p = p.next) {
  51429. var str = p.data;
  51430. var nb = n > str.length ? str.length : n;
  51431. if (nb === str.length) ret += str;else ret += str.slice(0, n);
  51432. n -= nb;
  51433. if (n === 0) {
  51434. if (nb === str.length) {
  51435. ++c;
  51436. if (p.next) this.head = p.next;else this.head = this.tail = null;
  51437. } else {
  51438. this.head = p;
  51439. p.data = str.slice(nb);
  51440. }
  51441. break;
  51442. }
  51443. ++c;
  51444. }
  51445. this.length -= c;
  51446. return ret;
  51447. } // Consumes a specified amount of bytes from the buffered data.
  51448. }, {
  51449. key: "_getBuffer",
  51450. value: function _getBuffer(n) {
  51451. var ret = Buffer.allocUnsafe(n);
  51452. var p = this.head;
  51453. var c = 1;
  51454. p.data.copy(ret);
  51455. n -= p.data.length;
  51456. while (p = p.next) {
  51457. var buf = p.data;
  51458. var nb = n > buf.length ? buf.length : n;
  51459. buf.copy(ret, ret.length - n, 0, nb);
  51460. n -= nb;
  51461. if (n === 0) {
  51462. if (nb === buf.length) {
  51463. ++c;
  51464. if (p.next) this.head = p.next;else this.head = this.tail = null;
  51465. } else {
  51466. this.head = p;
  51467. p.data = buf.slice(nb);
  51468. }
  51469. break;
  51470. }
  51471. ++c;
  51472. }
  51473. this.length -= c;
  51474. return ret;
  51475. } // Make sure the linked list only shows the minimal necessary information.
  51476. }, {
  51477. key: custom,
  51478. value: function value(_, options) {
  51479. return inspect(this, _objectSpread({}, options, {
  51480. // Only inspect one level.
  51481. depth: 0,
  51482. // It should not recurse.
  51483. customInspect: false
  51484. }));
  51485. }
  51486. }]);
  51487. return BufferList;
  51488. }();
  51489. /***/ }),
  51490. /***/ 4798:
  51491. /***/ ((module) => {
  51492. "use strict";
  51493. // undocumented cb() API, needed for core, not for public API
  51494. function destroy(err, cb) {
  51495. var _this = this;
  51496. var readableDestroyed = this._readableState && this._readableState.destroyed;
  51497. var writableDestroyed = this._writableState && this._writableState.destroyed;
  51498. if (readableDestroyed || writableDestroyed) {
  51499. if (cb) {
  51500. cb(err);
  51501. } else if (err) {
  51502. if (!this._writableState) {
  51503. ({env:{}}).nextTick(emitErrorNT, this, err);
  51504. } else if (!this._writableState.errorEmitted) {
  51505. this._writableState.errorEmitted = true;
  51506. ({env:{}}).nextTick(emitErrorNT, this, err);
  51507. }
  51508. }
  51509. return this;
  51510. } // we set destroyed to true before firing error callbacks in order
  51511. // to make it re-entrance safe in case destroy() is called within callbacks
  51512. if (this._readableState) {
  51513. this._readableState.destroyed = true;
  51514. } // if this is a duplex stream mark the writable part as destroyed as well
  51515. if (this._writableState) {
  51516. this._writableState.destroyed = true;
  51517. }
  51518. this._destroy(err || null, function (err) {
  51519. if (!cb && err) {
  51520. if (!_this._writableState) {
  51521. ({env:{}}).nextTick(emitErrorAndCloseNT, _this, err);
  51522. } else if (!_this._writableState.errorEmitted) {
  51523. _this._writableState.errorEmitted = true;
  51524. ({env:{}}).nextTick(emitErrorAndCloseNT, _this, err);
  51525. } else {
  51526. ({env:{}}).nextTick(emitCloseNT, _this);
  51527. }
  51528. } else if (cb) {
  51529. ({env:{}}).nextTick(emitCloseNT, _this);
  51530. cb(err);
  51531. } else {
  51532. ({env:{}}).nextTick(emitCloseNT, _this);
  51533. }
  51534. });
  51535. return this;
  51536. }
  51537. function emitErrorAndCloseNT(self, err) {
  51538. emitErrorNT(self, err);
  51539. emitCloseNT(self);
  51540. }
  51541. function emitCloseNT(self) {
  51542. if (self._writableState && !self._writableState.emitClose) return;
  51543. if (self._readableState && !self._readableState.emitClose) return;
  51544. self.emit('close');
  51545. }
  51546. function undestroy() {
  51547. if (this._readableState) {
  51548. this._readableState.destroyed = false;
  51549. this._readableState.reading = false;
  51550. this._readableState.ended = false;
  51551. this._readableState.endEmitted = false;
  51552. }
  51553. if (this._writableState) {
  51554. this._writableState.destroyed = false;
  51555. this._writableState.ended = false;
  51556. this._writableState.ending = false;
  51557. this._writableState.finalCalled = false;
  51558. this._writableState.prefinished = false;
  51559. this._writableState.finished = false;
  51560. this._writableState.errorEmitted = false;
  51561. }
  51562. }
  51563. function emitErrorNT(self, err) {
  51564. self.emit('error', err);
  51565. }
  51566. function errorOrDestroy(stream, err) {
  51567. // We have tests that rely on errors being emitted
  51568. // in the same tick, so changing this is semver major.
  51569. // For now when you opt-in to autoDestroy we allow
  51570. // the error to be emitted nextTick. In a future
  51571. // semver major update we should change the default to this.
  51572. var rState = stream._readableState;
  51573. var wState = stream._writableState;
  51574. if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit('error', err);
  51575. }
  51576. module.exports = {
  51577. destroy: destroy,
  51578. undestroy: undestroy,
  51579. errorOrDestroy: errorOrDestroy
  51580. };
  51581. /***/ }),
  51582. /***/ 8820:
  51583. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51584. "use strict";
  51585. // Ported from https://github.com/mafintosh/end-of-stream with
  51586. // permission from the author, Mathias Buus (@mafintosh).
  51587. var ERR_STREAM_PREMATURE_CLOSE = (__webpack_require__(5613)/* .codes.ERR_STREAM_PREMATURE_CLOSE */ .q.ERR_STREAM_PREMATURE_CLOSE);
  51588. function once(callback) {
  51589. var called = false;
  51590. return function () {
  51591. if (called) return;
  51592. called = true;
  51593. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  51594. args[_key] = arguments[_key];
  51595. }
  51596. callback.apply(this, args);
  51597. };
  51598. }
  51599. function noop() {}
  51600. function isRequest(stream) {
  51601. return stream.setHeader && typeof stream.abort === 'function';
  51602. }
  51603. function eos(stream, opts, callback) {
  51604. if (typeof opts === 'function') return eos(stream, null, opts);
  51605. if (!opts) opts = {};
  51606. callback = once(callback || noop);
  51607. var readable = opts.readable || opts.readable !== false && stream.readable;
  51608. var writable = opts.writable || opts.writable !== false && stream.writable;
  51609. var onlegacyfinish = function onlegacyfinish() {
  51610. if (!stream.writable) onfinish();
  51611. };
  51612. var writableEnded = stream._writableState && stream._writableState.finished;
  51613. var onfinish = function onfinish() {
  51614. writable = false;
  51615. writableEnded = true;
  51616. if (!readable) callback.call(stream);
  51617. };
  51618. var readableEnded = stream._readableState && stream._readableState.endEmitted;
  51619. var onend = function onend() {
  51620. readable = false;
  51621. readableEnded = true;
  51622. if (!writable) callback.call(stream);
  51623. };
  51624. var onerror = function onerror(err) {
  51625. callback.call(stream, err);
  51626. };
  51627. var onclose = function onclose() {
  51628. var err;
  51629. if (readable && !readableEnded) {
  51630. if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  51631. return callback.call(stream, err);
  51632. }
  51633. if (writable && !writableEnded) {
  51634. if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
  51635. return callback.call(stream, err);
  51636. }
  51637. };
  51638. var onrequest = function onrequest() {
  51639. stream.req.on('finish', onfinish);
  51640. };
  51641. if (isRequest(stream)) {
  51642. stream.on('complete', onfinish);
  51643. stream.on('abort', onclose);
  51644. if (stream.req) onrequest();else stream.on('request', onrequest);
  51645. } else if (writable && !stream._writableState) {
  51646. // legacy streams
  51647. stream.on('end', onlegacyfinish);
  51648. stream.on('close', onlegacyfinish);
  51649. }
  51650. stream.on('end', onend);
  51651. stream.on('finish', onfinish);
  51652. if (opts.error !== false) stream.on('error', onerror);
  51653. stream.on('close', onclose);
  51654. return function () {
  51655. stream.removeListener('complete', onfinish);
  51656. stream.removeListener('abort', onclose);
  51657. stream.removeListener('request', onrequest);
  51658. if (stream.req) stream.req.removeListener('finish', onfinish);
  51659. stream.removeListener('end', onlegacyfinish);
  51660. stream.removeListener('close', onlegacyfinish);
  51661. stream.removeListener('finish', onfinish);
  51662. stream.removeListener('end', onend);
  51663. stream.removeListener('error', onerror);
  51664. stream.removeListener('close', onclose);
  51665. };
  51666. }
  51667. module.exports = eos;
  51668. /***/ }),
  51669. /***/ 3799:
  51670. /***/ ((module) => {
  51671. module.exports = function () {
  51672. throw new Error('Readable.from is not available in the browser');
  51673. };
  51674. /***/ }),
  51675. /***/ 8751:
  51676. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51677. "use strict";
  51678. // Ported from https://github.com/mafintosh/pump with
  51679. // permission from the author, Mathias Buus (@mafintosh).
  51680. var eos;
  51681. function once(callback) {
  51682. var called = false;
  51683. return function () {
  51684. if (called) return;
  51685. called = true;
  51686. callback.apply(void 0, arguments);
  51687. };
  51688. }
  51689. var _require$codes = (__webpack_require__(5613)/* .codes */ .q),
  51690. ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS,
  51691. ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED;
  51692. function noop(err) {
  51693. // Rethrow the error if it exists to avoid swallowing it
  51694. if (err) throw err;
  51695. }
  51696. function isRequest(stream) {
  51697. return stream.setHeader && typeof stream.abort === 'function';
  51698. }
  51699. function destroyer(stream, reading, writing, callback) {
  51700. callback = once(callback);
  51701. var closed = false;
  51702. stream.on('close', function () {
  51703. closed = true;
  51704. });
  51705. if (eos === undefined) eos = __webpack_require__(8820);
  51706. eos(stream, {
  51707. readable: reading,
  51708. writable: writing
  51709. }, function (err) {
  51710. if (err) return callback(err);
  51711. closed = true;
  51712. callback();
  51713. });
  51714. var destroyed = false;
  51715. return function (err) {
  51716. if (closed) return;
  51717. if (destroyed) return;
  51718. destroyed = true; // request.destroy just do .end - .abort is what we want
  51719. if (isRequest(stream)) return stream.abort();
  51720. if (typeof stream.destroy === 'function') return stream.destroy();
  51721. callback(err || new ERR_STREAM_DESTROYED('pipe'));
  51722. };
  51723. }
  51724. function call(fn) {
  51725. fn();
  51726. }
  51727. function pipe(from, to) {
  51728. return from.pipe(to);
  51729. }
  51730. function popCallback(streams) {
  51731. if (!streams.length) return noop;
  51732. if (typeof streams[streams.length - 1] !== 'function') return noop;
  51733. return streams.pop();
  51734. }
  51735. function pipeline() {
  51736. for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) {
  51737. streams[_key] = arguments[_key];
  51738. }
  51739. var callback = popCallback(streams);
  51740. if (Array.isArray(streams[0])) streams = streams[0];
  51741. if (streams.length < 2) {
  51742. throw new ERR_MISSING_ARGS('streams');
  51743. }
  51744. var error;
  51745. var destroys = streams.map(function (stream, i) {
  51746. var reading = i < streams.length - 1;
  51747. var writing = i > 0;
  51748. return destroyer(stream, reading, writing, function (err) {
  51749. if (!error) error = err;
  51750. if (err) destroys.forEach(call);
  51751. if (reading) return;
  51752. destroys.forEach(call);
  51753. callback(error);
  51754. });
  51755. });
  51756. return streams.reduce(pipe);
  51757. }
  51758. module.exports = pipeline;
  51759. /***/ }),
  51760. /***/ 6876:
  51761. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51762. "use strict";
  51763. var ERR_INVALID_OPT_VALUE = (__webpack_require__(5613)/* .codes.ERR_INVALID_OPT_VALUE */ .q.ERR_INVALID_OPT_VALUE);
  51764. function highWaterMarkFrom(options, isDuplex, duplexKey) {
  51765. return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
  51766. }
  51767. function getHighWaterMark(state, options, duplexKey, isDuplex) {
  51768. var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
  51769. if (hwm != null) {
  51770. if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
  51771. var name = isDuplex ? duplexKey : 'highWaterMark';
  51772. throw new ERR_INVALID_OPT_VALUE(name, hwm);
  51773. }
  51774. return Math.floor(hwm);
  51775. } // Default value
  51776. return state.objectMode ? 16 : 16 * 1024;
  51777. }
  51778. module.exports = {
  51779. getHighWaterMark: getHighWaterMark
  51780. };
  51781. /***/ }),
  51782. /***/ 6054:
  51783. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51784. module.exports = __webpack_require__(9620).EventEmitter;
  51785. /***/ }),
  51786. /***/ 8237:
  51787. /***/ ((module, exports, __webpack_require__) => {
  51788. exports = module.exports = __webpack_require__(6751);
  51789. exports.Stream = exports;
  51790. exports.Readable = exports;
  51791. exports.Writable = __webpack_require__(679);
  51792. exports.Duplex = __webpack_require__(4611);
  51793. exports.Transform = __webpack_require__(4951);
  51794. exports.PassThrough = __webpack_require__(3684);
  51795. exports.finished = __webpack_require__(8820);
  51796. exports.pipeline = __webpack_require__(8751);
  51797. /***/ }),
  51798. /***/ 8100:
  51799. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51800. "use strict";
  51801. var Buffer = (__webpack_require__(365).Buffer);
  51802. var inherits = __webpack_require__(376);
  51803. var HashBase = __webpack_require__(5125);
  51804. var ARRAY16 = new Array(16);
  51805. var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
  51806. var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
  51807. var sl = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6];
  51808. var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11];
  51809. var hl = [0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e];
  51810. var hr = [0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000];
  51811. function RIPEMD160() {
  51812. HashBase.call(this, 64); // state
  51813. this._a = 0x67452301;
  51814. this._b = 0xefcdab89;
  51815. this._c = 0x98badcfe;
  51816. this._d = 0x10325476;
  51817. this._e = 0xc3d2e1f0;
  51818. }
  51819. inherits(RIPEMD160, HashBase);
  51820. RIPEMD160.prototype._update = function () {
  51821. var words = ARRAY16;
  51822. for (var j = 0; j < 16; ++j) {
  51823. words[j] = this._block.readInt32LE(j * 4);
  51824. }
  51825. var al = this._a | 0;
  51826. var bl = this._b | 0;
  51827. var cl = this._c | 0;
  51828. var dl = this._d | 0;
  51829. var el = this._e | 0;
  51830. var ar = this._a | 0;
  51831. var br = this._b | 0;
  51832. var cr = this._c | 0;
  51833. var dr = this._d | 0;
  51834. var er = this._e | 0; // computation
  51835. for (var i = 0; i < 80; i += 1) {
  51836. var tl;
  51837. var tr;
  51838. if (i < 16) {
  51839. tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]);
  51840. tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]);
  51841. } else if (i < 32) {
  51842. tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]);
  51843. tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]);
  51844. } else if (i < 48) {
  51845. tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]);
  51846. tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]);
  51847. } else if (i < 64) {
  51848. tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]);
  51849. tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]);
  51850. } else {
  51851. // if (i<80) {
  51852. tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]);
  51853. tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]);
  51854. }
  51855. al = el;
  51856. el = dl;
  51857. dl = rotl(cl, 10);
  51858. cl = bl;
  51859. bl = tl;
  51860. ar = er;
  51861. er = dr;
  51862. dr = rotl(cr, 10);
  51863. cr = br;
  51864. br = tr;
  51865. } // update state
  51866. var t = this._b + cl + dr | 0;
  51867. this._b = this._c + dl + er | 0;
  51868. this._c = this._d + el + ar | 0;
  51869. this._d = this._e + al + br | 0;
  51870. this._e = this._a + bl + cr | 0;
  51871. this._a = t;
  51872. };
  51873. RIPEMD160.prototype._digest = function () {
  51874. // create padding and handle blocks
  51875. this._block[this._blockOffset++] = 0x80;
  51876. if (this._blockOffset > 56) {
  51877. this._block.fill(0, this._blockOffset, 64);
  51878. this._update();
  51879. this._blockOffset = 0;
  51880. }
  51881. this._block.fill(0, this._blockOffset, 56);
  51882. this._block.writeUInt32LE(this._length[0], 56);
  51883. this._block.writeUInt32LE(this._length[1], 60);
  51884. this._update(); // produce result
  51885. var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20);
  51886. buffer.writeInt32LE(this._a, 0);
  51887. buffer.writeInt32LE(this._b, 4);
  51888. buffer.writeInt32LE(this._c, 8);
  51889. buffer.writeInt32LE(this._d, 12);
  51890. buffer.writeInt32LE(this._e, 16);
  51891. return buffer;
  51892. };
  51893. function rotl(x, n) {
  51894. return x << n | x >>> 32 - n;
  51895. }
  51896. function fn1(a, b, c, d, e, m, k, s) {
  51897. return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0;
  51898. }
  51899. function fn2(a, b, c, d, e, m, k, s) {
  51900. return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0;
  51901. }
  51902. function fn3(a, b, c, d, e, m, k, s) {
  51903. return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0;
  51904. }
  51905. function fn4(a, b, c, d, e, m, k, s) {
  51906. return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0;
  51907. }
  51908. function fn5(a, b, c, d, e, m, k, s) {
  51909. return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0;
  51910. }
  51911. module.exports = RIPEMD160;
  51912. /***/ }),
  51913. /***/ 9047:
  51914. /***/ ((module, exports, __webpack_require__) => {
  51915. /* eslint-disable node/no-deprecated-api */
  51916. var buffer = __webpack_require__(365);
  51917. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  51918. function copyProps(src, dst) {
  51919. for (var key in src) {
  51920. dst[key] = src[key];
  51921. }
  51922. }
  51923. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  51924. module.exports = buffer;
  51925. } else {
  51926. // Copy properties from require('buffer')
  51927. copyProps(buffer, exports);
  51928. exports.Buffer = SafeBuffer;
  51929. }
  51930. function SafeBuffer(arg, encodingOrOffset, length) {
  51931. return Buffer(arg, encodingOrOffset, length);
  51932. } // Copy static methods from Buffer
  51933. copyProps(Buffer, SafeBuffer);
  51934. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  51935. if (typeof arg === 'number') {
  51936. throw new TypeError('Argument must not be a number');
  51937. }
  51938. return Buffer(arg, encodingOrOffset, length);
  51939. };
  51940. SafeBuffer.alloc = function (size, fill, encoding) {
  51941. if (typeof size !== 'number') {
  51942. throw new TypeError('Argument must be a number');
  51943. }
  51944. var buf = Buffer(size);
  51945. if (fill !== undefined) {
  51946. if (typeof encoding === 'string') {
  51947. buf.fill(fill, encoding);
  51948. } else {
  51949. buf.fill(fill);
  51950. }
  51951. } else {
  51952. buf.fill(0);
  51953. }
  51954. return buf;
  51955. };
  51956. SafeBuffer.allocUnsafe = function (size) {
  51957. if (typeof size !== 'number') {
  51958. throw new TypeError('Argument must be a number');
  51959. }
  51960. return Buffer(size);
  51961. };
  51962. SafeBuffer.allocUnsafeSlow = function (size) {
  51963. if (typeof size !== 'number') {
  51964. throw new TypeError('Argument must be a number');
  51965. }
  51966. return buffer.SlowBuffer(size);
  51967. };
  51968. /***/ }),
  51969. /***/ 8723:
  51970. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  51971. "use strict";
  51972. /* eslint-disable node/no-deprecated-api */
  51973. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  51974. var buffer = __webpack_require__(365);
  51975. var Buffer = buffer.Buffer;
  51976. var safer = {};
  51977. var key;
  51978. for (key in buffer) {
  51979. if (!buffer.hasOwnProperty(key)) continue;
  51980. if (key === 'SlowBuffer' || key === 'Buffer') continue;
  51981. safer[key] = buffer[key];
  51982. }
  51983. var Safer = safer.Buffer = {};
  51984. for (key in Buffer) {
  51985. if (!Buffer.hasOwnProperty(key)) continue;
  51986. if (key === 'allocUnsafe' || key === 'allocUnsafeSlow') continue;
  51987. Safer[key] = Buffer[key];
  51988. }
  51989. safer.Buffer.prototype = Buffer.prototype;
  51990. if (!Safer.from || Safer.from === Uint8Array.from) {
  51991. Safer.from = function (value, encodingOrOffset, length) {
  51992. if (typeof value === 'number') {
  51993. throw new TypeError('The "value" argument must not be of type number. Received type ' + _typeof(value));
  51994. }
  51995. if (value && typeof value.length === 'undefined') {
  51996. throw new TypeError('The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type ' + _typeof(value));
  51997. }
  51998. return Buffer(value, encodingOrOffset, length);
  51999. };
  52000. }
  52001. if (!Safer.alloc) {
  52002. Safer.alloc = function (size, fill, encoding) {
  52003. if (typeof size !== 'number') {
  52004. throw new TypeError('The "size" argument must be of type number. Received type ' + _typeof(size));
  52005. }
  52006. if (size < 0 || size >= 2 * (1 << 30)) {
  52007. throw new RangeError('The value "' + size + '" is invalid for option "size"');
  52008. }
  52009. var buf = Buffer(size);
  52010. if (!fill || fill.length === 0) {
  52011. buf.fill(0);
  52012. } else if (typeof encoding === 'string') {
  52013. buf.fill(fill, encoding);
  52014. } else {
  52015. buf.fill(fill);
  52016. }
  52017. return buf;
  52018. };
  52019. }
  52020. if (!safer.kStringMaxLength) {
  52021. try {
  52022. safer.kStringMaxLength = ({env:{}}).binding('buffer').kStringMaxLength;
  52023. } catch (e) {// we can't determine kStringMaxLength in environments where process.binding
  52024. // is unsupported, so let's not set it
  52025. }
  52026. }
  52027. if (!safer.constants) {
  52028. safer.constants = {
  52029. MAX_LENGTH: safer.kMaxLength
  52030. };
  52031. if (safer.kStringMaxLength) {
  52032. safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength;
  52033. }
  52034. }
  52035. module.exports = safer;
  52036. /***/ }),
  52037. /***/ 2159:
  52038. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52039. var Buffer = (__webpack_require__(9047).Buffer); // prototype class for hash functions
  52040. function Hash(blockSize, finalSize) {
  52041. this._block = Buffer.alloc(blockSize);
  52042. this._finalSize = finalSize;
  52043. this._blockSize = blockSize;
  52044. this._len = 0;
  52045. }
  52046. Hash.prototype.update = function (data, enc) {
  52047. if (typeof data === 'string') {
  52048. enc = enc || 'utf8';
  52049. data = Buffer.from(data, enc);
  52050. }
  52051. var block = this._block;
  52052. var blockSize = this._blockSize;
  52053. var length = data.length;
  52054. var accum = this._len;
  52055. for (var offset = 0; offset < length;) {
  52056. var assigned = accum % blockSize;
  52057. var remainder = Math.min(length - offset, blockSize - assigned);
  52058. for (var i = 0; i < remainder; i++) {
  52059. block[assigned + i] = data[offset + i];
  52060. }
  52061. accum += remainder;
  52062. offset += remainder;
  52063. if (accum % blockSize === 0) {
  52064. this._update(block);
  52065. }
  52066. }
  52067. this._len += length;
  52068. return this;
  52069. };
  52070. Hash.prototype.digest = function (enc) {
  52071. var rem = this._len % this._blockSize;
  52072. this._block[rem] = 0x80; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
  52073. // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
  52074. this._block.fill(0, rem + 1);
  52075. if (rem >= this._finalSize) {
  52076. this._update(this._block);
  52077. this._block.fill(0);
  52078. }
  52079. var bits = this._len * 8; // uint32
  52080. if (bits <= 0xffffffff) {
  52081. this._block.writeUInt32BE(bits, this._blockSize - 4); // uint64
  52082. } else {
  52083. var lowBits = (bits & 0xffffffff) >>> 0;
  52084. var highBits = (bits - lowBits) / 0x100000000;
  52085. this._block.writeUInt32BE(highBits, this._blockSize - 8);
  52086. this._block.writeUInt32BE(lowBits, this._blockSize - 4);
  52087. }
  52088. this._update(this._block);
  52089. var hash = this._hash();
  52090. return enc ? hash.toString(enc) : hash;
  52091. };
  52092. Hash.prototype._update = function () {
  52093. throw new Error('_update must be implemented by subclass');
  52094. };
  52095. module.exports = Hash;
  52096. /***/ }),
  52097. /***/ 1806:
  52098. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52099. var exports = module.exports = function SHA(algorithm) {
  52100. algorithm = algorithm.toLowerCase();
  52101. var Algorithm = exports[algorithm];
  52102. if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)');
  52103. return new Algorithm();
  52104. };
  52105. exports.sha = __webpack_require__(9675);
  52106. exports.sha1 = __webpack_require__(2950);
  52107. exports.sha224 = __webpack_require__(8881);
  52108. exports.sha256 = __webpack_require__(9642);
  52109. exports.sha384 = __webpack_require__(8220);
  52110. exports.sha512 = __webpack_require__(6859);
  52111. /***/ }),
  52112. /***/ 9675:
  52113. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52114. /*
  52115. * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
  52116. * in FIPS PUB 180-1
  52117. * This source code is derived from sha1.js of the same repository.
  52118. * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
  52119. * operation was added.
  52120. */
  52121. var inherits = __webpack_require__(376);
  52122. var Hash = __webpack_require__(2159);
  52123. var Buffer = (__webpack_require__(9047).Buffer);
  52124. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  52125. var W = new Array(80);
  52126. function Sha() {
  52127. this.init();
  52128. this._w = W;
  52129. Hash.call(this, 64, 56);
  52130. }
  52131. inherits(Sha, Hash);
  52132. Sha.prototype.init = function () {
  52133. this._a = 0x67452301;
  52134. this._b = 0xefcdab89;
  52135. this._c = 0x98badcfe;
  52136. this._d = 0x10325476;
  52137. this._e = 0xc3d2e1f0;
  52138. return this;
  52139. };
  52140. function rotl5(num) {
  52141. return num << 5 | num >>> 27;
  52142. }
  52143. function rotl30(num) {
  52144. return num << 30 | num >>> 2;
  52145. }
  52146. function ft(s, b, c, d) {
  52147. if (s === 0) return b & c | ~b & d;
  52148. if (s === 2) return b & c | b & d | c & d;
  52149. return b ^ c ^ d;
  52150. }
  52151. Sha.prototype._update = function (M) {
  52152. var W = this._w;
  52153. var a = this._a | 0;
  52154. var b = this._b | 0;
  52155. var c = this._c | 0;
  52156. var d = this._d | 0;
  52157. var e = this._e | 0;
  52158. for (var i = 0; i < 16; ++i) {
  52159. W[i] = M.readInt32BE(i * 4);
  52160. }
  52161. for (; i < 80; ++i) {
  52162. W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  52163. }
  52164. for (var j = 0; j < 80; ++j) {
  52165. var s = ~~(j / 20);
  52166. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  52167. e = d;
  52168. d = c;
  52169. c = rotl30(b);
  52170. b = a;
  52171. a = t;
  52172. }
  52173. this._a = a + this._a | 0;
  52174. this._b = b + this._b | 0;
  52175. this._c = c + this._c | 0;
  52176. this._d = d + this._d | 0;
  52177. this._e = e + this._e | 0;
  52178. };
  52179. Sha.prototype._hash = function () {
  52180. var H = Buffer.allocUnsafe(20);
  52181. H.writeInt32BE(this._a | 0, 0);
  52182. H.writeInt32BE(this._b | 0, 4);
  52183. H.writeInt32BE(this._c | 0, 8);
  52184. H.writeInt32BE(this._d | 0, 12);
  52185. H.writeInt32BE(this._e | 0, 16);
  52186. return H;
  52187. };
  52188. module.exports = Sha;
  52189. /***/ }),
  52190. /***/ 2950:
  52191. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52192. /*
  52193. * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
  52194. * in FIPS PUB 180-1
  52195. * Version 2.1a Copyright Paul Johnston 2000 - 2002.
  52196. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52197. * Distributed under the BSD License
  52198. * See http://pajhome.org.uk/crypt/md5 for details.
  52199. */
  52200. var inherits = __webpack_require__(376);
  52201. var Hash = __webpack_require__(2159);
  52202. var Buffer = (__webpack_require__(9047).Buffer);
  52203. var K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0];
  52204. var W = new Array(80);
  52205. function Sha1() {
  52206. this.init();
  52207. this._w = W;
  52208. Hash.call(this, 64, 56);
  52209. }
  52210. inherits(Sha1, Hash);
  52211. Sha1.prototype.init = function () {
  52212. this._a = 0x67452301;
  52213. this._b = 0xefcdab89;
  52214. this._c = 0x98badcfe;
  52215. this._d = 0x10325476;
  52216. this._e = 0xc3d2e1f0;
  52217. return this;
  52218. };
  52219. function rotl1(num) {
  52220. return num << 1 | num >>> 31;
  52221. }
  52222. function rotl5(num) {
  52223. return num << 5 | num >>> 27;
  52224. }
  52225. function rotl30(num) {
  52226. return num << 30 | num >>> 2;
  52227. }
  52228. function ft(s, b, c, d) {
  52229. if (s === 0) return b & c | ~b & d;
  52230. if (s === 2) return b & c | b & d | c & d;
  52231. return b ^ c ^ d;
  52232. }
  52233. Sha1.prototype._update = function (M) {
  52234. var W = this._w;
  52235. var a = this._a | 0;
  52236. var b = this._b | 0;
  52237. var c = this._c | 0;
  52238. var d = this._d | 0;
  52239. var e = this._e | 0;
  52240. for (var i = 0; i < 16; ++i) {
  52241. W[i] = M.readInt32BE(i * 4);
  52242. }
  52243. for (; i < 80; ++i) {
  52244. W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]);
  52245. }
  52246. for (var j = 0; j < 80; ++j) {
  52247. var s = ~~(j / 20);
  52248. var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0;
  52249. e = d;
  52250. d = c;
  52251. c = rotl30(b);
  52252. b = a;
  52253. a = t;
  52254. }
  52255. this._a = a + this._a | 0;
  52256. this._b = b + this._b | 0;
  52257. this._c = c + this._c | 0;
  52258. this._d = d + this._d | 0;
  52259. this._e = e + this._e | 0;
  52260. };
  52261. Sha1.prototype._hash = function () {
  52262. var H = Buffer.allocUnsafe(20);
  52263. H.writeInt32BE(this._a | 0, 0);
  52264. H.writeInt32BE(this._b | 0, 4);
  52265. H.writeInt32BE(this._c | 0, 8);
  52266. H.writeInt32BE(this._d | 0, 12);
  52267. H.writeInt32BE(this._e | 0, 16);
  52268. return H;
  52269. };
  52270. module.exports = Sha1;
  52271. /***/ }),
  52272. /***/ 8881:
  52273. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52274. /**
  52275. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  52276. * in FIPS 180-2
  52277. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  52278. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52279. *
  52280. */
  52281. var inherits = __webpack_require__(376);
  52282. var Sha256 = __webpack_require__(9642);
  52283. var Hash = __webpack_require__(2159);
  52284. var Buffer = (__webpack_require__(9047).Buffer);
  52285. var W = new Array(64);
  52286. function Sha224() {
  52287. this.init();
  52288. this._w = W; // new Array(64)
  52289. Hash.call(this, 64, 56);
  52290. }
  52291. inherits(Sha224, Sha256);
  52292. Sha224.prototype.init = function () {
  52293. this._a = 0xc1059ed8;
  52294. this._b = 0x367cd507;
  52295. this._c = 0x3070dd17;
  52296. this._d = 0xf70e5939;
  52297. this._e = 0xffc00b31;
  52298. this._f = 0x68581511;
  52299. this._g = 0x64f98fa7;
  52300. this._h = 0xbefa4fa4;
  52301. return this;
  52302. };
  52303. Sha224.prototype._hash = function () {
  52304. var H = Buffer.allocUnsafe(28);
  52305. H.writeInt32BE(this._a, 0);
  52306. H.writeInt32BE(this._b, 4);
  52307. H.writeInt32BE(this._c, 8);
  52308. H.writeInt32BE(this._d, 12);
  52309. H.writeInt32BE(this._e, 16);
  52310. H.writeInt32BE(this._f, 20);
  52311. H.writeInt32BE(this._g, 24);
  52312. return H;
  52313. };
  52314. module.exports = Sha224;
  52315. /***/ }),
  52316. /***/ 9642:
  52317. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52318. /**
  52319. * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
  52320. * in FIPS 180-2
  52321. * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
  52322. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
  52323. *
  52324. */
  52325. var inherits = __webpack_require__(376);
  52326. var Hash = __webpack_require__(2159);
  52327. var Buffer = (__webpack_require__(9047).Buffer);
  52328. var K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2];
  52329. var W = new Array(64);
  52330. function Sha256() {
  52331. this.init();
  52332. this._w = W; // new Array(64)
  52333. Hash.call(this, 64, 56);
  52334. }
  52335. inherits(Sha256, Hash);
  52336. Sha256.prototype.init = function () {
  52337. this._a = 0x6a09e667;
  52338. this._b = 0xbb67ae85;
  52339. this._c = 0x3c6ef372;
  52340. this._d = 0xa54ff53a;
  52341. this._e = 0x510e527f;
  52342. this._f = 0x9b05688c;
  52343. this._g = 0x1f83d9ab;
  52344. this._h = 0x5be0cd19;
  52345. return this;
  52346. };
  52347. function ch(x, y, z) {
  52348. return z ^ x & (y ^ z);
  52349. }
  52350. function maj(x, y, z) {
  52351. return x & y | z & (x | y);
  52352. }
  52353. function sigma0(x) {
  52354. return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10);
  52355. }
  52356. function sigma1(x) {
  52357. return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7);
  52358. }
  52359. function gamma0(x) {
  52360. return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3;
  52361. }
  52362. function gamma1(x) {
  52363. return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10;
  52364. }
  52365. Sha256.prototype._update = function (M) {
  52366. var W = this._w;
  52367. var a = this._a | 0;
  52368. var b = this._b | 0;
  52369. var c = this._c | 0;
  52370. var d = this._d | 0;
  52371. var e = this._e | 0;
  52372. var f = this._f | 0;
  52373. var g = this._g | 0;
  52374. var h = this._h | 0;
  52375. for (var i = 0; i < 16; ++i) {
  52376. W[i] = M.readInt32BE(i * 4);
  52377. }
  52378. for (; i < 64; ++i) {
  52379. W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0;
  52380. }
  52381. for (var j = 0; j < 64; ++j) {
  52382. var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0;
  52383. var T2 = sigma0(a) + maj(a, b, c) | 0;
  52384. h = g;
  52385. g = f;
  52386. f = e;
  52387. e = d + T1 | 0;
  52388. d = c;
  52389. c = b;
  52390. b = a;
  52391. a = T1 + T2 | 0;
  52392. }
  52393. this._a = a + this._a | 0;
  52394. this._b = b + this._b | 0;
  52395. this._c = c + this._c | 0;
  52396. this._d = d + this._d | 0;
  52397. this._e = e + this._e | 0;
  52398. this._f = f + this._f | 0;
  52399. this._g = g + this._g | 0;
  52400. this._h = h + this._h | 0;
  52401. };
  52402. Sha256.prototype._hash = function () {
  52403. var H = Buffer.allocUnsafe(32);
  52404. H.writeInt32BE(this._a, 0);
  52405. H.writeInt32BE(this._b, 4);
  52406. H.writeInt32BE(this._c, 8);
  52407. H.writeInt32BE(this._d, 12);
  52408. H.writeInt32BE(this._e, 16);
  52409. H.writeInt32BE(this._f, 20);
  52410. H.writeInt32BE(this._g, 24);
  52411. H.writeInt32BE(this._h, 28);
  52412. return H;
  52413. };
  52414. module.exports = Sha256;
  52415. /***/ }),
  52416. /***/ 8220:
  52417. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52418. var inherits = __webpack_require__(376);
  52419. var SHA512 = __webpack_require__(6859);
  52420. var Hash = __webpack_require__(2159);
  52421. var Buffer = (__webpack_require__(9047).Buffer);
  52422. var W = new Array(160);
  52423. function Sha384() {
  52424. this.init();
  52425. this._w = W;
  52426. Hash.call(this, 128, 112);
  52427. }
  52428. inherits(Sha384, SHA512);
  52429. Sha384.prototype.init = function () {
  52430. this._ah = 0xcbbb9d5d;
  52431. this._bh = 0x629a292a;
  52432. this._ch = 0x9159015a;
  52433. this._dh = 0x152fecd8;
  52434. this._eh = 0x67332667;
  52435. this._fh = 0x8eb44a87;
  52436. this._gh = 0xdb0c2e0d;
  52437. this._hh = 0x47b5481d;
  52438. this._al = 0xc1059ed8;
  52439. this._bl = 0x367cd507;
  52440. this._cl = 0x3070dd17;
  52441. this._dl = 0xf70e5939;
  52442. this._el = 0xffc00b31;
  52443. this._fl = 0x68581511;
  52444. this._gl = 0x64f98fa7;
  52445. this._hl = 0xbefa4fa4;
  52446. return this;
  52447. };
  52448. Sha384.prototype._hash = function () {
  52449. var H = Buffer.allocUnsafe(48);
  52450. function writeInt64BE(h, l, offset) {
  52451. H.writeInt32BE(h, offset);
  52452. H.writeInt32BE(l, offset + 4);
  52453. }
  52454. writeInt64BE(this._ah, this._al, 0);
  52455. writeInt64BE(this._bh, this._bl, 8);
  52456. writeInt64BE(this._ch, this._cl, 16);
  52457. writeInt64BE(this._dh, this._dl, 24);
  52458. writeInt64BE(this._eh, this._el, 32);
  52459. writeInt64BE(this._fh, this._fl, 40);
  52460. return H;
  52461. };
  52462. module.exports = Sha384;
  52463. /***/ }),
  52464. /***/ 6859:
  52465. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52466. var inherits = __webpack_require__(376);
  52467. var Hash = __webpack_require__(2159);
  52468. var Buffer = (__webpack_require__(9047).Buffer);
  52469. var K = [0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817];
  52470. var W = new Array(160);
  52471. function Sha512() {
  52472. this.init();
  52473. this._w = W;
  52474. Hash.call(this, 128, 112);
  52475. }
  52476. inherits(Sha512, Hash);
  52477. Sha512.prototype.init = function () {
  52478. this._ah = 0x6a09e667;
  52479. this._bh = 0xbb67ae85;
  52480. this._ch = 0x3c6ef372;
  52481. this._dh = 0xa54ff53a;
  52482. this._eh = 0x510e527f;
  52483. this._fh = 0x9b05688c;
  52484. this._gh = 0x1f83d9ab;
  52485. this._hh = 0x5be0cd19;
  52486. this._al = 0xf3bcc908;
  52487. this._bl = 0x84caa73b;
  52488. this._cl = 0xfe94f82b;
  52489. this._dl = 0x5f1d36f1;
  52490. this._el = 0xade682d1;
  52491. this._fl = 0x2b3e6c1f;
  52492. this._gl = 0xfb41bd6b;
  52493. this._hl = 0x137e2179;
  52494. return this;
  52495. };
  52496. function Ch(x, y, z) {
  52497. return z ^ x & (y ^ z);
  52498. }
  52499. function maj(x, y, z) {
  52500. return x & y | z & (x | y);
  52501. }
  52502. function sigma0(x, xl) {
  52503. return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25);
  52504. }
  52505. function sigma1(x, xl) {
  52506. return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23);
  52507. }
  52508. function Gamma0(x, xl) {
  52509. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7;
  52510. }
  52511. function Gamma0l(x, xl) {
  52512. return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25);
  52513. }
  52514. function Gamma1(x, xl) {
  52515. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6;
  52516. }
  52517. function Gamma1l(x, xl) {
  52518. return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26);
  52519. }
  52520. function getCarry(a, b) {
  52521. return a >>> 0 < b >>> 0 ? 1 : 0;
  52522. }
  52523. Sha512.prototype._update = function (M) {
  52524. var W = this._w;
  52525. var ah = this._ah | 0;
  52526. var bh = this._bh | 0;
  52527. var ch = this._ch | 0;
  52528. var dh = this._dh | 0;
  52529. var eh = this._eh | 0;
  52530. var fh = this._fh | 0;
  52531. var gh = this._gh | 0;
  52532. var hh = this._hh | 0;
  52533. var al = this._al | 0;
  52534. var bl = this._bl | 0;
  52535. var cl = this._cl | 0;
  52536. var dl = this._dl | 0;
  52537. var el = this._el | 0;
  52538. var fl = this._fl | 0;
  52539. var gl = this._gl | 0;
  52540. var hl = this._hl | 0;
  52541. for (var i = 0; i < 32; i += 2) {
  52542. W[i] = M.readInt32BE(i * 4);
  52543. W[i + 1] = M.readInt32BE(i * 4 + 4);
  52544. }
  52545. for (; i < 160; i += 2) {
  52546. var xh = W[i - 15 * 2];
  52547. var xl = W[i - 15 * 2 + 1];
  52548. var gamma0 = Gamma0(xh, xl);
  52549. var gamma0l = Gamma0l(xl, xh);
  52550. xh = W[i - 2 * 2];
  52551. xl = W[i - 2 * 2 + 1];
  52552. var gamma1 = Gamma1(xh, xl);
  52553. var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
  52554. var Wi7h = W[i - 7 * 2];
  52555. var Wi7l = W[i - 7 * 2 + 1];
  52556. var Wi16h = W[i - 16 * 2];
  52557. var Wi16l = W[i - 16 * 2 + 1];
  52558. var Wil = gamma0l + Wi7l | 0;
  52559. var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0;
  52560. Wil = Wil + gamma1l | 0;
  52561. Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0;
  52562. Wil = Wil + Wi16l | 0;
  52563. Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0;
  52564. W[i] = Wih;
  52565. W[i + 1] = Wil;
  52566. }
  52567. for (var j = 0; j < 160; j += 2) {
  52568. Wih = W[j];
  52569. Wil = W[j + 1];
  52570. var majh = maj(ah, bh, ch);
  52571. var majl = maj(al, bl, cl);
  52572. var sigma0h = sigma0(ah, al);
  52573. var sigma0l = sigma0(al, ah);
  52574. var sigma1h = sigma1(eh, el);
  52575. var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j]
  52576. var Kih = K[j];
  52577. var Kil = K[j + 1];
  52578. var chh = Ch(eh, fh, gh);
  52579. var chl = Ch(el, fl, gl);
  52580. var t1l = hl + sigma1l | 0;
  52581. var t1h = hh + sigma1h + getCarry(t1l, hl) | 0;
  52582. t1l = t1l + chl | 0;
  52583. t1h = t1h + chh + getCarry(t1l, chl) | 0;
  52584. t1l = t1l + Kil | 0;
  52585. t1h = t1h + Kih + getCarry(t1l, Kil) | 0;
  52586. t1l = t1l + Wil | 0;
  52587. t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj
  52588. var t2l = sigma0l + majl | 0;
  52589. var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0;
  52590. hh = gh;
  52591. hl = gl;
  52592. gh = fh;
  52593. gl = fl;
  52594. fh = eh;
  52595. fl = el;
  52596. el = dl + t1l | 0;
  52597. eh = dh + t1h + getCarry(el, dl) | 0;
  52598. dh = ch;
  52599. dl = cl;
  52600. ch = bh;
  52601. cl = bl;
  52602. bh = ah;
  52603. bl = al;
  52604. al = t1l + t2l | 0;
  52605. ah = t1h + t2h + getCarry(al, t1l) | 0;
  52606. }
  52607. this._al = this._al + al | 0;
  52608. this._bl = this._bl + bl | 0;
  52609. this._cl = this._cl + cl | 0;
  52610. this._dl = this._dl + dl | 0;
  52611. this._el = this._el + el | 0;
  52612. this._fl = this._fl + fl | 0;
  52613. this._gl = this._gl + gl | 0;
  52614. this._hl = this._hl + hl | 0;
  52615. this._ah = this._ah + ah + getCarry(this._al, al) | 0;
  52616. this._bh = this._bh + bh + getCarry(this._bl, bl) | 0;
  52617. this._ch = this._ch + ch + getCarry(this._cl, cl) | 0;
  52618. this._dh = this._dh + dh + getCarry(this._dl, dl) | 0;
  52619. this._eh = this._eh + eh + getCarry(this._el, el) | 0;
  52620. this._fh = this._fh + fh + getCarry(this._fl, fl) | 0;
  52621. this._gh = this._gh + gh + getCarry(this._gl, gl) | 0;
  52622. this._hh = this._hh + hh + getCarry(this._hl, hl) | 0;
  52623. };
  52624. Sha512.prototype._hash = function () {
  52625. var H = Buffer.allocUnsafe(64);
  52626. function writeInt64BE(h, l, offset) {
  52627. H.writeInt32BE(h, offset);
  52628. H.writeInt32BE(l, offset + 4);
  52629. }
  52630. writeInt64BE(this._ah, this._al, 0);
  52631. writeInt64BE(this._bh, this._bl, 8);
  52632. writeInt64BE(this._ch, this._cl, 16);
  52633. writeInt64BE(this._dh, this._dl, 24);
  52634. writeInt64BE(this._eh, this._el, 32);
  52635. writeInt64BE(this._fh, this._fl, 40);
  52636. writeInt64BE(this._gh, this._gl, 48);
  52637. writeInt64BE(this._hh, this._hl, 56);
  52638. return H;
  52639. };
  52640. module.exports = Sha512;
  52641. /***/ }),
  52642. /***/ 4723:
  52643. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  52644. // Copyright Joyent, Inc. and other Node contributors.
  52645. //
  52646. // Permission is hereby granted, free of charge, to any person obtaining a
  52647. // copy of this software and associated documentation files (the
  52648. // "Software"), to deal in the Software without restriction, including
  52649. // without limitation the rights to use, copy, modify, merge, publish,
  52650. // distribute, sublicense, and/or sell copies of the Software, and to permit
  52651. // persons to whom the Software is furnished to do so, subject to the
  52652. // following conditions:
  52653. //
  52654. // The above copyright notice and this permission notice shall be included
  52655. // in all copies or substantial portions of the Software.
  52656. //
  52657. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  52658. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  52659. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  52660. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  52661. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  52662. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  52663. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  52664. module.exports = Stream;
  52665. var EE = (__webpack_require__(9620).EventEmitter);
  52666. var inherits = __webpack_require__(376);
  52667. inherits(Stream, EE);
  52668. Stream.Readable = __webpack_require__(6751);
  52669. Stream.Writable = __webpack_require__(679);
  52670. Stream.Duplex = __webpack_require__(4611);
  52671. Stream.Transform = __webpack_require__(4951);
  52672. Stream.PassThrough = __webpack_require__(3684);
  52673. Stream.finished = __webpack_require__(8820);
  52674. Stream.pipeline = __webpack_require__(8751); // Backwards-compat with node 0.4.x
  52675. Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant
  52676. // part of this class) is overridden in the Readable class.
  52677. function Stream() {
  52678. EE.call(this);
  52679. }
  52680. Stream.prototype.pipe = function (dest, options) {
  52681. var source = this;
  52682. function ondata(chunk) {
  52683. if (dest.writable) {
  52684. if (false === dest.write(chunk) && source.pause) {
  52685. source.pause();
  52686. }
  52687. }
  52688. }
  52689. source.on('data', ondata);
  52690. function ondrain() {
  52691. if (source.readable && source.resume) {
  52692. source.resume();
  52693. }
  52694. }
  52695. dest.on('drain', ondrain); // If the 'end' option is not supplied, dest.end() will be called when
  52696. // source gets the 'end' or 'close' events. Only dest.end() once.
  52697. if (!dest._isStdio && (!options || options.end !== false)) {
  52698. source.on('end', onend);
  52699. source.on('close', onclose);
  52700. }
  52701. var didOnEnd = false;
  52702. function onend() {
  52703. if (didOnEnd) return;
  52704. didOnEnd = true;
  52705. dest.end();
  52706. }
  52707. function onclose() {
  52708. if (didOnEnd) return;
  52709. didOnEnd = true;
  52710. if (typeof dest.destroy === 'function') dest.destroy();
  52711. } // don't leave dangling pipes when there are errors.
  52712. function onerror(er) {
  52713. cleanup();
  52714. if (EE.listenerCount(this, 'error') === 0) {
  52715. throw er; // Unhandled stream error in pipe.
  52716. }
  52717. }
  52718. source.on('error', onerror);
  52719. dest.on('error', onerror); // remove all the event listeners that were added.
  52720. function cleanup() {
  52721. source.removeListener('data', ondata);
  52722. dest.removeListener('drain', ondrain);
  52723. source.removeListener('end', onend);
  52724. source.removeListener('close', onclose);
  52725. source.removeListener('error', onerror);
  52726. dest.removeListener('error', onerror);
  52727. source.removeListener('end', cleanup);
  52728. source.removeListener('close', cleanup);
  52729. dest.removeListener('close', cleanup);
  52730. }
  52731. source.on('end', cleanup);
  52732. source.on('close', cleanup);
  52733. dest.on('close', cleanup);
  52734. dest.emit('pipe', source); // Allow for unix-like usage: A.pipe(B).pipe(C)
  52735. return dest;
  52736. };
  52737. /***/ }),
  52738. /***/ 113:
  52739. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  52740. "use strict";
  52741. // Copyright Joyent, Inc. and other Node contributors.
  52742. //
  52743. // Permission is hereby granted, free of charge, to any person obtaining a
  52744. // copy of this software and associated documentation files (the
  52745. // "Software"), to deal in the Software without restriction, including
  52746. // without limitation the rights to use, copy, modify, merge, publish,
  52747. // distribute, sublicense, and/or sell copies of the Software, and to permit
  52748. // persons to whom the Software is furnished to do so, subject to the
  52749. // following conditions:
  52750. //
  52751. // The above copyright notice and this permission notice shall be included
  52752. // in all copies or substantial portions of the Software.
  52753. //
  52754. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  52755. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  52756. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  52757. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  52758. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  52759. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  52760. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  52761. /*<replacement>*/
  52762. var Buffer = (__webpack_require__(4368).Buffer);
  52763. /*</replacement>*/
  52764. var isEncoding = Buffer.isEncoding || function (encoding) {
  52765. encoding = '' + encoding;
  52766. switch (encoding && encoding.toLowerCase()) {
  52767. case 'hex':
  52768. case 'utf8':
  52769. case 'utf-8':
  52770. case 'ascii':
  52771. case 'binary':
  52772. case 'base64':
  52773. case 'ucs2':
  52774. case 'ucs-2':
  52775. case 'utf16le':
  52776. case 'utf-16le':
  52777. case 'raw':
  52778. return true;
  52779. default:
  52780. return false;
  52781. }
  52782. };
  52783. function _normalizeEncoding(enc) {
  52784. if (!enc) return 'utf8';
  52785. var retried;
  52786. while (true) {
  52787. switch (enc) {
  52788. case 'utf8':
  52789. case 'utf-8':
  52790. return 'utf8';
  52791. case 'ucs2':
  52792. case 'ucs-2':
  52793. case 'utf16le':
  52794. case 'utf-16le':
  52795. return 'utf16le';
  52796. case 'latin1':
  52797. case 'binary':
  52798. return 'latin1';
  52799. case 'base64':
  52800. case 'ascii':
  52801. case 'hex':
  52802. return enc;
  52803. default:
  52804. if (retried) return; // undefined
  52805. enc = ('' + enc).toLowerCase();
  52806. retried = true;
  52807. }
  52808. }
  52809. }
  52810. ; // Do not cache `Buffer.isEncoding` when checking encoding names as some
  52811. // modules monkey-patch it to support additional encodings
  52812. function normalizeEncoding(enc) {
  52813. var nenc = _normalizeEncoding(enc);
  52814. if (typeof nenc !== 'string' && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error('Unknown encoding: ' + enc);
  52815. return nenc || enc;
  52816. } // StringDecoder provides an interface for efficiently splitting a series of
  52817. // buffers into a series of JS strings without breaking apart multi-byte
  52818. // characters.
  52819. exports.s = StringDecoder;
  52820. function StringDecoder(encoding) {
  52821. this.encoding = normalizeEncoding(encoding);
  52822. var nb;
  52823. switch (this.encoding) {
  52824. case 'utf16le':
  52825. this.text = utf16Text;
  52826. this.end = utf16End;
  52827. nb = 4;
  52828. break;
  52829. case 'utf8':
  52830. this.fillLast = utf8FillLast;
  52831. nb = 4;
  52832. break;
  52833. case 'base64':
  52834. this.text = base64Text;
  52835. this.end = base64End;
  52836. nb = 3;
  52837. break;
  52838. default:
  52839. this.write = simpleWrite;
  52840. this.end = simpleEnd;
  52841. return;
  52842. }
  52843. this.lastNeed = 0;
  52844. this.lastTotal = 0;
  52845. this.lastChar = Buffer.allocUnsafe(nb);
  52846. }
  52847. StringDecoder.prototype.write = function (buf) {
  52848. if (buf.length === 0) return '';
  52849. var r;
  52850. var i;
  52851. if (this.lastNeed) {
  52852. r = this.fillLast(buf);
  52853. if (r === undefined) return '';
  52854. i = this.lastNeed;
  52855. this.lastNeed = 0;
  52856. } else {
  52857. i = 0;
  52858. }
  52859. if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i);
  52860. return r || '';
  52861. };
  52862. StringDecoder.prototype.end = utf8End; // Returns only complete characters in a Buffer
  52863. StringDecoder.prototype.text = utf8Text; // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer
  52864. StringDecoder.prototype.fillLast = function (buf) {
  52865. if (this.lastNeed <= buf.length) {
  52866. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed);
  52867. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  52868. }
  52869. buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length);
  52870. this.lastNeed -= buf.length;
  52871. }; // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a
  52872. // continuation byte. If an invalid byte is detected, -2 is returned.
  52873. function utf8CheckByte(_byte) {
  52874. if (_byte <= 0x7F) return 0;else if (_byte >> 5 === 0x06) return 2;else if (_byte >> 4 === 0x0E) return 3;else if (_byte >> 3 === 0x1E) return 4;
  52875. return _byte >> 6 === 0x02 ? -1 : -2;
  52876. } // Checks at most 3 bytes at the end of a Buffer in order to detect an
  52877. // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4)
  52878. // needed to complete the UTF-8 character (if applicable) are returned.
  52879. function utf8CheckIncomplete(self, buf, i) {
  52880. var j = buf.length - 1;
  52881. if (j < i) return 0;
  52882. var nb = utf8CheckByte(buf[j]);
  52883. if (nb >= 0) {
  52884. if (nb > 0) self.lastNeed = nb - 1;
  52885. return nb;
  52886. }
  52887. if (--j < i || nb === -2) return 0;
  52888. nb = utf8CheckByte(buf[j]);
  52889. if (nb >= 0) {
  52890. if (nb > 0) self.lastNeed = nb - 2;
  52891. return nb;
  52892. }
  52893. if (--j < i || nb === -2) return 0;
  52894. nb = utf8CheckByte(buf[j]);
  52895. if (nb >= 0) {
  52896. if (nb > 0) {
  52897. if (nb === 2) nb = 0;else self.lastNeed = nb - 3;
  52898. }
  52899. return nb;
  52900. }
  52901. return 0;
  52902. } // Validates as many continuation bytes for a multi-byte UTF-8 character as
  52903. // needed or are available. If we see a non-continuation byte where we expect
  52904. // one, we "replace" the validated continuation bytes we've seen so far with
  52905. // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding
  52906. // behavior. The continuation byte check is included three times in the case
  52907. // where all of the continuation bytes for a character exist in the same buffer.
  52908. // It is also done this way as a slight performance increase instead of using a
  52909. // loop.
  52910. function utf8CheckExtraBytes(self, buf, p) {
  52911. if ((buf[0] & 0xC0) !== 0x80) {
  52912. self.lastNeed = 0;
  52913. return "\uFFFD";
  52914. }
  52915. if (self.lastNeed > 1 && buf.length > 1) {
  52916. if ((buf[1] & 0xC0) !== 0x80) {
  52917. self.lastNeed = 1;
  52918. return "\uFFFD";
  52919. }
  52920. if (self.lastNeed > 2 && buf.length > 2) {
  52921. if ((buf[2] & 0xC0) !== 0x80) {
  52922. self.lastNeed = 2;
  52923. return "\uFFFD";
  52924. }
  52925. }
  52926. }
  52927. } // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer.
  52928. function utf8FillLast(buf) {
  52929. var p = this.lastTotal - this.lastNeed;
  52930. var r = utf8CheckExtraBytes(this, buf, p);
  52931. if (r !== undefined) return r;
  52932. if (this.lastNeed <= buf.length) {
  52933. buf.copy(this.lastChar, p, 0, this.lastNeed);
  52934. return this.lastChar.toString(this.encoding, 0, this.lastTotal);
  52935. }
  52936. buf.copy(this.lastChar, p, 0, buf.length);
  52937. this.lastNeed -= buf.length;
  52938. } // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a
  52939. // partial character, the character's bytes are buffered until the required
  52940. // number of bytes are available.
  52941. function utf8Text(buf, i) {
  52942. var total = utf8CheckIncomplete(this, buf, i);
  52943. if (!this.lastNeed) return buf.toString('utf8', i);
  52944. this.lastTotal = total;
  52945. var end = buf.length - (total - this.lastNeed);
  52946. buf.copy(this.lastChar, 0, end);
  52947. return buf.toString('utf8', i, end);
  52948. } // For UTF-8, a replacement character is added when ending on a partial
  52949. // character.
  52950. function utf8End(buf) {
  52951. var r = buf && buf.length ? this.write(buf) : '';
  52952. if (this.lastNeed) return r + "\uFFFD";
  52953. return r;
  52954. } // UTF-16LE typically needs two bytes per character, but even if we have an even
  52955. // number of bytes available, we need to check if we end on a leading/high
  52956. // surrogate. In that case, we need to wait for the next two bytes in order to
  52957. // decode the last character properly.
  52958. function utf16Text(buf, i) {
  52959. if ((buf.length - i) % 2 === 0) {
  52960. var r = buf.toString('utf16le', i);
  52961. if (r) {
  52962. var c = r.charCodeAt(r.length - 1);
  52963. if (c >= 0xD800 && c <= 0xDBFF) {
  52964. this.lastNeed = 2;
  52965. this.lastTotal = 4;
  52966. this.lastChar[0] = buf[buf.length - 2];
  52967. this.lastChar[1] = buf[buf.length - 1];
  52968. return r.slice(0, -1);
  52969. }
  52970. }
  52971. return r;
  52972. }
  52973. this.lastNeed = 1;
  52974. this.lastTotal = 2;
  52975. this.lastChar[0] = buf[buf.length - 1];
  52976. return buf.toString('utf16le', i, buf.length - 1);
  52977. } // For UTF-16LE we do not explicitly append special replacement characters if we
  52978. // end on a partial character, we simply let v8 handle that.
  52979. function utf16End(buf) {
  52980. var r = buf && buf.length ? this.write(buf) : '';
  52981. if (this.lastNeed) {
  52982. var end = this.lastTotal - this.lastNeed;
  52983. return r + this.lastChar.toString('utf16le', 0, end);
  52984. }
  52985. return r;
  52986. }
  52987. function base64Text(buf, i) {
  52988. var n = (buf.length - i) % 3;
  52989. if (n === 0) return buf.toString('base64', i);
  52990. this.lastNeed = 3 - n;
  52991. this.lastTotal = 3;
  52992. if (n === 1) {
  52993. this.lastChar[0] = buf[buf.length - 1];
  52994. } else {
  52995. this.lastChar[0] = buf[buf.length - 2];
  52996. this.lastChar[1] = buf[buf.length - 1];
  52997. }
  52998. return buf.toString('base64', i, buf.length - n);
  52999. }
  53000. function base64End(buf) {
  53001. var r = buf && buf.length ? this.write(buf) : '';
  53002. if (this.lastNeed) return r + this.lastChar.toString('base64', 0, 3 - this.lastNeed);
  53003. return r;
  53004. } // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex)
  53005. function simpleWrite(buf) {
  53006. return buf.toString(this.encoding);
  53007. }
  53008. function simpleEnd(buf) {
  53009. return buf && buf.length ? this.write(buf) : '';
  53010. }
  53011. /***/ }),
  53012. /***/ 4368:
  53013. /***/ ((module, exports, __webpack_require__) => {
  53014. /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  53015. /* eslint-disable node/no-deprecated-api */
  53016. var buffer = __webpack_require__(365);
  53017. var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers
  53018. function copyProps(src, dst) {
  53019. for (var key in src) {
  53020. dst[key] = src[key];
  53021. }
  53022. }
  53023. if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
  53024. module.exports = buffer;
  53025. } else {
  53026. // Copy properties from require('buffer')
  53027. copyProps(buffer, exports);
  53028. exports.Buffer = SafeBuffer;
  53029. }
  53030. function SafeBuffer(arg, encodingOrOffset, length) {
  53031. return Buffer(arg, encodingOrOffset, length);
  53032. }
  53033. SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer
  53034. copyProps(Buffer, SafeBuffer);
  53035. SafeBuffer.from = function (arg, encodingOrOffset, length) {
  53036. if (typeof arg === 'number') {
  53037. throw new TypeError('Argument must not be a number');
  53038. }
  53039. return Buffer(arg, encodingOrOffset, length);
  53040. };
  53041. SafeBuffer.alloc = function (size, fill, encoding) {
  53042. if (typeof size !== 'number') {
  53043. throw new TypeError('Argument must be a number');
  53044. }
  53045. var buf = Buffer(size);
  53046. if (fill !== undefined) {
  53047. if (typeof encoding === 'string') {
  53048. buf.fill(fill, encoding);
  53049. } else {
  53050. buf.fill(fill);
  53051. }
  53052. } else {
  53053. buf.fill(0);
  53054. }
  53055. return buf;
  53056. };
  53057. SafeBuffer.allocUnsafe = function (size) {
  53058. if (typeof size !== 'number') {
  53059. throw new TypeError('Argument must be a number');
  53060. }
  53061. return Buffer(size);
  53062. };
  53063. SafeBuffer.allocUnsafeSlow = function (size) {
  53064. if (typeof size !== 'number') {
  53065. throw new TypeError('Argument must be a number');
  53066. }
  53067. return buffer.SlowBuffer(size);
  53068. };
  53069. /***/ }),
  53070. /***/ 8016:
  53071. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  53072. /**
  53073. * Module exports.
  53074. */
  53075. module.exports = deprecate;
  53076. /**
  53077. * Mark that a method should not be used.
  53078. * Returns a modified function which warns once by default.
  53079. *
  53080. * If `localStorage.noDeprecation = true` is set, then it is a no-op.
  53081. *
  53082. * If `localStorage.throwDeprecation = true` is set, then deprecated functions
  53083. * will throw an Error when invoked.
  53084. *
  53085. * If `localStorage.traceDeprecation = true` is set, then deprecated functions
  53086. * will invoke `console.trace()` instead of `console.error()`.
  53087. *
  53088. * @param {Function} fn - the function to deprecate
  53089. * @param {String} msg - the string to print to the console when `fn` is invoked
  53090. * @returns {Function} a new "deprecated" version of `fn`
  53091. * @api public
  53092. */
  53093. function deprecate(fn, msg) {
  53094. if (config('noDeprecation')) {
  53095. return fn;
  53096. }
  53097. var warned = false;
  53098. function deprecated() {
  53099. if (!warned) {
  53100. if (config('throwDeprecation')) {
  53101. throw new Error(msg);
  53102. } else if (config('traceDeprecation')) {
  53103. console.trace(msg);
  53104. } else {
  53105. console.warn(msg);
  53106. }
  53107. warned = true;
  53108. }
  53109. return fn.apply(this, arguments);
  53110. }
  53111. return deprecated;
  53112. }
  53113. /**
  53114. * Checks `localStorage` for boolean values for the given `name`.
  53115. *
  53116. * @param {String} name
  53117. * @returns {Boolean}
  53118. * @api private
  53119. */
  53120. function config(name) {
  53121. // accessing global.localStorage can trigger a DOMException in sandboxed iframes
  53122. try {
  53123. if (!__webpack_require__.g.localStorage) return false;
  53124. } catch (_) {
  53125. return false;
  53126. }
  53127. var val = __webpack_require__.g.localStorage[name];
  53128. if (null == val) return false;
  53129. return String(val).toLowerCase() === 'true';
  53130. }
  53131. /***/ }),
  53132. /***/ 8538:
  53133. /***/ ((module) => {
  53134. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  53135. module.exports = function isBuffer(arg) {
  53136. return arg && _typeof(arg) === 'object' && typeof arg.copy === 'function' && typeof arg.fill === 'function' && typeof arg.readUInt8 === 'function';
  53137. };
  53138. /***/ }),
  53139. /***/ 9957:
  53140. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  53141. "use strict";
  53142. // Currently in sync with Node.js lib/internal/util/types.js
  53143. // https://github.com/nodejs/node/commit/112cc7c27551254aa2b17098fb774867f05ed0d9
  53144. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  53145. var isArgumentsObject = __webpack_require__(2755);
  53146. var isGeneratorFunction = __webpack_require__(6738);
  53147. var whichTypedArray = __webpack_require__(1482);
  53148. var isTypedArray = __webpack_require__(7913);
  53149. function uncurryThis(f) {
  53150. return f.call.bind(f);
  53151. }
  53152. var BigIntSupported = typeof BigInt !== 'undefined';
  53153. var SymbolSupported = typeof Symbol !== 'undefined';
  53154. var ObjectToString = uncurryThis(Object.prototype.toString);
  53155. var numberValue = uncurryThis(Number.prototype.valueOf);
  53156. var stringValue = uncurryThis(String.prototype.valueOf);
  53157. var booleanValue = uncurryThis(Boolean.prototype.valueOf);
  53158. if (BigIntSupported) {
  53159. var bigIntValue = uncurryThis(BigInt.prototype.valueOf);
  53160. }
  53161. if (SymbolSupported) {
  53162. var symbolValue = uncurryThis(Symbol.prototype.valueOf);
  53163. }
  53164. function checkBoxedPrimitive(value, prototypeValueOf) {
  53165. if (_typeof(value) !== 'object') {
  53166. return false;
  53167. }
  53168. try {
  53169. prototypeValueOf(value);
  53170. return true;
  53171. } catch (e) {
  53172. return false;
  53173. }
  53174. }
  53175. exports.isArgumentsObject = isArgumentsObject;
  53176. exports.isGeneratorFunction = isGeneratorFunction;
  53177. exports.isTypedArray = isTypedArray; // Taken from here and modified for better browser support
  53178. // https://github.com/sindresorhus/p-is-promise/blob/cda35a513bda03f977ad5cde3a079d237e82d7ef/index.js
  53179. function isPromise(input) {
  53180. return typeof Promise !== 'undefined' && input instanceof Promise || input !== null && _typeof(input) === 'object' && typeof input.then === 'function' && typeof input["catch"] === 'function';
  53181. }
  53182. exports.isPromise = isPromise;
  53183. function isArrayBufferView(value) {
  53184. if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) {
  53185. return ArrayBuffer.isView(value);
  53186. }
  53187. return isTypedArray(value) || isDataView(value);
  53188. }
  53189. exports.isArrayBufferView = isArrayBufferView;
  53190. function isUint8Array(value) {
  53191. return whichTypedArray(value) === 'Uint8Array';
  53192. }
  53193. exports.isUint8Array = isUint8Array;
  53194. function isUint8ClampedArray(value) {
  53195. return whichTypedArray(value) === 'Uint8ClampedArray';
  53196. }
  53197. exports.isUint8ClampedArray = isUint8ClampedArray;
  53198. function isUint16Array(value) {
  53199. return whichTypedArray(value) === 'Uint16Array';
  53200. }
  53201. exports.isUint16Array = isUint16Array;
  53202. function isUint32Array(value) {
  53203. return whichTypedArray(value) === 'Uint32Array';
  53204. }
  53205. exports.isUint32Array = isUint32Array;
  53206. function isInt8Array(value) {
  53207. return whichTypedArray(value) === 'Int8Array';
  53208. }
  53209. exports.isInt8Array = isInt8Array;
  53210. function isInt16Array(value) {
  53211. return whichTypedArray(value) === 'Int16Array';
  53212. }
  53213. exports.isInt16Array = isInt16Array;
  53214. function isInt32Array(value) {
  53215. return whichTypedArray(value) === 'Int32Array';
  53216. }
  53217. exports.isInt32Array = isInt32Array;
  53218. function isFloat32Array(value) {
  53219. return whichTypedArray(value) === 'Float32Array';
  53220. }
  53221. exports.isFloat32Array = isFloat32Array;
  53222. function isFloat64Array(value) {
  53223. return whichTypedArray(value) === 'Float64Array';
  53224. }
  53225. exports.isFloat64Array = isFloat64Array;
  53226. function isBigInt64Array(value) {
  53227. return whichTypedArray(value) === 'BigInt64Array';
  53228. }
  53229. exports.isBigInt64Array = isBigInt64Array;
  53230. function isBigUint64Array(value) {
  53231. return whichTypedArray(value) === 'BigUint64Array';
  53232. }
  53233. exports.isBigUint64Array = isBigUint64Array;
  53234. function isMapToString(value) {
  53235. return ObjectToString(value) === '[object Map]';
  53236. }
  53237. isMapToString.working = typeof Map !== 'undefined' && isMapToString(new Map());
  53238. function isMap(value) {
  53239. if (typeof Map === 'undefined') {
  53240. return false;
  53241. }
  53242. return isMapToString.working ? isMapToString(value) : value instanceof Map;
  53243. }
  53244. exports.isMap = isMap;
  53245. function isSetToString(value) {
  53246. return ObjectToString(value) === '[object Set]';
  53247. }
  53248. isSetToString.working = typeof Set !== 'undefined' && isSetToString(new Set());
  53249. function isSet(value) {
  53250. if (typeof Set === 'undefined') {
  53251. return false;
  53252. }
  53253. return isSetToString.working ? isSetToString(value) : value instanceof Set;
  53254. }
  53255. exports.isSet = isSet;
  53256. function isWeakMapToString(value) {
  53257. return ObjectToString(value) === '[object WeakMap]';
  53258. }
  53259. isWeakMapToString.working = typeof WeakMap !== 'undefined' && isWeakMapToString(new WeakMap());
  53260. function isWeakMap(value) {
  53261. if (typeof WeakMap === 'undefined') {
  53262. return false;
  53263. }
  53264. return isWeakMapToString.working ? isWeakMapToString(value) : value instanceof WeakMap;
  53265. }
  53266. exports.isWeakMap = isWeakMap;
  53267. function isWeakSetToString(value) {
  53268. return ObjectToString(value) === '[object WeakSet]';
  53269. }
  53270. isWeakSetToString.working = typeof WeakSet !== 'undefined' && isWeakSetToString(new WeakSet());
  53271. function isWeakSet(value) {
  53272. return isWeakSetToString(value);
  53273. }
  53274. exports.isWeakSet = isWeakSet;
  53275. function isArrayBufferToString(value) {
  53276. return ObjectToString(value) === '[object ArrayBuffer]';
  53277. }
  53278. isArrayBufferToString.working = typeof ArrayBuffer !== 'undefined' && isArrayBufferToString(new ArrayBuffer());
  53279. function isArrayBuffer(value) {
  53280. if (typeof ArrayBuffer === 'undefined') {
  53281. return false;
  53282. }
  53283. return isArrayBufferToString.working ? isArrayBufferToString(value) : value instanceof ArrayBuffer;
  53284. }
  53285. exports.isArrayBuffer = isArrayBuffer;
  53286. function isDataViewToString(value) {
  53287. return ObjectToString(value) === '[object DataView]';
  53288. }
  53289. isDataViewToString.working = typeof ArrayBuffer !== 'undefined' && typeof DataView !== 'undefined' && isDataViewToString(new DataView(new ArrayBuffer(1), 0, 1));
  53290. function isDataView(value) {
  53291. if (typeof DataView === 'undefined') {
  53292. return false;
  53293. }
  53294. return isDataViewToString.working ? isDataViewToString(value) : value instanceof DataView;
  53295. }
  53296. exports.isDataView = isDataView; // Store a copy of SharedArrayBuffer in case it's deleted elsewhere
  53297. var SharedArrayBufferCopy = typeof SharedArrayBuffer !== 'undefined' ? SharedArrayBuffer : undefined;
  53298. function isSharedArrayBufferToString(value) {
  53299. return ObjectToString(value) === '[object SharedArrayBuffer]';
  53300. }
  53301. function isSharedArrayBuffer(value) {
  53302. if (typeof SharedArrayBufferCopy === 'undefined') {
  53303. return false;
  53304. }
  53305. if (typeof isSharedArrayBufferToString.working === 'undefined') {
  53306. isSharedArrayBufferToString.working = isSharedArrayBufferToString(new SharedArrayBufferCopy());
  53307. }
  53308. return isSharedArrayBufferToString.working ? isSharedArrayBufferToString(value) : value instanceof SharedArrayBufferCopy;
  53309. }
  53310. exports.isSharedArrayBuffer = isSharedArrayBuffer;
  53311. function isAsyncFunction(value) {
  53312. return ObjectToString(value) === '[object AsyncFunction]';
  53313. }
  53314. exports.isAsyncFunction = isAsyncFunction;
  53315. function isMapIterator(value) {
  53316. return ObjectToString(value) === '[object Map Iterator]';
  53317. }
  53318. exports.isMapIterator = isMapIterator;
  53319. function isSetIterator(value) {
  53320. return ObjectToString(value) === '[object Set Iterator]';
  53321. }
  53322. exports.isSetIterator = isSetIterator;
  53323. function isGeneratorObject(value) {
  53324. return ObjectToString(value) === '[object Generator]';
  53325. }
  53326. exports.isGeneratorObject = isGeneratorObject;
  53327. function isWebAssemblyCompiledModule(value) {
  53328. return ObjectToString(value) === '[object WebAssembly.Module]';
  53329. }
  53330. exports.isWebAssemblyCompiledModule = isWebAssemblyCompiledModule;
  53331. function isNumberObject(value) {
  53332. return checkBoxedPrimitive(value, numberValue);
  53333. }
  53334. exports.isNumberObject = isNumberObject;
  53335. function isStringObject(value) {
  53336. return checkBoxedPrimitive(value, stringValue);
  53337. }
  53338. exports.isStringObject = isStringObject;
  53339. function isBooleanObject(value) {
  53340. return checkBoxedPrimitive(value, booleanValue);
  53341. }
  53342. exports.isBooleanObject = isBooleanObject;
  53343. function isBigIntObject(value) {
  53344. return BigIntSupported && checkBoxedPrimitive(value, bigIntValue);
  53345. }
  53346. exports.isBigIntObject = isBigIntObject;
  53347. function isSymbolObject(value) {
  53348. return SymbolSupported && checkBoxedPrimitive(value, symbolValue);
  53349. }
  53350. exports.isSymbolObject = isSymbolObject;
  53351. function isBoxedPrimitive(value) {
  53352. return isNumberObject(value) || isStringObject(value) || isBooleanObject(value) || isBigIntObject(value) || isSymbolObject(value);
  53353. }
  53354. exports.isBoxedPrimitive = isBoxedPrimitive;
  53355. function isAnyArrayBuffer(value) {
  53356. return typeof Uint8Array !== 'undefined' && (isArrayBuffer(value) || isSharedArrayBuffer(value));
  53357. }
  53358. exports.isAnyArrayBuffer = isAnyArrayBuffer;
  53359. ['isProxy', 'isExternal', 'isModuleNamespaceObject'].forEach(function (method) {
  53360. Object.defineProperty(exports, method, {
  53361. enumerable: false,
  53362. value: function value() {
  53363. throw new Error(method + ' is not supported in userland');
  53364. }
  53365. });
  53366. });
  53367. /***/ }),
  53368. /***/ 161:
  53369. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  53370. function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
  53371. // Copyright Joyent, Inc. and other Node contributors.
  53372. //
  53373. // Permission is hereby granted, free of charge, to any person obtaining a
  53374. // copy of this software and associated documentation files (the
  53375. // "Software"), to deal in the Software without restriction, including
  53376. // without limitation the rights to use, copy, modify, merge, publish,
  53377. // distribute, sublicense, and/or sell copies of the Software, and to permit
  53378. // persons to whom the Software is furnished to do so, subject to the
  53379. // following conditions:
  53380. //
  53381. // The above copyright notice and this permission notice shall be included
  53382. // in all copies or substantial portions of the Software.
  53383. //
  53384. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  53385. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  53386. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  53387. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  53388. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  53389. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  53390. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  53391. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors(obj) {
  53392. var keys = Object.keys(obj);
  53393. var descriptors = {};
  53394. for (var i = 0; i < keys.length; i++) {
  53395. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  53396. }
  53397. return descriptors;
  53398. };
  53399. var formatRegExp = /%[sdj%]/g;
  53400. exports.format = function (f) {
  53401. if (!isString(f)) {
  53402. var objects = [];
  53403. for (var i = 0; i < arguments.length; i++) {
  53404. objects.push(inspect(arguments[i]));
  53405. }
  53406. return objects.join(' ');
  53407. }
  53408. var i = 1;
  53409. var args = arguments;
  53410. var len = args.length;
  53411. var str = String(f).replace(formatRegExp, function (x) {
  53412. if (x === '%%') return '%';
  53413. if (i >= len) return x;
  53414. switch (x) {
  53415. case '%s':
  53416. return String(args[i++]);
  53417. case '%d':
  53418. return Number(args[i++]);
  53419. case '%j':
  53420. try {
  53421. return JSON.stringify(args[i++]);
  53422. } catch (_) {
  53423. return '[Circular]';
  53424. }
  53425. default:
  53426. return x;
  53427. }
  53428. });
  53429. for (var x = args[i]; i < len; x = args[++i]) {
  53430. if (isNull(x) || !isObject(x)) {
  53431. str += ' ' + x;
  53432. } else {
  53433. str += ' ' + inspect(x);
  53434. }
  53435. }
  53436. return str;
  53437. }; // Mark that a method should not be used.
  53438. // Returns a modified function which warns once by default.
  53439. // If --no-deprecation is set, then it is a no-op.
  53440. exports.deprecate = function (fn, msg) {
  53441. if (typeof ({env:{}}) !== 'undefined' && ({env:{}}).noDeprecation === true) {
  53442. return fn;
  53443. } // Allow for deprecating things in the process of starting up.
  53444. if (typeof ({env:{}}) === 'undefined') {
  53445. return function () {
  53446. return exports.deprecate(fn, msg).apply(this, arguments);
  53447. };
  53448. }
  53449. var warned = false;
  53450. function deprecated() {
  53451. if (!warned) {
  53452. if (({env:{}}).throwDeprecation) {
  53453. throw new Error(msg);
  53454. } else if (({env:{}}).traceDeprecation) {
  53455. console.trace(msg);
  53456. } else {
  53457. console.error(msg);
  53458. }
  53459. warned = true;
  53460. }
  53461. return fn.apply(this, arguments);
  53462. }
  53463. return deprecated;
  53464. };
  53465. var debugs = {};
  53466. var debugEnvRegex = /^$/;
  53467. if (({env:{}}).env.NODE_DEBUG) {
  53468. var debugEnv = ({env:{}}).env.NODE_DEBUG;
  53469. debugEnv = debugEnv.replace(/[|\\{}()[\]^$+?.]/g, '\\$&').replace(/\*/g, '.*').replace(/,/g, '$|^').toUpperCase();
  53470. debugEnvRegex = new RegExp('^' + debugEnv + '$', 'i');
  53471. }
  53472. exports.debuglog = function (set) {
  53473. set = set.toUpperCase();
  53474. if (!debugs[set]) {
  53475. if (debugEnvRegex.test(set)) {
  53476. var pid = ({env:{}}).pid;
  53477. debugs[set] = function () {
  53478. var msg = exports.format.apply(exports, arguments);
  53479. console.error('%s %d: %s', set, pid, msg);
  53480. };
  53481. } else {
  53482. debugs[set] = function () {};
  53483. }
  53484. }
  53485. return debugs[set];
  53486. };
  53487. /**
  53488. * Echos the value of a value. Trys to print the value out
  53489. * in the best way possible given the different types.
  53490. *
  53491. * @param {Object} obj The object to print out.
  53492. * @param {Object} opts Optional options object that alters the output.
  53493. */
  53494. /* legacy: obj, showHidden, depth, colors*/
  53495. function inspect(obj, opts) {
  53496. // default options
  53497. var ctx = {
  53498. seen: [],
  53499. stylize: stylizeNoColor
  53500. }; // legacy...
  53501. if (arguments.length >= 3) ctx.depth = arguments[2];
  53502. if (arguments.length >= 4) ctx.colors = arguments[3];
  53503. if (isBoolean(opts)) {
  53504. // legacy...
  53505. ctx.showHidden = opts;
  53506. } else if (opts) {
  53507. // got an "options" object
  53508. exports._extend(ctx, opts);
  53509. } // set default options
  53510. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  53511. if (isUndefined(ctx.depth)) ctx.depth = 2;
  53512. if (isUndefined(ctx.colors)) ctx.colors = false;
  53513. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  53514. if (ctx.colors) ctx.stylize = stylizeWithColor;
  53515. return formatValue(ctx, obj, ctx.depth);
  53516. }
  53517. exports.inspect = inspect; // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  53518. inspect.colors = {
  53519. 'bold': [1, 22],
  53520. 'italic': [3, 23],
  53521. 'underline': [4, 24],
  53522. 'inverse': [7, 27],
  53523. 'white': [37, 39],
  53524. 'grey': [90, 39],
  53525. 'black': [30, 39],
  53526. 'blue': [34, 39],
  53527. 'cyan': [36, 39],
  53528. 'green': [32, 39],
  53529. 'magenta': [35, 39],
  53530. 'red': [31, 39],
  53531. 'yellow': [33, 39]
  53532. }; // Don't use 'blue' not visible on cmd.exe
  53533. inspect.styles = {
  53534. 'special': 'cyan',
  53535. 'number': 'yellow',
  53536. 'boolean': 'yellow',
  53537. 'undefined': 'grey',
  53538. 'null': 'bold',
  53539. 'string': 'green',
  53540. 'date': 'magenta',
  53541. // "name": intentionally not styling
  53542. 'regexp': 'red'
  53543. };
  53544. function stylizeWithColor(str, styleType) {
  53545. var style = inspect.styles[styleType];
  53546. if (style) {
  53547. return "\x1B[" + inspect.colors[style][0] + 'm' + str + "\x1B[" + inspect.colors[style][1] + 'm';
  53548. } else {
  53549. return str;
  53550. }
  53551. }
  53552. function stylizeNoColor(str, styleType) {
  53553. return str;
  53554. }
  53555. function arrayToHash(array) {
  53556. var hash = {};
  53557. array.forEach(function (val, idx) {
  53558. hash[val] = true;
  53559. });
  53560. return hash;
  53561. }
  53562. function formatValue(ctx, value, recurseTimes) {
  53563. // Provide a hook for user-specified inspect functions.
  53564. // Check that value is an object with an inspect function on it
  53565. if (ctx.customInspect && value && isFunction(value.inspect) && // Filter out the util module, it's inspect function is special
  53566. value.inspect !== exports.inspect && // Also filter out any prototype objects using the circular check.
  53567. !(value.constructor && value.constructor.prototype === value)) {
  53568. var ret = value.inspect(recurseTimes, ctx);
  53569. if (!isString(ret)) {
  53570. ret = formatValue(ctx, ret, recurseTimes);
  53571. }
  53572. return ret;
  53573. } // Primitive types cannot have properties
  53574. var primitive = formatPrimitive(ctx, value);
  53575. if (primitive) {
  53576. return primitive;
  53577. } // Look up the keys of the object.
  53578. var keys = Object.keys(value);
  53579. var visibleKeys = arrayToHash(keys);
  53580. if (ctx.showHidden) {
  53581. keys = Object.getOwnPropertyNames(value);
  53582. } // IE doesn't make error fields non-enumerable
  53583. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  53584. if (isError(value) && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  53585. return formatError(value);
  53586. } // Some type of object without properties can be shortcutted.
  53587. if (keys.length === 0) {
  53588. if (isFunction(value)) {
  53589. var name = value.name ? ': ' + value.name : '';
  53590. return ctx.stylize('[Function' + name + ']', 'special');
  53591. }
  53592. if (isRegExp(value)) {
  53593. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  53594. }
  53595. if (isDate(value)) {
  53596. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  53597. }
  53598. if (isError(value)) {
  53599. return formatError(value);
  53600. }
  53601. }
  53602. var base = '',
  53603. array = false,
  53604. braces = ['{', '}']; // Make Array say that they are Array
  53605. if (isArray(value)) {
  53606. array = true;
  53607. braces = ['[', ']'];
  53608. } // Make functions say that they are functions
  53609. if (isFunction(value)) {
  53610. var n = value.name ? ': ' + value.name : '';
  53611. base = ' [Function' + n + ']';
  53612. } // Make RegExps say that they are RegExps
  53613. if (isRegExp(value)) {
  53614. base = ' ' + RegExp.prototype.toString.call(value);
  53615. } // Make dates with properties first say the date
  53616. if (isDate(value)) {
  53617. base = ' ' + Date.prototype.toUTCString.call(value);
  53618. } // Make error with message first say the error
  53619. if (isError(value)) {
  53620. base = ' ' + formatError(value);
  53621. }
  53622. if (keys.length === 0 && (!array || value.length == 0)) {
  53623. return braces[0] + base + braces[1];
  53624. }
  53625. if (recurseTimes < 0) {
  53626. if (isRegExp(value)) {
  53627. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  53628. } else {
  53629. return ctx.stylize('[Object]', 'special');
  53630. }
  53631. }
  53632. ctx.seen.push(value);
  53633. var output;
  53634. if (array) {
  53635. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  53636. } else {
  53637. output = keys.map(function (key) {
  53638. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  53639. });
  53640. }
  53641. ctx.seen.pop();
  53642. return reduceToSingleString(output, base, braces);
  53643. }
  53644. function formatPrimitive(ctx, value) {
  53645. if (isUndefined(value)) return ctx.stylize('undefined', 'undefined');
  53646. if (isString(value)) {
  53647. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '').replace(/'/g, "\\'").replace(/\\"/g, '"') + '\'';
  53648. return ctx.stylize(simple, 'string');
  53649. }
  53650. if (isNumber(value)) return ctx.stylize('' + value, 'number');
  53651. if (isBoolean(value)) return ctx.stylize('' + value, 'boolean'); // For some reason typeof null is "object", so special case here.
  53652. if (isNull(value)) return ctx.stylize('null', 'null');
  53653. }
  53654. function formatError(value) {
  53655. return '[' + Error.prototype.toString.call(value) + ']';
  53656. }
  53657. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  53658. var output = [];
  53659. for (var i = 0, l = value.length; i < l; ++i) {
  53660. if (hasOwnProperty(value, String(i))) {
  53661. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), true));
  53662. } else {
  53663. output.push('');
  53664. }
  53665. }
  53666. keys.forEach(function (key) {
  53667. if (!key.match(/^\d+$/)) {
  53668. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, true));
  53669. }
  53670. });
  53671. return output;
  53672. }
  53673. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  53674. var name, str, desc;
  53675. desc = Object.getOwnPropertyDescriptor(value, key) || {
  53676. value: value[key]
  53677. };
  53678. if (desc.get) {
  53679. if (desc.set) {
  53680. str = ctx.stylize('[Getter/Setter]', 'special');
  53681. } else {
  53682. str = ctx.stylize('[Getter]', 'special');
  53683. }
  53684. } else {
  53685. if (desc.set) {
  53686. str = ctx.stylize('[Setter]', 'special');
  53687. }
  53688. }
  53689. if (!hasOwnProperty(visibleKeys, key)) {
  53690. name = '[' + key + ']';
  53691. }
  53692. if (!str) {
  53693. if (ctx.seen.indexOf(desc.value) < 0) {
  53694. if (isNull(recurseTimes)) {
  53695. str = formatValue(ctx, desc.value, null);
  53696. } else {
  53697. str = formatValue(ctx, desc.value, recurseTimes - 1);
  53698. }
  53699. if (str.indexOf('\n') > -1) {
  53700. if (array) {
  53701. str = str.split('\n').map(function (line) {
  53702. return ' ' + line;
  53703. }).join('\n').substr(2);
  53704. } else {
  53705. str = '\n' + str.split('\n').map(function (line) {
  53706. return ' ' + line;
  53707. }).join('\n');
  53708. }
  53709. }
  53710. } else {
  53711. str = ctx.stylize('[Circular]', 'special');
  53712. }
  53713. }
  53714. if (isUndefined(name)) {
  53715. if (array && key.match(/^\d+$/)) {
  53716. return str;
  53717. }
  53718. name = JSON.stringify('' + key);
  53719. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  53720. name = name.substr(1, name.length - 2);
  53721. name = ctx.stylize(name, 'name');
  53722. } else {
  53723. name = name.replace(/'/g, "\\'").replace(/\\"/g, '"').replace(/(^"|"$)/g, "'");
  53724. name = ctx.stylize(name, 'string');
  53725. }
  53726. }
  53727. return name + ': ' + str;
  53728. }
  53729. function reduceToSingleString(output, base, braces) {
  53730. var numLinesEst = 0;
  53731. var length = output.reduce(function (prev, cur) {
  53732. numLinesEst++;
  53733. if (cur.indexOf('\n') >= 0) numLinesEst++;
  53734. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  53735. }, 0);
  53736. if (length > 60) {
  53737. return braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1];
  53738. }
  53739. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  53740. } // NOTE: These type checking functions intentionally don't use `instanceof`
  53741. // because it is fragile and can be easily faked with `Object.create()`.
  53742. exports.types = __webpack_require__(9957);
  53743. function isArray(ar) {
  53744. return Array.isArray(ar);
  53745. }
  53746. exports.isArray = isArray;
  53747. function isBoolean(arg) {
  53748. return typeof arg === 'boolean';
  53749. }
  53750. exports.isBoolean = isBoolean;
  53751. function isNull(arg) {
  53752. return arg === null;
  53753. }
  53754. exports.isNull = isNull;
  53755. function isNullOrUndefined(arg) {
  53756. return arg == null;
  53757. }
  53758. exports.isNullOrUndefined = isNullOrUndefined;
  53759. function isNumber(arg) {
  53760. return typeof arg === 'number';
  53761. }
  53762. exports.isNumber = isNumber;
  53763. function isString(arg) {
  53764. return typeof arg === 'string';
  53765. }
  53766. exports.isString = isString;
  53767. function isSymbol(arg) {
  53768. return _typeof(arg) === 'symbol';
  53769. }
  53770. exports.isSymbol = isSymbol;
  53771. function isUndefined(arg) {
  53772. return arg === void 0;
  53773. }
  53774. exports.isUndefined = isUndefined;
  53775. function isRegExp(re) {
  53776. return isObject(re) && objectToString(re) === '[object RegExp]';
  53777. }
  53778. exports.isRegExp = isRegExp;
  53779. exports.types.isRegExp = isRegExp;
  53780. function isObject(arg) {
  53781. return _typeof(arg) === 'object' && arg !== null;
  53782. }
  53783. exports.isObject = isObject;
  53784. function isDate(d) {
  53785. return isObject(d) && objectToString(d) === '[object Date]';
  53786. }
  53787. exports.isDate = isDate;
  53788. exports.types.isDate = isDate;
  53789. function isError(e) {
  53790. return isObject(e) && (objectToString(e) === '[object Error]' || e instanceof Error);
  53791. }
  53792. exports.isError = isError;
  53793. exports.types.isNativeError = isError;
  53794. function isFunction(arg) {
  53795. return typeof arg === 'function';
  53796. }
  53797. exports.isFunction = isFunction;
  53798. function isPrimitive(arg) {
  53799. return arg === null || typeof arg === 'boolean' || typeof arg === 'number' || typeof arg === 'string' || _typeof(arg) === 'symbol' || // ES6 symbol
  53800. typeof arg === 'undefined';
  53801. }
  53802. exports.isPrimitive = isPrimitive;
  53803. exports.isBuffer = __webpack_require__(8538);
  53804. function objectToString(o) {
  53805. return Object.prototype.toString.call(o);
  53806. }
  53807. function pad(n) {
  53808. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  53809. }
  53810. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34
  53811. function timestamp() {
  53812. var d = new Date();
  53813. var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':');
  53814. return [d.getDate(), months[d.getMonth()], time].join(' ');
  53815. } // log is just a thin wrapper to console.log that prepends a timestamp
  53816. exports.log = function () {
  53817. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  53818. };
  53819. /**
  53820. * Inherit the prototype methods from one constructor into another.
  53821. *
  53822. * The Function.prototype.inherits from lang.js rewritten as a standalone
  53823. * function (not on Function.prototype). NOTE: If this file is to be loaded
  53824. * during bootstrapping this function needs to be rewritten using some native
  53825. * functions as prototype setup using normal JavaScript does not work as
  53826. * expected during bootstrapping (see mirror.js in r114903).
  53827. *
  53828. * @param {function} ctor Constructor function which needs to inherit the
  53829. * prototype.
  53830. * @param {function} superCtor Constructor function to inherit prototype from.
  53831. */
  53832. exports.inherits = __webpack_require__(376);
  53833. exports._extend = function (origin, add) {
  53834. // Don't do anything if add isn't an object
  53835. if (!add || !isObject(add)) return origin;
  53836. var keys = Object.keys(add);
  53837. var i = keys.length;
  53838. while (i--) {
  53839. origin[keys[i]] = add[keys[i]];
  53840. }
  53841. return origin;
  53842. };
  53843. function hasOwnProperty(obj, prop) {
  53844. return Object.prototype.hasOwnProperty.call(obj, prop);
  53845. }
  53846. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  53847. exports.promisify = function promisify(original) {
  53848. if (typeof original !== 'function') throw new TypeError('The "original" argument must be of type Function');
  53849. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  53850. var fn = original[kCustomPromisifiedSymbol];
  53851. if (typeof fn !== 'function') {
  53852. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  53853. }
  53854. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  53855. value: fn,
  53856. enumerable: false,
  53857. writable: false,
  53858. configurable: true
  53859. });
  53860. return fn;
  53861. }
  53862. function fn() {
  53863. var promiseResolve, promiseReject;
  53864. var promise = new Promise(function (resolve, reject) {
  53865. promiseResolve = resolve;
  53866. promiseReject = reject;
  53867. });
  53868. var args = [];
  53869. for (var i = 0; i < arguments.length; i++) {
  53870. args.push(arguments[i]);
  53871. }
  53872. args.push(function (err, value) {
  53873. if (err) {
  53874. promiseReject(err);
  53875. } else {
  53876. promiseResolve(value);
  53877. }
  53878. });
  53879. try {
  53880. original.apply(this, args);
  53881. } catch (err) {
  53882. promiseReject(err);
  53883. }
  53884. return promise;
  53885. }
  53886. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  53887. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  53888. value: fn,
  53889. enumerable: false,
  53890. writable: false,
  53891. configurable: true
  53892. });
  53893. return Object.defineProperties(fn, getOwnPropertyDescriptors(original));
  53894. };
  53895. exports.promisify.custom = kCustomPromisifiedSymbol;
  53896. function callbackifyOnRejected(reason, cb) {
  53897. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  53898. // Because `null` is a special error value in callbacks which means "no error
  53899. // occurred", we error-wrap so the callback consumer can distinguish between
  53900. // "the promise rejected with null" or "the promise fulfilled with undefined".
  53901. if (!reason) {
  53902. var newReason = new Error('Promise was rejected with a falsy value');
  53903. newReason.reason = reason;
  53904. reason = newReason;
  53905. }
  53906. return cb(reason);
  53907. }
  53908. function callbackify(original) {
  53909. if (typeof original !== 'function') {
  53910. throw new TypeError('The "original" argument must be of type Function');
  53911. } // We DO NOT return the promise as it gives the user a false sense that
  53912. // the promise is actually somehow related to the callback's execution
  53913. // and that the callback throwing will reject the promise.
  53914. function callbackified() {
  53915. var args = [];
  53916. for (var i = 0; i < arguments.length; i++) {
  53917. args.push(arguments[i]);
  53918. }
  53919. var maybeCb = args.pop();
  53920. if (typeof maybeCb !== 'function') {
  53921. throw new TypeError('The last argument must be of type Function');
  53922. }
  53923. var self = this;
  53924. var cb = function cb() {
  53925. return maybeCb.apply(self, arguments);
  53926. }; // In true node style we process the callback on `nextTick` with all the
  53927. // implications (stack, `uncaughtException`, `async_hooks`)
  53928. original.apply(this, args).then(function (ret) {
  53929. ({env:{}}).nextTick(cb.bind(null, null, ret));
  53930. }, function (rej) {
  53931. ({env:{}}).nextTick(callbackifyOnRejected.bind(null, rej, cb));
  53932. });
  53933. }
  53934. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  53935. Object.defineProperties(callbackified, getOwnPropertyDescriptors(original));
  53936. return callbackified;
  53937. }
  53938. exports.callbackify = callbackify;
  53939. /***/ }),
  53940. /***/ 1482:
  53941. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  53942. "use strict";
  53943. var forEach = __webpack_require__(5337);
  53944. var availableTypedArrays = __webpack_require__(6461);
  53945. var callBound = __webpack_require__(8780);
  53946. var $toString = callBound('Object.prototype.toString');
  53947. var hasToStringTag = __webpack_require__(5994)();
  53948. var g = typeof globalThis === 'undefined' ? __webpack_require__.g : globalThis;
  53949. var typedArrays = availableTypedArrays();
  53950. var $slice = callBound('String.prototype.slice');
  53951. var toStrTags = {};
  53952. var gOPD = __webpack_require__(3999);
  53953. var getPrototypeOf = Object.getPrototypeOf; // require('getprototypeof');
  53954. if (hasToStringTag && gOPD && getPrototypeOf) {
  53955. forEach(typedArrays, function (typedArray) {
  53956. if (typeof g[typedArray] === 'function') {
  53957. var arr = new g[typedArray]();
  53958. if (Symbol.toStringTag in arr) {
  53959. var proto = getPrototypeOf(arr);
  53960. var descriptor = gOPD(proto, Symbol.toStringTag);
  53961. if (!descriptor) {
  53962. var superProto = getPrototypeOf(proto);
  53963. descriptor = gOPD(superProto, Symbol.toStringTag);
  53964. }
  53965. toStrTags[typedArray] = descriptor.get;
  53966. }
  53967. }
  53968. });
  53969. }
  53970. var tryTypedArrays = function tryAllTypedArrays(value) {
  53971. var foundName = false;
  53972. forEach(toStrTags, function (getter, typedArray) {
  53973. if (!foundName) {
  53974. try {
  53975. var name = getter.call(value);
  53976. if (name === typedArray) {
  53977. foundName = name;
  53978. }
  53979. } catch (e) {}
  53980. }
  53981. });
  53982. return foundName;
  53983. };
  53984. var isTypedArray = __webpack_require__(7913);
  53985. module.exports = function whichTypedArray(value) {
  53986. if (!isTypedArray(value)) {
  53987. return false;
  53988. }
  53989. if (!hasToStringTag || !(Symbol.toStringTag in value)) {
  53990. return $slice($toString(value), 8, -1);
  53991. }
  53992. return tryTypedArrays(value);
  53993. };
  53994. /***/ }),
  53995. /***/ 6601:
  53996. /***/ (() => {
  53997. /* (ignored) */
  53998. /***/ }),
  53999. /***/ 9214:
  54000. /***/ (() => {
  54001. /* (ignored) */
  54002. /***/ }),
  54003. /***/ 2361:
  54004. /***/ (() => {
  54005. /* (ignored) */
  54006. /***/ }),
  54007. /***/ 4616:
  54008. /***/ (() => {
  54009. /* (ignored) */
  54010. /***/ }),
  54011. /***/ 6461:
  54012. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  54013. "use strict";
  54014. var possibleNames = ['BigInt64Array', 'BigUint64Array', 'Float32Array', 'Float64Array', 'Int16Array', 'Int32Array', 'Int8Array', 'Uint16Array', 'Uint32Array', 'Uint8Array', 'Uint8ClampedArray'];
  54015. var g = typeof globalThis === 'undefined' ? __webpack_require__.g : globalThis;
  54016. module.exports = function availableTypedArrays() {
  54017. var out = [];
  54018. for (var i = 0; i < possibleNames.length; i++) {
  54019. if (typeof g[possibleNames[i]] === 'function') {
  54020. out[out.length] = possibleNames[i];
  54021. }
  54022. }
  54023. return out;
  54024. };
  54025. /***/ }),
  54026. /***/ 3999:
  54027. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  54028. "use strict";
  54029. var GetIntrinsic = __webpack_require__(6893);
  54030. var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
  54031. if ($gOPD) {
  54032. try {
  54033. $gOPD([], 'length');
  54034. } catch (e) {
  54035. // IE 8 has a broken gOPD
  54036. $gOPD = null;
  54037. }
  54038. }
  54039. module.exports = $gOPD;
  54040. /***/ }),
  54041. /***/ 4946:
  54042. /***/ ((module) => {
  54043. "use strict";
  54044. module.exports = JSON.parse('{"aes-128-ecb":{"cipher":"AES","key":128,"iv":0,"mode":"ECB","type":"block"},"aes-192-ecb":{"cipher":"AES","key":192,"iv":0,"mode":"ECB","type":"block"},"aes-256-ecb":{"cipher":"AES","key":256,"iv":0,"mode":"ECB","type":"block"},"aes-128-cbc":{"cipher":"AES","key":128,"iv":16,"mode":"CBC","type":"block"},"aes-192-cbc":{"cipher":"AES","key":192,"iv":16,"mode":"CBC","type":"block"},"aes-256-cbc":{"cipher":"AES","key":256,"iv":16,"mode":"CBC","type":"block"},"aes128":{"cipher":"AES","key":128,"iv":16,"mode":"CBC","type":"block"},"aes192":{"cipher":"AES","key":192,"iv":16,"mode":"CBC","type":"block"},"aes256":{"cipher":"AES","key":256,"iv":16,"mode":"CBC","type":"block"},"aes-128-cfb":{"cipher":"AES","key":128,"iv":16,"mode":"CFB","type":"stream"},"aes-192-cfb":{"cipher":"AES","key":192,"iv":16,"mode":"CFB","type":"stream"},"aes-256-cfb":{"cipher":"AES","key":256,"iv":16,"mode":"CFB","type":"stream"},"aes-128-cfb8":{"cipher":"AES","key":128,"iv":16,"mode":"CFB8","type":"stream"},"aes-192-cfb8":{"cipher":"AES","key":192,"iv":16,"mode":"CFB8","type":"stream"},"aes-256-cfb8":{"cipher":"AES","key":256,"iv":16,"mode":"CFB8","type":"stream"},"aes-128-cfb1":{"cipher":"AES","key":128,"iv":16,"mode":"CFB1","type":"stream"},"aes-192-cfb1":{"cipher":"AES","key":192,"iv":16,"mode":"CFB1","type":"stream"},"aes-256-cfb1":{"cipher":"AES","key":256,"iv":16,"mode":"CFB1","type":"stream"},"aes-128-ofb":{"cipher":"AES","key":128,"iv":16,"mode":"OFB","type":"stream"},"aes-192-ofb":{"cipher":"AES","key":192,"iv":16,"mode":"OFB","type":"stream"},"aes-256-ofb":{"cipher":"AES","key":256,"iv":16,"mode":"OFB","type":"stream"},"aes-128-ctr":{"cipher":"AES","key":128,"iv":16,"mode":"CTR","type":"stream"},"aes-192-ctr":{"cipher":"AES","key":192,"iv":16,"mode":"CTR","type":"stream"},"aes-256-ctr":{"cipher":"AES","key":256,"iv":16,"mode":"CTR","type":"stream"},"aes-128-gcm":{"cipher":"AES","key":128,"iv":12,"mode":"GCM","type":"auth"},"aes-192-gcm":{"cipher":"AES","key":192,"iv":12,"mode":"GCM","type":"auth"},"aes-256-gcm":{"cipher":"AES","key":256,"iv":12,"mode":"GCM","type":"auth"}}');
  54045. /***/ }),
  54046. /***/ 5207:
  54047. /***/ ((module) => {
  54048. "use strict";
  54049. module.exports = JSON.parse('{"sha224WithRSAEncryption":{"sign":"rsa","hash":"sha224","id":"302d300d06096086480165030402040500041c"},"RSA-SHA224":{"sign":"ecdsa/rsa","hash":"sha224","id":"302d300d06096086480165030402040500041c"},"sha256WithRSAEncryption":{"sign":"rsa","hash":"sha256","id":"3031300d060960864801650304020105000420"},"RSA-SHA256":{"sign":"ecdsa/rsa","hash":"sha256","id":"3031300d060960864801650304020105000420"},"sha384WithRSAEncryption":{"sign":"rsa","hash":"sha384","id":"3041300d060960864801650304020205000430"},"RSA-SHA384":{"sign":"ecdsa/rsa","hash":"sha384","id":"3041300d060960864801650304020205000430"},"sha512WithRSAEncryption":{"sign":"rsa","hash":"sha512","id":"3051300d060960864801650304020305000440"},"RSA-SHA512":{"sign":"ecdsa/rsa","hash":"sha512","id":"3051300d060960864801650304020305000440"},"RSA-SHA1":{"sign":"rsa","hash":"sha1","id":"3021300906052b0e03021a05000414"},"ecdsa-with-SHA1":{"sign":"ecdsa","hash":"sha1","id":""},"sha256":{"sign":"ecdsa","hash":"sha256","id":""},"sha224":{"sign":"ecdsa","hash":"sha224","id":""},"sha384":{"sign":"ecdsa","hash":"sha384","id":""},"sha512":{"sign":"ecdsa","hash":"sha512","id":""},"DSA-SHA":{"sign":"dsa","hash":"sha1","id":""},"DSA-SHA1":{"sign":"dsa","hash":"sha1","id":""},"DSA":{"sign":"dsa","hash":"sha1","id":""},"DSA-WITH-SHA224":{"sign":"dsa","hash":"sha224","id":""},"DSA-SHA224":{"sign":"dsa","hash":"sha224","id":""},"DSA-WITH-SHA256":{"sign":"dsa","hash":"sha256","id":""},"DSA-SHA256":{"sign":"dsa","hash":"sha256","id":""},"DSA-WITH-SHA384":{"sign":"dsa","hash":"sha384","id":""},"DSA-SHA384":{"sign":"dsa","hash":"sha384","id":""},"DSA-WITH-SHA512":{"sign":"dsa","hash":"sha512","id":""},"DSA-SHA512":{"sign":"dsa","hash":"sha512","id":""},"DSA-RIPEMD160":{"sign":"dsa","hash":"rmd160","id":""},"ripemd160WithRSA":{"sign":"rsa","hash":"rmd160","id":"3021300906052b2403020105000414"},"RSA-RIPEMD160":{"sign":"rsa","hash":"rmd160","id":"3021300906052b2403020105000414"},"md5WithRSAEncryption":{"sign":"rsa","hash":"md5","id":"3020300c06082a864886f70d020505000410"},"RSA-MD5":{"sign":"rsa","hash":"md5","id":"3020300c06082a864886f70d020505000410"}}');
  54050. /***/ }),
  54051. /***/ 1308:
  54052. /***/ ((module) => {
  54053. "use strict";
  54054. module.exports = JSON.parse('{"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"}');
  54055. /***/ }),
  54056. /***/ 9799:
  54057. /***/ ((module) => {
  54058. "use strict";
  54059. module.exports = JSON.parse('{"modp1":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"},"modp2":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"},"modp5":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"},"modp14":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"},"modp15":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"},"modp16":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"},"modp17":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"},"modp18":{"gen":"02","prime":"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"}}');
  54060. /***/ }),
  54061. /***/ 8597:
  54062. /***/ ((module) => {
  54063. "use strict";
  54064. module.exports = {"i8":"6.5.4"};
  54065. /***/ }),
  54066. /***/ 2562:
  54067. /***/ ((module) => {
  54068. "use strict";
  54069. module.exports = JSON.parse('{"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"}');
  54070. /***/ })
  54071. /******/ });
  54072. /************************************************************************/
  54073. /******/ // The module cache
  54074. /******/ var __webpack_module_cache__ = {};
  54075. /******/
  54076. /******/ // The require function
  54077. /******/ function __webpack_require__(moduleId) {
  54078. /******/ // Check if module is in cache
  54079. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  54080. /******/ if (cachedModule !== undefined) {
  54081. /******/ return cachedModule.exports;
  54082. /******/ }
  54083. /******/ // Create a new module (and put it into the cache)
  54084. /******/ var module = __webpack_module_cache__[moduleId] = {
  54085. /******/ id: moduleId,
  54086. /******/ loaded: false,
  54087. /******/ exports: {}
  54088. /******/ };
  54089. /******/
  54090. /******/ // Execute the module function
  54091. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  54092. /******/
  54093. /******/ // Flag the module as loaded
  54094. /******/ module.loaded = true;
  54095. /******/
  54096. /******/ // Return the exports of the module
  54097. /******/ return module.exports;
  54098. /******/ }
  54099. /******/
  54100. /************************************************************************/
  54101. /******/ /* webpack/runtime/define property getters */
  54102. /******/ (() => {
  54103. /******/ // define getter functions for harmony exports
  54104. /******/ __webpack_require__.d = (exports, definition) => {
  54105. /******/ for(var key in definition) {
  54106. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  54107. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  54108. /******/ }
  54109. /******/ }
  54110. /******/ };
  54111. /******/ })();
  54112. /******/
  54113. /******/ /* webpack/runtime/global */
  54114. /******/ (() => {
  54115. /******/ __webpack_require__.g = (function() {
  54116. /******/ if (typeof globalThis === 'object') return globalThis;
  54117. /******/ try {
  54118. /******/ return this || new Function('return this')();
  54119. /******/ } catch (e) {
  54120. /******/ if (typeof window === 'object') return window;
  54121. /******/ }
  54122. /******/ })();
  54123. /******/ })();
  54124. /******/
  54125. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  54126. /******/ (() => {
  54127. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  54128. /******/ })();
  54129. /******/
  54130. /******/ /* webpack/runtime/node module decorator */
  54131. /******/ (() => {
  54132. /******/ __webpack_require__.nmd = (module) => {
  54133. /******/ module.paths = [];
  54134. /******/ if (!module.children) module.children = [];
  54135. /******/ return module;
  54136. /******/ };
  54137. /******/ })();
  54138. /******/
  54139. /************************************************************************/
  54140. /******/
  54141. /******/ // startup
  54142. /******/ // Load entry module and return exports
  54143. /******/ // This entry module used 'module' so it can't be inlined
  54144. /******/ var __webpack_exports__ = __webpack_require__(5507);
  54145. /******/
  54146. /******/ return __webpack_exports__;
  54147. /******/ })()
  54148. ;
  54149. });