1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410 |
- import { _getProvider, getApp as t, _removeServiceInstance as e, _registerComponent as n, registerVersion as s, SDK_VERSION as i } from "@firebase/app";
- import { Component as r } from "@firebase/component";
- import { Logger as o, LogLevel as u } from "@firebase/logger";
- import { FirebaseError as c, getUA as a, isIndexedDBAvailable as h, base64 as l, DecodeBase64StringError as f, isSafari as d, createMockUserToken as w, getModularInstance as _, deepEqual as m, getDefaultEmulatorHostnameAndPort as g } from "@firebase/util";
- import { Integer as y, Md5 as p, XhrIo as I, EventType as T, ErrorCode as E, createWebChannelTransport as A, getStatEventTarget as v, FetchXmlHttpFactory as R, WebChannel as P, Event as b, Stat as V } from "@firebase/webchannel-wrapper";
- const S = "@firebase/firestore";
- class D {
- 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;
- }
- }
- D.UNAUTHENTICATED = new D(null),
- D.GOOGLE_CREDENTIALS = new D("google-credentials-uid"), D.FIRST_PARTY = new D("first-party-uid"),
- D.MOCK_USER = new D("mock-user");
- let C = "9.23.0";
- const x = new o("@firebase/firestore");
- function N() {
- return x.logLevel;
- }
- function k(t) {
- x.setLogLevel(t);
- }
- function $(t, ...e) {
- if (x.logLevel <= u.DEBUG) {
- const n = e.map(F);
- x.debug(`Firestore (${C}): ${t}`, ...n);
- }
- }
- function M(t, ...e) {
- if (x.logLevel <= u.ERROR) {
- const n = e.map(F);
- x.error(`Firestore (${C}): ${t}`, ...n);
- }
- }
- function O(t, ...e) {
- if (x.logLevel <= u.WARN) {
- const n = e.map(F);
- x.warn(`Firestore (${C}): ${t}`, ...n);
- }
- }
- function F(t) {
- if ("string" == typeof t) return t;
- try {
- return e = t, JSON.stringify(e);
- } catch (e) {
-
- return t;
- }
-
-
- var e;
- }
- function B(t = "Unexpected state") {
-
-
- const e = `FIRESTORE (${C}) INTERNAL ASSERTION FAILED: ` + t;
-
-
-
- throw M(e), new Error(e);
- }
- function L(t, e) {
- t || B();
- }
- function q(t, e) {
- t || B();
- }
- function U(t,
- e) {
- return t;
- }
- const K = {
-
-
-
- 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 G extends c {
-
- 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 Q {
- constructor() {
- this.promise = new Promise(((t, e) => {
- this.resolve = t, this.reject = e;
- }));
- }
- }
- class j {
- constructor(t, e) {
- this.user = e, this.type = "OAuth", this.headers = new Map, this.headers.set("Authorization", `Bearer ${t}`);
- }
- }
- class z {
- getToken() {
- return Promise.resolve(null);
- }
- invalidateToken() {}
- start(t, e) {
-
- t.enqueueRetryable((() => e(D.UNAUTHENTICATED)));
- }
- shutdown() {}
- }
- class W {
- 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 H {
- constructor(t) {
- this.t = t,
-
- this.currentUser = D.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 Q;
- this.o = () => {
- this.i++, this.currentUser = this.u(), i.resolve(), i = new Q, t.enqueueRetryable((() => s(this.currentUser)));
- };
- const r = () => {
- const e = i;
- t.enqueueRetryable((async () => {
- await e.promise, await s(this.currentUser);
- }));
- }, o = t => {
- $("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) : (
-
- $("FirebaseAuthCredentialsProvider", "Auth not yet detected"), i.resolve(), i = new Q);
- }
- }), 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 ? ($("FirebaseAuthCredentialsProvider", "getToken aborted due to token change."),
- this.getToken()) : e ? (L("string" == typeof e.accessToken), new j(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 L(null === t || "string" == typeof t), new D(t);
- }
- }
- class J {
- constructor(t, e, n) {
- this.h = t, this.l = e, this.m = n, this.type = "FirstParty", this.user = D.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 Y {
- constructor(t, e, n) {
- this.h = t, this.l = e, this.m = n;
- }
- getToken() {
- return Promise.resolve(new J(this.h, this.l, this.m));
- }
- start(t, e) {
-
- t.enqueueRetryable((() => e(D.FIRST_PARTY)));
- }
- shutdown() {}
- invalidateToken() {}
- }
- class X {
- 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 Z {
- constructor(t) {
- this.I = t, this.forceRefresh = !1, this.appCheck = null, this.T = null;
- }
- start(t, e) {
- const n = t => {
- null != t.error && $("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, $("FirebaseAppCheckTokenProvider", `Received ${n ? "new" : "existing"} token.`),
- n ? e(t.token) : Promise.resolve();
- };
- this.o = e => {
- t.enqueueRetryable((() => n(e)));
- };
- const s = t => {
- $("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) :
-
- $("FirebaseAppCheckTokenProvider", "AppCheck not yet detected");
- }
- }), 0);
- }
- getToken() {
- const t = this.forceRefresh;
- return this.forceRefresh = !1, this.appCheck ? this.appCheck.getToken(t).then((t => t ? (L("string" == typeof t.token),
- this.T = t.token, new X(t.token)) : null)) : Promise.resolve(null);
- }
- invalidateToken() {
- this.forceRefresh = !0;
- }
- shutdown() {
- this.appCheck && this.appCheck.removeTokenListener(this.o);
- }
- }
- class tt {
- getToken() {
- return Promise.resolve(new X(""));
- }
- invalidateToken() {}
- start(t, e) {}
- shutdown() {}
- }
- function et(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 nt {
- static A() {
-
- const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", e = Math.floor(256 / t.length) * t.length;
-
- let n = "";
- for (;n.length < 20; ) {
- const s = et(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 st(t, e) {
- return t < e ? -1 : t > e ? 1 : 0;
- }
- function it(t, e, n) {
- return t.length === e.length && t.every(((t, s) => n(t, e[s])));
- }
- function rt(t) {
-
- return t + "\0";
- }
- class ot {
-
- 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 G(K.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
- if (e >= 1e9) throw new G(K.INVALID_ARGUMENT, "Timestamp nanoseconds out of range: " + e);
- if (t < -62135596800) throw new G(K.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
-
- if (t >= 253402300800) throw new G(K.INVALID_ARGUMENT, "Timestamp seconds out of range: " + t);
- }
-
- static now() {
- return ot.fromMillis(Date.now());
- }
-
- static fromDate(t) {
- return ot.fromMillis(t.getTime());
- }
-
- static fromMillis(t) {
- const e = Math.floor(t / 1e3), n = Math.floor(1e6 * (t - 1e3 * e));
- return new ot(e, n);
- }
-
- toDate() {
- return new Date(this.toMillis());
- }
-
- toMillis() {
- return 1e3 * this.seconds + this.nanoseconds / 1e6;
- }
- _compareTo(t) {
- return this.seconds === t.seconds ? st(this.nanoseconds, t.nanoseconds) : st(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 ut {
- constructor(t) {
- this.timestamp = t;
- }
- static fromTimestamp(t) {
- return new ut(t);
- }
- static min() {
- return new ut(new ot(0, 0));
- }
- static max() {
- return new ut(new ot(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 ct {
- constructor(t, e, n) {
- void 0 === e ? e = 0 : e > t.length && B(), void 0 === n ? n = t.length - e : n > t.length - e && B(),
- this.segments = t, this.offset = e, this.len = n;
- }
- get length() {
- return this.len;
- }
- isEqual(t) {
- return 0 === ct.comparator(this, t);
- }
- child(t) {
- const e = this.segments.slice(this.offset, this.limit());
- return t instanceof ct ? 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 at extends ct {
- construct(t, e, n) {
- return new at(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 G(K.INVALID_ARGUMENT, `Invalid segment (${n}). Paths must not contain // in them.`);
-
- e.push(...n.split("/").filter((t => t.length > 0)));
- }
- return new at(e);
- }
- static emptyPath() {
- return new at([]);
- }
- }
- const ht = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
- class lt extends ct {
- construct(t, e, n) {
- return new lt(t, e, n);
- }
-
- static isValidIdentifier(t) {
- return ht.test(t);
- }
- canonicalString() {
- return this.toArray().map((t => (t = t.replace(/\\/g, "\\\\").replace(/`/g, "\\`"),
- lt.isValidIdentifier(t) || (t = "`" + t + "`"), t))).join(".");
- }
- toString() {
- return this.canonicalString();
- }
-
- isKeyField() {
- return 1 === this.length && "__name__" === this.get(0);
- }
-
- static keyField() {
- return new lt([ "__name__" ]);
- }
-
- static fromServerFormat(t) {
- const e = [];
- let n = "", s = 0;
- const i = () => {
- if (0 === n.length) throw new G(K.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 G(K.INVALID_ARGUMENT, "Path has trailing escape character: " + t);
- const e = t[s + 1];
- if ("\\" !== e && "." !== e && "`" !== e) throw new G(K.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 G(K.INVALID_ARGUMENT, "Unterminated ` in path: " + t);
- return new lt(e);
- }
- static emptyPath() {
- return new lt([]);
- }
- }
- class ft {
- constructor(t) {
- this.path = t;
- }
- static fromPath(t) {
- return new ft(at.fromString(t));
- }
- static fromName(t) {
- return new ft(at.fromString(t).popFirst(5));
- }
- static empty() {
- return new ft(at.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 === at.comparator(this.path, t.path);
- }
- toString() {
- return this.path.toString();
- }
- static comparator(t, e) {
- return at.comparator(t.path, e.path);
- }
- static isDocumentKey(t) {
- return t.length % 2 == 0;
- }
-
- static fromSegments(t) {
- return new ft(new at(t.slice()));
- }
- }
- class dt {
- 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 wt(t) {
- return t.fields.find((t => 2 === t.kind));
- }
- function _t(t) {
- return t.fields.filter((t => 2 !== t.kind));
- }
- function mt(t, e) {
- let n = st(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 = yt(t.fields[s], e.fields[s]),
- 0 !== n) return n;
- return st(t.fields.length, e.fields.length);
- }
- dt.UNKNOWN_ID = -1;
- class gt {
- constructor(
- /** The field path of the component. */
- t,
- /** The fields sorting order. */
- e) {
- this.fieldPath = t, this.kind = e;
- }
- }
- function yt(t, e) {
- const n = lt.comparator(t.fieldPath, e.fieldPath);
- return 0 !== n ? n : st(t.kind, e.kind);
- }
- class pt {
- 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 pt(0, Et.min());
- }
- }
- function It(t, e) {
-
-
-
-
-
-
- const n = t.toTimestamp().seconds, s = t.toTimestamp().nanoseconds + 1, i = ut.fromTimestamp(1e9 === s ? new ot(n + 1, 0) : new ot(n, s));
- return new Et(i, ft.empty(), e);
- }
- function Tt(t) {
- return new Et(t.readTime, t.key, -1);
- }
- class Et {
- 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 Et(ut.min(), ft.empty(), -1);
- }
- static max() {
- return new Et(ut.max(), ft.empty(), -1);
- }
- }
- function At(t, e) {
- let n = t.readTime.compareTo(e.readTime);
- return 0 !== n ? n : (n = ft.comparator(t.documentKey, e.documentKey), 0 !== n ? n : st(t.largestBatchId, e.largestBatchId));
- }
- const vt = "The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.";
- class Rt {
- constructor() {
- this.onCommittedListeners = [];
- }
- addOnCommittedListener(t) {
- this.onCommittedListeners.push(t);
- }
- raiseOnCommittedEvent() {
- this.onCommittedListeners.forEach((t => t()));
- }
- }
- async function Pt(t) {
- if (t.code !== K.FAILED_PRECONDITION || t.message !== vt) throw t;
- $("LocalStore", "Unexpectedly lost primary lease");
- }
- class bt {
- 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 && B(), this.callbackAttached = !0, this.isDone ? this.error ? this.wrapFailure(e, this.error) : this.wrapSuccess(t, this.result) : new bt(((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 bt ? e : bt.resolve(e);
- } catch (t) {
- return bt.reject(t);
- }
- }
- wrapSuccess(t, e) {
- return t ? this.wrapUserFunction((() => t(e))) : bt.resolve(e);
- }
- wrapFailure(t, e) {
- return t ? this.wrapUserFunction((() => t(e))) : bt.reject(e);
- }
- static resolve(t) {
- return new bt(((e, n) => {
- e(t);
- }));
- }
- static reject(t) {
- return new bt(((e, n) => {
- n(t);
- }));
- }
- static waitFor(
-
-
- t) {
- return new bt(((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 = bt.resolve(!1);
- for (const n of t) e = e.next((t => t ? bt.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 bt(((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 bt(((n, s) => {
- const i = () => {
- !0 === t() ? e().next((() => {
- i();
- }), s) : n();
- };
- i();
- }));
- }
- }
- class Vt {
- constructor(t, e) {
- this.action = t, this.transaction = e, this.aborted = !1,
-
- this.v = new Q, this.transaction.oncomplete = () => {
- this.v.resolve();
- }, this.transaction.onabort = () => {
- e.error ? this.v.reject(new Ct(t, e.error)) : this.v.resolve();
- }, this.transaction.onerror = e => {
- const n = Mt(e.target.error);
- this.v.reject(new Ct(t, n));
- };
- }
- static open(t, e, n, s) {
- try {
- return new Vt(e, t.transaction(s, n));
- } catch (t) {
- throw new Ct(e, t);
- }
- }
- get R() {
- return this.v.promise;
- }
- abort(t) {
- t && this.v.reject(t), this.aborted || ($("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 Nt(e);
- }
- }
- class St {
-
- constructor(t, e, n) {
- this.name = t, this.version = e, this.V = n;
-
-
-
-
- 12.2 === St.S(a()) && M("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 $("SimpleDb", "Removing database:", t), kt(window.indexedDB.deleteDatabase(t)).toPromise();
- }
- static D() {
- if (!h()) return !1;
- if (St.C()) return !0;
-
-
-
-
-
-
-
- const t = a(), e = St.S(t), n = 0 < e && e < 10, s = St.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 $(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 M(t) {
- return this.db || ($("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 Ct(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 G(K.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 G(K.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 Ct(t, s));
- }, s.onupgradeneeded = t => {
- $("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((() => {
- $("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.M(t);
- const e = Vt.open(this.db, t, i ? "readonly" : "readwrite", n), r = s(e).next((t => (e.P(),
- t))).catch((t => (
-
- e.abort(t), bt.reject(t)))).toPromise();
-
-
- return r.catch((() => {})),
-
-
-
- await e.R, r;
- } catch (t) {
- const e = t, n = "FirebaseError" !== e.name && r < 3;
-
-
-
-
-
- if ($("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 Dt {
- 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 kt(this.L.delete());
- }
- }
- class Ct extends G {
- constructor(t, e) {
- super(K.UNAVAILABLE, `IndexedDB transaction '${t}' failed: ${e}`), this.name = "IndexedDbTransactionError";
- }
- }
- function xt(t) {
-
-
- return "IndexedDbTransactionError" === t.name;
- }
- class Nt {
- constructor(t) {
- this.store = t;
- }
- put(t, e) {
- let n;
- return void 0 !== e ? ($("SimpleDb", "PUT", this.store.name, t, e), n = this.store.put(e, t)) : ($("SimpleDb", "PUT", this.store.name, "<auto-key>", t),
- n = this.store.put(t)), kt(n);
- }
-
- add(t) {
- $("SimpleDb", "ADD", this.store.name, t, t);
- return kt(this.store.add(t));
- }
-
- get(t) {
-
-
- return kt(this.store.get(t)).next((e => (
-
- void 0 === e && (e = null), $("SimpleDb", "GET", this.store.name, t, e), e)));
- }
- delete(t) {
- $("SimpleDb", "DELETE", this.store.name, t);
- return kt(this.store.delete(t));
- }
-
- count() {
- $("SimpleDb", "COUNT", this.store.name);
- return kt(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 bt(((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 bt(((t, e) => {
- n.onerror = t => {
- e(t.target.error);
- }, n.onsuccess = e => {
- t(e.target.result);
- };
- }));
- }
- J(t, e) {
- $("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 bt(((n, s) => {
- e.onerror = t => {
- const e = Mt(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 bt(((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 Dt(i), o = e(i.primaryKey, i.value, r);
- if (o instanceof bt) {
- const t = o.catch((t => (r.done(), bt.reject(t))));
- n.push(t);
- }
- r.isDone ? s() : null === r.K ? i.continue() : i.continue(r.K);
- };
- })).next((() => bt.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 kt(t) {
- return new bt(((e, n) => {
- t.onsuccess = t => {
- const n = t.target.result;
- e(n);
- }, t.onerror = t => {
- const e = Mt(t.target.error);
- n(e);
- };
- }));
- }
- let $t = !1;
- function Mt(t) {
- const e = St.S(a());
- 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 G("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 $t || ($t = !0,
-
-
- setTimeout((() => {
- throw t;
- }), 0)), t;
- }
- }
- return t;
- }
- class Ot {
- 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) {
- $("IndexBackiller", `Scheduled in ${t}ms`), this.task = this.asyncQueue.enqueueAfterDelay("index_backfill" , t, (async () => {
- this.task = null;
- try {
- $("IndexBackiller", `Documents written: ${await this.tt.nt()}`);
- } catch (t) {
- xt(t) ? $("IndexBackiller", "Ignoring IndexedDB error during index backfill: ", t) : await Pt(t);
- }
- await this.et(6e4);
- }));
- }
- }
- class Ft {
- 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 bt.doWhile((() => !0 === i && s > 0), (() => this.localStore.indexManager.getNextCollectionGroupToUpdate(t).next((e => {
- if (null !== e && !n.has(e)) return $("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 => ($("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 = Tt(e);
- At(s, n) > 0 && (n = s);
- })), new Et(n.readTime, n.documentKey, Math.max(e.batchId, t.largestBatchId));
- }
- }
- class Bt {
- 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;
- }
- }
- Bt.ct = -1;
- function Lt(t) {
- return null == t;
- }
- function qt(t) {
-
-
- return 0 === t && 1 / t == -1 / 0;
- }
- function Ut(t) {
- return "number" == typeof t && Number.isInteger(t) && !qt(t) && t <= Number.MAX_SAFE_INTEGER && t >= Number.MIN_SAFE_INTEGER;
- }
- function Kt(t) {
- let e = "";
- for (let n = 0; n < t.length; n++) e.length > 0 && (e = Qt(e)), e = Gt(t.get(n), e);
- return Qt(e);
- }
- function Gt(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 Qt(t) {
- return t + "";
- }
- function jt(t) {
-
-
- const e = t.length;
- if (L(e >= 2), 2 === e) return L("" === t.charAt(0) && "" === t.charAt(1)), at.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) && B();
- 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:
- B();
- }
- i = e + 2;
- }
- return new at(n);
- }
- const zt = [ "userId", "batchId" ];
- function Wt(t, e) {
- return [ t, Kt(e) ];
- }
- function Ht(t, e, n) {
- return [ t, Kt(e), n ];
- }
- const Jt = {}, Yt = [ "prefixPath", "collectionGroup", "readTime", "documentId" ], Xt = [ "prefixPath", "collectionGroup", "documentId" ], Zt = [ "collectionGroup", "readTime", "prefixPath", "documentId" ], te = [ "canonicalId", "targetId" ], ee = [ "targetId", "path" ], ne = [ "path", "targetId" ], se = [ "collectionId", "parent" ], ie = [ "indexId", "uid" ], re = [ "uid", "sequenceNumber" ], oe = [ "indexId", "uid", "arrayValue", "directionalValue", "orderedDocumentKey", "documentKey" ], ue = [ "indexId", "uid", "orderedDocumentKey" ], ce = [ "userId", "collectionPath", "documentId" ], ae = [ "userId", "collectionPath", "largestBatchId" ], he = [ "userId", "collectionGroup", "largestBatchId" ], le = [ ...[ ...[ ...[ ...[ "mutationQueues", "mutations", "documentMutations", "remoteDocuments", "targets", "owner", "targetGlobal", "targetDocuments" ], "clientMetadata" ], "remoteDocumentGlobal" ], "collectionParents" ], "bundles", "namedQueries" ], fe = [ ...le, "documentOverlays" ], de = [ "mutationQueues", "mutations", "documentMutations", "remoteDocumentsV14", "targets", "owner", "targetGlobal", "targetDocuments", "clientMetadata", "remoteDocumentGlobal", "collectionParents", "bundles", "namedQueries", "documentOverlays" ], we = de, _e = [ ...we, "indexConfiguration", "indexState", "indexEntries" ];
- class me extends Rt {
- constructor(t, e) {
- super(), this.ht = t, this.currentSequenceNumber = e;
- }
- }
- function ge(t, e) {
- const n = U(t);
- return St.$(n.ht, e);
- }
- function ye(t) {
- let e = 0;
- for (const n in t) Object.prototype.hasOwnProperty.call(t, n) && e++;
- return e;
- }
- function pe(t, e) {
- for (const n in t) Object.prototype.hasOwnProperty.call(t, n) && e(n, t[n]);
- }
- function Ie(t) {
- for (const e in t) if (Object.prototype.hasOwnProperty.call(t, e)) return !1;
- return !0;
- }
- class Te {
- constructor(t, e) {
- this.comparator = t, this.root = e || Ae.EMPTY;
- }
-
- insert(t, e) {
- return new Te(this.comparator, this.root.insert(t, e, this.comparator).copy(null, null, Ae.BLACK, null, null));
- }
-
- remove(t) {
- return new Te(this.comparator, this.root.remove(t, this.comparator).copy(null, null, Ae.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 Ee(this.root, null, this.comparator, !1);
- }
- getIteratorFrom(t) {
- return new Ee(this.root, t, this.comparator, !1);
- }
- getReverseIterator() {
- return new Ee(this.root, null, this.comparator, !0);
- }
- getReverseIteratorFrom(t) {
- return new Ee(this.root, t, this.comparator, !0);
- }
- }
-
- class Ee {
- 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 Ae {
- constructor(t, e, n, s, i) {
- this.key = t, this.value = e, this.color = null != n ? n : Ae.RED, this.left = null != s ? s : Ae.EMPTY,
- this.right = null != i ? i : Ae.EMPTY, this.size = this.left.size + 1 + this.right.size;
- }
-
- copy(t, e, n, s, i) {
- return new Ae(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 Ae.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 Ae.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, Ae.RED, null, this.right.left);
- return this.right.copy(null, null, this.color, t, null);
- }
- rotateRight() {
- const t = this.copy(null, null, Ae.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 B();
- if (this.right.isRed()) throw B();
- const t = this.left.check();
- if (t !== this.right.check()) throw B();
- return t + (this.isRed() ? 0 : 1);
- }
- }
-
- Ae.EMPTY = null, Ae.RED = !0, Ae.BLACK = !1;
- Ae.EMPTY = new
- class {
- constructor() {
- this.size = 0;
- }
- get key() {
- throw B();
- }
- get value() {
- throw B();
- }
- get color() {
- throw B();
- }
- get left() {
- throw B();
- }
- get right() {
- throw B();
- }
-
- copy(t, e, n, s, i) {
- return this;
- }
-
- insert(t, e, n) {
- return new Ae(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 ve {
- constructor(t) {
- this.comparator = t, this.data = new Te(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 Re(this.data.getIterator());
- }
- getIteratorFrom(t) {
- return new Re(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 ve)) 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 ve(this.comparator);
- return e.data = t, e;
- }
- }
- class Re {
- constructor(t) {
- this.iter = t;
- }
- getNext() {
- return this.iter.getNext().key;
- }
- hasNext() {
- return this.iter.hasNext();
- }
- }
- function Pe(t) {
- return t.hasNext() ? t.getNext() : void 0;
- }
- class be {
- constructor(t) {
- this.fields = t,
-
-
- t.sort(lt.comparator);
- }
- static empty() {
- return new be([]);
- }
-
- unionWith(t) {
- let e = new ve(lt.comparator);
- for (const t of this.fields) e = e.add(t);
- for (const n of t) e = e.add(n);
- return new be(e.toArray());
- }
-
- covers(t) {
- for (const e of this.fields) if (e.isPrefixOf(t)) return !0;
- return !1;
- }
- isEqual(t) {
- return it(this.fields, t.fields, ((t, e) => t.isEqual(e)));
- }
- }
- class Ve extends Error {
- constructor() {
- super(...arguments), this.name = "Base64DecodeError";
- }
- }
- function Se(t) {
- try {
- return String.fromCharCode.apply(null,
-
-
-
- l.decodeStringToByteArray(t, false));
- } catch (t) {
- throw t instanceof f ? new Ve("Invalid base64 string: " + t) : t;
- }
- }
- function De() {
- return !0;
- }
- class Ce {
- constructor(t) {
- this.binaryString = t;
- }
- static fromBase64String(t) {
- const e = Se(t);
- return new Ce(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 Ce(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 function(t) {
- const e = [];
- for (let n = 0; n < t.length; n++) e[n] = t.charCodeAt(n);
- return l.encodeByteArray(e, !1);
- }(this.binaryString);
- }
- 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 st(this.binaryString, t.binaryString);
- }
- isEqual(t) {
- return this.binaryString === t.binaryString;
- }
- }
- Ce.EMPTY_BYTE_STRING = new Ce("");
- const xe = new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);
- function Ne(t) {
-
-
-
- if (L(!!t), "string" == typeof t) {
-
-
-
- let e = 0;
- const n = xe.exec(t);
- if (L(!!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: ke(t.seconds),
- nanos: ke(t.nanos)
- };
- }
- function ke(t) {
-
- return "number" == typeof t ? t : "string" == typeof t ? Number(t) : 0;
- }
- function $e(t) {
- return "string" == typeof t ? Ce.fromBase64String(t) : Ce.fromUint8Array(t);
- }
- function Me(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 Oe(t) {
- const e = t.mapValue.fields.__previous_value__;
- return Me(e) ? Oe(e) : e;
- }
- function Fe(t) {
- const e = Ne(t.mapValue.fields.__local_write_time__.timestampValue);
- return new ot(e.seconds, e.nanos);
- }
- class Be {
-
- 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 Le {
- constructor(t, e) {
- this.projectId = t, this.database = e || "(default)";
- }
- static empty() {
- return new Le("", "");
- }
- get isDefaultDatabase() {
- return "(default)" === this.database;
- }
- isEqual(t) {
- return t instanceof Le && t.projectId === this.projectId && t.database === this.database;
- }
- }
- const qe = {
- mapValue: {
- fields: {
- __type__: {
- stringValue: "__max__"
- }
- }
- }
- }, Ue = {
- nullValue: "NULL_VALUE"
- };
- function Ke(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 ? Me(t) ? 4 : rn(t) ? 9007199254740991 : 10 : B();
- }
- function Ge(t, e) {
- if (t === e) return !0;
- const n = Ke(t);
- if (n !== Ke(e)) return !1;
- switch (n) {
- case 0 :
- case 9007199254740991 :
- return !0;
- case 1 :
- return t.booleanValue === e.booleanValue;
- case 4 :
- return Fe(t).isEqual(Fe(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 = Ne(t.timestampValue), s = Ne(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 $e(t.bytesValue).isEqual($e(e.bytesValue));
- }(t, e);
- case 7 :
- return t.referenceValue === e.referenceValue;
- case 8 :
- return function(t, e) {
- return ke(t.geoPointValue.latitude) === ke(e.geoPointValue.latitude) && ke(t.geoPointValue.longitude) === ke(e.geoPointValue.longitude);
- }(t, e);
- case 2 :
- return function(t, e) {
- if ("integerValue" in t && "integerValue" in e) return ke(t.integerValue) === ke(e.integerValue);
- if ("doubleValue" in t && "doubleValue" in e) {
- const n = ke(t.doubleValue), s = ke(e.doubleValue);
- return n === s ? qt(n) === qt(s) : isNaN(n) && isNaN(s);
- }
- return !1;
- }(t, e);
- case 9 :
- return it(t.arrayValue.values || [], e.arrayValue.values || [], Ge);
- case 10 :
- return function(t, e) {
- const n = t.mapValue.fields || {}, s = e.mapValue.fields || {};
- if (ye(n) !== ye(s)) return !1;
- for (const t in n) if (n.hasOwnProperty(t) && (void 0 === s[t] || !Ge(n[t], s[t]))) return !1;
- return !0;
- }
- (t, e);
- default:
- return B();
- }
- }
- function Qe(t, e) {
- return void 0 !== (t.values || []).find((t => Ge(t, e)));
- }
- function je(t, e) {
- if (t === e) return 0;
- const n = Ke(t), s = Ke(e);
- if (n !== s) return st(n, s);
- switch (n) {
- case 0 :
- case 9007199254740991 :
- return 0;
- case 1 :
- return st(t.booleanValue, e.booleanValue);
- case 2 :
- return function(t, e) {
- const n = ke(t.integerValue || t.doubleValue), s = ke(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 ze(t.timestampValue, e.timestampValue);
- case 4 :
- return ze(Fe(t), Fe(e));
- case 5 :
- return st(t.stringValue, e.stringValue);
- case 6 :
- return function(t, e) {
- const n = $e(t), s = $e(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 = st(n[t], s[t]);
- if (0 !== e) return e;
- }
- return st(n.length, s.length);
- }(t.referenceValue, e.referenceValue);
- case 8 :
- return function(t, e) {
- const n = st(ke(t.latitude), ke(e.latitude));
- if (0 !== n) return n;
- return st(ke(t.longitude), ke(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 = je(n[t], s[t]);
- if (e) return e;
- }
- return st(n.length, s.length);
- }(t.arrayValue, e.arrayValue);
- case 10 :
- return function(t, e) {
- if (t === qe.mapValue && e === qe.mapValue) return 0;
- if (t === qe.mapValue) return 1;
- if (e === qe.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 = st(s[t], r[t]);
- if (0 !== e) return e;
- const o = je(n[s[t]], i[r[t]]);
- if (0 !== o) return o;
- }
- return st(s.length, r.length);
- }
-
- (t.mapValue, e.mapValue);
- default:
- throw B();
- }
- }
- function ze(t, e) {
- if ("string" == typeof t && "string" == typeof e && t.length === e.length) return st(t, e);
- const n = Ne(t), s = Ne(e), i = st(n.seconds, s.seconds);
- return 0 !== i ? i : st(n.nanos, s.nanos);
- }
- function We(t) {
- return He(t);
- }
- function He(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 = Ne(t);
- return `time(${e.seconds},${e.nanos})`;
- }(t.timestampValue) : "stringValue" in t ? t.stringValue : "bytesValue" in t ? $e(t.bytesValue).toBase64() : "referenceValue" in t ? (n = t.referenceValue,
- ft.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 += He(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}:${He(t.fields[i])}`;
- return n + "}";
- }(t.mapValue) : B();
- var e, n;
- }
- function Je(t) {
- switch (Ke(t)) {
- case 0 :
- case 1 :
- return 4;
- case 2 :
- return 8;
- case 3 :
- case 8 :
-
- return 16;
- case 4 :
- const e = Oe(t);
- return e ? 16 + Je(e) : 16;
- case 5 :
-
-
-
- return 2 * t.stringValue.length;
- case 6 :
- return $e(t.bytesValue).approximateByteSize();
- case 7 :
- return t.referenceValue.length;
- case 9 :
- return (t.arrayValue.values || []).reduce(((t, e) => t + Je(e)), 0);
- case 10 :
- return function(t) {
- let e = 0;
- return pe(t.fields, ((t, n) => {
- e += t.length + Je(n);
- })), e;
- }(t.mapValue);
- default:
- throw B();
- }
- }
- function Ye(t, e) {
- return {
- referenceValue: `projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`
- };
- }
- function Xe(t) {
- return !!t && "integerValue" in t;
- }
- function Ze(t) {
- return !!t && "arrayValue" in t;
- }
- function tn(t) {
- return !!t && "nullValue" in t;
- }
- function en(t) {
- return !!t && "doubleValue" in t && isNaN(Number(t.doubleValue));
- }
- function nn(t) {
- return !!t && "mapValue" in t;
- }
- function sn(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 pe(t.mapValue.fields, ((t, n) => e.mapValue.fields[t] = sn(n))), e;
- }
- if (t.arrayValue) {
- const e = {
- arrayValue: {
- values: []
- }
- };
- for (let n = 0; n < (t.arrayValue.values || []).length; ++n) e.arrayValue.values[n] = sn(t.arrayValue.values[n]);
- return e;
- }
- return Object.assign({}, t);
- }
- function rn(t) {
- return "__max__" === (((t.mapValue || {}).fields || {}).__type__ || {}).stringValue;
- }
- function on(t) {
- return "nullValue" in t ? Ue : "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 ? Ye(Le.empty(), ft.empty()) : "geoPointValue" in t ? {
- geoPointValue: {
- latitude: -90,
- longitude: -180
- }
- } : "arrayValue" in t ? {
- arrayValue: {}
- } : "mapValue" in t ? {
- mapValue: {}
- } : B();
- }
- function un(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 ? Ye(Le.empty(), ft.empty()) : "referenceValue" in t ? {
- geoPointValue: {
- latitude: -90,
- longitude: -180
- }
- } : "geoPointValue" in t ? {
- arrayValue: {}
- } : "arrayValue" in t ? {
- mapValue: {}
- } : "mapValue" in t ? qe : B();
- }
- function cn(t, e) {
- const n = je(t.value, e.value);
- return 0 !== n ? n : t.inclusive && !e.inclusive ? -1 : !t.inclusive && e.inclusive ? 1 : 0;
- }
- function an(t, e) {
- const n = je(t.value, e.value);
- return 0 !== n ? n : t.inclusive && !e.inclusive ? 1 : !t.inclusive && e.inclusive ? -1 : 0;
- }
- class hn {
- constructor(t) {
- this.value = t;
- }
- static empty() {
- return new hn({
- 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)],
- !nn(e)) return null;
- return e = (e.mapValue.fields || {})[t.lastSegment()], e || null;
- }
- }
-
- set(t, e) {
- this.getFieldsMap(t.popLast())[t.lastSegment()] = sn(e);
- }
-
- setAll(t) {
- let e = lt.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()] = sn(t) : s.push(i.lastSegment());
- }));
- const i = this.getFieldsMap(e);
- this.applyChanges(i, n, s);
- }
-
- delete(t) {
- const e = this.field(t.popLast());
- nn(e) && e.mapValue.fields && delete e.mapValue.fields[t.lastSegment()];
- }
- isEqual(t) {
- return Ge(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)];
- nn(s) && s.mapValue.fields || (s = {
- mapValue: {
- fields: {}
- }
- }, e.mapValue.fields[t.get(n)] = s), e = s;
- }
- return e.mapValue.fields;
- }
-
- applyChanges(t, e, n) {
- pe(e, ((e, n) => t[e] = n));
- for (const e of n) delete t[e];
- }
- clone() {
- return new hn(sn(this.value));
- }
- }
- function ln(t) {
- const e = [];
- return pe(t.fields, ((t, n) => {
- const s = new lt([ t ]);
- if (nn(n)) {
- const t = ln(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 be(e);
- }
- class fn {
- 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 fn(t, 0 ,
- ut.min(),
- ut.min(),
- ut.min(), hn.empty(), 0 );
- }
-
- static newFoundDocument(t, e, n, s) {
- return new fn(t, 1 ,
- e,
- ut.min(),
- n, s, 0 );
- }
- static newNoDocument(t, e) {
- return new fn(t, 2 ,
- e,
- ut.min(),
- ut.min(), hn.empty(), 0 );
- }
-
- static newUnknownDocument(t, e) {
- return new fn(t, 3 ,
- e,
- ut.min(),
- ut.min(), hn.empty(), 2 );
- }
-
- convertToFoundDocument(t, e) {
-
-
-
-
-
- return !this.createTime.isEqual(ut.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 = hn.empty(), this.documentState = 0 , this;
- }
-
- convertToUnknownDocument(t) {
- return this.version = t, this.documentType = 3 ,
- this.data = hn.empty(), this.documentState = 2 ,
- this;
- }
- setHasCommittedMutations() {
- return this.documentState = 2 , this;
- }
- setHasLocalMutations() {
- return this.documentState = 1 , this.version = ut.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 fn && 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 fn(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 dn {
- constructor(t, e) {
- this.position = t, this.inclusive = e;
- }
- }
- function wn(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 = ft.comparator(ft.fromName(o.referenceValue), n.key); else {
- s = je(o, n.data.field(r.field));
- }
- if ("desc" === r.dir && (s *= -1), 0 !== s) break;
- }
- return s;
- }
- function _n(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 (!Ge(t.position[n], e.position[n])) return !1;
- }
- return !0;
- }
- class mn {
- constructor(t, e = "asc" /* Direction.ASCENDING */) {
- this.field = t, this.dir = e;
- }
- }
- function gn(t, e) {
- return t.dir === e.dir && t.field.isEqual(e.field);
- }
- class yn {}
- class pn extends yn {
- 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 Sn(t, e, n) : "array-contains" === e ? new Nn(t, n) : "in" === e ? new kn(t, n) : "not-in" === e ? new $n(t, n) : "array-contains-any" === e ? new Mn(t, n) : new pn(t, e, n);
- }
- static createKeyFieldInFilter(t, e, n) {
- return "in" === e ? new Dn(t, n) : new Cn(t, n);
- }
- matches(t) {
- const e = t.data.field(this.field);
-
- return "!=" === this.op ? null !== e && this.matchesComparison(je(e, this.value)) : null !== e && Ke(this.value) === Ke(e) && this.matchesComparison(je(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 B();
- }
- }
- isInequality() {
- return [ "<" , "<=" , ">" , ">=" , "!=" , "not-in" ].indexOf(this.op) >= 0;
- }
- getFlattenedFilters() {
- return [ this ];
- }
- getFilters() {
- return [ this ];
- }
- getFirstInequalityField() {
- return this.isInequality() ? this.field : null;
- }
- }
- class In extends yn {
- constructor(t, e) {
- super(), this.filters = t, this.op = e, this.lt = null;
- }
-
- static create(t, e) {
- return new In(t, e);
- }
- matches(t) {
- return Tn(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 Tn(t) {
- return "and" === t.op;
- }
- function En(t) {
- return "or" === t.op;
- }
- function An(t) {
- return vn(t) && Tn(t);
- }
- function vn(t) {
- for (const e of t.filters) if (e instanceof In) return !1;
- return !0;
- }
- function Rn(t) {
- if (t instanceof pn)
-
-
-
- return t.field.canonicalString() + t.op.toString() + We(t.value);
- if (An(t))
-
-
-
-
-
-
- return t.filters.map((t => Rn(t))).join(",");
- {
-
- const e = t.filters.map((t => Rn(t))).join(",");
- return `${t.op}(${e})`;
- }
- }
- function Pn(t, e) {
- return t instanceof pn ? function(t, e) {
- return e instanceof pn && t.op === e.op && t.field.isEqual(e.field) && Ge(t.value, e.value);
- }(t, e) : t instanceof In ? function(t, e) {
- if (e instanceof In && t.op === e.op && t.filters.length === e.filters.length) {
- return t.filters.reduce(((t, n, s) => t && Pn(n, e.filters[s])), !0);
- }
- return !1;
- }
-
- (t, e) : void B();
- }
- function bn(t, e) {
- const n = t.filters.concat(e);
- return In.create(n, t.op);
- }
- function Vn(t) {
- return t instanceof pn ? function(t) {
- return `${t.field.canonicalString()} ${t.op} ${We(t.value)}`;
- }
- (t) : t instanceof In ? function(t) {
- return t.op.toString() + " {" + t.getFilters().map(Vn).join(" ,") + "}";
- }(t) : "Filter";
- }
- class Sn extends pn {
- constructor(t, e, n) {
- super(t, e, n), this.key = ft.fromName(n.referenceValue);
- }
- matches(t) {
- const e = ft.comparator(t.key, this.key);
- return this.matchesComparison(e);
- }
- }
- class Dn extends pn {
- constructor(t, e) {
- super(t, "in" , e), this.keys = xn("in" , e);
- }
- matches(t) {
- return this.keys.some((e => e.isEqual(t.key)));
- }
- }
- class Cn extends pn {
- constructor(t, e) {
- super(t, "not-in" , e), this.keys = xn("not-in" , e);
- }
- matches(t) {
- return !this.keys.some((e => e.isEqual(t.key)));
- }
- }
- function xn(t, e) {
- var n;
- return ((null === (n = e.arrayValue) || void 0 === n ? void 0 : n.values) || []).map((t => ft.fromName(t.referenceValue)));
- }
- class Nn extends pn {
- constructor(t, e) {
- super(t, "array-contains" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return Ze(e) && Qe(e.arrayValue, this.value);
- }
- }
- class kn extends pn {
- constructor(t, e) {
- super(t, "in" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return null !== e && Qe(this.value.arrayValue, e);
- }
- }
- class $n extends pn {
- constructor(t, e) {
- super(t, "not-in" , e);
- }
- matches(t) {
- if (Qe(this.value.arrayValue, {
- nullValue: "NULL_VALUE"
- })) return !1;
- const e = t.data.field(this.field);
- return null !== e && !Qe(this.value.arrayValue, e);
- }
- }
- class Mn extends pn {
- constructor(t, e) {
- super(t, "array-contains-any" , e);
- }
- matches(t) {
- const e = t.data.field(this.field);
- return !(!Ze(e) || !e.arrayValue.values) && e.arrayValue.values.some((t => Qe(this.value.arrayValue, t)));
- }
- }
- class On {
- 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 Fn(t, e = null, n = [], s = [], i = null, r = null, o = null) {
- return new On(t, e, n, s, i, r, o);
- }
- function Bn(t) {
- const e = U(t);
- if (null === e.dt) {
- let t = e.path.canonicalString();
- null !== e.collectionGroup && (t += "|cg:" + e.collectionGroup), t += "|f:", t += e.filters.map((t => Rn(t))).join(","),
- t += "|ob:", t += e.orderBy.map((t => function(t) {
-
- return t.field.canonicalString() + t.dir;
- }(t))).join(","), Lt(e.limit) || (t += "|l:", t += e.limit), e.startAt && (t += "|lb:",
- t += e.startAt.inclusive ? "b:" : "a:", t += e.startAt.position.map((t => We(t))).join(",")),
- e.endAt && (t += "|ub:", t += e.endAt.inclusive ? "a:" : "b:", t += e.endAt.position.map((t => We(t))).join(",")),
- e.dt = t;
- }
- return e.dt;
- }
- function Ln(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 (!gn(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 (!Pn(t.filters[n], e.filters[n])) return !1;
- return t.collectionGroup === e.collectionGroup && (!!t.path.isEqual(e.path) && (!!_n(t.startAt, e.startAt) && _n(t.endAt, e.endAt)));
- }
- function qn(t) {
- return ft.isDocumentKey(t.path) && null === t.collectionGroup && 0 === t.filters.length;
- }
- function Un(t, e) {
- return t.filters.filter((t => t instanceof pn && t.field.isEqual(e)));
- }
- function Kn(t, e, n) {
- let s = Ue, i = !0;
-
- for (const n of Un(t, e)) {
- let t = Ue, e = !0;
- switch (n.op) {
- case "<" :
- case "<=" :
- t = on(n.value);
- break;
- case "==" :
- case "in" :
- case ">=" :
- t = n.value;
- break;
- case ">" :
- t = n.value, e = !1;
- break;
- case "!=" :
- case "not-in" :
- t = Ue;
-
- }
- cn({
- 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];
- cn({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: n.inclusive
- }) < 0 && (s = t, i = n.inclusive);
- break;
- }
- }
- return {
- value: s,
- inclusive: i
- };
- }
- function Gn(t, e, n) {
- let s = qe, i = !0;
-
- for (const n of Un(t, e)) {
- let t = qe, e = !0;
- switch (n.op) {
- case ">=" :
- case ">" :
- t = un(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 = qe;
-
- }
- an({
- 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];
- an({
- value: s,
- inclusive: i
- }, {
- value: t,
- inclusive: n.inclusive
- }) > 0 && (s = t, i = n.inclusive);
- break;
- }
- }
- return {
- value: s,
- inclusive: i
- };
- }
- class Qn {
-
- 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 jn(t, e, n, s, i, r, o, u) {
- return new Qn(t, e, n, s, i, r, o, u);
- }
- function zn(t) {
- return new Qn(t);
- }
- function Wn(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 Hn(t) {
- return t.explicitOrderBy.length > 0 ? t.explicitOrderBy[0].field : null;
- }
- function Jn(t) {
- for (const e of t.filters) {
- const t = e.getFirstInequalityField();
- if (null !== t) return t;
- }
- return null;
- }
- function Yn(t) {
- return null !== t.collectionGroup;
- }
- function Xn(t) {
- const e = U(t);
- if (null === e.wt) {
- e.wt = [];
- const t = Jn(e), n = Hn(e);
- if (null !== t && null === n)
-
-
-
- t.isKeyField() || e.wt.push(new mn(t)), e.wt.push(new mn(lt.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 mn(lt.keyField(), t));
- }
- }
- }
- return e.wt;
- }
- function Zn(t) {
- const e = U(t);
- if (!e._t) if ("F" === e.limitType) e._t = Fn(e.path, e.collectionGroup, Xn(e), e.filters, e.limit, e.startAt, e.endAt); else {
-
- const t = [];
- for (const n of Xn(e)) {
- const e = "desc" === n.dir ? "asc" : "desc" ;
- t.push(new mn(n.field, e));
- }
-
- const n = e.endAt ? new dn(e.endAt.position, e.endAt.inclusive) : null, s = e.startAt ? new dn(e.startAt.position, e.startAt.inclusive) : null;
-
- e._t = Fn(e.path, e.collectionGroup, t, e.filters, e.limit, n, s);
- }
- return e._t;
- }
- function ts(t, e) {
- e.getFirstInequalityField(), Jn(t);
- const n = t.filters.concat([ e ]);
- return new Qn(t.path, t.collectionGroup, t.explicitOrderBy.slice(), n, t.limit, t.limitType, t.startAt, t.endAt);
- }
- function es(t, e, n) {
- return new Qn(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), e, n, t.startAt, t.endAt);
- }
- function ns(t, e) {
- return Ln(Zn(t), Zn(e)) && t.limitType === e.limitType;
- }
- function ss(t) {
- return `${Bn(Zn(t))}|lt:${t.limitType}`;
- }
- function is(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 => Vn(t))).join(", ")}]`),
- Lt(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 => We(t))).join(",")), t.endAt && (e += ", endAt: ",
- e += t.endAt.inclusive ? "a:" : "b:", e += t.endAt.position.map((t => We(t))).join(",")),
- `Target(${e})`;
- }(Zn(t))}; limitType=${t.limitType})`;
- }
- function rs(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) : ft.isDocumentKey(t.path) ? t.path.isEqual(n) : t.path.isImmediateParentOf(n);
- }
-
- (t, e) && function(t, e) {
-
-
-
-
-
-
- for (const n of Xn(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 = wn(t, e, n);
- return t.inclusive ? s <= 0 : s < 0;
- }(t.startAt, Xn(t), e)) return !1;
- if (t.endAt && !function(t, e, n) {
- const s = wn(t, e, n);
- return t.inclusive ? s >= 0 : s > 0;
- }(t.endAt, Xn(t), e)) return !1;
- return !0;
- }
-
- (t, e);
- }
- function os(t) {
- return t.collectionGroup || (t.path.length % 2 == 1 ? t.path.lastSegment() : t.path.get(t.path.length - 2));
- }
- function us(t) {
- return (e, n) => {
- let s = !1;
- for (const i of Xn(t)) {
- const t = cs(i, e, n);
- if (0 !== t) return t;
- s = s || i.field.isKeyField();
- }
- return 0;
- };
- }
- function cs(t, e, n) {
- const s = t.field.isKeyField() ? ft.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 ? je(s, i) : B();
- }(t.field, e, n);
- switch (t.dir) {
- case "asc" :
- return s;
- case "desc" :
- return -1 * s;
- default:
- return B();
- }
- }
- class as {
- 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) {
- pe(this.inner, ((e, n) => {
- for (const [e, s] of n) t(e, s);
- }));
- }
- isEmpty() {
- return Ie(this.inner);
- }
- size() {
- return this.innerSize;
- }
- }
- const hs = new Te(ft.comparator);
- function ls() {
- return hs;
- }
- const fs = new Te(ft.comparator);
- function ds(...t) {
- let e = fs;
- for (const n of t) e = e.insert(n.key, n);
- return e;
- }
- function ws(t) {
- let e = fs;
- return t.forEach(((t, n) => e = e.insert(t, n.overlayedDocument))), e;
- }
- function _s() {
- return gs();
- }
- function ms() {
- return gs();
- }
- function gs() {
- return new as((t => t.toString()), ((t, e) => t.isEqual(e)));
- }
- const ys = new Te(ft.comparator);
- const ps = new ve(ft.comparator);
- function Is(...t) {
- let e = ps;
- for (const n of t) e = e.add(n);
- return e;
- }
- const Ts = new ve(st);
- function Es() {
- return Ts;
- }
- function As(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: qt(e) ? "-0" : e
- };
- }
- function vs(t) {
- return {
- integerValue: "" + t
- };
- }
- function Rs(t, e) {
- return Ut(e) ? vs(e) : As(t, e);
- }
- class Ps {
- constructor() {
-
-
- this._ = void 0;
- }
- }
- function bs(t, e, n) {
- return t instanceof Ds ? function(t, e) {
- const n = {
- fields: {
- __type__: {
- stringValue: "server_timestamp"
- },
- __local_write_time__: {
- timestampValue: {
- seconds: t.seconds,
- nanos: t.nanoseconds
- }
- }
- }
- };
-
-
-
-
-
-
-
-
- return e && Me(e) && (e = Oe(e)), e && (n.fields.__previous_value__ = e),
- {
- mapValue: n
- };
- }(n, e) : t instanceof Cs ? xs(t, e) : t instanceof Ns ? ks(t, e) : function(t, e) {
-
-
-
- const n = Ss(t, e), s = Ms(n) + Ms(t.gt);
- return Xe(n) && Xe(t.gt) ? vs(s) : As(t.serializer, s);
- }(t, e);
- }
- function Vs(t, e, n) {
-
-
-
- return t instanceof Cs ? xs(t, e) : t instanceof Ns ? ks(t, e) : n;
- }
- function Ss(t, e) {
- return t instanceof $s ? Xe(n = e) || function(t) {
- return !!t && "doubleValue" in t;
- }
- (n) ? e : {
- integerValue: 0
- } : null;
- var n;
- }
- class Ds extends Ps {}
- class Cs extends Ps {
- constructor(t) {
- super(), this.elements = t;
- }
- }
- function xs(t, e) {
- const n = Os(e);
- for (const e of t.elements) n.some((t => Ge(t, e))) || n.push(e);
- return {
- arrayValue: {
- values: n
- }
- };
- }
- class Ns extends Ps {
- constructor(t) {
- super(), this.elements = t;
- }
- }
- function ks(t, e) {
- let n = Os(e);
- for (const e of t.elements) n = n.filter((t => !Ge(t, e)));
- return {
- arrayValue: {
- values: n
- }
- };
- }
- class $s extends Ps {
- constructor(t, e) {
- super(), this.serializer = t, this.gt = e;
- }
- }
- function Ms(t) {
- return ke(t.integerValue || t.doubleValue);
- }
- function Os(t) {
- return Ze(t) && t.arrayValue.values ? t.arrayValue.values.slice() : [];
- }
- class Fs {
- constructor(t, e) {
- this.field = t, this.transform = e;
- }
- }
- function Bs(t, e) {
- return t.field.isEqual(e.field) && function(t, e) {
- return t instanceof Cs && e instanceof Cs || t instanceof Ns && e instanceof Ns ? it(t.elements, e.elements, Ge) : t instanceof $s && e instanceof $s ? Ge(t.gt, e.gt) : t instanceof Ds && e instanceof Ds;
- }(t.transform, e.transform);
- }
- class Ls {
- 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 qs {
- constructor(t, e) {
- this.updateTime = t, this.exists = e;
- }
- static none() {
- return new qs;
- }
- static exists(t) {
- return new qs(void 0, t);
- }
- static updateTime(t) {
- return new qs(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 Us(t, e) {
- return void 0 !== t.updateTime ? e.isFoundDocument() && e.version.isEqual(t.updateTime) : void 0 === t.exists || t.exists === e.isFoundDocument();
- }
- class Ks {}
- function Gs(t, e) {
- if (!t.hasLocalMutations || e && 0 === e.fields.length) return null;
-
- if (null === e) return t.isNoDocument() ? new ti(t.key, qs.none()) : new Hs(t.key, t.data, qs.none());
- {
- const n = t.data, s = hn.empty();
- let i = new ve(lt.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 Js(t.key, s, new be(i.toArray()), qs.none());
- }
- }
- function Qs(t, e, n) {
- t instanceof Hs ? function(t, e, n) {
-
-
-
- const s = t.value.clone(), i = Xs(t.fieldTransforms, e, n.transformResults);
- s.setAll(i), e.convertToFoundDocument(n.version, s).setHasCommittedMutations();
- }(t, e, n) : t instanceof Js ? function(t, e, n) {
- if (!Us(t.precondition, e))
-
-
-
-
- return void e.convertToUnknownDocument(n.version);
- const s = Xs(t.fieldTransforms, e, n.transformResults), i = e.data;
- i.setAll(Ys(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 js(t, e, n, s) {
- return t instanceof Hs ? function(t, e, n, s) {
- if (!Us(t.precondition, e))
-
-
- return n;
- const i = t.value.clone(), r = Zs(t.fieldTransforms, s, e);
- return i.setAll(r), e.convertToFoundDocument(e.version, i).setHasLocalMutations(),
- null;
-
- }
-
- (t, e, n, s) : t instanceof Js ? function(t, e, n, s) {
- if (!Us(t.precondition, e)) return n;
- const i = Zs(t.fieldTransforms, s, e), r = e.data;
- if (r.setAll(Ys(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 (Us(t.precondition, e)) return e.convertToNoDocument(e.version).setHasLocalMutations(),
- null;
- return n;
- }
-
- (t, e, n);
- }
- function zs(t, e) {
- let n = null;
- for (const s of t.fieldTransforms) {
- const t = e.data.field(s.field), i = Ss(s.transform, t || null);
- null != i && (null === n && (n = hn.empty()), n.set(s.field, i));
- }
- return n || null;
- }
- function Ws(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) && it(t, e, ((t, e) => Bs(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 Hs extends Ks {
- 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 Js extends Ks {
- 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 Ys(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 Xs(t, e, n) {
- const s = new Map;
- L(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, Vs(o, u, n[i]));
- }
- return s;
- }
- function Zs(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, bs(t, r, e));
- }
- return s;
- }
- class ti extends Ks {
- constructor(t, e) {
- super(), this.key = t, this.precondition = e, this.type = 2 ,
- this.fieldTransforms = [];
- }
- getFieldMask() {
- return null;
- }
- }
- class ei extends Ks {
- constructor(t, e) {
- super(), this.key = t, this.precondition = e, this.type = 3 ,
- this.fieldTransforms = [];
- }
- getFieldMask() {
- return null;
- }
- }
- class ni {
-
- 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)) {
- Qs(s, t, n[e]);
- }
- }
- }
-
- applyToLocalView(t, e) {
-
-
- for (const n of this.baseMutations) n.key.isEqual(t.key) && (e = js(n, t, e, this.localWriteTime));
-
- for (const n of this.mutations) n.key.isEqual(t.key) && (e = js(n, t, e, this.localWriteTime));
- return e;
- }
-
- applyToLocalDocumentSet(t, e) {
-
-
-
- const n = ms();
- 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 = Gs(r, o);
- null !== u && n.set(s.key, u), r.isValidDocument() || r.convertToNoDocument(ut.min());
- })), n;
- }
- keys() {
- return this.mutations.reduce(((t, e) => t.add(e.key)), Is());
- }
- isEqual(t) {
- return this.batchId === t.batchId && it(this.mutations, t.mutations, ((t, e) => Ws(t, e))) && it(this.baseMutations, t.baseMutations, ((t, e) => Ws(t, e)));
- }
- }
- class si {
- 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) {
- L(t.mutations.length === n.length);
- let s = ys;
- const i = t.mutations;
- for (let t = 0; t < i.length; t++) s = s.insert(i[t].key, n[t].version);
- return new si(t, e, n, s);
- }
- }
- class ii {
- 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 ri {
- constructor(t, e, n) {
- this.alias = t, this.yt = e, this.fieldPath = n;
- }
- }
- class oi {
- constructor(t, e) {
- this.count = t, this.unchangedNames = e;
- }
- }
- var ui, ci;
- function ai(t) {
- switch (t) {
- default:
- return B();
- case K.CANCELLED:
- case K.UNKNOWN:
- case K.DEADLINE_EXCEEDED:
- case K.RESOURCE_EXHAUSTED:
- case K.INTERNAL:
- case K.UNAVAILABLE:
-
-
- case K.UNAUTHENTICATED:
- return !1;
- case K.INVALID_ARGUMENT:
- case K.NOT_FOUND:
- case K.ALREADY_EXISTS:
- case K.PERMISSION_DENIED:
- case K.FAILED_PRECONDITION:
-
-
-
- case K.ABORTED:
- case K.OUT_OF_RANGE:
- case K.UNIMPLEMENTED:
- case K.DATA_LOSS:
- return !0;
- }
- }
- function hi(t) {
- if (void 0 === t)
-
-
- return M("GRPC error has no .code"), K.UNKNOWN;
- switch (t) {
- case ui.OK:
- return K.OK;
- case ui.CANCELLED:
- return K.CANCELLED;
- case ui.UNKNOWN:
- return K.UNKNOWN;
- case ui.DEADLINE_EXCEEDED:
- return K.DEADLINE_EXCEEDED;
- case ui.RESOURCE_EXHAUSTED:
- return K.RESOURCE_EXHAUSTED;
- case ui.INTERNAL:
- return K.INTERNAL;
- case ui.UNAVAILABLE:
- return K.UNAVAILABLE;
- case ui.UNAUTHENTICATED:
- return K.UNAUTHENTICATED;
- case ui.INVALID_ARGUMENT:
- return K.INVALID_ARGUMENT;
- case ui.NOT_FOUND:
- return K.NOT_FOUND;
- case ui.ALREADY_EXISTS:
- return K.ALREADY_EXISTS;
- case ui.PERMISSION_DENIED:
- return K.PERMISSION_DENIED;
- case ui.FAILED_PRECONDITION:
- return K.FAILED_PRECONDITION;
- case ui.ABORTED:
- return K.ABORTED;
- case ui.OUT_OF_RANGE:
- return K.OUT_OF_RANGE;
- case ui.UNIMPLEMENTED:
- return K.UNIMPLEMENTED;
- case ui.DATA_LOSS:
- return K.DATA_LOSS;
- default:
- return B();
- }
- }
- (ci = ui || (ui = {}))[ci.OK = 0] = "OK", ci[ci.CANCELLED = 1] = "CANCELLED",
- ci[ci.UNKNOWN = 2] = "UNKNOWN", ci[ci.INVALID_ARGUMENT = 3] = "INVALID_ARGUMENT",
- ci[ci.DEADLINE_EXCEEDED = 4] = "DEADLINE_EXCEEDED", ci[ci.NOT_FOUND = 5] = "NOT_FOUND",
- ci[ci.ALREADY_EXISTS = 6] = "ALREADY_EXISTS", ci[ci.PERMISSION_DENIED = 7] = "PERMISSION_DENIED",
- ci[ci.UNAUTHENTICATED = 16] = "UNAUTHENTICATED", ci[ci.RESOURCE_EXHAUSTED = 8] = "RESOURCE_EXHAUSTED",
- ci[ci.FAILED_PRECONDITION = 9] = "FAILED_PRECONDITION", ci[ci.ABORTED = 10] = "ABORTED",
- ci[ci.OUT_OF_RANGE = 11] = "OUT_OF_RANGE", ci[ci.UNIMPLEMENTED = 12] = "UNIMPLEMENTED",
- ci[ci.INTERNAL = 13] = "INTERNAL", ci[ci.UNAVAILABLE = 14] = "UNAVAILABLE", ci[ci.DATA_LOSS = 15] = "DATA_LOSS";
- class li {
- constructor() {
- this.onExistenceFilterMismatchCallbacks = new Map;
- }
-
- static get instance() {
- return fi;
- }
-
- static getOrCreateInstance() {
- return null === fi && (fi = new li), fi;
- }
-
- onExistenceFilterMismatch(t) {
- const e = Symbol();
- return this.onExistenceFilterMismatchCallbacks.set(e, t), () => this.onExistenceFilterMismatchCallbacks.delete(e);
- }
-
- notifyOnExistenceFilterMismatch(t) {
- this.onExistenceFilterMismatchCallbacks.forEach((e => e(t)));
- }
- }
- let fi = null;
- function di() {
- return new TextEncoder;
- }
- const wi = new y([ 4294967295, 4294967295 ], 0);
- function _i(t) {
- const e = di().encode(t), n = new p;
- return n.update(e), new Uint8Array(n.digest());
- }
- function mi(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 y([ n, s ], 0), new y([ i, r ], 0) ];
- }
- class gi {
- constructor(t, e, n) {
- if (this.bitmap = t, this.padding = e, this.hashCount = n, e < 0 || e >= 8) throw new yi(`Invalid padding: ${e}`);
- if (n < 0) throw new yi(`Invalid hash count: ${n}`);
- if (t.length > 0 && 0 === this.hashCount)
-
- throw new yi(`Invalid hash count: ${n}`);
- if (0 === t.length && 0 !== e)
-
- throw new yi(`Invalid padding when bitmap length is 0: ${e}`);
- this.It = 8 * t.length - e,
-
- this.Tt = y.fromNumber(this.It);
- }
-
-
- Et(t, e, n) {
-
- let s = t.add(e.multiply(y.fromNumber(n)));
-
- return 1 === s.compare(wi) && (s = new y([ 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 = _i(t), [n, s] = mi(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 gi(i, s, e);
- return n.forEach((t => r.insert(t))), r;
- }
- insert(t) {
- if (0 === this.It) return;
- const e = _i(t), [n, s] = mi(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 yi extends Error {
- constructor() {
- super(...arguments), this.name = "BloomFilterError";
- }
- }
- class pi {
- 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, Ii.createSynthesizedTargetChangeForCurrentChange(t, e, n)), new pi(ut.min(), s, new Te(st), ls(), Is());
- }
- }
- class Ii {
- 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 Ii(n, e, Is(), Is(), Is());
- }
- }
- class Ti {
- 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 Ei {
- constructor(t, e) {
- this.targetId = t, this.Vt = e;
- }
- }
- class Ai {
- 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 = Ce.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 vi {
- constructor() {
-
- this.St = 0,
-
- this.Dt = bi(),
-
- this.Ct = Ce.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 $t() {
- return this.Nt;
- }
-
- Mt(t) {
- t.approximateByteSize() > 0 && (this.Nt = !0, this.Ct = t);
- }
-
- Ot() {
- let t = Is(), e = Is(), n = Is();
- 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:
- B();
- }
- })), new Ii(this.Ct, this.xt, t, e, n);
- }
-
- Ft() {
- this.Nt = !1, this.Dt = bi();
- }
- 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 Ri {
- constructor(t) {
- this.Gt = t,
-
- this.Qt = new Map,
-
- this.jt = ls(),
-
- this.zt = Pi(),
-
- this.Wt = new Te(st);
- }
-
- 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.Mt(t.resumeToken);
- break;
- case 1 :
-
-
- n.Ut(), n.kt ||
-
-
-
- n.Ft(), n.Mt(t.resumeToken);
- break;
- case 2 :
-
-
-
-
- n.Ut(), n.kt || this.removeTarget(e);
- break;
- case 3 :
- this.te(e) && (n.Kt(), n.Mt(t.resumeToken));
- break;
- case 4 :
- this.te(e) && (
-
-
-
- this.ee(e), n.Mt(t.resumeToken));
- break;
- default:
- B();
- }
- }));
- }
-
- 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 (qn(r)) if (0 === s) {
-
-
-
-
-
-
- const t = new ft(r.path);
- this.Yt(n, t, fn.newNoDocument(t, ut.min()));
- } else L(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 = li.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 = $e(i).toUint8Array();
- } catch (t) {
- if (t instanceof Ve) return O("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 gi(u, r, o);
- } catch (t) {
- return O(t instanceof yi ? "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 && qn(i.target)) {
-
-
-
-
-
-
-
-
- const e = new ft(i.target.path);
- null !== this.jt.get(e) || this.ae(s, e) || this.Yt(s, e, fn.newNoDocument(e, t));
- }
- n.$t && (e.set(s, n.Ot()), n.Ft());
- }
- }));
- let n = Is();
-
-
-
-
-
- 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 pi(t, e, this.Wt, this.jt, n);
- return this.jt = ls(), this.zt = Pi(), this.Wt = new Te(st), 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 vi, this.Qt.set(t, e)), e;
- }
- he(t) {
- let e = this.zt.get(t);
- return e || (e = new ve(st), this.zt = this.zt.insert(t, e)), e;
- }
-
- te(t) {
- const e = null !== this.se(t);
- return e || $("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 vi);
- this.Gt.getRemoteKeysForTarget(t).forEach((e => {
- this.Yt(t, e, null);
- }));
- }
-
- ae(t, e) {
- return this.Gt.getRemoteKeysForTarget(t).has(e);
- }
- }
- function Pi() {
- return new Te(ft.comparator);
- }
- function bi() {
- return new Te(ft.comparator);
- }
- const Vi = (() => {
- const t = {
- asc: "ASCENDING",
- desc: "DESCENDING"
- };
- return t;
- })(), Si = (() => {
- 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;
- })(), Di = (() => {
- const t = {
- and: "AND",
- or: "OR"
- };
- return t;
- })();
- class Ci {
- constructor(t, e) {
- this.databaseId = t, this.useProto3Json = e;
- }
- }
- function xi(t, e) {
- return t.useProto3Json || Lt(e) ? e : {
- value: e
- };
- }
- function Ni(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 ki(t, e) {
- return t.useProto3Json ? e.toBase64() : e.toUint8Array();
- }
- function $i(t, e) {
- return Ni(t, e.toTimestamp());
- }
- function Mi(t) {
- return L(!!t), ut.fromTimestamp(function(t) {
- const e = Ne(t);
- return new ot(e.seconds, e.nanos);
- }(t));
- }
- function Oi(t, e) {
- return function(t) {
- return new at([ "projects", t.projectId, "databases", t.database ]);
- }(t).child("documents").child(e).canonicalString();
- }
- function Fi(t) {
- const e = at.fromString(t);
- return L(hr(e)), e;
- }
- function Bi(t, e) {
- return Oi(t.databaseId, e.path);
- }
- function Li(t, e) {
- const n = Fi(e);
- if (n.get(1) !== t.databaseId.projectId) throw new G(K.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 G(K.INVALID_ARGUMENT, "Tried to deserialize key from different database: " + n.get(3) + " vs " + t.databaseId.database);
- return new ft(Gi(n));
- }
- function qi(t, e) {
- return Oi(t.databaseId, e);
- }
- function Ui(t) {
- const e = Fi(t);
-
-
-
-
- return 4 === e.length ? at.emptyPath() : Gi(e);
- }
- function Ki(t) {
- return new at([ "projects", t.databaseId.projectId, "databases", t.databaseId.database ]).canonicalString();
- }
- function Gi(t) {
- return L(t.length > 4 && "documents" === t.get(4)), t.popFirst(5);
- }
- function Qi(t, e, n) {
- return {
- name: Bi(t, e),
- fields: n.value.mapValue.fields
- };
- }
- function ji(t, e, n) {
- const s = Li(t, e.name), i = Mi(e.updateTime), r = e.createTime ? Mi(e.createTime) : ut.min(), o = new hn({
- mapValue: {
- fields: e.fields
- }
- }), u = fn.newFoundDocument(s, i, r, o);
- return n && u.setHasCommittedMutations(), n ? u.setHasCommittedMutations() : u;
- }
- function zi(t, e) {
- return "found" in e ? function(t, e) {
- L(!!e.found), e.found.name, e.found.updateTime;
- const n = Li(t, e.found.name), s = Mi(e.found.updateTime), i = e.found.createTime ? Mi(e.found.createTime) : ut.min(), r = new hn({
- mapValue: {
- fields: e.found.fields
- }
- });
- return fn.newFoundDocument(n, s, i, r);
- }(t, e) : "missing" in e ? function(t, e) {
- L(!!e.missing), L(!!e.readTime);
- const n = Li(t, e.missing), s = Mi(e.readTime);
- return fn.newNoDocument(n, s);
- }(t, e) : B();
- }
- function Wi(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 : B();
- }(e.targetChange.targetChangeType || "NO_CHANGE"), i = e.targetChange.targetIds || [], r = function(t, e) {
- return t.useProto3Json ? (L(void 0 === e || "string" == typeof e), Ce.fromBase64String(e || "")) : (L(void 0 === e || e instanceof Uint8Array),
- Ce.fromUint8Array(e || new Uint8Array));
- }(t, e.targetChange.resumeToken), o = e.targetChange.cause, u = o && function(t) {
- const e = void 0 === t.code ? K.UNKNOWN : hi(t.code);
- return new G(e, t.message || "");
- }(o);
- n = new Ai(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 = Li(t, s.document.name), r = Mi(s.document.updateTime), o = s.document.createTime ? Mi(s.document.createTime) : ut.min(), u = new hn({
- mapValue: {
- fields: s.document.fields
- }
- }), c = fn.newFoundDocument(i, r, o, u), a = s.targetIds || [], h = s.removedTargetIds || [];
- n = new Ti(a, h, c.key, c);
- } else if ("documentDelete" in e) {
- e.documentDelete;
- const s = e.documentDelete;
- s.document;
- const i = Li(t, s.document), r = s.readTime ? Mi(s.readTime) : ut.min(), o = fn.newNoDocument(i, r), u = s.removedTargetIds || [];
- n = new Ti([], u, o.key, o);
- } else if ("documentRemove" in e) {
- e.documentRemove;
- const s = e.documentRemove;
- s.document;
- const i = Li(t, s.document), r = s.removedTargetIds || [];
- n = new Ti([], r, i, null);
- } else {
- if (!("filter" in e)) return B();
- {
- e.filter;
- const t = e.filter;
- t.targetId;
- const {count: s = 0, unchangedNames: i} = t, r = new oi(s, i), o = t.targetId;
- n = new Ei(o, r);
- }
- }
- return n;
- }
- function Hi(t, e) {
- let n;
- if (e instanceof Hs) n = {
- update: Qi(t, e.key, e.value)
- }; else if (e instanceof ti) n = {
- delete: Bi(t, e.key)
- }; else if (e instanceof Js) n = {
- update: Qi(t, e.key, e.data),
- updateMask: ar(e.fieldMask)
- }; else {
- if (!(e instanceof ei)) return B();
- n = {
- verify: Bi(t, e.key)
- };
- }
- return e.fieldTransforms.length > 0 && (n.updateTransforms = e.fieldTransforms.map((t => function(t, e) {
- const n = e.transform;
- if (n instanceof Ds) return {
- fieldPath: e.field.canonicalString(),
- setToServerValue: "REQUEST_TIME"
- };
- if (n instanceof Cs) return {
- fieldPath: e.field.canonicalString(),
- appendMissingElements: {
- values: n.elements
- }
- };
- if (n instanceof Ns) return {
- fieldPath: e.field.canonicalString(),
- removeAllFromArray: {
- values: n.elements
- }
- };
- if (n instanceof $s) return {
- fieldPath: e.field.canonicalString(),
- increment: n.gt
- };
- throw B();
- }(0, t)))), e.precondition.isNone || (n.currentDocument = function(t, e) {
- return void 0 !== e.updateTime ? {
- updateTime: $i(t, e.updateTime)
- } : void 0 !== e.exists ? {
- exists: e.exists
- } : B();
- }(t, e.precondition)), n;
- }
- function Ji(t, e) {
- const n = e.currentDocument ? function(t) {
- return void 0 !== t.updateTime ? qs.updateTime(Mi(t.updateTime)) : void 0 !== t.exists ? qs.exists(t.exists) : qs.none();
- }(e.currentDocument) : qs.none(), s = e.updateTransforms ? e.updateTransforms.map((e => function(t, e) {
- let n = null;
- if ("setToServerValue" in e) L("REQUEST_TIME" === e.setToServerValue), n = new Ds; else if ("appendMissingElements" in e) {
- const t = e.appendMissingElements.values || [];
- n = new Cs(t);
- } else if ("removeAllFromArray" in e) {
- const t = e.removeAllFromArray.values || [];
- n = new Ns(t);
- } else "increment" in e ? n = new $s(t, e.increment) : B();
- const s = lt.fromServerFormat(e.fieldPath);
- return new Fs(s, n);
- }(t, e))) : [];
- if (e.update) {
- e.update.name;
- const i = Li(t, e.update.name), r = new hn({
- mapValue: {
- fields: e.update.fields
- }
- });
- if (e.updateMask) {
- const t = function(t) {
- const e = t.fieldPaths || [];
- return new be(e.map((t => lt.fromServerFormat(t))));
- }(e.updateMask);
- return new Js(i, r, t, n, s);
- }
- return new Hs(i, r, n, s);
- }
- if (e.delete) {
- const s = Li(t, e.delete);
- return new ti(s, n);
- }
- if (e.verify) {
- const s = Li(t, e.verify);
- return new ei(s, n);
- }
- return B();
- }
- function Yi(t, e) {
- return t && t.length > 0 ? (L(void 0 !== e), t.map((t => function(t, e) {
-
- let n = t.updateTime ? Mi(t.updateTime) : Mi(e);
- return n.isEqual(ut.min()) && (
-
-
-
-
-
- n = Mi(e)), new Ls(n, t.transformResults || []);
- }(t, e)))) : [];
- }
- function Xi(t, e) {
- return {
- documents: [ qi(t, e.path) ]
- };
- }
- function Zi(t, e) {
-
- const n = {
- structuredQuery: {}
- }, s = e.path;
- null !== e.collectionGroup ? (n.parent = qi(t, s), n.structuredQuery.from = [ {
- collectionId: e.collectionGroup,
- allDescendants: !0
- } ]) : (n.parent = qi(t, s.popLast()), n.structuredQuery.from = [ {
- collectionId: s.lastSegment()
- } ]);
- const i = function(t) {
- if (0 === t.length) return;
- return cr(In.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: or(t.field),
- direction: sr(t.dir)
- };
- }(t)));
- }(e.orderBy);
- r && (n.structuredQuery.orderBy = r);
- const o = xi(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 tr(t) {
- let e = Ui(t.parent);
- const n = t.structuredQuery, s = n.from ? n.from.length : 0;
- let i = null;
- if (s > 0) {
- L(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 = nr(t);
- if (e instanceof In && An(e)) return e.getFilters();
- return [ e ];
- }(n.where));
- let o = [];
- n.orderBy && (o = n.orderBy.map((t => function(t) {
- return new mn(ur(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, Lt(e) ? null : e;
- }(n.limit));
- let c = null;
- n.startAt && (c = function(t) {
- const e = !!t.before, n = t.values || [];
- return new dn(n, e);
- }(n.startAt));
- let a = null;
- return n.endAt && (a = function(t) {
- const e = !t.before, n = t.values || [];
- return new dn(n, e);
- }
-
- (n.endAt)), jn(e, i, o, r, u, "F" , c, a);
- }
- function er(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 B();
- }
- }(e.purpose);
- return null == n ? null : {
- "goog-listen-tags": n
- };
- }
- function nr(t) {
- return void 0 !== t.unaryFilter ? function(t) {
- switch (t.unaryFilter.op) {
- case "IS_NAN":
- const e = ur(t.unaryFilter.field);
- return pn.create(e, "==" , {
- doubleValue: NaN
- });
- case "IS_NULL":
- const n = ur(t.unaryFilter.field);
- return pn.create(n, "==" , {
- nullValue: "NULL_VALUE"
- });
- case "IS_NOT_NAN":
- const s = ur(t.unaryFilter.field);
- return pn.create(s, "!=" , {
- doubleValue: NaN
- });
- case "IS_NOT_NULL":
- const i = ur(t.unaryFilter.field);
- return pn.create(i, "!=" , {
- nullValue: "NULL_VALUE"
- });
- default:
- return B();
- }
- }(t) : void 0 !== t.fieldFilter ? function(t) {
- return pn.create(ur(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 B();
- }
- }(t.fieldFilter.op), t.fieldFilter.value);
- }(t) : void 0 !== t.compositeFilter ? function(t) {
- return In.create(t.compositeFilter.filters.map((t => nr(t))), function(t) {
- switch (t) {
- case "AND":
- return "and" ;
- case "OR":
- return "or" ;
- default:
- return B();
- }
- }(t.compositeFilter.op));
- }(t) : B();
- }
- function sr(t) {
- return Vi[t];
- }
- function ir(t) {
- return Si[t];
- }
- function rr(t) {
- return Di[t];
- }
- function or(t) {
- return {
- fieldPath: t.canonicalString()
- };
- }
- function ur(t) {
- return lt.fromServerFormat(t.fieldPath);
- }
- function cr(t) {
- return t instanceof pn ? function(t) {
- if ("==" === t.op) {
- if (en(t.value)) return {
- unaryFilter: {
- field: or(t.field),
- op: "IS_NAN"
- }
- };
- if (tn(t.value)) return {
- unaryFilter: {
- field: or(t.field),
- op: "IS_NULL"
- }
- };
- } else if ("!=" === t.op) {
- if (en(t.value)) return {
- unaryFilter: {
- field: or(t.field),
- op: "IS_NOT_NAN"
- }
- };
- if (tn(t.value)) return {
- unaryFilter: {
- field: or(t.field),
- op: "IS_NOT_NULL"
- }
- };
- }
- return {
- fieldFilter: {
- field: or(t.field),
- op: ir(t.op),
- value: t.value
- }
- };
- }(t) : t instanceof In ? function(t) {
- const e = t.getFilters().map((t => cr(t)));
- if (1 === e.length) return e[0];
- return {
- compositeFilter: {
- op: rr(t.op),
- filters: e
- }
- };
- }(t) : B();
- }
- function ar(t) {
- const e = [];
- return t.fields.forEach((t => e.push(t.canonicalString()))), {
- fieldPaths: e
- };
- }
- function hr(t) {
-
- return t.length >= 4 && "projects" === t.get(0) && "databases" === t.get(2);
- }
- class lr {
- 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 = ut.min()
- /**
- * The maximum snapshot version at which the associated view
- * contained no limbo documents.
- */ , r = ut.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 = Ce.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 lr(this.target, this.targetId, this.purpose, t, this.snapshotVersion, this.lastLimboFreeSnapshotVersion, this.resumeToken, this.expectedCount);
- }
-
- withResumeToken(t, e) {
- return new lr(this.target, this.targetId, this.purpose, this.sequenceNumber, e, this.lastLimboFreeSnapshotVersion, t,
- null);
- }
-
- withExpectedCount(t) {
- return new lr(this.target, this.targetId, this.purpose, this.sequenceNumber, this.snapshotVersion, this.lastLimboFreeSnapshotVersion, this.resumeToken, t);
- }
-
- withLastLimboFreeSnapshotVersion(t) {
- return new lr(this.target, this.targetId, this.purpose, this.sequenceNumber, this.snapshotVersion, t, this.resumeToken, this.expectedCount);
- }
- }
- class fr {
- constructor(t) {
- this.fe = t;
- }
- }
- function dr(t, e) {
- let n;
- if (e.document) n = ji(t.fe, e.document, !!e.hasCommittedMutations); else if (e.noDocument) {
- const t = ft.fromSegments(e.noDocument.path), s = gr(e.noDocument.readTime);
- n = fn.newNoDocument(t, s), e.hasCommittedMutations && n.setHasCommittedMutations();
- } else {
- if (!e.unknownDocument) return B();
- {
- const t = ft.fromSegments(e.unknownDocument.path), s = gr(e.unknownDocument.version);
- n = fn.newUnknownDocument(t, s);
- }
- }
- return e.readTime && n.setReadTime(function(t) {
- const e = new ot(t[0], t[1]);
- return ut.fromTimestamp(e);
- }(e.readTime)), n;
- }
- function wr(t, e) {
- const n = e.key, s = {
- prefixPath: n.getCollectionPath().popLast().toArray(),
- collectionGroup: n.collectionGroup,
- documentId: n.path.lastSegment(),
- readTime: _r(e.readTime),
- hasCommittedMutations: e.hasCommittedMutations
- };
- if (e.isFoundDocument()) s.document = function(t, e) {
- return {
- name: Bi(t, e.key),
- fields: e.data.value.mapValue.fields,
- updateTime: Ni(t, e.version.toTimestamp()),
- createTime: Ni(t, e.createTime.toTimestamp())
- };
- }(t.fe, e); else if (e.isNoDocument()) s.noDocument = {
- path: n.path.toArray(),
- readTime: mr(e.version)
- }; else {
- if (!e.isUnknownDocument()) return B();
- s.unknownDocument = {
- path: n.path.toArray(),
- version: mr(e.version)
- };
- }
- return s;
- }
- function _r(t) {
- const e = t.toTimestamp();
- return [ e.seconds, e.nanoseconds ];
- }
- function mr(t) {
- const e = t.toTimestamp();
- return {
- seconds: e.seconds,
- nanoseconds: e.nanoseconds
- };
- }
- function gr(t) {
- const e = new ot(t.seconds, t.nanoseconds);
- return ut.fromTimestamp(e);
- }
- function yr(t, e) {
- const n = (e.baseMutations || []).map((e => Ji(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 => Ji(t.fe, e))), i = ot.fromMillis(e.localWriteTimeMs);
- return new ni(e.batchId, i, n, s);
- }
- function pr(t) {
- const e = gr(t.readTime), n = void 0 !== t.lastLimboFreeSnapshotVersion ? gr(t.lastLimboFreeSnapshotVersion) : ut.min();
- let s;
- var i;
- return void 0 !== t.query.documents ? (L(1 === (i = t.query).documents.length),
- s = Zn(zn(Ui(i.documents[0])))) : s = function(t) {
- return Zn(tr(t));
- }(t.query), new lr(s, t.targetId, "TargetPurposeListen" , t.lastListenSequenceNumber, e, n, Ce.fromBase64String(t.resumeToken));
- }
- function Ir(t, e) {
- const n = mr(e.snapshotVersion), s = mr(e.lastLimboFreeSnapshotVersion);
- let i;
- i = qn(e.target) ? Xi(t.fe, e.target) : Zi(t.fe, e.target);
-
-
- const r = e.resumeToken.toBase64();
-
- return {
- targetId: e.targetId,
- canonicalId: Bn(e.target),
- readTime: n,
- resumeToken: r,
- lastListenSequenceNumber: e.sequenceNumber,
- lastLimboFreeSnapshotVersion: s,
- query: i
- };
- }
- function Tr(t) {
- const e = tr({
- parent: t.parent,
- structuredQuery: t.structuredQuery
- });
- return "LAST" === t.limitType ? es(e, e.limit, "L" ) : e;
- }
- function Er(t, e) {
- return new ii(e.largestBatchId, Ji(t.fe, e.overlayMutation));
- }
- function Ar(t, e) {
- const n = e.path.lastSegment();
- return [ t, Kt(e.path.popLast()), n ];
- }
- function vr(t, e, n, s) {
- return {
- indexId: t,
- uid: e.uid || "",
- sequenceNumber: n,
- readTime: mr(s.readTime),
- documentKey: Kt(s.documentKey.path),
- largestBatchId: s.largestBatchId
- };
- }
- class Rr {
- getBundleMetadata(t, e) {
- return Pr(t).get(e).next((t => {
- if (t) return {
- id: (e = t).bundleId,
- createTime: gr(e.createTime),
- version: e.version
- };
-
- var e;
- }));
- }
- saveBundleMetadata(t, e) {
- return Pr(t).put({
- bundleId: (n = e).id,
- createTime: mr(Mi(n.createTime)),
- version: n.version
- });
- var n;
- }
- getNamedQuery(t, e) {
- return br(t).get(e).next((t => {
- if (t) return {
- name: (e = t).name,
- query: Tr(e.bundledQuery),
- readTime: gr(e.readTime)
- };
- var e;
- }));
- }
- saveNamedQuery(t, e) {
- return br(t).put(function(t) {
- return {
- name: t.name,
- readTime: mr(Mi(t.readTime)),
- bundledQuery: t.bundledQuery
- };
- }(e));
- }
- }
- function Pr(t) {
- return ge(t, "bundles");
- }
- function br(t) {
- return ge(t, "namedQueries");
- }
- class Vr {
-
- constructor(t, e) {
- this.serializer = t, this.userId = e;
- }
- static de(t, e) {
- const n = e.uid || "";
- return new Vr(t, n);
- }
- getOverlay(t, e) {
- return Sr(t).get(Ar(this.userId, e)).next((t => t ? Er(this.serializer, t) : null));
- }
- getOverlays(t, e) {
- const n = _s();
- return bt.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 ii(e, i);
- s.push(this.we(t, r));
- })), bt.waitFor(s);
- }
- removeOverlaysForBatchId(t, e, n) {
- const s = new Set;
-
- e.forEach((t => s.add(Kt(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(Sr(t).J("collectionPathOverlayIndex", s));
- })), bt.waitFor(i);
- }
- getOverlaysForCollection(t, e, n) {
- const s = _s(), i = Kt(e), r = IDBKeyRange.bound([ this.userId, i, n ], [ this.userId, i, Number.POSITIVE_INFINITY ],
- !0);
- return Sr(t).j("collectionPathOverlayIndex", r).next((t => {
- for (const e of t) {
- const t = Er(this.serializer, e);
- s.set(t.getKey(), t);
- }
- return s;
- }));
- }
- getOverlaysForCollectionGroup(t, e, n, s) {
- const i = _s();
- let r;
-
-
- const o = IDBKeyRange.bound([ this.userId, e, n ], [ this.userId, e, Number.POSITIVE_INFINITY ],
- !0);
- return Sr(t).X({
- index: "collectionGroupOverlayIndex",
- range: o
- }, ((t, e, n) => {
-
-
-
-
- const o = Er(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 Sr(t).put(function(t, e, n) {
- const [s, i, r] = Ar(e, n.mutation.key);
- return {
- userId: e,
- collectionPath: i,
- documentId: r,
- collectionGroup: n.mutation.key.getCollectionGroup(),
- largestBatchId: n.largestBatchId,
- overlayMutation: Hi(t.fe, n.mutation)
- };
- }(this.serializer, this.userId, e));
- }
- }
- function Sr(t) {
- return ge(t, "documentOverlays");
- }
- class Dr {
- 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(ke(t.integerValue)); else if ("doubleValue" in t) {
- const n = ke(t.doubleValue);
- isNaN(n) ? this.ye(e, 13) : (this.ye(e, 15), qt(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($e(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 ? rn(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)) : B();
- }
- 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);
- ft.fromName(t).path.forEach((t => {
- this.ye(e, 60), this.be(t, e);
- }));
- }
- ye(t, e) {
- t.pe(e);
- }
- Ee(t) {
-
-
-
- t.pe(2);
- }
- }
- Dr.Ve = new Dr;
- function Cr(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 xr(t) {
-
- const e = 64 - function(t) {
- let e = 0;
- for (let n = 0; n < 8; ++n) {
- const s = Cr(255 & t[n]);
- if (e += s, 8 !== s) break;
- }
- return e;
- }(t);
- return Math.ceil(e / 8);
- }
- class Nr {
- 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();
- }
- $e(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();
- }
- Me(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 = xr(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 = xr(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 kr {
- constructor(t) {
- this.je = t;
- }
- Ae(t) {
- this.je.Se(t);
- }
- Ie(t) {
- this.je.$e(t);
- }
- pe(t) {
- this.je.Oe(t);
- }
- ge() {
- this.je.qe();
- }
- }
- class $r {
- constructor(t) {
- this.je = t;
- }
- Ae(t) {
- this.je.xe(t);
- }
- Ie(t) {
- this.je.Me(t);
- }
- pe(t) {
- this.je.Le(t);
- }
- ge() {
- this.je.Ke();
- }
- }
- class Mr {
- constructor() {
- this.je = new Nr, this.ze = new kr(this.je), this.We = new $r(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 Or {
- 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 Or(this.indexId, this.documentKey, this.arrayValue, n);
- }
- }
- function Fr(t, e) {
- let n = t.indexId - e.indexId;
- return 0 !== n ? n : (n = Br(t.arrayValue, e.arrayValue), 0 !== n ? n : (n = Br(t.directionalValue, e.directionalValue),
- 0 !== n ? n : ft.comparator(t.documentKey, e.documentKey)));
- }
- function Br(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 Lr {
- 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) {
- L(t.collectionGroup === this.collectionId);
-
- const e = wt(t);
- if (void 0 !== e && !this.en(e)) return !1;
- const n = _t(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 qr(t) {
- var e, n;
- if (L(t instanceof pn || t instanceof In), t instanceof pn) {
- if (t instanceof kn) {
- const s = (null === (n = null === (e = t.value.arrayValue) || void 0 === e ? void 0 : e.values) || void 0 === n ? void 0 : n.map((e => pn.create(t.field, "==" , e)))) || [];
- return In.create(s, "or" );
- }
-
- return t;
- }
-
- const s = t.filters.map((t => qr(t)));
- return In.create(s, t.op);
- }
- function Ur(t) {
- if (0 === t.getFilters().length) return [];
- const e = jr(qr(t));
- return L(Qr(e)), Kr(e) || Gr(e) ? [ e ] : e.getFilters();
- }
- function Kr(t) {
- return t instanceof pn;
- }
- function Gr(t) {
- return t instanceof In && An(t);
- }
- function Qr(t) {
- return Kr(t) || Gr(t) ||
-
- function(t) {
- if (t instanceof In && En(t)) {
- for (const e of t.getFilters()) if (!Kr(e) && !Gr(e)) return !1;
- return !0;
- }
- return !1;
- }(t);
- }
- function jr(t) {
- if (L(t instanceof pn || t instanceof In), t instanceof pn) return t;
- if (1 === t.filters.length) return jr(t.filters[0]);
-
- const e = t.filters.map((t => jr(t)));
- let n = In.create(e, t.op);
- return n = Hr(n), Qr(n) ? n : (L(n instanceof In), L(Tn(n)), L(n.filters.length > 1),
- n.filters.reduce(((t, e) => zr(t, e))));
- }
- function zr(t, e) {
- let n;
- return L(t instanceof pn || t instanceof In), L(e instanceof pn || e instanceof In),
-
- n = t instanceof pn ? e instanceof pn ? function(t, e) {
-
- return In.create([ t, e ], "and" );
- }(t, e) : Wr(t, e) : e instanceof pn ? Wr(e, t) : function(t, e) {
-
-
-
-
-
-
- if (L(t.filters.length > 0 && e.filters.length > 0), Tn(t) && Tn(e)) return bn(t, e.getFilters());
-
-
-
- const n = En(t) ? t : e, s = En(t) ? e : t, i = n.filters.map((t => zr(t, s)));
- return In.create(i, "or" );
- }(t, e), Hr(n);
- }
- function Wr(t, e) {
-
-
-
- if (Tn(e))
-
- return bn(e, t.getFilters());
- {
-
- const n = e.filters.map((e => zr(t, e)));
- return In.create(n, "or" );
- }
- }
- function Hr(t) {
- if (L(t instanceof pn || t instanceof In), t instanceof pn) return t;
- const e = t.getFilters();
-
- if (1 === e.length) return Hr(e[0]);
-
- if (vn(t)) return t;
-
-
- const n = e.map((t => Hr(t))), s = [];
-
-
-
-
-
-
-
- return n.forEach((e => {
- e instanceof pn ? s.push(e) : e instanceof In && (e.op === t.op ?
-
-
-
- s.push(...e.filters) :
-
-
-
- s.push(e));
- })), 1 === s.length ? s[0] : In.create(s, t.op);
- }
- class Jr {
- constructor() {
- this.rn = new Yr;
- }
- addToCollectionParentIndex(t, e) {
- return this.rn.add(e), bt.resolve();
- }
- getCollectionParents(t, e) {
- return bt.resolve(this.rn.getEntries(e));
- }
- addFieldIndex(t, e) {
-
- return bt.resolve();
- }
- deleteFieldIndex(t, e) {
-
- return bt.resolve();
- }
- getDocumentsMatchingTarget(t, e) {
-
- return bt.resolve(null);
- }
- getIndexType(t, e) {
-
- return bt.resolve(0 );
- }
- getFieldIndexes(t, e) {
-
- return bt.resolve([]);
- }
- getNextCollectionGroupToUpdate(t) {
-
- return bt.resolve(null);
- }
- getMinOffset(t, e) {
- return bt.resolve(Et.min());
- }
- getMinOffsetFromCollectionGroup(t, e) {
- return bt.resolve(Et.min());
- }
- updateCollectionGroup(t, e, n) {
-
- return bt.resolve();
- }
- updateIndexEntries(t, e) {
-
- return bt.resolve();
- }
- }
- class Yr {
- constructor() {
- this.index = {};
- }
-
- add(t) {
- const e = t.lastSegment(), n = t.popLast(), s = this.index[e] || new ve(at.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 ve(at.comparator)).toArray();
- }
- }
- const Xr = new Uint8Array(0);
- class Zr {
- constructor(t, e) {
- this.user = t, this.databaseId = e,
-
- this.on = new Yr,
-
- this.un = new as((t => Bn(t)), ((t, e) => Ln(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: Kt(s)
- };
- return to(t).put(i);
- }
- return bt.resolve();
- }
- getCollectionParents(t, e) {
- const n = [], s = IDBKeyRange.bound([ e, "" ], [ rt(e), "" ],
- !1,
- !0);
- return to(t).j(s).next((t => {
- for (const s of t) {
-
-
-
-
- if (s.collectionId !== e) break;
- n.push(jt(s.parent));
- }
- return n;
- }));
- }
- addFieldIndex(t, e) {
-
-
- const n = no(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 = so(t);
- return i.next((t => {
- n.put(vr(t, this.user, e.indexState.sequenceNumber, e.indexState.offset));
- }));
- }
- return i.next();
- }
- deleteFieldIndex(t, e) {
- const n = no(t), s = so(t), i = eo(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 = eo(t);
- let s = !0;
- const i = new Map;
- return bt.forEach(this.cn(e), (e => this.an(t, e).next((t => {
- s && (s = !!t), i.set(e, t);
- })))).next((() => {
- if (s) {
- let t = Is();
- const s = [];
- return bt.forEach(i, ((i, r) => {
- var o;
- $("IndexedDbIndexManager", `Using index ${o = i, `id=${o.indexId}|cg=${o.collectionGroup}|f=${o.fields.map((t => `${t.fieldPath}:${t.kind}`)).join(",")}`} to execute ${Bn(e)}`);
- const u = function(t, e) {
- const n = wt(e);
- if (void 0 === n) return null;
- for (const e of Un(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 _t(e)) for (const e of Un(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 _t(e)) {
- const e = 0 === i.kind ? Kn(t, i.fieldPath, t.startAt) : Gn(t, i.fieldPath, t.startAt);
- n.push(e.value), s && (s = e.inclusive);
- }
- return new dn(n, s);
- }
-
- (r, i), h = function(t, e) {
- const n = [];
- let s = !0;
-
-
- for (const i of _t(e)) {
- const e = 0 === i.kind ? Gn(t, i.fieldPath, t.endAt) : Kn(t, i.fieldPath, t.endAt);
- n.push(e.value), s && (s = e.inclusive);
- }
- return new dn(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 bt.forEach(w, (i => n.H(i, e.limit).next((e => {
- e.forEach((e => {
- const n = ft.fromSegments(e.documentKey);
- t.has(n) || (t = t.add(n), s.push(n));
- }));
- }))));
- })).next((() => s));
- }
- return bt.resolve(null);
- }));
- }
- cn(t) {
- let e = this.un.get(t);
- if (e) return e;
- if (0 === t.filters.length) e = [ t ]; else {
- e = Ur(In.create(t.filters, "and" )).map((e => Fn(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]) : Xr, 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 Or(t, ft.empty(), e, n);
- return s ? i : i.Je();
- }
- _n(t, e, n, s) {
- const i = new Or(t, ft.empty(), e, n);
- return s ? i.Je() : i;
- }
- an(t, e) {
- const n = new Lr(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 bt.forEach(s, (e => this.an(t, e).next((t => {
- t ? 0 !== n && t.fields.length < function(t) {
- let e = new ve(lt.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 Mr;
- for (const s of _t(t)) {
- const t = e.data.field(s.fieldPath);
- if (null == t) return null;
- const i = n.He(s.kind);
- Dr.Ve._e(t, i);
- }
- return n.Qe();
- }
- dn(t) {
- const e = new Mr;
- return Dr.Ve._e(t, e.He(0 )), e.Qe();
- }
-
- gn(t, e) {
- const n = new Mr;
- return Dr.Ve._e(Ye(this.databaseId, e), n.He(function(t) {
- const e = _t(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 Mr);
- let i = 0;
- for (const r of _t(t)) {
- const t = n[i++];
- for (const n of s) if (this.yn(e, r.fieldPath) && Ze(t)) s = this.pn(s, r, t); else {
- const e = n.He(r.kind);
- Dr.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 Mr;
- s.seed(n.Qe()), Dr.Ve._e(t, s.He(e.kind)), i.push(s);
- }
- return i;
- }
- yn(t, e) {
- return !!t.filters.find((t => t instanceof pn && t.field.isEqual(e) && ("in" === t.op || "not-in" === t.op)));
- }
- getFieldIndexes(t, e) {
- const n = no(t), s = so(t);
- return (e ? n.j("collectionGroupIndex", IDBKeyRange.bound(e, e)) : n.j()).next((t => {
- const e = [];
- return bt.forEach(t, (t => s.get([ t.indexId, this.uid ]).next((n => {
- e.push(function(t, e) {
- const n = e ? new pt(e.sequenceNumber, new Et(gr(e.readTime), new ft(jt(e.documentKey)), e.largestBatchId)) : pt.empty(), s = t.fields.map((([t, e]) => new gt(lt.fromServerFormat(t), e)));
- return new dt(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 : st(t.collectionGroup, e.collectionGroup);
- })), t[0].collectionGroup)));
- }
- updateCollectionGroup(t, e, n) {
- const s = no(t), i = so(t);
- return this.Tn(t).next((t => s.j("collectionGroupIndex", IDBKeyRange.bound(e, e)).next((e => bt.forEach(e, (e => i.put(vr(e.indexId, this.user, t, n))))))));
- }
- updateIndexEntries(t, e) {
-
-
-
-
-
- const n = new Map;
- return bt.forEach(e, ((e, s) => {
- const i = n.get(e.collectionGroup);
- return (i ? bt.resolve(i) : this.getFieldIndexes(t, e.collectionGroup)).next((i => (n.set(e.collectionGroup, i),
- bt.forEach(i, (n => this.En(t, e, n).next((e => {
- const i = this.An(s, n);
- return e.isEqual(i) ? bt.resolve() : this.vn(t, s, n, e, i);
- })))))));
- }));
- }
- Rn(t, e, n, s) {
- return eo(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 eo(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 = eo(t);
- let i = new ve(Fr);
- return s.X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only([ n.indexId, this.uid, this.gn(n, e) ])
- }, ((t, s) => {
- i = i.add(new Or(n.indexId, e, s.arrayValue, s.directionalValue));
- })).next((() => i));
- }
- An(t, e) {
- let n = new ve(Fr);
- const s = this.mn(e, t);
- if (null == s) return n;
- const i = wt(e);
- if (null != i) {
- const r = t.data.field(i.fieldPath);
- if (Ze(r)) for (const i of r.arrayValue.values || []) n = n.add(new Or(e.indexId, t.key, this.dn(i), s));
- } else n = n.add(new Or(e.indexId, t.key, Xr, s));
- return n;
- }
-
- vn(t, e, n, s, i) {
- $("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 = Pe(r), c = Pe(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 = Pe(o)) : e ? (i(u), u = Pe(r)) : (u = Pe(r), c = Pe(o));
- }
- }(s, i, Fr, (
- s => {
- r.push(this.Rn(t, e, n, s));
- }), (
- s => {
- r.push(this.Pn(t, e, n, s));
- })), bt.waitFor(r);
- }
- Tn(t) {
- let e = 1;
- return so(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) => Fr(t, e))).filter(((t, e, n) => !e || 0 !== Fr(t, n[e - 1])));
- const s = [];
- s.push(t);
- for (const i of n) {
- const n = Fr(i, t), r = Fr(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, Xr, [] ], n = [ s[t + 1].indexId, this.uid, s[t + 1].arrayValue, s[t + 1].directionalValue, Xr, [] ];
- i.push(IDBKeyRange.bound(e, n));
- }
- return i;
- }
- bn(t, e) {
-
-
- return Fr(t, e) > 0;
- }
- getMinOffsetFromCollectionGroup(t, e) {
- return this.getFieldIndexes(t, e).next(io);
- }
- getMinOffset(t, e) {
- return bt.mapArray(this.cn(e), (e => this.an(t, e).next((t => t || B())))).next(io);
- }
- }
- function to(t) {
- return ge(t, "collectionParents");
- }
- function eo(t) {
- return ge(t, "indexEntries");
- }
- function no(t) {
- return ge(t, "indexConfiguration");
- }
- function so(t) {
- return ge(t, "indexState");
- }
- function io(t) {
- L(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;
- At(i, e) < 0 && (e = i), n < i.largestBatchId && (n = i.largestBatchId);
- }
- return new Et(e.readTime, e.documentKey, n);
- }
- const ro = {
- didRun: !1,
- sequenceNumbersCollected: 0,
- targetsRemoved: 0,
- documentsRemoved: 0
- };
- class oo {
- 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 oo(t, oo.DEFAULT_COLLECTION_PERCENTILE, oo.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT);
- }
- }
- function uo(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((() => {
- L(1 === u);
- })));
- const a = [];
- for (const t of n.mutations) {
- const s = Ht(e, t.key.path, n.batchId);
- r.push(i.delete(s)), a.push(t.key);
- }
- return bt.waitFor(r).next((() => a));
- }
- function co(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 B();
- e = t.noDocument;
- }
- return JSON.stringify(e).length;
- }
- oo.DEFAULT_COLLECTION_PERCENTILE = 10,
- oo.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT = 1e3, oo.DEFAULT = new oo(41943040, oo.DEFAULT_COLLECTION_PERCENTILE, oo.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),
- oo.DISABLED = new oo(-1, 0, 0);
- class ao {
- 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) {
-
-
-
-
- L("" !== t.uid);
- const i = t.isAuthenticated() ? t.uid : "";
- return new ao(i, e, n, s);
- }
- checkEmpty(t) {
- let e = !0;
- const n = IDBKeyRange.bound([ this.userId, Number.NEGATIVE_INFINITY ], [ this.userId, Number.POSITIVE_INFINITY ]);
- return lo(t).X({
- index: "userMutationsIndex",
- range: n
- }, ((t, n, s) => {
- e = !1, s.done();
- })).next((() => e));
- }
- addMutationBatch(t, e, n, s) {
- const i = fo(t), r = lo(t);
-
-
-
-
-
-
-
-
-
- return r.add({}).next((o => {
- L("number" == typeof o);
- const u = new ni(o, e, n, s), c = function(t, e, n) {
- const s = n.baseMutations.map((e => Hi(t.fe, e))), i = n.mutations.map((e => Hi(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 ve(((t, e) => st(t.canonicalString(), e.canonicalString())));
- for (const t of s) {
- const e = Ht(this.userId, t.key.path, o);
- h = h.add(t.key.path.popLast()), a.push(r.put(c)), a.push(i.put(e, Jt));
- }
- return h.forEach((e => {
- a.push(this.indexManager.addToCollectionParentIndex(t, e));
- })), t.addOnCommittedListener((() => {
- this.Vn[o] = u.keys();
- })), bt.waitFor(a).next((() => u));
- }));
- }
- lookupMutationBatch(t, e) {
- return lo(t).get(e).next((t => t ? (L(t.userId === this.userId), yr(this.serializer, t)) : null));
- }
-
-
- Sn(t, e) {
- return this.Vn[e] ? bt.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 lo(t).X({
- index: "userMutationsIndex",
- range: s
- }, ((t, e, s) => {
- e.userId === this.userId && (L(e.batchId >= n), i = yr(this.serializer, e)), s.done();
- })).next((() => i));
- }
- getHighestUnacknowledgedBatchId(t) {
- const e = IDBKeyRange.upperBound([ this.userId, Number.POSITIVE_INFINITY ]);
- let n = -1;
- return lo(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 lo(t).j("userMutationsIndex", e).next((t => t.map((t => yr(this.serializer, t)))));
- }
- getAllMutationBatchesAffectingDocumentKey(t, e) {
-
-
- const n = Wt(this.userId, e.path), s = IDBKeyRange.lowerBound(n), i = [];
- return fo(t).X({
- range: s
- }, ((n, s, r) => {
- const [o, u, c] = n, a = jt(u);
-
-
-
-
-
-
-
- if (o === this.userId && e.path.isEqual(a))
-
- return lo(t).get(c).next((t => {
- if (!t) throw B();
- L(t.userId === this.userId), i.push(yr(this.serializer, t));
- }));
- r.done();
- })).next((() => i));
- }
- getAllMutationBatchesAffectingDocumentKeys(t, e) {
- let n = new ve(st);
- const s = [];
- return e.forEach((e => {
- const i = Wt(this.userId, e.path), r = IDBKeyRange.lowerBound(i), o = fo(t).X({
- range: r
- }, ((t, s, i) => {
- const [r, o, u] = t, c = jt(o);
-
-
-
-
-
-
-
- r === this.userId && e.path.isEqual(c) ? n = n.add(u) : i.done();
- }));
- s.push(o);
- })), bt.waitFor(s).next((() => this.Dn(t, n)));
- }
- getAllMutationBatchesAffectingQuery(t, e) {
- const n = e.path, s = n.length + 1, i = Wt(this.userId, n), r = IDBKeyRange.lowerBound(i);
-
-
-
- let o = new ve(st);
- return fo(t).X({
- range: r
- }, ((t, e, i) => {
- const [r, u, c] = t, a = jt(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(lo(t).get(e).next((t => {
- if (null === t) throw B();
- L(t.userId === this.userId), n.push(yr(this.serializer, t));
- })));
- })), bt.waitFor(s).next((() => n));
- }
- removeMutationBatch(t, e) {
- return uo(t.ht, this.userId, e).next((n => (t.addOnCommittedListener((() => {
- this.Cn(e.batchId);
- })), bt.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 bt.resolve();
-
-
- const n = IDBKeyRange.lowerBound([ this.userId ]);
- const s = [];
- return fo(t).X({
- range: n
- }, ((t, e, n) => {
- if (t[0] === this.userId) {
- const e = jt(t[1]);
- s.push(e);
- } else n.done();
- })).next((() => {
- L(0 === s.length);
- }));
- }));
- }
- containsKey(t, e) {
- return ho(t, this.userId, e);
- }
-
-
- xn(t) {
- return wo(t).get(this.userId).next((t => t || {
- userId: this.userId,
- lastAcknowledgedBatchId: -1,
- lastStreamToken: ""
- }));
- }
- }
- function ho(t, e, n) {
- const s = Wt(e, n.path), i = s[1], r = IDBKeyRange.lowerBound(s);
- let o = !1;
- return fo(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 lo(t) {
- return ge(t, "mutations");
- }
- function fo(t) {
- return ge(t, "documentMutations");
- }
- function wo(t) {
- return ge(t, "mutationQueues");
- }
- class _o {
- constructor(t) {
- this.Nn = t;
- }
- next() {
- return this.Nn += 2, this.Nn;
- }
- static kn() {
-
-
-
-
- return new _o(0);
- }
- static $n() {
-
- return new _o(-1);
- }
- }
- class mo {
- constructor(t, e) {
- this.referenceDelegate = t, this.serializer = e;
- }
-
-
-
-
-
-
- allocateTargetId(t) {
- return this.Mn(t).next((e => {
- const n = new _o(e.highestTargetId);
- return e.highestTargetId = n.next(), this.On(t, e).next((() => e.highestTargetId));
- }));
- }
- getLastRemoteSnapshotVersion(t) {
- return this.Mn(t).next((t => ut.fromTimestamp(new ot(t.lastRemoteSnapshotVersion.seconds, t.lastRemoteSnapshotVersion.nanoseconds))));
- }
- getHighestSequenceNumber(t) {
- return this.Mn(t).next((t => t.highestListenSequenceNumber));
- }
- setTargetsMetadata(t, e, n) {
- return this.Mn(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.Mn(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((() => go(t).delete(e.targetId))).next((() => this.Mn(t))).next((e => (L(e.targetCount > 0),
- e.targetCount -= 1, this.On(t, e))));
- }
-
- removeTargets(t, e, n) {
- let s = 0;
- const i = [];
- return go(t).X(((r, o) => {
- const u = pr(o);
- u.sequenceNumber <= e && null === n.get(u.targetId) && (s++, i.push(this.removeTargetData(t, u)));
- })).next((() => bt.waitFor(i))).next((() => s));
- }
-
- forEachTarget(t, e) {
- return go(t).X(((t, n) => {
- const s = pr(n);
- e(s);
- }));
- }
- Mn(t) {
- return yo(t).get("targetGlobalKey").next((t => (L(null !== t), t)));
- }
- On(t, e) {
- return yo(t).put("targetGlobalKey", e);
- }
- Fn(t, e) {
- return go(t).put(Ir(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.Mn(t).next((t => t.targetCount));
- }
- getTargetData(t, e) {
-
-
-
- const n = Bn(e), s = IDBKeyRange.bound([ n, Number.NEGATIVE_INFINITY ], [ n, Number.POSITIVE_INFINITY ]);
- let i = null;
- return go(t).X({
- range: s,
- index: "queryTargetsIndex"
- }, ((t, n, s) => {
- const r = pr(n);
-
-
- Ln(e, r.target) && (i = r, s.done());
- })).next((() => i));
- }
- addMatchingKeys(t, e, n) {
-
-
- const s = [], i = po(t);
- return e.forEach((e => {
- const r = Kt(e.path);
- s.push(i.put({
- targetId: n,
- path: r
- })), s.push(this.referenceDelegate.addReference(t, n, e));
- })), bt.waitFor(s);
- }
- removeMatchingKeys(t, e, n) {
-
-
- const s = po(t);
- return bt.forEach(e, (e => {
- const i = Kt(e.path);
- return bt.waitFor([ s.delete([ n, i ]), this.referenceDelegate.removeReference(t, n, e) ]);
- }));
- }
- removeMatchingKeysForTargetId(t, e) {
- const n = po(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 = po(t);
- let i = Is();
- return s.X({
- range: n,
- Y: !0
- }, ((t, e, n) => {
- const s = jt(t[1]), r = new ft(s);
- i = i.add(r);
- })).next((() => i));
- }
- containsKey(t, e) {
- const n = Kt(e.path), s = IDBKeyRange.bound([ n ], [ rt(n) ],
- !1,
- !0);
- let i = 0;
- return po(t).X({
- index: "documentTargetsIndex",
- Y: !0,
- range: s
- }, (([t, e], n, s) => {
-
-
-
- 0 !== t && (i++, s.done());
- })).next((() => i > 0));
- }
-
-
- le(t, e) {
- return go(t).get(e).next((t => t ? pr(t) : null));
- }
- }
- function go(t) {
- return ge(t, "targets");
- }
- function yo(t) {
- return ge(t, "targetGlobal");
- }
- function po(t) {
- return ge(t, "targetDocuments");
- }
- function Io([t, e], [n, s]) {
- const i = st(t, n);
- return 0 === i ? st(e, s) : i;
- }
- class To {
- constructor(t) {
- this.Ln = t, this.buffer = new ve(Io), 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();
- Io(e, t) < 0 && (this.buffer = this.buffer.delete(t).add(e));
- }
- }
- get maxValue() {
-
-
-
-
-
-
- return this.buffer.last()[0];
- }
- }
- class Eo {
- 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) {
- $("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) {
- xt(t) ? $("LruGarbageCollector", "Ignoring IndexedDB error during garbage collection: ", t) : await Pt(t);
- }
- await this.Qn(3e5);
- }));
- }
- }
- class Ao {
- 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 bt.resolve(Bt.ct);
- const n = new To(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 ? ($("LruGarbageCollector", "Garbage collection skipped; disabled"),
- bt.resolve(ro)) : this.getCacheSize(t).next((n => n < this.params.cacheSizeCollectionThreshold ? ($("LruGarbageCollector", `Garbage collection skipped; Cache size ${n} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),
- ro) : 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 ? ($("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(), N() <= u.DEBUG) {
- $("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 bt.resolve({
- didRun: !0,
- sequenceNumbersCollected: s,
- targetsRemoved: i,
- documentsRemoved: t
- });
- }));
- }
- }
- function vo(t, e) {
- return new Ao(t, e);
- }
- class Ro {
- constructor(t, e) {
- this.db = t, this.garbageCollector = vo(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 Po(t, n);
- }
- removeReference(t, e, n) {
- return Po(t, n);
- }
- removeTargets(t, e, n) {
- return this.db.getTargetCache().removeTargets(t, e, n);
- }
- markPotentiallyOrphaned(t, e) {
- return Po(t, e);
- }
-
- Xn(t, e) {
- return function(t, e) {
- let n = !1;
- return wo(t).Z((s => ho(t, s, e).next((t => (t && (n = !0), bt.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, ut.min()), po(t).delete([ 0, Kt(r.path) ]))));
- }));
- s.push(e);
- }
- })).next((() => bt.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 Po(t, e);
- }
-
- Yn(t, e) {
- const n = po(t);
- let s, i = Bt.ct;
- return n.X({
- index: "documentTargetsIndex"
- }, (([t, n], {path: r, sequenceNumber: o}) => {
- 0 === t ? (
-
-
- i !== Bt.ct && e(new ft(jt(s)), i),
-
-
-
-
- i = o, s = r) :
-
-
- i = Bt.ct;
- })).next((() => {
-
-
-
- i !== Bt.ct && e(new ft(jt(s)), i);
- }));
- }
- getCacheSize(t) {
- return this.db.getRemoteDocumentCache().getSize(t);
- }
- }
- function Po(t, e) {
- return po(t).put(
-
- function(t, e) {
- return {
- targetId: 0,
- path: Kt(t.path),
- sequenceNumber: e
- };
- }(e, t.currentSequenceNumber));
- }
- class bo {
- constructor() {
-
- this.changes = new as((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, fn.newInvalidDocument(t).setReadTime(e));
- }
-
- getEntry(t, e) {
- this.assertNotApplied();
- const n = this.changes.get(e);
- return void 0 !== n ? bt.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 Vo {
- constructor(t) {
- this.serializer = t;
- }
- setIndexManager(t) {
- this.indexManager = t;
- }
-
- addEntry(t, e, n) {
- return xo(t).put(n);
- }
-
- removeEntry(t, e, n) {
- return xo(t).delete(
-
- function(t, e) {
- const n = t.path.toArray();
- return [
- n.slice(0, n.length - 2),
- n[n.length - 2], _r(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 = fn.newInvalidDocument(e);
- return xo(t).X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only(No(e))
- }, ((t, s) => {
- n = this.ts(e, s);
- })).next((() => n));
- }
-
- es(t, e) {
- let n = {
- size: 0,
- document: fn.newInvalidDocument(e)
- };
- return xo(t).X({
- index: "documentKeyIndex",
- range: IDBKeyRange.only(No(e))
- }, ((t, s) => {
- n = {
- document: this.ts(e, s),
- size: co(s)
- };
- })).next((() => n));
- }
- getEntries(t, e) {
- let n = ls();
- 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 = ls(), s = new Te(ft.comparator);
- return this.ns(t, e, ((t, e) => {
- const i = this.ts(t, e);
- n = n.insert(t, i), s = s.insert(t, co(e));
- })).next((() => ({
- documents: n,
- rs: s
- })));
- }
- ns(t, e, n) {
- if (e.isEmpty()) return bt.resolve();
- let s = new ve($o);
- e.forEach((t => s = s.add(t)));
- const i = IDBKeyRange.bound(No(s.first()), No(s.last())), r = s.getIterator();
- let o = r.getNext();
- return xo(t).X({
- index: "documentKeyIndex",
- range: i
- }, ((t, e, s) => {
- const i = ft.fromSegments([ ...e.prefixPath, e.collectionGroup, e.documentId ]);
-
- for (;o && $o(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(No(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(), _r(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 xo(t).j(IDBKeyRange.bound(r, o, !0)).next((t => {
- let n = ls();
- for (const i of t) {
- const t = this.ts(ft.fromSegments(i.prefixPath.concat(i.collectionGroup, i.documentId)), i);
- t.isFoundDocument() && (rs(e, t) || s.has(t.key)) && (
-
- n = n.insert(t.key, t));
- }
- return n;
- }));
- }
- getAllFromCollectionGroup(t, e, n, s) {
- let i = ls();
- const r = ko(e, n), o = ko(e, Et.max());
- return xo(t).X({
- index: "collectionGroupIndex",
- range: IDBKeyRange.bound(r, o, !0)
- }, ((t, e, n) => {
- const r = this.ts(ft.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 Do(this, !!t && t.trackRemovals);
- }
- getSize(t) {
- return this.getMetadata(t).next((t => t.byteSize));
- }
- getMetadata(t) {
- return Co(t).get("remoteDocumentGlobalKey").next((t => (L(!!t), t)));
- }
- Zn(t, e) {
- return Co(t).put("remoteDocumentGlobalKey", e);
- }
-
- ts(t, e) {
- if (e) {
- const t = dr(this.serializer, e);
-
-
- if (!(t.isNoDocument() && t.version.isEqual(ut.min()))) return t;
- }
- return fn.newInvalidDocument(t);
- }
- }
- function So(t) {
- return new Vo(t);
- }
- class Do extends bo {
-
- constructor(t, e) {
- super(), this.os = t, this.trackRemovals = e,
-
-
- this.us = new as((t => t.toString()), ((t, e) => t.isEqual(e)));
- }
- applyChanges(t) {
- const e = [];
- let n = 0, s = new ve(((t, e) => st(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 = wr(this.os.serializer, r);
- s = s.add(i.path.popLast());
- const c = co(u);
- n += c - o.size, e.push(this.os.addEntry(t, i, u));
- } else if (n -= o.size, this.trackRemovals) {
-
-
-
-
- const n = wr(this.os.serializer, r.convertToNoDocument(ut.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)), bt.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 Co(t) {
- return ge(t, "remoteDocumentGlobal");
- }
- function xo(t) {
- return ge(t, "remoteDocumentsV14");
- }
- function No(t) {
- const e = t.path.toArray();
- return [
- e.slice(0, e.length - 2),
- e[e.length - 2],
- e[e.length - 1] ];
- }
- function ko(t, e) {
- const n = e.documentKey.path.toArray();
- return [
- t, _r(e.readTime),
- n.slice(0, n.length - 2),
- n.length > 0 ? n[n.length - 1] : "" ];
- }
- function $o(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 = st(n[t], s[t]),
- i) return i;
- return i = st(n.length, s.length), i || (i = st(n[n.length - 2], s[s.length - 2]),
- i || st(n[n.length - 1], s[s.length - 1]));
- }
- class Mo {
- 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 Oo {
- 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 && js(n.mutation, t, be.empty(), ot.now()),
- t)));
- }
-
- getDocuments(t, e) {
- return this.remoteDocumentCache.getEntries(t, e).next((e => this.getLocalViewOfDocuments(t, e, Is()).next((() => e))));
- }
-
- getLocalViewOfDocuments(t, e, n = Is()) {
- const s = _s();
- return this.populateOverlays(t, s, e).next((() => this.computeViews(t, e, s, n).next((t => {
- let e = ds();
- return t.forEach(((t, n) => {
- e = e.insert(t, n.overlayedDocument);
- })), e;
- }))));
- }
-
- getOverlayedDocuments(t, e) {
- const n = _s();
- return this.populateOverlays(t, n, e).next((() => this.computeViews(t, e, n, Is())));
- }
-
- 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 = ls();
- const r = gs(), o = gs();
- return e.forEach(((t, e) => {
- const o = n.get(e.key);
-
-
-
-
-
-
-
- s.has(e.key) && (void 0 === o || o.mutation instanceof Js) ? i = i.insert(e.key, e) : void 0 !== o ? (r.set(e.key, o.mutation.getFieldMask()),
- js(o.mutation, e, o.mutation.getFieldMask(), ot.now())) :
-
-
- r.set(e.key, be.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 Mo(e, null !== (n = r.get(t)) && void 0 !== n ? n : null));
- })), o)));
- }
- recalculateAndSaveOverlays(t, e) {
- const n = gs();
-
- let s = new Te(((t, e) => t - e)), i = Is();
- 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) || be.empty();
- o = i.applyToLocalView(r, o), n.set(t, o);
- const u = (s.get(i.batchId) || Is()).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 = ms();
- c.forEach((t => {
- if (!i.has(t)) {
- const s = Gs(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 bt.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 ft.isDocumentKey(t.path) && null === t.collectionGroup && 0 === t.filters.length;
- }(e) ? this.getDocumentsMatchingDocumentQuery(t, e.path) : Yn(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) : bt.resolve(_s());
-
-
-
-
- let o = -1, u = i;
- return r.next((e => bt.forEach(e, ((e, n) => (o < n.largestBatchId && (o = n.largestBatchId),
- i.get(e) ? bt.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, Is()))).next((t => ({
- batchId: o,
- changes: ws(t)
- })))));
- }));
- }
- getDocumentsMatchingDocumentQuery(t, e) {
-
- return this.getDocument(t, new ft(e)).next((t => {
- let e = ds();
- return t.isFoundDocument() && (e = e.insert(t.key, t)), e;
- }));
- }
- getDocumentsMatchingCollectionGroupQuery(t, e, n) {
- const s = e.collectionGroup;
- let i = ds();
- return this.indexManager.getCollectionParents(t, s).next((r => bt.forEach(r, (r => {
- const o = function(t, e) {
- return new Qn(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, fn.newInvalidDocument(s)));
- }));
-
- let n = ds();
- return t.forEach(((t, i) => {
- const r = s.get(t);
- void 0 !== r && js(r.mutation, i, be.empty(), ot.now()),
-
- rs(e, i) && (n = n.insert(t, i));
- })), n;
- }));
- }
- }
- class Fo {
- constructor(t) {
- this.serializer = t, this.cs = new Map, this.hs = new Map;
- }
- getBundleMetadata(t, e) {
- return bt.resolve(this.cs.get(e));
- }
- saveBundleMetadata(t, e) {
-
- var n;
- return this.cs.set(e.id, {
- id: (n = e).id,
- version: n.version,
- createTime: Mi(n.createTime)
- }), bt.resolve();
- }
- getNamedQuery(t, e) {
- return bt.resolve(this.hs.get(e));
- }
- saveNamedQuery(t, e) {
- return this.hs.set(e.name, function(t) {
- return {
- name: t.name,
- query: Tr(t.bundledQuery),
- readTime: Mi(t.readTime)
- };
- }(e)), bt.resolve();
- }
- }
- class Bo {
- constructor() {
-
-
- this.overlays = new Te(ft.comparator), this.ls = new Map;
- }
- getOverlay(t, e) {
- return bt.resolve(this.overlays.get(e));
- }
- getOverlays(t, e) {
- const n = _s();
- return bt.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);
- })), bt.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)), bt.resolve();
- }
- getOverlaysForCollection(t, e, n) {
- const s = _s(), i = e.length + 1, r = new ft(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 bt.resolve(s);
- }
- getOverlaysForCollectionGroup(t, e, n, s) {
- let i = new Te(((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 = _s(), i = i.insert(t.largestBatchId, e)), e.set(t.getKey(), t);
- }
- }
- const o = _s(), u = i.getIterator();
- for (;u.hasNext(); ) {
- if (u.getNext().value.forEach(((t, e) => o.set(t, e))), o.size() >= s) break;
- }
- return bt.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 ii(e, n));
-
- let i = this.ls.get(e);
- void 0 === i && (i = Is(), this.ls.set(e, i)), this.ls.set(e, i.add(n.key));
- }
- }
- class Lo {
- constructor() {
-
- this.fs = new ve(qo.ds),
-
- this.ws = new ve(qo._s);
- }
- isEmpty() {
- return this.fs.isEmpty();
- }
- addReference(t, e) {
- const n = new qo(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 qo(t, e));
- }
- ps(t, e) {
- t.forEach((t => this.removeReference(t, e)));
- }
-
- Is(t) {
- const e = new ft(new at([])), n = new qo(e, t), s = new qo(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 ft(new at([])), n = new qo(e, t), s = new qo(e, t + 1);
- let i = Is();
- return this.ws.forEachInRange([ n, s ], (t => {
- i = i.add(t.key);
- })), i;
- }
- containsKey(t) {
- const e = new qo(t, 0), n = this.fs.firstAfterOrEqual(e);
- return null !== n && t.isEqual(n.key);
- }
- }
- class qo {
- constructor(t, e) {
- this.key = t, this.As = e;
- }
- static ds(t, e) {
- return ft.comparator(t.key, e.key) || st(t.As, e.As);
- }
- static _s(t, e) {
- return st(t.As, e.As) || ft.comparator(t.key, e.key);
- }
- }
- class Uo {
- constructor(t, e) {
- this.indexManager = t, this.referenceDelegate = e,
-
- this.mutationQueue = [],
-
- this.vs = 1,
-
- this.Rs = new ve(qo.ds);
- }
- checkEmpty(t) {
- return bt.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 ni(i, e, n, s);
- this.mutationQueue.push(r);
-
- for (const e of s) this.Rs = this.Rs.add(new qo(e.key, i)), this.indexManager.addToCollectionParentIndex(t, e.key.path.popLast());
- return bt.resolve(r);
- }
- lookupMutationBatch(t, e) {
- return bt.resolve(this.Ps(e));
- }
- getNextMutationBatchAfterBatchId(t, e) {
- const n = e + 1, s = this.bs(n), i = s < 0 ? 0 : s;
-
-
- return bt.resolve(this.mutationQueue.length > i ? this.mutationQueue[i] : null);
- }
- getHighestUnacknowledgedBatchId() {
- return bt.resolve(0 === this.mutationQueue.length ? -1 : this.vs - 1);
- }
- getAllMutationBatches(t) {
- return bt.resolve(this.mutationQueue.slice());
- }
- getAllMutationBatchesAffectingDocumentKey(t, e) {
- const n = new qo(e, 0), s = new qo(e, Number.POSITIVE_INFINITY), i = [];
- return this.Rs.forEachInRange([ n, s ], (t => {
- const e = this.Ps(t.As);
- i.push(e);
- })), bt.resolve(i);
- }
- getAllMutationBatchesAffectingDocumentKeys(t, e) {
- let n = new ve(st);
- return e.forEach((t => {
- const e = new qo(t, 0), s = new qo(t, Number.POSITIVE_INFINITY);
- this.Rs.forEachInRange([ e, s ], (t => {
- n = n.add(t.As);
- }));
- })), bt.resolve(this.Vs(n));
- }
- getAllMutationBatchesAffectingQuery(t, e) {
-
-
- const n = e.path, s = n.length + 1;
-
-
-
-
- let i = n;
- ft.isDocumentKey(i) || (i = i.child(""));
- const r = new qo(new ft(i), 0);
-
-
- let o = new ve(st);
- return this.Rs.forEachWhile((t => {
- const e = t.key.path;
- return !!n.isPrefixOf(e) && (
-
-
-
-
-
- e.length === s && (o = o.add(t.As)), !0);
- }), r), bt.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) {
- L(0 === this.Ss(e.batchId, "removed")), this.mutationQueue.shift();
- let n = this.Rs;
- return bt.forEach(e.mutations, (s => {
- const i = new qo(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 qo(e, 0), s = this.Rs.firstAfterOrEqual(n);
- return bt.resolve(e.isEqual(s && s.key));
- }
- performConsistencyCheck(t) {
- return this.mutationQueue.length, bt.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 Ko {
-
- constructor(t) {
- this.Ds = t,
-
- this.docs = new Te(ft.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 bt.resolve(n ? n.document.mutableCopy() : fn.newInvalidDocument(e));
- }
- getEntries(t, e) {
- let n = ls();
- return e.forEach((t => {
- const e = this.docs.get(t);
- n = n.insert(t, e ? e.document.mutableCopy() : fn.newInvalidDocument(t));
- })), bt.resolve(n);
- }
- getDocumentsMatchingQuery(t, e, n, s) {
- let i = ls();
-
-
- const r = e.path, o = new ft(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 || (At(Tt(o), n) <= 0 || (s.has(o.key) || rs(e, o)) && (i = i.insert(o.key, o.mutableCopy())));
- }
- return bt.resolve(i);
- }
- getAllFromCollectionGroup(t, e, n, s) {
-
-
- B();
- }
- Cs(t, e) {
- return bt.forEach(this.docs, (t => e(t)));
- }
- newChangeBuffer(t) {
-
-
- return new Go(this);
- }
- getSize(t) {
- return bt.resolve(this.size);
- }
- }
- class Go extends bo {
- 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);
- })), bt.waitFor(e);
- }
- getFromCache(t, e) {
- return this.os.getEntry(t, e);
- }
- getAllFromCache(t, e) {
- return this.os.getEntries(t, e);
- }
- }
- class Qo {
- constructor(t) {
- this.persistence = t,
-
- this.xs = new as((t => Bn(t)), Ln),
-
- this.lastRemoteSnapshotVersion = ut.min(),
-
- this.highestTargetId = 0,
-
- this.Ns = 0,
-
- this.ks = new Lo, this.targetCount = 0, this.$s = _o.kn();
- }
- forEachTarget(t, e) {
- return this.xs.forEach(((t, n) => e(n))), bt.resolve();
- }
- getLastRemoteSnapshotVersion(t) {
- return bt.resolve(this.lastRemoteSnapshotVersion);
- }
- getHighestSequenceNumber(t) {
- return bt.resolve(this.Ns);
- }
- allocateTargetId(t) {
- return this.highestTargetId = this.$s.next(), bt.resolve(this.highestTargetId);
- }
- setTargetsMetadata(t, e, n) {
- return n && (this.lastRemoteSnapshotVersion = n), e > this.Ns && (this.Ns = e),
- bt.resolve();
- }
- Fn(t) {
- this.xs.set(t.target, t);
- const e = t.targetId;
- e > this.highestTargetId && (this.$s = new _o(e), this.highestTargetId = e), t.sequenceNumber > this.Ns && (this.Ns = t.sequenceNumber);
- }
- addTargetData(t, e) {
- return this.Fn(e), this.targetCount += 1, bt.resolve();
- }
- updateTargetData(t, e) {
- return this.Fn(e), bt.resolve();
- }
- removeTargetData(t, e) {
- return this.xs.delete(e.target), this.ks.Is(e.targetId), this.targetCount -= 1,
- bt.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++);
- })), bt.waitFor(i).next((() => s));
- }
- getTargetCount(t) {
- return bt.resolve(this.targetCount);
- }
- getTargetData(t, e) {
- const n = this.xs.get(e) || null;
- return bt.resolve(n);
- }
- addMatchingKeys(t, e, n) {
- return this.ks.gs(e, n), bt.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));
- })), bt.waitFor(i);
- }
- removeMatchingKeysForTargetId(t, e) {
- return this.ks.Is(e), bt.resolve();
- }
- getMatchingKeysForTargetId(t, e) {
- const n = this.ks.Es(e);
- return bt.resolve(n);
- }
- containsKey(t, e) {
- return bt.resolve(this.ks.containsKey(e));
- }
- }
- class jo {
-
- constructor(t, e) {
- this.Ms = {}, this.overlays = {}, this.Os = new Bt(0), this.Fs = !1, this.Fs = !0,
- this.referenceDelegate = t(this), this.Bs = new Qo(this);
- this.indexManager = new Jr, this.remoteDocumentCache = function(t) {
- return new Ko(t);
- }((t => this.referenceDelegate.Ls(t))), this.serializer = new fr(e), this.qs = new Fo(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 Bo, this.overlays[t.toKey()] = e), e;
- }
- getMutationQueue(t, e) {
- let n = this.Ms[t.toKey()];
- return n || (n = new Uo(e, this.referenceDelegate), this.Ms[t.toKey()] = n), n;
- }
- getTargetCache() {
- return this.Bs;
- }
- getRemoteDocumentCache() {
- return this.remoteDocumentCache;
- }
- getBundleCache() {
- return this.qs;
- }
- runTransaction(t, e, n) {
- $("MemoryPersistence", "Starting transaction:", t);
- const s = new zo(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 bt.or(Object.values(this.Ms).map((n => () => n.containsKey(t, e))));
- }
- }
- class zo extends Rt {
- constructor(t) {
- super(), this.currentSequenceNumber = t;
- }
- }
- class Wo {
- constructor(t) {
- this.persistence = t,
-
- this.Qs = new Lo,
-
- this.js = null;
- }
- static zs(t) {
- return new Wo(t);
- }
- get Ws() {
- if (this.js) return this.js;
- throw B();
- }
- addReference(t, e, n) {
- return this.Qs.addReference(n, e), this.Ws.delete(n.toString()), bt.resolve();
- }
- removeReference(t, e, n) {
- return this.Qs.removeReference(n, e), this.Ws.add(n.toString()), bt.resolve();
- }
- markPotentiallyOrphaned(t, e) {
- return this.Ws.add(e.toString()), bt.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 bt.forEach(this.Ws, (n => {
- const s = ft.fromPath(n);
- return this.Hs(t, s).next((t => {
- t || e.removeEntry(s, ut.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 bt.or([ () => bt.resolve(this.Qs.containsKey(e)), () => this.persistence.getTargetCache().containsKey(t, e), () => this.persistence.Gs(t, e) ]);
- }
- }
- class Ho {
- constructor(t, e) {
- this.persistence = t, this.Js = new as((t => Kt(t.path)), ((t, e) => t.isEqual(e))),
- this.garbageCollector = vo(this, e);
- }
- static zs(t, e) {
- return new Ho(t, e);
- }
-
-
- Us() {}
- Ks(t) {
- return bt.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 bt.forEach(this.Js, ((n, s) => this.Xn(t, n, s).next((t => t ? bt.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, ut.min()));
- })))).next((() => i.apply(t))).next((() => n));
- }
- markPotentiallyOrphaned(t, e) {
- return this.Js.set(e, t.currentSequenceNumber), bt.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), bt.resolve();
- }
- removeReference(t, e, n) {
- return this.Js.set(n, t.currentSequenceNumber), bt.resolve();
- }
- updateLimboDocument(t, e) {
- return this.Js.set(e, t.currentSequenceNumber), bt.resolve();
- }
- Ls(t) {
- let e = t.key.toString().length;
- return t.isFoundDocument() && (e += Je(t.data.value)), e;
- }
- Xn(t, e, n) {
- return bt.or([ () => this.persistence.Gs(t, e), () => this.persistence.getTargetCache().containsKey(t, e), () => {
- const t = this.Js.get(e);
- return bt.resolve(void 0 !== t && t > n);
- } ]);
- }
- getCacheSize(t) {
- return this.persistence.getRemoteDocumentCache().getSize(t);
- }
- }
- class Jo {
- constructor(t) {
- this.serializer = t;
- }
-
- O(t, e, n, s) {
- const i = new Vt("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", zt, {
- unique: !0
- }), t.createObjectStore("documentMutations");
- }
-
- (t), Yo(t), function(t) {
- t.createObjectStore("remoteDocuments");
- }(t));
-
-
- let r = bt.resolve();
- return n < 3 && s >= 3 && (
-
-
- 0 !== n && (!function(t) {
- t.deleteObjectStore("targetDocuments"), t.deleteObjectStore("targets"), t.deleteObjectStore("targetGlobal");
- }(t), Yo(t)), r = r.next((() =>
-
- function(t) {
- const e = t.store("targetGlobal"), n = {
- highestTargetId: 0,
- highestListenSequenceNumber: 0,
- lastRemoteSnapshotVersion: ut.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", zt, {
- unique: !0
- });
- const s = e.store("mutations"), i = n.map((t => s.put(t)));
- return bt.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: ce
- });
- e.createIndex("collectionPathOverlayIndex", ae, {
- unique: !1
- }), e.createIndex("collectionGroupOverlayIndex", he, {
- unique: !1
- });
- }(t);
- }))), n < 13 && s >= 13 && (r = r.next((() => function(t) {
- const e = t.createObjectStore("remoteDocumentsV14", {
- keyPath: Yt
- });
- e.createIndex("documentKeyIndex", Xt), e.createIndex("collectionGroupIndex", Zt);
- }(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: ie
- }).createIndex("sequenceNumberIndex", re, {
- unique: !1
- });
- t.createObjectStore("indexEntries", {
- keyPath: oe
- }).createIndex("documentKeyIndex", ue, {
- unique: !1
- });
- }(t)))), r;
- }
- Xs(t) {
- let e = 0;
- return t.store("remoteDocuments").X(((t, n) => {
- e += co(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 => bt.forEach(e, (e => {
- const s = IDBKeyRange.bound([ e.userId, -1 ], [ e.userId, e.lastAcknowledgedBatchId ]);
- return n.j("userMutationsIndex", s).next((n => bt.forEach(n, (n => {
- L(n.userId === e.userId);
- const s = yr(this.serializer, n);
- return uo(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 at(n), o = function(t) {
- return [ 0, Kt(t) ];
- }(r);
- s.push(e.get(o).next((n => n ? bt.resolve() : (n => e.put({
- targetId: 0,
- path: Kt(n),
- sequenceNumber: t.highestListenSequenceNumber
- }))(r))));
- })).next((() => bt.waitFor(s)));
- }));
- }
- ti(t, e) {
-
- t.createObjectStore("collectionParents", {
- keyPath: se
- });
- const n = e.store("collectionParents"), s = new Yr, i = t => {
- if (s.add(t)) {
- const e = t.lastSegment(), s = t.popLast();
- return n.put({
- collectionId: e,
- parent: Kt(s)
- });
- }
- };
-
-
- return e.store("remoteDocuments").X({
- Y: !0
- }, ((t, e) => {
- const n = new at(t);
- return i(n.popLast());
- })).next((() => e.store("documentMutations").X({
- Y: !0
- }, (([t, e, n], s) => {
- const r = jt(e);
- return i(r.popLast());
- }))));
- }
- ei(t) {
- const e = t.store("targets");
- return e.X(((t, n) => {
- const s = pr(n), i = Ir(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 ft(at.fromString(o.document.name).popFirst(5)) : o.noDocument ? ft.fromSegments(o.noDocument.path) : o.unknownDocument ? ft.fromSegments(o.unknownDocument.path) : B()).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((() => bt.waitFor(s)));
- }
- si(t, e) {
- const n = e.store("mutations"), s = So(this.serializer), i = new jo(Wo.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 : Is();
- yr(this.serializer, t).keys().forEach((t => s = s.add(t))), n.set(t.userId, s);
- })), bt.forEach(n, ((t, n) => {
- const r = new D(n), o = Vr.de(this.serializer, r), u = i.getIndexManager(r), c = ao.de(r, this.serializer, u, i.referenceDelegate);
- return new Oo(s, c, o, u).recalculateAndSaveOverlaysForDocumentKeys(new me(e, Bt.ct), t).next();
- }));
- }));
- }
- }
- function Yo(t) {
- t.createObjectStore("targetDocuments", {
- keyPath: ee
- }).createIndex("documentTargetsIndex", ne, {
- unique: !0
- });
-
- t.createObjectStore("targets", {
- keyPath: "targetId"
- }).createIndex("queryTargetsIndex", te, {
- unique: !0
- }), t.createObjectStore("targetGlobal");
- }
- const Xo = "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 Zo {
- 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(), !Zo.D()) throw new G(K.UNIMPLEMENTED, "This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");
- this.referenceDelegate = new Ro(this, s), this.di = e + "main", this.serializer = new fr(u),
- this.wi = new St(this.di, this.ui, new Jo(this.serializer)), this.Bs = new mo(this.referenceDelegate, this.serializer),
- this.remoteDocumentCache = So(this.serializer), this.qs = new Rr, this.window && this.window.localStorage ? this._i = this.window.localStorage : (this._i = null,
- !1 === a && M("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 G(K.FAILED_PRECONDITION, Xo);
- return this.gi(), this.yi(), this.pi(), this.runTransaction("getHighestListenSequenceNumber", "readonly", (t => this.Bs.getHighestSequenceNumber(t)));
- })).then((t => {
- this.Os = new Bt(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 => eu(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 (xt(t))
-
-
- return $("IndexedDbPersistence", "Failed to extend owner lease: ", t), this.isPrimary;
- if (!this.allowTabSynchronization) throw t;
- return $("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 tu(t).get("owner").next((t => bt.resolve(this.Ri(t))));
- }
- Pi(t) {
- return eu(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 = ge(t, "clientMetadata");
- return e.j().next((t => {
- const n = this.Si(t, 18e5), s = t.filter((t => -1 === n.indexOf(t)));
-
- return bt.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 bt.resolve(!0);
- return tu(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 G(K.FAILED_PRECONDITION, Xo);
- return !1;
- }
- }
- return !(!this.networkEnabled || !this.inForeground) || eu(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 && $("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 me(t, Bt.ct);
- return this.Ai(e).next((() => this.Pi(e)));
- })), this.wi.close(),
-
-
- this.$i();
- }
-
- Si(t, e) {
- return t.filter((t => this.Vi(t.updateTimeMs, e) && !this.Ci(t.clientId)));
- }
-
- Mi() {
- return this.runTransaction("getActiveClients", "readonly", (t => eu(t).j().next((t => this.Si(t, 18e5).map((t => t.clientId))))));
- }
- get started() {
- return this.Fs;
- }
- getMutationQueue(t, e) {
- return ao.de(t, this.serializer, e, this.referenceDelegate);
- }
- getTargetCache() {
- return this.Bs;
- }
- getRemoteDocumentCache() {
- return this.remoteDocumentCache;
- }
- getIndexManager(t) {
- return new Zr(t, this.serializer.fe.databaseId);
- }
- getDocumentOverlayCache(t) {
- return Vr.de(this.serializer, t);
- }
- getBundleCache() {
- return this.qs;
- }
- runTransaction(t, e, n) {
- $("IndexedDbPersistence", "Starting transaction:", t);
- const s = "readonly" === e ? "readonly" : "readwrite", i = 15 === (r = this.ui) ? _e : 14 === r ? we : 13 === r ? de : 12 === r ? fe : 11 === r ? le : void B();
-
- var r;
- let o;
-
-
- return this.wi.runTransaction(t, s, i, (s => (o = new me(s, this.Os ? this.Os.next() : Bt.ct),
- "readwrite-primary" === e ? this.Ti(o).next((t => !!t || this.Ei(o))).next((e => {
- if (!e) throw M(`Failed to obtain primary lease for action '${t}'.`), this.isPrimary = !1,
- this.ii.enqueueRetryable((() => this.fi(!1))), new G(K.FAILED_PRECONDITION, vt);
- return n(o);
- })).next((t => this.vi(o).next((() => t)))) : this.Oi(o).next((() => n(o)))))).then((t => (o.raiseOnCommittedEvent(),
- t)));
- }
-
-
-
- Oi(t) {
- return tu(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 G(K.FAILED_PRECONDITION, Xo);
- }));
- }
-
- vi(t) {
- const e = {
- ownerId: this.clientId,
- allowTabSynchronization: this.allowTabSynchronization,
- leaseTimestampMs: Date.now()
- };
- return tu(t).put("owner", e);
- }
- static D() {
- return St.D();
- }
- Ai(t) {
- const e = tu(t);
- return e.get("owner").next((t => this.Ri(t) ? ($("IndexedDbPersistence", "Releasing primary lease."),
- e.delete("owner")) : bt.resolve()));
- }
- Vi(t, e) {
- const n = Date.now();
- return !(t < n - e) && (!(t > n) || (M(`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]/;
- d() && (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 $("IndexedDbPersistence", `Client '${t}' ${n ? "is" : "is not"} zombied in LocalStorage`),
- n;
- } catch (t) {
-
- return M("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) {
-
- M("Failed to set zombie client id.", t);
- }
- }
- $i() {
- if (this._i) try {
- this._i.removeItem(this.Di(this.clientId));
- } catch (t) {
-
- }
- }
- Di(t) {
- return `firestore_zombie_${this.persistenceKey}_${t}`;
- }
- }
- function tu(t) {
- return ge(t, "owner");
- }
- function eu(t) {
- return ge(t, "clientMetadata");
- }
- function nu(t, e) {
-
-
-
-
-
- let n = t.projectId;
- return t.isDefaultDatabase || (n += "." + t.database), "firestore/" + e + "/" + n + "/";
- }
- class su {
- constructor(t, e, n, s) {
- this.targetId = t, this.fromCache = e, this.Fi = n, this.Bi = s;
- }
- static Li(t, e) {
- let n = Is(), s = Is();
- 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 su(t, e.fromCache, n, s);
- }
- }
- class iu {
- 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 (Wn(e))
-
-
-
- return bt.resolve(null);
- let n = Zn(e);
- return this.indexManager.getIndexType(t, n).next((s => 0 === s ? null : (null !== e.limit && 1 === s && (
-
-
-
-
-
-
-
- e = es(e, null, "F" ), n = Zn(e)), this.indexManager.getDocumentsMatchingTarget(t, n).next((s => {
- const i = Is(...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, es(e, null, "F" )) : this.Wi(t, r, e, n);
- }))));
- })))));
- }
-
- Gi(t, e, n, s) {
- return Wn(e) || s.isEqual(ut.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) : (N() <= u.DEBUG && $("QueryEngine", "Re-using previous result from %s to execute query: %s", s.toString(), is(e)),
- this.Wi(t, r, e, It(s, -1)));
- }));
-
-
- }
- ji(t, e) {
-
-
- let n = new ve(us(t));
- return e.forEach(((e, s) => {
- rs(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 N() <= u.DEBUG && $("QueryEngine", "Using full collection scan to execute query:", is(e)),
- this.Ui.getDocumentsMatchingQuery(t, e, Et.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 ru {
- constructor(
- /** Manages our in-memory or durable persistence. */
- t, e, n, s) {
- this.persistence = t, this.Hi = e, this.serializer = s,
-
- this.Ji = new Te(st),
-
-
- this.Yi = new as((t => Bn(t)), Ln),
-
- 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 Oo(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 ou(
- t, e, n, s) {
- return new ru(t, e, n, s);
- }
- async function uu(t, e) {
- const n = U(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 = Is();
- 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 cu(t, e) {
- const n = U(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 = bt.resolve();
- return r.forEach((t => {
- o = o.next((() => s.getEntry(e, t))).next((e => {
- const r = n.docVersions.get(t);
- L(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 = Is();
- 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 au(t) {
- const e = U(t);
- return e.persistence.runTransaction("Get last remote snapshot version", "readonly", (t => e.Bs.getLastRemoteSnapshotVersion(t)));
- }
- function hu(t, e) {
- const n = U(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(Ce.EMPTY_BYTE_STRING, ut.min()).withLastLimboFreeSnapshotVersion(ut.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 = ls(), c = Is();
-
-
-
-
- if (e.documentUpdates.forEach((s => {
- e.resolvedLimboDocuments.has(s) && o.push(n.persistence.referenceDelegate.updateLimboDocument(t, s));
- })),
-
-
- o.push(lu(t, r, e.documentUpdates).next((t => {
- u = t.nr, c = t.sr;
- }))), !s.isEqual(ut.min())) {
- const e = n.Bs.getLastRemoteSnapshotVersion(t).next((e => n.Bs.setTargetsMetadata(t, t.currentSequenceNumber, s)));
- o.push(e);
- }
- return bt.waitFor(o).next((() => r.apply(t))).next((() => n.localDocuments.getLocalViewOfDocuments(t, u, c))).next((() => u));
- })).then((t => (n.Ji = i, t)));
- }
- function lu(t, e, n) {
- let s = Is(), i = Is();
- return n.forEach((t => s = s.add(t))), e.getEntries(t, s).next((t => {
- let s = ls();
- return n.forEach(((n, r) => {
- const o = t.get(n);
-
- r.isFoundDocument() !== o.isFoundDocument() && (i = i.add(n)),
-
-
-
-
- r.isNoDocument() && r.version.isEqual(ut.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)) : $("LocalStore", "Ignoring outdated watch update for ", n, ". Current version:", o.version, " Watch version:", r.version);
- })), {
- nr: s,
- sr: i
- };
- }));
- }
- function fu(t, e) {
- const n = U(t);
- return n.persistence.runTransaction("Get next mutation batch", "readonly", (t => (void 0 === e && (e = -1),
- n.mutationQueue.getNextMutationBatchAfterBatchId(t, e))));
- }
- function du(t, e) {
- const n = U(t);
- return n.persistence.runTransaction("Allocate target", "readwrite", (t => {
- let s;
- return n.Bs.getTargetData(t, e).next((i => i ? (
-
-
-
- s = i, bt.resolve(s)) : n.Bs.allocateTargetId(t).next((i => (s = new lr(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 wu(t, e, n) {
- const s = U(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 (!xt(t)) throw t;
-
-
-
-
-
- $("LocalStore", `Failed to update sequence numbers for target ${e}: ${t}`);
- }
- s.Ji = s.Ji.remove(e), s.Yi.delete(i.target);
- }
- function _u(t, e, n) {
- const s = U(t);
- let i = ut.min(), r = Is();
- return s.persistence.runTransaction("Execute query", "readonly", (t => function(t, e, n) {
- const s = U(t), i = s.Yi.get(n);
- return void 0 !== i ? bt.resolve(s.Ji.get(i)) : s.Bs.getTargetData(e, n);
- }(s, t, Zn(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 : ut.min(), n ? r : Is()))).next((t => (yu(s, os(e), t),
- {
- documents: t,
- ir: r
- })))));
- }
- function mu(t, e) {
- const n = U(t), s = U(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 gu(t, e) {
- const n = U(t), s = n.Xi.get(e) || ut.min();
-
-
-
-
- return n.persistence.runTransaction("Get new document changes", "readonly", (t => n.Zi.getAllFromCollectionGroup(t, e, It(s, -1),
- Number.MAX_SAFE_INTEGER))).then((t => (yu(n, e, t), t)));
- }
- function yu(t, e, n) {
- let s = t.Xi.get(e) || ut.min();
- n.forEach(((t, e) => {
- e.readTime.compareTo(s) > 0 && (s = e.readTime);
- })), t.Xi.set(e, s);
- }
- async function pu(t, e, n, s) {
- const i = U(t);
- let r = Is(), o = ls();
- 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 du(i, function(t) {
-
-
- return Zn(zn(at.fromString(`__bundle__/docs/${t}`)));
- }(s));
-
-
- return i.persistence.runTransaction("Apply bundle documents", "readwrite", (t => lu(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 Iu(t, e, n = Is()) {
-
-
-
-
-
- const s = await du(t, Zn(Tr(e.bundledQuery))), i = U(t);
- return i.persistence.runTransaction("Save named query", "readwrite", (t => {
- const r = Mi(e.readTime);
-
-
- if (s.snapshotVersion.compareTo(r) >= 0) return i.qs.saveNamedQuery(t, e);
-
- const o = s.withResumeToken(Ce.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 Tu(t, e) {
- return `firestore_clients_${t}_${e}`;
- }
- function Eu(t, e, n) {
- let s = `firestore_mutations_${t}_${n}`;
- return e.isAuthenticated() && (s += `_${e.uid}`), s;
- }
- function Au(t, e) {
- return `firestore_targets_${t}_${e}`;
- }
- class vu {
- 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 G(s.error.code, s.error.message))), r ? new vu(t, e, s.state, i) : (M("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 Ru {
- 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 G(n.error.code, n.error.message))), i ? new Ru(t, n.state, s) : (M("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 Pu {
- 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 = Es();
- for (let t = 0; s && t < n.activeTargetIds.length; ++t) s = Ut(n.activeTargetIds[t]),
- i = i.add(n.activeTargetIds[t]);
- return s ? new Pu(t, i) : (M("SharedClientState", `Failed to parse client data for instance '${t}': ${e}`),
- null);
- }
- }
- class bu {
- 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 bu(e.clientId, e.onlineState) : (M("SharedClientState", `Failed to parse online state: ${t}`),
- null);
- }
- }
- class Vu {
- constructor() {
- this.activeTargetIds = Es();
- }
- 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 Su {
- 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 Te(st), this.started = !1,
-
- this.yr = [];
-
-
- const r = n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
- this.storage = this.window.localStorage, this.currentUser = i, this.pr = Tu(this.persistenceKey, this.wr),
- this.Ir =
-
- function(t) {
- return `firestore_sequence_number_${t}`;
- }
-
- (this.persistenceKey), this.gr = this.gr.insert(this.wr, new Vu), 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.Mi();
- for (const e of t) {
- if (e === this.wr) continue;
- const t = this.getItem(Tu(this.persistenceKey, e));
- if (t) {
- const n = Pu.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(Au(this.persistenceKey, t));
- if (n) {
- const s = Ru.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(Au(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.$r(t);
- }
- notifyBundleLoaded(t) {
- this.Mr(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 $("SharedClientState", "READ", t, e), e;
- }
- setItem(t, e) {
- $("SharedClientState", "SET", t, e), this.storage.setItem(t, e);
- }
- removeItem(t) {
- $("SharedClientState", "REMOVE", t), this.storage.removeItem(t);
- }
- mr(t) {
-
-
- const e = t;
- if (e.storageArea === this.storage) {
- if ($("SharedClientState", "EVENT", e.key, e.newValue), e.key === this.pr) return void M("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 = Bt.ct;
- if (null != t) try {
- const n = JSON.parse(t);
- L("number" == typeof n), e = n;
- } catch (t) {
- M("SharedClientState", "Failed to read sequence number from WebStorage", t);
- }
- return e;
- }
-
- (e.newValue);
- t !== Bt.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 vu(this.currentUser, t, e, n), i = Eu(this.persistenceKey, this.currentUser, t);
- this.setItem(i, s.hr());
- }
- Cr(t) {
- const e = Eu(this.persistenceKey, this.currentUser, t);
- this.removeItem(e);
- }
- $r(t) {
- const e = {
- clientId: this.wr,
- onlineState: t
- };
- this.storage.setItem(this.vr, JSON.stringify(e));
- }
- kr(t, e, n) {
- const s = Au(this.persistenceKey, t), i = new Ru(t, e, n);
- this.setItem(s, i.hr());
- }
- Mr(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 Pu.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 vu.ar(new D(i), s, e);
- }
-
- Ur(t, e) {
- const n = this.Ar.exec(t), s = Number(n[1]);
- return Ru.ar(s, e);
- }
-
- br(t) {
- return bu.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);
- $("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 = Es();
- return t.forEach(((t, n) => {
- e = e.unionWith(n.activeTargetIds);
- })), e;
- }
- }
- class Du {
- constructor() {
- this.Hr = new Vu, 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 Vu, Promise.resolve();
- }
- handleUserChange(t, e, n) {
-
- }
- setOnlineState(t) {
-
- }
- shutdown() {}
- writeSequenceNumber(t) {}
- notifyBundleLoaded(t) {
-
- }
- }
- class Cu {
- Yr(t) {
-
- }
- shutdown() {
-
- }
- }
- class xu {
- 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() {
- $("ConnectivityMonitor", "Network connectivity changed: AVAILABLE");
- for (const t of this.so) t(0 );
- }
- no() {
- $("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 Nu = null;
- function ku() {
- return null === Nu ? Nu = 268435456 + Math.round(2147483648 * Math.random()) : Nu++,
- "0x" + Nu.toString(16);
- }
- const $u = {
- BatchGetDocuments: "batchGet",
- Commit: "commit",
- RunQuery: "runQuery",
- RunAggregationQuery: "runAggregationQuery"
- };
- class Mu {
- 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 Ou = "WebChannelConnection";
- class Fu 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 = ku(), o = this.To(t, e);
- $("RestConnection", `Sending RPC '${t}' ${r}:`, o, n);
- const u = {};
- return this.Eo(u, s, i), this.Ao(t, o, u, n).then((e => ($("RestConnection", `Received RPC '${t}' ${r}: `, e),
- e)), (e => {
- throw O("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/" + C,
-
-
-
-
- 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 = $u[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 = ku();
- return new Promise(((r, o) => {
- const u = new I;
- u.setWithCredentials(!0), u.listenOnce(T.COMPLETE, (() => {
- try {
- switch (u.getLastErrorCode()) {
- case E.NO_ERROR:
- const e = u.getResponseJson();
- $(Ou, `XHR for RPC '${t}' ${i} received:`, JSON.stringify(e)), r(e);
- break;
- case E.TIMEOUT:
- $(Ou, `RPC '${t}' ${i} timed out`), o(new G(K.DEADLINE_EXCEEDED, "Request time out"));
- break;
- case E.HTTP_ERROR:
- const n = u.getStatus();
- if ($(Ou, `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(K).indexOf(e) >= 0 ? e : K.UNKNOWN;
- }(e.status);
- o(new G(t, e.message));
- } else o(new G(K.UNKNOWN, "Server responded with status " + u.getStatus()));
- } else
-
-
- o(new G(K.UNAVAILABLE, "Connection failed."));
- break;
- default:
- B();
- }
- } finally {
- $(Ou, `RPC '${t}' ${i} completed.`);
- }
- }));
- const c = JSON.stringify(s);
- $(Ou, `RPC '${t}' ${i} sending request:`, s), u.send(e, "POST", c, n, 15);
- }));
- }
- Ro(t, e, n) {
- const s = ku(), i = [ this.mo, "/", "google.firestore.v1.Firestore", "/", t, "/channel" ], r = A(), o = v(), 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 R({})),
- this.Eo(u.initMessageHeaders, e, n),
-
-
-
-
-
-
-
-
-
- u.encodeInitMessageHeaders = !0;
- const a = i.join("");
- $(Ou, `Creating RPC '${t}' stream ${s}: ${a}`, u);
- const h = r.createWebChannel(a, u);
-
-
-
-
-
- let l = !1, f = !1;
-
-
-
- const d = new Mu({
- ro: e => {
- f ? $(Ou, `Not sending because RPC '${t}' stream ${s} is closed:`, e) : (l || ($(Ou, `Opening RPC '${t}' stream ${s} transport.`),
- h.open(), l = !0), $(Ou, `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, P.EventType.OPEN, (() => {
- f || $(Ou, `RPC '${t}' stream ${s} transport opened.`);
- })), w(h, P.EventType.CLOSE, (() => {
- f || (f = !0, $(Ou, `RPC '${t}' stream ${s} transport closed`), d.wo());
- })), w(h, P.EventType.ERROR, (e => {
- f || (f = !0, O(Ou, `RPC '${t}' stream ${s} transport errored:`, e), d.wo(new G(K.UNAVAILABLE, "The operation could not be completed")));
- })), w(h, P.EventType.MESSAGE, (e => {
- var n;
- if (!f) {
- const i = e.data[0];
- L(!!i);
-
-
-
-
-
- const r = i, o = r.error || (null === (n = r[0]) || void 0 === n ? void 0 : n.error);
- if (o) {
- $(Ou, `RPC '${t}' stream ${s} received error:`, o);
-
- const e = o.status;
- let n =
-
- function(t) {
-
-
- const e = ui[t];
- if (void 0 !== e) return hi(e);
- }(e), i = o.message;
- void 0 === n && (n = K.INTERNAL, i = "Unknown error status: " + e + " with message " + o.message),
-
- f = !0, d.wo(new G(n, i)), h.close();
- } else $(Ou, `RPC '${t}' stream ${s} received:`, i), d._o(i);
- }
- })), w(o, b.STAT_EVENT, (e => {
- e.stat === V.PROXY ? $(Ou, `RPC '${t}' stream ${s} detected buffering proxy`) : e.stat === V.NOPROXY && $(Ou, `RPC '${t}' stream ${s} detected no buffering proxy`);
- })), setTimeout((() => {
-
-
-
-
- d.fo();
- }), 0), d;
- }
- }
- function Bu() {
-
-
- return "undefined" != typeof window ? window : null;
- }
- function Lu() {
-
-
- return "undefined" != typeof document ? document : null;
- }
- function qu(t) {
- return new Ci(t, !0);
- }
- class Uu {
- 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 && $("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);
- }
- $o() {
- 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 Ku {
- constructor(t, e, n, s, i, r, o, u) {
- this.ii = t, this.Mo = 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 Uu(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.Mo, 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 === K.RESOURCE_EXHAUSTED ? (
-
- M(e.toString()), M("Using maximum backoff delay to prevent overloading the backend."),
- this.qo.xo()) : e && e.code === K.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 G(K.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 $("PersistentStream", `close with error: ${t}`), this.stream = null, this.close(4 , t);
- }
-
- Xo(t) {
- return e => {
- this.ii.enqueueAndForget((() => this.Fo === t ? e() : ($("PersistentStream", "stream callback skipped by getCloseGuardedDispatcher."),
- Promise.resolve())));
- };
- }
- }
- class Gu extends Ku {
- 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 = Wi(this.serializer, t), n = function(t) {
-
-
-
- if (!("targetChange" in t)) return ut.min();
- const e = t.targetChange;
- return e.targetIds && e.targetIds.length ? ut.min() : e.readTime ? Mi(e.readTime) : ut.min();
- }(t);
- return this.listener.nu(e, n);
- }
-
- su(t) {
- const e = {};
- e.database = Ki(this.serializer), e.addTarget = function(t, e) {
- let n;
- const s = e.target;
- if (n = qn(s) ? {
- documents: Xi(t, s)
- } : {
- query: Zi(t, s)
- }, n.targetId = e.targetId, e.resumeToken.approximateByteSize() > 0) {
- n.resumeToken = ki(t, e.resumeToken);
- const s = xi(t, e.expectedCount);
- null !== s && (n.expectedCount = s);
- } else if (e.snapshotVersion.compareTo(ut.min()) > 0) {
-
-
-
- n.readTime = Ni(t, e.snapshotVersion.toTimestamp());
- const s = xi(t, e.expectedCount);
- null !== s && (n.expectedCount = s);
- }
- return n;
- }(this.serializer, t);
- const n = er(this.serializer, t);
- n && (e.labels = n), this.Wo(e);
- }
-
- iu(t) {
- const e = {};
- e.database = Ki(this.serializer), e.removeTarget = t, this.Wo(e);
- }
- }
- class Qu extends Ku {
- 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 (
-
- L(!!t.streamToken), this.lastStreamToken = t.streamToken, this.ru) {
-
-
-
- this.qo.reset();
- const e = Yi(t.writeResults, t.commitTime), n = Mi(t.commitTime);
- return this.listener.cu(n, e);
- }
-
- return L(!t.writeResults || 0 === t.writeResults.length), this.ru = !0, this.listener.au();
- }
-
- hu() {
-
-
- const t = {};
- t.database = Ki(this.serializer), this.Wo(t);
- }
- uu(t) {
- const e = {
- streamToken: this.lastStreamToken,
- writes: t.map((t => Hi(this.serializer, t)))
- };
- this.Wo(e);
- }
- }
- class ju 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 G(K.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 === K.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
- this.appCheckCredentials.invalidateToken()), t) : new G(K.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 === K.UNAUTHENTICATED && (this.authCredentials.invalidateToken(),
- this.appCheckCredentials.invalidateToken()), t) : new G(K.UNKNOWN, t.toString());
- }));
- }
- terminate() {
- this.lu = !0;
- }
- }
- async function zu(t, e, n) {
- var s;
- const i = U(t), {request: r, du: o} = function(t, e, n) {
- const s = Zi(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: or(t.fieldPath)
- }
- }) : "sum" === t.yt && r.push({
- alias: e,
- sum: {
- field: or(t.fieldPath)
- }
- });
- })), {
- request: {
- structuredAggregationQuery: {
- aggregations: r,
- structuredQuery: s.structuredQuery
- },
- parent: s.parent
- },
- du: i
- };
- }(i.serializer, Zn(e), n), u = r.parent;
- i.connection.po || delete r.parent;
- const c = (await i.vo("RunAggregationQuery", u, r, 1)).filter((t => !!t.result));
-
- L(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 Wu {
- 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 ? (M(e), this.mu = !1) : $("OnlineStateTracker", e);
- }
- Tu() {
- null !== this._u && (this._u.cancel(), this._u = null);
- }
- }
- class Hu {
- 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 () => {
-
-
-
- ic(this) && ($("RemoteStore", "Restarting streams for network reachability change."),
- await async function(t) {
- const e = U(t);
- e.vu.add(4 ), await Yu(e), e.bu.set("Unknown" ),
- e.vu.delete(4 ), await Ju(e);
- }(this));
- }));
- })), this.bu = new Wu(n, s);
- }
- }
- async function Ju(t) {
- if (ic(t)) for (const e of t.Ru) await e( !0);
- }
- async function Yu(t) {
- for (const e of t.Ru) await e( !1);
- }
- function Xu(t, e) {
- const n = U(t);
- n.Au.has(e.targetId) || (
-
- n.Au.set(e.targetId, e), sc(n) ?
-
- nc(n) : Ec(n).Ko() && tc(n, e));
- }
- function Zu(t, e) {
- const n = U(t), s = Ec(n);
- n.Au.delete(e), s.Ko() && ec(n, e), 0 === n.Au.size && (s.Ko() ? s.jo() : ic(n) &&
-
-
-
- n.bu.set("Unknown" ));
- }
- function tc(t, e) {
- if (t.Vu.qt(e.targetId), e.resumeToken.approximateByteSize() > 0 || e.snapshotVersion.compareTo(ut.min()) > 0) {
- const n = t.remoteSyncer.getRemoteKeysForTarget(e.targetId).size;
- e = e.withExpectedCount(n);
- }
- Ec(t).su(e);
- }
- function ec(t, e) {
- t.Vu.qt(e), Ec(t).iu(e);
- }
- function nc(t) {
- t.Vu = new Ri({
- getRemoteKeysForTarget: e => t.remoteSyncer.getRemoteKeysForTarget(e),
- le: e => t.Au.get(e) || null,
- ue: () => t.datastore.serializer.databaseId
- }), Ec(t).start(), t.bu.gu();
- }
- function sc(t) {
- return ic(t) && !Ec(t).Uo() && t.Au.size > 0;
- }
- function ic(t) {
- return 0 === U(t).vu.size;
- }
- function rc(t) {
- t.Vu = void 0;
- }
- async function oc(t) {
- t.Au.forEach(((e, n) => {
- tc(t, e);
- }));
- }
- async function uc(t, e) {
- rc(t),
-
- sc(t) ? (t.bu.Iu(e), nc(t)) :
-
-
-
- t.bu.set("Unknown" );
- }
- async function cc(t, e, n) {
- if (
-
- t.bu.set("Online" ), e instanceof Ai && 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) {
- $("RemoteStore", "Failed to remove targets %s: %s ", e.targetIds.join(","), n),
- await ac(t, n);
- } else if (e instanceof Ti ? t.Vu.Ht(e) : e instanceof Ei ? t.Vu.ne(e) : t.Vu.Xt(e),
- !n.isEqual(ut.min())) try {
- const e = await au(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(Ce.EMPTY_BYTE_STRING, s.snapshotVersion)),
-
-
- ec(t, e);
-
-
-
-
- const i = new lr(s.target, e, n, s.sequenceNumber);
- tc(t, i);
- })), t.remoteSyncer.applyRemoteEvent(n);
- }(t, n);
- } catch (e) {
- $("RemoteStore", "Failed to raise snapshot:", e), await ac(t, e);
- }
- }
- async function ac(t, e, n) {
- if (!xt(e)) throw e;
- t.vu.add(1 ),
-
- await Yu(t), t.bu.set("Offline" ), n || (
-
-
-
- n = () => au(t.localStore)),
-
- t.asyncQueue.enqueueRetryable((async () => {
- $("RemoteStore", "Retrying IndexedDB access"), await n(), t.vu.delete(1 ),
- await Ju(t);
- }));
- }
- function hc(t, e) {
- return e().catch((n => ac(t, n, e)));
- }
- async function lc(t) {
- const e = U(t), n = Ac(e);
- let s = e.Eu.length > 0 ? e.Eu[e.Eu.length - 1].batchId : -1;
- for (;fc(e); ) try {
- const t = await fu(e.localStore, s);
- if (null === t) {
- 0 === e.Eu.length && n.jo();
- break;
- }
- s = t.batchId, dc(e, t);
- } catch (t) {
- await ac(e, t);
- }
- wc(e) && _c(e);
- }
- function fc(t) {
- return ic(t) && t.Eu.length < 10;
- }
- function dc(t, e) {
- t.Eu.push(e);
- const n = Ac(t);
- n.Ko() && n.ou && n.uu(e.mutations);
- }
- function wc(t) {
- return ic(t) && !Ac(t).Uo() && t.Eu.length > 0;
- }
- function _c(t) {
- Ac(t).start();
- }
- async function mc(t) {
- Ac(t).hu();
- }
- async function gc(t) {
- const e = Ac(t);
-
- for (const n of t.Eu) e.uu(n.mutations);
- }
- async function yc(t, e, n) {
- const s = t.Eu.shift(), i = si.from(s, e, n);
- await hc(t, (() => t.remoteSyncer.applySuccessfulWrite(i))),
-
-
- await lc(t);
- }
- async function pc(t, e) {
-
-
- e && Ac(t).ou &&
-
- await async function(t, e) {
-
-
- if (n = e.code, ai(n) && n !== K.ABORTED) {
-
-
- const n = t.Eu.shift();
-
-
-
- Ac(t).Qo(), await hc(t, (() => t.remoteSyncer.rejectFailedWrite(n.batchId, e))),
-
-
- await lc(t);
- }
- var n;
- }(t, e),
-
-
- wc(t) && _c(t);
- }
- async function Ic(t, e) {
- const n = U(t);
- n.asyncQueue.verifyOperationInProgress(), $("RemoteStore", "RemoteStore received new credentials");
- const s = ic(n);
-
-
-
- n.vu.add(3 ), await Yu(n), s &&
-
- n.bu.set("Unknown" ), await n.remoteSyncer.handleCredentialChange(e),
- n.vu.delete(3 ), await Ju(n);
- }
- async function Tc(t, e) {
- const n = U(t);
- e ? (n.vu.delete(2 ), await Ju(n)) : e || (n.vu.add(2 ),
- await Yu(n), n.bu.set("Unknown" ));
- }
- function Ec(t) {
- return t.Su || (
-
- t.Su = function(t, e, n) {
- const s = U(t);
- return s.fu(), new Gu(e, s.connection, s.authCredentials, s.appCheckCredentials, s.serializer, n);
- }
-
- (t.datastore, t.asyncQueue, {
- uo: oc.bind(null, t),
- ao: uc.bind(null, t),
- nu: cc.bind(null, t)
- }), t.Ru.push((async e => {
- e ? (t.Su.Qo(), sc(t) ? nc(t) : t.bu.set("Unknown" )) : (await t.Su.stop(),
- rc(t));
- }))), t.Su;
- }
- function Ac(t) {
- return t.Du || (
-
- t.Du = function(t, e, n) {
- const s = U(t);
- return s.fu(), new Qu(e, s.connection, s.authCredentials, s.appCheckCredentials, s.serializer, n);
- }(t.datastore, t.asyncQueue, {
- uo: mc.bind(null, t),
- ao: pc.bind(null, t),
- au: gc.bind(null, t),
- cu: yc.bind(null, t)
- }), t.Ru.push((async e => {
- e ? (t.Du.Qo(),
-
- await lc(t)) : (await t.Du.stop(), t.Eu.length > 0 && ($("RemoteStore", `Stopping write stream with ${t.Eu.length} pending writes`),
- t.Eu = []));
- }))), t.Du;
- }
- class vc {
- constructor(t, e, n, s, i) {
- this.asyncQueue = t, this.timerId = e, this.targetTimeMs = n, this.op = s, this.removalCallback = i,
- this.deferred = new Q, 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 vc(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 G(K.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 Rc(t, e) {
- if (M("AsyncQueue", `${e}: ${t}`), xt(t)) return new G(K.UNAVAILABLE, `${e}: ${t}`);
- throw t;
- }
- class Pc {
-
- constructor(t) {
-
-
- this.comparator = t ? (e, n) => t(e, n) || ft.comparator(e.key, n.key) : (t, e) => ft.comparator(t.key, e.key),
- this.keyedMap = ds(), this.sortedSet = new Te(this.comparator);
- }
-
- static emptySet(t) {
- return new Pc(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 Pc)) 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 Pc;
- return n.comparator = this.comparator, n.keyedMap = t, n.sortedSet = e, n;
- }
- }
- class bc {
- constructor() {
- this.Cu = new Te(ft.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
- }) :
-
-
-
-
-
-
-
- B() : this.Cu = this.Cu.insert(e, t);
- }
- xu() {
- const t = [];
- return this.Cu.inorderTraversal(((e, n) => {
- t.push(n);
- })), t;
- }
- }
- class Vc {
- 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 Vc(t, e, Pc.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) && ns(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 Sc {
- constructor() {
- this.Nu = void 0, this.listeners = [];
- }
- }
- class Dc {
- constructor() {
- this.queries = new as((t => ss(t)), ns), this.onlineState = "Unknown" ,
- this.ku = new Set;
- }
- }
- async function Cc(t, e) {
- const n = U(t), s = e.query;
- let i = !1, r = n.queries.get(s);
- if (r || (i = !0, r = new Sc), i) try {
- r.Nu = await n.onListen(s);
- } catch (t) {
- const n = Rc(t, `Initialization of query '${is(e.query)}' failed`);
- return void e.onError(n);
- }
- if (n.queries.set(s, r), r.listeners.push(e),
-
- e.$u(n.onlineState), r.Nu) {
- e.Mu(r.Nu) && $c(n);
- }
- }
- async function xc(t, e) {
- const n = U(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 Nc(t, e) {
- const n = U(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.Mu(t) && (s = !0);
- i.Nu = t;
- }
- }
- s && $c(n);
- }
- function kc(t, e, n) {
- const s = U(t), i = s.queries.get(e);
- if (i) for (const t of i.listeners) t.onError(n);
-
-
- s.queries.delete(e);
- }
- function $c(t) {
- t.ku.forEach((t => {
- t.next();
- }));
- }
- class Mc {
- constructor(t, e, n) {
- this.query = t, this.Ou = e,
-
- this.Fu = !1, this.Bu = null, this.onlineState = "Unknown" ,
- this.options = n || {};
- }
-
- Mu(t) {
- if (!this.options.includeMetadataChanges) {
-
- const e = [];
- for (const n of t.docChanges) 3 !== n.type && e.push(n);
- t = new Vc(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);
- }
- $u(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 = Vc.fromInitialDocuments(t.query, t.docs, t.mutatedKeys, t.fromCache, t.hasCachedResults),
- this.Fu = !0, this.Ou.next(t);
- }
- }
- class Oc {
- 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 Fc {
- constructor(t) {
- this.serializer = t;
- }
- rr(t) {
- return Li(this.serializer, t);
- }
-
- ur(t) {
- return t.metadata.exists ? ji(this.serializer, t.document, !1) : fn.newNoDocument(this.rr(t.metadata.name), this.cr(t.metadata.readTime));
- }
- cr(t) {
- return Mi(t);
- }
- }
- class Bc {
- constructor(t, e, n) {
- this.ju = t, this.localStore = e, this.serializer = n,
-
- this.queries = [],
-
- this.documents = [],
-
- this.collectionGroups = new Set, this.progress = Lc(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 = at.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 Fc(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) || Is()).add(t);
- e.set(n, s);
- }
- }
- return e;
- }
-
- async complete() {
- const t = await pu(this.localStore, new Fc(this.serializer), this.documents, this.ju.id), e = this.Wu(this.documents);
- for (const t of this.queries) await Iu(this.localStore, t, e.get(t.name));
- return this.progress.taskState = "Success", {
- progress: this.progress,
- Hu: this.collectionGroups,
- Ju: t
- };
- }
- }
- function Lc(t) {
- return {
- taskState: "Running",
- documentsLoaded: 0,
- bytesLoaded: 0,
- totalDocuments: t.totalDocuments,
- totalBytes: t.totalBytes
- };
- }
- class qc {
- constructor(t) {
- this.key = t;
- }
- }
- class Uc {
- constructor(t) {
- this.key = t;
- }
- }
- class Kc {
- 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 = Is(),
-
- this.mutatedKeys = Is(), this.tc = us(t), this.ec = new Pc(this.tc);
- }
-
- get nc() {
- return this.Yu;
- }
-
- sc(t, e) {
- const n = e ? e.ic : new bc, 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 = rs(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 B();
- }
- };
- 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 Vc(this.query, t.ec, s, i, t.mutatedKeys, 0 === o, u,
- !1, !!n && n.resumeToken.approximateByteSize() > 0),
- cc: r
- };
- }
-
- return {
- cc: r
- };
- }
-
- $u(t) {
- return this.current && "Offline" === t ? (
-
-
-
-
- this.current = !1, this.applyChanges({
- ec: this.ec,
- ic: new bc,
- 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 = Is(), 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 Uc(t));
- })), this.Zu.forEach((n => {
- t.has(n) || e.push(new qc(n));
- })), e;
- }
-
-
- hc(t) {
- this.Yu = t.ir, this.Zu = Is();
- const e = this.sc(t.documents);
- return this.applyChanges(e, !0);
- }
-
-
- lc() {
- return Vc.fromInitialDocuments(this.query, this.ec, this.mutatedKeys, 0 === this.Xu, this.hasCachedResults);
- }
- }
- class Gc {
- 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 Qc {
- constructor(t) {
- this.key = t,
-
- this.fc = !1;
- }
- }
- class jc {
- 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 as((t => ss(t)), ns),
- this._c = new Map,
-
- this.mc = new Set,
-
- this.gc = new Te(ft.comparator),
-
- this.yc = new Map, this.Ic = new Lo,
-
- this.Tc = {},
-
- this.Ec = new Map, this.Ac = _o.$n(), this.onlineState = "Unknown" ,
-
-
-
- this.vc = void 0;
- }
- get isPrimaryClient() {
- return !0 === this.vc;
- }
- }
- async function zc(t, e) {
- const n = Ea(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 du(n.localStore, Zn(e)), r = n.sharedClientState.addLocalQueryTarget(t.targetId);
- s = t.targetId, i = await Wc(n, e, s, "current" === r, t.resumeToken), n.isPrimaryClient && Xu(n.remoteStore, t);
- }
- return i;
- }
- async function Wc(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 _u(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 ua(t, e.targetId, o.cc), o.snapshot;
- }(t, e, n, s);
- const r = await _u(t.localStore, e,
- !0), o = new Kc(e, r.ir), u = o.sc(r.documents), c = Ii.createSynthesizedTargetChangeForCurrentChange(n, s && "Offline" !== t.onlineState, i), a = o.applyChanges(u,
- t.isPrimaryClient, c);
- ua(t, n, a.cc);
- const h = new Gc(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 Hc(t, e) {
- const n = U(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 => !ns(t, e)))), void n.wc.delete(e);
-
- if (n.isPrimaryClient) {
-
-
- n.sharedClientState.removeLocalQueryTarget(s.targetId);
- n.sharedClientState.isActiveQueryTarget(s.targetId) || await wu(n.localStore, s.targetId,
- !1).then((() => {
- n.sharedClientState.clearQueryState(s.targetId), Zu(n.remoteStore, s.targetId),
- ra(n, s.targetId);
- })).catch(Pt);
- } else ra(n, s.targetId), await wu(n.localStore, s.targetId,
- !0);
- }
- async function Jc(t, e, n) {
- const s = Aa(t);
- try {
- const t = await function(t, e) {
- const n = U(t), s = ot.now(), i = e.reduce(((t, e) => t.add(e.key)), Is());
- let r, o;
- return n.persistence.runTransaction("Locally write mutations", "readwrite", (t => {
-
-
-
-
-
-
- let u = ls(), c = Is();
- 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 = zs(t, r.get(t.key).overlayedDocument);
- null != e &&
-
-
-
- o.push(new Js(t.key, e, ln(e.value.mapValue), qs.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: ws(r)
- })));
- }(s.localStore, e);
- s.sharedClientState.addPendingMutation(t.batchId), function(t, e, n) {
- let s = t.Tc[t.currentUser.toKey()];
- s || (s = new Te(st));
- s = s.insert(e, n), t.Tc[t.currentUser.toKey()] = s;
- }
-
- (s, t.batchId, n), await ha(s, t.changes), await lc(s.remoteStore);
- } catch (t) {
-
-
- const e = Rc(t, "Failed to persist write");
- n.reject(e);
- }
- }
- async function Yc(t, e) {
- const n = U(t);
- try {
- const t = await hu(n.localStore, e);
-
- e.targetChanges.forEach(((t, e) => {
- const s = n.yc.get(e);
- s && (
-
-
- L(t.addedDocuments.size + t.modifiedDocuments.size + t.removedDocuments.size <= 1),
- t.addedDocuments.size > 0 ? s.fc = !0 : t.modifiedDocuments.size > 0 ? L(s.fc) : t.removedDocuments.size > 0 && (L(s.fc),
- s.fc = !1));
- })), await ha(n, t, e);
- } catch (t) {
- await Pt(t);
- }
- }
- function Xc(t, e, n) {
- const s = U(t);
-
-
-
-
- if (s.isPrimaryClient && 0 === n || !s.isPrimaryClient && 1 === n) {
- const t = [];
- s.wc.forEach(((n, s) => {
- const i = s.view.$u(e);
- i.snapshot && t.push(i.snapshot);
- })), function(t, e) {
- const n = U(t);
- n.onlineState = e;
- let s = !1;
- n.queries.forEach(((t, n) => {
- for (const t of n.listeners)
-
- t.$u(e) && (s = !0);
- })), s && $c(n);
- }(s.eventManager, e), t.length && s.dc.nu(t), s.onlineState = e, s.isPrimaryClient && s.sharedClientState.setOnlineState(e);
- }
- }
- async function Zc(t, e, n) {
- const s = U(t);
-
- s.sharedClientState.updateQueryState(e, "rejected", n);
- const i = s.yc.get(e), r = i && i.key;
- if (r) {
-
-
-
-
-
-
- let t = new Te(ft.comparator);
-
-
-
- t = t.insert(r, fn.newNoDocument(r, ut.min()));
- const n = Is().add(r), i = new pi(ut.min(),
- new Map,
- new Te(st), t, n);
- await Yc(s, i),
-
-
-
-
-
- s.gc = s.gc.remove(r), s.yc.delete(e), aa(s);
- } else await wu(s.localStore, e,
- !1).then((() => ra(s, e, n))).catch(Pt);
- }
- async function ta(t, e) {
- const n = U(t), s = e.batch.batchId;
- try {
- const t = await cu(n.localStore, e);
-
-
-
-
- ia(n, s, null), sa(n, s), n.sharedClientState.updateMutationState(s, "acknowledged"),
- await ha(n, t);
- } catch (t) {
- await Pt(t);
- }
- }
- async function ea(t, e, n) {
- const s = U(t);
- try {
- const t = await function(t, e) {
- const n = U(t);
- return n.persistence.runTransaction("Reject batch", "readwrite-primary", (t => {
- let s;
- return n.mutationQueue.lookupMutationBatch(t, e).next((e => (L(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);
-
-
-
-
- ia(s, e, n), sa(s, e), s.sharedClientState.updateMutationState(e, "rejected", n),
- await ha(s, t);
- } catch (n) {
- await Pt(n);
- }
- }
- async function na(t, e) {
- const n = U(t);
- ic(n.remoteStore) || $("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 = U(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 = Rc(t, "Initialization of waitForPendingWrites() operation failed");
- e.reject(n);
- }
- }
- function sa(t, e) {
- (t.Ec.get(e) || []).forEach((t => {
- t.resolve();
- })), t.Ec.delete(e);
- }
- function ia(t, e, n) {
- const s = U(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 ra(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) ||
-
- oa(t, e);
- }));
- }
- }
- function oa(t, e) {
- t.mc.delete(e.path.canonicalString());
-
-
- const n = t.gc.get(e);
- null !== n && (Zu(t.remoteStore, n), t.gc = t.gc.remove(e), t.yc.delete(n), aa(t));
- }
- function ua(t, e, n) {
- for (const s of n) if (s instanceof qc) t.Ic.addReference(s.key, e), ca(t, s); else if (s instanceof Uc) {
- $("SyncEngine", "Document no longer in limbo: " + s.key), t.Ic.removeReference(s.key, e);
- t.Ic.containsKey(s.key) ||
-
- oa(t, s.key);
- } else B();
- }
- function ca(t, e) {
- const n = e.key, s = n.path.canonicalString();
- t.gc.get(n) || t.mc.has(s) || ($("SyncEngine", "New document in limbo: " + n), t.mc.add(s),
- aa(t));
- }
- function aa(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 ft(at.fromString(e)), s = t.Ac.next();
- t.yc.set(s, new Qc(n)), t.gc = t.gc.insert(n, s), Xu(t.remoteStore, new lr(Zn(zn(n.path)), s, "TargetPurposeLimboResolution" , Bt.ct));
- }
- }
- async function ha(t, e, n) {
- const s = U(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 = su.Li(u.targetId, t);
- r.push(e);
- }
- })));
- })), await Promise.all(o), s.dc.nu(i), await async function(t, e) {
- const n = U(t);
- try {
- await n.persistence.runTransaction("notifyLocalViewChanges", "readwrite", (t => bt.forEach(e, (e => bt.forEach(e.Fi, (s => n.persistence.referenceDelegate.addReference(t, e.targetId, s))).next((() => bt.forEach(e.Bi, (s => n.persistence.referenceDelegate.removeReference(t, e.targetId, s)))))))));
- } catch (t) {
- if (!xt(t)) throw t;
-
-
-
-
- $("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 la(t, e) {
- const n = U(t);
- if (!n.currentUser.isEqual(e)) {
- $("SyncEngine", "User change. New user:", e.toKey());
- const t = await uu(n.localStore, e);
- n.currentUser = e,
-
- function(t, e) {
- t.Ec.forEach((t => {
- t.forEach((t => {
- t.reject(new G(K.CANCELLED, e));
- }));
- })), t.Ec.clear();
- }(n, "'waitForPendingWrites' promise is rejected due to a user change."),
-
- n.sharedClientState.handleUserChange(e, t.removedBatchIds, t.addedBatchIds), await ha(n, t.er);
- }
- }
- function fa(t, e) {
- const n = U(t), s = n.yc.get(e);
- if (s && s.fc) return Is().add(s.key);
- {
- let t = Is();
- 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 da(t, e) {
- const n = U(t), s = await _u(n.localStore, e.query,
- !0), i = e.view.hc(s);
- return n.isPrimaryClient && ua(n, e.targetId, i.cc), i;
- }
- async function wa(t, e) {
- const n = U(t);
- return gu(n.localStore, e).then((t => ha(n, t)));
- }
- async function _a(t, e, n, s) {
- const i = U(t), r = await function(t, e) {
- const n = U(t), s = U(n.mutationQueue);
- return n.persistence.runTransaction("Lookup mutation documents", "readonly", (t => s.Sn(t, e).next((e => e ? n.localDocuments.getDocuments(t, e) : bt.resolve(null)))));
- }
-
- (i.localStore, e);
- null !== r ? ("pending" === n ?
-
-
-
- await lc(i.remoteStore) : "acknowledged" === n || "rejected" === n ? (
-
-
- ia(i, e, s || null), sa(i, e), function(t, e) {
- U(U(t).mutationQueue).Cn(e);
- }
-
- (i.localStore, e)) : B(), await ha(i, r)) :
-
-
-
-
-
-
-
- $("SyncEngine", "Cannot apply mutation batch with id: " + e);
- }
- async function ma(t, e) {
- const n = U(t);
- if (Ea(n), Aa(n), !0 === e && !0 !== n.vc) {
-
-
-
-
-
-
- const t = n.sharedClientState.getAllActiveQueryTargets(), e = await ga(n, t.toArray());
- n.vc = !0, await Tc(n.remoteStore, !0);
- for (const t of e) Xu(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((() => (ra(n, i),
- wu(n.localStore, i,
- !0)))), Zu(n.remoteStore, i);
- })), await e, await ga(n, t),
-
- function(t) {
- const e = U(t);
- e.yc.forEach(((t, n) => {
- Zu(e.remoteStore, n);
- })), e.Ic.Ts(), e.yc = new Map, e.gc = new Te(ft.comparator);
- }
-
-
- (n), n.vc = !1, await Tc(n.remoteStore, !1);
- }
- }
- async function ga(t, e, n) {
- const s = U(t), i = [], r = [];
- for (const t of e) {
- let e;
- const n = s._c.get(t);
- if (n && 0 !== n.length) {
-
-
-
-
- e = await du(s.localStore, Zn(n[0]));
- for (const t of n) {
- const e = s.wc.get(t), n = await da(s, e);
- n.snapshot && r.push(n.snapshot);
- }
- } else {
-
-
- const n = await mu(s.localStore, t);
- e = await du(s.localStore, n), await Wc(s, ya(n), t,
- !1, e.resumeToken);
- }
- i.push(e);
- }
- return s.dc.nu(r), i;
- }
- function ya(t) {
- return jn(t.path, t.collectionGroup, t.orderBy, t.filters, t.limit, "F" , t.startAt, t.endAt);
- }
- function pa(t) {
- const e = U(t);
- return U(U(e.localStore).persistence).Mi();
- }
- async function Ia(t, e, n, s) {
- const i = U(t);
- if (i.vc)
-
-
- return void $("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 gu(i.localStore, os(r[0])), s = pi.createSynthesizedRemoteEventForCurrentChange(e, "current" === n, Ce.EMPTY_BYTE_STRING);
- await ha(i, t, s);
- break;
- }
- case "rejected":
- await wu(i.localStore, e,
- !0), ra(i, e, s);
- break;
- default:
- B();
- }
- }
- async function Ta(t, e, n) {
- const s = Ea(t);
- if (s.vc) {
- for (const t of e) {
- if (s._c.has(t)) {
-
- $("SyncEngine", "Adding an already active target " + t);
- continue;
- }
- const e = await mu(s.localStore, t), n = await du(s.localStore, e);
- await Wc(s, ya(e), n.targetId,
- !1, n.resumeToken), Xu(s.remoteStore, n);
- }
- for (const t of n)
-
-
- s._c.has(t) &&
-
- await wu(s.localStore, t,
- !1).then((() => {
- Zu(s.remoteStore, t), ra(s, t);
- })).catch(Pt);
- }
- }
- function Ea(t) {
- const e = U(t);
- return e.remoteStore.remoteSyncer.applyRemoteEvent = Yc.bind(null, e), e.remoteStore.remoteSyncer.getRemoteKeysForTarget = fa.bind(null, e),
- e.remoteStore.remoteSyncer.rejectListen = Zc.bind(null, e), e.dc.nu = Nc.bind(null, e.eventManager),
- e.dc.Pc = kc.bind(null, e.eventManager), e;
- }
- function Aa(t) {
- const e = U(t);
- return e.remoteStore.remoteSyncer.applySuccessfulWrite = ta.bind(null, e), e.remoteStore.remoteSyncer.rejectFailedWrite = ea.bind(null, e),
- e;
- }
- function va(t, e, n) {
- const s = U(t);
-
- (
-
- async function(t, e, n) {
- try {
- const s = await e.getMetadata();
- if (await function(t, e) {
- const n = U(t), s = Mi(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(Lc(s));
- const i = new Bc(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 ha(t, o.Ju,
- void 0),
-
- await function(t, e) {
- const n = U(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 O("SyncEngine", `Loading bundle failed with ${t}`), n._failWith(t), Promise.resolve(new Set);
- }
- }
-
-
- )(s, e, n).then((t => {
- s.sharedClientState.notifyBundleLoaded(t);
- }));
- }
- class Ra {
- constructor() {
- this.synchronizeTabs = !1;
- }
- async initialize(t) {
- this.serializer = qu(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 ou(this.persistence, new iu, t.initialUser, this.serializer);
- }
- createPersistence(t) {
- return new jo(Wo.zs, this.serializer);
- }
- createSharedClientState(t) {
- return new Du;
- }
- async terminate() {
- this.gcScheduler && this.gcScheduler.stop(), await this.sharedClientState.shutdown(),
- await this.persistence.shutdown();
- }
- }
- class Pa extends Ra {
- constructor(t) {
- super(), this.cacheSizeBytes = t;
- }
- createGarbageCollectionScheduler(t, e) {
- L(this.persistence.referenceDelegate instanceof Ho);
- const n = this.persistence.referenceDelegate.garbageCollector;
- return new Eo(n, t.asyncQueue, e);
- }
- createPersistence(t) {
- const e = void 0 !== this.cacheSizeBytes ? oo.withCacheSize(this.cacheSizeBytes) : oo.DEFAULT;
- return new jo((t => Ho.zs(t, e)), this.serializer);
- }
- }
- class ba extends Ra {
- 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 Aa(this.Vc.syncEngine), await lc(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 ou(this.persistence, new iu, t.initialUser, this.serializer);
- }
- createGarbageCollectionScheduler(t, e) {
- const n = this.persistence.referenceDelegate.garbageCollector;
- return new Eo(n, t.asyncQueue, e);
- }
- createIndexBackfillerScheduler(t, e) {
- const n = new Ft(e, this.persistence);
- return new Ot(t.asyncQueue, n);
- }
- createPersistence(t) {
- const e = nu(t.databaseInfo.databaseId, t.databaseInfo.persistenceKey), n = void 0 !== this.cacheSizeBytes ? oo.withCacheSize(this.cacheSizeBytes) : oo.DEFAULT;
- return new Zo(this.synchronizeTabs, e, t.clientId, n, t.asyncQueue, Bu(), Lu(), this.serializer, this.sharedClientState, !!this.forceOwnership);
- }
- createSharedClientState(t) {
- return new Du;
- }
- }
- class Va extends ba {
- 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 Su && (this.sharedClientState.syncEngine = {
- jr: _a.bind(null, e),
- zr: Ia.bind(null, e),
- Wr: Ta.bind(null, e),
- Mi: pa.bind(null, e),
- Qr: wa.bind(null, e)
- }, await this.sharedClientState.start()),
-
-
- await this.persistence.Ii((async t => {
- await ma(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 = Bu();
- if (!Su.D(e)) throw new G(K.UNIMPLEMENTED, "IndexedDB persistence is only available on platforms that support LocalStorage.");
- const n = nu(t.databaseInfo.databaseId, t.databaseInfo.persistenceKey);
- return new Su(e, t.asyncQueue, n, t.clientId, t.initialUser);
- }
- }
- class Sa {
- 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 => Xc(this.syncEngine, t, 1 ),
- this.remoteStore.remoteSyncer.handleCredentialChange = la.bind(null, this.syncEngine),
- await Tc(this.remoteStore, this.syncEngine.isPrimaryClient));
- }
- createEventManager(t) {
- return new Dc;
- }
- createDatastore(t) {
- const e = qu(t.databaseInfo.databaseId), n = (s = t.databaseInfo, new Fu(s));
- var s;
- return function(t, e, n, s) {
- return new ju(t, e, n, s);
- }(t.authCredentials, t.appCheckCredentials, n, e);
- }
- createRemoteStore(t) {
- return e = this.localStore, n = this.datastore, s = t.asyncQueue, i = t => Xc(this.syncEngine, t, 0 ),
- r = xu.D() ? new xu : new Cu, new Hu(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 jc(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 = U(t);
- $("RemoteStore", "RemoteStore shutting down."), e.vu.add(5 ),
- await Yu(e), e.Pu.shutdown(),
-
-
- e.bu.set("Unknown" );
- }(this.remoteStore);
- }
- }
- function Da(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 Ca {
- 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) : M("Uncaught Error in snapshot listener:", t.toString());
- }
- Dc() {
- this.muted = !0;
- }
- Sc(t, e) {
- this.muted || setTimeout((() => {
- this.muted || t(e);
- }), 0);
- }
- }
- class xa {
- constructor(
- /** The reader to read from underlying binary bundle data source. */
- t, e) {
- this.Cc = t, this.serializer = e,
-
- this.metadata = new Q,
-
- 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.$c(`length string (${e}) is not valid number`);
- const s = await this.Mc(n);
- return new Oc(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.$c("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 Mc(t) {
- for (;this.buffer.length < t; ) {
- await this.Fc() && this.$c("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;
- }
- $c(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 Na {
- 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 G(K.INVALID_ARGUMENT, "Firestore transactions require all reads to be executed before all writes.");
- const e = await async function(t, e) {
- const n = U(t), s = Ki(n.serializer) + "/documents", i = {
- documents: e.map((t => Bi(n.serializer, t)))
- }, r = await n.vo("BatchGetDocuments", s, i, e.length), o = new Map;
- r.forEach((t => {
- const e = zi(n.serializer, t);
- o.set(e.key.toString(), e);
- }));
- const u = [];
- return e.forEach((t => {
- const e = o.get(t.toString());
- L(!!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 ti(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 = ft.fromPath(e);
- this.mutations.push(new ei(n, this.precondition(n)));
- })), await async function(t, e) {
- const n = U(t), s = Ki(n.serializer) + "/documents", i = {
- writes: e.map((t => Hi(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 B();
-
- e = ut.min();
- }
- const n = this.readVersions.get(t.key.toString());
- if (n) {
- if (!e.isEqual(n))
-
- throw new G(K.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(ut.min()) ? qs.exists(!1) : qs.updateTime(e) : qs.none();
- }
-
- preconditionForUpdate(t) {
- const e = this.readVersions.get(t.toString());
-
-
- if (!this.writtenDocs.has(t.toString()) && e) {
- if (e.isEqual(ut.min()))
-
-
-
-
-
-
-
-
-
- throw new G(K.INVALID_ARGUMENT, "Can't update a document that doesn't exist.");
-
- return qs.updateTime(e);
- }
-
-
- return qs.exists(!0);
- }
- write(t) {
- this.ensureCommitNotCalled(), this.mutations.push(t);
- }
- ensureCommitNotCalled() {}
- }
- class ka {
- 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 Uu(this.asyncQueue, "transaction_retry" );
- }
- run() {
- this.Bc -= 1, this.Lc();
- }
- Lc() {
- this.qo.No((async () => {
- const t = new Na(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 !Lt(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 || !ai(e);
- }
- return !1;
- }
- }
- class $a {
- 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 = D.UNAUTHENTICATED, this.clientId = nt.A(), this.authCredentialListener = () => Promise.resolve(),
- this.appCheckCredentialListener = () => Promise.resolve(), this.authCredentials.start(n, (async t => {
- $("FirestoreClient", "Received user=", t.uid), await this.authCredentialListener(t),
- this.user = t;
- })), this.appCheckCredentials.start(n, (t => ($("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 G(K.FAILED_PRECONDITION, "The client has already been terminated.");
- }
- terminate() {
- this.asyncQueue.enterRestrictedMode();
- const t = new Q;
- 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 = Rc(e, "Failed to shutdown persistence");
- t.reject(n);
- }
- })), t.promise;
- }
- }
- async function Ma(t, e) {
- t.asyncQueue.verifyOperationInProgress(), $("FirestoreClient", "Initializing OfflineComponentProvider");
- const n = await t.getConfiguration();
- await e.initialize(n);
- let s = n.initialUser;
- t.setCredentialChangeListener((async t => {
- s.isEqual(t) || (await uu(e.localStore, t), s = t);
- })),
-
-
- e.persistence.setDatabaseDeletedListener((() => t.terminate())), t._offlineComponents = e;
- }
- async function Oa(t, e) {
- t.asyncQueue.verifyOperationInProgress();
- const n = await Ba(t);
- $("FirestoreClient", "Initializing OnlineComponentProvider");
- const s = await t.getConfiguration();
- await e.initialize(n, s),
-
-
- t.setCredentialChangeListener((t => Ic(e.remoteStore, t))), t.setAppCheckTokenChangeListener(((t, n) => Ic(e.remoteStore, n))),
- t._onlineComponents = e;
- }
- function Fa(t) {
- return "FirebaseError" === t.name ? t.code === K.FAILED_PRECONDITION || t.code === K.UNIMPLEMENTED : !("undefined" != typeof DOMException && t instanceof DOMException) || (
-
-
-
- 22 === t.code || 20 === t.code ||
-
-
- 11 === t.code);
- }
- async function Ba(t) {
- if (!t._offlineComponents) if (t._uninitializedComponentsProvider) {
- $("FirestoreClient", "Using user provided OfflineComponentProvider");
- try {
- await Ma(t, t._uninitializedComponentsProvider._offline);
- } catch (e) {
- const n = e;
- if (!Fa(n)) throw n;
- O("Error using user provided cache. Falling back to memory cache: " + n), await Ma(t, new Ra);
- }
- } else $("FirestoreClient", "Using default OfflineComponentProvider"), await Ma(t, new Ra);
- return t._offlineComponents;
- }
- async function La(t) {
- return t._onlineComponents || (t._uninitializedComponentsProvider ? ($("FirestoreClient", "Using user provided OnlineComponentProvider"),
- await Oa(t, t._uninitializedComponentsProvider._online)) : ($("FirestoreClient", "Using default OnlineComponentProvider"),
- await Oa(t, new Sa))), t._onlineComponents;
- }
- function qa(t) {
- return Ba(t).then((t => t.persistence));
- }
- function Ua(t) {
- return Ba(t).then((t => t.localStore));
- }
- function Ka(t) {
- return La(t).then((t => t.remoteStore));
- }
- function Ga(t) {
- return La(t).then((t => t.syncEngine));
- }
- function Qa(t) {
- return La(t).then((t => t.datastore));
- }
- async function ja(t) {
- const e = await La(t), n = e.eventManager;
- return n.onListen = zc.bind(null, e.syncEngine), n.onUnlisten = Hc.bind(null, e.syncEngine),
- n;
- }
- function za(t) {
- return t.asyncQueue.enqueue((async () => {
- const e = await qa(t), n = await Ka(t);
- return e.setNetworkEnabled(!0), function(t) {
- const e = U(t);
- return e.vu.delete(0 ), Ju(e);
- }(n);
- }));
- }
- function Wa(t) {
- return t.asyncQueue.enqueue((async () => {
- const e = await qa(t), n = await Ka(t);
- return e.setNetworkEnabled(!1), async function(t) {
- const e = U(t);
- e.vu.add(0 ), await Yu(e),
-
- e.bu.set("Offline" );
- }(n);
- }));
- }
- function Ha(t, e) {
- const n = new Q;
- return t.asyncQueue.enqueueAndForget((async () => async function(t, e, n) {
- try {
- const s = await function(t, e) {
- const n = U(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 G(K.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 = Rc(t, `Failed to get document '${e} from cache`);
- n.reject(s);
- }
- }
-
- (await Ua(t), e, n))), n.promise;
- }
- function Ja(t, e, n = {}) {
- const s = new Q;
- return t.asyncQueue.enqueueAndForget((async () => function(t, e, n, s, i) {
- const r = new Ca({
- next: r => {
-
-
- e.enqueueAndForget((() => xc(t, o)));
- const u = r.docs.has(n);
- !u && r.fromCache ?
-
-
-
-
-
-
-
- i.reject(new G(K.UNAVAILABLE, "Failed to get document because the client is offline.")) : u && r.fromCache && s && "server" === s.source ? i.reject(new G(K.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 Mc(zn(n.path), r, {
- includeMetadataChanges: !0,
- Ku: !0
- });
- return Cc(t, o);
- }(await ja(t), t.asyncQueue, e, n, s))), s.promise;
- }
- function Ya(t, e) {
- const n = new Q;
- return t.asyncQueue.enqueueAndForget((async () => async function(t, e, n) {
- try {
- const s = await _u(t, e,
- !0), i = new Kc(e, s.ir), r = i.sc(s.documents), o = i.applyChanges(r,
- !1);
- n.resolve(o.snapshot);
- } catch (t) {
- const s = Rc(t, `Failed to execute query '${e} against cache`);
- n.reject(s);
- }
- }
-
- (await Ua(t), e, n))), n.promise;
- }
- function Xa(t, e, n = {}) {
- const s = new Q;
- return t.asyncQueue.enqueueAndForget((async () => function(t, e, n, s, i) {
- const r = new Ca({
- next: n => {
-
-
- e.enqueueAndForget((() => xc(t, o))), n.fromCache && "server" === s.source ? i.reject(new G(K.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 Mc(n, r, {
- includeMetadataChanges: !0,
- Ku: !0
- });
- return Cc(t, o);
- }(await ja(t), t.asyncQueue, e, n, s))), s.promise;
- }
- function Za(t, e) {
- const n = new Ca(e);
- return t.asyncQueue.enqueueAndForget((async () => function(t, e) {
- U(t).ku.add(e),
-
-
- e.next();
- }(await ja(t), n))), () => {
- n.Dc(), t.asyncQueue.enqueueAndForget((async () => function(t, e) {
- U(t).ku.delete(e);
- }(await ja(t), n)));
- };
- }
- function th(t, e, n, s) {
- const i = function(t, e) {
- let n;
- n = "string" == typeof t ? di().encode(t) : t;
- return function(t, e) {
- return new xa(t, e);
- }(function(t, e) {
- if (t instanceof Uint8Array) return Da(t, e);
- if (t instanceof ArrayBuffer) return Da(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, qu(e));
- t.asyncQueue.enqueueAndForget((async () => {
- va(await Ga(t), i, s);
- }));
- }
- function eh(t, e) {
- return t.asyncQueue.enqueue((async () => function(t, e) {
- const n = U(t);
- return n.persistence.runTransaction("Get named query", "readonly", (t => n.qs.getNamedQuery(t, e)));
- }(await Ua(t), e)));
- }
- function nh(t, e) {
- return t.asyncQueue.enqueue((async () => async function(t, e) {
- const n = U(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, mt, (e => {
- i.push(s.addFieldIndex(t, e));
- }), (e => {
- i.push(s.deleteFieldIndex(t, e));
- })))).next((() => bt.waitFor(i)))));
- }
-
-
-
- (await Ua(t), e)));
- }
- function sh(t) {
- const e = {};
- return void 0 !== t.timeoutSeconds && (e.timeoutSeconds = t.timeoutSeconds), e;
- }
- const ih = new Map;
- function rh(t, e, n) {
- if (!n) throw new G(K.INVALID_ARGUMENT, `Function ${t}() cannot be called with an empty ${e}.`);
- }
- function oh(t, e, n, s) {
- if (!0 === e && !0 === s) throw new G(K.INVALID_ARGUMENT, `${t} and ${n} cannot be used together.`);
- }
- function uh(t) {
- if (!ft.isDocumentKey(t)) throw new G(K.INVALID_ARGUMENT, `Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`);
- }
- function ch(t) {
- if (ft.isDocumentKey(t)) throw new G(K.INVALID_ARGUMENT, `Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`);
- }
- function ah(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" : B();
- }
- function hh(t,
- e) {
- if ("_delegate" in t && (
-
-
- t = t._delegate), !(t instanceof e)) {
- if (e.name === t.constructor.name) throw new G(K.INVALID_ARGUMENT, "Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");
- {
- const n = ah(t);
- throw new G(K.INVALID_ARGUMENT, `Expected type '${e.name}', but it was: ${n}`);
- }
- }
- return t;
- }
- function lh(t, e) {
- if (e <= 0) throw new G(K.INVALID_ARGUMENT, `Function ${t}() requires a positive number, but it was: ${e}.`);
- }
- class fh {
- constructor(t) {
- var e, n;
- if (void 0 === t.host) {
- if (void 0 !== t.ssl) throw new G(K.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 G(K.INVALID_ARGUMENT, "cacheSizeBytes must be at least 1048576");
- this.cacheSizeBytes = t.cacheSizeBytes;
- }
- oh("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 = sh(null !== (n = t.experimentalLongPollingOptions) && void 0 !== n ? n : {}),
- function(t) {
- if (void 0 !== t.timeoutSeconds) {
- if (isNaN(t.timeoutSeconds)) throw new G(K.INVALID_ARGUMENT, `invalid long polling timeout: ${t.timeoutSeconds} (must not be NaN)`);
- if (t.timeoutSeconds < 5) throw new G(K.INVALID_ARGUMENT, `invalid long polling timeout: ${t.timeoutSeconds} (minimum allowed value is 5)`);
- if (t.timeoutSeconds > 30) throw new G(K.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 dh {
-
- 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 fh({}),
- this._settingsFrozen = !1;
- }
-
- get app() {
- if (!this._app) throw new G(K.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 G(K.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 fh(t), void 0 !== t.credentials && (this._authCredentials = function(t) {
- if (!t) return new z;
- switch (t.type) {
- case "firstParty":
- return new Y(t.sessionIndex || "0", t.iamToken || null, t.authTokenFactory || null);
- case "provider":
- return t.client;
- default:
- throw new G(K.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 = ih.get(t);
- e && ($("ComponentProvider", "Removing Datastore"), ih.delete(t), e.terminate());
- }(this), Promise.resolve();
- }
- }
- function wh(t, e, n, s = {}) {
- var i;
- const r = (t = hh(t, dh))._getSettings(), o = `${e}:${n}`;
- if ("firestore.googleapis.com" !== r.host && r.host !== o && O("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 = D.MOCK_USER; else {
-
-
- e = w(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 G(K.INVALID_ARGUMENT, "mockUserToken must contain 'sub' or 'user_id' field!");
- n = new D(r);
- }
- t._authCredentials = new W(new j(e, n));
- }
- }
- class _h {
-
- 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 gh(this.firestore, this.converter, this._key.path.popLast());
- }
- withConverter(t) {
- return new _h(this.firestore, t, this._key);
- }
- }
- class mh {
-
-
- 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 mh(this.firestore, t, this._query);
- }
- }
- class gh extends mh {
-
- constructor(t, e, n) {
- super(t, e, zn(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 _h(this.firestore,
- null, new ft(t));
- }
- withConverter(t) {
- return new gh(this.firestore, t, this._path);
- }
- }
- function yh(t, e, ...n) {
- if (t = _(t), rh("collection", "path", e), t instanceof dh) {
- const s = at.fromString(e, ...n);
- return ch(s), new gh(t, null, s);
- }
- {
- if (!(t instanceof _h || t instanceof gh)) throw new G(K.INVALID_ARGUMENT, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
- const s = t._path.child(at.fromString(e, ...n));
- return ch(s), new gh(t.firestore,
- null, s);
- }
- }
- function ph(t, e) {
- if (t = hh(t, dh), rh("collectionGroup", "collection id", e), e.indexOf("/") >= 0) throw new G(K.INVALID_ARGUMENT, `Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);
- return new mh(t,
- null, function(t) {
- return new Qn(at.emptyPath(), t);
- }(e));
- }
- function Ih(t, e, ...n) {
- if (t = _(t),
-
-
- 1 === arguments.length && (e = nt.A()), rh("doc", "path", e), t instanceof dh) {
- const s = at.fromString(e, ...n);
- return uh(s), new _h(t,
- null, new ft(s));
- }
- {
- if (!(t instanceof _h || t instanceof gh)) throw new G(K.INVALID_ARGUMENT, "Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");
- const s = t._path.child(at.fromString(e, ...n));
- return uh(s), new _h(t.firestore, t instanceof gh ? t.converter : null, new ft(s));
- }
- }
- function Th(t, e) {
- return t = _(t), e = _(e), (t instanceof _h || t instanceof gh) && (e instanceof _h || e instanceof gh) && (t.firestore === e.firestore && t.path === e.path && t.converter === e.converter);
- }
- function Eh(t, e) {
- return t = _(t), e = _(e), t instanceof mh && e instanceof mh && (t.firestore === e.firestore && ns(t._query, e._query) && t.converter === e.converter);
- }
- class Ah {
- 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 Uu(this, "async_queue_retry" ),
-
-
-
- this.Xc = () => {
- const t = Lu();
- t && $("AsyncQueue", "Visibility state changed to " + t.visibilityState), this.qo.$o();
- };
- const t = Lu();
- 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 = Lu();
- e && "function" == typeof e.removeEventListener && e.removeEventListener("visibilitychange", this.Xc);
- }
- }
- enqueue(t) {
- if (this.Zc(), this.jc)
-
- return new Promise((() => {}));
-
-
-
- const e = new Q;
- 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 (!xt(t)) throw t;
-
- $("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 M("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 = vc.createAndSchedule(this, t, e, n, (t => this.na(t)));
- return this.zc.push(s), s;
- }
- Zc() {
- this.Wc && B();
- }
- 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 vh(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 Rh {
- constructor() {
- this._progressObserver = {}, this._taskCompletionResolver = new Q, 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 Ph = -1;
- class bh extends dh {
-
- constructor(t, e, n, s) {
- super(t, e, n, s),
-
- this.type = "firestore", this._queue = new Ah, this._persistenceKey = (null == s ? void 0 : s.name) || "[DEFAULT]";
- }
- _terminate() {
- return this._firestoreClient ||
-
-
- Ch(this), this._firestoreClient.terminate();
- }
- }
- function Vh(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 (m(i, e)) return t;
- throw new G(K.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 G(K.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 G(K.INVALID_ARGUMENT, "cacheSizeBytes must be at least 1048576");
- return s.initialize({
- options: e,
- instanceIdentifier: n
- });
- }
- function Sh(e, n) {
- const s = "object" == typeof e ? e : t(), i = "string" == typeof e ? e : n || "(default)", r = _getProvider(s, "firestore").getImmediate({
- identifier: i
- });
- if (!r._initialized) {
- const t = g("firestore");
- t && wh(r, ...t);
- }
- return r;
- }
- function Dh(t) {
- return t._firestoreClient || Ch(t), t._firestoreClient.verifyNotTerminated(), t._firestoreClient;
- }
- function Ch(t) {
- var e, n, s;
- const i = t._freezeSettings(), r = function(t, e, n, s) {
- return new Be(t, e, n, s.host, s.ssl, s.experimentalForceLongPolling, s.experimentalAutoDetectLongPolling, sh(s.experimentalLongPollingOptions), s.useFetchStreams);
- }(t._databaseId, (null === (e = t._app) || void 0 === e ? void 0 : e.options.appId) || "", t._persistenceKey, i);
- t._firestoreClient = new $a(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 xh(t, e) {
- Uh(t = hh(t, bh));
- const n = Dh(t);
- if (n._uninitializedComponentsProvider) throw new G(K.FAILED_PRECONDITION, "SDK cache is already specified.");
- O("enableIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");
- const s = t._freezeSettings(), i = new Sa;
- return kh(n, i, new ba(i, s.cacheSizeBytes, null == e ? void 0 : e.forceOwnership));
- }
- function Nh(t) {
- Uh(t = hh(t, bh));
- const e = Dh(t);
- if (e._uninitializedComponentsProvider) throw new G(K.FAILED_PRECONDITION, "SDK cache is already specified.");
- O("enableMultiTabIndexedDbPersistence() will be deprecated in the future, you can use `FirestoreSettings.cache` instead.");
- const n = t._freezeSettings(), s = new Sa;
- return kh(e, s, new Va(s, n.cacheSizeBytes));
- }
- function kh(t, e, n) {
- const s = new Q;
- return t.asyncQueue.enqueue((async () => {
- try {
- await Ma(t, n), await Oa(t, e), s.resolve();
- } catch (t) {
- const e = t;
- if (!Fa(e)) throw e;
- O("Error enabling indexeddb cache. Falling back to memory cache: " + e), s.reject(e);
- }
- })).then((() => s.promise));
- }
- function $h(t) {
- if (t._initialized && !t._terminated) throw new G(K.FAILED_PRECONDITION, "Persistence can only be cleared before a Firestore instance is initialized or after it is terminated.");
- const e = new Q;
- return t._queue.enqueueAndForgetEvenWhileRestricted((async () => {
- try {
- await async function(t) {
- if (!St.D()) return Promise.resolve();
- const e = t + "main";
- await St.delete(e);
- }(nu(t._databaseId, t._persistenceKey)), e.resolve();
- } catch (t) {
- e.reject(t);
- }
- })), e.promise;
- }
- function Mh(t) {
- return function(t) {
- const e = new Q;
- return t.asyncQueue.enqueueAndForget((async () => na(await Ga(t), e))), e.promise;
- }(Dh(t = hh(t, bh)));
- }
- function Oh(t) {
- return za(Dh(t = hh(t, bh)));
- }
- function Fh(t) {
- return Wa(Dh(t = hh(t, bh)));
- }
- function Bh(t) {
- return e(t.app, "firestore", t._databaseId.database), t._delete();
- }
- function Lh(t, e) {
- const n = Dh(t = hh(t, bh)), s = new Rh;
- return th(n, t._databaseId, e, s), s;
- }
- function qh(t, e) {
- return eh(Dh(t = hh(t, bh)), e).then((e => e ? new mh(t, null, e.query) : null));
- }
- function Uh(t) {
- if (t._initialized || t._terminated) throw new G(K.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 Kh {
-
- 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 Gh {
-
- constructor(t, e, n) {
- this._userDataWriter = e, this._data = n,
-
- this.type = "AggregateQuerySnapshot", this.query = t;
- }
-
- data() {
- return this._userDataWriter.convertObjectMap(this._data);
- }
- }
- class Qh {
-
- constructor(t) {
- this._byteString = t;
- }
-
- static fromBase64String(t) {
- try {
- return new Qh(Ce.fromBase64String(t));
- } catch (t) {
- throw new G(K.INVALID_ARGUMENT, "Failed to construct data from Base64 string: " + t);
- }
- }
-
- static fromUint8Array(t) {
- return new Qh(Ce.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 jh {
-
- constructor(...t) {
- for (let e = 0; e < t.length; ++e) if (0 === t[e].length) throw new G(K.INVALID_ARGUMENT, "Invalid field name at argument $(i + 1). Field names must not be empty.");
- this._internalPath = new lt(t);
- }
-
- isEqual(t) {
- return this._internalPath.isEqual(t._internalPath);
- }
- }
- function zh() {
- return new jh("__name__");
- }
- class Wh {
-
- constructor(t) {
- this._methodName = t;
- }
- }
- class Hh {
-
- constructor(t, e) {
- if (!isFinite(t) || t < -90 || t > 90) throw new G(K.INVALID_ARGUMENT, "Latitude must be a number between -90 and 90, but was: " + t);
- if (!isFinite(e) || e < -180 || e > 180) throw new G(K.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 st(this._lat, t._lat) || st(this._long, t._long);
- }
- }
- const Jh = /^__.*__$/;
- class Yh {
- constructor(t, e, n) {
- this.data = t, this.fieldMask = e, this.fieldTransforms = n;
- }
- toMutation(t, e) {
- return null !== this.fieldMask ? new Js(t, this.data, this.fieldMask, e, this.fieldTransforms) : new Hs(t, this.data, e, this.fieldTransforms);
- }
- }
- class Xh {
- 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 Js(t, this.data, this.fieldMask, e, this.fieldTransforms);
- }
- }
- function Zh(t) {
- switch (t) {
- case 0 :
-
- case 2 :
-
- case 1 :
- return !0;
- case 3 :
- case 4 :
- return !1;
- default:
- throw B();
- }
- }
- class tl {
-
- 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 tl(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 Il(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 (Zh(this.ca) && Jh.test(t)) throw this._a('Document fields cannot begin and end with "__"');
- }
- }
- class el {
- constructor(t, e, n) {
- this.databaseId = t, this.ignoreUndefinedProperties = e, this.serializer = n || qu(t);
- }
- ya(t, e, n, s = !1) {
- return new tl({
- ca: t,
- methodName: e,
- ga: n,
- path: lt.emptyPath(),
- la: !1,
- ma: s
- }, this.databaseId, this.serializer, this.ignoreUndefinedProperties);
- }
- }
- function nl(t) {
- const e = t._freezeSettings(), n = qu(t._databaseId);
- return new el(t._databaseId, !!e.ignoreUndefinedProperties, n);
- }
- function sl(t, e, n, s, i, r = {}) {
- const o = t.ya(r.merge || r.mergeFields ? 2 : 0 , e, n, i);
- ml("Data must be an object, but it was:", o, s);
- const u = wl(s, o);
- let c, a;
- if (r.merge) c = new be(o.fieldMask), a = o.fieldTransforms; else if (r.mergeFields) {
- const t = [];
- for (const s of r.mergeFields) {
- const i = gl(e, s, n);
- if (!o.contains(i)) throw new G(K.INVALID_ARGUMENT, `Field '${i}' is specified in your field mask but missing from your input data.`);
- Tl(t, i) || t.push(i);
- }
- c = new be(t), a = o.fieldTransforms.filter((t => c.covers(t.field)));
- } else c = null, a = o.fieldTransforms;
- return new Yh(new hn(u), c, a);
- }
- class il extends Wh {
- _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 il;
- }
- }
- function rl(t, e, n) {
- return new tl({
- ca: 3 ,
- ga: e.settings.ga,
- methodName: t._methodName,
- la: n
- }, e.databaseId, e.serializer, e.ignoreUndefinedProperties);
- }
- class ol extends Wh {
- _toFieldTransform(t) {
- return new Fs(t.path, new Ds);
- }
- isEqual(t) {
- return t instanceof ol;
- }
- }
- class ul extends Wh {
- constructor(t, e) {
- super(t), this.pa = e;
- }
- _toFieldTransform(t) {
- const e = rl(this, t,
- !0), n = this.pa.map((t => dl(t, e))), s = new Cs(n);
- return new Fs(t.path, s);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- class cl extends Wh {
- constructor(t, e) {
- super(t), this.pa = e;
- }
- _toFieldTransform(t) {
- const e = rl(this, t,
- !0), n = this.pa.map((t => dl(t, e))), s = new Ns(n);
- return new Fs(t.path, s);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- class al extends Wh {
- constructor(t, e) {
- super(t), this.Ia = e;
- }
- _toFieldTransform(t) {
- const e = new $s(t.serializer, Rs(t.serializer, this.Ia));
- return new Fs(t.path, e);
- }
- isEqual(t) {
-
- return this === t;
- }
- }
- function hl(t, e, n, s) {
- const i = t.ya(1 , e, n);
- ml("Data must be an object, but it was:", i, s);
- const r = [], o = hn.empty();
- pe(s, ((t, s) => {
- const u = pl(e, t, n);
-
-
- s = _(s);
- const c = i.da(u);
- if (s instanceof il)
-
- r.push(u); else {
- const t = dl(s, c);
- null != t && (r.push(u), o.set(u, t));
- }
- }));
- const u = new be(r);
- return new Xh(o, u, i.fieldTransforms);
- }
- function ll(t, e, n, s, i, r) {
- const o = t.ya(1 , e, n), u = [ gl(e, s, n) ], c = [ i ];
- if (r.length % 2 != 0) throw new G(K.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(gl(e, r[t])), c.push(r[t + 1]);
- const a = [], h = hn.empty();
-
-
- for (let t = u.length - 1; t >= 0; --t) if (!Tl(a, u[t])) {
- const e = u[t];
- let n = c[t];
-
-
- n = _(n);
- const s = o.da(e);
- if (n instanceof il)
-
- a.push(e); else {
- const t = dl(n, s);
- null != t && (a.push(e), h.set(e, t));
- }
- }
- const l = new be(a);
- return new Xh(h, l, o.fieldTransforms);
- }
- function fl(t, e, n, s = !1) {
- return dl(n, t.ya(s ? 4 : 3 , e));
- }
- function dl(t, e) {
- if (_l(
-
-
- t = _(t))) return ml("Unsupported field value:", e, t), wl(t, e);
- if (t instanceof Wh)
-
-
-
-
-
-
- return function(t, e) {
-
- if (!Zh(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 = dl(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 = _(t))) return {
- nullValue: "NULL_VALUE"
- };
- if ("number" == typeof t) return Rs(e.serializer, t);
- if ("boolean" == typeof t) return {
- booleanValue: t
- };
- if ("string" == typeof t) return {
- stringValue: t
- };
- if (t instanceof Date) {
- const n = ot.fromDate(t);
- return {
- timestampValue: Ni(e.serializer, n)
- };
- }
- if (t instanceof ot) {
-
-
-
- const n = new ot(t.seconds, 1e3 * Math.floor(t.nanoseconds / 1e3));
- return {
- timestampValue: Ni(e.serializer, n)
- };
- }
- if (t instanceof Hh) return {
- geoPointValue: {
- latitude: t.latitude,
- longitude: t.longitude
- }
- };
- if (t instanceof Qh) return {
- bytesValue: ki(e.serializer, t._byteString)
- };
- if (t instanceof _h) {
- 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: Oi(t.firestore._databaseId || e.databaseId, t._key.path)
- };
- }
- throw e._a(`Unsupported field value: ${ah(t)}`);
- }
-
- (t, e);
- }
- function wl(t, e) {
- const n = {};
- return Ie(t) ?
-
-
- e.path && e.path.length > 0 && e.fieldMask.push(e.path) : pe(t, ((t, s) => {
- const i = dl(s, e.ha(t));
- null != i && (n[t] = i);
- })), {
- mapValue: {
- fields: n
- }
- };
- }
- function _l(t) {
- return !("object" != typeof t || null === t || t instanceof Array || t instanceof Date || t instanceof ot || t instanceof Hh || t instanceof Qh || t instanceof _h || t instanceof Wh);
- }
- function ml(t, e, n) {
- if (!_l(n) || !function(t) {
- return "object" == typeof t && null !== t && (Object.getPrototypeOf(t) === Object.prototype || null === Object.getPrototypeOf(t));
- }(n)) {
- const s = ah(n);
- throw "an object" === s ? e._a(t + " a custom object") : e._a(t + " " + s);
- }
- }
- function gl(t, e, n) {
- if ((
-
-
- e = _(e)) instanceof jh) return e._internalPath;
- if ("string" == typeof e) return pl(t, e);
- throw Il("Field path arguments must be of type string or ", t,
- !1,
- void 0, n);
- }
- const yl = new RegExp("[~\\*/\\[\\]]");
- function pl(t, e, n) {
- if (e.search(yl) >= 0) throw Il(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`, t,
- !1,
- void 0, n);
- try {
- return new jh(...e.split("."))._internalPath;
- } catch (s) {
- throw Il(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`, t,
- !1,
- void 0, n);
- }
- }
- function Il(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 G(K.INVALID_ARGUMENT, u + t + c);
- }
- function Tl(t, e) {
- return t.some((t => t.isEqual(e)));
- }
- class El {
-
-
-
-
-
- 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 _h(this._firestore, this._converter, this._key);
- }
-
- exists() {
- return null !== this._document;
- }
-
- data() {
- if (this._document) {
- if (this._converter) {
-
-
- const t = new Al(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(vl("DocumentSnapshot.get", t));
- if (null !== e) return this._userDataWriter.convertValue(e);
- }
- }
- }
- class Al extends El {
-
- data() {
- return super.data();
- }
- }
- function vl(t, e) {
- return "string" == typeof e ? pl(t, e) : e instanceof jh ? e._internalPath : e._delegate._internalPath;
- }
- function Rl(t) {
- if ("L" === t.limitType && 0 === t.explicitOrderBy.length) throw new G(K.UNIMPLEMENTED, "limitToLast() queries require specifying at least one orderBy() clause");
- }
- class Pl {}
- class bl extends Pl {}
- function Vl(t, e, ...n) {
- let s = [];
- e instanceof Pl && s.push(e), s = s.concat(n), function(t) {
- const e = t.filter((t => t instanceof Cl)).length, n = t.filter((t => t instanceof Sl)).length;
- if (e > 1 || e > 0 && n > 0) throw new G(K.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 Sl extends bl {
-
- constructor(t, e, n) {
- super(), this._field = t, this._op = e, this._value = n,
-
- this.type = "where";
- }
- static _create(t, e, n) {
- return new Sl(t, e, n);
- }
- _apply(t) {
- const e = this._parse(t);
- return Wl(t._query, e), new mh(t.firestore, t.converter, ts(t._query, e));
- }
- _parse(t) {
- const e = nl(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 G(K.INVALID_ARGUMENT, `Invalid Query. You can't perform '${r}' queries on documentId().`);
- if ("in" === r || "not-in" === r) {
- zl(o, r);
- const e = [];
- for (const n of o) e.push(jl(s, t, n));
- u = {
- arrayValue: {
- values: e
- }
- };
- } else u = jl(s, t, o);
- } else "in" !== r && "not-in" !== r && "array-contains-any" !== r || zl(o, r),
- u = fl(n, e, o,
- "in" === r || "not-in" === r);
- return pn.create(i, r, u);
- }(t._query, "where", e, t.firestore._databaseId, this._field, this._op, this._value);
- return n;
- }
- }
- function Dl(t, e, n) {
- const s = e, i = vl("where", t);
- return Sl._create(i, s, n);
- }
- class Cl extends Pl {
-
- constructor(
- /** The type of this query constraint */
- t, e) {
- super(), this.type = t, this._queryConstraints = e;
- }
- static _create(t, e) {
- return new Cl(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] : In.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) Wl(n, t), n = ts(n, t);
- }
-
-
- (t._query, e), new mh(t.firestore, t.converter, ts(t._query, e)));
- }
- _getQueryConstraints() {
- return this._queryConstraints;
- }
- _getOperator() {
- return "and" === this.type ? "and" : "or" ;
- }
- }
- function xl(...t) {
-
- return t.forEach((t => Jl("or", t))), Cl._create("or" , t);
- }
- function Nl(...t) {
-
- return t.forEach((t => Jl("and", t))), Cl._create("and" , t);
- }
- class kl extends bl {
-
- constructor(t, e) {
- super(), this._field = t, this._direction = e,
-
- this.type = "orderBy";
- }
- static _create(t, e) {
- return new kl(t, e);
- }
- _apply(t) {
- const e = function(t, e, n) {
- if (null !== t.startAt) throw new G(K.INVALID_ARGUMENT, "Invalid query. You must not call startAt() or startAfter() before calling orderBy().");
- if (null !== t.endAt) throw new G(K.INVALID_ARGUMENT, "Invalid query. You must not call endAt() or endBefore() before calling orderBy().");
- const s = new mn(e, n);
- return function(t, e) {
- if (null === Hn(t)) {
-
- const n = Jn(t);
- null !== n && Hl(t, n, e.field);
- }
- }(t, s), s;
- }
-
- (t._query, this._field, this._direction);
- return new mh(t.firestore, t.converter, function(t, e) {
-
- const n = t.explicitOrderBy.concat([ e ]);
- return new Qn(t.path, t.collectionGroup, n, t.filters.slice(), t.limit, t.limitType, t.startAt, t.endAt);
- }(t._query, e));
- }
- }
- function $l(t, e = "asc") {
- const n = e, s = vl("orderBy", t);
- return kl._create(s, n);
- }
- class Ml extends bl {
-
- 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 Ml(t, e, n);
- }
- _apply(t) {
- return new mh(t.firestore, t.converter, es(t._query, this._limit, this._limitType));
- }
- }
- function Ol(t) {
- return lh("limit", t), Ml._create("limit", t, "F" );
- }
- function Fl(t) {
- return lh("limitToLast", t), Ml._create("limitToLast", t, "L" );
- }
- class Bl extends bl {
-
- 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 = Ql(t, this.type, this._docOrFields, this._inclusive);
- return new mh(t.firestore, t.converter, function(t, e) {
- return new Qn(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, e, t.endAt);
- }(t._query, e));
- }
- }
- function Ll(...t) {
- return Bl._create("startAt", t,
- !0);
- }
- function ql(...t) {
- return Bl._create("startAfter", t,
- !1);
- }
- class Ul extends bl {
-
- 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 Ul(t, e, n);
- }
- _apply(t) {
- const e = Ql(t, this.type, this._docOrFields, this._inclusive);
- return new mh(t.firestore, t.converter, function(t, e) {
- return new Qn(t.path, t.collectionGroup, t.explicitOrderBy.slice(), t.filters.slice(), t.limit, t.limitType, t.startAt, e);
- }(t._query, e));
- }
- }
- function Kl(...t) {
- return Ul._create("endBefore", t,
- !1);
- }
- function Gl(...t) {
- return Ul._create("endAt", t,
- !0);
- }
- function Ql(t, e, n, s) {
- if (n[0] = _(n[0]), n[0] instanceof El) return function(t, e, n, s, i) {
- if (!s) throw new G(K.NOT_FOUND, `Can't use a DocumentSnapshot that doesn't exist for ${n}().`);
- const r = [];
-
-
-
-
-
-
-
- for (const n of Xn(t)) if (n.field.isKeyField()) r.push(Ye(e, s.key)); else {
- const t = s.data.field(n.field);
- if (Me(t)) throw new G(K.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 G(K.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 dn(r, i);
- }
-
- (t._query, t.firestore._databaseId, e, n[0]._document, s);
- {
- const i = nl(t.firestore);
- return function(t, e, n, s, i, r) {
-
- const o = t.explicitOrderBy;
- if (i.length > o.length) throw new G(K.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 G(K.INVALID_ARGUMENT, `Invalid query. Expected a string for document ID in ${s}(), but got a ${typeof c}`);
- if (!Yn(t) && -1 !== c.indexOf("/")) throw new G(K.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(at.fromString(c));
- if (!ft.isDocumentKey(n)) throw new G(K.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 ft(n);
- u.push(Ye(e, i));
- } else {
- const t = fl(n, s, c);
- u.push(t);
- }
- }
- return new dn(u, r);
- }
-
- (t._query, t.firestore._databaseId, i, e, n, s);
- }
- }
- function jl(t, e, n) {
- if ("string" == typeof (n = _(n))) {
- if ("" === n) throw new G(K.INVALID_ARGUMENT, "Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");
- if (!Yn(e) && -1 !== n.indexOf("/")) throw new G(K.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(at.fromString(n));
- if (!ft.isDocumentKey(s)) throw new G(K.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 Ye(t, new ft(s));
- }
- if (n instanceof _h) return Ye(t, n._key);
- throw new G(K.INVALID_ARGUMENT, `Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${ah(n)}.`);
- }
- function zl(t, e) {
- if (!Array.isArray(t) || 0 === t.length) throw new G(K.INVALID_ARGUMENT, `Invalid Query. A non-empty array is required for '${e.toString()}' filters.`);
- }
- function Wl(t, e) {
- if (e.isInequality()) {
- const n = Jn(t), s = e.field;
- if (null !== n && !n.isEqual(s)) throw new G(K.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 = Hn(t);
- null !== i && Hl(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 G(K.INVALID_ARGUMENT, `Invalid query. You cannot use more than one '${e.op.toString()}' filter.`) : new G(K.INVALID_ARGUMENT, `Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`);
- }
- function Hl(t, e, n) {
- if (!n.isEqual(e)) throw new G(K.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 Jl(t, e) {
- if (!(e instanceof Sl || e instanceof Cl)) throw new G(K.INVALID_ARGUMENT, `Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`);
- }
- class Yl {
- convertValue(t, e = "none") {
- switch (Ke(t)) {
- case 0 :
- return null;
- case 1 :
- return t.booleanValue;
- case 2 :
- return ke(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($e(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 B();
- }
- }
- convertObject(t, e) {
- return this.convertObjectMap(t.fields, e);
- }
-
- convertObjectMap(t, e = "none") {
- const n = {};
- return pe(t, ((t, s) => {
- n[t] = this.convertValue(s, e);
- })), n;
- }
- convertGeoPoint(t) {
- return new Hh(ke(t.latitude), ke(t.longitude));
- }
- convertArray(t, e) {
- return (t.values || []).map((t => this.convertValue(t, e)));
- }
- convertServerTimestamp(t, e) {
- switch (e) {
- case "previous":
- const n = Oe(t);
- return null == n ? null : this.convertValue(n, e);
- case "estimate":
- return this.convertTimestamp(Fe(t));
- default:
- return null;
- }
- }
- convertTimestamp(t) {
- const e = Ne(t);
- return new ot(e.seconds, e.nanos);
- }
- convertDocumentKey(t, e) {
- const n = at.fromString(t);
- L(hr(n));
- const s = new Le(n.get(1), n.get(3)), i = new ft(n.popFirst(5));
- return s.isEqual(e) ||
-
- M(`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 Xl(t, e, n) {
- let s;
-
-
-
- return s = t ? n && (n.merge || n.mergeFields) ? t.toFirestore(e, n) : t.toFirestore(e) : e,
- s;
- }
- class Zl extends Yl {
- constructor(t) {
- super(), this.firestore = t;
- }
- convertBytes(t) {
- return new Qh(t);
- }
- convertReference(t) {
- const e = this.convertDocumentKey(t, this.firestore._databaseId);
- return new _h(this.firestore, null, e);
- }
- }
- function tf(t) {
- return new Kh("sum", gl("sum", t));
- }
- function ef(t) {
- return new Kh("avg", gl("average", t));
- }
- function nf() {
- return new Kh("count");
- }
- function sf(t, e) {
- var n, s;
- return t instanceof Kh && e instanceof Kh && 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 rf(t, e) {
- return Eh(t.query, e.query) && m(t.data(), e.data());
- }
- class of {
-
- constructor(t, e) {
- this.hasPendingWrites = t, this.fromCache = e;
- }
-
- isEqual(t) {
- return this.hasPendingWrites === t.hasPendingWrites && this.fromCache === t.fromCache;
- }
- }
- class uf extends El {
-
- 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 cf(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(vl("DocumentSnapshot.get", t));
- if (null !== n) return this._userDataWriter.convertValue(n, e.serverTimestamps);
- }
- }
- }
- class cf extends uf {
-
- data(t = {}) {
- return super.data(t);
- }
- }
- class af {
-
- constructor(t, e, n, s) {
- this._firestore = t, this._userDataWriter = e, this._snapshot = s, this.metadata = new of(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 cf(this._firestore, this._userDataWriter, n.key, n, new of(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 G(K.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 cf(t._firestore, t._userDataWriter, n.doc.key, n.doc, new of(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 cf(t._firestore, t._userDataWriter, e.doc.key, e.doc, new of(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: hf(e.type),
- doc: s,
- oldIndex: i,
- newIndex: r
- };
- }));
- }
- }(this, e), this._cachedChangesIncludeMetadataChanges = e), this._cachedChanges;
- }
- }
- function hf(t) {
- switch (t) {
- case 0 :
- return "added";
- case 2 :
- case 3 :
- return "modified";
- case 1 :
- return "removed";
- default:
- return B();
- }
- }
- function lf(t, e) {
- return t instanceof uf && e instanceof uf ? 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 af && e instanceof af && (t._firestore === e._firestore && Eh(t.query, e.query) && t.metadata.isEqual(e.metadata) && t._snapshot.isEqual(e._snapshot));
- }
- function ff(t) {
- t = hh(t, _h);
- const e = hh(t.firestore, bh);
- return Ja(Dh(e), t._key).then((n => Pf(e, t, n)));
- }
- class df extends Yl {
- constructor(t) {
- super(), this.firestore = t;
- }
- convertBytes(t) {
- return new Qh(t);
- }
- convertReference(t) {
- const e = this.convertDocumentKey(t, this.firestore._databaseId);
- return new _h(this.firestore, null, e);
- }
- }
- function wf(t) {
- t = hh(t, _h);
- const e = hh(t.firestore, bh), n = Dh(e), s = new df(e);
- return Ha(n, t._key).then((n => new uf(e, s, t._key, n, new of(null !== n && n.hasLocalMutations,
- !0), t.converter)));
- }
- function _f(t) {
- t = hh(t, _h);
- const e = hh(t.firestore, bh);
- return Ja(Dh(e), t._key, {
- source: "server"
- }).then((n => Pf(e, t, n)));
- }
- function mf(t) {
- t = hh(t, mh);
- const e = hh(t.firestore, bh), n = Dh(e), s = new df(e);
- return Rl(t._query), Xa(n, t._query).then((n => new af(e, s, t, n)));
- }
- function gf(t) {
- t = hh(t, mh);
- const e = hh(t.firestore, bh), n = Dh(e), s = new df(e);
- return Ya(n, t._query).then((n => new af(e, s, t, n)));
- }
- function yf(t) {
- t = hh(t, mh);
- const e = hh(t.firestore, bh), n = Dh(e), s = new df(e);
- return Xa(n, t._query, {
- source: "server"
- }).then((n => new af(e, s, t, n)));
- }
- function pf(t, e, n) {
- t = hh(t, _h);
- const s = hh(t.firestore, bh), i = Xl(t.converter, e, n);
- return Rf(s, [ sl(nl(s), "setDoc", t._key, i, null !== t.converter, n).toMutation(t._key, qs.none()) ]);
- }
- function If(t, e, n, ...s) {
- t = hh(t, _h);
- const i = hh(t.firestore, bh), r = nl(i);
- let o;
- o = "string" == typeof (
-
-
- e = _(e)) || e instanceof jh ? ll(r, "updateDoc", t._key, e, n, s) : hl(r, "updateDoc", t._key, e);
- return Rf(i, [ o.toMutation(t._key, qs.exists(!0)) ]);
- }
- function Tf(t) {
- return Rf(hh(t.firestore, bh), [ new ti(t._key, qs.none()) ]);
- }
- function Ef(t, e) {
- const n = hh(t.firestore, bh), s = Ih(t), i = Xl(t.converter, e);
- return Rf(n, [ sl(nl(t.firestore), "addDoc", s._key, i, null !== t.converter, {}).toMutation(s._key, qs.exists(!1)) ]).then((() => s));
- }
- function Af(t, ...e) {
- var n, s, i;
- t = _(t);
- let r = {
- includeMetadataChanges: !1
- }, o = 0;
- "object" != typeof e[o] || vh(e[o]) || (r = e[o], o++);
- const u = {
- includeMetadataChanges: r.includeMetadataChanges
- };
- if (vh(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 _h) a = hh(t.firestore, bh), h = zn(t._key.path), c = {
- next: n => {
- e[o] && e[o](Pf(a, t, n));
- },
- error: e[o + 1],
- complete: e[o + 2]
- }; else {
- const n = hh(t, mh);
- a = hh(n.firestore, bh), h = n._query;
- const s = new df(a);
- c = {
- next: t => {
- e[o] && e[o](new af(a, s, n, t));
- },
- error: e[o + 1],
- complete: e[o + 2]
- }, Rl(t._query);
- }
- return function(t, e, n, s) {
- const i = new Ca(s), r = new Mc(e, i, n);
- return t.asyncQueue.enqueueAndForget((async () => Cc(await ja(t), r))), () => {
- i.Dc(), t.asyncQueue.enqueueAndForget((async () => xc(await ja(t), r)));
- };
- }(Dh(a), h, u, c);
- }
- function vf(t, e) {
- return Za(Dh(t = hh(t, bh)), vh(e) ? e : {
- next: e
- });
- }
- function Rf(t, e) {
- return function(t, e) {
- const n = new Q;
- return t.asyncQueue.enqueueAndForget((async () => Jc(await Ga(t), e, n))), n.promise;
- }(Dh(t), e);
- }
- function Pf(t, e, n) {
- const s = n.docs.get(e._key), i = new df(t);
- return new uf(t, i, e._key, s, new of(n.hasPendingWrites, n.fromCache), e.converter);
- }
- function bf(t) {
- return Vf(t, {
- count: nf()
- });
- }
- function Vf(t, e) {
- const n = hh(t.firestore, bh), s = Dh(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 ri(e, t._aggregateType, t._internalFieldPath)));
-
- return function(t, e, n) {
- const s = new Q;
- return t.asyncQueue.enqueueAndForget((async () => {
-
-
-
-
- try {
-
- const i = await Qa(t);
- s.resolve(zu(i, e, n));
- } catch (t) {
- s.reject(t);
- }
- })), s.promise;
- }(s, t._query, i).then((e =>
-
- function(t, e, n) {
- const s = new df(t);
- return new Gh(e, s, n);
- }
-
- (n, t, e)));
- }
- class Sf {
- constructor(t) {
- this.kind = "memory", this._onlineComponentProvider = new Sa, (null == t ? void 0 : t.garbageCollector) ? this._offlineComponentProvider = t.garbageCollector._offlineComponentProvider : this._offlineComponentProvider = new Ra;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class Df {
- constructor(t) {
- let e;
- this.kind = "persistent", (null == t ? void 0 : t.tabManager) ? (t.tabManager._initialize(t),
- e = t.tabManager) : (e = Bf(void 0), e._initialize(t)), this._onlineComponentProvider = e._onlineComponentProvider,
- this._offlineComponentProvider = e._offlineComponentProvider;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class Cf {
- constructor() {
- this.kind = "memoryEager", this._offlineComponentProvider = new Ra;
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- class xf {
- constructor(t) {
- this.kind = "memoryLru", this._offlineComponentProvider = new Pa(t);
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
- }
- function Nf() {
- return new Cf;
- }
- function kf(t) {
- return new xf(null == t ? void 0 : t.cacheSizeBytes);
- }
- function $f(t) {
- return new Sf(t);
- }
- function Mf(t) {
- return new Df(t);
- }
- class Of {
- constructor(t) {
- this.forceOwnership = t, this.kind = "persistentSingleTab";
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
-
- _initialize(t) {
- this._onlineComponentProvider = new Sa, this._offlineComponentProvider = new ba(this._onlineComponentProvider, null == t ? void 0 : t.cacheSizeBytes, this.forceOwnership);
- }
- }
- class Ff {
- constructor() {
- this.kind = "PersistentMultipleTab";
- }
- toJSON() {
- return {
- kind: this.kind
- };
- }
-
- _initialize(t) {
- this._onlineComponentProvider = new Sa, this._offlineComponentProvider = new Va(this._onlineComponentProvider, null == t ? void 0 : t.cacheSizeBytes);
- }
- }
- function Bf(t) {
- return new Of(null == t ? void 0 : t.forceOwnership);
- }
- function Lf() {
- return new Ff;
- }
- const qf = {
- maxAttempts: 5
- };
- class Uf {
-
- constructor(t, e) {
- this._firestore = t, this._commitHandler = e, this._mutations = [], this._committed = !1,
- this._dataReader = nl(t);
- }
- set(t, e, n) {
- this._verifyNotCommitted();
- const s = Kf(t, this._firestore), i = Xl(s.converter, e, n), r = sl(this._dataReader, "WriteBatch.set", s._key, i, null !== s.converter, n);
- return this._mutations.push(r.toMutation(s._key, qs.none())), this;
- }
- update(t, e, n, ...s) {
- this._verifyNotCommitted();
- const i = Kf(t, this._firestore);
-
-
- let r;
- return r = "string" == typeof (e = _(e)) || e instanceof jh ? ll(this._dataReader, "WriteBatch.update", i._key, e, n, s) : hl(this._dataReader, "WriteBatch.update", i._key, e),
- this._mutations.push(r.toMutation(i._key, qs.exists(!0))), this;
- }
-
- delete(t) {
- this._verifyNotCommitted();
- const e = Kf(t, this._firestore);
- return this._mutations = this._mutations.concat(new ti(e._key, qs.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 G(K.FAILED_PRECONDITION, "A write batch can no longer be used after commit() has been called.");
- }
- }
- function Kf(t, e) {
- if ((t = _(t)).firestore !== e) throw new G(K.INVALID_ARGUMENT, "Provided document reference is from a different Firestore instance.");
- return t;
- }
- class Gf extends class {
-
- constructor(t, e) {
- this._firestore = t, this._transaction = e, this._dataReader = nl(t);
- }
-
- get(t) {
- const e = Kf(t, this._firestore), n = new Zl(this._firestore);
- return this._transaction.lookup([ e._key ]).then((t => {
- if (!t || 1 !== t.length) return B();
- const s = t[0];
- if (s.isFoundDocument()) return new El(this._firestore, n, s.key, s, e.converter);
- if (s.isNoDocument()) return new El(this._firestore, n, e._key, null, e.converter);
- throw B();
- }));
- }
- set(t, e, n) {
- const s = Kf(t, this._firestore), i = Xl(s.converter, e, n), r = sl(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 = Kf(t, this._firestore);
-
-
- let r;
- return r = "string" == typeof (e = _(e)) || e instanceof jh ? ll(this._dataReader, "Transaction.update", i._key, e, n, s) : hl(this._dataReader, "Transaction.update", i._key, e),
- this._transaction.update(i._key, r), this;
- }
-
- delete(t) {
- const e = Kf(t, this._firestore);
- return this._transaction.delete(e._key), this;
- }
- } {
-
-
-
- constructor(t, e) {
- super(t, e), this._firestore = t;
- }
-
- get(t) {
- const e = Kf(t, this._firestore), n = new df(this._firestore);
- return super.get(t).then((t => new uf(this._firestore, n, e._key, t._document, new of(
- !1,
- !1), e.converter)));
- }
- }
- function Qf(t, e, n) {
- t = hh(t, bh);
- const s = Object.assign(Object.assign({}, qf), n);
- !function(t) {
- if (t.maxAttempts < 1) throw new G(K.INVALID_ARGUMENT, "Max attempts must be at least 1");
- }(s);
- return function(t, e, n) {
- const s = new Q;
- return t.asyncQueue.enqueueAndForget((async () => {
- const i = await Qa(t);
- new ka(t.asyncQueue, i, n, e, s).run();
- })), s.promise;
- }(Dh(t), (n => e(new Gf(t, n))), s);
- }
- function jf() {
- return new il("deleteField");
- }
- function zf() {
- return new ol("serverTimestamp");
- }
- function Wf(...t) {
-
-
- return new ul("arrayUnion", t);
- }
- function Hf(...t) {
-
-
- return new cl("arrayRemove", t);
- }
- function Jf(t) {
- return new al("increment", t);
- }
- function Yf(t) {
- return Dh(t = hh(t, bh)), new Uf(t, (e => Rf(t, e)));
- }
- function Xf(t, e) {
- var n;
- const s = Dh(t = hh(t, bh));
- if (!s._uninitializedComponentsProvider || "memory" === (null === (n = s._uninitializedComponentsProvider) || void 0 === n ? void 0 : n._offlineKind))
-
-
- return O("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 G(K.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 = Zf(t, "collectionGroup"), s = [];
- if (Array.isArray(t.fields)) for (const e of t.fields) {
- const t = pl("setIndexConfiguration", Zf(e, "fieldPath"));
- "CONTAINS" === e.arrayConfig ? s.push(new gt(t, 2 )) : "ASCENDING" === e.order ? s.push(new gt(t, 0 )) : "DESCENDING" === e.order && s.push(new gt(t, 1 ));
- }
- n.push(new dt(dt.UNKNOWN_ID, e, s, pt.empty()));
- }
- return n;
- }(e);
- return nh(s, i);
- }
- function Zf(t, e) {
- if ("string" != typeof t[e]) throw new G(K.INVALID_ARGUMENT, "Missing string value for: " + e);
- return t[e];
- }
- !function(t, e = !0) {
- !function(t) {
- C = t;
- }(i), n(new r("firestore", ((t, {instanceIdentifier: n, options: s}) => {
- const i = t.getProvider("app").getImmediate(), r = new bh(new H(t.getProvider("auth-internal")), new Z(t.getProvider("app-check-internal")), function(t, e) {
- if (!Object.prototype.hasOwnProperty.apply(t.options, [ "projectId" ])) throw new G(K.INVALID_ARGUMENT, '"projectId" not provided in firebase.initializeApp.');
- return new Le(t.options.projectId, e);
- }(i, n), i);
- return s = Object.assign({
- useFetchStreams: e
- }, s), r._setSettings(s), r;
- }), "PUBLIC").setMultipleInstances(!0)), s(S, "3.13.0", t),
-
- s(S, "3.13.0", "esm2017");
- }("rn", !1);
- export { Yl as AbstractUserDataWriter, Kh as AggregateField, Gh as AggregateQuerySnapshot, Qh as Bytes, Ph as CACHE_SIZE_UNLIMITED, gh as CollectionReference, _h as DocumentReference, uf as DocumentSnapshot, jh as FieldPath, Wh as FieldValue, bh as Firestore, G as FirestoreError, Hh as GeoPoint, Rh as LoadBundleTask, mh as Query, Cl as QueryCompositeFilterConstraint, bl as QueryConstraint, cf as QueryDocumentSnapshot, Ul as QueryEndAtConstraint, Sl as QueryFieldFilterConstraint, Ml as QueryLimitConstraint, kl as QueryOrderByConstraint, af as QuerySnapshot, Bl as QueryStartAtConstraint, of as SnapshotMetadata, ot as Timestamp, Gf as Transaction, Uf as WriteBatch, Le as _DatabaseId, ft as _DocumentKey, tt as _EmptyAppCheckTokenProvider, z as _EmptyAuthCredentialsProvider, lt as _FieldPath, li as _TestingHooks, hh as _cast, q as _debugAssert, De as _isBase64Available, O as _logWarn, oh as _validateIsNotUsedTogether, Ef as addDoc, sf as aggregateFieldEqual, rf as aggregateQuerySnapshotEqual, Nl as and, Hf as arrayRemove, Wf as arrayUnion, ef as average, $h as clearIndexedDbPersistence, yh as collection, ph as collectionGroup, wh as connectFirestoreEmulator, nf as count, Tf as deleteDoc, jf as deleteField, Fh as disableNetwork, Ih as doc, zh as documentId, xh as enableIndexedDbPersistence, Nh as enableMultiTabIndexedDbPersistence, Oh as enableNetwork, Gl as endAt, Kl as endBefore, Dh as ensureFirestoreConfigured, Rf as executeWrite, Vf as getAggregateFromServer, bf as getCountFromServer, ff as getDoc, wf as getDocFromCache, _f as getDocFromServer, mf as getDocs, gf as getDocsFromCache, yf as getDocsFromServer, Sh as getFirestore, Jf as increment, Vh as initializeFirestore, Ol as limit, Fl as limitToLast, Lh as loadBundle, Nf as memoryEagerGarbageCollector, $f as memoryLocalCache, kf as memoryLruGarbageCollector, qh as namedQuery, Af as onSnapshot, vf as onSnapshotsInSync, xl as or, $l as orderBy, Mf as persistentLocalCache, Lf as persistentMultipleTabManager, Bf as persistentSingleTabManager, Vl as query, Eh as queryEqual, Th as refEqual, Qf as runTransaction, zf as serverTimestamp, pf as setDoc, Xf as setIndexConfiguration, k as setLogLevel, lf as snapshotEqual, ql as startAfter, Ll as startAt, tf as sum, Bh as terminate, If as updateDoc, Mh as waitForPendingWrites, Dl as where, Yf as writeBatch };
|