No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.browser.esm5.js 258KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483
  1. import { __extends as t, __awaiter as e, __generator as n, __spreadArray as r } from "tslib";
  2. import { SDK_VERSION as i, _registerComponent as o, registerVersion as a, _getProvider, getApp as u, _removeServiceInstance as s } from "@firebase/app";
  3. import { Component as c } from "@firebase/component";
  4. import { Logger as l, LogLevel as f } from "@firebase/logger";
  5. import { FirebaseError as h, getModularInstance as p, getDefaultEmulatorHostnameAndPort as d, createMockUserToken as y, deepEqual as m } from "@firebase/util";
  6. /**
  7. * @license
  8. * Copyright 2017 Google LLC
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. */
  22. /**
  23. * Simple wrapper around a nullable UID. Mostly exists to make code more
  24. * readable.
  25. */ var v = /** @class */ function() {
  26. function t(t) {
  27. this.uid = t;
  28. }
  29. return t.prototype.isAuthenticated = function() {
  30. return null != this.uid;
  31. },
  32. /**
  33. * Returns a key representing this user, suitable for inclusion in a
  34. * dictionary.
  35. */
  36. t.prototype.toKey = function() {
  37. return this.isAuthenticated() ? "uid:" + this.uid : "anonymous-user";
  38. }, t.prototype.isEqual = function(t) {
  39. return t.uid === this.uid;
  40. }, t;
  41. }();
  42. /** A user with a null UID. */ v.UNAUTHENTICATED = new v(null),
  43. // TODO(mikelehen): Look into getting a proper uid-equivalent for
  44. // non-FirebaseAuth providers.
  45. v.GOOGLE_CREDENTIALS = new v("google-credentials-uid"), v.FIRST_PARTY = new v("first-party-uid"),
  46. v.MOCK_USER = new v("mock-user");
  47. /**
  48. * @license
  49. * Copyright 2017 Google LLC
  50. *
  51. * Licensed under the Apache License, Version 2.0 (the "License");
  52. * you may not use this file except in compliance with the License.
  53. * You may obtain a copy of the License at
  54. *
  55. * http://www.apache.org/licenses/LICENSE-2.0
  56. *
  57. * Unless required by applicable law or agreed to in writing, software
  58. * distributed under the License is distributed on an "AS IS" BASIS,
  59. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  60. * See the License for the specific language governing permissions and
  61. * limitations under the License.
  62. */
  63. var g = "9.16.0", w = new l("@firebase/firestore");
  64. /**
  65. * @license
  66. * Copyright 2017 Google LLC
  67. *
  68. * Licensed under the Apache License, Version 2.0 (the "License");
  69. * you may not use this file except in compliance with the License.
  70. * You may obtain a copy of the License at
  71. *
  72. * http://www.apache.org/licenses/LICENSE-2.0
  73. *
  74. * Unless required by applicable law or agreed to in writing, software
  75. * distributed under the License is distributed on an "AS IS" BASIS,
  76. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  77. * See the License for the specific language governing permissions and
  78. * limitations under the License.
  79. */
  80. /**
  81. * Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
  82. *
  83. * @param logLevel - The verbosity you set for activity and error logging. Can
  84. * be any of the following values:
  85. *
  86. * <ul>
  87. * <li>`debug` for the most verbose logging level, primarily for
  88. * debugging.</li>
  89. * <li>`error` to log errors only.</li>
  90. * <li><code>`silent` to turn off logging.</li>
  91. * </ul>
  92. */
  93. function _(t) {
  94. w.setLogLevel(t);
  95. }
  96. function b(t) {
  97. for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
  98. if (w.logLevel <= f.DEBUG) {
  99. var i = e.map(k);
  100. w.debug.apply(w, r([ "Firestore (".concat(g, "): ").concat(t) ], i, !1));
  101. }
  102. }
  103. function T(t) {
  104. for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
  105. if (w.logLevel <= f.ERROR) {
  106. var i = e.map(k);
  107. w.error.apply(w, r([ "Firestore (".concat(g, "): ").concat(t) ], i, !1));
  108. }
  109. }
  110. /**
  111. * @internal
  112. */ function E(t) {
  113. for (var e = [], n = 1; n < arguments.length; n++) e[n - 1] = arguments[n];
  114. if (w.logLevel <= f.WARN) {
  115. var i = e.map(k);
  116. w.warn.apply(w, r([ "Firestore (".concat(g, "): ").concat(t) ], i, !1));
  117. }
  118. }
  119. /**
  120. * Converts an additional log parameter to a string representation.
  121. */ function k(t) {
  122. if ("string" == typeof t) return t;
  123. try {
  124. return e = t, JSON.stringify(e);
  125. } catch (e) {
  126. // Converting to JSON failed, just log the object directly
  127. return t;
  128. }
  129. /**
  130. * @license
  131. * Copyright 2020 Google LLC
  132. *
  133. * Licensed under the Apache License, Version 2.0 (the "License");
  134. * you may not use this file except in compliance with the License.
  135. * You may obtain a copy of the License at
  136. *
  137. * http://www.apache.org/licenses/LICENSE-2.0
  138. *
  139. * Unless required by applicable law or agreed to in writing, software
  140. * distributed under the License is distributed on an "AS IS" BASIS,
  141. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  142. * See the License for the specific language governing permissions and
  143. * limitations under the License.
  144. */
  145. /** Formats an object as a JSON string, suitable for logging. */ var e;
  146. }
  147. /**
  148. * @license
  149. * Copyright 2017 Google LLC
  150. *
  151. * Licensed under the Apache License, Version 2.0 (the "License");
  152. * you may not use this file except in compliance with the License.
  153. * You may obtain a copy of the License at
  154. *
  155. * http://www.apache.org/licenses/LICENSE-2.0
  156. *
  157. * Unless required by applicable law or agreed to in writing, software
  158. * distributed under the License is distributed on an "AS IS" BASIS,
  159. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  160. * See the License for the specific language governing permissions and
  161. * limitations under the License.
  162. */
  163. /**
  164. * Unconditionally fails, throwing an Error with the given message.
  165. * Messages are stripped in production builds.
  166. *
  167. * Returns `never` and can be used in expressions:
  168. * @example
  169. * let futureVar = fail('not implemented yet');
  170. */ function S(t) {
  171. void 0 === t && (t = "Unexpected state");
  172. // Log the failure in addition to throw an exception, just in case the
  173. // exception is swallowed.
  174. var e = "FIRESTORE (".concat(g, ") INTERNAL ASSERTION FAILED: ") + t;
  175. // NOTE: We don't use FirestoreError here because these are internal failures
  176. // that cannot be handled by the user. (Also it would create a circular
  177. // dependency between the error and assert modules which doesn't work.)
  178. throw T(e), new Error(e)
  179. /**
  180. * Fails if the given assertion condition is false, throwing an Error with the
  181. * given message if it did.
  182. *
  183. * Messages are stripped in production builds.
  184. */;
  185. }
  186. function I(t, e) {
  187. t || S();
  188. }
  189. /**
  190. * Casts `obj` to `T`. In non-production builds, verifies that `obj` is an
  191. * instance of `T` before casting.
  192. */ function A(t,
  193. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  194. e) {
  195. return t;
  196. }
  197. /**
  198. * @license
  199. * Copyright 2017 Google LLC
  200. *
  201. * Licensed under the Apache License, Version 2.0 (the "License");
  202. * you may not use this file except in compliance with the License.
  203. * You may obtain a copy of the License at
  204. *
  205. * http://www.apache.org/licenses/LICENSE-2.0
  206. *
  207. * Unless required by applicable law or agreed to in writing, software
  208. * distributed under the License is distributed on an "AS IS" BASIS,
  209. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  210. * See the License for the specific language governing permissions and
  211. * limitations under the License.
  212. */ var F = "cancelled", V = "unknown", P = "invalid-argument", D = "deadline-exceeded", O = "not-found", N = "permission-denied", q = "unauthenticated", R = "resource-exhausted", C = "failed-precondition", x = "aborted", L = "out-of-range", j = "unimplemented", M = "internal", U = "unavailable", B = /** @class */ function(e) {
  213. /** @hideconstructor */
  214. function n(
  215. /**
  216. * The backend error code associated with this error.
  217. */
  218. t,
  219. /**
  220. * A custom error description.
  221. */
  222. n) {
  223. var r = this;
  224. return (r = e.call(this, t, n) || this).code = t, r.message = n,
  225. // HACK: We write a toString property directly because Error is not a real
  226. // class and so inheritance does not work correctly. We could alternatively
  227. // do the same "back-door inheritance" trick that FirebaseError does.
  228. r.toString = function() {
  229. return "".concat(r.name, ": [code=").concat(r.code, "]: ").concat(r.message);
  230. }, r;
  231. }
  232. return t(n, e), n;
  233. }(h), G = function() {
  234. var t = this;
  235. this.promise = new Promise((function(e, n) {
  236. t.resolve = e, t.reject = n;
  237. }));
  238. }, Q = function(t, e) {
  239. this.user = e, this.type = "OAuth", this.headers = new Map, this.headers.set("Authorization", "Bearer ".concat(t));
  240. }, z = /** @class */ function() {
  241. function t() {}
  242. return t.prototype.getToken = function() {
  243. return Promise.resolve(null);
  244. }, t.prototype.invalidateToken = function() {}, t.prototype.start = function(t, e) {
  245. // Fire with initial user.
  246. t.enqueueRetryable((function() {
  247. return e(v.UNAUTHENTICATED);
  248. }));
  249. }, t.prototype.shutdown = function() {}, t;
  250. }(), K = /** @class */ function() {
  251. function t(t) {
  252. this.token = t,
  253. /**
  254. * Stores the listener registered with setChangeListener()
  255. * This isn't actually necessary since the UID never changes, but we use this
  256. * to verify the listen contract is adhered to in tests.
  257. */
  258. this.changeListener = null;
  259. }
  260. return t.prototype.getToken = function() {
  261. return Promise.resolve(this.token);
  262. }, t.prototype.invalidateToken = function() {}, t.prototype.start = function(t, e) {
  263. var n = this;
  264. this.changeListener = e,
  265. // Fire with initial user.
  266. t.enqueueRetryable((function() {
  267. return e(n.token.user);
  268. }));
  269. }, t.prototype.shutdown = function() {
  270. this.changeListener = null;
  271. }, t;
  272. }(), W = /** @class */ function() {
  273. function t(t) {
  274. var e = this;
  275. this.auth = null, t.onInit((function(t) {
  276. e.auth = t;
  277. }));
  278. }
  279. return t.prototype.getToken = function() {
  280. var t = this;
  281. return this.auth ? this.auth.getToken().then((function(e) {
  282. return e ? (I("string" == typeof e.accessToken), new Q(e.accessToken, new v(t.auth.getUid()))) : null;
  283. })) : Promise.resolve(null);
  284. }, t.prototype.invalidateToken = function() {}, t.prototype.start = function(t, e) {},
  285. t.prototype.shutdown = function() {}, t;
  286. }(), H = /** @class */ function() {
  287. function t(t, e, n, r) {
  288. this.t = t, this.i = e, this.o = n, this.u = r, this.type = "FirstParty", this.user = v.FIRST_PARTY,
  289. this.h = new Map
  290. /** Gets an authorization token, using a provided factory function, or falling back to First Party GAPI. */;
  291. }
  292. return t.prototype.l = function() {
  293. return this.u ? this.u() : (
  294. // Make sure this really is a Gapi client.
  295. I(!("object" != typeof this.t || null === this.t || !this.t.auth || !this.t.auth.getAuthHeaderValueForFirstParty)),
  296. this.t.auth.getAuthHeaderValueForFirstParty([]));
  297. }, Object.defineProperty(t.prototype, "headers", {
  298. get: function() {
  299. this.h.set("X-Goog-AuthUser", this.i);
  300. // Use array notation to prevent minification
  301. var t = this.l();
  302. return t && this.h.set("Authorization", t), this.o && this.h.set("X-Goog-Iam-Authorization-Token", this.o),
  303. this.h;
  304. },
  305. enumerable: !1,
  306. configurable: !0
  307. }), t;
  308. }(), Y = /** @class */ function() {
  309. function t(t, e, n, r) {
  310. this.t = t, this.i = e, this.o = n, this.u = r;
  311. }
  312. return t.prototype.getToken = function() {
  313. return Promise.resolve(new H(this.t, this.i, this.o, this.u));
  314. }, t.prototype.start = function(t, e) {
  315. // Fire with initial uid.
  316. t.enqueueRetryable((function() {
  317. return e(v.FIRST_PARTY);
  318. }));
  319. }, t.prototype.shutdown = function() {}, t.prototype.invalidateToken = function() {},
  320. t;
  321. }(), X = function(t) {
  322. this.value = t, this.type = "AppCheck", this.headers = new Map, t && t.length > 0 && this.headers.set("x-firebase-appcheck", this.value);
  323. }, J = /** @class */ function() {
  324. function t(t) {
  325. var e = this;
  326. this.m = t, this.appCheck = null, t.onInit((function(t) {
  327. e.appCheck = t;
  328. }));
  329. }
  330. return t.prototype.getToken = function() {
  331. return this.appCheck ? this.appCheck.getToken().then((function(t) {
  332. return t ? (I("string" == typeof t.token), new X(t.token)) : null;
  333. })) : Promise.resolve(null);
  334. }, t.prototype.invalidateToken = function() {}, t.prototype.start = function(t, e) {},
  335. t.prototype.shutdown = function() {}, t;
  336. }(), Z =
  337. /**
  338. * Constructs a DatabaseInfo using the provided host, databaseId and
  339. * persistenceKey.
  340. *
  341. * @param databaseId - The database to use.
  342. * @param appId - The Firebase App Id.
  343. * @param persistenceKey - A unique identifier for this Firestore's local
  344. * storage (used in conjunction with the databaseId).
  345. * @param host - The Firestore backend host to connect to.
  346. * @param ssl - Whether to use SSL when connecting.
  347. * @param forceLongPolling - Whether to use the forceLongPolling option
  348. * when using WebChannel as the network transport.
  349. * @param autoDetectLongPolling - Whether to use the detectBufferingProxy
  350. * option when using WebChannel as the network transport.
  351. * @param useFetchStreams Whether to use the Fetch API instead of
  352. * XMLHTTPRequest
  353. */
  354. function(t, e, n, r, i, o, a, u) {
  355. this.databaseId = t, this.appId = e, this.persistenceKey = n, this.host = r, this.ssl = i,
  356. this.forceLongPolling = o, this.autoDetectLongPolling = a, this.useFetchStreams = u;
  357. }, $ = /** @class */ function() {
  358. function t(t, e) {
  359. this.projectId = t, this.database = e || "(default)";
  360. }
  361. return t.empty = function() {
  362. return new t("", "");
  363. }, Object.defineProperty(t.prototype, "isDefaultDatabase", {
  364. get: function() {
  365. return "(default)" === this.database;
  366. },
  367. enumerable: !1,
  368. configurable: !0
  369. }), t.prototype.isEqual = function(e) {
  370. return e instanceof t && e.projectId === this.projectId && e.database === this.database;
  371. }, t;
  372. }(), tt = /** @class */ function() {
  373. function t(t, e, n) {
  374. void 0 === e ? e = 0 : e > t.length && S(), void 0 === n ? n = t.length - e : n > t.length - e && S(),
  375. this.segments = t, this.offset = e, this.len = n;
  376. }
  377. return Object.defineProperty(t.prototype, "length", {
  378. get: function() {
  379. return this.len;
  380. },
  381. enumerable: !1,
  382. configurable: !0
  383. }), t.prototype.isEqual = function(e) {
  384. return 0 === t.comparator(this, e);
  385. }, t.prototype.child = function(e) {
  386. var n = this.segments.slice(this.offset, this.limit());
  387. return e instanceof t ? e.forEach((function(t) {
  388. n.push(t);
  389. })) : n.push(e), this.construct(n);
  390. },
  391. /** The index of one past the last segment of the path. */ t.prototype.limit = function() {
  392. return this.offset + this.length;
  393. }, t.prototype.popFirst = function(t) {
  394. return t = void 0 === t ? 1 : t, this.construct(this.segments, this.offset + t, this.length - t);
  395. }, t.prototype.popLast = function() {
  396. return this.construct(this.segments, this.offset, this.length - 1);
  397. }, t.prototype.firstSegment = function() {
  398. return this.segments[this.offset];
  399. }, t.prototype.lastSegment = function() {
  400. return this.get(this.length - 1);
  401. }, t.prototype.get = function(t) {
  402. return this.segments[this.offset + t];
  403. }, t.prototype.isEmpty = function() {
  404. return 0 === this.length;
  405. }, t.prototype.isPrefixOf = function(t) {
  406. if (t.length < this.length) return !1;
  407. for (var e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
  408. return !0;
  409. }, t.prototype.isImmediateParentOf = function(t) {
  410. if (this.length + 1 !== t.length) return !1;
  411. for (var e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
  412. return !0;
  413. }, t.prototype.forEach = function(t) {
  414. for (var e = this.offset, n = this.limit(); e < n; e++) t(this.segments[e]);
  415. }, t.prototype.toArray = function() {
  416. return this.segments.slice(this.offset, this.limit());
  417. }, t.comparator = function(t, e) {
  418. for (var n = Math.min(t.length, e.length), r = 0; r < n; r++) {
  419. var i = t.get(r), o = e.get(r);
  420. if (i < o) return -1;
  421. if (i > o) return 1;
  422. }
  423. return t.length < e.length ? -1 : t.length > e.length ? 1 : 0;
  424. }, t;
  425. }(), et = /** @class */ function(e) {
  426. function n() {
  427. return null !== e && e.apply(this, arguments) || this;
  428. }
  429. return t(n, e), n.prototype.construct = function(t, e, r) {
  430. return new n(t, e, r);
  431. }, n.prototype.canonicalString = function() {
  432. // NOTE: The client is ignorant of any path segments containing escape
  433. // sequences (e.g. __id123__) and just passes them through raw (they exist
  434. // for legacy reasons and should not be used frequently).
  435. return this.toArray().join("/");
  436. }, n.prototype.toString = function() {
  437. return this.canonicalString();
  438. },
  439. /**
  440. * Creates a resource path from the given slash-delimited string. If multiple
  441. * arguments are provided, all components are combined. Leading and trailing
  442. * slashes from all components are ignored.
  443. */
  444. n.fromString = function() {
  445. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  446. // NOTE: The client is ignorant of any path segments containing escape
  447. // sequences (e.g. __id123__) and just passes them through raw (they exist
  448. // for legacy reasons and should not be used frequently).
  449. for (var r = [], i = 0, o = t; i < o.length; i++) {
  450. var a = o[i];
  451. if (a.indexOf("//") >= 0) throw new B(P, "Invalid segment (".concat(a, "). Paths must not contain // in them."));
  452. // Strip leading and traling slashed.
  453. r.push.apply(r, a.split("/").filter((function(t) {
  454. return t.length > 0;
  455. })));
  456. }
  457. return new n(r);
  458. }, n.emptyPath = function() {
  459. return new n([]);
  460. }, n;
  461. }(tt), nt = /^[_a-zA-Z][_a-zA-Z0-9]*$/, rt = /** @class */ function(e) {
  462. function n() {
  463. return null !== e && e.apply(this, arguments) || this;
  464. }
  465. return t(n, e), n.prototype.construct = function(t, e, r) {
  466. return new n(t, e, r);
  467. },
  468. /**
  469. * Returns true if the string could be used as a segment in a field path
  470. * without escaping.
  471. */
  472. n.isValidIdentifier = function(t) {
  473. return nt.test(t);
  474. }, n.prototype.canonicalString = function() {
  475. return this.toArray().map((function(t) {
  476. return t = t.replace(/\\/g, "\\\\").replace(/`/g, "\\`"), n.isValidIdentifier(t) || (t = "`" + t + "`"),
  477. t;
  478. })).join(".");
  479. }, n.prototype.toString = function() {
  480. return this.canonicalString();
  481. },
  482. /**
  483. * Returns true if this field references the key of a document.
  484. */
  485. n.prototype.isKeyField = function() {
  486. return 1 === this.length && "__name__" === this.get(0);
  487. },
  488. /**
  489. * The field designating the key of a document.
  490. */
  491. n.keyField = function() {
  492. return new n([ "__name__" ]);
  493. },
  494. /**
  495. * Parses a field string from the given server-formatted string.
  496. *
  497. * - Splitting the empty string is not allowed (for now at least).
  498. * - Empty segments within the string (e.g. if there are two consecutive
  499. * separators) are not allowed.
  500. *
  501. * TODO(b/37244157): we should make this more strict. Right now, it allows
  502. * non-identifier path components, even if they aren't escaped.
  503. */
  504. n.fromServerFormat = function(t) {
  505. for (var e = [], r = "", i = 0, o = function() {
  506. if (0 === r.length) throw new B(P, "Invalid field path (".concat(t, "). Paths must not be empty, begin with '.', end with '.', or contain '..'"));
  507. e.push(r), r = "";
  508. }, a = !1; i < t.length; ) {
  509. var u = t[i];
  510. if ("\\" === u) {
  511. if (i + 1 === t.length) throw new B(P, "Path has trailing escape character: " + t);
  512. var s = t[i + 1];
  513. if ("\\" !== s && "." !== s && "`" !== s) throw new B(P, "Path has invalid escape sequence: " + t);
  514. r += s, i += 2;
  515. } else "`" === u ? (a = !a, i++) : "." !== u || a ? (r += u, i++) : (o(), i++);
  516. }
  517. if (o(), a) throw new B(P, "Unterminated ` in path: " + t);
  518. return new n(e);
  519. }, n.emptyPath = function() {
  520. return new n([]);
  521. }, n;
  522. }(tt), it = /** @class */ function() {
  523. function t(t) {
  524. this.path = t;
  525. }
  526. return t.fromPath = function(e) {
  527. return new t(et.fromString(e));
  528. }, t.fromName = function(e) {
  529. return new t(et.fromString(e).popFirst(5));
  530. }, t.empty = function() {
  531. return new t(et.emptyPath());
  532. }, Object.defineProperty(t.prototype, "collectionGroup", {
  533. get: function() {
  534. return this.path.popLast().lastSegment();
  535. },
  536. enumerable: !1,
  537. configurable: !0
  538. }),
  539. /** Returns true if the document is in the specified collectionId. */ t.prototype.hasCollectionId = function(t) {
  540. return this.path.length >= 2 && this.path.get(this.path.length - 2) === t;
  541. },
  542. /** Returns the collection group (i.e. the name of the parent collection) for this key. */ t.prototype.getCollectionGroup = function() {
  543. return this.path.get(this.path.length - 2);
  544. },
  545. /** Returns the fully qualified path to the parent collection. */ t.prototype.getCollectionPath = function() {
  546. return this.path.popLast();
  547. }, t.prototype.isEqual = function(t) {
  548. return null !== t && 0 === et.comparator(this.path, t.path);
  549. }, t.prototype.toString = function() {
  550. return this.path.toString();
  551. }, t.comparator = function(t, e) {
  552. return et.comparator(t.path, e.path);
  553. }, t.isDocumentKey = function(t) {
  554. return t.length % 2 == 0;
  555. },
  556. /**
  557. * Creates and returns a new document key with the given segments.
  558. *
  559. * @param segments - The segments of the path to the document
  560. * @returns A new instance of DocumentKey
  561. */
  562. t.fromSegments = function(e) {
  563. return new t(new et(e.slice()));
  564. }, t;
  565. }();
  566. /** An error returned by a Firestore operation. */
  567. /**
  568. * @license
  569. * Copyright 2017 Google LLC
  570. *
  571. * Licensed under the Apache License, Version 2.0 (the "License");
  572. * you may not use this file except in compliance with the License.
  573. * You may obtain a copy of the License at
  574. *
  575. * http://www.apache.org/licenses/LICENSE-2.0
  576. *
  577. * Unless required by applicable law or agreed to in writing, software
  578. * distributed under the License is distributed on an "AS IS" BASIS,
  579. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  580. * See the License for the specific language governing permissions and
  581. * limitations under the License.
  582. */
  583. function ot(t, e, n) {
  584. if (!n) throw new B(P, "Function ".concat(t, "() cannot be called with an empty ").concat(e, "."));
  585. }
  586. /**
  587. * Validates that two boolean options are not set at the same time.
  588. * @internal
  589. */
  590. /**
  591. * Validates that `path` refers to a document (indicated by the fact it contains
  592. * an even numbers of segments).
  593. */ function at(t) {
  594. if (!it.isDocumentKey(t)) throw new B(P, "Invalid document reference. Document references must have an even number of segments, but ".concat(t, " has ").concat(t.length, "."));
  595. }
  596. /**
  597. * Validates that `path` refers to a collection (indicated by the fact it
  598. * contains an odd numbers of segments).
  599. */ function ut(t) {
  600. if (it.isDocumentKey(t)) throw new B(P, "Invalid collection reference. Collection references must have an odd number of segments, but ".concat(t, " has ").concat(t.length, "."));
  601. }
  602. /**
  603. * Returns true if it's a non-null object without a custom prototype
  604. * (i.e. excludes Array, Date, etc.).
  605. */
  606. /** Returns a string describing the type / value of the provided input. */ function st(t) {
  607. if (void 0 === t) return "undefined";
  608. if (null === t) return "null";
  609. if ("string" == typeof t) return t.length > 20 && (t = "".concat(t.substring(0, 20), "...")),
  610. JSON.stringify(t);
  611. if ("number" == typeof t || "boolean" == typeof t) return "" + t;
  612. if ("object" == typeof t) {
  613. if (t instanceof Array) return "an array";
  614. var e =
  615. /** try to get the constructor name for an object. */
  616. function(t) {
  617. return t.constructor ? t.constructor.name : null;
  618. }(t);
  619. return e ? "a custom ".concat(e, " object") : "an object";
  620. }
  621. return "function" == typeof t ? "a function" : S();
  622. }
  623. function ct(t,
  624. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  625. e) {
  626. if ("_delegate" in t && (
  627. // Unwrap Compat types
  628. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  629. t = t._delegate), !(t instanceof e)) {
  630. if (e.name === t.constructor.name) throw new B(P, "Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");
  631. var n = st(t);
  632. throw new B(P, "Expected type '".concat(e.name, "', but it was: ").concat(n));
  633. }
  634. return t;
  635. }
  636. function lt(t, e) {
  637. if (e <= 0) throw new B(P, "Function ".concat(t, "() requires a positive number, but it was: ").concat(e, "."));
  638. }
  639. /**
  640. * @license
  641. * Copyright 2017 Google LLC
  642. *
  643. * Licensed under the Apache License, Version 2.0 (the "License");
  644. * you may not use this file except in compliance with the License.
  645. * You may obtain a copy of the License at
  646. *
  647. * http://www.apache.org/licenses/LICENSE-2.0
  648. *
  649. * Unless required by applicable law or agreed to in writing, software
  650. * distributed under the License is distributed on an "AS IS" BASIS,
  651. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  652. * See the License for the specific language governing permissions and
  653. * limitations under the License.
  654. */
  655. /**
  656. * Returns whether a variable is either undefined or null.
  657. */ function ft(t) {
  658. return null == t;
  659. }
  660. /** Returns whether the value represents -0. */ function ht(t) {
  661. // Detect if the value is -0.0. Based on polyfill from
  662. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  663. return 0 === t && 1 / t == -1 / 0;
  664. }
  665. /**
  666. * Returns whether a value is an integer and in the safe integer range
  667. * @param value - The value to test for being an integer and in the safe range
  668. */
  669. /**
  670. * @license
  671. * Copyright 2020 Google LLC
  672. *
  673. * Licensed under the Apache License, Version 2.0 (the "License");
  674. * you may not use this file except in compliance with the License.
  675. * You may obtain a copy of the License at
  676. *
  677. * http://www.apache.org/licenses/LICENSE-2.0
  678. *
  679. * Unless required by applicable law or agreed to in writing, software
  680. * distributed under the License is distributed on an "AS IS" BASIS,
  681. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  682. * See the License for the specific language governing permissions and
  683. * limitations under the License.
  684. */ var pt, dt, yt = {
  685. BatchGetDocuments: "batchGet",
  686. Commit: "commit",
  687. RunQuery: "runQuery",
  688. RunAggregationQuery: "runAggregationQuery"
  689. };
  690. /**
  691. * Maps RPC names to the corresponding REST endpoint name.
  692. *
  693. * We use array notation to avoid mangling.
  694. */
  695. /**
  696. * @license
  697. * Copyright 2017 Google LLC
  698. *
  699. * Licensed under the Apache License, Version 2.0 (the "License");
  700. * you may not use this file except in compliance with the License.
  701. * You may obtain a copy of the License at
  702. *
  703. * http://www.apache.org/licenses/LICENSE-2.0
  704. *
  705. * Unless required by applicable law or agreed to in writing, software
  706. * distributed under the License is distributed on an "AS IS" BASIS,
  707. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  708. * See the License for the specific language governing permissions and
  709. * limitations under the License.
  710. */
  711. /**
  712. * Error Codes describing the different ways GRPC can fail. These are copied
  713. * directly from GRPC's sources here:
  714. *
  715. * https://github.com/grpc/grpc/blob/bceec94ea4fc5f0085d81235d8e1c06798dc341a/include/grpc%2B%2B/impl/codegen/status_code_enum.h
  716. *
  717. * Important! The names of these identifiers matter because the string forms
  718. * are used for reverse lookups from the webchannel stream. Do NOT change the
  719. * names of these identifiers or change this into a const enum.
  720. */
  721. /**
  722. * Converts an HTTP Status Code to the equivalent error code.
  723. *
  724. * @param status - An HTTP Status Code, like 200, 404, 503, etc.
  725. * @returns The equivalent Code. Unknown status codes are mapped to
  726. * Code.UNKNOWN.
  727. */
  728. function mt(t) {
  729. if (void 0 === t) return T("RPC_ERROR", "HTTP error has no status"), V;
  730. // The canonical error codes for Google APIs [1] specify mapping onto HTTP
  731. // status codes but the mapping is not bijective. In each case of ambiguity
  732. // this function chooses a primary error.
  733. // [1]
  734. // https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto
  735. switch (t) {
  736. case 200:
  737. // OK
  738. return "ok";
  739. case 400:
  740. // Bad Request
  741. return C;
  742. // Other possibilities based on the forward mapping
  743. // return Code.INVALID_ARGUMENT;
  744. // return Code.OUT_OF_RANGE;
  745. case 401:
  746. // Unauthorized
  747. return q;
  748. case 403:
  749. // Forbidden
  750. return N;
  751. case 404:
  752. // Not Found
  753. return O;
  754. case 409:
  755. // Conflict
  756. return x;
  757. // Other possibilities:
  758. // return Code.ALREADY_EXISTS;
  759. case 416:
  760. // Range Not Satisfiable
  761. return L;
  762. case 429:
  763. // Too Many Requests
  764. return R;
  765. case 499:
  766. // Client Closed Request
  767. return F;
  768. case 500:
  769. // Internal Server Error
  770. return V;
  771. // Other possibilities:
  772. // return Code.INTERNAL;
  773. // return Code.DATA_LOSS;
  774. case 501:
  775. // Unimplemented
  776. return j;
  777. case 503:
  778. // Service Unavailable
  779. return U;
  780. case 504:
  781. // Gateway Timeout
  782. return D;
  783. default:
  784. return t >= 200 && t < 300 ? "ok" : t >= 400 && t < 500 ? C : t >= 500 && t < 600 ? M : V;
  785. }
  786. }
  787. /**
  788. * @license
  789. * Copyright 2020 Google LLC
  790. *
  791. * Licensed under the Apache License, Version 2.0 (the "License");
  792. * you may not use this file except in compliance with the License.
  793. * You may obtain a copy of the License at
  794. *
  795. * http://www.apache.org/licenses/LICENSE-2.0
  796. *
  797. * Unless required by applicable law or agreed to in writing, software
  798. * distributed under the License is distributed on an "AS IS" BASIS,
  799. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  800. * See the License for the specific language governing permissions and
  801. * limitations under the License.
  802. */
  803. /**
  804. * A Rest-based connection that relies on the native HTTP stack
  805. * (e.g. `fetch` or a polyfill).
  806. */ (dt = pt || (pt = {}))[dt.OK = 0] = "OK", dt[dt.CANCELLED = 1] = "CANCELLED",
  807. dt[dt.UNKNOWN = 2] = "UNKNOWN", dt[dt.INVALID_ARGUMENT = 3] = "INVALID_ARGUMENT",
  808. dt[dt.DEADLINE_EXCEEDED = 4] = "DEADLINE_EXCEEDED", dt[dt.NOT_FOUND = 5] = "NOT_FOUND",
  809. dt[dt.ALREADY_EXISTS = 6] = "ALREADY_EXISTS", dt[dt.PERMISSION_DENIED = 7] = "PERMISSION_DENIED",
  810. dt[dt.UNAUTHENTICATED = 16] = "UNAUTHENTICATED", dt[dt.RESOURCE_EXHAUSTED = 8] = "RESOURCE_EXHAUSTED",
  811. dt[dt.FAILED_PRECONDITION = 9] = "FAILED_PRECONDITION", dt[dt.ABORTED = 10] = "ABORTED",
  812. dt[dt.OUT_OF_RANGE = 11] = "OUT_OF_RANGE", dt[dt.UNIMPLEMENTED = 12] = "UNIMPLEMENTED",
  813. dt[dt.INTERNAL = 13] = "INTERNAL", dt[dt.UNAVAILABLE = 14] = "UNAVAILABLE", dt[dt.DATA_LOSS = 15] = "DATA_LOSS";
  814. var vt = /** @class */ function(r) {
  815. /**
  816. * @param databaseInfo - The connection info.
  817. * @param fetchImpl - `fetch` or a Polyfill that implements the fetch API.
  818. */
  819. function i(t, e) {
  820. var n = this;
  821. return (n = r.call(this, t) || this).V = e, n;
  822. }
  823. /**
  824. * Base class for all Rest-based connections to the backend (WebChannel and
  825. * HTTP).
  826. */
  827. return t(i, r), i.prototype.$ = function(t, e) {
  828. throw new Error("Not supported by FetchConnection");
  829. }, i.prototype.R = function(t, r, i, o) {
  830. return e(this, void 0, void 0, (function() {
  831. var t, e, a, u, s, c, l;
  832. return n(this, (function(n) {
  833. switch (n.label) {
  834. case 0:
  835. e = JSON.stringify(o), n.label = 1;
  836. case 1:
  837. return n.trys.push([ 1, 3, , 4 ]), [ 4 /*yield*/ , this.V(r, {
  838. method: "POST",
  839. headers: i,
  840. body: e
  841. }) ];
  842. case 2:
  843. return a = n.sent(), [ 3 /*break*/ , 4 ];
  844. case 3:
  845. throw u = n.sent(), new B(mt((s = u).status), "Request failed with error: " + s.statusText);
  846. case 4:
  847. return a.ok ? [ 3 /*break*/ , 6 ] : [ 4 /*yield*/ , a.json() ];
  848. case 5:
  849. throw c = n.sent(), Array.isArray(c) && (c = c[0]), l = null === (t = null == c ? void 0 : c.error) || void 0 === t ? void 0 : t.message,
  850. new B(mt(a.status), "Request failed with error: ".concat(null != l ? l : a.statusText));
  851. case 6:
  852. return [ 2 /*return*/ , a.json() ];
  853. }
  854. }));
  855. }));
  856. }, i;
  857. }(/** @class */ function() {
  858. function t(t) {
  859. this.databaseInfo = t, this.databaseId = t.databaseId;
  860. var e = t.ssl ? "https" : "http";
  861. this.p = e + "://" + t.host, this.g = "projects/" + this.databaseId.projectId + "/databases/" + this.databaseId.database + "/documents";
  862. }
  863. return Object.defineProperty(t.prototype, "v", {
  864. get: function() {
  865. // Both `invokeRPC()` and `invokeStreamingRPC()` use their `path` arguments to determine
  866. // where to run the query, and expect the `request` to NOT specify the "path".
  867. return !1;
  868. },
  869. enumerable: !1,
  870. configurable: !0
  871. }), t.prototype.I = function(t, e, n, r, i) {
  872. var o = this.T(t, e);
  873. b("RestConnection", "Sending: ", o, n);
  874. var a = {};
  875. return this.A(a, r, i), this.R(t, o, a, n).then((function(t) {
  876. return b("RestConnection", "Received: ", t), t;
  877. }), (function(e) {
  878. throw E("RestConnection", "".concat(t, " failed with error: "), e, "url: ", o, "request:", n),
  879. e;
  880. }));
  881. }, t.prototype.P = function(t, e, n, r, i, o) {
  882. // The REST API automatically aggregates all of the streamed results, so we
  883. // can just use the normal invoke() method.
  884. return this.I(t, e, n, r, i);
  885. },
  886. /**
  887. * Modifies the headers for a request, adding any authorization token if
  888. * present and any additional headers for the request.
  889. */
  890. t.prototype.A = function(t, e, n) {
  891. t["X-Goog-Api-Client"] = "gl-js/ fire/" + g,
  892. // Content-Type: text/plain will avoid preflight requests which might
  893. // mess with CORS and redirects by proxies. If we add custom headers
  894. // we will need to change this code to potentially use the $httpOverwrite
  895. // parameter supported by ESF to avoid triggering preflight requests.
  896. t["Content-Type"] = "text/plain", this.databaseInfo.appId && (t["X-Firebase-GMPID"] = this.databaseInfo.appId),
  897. e && e.headers.forEach((function(e, n) {
  898. return t[n] = e;
  899. })), n && n.headers.forEach((function(e, n) {
  900. return t[n] = e;
  901. }));
  902. }, t.prototype.T = function(t, e) {
  903. var n = yt[t];
  904. return "".concat(this.p, "/v1/").concat(e, ":").concat(n);
  905. }, t;
  906. }());
  907. /**
  908. * @license
  909. * Copyright 2020 Google LLC
  910. *
  911. * Licensed under the Apache License, Version 2.0 (the "License");
  912. * you may not use this file except in compliance with the License.
  913. * You may obtain a copy of the License at
  914. *
  915. * http://www.apache.org/licenses/LICENSE-2.0
  916. *
  917. * Unless required by applicable law or agreed to in writing, software
  918. * distributed under the License is distributed on an "AS IS" BASIS,
  919. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  920. * See the License for the specific language governing permissions and
  921. * limitations under the License.
  922. */
  923. /** Initializes the HTTP connection for the REST API. */
  924. /**
  925. * @license
  926. * Copyright 2020 Google LLC
  927. *
  928. * Licensed under the Apache License, Version 2.0 (the "License");
  929. * you may not use this file except in compliance with the License.
  930. * You may obtain a copy of the License at
  931. *
  932. * http://www.apache.org/licenses/LICENSE-2.0
  933. *
  934. * Unless required by applicable law or agreed to in writing, software
  935. * distributed under the License is distributed on an "AS IS" BASIS,
  936. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  937. * See the License for the specific language governing permissions and
  938. * limitations under the License.
  939. */
  940. /**
  941. * Generates `nBytes` of random bytes.
  942. *
  943. * If `nBytes < 0` , an error will be thrown.
  944. */ function gt(t) {
  945. // Polyfills for IE and WebWorker by using `self` and `msCrypto` when `crypto` is not available.
  946. var e =
  947. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  948. "undefined" != typeof self && (self.crypto || self.msCrypto), n = new Uint8Array(t);
  949. if (e && "function" == typeof e.getRandomValues) e.getRandomValues(n); else
  950. // Falls back to Math.random
  951. for (var r = 0; r < t; r++) n[r] = Math.floor(256 * Math.random());
  952. return n;
  953. }
  954. /**
  955. * @license
  956. * Copyright 2017 Google LLC
  957. *
  958. * Licensed under the Apache License, Version 2.0 (the "License");
  959. * you may not use this file except in compliance with the License.
  960. * You may obtain a copy of the License at
  961. *
  962. * http://www.apache.org/licenses/LICENSE-2.0
  963. *
  964. * Unless required by applicable law or agreed to in writing, software
  965. * distributed under the License is distributed on an "AS IS" BASIS,
  966. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  967. * See the License for the specific language governing permissions and
  968. * limitations under the License.
  969. */ var wt = /** @class */ function() {
  970. function t() {}
  971. return t.N = function() {
  972. for (
  973. // Alphanumeric characters
  974. var t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", e = Math.floor(256 / t.length) * t.length, n = ""
  975. // The largest byte value that is a multiple of `char.length`.
  976. ; n.length < 20; ) for (var r = gt(40), i = 0; i < r.length; ++i)
  977. // Only accept values that are [0, maxMultiple), this ensures they can
  978. // be evenly mapped to indices of `chars` via a modulo operation.
  979. n.length < 20 && r[i] < e && (n += t.charAt(r[i] % t.length));
  980. return n;
  981. }, t;
  982. }();
  983. function _t(t, e) {
  984. return t < e ? -1 : t > e ? 1 : 0;
  985. }
  986. /** Helper to compare arrays using isEqual(). */ function bt(t, e, n) {
  987. return t.length === e.length && t.every((function(t, r) {
  988. return n(t, e[r]);
  989. }));
  990. }
  991. /**
  992. * @license
  993. * Copyright 2017 Google LLC
  994. *
  995. * Licensed under the Apache License, Version 2.0 (the "License");
  996. * you may not use this file except in compliance with the License.
  997. * You may obtain a copy of the License at
  998. *
  999. * http://www.apache.org/licenses/LICENSE-2.0
  1000. *
  1001. * Unless required by applicable law or agreed to in writing, software
  1002. * distributed under the License is distributed on an "AS IS" BASIS,
  1003. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1004. * See the License for the specific language governing permissions and
  1005. * limitations under the License.
  1006. */ function Tt(t) {
  1007. var e = 0;
  1008. for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && e++;
  1009. return e;
  1010. }
  1011. function Et(t, e) {
  1012. for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && e(n, t[n]);
  1013. }
  1014. /**
  1015. * @license
  1016. * Copyright 2020 Google LLC
  1017. *
  1018. * Licensed under the Apache License, Version 2.0 (the "License");
  1019. * you may not use this file except in compliance with the License.
  1020. * You may obtain a copy of the License at
  1021. *
  1022. * http://www.apache.org/licenses/LICENSE-2.0
  1023. *
  1024. * Unless required by applicable law or agreed to in writing, software
  1025. * distributed under the License is distributed on an "AS IS" BASIS,
  1026. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1027. * See the License for the specific language governing permissions and
  1028. * limitations under the License.
  1029. */
  1030. /**
  1031. * Immutable class that represents a "proto" byte string.
  1032. *
  1033. * Proto byte strings can either be Base64-encoded strings or Uint8Arrays when
  1034. * sent on the wire. This class abstracts away this differentiation by holding
  1035. * the proto byte string in a common class that must be converted into a string
  1036. * before being sent as a proto.
  1037. * @internal
  1038. */ var kt = /** @class */ function() {
  1039. function t(t) {
  1040. this.binaryString = t;
  1041. }
  1042. return t.fromBase64String = function(e) {
  1043. return new t(atob(e));
  1044. }, t.fromUint8Array = function(e) {
  1045. // TODO(indexing); Remove the copy of the byte string here as this method
  1046. // is frequently called during indexing.
  1047. var n =
  1048. /**
  1049. * Helper function to convert an Uint8array to a binary string.
  1050. */
  1051. function(t) {
  1052. for (var e = "", n = 0; n < t.length; ++n) e += String.fromCharCode(t[n]);
  1053. return e;
  1054. }(e);
  1055. return new t(n);
  1056. }, t.prototype[Symbol.iterator] = function() {
  1057. var t = this, e = 0;
  1058. return {
  1059. next: function() {
  1060. return e < t.binaryString.length ? {
  1061. value: t.binaryString.charCodeAt(e++),
  1062. done: !1
  1063. } : {
  1064. value: void 0,
  1065. done: !0
  1066. };
  1067. }
  1068. };
  1069. }, t.prototype.toBase64 = function() {
  1070. return t = this.binaryString, btoa(t);
  1071. /** Converts a binary string to a Base64 encoded string. */ var t;
  1072. }, t.prototype.toUint8Array = function() {
  1073. return function(t) {
  1074. for (var e = new Uint8Array(t.length), n = 0; n < t.length; n++) e[n] = t.charCodeAt(n);
  1075. return e;
  1076. }(this.binaryString);
  1077. }, t.prototype.approximateByteSize = function() {
  1078. return 2 * this.binaryString.length;
  1079. }, t.prototype.compareTo = function(t) {
  1080. return _t(this.binaryString, t.binaryString);
  1081. }, t.prototype.isEqual = function(t) {
  1082. return this.binaryString === t.binaryString;
  1083. }, t;
  1084. }();
  1085. kt.EMPTY_BYTE_STRING = new kt("");
  1086. var St = new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);
  1087. /**
  1088. * Converts the possible Proto values for a timestamp value into a "seconds and
  1089. * nanos" representation.
  1090. */ function It(t) {
  1091. // The json interface (for the browser) will return an iso timestamp string,
  1092. // while the proto js library (for node) will return a
  1093. // google.protobuf.Timestamp instance.
  1094. if (I(!!t), "string" == typeof t) {
  1095. // The date string can have higher precision (nanos) than the Date class
  1096. // (millis), so we do some custom parsing here.
  1097. // Parse the nanos right out of the string.
  1098. var e = 0, n = St.exec(t);
  1099. if (I(!!n), n[1]) {
  1100. // Pad the fraction out to 9 digits (nanos).
  1101. var r = n[1];
  1102. r = (r + "000000000").substr(0, 9), e = Number(r);
  1103. }
  1104. // Parse the date to get the seconds.
  1105. var i = new Date(t);
  1106. return {
  1107. seconds: Math.floor(i.getTime() / 1e3),
  1108. nanos: e
  1109. };
  1110. }
  1111. return {
  1112. seconds: At(t.seconds),
  1113. nanos: At(t.nanos)
  1114. };
  1115. }
  1116. /**
  1117. * Converts the possible Proto types for numbers into a JavaScript number.
  1118. * Returns 0 if the value is not numeric.
  1119. */ function At(t) {
  1120. // TODO(bjornick): Handle int64 greater than 53 bits.
  1121. return "number" == typeof t ? t : "string" == typeof t ? Number(t) : 0;
  1122. }
  1123. /** Converts the possible Proto types for Blobs into a ByteString. */ function Ft(t) {
  1124. return "string" == typeof t ? kt.fromBase64String(t) : kt.fromUint8Array(t);
  1125. }
  1126. /**
  1127. * @license
  1128. * Copyright 2017 Google LLC
  1129. *
  1130. * Licensed under the Apache License, Version 2.0 (the "License");
  1131. * you may not use this file except in compliance with the License.
  1132. * You may obtain a copy of the License at
  1133. *
  1134. * http://www.apache.org/licenses/LICENSE-2.0
  1135. *
  1136. * Unless required by applicable law or agreed to in writing, software
  1137. * distributed under the License is distributed on an "AS IS" BASIS,
  1138. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1139. * See the License for the specific language governing permissions and
  1140. * limitations under the License.
  1141. */
  1142. // The earliest date supported by Firestore timestamps (0001-01-01T00:00:00Z).
  1143. /**
  1144. * A `Timestamp` represents a point in time independent of any time zone or
  1145. * calendar, represented as seconds and fractions of seconds at nanosecond
  1146. * resolution in UTC Epoch time.
  1147. *
  1148. * It is encoded using the Proleptic Gregorian Calendar which extends the
  1149. * Gregorian calendar backwards to year one. It is encoded assuming all minutes
  1150. * are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second
  1151. * table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to
  1152. * 9999-12-31T23:59:59.999999999Z.
  1153. *
  1154. * For examples and further specifications, refer to the
  1155. * {@link https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto | Timestamp definition}.
  1156. */ var Vt = /** @class */ function() {
  1157. /**
  1158. * Creates a new timestamp.
  1159. *
  1160. * @param seconds - The number of seconds of UTC time since Unix epoch
  1161. * 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
  1162. * 9999-12-31T23:59:59Z inclusive.
  1163. * @param nanoseconds - The non-negative fractions of a second at nanosecond
  1164. * resolution. Negative second values with fractions must still have
  1165. * non-negative nanoseconds values that count forward in time. Must be
  1166. * from 0 to 999,999,999 inclusive.
  1167. */
  1168. function t(
  1169. /**
  1170. * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
  1171. */
  1172. t,
  1173. /**
  1174. * The fractions of a second at nanosecond resolution.*
  1175. */
  1176. e) {
  1177. if (this.seconds = t, this.nanoseconds = e, e < 0) throw new B(P, "Timestamp nanoseconds out of range: " + e);
  1178. if (e >= 1e9) throw new B(P, "Timestamp nanoseconds out of range: " + e);
  1179. if (t < -62135596800) throw new B(P, "Timestamp seconds out of range: " + t);
  1180. // This will break in the year 10,000.
  1181. if (t >= 253402300800) throw new B(P, "Timestamp seconds out of range: " + t);
  1182. }
  1183. /**
  1184. * Creates a new timestamp with the current date, with millisecond precision.
  1185. *
  1186. * @returns a new timestamp representing the current date.
  1187. */ return t.now = function() {
  1188. return t.fromMillis(Date.now());
  1189. },
  1190. /**
  1191. * Creates a new timestamp from the given date.
  1192. *
  1193. * @param date - The date to initialize the `Timestamp` from.
  1194. * @returns A new `Timestamp` representing the same point in time as the given
  1195. * date.
  1196. */
  1197. t.fromDate = function(e) {
  1198. return t.fromMillis(e.getTime());
  1199. },
  1200. /**
  1201. * Creates a new timestamp from the given number of milliseconds.
  1202. *
  1203. * @param milliseconds - Number of milliseconds since Unix epoch
  1204. * 1970-01-01T00:00:00Z.
  1205. * @returns A new `Timestamp` representing the same point in time as the given
  1206. * number of milliseconds.
  1207. */
  1208. t.fromMillis = function(e) {
  1209. var n = Math.floor(e / 1e3);
  1210. return new t(n, Math.floor(1e6 * (e - 1e3 * n)));
  1211. },
  1212. /**
  1213. * Converts a `Timestamp` to a JavaScript `Date` object. This conversion
  1214. * causes a loss of precision since `Date` objects only support millisecond
  1215. * precision.
  1216. *
  1217. * @returns JavaScript `Date` object representing the same point in time as
  1218. * this `Timestamp`, with millisecond precision.
  1219. */
  1220. t.prototype.toDate = function() {
  1221. return new Date(this.toMillis());
  1222. },
  1223. /**
  1224. * Converts a `Timestamp` to a numeric timestamp (in milliseconds since
  1225. * epoch). This operation causes a loss of precision.
  1226. *
  1227. * @returns The point in time corresponding to this timestamp, represented as
  1228. * the number of milliseconds since Unix epoch 1970-01-01T00:00:00Z.
  1229. */
  1230. t.prototype.toMillis = function() {
  1231. return 1e3 * this.seconds + this.nanoseconds / 1e6;
  1232. }, t.prototype._compareTo = function(t) {
  1233. return this.seconds === t.seconds ? _t(this.nanoseconds, t.nanoseconds) : _t(this.seconds, t.seconds);
  1234. },
  1235. /**
  1236. * Returns true if this `Timestamp` is equal to the provided one.
  1237. *
  1238. * @param other - The `Timestamp` to compare against.
  1239. * @returns true if this `Timestamp` is equal to the provided one.
  1240. */
  1241. t.prototype.isEqual = function(t) {
  1242. return t.seconds === this.seconds && t.nanoseconds === this.nanoseconds;
  1243. },
  1244. /** Returns a textual representation of this `Timestamp`. */ t.prototype.toString = function() {
  1245. return "Timestamp(seconds=" + this.seconds + ", nanoseconds=" + this.nanoseconds + ")";
  1246. },
  1247. /** Returns a JSON-serializable representation of this `Timestamp`. */ t.prototype.toJSON = function() {
  1248. return {
  1249. seconds: this.seconds,
  1250. nanoseconds: this.nanoseconds
  1251. };
  1252. },
  1253. /**
  1254. * Converts this object to a primitive string, which allows `Timestamp` objects
  1255. * to be compared using the `>`, `<=`, `>=` and `>` operators.
  1256. */
  1257. t.prototype.valueOf = function() {
  1258. // This method returns a string of the form <seconds>.<nanoseconds> where
  1259. // <seconds> is translated to have a non-negative value and both <seconds>
  1260. // and <nanoseconds> are left-padded with zeroes to be a consistent length.
  1261. // Strings with this format then have a lexiographical ordering that matches
  1262. // the expected ordering. The <seconds> translation is done to avoid having
  1263. // a leading negative sign (i.e. a leading '-' character) in its string
  1264. // representation, which would affect its lexiographical ordering.
  1265. var t = this.seconds - -62135596800;
  1266. // Note: Up to 12 decimal digits are required to represent all valid
  1267. // 'seconds' values.
  1268. return String(t).padStart(12, "0") + "." + String(this.nanoseconds).padStart(9, "0");
  1269. }, t;
  1270. }();
  1271. /**
  1272. * @license
  1273. * Copyright 2020 Google LLC
  1274. *
  1275. * Licensed under the Apache License, Version 2.0 (the "License");
  1276. * you may not use this file except in compliance with the License.
  1277. * You may obtain a copy of the License at
  1278. *
  1279. * http://www.apache.org/licenses/LICENSE-2.0
  1280. *
  1281. * Unless required by applicable law or agreed to in writing, software
  1282. * distributed under the License is distributed on an "AS IS" BASIS,
  1283. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1284. * See the License for the specific language governing permissions and
  1285. * limitations under the License.
  1286. */
  1287. /**
  1288. * Represents a locally-applied ServerTimestamp.
  1289. *
  1290. * Server Timestamps are backed by MapValues that contain an internal field
  1291. * `__type__` with a value of `server_timestamp`. The previous value and local
  1292. * write time are stored in its `__previous_value__` and `__local_write_time__`
  1293. * fields respectively.
  1294. *
  1295. * Notes:
  1296. * - ServerTimestampValue instances are created as the result of applying a
  1297. * transform. They can only exist in the local view of a document. Therefore
  1298. * they do not need to be parsed or serialized.
  1299. * - When evaluated locally (e.g. for snapshot.data()), they by default
  1300. * evaluate to `null`. This behavior can be configured by passing custom
  1301. * FieldValueOptions to value().
  1302. * - With respect to other ServerTimestampValues, they sort by their
  1303. * localWriteTime.
  1304. */ function Pt(t) {
  1305. var e, n;
  1306. return "server_timestamp" === (null === (n = ((null === (e = null == t ? void 0 : t.mapValue) || void 0 === e ? void 0 : e.fields) || {}).__type__) || void 0 === n ? void 0 : n.stringValue);
  1307. }
  1308. /**
  1309. * Returns the value of the field before this ServerTimestamp was set.
  1310. *
  1311. * Preserving the previous values allows the user to display the last resoled
  1312. * value until the backend responds with the timestamp.
  1313. */ function Dt(t) {
  1314. var e = t.mapValue.fields.__previous_value__;
  1315. return Pt(e) ? Dt(e) : e;
  1316. }
  1317. /**
  1318. * Returns the local time at which this timestamp was first set.
  1319. */ function Ot(t) {
  1320. var e = It(t.mapValue.fields.__local_write_time__.timestampValue);
  1321. return new Vt(e.seconds, e.nanos);
  1322. }
  1323. /**
  1324. * @license
  1325. * Copyright 2020 Google LLC
  1326. *
  1327. * Licensed under the Apache License, Version 2.0 (the "License");
  1328. * you may not use this file except in compliance with the License.
  1329. * You may obtain a copy of the License at
  1330. *
  1331. * http://www.apache.org/licenses/LICENSE-2.0
  1332. *
  1333. * Unless required by applicable law or agreed to in writing, software
  1334. * distributed under the License is distributed on an "AS IS" BASIS,
  1335. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1336. * See the License for the specific language governing permissions and
  1337. * limitations under the License.
  1338. */ var Nt = {
  1339. fields: {
  1340. __type__: {
  1341. stringValue: "__max__"
  1342. }
  1343. }
  1344. };
  1345. /** Extracts the backend's type order for the provided value. */ function qt(t) {
  1346. return "nullValue" in t ? 0 /* TypeOrder.NullValue */ : "booleanValue" in t ? 1 /* TypeOrder.BooleanValue */ : "integerValue" in t || "doubleValue" in t ? 2 /* TypeOrder.NumberValue */ : "timestampValue" in t ? 3 /* TypeOrder.TimestampValue */ : "stringValue" in t ? 5 /* TypeOrder.StringValue */ : "bytesValue" in t ? 6 /* TypeOrder.BlobValue */ : "referenceValue" in t ? 7 /* TypeOrder.RefValue */ : "geoPointValue" in t ? 8 /* TypeOrder.GeoPointValue */ : "arrayValue" in t ? 9 /* TypeOrder.ArrayValue */ : "mapValue" in t ? Pt(t) ? 4 /* TypeOrder.ServerTimestampValue */ :
  1347. /** Returns true if the Value represents the canonical {@link #MAX_VALUE} . */
  1348. function(t) {
  1349. return "__max__" === (((t.mapValue || {}).fields || {}).__type__ || {}).stringValue;
  1350. }(t) ? 9007199254740991 /* TypeOrder.MaxValue */ : 10 /* TypeOrder.ObjectValue */ : S();
  1351. }
  1352. /** Tests `left` and `right` for equality based on the backend semantics. */ function Rt(t, e) {
  1353. if (t === e) return !0;
  1354. var n = qt(t);
  1355. if (n !== qt(e)) return !1;
  1356. switch (n) {
  1357. case 0 /* TypeOrder.NullValue */ :
  1358. case 9007199254740991 /* TypeOrder.MaxValue */ :
  1359. return !0;
  1360. case 1 /* TypeOrder.BooleanValue */ :
  1361. return t.booleanValue === e.booleanValue;
  1362. case 4 /* TypeOrder.ServerTimestampValue */ :
  1363. return Ot(t).isEqual(Ot(e));
  1364. case 3 /* TypeOrder.TimestampValue */ :
  1365. return function(t, e) {
  1366. if ("string" == typeof t.timestampValue && "string" == typeof e.timestampValue && t.timestampValue.length === e.timestampValue.length)
  1367. // Use string equality for ISO 8601 timestamps
  1368. return t.timestampValue === e.timestampValue;
  1369. var n = It(t.timestampValue), r = It(e.timestampValue);
  1370. return n.seconds === r.seconds && n.nanos === r.nanos;
  1371. }(t, e);
  1372. case 5 /* TypeOrder.StringValue */ :
  1373. return t.stringValue === e.stringValue;
  1374. case 6 /* TypeOrder.BlobValue */ :
  1375. return function(t, e) {
  1376. return Ft(t.bytesValue).isEqual(Ft(e.bytesValue));
  1377. }(t, e);
  1378. case 7 /* TypeOrder.RefValue */ :
  1379. return t.referenceValue === e.referenceValue;
  1380. case 8 /* TypeOrder.GeoPointValue */ :
  1381. return function(t, e) {
  1382. return At(t.geoPointValue.latitude) === At(e.geoPointValue.latitude) && At(t.geoPointValue.longitude) === At(e.geoPointValue.longitude);
  1383. }(t, e);
  1384. case 2 /* TypeOrder.NumberValue */ :
  1385. return function(t, e) {
  1386. if ("integerValue" in t && "integerValue" in e) return At(t.integerValue) === At(e.integerValue);
  1387. if ("doubleValue" in t && "doubleValue" in e) {
  1388. var n = At(t.doubleValue), r = At(e.doubleValue);
  1389. return n === r ? ht(n) === ht(r) : isNaN(n) && isNaN(r);
  1390. }
  1391. return !1;
  1392. }(t, e);
  1393. case 9 /* TypeOrder.ArrayValue */ :
  1394. return bt(t.arrayValue.values || [], e.arrayValue.values || [], Rt);
  1395. case 10 /* TypeOrder.ObjectValue */ :
  1396. return function(t, e) {
  1397. var n = t.mapValue.fields || {}, r = e.mapValue.fields || {};
  1398. if (Tt(n) !== Tt(r)) return !1;
  1399. for (var i in n) if (n.hasOwnProperty(i) && (void 0 === r[i] || !Rt(n[i], r[i]))) return !1;
  1400. return !0;
  1401. }(t, e);
  1402. default:
  1403. return S();
  1404. }
  1405. }
  1406. function Ct(t, e) {
  1407. return void 0 !== (t.values || []).find((function(t) {
  1408. return Rt(t, e);
  1409. }));
  1410. }
  1411. function xt(t, e) {
  1412. if (t === e) return 0;
  1413. var n = qt(t), r = qt(e);
  1414. if (n !== r) return _t(n, r);
  1415. switch (n) {
  1416. case 0 /* TypeOrder.NullValue */ :
  1417. case 9007199254740991 /* TypeOrder.MaxValue */ :
  1418. return 0;
  1419. case 1 /* TypeOrder.BooleanValue */ :
  1420. return _t(t.booleanValue, e.booleanValue);
  1421. case 2 /* TypeOrder.NumberValue */ :
  1422. return function(t, e) {
  1423. var n = At(t.integerValue || t.doubleValue), r = At(e.integerValue || e.doubleValue);
  1424. return n < r ? -1 : n > r ? 1 : n === r ? 0 :
  1425. // one or both are NaN.
  1426. isNaN(n) ? isNaN(r) ? 0 : -1 : 1;
  1427. }(t, e);
  1428. case 3 /* TypeOrder.TimestampValue */ :
  1429. return Lt(t.timestampValue, e.timestampValue);
  1430. case 4 /* TypeOrder.ServerTimestampValue */ :
  1431. return Lt(Ot(t), Ot(e));
  1432. case 5 /* TypeOrder.StringValue */ :
  1433. return _t(t.stringValue, e.stringValue);
  1434. case 6 /* TypeOrder.BlobValue */ :
  1435. return function(t, e) {
  1436. var n = Ft(t), r = Ft(e);
  1437. return n.compareTo(r);
  1438. }(t.bytesValue, e.bytesValue);
  1439. case 7 /* TypeOrder.RefValue */ :
  1440. return function(t, e) {
  1441. for (var n = t.split("/"), r = e.split("/"), i = 0; i < n.length && i < r.length; i++) {
  1442. var o = _t(n[i], r[i]);
  1443. if (0 !== o) return o;
  1444. }
  1445. return _t(n.length, r.length);
  1446. }(t.referenceValue, e.referenceValue);
  1447. case 8 /* TypeOrder.GeoPointValue */ :
  1448. return function(t, e) {
  1449. var n = _t(At(t.latitude), At(e.latitude));
  1450. return 0 !== n ? n : _t(At(t.longitude), At(e.longitude));
  1451. }(t.geoPointValue, e.geoPointValue);
  1452. case 9 /* TypeOrder.ArrayValue */ :
  1453. return function(t, e) {
  1454. for (var n = t.values || [], r = e.values || [], i = 0; i < n.length && i < r.length; ++i) {
  1455. var o = xt(n[i], r[i]);
  1456. if (o) return o;
  1457. }
  1458. return _t(n.length, r.length);
  1459. }(t.arrayValue, e.arrayValue);
  1460. case 10 /* TypeOrder.ObjectValue */ :
  1461. return function(t, e) {
  1462. if (t === Nt && e === Nt) return 0;
  1463. if (t === Nt) return 1;
  1464. if (e === Nt) return -1;
  1465. var n = t.fields || {}, r = Object.keys(n), i = e.fields || {}, o = Object.keys(i);
  1466. // Even though MapValues are likely sorted correctly based on their insertion
  1467. // order (e.g. when received from the backend), local modifications can bring
  1468. // elements out of order. We need to re-sort the elements to ensure that
  1469. // canonical IDs are independent of insertion order.
  1470. r.sort(), o.sort();
  1471. for (var a = 0; a < r.length && a < o.length; ++a) {
  1472. var u = _t(r[a], o[a]);
  1473. if (0 !== u) return u;
  1474. var s = xt(n[r[a]], i[o[a]]);
  1475. if (0 !== s) return s;
  1476. }
  1477. return _t(r.length, o.length);
  1478. }(t.mapValue, e.mapValue);
  1479. default:
  1480. throw S();
  1481. }
  1482. }
  1483. function Lt(t, e) {
  1484. if ("string" == typeof t && "string" == typeof e && t.length === e.length) return _t(t, e);
  1485. var n = It(t), r = It(e), i = _t(n.seconds, r.seconds);
  1486. return 0 !== i ? i : _t(n.nanos, r.nanos);
  1487. }
  1488. function jt(t, e) {
  1489. return {
  1490. referenceValue: "projects/".concat(t.projectId, "/databases/").concat(t.database, "/documents/").concat(e.path.canonicalString())
  1491. };
  1492. }
  1493. /** Returns true if `value` is an ArrayValue. */ function Mt(t) {
  1494. return !!t && "arrayValue" in t;
  1495. }
  1496. /** Returns true if `value` is a NullValue. */ function Ut(t) {
  1497. return !!t && "nullValue" in t;
  1498. }
  1499. /** Returns true if `value` is NaN. */ function Bt(t) {
  1500. return !!t && "doubleValue" in t && isNaN(Number(t.doubleValue));
  1501. }
  1502. /** Returns true if `value` is a MapValue. */ function Gt(t) {
  1503. return !!t && "mapValue" in t;
  1504. }
  1505. /** Creates a deep copy of `source`. */ function Qt(t) {
  1506. if (t.geoPointValue) return {
  1507. geoPointValue: Object.assign({}, t.geoPointValue)
  1508. };
  1509. if (t.timestampValue && "object" == typeof t.timestampValue) return {
  1510. timestampValue: Object.assign({}, t.timestampValue)
  1511. };
  1512. if (t.mapValue) {
  1513. var e = {
  1514. mapValue: {
  1515. fields: {}
  1516. }
  1517. };
  1518. return Et(t.mapValue.fields, (function(t, n) {
  1519. return e.mapValue.fields[t] = Qt(n);
  1520. })), e;
  1521. }
  1522. if (t.arrayValue) {
  1523. for (var n = {
  1524. arrayValue: {
  1525. values: []
  1526. }
  1527. }, r = 0; r < (t.arrayValue.values || []).length; ++r) n.arrayValue.values[r] = Qt(t.arrayValue.values[r]);
  1528. return n;
  1529. }
  1530. return Object.assign({}, t);
  1531. }
  1532. var zt = function(t, e) {
  1533. this.position = t, this.inclusive = e;
  1534. };
  1535. function Kt(t, e) {
  1536. if (null === t) return null === e;
  1537. if (null === e) return !1;
  1538. if (t.inclusive !== e.inclusive || t.position.length !== e.position.length) return !1;
  1539. for (var n = 0; n < t.position.length; n++) if (!Rt(t.position[n], e.position[n])) return !1;
  1540. return !0;
  1541. }
  1542. /**
  1543. * @license
  1544. * Copyright 2022 Google LLC
  1545. *
  1546. * Licensed under the Apache License, Version 2.0 (the "License");
  1547. * you may not use this file except in compliance with the License.
  1548. * You may obtain a copy of the License at
  1549. *
  1550. * http://www.apache.org/licenses/LICENSE-2.0
  1551. *
  1552. * Unless required by applicable law or agreed to in writing, software
  1553. * distributed under the License is distributed on an "AS IS" BASIS,
  1554. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1555. * See the License for the specific language governing permissions and
  1556. * limitations under the License.
  1557. */ var Wt = function() {}, Ht = /** @class */ function(e) {
  1558. function n(t, n, r) {
  1559. var i = this;
  1560. return (i = e.call(this) || this).field = t, i.op = n, i.value = r, i;
  1561. }
  1562. /**
  1563. * Creates a filter based on the provided arguments.
  1564. */ return t(n, e), n.create = function(t, e, r) {
  1565. return t.isKeyField() ? "in" /* Operator.IN */ === e || "not-in" /* Operator.NOT_IN */ === e ? this.createKeyFieldInFilter(t, e, r) : new Jt(t, e, r) : "array-contains" /* Operator.ARRAY_CONTAINS */ === e ? new ee(t, r) : "in" /* Operator.IN */ === e ? new ne(t, r) : "not-in" /* Operator.NOT_IN */ === e ? new re(t, r) : "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ === e ? new ie(t, r) : new n(t, e, r);
  1566. }, n.createKeyFieldInFilter = function(t, e, n) {
  1567. return "in" /* Operator.IN */ === e ? new Zt(t, n) : new $t(t, n);
  1568. }, n.prototype.matches = function(t) {
  1569. var e = t.data.field(this.field);
  1570. // Types do not have to match in NOT_EQUAL filters.
  1571. return "!=" /* Operator.NOT_EQUAL */ === this.op ? null !== e && this.matchesComparison(xt(e, this.value)) : null !== e && qt(this.value) === qt(e) && this.matchesComparison(xt(e, this.value));
  1572. // Only compare types with matching backend order (such as double and int).
  1573. }, n.prototype.matchesComparison = function(t) {
  1574. switch (this.op) {
  1575. case "<" /* Operator.LESS_THAN */ :
  1576. return t < 0;
  1577. case "<=" /* Operator.LESS_THAN_OR_EQUAL */ :
  1578. return t <= 0;
  1579. case "==" /* Operator.EQUAL */ :
  1580. return 0 === t;
  1581. case "!=" /* Operator.NOT_EQUAL */ :
  1582. return 0 !== t;
  1583. case ">" /* Operator.GREATER_THAN */ :
  1584. return t > 0;
  1585. case ">=" /* Operator.GREATER_THAN_OR_EQUAL */ :
  1586. return t >= 0;
  1587. default:
  1588. return S();
  1589. }
  1590. }, n.prototype.isInequality = function() {
  1591. return [ "<" /* Operator.LESS_THAN */ , "<=" /* Operator.LESS_THAN_OR_EQUAL */ , ">" /* Operator.GREATER_THAN */ , ">=" /* Operator.GREATER_THAN_OR_EQUAL */ , "!=" /* Operator.NOT_EQUAL */ , "not-in" /* Operator.NOT_IN */ ].indexOf(this.op) >= 0;
  1592. }, n.prototype.getFlattenedFilters = function() {
  1593. return [ this ];
  1594. }, n.prototype.getFilters = function() {
  1595. return [ this ];
  1596. }, n.prototype.getFirstInequalityField = function() {
  1597. return this.isInequality() ? this.field : null;
  1598. }, n;
  1599. }(Wt), Yt = /** @class */ function(e) {
  1600. function n(t, n) {
  1601. var r = this;
  1602. return (r = e.call(this) || this).filters = t, r.op = n, r.D = null, r;
  1603. }
  1604. /**
  1605. * Creates a filter based on the provided arguments.
  1606. */ return t(n, e), n.create = function(t, e) {
  1607. return new n(t, e);
  1608. }, n.prototype.matches = function(t) {
  1609. return "and" /* CompositeOperator.AND */ === this.op ? void 0 === this.filters.find((function(e) {
  1610. return !e.matches(t);
  1611. })) : void 0 !== this.filters.find((function(e) {
  1612. return e.matches(t);
  1613. }));
  1614. }, n.prototype.getFlattenedFilters = function() {
  1615. return null !== this.D || (this.D = this.filters.reduce((function(t, e) {
  1616. return t.concat(e.getFlattenedFilters());
  1617. }), [])), this.D;
  1618. },
  1619. // Returns a mutable copy of `this.filters`
  1620. n.prototype.getFilters = function() {
  1621. return Object.assign([], this.filters);
  1622. }, n.prototype.getFirstInequalityField = function() {
  1623. var t = this.F((function(t) {
  1624. return t.isInequality();
  1625. }));
  1626. return null !== t ? t.field : null;
  1627. },
  1628. // Performs a depth-first search to find and return the first FieldFilter in the composite filter
  1629. // that satisfies the predicate. Returns `null` if none of the FieldFilters satisfy the
  1630. // predicate.
  1631. n.prototype.F = function(t) {
  1632. for (var e = 0, n = this.getFlattenedFilters(); e < n.length; e++) {
  1633. var r = n[e];
  1634. if (t(r)) return r;
  1635. }
  1636. return null;
  1637. }, n;
  1638. }(Wt);
  1639. function Xt(t, e) {
  1640. return t instanceof Ht ? function(t, e) {
  1641. return e instanceof Ht && t.op === e.op && t.field.isEqual(e.field) && Rt(t.value, e.value);
  1642. }(t, e) : t instanceof Yt ? function(t, e) {
  1643. return e instanceof Yt && t.op === e.op && t.filters.length === e.filters.length && t.filters.reduce((function(t, n, r) {
  1644. return t && Xt(n, e.filters[r]);
  1645. }), !0);
  1646. }(t, e) : void S();
  1647. }
  1648. var Jt = /** @class */ function(e) {
  1649. function n(t, n, r) {
  1650. var i = this;
  1651. return (i = e.call(this, t, n, r) || this).key = it.fromName(r.referenceValue),
  1652. i;
  1653. }
  1654. return t(n, e), n.prototype.matches = function(t) {
  1655. var e = it.comparator(t.key, this.key);
  1656. return this.matchesComparison(e);
  1657. }, n;
  1658. }(Ht), Zt = /** @class */ function(e) {
  1659. function n(t, n) {
  1660. var r = this;
  1661. return (r = e.call(this, t, "in" /* Operator.IN */ , n) || this).keys = te("in" /* Operator.IN */ , n),
  1662. r;
  1663. }
  1664. return t(n, e), n.prototype.matches = function(t) {
  1665. return this.keys.some((function(e) {
  1666. return e.isEqual(t.key);
  1667. }));
  1668. }, n;
  1669. }(Ht), $t = /** @class */ function(e) {
  1670. function n(t, n) {
  1671. var r = this;
  1672. return (r = e.call(this, t, "not-in" /* Operator.NOT_IN */ , n) || this).keys = te("not-in" /* Operator.NOT_IN */ , n),
  1673. r;
  1674. }
  1675. return t(n, e), n.prototype.matches = function(t) {
  1676. return !this.keys.some((function(e) {
  1677. return e.isEqual(t.key);
  1678. }));
  1679. }, n;
  1680. }(Ht);
  1681. /** Filter that matches on key fields within an array. */ function te(t, e) {
  1682. var n;
  1683. return ((null === (n = e.arrayValue) || void 0 === n ? void 0 : n.values) || []).map((function(t) {
  1684. return it.fromName(t.referenceValue);
  1685. }));
  1686. }
  1687. /** A Filter that implements the array-contains operator. */ var ee = /** @class */ function(e) {
  1688. function n(t, n) {
  1689. return e.call(this, t, "array-contains" /* Operator.ARRAY_CONTAINS */ , n) || this;
  1690. }
  1691. return t(n, e), n.prototype.matches = function(t) {
  1692. var e = t.data.field(this.field);
  1693. return Mt(e) && Ct(e.arrayValue, this.value);
  1694. }, n;
  1695. }(Ht), ne = /** @class */ function(e) {
  1696. function n(t, n) {
  1697. return e.call(this, t, "in" /* Operator.IN */ , n) || this;
  1698. }
  1699. return t(n, e), n.prototype.matches = function(t) {
  1700. var e = t.data.field(this.field);
  1701. return null !== e && Ct(this.value.arrayValue, e);
  1702. }, n;
  1703. }(Ht), re = /** @class */ function(e) {
  1704. function n(t, n) {
  1705. return e.call(this, t, "not-in" /* Operator.NOT_IN */ , n) || this;
  1706. }
  1707. return t(n, e), n.prototype.matches = function(t) {
  1708. if (Ct(this.value.arrayValue, {
  1709. nullValue: "NULL_VALUE"
  1710. })) return !1;
  1711. var e = t.data.field(this.field);
  1712. return null !== e && !Ct(this.value.arrayValue, e);
  1713. }, n;
  1714. }(Ht), ie = /** @class */ function(e) {
  1715. function n(t, n) {
  1716. return e.call(this, t, "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ , n) || this;
  1717. }
  1718. return t(n, e), n.prototype.matches = function(t) {
  1719. var e = this, n = t.data.field(this.field);
  1720. return !(!Mt(n) || !n.arrayValue.values) && n.arrayValue.values.some((function(t) {
  1721. return Ct(e.value.arrayValue, t);
  1722. }));
  1723. }, n;
  1724. }(Ht), oe = function(t, e /* Direction.ASCENDING */) {
  1725. void 0 === e && (e = "asc"), this.field = t, this.dir = e;
  1726. };
  1727. /** A Filter that implements the IN operator. */ function ae(t, e) {
  1728. return t.dir === e.dir && t.field.isEqual(e.field);
  1729. }
  1730. /**
  1731. * @license
  1732. * Copyright 2017 Google LLC
  1733. *
  1734. * Licensed under the Apache License, Version 2.0 (the "License");
  1735. * you may not use this file except in compliance with the License.
  1736. * You may obtain a copy of the License at
  1737. *
  1738. * http://www.apache.org/licenses/LICENSE-2.0
  1739. *
  1740. * Unless required by applicable law or agreed to in writing, software
  1741. * distributed under the License is distributed on an "AS IS" BASIS,
  1742. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1743. * See the License for the specific language governing permissions and
  1744. * limitations under the License.
  1745. */
  1746. /**
  1747. * A version of a document in Firestore. This corresponds to the version
  1748. * timestamp, such as update_time or read_time.
  1749. */ var ue = /** @class */ function() {
  1750. function t(t) {
  1751. this.timestamp = t;
  1752. }
  1753. return t.fromTimestamp = function(e) {
  1754. return new t(e);
  1755. }, t.min = function() {
  1756. return new t(new Vt(0, 0));
  1757. }, t.max = function() {
  1758. return new t(new Vt(253402300799, 999999999));
  1759. }, t.prototype.compareTo = function(t) {
  1760. return this.timestamp._compareTo(t.timestamp);
  1761. }, t.prototype.isEqual = function(t) {
  1762. return this.timestamp.isEqual(t.timestamp);
  1763. },
  1764. /** Returns a number representation of the version for use in spec tests. */ t.prototype.toMicroseconds = function() {
  1765. // Convert to microseconds.
  1766. return 1e6 * this.timestamp.seconds + this.timestamp.nanoseconds / 1e3;
  1767. }, t.prototype.toString = function() {
  1768. return "SnapshotVersion(" + this.timestamp.toString() + ")";
  1769. }, t.prototype.toTimestamp = function() {
  1770. return this.timestamp;
  1771. }, t;
  1772. }(), se = /** @class */ function() {
  1773. function t(t, e) {
  1774. this.comparator = t, this.root = e || le.EMPTY;
  1775. }
  1776. // Returns a copy of the map, with the specified key/value added or replaced.
  1777. return t.prototype.insert = function(e, n) {
  1778. return new t(this.comparator, this.root.insert(e, n, this.comparator).copy(null, null, le.BLACK, null, null));
  1779. },
  1780. // Returns a copy of the map, with the specified key removed.
  1781. t.prototype.remove = function(e) {
  1782. return new t(this.comparator, this.root.remove(e, this.comparator).copy(null, null, le.BLACK, null, null));
  1783. },
  1784. // Returns the value of the node with the given key, or null.
  1785. t.prototype.get = function(t) {
  1786. for (var e = this.root; !e.isEmpty(); ) {
  1787. var n = this.comparator(t, e.key);
  1788. if (0 === n) return e.value;
  1789. n < 0 ? e = e.left : n > 0 && (e = e.right);
  1790. }
  1791. return null;
  1792. },
  1793. // Returns the index of the element in this sorted map, or -1 if it doesn't
  1794. // exist.
  1795. t.prototype.indexOf = function(t) {
  1796. for (
  1797. // Number of nodes that were pruned when descending right
  1798. var e = 0, n = this.root; !n.isEmpty(); ) {
  1799. var r = this.comparator(t, n.key);
  1800. if (0 === r) return e + n.left.size;
  1801. r < 0 ? n = n.left : (
  1802. // Count all nodes left of the node plus the node itself
  1803. e += n.left.size + 1, n = n.right);
  1804. }
  1805. // Node not found
  1806. return -1;
  1807. }, t.prototype.isEmpty = function() {
  1808. return this.root.isEmpty();
  1809. }, Object.defineProperty(t.prototype, "size", {
  1810. // Returns the total number of nodes in the map.
  1811. get: function() {
  1812. return this.root.size;
  1813. },
  1814. enumerable: !1,
  1815. configurable: !0
  1816. }),
  1817. // Returns the minimum key in the map.
  1818. t.prototype.minKey = function() {
  1819. return this.root.minKey();
  1820. },
  1821. // Returns the maximum key in the map.
  1822. t.prototype.maxKey = function() {
  1823. return this.root.maxKey();
  1824. },
  1825. // Traverses the map in key order and calls the specified action function
  1826. // for each key/value pair. If action returns true, traversal is aborted.
  1827. // Returns the first truthy value returned by action, or the last falsey
  1828. // value returned by action.
  1829. t.prototype.inorderTraversal = function(t) {
  1830. return this.root.inorderTraversal(t);
  1831. }, t.prototype.forEach = function(t) {
  1832. this.inorderTraversal((function(e, n) {
  1833. return t(e, n), !1;
  1834. }));
  1835. }, t.prototype.toString = function() {
  1836. var t = [];
  1837. return this.inorderTraversal((function(e, n) {
  1838. return t.push("".concat(e, ":").concat(n)), !1;
  1839. })), "{".concat(t.join(", "), "}");
  1840. },
  1841. // Traverses the map in reverse key order and calls the specified action
  1842. // function for each key/value pair. If action returns true, traversal is
  1843. // aborted.
  1844. // Returns the first truthy value returned by action, or the last falsey
  1845. // value returned by action.
  1846. t.prototype.reverseTraversal = function(t) {
  1847. return this.root.reverseTraversal(t);
  1848. },
  1849. // Returns an iterator over the SortedMap.
  1850. t.prototype.getIterator = function() {
  1851. return new ce(this.root, null, this.comparator, !1);
  1852. }, t.prototype.getIteratorFrom = function(t) {
  1853. return new ce(this.root, t, this.comparator, !1);
  1854. }, t.prototype.getReverseIterator = function() {
  1855. return new ce(this.root, null, this.comparator, !0);
  1856. }, t.prototype.getReverseIteratorFrom = function(t) {
  1857. return new ce(this.root, t, this.comparator, !0);
  1858. }, t;
  1859. }(), ce = /** @class */ function() {
  1860. function t(t, e, n, r) {
  1861. this.isReverse = r, this.nodeStack = [];
  1862. for (var i = 1; !t.isEmpty(); ) if (i = e ? n(t.key, e) : 1,
  1863. // flip the comparison if we're going in reverse
  1864. e && r && (i *= -1), i < 0)
  1865. // This node is less than our start key. ignore it
  1866. t = this.isReverse ? t.left : t.right; else {
  1867. if (0 === i) {
  1868. // This node is exactly equal to our start key. Push it on the stack,
  1869. // but stop iterating;
  1870. this.nodeStack.push(t);
  1871. break;
  1872. }
  1873. // This node is greater than our start key, add it to the stack and move
  1874. // to the next one
  1875. this.nodeStack.push(t), t = this.isReverse ? t.right : t.left;
  1876. }
  1877. }
  1878. return t.prototype.getNext = function() {
  1879. var t = this.nodeStack.pop(), e = {
  1880. key: t.key,
  1881. value: t.value
  1882. };
  1883. if (this.isReverse) for (t = t.left; !t.isEmpty(); ) this.nodeStack.push(t), t = t.right; else for (t = t.right; !t.isEmpty(); ) this.nodeStack.push(t),
  1884. t = t.left;
  1885. return e;
  1886. }, t.prototype.hasNext = function() {
  1887. return this.nodeStack.length > 0;
  1888. }, t.prototype.peek = function() {
  1889. if (0 === this.nodeStack.length) return null;
  1890. var t = this.nodeStack[this.nodeStack.length - 1];
  1891. return {
  1892. key: t.key,
  1893. value: t.value
  1894. };
  1895. }, t;
  1896. }(), le = /** @class */ function() {
  1897. function t(e, n, r, i, o) {
  1898. this.key = e, this.value = n, this.color = null != r ? r : t.RED, this.left = null != i ? i : t.EMPTY,
  1899. this.right = null != o ? o : t.EMPTY, this.size = this.left.size + 1 + this.right.size;
  1900. }
  1901. // Returns a copy of the current node, optionally replacing pieces of it.
  1902. return t.prototype.copy = function(e, n, r, i, o) {
  1903. return new t(null != e ? e : this.key, null != n ? n : this.value, null != r ? r : this.color, null != i ? i : this.left, null != o ? o : this.right);
  1904. }, t.prototype.isEmpty = function() {
  1905. return !1;
  1906. },
  1907. // Traverses the tree in key order and calls the specified action function
  1908. // for each node. If action returns true, traversal is aborted.
  1909. // Returns the first truthy value returned by action, or the last falsey
  1910. // value returned by action.
  1911. t.prototype.inorderTraversal = function(t) {
  1912. return this.left.inorderTraversal(t) || t(this.key, this.value) || this.right.inorderTraversal(t);
  1913. },
  1914. // Traverses the tree in reverse key order and calls the specified action
  1915. // function for each node. If action returns true, traversal is aborted.
  1916. // Returns the first truthy value returned by action, or the last falsey
  1917. // value returned by action.
  1918. t.prototype.reverseTraversal = function(t) {
  1919. return this.right.reverseTraversal(t) || t(this.key, this.value) || this.left.reverseTraversal(t);
  1920. },
  1921. // Returns the minimum node in the tree.
  1922. t.prototype.min = function() {
  1923. return this.left.isEmpty() ? this : this.left.min();
  1924. },
  1925. // Returns the maximum key in the tree.
  1926. t.prototype.minKey = function() {
  1927. return this.min().key;
  1928. },
  1929. // Returns the maximum key in the tree.
  1930. t.prototype.maxKey = function() {
  1931. return this.right.isEmpty() ? this.key : this.right.maxKey();
  1932. },
  1933. // Returns new tree, with the key/value added.
  1934. t.prototype.insert = function(t, e, n) {
  1935. var r = this, i = n(t, r.key);
  1936. return (r = i < 0 ? r.copy(null, null, null, r.left.insert(t, e, n), null) : 0 === i ? r.copy(null, e, null, null, null) : r.copy(null, null, null, null, r.right.insert(t, e, n))).fixUp();
  1937. }, t.prototype.removeMin = function() {
  1938. if (this.left.isEmpty()) return t.EMPTY;
  1939. var e = this;
  1940. return e.left.isRed() || e.left.left.isRed() || (e = e.moveRedLeft()), (e = e.copy(null, null, null, e.left.removeMin(), null)).fixUp();
  1941. },
  1942. // Returns new tree, with the specified item removed.
  1943. t.prototype.remove = function(e, n) {
  1944. var r, i = this;
  1945. if (n(e, i.key) < 0) i.left.isEmpty() || i.left.isRed() || i.left.left.isRed() || (i = i.moveRedLeft()),
  1946. i = i.copy(null, null, null, i.left.remove(e, n), null); else {
  1947. if (i.left.isRed() && (i = i.rotateRight()), i.right.isEmpty() || i.right.isRed() || i.right.left.isRed() || (i = i.moveRedRight()),
  1948. 0 === n(e, i.key)) {
  1949. if (i.right.isEmpty()) return t.EMPTY;
  1950. r = i.right.min(), i = i.copy(r.key, r.value, null, null, i.right.removeMin());
  1951. }
  1952. i = i.copy(null, null, null, null, i.right.remove(e, n));
  1953. }
  1954. return i.fixUp();
  1955. }, t.prototype.isRed = function() {
  1956. return this.color;
  1957. },
  1958. // Returns new tree after performing any needed rotations.
  1959. t.prototype.fixUp = function() {
  1960. var t = this;
  1961. return t.right.isRed() && !t.left.isRed() && (t = t.rotateLeft()), t.left.isRed() && t.left.left.isRed() && (t = t.rotateRight()),
  1962. t.left.isRed() && t.right.isRed() && (t = t.colorFlip()), t;
  1963. }, t.prototype.moveRedLeft = function() {
  1964. var t = this.colorFlip();
  1965. return t.right.left.isRed() && (t = (t = (t = t.copy(null, null, null, null, t.right.rotateRight())).rotateLeft()).colorFlip()),
  1966. t;
  1967. }, t.prototype.moveRedRight = function() {
  1968. var t = this.colorFlip();
  1969. return t.left.left.isRed() && (t = (t = t.rotateRight()).colorFlip()), t;
  1970. }, t.prototype.rotateLeft = function() {
  1971. var e = this.copy(null, null, t.RED, null, this.right.left);
  1972. return this.right.copy(null, null, this.color, e, null);
  1973. }, t.prototype.rotateRight = function() {
  1974. var e = this.copy(null, null, t.RED, this.left.right, null);
  1975. return this.left.copy(null, null, this.color, null, e);
  1976. }, t.prototype.colorFlip = function() {
  1977. var t = this.left.copy(null, null, !this.left.color, null, null), e = this.right.copy(null, null, !this.right.color, null, null);
  1978. return this.copy(null, null, !this.color, t, e);
  1979. },
  1980. // For testing.
  1981. t.prototype.checkMaxDepth = function() {
  1982. var t = this.check();
  1983. return Math.pow(2, t) <= this.size + 1;
  1984. },
  1985. // In a balanced RB tree, the black-depth (number of black nodes) from root to
  1986. // leaves is equal on both sides. This function verifies that or asserts.
  1987. t.prototype.check = function() {
  1988. if (this.isRed() && this.left.isRed()) throw S();
  1989. if (this.right.isRed()) throw S();
  1990. var t = this.left.check();
  1991. if (t !== this.right.check()) throw S();
  1992. return t + (this.isRed() ? 0 : 1);
  1993. }, t;
  1994. }();
  1995. /**
  1996. * @license
  1997. * Copyright 2017 Google LLC
  1998. *
  1999. * Licensed under the Apache License, Version 2.0 (the "License");
  2000. * you may not use this file except in compliance with the License.
  2001. * You may obtain a copy of the License at
  2002. *
  2003. * http://www.apache.org/licenses/LICENSE-2.0
  2004. *
  2005. * Unless required by applicable law or agreed to in writing, software
  2006. * distributed under the License is distributed on an "AS IS" BASIS,
  2007. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2008. * See the License for the specific language governing permissions and
  2009. * limitations under the License.
  2010. */
  2011. // An immutable sorted map implementation, based on a Left-leaning Red-Black
  2012. // tree.
  2013. // end LLRBNode
  2014. // Empty node is shared between all LLRB trees.
  2015. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  2016. le.EMPTY = null, le.RED = !0, le.BLACK = !1,
  2017. // end LLRBEmptyNode
  2018. le.EMPTY = new (/** @class */ function() {
  2019. function t() {
  2020. this.size = 0;
  2021. }
  2022. return Object.defineProperty(t.prototype, "key", {
  2023. get: function() {
  2024. throw S();
  2025. },
  2026. enumerable: !1,
  2027. configurable: !0
  2028. }), Object.defineProperty(t.prototype, "value", {
  2029. get: function() {
  2030. throw S();
  2031. },
  2032. enumerable: !1,
  2033. configurable: !0
  2034. }), Object.defineProperty(t.prototype, "color", {
  2035. get: function() {
  2036. throw S();
  2037. },
  2038. enumerable: !1,
  2039. configurable: !0
  2040. }), Object.defineProperty(t.prototype, "left", {
  2041. get: function() {
  2042. throw S();
  2043. },
  2044. enumerable: !1,
  2045. configurable: !0
  2046. }), Object.defineProperty(t.prototype, "right", {
  2047. get: function() {
  2048. throw S();
  2049. },
  2050. enumerable: !1,
  2051. configurable: !0
  2052. }),
  2053. // Returns a copy of the current node.
  2054. t.prototype.copy = function(t, e, n, r, i) {
  2055. return this;
  2056. },
  2057. // Returns a copy of the tree, with the specified key/value added.
  2058. t.prototype.insert = function(t, e, n) {
  2059. return new le(t, e);
  2060. },
  2061. // Returns a copy of the tree, with the specified key removed.
  2062. t.prototype.remove = function(t, e) {
  2063. return this;
  2064. }, t.prototype.isEmpty = function() {
  2065. return !0;
  2066. }, t.prototype.inorderTraversal = function(t) {
  2067. return !1;
  2068. }, t.prototype.reverseTraversal = function(t) {
  2069. return !1;
  2070. }, t.prototype.minKey = function() {
  2071. return null;
  2072. }, t.prototype.maxKey = function() {
  2073. return null;
  2074. }, t.prototype.isRed = function() {
  2075. return !1;
  2076. },
  2077. // For testing.
  2078. t.prototype.checkMaxDepth = function() {
  2079. return !0;
  2080. }, t.prototype.check = function() {
  2081. return 0;
  2082. }, t;
  2083. }());
  2084. /**
  2085. * @license
  2086. * Copyright 2017 Google LLC
  2087. *
  2088. * Licensed under the Apache License, Version 2.0 (the "License");
  2089. * you may not use this file except in compliance with the License.
  2090. * You may obtain a copy of the License at
  2091. *
  2092. * http://www.apache.org/licenses/LICENSE-2.0
  2093. *
  2094. * Unless required by applicable law or agreed to in writing, software
  2095. * distributed under the License is distributed on an "AS IS" BASIS,
  2096. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2097. * See the License for the specific language governing permissions and
  2098. * limitations under the License.
  2099. */
  2100. /**
  2101. * SortedSet is an immutable (copy-on-write) collection that holds elements
  2102. * in order specified by the provided comparator.
  2103. *
  2104. * NOTE: if provided comparator returns 0 for two elements, we consider them to
  2105. * be equal!
  2106. */
  2107. var fe = /** @class */ function() {
  2108. function t(t) {
  2109. this.comparator = t, this.data = new se(this.comparator);
  2110. }
  2111. return t.prototype.has = function(t) {
  2112. return null !== this.data.get(t);
  2113. }, t.prototype.first = function() {
  2114. return this.data.minKey();
  2115. }, t.prototype.last = function() {
  2116. return this.data.maxKey();
  2117. }, Object.defineProperty(t.prototype, "size", {
  2118. get: function() {
  2119. return this.data.size;
  2120. },
  2121. enumerable: !1,
  2122. configurable: !0
  2123. }), t.prototype.indexOf = function(t) {
  2124. return this.data.indexOf(t);
  2125. },
  2126. /** Iterates elements in order defined by "comparator" */ t.prototype.forEach = function(t) {
  2127. this.data.inorderTraversal((function(e, n) {
  2128. return t(e), !1;
  2129. }));
  2130. },
  2131. /** Iterates over `elem`s such that: range[0] &lt;= elem &lt; range[1]. */ t.prototype.forEachInRange = function(t, e) {
  2132. for (var n = this.data.getIteratorFrom(t[0]); n.hasNext(); ) {
  2133. var r = n.getNext();
  2134. if (this.comparator(r.key, t[1]) >= 0) return;
  2135. e(r.key);
  2136. }
  2137. },
  2138. /**
  2139. * Iterates over `elem`s such that: start &lt;= elem until false is returned.
  2140. */
  2141. t.prototype.forEachWhile = function(t, e) {
  2142. var n;
  2143. for (n = void 0 !== e ? this.data.getIteratorFrom(e) : this.data.getIterator(); n.hasNext(); ) if (!t(n.getNext().key)) return;
  2144. },
  2145. /** Finds the least element greater than or equal to `elem`. */ t.prototype.firstAfterOrEqual = function(t) {
  2146. var e = this.data.getIteratorFrom(t);
  2147. return e.hasNext() ? e.getNext().key : null;
  2148. }, t.prototype.getIterator = function() {
  2149. return new he(this.data.getIterator());
  2150. }, t.prototype.getIteratorFrom = function(t) {
  2151. return new he(this.data.getIteratorFrom(t));
  2152. },
  2153. /** Inserts or updates an element */ t.prototype.add = function(t) {
  2154. return this.copy(this.data.remove(t).insert(t, !0));
  2155. },
  2156. /** Deletes an element */ t.prototype.delete = function(t) {
  2157. return this.has(t) ? this.copy(this.data.remove(t)) : this;
  2158. }, t.prototype.isEmpty = function() {
  2159. return this.data.isEmpty();
  2160. }, t.prototype.unionWith = function(t) {
  2161. var e = this;
  2162. // Make sure `result` always refers to the larger one of the two sets.
  2163. return e.size < t.size && (e = t, t = this), t.forEach((function(t) {
  2164. e = e.add(t);
  2165. })), e;
  2166. }, t.prototype.isEqual = function(e) {
  2167. if (!(e instanceof t)) return !1;
  2168. if (this.size !== e.size) return !1;
  2169. for (var n = this.data.getIterator(), r = e.data.getIterator(); n.hasNext(); ) {
  2170. var i = n.getNext().key, o = r.getNext().key;
  2171. if (0 !== this.comparator(i, o)) return !1;
  2172. }
  2173. return !0;
  2174. }, t.prototype.toArray = function() {
  2175. var t = [];
  2176. return this.forEach((function(e) {
  2177. t.push(e);
  2178. })), t;
  2179. }, t.prototype.toString = function() {
  2180. var t = [];
  2181. return this.forEach((function(e) {
  2182. return t.push(e);
  2183. })), "SortedSet(" + t.toString() + ")";
  2184. }, t.prototype.copy = function(e) {
  2185. var n = new t(this.comparator);
  2186. return n.data = e, n;
  2187. }, t;
  2188. }(), he = /** @class */ function() {
  2189. function t(t) {
  2190. this.iter = t;
  2191. }
  2192. return t.prototype.getNext = function() {
  2193. return this.iter.getNext().key;
  2194. }, t.prototype.hasNext = function() {
  2195. return this.iter.hasNext();
  2196. }, t;
  2197. }(), pe = /** @class */ function() {
  2198. function t(t) {
  2199. this.fields = t,
  2200. // TODO(dimond): validation of FieldMask
  2201. // Sort the field mask to support `FieldMask.isEqual()` and assert below.
  2202. t.sort(rt.comparator);
  2203. }
  2204. return t.empty = function() {
  2205. return new t([]);
  2206. },
  2207. /**
  2208. * Returns a new FieldMask object that is the result of adding all the given
  2209. * fields paths to this field mask.
  2210. */
  2211. t.prototype.unionWith = function(e) {
  2212. for (var n = new fe(rt.comparator), r = 0, i = this.fields; r < i.length; r++) {
  2213. var o = i[r];
  2214. n = n.add(o);
  2215. }
  2216. for (var a = 0, u = e; a < u.length; a++) {
  2217. var s = u[a];
  2218. n = n.add(s);
  2219. }
  2220. return new t(n.toArray());
  2221. },
  2222. /**
  2223. * Verifies that `fieldPath` is included by at least one field in this field
  2224. * mask.
  2225. *
  2226. * This is an O(n) operation, where `n` is the size of the field mask.
  2227. */
  2228. t.prototype.covers = function(t) {
  2229. for (var e = 0, n = this.fields; e < n.length; e++) {
  2230. if (n[e].isPrefixOf(t)) return !0;
  2231. }
  2232. return !1;
  2233. }, t.prototype.isEqual = function(t) {
  2234. return bt(this.fields, t.fields, (function(t, e) {
  2235. return t.isEqual(e);
  2236. }));
  2237. }, t;
  2238. }(), de = /** @class */ function() {
  2239. function t(t) {
  2240. this.value = t;
  2241. }
  2242. return t.empty = function() {
  2243. return new t({
  2244. mapValue: {}
  2245. });
  2246. },
  2247. /**
  2248. * Returns the value at the given path or null.
  2249. *
  2250. * @param path - the path to search
  2251. * @returns The value at the path or null if the path is not set.
  2252. */
  2253. t.prototype.field = function(t) {
  2254. if (t.isEmpty()) return this.value;
  2255. for (var e = this.value, n = 0; n < t.length - 1; ++n) if (!Gt(e = (e.mapValue.fields || {})[t.get(n)])) return null;
  2256. return (e = (e.mapValue.fields || {})[t.lastSegment()]) || null;
  2257. },
  2258. /**
  2259. * Sets the field to the provided value.
  2260. *
  2261. * @param path - The field path to set.
  2262. * @param value - The value to set.
  2263. */
  2264. t.prototype.set = function(t, e) {
  2265. this.getFieldsMap(t.popLast())[t.lastSegment()] = Qt(e);
  2266. },
  2267. /**
  2268. * Sets the provided fields to the provided values.
  2269. *
  2270. * @param data - A map of fields to values (or null for deletes).
  2271. */
  2272. t.prototype.setAll = function(t) {
  2273. var e = this, n = rt.emptyPath(), r = {}, i = [];
  2274. t.forEach((function(t, o) {
  2275. if (!n.isImmediateParentOf(o)) {
  2276. // Insert the accumulated changes at this parent location
  2277. var a = e.getFieldsMap(n);
  2278. e.applyChanges(a, r, i), r = {}, i = [], n = o.popLast();
  2279. }
  2280. t ? r[o.lastSegment()] = Qt(t) : i.push(o.lastSegment());
  2281. }));
  2282. var o = this.getFieldsMap(n);
  2283. this.applyChanges(o, r, i);
  2284. },
  2285. /**
  2286. * Removes the field at the specified path. If there is no field at the
  2287. * specified path, nothing is changed.
  2288. *
  2289. * @param path - The field path to remove.
  2290. */
  2291. t.prototype.delete = function(t) {
  2292. var e = this.field(t.popLast());
  2293. Gt(e) && e.mapValue.fields && delete e.mapValue.fields[t.lastSegment()];
  2294. }, t.prototype.isEqual = function(t) {
  2295. return Rt(this.value, t.value);
  2296. },
  2297. /**
  2298. * Returns the map that contains the leaf element of `path`. If the parent
  2299. * entry does not yet exist, or if it is not a map, a new map will be created.
  2300. */
  2301. t.prototype.getFieldsMap = function(t) {
  2302. var e = this.value;
  2303. e.mapValue.fields || (e.mapValue = {
  2304. fields: {}
  2305. });
  2306. for (var n = 0; n < t.length; ++n) {
  2307. var r = e.mapValue.fields[t.get(n)];
  2308. Gt(r) && r.mapValue.fields || (r = {
  2309. mapValue: {
  2310. fields: {}
  2311. }
  2312. }, e.mapValue.fields[t.get(n)] = r), e = r;
  2313. }
  2314. return e.mapValue.fields;
  2315. },
  2316. /**
  2317. * Modifies `fieldsMap` by adding, replacing or deleting the specified
  2318. * entries.
  2319. */
  2320. t.prototype.applyChanges = function(t, e, n) {
  2321. Et(e, (function(e, n) {
  2322. return t[e] = n;
  2323. }));
  2324. for (var r = 0, i = n; r < i.length; r++) {
  2325. var o = i[r];
  2326. delete t[o];
  2327. }
  2328. }, t.prototype.clone = function() {
  2329. return new t(Qt(this.value));
  2330. }, t;
  2331. }(), ye = /** @class */ function() {
  2332. function t(t, e, n, r, i, o, a) {
  2333. this.key = t, this.documentType = e, this.version = n, this.readTime = r, this.createTime = i,
  2334. this.data = o, this.documentState = a
  2335. /**
  2336. * Creates a document with no known version or data, but which can serve as
  2337. * base document for mutations.
  2338. */;
  2339. }
  2340. return t.newInvalidDocument = function(e) {
  2341. return new t(e, 0 /* DocumentType.INVALID */ ,
  2342. /* version */ ue.min(),
  2343. /* readTime */ ue.min(),
  2344. /* createTime */ ue.min(), de.empty(), 0 /* DocumentState.SYNCED */);
  2345. },
  2346. /**
  2347. * Creates a new document that is known to exist with the given data at the
  2348. * given version.
  2349. */
  2350. t.newFoundDocument = function(e, n, r, i) {
  2351. return new t(e, 1 /* DocumentType.FOUND_DOCUMENT */ ,
  2352. /* version */ n,
  2353. /* readTime */ ue.min(),
  2354. /* createTime */ r, i, 0 /* DocumentState.SYNCED */);
  2355. },
  2356. /** Creates a new document that is known to not exist at the given version. */ t.newNoDocument = function(e, n) {
  2357. return new t(e, 2 /* DocumentType.NO_DOCUMENT */ ,
  2358. /* version */ n,
  2359. /* readTime */ ue.min(),
  2360. /* createTime */ ue.min(), de.empty(), 0 /* DocumentState.SYNCED */);
  2361. },
  2362. /**
  2363. * Creates a new document that is known to exist at the given version but
  2364. * whose data is not known (e.g. a document that was updated without a known
  2365. * base document).
  2366. */
  2367. t.newUnknownDocument = function(e, n) {
  2368. return new t(e, 3 /* DocumentType.UNKNOWN_DOCUMENT */ ,
  2369. /* version */ n,
  2370. /* readTime */ ue.min(),
  2371. /* createTime */ ue.min(), de.empty(), 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */);
  2372. },
  2373. /**
  2374. * Changes the document type to indicate that it exists and that its version
  2375. * and data are known.
  2376. */
  2377. t.prototype.convertToFoundDocument = function(t, e) {
  2378. // If a document is switching state from being an invalid or deleted
  2379. // document to a valid (FOUND_DOCUMENT) document, either due to receiving an
  2380. // update from Watch or due to applying a local set mutation on top
  2381. // of a deleted document, our best guess about its createTime would be the
  2382. // version at which the document transitioned to a FOUND_DOCUMENT.
  2383. return !this.createTime.isEqual(ue.min()) || 2 /* DocumentType.NO_DOCUMENT */ !== this.documentType && 0 /* DocumentType.INVALID */ !== this.documentType || (this.createTime = t),
  2384. this.version = t, this.documentType = 1 /* DocumentType.FOUND_DOCUMENT */ , this.data = e,
  2385. this.documentState = 0 /* DocumentState.SYNCED */ , this;
  2386. },
  2387. /**
  2388. * Changes the document type to indicate that it doesn't exist at the given
  2389. * version.
  2390. */
  2391. t.prototype.convertToNoDocument = function(t) {
  2392. return this.version = t, this.documentType = 2 /* DocumentType.NO_DOCUMENT */ ,
  2393. this.data = de.empty(), this.documentState = 0 /* DocumentState.SYNCED */ , this;
  2394. },
  2395. /**
  2396. * Changes the document type to indicate that it exists at a given version but
  2397. * that its data is not known (e.g. a document that was updated without a known
  2398. * base document).
  2399. */
  2400. t.prototype.convertToUnknownDocument = function(t) {
  2401. return this.version = t, this.documentType = 3 /* DocumentType.UNKNOWN_DOCUMENT */ ,
  2402. this.data = de.empty(), this.documentState = 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */ ,
  2403. this;
  2404. }, t.prototype.setHasCommittedMutations = function() {
  2405. return this.documentState = 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */ , this;
  2406. }, t.prototype.setHasLocalMutations = function() {
  2407. return this.documentState = 1 /* DocumentState.HAS_LOCAL_MUTATIONS */ , this.version = ue.min(),
  2408. this;
  2409. }, t.prototype.setReadTime = function(t) {
  2410. return this.readTime = t, this;
  2411. }, Object.defineProperty(t.prototype, "hasLocalMutations", {
  2412. get: function() {
  2413. return 1 /* DocumentState.HAS_LOCAL_MUTATIONS */ === this.documentState;
  2414. },
  2415. enumerable: !1,
  2416. configurable: !0
  2417. }), Object.defineProperty(t.prototype, "hasCommittedMutations", {
  2418. get: function() {
  2419. return 2 /* DocumentState.HAS_COMMITTED_MUTATIONS */ === this.documentState;
  2420. },
  2421. enumerable: !1,
  2422. configurable: !0
  2423. }), Object.defineProperty(t.prototype, "hasPendingWrites", {
  2424. get: function() {
  2425. return this.hasLocalMutations || this.hasCommittedMutations;
  2426. },
  2427. enumerable: !1,
  2428. configurable: !0
  2429. }), t.prototype.isValidDocument = function() {
  2430. return 0 /* DocumentType.INVALID */ !== this.documentType;
  2431. }, t.prototype.isFoundDocument = function() {
  2432. return 1 /* DocumentType.FOUND_DOCUMENT */ === this.documentType;
  2433. }, t.prototype.isNoDocument = function() {
  2434. return 2 /* DocumentType.NO_DOCUMENT */ === this.documentType;
  2435. }, t.prototype.isUnknownDocument = function() {
  2436. return 3 /* DocumentType.UNKNOWN_DOCUMENT */ === this.documentType;
  2437. }, t.prototype.isEqual = function(e) {
  2438. return e instanceof t && this.key.isEqual(e.key) && this.version.isEqual(e.version) && this.documentType === e.documentType && this.documentState === e.documentState && this.data.isEqual(e.data);
  2439. }, t.prototype.mutableCopy = function() {
  2440. return new t(this.key, this.documentType, this.version, this.readTime, this.createTime, this.data.clone(), this.documentState);
  2441. }, t.prototype.toString = function() {
  2442. return "Document(".concat(this.key, ", ").concat(this.version, ", ").concat(JSON.stringify(this.data.value), ", {createTime: ").concat(this.createTime, "}), {documentType: ").concat(this.documentType, "}), {documentState: ").concat(this.documentState, "})");
  2443. }, t;
  2444. }(), me = function(t, e, n, r, i, o, a) {
  2445. void 0 === e && (e = null), void 0 === n && (n = []), void 0 === r && (r = []),
  2446. void 0 === i && (i = null), void 0 === o && (o = null), void 0 === a && (a = null),
  2447. this.path = t, this.collectionGroup = e, this.orderBy = n, this.filters = r, this.limit = i,
  2448. this.startAt = o, this.endAt = a, this.S = null;
  2449. };
  2450. /**
  2451. * Initializes a Target with a path and optional additional query constraints.
  2452. * Path must currently be empty if this is a collection group query.
  2453. *
  2454. * NOTE: you should always construct `Target` from `Query.toTarget` instead of
  2455. * using this factory method, because `Query` provides an implicit `orderBy`
  2456. * property.
  2457. */
  2458. function ve(t, e, n, r, i, o, a) {
  2459. return void 0 === e && (e = null), void 0 === n && (n = []), void 0 === r && (r = []),
  2460. void 0 === i && (i = null), void 0 === o && (o = null), void 0 === a && (a = null),
  2461. new me(t, e, n, r, i, o, a);
  2462. }
  2463. /**
  2464. * @license
  2465. * Copyright 2017 Google LLC
  2466. *
  2467. * Licensed under the Apache License, Version 2.0 (the "License");
  2468. * you may not use this file except in compliance with the License.
  2469. * You may obtain a copy of the License at
  2470. *
  2471. * http://www.apache.org/licenses/LICENSE-2.0
  2472. *
  2473. * Unless required by applicable law or agreed to in writing, software
  2474. * distributed under the License is distributed on an "AS IS" BASIS,
  2475. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2476. * See the License for the specific language governing permissions and
  2477. * limitations under the License.
  2478. */
  2479. /**
  2480. * Query encapsulates all the query attributes we support in the SDK. It can
  2481. * be run against the LocalStore, as well as be converted to a `Target` to
  2482. * query the RemoteStore results.
  2483. *
  2484. * Visible for testing.
  2485. */ var ge =
  2486. /**
  2487. * Initializes a Query with a path and optional additional query constraints.
  2488. * Path must currently be empty if this is a collection group query.
  2489. */
  2490. function(t, e, n, r, i, o /* LimitType.First */ , a, u) {
  2491. void 0 === e && (e = null), void 0 === n && (n = []), void 0 === r && (r = []),
  2492. void 0 === i && (i = null), void 0 === o && (o = "F"), void 0 === a && (a = null),
  2493. void 0 === u && (u = null), this.path = t, this.collectionGroup = e, this.explicitOrderBy = n,
  2494. this.filters = r, this.limit = i, this.limitType = o, this.startAt = a, this.endAt = u,
  2495. this.q = null,
  2496. // The corresponding `Target` of this `Query` instance.
  2497. this.O = null, this.startAt, this.endAt;
  2498. };
  2499. /** Creates a new Query for a query that matches all documents at `path` */ function we(t) {
  2500. return t.explicitOrderBy.length > 0 ? t.explicitOrderBy[0].field : null;
  2501. }
  2502. function _e(t) {
  2503. for (var e = 0, n = t.filters; e < n.length; e++) {
  2504. var r = n[e].getFirstInequalityField();
  2505. if (null !== r) return r;
  2506. }
  2507. return null;
  2508. }
  2509. /**
  2510. * Creates a new Query for a collection group query that matches all documents
  2511. * within the provided collection group.
  2512. */
  2513. /**
  2514. * Returns whether the query matches a collection group rather than a specific
  2515. * collection.
  2516. */ function be(t) {
  2517. return null !== t.collectionGroup;
  2518. }
  2519. /**
  2520. * Returns the implicit order by constraint that is used to execute the Query,
  2521. * which can be different from the order by constraints the user provided (e.g.
  2522. * the SDK and backend always orders by `__name__`).
  2523. */ function Te(t) {
  2524. var e = A(t);
  2525. if (null === e.q) {
  2526. e.q = [];
  2527. var n = _e(e), r = we(e);
  2528. if (null !== n && null === r)
  2529. // In order to implicitly add key ordering, we must also add the
  2530. // inequality filter field for it to be a valid query.
  2531. // Note that the default inequality field and key ordering is ascending.
  2532. n.isKeyField() || e.q.push(new oe(n)), e.q.push(new oe(rt.keyField(), "asc" /* Direction.ASCENDING */)); else {
  2533. for (var i = !1, o = 0, a = e.explicitOrderBy; o < a.length; o++) {
  2534. var u = a[o];
  2535. e.q.push(u), u.field.isKeyField() && (i = !0);
  2536. }
  2537. if (!i) {
  2538. // The order of the implicit key ordering always matches the last
  2539. // explicit order by
  2540. var s = e.explicitOrderBy.length > 0 ? e.explicitOrderBy[e.explicitOrderBy.length - 1].dir : "asc" /* Direction.ASCENDING */;
  2541. e.q.push(new oe(rt.keyField(), s));
  2542. }
  2543. }
  2544. }
  2545. return e.q;
  2546. }
  2547. /**
  2548. * Converts this `Query` instance to it's corresponding `Target` representation.
  2549. */ function Ee(t) {
  2550. var e = A(t);
  2551. if (!e.O) if ("F" /* LimitType.First */ === e.limitType) e.O = ve(e.path, e.collectionGroup, Te(e), e.filters, e.limit, e.startAt, e.endAt); else {
  2552. for (
  2553. // Flip the orderBy directions since we want the last results
  2554. var n = [], r = 0, i = Te(e); r < i.length; r++) {
  2555. var o = i[r], a = "desc" /* Direction.DESCENDING */ === o.dir ? "asc" /* Direction.ASCENDING */ : "desc" /* Direction.DESCENDING */;
  2556. n.push(new oe(o.field, a));
  2557. }
  2558. // We need to swap the cursors to match the now-flipped query ordering.
  2559. var u = e.endAt ? new zt(e.endAt.position, e.endAt.inclusive) : null, s = e.startAt ? new zt(e.startAt.position, e.startAt.inclusive) : null;
  2560. // Now return as a LimitType.First query.
  2561. e.O = ve(e.path, e.collectionGroup, n, e.filters, e.limit, u, s);
  2562. }
  2563. return e.O;
  2564. }
  2565. function ke(t, e) {
  2566. e.getFirstInequalityField(), _e(t);
  2567. var n = t.filters.concat([ e ]);
  2568. return new ge(t.path, t.collectionGroup, t.explicitOrderBy.slice(), n, t.limit, t.limitType, t.startAt, t.endAt);
  2569. }
  2570. /**
  2571. * @license
  2572. * Copyright 2020 Google LLC
  2573. *
  2574. * Licensed under the Apache License, Version 2.0 (the "License");
  2575. * you may not use this file except in compliance with the License.
  2576. * You may obtain a copy of the License at
  2577. *
  2578. * http://www.apache.org/licenses/LICENSE-2.0
  2579. *
  2580. * Unless required by applicable law or agreed to in writing, software
  2581. * distributed under the License is distributed on an "AS IS" BASIS,
  2582. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2583. * See the License for the specific language governing permissions and
  2584. * limitations under the License.
  2585. */
  2586. /**
  2587. * Returns an DoubleValue for `value` that is encoded based the serializer's
  2588. * `useProto3Json` setting.
  2589. */
  2590. /**
  2591. * Returns a value for a number that's appropriate to put into a proto.
  2592. * The return value is an IntegerValue if it can safely represent the value,
  2593. * otherwise a DoubleValue is returned.
  2594. */
  2595. function Se(t, e) {
  2596. return function(t) {
  2597. return "number" == typeof t && Number.isInteger(t) && !ht(t) && t <= Number.MAX_SAFE_INTEGER && t >= Number.MIN_SAFE_INTEGER;
  2598. }(e) ?
  2599. /**
  2600. * Returns an IntegerValue for `value`.
  2601. */
  2602. function(t) {
  2603. return {
  2604. integerValue: "" + t
  2605. };
  2606. }(e) : function(t, e) {
  2607. if (t.k) {
  2608. if (isNaN(e)) return {
  2609. doubleValue: "NaN"
  2610. };
  2611. if (e === 1 / 0) return {
  2612. doubleValue: "Infinity"
  2613. };
  2614. if (e === -1 / 0) return {
  2615. doubleValue: "-Infinity"
  2616. };
  2617. }
  2618. return {
  2619. doubleValue: ht(e) ? "-0" : e
  2620. };
  2621. }(t, e);
  2622. }
  2623. /**
  2624. * @license
  2625. * Copyright 2018 Google LLC
  2626. *
  2627. * Licensed under the Apache License, Version 2.0 (the "License");
  2628. * you may not use this file except in compliance with the License.
  2629. * You may obtain a copy of the License at
  2630. *
  2631. * http://www.apache.org/licenses/LICENSE-2.0
  2632. *
  2633. * Unless required by applicable law or agreed to in writing, software
  2634. * distributed under the License is distributed on an "AS IS" BASIS,
  2635. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2636. * See the License for the specific language governing permissions and
  2637. * limitations under the License.
  2638. */
  2639. /** Used to represent a field transform on a mutation. */ var Ie = function() {
  2640. // Make sure that the structural type of `TransformOperation` is unique.
  2641. // See https://github.com/microsoft/TypeScript/issues/5451
  2642. this._ = void 0;
  2643. }, Ae = /** @class */ function(e) {
  2644. function n() {
  2645. return null !== e && e.apply(this, arguments) || this;
  2646. }
  2647. return t(n, e), n;
  2648. }(Ie), Fe = /** @class */ function(e) {
  2649. function n(t) {
  2650. var n = this;
  2651. return (n = e.call(this) || this).elements = t, n;
  2652. }
  2653. return t(n, e), n;
  2654. }(Ie), Ve = /** @class */ function(e) {
  2655. function n(t) {
  2656. var n = this;
  2657. return (n = e.call(this) || this).elements = t, n;
  2658. }
  2659. return t(n, e), n;
  2660. }(Ie), Pe = /** @class */ function(e) {
  2661. function n(t, n) {
  2662. var r = this;
  2663. return (r = e.call(this) || this).C = t, r.L = n, r;
  2664. }
  2665. return t(n, e), n;
  2666. }(Ie), De = function(t, e) {
  2667. this.field = t, this.transform = e;
  2668. }, Oe = /** @class */ function() {
  2669. function t(t, e) {
  2670. this.updateTime = t, this.exists = e
  2671. /** Creates a new empty Precondition. */;
  2672. }
  2673. return t.none = function() {
  2674. return new t;
  2675. },
  2676. /** Creates a new Precondition with an exists flag. */ t.exists = function(e) {
  2677. return new t(void 0, e);
  2678. },
  2679. /** Creates a new Precondition based on a version a document exists at. */ t.updateTime = function(e) {
  2680. return new t(e);
  2681. }, Object.defineProperty(t.prototype, "isNone", {
  2682. /** Returns whether this Precondition is empty. */ get: function() {
  2683. return void 0 === this.updateTime && void 0 === this.exists;
  2684. },
  2685. enumerable: !1,
  2686. configurable: !0
  2687. }), t.prototype.isEqual = function(t) {
  2688. return this.exists === t.exists && (this.updateTime ? !!t.updateTime && this.updateTime.isEqual(t.updateTime) : !t.updateTime);
  2689. }, t;
  2690. }(), Ne = function() {}, qe = /** @class */ function(e) {
  2691. function n(t, n, r, i) {
  2692. void 0 === i && (i = []);
  2693. var o = this;
  2694. return (o = e.call(this) || this).key = t, o.value = n, o.precondition = r, o.fieldTransforms = i,
  2695. o.type = 0 /* MutationType.Set */ , o;
  2696. }
  2697. return t(n, e), n.prototype.getFieldMask = function() {
  2698. return null;
  2699. }, n;
  2700. }(Ne), Re = /** @class */ function(e) {
  2701. function n(t, n, r, i, o) {
  2702. void 0 === o && (o = []);
  2703. var a = this;
  2704. return (a = e.call(this) || this).key = t, a.data = n, a.fieldMask = r, a.precondition = i,
  2705. a.fieldTransforms = o, a.type = 1 /* MutationType.Patch */ , a;
  2706. }
  2707. return t(n, e), n.prototype.getFieldMask = function() {
  2708. return this.fieldMask;
  2709. }, n;
  2710. }(Ne), Ce = /** @class */ function(e) {
  2711. function n(t, n) {
  2712. var r = this;
  2713. return (r = e.call(this) || this).key = t, r.precondition = n, r.type = 2 /* MutationType.Delete */ ,
  2714. r.fieldTransforms = [], r;
  2715. }
  2716. return t(n, e), n.prototype.getFieldMask = function() {
  2717. return null;
  2718. }, n;
  2719. }(Ne), xe = /** @class */ function(e) {
  2720. function n(t, n) {
  2721. var r = this;
  2722. return (r = e.call(this) || this).key = t, r.precondition = n, r.type = 3 /* MutationType.Verify */ ,
  2723. r.fieldTransforms = [], r;
  2724. }
  2725. return t(n, e), n.prototype.getFieldMask = function() {
  2726. return null;
  2727. }, n;
  2728. }(Ne), Le = {
  2729. asc: "ASCENDING",
  2730. desc: "DESCENDING"
  2731. }, je = {
  2732. "<": "LESS_THAN",
  2733. "<=": "LESS_THAN_OR_EQUAL",
  2734. ">": "GREATER_THAN",
  2735. ">=": "GREATER_THAN_OR_EQUAL",
  2736. "==": "EQUAL",
  2737. "!=": "NOT_EQUAL",
  2738. "array-contains": "ARRAY_CONTAINS",
  2739. in: "IN",
  2740. "not-in": "NOT_IN",
  2741. "array-contains-any": "ARRAY_CONTAINS_ANY"
  2742. }, Me = {
  2743. and: "AND",
  2744. or: "OR"
  2745. }, Ue = function(t, e) {
  2746. this.databaseId = t, this.k = e;
  2747. };
  2748. /** Transforms a value into a server-generated timestamp. */
  2749. /**
  2750. * Returns a value for a number (or null) that's appropriate to put into
  2751. * a google.protobuf.Int32Value proto.
  2752. * DO NOT USE THIS FOR ANYTHING ELSE.
  2753. * This method cheats. It's typed as returning "number" because that's what
  2754. * our generated proto interfaces say Int32Value must be. But GRPC actually
  2755. * expects a { value: <number> } struct.
  2756. */
  2757. /**
  2758. * Returns a value for a Date that's appropriate to put into a proto.
  2759. */
  2760. function Be(t, e) {
  2761. return t.k ? "".concat(new Date(1e3 * e.seconds).toISOString().replace(/\.\d*/, "").replace("Z", ""), ".").concat(("000000000" + e.nanoseconds).slice(-9), "Z") : {
  2762. seconds: "" + e.seconds,
  2763. nanos: e.nanoseconds
  2764. };
  2765. }
  2766. /**
  2767. * Returns a value for bytes that's appropriate to put in a proto.
  2768. *
  2769. * Visible for testing.
  2770. */ function Ge(t, e) {
  2771. return t.k ? e.toBase64() : e.toUint8Array();
  2772. }
  2773. function Qe(t, e) {
  2774. return Be(t, e.toTimestamp());
  2775. }
  2776. function ze(t) {
  2777. return I(!!t), ue.fromTimestamp(function(t) {
  2778. var e = It(t);
  2779. return new Vt(e.seconds, e.nanos);
  2780. }(t));
  2781. }
  2782. function Ke(t, e) {
  2783. return function(t) {
  2784. return new et([ "projects", t.projectId, "databases", t.database ]);
  2785. }(t).child("documents").child(e).canonicalString();
  2786. }
  2787. function We(t, e) {
  2788. return Ke(t.databaseId, e.path);
  2789. }
  2790. function He(t, e) {
  2791. var n, r = function(t) {
  2792. var e = et.fromString(t);
  2793. return I(an(e)), e;
  2794. }(e);
  2795. if (r.get(1) !== t.databaseId.projectId) throw new B(P, "Tried to deserialize key from different project: " + r.get(1) + " vs " + t.databaseId.projectId);
  2796. if (r.get(3) !== t.databaseId.database) throw new B(P, "Tried to deserialize key from different database: " + r.get(3) + " vs " + t.databaseId.database);
  2797. return new it((I((n = r).length > 4 && "documents" === n.get(4)), n.popFirst(5)));
  2798. }
  2799. function Ye(t, e) {
  2800. return Ke(t.databaseId, e);
  2801. }
  2802. function Xe(t) {
  2803. return new et([ "projects", t.databaseId.projectId, "databases", t.databaseId.database ]).canonicalString();
  2804. }
  2805. function Je(t, e, n) {
  2806. return {
  2807. name: We(t, e),
  2808. fields: n.value.mapValue.fields
  2809. };
  2810. }
  2811. function Ze(t, e) {
  2812. // Dissect the path into parent, collectionId, and optional key filter.
  2813. var n = {
  2814. structuredQuery: {}
  2815. }, r = e.path;
  2816. null !== e.collectionGroup ? (n.parent = Ye(t, r), n.structuredQuery.from = [ {
  2817. collectionId: e.collectionGroup,
  2818. allDescendants: !0
  2819. } ]) : (n.parent = Ye(t, r.popLast()), n.structuredQuery.from = [ {
  2820. collectionId: r.lastSegment()
  2821. } ]);
  2822. var i = function(t) {
  2823. if (0 !== t.length) return rn(Yt.create(t, "and" /* CompositeOperator.AND */));
  2824. }(e.filters);
  2825. i && (n.structuredQuery.where = i);
  2826. var o = function(t) {
  2827. if (0 !== t.length) return t.map((function(t) {
  2828. // visible for testing
  2829. return function(t) {
  2830. return {
  2831. field: nn(t.field),
  2832. direction: $e(t.dir)
  2833. };
  2834. }(t);
  2835. }));
  2836. }(e.orderBy);
  2837. o && (n.structuredQuery.orderBy = o);
  2838. var a, u = function(t, e) {
  2839. return t.k || ft(e) ? e : {
  2840. value: e
  2841. };
  2842. }(t, e.limit);
  2843. return null !== u && (n.structuredQuery.limit = u), e.startAt && (n.structuredQuery.startAt = {
  2844. before: (a = e.startAt).inclusive,
  2845. values: a.position
  2846. }), e.endAt && (n.structuredQuery.endAt = function(t) {
  2847. return {
  2848. before: !t.inclusive,
  2849. values: t.position
  2850. };
  2851. }(e.endAt)), n;
  2852. }
  2853. function $e(t) {
  2854. return Le[t];
  2855. }
  2856. // visible for testing
  2857. function tn(t) {
  2858. return je[t];
  2859. }
  2860. function en(t) {
  2861. return Me[t];
  2862. }
  2863. function nn(t) {
  2864. return {
  2865. fieldPath: t.canonicalString()
  2866. };
  2867. }
  2868. function rn(t) {
  2869. return t instanceof Ht ? function(t) {
  2870. if ("==" /* Operator.EQUAL */ === t.op) {
  2871. if (Bt(t.value)) return {
  2872. unaryFilter: {
  2873. field: nn(t.field),
  2874. op: "IS_NAN"
  2875. }
  2876. };
  2877. if (Ut(t.value)) return {
  2878. unaryFilter: {
  2879. field: nn(t.field),
  2880. op: "IS_NULL"
  2881. }
  2882. };
  2883. } else if ("!=" /* Operator.NOT_EQUAL */ === t.op) {
  2884. if (Bt(t.value)) return {
  2885. unaryFilter: {
  2886. field: nn(t.field),
  2887. op: "IS_NOT_NAN"
  2888. }
  2889. };
  2890. if (Ut(t.value)) return {
  2891. unaryFilter: {
  2892. field: nn(t.field),
  2893. op: "IS_NOT_NULL"
  2894. }
  2895. };
  2896. }
  2897. return {
  2898. fieldFilter: {
  2899. field: nn(t.field),
  2900. op: tn(t.op),
  2901. value: t.value
  2902. }
  2903. };
  2904. }(t) : t instanceof Yt ? function(t) {
  2905. var e = t.getFilters().map((function(t) {
  2906. return rn(t);
  2907. }));
  2908. return 1 === e.length ? e[0] : {
  2909. compositeFilter: {
  2910. op: en(t.op),
  2911. filters: e
  2912. }
  2913. };
  2914. }(t) : S();
  2915. }
  2916. function on(t) {
  2917. var e = [];
  2918. return t.fields.forEach((function(t) {
  2919. return e.push(t.canonicalString());
  2920. })), {
  2921. fieldPaths: e
  2922. };
  2923. }
  2924. function an(t) {
  2925. // Resource names have at least 4 components (project ID, database ID)
  2926. return t.length >= 4 && "projects" === t.get(0) && "databases" === t.get(2);
  2927. }
  2928. /**
  2929. * @license
  2930. * Copyright 2020 Google LLC
  2931. *
  2932. * Licensed under the Apache License, Version 2.0 (the "License");
  2933. * you may not use this file except in compliance with the License.
  2934. * You may obtain a copy of the License at
  2935. *
  2936. * http://www.apache.org/licenses/LICENSE-2.0
  2937. *
  2938. * Unless required by applicable law or agreed to in writing, software
  2939. * distributed under the License is distributed on an "AS IS" BASIS,
  2940. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2941. * See the License for the specific language governing permissions and
  2942. * limitations under the License.
  2943. */ function un(t) {
  2944. return new Ue(t, /* useProto3Json= */ !0);
  2945. }
  2946. /**
  2947. * @license
  2948. * Copyright 2017 Google LLC
  2949. *
  2950. * Licensed under the Apache License, Version 2.0 (the "License");
  2951. * you may not use this file except in compliance with the License.
  2952. * You may obtain a copy of the License at
  2953. *
  2954. * http://www.apache.org/licenses/LICENSE-2.0
  2955. *
  2956. * Unless required by applicable law or agreed to in writing, software
  2957. * distributed under the License is distributed on an "AS IS" BASIS,
  2958. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  2959. * See the License for the specific language governing permissions and
  2960. * limitations under the License.
  2961. */
  2962. /**
  2963. * A helper for running delayed tasks following an exponential backoff curve
  2964. * between attempts.
  2965. *
  2966. * Each delay is made up of a "base" delay which follows the exponential
  2967. * backoff curve, and a +/- 50% "jitter" that is calculated and added to the
  2968. * base delay. This prevents clients from accidentally synchronizing their
  2969. * delays causing spikes of load to the backend.
  2970. */ var sn = /** @class */ function() {
  2971. function t(
  2972. /**
  2973. * The AsyncQueue to run backoff operations on.
  2974. */
  2975. t,
  2976. /**
  2977. * The ID to use when scheduling backoff operations on the AsyncQueue.
  2978. */
  2979. e,
  2980. /**
  2981. * The initial delay (used as the base delay on the first retry attempt).
  2982. * Note that jitter will still be applied, so the actual delay could be as
  2983. * little as 0.5*initialDelayMs.
  2984. */
  2985. n
  2986. /**
  2987. * The multiplier to use to determine the extended base delay after each
  2988. * attempt.
  2989. */ , r
  2990. /**
  2991. * The maximum base delay after which no further backoff is performed.
  2992. * Note that jitter will still be applied, so the actual delay could be as
  2993. * much as 1.5*maxDelayMs.
  2994. */ , i) {
  2995. void 0 === n && (n = 1e3), void 0 === r && (r = 1.5), void 0 === i && (i = 6e4),
  2996. this.M = t, this.timerId = e, this.U = n, this.j = r, this.B = i, this.W = 0, this.G = null,
  2997. /** The last backoff attempt, as epoch milliseconds. */
  2998. this.K = Date.now(), this.reset();
  2999. }
  3000. /**
  3001. * Resets the backoff delay.
  3002. *
  3003. * The very next backoffAndWait() will have no delay. If it is called again
  3004. * (i.e. due to an error), initialDelayMs (plus jitter) will be used, and
  3005. * subsequent ones will increase according to the backoffFactor.
  3006. */ return t.prototype.reset = function() {
  3007. this.W = 0;
  3008. },
  3009. /**
  3010. * Resets the backoff delay to the maximum delay (e.g. for use after a
  3011. * RESOURCE_EXHAUSTED error).
  3012. */
  3013. t.prototype.Y = function() {
  3014. this.W = this.B;
  3015. },
  3016. /**
  3017. * Returns a promise that resolves after currentDelayMs, and increases the
  3018. * delay for any subsequent attempts. If there was a pending backoff operation
  3019. * already, it will be canceled.
  3020. */
  3021. t.prototype.H = function(t) {
  3022. var e = this;
  3023. // Cancel any pending backoff operation.
  3024. this.cancel();
  3025. // First schedule using the current base (which may be 0 and should be
  3026. // honored as such).
  3027. var n = Math.floor(this.W + this.J()), r = Math.max(0, Date.now() - this.K), i = Math.max(0, n - r);
  3028. // Guard against lastAttemptTime being in the future due to a clock change.
  3029. i > 0 && b("ExponentialBackoff", "Backing off for ".concat(i, " ms (base delay: ").concat(this.W, " ms, delay with jitter: ").concat(n, " ms, last attempt: ").concat(r, " ms ago)")),
  3030. this.G = this.M.enqueueAfterDelay(this.timerId, i, (function() {
  3031. return e.K = Date.now(), t();
  3032. })),
  3033. // Apply backoff factor to determine next delay and ensure it is within
  3034. // bounds.
  3035. this.W *= this.j, this.W < this.U && (this.W = this.U), this.W > this.B && (this.W = this.B);
  3036. }, t.prototype.X = function() {
  3037. null !== this.G && (this.G.skipDelay(), this.G = null);
  3038. }, t.prototype.cancel = function() {
  3039. null !== this.G && (this.G.cancel(), this.G = null);
  3040. },
  3041. /** Returns a random value in the range [-currentBaseMs/2, currentBaseMs/2] */ t.prototype.J = function() {
  3042. return (Math.random() - .5) * this.W;
  3043. }, t;
  3044. }(), cn = /** @class */ function(e) {
  3045. function n(t, n, r, i) {
  3046. var o = this;
  3047. return (o = e.call(this) || this).authCredentials = t, o.appCheckCredentials = n,
  3048. o.connection = r, o.C = i, o.Z = !1, o;
  3049. }
  3050. return t(n, e), n.prototype.tt = function() {
  3051. if (this.Z) throw new B(C, "The client has already been terminated.");
  3052. },
  3053. /** Invokes the provided RPC with auth and AppCheck tokens. */ n.prototype.I = function(t, e, n) {
  3054. var r = this;
  3055. return this.tt(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((function(i) {
  3056. var o = i[0], a = i[1];
  3057. return r.connection.I(t, e, n, o, a);
  3058. })).catch((function(t) {
  3059. throw "FirebaseError" === t.name ? (t.code === q && (r.authCredentials.invalidateToken(),
  3060. r.appCheckCredentials.invalidateToken()), t) : new B(V, t.toString());
  3061. }));
  3062. },
  3063. /** Invokes the provided RPC with streamed results with auth and AppCheck tokens. */ n.prototype.P = function(t, e, n, r) {
  3064. var i = this;
  3065. return this.tt(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((function(o) {
  3066. var a = o[0], u = o[1];
  3067. return i.connection.P(t, e, n, a, u, r);
  3068. })).catch((function(t) {
  3069. throw "FirebaseError" === t.name ? (t.code === q && (i.authCredentials.invalidateToken(),
  3070. i.appCheckCredentials.invalidateToken()), t) : new B(V, t.toString());
  3071. }));
  3072. }, n.prototype.terminate = function() {
  3073. this.Z = !0;
  3074. }, n;
  3075. }((function() {}));
  3076. /**
  3077. * @license
  3078. * Copyright 2017 Google LLC
  3079. *
  3080. * Licensed under the Apache License, Version 2.0 (the "License");
  3081. * you may not use this file except in compliance with the License.
  3082. * You may obtain a copy of the License at
  3083. *
  3084. * http://www.apache.org/licenses/LICENSE-2.0
  3085. *
  3086. * Unless required by applicable law or agreed to in writing, software
  3087. * distributed under the License is distributed on an "AS IS" BASIS,
  3088. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3089. * See the License for the specific language governing permissions and
  3090. * limitations under the License.
  3091. */
  3092. /**
  3093. * Datastore and its related methods are a wrapper around the external Google
  3094. * Cloud Datastore grpc API, which provides an interface that is more convenient
  3095. * for the rest of the client SDK architecture to consume.
  3096. */
  3097. /**
  3098. * An implementation of Datastore that exposes additional state for internal
  3099. * consumption.
  3100. */
  3101. // TODO(firestorexp): Make sure there is only one Datastore instance per
  3102. // firestore-exp client.
  3103. function ln(t, r) {
  3104. return e(this, void 0, void 0, (function() {
  3105. var e, i, o;
  3106. return n(this, (function(n) {
  3107. switch (n.label) {
  3108. case 0:
  3109. return e = A(t), i = Xe(e.C) + "/documents", o = {
  3110. writes: r.map((function(t) {
  3111. return function(t, e) {
  3112. var n;
  3113. if (e instanceof qe) n = {
  3114. update: Je(t, e.key, e.value)
  3115. }; else if (e instanceof Ce) n = {
  3116. delete: We(t, e.key)
  3117. }; else if (e instanceof Re) n = {
  3118. update: Je(t, e.key, e.data),
  3119. updateMask: on(e.fieldMask)
  3120. }; else {
  3121. if (!(e instanceof xe)) return S();
  3122. n = {
  3123. verify: We(t, e.key)
  3124. };
  3125. }
  3126. return e.fieldTransforms.length > 0 && (n.updateTransforms = e.fieldTransforms.map((function(t) {
  3127. return function(t, e) {
  3128. var n = e.transform;
  3129. if (n instanceof Ae) return {
  3130. fieldPath: e.field.canonicalString(),
  3131. setToServerValue: "REQUEST_TIME"
  3132. };
  3133. if (n instanceof Fe) return {
  3134. fieldPath: e.field.canonicalString(),
  3135. appendMissingElements: {
  3136. values: n.elements
  3137. }
  3138. };
  3139. if (n instanceof Ve) return {
  3140. fieldPath: e.field.canonicalString(),
  3141. removeAllFromArray: {
  3142. values: n.elements
  3143. }
  3144. };
  3145. if (n instanceof Pe) return {
  3146. fieldPath: e.field.canonicalString(),
  3147. increment: n.L
  3148. };
  3149. throw S();
  3150. }(0, t);
  3151. }))), e.precondition.isNone || (n.currentDocument = function(t, e) {
  3152. return void 0 !== e.updateTime ? {
  3153. updateTime: Qe(t, e.updateTime)
  3154. } : void 0 !== e.exists ? {
  3155. exists: e.exists
  3156. } : S();
  3157. }(t, e.precondition)), n;
  3158. }(e.C, t);
  3159. }))
  3160. }, [ 4 /*yield*/ , e.I("Commit", i, o) ];
  3161. case 1:
  3162. return n.sent(), [ 2 /*return*/ ];
  3163. }
  3164. }));
  3165. }));
  3166. }
  3167. function fn(t, r) {
  3168. return e(this, void 0, void 0, (function() {
  3169. var e, i, o, a, u, s;
  3170. return n(this, (function(n) {
  3171. switch (n.label) {
  3172. case 0:
  3173. return e = A(t), i = Xe(e.C) + "/documents", o = {
  3174. documents: r.map((function(t) {
  3175. return We(e.C, t);
  3176. }))
  3177. }, [ 4 /*yield*/ , e.P("BatchGetDocuments", i, o, r.length) ];
  3178. case 1:
  3179. return a = n.sent(), u = new Map, a.forEach((function(t) {
  3180. var n = function(t, e) {
  3181. return "found" in e ? function(t, e) {
  3182. I(!!e.found), e.found.name, e.found.updateTime;
  3183. var n = He(t, e.found.name), r = ze(e.found.updateTime), i = e.found.createTime ? ze(e.found.createTime) : ue.min(), o = new de({
  3184. mapValue: {
  3185. fields: e.found.fields
  3186. }
  3187. });
  3188. return ye.newFoundDocument(n, r, i, o);
  3189. }(t, e) : "missing" in e ? function(t, e) {
  3190. I(!!e.missing), I(!!e.readTime);
  3191. var n = He(t, e.missing), r = ze(e.readTime);
  3192. return ye.newNoDocument(n, r);
  3193. }(t, e) : S();
  3194. }(e.C, t);
  3195. u.set(n.key.toString(), n);
  3196. })), s = [], [ 2 /*return*/ , (r.forEach((function(t) {
  3197. var e = u.get(t.toString());
  3198. I(!!e), s.push(e);
  3199. })), s) ];
  3200. }
  3201. }));
  3202. }));
  3203. }
  3204. /**
  3205. * @license
  3206. * Copyright 2020 Google LLC
  3207. *
  3208. * Licensed under the Apache License, Version 2.0 (the "License");
  3209. * you may not use this file except in compliance with the License.
  3210. * You may obtain a copy of the License at
  3211. *
  3212. * http://www.apache.org/licenses/LICENSE-2.0
  3213. *
  3214. * Unless required by applicable law or agreed to in writing, software
  3215. * distributed under the License is distributed on an "AS IS" BASIS,
  3216. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3217. * See the License for the specific language governing permissions and
  3218. * limitations under the License.
  3219. */
  3220. var hn = new Map;
  3221. /**
  3222. * An instance map that ensures only one Datastore exists per Firestore
  3223. * instance.
  3224. */
  3225. /**
  3226. * Returns an initialized and started Datastore for the given Firestore
  3227. * instance. Callers must invoke removeComponents() when the Firestore
  3228. * instance is terminated.
  3229. */ function pn(t) {
  3230. if (t._terminated) throw new B(C, "The client has already been terminated.");
  3231. if (!hn.has(t)) {
  3232. b("ComponentProvider", "Initializing Datastore");
  3233. var e = function(t) {
  3234. return new vt(t, fetch.bind(null));
  3235. }((i = t._databaseId, o = t.app.options.appId || "", a = t._persistenceKey, u = t._freezeSettings(),
  3236. new Z(i, o, a, u.host, u.ssl, u.experimentalForceLongPolling, u.experimentalAutoDetectLongPolling, u.useFetchStreams))), n = un(t._databaseId), r = function(t, e, n, r) {
  3237. return new cn(t, e, n, r);
  3238. }(t._authCredentials, t._appCheckCredentials, e, n);
  3239. hn.set(t, r);
  3240. }
  3241. var i, o, a, u;
  3242. /**
  3243. * @license
  3244. * Copyright 2018 Google LLC
  3245. *
  3246. * Licensed under the Apache License, Version 2.0 (the "License");
  3247. * you may not use this file except in compliance with the License.
  3248. * You may obtain a copy of the License at
  3249. *
  3250. * http://www.apache.org/licenses/LICENSE-2.0
  3251. *
  3252. * Unless required by applicable law or agreed to in writing, software
  3253. * distributed under the License is distributed on an "AS IS" BASIS,
  3254. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3255. * See the License for the specific language governing permissions and
  3256. * limitations under the License.
  3257. */ return hn.get(t);
  3258. }
  3259. /**
  3260. * Removes all components associated with the provided instance. Must be called
  3261. * when the `Firestore` instance is terminated.
  3262. */
  3263. /**
  3264. * A concrete type describing all the values that can be applied via a
  3265. * user-supplied `FirestoreSettings` object. This is a separate type so that
  3266. * defaults can be supplied and the value can be checked for equality.
  3267. */ var dn = /** @class */ function() {
  3268. function t(t) {
  3269. var e;
  3270. if (void 0 === t.host) {
  3271. if (void 0 !== t.ssl) throw new B(P, "Can't provide ssl option if host option is not set");
  3272. this.host = "firestore.googleapis.com", this.ssl = !0;
  3273. } else this.host = t.host, this.ssl = null === (e = t.ssl) || void 0 === e || e;
  3274. if (this.credentials = t.credentials, this.ignoreUndefinedProperties = !!t.ignoreUndefinedProperties,
  3275. void 0 === t.cacheSizeBytes) this.cacheSizeBytes = 41943040; else {
  3276. if (-1 !== t.cacheSizeBytes && t.cacheSizeBytes < 1048576) throw new B(P, "cacheSizeBytes must be at least 1048576");
  3277. this.cacheSizeBytes = t.cacheSizeBytes;
  3278. }
  3279. this.experimentalForceLongPolling = !!t.experimentalForceLongPolling, this.experimentalAutoDetectLongPolling = !!t.experimentalAutoDetectLongPolling,
  3280. this.useFetchStreams = !!t.useFetchStreams, function(t, e, n, r) {
  3281. if (!0 === e && !0 === r) throw new B(P, "".concat("experimentalForceLongPolling", " and ").concat("experimentalAutoDetectLongPolling", " cannot be used together."));
  3282. }(0, t.experimentalForceLongPolling, 0, t.experimentalAutoDetectLongPolling);
  3283. }
  3284. return t.prototype.isEqual = function(t) {
  3285. return this.host === t.host && this.ssl === t.ssl && this.credentials === t.credentials && this.cacheSizeBytes === t.cacheSizeBytes && this.experimentalForceLongPolling === t.experimentalForceLongPolling && this.experimentalAutoDetectLongPolling === t.experimentalAutoDetectLongPolling && this.ignoreUndefinedProperties === t.ignoreUndefinedProperties && this.useFetchStreams === t.useFetchStreams;
  3286. }, t;
  3287. }(), yn = /** @class */ function() {
  3288. /** @hideconstructor */
  3289. function t(t, e, n, r) {
  3290. this._authCredentials = t, this._appCheckCredentials = e, this._databaseId = n,
  3291. this._app = r,
  3292. /**
  3293. * Whether it's a Firestore or Firestore Lite instance.
  3294. */
  3295. this.type = "firestore-lite", this._persistenceKey = "(lite)", this._settings = new dn({}),
  3296. this._settingsFrozen = !1;
  3297. }
  3298. return Object.defineProperty(t.prototype, "app", {
  3299. /**
  3300. * The {@link @firebase/app#FirebaseApp} associated with this `Firestore` service
  3301. * instance.
  3302. */
  3303. get: function() {
  3304. if (!this._app) throw new B(C, "Firestore was not initialized using the Firebase SDK. 'app' is not available");
  3305. return this._app;
  3306. },
  3307. enumerable: !1,
  3308. configurable: !0
  3309. }), Object.defineProperty(t.prototype, "_initialized", {
  3310. get: function() {
  3311. return this._settingsFrozen;
  3312. },
  3313. enumerable: !1,
  3314. configurable: !0
  3315. }), Object.defineProperty(t.prototype, "_terminated", {
  3316. get: function() {
  3317. return void 0 !== this._terminateTask;
  3318. },
  3319. enumerable: !1,
  3320. configurable: !0
  3321. }), t.prototype._setSettings = function(t) {
  3322. if (this._settingsFrozen) throw new B(C, "Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");
  3323. this._settings = new dn(t), void 0 !== t.credentials && (this._authCredentials = function(t) {
  3324. if (!t) return new z;
  3325. switch (t.type) {
  3326. case "gapi":
  3327. var e = t.client;
  3328. return new Y(e, t.sessionIndex || "0", t.iamToken || null, t.authTokenFactory || null);
  3329. case "provider":
  3330. return t.client;
  3331. default:
  3332. throw new B(P, "makeAuthCredentialsProvider failed due to invalid credential type");
  3333. }
  3334. }(t.credentials));
  3335. }, t.prototype._getSettings = function() {
  3336. return this._settings;
  3337. }, t.prototype._freezeSettings = function() {
  3338. return this._settingsFrozen = !0, this._settings;
  3339. }, t.prototype._delete = function() {
  3340. return this._terminateTask || (this._terminateTask = this._terminate()), this._terminateTask;
  3341. },
  3342. /** Returns a JSON-serializable representation of this `Firestore` instance. */ t.prototype.toJSON = function() {
  3343. return {
  3344. app: this._app,
  3345. databaseId: this._databaseId,
  3346. settings: this._settings
  3347. };
  3348. },
  3349. /**
  3350. * Terminates all components used by this client. Subclasses can override
  3351. * this method to clean up their own dependencies, but must also call this
  3352. * method.
  3353. *
  3354. * Only ever called once.
  3355. */
  3356. t.prototype._terminate = function() {
  3357. return t = this, (e = hn.get(t)) && (b("ComponentProvider", "Removing Datastore"),
  3358. hn.delete(t), e.terminate()), Promise.resolve();
  3359. var t, e;
  3360. }, t;
  3361. }();
  3362. /**
  3363. * @license
  3364. * Copyright 2020 Google LLC
  3365. *
  3366. * Licensed under the Apache License, Version 2.0 (the "License");
  3367. * you may not use this file except in compliance with the License.
  3368. * You may obtain a copy of the License at
  3369. *
  3370. * http://www.apache.org/licenses/LICENSE-2.0
  3371. *
  3372. * Unless required by applicable law or agreed to in writing, software
  3373. * distributed under the License is distributed on an "AS IS" BASIS,
  3374. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3375. * See the License for the specific language governing permissions and
  3376. * limitations under the License.
  3377. */
  3378. /**
  3379. * The Cloud Firestore service interface.
  3380. *
  3381. * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
  3382. */ function mn(t, e, n) {
  3383. n || (n = "(default)");
  3384. var r = _getProvider(t, "firestore/lite");
  3385. if (r.isInitialized(n)) throw new B(C, "Firestore can only be initialized once per app.");
  3386. return r.initialize({
  3387. options: e,
  3388. instanceIdentifier: n
  3389. });
  3390. }
  3391. function vn(t, e) {
  3392. var n = "object" == typeof t ? t : u(), i = "string" == typeof t ? t : e || "(default)", o = _getProvider(n, "firestore/lite").getImmediate({
  3393. identifier: i
  3394. });
  3395. if (!o._initialized) {
  3396. var a = d("firestore");
  3397. a && gn.apply(void 0, r([ o ], a, !1));
  3398. }
  3399. return o;
  3400. }
  3401. /**
  3402. * Modify this instance to communicate with the Cloud Firestore emulator.
  3403. *
  3404. * Note: This must be called before this instance has been used to do any
  3405. * operations.
  3406. *
  3407. * @param firestore - The `Firestore` instance to configure to connect to the
  3408. * emulator.
  3409. * @param host - the emulator host (ex: localhost).
  3410. * @param port - the emulator port (ex: 9000).
  3411. * @param options.mockUserToken - the mock auth token to use for unit testing
  3412. * Security Rules.
  3413. */ function gn(t, e, n, r) {
  3414. var i;
  3415. void 0 === r && (r = {});
  3416. var o = (t = ct(t, yn))._getSettings();
  3417. if ("firestore.googleapis.com" !== o.host && o.host !== e && E("Host has been set in both settings() and useEmulator(), emulator host will be used"),
  3418. t._setSettings(Object.assign(Object.assign({}, o), {
  3419. host: "".concat(e, ":").concat(n),
  3420. ssl: !1
  3421. })), r.mockUserToken) {
  3422. var a, u;
  3423. if ("string" == typeof r.mockUserToken) a = r.mockUserToken, u = v.MOCK_USER; else {
  3424. // Let createMockUserToken validate first (catches common mistakes like
  3425. // invalid field "uid" and missing field "sub" / "user_id".)
  3426. a = y(r.mockUserToken, null === (i = t._app) || void 0 === i ? void 0 : i.options.projectId);
  3427. var s = r.mockUserToken.sub || r.mockUserToken.user_id;
  3428. if (!s) throw new B(P, "mockUserToken must contain 'sub' or 'user_id' field!");
  3429. u = new v(s);
  3430. }
  3431. t._authCredentials = new K(new Q(a, u));
  3432. }
  3433. }
  3434. /**
  3435. * Terminates the provided `Firestore` instance.
  3436. *
  3437. * After calling `terminate()` only the `clearIndexedDbPersistence()` functions
  3438. * may be used. Any other function will throw a `FirestoreError`. Termination
  3439. * does not cancel any pending writes, and any promises that are awaiting a
  3440. * response from the server will not be resolved.
  3441. *
  3442. * To restart after termination, create a new instance of `Firestore` with
  3443. * {@link (getFirestore:1)}.
  3444. *
  3445. * Note: Under normal circumstances, calling `terminate()` is not required. This
  3446. * function is useful only when you want to force this instance to release all of
  3447. * its resources or in combination with {@link clearIndexedDbPersistence} to
  3448. * ensure that all local state is destroyed between test runs.
  3449. *
  3450. * @param firestore - The `Firestore` instance to terminate.
  3451. * @returns A `Promise` that is resolved when the instance has been successfully
  3452. * terminated.
  3453. */ function wn(t) {
  3454. return t = ct(t, yn), s(t.app, "firestore/lite"), t._delete();
  3455. }
  3456. /**
  3457. * @license
  3458. * Copyright 2020 Google LLC
  3459. *
  3460. * Licensed under the Apache License, Version 2.0 (the "License");
  3461. * you may not use this file except in compliance with the License.
  3462. * You may obtain a copy of the License at
  3463. *
  3464. * http://www.apache.org/licenses/LICENSE-2.0
  3465. *
  3466. * Unless required by applicable law or agreed to in writing, software
  3467. * distributed under the License is distributed on an "AS IS" BASIS,
  3468. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3469. * See the License for the specific language governing permissions and
  3470. * limitations under the License.
  3471. */
  3472. /**
  3473. * @license
  3474. * Copyright 2022 Google LLC
  3475. *
  3476. * Licensed under the Apache License, Version 2.0 (the "License");
  3477. * you may not use this file except in compliance with the License.
  3478. * You may obtain a copy of the License at
  3479. *
  3480. * http://www.apache.org/licenses/LICENSE-2.0
  3481. *
  3482. * Unless required by applicable law or agreed to in writing, software
  3483. * distributed under the License is distributed on an "AS IS" BASIS,
  3484. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3485. * See the License for the specific language governing permissions and
  3486. * limitations under the License.
  3487. */
  3488. /**
  3489. * Represents an aggregation that can be performed by Firestore.
  3490. */
  3491. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  3492. var _n = function() {
  3493. /** A type string to uniquely identify instances of this class. */
  3494. this.type = "AggregateField";
  3495. }, bn = /** @class */ function() {
  3496. /** @hideconstructor */
  3497. function t(t, e) {
  3498. this._data = e,
  3499. /** A type string to uniquely identify instances of this class. */
  3500. this.type = "AggregateQuerySnapshot", this.query = t
  3501. /**
  3502. * Returns the results of the aggregations performed over the underlying
  3503. * query.
  3504. *
  3505. * The keys of the returned object will be the same as those of the
  3506. * `AggregateSpec` object specified to the aggregation method, and the values
  3507. * will be the corresponding aggregation result.
  3508. *
  3509. * @returns The results of the aggregations performed over the underlying
  3510. * query.
  3511. */;
  3512. }
  3513. return t.prototype.data = function() {
  3514. return this._data;
  3515. }, t;
  3516. }(), Tn = /** @class */ function() {
  3517. function t(t, e, n) {
  3518. this.query = t, this.datastore = e, this.userDataWriter = n;
  3519. }
  3520. return t.prototype.run = function() {
  3521. var t = this;
  3522. return function(t, r) {
  3523. return e(this, void 0, void 0, (function() {
  3524. var e, i, o;
  3525. return n(this, (function(n) {
  3526. switch (n.label) {
  3527. case 0:
  3528. return e = A(t), i = function(t, e) {
  3529. var n = Ze(t, e);
  3530. return {
  3531. structuredAggregationQuery: {
  3532. aggregations: [ {
  3533. count: {},
  3534. alias: "count_alias"
  3535. } ],
  3536. structuredQuery: n.structuredQuery
  3537. },
  3538. parent: n.parent
  3539. };
  3540. }(e.C, Ee(r)), o = i.parent, e.connection.v || delete i.parent, [ 4 /*yield*/ , e.P("RunAggregationQuery", o, i, /*expectedResponseCount=*/ 1) ];
  3541. case 1:
  3542. return [ 2 /*return*/ , n.sent().filter((function(t) {
  3543. return !!t.result;
  3544. })).map((function(t) {
  3545. return t.result.aggregateFields;
  3546. })) ];
  3547. }
  3548. }));
  3549. }));
  3550. }(this.datastore, this.query._query).then((function(e) {
  3551. I(void 0 !== e[0]);
  3552. var n = Object.entries(e[0]).filter((function(t) {
  3553. var e = t[0];
  3554. return t[1], "count_alias" === e;
  3555. })).map((function(e) {
  3556. e[0];
  3557. var n = e[1];
  3558. return t.userDataWriter.convertValue(n);
  3559. }))[0];
  3560. return I("number" == typeof n), Promise.resolve(new bn(t.query, {
  3561. count: n
  3562. }));
  3563. }));
  3564. }, t;
  3565. }(), En = /** @class */ function() {
  3566. /** @hideconstructor */
  3567. function t(t,
  3568. /**
  3569. * If provided, the `FirestoreDataConverter` associated with this instance.
  3570. */
  3571. e, n) {
  3572. this.converter = e, this._key = n,
  3573. /** The type of this Firestore reference. */
  3574. this.type = "document", this.firestore = t;
  3575. }
  3576. return Object.defineProperty(t.prototype, "_path", {
  3577. get: function() {
  3578. return this._key.path;
  3579. },
  3580. enumerable: !1,
  3581. configurable: !0
  3582. }), Object.defineProperty(t.prototype, "id", {
  3583. /**
  3584. * The document's identifier within its collection.
  3585. */
  3586. get: function() {
  3587. return this._key.path.lastSegment();
  3588. },
  3589. enumerable: !1,
  3590. configurable: !0
  3591. }), Object.defineProperty(t.prototype, "path", {
  3592. /**
  3593. * A string representing the path of the referenced document (relative
  3594. * to the root of the database).
  3595. */
  3596. get: function() {
  3597. return this._key.path.canonicalString();
  3598. },
  3599. enumerable: !1,
  3600. configurable: !0
  3601. }), Object.defineProperty(t.prototype, "parent", {
  3602. /**
  3603. * The collection this `DocumentReference` belongs to.
  3604. */
  3605. get: function() {
  3606. return new Sn(this.firestore, this.converter, this._key.path.popLast());
  3607. },
  3608. enumerable: !1,
  3609. configurable: !0
  3610. }), t.prototype.withConverter = function(e) {
  3611. return new t(this.firestore, e, this._key);
  3612. }, t;
  3613. }(), kn = /** @class */ function() {
  3614. // This is the lite version of the Query class in the main SDK.
  3615. /** @hideconstructor protected */
  3616. function t(t,
  3617. /**
  3618. * If provided, the `FirestoreDataConverter` associated with this instance.
  3619. */
  3620. e, n) {
  3621. this.converter = e, this._query = n,
  3622. /** The type of this Firestore reference. */
  3623. this.type = "query", this.firestore = t;
  3624. }
  3625. return t.prototype.withConverter = function(e) {
  3626. return new t(this.firestore, e, this._query);
  3627. }, t;
  3628. }(), Sn = /** @class */ function(e) {
  3629. /** @hideconstructor */
  3630. function n(t, n, r) {
  3631. var i = this;
  3632. return (i = e.call(this, t, n, new ge(r)) || this)._path = r,
  3633. /** The type of this Firestore reference. */
  3634. i.type = "collection", i;
  3635. }
  3636. return t(n, e), Object.defineProperty(n.prototype, "id", {
  3637. /** The collection's identifier. */ get: function() {
  3638. return this._query.path.lastSegment();
  3639. },
  3640. enumerable: !1,
  3641. configurable: !0
  3642. }), Object.defineProperty(n.prototype, "path", {
  3643. /**
  3644. * A string representing the path of the referenced collection (relative
  3645. * to the root of the database).
  3646. */
  3647. get: function() {
  3648. return this._query.path.canonicalString();
  3649. },
  3650. enumerable: !1,
  3651. configurable: !0
  3652. }), Object.defineProperty(n.prototype, "parent", {
  3653. /**
  3654. * A reference to the containing `DocumentReference` if this is a
  3655. * subcollection. If this isn't a subcollection, the reference is null.
  3656. */
  3657. get: function() {
  3658. var t = this._path.popLast();
  3659. return t.isEmpty() ? null : new En(this.firestore,
  3660. /* converter= */ null, new it(t));
  3661. },
  3662. enumerable: !1,
  3663. configurable: !0
  3664. }), n.prototype.withConverter = function(t) {
  3665. return new n(this.firestore, t, this._path);
  3666. }, n;
  3667. }(kn);
  3668. /**
  3669. * The results of executing an aggregation query.
  3670. */ function In(t, e) {
  3671. for (var n = [], i = 2; i < arguments.length; i++) n[i - 2] = arguments[i];
  3672. if (t = p(t), ot("collection", "path", e), t instanceof yn) {
  3673. var o = et.fromString.apply(et, r([ e ], n, !1));
  3674. return ut(o), new Sn(t, /* converter= */ null, o);
  3675. }
  3676. if (!(t instanceof En || t instanceof Sn)) throw new B(P, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
  3677. var a = t._path.child(et.fromString.apply(et, r([ e ], n, !1)));
  3678. return ut(a), new Sn(t.firestore,
  3679. /* converter= */ null, a);
  3680. }
  3681. // TODO(firestorelite): Consider using ErrorFactory -
  3682. // https://github.com/firebase/firebase-js-sdk/blob/0131e1f/packages/util/src/errors.ts#L106
  3683. /**
  3684. * Creates and returns a new `Query` instance that includes all documents in the
  3685. * database that are contained in a collection or subcollection with the
  3686. * given `collectionId`.
  3687. *
  3688. * @param firestore - A reference to the root `Firestore` instance.
  3689. * @param collectionId - Identifies the collections to query over. Every
  3690. * collection or subcollection with this ID as the last segment of its path
  3691. * will be included. Cannot contain a slash.
  3692. * @returns The created `Query`.
  3693. */ function An(t, e) {
  3694. if (t = ct(t, yn), ot("collectionGroup", "collection id", e), e.indexOf("/") >= 0) throw new B(P, "Invalid collection ID '".concat(e, "' passed to function collectionGroup(). Collection IDs must not contain '/'."));
  3695. return new kn(t,
  3696. /* converter= */ null, function(t) {
  3697. return new ge(et.emptyPath(), t);
  3698. }(e));
  3699. }
  3700. function Fn(t, e) {
  3701. for (var n = [], i = 2; i < arguments.length; i++) n[i - 2] = arguments[i];
  3702. if (t = p(t),
  3703. // We allow omission of 'pathString' but explicitly prohibit passing in both
  3704. // 'undefined' and 'null'.
  3705. 1 === arguments.length && (e = wt.N()), ot("doc", "path", e), t instanceof yn) {
  3706. var o = et.fromString.apply(et, r([ e ], n, !1));
  3707. return at(o), new En(t,
  3708. /* converter= */ null, new it(o));
  3709. }
  3710. if (!(t instanceof En || t instanceof Sn)) throw new B(P, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
  3711. var a = t._path.child(et.fromString.apply(et, r([ e ], n, !1)));
  3712. return at(a), new En(t.firestore, t instanceof Sn ? t.converter : null, new it(a));
  3713. }
  3714. /**
  3715. * Returns true if the provided references are equal.
  3716. *
  3717. * @param left - A reference to compare.
  3718. * @param right - A reference to compare.
  3719. * @returns true if the references point to the same location in the same
  3720. * Firestore database.
  3721. */ function Vn(t, e) {
  3722. return t = p(t), e = p(e), (t instanceof En || t instanceof Sn) && (e instanceof En || e instanceof Sn) && t.firestore === e.firestore && t.path === e.path && t.converter === e.converter
  3723. /**
  3724. * Returns true if the provided queries point to the same collection and apply
  3725. * the same constraints.
  3726. *
  3727. * @param left - A `Query` to compare.
  3728. * @param right - A `Query` to compare.
  3729. * @returns true if the references point to the same location in the same
  3730. * Firestore database.
  3731. */;
  3732. }
  3733. function Pn(t, e) {
  3734. return t = p(t), e = p(e), t instanceof kn && e instanceof kn && t.firestore === e.firestore && function(t, e) {
  3735. return function(t, e) {
  3736. if (t.limit !== e.limit) return !1;
  3737. if (t.orderBy.length !== e.orderBy.length) return !1;
  3738. for (var n = 0; n < t.orderBy.length; n++) if (!ae(t.orderBy[n], e.orderBy[n])) return !1;
  3739. if (t.filters.length !== e.filters.length) return !1;
  3740. for (var r = 0; r < t.filters.length; r++) if (!Xt(t.filters[r], e.filters[r])) return !1;
  3741. return t.collectionGroup === e.collectionGroup && !!t.path.isEqual(e.path) && !!Kt(t.startAt, e.startAt) && Kt(t.endAt, e.endAt);
  3742. }(Ee(t), Ee(e)) && t.limitType === e.limitType;
  3743. }(t._query, e._query) && t.converter === e.converter
  3744. /**
  3745. * @license
  3746. * Copyright 2020 Google LLC
  3747. *
  3748. * Licensed under the Apache License, Version 2.0 (the "License");
  3749. * you may not use this file except in compliance with the License.
  3750. * You may obtain a copy of the License at
  3751. *
  3752. * http://www.apache.org/licenses/LICENSE-2.0
  3753. *
  3754. * Unless required by applicable law or agreed to in writing, software
  3755. * distributed under the License is distributed on an "AS IS" BASIS,
  3756. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3757. * See the License for the specific language governing permissions and
  3758. * limitations under the License.
  3759. */
  3760. /**
  3761. * An immutable object representing an array of bytes.
  3762. */;
  3763. }
  3764. var Dn = /** @class */ function() {
  3765. /** @hideconstructor */
  3766. function t(t) {
  3767. this._byteString = t;
  3768. }
  3769. /**
  3770. * Creates a new `Bytes` object from the given Base64 string, converting it to
  3771. * bytes.
  3772. *
  3773. * @param base64 - The Base64 string used to create the `Bytes` object.
  3774. */ return t.fromBase64String = function(e) {
  3775. try {
  3776. return new t(kt.fromBase64String(e));
  3777. } catch (e) {
  3778. throw new B(P, "Failed to construct data from Base64 string: " + e);
  3779. }
  3780. },
  3781. /**
  3782. * Creates a new `Bytes` object from the given Uint8Array.
  3783. *
  3784. * @param array - The Uint8Array used to create the `Bytes` object.
  3785. */
  3786. t.fromUint8Array = function(e) {
  3787. return new t(kt.fromUint8Array(e));
  3788. },
  3789. /**
  3790. * Returns the underlying bytes as a Base64-encoded string.
  3791. *
  3792. * @returns The Base64-encoded string created from the `Bytes` object.
  3793. */
  3794. t.prototype.toBase64 = function() {
  3795. return this._byteString.toBase64();
  3796. },
  3797. /**
  3798. * Returns the underlying bytes in a new `Uint8Array`.
  3799. *
  3800. * @returns The Uint8Array created from the `Bytes` object.
  3801. */
  3802. t.prototype.toUint8Array = function() {
  3803. return this._byteString.toUint8Array();
  3804. },
  3805. /**
  3806. * Returns a string representation of the `Bytes` object.
  3807. *
  3808. * @returns A string representation of the `Bytes` object.
  3809. */
  3810. t.prototype.toString = function() {
  3811. return "Bytes(base64: " + this.toBase64() + ")";
  3812. },
  3813. /**
  3814. * Returns true if this `Bytes` object is equal to the provided one.
  3815. *
  3816. * @param other - The `Bytes` object to compare against.
  3817. * @returns true if this `Bytes` object is equal to the provided one.
  3818. */
  3819. t.prototype.isEqual = function(t) {
  3820. return this._byteString.isEqual(t._byteString);
  3821. }, t;
  3822. }(), On = /** @class */ function() {
  3823. /**
  3824. * Creates a `FieldPath` from the provided field names. If more than one field
  3825. * name is provided, the path will point to a nested field in a document.
  3826. *
  3827. * @param fieldNames - A list of field names.
  3828. */
  3829. function t() {
  3830. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  3831. for (var n = 0; n < t.length; ++n) if (0 === t[n].length) throw new B(P, "Invalid field name at argument $(i + 1). Field names must not be empty.");
  3832. this._internalPath = new rt(t);
  3833. }
  3834. /**
  3835. * Returns true if this `FieldPath` is equal to the provided one.
  3836. *
  3837. * @param other - The `FieldPath` to compare against.
  3838. * @returns true if this `FieldPath` is equal to the provided one.
  3839. */ return t.prototype.isEqual = function(t) {
  3840. return this._internalPath.isEqual(t._internalPath);
  3841. }, t;
  3842. }();
  3843. /**
  3844. * @license
  3845. * Copyright 2020 Google LLC
  3846. *
  3847. * Licensed under the Apache License, Version 2.0 (the "License");
  3848. * you may not use this file except in compliance with the License.
  3849. * You may obtain a copy of the License at
  3850. *
  3851. * http://www.apache.org/licenses/LICENSE-2.0
  3852. *
  3853. * Unless required by applicable law or agreed to in writing, software
  3854. * distributed under the License is distributed on an "AS IS" BASIS,
  3855. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3856. * See the License for the specific language governing permissions and
  3857. * limitations under the License.
  3858. */
  3859. /**
  3860. * A `FieldPath` refers to a field in a document. The path may consist of a
  3861. * single field name (referring to a top-level field in the document), or a
  3862. * list of field names (referring to a nested field in the document).
  3863. *
  3864. * Create a `FieldPath` by providing field names. If more than one field
  3865. * name is provided, the path will point to a nested field in a document.
  3866. */
  3867. /**
  3868. * Returns a special sentinel `FieldPath` to refer to the ID of a document.
  3869. * It can be used in queries to sort or filter by the document ID.
  3870. */
  3871. function Nn() {
  3872. return new On("__name__");
  3873. }
  3874. /**
  3875. * @license
  3876. * Copyright 2020 Google LLC
  3877. *
  3878. * Licensed under the Apache License, Version 2.0 (the "License");
  3879. * you may not use this file except in compliance with the License.
  3880. * You may obtain a copy of the License at
  3881. *
  3882. * http://www.apache.org/licenses/LICENSE-2.0
  3883. *
  3884. * Unless required by applicable law or agreed to in writing, software
  3885. * distributed under the License is distributed on an "AS IS" BASIS,
  3886. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3887. * See the License for the specific language governing permissions and
  3888. * limitations under the License.
  3889. */
  3890. /**
  3891. * Sentinel values that can be used when writing document fields with `set()`
  3892. * or `update()`.
  3893. */ var qn =
  3894. /**
  3895. * @param _methodName - The public API endpoint that returns this class.
  3896. * @hideconstructor
  3897. */
  3898. function(t) {
  3899. this._methodName = t;
  3900. }, Rn = /** @class */ function() {
  3901. /**
  3902. * Creates a new immutable `GeoPoint` object with the provided latitude and
  3903. * longitude values.
  3904. * @param latitude - The latitude as number between -90 and 90.
  3905. * @param longitude - The longitude as number between -180 and 180.
  3906. */
  3907. function t(t, e) {
  3908. if (!isFinite(t) || t < -90 || t > 90) throw new B(P, "Latitude must be a number between -90 and 90, but was: " + t);
  3909. if (!isFinite(e) || e < -180 || e > 180) throw new B(P, "Longitude must be a number between -180 and 180, but was: " + e);
  3910. this._lat = t, this._long = e;
  3911. }
  3912. return Object.defineProperty(t.prototype, "latitude", {
  3913. /**
  3914. * The latitude of this `GeoPoint` instance.
  3915. */
  3916. get: function() {
  3917. return this._lat;
  3918. },
  3919. enumerable: !1,
  3920. configurable: !0
  3921. }), Object.defineProperty(t.prototype, "longitude", {
  3922. /**
  3923. * The longitude of this `GeoPoint` instance.
  3924. */
  3925. get: function() {
  3926. return this._long;
  3927. },
  3928. enumerable: !1,
  3929. configurable: !0
  3930. }),
  3931. /**
  3932. * Returns true if this `GeoPoint` is equal to the provided one.
  3933. *
  3934. * @param other - The `GeoPoint` to compare against.
  3935. * @returns true if this `GeoPoint` is equal to the provided one.
  3936. */
  3937. t.prototype.isEqual = function(t) {
  3938. return this._lat === t._lat && this._long === t._long;
  3939. },
  3940. /** Returns a JSON-serializable representation of this GeoPoint. */ t.prototype.toJSON = function() {
  3941. return {
  3942. latitude: this._lat,
  3943. longitude: this._long
  3944. };
  3945. },
  3946. /**
  3947. * Actually private to JS consumers of our API, so this function is prefixed
  3948. * with an underscore.
  3949. */
  3950. t.prototype._compareTo = function(t) {
  3951. return _t(this._lat, t._lat) || _t(this._long, t._long);
  3952. }, t;
  3953. }(), Cn = /^__.*__$/, xn = /** @class */ function() {
  3954. function t(t, e, n) {
  3955. this.data = t, this.fieldMask = e, this.fieldTransforms = n;
  3956. }
  3957. return t.prototype.toMutation = function(t, e) {
  3958. return null !== this.fieldMask ? new Re(t, this.data, this.fieldMask, e, this.fieldTransforms) : new qe(t, this.data, e, this.fieldTransforms);
  3959. }, t;
  3960. }(), Ln = /** @class */ function() {
  3961. function t(t,
  3962. // The fieldMask does not include document transforms.
  3963. e, n) {
  3964. this.data = t, this.fieldMask = e, this.fieldTransforms = n;
  3965. }
  3966. return t.prototype.toMutation = function(t, e) {
  3967. return new Re(t, this.data, this.fieldMask, e, this.fieldTransforms);
  3968. }, t;
  3969. }();
  3970. /**
  3971. * @license
  3972. * Copyright 2017 Google LLC
  3973. *
  3974. * Licensed under the Apache License, Version 2.0 (the "License");
  3975. * you may not use this file except in compliance with the License.
  3976. * You may obtain a copy of the License at
  3977. *
  3978. * http://www.apache.org/licenses/LICENSE-2.0
  3979. *
  3980. * Unless required by applicable law or agreed to in writing, software
  3981. * distributed under the License is distributed on an "AS IS" BASIS,
  3982. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  3983. * See the License for the specific language governing permissions and
  3984. * limitations under the License.
  3985. */
  3986. /**
  3987. * An immutable object representing a geographic location in Firestore. The
  3988. * location is represented as latitude/longitude pair.
  3989. *
  3990. * Latitude values are in the range of [-90, 90].
  3991. * Longitude values are in the range of [-180, 180].
  3992. */ function jn(t) {
  3993. switch (t) {
  3994. case 0 /* UserDataSource.Set */ :
  3995. // fall through
  3996. case 2 /* UserDataSource.MergeSet */ :
  3997. // fall through
  3998. case 1 /* UserDataSource.Update */ :
  3999. return !0;
  4000. case 3 /* UserDataSource.Argument */ :
  4001. case 4 /* UserDataSource.ArrayArgument */ :
  4002. return !1;
  4003. default:
  4004. throw S();
  4005. }
  4006. }
  4007. /** A "context" object passed around while parsing user data. */ var Mn = /** @class */ function() {
  4008. /**
  4009. * Initializes a ParseContext with the given source and path.
  4010. *
  4011. * @param settings - The settings for the parser.
  4012. * @param databaseId - The database ID of the Firestore instance.
  4013. * @param serializer - The serializer to use to generate the Value proto.
  4014. * @param ignoreUndefinedProperties - Whether to ignore undefined properties
  4015. * rather than throw.
  4016. * @param fieldTransforms - A mutable list of field transforms encountered
  4017. * while parsing the data.
  4018. * @param fieldMask - A mutable list of field paths encountered while parsing
  4019. * the data.
  4020. *
  4021. * TODO(b/34871131): We don't support array paths right now, so path can be
  4022. * null to indicate the context represents any location within an array (in
  4023. * which case certain features will not work and errors will be somewhat
  4024. * compromised).
  4025. */
  4026. function t(t, e, n, r, i, o) {
  4027. this.settings = t, this.databaseId = e, this.C = n, this.ignoreUndefinedProperties = r,
  4028. // Minor hack: If fieldTransforms is undefined, we assume this is an
  4029. // external call and we need to validate the entire path.
  4030. void 0 === i && this.et(), this.fieldTransforms = i || [], this.fieldMask = o || [];
  4031. }
  4032. return Object.defineProperty(t.prototype, "path", {
  4033. get: function() {
  4034. return this.settings.path;
  4035. },
  4036. enumerable: !1,
  4037. configurable: !0
  4038. }), Object.defineProperty(t.prototype, "nt", {
  4039. get: function() {
  4040. return this.settings.nt;
  4041. },
  4042. enumerable: !1,
  4043. configurable: !0
  4044. }),
  4045. /** Returns a new context with the specified settings overwritten. */ t.prototype.rt = function(e) {
  4046. return new t(Object.assign(Object.assign({}, this.settings), e), this.databaseId, this.C, this.ignoreUndefinedProperties, this.fieldTransforms, this.fieldMask);
  4047. }, t.prototype.st = function(t) {
  4048. var e, n = null === (e = this.path) || void 0 === e ? void 0 : e.child(t), r = this.rt({
  4049. path: n,
  4050. it: !1
  4051. });
  4052. return r.ot(t), r;
  4053. }, t.prototype.ut = function(t) {
  4054. var e, n = null === (e = this.path) || void 0 === e ? void 0 : e.child(t), r = this.rt({
  4055. path: n,
  4056. it: !1
  4057. });
  4058. return r.et(), r;
  4059. }, t.prototype.ct = function(t) {
  4060. // TODO(b/34871131): We don't support array paths right now; so make path
  4061. // undefined.
  4062. return this.rt({
  4063. path: void 0,
  4064. it: !0
  4065. });
  4066. }, t.prototype.at = function(t) {
  4067. return ar(t, this.settings.methodName, this.settings.ht || !1, this.path, this.settings.lt);
  4068. },
  4069. /** Returns 'true' if 'fieldPath' was traversed when creating this context. */ t.prototype.contains = function(t) {
  4070. return void 0 !== this.fieldMask.find((function(e) {
  4071. return t.isPrefixOf(e);
  4072. })) || void 0 !== this.fieldTransforms.find((function(e) {
  4073. return t.isPrefixOf(e.field);
  4074. }));
  4075. }, t.prototype.et = function() {
  4076. // TODO(b/34871131): Remove null check once we have proper paths for fields
  4077. // within arrays.
  4078. if (this.path) for (var t = 0; t < this.path.length; t++) this.ot(this.path.get(t));
  4079. }, t.prototype.ot = function(t) {
  4080. if (0 === t.length) throw this.at("Document fields must not be empty");
  4081. if (jn(this.nt) && Cn.test(t)) throw this.at('Document fields cannot begin and end with "__"');
  4082. }, t;
  4083. }(), Un = /** @class */ function() {
  4084. function t(t, e, n) {
  4085. this.databaseId = t, this.ignoreUndefinedProperties = e, this.C = n || un(t)
  4086. /** Creates a new top-level parse context. */;
  4087. }
  4088. return t.prototype.ft = function(t, e, n, r) {
  4089. return void 0 === r && (r = !1), new Mn({
  4090. nt: t,
  4091. methodName: e,
  4092. lt: n,
  4093. path: rt.emptyPath(),
  4094. it: !1,
  4095. ht: r
  4096. }, this.databaseId, this.C, this.ignoreUndefinedProperties);
  4097. }, t;
  4098. }();
  4099. /**
  4100. * Helper for parsing raw user input (provided via the API) into internal model
  4101. * classes.
  4102. */ function Bn(t) {
  4103. var e = t._freezeSettings(), n = un(t._databaseId);
  4104. return new Un(t._databaseId, !!e.ignoreUndefinedProperties, n);
  4105. }
  4106. /** Parse document data from a set() call. */ function Gn(t, e, n, r, i, o) {
  4107. void 0 === o && (o = {});
  4108. var a = t.ft(o.merge || o.mergeFields ? 2 /* UserDataSource.MergeSet */ : 0 /* UserDataSource.Set */ , e, n, i);
  4109. nr("Data must be an object, but it was:", a, r);
  4110. var u, s, c = tr(r, a);
  4111. if (o.merge) u = new pe(a.fieldMask), s = a.fieldTransforms; else if (o.mergeFields) {
  4112. for (var l = [], f = 0, h = o.mergeFields; f < h.length; f++) {
  4113. var p = rr(e, h[f], n);
  4114. if (!a.contains(p)) throw new B(P, "Field '".concat(p, "' is specified in your field mask but missing from your input data."));
  4115. ur(l, p) || l.push(p);
  4116. }
  4117. u = new pe(l), s = a.fieldTransforms.filter((function(t) {
  4118. return u.covers(t.field);
  4119. }));
  4120. } else u = null, s = a.fieldTransforms;
  4121. return new xn(new de(c), u, s);
  4122. }
  4123. var Qn = /** @class */ function(e) {
  4124. function n() {
  4125. return null !== e && e.apply(this, arguments) || this;
  4126. }
  4127. return t(n, e), n.prototype._toFieldTransform = function(t) {
  4128. if (2 /* UserDataSource.MergeSet */ !== t.nt) throw 1 /* UserDataSource.Update */ === t.nt ? t.at("".concat(this._methodName, "() can only appear at the top level of your update data")) : t.at("".concat(this._methodName, "() cannot be used with set() unless you pass {merge:true}"));
  4129. // No transform to add for a delete, but we need to add it to our
  4130. // fieldMask so it gets deleted.
  4131. return t.fieldMask.push(t.path), null;
  4132. }, n.prototype.isEqual = function(t) {
  4133. return t instanceof n;
  4134. }, n;
  4135. }(qn);
  4136. /**
  4137. * Creates a child context for parsing SerializableFieldValues.
  4138. *
  4139. * This is different than calling `ParseContext.contextWith` because it keeps
  4140. * the fieldTransforms and fieldMask separate.
  4141. *
  4142. * The created context has its `dataSource` set to `UserDataSource.Argument`.
  4143. * Although these values are used with writes, any elements in these FieldValues
  4144. * are not considered writes since they cannot contain any FieldValue sentinels,
  4145. * etc.
  4146. *
  4147. * @param fieldValue - The sentinel FieldValue for which to create a child
  4148. * context.
  4149. * @param context - The parent context.
  4150. * @param arrayElement - Whether or not the FieldValue has an array.
  4151. */ function zn(t, e, n) {
  4152. return new Mn({
  4153. nt: 3 /* UserDataSource.Argument */ ,
  4154. lt: e.settings.lt,
  4155. methodName: t._methodName,
  4156. it: n
  4157. }, e.databaseId, e.C, e.ignoreUndefinedProperties);
  4158. }
  4159. var Kn = /** @class */ function(e) {
  4160. function n() {
  4161. return null !== e && e.apply(this, arguments) || this;
  4162. }
  4163. return t(n, e), n.prototype._toFieldTransform = function(t) {
  4164. return new De(t.path, new Ae);
  4165. }, n.prototype.isEqual = function(t) {
  4166. return t instanceof n;
  4167. }, n;
  4168. }(qn), Wn = /** @class */ function(e) {
  4169. function n(t, n) {
  4170. var r = this;
  4171. return (r = e.call(this, t) || this).dt = n, r;
  4172. }
  4173. return t(n, e), n.prototype._toFieldTransform = function(t) {
  4174. var e = zn(this, t,
  4175. /*array=*/ !0), n = this.dt.map((function(t) {
  4176. return $n(t, e);
  4177. })), r = new Fe(n);
  4178. return new De(t.path, r);
  4179. }, n.prototype.isEqual = function(t) {
  4180. // TODO(mrschmidt): Implement isEquals
  4181. return this === t;
  4182. }, n;
  4183. }(qn), Hn = /** @class */ function(e) {
  4184. function n(t, n) {
  4185. var r = this;
  4186. return (r = e.call(this, t) || this).dt = n, r;
  4187. }
  4188. return t(n, e), n.prototype._toFieldTransform = function(t) {
  4189. var e = zn(this, t,
  4190. /*array=*/ !0), n = this.dt.map((function(t) {
  4191. return $n(t, e);
  4192. })), r = new Ve(n);
  4193. return new De(t.path, r);
  4194. }, n.prototype.isEqual = function(t) {
  4195. // TODO(mrschmidt): Implement isEquals
  4196. return this === t;
  4197. }, n;
  4198. }(qn), Yn = /** @class */ function(e) {
  4199. function n(t, n) {
  4200. var r = this;
  4201. return (r = e.call(this, t) || this).wt = n, r;
  4202. }
  4203. return t(n, e), n.prototype._toFieldTransform = function(t) {
  4204. var e = new Pe(t.C, Se(t.C, this.wt));
  4205. return new De(t.path, e);
  4206. }, n.prototype.isEqual = function(t) {
  4207. // TODO(mrschmidt): Implement isEquals
  4208. return this === t;
  4209. }, n;
  4210. }(qn);
  4211. /** Parse update data from an update() call. */ function Xn(t, e, n, r) {
  4212. var i = t.ft(1 /* UserDataSource.Update */ , e, n);
  4213. nr("Data must be an object, but it was:", i, r);
  4214. var o = [], a = de.empty();
  4215. Et(r, (function(t, r) {
  4216. var u = or(e, t, n);
  4217. // For Compat types, we have to "extract" the underlying types before
  4218. // performing validation.
  4219. r = p(r);
  4220. var s = i.ut(u);
  4221. if (r instanceof Qn)
  4222. // Add it to the field mask, but don't add anything to updateData.
  4223. o.push(u); else {
  4224. var c = $n(r, s);
  4225. null != c && (o.push(u), a.set(u, c));
  4226. }
  4227. }));
  4228. var u = new pe(o);
  4229. return new Ln(a, u, i.fieldTransforms);
  4230. }
  4231. /** Parse update data from a list of field/value arguments. */ function Jn(t, e, n, r, i, o) {
  4232. var a = t.ft(1 /* UserDataSource.Update */ , e, n), u = [ rr(e, r, n) ], s = [ i ];
  4233. if (o.length % 2 != 0) throw new B(P, "Function ".concat(e, "() needs to be called with an even number of arguments that alternate between field names and values."));
  4234. for (var c = 0; c < o.length; c += 2) u.push(rr(e, o[c])), s.push(o[c + 1]);
  4235. // We iterate in reverse order to pick the last value for a field if the
  4236. // user specified the field multiple times.
  4237. for (var l = [], f = de.empty(), h = u.length - 1; h >= 0; --h) if (!ur(l, u[h])) {
  4238. var d = u[h], y = s[h];
  4239. // For Compat types, we have to "extract" the underlying types before
  4240. // performing validation.
  4241. y = p(y);
  4242. var m = a.ut(d);
  4243. if (y instanceof Qn)
  4244. // Add it to the field mask, but don't add anything to updateData.
  4245. l.push(d); else {
  4246. var v = $n(y, m);
  4247. null != v && (l.push(d), f.set(d, v));
  4248. }
  4249. }
  4250. var g = new pe(l);
  4251. return new Ln(f, g, a.fieldTransforms);
  4252. }
  4253. /**
  4254. * Parse a "query value" (e.g. value in a where filter or a value in a cursor
  4255. * bound).
  4256. *
  4257. * @param allowArrays - Whether the query value is an array that may directly
  4258. * contain additional arrays (e.g. the operand of an `in` query).
  4259. */ function Zn(t, e, n, r) {
  4260. return void 0 === r && (r = !1), $n(n, t.ft(r ? 4 /* UserDataSource.ArrayArgument */ : 3 /* UserDataSource.Argument */ , e));
  4261. }
  4262. /**
  4263. * Parses user data to Protobuf Values.
  4264. *
  4265. * @param input - Data to be parsed.
  4266. * @param context - A context object representing the current path being parsed,
  4267. * the source of the data being parsed, etc.
  4268. * @returns The parsed value, or null if the value was a FieldValue sentinel
  4269. * that should not be included in the resulting parsed data.
  4270. */ function $n(t, e) {
  4271. if (er(
  4272. // Unwrap the API type from the Compat SDK. This will return the API type
  4273. // from firestore-exp.
  4274. t = p(t))) return nr("Unsupported field value:", e, t), tr(t, e);
  4275. if (t instanceof qn)
  4276. // FieldValues usually parse into transforms (except deleteField())
  4277. // in which case we do not want to include this field in our parsed data
  4278. // (as doing so will overwrite the field directly prior to the transform
  4279. // trying to transform it). So we don't add this location to
  4280. // context.fieldMask and we return null as our parsing result.
  4281. /**
  4282. * "Parses" the provided FieldValueImpl, adding any necessary transforms to
  4283. * context.fieldTransforms.
  4284. */
  4285. return function(t, e) {
  4286. // Sentinels are only supported with writes, and not within arrays.
  4287. if (!jn(e.nt)) throw e.at("".concat(t._methodName, "() can only be used with update() and set()"));
  4288. if (!e.path) throw e.at("".concat(t._methodName, "() is not currently supported inside arrays"));
  4289. var n = t._toFieldTransform(e);
  4290. n && e.fieldTransforms.push(n);
  4291. }(t, e), null;
  4292. if (void 0 === t && e.ignoreUndefinedProperties)
  4293. // If the input is undefined it can never participate in the fieldMask, so
  4294. // don't handle this below. If `ignoreUndefinedProperties` is false,
  4295. // `parseScalarValue` will reject an undefined value.
  4296. return null;
  4297. if (
  4298. // If context.path is null we are inside an array and we don't support
  4299. // field mask paths more granular than the top-level array.
  4300. e.path && e.fieldMask.push(e.path), t instanceof Array) {
  4301. // TODO(b/34871131): Include the path containing the array in the error
  4302. // message.
  4303. // In the case of IN queries, the parsed data is an array (representing
  4304. // the set of values to be included for the IN query) that may directly
  4305. // contain additional arrays (each representing an individual field
  4306. // value), so we disable this validation.
  4307. if (e.settings.it && 4 /* UserDataSource.ArrayArgument */ !== e.nt) throw e.at("Nested arrays are not supported");
  4308. return function(t, e) {
  4309. for (var n = [], r = 0, i = 0, o = t; i < o.length; i++) {
  4310. var a = $n(o[i], e.ct(r));
  4311. null == a && (
  4312. // Just include nulls in the array for fields being replaced with a
  4313. // sentinel.
  4314. a = {
  4315. nullValue: "NULL_VALUE"
  4316. }), n.push(a), r++;
  4317. }
  4318. return {
  4319. arrayValue: {
  4320. values: n
  4321. }
  4322. };
  4323. }(t, e);
  4324. }
  4325. return function(t, e) {
  4326. if (null === (t = p(t))) return {
  4327. nullValue: "NULL_VALUE"
  4328. };
  4329. if ("number" == typeof t) return Se(e.C, t);
  4330. if ("boolean" == typeof t) return {
  4331. booleanValue: t
  4332. };
  4333. if ("string" == typeof t) return {
  4334. stringValue: t
  4335. };
  4336. if (t instanceof Date) {
  4337. var n = Vt.fromDate(t);
  4338. return {
  4339. timestampValue: Be(e.C, n)
  4340. };
  4341. }
  4342. if (t instanceof Vt) {
  4343. // Firestore backend truncates precision down to microseconds. To ensure
  4344. // offline mode works the same with regards to truncation, perform the
  4345. // truncation immediately without waiting for the backend to do that.
  4346. var r = new Vt(t.seconds, 1e3 * Math.floor(t.nanoseconds / 1e3));
  4347. return {
  4348. timestampValue: Be(e.C, r)
  4349. };
  4350. }
  4351. if (t instanceof Rn) return {
  4352. geoPointValue: {
  4353. latitude: t.latitude,
  4354. longitude: t.longitude
  4355. }
  4356. };
  4357. if (t instanceof Dn) return {
  4358. bytesValue: Ge(e.C, t._byteString)
  4359. };
  4360. if (t instanceof En) {
  4361. var i = e.databaseId, o = t.firestore._databaseId;
  4362. if (!o.isEqual(i)) throw e.at("Document reference is for database ".concat(o.projectId, "/").concat(o.database, " but should be for database ").concat(i.projectId, "/").concat(i.database));
  4363. return {
  4364. referenceValue: Ke(t.firestore._databaseId || e.databaseId, t._key.path)
  4365. };
  4366. }
  4367. throw e.at("Unsupported field value: ".concat(st(t)));
  4368. }(t, e);
  4369. }
  4370. function tr(t, e) {
  4371. var n = {};
  4372. return function(t) {
  4373. for (var e in t) if (Object.prototype.hasOwnProperty.call(t, e)) return !1;
  4374. return !0;
  4375. }(t) ?
  4376. // If we encounter an empty object, we explicitly add it to the update
  4377. // mask to ensure that the server creates a map entry.
  4378. e.path && e.path.length > 0 && e.fieldMask.push(e.path) : Et(t, (function(t, r) {
  4379. var i = $n(r, e.st(t));
  4380. null != i && (n[t] = i);
  4381. })), {
  4382. mapValue: {
  4383. fields: n
  4384. }
  4385. };
  4386. }
  4387. function er(t) {
  4388. return !("object" != typeof t || null === t || t instanceof Array || t instanceof Date || t instanceof Vt || t instanceof Rn || t instanceof Dn || t instanceof En || t instanceof qn);
  4389. }
  4390. function nr(t, e, n) {
  4391. if (!er(n) || !function(t) {
  4392. return "object" == typeof t && null !== t && (Object.getPrototypeOf(t) === Object.prototype || null === Object.getPrototypeOf(t));
  4393. }(n)) {
  4394. var r = st(n);
  4395. throw "an object" === r ? e.at(t + " a custom object") : e.at(t + " " + r);
  4396. }
  4397. }
  4398. /**
  4399. * Helper that calls fromDotSeparatedString() but wraps any error thrown.
  4400. */ function rr(t, e, n) {
  4401. if (
  4402. // If required, replace the FieldPath Compat class with with the firestore-exp
  4403. // FieldPath.
  4404. (e = p(e)) instanceof On) return e._internalPath;
  4405. if ("string" == typeof e) return or(t, e);
  4406. throw ar("Field path arguments must be of type string or ", t,
  4407. /* hasConverter= */ !1,
  4408. /* path= */ void 0, n);
  4409. }
  4410. /**
  4411. * Matches any characters in a field path string that are reserved.
  4412. */ var ir = new RegExp("[~\\*/\\[\\]]");
  4413. /**
  4414. * Wraps fromDotSeparatedString with an error message about the method that
  4415. * was thrown.
  4416. * @param methodName - The publicly visible method name
  4417. * @param path - The dot-separated string form of a field path which will be
  4418. * split on dots.
  4419. * @param targetDoc - The document against which the field path will be
  4420. * evaluated.
  4421. */ function or(t, e, n) {
  4422. if (e.search(ir) >= 0) throw ar("Invalid field path (".concat(e, "). Paths must not contain '~', '*', '/', '[', or ']'"), t,
  4423. /* hasConverter= */ !1,
  4424. /* path= */ void 0, n);
  4425. try {
  4426. return (new (On.bind.apply(On, r([ void 0 ], e.split("."), !1))))._internalPath;
  4427. } catch (r) {
  4428. throw ar("Invalid field path (".concat(e, "). Paths must not be empty, begin with '.', end with '.', or contain '..'"), t,
  4429. /* hasConverter= */ !1,
  4430. /* path= */ void 0, n);
  4431. }
  4432. }
  4433. function ar(t, e, n, r, i) {
  4434. var o = r && !r.isEmpty(), a = void 0 !== i, u = "Function ".concat(e, "() called with invalid data");
  4435. n && (u += " (via `toFirestore()`)"), u += ". ";
  4436. var s = "";
  4437. return (o || a) && (s += " (found", o && (s += " in field ".concat(r)), a && (s += " in document ".concat(i)),
  4438. s += ")"), new B(P, u + t + s)
  4439. /** Checks `haystack` if FieldPath `needle` is present. Runs in O(n). */;
  4440. }
  4441. function ur(t, e) {
  4442. return t.some((function(t) {
  4443. return t.isEqual(e);
  4444. }));
  4445. }
  4446. /**
  4447. * @license
  4448. * Copyright 2020 Google LLC
  4449. *
  4450. * Licensed under the Apache License, Version 2.0 (the "License");
  4451. * you may not use this file except in compliance with the License.
  4452. * You may obtain a copy of the License at
  4453. *
  4454. * http://www.apache.org/licenses/LICENSE-2.0
  4455. *
  4456. * Unless required by applicable law or agreed to in writing, software
  4457. * distributed under the License is distributed on an "AS IS" BASIS,
  4458. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4459. * See the License for the specific language governing permissions and
  4460. * limitations under the License.
  4461. */
  4462. /**
  4463. * A `DocumentSnapshot` contains data read from a document in your Firestore
  4464. * database. The data can be extracted with `.data()` or `.get(<field>)` to
  4465. * get a specific field.
  4466. *
  4467. * For a `DocumentSnapshot` that points to a non-existing document, any data
  4468. * access will return 'undefined'. You can use the `exists()` method to
  4469. * explicitly verify a document's existence.
  4470. */ var sr = /** @class */ function() {
  4471. // Note: This class is stripped down version of the DocumentSnapshot in
  4472. // the legacy SDK. The changes are:
  4473. // - No support for SnapshotMetadata.
  4474. // - No support for SnapshotOptions.
  4475. /** @hideconstructor protected */
  4476. function t(t, e, n, r, i) {
  4477. this._firestore = t, this._userDataWriter = e, this._key = n, this._document = r,
  4478. this._converter = i;
  4479. }
  4480. return Object.defineProperty(t.prototype, "id", {
  4481. /** Property of the `DocumentSnapshot` that provides the document's ID. */ get: function() {
  4482. return this._key.path.lastSegment();
  4483. },
  4484. enumerable: !1,
  4485. configurable: !0
  4486. }), Object.defineProperty(t.prototype, "ref", {
  4487. /**
  4488. * The `DocumentReference` for the document included in the `DocumentSnapshot`.
  4489. */
  4490. get: function() {
  4491. return new En(this._firestore, this._converter, this._key);
  4492. },
  4493. enumerable: !1,
  4494. configurable: !0
  4495. }),
  4496. /**
  4497. * Signals whether or not the document at the snapshot's location exists.
  4498. *
  4499. * @returns true if the document exists.
  4500. */
  4501. t.prototype.exists = function() {
  4502. return null !== this._document;
  4503. },
  4504. /**
  4505. * Retrieves all fields in the document as an `Object`. Returns `undefined` if
  4506. * the document doesn't exist.
  4507. *
  4508. * @returns An `Object` containing all fields in the document or `undefined`
  4509. * if the document doesn't exist.
  4510. */
  4511. t.prototype.data = function() {
  4512. if (this._document) {
  4513. if (this._converter) {
  4514. // We only want to use the converter and create a new DocumentSnapshot
  4515. // if a converter has been provided.
  4516. var t = new cr(this._firestore, this._userDataWriter, this._key, this._document,
  4517. /* converter= */ null);
  4518. return this._converter.fromFirestore(t);
  4519. }
  4520. return this._userDataWriter.convertValue(this._document.data.value);
  4521. }
  4522. },
  4523. /**
  4524. * Retrieves the field specified by `fieldPath`. Returns `undefined` if the
  4525. * document or field doesn't exist.
  4526. *
  4527. * @param fieldPath - The path (for example 'foo' or 'foo.bar') to a specific
  4528. * field.
  4529. * @returns The data at the specified field location or undefined if no such
  4530. * field exists in the document.
  4531. */
  4532. // We are using `any` here to avoid an explicit cast by our users.
  4533. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  4534. t.prototype.get = function(t) {
  4535. if (this._document) {
  4536. var e = this._document.data.field(hr("DocumentSnapshot.get", t));
  4537. if (null !== e) return this._userDataWriter.convertValue(e);
  4538. }
  4539. }, t;
  4540. }(), cr = /** @class */ function(e) {
  4541. function n() {
  4542. return null !== e && e.apply(this, arguments) || this;
  4543. }
  4544. /**
  4545. * Retrieves all fields in the document as an `Object`.
  4546. *
  4547. * @override
  4548. * @returns An `Object` containing all fields in the document.
  4549. */ return t(n, e), n.prototype.data = function() {
  4550. return e.prototype.data.call(this);
  4551. }, n;
  4552. }(sr), lr = /** @class */ function() {
  4553. /** @hideconstructor */
  4554. function t(t, e) {
  4555. this._docs = e, this.query = t;
  4556. }
  4557. return Object.defineProperty(t.prototype, "docs", {
  4558. /** An array of all the documents in the `QuerySnapshot`. */ get: function() {
  4559. return r([], this._docs, !0);
  4560. },
  4561. enumerable: !1,
  4562. configurable: !0
  4563. }), Object.defineProperty(t.prototype, "size", {
  4564. /** The number of documents in the `QuerySnapshot`. */ get: function() {
  4565. return this.docs.length;
  4566. },
  4567. enumerable: !1,
  4568. configurable: !0
  4569. }), Object.defineProperty(t.prototype, "empty", {
  4570. /** True if there are no documents in the `QuerySnapshot`. */ get: function() {
  4571. return 0 === this.docs.length;
  4572. },
  4573. enumerable: !1,
  4574. configurable: !0
  4575. }),
  4576. /**
  4577. * Enumerates all of the documents in the `QuerySnapshot`.
  4578. *
  4579. * @param callback - A callback to be called with a `QueryDocumentSnapshot` for
  4580. * each document in the snapshot.
  4581. * @param thisArg - The `this` binding for the callback.
  4582. */
  4583. t.prototype.forEach = function(t, e) {
  4584. this._docs.forEach(t, e);
  4585. }, t;
  4586. }();
  4587. /**
  4588. * A `QueryDocumentSnapshot` contains data read from a document in your
  4589. * Firestore database as part of a query. The document is guaranteed to exist
  4590. * and its data can be extracted with `.data()` or `.get(<field>)` to get a
  4591. * specific field.
  4592. *
  4593. * A `QueryDocumentSnapshot` offers the same API surface as a
  4594. * `DocumentSnapshot`. Since query results contain only existing documents, the
  4595. * `exists` property will always be true and `data()` will never return
  4596. * 'undefined'.
  4597. */
  4598. /**
  4599. * Returns true if the provided snapshots are equal.
  4600. *
  4601. * @param left - A snapshot to compare.
  4602. * @param right - A snapshot to compare.
  4603. * @returns true if the snapshots are equal.
  4604. */
  4605. function fr(t, e) {
  4606. return t = p(t), e = p(e), t instanceof sr && e instanceof sr ? t._firestore === e._firestore && t._key.isEqual(e._key) && (null === t._document ? null === e._document : t._document.isEqual(e._document)) && t._converter === e._converter : t instanceof lr && e instanceof lr && Pn(t.query, e.query) && bt(t.docs, e.docs, fr)
  4607. /**
  4608. * Helper that calls `fromDotSeparatedString()` but wraps any error thrown.
  4609. */;
  4610. }
  4611. function hr(t, e) {
  4612. return "string" == typeof e ? or(t, e) : e instanceof On ? e._internalPath : e._delegate._internalPath;
  4613. }
  4614. /**
  4615. * @license
  4616. * Copyright 2020 Google LLC
  4617. *
  4618. * Licensed under the Apache License, Version 2.0 (the "License");
  4619. * you may not use this file except in compliance with the License.
  4620. * You may obtain a copy of the License at
  4621. *
  4622. * http://www.apache.org/licenses/LICENSE-2.0
  4623. *
  4624. * Unless required by applicable law or agreed to in writing, software
  4625. * distributed under the License is distributed on an "AS IS" BASIS,
  4626. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  4627. * See the License for the specific language governing permissions and
  4628. * limitations under the License.
  4629. */
  4630. /**
  4631. * An `AppliableConstraint` is an abstraction of a constraint that can be applied
  4632. * to a Firestore query.
  4633. */ var pr = function() {}, dr = /** @class */ function(e) {
  4634. function n() {
  4635. return null !== e && e.apply(this, arguments) || this;
  4636. }
  4637. return t(n, e), n;
  4638. }(pr);
  4639. /**
  4640. * A `QueryConstraint` is used to narrow the set of documents returned by a
  4641. * Firestore query. `QueryConstraint`s are created by invoking {@link where},
  4642. * {@link orderBy}, {@link startAt}, {@link startAfter}, {@link
  4643. * endBefore}, {@link endAt}, {@link limit}, {@link limitToLast} and
  4644. * can then be passed to {@link query} to create a new query instance that
  4645. * also contains this `QueryConstraint`.
  4646. */ function yr(t, e) {
  4647. for (var n = [], r = 2; r < arguments.length; r++) n[r - 2] = arguments[r];
  4648. var i = [];
  4649. e instanceof pr && i.push(e), function(t) {
  4650. var e = t.filter((function(t) {
  4651. return t instanceof gr;
  4652. })).length, n = t.filter((function(t) {
  4653. return t instanceof mr;
  4654. })).length;
  4655. if (e > 1 || e > 0 && n > 0) throw new B(P, "InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.");
  4656. }(i = i.concat(n));
  4657. for (var o = 0, a = i; o < a.length; o++) {
  4658. var u = a[o];
  4659. t = u._apply(t);
  4660. }
  4661. return t;
  4662. }
  4663. /**
  4664. * A `QueryFieldFilterConstraint` is used to narrow the set of documents returned by
  4665. * a Firestore query by filtering on one or more document fields.
  4666. * `QueryFieldFilterConstraint`s are created by invoking {@link where} and can then
  4667. * be passed to {@link query} to create a new query instance that also contains
  4668. * this `QueryFieldFilterConstraint`.
  4669. */ var mr = /** @class */ function(e) {
  4670. /**
  4671. * @internal
  4672. */
  4673. function n(t, n, r) {
  4674. var i = this;
  4675. return (i = e.call(this) || this)._field = t, i._op = n, i._value = r,
  4676. /** The type of this query constraint */
  4677. i.type = "where", i;
  4678. }
  4679. return t(n, e), n._create = function(t, e, r) {
  4680. return new n(t, e, r);
  4681. }, n.prototype._apply = function(t) {
  4682. var e = this._parse(t);
  4683. return Rr(t._query, e), new kn(t.firestore, t.converter, ke(t._query, e));
  4684. }, n.prototype._parse = function(t) {
  4685. var e = Bn(t.firestore), n = function(t, e, n, r, i, o, a) {
  4686. var u;
  4687. if (i.isKeyField()) {
  4688. if ("array-contains" /* Operator.ARRAY_CONTAINS */ === o || "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ === o) throw new B(P, "Invalid Query. You can't perform '".concat(o, "' queries on documentId()."));
  4689. if ("in" /* Operator.IN */ === o || "not-in" /* Operator.NOT_IN */ === o) {
  4690. qr(a, o);
  4691. for (var s = [], c = 0, l = a; c < l.length; c++) {
  4692. var f = l[c];
  4693. s.push(Nr(r, t, f));
  4694. }
  4695. u = {
  4696. arrayValue: {
  4697. values: s
  4698. }
  4699. };
  4700. } else u = Nr(r, t, a);
  4701. } else "in" /* Operator.IN */ !== o && "not-in" /* Operator.NOT_IN */ !== o && "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ !== o || qr(a, o),
  4702. u = Zn(n, "where", a,
  4703. /* allowArrays= */ "in" /* Operator.IN */ === o || "not-in" /* Operator.NOT_IN */ === o);
  4704. return Ht.create(i, o, u);
  4705. }(t._query, 0, e, t.firestore._databaseId, this._field, this._op, this._value);
  4706. return n;
  4707. }, n;
  4708. }(dr);
  4709. /**
  4710. * Creates a {@link QueryFieldFilterConstraint} that enforces that documents
  4711. * must contain the specified field and that the value should satisfy the
  4712. * relation constraint provided.
  4713. *
  4714. * @param fieldPath - The path to compare
  4715. * @param opStr - The operation string (e.g "&lt;", "&lt;=", "==", "&lt;",
  4716. * "&lt;=", "!=").
  4717. * @param value - The value for comparison
  4718. * @returns The created {@link QueryFieldFilterConstraint}.
  4719. */ function vr(t, e, n) {
  4720. var r = e, i = hr("where", t);
  4721. return mr._create(i, r, n);
  4722. }
  4723. /**
  4724. * A `QueryCompositeFilterConstraint` is used to narrow the set of documents
  4725. * returned by a Firestore query by performing the logical OR or AND of multiple
  4726. * {@link QueryFieldFilterConstraint}s or {@link QueryCompositeFilterConstraint}s.
  4727. * `QueryCompositeFilterConstraint`s are created by invoking {@link or} or
  4728. * {@link and} and can then be passed to {@link query} to create a new query
  4729. * instance that also contains the `QueryCompositeFilterConstraint`.
  4730. * @internal TODO remove this internal tag with OR Query support in the server
  4731. */ var gr = /** @class */ function(e) {
  4732. /**
  4733. * @internal
  4734. */
  4735. function n(
  4736. /** The type of this query constraint */
  4737. t, n) {
  4738. var r = this;
  4739. return (r = e.call(this) || this).type = t, r._queryConstraints = n, r;
  4740. }
  4741. return t(n, e), n._create = function(t, e) {
  4742. return new n(t, e);
  4743. }, n.prototype._parse = function(t) {
  4744. var e = this._queryConstraints.map((function(e) {
  4745. return e._parse(t);
  4746. })).filter((function(t) {
  4747. return t.getFilters().length > 0;
  4748. }));
  4749. return 1 === e.length ? e[0] : Yt.create(e, this._getOperator());
  4750. }, n.prototype._apply = function(t) {
  4751. var e = this._parse(t);
  4752. return 0 === e.getFilters().length ? t : (function(t, e) {
  4753. for (var n = t, r = 0, i = e.getFlattenedFilters(); r < i.length; r++) {
  4754. var o = i[r];
  4755. Rr(n, o), n = ke(n, o);
  4756. }
  4757. }(t._query, e), new kn(t.firestore, t.converter, ke(t._query, e)));
  4758. }, n.prototype._getQueryConstraints = function() {
  4759. return this._queryConstraints;
  4760. }, n.prototype._getOperator = function() {
  4761. return "and" === this.type ? "and" /* CompositeOperator.AND */ : "or" /* CompositeOperator.OR */;
  4762. }, n;
  4763. }(pr);
  4764. /**
  4765. * Creates a new {@link QueryCompositeFilterConstraint} that is a disjunction of
  4766. * the given filter constraints. A disjunction filter includes a document if it
  4767. * satisfies any of the given filters.
  4768. *
  4769. * @param queryConstraints - Optional. The list of
  4770. * {@link QueryFilterConstraint}s to perform a disjunction for. These must be
  4771. * created with calls to {@link where}, {@link or}, or {@link and}.
  4772. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  4773. * @internal TODO remove this internal tag with OR Query support in the server
  4774. */ function wr() {
  4775. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4776. // Only support QueryFilterConstraints
  4777. return t.forEach((function(t) {
  4778. return xr("or", t);
  4779. })), gr._create("or" /* CompositeOperator.OR */ , t)
  4780. /**
  4781. * Creates a new {@link QueryCompositeFilterConstraint} that is a conjunction of
  4782. * the given filter constraints. A conjunction filter includes a document if it
  4783. * satisfies all of the given filters.
  4784. *
  4785. * @param queryConstraints - Optional. The list of
  4786. * {@link QueryFilterConstraint}s to perform a conjunction for. These must be
  4787. * created with calls to {@link where}, {@link or}, or {@link and}.
  4788. * @returns The newly created {@link QueryCompositeFilterConstraint}.
  4789. * @internal TODO remove this internal tag with OR Query support in the server
  4790. */;
  4791. }
  4792. function _r() {
  4793. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4794. // Only support QueryFilterConstraints
  4795. return t.forEach((function(t) {
  4796. return xr("and", t);
  4797. })), gr._create("and" /* CompositeOperator.AND */ , t)
  4798. /**
  4799. * A `QueryOrderByConstraint` is used to sort the set of documents returned by a
  4800. * Firestore query. `QueryOrderByConstraint`s are created by invoking
  4801. * {@link orderBy} and can then be passed to {@link query} to create a new query
  4802. * instance that also contains this `QueryOrderByConstraint`.
  4803. *
  4804. * Note: Documents that do not contain the orderBy field will not be present in
  4805. * the query result.
  4806. */;
  4807. }
  4808. var br = /** @class */ function(e) {
  4809. /**
  4810. * @internal
  4811. */
  4812. function n(t, n) {
  4813. var r = this;
  4814. return (r = e.call(this) || this)._field = t, r._direction = n,
  4815. /** The type of this query constraint */
  4816. r.type = "orderBy", r;
  4817. }
  4818. return t(n, e), n._create = function(t, e) {
  4819. return new n(t, e);
  4820. }, n.prototype._apply = function(t) {
  4821. var e = function(t, e, n) {
  4822. if (null !== t.startAt) throw new B(P, "Invalid query. You must not call startAt() or startAfter() before calling orderBy().");
  4823. if (null !== t.endAt) throw new B(P, "Invalid query. You must not call endAt() or endBefore() before calling orderBy().");
  4824. var r = new oe(e, n);
  4825. return function(t, e) {
  4826. if (null === we(t)) {
  4827. // This is the first order by. It must match any inequality.
  4828. var n = _e(t);
  4829. null !== n && Cr(t, n, e.field);
  4830. }
  4831. }(t, r), r;
  4832. }(t._query, this._field, this._direction);
  4833. return new kn(t.firestore, t.converter, function(t, e) {
  4834. // TODO(dimond): validate that orderBy does not list the same key twice.
  4835. var n = t.explicitOrderBy.concat([ e ]);
  4836. return new ge(t.path, t.collectionGroup, n, t.filters.slice(), t.limit, t.limitType, t.startAt, t.endAt);
  4837. }(t._query, e));
  4838. }, n;
  4839. }(dr);
  4840. /**
  4841. * Creates a {@link QueryOrderByConstraint} that sorts the query result by the
  4842. * specified field, optionally in descending order instead of ascending.
  4843. *
  4844. * Note: Documents that do not contain the specified field will not be present
  4845. * in the query result.
  4846. *
  4847. * @param fieldPath - The field to sort by.
  4848. * @param directionStr - Optional direction to sort by ('asc' or 'desc'). If
  4849. * not specified, order will be ascending.
  4850. * @returns The created {@link QueryOrderByConstraint}.
  4851. */ function Tr(t, e) {
  4852. void 0 === e && (e = "asc");
  4853. var n = e, r = hr("orderBy", t);
  4854. return br._create(r, n);
  4855. }
  4856. /**
  4857. * A `QueryLimitConstraint` is used to limit the number of documents returned by
  4858. * a Firestore query.
  4859. * `QueryLimitConstraint`s are created by invoking {@link limit} or
  4860. * {@link limitToLast} and can then be passed to {@link query} to create a new
  4861. * query instance that also contains this `QueryLimitConstraint`.
  4862. */ var Er = /** @class */ function(e) {
  4863. /**
  4864. * @internal
  4865. */
  4866. function n(
  4867. /** The type of this query constraint */
  4868. t, n, r) {
  4869. var i = this;
  4870. return (i = e.call(this) || this).type = t, i._limit = n, i._limitType = r, i;
  4871. }
  4872. return t(n, e), n._create = function(t, e, r) {
  4873. return new n(t, e, r);
  4874. }, n.prototype._apply = function(t) {
  4875. return new kn(t.firestore, t.converter, function(t, e, n) {
  4876. return new ge(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), e, n, t.startAt, t.endAt);
  4877. }(t._query, this._limit, this._limitType));
  4878. }, n;
  4879. }(dr);
  4880. /**
  4881. * Creates a {@link QueryLimitConstraint} that only returns the first matching
  4882. * documents.
  4883. *
  4884. * @param limit - The maximum number of items to return.
  4885. * @returns The created {@link QueryLimitConstraint}.
  4886. */ function kr(t) {
  4887. return lt("limit", t), Er._create("limit", t, "F" /* LimitType.First */)
  4888. /**
  4889. * Creates a {@link QueryLimitConstraint} that only returns the last matching
  4890. * documents.
  4891. *
  4892. * You must specify at least one `orderBy` clause for `limitToLast` queries,
  4893. * otherwise an exception will be thrown during execution.
  4894. *
  4895. * @param limit - The maximum number of items to return.
  4896. * @returns The created {@link QueryLimitConstraint}.
  4897. */;
  4898. }
  4899. function Sr(t) {
  4900. return lt("limitToLast", t), Er._create("limitToLast", t, "L" /* LimitType.Last */)
  4901. /**
  4902. * A `QueryStartAtConstraint` is used to exclude documents from the start of a
  4903. * result set returned by a Firestore query.
  4904. * `QueryStartAtConstraint`s are created by invoking {@link (startAt:1)} or
  4905. * {@link (startAfter:1)} and can then be passed to {@link query} to create a
  4906. * new query instance that also contains this `QueryStartAtConstraint`.
  4907. */;
  4908. }
  4909. var Ir = /** @class */ function(e) {
  4910. /**
  4911. * @internal
  4912. */
  4913. function n(
  4914. /** The type of this query constraint */
  4915. t, n, r) {
  4916. var i = this;
  4917. return (i = e.call(this) || this).type = t, i._docOrFields = n, i._inclusive = r,
  4918. i;
  4919. }
  4920. return t(n, e), n._create = function(t, e, r) {
  4921. return new n(t, e, r);
  4922. }, n.prototype._apply = function(t) {
  4923. var e = Or(t, this.type, this._docOrFields, this._inclusive);
  4924. return new kn(t.firestore, t.converter, function(t, e) {
  4925. return new ge(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, e, t.endAt);
  4926. }(t._query, e));
  4927. }, n;
  4928. }(dr);
  4929. function Ar() {
  4930. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4931. return Ir._create("startAt", t,
  4932. /*inclusive=*/ !0);
  4933. }
  4934. function Fr() {
  4935. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4936. return Ir._create("startAfter", t,
  4937. /*inclusive=*/ !1);
  4938. }
  4939. /**
  4940. * A `QueryEndAtConstraint` is used to exclude documents from the end of a
  4941. * result set returned by a Firestore query.
  4942. * `QueryEndAtConstraint`s are created by invoking {@link (endAt:1)} or
  4943. * {@link (endBefore:1)} and can then be passed to {@link query} to create a new
  4944. * query instance that also contains this `QueryEndAtConstraint`.
  4945. */ var Vr = /** @class */ function(e) {
  4946. /**
  4947. * @internal
  4948. */
  4949. function n(
  4950. /** The type of this query constraint */
  4951. t, n, r) {
  4952. var i = this;
  4953. return (i = e.call(this) || this).type = t, i._docOrFields = n, i._inclusive = r,
  4954. i;
  4955. }
  4956. return t(n, e), n._create = function(t, e, r) {
  4957. return new n(t, e, r);
  4958. }, n.prototype._apply = function(t) {
  4959. var e = Or(t, this.type, this._docOrFields, this._inclusive);
  4960. return new kn(t.firestore, t.converter, function(t, e) {
  4961. return new ge(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, t.startAt, e);
  4962. }(t._query, e));
  4963. }, n;
  4964. }(dr);
  4965. function Pr() {
  4966. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4967. return Vr._create("endBefore", t,
  4968. /*inclusive=*/ !1);
  4969. }
  4970. function Dr() {
  4971. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  4972. return Vr._create("endAt", t,
  4973. /*inclusive=*/ !0);
  4974. }
  4975. /** Helper function to create a bound from a document or fields */ function Or(t, e, n, r) {
  4976. if (n[0] = p(n[0]), n[0] instanceof sr) return function(t, e, n, r, i) {
  4977. if (!r) throw new B(O, "Can't use a DocumentSnapshot that doesn't exist for ".concat(n, "()."));
  4978. // Because people expect to continue/end a query at the exact document
  4979. // provided, we need to use the implicit sort order rather than the explicit
  4980. // sort order, because it's guaranteed to contain the document key. That way
  4981. // the position becomes unambiguous and the query continues/ends exactly at
  4982. // the provided document. Without the key (by using the explicit sort
  4983. // orders), multiple documents could match the position, yielding duplicate
  4984. // results.
  4985. for (var o = [], a = 0, u = Te(t); a < u.length; a++) {
  4986. var s = u[a];
  4987. if (s.field.isKeyField()) o.push(jt(e, r.key)); else {
  4988. var c = r.data.field(s.field);
  4989. if (Pt(c)) throw new B(P, 'Invalid query. You are trying to start or end a query using a document for which the field "' + s.field + '" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');
  4990. if (null === c) {
  4991. var l = s.field.canonicalString();
  4992. throw new B(P, "Invalid query. You are trying to start or end a query using a document for which the field '".concat(l, "' (used as the orderBy) does not exist."));
  4993. }
  4994. o.push(c);
  4995. }
  4996. }
  4997. return new zt(o, i);
  4998. }(t._query, t.firestore._databaseId, e, n[0]._document, r);
  4999. var i = Bn(t.firestore);
  5000. return function(t, e, n, r, i, o) {
  5001. // Use explicit order by's because it has to match the query the user made
  5002. var a = t.explicitOrderBy;
  5003. if (i.length > a.length) throw new B(P, "Too many arguments provided to ".concat(r, "(). The number of arguments must be less than or equal to the number of orderBy() clauses"));
  5004. for (var u = [], s = 0; s < i.length; s++) {
  5005. var c = i[s];
  5006. if (a[s].field.isKeyField()) {
  5007. if ("string" != typeof c) throw new B(P, "Invalid query. Expected a string for document ID in ".concat(r, "(), but got a ").concat(typeof c));
  5008. if (!be(t) && -1 !== c.indexOf("/")) throw new B(P, "Invalid query. When querying a collection and ordering by documentId(), the value passed to ".concat(r, "() must be a plain document ID, but '").concat(c, "' contains a slash."));
  5009. var l = t.path.child(et.fromString(c));
  5010. if (!it.isDocumentKey(l)) throw new B(P, "Invalid query. When querying a collection group and ordering by documentId(), the value passed to ".concat(r, "() must result in a valid document path, but '").concat(l, "' is not because it contains an odd number of segments."));
  5011. var f = new it(l);
  5012. u.push(jt(e, f));
  5013. } else {
  5014. var h = Zn(n, r, c);
  5015. u.push(h);
  5016. }
  5017. }
  5018. return new zt(u, o);
  5019. }(t._query, t.firestore._databaseId, i, e, n, r);
  5020. }
  5021. function Nr(t, e, n) {
  5022. if ("string" == typeof (n = p(n))) {
  5023. if ("" === n) throw new B(P, "Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");
  5024. if (!be(e) && -1 !== n.indexOf("/")) throw new B(P, "Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '".concat(n, "' contains a '/' character."));
  5025. var r = e.path.child(et.fromString(n));
  5026. if (!it.isDocumentKey(r)) throw new B(P, "Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '".concat(r, "' is not because it has an odd number of segments (").concat(r.length, ")."));
  5027. return jt(t, new it(r));
  5028. }
  5029. if (n instanceof En) return jt(t, n._key);
  5030. throw new B(P, "Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ".concat(st(n), "."));
  5031. }
  5032. /**
  5033. * Validates that the value passed into a disjunctive filter satisfies all
  5034. * array requirements.
  5035. */ function qr(t, e) {
  5036. if (!Array.isArray(t) || 0 === t.length) throw new B(P, "Invalid Query. A non-empty array is required for '".concat(e.toString(), "' filters."));
  5037. if (t.length > 10) throw new B(P, "Invalid Query. '".concat(e.toString(), "' filters support a maximum of 10 elements in the value array."));
  5038. }
  5039. /**
  5040. * Given an operator, returns the set of operators that cannot be used with it.
  5041. *
  5042. * Operators in a query must adhere to the following set of rules:
  5043. * 1. Only one array operator is allowed.
  5044. * 2. Only one disjunctive operator is allowed.
  5045. * 3. `NOT_EQUAL` cannot be used with another `NOT_EQUAL` operator.
  5046. * 4. `NOT_IN` cannot be used with array, disjunctive, or `NOT_EQUAL` operators.
  5047. *
  5048. * Array operators: `ARRAY_CONTAINS`, `ARRAY_CONTAINS_ANY`
  5049. * Disjunctive operators: `IN`, `ARRAY_CONTAINS_ANY`, `NOT_IN`
  5050. */ function Rr(t, e) {
  5051. if (e.isInequality()) {
  5052. var n = _e(t), r = e.field;
  5053. if (null !== n && !n.isEqual(r)) throw new B(P, "Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '".concat(n.toString(), "' and '").concat(r.toString(), "'"));
  5054. var i = we(t);
  5055. null !== i && Cr(t, r, i);
  5056. }
  5057. var o = function(t, e) {
  5058. for (var n = 0, r = t; n < r.length; n++) for (var i = 0, o = r[n].getFlattenedFilters(); i < o.length; i++) {
  5059. var a = o[i];
  5060. if (e.indexOf(a.op) >= 0) return a.op;
  5061. }
  5062. return null;
  5063. }(t.filters, function(t) {
  5064. switch (t) {
  5065. case "!=" /* Operator.NOT_EQUAL */ :
  5066. return [ "!=" /* Operator.NOT_EQUAL */ , "not-in" /* Operator.NOT_IN */ ];
  5067. case "array-contains" /* Operator.ARRAY_CONTAINS */ :
  5068. return [ "array-contains" /* Operator.ARRAY_CONTAINS */ , "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ , "not-in" /* Operator.NOT_IN */ ];
  5069. case "in" /* Operator.IN */ :
  5070. return [ "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ , "in" /* Operator.IN */ , "not-in" /* Operator.NOT_IN */ ];
  5071. case "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ :
  5072. return [ "array-contains" /* Operator.ARRAY_CONTAINS */ , "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ , "in" /* Operator.IN */ , "not-in" /* Operator.NOT_IN */ ];
  5073. case "not-in" /* Operator.NOT_IN */ :
  5074. return [ "array-contains" /* Operator.ARRAY_CONTAINS */ , "array-contains-any" /* Operator.ARRAY_CONTAINS_ANY */ , "in" /* Operator.IN */ , "not-in" /* Operator.NOT_IN */ , "!=" /* Operator.NOT_EQUAL */ ];
  5075. default:
  5076. return [];
  5077. }
  5078. }(e.op));
  5079. if (null !== o)
  5080. // Special case when it's a duplicate op to give a slightly clearer error message.
  5081. throw o === e.op ? new B(P, "Invalid query. You cannot use more than one '".concat(e.op.toString(), "' filter.")) : new B(P, "Invalid query. You cannot use '".concat(e.op.toString(), "' filters with '").concat(o.toString(), "' filters."));
  5082. }
  5083. function Cr(t, e, n) {
  5084. if (!n.isEqual(e)) throw new B(P, "Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '".concat(e.toString(), "' and so you must also use '").concat(e.toString(), "' as your first argument to orderBy(), but your first orderBy() is on field '").concat(n.toString(), "' instead."));
  5085. }
  5086. function xr(t, e) {
  5087. if (!(e instanceof mr || e instanceof gr)) throw new B(P, "Function ".concat(t, "() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'."));
  5088. }
  5089. /**
  5090. * @license
  5091. * Copyright 2020 Google LLC
  5092. *
  5093. * Licensed under the Apache License, Version 2.0 (the "License");
  5094. * you may not use this file except in compliance with the License.
  5095. * You may obtain a copy of the License at
  5096. *
  5097. * http://www.apache.org/licenses/LICENSE-2.0
  5098. *
  5099. * Unless required by applicable law or agreed to in writing, software
  5100. * distributed under the License is distributed on an "AS IS" BASIS,
  5101. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5102. * See the License for the specific language governing permissions and
  5103. * limitations under the License.
  5104. */
  5105. /**
  5106. * Converts custom model object of type T into `DocumentData` by applying the
  5107. * converter if it exists.
  5108. *
  5109. * This function is used when converting user objects to `DocumentData`
  5110. * because we want to provide the user with a more specific error message if
  5111. * their `set()` or fails due to invalid data originating from a `toFirestore()`
  5112. * call.
  5113. */ function Lr(t, e, n) {
  5114. // Cast to `any` in order to satisfy the union type constraint on
  5115. // toFirestore().
  5116. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  5117. return t ? n && (n.merge || n.mergeFields) ? t.toFirestore(e, n) : t.toFirestore(e) : e;
  5118. }
  5119. var jr = /** @class */ function(e) {
  5120. function n(t) {
  5121. var n = this;
  5122. return (n = e.call(this) || this).firestore = t, n;
  5123. }
  5124. return t(n, e), n.prototype.convertBytes = function(t) {
  5125. return new Dn(t);
  5126. }, n.prototype.convertReference = function(t) {
  5127. var e = this.convertDocumentKey(t, this.firestore._databaseId);
  5128. return new En(this.firestore, /* converter= */ null, e);
  5129. }, n;
  5130. }(/** @class */ function() {
  5131. function t() {}
  5132. return t.prototype.convertValue = function(t, e) {
  5133. switch (void 0 === e && (e = "none"), qt(t)) {
  5134. case 0 /* TypeOrder.NullValue */ :
  5135. return null;
  5136. case 1 /* TypeOrder.BooleanValue */ :
  5137. return t.booleanValue;
  5138. case 2 /* TypeOrder.NumberValue */ :
  5139. return At(t.integerValue || t.doubleValue);
  5140. case 3 /* TypeOrder.TimestampValue */ :
  5141. return this.convertTimestamp(t.timestampValue);
  5142. case 4 /* TypeOrder.ServerTimestampValue */ :
  5143. return this.convertServerTimestamp(t, e);
  5144. case 5 /* TypeOrder.StringValue */ :
  5145. return t.stringValue;
  5146. case 6 /* TypeOrder.BlobValue */ :
  5147. return this.convertBytes(Ft(t.bytesValue));
  5148. case 7 /* TypeOrder.RefValue */ :
  5149. return this.convertReference(t.referenceValue);
  5150. case 8 /* TypeOrder.GeoPointValue */ :
  5151. return this.convertGeoPoint(t.geoPointValue);
  5152. case 9 /* TypeOrder.ArrayValue */ :
  5153. return this.convertArray(t.arrayValue, e);
  5154. case 10 /* TypeOrder.ObjectValue */ :
  5155. return this.convertObject(t.mapValue, e);
  5156. default:
  5157. throw S();
  5158. }
  5159. }, t.prototype.convertObject = function(t, e) {
  5160. var n = this, r = {};
  5161. return Et(t.fields, (function(t, i) {
  5162. r[t] = n.convertValue(i, e);
  5163. })), r;
  5164. }, t.prototype.convertGeoPoint = function(t) {
  5165. return new Rn(At(t.latitude), At(t.longitude));
  5166. }, t.prototype.convertArray = function(t, e) {
  5167. var n = this;
  5168. return (t.values || []).map((function(t) {
  5169. return n.convertValue(t, e);
  5170. }));
  5171. }, t.prototype.convertServerTimestamp = function(t, e) {
  5172. switch (e) {
  5173. case "previous":
  5174. var n = Dt(t);
  5175. return null == n ? null : this.convertValue(n, e);
  5176. case "estimate":
  5177. return this.convertTimestamp(Ot(t));
  5178. default:
  5179. return null;
  5180. }
  5181. }, t.prototype.convertTimestamp = function(t) {
  5182. var e = It(t);
  5183. return new Vt(e.seconds, e.nanos);
  5184. }, t.prototype.convertDocumentKey = function(t, e) {
  5185. var n = et.fromString(t);
  5186. I(an(n));
  5187. var r = new $(n.get(1), n.get(3)), i = new it(n.popFirst(5));
  5188. return r.isEqual(e) ||
  5189. // TODO(b/64130202): Somehow support foreign references.
  5190. T("Document ".concat(i, " contains a document reference within a different database (").concat(r.projectId, "/").concat(r.database, ") which is not supported. It will be treated as a reference in the current database (").concat(e.projectId, "/").concat(e.database, ") instead.")),
  5191. i;
  5192. }, t;
  5193. }());
  5194. /**
  5195. * Reads the document referred to by the specified document reference.
  5196. *
  5197. * All documents are directly fetched from the server, even if the document was
  5198. * previously read or modified. Recent modifications are only reflected in the
  5199. * retrieved `DocumentSnapshot` if they have already been applied by the
  5200. * backend. If the client is offline, the read fails. If you like to use
  5201. * caching or see local modifications, please use the full Firestore SDK.
  5202. *
  5203. * @param reference - The reference of the document to fetch.
  5204. * @returns A Promise resolved with a `DocumentSnapshot` containing the current
  5205. * document contents.
  5206. */ function Mr(t) {
  5207. var e = pn((t = ct(t, En)).firestore), n = new jr(t.firestore);
  5208. return fn(e, [ t._key ]).then((function(e) {
  5209. I(1 === e.length);
  5210. var r = e[0];
  5211. return new sr(t.firestore, n, t._key, r.isFoundDocument() ? r : null, t.converter);
  5212. }));
  5213. }
  5214. /**
  5215. * Executes the query and returns the results as a {@link QuerySnapshot}.
  5216. *
  5217. * All queries are executed directly by the server, even if the the query was
  5218. * previously executed. Recent modifications are only reflected in the retrieved
  5219. * results if they have already been applied by the backend. If the client is
  5220. * offline, the operation fails. To see previously cached result and local
  5221. * modifications, use the full Firestore SDK.
  5222. *
  5223. * @param query - The `Query` to execute.
  5224. * @returns A Promise that will be resolved with the results of the query.
  5225. */ function Ur(t) {
  5226. !function(t) {
  5227. if ("L" /* LimitType.Last */ === t.limitType && 0 === t.explicitOrderBy.length) throw new B(j, "limitToLast() queries require specifying at least one orderBy() clause");
  5228. }((t = ct(t, kn))._query);
  5229. var r = pn(t.firestore), i = new jr(t.firestore);
  5230. return function(t, r) {
  5231. return e(this, void 0, void 0, (function() {
  5232. var e, i;
  5233. return n(this, (function(n) {
  5234. switch (n.label) {
  5235. case 0:
  5236. return e = A(t), i = Ze(e.C, Ee(r)), [ 4 /*yield*/ , e.P("RunQuery", i.parent, {
  5237. structuredQuery: i.structuredQuery
  5238. }) ];
  5239. case 1:
  5240. return [ 2 /*return*/ , n.sent().filter((function(t) {
  5241. return !!t.document;
  5242. })).map((function(t) {
  5243. return function(t, e, n) {
  5244. var r = He(t, e.name), i = ze(e.updateTime), o = e.createTime ? ze(e.createTime) : ue.min(), a = new de({
  5245. mapValue: {
  5246. fields: e.fields
  5247. }
  5248. });
  5249. return ye.newFoundDocument(r, i, o, a);
  5250. }(e.C, t.document);
  5251. })) ];
  5252. }
  5253. }));
  5254. }));
  5255. }(r, t._query).then((function(e) {
  5256. var n = e.map((function(e) {
  5257. return new cr(t.firestore, i, e.key, e, t.converter);
  5258. }));
  5259. return "L" /* LimitType.Last */ === t._query.limitType &&
  5260. // Limit to last queries reverse the orderBy constraint that was
  5261. // specified by the user. As such, we need to reverse the order of the
  5262. // results to return the documents in the expected order.
  5263. n.reverse(), new lr(t, n);
  5264. }));
  5265. }
  5266. function Br(t, e, n) {
  5267. var r = Lr((t = ct(t, En)).converter, e, n), i = Gn(Bn(t.firestore), "setDoc", t._key, r, null !== t.converter, n);
  5268. return ln(pn(t.firestore), [ i.toMutation(t._key, Oe.none()) ]);
  5269. }
  5270. function Gr(t, e, n) {
  5271. for (var r = [], i = 3; i < arguments.length; i++) r[i - 3] = arguments[i];
  5272. var o, a = Bn((t = ct(t, En)).firestore);
  5273. // For Compat types, we have to "extract" the underlying types before
  5274. // performing validation.
  5275. return o = "string" == typeof (e = p(e)) || e instanceof On ? Jn(a, "updateDoc", t._key, e, n, r) : Xn(a, "updateDoc", t._key, e),
  5276. ln(pn(t.firestore), [ o.toMutation(t._key, Oe.exists(!0)) ]);
  5277. }
  5278. /**
  5279. * Deletes the document referred to by the specified `DocumentReference`.
  5280. *
  5281. * The deletion will only be reflected in document reads that occur after the
  5282. * returned promise resolves. If the client is offline, the
  5283. * delete fails. If you would like to see local modifications or buffer writes
  5284. * until the client is online, use the full Firestore SDK.
  5285. *
  5286. * @param reference - A reference to the document to delete.
  5287. * @returns A `Promise` resolved once the document has been successfully
  5288. * deleted from the backend.
  5289. */ function Qr(t) {
  5290. return ln(pn((t = ct(t, En)).firestore), [ new Ce(t._key, Oe.none()) ]);
  5291. }
  5292. /**
  5293. * Add a new document to specified `CollectionReference` with the given data,
  5294. * assigning it a document ID automatically.
  5295. *
  5296. * The result of this write will only be reflected in document reads that occur
  5297. * after the returned promise resolves. If the client is offline, the
  5298. * write fails. If you would like to see local modifications or buffer writes
  5299. * until the client is online, use the full Firestore SDK.
  5300. *
  5301. * @param reference - A reference to the collection to add this document to.
  5302. * @param data - An Object containing the data for the new document.
  5303. * @throws Error - If the provided input is not a valid Firestore document.
  5304. * @returns A `Promise` resolved with a `DocumentReference` pointing to the
  5305. * newly created document after it has been written to the backend.
  5306. */ function zr(t, e) {
  5307. var n = Fn(t = ct(t, Sn)), r = Lr(t.converter, e), i = Gn(Bn(t.firestore), "addDoc", n._key, r, null !== n.converter, {});
  5308. return ln(pn(t.firestore), [ i.toMutation(n._key, Oe.exists(!1)) ]).then((function() {
  5309. return n;
  5310. }));
  5311. }
  5312. /**
  5313. * @license
  5314. * Copyright 2022 Google LLC
  5315. *
  5316. * Licensed under the Apache License, Version 2.0 (the "License");
  5317. * you may not use this file except in compliance with the License.
  5318. * You may obtain a copy of the License at
  5319. *
  5320. * http://www.apache.org/licenses/LICENSE-2.0
  5321. *
  5322. * Unless required by applicable law or agreed to in writing, software
  5323. * distributed under the License is distributed on an "AS IS" BASIS,
  5324. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5325. * See the License for the specific language governing permissions and
  5326. * limitations under the License.
  5327. */
  5328. /**
  5329. * Calculates the number of documents in the result set of the given query,
  5330. * without actually downloading the documents.
  5331. *
  5332. * Using this function to count the documents is efficient because only the
  5333. * final count, not the documents' data, is downloaded. This function can even
  5334. * count the documents if the result set would be prohibitively large to
  5335. * download entirely (e.g. thousands of documents).
  5336. *
  5337. * @param query - The query whose result set size to calculate.
  5338. * @returns A Promise that will be resolved with the count; the count can be
  5339. * retrieved from `snapshot.data().count`, where `snapshot` is the
  5340. * `AggregateQuerySnapshot` to which the returned Promise resolves.
  5341. */ function Kr(t) {
  5342. var e = ct(t.firestore, yn), n = pn(e), r = new jr(e);
  5343. return new Tn(t, n, r).run();
  5344. }
  5345. /**
  5346. * Compares two `AggregateQuerySnapshot` instances for equality.
  5347. *
  5348. * Two `AggregateQuerySnapshot` instances are considered "equal" if they have
  5349. * underlying queries that compare equal, and the same data.
  5350. *
  5351. * @param left - The first `AggregateQuerySnapshot` to compare.
  5352. * @param right - The second `AggregateQuerySnapshot` to compare.
  5353. *
  5354. * @returns `true` if the objects are "equal", as defined above, or `false`
  5355. * otherwise.
  5356. */ function Wr(t, e) {
  5357. return Pn(t.query, e.query) && m(t.data(), e.data());
  5358. }
  5359. /**
  5360. * @license
  5361. * Copyright 2020 Google LLC
  5362. *
  5363. * Licensed under the Apache License, Version 2.0 (the "License");
  5364. * you may not use this file except in compliance with the License.
  5365. * You may obtain a copy of the License at
  5366. *
  5367. * http://www.apache.org/licenses/LICENSE-2.0
  5368. *
  5369. * Unless required by applicable law or agreed to in writing, software
  5370. * distributed under the License is distributed on an "AS IS" BASIS,
  5371. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5372. * See the License for the specific language governing permissions and
  5373. * limitations under the License.
  5374. */
  5375. /**
  5376. * Returns a sentinel for use with {@link @firebase/firestore/lite#(updateDoc:1)} or
  5377. * {@link @firebase/firestore/lite#(setDoc:1)} with `{merge: true}` to mark a field for deletion.
  5378. */ function Hr() {
  5379. return new Qn("deleteField");
  5380. }
  5381. /**
  5382. * Returns a sentinel used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link @firebase/firestore/lite#(updateDoc:1)} to
  5383. * include a server-generated timestamp in the written data.
  5384. */ function Yr() {
  5385. return new Kn("serverTimestamp");
  5386. }
  5387. /**
  5388. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  5389. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to union the given elements with any array
  5390. * value that already exists on the server. Each specified element that doesn't
  5391. * already exist in the array will be added to the end. If the field being
  5392. * modified is not already an array it will be overwritten with an array
  5393. * containing exactly the specified elements.
  5394. *
  5395. * @param elements - The elements to union into the array.
  5396. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  5397. * `updateDoc()`.
  5398. */ function Xr() {
  5399. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  5400. // NOTE: We don't actually parse the data until it's used in set() or
  5401. // update() since we'd need the Firestore instance to do this.
  5402. return new Wn("arrayUnion", t);
  5403. }
  5404. /**
  5405. * Returns a special value that can be used with {@link (setDoc:1)} or {@link
  5406. * updateDoc:1} that tells the server to remove the given elements from any
  5407. * array value that already exists on the server. All instances of each element
  5408. * specified will be removed from the array. If the field being modified is not
  5409. * already an array it will be overwritten with an empty array.
  5410. *
  5411. * @param elements - The elements to remove from the array.
  5412. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  5413. * `updateDoc()`
  5414. */ function Jr() {
  5415. for (var t = [], e = 0; e < arguments.length; e++) t[e] = arguments[e];
  5416. // NOTE: We don't actually parse the data until it's used in set() or
  5417. // update() since we'd need the Firestore instance to do this.
  5418. return new Hn("arrayRemove", t);
  5419. }
  5420. /**
  5421. * Returns a special value that can be used with {@link @firebase/firestore/lite#(setDoc:1)} or {@link
  5422. * @firebase/firestore/lite#(updateDoc:1)} that tells the server to increment the field's current value by
  5423. * the given value.
  5424. *
  5425. * If either the operand or the current field value uses floating point
  5426. * precision, all arithmetic follows IEEE 754 semantics. If both values are
  5427. * integers, values outside of JavaScript's safe number range
  5428. * (`Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`) are also subject to
  5429. * precision loss. Furthermore, once processed by the Firestore backend, all
  5430. * integer operations are capped between -2^63 and 2^63-1.
  5431. *
  5432. * If the current field value is not of type `number`, or if the field does not
  5433. * yet exist, the transformation sets the field to the given value.
  5434. *
  5435. * @param n - The value to increment by.
  5436. * @returns The `FieldValue` sentinel for use in a call to `setDoc()` or
  5437. * `updateDoc()`
  5438. */ function Zr(t) {
  5439. return new Yn("increment", t);
  5440. }
  5441. /**
  5442. * @license
  5443. * Copyright 2020 Google LLC
  5444. *
  5445. * Licensed under the Apache License, Version 2.0 (the "License");
  5446. * you may not use this file except in compliance with the License.
  5447. * You may obtain a copy of the License at
  5448. *
  5449. * http://www.apache.org/licenses/LICENSE-2.0
  5450. *
  5451. * Unless required by applicable law or agreed to in writing, software
  5452. * distributed under the License is distributed on an "AS IS" BASIS,
  5453. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5454. * See the License for the specific language governing permissions and
  5455. * limitations under the License.
  5456. */
  5457. /**
  5458. * A write batch, used to perform multiple writes as a single atomic unit.
  5459. *
  5460. * A `WriteBatch` object can be acquired by calling {@link writeBatch}. It
  5461. * provides methods for adding writes to the write batch. None of the writes
  5462. * will be committed (or visible locally) until {@link WriteBatch.commit} is
  5463. * called.
  5464. */ var $r = /** @class */ function() {
  5465. /** @hideconstructor */
  5466. function t(t, e) {
  5467. this._firestore = t, this._commitHandler = e, this._mutations = [], this._committed = !1,
  5468. this._dataReader = Bn(t);
  5469. }
  5470. return t.prototype.set = function(t, e, n) {
  5471. this._verifyNotCommitted();
  5472. var r = ti(t, this._firestore), i = Lr(r.converter, e, n), o = Gn(this._dataReader, "WriteBatch.set", r._key, i, null !== r.converter, n);
  5473. return this._mutations.push(o.toMutation(r._key, Oe.none())), this;
  5474. }, t.prototype.update = function(t, e, n) {
  5475. for (var r = [], i = 3; i < arguments.length; i++) r[i - 3] = arguments[i];
  5476. this._verifyNotCommitted();
  5477. var o, a = ti(t, this._firestore);
  5478. // For Compat types, we have to "extract" the underlying types before
  5479. // performing validation.
  5480. return o = "string" == typeof (e = p(e)) || e instanceof On ? Jn(this._dataReader, "WriteBatch.update", a._key, e, n, r) : Xn(this._dataReader, "WriteBatch.update", a._key, e),
  5481. this._mutations.push(o.toMutation(a._key, Oe.exists(!0))), this;
  5482. },
  5483. /**
  5484. * Deletes the document referred to by the provided {@link DocumentReference}.
  5485. *
  5486. * @param documentRef - A reference to the document to be deleted.
  5487. * @returns This `WriteBatch` instance. Used for chaining method calls.
  5488. */
  5489. t.prototype.delete = function(t) {
  5490. this._verifyNotCommitted();
  5491. var e = ti(t, this._firestore);
  5492. return this._mutations = this._mutations.concat(new Ce(e._key, Oe.none())), this;
  5493. },
  5494. /**
  5495. * Commits all of the writes in this write batch as a single atomic unit.
  5496. *
  5497. * The result of these writes will only be reflected in document reads that
  5498. * occur after the returned promise resolves. If the client is offline, the
  5499. * write fails. If you would like to see local modifications or buffer writes
  5500. * until the client is online, use the full Firestore SDK.
  5501. *
  5502. * @returns A `Promise` resolved once all of the writes in the batch have been
  5503. * successfully written to the backend as an atomic unit (note that it won't
  5504. * resolve while you're offline).
  5505. */
  5506. t.prototype.commit = function() {
  5507. return this._verifyNotCommitted(), this._committed = !0, this._mutations.length > 0 ? this._commitHandler(this._mutations) : Promise.resolve();
  5508. }, t.prototype._verifyNotCommitted = function() {
  5509. if (this._committed) throw new B(C, "A write batch can no longer be used after commit() has been called.");
  5510. }, t;
  5511. }();
  5512. function ti(t, e) {
  5513. if ((t = p(t)).firestore !== e) throw new B(P, "Provided document reference is from a different Firestore instance.");
  5514. return t;
  5515. }
  5516. /**
  5517. * Creates a write batch, used for performing multiple writes as a single
  5518. * atomic operation. The maximum number of writes allowed in a single WriteBatch
  5519. * is 500.
  5520. *
  5521. * The result of these writes will only be reflected in document reads that
  5522. * occur after the returned promise resolves. If the client is offline, the
  5523. * write fails. If you would like to see local modifications or buffer writes
  5524. * until the client is online, use the full Firestore SDK.
  5525. *
  5526. * @returns A `WriteBatch` that can be used to atomically execute multiple
  5527. * writes.
  5528. */ function ei(t) {
  5529. var e = pn(t = ct(t, yn));
  5530. return new $r(t, (function(t) {
  5531. return ln(e, t);
  5532. }));
  5533. }
  5534. /**
  5535. * @license
  5536. * Copyright 2017 Google LLC
  5537. *
  5538. * Licensed under the Apache License, Version 2.0 (the "License");
  5539. * you may not use this file except in compliance with the License.
  5540. * You may obtain a copy of the License at
  5541. *
  5542. * http://www.apache.org/licenses/LICENSE-2.0
  5543. *
  5544. * Unless required by applicable law or agreed to in writing, software
  5545. * distributed under the License is distributed on an "AS IS" BASIS,
  5546. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5547. * See the License for the specific language governing permissions and
  5548. * limitations under the License.
  5549. */
  5550. /**
  5551. * Internal transaction object responsible for accumulating the mutations to
  5552. * perform and the base versions for any documents read.
  5553. */ var ni = /** @class */ function() {
  5554. function t(t) {
  5555. this.datastore = t,
  5556. // The version of each document that was read during this transaction.
  5557. this.readVersions = new Map, this.mutations = [], this.committed = !1,
  5558. /**
  5559. * A deferred usage error that occurred previously in this transaction that
  5560. * will cause the transaction to fail once it actually commits.
  5561. */
  5562. this.lastWriteError = null,
  5563. /**
  5564. * Set of documents that have been written in the transaction.
  5565. *
  5566. * When there's more than one write to the same key in a transaction, any
  5567. * writes after the first are handled differently.
  5568. */
  5569. this.writtenDocs = new Set;
  5570. }
  5571. return t.prototype.lookup = function(t) {
  5572. return e(this, void 0, void 0, (function() {
  5573. var e, r = this;
  5574. return n(this, (function(n) {
  5575. switch (n.label) {
  5576. case 0:
  5577. if (this.ensureCommitNotCalled(), this.mutations.length > 0) throw new B(P, "Firestore transactions require all reads to be executed before all writes.");
  5578. return [ 4 /*yield*/ , fn(this.datastore, t) ];
  5579. case 1:
  5580. return [ 2 /*return*/ , ((e = n.sent()).forEach((function(t) {
  5581. return r.recordVersion(t);
  5582. })), e) ];
  5583. }
  5584. }));
  5585. }));
  5586. }, t.prototype.set = function(t, e) {
  5587. this.write(e.toMutation(t, this.precondition(t))), this.writtenDocs.add(t.toString());
  5588. }, t.prototype.update = function(t, e) {
  5589. try {
  5590. this.write(e.toMutation(t, this.preconditionForUpdate(t)));
  5591. } catch (t) {
  5592. this.lastWriteError = t;
  5593. }
  5594. this.writtenDocs.add(t.toString());
  5595. }, t.prototype.delete = function(t) {
  5596. this.write(new Ce(t, this.precondition(t))), this.writtenDocs.add(t.toString());
  5597. }, t.prototype.commit = function() {
  5598. return e(this, void 0, void 0, (function() {
  5599. var t, e = this;
  5600. return n(this, (function(n) {
  5601. switch (n.label) {
  5602. case 0:
  5603. if (this.ensureCommitNotCalled(), this.lastWriteError) throw this.lastWriteError;
  5604. return t = this.readVersions,
  5605. // For each mutation, note that the doc was written.
  5606. this.mutations.forEach((function(e) {
  5607. t.delete(e.key.toString());
  5608. })),
  5609. // For each document that was read but not written to, we want to perform
  5610. // a `verify` operation.
  5611. t.forEach((function(t, n) {
  5612. var r = it.fromPath(n);
  5613. e.mutations.push(new xe(r, e.precondition(r)));
  5614. })), [ 4 /*yield*/ , ln(this.datastore, this.mutations) ];
  5615. case 1:
  5616. // For each mutation, note that the doc was written.
  5617. return n.sent(), this.committed = !0, [ 2 /*return*/ ];
  5618. }
  5619. }));
  5620. }));
  5621. }, t.prototype.recordVersion = function(t) {
  5622. var e;
  5623. if (t.isFoundDocument()) e = t.version; else {
  5624. if (!t.isNoDocument()) throw S();
  5625. // Represent a deleted doc using SnapshotVersion.min().
  5626. e = ue.min();
  5627. }
  5628. var n = this.readVersions.get(t.key.toString());
  5629. if (n) {
  5630. if (!e.isEqual(n))
  5631. // This transaction will fail no matter what.
  5632. throw new B(x, "Document version changed between two reads.");
  5633. } else this.readVersions.set(t.key.toString(), e);
  5634. },
  5635. /**
  5636. * Returns the version of this document when it was read in this transaction,
  5637. * as a precondition, or no precondition if it was not read.
  5638. */
  5639. t.prototype.precondition = function(t) {
  5640. var e = this.readVersions.get(t.toString());
  5641. return !this.writtenDocs.has(t.toString()) && e ? e.isEqual(ue.min()) ? Oe.exists(!1) : Oe.updateTime(e) : Oe.none();
  5642. },
  5643. /**
  5644. * Returns the precondition for a document if the operation is an update.
  5645. */
  5646. t.prototype.preconditionForUpdate = function(t) {
  5647. var e = this.readVersions.get(t.toString());
  5648. // The first time a document is written, we want to take into account the
  5649. // read time and existence
  5650. if (!this.writtenDocs.has(t.toString()) && e) {
  5651. if (e.isEqual(ue.min()))
  5652. // The document doesn't exist, so fail the transaction.
  5653. // This has to be validated locally because you can't send a
  5654. // precondition that a document does not exist without changing the
  5655. // semantics of the backend write to be an insert. This is the reverse
  5656. // of what we want, since we want to assert that the document doesn't
  5657. // exist but then send the update and have it fail. Since we can't
  5658. // express that to the backend, we have to validate locally.
  5659. // Note: this can change once we can send separate verify writes in the
  5660. // transaction.
  5661. throw new B(P, "Can't update a document that doesn't exist.");
  5662. // Document exists, base precondition on document update time.
  5663. return Oe.updateTime(e);
  5664. }
  5665. // Document was not read, so we just use the preconditions for a blind
  5666. // update.
  5667. return Oe.exists(!0);
  5668. }, t.prototype.write = function(t) {
  5669. this.ensureCommitNotCalled(), this.mutations.push(t);
  5670. }, t.prototype.ensureCommitNotCalled = function() {}, t;
  5671. }(), ri = {
  5672. maxAttempts: 5
  5673. }, ii = /** @class */ function() {
  5674. function t(t, e, n, r, i) {
  5675. this.asyncQueue = t, this.datastore = e, this.options = n, this.updateFunction = r,
  5676. this.deferred = i, this.yt = n.maxAttempts, this.gt = new sn(this.asyncQueue, "transaction_retry" /* TimerId.TransactionRetry */)
  5677. /** Runs the transaction and sets the result on deferred. */;
  5678. }
  5679. return t.prototype.run = function() {
  5680. this.yt -= 1, this._t();
  5681. }, t.prototype._t = function() {
  5682. var t = this;
  5683. this.gt.H((function() {
  5684. return e(t, void 0, void 0, (function() {
  5685. var t, e, r = this;
  5686. return n(this, (function(n) {
  5687. return t = new ni(this.datastore), (e = this.vt(t)) && e.then((function(e) {
  5688. r.asyncQueue.enqueueAndForget((function() {
  5689. return t.commit().then((function() {
  5690. r.deferred.resolve(e);
  5691. })).catch((function(t) {
  5692. r.bt(t);
  5693. }));
  5694. }));
  5695. })).catch((function(t) {
  5696. r.bt(t);
  5697. })), [ 2 /*return*/ ];
  5698. }));
  5699. }));
  5700. }));
  5701. }, t.prototype.vt = function(t) {
  5702. try {
  5703. var e = this.updateFunction(t);
  5704. return !ft(e) && e.catch && e.then ? e : (this.deferred.reject(Error("Transaction callback must return a Promise")),
  5705. null);
  5706. } catch (t) {
  5707. // Do not retry errors thrown by user provided updateFunction.
  5708. return this.deferred.reject(t), null;
  5709. }
  5710. }, t.prototype.bt = function(t) {
  5711. var e = this;
  5712. this.yt > 0 && this.Et(t) ? (this.yt -= 1, this.asyncQueue.enqueueAndForget((function() {
  5713. return e._t(), Promise.resolve();
  5714. }))) : this.deferred.reject(t);
  5715. }, t.prototype.Et = function(t) {
  5716. if ("FirebaseError" === t.name) {
  5717. // In transactions, the backend will fail outdated reads with FAILED_PRECONDITION and
  5718. // non-matching document versions with ABORTED. These errors should be retried.
  5719. var e = t.code;
  5720. return "aborted" === e || "failed-precondition" === e || "already-exists" === e || !
  5721. /**
  5722. * Determines whether an error code represents a permanent error when received
  5723. * in response to a non-write operation.
  5724. *
  5725. * See isPermanentWriteError for classifying write errors.
  5726. */
  5727. function(t) {
  5728. switch (t) {
  5729. default:
  5730. return S();
  5731. case F:
  5732. case V:
  5733. case D:
  5734. case R:
  5735. case M:
  5736. case U:
  5737. // Unauthenticated means something went wrong with our token and we need
  5738. // to retry with new credentials which will happen automatically.
  5739. case q:
  5740. return !1;
  5741. case P:
  5742. case O:
  5743. case "already-exists":
  5744. case N:
  5745. case C:
  5746. // Aborted might be retried in some scenarios, but that is dependant on
  5747. // the context and should handled individually by the calling code.
  5748. // See https://cloud.google.com/apis/design/errors.
  5749. case x:
  5750. case L:
  5751. case j:
  5752. case "data-loss":
  5753. return !0;
  5754. }
  5755. }(e);
  5756. }
  5757. return !1;
  5758. }, t;
  5759. }();
  5760. /**
  5761. * @license
  5762. * Copyright 2022 Google LLC
  5763. *
  5764. * Licensed under the Apache License, Version 2.0 (the "License");
  5765. * you may not use this file except in compliance with the License.
  5766. * You may obtain a copy of the License at
  5767. *
  5768. * http://www.apache.org/licenses/LICENSE-2.0
  5769. *
  5770. * Unless required by applicable law or agreed to in writing, software
  5771. * distributed under the License is distributed on an "AS IS" BASIS,
  5772. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5773. * See the License for the specific language governing permissions and
  5774. * limitations under the License.
  5775. */
  5776. /**
  5777. * @license
  5778. * Copyright 2020 Google LLC
  5779. *
  5780. * Licensed under the Apache License, Version 2.0 (the "License");
  5781. * you may not use this file except in compliance with the License.
  5782. * You may obtain a copy of the License at
  5783. *
  5784. * http://www.apache.org/licenses/LICENSE-2.0
  5785. *
  5786. * Unless required by applicable law or agreed to in writing, software
  5787. * distributed under the License is distributed on an "AS IS" BASIS,
  5788. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5789. * See the License for the specific language governing permissions and
  5790. * limitations under the License.
  5791. */
  5792. /** The Platform's 'document' implementation or null if not available. */ function oi() {
  5793. // `document` is not always available, e.g. in ReactNative and WebWorkers.
  5794. // eslint-disable-next-line no-restricted-globals
  5795. return "undefined" != typeof document ? document : null;
  5796. }
  5797. /**
  5798. * @license
  5799. * Copyright 2017 Google LLC
  5800. *
  5801. * Licensed under the Apache License, Version 2.0 (the "License");
  5802. * you may not use this file except in compliance with the License.
  5803. * You may obtain a copy of the License at
  5804. *
  5805. * http://www.apache.org/licenses/LICENSE-2.0
  5806. *
  5807. * Unless required by applicable law or agreed to in writing, software
  5808. * distributed under the License is distributed on an "AS IS" BASIS,
  5809. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  5810. * See the License for the specific language governing permissions and
  5811. * limitations under the License.
  5812. */
  5813. /**
  5814. * Represents an operation scheduled to be run in the future on an AsyncQueue.
  5815. *
  5816. * It is created via DelayedOperation.createAndSchedule().
  5817. *
  5818. * Supports cancellation (via cancel()) and early execution (via skipDelay()).
  5819. *
  5820. * Note: We implement `PromiseLike` instead of `Promise`, as the `Promise` type
  5821. * in newer versions of TypeScript defines `finally`, which is not available in
  5822. * IE.
  5823. */ var ai, ui = /** @class */ function() {
  5824. function t(t, e, n, r, i) {
  5825. this.asyncQueue = t, this.timerId = e, this.targetTimeMs = n, this.op = r, this.removalCallback = i,
  5826. this.deferred = new G, this.then = this.deferred.promise.then.bind(this.deferred.promise),
  5827. // It's normal for the deferred promise to be canceled (due to cancellation)
  5828. // and so we attach a dummy catch callback to avoid
  5829. // 'UnhandledPromiseRejectionWarning' log spam.
  5830. this.deferred.promise.catch((function(t) {}))
  5831. /**
  5832. * Creates and returns a DelayedOperation that has been scheduled to be
  5833. * executed on the provided asyncQueue after the provided delayMs.
  5834. *
  5835. * @param asyncQueue - The queue to schedule the operation on.
  5836. * @param id - A Timer ID identifying the type of operation this is.
  5837. * @param delayMs - The delay (ms) before the operation should be scheduled.
  5838. * @param op - The operation to run.
  5839. * @param removalCallback - A callback to be called synchronously once the
  5840. * operation is executed or canceled, notifying the AsyncQueue to remove it
  5841. * from its delayedOperations list.
  5842. * PORTING NOTE: This exists to prevent making removeDelayedOperation() and
  5843. * the DelayedOperation class public.
  5844. */;
  5845. }
  5846. return t.createAndSchedule = function(e, n, r, i, o) {
  5847. var a = new t(e, n, Date.now() + r, i, o);
  5848. return a.start(r), a;
  5849. },
  5850. /**
  5851. * Starts the timer. This is called immediately after construction by
  5852. * createAndSchedule().
  5853. */
  5854. t.prototype.start = function(t) {
  5855. var e = this;
  5856. this.timerHandle = setTimeout((function() {
  5857. return e.handleDelayElapsed();
  5858. }), t);
  5859. },
  5860. /**
  5861. * Queues the operation to run immediately (if it hasn't already been run or
  5862. * canceled).
  5863. */
  5864. t.prototype.skipDelay = function() {
  5865. return this.handleDelayElapsed();
  5866. },
  5867. /**
  5868. * Cancels the operation if it hasn't already been executed or canceled. The
  5869. * promise will be rejected.
  5870. *
  5871. * As long as the operation has not yet been run, calling cancel() provides a
  5872. * guarantee that the operation will not be run.
  5873. */
  5874. t.prototype.cancel = function(t) {
  5875. null !== this.timerHandle && (this.clearTimeout(), this.deferred.reject(new B(F, "Operation cancelled" + (t ? ": " + t : ""))));
  5876. }, t.prototype.handleDelayElapsed = function() {
  5877. var t = this;
  5878. this.asyncQueue.enqueueAndForget((function() {
  5879. return null !== t.timerHandle ? (t.clearTimeout(), t.op().then((function(e) {
  5880. return t.deferred.resolve(e);
  5881. }))) : Promise.resolve();
  5882. }));
  5883. }, t.prototype.clearTimeout = function() {
  5884. null !== this.timerHandle && (this.removalCallback(this), clearTimeout(this.timerHandle),
  5885. this.timerHandle = null);
  5886. }, t;
  5887. }(), si = /** @class */ function() {
  5888. function t() {
  5889. var t = this;
  5890. // The last promise in the queue.
  5891. this.It = Promise.resolve(),
  5892. // A list of retryable operations. Retryable operations are run in order and
  5893. // retried with backoff.
  5894. this.Tt = [],
  5895. // Is this AsyncQueue being shut down? Once it is set to true, it will not
  5896. // be changed again.
  5897. this.At = !1,
  5898. // Operations scheduled to be queued in the future. Operations are
  5899. // automatically removed after they are run or canceled.
  5900. this.Rt = [],
  5901. // visible for testing
  5902. this.Pt = null,
  5903. // Flag set while there's an outstanding AsyncQueue operation, used for
  5904. // assertion sanity-checks.
  5905. this.Vt = !1,
  5906. // Enabled during shutdown on Safari to prevent future access to IndexedDB.
  5907. this.$t = !1,
  5908. // List of TimerIds to fast-forward delays for.
  5909. this.Nt = [],
  5910. // Backoff timer used to schedule retries for retryable operations
  5911. this.gt = new sn(this, "async_queue_retry" /* TimerId.AsyncQueueRetry */),
  5912. // Visibility handler that triggers an immediate retry of all retryable
  5913. // operations. Meant to speed up recovery when we regain file system access
  5914. // after page comes into foreground.
  5915. this.Dt = function() {
  5916. var e = oi();
  5917. e && b("AsyncQueue", "Visibility state changed to " + e.visibilityState), t.gt.X();
  5918. };
  5919. var e = oi();
  5920. e && "function" == typeof e.addEventListener && e.addEventListener("visibilitychange", this.Dt);
  5921. }
  5922. return Object.defineProperty(t.prototype, "isShuttingDown", {
  5923. get: function() {
  5924. return this.At;
  5925. },
  5926. enumerable: !1,
  5927. configurable: !0
  5928. }),
  5929. /**
  5930. * Adds a new operation to the queue without waiting for it to complete (i.e.
  5931. * we ignore the Promise result).
  5932. */
  5933. t.prototype.enqueueAndForget = function(t) {
  5934. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  5935. this.enqueue(t);
  5936. }, t.prototype.enqueueAndForgetEvenWhileRestricted = function(t) {
  5937. this.Ft(),
  5938. // eslint-disable-next-line @typescript-eslint/no-floating-promises
  5939. this.xt(t);
  5940. }, t.prototype.enterRestrictedMode = function(t) {
  5941. if (!this.At) {
  5942. this.At = !0, this.$t = t || !1;
  5943. var e = oi();
  5944. e && "function" == typeof e.removeEventListener && e.removeEventListener("visibilitychange", this.Dt);
  5945. }
  5946. }, t.prototype.enqueue = function(t) {
  5947. var e = this;
  5948. if (this.Ft(), this.At)
  5949. // Return a Promise which never resolves.
  5950. return new Promise((function() {}));
  5951. // Create a deferred Promise that we can return to the callee. This
  5952. // allows us to return a "hanging Promise" only to the callee and still
  5953. // advance the queue even when the operation is not run.
  5954. var n = new G;
  5955. return this.xt((function() {
  5956. return e.At && e.$t ? Promise.resolve() : (t().then(n.resolve, n.reject), n.promise);
  5957. })).then((function() {
  5958. return n.promise;
  5959. }));
  5960. }, t.prototype.enqueueRetryable = function(t) {
  5961. var e = this;
  5962. this.enqueueAndForget((function() {
  5963. return e.Tt.push(t), e.St();
  5964. }));
  5965. },
  5966. /**
  5967. * Runs the next operation from the retryable queue. If the operation fails,
  5968. * reschedules with backoff.
  5969. */
  5970. t.prototype.St = function() {
  5971. return e(this, void 0, void 0, (function() {
  5972. var t, e = this;
  5973. return n(this, (function(n) {
  5974. switch (n.label) {
  5975. case 0:
  5976. if (0 === this.Tt.length) return [ 3 /*break*/ , 5 ];
  5977. n.label = 1;
  5978. case 1:
  5979. return n.trys.push([ 1, 3, , 4 ]), [ 4 /*yield*/ , this.Tt[0]() ];
  5980. case 2:
  5981. return n.sent(), this.Tt.shift(), this.gt.reset(), [ 3 /*break*/ , 4 ];
  5982. case 3:
  5983. if (t = n.sent(), "IndexedDbTransactionError" !== t.name) throw t;
  5984. // Failure will be handled by AsyncQueue
  5985. return b("AsyncQueue", "Operation failed with retryable error: " + t),
  5986. [ 3 /*break*/ , 4 ];
  5987. case 4:
  5988. this.Tt.length > 0 &&
  5989. // If there are additional operations, we re-schedule `retryNextOp()`.
  5990. // This is necessary to run retryable operations that failed during
  5991. // their initial attempt since we don't know whether they are already
  5992. // enqueued. If, for example, `op1`, `op2`, `op3` are enqueued and `op1`
  5993. // needs to be re-run, we will run `op1`, `op1`, `op2` using the
  5994. // already enqueued calls to `retryNextOp()`. `op3()` will then run in the
  5995. // call scheduled here.
  5996. // Since `backoffAndRun()` cancels an existing backoff and schedules a
  5997. // new backoff on every call, there is only ever a single additional
  5998. // operation in the queue.
  5999. this.gt.H((function() {
  6000. return e.St();
  6001. })), n.label = 5;
  6002. case 5:
  6003. return [ 2 /*return*/ ];
  6004. }
  6005. }));
  6006. }));
  6007. }, t.prototype.xt = function(t) {
  6008. var e = this, n = this.It.then((function() {
  6009. return e.Vt = !0, t().catch((function(t) {
  6010. e.Pt = t, e.Vt = !1;
  6011. var n =
  6012. /**
  6013. * Chrome includes Error.message in Error.stack. Other browsers do not.
  6014. * This returns expected output of message + stack when available.
  6015. * @param error - Error or FirestoreError
  6016. */
  6017. function(t) {
  6018. var e = t.message || "";
  6019. return t.stack && (e = t.stack.includes(t.message) ? t.stack : t.message + "\n" + t.stack),
  6020. e;
  6021. }(t);
  6022. // Re-throw the error so that this.tail becomes a rejected Promise and
  6023. // all further attempts to chain (via .then) will just short-circuit
  6024. // and return the rejected Promise.
  6025. throw T("INTERNAL UNHANDLED ERROR: ", n), t;
  6026. })).then((function(t) {
  6027. return e.Vt = !1, t;
  6028. }));
  6029. }));
  6030. return this.It = n, n;
  6031. }, t.prototype.enqueueAfterDelay = function(t, e, n) {
  6032. var r = this;
  6033. this.Ft(),
  6034. // Fast-forward delays for timerIds that have been overriden.
  6035. this.Nt.indexOf(t) > -1 && (e = 0);
  6036. var i = ui.createAndSchedule(this, t, e, n, (function(t) {
  6037. return r.qt(t);
  6038. }));
  6039. return this.Rt.push(i), i;
  6040. }, t.prototype.Ft = function() {
  6041. this.Pt && S();
  6042. }, t.prototype.verifyOperationInProgress = function() {},
  6043. /**
  6044. * Waits until all currently queued tasks are finished executing. Delayed
  6045. * operations are not run.
  6046. */
  6047. t.prototype.Ot = function() {
  6048. return e(this, void 0, void 0, (function() {
  6049. var t;
  6050. return n(this, (function(e) {
  6051. switch (e.label) {
  6052. case 0:
  6053. return [ 4 /*yield*/ , t = this.It ];
  6054. case 1:
  6055. e.sent(), e.label = 2;
  6056. case 2:
  6057. if (t !== this.It) return [ 3 /*break*/ , 0 ];
  6058. e.label = 3;
  6059. case 3:
  6060. return [ 2 /*return*/ ];
  6061. }
  6062. }));
  6063. }));
  6064. },
  6065. /**
  6066. * For Tests: Determine if a delayed operation with a particular TimerId
  6067. * exists.
  6068. */
  6069. t.prototype.kt = function(t) {
  6070. for (var e = 0, n = this.Rt; e < n.length; e++) {
  6071. if (n[e].timerId === t) return !0;
  6072. }
  6073. return !1;
  6074. },
  6075. /**
  6076. * For Tests: Runs some or all delayed operations early.
  6077. *
  6078. * @param lastTimerId - Delayed operations up to and including this TimerId
  6079. * will be drained. Pass TimerId.All to run all delayed operations.
  6080. * @returns a Promise that resolves once all operations have been run.
  6081. */
  6082. t.prototype.Ct = function(t) {
  6083. var e = this;
  6084. // Note that draining may generate more delayed ops, so we do that first.
  6085. return this.Ot().then((function() {
  6086. // Run ops in the same order they'd run if they ran naturally.
  6087. e.Rt.sort((function(t, e) {
  6088. return t.targetTimeMs - e.targetTimeMs;
  6089. }));
  6090. for (var n = 0, r = e.Rt; n < r.length; n++) {
  6091. var i = r[n];
  6092. if (i.skipDelay(), "all" /* TimerId.All */ !== t && i.timerId === t) break;
  6093. }
  6094. return e.Ot();
  6095. }));
  6096. },
  6097. /**
  6098. * For Tests: Skip all subsequent delays for a timer id.
  6099. */
  6100. t.prototype.Lt = function(t) {
  6101. this.Nt.push(t);
  6102. },
  6103. /** Called once a DelayedOperation is run or canceled. */ t.prototype.qt = function(t) {
  6104. // NOTE: indexOf / slice are O(n), but delayedOperations is expected to be small.
  6105. var e = this.Rt.indexOf(t);
  6106. this.Rt.splice(e, 1);
  6107. }, t;
  6108. }(), ci = /** @class */ function() {
  6109. /** @hideconstructor */
  6110. function t(t, e) {
  6111. this._firestore = t, this._transaction = e, this._dataReader = Bn(t)
  6112. /**
  6113. * Reads the document referenced by the provided {@link DocumentReference}.
  6114. *
  6115. * @param documentRef - A reference to the document to be read.
  6116. * @returns A `DocumentSnapshot` with the read data.
  6117. */;
  6118. }
  6119. return t.prototype.get = function(t) {
  6120. var e = this, n = ti(t, this._firestore), r = new jr(this._firestore);
  6121. return this._transaction.lookup([ n._key ]).then((function(t) {
  6122. if (!t || 1 !== t.length) return S();
  6123. var i = t[0];
  6124. if (i.isFoundDocument()) return new sr(e._firestore, r, i.key, i, n.converter);
  6125. if (i.isNoDocument()) return new sr(e._firestore, r, n._key, null, n.converter);
  6126. throw S();
  6127. }));
  6128. }, t.prototype.set = function(t, e, n) {
  6129. var r = ti(t, this._firestore), i = Lr(r.converter, e, n), o = Gn(this._dataReader, "Transaction.set", r._key, i, null !== r.converter, n);
  6130. return this._transaction.set(r._key, o), this;
  6131. }, t.prototype.update = function(t, e, n) {
  6132. for (var r = [], i = 3; i < arguments.length; i++) r[i - 3] = arguments[i];
  6133. var o, a = ti(t, this._firestore);
  6134. // For Compat types, we have to "extract" the underlying types before
  6135. // performing validation.
  6136. return o = "string" == typeof (e = p(e)) || e instanceof On ? Jn(this._dataReader, "Transaction.update", a._key, e, n, r) : Xn(this._dataReader, "Transaction.update", a._key, e),
  6137. this._transaction.update(a._key, o), this;
  6138. },
  6139. /**
  6140. * Deletes the document referred to by the provided {@link DocumentReference}.
  6141. *
  6142. * @param documentRef - A reference to the document to be deleted.
  6143. * @returns This `Transaction` instance. Used for chaining method calls.
  6144. */
  6145. t.prototype.delete = function(t) {
  6146. var e = ti(t, this._firestore);
  6147. return this._transaction.delete(e._key), this;
  6148. }, t;
  6149. }();
  6150. /**
  6151. * @license
  6152. * Copyright 2020 Google LLC
  6153. *
  6154. * Licensed under the Apache License, Version 2.0 (the "License");
  6155. * you may not use this file except in compliance with the License.
  6156. * You may obtain a copy of the License at
  6157. *
  6158. * http://www.apache.org/licenses/LICENSE-2.0
  6159. *
  6160. * Unless required by applicable law or agreed to in writing, software
  6161. * distributed under the License is distributed on an "AS IS" BASIS,
  6162. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  6163. * See the License for the specific language governing permissions and
  6164. * limitations under the License.
  6165. */
  6166. /**
  6167. * Executes the given `updateFunction` and then attempts to commit the changes
  6168. * applied within the transaction. If any document read within the transaction
  6169. * has changed, Cloud Firestore retries the `updateFunction`. If it fails to
  6170. * commit after 5 attempts, the transaction fails.
  6171. *
  6172. * The maximum number of writes allowed in a single transaction is 500.
  6173. *
  6174. * @param firestore - A reference to the Firestore database to run this
  6175. * transaction against.
  6176. * @param updateFunction - The function to execute within the transaction
  6177. * context.
  6178. * @param options - An options object to configure maximum number of attempts to
  6179. * commit.
  6180. * @returns If the transaction completed successfully or was explicitly aborted
  6181. * (the `updateFunction` returned a failed promise), the promise returned by the
  6182. * `updateFunction `is returned here. Otherwise, if the transaction failed, a
  6183. * rejected promise with the corresponding failure error is returned.
  6184. */
  6185. function li(t, e, n) {
  6186. var r = pn(t = ct(t, yn)), i = Object.assign(Object.assign({}, ri), n);
  6187. !function(t) {
  6188. if (t.maxAttempts < 1) throw new B(P, "Max attempts must be at least 1");
  6189. }(i);
  6190. var o = new G;
  6191. return new ii(new si, r, i, (function(n) {
  6192. return e(new ci(t, n));
  6193. }), o).run(), o.promise
  6194. /**
  6195. * Firestore Lite
  6196. *
  6197. * @remarks Firestore Lite is a small online-only SDK that allows read
  6198. * and write access to your Firestore database. All operations connect
  6199. * directly to the backend, and `onSnapshot()` APIs are not supported.
  6200. * @packageDocumentation
  6201. */;
  6202. }
  6203. ai = "".concat(i, "_lite"), g = ai, o(new c("firestore/lite", (function(t, e) {
  6204. var n = e.instanceIdentifier, r = e.options, i = t.getProvider("app").getImmediate(), o = new yn(new W(t.getProvider("auth-internal")), new J(t.getProvider("app-check-internal")), function(t, e) {
  6205. if (!Object.prototype.hasOwnProperty.apply(t.options, [ "projectId" ])) throw new B(P, '"projectId" not provided in firebase.initializeApp.');
  6206. return new $(t.options.projectId, e);
  6207. }(i, n), i);
  6208. return r && o._setSettings(r), o;
  6209. }), "PUBLIC").setMultipleInstances(!0)),
  6210. // RUNTIME_ENV and BUILD_TARGET are replaced by real values during the compilation
  6211. a("firestore-lite", "3.8.1", ""), a("firestore-lite", "3.8.1", "esm5");
  6212. export { _n as AggregateField, bn as AggregateQuerySnapshot, Dn as Bytes, Sn as CollectionReference, En as DocumentReference, sr as DocumentSnapshot, On as FieldPath, qn as FieldValue, yn as Firestore, B as FirestoreError, Rn as GeoPoint, kn as Query, gr as QueryCompositeFilterConstraint, dr as QueryConstraint, cr as QueryDocumentSnapshot, Vr as QueryEndAtConstraint, mr as QueryFieldFilterConstraint, Er as QueryLimitConstraint, br as QueryOrderByConstraint, lr as QuerySnapshot, Ir as QueryStartAtConstraint, Vt as Timestamp, ci as Transaction, $r as WriteBatch, zr as addDoc, Wr as aggregateQuerySnapshotEqual, _r as and, Jr as arrayRemove, Xr as arrayUnion, In as collection, An as collectionGroup, gn as connectFirestoreEmulator, Qr as deleteDoc, Hr as deleteField, Fn as doc, Nn as documentId, Dr as endAt, Pr as endBefore, Kr as getCount, Mr as getDoc, Ur as getDocs, vn as getFirestore, Zr as increment, mn as initializeFirestore, kr as limit, Sr as limitToLast, wr as or, Tr as orderBy, yr as query, Pn as queryEqual, Vn as refEqual, li as runTransaction, Yr as serverTimestamp, Br as setDoc, _ as setLogLevel, fr as snapshotEqual, Fr as startAfter, Ar as startAt, wn as terminate, Gr as updateDoc, vr as where, ei as writeBatch };
  6213. //# sourceMappingURL=index.browser.esm5.js.map