123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387 |
- import { _registerComponent, registerVersion, _getProvider, getApp, _removeServiceInstance, SDK_VERSION } from '@firebase/app';
- import { Component } from '@firebase/component';
- import { Logger, LogLevel } from '@firebase/logger';
- import { FirebaseError, createMockUserToken, getModularInstance, deepEqual, getDefaultEmulatorHostnameAndPort, getUA, isIndexedDBAvailable, isSafari } from '@firebase/util';
- import { Integer, XhrIo, EventType, ErrorCode, createWebChannelTransport, getStatEventTarget, FetchXmlHttpFactory, WebChannel, Event, Stat, Md5 } from '@firebase/webchannel-wrapper';
- const b = "@firebase/firestore";
- class V {
- constructor(t) {
- this.uid = t;
- }
- isAuthenticated() {
- return null != this.uid;
- }
-
- toKey() {
- return this.isAuthenticated() ? "uid:" + this.uid : "anonymous-user";
- }
- isEqual(t) {
- return t.uid === this.uid;
- }
- }
- V.UNAUTHENTICATED = new V(null),
- V.GOOGLE_CREDENTIALS = new V("google-credentials-uid"), V.FIRST_PARTY = new V("first-party-uid"),
- V.MOCK_USER = new V("mock-user");
- let S = "9.23.0";
- const D = new Logger("@firebase/firestore");
- function C() {
- return D.logLevel;
- }
- function x(t) {
- D.setLogLevel(t);
- }
- function N(t, ...e) {
- if (D.logLevel <= LogLevel.DEBUG) {
- const n = e.map($);
- D.debug(`Firestore (${S}): ${t}`, ...n);
- }
- }
- function k(t, ...e) {
- if (D.logLevel <= LogLevel.ERROR) {
- const n = e.map($);
- D.error(`Firestore (${S}): ${t}`, ...n);
- }
- }
- function M(t, ...e) {
- if (D.logLevel <= LogLevel.WARN) {
- const n = e.map($);
- D.warn(`Firestore (${S}): ${t}`, ...n);
- }
- }
- function $(t) {
- if ("string" == typeof t) return t;
- try {
- return e = t, JSON.stringify(e);
- } catch (e) {
-
- return t;
- }
-
-
- var e;
- }
- function O(t = "Unexpected state") {
-
-
- const e = `FIRESTORE (${S}) INTERNAL ASSERTION FAILED: ` + t;
-
-
-
- throw k(e), new Error(e);
- }
- function F(t, e) {
- t || O();
- }
- function B(t, e) {
- t || O();
- }
- function L(t,
- e) {
- return t;
- }
- const q = {
-
-
-
- OK: "ok",
-
- CANCELLED: "cancelled",
-
- UNKNOWN: "unknown",
-
- INVALID_ARGUMENT: "invalid-argument",
-
- DEADLINE_EXCEEDED: "deadline-exceeded",
-
- NOT_FOUND: "not-found",
-
- ALREADY_EXISTS: "already-exists",
-
- PERMISSION_DENIED: "permission-denied",
-
- UNAUTHENTICATED: "unauthenticated",
-
- RESOURCE_EXHAUSTED: "resource-exhausted",
-
- FAILED_PRECONDITION: "failed-precondition",
-
- ABORTED: "aborted",
-
- OUT_OF_RANGE: "out-of-range",
-
- UNIMPLEMENTED: "unimplemented",
-
- INTERNAL: "internal",
-
- UNAVAILABLE: "unavailable",
-
- DATA_LOSS: "data-loss"
- };
- class U extends FirebaseError {
-
- constructor(
- /**
- * The backend error code associated with this error.
- */
- t,
- /**
- * A custom error description.
- */
- e) {
- super(t, e), this.code = t, this.message = e,
-
-
-
- this.toString = () => `${this.name}: [code=${this.code}]: ${this.message}`;
- }
- }
- class K {
- constructor() {
- this.promise = new Promise(((t, e) => {
- this.resolve = t, this.reject = e;
- }));
- }
- }
- class G {
- constructor(t, e) {
- this.user = e, this.type = "OAuth", this.headers = new Map, this.headers.set("Authorization", `Bearer ${t}`);
- }
- }
- class Q {
- getToken() {
- return Promise.resolve(null);
- }
- invalidateToken() {}
- start(t, e) {
-
- t.enqueueRetryable((() => e(V.UNAUTHENTICATED)));
- }
- shutdown() {}
- }
- class j {
- constructor(t) {
- this.token = t,
-
- this.changeListener = null;
- }
- getToken() {
- return Promise.resolve(this.token);
- }
- invalidateToken() {}
- start(t, e) {
- this.changeListener = e,
-
- t.enqueueRetryable((() => e(this.token.user)));
- }
- shutdown() {
- this.changeListener = null;
- }
- }
- class z {
- constructor(t) {
- this.t = t,
-
- this.currentUser = V.UNAUTHENTICATED,
-
- this.i = 0, this.forceRefresh = !1, this.auth = null;
- }
- start(t, e) {
- let n = this.i;
-
- const s = t => this.i !== n ? (n = this.i, e(t)) : Promise.resolve();
-
-
- let i = new K;
- this.o = () => {
- this.i++, this.currentUser = this.u(), i.resolve(), i = new K, t.enqueueRetryable((() => s(this.currentUser)));
- };
- const r = () => {
- const e = i;
- t.enqueueRetryable((async () => {
- await e.promise, await s(this.currentUser);
- }));
- }, o = t => {
- N("FirebaseAuthCredentialsProvider", "Auth detected"), this.auth = t, this.auth.addAuthTokenListener(this.o),
- r();
- };
- this.t.onInit((t => o(t))),
-
-
-
- setTimeout((() => {
- if (!this.auth) {
- const t = this.t.getImmediate({
- optional: !0
- });
- t ? o(t) : (
-
- N("FirebaseAuthCredentialsProvider", "Auth not yet detected"), i.resolve(), i = new K);
- }
- }), 0), r();
- }
- getToken() {
-
-
-
- const t = this.i, e = this.forceRefresh;
- return this.forceRefresh = !1, this.auth ? this.auth.getToken(e).then((e =>
-
-
-
- this.i !== t ? (N("FirebaseAuthCredentialsProvider", "getToken aborted due to token change."),
- this.getToken()) : e ? (F("string" == typeof e.accessToken), new G(e.accessToken, this.currentUser)) : null)) : Promise.resolve(null);
- }
- invalidateToken() {
- this.forceRefresh = !0;
- }
- shutdown() {
- this.auth && this.auth.removeAuthTokenListener(this.o);
- }
-
-
-
-
- u() {
- const t = this.auth && this.auth.getUid();
- return F(null === t || "string" == typeof t), new V(t);
- }
- }
- class W {
- constructor(t, e, n) {
- this.h = t, this.l = e, this.m = n, this.type = "FirstParty", this.user = V.FIRST_PARTY,
- this.g = new Map;
- }
-
- p() {
- return this.m ? this.m() : null;
- }
- get headers() {
- this.g.set("X-Goog-AuthUser", this.h);
-
- const t = this.p();
- return t && this.g.set("Authorization", t), this.l && this.g.set("X-Goog-Iam-Authorization-Token", this.l),
- this.g;
- }
- }
- class H {
- constructor(t, e, n) {
- this.h = t, this.l = e, this.m = n;
- }
- getToken() {
- return Promise.resolve(new W(this.h, this.l, this.m));
- }
- start(t, e) {
-
- t.enqueueRetryable((() => e(V.FIRST_PARTY)));
- }
- shutdown() {}
- invalidateToken() {}
- }
- class J {
- constructor(t) {
- this.value = t, this.type = "AppCheck", this.headers = new Map, t && t.length > 0 && this.headers.set("x-firebase-appcheck", this.value);
- }
- }
- class Y {
- constructor(t) {
- this.I = t, this.forceRefresh = !1, this.appCheck = null, this.T = null;
- }
- start(t, e) {
- const n = t => {
- null != t.error && N("FirebaseAppCheckTokenProvider", `Error getting App Check token; using placeholder token instead. Error: ${t.error.message}`);
- const n = t.token !== this.T;
- return this.T = t.token, N("FirebaseAppCheckTokenProvider", `Received ${n ? "new" : "existing"} token.`),
- n ? e(t.token) : Promise.resolve();
- };
- this.o = e => {
- t.enqueueRetryable((() => n(e)));
- };
- const s = t => {
- N("FirebaseAppCheckTokenProvider", "AppCheck detected"), this.appCheck = t, this.appCheck.addTokenListener(this.o);
- };
- this.I.onInit((t => s(t))),
-
-
- setTimeout((() => {
- if (!this.appCheck) {
- const t = this.I.getImmediate({
- optional: !0
- });
- t ? s(t) :
-
- N("FirebaseAppCheckTokenProvider", "AppCheck not yet detected");
- }
- }), 0);
- }
- getToken() {
- const t = this.forceRefresh;
- return this.forceRefresh = !1, this.appCheck ? this.appCheck.getToken(t).then((t => t ? (F("string" == typeof t.token),
- this.T = t.token, new J(t.token)) : null)) : Promise.resolve(null);
- }
- invalidateToken() {
- this.forceRefresh = !0;
- }
- shutdown() {
- this.appCheck && this.appCheck.removeTokenListener(this.o);
- }
- }
- class X {
- getToken() {
- return Promise.resolve(new J(""));
- }
- invalidateToken() {}
- start(t, e) {}
- shutdown() {}
- }
- function Z(t) {
-
- const e =
-
- "undefined" != typeof self && (self.crypto || self.msCrypto), n = new Uint8Array(t);
- if (e && "function" == typeof e.getRandomValues) e.getRandomValues(n); else
-
- for (let e = 0; e < t; e++) n[e] = Math.floor(256 * Math.random());
- return n;
- }
- class tt {
- static A() {
-
- const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", e = Math.floor(256 / t.length) * t.length;
-
- let n = "";
- for (;n.length < 20; ) {
- const s = Z(40);
- for (let i = 0; i < s.length; ++i)
-
-
- n.length < 20 && s[i] < e && (n += t.charAt(s[i] % t.length));
- }
- return n;
- }
- }
- function et(t, e) {
- return t < e ? -1 : t > e ? 1 : 0;
- }
- function nt(t, e, n) {
- return t.length === e.length && t.every(((t, s) => n(t, e[s])));
- }
- function st(t) {
-
- return t + "\0";
- }
- class it {
-
- constructor(
- /**
- * The number of seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z.
- */
- t,
- /**
- * The fractions of a second at nanosecond resolution.*
- */
- e) {
- if (this.seconds = t, this.nanoseconds = e, e < 0) throw new U(q.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
- if (e >= 1e9) throw new U(q.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
- if (t < -62135596800) throw new U(q.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
-
- if (t >= 253402300800) throw new U(q.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
- }
-
- static now() {
- return it.fromMillis(Date.now());
- }
-
- static fromDate(t) {
- return it.fromMillis(t.getTime());
- }
-
- static fromMillis(t) {
- const e = Math.floor(t / 1e3), n = Math.floor(1e6 * (t - 1e3 * e));
- return new it(e, n);
- }
-
- toDate() {
- return new Date(this.toMillis());
- }
-
- toMillis() {
- return 1e3 * this.seconds + this.nanoseconds / 1e6;
- }
- _compareTo(t) {
- return this.seconds === t.seconds ? et(this.nanoseconds, t.nanoseconds) : et(this.seconds, t.seconds);
- }
-
- isEqual(t) {
- return t.seconds === this.seconds && t.nanoseconds === this.nanoseconds;
- }
- toString() {
- return "Timestamp(seconds=" + this.seconds + ", nanoseconds=" + this.nanoseconds + ")";
- }
- toJSON() {
- return {
- seconds: this.seconds,
- nanoseconds: this.nanoseconds
- };
- }
-
- valueOf() {
-
-
-
-
-
-
-
- const t = this.seconds - -62135596800;
-
-
- return String(t).padStart(12, "0") + "." + String(this.nanoseconds).padStart(9, "0");
- }
- }
- class rt {
- constructor(t) {
- this.timestamp = t;
- }
- static fromTimestamp(t) {
- return new rt(t);
- }
- static min() {
- return new rt(new it(0, 0));
- }
- static max() {
- return new rt(new it(253402300799, 999999999));
- }
- compareTo(t) {
- return this.timestamp._compareTo(t.timestamp);
- }
- isEqual(t) {
- return this.timestamp.isEqual(t.timestamp);
- }
- toMicroseconds() {
-
- return 1e6 * this.timestamp.seconds + this.timestamp.nanoseconds / 1e3;
- }
- toString() {
- return "SnapshotVersion(" + this.timestamp.toString() + ")";
- }
- toTimestamp() {
- return this.timestamp;
- }
- }
- class ot {
- constructor(t, e, n) {
- void 0 === e ? e = 0 : e > t.length && O(), void 0 === n ? n = t.length - e : n > t.length - e && O(),
- this.segments = t, this.offset = e, this.len = n;
- }
- get length() {
- return this.len;
- }
- isEqual(t) {
- return 0 === ot.comparator(this, t);
- }
- child(t) {
- const e = this.segments.slice(this.offset, this.limit());
- return t instanceof ot ? t.forEach((t => {
- e.push(t);
- })) : e.push(t), this.construct(e);
- }
- limit() {
- return this.offset + this.length;
- }
- popFirst(t) {
- return t = void 0 === t ? 1 : t, this.construct(this.segments, this.offset + t, this.length - t);
- }
- popLast() {
- return this.construct(this.segments, this.offset, this.length - 1);
- }
- firstSegment() {
- return this.segments[this.offset];
- }
- lastSegment() {
- return this.get(this.length - 1);
- }
- get(t) {
- return this.segments[this.offset + t];
- }
- isEmpty() {
- return 0 === this.length;
- }
- isPrefixOf(t) {
- if (t.length < this.length) return !1;
- for (let e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
- return !0;
- }
- isImmediateParentOf(t) {
- if (this.length + 1 !== t.length) return !1;
- for (let e = 0; e < this.length; e++) if (this.get(e) !== t.get(e)) return !1;
- return !0;
- }
- forEach(t) {
- for (let e = this.offset, n = this.limit(); e < n; e++) t(this.segments[e]);
- }
- toArray() {
- return this.segments.slice(this.offset, this.limit());
- }
- static comparator(t, e) {
- const n = Math.min(t.length, e.length);
- for (let s = 0; s < n; s++) {
- const n = t.get(s), i = e.get(s);
- if (n < i) return -1;
- if (n > i) return 1;
- }
- return t.length < e.length ? -1 : t.length > e.length ? 1 : 0;
- }
- }
- class ut extends ot {
- construct(t, e, n) {
- return new ut(t, e, n);
- }
- canonicalString() {
-
-
-
- return this.toArray().join("/");
- }
- toString() {
- return this.canonicalString();
- }
-
- static fromString(...t) {
-
-
-
- const e = [];
- for (const n of t) {
- if (n.indexOf("//") >= 0) throw new U(q.INVALID_ARGUMENT, `Invalid segment (${n}). Paths must not contain // in them.`);
-
- e.push(...n.split("/").filter((t => t.length > 0)));
- }
- return new ut(e);
- }
- static emptyPath() {
- return new ut([]);
- }
- }
- const ct = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
- class at extends ot {
- construct(t, e, n) {
- return new at(t, e, n);
- }
-
- static isValidIdentifier(t) {
- return ct.test(t);
- }
- canonicalString() {
- return this.toArray().map((t => (t = t.replace(/\\/g, "\\\\").replace(/`/g, "\\`"),
- at.isValidIdentifier(t) || (t = "`" + t + "`"), t))).join(".");
- }
- toString() {
- return this.canonicalString();
- }
-
- isKeyField() {
- return 1 === this.length && "__name__" === this.get(0);
- }
-
- static keyField() {
- return new at([ "__name__" ]);
- }
-
- static fromServerFormat(t) {
- const e = [];
- let n = "", s = 0;
- const i = () => {
- if (0 === n.length) throw new U(q.INVALID_ARGUMENT, `Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);
- e.push(n), n = "";
- };
- let r = !1;
- for (;s < t.length; ) {
- const e = t[s];
- if ("\\" === e) {
- if (s + 1 === t.length) throw new U(q.INVALID_ARGUMENT, "Path has trailing escape character: " + t);
- const e = t[s + 1];
- if ("\\" !== e && "." !== e && "`" !== e) throw new U(q.INVALID_ARGUMENT, "Path has invalid escape sequence: " + t);
- n += e, s += 2;
- } else "`" === e ? (r = !r, s++) : "." !== e || r ? (n += e, s++) : (i(), s++);
- }
- if (i(), r) throw new U(q.INVALID_ARGUMENT, "Unterminated ` in path: " + t);
- return new at(e);
- }
- static emptyPath() {
- return new at([]);
- }
- }
- class ht {
- constructor(t) {
- this.path = t;
- }
- static fromPath(t) {
- return new ht(ut.fromString(t));
- }
- static fromName(t) {
- return new ht(ut.fromString(t).popFirst(5));
- }
- static empty() {
- return new ht(ut.emptyPath());
- }
- get collectionGroup() {
- return this.path.popLast().lastSegment();
- }
- hasCollectionId(t) {
- return this.path.length >= 2 && this.path.get(this.path.length - 2) === t;
- }
- getCollectionGroup() {
- return this.path.get(this.path.length - 2);
- }
- getCollectionPath() {
- return this.path.popLast();
- }
- isEqual(t) {
- return null !== t && 0 === ut.comparator(this.path, t.path);
- }
- toString() {
- return this.path.toString();
- }
- static comparator(t, e) {
- return ut.comparator(t.path, e.path);
- }
- static isDocumentKey(t) {
- return t.length % 2 == 0;
- }
-
- static fromSegments(t) {
- return new ht(new ut(t.slice()));
- }
- }
- class lt {
- constructor(
- /**
- * The index ID. Returns -1 if the index ID is not available (e.g. the index
- * has not yet been persisted).
- */
- t,
- /** The collection ID this index applies to. */
- e,
- /** The field segments for this index. */
- n,
- /** Shows how up-to-date the index is for the current user. */
- s) {
- this.indexId = t, this.collectionGroup = e, this.fields = n, this.indexState = s;
- }
- }
- function ft(t) {
- return t.fields.find((t => 2 === t.kind));
- }
- function dt(t) {
- return t.fields.filter((t => 2 !== t.kind));
- }
- function wt(t, e) {
- let n = et(t.collectionGroup, e.collectionGroup);
- if (0 !== n) return n;
- for (let s = 0; s < Math.min(t.fields.length, e.fields.length); ++s) if (n = mt(t.fields[s], e.fields[s]),
- 0 !== n) return n;
- return et(t.fields.length, e.fields.length);
- }
- lt.UNKNOWN_ID = -1;
- class _t {
- constructor(
- /** The field path of the component. */
- t,
- /** The fields sorting order. */
- e) {
- this.fieldPath = t, this.kind = e;
- }
- }
- function mt(t, e) {
- const n = at.comparator(t.fieldPath, e.fieldPath);
- return 0 !== n ? n : et(t.kind, e.kind);
- }
- class gt {
- constructor(
- /**
- * Indicates when the index was last updated (relative to other indexes).
- */
- t,
- /** The the latest indexed read time, document and batch id. */
- e) {
- this.sequenceNumber = t, this.offset = e;
- }
- static empty() {
- return new gt(0, It.min());
- }
- }
- function yt(t, e) {
-
-
-
-
-
-
- const n = t.toTimestamp().seconds, s = t.toTimestamp().nanoseconds + 1, i = rt.fromTimestamp(1e9 === s ? new it(n + 1, 0) : new it(n, s));
- return new It(i, ht.empty(), e);
- }
- function pt(t) {
- return new It(t.readTime, t.key, -1);
- }
- class It {
- constructor(
- /**
- * The latest read time version that has been indexed by Firestore for this
- * field index.
- */
- t,
- /**
- * The key of the last document that was indexed for this query. Use
- * `DocumentKey.empty()` if no document has been indexed.
- */
- e,
- /*
- * The largest mutation batch id that's been processed by Firestore.
- */
- n) {
- this.readTime = t, this.documentKey = e, this.largestBatchId = n;
- }
- static min() {
- return new It(rt.min(), ht.empty(), -1);
- }
- static max() {
- return new It(rt.max(), ht.empty(), -1);
- }
- }
- function Tt(t, e) {
- let n = t.readTime.compareTo(e.readTime);
- return 0 !== n ? n : (n = ht.comparator(t.documentKey, e.documentKey), 0 !== n ? n : et(t.largestBatchId, e.largestBatchId));
- }
- const Et = "The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";
- class At {
- constructor() {
- this.onCommittedListeners = [];
- }
- addOnCommittedListener(t) {
- this.onCommittedListeners.push(t);
- }
- raiseOnCommittedEvent() {
- this.onCommittedListeners.forEach((t => t()));
- }
- }
- async function vt(t) {
- if (t.code !== q.FAILED_PRECONDITION || t.message !== Et) throw t;
- N("LocalStore", "Unexpectedly lost primary lease");
- }
- class Rt {
- constructor(t) {
-
-
- this.nextCallback = null, this.catchCallback = null,
-
- this.result = void 0, this.error = void 0, this.isDone = !1,
-
-
- this.callbackAttached = !1, t((t => {
- this.isDone = !0, this.result = t, this.nextCallback &&
-
-
- this.nextCallback(t);
- }), (t => {
- this.isDone = !0, this.error = t, this.catchCallback && this.catchCallback(t);
- }));
- }
- catch(t) {
- return this.next(void 0, t);
- }
- next(t, e) {
- return this.callbackAttached && O(), this.callbackAttached = !0, this.isDone ? this.error ? this.wrapFailure(e, this.error) : this.wrapSuccess(t, this.result) : new Rt(((n, s) => {
- this.nextCallback = e => {
- this.wrapSuccess(t, e).next(n, s);
- }, this.catchCallback = t => {
- this.wrapFailure(e, t).next(n, s);
- };
- }));
- }
- toPromise() {
- return new Promise(((t, e) => {
- this.next(t, e);
- }));
- }
- wrapUserFunction(t) {
- try {
- const e = t();
- return e instanceof Rt ? e : Rt.resolve(e);
- } catch (t) {
- return Rt.reject(t);
- }
- }
- wrapSuccess(t, e) {
- return t ? this.wrapUserFunction((() => t(e))) : Rt.resolve(e);
- }
- wrapFailure(t, e) {
- return t ? this.wrapUserFunction((() => t(e))) : Rt.reject(e);
- }
- static resolve(t) {
- return new Rt(((e, n) => {
- e(t);
- }));
- }
- static reject(t) {
- return new Rt(((e, n) => {
- n(t);
- }));
- }
- static waitFor(
-
-
- t) {
- return new Rt(((e, n) => {
- let s = 0, i = 0, r = !1;
- t.forEach((t => {
- ++s, t.next((() => {
- ++i, r && i === s && e();
- }), (t => n(t)));
- })), r = !0, i === s && e();
- }));
- }
-
- static or(t) {
- let e = Rt.resolve(!1);
- for (const n of t) e = e.next((t => t ? Rt.resolve(t) : n()));
- return e;
- }
- static forEach(t, e) {
- const n = [];
- return t.forEach(((t, s) => {
- n.push(e.call(this, t, s));
- })), this.waitFor(n);
- }
-
- static mapArray(t, e) {
- return new Rt(((n, s) => {
- const i = t.length, r = new Array(i);
- let o = 0;
- for (let u = 0; u < i; u++) {
- const c = u;
- e(t[c]).next((t => {
- r[c] = t, ++o, o === i && n(r);
- }), (t => s(t)));
- }
- }));
- }
-
- static doWhile(t, e) {
- return new Rt(((n, s) => {
- const i = () => {
- !0 === t() ? e().next((() => {
- i();
- }), s) : n();
- };
- i();
- }));
- }
- }
- class Pt {
- constructor(t, e) {
- this.action = t, this.transaction = e, this.aborted = !1,
-
- this.v = new K, this.transaction.oncomplete = () => {
- this.v.resolve();
- }, this.transaction.onabort = () => {
- e.error ? this.v.reject(new St(t, e.error)) : this.v.resolve();
- }, this.transaction.onerror = e => {
- const n = kt(e.target.error);
- this.v.reject(new St(t, n));
- };
- }
- static open(t, e, n, s) {
- try {
- return new Pt(e, t.transaction(s, n));
- } catch (t) {
- throw new St(e, t);
- }
- }
- get R() {
- return this.v.promise;
- }
- abort(t) {
- t && this.v.reject(t), this.aborted || (N("SimpleDb", "Aborting transaction:", t ? t.message : "Client-initiated abort"),
- this.aborted = !0, this.transaction.abort());
- }
- P() {
-
-
-
- const t = this.transaction;
- this.aborted || "function" != typeof t.commit || t.commit();
- }
-
- store(t) {
- const e = this.transaction.objectStore(t);
- return new Ct(e);
- }
- }
- class bt {
-
- constructor(t, e, n) {
- this.name = t, this.version = e, this.V = n;
-
-
-
-
- 12.2 === bt.S(getUA()) && k("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");
- }
- static delete(t) {
- return N("SimpleDb", "Removing database:", t), xt(window.indexedDB.deleteDatabase(t)).toPromise();
- }
- static D() {
- if (!isIndexedDBAvailable()) return !1;
- if (bt.C()) return !0;
-
-
-
-
-
-
-
- const t = getUA(), e = bt.S(t), n = 0 < e && e < 10, s = bt.N(t), i = 0 < s && s < 4.5;
-
-
-
-
-
-
-
-
- return !(t.indexOf("MSIE ") > 0 || t.indexOf("Trident/") > 0 || t.indexOf("Edge/") > 0 || n || i);
- }
-
- static C() {
- var t;
- return "undefined" != typeof process && "YES" === (null === (t = process.env) || void 0 === t ? void 0 : t.k);
- }
- static M(t, e) {
- return t.store(e);
- }
-
-
- static S(t) {
- const e = t.match(/i(?:phone|pad|pod) os ([\d_]+)/i), n = e ? e[1].split("_").slice(0, 2).join(".") : "-1";
- return Number(n);
- }
-
-
- static N(t) {
- const e = t.match(/Android ([\d.]+)/i), n = e ? e[1].split(".").slice(0, 2).join(".") : "-1";
- return Number(n);
- }
-
- async $(t) {
- return this.db || (N("SimpleDb", "Opening database:", this.name), this.db = await new Promise(((e, n) => {
-
-
-
-
-
- const s = indexedDB.open(this.name, this.version);
- s.onsuccess = t => {
- const n = t.target.result;
- e(n);
- }, s.onblocked = () => {
- n(new St(t, "Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."));
- }, s.onerror = e => {
- const s = e.target.error;
- "VersionError" === s.name ? n(new U(q.FAILED_PRECONDITION, "A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")) : "InvalidStateError" === s.name ? n(new U(q.FAILED_PRECONDITION, "Unable to open an IndexedDB connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDB: " + s)) : n(new St(t, s));
- }, s.onupgradeneeded = t => {
- N("SimpleDb", 'Database "' + this.name + '" requires upgrade from version:', t.oldVersion);
- const e = t.target.result;
- this.V.O(e, s.transaction, t.oldVersion, this.version).next((() => {
- N("SimpleDb", "Database upgrade to version " + this.version + " complete");
- }));
- };
- }))), this.F && (this.db.onversionchange = t => this.F(t)), this.db;
- }
- B(t) {
- this.F = t, this.db && (this.db.onversionchange = e => t(e));
- }
- async runTransaction(t, e, n, s) {
- const i = "readonly" === e;
- let r = 0;
- for (;;) {
- ++r;
- try {
- this.db = await this.$(t);
- const e = Pt.open(this.db, t, i ? "readonly" : "readwrite", n), r = s(e).next((t => (e.P(),
- t))).catch((t => (
-
- e.abort(t), Rt.reject(t)))).toPromise();
-
-
- return r.catch((() => {})),
-
-
-
- await e.R, r;
- } catch (t) {
- const e = t, n = "FirebaseError" !== e.name && r < 3;
-
-
-
-
-
- if (N("SimpleDb", "Transaction failed with error:", e.message, "Retrying:", n),
- this.close(), !n) return Promise.reject(e);
- }
- }
- }
- close() {
- this.db && this.db.close(), this.db = void 0;
- }
- }
- class Vt {
- constructor(t) {
- this.L = t, this.q = !1, this.U = null;
- }
- get isDone() {
- return this.q;
- }
- get K() {
- return this.U;
- }
- set cursor(t) {
- this.L = t;
- }
-
- done() {
- this.q = !0;
- }
-
- G(t) {
- this.U = t;
- }
-
- delete() {
- return xt(this.L.delete());
- }
- }
- class St extends U {
- constructor(t, e) {
- super(q.UNAVAILABLE, `IndexedDB transaction '${t}' failed: ${e}`), this.name = "IndexedDbTransactionError";
- }
- }
- function Dt(t) {
-
-
- return "IndexedDbTransactionError" === t.name;
- }
- class Ct {
- constructor(t) {
- this.store = t;
- }
- put(t, e) {
- let n;
- return void 0 !== e ? (N("SimpleDb", "PUT", this.store.name, t, e), n = this.store.put(e, t)) : (N("SimpleDb", "PUT", this.store.name, "<auto-key>", t),
- n = this.store.put(t)), xt(n);
- }
-
- add(t) {
- N("SimpleDb", "ADD", this.store.name, t, t);
- return xt(this.store.add(t));
- }
-
- get(t) {
-
-
- return xt(this.store.get(t)).next((e => (
-
- void 0 === e && (e = null), N("SimpleDb", "GET", this.store.name, t, e), e)));
- }
- delete(t) {
- N("SimpleDb", "DELETE", this.store.name, t);
- return xt(this.store.delete(t));
- }
-
- count() {
- N("SimpleDb", "COUNT", this.store.name);
- return xt(this.store.count());
- }
- j(t, e) {
- const n = this.options(t, e);
-
-
- if (n.index || "function" != typeof this.store.getAll) {
- const t = this.cursor(n), e = [];
- return this.W(t, ((t, n) => {
- e.push(n);
- })).next((() => e));
- }
- {
- const t = this.store.getAll(n.range);
- return new Rt(((e, n) => {
- t.onerror = t => {
- n(t.target.error);
- }, t.onsuccess = t => {
- e(t.target.result);
- };
- }));
- }
- }
-
- H(t, e) {
- const n = this.store.getAll(t, null === e ? void 0 : e);
- return new Rt(((t, e) => {
- n.onerror = t => {
- e(t.target.error);
- }, n.onsuccess = e => {
- t(e.target.result);
- };
- }));
- }
- J(t, e) {
- N("SimpleDb", "DELETE ALL", this.store.name);
- const n = this.options(t, e);
- n.Y = !1;
- const s = this.cursor(n);
- return this.W(s, ((t, e, n) => n.delete()));
- }
- X(t, e) {
- let n;
- e ? n = t : (n = {}, e = t);
- const s = this.cursor(n);
- return this.W(s, e);
- }
-
- Z(t) {
- const e = this.cursor({});
- return new Rt(((n, s) => {
- e.onerror = t => {
- const e = kt(t.target.error);
- s(e);
- }, e.onsuccess = e => {
- const s = e.target.result;
- s ? t(s.primaryKey, s.value).next((t => {
- t ? s.continue() : n();
- })) : n();
- };
- }));
- }
- W(t, e) {
- const n = [];
- return new Rt(((s, i) => {
- t.onerror = t => {
- i(t.target.error);
- }, t.onsuccess = t => {
- const i = t.target.result;
- if (!i) return void s();
- const r = new Vt(i), o = e(i.primaryKey, i.value, r);
- if (o instanceof Rt) {
- const t = o.catch((t => (r.done(), Rt.reject(t))));
- n.push(t);
- }
- r.isDone ? s() : null === r.K ? i.continue() : i.continue(r.K);
- };
- })).next((() => Rt.waitFor(n)));
- }
- options(t, e) {
- let n;
- return void 0 !== t && ("string" == typeof t ? n = t : e = t), {
- index: n,
- range: e
- };
- }
- cursor(t) {
- let e = "next";
- if (t.reverse && (e = "prev"), t.index) {
- const n = this.store.index(t.index);
- return t.Y ? n.openKeyCursor(t.range, e) : n.openCursor(t.range, e);
- }
- return this.store.openCursor(t.range, e);
- }
- }
- function xt(t) {
- return new Rt(((e, n) => {
- t.onsuccess = t => {
- const n = t.target.result;
- e(n);
- }, t.onerror = t => {
- const e = kt(t.target.error);
- n(e);
- };
- }));
- }
- let Nt = !1;
- function kt(t) {
- const e = bt.S(getUA());
- if (e >= 12.2 && e < 13) {
- const e = "An internal error was encountered in the Indexed Database server";
- if (t.message.indexOf(e) >= 0) {
-
- const t = new U("internal", `IOS_INDEXEDDB_BUG1: IndexedDb has thrown '${e}'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.`);
- return Nt || (Nt = !0,
-
-
- setTimeout((() => {
- throw t;
- }), 0)), t;
- }
- }
- return t;
- }
- class Mt {
- constructor(t, e) {
- this.asyncQueue = t, this.tt = e, this.task = null;
- }
- start() {
- this.et(15e3);
- }
- stop() {
- this.task && (this.task.cancel(), this.task = null);
- }
- get started() {
- return null !== this.task;
- }
- et(t) {
- N("IndexBackiller", `Scheduled in ${t}ms`), this.task = this.asyncQueue.enqueueAfterDelay("index_backfill" , t, (async () => {
- this.task = null;
- try {
- N("IndexBackiller", `Documents written: ${await this.tt.nt()}`);
- } catch (t) {
- Dt(t) ? N("IndexBackiller", "Ignoring IndexedDB error during index backfill: ", t) : await vt(t);
- }
- await this.et(6e4);
- }));
- }
- }
- class $t {
- constructor(
- /**
- * LocalStore provides access to IndexManager and LocalDocumentView.
- * These properties will update when the user changes. Consequently,
- * making a local copy of IndexManager and LocalDocumentView will require
- * updates over time. The simpler solution is to rely on LocalStore to have
- * an up-to-date references to IndexManager and LocalDocumentStore.
- */
- t, e) {
- this.localStore = t, this.persistence = e;
- }
- async nt(t = 50) {
- return this.persistence.runTransaction("Backfill Indexes", "readwrite-primary", (e => this.st(e, t)));
- }
- st(t, e) {
- const n = new Set;
- let s = e, i = !0;
- return Rt.doWhile((() => !0 === i && s > 0), (() => this.localStore.indexManager.getNextCollectionGroupToUpdate(t).next((e => {
- if (null !== e && !n.has(e)) return N("IndexBackiller", `Processing collection: ${e}`),
- this.it(t, e, s).next((t => {
- s -= t, n.add(e);
- }));
- i = !1;
- })))).next((() => e - s));
- }
-
- it(t, e, n) {
-
- return this.localStore.indexManager.getMinOffsetFromCollectionGroup(t, e).next((s => this.localStore.localDocuments.getNextDocuments(t, e, s, n).next((n => {
- const i = n.changes;
- return this.localStore.indexManager.updateIndexEntries(t, i).next((() => this.rt(s, n))).next((n => (N("IndexBackiller", `Updating offset: ${n}`),
- this.localStore.indexManager.updateCollectionGroup(t, e, n)))).next((() => i.size));
- }))));
- }
- rt(t, e) {
- let n = t;
- return e.changes.forEach(((t, e) => {
- const s = pt(e);
- Tt(s, n) > 0 && (n = s);
- })), new It(n.readTime, n.documentKey, Math.max(e.batchId, t.largestBatchId));
- }
- }
- class Ot {
- constructor(t, e) {
- this.previousValue = t, e && (e.sequenceNumberHandler = t => this.ot(t), this.ut = t => e.writeSequenceNumber(t));
- }
- ot(t) {
- return this.previousValue = Math.max(t, this.previousValue), this.previousValue;
- }
- next() {
- const t = ++this.previousValue;
- return this.ut && this.ut(t), t;
- }
- }
- Ot.ct = -1;
- function Ft(t) {
- return null == t;
- }
- function Bt(t) {
-
-
- return 0 === t && 1 / t == -1 / 0;
- }
- function Lt(t) {
- return "number" == typeof t && Number.isInteger(t) && !Bt(t) && t <= Number.MAX_SAFE_INTEGER && t >= Number.MIN_SAFE_INTEGER;
- }
- function qt(t) {
- let e = "";
- for (let n = 0; n < t.length; n++) e.length > 0 && (e = Kt(e)), e = Ut(t.get(n), e);
- return Kt(e);
- }
- function Ut(t, e) {
- let n = e;
- const s = t.length;
- for (let e = 0; e < s; e++) {
- const s = t.charAt(e);
- switch (s) {
- case "\0":
- n += "";
- break;
- case "":
- n += "";
- break;
- default:
- n += s;
- }
- }
- return n;
- }
- function Kt(t) {
- return t + "";
- }
- function Gt(t) {
-
-
- const e = t.length;
- if (F(e >= 2), 2 === e) return F("" === t.charAt(0) && "" === t.charAt(1)), ut.emptyPath();
-
-
- const __PRIVATE_lastReasonableEscapeIndex = e - 2, n = [];
- let s = "";
- for (let i = 0; i < e; ) {
-
-
- const e = t.indexOf("", i);
- (e < 0 || e > __PRIVATE_lastReasonableEscapeIndex) && O();
- switch (t.charAt(e + 1)) {
- case "":
- const r = t.substring(i, e);
- let o;
- 0 === s.length ?
-
-
- o = r : (s += r, o = s, s = ""), n.push(o);
- break;
- case "":
- s += t.substring(i, e), s += "\0";
- break;
- case "":
-
- s += t.substring(i, e + 1);
- break;
- default:
- O();
- }
- i = e + 2;
- }
- return new ut(n);
- }
- const Qt = [ "userId", "batchId" ];
- function jt(t, e) {
- return [ t, qt(e) ];
- }
- function zt(t, e, n) {
- return [ t, qt(e), n ];
- }
- const Wt = {}, Ht = [ "prefixPath", "collectionGroup", "readTime", "documentId" ], Jt = [ "prefixPath", "collectionGroup", "documentId" ], Yt = [ "collectionGroup", "readTime", "prefixPath", "documentId" ], Xt = [ "canonicalId", "targetId" ], Zt = [ "targetId", "path" ], te = [ "path", "targetId" ], ee = [ "collectionId", "parent" ], ne = [ "indexId", "uid" ], se = [ "uid", "sequenceNumber" ], ie = [ "indexId", "uid", "arrayValue", "directionalValue", "orderedDocumentKey", "documentKey" ], re = [ "indexId", "uid", "orderedDocumentKey" ], oe = [ "userId", "collectionPath", "documentId" ], ue = [ "userId", "collectionPath", "largestBatchId" ], ce = [ "userId", "collectionGroup", "largestBatchId" ], ae = [ ...[ ...[ ...[ ...[ "mutationQueues", "mutations", "documentMutations", "remoteDocuments", "targets", "owner", "targetGlobal", "targetDocuments" ], "clientMetadata" ], "remoteDocumentGlobal" ], "collectionParents" ], "bundles", "namedQueries" ], he = [ ...ae, "documentOverlays" ], le = [ "mutationQueues", "mutations", "documentMutations", "remoteDocumentsV14", "targets", "owner", "targetGlobal", "targetDocuments", "clientMetadata", "remoteDocumentGlobal", "collectionParents", "bundles", "namedQueries", "documentOverlays" ], fe = le, de = [ ...fe, "indexConfiguration", "indexState", "indexEntries" ];
- class we extends At {
- constructor(t, e) {
- super(), this.ht = t, this.currentSequenceNumber = e;
- }
- }
- function _e(t, e) {
- const n = L(t);
- return bt.M(n.ht, e);
- }
- function me(t) {
- let e = 0;
- for (const n in t) Object.prototype.hasOwnProperty.call(t, n) && e++;
- return e;
- }
- function ge(t, e) {
- for (const n in t) Object.prototype.hasOwnProperty.call(t, n) && e(n, t[n]);
- }
- function ye(t) {
- for (const e in t) if (Object.prototype.hasOwnProperty.call(t, e)) return !1;
- return !0;
- }
- class pe {
- constructor(t, e) {
- this.comparator = t, this.root = e || Te.EMPTY;
- }
-
- insert(t, e) {
- return new pe(this.comparator, this.root.insert(t, e, this.comparator).copy(null, null, Te.BLACK, null, null));
- }
-
- remove(t) {
- return new pe(this.comparator, this.root.remove(t, this.comparator).copy(null, null, Te.BLACK, null, null));
- }
-
- get(t) {
- let e = this.root;
- for (;!e.isEmpty(); ) {
- const n = this.comparator(t, e.key);
- if (0 === n) return e.value;
- n < 0 ? e = e.left : n > 0 && (e = e.right);
- }
- return null;
- }
-
-
- indexOf(t) {
-
- let e = 0, n = this.root;
- for (;!n.isEmpty(); ) {
- const s = this.comparator(t, n.key);
- if (0 === s) return e + n.left.size;
- s < 0 ? n = n.left : (
-
- e += n.left.size + 1, n = n.right);
- }
-
- return -1;
- }
- isEmpty() {
- return this.root.isEmpty();
- }
-
- get size() {
- return this.root.size;
- }
-
- minKey() {
- return this.root.minKey();
- }
-
- maxKey() {
- return this.root.maxKey();
- }
-
-
-
-
- inorderTraversal(t) {
- return this.root.inorderTraversal(t);
- }
- forEach(t) {
- this.inorderTraversal(((e, n) => (t(e, n), !1)));
- }
- toString() {
- const t = [];
- return this.inorderTraversal(((e, n) => (t.push(`${e}:${n}`), !1))), `{${t.join(", ")}}`;
- }
-
-
-
-
-
- reverseTraversal(t) {
- return this.root.reverseTraversal(t);
- }
-
- getIterator() {
- return new Ie(this.root, null, this.comparator, !1);
- }
- getIteratorFrom(t) {
- return new Ie(this.root, t, this.comparator, !1);
- }
- getReverseIterator() {
- return new Ie(this.root, null, this.comparator, !0);
- }
- getReverseIteratorFrom(t) {
- return new Ie(this.root, t, this.comparator, !0);
- }
- }
-
- class Ie {
- constructor(t, e, n, s) {
- this.isReverse = s, this.nodeStack = [];
- let i = 1;
- for (;!t.isEmpty(); ) if (i = e ? n(t.key, e) : 1,
-
- e && s && (i *= -1), i < 0)
-
- t = this.isReverse ? t.left : t.right; else {
- if (0 === i) {
-
-
- this.nodeStack.push(t);
- break;
- }
-
-
- this.nodeStack.push(t), t = this.isReverse ? t.right : t.left;
- }
- }
- getNext() {
- let t = this.nodeStack.pop();
- const e = {
- key: t.key,
- value: t.value
- };
- 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),
- t = t.left;
- return e;
- }
- hasNext() {
- return this.nodeStack.length > 0;
- }
- peek() {
- if (0 === this.nodeStack.length) return null;
- const t = this.nodeStack[this.nodeStack.length - 1];
- return {
- key: t.key,
- value: t.value
- };
- }
- }
-
- class Te {
- constructor(t, e, n, s, i) {
- this.key = t, this.value = e, this.color = null != n ? n : Te.RED, this.left = null != s ? s : Te.EMPTY,
- this.right = null != i ? i : Te.EMPTY, this.size = this.left.size + 1 + this.right.size;
- }
-
- copy(t, e, n, s, i) {
- return new Te(null != t ? t : this.key, null != e ? e : this.value, null != n ? n : this.color, null != s ? s : this.left, null != i ? i : this.right);
- }
- isEmpty() {
- return !1;
- }
-
-
-
-
- inorderTraversal(t) {
- return this.left.inorderTraversal(t) || t(this.key, this.value) || this.right.inorderTraversal(t);
- }
-
-
-
-
- reverseTraversal(t) {
- return this.right.reverseTraversal(t) || t(this.key, this.value) || this.left.reverseTraversal(t);
- }
-
- min() {
- return this.left.isEmpty() ? this : this.left.min();
- }
-
- minKey() {
- return this.min().key;
- }
-
- maxKey() {
- return this.right.isEmpty() ? this.key : this.right.maxKey();
- }
-
- insert(t, e, n) {
- let s = this;
- const i = n(t, s.key);
- return s = i < 0 ? s.copy(null, null, null, s.left.insert(t, e, n), null) : 0 === i ? s.copy(null, e, null, null, null) : s.copy(null, null, null, null, s.right.insert(t, e, n)),
- s.fixUp();
- }
- removeMin() {
- if (this.left.isEmpty()) return Te.EMPTY;
- let t = this;
- return t.left.isRed() || t.left.left.isRed() || (t = t.moveRedLeft()), t = t.copy(null, null, null, t.left.removeMin(), null),
- t.fixUp();
- }
-
- remove(t, e) {
- let n, s = this;
- if (e(t, s.key) < 0) s.left.isEmpty() || s.left.isRed() || s.left.left.isRed() || (s = s.moveRedLeft()),
- s = s.copy(null, null, null, s.left.remove(t, e), null); else {
- if (s.left.isRed() && (s = s.rotateRight()), s.right.isEmpty() || s.right.isRed() || s.right.left.isRed() || (s = s.moveRedRight()),
- 0 === e(t, s.key)) {
- if (s.right.isEmpty()) return Te.EMPTY;
- n = s.right.min(), s = s.copy(n.key, n.value, null, null, s.right.removeMin());
- }
- s = s.copy(null, null, null, null, s.right.remove(t, e));
- }
- return s.fixUp();
- }
- isRed() {
- return this.color;
- }
-
- fixUp() {
- let t = this;
- return t.right.isRed() && !t.left.isRed() && (t = t.rotateLeft()), t.left.isRed() && t.left.left.isRed() && (t = t.rotateRight()),
- t.left.isRed() && t.right.isRed() && (t = t.colorFlip()), t;
- }
- moveRedLeft() {
- let t = this.colorFlip();
- return t.right.left.isRed() && (t = t.copy(null, null, null, null, t.right.rotateRight()),
- t = t.rotateLeft(), t = t.colorFlip()), t;
- }
- moveRedRight() {
- let t = this.colorFlip();
- return t.left.left.isRed() && (t = t.rotateRight(), t = t.colorFlip()), t;
- }
- rotateLeft() {
- const t = this.copy(null, null, Te.RED, null, this.right.left);
- return this.right.copy(null, null, this.color, t, null);
- }
- rotateRight() {
- const t = this.copy(null, null, Te.RED, this.left.right, null);
- return this.left.copy(null, null, this.color, null, t);
- }
- colorFlip() {
- const t = this.left.copy(null, null, !this.left.color, null, null), e = this.right.copy(null, null, !this.right.color, null, null);
- return this.copy(null, null, !this.color, t, e);
- }
-
- checkMaxDepth() {
- const t = this.check();
- return Math.pow(2, t) <= this.size + 1;
- }
-
-
- check() {
- if (this.isRed() && this.left.isRed()) throw O();
- if (this.right.isRed()) throw O();
- const t = this.left.check();
- if (t !== this.right.check()) throw O();
- return t + (this.isRed() ? 0 : 1);
- }
- }
-
- Te.EMPTY = null, Te.RED = !0, Te.BLACK = !1;
- Te.EMPTY = new
- class {
- constructor() {
- this.size = 0;
- }
- get key() {
- throw O();
- }
- get value() {
- throw O();
- }
- get color() {
- throw O();
- }
- get left() {
- throw O();
- }
- get right() {
- throw O();
- }
-
- copy(t, e, n, s, i) {
- return this;
- }
-
- insert(t, e, n) {
- return new Te(t, e);
- }
-
- remove(t, e) {
- return this;
- }
- isEmpty() {
- return !0;
- }
- inorderTraversal(t) {
- return !1;
- }
- reverseTraversal(t) {
- return !1;
- }
- minKey() {
- return null;
- }
- maxKey() {
- return null;
- }
- isRed() {
- return !1;
- }
-
- checkMaxDepth() {
- return !0;
- }
- check() {
- return 0;
- }
- };
- class Ee {
- constructor(t) {
- this.comparator = t, this.data = new pe(this.comparator);
- }
- has(t) {
- return null !== this.data.get(t);
- }
- first() {
- return this.data.minKey();
- }
- last() {
- return this.data.maxKey();
- }
- get size() {
- return this.data.size;
- }
- indexOf(t) {
- return this.data.indexOf(t);
- }
- forEach(t) {
- this.data.inorderTraversal(((e, n) => (t(e), !1)));
- }
- forEachInRange(t, e) {
- const n = this.data.getIteratorFrom(t[0]);
- for (;n.hasNext(); ) {
- const s = n.getNext();
- if (this.comparator(s.key, t[1]) >= 0) return;
- e(s.key);
- }
- }
-
- forEachWhile(t, e) {
- let n;
- for (n = void 0 !== e ? this.data.getIteratorFrom(e) : this.data.getIterator(); n.hasNext(); ) {
- if (!t(n.getNext().key)) return;
- }
- }
- firstAfterOrEqual(t) {
- const e = this.data.getIteratorFrom(t);
- return e.hasNext() ? e.getNext().key : null;
- }
- getIterator() {
- return new Ae(this.data.getIterator());
- }
- getIteratorFrom(t) {
- return new Ae(this.data.getIteratorFrom(t));
- }
- add(t) {
- return this.copy(this.data.remove(t).insert(t, !0));
- }
- delete(t) {
- return this.has(t) ? this.copy(this.data.remove(t)) : this;
- }
- isEmpty() {
- return this.data.isEmpty();
- }
- unionWith(t) {
- let e = this;
-
- return e.size < t.size && (e = t, t = this), t.forEach((t => {
- e = e.add(t);
- })), e;
- }
- isEqual(t) {
- if (!(t instanceof Ee)) return !1;
- if (this.size !== t.size) return !1;
- const e = this.data.getIterator(), n = t.data.getIterator();
- for (;e.hasNext(); ) {
- const t = e.getNext().key, s = n.getNext().key;
- if (0 !== this.comparator(t, s)) return !1;
- }
- return !0;
- }
- toArray() {
- const t = [];
- return this.forEach((e => {
- t.push(e);
- })), t;
- }
- toString() {
- const t = [];
- return this.forEach((e => t.push(e))), "SortedSet(" + t.toString() + ")";
- }
- copy(t) {
- const e = new Ee(this.comparator);
- return e.data = t, e;
- }
- }
- class Ae {
- constructor(t) {
- this.iter = t;
- }
- getNext() {
- return this.iter.getNext().key;
- }
- hasNext() {
- return this.iter.hasNext();
- }
- }
- function ve(t) {
- return t.hasNext() ? t.getNext() : void 0;
- }
- class Re {
- constructor(t) {
- this.fields = t,
-
-
- t.sort(at.comparator);
- }
- static empty() {
- return new Re([]);
- }
-
- unionWith(t) {
- let e = new Ee(at.comparator);
- for (const t of this.fields) e = e.add(t);
- for (const n of t) e = e.add(n);
- return new Re(e.toArray());
- }
-
- covers(t) {
- for (const e of this.fields) if (e.isPrefixOf(t)) return !0;
- return !1;
- }
- isEqual(t) {
- return nt(this.fields, t.fields, ((t, e) => t.isEqual(e)));
- }
- }
- class Pe extends Error {
- constructor() {
- super(...arguments), this.name = "Base64DecodeError";
- }
- }
- function be() {
- return "undefined" != typeof atob;
- }
- class Ve {
- constructor(t) {
- this.binaryString = t;
- }
- static fromBase64String(t) {
- const e = function(t) {
- try {
- return atob(t);
- } catch (t) {
-
-
-
- throw "undefined" != typeof DOMException && t instanceof DOMException ? new Pe("Invalid base64 string: " + t) : t;
- }
- }
- (t);
- return new Ve(e);
- }
- static fromUint8Array(t) {
-
-
- const e =
-
- function(t) {
- let e = "";
- for (let n = 0; n < t.length; ++n) e += String.fromCharCode(t[n]);
- return e;
- }
-
- (t);
- return new Ve(e);
- }
- [Symbol.iterator]() {
- let t = 0;
- return {
- next: () => t < this.binaryString.length ? {
- value: this.binaryString.charCodeAt(t++),
- done: !1
- } : {
- value: void 0,
- done: !0
- }
- };
- }
- toBase64() {
- return t = this.binaryString, btoa(t);
- var t;
- }
- toUint8Array() {
- return function(t) {
- const e = new Uint8Array(t.length);
- for (let n = 0; n < t.length; n++) e[n] = t.charCodeAt(n);
- return e;
- }
-
-
- (this.binaryString);
- }
- approximateByteSize() {
- return 2 * this.binaryString.length;
- }
- compareTo(t) {
- return et(this.binaryString, t.binaryString);
- }
- isEqual(t) {
- return this.binaryString === t.binaryString;
- }
- }
- Ve.EMPTY_BYTE_STRING = new Ve("");
- const Se = new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);
- function De(t) {
-
-
-
- if (F(!!t), "string" == typeof t) {
-
-
-
- let e = 0;
- const n = Se.exec(t);
- if (F(!!n), n[1]) {
-
- let t = n[1];
- t = (t + "000000000").substr(0, 9), e = Number(t);
- }
-
- const s = new Date(t);
- return {
- seconds: Math.floor(s.getTime() / 1e3),
- nanos: e
- };
- }
- return {
- seconds: Ce(t.seconds),
- nanos: Ce(t.nanos)
- };
- }
- function Ce(t) {
-
- return "number" == typeof t ? t : "string" == typeof t ? Number(t) : 0;
- }
- function xe(t) {
- return "string" == typeof t ? Ve.fromBase64String(t) : Ve.fromUint8Array(t);
- }
- function Ne(t) {
- var e, n;
- 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);
- }
- function ke(t) {
- const e = t.mapValue.fields.__previous_value__;
- return Ne(e) ? ke(e) : e;
- }
- function Me(t) {
- const e = De(t.mapValue.fields.__local_write_time__.timestampValue);
- return new it(e.seconds, e.nanos);
- }
- class $e {
-
- constructor(t, e, n, s, i, r, o, u, c) {
- this.databaseId = t, this.appId = e, this.persistenceKey = n, this.host = s, this.ssl = i,
- this.forceLongPolling = r, this.autoDetectLongPolling = o, this.longPollingOptions = u,
- this.useFetchStreams = c;
- }
- }
- class Oe {
- constructor(t, e) {
- this.projectId = t, this.database = e || "(default)";
- }
- static empty() {
- return new Oe("", "");
- }
- get isDefaultDatabase() {
- return "(default)" === this.database;
- }
- isEqual(t) {
- return t instanceof Oe && t.projectId === this.projectId && t.database === this.database;
- }
- }
- const Fe = {
- mapValue: {
- fields: {
- __type__: {
- stringValue: "__max__"
- }
- }
- }
- }, Be = {
- nullValue: "NULL_VALUE"
- };
- function Le(t) {
- return "nullValue" in t ? 0 : "booleanValue" in t ? 1 : "integerValue" in t || "doubleValue" in t ? 2 : "timestampValue" in t ? 3 : "stringValue" in t ? 5 : "bytesValue" in t ? 6 : "referenceValue" in t ? 7 : "geoPointValue" in t ? 8 : "arrayValue" in t ? 9 : "mapValue" in t ? Ne(t) ? 4 : en(t) ? 9007199254740991 : 10 : O();
- }
- function qe(t, e) {
- if (t === e) return !0;
- const n = Le(t);
- if (n !== Le(e)) return !1;
- switch (n) {
- case 0 :
- case 9007199254740991 :
- return !0;
- case 1 :
- return t.booleanValue === e.booleanValue;
- case 4 :
- return Me(t).isEqual(Me(e));
- case 3 :
- return function(t, e) {
- if ("string" == typeof t.timestampValue && "string" == typeof e.timestampValue && t.timestampValue.length === e.timestampValue.length)
-
- return t.timestampValue === e.timestampValue;
- const n = De(t.timestampValue), s = De(e.timestampValue);
- return n.seconds === s.seconds && n.nanos === s.nanos;
- }(t, e);
- case 5 :
- return t.stringValue === e.stringValue;
- case 6 :
- return function(t, e) {
- return xe(t.bytesValue).isEqual(xe(e.bytesValue));
- }(t, e);
- case 7 :
- return t.referenceValue === e.referenceValue;
- case 8 :
- return function(t, e) {
- return Ce(t.geoPointValue.latitude) === Ce(e.geoPointValue.latitude) && Ce(t.geoPointValue.longitude) === Ce(e.geoPointValue.longitude);
- }(t, e);
- case 2 :
- return function(t, e) {
- if ("integerValue" in t && "integerValue" in e) return Ce(t.integerValue) === Ce(e.integerValue);
- if ("doubleValue" in t && "doubleValue" in e) {
- const n = Ce(t.doubleValue), s = Ce(e.doubleValue);
- return n === s ? Bt(n) === Bt(s) : isNaN(n) && isNaN(s);
- }
- return !1;
- }(t, e);
- case 9 :
- return nt(t.arrayValue.values || [], e.arrayValue.values || [], qe);
- case 10 :
- return function(t, e) {
- const n = t.mapValue.fields || {}, s = e.mapValue.fields || {};
- if (me(n) !== me(s)) return !1;
- for (const t in n) if (n.hasOwnProperty(t) && (void 0 === s[t] || !qe(n[t], s[t]))) return !1;
- return !0;
- }
- (t, e);
- default:
- return O();
- }
- }
- function Ue(t, e) {
- return void 0 !== (t.values || []).find((t => qe(t, e)));
- }
- function Ke(t, e) {
- if (t === e) return 0;
- const n = Le(t), s = Le(e);
- if (n !== s) return et(n, s);
- switch (n) {
- case 0 :
- case 9007199254740991 :
- return 0;
- case 1 :
- return et(t.booleanValue, e.booleanValue);
- case 2 :
- return function(t, e) {
- const n = Ce(t.integerValue || t.doubleValue), s = Ce(e.integerValue || e.doubleValue);
- return n < s ? -1 : n > s ? 1 : n === s ? 0 :
-
- isNaN(n) ? isNaN(s) ? 0 : -1 : 1;
- }(t, e);
- case 3 :
- return Ge(t.timestampValue, e.timestampValue);
- case 4 :
- return Ge(Me(t), Me(e));
- case 5 :
- return et(t.stringValue, e.stringValue);
- case 6 :
- return function(t, e) {
- const n = xe(t), s = xe(e);
- return n.compareTo(s);
- }(t.bytesValue, e.bytesValue);
- case 7 :
- return function(t, e) {
- const n = t.split("/"), s = e.split("/");
- for (let t = 0; t < n.length && t < s.length; t++) {
- const e = et(n[t], s[t]);
- if (0 !== e) return e;
- }
- return et(n.length, s.length);
- }(t.referenceValue, e.referenceValue);
- case 8 :
- return function(t, e) {
- const n = et(Ce(t.latitude), Ce(e.latitude));
- if (0 !== n) return n;
- return et(Ce(t.longitude), Ce(e.longitude));
- }(t.geoPointValue, e.geoPointValue);
- case 9 :
- return function(t, e) {
- const n = t.values || [], s = e.values || [];
- for (let t = 0; t < n.length && t < s.length; ++t) {
- const e = Ke(n[t], s[t]);
- if (e) return e;
- }
- return et(n.length, s.length);
- }(t.arrayValue, e.arrayValue);
- case 10 :
- return function(t, e) {
- if (t === Fe.mapValue && e === Fe.mapValue) return 0;
- if (t === Fe.mapValue) return 1;
- if (e === Fe.mapValue) return -1;
- const n = t.fields || {}, s = Object.keys(n), i = e.fields || {}, r = Object.keys(i);
-
-
-
-
- s.sort(), r.sort();
- for (let t = 0; t < s.length && t < r.length; ++t) {
- const e = et(s[t], r[t]);
- if (0 !== e) return e;
- const o = Ke(n[s[t]], i[r[t]]);
- if (0 !== o) return o;
- }
- return et(s.length, r.length);
- }
-
- (t.mapValue, e.mapValue);
- default:
- throw O();
- }
- }
- function Ge(t, e) {
- if ("string" == typeof t && "string" == typeof e && t.length === e.length) return et(t, e);
- const n = De(t), s = De(e), i = et(n.seconds, s.seconds);
- return 0 !== i ? i : et(n.nanos, s.nanos);
- }
- function Qe(t) {
- return je(t);
- }
- function je(t) {
- return "nullValue" in t ? "null" : "booleanValue" in t ? "" + t.booleanValue : "integerValue" in t ? "" + t.integerValue : "doubleValue" in t ? "" + t.doubleValue : "timestampValue" in t ? function(t) {
- const e = De(t);
- return `time(${e.seconds},${e.nanos})`;
- }(t.timestampValue) : "stringValue" in t ? t.stringValue : "bytesValue" in t ? xe(t.bytesValue).toBase64() : "referenceValue" in t ? (n = t.referenceValue,
- ht.fromName(n).toString()) : "geoPointValue" in t ? `geo(${(e = t.geoPointValue).latitude},${e.longitude})` : "arrayValue" in t ? function(t) {
- let e = "[", n = !0;
- for (const s of t.values || []) n ? n = !1 : e += ",", e += je(s);
- return e + "]";
- }
-
- (t.arrayValue) : "mapValue" in t ? function(t) {
-
-
- const e = Object.keys(t.fields || {}).sort();
- let n = "{", s = !0;
- for (const i of e) s ? s = !1 : n += ",", n += `${i}:${je(t.fields[i])}`;
- return n + "}";
- }(t.mapValue) : O();
- var e, n;
- }
- function ze(t) {
- switch (Le(t)) {
- case 0 :
- case 1 :
- return 4;
- case 2 :
- return 8;
- case 3 :
- case 8 :
-
- return 16;
- case 4 :
- const e = ke(t);
- return e ? 16 + ze(e) : 16;
- case 5 :
-
-
-
- return 2 * t.stringValue.length;
- case 6 :
- return xe(t.bytesValue).approximateByteSize();
- case 7 :
- return t.referenceValue.length;
- case 9 :
- return (t.arrayValue.values || []).reduce(((t, e) => t + ze(e)), 0);
- case 10 :
- return function(t) {
- let e = 0;
- return ge(t.fields, ((t, n) => {
- e += t.length + ze(n);
- })), e;
- }(t.mapValue);
- default:
- throw O();
- }
- }
- function We(t, e) {
- return {
- referenceValue: `projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`
- };
- }
- function He(t) {
- return !!t && "integerValue" in t;
- }
- function Je(t) {
- return !!t && "arrayValue" in t;
- }
- function Ye(t) {
- return !!t && "nullValue" in t;
- }
- function Xe(t) {
- return !!t && "doubleValue" in t && isNaN(Number(t.doubleValue));
- }
- function Ze(t) {
- return !!t && "mapValue" in t;
- }
- function tn(t) {
- if (t.geoPointValue) return {
- geoPointValue: Object.assign({}, t.geoPointValue)
- };
- if (t.timestampValue && "object" == typeof t.timestampValue) return {
- timestampValue: Object.assign({}, t.timestampValue)
- };
- if (t.mapValue) {
- const e = {
- mapValue: {
- fields: {}
- }
- };
- return ge(t.mapValue.fields, ((t, n) => e.mapValue.fields[t] = tn(n))), e;
- }
- if (t.arrayValue) {
- const e = {
- arrayValue: {
- values: []
- }
- };
- for (let n = 0; n < (t.arrayValue.values || []).length; ++n) e.arrayValue.values[n] = tn(t.arrayValue.values[n]);
- return e;
- }
- return Object.assign({}, t);
- }
- function en(t) {
- return "__max__" === (((t.mapValue || {}).fields || {}).__type__ || {}).stringValue;
- }
- function nn(t) {
- return "nullValue" in t ? Be : "booleanValue" in t ? {
- booleanValue: !1
- } : "integerValue" in t || "doubleValue" in t ? {
- doubleValue: NaN
- } : "timestampValue" in t ? {
- timestampValue: {
- seconds: Number.MIN_SAFE_INTEGER
- }
- } : "stringValue" in t ? {
- stringValue: ""
- } : "bytesValue" in t ? {
- bytesValue: ""
- } : "referenceValue" in t ? We(Oe.empty(), ht.empty()) : "geoPointValue" in t ? {
- geoPointValue: {
- latitude: -90,
- longitude: -180
- }
- } : "arrayValue" in t ? {
- arrayValue: {}
- } : "mapValue" in t ? {
- mapValue: {}
- } : O();
- }
- function sn(t) {
- return "nullValue" in t ? {
- booleanValue: !1
- } : "booleanValue" in t ? {
- doubleValue: NaN
- } : "integerValue" in t || "doubleValue" in t ? {
- timestampValue: {
- seconds: Number.MIN_SAFE_INTEGER
- }
- } : "timestampValue" in t ? {
- stringValue: ""
- } : "stringValue" in t ? {
- bytesValue: ""
- } : "bytesValue" in t ? We(Oe.empty(), ht.empty()) : "referenceValue" in t ? {
- geoPointValue: {
- latitude: -90,
- longitude: -180
- }
- } : "geoPointValue" in t ? {
- arrayValue: {}
- } : "arrayValue" in t ? {
- mapValue: {}
- } : "mapValue" in t ? Fe : O();
- }
- function rn(t, e) {
- const n = Ke(t.value, e.value);
- return 0 !== n ? n : t.inclusive && !e.inclusive ? -1 : !t.inclusive && e.inclusive ? 1 : 0;
- }
- function on(t, e) {
- const n = Ke(t.value, e.value);
- return 0 !== n ? n : t.inclusive && !e.inclusive ? 1 : !t.inclusive && e.inclusive ? -1 : 0;
- }
- class un {
- constructor(t) {
- this.value = t;
- }
- static empty() {
- return new un({
- mapValue: {}
- });
- }
-
- field(t) {
- if (t.isEmpty()) return this.value;
- {
- let e = this.value;
- for (let n = 0; n < t.length - 1; ++n) if (e = (e.mapValue.fields || {})[t.get(n)],
- !Ze(e)) return null;
- return e = (e.mapValue.fields || {})[t.lastSegment()], e || null;
- }
- }
-
- set(t, e) {
- this.getFieldsMap(t.popLast())[t.lastSegment()] = tn(e);
- }
-
- setAll(t) {
- let e = at.emptyPath(), n = {}, s = [];
- t.forEach(((t, i) => {
- if (!e.isImmediateParentOf(i)) {
-
- const t = this.getFieldsMap(e);
- this.applyChanges(t, n, s), n = {}, s = [], e = i.popLast();
- }
- t ? n[i.lastSegment()] = tn(t) : s.push(i.lastSegment());
- }));
- const i = this.getFieldsMap(e);
- this.applyChanges(i, n, s);
- }
-
- delete(t) {
- const e = this.field(t.popLast());
- Ze(e) && e.mapValue.fields && delete e.mapValue.fields[t.lastSegment()];
- }
- isEqual(t) {
- return qe(this.value, t.value);
- }
-
- getFieldsMap(t) {
- let e = this.value;
- e.mapValue.fields || (e.mapValue = {
- fields: {}
- });
- for (let n = 0; n < t.length; ++n) {
- let s = e.mapValue.fields[t.get(n)];
- Ze(s) && s.mapValue.fields || (s = {
- mapValue: {
- fields: {}
- }
- }, e.mapValue.fields[t.get(n)] = s), e = s;
- }
- return e.mapValue.fields;
- }
-
- applyChanges(t, e, n) {
- ge(e, ((e, n) => t[e] = n));
- for (const e of n) delete t[e];
- }
- clone() {
- return new un(tn(this.value));
- }
- }
- function cn(t) {
- const e = [];
- return ge(t.fields, ((t, n) => {
- const s = new at([ t ]);
- if (Ze(n)) {
- const t = cn(n.mapValue).fields;
- if (0 === t.length)
-
- e.push(s); else
-
-
- for (const n of t) e.push(s.child(n));
- } else
-
-
- e.push(s);
- })), new Re(e);
- }
- class an {
- constructor(t, e, n, s, i, r, o) {
- this.key = t, this.documentType = e, this.version = n, this.readTime = s, this.createTime = i,
- this.data = r, this.documentState = o;
- }
-
- static newInvalidDocument(t) {
- return new an(t, 0 ,
- rt.min(),
- rt.min(),
- rt.min(), un.empty(), 0 );
- }
-
- static newFoundDocument(t, e, n, s) {
- return new an(t, 1 ,
- e,
- rt.min(),
- n, s, 0 );
- }
- static newNoDocument(t, e) {
- return new an(t, 2 ,
- e,
- rt.min(),
- rt.min(), un.empty(), 0 );
- }
-
- static newUnknownDocument(t, e) {
- return new an(t, 3 ,
- e,
- rt.min(),
- rt.min(), un.empty(), 2 );
- }
-
- convertToFoundDocument(t, e) {
-
-
-
-
-
- return !this.createTime.isEqual(rt.min()) || 2 !== this.documentType && 0 !== this.documentType || (this.createTime = t),
- this.version = t, this.documentType = 1 , this.data = e,
- this.documentState = 0 , this;
- }
-
- convertToNoDocument(t) {
- return this.version = t, this.documentType = 2 ,
- this.data = un.empty(), this.documentState = 0 , this;
- }
-
- convertToUnknownDocument(t) {
- return this.version = t, this.documentType = 3 ,
- this.data = un.empty(), this.documentState = 2 ,
- this;
- }
- setHasCommittedMutations() {
- return this.documentState = 2 , this;
- }
- setHasLocalMutations() {
- return this.documentState = 1 , this.version = rt.min(),
- this;
- }
- setReadTime(t) {
- return this.readTime = t, this;
- }
- get hasLocalMutations() {
- return 1 === this.documentState;
- }
- get hasCommittedMutations() {
- return 2 === this.documentState;
- }
- get hasPendingWrites() {
- return this.hasLocalMutations || this.hasCommittedMutations;
- }
- isValidDocument() {
- return 0 !== this.documentType;
- }
- isFoundDocument() {
- return 1 === this.documentType;
- }
- isNoDocument() {
- return 2 === this.documentType;
- }
- isUnknownDocument() {
- return 3 === this.documentType;
- }
- isEqual(t) {
- return t instanceof an && this.key.isEqual(t.key) && this.version.isEqual(t.version) && this.documentType === t.documentType && this.documentState === t.documentState && this.data.isEqual(t.data);
- }
- mutableCopy() {
- return new an(this.key, this.documentType, this.version, this.readTime, this.createTime, this.data.clone(), this.documentState);
- }
- toString() {
- return `Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {createTime: ${this.createTime}}), {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`;
- }
- }
- class hn {
- constructor(t, e) {
- this.position = t, this.inclusive = e;
- }
- }
- function ln(t, e, n) {
- let s = 0;
- for (let i = 0; i < t.position.length; i++) {
- const r = e[i], o = t.position[i];
- if (r.field.isKeyField()) s = ht.comparator(ht.fromName(o.referenceValue), n.key); else {
- s = Ke(o, n.data.field(r.field));
- }
- if ("desc" === r.dir && (s *= -1), 0 !== s) break;
- }
- return s;
- }
- function fn(t, e) {
- if (null === t) return null === e;
- if (null === e) return !1;
- if (t.inclusive !== e.inclusive || t.position.length !== e.position.length) return !1;
- for (let n = 0; n < t.position.length; n++) {
- if (!qe(t.position[n], e.position[n])) return !1;
- }
- return !0;
- }
- class dn {
- constructor(t, e = "asc" /* Direction.ASCENDING */) {
- this.field = t, this.dir = e;
- }
- }
- function wn(t, e) {
- return t.dir === e.dir && t.field.isEqual(e.field);
- }
- class _n {}
- class mn extends _n {
- constructor(t, e, n) {
- super(), this.field = t, this.op = e, this.value = n;
- }
-
- static create(t, e, n) {
- return t.isKeyField() ? "in" === e || "not-in" === e ? this.createKeyFieldInFilter(t, e, n) : new Pn(t, e, n) : "array-contains" === e ? new Dn(t, n) : "in" === e ? new Cn(t, n) : "not-in" === e ? new xn(t, n) : "array-contains-any" === e ? new Nn(t, n) : new mn(t, e, n);
- }
- static createKeyFieldInFilter(t, e, n) {
- return "in" === e ? new bn(t, n) : new Vn(t, n);
- }
- matches(t) {
- const e = t.data.field(this.field);
-
- return "!=" === this.op ? null !== e && this.matchesComparison(Ke(e, this.value)) : null !== e && Le(this.value) === Le(e) && this.matchesComparison(Ke(e, this.value));
-
- }
- matchesComparison(t) {
- switch (this.op) {
- case "<" :
- return t < 0;
- case "<=" :
- return t <= 0;
- case "==" :
- return 0 === t;
- case "!=" :
- return 0 !== t;
- case ">" :
- return t > 0;
- case ">=" :
- return t >= 0;
- default:
- return O();
- }
- }
- isInequality() {
- return [ "<" , "<=" , ">" , ">=" , "!=" , "not-in" ].indexOf(this.op) >= 0;
- }
- getFlattenedFilters() {
- return [ this ];
- }
- getFilters() {
- return [ this ];
- }
- getFirstInequalityField() {
- return this.isInequality() ? this.field : null;
- }
- }
- class gn extends _n {
- constructor(t, e) {
- super(), this.filters = t, this.op = e, this.lt = null;
- }
-
- static create(t, e) {
- return new gn(t, e);
- }
- matches(t) {
- return yn(this) ? void 0 === this.filters.find((e => !e.matches(t))) : void 0 !== this.filters.find((e => e.matches(t)));
- }
- getFlattenedFilters() {
- return null !== this.lt || (this.lt = this.filters.reduce(((t, e) => t.concat(e.getFlattenedFilters())), [])),
- this.lt;
- }
-
- getFilters() {
- return Object.assign([], this.filters);
- }
- getFirstInequalityField() {
- const t = this.ft((t => t.isInequality()));
- return null !== t ? t.field : null;
- }
-
-
-
- ft(t) {
- for (const e of this.getFlattenedFilters()) if (t(e)) return e;
- return null;
- }
- }
- function yn(t) {
- return "and" === t.op;
- }
- function pn(t) {
- return "or" === t.op;
- }
- function In(t) {
- return Tn(t) && yn(t);
- }
- function Tn(t) {
- for (const e of t.filters) if (e instanceof gn) return !1;
- return !0;
- }
- function En(t) {
- if (t instanceof mn)
-
-
-
- return t.field.canonicalString() + t.op.toString() + Qe(t.value);
- if (In(t))
-
-
-
-
-
-
- return t.filters.map((t => En(t))).join(",");
- {
-
- const e = t.filters.map((t => En(t))).join(",");
- return `${t.op}(${e})`;
- }
- }
- function An(t, e) {
- return t instanceof mn ? function(t, e) {
- return e instanceof mn && t.op === e.op && t.field.isEqual(e.field) && qe(t.value, e.value);
- }(t, e) : t instanceof gn ? function(t, e) {
- if (e instanceof gn && t.op === e.op && t.filters.length === e.filters.length) {
- return t.filters.reduce(((t, n, s) => t && An(n, e.filters[s])), !0);
- }
- return !1;
- }
-
- (t, e) : void O();
- }
- function vn(t, e) {
- const n = t.filters.concat(e);
- return gn.create(n, t.op);
- }
- function Rn(t) {
- return t instanceof mn ? function(t) {
- return `${t.field.canonicalString()} ${t.op} ${Qe(t.value)}`;
- }
- (t) : t instanceof gn ? function(t) {
- return t.op.toString() + " {" + t.getFilters().map(Rn).join(" ,") + "}";
- }(t) : "Filter";
- }
- class Pn extends mn {
- constructor(t, e, n) {
- super(t, e, n), this.key = ht.fromName(n.referenceValue);
- }
- matches(t) {
- const e = ht.comparator(t.key, this.key);
- return this.matchesComparison(e);
- }
- }
- class bn extends mn {
- constructor(t, e) {
- super(t, "in" , e), this.keys = Sn("in" , e);
- }
- matches(t) {
- return this.keys.some((e => e.isEqual(t.key)));
- }
- }
- class Vn extends mn {
- constructor(t, e) {
- super(t, "not-in" , e), this.keys = Sn("not-in" , e);
- }
- matches(t) {
- return !this.keys.some((e => e.isEqual(t.key)));
- }
- }
- function Sn(t, e) {
- var n;
- return ((null === (n = e.arrayValue) || void 0 === n ? void 0 : n.values) || []).map((t => ht.fromName(t.referenceValue)));
- }
- class Dn extends mn {
- constructor(t, e) {
- super(t, "array-contains" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return Je(e) && Ue(e.arrayValue, this.value);
- }
- }
- class Cn extends mn {
- constructor(t, e) {
- super(t, "in" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return null !== e && Ue(this.value.arrayValue, e);
- }
- }
- class xn extends mn {
- constructor(t, e) {
- super(t, "not-in" , e);
- }
- matches(t) {
- if (Ue(this.value.arrayValue, {
- nullValue: "NULL_VALUE"
- })) return !1;
- const e = t.data.field(this.field);
- return null !== e && !Ue(this.value.arrayValue, e);
- }
- }
- class Nn extends mn {
- constructor(t, e) {
- super(t, "array-contains-any" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return !(!Je(e) || !e.arrayValue.values) && e.arrayValue.values.some((t => Ue(this.value.arrayValue, t)));
- }
- }
- class kn {
- constructor(t, e = null, n = [], s = [], i = null, r = null, o = null) {
- this.path = t, this.collectionGroup = e, this.orderBy = n, this.filters = s, this.limit = i,
- this.startAt = r, this.endAt = o, this.dt = null;
- }
- }
- function Mn(t, e = null, n = [], s = [], i = null, r = null, o = null) {
- return new kn(t, e, n, s, i, r, o);
- }
- function $n(t) {
- const e = L(t);
- if (null === e.dt) {
- let t = e.path.canonicalString();
- null !== e.collectionGroup && (t += "|cg:" + e.collectionGroup), t += "|f:", t += e.filters.map((t => En(t))).join(","),
- t += "|ob:", t += e.orderBy.map((t => function(t) {
-
- return t.field.canonicalString() + t.dir;
- }(t))).join(","), Ft(e.limit) || (t += "|l:", t += e.limit), e.startAt && (t += "|lb:",
- t += e.startAt.inclusive ? "b:" : "a:", t += e.startAt.position.map((t => Qe(t))).join(",")),
- e.endAt && (t += "|ub:", t += e.endAt.inclusive ? "a:" : "b:", t += e.endAt.position.map((t => Qe(t))).join(",")),
- e.dt = t;
- }
- return e.dt;
- }
- function On(t, e) {
- if (t.limit !== e.limit) return !1;
- if (t.orderBy.length !== e.orderBy.length) return !1;
- for (let n = 0; n < t.orderBy.length; n++) if (!wn(t.orderBy[n], e.orderBy[n])) return !1;
- if (t.filters.length !== e.filters.length) return !1;
- for (let n = 0; n < t.filters.length; n++) if (!An(t.filters[n], e.filters[n])) return !1;
- return t.collectionGroup === e.collectionGroup && (!!t.path.isEqual(e.path) && (!!fn(t.startAt, e.startAt) && fn(t.endAt, e.endAt)));
- }
- function Fn(t) {
- return ht.isDocumentKey(t.path) && null === t.collectionGroup && 0 === t.filters.length;
- }
- function Bn(t, e) {
- return t.filters.filter((t => t instanceof mn && t.field.isEqual(e)));
- }
- function Ln(t, e, n) {
- let s = Be, i = !0;
-
- for (const n of Bn(t, e)) {
- let t = Be, e = !0;
- switch (n.op) {
- case "<" :
- case "<=" :
- t = nn(n.value);
- break;
- case "==" :
- case "in" :
- case ">=" :
- t = n.value;
- break;
- case ">" :
- t = n.value, e = !1;
- break;
- case "!=" :
- case "not-in" :
- t = Be;
-
- }
- rn({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: e
- }) < 0 && (s = t, i = e);
- }
-
-
- if (null !== n) for (let r = 0; r < t.orderBy.length; ++r) {
- if (t.orderBy[r].field.isEqual(e)) {
- const t = n.position[r];
- rn({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: n.inclusive
- }) < 0 && (s = t, i = n.inclusive);
- break;
- }
- }
- return {
- value: s,
- inclusive: i
- };
- }
- function qn(t, e, n) {
- let s = Fe, i = !0;
-
- for (const n of Bn(t, e)) {
- let t = Fe, e = !0;
- switch (n.op) {
- case ">=" :
- case ">" :
- t = sn(n.value), e = !1;
- break;
- case "==" :
- case "in" :
- case "<=" :
- t = n.value;
- break;
- case "<" :
- t = n.value, e = !1;
- break;
- case "!=" :
- case "not-in" :
- t = Fe;
-
- }
- on({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: e
- }) > 0 && (s = t, i = e);
- }
-
-
- if (null !== n) for (let r = 0; r < t.orderBy.length; ++r) {
- if (t.orderBy[r].field.isEqual(e)) {
- const t = n.position[r];
- on({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: n.inclusive
- }) > 0 && (s = t, i = n.inclusive);
- break;
- }
- }
- return {
- value: s,
- inclusive: i
- };
- }
- class Un {
-
- constructor(t, e = null, n = [], s = [], i = null, r = "F" /* LimitType.First */ , o = null, u = null) {
- this.path = t, this.collectionGroup = e, this.explicitOrderBy = n, this.filters = s,
- this.limit = i, this.limitType = r, this.startAt = o, this.endAt = u, this.wt = null,
-
- this._t = null, this.startAt, this.endAt;
- }
- }
- function Kn(t, e, n, s, i, r, o, u) {
- return new Un(t, e, n, s, i, r, o, u);
- }
- function Gn(t) {
- return new Un(t);
- }
- function Qn(t) {
- return 0 === t.filters.length && null === t.limit && null == t.startAt && null == t.endAt && (0 === t.explicitOrderBy.length || 1 === t.explicitOrderBy.length && t.explicitOrderBy[0].field.isKeyField());
- }
- function jn(t) {
- return t.explicitOrderBy.length > 0 ? t.explicitOrderBy[0].field : null;
- }
- function zn(t) {
- for (const e of t.filters) {
- const t = e.getFirstInequalityField();
- if (null !== t) return t;
- }
- return null;
- }
- function Wn(t) {
- return null !== t.collectionGroup;
- }
- function Hn(t) {
- const e = L(t);
- if (null === e.wt) {
- e.wt = [];
- const t = zn(e), n = jn(e);
- if (null !== t && null === n)
-
-
-
- t.isKeyField() || e.wt.push(new dn(t)), e.wt.push(new dn(at.keyField(), "asc" )); else {
- let t = !1;
- for (const n of e.explicitOrderBy) e.wt.push(n), n.field.isKeyField() && (t = !0);
- if (!t) {
-
-
- const t = e.explicitOrderBy.length > 0 ? e.explicitOrderBy[e.explicitOrderBy.length - 1].dir : "asc" ;
- e.wt.push(new dn(at.keyField(), t));
- }
- }
- }
- return e.wt;
- }
- function Jn(t) {
- const e = L(t);
- if (!e._t) if ("F" === e.limitType) e._t = Mn(e.path, e.collectionGroup, Hn(e), e.filters, e.limit, e.startAt, e.endAt); else {
-
- const t = [];
- for (const n of Hn(e)) {
- const e = "desc" === n.dir ? "asc" : "desc" ;
- t.push(new dn(n.field, e));
- }
-
- const n = e.endAt ? new hn(e.endAt.position, e.endAt.inclusive) : null, s = e.startAt ? new hn(e.startAt.position, e.startAt.inclusive) : null;
-
- e._t = Mn(e.path, e.collectionGroup, t, e.filters, e.limit, n, s);
- }
- return e._t;
- }
- function Yn(t, e) {
- e.getFirstInequalityField(), zn(t);
- const n = t.filters.concat([ e ]);
- return new Un(t.path, t.collectionGroup, t.explicitOrderBy.slice(), n, t.limit, t.limitType, t.startAt, t.endAt);
- }
- function Xn(t, e, n) {
- return new Un(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), e, n, t.startAt, t.endAt);
- }
- function Zn(t, e) {
- return On(Jn(t), Jn(e)) && t.limitType === e.limitType;
- }
- function ts(t) {
- return `${$n(Jn(t))}|lt:${t.limitType}`;
- }
- function es(t) {
- return `Query(target=${function(t) {
- let e = t.path.canonicalString();
- return null !== t.collectionGroup && (e += " collectionGroup=" + t.collectionGroup),
- t.filters.length > 0 && (e += `, filters: [${t.filters.map((t => Rn(t))).join(", ")}]`),
- Ft(t.limit) || (e += ", limit: " + t.limit), t.orderBy.length > 0 && (e += `, orderBy: [${t.orderBy.map((t => function(t) {
- return `${t.field.canonicalString()} (${t.dir})`;
- }(t))).join(", ")}]`), t.startAt && (e += ", startAt: ", e += t.startAt.inclusive ? "b:" : "a:",
- e += t.startAt.position.map((t => Qe(t))).join(",")), t.endAt && (e += ", endAt: ",
- e += t.endAt.inclusive ? "a:" : "b:", e += t.endAt.position.map((t => Qe(t))).join(",")),
- `Target(${e})`;
- }(Jn(t))}; limitType=${t.limitType})`;
- }
- function ns(t, e) {
- return e.isFoundDocument() && function(t, e) {
- const n = e.key.path;
- return null !== t.collectionGroup ? e.key.hasCollectionId(t.collectionGroup) && t.path.isPrefixOf(n) : ht.isDocumentKey(t.path) ? t.path.isEqual(n) : t.path.isImmediateParentOf(n);
- }
-
- (t, e) && function(t, e) {
-
-
-
-
-
-
- for (const n of Hn(t))
-
- if (!n.field.isKeyField() && null === e.data.field(n.field)) return !1;
- return !0;
- }(t, e) && function(t, e) {
- for (const n of t.filters) if (!n.matches(e)) return !1;
- return !0;
- }
- (t, e) && function(t, e) {
- if (t.startAt && !
-
- function(t, e, n) {
- const s = ln(t, e, n);
- return t.inclusive ? s <= 0 : s < 0;
- }(t.startAt, Hn(t), e)) return !1;
- if (t.endAt && !function(t, e, n) {
- const s = ln(t, e, n);
- return t.inclusive ? s >= 0 : s > 0;
- }(t.endAt, Hn(t), e)) return !1;
- return !0;
- }
-
- (t, e);
- }
- function ss(t) {
- return t.collectionGroup || (t.path.length % 2 == 1 ? t.path.lastSegment() : t.path.get(t.path.length - 2));
- }
- function is(t) {
- return (e, n) => {
- let s = !1;
- for (const i of Hn(t)) {
- const t = rs(i, e, n);
- if (0 !== t) return t;
- s = s || i.field.isKeyField();
- }
- return 0;
- };
- }
- function rs(t, e, n) {
- const s = t.field.isKeyField() ? ht.comparator(e.key, n.key) : function(t, e, n) {
- const s = e.data.field(t), i = n.data.field(t);
- return null !== s && null !== i ? Ke(s, i) : O();
- }(t.field, e, n);
- switch (t.dir) {
- case "asc" :
- return s;
- case "desc" :
- return -1 * s;
- default:
- return O();
- }
- }
- class os {
- constructor(t, e) {
- this.mapKeyFn = t, this.equalsFn = e,
-
- this.inner = {},
-
- this.innerSize = 0;
- }
- get(t) {
- const e = this.mapKeyFn(t), n = this.inner[e];
- if (void 0 !== n) for (const [e, s] of n) if (this.equalsFn(e, t)) return s;
- }
- has(t) {
- return void 0 !== this.get(t);
- }
- set(t, e) {
- const n = this.mapKeyFn(t), s = this.inner[n];
- if (void 0 === s) return this.inner[n] = [ [ t, e ] ], void this.innerSize++;
- for (let n = 0; n < s.length; n++) if (this.equalsFn(s[n][0], t))
-
- return void (s[n] = [ t, e ]);
- s.push([ t, e ]), this.innerSize++;
- }
-
- delete(t) {
- const e = this.mapKeyFn(t), n = this.inner[e];
- if (void 0 === n) return !1;
- for (let s = 0; s < n.length; s++) if (this.equalsFn(n[s][0], t)) return 1 === n.length ? delete this.inner[e] : n.splice(s, 1),
- this.innerSize--, !0;
- return !1;
- }
- forEach(t) {
- ge(this.inner, ((e, n) => {
- for (const [e, s] of n) t(e, s);
- }));
- }
- isEmpty() {
- return ye(this.inner);
- }
- size() {
- return this.innerSize;
- }
- }
- const us = new pe(ht.comparator);
- function cs() {
- return us;
- }
- const as = new pe(ht.comparator);
- function hs(...t) {
- let e = as;
- for (const n of t) e = e.insert(n.key, n);
- return e;
- }
- function ls(t) {
- let e = as;
- return t.forEach(((t, n) => e = e.insert(t, n.overlayedDocument))), e;
- }
- function fs() {
- return ws();
- }
- function ds() {
- return ws();
- }
- function ws() {
- return new os((t => t.toString()), ((t, e) => t.isEqual(e)));
- }
- const _s = new pe(ht.comparator);
- const ms = new Ee(ht.comparator);
- function gs(...t) {
- let e = ms;
- for (const n of t) e = e.add(n);
- return e;
- }
- const ys = new Ee(et);
- function ps() {
- return ys;
- }
- function Is(t, e) {
- if (t.useProto3Json) {
- if (isNaN(e)) return {
- doubleValue: "NaN"
- };
- if (e === 1 / 0) return {
- doubleValue: "Infinity"
- };
- if (e === -1 / 0) return {
- doubleValue: "-Infinity"
- };
- }
- return {
- doubleValue: Bt(e) ? "-0" : e
- };
- }
- function Ts(t) {
- return {
- integerValue: "" + t
- };
- }
- function Es(t, e) {
- return Lt(e) ? Ts(e) : Is(t, e);
- }
- class As {
- constructor() {
-
-
- this._ = void 0;
- }
- }
- function vs(t, e, n) {
- return t instanceof bs ? function(t, e) {
- const n = {
- fields: {
- __type__: {
- stringValue: "server_timestamp"
- },
- __local_write_time__: {
- timestampValue: {
- seconds: t.seconds,
- nanos: t.nanoseconds
- }
- }
- }
- };
-
-
-
-
-
-
-
-
- return e && Ne(e) && (e = ke(e)), e && (n.fields.__previous_value__ = e),
- {
- mapValue: n
- };
- }(n, e) : t instanceof Vs ? Ss(t, e) : t instanceof Ds ? Cs(t, e) : function(t, e) {
-
-
-
- const n = Ps(t, e), s = Ns(n) + Ns(t.gt);
- return He(n) && He(t.gt) ? Ts(s) : Is(t.serializer, s);
- }(t, e);
- }
- function Rs(t, e, n) {
-
-
-
- return t instanceof Vs ? Ss(t, e) : t instanceof Ds ? Cs(t, e) : n;
- }
- function Ps(t, e) {
- return t instanceof xs ? He(n = e) || function(t) {
- return !!t && "doubleValue" in t;
- }
- (n) ? e : {
- integerValue: 0
- } : null;
- var n;
- }
- class bs extends As {}
- class Vs extends As {
- constructor(t) {
- super(), this.elements = t;
- }
- }
- function Ss(t, e) {
- const n = ks(e);
- for (const e of t.elements) n.some((t => qe(t, e))) || n.push(e);
- return {
- arrayValue: {
- values: n
- }
- };
- }
- class Ds extends As {
- constructor(t) {
- super(), this.elements = t;
- }
- }
- function Cs(t, e) {
- let n = ks(e);
- for (const e of t.elements) n = n.filter((t => !qe(t, e)));
- return {
- arrayValue: {
- values: n
- }
- };
- }
- class xs extends As {
- constructor(t, e) {
- super(), this.serializer = t, this.gt = e;
- }
- }
- function Ns(t) {
- return Ce(t.integerValue || t.doubleValue);
- }
- function ks(t) {
- return Je(t) && t.arrayValue.values ? t.arrayValue.values.slice() : [];
- }
- class Ms {
- constructor(t, e) {
- this.field = t, this.transform = e;
- }
- }
- function $s(t, e) {
- return t.field.isEqual(e.field) && function(t, e) {
- return t instanceof Vs && e instanceof Vs || t instanceof Ds && e instanceof Ds ? nt(t.elements, e.elements, qe) : t instanceof xs && e instanceof xs ? qe(t.gt, e.gt) : t instanceof bs && e instanceof bs;
- }(t.transform, e.transform);
- }
- class Os {
- constructor(
- /**
- * The version at which the mutation was committed:
- *
- * - For most operations, this is the updateTime in the WriteResult.
- * - For deletes, the commitTime of the WriteResponse (because deletes are
- * not stored and have no updateTime).
- *
- * Note that these versions can be different: No-op writes will not change
- * the updateTime even though the commitTime advances.
- */
- t,
- /**
- * The resulting fields returned from the backend after a mutation
- * containing field transforms has been committed. Contains one FieldValue
- * for each FieldTransform that was in the mutation.
- *
- * Will be empty if the mutation did not contain any field transforms.
- */
- e) {
- this.version = t, this.transformResults = e;
- }
- }
- class Fs {
- constructor(t, e) {
- this.updateTime = t, this.exists = e;
- }
- static none() {
- return new Fs;
- }
- static exists(t) {
- return new Fs(void 0, t);
- }
- static updateTime(t) {
- return new Fs(t);
- }
- get isNone() {
- return void 0 === this.updateTime && void 0 === this.exists;
- }
- isEqual(t) {
- return this.exists === t.exists && (this.updateTime ? !!t.updateTime && this.updateTime.isEqual(t.updateTime) : !t.updateTime);
- }
- }
- function Bs(t, e) {
- return void 0 !== t.updateTime ? e.isFoundDocument() && e.version.isEqual(t.updateTime) : void 0 === t.exists || t.exists === e.isFoundDocument();
- }
- class Ls {}
- function qs(t, e) {
- if (!t.hasLocalMutations || e && 0 === e.fields.length) return null;
-
- if (null === e) return t.isNoDocument() ? new Ys(t.key, Fs.none()) : new js(t.key, t.data, Fs.none());
- {
- const n = t.data, s = un.empty();
- let i = new Ee(at.comparator);
- for (let t of e.fields) if (!i.has(t)) {
- let e = n.field(t);
-
-
-
-
-
-
-
-
-
- null === e && t.length > 1 && (t = t.popLast(), e = n.field(t)), null === e ? s.delete(t) : s.set(t, e),
- i = i.add(t);
- }
- return new zs(t.key, s, new Re(i.toArray()), Fs.none());
- }
- }
- function Us(t, e, n) {
- t instanceof js ? function(t, e, n) {
-
-
-
- const s = t.value.clone(), i = Hs(t.fieldTransforms, e, n.transformResults);
- s.setAll(i), e.convertToFoundDocument(n.version, s).setHasCommittedMutations();
- }(t, e, n) : t instanceof zs ? function(t, e, n) {
- if (!Bs(t.precondition, e))
-
-
-
-
- return void e.convertToUnknownDocument(n.version);
- const s = Hs(t.fieldTransforms, e, n.transformResults), i = e.data;
- i.setAll(Ws(t)), i.setAll(s), e.convertToFoundDocument(n.version, i).setHasCommittedMutations();
- }(t, e, n) : function(t, e, n) {
-
-
-
- e.convertToNoDocument(n.version).setHasCommittedMutations();
- }(0, e, n);
- }
- function Ks(t, e, n, s) {
- return t instanceof js ? function(t, e, n, s) {
- if (!Bs(t.precondition, e))
-
-
- return n;
- const i = t.value.clone(), r = Js(t.fieldTransforms, s, e);
- return i.setAll(r), e.convertToFoundDocument(e.version, i).setHasLocalMutations(),
- null;
-
- }
-
- (t, e, n, s) : t instanceof zs ? function(t, e, n, s) {
- if (!Bs(t.precondition, e)) return n;
- const i = Js(t.fieldTransforms, s, e), r = e.data;
- if (r.setAll(Ws(t)), r.setAll(i), e.convertToFoundDocument(e.version, r).setHasLocalMutations(),
- null === n) return null;
- return n.unionWith(t.fieldMask.fields).unionWith(t.fieldTransforms.map((t => t.field)));
- }
-
- (t, e, n, s) : function(t, e, n) {
- if (Bs(t.precondition, e)) return e.convertToNoDocument(e.version).setHasLocalMutations(),
- null;
- return n;
- }
-
- (t, e, n);
- }
- function Gs(t, e) {
- let n = null;
- for (const s of t.fieldTransforms) {
- const t = e.data.field(s.field), i = Ps(s.transform, t || null);
- null != i && (null === n && (n = un.empty()), n.set(s.field, i));
- }
- return n || null;
- }
- function Qs(t, e) {
- return t.type === e.type && (!!t.key.isEqual(e.key) && (!!t.precondition.isEqual(e.precondition) && (!!function(t, e) {
- return void 0 === t && void 0 === e || !(!t || !e) && nt(t, e, ((t, e) => $s(t, e)));
- }(t.fieldTransforms, e.fieldTransforms) && (0 === t.type ? t.value.isEqual(e.value) : 1 !== t.type || t.data.isEqual(e.data) && t.fieldMask.isEqual(e.fieldMask)))));
- }
- class js extends Ls {
- constructor(t, e, n, s = []) {
- super(), this.key = t, this.value = e, this.precondition = n, this.fieldTransforms = s,
- this.type = 0 ;
- }
- getFieldMask() {
- return null;
- }
- }
- class zs extends Ls {
- constructor(t, e, n, s, i = []) {
- super(), this.key = t, this.data = e, this.fieldMask = n, this.precondition = s,
- this.fieldTransforms = i, this.type = 1 ;
- }
- getFieldMask() {
- return this.fieldMask;
- }
- }
- function Ws(t) {
- const e = new Map;
- return t.fieldMask.fields.forEach((n => {
- if (!n.isEmpty()) {
- const s = t.data.field(n);
- e.set(n, s);
- }
- })), e;
- }
- function Hs(t, e, n) {
- const s = new Map;
- F(t.length === n.length);
- for (let i = 0; i < n.length; i++) {
- const r = t[i], o = r.transform, u = e.data.field(r.field);
- s.set(r.field, Rs(o, u, n[i]));
- }
- return s;
- }
- function Js(t, e, n) {
- const s = new Map;
- for (const i of t) {
- const t = i.transform, r = n.data.field(i.field);
- s.set(i.field, vs(t, r, e));
- }
- return s;
- }
- class Ys extends Ls {
- constructor(t, e) {
- super(), this.key = t, this.precondition = e, this.type = 2 ,
- this.fieldTransforms = [];
- }
- getFieldMask() {
- return null;
- }
- }
- class Xs extends Ls {
- constructor(t, e) {
- super(), this.key = t, this.precondition = e, this.type = 3 ,
- this.fieldTransforms = [];
- }
- getFieldMask() {
- return null;
- }
- }
- class Zs {
-
- constructor(t, e, n, s) {
- this.batchId = t, this.localWriteTime = e, this.baseMutations = n, this.mutations = s;
- }
-
- applyToRemoteDocument(t, e) {
- const n = e.mutationResults;
- for (let e = 0; e < this.mutations.length; e++) {
- const s = this.mutations[e];
- if (s.key.isEqual(t.key)) {
- Us(s, t, n[e]);
- }
- }
- }
-
- applyToLocalView(t, e) {
-
-
- for (const n of this.baseMutations) n.key.isEqual(t.key) && (e = Ks(n, t, e, this.localWriteTime));
-
- for (const n of this.mutations) n.key.isEqual(t.key) && (e = Ks(n, t, e, this.localWriteTime));
- return e;
- }
-
- applyToLocalDocumentSet(t, e) {
-
-
-
- const n = ds();
- return this.mutations.forEach((s => {
- const i = t.get(s.key), r = i.overlayedDocument;
-
-
- let o = this.applyToLocalView(r, i.mutatedFields);
-
-
-
- o = e.has(s.key) ? null : o;
- const u = qs(r, o);
- null !== u && n.set(s.key, u), r.isValidDocument() || r.convertToNoDocument(rt.min());
- })), n;
- }
- keys() {
- return this.mutations.reduce(((t, e) => t.add(e.key)), gs());
- }
- isEqual(t) {
- return this.batchId === t.batchId && nt(this.mutations, t.mutations, ((t, e) => Qs(t, e))) && nt(this.baseMutations, t.baseMutations, ((t, e) => Qs(t, e)));
- }
- }
- class ti {
- constructor(t, e, n,
- /**
- * A pre-computed mapping from each mutated document to the resulting
- * version.
- */
- s) {
- this.batch = t, this.commitVersion = e, this.mutationResults = n, this.docVersions = s;
- }
-
- static from(t, e, n) {
- F(t.mutations.length === n.length);
- let s = _s;
- const i = t.mutations;
- for (let t = 0; t < i.length; t++) s = s.insert(i[t].key, n[t].version);
- return new ti(t, e, n, s);
- }
- }
- class ei {
- constructor(t, e) {
- this.largestBatchId = t, this.mutation = e;
- }
- getKey() {
- return this.mutation.key;
- }
- isEqual(t) {
- return null !== t && this.mutation === t.mutation;
- }
- toString() {
- return `Overlay{\n largestBatchId: ${this.largestBatchId},\n mutation: ${this.mutation.toString()}\n }`;
- }
- }
- class ni {
- constructor(t, e, n) {
- this.alias = t, this.yt = e, this.fieldPath = n;
- }
- }
- class si {
- constructor(t, e) {
- this.count = t, this.unchangedNames = e;
- }
- }
- var ii, ri;
- function oi(t) {
- switch (t) {
- default:
- return O();
- case q.CANCELLED:
- case q.UNKNOWN:
- case q.DEADLINE_EXCEEDED:
- case q.RESOURCE_EXHAUSTED:
- case q.INTERNAL:
- case q.UNAVAILABLE:
-
-
- case q.UNAUTHENTICATED:
- return !1;
- case q.INVALID_ARGUMENT:
- case q.NOT_FOUND:
- case q.ALREADY_EXISTS:
- case q.PERMISSION_DENIED:
- case q.FAILED_PRECONDITION:
-
-
-
- case q.ABORTED:
- case q.OUT_OF_RANGE:
- case q.UNIMPLEMENTED:
- case q.DATA_LOSS:
- return !0;
- }
- }
- function ui(t) {
- if (void 0 === t)
-
-
- return k("GRPC error has no .code"), q.UNKNOWN;
- switch (t) {
- case ii.OK:
- return q.OK;
- case ii.CANCELLED:
- return q.CANCELLED;
- case ii.UNKNOWN:
- return q.UNKNOWN;
- case ii.DEADLINE_EXCEEDED:
- return q.DEADLINE_EXCEEDED;
- case ii.RESOURCE_EXHAUSTED:
- return q.RESOURCE_EXHAUSTED;
- case ii.INTERNAL:
- return q.INTERNAL;
- case ii.UNAVAILABLE:
- return q.UNAVAILABLE;
- case ii.UNAUTHENTICATED:
- return q.UNAUTHENTICATED;
- case ii.INVALID_ARGUMENT:
- return q.INVALID_ARGUMENT;
- case ii.NOT_FOUND:
- return q.NOT_FOUND;
- case ii.ALREADY_EXISTS:
- return q.ALREADY_EXISTS;
- case ii.PERMISSION_DENIED:
- return q.PERMISSION_DENIED;
- case ii.FAILED_PRECONDITION:
- return q.FAILED_PRECONDITION;
- case ii.ABORTED:
- return q.ABORTED;
- case ii.OUT_OF_RANGE:
- return q.OUT_OF_RANGE;
- case ii.UNIMPLEMENTED:
- return q.UNIMPLEMENTED;
- case ii.DATA_LOSS:
- return q.DATA_LOSS;
- default:
- return O();
- }
- }
- (ri = ii || (ii = {}))[ri.OK = 0] = "OK", ri[ri.CANCELLED = 1] = "CANCELLED",
- ri[ri.UNKNOWN = 2] = "UNKNOWN", ri[ri.INVALID_ARGUMENT = 3] = "INVALID_ARGUMENT",
- ri[ri.DEADLINE_EXCEEDED = 4] = "DEADLINE_EXCEEDED", ri[ri.NOT_FOUND = 5] = "NOT_FOUND",
- ri[ri.ALREADY_EXISTS = 6] = "ALREADY_EXISTS", ri[ri.PERMISSION_DENIED = 7] = "PERMISSION_DENIED",
- ri[ri.UNAUTHENTICATED = 16] = "UNAUTHENTICATED", ri[ri.RESOURCE_EXHAUSTED = 8] = "RESOURCE_EXHAUSTED",
- ri[ri.FAILED_PRECONDITION = 9] = "FAILED_PRECONDITION", ri[ri.ABORTED = 10] = "ABORTED",
- ri[ri.OUT_OF_RANGE = 11] = "OUT_OF_RANGE", ri[ri.UNIMPLEMENTED = 12] = "UNIMPLEMENTED",
- ri[ri.INTERNAL = 13] = "INTERNAL", ri[ri.UNAVAILABLE = 14] = "UNAVAILABLE", ri[ri.DATA_LOSS = 15] = "DATA_LOSS";
- class ci {
- constructor() {
- this.onExistenceFilterMismatchCallbacks = new Map;
- }
-
- static get instance() {
- return ai;
- }
-
- static getOrCreateInstance() {
- return null === ai && (ai = new ci), ai;
- }
-
- onExistenceFilterMismatch(t) {
- const e = Symbol();
- return this.onExistenceFilterMismatchCallbacks.set(e, t), () => this.onExistenceFilterMismatchCallbacks.delete(e);
- }
-
- notifyOnExistenceFilterMismatch(t) {
- this.onExistenceFilterMismatchCallbacks.forEach((e => e(t)));
- }
- }
- let ai = null;
- function hi() {
- return new TextEncoder;
- }
- const li = new Integer([ 4294967295, 4294967295 ], 0);
- function fi(t) {
- const e = hi().encode(t), n = new Md5;
- return n.update(e), new Uint8Array(n.digest());
- }
- function di(t) {
- const e = new DataView(t.buffer), n = e.getUint32(0, !0), s = e.getUint32(4, !0), i = e.getUint32(8, !0), r = e.getUint32(12, !0);
- return [ new Integer([ n, s ], 0), new Integer([ i, r ], 0) ];
- }
- class wi {
- constructor(t, e, n) {
- if (this.bitmap = t, this.padding = e, this.hashCount = n, e < 0 || e >= 8) throw new _i(`Invalid padding: ${e}`);
- if (n < 0) throw new _i(`Invalid hash count: ${n}`);
- if (t.length > 0 && 0 === this.hashCount)
-
- throw new _i(`Invalid hash count: ${n}`);
- if (0 === t.length && 0 !== e)
-
- throw new _i(`Invalid padding when bitmap length is 0: ${e}`);
- this.It = 8 * t.length - e,
-
- this.Tt = Integer.fromNumber(this.It);
- }
-
-
- Et(t, e, n) {
-
- let s = t.add(e.multiply(Integer.fromNumber(n)));
-
- return 1 === s.compare(li) && (s = new Integer([ s.getBits(0), s.getBits(1) ], 0)),
- s.modulo(this.Tt).toNumber();
- }
-
- At(t) {
- return 0 != (this.bitmap[Math.floor(t / 8)] & 1 << t % 8);
- }
- vt(t) {
-
- if (0 === this.It) return !1;
- const e = fi(t), [n, s] = di(e);
- for (let t = 0; t < this.hashCount; t++) {
- const e = this.Et(n, s, t);
- if (!this.At(e)) return !1;
- }
- return !0;
- }
- static create(t, e, n) {
- const s = t % 8 == 0 ? 0 : 8 - t % 8, i = new Uint8Array(Math.ceil(t / 8)), r = new wi(i, s, e);
- return n.forEach((t => r.insert(t))), r;
- }
- insert(t) {
- if (0 === this.It) return;
- const e = fi(t), [n, s] = di(e);
- for (let t = 0; t < this.hashCount; t++) {
- const e = this.Et(n, s, t);
- this.Rt(e);
- }
- }
- Rt(t) {
- const e = Math.floor(t / 8), n = t % 8;
- this.bitmap[e] |= 1 << n;
- }
- }
- class _i extends Error {
- constructor() {
- super(...arguments), this.name = "BloomFilterError";
- }
- }
- class mi {
- constructor(
- /**
- * The snapshot version this event brings us up to, or MIN if not set.
- */
- t,
- /**
- * A map from target to changes to the target. See TargetChange.
- */
- e,
- /**
- * A map of targets that is known to be inconsistent, and the purpose for
- * re-listening. Listens for these targets should be re-established without
- * resume tokens.
- */
- n,
- /**
- * A set of which documents have changed or been deleted, along with the
- * doc's new values (if not deleted).
- */
- s,
- /**
- * A set of which document updates are due only to limbo resolution targets.
- */
- i) {
- this.snapshotVersion = t, this.targetChanges = e, this.targetMismatches = n, this.documentUpdates = s,
- this.resolvedLimboDocuments = i;
- }
-
-
- static createSynthesizedRemoteEventForCurrentChange(t, e, n) {
- const s = new Map;
- return s.set(t, gi.createSynthesizedTargetChangeForCurrentChange(t, e, n)), new mi(rt.min(), s, new pe(et), cs(), gs());
- }
- }
- class gi {
- constructor(
- /**
- * An opaque, server-assigned token that allows watching a query to be resumed
- * after disconnecting without retransmitting all the data that matches the
- * query. The resume token essentially identifies a point in time from which
- * the server should resume sending results.
- */
- t,
- /**
- * The "current" (synced) status of this target. Note that "current"
- * has special meaning in the RPC protocol that implies that a target is
- * both up-to-date and consistent with the rest of the watch stream.
- */
- e,
- /**
- * The set of documents that were newly assigned to this target as part of
- * this remote event.
- */
- n,
- /**
- * The set of documents that were already assigned to this target but received
- * an update during this remote event.
- */
- s,
- /**
- * The set of documents that were removed from this target as part of this
- * remote event.
- */
- i) {
- this.resumeToken = t, this.current = e, this.addedDocuments = n, this.modifiedDocuments = s,
- this.removedDocuments = i;
- }
-
- static createSynthesizedTargetChangeForCurrentChange(t, e, n) {
- return new gi(n, e, gs(), gs(), gs());
- }
- }
- class yi {
- constructor(
- /** The new document applies to all of these targets. */
- t,
- /** The new document is removed from all of these targets. */
- e,
- /** The key of the document for this change. */
- n,
- /**
- * The new document or NoDocument if it was deleted. Is null if the
- * document went out of view without the server sending a new document.
- */
- s) {
- this.Pt = t, this.removedTargetIds = e, this.key = n, this.bt = s;
- }
- }
- class pi {
- constructor(t, e) {
- this.targetId = t, this.Vt = e;
- }
- }
- class Ii {
- constructor(
- /** What kind of change occurred to the watch target. */
- t,
- /** The target IDs that were added/removed/set. */
- e,
- /**
- * An opaque, server-assigned token that allows watching a target to be
- * resumed after disconnecting without retransmitting all the data that
- * matches the target. The resume token essentially identifies a point in
- * time from which the server should resume sending results.
- */
- n = Ve.EMPTY_BYTE_STRING
- /** An RPC error indicating why the watch failed. */ , s = null) {
- this.state = t, this.targetIds = e, this.resumeToken = n, this.cause = s;
- }
- }
- class Ti {
- constructor() {
-
- this.St = 0,
-
- this.Dt = vi(),
-
- this.Ct = Ve.EMPTY_BYTE_STRING, this.xt = !1,
-
- this.Nt = !0;
- }
-
- get current() {
- return this.xt;
- }
- get resumeToken() {
- return this.Ct;
- }
- get kt() {
- return 0 !== this.St;
- }
- get Mt() {
- return this.Nt;
- }
-
- $t(t) {
- t.approximateByteSize() > 0 && (this.Nt = !0, this.Ct = t);
- }
-
- Ot() {
- let t = gs(), e = gs(), n = gs();
- return this.Dt.forEach(((s, i) => {
- switch (i) {
- case 0 :
- t = t.add(s);
- break;
- case 2 :
- e = e.add(s);
- break;
- case 1 :
- n = n.add(s);
- break;
- default:
- O();
- }
- })), new gi(this.Ct, this.xt, t, e, n);
- }
-
- Ft() {
- this.Nt = !1, this.Dt = vi();
- }
- Bt(t, e) {
- this.Nt = !0, this.Dt = this.Dt.insert(t, e);
- }
- Lt(t) {
- this.Nt = !0, this.Dt = this.Dt.remove(t);
- }
- qt() {
- this.St += 1;
- }
- Ut() {
- this.St -= 1;
- }
- Kt() {
- this.Nt = !0, this.xt = !0;
- }
- }
- class Ei {
- constructor(t) {
- this.Gt = t,
-
- this.Qt = new Map,
-
- this.jt = cs(),
-
- this.zt = Ai(),
-
- this.Wt = new pe(et);
- }
-
- Ht(t) {
- for (const e of t.Pt) t.bt && t.bt.isFoundDocument() ? this.Jt(e, t.bt) : this.Yt(e, t.key, t.bt);
- for (const e of t.removedTargetIds) this.Yt(e, t.key, t.bt);
- }
- Xt(t) {
- this.forEachTarget(t, (e => {
- const n = this.Zt(e);
- switch (t.state) {
- case 0 :
- this.te(e) && n.$t(t.resumeToken);
- break;
- case 1 :
-
-
- n.Ut(), n.kt ||
-
-
-
- n.Ft(), n.$t(t.resumeToken);
- break;
- case 2 :
-
-
-
-
- n.Ut(), n.kt || this.removeTarget(e);
- break;
- case 3 :
- this.te(e) && (n.Kt(), n.$t(t.resumeToken));
- break;
- case 4 :
- this.te(e) && (
-
-
-
- this.ee(e), n.$t(t.resumeToken));
- break;
- default:
- O();
- }
- }));
- }
-
- forEachTarget(t, e) {
- t.targetIds.length > 0 ? t.targetIds.forEach(e) : this.Qt.forEach(((t, n) => {
- this.te(n) && e(n);
- }));
- }
-
- ne(t) {
- var e;
- const n = t.targetId, s = t.Vt.count, i = this.se(n);
- if (i) {
- const r = i.target;
- if (Fn(r)) if (0 === s) {
-
-
-
-
-
-
- const t = new ht(r.path);
- this.Yt(n, t, an.newNoDocument(t, rt.min()));
- } else F(1 === s); else {
- const i = this.ie(n);
-
-
- if (i !== s) {
-
- const s = this.re(t, i);
- if (0 !== s) {
-
-
- this.ee(n);
- const t = 2 === s ? "TargetPurposeExistenceFilterMismatchBloom" : "TargetPurposeExistenceFilterMismatch" ;
- this.Wt = this.Wt.insert(n, t);
- }
- null === (e = ci.instance) || void 0 === e || e.notifyOnExistenceFilterMismatch(function(t, e, n) {
- var s, i, r, o, u, c;
- const a = {
- localCacheCount: e,
- existenceFilterCount: n.count
- }, h = n.unchangedNames;
- h && (a.bloomFilter = {
- applied: 0 === t,
- hashCount: null !== (s = null == h ? void 0 : h.hashCount) && void 0 !== s ? s : 0,
- bitmapLength: null !== (o = null === (r = null === (i = null == h ? void 0 : h.bits) || void 0 === i ? void 0 : i.bitmap) || void 0 === r ? void 0 : r.length) && void 0 !== o ? o : 0,
- padding: null !== (c = null === (u = null == h ? void 0 : h.bits) || void 0 === u ? void 0 : u.padding) && void 0 !== c ? c : 0
- });
- return a;
- }
-
- (s, i, t.Vt));
- }
- }
- }
- }
-
- re(t, e) {
- const {unchangedNames: n, count: s} = t.Vt;
- if (!n || !n.bits) return 1 ;
- const {bits: {bitmap: i = "", padding: r = 0}, hashCount: o = 0} = n;
- let u, c;
- try {
- u = xe(i).toUint8Array();
- } catch (t) {
- if (t instanceof Pe) return M("Decoding the base64 bloom filter in existence filter failed (" + t.message + "); ignoring the bloom filter and falling back to full re-query."),
- 1 ;
- throw t;
- }
- try {
-
- c = new wi(u, r, o);
- } catch (t) {
- return M(t instanceof _i ? "BloomFilter error: " : "Applying bloom filter failed: ", t),
- 1 ;
- }
- if (0 === c.It) return 1 ;
- return s !== e - this.oe(t.targetId, c) ? 2 : 0 ;
- }
-
- oe(t, e) {
- const n = this.Gt.getRemoteKeysForTarget(t);
- let s = 0;
- return n.forEach((n => {
- const i = this.Gt.ue(), r = `projects/${i.projectId}/databases/${i.database}/documents/${n.path.canonicalString()}`;
- e.vt(r) || (this.Yt(t, n, null), s++);
- })), s;
- }
-
- ce(t) {
- const e = new Map;
- this.Qt.forEach(((n, s) => {
- const i = this.se(s);
- if (i) {
- if (n.current && Fn(i.target)) {
-
-
-
-
-
-
-
-
- const e = new ht(i.target.path);
- null !== this.jt.get(e) || this.ae(s, e) || this.Yt(s, e, an.newNoDocument(e, t));
- }
- n.Mt && (e.set(s, n.Ot()), n.Ft());
- }
- }));
- let n = gs();
-
-
-
-
-
- this.zt.forEach(((t, e) => {
- let s = !0;
- e.forEachWhile((t => {
- const e = this.se(t);
- return !e || "TargetPurposeLimboResolution" === e.purpose || (s = !1,
- !1);
- })), s && (n = n.add(t));
- })), this.jt.forEach(((e, n) => n.setReadTime(t)));
- const s = new mi(t, e, this.Wt, this.jt, n);
- return this.jt = cs(), this.zt = Ai(), this.Wt = new pe(et), s;
- }
-
-
- Jt(t, e) {
- if (!this.te(t)) return;
- const n = this.ae(t, e.key) ? 2 : 0 ;
- this.Zt(t).Bt(e.key, n), this.jt = this.jt.insert(e.key, e), this.zt = this.zt.insert(e.key, this.he(e.key).add(t));
- }
-
-
- Yt(t, e, n) {
- if (!this.te(t)) return;
- const s = this.Zt(t);
- this.ae(t, e) ? s.Bt(e, 1 ) :
-
-
- s.Lt(e), this.zt = this.zt.insert(e, this.he(e).delete(t)), n && (this.jt = this.jt.insert(e, n));
- }
- removeTarget(t) {
- this.Qt.delete(t);
- }
-
- ie(t) {
- const e = this.Zt(t).Ot();
- return this.Gt.getRemoteKeysForTarget(t).size + e.addedDocuments.size - e.removedDocuments.size;
- }
-
- qt(t) {
- this.Zt(t).qt();
- }
- Zt(t) {
- let e = this.Qt.get(t);
- return e || (e = new Ti, this.Qt.set(t, e)), e;
- }
- he(t) {
- let e = this.zt.get(t);
- return e || (e = new Ee(et), this.zt = this.zt.insert(t, e)), e;
- }
-
- te(t) {
- const e = null !== this.se(t);
- return e || N("WatchChangeAggregator", "Detected inactive target", t), e;
- }
-
- se(t) {
- const e = this.Qt.get(t);
- return e && e.kt ? null : this.Gt.le(t);
- }
-
- ee(t) {
- this.Qt.set(t, new Ti);
- this.Gt.getRemoteKeysForTarget(t).forEach((e => {
- this.Yt(t, e, null);
- }));
- }
-
- ae(t, e) {
- return this.Gt.getRemoteKeysForTarget(t).has(e);
- }
- }
- function Ai() {
- return new pe(ht.comparator);
- }
- function vi() {
- return new pe(ht.comparator);
- }
- const Ri = (() => {
- const t = {
- asc: "ASCENDING",
- desc: "DESCENDING"
- };
- return t;
- })(), Pi = (() => {
- const t = {
- "<": "LESS_THAN",
- "<=": "LESS_THAN_OR_EQUAL",
- ">": "GREATER_THAN",
- ">=": "GREATER_THAN_OR_EQUAL",
- "==": "EQUAL",
- "!=": "NOT_EQUAL",
- "array-contains": "ARRAY_CONTAINS",
- in: "IN",
- "not-in": "NOT_IN",
- "array-contains-any": "ARRAY_CONTAINS_ANY"
- };
- return t;
- })(), bi = (() => {
- const t = {
- and: "AND",
- or: "OR"
- };
- return t;
- })();
- class Vi {
- constructor(t, e) {
- this.databaseId = t, this.useProto3Json = e;
- }
- }
- function Si(t, e) {
- return t.useProto3Json || Ft(e) ? e : {
- value: e
- };
- }
- function Di(t, e) {
- if (t.useProto3Json) {
- return `${new Date(1e3 * e.seconds).toISOString().replace(/\.\d*/, "").replace("Z", "")}.${("000000000" + e.nanoseconds).slice(-9)}Z`;
- }
- return {
- seconds: "" + e.seconds,
- nanos: e.nanoseconds
- };
- }
- function Ci(t, e) {
- return t.useProto3Json ? e.toBase64() : e.toUint8Array();
- }
- function xi(t, e) {
- return Di(t, e.toTimestamp());
- }
- function Ni(t) {
- return F(!!t), rt.fromTimestamp(function(t) {
- const e = De(t);
- return new it(e.seconds, e.nanos);
- }(t));
- }
- function ki(t, e) {
- return function(t) {
- return new ut([ "projects", t.projectId, "databases", t.database ]);
- }(t).child("documents").child(e).canonicalString();
- }
- function Mi(t) {
- const e = ut.fromString(t);
- return F(ur(e)), e;
- }
- function $i(t, e) {
- return ki(t.databaseId, e.path);
- }
- function Oi(t, e) {
- const n = Mi(e);
- if (n.get(1) !== t.databaseId.projectId) throw new U(q.INVALID_ARGUMENT, "Tried to deserialize key from different project: " + n.get(1) + " vs " + t.databaseId.projectId);
- if (n.get(3) !== t.databaseId.database) throw new U(q.INVALID_ARGUMENT, "Tried to deserialize key from different database: " + n.get(3) + " vs " + t.databaseId.database);
- return new ht(qi(n));
- }
- function Fi(t, e) {
- return ki(t.databaseId, e);
- }
- function Bi(t) {
- const e = Mi(t);
-
-
-
-
- return 4 === e.length ? ut.emptyPath() : qi(e);
- }
- function Li(t) {
- return new ut([ "projects", t.databaseId.projectId, "databases", t.databaseId.database ]).canonicalString();
- }
- function qi(t) {
- return F(t.length > 4 && "documents" === t.get(4)), t.popFirst(5);
- }
- function Ui(t, e, n) {
- return {
- name: $i(t, e),
- fields: n.value.mapValue.fields
- };
- }
- function Ki(t, e, n) {
- const s = Oi(t, e.name), i = Ni(e.updateTime), r = e.createTime ? Ni(e.createTime) : rt.min(), o = new un({
- mapValue: {
- fields: e.fields
- }
- }), u = an.newFoundDocument(s, i, r, o);
- return n && u.setHasCommittedMutations(), n ? u.setHasCommittedMutations() : u;
- }
- function Gi(t, e) {
- return "found" in e ? function(t, e) {
- F(!!e.found), e.found.name, e.found.updateTime;
- const n = Oi(t, e.found.name), s = Ni(e.found.updateTime), i = e.found.createTime ? Ni(e.found.createTime) : rt.min(), r = new un({
- mapValue: {
- fields: e.found.fields
- }
- });
- return an.newFoundDocument(n, s, i, r);
- }(t, e) : "missing" in e ? function(t, e) {
- F(!!e.missing), F(!!e.readTime);
- const n = Oi(t, e.missing), s = Ni(e.readTime);
- return an.newNoDocument(n, s);
- }(t, e) : O();
- }
- function Qi(t, e) {
- let n;
- if ("targetChange" in e) {
- e.targetChange;
-
-
- const s = function(t) {
- return "NO_CHANGE" === t ? 0 : "ADD" === t ? 1 : "REMOVE" === t ? 2 : "CURRENT" === t ? 3 : "RESET" === t ? 4 : O();
- }(e.targetChange.targetChangeType || "NO_CHANGE"), i = e.targetChange.targetIds || [], r = function(t, e) {
- return t.useProto3Json ? (F(void 0 === e || "string" == typeof e), Ve.fromBase64String(e || "")) : (F(void 0 === e || e instanceof Uint8Array),
- Ve.fromUint8Array(e || new Uint8Array));
- }(t, e.targetChange.resumeToken), o = e.targetChange.cause, u = o && function(t) {
- const e = void 0 === t.code ? q.UNKNOWN : ui(t.code);
- return new U(e, t.message || "");
- }(o);
- n = new Ii(s, i, r, u || null);
- } else if ("documentChange" in e) {
- e.documentChange;
- const s = e.documentChange;
- s.document, s.document.name, s.document.updateTime;
- const i = Oi(t, s.document.name), r = Ni(s.document.updateTime), o = s.document.createTime ? Ni(s.document.createTime) : rt.min(), u = new un({
- mapValue: {
- fields: s.document.fields
- }
- }), c = an.newFoundDocument(i, r, o, u), a = s.targetIds || [], h = s.removedTargetIds || [];
- n = new yi(a, h, c.key, c);
- } else if ("documentDelete" in e) {
- e.documentDelete;
- const s = e.documentDelete;
- s.document;
- const i = Oi(t, s.document), r = s.readTime ? Ni(s.readTime) : rt.min(), o = an.newNoDocument(i, r), u = s.removedTargetIds || [];
- n = new yi([], u, o.key, o);
- } else if ("documentRemove" in e) {
- e.documentRemove;
- const s = e.documentRemove;
- s.document;
- const i = Oi(t, s.document), r = s.removedTargetIds || [];
- n = new yi([], r, i, null);
- } else {
- if (!("filter" in e)) return O();
- {
- e.filter;
- const t = e.filter;
- t.targetId;
- const {count: s = 0, unchangedNames: i} = t, r = new si(s, i), o = t.targetId;
- n = new pi(o, r);
- }
- }
- return n;
- }
- function ji(t, e) {
- let n;
- if (e instanceof js) n = {
- update: Ui(t, e.key, e.value)
- }; else if (e instanceof Ys) n = {
- delete: $i(t, e.key)
- }; else if (e instanceof zs) n = {
- update: Ui(t, e.key, e.data),
- updateMask: or(e.fieldMask)
- }; else {
- if (!(e instanceof Xs)) return O();
- n = {
- verify: $i(t, e.key)
- };
- }
- return e.fieldTransforms.length > 0 && (n.updateTransforms = e.fieldTransforms.map((t => function(t, e) {
- const n = e.transform;
- if (n instanceof bs) return {
- fieldPath: e.field.canonicalString(),
- setToServerValue: "REQUEST_TIME"
- };
- if (n instanceof Vs) return {
- fieldPath: e.field.canonicalString(),
- appendMissingElements: {
- values: n.elements
- }
- };
- if (n instanceof Ds) return {
- fieldPath: e.field.canonicalString(),
- removeAllFromArray: {
- values: n.elements
- }
- };
- if (n instanceof xs) return {
- fieldPath: e.field.canonicalString(),
- increment: n.gt
- };
- throw O();
- }(0, t)))), e.precondition.isNone || (n.currentDocument = function(t, e) {
- return void 0 !== e.updateTime ? {
- updateTime: xi(t, e.updateTime)
- } : void 0 !== e.exists ? {
- exists: e.exists
- } : O();
- }(t, e.precondition)), n;
- }
- function zi(t, e) {
- const n = e.currentDocument ? function(t) {
- return void 0 !== t.updateTime ? Fs.updateTime(Ni(t.updateTime)) : void 0 !== t.exists ? Fs.exists(t.exists) : Fs.none();
- }(e.currentDocument) : Fs.none(), s = e.updateTransforms ? e.updateTransforms.map((e => function(t, e) {
- let n = null;
- if ("setToServerValue" in e) F("REQUEST_TIME" === e.setToServerValue), n = new bs; else if ("appendMissingElements" in e) {
- const t = e.appendMissingElements.values || [];
- n = new Vs(t);
- } else if ("removeAllFromArray" in e) {
- const t = e.removeAllFromArray.values || [];
- n = new Ds(t);
- } else "increment" in e ? n = new xs(t, e.increment) : O();
- const s = at.fromServerFormat(e.fieldPath);
- return new Ms(s, n);
- }(t, e))) : [];
- if (e.update) {
- e.update.name;
- const i = Oi(t, e.update.name), r = new un({
- mapValue: {
- fields: e.update.fields
- }
- });
- if (e.updateMask) {
- const t = function(t) {
- const e = t.fieldPaths || [];
- return new Re(e.map((t => at.fromServerFormat(t))));
- }(e.updateMask);
- return new zs(i, r, t, n, s);
- }
- return new js(i, r, n, s);
- }
- if (e.delete) {
- const s = Oi(t, e.delete);
- return new Ys(s, n);
- }
- if (e.verify) {
- const s = Oi(t, e.verify);
- return new Xs(s, n);
- }
- return O();
- }
- function Wi(t, e) {
- return t && t.length > 0 ? (F(void 0 !== e), t.map((t => function(t, e) {
-
- let n = t.updateTime ? Ni(t.updateTime) : Ni(e);
- return n.isEqual(rt.min()) && (
-
-
-
-
-
- n = Ni(e)), new Os(n, t.transformResults || []);
- }(t, e)))) : [];
- }
- function Hi(t, e) {
- return {
- documents: [ Fi(t, e.path) ]
- };
- }
- function Ji(t, e) {
-
- const n = {
- structuredQuery: {}
- }, s = e.path;
- null !== e.collectionGroup ? (n.parent = Fi(t, s), n.structuredQuery.from = [ {
- collectionId: e.collectionGroup,
- allDescendants: !0
- } ]) : (n.parent = Fi(t, s.popLast()), n.structuredQuery.from = [ {
- collectionId: s.lastSegment()
- } ]);
- const i = function(t) {
- if (0 === t.length) return;
- return rr(gn.create(t, "and" ));
- }(e.filters);
- i && (n.structuredQuery.where = i);
- const r = function(t) {
- if (0 === t.length) return;
- return t.map((t =>
-
- function(t) {
- return {
- field: sr(t.field),
- direction: tr(t.dir)
- };
- }(t)));
- }(e.orderBy);
- r && (n.structuredQuery.orderBy = r);
- const o = Si(t, e.limit);
- var u;
- return null !== o && (n.structuredQuery.limit = o), e.startAt && (n.structuredQuery.startAt = {
- before: (u = e.startAt).inclusive,
- values: u.position
- }), e.endAt && (n.structuredQuery.endAt = function(t) {
- return {
- before: !t.inclusive,
- values: t.position
- };
- }(e.endAt)), n;
- }
- function Yi(t) {
- let e = Bi(t.parent);
- const n = t.structuredQuery, s = n.from ? n.from.length : 0;
- let i = null;
- if (s > 0) {
- F(1 === s);
- const t = n.from[0];
- t.allDescendants ? i = t.collectionId : e = e.child(t.collectionId);
- }
- let r = [];
- n.where && (r = function(t) {
- const e = Zi(t);
- if (e instanceof gn && In(e)) return e.getFilters();
- return [ e ];
- }(n.where));
- let o = [];
- n.orderBy && (o = n.orderBy.map((t => function(t) {
- return new dn(ir(t.field),
-
- function(t) {
- switch (t) {
- case "ASCENDING":
- return "asc" ;
- case "DESCENDING":
- return "desc" ;
- default:
- return;
- }
- }
-
- (t.direction));
- }
-
- (t))));
- let u = null;
- n.limit && (u = function(t) {
- let e;
- return e = "object" == typeof t ? t.value : t, Ft(e) ? null : e;
- }(n.limit));
- let c = null;
- n.startAt && (c = function(t) {
- const e = !!t.before, n = t.values || [];
- return new hn(n, e);
- }(n.startAt));
- let a = null;
- return n.endAt && (a = function(t) {
- const e = !t.before, n = t.values || [];
- return new hn(n, e);
- }
-
- (n.endAt)), Kn(e, i, o, r, u, "F" , c, a);
- }
- function Xi(t, e) {
- const n = function(t) {
- switch (t) {
- case "TargetPurposeListen" :
- return null;
- case "TargetPurposeExistenceFilterMismatch" :
- return "existence-filter-mismatch";
- case "TargetPurposeExistenceFilterMismatchBloom" :
- return "existence-filter-mismatch-bloom";
- case "TargetPurposeLimboResolution" :
- return "limbo-document";
- default:
- return O();
- }
- }(e.purpose);
- return null == n ? null : {
- "goog-listen-tags": n
- };
- }
- function Zi(t) {
- return void 0 !== t.unaryFilter ? function(t) {
- switch (t.unaryFilter.op) {
- case "IS_NAN":
- const e = ir(t.unaryFilter.field);
- return mn.create(e, "==" , {
- doubleValue: NaN
- });
- case "IS_NULL":
- const n = ir(t.unaryFilter.field);
- return mn.create(n, "==" , {
- nullValue: "NULL_VALUE"
- });
- case "IS_NOT_NAN":
- const s = ir(t.unaryFilter.field);
- return mn.create(s, "!=" , {
- doubleValue: NaN
- });
- case "IS_NOT_NULL":
- const i = ir(t.unaryFilter.field);
- return mn.create(i, "!=" , {
- nullValue: "NULL_VALUE"
- });
- default:
- return O();
- }
- }(t) : void 0 !== t.fieldFilter ? function(t) {
- return mn.create(ir(t.fieldFilter.field), function(t) {
- switch (t) {
- case "EQUAL":
- return "==" ;
- case "NOT_EQUAL":
- return "!=" ;
- case "GREATER_THAN":
- return ">" ;
- case "GREATER_THAN_OR_EQUAL":
- return ">=" ;
- case "LESS_THAN":
- return "<" ;
- case "LESS_THAN_OR_EQUAL":
- return "<=" ;
- case "ARRAY_CONTAINS":
- return "array-contains" ;
- case "IN":
- return "in" ;
- case "NOT_IN":
- return "not-in" ;
- case "ARRAY_CONTAINS_ANY":
- return "array-contains-any" ;
- default:
- return O();
- }
- }(t.fieldFilter.op), t.fieldFilter.value);
- }(t) : void 0 !== t.compositeFilter ? function(t) {
- return gn.create(t.compositeFilter.filters.map((t => Zi(t))), function(t) {
- switch (t) {
- case "AND":
- return "and" ;
- case "OR":
- return "or" ;
- default:
- return O();
- }
- }(t.compositeFilter.op));
- }(t) : O();
- }
- function tr(t) {
- return Ri[t];
- }
- function er(t) {
- return Pi[t];
- }
- function nr(t) {
- return bi[t];
- }
- function sr(t) {
- return {
- fieldPath: t.canonicalString()
- };
- }
- function ir(t) {
- return at.fromServerFormat(t.fieldPath);
- }
- function rr(t) {
- return t instanceof mn ? function(t) {
- if ("==" === t.op) {
- if (Xe(t.value)) return {
- unaryFilter: {
- field: sr(t.field),
- op: "IS_NAN"
- }
- };
- if (Ye(t.value)) return {
- unaryFilter: {
- field: sr(t.field),
- op: "IS_NULL"
- }
- };
- } else if ("!=" === t.op) {
- if (Xe(t.value)) return {
- unaryFilter: {
- field: sr(t.field),
- op: "IS_NOT_NAN"
- }
- };
- if (Ye(t.value)) return {
- unaryFilter: {
- field: sr(t.field),
- op: "IS_NOT_NULL"
- }
- };
- }
- return {
- fieldFilter: {
- field: sr(t.field),
- op: er(t.op),
- value: t.value
- }
- };
- }(t) : t instanceof gn ? function(t) {
- const e = t.getFilters().map((t => rr(t)));
- if (1 === e.length) return e[0];
- return {
- compositeFilter: {
- op: nr(t.op),
- filters: e
- }
- };
- }(t) : O();
- }
- function or(t) {
- const e = [];
- return t.fields.forEach((t => e.push(t.canonicalString()))), {
- fieldPaths: e
- };
- }
- function ur(t) {
-
- return t.length >= 4 && "projects" === t.get(0) && "databases" === t.get(2);
- }
- class cr {
- constructor(
- /** The target being listened to. */
- t,
- /**
- * The target ID to which the target corresponds; Assigned by the
- * LocalStore for user listens and by the SyncEngine for limbo watches.
- */
- e,
- /** The purpose of the target. */
- n,
- /**
- * The sequence number of the last transaction during which this target data
- * was modified.
- */
- s,
- /** The latest snapshot version seen for this target. */
- i = rt.min()
- /**
- * The maximum snapshot version at which the associated view
- * contained no limbo documents.
- */ , r = rt.min()
- /**
- * An opaque, server-assigned token that allows watching a target to be
- * resumed after disconnecting without retransmitting all the data that
- * matches the target. The resume token essentially identifies a point in
- * time from which the server should resume sending results.
- */ , o = Ve.EMPTY_BYTE_STRING
- /**
- * The number of documents that last matched the query at the resume token or
- * read time. Documents are counted only when making a listen request with
- * resume token or read time, otherwise, keep it null.
- */ , u = null) {
- this.target = t, this.targetId = e, this.purpose = n, this.sequenceNumber = s, this.snapshotVersion = i,
- this.lastLimboFreeSnapshotVersion = r, this.resumeToken = o, this.expectedCount = u;
- }
- withSequenceNumber(t) {
- return new cr(this.target, this.targetId, this.purpose, t, this.snapshotVersion, this.lastLimboFreeSnapshotVersion, this.resumeToken, this.expectedCount);
- }
-
- withResumeToken(t, e) {
- return new cr(this.target, this.targetId, this.purpose, this.sequenceNumber, e, this.lastLimboFreeSnapshotVersion, t,
- null);
- }
-
- withExpectedCount(t) {
- return new cr(this.target, this.targetId, this.purpose, this.sequenceNumber, this.snapshotVersion, this.lastLimboFreeSnapshotVersion, this.resumeToken, t);
- }
-
- withLastLimboFreeSnapshotVersion(t) {
- return new cr(this.target, this.targetId, this.purpose, this.sequenceNumber, this.snapshotVersion, t, this.resumeToken, this.expectedCount);
- }
- }
- class ar {
- constructor(t) {
- this.fe = t;
- }
- }
- function hr(t, e) {
- let n;
- if (e.document) n = Ki(t.fe, e.document, !!e.hasCommittedMutations); else if (e.noDocument) {
- const t = ht.fromSegments(e.noDocument.path), s = wr(e.noDocument.readTime);
- n = an.newNoDocument(t, s), e.hasCommittedMutations && n.setHasCommittedMutations();
- } else {
- if (!e.unknownDocument) return O();
- {
- const t = ht.fromSegments(e.unknownDocument.path), s = wr(e.unknownDocument.version);
- n = an.newUnknownDocument(t, s);
- }
- }
- return e.readTime && n.setReadTime(function(t) {
- const e = new it(t[0], t[1]);
- return rt.fromTimestamp(e);
- }(e.readTime)), n;
- }
- function lr(t, e) {
- const n = e.key, s = {
- prefixPath: n.getCollectionPath().popLast().toArray(),
- collectionGroup: n.collectionGroup,
- documentId: n.path.lastSegment(),
- readTime: fr(e.readTime),
- hasCommittedMutations: e.hasCommittedMutations
- };
- if (e.isFoundDocument()) s.document = function(t, e) {
- return {
- name: $i(t, e.key),
- fields: e.data.value.mapValue.fields,
- updateTime: Di(t, e.version.toTimestamp()),
- createTime: Di(t, e.createTime.toTimestamp())
- };
- }(t.fe, e); else if (e.isNoDocument()) s.noDocument = {
- path: n.path.toArray(),
- readTime: dr(e.version)
- }; else {
- if (!e.isUnknownDocument()) return O();
- s.unknownDocument = {
- path: n.path.toArray(),
- version: dr(e.version)
- };
- }
- return s;
- }
- function fr(t) {
- const e = t.toTimestamp();
- return [ e.seconds, e.nanoseconds ];
- }
- function dr(t) {
- const e = t.toTimestamp();
- return {
- seconds: e.seconds,
- nanoseconds: e.nanoseconds
- };
- }
- function wr(t) {
- const e = new it(t.seconds, t.nanoseconds);
- return rt.fromTimestamp(e);
- }
- function _r(t, e) {
- const n = (e.baseMutations || []).map((e => zi(t.fe, e)));
-
-
-
-
-
- for (let t = 0; t < e.mutations.length - 1; ++t) {
- const n = e.mutations[t];
- if (t + 1 < e.mutations.length && void 0 !== e.mutations[t + 1].transform) {
- const s = e.mutations[t + 1];
- n.updateTransforms = s.transform.fieldTransforms, e.mutations.splice(t + 1, 1),
- ++t;
- }
- }
- const s = e.mutations.map((e => zi(t.fe, e))), i = it.fromMillis(e.localWriteTimeMs);
- return new Zs(e.batchId, i, n, s);
- }
- function mr(t) {
- const e = wr(t.readTime), n = void 0 !== t.lastLimboFreeSnapshotVersion ? wr(t.lastLimboFreeSnapshotVersion) : rt.min();
- let s;
- var i;
- return void 0 !== t.query.documents ? (F(1 === (i = t.query).documents.length),
- s = Jn(Gn(Bi(i.documents[0])))) : s = function(t) {
- return Jn(Yi(t));
- }(t.query), new cr(s, t.targetId, "TargetPurposeListen" , t.lastListenSequenceNumber, e, n, Ve.fromBase64String(t.resumeToken));
- }
- function gr(t, e) {
- const n = dr(e.snapshotVersion), s = dr(e.lastLimboFreeSnapshotVersion);
- let i;
- i = Fn(e.target) ? Hi(t.fe, e.target) : Ji(t.fe, e.target);
-
-
- const r = e.resumeToken.toBase64();
-
- return {
- targetId: e.targetId,
- canonicalId: $n(e.target),
- readTime: n,
- resumeToken: r,
- lastListenSequenceNumber: e.sequenceNumber,
- lastLimboFreeSnapshotVersion: s,
- query: i
- };
- }
- function yr(t) {
- const e = Yi({
- parent: t.parent,
- structuredQuery: t.structuredQuery
- });
- return "LAST" === t.limitType ? Xn(e, e.limit, "L" ) : e;
- }
- function pr(t, e) {
- return new ei(e.largestBatchId, zi(t.fe, e.overlayMutation));
- }
- function Ir(t, e) {
- const n = e.path.lastSegment();
- return [ t, qt(e.path.popLast()), n ];
- }
- function Tr(t, e, n, s) {
- return {
- indexId: t,
- uid: e.uid || "",
- sequenceNumber: n,
- readTime: dr(s.readTime),
- documentKey: qt(s.documentKey.path),
- largestBatchId: s.largestBatchId
- };
- }
- class Er {
- getBundleMetadata(t, e) {
- return Ar(t).get(e).next((t => {
- if (t) return {
- id: (e = t).bundleId,
- createTime: wr(e.createTime),
- version: e.version
- };
-
- var e;
- }));
- }
- saveBundleMetadata(t, e) {
- return Ar(t).put({
- bundleId: (n = e).id,
- createTime: dr(Ni(n.createTime)),
- version: n.version
- });
- var n;
- }
- getNamedQuery(t, e) {
- return vr(t).get(e).next((t => {
- if (t) return {
- name: (e = t).name,
- query: yr(e.bundledQuery),
- readTime: wr(e.readTime)
- };
- var e;
- }));
- }
- saveNamedQuery(t, e) {
- return vr(t).put(function(t) {
- return {
- name: t.name,
- readTime: dr(Ni(t.readTime)),
- bundledQuery: t.bundledQuery
- };
- }(e));
- }
- }
- function Ar(t) {
- return _e(t, "bundles");
- }
- function vr(t) {
- return _e(t, "namedQueries");
- }
- class Rr {
-
- constructor(t, e) {
- this.serializer = t, this.userId = e;
- }
- static de(t, e) {
- const n = e.uid || "";
- return new Rr(t, n);
- }
- getOverlay(t, e) {
- return Pr(t).get(Ir(this.userId, e)).next((t => t ? pr(this.serializer, t) : null));
- }
- getOverlays(t, e) {
- const n = fs();
- return Rt.forEach(e, (e => this.getOverlay(t, e).next((t => {
- null !== t && n.set(e, t);
- })))).next((() => n));
- }
- saveOverlays(t, e, n) {
- const s = [];
- return n.forEach(((n, i) => {
- const r = new ei(e, i);
- s.push(this.we(t, r));
- })), Rt.waitFor(s);
- }
- removeOverlaysForBatchId(t, e, n) {
- const s = new Set;
-
- e.forEach((t => s.add(qt(t.getCollectionPath()))));
- const i = [];
- return s.forEach((e => {
- const s = IDBKeyRange.bound([ this.userId, e, n ], [ this.userId, e, n + 1 ],
- !1,
- !0);
- i.push(Pr(t).J("collectionPathOverlayIndex", s));
- })), Rt.waitFor(i);
- }
- getOverlaysForCollection(t, e, n) {
- const s = fs(), i = qt(e), r = IDBKeyRange.bound([ this.userId, i, n ], [ this.userId, i, Number.POSITIVE_INFINITY ],
- !0);
- return Pr(t).j("collectionPathOverlayIndex", r).next((t => {
- for (const e of t) {
- const t = pr(this.serializer, e);
- s.set(t.getKey(), t);
- }
- return s;
- }));
- }
- getOverlaysForCollectionGroup(t, e, n, s) {
- const i = fs();
- let r;
-
-
- const o = IDBKeyRange.bound([ this.userId, e, n ], [ this.userId, e, Number.POSITIVE_INFINITY ],
- !0);
- return Pr(t).X({
- index: "collectionGroupOverlayIndex",
- range: o
- }, ((t, e, n) => {
-
-
-
-
- const o = pr(this.serializer, e);
- i.size() < s || o.largestBatchId === r ? (i.set(o.getKey(), o), r = o.largestBatchId) : n.done();
- })).next((() => i));
- }
- we(t, e) {
- return Pr(t).put(function(t, e, n) {
- const [s, i, r] = Ir(e, n.mutation.key);
- return {
- userId: e,
- collectionPath: i,
- documentId: r,
- collectionGroup: n.mutation.key.getCollectionGroup(),
- largestBatchId: n.largestBatchId,
- overlayMutation: ji(t.fe, n.mutation)
- };
- }(this.serializer, this.userId, e));
- }
- }
- function Pr(t) {
- return _e(t, "documentOverlays");
- }
- class br {
- constructor() {}
-
-
-
-
-
-
-
- _e(t, e) {
- this.me(t, e),
-
-
- e.ge();
- }
- me(t, e) {
- if ("nullValue" in t) this.ye(e, 5); else if ("booleanValue" in t) this.ye(e, 10),
- e.pe(t.booleanValue ? 1 : 0); else if ("integerValue" in t) this.ye(e, 15), e.pe(Ce(t.integerValue)); else if ("doubleValue" in t) {
- const n = Ce(t.doubleValue);
- isNaN(n) ? this.ye(e, 13) : (this.ye(e, 15), Bt(n) ?
-
- e.pe(0) : e.pe(n));
- } else if ("timestampValue" in t) {
- const n = t.timestampValue;
- this.ye(e, 20), "string" == typeof n ? e.Ie(n) : (e.Ie(`${n.seconds || ""}`), e.pe(n.nanos || 0));
- } else if ("stringValue" in t) this.Te(t.stringValue, e), this.Ee(e); else if ("bytesValue" in t) this.ye(e, 30),
- e.Ae(xe(t.bytesValue)), this.Ee(e); else if ("referenceValue" in t) this.ve(t.referenceValue, e); else if ("geoPointValue" in t) {
- const n = t.geoPointValue;
- this.ye(e, 45), e.pe(n.latitude || 0), e.pe(n.longitude || 0);
- } else "mapValue" in t ? en(t) ? this.ye(e, Number.MAX_SAFE_INTEGER) : (this.Re(t.mapValue, e),
- this.Ee(e)) : "arrayValue" in t ? (this.Pe(t.arrayValue, e), this.Ee(e)) : O();
- }
- Te(t, e) {
- this.ye(e, 25), this.be(t, e);
- }
- be(t, e) {
- e.Ie(t);
- }
- Re(t, e) {
- const n = t.fields || {};
- this.ye(e, 55);
- for (const t of Object.keys(n)) this.Te(t, e), this.me(n[t], e);
- }
- Pe(t, e) {
- const n = t.values || [];
- this.ye(e, 50);
- for (const t of n) this.me(t, e);
- }
- ve(t, e) {
- this.ye(e, 37);
- ht.fromName(t).path.forEach((t => {
- this.ye(e, 60), this.be(t, e);
- }));
- }
- ye(t, e) {
- t.pe(e);
- }
- Ee(t) {
-
-
-
- t.pe(2);
- }
- }
- br.Ve = new br;
- function Vr(t) {
- if (0 === t) return 8;
- let e = 0;
- return t >> 4 == 0 && (
-
- e += 4, t <<= 4), t >> 6 == 0 && (
-
- e += 2, t <<= 2), t >> 7 == 0 && (
-
- e += 1), e;
- }
- function Sr(t) {
-
- const e = 64 - function(t) {
- let e = 0;
- for (let n = 0; n < 8; ++n) {
- const s = Vr(255 & t[n]);
- if (e += s, 8 !== s) break;
- }
- return e;
- }(t);
- return Math.ceil(e / 8);
- }
- class Dr {
- constructor() {
- this.buffer = new Uint8Array(1024), this.position = 0;
- }
- Se(t) {
- const e = t[Symbol.iterator]();
- let n = e.next();
- for (;!n.done; ) this.De(n.value), n = e.next();
- this.Ce();
- }
- xe(t) {
- const e = t[Symbol.iterator]();
- let n = e.next();
- for (;!n.done; ) this.Ne(n.value), n = e.next();
- this.ke();
- }
- Me(t) {
- for (const e of t) {
- const t = e.charCodeAt(0);
- if (t < 128) this.De(t); else if (t < 2048) this.De(960 | t >>> 6), this.De(128 | 63 & t); else if (e < "\ud800" || "\udbff" < e) this.De(480 | t >>> 12),
- this.De(128 | 63 & t >>> 6), this.De(128 | 63 & t); else {
- const t = e.codePointAt(0);
- this.De(240 | t >>> 18), this.De(128 | 63 & t >>> 12), this.De(128 | 63 & t >>> 6),
- this.De(128 | 63 & t);
- }
- }
- this.Ce();
- }
- $e(t) {
- for (const e of t) {
- const t = e.charCodeAt(0);
- if (t < 128) this.Ne(t); else if (t < 2048) this.Ne(960 | t >>> 6), this.Ne(128 | 63 & t); else if (e < "\ud800" || "\udbff" < e) this.Ne(480 | t >>> 12),
- this.Ne(128 | 63 & t >>> 6), this.Ne(128 | 63 & t); else {
- const t = e.codePointAt(0);
- this.Ne(240 | t >>> 18), this.Ne(128 | 63 & t >>> 12), this.Ne(128 | 63 & t >>> 6),
- this.Ne(128 | 63 & t);
- }
- }
- this.ke();
- }
- Oe(t) {
-
-
- const e = this.Fe(t), n = Sr(e);
- this.Be(1 + n), this.buffer[this.position++] = 255 & n;
-
- for (let t = e.length - n; t < e.length; ++t) this.buffer[this.position++] = 255 & e[t];
- }
- Le(t) {
-
-
- const e = this.Fe(t), n = Sr(e);
- this.Be(1 + n), this.buffer[this.position++] = ~(255 & n);
-
- for (let t = e.length - n; t < e.length; ++t) this.buffer[this.position++] = ~(255 & e[t]);
- }
-
- qe() {
- this.Ue(255), this.Ue(255);
- }
-
- Ke() {
- this.Ge(255), this.Ge(255);
- }
-
- reset() {
- this.position = 0;
- }
- seed(t) {
- this.Be(t.length), this.buffer.set(t, this.position), this.position += t.length;
- }
- Qe() {
- return this.buffer.slice(0, this.position);
- }
-
- Fe(t) {
- const e =
-
- function(t) {
- const e = new DataView(new ArrayBuffer(8));
- return e.setFloat64(0, t, !1), new Uint8Array(e.buffer);
- }(t), n = 0 != (128 & e[0]);
-
-
-
- e[0] ^= n ? 255 : 128;
- for (let t = 1; t < e.length; ++t) e[t] ^= n ? 255 : 0;
- return e;
- }
- De(t) {
- const e = 255 & t;
- 0 === e ? (this.Ue(0), this.Ue(255)) : 255 === e ? (this.Ue(255), this.Ue(0)) : this.Ue(e);
- }
- Ne(t) {
- const e = 255 & t;
- 0 === e ? (this.Ge(0), this.Ge(255)) : 255 === e ? (this.Ge(255), this.Ge(0)) : this.Ge(t);
- }
- Ce() {
- this.Ue(0), this.Ue(1);
- }
- ke() {
- this.Ge(0), this.Ge(1);
- }
- Ue(t) {
- this.Be(1), this.buffer[this.position++] = t;
- }
- Ge(t) {
- this.Be(1), this.buffer[this.position++] = ~t;
- }
- Be(t) {
- const e = t + this.position;
- if (e <= this.buffer.length) return;
-
- let n = 2 * this.buffer.length;
-
- n < e && (n = e);
-
- const s = new Uint8Array(n);
- s.set(this.buffer),
- this.buffer = s;
- }
- }
- class Cr {
- constructor(t) {
- this.je = t;
- }
- Ae(t) {
- this.je.Se(t);
- }
- Ie(t) {
- this.je.Me(t);
- }
- pe(t) {
- this.je.Oe(t);
- }
- ge() {
- this.je.qe();
- }
- }
- class xr {
- constructor(t) {
- this.je = t;
- }
- Ae(t) {
- this.je.xe(t);
- }
- Ie(t) {
- this.je.$e(t);
- }
- pe(t) {
- this.je.Le(t);
- }
- ge() {
- this.je.Ke();
- }
- }
- class Nr {
- constructor() {
- this.je = new Dr, this.ze = new Cr(this.je), this.We = new xr(this.je);
- }
- seed(t) {
- this.je.seed(t);
- }
- He(t) {
- return 0 === t ? this.ze : this.We;
- }
- Qe() {
- return this.je.Qe();
- }
- reset() {
- this.je.reset();
- }
- }
- class kr {
- constructor(t, e, n, s) {
- this.indexId = t, this.documentKey = e, this.arrayValue = n, this.directionalValue = s;
- }
-
- Je() {
- const t = this.directionalValue.length, e = 0 === t || 255 === this.directionalValue[t - 1] ? t + 1 : t, n = new Uint8Array(e);
- return n.set(this.directionalValue, 0), e !== t ? n.set([ 0 ], this.directionalValue.length) : ++n[n.length - 1],
- new kr(this.indexId, this.documentKey, this.arrayValue, n);
- }
- }
- function Mr(t, e) {
- let n = t.indexId - e.indexId;
- return 0 !== n ? n : (n = $r(t.arrayValue, e.arrayValue), 0 !== n ? n : (n = $r(t.directionalValue, e.directionalValue),
- 0 !== n ? n : ht.comparator(t.documentKey, e.documentKey)));
- }
- function $r(t, e) {
- for (let n = 0; n < t.length && n < e.length; ++n) {
- const s = t[n] - e[n];
- if (0 !== s) return s;
- }
- return t.length - e.length;
- }
- class Or {
- constructor(t) {
- this.collectionId = null != t.collectionGroup ? t.collectionGroup : t.path.lastSegment(),
- this.Ye = t.orderBy, this.Xe = [];
- for (const e of t.filters) {
- const t = e;
- t.isInequality() ? this.Ze = t : this.Xe.push(t);
- }
- }
-
- tn(t) {
- F(t.collectionGroup === this.collectionId);
-
- const e = ft(t);
- if (void 0 !== e && !this.en(e)) return !1;
- const n = dt(t);
- let s = new Set, i = 0, r = 0;
-
- for (;i < n.length && this.en(n[i]); ++i) s = s.add(n[i].fieldPath.canonicalString());
-
-
-
- if (i === n.length) return !0;
- if (void 0 !== this.Ze) {
-
-
-
- if (!s.has(this.Ze.field.canonicalString())) {
- const t = n[i];
- if (!this.nn(this.Ze, t) || !this.sn(this.Ye[r++], t)) return !1;
- }
- ++i;
- }
-
-
- for (;i < n.length; ++i) {
- const t = n[i];
- if (r >= this.Ye.length || !this.sn(this.Ye[r++], t)) return !1;
- }
- return !0;
- }
- en(t) {
- for (const e of this.Xe) if (this.nn(e, t)) return !0;
- return !1;
- }
- nn(t, e) {
- if (void 0 === t || !t.field.isEqual(e.fieldPath)) return !1;
- const n = "array-contains" === t.op || "array-contains-any" === t.op;
- return 2 === e.kind === n;
- }
- sn(t, e) {
- return !!t.field.isEqual(e.fieldPath) && (0 === e.kind && "asc" === t.dir || 1 === e.kind && "desc" === t.dir);
- }
- }
- function Fr(t) {
- var e, n;
- if (F(t instanceof mn || t instanceof gn), t instanceof mn) {
- if (t instanceof Cn) {
- const s = (null === (n = null === (e = t.value.arrayValue) || void 0 === e ? void 0 : e.values) || void 0 === n ? void 0 : n.map((e => mn.create(t.field, "==" , e)))) || [];
- return gn.create(s, "or" );
- }
-
- return t;
- }
-
- const s = t.filters.map((t => Fr(t)));
- return gn.create(s, t.op);
- }
- function Br(t) {
- if (0 === t.getFilters().length) return [];
- const e = Kr(Fr(t));
- return F(Ur(e)), Lr(e) || qr(e) ? [ e ] : e.getFilters();
- }
- function Lr(t) {
- return t instanceof mn;
- }
- function qr(t) {
- return t instanceof gn && In(t);
- }
- function Ur(t) {
- return Lr(t) || qr(t) ||
-
- function(t) {
- if (t instanceof gn && pn(t)) {
- for (const e of t.getFilters()) if (!Lr(e) && !qr(e)) return !1;
- return !0;
- }
- return !1;
- }(t);
- }
- function Kr(t) {
- if (F(t instanceof mn || t instanceof gn), t instanceof mn) return t;
- if (1 === t.filters.length) return Kr(t.filters[0]);
-
- const e = t.filters.map((t => Kr(t)));
- let n = gn.create(e, t.op);
- return n = jr(n), Ur(n) ? n : (F(n instanceof gn), F(yn(n)), F(n.filters.length > 1),
- n.filters.reduce(((t, e) => Gr(t, e))));
- }
- function Gr(t, e) {
- let n;
- return F(t instanceof mn || t instanceof gn), F(e instanceof mn || e instanceof gn),
-
- n = t instanceof mn ? e instanceof mn ? function(t, e) {
-
- return gn.create([ t, e ], "and" );
- }(t, e) : Qr(t, e) : e instanceof mn ? Qr(e, t) : function(t, e) {
-
-
-
-
-
-
- if (F(t.filters.length > 0 && e.filters.length > 0), yn(t) && yn(e)) return vn(t, e.getFilters());
-
-
-
- const n = pn(t) ? t : e, s = pn(t) ? e : t, i = n.filters.map((t => Gr(t, s)));
- return gn.create(i, "or" );
- }(t, e), jr(n);
- }
- function Qr(t, e) {
-
-
-
- if (yn(e))
-
- return vn(e, t.getFilters());
- {
-
- const n = e.filters.map((e => Gr(t, e)));
- return gn.create(n, "or" );
- }
- }
- function jr(t) {
- if (F(t instanceof mn || t instanceof gn), t instanceof mn) return t;
- const e = t.getFilters();
-
- if (1 === e.length) return jr(e[0]);
-
- if (Tn(t)) return t;
-
-
- const n = e.map((t => jr(t))), s = [];
-
-
-
-
-
-
-
- return n.forEach((e => {
- e instanceof mn ? s.push(e) : e instanceof gn && (e.op === t.op ?
-
-
-
- s.push(...e.filters) :
-
-
-
- s.push(e));
- })), 1 === s.length ? s[0] : gn.create(s, t.op);
- }
- class zr {
- constructor() {
- this.rn = new Wr;
- }
- addToCollectionParentIndex(t, e) {
- return this.rn.add(e), Rt.resolve();
- }
- getCollectionParents(t, e) {
- return Rt.resolve(this.rn.getEntries(e));
- }
- addFieldIndex(t, e) {
-
- return Rt.resolve();
- }
- deleteFieldIndex(t, e) {
-
- return Rt.resolve();
- }
- getDocumentsMatchingTarget(t, e) {
-
- return Rt.resolve(null);
- }
- getIndexType(t, e) {
-
- return Rt.resolve(0 );
- }
- getFieldIndexes(t, e) {
-
- return Rt.resolve([]);
- }
- getNextCollectionGroupToUpdate(t) {
-
- return Rt.resolve(null);
- }
- getMinOffset(t, e) {
- return Rt.resolve(It.min());
- }
- getMinOffsetFromCollectionGroup(t, e) {
- return Rt.resolve(It.min());
- }
- updateCollectionGroup(t, e, n) {
-
- return Rt.resolve();
- }
- updateIndexEntries(t, e) {
-
- return Rt.resolve();
- }
- }
- class Wr {
- constructor() {
- this.index = {};
- }
-
- add(t) {
- const e = t.lastSegment(), n = t.popLast(), s = this.index[e] || new Ee(ut.comparator), i = !s.has(n);
- return this.index[e] = s.add(n), i;
- }
- has(t) {
- const e = t.lastSegment(), n = t.popLast(), s = this.index[e];
- return s && s.has(n);
- }
- getEntries(t) {
- return (this.index[t] || new Ee(ut.comparator)).toArray();
- }
- }
- const Hr = new Uint8Array(0);
- class Jr {
- constructor(t, e) {
- this.user = t, this.databaseId = e,
-
- this.on = new Wr,
-
- this.un = new os((t => $n(t)), ((t, e) => On(t, e))), this.uid = t.uid || "";
- }
-
- addToCollectionParentIndex(t, e) {
- if (!this.on.has(e)) {
- const n = e.lastSegment(), s = e.popLast();
- t.addOnCommittedListener((() => {
-
-
- this.on.add(e);
- }));
- const i = {
- collectionId: n,
- parent: qt(s)
- };
- return Yr(t).put(i);
- }
- return Rt.resolve();
- }
- getCollectionParents(t, e) {
- const n = [], s = IDBKeyRange.bound([ e, "" ], [ st(e), "" ],
- !1,
- !0);
- return Yr(t).j(s).next((t => {
- for (const s of t) {
-
-
-
-
- if (s.collectionId !== e) break;
- n.push(Gt(s.parent));
- }
- return n;
- }));
- }
- addFieldIndex(t, e) {
-
-
- const n = Zr(t), s = function(t) {
- return {
- indexId: t.indexId,
- collectionGroup: t.collectionGroup,
- fields: t.fields.map((t => [ t.fieldPath.canonicalString(), t.kind ]))
- };
- }(e);
- delete s.indexId;
-
- const i = n.add(s);
- if (e.indexState) {
- const n = to(t);
- return i.next((t => {
- n.put(Tr(t, this.user, e.indexState.sequenceNumber, e.indexState.offset));
- }));
- }
- return i.next();
- }
- deleteFieldIndex(t, e) {
- const n = Zr(t), s = to(t), i = Xr(t);
- return n.delete(e.indexId).next((() => s.delete(IDBKeyRange.bound([ e.indexId ], [ e.indexId + 1 ],
- !1,
- !0)))).next((() => i.delete(IDBKeyRange.bound([ e.indexId ], [ e.indexId + 1 ],
- !1,
- !0))));
- }
- getDocumentsMatchingTarget(t, e) {
- const n = Xr(t);
- let s = !0;
- const i = new Map;
- return Rt.forEach(this.cn(e), (e => this.an(t, e).next((t => {
- s && (s = !!t), i.set(e, t);
- })))).next((() => {
- if (s) {
- let t = gs();
- const s = [];
- return Rt.forEach(i, ((i, r) => {
- var o;
- N("IndexedDbIndexManager", `Using index ${o = i, `id=${o.indexId}|cg=${o.collectionGroup}|f=${o.fields.map((t => `${t.fieldPath}:${t.kind}`)).join(",")}`} to execute ${$n(e)}`);
- const u = function(t, e) {
- const n = ft(e);
- if (void 0 === n) return null;
- for (const e of Bn(t, n.fieldPath)) switch (e.op) {
- case "array-contains-any" :
- return e.value.arrayValue.values || [];
- case "array-contains" :
- return [ e.value ];
-
- }
- return null;
- }
-
- (r, i), c = function(t, e) {
- const n = new Map;
- for (const s of dt(e)) for (const e of Bn(t, s.fieldPath)) switch (e.op) {
- case "==" :
- case "in" :
-
-
-
- n.set(s.fieldPath.canonicalString(), e.value);
- break;
- case "not-in" :
- case "!=" :
-
-
- return n.set(s.fieldPath.canonicalString(), e.value), Array.from(n.values());
-
- }
- return null;
- }
-
- (r, i), a = function(t, e) {
- const n = [];
- let s = !0;
-
-
- for (const i of dt(e)) {
- const e = 0 === i.kind ? Ln(t, i.fieldPath, t.startAt) : qn(t, i.fieldPath, t.startAt);
- n.push(e.value), s && (s = e.inclusive);
- }
- return new hn(n, s);
- }
-
- (r, i), h = function(t, e) {
- const n = [];
- let s = !0;
-
-
- for (const i of dt(e)) {
- const e = 0 === i.kind ? qn(t, i.fieldPath, t.endAt) : Ln(t, i.fieldPath, t.endAt);
- n.push(e.value), s && (s = e.inclusive);
- }
- return new hn(n, s);
- }(r, i), l = this.hn(i, r, a), f = this.hn(i, r, h), d = this.ln(i, r, c), w = this.fn(i.indexId, u, l, a.inclusive, f, h.inclusive, d);
- return Rt.forEach(w, (i => n.H(i, e.limit).next((e => {
- e.forEach((e => {
- const n = ht.fromSegments(e.documentKey);
- t.has(n) || (t = t.add(n), s.push(n));
- }));
- }))));
- })).next((() => s));
- }
- return Rt.resolve(null);
- }));
- }
- cn(t) {
- let e = this.un.get(t);
- if (e) return e;
- if (0 === t.filters.length) e = [ t ]; else {
- e = Br(gn.create(t.filters, "and" )).map((e => Mn(t.path, t.collectionGroup, t.orderBy, e.getFilters(), t.limit, t.startAt, t.endAt)));
- }
- return this.un.set(t, e), e;
- }
-
- fn(t, e, n, s, i, r, o) {
-
-
-
-
- const u = (null != e ? e.length : 1) * Math.max(n.length, i.length), c = u / (null != e ? e.length : 1), a = [];
- for (let h = 0; h < u; ++h) {
- const u = e ? this.dn(e[h / c]) : Hr, l = this.wn(t, u, n[h % c], s), f = this._n(t, u, i[h % c], r), d = o.map((e => this.wn(t, u, e,
- !0)));
- a.push(...this.createRange(l, f, d));
- }
- return a;
- }
- wn(t, e, n, s) {
- const i = new kr(t, ht.empty(), e, n);
- return s ? i : i.Je();
- }
- _n(t, e, n, s) {
- const i = new kr(t, ht.empty(), e, n);
- return s ? i.Je() : i;
- }
- an(t, e) {
- const n = new Or(e), s = null != e.collectionGroup ? e.collectionGroup : e.path.lastSegment();
- return this.getFieldIndexes(t, s).next((t => {
-
- let e = null;
- for (const s of t) {
- n.tn(s) && (!e || s.fields.length > e.fields.length) && (e = s);
- }
- return e;
- }));
- }
- getIndexType(t, e) {
- let n = 2 ;
- const s = this.cn(e);
- return Rt.forEach(s, (e => this.an(t, e).next((t => {
- t ? 0 !== n && t.fields.length < function(t) {
- let e = new Ee(at.comparator), n = !1;
- for (const s of t.filters) for (const t of s.getFlattenedFilters())
-
-
- t.field.isKeyField() || (
-
-
-
-
- "array-contains" === t.op || "array-contains-any" === t.op ? n = !0 : e = e.add(t.field));
- for (const n of t.orderBy)
-
-
- n.field.isKeyField() || (e = e.add(n.field));
- return e.size + (n ? 1 : 0);
- }(e) && (n = 1 ) : n = 0 ;
- })))).next((() =>
-
-
-
- function(t) {
- return null !== t.limit;
- }(e) && s.length > 1 && 2 === n ? 1 : n));
- }
-
- mn(t, e) {
- const n = new Nr;
- for (const s of dt(t)) {
- const t = e.data.field(s.fieldPath);
- if (null == t) return null;
- const i = n.He(s.kind);
- br.Ve._e(t, i);
- }
- return n.Qe();
- }
- dn(t) {
- const e = new Nr;
- return br.Ve._e(t, e.He(0 )), e.Qe();
- }
-
- gn(t, e) {
- const n = new Nr;
- return br.Ve._e(We(this.databaseId, e), n.He(function(t) {
- const e = dt(t);
- return 0 === e.length ? 0 : e[e.length - 1].kind;
- }(t))), n.Qe();
- }
-
- ln(t, e, n) {
- if (null === n) return [];
- let s = [];
- s.push(new Nr);
- let i = 0;
- for (const r of dt(t)) {
- const t = n[i++];
- for (const n of s) if (this.yn(e, r.fieldPath) && Je(t)) s = this.pn(s, r, t); else {
- const e = n.He(r.kind);
- br.Ve._e(t, e);
- }
- }
- return this.In(s);
- }
-
- hn(t, e, n) {
- return this.ln(t, e, n.position);
- }
- In(t) {
- const e = [];
- for (let n = 0; n < t.length; ++n) e[n] = t[n].Qe();
- return e;
- }
-
- pn(t, e, n) {
- const s = [ ...t ], i = [];
- for (const t of n.arrayValue.values || []) for (const n of s) {
- const s = new Nr;
- s.seed(n.Qe()), br.Ve._e(t, s.He(e.kind)), i.push(s);
- }
- return i;
- }
- yn(t, e) {
- return !!t.filters.find((t => t instanceof mn && t.field.isEqual(e) && ("in" === t.op || "not-in" === t.op)));
- }
- getFieldIndexes(t, e) {
- const n = Zr(t), s = to(t);
- return (e ? n.j("collectionGroupIndex", IDBKeyRange.bound(e, e)) : n.j()).next((t => {
- const e = [];
- return Rt.forEach(t, (t => s.get([ t.indexId, this.uid ]).next((n => {
- e.push(function(t, e) {
- const n = e ? new gt(e.sequenceNumber, new It(wr(e.readTime), new ht(Gt(e.documentKey)), e.largestBatchId)) : gt.empty(), s = t.fields.map((([t, e]) => new _t(at.fromServerFormat(t), e)));
- return new lt(t.indexId, t.collectionGroup, s, n);
- }(t, n));
- })))).next((() => e));
- }));
- }
- getNextCollectionGroupToUpdate(t) {
- return this.getFieldIndexes(t).next((t => 0 === t.length ? null : (t.sort(((t, e) => {
- const n = t.indexState.sequenceNumber - e.indexState.sequenceNumber;
- return 0 !== n ? n : et(t.collectionGroup, e.collectionGroup);
- })), t[0].collectionGroup)));
- }
- updateCollectionGroup(t, e, n) {
- const s = Zr(t), i = to(t);
- return this.Tn(t).next((t => s.j("collectionGroupIndex", IDBKeyRange.bound(e, e)).next((e => Rt.forEach(e, (e => i.put(Tr(e.indexId, this.user, t, n))))))));
- }
- updateIndexEntries(t, e) {
-
-
-
-
-
- const n = new Map;
- return Rt.forEach(e, ((e, s) => {
- const i = n.get(e.collectionGroup);
- return (i ? Rt.resolve(i) : this.getFieldIndexes(t, e.collectionGroup)).next((i => (n.set(e.collectionGroup, i),
- Rt.forEach(i, (n => this.En(t, e, n).next((e => {
- const i = this.An(s, n);
- return e.isEqual(i) ? Rt.resolve() : this.vn(t, s, n, e, i);
- })))))));
- }));
- }
- Rn(t, e, n, s) {
- return Xr(t).put({
- indexId: s.indexId,
- uid: this.uid,
- arrayValue: s.arrayValue,
- directionalValue: s.directionalValue,
- orderedDocumentKey: this.gn(n, e.key),
- documentKey: e.key.path.toArray()
- });
- }
- Pn(t, e, n, s) {
- return Xr(t).delete([ s.indexId, this.uid, s.arrayValue, s.directionalValue, this.gn(n, e.key), e.key.path.toArray() ]);
- }
- En(t, e, n) {
- const s = Xr(t);
- let i = new Ee(Mr);
- return s.X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only([ n.indexId, this.uid, this.gn(n, e) ])
- }, ((t, s) => {
- i = i.add(new kr(n.indexId, e, s.arrayValue, s.directionalValue));
- })).next((() => i));
- }
- An(t, e) {
- let n = new Ee(Mr);
- const s = this.mn(e, t);
- if (null == s) return n;
- const i = ft(e);
- if (null != i) {
- const r = t.data.field(i.fieldPath);
- if (Je(r)) for (const i of r.arrayValue.values || []) n = n.add(new kr(e.indexId, t.key, this.dn(i), s));
- } else n = n.add(new kr(e.indexId, t.key, Hr, s));
- return n;
- }
-
- vn(t, e, n, s, i) {
- N("IndexedDbIndexManager", "Updating index entries for document '%s'", e.key);
- const r = [];
- return function(t, e, n, s, i) {
- const r = t.getIterator(), o = e.getIterator();
- let u = ve(r), c = ve(o);
-
-
- for (;u || c; ) {
- let t = !1, e = !1;
- if (u && c) {
- const s = n(u, c);
- s < 0 ?
-
-
- e = !0 : s > 0 && (
-
-
- t = !0);
- } else null != u ? e = !0 : t = !0;
- t ? (s(c), c = ve(o)) : e ? (i(u), u = ve(r)) : (u = ve(r), c = ve(o));
- }
- }(s, i, Mr, (
- s => {
- r.push(this.Rn(t, e, n, s));
- }), (
- s => {
- r.push(this.Pn(t, e, n, s));
- })), Rt.waitFor(r);
- }
- Tn(t) {
- let e = 1;
- return to(t).X({
- index: "sequenceNumberIndex",
- reverse: !0,
- range: IDBKeyRange.upperBound([ this.uid, Number.MAX_SAFE_INTEGER ])
- }, ((t, n, s) => {
- s.done(), e = n.sequenceNumber + 1;
- })).next((() => e));
- }
-
- createRange(t, e, n) {
-
-
- n = n.sort(((t, e) => Mr(t, e))).filter(((t, e, n) => !e || 0 !== Mr(t, n[e - 1])));
- const s = [];
- s.push(t);
- for (const i of n) {
- const n = Mr(i, t), r = Mr(i, e);
- if (0 === n)
-
-
- s[0] = t.Je(); else if (n > 0 && r < 0)
-
- s.push(i), s.push(i.Je()); else if (r > 0)
-
- break;
- }
- s.push(e);
- const i = [];
- for (let t = 0; t < s.length; t += 2) {
-
-
- if (this.bn(s[t], s[t + 1])) return [];
- const e = [ s[t].indexId, this.uid, s[t].arrayValue, s[t].directionalValue, Hr, [] ], n = [ s[t + 1].indexId, this.uid, s[t + 1].arrayValue, s[t + 1].directionalValue, Hr, [] ];
- i.push(IDBKeyRange.bound(e, n));
- }
- return i;
- }
- bn(t, e) {
-
-
- return Mr(t, e) > 0;
- }
- getMinOffsetFromCollectionGroup(t, e) {
- return this.getFieldIndexes(t, e).next(eo);
- }
- getMinOffset(t, e) {
- return Rt.mapArray(this.cn(e), (e => this.an(t, e).next((t => t || O())))).next(eo);
- }
- }
- function Yr(t) {
- return _e(t, "collectionParents");
- }
- function Xr(t) {
- return _e(t, "indexEntries");
- }
- function Zr(t) {
- return _e(t, "indexConfiguration");
- }
- function to(t) {
- return _e(t, "indexState");
- }
- function eo(t) {
- F(0 !== t.length);
- let e = t[0].indexState.offset, n = e.largestBatchId;
- for (let s = 1; s < t.length; s++) {
- const i = t[s].indexState.offset;
- Tt(i, e) < 0 && (e = i), n < i.largestBatchId && (n = i.largestBatchId);
- }
- return new It(e.readTime, e.documentKey, n);
- }
- const no = {
- didRun: !1,
- sequenceNumbersCollected: 0,
- targetsRemoved: 0,
- documentsRemoved: 0
- };
- class so {
- constructor(
- // When we attempt to collect, we will only do so if the cache size is greater than this
- // threshold. Passing `COLLECTION_DISABLED` here will cause collection to always be skipped.
- t,
- // The percentage of sequence numbers that we will attempt to collect
- e,
- // A cap on the total number of sequence numbers that will be collected. This prevents
- // us from collecting a huge number of sequence numbers if the cache has grown very large.
- n) {
- this.cacheSizeCollectionThreshold = t, this.percentileToCollect = e, this.maximumSequenceNumbersToCollect = n;
- }
- static withCacheSize(t) {
- return new so(t, so.DEFAULT_COLLECTION_PERCENTILE, so.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT);
- }
- }
- function io(t, e, n) {
- const s = t.store("mutations"), i = t.store("documentMutations"), r = [], o = IDBKeyRange.only(n.batchId);
- let u = 0;
- const c = s.X({
- range: o
- }, ((t, e, n) => (u++, n.delete())));
- r.push(c.next((() => {
- F(1 === u);
- })));
- const a = [];
- for (const t of n.mutations) {
- const s = zt(e, t.key.path, n.batchId);
- r.push(i.delete(s)), a.push(t.key);
- }
- return Rt.waitFor(r).next((() => a));
- }
- function ro(t) {
- if (!t) return 0;
- let e;
- if (t.document) e = t.document; else if (t.unknownDocument) e = t.unknownDocument; else {
- if (!t.noDocument) throw O();
- e = t.noDocument;
- }
- return JSON.stringify(e).length;
- }
- so.DEFAULT_COLLECTION_PERCENTILE = 10,
- so.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT = 1e3, so.DEFAULT = new so(41943040, so.DEFAULT_COLLECTION_PERCENTILE, so.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),
- so.DISABLED = new so(-1, 0, 0);
- class oo {
- constructor(
- /**
- * The normalized userId (e.g. null UID => "" userId) used to store /
- * retrieve mutations.
- */
- t, e, n, s) {
- this.userId = t, this.serializer = e, this.indexManager = n, this.referenceDelegate = s,
-
-
- this.Vn = {};
- }
-
- static de(t, e, n, s) {
-
-
-
-
- F("" !== t.uid);
- const i = t.isAuthenticated() ? t.uid : "";
- return new oo(i, e, n, s);
- }
- checkEmpty(t) {
- let e = !0;
- const n = IDBKeyRange.bound([ this.userId, Number.NEGATIVE_INFINITY ], [ this.userId, Number.POSITIVE_INFINITY ]);
- return co(t).X({
- index: "userMutationsIndex",
- range: n
- }, ((t, n, s) => {
- e = !1, s.done();
- })).next((() => e));
- }
- addMutationBatch(t, e, n, s) {
- const i = ao(t), r = co(t);
-
-
-
-
-
-
-
-
-
- return r.add({}).next((o => {
- F("number" == typeof o);
- const u = new Zs(o, e, n, s), c = function(t, e, n) {
- const s = n.baseMutations.map((e => ji(t.fe, e))), i = n.mutations.map((e => ji(t.fe, e)));
- return {
- userId: e,
- batchId: n.batchId,
- localWriteTimeMs: n.localWriteTime.toMillis(),
- baseMutations: s,
- mutations: i
- };
- }(this.serializer, this.userId, u), a = [];
- let h = new Ee(((t, e) => et(t.canonicalString(), e.canonicalString())));
- for (const t of s) {
- const e = zt(this.userId, t.key.path, o);
- h = h.add(t.key.path.popLast()), a.push(r.put(c)), a.push(i.put(e, Wt));
- }
- return h.forEach((e => {
- a.push(this.indexManager.addToCollectionParentIndex(t, e));
- })), t.addOnCommittedListener((() => {
- this.Vn[o] = u.keys();
- })), Rt.waitFor(a).next((() => u));
- }));
- }
- lookupMutationBatch(t, e) {
- return co(t).get(e).next((t => t ? (F(t.userId === this.userId), _r(this.serializer, t)) : null));
- }
-
-
- Sn(t, e) {
- return this.Vn[e] ? Rt.resolve(this.Vn[e]) : this.lookupMutationBatch(t, e).next((t => {
- if (t) {
- const n = t.keys();
- return this.Vn[e] = n, n;
- }
- return null;
- }));
- }
- getNextMutationBatchAfterBatchId(t, e) {
- const n = e + 1, s = IDBKeyRange.lowerBound([ this.userId, n ]);
- let i = null;
- return co(t).X({
- index: "userMutationsIndex",
- range: s
- }, ((t, e, s) => {
- e.userId === this.userId && (F(e.batchId >= n), i = _r(this.serializer, e)), s.done();
- })).next((() => i));
- }
- getHighestUnacknowledgedBatchId(t) {
- const e = IDBKeyRange.upperBound([ this.userId, Number.POSITIVE_INFINITY ]);
- let n = -1;
- return co(t).X({
- index: "userMutationsIndex",
- range: e,
- reverse: !0
- }, ((t, e, s) => {
- n = e.batchId, s.done();
- })).next((() => n));
- }
- getAllMutationBatches(t) {
- const e = IDBKeyRange.bound([ this.userId, -1 ], [ this.userId, Number.POSITIVE_INFINITY ]);
- return co(t).j("userMutationsIndex", e).next((t => t.map((t => _r(this.serializer, t)))));
- }
- getAllMutationBatchesAffectingDocumentKey(t, e) {
-
-
- const n = jt(this.userId, e.path), s = IDBKeyRange.lowerBound(n), i = [];
- return ao(t).X({
- range: s
- }, ((n, s, r) => {
- const [o, u, c] = n, a = Gt(u);
-
-
-
-
-
-
-
- if (o === this.userId && e.path.isEqual(a))
-
- return co(t).get(c).next((t => {
- if (!t) throw O();
- F(t.userId === this.userId), i.push(_r(this.serializer, t));
- }));
- r.done();
- })).next((() => i));
- }
- getAllMutationBatchesAffectingDocumentKeys(t, e) {
- let n = new Ee(et);
- const s = [];
- return e.forEach((e => {
- const i = jt(this.userId, e.path), r = IDBKeyRange.lowerBound(i), o = ao(t).X({
- range: r
- }, ((t, s, i) => {
- const [r, o, u] = t, c = Gt(o);
-
-
-
-
-
-
-
- r === this.userId && e.path.isEqual(c) ? n = n.add(u) : i.done();
- }));
- s.push(o);
- })), Rt.waitFor(s).next((() => this.Dn(t, n)));
- }
- getAllMutationBatchesAffectingQuery(t, e) {
- const n = e.path, s = n.length + 1, i = jt(this.userId, n), r = IDBKeyRange.lowerBound(i);
-
-
-
- let o = new Ee(et);
- return ao(t).X({
- range: r
- }, ((t, e, i) => {
- const [r, u, c] = t, a = Gt(u);
- r === this.userId && n.isPrefixOf(a) ?
-
-
-
-
-
- a.length === s && (o = o.add(c)) : i.done();
- })).next((() => this.Dn(t, o)));
- }
- Dn(t, e) {
- const n = [], s = [];
-
- return e.forEach((e => {
- s.push(co(t).get(e).next((t => {
- if (null === t) throw O();
- F(t.userId === this.userId), n.push(_r(this.serializer, t));
- })));
- })), Rt.waitFor(s).next((() => n));
- }
- removeMutationBatch(t, e) {
- return io(t.ht, this.userId, e).next((n => (t.addOnCommittedListener((() => {
- this.Cn(e.batchId);
- })), Rt.forEach(n, (e => this.referenceDelegate.markPotentiallyOrphaned(t, e))))));
- }
-
-
- Cn(t) {
- delete this.Vn[t];
- }
- performConsistencyCheck(t) {
- return this.checkEmpty(t).next((e => {
- if (!e) return Rt.resolve();
-
-
- const n = IDBKeyRange.lowerBound([ this.userId ]);
- const s = [];
- return ao(t).X({
- range: n
- }, ((t, e, n) => {
- if (t[0] === this.userId) {
- const e = Gt(t[1]);
- s.push(e);
- } else n.done();
- })).next((() => {
- F(0 === s.length);
- }));
- }));
- }
- containsKey(t, e) {
- return uo(t, this.userId, e);
- }
-
-
- xn(t) {
- return ho(t).get(this.userId).next((t => t || {
- userId: this.userId,
- lastAcknowledgedBatchId: -1,
- lastStreamToken: ""
- }));
- }
- }
- function uo(t, e, n) {
- const s = jt(e, n.path), i = s[1], r = IDBKeyRange.lowerBound(s);
- let o = !1;
- return ao(t).X({
- range: r,
- Y: !0
- }, ((t, n, s) => {
- const [r, u, c] = t;
- r === e && u === i && (o = !0), s.done();
- })).next((() => o));
- }
- function co(t) {
- return _e(t, "mutations");
- }
- function ao(t) {
- return _e(t, "documentMutations");
- }
- function ho(t) {
- return _e(t, "mutationQueues");
- }
- class lo {
- constructor(t) {
- this.Nn = t;
- }
- next() {
- return this.Nn += 2, this.Nn;
- }
- static kn() {
-
-
-
-
- return new lo(0);
- }
- static Mn() {
-
- return new lo(-1);
- }
- }
- class fo {
- constructor(t, e) {
- this.referenceDelegate = t, this.serializer = e;
- }
-
-
-
-
-
-
- allocateTargetId(t) {
- return this.$n(t).next((e => {
- const n = new lo(e.highestTargetId);
- return e.highestTargetId = n.next(), this.On(t, e).next((() => e.highestTargetId));
- }));
- }
- getLastRemoteSnapshotVersion(t) {
- return this.$n(t).next((t => rt.fromTimestamp(new it(t.lastRemoteSnapshotVersion.seconds, t.lastRemoteSnapshotVersion.nanoseconds))));
- }
- getHighestSequenceNumber(t) {
- return this.$n(t).next((t => t.highestListenSequenceNumber));
- }
- setTargetsMetadata(t, e, n) {
- return this.$n(t).next((s => (s.highestListenSequenceNumber = e, n && (s.lastRemoteSnapshotVersion = n.toTimestamp()),
- e > s.highestListenSequenceNumber && (s.highestListenSequenceNumber = e), this.On(t, s))));
- }
- addTargetData(t, e) {
- return this.Fn(t, e).next((() => this.$n(t).next((n => (n.targetCount += 1, this.Bn(e, n),
- this.On(t, n))))));
- }
- updateTargetData(t, e) {
- return this.Fn(t, e);
- }
- removeTargetData(t, e) {
- return this.removeMatchingKeysForTargetId(t, e.targetId).next((() => wo(t).delete(e.targetId))).next((() => this.$n(t))).next((e => (F(e.targetCount > 0),
- e.targetCount -= 1, this.On(t, e))));
- }
-
- removeTargets(t, e, n) {
- let s = 0;
- const i = [];
- return wo(t).X(((r, o) => {
- const u = mr(o);
- u.sequenceNumber <= e && null === n.get(u.targetId) && (s++, i.push(this.removeTargetData(t, u)));
- })).next((() => Rt.waitFor(i))).next((() => s));
- }
-
- forEachTarget(t, e) {
- return wo(t).X(((t, n) => {
- const s = mr(n);
- e(s);
- }));
- }
- $n(t) {
- return _o(t).get("targetGlobalKey").next((t => (F(null !== t), t)));
- }
- On(t, e) {
- return _o(t).put("targetGlobalKey", e);
- }
- Fn(t, e) {
- return wo(t).put(gr(this.serializer, e));
- }
-
- Bn(t, e) {
- let n = !1;
- return t.targetId > e.highestTargetId && (e.highestTargetId = t.targetId, n = !0),
- t.sequenceNumber > e.highestListenSequenceNumber && (e.highestListenSequenceNumber = t.sequenceNumber,
- n = !0), n;
- }
- getTargetCount(t) {
- return this.$n(t).next((t => t.targetCount));
- }
- getTargetData(t, e) {
-
-
-
- const n = $n(e), s = IDBKeyRange.bound([ n, Number.NEGATIVE_INFINITY ], [ n, Number.POSITIVE_INFINITY ]);
- let i = null;
- return wo(t).X({
- range: s,
- index: "queryTargetsIndex"
- }, ((t, n, s) => {
- const r = mr(n);
-
-
- On(e, r.target) && (i = r, s.done());
- })).next((() => i));
- }
- addMatchingKeys(t, e, n) {
-
-
- const s = [], i = mo(t);
- return e.forEach((e => {
- const r = qt(e.path);
- s.push(i.put({
- targetId: n,
- path: r
- })), s.push(this.referenceDelegate.addReference(t, n, e));
- })), Rt.waitFor(s);
- }
- removeMatchingKeys(t, e, n) {
-
-
- const s = mo(t);
- return Rt.forEach(e, (e => {
- const i = qt(e.path);
- return Rt.waitFor([ s.delete([ n, i ]), this.referenceDelegate.removeReference(t, n, e) ]);
- }));
- }
- removeMatchingKeysForTargetId(t, e) {
- const n = mo(t), s = IDBKeyRange.bound([ e ], [ e + 1 ],
- !1,
- !0);
- return n.delete(s);
- }
- getMatchingKeysForTargetId(t, e) {
- const n = IDBKeyRange.bound([ e ], [ e + 1 ],
- !1,
- !0), s = mo(t);
- let i = gs();
- return s.X({
- range: n,
- Y: !0
- }, ((t, e, n) => {
- const s = Gt(t[1]), r = new ht(s);
- i = i.add(r);
- })).next((() => i));
- }
- containsKey(t, e) {
- const n = qt(e.path), s = IDBKeyRange.bound([ n ], [ st(n) ],
- !1,
- !0);
- let i = 0;
- return mo(t).X({
- index: "documentTargetsIndex",
- Y: !0,
- range: s
- }, (([t, e], n, s) => {
-
-
-
- 0 !== t && (i++, s.done());
- })).next((() => i > 0));
- }
-
-
- le(t, e) {
- return wo(t).get(e).next((t => t ? mr(t) : null));
- }
- }
- function wo(t) {
- return _e(t, "targets");
- }
- function _o(t) {
- return _e(t, "targetGlobal");
- }
- function mo(t) {
- return _e(t, "targetDocuments");
- }
- function go([t, e], [n, s]) {
- const i = et(t, n);
- return 0 === i ? et(e, s) : i;
- }
- class yo {
- constructor(t) {
- this.Ln = t, this.buffer = new Ee(go), this.qn = 0;
- }
- Un() {
- return ++this.qn;
- }
- Kn(t) {
- const e = [ t, this.Un() ];
- if (this.buffer.size < this.Ln) this.buffer = this.buffer.add(e); else {
- const t = this.buffer.last();
- go(e, t) < 0 && (this.buffer = this.buffer.delete(t).add(e));
- }
- }
- get maxValue() {
-
-
-
-
-
-
- return this.buffer.last()[0];
- }
- }
- class po {
- constructor(t, e, n) {
- this.garbageCollector = t, this.asyncQueue = e, this.localStore = n, this.Gn = null;
- }
- start() {
- -1 !== this.garbageCollector.params.cacheSizeCollectionThreshold && this.Qn(6e4);
- }
- stop() {
- this.Gn && (this.Gn.cancel(), this.Gn = null);
- }
- get started() {
- return null !== this.Gn;
- }
- Qn(t) {
- N("LruGarbageCollector", `Garbage collection scheduled in ${t}ms`), this.Gn = this.asyncQueue.enqueueAfterDelay("lru_garbage_collection" , t, (async () => {
- this.Gn = null;
- try {
- await this.localStore.collectGarbage(this.garbageCollector);
- } catch (t) {
- Dt(t) ? N("LruGarbageCollector", "Ignoring IndexedDB error during garbage collection: ", t) : await vt(t);
- }
- await this.Qn(3e5);
- }));
- }
- }
- class Io {
- constructor(t, e) {
- this.jn = t, this.params = e;
- }
- calculateTargetCount(t, e) {
- return this.jn.zn(t).next((t => Math.floor(e / 100 * t)));
- }
- nthSequenceNumber(t, e) {
- if (0 === e) return Rt.resolve(Ot.ct);
- const n = new yo(e);
- return this.jn.forEachTarget(t, (t => n.Kn(t.sequenceNumber))).next((() => this.jn.Wn(t, (t => n.Kn(t))))).next((() => n.maxValue));
- }
- removeTargets(t, e, n) {
- return this.jn.removeTargets(t, e, n);
- }
- removeOrphanedDocuments(t, e) {
- return this.jn.removeOrphanedDocuments(t, e);
- }
- collect(t, e) {
- return -1 === this.params.cacheSizeCollectionThreshold ? (N("LruGarbageCollector", "Garbage collection skipped; disabled"),
- Rt.resolve(no)) : this.getCacheSize(t).next((n => n < this.params.cacheSizeCollectionThreshold ? (N("LruGarbageCollector", `Garbage collection skipped; Cache size ${n} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),
- no) : this.Hn(t, e)));
- }
- getCacheSize(t) {
- return this.jn.getCacheSize(t);
- }
- Hn(t, e) {
- let n, s, i, r, o, c, a;
- const h = Date.now();
- return this.calculateTargetCount(t, this.params.percentileToCollect).next((e => (
-
- e > this.params.maximumSequenceNumbersToCollect ? (N("LruGarbageCollector", `Capping sequence numbers to collect down to the maximum of ${this.params.maximumSequenceNumbersToCollect} from ${e}`),
- s = this.params.maximumSequenceNumbersToCollect) : s = e, r = Date.now(), this.nthSequenceNumber(t, s)))).next((s => (n = s,
- o = Date.now(), this.removeTargets(t, n, e)))).next((e => (i = e, c = Date.now(),
- this.removeOrphanedDocuments(t, n)))).next((t => {
- if (a = Date.now(), C() <= LogLevel.DEBUG) {
- N("LruGarbageCollector", `LRU Garbage Collection\n\tCounted targets in ${r - h}ms\n\tDetermined least recently used ${s} in ` + (o - r) + "ms\n" + `\tRemoved ${i} targets in ` + (c - o) + "ms\n" + `\tRemoved ${t} documents in ` + (a - c) + "ms\n" + `Total Duration: ${a - h}ms`);
- }
- return Rt.resolve({
- didRun: !0,
- sequenceNumbersCollected: s,
- targetsRemoved: i,
- documentsRemoved: t
- });
- }));
- }
- }
- function To(t, e) {
- return new Io(t, e);
- }
- class Eo {
- constructor(t, e) {
- this.db = t, this.garbageCollector = To(this, e);
- }
- zn(t) {
- const e = this.Jn(t);
- return this.db.getTargetCache().getTargetCount(t).next((t => e.next((e => t + e))));
- }
- Jn(t) {
- let e = 0;
- return this.Wn(t, (t => {
- e++;
- })).next((() => e));
- }
- forEachTarget(t, e) {
- return this.db.getTargetCache().forEachTarget(t, e);
- }
- Wn(t, e) {
- return this.Yn(t, ((t, n) => e(n)));
- }
- addReference(t, e, n) {
- return Ao(t, n);
- }
- removeReference(t, e, n) {
- return Ao(t, n);
- }
- removeTargets(t, e, n) {
- return this.db.getTargetCache().removeTargets(t, e, n);
- }
- markPotentiallyOrphaned(t, e) {
- return Ao(t, e);
- }
-
- Xn(t, e) {
- return function(t, e) {
- let n = !1;
- return ho(t).Z((s => uo(t, s, e).next((t => (t && (n = !0), Rt.resolve(!t)))))).next((() => n));
- }(t, e);
- }
- removeOrphanedDocuments(t, e) {
- const n = this.db.getRemoteDocumentCache().newChangeBuffer(), s = [];
- let i = 0;
- return this.Yn(t, ((r, o) => {
- if (o <= e) {
- const e = this.Xn(t, r).next((e => {
- if (!e)
-
-
- return i++, n.getEntry(t, r).next((() => (n.removeEntry(r, rt.min()), mo(t).delete([ 0, qt(r.path) ]))));
- }));
- s.push(e);
- }
- })).next((() => Rt.waitFor(s))).next((() => n.apply(t))).next((() => i));
- }
- removeTarget(t, e) {
- const n = e.withSequenceNumber(t.currentSequenceNumber);
- return this.db.getTargetCache().updateTargetData(t, n);
- }
- updateLimboDocument(t, e) {
- return Ao(t, e);
- }
-
- Yn(t, e) {
- const n = mo(t);
- let s, i = Ot.ct;
- return n.X({
- index: "documentTargetsIndex"
- }, (([t, n], {path: r, sequenceNumber: o}) => {
- 0 === t ? (
-
-
- i !== Ot.ct && e(new ht(Gt(s)), i),
-
-
-
-
- i = o, s = r) :
-
-
- i = Ot.ct;
- })).next((() => {
-
-
-
- i !== Ot.ct && e(new ht(Gt(s)), i);
- }));
- }
- getCacheSize(t) {
- return this.db.getRemoteDocumentCache().getSize(t);
- }
- }
- function Ao(t, e) {
- return mo(t).put(
-
- function(t, e) {
- return {
- targetId: 0,
- path: qt(t.path),
- sequenceNumber: e
- };
- }(e, t.currentSequenceNumber));
- }
- class vo {
- constructor() {
-
- this.changes = new os((t => t.toString()), ((t, e) => t.isEqual(e))), this.changesApplied = !1;
- }
-
- addEntry(t) {
- this.assertNotApplied(), this.changes.set(t.key, t);
- }
-
- removeEntry(t, e) {
- this.assertNotApplied(), this.changes.set(t, an.newInvalidDocument(t).setReadTime(e));
- }
-
- getEntry(t, e) {
- this.assertNotApplied();
- const n = this.changes.get(e);
- return void 0 !== n ? Rt.resolve(n) : this.getFromCache(t, e);
- }
-
- getEntries(t, e) {
- return this.getAllFromCache(t, e);
- }
-
- apply(t) {
- return this.assertNotApplied(), this.changesApplied = !0, this.applyChanges(t);
- }
- assertNotApplied() {}
- }
- class Ro {
- constructor(t) {
- this.serializer = t;
- }
- setIndexManager(t) {
- this.indexManager = t;
- }
-
- addEntry(t, e, n) {
- return So(t).put(n);
- }
-
- removeEntry(t, e, n) {
- return So(t).delete(
-
- function(t, e) {
- const n = t.path.toArray();
- return [
- n.slice(0, n.length - 2),
- n[n.length - 2], fr(e),
- n[n.length - 1] ];
- }
-
- (e, n));
- }
-
- updateMetadata(t, e) {
- return this.getMetadata(t).next((n => (n.byteSize += e, this.Zn(t, n))));
- }
- getEntry(t, e) {
- let n = an.newInvalidDocument(e);
- return So(t).X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only(Do(e))
- }, ((t, s) => {
- n = this.ts(e, s);
- })).next((() => n));
- }
-
- es(t, e) {
- let n = {
- size: 0,
- document: an.newInvalidDocument(e)
- };
- return So(t).X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only(Do(e))
- }, ((t, s) => {
- n = {
- document: this.ts(e, s),
- size: ro(s)
- };
- })).next((() => n));
- }
- getEntries(t, e) {
- let n = cs();
- return this.ns(t, e, ((t, e) => {
- const s = this.ts(t, e);
- n = n.insert(t, s);
- })).next((() => n));
- }
-
- ss(t, e) {
- let n = cs(), s = new pe(ht.comparator);
- return this.ns(t, e, ((t, e) => {
- const i = this.ts(t, e);
- n = n.insert(t, i), s = s.insert(t, ro(e));
- })).next((() => ({
- documents: n,
- rs: s
- })));
- }
- ns(t, e, n) {
- if (e.isEmpty()) return Rt.resolve();
- let s = new Ee(xo);
- e.forEach((t => s = s.add(t)));
- const i = IDBKeyRange.bound(Do(s.first()), Do(s.last())), r = s.getIterator();
- let o = r.getNext();
- return So(t).X({
- index: "documentKeyIndex",
- range: i
- }, ((t, e, s) => {
- const i = ht.fromSegments([ ...e.prefixPath, e.collectionGroup, e.documentId ]);
-
- for (;o && xo(o, i) < 0; ) n(o, null), o = r.getNext();
- o && o.isEqual(i) && (
-
- n(o, e), o = r.hasNext() ? r.getNext() : null),
-
- o ? s.G(Do(o)) : s.done();
- })).next((() => {
-
-
- for (;o; ) n(o, null), o = r.hasNext() ? r.getNext() : null;
- }));
- }
- getDocumentsMatchingQuery(t, e, n, s) {
- const i = e.path, r = [ i.popLast().toArray(), i.lastSegment(), fr(n.readTime), n.documentKey.path.isEmpty() ? "" : n.documentKey.path.lastSegment() ], o = [ i.popLast().toArray(), i.lastSegment(), [ Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER ], "" ];
- return So(t).j(IDBKeyRange.bound(r, o, !0)).next((t => {
- let n = cs();
- for (const i of t) {
- const t = this.ts(ht.fromSegments(i.prefixPath.concat(i.collectionGroup, i.documentId)), i);
- t.isFoundDocument() && (ns(e, t) || s.has(t.key)) && (
-
- n = n.insert(t.key, t));
- }
- return n;
- }));
- }
- getAllFromCollectionGroup(t, e, n, s) {
- let i = cs();
- const r = Co(e, n), o = Co(e, It.max());
- return So(t).X({
- index: "collectionGroupIndex",
- range: IDBKeyRange.bound(r, o, !0)
- }, ((t, e, n) => {
- const r = this.ts(ht.fromSegments(e.prefixPath.concat(e.collectionGroup, e.documentId)), e);
- i = i.insert(r.key, r), i.size === s && n.done();
- })).next((() => i));
- }
- newChangeBuffer(t) {
- return new bo(this, !!t && t.trackRemovals);
- }
- getSize(t) {
- return this.getMetadata(t).next((t => t.byteSize));
- }
- getMetadata(t) {
- return Vo(t).get("remoteDocumentGlobalKey").next((t => (F(!!t), t)));
- }
- Zn(t, e) {
- return Vo(t).put("remoteDocumentGlobalKey", e);
- }
-
- ts(t, e) {
- if (e) {
- const t = hr(this.serializer, e);
-
-
- if (!(t.isNoDocument() && t.version.isEqual(rt.min()))) return t;
- }
- return an.newInvalidDocument(t);
- }
- }
- function Po(t) {
- return new Ro(t);
- }
- class bo extends vo {
-
- constructor(t, e) {
- super(), this.os = t, this.trackRemovals = e,
-
-
- this.us = new os((t => t.toString()), ((t, e) => t.isEqual(e)));
- }
- applyChanges(t) {
- const e = [];
- let n = 0, s = new Ee(((t, e) => et(t.canonicalString(), e.canonicalString())));
- return this.changes.forEach(((i, r) => {
- const o = this.us.get(i);
- if (e.push(this.os.removeEntry(t, i, o.readTime)), r.isValidDocument()) {
- const u = lr(this.os.serializer, r);
- s = s.add(i.path.popLast());
- const c = ro(u);
- n += c - o.size, e.push(this.os.addEntry(t, i, u));
- } else if (n -= o.size, this.trackRemovals) {
-
-
-
-
- const n = lr(this.os.serializer, r.convertToNoDocument(rt.min()));
- e.push(this.os.addEntry(t, i, n));
- }
- })), s.forEach((n => {
- e.push(this.os.indexManager.addToCollectionParentIndex(t, n));
- })), e.push(this.os.updateMetadata(t, n)), Rt.waitFor(e);
- }
- getFromCache(t, e) {
-
- return this.os.es(t, e).next((t => (this.us.set(e, {
- size: t.size,
- readTime: t.document.readTime
- }), t.document)));
- }
- getAllFromCache(t, e) {
-
-
- return this.os.ss(t, e).next((({documents: t, rs: e}) => (
-
-
-
- e.forEach(((e, n) => {
- this.us.set(e, {
- size: n,
- readTime: t.get(e).readTime
- });
- })), t)));
- }
- }
- function Vo(t) {
- return _e(t, "remoteDocumentGlobal");
- }
- function So(t) {
- return _e(t, "remoteDocumentsV14");
- }
- function Do(t) {
- const e = t.path.toArray();
- return [
- e.slice(0, e.length - 2),
- e[e.length - 2],
- e[e.length - 1] ];
- }
- function Co(t, e) {
- const n = e.documentKey.path.toArray();
- return [
- t, fr(e.readTime),
- n.slice(0, n.length - 2),
- n.length > 0 ? n[n.length - 1] : "" ];
- }
- function xo(t, e) {
- const n = t.path.toArray(), s = e.path.toArray();
-
- let i = 0;
- for (let t = 0; t < n.length - 2 && t < s.length - 2; ++t) if (i = et(n[t], s[t]),
- i) return i;
- return i = et(n.length, s.length), i || (i = et(n[n.length - 2], s[s.length - 2]),
- i || et(n[n.length - 1], s[s.length - 1]));
- }
- class No {
- constructor(t,
- /**
- * The fields that are locally mutated by patch mutations.
- *
- * If the overlayed document is from set or delete mutations, this is `null`.
- * If there is no overlay (mutation) for the document, this is an empty `FieldMask`.
- */
- e) {
- this.overlayedDocument = t, this.mutatedFields = e;
- }
- }
- class ko {
- constructor(t, e, n, s) {
- this.remoteDocumentCache = t, this.mutationQueue = e, this.documentOverlayCache = n,
- this.indexManager = s;
- }
-
- getDocument(t, e) {
- let n = null;
- return this.documentOverlayCache.getOverlay(t, e).next((s => (n = s, this.remoteDocumentCache.getEntry(t, e)))).next((t => (null !== n && Ks(n.mutation, t, Re.empty(), it.now()),
- t)));
- }
-
- getDocuments(t, e) {
- return this.remoteDocumentCache.getEntries(t, e).next((e => this.getLocalViewOfDocuments(t, e, gs()).next((() => e))));
- }
-
- getLocalViewOfDocuments(t, e, n = gs()) {
- const s = fs();
- return this.populateOverlays(t, s, e).next((() => this.computeViews(t, e, s, n).next((t => {
- let e = hs();
- return t.forEach(((t, n) => {
- e = e.insert(t, n.overlayedDocument);
- })), e;
- }))));
- }
-
- getOverlayedDocuments(t, e) {
- const n = fs();
- return this.populateOverlays(t, n, e).next((() => this.computeViews(t, e, n, gs())));
- }
-
- populateOverlays(t, e, n) {
- const s = [];
- return n.forEach((t => {
- e.has(t) || s.push(t);
- })), this.documentOverlayCache.getOverlays(t, s).next((t => {
- t.forEach(((t, n) => {
- e.set(t, n);
- }));
- }));
- }
-
- computeViews(t, e, n, s) {
- let i = cs();
- const r = ws(), o = ws();
- return e.forEach(((t, e) => {
- const o = n.get(e.key);
-
-
-
-
-
-
-
- s.has(e.key) && (void 0 === o || o.mutation instanceof zs) ? i = i.insert(e.key, e) : void 0 !== o ? (r.set(e.key, o.mutation.getFieldMask()),
- Ks(o.mutation, e, o.mutation.getFieldMask(), it.now())) :
-
-
- r.set(e.key, Re.empty());
- })), this.recalculateAndSaveOverlays(t, i).next((t => (t.forEach(((t, e) => r.set(t, e))),
- e.forEach(((t, e) => {
- var n;
- return o.set(t, new No(e, null !== (n = r.get(t)) && void 0 !== n ? n : null));
- })), o)));
- }
- recalculateAndSaveOverlays(t, e) {
- const n = ws();
-
- let s = new pe(((t, e) => t - e)), i = gs();
- return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(t, e).next((t => {
- for (const i of t) i.keys().forEach((t => {
- const r = e.get(t);
- if (null === r) return;
- let o = n.get(t) || Re.empty();
- o = i.applyToLocalView(r, o), n.set(t, o);
- const u = (s.get(i.batchId) || gs()).add(t);
- s = s.insert(i.batchId, u);
- }));
- })).next((() => {
- const r = [], o = s.getReverseIterator();
-
-
- for (;o.hasNext(); ) {
- const s = o.getNext(), u = s.key, c = s.value, a = ds();
- c.forEach((t => {
- if (!i.has(t)) {
- const s = qs(e.get(t), n.get(t));
- null !== s && a.set(t, s), i = i.add(t);
- }
- })), r.push(this.documentOverlayCache.saveOverlays(t, u, a));
- }
- return Rt.waitFor(r);
- })).next((() => n));
- }
-
- recalculateAndSaveOverlaysForDocumentKeys(t, e) {
- return this.remoteDocumentCache.getEntries(t, e).next((e => this.recalculateAndSaveOverlays(t, e)));
- }
-
- getDocumentsMatchingQuery(t, e, n) {
-
- return function(t) {
- return ht.isDocumentKey(t.path) && null === t.collectionGroup && 0 === t.filters.length;
- }(e) ? this.getDocumentsMatchingDocumentQuery(t, e.path) : Wn(e) ? this.getDocumentsMatchingCollectionGroupQuery(t, e, n) : this.getDocumentsMatchingCollectionQuery(t, e, n);
- }
-
- getNextDocuments(t, e, n, s) {
- return this.remoteDocumentCache.getAllFromCollectionGroup(t, e, n, s).next((i => {
- const r = s - i.size > 0 ? this.documentOverlayCache.getOverlaysForCollectionGroup(t, e, n.largestBatchId, s - i.size) : Rt.resolve(fs());
-
-
-
-
- let o = -1, u = i;
- return r.next((e => Rt.forEach(e, ((e, n) => (o < n.largestBatchId && (o = n.largestBatchId),
- i.get(e) ? Rt.resolve() : this.remoteDocumentCache.getEntry(t, e).next((t => {
- u = u.insert(e, t);
- }))))).next((() => this.populateOverlays(t, e, i))).next((() => this.computeViews(t, u, e, gs()))).next((t => ({
- batchId: o,
- changes: ls(t)
- })))));
- }));
- }
- getDocumentsMatchingDocumentQuery(t, e) {
-
- return this.getDocument(t, new ht(e)).next((t => {
- let e = hs();
- return t.isFoundDocument() && (e = e.insert(t.key, t)), e;
- }));
- }
- getDocumentsMatchingCollectionGroupQuery(t, e, n) {
- const s = e.collectionGroup;
- let i = hs();
- return this.indexManager.getCollectionParents(t, s).next((r => Rt.forEach(r, (r => {
- const o = function(t, e) {
- return new Un(e,
- null, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, t.startAt, t.endAt);
- }(e, r.child(s));
- return this.getDocumentsMatchingCollectionQuery(t, o, n).next((t => {
- t.forEach(((t, e) => {
- i = i.insert(t, e);
- }));
- }));
- })).next((() => i))));
- }
- getDocumentsMatchingCollectionQuery(t, e, n) {
-
- let s;
- return this.documentOverlayCache.getOverlaysForCollection(t, e.path, n.largestBatchId).next((i => (s = i,
- this.remoteDocumentCache.getDocumentsMatchingQuery(t, e, n, s)))).next((t => {
-
-
- s.forEach(((e, n) => {
- const s = n.getKey();
- null === t.get(s) && (t = t.insert(s, an.newInvalidDocument(s)));
- }));
-
- let n = hs();
- return t.forEach(((t, i) => {
- const r = s.get(t);
- void 0 !== r && Ks(r.mutation, i, Re.empty(), it.now()),
-
- ns(e, i) && (n = n.insert(t, i));
- })), n;
- }));
- }
- }
- class Mo {
- constructor(t) {
- this.serializer = t, this.cs = new Map, this.hs = new Map;
- }
- getBundleMetadata(t, e) {
- return Rt.resolve(this.cs.get(e));
- }
- saveBundleMetadata(t, e) {
-
- var n;
- return this.cs.set(e.id, {
- id: (n = e).id,
- version: n.version,
- createTime: Ni(n.createTime)
- }), Rt.resolve();
- }
- getNamedQuery(t, e) {
- return Rt.resolve(this.hs.get(e));
- }
- saveNamedQuery(t, e) {
- return this.hs.set(e.name, function(t) {
- return {
- name: t.name,
- query: yr(t.bundledQuery),
- readTime: Ni(t.readTime)
- };
- }(e)), Rt.resolve();
- }
- }
- class $o {
- constructor() {
-
-
- this.overlays = new pe(ht.comparator), this.ls = new Map;
- }
- getOverlay(t, e) {
- return Rt.resolve(this.overlays.get(e));
- }
- getOverlays(t, e) {
- const n = fs();
- return Rt.forEach(e, (e => this.getOverlay(t, e).next((t => {
- null !== t && n.set(e, t);
- })))).next((() => n));
- }
- saveOverlays(t, e, n) {
- return n.forEach(((n, s) => {
- this.we(t, e, s);
- })), Rt.resolve();
- }
- removeOverlaysForBatchId(t, e, n) {
- const s = this.ls.get(n);
- return void 0 !== s && (s.forEach((t => this.overlays = this.overlays.remove(t))),
- this.ls.delete(n)), Rt.resolve();
- }
- getOverlaysForCollection(t, e, n) {
- const s = fs(), i = e.length + 1, r = new ht(e.child("")), o = this.overlays.getIteratorFrom(r);
- for (;o.hasNext(); ) {
- const t = o.getNext().value, r = t.getKey();
- if (!e.isPrefixOf(r.path)) break;
-
- r.path.length === i && (t.largestBatchId > n && s.set(t.getKey(), t));
- }
- return Rt.resolve(s);
- }
- getOverlaysForCollectionGroup(t, e, n, s) {
- let i = new pe(((t, e) => t - e));
- const r = this.overlays.getIterator();
- for (;r.hasNext(); ) {
- const t = r.getNext().value;
- if (t.getKey().getCollectionGroup() === e && t.largestBatchId > n) {
- let e = i.get(t.largestBatchId);
- null === e && (e = fs(), i = i.insert(t.largestBatchId, e)), e.set(t.getKey(), t);
- }
- }
- const o = fs(), u = i.getIterator();
- for (;u.hasNext(); ) {
- if (u.getNext().value.forEach(((t, e) => o.set(t, e))), o.size() >= s) break;
- }
- return Rt.resolve(o);
- }
- we(t, e, n) {
-
- const s = this.overlays.get(n.key);
- if (null !== s) {
- const t = this.ls.get(s.largestBatchId).delete(n.key);
- this.ls.set(s.largestBatchId, t);
- }
- this.overlays = this.overlays.insert(n.key, new ei(e, n));
-
- let i = this.ls.get(e);
- void 0 === i && (i = gs(), this.ls.set(e, i)), this.ls.set(e, i.add(n.key));
- }
- }
- class Oo {
- constructor() {
-
- this.fs = new Ee(Fo.ds),
-
- this.ws = new Ee(Fo._s);
- }
- isEmpty() {
- return this.fs.isEmpty();
- }
- addReference(t, e) {
- const n = new Fo(t, e);
- this.fs = this.fs.add(n), this.ws = this.ws.add(n);
- }
- gs(t, e) {
- t.forEach((t => this.addReference(t, e)));
- }
-
- removeReference(t, e) {
- this.ys(new Fo(t, e));
- }
- ps(t, e) {
- t.forEach((t => this.removeReference(t, e)));
- }
-
- Is(t) {
- const e = new ht(new ut([])), n = new Fo(e, t), s = new Fo(e, t + 1), i = [];
- return this.ws.forEachInRange([ n, s ], (t => {
- this.ys(t), i.push(t.key);
- })), i;
- }
- Ts() {
- this.fs.forEach((t => this.ys(t)));
- }
- ys(t) {
- this.fs = this.fs.delete(t), this.ws = this.ws.delete(t);
- }
- Es(t) {
- const e = new ht(new ut([])), n = new Fo(e, t), s = new Fo(e, t + 1);
- let i = gs();
- return this.ws.forEachInRange([ n, s ], (t => {
- i = i.add(t.key);
- })), i;
- }
- containsKey(t) {
- const e = new Fo(t, 0), n = this.fs.firstAfterOrEqual(e);
- return null !== n && t.isEqual(n.key);
- }
- }
- class Fo {
- constructor(t, e) {
- this.key = t, this.As = e;
- }
- static ds(t, e) {
- return ht.comparator(t.key, e.key) || et(t.As, e.As);
- }
- static _s(t, e) {
- return et(t.As, e.As) || ht.comparator(t.key, e.key);
- }
- }
- class Bo {
- constructor(t, e) {
- this.indexManager = t, this.referenceDelegate = e,
-
- this.mutationQueue = [],
-
- this.vs = 1,
-
- this.Rs = new Ee(Fo.ds);
- }
- checkEmpty(t) {
- return Rt.resolve(0 === this.mutationQueue.length);
- }
- addMutationBatch(t, e, n, s) {
- const i = this.vs;
- this.vs++, this.mutationQueue.length > 0 && this.mutationQueue[this.mutationQueue.length - 1];
- const r = new Zs(i, e, n, s);
- this.mutationQueue.push(r);
-
- for (const e of s) this.Rs = this.Rs.add(new Fo(e.key, i)), this.indexManager.addToCollectionParentIndex(t, e.key.path.popLast());
- return Rt.resolve(r);
- }
- lookupMutationBatch(t, e) {
- return Rt.resolve(this.Ps(e));
- }
- getNextMutationBatchAfterBatchId(t, e) {
- const n = e + 1, s = this.bs(n), i = s < 0 ? 0 : s;
-
-
- return Rt.resolve(this.mutationQueue.length > i ? this.mutationQueue[i] : null);
- }
- getHighestUnacknowledgedBatchId() {
- return Rt.resolve(0 === this.mutationQueue.length ? -1 : this.vs - 1);
- }
- getAllMutationBatches(t) {
- return Rt.resolve(this.mutationQueue.slice());
- }
- getAllMutationBatchesAffectingDocumentKey(t, e) {
- const n = new Fo(e, 0), s = new Fo(e, Number.POSITIVE_INFINITY), i = [];
- return this.Rs.forEachInRange([ n, s ], (t => {
- const e = this.Ps(t.As);
- i.push(e);
- })), Rt.resolve(i);
- }
- getAllMutationBatchesAffectingDocumentKeys(t, e) {
- let n = new Ee(et);
- return e.forEach((t => {
- const e = new Fo(t, 0), s = new Fo(t, Number.POSITIVE_INFINITY);
- this.Rs.forEachInRange([ e, s ], (t => {
- n = n.add(t.As);
- }));
- })), Rt.resolve(this.Vs(n));
- }
- getAllMutationBatchesAffectingQuery(t, e) {
-
-
- const n = e.path, s = n.length + 1;
-
-
-
-
- let i = n;
- ht.isDocumentKey(i) || (i = i.child(""));
- const r = new Fo(new ht(i), 0);
-
-
- let o = new Ee(et);
- return this.Rs.forEachWhile((t => {
- const e = t.key.path;
- return !!n.isPrefixOf(e) && (
-
-
-
-
-
- e.length === s && (o = o.add(t.As)), !0);
- }), r), Rt.resolve(this.Vs(o));
- }
- Vs(t) {
-
-
- const e = [];
- return t.forEach((t => {
- const n = this.Ps(t);
- null !== n && e.push(n);
- })), e;
- }
- removeMutationBatch(t, e) {
- F(0 === this.Ss(e.batchId, "removed")), this.mutationQueue.shift();
- let n = this.Rs;
- return Rt.forEach(e.mutations, (s => {
- const i = new Fo(s.key, e.batchId);
- return n = n.delete(i), this.referenceDelegate.markPotentiallyOrphaned(t, s.key);
- })).next((() => {
- this.Rs = n;
- }));
- }
- Cn(t) {
-
- }
- containsKey(t, e) {
- const n = new Fo(e, 0), s = this.Rs.firstAfterOrEqual(n);
- return Rt.resolve(e.isEqual(s && s.key));
- }
- performConsistencyCheck(t) {
- return this.mutationQueue.length, Rt.resolve();
- }
-
- Ss(t, e) {
- return this.bs(t);
- }
-
- bs(t) {
- if (0 === this.mutationQueue.length)
-
- return 0;
-
-
-
-
- return t - this.mutationQueue[0].batchId;
- }
-
- Ps(t) {
- const e = this.bs(t);
- if (e < 0 || e >= this.mutationQueue.length) return null;
- return this.mutationQueue[e];
- }
- }
- class Lo {
-
- constructor(t) {
- this.Ds = t,
-
- this.docs = new pe(ht.comparator),
-
- this.size = 0;
- }
- setIndexManager(t) {
- this.indexManager = t;
- }
-
- addEntry(t, e) {
- const n = e.key, s = this.docs.get(n), i = s ? s.size : 0, r = this.Ds(e);
- return this.docs = this.docs.insert(n, {
- document: e.mutableCopy(),
- size: r
- }), this.size += r - i, this.indexManager.addToCollectionParentIndex(t, n.path.popLast());
- }
-
- removeEntry(t) {
- const e = this.docs.get(t);
- e && (this.docs = this.docs.remove(t), this.size -= e.size);
- }
- getEntry(t, e) {
- const n = this.docs.get(e);
- return Rt.resolve(n ? n.document.mutableCopy() : an.newInvalidDocument(e));
- }
- getEntries(t, e) {
- let n = cs();
- return e.forEach((t => {
- const e = this.docs.get(t);
- n = n.insert(t, e ? e.document.mutableCopy() : an.newInvalidDocument(t));
- })), Rt.resolve(n);
- }
- getDocumentsMatchingQuery(t, e, n, s) {
- let i = cs();
-
-
- const r = e.path, o = new ht(r.child("")), u = this.docs.getIteratorFrom(o);
- for (;u.hasNext(); ) {
- const {key: t, value: {document: o}} = u.getNext();
- if (!r.isPrefixOf(t.path)) break;
- t.path.length > r.length + 1 || (Tt(pt(o), n) <= 0 || (s.has(o.key) || ns(e, o)) && (i = i.insert(o.key, o.mutableCopy())));
- }
- return Rt.resolve(i);
- }
- getAllFromCollectionGroup(t, e, n, s) {
-
-
- O();
- }
- Cs(t, e) {
- return Rt.forEach(this.docs, (t => e(t)));
- }
- newChangeBuffer(t) {
-
-
- return new qo(this);
- }
- getSize(t) {
- return Rt.resolve(this.size);
- }
- }
- class qo extends vo {
- constructor(t) {
- super(), this.os = t;
- }
- applyChanges(t) {
- const e = [];
- return this.changes.forEach(((n, s) => {
- s.isValidDocument() ? e.push(this.os.addEntry(t, s)) : this.os.removeEntry(n);
- })), Rt.waitFor(e);
- }
- getFromCache(t, e) {
- return this.os.getEntry(t, e);
- }
- getAllFromCache(t, e) {
- return this.os.getEntries(t, e);
- }
- }
- class Uo {
- constructor(t) {
- this.persistence = t,
-
- this.xs = new os((t => $n(t)), On),
-
- this.lastRemoteSnapshotVersion = rt.min(),
-
- this.highestTargetId = 0,
-
- this.Ns = 0,
-
- this.ks = new Oo, this.targetCount = 0, this.Ms = lo.kn();
- }
- forEachTarget(t, e) {
- return this.xs.forEach(((t, n) => e(n))), Rt.resolve();
- }
- getLastRemoteSnapshotVersion(t) {
- return Rt.resolve(this.lastRemoteSnapshotVersion);
- }
- getHighestSequenceNumber(t) {
- return Rt.resolve(this.Ns);
- }
- allocateTargetId(t) {
- return this.highestTargetId = this.Ms.next(), Rt.resolve(this.highestTargetId);
- }
- setTargetsMetadata(t, e, n) {
- return n && (this.lastRemoteSnapshotVersion = n), e > this.Ns && (this.Ns = e),
- Rt.resolve();
- }
- Fn(t) {
- this.xs.set(t.target, t);
- const e = t.targetId;
- e > this.highestTargetId && (this.Ms = new lo(e), this.highestTargetId = e), t.sequenceNumber > this.Ns && (this.Ns = t.sequenceNumber);
- }
- addTargetData(t, e) {
- return this.Fn(e), this.targetCount += 1, Rt.resolve();
- }
- updateTargetData(t, e) {
- return this.Fn(e), Rt.resolve();
- }
- removeTargetData(t, e) {
- return this.xs.delete(e.target), this.ks.Is(e.targetId), this.targetCount -= 1,
- Rt.resolve();
- }
- removeTargets(t, e, n) {
- let s = 0;
- const i = [];
- return this.xs.forEach(((r, o) => {
- o.sequenceNumber <= e && null === n.get(o.targetId) && (this.xs.delete(r), i.push(this.removeMatchingKeysForTargetId(t, o.targetId)),
- s++);
- })), Rt.waitFor(i).next((() => s));
- }
- getTargetCount(t) {
- return Rt.resolve(this.targetCount);
- }
- getTargetData(t, e) {
- const n = this.xs.get(e) || null;
- return Rt.resolve(n);
- }
- addMatchingKeys(t, e, n) {
- return this.ks.gs(e, n), Rt.resolve();
- }
- removeMatchingKeys(t, e, n) {
- this.ks.ps(e, n);
- const s = this.persistence.referenceDelegate, i = [];
- return s && e.forEach((e => {
- i.push(s.markPotentiallyOrphaned(t, e));
- })), Rt.waitFor(i);
- }
- removeMatchingKeysForTargetId(t, e) {
- return this.ks.Is(e), Rt.resolve();
- }
- getMatchingKeysForTargetId(t, e) {
- const n = this.ks.Es(e);
- return Rt.resolve(n);
- }
- containsKey(t, e) {
- return Rt.resolve(this.ks.containsKey(e));
- }
- }
- class Ko {
-
- constructor(t, e) {
- this.$s = {}, this.overlays = {}, this.Os = new Ot(0), this.Fs = !1, this.Fs = !0,
- this.referenceDelegate = t(this), this.Bs = new Uo(this);
- this.indexManager = new zr, this.remoteDocumentCache = function(t) {
- return new Lo(t);
- }((t => this.referenceDelegate.Ls(t))), this.serializer = new ar(e), this.qs = new Mo(this.serializer);
- }
- start() {
- return Promise.resolve();
- }
- shutdown() {
-
- return this.Fs = !1, Promise.resolve();
- }
- get started() {
- return this.Fs;
- }
- setDatabaseDeletedListener() {
-
- }
- setNetworkEnabled() {
-
- }
- getIndexManager(t) {
-
-
- return this.indexManager;
- }
- getDocumentOverlayCache(t) {
- let e = this.overlays[t.toKey()];
- return e || (e = new $o, this.overlays[t.toKey()] = e), e;
- }
- getMutationQueue(t, e) {
- let n = this.$s[t.toKey()];
- return n || (n = new Bo(e, this.referenceDelegate), this.$s[t.toKey()] = n), n;
- }
- getTargetCache() {
- return this.Bs;
- }
- getRemoteDocumentCache() {
- return this.remoteDocumentCache;
- }
- getBundleCache() {
- return this.qs;
- }
- runTransaction(t, e, n) {
- N("MemoryPersistence", "Starting transaction:", t);
- const s = new Go(this.Os.next());
- return this.referenceDelegate.Us(), n(s).next((t => this.referenceDelegate.Ks(s).next((() => t)))).toPromise().then((t => (s.raiseOnCommittedEvent(),
- t)));
- }
- Gs(t, e) {
- return Rt.or(Object.values(this.$s).map((n => () => n.containsKey(t, e))));
- }
- }
- class Go extends At {
- constructor(t) {
- super(), this.currentSequenceNumber = t;
- }
- }
- class Qo {
- constructor(t) {
- this.persistence = t,
-
- this.Qs = new Oo,
-
- this.js = null;
- }
- static zs(t) {
- return new Qo(t);
- }
- get Ws() {
- if (this.js) return this.js;
- throw O();
- }
- addReference(t, e, n) {
- return this.Qs.addReference(n, e), this.Ws.delete(n.toString()), Rt.resolve();
- }
- removeReference(t, e, n) {
- return this.Qs.removeReference(n, e), this.Ws.add(n.toString()), Rt.resolve();
- }
- markPotentiallyOrphaned(t, e) {
- return this.Ws.add(e.toString()), Rt.resolve();
- }
- removeTarget(t, e) {
- this.Qs.Is(e.targetId).forEach((t => this.Ws.add(t.toString())));
- const n = this.persistence.getTargetCache();
- return n.getMatchingKeysForTargetId(t, e.targetId).next((t => {
- t.forEach((t => this.Ws.add(t.toString())));
- })).next((() => n.removeTargetData(t, e)));
- }
- Us() {
- this.js = new Set;
- }
- Ks(t) {
-
- const e = this.persistence.getRemoteDocumentCache().newChangeBuffer();
- return Rt.forEach(this.Ws, (n => {
- const s = ht.fromPath(n);
- return this.Hs(t, s).next((t => {
- t || e.removeEntry(s, rt.min());
- }));
- })).next((() => (this.js = null, e.apply(t))));
- }
- updateLimboDocument(t, e) {
- return this.Hs(t, e).next((t => {
- t ? this.Ws.delete(e.toString()) : this.Ws.add(e.toString());
- }));
- }
- Ls(t) {
-
- return 0;
- }
- Hs(t, e) {
- return Rt.or([ () => Rt.resolve(this.Qs.containsKey(e)), () => this.persistence.getTargetCache().containsKey(t, e), () => this.persistence.Gs(t, e) ]);
- }
- }
- class jo {
- constructor(t, e) {
- this.persistence = t, this.Js = new os((t => qt(t.path)), ((t, e) => t.isEqual(e))),
- this.garbageCollector = To(this, e);
- }
- static zs(t, e) {
- return new jo(t, e);
- }
-
-
- Us() {}
- Ks(t) {
- return Rt.resolve();
- }
- forEachTarget(t, e) {
- return this.persistence.getTargetCache().forEachTarget(t, e);
- }
- zn(t) {
- const e = this.Jn(t);
- return this.persistence.getTargetCache().getTargetCount(t).next((t => e.next((e => t + e))));
- }
- Jn(t) {
- let e = 0;
- return this.Wn(t, (t => {
- e++;
- })).next((() => e));
- }
- Wn(t, e) {
- return Rt.forEach(this.Js, ((n, s) => this.Xn(t, n, s).next((t => t ? Rt.resolve() : e(s)))));
- }
- removeTargets(t, e, n) {
- return this.persistence.getTargetCache().removeTargets(t, e, n);
- }
- removeOrphanedDocuments(t, e) {
- let n = 0;
- const s = this.persistence.getRemoteDocumentCache(), i = s.newChangeBuffer();
- return s.Cs(t, (s => this.Xn(t, s, e).next((t => {
- t || (n++, i.removeEntry(s, rt.min()));
- })))).next((() => i.apply(t))).next((() => n));
- }
- markPotentiallyOrphaned(t, e) {
- return this.Js.set(e, t.currentSequenceNumber), Rt.resolve();
- }
- removeTarget(t, e) {
- const n = e.withSequenceNumber(t.currentSequenceNumber);
- return this.persistence.getTargetCache().updateTargetData(t, n);
- }
- addReference(t, e, n) {
- return this.Js.set(n, t.currentSequenceNumber), Rt.resolve();
- }
- removeReference(t, e, n) {
- return this.Js.set(n, t.currentSequenceNumber), Rt.resolve();
- }
- updateLimboDocument(t, e) {
- return this.Js.set(e, t.currentSequenceNumber), Rt.resolve();
- }
- Ls(t) {
- let e = t.key.toString().length;
- return t.isFoundDocument() && (e += ze(t.data.value)), e;
- }
- Xn(t, e, n) {
- return Rt.or([ () => this.persistence.Gs(t, e), () => this.persistence.getTargetCache().containsKey(t, e), () => {
- const t = this.Js.get(e);
- return Rt.resolve(void 0 !== t && t > n);
- } ]);
- }
- getCacheSize(t) {
- return this.persistence.getRemoteDocumentCache().getSize(t);
- }
- }
- class zo {
- constructor(t) {
- this.serializer = t;
- }
-
- O(t, e, n, s) {
- const i = new Pt("createOrUpgrade", e);
- n < 1 && s >= 1 && (function(t) {
- t.createObjectStore("owner");
- }(t), function(t) {
- t.createObjectStore("mutationQueues", {
- keyPath: "userId"
- });
- t.createObjectStore("mutations", {
- keyPath: "batchId",
- autoIncrement: !0
- }).createIndex("userMutationsIndex", Qt, {
- unique: !0
- }), t.createObjectStore("documentMutations");
- }
-
- (t), Wo(t), function(t) {
- t.createObjectStore("remoteDocuments");
- }(t));
-
-
- let r = Rt.resolve();
- return n < 3 && s >= 3 && (
-
-
- 0 !== n && (!function(t) {
- t.deleteObjectStore("targetDocuments"), t.deleteObjectStore("targets"), t.deleteObjectStore("targetGlobal");
- }(t), Wo(t)), r = r.next((() =>
-
- function(t) {
- const e = t.store("targetGlobal"), n = {
- highestTargetId: 0,
- highestListenSequenceNumber: 0,
- lastRemoteSnapshotVersion: rt.min().toTimestamp(),
- targetCount: 0
- };
- return e.put("targetGlobalKey", n);
- }(i)))), n < 4 && s >= 4 && (0 !== n && (
-
-
-
-
-
-
- r = r.next((() => function(t, e) {
- return e.store("mutations").j().next((n => {
- t.deleteObjectStore("mutations");
- t.createObjectStore("mutations", {
- keyPath: "batchId",
- autoIncrement: !0
- }).createIndex("userMutationsIndex", Qt, {
- unique: !0
- });
- const s = e.store("mutations"), i = n.map((t => s.put(t)));
- return Rt.waitFor(i);
- }));
- }(t, i)))), r = r.next((() => {
- !function(t) {
- t.createObjectStore("clientMetadata", {
- keyPath: "clientId"
- });
- }(t);
- }))), n < 5 && s >= 5 && (r = r.next((() => this.Ys(i)))), n < 6 && s >= 6 && (r = r.next((() => (function(t) {
- t.createObjectStore("remoteDocumentGlobal");
- }(t), this.Xs(i))))), n < 7 && s >= 7 && (r = r.next((() => this.Zs(i)))), n < 8 && s >= 8 && (r = r.next((() => this.ti(t, i)))),
- n < 9 && s >= 9 && (r = r.next((() => {
-
-
-
- !function(t) {
- t.objectStoreNames.contains("remoteDocumentChanges") && t.deleteObjectStore("remoteDocumentChanges");
- }(t);
-
-
- }))), n < 10 && s >= 10 && (r = r.next((() => this.ei(i)))), n < 11 && s >= 11 && (r = r.next((() => {
- !function(t) {
- t.createObjectStore("bundles", {
- keyPath: "bundleId"
- });
- }(t), function(t) {
- t.createObjectStore("namedQueries", {
- keyPath: "name"
- });
- }(t);
- }))), n < 12 && s >= 12 && (r = r.next((() => {
- !function(t) {
- const e = t.createObjectStore("documentOverlays", {
- keyPath: oe
- });
- e.createIndex("collectionPathOverlayIndex", ue, {
- unique: !1
- }), e.createIndex("collectionGroupOverlayIndex", ce, {
- unique: !1
- });
- }(t);
- }))), n < 13 && s >= 13 && (r = r.next((() => function(t) {
- const e = t.createObjectStore("remoteDocumentsV14", {
- keyPath: Ht
- });
- e.createIndex("documentKeyIndex", Jt), e.createIndex("collectionGroupIndex", Yt);
- }(t))).next((() => this.ni(t, i))).next((() => t.deleteObjectStore("remoteDocuments")))),
- n < 14 && s >= 14 && (r = r.next((() => this.si(t, i)))), n < 15 && s >= 15 && (r = r.next((() => function(t) {
- t.createObjectStore("indexConfiguration", {
- keyPath: "indexId",
- autoIncrement: !0
- }).createIndex("collectionGroupIndex", "collectionGroup", {
- unique: !1
- });
- t.createObjectStore("indexState", {
- keyPath: ne
- }).createIndex("sequenceNumberIndex", se, {
- unique: !1
- });
- t.createObjectStore("indexEntries", {
- keyPath: ie
- }).createIndex("documentKeyIndex", re, {
- unique: !1
- });
- }(t)))), r;
- }
- Xs(t) {
- let e = 0;
- return t.store("remoteDocuments").X(((t, n) => {
- e += ro(n);
- })).next((() => {
- const n = {
- byteSize: e
- };
- return t.store("remoteDocumentGlobal").put("remoteDocumentGlobalKey", n);
- }));
- }
- Ys(t) {
- const e = t.store("mutationQueues"), n = t.store("mutations");
- return e.j().next((e => Rt.forEach(e, (e => {
- const s = IDBKeyRange.bound([ e.userId, -1 ], [ e.userId, e.lastAcknowledgedBatchId ]);
- return n.j("userMutationsIndex", s).next((n => Rt.forEach(n, (n => {
- F(n.userId === e.userId);
- const s = _r(this.serializer, n);
- return io(t, e.userId, s).next((() => {}));
- }))));
- }))));
- }
-
- Zs(t) {
- const e = t.store("targetDocuments"), n = t.store("remoteDocuments");
- return t.store("targetGlobal").get("targetGlobalKey").next((t => {
- const s = [];
- return n.X(((n, i) => {
- const r = new ut(n), o = function(t) {
- return [ 0, qt(t) ];
- }(r);
- s.push(e.get(o).next((n => n ? Rt.resolve() : (n => e.put({
- targetId: 0,
- path: qt(n),
- sequenceNumber: t.highestListenSequenceNumber
- }))(r))));
- })).next((() => Rt.waitFor(s)));
- }));
- }
- ti(t, e) {
-
- t.createObjectStore("collectionParents", {
- keyPath: ee
- });
- const n = e.store("collectionParents"), s = new Wr, i = t => {
- if (s.add(t)) {
- const e = t.lastSegment(), s = t.popLast();
- return n.put({
- collectionId: e,
- parent: qt(s)
- });
- }
- };
-
-
- return e.store("remoteDocuments").X({
- Y: !0
- }, ((t, e) => {
- const n = new ut(t);
- return i(n.popLast());
- })).next((() => e.store("documentMutations").X({
- Y: !0
- }, (([t, e, n], s) => {
- const r = Gt(e);
- return i(r.popLast());
- }))));
- }
- ei(t) {
- const e = t.store("targets");
- return e.X(((t, n) => {
- const s = mr(n), i = gr(this.serializer, s);
- return e.put(i);
- }));
- }
- ni(t, e) {
- const n = e.store("remoteDocuments"), s = [];
- return n.X(((t, n) => {
- const i = e.store("remoteDocumentsV14"), r = (o = n, o.document ? new ht(ut.fromString(o.document.name).popFirst(5)) : o.noDocument ? ht.fromSegments(o.noDocument.path) : o.unknownDocument ? ht.fromSegments(o.unknownDocument.path) : O()).path.toArray();
- var o;
-
- const u = {
- prefixPath: r.slice(0, r.length - 2),
- collectionGroup: r[r.length - 2],
- documentId: r[r.length - 1],
- readTime: n.readTime || [ 0, 0 ],
- unknownDocument: n.unknownDocument,
- noDocument: n.noDocument,
- document: n.document,
- hasCommittedMutations: !!n.hasCommittedMutations
- };
- s.push(i.put(u));
- })).next((() => Rt.waitFor(s)));
- }
- si(t, e) {
- const n = e.store("mutations"), s = Po(this.serializer), i = new Ko(Qo.zs, this.serializer.fe);
- return n.j().next((t => {
- const n = new Map;
- return t.forEach((t => {
- var e;
- let s = null !== (e = n.get(t.userId)) && void 0 !== e ? e : gs();
- _r(this.serializer, t).keys().forEach((t => s = s.add(t))), n.set(t.userId, s);
- })), Rt.forEach(n, ((t, n) => {
- const r = new V(n), o = Rr.de(this.serializer, r), u = i.getIndexManager(r), c = oo.de(r, this.serializer, u, i.referenceDelegate);
- return new ko(s, c, o, u).recalculateAndSaveOverlaysForDocumentKeys(new we(e, Ot.ct), t).next();
- }));
- }));
- }
- }
- function Wo(t) {
- t.createObjectStore("targetDocuments", {
- keyPath: Zt
- }).createIndex("documentTargetsIndex", te, {
- unique: !0
- });
-
- t.createObjectStore("targets", {
- keyPath: "targetId"
- }).createIndex("queryTargetsIndex", Xt, {
- unique: !0
- }), t.createObjectStore("targetGlobal");
- }
- const Ho = "Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using `experimentalForceOwningTab:true`, make sure that only one tab has persistence enabled at any given time.";
- class Jo {
- constructor(
- /**
- * Whether to synchronize the in-memory state of multiple tabs and share
- * access to local persistence.
- */
- t, e, n, s, i, r, o, u, c,
- /**
- * If set to true, forcefully obtains database access. Existing tabs will
- * no longer be able to access IndexedDB.
- */
- a, h = 15) {
- if (this.allowTabSynchronization = t, this.persistenceKey = e, this.clientId = n,
- this.ii = i, this.window = r, this.document = o, this.ri = c, this.oi = a, this.ui = h,
- this.Os = null, this.Fs = !1, this.isPrimary = !1, this.networkEnabled = !0,
-
- this.ci = null, this.inForeground = !1,
-
- this.ai = null,
-
- this.hi = null,
-
- this.li = Number.NEGATIVE_INFINITY,
-
- this.fi = t => Promise.resolve(), !Jo.D()) throw new U(q.UNIMPLEMENTED, "This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");
- this.referenceDelegate = new Eo(this, s), this.di = e + "main", this.serializer = new ar(u),
- this.wi = new bt(this.di, this.ui, new zo(this.serializer)), this.Bs = new fo(this.referenceDelegate, this.serializer),
- this.remoteDocumentCache = Po(this.serializer), this.qs = new Er, this.window && this.window.localStorage ? this._i = this.window.localStorage : (this._i = null,
- !1 === a && k("IndexedDbPersistence", "LocalStorage is unavailable. As a result, persistence may not work reliably. In particular enablePersistence() could fail immediately after refreshing the page."));
- }
-
- start() {
-
-
-
- return this.mi().then((() => {
- if (!this.isPrimary && !this.allowTabSynchronization)
-
-
- throw new U(q.FAILED_PRECONDITION, Ho);
- return this.gi(), this.yi(), this.pi(), this.runTransaction("getHighestListenSequenceNumber", "readonly", (t => this.Bs.getHighestSequenceNumber(t)));
- })).then((t => {
- this.Os = new Ot(t, this.ri);
- })).then((() => {
- this.Fs = !0;
- })).catch((t => (this.wi && this.wi.close(), Promise.reject(t))));
- }
-
- Ii(t) {
- return this.fi = async e => {
- if (this.started) return t(e);
- }, t(this.isPrimary);
- }
-
- setDatabaseDeletedListener(t) {
- this.wi.B((async e => {
-
- null === e.newVersion && await t();
- }));
- }
-
- setNetworkEnabled(t) {
- this.networkEnabled !== t && (this.networkEnabled = t,
-
-
- this.ii.enqueueAndForget((async () => {
- this.started && await this.mi();
- })));
- }
-
- mi() {
- return this.runTransaction("updateClientMetadataAndTryBecomePrimary", "readwrite", (t => Xo(t).put({
- clientId: this.clientId,
- updateTimeMs: Date.now(),
- networkEnabled: this.networkEnabled,
- inForeground: this.inForeground
- }).next((() => {
- if (this.isPrimary) return this.Ti(t).next((t => {
- t || (this.isPrimary = !1, this.ii.enqueueRetryable((() => this.fi(!1))));
- }));
- })).next((() => this.Ei(t))).next((e => this.isPrimary && !e ? this.Ai(t).next((() => !1)) : !!e && this.vi(t).next((() => !0)))))).catch((t => {
- if (Dt(t))
-
-
- return N("IndexedDbPersistence", "Failed to extend owner lease: ", t), this.isPrimary;
- if (!this.allowTabSynchronization) throw t;
- return N("IndexedDbPersistence", "Releasing owner lease after error during lease refresh", t),
- !1;
- })).then((t => {
- this.isPrimary !== t && this.ii.enqueueRetryable((() => this.fi(t))), this.isPrimary = t;
- }));
- }
- Ti(t) {
- return Yo(t).get("owner").next((t => Rt.resolve(this.Ri(t))));
- }
- Pi(t) {
- return Xo(t).delete(this.clientId);
- }
-
- async bi() {
- if (this.isPrimary && !this.Vi(this.li, 18e5)) {
- this.li = Date.now();
- const t = await this.runTransaction("maybeGarbageCollectMultiClientState", "readwrite-primary", (t => {
- const e = _e(t, "clientMetadata");
- return e.j().next((t => {
- const n = this.Si(t, 18e5), s = t.filter((t => -1 === n.indexOf(t)));
-
- return Rt.forEach(s, (t => e.delete(t.clientId))).next((() => s));
- }));
- })).catch((() => []));
-
-
-
-
-
- if (this._i) for (const e of t) this._i.removeItem(this.Di(e.clientId));
- }
- }
-
- pi() {
- this.hi = this.ii.enqueueAfterDelay("client_metadata_refresh" , 4e3, (() => this.mi().then((() => this.bi())).then((() => this.pi()))));
- }
- Ri(t) {
- return !!t && t.ownerId === this.clientId;
- }
-
- Ei(t) {
- if (this.oi) return Rt.resolve(!0);
- return Yo(t).get("owner").next((e => {
-
-
-
-
-
-
-
-
-
- if (null !== e && this.Vi(e.leaseTimestampMs, 5e3) && !this.Ci(e.ownerId)) {
- if (this.Ri(e) && this.networkEnabled) return !0;
- if (!this.Ri(e)) {
- if (!e.allowTabSynchronization)
-
-
-
-
-
-
-
-
-
-
-
- throw new U(q.FAILED_PRECONDITION, Ho);
- return !1;
- }
- }
- return !(!this.networkEnabled || !this.inForeground) || Xo(t).j().next((t => void 0 === this.Si(t, 5e3).find((t => {
- if (this.clientId !== t.clientId) {
- const e = !this.networkEnabled && t.networkEnabled, n = !this.inForeground && t.inForeground, s = this.networkEnabled === t.networkEnabled;
- if (e || n && s) return !0;
- }
- return !1;
- }))));
- })).next((t => (this.isPrimary !== t && N("IndexedDbPersistence", `Client ${t ? "is" : "is not"} eligible for a primary lease.`),
- t)));
- }
- async shutdown() {
-
-
- this.Fs = !1, this.xi(), this.hi && (this.hi.cancel(), this.hi = null), this.Ni(),
- this.ki(),
-
-
- await this.wi.runTransaction("shutdown", "readwrite", [ "owner", "clientMetadata" ], (t => {
- const e = new we(t, Ot.ct);
- return this.Ai(e).next((() => this.Pi(e)));
- })), this.wi.close(),
-
-
- this.Mi();
- }
-
- Si(t, e) {
- return t.filter((t => this.Vi(t.updateTimeMs, e) && !this.Ci(t.clientId)));
- }
-
- $i() {
- return this.runTransaction("getActiveClients", "readonly", (t => Xo(t).j().next((t => this.Si(t, 18e5).map((t => t.clientId))))));
- }
- get started() {
- return this.Fs;
- }
- getMutationQueue(t, e) {
- return oo.de(t, this.serializer, e, this.referenceDelegate);
- }
- getTargetCache() {
- return this.Bs;
- }
- getRemoteDocumentCache() {
- return this.remoteDocumentCache;
- }
- getIndexManager(t) {
- return new Jr(t, this.serializer.fe.databaseId);
- }
- getDocumentOverlayCache(t) {
- return Rr.de(this.serializer, t);
- }
- getBundleCache() {
- return this.qs;
- }
- runTransaction(t, e, n) {
- N("IndexedDbPersistence", "Starting transaction:", t);
- const s = "readonly" === e ? "readonly" : "readwrite", i = 15 === (r = this.ui) ? de : 14 === r ? fe : 13 === r ? le : 12 === r ? he : 11 === r ? ae : void O();
-
- var r;
- let o;
-
-
- return this.wi.runTransaction(t, s, i, (s => (o = new we(s, this.Os ? this.Os.next() : Ot.ct),
- "readwrite-primary" === e ? this.Ti(o).next((t => !!t || this.Ei(o))).next((e => {
- if (!e) throw k(`Failed to obtain primary lease for action '${t}'.`), this.isPrimary = !1,
- this.ii.enqueueRetryable((() => this.fi(!1))), new U(q.FAILED_PRECONDITION, Et);
- return n(o);
- })).next((t => this.vi(o).next((() => t)))) : this.Oi(o).next((() => n(o)))))).then((t => (o.raiseOnCommittedEvent(),
- t)));
- }
-
-
-
- Oi(t) {
- return Yo(t).get("owner").next((t => {
- if (null !== t && this.Vi(t.leaseTimestampMs, 5e3) && !this.Ci(t.ownerId) && !this.Ri(t) && !(this.oi || this.allowTabSynchronization && t.allowTabSynchronization)) throw new U(q.FAILED_PRECONDITION, Ho);
- }));
- }
-
- vi(t) {
- const e = {
- ownerId: this.clientId,
- allowTabSynchronization: this.allowTabSynchronization,
- leaseTimestampMs: Date.now()
- };
- return Yo(t).put("owner", e);
- }
- static D() {
- return bt.D();
- }
- Ai(t) {
- const e = Yo(t);
- return e.get("owner").next((t => this.Ri(t) ? (N("IndexedDbPersistence", "Releasing primary lease."),
- e.delete("owner")) : Rt.resolve()));
- }
- Vi(t, e) {
- const n = Date.now();
- return !(t < n - e) && (!(t > n) || (k(`Detected an update time that is in the future: ${t} > ${n}`),
- !1));
- }
- gi() {
- null !== this.document && "function" == typeof this.document.addEventListener && (this.ai = () => {
- this.ii.enqueueAndForget((() => (this.inForeground = "visible" === this.document.visibilityState,
- this.mi())));
- }, this.document.addEventListener("visibilitychange", this.ai), this.inForeground = "visible" === this.document.visibilityState);
- }
- Ni() {
- this.ai && (this.document.removeEventListener("visibilitychange", this.ai), this.ai = null);
- }
-
- yi() {
- var t;
- "function" == typeof (null === (t = this.window) || void 0 === t ? void 0 : t.addEventListener) && (this.ci = () => {
-
-
-
- this.xi();
- const t = /(?:Version|Mobile)\/1[456]/;
- isSafari() && (navigator.appVersion.match(t) || navigator.userAgent.match(t)) &&
-
-
-
-
- this.ii.enterRestrictedMode( !0), this.ii.enqueueAndForget((() => this.shutdown()));
- }, this.window.addEventListener("pagehide", this.ci));
- }
- ki() {
- this.ci && (this.window.removeEventListener("pagehide", this.ci), this.ci = null);
- }
-
- Ci(t) {
- var e;
- try {
- const n = null !== (null === (e = this._i) || void 0 === e ? void 0 : e.getItem(this.Di(t)));
- return N("IndexedDbPersistence", `Client '${t}' ${n ? "is" : "is not"} zombied in LocalStorage`),
- n;
- } catch (t) {
-
- return k("IndexedDbPersistence", "Failed to get zombied client id.", t), !1;
- }
- }
-
- xi() {
- if (this._i) try {
- this._i.setItem(this.Di(this.clientId), String(Date.now()));
- } catch (t) {
-
- k("Failed to set zombie client id.", t);
- }
- }
- Mi() {
- if (this._i) try {
- this._i.removeItem(this.Di(this.clientId));
- } catch (t) {
-
- }
- }
- Di(t) {
- return `firestore_zombie_${this.persistenceKey}_${t}`;
- }
- }
- function Yo(t) {
- return _e(t, "owner");
- }
- function Xo(t) {
- return _e(t, "clientMetadata");
- }
- function Zo(t, e) {
-
-
-
-
-
- let n = t.projectId;
- return t.isDefaultDatabase || (n += "." + t.database), "firestore/" + e + "/" + n + "/";
- }
- class tu {
- constructor(t, e, n, s) {
- this.targetId = t, this.fromCache = e, this.Fi = n, this.Bi = s;
- }
- static Li(t, e) {
- let n = gs(), s = gs();
- for (const t of e.docChanges) switch (t.type) {
- case 0 :
- n = n.add(t.doc.key);
- break;
- case 1 :
- s = s.add(t.doc.key);
-
- }
- return new tu(t, e.fromCache, n, s);
- }
- }
- class eu {
- constructor() {
- this.qi = !1;
- }
- initialize(t, e) {
- this.Ui = t, this.indexManager = e, this.qi = !0;
- }
- getDocumentsMatchingQuery(t, e, n, s) {
- return this.Ki(t, e).next((i => i || this.Gi(t, e, s, n))).next((n => n || this.Qi(t, e)));
- }
-
- Ki(t, e) {
- if (Qn(e))
-
-
-
- return Rt.resolve(null);
- let n = Jn(e);
- return this.indexManager.getIndexType(t, n).next((s => 0 === s ? null : (null !== e.limit && 1 === s && (
-
-
-
-
-
-
-
- e = Xn(e, null, "F" ), n = Jn(e)), this.indexManager.getDocumentsMatchingTarget(t, n).next((s => {
- const i = gs(...s);
- return this.Ui.getDocuments(t, i).next((s => this.indexManager.getMinOffset(t, n).next((n => {
- const r = this.ji(e, s);
- return this.zi(e, r, i, n.readTime) ? this.Ki(t, Xn(e, null, "F" )) : this.Wi(t, r, e, n);
- }))));
- })))));
- }
-
- Gi(t, e, n, s) {
- return Qn(e) || s.isEqual(rt.min()) ? this.Qi(t, e) : this.Ui.getDocuments(t, n).next((i => {
- const r = this.ji(e, i);
- return this.zi(e, r, n, s) ? this.Qi(t, e) : (C() <= LogLevel.DEBUG && N("QueryEngine", "Re-using previous result from %s to execute query: %s", s.toString(), es(e)),
- this.Wi(t, r, e, yt(s, -1)));
- }));
-
-
- }
- ji(t, e) {
-
-
- let n = new Ee(is(t));
- return e.forEach(((e, s) => {
- ns(t, s) && (n = n.add(s));
- })), n;
- }
-
- zi(t, e, n, s) {
- if (null === t.limit)
-
- return !1;
- if (n.size !== e.size)
-
-
- return !0;
-
-
-
-
-
-
-
-
- const i = "F" === t.limitType ? e.last() : e.first();
- return !!i && (i.hasPendingWrites || i.version.compareTo(s) > 0);
- }
- Qi(t, e) {
- return C() <= LogLevel.DEBUG && N("QueryEngine", "Using full collection scan to execute query:", es(e)),
- this.Ui.getDocumentsMatchingQuery(t, e, It.min());
- }
-
- Wi(t, e, n, s) {
-
- return this.Ui.getDocumentsMatchingQuery(t, n, s).next((t => (
-
- e.forEach((e => {
- t = t.insert(e.key, e);
- })), t)));
- }
- }
- class nu {
- constructor(
- /** Manages our in-memory or durable persistence. */
- t, e, n, s) {
- this.persistence = t, this.Hi = e, this.serializer = s,
-
- this.Ji = new pe(et),
-
-
- this.Yi = new os((t => $n(t)), On),
-
- this.Xi = new Map, this.Zi = t.getRemoteDocumentCache(), this.Bs = t.getTargetCache(),
- this.qs = t.getBundleCache(), this.tr(n);
- }
- tr(t) {
-
-
- this.documentOverlayCache = this.persistence.getDocumentOverlayCache(t), this.indexManager = this.persistence.getIndexManager(t),
- this.mutationQueue = this.persistence.getMutationQueue(t, this.indexManager), this.localDocuments = new ko(this.Zi, this.mutationQueue, this.documentOverlayCache, this.indexManager),
- this.Zi.setIndexManager(this.indexManager), this.Hi.initialize(this.localDocuments, this.indexManager);
- }
- collectGarbage(t) {
- return this.persistence.runTransaction("Collect garbage", "readwrite-primary", (e => t.collect(e, this.Ji)));
- }
- }
- function su(
- t, e, n, s) {
- return new nu(t, e, n, s);
- }
- async function iu(t, e) {
- const n = L(t);
- return await n.persistence.runTransaction("Handle user change", "readonly", (t => {
-
-
- let s;
- return n.mutationQueue.getAllMutationBatches(t).next((i => (s = i, n.tr(e), n.mutationQueue.getAllMutationBatches(t)))).next((e => {
- const i = [], r = [];
-
- let o = gs();
- for (const t of s) {
- i.push(t.batchId);
- for (const e of t.mutations) o = o.add(e.key);
- }
- for (const t of e) {
- r.push(t.batchId);
- for (const e of t.mutations) o = o.add(e.key);
- }
-
-
- return n.localDocuments.getDocuments(t, o).next((t => ({
- er: t,
- removedBatchIds: i,
- addedBatchIds: r
- })));
- }));
- }));
- }
- function ru(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Acknowledge batch", "readwrite-primary", (t => {
- const s = e.batch.keys(), i = n.Zi.newChangeBuffer({
- trackRemovals: !0
- });
- return function(t, e, n, s) {
- const i = n.batch, r = i.keys();
- let o = Rt.resolve();
- return r.forEach((t => {
- o = o.next((() => s.getEntry(e, t))).next((e => {
- const r = n.docVersions.get(t);
- F(null !== r), e.version.compareTo(r) < 0 && (i.applyToRemoteDocument(e, n), e.isValidDocument() && (
-
-
-
- e.setReadTime(n.commitVersion), s.addEntry(e)));
- }));
- })), o.next((() => t.mutationQueue.removeMutationBatch(e, i)));
- }
-
-
- (n, t, e, i).next((() => i.apply(t))).next((() => n.mutationQueue.performConsistencyCheck(t))).next((() => n.documentOverlayCache.removeOverlaysForBatchId(t, s, e.batch.batchId))).next((() => n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t, function(t) {
- let e = gs();
- for (let n = 0; n < t.mutationResults.length; ++n) {
- t.mutationResults[n].transformResults.length > 0 && (e = e.add(t.batch.mutations[n].key));
- }
- return e;
- }
-
- (e)))).next((() => n.localDocuments.getDocuments(t, s)));
- }));
- }
- function ou(t) {
- const e = L(t);
- return e.persistence.runTransaction("Get last remote snapshot version", "readonly", (t => e.Bs.getLastRemoteSnapshotVersion(t)));
- }
- function uu(t, e) {
- const n = L(t), s = e.snapshotVersion;
- let i = n.Ji;
- return n.persistence.runTransaction("Apply remote event", "readwrite-primary", (t => {
- const r = n.Zi.newChangeBuffer({
- trackRemovals: !0
- });
-
- i = n.Ji;
- const o = [];
- e.targetChanges.forEach(((r, u) => {
- const c = i.get(u);
- if (!c) return;
-
-
-
- o.push(n.Bs.removeMatchingKeys(t, r.removedDocuments, u).next((() => n.Bs.addMatchingKeys(t, r.addedDocuments, u))));
- let a = c.withSequenceNumber(t.currentSequenceNumber);
- null !== e.targetMismatches.get(u) ? a = a.withResumeToken(Ve.EMPTY_BYTE_STRING, rt.min()).withLastLimboFreeSnapshotVersion(rt.min()) : r.resumeToken.approximateByteSize() > 0 && (a = a.withResumeToken(r.resumeToken, s)),
- i = i.insert(u, a),
-
-
-
- function(t, e, n) {
-
- if (0 === t.resumeToken.approximateByteSize()) return !0;
-
-
-
-
-
- if (e.snapshotVersion.toMicroseconds() - t.snapshotVersion.toMicroseconds() >= 3e8) return !0;
-
-
-
-
-
- return n.addedDocuments.size + n.modifiedDocuments.size + n.removedDocuments.size > 0;
- }
-
- (c, a, r) && o.push(n.Bs.updateTargetData(t, a));
- }));
- let u = cs(), c = gs();
-
-
-
-
- if (e.documentUpdates.forEach((s => {
- e.resolvedLimboDocuments.has(s) && o.push(n.persistence.referenceDelegate.updateLimboDocument(t, s));
- })),
-
-
- o.push(cu(t, r, e.documentUpdates).next((t => {
- u = t.nr, c = t.sr;
- }))), !s.isEqual(rt.min())) {
- const e = n.Bs.getLastRemoteSnapshotVersion(t).next((e => n.Bs.setTargetsMetadata(t, t.currentSequenceNumber, s)));
- o.push(e);
- }
- return Rt.waitFor(o).next((() => r.apply(t))).next((() => n.localDocuments.getLocalViewOfDocuments(t, u, c))).next((() => u));
- })).then((t => (n.Ji = i, t)));
- }
- function cu(t, e, n) {
- let s = gs(), i = gs();
- return n.forEach((t => s = s.add(t))), e.getEntries(t, s).next((t => {
- let s = cs();
- return n.forEach(((n, r) => {
- const o = t.get(n);
-
- r.isFoundDocument() !== o.isFoundDocument() && (i = i.add(n)),
-
-
-
-
- r.isNoDocument() && r.version.isEqual(rt.min()) ? (
-
-
-
- e.removeEntry(n, r.readTime), s = s.insert(n, r)) : !o.isValidDocument() || r.version.compareTo(o.version) > 0 || 0 === r.version.compareTo(o.version) && o.hasPendingWrites ? (e.addEntry(r),
- s = s.insert(n, r)) : N("LocalStore", "Ignoring outdated watch update for ", n, ". Current version:", o.version, " Watch version:", r.version);
- })), {
- nr: s,
- sr: i
- };
- }));
- }
- function au(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Get next mutation batch", "readonly", (t => (void 0 === e && (e = -1),
- n.mutationQueue.getNextMutationBatchAfterBatchId(t, e))));
- }
- function hu(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Allocate target", "readwrite", (t => {
- let s;
- return n.Bs.getTargetData(t, e).next((i => i ? (
-
-
-
- s = i, Rt.resolve(s)) : n.Bs.allocateTargetId(t).next((i => (s = new cr(e, i, "TargetPurposeListen" , t.currentSequenceNumber),
- n.Bs.addTargetData(t, s).next((() => s)))))));
- })).then((t => {
-
-
- const s = n.Ji.get(t.targetId);
- return (null === s || t.snapshotVersion.compareTo(s.snapshotVersion) > 0) && (n.Ji = n.Ji.insert(t.targetId, t),
- n.Yi.set(e, t.targetId)), t;
- }));
- }
- async function lu(t, e, n) {
- const s = L(t), i = s.Ji.get(e), r = n ? "readwrite" : "readwrite-primary";
- try {
- n || await s.persistence.runTransaction("Release target", r, (t => s.persistence.referenceDelegate.removeTarget(t, i)));
- } catch (t) {
- if (!Dt(t)) throw t;
-
-
-
-
-
- N("LocalStore", `Failed to update sequence numbers for target ${e}: ${t}`);
- }
- s.Ji = s.Ji.remove(e), s.Yi.delete(i.target);
- }
- function fu(t, e, n) {
- const s = L(t);
- let i = rt.min(), r = gs();
- return s.persistence.runTransaction("Execute query", "readonly", (t => function(t, e, n) {
- const s = L(t), i = s.Yi.get(n);
- return void 0 !== i ? Rt.resolve(s.Ji.get(i)) : s.Bs.getTargetData(e, n);
- }(s, t, Jn(e)).next((e => {
- if (e) return i = e.lastLimboFreeSnapshotVersion, s.Bs.getMatchingKeysForTargetId(t, e.targetId).next((t => {
- r = t;
- }));
- })).next((() => s.Hi.getDocumentsMatchingQuery(t, e, n ? i : rt.min(), n ? r : gs()))).next((t => (_u(s, ss(e), t),
- {
- documents: t,
- ir: r
- })))));
- }
- function du(t, e) {
- const n = L(t), s = L(n.Bs), i = n.Ji.get(e);
- return i ? Promise.resolve(i.target) : n.persistence.runTransaction("Get target data", "readonly", (t => s.le(t, e).next((t => t ? t.target : null))));
- }
- function wu(t, e) {
- const n = L(t), s = n.Xi.get(e) || rt.min();
-
-
-
-
- return n.persistence.runTransaction("Get new document changes", "readonly", (t => n.Zi.getAllFromCollectionGroup(t, e, yt(s, -1),
- Number.MAX_SAFE_INTEGER))).then((t => (_u(n, e, t), t)));
- }
- function _u(t, e, n) {
- let s = t.Xi.get(e) || rt.min();
- n.forEach(((t, e) => {
- e.readTime.compareTo(s) > 0 && (s = e.readTime);
- })), t.Xi.set(e, s);
- }
- async function mu(t, e, n, s) {
- const i = L(t);
- let r = gs(), o = cs();
- for (const t of n) {
- const n = e.rr(t.metadata.name);
- t.document && (r = r.add(n));
- const s = e.ur(t);
- s.setReadTime(e.cr(t.metadata.readTime)), o = o.insert(n, s);
- }
- const u = i.Zi.newChangeBuffer({
- trackRemovals: !0
- }), c = await hu(i, function(t) {
-
-
- return Jn(Gn(ut.fromString(`__bundle__/docs/${t}`)));
- }(s));
-
-
- return i.persistence.runTransaction("Apply bundle documents", "readwrite", (t => cu(t, u, o).next((e => (u.apply(t),
- e))).next((e => i.Bs.removeMatchingKeysForTargetId(t, c.targetId).next((() => i.Bs.addMatchingKeys(t, r, c.targetId))).next((() => i.localDocuments.getLocalViewOfDocuments(t, e.nr, e.sr))).next((() => e.nr))))));
- }
- async function gu(t, e, n = gs()) {
-
-
-
-
-
- const s = await hu(t, Jn(yr(e.bundledQuery))), i = L(t);
- return i.persistence.runTransaction("Save named query", "readwrite", (t => {
- const r = Ni(e.readTime);
-
-
- if (s.snapshotVersion.compareTo(r) >= 0) return i.qs.saveNamedQuery(t, e);
-
- const o = s.withResumeToken(Ve.EMPTY_BYTE_STRING, r);
- return i.Ji = i.Ji.insert(o.targetId, o), i.Bs.updateTargetData(t, o).next((() => i.Bs.removeMatchingKeysForTargetId(t, s.targetId))).next((() => i.Bs.addMatchingKeys(t, n, s.targetId))).next((() => i.qs.saveNamedQuery(t, e)));
- }));
- }
- function yu(t, e) {
- return `firestore_clients_${t}_${e}`;
- }
- function pu(t, e, n) {
- let s = `firestore_mutations_${t}_${n}`;
- return e.isAuthenticated() && (s += `_${e.uid}`), s;
- }
- function Iu(t, e) {
- return `firestore_targets_${t}_${e}`;
- }
- class Tu {
- constructor(t, e, n, s) {
- this.user = t, this.batchId = e, this.state = n, this.error = s;
- }
-
- static ar(t, e, n) {
- const s = JSON.parse(n);
- let i, r = "object" == typeof s && -1 !== [ "pending", "acknowledged", "rejected" ].indexOf(s.state) && (void 0 === s.error || "object" == typeof s.error);
- return r && s.error && (r = "string" == typeof s.error.message && "string" == typeof s.error.code,
- r && (i = new U(s.error.code, s.error.message))), r ? new Tu(t, e, s.state, i) : (k("SharedClientState", `Failed to parse mutation state for ID '${e}': ${n}`),
- null);
- }
- hr() {
- const t = {
- state: this.state,
- updateTimeMs: Date.now()
- };
- return this.error && (t.error = {
- code: this.error.code,
- message: this.error.message
- }), JSON.stringify(t);
- }
- }
- class Eu {
- constructor(t, e, n) {
- this.targetId = t, this.state = e, this.error = n;
- }
-
- static ar(t, e) {
- const n = JSON.parse(e);
- let s, i = "object" == typeof n && -1 !== [ "not-current", "current", "rejected" ].indexOf(n.state) && (void 0 === n.error || "object" == typeof n.error);
- return i && n.error && (i = "string" == typeof n.error.message && "string" == typeof n.error.code,
- i && (s = new U(n.error.code, n.error.message))), i ? new Eu(t, n.state, s) : (k("SharedClientState", `Failed to parse target state for ID '${t}': ${e}`),
- null);
- }
- hr() {
- const t = {
- state: this.state,
- updateTimeMs: Date.now()
- };
- return this.error && (t.error = {
- code: this.error.code,
- message: this.error.message
- }), JSON.stringify(t);
- }
- }
- class Au {
- constructor(t, e) {
- this.clientId = t, this.activeTargetIds = e;
- }
-
- static ar(t, e) {
- const n = JSON.parse(e);
- let s = "object" == typeof n && n.activeTargetIds instanceof Array, i = ps();
- for (let t = 0; s && t < n.activeTargetIds.length; ++t) s = Lt(n.activeTargetIds[t]),
- i = i.add(n.activeTargetIds[t]);
- return s ? new Au(t, i) : (k("SharedClientState", `Failed to parse client data for instance '${t}': ${e}`),
- null);
- }
- }
- class vu {
- constructor(t, e) {
- this.clientId = t, this.onlineState = e;
- }
-
- static ar(t) {
- const e = JSON.parse(t);
- return "object" == typeof e && -1 !== [ "Unknown", "Online", "Offline" ].indexOf(e.onlineState) && "string" == typeof e.clientId ? new vu(e.clientId, e.onlineState) : (k("SharedClientState", `Failed to parse online state: ${t}`),
- null);
- }
- }
- class Ru {
- constructor() {
- this.activeTargetIds = ps();
- }
- lr(t) {
- this.activeTargetIds = this.activeTargetIds.add(t);
- }
- dr(t) {
- this.activeTargetIds = this.activeTargetIds.delete(t);
- }
-
- hr() {
- const t = {
- activeTargetIds: this.activeTargetIds.toArray(),
- updateTimeMs: Date.now()
- };
- return JSON.stringify(t);
- }
- }
- class Pu {
- constructor(t, e, n, s, i) {
- this.window = t, this.ii = e, this.persistenceKey = n, this.wr = s, this.syncEngine = null,
- this.onlineStateHandler = null, this.sequenceNumberHandler = null, this._r = this.mr.bind(this),
- this.gr = new pe(et), this.started = !1,
-
- this.yr = [];
-
-
- const r = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
- this.storage = this.window.localStorage, this.currentUser = i, this.pr = yu(this.persistenceKey, this.wr),
- this.Ir =
-
- function(t) {
- return `firestore_sequence_number_${t}`;
- }
-
- (this.persistenceKey), this.gr = this.gr.insert(this.wr, new Ru), this.Tr = new RegExp(`^firestore_clients_${r}_([^_]*)$`),
- this.Er = new RegExp(`^firestore_mutations_${r}_(\\d+)(?:_(.*))?$`), this.Ar = new RegExp(`^firestore_targets_${r}_(\\d+)$`),
- this.vr =
-
- function(t) {
- return `firestore_online_state_${t}`;
- }
-
-
-
-
-
- (this.persistenceKey), this.Rr = function(t) {
- return `firestore_bundle_loaded_v2_${t}`;
- }
-
-
- (this.persistenceKey),
-
-
-
-
-
-
- this.window.addEventListener("storage", this._r);
- }
- static D(t) {
- return !(!t || !t.localStorage);
- }
- async start() {
-
-
- const t = await this.syncEngine.$i();
- for (const e of t) {
- if (e === this.wr) continue;
- const t = this.getItem(yu(this.persistenceKey, e));
- if (t) {
- const n = Au.ar(e, t);
- n && (this.gr = this.gr.insert(n.clientId, n));
- }
- }
- this.Pr();
-
-
- const e = this.storage.getItem(this.vr);
- if (e) {
- const t = this.br(e);
- t && this.Vr(t);
- }
- for (const t of this.yr) this.mr(t);
- this.yr = [],
-
-
- this.window.addEventListener("pagehide", (() => this.shutdown())), this.started = !0;
- }
- writeSequenceNumber(t) {
- this.setItem(this.Ir, JSON.stringify(t));
- }
- getAllActiveQueryTargets() {
- return this.Sr(this.gr);
- }
- isActiveQueryTarget(t) {
- let e = !1;
- return this.gr.forEach(((n, s) => {
- s.activeTargetIds.has(t) && (e = !0);
- })), e;
- }
- addPendingMutation(t) {
- this.Dr(t, "pending");
- }
- updateMutationState(t, e, n) {
- this.Dr(t, e, n),
-
-
-
- this.Cr(t);
- }
- addLocalQueryTarget(t) {
- let e = "not-current";
-
-
- if (this.isActiveQueryTarget(t)) {
- const n = this.storage.getItem(Iu(this.persistenceKey, t));
- if (n) {
- const s = Eu.ar(t, n);
- s && (e = s.state);
- }
- }
- return this.Nr.lr(t), this.Pr(), e;
- }
- removeLocalQueryTarget(t) {
- this.Nr.dr(t), this.Pr();
- }
- isLocalQueryTarget(t) {
- return this.Nr.activeTargetIds.has(t);
- }
- clearQueryState(t) {
- this.removeItem(Iu(this.persistenceKey, t));
- }
- updateQueryState(t, e, n) {
- this.kr(t, e, n);
- }
- handleUserChange(t, e, n) {
- e.forEach((t => {
- this.Cr(t);
- })), this.currentUser = t, n.forEach((t => {
- this.addPendingMutation(t);
- }));
- }
- setOnlineState(t) {
- this.Mr(t);
- }
- notifyBundleLoaded(t) {
- this.$r(t);
- }
- shutdown() {
- this.started && (this.window.removeEventListener("storage", this._r), this.removeItem(this.pr),
- this.started = !1);
- }
- getItem(t) {
- const e = this.storage.getItem(t);
- return N("SharedClientState", "READ", t, e), e;
- }
- setItem(t, e) {
- N("SharedClientState", "SET", t, e), this.storage.setItem(t, e);
- }
- removeItem(t) {
- N("SharedClientState", "REMOVE", t), this.storage.removeItem(t);
- }
- mr(t) {
-
-
- const e = t;
- if (e.storageArea === this.storage) {
- if (N("SharedClientState", "EVENT", e.key, e.newValue), e.key === this.pr) return void k("Received WebStorage notification for local change. Another client might have garbage-collected our state");
- this.ii.enqueueRetryable((async () => {
- if (this.started) {
- if (null !== e.key) if (this.Tr.test(e.key)) {
- if (null == e.newValue) {
- const t = this.Or(e.key);
- return this.Fr(t, null);
- }
- {
- const t = this.Br(e.key, e.newValue);
- if (t) return this.Fr(t.clientId, t);
- }
- } else if (this.Er.test(e.key)) {
- if (null !== e.newValue) {
- const t = this.Lr(e.key, e.newValue);
- if (t) return this.qr(t);
- }
- } else if (this.Ar.test(e.key)) {
- if (null !== e.newValue) {
- const t = this.Ur(e.key, e.newValue);
- if (t) return this.Kr(t);
- }
- } else if (e.key === this.vr) {
- if (null !== e.newValue) {
- const t = this.br(e.newValue);
- if (t) return this.Vr(t);
- }
- } else if (e.key === this.Ir) {
- const t = function(t) {
- let e = Ot.ct;
- if (null != t) try {
- const n = JSON.parse(t);
- F("number" == typeof n), e = n;
- } catch (t) {
- k("SharedClientState", "Failed to read sequence number from WebStorage", t);
- }
- return e;
- }
-
- (e.newValue);
- t !== Ot.ct && this.sequenceNumberHandler(t);
- } else if (e.key === this.Rr) {
- const t = this.Gr(e.newValue);
- await Promise.all(t.map((t => this.syncEngine.Qr(t))));
- }
- } else this.yr.push(e);
- }));
- }
- }
- get Nr() {
- return this.gr.get(this.wr);
- }
- Pr() {
- this.setItem(this.pr, this.Nr.hr());
- }
- Dr(t, e, n) {
- const s = new Tu(this.currentUser, t, e, n), i = pu(this.persistenceKey, this.currentUser, t);
- this.setItem(i, s.hr());
- }
- Cr(t) {
- const e = pu(this.persistenceKey, this.currentUser, t);
- this.removeItem(e);
- }
- Mr(t) {
- const e = {
- clientId: this.wr,
- onlineState: t
- };
- this.storage.setItem(this.vr, JSON.stringify(e));
- }
- kr(t, e, n) {
- const s = Iu(this.persistenceKey, t), i = new Eu(t, e, n);
- this.setItem(s, i.hr());
- }
- $r(t) {
- const e = JSON.stringify(Array.from(t));
- this.setItem(this.Rr, e);
- }
-
- Or(t) {
- const e = this.Tr.exec(t);
- return e ? e[1] : null;
- }
-
- Br(t, e) {
- const n = this.Or(t);
- return Au.ar(n, e);
- }
-
- Lr(t, e) {
- const n = this.Er.exec(t), s = Number(n[1]), i = void 0 !== n[2] ? n[2] : null;
- return Tu.ar(new V(i), s, e);
- }
-
- Ur(t, e) {
- const n = this.Ar.exec(t), s = Number(n[1]);
- return Eu.ar(s, e);
- }
-
- br(t) {
- return vu.ar(t);
- }
- Gr(t) {
- return JSON.parse(t);
- }
- async qr(t) {
- if (t.user.uid === this.currentUser.uid) return this.syncEngine.jr(t.batchId, t.state, t.error);
- N("SharedClientState", `Ignoring mutation for non-active user ${t.user.uid}`);
- }
- Kr(t) {
- return this.syncEngine.zr(t.targetId, t.state, t.error);
- }
- Fr(t, e) {
- const n = e ? this.gr.insert(t, e) : this.gr.remove(t), s = this.Sr(this.gr), i = this.Sr(n), r = [], o = [];
- return i.forEach((t => {
- s.has(t) || r.push(t);
- })), s.forEach((t => {
- i.has(t) || o.push(t);
- })), this.syncEngine.Wr(r, o).then((() => {
- this.gr = n;
- }));
- }
- Vr(t) {
-
-
-
-
-
- this.gr.get(t.clientId) && this.onlineStateHandler(t.onlineState);
- }
- Sr(t) {
- let e = ps();
- return t.forEach(((t, n) => {
- e = e.unionWith(n.activeTargetIds);
- })), e;
- }
- }
- class bu {
- constructor() {
- this.Hr = new Ru, this.Jr = {}, this.onlineStateHandler = null, this.sequenceNumberHandler = null;
- }
- addPendingMutation(t) {
-
- }
- updateMutationState(t, e, n) {
-
- }
- addLocalQueryTarget(t) {
- return this.Hr.lr(t), this.Jr[t] || "not-current";
- }
- updateQueryState(t, e, n) {
- this.Jr[t] = e;
- }
- removeLocalQueryTarget(t) {
- this.Hr.dr(t);
- }
- isLocalQueryTarget(t) {
- return this.Hr.activeTargetIds.has(t);
- }
- clearQueryState(t) {
- delete this.Jr[t];
- }
- getAllActiveQueryTargets() {
- return this.Hr.activeTargetIds;
- }
- isActiveQueryTarget(t) {
- return this.Hr.activeTargetIds.has(t);
- }
- start() {
- return this.Hr = new Ru, Promise.resolve();
- }
- handleUserChange(t, e, n) {
-
- }
- setOnlineState(t) {
-
- }
- shutdown() {}
- writeSequenceNumber(t) {}
- notifyBundleLoaded(t) {
-
- }
- }
- class Vu {
- Yr(t) {
-
- }
- shutdown() {
-
- }
- }
- class Su {
- constructor() {
- this.Xr = () => this.Zr(), this.eo = () => this.no(), this.so = [], this.io();
- }
- Yr(t) {
- this.so.push(t);
- }
- shutdown() {
- window.removeEventListener("online", this.Xr), window.removeEventListener("offline", this.eo);
- }
- io() {
- window.addEventListener("online", this.Xr), window.addEventListener("offline", this.eo);
- }
- Zr() {
- N("ConnectivityMonitor", "Network connectivity changed: AVAILABLE");
- for (const t of this.so) t(0 );
- }
- no() {
- N("ConnectivityMonitor", "Network connectivity changed: UNAVAILABLE");
- for (const t of this.so) t(1 );
- }
-
-
-
- static D() {
- return "undefined" != typeof window && void 0 !== window.addEventListener && void 0 !== window.removeEventListener;
- }
- }
- let Du = null;
- function Cu() {
- return null === Du ? Du = 268435456 + Math.round(2147483648 * Math.random()) : Du++,
- "0x" + Du.toString(16);
- }
- const xu = {
- BatchGetDocuments: "batchGet",
- Commit: "commit",
- RunQuery: "runQuery",
- RunAggregationQuery: "runAggregationQuery"
- };
- class Nu {
- constructor(t) {
- this.ro = t.ro, this.oo = t.oo;
- }
- uo(t) {
- this.co = t;
- }
- ao(t) {
- this.ho = t;
- }
- onMessage(t) {
- this.lo = t;
- }
- close() {
- this.oo();
- }
- send(t) {
- this.ro(t);
- }
- fo() {
- this.co();
- }
- wo(t) {
- this.ho(t);
- }
- _o(t) {
- this.lo(t);
- }
- }
- const ku = "WebChannelConnection";
- class Mu extends
- /**
- * Base class for all Rest-based connections to the backend (WebChannel and
- * HTTP).
- */
- class {
- constructor(t) {
- this.databaseInfo = t, this.databaseId = t.databaseId;
- const e = t.ssl ? "https" : "http";
- this.mo = e + "://" + t.host, this.yo = "projects/" + this.databaseId.projectId + "/databases/" + this.databaseId.database + "/documents";
- }
- get po() {
-
-
- return !1;
- }
- Io(t, e, n, s, i) {
- const r = Cu(), o = this.To(t, e);
- N("RestConnection", `Sending RPC '${t}' ${r}:`, o, n);
- const u = {};
- return this.Eo(u, s, i), this.Ao(t, o, u, n).then((e => (N("RestConnection", `Received RPC '${t}' ${r}: `, e),
- e)), (e => {
- throw M("RestConnection", `RPC '${t}' ${r} failed with error: `, e, "url: ", o, "request:", n),
- e;
- }));
- }
- vo(t, e, n, s, i, r) {
-
-
- return this.Io(t, e, n, s, i);
- }
-
- Eo(t, e, n) {
- t["X-Goog-Api-Client"] = "gl-js/ fire/" + S,
-
-
-
-
- t["Content-Type"] = "text/plain", this.databaseInfo.appId && (t["X-Firebase-GMPID"] = this.databaseInfo.appId),
- e && e.headers.forEach(((e, n) => t[n] = e)), n && n.headers.forEach(((e, n) => t[n] = e));
- }
- To(t, e) {
- const n = xu[t];
- return `${this.mo}/v1/${e}:${n}`;
- }
- } {
- constructor(t) {
- super(t), this.forceLongPolling = t.forceLongPolling, this.autoDetectLongPolling = t.autoDetectLongPolling,
- this.useFetchStreams = t.useFetchStreams, this.longPollingOptions = t.longPollingOptions;
- }
- Ao(t, e, n, s) {
- const i = Cu();
- return new Promise(((r, o) => {
- const u = new XhrIo;
- u.setWithCredentials(!0), u.listenOnce(EventType.COMPLETE, (() => {
- try {
- switch (u.getLastErrorCode()) {
- case ErrorCode.NO_ERROR:
- const e = u.getResponseJson();
- N(ku, `XHR for RPC '${t}' ${i} received:`, JSON.stringify(e)), r(e);
- break;
- case ErrorCode.TIMEOUT:
- N(ku, `RPC '${t}' ${i} timed out`), o(new U(q.DEADLINE_EXCEEDED, "Request time out"));
- break;
- case ErrorCode.HTTP_ERROR:
- const n = u.getStatus();
- if (N(ku, `RPC '${t}' ${i} failed with status:`, n, "response text:", u.getResponseText()),
- n > 0) {
- let t = u.getResponseJson();
- Array.isArray(t) && (t = t[0]);
- const e = null == t ? void 0 : t.error;
- if (e && e.status && e.message) {
- const t = function(t) {
- const e = t.toLowerCase().replace(/_/g, "-");
- return Object.values(q).indexOf(e) >= 0 ? e : q.UNKNOWN;
- }(e.status);
- o(new U(t, e.message));
- } else o(new U(q.UNKNOWN, "Server responded with status " + u.getStatus()));
- } else
-
-
- o(new U(q.UNAVAILABLE, "Connection failed."));
- break;
- default:
- O();
- }
- } finally {
- N(ku, `RPC '${t}' ${i} completed.`);
- }
- }));
- const c = JSON.stringify(s);
- N(ku, `RPC '${t}' ${i} sending request:`, s), u.send(e, "POST", c, n, 15);
- }));
- }
- Ro(t, e, n) {
- const s = Cu(), i = [ this.mo, "/", "google.firestore.v1.Firestore", "/", t, "/channel" ], r = createWebChannelTransport(), o = getStatEventTarget(), u = {
-
-
- httpSessionIdParam: "gsessionid",
- initMessageHeaders: {},
- messageUrlParams: {
-
-
- database: `projects/${this.databaseId.projectId}/databases/${this.databaseId.database}`
- },
- sendRawJson: !0,
- supportsCrossDomainXhr: !0,
- internalChannelParams: {
-
-
-
-
-
-
- forwardChannelRequestTimeoutMs: 6e5
- },
- forceLongPolling: this.forceLongPolling,
- detectBufferingProxy: this.autoDetectLongPolling
- }, c = this.longPollingOptions.timeoutSeconds;
- void 0 !== c && (u.longPollingTimeout = Math.round(1e3 * c)), this.useFetchStreams && (u.xmlHttpFactory = new FetchXmlHttpFactory({})),
- this.Eo(u.initMessageHeaders, e, n),
-
-
-
-
-
-
-
-
-
- u.encodeInitMessageHeaders = !0;
- const a = i.join("");
- N(ku, `Creating RPC '${t}' stream ${s}: ${a}`, u);
- const h = r.createWebChannel(a, u);
-
-
-
-
-
- let l = !1, f = !1;
-
-
-
- const d = new Nu({
- ro: e => {
- f ? N(ku, `Not sending because RPC '${t}' stream ${s} is closed:`, e) : (l || (N(ku, `Opening RPC '${t}' stream ${s} transport.`),
- h.open(), l = !0), N(ku, `RPC '${t}' stream ${s} sending:`, e), h.send(e));
- },
- oo: () => h.close()
- }), w = (t, e, n) => {
-
-
- t.listen(e, (t => {
- try {
- n(t);
- } catch (t) {
- setTimeout((() => {
- throw t;
- }), 0);
- }
- }));
- };
-
-
-
-
- return w(h, WebChannel.EventType.OPEN, (() => {
- f || N(ku, `RPC '${t}' stream ${s} transport opened.`);
- })), w(h, WebChannel.EventType.CLOSE, (() => {
- f || (f = !0, N(ku, `RPC '${t}' stream ${s} transport closed`), d.wo());
- })), w(h, WebChannel.EventType.ERROR, (e => {
- f || (f = !0, M(ku, `RPC '${t}' stream ${s} transport errored:`, e), d.wo(new U(q.UNAVAILABLE, "The operation could not be completed")));
- })), w(h, WebChannel.EventType.MESSAGE, (e => {
- var n;
- if (!f) {
- const i = e.data[0];
- F(!!i);
-
-
-
-
-
- const r = i, o = r.error || (null === (n = r[0]) || void 0 === n ? void 0 : n.error);
- if (o) {
- N(ku, `RPC '${t}' stream ${s} received error:`, o);
-
- const e = o.status;
- let n =
-
- function(t) {
-
-
- const e = ii[t];
- if (void 0 !== e) return ui(e);
- }(e), i = o.message;
- void 0 === n && (n = q.INTERNAL, i = "Unknown error status: " + e + " with message " + o.message),
-
- f = !0, d.wo(new U(n, i)), h.close();
- } else N(ku, `RPC '${t}' stream ${s} received:`, i), d._o(i);
- }
- })), w(o, Event.STAT_EVENT, (e => {
- e.stat === Stat.PROXY ? N(ku, `RPC '${t}' stream ${s} detected buffering proxy`) : e.stat === Stat.NOPROXY && N(ku, `RPC '${t}' stream ${s} detected no buffering proxy`);
- })), setTimeout((() => {
-
-
-
-
- d.fo();
- }), 0), d;
- }
- }
- function $u() {
-
-
- return "undefined" != typeof window ? window : null;
- }
- function Ou() {
-
-
- return "undefined" != typeof document ? document : null;
- }
- function Fu(t) {
- return new Vi(t, !0);
- }
- class Bu {
- constructor(
- /**
- * The AsyncQueue to run backoff operations on.
- */
- t,
- /**
- * The ID to use when scheduling backoff operations on the AsyncQueue.
- */
- e,
- /**
- * The initial delay (used as the base delay on the first retry attempt).
- * Note that jitter will still be applied, so the actual delay could be as
- * little as 0.5*initialDelayMs.
- */
- n = 1e3
- /**
- * The multiplier to use to determine the extended base delay after each
- * attempt.
- */ , s = 1.5
- /**
- * The maximum base delay after which no further backoff is performed.
- * Note that jitter will still be applied, so the actual delay could be as
- * much as 1.5*maxDelayMs.
- */ , i = 6e4) {
- this.ii = t, this.timerId = e, this.Po = n, this.bo = s, this.Vo = i, this.So = 0,
- this.Do = null,
-
- this.Co = Date.now(), this.reset();
- }
-
- reset() {
- this.So = 0;
- }
-
- xo() {
- this.So = this.Vo;
- }
-
- No(t) {
-
- this.cancel();
-
-
- const e = Math.floor(this.So + this.ko()), n = Math.max(0, Date.now() - this.Co), s = Math.max(0, e - n);
-
- s > 0 && N("ExponentialBackoff", `Backing off for ${s} ms (base delay: ${this.So} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),
- this.Do = this.ii.enqueueAfterDelay(this.timerId, s, (() => (this.Co = Date.now(),
- t()))),
-
-
- this.So *= this.bo, this.So < this.Po && (this.So = this.Po), this.So > this.Vo && (this.So = this.Vo);
- }
- Mo() {
- null !== this.Do && (this.Do.skipDelay(), this.Do = null);
- }
- cancel() {
- null !== this.Do && (this.Do.cancel(), this.Do = null);
- }
- ko() {
- return (Math.random() - .5) * this.So;
- }
- }
- class Lu {
- constructor(t, e, n, s, i, r, o, u) {
- this.ii = t, this.$o = n, this.Oo = s, this.connection = i, this.authCredentialsProvider = r,
- this.appCheckCredentialsProvider = o, this.listener = u, this.state = 0 ,
-
- this.Fo = 0, this.Bo = null, this.Lo = null, this.stream = null, this.qo = new Bu(t, e);
- }
-
- Uo() {
- return 1 === this.state || 5 === this.state || this.Ko();
- }
-
- Ko() {
- return 2 === this.state || 3 === this.state;
- }
-
- start() {
- 4 !== this.state ? this.auth() : this.Go();
- }
-
- async stop() {
- this.Uo() && await this.close(0 );
- }
-
- Qo() {
- this.state = 0 , this.qo.reset();
- }
-
- jo() {
-
-
- this.Ko() && null === this.Bo && (this.Bo = this.ii.enqueueAfterDelay(this.$o, 6e4, (() => this.zo())));
- }
- Wo(t) {
- this.Ho(), this.stream.send(t);
- }
- async zo() {
- if (this.Ko())
-
-
- return this.close(0 );
- }
- Ho() {
- this.Bo && (this.Bo.cancel(), this.Bo = null);
- }
- Jo() {
- this.Lo && (this.Lo.cancel(), this.Lo = null);
- }
-
- async close(t, e) {
-
- this.Ho(), this.Jo(), this.qo.cancel(),
-
-
- this.Fo++, 4 !== t ?
-
- this.qo.reset() : e && e.code === q.RESOURCE_EXHAUSTED ? (
-
- k(e.toString()), k("Using maximum backoff delay to prevent overloading the backend."),
- this.qo.xo()) : e && e.code === q.UNAUTHENTICATED && 3 !== this.state && (
-
-
-
-
-
-
- this.authCredentialsProvider.invalidateToken(), this.appCheckCredentialsProvider.invalidateToken()),
-
- null !== this.stream && (this.Yo(), this.stream.close(), this.stream = null),
-
-
- this.state = t,
-
- await this.listener.ao(e);
- }
-
- Yo() {}
- auth() {
- this.state = 1 ;
- const t = this.Xo(this.Fo), e = this.Fo;
-
- Promise.all([ this.authCredentialsProvider.getToken(), this.appCheckCredentialsProvider.getToken() ]).then((([t, n]) => {
-
-
-
-
- this.Fo === e &&
-
-
-
- this.Zo(t, n);
- }), (e => {
- t((() => {
- const t = new U(q.UNKNOWN, "Fetching auth token failed: " + e.message);
- return this.tu(t);
- }));
- }));
- }
- Zo(t, e) {
- const n = this.Xo(this.Fo);
- this.stream = this.eu(t, e), this.stream.uo((() => {
- n((() => (this.state = 2 , this.Lo = this.ii.enqueueAfterDelay(this.Oo, 1e4, (() => (this.Ko() && (this.state = 3 ),
- Promise.resolve()))), this.listener.uo())));
- })), this.stream.ao((t => {
- n((() => this.tu(t)));
- })), this.stream.onMessage((t => {
- n((() => this.onMessage(t)));
- }));
- }
- Go() {
- this.state = 5 , this.qo.No((async () => {
- this.state = 0 , this.start();
- }));
- }
-
- tu(t) {
-
-
-
-
- return N("PersistentStream", `close with error: ${t}`), this.stream = null, this.close(4 , t);
- }
-
- Xo(t) {
- return e => {
- this.ii.enqueueAndForget((() => this.Fo === t ? e() : (N("PersistentStream", "stream callback skipped by getCloseGuardedDispatcher."),
- Promise.resolve())));
- };
- }
- }
- class qu extends Lu {
- constructor(t, e, n, s, i, r) {
- super(t, "listen_stream_connection_backoff" , "listen_stream_idle" , "health_check_timeout" , e, n, s, r),
- this.serializer = i;
- }
- eu(t, e) {
- return this.connection.Ro("Listen", t, e);
- }
- onMessage(t) {
-
- this.qo.reset();
- const e = Qi(this.serializer, t), n = function(t) {
-
-
-
- if (!("targetChange" in t)) return rt.min();
- const e = t.targetChange;
- return e.targetIds && e.targetIds.length ? rt.min() : e.readTime ? Ni(e.readTime) : rt.min();
- }(t);
- return this.listener.nu(e, n);
- }
-
- su(t) {
- const e = {};
- e.database = Li(this.serializer), e.addTarget = function(t, e) {
- let n;
- const s = e.target;
- if (n = Fn(s) ? {
- documents: Hi(t, s)
- } : {
- query: Ji(t, s)
- }, n.targetId = e.targetId, e.resumeToken.approximateByteSize() > 0) {
- n.resumeToken = Ci(t, e.resumeToken);
- const s = Si(t, e.expectedCount);
- null !== s && (n.expectedCount = s);
- } else if (e.snapshotVersion.compareTo(rt.min()) > 0) {
-
-
-
- n.readTime = Di(t, e.snapshotVersion.toTimestamp());
- const s = Si(t, e.expectedCount);
- null !== s && (n.expectedCount = s);
- }
- return n;
- }(this.serializer, t);
- const n = Xi(this.serializer, t);
- n && (e.labels = n), this.Wo(e);
- }
-
- iu(t) {
- const e = {};
- e.database = Li(this.serializer), e.removeTarget = t, this.Wo(e);
- }
- }
- class Uu extends Lu {
- constructor(t, e, n, s, i, r) {
- super(t, "write_stream_connection_backoff" , "write_stream_idle" , "health_check_timeout" , e, n, s, r),
- this.serializer = i, this.ru = !1;
- }
-
- get ou() {
- return this.ru;
- }
-
- start() {
- this.ru = !1, this.lastStreamToken = void 0, super.start();
- }
- Yo() {
- this.ru && this.uu([]);
- }
- eu(t, e) {
- return this.connection.Ro("Write", t, e);
- }
- onMessage(t) {
- if (
-
- F(!!t.streamToken), this.lastStreamToken = t.streamToken, this.ru) {
-
-
-
- this.qo.reset();
- const e = Wi(t.writeResults, t.commitTime), n = Ni(t.commitTime);
- return this.listener.cu(n, e);
- }
-
- return F(!t.writeResults || 0 === t.writeResults.length), this.ru = !0, this.listener.au();
- }
-
- hu() {
-
-
- const t = {};
- t.database = Li(this.serializer), this.Wo(t);
- }
- uu(t) {
- const e = {
- streamToken: this.lastStreamToken,
- writes: t.map((t => ji(this.serializer, t)))
- };
- this.Wo(e);
- }
- }
- class Ku extends class {} {
- constructor(t, e, n, s) {
- super(), this.authCredentials = t, this.appCheckCredentials = e, this.connection = n,
- this.serializer = s, this.lu = !1;
- }
- fu() {
- if (this.lu) throw new U(q.FAILED_PRECONDITION, "The client has already been terminated.");
- }
- Io(t, e, n) {
- return this.fu(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((([s, i]) => this.connection.Io(t, e, n, s, i))).catch((t => {
- throw "FirebaseError" === t.name ? (t.code === q.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
- this.appCheckCredentials.invalidateToken()), t) : new U(q.UNKNOWN, t.toString());
- }));
- }
- vo(t, e, n, s) {
- return this.fu(), Promise.all([ this.authCredentials.getToken(), this.appCheckCredentials.getToken() ]).then((([i, r]) => this.connection.vo(t, e, n, i, r, s))).catch((t => {
- throw "FirebaseError" === t.name ? (t.code === q.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
- this.appCheckCredentials.invalidateToken()), t) : new U(q.UNKNOWN, t.toString());
- }));
- }
- terminate() {
- this.lu = !0;
- }
- }
- async function Gu(t, e, n) {
- var s;
- const i = L(t), {request: r, du: o} = function(t, e, n) {
- const s = Ji(t, e), i = {}, r = [];
- let o = 0;
- return n.forEach((t => {
-
-
-
- const e = "aggregate_" + o++;
- i[e] = t.alias, "count" === t.yt ? r.push({
- alias: e,
- count: {}
- }) : "avg" === t.yt ? r.push({
- alias: e,
- avg: {
- field: sr(t.fieldPath)
- }
- }) : "sum" === t.yt && r.push({
- alias: e,
- sum: {
- field: sr(t.fieldPath)
- }
- });
- })), {
- request: {
- structuredAggregationQuery: {
- aggregations: r,
- structuredQuery: s.structuredQuery
- },
- parent: s.parent
- },
- du: i
- };
- }(i.serializer, Jn(e), n), u = r.parent;
- i.connection.po || delete r.parent;
- const c = (await i.vo("RunAggregationQuery", u, r, 1)).filter((t => !!t.result));
-
- F(1 === c.length);
-
-
-
- const a = null === (s = c[0].result) || void 0 === s ? void 0 : s.aggregateFields;
- return Object.keys(a).reduce(((t, e) => (t[o[e]] = a[e], t)), {});
- }
- class Qu {
- constructor(t, e) {
- this.asyncQueue = t, this.onlineStateHandler = e,
-
- this.state = "Unknown" ,
-
- this.wu = 0,
-
- this._u = null,
-
- this.mu = !0;
- }
-
- gu() {
- 0 === this.wu && (this.yu("Unknown" ), this._u = this.asyncQueue.enqueueAfterDelay("online_state_timeout" , 1e4, (() => (this._u = null,
- this.pu("Backend didn't respond within 10 seconds."), this.yu("Offline" ),
- Promise.resolve()))));
- }
-
- Iu(t) {
- "Online" === this.state ? this.yu("Unknown" ) : (this.wu++,
- this.wu >= 1 && (this.Tu(), this.pu(`Connection failed 1 times. Most recent error: ${t.toString()}`),
- this.yu("Offline" )));
- }
-
- set(t) {
- this.Tu(), this.wu = 0, "Online" === t && (
-
-
- this.mu = !1), this.yu(t);
- }
- yu(t) {
- t !== this.state && (this.state = t, this.onlineStateHandler(t));
- }
- pu(t) {
- const e = `Could not reach Cloud Firestore backend. ${t}\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;
- this.mu ? (k(e), this.mu = !1) : N("OnlineStateTracker", e);
- }
- Tu() {
- null !== this._u && (this._u.cancel(), this._u = null);
- }
- }
- class ju {
- constructor(
- /**
- * The local store, used to fill the write pipeline with outbound mutations.
- */
- t,
- /** The client-side proxy for interacting with the backend. */
- e, n, s, i) {
- this.localStore = t, this.datastore = e, this.asyncQueue = n, this.remoteSyncer = {},
-
- this.Eu = [],
-
- this.Au = new Map,
-
- this.vu = new Set,
-
- this.Ru = [], this.Pu = i, this.Pu.Yr((t => {
- n.enqueueAndForget((async () => {
-
-
-
- ec(this) && (N("RemoteStore", "Restarting streams for network reachability change."),
- await async function(t) {
- const e = L(t);
- e.vu.add(4 ), await Wu(e), e.bu.set("Unknown" ),
- e.vu.delete(4 ), await zu(e);
- }(this));
- }));
- })), this.bu = new Qu(n, s);
- }
- }
- async function zu(t) {
- if (ec(t)) for (const e of t.Ru) await e( !0);
- }
- async function Wu(t) {
- for (const e of t.Ru) await e( !1);
- }
- function Hu(t, e) {
- const n = L(t);
- n.Au.has(e.targetId) || (
-
- n.Au.set(e.targetId, e), tc(n) ?
-
- Zu(n) : pc(n).Ko() && Yu(n, e));
- }
- function Ju(t, e) {
- const n = L(t), s = pc(n);
- n.Au.delete(e), s.Ko() && Xu(n, e), 0 === n.Au.size && (s.Ko() ? s.jo() : ec(n) &&
-
-
-
- n.bu.set("Unknown" ));
- }
- function Yu(t, e) {
- if (t.Vu.qt(e.targetId), e.resumeToken.approximateByteSize() > 0 || e.snapshotVersion.compareTo(rt.min()) > 0) {
- const n = t.remoteSyncer.getRemoteKeysForTarget(e.targetId).size;
- e = e.withExpectedCount(n);
- }
- pc(t).su(e);
- }
- function Xu(t, e) {
- t.Vu.qt(e), pc(t).iu(e);
- }
- function Zu(t) {
- t.Vu = new Ei({
- getRemoteKeysForTarget: e => t.remoteSyncer.getRemoteKeysForTarget(e),
- le: e => t.Au.get(e) || null,
- ue: () => t.datastore.serializer.databaseId
- }), pc(t).start(), t.bu.gu();
- }
- function tc(t) {
- return ec(t) && !pc(t).Uo() && t.Au.size > 0;
- }
- function ec(t) {
- return 0 === L(t).vu.size;
- }
- function nc(t) {
- t.Vu = void 0;
- }
- async function sc(t) {
- t.Au.forEach(((e, n) => {
- Yu(t, e);
- }));
- }
- async function ic(t, e) {
- nc(t),
-
- tc(t) ? (t.bu.Iu(e), Zu(t)) :
-
-
-
- t.bu.set("Unknown" );
- }
- async function rc(t, e, n) {
- if (
-
- t.bu.set("Online" ), e instanceof Ii && 2 === e.state && e.cause)
-
-
- try {
- await
-
- async function(t, e) {
- const n = e.cause;
- for (const s of e.targetIds)
-
- t.Au.has(s) && (await t.remoteSyncer.rejectListen(s, n), t.Au.delete(s), t.Vu.removeTarget(s));
- }
-
- (t, e);
- } catch (n) {
- N("RemoteStore", "Failed to remove targets %s: %s ", e.targetIds.join(","), n),
- await oc(t, n);
- } else if (e instanceof yi ? t.Vu.Ht(e) : e instanceof pi ? t.Vu.ne(e) : t.Vu.Xt(e),
- !n.isEqual(rt.min())) try {
- const e = await ou(t.localStore);
- n.compareTo(e) >= 0 &&
-
-
- await
-
- function(t, e) {
- const n = t.Vu.ce(e);
-
-
- return n.targetChanges.forEach(((n, s) => {
- if (n.resumeToken.approximateByteSize() > 0) {
- const i = t.Au.get(s);
-
- i && t.Au.set(s, i.withResumeToken(n.resumeToken, e));
- }
- })),
-
-
- n.targetMismatches.forEach(((e, n) => {
- const s = t.Au.get(e);
- if (!s)
-
- return;
-
-
- t.Au.set(e, s.withResumeToken(Ve.EMPTY_BYTE_STRING, s.snapshotVersion)),
-
-
- Xu(t, e);
-
-
-
-
- const i = new cr(s.target, e, n, s.sequenceNumber);
- Yu(t, i);
- })), t.remoteSyncer.applyRemoteEvent(n);
- }(t, n);
- } catch (e) {
- N("RemoteStore", "Failed to raise snapshot:", e), await oc(t, e);
- }
- }
- async function oc(t, e, n) {
- if (!Dt(e)) throw e;
- t.vu.add(1 ),
-
- await Wu(t), t.bu.set("Offline" ), n || (
-
-
-
- n = () => ou(t.localStore)),
-
- t.asyncQueue.enqueueRetryable((async () => {
- N("RemoteStore", "Retrying IndexedDB access"), await n(), t.vu.delete(1 ),
- await zu(t);
- }));
- }
- function uc(t, e) {
- return e().catch((n => oc(t, n, e)));
- }
- async function cc(t) {
- const e = L(t), n = Ic(e);
- let s = e.Eu.length > 0 ? e.Eu[e.Eu.length - 1].batchId : -1;
- for (;ac(e); ) try {
- const t = await au(e.localStore, s);
- if (null === t) {
- 0 === e.Eu.length && n.jo();
- break;
- }
- s = t.batchId, hc(e, t);
- } catch (t) {
- await oc(e, t);
- }
- lc(e) && fc(e);
- }
- function ac(t) {
- return ec(t) && t.Eu.length < 10;
- }
- function hc(t, e) {
- t.Eu.push(e);
- const n = Ic(t);
- n.Ko() && n.ou && n.uu(e.mutations);
- }
- function lc(t) {
- return ec(t) && !Ic(t).Uo() && t.Eu.length > 0;
- }
- function fc(t) {
- Ic(t).start();
- }
- async function dc(t) {
- Ic(t).hu();
- }
- async function wc(t) {
- const e = Ic(t);
-
- for (const n of t.Eu) e.uu(n.mutations);
- }
- async function _c(t, e, n) {
- const s = t.Eu.shift(), i = ti.from(s, e, n);
- await uc(t, (() => t.remoteSyncer.applySuccessfulWrite(i))),
-
-
- await cc(t);
- }
- async function mc(t, e) {
-
-
- e && Ic(t).ou &&
-
- await async function(t, e) {
-
-
- if (n = e.code, oi(n) && n !== q.ABORTED) {
-
-
- const n = t.Eu.shift();
-
-
-
- Ic(t).Qo(), await uc(t, (() => t.remoteSyncer.rejectFailedWrite(n.batchId, e))),
-
-
- await cc(t);
- }
- var n;
- }(t, e),
-
-
- lc(t) && fc(t);
- }
- async function gc(t, e) {
- const n = L(t);
- n.asyncQueue.verifyOperationInProgress(), N("RemoteStore", "RemoteStore received new credentials");
- const s = ec(n);
-
-
-
- n.vu.add(3 ), await Wu(n), s &&
-
- n.bu.set("Unknown" ), await n.remoteSyncer.handleCredentialChange(e),
- n.vu.delete(3 ), await zu(n);
- }
- async function yc(t, e) {
- const n = L(t);
- e ? (n.vu.delete(2 ), await zu(n)) : e || (n.vu.add(2 ),
- await Wu(n), n.bu.set("Unknown" ));
- }
- function pc(t) {
- return t.Su || (
-
- t.Su = function(t, e, n) {
- const s = L(t);
- return s.fu(), new qu(e, s.connection, s.authCredentials, s.appCheckCredentials, s.serializer, n);
- }
-
- (t.datastore, t.asyncQueue, {
- uo: sc.bind(null, t),
- ao: ic.bind(null, t),
- nu: rc.bind(null, t)
- }), t.Ru.push((async e => {
- e ? (t.Su.Qo(), tc(t) ? Zu(t) : t.bu.set("Unknown" )) : (await t.Su.stop(),
- nc(t));
- }))), t.Su;
- }
- function Ic(t) {
- return t.Du || (
-
- t.Du = function(t, e, n) {
- const s = L(t);
- return s.fu(), new Uu(e, s.connection, s.authCredentials, s.appCheckCredentials, s.serializer, n);
- }(t.datastore, t.asyncQueue, {
- uo: dc.bind(null, t),
- ao: mc.bind(null, t),
- au: wc.bind(null, t),
- cu: _c.bind(null, t)
- }), t.Ru.push((async e => {
- e ? (t.Du.Qo(),
-
- await cc(t)) : (await t.Du.stop(), t.Eu.length > 0 && (N("RemoteStore", `Stopping write stream with ${t.Eu.length} pending writes`),
- t.Eu = []));
- }))), t.Du;
- }
- class Tc {
- constructor(t, e, n, s, i) {
- this.asyncQueue = t, this.timerId = e, this.targetTimeMs = n, this.op = s, this.removalCallback = i,
- this.deferred = new K, this.then = this.deferred.promise.then.bind(this.deferred.promise),
-
-
-
- this.deferred.promise.catch((t => {}));
- }
-
- static createAndSchedule(t, e, n, s, i) {
- const r = Date.now() + n, o = new Tc(t, e, r, s, i);
- return o.start(n), o;
- }
-
- start(t) {
- this.timerHandle = setTimeout((() => this.handleDelayElapsed()), t);
- }
-
- skipDelay() {
- return this.handleDelayElapsed();
- }
-
- cancel(t) {
- null !== this.timerHandle && (this.clearTimeout(), this.deferred.reject(new U(q.CANCELLED, "Operation cancelled" + (t ? ": " + t : ""))));
- }
- handleDelayElapsed() {
- this.asyncQueue.enqueueAndForget((() => null !== this.timerHandle ? (this.clearTimeout(),
- this.op().then((t => this.deferred.resolve(t)))) : Promise.resolve()));
- }
- clearTimeout() {
- null !== this.timerHandle && (this.removalCallback(this), clearTimeout(this.timerHandle),
- this.timerHandle = null);
- }
- }
- function Ec(t, e) {
- if (k("AsyncQueue", `${e}: ${t}`), Dt(t)) return new U(q.UNAVAILABLE, `${e}: ${t}`);
- throw t;
- }
- class Ac {
-
- constructor(t) {
-
-
- this.comparator = t ? (e, n) => t(e, n) || ht.comparator(e.key, n.key) : (t, e) => ht.comparator(t.key, e.key),
- this.keyedMap = hs(), this.sortedSet = new pe(this.comparator);
- }
-
- static emptySet(t) {
- return new Ac(t.comparator);
- }
- has(t) {
- return null != this.keyedMap.get(t);
- }
- get(t) {
- return this.keyedMap.get(t);
- }
- first() {
- return this.sortedSet.minKey();
- }
- last() {
- return this.sortedSet.maxKey();
- }
- isEmpty() {
- return this.sortedSet.isEmpty();
- }
-
- indexOf(t) {
- const e = this.keyedMap.get(t);
- return e ? this.sortedSet.indexOf(e) : -1;
- }
- get size() {
- return this.sortedSet.size;
- }
- forEach(t) {
- this.sortedSet.inorderTraversal(((e, n) => (t(e), !1)));
- }
- add(t) {
-
- const e = this.delete(t.key);
- return e.copy(e.keyedMap.insert(t.key, t), e.sortedSet.insert(t, null));
- }
- delete(t) {
- const e = this.get(t);
- return e ? this.copy(this.keyedMap.remove(t), this.sortedSet.remove(e)) : this;
- }
- isEqual(t) {
- if (!(t instanceof Ac)) return !1;
- if (this.size !== t.size) return !1;
- const e = this.sortedSet.getIterator(), n = t.sortedSet.getIterator();
- for (;e.hasNext(); ) {
- const t = e.getNext().key, s = n.getNext().key;
- if (!t.isEqual(s)) return !1;
- }
- return !0;
- }
- toString() {
- const t = [];
- return this.forEach((e => {
- t.push(e.toString());
- })), 0 === t.length ? "DocumentSet ()" : "DocumentSet (\n " + t.join(" \n") + "\n)";
- }
- copy(t, e) {
- const n = new Ac;
- return n.comparator = this.comparator, n.keyedMap = t, n.sortedSet = e, n;
- }
- }
- class vc {
- constructor() {
- this.Cu = new pe(ht.comparator);
- }
- track(t) {
- const e = t.doc.key, n = this.Cu.get(e);
- n ?
-
- 0 !== t.type && 3 === n.type ? this.Cu = this.Cu.insert(e, t) : 3 === t.type && 1 !== n.type ? this.Cu = this.Cu.insert(e, {
- type: n.type,
- doc: t.doc
- }) : 2 === t.type && 2 === n.type ? this.Cu = this.Cu.insert(e, {
- type: 2 ,
- doc: t.doc
- }) : 2 === t.type && 0 === n.type ? this.Cu = this.Cu.insert(e, {
- type: 0 ,
- doc: t.doc
- }) : 1 === t.type && 0 === n.type ? this.Cu = this.Cu.remove(e) : 1 === t.type && 2 === n.type ? this.Cu = this.Cu.insert(e, {
- type: 1 ,
- doc: n.doc
- }) : 0 === t.type && 1 === n.type ? this.Cu = this.Cu.insert(e, {
- type: 2 ,
- doc: t.doc
- }) :
-
-
-
-
-
-
-
- O() : this.Cu = this.Cu.insert(e, t);
- }
- xu() {
- const t = [];
- return this.Cu.inorderTraversal(((e, n) => {
- t.push(n);
- })), t;
- }
- }
- class Rc {
- constructor(t, e, n, s, i, r, o, u, c) {
- this.query = t, this.docs = e, this.oldDocs = n, this.docChanges = s, this.mutatedKeys = i,
- this.fromCache = r, this.syncStateChanged = o, this.excludesMetadataChanges = u,
- this.hasCachedResults = c;
- }
- static fromInitialDocuments(t, e, n, s, i) {
- const r = [];
- return e.forEach((t => {
- r.push({
- type: 0 ,
- doc: t
- });
- })), new Rc(t, e, Ac.emptySet(e), r, n, s,
- !0,
- !1, i);
- }
- get hasPendingWrites() {
- return !this.mutatedKeys.isEmpty();
- }
- isEqual(t) {
- if (!(this.fromCache === t.fromCache && this.hasCachedResults === t.hasCachedResults && this.syncStateChanged === t.syncStateChanged && this.mutatedKeys.isEqual(t.mutatedKeys) && Zn(this.query, t.query) && this.docs.isEqual(t.docs) && this.oldDocs.isEqual(t.oldDocs))) return !1;
- const e = this.docChanges, n = t.docChanges;
- if (e.length !== n.length) return !1;
- for (let t = 0; t < e.length; t++) if (e[t].type !== n[t].type || !e[t].doc.isEqual(n[t].doc)) return !1;
- return !0;
- }
- }
- class Pc {
- constructor() {
- this.Nu = void 0, this.listeners = [];
- }
- }
- class bc {
- constructor() {
- this.queries = new os((t => ts(t)), Zn), this.onlineState = "Unknown" ,
- this.ku = new Set;
- }
- }
- async function Vc(t, e) {
- const n = L(t), s = e.query;
- let i = !1, r = n.queries.get(s);
- if (r || (i = !0, r = new Pc), i) try {
- r.Nu = await n.onListen(s);
- } catch (t) {
- const n = Ec(t, `Initialization of query '${es(e.query)}' failed`);
- return void e.onError(n);
- }
- if (n.queries.set(s, r), r.listeners.push(e),
-
- e.Mu(n.onlineState), r.Nu) {
- e.$u(r.Nu) && xc(n);
- }
- }
- async function Sc(t, e) {
- const n = L(t), s = e.query;
- let i = !1;
- const r = n.queries.get(s);
- if (r) {
- const t = r.listeners.indexOf(e);
- t >= 0 && (r.listeners.splice(t, 1), i = 0 === r.listeners.length);
- }
- if (i) return n.queries.delete(s), n.onUnlisten(s);
- }
- function Dc(t, e) {
- const n = L(t);
- let s = !1;
- for (const t of e) {
- const e = t.query, i = n.queries.get(e);
- if (i) {
- for (const e of i.listeners) e.$u(t) && (s = !0);
- i.Nu = t;
- }
- }
- s && xc(n);
- }
- function Cc(t, e, n) {
- const s = L(t), i = s.queries.get(e);
- if (i) for (const t of i.listeners) t.onError(n);
-
-
- s.queries.delete(e);
- }
- function xc(t) {
- t.ku.forEach((t => {
- t.next();
- }));
- }
- class Nc {
- constructor(t, e, n) {
- this.query = t, this.Ou = e,
-
- this.Fu = !1, this.Bu = null, this.onlineState = "Unknown" ,
- this.options = n || {};
- }
-
- $u(t) {
- if (!this.options.includeMetadataChanges) {
-
- const e = [];
- for (const n of t.docChanges) 3 !== n.type && e.push(n);
- t = new Rc(t.query, t.docs, t.oldDocs, e, t.mutatedKeys, t.fromCache, t.syncStateChanged,
- !0, t.hasCachedResults);
- }
- let e = !1;
- return this.Fu ? this.Lu(t) && (this.Ou.next(t), e = !0) : this.qu(t, this.onlineState) && (this.Uu(t),
- e = !0), this.Bu = t, e;
- }
- onError(t) {
- this.Ou.error(t);
- }
- Mu(t) {
- this.onlineState = t;
- let e = !1;
- return this.Bu && !this.Fu && this.qu(this.Bu, t) && (this.Uu(this.Bu), e = !0),
- e;
- }
- qu(t, e) {
-
- if (!t.fromCache) return !0;
-
-
- const n = "Offline" !== e;
-
-
- return (!this.options.Ku || !n) && (!t.docs.isEmpty() || t.hasCachedResults || "Offline" === e);
-
-
- }
- Lu(t) {
-
-
-
-
- if (t.docChanges.length > 0) return !0;
- const e = this.Bu && this.Bu.hasPendingWrites !== t.hasPendingWrites;
- return !(!t.syncStateChanged && !e) && !0 === this.options.includeMetadataChanges;
-
-
-
- }
- Uu(t) {
- t = Rc.fromInitialDocuments(t.query, t.docs, t.mutatedKeys, t.fromCache, t.hasCachedResults),
- this.Fu = !0, this.Ou.next(t);
- }
- }
- class kc {
- constructor(t,
- // How many bytes this element takes to store in the bundle.
- e) {
- this.Gu = t, this.byteLength = e;
- }
- Qu() {
- return "metadata" in this.Gu;
- }
- }
- class Mc {
- constructor(t) {
- this.serializer = t;
- }
- rr(t) {
- return Oi(this.serializer, t);
- }
-
- ur(t) {
- return t.metadata.exists ? Ki(this.serializer, t.document, !1) : an.newNoDocument(this.rr(t.metadata.name), this.cr(t.metadata.readTime));
- }
- cr(t) {
- return Ni(t);
- }
- }
- class $c {
- constructor(t, e, n) {
- this.ju = t, this.localStore = e, this.serializer = n,
-
- this.queries = [],
-
- this.documents = [],
-
- this.collectionGroups = new Set, this.progress = Oc(t);
- }
-
- zu(t) {
- this.progress.bytesLoaded += t.byteLength;
- let e = this.progress.documentsLoaded;
- if (t.Gu.namedQuery) this.queries.push(t.Gu.namedQuery); else if (t.Gu.documentMetadata) {
- this.documents.push({
- metadata: t.Gu.documentMetadata
- }), t.Gu.documentMetadata.exists || ++e;
- const n = ut.fromString(t.Gu.documentMetadata.name);
- this.collectionGroups.add(n.get(n.length - 2));
- } else t.Gu.document && (this.documents[this.documents.length - 1].document = t.Gu.document,
- ++e);
- return e !== this.progress.documentsLoaded ? (this.progress.documentsLoaded = e,
- Object.assign({}, this.progress)) : null;
- }
- Wu(t) {
- const e = new Map, n = new Mc(this.serializer);
- for (const s of t) if (s.metadata.queries) {
- const t = n.rr(s.metadata.name);
- for (const n of s.metadata.queries) {
- const s = (e.get(n) || gs()).add(t);
- e.set(n, s);
- }
- }
- return e;
- }
-
- async complete() {
- const t = await mu(this.localStore, new Mc(this.serializer), this.documents, this.ju.id), e = this.Wu(this.documents);
- for (const t of this.queries) await gu(this.localStore, t, e.get(t.name));
- return this.progress.taskState = "Success", {
- progress: this.progress,
- Hu: this.collectionGroups,
- Ju: t
- };
- }
- }
- function Oc(t) {
- return {
- taskState: "Running",
- documentsLoaded: 0,
- bytesLoaded: 0,
- totalDocuments: t.totalDocuments,
- totalBytes: t.totalBytes
- };
- }
- class Fc {
- constructor(t) {
- this.key = t;
- }
- }
- class Bc {
- constructor(t) {
- this.key = t;
- }
- }
- class Lc {
- constructor(t,
- /** Documents included in the remote target */
- e) {
- this.query = t, this.Yu = e, this.Xu = null, this.hasCachedResults = !1,
-
- this.current = !1,
-
- this.Zu = gs(),
-
- this.mutatedKeys = gs(), this.tc = is(t), this.ec = new Ac(this.tc);
- }
-
- get nc() {
- return this.Yu;
- }
-
- sc(t, e) {
- const n = e ? e.ic : new vc, s = e ? e.ec : this.ec;
- let i = e ? e.mutatedKeys : this.mutatedKeys, r = s, o = !1;
-
-
-
-
-
-
-
-
- const u = "F" === this.query.limitType && s.size === this.query.limit ? s.last() : null, c = "L" === this.query.limitType && s.size === this.query.limit ? s.first() : null;
-
- if (t.inorderTraversal(((t, e) => {
- const a = s.get(t), h = ns(this.query, e) ? e : null, l = !!a && this.mutatedKeys.has(a.key), f = !!h && (h.hasLocalMutations ||
-
-
- this.mutatedKeys.has(h.key) && h.hasCommittedMutations);
- let d = !1;
-
- if (a && h) {
- a.data.isEqual(h.data) ? l !== f && (n.track({
- type: 3 ,
- doc: h
- }), d = !0) : this.rc(a, h) || (n.track({
- type: 2 ,
- doc: h
- }), d = !0, (u && this.tc(h, u) > 0 || c && this.tc(h, c) < 0) && (
-
-
-
- o = !0));
- } else !a && h ? (n.track({
- type: 0 ,
- doc: h
- }), d = !0) : a && !h && (n.track({
- type: 1 ,
- doc: a
- }), d = !0, (u || c) && (
-
-
-
- o = !0));
- d && (h ? (r = r.add(h), i = f ? i.add(t) : i.delete(t)) : (r = r.delete(t), i = i.delete(t)));
- })), null !== this.query.limit) for (;r.size > this.query.limit; ) {
- const t = "F" === this.query.limitType ? r.last() : r.first();
- r = r.delete(t.key), i = i.delete(t.key), n.track({
- type: 1 ,
- doc: t
- });
- }
- return {
- ec: r,
- ic: n,
- zi: o,
- mutatedKeys: i
- };
- }
- rc(t, e) {
-
-
-
-
-
-
-
- return t.hasLocalMutations && e.hasCommittedMutations && !e.hasLocalMutations;
- }
-
-
- applyChanges(t, e, n) {
- const s = this.ec;
- this.ec = t.ec, this.mutatedKeys = t.mutatedKeys;
-
- const i = t.ic.xu();
- i.sort(((t, e) => function(t, e) {
- const n = t => {
- switch (t) {
- case 0 :
- return 1;
- case 2 :
- case 3 :
-
-
-
- return 2;
- case 1 :
- return 0;
- default:
- return O();
- }
- };
- return n(t) - n(e);
- }
-
- (t.type, e.type) || this.tc(t.doc, e.doc))), this.oc(n);
- const r = e ? this.uc() : [], o = 0 === this.Zu.size && this.current ? 1 : 0 , u = o !== this.Xu;
- if (this.Xu = o, 0 !== i.length || u) {
- return {
- snapshot: new Rc(this.query, t.ec, s, i, t.mutatedKeys, 0 === o, u,
- !1, !!n && n.resumeToken.approximateByteSize() > 0),
- cc: r
- };
- }
-
- return {
- cc: r
- };
- }
-
- Mu(t) {
- return this.current && "Offline" === t ? (
-
-
-
-
- this.current = !1, this.applyChanges({
- ec: this.ec,
- ic: new vc,
- mutatedKeys: this.mutatedKeys,
- zi: !1
- },
- !1)) : {
- cc: []
- };
- }
-
- ac(t) {
-
- return !this.Yu.has(t) && (
-
- !!this.ec.has(t) && !this.ec.get(t).hasLocalMutations);
- }
-
- oc(t) {
- t && (t.addedDocuments.forEach((t => this.Yu = this.Yu.add(t))), t.modifiedDocuments.forEach((t => {})),
- t.removedDocuments.forEach((t => this.Yu = this.Yu.delete(t))), this.current = t.current);
- }
- uc() {
-
- if (!this.current) return [];
-
-
- const t = this.Zu;
- this.Zu = gs(), this.ec.forEach((t => {
- this.ac(t.key) && (this.Zu = this.Zu.add(t.key));
- }));
-
- const e = [];
- return t.forEach((t => {
- this.Zu.has(t) || e.push(new Bc(t));
- })), this.Zu.forEach((n => {
- t.has(n) || e.push(new Fc(n));
- })), e;
- }
-
-
- hc(t) {
- this.Yu = t.ir, this.Zu = gs();
- const e = this.sc(t.documents);
- return this.applyChanges(e, !0);
- }
-
-
- lc() {
- return Rc.fromInitialDocuments(this.query, this.ec, this.mutatedKeys, 0 === this.Xu, this.hasCachedResults);
- }
- }
- class qc {
- constructor(
- /**
- * The query itself.
- */
- t,
- /**
- * The target number created by the client that is used in the watch
- * stream to identify this query.
- */
- e,
- /**
- * The view is responsible for computing the final merged truth of what
- * docs are in the query. It gets notified of local and remote changes,
- * and applies the query filters and limits to determine the most correct
- * possible results.
- */
- n) {
- this.query = t, this.targetId = e, this.view = n;
- }
- }
- class Uc {
- constructor(t) {
- this.key = t,
-
- this.fc = !1;
- }
- }
- class Kc {
- constructor(t, e, n,
- // PORTING NOTE: Manages state synchronization in multi-tab environments.
- s, i, r) {
- this.localStore = t, this.remoteStore = e, this.eventManager = n, this.sharedClientState = s,
- this.currentUser = i, this.maxConcurrentLimboResolutions = r, this.dc = {}, this.wc = new os((t => ts(t)), Zn),
- this._c = new Map,
-
- this.mc = new Set,
-
- this.gc = new pe(ht.comparator),
-
- this.yc = new Map, this.Ic = new Oo,
-
- this.Tc = {},
-
- this.Ec = new Map, this.Ac = lo.Mn(), this.onlineState = "Unknown" ,
-
-
-
- this.vc = void 0;
- }
- get isPrimaryClient() {
- return !0 === this.vc;
- }
- }
- async function Gc(t, e) {
- const n = pa(t);
- let s, i;
- const r = n.wc.get(e);
- if (r)
-
-
-
-
-
-
- s = r.targetId, n.sharedClientState.addLocalQueryTarget(s), i = r.view.lc(); else {
- const t = await hu(n.localStore, Jn(e)), r = n.sharedClientState.addLocalQueryTarget(t.targetId);
- s = t.targetId, i = await Qc(n, e, s, "current" === r, t.resumeToken), n.isPrimaryClient && Hu(n.remoteStore, t);
- }
- return i;
- }
- async function Qc(t, e, n, s, i) {
-
-
-
- t.Rc = (e, n, s) => async function(t, e, n, s) {
- let i = e.view.sc(n);
- i.zi && (
-
-
-
- i = await fu(t.localStore, e.query,
- !1).then((({documents: t}) => e.view.sc(t, i))));
- const r = s && s.targetChanges.get(e.targetId), o = e.view.applyChanges(i,
- t.isPrimaryClient, r);
- return ia(t, e.targetId, o.cc), o.snapshot;
- }(t, e, n, s);
- const r = await fu(t.localStore, e,
- !0), o = new Lc(e, r.ir), u = o.sc(r.documents), c = gi.createSynthesizedTargetChangeForCurrentChange(n, s && "Offline" !== t.onlineState, i), a = o.applyChanges(u,
- t.isPrimaryClient, c);
- ia(t, n, a.cc);
- const h = new qc(e, n, o);
- return t.wc.set(e, h), t._c.has(n) ? t._c.get(n).push(e) : t._c.set(n, [ e ]), a.snapshot;
- }
- async function jc(t, e) {
- const n = L(t), s = n.wc.get(e), i = n._c.get(s.targetId);
- if (i.length > 1) return n._c.set(s.targetId, i.filter((t => !Zn(t, e)))), void n.wc.delete(e);
-
- if (n.isPrimaryClient) {
-
-
- n.sharedClientState.removeLocalQueryTarget(s.targetId);
- n.sharedClientState.isActiveQueryTarget(s.targetId) || await lu(n.localStore, s.targetId,
- !1).then((() => {
- n.sharedClientState.clearQueryState(s.targetId), Ju(n.remoteStore, s.targetId),
- na(n, s.targetId);
- })).catch(vt);
- } else na(n, s.targetId), await lu(n.localStore, s.targetId,
- !0);
- }
- async function zc(t, e, n) {
- const s = Ia(t);
- try {
- const t = await function(t, e) {
- const n = L(t), s = it.now(), i = e.reduce(((t, e) => t.add(e.key)), gs());
- let r, o;
- return n.persistence.runTransaction("Locally write mutations", "readwrite", (t => {
-
-
-
-
-
-
- let u = cs(), c = gs();
- return n.Zi.getEntries(t, i).next((t => {
- u = t, u.forEach(((t, e) => {
- e.isValidDocument() || (c = c.add(t));
- }));
- })).next((() => n.localDocuments.getOverlayedDocuments(t, u))).next((i => {
- r = i;
-
-
-
-
-
- const o = [];
- for (const t of e) {
- const e = Gs(t, r.get(t.key).overlayedDocument);
- null != e &&
-
-
-
- o.push(new zs(t.key, e, cn(e.value.mapValue), Fs.exists(!0)));
- }
- return n.mutationQueue.addMutationBatch(t, s, o, e);
- })).next((e => {
- o = e;
- const s = e.applyToLocalDocumentSet(r, c);
- return n.documentOverlayCache.saveOverlays(t, e.batchId, s);
- }));
- })).then((() => ({
- batchId: o.batchId,
- changes: ls(r)
- })));
- }(s.localStore, e);
- s.sharedClientState.addPendingMutation(t.batchId), function(t, e, n) {
- let s = t.Tc[t.currentUser.toKey()];
- s || (s = new pe(et));
- s = s.insert(e, n), t.Tc[t.currentUser.toKey()] = s;
- }
-
- (s, t.batchId, n), await ua(s, t.changes), await cc(s.remoteStore);
- } catch (t) {
-
-
- const e = Ec(t, "Failed to persist write");
- n.reject(e);
- }
- }
- async function Wc(t, e) {
- const n = L(t);
- try {
- const t = await uu(n.localStore, e);
-
- e.targetChanges.forEach(((t, e) => {
- const s = n.yc.get(e);
- s && (
-
-
- F(t.addedDocuments.size + t.modifiedDocuments.size + t.removedDocuments.size <= 1),
- t.addedDocuments.size > 0 ? s.fc = !0 : t.modifiedDocuments.size > 0 ? F(s.fc) : t.removedDocuments.size > 0 && (F(s.fc),
- s.fc = !1));
- })), await ua(n, t, e);
- } catch (t) {
- await vt(t);
- }
- }
- function Hc(t, e, n) {
- const s = L(t);
-
-
-
-
- if (s.isPrimaryClient && 0 === n || !s.isPrimaryClient && 1 === n) {
- const t = [];
- s.wc.forEach(((n, s) => {
- const i = s.view.Mu(e);
- i.snapshot && t.push(i.snapshot);
- })), function(t, e) {
- const n = L(t);
- n.onlineState = e;
- let s = !1;
- n.queries.forEach(((t, n) => {
- for (const t of n.listeners)
-
- t.Mu(e) && (s = !0);
- })), s && xc(n);
- }(s.eventManager, e), t.length && s.dc.nu(t), s.onlineState = e, s.isPrimaryClient && s.sharedClientState.setOnlineState(e);
- }
- }
- async function Jc(t, e, n) {
- const s = L(t);
-
- s.sharedClientState.updateQueryState(e, "rejected", n);
- const i = s.yc.get(e), r = i && i.key;
- if (r) {
-
-
-
-
-
-
- let t = new pe(ht.comparator);
-
-
-
- t = t.insert(r, an.newNoDocument(r, rt.min()));
- const n = gs().add(r), i = new mi(rt.min(),
- new Map,
- new pe(et), t, n);
- await Wc(s, i),
-
-
-
-
-
- s.gc = s.gc.remove(r), s.yc.delete(e), oa(s);
- } else await lu(s.localStore, e,
- !1).then((() => na(s, e, n))).catch(vt);
- }
- async function Yc(t, e) {
- const n = L(t), s = e.batch.batchId;
- try {
- const t = await ru(n.localStore, e);
-
-
-
-
- ea(n, s, null), ta(n, s), n.sharedClientState.updateMutationState(s, "acknowledged"),
- await ua(n, t);
- } catch (t) {
- await vt(t);
- }
- }
- async function Xc(t, e, n) {
- const s = L(t);
- try {
- const t = await function(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Reject batch", "readwrite-primary", (t => {
- let s;
- return n.mutationQueue.lookupMutationBatch(t, e).next((e => (F(null !== e), s = e.keys(),
- n.mutationQueue.removeMutationBatch(t, e)))).next((() => n.mutationQueue.performConsistencyCheck(t))).next((() => n.documentOverlayCache.removeOverlaysForBatchId(t, s, e))).next((() => n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(t, s))).next((() => n.localDocuments.getDocuments(t, s)));
- }));
- }
-
- (s.localStore, e);
-
-
-
-
- ea(s, e, n), ta(s, e), s.sharedClientState.updateMutationState(e, "rejected", n),
- await ua(s, t);
- } catch (n) {
- await vt(n);
- }
- }
- async function Zc(t, e) {
- const n = L(t);
- ec(n.remoteStore) || N("SyncEngine", "The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled.");
- try {
- const t = await function(t) {
- const e = L(t);
- return e.persistence.runTransaction("Get highest unacknowledged batch id", "readonly", (t => e.mutationQueue.getHighestUnacknowledgedBatchId(t)));
- }(n.localStore);
- if (-1 === t)
-
- return void e.resolve();
- const s = n.Ec.get(t) || [];
- s.push(e), n.Ec.set(t, s);
- } catch (t) {
- const n = Ec(t, "Initialization of waitForPendingWrites() operation failed");
- e.reject(n);
- }
- }
- function ta(t, e) {
- (t.Ec.get(e) || []).forEach((t => {
- t.resolve();
- })), t.Ec.delete(e);
- }
- function ea(t, e, n) {
- const s = L(t);
- let i = s.Tc[s.currentUser.toKey()];
-
-
- if (i) {
- const t = i.get(e);
- t && (n ? t.reject(n) : t.resolve(), i = i.remove(e)), s.Tc[s.currentUser.toKey()] = i;
- }
- }
- function na(t, e, n = null) {
- t.sharedClientState.removeLocalQueryTarget(e);
- for (const s of t._c.get(e)) t.wc.delete(s), n && t.dc.Pc(s, n);
- if (t._c.delete(e), t.isPrimaryClient) {
- t.Ic.Is(e).forEach((e => {
- t.Ic.containsKey(e) ||
-
- sa(t, e);
- }));
- }
- }
- function sa(t, e) {
- t.mc.delete(e.path.canonicalString());
-
-
- const n = t.gc.get(e);
- null !== n && (Ju(t.remoteStore, n), t.gc = t.gc.remove(e), t.yc.delete(n), oa(t));
- }
- function ia(t, e, n) {
- for (const s of n) if (s instanceof Fc) t.Ic.addReference(s.key, e), ra(t, s); else if (s instanceof Bc) {
- N("SyncEngine", "Document no longer in limbo: " + s.key), t.Ic.removeReference(s.key, e);
- t.Ic.containsKey(s.key) ||
-
- sa(t, s.key);
- } else O();
- }
- function ra(t, e) {
- const n = e.key, s = n.path.canonicalString();
- t.gc.get(n) || t.mc.has(s) || (N("SyncEngine", "New document in limbo: " + n), t.mc.add(s),
- oa(t));
- }
- function oa(t) {
- for (;t.mc.size > 0 && t.gc.size < t.maxConcurrentLimboResolutions; ) {
- const e = t.mc.values().next().value;
- t.mc.delete(e);
- const n = new ht(ut.fromString(e)), s = t.Ac.next();
- t.yc.set(s, new Uc(n)), t.gc = t.gc.insert(n, s), Hu(t.remoteStore, new cr(Jn(Gn(n.path)), s, "TargetPurposeLimboResolution" , Ot.ct));
- }
- }
- async function ua(t, e, n) {
- const s = L(t), i = [], r = [], o = [];
- s.wc.isEmpty() || (s.wc.forEach(((t, u) => {
- o.push(s.Rc(u, e, n).then((t => {
-
- if (
-
-
- (t || n) && s.isPrimaryClient && s.sharedClientState.updateQueryState(u.targetId, (null == t ? void 0 : t.fromCache) ? "not-current" : "current"),
- t) {
- i.push(t);
- const e = tu.Li(u.targetId, t);
- r.push(e);
- }
- })));
- })), await Promise.all(o), s.dc.nu(i), await async function(t, e) {
- const n = L(t);
- try {
- await n.persistence.runTransaction("notifyLocalViewChanges", "readwrite", (t => Rt.forEach(e, (e => Rt.forEach(e.Fi, (s => n.persistence.referenceDelegate.addReference(t, e.targetId, s))).next((() => Rt.forEach(e.Bi, (s => n.persistence.referenceDelegate.removeReference(t, e.targetId, s)))))))));
- } catch (t) {
- if (!Dt(t)) throw t;
-
-
-
-
- N("LocalStore", "Failed to update sequence numbers: " + t);
- }
- for (const t of e) {
- const e = t.targetId;
- if (!t.fromCache) {
- const t = n.Ji.get(e), s = t.snapshotVersion, i = t.withLastLimboFreeSnapshotVersion(s);
-
- n.Ji = n.Ji.insert(e, i);
- }
- }
- }(s.localStore, r));
- }
- async function ca(t, e) {
- const n = L(t);
- if (!n.currentUser.isEqual(e)) {
- N("SyncEngine", "User change. New user:", e.toKey());
- const t = await iu(n.localStore, e);
- n.currentUser = e,
-
- function(t, e) {
- t.Ec.forEach((t => {
- t.forEach((t => {
- t.reject(new U(q.CANCELLED, e));
- }));
- })), t.Ec.clear();
- }(n, "'waitForPendingWrites' promise is rejected due to a user change."),
-
- n.sharedClientState.handleUserChange(e, t.removedBatchIds, t.addedBatchIds), await ua(n, t.er);
- }
- }
- function aa(t, e) {
- const n = L(t), s = n.yc.get(e);
- if (s && s.fc) return gs().add(s.key);
- {
- let t = gs();
- const s = n._c.get(e);
- if (!s) return t;
- for (const e of s) {
- const s = n.wc.get(e);
- t = t.unionWith(s.view.nc);
- }
- return t;
- }
- }
- async function ha(t, e) {
- const n = L(t), s = await fu(n.localStore, e.query,
- !0), i = e.view.hc(s);
- return n.isPrimaryClient && ia(n, e.targetId, i.cc), i;
- }
- async function la(t, e) {
- const n = L(t);
- return wu(n.localStore, e).then((t => ua(n, t)));
- }
- async function fa(t, e, n, s) {
- const i = L(t), r = await function(t, e) {
- const n = L(t), s = L(n.mutationQueue);
- return n.persistence.runTransaction("Lookup mutation documents", "readonly", (t => s.Sn(t, e).next((e => e ? n.localDocuments.getDocuments(t, e) : Rt.resolve(null)))));
- }
-
- (i.localStore, e);
- null !== r ? ("pending" === n ?
-
-
-
- await cc(i.remoteStore) : "acknowledged" === n || "rejected" === n ? (
-
-
- ea(i, e, s || null), ta(i, e), function(t, e) {
- L(L(t).mutationQueue).Cn(e);
- }
-
- (i.localStore, e)) : O(), await ua(i, r)) :
-
-
-
-
-
-
-
- N("SyncEngine", "Cannot apply mutation batch with id: " + e);
- }
- async function da(t, e) {
- const n = L(t);
- if (pa(n), Ia(n), !0 === e && !0 !== n.vc) {
-
-
-
-
-
-
- const t = n.sharedClientState.getAllActiveQueryTargets(), e = await wa(n, t.toArray());
- n.vc = !0, await yc(n.remoteStore, !0);
- for (const t of e) Hu(n.remoteStore, t);
- } else if (!1 === e && !1 !== n.vc) {
- const t = [];
- let e = Promise.resolve();
- n._c.forEach(((s, i) => {
- n.sharedClientState.isLocalQueryTarget(i) ? t.push(i) : e = e.then((() => (na(n, i),
- lu(n.localStore, i,
- !0)))), Ju(n.remoteStore, i);
- })), await e, await wa(n, t),
-
- function(t) {
- const e = L(t);
- e.yc.forEach(((t, n) => {
- Ju(e.remoteStore, n);
- })), e.Ic.Ts(), e.yc = new Map, e.gc = new pe(ht.comparator);
- }
-
-
- (n), n.vc = !1, await yc(n.remoteStore, !1);
- }
- }
- async function wa(t, e, n) {
- const s = L(t), i = [], r = [];
- for (const t of e) {
- let e;
- const n = s._c.get(t);
- if (n && 0 !== n.length) {
-
-
-
-
- e = await hu(s.localStore, Jn(n[0]));
- for (const t of n) {
- const e = s.wc.get(t), n = await ha(s, e);
- n.snapshot && r.push(n.snapshot);
- }
- } else {
-
-
- const n = await du(s.localStore, t);
- e = await hu(s.localStore, n), await Qc(s, _a(n), t,
- !1, e.resumeToken);
- }
- i.push(e);
- }
- return s.dc.nu(r), i;
- }
- function _a(t) {
- return Kn(t.path, t.collectionGroup, t.orderBy, t.filters, t.limit, "F" , t.startAt, t.endAt);
- }
- function ma(t) {
- const e = L(t);
- return L(L(e.localStore).persistence).$i();
- }
- async function ga(t, e, n, s) {
- const i = L(t);
- if (i.vc)
-
-
- return void N("SyncEngine", "Ignoring unexpected query state notification.");
- const r = i._c.get(e);
- if (r && r.length > 0) switch (n) {
- case "current":
- case "not-current":
- {
- const t = await wu(i.localStore, ss(r[0])), s = mi.createSynthesizedRemoteEventForCurrentChange(e, "current" === n, Ve.EMPTY_BYTE_STRING);
- await ua(i, t, s);
- break;
- }
- case "rejected":
- await lu(i.localStore, e,
- !0), na(i, e, s);
- break;
- default:
- O();
- }
- }
- async function ya(t, e, n) {
- const s = pa(t);
- if (s.vc) {
- for (const t of e) {
- if (s._c.has(t)) {
-
- N("SyncEngine", "Adding an already active target " + t);
- continue;
- }
- const e = await du(s.localStore, t), n = await hu(s.localStore, e);
- await Qc(s, _a(e), n.targetId,
- !1, n.resumeToken), Hu(s.remoteStore, n);
- }
- for (const t of n)
-
-
- s._c.has(t) &&
-
- await lu(s.localStore, t,
- !1).then((() => {
- Ju(s.remoteStore, t), na(s, t);
- })).catch(vt);
- }
- }
- function pa(t) {
- const e = L(t);
- return e.remoteStore.remoteSyncer.applyRemoteEvent = Wc.bind(null, e), e.remoteStore.remoteSyncer.getRemoteKeysForTarget = aa.bind(null, e),
- e.remoteStore.remoteSyncer.rejectListen = Jc.bind(null, e), e.dc.nu = Dc.bind(null, e.eventManager),
- e.dc.Pc = Cc.bind(null, e.eventManager), e;
- }
- function Ia(t) {
- const e = L(t);
- return e.remoteStore.remoteSyncer.applySuccessfulWrite = Yc.bind(null, e), e.remoteStore.remoteSyncer.rejectFailedWrite = Xc.bind(null, e),
- e;
- }
- function Ta(t, e, n) {
- const s = L(t);
-
- (
-
- async function(t, e, n) {
- try {
- const s = await e.getMetadata();
- if (await function(t, e) {
- const n = L(t), s = Ni(e.createTime);
- return n.persistence.runTransaction("hasNewerBundle", "readonly", (t => n.qs.getBundleMetadata(t, e.id))).then((t => !!t && t.createTime.compareTo(s) >= 0));
- }
-
- (t.localStore, s)) return await e.close(), n._completeWith(function(t) {
- return {
- taskState: "Success",
- documentsLoaded: t.totalDocuments,
- bytesLoaded: t.totalBytes,
- totalDocuments: t.totalDocuments,
- totalBytes: t.totalBytes
- };
- }(s)), Promise.resolve(new Set);
- n._updateProgress(Oc(s));
- const i = new $c(s, t.localStore, e.serializer);
- let r = await e.bc();
- for (;r; ) {
- const t = await i.zu(r);
- t && n._updateProgress(t), r = await e.bc();
- }
- const o = await i.complete();
- return await ua(t, o.Ju,
- void 0),
-
- await function(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Save bundle", "readwrite", (t => n.qs.saveBundleMetadata(t, e)));
- }
-
- (t.localStore, s), n._completeWith(o.progress), Promise.resolve(o.Hu);
- } catch (t) {
- return M("SyncEngine", `Loading bundle failed with ${t}`), n._failWith(t), Promise.resolve(new Set);
- }
- }
-
-
- )(s, e, n).then((t => {
- s.sharedClientState.notifyBundleLoaded(t);
- }));
- }
- class Ea {
- constructor() {
- this.synchronizeTabs = !1;
- }
- async initialize(t) {
- this.serializer = Fu(t.databaseInfo.databaseId), this.sharedClientState = this.createSharedClientState(t),
- this.persistence = this.createPersistence(t), await this.persistence.start(), this.localStore = this.createLocalStore(t),
- this.gcScheduler = this.createGarbageCollectionScheduler(t, this.localStore), this.indexBackfillerScheduler = this.createIndexBackfillerScheduler(t, this.localStore);
- }
- createGarbageCollectionScheduler(t, e) {
- return null;
- }
- createIndexBackfillerScheduler(t, e) {
- return null;
- }
- createLocalStore(t) {
- return su(this.persistence, new eu, t.initialUser, this.serializer);
- }
- createPersistence(t) {
- return new Ko(Qo.zs, this.serializer);
- }
- createSharedClientState(t) {
- return new bu;
- }
- async terminate() {
- this.gcScheduler && this.gcScheduler.stop(), await this.sharedClientState.shutdown(),
- await this.persistence.shutdown();
- }
- }
- class Aa extends Ea {
- constructor(t) {
- super(), this.cacheSizeBytes = t;
- }
- createGarbageCollectionScheduler(t, e) {
- F(this.persistence.referenceDelegate instanceof jo);
- const n = this.persistence.referenceDelegate.garbageCollector;
- return new po(n, t.asyncQueue, e);
- }
- createPersistence(t) {
- const e = void 0 !== this.cacheSizeBytes ? so.withCacheSize(this.cacheSizeBytes) : so.DEFAULT;
- return new Ko((t => jo.zs(t, e)), this.serializer);
- }
- }
- class va extends Ea {
- constructor(t, e, n) {
- super(), this.Vc = t, this.cacheSizeBytes = e, this.forceOwnership = n, this.synchronizeTabs = !1;
- }
- async initialize(t) {
- await super.initialize(t), await this.Vc.initialize(this, t),
-
- await Ia(this.Vc.syncEngine), await cc(this.Vc.remoteStore),
-
-
- await this.persistence.Ii((() => (this.gcScheduler && !this.gcScheduler.started && this.gcScheduler.start(),
- this.indexBackfillerScheduler && !this.indexBackfillerScheduler.started && this.indexBackfillerScheduler.start(),
- Promise.resolve())));
- }
- createLocalStore(t) {
- return su(this.persistence, new eu, t.initialUser, this.serializer);
- }
- createGarbageCollectionScheduler(t, e) {
- const n = this.persistence.referenceDelegate.garbageCollector;
- return new po(n, t.asyncQueue, e);
- }
- createIndexBackfillerScheduler(t, e) {
- const n = new $t(e, this.persistence);
- return new Mt(t.asyncQueue, n);
- }
- createPersistence(t) {
- const e = Zo(t.databaseInfo.databaseId, t.databaseInfo.persistenceKey), n = void 0 !== this.cacheSizeBytes ? so.withCacheSize(this.cacheSizeBytes) : so.DEFAULT;
- return new Jo(this.synchronizeTabs, e, t.clientId, n, t.asyncQueue, $u(), Ou(), this.serializer, this.sharedClientState, !!this.forceOwnership);
- }
- createSharedClientState(t) {
- return new bu;
- }
- }
- class Ra extends va {
- constructor(t, e) {
- super(t, e, !1), this.Vc = t, this.cacheSizeBytes = e, this.synchronizeTabs = !0;
- }
- async initialize(t) {
- await super.initialize(t);
- const e = this.Vc.syncEngine;
- this.sharedClientState instanceof Pu && (this.sharedClientState.syncEngine = {
- jr: fa.bind(null, e),
- zr: ga.bind(null, e),
- Wr: ya.bind(null, e),
- $i: ma.bind(null, e),
- Qr: la.bind(null, e)
- }, await this.sharedClientState.start()),
-
-
- await this.persistence.Ii((async t => {
- await da(this.Vc.syncEngine, t), this.gcScheduler && (t && !this.gcScheduler.started ? this.gcScheduler.start() : t || this.gcScheduler.stop()),
- this.indexBackfillerScheduler && (t && !this.indexBackfillerScheduler.started ? this.indexBackfillerScheduler.start() : t || this.indexBackfillerScheduler.stop());
- }));
- }
- createSharedClientState(t) {
- const e = $u();
- if (!Pu.D(e)) throw new U(q.UNIMPLEMENTED, "IndexedDB persistence is only available on platforms that support LocalStorage.");
- const n = Zo(t.databaseInfo.databaseId, t.databaseInfo.persistenceKey);
- return new Pu(e, t.asyncQueue, n, t.clientId, t.initialUser);
- }
- }
- class Pa {
- async initialize(t, e) {
- this.localStore || (this.localStore = t.localStore, this.sharedClientState = t.sharedClientState,
- this.datastore = this.createDatastore(e), this.remoteStore = this.createRemoteStore(e),
- this.eventManager = this.createEventManager(e), this.syncEngine = this.createSyncEngine(e,
- !t.synchronizeTabs), this.sharedClientState.onlineStateHandler = t => Hc(this.syncEngine, t, 1 ),
- this.remoteStore.remoteSyncer.handleCredentialChange = ca.bind(null, this.syncEngine),
- await yc(this.remoteStore, this.syncEngine.isPrimaryClient));
- }
- createEventManager(t) {
- return new bc;
- }
- createDatastore(t) {
- const e = Fu(t.databaseInfo.databaseId), n = (s = t.databaseInfo, new Mu(s));
- var s;
- return function(t, e, n, s) {
- return new Ku(t, e, n, s);
- }(t.authCredentials, t.appCheckCredentials, n, e);
- }
- createRemoteStore(t) {
- return e = this.localStore, n = this.datastore, s = t.asyncQueue, i = t => Hc(this.syncEngine, t, 0 ),
- r = Su.D() ? new Su : new Vu, new ju(e, n, s, i, r);
- var e, n, s, i, r;
- }
- createSyncEngine(t, e) {
- return function(t, e, n,
-
- s, i, r, o) {
- const u = new Kc(t, e, n, s, i, r);
- return o && (u.vc = !0), u;
- }(this.localStore, this.remoteStore, this.eventManager, this.sharedClientState, t.initialUser, t.maxConcurrentLimboResolutions, e);
- }
- terminate() {
- return async function(t) {
- const e = L(t);
- N("RemoteStore", "RemoteStore shutting down."), e.vu.add(5 ),
- await Wu(e), e.Pu.shutdown(),
-
-
- e.bu.set("Unknown" );
- }(this.remoteStore);
- }
- }
- function ba(t, e = 10240) {
- let n = 0;
-
-
-
-
- return {
-
- async read() {
- if (n < t.byteLength) {
- const s = {
- value: t.slice(n, n + e),
- done: !1
- };
- return n += e, s;
- }
- return {
- done: !0
- };
- },
- async cancel() {},
- releaseLock() {},
- closed: Promise.resolve()
- };
- }
- class Va {
- constructor(t) {
- this.observer = t,
-
- this.muted = !1;
- }
- next(t) {
- this.observer.next && this.Sc(this.observer.next, t);
- }
- error(t) {
- this.observer.error ? this.Sc(this.observer.error, t) : k("Uncaught Error in snapshot listener:", t.toString());
- }
- Dc() {
- this.muted = !0;
- }
- Sc(t, e) {
- this.muted || setTimeout((() => {
- this.muted || t(e);
- }), 0);
- }
- }
- class Sa {
- constructor(
- /** The reader to read from underlying binary bundle data source. */
- t, e) {
- this.Cc = t, this.serializer = e,
-
- this.metadata = new K,
-
- this.buffer = new Uint8Array, this.xc = new TextDecoder("utf-8"),
-
- this.Nc().then((t => {
- t && t.Qu() ? this.metadata.resolve(t.Gu.metadata) : this.metadata.reject(new Error(`The first element of the bundle is not a metadata, it is\n ${JSON.stringify(null == t ? void 0 : t.Gu)}`));
- }), (t => this.metadata.reject(t)));
- }
- close() {
- return this.Cc.cancel();
- }
- async getMetadata() {
- return this.metadata.promise;
- }
- async bc() {
-
- return await this.getMetadata(), this.Nc();
- }
-
- async Nc() {
- const t = await this.kc();
- if (null === t) return null;
- const e = this.xc.decode(t), n = Number(e);
- isNaN(n) && this.Mc(`length string (${e}) is not valid number`);
- const s = await this.$c(n);
- return new kc(JSON.parse(s), t.length + n);
- }
- Oc() {
- return this.buffer.findIndex((t => t === "{".charCodeAt(0)));
- }
-
- async kc() {
- for (;this.Oc() < 0; ) {
- if (await this.Fc()) break;
- }
-
-
- if (0 === this.buffer.length) return null;
- const t = this.Oc();
-
-
- t < 0 && this.Mc("Reached the end of bundle when a length string is expected.");
- const e = this.buffer.slice(0, t);
-
- return this.buffer = this.buffer.slice(t), e;
- }
-
- async $c(t) {
- for (;this.buffer.length < t; ) {
- await this.Fc() && this.Mc("Reached the end of bundle when more is expected.");
- }
- const e = this.xc.decode(this.buffer.slice(0, t));
-
- return this.buffer = this.buffer.slice(t), e;
- }
- Mc(t) {
-
- throw this.Cc.cancel(), new Error(`Invalid bundle format: ${t}`);
- }
-
- async Fc() {
- const t = await this.Cc.read();
- if (!t.done) {
- const e = new Uint8Array(this.buffer.length + t.value.length);
- e.set(this.buffer), e.set(t.value, this.buffer.length), this.buffer = e;
- }
- return t.done;
- }
- }
- class Da {
- constructor(t) {
- this.datastore = t,
-
- this.readVersions = new Map, this.mutations = [], this.committed = !1,
-
- this.lastWriteError = null,
-
- this.writtenDocs = new Set;
- }
- async lookup(t) {
- if (this.ensureCommitNotCalled(), this.mutations.length > 0) throw new U(q.INVALID_ARGUMENT, "Firestore transactions require all reads to be executed before all writes.");
- const e = await async function(t, e) {
- const n = L(t), s = Li(n.serializer) + "/documents", i = {
- documents: e.map((t => $i(n.serializer, t)))
- }, r = await n.vo("BatchGetDocuments", s, i, e.length), o = new Map;
- r.forEach((t => {
- const e = Gi(n.serializer, t);
- o.set(e.key.toString(), e);
- }));
- const u = [];
- return e.forEach((t => {
- const e = o.get(t.toString());
- F(!!e), u.push(e);
- })), u;
- }(this.datastore, t);
- return e.forEach((t => this.recordVersion(t))), e;
- }
- set(t, e) {
- this.write(e.toMutation(t, this.precondition(t))), this.writtenDocs.add(t.toString());
- }
- update(t, e) {
- try {
- this.write(e.toMutation(t, this.preconditionForUpdate(t)));
- } catch (t) {
- this.lastWriteError = t;
- }
- this.writtenDocs.add(t.toString());
- }
- delete(t) {
- this.write(new Ys(t, this.precondition(t))), this.writtenDocs.add(t.toString());
- }
- async commit() {
- if (this.ensureCommitNotCalled(), this.lastWriteError) throw this.lastWriteError;
- const t = this.readVersions;
-
- this.mutations.forEach((e => {
- t.delete(e.key.toString());
- })),
-
-
- t.forEach(((t, e) => {
- const n = ht.fromPath(e);
- this.mutations.push(new Xs(n, this.precondition(n)));
- })), await async function(t, e) {
- const n = L(t), s = Li(n.serializer) + "/documents", i = {
- writes: e.map((t => ji(n.serializer, t)))
- };
- await n.Io("Commit", s, i);
- }(this.datastore, this.mutations), this.committed = !0;
- }
- recordVersion(t) {
- let e;
- if (t.isFoundDocument()) e = t.version; else {
- if (!t.isNoDocument()) throw O();
-
- e = rt.min();
- }
- const n = this.readVersions.get(t.key.toString());
- if (n) {
- if (!e.isEqual(n))
-
- throw new U(q.ABORTED, "Document version changed between two reads.");
- } else this.readVersions.set(t.key.toString(), e);
- }
-
- precondition(t) {
- const e = this.readVersions.get(t.toString());
- return !this.writtenDocs.has(t.toString()) && e ? e.isEqual(rt.min()) ? Fs.exists(!1) : Fs.updateTime(e) : Fs.none();
- }
-
- preconditionForUpdate(t) {
- const e = this.readVersions.get(t.toString());
-
-
- if (!this.writtenDocs.has(t.toString()) && e) {
- if (e.isEqual(rt.min()))
-
-
-
-
-
-
-
-
-
- throw new U(q.INVALID_ARGUMENT, "Can't update a document that doesn't exist.");
-
- return Fs.updateTime(e);
- }
-
-
- return Fs.exists(!0);
- }
- write(t) {
- this.ensureCommitNotCalled(), this.mutations.push(t);
- }
- ensureCommitNotCalled() {}
- }
- class Ca {
- constructor(t, e, n, s, i) {
- this.asyncQueue = t, this.datastore = e, this.options = n, this.updateFunction = s,
- this.deferred = i, this.Bc = n.maxAttempts, this.qo = new Bu(this.asyncQueue, "transaction_retry" );
- }
- run() {
- this.Bc -= 1, this.Lc();
- }
- Lc() {
- this.qo.No((async () => {
- const t = new Da(this.datastore), e = this.qc(t);
- e && e.then((e => {
- this.asyncQueue.enqueueAndForget((() => t.commit().then((() => {
- this.deferred.resolve(e);
- })).catch((t => {
- this.Uc(t);
- }))));
- })).catch((t => {
- this.Uc(t);
- }));
- }));
- }
- qc(t) {
- try {
- const e = this.updateFunction(t);
- return !Ft(e) && e.catch && e.then ? e : (this.deferred.reject(Error("Transaction callback must return a Promise")),
- null);
- } catch (t) {
-
- return this.deferred.reject(t), null;
- }
- }
- Uc(t) {
- this.Bc > 0 && this.Kc(t) ? (this.Bc -= 1, this.asyncQueue.enqueueAndForget((() => (this.Lc(),
- Promise.resolve())))) : this.deferred.reject(t);
- }
- Kc(t) {
- if ("FirebaseError" === t.name) {
-
-
- const e = t.code;
- return "aborted" === e || "failed-precondition" === e || "already-exists" === e || !oi(e);
- }
- return !1;
- }
- }
- class xa {
- constructor(t, e,
- /**
- * Asynchronous queue responsible for all of our internal processing. When
- * we get incoming work from the user (via public API) or the network
- * (incoming GRPC messages), we should always schedule onto this queue.
- * This ensures all of our work is properly serialized (e.g. we don't
- * start processing a new operation while the previous one is waiting for
- * an async I/O to complete).
- */
- n, s) {
- this.authCredentials = t, this.appCheckCredentials = e, this.asyncQueue = n, this.databaseInfo = s,
- this.user = V.UNAUTHENTICATED, this.clientId = tt.A(), this.authCredentialListener = () => Promise.resolve(),
- this.appCheckCredentialListener = () => Promise.resolve(), this.authCredentials.start(n, (async t => {
- N("FirestoreClient", "Received user=", t.uid), await this.authCredentialListener(t),
- this.user = t;
- })), this.appCheckCredentials.start(n, (t => (N("FirestoreClient", "Received new app check token=", t),
- this.appCheckCredentialListener(t, this.user))));
- }
- async getConfiguration() {
- return {
- asyncQueue: this.asyncQueue,
- databaseInfo: this.databaseInfo,
- clientId: this.clientId,
- authCredentials: this.authCredentials,
- appCheckCredentials: this.appCheckCredentials,
- initialUser: this.user,
- maxConcurrentLimboResolutions: 100
- };
- }
- setCredentialChangeListener(t) {
- this.authCredentialListener = t;
- }
- setAppCheckTokenChangeListener(t) {
- this.appCheckCredentialListener = t;
- }
-
- verifyNotTerminated() {
- if (this.asyncQueue.isShuttingDown) throw new U(q.FAILED_PRECONDITION, "The client has already been terminated.");
- }
- terminate() {
- this.asyncQueue.enterRestrictedMode();
- const t = new K;
- return this.asyncQueue.enqueueAndForgetEvenWhileRestricted((async () => {
- try {
- this._onlineComponents && await this._onlineComponents.terminate(), this._offlineComponents && await this._offlineComponents.terminate(),
-
-
-
- this.authCredentials.shutdown(), this.appCheckCredentials.shutdown(), t.resolve();
- } catch (e) {
- const n = Ec(e, "Failed to shutdown persistence");
- t.reject(n);
- }
- })), t.promise;
- }
- }
- async function Na(t, e) {
- t.asyncQueue.verifyOperationInProgress(), N("FirestoreClient", "Initializing OfflineComponentProvider");
- const n = await t.getConfiguration();
- await e.initialize(n);
- let s = n.initialUser;
- t.setCredentialChangeListener((async t => {
- s.isEqual(t) || (await iu(e.localStore, t), s = t);
- })),
-
-
- e.persistence.setDatabaseDeletedListener((() => t.terminate())), t._offlineComponents = e;
- }
- async function ka(t, e) {
- t.asyncQueue.verifyOperationInProgress();
- const n = await $a(t);
- N("FirestoreClient", "Initializing OnlineComponentProvider");
- const s = await t.getConfiguration();
- await e.initialize(n, s),
-
-
- t.setCredentialChangeListener((t => gc(e.remoteStore, t))), t.setAppCheckTokenChangeListener(((t, n) => gc(e.remoteStore, n))),
- t._onlineComponents = e;
- }
- function Ma(t) {
- return "FirebaseError" === t.name ? t.code === q.FAILED_PRECONDITION || t.code === q.UNIMPLEMENTED : !("undefined" != typeof DOMException && t instanceof DOMException) || (
-
-
-
- 22 === t.code || 20 === t.code ||
-
-
- 11 === t.code);
- }
- async function $a(t) {
- if (!t._offlineComponents) if (t._uninitializedComponentsProvider) {
- N("FirestoreClient", "Using user provided OfflineComponentProvider");
- try {
- await Na(t, t._uninitializedComponentsProvider._offline);
- } catch (e) {
- const n = e;
- if (!Ma(n)) throw n;
- M("Error using user provided cache. Falling back to memory cache: " + n), await Na(t, new Ea);
- }
- } else N("FirestoreClient", "Using default OfflineComponentProvider"), await Na(t, new Ea);
- return t._offlineComponents;
- }
- async function Oa(t) {
- return t._onlineComponents || (t._uninitializedComponentsProvider ? (N("FirestoreClient", "Using user provided OnlineComponentProvider"),
- await ka(t, t._uninitializedComponentsProvider._online)) : (N("FirestoreClient", "Using default OnlineComponentProvider"),
- await ka(t, new Pa))), t._onlineComponents;
- }
- function Fa(t) {
- return $a(t).then((t => t.persistence));
- }
- function Ba(t) {
- return $a(t).then((t => t.localStore));
- }
- function La(t) {
- return Oa(t).then((t => t.remoteStore));
- }
- function qa(t) {
- return Oa(t).then((t => t.syncEngine));
- }
- function Ua(t) {
- return Oa(t).then((t => t.datastore));
- }
- async function Ka(t) {
- const e = await Oa(t), n = e.eventManager;
- return n.onListen = Gc.bind(null, e.syncEngine), n.onUnlisten = jc.bind(null, e.syncEngine),
- n;
- }
- function Ga(t) {
- return t.asyncQueue.enqueue((async () => {
- const e = await Fa(t), n = await La(t);
- return e.setNetworkEnabled(!0), function(t) {
- const e = L(t);
- return e.vu.delete(0 ), zu(e);
- }(n);
- }));
- }
- function Qa(t) {
- return t.asyncQueue.enqueue((async () => {
- const e = await Fa(t), n = await La(t);
- return e.setNetworkEnabled(!1), async function(t) {
- const e = L(t);
- e.vu.add(0 ), await Wu(e),
-
- e.bu.set("Offline" );
- }(n);
- }));
- }
- function ja(t, e) {
- const n = new K;
- return t.asyncQueue.enqueueAndForget((async () => async function(t, e, n) {
- try {
- const s = await function(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("read document", "readonly", (t => n.localDocuments.getDocument(t, e)));
- }(t, e);
- s.isFoundDocument() ? n.resolve(s) : s.isNoDocument() ? n.resolve(null) : n.reject(new U(q.UNAVAILABLE, "Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)"));
- } catch (t) {
- const s = Ec(t, `Failed to get document '${e} from cache`);
- n.reject(s);
- }
- }
-
- (await Ba(t), e, n))), n.promise;
- }
- function za(t, e, n = {}) {
- const s = new K;
- return t.asyncQueue.enqueueAndForget((async () => function(t, e, n, s, i) {
- const r = new Va({
- next: r => {
-
-
- e.enqueueAndForget((() => Sc(t, o)));
- const u = r.docs.has(n);
- !u && r.fromCache ?
-
-
-
-
-
-
-
- i.reject(new U(q.UNAVAILABLE, "Failed to get document because the client is offline.")) : u && r.fromCache && s && "server" === s.source ? i.reject(new U(q.UNAVAILABLE, 'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')) : i.resolve(r);
- },
- error: t => i.reject(t)
- }), o = new Nc(Gn(n.path), r, {
- includeMetadataChanges: !0,
- Ku: !0
- });
- return Vc(t, o);
- }(await Ka(t), t.asyncQueue, e, n, s))), s.promise;
- }
- function Wa(t, e) {
- const n = new K;
- return t.asyncQueue.enqueueAndForget((async () => async function(t, e, n) {
- try {
- const s = await fu(t, e,
- !0), i = new Lc(e, s.ir), r = i.sc(s.documents), o = i.applyChanges(r,
- !1);
- n.resolve(o.snapshot);
- } catch (t) {
- const s = Ec(t, `Failed to execute query '${e} against cache`);
- n.reject(s);
- }
- }
-
- (await Ba(t), e, n))), n.promise;
- }
- function Ha(t, e, n = {}) {
- const s = new K;
- return t.asyncQueue.enqueueAndForget((async () => function(t, e, n, s, i) {
- const r = new Va({
- next: n => {
-
-
- e.enqueueAndForget((() => Sc(t, o))), n.fromCache && "server" === s.source ? i.reject(new U(q.UNAVAILABLE, 'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')) : i.resolve(n);
- },
- error: t => i.reject(t)
- }), o = new Nc(n, r, {
- includeMetadataChanges: !0,
- Ku: !0
- });
- return Vc(t, o);
- }(await Ka(t), t.asyncQueue, e, n, s))), s.promise;
- }
- function Ja(t, e) {
- const n = new Va(e);
- return t.asyncQueue.enqueueAndForget((async () => function(t, e) {
- L(t).ku.add(e),
-
-
- e.next();
- }(await Ka(t), n))), () => {
- n.Dc(), t.asyncQueue.enqueueAndForget((async () => function(t, e) {
- L(t).ku.delete(e);
- }(await Ka(t), n)));
- };
- }
- function Ya(t, e, n, s) {
- const i = function(t, e) {
- let n;
- n = "string" == typeof t ? hi().encode(t) : t;
- return function(t, e) {
- return new Sa(t, e);
- }(function(t, e) {
- if (t instanceof Uint8Array) return ba(t, e);
- if (t instanceof ArrayBuffer) return ba(new Uint8Array(t), e);
- if (t instanceof ReadableStream) return t.getReader();
- throw new Error("Source of `toByteStreamReader` has to be a ArrayBuffer or ReadableStream");
- }(n), e);
- }(n, Fu(e));
- t.asyncQueue.enqueueAndForget((async () => {
- Ta(await qa(t), i, s);
- }));
- }
- function Xa(t, e) {
- return t.asyncQueue.enqueue((async () => function(t, e) {
- const n = L(t);
- return n.persistence.runTransaction("Get named query", "readonly", (t => n.qs.getNamedQuery(t, e)));
- }(await Ba(t), e)));
- }
- function Za(t, e) {
- return t.asyncQueue.enqueue((async () => async function(t, e) {
- const n = L(t), s = n.indexManager, i = [];
- return n.persistence.runTransaction("Configure indexes", "readwrite", (t => s.getFieldIndexes(t).next((n =>
-
-
- function(t, e, n, s, i) {
- t = [ ...t ], e = [ ...e ], t.sort(n), e.sort(n);
- const r = t.length, o = e.length;
- let u = 0, c = 0;
- for (;u < o && c < r; ) {
- const r = n(t[c], e[u]);
- r < 0 ?
-
-
- i(t[c++]) : r > 0 ?
-
-
- s(e[u++]) : (u++, c++);
- }
- for (;u < o; ) s(e[u++]);
- for (;c < r; ) i(t[c++]);
- }(n, e, wt, (e => {
- i.push(s.addFieldIndex(t, e));
- }), (e => {
- i.push(s.deleteFieldIndex(t, e));
- })))).next((() => Rt.waitFor(i)))));
- }
-
-
-
- (await Ba(t), e)));
- }
- function th(t) {
- const e = {};
- return void 0 !== t.timeoutSeconds && (e.timeoutSeconds = t.timeoutSeconds), e;
- }
- const eh = new Map;
- function nh(t, e, n) {
- if (!n) throw new U(q.INVALID_ARGUMENT, `Function ${t}() cannot be called with an empty ${e}.`);
- }
- function sh(t, e, n, s) {
- if (!0 === e && !0 === s) throw new U(q.INVALID_ARGUMENT, `${t} and ${n} cannot be used together.`);
- }
- function ih(t) {
- if (!ht.isDocumentKey(t)) throw new U(q.INVALID_ARGUMENT, `Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`);
- }
- function rh(t) {
- if (ht.isDocumentKey(t)) throw new U(q.INVALID_ARGUMENT, `Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`);
- }
- function oh(t) {
- if (void 0 === t) return "undefined";
- if (null === t) return "null";
- if ("string" == typeof t) return t.length > 20 && (t = `${t.substring(0, 20)}...`),
- JSON.stringify(t);
- if ("number" == typeof t || "boolean" == typeof t) return "" + t;
- if ("object" == typeof t) {
- if (t instanceof Array) return "an array";
- {
- const e =
-
- function(t) {
- if (t.constructor) return t.constructor.name;
- return null;
- }
-
- (t);
- return e ? `a custom ${e} object` : "an object";
- }
- }
- return "function" == typeof t ? "a function" : O();
- }
- function uh(t,
- e) {
- if ("_delegate" in t && (
-
-
- t = t._delegate), !(t instanceof e)) {
- if (e.name === t.constructor.name) throw new U(q.INVALID_ARGUMENT, "Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");
- {
- const n = oh(t);
- throw new U(q.INVALID_ARGUMENT, `Expected type '${e.name}', but it was: ${n}`);
- }
- }
- return t;
- }
- function ch(t, e) {
- if (e <= 0) throw new U(q.INVALID_ARGUMENT, `Function ${t}() requires a positive number, but it was: ${e}.`);
- }
- class ah {
- constructor(t) {
- var e, n;
- if (void 0 === t.host) {
- if (void 0 !== t.ssl) throw new U(q.INVALID_ARGUMENT, "Can't provide ssl option if host option is not set");
- this.host = "firestore.googleapis.com", this.ssl = true;
- } else this.host = t.host, this.ssl = null === (e = t.ssl) || void 0 === e || e;
- if (this.credentials = t.credentials, this.ignoreUndefinedProperties = !!t.ignoreUndefinedProperties,
- this.cache = t.localCache, void 0 === t.cacheSizeBytes) this.cacheSizeBytes = 41943040; else {
- if (-1 !== t.cacheSizeBytes && t.cacheSizeBytes < 1048576) throw new U(q.INVALID_ARGUMENT, "cacheSizeBytes must be at least 1048576");
- this.cacheSizeBytes = t.cacheSizeBytes;
- }
- sh("experimentalForceLongPolling", t.experimentalForceLongPolling, "experimentalAutoDetectLongPolling", t.experimentalAutoDetectLongPolling),
- this.experimentalForceLongPolling = !!t.experimentalForceLongPolling, this.experimentalForceLongPolling ? this.experimentalAutoDetectLongPolling = !1 : void 0 === t.experimentalAutoDetectLongPolling ? this.experimentalAutoDetectLongPolling = true :
-
-
-
- this.experimentalAutoDetectLongPolling = !!t.experimentalAutoDetectLongPolling,
- this.experimentalLongPollingOptions = th(null !== (n = t.experimentalLongPollingOptions) && void 0 !== n ? n : {}),
- function(t) {
- if (void 0 !== t.timeoutSeconds) {
- if (isNaN(t.timeoutSeconds)) throw new U(q.INVALID_ARGUMENT, `invalid long polling timeout: ${t.timeoutSeconds} (must not be NaN)`);
- if (t.timeoutSeconds < 5) throw new U(q.INVALID_ARGUMENT, `invalid long polling timeout: ${t.timeoutSeconds} (minimum allowed value is 5)`);
- if (t.timeoutSeconds > 30) throw new U(q.INVALID_ARGUMENT, `invalid long polling timeout: ${t.timeoutSeconds} (maximum allowed value is 30)`);
- }
- }
-
-
- (this.experimentalLongPollingOptions), this.useFetchStreams = !!t.useFetchStreams;
- }
- isEqual(t) {
- 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,
- n = t.experimentalLongPollingOptions, e.timeoutSeconds === n.timeoutSeconds) && this.ignoreUndefinedProperties === t.ignoreUndefinedProperties && this.useFetchStreams === t.useFetchStreams;
- var e, n;
- }
- }
- class hh {
-
- constructor(t, e, n, s) {
- this._authCredentials = t, this._appCheckCredentials = e, this._databaseId = n,
- this._app = s,
-
- this.type = "firestore-lite", this._persistenceKey = "(lite)", this._settings = new ah({}),
- this._settingsFrozen = !1;
- }
-
- get app() {
- if (!this._app) throw new U(q.FAILED_PRECONDITION, "Firestore was not initialized using the Firebase SDK. 'app' is not available");
- return this._app;
- }
- get _initialized() {
- return this._settingsFrozen;
- }
- get _terminated() {
- return void 0 !== this._terminateTask;
- }
- _setSettings(t) {
- if (this._settingsFrozen) throw new U(q.FAILED_PRECONDITION, "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.");
- this._settings = new ah(t), void 0 !== t.credentials && (this._authCredentials = function(t) {
- if (!t) return new Q;
- switch (t.type) {
- case "firstParty":
- return new H(t.sessionIndex || "0", t.iamToken || null, t.authTokenFactory || null);
- case "provider":
- return t.client;
- default:
- throw new U(q.INVALID_ARGUMENT, "makeAuthCredentialsProvider failed due to invalid credential type");
- }
- }(t.credentials));
- }
- _getSettings() {
- return this._settings;
- }
- _freezeSettings() {
- return this._settingsFrozen = !0, this._settings;
- }
- _delete() {
- return this._terminateTask || (this._terminateTask = this._terminate()), this._terminateTask;
- }
- toJSON() {
- return {
- app: this._app,
- databaseId: this._databaseId,
- settings: this._settings
- };
- }
-
- _terminate() {
-
- return function(t) {
- const e = eh.get(t);
- e && (N("ComponentProvider", "Removing Datastore"), eh.delete(t), e.terminate());
- }(this), Promise.resolve();
- }
- }
- function lh(t, e, n, s = {}) {
- var i;
- const r = (t = uh(t, hh))._getSettings(), o = `${e}:${n}`;
- if ("firestore.googleapis.com" !== r.host && r.host !== o && M("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used."),
- t._setSettings(Object.assign(Object.assign({}, r), {
- host: o,
- ssl: !1
- })), s.mockUserToken) {
- let e, n;
- if ("string" == typeof s.mockUserToken) e = s.mockUserToken, n = V.MOCK_USER; else {
-
-
- e = createMockUserToken(s.mockUserToken, null === (i = t._app) || void 0 === i ? void 0 : i.options.projectId);
- const r = s.mockUserToken.sub || s.mockUserToken.user_id;
- if (!r) throw new U(q.INVALID_ARGUMENT, "mockUserToken must contain 'sub' or 'user_id' field!");
- n = new V(r);
- }
- t._authCredentials = new j(new G(e, n));
- }
- }
- class fh {
-
- constructor(t,
- /**
- * If provided, the `FirestoreDataConverter` associated with this instance.
- */
- e, n) {
- this.converter = e, this._key = n,
-
- this.type = "document", this.firestore = t;
- }
- get _path() {
- return this._key.path;
- }
-
- get id() {
- return this._key.path.lastSegment();
- }
-
- get path() {
- return this._key.path.canonicalString();
- }
-
- get parent() {
- return new wh(this.firestore, this.converter, this._key.path.popLast());
- }
- withConverter(t) {
- return new fh(this.firestore, t, this._key);
- }
- }
- class dh {
-
-
- constructor(t,
- /**
- * If provided, the `FirestoreDataConverter` associated with this instance.
- */
- e, n) {
- this.converter = e, this._query = n,
-
- this.type = "query", this.firestore = t;
- }
- withConverter(t) {
- return new dh(this.firestore, t, this._query);
- }
- }
- class wh extends dh {
-
- constructor(t, e, n) {
- super(t, e, Gn(n)), this._path = n,
-
- this.type = "collection";
- }
- get id() {
- return this._query.path.lastSegment();
- }
-
- get path() {
- return this._query.path.canonicalString();
- }
-
- get parent() {
- const t = this._path.popLast();
- return t.isEmpty() ? null : new fh(this.firestore,
- null, new ht(t));
- }
- withConverter(t) {
- return new wh(this.firestore, t, this._path);
- }
- }
- function _h(t, e, ...n) {
- if (t = getModularInstance(t), nh("collection", "path", e), t instanceof hh) {
- const s = ut.fromString(e, ...n);
- return rh(s), new wh(t, null, s);
- }
- {
- if (!(t instanceof fh || t instanceof wh)) throw new U(q.INVALID_ARGUMENT, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
- const s = t._path.child(ut.fromString(e, ...n));
- return rh(s), new wh(t.firestore,
- null, s);
- }
- }
- function mh(t, e) {
- if (t = uh(t, hh), nh("collectionGroup", "collection id", e), e.indexOf("/") >= 0) throw new U(q.INVALID_ARGUMENT, `Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);
- return new dh(t,
- null, function(t) {
- return new Un(ut.emptyPath(), t);
- }(e));
- }
- function gh(t, e, ...n) {
- if (t = getModularInstance(t),
-
-
- 1 === arguments.length && (e = tt.A()), nh("doc", "path", e), t instanceof hh) {
- const s = ut.fromString(e, ...n);
- return ih(s), new fh(t,
- null, new ht(s));
- }
- {
- if (!(t instanceof fh || t instanceof wh)) throw new U(q.INVALID_ARGUMENT, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
- const s = t._path.child(ut.fromString(e, ...n));
- return ih(s), new fh(t.firestore, t instanceof wh ? t.converter : null, new ht(s));
- }
- }
- function yh(t, e) {
- return t = getModularInstance(t), e = getModularInstance(e), (t instanceof fh || t instanceof wh) && (e instanceof fh || e instanceof wh) && (t.firestore === e.firestore && t.path === e.path && t.converter === e.converter);
- }
- function ph(t, e) {
- return t = getModularInstance(t), e = getModularInstance(e), t instanceof dh && e instanceof dh && (t.firestore === e.firestore && Zn(t._query, e._query) && t.converter === e.converter);
- }
- class Ih {
- constructor() {
-
- this.Gc = Promise.resolve(),
-
-
- this.Qc = [],
-
-
- this.jc = !1,
-
-
- this.zc = [],
-
- this.Wc = null,
-
-
- this.Hc = !1,
-
- this.Jc = !1,
-
- this.Yc = [],
-
- this.qo = new Bu(this, "async_queue_retry" ),
-
-
-
- this.Xc = () => {
- const t = Ou();
- t && N("AsyncQueue", "Visibility state changed to " + t.visibilityState), this.qo.Mo();
- };
- const t = Ou();
- t && "function" == typeof t.addEventListener && t.addEventListener("visibilitychange", this.Xc);
- }
- get isShuttingDown() {
- return this.jc;
- }
-
- enqueueAndForget(t) {
-
- this.enqueue(t);
- }
- enqueueAndForgetEvenWhileRestricted(t) {
- this.Zc(),
-
- this.ta(t);
- }
- enterRestrictedMode(t) {
- if (!this.jc) {
- this.jc = !0, this.Jc = t || !1;
- const e = Ou();
- e && "function" == typeof e.removeEventListener && e.removeEventListener("visibilitychange", this.Xc);
- }
- }
- enqueue(t) {
- if (this.Zc(), this.jc)
-
- return new Promise((() => {}));
-
-
-
- const e = new K;
- return this.ta((() => this.jc && this.Jc ? Promise.resolve() : (t().then(e.resolve, e.reject),
- e.promise))).then((() => e.promise));
- }
- enqueueRetryable(t) {
- this.enqueueAndForget((() => (this.Qc.push(t), this.ea())));
- }
-
- async ea() {
- if (0 !== this.Qc.length) {
- try {
- await this.Qc[0](), this.Qc.shift(), this.qo.reset();
- } catch (t) {
- if (!Dt(t)) throw t;
-
- N("AsyncQueue", "Operation failed with retryable error: " + t);
- }
- this.Qc.length > 0 &&
-
-
-
-
-
-
-
-
-
-
- this.qo.No((() => this.ea()));
- }
- }
- ta(t) {
- const e = this.Gc.then((() => (this.Hc = !0, t().catch((t => {
- this.Wc = t, this.Hc = !1;
- const e =
-
- function(t) {
- let e = t.message || "";
- t.stack && (e = t.stack.includes(t.message) ? t.stack : t.message + "\n" + t.stack);
- return e;
- }
-
- (t);
-
-
-
- throw k("INTERNAL UNHANDLED ERROR: ", e), t;
- })).then((t => (this.Hc = !1, t))))));
- return this.Gc = e, e;
- }
- enqueueAfterDelay(t, e, n) {
- this.Zc(),
-
- this.Yc.indexOf(t) > -1 && (e = 0);
- const s = Tc.createAndSchedule(this, t, e, n, (t => this.na(t)));
- return this.zc.push(s), s;
- }
- Zc() {
- this.Wc && O();
- }
- verifyOperationInProgress() {}
-
- async sa() {
-
-
-
-
- let t;
- do {
- t = this.Gc, await t;
- } while (t !== this.Gc);
- }
-
- ia(t) {
- for (const e of this.zc) if (e.timerId === t) return !0;
- return !1;
- }
-
- ra(t) {
-
- return this.sa().then((() => {
-
- this.zc.sort(((t, e) => t.targetTimeMs - e.targetTimeMs));
- for (const e of this.zc) if (e.skipDelay(), "all" !== t && e.timerId === t) break;
- return this.sa();
- }));
- }
-
- oa(t) {
- this.Yc.push(t);
- }
- na(t) {
-
- const e = this.zc.indexOf(t);
- this.zc.splice(e, 1);
- }
- }
- function Th(t) {
-
- return function(t, e) {
- if ("object" != typeof t || null === t) return !1;
- const n = t;
- for (const t of e) if (t in n && "function" == typeof n[t]) return !0;
- return !1;
- }
-
-
- (t, [ "next", "error", "complete" ]);
- }
- class Eh {
- constructor() {
- this._progressObserver = {}, this._taskCompletionResolver = new K, this._lastProgress = {
- taskState: "Running",
- totalBytes: 0,
- totalDocuments: 0,
- bytesLoaded: 0,
- documentsLoaded: 0
- };
- }
-
- onProgress(t, e, n) {
- this._progressObserver = {
- next: t,
- error: e,
- complete: n
- };
- }
-
- catch(t) {
- return this._taskCompletionResolver.promise.catch(t);
- }
-
- then(t, e) {
- return this._taskCompletionResolver.promise.then(t, e);
- }
-
- _completeWith(t) {
- this._updateProgress(t), this._progressObserver.complete && this._progressObserver.complete(),
- this._taskCompletionResolver.resolve(t);
- }
-
- _failWith(t) {
- this._lastProgress.taskState = "Error", this._progressObserver.next && this._progressObserver.next(this._lastProgress),
- this._progressObserver.error && this._progressObserver.error(t), this._taskCompletionResolver.reject(t);
- }
-
- _updateProgress(t) {
- this._lastProgress = t, this._progressObserver.next && this._progressObserver.next(t);
- }
- }
- const Ah = -1;
- class vh extends hh {
-
- constructor(t, e, n, s) {
- super(t, e, n, s),
-
- this.type = "firestore", this._queue = new Ih, this._persistenceKey = (null == s ? void 0 : s.name) || "[DEFAULT]";
- }
- _terminate() {
- return this._firestoreClient ||
-
-
- Vh(this), this._firestoreClient.terminate();
- }
- }
- function Rh(t, e, n) {
- n || (n = "(default)");
- const s = _getProvider(t, "firestore");
- if (s.isInitialized(n)) {
- const t = s.getImmediate({
- identifier: n
- }), i = s.getOptions(n);
- if (deepEqual(i, e)) return t;
- throw new U(q.FAILED_PRECONDITION, "initializeFirestore() has already been called with different options. To avoid this error, call initializeFirestore() with the same options as when it was originally called, or call getFirestore() to return the already initialized instance.");
- }
- if (void 0 !== e.cacheSizeBytes && void 0 !== e.localCache) throw new U(q.INVALID_ARGUMENT, "cache and cacheSizeBytes cannot be specified at the same time as cacheSizeBytes willbe deprecated. Instead, specify the cache size in the cache object");
- if (void 0 !== e.cacheSizeBytes && -1 !== e.cacheSizeBytes && e.cacheSizeBytes < 1048576) throw new U(q.INVALID_ARGUMENT, "cacheSizeBytes must be at least 1048576");
- return s.initialize({
- options: e,
- instanceIdentifier: n
- });
- }
- function Ph(e, n) {
- const s = "object" == typeof e ? e : getApp(), i = "string" == typeof e ? e : n || "(default)", r = _getProvider(s, "firestore").getImmediate({
- identifier: i
- });
- if (!r._initialized) {
- const t = getDefaultEmulatorHostnameAndPort("firestore");
- t && lh(r, ...t);
- }
- return r;
- }
- function bh(t) {
- return t._firestoreClient || Vh(t), t._firestoreClient.verifyNotTerminated(), t._firestoreClient;
- }
- function Vh(t) {
- var e, n, s;
- const i = t._freezeSettings(), r = function(t, e, n, s) {
- return new $e(t, e, n, s.host, s.ssl, s.experimentalForceLongPolling, s.experimentalAutoDetectLongPolling, th(s.experimentalLongPollingOptions), s.useFetchStreams);
- }(t._databaseId, (null === (e = t._app) || void 0 === e ? void 0 : e.options.appId) || "", t._persistenceKey, i);
- t._firestoreClient = new xa(t._authCredentials, t._appCheckCredentials, t._queue, r),
- (null === (n = i.cache) || void 0 === n ? void 0 : n._offlineComponentProvider) && (null === (s = i.cache) || void 0 === s ? void 0 : s._onlineComponentProvider) && (t._firestoreClient._uninitializedComponentsProvider = {
- _offlineKind: i.cache.kind,
- _offline: i.cache._offlineComponentProvider,
- _online: i.cache._onlineComponentProvider
- });
- }
- function Sh(t, e) {
- Bh(t = uh(t, vh));
- const n = bh(t);
- if (n._uninitializedComponentsProvider) throw new U(q.FAILED_PRECONDITION, "SDK cache is already specified.");
- M("enableIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");
- const s = t._freezeSettings(), i = new Pa;
- return Ch(n, i, new va(i, s.cacheSizeBytes, null == e ? void 0 : e.forceOwnership));
- }
- function Dh(t) {
- Bh(t = uh(t, vh));
- const e = bh(t);
- if (e._uninitializedComponentsProvider) throw new U(q.FAILED_PRECONDITION, "SDK cache is already specified.");
- M("enableMultiTabIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");
- const n = t._freezeSettings(), s = new Pa;
- return Ch(e, s, new Ra(s, n.cacheSizeBytes));
- }
- function Ch(t, e, n) {
- const s = new K;
- return t.asyncQueue.enqueue((async () => {
- try {
- await Na(t, n), await ka(t, e), s.resolve();
- } catch (t) {
- const e = t;
- if (!Ma(e)) throw e;
- M("Error enabling indexeddb cache. Falling back to memory cache: " + e), s.reject(e);
- }
- })).then((() => s.promise));
- }
- function xh(t) {
- if (t._initialized && !t._terminated) throw new U(q.FAILED_PRECONDITION, "Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");
- const e = new K;
- return t._queue.enqueueAndForgetEvenWhileRestricted((async () => {
- try {
- await async function(t) {
- if (!bt.D()) return Promise.resolve();
- const e = t + "main";
- await bt.delete(e);
- }(Zo(t._databaseId, t._persistenceKey)), e.resolve();
- } catch (t) {
- e.reject(t);
- }
- })), e.promise;
- }
- function Nh(t) {
- return function(t) {
- const e = new K;
- return t.asyncQueue.enqueueAndForget((async () => Zc(await qa(t), e))), e.promise;
- }(bh(t = uh(t, vh)));
- }
- function kh(t) {
- return Ga(bh(t = uh(t, vh)));
- }
- function Mh(t) {
- return Qa(bh(t = uh(t, vh)));
- }
- function $h(t) {
- return _removeServiceInstance(t.app, "firestore", t._databaseId.database), t._delete();
- }
- function Oh(t, e) {
- const n = bh(t = uh(t, vh)), s = new Eh;
- return Ya(n, t._databaseId, e, s), s;
- }
- function Fh(t, e) {
- return Xa(bh(t = uh(t, vh)), e).then((e => e ? new dh(t, null, e.query) : null));
- }
- function Bh(t) {
- if (t._initialized || t._terminated) throw new U(q.FAILED_PRECONDITION, "Firestore has already been started and persistence can no longer be enabled. You can only enable persistence before calling any other methods on a Firestore object.");
- }
- class Lh {
-
- constructor(
- // TODO (sum/avg) make aggregateType public when the feature is supported
- t = "count", e) {
- this._aggregateType = t, this._internalFieldPath = e,
-
- this.type = "AggregateField";
- }
- }
- class qh {
-
- constructor(t, e, n) {
- this._userDataWriter = e, this._data = n,
-
- this.type = "AggregateQuerySnapshot", this.query = t;
- }
-
- data() {
- return this._userDataWriter.convertObjectMap(this._data);
- }
- }
- class Uh {
-
- constructor(t) {
- this._byteString = t;
- }
-
- static fromBase64String(t) {
- try {
- return new Uh(Ve.fromBase64String(t));
- } catch (t) {
- throw new U(q.INVALID_ARGUMENT, "Failed to construct data from Base64 string: " + t);
- }
- }
-
- static fromUint8Array(t) {
- return new Uh(Ve.fromUint8Array(t));
- }
-
- toBase64() {
- return this._byteString.toBase64();
- }
-
- toUint8Array() {
- return this._byteString.toUint8Array();
- }
-
- toString() {
- return "Bytes(base64: " + this.toBase64() + ")";
- }
-
- isEqual(t) {
- return this._byteString.isEqual(t._byteString);
- }
- }
- class Kh {
-
- constructor(...t) {
- for (let e = 0; e < t.length; ++e) if (0 === t[e].length) throw new U(q.INVALID_ARGUMENT, "Invalid field name at argument $(i + 1). Field names must not be empty.");
- this._internalPath = new at(t);
- }
-
- isEqual(t) {
- return this._internalPath.isEqual(t._internalPath);
- }
- }
- function Gh() {
- return new Kh("__name__");
- }
- class Qh {
-
- constructor(t) {
- this._methodName = t;
- }
- }
- class jh {
-
- constructor(t, e) {
- if (!isFinite(t) || t < -90 || t > 90) throw new U(q.INVALID_ARGUMENT, "Latitude must be a number between -90 and 90, but was: " + t);
- if (!isFinite(e) || e < -180 || e > 180) throw new U(q.INVALID_ARGUMENT, "Longitude must be a number between -180 and 180, but was: " + e);
- this._lat = t, this._long = e;
- }
-
- get latitude() {
- return this._lat;
- }
-
- get longitude() {
- return this._long;
- }
-
- isEqual(t) {
- return this._lat === t._lat && this._long === t._long;
- }
- toJSON() {
- return {
- latitude: this._lat,
- longitude: this._long
- };
- }
-
- _compareTo(t) {
- return et(this._lat, t._lat) || et(this._long, t._long);
- }
- }
- const zh = /^__.*__$/;
- class Wh {
- constructor(t, e, n) {
- this.data = t, this.fieldMask = e, this.fieldTransforms = n;
- }
- toMutation(t, e) {
- return null !== this.fieldMask ? new zs(t, this.data, this.fieldMask, e, this.fieldTransforms) : new js(t, this.data, e, this.fieldTransforms);
- }
- }
- class Hh {
- constructor(t,
- // The fieldMask does not include document transforms.
- e, n) {
- this.data = t, this.fieldMask = e, this.fieldTransforms = n;
- }
- toMutation(t, e) {
- return new zs(t, this.data, this.fieldMask, e, this.fieldTransforms);
- }
- }
- function Jh(t) {
- switch (t) {
- case 0 :
-
- case 2 :
-
- case 1 :
- return !0;
- case 3 :
- case 4 :
- return !1;
- default:
- throw O();
- }
- }
- class Yh {
-
- constructor(t, e, n, s, i, r) {
- this.settings = t, this.databaseId = e, this.serializer = n, this.ignoreUndefinedProperties = s,
-
-
- void 0 === i && this.ua(), this.fieldTransforms = i || [], this.fieldMask = r || [];
- }
- get path() {
- return this.settings.path;
- }
- get ca() {
- return this.settings.ca;
- }
- aa(t) {
- return new Yh(Object.assign(Object.assign({}, this.settings), t), this.databaseId, this.serializer, this.ignoreUndefinedProperties, this.fieldTransforms, this.fieldMask);
- }
- ha(t) {
- var e;
- const n = null === (e = this.path) || void 0 === e ? void 0 : e.child(t), s = this.aa({
- path: n,
- la: !1
- });
- return s.fa(t), s;
- }
- da(t) {
- var e;
- const n = null === (e = this.path) || void 0 === e ? void 0 : e.child(t), s = this.aa({
- path: n,
- la: !1
- });
- return s.ua(), s;
- }
- wa(t) {
-
-
- return this.aa({
- path: void 0,
- la: !0
- });
- }
- _a(t) {
- return gl(t, this.settings.methodName, this.settings.ma || !1, this.path, this.settings.ga);
- }
- contains(t) {
- return void 0 !== this.fieldMask.find((e => t.isPrefixOf(e))) || void 0 !== this.fieldTransforms.find((e => t.isPrefixOf(e.field)));
- }
- ua() {
-
-
- if (this.path) for (let t = 0; t < this.path.length; t++) this.fa(this.path.get(t));
- }
- fa(t) {
- if (0 === t.length) throw this._a("Document fields must not be empty");
- if (Jh(this.ca) && zh.test(t)) throw this._a('Document fields cannot begin and end with "__"');
- }
- }
- class Xh {
- constructor(t, e, n) {
- this.databaseId = t, this.ignoreUndefinedProperties = e, this.serializer = n || Fu(t);
- }
- ya(t, e, n, s = !1) {
- return new Yh({
- ca: t,
- methodName: e,
- ga: n,
- path: at.emptyPath(),
- la: !1,
- ma: s
- }, this.databaseId, this.serializer, this.ignoreUndefinedProperties);
- }
- }
- function Zh(t) {
- const e = t._freezeSettings(), n = Fu(t._databaseId);
- return new Xh(t._databaseId, !!e.ignoreUndefinedProperties, n);
- }
- function tl(t, e, n, s, i, r = {}) {
- const o = t.ya(r.merge || r.mergeFields ? 2 : 0 , e, n, i);
- dl("Data must be an object, but it was:", o, s);
- const u = ll(s, o);
- let c, a;
- if (r.merge) c = new Re(o.fieldMask), a = o.fieldTransforms; else if (r.mergeFields) {
- const t = [];
- for (const s of r.mergeFields) {
- const i = wl(e, s, n);
- if (!o.contains(i)) throw new U(q.INVALID_ARGUMENT, `Field '${i}' is specified in your field mask but missing from your input data.`);
- yl(t, i) || t.push(i);
- }
- c = new Re(t), a = o.fieldTransforms.filter((t => c.covers(t.field)));
- } else c = null, a = o.fieldTransforms;
- return new Wh(new un(u), c, a);
- }
- class el extends Qh {
- _toFieldTransform(t) {
- if (2 !== t.ca) throw 1 === t.ca ? t._a(`${this._methodName}() can only appear at the top level of your update data`) : t._a(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);
-
-
- return t.fieldMask.push(t.path), null;
- }
- isEqual(t) {
- return t instanceof el;
- }
- }
- function nl(t, e, n) {
- return new Yh({
- ca: 3 ,
- ga: e.settings.ga,
- methodName: t._methodName,
- la: n
- }, e.databaseId, e.serializer, e.ignoreUndefinedProperties);
- }
- class sl extends Qh {
- _toFieldTransform(t) {
- return new Ms(t.path, new bs);
- }
- isEqual(t) {
- return t instanceof sl;
- }
- }
- class il extends Qh {
- constructor(t, e) {
- super(t), this.pa = e;
- }
- _toFieldTransform(t) {
- const e = nl(this, t,
- !0), n = this.pa.map((t => hl(t, e))), s = new Vs(n);
- return new Ms(t.path, s);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- class rl extends Qh {
- constructor(t, e) {
- super(t), this.pa = e;
- }
- _toFieldTransform(t) {
- const e = nl(this, t,
- !0), n = this.pa.map((t => hl(t, e))), s = new Ds(n);
- return new Ms(t.path, s);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- class ol extends Qh {
- constructor(t, e) {
- super(t), this.Ia = e;
- }
- _toFieldTransform(t) {
- const e = new xs(t.serializer, Es(t.serializer, this.Ia));
- return new Ms(t.path, e);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- function ul(t, e, n, s) {
- const i = t.ya(1 , e, n);
- dl("Data must be an object, but it was:", i, s);
- const r = [], o = un.empty();
- ge(s, ((t, s) => {
- const u = ml(e, t, n);
-
-
- s = getModularInstance(s);
- const c = i.da(u);
- if (s instanceof el)
-
- r.push(u); else {
- const t = hl(s, c);
- null != t && (r.push(u), o.set(u, t));
- }
- }));
- const u = new Re(r);
- return new Hh(o, u, i.fieldTransforms);
- }
- function cl(t, e, n, s, i, r) {
- const o = t.ya(1 , e, n), u = [ wl(e, s, n) ], c = [ i ];
- if (r.length % 2 != 0) throw new U(q.INVALID_ARGUMENT, `Function ${e}() needs to be called with an even number of arguments that alternate between field names and values.`);
- for (let t = 0; t < r.length; t += 2) u.push(wl(e, r[t])), c.push(r[t + 1]);
- const a = [], h = un.empty();
-
-
- for (let t = u.length - 1; t >= 0; --t) if (!yl(a, u[t])) {
- const e = u[t];
- let n = c[t];
-
-
- n = getModularInstance(n);
- const s = o.da(e);
- if (n instanceof el)
-
- a.push(e); else {
- const t = hl(n, s);
- null != t && (a.push(e), h.set(e, t));
- }
- }
- const l = new Re(a);
- return new Hh(h, l, o.fieldTransforms);
- }
- function al(t, e, n, s = !1) {
- return hl(n, t.ya(s ? 4 : 3 , e));
- }
- function hl(t, e) {
- if (fl(
-
-
- t = getModularInstance(t))) return dl("Unsupported field value:", e, t), ll(t, e);
- if (t instanceof Qh)
-
-
-
-
-
-
- return function(t, e) {
-
- if (!Jh(e.ca)) throw e._a(`${t._methodName}() can only be used with update() and set()`);
- if (!e.path) throw e._a(`${t._methodName}() is not currently supported inside arrays`);
- const n = t._toFieldTransform(e);
- n && e.fieldTransforms.push(n);
- }
-
- (t, e), null;
- if (void 0 === t && e.ignoreUndefinedProperties)
-
-
-
- return null;
- if (
-
-
- e.path && e.fieldMask.push(e.path), t instanceof Array) {
-
-
-
-
-
-
- if (e.settings.la && 4 !== e.ca) throw e._a("Nested arrays are not supported");
- return function(t, e) {
- const n = [];
- let s = 0;
- for (const i of t) {
- let t = hl(i, e.wa(s));
- null == t && (
-
-
- t = {
- nullValue: "NULL_VALUE"
- }), n.push(t), s++;
- }
- return {
- arrayValue: {
- values: n
- }
- };
- }(t, e);
- }
- return function(t, e) {
- if (null === (t = getModularInstance(t))) return {
- nullValue: "NULL_VALUE"
- };
- if ("number" == typeof t) return Es(e.serializer, t);
- if ("boolean" == typeof t) return {
- booleanValue: t
- };
- if ("string" == typeof t) return {
- stringValue: t
- };
- if (t instanceof Date) {
- const n = it.fromDate(t);
- return {
- timestampValue: Di(e.serializer, n)
- };
- }
- if (t instanceof it) {
-
-
-
- const n = new it(t.seconds, 1e3 * Math.floor(t.nanoseconds / 1e3));
- return {
- timestampValue: Di(e.serializer, n)
- };
- }
- if (t instanceof jh) return {
- geoPointValue: {
- latitude: t.latitude,
- longitude: t.longitude
- }
- };
- if (t instanceof Uh) return {
- bytesValue: Ci(e.serializer, t._byteString)
- };
- if (t instanceof fh) {
- const n = e.databaseId, s = t.firestore._databaseId;
- if (!s.isEqual(n)) throw e._a(`Document reference is for database ${s.projectId}/${s.database} but should be for database ${n.projectId}/${n.database}`);
- return {
- referenceValue: ki(t.firestore._databaseId || e.databaseId, t._key.path)
- };
- }
- throw e._a(`Unsupported field value: ${oh(t)}`);
- }
-
- (t, e);
- }
- function ll(t, e) {
- const n = {};
- return ye(t) ?
-
-
- e.path && e.path.length > 0 && e.fieldMask.push(e.path) : ge(t, ((t, s) => {
- const i = hl(s, e.ha(t));
- null != i && (n[t] = i);
- })), {
- mapValue: {
- fields: n
- }
- };
- }
- function fl(t) {
- return !("object" != typeof t || null === t || t instanceof Array || t instanceof Date || t instanceof it || t instanceof jh || t instanceof Uh || t instanceof fh || t instanceof Qh);
- }
- function dl(t, e, n) {
- if (!fl(n) || !function(t) {
- return "object" == typeof t && null !== t && (Object.getPrototypeOf(t) === Object.prototype || null === Object.getPrototypeOf(t));
- }(n)) {
- const s = oh(n);
- throw "an object" === s ? e._a(t + " a custom object") : e._a(t + " " + s);
- }
- }
- function wl(t, e, n) {
- if ((
-
-
- e = getModularInstance(e)) instanceof Kh) return e._internalPath;
- if ("string" == typeof e) return ml(t, e);
- throw gl("Field path arguments must be of type string or ", t,
- !1,
- void 0, n);
- }
- const _l = new RegExp("[~\\*/\\[\\]]");
- function ml(t, e, n) {
- if (e.search(_l) >= 0) throw gl(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`, t,
- !1,
- void 0, n);
- try {
- return new Kh(...e.split("."))._internalPath;
- } catch (s) {
- throw gl(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`, t,
- !1,
- void 0, n);
- }
- }
- function gl(t, e, n, s, i) {
- const r = s && !s.isEmpty(), o = void 0 !== i;
- let u = `Function ${e}() called with invalid data`;
- n && (u += " (via `toFirestore()`)"), u += ". ";
- let c = "";
- return (r || o) && (c += " (found", r && (c += ` in field ${s}`), o && (c += ` in document ${i}`),
- c += ")"), new U(q.INVALID_ARGUMENT, u + t + c);
- }
- function yl(t, e) {
- return t.some((t => t.isEqual(e)));
- }
- class pl {
-
-
-
-
-
- constructor(t, e, n, s, i) {
- this._firestore = t, this._userDataWriter = e, this._key = n, this._document = s,
- this._converter = i;
- }
- get id() {
- return this._key.path.lastSegment();
- }
-
- get ref() {
- return new fh(this._firestore, this._converter, this._key);
- }
-
- exists() {
- return null !== this._document;
- }
-
- data() {
- if (this._document) {
- if (this._converter) {
-
-
- const t = new Il(this._firestore, this._userDataWriter, this._key, this._document,
- null);
- return this._converter.fromFirestore(t);
- }
- return this._userDataWriter.convertValue(this._document.data.value);
- }
- }
-
-
-
- get(t) {
- if (this._document) {
- const e = this._document.data.field(Tl("DocumentSnapshot.get", t));
- if (null !== e) return this._userDataWriter.convertValue(e);
- }
- }
- }
- class Il extends pl {
-
- data() {
- return super.data();
- }
- }
- function Tl(t, e) {
- return "string" == typeof e ? ml(t, e) : e instanceof Kh ? e._internalPath : e._delegate._internalPath;
- }
- function El(t) {
- if ("L" === t.limitType && 0 === t.explicitOrderBy.length) throw new U(q.UNIMPLEMENTED, "limitToLast() queries require specifying at least one orderBy() clause");
- }
- class Al {}
- class vl extends Al {}
- function Rl(t, e, ...n) {
- let s = [];
- e instanceof Al && s.push(e), s = s.concat(n), function(t) {
- const e = t.filter((t => t instanceof Vl)).length, n = t.filter((t => t instanceof Pl)).length;
- if (e > 1 || e > 0 && n > 0) throw new U(q.INVALID_ARGUMENT, "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(...)))`.");
- }
-
-
- (s);
- for (const e of s) t = e._apply(t);
- return t;
- }
- class Pl extends vl {
-
- constructor(t, e, n) {
- super(), this._field = t, this._op = e, this._value = n,
-
- this.type = "where";
- }
- static _create(t, e, n) {
- return new Pl(t, e, n);
- }
- _apply(t) {
- const e = this._parse(t);
- return Ql(t._query, e), new dh(t.firestore, t.converter, Yn(t._query, e));
- }
- _parse(t) {
- const e = Zh(t.firestore), n = function(t, e, n, s, i, r, o) {
- let u;
- if (i.isKeyField()) {
- if ("array-contains" === r || "array-contains-any" === r) throw new U(q.INVALID_ARGUMENT, `Invalid Query. You can't perform '${r}' queries on documentId().`);
- if ("in" === r || "not-in" === r) {
- Gl(o, r);
- const e = [];
- for (const n of o) e.push(Kl(s, t, n));
- u = {
- arrayValue: {
- values: e
- }
- };
- } else u = Kl(s, t, o);
- } else "in" !== r && "not-in" !== r && "array-contains-any" !== r || Gl(o, r),
- u = al(n, e, o,
- "in" === r || "not-in" === r);
- return mn.create(i, r, u);
- }(t._query, "where", e, t.firestore._databaseId, this._field, this._op, this._value);
- return n;
- }
- }
- function bl(t, e, n) {
- const s = e, i = Tl("where", t);
- return Pl._create(i, s, n);
- }
- class Vl extends Al {
-
- constructor(
- /** The type of this query constraint */
- t, e) {
- super(), this.type = t, this._queryConstraints = e;
- }
- static _create(t, e) {
- return new Vl(t, e);
- }
- _parse(t) {
- const e = this._queryConstraints.map((e => e._parse(t))).filter((t => t.getFilters().length > 0));
- return 1 === e.length ? e[0] : gn.create(e, this._getOperator());
- }
- _apply(t) {
- const e = this._parse(t);
- return 0 === e.getFilters().length ? t : (function(t, e) {
- let n = t;
- const s = e.getFlattenedFilters();
- for (const t of s) Ql(n, t), n = Yn(n, t);
- }
-
-
- (t._query, e), new dh(t.firestore, t.converter, Yn(t._query, e)));
- }
- _getQueryConstraints() {
- return this._queryConstraints;
- }
- _getOperator() {
- return "and" === this.type ? "and" : "or" ;
- }
- }
- function Sl(...t) {
-
- return t.forEach((t => zl("or", t))), Vl._create("or" , t);
- }
- function Dl(...t) {
-
- return t.forEach((t => zl("and", t))), Vl._create("and" , t);
- }
- class Cl extends vl {
-
- constructor(t, e) {
- super(), this._field = t, this._direction = e,
-
- this.type = "orderBy";
- }
- static _create(t, e) {
- return new Cl(t, e);
- }
- _apply(t) {
- const e = function(t, e, n) {
- if (null !== t.startAt) throw new U(q.INVALID_ARGUMENT, "Invalid query. You must not call startAt() or startAfter() before calling orderBy().");
- if (null !== t.endAt) throw new U(q.INVALID_ARGUMENT, "Invalid query. You must not call endAt() or endBefore() before calling orderBy().");
- const s = new dn(e, n);
- return function(t, e) {
- if (null === jn(t)) {
-
- const n = zn(t);
- null !== n && jl(t, n, e.field);
- }
- }(t, s), s;
- }
-
- (t._query, this._field, this._direction);
- return new dh(t.firestore, t.converter, function(t, e) {
-
- const n = t.explicitOrderBy.concat([ e ]);
- return new Un(t.path, t.collectionGroup, n, t.filters.slice(), t.limit, t.limitType, t.startAt, t.endAt);
- }(t._query, e));
- }
- }
- function xl(t, e = "asc") {
- const n = e, s = Tl("orderBy", t);
- return Cl._create(s, n);
- }
- class Nl extends vl {
-
- constructor(
- /** The type of this query constraint */
- t, e, n) {
- super(), this.type = t, this._limit = e, this._limitType = n;
- }
- static _create(t, e, n) {
- return new Nl(t, e, n);
- }
- _apply(t) {
- return new dh(t.firestore, t.converter, Xn(t._query, this._limit, this._limitType));
- }
- }
- function kl(t) {
- return ch("limit", t), Nl._create("limit", t, "F" );
- }
- function Ml(t) {
- return ch("limitToLast", t), Nl._create("limitToLast", t, "L" );
- }
- class $l extends vl {
-
- constructor(
- /** The type of this query constraint */
- t, e, n) {
- super(), this.type = t, this._docOrFields = e, this._inclusive = n;
- }
- static _create(t, e, n) {
- return new $l(t, e, n);
- }
- _apply(t) {
- const e = Ul(t, this.type, this._docOrFields, this._inclusive);
- return new dh(t.firestore, t.converter, function(t, e) {
- return new Un(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, e, t.endAt);
- }(t._query, e));
- }
- }
- function Ol(...t) {
- return $l._create("startAt", t,
- !0);
- }
- function Fl(...t) {
- return $l._create("startAfter", t,
- !1);
- }
- class Bl extends vl {
-
- constructor(
- /** The type of this query constraint */
- t, e, n) {
- super(), this.type = t, this._docOrFields = e, this._inclusive = n;
- }
- static _create(t, e, n) {
- return new Bl(t, e, n);
- }
- _apply(t) {
- const e = Ul(t, this.type, this._docOrFields, this._inclusive);
- return new dh(t.firestore, t.converter, function(t, e) {
- return new Un(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, t.startAt, e);
- }(t._query, e));
- }
- }
- function Ll(...t) {
- return Bl._create("endBefore", t,
- !1);
- }
- function ql(...t) {
- return Bl._create("endAt", t,
- !0);
- }
- function Ul(t, e, n, s) {
- if (n[0] = getModularInstance(n[0]), n[0] instanceof pl) return function(t, e, n, s, i) {
- if (!s) throw new U(q.NOT_FOUND, `Can't use a DocumentSnapshot that doesn't exist for ${n}().`);
- const r = [];
-
-
-
-
-
-
-
- for (const n of Hn(t)) if (n.field.isKeyField()) r.push(We(e, s.key)); else {
- const t = s.data.field(n.field);
- if (Ne(t)) throw new U(q.INVALID_ARGUMENT, '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.)');
- if (null === t) {
- const t = n.field.canonicalString();
- throw new U(q.INVALID_ARGUMENT, `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.`);
- }
- r.push(t);
- }
- return new hn(r, i);
- }
-
- (t._query, t.firestore._databaseId, e, n[0]._document, s);
- {
- const i = Zh(t.firestore);
- return function(t, e, n, s, i, r) {
-
- const o = t.explicitOrderBy;
- if (i.length > o.length) throw new U(q.INVALID_ARGUMENT, `Too many arguments provided to ${s}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);
- const u = [];
- for (let r = 0; r < i.length; r++) {
- const c = i[r];
- if (o[r].field.isKeyField()) {
- if ("string" != typeof c) throw new U(q.INVALID_ARGUMENT, `Invalid query. Expected a string for document ID in ${s}(), but got a ${typeof c}`);
- if (!Wn(t) && -1 !== c.indexOf("/")) throw new U(q.INVALID_ARGUMENT, `Invalid query. When querying a collection and ordering by documentId(), the value passed to ${s}() must be a plain document ID, but '${c}' contains a slash.`);
- const n = t.path.child(ut.fromString(c));
- if (!ht.isDocumentKey(n)) throw new U(q.INVALID_ARGUMENT, `Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${s}() must result in a valid document path, but '${n}' is not because it contains an odd number of segments.`);
- const i = new ht(n);
- u.push(We(e, i));
- } else {
- const t = al(n, s, c);
- u.push(t);
- }
- }
- return new hn(u, r);
- }
-
- (t._query, t.firestore._databaseId, i, e, n, s);
- }
- }
- function Kl(t, e, n) {
- if ("string" == typeof (n = getModularInstance(n))) {
- if ("" === n) throw new U(q.INVALID_ARGUMENT, "Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");
- if (!Wn(e) && -1 !== n.indexOf("/")) throw new U(q.INVALID_ARGUMENT, `Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${n}' contains a '/' character.`);
- const s = e.path.child(ut.fromString(n));
- if (!ht.isDocumentKey(s)) throw new U(q.INVALID_ARGUMENT, `Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${s}' is not because it has an odd number of segments (${s.length}).`);
- return We(t, new ht(s));
- }
- if (n instanceof fh) return We(t, n._key);
- throw new U(q.INVALID_ARGUMENT, `Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${oh(n)}.`);
- }
- function Gl(t, e) {
- if (!Array.isArray(t) || 0 === t.length) throw new U(q.INVALID_ARGUMENT, `Invalid Query. A non-empty array is required for '${e.toString()}' filters.`);
- }
- function Ql(t, e) {
- if (e.isInequality()) {
- const n = zn(t), s = e.field;
- if (null !== n && !n.isEqual(s)) throw new U(q.INVALID_ARGUMENT, `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 '${s.toString()}'`);
- const i = jn(t);
- null !== i && jl(t, s, i);
- }
- const n = function(t, e) {
- for (const n of t) for (const t of n.getFlattenedFilters()) if (e.indexOf(t.op) >= 0) return t.op;
- return null;
- }(t.filters, function(t) {
- switch (t) {
- case "!=" :
- return [ "!=" , "not-in" ];
- case "array-contains-any" :
- case "in" :
- return [ "not-in" ];
- case "not-in" :
- return [ "array-contains-any" , "in" , "not-in" , "!=" ];
- default:
- return [];
- }
- }(e.op));
- if (null !== n)
-
- throw n === e.op ? new U(q.INVALID_ARGUMENT, `Invalid query. You cannot use more than one '${e.op.toString()}' filter.`) : new U(q.INVALID_ARGUMENT, `Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`);
- }
- function jl(t, e, n) {
- if (!n.isEqual(e)) throw new U(q.INVALID_ARGUMENT, `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.`);
- }
- function zl(t, e) {
- if (!(e instanceof Pl || e instanceof Vl)) throw new U(q.INVALID_ARGUMENT, `Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`);
- }
- class Wl {
- convertValue(t, e = "none") {
- switch (Le(t)) {
- case 0 :
- return null;
- case 1 :
- return t.booleanValue;
- case 2 :
- return Ce(t.integerValue || t.doubleValue);
- case 3 :
- return this.convertTimestamp(t.timestampValue);
- case 4 :
- return this.convertServerTimestamp(t, e);
- case 5 :
- return t.stringValue;
- case 6 :
- return this.convertBytes(xe(t.bytesValue));
- case 7 :
- return this.convertReference(t.referenceValue);
- case 8 :
- return this.convertGeoPoint(t.geoPointValue);
- case 9 :
- return this.convertArray(t.arrayValue, e);
- case 10 :
- return this.convertObject(t.mapValue, e);
- default:
- throw O();
- }
- }
- convertObject(t, e) {
- return this.convertObjectMap(t.fields, e);
- }
-
- convertObjectMap(t, e = "none") {
- const n = {};
- return ge(t, ((t, s) => {
- n[t] = this.convertValue(s, e);
- })), n;
- }
- convertGeoPoint(t) {
- return new jh(Ce(t.latitude), Ce(t.longitude));
- }
- convertArray(t, e) {
- return (t.values || []).map((t => this.convertValue(t, e)));
- }
- convertServerTimestamp(t, e) {
- switch (e) {
- case "previous":
- const n = ke(t);
- return null == n ? null : this.convertValue(n, e);
- case "estimate":
- return this.convertTimestamp(Me(t));
- default:
- return null;
- }
- }
- convertTimestamp(t) {
- const e = De(t);
- return new it(e.seconds, e.nanos);
- }
- convertDocumentKey(t, e) {
- const n = ut.fromString(t);
- F(ur(n));
- const s = new Oe(n.get(1), n.get(3)), i = new ht(n.popFirst(5));
- return s.isEqual(e) ||
-
- k(`Document ${i} contains a document reference within a different database (${s.projectId}/${s.database}) which is not supported. It will be treated as a reference in the current database (${e.projectId}/${e.database}) instead.`),
- i;
- }
- }
- function Hl(t, e, n) {
- let s;
-
-
-
- return s = t ? n && (n.merge || n.mergeFields) ? t.toFirestore(e, n) : t.toFirestore(e) : e,
- s;
- }
- class Jl extends Wl {
- constructor(t) {
- super(), this.firestore = t;
- }
- convertBytes(t) {
- return new Uh(t);
- }
- convertReference(t) {
- const e = this.convertDocumentKey(t, this.firestore._databaseId);
- return new fh(this.firestore, null, e);
- }
- }
- function Yl(t) {
- return new Lh("sum", wl("sum", t));
- }
- function Xl(t) {
- return new Lh("avg", wl("average", t));
- }
- function Zl() {
- return new Lh("count");
- }
- function tf(t, e) {
- var n, s;
- return t instanceof Lh && e instanceof Lh && t._aggregateType === e._aggregateType && (null === (n = t._internalFieldPath) || void 0 === n ? void 0 : n.canonicalString()) === (null === (s = e._internalFieldPath) || void 0 === s ? void 0 : s.canonicalString());
- }
- function ef(t, e) {
- return ph(t.query, e.query) && deepEqual(t.data(), e.data());
- }
- class nf {
-
- constructor(t, e) {
- this.hasPendingWrites = t, this.fromCache = e;
- }
-
- isEqual(t) {
- return this.hasPendingWrites === t.hasPendingWrites && this.fromCache === t.fromCache;
- }
- }
- class sf extends pl {
-
- constructor(t, e, n, s, i, r) {
- super(t, e, n, s, r), this._firestore = t, this._firestoreImpl = t, this.metadata = i;
- }
-
- exists() {
- return super.exists();
- }
-
- data(t = {}) {
- if (this._document) {
- if (this._converter) {
-
-
- const e = new rf(this._firestore, this._userDataWriter, this._key, this._document, this.metadata,
- null);
- return this._converter.fromFirestore(e, t);
- }
- return this._userDataWriter.convertValue(this._document.data.value, t.serverTimestamps);
- }
- }
-
-
-
- get(t, e = {}) {
- if (this._document) {
- const n = this._document.data.field(Tl("DocumentSnapshot.get", t));
- if (null !== n) return this._userDataWriter.convertValue(n, e.serverTimestamps);
- }
- }
- }
- class rf extends sf {
-
- data(t = {}) {
- return super.data(t);
- }
- }
- class of {
-
- constructor(t, e, n, s) {
- this._firestore = t, this._userDataWriter = e, this._snapshot = s, this.metadata = new nf(s.hasPendingWrites, s.fromCache),
- this.query = n;
- }
- get docs() {
- const t = [];
- return this.forEach((e => t.push(e))), t;
- }
- get size() {
- return this._snapshot.docs.size;
- }
- get empty() {
- return 0 === this.size;
- }
-
- forEach(t, e) {
- this._snapshot.docs.forEach((n => {
- t.call(e, new rf(this._firestore, this._userDataWriter, n.key, n, new nf(this._snapshot.mutatedKeys.has(n.key), this._snapshot.fromCache), this.query.converter));
- }));
- }
-
- docChanges(t = {}) {
- const e = !!t.includeMetadataChanges;
- if (e && this._snapshot.excludesMetadataChanges) throw new U(q.INVALID_ARGUMENT, "To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");
- return this._cachedChanges && this._cachedChangesIncludeMetadataChanges === e || (this._cachedChanges =
-
- function(t, e) {
- if (t._snapshot.oldDocs.isEmpty()) {
- let e = 0;
- return t._snapshot.docChanges.map((n => {
- const s = new rf(t._firestore, t._userDataWriter, n.doc.key, n.doc, new nf(t._snapshot.mutatedKeys.has(n.doc.key), t._snapshot.fromCache), t.query.converter);
- return n.doc, {
- type: "added",
- doc: s,
- oldIndex: -1,
- newIndex: e++
- };
- }));
- }
- {
-
-
- let n = t._snapshot.oldDocs;
- return t._snapshot.docChanges.filter((t => e || 3 !== t.type)).map((e => {
- const s = new rf(t._firestore, t._userDataWriter, e.doc.key, e.doc, new nf(t._snapshot.mutatedKeys.has(e.doc.key), t._snapshot.fromCache), t.query.converter);
- let i = -1, r = -1;
- return 0 !== e.type && (i = n.indexOf(e.doc.key), n = n.delete(e.doc.key)),
- 1 !== e.type && (n = n.add(e.doc), r = n.indexOf(e.doc.key)),
- {
- type: uf(e.type),
- doc: s,
- oldIndex: i,
- newIndex: r
- };
- }));
- }
- }(this, e), this._cachedChangesIncludeMetadataChanges = e), this._cachedChanges;
- }
- }
- function uf(t) {
- switch (t) {
- case 0 :
- return "added";
- case 2 :
- case 3 :
- return "modified";
- case 1 :
- return "removed";
- default:
- return O();
- }
- }
- function cf(t, e) {
- return t instanceof sf && e instanceof sf ? 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 of && e instanceof of && (t._firestore === e._firestore && ph(t.query, e.query) && t.metadata.isEqual(e.metadata) && t._snapshot.isEqual(e._snapshot));
- }
- function af(t) {
- t = uh(t, fh);
- const e = uh(t.firestore, vh);
- return za(bh(e), t._key).then((n => Af(e, t, n)));
- }
- class hf extends Wl {
- constructor(t) {
- super(), this.firestore = t;
- }
- convertBytes(t) {
- return new Uh(t);
- }
- convertReference(t) {
- const e = this.convertDocumentKey(t, this.firestore._databaseId);
- return new fh(this.firestore, null, e);
- }
- }
- function lf(t) {
- t = uh(t, fh);
- const e = uh(t.firestore, vh), n = bh(e), s = new hf(e);
- return ja(n, t._key).then((n => new sf(e, s, t._key, n, new nf(null !== n && n.hasLocalMutations,
- !0), t.converter)));
- }
- function ff(t) {
- t = uh(t, fh);
- const e = uh(t.firestore, vh);
- return za(bh(e), t._key, {
- source: "server"
- }).then((n => Af(e, t, n)));
- }
- function df(t) {
- t = uh(t, dh);
- const e = uh(t.firestore, vh), n = bh(e), s = new hf(e);
- return El(t._query), Ha(n, t._query).then((n => new of(e, s, t, n)));
- }
- function wf(t) {
- t = uh(t, dh);
- const e = uh(t.firestore, vh), n = bh(e), s = new hf(e);
- return Wa(n, t._query).then((n => new of(e, s, t, n)));
- }
- function _f(t) {
- t = uh(t, dh);
- const e = uh(t.firestore, vh), n = bh(e), s = new hf(e);
- return Ha(n, t._query, {
- source: "server"
- }).then((n => new of(e, s, t, n)));
- }
- function mf(t, e, n) {
- t = uh(t, fh);
- const s = uh(t.firestore, vh), i = Hl(t.converter, e, n);
- return Ef(s, [ tl(Zh(s), "setDoc", t._key, i, null !== t.converter, n).toMutation(t._key, Fs.none()) ]);
- }
- function gf(t, e, n, ...s) {
- t = uh(t, fh);
- const i = uh(t.firestore, vh), r = Zh(i);
- let o;
- o = "string" == typeof (
-
-
- e = getModularInstance(e)) || e instanceof Kh ? cl(r, "updateDoc", t._key, e, n, s) : ul(r, "updateDoc", t._key, e);
- return Ef(i, [ o.toMutation(t._key, Fs.exists(!0)) ]);
- }
- function yf(t) {
- return Ef(uh(t.firestore, vh), [ new Ys(t._key, Fs.none()) ]);
- }
- function pf(t, e) {
- const n = uh(t.firestore, vh), s = gh(t), i = Hl(t.converter, e);
- return Ef(n, [ tl(Zh(t.firestore), "addDoc", s._key, i, null !== t.converter, {}).toMutation(s._key, Fs.exists(!1)) ]).then((() => s));
- }
- function If(t, ...e) {
- var n, s, i;
- t = getModularInstance(t);
- let r = {
- includeMetadataChanges: !1
- }, o = 0;
- "object" != typeof e[o] || Th(e[o]) || (r = e[o], o++);
- const u = {
- includeMetadataChanges: r.includeMetadataChanges
- };
- if (Th(e[o])) {
- const t = e[o];
- e[o] = null === (n = t.next) || void 0 === n ? void 0 : n.bind(t), e[o + 1] = null === (s = t.error) || void 0 === s ? void 0 : s.bind(t),
- e[o + 2] = null === (i = t.complete) || void 0 === i ? void 0 : i.bind(t);
- }
- let c, a, h;
- if (t instanceof fh) a = uh(t.firestore, vh), h = Gn(t._key.path), c = {
- next: n => {
- e[o] && e[o](Af(a, t, n));
- },
- error: e[o + 1],
- complete: e[o + 2]
- }; else {
- const n = uh(t, dh);
- a = uh(n.firestore, vh), h = n._query;
- const s = new hf(a);
- c = {
- next: t => {
- e[o] && e[o](new of(a, s, n, t));
- },
- error: e[o + 1],
- complete: e[o + 2]
- }, El(t._query);
- }
- return function(t, e, n, s) {
- const i = new Va(s), r = new Nc(e, i, n);
- return t.asyncQueue.enqueueAndForget((async () => Vc(await Ka(t), r))), () => {
- i.Dc(), t.asyncQueue.enqueueAndForget((async () => Sc(await Ka(t), r)));
- };
- }(bh(a), h, u, c);
- }
- function Tf(t, e) {
- return Ja(bh(t = uh(t, vh)), Th(e) ? e : {
- next: e
- });
- }
- function Ef(t, e) {
- return function(t, e) {
- const n = new K;
- return t.asyncQueue.enqueueAndForget((async () => zc(await qa(t), e, n))), n.promise;
- }(bh(t), e);
- }
- function Af(t, e, n) {
- const s = n.docs.get(e._key), i = new hf(t);
- return new sf(t, i, e._key, s, new nf(n.hasPendingWrites, n.fromCache), e.converter);
- }
- function vf(t) {
- return Rf(t, {
- count: Zl()
- });
- }
- function Rf(t, e) {
- const n = uh(t.firestore, vh), s = bh(n), i = function(t, e) {
- const n = [];
- for (const s in t) Object.prototype.hasOwnProperty.call(t, s) && n.push(e(t[s], s, t));
- return n;
- }(e, ((t, e) => new ni(e, t._aggregateType, t._internalFieldPath)));
-
- return function(t, e, n) {
- const s = new K;
- return t.asyncQueue.enqueueAndForget((async () => {
-
-
-
-
- try {
-
- const i = await Ua(t);
- s.resolve(Gu(i, e, n));
- } catch (t) {
- s.reject(t);
- }
- })), s.promise;
- }(s, t._query, i).then((e =>
-
- function(t, e, n) {
- const s = new hf(t);
- return new qh(e, s, n);
- }
-
- (n, t, e)));
- }
- class Pf {
- constructor(t) {
- this.kind = "memory", this._onlineComponentProvider = new Pa, (null == t ? void 0 : t.garbageCollector) ? this._offlineComponentProvider = t.garbageCollector._offlineComponentProvider : this._offlineComponentProvider = new Ea;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class bf {
- constructor(t) {
- let e;
- this.kind = "persistent", (null == t ? void 0 : t.tabManager) ? (t.tabManager._initialize(t),
- e = t.tabManager) : (e = $f(void 0), e._initialize(t)), this._onlineComponentProvider = e._onlineComponentProvider,
- this._offlineComponentProvider = e._offlineComponentProvider;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class Vf {
- constructor() {
- this.kind = "memoryEager", this._offlineComponentProvider = new Ea;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class Sf {
- constructor(t) {
- this.kind = "memoryLru", this._offlineComponentProvider = new Aa(t);
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- function Df() {
- return new Vf;
- }
- function Cf(t) {
- return new Sf(null == t ? void 0 : t.cacheSizeBytes);
- }
- function xf(t) {
- return new Pf(t);
- }
- function Nf(t) {
- return new bf(t);
- }
- class kf {
- constructor(t) {
- this.forceOwnership = t, this.kind = "persistentSingleTab";
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
-
- _initialize(t) {
- this._onlineComponentProvider = new Pa, this._offlineComponentProvider = new va(this._onlineComponentProvider, null == t ? void 0 : t.cacheSizeBytes, this.forceOwnership);
- }
- }
- class Mf {
- constructor() {
- this.kind = "PersistentMultipleTab";
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
-
- _initialize(t) {
- this._onlineComponentProvider = new Pa, this._offlineComponentProvider = new Ra(this._onlineComponentProvider, null == t ? void 0 : t.cacheSizeBytes);
- }
- }
- function $f(t) {
- return new kf(null == t ? void 0 : t.forceOwnership);
- }
- function Of() {
- return new Mf;
- }
- const Ff = {
- maxAttempts: 5
- };
- class Bf {
-
- constructor(t, e) {
- this._firestore = t, this._commitHandler = e, this._mutations = [], this._committed = !1,
- this._dataReader = Zh(t);
- }
- set(t, e, n) {
- this._verifyNotCommitted();
- const s = Lf(t, this._firestore), i = Hl(s.converter, e, n), r = tl(this._dataReader, "WriteBatch.set", s._key, i, null !== s.converter, n);
- return this._mutations.push(r.toMutation(s._key, Fs.none())), this;
- }
- update(t, e, n, ...s) {
- this._verifyNotCommitted();
- const i = Lf(t, this._firestore);
-
-
- let r;
- return r = "string" == typeof (e = getModularInstance(e)) || e instanceof Kh ? cl(this._dataReader, "WriteBatch.update", i._key, e, n, s) : ul(this._dataReader, "WriteBatch.update", i._key, e),
- this._mutations.push(r.toMutation(i._key, Fs.exists(!0))), this;
- }
-
- delete(t) {
- this._verifyNotCommitted();
- const e = Lf(t, this._firestore);
- return this._mutations = this._mutations.concat(new Ys(e._key, Fs.none())), this;
- }
-
- commit() {
- return this._verifyNotCommitted(), this._committed = !0, this._mutations.length > 0 ? this._commitHandler(this._mutations) : Promise.resolve();
- }
- _verifyNotCommitted() {
- if (this._committed) throw new U(q.FAILED_PRECONDITION, "A write batch can no longer be used after commit() has been called.");
- }
- }
- function Lf(t, e) {
- if ((t = getModularInstance(t)).firestore !== e) throw new U(q.INVALID_ARGUMENT, "Provided document reference is from a different Firestore instance.");
- return t;
- }
- class qf extends class {
-
- constructor(t, e) {
- this._firestore = t, this._transaction = e, this._dataReader = Zh(t);
- }
-
- get(t) {
- const e = Lf(t, this._firestore), n = new Jl(this._firestore);
- return this._transaction.lookup([ e._key ]).then((t => {
- if (!t || 1 !== t.length) return O();
- const s = t[0];
- if (s.isFoundDocument()) return new pl(this._firestore, n, s.key, s, e.converter);
- if (s.isNoDocument()) return new pl(this._firestore, n, e._key, null, e.converter);
- throw O();
- }));
- }
- set(t, e, n) {
- const s = Lf(t, this._firestore), i = Hl(s.converter, e, n), r = tl(this._dataReader, "Transaction.set", s._key, i, null !== s.converter, n);
- return this._transaction.set(s._key, r), this;
- }
- update(t, e, n, ...s) {
- const i = Lf(t, this._firestore);
-
-
- let r;
- return r = "string" == typeof (e = getModularInstance(e)) || e instanceof Kh ? cl(this._dataReader, "Transaction.update", i._key, e, n, s) : ul(this._dataReader, "Transaction.update", i._key, e),
- this._transaction.update(i._key, r), this;
- }
-
- delete(t) {
- const e = Lf(t, this._firestore);
- return this._transaction.delete(e._key), this;
- }
- } {
-
-
-
- constructor(t, e) {
- super(t, e), this._firestore = t;
- }
-
- get(t) {
- const e = Lf(t, this._firestore), n = new hf(this._firestore);
- return super.get(t).then((t => new sf(this._firestore, n, e._key, t._document, new nf(
- !1,
- !1), e.converter)));
- }
- }
- function Uf(t, e, n) {
- t = uh(t, vh);
- const s = Object.assign(Object.assign({}, Ff), n);
- !function(t) {
- if (t.maxAttempts < 1) throw new U(q.INVALID_ARGUMENT, "Max attempts must be at least 1");
- }(s);
- return function(t, e, n) {
- const s = new K;
- return t.asyncQueue.enqueueAndForget((async () => {
- const i = await Ua(t);
- new Ca(t.asyncQueue, i, n, e, s).run();
- })), s.promise;
- }(bh(t), (n => e(new qf(t, n))), s);
- }
- function Kf() {
- return new el("deleteField");
- }
- function Gf() {
- return new sl("serverTimestamp");
- }
- function Qf(...t) {
-
-
- return new il("arrayUnion", t);
- }
- function jf(...t) {
-
-
- return new rl("arrayRemove", t);
- }
- function zf(t) {
- return new ol("increment", t);
- }
- function Wf(t) {
- return bh(t = uh(t, vh)), new Bf(t, (e => Ef(t, e)));
- }
- function Hf(t, e) {
- var n;
- const s = bh(t = uh(t, vh));
- if (!s._uninitializedComponentsProvider || "memory" === (null === (n = s._uninitializedComponentsProvider) || void 0 === n ? void 0 : n._offlineKind))
-
-
- return M("Cannot enable indexes when persistence is disabled"), Promise.resolve();
- const i = function(t) {
- const e = "string" == typeof t ? function(t) {
- try {
- return JSON.parse(t);
- } catch (t) {
- throw new U(q.INVALID_ARGUMENT, "Failed to parse JSON: " + (null == t ? void 0 : t.message));
- }
- }(t) : t, n = [];
- if (Array.isArray(e.indexes)) for (const t of e.indexes) {
- const e = Jf(t, "collectionGroup"), s = [];
- if (Array.isArray(t.fields)) for (const e of t.fields) {
- const t = ml("setIndexConfiguration", Jf(e, "fieldPath"));
- "CONTAINS" === e.arrayConfig ? s.push(new _t(t, 2 )) : "ASCENDING" === e.order ? s.push(new _t(t, 0 )) : "DESCENDING" === e.order && s.push(new _t(t, 1 ));
- }
- n.push(new lt(lt.UNKNOWN_ID, e, s, gt.empty()));
- }
- return n;
- }(e);
- return Za(s, i);
- }
- function Jf(t, e) {
- if ("string" != typeof t[e]) throw new U(q.INVALID_ARGUMENT, "Missing string value for: " + e);
- return t[e];
- }
- !function(t, e = !0) {
- !function(t) {
- S = t;
- }(SDK_VERSION), _registerComponent(new Component("firestore", ((t, {instanceIdentifier: n, options: s}) => {
- const i = t.getProvider("app").getImmediate(), r = new vh(new z(t.getProvider("auth-internal")), new Y(t.getProvider("app-check-internal")), function(t, e) {
- if (!Object.prototype.hasOwnProperty.apply(t.options, [ "projectId" ])) throw new U(q.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
- return new Oe(t.options.projectId, e);
- }(i, n), i);
- return s = Object.assign({
- useFetchStreams: e
- }, s), r._setSettings(s), r;
- }), "PUBLIC").setMultipleInstances(!0)), registerVersion(b, "3.13.0", t),
-
- registerVersion(b, "3.13.0", "esm2017");
- }();
- export { Wl as AbstractUserDataWriter, Lh as AggregateField, qh as AggregateQuerySnapshot, Uh as Bytes, Ah as CACHE_SIZE_UNLIMITED, wh as CollectionReference, fh as DocumentReference, sf as DocumentSnapshot, Kh as FieldPath, Qh as FieldValue, vh as Firestore, U as FirestoreError, jh as GeoPoint, Eh as LoadBundleTask, dh as Query, Vl as QueryCompositeFilterConstraint, vl as QueryConstraint, rf as QueryDocumentSnapshot, Bl as QueryEndAtConstraint, Pl as QueryFieldFilterConstraint, Nl as QueryLimitConstraint, Cl as QueryOrderByConstraint, of as QuerySnapshot, $l as QueryStartAtConstraint, nf as SnapshotMetadata, it as Timestamp, qf as Transaction, Bf as WriteBatch, Oe as _DatabaseId, ht as _DocumentKey, X as _EmptyAppCheckTokenProvider, Q as _EmptyAuthCredentialsProvider, at as _FieldPath, ci as _TestingHooks, uh as _cast, B as _debugAssert, be as _isBase64Available, M as _logWarn, sh as _validateIsNotUsedTogether, pf as addDoc, tf as aggregateFieldEqual, ef as aggregateQuerySnapshotEqual, Dl as and, jf as arrayRemove, Qf as arrayUnion, Xl as average, xh as clearIndexedDbPersistence, _h as collection, mh as collectionGroup, lh as connectFirestoreEmulator, Zl as count, yf as deleteDoc, Kf as deleteField, Mh as disableNetwork, gh as doc, Gh as documentId, Sh as enableIndexedDbPersistence, Dh as enableMultiTabIndexedDbPersistence, kh as enableNetwork, ql as endAt, Ll as endBefore, bh as ensureFirestoreConfigured, Ef as executeWrite, Rf as getAggregateFromServer, vf as getCountFromServer, af as getDoc, lf as getDocFromCache, ff as getDocFromServer, df as getDocs, wf as getDocsFromCache, _f as getDocsFromServer, Ph as getFirestore, zf as increment, Rh as initializeFirestore, kl as limit, Ml as limitToLast, Oh as loadBundle, Df as memoryEagerGarbageCollector, xf as memoryLocalCache, Cf as memoryLruGarbageCollector, Fh as namedQuery, If as onSnapshot, Tf as onSnapshotsInSync, Sl as or, xl as orderBy, Nf as persistentLocalCache, Of as persistentMultipleTabManager, $f as persistentSingleTabManager, Rl as query, ph as queryEqual, yh as refEqual, Uf as runTransaction, Gf as serverTimestamp, mf as setDoc, Hf as setIndexConfiguration, x as setLogLevel, cf as snapshotEqual, Fl as startAfter, Ol as startAt, Yl as sum, $h as terminate, gf as updateDoc, Nh as waitForPendingWrites, bl as where, Wf as writeBatch };
|