index.rn.esm2017.js 265 KB

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