index.cjs 1.7 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593
  1. var __create = Object.create;
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __getProtoOf = Object.getPrototypeOf;
  6. var __hasOwnProp = Object.prototype.hasOwnProperty;
  7. var __glob = (map) => (path) => {
  8. var fn = map[path];
  9. if (fn) return fn();
  10. throw new Error("Module not found in bundle: " + path);
  11. };
  12. var __esm = (fn, res) => function __init() {
  13. return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
  14. };
  15. var __commonJS = (cb, mod) => function __require() {
  16. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  17. };
  18. var __export = (target, all) => {
  19. for (var name in all)
  20. __defProp(target, name, { get: all[name], enumerable: true });
  21. };
  22. var __copyProps = (to, from, except, desc) => {
  23. if (from && typeof from === "object" || typeof from === "function") {
  24. for (let key of __getOwnPropNames(from))
  25. if (!__hasOwnProp.call(to, key) && key !== except)
  26. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  27. }
  28. return to;
  29. };
  30. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  31. // If the importer is in node compatibility mode or this is not an ESM
  32. // file that has been converted to a CommonJS file using a Babel-
  33. // compatible transform (i.e. "__esModule" has not been set), then set
  34. // "default" to the CommonJS "module.exports" for node compatibility.
  35. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  36. mod
  37. ));
  38. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  39. // node_modules/mongodb/lib/error.js
  40. var require_error = __commonJS({
  41. "node_modules/mongodb/lib/error.js"(exports2) {
  42. "use strict";
  43. Object.defineProperty(exports2, "__esModule", { value: true });
  44. exports2.isResumableError = exports2.isNetworkTimeoutError = exports2.isSDAMUnrecoverableError = exports2.isNodeShuttingDownError = exports2.isRetryableReadError = exports2.isRetryableWriteError = exports2.needsRetryableWriteLabel = exports2.MongoWriteConcernError = exports2.MongoServerSelectionError = exports2.MongoSystemError = exports2.MongoMissingDependencyError = exports2.MongoMissingCredentialsError = exports2.MongoCompatibilityError = exports2.MongoInvalidArgumentError = exports2.MongoParseError = exports2.MongoNetworkTimeoutError = exports2.MongoNetworkError = exports2.isNetworkErrorBeforeHandshake = exports2.MongoTopologyClosedError = exports2.MongoCursorExhaustedError = exports2.MongoServerClosedError = exports2.MongoCursorInUseError = exports2.MongoUnexpectedServerResponseError = exports2.MongoGridFSChunkError = exports2.MongoGridFSStreamError = exports2.MongoTailableCursorError = exports2.MongoChangeStreamError = exports2.MongoAzureError = exports2.MongoAWSError = exports2.MongoKerberosError = exports2.MongoExpiredSessionError = exports2.MongoTransactionError = exports2.MongoNotConnectedError = exports2.MongoDecompressionError = exports2.MongoBatchReExecutionError = exports2.MongoRuntimeError = exports2.MongoAPIError = exports2.MongoDriverError = exports2.MongoServerError = exports2.MongoError = exports2.MongoErrorLabel = exports2.GET_MORE_RESUMABLE_CODES = exports2.MONGODB_ERROR_CODES = exports2.NODE_IS_RECOVERING_ERROR_MESSAGE = exports2.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = exports2.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = void 0;
  45. var kErrorLabels = Symbol("errorLabels");
  46. exports2.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE = new RegExp("not master", "i");
  47. exports2.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE = new RegExp("not master or secondary", "i");
  48. exports2.NODE_IS_RECOVERING_ERROR_MESSAGE = new RegExp("node is recovering", "i");
  49. exports2.MONGODB_ERROR_CODES = Object.freeze({
  50. HostUnreachable: 6,
  51. HostNotFound: 7,
  52. NetworkTimeout: 89,
  53. ShutdownInProgress: 91,
  54. PrimarySteppedDown: 189,
  55. ExceededTimeLimit: 262,
  56. SocketException: 9001,
  57. NotWritablePrimary: 10107,
  58. InterruptedAtShutdown: 11600,
  59. InterruptedDueToReplStateChange: 11602,
  60. NotPrimaryNoSecondaryOk: 13435,
  61. NotPrimaryOrSecondary: 13436,
  62. StaleShardVersion: 63,
  63. StaleEpoch: 150,
  64. StaleConfig: 13388,
  65. RetryChangeStream: 234,
  66. FailedToSatisfyReadPreference: 133,
  67. CursorNotFound: 43,
  68. LegacyNotPrimary: 10058,
  69. WriteConcernFailed: 64,
  70. NamespaceNotFound: 26,
  71. IllegalOperation: 20,
  72. MaxTimeMSExpired: 50,
  73. UnknownReplWriteConcern: 79,
  74. UnsatisfiableWriteConcern: 100,
  75. Reauthenticate: 391
  76. });
  77. exports2.GET_MORE_RESUMABLE_CODES = /* @__PURE__ */ new Set([
  78. exports2.MONGODB_ERROR_CODES.HostUnreachable,
  79. exports2.MONGODB_ERROR_CODES.HostNotFound,
  80. exports2.MONGODB_ERROR_CODES.NetworkTimeout,
  81. exports2.MONGODB_ERROR_CODES.ShutdownInProgress,
  82. exports2.MONGODB_ERROR_CODES.PrimarySteppedDown,
  83. exports2.MONGODB_ERROR_CODES.ExceededTimeLimit,
  84. exports2.MONGODB_ERROR_CODES.SocketException,
  85. exports2.MONGODB_ERROR_CODES.NotWritablePrimary,
  86. exports2.MONGODB_ERROR_CODES.InterruptedAtShutdown,
  87. exports2.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
  88. exports2.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
  89. exports2.MONGODB_ERROR_CODES.NotPrimaryOrSecondary,
  90. exports2.MONGODB_ERROR_CODES.StaleShardVersion,
  91. exports2.MONGODB_ERROR_CODES.StaleEpoch,
  92. exports2.MONGODB_ERROR_CODES.StaleConfig,
  93. exports2.MONGODB_ERROR_CODES.RetryChangeStream,
  94. exports2.MONGODB_ERROR_CODES.FailedToSatisfyReadPreference,
  95. exports2.MONGODB_ERROR_CODES.CursorNotFound
  96. ]);
  97. exports2.MongoErrorLabel = Object.freeze({
  98. RetryableWriteError: "RetryableWriteError",
  99. TransientTransactionError: "TransientTransactionError",
  100. UnknownTransactionCommitResult: "UnknownTransactionCommitResult",
  101. ResumableChangeStreamError: "ResumableChangeStreamError",
  102. HandshakeError: "HandshakeError",
  103. ResetPool: "ResetPool",
  104. InterruptInUseConnections: "InterruptInUseConnections",
  105. NoWritesPerformed: "NoWritesPerformed"
  106. });
  107. function isAggregateError(e) {
  108. return "errors" in e && Array.isArray(e.errors);
  109. }
  110. var MongoError = class _MongoError extends Error {
  111. constructor(message) {
  112. super(_MongoError.buildErrorMessage(message));
  113. if (message instanceof Error) {
  114. this.cause = message;
  115. }
  116. this[kErrorLabels] = /* @__PURE__ */ new Set();
  117. }
  118. /** @internal */
  119. static buildErrorMessage(e) {
  120. if (typeof e === "string") {
  121. return e;
  122. }
  123. if (isAggregateError(e) && e.message.length === 0) {
  124. return e.errors.length === 0 ? "AggregateError has an empty errors array. Please check the `cause` property for more information." : e.errors.map(({ message }) => message).join(", ");
  125. }
  126. return e.message;
  127. }
  128. get name() {
  129. return "MongoError";
  130. }
  131. /** Legacy name for server error responses */
  132. get errmsg() {
  133. return this.message;
  134. }
  135. /**
  136. * Checks the error to see if it has an error label
  137. *
  138. * @param label - The error label to check for
  139. * @returns returns true if the error has the provided error label
  140. */
  141. hasErrorLabel(label) {
  142. return this[kErrorLabels].has(label);
  143. }
  144. addErrorLabel(label) {
  145. this[kErrorLabels].add(label);
  146. }
  147. get errorLabels() {
  148. return Array.from(this[kErrorLabels]);
  149. }
  150. };
  151. exports2.MongoError = MongoError;
  152. var MongoServerError = class extends MongoError {
  153. constructor(message) {
  154. super(message.message || message.errmsg || message.$err || "n/a");
  155. if (message.errorLabels) {
  156. this[kErrorLabels] = new Set(message.errorLabels);
  157. }
  158. for (const name in message) {
  159. if (name !== "errorLabels" && name !== "errmsg" && name !== "message")
  160. this[name] = message[name];
  161. }
  162. }
  163. get name() {
  164. return "MongoServerError";
  165. }
  166. };
  167. exports2.MongoServerError = MongoServerError;
  168. var MongoDriverError = class extends MongoError {
  169. constructor(message) {
  170. super(message);
  171. }
  172. get name() {
  173. return "MongoDriverError";
  174. }
  175. };
  176. exports2.MongoDriverError = MongoDriverError;
  177. var MongoAPIError = class extends MongoDriverError {
  178. constructor(message) {
  179. super(message);
  180. }
  181. get name() {
  182. return "MongoAPIError";
  183. }
  184. };
  185. exports2.MongoAPIError = MongoAPIError;
  186. var MongoRuntimeError = class extends MongoDriverError {
  187. constructor(message) {
  188. super(message);
  189. }
  190. get name() {
  191. return "MongoRuntimeError";
  192. }
  193. };
  194. exports2.MongoRuntimeError = MongoRuntimeError;
  195. var MongoBatchReExecutionError = class extends MongoAPIError {
  196. constructor(message = "This batch has already been executed, create new batch to execute") {
  197. super(message);
  198. }
  199. get name() {
  200. return "MongoBatchReExecutionError";
  201. }
  202. };
  203. exports2.MongoBatchReExecutionError = MongoBatchReExecutionError;
  204. var MongoDecompressionError = class extends MongoRuntimeError {
  205. constructor(message) {
  206. super(message);
  207. }
  208. get name() {
  209. return "MongoDecompressionError";
  210. }
  211. };
  212. exports2.MongoDecompressionError = MongoDecompressionError;
  213. var MongoNotConnectedError = class extends MongoAPIError {
  214. constructor(message) {
  215. super(message);
  216. }
  217. get name() {
  218. return "MongoNotConnectedError";
  219. }
  220. };
  221. exports2.MongoNotConnectedError = MongoNotConnectedError;
  222. var MongoTransactionError = class extends MongoAPIError {
  223. constructor(message) {
  224. super(message);
  225. }
  226. get name() {
  227. return "MongoTransactionError";
  228. }
  229. };
  230. exports2.MongoTransactionError = MongoTransactionError;
  231. var MongoExpiredSessionError = class extends MongoAPIError {
  232. constructor(message = "Cannot use a session that has ended") {
  233. super(message);
  234. }
  235. get name() {
  236. return "MongoExpiredSessionError";
  237. }
  238. };
  239. exports2.MongoExpiredSessionError = MongoExpiredSessionError;
  240. var MongoKerberosError = class extends MongoRuntimeError {
  241. constructor(message) {
  242. super(message);
  243. }
  244. get name() {
  245. return "MongoKerberosError";
  246. }
  247. };
  248. exports2.MongoKerberosError = MongoKerberosError;
  249. var MongoAWSError = class extends MongoRuntimeError {
  250. constructor(message) {
  251. super(message);
  252. }
  253. get name() {
  254. return "MongoAWSError";
  255. }
  256. };
  257. exports2.MongoAWSError = MongoAWSError;
  258. var MongoAzureError = class extends MongoRuntimeError {
  259. constructor(message) {
  260. super(message);
  261. }
  262. get name() {
  263. return "MongoAzureError";
  264. }
  265. };
  266. exports2.MongoAzureError = MongoAzureError;
  267. var MongoChangeStreamError = class extends MongoRuntimeError {
  268. constructor(message) {
  269. super(message);
  270. }
  271. get name() {
  272. return "MongoChangeStreamError";
  273. }
  274. };
  275. exports2.MongoChangeStreamError = MongoChangeStreamError;
  276. var MongoTailableCursorError = class extends MongoAPIError {
  277. constructor(message = "Tailable cursor does not support this operation") {
  278. super(message);
  279. }
  280. get name() {
  281. return "MongoTailableCursorError";
  282. }
  283. };
  284. exports2.MongoTailableCursorError = MongoTailableCursorError;
  285. var MongoGridFSStreamError = class extends MongoRuntimeError {
  286. constructor(message) {
  287. super(message);
  288. }
  289. get name() {
  290. return "MongoGridFSStreamError";
  291. }
  292. };
  293. exports2.MongoGridFSStreamError = MongoGridFSStreamError;
  294. var MongoGridFSChunkError = class extends MongoRuntimeError {
  295. constructor(message) {
  296. super(message);
  297. }
  298. get name() {
  299. return "MongoGridFSChunkError";
  300. }
  301. };
  302. exports2.MongoGridFSChunkError = MongoGridFSChunkError;
  303. var MongoUnexpectedServerResponseError = class extends MongoRuntimeError {
  304. constructor(message) {
  305. super(message);
  306. }
  307. get name() {
  308. return "MongoUnexpectedServerResponseError";
  309. }
  310. };
  311. exports2.MongoUnexpectedServerResponseError = MongoUnexpectedServerResponseError;
  312. var MongoCursorInUseError = class extends MongoAPIError {
  313. constructor(message = "Cursor is already initialized") {
  314. super(message);
  315. }
  316. get name() {
  317. return "MongoCursorInUseError";
  318. }
  319. };
  320. exports2.MongoCursorInUseError = MongoCursorInUseError;
  321. var MongoServerClosedError = class extends MongoAPIError {
  322. constructor(message = "Server is closed") {
  323. super(message);
  324. }
  325. get name() {
  326. return "MongoServerClosedError";
  327. }
  328. };
  329. exports2.MongoServerClosedError = MongoServerClosedError;
  330. var MongoCursorExhaustedError = class extends MongoAPIError {
  331. constructor(message) {
  332. super(message || "Cursor is exhausted");
  333. }
  334. get name() {
  335. return "MongoCursorExhaustedError";
  336. }
  337. };
  338. exports2.MongoCursorExhaustedError = MongoCursorExhaustedError;
  339. var MongoTopologyClosedError = class extends MongoAPIError {
  340. constructor(message = "Topology is closed") {
  341. super(message);
  342. }
  343. get name() {
  344. return "MongoTopologyClosedError";
  345. }
  346. };
  347. exports2.MongoTopologyClosedError = MongoTopologyClosedError;
  348. var kBeforeHandshake = Symbol("beforeHandshake");
  349. function isNetworkErrorBeforeHandshake(err) {
  350. return err[kBeforeHandshake] === true;
  351. }
  352. exports2.isNetworkErrorBeforeHandshake = isNetworkErrorBeforeHandshake;
  353. var MongoNetworkError = class extends MongoError {
  354. constructor(message, options) {
  355. super(message);
  356. if (options && typeof options.beforeHandshake === "boolean") {
  357. this[kBeforeHandshake] = options.beforeHandshake;
  358. }
  359. }
  360. get name() {
  361. return "MongoNetworkError";
  362. }
  363. };
  364. exports2.MongoNetworkError = MongoNetworkError;
  365. var MongoNetworkTimeoutError = class extends MongoNetworkError {
  366. constructor(message, options) {
  367. super(message, options);
  368. }
  369. get name() {
  370. return "MongoNetworkTimeoutError";
  371. }
  372. };
  373. exports2.MongoNetworkTimeoutError = MongoNetworkTimeoutError;
  374. var MongoParseError = class extends MongoDriverError {
  375. constructor(message) {
  376. super(message);
  377. }
  378. get name() {
  379. return "MongoParseError";
  380. }
  381. };
  382. exports2.MongoParseError = MongoParseError;
  383. var MongoInvalidArgumentError = class extends MongoAPIError {
  384. constructor(message) {
  385. super(message);
  386. }
  387. get name() {
  388. return "MongoInvalidArgumentError";
  389. }
  390. };
  391. exports2.MongoInvalidArgumentError = MongoInvalidArgumentError;
  392. var MongoCompatibilityError = class extends MongoAPIError {
  393. constructor(message) {
  394. super(message);
  395. }
  396. get name() {
  397. return "MongoCompatibilityError";
  398. }
  399. };
  400. exports2.MongoCompatibilityError = MongoCompatibilityError;
  401. var MongoMissingCredentialsError = class extends MongoAPIError {
  402. constructor(message) {
  403. super(message);
  404. }
  405. get name() {
  406. return "MongoMissingCredentialsError";
  407. }
  408. };
  409. exports2.MongoMissingCredentialsError = MongoMissingCredentialsError;
  410. var MongoMissingDependencyError = class extends MongoAPIError {
  411. constructor(message, { cause } = {}) {
  412. super(message);
  413. if (cause)
  414. this.cause = cause;
  415. }
  416. get name() {
  417. return "MongoMissingDependencyError";
  418. }
  419. };
  420. exports2.MongoMissingDependencyError = MongoMissingDependencyError;
  421. var MongoSystemError = class extends MongoError {
  422. constructor(message, reason) {
  423. var _a;
  424. if (reason && reason.error) {
  425. super(reason.error.message || reason.error);
  426. } else {
  427. super(message);
  428. }
  429. if (reason) {
  430. this.reason = reason;
  431. }
  432. this.code = (_a = reason.error) == null ? void 0 : _a.code;
  433. }
  434. get name() {
  435. return "MongoSystemError";
  436. }
  437. };
  438. exports2.MongoSystemError = MongoSystemError;
  439. var MongoServerSelectionError = class extends MongoSystemError {
  440. constructor(message, reason) {
  441. super(message, reason);
  442. }
  443. get name() {
  444. return "MongoServerSelectionError";
  445. }
  446. };
  447. exports2.MongoServerSelectionError = MongoServerSelectionError;
  448. function makeWriteConcernResultObject(input) {
  449. const output = Object.assign({}, input);
  450. if (output.ok === 0) {
  451. output.ok = 1;
  452. delete output.errmsg;
  453. delete output.code;
  454. delete output.codeName;
  455. }
  456. return output;
  457. }
  458. var MongoWriteConcernError = class extends MongoServerError {
  459. constructor(message, result) {
  460. if (result && Array.isArray(result.errorLabels)) {
  461. message.errorLabels = result.errorLabels;
  462. }
  463. super(message);
  464. this.errInfo = message.errInfo;
  465. if (result != null) {
  466. this.result = makeWriteConcernResultObject(result);
  467. }
  468. }
  469. get name() {
  470. return "MongoWriteConcernError";
  471. }
  472. };
  473. exports2.MongoWriteConcernError = MongoWriteConcernError;
  474. var RETRYABLE_READ_ERROR_CODES = /* @__PURE__ */ new Set([
  475. exports2.MONGODB_ERROR_CODES.HostUnreachable,
  476. exports2.MONGODB_ERROR_CODES.HostNotFound,
  477. exports2.MONGODB_ERROR_CODES.NetworkTimeout,
  478. exports2.MONGODB_ERROR_CODES.ShutdownInProgress,
  479. exports2.MONGODB_ERROR_CODES.PrimarySteppedDown,
  480. exports2.MONGODB_ERROR_CODES.SocketException,
  481. exports2.MONGODB_ERROR_CODES.NotWritablePrimary,
  482. exports2.MONGODB_ERROR_CODES.InterruptedAtShutdown,
  483. exports2.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
  484. exports2.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
  485. exports2.MONGODB_ERROR_CODES.NotPrimaryOrSecondary
  486. ]);
  487. var RETRYABLE_WRITE_ERROR_CODES = /* @__PURE__ */ new Set([
  488. ...RETRYABLE_READ_ERROR_CODES,
  489. exports2.MONGODB_ERROR_CODES.ExceededTimeLimit
  490. ]);
  491. function needsRetryableWriteLabel(error, maxWireVersion) {
  492. var _a;
  493. if (error instanceof MongoNetworkError) {
  494. return true;
  495. }
  496. if (error instanceof MongoError) {
  497. if ((maxWireVersion >= 9 || error.hasErrorLabel(exports2.MongoErrorLabel.RetryableWriteError)) && !error.hasErrorLabel(exports2.MongoErrorLabel.HandshakeError)) {
  498. return false;
  499. }
  500. }
  501. if (error instanceof MongoWriteConcernError) {
  502. return RETRYABLE_WRITE_ERROR_CODES.has(((_a = error.result) == null ? void 0 : _a.code) ?? error.code ?? 0);
  503. }
  504. if (error instanceof MongoError && typeof error.code === "number") {
  505. return RETRYABLE_WRITE_ERROR_CODES.has(error.code);
  506. }
  507. const isNotWritablePrimaryError2 = exports2.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(error.message);
  508. if (isNotWritablePrimaryError2) {
  509. return true;
  510. }
  511. const isNodeIsRecoveringError = exports2.NODE_IS_RECOVERING_ERROR_MESSAGE.test(error.message);
  512. if (isNodeIsRecoveringError) {
  513. return true;
  514. }
  515. return false;
  516. }
  517. exports2.needsRetryableWriteLabel = needsRetryableWriteLabel;
  518. function isRetryableWriteError(error) {
  519. return error.hasErrorLabel(exports2.MongoErrorLabel.RetryableWriteError);
  520. }
  521. exports2.isRetryableWriteError = isRetryableWriteError;
  522. function isRetryableReadError(error) {
  523. const hasRetryableErrorCode = typeof error.code === "number" ? RETRYABLE_READ_ERROR_CODES.has(error.code) : false;
  524. if (hasRetryableErrorCode) {
  525. return true;
  526. }
  527. if (error instanceof MongoNetworkError) {
  528. return true;
  529. }
  530. const isNotWritablePrimaryError2 = exports2.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(error.message);
  531. if (isNotWritablePrimaryError2) {
  532. return true;
  533. }
  534. const isNodeIsRecoveringError = exports2.NODE_IS_RECOVERING_ERROR_MESSAGE.test(error.message);
  535. if (isNodeIsRecoveringError) {
  536. return true;
  537. }
  538. return false;
  539. }
  540. exports2.isRetryableReadError = isRetryableReadError;
  541. var SDAM_RECOVERING_CODES = /* @__PURE__ */ new Set([
  542. exports2.MONGODB_ERROR_CODES.ShutdownInProgress,
  543. exports2.MONGODB_ERROR_CODES.PrimarySteppedDown,
  544. exports2.MONGODB_ERROR_CODES.InterruptedAtShutdown,
  545. exports2.MONGODB_ERROR_CODES.InterruptedDueToReplStateChange,
  546. exports2.MONGODB_ERROR_CODES.NotPrimaryOrSecondary
  547. ]);
  548. var SDAM_NOT_PRIMARY_CODES = /* @__PURE__ */ new Set([
  549. exports2.MONGODB_ERROR_CODES.NotWritablePrimary,
  550. exports2.MONGODB_ERROR_CODES.NotPrimaryNoSecondaryOk,
  551. exports2.MONGODB_ERROR_CODES.LegacyNotPrimary
  552. ]);
  553. var SDAM_NODE_SHUTTING_DOWN_ERROR_CODES = /* @__PURE__ */ new Set([
  554. exports2.MONGODB_ERROR_CODES.InterruptedAtShutdown,
  555. exports2.MONGODB_ERROR_CODES.ShutdownInProgress
  556. ]);
  557. function isRecoveringError(err) {
  558. if (typeof err.code === "number") {
  559. return SDAM_RECOVERING_CODES.has(err.code);
  560. }
  561. return exports2.LEGACY_NOT_PRIMARY_OR_SECONDARY_ERROR_MESSAGE.test(err.message) || exports2.NODE_IS_RECOVERING_ERROR_MESSAGE.test(err.message);
  562. }
  563. function isNotWritablePrimaryError(err) {
  564. if (typeof err.code === "number") {
  565. return SDAM_NOT_PRIMARY_CODES.has(err.code);
  566. }
  567. if (isRecoveringError(err)) {
  568. return false;
  569. }
  570. return exports2.LEGACY_NOT_WRITABLE_PRIMARY_ERROR_MESSAGE.test(err.message);
  571. }
  572. function isNodeShuttingDownError(err) {
  573. return !!(typeof err.code === "number" && SDAM_NODE_SHUTTING_DOWN_ERROR_CODES.has(err.code));
  574. }
  575. exports2.isNodeShuttingDownError = isNodeShuttingDownError;
  576. function isSDAMUnrecoverableError(error) {
  577. if (error instanceof MongoParseError || error == null) {
  578. return true;
  579. }
  580. return isRecoveringError(error) || isNotWritablePrimaryError(error);
  581. }
  582. exports2.isSDAMUnrecoverableError = isSDAMUnrecoverableError;
  583. function isNetworkTimeoutError(err) {
  584. return !!(err instanceof MongoNetworkError && err.message.match(/timed out/));
  585. }
  586. exports2.isNetworkTimeoutError = isNetworkTimeoutError;
  587. function isResumableError(error, wireVersion) {
  588. if (error == null || !(error instanceof MongoError)) {
  589. return false;
  590. }
  591. if (error instanceof MongoNetworkError) {
  592. return true;
  593. }
  594. if (wireVersion != null && wireVersion >= 9) {
  595. if (error.code === exports2.MONGODB_ERROR_CODES.CursorNotFound) {
  596. return true;
  597. }
  598. return error.hasErrorLabel(exports2.MongoErrorLabel.ResumableChangeStreamError);
  599. }
  600. if (typeof error.code === "number") {
  601. return exports2.GET_MORE_RESUMABLE_CODES.has(error.code);
  602. }
  603. return false;
  604. }
  605. exports2.isResumableError = isResumableError;
  606. }
  607. });
  608. // node_modules/bson/lib/bson.cjs
  609. var require_bson = __commonJS({
  610. "node_modules/bson/lib/bson.cjs"(exports2) {
  611. "use strict";
  612. function isAnyArrayBuffer(value) {
  613. return ["[object ArrayBuffer]", "[object SharedArrayBuffer]"].includes(Object.prototype.toString.call(value));
  614. }
  615. function isUint8Array(value) {
  616. return Object.prototype.toString.call(value) === "[object Uint8Array]";
  617. }
  618. function isRegExp(d) {
  619. return Object.prototype.toString.call(d) === "[object RegExp]";
  620. }
  621. function isMap(d) {
  622. return Object.prototype.toString.call(d) === "[object Map]";
  623. }
  624. function isDate(d) {
  625. return Object.prototype.toString.call(d) === "[object Date]";
  626. }
  627. var BSON_MAJOR_VERSION = 5;
  628. var BSON_INT32_MAX = 2147483647;
  629. var BSON_INT32_MIN = -2147483648;
  630. var BSON_INT64_MAX = Math.pow(2, 63) - 1;
  631. var BSON_INT64_MIN = -Math.pow(2, 63);
  632. var JS_INT_MAX = Math.pow(2, 53);
  633. var JS_INT_MIN = -Math.pow(2, 53);
  634. var BSON_DATA_NUMBER = 1;
  635. var BSON_DATA_STRING = 2;
  636. var BSON_DATA_OBJECT = 3;
  637. var BSON_DATA_ARRAY = 4;
  638. var BSON_DATA_BINARY = 5;
  639. var BSON_DATA_UNDEFINED = 6;
  640. var BSON_DATA_OID = 7;
  641. var BSON_DATA_BOOLEAN = 8;
  642. var BSON_DATA_DATE = 9;
  643. var BSON_DATA_NULL = 10;
  644. var BSON_DATA_REGEXP = 11;
  645. var BSON_DATA_DBPOINTER = 12;
  646. var BSON_DATA_CODE = 13;
  647. var BSON_DATA_SYMBOL = 14;
  648. var BSON_DATA_CODE_W_SCOPE = 15;
  649. var BSON_DATA_INT = 16;
  650. var BSON_DATA_TIMESTAMP = 17;
  651. var BSON_DATA_LONG = 18;
  652. var BSON_DATA_DECIMAL128 = 19;
  653. var BSON_DATA_MIN_KEY = 255;
  654. var BSON_DATA_MAX_KEY = 127;
  655. var BSON_BINARY_SUBTYPE_DEFAULT = 0;
  656. var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
  657. var BSONType = Object.freeze({
  658. double: 1,
  659. string: 2,
  660. object: 3,
  661. array: 4,
  662. binData: 5,
  663. undefined: 6,
  664. objectId: 7,
  665. bool: 8,
  666. date: 9,
  667. null: 10,
  668. regex: 11,
  669. dbPointer: 12,
  670. javascript: 13,
  671. symbol: 14,
  672. javascriptWithScope: 15,
  673. int: 16,
  674. timestamp: 17,
  675. long: 18,
  676. decimal: 19,
  677. minKey: -1,
  678. maxKey: 127
  679. });
  680. var BSONError = class extends Error {
  681. get bsonError() {
  682. return true;
  683. }
  684. get name() {
  685. return "BSONError";
  686. }
  687. constructor(message) {
  688. super(message);
  689. }
  690. static isBSONError(value) {
  691. return value != null && typeof value === "object" && "bsonError" in value && value.bsonError === true && "name" in value && "message" in value && "stack" in value;
  692. }
  693. };
  694. var BSONVersionError = class extends BSONError {
  695. get name() {
  696. return "BSONVersionError";
  697. }
  698. constructor() {
  699. super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.x.x`);
  700. }
  701. };
  702. var BSONRuntimeError = class extends BSONError {
  703. get name() {
  704. return "BSONRuntimeError";
  705. }
  706. constructor(message) {
  707. super(message);
  708. }
  709. };
  710. function nodejsMathRandomBytes(byteLength) {
  711. return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
  712. }
  713. var nodejsRandomBytes = (() => {
  714. try {
  715. return require("crypto").randomBytes;
  716. } catch {
  717. return nodejsMathRandomBytes;
  718. }
  719. })();
  720. var nodeJsByteUtils = {
  721. toLocalBufferType(potentialBuffer) {
  722. if (Buffer.isBuffer(potentialBuffer)) {
  723. return potentialBuffer;
  724. }
  725. if (ArrayBuffer.isView(potentialBuffer)) {
  726. return Buffer.from(potentialBuffer.buffer, potentialBuffer.byteOffset, potentialBuffer.byteLength);
  727. }
  728. const stringTag = (potentialBuffer == null ? void 0 : potentialBuffer[Symbol.toStringTag]) ?? Object.prototype.toString.call(potentialBuffer);
  729. if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
  730. return Buffer.from(potentialBuffer);
  731. }
  732. throw new BSONError(`Cannot create Buffer from ${String(potentialBuffer)}`);
  733. },
  734. allocate(size) {
  735. return Buffer.alloc(size);
  736. },
  737. equals(a, b) {
  738. return nodeJsByteUtils.toLocalBufferType(a).equals(b);
  739. },
  740. fromNumberArray(array) {
  741. return Buffer.from(array);
  742. },
  743. fromBase64(base64) {
  744. return Buffer.from(base64, "base64");
  745. },
  746. toBase64(buffer2) {
  747. return nodeJsByteUtils.toLocalBufferType(buffer2).toString("base64");
  748. },
  749. fromISO88591(codePoints) {
  750. return Buffer.from(codePoints, "binary");
  751. },
  752. toISO88591(buffer2) {
  753. return nodeJsByteUtils.toLocalBufferType(buffer2).toString("binary");
  754. },
  755. fromHex(hex) {
  756. return Buffer.from(hex, "hex");
  757. },
  758. toHex(buffer2) {
  759. return nodeJsByteUtils.toLocalBufferType(buffer2).toString("hex");
  760. },
  761. fromUTF8(text) {
  762. return Buffer.from(text, "utf8");
  763. },
  764. toUTF8(buffer2, start, end) {
  765. return nodeJsByteUtils.toLocalBufferType(buffer2).toString("utf8", start, end);
  766. },
  767. utf8ByteLength(input) {
  768. return Buffer.byteLength(input, "utf8");
  769. },
  770. encodeUTF8Into(buffer2, source, byteOffset) {
  771. return nodeJsByteUtils.toLocalBufferType(buffer2).write(source, byteOffset, void 0, "utf8");
  772. },
  773. randomBytes: nodejsRandomBytes
  774. };
  775. function isReactNative() {
  776. const { navigator: navigator2 } = globalThis;
  777. return typeof navigator2 === "object" && navigator2.product === "ReactNative";
  778. }
  779. function webMathRandomBytes(byteLength) {
  780. if (byteLength < 0) {
  781. throw new RangeError(`The argument 'byteLength' is invalid. Received ${byteLength}`);
  782. }
  783. return webByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
  784. }
  785. var webRandomBytes = (() => {
  786. var _a2;
  787. const { crypto } = globalThis;
  788. if (crypto != null && typeof crypto.getRandomValues === "function") {
  789. return (byteLength) => {
  790. return crypto.getRandomValues(webByteUtils.allocate(byteLength));
  791. };
  792. } else {
  793. if (isReactNative()) {
  794. const { console } = globalThis;
  795. (_a2 = console == null ? void 0 : console.warn) == null ? void 0 : _a2.call(console, "BSON: For React Native please polyfill crypto.getRandomValues, e.g. using: https://www.npmjs.com/package/react-native-get-random-values.");
  796. }
  797. return webMathRandomBytes;
  798. }
  799. })();
  800. var HEX_DIGIT = /(\d|[a-f])/i;
  801. var webByteUtils = {
  802. toLocalBufferType(potentialUint8array) {
  803. const stringTag = (potentialUint8array == null ? void 0 : potentialUint8array[Symbol.toStringTag]) ?? Object.prototype.toString.call(potentialUint8array);
  804. if (stringTag === "Uint8Array") {
  805. return potentialUint8array;
  806. }
  807. if (ArrayBuffer.isView(potentialUint8array)) {
  808. return new Uint8Array(potentialUint8array.buffer.slice(potentialUint8array.byteOffset, potentialUint8array.byteOffset + potentialUint8array.byteLength));
  809. }
  810. if (stringTag === "ArrayBuffer" || stringTag === "SharedArrayBuffer" || stringTag === "[object ArrayBuffer]" || stringTag === "[object SharedArrayBuffer]") {
  811. return new Uint8Array(potentialUint8array);
  812. }
  813. throw new BSONError(`Cannot make a Uint8Array from ${String(potentialUint8array)}`);
  814. },
  815. allocate(size) {
  816. if (typeof size !== "number") {
  817. throw new TypeError(`The "size" argument must be of type number. Received ${String(size)}`);
  818. }
  819. return new Uint8Array(size);
  820. },
  821. equals(a, b) {
  822. if (a.byteLength !== b.byteLength) {
  823. return false;
  824. }
  825. for (let i = 0; i < a.byteLength; i++) {
  826. if (a[i] !== b[i]) {
  827. return false;
  828. }
  829. }
  830. return true;
  831. },
  832. fromNumberArray(array) {
  833. return Uint8Array.from(array);
  834. },
  835. fromBase64(base64) {
  836. return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
  837. },
  838. toBase64(uint8array) {
  839. return btoa(webByteUtils.toISO88591(uint8array));
  840. },
  841. fromISO88591(codePoints) {
  842. return Uint8Array.from(codePoints, (c) => c.charCodeAt(0) & 255);
  843. },
  844. toISO88591(uint8array) {
  845. return Array.from(Uint16Array.from(uint8array), (b) => String.fromCharCode(b)).join("");
  846. },
  847. fromHex(hex) {
  848. const evenLengthHex = hex.length % 2 === 0 ? hex : hex.slice(0, hex.length - 1);
  849. const buffer2 = [];
  850. for (let i = 0; i < evenLengthHex.length; i += 2) {
  851. const firstDigit = evenLengthHex[i];
  852. const secondDigit = evenLengthHex[i + 1];
  853. if (!HEX_DIGIT.test(firstDigit)) {
  854. break;
  855. }
  856. if (!HEX_DIGIT.test(secondDigit)) {
  857. break;
  858. }
  859. const hexDigit = Number.parseInt(`${firstDigit}${secondDigit}`, 16);
  860. buffer2.push(hexDigit);
  861. }
  862. return Uint8Array.from(buffer2);
  863. },
  864. toHex(uint8array) {
  865. return Array.from(uint8array, (byte) => byte.toString(16).padStart(2, "0")).join("");
  866. },
  867. fromUTF8(text) {
  868. return new TextEncoder().encode(text);
  869. },
  870. toUTF8(uint8array, start, end) {
  871. return new TextDecoder("utf8", { fatal: false }).decode(uint8array.slice(start, end));
  872. },
  873. utf8ByteLength(input) {
  874. return webByteUtils.fromUTF8(input).byteLength;
  875. },
  876. encodeUTF8Into(buffer2, source, byteOffset) {
  877. const bytes = webByteUtils.fromUTF8(source);
  878. buffer2.set(bytes, byteOffset);
  879. return bytes.byteLength;
  880. },
  881. randomBytes: webRandomBytes
  882. };
  883. var _a;
  884. var hasGlobalBuffer = typeof Buffer === "function" && ((_a = Buffer.prototype) == null ? void 0 : _a._isBuffer) !== true;
  885. var ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
  886. var BSONDataView = class extends DataView {
  887. static fromUint8Array(input) {
  888. return new DataView(input.buffer, input.byteOffset, input.byteLength);
  889. }
  890. };
  891. var BSONValue = class {
  892. get [Symbol.for("@@mdb.bson.version")]() {
  893. return BSON_MAJOR_VERSION;
  894. }
  895. };
  896. var Binary = class _Binary extends BSONValue {
  897. get _bsontype() {
  898. return "Binary";
  899. }
  900. constructor(buffer2, subType) {
  901. super();
  902. if (!(buffer2 == null) && !(typeof buffer2 === "string") && !ArrayBuffer.isView(buffer2) && !(buffer2 instanceof ArrayBuffer) && !Array.isArray(buffer2)) {
  903. throw new BSONError("Binary can only be constructed from string, Buffer, TypedArray, or Array<number>");
  904. }
  905. this.sub_type = subType ?? _Binary.BSON_BINARY_SUBTYPE_DEFAULT;
  906. if (buffer2 == null) {
  907. this.buffer = ByteUtils.allocate(_Binary.BUFFER_SIZE);
  908. this.position = 0;
  909. } else {
  910. if (typeof buffer2 === "string") {
  911. this.buffer = ByteUtils.fromISO88591(buffer2);
  912. } else if (Array.isArray(buffer2)) {
  913. this.buffer = ByteUtils.fromNumberArray(buffer2);
  914. } else {
  915. this.buffer = ByteUtils.toLocalBufferType(buffer2);
  916. }
  917. this.position = this.buffer.byteLength;
  918. }
  919. }
  920. put(byteValue) {
  921. if (typeof byteValue === "string" && byteValue.length !== 1) {
  922. throw new BSONError("only accepts single character String");
  923. } else if (typeof byteValue !== "number" && byteValue.length !== 1)
  924. throw new BSONError("only accepts single character Uint8Array or Array");
  925. let decodedByte;
  926. if (typeof byteValue === "string") {
  927. decodedByte = byteValue.charCodeAt(0);
  928. } else if (typeof byteValue === "number") {
  929. decodedByte = byteValue;
  930. } else {
  931. decodedByte = byteValue[0];
  932. }
  933. if (decodedByte < 0 || decodedByte > 255) {
  934. throw new BSONError("only accepts number in a valid unsigned byte range 0-255");
  935. }
  936. if (this.buffer.byteLength > this.position) {
  937. this.buffer[this.position++] = decodedByte;
  938. } else {
  939. const newSpace = ByteUtils.allocate(_Binary.BUFFER_SIZE + this.buffer.length);
  940. newSpace.set(this.buffer, 0);
  941. this.buffer = newSpace;
  942. this.buffer[this.position++] = decodedByte;
  943. }
  944. }
  945. write(sequence, offset) {
  946. offset = typeof offset === "number" ? offset : this.position;
  947. if (this.buffer.byteLength < offset + sequence.length) {
  948. const newSpace = ByteUtils.allocate(this.buffer.byteLength + sequence.length);
  949. newSpace.set(this.buffer, 0);
  950. this.buffer = newSpace;
  951. }
  952. if (ArrayBuffer.isView(sequence)) {
  953. this.buffer.set(ByteUtils.toLocalBufferType(sequence), offset);
  954. this.position = offset + sequence.byteLength > this.position ? offset + sequence.length : this.position;
  955. } else if (typeof sequence === "string") {
  956. const bytes = ByteUtils.fromISO88591(sequence);
  957. this.buffer.set(bytes, offset);
  958. this.position = offset + sequence.length > this.position ? offset + sequence.length : this.position;
  959. }
  960. }
  961. read(position, length) {
  962. length = length && length > 0 ? length : this.position;
  963. return this.buffer.slice(position, position + length);
  964. }
  965. value(asRaw) {
  966. asRaw = !!asRaw;
  967. if (asRaw && this.buffer.length === this.position) {
  968. return this.buffer;
  969. }
  970. if (asRaw) {
  971. return this.buffer.slice(0, this.position);
  972. }
  973. return ByteUtils.toISO88591(this.buffer.subarray(0, this.position));
  974. }
  975. length() {
  976. return this.position;
  977. }
  978. toJSON() {
  979. return ByteUtils.toBase64(this.buffer);
  980. }
  981. toString(encoding) {
  982. if (encoding === "hex")
  983. return ByteUtils.toHex(this.buffer);
  984. if (encoding === "base64")
  985. return ByteUtils.toBase64(this.buffer);
  986. if (encoding === "utf8" || encoding === "utf-8")
  987. return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
  988. return ByteUtils.toUTF8(this.buffer, 0, this.buffer.byteLength);
  989. }
  990. toExtendedJSON(options) {
  991. options = options || {};
  992. const base64String = ByteUtils.toBase64(this.buffer);
  993. const subType = Number(this.sub_type).toString(16);
  994. if (options.legacy) {
  995. return {
  996. $binary: base64String,
  997. $type: subType.length === 1 ? "0" + subType : subType
  998. };
  999. }
  1000. return {
  1001. $binary: {
  1002. base64: base64String,
  1003. subType: subType.length === 1 ? "0" + subType : subType
  1004. }
  1005. };
  1006. }
  1007. toUUID() {
  1008. if (this.sub_type === _Binary.SUBTYPE_UUID) {
  1009. return new UUID(this.buffer.slice(0, this.position));
  1010. }
  1011. throw new BSONError(`Binary sub_type "${this.sub_type}" is not supported for converting to UUID. Only "${_Binary.SUBTYPE_UUID}" is currently supported.`);
  1012. }
  1013. static createFromHexString(hex, subType) {
  1014. return new _Binary(ByteUtils.fromHex(hex), subType);
  1015. }
  1016. static createFromBase64(base64, subType) {
  1017. return new _Binary(ByteUtils.fromBase64(base64), subType);
  1018. }
  1019. static fromExtendedJSON(doc, options) {
  1020. options = options || {};
  1021. let data;
  1022. let type;
  1023. if ("$binary" in doc) {
  1024. if (options.legacy && typeof doc.$binary === "string" && "$type" in doc) {
  1025. type = doc.$type ? parseInt(doc.$type, 16) : 0;
  1026. data = ByteUtils.fromBase64(doc.$binary);
  1027. } else {
  1028. if (typeof doc.$binary !== "string") {
  1029. type = doc.$binary.subType ? parseInt(doc.$binary.subType, 16) : 0;
  1030. data = ByteUtils.fromBase64(doc.$binary.base64);
  1031. }
  1032. }
  1033. } else if ("$uuid" in doc) {
  1034. type = 4;
  1035. data = UUID.bytesFromString(doc.$uuid);
  1036. }
  1037. if (!data) {
  1038. throw new BSONError(`Unexpected Binary Extended JSON format ${JSON.stringify(doc)}`);
  1039. }
  1040. return type === BSON_BINARY_SUBTYPE_UUID_NEW ? new UUID(data) : new _Binary(data, type);
  1041. }
  1042. [Symbol.for("nodejs.util.inspect.custom")]() {
  1043. return this.inspect();
  1044. }
  1045. inspect() {
  1046. const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
  1047. return `Binary.createFromBase64("${base64}", ${this.sub_type})`;
  1048. }
  1049. };
  1050. Binary.BSON_BINARY_SUBTYPE_DEFAULT = 0;
  1051. Binary.BUFFER_SIZE = 256;
  1052. Binary.SUBTYPE_DEFAULT = 0;
  1053. Binary.SUBTYPE_FUNCTION = 1;
  1054. Binary.SUBTYPE_BYTE_ARRAY = 2;
  1055. Binary.SUBTYPE_UUID_OLD = 3;
  1056. Binary.SUBTYPE_UUID = 4;
  1057. Binary.SUBTYPE_MD5 = 5;
  1058. Binary.SUBTYPE_ENCRYPTED = 6;
  1059. Binary.SUBTYPE_COLUMN = 7;
  1060. Binary.SUBTYPE_USER_DEFINED = 128;
  1061. var UUID_BYTE_LENGTH = 16;
  1062. var UUID_WITHOUT_DASHES = /^[0-9A-F]{32}$/i;
  1063. var UUID_WITH_DASHES = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
  1064. var UUID = class _UUID extends Binary {
  1065. constructor(input) {
  1066. let bytes;
  1067. if (input == null) {
  1068. bytes = _UUID.generate();
  1069. } else if (input instanceof _UUID) {
  1070. bytes = ByteUtils.toLocalBufferType(new Uint8Array(input.buffer));
  1071. } else if (ArrayBuffer.isView(input) && input.byteLength === UUID_BYTE_LENGTH) {
  1072. bytes = ByteUtils.toLocalBufferType(input);
  1073. } else if (typeof input === "string") {
  1074. bytes = _UUID.bytesFromString(input);
  1075. } else {
  1076. throw new BSONError("Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).");
  1077. }
  1078. super(bytes, BSON_BINARY_SUBTYPE_UUID_NEW);
  1079. }
  1080. get id() {
  1081. return this.buffer;
  1082. }
  1083. set id(value) {
  1084. this.buffer = value;
  1085. }
  1086. toHexString(includeDashes = true) {
  1087. if (includeDashes) {
  1088. return [
  1089. ByteUtils.toHex(this.buffer.subarray(0, 4)),
  1090. ByteUtils.toHex(this.buffer.subarray(4, 6)),
  1091. ByteUtils.toHex(this.buffer.subarray(6, 8)),
  1092. ByteUtils.toHex(this.buffer.subarray(8, 10)),
  1093. ByteUtils.toHex(this.buffer.subarray(10, 16))
  1094. ].join("-");
  1095. }
  1096. return ByteUtils.toHex(this.buffer);
  1097. }
  1098. toString(encoding) {
  1099. if (encoding === "hex")
  1100. return ByteUtils.toHex(this.id);
  1101. if (encoding === "base64")
  1102. return ByteUtils.toBase64(this.id);
  1103. return this.toHexString();
  1104. }
  1105. toJSON() {
  1106. return this.toHexString();
  1107. }
  1108. equals(otherId) {
  1109. if (!otherId) {
  1110. return false;
  1111. }
  1112. if (otherId instanceof _UUID) {
  1113. return ByteUtils.equals(otherId.id, this.id);
  1114. }
  1115. try {
  1116. return ByteUtils.equals(new _UUID(otherId).id, this.id);
  1117. } catch {
  1118. return false;
  1119. }
  1120. }
  1121. toBinary() {
  1122. return new Binary(this.id, Binary.SUBTYPE_UUID);
  1123. }
  1124. static generate() {
  1125. const bytes = ByteUtils.randomBytes(UUID_BYTE_LENGTH);
  1126. bytes[6] = bytes[6] & 15 | 64;
  1127. bytes[8] = bytes[8] & 63 | 128;
  1128. return bytes;
  1129. }
  1130. static isValid(input) {
  1131. if (!input) {
  1132. return false;
  1133. }
  1134. if (typeof input === "string") {
  1135. return _UUID.isValidUUIDString(input);
  1136. }
  1137. if (isUint8Array(input)) {
  1138. return input.byteLength === UUID_BYTE_LENGTH;
  1139. }
  1140. return input._bsontype === "Binary" && input.sub_type === this.SUBTYPE_UUID && input.buffer.byteLength === 16;
  1141. }
  1142. static createFromHexString(hexString) {
  1143. const buffer2 = _UUID.bytesFromString(hexString);
  1144. return new _UUID(buffer2);
  1145. }
  1146. static createFromBase64(base64) {
  1147. return new _UUID(ByteUtils.fromBase64(base64));
  1148. }
  1149. static bytesFromString(representation) {
  1150. if (!_UUID.isValidUUIDString(representation)) {
  1151. throw new BSONError("UUID string representation must be 32 hex digits or canonical hyphenated representation");
  1152. }
  1153. return ByteUtils.fromHex(representation.replace(/-/g, ""));
  1154. }
  1155. static isValidUUIDString(representation) {
  1156. return UUID_WITHOUT_DASHES.test(representation) || UUID_WITH_DASHES.test(representation);
  1157. }
  1158. [Symbol.for("nodejs.util.inspect.custom")]() {
  1159. return this.inspect();
  1160. }
  1161. inspect() {
  1162. return `new UUID("${this.toHexString()}")`;
  1163. }
  1164. };
  1165. UUID.cacheHexString = false;
  1166. var Code = class _Code extends BSONValue {
  1167. get _bsontype() {
  1168. return "Code";
  1169. }
  1170. constructor(code, scope) {
  1171. super();
  1172. this.code = code.toString();
  1173. this.scope = scope ?? null;
  1174. }
  1175. toJSON() {
  1176. if (this.scope != null) {
  1177. return { code: this.code, scope: this.scope };
  1178. }
  1179. return { code: this.code };
  1180. }
  1181. toExtendedJSON() {
  1182. if (this.scope) {
  1183. return { $code: this.code, $scope: this.scope };
  1184. }
  1185. return { $code: this.code };
  1186. }
  1187. static fromExtendedJSON(doc) {
  1188. return new _Code(doc.$code, doc.$scope);
  1189. }
  1190. [Symbol.for("nodejs.util.inspect.custom")]() {
  1191. return this.inspect();
  1192. }
  1193. inspect() {
  1194. const codeJson = this.toJSON();
  1195. return `new Code("${String(codeJson.code)}"${codeJson.scope != null ? `, ${JSON.stringify(codeJson.scope)}` : ""})`;
  1196. }
  1197. };
  1198. function isDBRefLike(value) {
  1199. return value != null && typeof value === "object" && "$id" in value && value.$id != null && "$ref" in value && typeof value.$ref === "string" && (!("$db" in value) || "$db" in value && typeof value.$db === "string");
  1200. }
  1201. var DBRef = class _DBRef extends BSONValue {
  1202. get _bsontype() {
  1203. return "DBRef";
  1204. }
  1205. constructor(collection, oid, db, fields) {
  1206. super();
  1207. const parts = collection.split(".");
  1208. if (parts.length === 2) {
  1209. db = parts.shift();
  1210. collection = parts.shift();
  1211. }
  1212. this.collection = collection;
  1213. this.oid = oid;
  1214. this.db = db;
  1215. this.fields = fields || {};
  1216. }
  1217. get namespace() {
  1218. return this.collection;
  1219. }
  1220. set namespace(value) {
  1221. this.collection = value;
  1222. }
  1223. toJSON() {
  1224. const o = Object.assign({
  1225. $ref: this.collection,
  1226. $id: this.oid
  1227. }, this.fields);
  1228. if (this.db != null)
  1229. o.$db = this.db;
  1230. return o;
  1231. }
  1232. toExtendedJSON(options) {
  1233. options = options || {};
  1234. let o = {
  1235. $ref: this.collection,
  1236. $id: this.oid
  1237. };
  1238. if (options.legacy) {
  1239. return o;
  1240. }
  1241. if (this.db)
  1242. o.$db = this.db;
  1243. o = Object.assign(o, this.fields);
  1244. return o;
  1245. }
  1246. static fromExtendedJSON(doc) {
  1247. const copy = Object.assign({}, doc);
  1248. delete copy.$ref;
  1249. delete copy.$id;
  1250. delete copy.$db;
  1251. return new _DBRef(doc.$ref, doc.$id, doc.$db, copy);
  1252. }
  1253. [Symbol.for("nodejs.util.inspect.custom")]() {
  1254. return this.inspect();
  1255. }
  1256. inspect() {
  1257. const oid = this.oid === void 0 || this.oid.toString === void 0 ? this.oid : this.oid.toString();
  1258. return `new DBRef("${this.namespace}", new ObjectId("${String(oid)}")${this.db ? `, "${this.db}"` : ""})`;
  1259. }
  1260. };
  1261. var wasm = void 0;
  1262. try {
  1263. wasm = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11])), {}).exports;
  1264. } catch {
  1265. }
  1266. var TWO_PWR_16_DBL = 1 << 16;
  1267. var TWO_PWR_24_DBL = 1 << 24;
  1268. var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
  1269. var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
  1270. var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
  1271. var INT_CACHE = {};
  1272. var UINT_CACHE = {};
  1273. var MAX_INT64_STRING_LENGTH = 20;
  1274. var DECIMAL_REG_EX = /^(\+?0|(\+|-)?[1-9][0-9]*)$/;
  1275. var Long = class _Long extends BSONValue {
  1276. get _bsontype() {
  1277. return "Long";
  1278. }
  1279. get __isLong__() {
  1280. return true;
  1281. }
  1282. constructor(low = 0, high, unsigned) {
  1283. super();
  1284. if (typeof low === "bigint") {
  1285. Object.assign(this, _Long.fromBigInt(low, !!high));
  1286. } else if (typeof low === "string") {
  1287. Object.assign(this, _Long.fromString(low, !!high));
  1288. } else {
  1289. this.low = low | 0;
  1290. this.high = high | 0;
  1291. this.unsigned = !!unsigned;
  1292. }
  1293. }
  1294. static fromBits(lowBits, highBits, unsigned) {
  1295. return new _Long(lowBits, highBits, unsigned);
  1296. }
  1297. static fromInt(value, unsigned) {
  1298. let obj, cachedObj, cache;
  1299. if (unsigned) {
  1300. value >>>= 0;
  1301. if (cache = 0 <= value && value < 256) {
  1302. cachedObj = UINT_CACHE[value];
  1303. if (cachedObj)
  1304. return cachedObj;
  1305. }
  1306. obj = _Long.fromBits(value, (value | 0) < 0 ? -1 : 0, true);
  1307. if (cache)
  1308. UINT_CACHE[value] = obj;
  1309. return obj;
  1310. } else {
  1311. value |= 0;
  1312. if (cache = -128 <= value && value < 128) {
  1313. cachedObj = INT_CACHE[value];
  1314. if (cachedObj)
  1315. return cachedObj;
  1316. }
  1317. obj = _Long.fromBits(value, value < 0 ? -1 : 0, false);
  1318. if (cache)
  1319. INT_CACHE[value] = obj;
  1320. return obj;
  1321. }
  1322. }
  1323. static fromNumber(value, unsigned) {
  1324. if (isNaN(value))
  1325. return unsigned ? _Long.UZERO : _Long.ZERO;
  1326. if (unsigned) {
  1327. if (value < 0)
  1328. return _Long.UZERO;
  1329. if (value >= TWO_PWR_64_DBL)
  1330. return _Long.MAX_UNSIGNED_VALUE;
  1331. } else {
  1332. if (value <= -TWO_PWR_63_DBL)
  1333. return _Long.MIN_VALUE;
  1334. if (value + 1 >= TWO_PWR_63_DBL)
  1335. return _Long.MAX_VALUE;
  1336. }
  1337. if (value < 0)
  1338. return _Long.fromNumber(-value, unsigned).neg();
  1339. return _Long.fromBits(value % TWO_PWR_32_DBL | 0, value / TWO_PWR_32_DBL | 0, unsigned);
  1340. }
  1341. static fromBigInt(value, unsigned) {
  1342. return _Long.fromString(value.toString(), unsigned);
  1343. }
  1344. static fromString(str, unsigned, radix) {
  1345. if (str.length === 0)
  1346. throw new BSONError("empty string");
  1347. if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
  1348. return _Long.ZERO;
  1349. if (typeof unsigned === "number") {
  1350. radix = unsigned, unsigned = false;
  1351. } else {
  1352. unsigned = !!unsigned;
  1353. }
  1354. radix = radix || 10;
  1355. if (radix < 2 || 36 < radix)
  1356. throw new BSONError("radix");
  1357. let p;
  1358. if ((p = str.indexOf("-")) > 0)
  1359. throw new BSONError("interior hyphen");
  1360. else if (p === 0) {
  1361. return _Long.fromString(str.substring(1), unsigned, radix).neg();
  1362. }
  1363. const radixToPower = _Long.fromNumber(Math.pow(radix, 8));
  1364. let result = _Long.ZERO;
  1365. for (let i = 0; i < str.length; i += 8) {
  1366. const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
  1367. if (size < 8) {
  1368. const power = _Long.fromNumber(Math.pow(radix, size));
  1369. result = result.mul(power).add(_Long.fromNumber(value));
  1370. } else {
  1371. result = result.mul(radixToPower);
  1372. result = result.add(_Long.fromNumber(value));
  1373. }
  1374. }
  1375. result.unsigned = unsigned;
  1376. return result;
  1377. }
  1378. static fromBytes(bytes, unsigned, le) {
  1379. return le ? _Long.fromBytesLE(bytes, unsigned) : _Long.fromBytesBE(bytes, unsigned);
  1380. }
  1381. static fromBytesLE(bytes, unsigned) {
  1382. return new _Long(bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24, bytes[4] | bytes[5] << 8 | bytes[6] << 16 | bytes[7] << 24, unsigned);
  1383. }
  1384. static fromBytesBE(bytes, unsigned) {
  1385. return new _Long(bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7], bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], unsigned);
  1386. }
  1387. static isLong(value) {
  1388. return value != null && typeof value === "object" && "__isLong__" in value && value.__isLong__ === true;
  1389. }
  1390. static fromValue(val, unsigned) {
  1391. if (typeof val === "number")
  1392. return _Long.fromNumber(val, unsigned);
  1393. if (typeof val === "string")
  1394. return _Long.fromString(val, unsigned);
  1395. return _Long.fromBits(val.low, val.high, typeof unsigned === "boolean" ? unsigned : val.unsigned);
  1396. }
  1397. add(addend) {
  1398. if (!_Long.isLong(addend))
  1399. addend = _Long.fromValue(addend);
  1400. const a48 = this.high >>> 16;
  1401. const a32 = this.high & 65535;
  1402. const a16 = this.low >>> 16;
  1403. const a00 = this.low & 65535;
  1404. const b48 = addend.high >>> 16;
  1405. const b32 = addend.high & 65535;
  1406. const b16 = addend.low >>> 16;
  1407. const b00 = addend.low & 65535;
  1408. let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
  1409. c00 += a00 + b00;
  1410. c16 += c00 >>> 16;
  1411. c00 &= 65535;
  1412. c16 += a16 + b16;
  1413. c32 += c16 >>> 16;
  1414. c16 &= 65535;
  1415. c32 += a32 + b32;
  1416. c48 += c32 >>> 16;
  1417. c32 &= 65535;
  1418. c48 += a48 + b48;
  1419. c48 &= 65535;
  1420. return _Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  1421. }
  1422. and(other) {
  1423. if (!_Long.isLong(other))
  1424. other = _Long.fromValue(other);
  1425. return _Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
  1426. }
  1427. compare(other) {
  1428. if (!_Long.isLong(other))
  1429. other = _Long.fromValue(other);
  1430. if (this.eq(other))
  1431. return 0;
  1432. const thisNeg = this.isNegative(), otherNeg = other.isNegative();
  1433. if (thisNeg && !otherNeg)
  1434. return -1;
  1435. if (!thisNeg && otherNeg)
  1436. return 1;
  1437. if (!this.unsigned)
  1438. return this.sub(other).isNegative() ? -1 : 1;
  1439. return other.high >>> 0 > this.high >>> 0 || other.high === this.high && other.low >>> 0 > this.low >>> 0 ? -1 : 1;
  1440. }
  1441. comp(other) {
  1442. return this.compare(other);
  1443. }
  1444. divide(divisor) {
  1445. if (!_Long.isLong(divisor))
  1446. divisor = _Long.fromValue(divisor);
  1447. if (divisor.isZero())
  1448. throw new BSONError("division by zero");
  1449. if (wasm) {
  1450. if (!this.unsigned && this.high === -2147483648 && divisor.low === -1 && divisor.high === -1) {
  1451. return this;
  1452. }
  1453. const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
  1454. return _Long.fromBits(low, wasm.get_high(), this.unsigned);
  1455. }
  1456. if (this.isZero())
  1457. return this.unsigned ? _Long.UZERO : _Long.ZERO;
  1458. let approx, rem, res;
  1459. if (!this.unsigned) {
  1460. if (this.eq(_Long.MIN_VALUE)) {
  1461. if (divisor.eq(_Long.ONE) || divisor.eq(_Long.NEG_ONE))
  1462. return _Long.MIN_VALUE;
  1463. else if (divisor.eq(_Long.MIN_VALUE))
  1464. return _Long.ONE;
  1465. else {
  1466. const halfThis = this.shr(1);
  1467. approx = halfThis.div(divisor).shl(1);
  1468. if (approx.eq(_Long.ZERO)) {
  1469. return divisor.isNegative() ? _Long.ONE : _Long.NEG_ONE;
  1470. } else {
  1471. rem = this.sub(divisor.mul(approx));
  1472. res = approx.add(rem.div(divisor));
  1473. return res;
  1474. }
  1475. }
  1476. } else if (divisor.eq(_Long.MIN_VALUE))
  1477. return this.unsigned ? _Long.UZERO : _Long.ZERO;
  1478. if (this.isNegative()) {
  1479. if (divisor.isNegative())
  1480. return this.neg().div(divisor.neg());
  1481. return this.neg().div(divisor).neg();
  1482. } else if (divisor.isNegative())
  1483. return this.div(divisor.neg()).neg();
  1484. res = _Long.ZERO;
  1485. } else {
  1486. if (!divisor.unsigned)
  1487. divisor = divisor.toUnsigned();
  1488. if (divisor.gt(this))
  1489. return _Long.UZERO;
  1490. if (divisor.gt(this.shru(1)))
  1491. return _Long.UONE;
  1492. res = _Long.UZERO;
  1493. }
  1494. rem = this;
  1495. while (rem.gte(divisor)) {
  1496. approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
  1497. const log2 = Math.ceil(Math.log(approx) / Math.LN2);
  1498. const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
  1499. let approxRes = _Long.fromNumber(approx);
  1500. let approxRem = approxRes.mul(divisor);
  1501. while (approxRem.isNegative() || approxRem.gt(rem)) {
  1502. approx -= delta;
  1503. approxRes = _Long.fromNumber(approx, this.unsigned);
  1504. approxRem = approxRes.mul(divisor);
  1505. }
  1506. if (approxRes.isZero())
  1507. approxRes = _Long.ONE;
  1508. res = res.add(approxRes);
  1509. rem = rem.sub(approxRem);
  1510. }
  1511. return res;
  1512. }
  1513. div(divisor) {
  1514. return this.divide(divisor);
  1515. }
  1516. equals(other) {
  1517. if (!_Long.isLong(other))
  1518. other = _Long.fromValue(other);
  1519. if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
  1520. return false;
  1521. return this.high === other.high && this.low === other.low;
  1522. }
  1523. eq(other) {
  1524. return this.equals(other);
  1525. }
  1526. getHighBits() {
  1527. return this.high;
  1528. }
  1529. getHighBitsUnsigned() {
  1530. return this.high >>> 0;
  1531. }
  1532. getLowBits() {
  1533. return this.low;
  1534. }
  1535. getLowBitsUnsigned() {
  1536. return this.low >>> 0;
  1537. }
  1538. getNumBitsAbs() {
  1539. if (this.isNegative()) {
  1540. return this.eq(_Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
  1541. }
  1542. const val = this.high !== 0 ? this.high : this.low;
  1543. let bit;
  1544. for (bit = 31; bit > 0; bit--)
  1545. if ((val & 1 << bit) !== 0)
  1546. break;
  1547. return this.high !== 0 ? bit + 33 : bit + 1;
  1548. }
  1549. greaterThan(other) {
  1550. return this.comp(other) > 0;
  1551. }
  1552. gt(other) {
  1553. return this.greaterThan(other);
  1554. }
  1555. greaterThanOrEqual(other) {
  1556. return this.comp(other) >= 0;
  1557. }
  1558. gte(other) {
  1559. return this.greaterThanOrEqual(other);
  1560. }
  1561. ge(other) {
  1562. return this.greaterThanOrEqual(other);
  1563. }
  1564. isEven() {
  1565. return (this.low & 1) === 0;
  1566. }
  1567. isNegative() {
  1568. return !this.unsigned && this.high < 0;
  1569. }
  1570. isOdd() {
  1571. return (this.low & 1) === 1;
  1572. }
  1573. isPositive() {
  1574. return this.unsigned || this.high >= 0;
  1575. }
  1576. isZero() {
  1577. return this.high === 0 && this.low === 0;
  1578. }
  1579. lessThan(other) {
  1580. return this.comp(other) < 0;
  1581. }
  1582. lt(other) {
  1583. return this.lessThan(other);
  1584. }
  1585. lessThanOrEqual(other) {
  1586. return this.comp(other) <= 0;
  1587. }
  1588. lte(other) {
  1589. return this.lessThanOrEqual(other);
  1590. }
  1591. modulo(divisor) {
  1592. if (!_Long.isLong(divisor))
  1593. divisor = _Long.fromValue(divisor);
  1594. if (wasm) {
  1595. const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
  1596. return _Long.fromBits(low, wasm.get_high(), this.unsigned);
  1597. }
  1598. return this.sub(this.div(divisor).mul(divisor));
  1599. }
  1600. mod(divisor) {
  1601. return this.modulo(divisor);
  1602. }
  1603. rem(divisor) {
  1604. return this.modulo(divisor);
  1605. }
  1606. multiply(multiplier) {
  1607. if (this.isZero())
  1608. return _Long.ZERO;
  1609. if (!_Long.isLong(multiplier))
  1610. multiplier = _Long.fromValue(multiplier);
  1611. if (wasm) {
  1612. const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
  1613. return _Long.fromBits(low, wasm.get_high(), this.unsigned);
  1614. }
  1615. if (multiplier.isZero())
  1616. return _Long.ZERO;
  1617. if (this.eq(_Long.MIN_VALUE))
  1618. return multiplier.isOdd() ? _Long.MIN_VALUE : _Long.ZERO;
  1619. if (multiplier.eq(_Long.MIN_VALUE))
  1620. return this.isOdd() ? _Long.MIN_VALUE : _Long.ZERO;
  1621. if (this.isNegative()) {
  1622. if (multiplier.isNegative())
  1623. return this.neg().mul(multiplier.neg());
  1624. else
  1625. return this.neg().mul(multiplier).neg();
  1626. } else if (multiplier.isNegative())
  1627. return this.mul(multiplier.neg()).neg();
  1628. if (this.lt(_Long.TWO_PWR_24) && multiplier.lt(_Long.TWO_PWR_24))
  1629. return _Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
  1630. const a48 = this.high >>> 16;
  1631. const a32 = this.high & 65535;
  1632. const a16 = this.low >>> 16;
  1633. const a00 = this.low & 65535;
  1634. const b48 = multiplier.high >>> 16;
  1635. const b32 = multiplier.high & 65535;
  1636. const b16 = multiplier.low >>> 16;
  1637. const b00 = multiplier.low & 65535;
  1638. let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
  1639. c00 += a00 * b00;
  1640. c16 += c00 >>> 16;
  1641. c00 &= 65535;
  1642. c16 += a16 * b00;
  1643. c32 += c16 >>> 16;
  1644. c16 &= 65535;
  1645. c16 += a00 * b16;
  1646. c32 += c16 >>> 16;
  1647. c16 &= 65535;
  1648. c32 += a32 * b00;
  1649. c48 += c32 >>> 16;
  1650. c32 &= 65535;
  1651. c32 += a16 * b16;
  1652. c48 += c32 >>> 16;
  1653. c32 &= 65535;
  1654. c32 += a00 * b32;
  1655. c48 += c32 >>> 16;
  1656. c32 &= 65535;
  1657. c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
  1658. c48 &= 65535;
  1659. return _Long.fromBits(c16 << 16 | c00, c48 << 16 | c32, this.unsigned);
  1660. }
  1661. mul(multiplier) {
  1662. return this.multiply(multiplier);
  1663. }
  1664. negate() {
  1665. if (!this.unsigned && this.eq(_Long.MIN_VALUE))
  1666. return _Long.MIN_VALUE;
  1667. return this.not().add(_Long.ONE);
  1668. }
  1669. neg() {
  1670. return this.negate();
  1671. }
  1672. not() {
  1673. return _Long.fromBits(~this.low, ~this.high, this.unsigned);
  1674. }
  1675. notEquals(other) {
  1676. return !this.equals(other);
  1677. }
  1678. neq(other) {
  1679. return this.notEquals(other);
  1680. }
  1681. ne(other) {
  1682. return this.notEquals(other);
  1683. }
  1684. or(other) {
  1685. if (!_Long.isLong(other))
  1686. other = _Long.fromValue(other);
  1687. return _Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
  1688. }
  1689. shiftLeft(numBits) {
  1690. if (_Long.isLong(numBits))
  1691. numBits = numBits.toInt();
  1692. if ((numBits &= 63) === 0)
  1693. return this;
  1694. else if (numBits < 32)
  1695. return _Long.fromBits(this.low << numBits, this.high << numBits | this.low >>> 32 - numBits, this.unsigned);
  1696. else
  1697. return _Long.fromBits(0, this.low << numBits - 32, this.unsigned);
  1698. }
  1699. shl(numBits) {
  1700. return this.shiftLeft(numBits);
  1701. }
  1702. shiftRight(numBits) {
  1703. if (_Long.isLong(numBits))
  1704. numBits = numBits.toInt();
  1705. if ((numBits &= 63) === 0)
  1706. return this;
  1707. else if (numBits < 32)
  1708. return _Long.fromBits(this.low >>> numBits | this.high << 32 - numBits, this.high >> numBits, this.unsigned);
  1709. else
  1710. return _Long.fromBits(this.high >> numBits - 32, this.high >= 0 ? 0 : -1, this.unsigned);
  1711. }
  1712. shr(numBits) {
  1713. return this.shiftRight(numBits);
  1714. }
  1715. shiftRightUnsigned(numBits) {
  1716. if (_Long.isLong(numBits))
  1717. numBits = numBits.toInt();
  1718. numBits &= 63;
  1719. if (numBits === 0)
  1720. return this;
  1721. else {
  1722. const high = this.high;
  1723. if (numBits < 32) {
  1724. const low = this.low;
  1725. return _Long.fromBits(low >>> numBits | high << 32 - numBits, high >>> numBits, this.unsigned);
  1726. } else if (numBits === 32)
  1727. return _Long.fromBits(high, 0, this.unsigned);
  1728. else
  1729. return _Long.fromBits(high >>> numBits - 32, 0, this.unsigned);
  1730. }
  1731. }
  1732. shr_u(numBits) {
  1733. return this.shiftRightUnsigned(numBits);
  1734. }
  1735. shru(numBits) {
  1736. return this.shiftRightUnsigned(numBits);
  1737. }
  1738. subtract(subtrahend) {
  1739. if (!_Long.isLong(subtrahend))
  1740. subtrahend = _Long.fromValue(subtrahend);
  1741. return this.add(subtrahend.neg());
  1742. }
  1743. sub(subtrahend) {
  1744. return this.subtract(subtrahend);
  1745. }
  1746. toInt() {
  1747. return this.unsigned ? this.low >>> 0 : this.low;
  1748. }
  1749. toNumber() {
  1750. if (this.unsigned)
  1751. return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
  1752. return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
  1753. }
  1754. toBigInt() {
  1755. return BigInt(this.toString());
  1756. }
  1757. toBytes(le) {
  1758. return le ? this.toBytesLE() : this.toBytesBE();
  1759. }
  1760. toBytesLE() {
  1761. const hi = this.high, lo = this.low;
  1762. return [
  1763. lo & 255,
  1764. lo >>> 8 & 255,
  1765. lo >>> 16 & 255,
  1766. lo >>> 24,
  1767. hi & 255,
  1768. hi >>> 8 & 255,
  1769. hi >>> 16 & 255,
  1770. hi >>> 24
  1771. ];
  1772. }
  1773. toBytesBE() {
  1774. const hi = this.high, lo = this.low;
  1775. return [
  1776. hi >>> 24,
  1777. hi >>> 16 & 255,
  1778. hi >>> 8 & 255,
  1779. hi & 255,
  1780. lo >>> 24,
  1781. lo >>> 16 & 255,
  1782. lo >>> 8 & 255,
  1783. lo & 255
  1784. ];
  1785. }
  1786. toSigned() {
  1787. if (!this.unsigned)
  1788. return this;
  1789. return _Long.fromBits(this.low, this.high, false);
  1790. }
  1791. toString(radix) {
  1792. radix = radix || 10;
  1793. if (radix < 2 || 36 < radix)
  1794. throw new BSONError("radix");
  1795. if (this.isZero())
  1796. return "0";
  1797. if (this.isNegative()) {
  1798. if (this.eq(_Long.MIN_VALUE)) {
  1799. const radixLong = _Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
  1800. return div.toString(radix) + rem1.toInt().toString(radix);
  1801. } else
  1802. return "-" + this.neg().toString(radix);
  1803. }
  1804. const radixToPower = _Long.fromNumber(Math.pow(radix, 6), this.unsigned);
  1805. let rem = this;
  1806. let result = "";
  1807. while (true) {
  1808. const remDiv = rem.div(radixToPower);
  1809. const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
  1810. let digits = intval.toString(radix);
  1811. rem = remDiv;
  1812. if (rem.isZero()) {
  1813. return digits + result;
  1814. } else {
  1815. while (digits.length < 6)
  1816. digits = "0" + digits;
  1817. result = "" + digits + result;
  1818. }
  1819. }
  1820. }
  1821. toUnsigned() {
  1822. if (this.unsigned)
  1823. return this;
  1824. return _Long.fromBits(this.low, this.high, true);
  1825. }
  1826. xor(other) {
  1827. if (!_Long.isLong(other))
  1828. other = _Long.fromValue(other);
  1829. return _Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
  1830. }
  1831. eqz() {
  1832. return this.isZero();
  1833. }
  1834. le(other) {
  1835. return this.lessThanOrEqual(other);
  1836. }
  1837. toExtendedJSON(options) {
  1838. if (options && options.relaxed)
  1839. return this.toNumber();
  1840. return { $numberLong: this.toString() };
  1841. }
  1842. static fromExtendedJSON(doc, options) {
  1843. const { useBigInt64 = false, relaxed = true } = { ...options };
  1844. if (doc.$numberLong.length > MAX_INT64_STRING_LENGTH) {
  1845. throw new BSONError("$numberLong string is too long");
  1846. }
  1847. if (!DECIMAL_REG_EX.test(doc.$numberLong)) {
  1848. throw new BSONError(`$numberLong string "${doc.$numberLong}" is in an invalid format`);
  1849. }
  1850. if (useBigInt64) {
  1851. const bigIntResult = BigInt(doc.$numberLong);
  1852. return BigInt.asIntN(64, bigIntResult);
  1853. }
  1854. const longResult = _Long.fromString(doc.$numberLong);
  1855. if (relaxed) {
  1856. return longResult.toNumber();
  1857. }
  1858. return longResult;
  1859. }
  1860. [Symbol.for("nodejs.util.inspect.custom")]() {
  1861. return this.inspect();
  1862. }
  1863. inspect() {
  1864. return `new Long("${this.toString()}"${this.unsigned ? ", true" : ""})`;
  1865. }
  1866. };
  1867. Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
  1868. Long.MAX_UNSIGNED_VALUE = Long.fromBits(4294967295 | 0, 4294967295 | 0, true);
  1869. Long.ZERO = Long.fromInt(0);
  1870. Long.UZERO = Long.fromInt(0, true);
  1871. Long.ONE = Long.fromInt(1);
  1872. Long.UONE = Long.fromInt(1, true);
  1873. Long.NEG_ONE = Long.fromInt(-1);
  1874. Long.MAX_VALUE = Long.fromBits(4294967295 | 0, 2147483647 | 0, false);
  1875. Long.MIN_VALUE = Long.fromBits(0, 2147483648 | 0, false);
  1876. var PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
  1877. var PARSE_INF_REGEXP = /^(\+|-)?(Infinity|inf)$/i;
  1878. var PARSE_NAN_REGEXP = /^(\+|-)?NaN$/i;
  1879. var EXPONENT_MAX = 6111;
  1880. var EXPONENT_MIN = -6176;
  1881. var EXPONENT_BIAS = 6176;
  1882. var MAX_DIGITS = 34;
  1883. var NAN_BUFFER = ByteUtils.fromNumberArray([
  1884. 124,
  1885. 0,
  1886. 0,
  1887. 0,
  1888. 0,
  1889. 0,
  1890. 0,
  1891. 0,
  1892. 0,
  1893. 0,
  1894. 0,
  1895. 0,
  1896. 0,
  1897. 0,
  1898. 0,
  1899. 0
  1900. ].reverse());
  1901. var INF_NEGATIVE_BUFFER = ByteUtils.fromNumberArray([
  1902. 248,
  1903. 0,
  1904. 0,
  1905. 0,
  1906. 0,
  1907. 0,
  1908. 0,
  1909. 0,
  1910. 0,
  1911. 0,
  1912. 0,
  1913. 0,
  1914. 0,
  1915. 0,
  1916. 0,
  1917. 0
  1918. ].reverse());
  1919. var INF_POSITIVE_BUFFER = ByteUtils.fromNumberArray([
  1920. 120,
  1921. 0,
  1922. 0,
  1923. 0,
  1924. 0,
  1925. 0,
  1926. 0,
  1927. 0,
  1928. 0,
  1929. 0,
  1930. 0,
  1931. 0,
  1932. 0,
  1933. 0,
  1934. 0,
  1935. 0
  1936. ].reverse());
  1937. var EXPONENT_REGEX = /^([-+])?(\d+)?$/;
  1938. var COMBINATION_MASK = 31;
  1939. var EXPONENT_MASK = 16383;
  1940. var COMBINATION_INFINITY = 30;
  1941. var COMBINATION_NAN = 31;
  1942. function isDigit(value) {
  1943. return !isNaN(parseInt(value, 10));
  1944. }
  1945. function divideu128(value) {
  1946. const DIVISOR = Long.fromNumber(1e3 * 1e3 * 1e3);
  1947. let _rem = Long.fromNumber(0);
  1948. if (!value.parts[0] && !value.parts[1] && !value.parts[2] && !value.parts[3]) {
  1949. return { quotient: value, rem: _rem };
  1950. }
  1951. for (let i = 0; i <= 3; i++) {
  1952. _rem = _rem.shiftLeft(32);
  1953. _rem = _rem.add(new Long(value.parts[i], 0));
  1954. value.parts[i] = _rem.div(DIVISOR).low;
  1955. _rem = _rem.modulo(DIVISOR);
  1956. }
  1957. return { quotient: value, rem: _rem };
  1958. }
  1959. function multiply64x2(left, right) {
  1960. if (!left && !right) {
  1961. return { high: Long.fromNumber(0), low: Long.fromNumber(0) };
  1962. }
  1963. const leftHigh = left.shiftRightUnsigned(32);
  1964. const leftLow = new Long(left.getLowBits(), 0);
  1965. const rightHigh = right.shiftRightUnsigned(32);
  1966. const rightLow = new Long(right.getLowBits(), 0);
  1967. let productHigh = leftHigh.multiply(rightHigh);
  1968. let productMid = leftHigh.multiply(rightLow);
  1969. const productMid2 = leftLow.multiply(rightHigh);
  1970. let productLow = leftLow.multiply(rightLow);
  1971. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  1972. productMid = new Long(productMid.getLowBits(), 0).add(productMid2).add(productLow.shiftRightUnsigned(32));
  1973. productHigh = productHigh.add(productMid.shiftRightUnsigned(32));
  1974. productLow = productMid.shiftLeft(32).add(new Long(productLow.getLowBits(), 0));
  1975. return { high: productHigh, low: productLow };
  1976. }
  1977. function lessThan(left, right) {
  1978. const uhleft = left.high >>> 0;
  1979. const uhright = right.high >>> 0;
  1980. if (uhleft < uhright) {
  1981. return true;
  1982. } else if (uhleft === uhright) {
  1983. const ulleft = left.low >>> 0;
  1984. const ulright = right.low >>> 0;
  1985. if (ulleft < ulright)
  1986. return true;
  1987. }
  1988. return false;
  1989. }
  1990. function invalidErr(string, message) {
  1991. throw new BSONError(`"${string}" is not a valid Decimal128 string - ${message}`);
  1992. }
  1993. var Decimal128 = class _Decimal128 extends BSONValue {
  1994. get _bsontype() {
  1995. return "Decimal128";
  1996. }
  1997. constructor(bytes) {
  1998. super();
  1999. if (typeof bytes === "string") {
  2000. this.bytes = _Decimal128.fromString(bytes).bytes;
  2001. } else if (isUint8Array(bytes)) {
  2002. if (bytes.byteLength !== 16) {
  2003. throw new BSONError("Decimal128 must take a Buffer of 16 bytes");
  2004. }
  2005. this.bytes = bytes;
  2006. } else {
  2007. throw new BSONError("Decimal128 must take a Buffer or string");
  2008. }
  2009. }
  2010. static fromString(representation) {
  2011. return _Decimal128._fromString(representation, { allowRounding: false });
  2012. }
  2013. static fromStringWithRounding(representation) {
  2014. return _Decimal128._fromString(representation, { allowRounding: true });
  2015. }
  2016. static _fromString(representation, options) {
  2017. let isNegative = false;
  2018. let sawSign = false;
  2019. let sawRadix = false;
  2020. let foundNonZero = false;
  2021. let significantDigits = 0;
  2022. let nDigitsRead = 0;
  2023. let nDigits = 0;
  2024. let radixPosition = 0;
  2025. let firstNonZero = 0;
  2026. const digits = [0];
  2027. let nDigitsStored = 0;
  2028. let digitsInsert = 0;
  2029. let lastDigit = 0;
  2030. let exponent = 0;
  2031. let significandHigh = new Long(0, 0);
  2032. let significandLow = new Long(0, 0);
  2033. let biasedExponent = 0;
  2034. let index = 0;
  2035. if (representation.length >= 7e3) {
  2036. throw new BSONError("" + representation + " not a valid Decimal128 string");
  2037. }
  2038. const stringMatch = representation.match(PARSE_STRING_REGEXP);
  2039. const infMatch = representation.match(PARSE_INF_REGEXP);
  2040. const nanMatch = representation.match(PARSE_NAN_REGEXP);
  2041. if (!stringMatch && !infMatch && !nanMatch || representation.length === 0) {
  2042. throw new BSONError("" + representation + " not a valid Decimal128 string");
  2043. }
  2044. if (stringMatch) {
  2045. const unsignedNumber = stringMatch[2];
  2046. const e = stringMatch[4];
  2047. const expSign = stringMatch[5];
  2048. const expNumber = stringMatch[6];
  2049. if (e && expNumber === void 0)
  2050. invalidErr(representation, "missing exponent power");
  2051. if (e && unsignedNumber === void 0)
  2052. invalidErr(representation, "missing exponent base");
  2053. if (e === void 0 && (expSign || expNumber)) {
  2054. invalidErr(representation, "missing e before exponent");
  2055. }
  2056. }
  2057. if (representation[index] === "+" || representation[index] === "-") {
  2058. sawSign = true;
  2059. isNegative = representation[index++] === "-";
  2060. }
  2061. if (!isDigit(representation[index]) && representation[index] !== ".") {
  2062. if (representation[index] === "i" || representation[index] === "I") {
  2063. return new _Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
  2064. } else if (representation[index] === "N") {
  2065. return new _Decimal128(NAN_BUFFER);
  2066. }
  2067. }
  2068. while (isDigit(representation[index]) || representation[index] === ".") {
  2069. if (representation[index] === ".") {
  2070. if (sawRadix)
  2071. invalidErr(representation, "contains multiple periods");
  2072. sawRadix = true;
  2073. index = index + 1;
  2074. continue;
  2075. }
  2076. if (nDigitsStored < MAX_DIGITS) {
  2077. if (representation[index] !== "0" || foundNonZero) {
  2078. if (!foundNonZero) {
  2079. firstNonZero = nDigitsRead;
  2080. }
  2081. foundNonZero = true;
  2082. digits[digitsInsert++] = parseInt(representation[index], 10);
  2083. nDigitsStored = nDigitsStored + 1;
  2084. }
  2085. }
  2086. if (foundNonZero)
  2087. nDigits = nDigits + 1;
  2088. if (sawRadix)
  2089. radixPosition = radixPosition + 1;
  2090. nDigitsRead = nDigitsRead + 1;
  2091. index = index + 1;
  2092. }
  2093. if (sawRadix && !nDigitsRead)
  2094. throw new BSONError("" + representation + " not a valid Decimal128 string");
  2095. if (representation[index] === "e" || representation[index] === "E") {
  2096. const match = representation.substr(++index).match(EXPONENT_REGEX);
  2097. if (!match || !match[2])
  2098. return new _Decimal128(NAN_BUFFER);
  2099. exponent = parseInt(match[0], 10);
  2100. index = index + match[0].length;
  2101. }
  2102. if (representation[index])
  2103. return new _Decimal128(NAN_BUFFER);
  2104. if (!nDigitsStored) {
  2105. digits[0] = 0;
  2106. nDigits = 1;
  2107. nDigitsStored = 1;
  2108. significantDigits = 0;
  2109. } else {
  2110. lastDigit = nDigitsStored - 1;
  2111. significantDigits = nDigits;
  2112. if (significantDigits !== 1) {
  2113. while (representation[firstNonZero + significantDigits - 1 + Number(sawSign) + Number(sawRadix)] === "0") {
  2114. significantDigits = significantDigits - 1;
  2115. }
  2116. }
  2117. }
  2118. if (exponent <= radixPosition && radixPosition > exponent + (1 << 14)) {
  2119. exponent = EXPONENT_MIN;
  2120. } else {
  2121. exponent = exponent - radixPosition;
  2122. }
  2123. while (exponent > EXPONENT_MAX) {
  2124. lastDigit = lastDigit + 1;
  2125. if (lastDigit >= MAX_DIGITS) {
  2126. if (significantDigits === 0) {
  2127. exponent = EXPONENT_MAX;
  2128. break;
  2129. }
  2130. invalidErr(representation, "overflow");
  2131. }
  2132. exponent = exponent - 1;
  2133. }
  2134. if (options.allowRounding) {
  2135. while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
  2136. if (lastDigit === 0 && significantDigits < nDigitsStored) {
  2137. exponent = EXPONENT_MIN;
  2138. significantDigits = 0;
  2139. break;
  2140. }
  2141. if (nDigitsStored < nDigits) {
  2142. nDigits = nDigits - 1;
  2143. } else {
  2144. lastDigit = lastDigit - 1;
  2145. }
  2146. if (exponent < EXPONENT_MAX) {
  2147. exponent = exponent + 1;
  2148. } else {
  2149. const digitsString = digits.join("");
  2150. if (digitsString.match(/^0+$/)) {
  2151. exponent = EXPONENT_MAX;
  2152. break;
  2153. }
  2154. invalidErr(representation, "overflow");
  2155. }
  2156. }
  2157. if (lastDigit + 1 < significantDigits) {
  2158. let endOfString = nDigitsRead;
  2159. if (sawRadix) {
  2160. firstNonZero = firstNonZero + 1;
  2161. endOfString = endOfString + 1;
  2162. }
  2163. if (sawSign) {
  2164. firstNonZero = firstNonZero + 1;
  2165. endOfString = endOfString + 1;
  2166. }
  2167. const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
  2168. let roundBit = 0;
  2169. if (roundDigit >= 5) {
  2170. roundBit = 1;
  2171. if (roundDigit === 5) {
  2172. roundBit = digits[lastDigit] % 2 === 1 ? 1 : 0;
  2173. for (let i = firstNonZero + lastDigit + 2; i < endOfString; i++) {
  2174. if (parseInt(representation[i], 10)) {
  2175. roundBit = 1;
  2176. break;
  2177. }
  2178. }
  2179. }
  2180. }
  2181. if (roundBit) {
  2182. let dIdx = lastDigit;
  2183. for (; dIdx >= 0; dIdx--) {
  2184. if (++digits[dIdx] > 9) {
  2185. digits[dIdx] = 0;
  2186. if (dIdx === 0) {
  2187. if (exponent < EXPONENT_MAX) {
  2188. exponent = exponent + 1;
  2189. digits[dIdx] = 1;
  2190. } else {
  2191. return new _Decimal128(isNegative ? INF_NEGATIVE_BUFFER : INF_POSITIVE_BUFFER);
  2192. }
  2193. }
  2194. } else {
  2195. break;
  2196. }
  2197. }
  2198. }
  2199. }
  2200. } else {
  2201. while (exponent < EXPONENT_MIN || nDigitsStored < nDigits) {
  2202. if (lastDigit === 0) {
  2203. if (significantDigits === 0) {
  2204. exponent = EXPONENT_MIN;
  2205. break;
  2206. }
  2207. invalidErr(representation, "exponent underflow");
  2208. }
  2209. if (nDigitsStored < nDigits) {
  2210. if (representation[nDigits - 1 + Number(sawSign) + Number(sawRadix)] !== "0" && significantDigits !== 0) {
  2211. invalidErr(representation, "inexact rounding");
  2212. }
  2213. nDigits = nDigits - 1;
  2214. } else {
  2215. if (digits[lastDigit] !== 0) {
  2216. invalidErr(representation, "inexact rounding");
  2217. }
  2218. lastDigit = lastDigit - 1;
  2219. }
  2220. if (exponent < EXPONENT_MAX) {
  2221. exponent = exponent + 1;
  2222. } else {
  2223. invalidErr(representation, "overflow");
  2224. }
  2225. }
  2226. if (lastDigit + 1 < significantDigits) {
  2227. if (sawRadix) {
  2228. firstNonZero = firstNonZero + 1;
  2229. }
  2230. if (sawSign) {
  2231. firstNonZero = firstNonZero + 1;
  2232. }
  2233. const roundDigit = parseInt(representation[firstNonZero + lastDigit + 1], 10);
  2234. if (roundDigit !== 0) {
  2235. invalidErr(representation, "inexact rounding");
  2236. }
  2237. }
  2238. }
  2239. significandHigh = Long.fromNumber(0);
  2240. significandLow = Long.fromNumber(0);
  2241. if (significantDigits === 0) {
  2242. significandHigh = Long.fromNumber(0);
  2243. significandLow = Long.fromNumber(0);
  2244. } else if (lastDigit < 17) {
  2245. let dIdx = 0;
  2246. significandLow = Long.fromNumber(digits[dIdx++]);
  2247. significandHigh = new Long(0, 0);
  2248. for (; dIdx <= lastDigit; dIdx++) {
  2249. significandLow = significandLow.multiply(Long.fromNumber(10));
  2250. significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
  2251. }
  2252. } else {
  2253. let dIdx = 0;
  2254. significandHigh = Long.fromNumber(digits[dIdx++]);
  2255. for (; dIdx <= lastDigit - 17; dIdx++) {
  2256. significandHigh = significandHigh.multiply(Long.fromNumber(10));
  2257. significandHigh = significandHigh.add(Long.fromNumber(digits[dIdx]));
  2258. }
  2259. significandLow = Long.fromNumber(digits[dIdx++]);
  2260. for (; dIdx <= lastDigit; dIdx++) {
  2261. significandLow = significandLow.multiply(Long.fromNumber(10));
  2262. significandLow = significandLow.add(Long.fromNumber(digits[dIdx]));
  2263. }
  2264. }
  2265. const significand = multiply64x2(significandHigh, Long.fromString("100000000000000000"));
  2266. significand.low = significand.low.add(significandLow);
  2267. if (lessThan(significand.low, significandLow)) {
  2268. significand.high = significand.high.add(Long.fromNumber(1));
  2269. }
  2270. biasedExponent = exponent + EXPONENT_BIAS;
  2271. const dec = { low: Long.fromNumber(0), high: Long.fromNumber(0) };
  2272. if (significand.high.shiftRightUnsigned(49).and(Long.fromNumber(1)).equals(Long.fromNumber(1))) {
  2273. dec.high = dec.high.or(Long.fromNumber(3).shiftLeft(61));
  2274. dec.high = dec.high.or(Long.fromNumber(biasedExponent).and(Long.fromNumber(16383).shiftLeft(47)));
  2275. dec.high = dec.high.or(significand.high.and(Long.fromNumber(140737488355327)));
  2276. } else {
  2277. dec.high = dec.high.or(Long.fromNumber(biasedExponent & 16383).shiftLeft(49));
  2278. dec.high = dec.high.or(significand.high.and(Long.fromNumber(562949953421311)));
  2279. }
  2280. dec.low = significand.low;
  2281. if (isNegative) {
  2282. dec.high = dec.high.or(Long.fromString("9223372036854775808"));
  2283. }
  2284. const buffer2 = ByteUtils.allocate(16);
  2285. index = 0;
  2286. buffer2[index++] = dec.low.low & 255;
  2287. buffer2[index++] = dec.low.low >> 8 & 255;
  2288. buffer2[index++] = dec.low.low >> 16 & 255;
  2289. buffer2[index++] = dec.low.low >> 24 & 255;
  2290. buffer2[index++] = dec.low.high & 255;
  2291. buffer2[index++] = dec.low.high >> 8 & 255;
  2292. buffer2[index++] = dec.low.high >> 16 & 255;
  2293. buffer2[index++] = dec.low.high >> 24 & 255;
  2294. buffer2[index++] = dec.high.low & 255;
  2295. buffer2[index++] = dec.high.low >> 8 & 255;
  2296. buffer2[index++] = dec.high.low >> 16 & 255;
  2297. buffer2[index++] = dec.high.low >> 24 & 255;
  2298. buffer2[index++] = dec.high.high & 255;
  2299. buffer2[index++] = dec.high.high >> 8 & 255;
  2300. buffer2[index++] = dec.high.high >> 16 & 255;
  2301. buffer2[index++] = dec.high.high >> 24 & 255;
  2302. return new _Decimal128(buffer2);
  2303. }
  2304. toString() {
  2305. let biased_exponent;
  2306. let significand_digits = 0;
  2307. const significand = new Array(36);
  2308. for (let i = 0; i < significand.length; i++)
  2309. significand[i] = 0;
  2310. let index = 0;
  2311. let is_zero = false;
  2312. let significand_msb;
  2313. let significand128 = { parts: [0, 0, 0, 0] };
  2314. let j, k;
  2315. const string = [];
  2316. index = 0;
  2317. const buffer2 = this.bytes;
  2318. const low = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  2319. const midl = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  2320. const midh = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  2321. const high = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  2322. index = 0;
  2323. const dec = {
  2324. low: new Long(low, midl),
  2325. high: new Long(midh, high)
  2326. };
  2327. if (dec.high.lessThan(Long.ZERO)) {
  2328. string.push("-");
  2329. }
  2330. const combination = high >> 26 & COMBINATION_MASK;
  2331. if (combination >> 3 === 3) {
  2332. if (combination === COMBINATION_INFINITY) {
  2333. return string.join("") + "Infinity";
  2334. } else if (combination === COMBINATION_NAN) {
  2335. return "NaN";
  2336. } else {
  2337. biased_exponent = high >> 15 & EXPONENT_MASK;
  2338. significand_msb = 8 + (high >> 14 & 1);
  2339. }
  2340. } else {
  2341. significand_msb = high >> 14 & 7;
  2342. biased_exponent = high >> 17 & EXPONENT_MASK;
  2343. }
  2344. const exponent = biased_exponent - EXPONENT_BIAS;
  2345. significand128.parts[0] = (high & 16383) + ((significand_msb & 15) << 14);
  2346. significand128.parts[1] = midh;
  2347. significand128.parts[2] = midl;
  2348. significand128.parts[3] = low;
  2349. if (significand128.parts[0] === 0 && significand128.parts[1] === 0 && significand128.parts[2] === 0 && significand128.parts[3] === 0) {
  2350. is_zero = true;
  2351. } else {
  2352. for (k = 3; k >= 0; k--) {
  2353. let least_digits = 0;
  2354. const result = divideu128(significand128);
  2355. significand128 = result.quotient;
  2356. least_digits = result.rem.low;
  2357. if (!least_digits)
  2358. continue;
  2359. for (j = 8; j >= 0; j--) {
  2360. significand[k * 9 + j] = least_digits % 10;
  2361. least_digits = Math.floor(least_digits / 10);
  2362. }
  2363. }
  2364. }
  2365. if (is_zero) {
  2366. significand_digits = 1;
  2367. significand[index] = 0;
  2368. } else {
  2369. significand_digits = 36;
  2370. while (!significand[index]) {
  2371. significand_digits = significand_digits - 1;
  2372. index = index + 1;
  2373. }
  2374. }
  2375. const scientific_exponent = significand_digits - 1 + exponent;
  2376. if (scientific_exponent >= 34 || scientific_exponent <= -7 || exponent > 0) {
  2377. if (significand_digits > 34) {
  2378. string.push(`${0}`);
  2379. if (exponent > 0)
  2380. string.push(`E+${exponent}`);
  2381. else if (exponent < 0)
  2382. string.push(`E${exponent}`);
  2383. return string.join("");
  2384. }
  2385. string.push(`${significand[index++]}`);
  2386. significand_digits = significand_digits - 1;
  2387. if (significand_digits) {
  2388. string.push(".");
  2389. }
  2390. for (let i = 0; i < significand_digits; i++) {
  2391. string.push(`${significand[index++]}`);
  2392. }
  2393. string.push("E");
  2394. if (scientific_exponent > 0) {
  2395. string.push(`+${scientific_exponent}`);
  2396. } else {
  2397. string.push(`${scientific_exponent}`);
  2398. }
  2399. } else {
  2400. if (exponent >= 0) {
  2401. for (let i = 0; i < significand_digits; i++) {
  2402. string.push(`${significand[index++]}`);
  2403. }
  2404. } else {
  2405. let radix_position = significand_digits + exponent;
  2406. if (radix_position > 0) {
  2407. for (let i = 0; i < radix_position; i++) {
  2408. string.push(`${significand[index++]}`);
  2409. }
  2410. } else {
  2411. string.push("0");
  2412. }
  2413. string.push(".");
  2414. while (radix_position++ < 0) {
  2415. string.push("0");
  2416. }
  2417. for (let i = 0; i < significand_digits - Math.max(radix_position - 1, 0); i++) {
  2418. string.push(`${significand[index++]}`);
  2419. }
  2420. }
  2421. }
  2422. return string.join("");
  2423. }
  2424. toJSON() {
  2425. return { $numberDecimal: this.toString() };
  2426. }
  2427. toExtendedJSON() {
  2428. return { $numberDecimal: this.toString() };
  2429. }
  2430. static fromExtendedJSON(doc) {
  2431. return _Decimal128.fromString(doc.$numberDecimal);
  2432. }
  2433. [Symbol.for("nodejs.util.inspect.custom")]() {
  2434. return this.inspect();
  2435. }
  2436. inspect() {
  2437. return `new Decimal128("${this.toString()}")`;
  2438. }
  2439. };
  2440. var Double = class _Double extends BSONValue {
  2441. get _bsontype() {
  2442. return "Double";
  2443. }
  2444. constructor(value) {
  2445. super();
  2446. if (value instanceof Number) {
  2447. value = value.valueOf();
  2448. }
  2449. this.value = +value;
  2450. }
  2451. valueOf() {
  2452. return this.value;
  2453. }
  2454. toJSON() {
  2455. return this.value;
  2456. }
  2457. toString(radix) {
  2458. return this.value.toString(radix);
  2459. }
  2460. toExtendedJSON(options) {
  2461. if (options && (options.legacy || options.relaxed && isFinite(this.value))) {
  2462. return this.value;
  2463. }
  2464. if (Object.is(Math.sign(this.value), -0)) {
  2465. return { $numberDouble: "-0.0" };
  2466. }
  2467. return {
  2468. $numberDouble: Number.isInteger(this.value) ? this.value.toFixed(1) : this.value.toString()
  2469. };
  2470. }
  2471. static fromExtendedJSON(doc, options) {
  2472. const doubleValue = parseFloat(doc.$numberDouble);
  2473. return options && options.relaxed ? doubleValue : new _Double(doubleValue);
  2474. }
  2475. [Symbol.for("nodejs.util.inspect.custom")]() {
  2476. return this.inspect();
  2477. }
  2478. inspect() {
  2479. const eJSON = this.toExtendedJSON();
  2480. return `new Double(${eJSON.$numberDouble})`;
  2481. }
  2482. };
  2483. var Int32 = class _Int32 extends BSONValue {
  2484. get _bsontype() {
  2485. return "Int32";
  2486. }
  2487. constructor(value) {
  2488. super();
  2489. if (value instanceof Number) {
  2490. value = value.valueOf();
  2491. }
  2492. this.value = +value | 0;
  2493. }
  2494. valueOf() {
  2495. return this.value;
  2496. }
  2497. toString(radix) {
  2498. return this.value.toString(radix);
  2499. }
  2500. toJSON() {
  2501. return this.value;
  2502. }
  2503. toExtendedJSON(options) {
  2504. if (options && (options.relaxed || options.legacy))
  2505. return this.value;
  2506. return { $numberInt: this.value.toString() };
  2507. }
  2508. static fromExtendedJSON(doc, options) {
  2509. return options && options.relaxed ? parseInt(doc.$numberInt, 10) : new _Int32(doc.$numberInt);
  2510. }
  2511. [Symbol.for("nodejs.util.inspect.custom")]() {
  2512. return this.inspect();
  2513. }
  2514. inspect() {
  2515. return `new Int32(${this.valueOf()})`;
  2516. }
  2517. };
  2518. var MaxKey = class _MaxKey extends BSONValue {
  2519. get _bsontype() {
  2520. return "MaxKey";
  2521. }
  2522. toExtendedJSON() {
  2523. return { $maxKey: 1 };
  2524. }
  2525. static fromExtendedJSON() {
  2526. return new _MaxKey();
  2527. }
  2528. [Symbol.for("nodejs.util.inspect.custom")]() {
  2529. return this.inspect();
  2530. }
  2531. inspect() {
  2532. return "new MaxKey()";
  2533. }
  2534. };
  2535. var MinKey = class _MinKey extends BSONValue {
  2536. get _bsontype() {
  2537. return "MinKey";
  2538. }
  2539. toExtendedJSON() {
  2540. return { $minKey: 1 };
  2541. }
  2542. static fromExtendedJSON() {
  2543. return new _MinKey();
  2544. }
  2545. [Symbol.for("nodejs.util.inspect.custom")]() {
  2546. return this.inspect();
  2547. }
  2548. inspect() {
  2549. return "new MinKey()";
  2550. }
  2551. };
  2552. var checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$");
  2553. var PROCESS_UNIQUE = null;
  2554. var kId = Symbol("id");
  2555. var ObjectId3 = class _ObjectId extends BSONValue {
  2556. get _bsontype() {
  2557. return "ObjectId";
  2558. }
  2559. constructor(inputId) {
  2560. super();
  2561. let workingId;
  2562. if (typeof inputId === "object" && inputId && "id" in inputId) {
  2563. if (typeof inputId.id !== "string" && !ArrayBuffer.isView(inputId.id)) {
  2564. throw new BSONError("Argument passed in must have an id that is of type string or Buffer");
  2565. }
  2566. if ("toHexString" in inputId && typeof inputId.toHexString === "function") {
  2567. workingId = ByteUtils.fromHex(inputId.toHexString());
  2568. } else {
  2569. workingId = inputId.id;
  2570. }
  2571. } else {
  2572. workingId = inputId;
  2573. }
  2574. if (workingId == null || typeof workingId === "number") {
  2575. this[kId] = _ObjectId.generate(typeof workingId === "number" ? workingId : void 0);
  2576. } else if (ArrayBuffer.isView(workingId) && workingId.byteLength === 12) {
  2577. this[kId] = ByteUtils.toLocalBufferType(workingId);
  2578. } else if (typeof workingId === "string") {
  2579. if (workingId.length === 12) {
  2580. const bytes = ByteUtils.fromUTF8(workingId);
  2581. if (bytes.byteLength === 12) {
  2582. this[kId] = bytes;
  2583. } else {
  2584. throw new BSONError("Argument passed in must be a string of 12 bytes");
  2585. }
  2586. } else if (workingId.length === 24 && checkForHexRegExp.test(workingId)) {
  2587. this[kId] = ByteUtils.fromHex(workingId);
  2588. } else {
  2589. throw new BSONError("Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer");
  2590. }
  2591. } else {
  2592. throw new BSONError("Argument passed in does not match the accepted types");
  2593. }
  2594. if (_ObjectId.cacheHexString) {
  2595. this.__id = ByteUtils.toHex(this.id);
  2596. }
  2597. }
  2598. get id() {
  2599. return this[kId];
  2600. }
  2601. set id(value) {
  2602. this[kId] = value;
  2603. if (_ObjectId.cacheHexString) {
  2604. this.__id = ByteUtils.toHex(value);
  2605. }
  2606. }
  2607. toHexString() {
  2608. if (_ObjectId.cacheHexString && this.__id) {
  2609. return this.__id;
  2610. }
  2611. const hexString = ByteUtils.toHex(this.id);
  2612. if (_ObjectId.cacheHexString && !this.__id) {
  2613. this.__id = hexString;
  2614. }
  2615. return hexString;
  2616. }
  2617. static getInc() {
  2618. return _ObjectId.index = (_ObjectId.index + 1) % 16777215;
  2619. }
  2620. static generate(time) {
  2621. if ("number" !== typeof time) {
  2622. time = Math.floor(Date.now() / 1e3);
  2623. }
  2624. const inc = _ObjectId.getInc();
  2625. const buffer2 = ByteUtils.allocate(12);
  2626. BSONDataView.fromUint8Array(buffer2).setUint32(0, time, false);
  2627. if (PROCESS_UNIQUE === null) {
  2628. PROCESS_UNIQUE = ByteUtils.randomBytes(5);
  2629. }
  2630. buffer2[4] = PROCESS_UNIQUE[0];
  2631. buffer2[5] = PROCESS_UNIQUE[1];
  2632. buffer2[6] = PROCESS_UNIQUE[2];
  2633. buffer2[7] = PROCESS_UNIQUE[3];
  2634. buffer2[8] = PROCESS_UNIQUE[4];
  2635. buffer2[11] = inc & 255;
  2636. buffer2[10] = inc >> 8 & 255;
  2637. buffer2[9] = inc >> 16 & 255;
  2638. return buffer2;
  2639. }
  2640. toString(encoding) {
  2641. if (encoding === "base64")
  2642. return ByteUtils.toBase64(this.id);
  2643. if (encoding === "hex")
  2644. return this.toHexString();
  2645. return this.toHexString();
  2646. }
  2647. toJSON() {
  2648. return this.toHexString();
  2649. }
  2650. equals(otherId) {
  2651. if (otherId === void 0 || otherId === null) {
  2652. return false;
  2653. }
  2654. if (otherId instanceof _ObjectId) {
  2655. return this[kId][11] === otherId[kId][11] && ByteUtils.equals(this[kId], otherId[kId]);
  2656. }
  2657. if (typeof otherId === "string" && _ObjectId.isValid(otherId) && otherId.length === 12 && isUint8Array(this.id)) {
  2658. return ByteUtils.equals(this.id, ByteUtils.fromISO88591(otherId));
  2659. }
  2660. if (typeof otherId === "string" && _ObjectId.isValid(otherId) && otherId.length === 24) {
  2661. return otherId.toLowerCase() === this.toHexString();
  2662. }
  2663. if (typeof otherId === "string" && _ObjectId.isValid(otherId) && otherId.length === 12) {
  2664. return ByteUtils.equals(ByteUtils.fromUTF8(otherId), this.id);
  2665. }
  2666. if (typeof otherId === "object" && "toHexString" in otherId && typeof otherId.toHexString === "function") {
  2667. const otherIdString = otherId.toHexString();
  2668. const thisIdString = this.toHexString().toLowerCase();
  2669. return typeof otherIdString === "string" && otherIdString.toLowerCase() === thisIdString;
  2670. }
  2671. return false;
  2672. }
  2673. getTimestamp() {
  2674. const timestamp = /* @__PURE__ */ new Date();
  2675. const time = BSONDataView.fromUint8Array(this.id).getUint32(0, false);
  2676. timestamp.setTime(Math.floor(time) * 1e3);
  2677. return timestamp;
  2678. }
  2679. static createPk() {
  2680. return new _ObjectId();
  2681. }
  2682. static createFromTime(time) {
  2683. const buffer2 = ByteUtils.fromNumberArray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  2684. BSONDataView.fromUint8Array(buffer2).setUint32(0, time, false);
  2685. return new _ObjectId(buffer2);
  2686. }
  2687. static createFromHexString(hexString) {
  2688. if ((hexString == null ? void 0 : hexString.length) !== 24) {
  2689. throw new BSONError("hex string must be 24 characters");
  2690. }
  2691. return new _ObjectId(ByteUtils.fromHex(hexString));
  2692. }
  2693. static createFromBase64(base64) {
  2694. if ((base64 == null ? void 0 : base64.length) !== 16) {
  2695. throw new BSONError("base64 string must be 16 characters");
  2696. }
  2697. return new _ObjectId(ByteUtils.fromBase64(base64));
  2698. }
  2699. static isValid(id) {
  2700. if (id == null)
  2701. return false;
  2702. try {
  2703. new _ObjectId(id);
  2704. return true;
  2705. } catch {
  2706. return false;
  2707. }
  2708. }
  2709. toExtendedJSON() {
  2710. if (this.toHexString)
  2711. return { $oid: this.toHexString() };
  2712. return { $oid: this.toString("hex") };
  2713. }
  2714. static fromExtendedJSON(doc) {
  2715. return new _ObjectId(doc.$oid);
  2716. }
  2717. [Symbol.for("nodejs.util.inspect.custom")]() {
  2718. return this.inspect();
  2719. }
  2720. inspect() {
  2721. return `new ObjectId("${this.toHexString()}")`;
  2722. }
  2723. };
  2724. ObjectId3.index = Math.floor(Math.random() * 16777215);
  2725. function internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined) {
  2726. let totalLength = 4 + 1;
  2727. if (Array.isArray(object)) {
  2728. for (let i = 0; i < object.length; i++) {
  2729. totalLength += calculateElement(i.toString(), object[i], serializeFunctions, true, ignoreUndefined);
  2730. }
  2731. } else {
  2732. if (typeof (object == null ? void 0 : object.toBSON) === "function") {
  2733. object = object.toBSON();
  2734. }
  2735. for (const key of Object.keys(object)) {
  2736. totalLength += calculateElement(key, object[key], serializeFunctions, false, ignoreUndefined);
  2737. }
  2738. }
  2739. return totalLength;
  2740. }
  2741. function calculateElement(name, value, serializeFunctions = false, isArray = false, ignoreUndefined = false) {
  2742. if (typeof (value == null ? void 0 : value.toBSON) === "function") {
  2743. value = value.toBSON();
  2744. }
  2745. switch (typeof value) {
  2746. case "string":
  2747. return 1 + ByteUtils.utf8ByteLength(name) + 1 + 4 + ByteUtils.utf8ByteLength(value) + 1;
  2748. case "number":
  2749. if (Math.floor(value) === value && value >= JS_INT_MIN && value <= JS_INT_MAX) {
  2750. if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
  2751. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (4 + 1);
  2752. } else {
  2753. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
  2754. }
  2755. } else {
  2756. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
  2757. }
  2758. case "undefined":
  2759. if (isArray || !ignoreUndefined)
  2760. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
  2761. return 0;
  2762. case "boolean":
  2763. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 1);
  2764. case "object":
  2765. if (value != null && typeof value._bsontype === "string" && value[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
  2766. throw new BSONVersionError();
  2767. } else if (value == null || value._bsontype === "MinKey" || value._bsontype === "MaxKey") {
  2768. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1;
  2769. } else if (value._bsontype === "ObjectId") {
  2770. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (12 + 1);
  2771. } else if (value instanceof Date || isDate(value)) {
  2772. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
  2773. } else if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isAnyArrayBuffer(value)) {
  2774. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (1 + 4 + 1) + value.byteLength;
  2775. } else if (value._bsontype === "Long" || value._bsontype === "Double" || value._bsontype === "Timestamp") {
  2776. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1);
  2777. } else if (value._bsontype === "Decimal128") {
  2778. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (16 + 1);
  2779. } else if (value._bsontype === "Code") {
  2780. if (value.scope != null && Object.keys(value.scope).length > 0) {
  2781. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + 4 + ByteUtils.utf8ByteLength(value.code.toString()) + 1 + internalCalculateObjectSize(value.scope, serializeFunctions, ignoreUndefined);
  2782. } else {
  2783. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + ByteUtils.utf8ByteLength(value.code.toString()) + 1;
  2784. }
  2785. } else if (value._bsontype === "Binary") {
  2786. const binary = value;
  2787. if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
  2788. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (binary.position + 1 + 4 + 1 + 4);
  2789. } else {
  2790. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (binary.position + 1 + 4 + 1);
  2791. }
  2792. } else if (value._bsontype === "Symbol") {
  2793. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + ByteUtils.utf8ByteLength(value.value) + 4 + 1 + 1;
  2794. } else if (value._bsontype === "DBRef") {
  2795. const ordered_values = Object.assign({
  2796. $ref: value.collection,
  2797. $id: value.oid
  2798. }, value.fields);
  2799. if (value.db != null) {
  2800. ordered_values["$db"] = value.db;
  2801. }
  2802. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + internalCalculateObjectSize(ordered_values, serializeFunctions, ignoreUndefined);
  2803. } else if (value instanceof RegExp || isRegExp(value)) {
  2804. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + ByteUtils.utf8ByteLength(value.source) + 1 + (value.global ? 1 : 0) + (value.ignoreCase ? 1 : 0) + (value.multiline ? 1 : 0) + 1;
  2805. } else if (value._bsontype === "BSONRegExp") {
  2806. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + ByteUtils.utf8ByteLength(value.pattern) + 1 + ByteUtils.utf8ByteLength(value.options) + 1;
  2807. } else {
  2808. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + internalCalculateObjectSize(value, serializeFunctions, ignoreUndefined) + 1;
  2809. }
  2810. case "function":
  2811. if (serializeFunctions) {
  2812. return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + 1 + 4 + ByteUtils.utf8ByteLength(value.toString()) + 1;
  2813. }
  2814. }
  2815. return 0;
  2816. }
  2817. function alphabetize(str) {
  2818. return str.split("").sort().join("");
  2819. }
  2820. var BSONRegExp = class _BSONRegExp extends BSONValue {
  2821. get _bsontype() {
  2822. return "BSONRegExp";
  2823. }
  2824. constructor(pattern, options) {
  2825. super();
  2826. this.pattern = pattern;
  2827. this.options = alphabetize(options ?? "");
  2828. if (this.pattern.indexOf("\0") !== -1) {
  2829. throw new BSONError(`BSON Regex patterns cannot contain null bytes, found: ${JSON.stringify(this.pattern)}`);
  2830. }
  2831. if (this.options.indexOf("\0") !== -1) {
  2832. throw new BSONError(`BSON Regex options cannot contain null bytes, found: ${JSON.stringify(this.options)}`);
  2833. }
  2834. for (let i = 0; i < this.options.length; i++) {
  2835. if (!(this.options[i] === "i" || this.options[i] === "m" || this.options[i] === "x" || this.options[i] === "l" || this.options[i] === "s" || this.options[i] === "u")) {
  2836. throw new BSONError(`The regular expression option [${this.options[i]}] is not supported`);
  2837. }
  2838. }
  2839. }
  2840. static parseOptions(options) {
  2841. return options ? options.split("").sort().join("") : "";
  2842. }
  2843. toExtendedJSON(options) {
  2844. options = options || {};
  2845. if (options.legacy) {
  2846. return { $regex: this.pattern, $options: this.options };
  2847. }
  2848. return { $regularExpression: { pattern: this.pattern, options: this.options } };
  2849. }
  2850. static fromExtendedJSON(doc) {
  2851. if ("$regex" in doc) {
  2852. if (typeof doc.$regex !== "string") {
  2853. if (doc.$regex._bsontype === "BSONRegExp") {
  2854. return doc;
  2855. }
  2856. } else {
  2857. return new _BSONRegExp(doc.$regex, _BSONRegExp.parseOptions(doc.$options));
  2858. }
  2859. }
  2860. if ("$regularExpression" in doc) {
  2861. return new _BSONRegExp(doc.$regularExpression.pattern, _BSONRegExp.parseOptions(doc.$regularExpression.options));
  2862. }
  2863. throw new BSONError(`Unexpected BSONRegExp EJSON object form: ${JSON.stringify(doc)}`);
  2864. }
  2865. [Symbol.for("nodejs.util.inspect.custom")]() {
  2866. return this.inspect();
  2867. }
  2868. inspect() {
  2869. return `new BSONRegExp(${JSON.stringify(this.pattern)}, ${JSON.stringify(this.options)})`;
  2870. }
  2871. };
  2872. var BSONSymbol = class _BSONSymbol extends BSONValue {
  2873. get _bsontype() {
  2874. return "BSONSymbol";
  2875. }
  2876. constructor(value) {
  2877. super();
  2878. this.value = value;
  2879. }
  2880. valueOf() {
  2881. return this.value;
  2882. }
  2883. toString() {
  2884. return this.value;
  2885. }
  2886. inspect() {
  2887. return `new BSONSymbol("${this.value}")`;
  2888. }
  2889. toJSON() {
  2890. return this.value;
  2891. }
  2892. toExtendedJSON() {
  2893. return { $symbol: this.value };
  2894. }
  2895. static fromExtendedJSON(doc) {
  2896. return new _BSONSymbol(doc.$symbol);
  2897. }
  2898. [Symbol.for("nodejs.util.inspect.custom")]() {
  2899. return this.inspect();
  2900. }
  2901. };
  2902. var LongWithoutOverridesClass = Long;
  2903. var Timestamp = class _Timestamp extends LongWithoutOverridesClass {
  2904. get _bsontype() {
  2905. return "Timestamp";
  2906. }
  2907. constructor(low) {
  2908. if (low == null) {
  2909. super(0, 0, true);
  2910. } else if (typeof low === "bigint") {
  2911. super(low, true);
  2912. } else if (Long.isLong(low)) {
  2913. super(low.low, low.high, true);
  2914. } else if (typeof low === "object" && "t" in low && "i" in low) {
  2915. if (typeof low.t !== "number" && (typeof low.t !== "object" || low.t._bsontype !== "Int32")) {
  2916. throw new BSONError("Timestamp constructed from { t, i } must provide t as a number");
  2917. }
  2918. if (typeof low.i !== "number" && (typeof low.i !== "object" || low.i._bsontype !== "Int32")) {
  2919. throw new BSONError("Timestamp constructed from { t, i } must provide i as a number");
  2920. }
  2921. const t = Number(low.t);
  2922. const i = Number(low.i);
  2923. if (t < 0 || Number.isNaN(t)) {
  2924. throw new BSONError("Timestamp constructed from { t, i } must provide a positive t");
  2925. }
  2926. if (i < 0 || Number.isNaN(i)) {
  2927. throw new BSONError("Timestamp constructed from { t, i } must provide a positive i");
  2928. }
  2929. if (t > 4294967295) {
  2930. throw new BSONError("Timestamp constructed from { t, i } must provide t equal or less than uint32 max");
  2931. }
  2932. if (i > 4294967295) {
  2933. throw new BSONError("Timestamp constructed from { t, i } must provide i equal or less than uint32 max");
  2934. }
  2935. super(i, t, true);
  2936. } else {
  2937. throw new BSONError("A Timestamp can only be constructed with: bigint, Long, or { t: number; i: number }");
  2938. }
  2939. }
  2940. toJSON() {
  2941. return {
  2942. $timestamp: this.toString()
  2943. };
  2944. }
  2945. static fromInt(value) {
  2946. return new _Timestamp(Long.fromInt(value, true));
  2947. }
  2948. static fromNumber(value) {
  2949. return new _Timestamp(Long.fromNumber(value, true));
  2950. }
  2951. static fromBits(lowBits, highBits) {
  2952. return new _Timestamp({ i: lowBits, t: highBits });
  2953. }
  2954. static fromString(str, optRadix) {
  2955. return new _Timestamp(Long.fromString(str, true, optRadix));
  2956. }
  2957. toExtendedJSON() {
  2958. return { $timestamp: { t: this.high >>> 0, i: this.low >>> 0 } };
  2959. }
  2960. static fromExtendedJSON(doc) {
  2961. const i = Long.isLong(doc.$timestamp.i) ? doc.$timestamp.i.getLowBitsUnsigned() : doc.$timestamp.i;
  2962. const t = Long.isLong(doc.$timestamp.t) ? doc.$timestamp.t.getLowBitsUnsigned() : doc.$timestamp.t;
  2963. return new _Timestamp({ t, i });
  2964. }
  2965. [Symbol.for("nodejs.util.inspect.custom")]() {
  2966. return this.inspect();
  2967. }
  2968. inspect() {
  2969. return `new Timestamp({ t: ${this.getHighBits()}, i: ${this.getLowBits()} })`;
  2970. }
  2971. };
  2972. Timestamp.MAX_VALUE = Long.MAX_UNSIGNED_VALUE;
  2973. var FIRST_BIT = 128;
  2974. var FIRST_TWO_BITS = 192;
  2975. var FIRST_THREE_BITS = 224;
  2976. var FIRST_FOUR_BITS = 240;
  2977. var FIRST_FIVE_BITS = 248;
  2978. var TWO_BIT_CHAR = 192;
  2979. var THREE_BIT_CHAR = 224;
  2980. var FOUR_BIT_CHAR = 240;
  2981. var CONTINUING_CHAR = 128;
  2982. function validateUtf8(bytes, start, end) {
  2983. let continuation = 0;
  2984. for (let i = start; i < end; i += 1) {
  2985. const byte = bytes[i];
  2986. if (continuation) {
  2987. if ((byte & FIRST_TWO_BITS) !== CONTINUING_CHAR) {
  2988. return false;
  2989. }
  2990. continuation -= 1;
  2991. } else if (byte & FIRST_BIT) {
  2992. if ((byte & FIRST_THREE_BITS) === TWO_BIT_CHAR) {
  2993. continuation = 1;
  2994. } else if ((byte & FIRST_FOUR_BITS) === THREE_BIT_CHAR) {
  2995. continuation = 2;
  2996. } else if ((byte & FIRST_FIVE_BITS) === FOUR_BIT_CHAR) {
  2997. continuation = 3;
  2998. } else {
  2999. return false;
  3000. }
  3001. }
  3002. }
  3003. return !continuation;
  3004. }
  3005. var JS_INT_MAX_LONG = Long.fromNumber(JS_INT_MAX);
  3006. var JS_INT_MIN_LONG = Long.fromNumber(JS_INT_MIN);
  3007. function internalDeserialize(buffer2, options, isArray) {
  3008. options = options == null ? {} : options;
  3009. const index = options && options.index ? options.index : 0;
  3010. const size = buffer2[index] | buffer2[index + 1] << 8 | buffer2[index + 2] << 16 | buffer2[index + 3] << 24;
  3011. if (size < 5) {
  3012. throw new BSONError(`bson size must be >= 5, is ${size}`);
  3013. }
  3014. if (options.allowObjectSmallerThanBufferSize && buffer2.length < size) {
  3015. throw new BSONError(`buffer length ${buffer2.length} must be >= bson size ${size}`);
  3016. }
  3017. if (!options.allowObjectSmallerThanBufferSize && buffer2.length !== size) {
  3018. throw new BSONError(`buffer length ${buffer2.length} must === bson size ${size}`);
  3019. }
  3020. if (size + index > buffer2.byteLength) {
  3021. throw new BSONError(`(bson size ${size} + options.index ${index} must be <= buffer length ${buffer2.byteLength})`);
  3022. }
  3023. if (buffer2[index + size - 1] !== 0) {
  3024. throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
  3025. }
  3026. return deserializeObject(buffer2, index, options, isArray);
  3027. }
  3028. var allowedDBRefKeys = /^\$ref$|^\$id$|^\$db$/;
  3029. function deserializeObject(buffer2, index, options, isArray = false) {
  3030. const fieldsAsRaw = options["fieldsAsRaw"] == null ? null : options["fieldsAsRaw"];
  3031. const raw = options["raw"] == null ? false : options["raw"];
  3032. const bsonRegExp = typeof options["bsonRegExp"] === "boolean" ? options["bsonRegExp"] : false;
  3033. const promoteBuffers = options.promoteBuffers ?? false;
  3034. const promoteLongs = options.promoteLongs ?? true;
  3035. const promoteValues = options.promoteValues ?? true;
  3036. const useBigInt64 = options.useBigInt64 ?? false;
  3037. if (useBigInt64 && !promoteValues) {
  3038. throw new BSONError("Must either request bigint or Long for int64 deserialization");
  3039. }
  3040. if (useBigInt64 && !promoteLongs) {
  3041. throw new BSONError("Must either request bigint or Long for int64 deserialization");
  3042. }
  3043. const validation = options.validation == null ? { utf8: true } : options.validation;
  3044. let globalUTFValidation = true;
  3045. let validationSetting;
  3046. const utf8KeysSet = /* @__PURE__ */ new Set();
  3047. const utf8ValidatedKeys = validation.utf8;
  3048. if (typeof utf8ValidatedKeys === "boolean") {
  3049. validationSetting = utf8ValidatedKeys;
  3050. } else {
  3051. globalUTFValidation = false;
  3052. const utf8ValidationValues = Object.keys(utf8ValidatedKeys).map(function(key) {
  3053. return utf8ValidatedKeys[key];
  3054. });
  3055. if (utf8ValidationValues.length === 0) {
  3056. throw new BSONError("UTF-8 validation setting cannot be empty");
  3057. }
  3058. if (typeof utf8ValidationValues[0] !== "boolean") {
  3059. throw new BSONError("Invalid UTF-8 validation option, must specify boolean values");
  3060. }
  3061. validationSetting = utf8ValidationValues[0];
  3062. if (!utf8ValidationValues.every((item) => item === validationSetting)) {
  3063. throw new BSONError("Invalid UTF-8 validation option - keys must be all true or all false");
  3064. }
  3065. }
  3066. if (!globalUTFValidation) {
  3067. for (const key of Object.keys(utf8ValidatedKeys)) {
  3068. utf8KeysSet.add(key);
  3069. }
  3070. }
  3071. const startIndex = index;
  3072. if (buffer2.length < 5)
  3073. throw new BSONError("corrupt bson message < 5 bytes long");
  3074. const size = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3075. if (size < 5 || size > buffer2.length)
  3076. throw new BSONError("corrupt bson message");
  3077. const object = isArray ? [] : {};
  3078. let arrayIndex = 0;
  3079. const done = false;
  3080. let isPossibleDBRef = isArray ? false : null;
  3081. const dataview = new DataView(buffer2.buffer, buffer2.byteOffset, buffer2.byteLength);
  3082. while (!done) {
  3083. const elementType = buffer2[index++];
  3084. if (elementType === 0)
  3085. break;
  3086. let i = index;
  3087. while (buffer2[i] !== 0 && i < buffer2.length) {
  3088. i++;
  3089. }
  3090. if (i >= buffer2.byteLength)
  3091. throw new BSONError("Bad BSON Document: illegal CString");
  3092. const name = isArray ? arrayIndex++ : ByteUtils.toUTF8(buffer2, index, i);
  3093. let shouldValidateKey = true;
  3094. if (globalUTFValidation || utf8KeysSet.has(name)) {
  3095. shouldValidateKey = validationSetting;
  3096. } else {
  3097. shouldValidateKey = !validationSetting;
  3098. }
  3099. if (isPossibleDBRef !== false && name[0] === "$") {
  3100. isPossibleDBRef = allowedDBRefKeys.test(name);
  3101. }
  3102. let value;
  3103. index = i + 1;
  3104. if (elementType === BSON_DATA_STRING) {
  3105. const stringSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3106. if (stringSize <= 0 || stringSize > buffer2.length - index || buffer2[index + stringSize - 1] !== 0) {
  3107. throw new BSONError("bad string length in bson");
  3108. }
  3109. value = getValidatedString(buffer2, index, index + stringSize - 1, shouldValidateKey);
  3110. index = index + stringSize;
  3111. } else if (elementType === BSON_DATA_OID) {
  3112. const oid = ByteUtils.allocate(12);
  3113. oid.set(buffer2.subarray(index, index + 12));
  3114. value = new ObjectId3(oid);
  3115. index = index + 12;
  3116. } else if (elementType === BSON_DATA_INT && promoteValues === false) {
  3117. value = new Int32(buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24);
  3118. } else if (elementType === BSON_DATA_INT) {
  3119. value = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3120. } else if (elementType === BSON_DATA_NUMBER && promoteValues === false) {
  3121. value = new Double(dataview.getFloat64(index, true));
  3122. index = index + 8;
  3123. } else if (elementType === BSON_DATA_NUMBER) {
  3124. value = dataview.getFloat64(index, true);
  3125. index = index + 8;
  3126. } else if (elementType === BSON_DATA_DATE) {
  3127. const lowBits = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3128. const highBits = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3129. value = new Date(new Long(lowBits, highBits).toNumber());
  3130. } else if (elementType === BSON_DATA_BOOLEAN) {
  3131. if (buffer2[index] !== 0 && buffer2[index] !== 1)
  3132. throw new BSONError("illegal boolean type value");
  3133. value = buffer2[index++] === 1;
  3134. } else if (elementType === BSON_DATA_OBJECT) {
  3135. const _index = index;
  3136. const objectSize = buffer2[index] | buffer2[index + 1] << 8 | buffer2[index + 2] << 16 | buffer2[index + 3] << 24;
  3137. if (objectSize <= 0 || objectSize > buffer2.length - index)
  3138. throw new BSONError("bad embedded document length in bson");
  3139. if (raw) {
  3140. value = buffer2.slice(index, index + objectSize);
  3141. } else {
  3142. let objectOptions = options;
  3143. if (!globalUTFValidation) {
  3144. objectOptions = { ...options, validation: { utf8: shouldValidateKey } };
  3145. }
  3146. value = deserializeObject(buffer2, _index, objectOptions, false);
  3147. }
  3148. index = index + objectSize;
  3149. } else if (elementType === BSON_DATA_ARRAY) {
  3150. const _index = index;
  3151. const objectSize = buffer2[index] | buffer2[index + 1] << 8 | buffer2[index + 2] << 16 | buffer2[index + 3] << 24;
  3152. let arrayOptions = options;
  3153. const stopIndex = index + objectSize;
  3154. if (fieldsAsRaw && fieldsAsRaw[name]) {
  3155. arrayOptions = { ...options, raw: true };
  3156. }
  3157. if (!globalUTFValidation) {
  3158. arrayOptions = { ...arrayOptions, validation: { utf8: shouldValidateKey } };
  3159. }
  3160. value = deserializeObject(buffer2, _index, arrayOptions, true);
  3161. index = index + objectSize;
  3162. if (buffer2[index - 1] !== 0)
  3163. throw new BSONError("invalid array terminator byte");
  3164. if (index !== stopIndex)
  3165. throw new BSONError("corrupted array bson");
  3166. } else if (elementType === BSON_DATA_UNDEFINED) {
  3167. value = void 0;
  3168. } else if (elementType === BSON_DATA_NULL) {
  3169. value = null;
  3170. } else if (elementType === BSON_DATA_LONG) {
  3171. const dataview2 = BSONDataView.fromUint8Array(buffer2.subarray(index, index + 8));
  3172. const lowBits = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3173. const highBits = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3174. const long = new Long(lowBits, highBits);
  3175. if (useBigInt64) {
  3176. value = dataview2.getBigInt64(0, true);
  3177. } else if (promoteLongs && promoteValues === true) {
  3178. value = long.lessThanOrEqual(JS_INT_MAX_LONG) && long.greaterThanOrEqual(JS_INT_MIN_LONG) ? long.toNumber() : long;
  3179. } else {
  3180. value = long;
  3181. }
  3182. } else if (elementType === BSON_DATA_DECIMAL128) {
  3183. const bytes = ByteUtils.allocate(16);
  3184. bytes.set(buffer2.subarray(index, index + 16), 0);
  3185. index = index + 16;
  3186. value = new Decimal128(bytes);
  3187. } else if (elementType === BSON_DATA_BINARY) {
  3188. let binarySize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3189. const totalBinarySize = binarySize;
  3190. const subType = buffer2[index++];
  3191. if (binarySize < 0)
  3192. throw new BSONError("Negative binary type element size found");
  3193. if (binarySize > buffer2.byteLength)
  3194. throw new BSONError("Binary type size larger than document size");
  3195. if (buffer2["slice"] != null) {
  3196. if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
  3197. binarySize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3198. if (binarySize < 0)
  3199. throw new BSONError("Negative binary type element size found for subtype 0x02");
  3200. if (binarySize > totalBinarySize - 4)
  3201. throw new BSONError("Binary type with subtype 0x02 contains too long binary size");
  3202. if (binarySize < totalBinarySize - 4)
  3203. throw new BSONError("Binary type with subtype 0x02 contains too short binary size");
  3204. }
  3205. if (promoteBuffers && promoteValues) {
  3206. value = ByteUtils.toLocalBufferType(buffer2.slice(index, index + binarySize));
  3207. } else {
  3208. value = new Binary(buffer2.slice(index, index + binarySize), subType);
  3209. if (subType === BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
  3210. value = value.toUUID();
  3211. }
  3212. }
  3213. } else {
  3214. const _buffer = ByteUtils.allocate(binarySize);
  3215. if (subType === Binary.SUBTYPE_BYTE_ARRAY) {
  3216. binarySize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3217. if (binarySize < 0)
  3218. throw new BSONError("Negative binary type element size found for subtype 0x02");
  3219. if (binarySize > totalBinarySize - 4)
  3220. throw new BSONError("Binary type with subtype 0x02 contains too long binary size");
  3221. if (binarySize < totalBinarySize - 4)
  3222. throw new BSONError("Binary type with subtype 0x02 contains too short binary size");
  3223. }
  3224. for (i = 0; i < binarySize; i++) {
  3225. _buffer[i] = buffer2[index + i];
  3226. }
  3227. if (promoteBuffers && promoteValues) {
  3228. value = _buffer;
  3229. } else {
  3230. value = new Binary(buffer2.slice(index, index + binarySize), subType);
  3231. if (subType === BSON_BINARY_SUBTYPE_UUID_NEW && UUID.isValid(value)) {
  3232. value = value.toUUID();
  3233. }
  3234. }
  3235. }
  3236. index = index + binarySize;
  3237. } else if (elementType === BSON_DATA_REGEXP && bsonRegExp === false) {
  3238. i = index;
  3239. while (buffer2[i] !== 0 && i < buffer2.length) {
  3240. i++;
  3241. }
  3242. if (i >= buffer2.length)
  3243. throw new BSONError("Bad BSON Document: illegal CString");
  3244. const source = ByteUtils.toUTF8(buffer2, index, i);
  3245. index = i + 1;
  3246. i = index;
  3247. while (buffer2[i] !== 0 && i < buffer2.length) {
  3248. i++;
  3249. }
  3250. if (i >= buffer2.length)
  3251. throw new BSONError("Bad BSON Document: illegal CString");
  3252. const regExpOptions = ByteUtils.toUTF8(buffer2, index, i);
  3253. index = i + 1;
  3254. const optionsArray = new Array(regExpOptions.length);
  3255. for (i = 0; i < regExpOptions.length; i++) {
  3256. switch (regExpOptions[i]) {
  3257. case "m":
  3258. optionsArray[i] = "m";
  3259. break;
  3260. case "s":
  3261. optionsArray[i] = "g";
  3262. break;
  3263. case "i":
  3264. optionsArray[i] = "i";
  3265. break;
  3266. }
  3267. }
  3268. value = new RegExp(source, optionsArray.join(""));
  3269. } else if (elementType === BSON_DATA_REGEXP && bsonRegExp === true) {
  3270. i = index;
  3271. while (buffer2[i] !== 0 && i < buffer2.length) {
  3272. i++;
  3273. }
  3274. if (i >= buffer2.length)
  3275. throw new BSONError("Bad BSON Document: illegal CString");
  3276. const source = ByteUtils.toUTF8(buffer2, index, i);
  3277. index = i + 1;
  3278. i = index;
  3279. while (buffer2[i] !== 0 && i < buffer2.length) {
  3280. i++;
  3281. }
  3282. if (i >= buffer2.length)
  3283. throw new BSONError("Bad BSON Document: illegal CString");
  3284. const regExpOptions = ByteUtils.toUTF8(buffer2, index, i);
  3285. index = i + 1;
  3286. value = new BSONRegExp(source, regExpOptions);
  3287. } else if (elementType === BSON_DATA_SYMBOL) {
  3288. const stringSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3289. if (stringSize <= 0 || stringSize > buffer2.length - index || buffer2[index + stringSize - 1] !== 0) {
  3290. throw new BSONError("bad string length in bson");
  3291. }
  3292. const symbol = getValidatedString(buffer2, index, index + stringSize - 1, shouldValidateKey);
  3293. value = promoteValues ? symbol : new BSONSymbol(symbol);
  3294. index = index + stringSize;
  3295. } else if (elementType === BSON_DATA_TIMESTAMP) {
  3296. const i2 = buffer2[index++] + buffer2[index++] * (1 << 8) + buffer2[index++] * (1 << 16) + buffer2[index++] * (1 << 24);
  3297. const t = buffer2[index++] + buffer2[index++] * (1 << 8) + buffer2[index++] * (1 << 16) + buffer2[index++] * (1 << 24);
  3298. value = new Timestamp({ i: i2, t });
  3299. } else if (elementType === BSON_DATA_MIN_KEY) {
  3300. value = new MinKey();
  3301. } else if (elementType === BSON_DATA_MAX_KEY) {
  3302. value = new MaxKey();
  3303. } else if (elementType === BSON_DATA_CODE) {
  3304. const stringSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3305. if (stringSize <= 0 || stringSize > buffer2.length - index || buffer2[index + stringSize - 1] !== 0) {
  3306. throw new BSONError("bad string length in bson");
  3307. }
  3308. const functionString = getValidatedString(buffer2, index, index + stringSize - 1, shouldValidateKey);
  3309. value = new Code(functionString);
  3310. index = index + stringSize;
  3311. } else if (elementType === BSON_DATA_CODE_W_SCOPE) {
  3312. const totalSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3313. if (totalSize < 4 + 4 + 4 + 1) {
  3314. throw new BSONError("code_w_scope total size shorter minimum expected length");
  3315. }
  3316. const stringSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3317. if (stringSize <= 0 || stringSize > buffer2.length - index || buffer2[index + stringSize - 1] !== 0) {
  3318. throw new BSONError("bad string length in bson");
  3319. }
  3320. const functionString = getValidatedString(buffer2, index, index + stringSize - 1, shouldValidateKey);
  3321. index = index + stringSize;
  3322. const _index = index;
  3323. const objectSize = buffer2[index] | buffer2[index + 1] << 8 | buffer2[index + 2] << 16 | buffer2[index + 3] << 24;
  3324. const scopeObject = deserializeObject(buffer2, _index, options, false);
  3325. index = index + objectSize;
  3326. if (totalSize < 4 + 4 + objectSize + stringSize) {
  3327. throw new BSONError("code_w_scope total size is too short, truncating scope");
  3328. }
  3329. if (totalSize > 4 + 4 + objectSize + stringSize) {
  3330. throw new BSONError("code_w_scope total size is too long, clips outer document");
  3331. }
  3332. value = new Code(functionString, scopeObject);
  3333. } else if (elementType === BSON_DATA_DBPOINTER) {
  3334. const stringSize = buffer2[index++] | buffer2[index++] << 8 | buffer2[index++] << 16 | buffer2[index++] << 24;
  3335. if (stringSize <= 0 || stringSize > buffer2.length - index || buffer2[index + stringSize - 1] !== 0)
  3336. throw new BSONError("bad string length in bson");
  3337. if (validation != null && validation.utf8) {
  3338. if (!validateUtf8(buffer2, index, index + stringSize - 1)) {
  3339. throw new BSONError("Invalid UTF-8 string in BSON document");
  3340. }
  3341. }
  3342. const namespace = ByteUtils.toUTF8(buffer2, index, index + stringSize - 1);
  3343. index = index + stringSize;
  3344. const oidBuffer = ByteUtils.allocate(12);
  3345. oidBuffer.set(buffer2.subarray(index, index + 12), 0);
  3346. const oid = new ObjectId3(oidBuffer);
  3347. index = index + 12;
  3348. value = new DBRef(namespace, oid);
  3349. } else {
  3350. throw new BSONError(`Detected unknown BSON type ${elementType.toString(16)} for fieldname "${name}"`);
  3351. }
  3352. if (name === "__proto__") {
  3353. Object.defineProperty(object, name, {
  3354. value,
  3355. writable: true,
  3356. enumerable: true,
  3357. configurable: true
  3358. });
  3359. } else {
  3360. object[name] = value;
  3361. }
  3362. }
  3363. if (size !== index - startIndex) {
  3364. if (isArray)
  3365. throw new BSONError("corrupt array bson");
  3366. throw new BSONError("corrupt object bson");
  3367. }
  3368. if (!isPossibleDBRef)
  3369. return object;
  3370. if (isDBRefLike(object)) {
  3371. const copy = Object.assign({}, object);
  3372. delete copy.$ref;
  3373. delete copy.$id;
  3374. delete copy.$db;
  3375. return new DBRef(object.$ref, object.$id, object.$db, copy);
  3376. }
  3377. return object;
  3378. }
  3379. function getValidatedString(buffer2, start, end, shouldValidateUtf8) {
  3380. const value = ByteUtils.toUTF8(buffer2, start, end);
  3381. if (shouldValidateUtf8) {
  3382. for (let i = 0; i < value.length; i++) {
  3383. if (value.charCodeAt(i) === 65533) {
  3384. if (!validateUtf8(buffer2, start, end)) {
  3385. throw new BSONError("Invalid UTF-8 string in BSON document");
  3386. }
  3387. break;
  3388. }
  3389. }
  3390. }
  3391. return value;
  3392. }
  3393. var regexp = /\x00/;
  3394. var ignoreKeys = /* @__PURE__ */ new Set(["$db", "$ref", "$id", "$clusterTime"]);
  3395. function serializeString(buffer2, key, value, index) {
  3396. buffer2[index++] = BSON_DATA_STRING;
  3397. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3398. index = index + numberOfWrittenBytes + 1;
  3399. buffer2[index - 1] = 0;
  3400. const size = ByteUtils.encodeUTF8Into(buffer2, value, index + 4);
  3401. buffer2[index + 3] = size + 1 >> 24 & 255;
  3402. buffer2[index + 2] = size + 1 >> 16 & 255;
  3403. buffer2[index + 1] = size + 1 >> 8 & 255;
  3404. buffer2[index] = size + 1 & 255;
  3405. index = index + 4 + size;
  3406. buffer2[index++] = 0;
  3407. return index;
  3408. }
  3409. var NUMBER_SPACE = new DataView(new ArrayBuffer(8), 0, 8);
  3410. var FOUR_BYTE_VIEW_ON_NUMBER = new Uint8Array(NUMBER_SPACE.buffer, 0, 4);
  3411. var EIGHT_BYTE_VIEW_ON_NUMBER = new Uint8Array(NUMBER_SPACE.buffer, 0, 8);
  3412. function serializeNumber(buffer2, key, value, index) {
  3413. const isNegativeZero = Object.is(value, -0);
  3414. const type = !isNegativeZero && Number.isSafeInteger(value) && value <= BSON_INT32_MAX && value >= BSON_INT32_MIN ? BSON_DATA_INT : BSON_DATA_NUMBER;
  3415. if (type === BSON_DATA_INT) {
  3416. NUMBER_SPACE.setInt32(0, value, true);
  3417. } else {
  3418. NUMBER_SPACE.setFloat64(0, value, true);
  3419. }
  3420. const bytes = type === BSON_DATA_INT ? FOUR_BYTE_VIEW_ON_NUMBER : EIGHT_BYTE_VIEW_ON_NUMBER;
  3421. buffer2[index++] = type;
  3422. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3423. index = index + numberOfWrittenBytes;
  3424. buffer2[index++] = 0;
  3425. buffer2.set(bytes, index);
  3426. index += bytes.byteLength;
  3427. return index;
  3428. }
  3429. function serializeBigInt(buffer2, key, value, index) {
  3430. buffer2[index++] = BSON_DATA_LONG;
  3431. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3432. index += numberOfWrittenBytes;
  3433. buffer2[index++] = 0;
  3434. NUMBER_SPACE.setBigInt64(0, value, true);
  3435. buffer2.set(EIGHT_BYTE_VIEW_ON_NUMBER, index);
  3436. index += EIGHT_BYTE_VIEW_ON_NUMBER.byteLength;
  3437. return index;
  3438. }
  3439. function serializeNull(buffer2, key, _, index) {
  3440. buffer2[index++] = BSON_DATA_NULL;
  3441. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3442. index = index + numberOfWrittenBytes;
  3443. buffer2[index++] = 0;
  3444. return index;
  3445. }
  3446. function serializeBoolean(buffer2, key, value, index) {
  3447. buffer2[index++] = BSON_DATA_BOOLEAN;
  3448. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3449. index = index + numberOfWrittenBytes;
  3450. buffer2[index++] = 0;
  3451. buffer2[index++] = value ? 1 : 0;
  3452. return index;
  3453. }
  3454. function serializeDate(buffer2, key, value, index) {
  3455. buffer2[index++] = BSON_DATA_DATE;
  3456. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3457. index = index + numberOfWrittenBytes;
  3458. buffer2[index++] = 0;
  3459. const dateInMilis = Long.fromNumber(value.getTime());
  3460. const lowBits = dateInMilis.getLowBits();
  3461. const highBits = dateInMilis.getHighBits();
  3462. buffer2[index++] = lowBits & 255;
  3463. buffer2[index++] = lowBits >> 8 & 255;
  3464. buffer2[index++] = lowBits >> 16 & 255;
  3465. buffer2[index++] = lowBits >> 24 & 255;
  3466. buffer2[index++] = highBits & 255;
  3467. buffer2[index++] = highBits >> 8 & 255;
  3468. buffer2[index++] = highBits >> 16 & 255;
  3469. buffer2[index++] = highBits >> 24 & 255;
  3470. return index;
  3471. }
  3472. function serializeRegExp(buffer2, key, value, index) {
  3473. buffer2[index++] = BSON_DATA_REGEXP;
  3474. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3475. index = index + numberOfWrittenBytes;
  3476. buffer2[index++] = 0;
  3477. if (value.source && value.source.match(regexp) != null) {
  3478. throw new BSONError("value " + value.source + " must not contain null bytes");
  3479. }
  3480. index = index + ByteUtils.encodeUTF8Into(buffer2, value.source, index);
  3481. buffer2[index++] = 0;
  3482. if (value.ignoreCase)
  3483. buffer2[index++] = 105;
  3484. if (value.global)
  3485. buffer2[index++] = 115;
  3486. if (value.multiline)
  3487. buffer2[index++] = 109;
  3488. buffer2[index++] = 0;
  3489. return index;
  3490. }
  3491. function serializeBSONRegExp(buffer2, key, value, index) {
  3492. buffer2[index++] = BSON_DATA_REGEXP;
  3493. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3494. index = index + numberOfWrittenBytes;
  3495. buffer2[index++] = 0;
  3496. if (value.pattern.match(regexp) != null) {
  3497. throw new BSONError("pattern " + value.pattern + " must not contain null bytes");
  3498. }
  3499. index = index + ByteUtils.encodeUTF8Into(buffer2, value.pattern, index);
  3500. buffer2[index++] = 0;
  3501. const sortedOptions = value.options.split("").sort().join("");
  3502. index = index + ByteUtils.encodeUTF8Into(buffer2, sortedOptions, index);
  3503. buffer2[index++] = 0;
  3504. return index;
  3505. }
  3506. function serializeMinMax(buffer2, key, value, index) {
  3507. if (value === null) {
  3508. buffer2[index++] = BSON_DATA_NULL;
  3509. } else if (value._bsontype === "MinKey") {
  3510. buffer2[index++] = BSON_DATA_MIN_KEY;
  3511. } else {
  3512. buffer2[index++] = BSON_DATA_MAX_KEY;
  3513. }
  3514. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3515. index = index + numberOfWrittenBytes;
  3516. buffer2[index++] = 0;
  3517. return index;
  3518. }
  3519. function serializeObjectId(buffer2, key, value, index) {
  3520. buffer2[index++] = BSON_DATA_OID;
  3521. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3522. index = index + numberOfWrittenBytes;
  3523. buffer2[index++] = 0;
  3524. if (isUint8Array(value.id)) {
  3525. buffer2.set(value.id.subarray(0, 12), index);
  3526. } else {
  3527. throw new BSONError("object [" + JSON.stringify(value) + "] is not a valid ObjectId");
  3528. }
  3529. return index + 12;
  3530. }
  3531. function serializeBuffer(buffer2, key, value, index) {
  3532. buffer2[index++] = BSON_DATA_BINARY;
  3533. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3534. index = index + numberOfWrittenBytes;
  3535. buffer2[index++] = 0;
  3536. const size = value.length;
  3537. buffer2[index++] = size & 255;
  3538. buffer2[index++] = size >> 8 & 255;
  3539. buffer2[index++] = size >> 16 & 255;
  3540. buffer2[index++] = size >> 24 & 255;
  3541. buffer2[index++] = BSON_BINARY_SUBTYPE_DEFAULT;
  3542. buffer2.set(value, index);
  3543. index = index + size;
  3544. return index;
  3545. }
  3546. function serializeObject(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path) {
  3547. if (path.has(value)) {
  3548. throw new BSONError("Cannot convert circular structure to BSON");
  3549. }
  3550. path.add(value);
  3551. buffer2[index++] = Array.isArray(value) ? BSON_DATA_ARRAY : BSON_DATA_OBJECT;
  3552. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3553. index = index + numberOfWrittenBytes;
  3554. buffer2[index++] = 0;
  3555. const endIndex = serializeInto(buffer2, value, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path);
  3556. path.delete(value);
  3557. return endIndex;
  3558. }
  3559. function serializeDecimal128(buffer2, key, value, index) {
  3560. buffer2[index++] = BSON_DATA_DECIMAL128;
  3561. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3562. index = index + numberOfWrittenBytes;
  3563. buffer2[index++] = 0;
  3564. buffer2.set(value.bytes.subarray(0, 16), index);
  3565. return index + 16;
  3566. }
  3567. function serializeLong(buffer2, key, value, index) {
  3568. buffer2[index++] = value._bsontype === "Long" ? BSON_DATA_LONG : BSON_DATA_TIMESTAMP;
  3569. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3570. index = index + numberOfWrittenBytes;
  3571. buffer2[index++] = 0;
  3572. const lowBits = value.getLowBits();
  3573. const highBits = value.getHighBits();
  3574. buffer2[index++] = lowBits & 255;
  3575. buffer2[index++] = lowBits >> 8 & 255;
  3576. buffer2[index++] = lowBits >> 16 & 255;
  3577. buffer2[index++] = lowBits >> 24 & 255;
  3578. buffer2[index++] = highBits & 255;
  3579. buffer2[index++] = highBits >> 8 & 255;
  3580. buffer2[index++] = highBits >> 16 & 255;
  3581. buffer2[index++] = highBits >> 24 & 255;
  3582. return index;
  3583. }
  3584. function serializeInt32(buffer2, key, value, index) {
  3585. value = value.valueOf();
  3586. buffer2[index++] = BSON_DATA_INT;
  3587. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3588. index = index + numberOfWrittenBytes;
  3589. buffer2[index++] = 0;
  3590. buffer2[index++] = value & 255;
  3591. buffer2[index++] = value >> 8 & 255;
  3592. buffer2[index++] = value >> 16 & 255;
  3593. buffer2[index++] = value >> 24 & 255;
  3594. return index;
  3595. }
  3596. function serializeDouble(buffer2, key, value, index) {
  3597. buffer2[index++] = BSON_DATA_NUMBER;
  3598. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3599. index = index + numberOfWrittenBytes;
  3600. buffer2[index++] = 0;
  3601. NUMBER_SPACE.setFloat64(0, value.value, true);
  3602. buffer2.set(EIGHT_BYTE_VIEW_ON_NUMBER, index);
  3603. index = index + 8;
  3604. return index;
  3605. }
  3606. function serializeFunction(buffer2, key, value, index) {
  3607. buffer2[index++] = BSON_DATA_CODE;
  3608. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3609. index = index + numberOfWrittenBytes;
  3610. buffer2[index++] = 0;
  3611. const functionString = value.toString();
  3612. const size = ByteUtils.encodeUTF8Into(buffer2, functionString, index + 4) + 1;
  3613. buffer2[index] = size & 255;
  3614. buffer2[index + 1] = size >> 8 & 255;
  3615. buffer2[index + 2] = size >> 16 & 255;
  3616. buffer2[index + 3] = size >> 24 & 255;
  3617. index = index + 4 + size - 1;
  3618. buffer2[index++] = 0;
  3619. return index;
  3620. }
  3621. function serializeCode(buffer2, key, value, index, checkKeys = false, depth = 0, serializeFunctions = false, ignoreUndefined = true, path) {
  3622. if (value.scope && typeof value.scope === "object") {
  3623. buffer2[index++] = BSON_DATA_CODE_W_SCOPE;
  3624. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3625. index = index + numberOfWrittenBytes;
  3626. buffer2[index++] = 0;
  3627. let startIndex = index;
  3628. const functionString = value.code;
  3629. index = index + 4;
  3630. const codeSize = ByteUtils.encodeUTF8Into(buffer2, functionString, index + 4) + 1;
  3631. buffer2[index] = codeSize & 255;
  3632. buffer2[index + 1] = codeSize >> 8 & 255;
  3633. buffer2[index + 2] = codeSize >> 16 & 255;
  3634. buffer2[index + 3] = codeSize >> 24 & 255;
  3635. buffer2[index + 4 + codeSize - 1] = 0;
  3636. index = index + codeSize + 4;
  3637. const endIndex = serializeInto(buffer2, value.scope, checkKeys, index, depth + 1, serializeFunctions, ignoreUndefined, path);
  3638. index = endIndex - 1;
  3639. const totalSize = endIndex - startIndex;
  3640. buffer2[startIndex++] = totalSize & 255;
  3641. buffer2[startIndex++] = totalSize >> 8 & 255;
  3642. buffer2[startIndex++] = totalSize >> 16 & 255;
  3643. buffer2[startIndex++] = totalSize >> 24 & 255;
  3644. buffer2[index++] = 0;
  3645. } else {
  3646. buffer2[index++] = BSON_DATA_CODE;
  3647. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3648. index = index + numberOfWrittenBytes;
  3649. buffer2[index++] = 0;
  3650. const functionString = value.code.toString();
  3651. const size = ByteUtils.encodeUTF8Into(buffer2, functionString, index + 4) + 1;
  3652. buffer2[index] = size & 255;
  3653. buffer2[index + 1] = size >> 8 & 255;
  3654. buffer2[index + 2] = size >> 16 & 255;
  3655. buffer2[index + 3] = size >> 24 & 255;
  3656. index = index + 4 + size - 1;
  3657. buffer2[index++] = 0;
  3658. }
  3659. return index;
  3660. }
  3661. function serializeBinary(buffer2, key, value, index) {
  3662. buffer2[index++] = BSON_DATA_BINARY;
  3663. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3664. index = index + numberOfWrittenBytes;
  3665. buffer2[index++] = 0;
  3666. const data = value.buffer;
  3667. let size = value.position;
  3668. if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY)
  3669. size = size + 4;
  3670. buffer2[index++] = size & 255;
  3671. buffer2[index++] = size >> 8 & 255;
  3672. buffer2[index++] = size >> 16 & 255;
  3673. buffer2[index++] = size >> 24 & 255;
  3674. buffer2[index++] = value.sub_type;
  3675. if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
  3676. size = size - 4;
  3677. buffer2[index++] = size & 255;
  3678. buffer2[index++] = size >> 8 & 255;
  3679. buffer2[index++] = size >> 16 & 255;
  3680. buffer2[index++] = size >> 24 & 255;
  3681. }
  3682. buffer2.set(data, index);
  3683. index = index + value.position;
  3684. return index;
  3685. }
  3686. function serializeSymbol(buffer2, key, value, index) {
  3687. buffer2[index++] = BSON_DATA_SYMBOL;
  3688. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3689. index = index + numberOfWrittenBytes;
  3690. buffer2[index++] = 0;
  3691. const size = ByteUtils.encodeUTF8Into(buffer2, value.value, index + 4) + 1;
  3692. buffer2[index] = size & 255;
  3693. buffer2[index + 1] = size >> 8 & 255;
  3694. buffer2[index + 2] = size >> 16 & 255;
  3695. buffer2[index + 3] = size >> 24 & 255;
  3696. index = index + 4 + size - 1;
  3697. buffer2[index++] = 0;
  3698. return index;
  3699. }
  3700. function serializeDBRef(buffer2, key, value, index, depth, serializeFunctions, path) {
  3701. buffer2[index++] = BSON_DATA_OBJECT;
  3702. const numberOfWrittenBytes = ByteUtils.encodeUTF8Into(buffer2, key, index);
  3703. index = index + numberOfWrittenBytes;
  3704. buffer2[index++] = 0;
  3705. let startIndex = index;
  3706. let output = {
  3707. $ref: value.collection || value.namespace,
  3708. $id: value.oid
  3709. };
  3710. if (value.db != null) {
  3711. output.$db = value.db;
  3712. }
  3713. output = Object.assign(output, value.fields);
  3714. const endIndex = serializeInto(buffer2, output, false, index, depth + 1, serializeFunctions, true, path);
  3715. const size = endIndex - startIndex;
  3716. buffer2[startIndex++] = size & 255;
  3717. buffer2[startIndex++] = size >> 8 & 255;
  3718. buffer2[startIndex++] = size >> 16 & 255;
  3719. buffer2[startIndex++] = size >> 24 & 255;
  3720. return endIndex;
  3721. }
  3722. function serializeInto(buffer2, object, checkKeys, startingIndex, depth, serializeFunctions, ignoreUndefined, path) {
  3723. if (path == null) {
  3724. if (object == null) {
  3725. buffer2[0] = 5;
  3726. buffer2[1] = 0;
  3727. buffer2[2] = 0;
  3728. buffer2[3] = 0;
  3729. buffer2[4] = 0;
  3730. return 5;
  3731. }
  3732. if (Array.isArray(object)) {
  3733. throw new BSONError("serialize does not support an array as the root input");
  3734. }
  3735. if (typeof object !== "object") {
  3736. throw new BSONError("serialize does not support non-object as the root input");
  3737. } else if ("_bsontype" in object && typeof object._bsontype === "string") {
  3738. throw new BSONError(`BSON types cannot be serialized as a document`);
  3739. } else if (isDate(object) || isRegExp(object) || isUint8Array(object) || isAnyArrayBuffer(object)) {
  3740. throw new BSONError(`date, regexp, typedarray, and arraybuffer cannot be BSON documents`);
  3741. }
  3742. path = /* @__PURE__ */ new Set();
  3743. }
  3744. path.add(object);
  3745. let index = startingIndex + 4;
  3746. if (Array.isArray(object)) {
  3747. for (let i = 0; i < object.length; i++) {
  3748. const key = `${i}`;
  3749. let value = object[i];
  3750. if (typeof (value == null ? void 0 : value.toBSON) === "function") {
  3751. value = value.toBSON();
  3752. }
  3753. if (typeof value === "string") {
  3754. index = serializeString(buffer2, key, value, index);
  3755. } else if (typeof value === "number") {
  3756. index = serializeNumber(buffer2, key, value, index);
  3757. } else if (typeof value === "bigint") {
  3758. index = serializeBigInt(buffer2, key, value, index);
  3759. } else if (typeof value === "boolean") {
  3760. index = serializeBoolean(buffer2, key, value, index);
  3761. } else if (value instanceof Date || isDate(value)) {
  3762. index = serializeDate(buffer2, key, value, index);
  3763. } else if (value === void 0) {
  3764. index = serializeNull(buffer2, key, value, index);
  3765. } else if (value === null) {
  3766. index = serializeNull(buffer2, key, value, index);
  3767. } else if (isUint8Array(value)) {
  3768. index = serializeBuffer(buffer2, key, value, index);
  3769. } else if (value instanceof RegExp || isRegExp(value)) {
  3770. index = serializeRegExp(buffer2, key, value, index);
  3771. } else if (typeof value === "object" && value._bsontype == null) {
  3772. index = serializeObject(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3773. } else if (typeof value === "object" && value[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
  3774. throw new BSONVersionError();
  3775. } else if (value._bsontype === "ObjectId") {
  3776. index = serializeObjectId(buffer2, key, value, index);
  3777. } else if (value._bsontype === "Decimal128") {
  3778. index = serializeDecimal128(buffer2, key, value, index);
  3779. } else if (value._bsontype === "Long" || value._bsontype === "Timestamp") {
  3780. index = serializeLong(buffer2, key, value, index);
  3781. } else if (value._bsontype === "Double") {
  3782. index = serializeDouble(buffer2, key, value, index);
  3783. } else if (typeof value === "function" && serializeFunctions) {
  3784. index = serializeFunction(buffer2, key, value, index);
  3785. } else if (value._bsontype === "Code") {
  3786. index = serializeCode(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3787. } else if (value._bsontype === "Binary") {
  3788. index = serializeBinary(buffer2, key, value, index);
  3789. } else if (value._bsontype === "BSONSymbol") {
  3790. index = serializeSymbol(buffer2, key, value, index);
  3791. } else if (value._bsontype === "DBRef") {
  3792. index = serializeDBRef(buffer2, key, value, index, depth, serializeFunctions, path);
  3793. } else if (value._bsontype === "BSONRegExp") {
  3794. index = serializeBSONRegExp(buffer2, key, value, index);
  3795. } else if (value._bsontype === "Int32") {
  3796. index = serializeInt32(buffer2, key, value, index);
  3797. } else if (value._bsontype === "MinKey" || value._bsontype === "MaxKey") {
  3798. index = serializeMinMax(buffer2, key, value, index);
  3799. } else if (typeof value._bsontype !== "undefined") {
  3800. throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
  3801. }
  3802. }
  3803. } else if (object instanceof Map || isMap(object)) {
  3804. const iterator = object.entries();
  3805. let done = false;
  3806. while (!done) {
  3807. const entry = iterator.next();
  3808. done = !!entry.done;
  3809. if (done)
  3810. continue;
  3811. const key = entry.value[0];
  3812. let value = entry.value[1];
  3813. if (typeof (value == null ? void 0 : value.toBSON) === "function") {
  3814. value = value.toBSON();
  3815. }
  3816. const type = typeof value;
  3817. if (typeof key === "string" && !ignoreKeys.has(key)) {
  3818. if (key.match(regexp) != null) {
  3819. throw new BSONError("key " + key + " must not contain null bytes");
  3820. }
  3821. if (checkKeys) {
  3822. if ("$" === key[0]) {
  3823. throw new BSONError("key " + key + " must not start with '$'");
  3824. } else if (~key.indexOf(".")) {
  3825. throw new BSONError("key " + key + " must not contain '.'");
  3826. }
  3827. }
  3828. }
  3829. if (type === "string") {
  3830. index = serializeString(buffer2, key, value, index);
  3831. } else if (type === "number") {
  3832. index = serializeNumber(buffer2, key, value, index);
  3833. } else if (type === "bigint") {
  3834. index = serializeBigInt(buffer2, key, value, index);
  3835. } else if (type === "boolean") {
  3836. index = serializeBoolean(buffer2, key, value, index);
  3837. } else if (value instanceof Date || isDate(value)) {
  3838. index = serializeDate(buffer2, key, value, index);
  3839. } else if (value === null || value === void 0 && ignoreUndefined === false) {
  3840. index = serializeNull(buffer2, key, value, index);
  3841. } else if (isUint8Array(value)) {
  3842. index = serializeBuffer(buffer2, key, value, index);
  3843. } else if (value instanceof RegExp || isRegExp(value)) {
  3844. index = serializeRegExp(buffer2, key, value, index);
  3845. } else if (type === "object" && value._bsontype == null) {
  3846. index = serializeObject(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3847. } else if (typeof value === "object" && value[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
  3848. throw new BSONVersionError();
  3849. } else if (value._bsontype === "ObjectId") {
  3850. index = serializeObjectId(buffer2, key, value, index);
  3851. } else if (type === "object" && value._bsontype === "Decimal128") {
  3852. index = serializeDecimal128(buffer2, key, value, index);
  3853. } else if (value._bsontype === "Long" || value._bsontype === "Timestamp") {
  3854. index = serializeLong(buffer2, key, value, index);
  3855. } else if (value._bsontype === "Double") {
  3856. index = serializeDouble(buffer2, key, value, index);
  3857. } else if (value._bsontype === "Code") {
  3858. index = serializeCode(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3859. } else if (typeof value === "function" && serializeFunctions) {
  3860. index = serializeFunction(buffer2, key, value, index);
  3861. } else if (value._bsontype === "Binary") {
  3862. index = serializeBinary(buffer2, key, value, index);
  3863. } else if (value._bsontype === "BSONSymbol") {
  3864. index = serializeSymbol(buffer2, key, value, index);
  3865. } else if (value._bsontype === "DBRef") {
  3866. index = serializeDBRef(buffer2, key, value, index, depth, serializeFunctions, path);
  3867. } else if (value._bsontype === "BSONRegExp") {
  3868. index = serializeBSONRegExp(buffer2, key, value, index);
  3869. } else if (value._bsontype === "Int32") {
  3870. index = serializeInt32(buffer2, key, value, index);
  3871. } else if (value._bsontype === "MinKey" || value._bsontype === "MaxKey") {
  3872. index = serializeMinMax(buffer2, key, value, index);
  3873. } else if (typeof value._bsontype !== "undefined") {
  3874. throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
  3875. }
  3876. }
  3877. } else {
  3878. if (typeof (object == null ? void 0 : object.toBSON) === "function") {
  3879. object = object.toBSON();
  3880. if (object != null && typeof object !== "object") {
  3881. throw new BSONError("toBSON function did not return an object");
  3882. }
  3883. }
  3884. for (const key of Object.keys(object)) {
  3885. let value = object[key];
  3886. if (typeof (value == null ? void 0 : value.toBSON) === "function") {
  3887. value = value.toBSON();
  3888. }
  3889. const type = typeof value;
  3890. if (typeof key === "string" && !ignoreKeys.has(key)) {
  3891. if (key.match(regexp) != null) {
  3892. throw new BSONError("key " + key + " must not contain null bytes");
  3893. }
  3894. if (checkKeys) {
  3895. if ("$" === key[0]) {
  3896. throw new BSONError("key " + key + " must not start with '$'");
  3897. } else if (~key.indexOf(".")) {
  3898. throw new BSONError("key " + key + " must not contain '.'");
  3899. }
  3900. }
  3901. }
  3902. if (type === "string") {
  3903. index = serializeString(buffer2, key, value, index);
  3904. } else if (type === "number") {
  3905. index = serializeNumber(buffer2, key, value, index);
  3906. } else if (type === "bigint") {
  3907. index = serializeBigInt(buffer2, key, value, index);
  3908. } else if (type === "boolean") {
  3909. index = serializeBoolean(buffer2, key, value, index);
  3910. } else if (value instanceof Date || isDate(value)) {
  3911. index = serializeDate(buffer2, key, value, index);
  3912. } else if (value === void 0) {
  3913. if (ignoreUndefined === false)
  3914. index = serializeNull(buffer2, key, value, index);
  3915. } else if (value === null) {
  3916. index = serializeNull(buffer2, key, value, index);
  3917. } else if (isUint8Array(value)) {
  3918. index = serializeBuffer(buffer2, key, value, index);
  3919. } else if (value instanceof RegExp || isRegExp(value)) {
  3920. index = serializeRegExp(buffer2, key, value, index);
  3921. } else if (type === "object" && value._bsontype == null) {
  3922. index = serializeObject(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3923. } else if (typeof value === "object" && value[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
  3924. throw new BSONVersionError();
  3925. } else if (value._bsontype === "ObjectId") {
  3926. index = serializeObjectId(buffer2, key, value, index);
  3927. } else if (type === "object" && value._bsontype === "Decimal128") {
  3928. index = serializeDecimal128(buffer2, key, value, index);
  3929. } else if (value._bsontype === "Long" || value._bsontype === "Timestamp") {
  3930. index = serializeLong(buffer2, key, value, index);
  3931. } else if (value._bsontype === "Double") {
  3932. index = serializeDouble(buffer2, key, value, index);
  3933. } else if (value._bsontype === "Code") {
  3934. index = serializeCode(buffer2, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
  3935. } else if (typeof value === "function" && serializeFunctions) {
  3936. index = serializeFunction(buffer2, key, value, index);
  3937. } else if (value._bsontype === "Binary") {
  3938. index = serializeBinary(buffer2, key, value, index);
  3939. } else if (value._bsontype === "BSONSymbol") {
  3940. index = serializeSymbol(buffer2, key, value, index);
  3941. } else if (value._bsontype === "DBRef") {
  3942. index = serializeDBRef(buffer2, key, value, index, depth, serializeFunctions, path);
  3943. } else if (value._bsontype === "BSONRegExp") {
  3944. index = serializeBSONRegExp(buffer2, key, value, index);
  3945. } else if (value._bsontype === "Int32") {
  3946. index = serializeInt32(buffer2, key, value, index);
  3947. } else if (value._bsontype === "MinKey" || value._bsontype === "MaxKey") {
  3948. index = serializeMinMax(buffer2, key, value, index);
  3949. } else if (typeof value._bsontype !== "undefined") {
  3950. throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
  3951. }
  3952. }
  3953. }
  3954. path.delete(object);
  3955. buffer2[index++] = 0;
  3956. const size = index - startingIndex;
  3957. buffer2[startingIndex++] = size & 255;
  3958. buffer2[startingIndex++] = size >> 8 & 255;
  3959. buffer2[startingIndex++] = size >> 16 & 255;
  3960. buffer2[startingIndex++] = size >> 24 & 255;
  3961. return index;
  3962. }
  3963. function isBSONType(value) {
  3964. return value != null && typeof value === "object" && "_bsontype" in value && typeof value._bsontype === "string";
  3965. }
  3966. var keysToCodecs = {
  3967. $oid: ObjectId3,
  3968. $binary: Binary,
  3969. $uuid: Binary,
  3970. $symbol: BSONSymbol,
  3971. $numberInt: Int32,
  3972. $numberDecimal: Decimal128,
  3973. $numberDouble: Double,
  3974. $numberLong: Long,
  3975. $minKey: MinKey,
  3976. $maxKey: MaxKey,
  3977. $regex: BSONRegExp,
  3978. $regularExpression: BSONRegExp,
  3979. $timestamp: Timestamp
  3980. };
  3981. function deserializeValue(value, options = {}) {
  3982. if (typeof value === "number") {
  3983. const in32BitRange = value <= BSON_INT32_MAX && value >= BSON_INT32_MIN;
  3984. const in64BitRange = value <= BSON_INT64_MAX && value >= BSON_INT64_MIN;
  3985. if (options.relaxed || options.legacy) {
  3986. return value;
  3987. }
  3988. if (Number.isInteger(value) && !Object.is(value, -0)) {
  3989. if (in32BitRange) {
  3990. return new Int32(value);
  3991. }
  3992. if (in64BitRange) {
  3993. if (options.useBigInt64) {
  3994. return BigInt(value);
  3995. }
  3996. return Long.fromNumber(value);
  3997. }
  3998. }
  3999. return new Double(value);
  4000. }
  4001. if (value == null || typeof value !== "object")
  4002. return value;
  4003. if (value.$undefined)
  4004. return null;
  4005. const keys = Object.keys(value).filter((k) => k.startsWith("$") && value[k] != null);
  4006. for (let i = 0; i < keys.length; i++) {
  4007. const c = keysToCodecs[keys[i]];
  4008. if (c)
  4009. return c.fromExtendedJSON(value, options);
  4010. }
  4011. if (value.$date != null) {
  4012. const d = value.$date;
  4013. const date = /* @__PURE__ */ new Date();
  4014. if (options.legacy) {
  4015. if (typeof d === "number")
  4016. date.setTime(d);
  4017. else if (typeof d === "string")
  4018. date.setTime(Date.parse(d));
  4019. else if (typeof d === "bigint")
  4020. date.setTime(Number(d));
  4021. else
  4022. throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
  4023. } else {
  4024. if (typeof d === "string")
  4025. date.setTime(Date.parse(d));
  4026. else if (Long.isLong(d))
  4027. date.setTime(d.toNumber());
  4028. else if (typeof d === "number" && options.relaxed)
  4029. date.setTime(d);
  4030. else if (typeof d === "bigint")
  4031. date.setTime(Number(d));
  4032. else
  4033. throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
  4034. }
  4035. return date;
  4036. }
  4037. if (value.$code != null) {
  4038. const copy = Object.assign({}, value);
  4039. if (value.$scope) {
  4040. copy.$scope = deserializeValue(value.$scope);
  4041. }
  4042. return Code.fromExtendedJSON(value);
  4043. }
  4044. if (isDBRefLike(value) || value.$dbPointer) {
  4045. const v = value.$ref ? value : value.$dbPointer;
  4046. if (v instanceof DBRef)
  4047. return v;
  4048. const dollarKeys = Object.keys(v).filter((k) => k.startsWith("$"));
  4049. let valid = true;
  4050. dollarKeys.forEach((k) => {
  4051. if (["$ref", "$id", "$db"].indexOf(k) === -1)
  4052. valid = false;
  4053. });
  4054. if (valid)
  4055. return DBRef.fromExtendedJSON(v);
  4056. }
  4057. return value;
  4058. }
  4059. function serializeArray(array, options) {
  4060. return array.map((v, index) => {
  4061. options.seenObjects.push({ propertyName: `index ${index}`, obj: null });
  4062. try {
  4063. return serializeValue(v, options);
  4064. } finally {
  4065. options.seenObjects.pop();
  4066. }
  4067. });
  4068. }
  4069. function getISOString(date) {
  4070. const isoStr = date.toISOString();
  4071. return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + "Z";
  4072. }
  4073. function serializeValue(value, options) {
  4074. if (value instanceof Map || isMap(value)) {
  4075. const obj = /* @__PURE__ */ Object.create(null);
  4076. for (const [k, v] of value) {
  4077. if (typeof k !== "string") {
  4078. throw new BSONError("Can only serialize maps with string keys");
  4079. }
  4080. obj[k] = v;
  4081. }
  4082. return serializeValue(obj, options);
  4083. }
  4084. if ((typeof value === "object" || typeof value === "function") && value !== null) {
  4085. const index = options.seenObjects.findIndex((entry) => entry.obj === value);
  4086. if (index !== -1) {
  4087. const props = options.seenObjects.map((entry) => entry.propertyName);
  4088. const leadingPart = props.slice(0, index).map((prop) => `${prop} -> `).join("");
  4089. const alreadySeen = props[index];
  4090. const circularPart = " -> " + props.slice(index + 1, props.length - 1).map((prop) => `${prop} -> `).join("");
  4091. const current = props[props.length - 1];
  4092. const leadingSpace = " ".repeat(leadingPart.length + alreadySeen.length / 2);
  4093. const dashes = "-".repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
  4094. throw new BSONError(`Converting circular structure to EJSON:
  4095. ${leadingPart}${alreadySeen}${circularPart}${current}
  4096. ${leadingSpace}\\${dashes}/`);
  4097. }
  4098. options.seenObjects[options.seenObjects.length - 1].obj = value;
  4099. }
  4100. if (Array.isArray(value))
  4101. return serializeArray(value, options);
  4102. if (value === void 0)
  4103. return null;
  4104. if (value instanceof Date || isDate(value)) {
  4105. const dateNum = value.getTime(), inRange = dateNum > -1 && dateNum < 2534023188e5;
  4106. if (options.legacy) {
  4107. return options.relaxed && inRange ? { $date: value.getTime() } : { $date: getISOString(value) };
  4108. }
  4109. return options.relaxed && inRange ? { $date: getISOString(value) } : { $date: { $numberLong: value.getTime().toString() } };
  4110. }
  4111. if (typeof value === "number" && (!options.relaxed || !isFinite(value))) {
  4112. if (Number.isInteger(value) && !Object.is(value, -0)) {
  4113. if (value >= BSON_INT32_MIN && value <= BSON_INT32_MAX) {
  4114. return { $numberInt: value.toString() };
  4115. }
  4116. if (value >= BSON_INT64_MIN && value <= BSON_INT64_MAX) {
  4117. return { $numberLong: value.toString() };
  4118. }
  4119. }
  4120. return { $numberDouble: Object.is(value, -0) ? "-0.0" : value.toString() };
  4121. }
  4122. if (typeof value === "bigint") {
  4123. if (!options.relaxed) {
  4124. return { $numberLong: BigInt.asIntN(64, value).toString() };
  4125. }
  4126. return Number(BigInt.asIntN(64, value));
  4127. }
  4128. if (value instanceof RegExp || isRegExp(value)) {
  4129. let flags = value.flags;
  4130. if (flags === void 0) {
  4131. const match = value.toString().match(/[gimuy]*$/);
  4132. if (match) {
  4133. flags = match[0];
  4134. }
  4135. }
  4136. const rx = new BSONRegExp(value.source, flags);
  4137. return rx.toExtendedJSON(options);
  4138. }
  4139. if (value != null && typeof value === "object")
  4140. return serializeDocument(value, options);
  4141. return value;
  4142. }
  4143. var BSON_TYPE_MAPPINGS = {
  4144. Binary: (o) => new Binary(o.value(), o.sub_type),
  4145. Code: (o) => new Code(o.code, o.scope),
  4146. DBRef: (o) => new DBRef(o.collection || o.namespace, o.oid, o.db, o.fields),
  4147. Decimal128: (o) => new Decimal128(o.bytes),
  4148. Double: (o) => new Double(o.value),
  4149. Int32: (o) => new Int32(o.value),
  4150. Long: (o) => Long.fromBits(o.low != null ? o.low : o.low_, o.low != null ? o.high : o.high_, o.low != null ? o.unsigned : o.unsigned_),
  4151. MaxKey: () => new MaxKey(),
  4152. MinKey: () => new MinKey(),
  4153. ObjectId: (o) => new ObjectId3(o),
  4154. BSONRegExp: (o) => new BSONRegExp(o.pattern, o.options),
  4155. BSONSymbol: (o) => new BSONSymbol(o.value),
  4156. Timestamp: (o) => Timestamp.fromBits(o.low, o.high)
  4157. };
  4158. function serializeDocument(doc, options) {
  4159. if (doc == null || typeof doc !== "object")
  4160. throw new BSONError("not an object instance");
  4161. const bsontype = doc._bsontype;
  4162. if (typeof bsontype === "undefined") {
  4163. const _doc = {};
  4164. for (const name of Object.keys(doc)) {
  4165. options.seenObjects.push({ propertyName: name, obj: null });
  4166. try {
  4167. const value = serializeValue(doc[name], options);
  4168. if (name === "__proto__") {
  4169. Object.defineProperty(_doc, name, {
  4170. value,
  4171. writable: true,
  4172. enumerable: true,
  4173. configurable: true
  4174. });
  4175. } else {
  4176. _doc[name] = value;
  4177. }
  4178. } finally {
  4179. options.seenObjects.pop();
  4180. }
  4181. }
  4182. return _doc;
  4183. } else if (doc != null && typeof doc === "object" && typeof doc._bsontype === "string" && doc[Symbol.for("@@mdb.bson.version")] !== BSON_MAJOR_VERSION) {
  4184. throw new BSONVersionError();
  4185. } else if (isBSONType(doc)) {
  4186. let outDoc = doc;
  4187. if (typeof outDoc.toExtendedJSON !== "function") {
  4188. const mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
  4189. if (!mapper) {
  4190. throw new BSONError("Unrecognized or invalid _bsontype: " + doc._bsontype);
  4191. }
  4192. outDoc = mapper(outDoc);
  4193. }
  4194. if (bsontype === "Code" && outDoc.scope) {
  4195. outDoc = new Code(outDoc.code, serializeValue(outDoc.scope, options));
  4196. } else if (bsontype === "DBRef" && outDoc.oid) {
  4197. outDoc = new DBRef(serializeValue(outDoc.collection, options), serializeValue(outDoc.oid, options), serializeValue(outDoc.db, options), serializeValue(outDoc.fields, options));
  4198. }
  4199. return outDoc.toExtendedJSON(options);
  4200. } else {
  4201. throw new BSONError("_bsontype must be a string, but was: " + typeof bsontype);
  4202. }
  4203. }
  4204. function parse(text, options) {
  4205. const ejsonOptions = {
  4206. useBigInt64: (options == null ? void 0 : options.useBigInt64) ?? false,
  4207. relaxed: (options == null ? void 0 : options.relaxed) ?? true,
  4208. legacy: (options == null ? void 0 : options.legacy) ?? false
  4209. };
  4210. return JSON.parse(text, (key, value) => {
  4211. if (key.indexOf("\0") !== -1) {
  4212. throw new BSONError(`BSON Document field names cannot contain null bytes, found: ${JSON.stringify(key)}`);
  4213. }
  4214. return deserializeValue(value, ejsonOptions);
  4215. });
  4216. }
  4217. function stringify(value, replacer, space, options) {
  4218. if (space != null && typeof space === "object") {
  4219. options = space;
  4220. space = 0;
  4221. }
  4222. if (replacer != null && typeof replacer === "object" && !Array.isArray(replacer)) {
  4223. options = replacer;
  4224. replacer = void 0;
  4225. space = 0;
  4226. }
  4227. const serializeOptions = Object.assign({ relaxed: true, legacy: false }, options, {
  4228. seenObjects: [{ propertyName: "(root)", obj: null }]
  4229. });
  4230. const doc = serializeValue(value, serializeOptions);
  4231. return JSON.stringify(doc, replacer, space);
  4232. }
  4233. function EJSONserialize(value, options) {
  4234. options = options || {};
  4235. return JSON.parse(stringify(value, options));
  4236. }
  4237. function EJSONdeserialize(ejson, options) {
  4238. options = options || {};
  4239. return parse(JSON.stringify(ejson), options);
  4240. }
  4241. var EJSON = /* @__PURE__ */ Object.create(null);
  4242. EJSON.parse = parse;
  4243. EJSON.stringify = stringify;
  4244. EJSON.serialize = EJSONserialize;
  4245. EJSON.deserialize = EJSONdeserialize;
  4246. Object.freeze(EJSON);
  4247. var MAXSIZE = 1024 * 1024 * 17;
  4248. var buffer = ByteUtils.allocate(MAXSIZE);
  4249. function setInternalBufferSize(size) {
  4250. if (buffer.length < size) {
  4251. buffer = ByteUtils.allocate(size);
  4252. }
  4253. }
  4254. function serialize(object, options = {}) {
  4255. const checkKeys = typeof options.checkKeys === "boolean" ? options.checkKeys : false;
  4256. const serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
  4257. const ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : true;
  4258. const minInternalBufferSize = typeof options.minInternalBufferSize === "number" ? options.minInternalBufferSize : MAXSIZE;
  4259. if (buffer.length < minInternalBufferSize) {
  4260. buffer = ByteUtils.allocate(minInternalBufferSize);
  4261. }
  4262. const serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, null);
  4263. const finishedBuffer = ByteUtils.allocate(serializationIndex);
  4264. finishedBuffer.set(buffer.subarray(0, serializationIndex), 0);
  4265. return finishedBuffer;
  4266. }
  4267. function serializeWithBufferAndIndex(object, finalBuffer, options = {}) {
  4268. const checkKeys = typeof options.checkKeys === "boolean" ? options.checkKeys : false;
  4269. const serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
  4270. const ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : true;
  4271. const startIndex = typeof options.index === "number" ? options.index : 0;
  4272. const serializationIndex = serializeInto(buffer, object, checkKeys, 0, 0, serializeFunctions, ignoreUndefined, null);
  4273. finalBuffer.set(buffer.subarray(0, serializationIndex), startIndex);
  4274. return startIndex + serializationIndex - 1;
  4275. }
  4276. function deserialize(buffer2, options = {}) {
  4277. return internalDeserialize(ByteUtils.toLocalBufferType(buffer2), options);
  4278. }
  4279. function calculateObjectSize(object, options = {}) {
  4280. options = options || {};
  4281. const serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
  4282. const ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : true;
  4283. return internalCalculateObjectSize(object, serializeFunctions, ignoreUndefined);
  4284. }
  4285. function deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex, options) {
  4286. const internalOptions = Object.assign({ allowObjectSmallerThanBufferSize: true, index: 0 }, options);
  4287. const bufferData = ByteUtils.toLocalBufferType(data);
  4288. let index = startIndex;
  4289. for (let i = 0; i < numberOfDocuments; i++) {
  4290. const size = bufferData[index] | bufferData[index + 1] << 8 | bufferData[index + 2] << 16 | bufferData[index + 3] << 24;
  4291. internalOptions.index = index;
  4292. documents[docStartIndex + i] = internalDeserialize(bufferData, internalOptions);
  4293. index = index + size;
  4294. }
  4295. return index;
  4296. }
  4297. var bson = /* @__PURE__ */ Object.freeze({
  4298. __proto__: null,
  4299. BSONError,
  4300. BSONRegExp,
  4301. BSONRuntimeError,
  4302. BSONSymbol,
  4303. BSONType,
  4304. BSONValue,
  4305. BSONVersionError,
  4306. Binary,
  4307. Code,
  4308. DBRef,
  4309. Decimal128,
  4310. Double,
  4311. EJSON,
  4312. Int32,
  4313. Long,
  4314. MaxKey,
  4315. MinKey,
  4316. ObjectId: ObjectId3,
  4317. Timestamp,
  4318. UUID,
  4319. calculateObjectSize,
  4320. deserialize,
  4321. deserializeStream,
  4322. serialize,
  4323. serializeWithBufferAndIndex,
  4324. setInternalBufferSize
  4325. });
  4326. exports2.BSON = bson;
  4327. exports2.BSONError = BSONError;
  4328. exports2.BSONRegExp = BSONRegExp;
  4329. exports2.BSONRuntimeError = BSONRuntimeError;
  4330. exports2.BSONSymbol = BSONSymbol;
  4331. exports2.BSONType = BSONType;
  4332. exports2.BSONValue = BSONValue;
  4333. exports2.BSONVersionError = BSONVersionError;
  4334. exports2.Binary = Binary;
  4335. exports2.Code = Code;
  4336. exports2.DBRef = DBRef;
  4337. exports2.Decimal128 = Decimal128;
  4338. exports2.Double = Double;
  4339. exports2.EJSON = EJSON;
  4340. exports2.Int32 = Int32;
  4341. exports2.Long = Long;
  4342. exports2.MaxKey = MaxKey;
  4343. exports2.MinKey = MinKey;
  4344. exports2.ObjectId = ObjectId3;
  4345. exports2.Timestamp = Timestamp;
  4346. exports2.UUID = UUID;
  4347. exports2.calculateObjectSize = calculateObjectSize;
  4348. exports2.deserialize = deserialize;
  4349. exports2.deserializeStream = deserializeStream;
  4350. exports2.serialize = serialize;
  4351. exports2.serializeWithBufferAndIndex = serializeWithBufferAndIndex;
  4352. exports2.setInternalBufferSize = setInternalBufferSize;
  4353. }
  4354. });
  4355. // node_modules/mongodb/lib/bson.js
  4356. var require_bson2 = __commonJS({
  4357. "node_modules/mongodb/lib/bson.js"(exports2) {
  4358. "use strict";
  4359. Object.defineProperty(exports2, "__esModule", { value: true });
  4360. exports2.resolveBSONOptions = exports2.pluckBSONSerializeOptions = exports2.Timestamp = exports2.serialize = exports2.ObjectId = exports2.MinKey = exports2.MaxKey = exports2.Long = exports2.Int32 = exports2.Double = exports2.deserialize = exports2.Decimal128 = exports2.DBRef = exports2.Code = exports2.calculateObjectSize = exports2.BSONType = exports2.BSONSymbol = exports2.BSONRegExp = exports2.BSON = exports2.Binary = void 0;
  4361. var bson_1 = require_bson();
  4362. Object.defineProperty(exports2, "Binary", { enumerable: true, get: function() {
  4363. return bson_1.Binary;
  4364. } });
  4365. Object.defineProperty(exports2, "BSON", { enumerable: true, get: function() {
  4366. return bson_1.BSON;
  4367. } });
  4368. Object.defineProperty(exports2, "BSONRegExp", { enumerable: true, get: function() {
  4369. return bson_1.BSONRegExp;
  4370. } });
  4371. Object.defineProperty(exports2, "BSONSymbol", { enumerable: true, get: function() {
  4372. return bson_1.BSONSymbol;
  4373. } });
  4374. Object.defineProperty(exports2, "BSONType", { enumerable: true, get: function() {
  4375. return bson_1.BSONType;
  4376. } });
  4377. Object.defineProperty(exports2, "calculateObjectSize", { enumerable: true, get: function() {
  4378. return bson_1.calculateObjectSize;
  4379. } });
  4380. Object.defineProperty(exports2, "Code", { enumerable: true, get: function() {
  4381. return bson_1.Code;
  4382. } });
  4383. Object.defineProperty(exports2, "DBRef", { enumerable: true, get: function() {
  4384. return bson_1.DBRef;
  4385. } });
  4386. Object.defineProperty(exports2, "Decimal128", { enumerable: true, get: function() {
  4387. return bson_1.Decimal128;
  4388. } });
  4389. Object.defineProperty(exports2, "deserialize", { enumerable: true, get: function() {
  4390. return bson_1.deserialize;
  4391. } });
  4392. Object.defineProperty(exports2, "Double", { enumerable: true, get: function() {
  4393. return bson_1.Double;
  4394. } });
  4395. Object.defineProperty(exports2, "Int32", { enumerable: true, get: function() {
  4396. return bson_1.Int32;
  4397. } });
  4398. Object.defineProperty(exports2, "Long", { enumerable: true, get: function() {
  4399. return bson_1.Long;
  4400. } });
  4401. Object.defineProperty(exports2, "MaxKey", { enumerable: true, get: function() {
  4402. return bson_1.MaxKey;
  4403. } });
  4404. Object.defineProperty(exports2, "MinKey", { enumerable: true, get: function() {
  4405. return bson_1.MinKey;
  4406. } });
  4407. Object.defineProperty(exports2, "ObjectId", { enumerable: true, get: function() {
  4408. return bson_1.ObjectId;
  4409. } });
  4410. Object.defineProperty(exports2, "serialize", { enumerable: true, get: function() {
  4411. return bson_1.serialize;
  4412. } });
  4413. Object.defineProperty(exports2, "Timestamp", { enumerable: true, get: function() {
  4414. return bson_1.Timestamp;
  4415. } });
  4416. function pluckBSONSerializeOptions(options) {
  4417. const { fieldsAsRaw, useBigInt64, promoteValues, promoteBuffers, promoteLongs, serializeFunctions, ignoreUndefined, bsonRegExp, raw, enableUtf8Validation } = options;
  4418. return {
  4419. fieldsAsRaw,
  4420. useBigInt64,
  4421. promoteValues,
  4422. promoteBuffers,
  4423. promoteLongs,
  4424. serializeFunctions,
  4425. ignoreUndefined,
  4426. bsonRegExp,
  4427. raw,
  4428. enableUtf8Validation
  4429. };
  4430. }
  4431. exports2.pluckBSONSerializeOptions = pluckBSONSerializeOptions;
  4432. function resolveBSONOptions(options, parent) {
  4433. const parentOptions = parent == null ? void 0 : parent.bsonOptions;
  4434. return {
  4435. raw: (options == null ? void 0 : options.raw) ?? (parentOptions == null ? void 0 : parentOptions.raw) ?? false,
  4436. useBigInt64: (options == null ? void 0 : options.useBigInt64) ?? (parentOptions == null ? void 0 : parentOptions.useBigInt64) ?? false,
  4437. promoteLongs: (options == null ? void 0 : options.promoteLongs) ?? (parentOptions == null ? void 0 : parentOptions.promoteLongs) ?? true,
  4438. promoteValues: (options == null ? void 0 : options.promoteValues) ?? (parentOptions == null ? void 0 : parentOptions.promoteValues) ?? true,
  4439. promoteBuffers: (options == null ? void 0 : options.promoteBuffers) ?? (parentOptions == null ? void 0 : parentOptions.promoteBuffers) ?? false,
  4440. ignoreUndefined: (options == null ? void 0 : options.ignoreUndefined) ?? (parentOptions == null ? void 0 : parentOptions.ignoreUndefined) ?? false,
  4441. bsonRegExp: (options == null ? void 0 : options.bsonRegExp) ?? (parentOptions == null ? void 0 : parentOptions.bsonRegExp) ?? false,
  4442. serializeFunctions: (options == null ? void 0 : options.serializeFunctions) ?? (parentOptions == null ? void 0 : parentOptions.serializeFunctions) ?? false,
  4443. fieldsAsRaw: (options == null ? void 0 : options.fieldsAsRaw) ?? (parentOptions == null ? void 0 : parentOptions.fieldsAsRaw) ?? {},
  4444. enableUtf8Validation: (options == null ? void 0 : options.enableUtf8Validation) ?? (parentOptions == null ? void 0 : parentOptions.enableUtf8Validation) ?? true
  4445. };
  4446. }
  4447. exports2.resolveBSONOptions = resolveBSONOptions;
  4448. }
  4449. });
  4450. // node_modules/mongodb/lib/cmap/wire_protocol/constants.js
  4451. var require_constants = __commonJS({
  4452. "node_modules/mongodb/lib/cmap/wire_protocol/constants.js"(exports2) {
  4453. "use strict";
  4454. Object.defineProperty(exports2, "__esModule", { value: true });
  4455. exports2.OP_MSG = exports2.OP_COMPRESSED = exports2.OP_DELETE = exports2.OP_QUERY = exports2.OP_INSERT = exports2.OP_UPDATE = exports2.OP_REPLY = exports2.MIN_SUPPORTED_QE_SERVER_VERSION = exports2.MIN_SUPPORTED_QE_WIRE_VERSION = exports2.MAX_SUPPORTED_WIRE_VERSION = exports2.MIN_SUPPORTED_WIRE_VERSION = exports2.MAX_SUPPORTED_SERVER_VERSION = exports2.MIN_SUPPORTED_SERVER_VERSION = void 0;
  4456. exports2.MIN_SUPPORTED_SERVER_VERSION = "3.6";
  4457. exports2.MAX_SUPPORTED_SERVER_VERSION = "7.0";
  4458. exports2.MIN_SUPPORTED_WIRE_VERSION = 6;
  4459. exports2.MAX_SUPPORTED_WIRE_VERSION = 21;
  4460. exports2.MIN_SUPPORTED_QE_WIRE_VERSION = 21;
  4461. exports2.MIN_SUPPORTED_QE_SERVER_VERSION = "7.0";
  4462. exports2.OP_REPLY = 1;
  4463. exports2.OP_UPDATE = 2001;
  4464. exports2.OP_INSERT = 2002;
  4465. exports2.OP_QUERY = 2004;
  4466. exports2.OP_DELETE = 2006;
  4467. exports2.OP_COMPRESSED = 2012;
  4468. exports2.OP_MSG = 2013;
  4469. }
  4470. });
  4471. // node_modules/mongodb/lib/constants.js
  4472. var require_constants2 = __commonJS({
  4473. "node_modules/mongodb/lib/constants.js"(exports2) {
  4474. "use strict";
  4475. Object.defineProperty(exports2, "__esModule", { value: true });
  4476. exports2.TOPOLOGY_EVENTS = exports2.CMAP_EVENTS = exports2.HEARTBEAT_EVENTS = exports2.RESUME_TOKEN_CHANGED = exports2.END = exports2.CHANGE = exports2.INIT = exports2.MORE = exports2.RESPONSE = exports2.SERVER_HEARTBEAT_FAILED = exports2.SERVER_HEARTBEAT_SUCCEEDED = exports2.SERVER_HEARTBEAT_STARTED = exports2.COMMAND_FAILED = exports2.COMMAND_SUCCEEDED = exports2.COMMAND_STARTED = exports2.CLUSTER_TIME_RECEIVED = exports2.CONNECTION_CHECKED_IN = exports2.CONNECTION_CHECKED_OUT = exports2.CONNECTION_CHECK_OUT_FAILED = exports2.CONNECTION_CHECK_OUT_STARTED = exports2.CONNECTION_CLOSED = exports2.CONNECTION_READY = exports2.CONNECTION_CREATED = exports2.CONNECTION_POOL_READY = exports2.CONNECTION_POOL_CLEARED = exports2.CONNECTION_POOL_CLOSED = exports2.CONNECTION_POOL_CREATED = exports2.TOPOLOGY_DESCRIPTION_CHANGED = exports2.TOPOLOGY_CLOSED = exports2.TOPOLOGY_OPENING = exports2.SERVER_DESCRIPTION_CHANGED = exports2.SERVER_CLOSED = exports2.SERVER_OPENING = exports2.DESCRIPTION_RECEIVED = exports2.UNPINNED = exports2.PINNED = exports2.MESSAGE = exports2.ENDED = exports2.CLOSED = exports2.CONNECT = exports2.OPEN = exports2.CLOSE = exports2.TIMEOUT = exports2.ERROR = exports2.SYSTEM_JS_COLLECTION = exports2.SYSTEM_COMMAND_COLLECTION = exports2.SYSTEM_USER_COLLECTION = exports2.SYSTEM_PROFILE_COLLECTION = exports2.SYSTEM_INDEX_COLLECTION = exports2.SYSTEM_NAMESPACE_COLLECTION = void 0;
  4477. exports2.LEGACY_HELLO_COMMAND_CAMEL_CASE = exports2.LEGACY_HELLO_COMMAND = exports2.MONGO_CLIENT_EVENTS = exports2.LOCAL_SERVER_EVENTS = exports2.SERVER_RELAY_EVENTS = exports2.APM_EVENTS = void 0;
  4478. exports2.SYSTEM_NAMESPACE_COLLECTION = "system.namespaces";
  4479. exports2.SYSTEM_INDEX_COLLECTION = "system.indexes";
  4480. exports2.SYSTEM_PROFILE_COLLECTION = "system.profile";
  4481. exports2.SYSTEM_USER_COLLECTION = "system.users";
  4482. exports2.SYSTEM_COMMAND_COLLECTION = "$cmd";
  4483. exports2.SYSTEM_JS_COLLECTION = "system.js";
  4484. exports2.ERROR = "error";
  4485. exports2.TIMEOUT = "timeout";
  4486. exports2.CLOSE = "close";
  4487. exports2.OPEN = "open";
  4488. exports2.CONNECT = "connect";
  4489. exports2.CLOSED = "closed";
  4490. exports2.ENDED = "ended";
  4491. exports2.MESSAGE = "message";
  4492. exports2.PINNED = "pinned";
  4493. exports2.UNPINNED = "unpinned";
  4494. exports2.DESCRIPTION_RECEIVED = "descriptionReceived";
  4495. exports2.SERVER_OPENING = "serverOpening";
  4496. exports2.SERVER_CLOSED = "serverClosed";
  4497. exports2.SERVER_DESCRIPTION_CHANGED = "serverDescriptionChanged";
  4498. exports2.TOPOLOGY_OPENING = "topologyOpening";
  4499. exports2.TOPOLOGY_CLOSED = "topologyClosed";
  4500. exports2.TOPOLOGY_DESCRIPTION_CHANGED = "topologyDescriptionChanged";
  4501. exports2.CONNECTION_POOL_CREATED = "connectionPoolCreated";
  4502. exports2.CONNECTION_POOL_CLOSED = "connectionPoolClosed";
  4503. exports2.CONNECTION_POOL_CLEARED = "connectionPoolCleared";
  4504. exports2.CONNECTION_POOL_READY = "connectionPoolReady";
  4505. exports2.CONNECTION_CREATED = "connectionCreated";
  4506. exports2.CONNECTION_READY = "connectionReady";
  4507. exports2.CONNECTION_CLOSED = "connectionClosed";
  4508. exports2.CONNECTION_CHECK_OUT_STARTED = "connectionCheckOutStarted";
  4509. exports2.CONNECTION_CHECK_OUT_FAILED = "connectionCheckOutFailed";
  4510. exports2.CONNECTION_CHECKED_OUT = "connectionCheckedOut";
  4511. exports2.CONNECTION_CHECKED_IN = "connectionCheckedIn";
  4512. exports2.CLUSTER_TIME_RECEIVED = "clusterTimeReceived";
  4513. exports2.COMMAND_STARTED = "commandStarted";
  4514. exports2.COMMAND_SUCCEEDED = "commandSucceeded";
  4515. exports2.COMMAND_FAILED = "commandFailed";
  4516. exports2.SERVER_HEARTBEAT_STARTED = "serverHeartbeatStarted";
  4517. exports2.SERVER_HEARTBEAT_SUCCEEDED = "serverHeartbeatSucceeded";
  4518. exports2.SERVER_HEARTBEAT_FAILED = "serverHeartbeatFailed";
  4519. exports2.RESPONSE = "response";
  4520. exports2.MORE = "more";
  4521. exports2.INIT = "init";
  4522. exports2.CHANGE = "change";
  4523. exports2.END = "end";
  4524. exports2.RESUME_TOKEN_CHANGED = "resumeTokenChanged";
  4525. exports2.HEARTBEAT_EVENTS = Object.freeze([
  4526. exports2.SERVER_HEARTBEAT_STARTED,
  4527. exports2.SERVER_HEARTBEAT_SUCCEEDED,
  4528. exports2.SERVER_HEARTBEAT_FAILED
  4529. ]);
  4530. exports2.CMAP_EVENTS = Object.freeze([
  4531. exports2.CONNECTION_POOL_CREATED,
  4532. exports2.CONNECTION_POOL_READY,
  4533. exports2.CONNECTION_POOL_CLEARED,
  4534. exports2.CONNECTION_POOL_CLOSED,
  4535. exports2.CONNECTION_CREATED,
  4536. exports2.CONNECTION_READY,
  4537. exports2.CONNECTION_CLOSED,
  4538. exports2.CONNECTION_CHECK_OUT_STARTED,
  4539. exports2.CONNECTION_CHECK_OUT_FAILED,
  4540. exports2.CONNECTION_CHECKED_OUT,
  4541. exports2.CONNECTION_CHECKED_IN
  4542. ]);
  4543. exports2.TOPOLOGY_EVENTS = Object.freeze([
  4544. exports2.SERVER_OPENING,
  4545. exports2.SERVER_CLOSED,
  4546. exports2.SERVER_DESCRIPTION_CHANGED,
  4547. exports2.TOPOLOGY_OPENING,
  4548. exports2.TOPOLOGY_CLOSED,
  4549. exports2.TOPOLOGY_DESCRIPTION_CHANGED,
  4550. exports2.ERROR,
  4551. exports2.TIMEOUT,
  4552. exports2.CLOSE
  4553. ]);
  4554. exports2.APM_EVENTS = Object.freeze([
  4555. exports2.COMMAND_STARTED,
  4556. exports2.COMMAND_SUCCEEDED,
  4557. exports2.COMMAND_FAILED
  4558. ]);
  4559. exports2.SERVER_RELAY_EVENTS = Object.freeze([
  4560. exports2.SERVER_HEARTBEAT_STARTED,
  4561. exports2.SERVER_HEARTBEAT_SUCCEEDED,
  4562. exports2.SERVER_HEARTBEAT_FAILED,
  4563. exports2.COMMAND_STARTED,
  4564. exports2.COMMAND_SUCCEEDED,
  4565. exports2.COMMAND_FAILED,
  4566. ...exports2.CMAP_EVENTS
  4567. ]);
  4568. exports2.LOCAL_SERVER_EVENTS = Object.freeze([
  4569. exports2.CONNECT,
  4570. exports2.DESCRIPTION_RECEIVED,
  4571. exports2.CLOSED,
  4572. exports2.ENDED
  4573. ]);
  4574. exports2.MONGO_CLIENT_EVENTS = Object.freeze([
  4575. ...exports2.CMAP_EVENTS,
  4576. ...exports2.APM_EVENTS,
  4577. ...exports2.TOPOLOGY_EVENTS,
  4578. ...exports2.HEARTBEAT_EVENTS
  4579. ]);
  4580. exports2.LEGACY_HELLO_COMMAND = "ismaster";
  4581. exports2.LEGACY_HELLO_COMMAND_CAMEL_CASE = "isMaster";
  4582. }
  4583. });
  4584. // node_modules/mongodb/lib/read_concern.js
  4585. var require_read_concern = __commonJS({
  4586. "node_modules/mongodb/lib/read_concern.js"(exports2) {
  4587. "use strict";
  4588. Object.defineProperty(exports2, "__esModule", { value: true });
  4589. exports2.ReadConcern = exports2.ReadConcernLevel = void 0;
  4590. exports2.ReadConcernLevel = Object.freeze({
  4591. local: "local",
  4592. majority: "majority",
  4593. linearizable: "linearizable",
  4594. available: "available",
  4595. snapshot: "snapshot"
  4596. });
  4597. var ReadConcern = class _ReadConcern {
  4598. /** Constructs a ReadConcern from the read concern level.*/
  4599. constructor(level) {
  4600. this.level = exports2.ReadConcernLevel[level] ?? level;
  4601. }
  4602. /**
  4603. * Construct a ReadConcern given an options object.
  4604. *
  4605. * @param options - The options object from which to extract the write concern.
  4606. */
  4607. static fromOptions(options) {
  4608. if (options == null) {
  4609. return;
  4610. }
  4611. if (options.readConcern) {
  4612. const { readConcern } = options;
  4613. if (readConcern instanceof _ReadConcern) {
  4614. return readConcern;
  4615. } else if (typeof readConcern === "string") {
  4616. return new _ReadConcern(readConcern);
  4617. } else if ("level" in readConcern && readConcern.level) {
  4618. return new _ReadConcern(readConcern.level);
  4619. }
  4620. }
  4621. if (options.level) {
  4622. return new _ReadConcern(options.level);
  4623. }
  4624. return;
  4625. }
  4626. static get MAJORITY() {
  4627. return exports2.ReadConcernLevel.majority;
  4628. }
  4629. static get AVAILABLE() {
  4630. return exports2.ReadConcernLevel.available;
  4631. }
  4632. static get LINEARIZABLE() {
  4633. return exports2.ReadConcernLevel.linearizable;
  4634. }
  4635. static get SNAPSHOT() {
  4636. return exports2.ReadConcernLevel.snapshot;
  4637. }
  4638. toJSON() {
  4639. return { level: this.level };
  4640. }
  4641. };
  4642. exports2.ReadConcern = ReadConcern;
  4643. }
  4644. });
  4645. // node_modules/mongodb/lib/read_preference.js
  4646. var require_read_preference = __commonJS({
  4647. "node_modules/mongodb/lib/read_preference.js"(exports2) {
  4648. "use strict";
  4649. Object.defineProperty(exports2, "__esModule", { value: true });
  4650. exports2.ReadPreference = exports2.ReadPreferenceMode = void 0;
  4651. var error_1 = require_error();
  4652. exports2.ReadPreferenceMode = Object.freeze({
  4653. primary: "primary",
  4654. primaryPreferred: "primaryPreferred",
  4655. secondary: "secondary",
  4656. secondaryPreferred: "secondaryPreferred",
  4657. nearest: "nearest"
  4658. });
  4659. var ReadPreference = class _ReadPreference {
  4660. /**
  4661. * @param mode - A string describing the read preference mode (primary|primaryPreferred|secondary|secondaryPreferred|nearest)
  4662. * @param tags - A tag set used to target reads to members with the specified tag(s). tagSet is not available if using read preference mode primary.
  4663. * @param options - Additional read preference options
  4664. */
  4665. constructor(mode, tags, options) {
  4666. if (!_ReadPreference.isValid(mode)) {
  4667. throw new error_1.MongoInvalidArgumentError(`Invalid read preference mode ${JSON.stringify(mode)}`);
  4668. }
  4669. if (options == null && typeof tags === "object" && !Array.isArray(tags)) {
  4670. options = tags;
  4671. tags = void 0;
  4672. } else if (tags && !Array.isArray(tags)) {
  4673. throw new error_1.MongoInvalidArgumentError("ReadPreference tags must be an array");
  4674. }
  4675. this.mode = mode;
  4676. this.tags = tags;
  4677. this.hedge = options == null ? void 0 : options.hedge;
  4678. this.maxStalenessSeconds = void 0;
  4679. this.minWireVersion = void 0;
  4680. options = options ?? {};
  4681. if (options.maxStalenessSeconds != null) {
  4682. if (options.maxStalenessSeconds <= 0) {
  4683. throw new error_1.MongoInvalidArgumentError("maxStalenessSeconds must be a positive integer");
  4684. }
  4685. this.maxStalenessSeconds = options.maxStalenessSeconds;
  4686. this.minWireVersion = 5;
  4687. }
  4688. if (this.mode === _ReadPreference.PRIMARY) {
  4689. if (this.tags && Array.isArray(this.tags) && this.tags.length > 0) {
  4690. throw new error_1.MongoInvalidArgumentError("Primary read preference cannot be combined with tags");
  4691. }
  4692. if (this.maxStalenessSeconds) {
  4693. throw new error_1.MongoInvalidArgumentError("Primary read preference cannot be combined with maxStalenessSeconds");
  4694. }
  4695. if (this.hedge) {
  4696. throw new error_1.MongoInvalidArgumentError("Primary read preference cannot be combined with hedge");
  4697. }
  4698. }
  4699. }
  4700. // Support the deprecated `preference` property introduced in the porcelain layer
  4701. get preference() {
  4702. return this.mode;
  4703. }
  4704. static fromString(mode) {
  4705. return new _ReadPreference(mode);
  4706. }
  4707. /**
  4708. * Construct a ReadPreference given an options object.
  4709. *
  4710. * @param options - The options object from which to extract the read preference.
  4711. */
  4712. static fromOptions(options) {
  4713. var _a;
  4714. if (!options)
  4715. return;
  4716. const readPreference = options.readPreference ?? ((_a = options.session) == null ? void 0 : _a.transaction.options.readPreference);
  4717. const readPreferenceTags = options.readPreferenceTags;
  4718. if (readPreference == null) {
  4719. return;
  4720. }
  4721. if (typeof readPreference === "string") {
  4722. return new _ReadPreference(readPreference, readPreferenceTags, {
  4723. maxStalenessSeconds: options.maxStalenessSeconds,
  4724. hedge: options.hedge
  4725. });
  4726. } else if (!(readPreference instanceof _ReadPreference) && typeof readPreference === "object") {
  4727. const mode = readPreference.mode || readPreference.preference;
  4728. if (mode && typeof mode === "string") {
  4729. return new _ReadPreference(mode, readPreference.tags ?? readPreferenceTags, {
  4730. maxStalenessSeconds: readPreference.maxStalenessSeconds,
  4731. hedge: options.hedge
  4732. });
  4733. }
  4734. }
  4735. if (readPreferenceTags) {
  4736. readPreference.tags = readPreferenceTags;
  4737. }
  4738. return readPreference;
  4739. }
  4740. /**
  4741. * Replaces options.readPreference with a ReadPreference instance
  4742. */
  4743. static translate(options) {
  4744. if (options.readPreference == null)
  4745. return options;
  4746. const r = options.readPreference;
  4747. if (typeof r === "string") {
  4748. options.readPreference = new _ReadPreference(r);
  4749. } else if (r && !(r instanceof _ReadPreference) && typeof r === "object") {
  4750. const mode = r.mode || r.preference;
  4751. if (mode && typeof mode === "string") {
  4752. options.readPreference = new _ReadPreference(mode, r.tags, {
  4753. maxStalenessSeconds: r.maxStalenessSeconds
  4754. });
  4755. }
  4756. } else if (!(r instanceof _ReadPreference)) {
  4757. throw new error_1.MongoInvalidArgumentError(`Invalid read preference: ${r}`);
  4758. }
  4759. return options;
  4760. }
  4761. /**
  4762. * Validate if a mode is legal
  4763. *
  4764. * @param mode - The string representing the read preference mode.
  4765. */
  4766. static isValid(mode) {
  4767. const VALID_MODES = /* @__PURE__ */ new Set([
  4768. _ReadPreference.PRIMARY,
  4769. _ReadPreference.PRIMARY_PREFERRED,
  4770. _ReadPreference.SECONDARY,
  4771. _ReadPreference.SECONDARY_PREFERRED,
  4772. _ReadPreference.NEAREST,
  4773. null
  4774. ]);
  4775. return VALID_MODES.has(mode);
  4776. }
  4777. /**
  4778. * Validate if a mode is legal
  4779. *
  4780. * @param mode - The string representing the read preference mode.
  4781. */
  4782. isValid(mode) {
  4783. return _ReadPreference.isValid(typeof mode === "string" ? mode : this.mode);
  4784. }
  4785. /**
  4786. * Indicates that this readPreference needs the "SecondaryOk" bit when sent over the wire
  4787. * @see https://www.mongodb.com/docs/manual/reference/mongodb-wire-protocol/#op-query
  4788. */
  4789. secondaryOk() {
  4790. const NEEDS_SECONDARYOK = /* @__PURE__ */ new Set([
  4791. _ReadPreference.PRIMARY_PREFERRED,
  4792. _ReadPreference.SECONDARY,
  4793. _ReadPreference.SECONDARY_PREFERRED,
  4794. _ReadPreference.NEAREST
  4795. ]);
  4796. return NEEDS_SECONDARYOK.has(this.mode);
  4797. }
  4798. /**
  4799. * Check if the two ReadPreferences are equivalent
  4800. *
  4801. * @param readPreference - The read preference with which to check equality
  4802. */
  4803. equals(readPreference) {
  4804. return readPreference.mode === this.mode;
  4805. }
  4806. /** Return JSON representation */
  4807. toJSON() {
  4808. const readPreference = { mode: this.mode };
  4809. if (Array.isArray(this.tags))
  4810. readPreference.tags = this.tags;
  4811. if (this.maxStalenessSeconds)
  4812. readPreference.maxStalenessSeconds = this.maxStalenessSeconds;
  4813. if (this.hedge)
  4814. readPreference.hedge = this.hedge;
  4815. return readPreference;
  4816. }
  4817. };
  4818. ReadPreference.PRIMARY = exports2.ReadPreferenceMode.primary;
  4819. ReadPreference.PRIMARY_PREFERRED = exports2.ReadPreferenceMode.primaryPreferred;
  4820. ReadPreference.SECONDARY = exports2.ReadPreferenceMode.secondary;
  4821. ReadPreference.SECONDARY_PREFERRED = exports2.ReadPreferenceMode.secondaryPreferred;
  4822. ReadPreference.NEAREST = exports2.ReadPreferenceMode.nearest;
  4823. ReadPreference.primary = new ReadPreference(exports2.ReadPreferenceMode.primary);
  4824. ReadPreference.primaryPreferred = new ReadPreference(exports2.ReadPreferenceMode.primaryPreferred);
  4825. ReadPreference.secondary = new ReadPreference(exports2.ReadPreferenceMode.secondary);
  4826. ReadPreference.secondaryPreferred = new ReadPreference(exports2.ReadPreferenceMode.secondaryPreferred);
  4827. ReadPreference.nearest = new ReadPreference(exports2.ReadPreferenceMode.nearest);
  4828. exports2.ReadPreference = ReadPreference;
  4829. }
  4830. });
  4831. // node_modules/mongodb/lib/sdam/common.js
  4832. var require_common = __commonJS({
  4833. "node_modules/mongodb/lib/sdam/common.js"(exports2) {
  4834. "use strict";
  4835. Object.defineProperty(exports2, "__esModule", { value: true });
  4836. exports2._advanceClusterTime = exports2.drainTimerQueue = exports2.ServerType = exports2.TopologyType = exports2.STATE_CONNECTED = exports2.STATE_CONNECTING = exports2.STATE_CLOSED = exports2.STATE_CLOSING = void 0;
  4837. var timers_1 = require("timers");
  4838. exports2.STATE_CLOSING = "closing";
  4839. exports2.STATE_CLOSED = "closed";
  4840. exports2.STATE_CONNECTING = "connecting";
  4841. exports2.STATE_CONNECTED = "connected";
  4842. exports2.TopologyType = Object.freeze({
  4843. Single: "Single",
  4844. ReplicaSetNoPrimary: "ReplicaSetNoPrimary",
  4845. ReplicaSetWithPrimary: "ReplicaSetWithPrimary",
  4846. Sharded: "Sharded",
  4847. Unknown: "Unknown",
  4848. LoadBalanced: "LoadBalanced"
  4849. });
  4850. exports2.ServerType = Object.freeze({
  4851. Standalone: "Standalone",
  4852. Mongos: "Mongos",
  4853. PossiblePrimary: "PossiblePrimary",
  4854. RSPrimary: "RSPrimary",
  4855. RSSecondary: "RSSecondary",
  4856. RSArbiter: "RSArbiter",
  4857. RSOther: "RSOther",
  4858. RSGhost: "RSGhost",
  4859. Unknown: "Unknown",
  4860. LoadBalancer: "LoadBalancer"
  4861. });
  4862. function drainTimerQueue(queue) {
  4863. queue.forEach(timers_1.clearTimeout);
  4864. queue.clear();
  4865. }
  4866. exports2.drainTimerQueue = drainTimerQueue;
  4867. function _advanceClusterTime(entity, $clusterTime) {
  4868. if (entity.clusterTime == null) {
  4869. entity.clusterTime = $clusterTime;
  4870. } else {
  4871. if ($clusterTime.clusterTime.greaterThan(entity.clusterTime.clusterTime)) {
  4872. entity.clusterTime = $clusterTime;
  4873. }
  4874. }
  4875. }
  4876. exports2._advanceClusterTime = _advanceClusterTime;
  4877. }
  4878. });
  4879. // node_modules/mongodb/lib/write_concern.js
  4880. var require_write_concern = __commonJS({
  4881. "node_modules/mongodb/lib/write_concern.js"(exports2) {
  4882. "use strict";
  4883. Object.defineProperty(exports2, "__esModule", { value: true });
  4884. exports2.WriteConcern = exports2.WRITE_CONCERN_KEYS = void 0;
  4885. exports2.WRITE_CONCERN_KEYS = ["w", "wtimeout", "j", "journal", "fsync"];
  4886. var WriteConcern = class _WriteConcern {
  4887. /**
  4888. * Constructs a WriteConcern from the write concern properties.
  4889. * @param w - request acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags.
  4890. * @param wtimeoutMS - specify a time limit to prevent write operations from blocking indefinitely
  4891. * @param journal - request acknowledgment that the write operation has been written to the on-disk journal
  4892. * @param fsync - equivalent to the j option. Is deprecated and will be removed in the next major version.
  4893. */
  4894. constructor(w, wtimeoutMS, journal, fsync) {
  4895. if (w != null) {
  4896. if (!Number.isNaN(Number(w))) {
  4897. this.w = Number(w);
  4898. } else {
  4899. this.w = w;
  4900. }
  4901. }
  4902. if (wtimeoutMS != null) {
  4903. this.wtimeoutMS = this.wtimeout = wtimeoutMS;
  4904. }
  4905. if (journal != null) {
  4906. this.journal = this.j = journal;
  4907. }
  4908. if (fsync != null) {
  4909. this.journal = this.j = fsync ? true : false;
  4910. }
  4911. }
  4912. /**
  4913. * Apply a write concern to a command document. Will modify and return the command.
  4914. */
  4915. static apply(command, writeConcern) {
  4916. const wc = {};
  4917. if (writeConcern.w != null)
  4918. wc.w = writeConcern.w;
  4919. if (writeConcern.wtimeoutMS != null)
  4920. wc.wtimeout = writeConcern.wtimeoutMS;
  4921. if (writeConcern.journal != null)
  4922. wc.j = writeConcern.j;
  4923. command.writeConcern = wc;
  4924. return command;
  4925. }
  4926. /** Construct a WriteConcern given an options object. */
  4927. static fromOptions(options, inherit) {
  4928. if (options == null)
  4929. return void 0;
  4930. inherit = inherit ?? {};
  4931. let opts;
  4932. if (typeof options === "string" || typeof options === "number") {
  4933. opts = { w: options };
  4934. } else if (options instanceof _WriteConcern) {
  4935. opts = options;
  4936. } else {
  4937. opts = options.writeConcern;
  4938. }
  4939. const parentOpts = inherit instanceof _WriteConcern ? inherit : inherit.writeConcern;
  4940. const { w = void 0, wtimeout = void 0, j = void 0, fsync = void 0, journal = void 0, wtimeoutMS = void 0 } = {
  4941. ...parentOpts,
  4942. ...opts
  4943. };
  4944. if (w != null || wtimeout != null || wtimeoutMS != null || j != null || journal != null || fsync != null) {
  4945. return new _WriteConcern(w, wtimeout ?? wtimeoutMS, j ?? journal, fsync);
  4946. }
  4947. return void 0;
  4948. }
  4949. };
  4950. exports2.WriteConcern = WriteConcern;
  4951. }
  4952. });
  4953. // node_modules/mongodb/lib/utils.js
  4954. var require_utils = __commonJS({
  4955. "node_modules/mongodb/lib/utils.js"(exports2) {
  4956. "use strict";
  4957. Object.defineProperty(exports2, "__esModule", { value: true });
  4958. exports2.matchesParentDomain = exports2.parseUnsignedInteger = exports2.parseInteger = exports2.compareObjectId = exports2.getMongoDBClientEncryption = exports2.commandSupportsReadConcern = exports2.shuffle = exports2.supportsRetryableWrites = exports2.enumToString = exports2.emitWarningOnce = exports2.emitWarning = exports2.MONGODB_WARNING_CODE = exports2.DEFAULT_PK_FACTORY = exports2.HostAddress = exports2.BufferPool = exports2.List = exports2.deepCopy = exports2.isRecord = exports2.setDifference = exports2.isHello = exports2.isSuperset = exports2.resolveOptions = exports2.hasAtomicOperators = exports2.calculateDurationInMs = exports2.now = exports2.makeStateMachine = exports2.errorStrictEqual = exports2.arrayStrictEqual = exports2.eachAsync = exports2.maxWireVersion = exports2.uuidV4 = exports2.databaseNamespace = exports2.maybeCallback = exports2.makeCounter = exports2.MongoDBCollectionNamespace = exports2.MongoDBNamespace = exports2.ns = exports2.getTopology = exports2.decorateWithExplain = exports2.decorateWithReadConcern = exports2.decorateWithCollation = exports2.isPromiseLike = exports2.applyRetryableWrites = exports2.filterOptions = exports2.mergeOptions = exports2.isObject = exports2.normalizeHintField = exports2.checkCollectionName = exports2.hostMatchesWildcards = exports2.ByteUtils = void 0;
  4959. exports2.request = void 0;
  4960. var crypto = require("crypto");
  4961. var http = require("http");
  4962. var url = require("url");
  4963. var url_1 = require("url");
  4964. var bson_1 = require_bson2();
  4965. var constants_1 = require_constants();
  4966. var constants_2 = require_constants2();
  4967. var error_1 = require_error();
  4968. var read_concern_1 = require_read_concern();
  4969. var read_preference_1 = require_read_preference();
  4970. var common_1 = require_common();
  4971. var write_concern_1 = require_write_concern();
  4972. exports2.ByteUtils = {
  4973. toLocalBufferType(buffer) {
  4974. return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
  4975. },
  4976. equals(seqA, seqB) {
  4977. return exports2.ByteUtils.toLocalBufferType(seqA).equals(seqB);
  4978. },
  4979. compare(seqA, seqB) {
  4980. return exports2.ByteUtils.toLocalBufferType(seqA).compare(seqB);
  4981. },
  4982. toBase64(uint8array) {
  4983. return exports2.ByteUtils.toLocalBufferType(uint8array).toString("base64");
  4984. }
  4985. };
  4986. function hostMatchesWildcards(host, wildcards) {
  4987. for (const wildcard of wildcards) {
  4988. if (host === wildcard || wildcard.startsWith("*.") && (host == null ? void 0 : host.endsWith(wildcard.substring(2, wildcard.length))) || wildcard.startsWith("*/") && (host == null ? void 0 : host.endsWith(wildcard.substring(2, wildcard.length)))) {
  4989. return true;
  4990. }
  4991. }
  4992. return false;
  4993. }
  4994. exports2.hostMatchesWildcards = hostMatchesWildcards;
  4995. function checkCollectionName(collectionName) {
  4996. if ("string" !== typeof collectionName) {
  4997. throw new error_1.MongoInvalidArgumentError("Collection name must be a String");
  4998. }
  4999. if (!collectionName || collectionName.indexOf("..") !== -1) {
  5000. throw new error_1.MongoInvalidArgumentError("Collection names cannot be empty");
  5001. }
  5002. if (collectionName.indexOf("$") !== -1 && collectionName.match(/((^\$cmd)|(oplog\.\$main))/) == null) {
  5003. throw new error_1.MongoInvalidArgumentError("Collection names must not contain '$'");
  5004. }
  5005. if (collectionName.match(/^\.|\.$/) != null) {
  5006. throw new error_1.MongoInvalidArgumentError("Collection names must not start or end with '.'");
  5007. }
  5008. if (collectionName.indexOf("\0") !== -1) {
  5009. throw new error_1.MongoInvalidArgumentError("Collection names cannot contain a null character");
  5010. }
  5011. }
  5012. exports2.checkCollectionName = checkCollectionName;
  5013. function normalizeHintField(hint) {
  5014. let finalHint = void 0;
  5015. if (typeof hint === "string") {
  5016. finalHint = hint;
  5017. } else if (Array.isArray(hint)) {
  5018. finalHint = {};
  5019. hint.forEach((param) => {
  5020. finalHint[param] = 1;
  5021. });
  5022. } else if (hint != null && typeof hint === "object") {
  5023. finalHint = {};
  5024. for (const name in hint) {
  5025. finalHint[name] = hint[name];
  5026. }
  5027. }
  5028. return finalHint;
  5029. }
  5030. exports2.normalizeHintField = normalizeHintField;
  5031. var TO_STRING = (object) => Object.prototype.toString.call(object);
  5032. function isObject(arg) {
  5033. return "[object Object]" === TO_STRING(arg);
  5034. }
  5035. exports2.isObject = isObject;
  5036. function mergeOptions(target, source) {
  5037. return { ...target, ...source };
  5038. }
  5039. exports2.mergeOptions = mergeOptions;
  5040. function filterOptions(options, names) {
  5041. const filterOptions2 = {};
  5042. for (const name in options) {
  5043. if (names.includes(name)) {
  5044. filterOptions2[name] = options[name];
  5045. }
  5046. }
  5047. return filterOptions2;
  5048. }
  5049. exports2.filterOptions = filterOptions;
  5050. function applyRetryableWrites(target, db) {
  5051. var _a;
  5052. if (db && ((_a = db.s.options) == null ? void 0 : _a.retryWrites)) {
  5053. target.retryWrites = true;
  5054. }
  5055. return target;
  5056. }
  5057. exports2.applyRetryableWrites = applyRetryableWrites;
  5058. function isPromiseLike(value) {
  5059. return !!value && typeof value.then === "function";
  5060. }
  5061. exports2.isPromiseLike = isPromiseLike;
  5062. function decorateWithCollation(command, target, options) {
  5063. const capabilities = getTopology(target).capabilities;
  5064. if (options.collation && typeof options.collation === "object") {
  5065. if (capabilities && capabilities.commandsTakeCollation) {
  5066. command.collation = options.collation;
  5067. } else {
  5068. throw new error_1.MongoCompatibilityError(`Current topology does not support collation`);
  5069. }
  5070. }
  5071. }
  5072. exports2.decorateWithCollation = decorateWithCollation;
  5073. function decorateWithReadConcern(command, coll, options) {
  5074. if (options && options.session && options.session.inTransaction()) {
  5075. return;
  5076. }
  5077. const readConcern = Object.assign({}, command.readConcern || {});
  5078. if (coll.s.readConcern) {
  5079. Object.assign(readConcern, coll.s.readConcern);
  5080. }
  5081. if (Object.keys(readConcern).length > 0) {
  5082. Object.assign(command, { readConcern });
  5083. }
  5084. }
  5085. exports2.decorateWithReadConcern = decorateWithReadConcern;
  5086. function decorateWithExplain(command, explain) {
  5087. if (command.explain) {
  5088. return command;
  5089. }
  5090. return { explain: command, verbosity: explain.verbosity };
  5091. }
  5092. exports2.decorateWithExplain = decorateWithExplain;
  5093. function getTopology(provider) {
  5094. if ("topology" in provider && provider.topology) {
  5095. return provider.topology;
  5096. } else if ("client" in provider && provider.client.topology) {
  5097. return provider.client.topology;
  5098. }
  5099. throw new error_1.MongoNotConnectedError("MongoClient must be connected to perform this operation");
  5100. }
  5101. exports2.getTopology = getTopology;
  5102. function ns(ns2) {
  5103. return MongoDBNamespace.fromString(ns2);
  5104. }
  5105. exports2.ns = ns;
  5106. var MongoDBNamespace = class _MongoDBNamespace {
  5107. /**
  5108. * Create a namespace object
  5109. *
  5110. * @param db - database name
  5111. * @param collection - collection name
  5112. */
  5113. constructor(db, collection) {
  5114. this.db = db;
  5115. this.collection = collection;
  5116. this.collection = collection === "" ? void 0 : collection;
  5117. }
  5118. toString() {
  5119. return this.collection ? `${this.db}.${this.collection}` : this.db;
  5120. }
  5121. withCollection(collection) {
  5122. return new MongoDBCollectionNamespace(this.db, collection);
  5123. }
  5124. static fromString(namespace) {
  5125. if (typeof namespace !== "string" || namespace === "") {
  5126. throw new error_1.MongoRuntimeError(`Cannot parse namespace from "${namespace}"`);
  5127. }
  5128. const [db, ...collectionParts] = namespace.split(".");
  5129. const collection = collectionParts.join(".");
  5130. return new _MongoDBNamespace(db, collection === "" ? void 0 : collection);
  5131. }
  5132. };
  5133. exports2.MongoDBNamespace = MongoDBNamespace;
  5134. var MongoDBCollectionNamespace = class extends MongoDBNamespace {
  5135. constructor(db, collection) {
  5136. super(db, collection);
  5137. this.collection = collection;
  5138. }
  5139. };
  5140. exports2.MongoDBCollectionNamespace = MongoDBCollectionNamespace;
  5141. function* makeCounter(seed = 0) {
  5142. let count = seed;
  5143. while (true) {
  5144. const newCount = count;
  5145. count += 1;
  5146. yield newCount;
  5147. }
  5148. }
  5149. exports2.makeCounter = makeCounter;
  5150. function maybeCallback(promiseFn, callback) {
  5151. const promise = promiseFn();
  5152. if (callback == null) {
  5153. return promise;
  5154. }
  5155. promise.then((result) => callback(void 0, result), (error) => callback(error));
  5156. return;
  5157. }
  5158. exports2.maybeCallback = maybeCallback;
  5159. function databaseNamespace(ns2) {
  5160. return ns2.split(".")[0];
  5161. }
  5162. exports2.databaseNamespace = databaseNamespace;
  5163. function uuidV4() {
  5164. const result = crypto.randomBytes(16);
  5165. result[6] = result[6] & 15 | 64;
  5166. result[8] = result[8] & 63 | 128;
  5167. return result;
  5168. }
  5169. exports2.uuidV4 = uuidV4;
  5170. function maxWireVersion(topologyOrServer) {
  5171. if (topologyOrServer) {
  5172. if (topologyOrServer.loadBalanced) {
  5173. return constants_1.MAX_SUPPORTED_WIRE_VERSION;
  5174. }
  5175. if (topologyOrServer.hello) {
  5176. return topologyOrServer.hello.maxWireVersion;
  5177. }
  5178. if ("lastHello" in topologyOrServer && typeof topologyOrServer.lastHello === "function") {
  5179. const lastHello = topologyOrServer.lastHello();
  5180. if (lastHello) {
  5181. return lastHello.maxWireVersion;
  5182. }
  5183. }
  5184. if (topologyOrServer.description && "maxWireVersion" in topologyOrServer.description && topologyOrServer.description.maxWireVersion != null) {
  5185. return topologyOrServer.description.maxWireVersion;
  5186. }
  5187. }
  5188. return 0;
  5189. }
  5190. exports2.maxWireVersion = maxWireVersion;
  5191. function eachAsync(arr, eachFn, callback) {
  5192. arr = arr || [];
  5193. let idx = 0;
  5194. let awaiting = 0;
  5195. for (idx = 0; idx < arr.length; ++idx) {
  5196. awaiting++;
  5197. eachFn(arr[idx], eachCallback);
  5198. }
  5199. if (awaiting === 0) {
  5200. callback();
  5201. return;
  5202. }
  5203. function eachCallback(err) {
  5204. awaiting--;
  5205. if (err) {
  5206. callback(err);
  5207. return;
  5208. }
  5209. if (idx === arr.length && awaiting <= 0) {
  5210. callback();
  5211. }
  5212. }
  5213. }
  5214. exports2.eachAsync = eachAsync;
  5215. function arrayStrictEqual(arr, arr2) {
  5216. if (!Array.isArray(arr) || !Array.isArray(arr2)) {
  5217. return false;
  5218. }
  5219. return arr.length === arr2.length && arr.every((elt, idx) => elt === arr2[idx]);
  5220. }
  5221. exports2.arrayStrictEqual = arrayStrictEqual;
  5222. function errorStrictEqual(lhs, rhs) {
  5223. if (lhs === rhs) {
  5224. return true;
  5225. }
  5226. if (!lhs || !rhs) {
  5227. return lhs === rhs;
  5228. }
  5229. if (lhs == null && rhs != null || lhs != null && rhs == null) {
  5230. return false;
  5231. }
  5232. if (lhs.constructor.name !== rhs.constructor.name) {
  5233. return false;
  5234. }
  5235. if (lhs.message !== rhs.message) {
  5236. return false;
  5237. }
  5238. return true;
  5239. }
  5240. exports2.errorStrictEqual = errorStrictEqual;
  5241. function makeStateMachine(stateTable) {
  5242. return function stateTransition(target, newState) {
  5243. const legalStates = stateTable[target.s.state];
  5244. if (legalStates && legalStates.indexOf(newState) < 0) {
  5245. throw new error_1.MongoRuntimeError(`illegal state transition from [${target.s.state}] => [${newState}], allowed: [${legalStates}]`);
  5246. }
  5247. target.emit("stateChanged", target.s.state, newState);
  5248. target.s.state = newState;
  5249. };
  5250. }
  5251. exports2.makeStateMachine = makeStateMachine;
  5252. function now() {
  5253. const hrtime = process.hrtime();
  5254. return Math.floor(hrtime[0] * 1e3 + hrtime[1] / 1e6);
  5255. }
  5256. exports2.now = now;
  5257. function calculateDurationInMs(started) {
  5258. if (typeof started !== "number") {
  5259. throw new error_1.MongoInvalidArgumentError("Numeric value required to calculate duration");
  5260. }
  5261. const elapsed = now() - started;
  5262. return elapsed < 0 ? 0 : elapsed;
  5263. }
  5264. exports2.calculateDurationInMs = calculateDurationInMs;
  5265. function hasAtomicOperators(doc) {
  5266. if (Array.isArray(doc)) {
  5267. for (const document of doc) {
  5268. if (hasAtomicOperators(document)) {
  5269. return true;
  5270. }
  5271. }
  5272. return false;
  5273. }
  5274. const keys = Object.keys(doc);
  5275. return keys.length > 0 && keys[0][0] === "$";
  5276. }
  5277. exports2.hasAtomicOperators = hasAtomicOperators;
  5278. function resolveOptions(parent, options) {
  5279. const result = Object.assign({}, options, (0, bson_1.resolveBSONOptions)(options, parent));
  5280. const session = options == null ? void 0 : options.session;
  5281. if (!(session == null ? void 0 : session.inTransaction())) {
  5282. const readConcern = read_concern_1.ReadConcern.fromOptions(options) ?? (parent == null ? void 0 : parent.readConcern);
  5283. if (readConcern) {
  5284. result.readConcern = readConcern;
  5285. }
  5286. const writeConcern = write_concern_1.WriteConcern.fromOptions(options) ?? (parent == null ? void 0 : parent.writeConcern);
  5287. if (writeConcern) {
  5288. result.writeConcern = writeConcern;
  5289. }
  5290. }
  5291. const readPreference = read_preference_1.ReadPreference.fromOptions(options) ?? (parent == null ? void 0 : parent.readPreference);
  5292. if (readPreference) {
  5293. result.readPreference = readPreference;
  5294. }
  5295. return result;
  5296. }
  5297. exports2.resolveOptions = resolveOptions;
  5298. function isSuperset(set, subset) {
  5299. set = Array.isArray(set) ? new Set(set) : set;
  5300. subset = Array.isArray(subset) ? new Set(subset) : subset;
  5301. for (const elem of subset) {
  5302. if (!set.has(elem)) {
  5303. return false;
  5304. }
  5305. }
  5306. return true;
  5307. }
  5308. exports2.isSuperset = isSuperset;
  5309. function isHello(doc) {
  5310. return doc[constants_2.LEGACY_HELLO_COMMAND] || doc.hello ? true : false;
  5311. }
  5312. exports2.isHello = isHello;
  5313. function setDifference(setA, setB) {
  5314. const difference = new Set(setA);
  5315. for (const elem of setB) {
  5316. difference.delete(elem);
  5317. }
  5318. return difference;
  5319. }
  5320. exports2.setDifference = setDifference;
  5321. var HAS_OWN = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
  5322. function isRecord(value, requiredKeys = void 0) {
  5323. if (!isObject(value)) {
  5324. return false;
  5325. }
  5326. const ctor = value.constructor;
  5327. if (ctor && ctor.prototype) {
  5328. if (!isObject(ctor.prototype)) {
  5329. return false;
  5330. }
  5331. if (!HAS_OWN(ctor.prototype, "isPrototypeOf")) {
  5332. return false;
  5333. }
  5334. }
  5335. if (requiredKeys) {
  5336. const keys = Object.keys(value);
  5337. return isSuperset(keys, requiredKeys);
  5338. }
  5339. return true;
  5340. }
  5341. exports2.isRecord = isRecord;
  5342. function deepCopy(value) {
  5343. if (value == null) {
  5344. return value;
  5345. } else if (Array.isArray(value)) {
  5346. return value.map((item) => deepCopy(item));
  5347. } else if (isRecord(value)) {
  5348. const res = {};
  5349. for (const key in value) {
  5350. res[key] = deepCopy(value[key]);
  5351. }
  5352. return res;
  5353. }
  5354. const ctor = value.constructor;
  5355. if (ctor) {
  5356. switch (ctor.name.toLowerCase()) {
  5357. case "date":
  5358. return new ctor(Number(value));
  5359. case "map":
  5360. return new Map(value);
  5361. case "set":
  5362. return new Set(value);
  5363. case "buffer":
  5364. return Buffer.from(value);
  5365. }
  5366. }
  5367. return value;
  5368. }
  5369. exports2.deepCopy = deepCopy;
  5370. var List = class {
  5371. get length() {
  5372. return this.count;
  5373. }
  5374. get [Symbol.toStringTag]() {
  5375. return "List";
  5376. }
  5377. constructor() {
  5378. this.count = 0;
  5379. this.head = {
  5380. next: null,
  5381. prev: null,
  5382. value: null
  5383. };
  5384. this.head.next = this.head;
  5385. this.head.prev = this.head;
  5386. }
  5387. toArray() {
  5388. return Array.from(this);
  5389. }
  5390. toString() {
  5391. return `head <=> ${this.toArray().join(" <=> ")} <=> head`;
  5392. }
  5393. *[Symbol.iterator]() {
  5394. for (const node of this.nodes()) {
  5395. yield node.value;
  5396. }
  5397. }
  5398. *nodes() {
  5399. let ptr = this.head.next;
  5400. while (ptr !== this.head) {
  5401. const { next } = ptr;
  5402. yield ptr;
  5403. ptr = next;
  5404. }
  5405. }
  5406. /** Insert at end of list */
  5407. push(value) {
  5408. this.count += 1;
  5409. const newNode = {
  5410. next: this.head,
  5411. prev: this.head.prev,
  5412. value
  5413. };
  5414. this.head.prev.next = newNode;
  5415. this.head.prev = newNode;
  5416. }
  5417. /** Inserts every item inside an iterable instead of the iterable itself */
  5418. pushMany(iterable) {
  5419. for (const value of iterable) {
  5420. this.push(value);
  5421. }
  5422. }
  5423. /** Insert at front of list */
  5424. unshift(value) {
  5425. this.count += 1;
  5426. const newNode = {
  5427. next: this.head.next,
  5428. prev: this.head,
  5429. value
  5430. };
  5431. this.head.next.prev = newNode;
  5432. this.head.next = newNode;
  5433. }
  5434. remove(node) {
  5435. if (node === this.head || this.length === 0) {
  5436. return null;
  5437. }
  5438. this.count -= 1;
  5439. const prevNode = node.prev;
  5440. const nextNode = node.next;
  5441. prevNode.next = nextNode;
  5442. nextNode.prev = prevNode;
  5443. return node.value;
  5444. }
  5445. /** Removes the first node at the front of the list */
  5446. shift() {
  5447. return this.remove(this.head.next);
  5448. }
  5449. /** Removes the last node at the end of the list */
  5450. pop() {
  5451. return this.remove(this.head.prev);
  5452. }
  5453. /** Iterates through the list and removes nodes where filter returns true */
  5454. prune(filter) {
  5455. for (const node of this.nodes()) {
  5456. if (filter(node.value)) {
  5457. this.remove(node);
  5458. }
  5459. }
  5460. }
  5461. clear() {
  5462. this.count = 0;
  5463. this.head.next = this.head;
  5464. this.head.prev = this.head;
  5465. }
  5466. /** Returns the first item in the list, does not remove */
  5467. first() {
  5468. return this.head.next.value;
  5469. }
  5470. /** Returns the last item in the list, does not remove */
  5471. last() {
  5472. return this.head.prev.value;
  5473. }
  5474. };
  5475. exports2.List = List;
  5476. var BufferPool = class {
  5477. constructor() {
  5478. this.buffers = new List();
  5479. this.totalByteLength = 0;
  5480. }
  5481. get length() {
  5482. return this.totalByteLength;
  5483. }
  5484. /** Adds a buffer to the internal buffer pool list */
  5485. append(buffer) {
  5486. this.buffers.push(buffer);
  5487. this.totalByteLength += buffer.length;
  5488. }
  5489. /**
  5490. * If BufferPool contains 4 bytes or more construct an int32 from the leading bytes,
  5491. * otherwise return null. Size can be negative, caller should error check.
  5492. */
  5493. getInt32() {
  5494. if (this.totalByteLength < 4) {
  5495. return null;
  5496. }
  5497. const firstBuffer = this.buffers.first();
  5498. if (firstBuffer != null && firstBuffer.byteLength >= 4) {
  5499. return firstBuffer.readInt32LE(0);
  5500. }
  5501. const top4Bytes = this.read(4);
  5502. const value = top4Bytes.readInt32LE(0);
  5503. this.totalByteLength += 4;
  5504. this.buffers.unshift(top4Bytes);
  5505. return value;
  5506. }
  5507. /** Reads the requested number of bytes, optionally consuming them */
  5508. read(size) {
  5509. if (typeof size !== "number" || size < 0) {
  5510. throw new error_1.MongoInvalidArgumentError('Argument "size" must be a non-negative number');
  5511. }
  5512. if (size > this.totalByteLength) {
  5513. return Buffer.alloc(0);
  5514. }
  5515. const result = Buffer.allocUnsafe(size);
  5516. for (let bytesRead = 0; bytesRead < size; ) {
  5517. const buffer = this.buffers.shift();
  5518. if (buffer == null) {
  5519. break;
  5520. }
  5521. const bytesRemaining = size - bytesRead;
  5522. const bytesReadable = Math.min(bytesRemaining, buffer.byteLength);
  5523. const bytes = buffer.subarray(0, bytesReadable);
  5524. result.set(bytes, bytesRead);
  5525. bytesRead += bytesReadable;
  5526. this.totalByteLength -= bytesReadable;
  5527. if (bytesReadable < buffer.byteLength) {
  5528. this.buffers.unshift(buffer.subarray(bytesReadable));
  5529. }
  5530. }
  5531. return result;
  5532. }
  5533. };
  5534. exports2.BufferPool = BufferPool;
  5535. var HostAddress = class _HostAddress {
  5536. constructor(hostString) {
  5537. this.host = void 0;
  5538. this.port = void 0;
  5539. this.socketPath = void 0;
  5540. this.isIPv6 = false;
  5541. const escapedHost = hostString.split(" ").join("%20");
  5542. if (escapedHost.endsWith(".sock")) {
  5543. this.socketPath = decodeURIComponent(escapedHost);
  5544. return;
  5545. }
  5546. const urlString = `iLoveJS://${escapedHost}`;
  5547. let url2;
  5548. try {
  5549. url2 = new url_1.URL(urlString);
  5550. } catch (urlError) {
  5551. const runtimeError = new error_1.MongoRuntimeError(`Unable to parse ${escapedHost} with URL`);
  5552. runtimeError.cause = urlError;
  5553. throw runtimeError;
  5554. }
  5555. const hostname = url2.hostname;
  5556. const port = url2.port;
  5557. let normalized = decodeURIComponent(hostname).toLowerCase();
  5558. if (normalized.startsWith("[") && normalized.endsWith("]")) {
  5559. this.isIPv6 = true;
  5560. normalized = normalized.substring(1, hostname.length - 1);
  5561. }
  5562. this.host = normalized.toLowerCase();
  5563. if (typeof port === "number") {
  5564. this.port = port;
  5565. } else if (typeof port === "string" && port !== "") {
  5566. this.port = Number.parseInt(port, 10);
  5567. } else {
  5568. this.port = 27017;
  5569. }
  5570. if (this.port === 0) {
  5571. throw new error_1.MongoParseError("Invalid port (zero) with hostname");
  5572. }
  5573. Object.freeze(this);
  5574. }
  5575. [Symbol.for("nodejs.util.inspect.custom")]() {
  5576. return this.inspect();
  5577. }
  5578. inspect() {
  5579. return `new HostAddress('${this.toString()}')`;
  5580. }
  5581. toString() {
  5582. if (typeof this.host === "string") {
  5583. if (this.isIPv6) {
  5584. return `[${this.host}]:${this.port}`;
  5585. }
  5586. return `${this.host}:${this.port}`;
  5587. }
  5588. return `${this.socketPath}`;
  5589. }
  5590. static fromString(s) {
  5591. return new _HostAddress(s);
  5592. }
  5593. static fromHostPort(host, port) {
  5594. if (host.includes(":")) {
  5595. host = `[${host}]`;
  5596. }
  5597. return _HostAddress.fromString(`${host}:${port}`);
  5598. }
  5599. static fromSrvRecord({ name, port }) {
  5600. return _HostAddress.fromHostPort(name, port);
  5601. }
  5602. toHostPort() {
  5603. if (this.socketPath) {
  5604. return { host: this.socketPath, port: 0 };
  5605. }
  5606. const host = this.host ?? "";
  5607. const port = this.port ?? 0;
  5608. return { host, port };
  5609. }
  5610. };
  5611. exports2.HostAddress = HostAddress;
  5612. exports2.DEFAULT_PK_FACTORY = {
  5613. // We prefer not to rely on ObjectId having a createPk method
  5614. createPk() {
  5615. return new bson_1.ObjectId();
  5616. }
  5617. };
  5618. exports2.MONGODB_WARNING_CODE = "MONGODB DRIVER";
  5619. function emitWarning(message) {
  5620. return process.emitWarning(message, { code: exports2.MONGODB_WARNING_CODE });
  5621. }
  5622. exports2.emitWarning = emitWarning;
  5623. var emittedWarnings = /* @__PURE__ */ new Set();
  5624. function emitWarningOnce(message) {
  5625. if (!emittedWarnings.has(message)) {
  5626. emittedWarnings.add(message);
  5627. return emitWarning(message);
  5628. }
  5629. }
  5630. exports2.emitWarningOnce = emitWarningOnce;
  5631. function enumToString(en) {
  5632. return Object.values(en).join(", ");
  5633. }
  5634. exports2.enumToString = enumToString;
  5635. function supportsRetryableWrites(server) {
  5636. if (!server) {
  5637. return false;
  5638. }
  5639. if (server.loadBalanced) {
  5640. return true;
  5641. }
  5642. if (server.description.logicalSessionTimeoutMinutes != null) {
  5643. if (server.description.type !== common_1.ServerType.Standalone) {
  5644. return true;
  5645. }
  5646. }
  5647. return false;
  5648. }
  5649. exports2.supportsRetryableWrites = supportsRetryableWrites;
  5650. function shuffle(sequence, limit = 0) {
  5651. const items = Array.from(sequence);
  5652. if (limit > items.length) {
  5653. throw new error_1.MongoRuntimeError("Limit must be less than the number of items");
  5654. }
  5655. let remainingItemsToShuffle = items.length;
  5656. const lowerBound = limit % items.length === 0 ? 1 : items.length - limit;
  5657. while (remainingItemsToShuffle > lowerBound) {
  5658. const randomIndex = Math.floor(Math.random() * remainingItemsToShuffle);
  5659. remainingItemsToShuffle -= 1;
  5660. const swapHold = items[remainingItemsToShuffle];
  5661. items[remainingItemsToShuffle] = items[randomIndex];
  5662. items[randomIndex] = swapHold;
  5663. }
  5664. return limit % items.length === 0 ? items : items.slice(lowerBound);
  5665. }
  5666. exports2.shuffle = shuffle;
  5667. function commandSupportsReadConcern(command, options) {
  5668. if (command.aggregate || command.count || command.distinct || command.find || command.geoNear) {
  5669. return true;
  5670. }
  5671. if (command.mapReduce && options && options.out && (options.out.inline === 1 || options.out === "inline")) {
  5672. return true;
  5673. }
  5674. return false;
  5675. }
  5676. exports2.commandSupportsReadConcern = commandSupportsReadConcern;
  5677. function getMongoDBClientEncryption() {
  5678. let mongodbClientEncryption = null;
  5679. if (typeof process.env.MONGODB_CLIENT_ENCRYPTION_OVERRIDE === "string" && process.env.MONGODB_CLIENT_ENCRYPTION_OVERRIDE.length > 0) {
  5680. try {
  5681. mongodbClientEncryption = require(process.env.MONGODB_CLIENT_ENCRYPTION_OVERRIDE);
  5682. } catch {
  5683. }
  5684. } else {
  5685. try {
  5686. mongodbClientEncryption = require("mongodb-client-encryption");
  5687. } catch {
  5688. }
  5689. }
  5690. return mongodbClientEncryption;
  5691. }
  5692. exports2.getMongoDBClientEncryption = getMongoDBClientEncryption;
  5693. function compareObjectId(oid1, oid2) {
  5694. if (oid1 == null && oid2 == null) {
  5695. return 0;
  5696. }
  5697. if (oid1 == null) {
  5698. return -1;
  5699. }
  5700. if (oid2 == null) {
  5701. return 1;
  5702. }
  5703. return exports2.ByteUtils.compare(oid1.id, oid2.id);
  5704. }
  5705. exports2.compareObjectId = compareObjectId;
  5706. function parseInteger(value) {
  5707. if (typeof value === "number")
  5708. return Math.trunc(value);
  5709. const parsedValue = Number.parseInt(String(value), 10);
  5710. return Number.isNaN(parsedValue) ? null : parsedValue;
  5711. }
  5712. exports2.parseInteger = parseInteger;
  5713. function parseUnsignedInteger(value) {
  5714. const parsedInt = parseInteger(value);
  5715. return parsedInt != null && parsedInt >= 0 ? parsedInt : null;
  5716. }
  5717. exports2.parseUnsignedInteger = parseUnsignedInteger;
  5718. function matchesParentDomain(address, srvHost) {
  5719. const normalizedAddress = address.endsWith(".") ? address.slice(0, address.length - 1) : address;
  5720. const normalizedSrvHost = srvHost.endsWith(".") ? srvHost.slice(0, srvHost.length - 1) : srvHost;
  5721. const allCharacterBeforeFirstDot = /^.*?\./;
  5722. const addressDomain = `.${normalizedAddress.replace(allCharacterBeforeFirstDot, "")}`;
  5723. const srvHostDomain = `.${normalizedSrvHost.replace(allCharacterBeforeFirstDot, "")}`;
  5724. return addressDomain.endsWith(srvHostDomain);
  5725. }
  5726. exports2.matchesParentDomain = matchesParentDomain;
  5727. async function request(uri, options = {}) {
  5728. return new Promise((resolve, reject) => {
  5729. const requestOptions = {
  5730. method: "GET",
  5731. timeout: 1e4,
  5732. json: true,
  5733. ...url.parse(uri),
  5734. ...options
  5735. };
  5736. const req = http.request(requestOptions, (res) => {
  5737. res.setEncoding("utf8");
  5738. let data = "";
  5739. res.on("data", (d) => {
  5740. data += d;
  5741. });
  5742. res.once("end", () => {
  5743. if (options.json === false) {
  5744. resolve(data);
  5745. return;
  5746. }
  5747. try {
  5748. const parsed = JSON.parse(data);
  5749. resolve(parsed);
  5750. } catch {
  5751. reject(new error_1.MongoRuntimeError(`Invalid JSON response: "${data}"`));
  5752. }
  5753. });
  5754. });
  5755. req.once("timeout", () => req.destroy(new error_1.MongoNetworkTimeoutError(`Network request to ${uri} timed out after ${options.timeout} ms`)));
  5756. req.once("error", (error) => reject(error));
  5757. req.end();
  5758. });
  5759. }
  5760. exports2.request = request;
  5761. }
  5762. });
  5763. // node_modules/mongodb/lib/explain.js
  5764. var require_explain = __commonJS({
  5765. "node_modules/mongodb/lib/explain.js"(exports2) {
  5766. "use strict";
  5767. Object.defineProperty(exports2, "__esModule", { value: true });
  5768. exports2.Explain = exports2.ExplainVerbosity = void 0;
  5769. var error_1 = require_error();
  5770. exports2.ExplainVerbosity = Object.freeze({
  5771. queryPlanner: "queryPlanner",
  5772. queryPlannerExtended: "queryPlannerExtended",
  5773. executionStats: "executionStats",
  5774. allPlansExecution: "allPlansExecution"
  5775. });
  5776. var Explain = class _Explain {
  5777. constructor(verbosity) {
  5778. if (typeof verbosity === "boolean") {
  5779. this.verbosity = verbosity ? exports2.ExplainVerbosity.allPlansExecution : exports2.ExplainVerbosity.queryPlanner;
  5780. } else {
  5781. this.verbosity = verbosity;
  5782. }
  5783. }
  5784. static fromOptions(options) {
  5785. if ((options == null ? void 0 : options.explain) == null)
  5786. return;
  5787. const explain = options.explain;
  5788. if (typeof explain === "boolean" || typeof explain === "string") {
  5789. return new _Explain(explain);
  5790. }
  5791. throw new error_1.MongoInvalidArgumentError('Field "explain" must be a string or a boolean');
  5792. }
  5793. };
  5794. exports2.Explain = Explain;
  5795. }
  5796. });
  5797. // node_modules/mongodb/lib/sdam/server_selection.js
  5798. var require_server_selection = __commonJS({
  5799. "node_modules/mongodb/lib/sdam/server_selection.js"(exports2) {
  5800. "use strict";
  5801. Object.defineProperty(exports2, "__esModule", { value: true });
  5802. exports2.readPreferenceServerSelector = exports2.secondaryWritableServerSelector = exports2.sameServerSelector = exports2.writableServerSelector = exports2.MIN_SECONDARY_WRITE_WIRE_VERSION = void 0;
  5803. var error_1 = require_error();
  5804. var read_preference_1 = require_read_preference();
  5805. var common_1 = require_common();
  5806. var IDLE_WRITE_PERIOD = 1e4;
  5807. var SMALLEST_MAX_STALENESS_SECONDS = 90;
  5808. exports2.MIN_SECONDARY_WRITE_WIRE_VERSION = 13;
  5809. function writableServerSelector() {
  5810. return (topologyDescription, servers) => latencyWindowReducer(topologyDescription, servers.filter((s) => s.isWritable));
  5811. }
  5812. exports2.writableServerSelector = writableServerSelector;
  5813. function sameServerSelector(description) {
  5814. return (topologyDescription, servers) => {
  5815. if (!description)
  5816. return [];
  5817. return servers.filter((sd) => {
  5818. return sd.address === description.address && sd.type !== common_1.ServerType.Unknown;
  5819. });
  5820. };
  5821. }
  5822. exports2.sameServerSelector = sameServerSelector;
  5823. function secondaryWritableServerSelector(wireVersion, readPreference) {
  5824. if (!readPreference || !wireVersion || wireVersion && wireVersion < exports2.MIN_SECONDARY_WRITE_WIRE_VERSION) {
  5825. return readPreferenceServerSelector(read_preference_1.ReadPreference.primary);
  5826. }
  5827. return readPreferenceServerSelector(readPreference);
  5828. }
  5829. exports2.secondaryWritableServerSelector = secondaryWritableServerSelector;
  5830. function maxStalenessReducer(readPreference, topologyDescription, servers) {
  5831. if (readPreference.maxStalenessSeconds == null || readPreference.maxStalenessSeconds < 0) {
  5832. return servers;
  5833. }
  5834. const maxStaleness = readPreference.maxStalenessSeconds;
  5835. const maxStalenessVariance = (topologyDescription.heartbeatFrequencyMS + IDLE_WRITE_PERIOD) / 1e3;
  5836. if (maxStaleness < maxStalenessVariance) {
  5837. throw new error_1.MongoInvalidArgumentError(`Option "maxStalenessSeconds" must be at least ${maxStalenessVariance} seconds`);
  5838. }
  5839. if (maxStaleness < SMALLEST_MAX_STALENESS_SECONDS) {
  5840. throw new error_1.MongoInvalidArgumentError(`Option "maxStalenessSeconds" must be at least ${SMALLEST_MAX_STALENESS_SECONDS} seconds`);
  5841. }
  5842. if (topologyDescription.type === common_1.TopologyType.ReplicaSetWithPrimary) {
  5843. const primary = Array.from(topologyDescription.servers.values()).filter(primaryFilter)[0];
  5844. return servers.reduce((result, server) => {
  5845. const stalenessMS = server.lastUpdateTime - server.lastWriteDate - (primary.lastUpdateTime - primary.lastWriteDate) + topologyDescription.heartbeatFrequencyMS;
  5846. const staleness = stalenessMS / 1e3;
  5847. const maxStalenessSeconds = readPreference.maxStalenessSeconds ?? 0;
  5848. if (staleness <= maxStalenessSeconds) {
  5849. result.push(server);
  5850. }
  5851. return result;
  5852. }, []);
  5853. }
  5854. if (topologyDescription.type === common_1.TopologyType.ReplicaSetNoPrimary) {
  5855. if (servers.length === 0) {
  5856. return servers;
  5857. }
  5858. const sMax = servers.reduce((max, s) => s.lastWriteDate > max.lastWriteDate ? s : max);
  5859. return servers.reduce((result, server) => {
  5860. const stalenessMS = sMax.lastWriteDate - server.lastWriteDate + topologyDescription.heartbeatFrequencyMS;
  5861. const staleness = stalenessMS / 1e3;
  5862. const maxStalenessSeconds = readPreference.maxStalenessSeconds ?? 0;
  5863. if (staleness <= maxStalenessSeconds) {
  5864. result.push(server);
  5865. }
  5866. return result;
  5867. }, []);
  5868. }
  5869. return servers;
  5870. }
  5871. function tagSetMatch(tagSet, serverTags) {
  5872. const keys = Object.keys(tagSet);
  5873. const serverTagKeys = Object.keys(serverTags);
  5874. for (let i = 0; i < keys.length; ++i) {
  5875. const key = keys[i];
  5876. if (serverTagKeys.indexOf(key) === -1 || serverTags[key] !== tagSet[key]) {
  5877. return false;
  5878. }
  5879. }
  5880. return true;
  5881. }
  5882. function tagSetReducer(readPreference, servers) {
  5883. if (readPreference.tags == null || Array.isArray(readPreference.tags) && readPreference.tags.length === 0) {
  5884. return servers;
  5885. }
  5886. for (let i = 0; i < readPreference.tags.length; ++i) {
  5887. const tagSet = readPreference.tags[i];
  5888. const serversMatchingTagset = servers.reduce((matched, server) => {
  5889. if (tagSetMatch(tagSet, server.tags))
  5890. matched.push(server);
  5891. return matched;
  5892. }, []);
  5893. if (serversMatchingTagset.length) {
  5894. return serversMatchingTagset;
  5895. }
  5896. }
  5897. return [];
  5898. }
  5899. function latencyWindowReducer(topologyDescription, servers) {
  5900. const low = servers.reduce((min, server) => min === -1 ? server.roundTripTime : Math.min(server.roundTripTime, min), -1);
  5901. const high = low + topologyDescription.localThresholdMS;
  5902. return servers.reduce((result, server) => {
  5903. if (server.roundTripTime <= high && server.roundTripTime >= low)
  5904. result.push(server);
  5905. return result;
  5906. }, []);
  5907. }
  5908. function primaryFilter(server) {
  5909. return server.type === common_1.ServerType.RSPrimary;
  5910. }
  5911. function secondaryFilter(server) {
  5912. return server.type === common_1.ServerType.RSSecondary;
  5913. }
  5914. function nearestFilter(server) {
  5915. return server.type === common_1.ServerType.RSSecondary || server.type === common_1.ServerType.RSPrimary;
  5916. }
  5917. function knownFilter(server) {
  5918. return server.type !== common_1.ServerType.Unknown;
  5919. }
  5920. function loadBalancerFilter(server) {
  5921. return server.type === common_1.ServerType.LoadBalancer;
  5922. }
  5923. function readPreferenceServerSelector(readPreference) {
  5924. if (!readPreference.isValid()) {
  5925. throw new error_1.MongoInvalidArgumentError("Invalid read preference specified");
  5926. }
  5927. return (topologyDescription, servers) => {
  5928. const commonWireVersion = topologyDescription.commonWireVersion;
  5929. if (commonWireVersion && readPreference.minWireVersion && readPreference.minWireVersion > commonWireVersion) {
  5930. throw new error_1.MongoCompatibilityError(`Minimum wire version '${readPreference.minWireVersion}' required, but found '${commonWireVersion}'`);
  5931. }
  5932. if (topologyDescription.type === common_1.TopologyType.LoadBalanced) {
  5933. return servers.filter(loadBalancerFilter);
  5934. }
  5935. if (topologyDescription.type === common_1.TopologyType.Unknown) {
  5936. return [];
  5937. }
  5938. if (topologyDescription.type === common_1.TopologyType.Single || topologyDescription.type === common_1.TopologyType.Sharded) {
  5939. return latencyWindowReducer(topologyDescription, servers.filter(knownFilter));
  5940. }
  5941. const mode = readPreference.mode;
  5942. if (mode === read_preference_1.ReadPreference.PRIMARY) {
  5943. return servers.filter(primaryFilter);
  5944. }
  5945. if (mode === read_preference_1.ReadPreference.PRIMARY_PREFERRED) {
  5946. const result = servers.filter(primaryFilter);
  5947. if (result.length) {
  5948. return result;
  5949. }
  5950. }
  5951. const filter = mode === read_preference_1.ReadPreference.NEAREST ? nearestFilter : secondaryFilter;
  5952. const selectedServers = latencyWindowReducer(topologyDescription, tagSetReducer(readPreference, maxStalenessReducer(readPreference, topologyDescription, servers.filter(filter))));
  5953. if (mode === read_preference_1.ReadPreference.SECONDARY_PREFERRED && selectedServers.length === 0) {
  5954. return servers.filter(primaryFilter);
  5955. }
  5956. return selectedServers;
  5957. };
  5958. }
  5959. exports2.readPreferenceServerSelector = readPreferenceServerSelector;
  5960. }
  5961. });
  5962. // node_modules/mongodb/lib/operations/operation.js
  5963. var require_operation = __commonJS({
  5964. "node_modules/mongodb/lib/operations/operation.js"(exports2) {
  5965. "use strict";
  5966. Object.defineProperty(exports2, "__esModule", { value: true });
  5967. exports2.defineAspects = exports2.AbstractCallbackOperation = exports2.AbstractOperation = exports2.Aspect = void 0;
  5968. var util_1 = require("util");
  5969. var bson_1 = require_bson2();
  5970. var read_preference_1 = require_read_preference();
  5971. exports2.Aspect = {
  5972. READ_OPERATION: Symbol("READ_OPERATION"),
  5973. WRITE_OPERATION: Symbol("WRITE_OPERATION"),
  5974. RETRYABLE: Symbol("RETRYABLE"),
  5975. EXPLAINABLE: Symbol("EXPLAINABLE"),
  5976. SKIP_COLLATION: Symbol("SKIP_COLLATION"),
  5977. CURSOR_CREATING: Symbol("CURSOR_CREATING"),
  5978. MUST_SELECT_SAME_SERVER: Symbol("MUST_SELECT_SAME_SERVER")
  5979. };
  5980. var kSession = Symbol("session");
  5981. var AbstractOperation = class {
  5982. constructor(options = {}) {
  5983. this.readPreference = this.hasAspect(exports2.Aspect.WRITE_OPERATION) ? read_preference_1.ReadPreference.primary : read_preference_1.ReadPreference.fromOptions(options) ?? read_preference_1.ReadPreference.primary;
  5984. this.bsonOptions = (0, bson_1.resolveBSONOptions)(options);
  5985. this[kSession] = options.session != null ? options.session : void 0;
  5986. this.options = options;
  5987. this.bypassPinningCheck = !!options.bypassPinningCheck;
  5988. this.trySecondaryWrite = false;
  5989. }
  5990. hasAspect(aspect) {
  5991. const ctor = this.constructor;
  5992. if (ctor.aspects == null) {
  5993. return false;
  5994. }
  5995. return ctor.aspects.has(aspect);
  5996. }
  5997. get session() {
  5998. return this[kSession];
  5999. }
  6000. clearSession() {
  6001. this[kSession] = void 0;
  6002. }
  6003. get canRetryRead() {
  6004. return true;
  6005. }
  6006. get canRetryWrite() {
  6007. return true;
  6008. }
  6009. };
  6010. exports2.AbstractOperation = AbstractOperation;
  6011. var AbstractCallbackOperation = class extends AbstractOperation {
  6012. constructor(options = {}) {
  6013. super(options);
  6014. }
  6015. execute(server, session) {
  6016. return (0, util_1.promisify)((callback) => {
  6017. this.executeCallback(server, session, callback);
  6018. })();
  6019. }
  6020. };
  6021. exports2.AbstractCallbackOperation = AbstractCallbackOperation;
  6022. function defineAspects(operation, aspects) {
  6023. if (!Array.isArray(aspects) && !(aspects instanceof Set)) {
  6024. aspects = [aspects];
  6025. }
  6026. aspects = new Set(aspects);
  6027. Object.defineProperty(operation, "aspects", {
  6028. value: aspects,
  6029. writable: false
  6030. });
  6031. return aspects;
  6032. }
  6033. exports2.defineAspects = defineAspects;
  6034. }
  6035. });
  6036. // node_modules/mongodb/lib/operations/command.js
  6037. var require_command = __commonJS({
  6038. "node_modules/mongodb/lib/operations/command.js"(exports2) {
  6039. "use strict";
  6040. Object.defineProperty(exports2, "__esModule", { value: true });
  6041. exports2.CommandCallbackOperation = exports2.CommandOperation = void 0;
  6042. var error_1 = require_error();
  6043. var explain_1 = require_explain();
  6044. var read_concern_1 = require_read_concern();
  6045. var server_selection_1 = require_server_selection();
  6046. var utils_1 = require_utils();
  6047. var write_concern_1 = require_write_concern();
  6048. var operation_1 = require_operation();
  6049. var CommandOperation = class extends operation_1.AbstractCallbackOperation {
  6050. constructor(parent, options) {
  6051. super(options);
  6052. this.options = options ?? {};
  6053. const dbNameOverride = (options == null ? void 0 : options.dbName) || (options == null ? void 0 : options.authdb);
  6054. if (dbNameOverride) {
  6055. this.ns = new utils_1.MongoDBNamespace(dbNameOverride, "$cmd");
  6056. } else {
  6057. this.ns = parent ? parent.s.namespace.withCollection("$cmd") : new utils_1.MongoDBNamespace("admin", "$cmd");
  6058. }
  6059. this.readConcern = read_concern_1.ReadConcern.fromOptions(options);
  6060. this.writeConcern = write_concern_1.WriteConcern.fromOptions(options);
  6061. if (this.hasAspect(operation_1.Aspect.EXPLAINABLE)) {
  6062. this.explain = explain_1.Explain.fromOptions(options);
  6063. } else if ((options == null ? void 0 : options.explain) != null) {
  6064. throw new error_1.MongoInvalidArgumentError(`Option "explain" is not supported on this command`);
  6065. }
  6066. }
  6067. get canRetryWrite() {
  6068. if (this.hasAspect(operation_1.Aspect.EXPLAINABLE)) {
  6069. return this.explain == null;
  6070. }
  6071. return true;
  6072. }
  6073. async executeCommand(server, session, cmd) {
  6074. this.server = server;
  6075. const options = {
  6076. ...this.options,
  6077. ...this.bsonOptions,
  6078. readPreference: this.readPreference,
  6079. session
  6080. };
  6081. const serverWireVersion = (0, utils_1.maxWireVersion)(server);
  6082. const inTransaction = this.session && this.session.inTransaction();
  6083. if (this.readConcern && (0, utils_1.commandSupportsReadConcern)(cmd) && !inTransaction) {
  6084. Object.assign(cmd, { readConcern: this.readConcern });
  6085. }
  6086. if (this.trySecondaryWrite && serverWireVersion < server_selection_1.MIN_SECONDARY_WRITE_WIRE_VERSION) {
  6087. options.omitReadPreference = true;
  6088. }
  6089. if (this.writeConcern && this.hasAspect(operation_1.Aspect.WRITE_OPERATION) && !inTransaction) {
  6090. write_concern_1.WriteConcern.apply(cmd, this.writeConcern);
  6091. }
  6092. if (options.collation && typeof options.collation === "object" && !this.hasAspect(operation_1.Aspect.SKIP_COLLATION)) {
  6093. Object.assign(cmd, { collation: options.collation });
  6094. }
  6095. if (typeof options.maxTimeMS === "number") {
  6096. cmd.maxTimeMS = options.maxTimeMS;
  6097. }
  6098. if (this.hasAspect(operation_1.Aspect.EXPLAINABLE) && this.explain) {
  6099. cmd = (0, utils_1.decorateWithExplain)(cmd, this.explain);
  6100. }
  6101. return server.commandAsync(this.ns, cmd, options);
  6102. }
  6103. };
  6104. exports2.CommandOperation = CommandOperation;
  6105. var CommandCallbackOperation = class extends CommandOperation {
  6106. constructor(parent, options) {
  6107. super(parent, options);
  6108. }
  6109. executeCommandCallback(server, session, cmd, callback) {
  6110. super.executeCommand(server, session, cmd).then((res) => callback(void 0, res), (err) => callback(err, void 0));
  6111. }
  6112. };
  6113. exports2.CommandCallbackOperation = CommandCallbackOperation;
  6114. }
  6115. });
  6116. // node_modules/mongodb/lib/operations/add_user.js
  6117. var require_add_user = __commonJS({
  6118. "node_modules/mongodb/lib/operations/add_user.js"(exports2) {
  6119. "use strict";
  6120. Object.defineProperty(exports2, "__esModule", { value: true });
  6121. exports2.AddUserOperation = void 0;
  6122. var crypto = require("crypto");
  6123. var error_1 = require_error();
  6124. var utils_1 = require_utils();
  6125. var command_1 = require_command();
  6126. var operation_1 = require_operation();
  6127. var AddUserOperation = class extends command_1.CommandCallbackOperation {
  6128. constructor(db, username, password, options) {
  6129. super(db, options);
  6130. this.db = db;
  6131. this.username = username;
  6132. this.password = password;
  6133. this.options = options ?? {};
  6134. }
  6135. executeCallback(server, session, callback) {
  6136. const db = this.db;
  6137. const username = this.username;
  6138. const password = this.password;
  6139. const options = this.options;
  6140. if ("digestPassword" in options && options.digestPassword != null) {
  6141. return callback(new error_1.MongoInvalidArgumentError('Option "digestPassword" not supported via addUser, use db.command(...) instead'));
  6142. }
  6143. let roles;
  6144. if (!options.roles || Array.isArray(options.roles) && options.roles.length === 0) {
  6145. (0, utils_1.emitWarningOnce)('Creating a user without roles is deprecated. Defaults to "root" if db is "admin" or "dbOwner" otherwise');
  6146. if (db.databaseName.toLowerCase() === "admin") {
  6147. roles = ["root"];
  6148. } else {
  6149. roles = ["dbOwner"];
  6150. }
  6151. } else {
  6152. roles = Array.isArray(options.roles) ? options.roles : [options.roles];
  6153. }
  6154. let topology;
  6155. try {
  6156. topology = (0, utils_1.getTopology)(db);
  6157. } catch (error) {
  6158. return callback(error);
  6159. }
  6160. const digestPassword = topology.lastHello().maxWireVersion >= 7;
  6161. let userPassword = password;
  6162. if (!digestPassword) {
  6163. const md5 = crypto.createHash("md5");
  6164. md5.update(`${username}:mongo:${password}`);
  6165. userPassword = md5.digest("hex");
  6166. }
  6167. const command = {
  6168. createUser: username,
  6169. customData: options.customData || {},
  6170. roles,
  6171. digestPassword
  6172. };
  6173. if (typeof password === "string") {
  6174. command.pwd = userPassword;
  6175. }
  6176. super.executeCommandCallback(server, session, command, callback);
  6177. }
  6178. };
  6179. exports2.AddUserOperation = AddUserOperation;
  6180. (0, operation_1.defineAspects)(AddUserOperation, [operation_1.Aspect.WRITE_OPERATION]);
  6181. }
  6182. });
  6183. // node_modules/mongodb/lib/operations/execute_operation.js
  6184. var require_execute_operation = __commonJS({
  6185. "node_modules/mongodb/lib/operations/execute_operation.js"(exports2) {
  6186. "use strict";
  6187. Object.defineProperty(exports2, "__esModule", { value: true });
  6188. exports2.executeOperation = void 0;
  6189. var error_1 = require_error();
  6190. var read_preference_1 = require_read_preference();
  6191. var server_selection_1 = require_server_selection();
  6192. var utils_1 = require_utils();
  6193. var operation_1 = require_operation();
  6194. var MMAPv1_RETRY_WRITES_ERROR_CODE = error_1.MONGODB_ERROR_CODES.IllegalOperation;
  6195. var MMAPv1_RETRY_WRITES_ERROR_MESSAGE = "This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.";
  6196. function executeOperation(client, operation, callback) {
  6197. return (0, utils_1.maybeCallback)(() => executeOperationAsync(client, operation), callback);
  6198. }
  6199. exports2.executeOperation = executeOperation;
  6200. async function executeOperationAsync(client, operation) {
  6201. var _a;
  6202. if (!(operation instanceof operation_1.AbstractCallbackOperation)) {
  6203. throw new error_1.MongoRuntimeError("This method requires a valid operation instance");
  6204. }
  6205. if (client.topology == null) {
  6206. if (client.s.hasBeenClosed) {
  6207. throw new error_1.MongoNotConnectedError("Client must be connected before running operations");
  6208. }
  6209. client.s.options[Symbol.for("@@mdb.skipPingOnConnect")] = true;
  6210. try {
  6211. await client.connect();
  6212. } finally {
  6213. delete client.s.options[Symbol.for("@@mdb.skipPingOnConnect")];
  6214. }
  6215. }
  6216. const { topology } = client;
  6217. if (topology == null) {
  6218. throw new error_1.MongoRuntimeError("client.connect did not create a topology but also did not throw");
  6219. }
  6220. let session = operation.session;
  6221. let owner;
  6222. if (session == null) {
  6223. owner = Symbol();
  6224. session = client.startSession({ owner, explicit: false });
  6225. } else if (session.hasEnded) {
  6226. throw new error_1.MongoExpiredSessionError("Use of expired sessions is not permitted");
  6227. } else if (session.snapshotEnabled && !topology.capabilities.supportsSnapshotReads) {
  6228. throw new error_1.MongoCompatibilityError("Snapshot reads require MongoDB 5.0 or later");
  6229. }
  6230. const readPreference = operation.readPreference ?? read_preference_1.ReadPreference.primary;
  6231. const inTransaction = !!(session == null ? void 0 : session.inTransaction());
  6232. if (inTransaction && !readPreference.equals(read_preference_1.ReadPreference.primary)) {
  6233. throw new error_1.MongoTransactionError(`Read preference in a transaction must be primary, not: ${readPreference.mode}`);
  6234. }
  6235. if ((session == null ? void 0 : session.isPinned) && session.transaction.isCommitted && !operation.bypassPinningCheck) {
  6236. session.unpin();
  6237. }
  6238. let selector;
  6239. if (operation.hasAspect(operation_1.Aspect.MUST_SELECT_SAME_SERVER)) {
  6240. selector = (0, server_selection_1.sameServerSelector)((_a = operation.server) == null ? void 0 : _a.description);
  6241. } else if (operation.trySecondaryWrite) {
  6242. selector = (0, server_selection_1.secondaryWritableServerSelector)(topology.commonWireVersion, readPreference);
  6243. } else {
  6244. selector = readPreference;
  6245. }
  6246. const server = await topology.selectServerAsync(selector, { session });
  6247. if (session == null) {
  6248. return operation.execute(server, void 0);
  6249. }
  6250. if (!operation.hasAspect(operation_1.Aspect.RETRYABLE)) {
  6251. try {
  6252. return await operation.execute(server, session);
  6253. } finally {
  6254. if ((session == null ? void 0 : session.owner) != null && session.owner === owner) {
  6255. await session.endSession().catch(() => null);
  6256. }
  6257. }
  6258. }
  6259. const willRetryRead = topology.s.options.retryReads && !inTransaction && operation.canRetryRead;
  6260. const willRetryWrite = topology.s.options.retryWrites && !inTransaction && (0, utils_1.supportsRetryableWrites)(server) && operation.canRetryWrite;
  6261. const hasReadAspect = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
  6262. const hasWriteAspect = operation.hasAspect(operation_1.Aspect.WRITE_OPERATION);
  6263. const willRetry = hasReadAspect && willRetryRead || hasWriteAspect && willRetryWrite;
  6264. if (hasWriteAspect && willRetryWrite) {
  6265. operation.options.willRetryWrite = true;
  6266. session.incrementTransactionNumber();
  6267. }
  6268. try {
  6269. return await operation.execute(server, session);
  6270. } catch (operationError) {
  6271. if (willRetry && operationError instanceof error_1.MongoError) {
  6272. return await retryOperation(operation, operationError, {
  6273. session,
  6274. topology,
  6275. selector
  6276. });
  6277. }
  6278. throw operationError;
  6279. } finally {
  6280. if ((session == null ? void 0 : session.owner) != null && session.owner === owner) {
  6281. await session.endSession().catch(() => null);
  6282. }
  6283. }
  6284. }
  6285. async function retryOperation(operation, originalError, { session, topology, selector }) {
  6286. const isWriteOperation = operation.hasAspect(operation_1.Aspect.WRITE_OPERATION);
  6287. const isReadOperation = operation.hasAspect(operation_1.Aspect.READ_OPERATION);
  6288. if (isWriteOperation && originalError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
  6289. throw new error_1.MongoServerError({
  6290. message: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
  6291. errmsg: MMAPv1_RETRY_WRITES_ERROR_MESSAGE,
  6292. originalError
  6293. });
  6294. }
  6295. if (isWriteOperation && !(0, error_1.isRetryableWriteError)(originalError)) {
  6296. throw originalError;
  6297. }
  6298. if (isReadOperation && !(0, error_1.isRetryableReadError)(originalError)) {
  6299. throw originalError;
  6300. }
  6301. if (originalError instanceof error_1.MongoNetworkError && session.isPinned && !session.inTransaction() && operation.hasAspect(operation_1.Aspect.CURSOR_CREATING)) {
  6302. session.unpin({ force: true, forceClear: true });
  6303. }
  6304. const server = await topology.selectServerAsync(selector, { session });
  6305. if (isWriteOperation && !(0, utils_1.supportsRetryableWrites)(server)) {
  6306. throw new error_1.MongoUnexpectedServerResponseError("Selected server does not support retryable writes");
  6307. }
  6308. try {
  6309. return await operation.execute(server, session);
  6310. } catch (retryError) {
  6311. if (retryError instanceof error_1.MongoError && retryError.hasErrorLabel(error_1.MongoErrorLabel.NoWritesPerformed)) {
  6312. throw originalError;
  6313. }
  6314. throw retryError;
  6315. }
  6316. }
  6317. }
  6318. });
  6319. // node_modules/mongodb/lib/operations/list_databases.js
  6320. var require_list_databases = __commonJS({
  6321. "node_modules/mongodb/lib/operations/list_databases.js"(exports2) {
  6322. "use strict";
  6323. Object.defineProperty(exports2, "__esModule", { value: true });
  6324. exports2.ListDatabasesOperation = void 0;
  6325. var utils_1 = require_utils();
  6326. var command_1 = require_command();
  6327. var operation_1 = require_operation();
  6328. var ListDatabasesOperation = class extends command_1.CommandCallbackOperation {
  6329. constructor(db, options) {
  6330. super(db, options);
  6331. this.options = options ?? {};
  6332. this.ns = new utils_1.MongoDBNamespace("admin", "$cmd");
  6333. }
  6334. executeCallback(server, session, callback) {
  6335. const cmd = { listDatabases: 1 };
  6336. if (typeof this.options.nameOnly === "boolean") {
  6337. cmd.nameOnly = this.options.nameOnly;
  6338. }
  6339. if (this.options.filter) {
  6340. cmd.filter = this.options.filter;
  6341. }
  6342. if (typeof this.options.authorizedDatabases === "boolean") {
  6343. cmd.authorizedDatabases = this.options.authorizedDatabases;
  6344. }
  6345. if ((0, utils_1.maxWireVersion)(server) >= 9 && this.options.comment !== void 0) {
  6346. cmd.comment = this.options.comment;
  6347. }
  6348. super.executeCommandCallback(server, session, cmd, callback);
  6349. }
  6350. };
  6351. exports2.ListDatabasesOperation = ListDatabasesOperation;
  6352. (0, operation_1.defineAspects)(ListDatabasesOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE]);
  6353. }
  6354. });
  6355. // node_modules/mongodb/lib/operations/remove_user.js
  6356. var require_remove_user = __commonJS({
  6357. "node_modules/mongodb/lib/operations/remove_user.js"(exports2) {
  6358. "use strict";
  6359. Object.defineProperty(exports2, "__esModule", { value: true });
  6360. exports2.RemoveUserOperation = void 0;
  6361. var command_1 = require_command();
  6362. var operation_1 = require_operation();
  6363. var RemoveUserOperation = class extends command_1.CommandCallbackOperation {
  6364. constructor(db, username, options) {
  6365. super(db, options);
  6366. this.options = options;
  6367. this.username = username;
  6368. }
  6369. executeCallback(server, session, callback) {
  6370. super.executeCommandCallback(server, session, { dropUser: this.username }, (err) => {
  6371. callback(err, err ? false : true);
  6372. });
  6373. }
  6374. };
  6375. exports2.RemoveUserOperation = RemoveUserOperation;
  6376. (0, operation_1.defineAspects)(RemoveUserOperation, [operation_1.Aspect.WRITE_OPERATION]);
  6377. }
  6378. });
  6379. // node_modules/mongodb/lib/operations/run_command.js
  6380. var require_run_command = __commonJS({
  6381. "node_modules/mongodb/lib/operations/run_command.js"(exports2) {
  6382. "use strict";
  6383. Object.defineProperty(exports2, "__esModule", { value: true });
  6384. exports2.RunAdminCommandOperation = exports2.RunCommandOperation = void 0;
  6385. var utils_1 = require_utils();
  6386. var command_1 = require_command();
  6387. var RunCommandOperation = class extends command_1.CommandCallbackOperation {
  6388. constructor(parent, command, options) {
  6389. super(parent, options);
  6390. this.options = options ?? {};
  6391. this.command = command;
  6392. }
  6393. executeCallback(server, session, callback) {
  6394. const command = this.command;
  6395. this.executeCommandCallback(server, session, command, callback);
  6396. }
  6397. };
  6398. exports2.RunCommandOperation = RunCommandOperation;
  6399. var RunAdminCommandOperation = class extends RunCommandOperation {
  6400. constructor(parent, command, options) {
  6401. super(parent, command, options);
  6402. this.ns = new utils_1.MongoDBNamespace("admin");
  6403. }
  6404. };
  6405. exports2.RunAdminCommandOperation = RunAdminCommandOperation;
  6406. }
  6407. });
  6408. // node_modules/mongodb/lib/operations/validate_collection.js
  6409. var require_validate_collection = __commonJS({
  6410. "node_modules/mongodb/lib/operations/validate_collection.js"(exports2) {
  6411. "use strict";
  6412. Object.defineProperty(exports2, "__esModule", { value: true });
  6413. exports2.ValidateCollectionOperation = void 0;
  6414. var error_1 = require_error();
  6415. var command_1 = require_command();
  6416. var ValidateCollectionOperation = class extends command_1.CommandCallbackOperation {
  6417. constructor(admin, collectionName, options) {
  6418. const command = { validate: collectionName };
  6419. const keys = Object.keys(options);
  6420. for (let i = 0; i < keys.length; i++) {
  6421. if (Object.prototype.hasOwnProperty.call(options, keys[i]) && keys[i] !== "session") {
  6422. command[keys[i]] = options[keys[i]];
  6423. }
  6424. }
  6425. super(admin.s.db, options);
  6426. this.options = options;
  6427. this.command = command;
  6428. this.collectionName = collectionName;
  6429. }
  6430. executeCallback(server, session, callback) {
  6431. const collectionName = this.collectionName;
  6432. super.executeCommandCallback(server, session, this.command, (err, doc) => {
  6433. if (err != null)
  6434. return callback(err);
  6435. if (doc.ok === 0)
  6436. return callback(new error_1.MongoRuntimeError("Error with validate command"));
  6437. if (doc.result != null && typeof doc.result !== "string")
  6438. return callback(new error_1.MongoRuntimeError("Error with validation data"));
  6439. if (doc.result != null && doc.result.match(/exception|corrupt/) != null)
  6440. return callback(new error_1.MongoRuntimeError(`Invalid collection ${collectionName}`));
  6441. if (doc.valid != null && !doc.valid)
  6442. return callback(new error_1.MongoRuntimeError(`Invalid collection ${collectionName}`));
  6443. return callback(void 0, doc);
  6444. });
  6445. }
  6446. };
  6447. exports2.ValidateCollectionOperation = ValidateCollectionOperation;
  6448. }
  6449. });
  6450. // node_modules/mongodb/lib/admin.js
  6451. var require_admin = __commonJS({
  6452. "node_modules/mongodb/lib/admin.js"(exports2) {
  6453. "use strict";
  6454. Object.defineProperty(exports2, "__esModule", { value: true });
  6455. exports2.Admin = void 0;
  6456. var add_user_1 = require_add_user();
  6457. var execute_operation_1 = require_execute_operation();
  6458. var list_databases_1 = require_list_databases();
  6459. var remove_user_1 = require_remove_user();
  6460. var run_command_1 = require_run_command();
  6461. var validate_collection_1 = require_validate_collection();
  6462. var Admin = class {
  6463. /**
  6464. * Create a new Admin instance
  6465. * @internal
  6466. */
  6467. constructor(db) {
  6468. this.s = { db };
  6469. }
  6470. /**
  6471. * Execute a command
  6472. *
  6473. * The driver will ensure the following fields are attached to the command sent to the server:
  6474. * - `lsid` - sourced from an implicit session or options.session
  6475. * - `$readPreference` - defaults to primary or can be configured by options.readPreference
  6476. * - `$db` - sourced from the name of this database
  6477. *
  6478. * If the client has a serverApi setting:
  6479. * - `apiVersion`
  6480. * - `apiStrict`
  6481. * - `apiDeprecationErrors`
  6482. *
  6483. * When in a transaction:
  6484. * - `readConcern` - sourced from readConcern set on the TransactionOptions
  6485. * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
  6486. *
  6487. * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
  6488. *
  6489. * @param command - The command to execute
  6490. * @param options - Optional settings for the command
  6491. */
  6492. async command(command, options) {
  6493. return (0, execute_operation_1.executeOperation)(this.s.db.client, new run_command_1.RunCommandOperation(this.s.db, command, { dbName: "admin", ...options }));
  6494. }
  6495. /**
  6496. * Retrieve the server build information
  6497. *
  6498. * @param options - Optional settings for the command
  6499. */
  6500. async buildInfo(options) {
  6501. return this.command({ buildinfo: 1 }, options);
  6502. }
  6503. /**
  6504. * Retrieve the server build information
  6505. *
  6506. * @param options - Optional settings for the command
  6507. */
  6508. async serverInfo(options) {
  6509. return this.command({ buildinfo: 1 }, options);
  6510. }
  6511. /**
  6512. * Retrieve this db's server status.
  6513. *
  6514. * @param options - Optional settings for the command
  6515. */
  6516. async serverStatus(options) {
  6517. return this.command({ serverStatus: 1 }, options);
  6518. }
  6519. /**
  6520. * Ping the MongoDB server and retrieve results
  6521. *
  6522. * @param options - Optional settings for the command
  6523. */
  6524. async ping(options) {
  6525. return this.command({ ping: 1 }, options);
  6526. }
  6527. /**
  6528. * Add a user to the database
  6529. *
  6530. * @param username - The username for the new user
  6531. * @param passwordOrOptions - An optional password for the new user, or the options for the command
  6532. * @param options - Optional settings for the command
  6533. * @deprecated Use the createUser command in `db.command()` instead.
  6534. * @see https://www.mongodb.com/docs/manual/reference/command/createUser/
  6535. */
  6536. async addUser(username, passwordOrOptions, options) {
  6537. options = options != null && typeof options === "object" ? options : passwordOrOptions != null && typeof passwordOrOptions === "object" ? passwordOrOptions : void 0;
  6538. const password = typeof passwordOrOptions === "string" ? passwordOrOptions : void 0;
  6539. return (0, execute_operation_1.executeOperation)(this.s.db.client, new add_user_1.AddUserOperation(this.s.db, username, password, { dbName: "admin", ...options }));
  6540. }
  6541. /**
  6542. * Remove a user from a database
  6543. *
  6544. * @param username - The username to remove
  6545. * @param options - Optional settings for the command
  6546. */
  6547. async removeUser(username, options) {
  6548. return (0, execute_operation_1.executeOperation)(this.s.db.client, new remove_user_1.RemoveUserOperation(this.s.db, username, { dbName: "admin", ...options }));
  6549. }
  6550. /**
  6551. * Validate an existing collection
  6552. *
  6553. * @param collectionName - The name of the collection to validate.
  6554. * @param options - Optional settings for the command
  6555. */
  6556. async validateCollection(collectionName, options = {}) {
  6557. return (0, execute_operation_1.executeOperation)(this.s.db.client, new validate_collection_1.ValidateCollectionOperation(this, collectionName, options));
  6558. }
  6559. /**
  6560. * List the available databases
  6561. *
  6562. * @param options - Optional settings for the command
  6563. */
  6564. async listDatabases(options) {
  6565. return (0, execute_operation_1.executeOperation)(this.s.db.client, new list_databases_1.ListDatabasesOperation(this.s.db, options));
  6566. }
  6567. /**
  6568. * Get ReplicaSet status
  6569. *
  6570. * @param options - Optional settings for the command
  6571. */
  6572. async replSetGetStatus(options) {
  6573. return this.command({ replSetGetStatus: 1 }, options);
  6574. }
  6575. };
  6576. exports2.Admin = Admin;
  6577. }
  6578. });
  6579. // node_modules/mongodb/lib/operations/delete.js
  6580. var require_delete = __commonJS({
  6581. "node_modules/mongodb/lib/operations/delete.js"(exports2) {
  6582. "use strict";
  6583. Object.defineProperty(exports2, "__esModule", { value: true });
  6584. exports2.makeDeleteStatement = exports2.DeleteManyOperation = exports2.DeleteOneOperation = exports2.DeleteOperation = void 0;
  6585. var error_1 = require_error();
  6586. var command_1 = require_command();
  6587. var operation_1 = require_operation();
  6588. var DeleteOperation = class extends command_1.CommandCallbackOperation {
  6589. constructor(ns, statements, options) {
  6590. super(void 0, options);
  6591. this.options = options;
  6592. this.ns = ns;
  6593. this.statements = statements;
  6594. }
  6595. get canRetryWrite() {
  6596. if (super.canRetryWrite === false) {
  6597. return false;
  6598. }
  6599. return this.statements.every((op) => op.limit != null ? op.limit > 0 : true);
  6600. }
  6601. executeCallback(server, session, callback) {
  6602. const options = this.options ?? {};
  6603. const ordered = typeof options.ordered === "boolean" ? options.ordered : true;
  6604. const command = {
  6605. delete: this.ns.collection,
  6606. deletes: this.statements,
  6607. ordered
  6608. };
  6609. if (options.let) {
  6610. command.let = options.let;
  6611. }
  6612. if (options.comment !== void 0) {
  6613. command.comment = options.comment;
  6614. }
  6615. const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
  6616. if (unacknowledgedWrite) {
  6617. if (this.statements.find((o) => o.hint)) {
  6618. callback(new error_1.MongoCompatibilityError(`hint is not supported with unacknowledged writes`));
  6619. return;
  6620. }
  6621. }
  6622. super.executeCommandCallback(server, session, command, callback);
  6623. }
  6624. };
  6625. exports2.DeleteOperation = DeleteOperation;
  6626. var DeleteOneOperation = class extends DeleteOperation {
  6627. constructor(collection, filter, options) {
  6628. super(collection.s.namespace, [makeDeleteStatement(filter, { ...options, limit: 1 })], options);
  6629. }
  6630. executeCallback(server, session, callback) {
  6631. super.executeCallback(server, session, (err, res) => {
  6632. var _a;
  6633. if (err || res == null)
  6634. return callback(err);
  6635. if (res.code)
  6636. return callback(new error_1.MongoServerError(res));
  6637. if (res.writeErrors)
  6638. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  6639. if (this.explain)
  6640. return callback(void 0, res);
  6641. callback(void 0, {
  6642. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  6643. deletedCount: res.n
  6644. });
  6645. });
  6646. }
  6647. };
  6648. exports2.DeleteOneOperation = DeleteOneOperation;
  6649. var DeleteManyOperation = class extends DeleteOperation {
  6650. constructor(collection, filter, options) {
  6651. super(collection.s.namespace, [makeDeleteStatement(filter, options)], options);
  6652. }
  6653. executeCallback(server, session, callback) {
  6654. super.executeCallback(server, session, (err, res) => {
  6655. var _a;
  6656. if (err || res == null)
  6657. return callback(err);
  6658. if (res.code)
  6659. return callback(new error_1.MongoServerError(res));
  6660. if (res.writeErrors)
  6661. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  6662. if (this.explain)
  6663. return callback(void 0, res);
  6664. callback(void 0, {
  6665. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  6666. deletedCount: res.n
  6667. });
  6668. });
  6669. }
  6670. };
  6671. exports2.DeleteManyOperation = DeleteManyOperation;
  6672. function makeDeleteStatement(filter, options) {
  6673. const op = {
  6674. q: filter,
  6675. limit: typeof options.limit === "number" ? options.limit : 0
  6676. };
  6677. if (options.collation) {
  6678. op.collation = options.collation;
  6679. }
  6680. if (options.hint) {
  6681. op.hint = options.hint;
  6682. }
  6683. return op;
  6684. }
  6685. exports2.makeDeleteStatement = makeDeleteStatement;
  6686. (0, operation_1.defineAspects)(DeleteOperation, [operation_1.Aspect.RETRYABLE, operation_1.Aspect.WRITE_OPERATION]);
  6687. (0, operation_1.defineAspects)(DeleteOneOperation, [
  6688. operation_1.Aspect.RETRYABLE,
  6689. operation_1.Aspect.WRITE_OPERATION,
  6690. operation_1.Aspect.EXPLAINABLE,
  6691. operation_1.Aspect.SKIP_COLLATION
  6692. ]);
  6693. (0, operation_1.defineAspects)(DeleteManyOperation, [
  6694. operation_1.Aspect.WRITE_OPERATION,
  6695. operation_1.Aspect.EXPLAINABLE,
  6696. operation_1.Aspect.SKIP_COLLATION
  6697. ]);
  6698. }
  6699. });
  6700. // node_modules/mongodb/lib/operations/bulk_write.js
  6701. var require_bulk_write = __commonJS({
  6702. "node_modules/mongodb/lib/operations/bulk_write.js"(exports2) {
  6703. "use strict";
  6704. Object.defineProperty(exports2, "__esModule", { value: true });
  6705. exports2.BulkWriteOperation = void 0;
  6706. var operation_1 = require_operation();
  6707. var BulkWriteOperation = class extends operation_1.AbstractCallbackOperation {
  6708. constructor(collection, operations, options) {
  6709. super(options);
  6710. this.options = options;
  6711. this.collection = collection;
  6712. this.operations = operations;
  6713. }
  6714. executeCallback(server, session, callback) {
  6715. const coll = this.collection;
  6716. const operations = this.operations;
  6717. const options = { ...this.options, ...this.bsonOptions, readPreference: this.readPreference };
  6718. const bulk = options.ordered === false ? coll.initializeUnorderedBulkOp(options) : coll.initializeOrderedBulkOp(options);
  6719. try {
  6720. for (let i = 0; i < operations.length; i++) {
  6721. bulk.raw(operations[i]);
  6722. }
  6723. } catch (err) {
  6724. return callback(err);
  6725. }
  6726. bulk.execute({ ...options, session }).then((result) => callback(void 0, result), (error) => callback(error));
  6727. }
  6728. };
  6729. exports2.BulkWriteOperation = BulkWriteOperation;
  6730. (0, operation_1.defineAspects)(BulkWriteOperation, [operation_1.Aspect.WRITE_OPERATION]);
  6731. }
  6732. });
  6733. // node_modules/mongodb/lib/operations/common_functions.js
  6734. var require_common_functions = __commonJS({
  6735. "node_modules/mongodb/lib/operations/common_functions.js"(exports2) {
  6736. "use strict";
  6737. Object.defineProperty(exports2, "__esModule", { value: true });
  6738. exports2.prepareDocs = exports2.indexInformation = void 0;
  6739. var error_1 = require_error();
  6740. var utils_1 = require_utils();
  6741. function indexInformation(db, name, _optionsOrCallback, _callback) {
  6742. let options = _optionsOrCallback;
  6743. let callback = _callback;
  6744. if ("function" === typeof _optionsOrCallback) {
  6745. callback = _optionsOrCallback;
  6746. options = {};
  6747. }
  6748. const full = options.full == null ? false : options.full;
  6749. let topology;
  6750. try {
  6751. topology = (0, utils_1.getTopology)(db);
  6752. } catch (error) {
  6753. return callback(error);
  6754. }
  6755. if (topology.isDestroyed())
  6756. return callback(new error_1.MongoTopologyClosedError());
  6757. function processResults(indexes) {
  6758. const info = {};
  6759. for (let i = 0; i < indexes.length; i++) {
  6760. const index = indexes[i];
  6761. info[index.name] = [];
  6762. for (const name2 in index.key) {
  6763. info[index.name].push([name2, index.key[name2]]);
  6764. }
  6765. }
  6766. return info;
  6767. }
  6768. db.collection(name).listIndexes(options).toArray().then((indexes) => {
  6769. if (!Array.isArray(indexes))
  6770. return callback(void 0, []);
  6771. if (full)
  6772. return callback(void 0, indexes);
  6773. callback(void 0, processResults(indexes));
  6774. }, (error) => callback(error));
  6775. }
  6776. exports2.indexInformation = indexInformation;
  6777. function prepareDocs(coll, docs, options) {
  6778. var _a;
  6779. const forceServerObjectId = typeof options.forceServerObjectId === "boolean" ? options.forceServerObjectId : (_a = coll.s.db.options) == null ? void 0 : _a.forceServerObjectId;
  6780. if (forceServerObjectId === true) {
  6781. return docs;
  6782. }
  6783. return docs.map((doc) => {
  6784. if (doc._id == null) {
  6785. doc._id = coll.s.pkFactory.createPk();
  6786. }
  6787. return doc;
  6788. });
  6789. }
  6790. exports2.prepareDocs = prepareDocs;
  6791. }
  6792. });
  6793. // node_modules/mongodb/lib/operations/insert.js
  6794. var require_insert = __commonJS({
  6795. "node_modules/mongodb/lib/operations/insert.js"(exports2) {
  6796. "use strict";
  6797. Object.defineProperty(exports2, "__esModule", { value: true });
  6798. exports2.InsertManyOperation = exports2.InsertOneOperation = exports2.InsertOperation = void 0;
  6799. var error_1 = require_error();
  6800. var write_concern_1 = require_write_concern();
  6801. var bulk_write_1 = require_bulk_write();
  6802. var command_1 = require_command();
  6803. var common_functions_1 = require_common_functions();
  6804. var operation_1 = require_operation();
  6805. var InsertOperation = class extends command_1.CommandCallbackOperation {
  6806. constructor(ns, documents, options) {
  6807. super(void 0, options);
  6808. this.options = { ...options, checkKeys: options.checkKeys ?? false };
  6809. this.ns = ns;
  6810. this.documents = documents;
  6811. }
  6812. executeCallback(server, session, callback) {
  6813. const options = this.options ?? {};
  6814. const ordered = typeof options.ordered === "boolean" ? options.ordered : true;
  6815. const command = {
  6816. insert: this.ns.collection,
  6817. documents: this.documents,
  6818. ordered
  6819. };
  6820. if (typeof options.bypassDocumentValidation === "boolean") {
  6821. command.bypassDocumentValidation = options.bypassDocumentValidation;
  6822. }
  6823. if (options.comment !== void 0) {
  6824. command.comment = options.comment;
  6825. }
  6826. super.executeCommandCallback(server, session, command, callback);
  6827. }
  6828. };
  6829. exports2.InsertOperation = InsertOperation;
  6830. var InsertOneOperation = class extends InsertOperation {
  6831. constructor(collection, doc, options) {
  6832. super(collection.s.namespace, (0, common_functions_1.prepareDocs)(collection, [doc], options), options);
  6833. }
  6834. executeCallback(server, session, callback) {
  6835. super.executeCallback(server, session, (err, res) => {
  6836. var _a;
  6837. if (err || res == null)
  6838. return callback(err);
  6839. if (res.code)
  6840. return callback(new error_1.MongoServerError(res));
  6841. if (res.writeErrors) {
  6842. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  6843. }
  6844. callback(void 0, {
  6845. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  6846. insertedId: this.documents[0]._id
  6847. });
  6848. });
  6849. }
  6850. };
  6851. exports2.InsertOneOperation = InsertOneOperation;
  6852. var InsertManyOperation = class extends operation_1.AbstractCallbackOperation {
  6853. constructor(collection, docs, options) {
  6854. super(options);
  6855. if (!Array.isArray(docs)) {
  6856. throw new error_1.MongoInvalidArgumentError('Argument "docs" must be an array of documents');
  6857. }
  6858. this.options = options;
  6859. this.collection = collection;
  6860. this.docs = docs;
  6861. }
  6862. executeCallback(server, session, callback) {
  6863. const coll = this.collection;
  6864. const options = { ...this.options, ...this.bsonOptions, readPreference: this.readPreference };
  6865. const writeConcern = write_concern_1.WriteConcern.fromOptions(options);
  6866. const bulkWriteOperation = new bulk_write_1.BulkWriteOperation(coll, (0, common_functions_1.prepareDocs)(coll, this.docs, options).map((document) => ({ insertOne: { document } })), options);
  6867. bulkWriteOperation.executeCallback(server, session, (err, res) => {
  6868. if (err || res == null) {
  6869. if (err && err.message === "Operation must be an object with an operation key") {
  6870. err = new error_1.MongoInvalidArgumentError("Collection.insertMany() cannot be called with an array that has null/undefined values");
  6871. }
  6872. return callback(err);
  6873. }
  6874. callback(void 0, {
  6875. acknowledged: (writeConcern == null ? void 0 : writeConcern.w) !== 0,
  6876. insertedCount: res.insertedCount,
  6877. insertedIds: res.insertedIds
  6878. });
  6879. });
  6880. }
  6881. };
  6882. exports2.InsertManyOperation = InsertManyOperation;
  6883. (0, operation_1.defineAspects)(InsertOperation, [operation_1.Aspect.RETRYABLE, operation_1.Aspect.WRITE_OPERATION]);
  6884. (0, operation_1.defineAspects)(InsertOneOperation, [operation_1.Aspect.RETRYABLE, operation_1.Aspect.WRITE_OPERATION]);
  6885. (0, operation_1.defineAspects)(InsertManyOperation, [operation_1.Aspect.WRITE_OPERATION]);
  6886. }
  6887. });
  6888. // node_modules/mongodb/lib/operations/update.js
  6889. var require_update = __commonJS({
  6890. "node_modules/mongodb/lib/operations/update.js"(exports2) {
  6891. "use strict";
  6892. Object.defineProperty(exports2, "__esModule", { value: true });
  6893. exports2.makeUpdateStatement = exports2.ReplaceOneOperation = exports2.UpdateManyOperation = exports2.UpdateOneOperation = exports2.UpdateOperation = void 0;
  6894. var error_1 = require_error();
  6895. var utils_1 = require_utils();
  6896. var command_1 = require_command();
  6897. var operation_1 = require_operation();
  6898. var UpdateOperation = class extends command_1.CommandCallbackOperation {
  6899. constructor(ns, statements, options) {
  6900. super(void 0, options);
  6901. this.options = options;
  6902. this.ns = ns;
  6903. this.statements = statements;
  6904. }
  6905. get canRetryWrite() {
  6906. if (super.canRetryWrite === false) {
  6907. return false;
  6908. }
  6909. return this.statements.every((op) => op.multi == null || op.multi === false);
  6910. }
  6911. executeCallback(server, session, callback) {
  6912. const options = this.options ?? {};
  6913. const ordered = typeof options.ordered === "boolean" ? options.ordered : true;
  6914. const command = {
  6915. update: this.ns.collection,
  6916. updates: this.statements,
  6917. ordered
  6918. };
  6919. if (typeof options.bypassDocumentValidation === "boolean") {
  6920. command.bypassDocumentValidation = options.bypassDocumentValidation;
  6921. }
  6922. if (options.let) {
  6923. command.let = options.let;
  6924. }
  6925. if (options.comment !== void 0) {
  6926. command.comment = options.comment;
  6927. }
  6928. const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
  6929. if (unacknowledgedWrite) {
  6930. if (this.statements.find((o) => o.hint)) {
  6931. callback(new error_1.MongoCompatibilityError(`hint is not supported with unacknowledged writes`));
  6932. return;
  6933. }
  6934. }
  6935. super.executeCommandCallback(server, session, command, callback);
  6936. }
  6937. };
  6938. exports2.UpdateOperation = UpdateOperation;
  6939. var UpdateOneOperation = class extends UpdateOperation {
  6940. constructor(collection, filter, update, options) {
  6941. super(collection.s.namespace, [makeUpdateStatement(filter, update, { ...options, multi: false })], options);
  6942. if (!(0, utils_1.hasAtomicOperators)(update)) {
  6943. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  6944. }
  6945. }
  6946. executeCallback(server, session, callback) {
  6947. super.executeCallback(server, session, (err, res) => {
  6948. var _a;
  6949. if (err || !res)
  6950. return callback(err);
  6951. if (this.explain != null)
  6952. return callback(void 0, res);
  6953. if (res.code)
  6954. return callback(new error_1.MongoServerError(res));
  6955. if (res.writeErrors)
  6956. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  6957. callback(void 0, {
  6958. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  6959. modifiedCount: res.nModified != null ? res.nModified : res.n,
  6960. upsertedId: Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
  6961. upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
  6962. matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
  6963. });
  6964. });
  6965. }
  6966. };
  6967. exports2.UpdateOneOperation = UpdateOneOperation;
  6968. var UpdateManyOperation = class extends UpdateOperation {
  6969. constructor(collection, filter, update, options) {
  6970. super(collection.s.namespace, [makeUpdateStatement(filter, update, { ...options, multi: true })], options);
  6971. if (!(0, utils_1.hasAtomicOperators)(update)) {
  6972. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  6973. }
  6974. }
  6975. executeCallback(server, session, callback) {
  6976. super.executeCallback(server, session, (err, res) => {
  6977. var _a;
  6978. if (err || !res)
  6979. return callback(err);
  6980. if (this.explain != null)
  6981. return callback(void 0, res);
  6982. if (res.code)
  6983. return callback(new error_1.MongoServerError(res));
  6984. if (res.writeErrors)
  6985. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  6986. callback(void 0, {
  6987. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  6988. modifiedCount: res.nModified != null ? res.nModified : res.n,
  6989. upsertedId: Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
  6990. upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
  6991. matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
  6992. });
  6993. });
  6994. }
  6995. };
  6996. exports2.UpdateManyOperation = UpdateManyOperation;
  6997. var ReplaceOneOperation = class extends UpdateOperation {
  6998. constructor(collection, filter, replacement, options) {
  6999. super(collection.s.namespace, [makeUpdateStatement(filter, replacement, { ...options, multi: false })], options);
  7000. if ((0, utils_1.hasAtomicOperators)(replacement)) {
  7001. throw new error_1.MongoInvalidArgumentError("Replacement document must not contain atomic operators");
  7002. }
  7003. }
  7004. executeCallback(server, session, callback) {
  7005. super.executeCallback(server, session, (err, res) => {
  7006. var _a;
  7007. if (err || !res)
  7008. return callback(err);
  7009. if (this.explain != null)
  7010. return callback(void 0, res);
  7011. if (res.code)
  7012. return callback(new error_1.MongoServerError(res));
  7013. if (res.writeErrors)
  7014. return callback(new error_1.MongoServerError(res.writeErrors[0]));
  7015. callback(void 0, {
  7016. acknowledged: ((_a = this.writeConcern) == null ? void 0 : _a.w) !== 0,
  7017. modifiedCount: res.nModified != null ? res.nModified : res.n,
  7018. upsertedId: Array.isArray(res.upserted) && res.upserted.length > 0 ? res.upserted[0]._id : null,
  7019. upsertedCount: Array.isArray(res.upserted) && res.upserted.length ? res.upserted.length : 0,
  7020. matchedCount: Array.isArray(res.upserted) && res.upserted.length > 0 ? 0 : res.n
  7021. });
  7022. });
  7023. }
  7024. };
  7025. exports2.ReplaceOneOperation = ReplaceOneOperation;
  7026. function makeUpdateStatement(filter, update, options) {
  7027. if (filter == null || typeof filter !== "object") {
  7028. throw new error_1.MongoInvalidArgumentError("Selector must be a valid JavaScript object");
  7029. }
  7030. if (update == null || typeof update !== "object") {
  7031. throw new error_1.MongoInvalidArgumentError("Document must be a valid JavaScript object");
  7032. }
  7033. const op = { q: filter, u: update };
  7034. if (typeof options.upsert === "boolean") {
  7035. op.upsert = options.upsert;
  7036. }
  7037. if (options.multi) {
  7038. op.multi = options.multi;
  7039. }
  7040. if (options.hint) {
  7041. op.hint = options.hint;
  7042. }
  7043. if (options.arrayFilters) {
  7044. op.arrayFilters = options.arrayFilters;
  7045. }
  7046. if (options.collation) {
  7047. op.collation = options.collation;
  7048. }
  7049. return op;
  7050. }
  7051. exports2.makeUpdateStatement = makeUpdateStatement;
  7052. (0, operation_1.defineAspects)(UpdateOperation, [operation_1.Aspect.RETRYABLE, operation_1.Aspect.WRITE_OPERATION, operation_1.Aspect.SKIP_COLLATION]);
  7053. (0, operation_1.defineAspects)(UpdateOneOperation, [
  7054. operation_1.Aspect.RETRYABLE,
  7055. operation_1.Aspect.WRITE_OPERATION,
  7056. operation_1.Aspect.EXPLAINABLE,
  7057. operation_1.Aspect.SKIP_COLLATION
  7058. ]);
  7059. (0, operation_1.defineAspects)(UpdateManyOperation, [
  7060. operation_1.Aspect.WRITE_OPERATION,
  7061. operation_1.Aspect.EXPLAINABLE,
  7062. operation_1.Aspect.SKIP_COLLATION
  7063. ]);
  7064. (0, operation_1.defineAspects)(ReplaceOneOperation, [
  7065. operation_1.Aspect.RETRYABLE,
  7066. operation_1.Aspect.WRITE_OPERATION,
  7067. operation_1.Aspect.SKIP_COLLATION
  7068. ]);
  7069. }
  7070. });
  7071. // node_modules/mongodb/lib/bulk/common.js
  7072. var require_common2 = __commonJS({
  7073. "node_modules/mongodb/lib/bulk/common.js"(exports2) {
  7074. "use strict";
  7075. Object.defineProperty(exports2, "__esModule", { value: true });
  7076. exports2.BulkOperationBase = exports2.FindOperators = exports2.MongoBulkWriteError = exports2.mergeBatchResults = exports2.WriteError = exports2.WriteConcernError = exports2.BulkWriteResult = exports2.Batch = exports2.BatchType = void 0;
  7077. var bson_1 = require_bson2();
  7078. var error_1 = require_error();
  7079. var delete_1 = require_delete();
  7080. var execute_operation_1 = require_execute_operation();
  7081. var insert_1 = require_insert();
  7082. var operation_1 = require_operation();
  7083. var update_1 = require_update();
  7084. var utils_1 = require_utils();
  7085. var write_concern_1 = require_write_concern();
  7086. var kServerError = Symbol("serverError");
  7087. exports2.BatchType = Object.freeze({
  7088. INSERT: 1,
  7089. UPDATE: 2,
  7090. DELETE: 3
  7091. });
  7092. var Batch = class {
  7093. constructor(batchType, originalZeroIndex) {
  7094. this.originalZeroIndex = originalZeroIndex;
  7095. this.currentIndex = 0;
  7096. this.originalIndexes = [];
  7097. this.batchType = batchType;
  7098. this.operations = [];
  7099. this.size = 0;
  7100. this.sizeBytes = 0;
  7101. }
  7102. };
  7103. exports2.Batch = Batch;
  7104. var BulkWriteResult = class _BulkWriteResult {
  7105. static generateIdMap(ids) {
  7106. const idMap = {};
  7107. for (const doc of ids) {
  7108. idMap[doc.index] = doc._id;
  7109. }
  7110. return idMap;
  7111. }
  7112. /**
  7113. * Create a new BulkWriteResult instance
  7114. * @internal
  7115. */
  7116. constructor(bulkResult, isOrdered) {
  7117. this.result = bulkResult;
  7118. this.insertedCount = this.result.nInserted ?? 0;
  7119. this.matchedCount = this.result.nMatched ?? 0;
  7120. this.modifiedCount = this.result.nModified ?? 0;
  7121. this.deletedCount = this.result.nRemoved ?? 0;
  7122. this.upsertedCount = this.result.upserted.length ?? 0;
  7123. this.upsertedIds = _BulkWriteResult.generateIdMap(this.result.upserted);
  7124. this.insertedIds = _BulkWriteResult.generateIdMap(this.getSuccessfullyInsertedIds(bulkResult, isOrdered));
  7125. Object.defineProperty(this, "result", { value: this.result, enumerable: false });
  7126. }
  7127. /**
  7128. * Returns document_ids that were actually inserted
  7129. * @internal
  7130. */
  7131. getSuccessfullyInsertedIds(bulkResult, isOrdered) {
  7132. if (bulkResult.writeErrors.length === 0)
  7133. return bulkResult.insertedIds;
  7134. if (isOrdered) {
  7135. return bulkResult.insertedIds.slice(0, bulkResult.writeErrors[0].index);
  7136. }
  7137. return bulkResult.insertedIds.filter(({ index }) => !bulkResult.writeErrors.some((writeError) => index === writeError.index));
  7138. }
  7139. /** Evaluates to true if the bulk operation correctly executes */
  7140. get ok() {
  7141. return this.result.ok;
  7142. }
  7143. /**
  7144. * The number of inserted documents
  7145. * @deprecated Use insertedCount instead.
  7146. */
  7147. get nInserted() {
  7148. return this.result.nInserted;
  7149. }
  7150. /**
  7151. * Number of upserted documents
  7152. * @deprecated User upsertedCount instead.
  7153. */
  7154. get nUpserted() {
  7155. return this.result.nUpserted;
  7156. }
  7157. /**
  7158. * Number of matched documents
  7159. * @deprecated Use matchedCount instead.
  7160. */
  7161. get nMatched() {
  7162. return this.result.nMatched;
  7163. }
  7164. /**
  7165. * Number of documents updated physically on disk
  7166. * @deprecated Use modifiedCount instead.
  7167. */
  7168. get nModified() {
  7169. return this.result.nModified;
  7170. }
  7171. /**
  7172. * Number of removed documents
  7173. * @deprecated Use deletedCount instead.
  7174. */
  7175. get nRemoved() {
  7176. return this.result.nRemoved;
  7177. }
  7178. /**
  7179. * Returns an array of all inserted ids
  7180. * @deprecated Use insertedIds instead.
  7181. */
  7182. getInsertedIds() {
  7183. return this.result.insertedIds;
  7184. }
  7185. /**
  7186. * Returns an array of all upserted ids
  7187. * @deprecated Use upsertedIds instead.
  7188. */
  7189. getUpsertedIds() {
  7190. return this.result.upserted;
  7191. }
  7192. /** Returns the upserted id at the given index */
  7193. getUpsertedIdAt(index) {
  7194. return this.result.upserted[index];
  7195. }
  7196. /** Returns raw internal result */
  7197. getRawResponse() {
  7198. return this.result;
  7199. }
  7200. /** Returns true if the bulk operation contains a write error */
  7201. hasWriteErrors() {
  7202. return this.result.writeErrors.length > 0;
  7203. }
  7204. /** Returns the number of write errors off the bulk operation */
  7205. getWriteErrorCount() {
  7206. return this.result.writeErrors.length;
  7207. }
  7208. /** Returns a specific write error object */
  7209. getWriteErrorAt(index) {
  7210. return index < this.result.writeErrors.length ? this.result.writeErrors[index] : void 0;
  7211. }
  7212. /** Retrieve all write errors */
  7213. getWriteErrors() {
  7214. return this.result.writeErrors;
  7215. }
  7216. /** Retrieve the write concern error if one exists */
  7217. getWriteConcernError() {
  7218. if (this.result.writeConcernErrors.length === 0) {
  7219. return;
  7220. } else if (this.result.writeConcernErrors.length === 1) {
  7221. return this.result.writeConcernErrors[0];
  7222. } else {
  7223. let errmsg = "";
  7224. for (let i = 0; i < this.result.writeConcernErrors.length; i++) {
  7225. const err = this.result.writeConcernErrors[i];
  7226. errmsg = errmsg + err.errmsg;
  7227. if (i === 0)
  7228. errmsg = errmsg + " and ";
  7229. }
  7230. return new WriteConcernError({ errmsg, code: error_1.MONGODB_ERROR_CODES.WriteConcernFailed });
  7231. }
  7232. }
  7233. toString() {
  7234. return `BulkWriteResult(${this.result})`;
  7235. }
  7236. isOk() {
  7237. return this.result.ok === 1;
  7238. }
  7239. };
  7240. exports2.BulkWriteResult = BulkWriteResult;
  7241. var WriteConcernError = class {
  7242. constructor(error) {
  7243. this[kServerError] = error;
  7244. }
  7245. /** Write concern error code. */
  7246. get code() {
  7247. return this[kServerError].code;
  7248. }
  7249. /** Write concern error message. */
  7250. get errmsg() {
  7251. return this[kServerError].errmsg;
  7252. }
  7253. /** Write concern error info. */
  7254. get errInfo() {
  7255. return this[kServerError].errInfo;
  7256. }
  7257. toJSON() {
  7258. return this[kServerError];
  7259. }
  7260. toString() {
  7261. return `WriteConcernError(${this.errmsg})`;
  7262. }
  7263. };
  7264. exports2.WriteConcernError = WriteConcernError;
  7265. var WriteError = class {
  7266. constructor(err) {
  7267. this.err = err;
  7268. }
  7269. /** WriteError code. */
  7270. get code() {
  7271. return this.err.code;
  7272. }
  7273. /** WriteError original bulk operation index. */
  7274. get index() {
  7275. return this.err.index;
  7276. }
  7277. /** WriteError message. */
  7278. get errmsg() {
  7279. return this.err.errmsg;
  7280. }
  7281. /** WriteError details. */
  7282. get errInfo() {
  7283. return this.err.errInfo;
  7284. }
  7285. /** Returns the underlying operation that caused the error */
  7286. getOperation() {
  7287. return this.err.op;
  7288. }
  7289. toJSON() {
  7290. return { code: this.err.code, index: this.err.index, errmsg: this.err.errmsg, op: this.err.op };
  7291. }
  7292. toString() {
  7293. return `WriteError(${JSON.stringify(this.toJSON())})`;
  7294. }
  7295. };
  7296. exports2.WriteError = WriteError;
  7297. function mergeBatchResults(batch, bulkResult, err, result) {
  7298. if (err) {
  7299. result = err;
  7300. } else if (result && result.result) {
  7301. result = result.result;
  7302. }
  7303. if (result == null) {
  7304. return;
  7305. }
  7306. if (result.ok === 0 && bulkResult.ok === 1) {
  7307. bulkResult.ok = 0;
  7308. const writeError = {
  7309. index: 0,
  7310. code: result.code || 0,
  7311. errmsg: result.message,
  7312. errInfo: result.errInfo,
  7313. op: batch.operations[0]
  7314. };
  7315. bulkResult.writeErrors.push(new WriteError(writeError));
  7316. return;
  7317. } else if (result.ok === 0 && bulkResult.ok === 0) {
  7318. return;
  7319. }
  7320. if (isInsertBatch(batch) && result.n) {
  7321. bulkResult.nInserted = bulkResult.nInserted + result.n;
  7322. }
  7323. if (isDeleteBatch(batch) && result.n) {
  7324. bulkResult.nRemoved = bulkResult.nRemoved + result.n;
  7325. }
  7326. let nUpserted = 0;
  7327. if (Array.isArray(result.upserted)) {
  7328. nUpserted = result.upserted.length;
  7329. for (let i = 0; i < result.upserted.length; i++) {
  7330. bulkResult.upserted.push({
  7331. index: result.upserted[i].index + batch.originalZeroIndex,
  7332. _id: result.upserted[i]._id
  7333. });
  7334. }
  7335. } else if (result.upserted) {
  7336. nUpserted = 1;
  7337. bulkResult.upserted.push({
  7338. index: batch.originalZeroIndex,
  7339. _id: result.upserted
  7340. });
  7341. }
  7342. if (isUpdateBatch(batch) && result.n) {
  7343. const nModified = result.nModified;
  7344. bulkResult.nUpserted = bulkResult.nUpserted + nUpserted;
  7345. bulkResult.nMatched = bulkResult.nMatched + (result.n - nUpserted);
  7346. if (typeof nModified === "number") {
  7347. bulkResult.nModified = bulkResult.nModified + nModified;
  7348. } else {
  7349. bulkResult.nModified = 0;
  7350. }
  7351. }
  7352. if (Array.isArray(result.writeErrors)) {
  7353. for (let i = 0; i < result.writeErrors.length; i++) {
  7354. const writeError = {
  7355. index: batch.originalIndexes[result.writeErrors[i].index],
  7356. code: result.writeErrors[i].code,
  7357. errmsg: result.writeErrors[i].errmsg,
  7358. errInfo: result.writeErrors[i].errInfo,
  7359. op: batch.operations[result.writeErrors[i].index]
  7360. };
  7361. bulkResult.writeErrors.push(new WriteError(writeError));
  7362. }
  7363. }
  7364. if (result.writeConcernError) {
  7365. bulkResult.writeConcernErrors.push(new WriteConcernError(result.writeConcernError));
  7366. }
  7367. }
  7368. exports2.mergeBatchResults = mergeBatchResults;
  7369. function executeCommands(bulkOperation, options, callback) {
  7370. if (bulkOperation.s.batches.length === 0) {
  7371. return callback(void 0, new BulkWriteResult(bulkOperation.s.bulkResult, bulkOperation.isOrdered));
  7372. }
  7373. const batch = bulkOperation.s.batches.shift();
  7374. function resultHandler(err, result) {
  7375. if (err && "message" in err && !(err instanceof error_1.MongoWriteConcernError)) {
  7376. return callback(new MongoBulkWriteError(err, new BulkWriteResult(bulkOperation.s.bulkResult, bulkOperation.isOrdered)));
  7377. }
  7378. if (err instanceof error_1.MongoWriteConcernError) {
  7379. return handleMongoWriteConcernError(batch, bulkOperation.s.bulkResult, bulkOperation.isOrdered, err, callback);
  7380. }
  7381. mergeBatchResults(batch, bulkOperation.s.bulkResult, err, result);
  7382. const writeResult = new BulkWriteResult(bulkOperation.s.bulkResult, bulkOperation.isOrdered);
  7383. if (bulkOperation.handleWriteError(callback, writeResult))
  7384. return;
  7385. executeCommands(bulkOperation, options, callback);
  7386. }
  7387. const finalOptions = (0, utils_1.resolveOptions)(bulkOperation, {
  7388. ...options,
  7389. ordered: bulkOperation.isOrdered
  7390. });
  7391. if (finalOptions.bypassDocumentValidation !== true) {
  7392. delete finalOptions.bypassDocumentValidation;
  7393. }
  7394. if (bulkOperation.operationId) {
  7395. resultHandler.operationId = bulkOperation.operationId;
  7396. }
  7397. if (bulkOperation.s.bypassDocumentValidation === true) {
  7398. finalOptions.bypassDocumentValidation = true;
  7399. }
  7400. if (bulkOperation.s.checkKeys === false) {
  7401. finalOptions.checkKeys = false;
  7402. }
  7403. if (finalOptions.retryWrites) {
  7404. if (isUpdateBatch(batch)) {
  7405. finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some((op) => op.multi);
  7406. }
  7407. if (isDeleteBatch(batch)) {
  7408. finalOptions.retryWrites = finalOptions.retryWrites && !batch.operations.some((op) => op.limit === 0);
  7409. }
  7410. }
  7411. try {
  7412. if (isInsertBatch(batch)) {
  7413. (0, execute_operation_1.executeOperation)(bulkOperation.s.collection.client, new insert_1.InsertOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler);
  7414. } else if (isUpdateBatch(batch)) {
  7415. (0, execute_operation_1.executeOperation)(bulkOperation.s.collection.client, new update_1.UpdateOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler);
  7416. } else if (isDeleteBatch(batch)) {
  7417. (0, execute_operation_1.executeOperation)(bulkOperation.s.collection.client, new delete_1.DeleteOperation(bulkOperation.s.namespace, batch.operations, finalOptions), resultHandler);
  7418. }
  7419. } catch (err) {
  7420. err.ok = 0;
  7421. mergeBatchResults(batch, bulkOperation.s.bulkResult, err, void 0);
  7422. callback();
  7423. }
  7424. }
  7425. function handleMongoWriteConcernError(batch, bulkResult, isOrdered, err, callback) {
  7426. var _a, _b;
  7427. mergeBatchResults(batch, bulkResult, void 0, err.result);
  7428. callback(new MongoBulkWriteError({
  7429. message: (_a = err.result) == null ? void 0 : _a.writeConcernError.errmsg,
  7430. code: (_b = err.result) == null ? void 0 : _b.writeConcernError.result
  7431. }, new BulkWriteResult(bulkResult, isOrdered)));
  7432. }
  7433. var MongoBulkWriteError = class extends error_1.MongoServerError {
  7434. /** Creates a new MongoBulkWriteError */
  7435. constructor(error, result) {
  7436. super(error);
  7437. this.writeErrors = [];
  7438. if (error instanceof WriteConcernError)
  7439. this.err = error;
  7440. else if (!(error instanceof Error)) {
  7441. this.message = error.message;
  7442. this.code = error.code;
  7443. this.writeErrors = error.writeErrors ?? [];
  7444. }
  7445. this.result = result;
  7446. Object.assign(this, error);
  7447. }
  7448. get name() {
  7449. return "MongoBulkWriteError";
  7450. }
  7451. /** Number of documents inserted. */
  7452. get insertedCount() {
  7453. return this.result.insertedCount;
  7454. }
  7455. /** Number of documents matched for update. */
  7456. get matchedCount() {
  7457. return this.result.matchedCount;
  7458. }
  7459. /** Number of documents modified. */
  7460. get modifiedCount() {
  7461. return this.result.modifiedCount;
  7462. }
  7463. /** Number of documents deleted. */
  7464. get deletedCount() {
  7465. return this.result.deletedCount;
  7466. }
  7467. /** Number of documents upserted. */
  7468. get upsertedCount() {
  7469. return this.result.upsertedCount;
  7470. }
  7471. /** Inserted document generated Id's, hash key is the index of the originating operation */
  7472. get insertedIds() {
  7473. return this.result.insertedIds;
  7474. }
  7475. /** Upserted document generated Id's, hash key is the index of the originating operation */
  7476. get upsertedIds() {
  7477. return this.result.upsertedIds;
  7478. }
  7479. };
  7480. exports2.MongoBulkWriteError = MongoBulkWriteError;
  7481. var FindOperators = class {
  7482. /**
  7483. * Creates a new FindOperators object.
  7484. * @internal
  7485. */
  7486. constructor(bulkOperation) {
  7487. this.bulkOperation = bulkOperation;
  7488. }
  7489. /** Add a multiple update operation to the bulk operation */
  7490. update(updateDocument) {
  7491. const currentOp = buildCurrentOp(this.bulkOperation);
  7492. return this.bulkOperation.addToOperationsList(exports2.BatchType.UPDATE, (0, update_1.makeUpdateStatement)(currentOp.selector, updateDocument, {
  7493. ...currentOp,
  7494. multi: true
  7495. }));
  7496. }
  7497. /** Add a single update operation to the bulk operation */
  7498. updateOne(updateDocument) {
  7499. if (!(0, utils_1.hasAtomicOperators)(updateDocument)) {
  7500. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  7501. }
  7502. const currentOp = buildCurrentOp(this.bulkOperation);
  7503. return this.bulkOperation.addToOperationsList(exports2.BatchType.UPDATE, (0, update_1.makeUpdateStatement)(currentOp.selector, updateDocument, { ...currentOp, multi: false }));
  7504. }
  7505. /** Add a replace one operation to the bulk operation */
  7506. replaceOne(replacement) {
  7507. if ((0, utils_1.hasAtomicOperators)(replacement)) {
  7508. throw new error_1.MongoInvalidArgumentError("Replacement document must not use atomic operators");
  7509. }
  7510. const currentOp = buildCurrentOp(this.bulkOperation);
  7511. return this.bulkOperation.addToOperationsList(exports2.BatchType.UPDATE, (0, update_1.makeUpdateStatement)(currentOp.selector, replacement, { ...currentOp, multi: false }));
  7512. }
  7513. /** Add a delete one operation to the bulk operation */
  7514. deleteOne() {
  7515. const currentOp = buildCurrentOp(this.bulkOperation);
  7516. return this.bulkOperation.addToOperationsList(exports2.BatchType.DELETE, (0, delete_1.makeDeleteStatement)(currentOp.selector, { ...currentOp, limit: 1 }));
  7517. }
  7518. /** Add a delete many operation to the bulk operation */
  7519. delete() {
  7520. const currentOp = buildCurrentOp(this.bulkOperation);
  7521. return this.bulkOperation.addToOperationsList(exports2.BatchType.DELETE, (0, delete_1.makeDeleteStatement)(currentOp.selector, { ...currentOp, limit: 0 }));
  7522. }
  7523. /** Upsert modifier for update bulk operation, noting that this operation is an upsert. */
  7524. upsert() {
  7525. if (!this.bulkOperation.s.currentOp) {
  7526. this.bulkOperation.s.currentOp = {};
  7527. }
  7528. this.bulkOperation.s.currentOp.upsert = true;
  7529. return this;
  7530. }
  7531. /** Specifies the collation for the query condition. */
  7532. collation(collation) {
  7533. if (!this.bulkOperation.s.currentOp) {
  7534. this.bulkOperation.s.currentOp = {};
  7535. }
  7536. this.bulkOperation.s.currentOp.collation = collation;
  7537. return this;
  7538. }
  7539. /** Specifies arrayFilters for UpdateOne or UpdateMany bulk operations. */
  7540. arrayFilters(arrayFilters) {
  7541. if (!this.bulkOperation.s.currentOp) {
  7542. this.bulkOperation.s.currentOp = {};
  7543. }
  7544. this.bulkOperation.s.currentOp.arrayFilters = arrayFilters;
  7545. return this;
  7546. }
  7547. /** Specifies hint for the bulk operation. */
  7548. hint(hint) {
  7549. if (!this.bulkOperation.s.currentOp) {
  7550. this.bulkOperation.s.currentOp = {};
  7551. }
  7552. this.bulkOperation.s.currentOp.hint = hint;
  7553. return this;
  7554. }
  7555. };
  7556. exports2.FindOperators = FindOperators;
  7557. var BulkWriteShimOperation = class extends operation_1.AbstractCallbackOperation {
  7558. constructor(bulkOperation, options) {
  7559. super(options);
  7560. this.bulkOperation = bulkOperation;
  7561. }
  7562. executeCallback(server, session, callback) {
  7563. if (this.options.session == null) {
  7564. this.options.session = session;
  7565. }
  7566. return executeCommands(this.bulkOperation, this.options, callback);
  7567. }
  7568. };
  7569. var BulkOperationBase = class {
  7570. /**
  7571. * Create a new OrderedBulkOperation or UnorderedBulkOperation instance
  7572. * @internal
  7573. */
  7574. constructor(collection, options, isOrdered) {
  7575. this.isOrdered = isOrdered;
  7576. const topology = (0, utils_1.getTopology)(collection);
  7577. options = options == null ? {} : options;
  7578. const namespace = collection.s.namespace;
  7579. const executed = false;
  7580. const currentOp = void 0;
  7581. const hello = topology.lastHello();
  7582. const usingAutoEncryption = !!(topology.s.options && topology.s.options.autoEncrypter);
  7583. const maxBsonObjectSize = hello && hello.maxBsonObjectSize ? hello.maxBsonObjectSize : 1024 * 1024 * 16;
  7584. const maxBatchSizeBytes = usingAutoEncryption ? 1024 * 1024 * 2 : maxBsonObjectSize;
  7585. const maxWriteBatchSize = hello && hello.maxWriteBatchSize ? hello.maxWriteBatchSize : 1e3;
  7586. const maxKeySize = (maxWriteBatchSize - 1).toString(10).length + 2;
  7587. let finalOptions = Object.assign({}, options);
  7588. finalOptions = (0, utils_1.applyRetryableWrites)(finalOptions, collection.s.db);
  7589. const bulkResult = {
  7590. ok: 1,
  7591. writeErrors: [],
  7592. writeConcernErrors: [],
  7593. insertedIds: [],
  7594. nInserted: 0,
  7595. nUpserted: 0,
  7596. nMatched: 0,
  7597. nModified: 0,
  7598. nRemoved: 0,
  7599. upserted: []
  7600. };
  7601. this.s = {
  7602. // Final result
  7603. bulkResult,
  7604. // Current batch state
  7605. currentBatch: void 0,
  7606. currentIndex: 0,
  7607. // ordered specific
  7608. currentBatchSize: 0,
  7609. currentBatchSizeBytes: 0,
  7610. // unordered specific
  7611. currentInsertBatch: void 0,
  7612. currentUpdateBatch: void 0,
  7613. currentRemoveBatch: void 0,
  7614. batches: [],
  7615. // Write concern
  7616. writeConcern: write_concern_1.WriteConcern.fromOptions(options),
  7617. // Max batch size options
  7618. maxBsonObjectSize,
  7619. maxBatchSizeBytes,
  7620. maxWriteBatchSize,
  7621. maxKeySize,
  7622. // Namespace
  7623. namespace,
  7624. // Topology
  7625. topology,
  7626. // Options
  7627. options: finalOptions,
  7628. // BSON options
  7629. bsonOptions: (0, bson_1.resolveBSONOptions)(options),
  7630. // Current operation
  7631. currentOp,
  7632. // Executed
  7633. executed,
  7634. // Collection
  7635. collection,
  7636. // Fundamental error
  7637. err: void 0,
  7638. // check keys
  7639. checkKeys: typeof options.checkKeys === "boolean" ? options.checkKeys : false
  7640. };
  7641. if (options.bypassDocumentValidation === true) {
  7642. this.s.bypassDocumentValidation = true;
  7643. }
  7644. }
  7645. /**
  7646. * Add a single insert document to the bulk operation
  7647. *
  7648. * @example
  7649. * ```ts
  7650. * const bulkOp = collection.initializeOrderedBulkOp();
  7651. *
  7652. * // Adds three inserts to the bulkOp.
  7653. * bulkOp
  7654. * .insert({ a: 1 })
  7655. * .insert({ b: 2 })
  7656. * .insert({ c: 3 });
  7657. * await bulkOp.execute();
  7658. * ```
  7659. */
  7660. insert(document) {
  7661. if (document._id == null && !shouldForceServerObjectId(this)) {
  7662. document._id = new bson_1.ObjectId();
  7663. }
  7664. return this.addToOperationsList(exports2.BatchType.INSERT, document);
  7665. }
  7666. /**
  7667. * Builds a find operation for an update/updateOne/delete/deleteOne/replaceOne.
  7668. * Returns a builder object used to complete the definition of the operation.
  7669. *
  7670. * @example
  7671. * ```ts
  7672. * const bulkOp = collection.initializeOrderedBulkOp();
  7673. *
  7674. * // Add an updateOne to the bulkOp
  7675. * bulkOp.find({ a: 1 }).updateOne({ $set: { b: 2 } });
  7676. *
  7677. * // Add an updateMany to the bulkOp
  7678. * bulkOp.find({ c: 3 }).update({ $set: { d: 4 } });
  7679. *
  7680. * // Add an upsert
  7681. * bulkOp.find({ e: 5 }).upsert().updateOne({ $set: { f: 6 } });
  7682. *
  7683. * // Add a deletion
  7684. * bulkOp.find({ g: 7 }).deleteOne();
  7685. *
  7686. * // Add a multi deletion
  7687. * bulkOp.find({ h: 8 }).delete();
  7688. *
  7689. * // Add a replaceOne
  7690. * bulkOp.find({ i: 9 }).replaceOne({writeConcern: { j: 10 }});
  7691. *
  7692. * // Update using a pipeline (requires Mongodb 4.2 or higher)
  7693. * bulk.find({ k: 11, y: { $exists: true }, z: { $exists: true } }).updateOne([
  7694. * { $set: { total: { $sum: [ '$y', '$z' ] } } }
  7695. * ]);
  7696. *
  7697. * // All of the ops will now be executed
  7698. * await bulkOp.execute();
  7699. * ```
  7700. */
  7701. find(selector) {
  7702. if (!selector) {
  7703. throw new error_1.MongoInvalidArgumentError("Bulk find operation must specify a selector");
  7704. }
  7705. this.s.currentOp = {
  7706. selector
  7707. };
  7708. return new FindOperators(this);
  7709. }
  7710. /** Specifies a raw operation to perform in the bulk write. */
  7711. raw(op) {
  7712. if (op == null || typeof op !== "object") {
  7713. throw new error_1.MongoInvalidArgumentError("Operation must be an object with an operation key");
  7714. }
  7715. if ("insertOne" in op) {
  7716. const forceServerObjectId = shouldForceServerObjectId(this);
  7717. if (op.insertOne && op.insertOne.document == null) {
  7718. if (forceServerObjectId !== true && op.insertOne._id == null) {
  7719. op.insertOne._id = new bson_1.ObjectId();
  7720. }
  7721. return this.addToOperationsList(exports2.BatchType.INSERT, op.insertOne);
  7722. }
  7723. if (forceServerObjectId !== true && op.insertOne.document._id == null) {
  7724. op.insertOne.document._id = new bson_1.ObjectId();
  7725. }
  7726. return this.addToOperationsList(exports2.BatchType.INSERT, op.insertOne.document);
  7727. }
  7728. if ("replaceOne" in op || "updateOne" in op || "updateMany" in op) {
  7729. if ("replaceOne" in op) {
  7730. if ("q" in op.replaceOne) {
  7731. throw new error_1.MongoInvalidArgumentError("Raw operations are not allowed");
  7732. }
  7733. const updateStatement = (0, update_1.makeUpdateStatement)(op.replaceOne.filter, op.replaceOne.replacement, { ...op.replaceOne, multi: false });
  7734. if ((0, utils_1.hasAtomicOperators)(updateStatement.u)) {
  7735. throw new error_1.MongoInvalidArgumentError("Replacement document must not use atomic operators");
  7736. }
  7737. return this.addToOperationsList(exports2.BatchType.UPDATE, updateStatement);
  7738. }
  7739. if ("updateOne" in op) {
  7740. if ("q" in op.updateOne) {
  7741. throw new error_1.MongoInvalidArgumentError("Raw operations are not allowed");
  7742. }
  7743. const updateStatement = (0, update_1.makeUpdateStatement)(op.updateOne.filter, op.updateOne.update, {
  7744. ...op.updateOne,
  7745. multi: false
  7746. });
  7747. if (!(0, utils_1.hasAtomicOperators)(updateStatement.u)) {
  7748. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  7749. }
  7750. return this.addToOperationsList(exports2.BatchType.UPDATE, updateStatement);
  7751. }
  7752. if ("updateMany" in op) {
  7753. if ("q" in op.updateMany) {
  7754. throw new error_1.MongoInvalidArgumentError("Raw operations are not allowed");
  7755. }
  7756. const updateStatement = (0, update_1.makeUpdateStatement)(op.updateMany.filter, op.updateMany.update, {
  7757. ...op.updateMany,
  7758. multi: true
  7759. });
  7760. if (!(0, utils_1.hasAtomicOperators)(updateStatement.u)) {
  7761. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  7762. }
  7763. return this.addToOperationsList(exports2.BatchType.UPDATE, updateStatement);
  7764. }
  7765. }
  7766. if ("deleteOne" in op) {
  7767. if ("q" in op.deleteOne) {
  7768. throw new error_1.MongoInvalidArgumentError("Raw operations are not allowed");
  7769. }
  7770. return this.addToOperationsList(exports2.BatchType.DELETE, (0, delete_1.makeDeleteStatement)(op.deleteOne.filter, { ...op.deleteOne, limit: 1 }));
  7771. }
  7772. if ("deleteMany" in op) {
  7773. if ("q" in op.deleteMany) {
  7774. throw new error_1.MongoInvalidArgumentError("Raw operations are not allowed");
  7775. }
  7776. return this.addToOperationsList(exports2.BatchType.DELETE, (0, delete_1.makeDeleteStatement)(op.deleteMany.filter, { ...op.deleteMany, limit: 0 }));
  7777. }
  7778. throw new error_1.MongoInvalidArgumentError("bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany");
  7779. }
  7780. get bsonOptions() {
  7781. return this.s.bsonOptions;
  7782. }
  7783. get writeConcern() {
  7784. return this.s.writeConcern;
  7785. }
  7786. get batches() {
  7787. const batches = [...this.s.batches];
  7788. if (this.isOrdered) {
  7789. if (this.s.currentBatch)
  7790. batches.push(this.s.currentBatch);
  7791. } else {
  7792. if (this.s.currentInsertBatch)
  7793. batches.push(this.s.currentInsertBatch);
  7794. if (this.s.currentUpdateBatch)
  7795. batches.push(this.s.currentUpdateBatch);
  7796. if (this.s.currentRemoveBatch)
  7797. batches.push(this.s.currentRemoveBatch);
  7798. }
  7799. return batches;
  7800. }
  7801. async execute(options = {}) {
  7802. if (this.s.executed) {
  7803. throw new error_1.MongoBatchReExecutionError();
  7804. }
  7805. const writeConcern = write_concern_1.WriteConcern.fromOptions(options);
  7806. if (writeConcern) {
  7807. this.s.writeConcern = writeConcern;
  7808. }
  7809. if (this.isOrdered) {
  7810. if (this.s.currentBatch)
  7811. this.s.batches.push(this.s.currentBatch);
  7812. } else {
  7813. if (this.s.currentInsertBatch)
  7814. this.s.batches.push(this.s.currentInsertBatch);
  7815. if (this.s.currentUpdateBatch)
  7816. this.s.batches.push(this.s.currentUpdateBatch);
  7817. if (this.s.currentRemoveBatch)
  7818. this.s.batches.push(this.s.currentRemoveBatch);
  7819. }
  7820. if (this.s.batches.length === 0) {
  7821. throw new error_1.MongoInvalidArgumentError("Invalid BulkOperation, Batch cannot be empty");
  7822. }
  7823. this.s.executed = true;
  7824. const finalOptions = { ...this.s.options, ...options };
  7825. const operation = new BulkWriteShimOperation(this, finalOptions);
  7826. return (0, execute_operation_1.executeOperation)(this.s.collection.client, operation);
  7827. }
  7828. /**
  7829. * Handles the write error before executing commands
  7830. * @internal
  7831. */
  7832. handleWriteError(callback, writeResult) {
  7833. if (this.s.bulkResult.writeErrors.length > 0) {
  7834. const msg = this.s.bulkResult.writeErrors[0].errmsg ? this.s.bulkResult.writeErrors[0].errmsg : "write operation failed";
  7835. callback(new MongoBulkWriteError({
  7836. message: msg,
  7837. code: this.s.bulkResult.writeErrors[0].code,
  7838. writeErrors: this.s.bulkResult.writeErrors
  7839. }, writeResult));
  7840. return true;
  7841. }
  7842. const writeConcernError = writeResult.getWriteConcernError();
  7843. if (writeConcernError) {
  7844. callback(new MongoBulkWriteError(writeConcernError, writeResult));
  7845. return true;
  7846. }
  7847. return false;
  7848. }
  7849. };
  7850. exports2.BulkOperationBase = BulkOperationBase;
  7851. Object.defineProperty(BulkOperationBase.prototype, "length", {
  7852. enumerable: true,
  7853. get() {
  7854. return this.s.currentIndex;
  7855. }
  7856. });
  7857. function shouldForceServerObjectId(bulkOperation) {
  7858. var _a, _b;
  7859. if (typeof bulkOperation.s.options.forceServerObjectId === "boolean") {
  7860. return bulkOperation.s.options.forceServerObjectId;
  7861. }
  7862. if (typeof ((_a = bulkOperation.s.collection.s.db.options) == null ? void 0 : _a.forceServerObjectId) === "boolean") {
  7863. return (_b = bulkOperation.s.collection.s.db.options) == null ? void 0 : _b.forceServerObjectId;
  7864. }
  7865. return false;
  7866. }
  7867. function isInsertBatch(batch) {
  7868. return batch.batchType === exports2.BatchType.INSERT;
  7869. }
  7870. function isUpdateBatch(batch) {
  7871. return batch.batchType === exports2.BatchType.UPDATE;
  7872. }
  7873. function isDeleteBatch(batch) {
  7874. return batch.batchType === exports2.BatchType.DELETE;
  7875. }
  7876. function buildCurrentOp(bulkOp) {
  7877. let { currentOp } = bulkOp.s;
  7878. bulkOp.s.currentOp = void 0;
  7879. if (!currentOp)
  7880. currentOp = {};
  7881. return currentOp;
  7882. }
  7883. }
  7884. });
  7885. // node_modules/mongodb/lib/bulk/ordered.js
  7886. var require_ordered = __commonJS({
  7887. "node_modules/mongodb/lib/bulk/ordered.js"(exports2) {
  7888. "use strict";
  7889. Object.defineProperty(exports2, "__esModule", { value: true });
  7890. exports2.OrderedBulkOperation = void 0;
  7891. var BSON = require_bson2();
  7892. var error_1 = require_error();
  7893. var common_1 = require_common2();
  7894. var OrderedBulkOperation = class extends common_1.BulkOperationBase {
  7895. /** @internal */
  7896. constructor(collection, options) {
  7897. super(collection, options, true);
  7898. }
  7899. addToOperationsList(batchType, document) {
  7900. const bsonSize = BSON.calculateObjectSize(document, {
  7901. checkKeys: false,
  7902. // Since we don't know what the user selected for BSON options here,
  7903. // err on the safe side, and check the size with ignoreUndefined: false.
  7904. ignoreUndefined: false
  7905. });
  7906. if (bsonSize >= this.s.maxBsonObjectSize)
  7907. throw new error_1.MongoInvalidArgumentError(`Document is larger than the maximum size ${this.s.maxBsonObjectSize}`);
  7908. if (this.s.currentBatch == null) {
  7909. this.s.currentBatch = new common_1.Batch(batchType, this.s.currentIndex);
  7910. }
  7911. const maxKeySize = this.s.maxKeySize;
  7912. if (
  7913. // New batch if we exceed the max batch op size
  7914. this.s.currentBatchSize + 1 >= this.s.maxWriteBatchSize || // New batch if we exceed the maxBatchSizeBytes. Only matters if batch already has a doc,
  7915. // since we can't sent an empty batch
  7916. this.s.currentBatchSize > 0 && this.s.currentBatchSizeBytes + maxKeySize + bsonSize >= this.s.maxBatchSizeBytes || // New batch if the new op does not have the same op type as the current batch
  7917. this.s.currentBatch.batchType !== batchType
  7918. ) {
  7919. this.s.batches.push(this.s.currentBatch);
  7920. this.s.currentBatch = new common_1.Batch(batchType, this.s.currentIndex);
  7921. this.s.currentBatchSize = 0;
  7922. this.s.currentBatchSizeBytes = 0;
  7923. }
  7924. if (batchType === common_1.BatchType.INSERT) {
  7925. this.s.bulkResult.insertedIds.push({
  7926. index: this.s.currentIndex,
  7927. _id: document._id
  7928. });
  7929. }
  7930. if (Array.isArray(document)) {
  7931. throw new error_1.MongoInvalidArgumentError("Operation passed in cannot be an Array");
  7932. }
  7933. this.s.currentBatch.originalIndexes.push(this.s.currentIndex);
  7934. this.s.currentBatch.operations.push(document);
  7935. this.s.currentBatchSize += 1;
  7936. this.s.currentBatchSizeBytes += maxKeySize + bsonSize;
  7937. this.s.currentIndex += 1;
  7938. return this;
  7939. }
  7940. };
  7941. exports2.OrderedBulkOperation = OrderedBulkOperation;
  7942. }
  7943. });
  7944. // node_modules/mongodb/lib/bulk/unordered.js
  7945. var require_unordered = __commonJS({
  7946. "node_modules/mongodb/lib/bulk/unordered.js"(exports2) {
  7947. "use strict";
  7948. Object.defineProperty(exports2, "__esModule", { value: true });
  7949. exports2.UnorderedBulkOperation = void 0;
  7950. var BSON = require_bson2();
  7951. var error_1 = require_error();
  7952. var common_1 = require_common2();
  7953. var UnorderedBulkOperation = class extends common_1.BulkOperationBase {
  7954. /** @internal */
  7955. constructor(collection, options) {
  7956. super(collection, options, false);
  7957. }
  7958. handleWriteError(callback, writeResult) {
  7959. if (this.s.batches.length) {
  7960. return false;
  7961. }
  7962. return super.handleWriteError(callback, writeResult);
  7963. }
  7964. addToOperationsList(batchType, document) {
  7965. const bsonSize = BSON.calculateObjectSize(document, {
  7966. checkKeys: false,
  7967. // Since we don't know what the user selected for BSON options here,
  7968. // err on the safe side, and check the size with ignoreUndefined: false.
  7969. ignoreUndefined: false
  7970. });
  7971. if (bsonSize >= this.s.maxBsonObjectSize) {
  7972. throw new error_1.MongoInvalidArgumentError(`Document is larger than the maximum size ${this.s.maxBsonObjectSize}`);
  7973. }
  7974. this.s.currentBatch = void 0;
  7975. if (batchType === common_1.BatchType.INSERT) {
  7976. this.s.currentBatch = this.s.currentInsertBatch;
  7977. } else if (batchType === common_1.BatchType.UPDATE) {
  7978. this.s.currentBatch = this.s.currentUpdateBatch;
  7979. } else if (batchType === common_1.BatchType.DELETE) {
  7980. this.s.currentBatch = this.s.currentRemoveBatch;
  7981. }
  7982. const maxKeySize = this.s.maxKeySize;
  7983. if (this.s.currentBatch == null) {
  7984. this.s.currentBatch = new common_1.Batch(batchType, this.s.currentIndex);
  7985. }
  7986. if (
  7987. // New batch if we exceed the max batch op size
  7988. this.s.currentBatch.size + 1 >= this.s.maxWriteBatchSize || // New batch if we exceed the maxBatchSizeBytes. Only matters if batch already has a doc,
  7989. // since we can't sent an empty batch
  7990. this.s.currentBatch.size > 0 && this.s.currentBatch.sizeBytes + maxKeySize + bsonSize >= this.s.maxBatchSizeBytes || // New batch if the new op does not have the same op type as the current batch
  7991. this.s.currentBatch.batchType !== batchType
  7992. ) {
  7993. this.s.batches.push(this.s.currentBatch);
  7994. this.s.currentBatch = new common_1.Batch(batchType, this.s.currentIndex);
  7995. }
  7996. if (Array.isArray(document)) {
  7997. throw new error_1.MongoInvalidArgumentError("Operation passed in cannot be an Array");
  7998. }
  7999. this.s.currentBatch.operations.push(document);
  8000. this.s.currentBatch.originalIndexes.push(this.s.currentIndex);
  8001. this.s.currentIndex = this.s.currentIndex + 1;
  8002. if (batchType === common_1.BatchType.INSERT) {
  8003. this.s.currentInsertBatch = this.s.currentBatch;
  8004. this.s.bulkResult.insertedIds.push({
  8005. index: this.s.bulkResult.insertedIds.length,
  8006. _id: document._id
  8007. });
  8008. } else if (batchType === common_1.BatchType.UPDATE) {
  8009. this.s.currentUpdateBatch = this.s.currentBatch;
  8010. } else if (batchType === common_1.BatchType.DELETE) {
  8011. this.s.currentRemoveBatch = this.s.currentBatch;
  8012. }
  8013. this.s.currentBatch.size += 1;
  8014. this.s.currentBatch.sizeBytes += maxKeySize + bsonSize;
  8015. return this;
  8016. }
  8017. };
  8018. exports2.UnorderedBulkOperation = UnorderedBulkOperation;
  8019. }
  8020. });
  8021. // node_modules/mongodb/lib/operations/aggregate.js
  8022. var require_aggregate = __commonJS({
  8023. "node_modules/mongodb/lib/operations/aggregate.js"(exports2) {
  8024. "use strict";
  8025. Object.defineProperty(exports2, "__esModule", { value: true });
  8026. exports2.AggregateOperation = exports2.DB_AGGREGATE_COLLECTION = void 0;
  8027. var error_1 = require_error();
  8028. var utils_1 = require_utils();
  8029. var write_concern_1 = require_write_concern();
  8030. var command_1 = require_command();
  8031. var operation_1 = require_operation();
  8032. exports2.DB_AGGREGATE_COLLECTION = 1;
  8033. var MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
  8034. var AggregateOperation = class extends command_1.CommandCallbackOperation {
  8035. constructor(ns, pipeline, options) {
  8036. super(void 0, { ...options, dbName: ns.db });
  8037. this.options = { ...options };
  8038. this.target = ns.collection || exports2.DB_AGGREGATE_COLLECTION;
  8039. this.pipeline = pipeline;
  8040. this.hasWriteStage = false;
  8041. if (typeof (options == null ? void 0 : options.out) === "string") {
  8042. this.pipeline = this.pipeline.concat({ $out: options.out });
  8043. this.hasWriteStage = true;
  8044. } else if (pipeline.length > 0) {
  8045. const finalStage = pipeline[pipeline.length - 1];
  8046. if (finalStage.$out || finalStage.$merge) {
  8047. this.hasWriteStage = true;
  8048. }
  8049. }
  8050. if (this.hasWriteStage) {
  8051. this.trySecondaryWrite = true;
  8052. } else {
  8053. delete this.options.writeConcern;
  8054. }
  8055. if (this.explain && this.writeConcern) {
  8056. throw new error_1.MongoInvalidArgumentError('Option "explain" cannot be used on an aggregate call with writeConcern');
  8057. }
  8058. if ((options == null ? void 0 : options.cursor) != null && typeof options.cursor !== "object") {
  8059. throw new error_1.MongoInvalidArgumentError("Cursor options must be an object");
  8060. }
  8061. }
  8062. get canRetryRead() {
  8063. return !this.hasWriteStage;
  8064. }
  8065. addToPipeline(stage) {
  8066. this.pipeline.push(stage);
  8067. }
  8068. executeCallback(server, session, callback) {
  8069. const options = this.options;
  8070. const serverWireVersion = (0, utils_1.maxWireVersion)(server);
  8071. const command = { aggregate: this.target, pipeline: this.pipeline };
  8072. if (this.hasWriteStage && serverWireVersion < MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) {
  8073. this.readConcern = void 0;
  8074. }
  8075. if (this.hasWriteStage && this.writeConcern) {
  8076. write_concern_1.WriteConcern.apply(command, this.writeConcern);
  8077. }
  8078. if (options.bypassDocumentValidation === true) {
  8079. command.bypassDocumentValidation = options.bypassDocumentValidation;
  8080. }
  8081. if (typeof options.allowDiskUse === "boolean") {
  8082. command.allowDiskUse = options.allowDiskUse;
  8083. }
  8084. if (options.hint) {
  8085. command.hint = options.hint;
  8086. }
  8087. if (options.let) {
  8088. command.let = options.let;
  8089. }
  8090. if (options.comment !== void 0) {
  8091. command.comment = options.comment;
  8092. }
  8093. command.cursor = options.cursor || {};
  8094. if (options.batchSize && !this.hasWriteStage) {
  8095. command.cursor.batchSize = options.batchSize;
  8096. }
  8097. super.executeCommandCallback(server, session, command, callback);
  8098. }
  8099. };
  8100. exports2.AggregateOperation = AggregateOperation;
  8101. (0, operation_1.defineAspects)(AggregateOperation, [
  8102. operation_1.Aspect.READ_OPERATION,
  8103. operation_1.Aspect.RETRYABLE,
  8104. operation_1.Aspect.EXPLAINABLE,
  8105. operation_1.Aspect.CURSOR_CREATING
  8106. ]);
  8107. }
  8108. });
  8109. // node_modules/mongodb/lib/mongo_types.js
  8110. var require_mongo_types = __commonJS({
  8111. "node_modules/mongodb/lib/mongo_types.js"(exports2) {
  8112. "use strict";
  8113. Object.defineProperty(exports2, "__esModule", { value: true });
  8114. exports2.CancellationToken = exports2.TypedEventEmitter = void 0;
  8115. var events_1 = require("events");
  8116. var TypedEventEmitter = class extends events_1.EventEmitter {
  8117. /** @internal */
  8118. emitAndLog(event, ...args) {
  8119. var _a;
  8120. this.emit(event, ...args);
  8121. if (this.component)
  8122. (_a = this.mongoLogger) == null ? void 0 : _a.debug(this.component, args[0]);
  8123. }
  8124. };
  8125. exports2.TypedEventEmitter = TypedEventEmitter;
  8126. var CancellationToken = class extends TypedEventEmitter {
  8127. };
  8128. exports2.CancellationToken = CancellationToken;
  8129. }
  8130. });
  8131. // node_modules/mongodb/lib/operations/get_more.js
  8132. var require_get_more = __commonJS({
  8133. "node_modules/mongodb/lib/operations/get_more.js"(exports2) {
  8134. "use strict";
  8135. Object.defineProperty(exports2, "__esModule", { value: true });
  8136. exports2.GetMoreOperation = void 0;
  8137. var error_1 = require_error();
  8138. var utils_1 = require_utils();
  8139. var operation_1 = require_operation();
  8140. var GetMoreOperation = class extends operation_1.AbstractCallbackOperation {
  8141. constructor(ns, cursorId, server, options) {
  8142. super(options);
  8143. this.options = options;
  8144. this.ns = ns;
  8145. this.cursorId = cursorId;
  8146. this.server = server;
  8147. }
  8148. /**
  8149. * Although there is a server already associated with the get more operation, the signature
  8150. * for execute passes a server so we will just use that one.
  8151. */
  8152. executeCallback(server, session, callback) {
  8153. if (server !== this.server) {
  8154. return callback(new error_1.MongoRuntimeError("Getmore must run on the same server operation began on"));
  8155. }
  8156. if (this.cursorId == null || this.cursorId.isZero()) {
  8157. return callback(new error_1.MongoRuntimeError("Unable to iterate cursor with no id"));
  8158. }
  8159. const collection = this.ns.collection;
  8160. if (collection == null) {
  8161. return callback(new error_1.MongoRuntimeError("A collection name must be determined before getMore"));
  8162. }
  8163. const getMoreCmd = {
  8164. getMore: this.cursorId,
  8165. collection
  8166. };
  8167. if (typeof this.options.batchSize === "number") {
  8168. getMoreCmd.batchSize = Math.abs(this.options.batchSize);
  8169. }
  8170. if (typeof this.options.maxAwaitTimeMS === "number") {
  8171. getMoreCmd.maxTimeMS = this.options.maxAwaitTimeMS;
  8172. }
  8173. if (this.options.comment !== void 0 && (0, utils_1.maxWireVersion)(server) >= 9) {
  8174. getMoreCmd.comment = this.options.comment;
  8175. }
  8176. const commandOptions = {
  8177. returnFieldSelector: null,
  8178. documentsReturnedIn: "nextBatch",
  8179. ...this.options
  8180. };
  8181. server.command(this.ns, getMoreCmd, commandOptions, callback);
  8182. }
  8183. };
  8184. exports2.GetMoreOperation = GetMoreOperation;
  8185. (0, operation_1.defineAspects)(GetMoreOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.MUST_SELECT_SAME_SERVER]);
  8186. }
  8187. });
  8188. // node_modules/mongodb/lib/operations/kill_cursors.js
  8189. var require_kill_cursors = __commonJS({
  8190. "node_modules/mongodb/lib/operations/kill_cursors.js"(exports2) {
  8191. "use strict";
  8192. Object.defineProperty(exports2, "__esModule", { value: true });
  8193. exports2.KillCursorsOperation = void 0;
  8194. var error_1 = require_error();
  8195. var operation_1 = require_operation();
  8196. var KillCursorsOperation = class extends operation_1.AbstractCallbackOperation {
  8197. constructor(cursorId, ns, server, options) {
  8198. super(options);
  8199. this.ns = ns;
  8200. this.cursorId = cursorId;
  8201. this.server = server;
  8202. }
  8203. executeCallback(server, session, callback) {
  8204. if (server !== this.server) {
  8205. return callback(new error_1.MongoRuntimeError("Killcursor must run on the same server operation began on"));
  8206. }
  8207. const killCursors = this.ns.collection;
  8208. if (killCursors == null) {
  8209. return callback(new error_1.MongoRuntimeError("A collection name must be determined before killCursors"));
  8210. }
  8211. const killCursorsCommand = {
  8212. killCursors,
  8213. cursors: [this.cursorId]
  8214. };
  8215. server.command(this.ns, killCursorsCommand, { session }, () => callback());
  8216. }
  8217. };
  8218. exports2.KillCursorsOperation = KillCursorsOperation;
  8219. (0, operation_1.defineAspects)(KillCursorsOperation, [operation_1.Aspect.MUST_SELECT_SAME_SERVER]);
  8220. }
  8221. });
  8222. // node_modules/mongodb/lib/cmap/metrics.js
  8223. var require_metrics = __commonJS({
  8224. "node_modules/mongodb/lib/cmap/metrics.js"(exports2) {
  8225. "use strict";
  8226. Object.defineProperty(exports2, "__esModule", { value: true });
  8227. exports2.ConnectionPoolMetrics = void 0;
  8228. var ConnectionPoolMetrics = class _ConnectionPoolMetrics {
  8229. constructor() {
  8230. this.txnConnections = 0;
  8231. this.cursorConnections = 0;
  8232. this.otherConnections = 0;
  8233. }
  8234. /**
  8235. * Mark a connection as pinned for a specific operation.
  8236. */
  8237. markPinned(pinType) {
  8238. if (pinType === _ConnectionPoolMetrics.TXN) {
  8239. this.txnConnections += 1;
  8240. } else if (pinType === _ConnectionPoolMetrics.CURSOR) {
  8241. this.cursorConnections += 1;
  8242. } else {
  8243. this.otherConnections += 1;
  8244. }
  8245. }
  8246. /**
  8247. * Unmark a connection as pinned for an operation.
  8248. */
  8249. markUnpinned(pinType) {
  8250. if (pinType === _ConnectionPoolMetrics.TXN) {
  8251. this.txnConnections -= 1;
  8252. } else if (pinType === _ConnectionPoolMetrics.CURSOR) {
  8253. this.cursorConnections -= 1;
  8254. } else {
  8255. this.otherConnections -= 1;
  8256. }
  8257. }
  8258. /**
  8259. * Return information about the cmap metrics as a string.
  8260. */
  8261. info(maxPoolSize) {
  8262. return `Timed out while checking out a connection from connection pool: maxPoolSize: ${maxPoolSize}, connections in use by cursors: ${this.cursorConnections}, connections in use by transactions: ${this.txnConnections}, connections in use by other operations: ${this.otherConnections}`;
  8263. }
  8264. /**
  8265. * Reset the metrics to the initial values.
  8266. */
  8267. reset() {
  8268. this.txnConnections = 0;
  8269. this.cursorConnections = 0;
  8270. this.otherConnections = 0;
  8271. }
  8272. };
  8273. ConnectionPoolMetrics.TXN = "txn";
  8274. ConnectionPoolMetrics.CURSOR = "cursor";
  8275. ConnectionPoolMetrics.OTHER = "other";
  8276. exports2.ConnectionPoolMetrics = ConnectionPoolMetrics;
  8277. }
  8278. });
  8279. // node_modules/mongodb/lib/sdam/server_description.js
  8280. var require_server_description = __commonJS({
  8281. "node_modules/mongodb/lib/sdam/server_description.js"(exports2) {
  8282. "use strict";
  8283. Object.defineProperty(exports2, "__esModule", { value: true });
  8284. exports2.compareTopologyVersion = exports2.parseServerType = exports2.ServerDescription = void 0;
  8285. var bson_1 = require_bson2();
  8286. var error_1 = require_error();
  8287. var utils_1 = require_utils();
  8288. var common_1 = require_common();
  8289. var WRITABLE_SERVER_TYPES = /* @__PURE__ */ new Set([
  8290. common_1.ServerType.RSPrimary,
  8291. common_1.ServerType.Standalone,
  8292. common_1.ServerType.Mongos,
  8293. common_1.ServerType.LoadBalancer
  8294. ]);
  8295. var DATA_BEARING_SERVER_TYPES = /* @__PURE__ */ new Set([
  8296. common_1.ServerType.RSPrimary,
  8297. common_1.ServerType.RSSecondary,
  8298. common_1.ServerType.Mongos,
  8299. common_1.ServerType.Standalone,
  8300. common_1.ServerType.LoadBalancer
  8301. ]);
  8302. var ServerDescription = class {
  8303. /**
  8304. * Create a ServerDescription
  8305. * @internal
  8306. *
  8307. * @param address - The address of the server
  8308. * @param hello - An optional hello response for this server
  8309. */
  8310. constructor(address, hello, options = {}) {
  8311. var _a, _b, _c, _d, _e, _f;
  8312. if (address == null || address === "") {
  8313. throw new error_1.MongoRuntimeError("ServerDescription must be provided with a non-empty address");
  8314. }
  8315. this.address = typeof address === "string" ? utils_1.HostAddress.fromString(address).toString() : address.toString();
  8316. this.type = parseServerType(hello, options);
  8317. this.hosts = ((_a = hello == null ? void 0 : hello.hosts) == null ? void 0 : _a.map((host) => host.toLowerCase())) ?? [];
  8318. this.passives = ((_b = hello == null ? void 0 : hello.passives) == null ? void 0 : _b.map((host) => host.toLowerCase())) ?? [];
  8319. this.arbiters = ((_c = hello == null ? void 0 : hello.arbiters) == null ? void 0 : _c.map((host) => host.toLowerCase())) ?? [];
  8320. this.tags = (hello == null ? void 0 : hello.tags) ?? {};
  8321. this.minWireVersion = (hello == null ? void 0 : hello.minWireVersion) ?? 0;
  8322. this.maxWireVersion = (hello == null ? void 0 : hello.maxWireVersion) ?? 0;
  8323. this.roundTripTime = (options == null ? void 0 : options.roundTripTime) ?? -1;
  8324. this.lastUpdateTime = (0, utils_1.now)();
  8325. this.lastWriteDate = ((_d = hello == null ? void 0 : hello.lastWrite) == null ? void 0 : _d.lastWriteDate) ?? 0;
  8326. this.error = options.error ?? null;
  8327. this.topologyVersion = ((_e = this.error) == null ? void 0 : _e.topologyVersion) ?? (hello == null ? void 0 : hello.topologyVersion) ?? null;
  8328. this.setName = (hello == null ? void 0 : hello.setName) ?? null;
  8329. this.setVersion = (hello == null ? void 0 : hello.setVersion) ?? null;
  8330. this.electionId = (hello == null ? void 0 : hello.electionId) ?? null;
  8331. this.logicalSessionTimeoutMinutes = (hello == null ? void 0 : hello.logicalSessionTimeoutMinutes) ?? null;
  8332. this.primary = (hello == null ? void 0 : hello.primary) ?? null;
  8333. this.me = ((_f = hello == null ? void 0 : hello.me) == null ? void 0 : _f.toLowerCase()) ?? null;
  8334. this.$clusterTime = (hello == null ? void 0 : hello.$clusterTime) ?? null;
  8335. }
  8336. get hostAddress() {
  8337. return utils_1.HostAddress.fromString(this.address);
  8338. }
  8339. get allHosts() {
  8340. return this.hosts.concat(this.arbiters).concat(this.passives);
  8341. }
  8342. /** Is this server available for reads*/
  8343. get isReadable() {
  8344. return this.type === common_1.ServerType.RSSecondary || this.isWritable;
  8345. }
  8346. /** Is this server data bearing */
  8347. get isDataBearing() {
  8348. return DATA_BEARING_SERVER_TYPES.has(this.type);
  8349. }
  8350. /** Is this server available for writes */
  8351. get isWritable() {
  8352. return WRITABLE_SERVER_TYPES.has(this.type);
  8353. }
  8354. get host() {
  8355. const chopLength = `:${this.port}`.length;
  8356. return this.address.slice(0, -chopLength);
  8357. }
  8358. get port() {
  8359. const port = this.address.split(":").pop();
  8360. return port ? Number.parseInt(port, 10) : 27017;
  8361. }
  8362. /**
  8363. * Determines if another `ServerDescription` is equal to this one per the rules defined
  8364. * in the {@link https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#serverdescription|SDAM spec}
  8365. */
  8366. equals(other) {
  8367. const topologyVersionsEqual = this.topologyVersion === (other == null ? void 0 : other.topologyVersion) || compareTopologyVersion(this.topologyVersion, other == null ? void 0 : other.topologyVersion) === 0;
  8368. const electionIdsEqual = this.electionId != null && (other == null ? void 0 : other.electionId) != null ? (0, utils_1.compareObjectId)(this.electionId, other.electionId) === 0 : this.electionId === (other == null ? void 0 : other.electionId);
  8369. return other != null && (0, utils_1.errorStrictEqual)(this.error, other.error) && this.type === other.type && this.minWireVersion === other.minWireVersion && (0, utils_1.arrayStrictEqual)(this.hosts, other.hosts) && tagsStrictEqual(this.tags, other.tags) && this.setName === other.setName && this.setVersion === other.setVersion && electionIdsEqual && this.primary === other.primary && this.logicalSessionTimeoutMinutes === other.logicalSessionTimeoutMinutes && topologyVersionsEqual;
  8370. }
  8371. };
  8372. exports2.ServerDescription = ServerDescription;
  8373. function parseServerType(hello, options) {
  8374. if (options == null ? void 0 : options.loadBalanced) {
  8375. return common_1.ServerType.LoadBalancer;
  8376. }
  8377. if (!hello || !hello.ok) {
  8378. return common_1.ServerType.Unknown;
  8379. }
  8380. if (hello.isreplicaset) {
  8381. return common_1.ServerType.RSGhost;
  8382. }
  8383. if (hello.msg && hello.msg === "isdbgrid") {
  8384. return common_1.ServerType.Mongos;
  8385. }
  8386. if (hello.setName) {
  8387. if (hello.hidden) {
  8388. return common_1.ServerType.RSOther;
  8389. } else if (hello.isWritablePrimary) {
  8390. return common_1.ServerType.RSPrimary;
  8391. } else if (hello.secondary) {
  8392. return common_1.ServerType.RSSecondary;
  8393. } else if (hello.arbiterOnly) {
  8394. return common_1.ServerType.RSArbiter;
  8395. } else {
  8396. return common_1.ServerType.RSOther;
  8397. }
  8398. }
  8399. return common_1.ServerType.Standalone;
  8400. }
  8401. exports2.parseServerType = parseServerType;
  8402. function tagsStrictEqual(tags, tags2) {
  8403. const tagsKeys = Object.keys(tags);
  8404. const tags2Keys = Object.keys(tags2);
  8405. return tagsKeys.length === tags2Keys.length && tagsKeys.every((key) => tags2[key] === tags[key]);
  8406. }
  8407. function compareTopologyVersion(currentTv, newTv) {
  8408. if (currentTv == null || newTv == null) {
  8409. return -1;
  8410. }
  8411. if (!currentTv.processId.equals(newTv.processId)) {
  8412. return -1;
  8413. }
  8414. const currentCounter = bson_1.Long.isLong(currentTv.counter) ? currentTv.counter : bson_1.Long.fromNumber(currentTv.counter);
  8415. const newCounter = bson_1.Long.isLong(newTv.counter) ? newTv.counter : bson_1.Long.fromNumber(newTv.counter);
  8416. return currentCounter.compare(newCounter);
  8417. }
  8418. exports2.compareTopologyVersion = compareTopologyVersion;
  8419. }
  8420. });
  8421. // node_modules/mongodb/lib/sdam/topology_description.js
  8422. var require_topology_description = __commonJS({
  8423. "node_modules/mongodb/lib/sdam/topology_description.js"(exports2) {
  8424. "use strict";
  8425. Object.defineProperty(exports2, "__esModule", { value: true });
  8426. exports2.TopologyDescription = void 0;
  8427. var WIRE_CONSTANTS = require_constants();
  8428. var error_1 = require_error();
  8429. var utils_1 = require_utils();
  8430. var common_1 = require_common();
  8431. var server_description_1 = require_server_description();
  8432. var MIN_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_SERVER_VERSION;
  8433. var MAX_SUPPORTED_SERVER_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_SERVER_VERSION;
  8434. var MIN_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MIN_SUPPORTED_WIRE_VERSION;
  8435. var MAX_SUPPORTED_WIRE_VERSION = WIRE_CONSTANTS.MAX_SUPPORTED_WIRE_VERSION;
  8436. var MONGOS_OR_UNKNOWN = /* @__PURE__ */ new Set([common_1.ServerType.Mongos, common_1.ServerType.Unknown]);
  8437. var MONGOS_OR_STANDALONE = /* @__PURE__ */ new Set([common_1.ServerType.Mongos, common_1.ServerType.Standalone]);
  8438. var NON_PRIMARY_RS_MEMBERS = /* @__PURE__ */ new Set([
  8439. common_1.ServerType.RSSecondary,
  8440. common_1.ServerType.RSArbiter,
  8441. common_1.ServerType.RSOther
  8442. ]);
  8443. var TopologyDescription = class _TopologyDescription {
  8444. /**
  8445. * Create a TopologyDescription
  8446. */
  8447. constructor(topologyType, serverDescriptions = null, setName = null, maxSetVersion = null, maxElectionId = null, commonWireVersion = null, options = null) {
  8448. options = options ?? {};
  8449. this.type = topologyType ?? common_1.TopologyType.Unknown;
  8450. this.servers = serverDescriptions ?? /* @__PURE__ */ new Map();
  8451. this.stale = false;
  8452. this.compatible = true;
  8453. this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 0;
  8454. this.localThresholdMS = options.localThresholdMS ?? 15;
  8455. this.setName = setName ?? null;
  8456. this.maxElectionId = maxElectionId ?? null;
  8457. this.maxSetVersion = maxSetVersion ?? null;
  8458. this.commonWireVersion = commonWireVersion ?? 0;
  8459. for (const serverDescription of this.servers.values()) {
  8460. if (serverDescription.type === common_1.ServerType.Unknown || serverDescription.type === common_1.ServerType.LoadBalancer) {
  8461. continue;
  8462. }
  8463. if (serverDescription.minWireVersion > MAX_SUPPORTED_WIRE_VERSION) {
  8464. this.compatible = false;
  8465. this.compatibilityError = `Server at ${serverDescription.address} requires wire version ${serverDescription.minWireVersion}, but this version of the driver only supports up to ${MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${MAX_SUPPORTED_SERVER_VERSION})`;
  8466. }
  8467. if (serverDescription.maxWireVersion < MIN_SUPPORTED_WIRE_VERSION) {
  8468. this.compatible = false;
  8469. this.compatibilityError = `Server at ${serverDescription.address} reports wire version ${serverDescription.maxWireVersion}, but this version of the driver requires at least ${MIN_SUPPORTED_WIRE_VERSION} (MongoDB ${MIN_SUPPORTED_SERVER_VERSION}).`;
  8470. break;
  8471. }
  8472. }
  8473. this.logicalSessionTimeoutMinutes = null;
  8474. for (const [, server] of this.servers) {
  8475. if (server.isReadable) {
  8476. if (server.logicalSessionTimeoutMinutes == null) {
  8477. this.logicalSessionTimeoutMinutes = null;
  8478. break;
  8479. }
  8480. if (this.logicalSessionTimeoutMinutes == null) {
  8481. this.logicalSessionTimeoutMinutes = server.logicalSessionTimeoutMinutes;
  8482. continue;
  8483. }
  8484. this.logicalSessionTimeoutMinutes = Math.min(this.logicalSessionTimeoutMinutes, server.logicalSessionTimeoutMinutes);
  8485. }
  8486. }
  8487. }
  8488. /**
  8489. * Returns a new TopologyDescription based on the SrvPollingEvent
  8490. * @internal
  8491. */
  8492. updateFromSrvPollingEvent(ev, srvMaxHosts = 0) {
  8493. const incomingHostnames = ev.hostnames();
  8494. const currentHostnames = new Set(this.servers.keys());
  8495. const hostnamesToAdd = new Set(incomingHostnames);
  8496. const hostnamesToRemove = /* @__PURE__ */ new Set();
  8497. for (const hostname of currentHostnames) {
  8498. hostnamesToAdd.delete(hostname);
  8499. if (!incomingHostnames.has(hostname)) {
  8500. hostnamesToRemove.add(hostname);
  8501. }
  8502. }
  8503. if (hostnamesToAdd.size === 0 && hostnamesToRemove.size === 0) {
  8504. return this;
  8505. }
  8506. const serverDescriptions = new Map(this.servers);
  8507. for (const removedHost of hostnamesToRemove) {
  8508. serverDescriptions.delete(removedHost);
  8509. }
  8510. if (hostnamesToAdd.size > 0) {
  8511. if (srvMaxHosts === 0) {
  8512. for (const hostToAdd of hostnamesToAdd) {
  8513. serverDescriptions.set(hostToAdd, new server_description_1.ServerDescription(hostToAdd));
  8514. }
  8515. } else if (serverDescriptions.size < srvMaxHosts) {
  8516. const selectedHosts = (0, utils_1.shuffle)(hostnamesToAdd, srvMaxHosts - serverDescriptions.size);
  8517. for (const selectedHostToAdd of selectedHosts) {
  8518. serverDescriptions.set(selectedHostToAdd, new server_description_1.ServerDescription(selectedHostToAdd));
  8519. }
  8520. }
  8521. }
  8522. return new _TopologyDescription(this.type, serverDescriptions, this.setName, this.maxSetVersion, this.maxElectionId, this.commonWireVersion, { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS });
  8523. }
  8524. /**
  8525. * Returns a copy of this description updated with a given ServerDescription
  8526. * @internal
  8527. */
  8528. update(serverDescription) {
  8529. const address = serverDescription.address;
  8530. let { type: topologyType, setName, maxSetVersion, maxElectionId, commonWireVersion } = this;
  8531. const serverType = serverDescription.type;
  8532. const serverDescriptions = new Map(this.servers);
  8533. if (serverDescription.maxWireVersion !== 0) {
  8534. if (commonWireVersion == null) {
  8535. commonWireVersion = serverDescription.maxWireVersion;
  8536. } else {
  8537. commonWireVersion = Math.min(commonWireVersion, serverDescription.maxWireVersion);
  8538. }
  8539. }
  8540. if (typeof serverDescription.setName === "string" && typeof setName === "string" && serverDescription.setName !== setName) {
  8541. if (topologyType === common_1.TopologyType.Single) {
  8542. serverDescription = new server_description_1.ServerDescription(address);
  8543. } else {
  8544. serverDescriptions.delete(address);
  8545. }
  8546. }
  8547. serverDescriptions.set(address, serverDescription);
  8548. if (topologyType === common_1.TopologyType.Single) {
  8549. return new _TopologyDescription(common_1.TopologyType.Single, serverDescriptions, setName, maxSetVersion, maxElectionId, commonWireVersion, { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS });
  8550. }
  8551. if (topologyType === common_1.TopologyType.Unknown) {
  8552. if (serverType === common_1.ServerType.Standalone && this.servers.size !== 1) {
  8553. serverDescriptions.delete(address);
  8554. } else {
  8555. topologyType = topologyTypeForServerType(serverType);
  8556. }
  8557. }
  8558. if (topologyType === common_1.TopologyType.Sharded) {
  8559. if (!MONGOS_OR_UNKNOWN.has(serverType)) {
  8560. serverDescriptions.delete(address);
  8561. }
  8562. }
  8563. if (topologyType === common_1.TopologyType.ReplicaSetNoPrimary) {
  8564. if (MONGOS_OR_STANDALONE.has(serverType)) {
  8565. serverDescriptions.delete(address);
  8566. }
  8567. if (serverType === common_1.ServerType.RSPrimary) {
  8568. const result = updateRsFromPrimary(serverDescriptions, serverDescription, setName, maxSetVersion, maxElectionId);
  8569. topologyType = result[0];
  8570. setName = result[1];
  8571. maxSetVersion = result[2];
  8572. maxElectionId = result[3];
  8573. } else if (NON_PRIMARY_RS_MEMBERS.has(serverType)) {
  8574. const result = updateRsNoPrimaryFromMember(serverDescriptions, serverDescription, setName);
  8575. topologyType = result[0];
  8576. setName = result[1];
  8577. }
  8578. }
  8579. if (topologyType === common_1.TopologyType.ReplicaSetWithPrimary) {
  8580. if (MONGOS_OR_STANDALONE.has(serverType)) {
  8581. serverDescriptions.delete(address);
  8582. topologyType = checkHasPrimary(serverDescriptions);
  8583. } else if (serverType === common_1.ServerType.RSPrimary) {
  8584. const result = updateRsFromPrimary(serverDescriptions, serverDescription, setName, maxSetVersion, maxElectionId);
  8585. topologyType = result[0];
  8586. setName = result[1];
  8587. maxSetVersion = result[2];
  8588. maxElectionId = result[3];
  8589. } else if (NON_PRIMARY_RS_MEMBERS.has(serverType)) {
  8590. topologyType = updateRsWithPrimaryFromMember(serverDescriptions, serverDescription, setName);
  8591. } else {
  8592. topologyType = checkHasPrimary(serverDescriptions);
  8593. }
  8594. }
  8595. return new _TopologyDescription(topologyType, serverDescriptions, setName, maxSetVersion, maxElectionId, commonWireVersion, { heartbeatFrequencyMS: this.heartbeatFrequencyMS, localThresholdMS: this.localThresholdMS });
  8596. }
  8597. get error() {
  8598. const descriptionsWithError = Array.from(this.servers.values()).filter((sd) => sd.error);
  8599. if (descriptionsWithError.length > 0) {
  8600. return descriptionsWithError[0].error;
  8601. }
  8602. return null;
  8603. }
  8604. /**
  8605. * Determines if the topology description has any known servers
  8606. */
  8607. get hasKnownServers() {
  8608. return Array.from(this.servers.values()).some((sd) => sd.type !== common_1.ServerType.Unknown);
  8609. }
  8610. /**
  8611. * Determines if this topology description has a data-bearing server available.
  8612. */
  8613. get hasDataBearingServers() {
  8614. return Array.from(this.servers.values()).some((sd) => sd.isDataBearing);
  8615. }
  8616. /**
  8617. * Determines if the topology has a definition for the provided address
  8618. * @internal
  8619. */
  8620. hasServer(address) {
  8621. return this.servers.has(address);
  8622. }
  8623. };
  8624. exports2.TopologyDescription = TopologyDescription;
  8625. function topologyTypeForServerType(serverType) {
  8626. switch (serverType) {
  8627. case common_1.ServerType.Standalone:
  8628. return common_1.TopologyType.Single;
  8629. case common_1.ServerType.Mongos:
  8630. return common_1.TopologyType.Sharded;
  8631. case common_1.ServerType.RSPrimary:
  8632. return common_1.TopologyType.ReplicaSetWithPrimary;
  8633. case common_1.ServerType.RSOther:
  8634. case common_1.ServerType.RSSecondary:
  8635. return common_1.TopologyType.ReplicaSetNoPrimary;
  8636. default:
  8637. return common_1.TopologyType.Unknown;
  8638. }
  8639. }
  8640. function updateRsFromPrimary(serverDescriptions, serverDescription, setName = null, maxSetVersion = null, maxElectionId = null) {
  8641. setName = setName || serverDescription.setName;
  8642. if (setName !== serverDescription.setName) {
  8643. serverDescriptions.delete(serverDescription.address);
  8644. return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
  8645. }
  8646. if (serverDescription.maxWireVersion >= 17) {
  8647. const electionIdComparison = (0, utils_1.compareObjectId)(maxElectionId, serverDescription.electionId);
  8648. const maxElectionIdIsEqual = electionIdComparison === 0;
  8649. const maxElectionIdIsLess = electionIdComparison === -1;
  8650. const maxSetVersionIsLessOrEqual = (maxSetVersion ?? -1) <= (serverDescription.setVersion ?? -1);
  8651. if (maxElectionIdIsLess || maxElectionIdIsEqual && maxSetVersionIsLessOrEqual) {
  8652. maxElectionId = serverDescription.electionId;
  8653. maxSetVersion = serverDescription.setVersion;
  8654. } else {
  8655. serverDescriptions.set(serverDescription.address, new server_description_1.ServerDescription(serverDescription.address));
  8656. return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
  8657. }
  8658. } else {
  8659. const electionId = serverDescription.electionId ? serverDescription.electionId : null;
  8660. if (serverDescription.setVersion && electionId) {
  8661. if (maxSetVersion && maxElectionId) {
  8662. if (maxSetVersion > serverDescription.setVersion || (0, utils_1.compareObjectId)(maxElectionId, electionId) > 0) {
  8663. serverDescriptions.set(serverDescription.address, new server_description_1.ServerDescription(serverDescription.address));
  8664. return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
  8665. }
  8666. }
  8667. maxElectionId = serverDescription.electionId;
  8668. }
  8669. if (serverDescription.setVersion != null && (maxSetVersion == null || serverDescription.setVersion > maxSetVersion)) {
  8670. maxSetVersion = serverDescription.setVersion;
  8671. }
  8672. }
  8673. for (const [address, server] of serverDescriptions) {
  8674. if (server.type === common_1.ServerType.RSPrimary && server.address !== serverDescription.address) {
  8675. serverDescriptions.set(address, new server_description_1.ServerDescription(server.address));
  8676. break;
  8677. }
  8678. }
  8679. serverDescription.allHosts.forEach((address) => {
  8680. if (!serverDescriptions.has(address)) {
  8681. serverDescriptions.set(address, new server_description_1.ServerDescription(address));
  8682. }
  8683. });
  8684. const currentAddresses = Array.from(serverDescriptions.keys());
  8685. const responseAddresses = serverDescription.allHosts;
  8686. currentAddresses.filter((addr) => responseAddresses.indexOf(addr) === -1).forEach((address) => {
  8687. serverDescriptions.delete(address);
  8688. });
  8689. return [checkHasPrimary(serverDescriptions), setName, maxSetVersion, maxElectionId];
  8690. }
  8691. function updateRsWithPrimaryFromMember(serverDescriptions, serverDescription, setName = null) {
  8692. if (setName == null) {
  8693. throw new error_1.MongoRuntimeError('Argument "setName" is required if connected to a replica set');
  8694. }
  8695. if (setName !== serverDescription.setName || serverDescription.me && serverDescription.address !== serverDescription.me) {
  8696. serverDescriptions.delete(serverDescription.address);
  8697. }
  8698. return checkHasPrimary(serverDescriptions);
  8699. }
  8700. function updateRsNoPrimaryFromMember(serverDescriptions, serverDescription, setName = null) {
  8701. const topologyType = common_1.TopologyType.ReplicaSetNoPrimary;
  8702. setName = setName ?? serverDescription.setName;
  8703. if (setName !== serverDescription.setName) {
  8704. serverDescriptions.delete(serverDescription.address);
  8705. return [topologyType, setName];
  8706. }
  8707. serverDescription.allHosts.forEach((address) => {
  8708. if (!serverDescriptions.has(address)) {
  8709. serverDescriptions.set(address, new server_description_1.ServerDescription(address));
  8710. }
  8711. });
  8712. if (serverDescription.me && serverDescription.address !== serverDescription.me) {
  8713. serverDescriptions.delete(serverDescription.address);
  8714. }
  8715. return [topologyType, setName];
  8716. }
  8717. function checkHasPrimary(serverDescriptions) {
  8718. for (const serverDescription of serverDescriptions.values()) {
  8719. if (serverDescription.type === common_1.ServerType.RSPrimary) {
  8720. return common_1.TopologyType.ReplicaSetWithPrimary;
  8721. }
  8722. }
  8723. return common_1.TopologyType.ReplicaSetNoPrimary;
  8724. }
  8725. }
  8726. });
  8727. // node_modules/mongodb/lib/cmap/wire_protocol/shared.js
  8728. var require_shared = __commonJS({
  8729. "node_modules/mongodb/lib/cmap/wire_protocol/shared.js"(exports2) {
  8730. "use strict";
  8731. Object.defineProperty(exports2, "__esModule", { value: true });
  8732. exports2.isSharded = exports2.getReadPreference = void 0;
  8733. var error_1 = require_error();
  8734. var read_preference_1 = require_read_preference();
  8735. var common_1 = require_common();
  8736. var topology_description_1 = require_topology_description();
  8737. function getReadPreference(options) {
  8738. let readPreference = (options == null ? void 0 : options.readPreference) ?? read_preference_1.ReadPreference.primary;
  8739. if (options == null ? void 0 : options.readPreference) {
  8740. readPreference = options.readPreference;
  8741. }
  8742. if (typeof readPreference === "string") {
  8743. readPreference = read_preference_1.ReadPreference.fromString(readPreference);
  8744. }
  8745. if (!(readPreference instanceof read_preference_1.ReadPreference)) {
  8746. throw new error_1.MongoInvalidArgumentError('Option "readPreference" must be a ReadPreference instance');
  8747. }
  8748. return readPreference;
  8749. }
  8750. exports2.getReadPreference = getReadPreference;
  8751. function isSharded(topologyOrServer) {
  8752. if (topologyOrServer == null) {
  8753. return false;
  8754. }
  8755. if (topologyOrServer.description && topologyOrServer.description.type === common_1.ServerType.Mongos) {
  8756. return true;
  8757. }
  8758. if (topologyOrServer.description && topologyOrServer.description instanceof topology_description_1.TopologyDescription) {
  8759. const servers = Array.from(topologyOrServer.description.servers.values());
  8760. return servers.some((server) => server.type === common_1.ServerType.Mongos);
  8761. }
  8762. return false;
  8763. }
  8764. exports2.isSharded = isSharded;
  8765. }
  8766. });
  8767. // node_modules/mongodb/lib/transactions.js
  8768. var require_transactions = __commonJS({
  8769. "node_modules/mongodb/lib/transactions.js"(exports2) {
  8770. "use strict";
  8771. Object.defineProperty(exports2, "__esModule", { value: true });
  8772. exports2.isTransactionCommand = exports2.Transaction = exports2.TxnState = void 0;
  8773. var error_1 = require_error();
  8774. var read_concern_1 = require_read_concern();
  8775. var read_preference_1 = require_read_preference();
  8776. var write_concern_1 = require_write_concern();
  8777. exports2.TxnState = Object.freeze({
  8778. NO_TRANSACTION: "NO_TRANSACTION",
  8779. STARTING_TRANSACTION: "STARTING_TRANSACTION",
  8780. TRANSACTION_IN_PROGRESS: "TRANSACTION_IN_PROGRESS",
  8781. TRANSACTION_COMMITTED: "TRANSACTION_COMMITTED",
  8782. TRANSACTION_COMMITTED_EMPTY: "TRANSACTION_COMMITTED_EMPTY",
  8783. TRANSACTION_ABORTED: "TRANSACTION_ABORTED"
  8784. });
  8785. var stateMachine = {
  8786. [exports2.TxnState.NO_TRANSACTION]: [exports2.TxnState.NO_TRANSACTION, exports2.TxnState.STARTING_TRANSACTION],
  8787. [exports2.TxnState.STARTING_TRANSACTION]: [
  8788. exports2.TxnState.TRANSACTION_IN_PROGRESS,
  8789. exports2.TxnState.TRANSACTION_COMMITTED,
  8790. exports2.TxnState.TRANSACTION_COMMITTED_EMPTY,
  8791. exports2.TxnState.TRANSACTION_ABORTED
  8792. ],
  8793. [exports2.TxnState.TRANSACTION_IN_PROGRESS]: [
  8794. exports2.TxnState.TRANSACTION_IN_PROGRESS,
  8795. exports2.TxnState.TRANSACTION_COMMITTED,
  8796. exports2.TxnState.TRANSACTION_ABORTED
  8797. ],
  8798. [exports2.TxnState.TRANSACTION_COMMITTED]: [
  8799. exports2.TxnState.TRANSACTION_COMMITTED,
  8800. exports2.TxnState.TRANSACTION_COMMITTED_EMPTY,
  8801. exports2.TxnState.STARTING_TRANSACTION,
  8802. exports2.TxnState.NO_TRANSACTION
  8803. ],
  8804. [exports2.TxnState.TRANSACTION_ABORTED]: [exports2.TxnState.STARTING_TRANSACTION, exports2.TxnState.NO_TRANSACTION],
  8805. [exports2.TxnState.TRANSACTION_COMMITTED_EMPTY]: [
  8806. exports2.TxnState.TRANSACTION_COMMITTED_EMPTY,
  8807. exports2.TxnState.NO_TRANSACTION
  8808. ]
  8809. };
  8810. var ACTIVE_STATES = /* @__PURE__ */ new Set([
  8811. exports2.TxnState.STARTING_TRANSACTION,
  8812. exports2.TxnState.TRANSACTION_IN_PROGRESS
  8813. ]);
  8814. var COMMITTED_STATES = /* @__PURE__ */ new Set([
  8815. exports2.TxnState.TRANSACTION_COMMITTED,
  8816. exports2.TxnState.TRANSACTION_COMMITTED_EMPTY,
  8817. exports2.TxnState.TRANSACTION_ABORTED
  8818. ]);
  8819. var Transaction = class {
  8820. /** Create a transaction @internal */
  8821. constructor(options) {
  8822. options = options ?? {};
  8823. this.state = exports2.TxnState.NO_TRANSACTION;
  8824. this.options = {};
  8825. const writeConcern = write_concern_1.WriteConcern.fromOptions(options);
  8826. if (writeConcern) {
  8827. if (writeConcern.w === 0) {
  8828. throw new error_1.MongoTransactionError("Transactions do not support unacknowledged write concern");
  8829. }
  8830. this.options.writeConcern = writeConcern;
  8831. }
  8832. if (options.readConcern) {
  8833. this.options.readConcern = read_concern_1.ReadConcern.fromOptions(options);
  8834. }
  8835. if (options.readPreference) {
  8836. this.options.readPreference = read_preference_1.ReadPreference.fromOptions(options);
  8837. }
  8838. if (options.maxCommitTimeMS) {
  8839. this.options.maxTimeMS = options.maxCommitTimeMS;
  8840. }
  8841. this._pinnedServer = void 0;
  8842. this._recoveryToken = void 0;
  8843. }
  8844. /** @internal */
  8845. get server() {
  8846. return this._pinnedServer;
  8847. }
  8848. get recoveryToken() {
  8849. return this._recoveryToken;
  8850. }
  8851. get isPinned() {
  8852. return !!this.server;
  8853. }
  8854. /** @returns Whether the transaction has started */
  8855. get isStarting() {
  8856. return this.state === exports2.TxnState.STARTING_TRANSACTION;
  8857. }
  8858. /**
  8859. * @returns Whether this session is presently in a transaction
  8860. */
  8861. get isActive() {
  8862. return ACTIVE_STATES.has(this.state);
  8863. }
  8864. get isCommitted() {
  8865. return COMMITTED_STATES.has(this.state);
  8866. }
  8867. /**
  8868. * Transition the transaction in the state machine
  8869. * @internal
  8870. * @param nextState - The new state to transition to
  8871. */
  8872. transition(nextState) {
  8873. const nextStates = stateMachine[this.state];
  8874. if (nextStates && nextStates.includes(nextState)) {
  8875. this.state = nextState;
  8876. if (this.state === exports2.TxnState.NO_TRANSACTION || this.state === exports2.TxnState.STARTING_TRANSACTION || this.state === exports2.TxnState.TRANSACTION_ABORTED) {
  8877. this.unpinServer();
  8878. }
  8879. return;
  8880. }
  8881. throw new error_1.MongoRuntimeError(`Attempted illegal state transition from [${this.state}] to [${nextState}]`);
  8882. }
  8883. /** @internal */
  8884. pinServer(server) {
  8885. if (this.isActive) {
  8886. this._pinnedServer = server;
  8887. }
  8888. }
  8889. /** @internal */
  8890. unpinServer() {
  8891. this._pinnedServer = void 0;
  8892. }
  8893. };
  8894. exports2.Transaction = Transaction;
  8895. function isTransactionCommand(command) {
  8896. return !!(command.commitTransaction || command.abortTransaction);
  8897. }
  8898. exports2.isTransactionCommand = isTransactionCommand;
  8899. }
  8900. });
  8901. // node_modules/mongodb/lib/sessions.js
  8902. var require_sessions = __commonJS({
  8903. "node_modules/mongodb/lib/sessions.js"(exports2) {
  8904. "use strict";
  8905. var _a;
  8906. Object.defineProperty(exports2, "__esModule", { value: true });
  8907. exports2.updateSessionFromResponse = exports2.applySession = exports2.ServerSessionPool = exports2.ServerSession = exports2.maybeClearPinnedConnection = exports2.ClientSession = void 0;
  8908. var util_1 = require("util");
  8909. var bson_1 = require_bson2();
  8910. var metrics_1 = require_metrics();
  8911. var shared_1 = require_shared();
  8912. var constants_1 = require_constants2();
  8913. var error_1 = require_error();
  8914. var mongo_types_1 = require_mongo_types();
  8915. var execute_operation_1 = require_execute_operation();
  8916. var run_command_1 = require_run_command();
  8917. var read_concern_1 = require_read_concern();
  8918. var read_preference_1 = require_read_preference();
  8919. var common_1 = require_common();
  8920. var transactions_1 = require_transactions();
  8921. var utils_1 = require_utils();
  8922. var write_concern_1 = require_write_concern();
  8923. var minWireVersionForShardedTransactions = 8;
  8924. var kServerSession = Symbol("serverSession");
  8925. var kSnapshotTime = Symbol("snapshotTime");
  8926. var kSnapshotEnabled = Symbol("snapshotEnabled");
  8927. var kPinnedConnection = Symbol("pinnedConnection");
  8928. var kTxnNumberIncrement = Symbol("txnNumberIncrement");
  8929. var ClientSession = class _ClientSession extends mongo_types_1.TypedEventEmitter {
  8930. /**
  8931. * Create a client session.
  8932. * @internal
  8933. * @param client - The current client
  8934. * @param sessionPool - The server session pool (Internal Class)
  8935. * @param options - Optional settings
  8936. * @param clientOptions - Optional settings provided when creating a MongoClient
  8937. */
  8938. constructor(client, sessionPool, options, clientOptions) {
  8939. super();
  8940. this[_a] = false;
  8941. if (client == null) {
  8942. throw new error_1.MongoRuntimeError("ClientSession requires a MongoClient");
  8943. }
  8944. if (sessionPool == null || !(sessionPool instanceof ServerSessionPool)) {
  8945. throw new error_1.MongoRuntimeError("ClientSession requires a ServerSessionPool");
  8946. }
  8947. options = options ?? {};
  8948. if (options.snapshot === true) {
  8949. this[kSnapshotEnabled] = true;
  8950. if (options.causalConsistency === true) {
  8951. throw new error_1.MongoInvalidArgumentError('Properties "causalConsistency" and "snapshot" are mutually exclusive');
  8952. }
  8953. }
  8954. this.client = client;
  8955. this.sessionPool = sessionPool;
  8956. this.hasEnded = false;
  8957. this.clientOptions = clientOptions;
  8958. this.explicit = !!options.explicit;
  8959. this[kServerSession] = this.explicit ? this.sessionPool.acquire() : null;
  8960. this[kTxnNumberIncrement] = 0;
  8961. const defaultCausalConsistencyValue = this.explicit && options.snapshot !== true;
  8962. this.supports = {
  8963. // if we can enable causal consistency, do so by default
  8964. causalConsistency: options.causalConsistency ?? defaultCausalConsistencyValue
  8965. };
  8966. this.clusterTime = options.initialClusterTime;
  8967. this.operationTime = void 0;
  8968. this.owner = options.owner;
  8969. this.defaultTransactionOptions = Object.assign({}, options.defaultTransactionOptions);
  8970. this.transaction = new transactions_1.Transaction();
  8971. }
  8972. /** The server id associated with this session */
  8973. get id() {
  8974. var _a2;
  8975. return (_a2 = this[kServerSession]) == null ? void 0 : _a2.id;
  8976. }
  8977. get serverSession() {
  8978. let serverSession = this[kServerSession];
  8979. if (serverSession == null) {
  8980. if (this.explicit) {
  8981. throw new error_1.MongoRuntimeError("Unexpected null serverSession for an explicit session");
  8982. }
  8983. if (this.hasEnded) {
  8984. throw new error_1.MongoRuntimeError("Unexpected null serverSession for an ended implicit session");
  8985. }
  8986. serverSession = this.sessionPool.acquire();
  8987. this[kServerSession] = serverSession;
  8988. }
  8989. return serverSession;
  8990. }
  8991. /** Whether or not this session is configured for snapshot reads */
  8992. get snapshotEnabled() {
  8993. return this[kSnapshotEnabled];
  8994. }
  8995. get loadBalanced() {
  8996. var _a2;
  8997. return ((_a2 = this.client.topology) == null ? void 0 : _a2.description.type) === common_1.TopologyType.LoadBalanced;
  8998. }
  8999. /** @internal */
  9000. get pinnedConnection() {
  9001. return this[kPinnedConnection];
  9002. }
  9003. /** @internal */
  9004. pin(conn) {
  9005. if (this[kPinnedConnection]) {
  9006. throw TypeError("Cannot pin multiple connections to the same session");
  9007. }
  9008. this[kPinnedConnection] = conn;
  9009. conn.emit(constants_1.PINNED, this.inTransaction() ? metrics_1.ConnectionPoolMetrics.TXN : metrics_1.ConnectionPoolMetrics.CURSOR);
  9010. }
  9011. /** @internal */
  9012. unpin(options) {
  9013. if (this.loadBalanced) {
  9014. return maybeClearPinnedConnection(this, options);
  9015. }
  9016. this.transaction.unpinServer();
  9017. }
  9018. get isPinned() {
  9019. return this.loadBalanced ? !!this[kPinnedConnection] : this.transaction.isPinned;
  9020. }
  9021. /**
  9022. * Ends this session on the server
  9023. *
  9024. * @param options - Optional settings. Currently reserved for future use
  9025. */
  9026. async endSession(options) {
  9027. try {
  9028. if (this.inTransaction()) {
  9029. await this.abortTransaction();
  9030. }
  9031. if (!this.hasEnded) {
  9032. const serverSession = this[kServerSession];
  9033. if (serverSession != null) {
  9034. this.sessionPool.release(serverSession);
  9035. Object.defineProperty(this, kServerSession, {
  9036. value: ServerSession.clone(serverSession),
  9037. writable: false
  9038. });
  9039. }
  9040. this.hasEnded = true;
  9041. this.emit("ended", this);
  9042. }
  9043. } catch {
  9044. } finally {
  9045. maybeClearPinnedConnection(this, { force: true, ...options });
  9046. }
  9047. }
  9048. /**
  9049. * Advances the operationTime for a ClientSession.
  9050. *
  9051. * @param operationTime - the `BSON.Timestamp` of the operation type it is desired to advance to
  9052. */
  9053. advanceOperationTime(operationTime) {
  9054. if (this.operationTime == null) {
  9055. this.operationTime = operationTime;
  9056. return;
  9057. }
  9058. if (operationTime.greaterThan(this.operationTime)) {
  9059. this.operationTime = operationTime;
  9060. }
  9061. }
  9062. /**
  9063. * Advances the clusterTime for a ClientSession to the provided clusterTime of another ClientSession
  9064. *
  9065. * @param clusterTime - the $clusterTime returned by the server from another session in the form of a document containing the `BSON.Timestamp` clusterTime and signature
  9066. */
  9067. advanceClusterTime(clusterTime) {
  9068. var _a2, _b;
  9069. if (!clusterTime || typeof clusterTime !== "object") {
  9070. throw new error_1.MongoInvalidArgumentError("input cluster time must be an object");
  9071. }
  9072. if (!clusterTime.clusterTime || clusterTime.clusterTime._bsontype !== "Timestamp") {
  9073. throw new error_1.MongoInvalidArgumentError('input cluster time "clusterTime" property must be a valid BSON Timestamp');
  9074. }
  9075. if (!clusterTime.signature || ((_a2 = clusterTime.signature.hash) == null ? void 0 : _a2._bsontype) !== "Binary" || typeof clusterTime.signature.keyId !== "bigint" && typeof clusterTime.signature.keyId !== "number" && ((_b = clusterTime.signature.keyId) == null ? void 0 : _b._bsontype) !== "Long") {
  9076. throw new error_1.MongoInvalidArgumentError('input cluster time must have a valid "signature" property with BSON Binary hash and BSON Long keyId');
  9077. }
  9078. (0, common_1._advanceClusterTime)(this, clusterTime);
  9079. }
  9080. /**
  9081. * Used to determine if this session equals another
  9082. *
  9083. * @param session - The session to compare to
  9084. */
  9085. equals(session) {
  9086. if (!(session instanceof _ClientSession)) {
  9087. return false;
  9088. }
  9089. if (this.id == null || session.id == null) {
  9090. return false;
  9091. }
  9092. return utils_1.ByteUtils.equals(this.id.id.buffer, session.id.id.buffer);
  9093. }
  9094. /**
  9095. * Increment the transaction number on the internal ServerSession
  9096. *
  9097. * @privateRemarks
  9098. * This helper increments a value stored on the client session that will be
  9099. * added to the serverSession's txnNumber upon applying it to a command.
  9100. * This is because the serverSession is lazily acquired after a connection is obtained
  9101. */
  9102. incrementTransactionNumber() {
  9103. this[kTxnNumberIncrement] += 1;
  9104. }
  9105. /** @returns whether this session is currently in a transaction or not */
  9106. inTransaction() {
  9107. return this.transaction.isActive;
  9108. }
  9109. /**
  9110. * Starts a new transaction with the given options.
  9111. *
  9112. * @param options - Options for the transaction
  9113. */
  9114. startTransaction(options) {
  9115. var _a2, _b, _c;
  9116. if (this[kSnapshotEnabled]) {
  9117. throw new error_1.MongoCompatibilityError("Transactions are not supported in snapshot sessions");
  9118. }
  9119. if (this.inTransaction()) {
  9120. throw new error_1.MongoTransactionError("Transaction already in progress");
  9121. }
  9122. if (this.isPinned && this.transaction.isCommitted) {
  9123. this.unpin();
  9124. }
  9125. const topologyMaxWireVersion = (0, utils_1.maxWireVersion)(this.client.topology);
  9126. if ((0, shared_1.isSharded)(this.client.topology) && topologyMaxWireVersion != null && topologyMaxWireVersion < minWireVersionForShardedTransactions) {
  9127. throw new error_1.MongoCompatibilityError("Transactions are not supported on sharded clusters in MongoDB < 4.2.");
  9128. }
  9129. this.incrementTransactionNumber();
  9130. this.transaction = new transactions_1.Transaction({
  9131. readConcern: (options == null ? void 0 : options.readConcern) ?? this.defaultTransactionOptions.readConcern ?? ((_a2 = this.clientOptions) == null ? void 0 : _a2.readConcern),
  9132. writeConcern: (options == null ? void 0 : options.writeConcern) ?? this.defaultTransactionOptions.writeConcern ?? ((_b = this.clientOptions) == null ? void 0 : _b.writeConcern),
  9133. readPreference: (options == null ? void 0 : options.readPreference) ?? this.defaultTransactionOptions.readPreference ?? ((_c = this.clientOptions) == null ? void 0 : _c.readPreference),
  9134. maxCommitTimeMS: (options == null ? void 0 : options.maxCommitTimeMS) ?? this.defaultTransactionOptions.maxCommitTimeMS
  9135. });
  9136. this.transaction.transition(transactions_1.TxnState.STARTING_TRANSACTION);
  9137. }
  9138. /**
  9139. * Commits the currently active transaction in this session.
  9140. */
  9141. async commitTransaction() {
  9142. return endTransactionAsync(this, "commitTransaction");
  9143. }
  9144. /**
  9145. * Aborts the currently active transaction in this session.
  9146. */
  9147. async abortTransaction() {
  9148. return endTransactionAsync(this, "abortTransaction");
  9149. }
  9150. /**
  9151. * This is here to ensure that ClientSession is never serialized to BSON.
  9152. */
  9153. toBSON() {
  9154. throw new error_1.MongoRuntimeError("ClientSession cannot be serialized to BSON.");
  9155. }
  9156. /**
  9157. * Runs a provided callback within a transaction, retrying either the commitTransaction operation
  9158. * or entire transaction as needed (and when the error permits) to better ensure that
  9159. * the transaction can complete successfully.
  9160. *
  9161. * **IMPORTANT:** This method requires the user to return a Promise, and `await` all operations.
  9162. * Any callbacks that do not return a Promise will result in undefined behavior.
  9163. *
  9164. * @remarks
  9165. * This function:
  9166. * - Will return the command response from the final commitTransaction if every operation is successful (can be used as a truthy object)
  9167. * - Will return `undefined` if the transaction is explicitly aborted with `await session.abortTransaction()`
  9168. * - Will throw if one of the operations throws or `throw` statement is used inside the `withTransaction` callback
  9169. *
  9170. * Checkout a descriptive example here:
  9171. * @see https://www.mongodb.com/developer/quickstart/node-transactions/
  9172. *
  9173. * @param fn - callback to run within a transaction
  9174. * @param options - optional settings for the transaction
  9175. * @returns A raw command response or undefined
  9176. */
  9177. async withTransaction(fn, options) {
  9178. const startTime = (0, utils_1.now)();
  9179. return attemptTransaction(this, startTime, fn, options);
  9180. }
  9181. };
  9182. exports2.ClientSession = ClientSession;
  9183. _a = kSnapshotEnabled;
  9184. var MAX_WITH_TRANSACTION_TIMEOUT = 12e4;
  9185. var NON_DETERMINISTIC_WRITE_CONCERN_ERRORS = /* @__PURE__ */ new Set([
  9186. "CannotSatisfyWriteConcern",
  9187. "UnknownReplWriteConcern",
  9188. "UnsatisfiableWriteConcern"
  9189. ]);
  9190. function hasNotTimedOut(startTime, max) {
  9191. return (0, utils_1.calculateDurationInMs)(startTime) < max;
  9192. }
  9193. function isUnknownTransactionCommitResult(err) {
  9194. const isNonDeterministicWriteConcernError = err instanceof error_1.MongoServerError && err.codeName && NON_DETERMINISTIC_WRITE_CONCERN_ERRORS.has(err.codeName);
  9195. return isMaxTimeMSExpiredError(err) || !isNonDeterministicWriteConcernError && err.code !== error_1.MONGODB_ERROR_CODES.UnsatisfiableWriteConcern && err.code !== error_1.MONGODB_ERROR_CODES.UnknownReplWriteConcern;
  9196. }
  9197. function maybeClearPinnedConnection(session, options) {
  9198. const conn = session[kPinnedConnection];
  9199. const error = options == null ? void 0 : options.error;
  9200. if (session.inTransaction() && error && error instanceof error_1.MongoError && error.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
  9201. return;
  9202. }
  9203. const topology = session.client.topology;
  9204. if (conn && topology != null) {
  9205. const servers = Array.from(topology.s.servers.values());
  9206. const loadBalancer = servers[0];
  9207. if ((options == null ? void 0 : options.error) == null || (options == null ? void 0 : options.force)) {
  9208. loadBalancer.pool.checkIn(conn);
  9209. conn.emit(constants_1.UNPINNED, session.transaction.state !== transactions_1.TxnState.NO_TRANSACTION ? metrics_1.ConnectionPoolMetrics.TXN : metrics_1.ConnectionPoolMetrics.CURSOR);
  9210. if (options == null ? void 0 : options.forceClear) {
  9211. loadBalancer.pool.clear({ serviceId: conn.serviceId });
  9212. }
  9213. }
  9214. session[kPinnedConnection] = void 0;
  9215. }
  9216. }
  9217. exports2.maybeClearPinnedConnection = maybeClearPinnedConnection;
  9218. function isMaxTimeMSExpiredError(err) {
  9219. if (err == null || !(err instanceof error_1.MongoServerError)) {
  9220. return false;
  9221. }
  9222. return err.code === error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired || err.writeConcernError && err.writeConcernError.code === error_1.MONGODB_ERROR_CODES.MaxTimeMSExpired;
  9223. }
  9224. function attemptTransactionCommit(session, startTime, fn, options) {
  9225. return session.commitTransaction().catch((err) => {
  9226. if (err instanceof error_1.MongoError && hasNotTimedOut(startTime, MAX_WITH_TRANSACTION_TIMEOUT) && !isMaxTimeMSExpiredError(err)) {
  9227. if (err.hasErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult)) {
  9228. return attemptTransactionCommit(session, startTime, fn, options);
  9229. }
  9230. if (err.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
  9231. return attemptTransaction(session, startTime, fn, options);
  9232. }
  9233. }
  9234. throw err;
  9235. });
  9236. }
  9237. var USER_EXPLICIT_TXN_END_STATES = /* @__PURE__ */ new Set([
  9238. transactions_1.TxnState.NO_TRANSACTION,
  9239. transactions_1.TxnState.TRANSACTION_COMMITTED,
  9240. transactions_1.TxnState.TRANSACTION_ABORTED
  9241. ]);
  9242. function userExplicitlyEndedTransaction(session) {
  9243. return USER_EXPLICIT_TXN_END_STATES.has(session.transaction.state);
  9244. }
  9245. function attemptTransaction(session, startTime, fn, options) {
  9246. session.startTransaction(options);
  9247. let promise;
  9248. try {
  9249. promise = fn(session);
  9250. } catch (err) {
  9251. promise = Promise.reject(err);
  9252. }
  9253. if (!(0, utils_1.isPromiseLike)(promise)) {
  9254. session.abortTransaction().catch(() => null);
  9255. throw new error_1.MongoInvalidArgumentError("Function provided to `withTransaction` must return a Promise");
  9256. }
  9257. return promise.then(() => {
  9258. if (userExplicitlyEndedTransaction(session)) {
  9259. return;
  9260. }
  9261. return attemptTransactionCommit(session, startTime, fn, options);
  9262. }, (err) => {
  9263. function maybeRetryOrThrow(err2) {
  9264. if (err2 instanceof error_1.MongoError && err2.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError) && hasNotTimedOut(startTime, MAX_WITH_TRANSACTION_TIMEOUT)) {
  9265. return attemptTransaction(session, startTime, fn, options);
  9266. }
  9267. if (isMaxTimeMSExpiredError(err2)) {
  9268. err2.addErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult);
  9269. }
  9270. throw err2;
  9271. }
  9272. if (session.inTransaction()) {
  9273. return session.abortTransaction().then(() => maybeRetryOrThrow(err));
  9274. }
  9275. return maybeRetryOrThrow(err);
  9276. });
  9277. }
  9278. var endTransactionAsync = (0, util_1.promisify)(endTransaction);
  9279. function endTransaction(session, commandName, callback) {
  9280. const txnState = session.transaction.state;
  9281. if (txnState === transactions_1.TxnState.NO_TRANSACTION) {
  9282. callback(new error_1.MongoTransactionError("No transaction started"));
  9283. return;
  9284. }
  9285. if (commandName === "commitTransaction") {
  9286. if (txnState === transactions_1.TxnState.STARTING_TRANSACTION || txnState === transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY) {
  9287. session.transaction.transition(transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY);
  9288. callback();
  9289. return;
  9290. }
  9291. if (txnState === transactions_1.TxnState.TRANSACTION_ABORTED) {
  9292. callback(new error_1.MongoTransactionError("Cannot call commitTransaction after calling abortTransaction"));
  9293. return;
  9294. }
  9295. } else {
  9296. if (txnState === transactions_1.TxnState.STARTING_TRANSACTION) {
  9297. session.transaction.transition(transactions_1.TxnState.TRANSACTION_ABORTED);
  9298. callback();
  9299. return;
  9300. }
  9301. if (txnState === transactions_1.TxnState.TRANSACTION_ABORTED) {
  9302. callback(new error_1.MongoTransactionError("Cannot call abortTransaction twice"));
  9303. return;
  9304. }
  9305. if (txnState === transactions_1.TxnState.TRANSACTION_COMMITTED || txnState === transactions_1.TxnState.TRANSACTION_COMMITTED_EMPTY) {
  9306. callback(new error_1.MongoTransactionError("Cannot call abortTransaction after calling commitTransaction"));
  9307. return;
  9308. }
  9309. }
  9310. const command = { [commandName]: 1 };
  9311. let writeConcern;
  9312. if (session.transaction.options.writeConcern) {
  9313. writeConcern = Object.assign({}, session.transaction.options.writeConcern);
  9314. } else if (session.clientOptions && session.clientOptions.writeConcern) {
  9315. writeConcern = { w: session.clientOptions.writeConcern.w };
  9316. }
  9317. if (txnState === transactions_1.TxnState.TRANSACTION_COMMITTED) {
  9318. writeConcern = Object.assign({ wtimeoutMS: 1e4 }, writeConcern, { w: "majority" });
  9319. }
  9320. if (writeConcern) {
  9321. write_concern_1.WriteConcern.apply(command, writeConcern);
  9322. }
  9323. if (commandName === "commitTransaction" && session.transaction.options.maxTimeMS) {
  9324. Object.assign(command, { maxTimeMS: session.transaction.options.maxTimeMS });
  9325. }
  9326. function commandHandler(error, result) {
  9327. if (commandName !== "commitTransaction") {
  9328. session.transaction.transition(transactions_1.TxnState.TRANSACTION_ABORTED);
  9329. if (session.loadBalanced) {
  9330. maybeClearPinnedConnection(session, { force: false });
  9331. }
  9332. return callback();
  9333. }
  9334. session.transaction.transition(transactions_1.TxnState.TRANSACTION_COMMITTED);
  9335. if (error instanceof error_1.MongoError) {
  9336. if (error.hasErrorLabel(error_1.MongoErrorLabel.RetryableWriteError) || error instanceof error_1.MongoWriteConcernError || isMaxTimeMSExpiredError(error)) {
  9337. if (isUnknownTransactionCommitResult(error)) {
  9338. error.addErrorLabel(error_1.MongoErrorLabel.UnknownTransactionCommitResult);
  9339. session.unpin({ error });
  9340. }
  9341. } else if (error.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
  9342. session.unpin({ error });
  9343. }
  9344. }
  9345. callback(error, result);
  9346. }
  9347. if (session.transaction.recoveryToken) {
  9348. command.recoveryToken = session.transaction.recoveryToken;
  9349. }
  9350. (0, execute_operation_1.executeOperation)(session.client, new run_command_1.RunAdminCommandOperation(void 0, command, {
  9351. session,
  9352. readPreference: read_preference_1.ReadPreference.primary,
  9353. bypassPinningCheck: true
  9354. }), (error, result) => {
  9355. if (command.abortTransaction) {
  9356. session.unpin();
  9357. }
  9358. if (error instanceof error_1.MongoError && error.hasErrorLabel(error_1.MongoErrorLabel.RetryableWriteError)) {
  9359. if (command.commitTransaction) {
  9360. session.unpin({ force: true });
  9361. command.writeConcern = Object.assign({ wtimeout: 1e4 }, command.writeConcern, {
  9362. w: "majority"
  9363. });
  9364. }
  9365. return (0, execute_operation_1.executeOperation)(session.client, new run_command_1.RunAdminCommandOperation(void 0, command, {
  9366. session,
  9367. readPreference: read_preference_1.ReadPreference.primary,
  9368. bypassPinningCheck: true
  9369. }), commandHandler);
  9370. }
  9371. commandHandler(error, result);
  9372. });
  9373. }
  9374. var ServerSession = class _ServerSession {
  9375. /** @internal */
  9376. constructor() {
  9377. this.id = { id: new bson_1.Binary((0, utils_1.uuidV4)(), bson_1.Binary.SUBTYPE_UUID) };
  9378. this.lastUse = (0, utils_1.now)();
  9379. this.txnNumber = 0;
  9380. this.isDirty = false;
  9381. }
  9382. /**
  9383. * Determines if the server session has timed out.
  9384. *
  9385. * @param sessionTimeoutMinutes - The server's "logicalSessionTimeoutMinutes"
  9386. */
  9387. hasTimedOut(sessionTimeoutMinutes) {
  9388. const idleTimeMinutes = Math.round((0, utils_1.calculateDurationInMs)(this.lastUse) % 864e5 % 36e5 / 6e4);
  9389. return idleTimeMinutes > sessionTimeoutMinutes - 1;
  9390. }
  9391. /**
  9392. * @internal
  9393. * Cloning meant to keep a readable reference to the server session data
  9394. * after ClientSession has ended
  9395. */
  9396. static clone(serverSession) {
  9397. const arrayBuffer = new ArrayBuffer(16);
  9398. const idBytes = Buffer.from(arrayBuffer);
  9399. idBytes.set(serverSession.id.id.buffer);
  9400. const id = new bson_1.Binary(idBytes, serverSession.id.id.sub_type);
  9401. return Object.setPrototypeOf({
  9402. id: { id },
  9403. lastUse: serverSession.lastUse,
  9404. txnNumber: serverSession.txnNumber,
  9405. isDirty: serverSession.isDirty
  9406. }, _ServerSession.prototype);
  9407. }
  9408. };
  9409. exports2.ServerSession = ServerSession;
  9410. var ServerSessionPool = class {
  9411. constructor(client) {
  9412. if (client == null) {
  9413. throw new error_1.MongoRuntimeError("ServerSessionPool requires a MongoClient");
  9414. }
  9415. this.client = client;
  9416. this.sessions = new utils_1.List();
  9417. }
  9418. /**
  9419. * Acquire a Server Session from the pool.
  9420. * Iterates through each session in the pool, removing any stale sessions
  9421. * along the way. The first non-stale session found is removed from the
  9422. * pool and returned. If no non-stale session is found, a new ServerSession is created.
  9423. */
  9424. acquire() {
  9425. var _a2, _b;
  9426. const sessionTimeoutMinutes = ((_a2 = this.client.topology) == null ? void 0 : _a2.logicalSessionTimeoutMinutes) ?? 10;
  9427. let session = null;
  9428. while (this.sessions.length > 0) {
  9429. const potentialSession = this.sessions.shift();
  9430. if (potentialSession != null && (!!((_b = this.client.topology) == null ? void 0 : _b.loadBalanced) || !potentialSession.hasTimedOut(sessionTimeoutMinutes))) {
  9431. session = potentialSession;
  9432. break;
  9433. }
  9434. }
  9435. if (session == null) {
  9436. session = new ServerSession();
  9437. }
  9438. return session;
  9439. }
  9440. /**
  9441. * Release a session to the session pool
  9442. * Adds the session back to the session pool if the session has not timed out yet.
  9443. * This method also removes any stale sessions from the pool.
  9444. *
  9445. * @param session - The session to release to the pool
  9446. */
  9447. release(session) {
  9448. var _a2, _b;
  9449. const sessionTimeoutMinutes = ((_a2 = this.client.topology) == null ? void 0 : _a2.logicalSessionTimeoutMinutes) ?? 10;
  9450. if (((_b = this.client.topology) == null ? void 0 : _b.loadBalanced) && !sessionTimeoutMinutes) {
  9451. this.sessions.unshift(session);
  9452. }
  9453. if (!sessionTimeoutMinutes) {
  9454. return;
  9455. }
  9456. this.sessions.prune((session2) => session2.hasTimedOut(sessionTimeoutMinutes));
  9457. if (!session.hasTimedOut(sessionTimeoutMinutes)) {
  9458. if (session.isDirty) {
  9459. return;
  9460. }
  9461. this.sessions.unshift(session);
  9462. }
  9463. }
  9464. };
  9465. exports2.ServerSessionPool = ServerSessionPool;
  9466. function applySession(session, command, options) {
  9467. var _a2, _b;
  9468. if (session.hasEnded) {
  9469. return new error_1.MongoExpiredSessionError();
  9470. }
  9471. const serverSession = session.serverSession;
  9472. if (serverSession == null) {
  9473. return new error_1.MongoRuntimeError("Unable to acquire server session");
  9474. }
  9475. if (((_a2 = options.writeConcern) == null ? void 0 : _a2.w) === 0) {
  9476. if (session && session.explicit) {
  9477. return new error_1.MongoAPIError("Cannot have explicit session with unacknowledged writes");
  9478. }
  9479. return;
  9480. }
  9481. serverSession.lastUse = (0, utils_1.now)();
  9482. command.lsid = serverSession.id;
  9483. const inTxnOrTxnCommand = session.inTransaction() || (0, transactions_1.isTransactionCommand)(command);
  9484. const isRetryableWrite = !!options.willRetryWrite;
  9485. if (isRetryableWrite || inTxnOrTxnCommand) {
  9486. serverSession.txnNumber += session[kTxnNumberIncrement];
  9487. session[kTxnNumberIncrement] = 0;
  9488. command.txnNumber = bson_1.Long.fromNumber(serverSession.txnNumber);
  9489. }
  9490. if (!inTxnOrTxnCommand) {
  9491. if (session.transaction.state !== transactions_1.TxnState.NO_TRANSACTION) {
  9492. session.transaction.transition(transactions_1.TxnState.NO_TRANSACTION);
  9493. }
  9494. if (session.supports.causalConsistency && session.operationTime && (0, utils_1.commandSupportsReadConcern)(command, options)) {
  9495. command.readConcern = command.readConcern || {};
  9496. Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
  9497. } else if (session[kSnapshotEnabled]) {
  9498. command.readConcern = command.readConcern || { level: read_concern_1.ReadConcernLevel.snapshot };
  9499. if (session[kSnapshotTime] != null) {
  9500. Object.assign(command.readConcern, { atClusterTime: session[kSnapshotTime] });
  9501. }
  9502. }
  9503. return;
  9504. }
  9505. command.autocommit = false;
  9506. if (session.transaction.state === transactions_1.TxnState.STARTING_TRANSACTION) {
  9507. session.transaction.transition(transactions_1.TxnState.TRANSACTION_IN_PROGRESS);
  9508. command.startTransaction = true;
  9509. const readConcern = session.transaction.options.readConcern || ((_b = session == null ? void 0 : session.clientOptions) == null ? void 0 : _b.readConcern);
  9510. if (readConcern) {
  9511. command.readConcern = readConcern;
  9512. }
  9513. if (session.supports.causalConsistency && session.operationTime) {
  9514. command.readConcern = command.readConcern || {};
  9515. Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
  9516. }
  9517. }
  9518. return;
  9519. }
  9520. exports2.applySession = applySession;
  9521. function updateSessionFromResponse(session, document) {
  9522. var _a2;
  9523. if (document.$clusterTime) {
  9524. (0, common_1._advanceClusterTime)(session, document.$clusterTime);
  9525. }
  9526. if (document.operationTime && session && session.supports.causalConsistency) {
  9527. session.advanceOperationTime(document.operationTime);
  9528. }
  9529. if (document.recoveryToken && session && session.inTransaction()) {
  9530. session.transaction._recoveryToken = document.recoveryToken;
  9531. }
  9532. if ((session == null ? void 0 : session[kSnapshotEnabled]) && session[kSnapshotTime] == null) {
  9533. const atClusterTime = ((_a2 = document.cursor) == null ? void 0 : _a2.atClusterTime) || document.atClusterTime;
  9534. if (atClusterTime) {
  9535. session[kSnapshotTime] = atClusterTime;
  9536. }
  9537. }
  9538. }
  9539. exports2.updateSessionFromResponse = updateSessionFromResponse;
  9540. }
  9541. });
  9542. // node_modules/mongodb/lib/cursor/abstract_cursor.js
  9543. var require_abstract_cursor = __commonJS({
  9544. "node_modules/mongodb/lib/cursor/abstract_cursor.js"(exports2) {
  9545. "use strict";
  9546. Object.defineProperty(exports2, "__esModule", { value: true });
  9547. exports2.assertUninitialized = exports2.AbstractCursor = exports2.CURSOR_FLAGS = void 0;
  9548. var stream_1 = require("stream");
  9549. var util_1 = require("util");
  9550. var bson_1 = require_bson2();
  9551. var error_1 = require_error();
  9552. var mongo_types_1 = require_mongo_types();
  9553. var execute_operation_1 = require_execute_operation();
  9554. var get_more_1 = require_get_more();
  9555. var kill_cursors_1 = require_kill_cursors();
  9556. var read_concern_1 = require_read_concern();
  9557. var read_preference_1 = require_read_preference();
  9558. var sessions_1 = require_sessions();
  9559. var utils_1 = require_utils();
  9560. var kId = Symbol("id");
  9561. var kDocuments = Symbol("documents");
  9562. var kServer = Symbol("server");
  9563. var kNamespace = Symbol("namespace");
  9564. var kClient = Symbol("client");
  9565. var kSession = Symbol("session");
  9566. var kOptions = Symbol("options");
  9567. var kTransform = Symbol("transform");
  9568. var kInitialized = Symbol("initialized");
  9569. var kClosed = Symbol("closed");
  9570. var kKilled = Symbol("killed");
  9571. var kInit = Symbol("kInit");
  9572. exports2.CURSOR_FLAGS = [
  9573. "tailable",
  9574. "oplogReplay",
  9575. "noCursorTimeout",
  9576. "awaitData",
  9577. "exhaust",
  9578. "partial"
  9579. ];
  9580. var AbstractCursor = class extends mongo_types_1.TypedEventEmitter {
  9581. /** @internal */
  9582. constructor(client, namespace, options = {}) {
  9583. super();
  9584. if (!client.s.isMongoClient) {
  9585. throw new error_1.MongoRuntimeError("Cursor must be constructed with MongoClient");
  9586. }
  9587. this[kClient] = client;
  9588. this[kNamespace] = namespace;
  9589. this[kId] = null;
  9590. this[kDocuments] = new utils_1.List();
  9591. this[kInitialized] = false;
  9592. this[kClosed] = false;
  9593. this[kKilled] = false;
  9594. this[kOptions] = {
  9595. readPreference: options.readPreference && options.readPreference instanceof read_preference_1.ReadPreference ? options.readPreference : read_preference_1.ReadPreference.primary,
  9596. ...(0, bson_1.pluckBSONSerializeOptions)(options)
  9597. };
  9598. const readConcern = read_concern_1.ReadConcern.fromOptions(options);
  9599. if (readConcern) {
  9600. this[kOptions].readConcern = readConcern;
  9601. }
  9602. if (typeof options.batchSize === "number") {
  9603. this[kOptions].batchSize = options.batchSize;
  9604. }
  9605. if (options.comment !== void 0) {
  9606. this[kOptions].comment = options.comment;
  9607. }
  9608. if (typeof options.maxTimeMS === "number") {
  9609. this[kOptions].maxTimeMS = options.maxTimeMS;
  9610. }
  9611. if (typeof options.maxAwaitTimeMS === "number") {
  9612. this[kOptions].maxAwaitTimeMS = options.maxAwaitTimeMS;
  9613. }
  9614. if (options.session instanceof sessions_1.ClientSession) {
  9615. this[kSession] = options.session;
  9616. } else {
  9617. this[kSession] = this[kClient].startSession({ owner: this, explicit: false });
  9618. }
  9619. }
  9620. get id() {
  9621. return this[kId] ?? void 0;
  9622. }
  9623. /** @internal */
  9624. get isDead() {
  9625. var _a;
  9626. return (((_a = this[kId]) == null ? void 0 : _a.isZero()) ?? false) || this[kClosed] || this[kKilled];
  9627. }
  9628. /** @internal */
  9629. get client() {
  9630. return this[kClient];
  9631. }
  9632. /** @internal */
  9633. get server() {
  9634. return this[kServer];
  9635. }
  9636. get namespace() {
  9637. return this[kNamespace];
  9638. }
  9639. get readPreference() {
  9640. return this[kOptions].readPreference;
  9641. }
  9642. get readConcern() {
  9643. return this[kOptions].readConcern;
  9644. }
  9645. /** @internal */
  9646. get session() {
  9647. return this[kSession];
  9648. }
  9649. set session(clientSession) {
  9650. this[kSession] = clientSession;
  9651. }
  9652. /** @internal */
  9653. get cursorOptions() {
  9654. return this[kOptions];
  9655. }
  9656. get closed() {
  9657. return this[kClosed];
  9658. }
  9659. get killed() {
  9660. return this[kKilled];
  9661. }
  9662. get loadBalanced() {
  9663. var _a;
  9664. return !!((_a = this[kClient].topology) == null ? void 0 : _a.loadBalanced);
  9665. }
  9666. /** Returns current buffered documents length */
  9667. bufferedCount() {
  9668. return this[kDocuments].length;
  9669. }
  9670. /** Returns current buffered documents */
  9671. readBufferedDocuments(number) {
  9672. const bufferedDocs = [];
  9673. const documentsToRead = Math.min(number ?? this[kDocuments].length, this[kDocuments].length);
  9674. for (let count = 0; count < documentsToRead; count++) {
  9675. const document = this[kDocuments].shift();
  9676. if (document != null) {
  9677. bufferedDocs.push(document);
  9678. }
  9679. }
  9680. return bufferedDocs;
  9681. }
  9682. async *[Symbol.asyncIterator]() {
  9683. if (this.closed) {
  9684. return;
  9685. }
  9686. try {
  9687. while (true) {
  9688. const document = await this.next();
  9689. if (document === null) {
  9690. if (!this.closed) {
  9691. const message = "Cursor returned a `null` document, but the cursor is not exhausted. Mapping documents to `null` is not supported in the cursor transform.";
  9692. await cleanupCursorAsync(this, { needsToEmitClosed: true }).catch(() => null);
  9693. throw new error_1.MongoAPIError(message);
  9694. }
  9695. break;
  9696. }
  9697. yield document;
  9698. if (this[kId] === bson_1.Long.ZERO) {
  9699. break;
  9700. }
  9701. }
  9702. } finally {
  9703. if (!this.closed) {
  9704. await this.close().catch(() => null);
  9705. }
  9706. }
  9707. }
  9708. stream(options) {
  9709. if (options == null ? void 0 : options.transform) {
  9710. const transform = options.transform;
  9711. const readable = new ReadableCursorStream(this);
  9712. return readable.pipe(new stream_1.Transform({
  9713. objectMode: true,
  9714. highWaterMark: 1,
  9715. transform(chunk, _, callback) {
  9716. try {
  9717. const transformed = transform(chunk);
  9718. callback(void 0, transformed);
  9719. } catch (err) {
  9720. callback(err);
  9721. }
  9722. }
  9723. }));
  9724. }
  9725. return new ReadableCursorStream(this);
  9726. }
  9727. async hasNext() {
  9728. if (this[kId] === bson_1.Long.ZERO) {
  9729. return false;
  9730. }
  9731. if (this[kDocuments].length !== 0) {
  9732. return true;
  9733. }
  9734. const doc = await next(this, { blocking: true, transform: false });
  9735. if (doc) {
  9736. this[kDocuments].unshift(doc);
  9737. return true;
  9738. }
  9739. return false;
  9740. }
  9741. /** Get the next available document from the cursor, returns null if no more documents are available. */
  9742. async next() {
  9743. if (this[kId] === bson_1.Long.ZERO) {
  9744. throw new error_1.MongoCursorExhaustedError();
  9745. }
  9746. return next(this, { blocking: true, transform: true });
  9747. }
  9748. /**
  9749. * Try to get the next available document from the cursor or `null` if an empty batch is returned
  9750. */
  9751. async tryNext() {
  9752. if (this[kId] === bson_1.Long.ZERO) {
  9753. throw new error_1.MongoCursorExhaustedError();
  9754. }
  9755. return next(this, { blocking: false, transform: true });
  9756. }
  9757. /**
  9758. * Iterates over all the documents for this cursor using the iterator, callback pattern.
  9759. *
  9760. * If the iterator returns `false`, iteration will stop.
  9761. *
  9762. * @param iterator - The iteration callback.
  9763. * @deprecated - Will be removed in a future release. Use for await...of instead.
  9764. */
  9765. async forEach(iterator) {
  9766. if (typeof iterator !== "function") {
  9767. throw new error_1.MongoInvalidArgumentError('Argument "iterator" must be a function');
  9768. }
  9769. for await (const document of this) {
  9770. const result = iterator(document);
  9771. if (result === false) {
  9772. break;
  9773. }
  9774. }
  9775. }
  9776. async close() {
  9777. const needsToEmitClosed = !this[kClosed];
  9778. this[kClosed] = true;
  9779. await cleanupCursorAsync(this, { needsToEmitClosed });
  9780. }
  9781. /**
  9782. * Returns an array of documents. The caller is responsible for making sure that there
  9783. * is enough memory to store the results. Note that the array only contains partial
  9784. * results when this cursor had been previously accessed. In that case,
  9785. * cursor.rewind() can be used to reset the cursor.
  9786. */
  9787. async toArray() {
  9788. const array = [];
  9789. for await (const document of this) {
  9790. array.push(document);
  9791. }
  9792. return array;
  9793. }
  9794. /**
  9795. * Add a cursor flag to the cursor
  9796. *
  9797. * @param flag - The flag to set, must be one of following ['tailable', 'oplogReplay', 'noCursorTimeout', 'awaitData', 'partial' -.
  9798. * @param value - The flag boolean value.
  9799. */
  9800. addCursorFlag(flag, value) {
  9801. assertUninitialized(this);
  9802. if (!exports2.CURSOR_FLAGS.includes(flag)) {
  9803. throw new error_1.MongoInvalidArgumentError(`Flag ${flag} is not one of ${exports2.CURSOR_FLAGS}`);
  9804. }
  9805. if (typeof value !== "boolean") {
  9806. throw new error_1.MongoInvalidArgumentError(`Flag ${flag} must be a boolean value`);
  9807. }
  9808. this[kOptions][flag] = value;
  9809. return this;
  9810. }
  9811. /**
  9812. * Map all documents using the provided function
  9813. * If there is a transform set on the cursor, that will be called first and the result passed to
  9814. * this function's transform.
  9815. *
  9816. * @remarks
  9817. *
  9818. * **Note** Cursors use `null` internally to indicate that there are no more documents in the cursor. Providing a mapping
  9819. * function that maps values to `null` will result in the cursor closing itself before it has finished iterating
  9820. * all documents. This will **not** result in a memory leak, just surprising behavior. For example:
  9821. *
  9822. * ```typescript
  9823. * const cursor = collection.find({});
  9824. * cursor.map(() => null);
  9825. *
  9826. * const documents = await cursor.toArray();
  9827. * // documents is always [], regardless of how many documents are in the collection.
  9828. * ```
  9829. *
  9830. * Other falsey values are allowed:
  9831. *
  9832. * ```typescript
  9833. * const cursor = collection.find({});
  9834. * cursor.map(() => '');
  9835. *
  9836. * const documents = await cursor.toArray();
  9837. * // documents is now an array of empty strings
  9838. * ```
  9839. *
  9840. * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
  9841. * it **does not** return a new instance of a cursor. This means when calling map,
  9842. * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
  9843. * Take note of the following example:
  9844. *
  9845. * @example
  9846. * ```typescript
  9847. * const cursor: FindCursor<Document> = coll.find();
  9848. * const mappedCursor: FindCursor<number> = cursor.map(doc => Object.keys(doc).length);
  9849. * const keyCounts: number[] = await mappedCursor.toArray(); // cursor.toArray() still returns Document[]
  9850. * ```
  9851. * @param transform - The mapping transformation method.
  9852. */
  9853. map(transform) {
  9854. assertUninitialized(this);
  9855. const oldTransform = this[kTransform];
  9856. if (oldTransform) {
  9857. this[kTransform] = (doc) => {
  9858. return transform(oldTransform(doc));
  9859. };
  9860. } else {
  9861. this[kTransform] = transform;
  9862. }
  9863. return this;
  9864. }
  9865. /**
  9866. * Set the ReadPreference for the cursor.
  9867. *
  9868. * @param readPreference - The new read preference for the cursor.
  9869. */
  9870. withReadPreference(readPreference) {
  9871. assertUninitialized(this);
  9872. if (readPreference instanceof read_preference_1.ReadPreference) {
  9873. this[kOptions].readPreference = readPreference;
  9874. } else if (typeof readPreference === "string") {
  9875. this[kOptions].readPreference = read_preference_1.ReadPreference.fromString(readPreference);
  9876. } else {
  9877. throw new error_1.MongoInvalidArgumentError(`Invalid read preference: ${readPreference}`);
  9878. }
  9879. return this;
  9880. }
  9881. /**
  9882. * Set the ReadPreference for the cursor.
  9883. *
  9884. * @param readPreference - The new read preference for the cursor.
  9885. */
  9886. withReadConcern(readConcern) {
  9887. assertUninitialized(this);
  9888. const resolvedReadConcern = read_concern_1.ReadConcern.fromOptions({ readConcern });
  9889. if (resolvedReadConcern) {
  9890. this[kOptions].readConcern = resolvedReadConcern;
  9891. }
  9892. return this;
  9893. }
  9894. /**
  9895. * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
  9896. *
  9897. * @param value - Number of milliseconds to wait before aborting the query.
  9898. */
  9899. maxTimeMS(value) {
  9900. assertUninitialized(this);
  9901. if (typeof value !== "number") {
  9902. throw new error_1.MongoInvalidArgumentError("Argument for maxTimeMS must be a number");
  9903. }
  9904. this[kOptions].maxTimeMS = value;
  9905. return this;
  9906. }
  9907. /**
  9908. * Set the batch size for the cursor.
  9909. *
  9910. * @param value - The number of documents to return per batch. See {@link https://www.mongodb.com/docs/manual/reference/command/find/|find command documentation}.
  9911. */
  9912. batchSize(value) {
  9913. assertUninitialized(this);
  9914. if (this[kOptions].tailable) {
  9915. throw new error_1.MongoTailableCursorError("Tailable cursor does not support batchSize");
  9916. }
  9917. if (typeof value !== "number") {
  9918. throw new error_1.MongoInvalidArgumentError('Operation "batchSize" requires an integer');
  9919. }
  9920. this[kOptions].batchSize = value;
  9921. return this;
  9922. }
  9923. /**
  9924. * Rewind this cursor to its uninitialized state. Any options that are present on the cursor will
  9925. * remain in effect. Iterating this cursor will cause new queries to be sent to the server, even
  9926. * if the resultant data has already been retrieved by this cursor.
  9927. */
  9928. rewind() {
  9929. if (!this[kInitialized]) {
  9930. return;
  9931. }
  9932. this[kId] = null;
  9933. this[kDocuments].clear();
  9934. this[kClosed] = false;
  9935. this[kKilled] = false;
  9936. this[kInitialized] = false;
  9937. const session = this[kSession];
  9938. if (session) {
  9939. if (session.explicit === false) {
  9940. if (!session.hasEnded) {
  9941. session.endSession().catch(() => null);
  9942. }
  9943. this[kSession] = this.client.startSession({ owner: this, explicit: false });
  9944. }
  9945. }
  9946. }
  9947. /** @internal */
  9948. _getMore(batchSize, callback) {
  9949. const getMoreOperation = new get_more_1.GetMoreOperation(this[kNamespace], this[kId], this[kServer], {
  9950. ...this[kOptions],
  9951. session: this[kSession],
  9952. batchSize
  9953. });
  9954. (0, execute_operation_1.executeOperation)(this[kClient], getMoreOperation, callback);
  9955. }
  9956. /**
  9957. * @internal
  9958. *
  9959. * This function is exposed for the unified test runner's createChangeStream
  9960. * operation. We cannot refactor to use the abstract _initialize method without
  9961. * a significant refactor.
  9962. */
  9963. [kInit](callback) {
  9964. this._initialize(this[kSession], (error, state) => {
  9965. if (state) {
  9966. const response = state.response;
  9967. this[kServer] = state.server;
  9968. if (response.cursor) {
  9969. this[kId] = typeof response.cursor.id === "number" ? bson_1.Long.fromNumber(response.cursor.id) : typeof response.cursor.id === "bigint" ? bson_1.Long.fromBigInt(response.cursor.id) : response.cursor.id;
  9970. if (response.cursor.ns) {
  9971. this[kNamespace] = (0, utils_1.ns)(response.cursor.ns);
  9972. }
  9973. this[kDocuments].pushMany(response.cursor.firstBatch);
  9974. }
  9975. if (this[kId] == null) {
  9976. this[kId] = bson_1.Long.ZERO;
  9977. this[kDocuments].push(state.response);
  9978. }
  9979. }
  9980. this[kInitialized] = true;
  9981. if (error) {
  9982. return cleanupCursor(this, { error }, () => callback(error, void 0));
  9983. }
  9984. if (this.isDead) {
  9985. return cleanupCursor(this, void 0, () => callback());
  9986. }
  9987. callback();
  9988. });
  9989. }
  9990. };
  9991. AbstractCursor.CLOSE = "close";
  9992. exports2.AbstractCursor = AbstractCursor;
  9993. async function next(cursor, { blocking, transform }) {
  9994. if (cursor.closed) {
  9995. return null;
  9996. }
  9997. do {
  9998. if (cursor[kId] == null) {
  9999. await (0, util_1.promisify)(cursor[kInit].bind(cursor))();
  10000. }
  10001. if (cursor[kDocuments].length !== 0) {
  10002. const doc = cursor[kDocuments].shift();
  10003. if (doc != null && transform && cursor[kTransform]) {
  10004. try {
  10005. return cursor[kTransform](doc);
  10006. } catch (error) {
  10007. await cleanupCursorAsync(cursor, { error, needsToEmitClosed: true }).catch(() => null);
  10008. throw error;
  10009. }
  10010. }
  10011. return doc;
  10012. }
  10013. if (cursor.isDead) {
  10014. await cleanupCursorAsync(cursor, {});
  10015. return null;
  10016. }
  10017. const batchSize = cursor[kOptions].batchSize || 1e3;
  10018. try {
  10019. const response = await (0, util_1.promisify)(cursor._getMore.bind(cursor))(batchSize);
  10020. if (response) {
  10021. const cursorId = typeof response.cursor.id === "number" ? bson_1.Long.fromNumber(response.cursor.id) : typeof response.cursor.id === "bigint" ? bson_1.Long.fromBigInt(response.cursor.id) : response.cursor.id;
  10022. cursor[kDocuments].pushMany(response.cursor.nextBatch);
  10023. cursor[kId] = cursorId;
  10024. }
  10025. } catch (error) {
  10026. await cleanupCursorAsync(cursor, { error }).catch(() => null);
  10027. throw error;
  10028. }
  10029. if (cursor.isDead) {
  10030. await cleanupCursorAsync(cursor, {});
  10031. }
  10032. if (cursor[kDocuments].length === 0 && blocking === false) {
  10033. return null;
  10034. }
  10035. } while (!cursor.isDead || cursor[kDocuments].length !== 0);
  10036. return null;
  10037. }
  10038. var cleanupCursorAsync = (0, util_1.promisify)(cleanupCursor);
  10039. function cleanupCursor(cursor, options, callback) {
  10040. const cursorId = cursor[kId];
  10041. const cursorNs = cursor[kNamespace];
  10042. const server = cursor[kServer];
  10043. const session = cursor[kSession];
  10044. const error = options == null ? void 0 : options.error;
  10045. const needsToEmitClosed = (options == null ? void 0 : options.needsToEmitClosed) ?? cursor[kDocuments].length === 0;
  10046. if (error) {
  10047. if (cursor.loadBalanced && error instanceof error_1.MongoNetworkError) {
  10048. return completeCleanup();
  10049. }
  10050. }
  10051. if (cursorId == null || server == null || cursorId.isZero() || cursorNs == null) {
  10052. if (needsToEmitClosed) {
  10053. cursor[kClosed] = true;
  10054. cursor[kId] = bson_1.Long.ZERO;
  10055. cursor.emit(AbstractCursor.CLOSE);
  10056. }
  10057. if (session) {
  10058. if (session.owner === cursor) {
  10059. session.endSession({ error }).finally(() => {
  10060. callback();
  10061. });
  10062. return;
  10063. }
  10064. if (!session.inTransaction()) {
  10065. (0, sessions_1.maybeClearPinnedConnection)(session, { error });
  10066. }
  10067. }
  10068. return callback();
  10069. }
  10070. function completeCleanup() {
  10071. if (session) {
  10072. if (session.owner === cursor) {
  10073. session.endSession({ error }).finally(() => {
  10074. cursor.emit(AbstractCursor.CLOSE);
  10075. callback();
  10076. });
  10077. return;
  10078. }
  10079. if (!session.inTransaction()) {
  10080. (0, sessions_1.maybeClearPinnedConnection)(session, { error });
  10081. }
  10082. }
  10083. cursor.emit(AbstractCursor.CLOSE);
  10084. return callback();
  10085. }
  10086. cursor[kKilled] = true;
  10087. if (session.hasEnded) {
  10088. return completeCleanup();
  10089. }
  10090. (0, execute_operation_1.executeOperation)(cursor[kClient], new kill_cursors_1.KillCursorsOperation(cursorId, cursorNs, server, { session })).catch(() => null).finally(completeCleanup);
  10091. }
  10092. function assertUninitialized(cursor) {
  10093. if (cursor[kInitialized]) {
  10094. throw new error_1.MongoCursorInUseError();
  10095. }
  10096. }
  10097. exports2.assertUninitialized = assertUninitialized;
  10098. var ReadableCursorStream = class extends stream_1.Readable {
  10099. constructor(cursor) {
  10100. super({
  10101. objectMode: true,
  10102. autoDestroy: false,
  10103. highWaterMark: 1
  10104. });
  10105. this._readInProgress = false;
  10106. this._cursor = cursor;
  10107. }
  10108. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  10109. _read(size) {
  10110. if (!this._readInProgress) {
  10111. this._readInProgress = true;
  10112. this._readNext();
  10113. }
  10114. }
  10115. _destroy(error, callback) {
  10116. this._cursor.close().then(() => callback(error), (closeError) => callback(closeError));
  10117. }
  10118. _readNext() {
  10119. next(this._cursor, { blocking: true, transform: true }).then((result) => {
  10120. if (result == null) {
  10121. this.push(null);
  10122. } else if (this.destroyed) {
  10123. this._cursor.close().catch(() => null);
  10124. } else {
  10125. if (this.push(result)) {
  10126. return this._readNext();
  10127. }
  10128. this._readInProgress = false;
  10129. }
  10130. }, (err) => {
  10131. if (err.message.match(/server is closed/)) {
  10132. this._cursor.close().catch(() => null);
  10133. return this.push(null);
  10134. }
  10135. if (err.message.match(/operation was interrupted/)) {
  10136. return this.push(null);
  10137. }
  10138. return this.destroy(err);
  10139. });
  10140. }
  10141. };
  10142. }
  10143. });
  10144. // node_modules/mongodb/lib/cursor/aggregation_cursor.js
  10145. var require_aggregation_cursor = __commonJS({
  10146. "node_modules/mongodb/lib/cursor/aggregation_cursor.js"(exports2) {
  10147. "use strict";
  10148. Object.defineProperty(exports2, "__esModule", { value: true });
  10149. exports2.AggregationCursor = void 0;
  10150. var aggregate_1 = require_aggregate();
  10151. var execute_operation_1 = require_execute_operation();
  10152. var utils_1 = require_utils();
  10153. var abstract_cursor_1 = require_abstract_cursor();
  10154. var kPipeline = Symbol("pipeline");
  10155. var kOptions = Symbol("options");
  10156. var AggregationCursor = class _AggregationCursor extends abstract_cursor_1.AbstractCursor {
  10157. /** @internal */
  10158. constructor(client, namespace, pipeline = [], options = {}) {
  10159. super(client, namespace, options);
  10160. this[kPipeline] = pipeline;
  10161. this[kOptions] = options;
  10162. }
  10163. get pipeline() {
  10164. return this[kPipeline];
  10165. }
  10166. clone() {
  10167. const clonedOptions = (0, utils_1.mergeOptions)({}, this[kOptions]);
  10168. delete clonedOptions.session;
  10169. return new _AggregationCursor(this.client, this.namespace, this[kPipeline], {
  10170. ...clonedOptions
  10171. });
  10172. }
  10173. map(transform) {
  10174. return super.map(transform);
  10175. }
  10176. /** @internal */
  10177. _initialize(session, callback) {
  10178. const aggregateOperation = new aggregate_1.AggregateOperation(this.namespace, this[kPipeline], {
  10179. ...this[kOptions],
  10180. ...this.cursorOptions,
  10181. session
  10182. });
  10183. (0, execute_operation_1.executeOperation)(this.client, aggregateOperation, (err, response) => {
  10184. if (err || response == null)
  10185. return callback(err);
  10186. callback(void 0, { server: aggregateOperation.server, session, response });
  10187. });
  10188. }
  10189. /** Execute the explain for the cursor */
  10190. async explain(verbosity) {
  10191. return (0, execute_operation_1.executeOperation)(this.client, new aggregate_1.AggregateOperation(this.namespace, this[kPipeline], {
  10192. ...this[kOptions],
  10193. ...this.cursorOptions,
  10194. explain: verbosity ?? true
  10195. }));
  10196. }
  10197. group($group) {
  10198. (0, abstract_cursor_1.assertUninitialized)(this);
  10199. this[kPipeline].push({ $group });
  10200. return this;
  10201. }
  10202. /** Add a limit stage to the aggregation pipeline */
  10203. limit($limit) {
  10204. (0, abstract_cursor_1.assertUninitialized)(this);
  10205. this[kPipeline].push({ $limit });
  10206. return this;
  10207. }
  10208. /** Add a match stage to the aggregation pipeline */
  10209. match($match) {
  10210. (0, abstract_cursor_1.assertUninitialized)(this);
  10211. this[kPipeline].push({ $match });
  10212. return this;
  10213. }
  10214. /** Add an out stage to the aggregation pipeline */
  10215. out($out) {
  10216. (0, abstract_cursor_1.assertUninitialized)(this);
  10217. this[kPipeline].push({ $out });
  10218. return this;
  10219. }
  10220. /**
  10221. * Add a project stage to the aggregation pipeline
  10222. *
  10223. * @remarks
  10224. * In order to strictly type this function you must provide an interface
  10225. * that represents the effect of your projection on the result documents.
  10226. *
  10227. * By default chaining a projection to your cursor changes the returned type to the generic {@link Document} type.
  10228. * You should specify a parameterized type to have assertions on your final results.
  10229. *
  10230. * @example
  10231. * ```typescript
  10232. * // Best way
  10233. * const docs: AggregationCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
  10234. * // Flexible way
  10235. * const docs: AggregationCursor<Document> = cursor.project({ _id: 0, a: true });
  10236. * ```
  10237. *
  10238. * @remarks
  10239. * In order to strictly type this function you must provide an interface
  10240. * that represents the effect of your projection on the result documents.
  10241. *
  10242. * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
  10243. * it **does not** return a new instance of a cursor. This means when calling project,
  10244. * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
  10245. * Take note of the following example:
  10246. *
  10247. * @example
  10248. * ```typescript
  10249. * const cursor: AggregationCursor<{ a: number; b: string }> = coll.aggregate([]);
  10250. * const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
  10251. * const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
  10252. *
  10253. * // or always use chaining and save the final cursor
  10254. *
  10255. * const cursor = coll.aggregate().project<{ a: string }>({
  10256. * _id: 0,
  10257. * a: { $convert: { input: '$a', to: 'string' }
  10258. * }});
  10259. * ```
  10260. */
  10261. project($project) {
  10262. (0, abstract_cursor_1.assertUninitialized)(this);
  10263. this[kPipeline].push({ $project });
  10264. return this;
  10265. }
  10266. /** Add a lookup stage to the aggregation pipeline */
  10267. lookup($lookup) {
  10268. (0, abstract_cursor_1.assertUninitialized)(this);
  10269. this[kPipeline].push({ $lookup });
  10270. return this;
  10271. }
  10272. /** Add a redact stage to the aggregation pipeline */
  10273. redact($redact) {
  10274. (0, abstract_cursor_1.assertUninitialized)(this);
  10275. this[kPipeline].push({ $redact });
  10276. return this;
  10277. }
  10278. /** Add a skip stage to the aggregation pipeline */
  10279. skip($skip) {
  10280. (0, abstract_cursor_1.assertUninitialized)(this);
  10281. this[kPipeline].push({ $skip });
  10282. return this;
  10283. }
  10284. /** Add a sort stage to the aggregation pipeline */
  10285. sort($sort) {
  10286. (0, abstract_cursor_1.assertUninitialized)(this);
  10287. this[kPipeline].push({ $sort });
  10288. return this;
  10289. }
  10290. /** Add a unwind stage to the aggregation pipeline */
  10291. unwind($unwind) {
  10292. (0, abstract_cursor_1.assertUninitialized)(this);
  10293. this[kPipeline].push({ $unwind });
  10294. return this;
  10295. }
  10296. /** Add a geoNear stage to the aggregation pipeline */
  10297. geoNear($geoNear) {
  10298. (0, abstract_cursor_1.assertUninitialized)(this);
  10299. this[kPipeline].push({ $geoNear });
  10300. return this;
  10301. }
  10302. };
  10303. exports2.AggregationCursor = AggregationCursor;
  10304. }
  10305. });
  10306. // node_modules/mongodb/lib/operations/count.js
  10307. var require_count = __commonJS({
  10308. "node_modules/mongodb/lib/operations/count.js"(exports2) {
  10309. "use strict";
  10310. Object.defineProperty(exports2, "__esModule", { value: true });
  10311. exports2.CountOperation = void 0;
  10312. var command_1 = require_command();
  10313. var operation_1 = require_operation();
  10314. var CountOperation = class extends command_1.CommandCallbackOperation {
  10315. constructor(namespace, filter, options) {
  10316. super({ s: { namespace } }, options);
  10317. this.options = options;
  10318. this.collectionName = namespace.collection;
  10319. this.query = filter;
  10320. }
  10321. executeCallback(server, session, callback) {
  10322. const options = this.options;
  10323. const cmd = {
  10324. count: this.collectionName,
  10325. query: this.query
  10326. };
  10327. if (typeof options.limit === "number") {
  10328. cmd.limit = options.limit;
  10329. }
  10330. if (typeof options.skip === "number") {
  10331. cmd.skip = options.skip;
  10332. }
  10333. if (options.hint != null) {
  10334. cmd.hint = options.hint;
  10335. }
  10336. if (typeof options.maxTimeMS === "number") {
  10337. cmd.maxTimeMS = options.maxTimeMS;
  10338. }
  10339. super.executeCommandCallback(server, session, cmd, (err, result) => {
  10340. callback(err, result ? result.n : 0);
  10341. });
  10342. }
  10343. };
  10344. exports2.CountOperation = CountOperation;
  10345. (0, operation_1.defineAspects)(CountOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE]);
  10346. }
  10347. });
  10348. // node_modules/mongodb/lib/sort.js
  10349. var require_sort = __commonJS({
  10350. "node_modules/mongodb/lib/sort.js"(exports2) {
  10351. "use strict";
  10352. Object.defineProperty(exports2, "__esModule", { value: true });
  10353. exports2.formatSort = void 0;
  10354. var error_1 = require_error();
  10355. function prepareDirection(direction = 1) {
  10356. const value = `${direction}`.toLowerCase();
  10357. if (isMeta(direction))
  10358. return direction;
  10359. switch (value) {
  10360. case "ascending":
  10361. case "asc":
  10362. case "1":
  10363. return 1;
  10364. case "descending":
  10365. case "desc":
  10366. case "-1":
  10367. return -1;
  10368. default:
  10369. throw new error_1.MongoInvalidArgumentError(`Invalid sort direction: ${JSON.stringify(direction)}`);
  10370. }
  10371. }
  10372. function isMeta(t) {
  10373. return typeof t === "object" && t != null && "$meta" in t && typeof t.$meta === "string";
  10374. }
  10375. function isPair(t) {
  10376. if (Array.isArray(t) && t.length === 2) {
  10377. try {
  10378. prepareDirection(t[1]);
  10379. return true;
  10380. } catch (e) {
  10381. return false;
  10382. }
  10383. }
  10384. return false;
  10385. }
  10386. function isDeep(t) {
  10387. return Array.isArray(t) && Array.isArray(t[0]);
  10388. }
  10389. function isMap(t) {
  10390. return t instanceof Map && t.size > 0;
  10391. }
  10392. function pairToMap(v) {
  10393. return /* @__PURE__ */ new Map([[`${v[0]}`, prepareDirection([v[1]])]]);
  10394. }
  10395. function deepToMap(t) {
  10396. const sortEntries = t.map(([k, v]) => [`${k}`, prepareDirection(v)]);
  10397. return new Map(sortEntries);
  10398. }
  10399. function stringsToMap(t) {
  10400. const sortEntries = t.map((key) => [`${key}`, 1]);
  10401. return new Map(sortEntries);
  10402. }
  10403. function objectToMap(t) {
  10404. const sortEntries = Object.entries(t).map(([k, v]) => [
  10405. `${k}`,
  10406. prepareDirection(v)
  10407. ]);
  10408. return new Map(sortEntries);
  10409. }
  10410. function mapToMap(t) {
  10411. const sortEntries = Array.from(t).map(([k, v]) => [
  10412. `${k}`,
  10413. prepareDirection(v)
  10414. ]);
  10415. return new Map(sortEntries);
  10416. }
  10417. function formatSort(sort, direction) {
  10418. if (sort == null)
  10419. return void 0;
  10420. if (typeof sort === "string")
  10421. return /* @__PURE__ */ new Map([[sort, prepareDirection(direction)]]);
  10422. if (typeof sort !== "object") {
  10423. throw new error_1.MongoInvalidArgumentError(`Invalid sort format: ${JSON.stringify(sort)} Sort must be a valid object`);
  10424. }
  10425. if (!Array.isArray(sort)) {
  10426. return isMap(sort) ? mapToMap(sort) : Object.keys(sort).length ? objectToMap(sort) : void 0;
  10427. }
  10428. if (!sort.length)
  10429. return void 0;
  10430. if (isDeep(sort))
  10431. return deepToMap(sort);
  10432. if (isPair(sort))
  10433. return pairToMap(sort);
  10434. return stringsToMap(sort);
  10435. }
  10436. exports2.formatSort = formatSort;
  10437. }
  10438. });
  10439. // node_modules/mongodb/lib/operations/find.js
  10440. var require_find = __commonJS({
  10441. "node_modules/mongodb/lib/operations/find.js"(exports2) {
  10442. "use strict";
  10443. Object.defineProperty(exports2, "__esModule", { value: true });
  10444. exports2.FindOperation = void 0;
  10445. var error_1 = require_error();
  10446. var read_concern_1 = require_read_concern();
  10447. var sort_1 = require_sort();
  10448. var utils_1 = require_utils();
  10449. var command_1 = require_command();
  10450. var operation_1 = require_operation();
  10451. var FindOperation = class extends command_1.CommandCallbackOperation {
  10452. constructor(collection, ns, filter = {}, options = {}) {
  10453. super(collection, options);
  10454. this.options = { ...options };
  10455. delete this.options.writeConcern;
  10456. this.ns = ns;
  10457. if (typeof filter !== "object" || Array.isArray(filter)) {
  10458. throw new error_1.MongoInvalidArgumentError("Query filter must be a plain object or ObjectId");
  10459. }
  10460. this.filter = filter != null && filter._bsontype === "ObjectId" ? { _id: filter } : filter;
  10461. }
  10462. executeCallback(server, session, callback) {
  10463. this.server = server;
  10464. const options = this.options;
  10465. let findCommand = makeFindCommand(this.ns, this.filter, options);
  10466. if (this.explain) {
  10467. findCommand = (0, utils_1.decorateWithExplain)(findCommand, this.explain);
  10468. }
  10469. server.command(this.ns, findCommand, {
  10470. ...this.options,
  10471. ...this.bsonOptions,
  10472. documentsReturnedIn: "firstBatch",
  10473. session
  10474. }, callback);
  10475. }
  10476. };
  10477. exports2.FindOperation = FindOperation;
  10478. function makeFindCommand(ns, filter, options) {
  10479. const findCommand = {
  10480. find: ns.collection,
  10481. filter
  10482. };
  10483. if (options.sort) {
  10484. findCommand.sort = (0, sort_1.formatSort)(options.sort);
  10485. }
  10486. if (options.projection) {
  10487. let projection = options.projection;
  10488. if (projection && Array.isArray(projection)) {
  10489. projection = projection.length ? projection.reduce((result, field) => {
  10490. result[field] = 1;
  10491. return result;
  10492. }, {}) : { _id: 1 };
  10493. }
  10494. findCommand.projection = projection;
  10495. }
  10496. if (options.hint) {
  10497. findCommand.hint = (0, utils_1.normalizeHintField)(options.hint);
  10498. }
  10499. if (typeof options.skip === "number") {
  10500. findCommand.skip = options.skip;
  10501. }
  10502. if (typeof options.limit === "number") {
  10503. if (options.limit < 0) {
  10504. findCommand.limit = -options.limit;
  10505. findCommand.singleBatch = true;
  10506. } else {
  10507. findCommand.limit = options.limit;
  10508. }
  10509. }
  10510. if (typeof options.batchSize === "number") {
  10511. if (options.batchSize < 0) {
  10512. if (options.limit && options.limit !== 0 && Math.abs(options.batchSize) < Math.abs(options.limit)) {
  10513. findCommand.limit = -options.batchSize;
  10514. }
  10515. findCommand.singleBatch = true;
  10516. } else {
  10517. findCommand.batchSize = options.batchSize;
  10518. }
  10519. }
  10520. if (typeof options.singleBatch === "boolean") {
  10521. findCommand.singleBatch = options.singleBatch;
  10522. }
  10523. if (options.comment !== void 0) {
  10524. findCommand.comment = options.comment;
  10525. }
  10526. if (typeof options.maxTimeMS === "number") {
  10527. findCommand.maxTimeMS = options.maxTimeMS;
  10528. }
  10529. const readConcern = read_concern_1.ReadConcern.fromOptions(options);
  10530. if (readConcern) {
  10531. findCommand.readConcern = readConcern.toJSON();
  10532. }
  10533. if (options.max) {
  10534. findCommand.max = options.max;
  10535. }
  10536. if (options.min) {
  10537. findCommand.min = options.min;
  10538. }
  10539. if (typeof options.returnKey === "boolean") {
  10540. findCommand.returnKey = options.returnKey;
  10541. }
  10542. if (typeof options.showRecordId === "boolean") {
  10543. findCommand.showRecordId = options.showRecordId;
  10544. }
  10545. if (typeof options.tailable === "boolean") {
  10546. findCommand.tailable = options.tailable;
  10547. }
  10548. if (typeof options.oplogReplay === "boolean") {
  10549. findCommand.oplogReplay = options.oplogReplay;
  10550. }
  10551. if (typeof options.timeout === "boolean") {
  10552. findCommand.noCursorTimeout = !options.timeout;
  10553. } else if (typeof options.noCursorTimeout === "boolean") {
  10554. findCommand.noCursorTimeout = options.noCursorTimeout;
  10555. }
  10556. if (typeof options.awaitData === "boolean") {
  10557. findCommand.awaitData = options.awaitData;
  10558. }
  10559. if (typeof options.allowPartialResults === "boolean") {
  10560. findCommand.allowPartialResults = options.allowPartialResults;
  10561. }
  10562. if (options.collation) {
  10563. findCommand.collation = options.collation;
  10564. }
  10565. if (typeof options.allowDiskUse === "boolean") {
  10566. findCommand.allowDiskUse = options.allowDiskUse;
  10567. }
  10568. if (options.let) {
  10569. findCommand.let = options.let;
  10570. }
  10571. return findCommand;
  10572. }
  10573. (0, operation_1.defineAspects)(FindOperation, [
  10574. operation_1.Aspect.READ_OPERATION,
  10575. operation_1.Aspect.RETRYABLE,
  10576. operation_1.Aspect.EXPLAINABLE,
  10577. operation_1.Aspect.CURSOR_CREATING
  10578. ]);
  10579. }
  10580. });
  10581. // node_modules/mongodb/lib/cursor/find_cursor.js
  10582. var require_find_cursor = __commonJS({
  10583. "node_modules/mongodb/lib/cursor/find_cursor.js"(exports2) {
  10584. "use strict";
  10585. Object.defineProperty(exports2, "__esModule", { value: true });
  10586. exports2.FindCursor = exports2.FLAGS = void 0;
  10587. var bson_1 = require_bson2();
  10588. var error_1 = require_error();
  10589. var count_1 = require_count();
  10590. var execute_operation_1 = require_execute_operation();
  10591. var find_1 = require_find();
  10592. var sort_1 = require_sort();
  10593. var utils_1 = require_utils();
  10594. var abstract_cursor_1 = require_abstract_cursor();
  10595. var kFilter = Symbol("filter");
  10596. var kNumReturned = Symbol("numReturned");
  10597. var kBuiltOptions = Symbol("builtOptions");
  10598. exports2.FLAGS = [
  10599. "tailable",
  10600. "oplogReplay",
  10601. "noCursorTimeout",
  10602. "awaitData",
  10603. "exhaust",
  10604. "partial"
  10605. ];
  10606. var FindCursor = class _FindCursor extends abstract_cursor_1.AbstractCursor {
  10607. /** @internal */
  10608. constructor(client, namespace, filter = {}, options = {}) {
  10609. super(client, namespace, options);
  10610. this[kFilter] = filter;
  10611. this[kBuiltOptions] = options;
  10612. if (options.sort != null) {
  10613. this[kBuiltOptions].sort = (0, sort_1.formatSort)(options.sort);
  10614. }
  10615. }
  10616. clone() {
  10617. const clonedOptions = (0, utils_1.mergeOptions)({}, this[kBuiltOptions]);
  10618. delete clonedOptions.session;
  10619. return new _FindCursor(this.client, this.namespace, this[kFilter], {
  10620. ...clonedOptions
  10621. });
  10622. }
  10623. map(transform) {
  10624. return super.map(transform);
  10625. }
  10626. /** @internal */
  10627. _initialize(session, callback) {
  10628. const findOperation = new find_1.FindOperation(void 0, this.namespace, this[kFilter], {
  10629. ...this[kBuiltOptions],
  10630. ...this.cursorOptions,
  10631. session
  10632. });
  10633. (0, execute_operation_1.executeOperation)(this.client, findOperation, (err, response) => {
  10634. if (err || response == null)
  10635. return callback(err);
  10636. if (response.cursor) {
  10637. this[kNumReturned] = response.cursor.firstBatch.length;
  10638. } else {
  10639. this[kNumReturned] = response.documents ? response.documents.length : 0;
  10640. }
  10641. callback(void 0, { server: findOperation.server, session, response });
  10642. });
  10643. }
  10644. /** @internal */
  10645. _getMore(batchSize, callback) {
  10646. const numReturned = this[kNumReturned];
  10647. if (numReturned) {
  10648. const limit = this[kBuiltOptions].limit;
  10649. batchSize = limit && limit > 0 && numReturned + batchSize > limit ? limit - numReturned : batchSize;
  10650. if (batchSize <= 0) {
  10651. this.close().finally(() => callback(void 0, { cursor: { id: bson_1.Long.ZERO, nextBatch: [] } }));
  10652. return;
  10653. }
  10654. }
  10655. super._getMore(batchSize, (err, response) => {
  10656. if (err)
  10657. return callback(err);
  10658. if (response) {
  10659. this[kNumReturned] = this[kNumReturned] + response.cursor.nextBatch.length;
  10660. }
  10661. callback(void 0, response);
  10662. });
  10663. }
  10664. /**
  10665. * Get the count of documents for this cursor
  10666. * @deprecated Use `collection.estimatedDocumentCount` or `collection.countDocuments` instead
  10667. */
  10668. async count(options) {
  10669. (0, utils_1.emitWarningOnce)("cursor.count is deprecated and will be removed in the next major version, please use `collection.estimatedDocumentCount` or `collection.countDocuments` instead ");
  10670. if (typeof options === "boolean") {
  10671. throw new error_1.MongoInvalidArgumentError("Invalid first parameter to count");
  10672. }
  10673. return (0, execute_operation_1.executeOperation)(this.client, new count_1.CountOperation(this.namespace, this[kFilter], {
  10674. ...this[kBuiltOptions],
  10675. ...this.cursorOptions,
  10676. ...options
  10677. }));
  10678. }
  10679. /** Execute the explain for the cursor */
  10680. async explain(verbosity) {
  10681. return (0, execute_operation_1.executeOperation)(this.client, new find_1.FindOperation(void 0, this.namespace, this[kFilter], {
  10682. ...this[kBuiltOptions],
  10683. ...this.cursorOptions,
  10684. explain: verbosity ?? true
  10685. }));
  10686. }
  10687. /** Set the cursor query */
  10688. filter(filter) {
  10689. (0, abstract_cursor_1.assertUninitialized)(this);
  10690. this[kFilter] = filter;
  10691. return this;
  10692. }
  10693. /**
  10694. * Set the cursor hint
  10695. *
  10696. * @param hint - If specified, then the query system will only consider plans using the hinted index.
  10697. */
  10698. hint(hint) {
  10699. (0, abstract_cursor_1.assertUninitialized)(this);
  10700. this[kBuiltOptions].hint = hint;
  10701. return this;
  10702. }
  10703. /**
  10704. * Set the cursor min
  10705. *
  10706. * @param min - Specify a $min value to specify the inclusive lower bound for a specific index in order to constrain the results of find(). The $min specifies the lower bound for all keys of a specific index in order.
  10707. */
  10708. min(min) {
  10709. (0, abstract_cursor_1.assertUninitialized)(this);
  10710. this[kBuiltOptions].min = min;
  10711. return this;
  10712. }
  10713. /**
  10714. * Set the cursor max
  10715. *
  10716. * @param max - Specify a $max value to specify the exclusive upper bound for a specific index in order to constrain the results of find(). The $max specifies the upper bound for all keys of a specific index in order.
  10717. */
  10718. max(max) {
  10719. (0, abstract_cursor_1.assertUninitialized)(this);
  10720. this[kBuiltOptions].max = max;
  10721. return this;
  10722. }
  10723. /**
  10724. * Set the cursor returnKey.
  10725. * If set to true, modifies the cursor to only return the index field or fields for the results of the query, rather than documents.
  10726. * If set to true and the query does not use an index to perform the read operation, the returned documents will not contain any fields.
  10727. *
  10728. * @param value - the returnKey value.
  10729. */
  10730. returnKey(value) {
  10731. (0, abstract_cursor_1.assertUninitialized)(this);
  10732. this[kBuiltOptions].returnKey = value;
  10733. return this;
  10734. }
  10735. /**
  10736. * Modifies the output of a query by adding a field $recordId to matching documents. $recordId is the internal key which uniquely identifies a document in a collection.
  10737. *
  10738. * @param value - The $showDiskLoc option has now been deprecated and replaced with the showRecordId field. $showDiskLoc will still be accepted for OP_QUERY stye find.
  10739. */
  10740. showRecordId(value) {
  10741. (0, abstract_cursor_1.assertUninitialized)(this);
  10742. this[kBuiltOptions].showRecordId = value;
  10743. return this;
  10744. }
  10745. /**
  10746. * Add a query modifier to the cursor query
  10747. *
  10748. * @param name - The query modifier (must start with $, such as $orderby etc)
  10749. * @param value - The modifier value.
  10750. */
  10751. addQueryModifier(name, value) {
  10752. (0, abstract_cursor_1.assertUninitialized)(this);
  10753. if (name[0] !== "$") {
  10754. throw new error_1.MongoInvalidArgumentError(`${name} is not a valid query modifier`);
  10755. }
  10756. const field = name.substr(1);
  10757. switch (field) {
  10758. case "comment":
  10759. this[kBuiltOptions].comment = value;
  10760. break;
  10761. case "explain":
  10762. this[kBuiltOptions].explain = value;
  10763. break;
  10764. case "hint":
  10765. this[kBuiltOptions].hint = value;
  10766. break;
  10767. case "max":
  10768. this[kBuiltOptions].max = value;
  10769. break;
  10770. case "maxTimeMS":
  10771. this[kBuiltOptions].maxTimeMS = value;
  10772. break;
  10773. case "min":
  10774. this[kBuiltOptions].min = value;
  10775. break;
  10776. case "orderby":
  10777. this[kBuiltOptions].sort = (0, sort_1.formatSort)(value);
  10778. break;
  10779. case "query":
  10780. this[kFilter] = value;
  10781. break;
  10782. case "returnKey":
  10783. this[kBuiltOptions].returnKey = value;
  10784. break;
  10785. case "showDiskLoc":
  10786. this[kBuiltOptions].showRecordId = value;
  10787. break;
  10788. default:
  10789. throw new error_1.MongoInvalidArgumentError(`Invalid query modifier: ${name}`);
  10790. }
  10791. return this;
  10792. }
  10793. /**
  10794. * Add a comment to the cursor query allowing for tracking the comment in the log.
  10795. *
  10796. * @param value - The comment attached to this query.
  10797. */
  10798. comment(value) {
  10799. (0, abstract_cursor_1.assertUninitialized)(this);
  10800. this[kBuiltOptions].comment = value;
  10801. return this;
  10802. }
  10803. /**
  10804. * Set a maxAwaitTimeMS on a tailing cursor query to allow to customize the timeout value for the option awaitData (Only supported on MongoDB 3.2 or higher, ignored otherwise)
  10805. *
  10806. * @param value - Number of milliseconds to wait before aborting the tailed query.
  10807. */
  10808. maxAwaitTimeMS(value) {
  10809. (0, abstract_cursor_1.assertUninitialized)(this);
  10810. if (typeof value !== "number") {
  10811. throw new error_1.MongoInvalidArgumentError("Argument for maxAwaitTimeMS must be a number");
  10812. }
  10813. this[kBuiltOptions].maxAwaitTimeMS = value;
  10814. return this;
  10815. }
  10816. /**
  10817. * Set a maxTimeMS on the cursor query, allowing for hard timeout limits on queries (Only supported on MongoDB 2.6 or higher)
  10818. *
  10819. * @param value - Number of milliseconds to wait before aborting the query.
  10820. */
  10821. maxTimeMS(value) {
  10822. (0, abstract_cursor_1.assertUninitialized)(this);
  10823. if (typeof value !== "number") {
  10824. throw new error_1.MongoInvalidArgumentError("Argument for maxTimeMS must be a number");
  10825. }
  10826. this[kBuiltOptions].maxTimeMS = value;
  10827. return this;
  10828. }
  10829. /**
  10830. * Add a project stage to the aggregation pipeline
  10831. *
  10832. * @remarks
  10833. * In order to strictly type this function you must provide an interface
  10834. * that represents the effect of your projection on the result documents.
  10835. *
  10836. * By default chaining a projection to your cursor changes the returned type to the generic
  10837. * {@link Document} type.
  10838. * You should specify a parameterized type to have assertions on your final results.
  10839. *
  10840. * @example
  10841. * ```typescript
  10842. * // Best way
  10843. * const docs: FindCursor<{ a: number }> = cursor.project<{ a: number }>({ _id: 0, a: true });
  10844. * // Flexible way
  10845. * const docs: FindCursor<Document> = cursor.project({ _id: 0, a: true });
  10846. * ```
  10847. *
  10848. * @remarks
  10849. *
  10850. * **Note for Typescript Users:** adding a transform changes the return type of the iteration of this cursor,
  10851. * it **does not** return a new instance of a cursor. This means when calling project,
  10852. * you should always assign the result to a new variable in order to get a correctly typed cursor variable.
  10853. * Take note of the following example:
  10854. *
  10855. * @example
  10856. * ```typescript
  10857. * const cursor: FindCursor<{ a: number; b: string }> = coll.find();
  10858. * const projectCursor = cursor.project<{ a: number }>({ _id: 0, a: true });
  10859. * const aPropOnlyArray: {a: number}[] = await projectCursor.toArray();
  10860. *
  10861. * // or always use chaining and save the final cursor
  10862. *
  10863. * const cursor = coll.find().project<{ a: string }>({
  10864. * _id: 0,
  10865. * a: { $convert: { input: '$a', to: 'string' }
  10866. * }});
  10867. * ```
  10868. */
  10869. project(value) {
  10870. (0, abstract_cursor_1.assertUninitialized)(this);
  10871. this[kBuiltOptions].projection = value;
  10872. return this;
  10873. }
  10874. /**
  10875. * Sets the sort order of the cursor query.
  10876. *
  10877. * @param sort - The key or keys set for the sort.
  10878. * @param direction - The direction of the sorting (1 or -1).
  10879. */
  10880. sort(sort, direction) {
  10881. (0, abstract_cursor_1.assertUninitialized)(this);
  10882. if (this[kBuiltOptions].tailable) {
  10883. throw new error_1.MongoTailableCursorError("Tailable cursor does not support sorting");
  10884. }
  10885. this[kBuiltOptions].sort = (0, sort_1.formatSort)(sort, direction);
  10886. return this;
  10887. }
  10888. /**
  10889. * Allows disk use for blocking sort operations exceeding 100MB memory. (MongoDB 3.2 or higher)
  10890. *
  10891. * @remarks
  10892. * {@link https://www.mongodb.com/docs/manual/reference/command/find/#find-cmd-allowdiskuse | find command allowDiskUse documentation}
  10893. */
  10894. allowDiskUse(allow = true) {
  10895. (0, abstract_cursor_1.assertUninitialized)(this);
  10896. if (!this[kBuiltOptions].sort) {
  10897. throw new error_1.MongoInvalidArgumentError('Option "allowDiskUse" requires a sort specification');
  10898. }
  10899. if (!allow) {
  10900. this[kBuiltOptions].allowDiskUse = false;
  10901. return this;
  10902. }
  10903. this[kBuiltOptions].allowDiskUse = true;
  10904. return this;
  10905. }
  10906. /**
  10907. * Set the collation options for the cursor.
  10908. *
  10909. * @param value - The cursor collation options (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
  10910. */
  10911. collation(value) {
  10912. (0, abstract_cursor_1.assertUninitialized)(this);
  10913. this[kBuiltOptions].collation = value;
  10914. return this;
  10915. }
  10916. /**
  10917. * Set the limit for the cursor.
  10918. *
  10919. * @param value - The limit for the cursor query.
  10920. */
  10921. limit(value) {
  10922. (0, abstract_cursor_1.assertUninitialized)(this);
  10923. if (this[kBuiltOptions].tailable) {
  10924. throw new error_1.MongoTailableCursorError("Tailable cursor does not support limit");
  10925. }
  10926. if (typeof value !== "number") {
  10927. throw new error_1.MongoInvalidArgumentError('Operation "limit" requires an integer');
  10928. }
  10929. this[kBuiltOptions].limit = value;
  10930. return this;
  10931. }
  10932. /**
  10933. * Set the skip for the cursor.
  10934. *
  10935. * @param value - The skip for the cursor query.
  10936. */
  10937. skip(value) {
  10938. (0, abstract_cursor_1.assertUninitialized)(this);
  10939. if (this[kBuiltOptions].tailable) {
  10940. throw new error_1.MongoTailableCursorError("Tailable cursor does not support skip");
  10941. }
  10942. if (typeof value !== "number") {
  10943. throw new error_1.MongoInvalidArgumentError('Operation "skip" requires an integer');
  10944. }
  10945. this[kBuiltOptions].skip = value;
  10946. return this;
  10947. }
  10948. };
  10949. exports2.FindCursor = FindCursor;
  10950. }
  10951. });
  10952. // node_modules/mongodb/lib/operations/indexes.js
  10953. var require_indexes = __commonJS({
  10954. "node_modules/mongodb/lib/operations/indexes.js"(exports2) {
  10955. "use strict";
  10956. Object.defineProperty(exports2, "__esModule", { value: true });
  10957. exports2.IndexInformationOperation = exports2.IndexExistsOperation = exports2.ListIndexesOperation = exports2.DropIndexesOperation = exports2.DropIndexOperation = exports2.EnsureIndexOperation = exports2.CreateIndexOperation = exports2.CreateIndexesOperation = exports2.IndexesOperation = void 0;
  10958. var error_1 = require_error();
  10959. var read_preference_1 = require_read_preference();
  10960. var utils_1 = require_utils();
  10961. var command_1 = require_command();
  10962. var common_functions_1 = require_common_functions();
  10963. var operation_1 = require_operation();
  10964. var VALID_INDEX_OPTIONS = /* @__PURE__ */ new Set([
  10965. "background",
  10966. "unique",
  10967. "name",
  10968. "partialFilterExpression",
  10969. "sparse",
  10970. "hidden",
  10971. "expireAfterSeconds",
  10972. "storageEngine",
  10973. "collation",
  10974. "version",
  10975. // text indexes
  10976. "weights",
  10977. "default_language",
  10978. "language_override",
  10979. "textIndexVersion",
  10980. // 2d-sphere indexes
  10981. "2dsphereIndexVersion",
  10982. // 2d indexes
  10983. "bits",
  10984. "min",
  10985. "max",
  10986. // geoHaystack Indexes
  10987. "bucketSize",
  10988. // wildcard indexes
  10989. "wildcardProjection"
  10990. ]);
  10991. function isIndexDirection(x) {
  10992. return typeof x === "number" || x === "2d" || x === "2dsphere" || x === "text" || x === "geoHaystack";
  10993. }
  10994. function isSingleIndexTuple(t) {
  10995. return Array.isArray(t) && t.length === 2 && isIndexDirection(t[1]);
  10996. }
  10997. function makeIndexSpec(indexSpec, options) {
  10998. const key = /* @__PURE__ */ new Map();
  10999. const indexSpecs = !Array.isArray(indexSpec) || isSingleIndexTuple(indexSpec) ? [indexSpec] : indexSpec;
  11000. for (const spec of indexSpecs) {
  11001. if (typeof spec === "string") {
  11002. key.set(spec, 1);
  11003. } else if (Array.isArray(spec)) {
  11004. key.set(spec[0], spec[1] ?? 1);
  11005. } else if (spec instanceof Map) {
  11006. for (const [property, value] of spec) {
  11007. key.set(property, value);
  11008. }
  11009. } else if ((0, utils_1.isObject)(spec)) {
  11010. for (const [property, value] of Object.entries(spec)) {
  11011. key.set(property, value);
  11012. }
  11013. }
  11014. }
  11015. return { ...options, key };
  11016. }
  11017. var IndexesOperation = class extends operation_1.AbstractCallbackOperation {
  11018. constructor(collection, options) {
  11019. super(options);
  11020. this.options = options;
  11021. this.collection = collection;
  11022. }
  11023. executeCallback(server, session, callback) {
  11024. const coll = this.collection;
  11025. const options = this.options;
  11026. (0, common_functions_1.indexInformation)(coll.s.db, coll.collectionName, { full: true, ...options, readPreference: this.readPreference, session }, callback);
  11027. }
  11028. };
  11029. exports2.IndexesOperation = IndexesOperation;
  11030. var CreateIndexesOperation = class extends command_1.CommandCallbackOperation {
  11031. constructor(parent, collectionName, indexes, options) {
  11032. super(parent, options);
  11033. this.options = options ?? {};
  11034. this.collectionName = collectionName;
  11035. this.indexes = indexes.map((userIndex) => {
  11036. const key = userIndex.key instanceof Map ? userIndex.key : new Map(Object.entries(userIndex.key));
  11037. const name = userIndex.name != null ? userIndex.name : Array.from(key).flat().join("_");
  11038. const validIndexOptions = Object.fromEntries(Object.entries({ ...userIndex }).filter(([optionName]) => VALID_INDEX_OPTIONS.has(optionName)));
  11039. return {
  11040. ...validIndexOptions,
  11041. name,
  11042. key
  11043. };
  11044. });
  11045. }
  11046. executeCallback(server, session, callback) {
  11047. const options = this.options;
  11048. const indexes = this.indexes;
  11049. const serverWireVersion = (0, utils_1.maxWireVersion)(server);
  11050. const cmd = { createIndexes: this.collectionName, indexes };
  11051. if (options.commitQuorum != null) {
  11052. if (serverWireVersion < 9) {
  11053. callback(new error_1.MongoCompatibilityError("Option `commitQuorum` for `createIndexes` not supported on servers < 4.4"));
  11054. return;
  11055. }
  11056. cmd.commitQuorum = options.commitQuorum;
  11057. }
  11058. this.options.collation = void 0;
  11059. super.executeCommandCallback(server, session, cmd, (err) => {
  11060. if (err) {
  11061. callback(err);
  11062. return;
  11063. }
  11064. const indexNames = indexes.map((index) => index.name || "");
  11065. callback(void 0, indexNames);
  11066. });
  11067. }
  11068. };
  11069. exports2.CreateIndexesOperation = CreateIndexesOperation;
  11070. var CreateIndexOperation = class extends CreateIndexesOperation {
  11071. constructor(parent, collectionName, indexSpec, options) {
  11072. super(parent, collectionName, [makeIndexSpec(indexSpec, options)], options);
  11073. }
  11074. executeCallback(server, session, callback) {
  11075. super.executeCallback(server, session, (err, indexNames) => {
  11076. if (err || !indexNames)
  11077. return callback(err);
  11078. return callback(void 0, indexNames[0]);
  11079. });
  11080. }
  11081. };
  11082. exports2.CreateIndexOperation = CreateIndexOperation;
  11083. var EnsureIndexOperation = class extends CreateIndexOperation {
  11084. constructor(db, collectionName, indexSpec, options) {
  11085. super(db, collectionName, indexSpec, options);
  11086. this.readPreference = read_preference_1.ReadPreference.primary;
  11087. this.db = db;
  11088. this.collectionName = collectionName;
  11089. }
  11090. executeCallback(server, session, callback) {
  11091. const indexName = this.indexes[0].name;
  11092. const cursor = this.db.collection(this.collectionName).listIndexes({ session });
  11093. cursor.toArray().then((indexes) => {
  11094. indexes = Array.isArray(indexes) ? indexes : [indexes];
  11095. if (indexes.some((index) => index.name === indexName)) {
  11096. callback(void 0, indexName);
  11097. return;
  11098. }
  11099. super.executeCallback(server, session, callback);
  11100. }, (error) => {
  11101. if (error instanceof error_1.MongoError && error.code === error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
  11102. return super.executeCallback(server, session, callback);
  11103. }
  11104. return callback(error);
  11105. });
  11106. }
  11107. };
  11108. exports2.EnsureIndexOperation = EnsureIndexOperation;
  11109. var DropIndexOperation = class extends command_1.CommandCallbackOperation {
  11110. constructor(collection, indexName, options) {
  11111. super(collection, options);
  11112. this.options = options ?? {};
  11113. this.collection = collection;
  11114. this.indexName = indexName;
  11115. }
  11116. executeCallback(server, session, callback) {
  11117. const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
  11118. super.executeCommandCallback(server, session, cmd, callback);
  11119. }
  11120. };
  11121. exports2.DropIndexOperation = DropIndexOperation;
  11122. var DropIndexesOperation = class extends DropIndexOperation {
  11123. constructor(collection, options) {
  11124. super(collection, "*", options);
  11125. }
  11126. executeCallback(server, session, callback) {
  11127. super.executeCallback(server, session, (err) => {
  11128. if (err)
  11129. return callback(err, false);
  11130. callback(void 0, true);
  11131. });
  11132. }
  11133. };
  11134. exports2.DropIndexesOperation = DropIndexesOperation;
  11135. var ListIndexesOperation = class extends command_1.CommandCallbackOperation {
  11136. constructor(collection, options) {
  11137. super(collection, options);
  11138. this.options = { ...options };
  11139. delete this.options.writeConcern;
  11140. this.collectionNamespace = collection.s.namespace;
  11141. }
  11142. executeCallback(server, session, callback) {
  11143. const serverWireVersion = (0, utils_1.maxWireVersion)(server);
  11144. const cursor = this.options.batchSize ? { batchSize: this.options.batchSize } : {};
  11145. const command = { listIndexes: this.collectionNamespace.collection, cursor };
  11146. if (serverWireVersion >= 9 && this.options.comment !== void 0) {
  11147. command.comment = this.options.comment;
  11148. }
  11149. super.executeCommandCallback(server, session, command, callback);
  11150. }
  11151. };
  11152. exports2.ListIndexesOperation = ListIndexesOperation;
  11153. var IndexExistsOperation = class extends operation_1.AbstractCallbackOperation {
  11154. constructor(collection, indexes, options) {
  11155. super(options);
  11156. this.options = options;
  11157. this.collection = collection;
  11158. this.indexes = indexes;
  11159. }
  11160. executeCallback(server, session, callback) {
  11161. const coll = this.collection;
  11162. const indexes = this.indexes;
  11163. (0, common_functions_1.indexInformation)(coll.s.db, coll.collectionName, { ...this.options, readPreference: this.readPreference, session }, (err, indexInformation) => {
  11164. if (err != null)
  11165. return callback(err);
  11166. if (!Array.isArray(indexes))
  11167. return callback(void 0, indexInformation[indexes] != null);
  11168. for (let i = 0; i < indexes.length; i++) {
  11169. if (indexInformation[indexes[i]] == null) {
  11170. return callback(void 0, false);
  11171. }
  11172. }
  11173. return callback(void 0, true);
  11174. });
  11175. }
  11176. };
  11177. exports2.IndexExistsOperation = IndexExistsOperation;
  11178. var IndexInformationOperation = class extends operation_1.AbstractCallbackOperation {
  11179. constructor(db, name, options) {
  11180. super(options);
  11181. this.options = options ?? {};
  11182. this.db = db;
  11183. this.name = name;
  11184. }
  11185. executeCallback(server, session, callback) {
  11186. const db = this.db;
  11187. const name = this.name;
  11188. (0, common_functions_1.indexInformation)(db, name, { ...this.options, readPreference: this.readPreference, session }, callback);
  11189. }
  11190. };
  11191. exports2.IndexInformationOperation = IndexInformationOperation;
  11192. (0, operation_1.defineAspects)(ListIndexesOperation, [
  11193. operation_1.Aspect.READ_OPERATION,
  11194. operation_1.Aspect.RETRYABLE,
  11195. operation_1.Aspect.CURSOR_CREATING
  11196. ]);
  11197. (0, operation_1.defineAspects)(CreateIndexesOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11198. (0, operation_1.defineAspects)(CreateIndexOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11199. (0, operation_1.defineAspects)(EnsureIndexOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11200. (0, operation_1.defineAspects)(DropIndexOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11201. (0, operation_1.defineAspects)(DropIndexesOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11202. }
  11203. });
  11204. // node_modules/mongodb/lib/cursor/list_indexes_cursor.js
  11205. var require_list_indexes_cursor = __commonJS({
  11206. "node_modules/mongodb/lib/cursor/list_indexes_cursor.js"(exports2) {
  11207. "use strict";
  11208. Object.defineProperty(exports2, "__esModule", { value: true });
  11209. exports2.ListIndexesCursor = void 0;
  11210. var execute_operation_1 = require_execute_operation();
  11211. var indexes_1 = require_indexes();
  11212. var abstract_cursor_1 = require_abstract_cursor();
  11213. var ListIndexesCursor = class _ListIndexesCursor extends abstract_cursor_1.AbstractCursor {
  11214. constructor(collection, options) {
  11215. super(collection.client, collection.s.namespace, options);
  11216. this.parent = collection;
  11217. this.options = options;
  11218. }
  11219. clone() {
  11220. return new _ListIndexesCursor(this.parent, {
  11221. ...this.options,
  11222. ...this.cursorOptions
  11223. });
  11224. }
  11225. /** @internal */
  11226. _initialize(session, callback) {
  11227. const operation = new indexes_1.ListIndexesOperation(this.parent, {
  11228. ...this.cursorOptions,
  11229. ...this.options,
  11230. session
  11231. });
  11232. (0, execute_operation_1.executeOperation)(this.parent.client, operation, (err, response) => {
  11233. if (err || response == null)
  11234. return callback(err);
  11235. callback(void 0, { server: operation.server, session, response });
  11236. });
  11237. }
  11238. };
  11239. exports2.ListIndexesCursor = ListIndexesCursor;
  11240. }
  11241. });
  11242. // node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js
  11243. var require_list_search_indexes_cursor = __commonJS({
  11244. "node_modules/mongodb/lib/cursor/list_search_indexes_cursor.js"(exports2) {
  11245. "use strict";
  11246. Object.defineProperty(exports2, "__esModule", { value: true });
  11247. exports2.ListSearchIndexesCursor = void 0;
  11248. var aggregation_cursor_1 = require_aggregation_cursor();
  11249. var ListSearchIndexesCursor = class extends aggregation_cursor_1.AggregationCursor {
  11250. /** @internal */
  11251. constructor({ fullNamespace: ns, client }, name, options = {}) {
  11252. const pipeline = name == null ? [{ $listSearchIndexes: {} }] : [{ $listSearchIndexes: { name } }];
  11253. super(client, ns, pipeline, options);
  11254. }
  11255. };
  11256. exports2.ListSearchIndexesCursor = ListSearchIndexesCursor;
  11257. }
  11258. });
  11259. // node_modules/mongodb/lib/operations/count_documents.js
  11260. var require_count_documents = __commonJS({
  11261. "node_modules/mongodb/lib/operations/count_documents.js"(exports2) {
  11262. "use strict";
  11263. Object.defineProperty(exports2, "__esModule", { value: true });
  11264. exports2.CountDocumentsOperation = void 0;
  11265. var aggregate_1 = require_aggregate();
  11266. var CountDocumentsOperation = class extends aggregate_1.AggregateOperation {
  11267. constructor(collection, query, options) {
  11268. const pipeline = [];
  11269. pipeline.push({ $match: query });
  11270. if (typeof options.skip === "number") {
  11271. pipeline.push({ $skip: options.skip });
  11272. }
  11273. if (typeof options.limit === "number") {
  11274. pipeline.push({ $limit: options.limit });
  11275. }
  11276. pipeline.push({ $group: { _id: 1, n: { $sum: 1 } } });
  11277. super(collection.s.namespace, pipeline, options);
  11278. }
  11279. executeCallback(server, session, callback) {
  11280. super.executeCallback(server, session, (err, result) => {
  11281. if (err || !result) {
  11282. callback(err);
  11283. return;
  11284. }
  11285. const response = result;
  11286. if (response.cursor == null || response.cursor.firstBatch == null) {
  11287. callback(void 0, 0);
  11288. return;
  11289. }
  11290. const docs = response.cursor.firstBatch;
  11291. callback(void 0, docs.length ? docs[0].n : 0);
  11292. });
  11293. }
  11294. };
  11295. exports2.CountDocumentsOperation = CountDocumentsOperation;
  11296. }
  11297. });
  11298. // node_modules/mongodb/lib/operations/distinct.js
  11299. var require_distinct = __commonJS({
  11300. "node_modules/mongodb/lib/operations/distinct.js"(exports2) {
  11301. "use strict";
  11302. Object.defineProperty(exports2, "__esModule", { value: true });
  11303. exports2.DistinctOperation = void 0;
  11304. var utils_1 = require_utils();
  11305. var command_1 = require_command();
  11306. var operation_1 = require_operation();
  11307. var DistinctOperation = class extends command_1.CommandCallbackOperation {
  11308. /**
  11309. * Construct a Distinct operation.
  11310. *
  11311. * @param collection - Collection instance.
  11312. * @param key - Field of the document to find distinct values for.
  11313. * @param query - The query for filtering the set of documents to which we apply the distinct filter.
  11314. * @param options - Optional settings. See Collection.prototype.distinct for a list of options.
  11315. */
  11316. constructor(collection, key, query, options) {
  11317. super(collection, options);
  11318. this.options = options ?? {};
  11319. this.collection = collection;
  11320. this.key = key;
  11321. this.query = query;
  11322. }
  11323. executeCallback(server, session, callback) {
  11324. const coll = this.collection;
  11325. const key = this.key;
  11326. const query = this.query;
  11327. const options = this.options;
  11328. const cmd = {
  11329. distinct: coll.collectionName,
  11330. key,
  11331. query
  11332. };
  11333. if (typeof options.maxTimeMS === "number") {
  11334. cmd.maxTimeMS = options.maxTimeMS;
  11335. }
  11336. if (typeof options.comment !== "undefined") {
  11337. cmd.comment = options.comment;
  11338. }
  11339. (0, utils_1.decorateWithReadConcern)(cmd, coll, options);
  11340. try {
  11341. (0, utils_1.decorateWithCollation)(cmd, coll, options);
  11342. } catch (err) {
  11343. return callback(err);
  11344. }
  11345. super.executeCommandCallback(server, session, cmd, (err, result) => {
  11346. if (err) {
  11347. callback(err);
  11348. return;
  11349. }
  11350. callback(void 0, this.explain ? result : result.values);
  11351. });
  11352. }
  11353. };
  11354. exports2.DistinctOperation = DistinctOperation;
  11355. (0, operation_1.defineAspects)(DistinctOperation, [operation_1.Aspect.READ_OPERATION, operation_1.Aspect.RETRYABLE, operation_1.Aspect.EXPLAINABLE]);
  11356. }
  11357. });
  11358. // node_modules/mongodb/lib/operations/drop.js
  11359. var require_drop = __commonJS({
  11360. "node_modules/mongodb/lib/operations/drop.js"(exports2) {
  11361. "use strict";
  11362. Object.defineProperty(exports2, "__esModule", { value: true });
  11363. exports2.DropDatabaseOperation = exports2.DropCollectionOperation = void 0;
  11364. var error_1 = require_error();
  11365. var command_1 = require_command();
  11366. var operation_1 = require_operation();
  11367. var DropCollectionOperation = class _DropCollectionOperation extends command_1.CommandCallbackOperation {
  11368. constructor(db, name, options = {}) {
  11369. super(db, options);
  11370. this.db = db;
  11371. this.options = options;
  11372. this.name = name;
  11373. }
  11374. executeCallback(server, session, callback) {
  11375. (async () => {
  11376. var _a, _b, _c;
  11377. const db = this.db;
  11378. const options = this.options;
  11379. const name = this.name;
  11380. const encryptedFieldsMap = (_a = db.client.options.autoEncryption) == null ? void 0 : _a.encryptedFieldsMap;
  11381. let encryptedFields = options.encryptedFields ?? (encryptedFieldsMap == null ? void 0 : encryptedFieldsMap[`${db.databaseName}.${name}`]);
  11382. if (!encryptedFields && encryptedFieldsMap) {
  11383. const listCollectionsResult = await db.listCollections({ name }, { nameOnly: false }).toArray();
  11384. encryptedFields = (_c = (_b = listCollectionsResult == null ? void 0 : listCollectionsResult[0]) == null ? void 0 : _b.options) == null ? void 0 : _c.encryptedFields;
  11385. }
  11386. if (encryptedFields) {
  11387. const escCollection = encryptedFields.escCollection || `enxcol_.${name}.esc`;
  11388. const ecocCollection = encryptedFields.ecocCollection || `enxcol_.${name}.ecoc`;
  11389. for (const collectionName of [escCollection, ecocCollection]) {
  11390. const dropOp = new _DropCollectionOperation(db, collectionName);
  11391. try {
  11392. await dropOp.executeWithoutEncryptedFieldsCheck(server, session);
  11393. } catch (err) {
  11394. if (!(err instanceof error_1.MongoServerError) || err.code !== error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
  11395. throw err;
  11396. }
  11397. }
  11398. }
  11399. }
  11400. return this.executeWithoutEncryptedFieldsCheck(server, session);
  11401. })().then((result) => callback(void 0, result), (err) => callback(err));
  11402. }
  11403. executeWithoutEncryptedFieldsCheck(server, session) {
  11404. return new Promise((resolve, reject) => {
  11405. super.executeCommandCallback(server, session, { drop: this.name }, (err, result) => {
  11406. if (err)
  11407. return reject(err);
  11408. resolve(!!result.ok);
  11409. });
  11410. });
  11411. }
  11412. };
  11413. exports2.DropCollectionOperation = DropCollectionOperation;
  11414. var DropDatabaseOperation = class extends command_1.CommandCallbackOperation {
  11415. constructor(db, options) {
  11416. super(db, options);
  11417. this.options = options;
  11418. }
  11419. executeCallback(server, session, callback) {
  11420. super.executeCommandCallback(server, session, { dropDatabase: 1 }, (err, result) => {
  11421. if (err)
  11422. return callback(err);
  11423. if (result.ok)
  11424. return callback(void 0, true);
  11425. callback(void 0, false);
  11426. });
  11427. }
  11428. };
  11429. exports2.DropDatabaseOperation = DropDatabaseOperation;
  11430. (0, operation_1.defineAspects)(DropCollectionOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11431. (0, operation_1.defineAspects)(DropDatabaseOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11432. }
  11433. });
  11434. // node_modules/mongodb/lib/operations/estimated_document_count.js
  11435. var require_estimated_document_count = __commonJS({
  11436. "node_modules/mongodb/lib/operations/estimated_document_count.js"(exports2) {
  11437. "use strict";
  11438. Object.defineProperty(exports2, "__esModule", { value: true });
  11439. exports2.EstimatedDocumentCountOperation = void 0;
  11440. var command_1 = require_command();
  11441. var operation_1 = require_operation();
  11442. var EstimatedDocumentCountOperation = class extends command_1.CommandCallbackOperation {
  11443. constructor(collection, options = {}) {
  11444. super(collection, options);
  11445. this.options = options;
  11446. this.collectionName = collection.collectionName;
  11447. }
  11448. executeCallback(server, session, callback) {
  11449. const cmd = { count: this.collectionName };
  11450. if (typeof this.options.maxTimeMS === "number") {
  11451. cmd.maxTimeMS = this.options.maxTimeMS;
  11452. }
  11453. if (this.options.comment !== void 0) {
  11454. cmd.comment = this.options.comment;
  11455. }
  11456. super.executeCommandCallback(server, session, cmd, (err, response) => {
  11457. if (err) {
  11458. callback(err);
  11459. return;
  11460. }
  11461. callback(void 0, (response == null ? void 0 : response.n) || 0);
  11462. });
  11463. }
  11464. };
  11465. exports2.EstimatedDocumentCountOperation = EstimatedDocumentCountOperation;
  11466. (0, operation_1.defineAspects)(EstimatedDocumentCountOperation, [
  11467. operation_1.Aspect.READ_OPERATION,
  11468. operation_1.Aspect.RETRYABLE,
  11469. operation_1.Aspect.CURSOR_CREATING
  11470. ]);
  11471. }
  11472. });
  11473. // node_modules/mongodb/lib/operations/find_and_modify.js
  11474. var require_find_and_modify = __commonJS({
  11475. "node_modules/mongodb/lib/operations/find_and_modify.js"(exports2) {
  11476. "use strict";
  11477. Object.defineProperty(exports2, "__esModule", { value: true });
  11478. exports2.FindOneAndUpdateOperation = exports2.FindOneAndReplaceOperation = exports2.FindOneAndDeleteOperation = exports2.ReturnDocument = void 0;
  11479. var error_1 = require_error();
  11480. var read_preference_1 = require_read_preference();
  11481. var sort_1 = require_sort();
  11482. var utils_1 = require_utils();
  11483. var command_1 = require_command();
  11484. var operation_1 = require_operation();
  11485. exports2.ReturnDocument = Object.freeze({
  11486. BEFORE: "before",
  11487. AFTER: "after"
  11488. });
  11489. function configureFindAndModifyCmdBaseUpdateOpts(cmdBase, options) {
  11490. cmdBase.new = options.returnDocument === exports2.ReturnDocument.AFTER;
  11491. cmdBase.upsert = options.upsert === true;
  11492. if (options.bypassDocumentValidation === true) {
  11493. cmdBase.bypassDocumentValidation = options.bypassDocumentValidation;
  11494. }
  11495. return cmdBase;
  11496. }
  11497. var FindAndModifyOperation = class extends command_1.CommandCallbackOperation {
  11498. constructor(collection, query, options) {
  11499. super(collection, options);
  11500. this.options = options ?? {};
  11501. this.cmdBase = {
  11502. remove: false,
  11503. new: false,
  11504. upsert: false
  11505. };
  11506. options.includeResultMetadata ?? (options.includeResultMetadata = true);
  11507. const sort = (0, sort_1.formatSort)(options.sort);
  11508. if (sort) {
  11509. this.cmdBase.sort = sort;
  11510. }
  11511. if (options.projection) {
  11512. this.cmdBase.fields = options.projection;
  11513. }
  11514. if (options.maxTimeMS) {
  11515. this.cmdBase.maxTimeMS = options.maxTimeMS;
  11516. }
  11517. if (options.writeConcern) {
  11518. this.cmdBase.writeConcern = options.writeConcern;
  11519. }
  11520. if (options.let) {
  11521. this.cmdBase.let = options.let;
  11522. }
  11523. if (options.comment !== void 0) {
  11524. this.cmdBase.comment = options.comment;
  11525. }
  11526. this.readPreference = read_preference_1.ReadPreference.primary;
  11527. this.collection = collection;
  11528. this.query = query;
  11529. }
  11530. executeCallback(server, session, callback) {
  11531. var _a;
  11532. const coll = this.collection;
  11533. const query = this.query;
  11534. const options = { ...this.options, ...this.bsonOptions };
  11535. const cmd = {
  11536. findAndModify: coll.collectionName,
  11537. query,
  11538. ...this.cmdBase
  11539. };
  11540. try {
  11541. (0, utils_1.decorateWithCollation)(cmd, coll, options);
  11542. } catch (err) {
  11543. return callback(err);
  11544. }
  11545. if (options.hint) {
  11546. const unacknowledgedWrite = ((_a = this.writeConcern) == null ? void 0 : _a.w) === 0;
  11547. if (unacknowledgedWrite || (0, utils_1.maxWireVersion)(server) < 8) {
  11548. callback(new error_1.MongoCompatibilityError("The current topology does not support a hint on findAndModify commands"));
  11549. return;
  11550. }
  11551. cmd.hint = options.hint;
  11552. }
  11553. super.executeCommandCallback(server, session, cmd, (err, result) => {
  11554. if (err)
  11555. return callback(err);
  11556. return callback(void 0, options.includeResultMetadata ? result : result.value ?? null);
  11557. });
  11558. }
  11559. };
  11560. var FindOneAndDeleteOperation = class extends FindAndModifyOperation {
  11561. constructor(collection, filter, options) {
  11562. if (filter == null || typeof filter !== "object") {
  11563. throw new error_1.MongoInvalidArgumentError('Argument "filter" must be an object');
  11564. }
  11565. super(collection, filter, options);
  11566. this.cmdBase.remove = true;
  11567. }
  11568. };
  11569. exports2.FindOneAndDeleteOperation = FindOneAndDeleteOperation;
  11570. var FindOneAndReplaceOperation = class extends FindAndModifyOperation {
  11571. constructor(collection, filter, replacement, options) {
  11572. if (filter == null || typeof filter !== "object") {
  11573. throw new error_1.MongoInvalidArgumentError('Argument "filter" must be an object');
  11574. }
  11575. if (replacement == null || typeof replacement !== "object") {
  11576. throw new error_1.MongoInvalidArgumentError('Argument "replacement" must be an object');
  11577. }
  11578. if ((0, utils_1.hasAtomicOperators)(replacement)) {
  11579. throw new error_1.MongoInvalidArgumentError("Replacement document must not contain atomic operators");
  11580. }
  11581. super(collection, filter, options);
  11582. this.cmdBase.update = replacement;
  11583. configureFindAndModifyCmdBaseUpdateOpts(this.cmdBase, options);
  11584. }
  11585. };
  11586. exports2.FindOneAndReplaceOperation = FindOneAndReplaceOperation;
  11587. var FindOneAndUpdateOperation = class extends FindAndModifyOperation {
  11588. constructor(collection, filter, update, options) {
  11589. if (filter == null || typeof filter !== "object") {
  11590. throw new error_1.MongoInvalidArgumentError('Argument "filter" must be an object');
  11591. }
  11592. if (update == null || typeof update !== "object") {
  11593. throw new error_1.MongoInvalidArgumentError('Argument "update" must be an object');
  11594. }
  11595. if (!(0, utils_1.hasAtomicOperators)(update)) {
  11596. throw new error_1.MongoInvalidArgumentError("Update document requires atomic operators");
  11597. }
  11598. super(collection, filter, options);
  11599. this.cmdBase.update = update;
  11600. configureFindAndModifyCmdBaseUpdateOpts(this.cmdBase, options);
  11601. if (options.arrayFilters) {
  11602. this.cmdBase.arrayFilters = options.arrayFilters;
  11603. }
  11604. }
  11605. };
  11606. exports2.FindOneAndUpdateOperation = FindOneAndUpdateOperation;
  11607. (0, operation_1.defineAspects)(FindAndModifyOperation, [
  11608. operation_1.Aspect.WRITE_OPERATION,
  11609. operation_1.Aspect.RETRYABLE,
  11610. operation_1.Aspect.EXPLAINABLE
  11611. ]);
  11612. }
  11613. });
  11614. // node_modules/mongodb/lib/operations/is_capped.js
  11615. var require_is_capped = __commonJS({
  11616. "node_modules/mongodb/lib/operations/is_capped.js"(exports2) {
  11617. "use strict";
  11618. Object.defineProperty(exports2, "__esModule", { value: true });
  11619. exports2.IsCappedOperation = void 0;
  11620. var error_1 = require_error();
  11621. var operation_1 = require_operation();
  11622. var IsCappedOperation = class extends operation_1.AbstractCallbackOperation {
  11623. constructor(collection, options) {
  11624. super(options);
  11625. this.options = options;
  11626. this.collection = collection;
  11627. }
  11628. executeCallback(server, session, callback) {
  11629. const coll = this.collection;
  11630. coll.s.db.listCollections({ name: coll.collectionName }, { ...this.options, nameOnly: false, readPreference: this.readPreference, session }).toArray().then((collections) => {
  11631. var _a;
  11632. if (collections.length === 0) {
  11633. return callback(new error_1.MongoAPIError(`collection ${coll.namespace} not found`));
  11634. }
  11635. callback(void 0, !!((_a = collections[0].options) == null ? void 0 : _a.capped));
  11636. }, (error) => callback(error));
  11637. }
  11638. };
  11639. exports2.IsCappedOperation = IsCappedOperation;
  11640. }
  11641. });
  11642. // node_modules/mongodb/lib/operations/options_operation.js
  11643. var require_options_operation = __commonJS({
  11644. "node_modules/mongodb/lib/operations/options_operation.js"(exports2) {
  11645. "use strict";
  11646. Object.defineProperty(exports2, "__esModule", { value: true });
  11647. exports2.OptionsOperation = void 0;
  11648. var error_1 = require_error();
  11649. var operation_1 = require_operation();
  11650. var OptionsOperation = class extends operation_1.AbstractCallbackOperation {
  11651. constructor(collection, options) {
  11652. super(options);
  11653. this.options = options;
  11654. this.collection = collection;
  11655. }
  11656. executeCallback(server, session, callback) {
  11657. const coll = this.collection;
  11658. coll.s.db.listCollections({ name: coll.collectionName }, { ...this.options, nameOnly: false, readPreference: this.readPreference, session }).toArray().then((collections) => {
  11659. if (collections.length === 0) {
  11660. return callback(new error_1.MongoAPIError(`collection ${coll.namespace} not found`));
  11661. }
  11662. callback(void 0, collections[0].options);
  11663. }, (error) => callback(error));
  11664. }
  11665. };
  11666. exports2.OptionsOperation = OptionsOperation;
  11667. }
  11668. });
  11669. // node_modules/mongodb/lib/operations/rename.js
  11670. var require_rename = __commonJS({
  11671. "node_modules/mongodb/lib/operations/rename.js"(exports2) {
  11672. "use strict";
  11673. Object.defineProperty(exports2, "__esModule", { value: true });
  11674. exports2.RenameOperation = void 0;
  11675. var collection_1 = require_collection();
  11676. var error_1 = require_error();
  11677. var utils_1 = require_utils();
  11678. var operation_1 = require_operation();
  11679. var run_command_1 = require_run_command();
  11680. var RenameOperation = class extends run_command_1.RunAdminCommandOperation {
  11681. constructor(collection, newName, options) {
  11682. (0, utils_1.checkCollectionName)(newName);
  11683. const renameCollection = collection.namespace;
  11684. const toCollection = collection.s.namespace.withCollection(newName).toString();
  11685. const dropTarget = typeof options.dropTarget === "boolean" ? options.dropTarget : false;
  11686. const cmd = { renameCollection, to: toCollection, dropTarget };
  11687. super(collection, cmd, options);
  11688. this.options = options;
  11689. this.collection = collection;
  11690. this.newName = newName;
  11691. }
  11692. executeCallback(server, session, callback) {
  11693. const coll = this.collection;
  11694. super.executeCallback(server, session, (err, doc) => {
  11695. if (err)
  11696. return callback(err);
  11697. if (doc == null ? void 0 : doc.errmsg) {
  11698. return callback(new error_1.MongoServerError(doc));
  11699. }
  11700. let newColl;
  11701. try {
  11702. newColl = new collection_1.Collection(coll.s.db, this.newName, coll.s.options);
  11703. } catch (err2) {
  11704. return callback(err2);
  11705. }
  11706. return callback(void 0, newColl);
  11707. });
  11708. }
  11709. };
  11710. exports2.RenameOperation = RenameOperation;
  11711. (0, operation_1.defineAspects)(RenameOperation, [operation_1.Aspect.WRITE_OPERATION]);
  11712. }
  11713. });
  11714. // node_modules/mongodb/lib/operations/search_indexes/create.js
  11715. var require_create = __commonJS({
  11716. "node_modules/mongodb/lib/operations/search_indexes/create.js"(exports2) {
  11717. "use strict";
  11718. Object.defineProperty(exports2, "__esModule", { value: true });
  11719. exports2.CreateSearchIndexesOperation = void 0;
  11720. var operation_1 = require_operation();
  11721. var CreateSearchIndexesOperation = class extends operation_1.AbstractCallbackOperation {
  11722. constructor(collection, descriptions) {
  11723. super();
  11724. this.collection = collection;
  11725. this.descriptions = descriptions;
  11726. }
  11727. executeCallback(server, session, callback) {
  11728. const namespace = this.collection.fullNamespace;
  11729. const command = {
  11730. createSearchIndexes: namespace.collection,
  11731. indexes: this.descriptions
  11732. };
  11733. server.command(namespace, command, { session }, (err, res) => {
  11734. if (err || !res) {
  11735. callback(err);
  11736. return;
  11737. }
  11738. const indexesCreated = (res == null ? void 0 : res.indexesCreated) ?? [];
  11739. callback(void 0, indexesCreated.map(({ name }) => name));
  11740. });
  11741. }
  11742. };
  11743. exports2.CreateSearchIndexesOperation = CreateSearchIndexesOperation;
  11744. }
  11745. });
  11746. // node_modules/mongodb/lib/operations/search_indexes/drop.js
  11747. var require_drop2 = __commonJS({
  11748. "node_modules/mongodb/lib/operations/search_indexes/drop.js"(exports2) {
  11749. "use strict";
  11750. Object.defineProperty(exports2, "__esModule", { value: true });
  11751. exports2.DropSearchIndexOperation = void 0;
  11752. var operation_1 = require_operation();
  11753. var DropSearchIndexOperation = class extends operation_1.AbstractCallbackOperation {
  11754. constructor(collection, name) {
  11755. super();
  11756. this.collection = collection;
  11757. this.name = name;
  11758. }
  11759. executeCallback(server, session, callback) {
  11760. const namespace = this.collection.fullNamespace;
  11761. const command = {
  11762. dropSearchIndex: namespace.collection
  11763. };
  11764. if (typeof this.name === "string") {
  11765. command.name = this.name;
  11766. }
  11767. server.command(namespace, command, { session }, (err) => {
  11768. if (err) {
  11769. callback(err);
  11770. return;
  11771. }
  11772. callback();
  11773. });
  11774. }
  11775. };
  11776. exports2.DropSearchIndexOperation = DropSearchIndexOperation;
  11777. }
  11778. });
  11779. // node_modules/mongodb/lib/operations/search_indexes/update.js
  11780. var require_update2 = __commonJS({
  11781. "node_modules/mongodb/lib/operations/search_indexes/update.js"(exports2) {
  11782. "use strict";
  11783. Object.defineProperty(exports2, "__esModule", { value: true });
  11784. exports2.UpdateSearchIndexOperation = void 0;
  11785. var operation_1 = require_operation();
  11786. var UpdateSearchIndexOperation = class extends operation_1.AbstractCallbackOperation {
  11787. constructor(collection, name, definition) {
  11788. super();
  11789. this.collection = collection;
  11790. this.name = name;
  11791. this.definition = definition;
  11792. }
  11793. executeCallback(server, session, callback) {
  11794. const namespace = this.collection.fullNamespace;
  11795. const command = {
  11796. updateSearchIndex: namespace.collection,
  11797. name: this.name,
  11798. definition: this.definition
  11799. };
  11800. server.command(namespace, command, { session }, (err) => {
  11801. if (err) {
  11802. callback(err);
  11803. return;
  11804. }
  11805. callback();
  11806. });
  11807. }
  11808. };
  11809. exports2.UpdateSearchIndexOperation = UpdateSearchIndexOperation;
  11810. }
  11811. });
  11812. // node_modules/mongodb/lib/operations/stats.js
  11813. var require_stats = __commonJS({
  11814. "node_modules/mongodb/lib/operations/stats.js"(exports2) {
  11815. "use strict";
  11816. Object.defineProperty(exports2, "__esModule", { value: true });
  11817. exports2.DbStatsOperation = exports2.CollStatsOperation = void 0;
  11818. var command_1 = require_command();
  11819. var operation_1 = require_operation();
  11820. var CollStatsOperation = class extends command_1.CommandCallbackOperation {
  11821. /**
  11822. * Construct a Stats operation.
  11823. *
  11824. * @param collection - Collection instance
  11825. * @param options - Optional settings. See Collection.prototype.stats for a list of options.
  11826. */
  11827. constructor(collection, options) {
  11828. super(collection, options);
  11829. this.options = options ?? {};
  11830. this.collectionName = collection.collectionName;
  11831. }
  11832. executeCallback(server, session, callback) {
  11833. const command = { collStats: this.collectionName };
  11834. if (this.options.scale != null) {
  11835. command.scale = this.options.scale;
  11836. }
  11837. super.executeCommandCallback(server, session, command, callback);
  11838. }
  11839. };
  11840. exports2.CollStatsOperation = CollStatsOperation;
  11841. var DbStatsOperation = class extends command_1.CommandCallbackOperation {
  11842. constructor(db, options) {
  11843. super(db, options);
  11844. this.options = options;
  11845. }
  11846. executeCallback(server, session, callback) {
  11847. const command = { dbStats: true };
  11848. if (this.options.scale != null) {
  11849. command.scale = this.options.scale;
  11850. }
  11851. super.executeCommandCallback(server, session, command, callback);
  11852. }
  11853. };
  11854. exports2.DbStatsOperation = DbStatsOperation;
  11855. (0, operation_1.defineAspects)(CollStatsOperation, [operation_1.Aspect.READ_OPERATION]);
  11856. (0, operation_1.defineAspects)(DbStatsOperation, [operation_1.Aspect.READ_OPERATION]);
  11857. }
  11858. });
  11859. // node_modules/mongodb/lib/collection.js
  11860. var require_collection = __commonJS({
  11861. "node_modules/mongodb/lib/collection.js"(exports2) {
  11862. "use strict";
  11863. Object.defineProperty(exports2, "__esModule", { value: true });
  11864. exports2.Collection = void 0;
  11865. var bson_1 = require_bson2();
  11866. var ordered_1 = require_ordered();
  11867. var unordered_1 = require_unordered();
  11868. var change_stream_1 = require_change_stream();
  11869. var aggregation_cursor_1 = require_aggregation_cursor();
  11870. var find_cursor_1 = require_find_cursor();
  11871. var list_indexes_cursor_1 = require_list_indexes_cursor();
  11872. var list_search_indexes_cursor_1 = require_list_search_indexes_cursor();
  11873. var error_1 = require_error();
  11874. var bulk_write_1 = require_bulk_write();
  11875. var count_1 = require_count();
  11876. var count_documents_1 = require_count_documents();
  11877. var delete_1 = require_delete();
  11878. var distinct_1 = require_distinct();
  11879. var drop_1 = require_drop();
  11880. var estimated_document_count_1 = require_estimated_document_count();
  11881. var execute_operation_1 = require_execute_operation();
  11882. var find_and_modify_1 = require_find_and_modify();
  11883. var indexes_1 = require_indexes();
  11884. var insert_1 = require_insert();
  11885. var is_capped_1 = require_is_capped();
  11886. var options_operation_1 = require_options_operation();
  11887. var rename_1 = require_rename();
  11888. var create_1 = require_create();
  11889. var drop_2 = require_drop2();
  11890. var update_1 = require_update2();
  11891. var stats_1 = require_stats();
  11892. var update_2 = require_update();
  11893. var read_concern_1 = require_read_concern();
  11894. var read_preference_1 = require_read_preference();
  11895. var utils_1 = require_utils();
  11896. var write_concern_1 = require_write_concern();
  11897. var Collection = class {
  11898. /**
  11899. * Create a new Collection instance
  11900. * @internal
  11901. */
  11902. constructor(db, name, options) {
  11903. var _a;
  11904. (0, utils_1.checkCollectionName)(name);
  11905. this.s = {
  11906. db,
  11907. options,
  11908. namespace: new utils_1.MongoDBCollectionNamespace(db.databaseName, name),
  11909. pkFactory: ((_a = db.options) == null ? void 0 : _a.pkFactory) ?? utils_1.DEFAULT_PK_FACTORY,
  11910. readPreference: read_preference_1.ReadPreference.fromOptions(options),
  11911. bsonOptions: (0, bson_1.resolveBSONOptions)(options, db),
  11912. readConcern: read_concern_1.ReadConcern.fromOptions(options),
  11913. writeConcern: write_concern_1.WriteConcern.fromOptions(options)
  11914. };
  11915. this.client = db.client;
  11916. }
  11917. /**
  11918. * The name of the database this collection belongs to
  11919. */
  11920. get dbName() {
  11921. return this.s.namespace.db;
  11922. }
  11923. /**
  11924. * The name of this collection
  11925. */
  11926. get collectionName() {
  11927. return this.s.namespace.collection;
  11928. }
  11929. /**
  11930. * The namespace of this collection, in the format `${this.dbName}.${this.collectionName}`
  11931. */
  11932. get namespace() {
  11933. return this.fullNamespace.toString();
  11934. }
  11935. /**
  11936. * @internal
  11937. *
  11938. * The `MongoDBNamespace` for the collection.
  11939. */
  11940. get fullNamespace() {
  11941. return this.s.namespace;
  11942. }
  11943. /**
  11944. * The current readConcern of the collection. If not explicitly defined for
  11945. * this collection, will be inherited from the parent DB
  11946. */
  11947. get readConcern() {
  11948. if (this.s.readConcern == null) {
  11949. return this.s.db.readConcern;
  11950. }
  11951. return this.s.readConcern;
  11952. }
  11953. /**
  11954. * The current readPreference of the collection. If not explicitly defined for
  11955. * this collection, will be inherited from the parent DB
  11956. */
  11957. get readPreference() {
  11958. if (this.s.readPreference == null) {
  11959. return this.s.db.readPreference;
  11960. }
  11961. return this.s.readPreference;
  11962. }
  11963. get bsonOptions() {
  11964. return this.s.bsonOptions;
  11965. }
  11966. /**
  11967. * The current writeConcern of the collection. If not explicitly defined for
  11968. * this collection, will be inherited from the parent DB
  11969. */
  11970. get writeConcern() {
  11971. if (this.s.writeConcern == null) {
  11972. return this.s.db.writeConcern;
  11973. }
  11974. return this.s.writeConcern;
  11975. }
  11976. /** The current index hint for the collection */
  11977. get hint() {
  11978. return this.s.collectionHint;
  11979. }
  11980. set hint(v) {
  11981. this.s.collectionHint = (0, utils_1.normalizeHintField)(v);
  11982. }
  11983. /**
  11984. * Inserts a single document into MongoDB. If documents passed in do not contain the **_id** field,
  11985. * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
  11986. * can be overridden by setting the **forceServerObjectId** flag.
  11987. *
  11988. * @param doc - The document to insert
  11989. * @param options - Optional settings for the command
  11990. */
  11991. async insertOne(doc, options) {
  11992. return (0, execute_operation_1.executeOperation)(this.client, new insert_1.InsertOneOperation(this, doc, (0, utils_1.resolveOptions)(this, options)));
  11993. }
  11994. /**
  11995. * Inserts an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
  11996. * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
  11997. * can be overridden by setting the **forceServerObjectId** flag.
  11998. *
  11999. * @param docs - The documents to insert
  12000. * @param options - Optional settings for the command
  12001. */
  12002. async insertMany(docs, options) {
  12003. return (0, execute_operation_1.executeOperation)(this.client, new insert_1.InsertManyOperation(this, docs, (0, utils_1.resolveOptions)(this, options ?? { ordered: true })));
  12004. }
  12005. /**
  12006. * Perform a bulkWrite operation without a fluent API
  12007. *
  12008. * Legal operation types are
  12009. * - `insertOne`
  12010. * - `replaceOne`
  12011. * - `updateOne`
  12012. * - `updateMany`
  12013. * - `deleteOne`
  12014. * - `deleteMany`
  12015. *
  12016. * If documents passed in do not contain the **_id** field,
  12017. * one will be added to each of the documents missing it by the driver, mutating the document. This behavior
  12018. * can be overridden by setting the **forceServerObjectId** flag.
  12019. *
  12020. * @param operations - Bulk operations to perform
  12021. * @param options - Optional settings for the command
  12022. * @throws MongoDriverError if operations is not an array
  12023. */
  12024. async bulkWrite(operations, options) {
  12025. if (!Array.isArray(operations)) {
  12026. throw new error_1.MongoInvalidArgumentError('Argument "operations" must be an array of documents');
  12027. }
  12028. return (0, execute_operation_1.executeOperation)(this.client, new bulk_write_1.BulkWriteOperation(this, operations, (0, utils_1.resolveOptions)(this, options ?? { ordered: true })));
  12029. }
  12030. /**
  12031. * Update a single document in a collection
  12032. *
  12033. * @param filter - The filter used to select the document to update
  12034. * @param update - The update operations to be applied to the document
  12035. * @param options - Optional settings for the command
  12036. */
  12037. async updateOne(filter, update, options) {
  12038. return (0, execute_operation_1.executeOperation)(this.client, new update_2.UpdateOneOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)));
  12039. }
  12040. /**
  12041. * Replace a document in a collection with another document
  12042. *
  12043. * @param filter - The filter used to select the document to replace
  12044. * @param replacement - The Document that replaces the matching document
  12045. * @param options - Optional settings for the command
  12046. */
  12047. async replaceOne(filter, replacement, options) {
  12048. return (0, execute_operation_1.executeOperation)(this.client, new update_2.ReplaceOneOperation(this, filter, replacement, (0, utils_1.resolveOptions)(this, options)));
  12049. }
  12050. /**
  12051. * Update multiple documents in a collection
  12052. *
  12053. * @param filter - The filter used to select the documents to update
  12054. * @param update - The update operations to be applied to the documents
  12055. * @param options - Optional settings for the command
  12056. */
  12057. async updateMany(filter, update, options) {
  12058. return (0, execute_operation_1.executeOperation)(this.client, new update_2.UpdateManyOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)));
  12059. }
  12060. /**
  12061. * Delete a document from a collection
  12062. *
  12063. * @param filter - The filter used to select the document to remove
  12064. * @param options - Optional settings for the command
  12065. */
  12066. async deleteOne(filter = {}, options = {}) {
  12067. return (0, execute_operation_1.executeOperation)(this.client, new delete_1.DeleteOneOperation(this, filter, (0, utils_1.resolveOptions)(this, options)));
  12068. }
  12069. /**
  12070. * Delete multiple documents from a collection
  12071. *
  12072. * @param filter - The filter used to select the documents to remove
  12073. * @param options - Optional settings for the command
  12074. */
  12075. async deleteMany(filter = {}, options = {}) {
  12076. return (0, execute_operation_1.executeOperation)(this.client, new delete_1.DeleteManyOperation(this, filter, (0, utils_1.resolveOptions)(this, options)));
  12077. }
  12078. /**
  12079. * Rename the collection.
  12080. *
  12081. * @remarks
  12082. * This operation does not inherit options from the Db or MongoClient.
  12083. *
  12084. * @param newName - New name of of the collection.
  12085. * @param options - Optional settings for the command
  12086. */
  12087. async rename(newName, options) {
  12088. return (0, execute_operation_1.executeOperation)(this.client, new rename_1.RenameOperation(this, newName, {
  12089. ...options,
  12090. readPreference: read_preference_1.ReadPreference.PRIMARY
  12091. }));
  12092. }
  12093. /**
  12094. * Drop the collection from the database, removing it permanently. New accesses will create a new collection.
  12095. *
  12096. * @param options - Optional settings for the command
  12097. */
  12098. async drop(options) {
  12099. return (0, execute_operation_1.executeOperation)(this.client, new drop_1.DropCollectionOperation(this.s.db, this.collectionName, options));
  12100. }
  12101. async findOne(filter = {}, options = {}) {
  12102. const cursor = this.find(filter, options).limit(-1).batchSize(1);
  12103. const res = await cursor.next();
  12104. await cursor.close();
  12105. return res;
  12106. }
  12107. find(filter = {}, options = {}) {
  12108. return new find_cursor_1.FindCursor(this.client, this.s.namespace, filter, (0, utils_1.resolveOptions)(this, options));
  12109. }
  12110. /**
  12111. * Returns the options of the collection.
  12112. *
  12113. * @param options - Optional settings for the command
  12114. */
  12115. async options(options) {
  12116. return (0, execute_operation_1.executeOperation)(this.client, new options_operation_1.OptionsOperation(this, (0, utils_1.resolveOptions)(this, options)));
  12117. }
  12118. /**
  12119. * Returns if the collection is a capped collection
  12120. *
  12121. * @param options - Optional settings for the command
  12122. */
  12123. async isCapped(options) {
  12124. return (0, execute_operation_1.executeOperation)(this.client, new is_capped_1.IsCappedOperation(this, (0, utils_1.resolveOptions)(this, options)));
  12125. }
  12126. /**
  12127. * Creates an index on the db and collection collection.
  12128. *
  12129. * @param indexSpec - The field name or index specification to create an index for
  12130. * @param options - Optional settings for the command
  12131. *
  12132. * @example
  12133. * ```ts
  12134. * const collection = client.db('foo').collection('bar');
  12135. *
  12136. * await collection.createIndex({ a: 1, b: -1 });
  12137. *
  12138. * // Alternate syntax for { c: 1, d: -1 } that ensures order of indexes
  12139. * await collection.createIndex([ [c, 1], [d, -1] ]);
  12140. *
  12141. * // Equivalent to { e: 1 }
  12142. * await collection.createIndex('e');
  12143. *
  12144. * // Equivalent to { f: 1, g: 1 }
  12145. * await collection.createIndex(['f', 'g'])
  12146. *
  12147. * // Equivalent to { h: 1, i: -1 }
  12148. * await collection.createIndex([ { h: 1 }, { i: -1 } ]);
  12149. *
  12150. * // Equivalent to { j: 1, k: -1, l: 2d }
  12151. * await collection.createIndex(['j', ['k', -1], { l: '2d' }])
  12152. * ```
  12153. */
  12154. async createIndex(indexSpec, options) {
  12155. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.CreateIndexOperation(this, this.collectionName, indexSpec, (0, utils_1.resolveOptions)(this, options)));
  12156. }
  12157. /**
  12158. * Creates multiple indexes in the collection, this method is only supported for
  12159. * MongoDB 2.6 or higher. Earlier version of MongoDB will throw a command not supported
  12160. * error.
  12161. *
  12162. * **Note**: Unlike {@link Collection#createIndex| createIndex}, this function takes in raw index specifications.
  12163. * Index specifications are defined {@link https://www.mongodb.com/docs/manual/reference/command/createIndexes/| here}.
  12164. *
  12165. * @param indexSpecs - An array of index specifications to be created
  12166. * @param options - Optional settings for the command
  12167. *
  12168. * @example
  12169. * ```ts
  12170. * const collection = client.db('foo').collection('bar');
  12171. * await collection.createIndexes([
  12172. * // Simple index on field fizz
  12173. * {
  12174. * key: { fizz: 1 },
  12175. * }
  12176. * // wildcard index
  12177. * {
  12178. * key: { '$**': 1 }
  12179. * },
  12180. * // named index on darmok and jalad
  12181. * {
  12182. * key: { darmok: 1, jalad: -1 }
  12183. * name: 'tanagra'
  12184. * }
  12185. * ]);
  12186. * ```
  12187. */
  12188. async createIndexes(indexSpecs, options) {
  12189. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.CreateIndexesOperation(this, this.collectionName, indexSpecs, (0, utils_1.resolveOptions)(this, { ...options, maxTimeMS: void 0 })));
  12190. }
  12191. /**
  12192. * Drops an index from this collection.
  12193. *
  12194. * @param indexName - Name of the index to drop.
  12195. * @param options - Optional settings for the command
  12196. */
  12197. async dropIndex(indexName, options) {
  12198. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.DropIndexOperation(this, indexName, {
  12199. ...(0, utils_1.resolveOptions)(this, options),
  12200. readPreference: read_preference_1.ReadPreference.primary
  12201. }));
  12202. }
  12203. /**
  12204. * Drops all indexes from this collection.
  12205. *
  12206. * @param options - Optional settings for the command
  12207. */
  12208. async dropIndexes(options) {
  12209. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.DropIndexesOperation(this, (0, utils_1.resolveOptions)(this, options)));
  12210. }
  12211. /**
  12212. * Get the list of all indexes information for the collection.
  12213. *
  12214. * @param options - Optional settings for the command
  12215. */
  12216. listIndexes(options) {
  12217. return new list_indexes_cursor_1.ListIndexesCursor(this, (0, utils_1.resolveOptions)(this, options));
  12218. }
  12219. /**
  12220. * Checks if one or more indexes exist on the collection, fails on first non-existing index
  12221. *
  12222. * @param indexes - One or more index names to check.
  12223. * @param options - Optional settings for the command
  12224. */
  12225. async indexExists(indexes, options) {
  12226. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.IndexExistsOperation(this, indexes, (0, utils_1.resolveOptions)(this, options)));
  12227. }
  12228. /**
  12229. * Retrieves this collections index info.
  12230. *
  12231. * @param options - Optional settings for the command
  12232. */
  12233. async indexInformation(options) {
  12234. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.IndexInformationOperation(this.s.db, this.collectionName, (0, utils_1.resolveOptions)(this, options)));
  12235. }
  12236. /**
  12237. * Gets an estimate of the count of documents in a collection using collection metadata.
  12238. * This will always run a count command on all server versions.
  12239. *
  12240. * due to an oversight in versions 5.0.0-5.0.8 of MongoDB, the count command,
  12241. * which estimatedDocumentCount uses in its implementation, was not included in v1 of
  12242. * the Stable API, and so users of the Stable API with estimatedDocumentCount are
  12243. * recommended to upgrade their server version to 5.0.9+ or set apiStrict: false to avoid
  12244. * encountering errors.
  12245. *
  12246. * @see {@link https://www.mongodb.com/docs/manual/reference/command/count/#behavior|Count: Behavior}
  12247. * @param options - Optional settings for the command
  12248. */
  12249. async estimatedDocumentCount(options) {
  12250. return (0, execute_operation_1.executeOperation)(this.client, new estimated_document_count_1.EstimatedDocumentCountOperation(this, (0, utils_1.resolveOptions)(this, options)));
  12251. }
  12252. /**
  12253. * Gets the number of documents matching the filter.
  12254. * For a fast count of the total documents in a collection see {@link Collection#estimatedDocumentCount| estimatedDocumentCount}.
  12255. * **Note**: When migrating from {@link Collection#count| count} to {@link Collection#countDocuments| countDocuments}
  12256. * the following query operators must be replaced:
  12257. *
  12258. * | Operator | Replacement |
  12259. * | -------- | ----------- |
  12260. * | `$where` | [`$expr`][1] |
  12261. * | `$near` | [`$geoWithin`][2] with [`$center`][3] |
  12262. * | `$nearSphere` | [`$geoWithin`][2] with [`$centerSphere`][4] |
  12263. *
  12264. * [1]: https://www.mongodb.com/docs/manual/reference/operator/query/expr/
  12265. * [2]: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
  12266. * [3]: https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
  12267. * [4]: https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
  12268. *
  12269. * @param filter - The filter for the count
  12270. * @param options - Optional settings for the command
  12271. *
  12272. * @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/
  12273. * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
  12274. * @see https://www.mongodb.com/docs/manual/reference/operator/query/center/#op._S_center
  12275. * @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/#op._S_centerSphere
  12276. */
  12277. async countDocuments(filter = {}, options = {}) {
  12278. return (0, execute_operation_1.executeOperation)(this.client, new count_documents_1.CountDocumentsOperation(this, filter, (0, utils_1.resolveOptions)(this, options)));
  12279. }
  12280. async distinct(key, filter = {}, options = {}) {
  12281. return (0, execute_operation_1.executeOperation)(this.client, new distinct_1.DistinctOperation(this, key, filter, (0, utils_1.resolveOptions)(this, options)));
  12282. }
  12283. /**
  12284. * Retrieve all the indexes on the collection.
  12285. *
  12286. * @param options - Optional settings for the command
  12287. */
  12288. async indexes(options) {
  12289. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.IndexesOperation(this, (0, utils_1.resolveOptions)(this, options)));
  12290. }
  12291. /**
  12292. * Get all the collection statistics.
  12293. *
  12294. * @deprecated the `collStats` operation will be removed in the next major release. Please
  12295. * use an aggregation pipeline with the [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/) stage instead
  12296. *
  12297. * @param options - Optional settings for the command
  12298. */
  12299. async stats(options) {
  12300. return (0, execute_operation_1.executeOperation)(this.client, new stats_1.CollStatsOperation(this, options));
  12301. }
  12302. async findOneAndDelete(filter, options) {
  12303. return (0, execute_operation_1.executeOperation)(this.client, new find_and_modify_1.FindOneAndDeleteOperation(this, filter, (0, utils_1.resolveOptions)(this, options)));
  12304. }
  12305. async findOneAndReplace(filter, replacement, options) {
  12306. return (0, execute_operation_1.executeOperation)(this.client, new find_and_modify_1.FindOneAndReplaceOperation(this, filter, replacement, (0, utils_1.resolveOptions)(this, options)));
  12307. }
  12308. async findOneAndUpdate(filter, update, options) {
  12309. return (0, execute_operation_1.executeOperation)(this.client, new find_and_modify_1.FindOneAndUpdateOperation(this, filter, update, (0, utils_1.resolveOptions)(this, options)));
  12310. }
  12311. /**
  12312. * Execute an aggregation framework pipeline against the collection, needs MongoDB \>= 2.2
  12313. *
  12314. * @param pipeline - An array of aggregation pipelines to execute
  12315. * @param options - Optional settings for the command
  12316. */
  12317. aggregate(pipeline = [], options) {
  12318. if (!Array.isArray(pipeline)) {
  12319. throw new error_1.MongoInvalidArgumentError('Argument "pipeline" must be an array of aggregation stages');
  12320. }
  12321. return new aggregation_cursor_1.AggregationCursor(this.client, this.s.namespace, pipeline, (0, utils_1.resolveOptions)(this, options));
  12322. }
  12323. /**
  12324. * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
  12325. *
  12326. * @remarks
  12327. * watch() accepts two generic arguments for distinct use cases:
  12328. * - The first is to override the schema that may be defined for this specific collection
  12329. * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
  12330. * @example
  12331. * By just providing the first argument I can type the change to be `ChangeStreamDocument<{ _id: number }>`
  12332. * ```ts
  12333. * collection.watch<{ _id: number }>()
  12334. * .on('change', change => console.log(change._id.toFixed(4)));
  12335. * ```
  12336. *
  12337. * @example
  12338. * Passing a second argument provides a way to reflect the type changes caused by an advanced pipeline.
  12339. * Here, we are using a pipeline to have MongoDB filter for insert changes only and add a comment.
  12340. * No need start from scratch on the ChangeStreamInsertDocument type!
  12341. * By using an intersection we can save time and ensure defaults remain the same type!
  12342. * ```ts
  12343. * collection
  12344. * .watch<Schema, ChangeStreamInsertDocument<Schema> & { comment: string }>([
  12345. * { $addFields: { comment: 'big changes' } },
  12346. * { $match: { operationType: 'insert' } }
  12347. * ])
  12348. * .on('change', change => {
  12349. * change.comment.startsWith('big');
  12350. * change.operationType === 'insert';
  12351. * // No need to narrow in code because the generics did that for us!
  12352. * expectType<Schema>(change.fullDocument);
  12353. * });
  12354. * ```
  12355. *
  12356. * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
  12357. * @param options - Optional settings for the command
  12358. * @typeParam TLocal - Type of the data being detected by the change stream
  12359. * @typeParam TChange - Type of the whole change stream document emitted
  12360. */
  12361. watch(pipeline = [], options = {}) {
  12362. if (!Array.isArray(pipeline)) {
  12363. options = pipeline;
  12364. pipeline = [];
  12365. }
  12366. return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
  12367. }
  12368. /**
  12369. * Initiate an Out of order batch write operation. All operations will be buffered into insert/update/remove commands executed out of order.
  12370. *
  12371. * @throws MongoNotConnectedError
  12372. * @remarks
  12373. * **NOTE:** MongoClient must be connected prior to calling this method due to a known limitation in this legacy implementation.
  12374. * However, `collection.bulkWrite()` provides an equivalent API that does not require prior connecting.
  12375. */
  12376. initializeUnorderedBulkOp(options) {
  12377. return new unordered_1.UnorderedBulkOperation(this, (0, utils_1.resolveOptions)(this, options));
  12378. }
  12379. /**
  12380. * Initiate an In order bulk write operation. Operations will be serially executed in the order they are added, creating a new operation for each switch in types.
  12381. *
  12382. * @throws MongoNotConnectedError
  12383. * @remarks
  12384. * **NOTE:** MongoClient must be connected prior to calling this method due to a known limitation in this legacy implementation.
  12385. * However, `collection.bulkWrite()` provides an equivalent API that does not require prior connecting.
  12386. */
  12387. initializeOrderedBulkOp(options) {
  12388. return new ordered_1.OrderedBulkOperation(this, (0, utils_1.resolveOptions)(this, options));
  12389. }
  12390. /**
  12391. * An estimated count of matching documents in the db to a filter.
  12392. *
  12393. * **NOTE:** This method has been deprecated, since it does not provide an accurate count of the documents
  12394. * in a collection. To obtain an accurate count of documents in the collection, use {@link Collection#countDocuments| countDocuments}.
  12395. * To obtain an estimated count of all documents in the collection, use {@link Collection#estimatedDocumentCount| estimatedDocumentCount}.
  12396. *
  12397. * @deprecated use {@link Collection#countDocuments| countDocuments} or {@link Collection#estimatedDocumentCount| estimatedDocumentCount} instead
  12398. *
  12399. * @param filter - The filter for the count.
  12400. * @param options - Optional settings for the command
  12401. */
  12402. async count(filter = {}, options = {}) {
  12403. return (0, execute_operation_1.executeOperation)(this.client, new count_1.CountOperation(this.fullNamespace, filter, (0, utils_1.resolveOptions)(this, options)));
  12404. }
  12405. listSearchIndexes(indexNameOrOptions, options) {
  12406. options = typeof indexNameOrOptions === "object" ? indexNameOrOptions : options == null ? {} : options;
  12407. const indexName = indexNameOrOptions == null ? null : typeof indexNameOrOptions === "object" ? null : indexNameOrOptions;
  12408. return new list_search_indexes_cursor_1.ListSearchIndexesCursor(this, indexName, options);
  12409. }
  12410. /**
  12411. * Creates a single search index for the collection.
  12412. *
  12413. * @param description - The index description for the new search index.
  12414. * @returns A promise that resolves to the name of the new search index.
  12415. *
  12416. * @remarks Only available when used against a 7.0+ Atlas cluster.
  12417. */
  12418. async createSearchIndex(description) {
  12419. const [index] = await this.createSearchIndexes([description]);
  12420. return index;
  12421. }
  12422. /**
  12423. * Creates multiple search indexes for the current collection.
  12424. *
  12425. * @param descriptions - An array of `SearchIndexDescription`s for the new search indexes.
  12426. * @returns A promise that resolves to an array of the newly created search index names.
  12427. *
  12428. * @remarks Only available when used against a 7.0+ Atlas cluster.
  12429. * @returns
  12430. */
  12431. async createSearchIndexes(descriptions) {
  12432. return (0, execute_operation_1.executeOperation)(this.client, new create_1.CreateSearchIndexesOperation(this, descriptions));
  12433. }
  12434. /**
  12435. * Deletes a search index by index name.
  12436. *
  12437. * @param name - The name of the search index to be deleted.
  12438. *
  12439. * @remarks Only available when used against a 7.0+ Atlas cluster.
  12440. */
  12441. async dropSearchIndex(name) {
  12442. return (0, execute_operation_1.executeOperation)(this.client, new drop_2.DropSearchIndexOperation(this, name));
  12443. }
  12444. /**
  12445. * Updates a search index by replacing the existing index definition with the provided definition.
  12446. *
  12447. * @param name - The name of the search index to update.
  12448. * @param definition - The new search index definition.
  12449. *
  12450. * @remarks Only available when used against a 7.0+ Atlas cluster.
  12451. */
  12452. async updateSearchIndex(name, definition) {
  12453. return (0, execute_operation_1.executeOperation)(this.client, new update_1.UpdateSearchIndexOperation(this, name, definition));
  12454. }
  12455. };
  12456. exports2.Collection = Collection;
  12457. }
  12458. });
  12459. // node_modules/mongodb/lib/cursor/change_stream_cursor.js
  12460. var require_change_stream_cursor = __commonJS({
  12461. "node_modules/mongodb/lib/cursor/change_stream_cursor.js"(exports2) {
  12462. "use strict";
  12463. Object.defineProperty(exports2, "__esModule", { value: true });
  12464. exports2.ChangeStreamCursor = void 0;
  12465. var change_stream_1 = require_change_stream();
  12466. var constants_1 = require_constants2();
  12467. var aggregate_1 = require_aggregate();
  12468. var execute_operation_1 = require_execute_operation();
  12469. var utils_1 = require_utils();
  12470. var abstract_cursor_1 = require_abstract_cursor();
  12471. var ChangeStreamCursor = class _ChangeStreamCursor extends abstract_cursor_1.AbstractCursor {
  12472. constructor(client, namespace, pipeline = [], options = {}) {
  12473. super(client, namespace, options);
  12474. this.pipeline = pipeline;
  12475. this.options = options;
  12476. this._resumeToken = null;
  12477. this.startAtOperationTime = options.startAtOperationTime;
  12478. if (options.startAfter) {
  12479. this.resumeToken = options.startAfter;
  12480. } else if (options.resumeAfter) {
  12481. this.resumeToken = options.resumeAfter;
  12482. }
  12483. }
  12484. set resumeToken(token) {
  12485. this._resumeToken = token;
  12486. this.emit(change_stream_1.ChangeStream.RESUME_TOKEN_CHANGED, token);
  12487. }
  12488. get resumeToken() {
  12489. return this._resumeToken;
  12490. }
  12491. get resumeOptions() {
  12492. const options = {
  12493. ...this.options
  12494. };
  12495. for (const key of ["resumeAfter", "startAfter", "startAtOperationTime"]) {
  12496. delete options[key];
  12497. }
  12498. if (this.resumeToken != null) {
  12499. if (this.options.startAfter && !this.hasReceived) {
  12500. options.startAfter = this.resumeToken;
  12501. } else {
  12502. options.resumeAfter = this.resumeToken;
  12503. }
  12504. } else if (this.startAtOperationTime != null && (0, utils_1.maxWireVersion)(this.server) >= 7) {
  12505. options.startAtOperationTime = this.startAtOperationTime;
  12506. }
  12507. return options;
  12508. }
  12509. cacheResumeToken(resumeToken) {
  12510. if (this.bufferedCount() === 0 && this.postBatchResumeToken) {
  12511. this.resumeToken = this.postBatchResumeToken;
  12512. } else {
  12513. this.resumeToken = resumeToken;
  12514. }
  12515. this.hasReceived = true;
  12516. }
  12517. _processBatch(response) {
  12518. const cursor = response.cursor;
  12519. if (cursor.postBatchResumeToken) {
  12520. this.postBatchResumeToken = response.cursor.postBatchResumeToken;
  12521. const batch = "firstBatch" in response.cursor ? response.cursor.firstBatch : response.cursor.nextBatch;
  12522. if (batch.length === 0) {
  12523. this.resumeToken = cursor.postBatchResumeToken;
  12524. }
  12525. }
  12526. }
  12527. clone() {
  12528. return new _ChangeStreamCursor(this.client, this.namespace, this.pipeline, {
  12529. ...this.cursorOptions
  12530. });
  12531. }
  12532. _initialize(session, callback) {
  12533. const aggregateOperation = new aggregate_1.AggregateOperation(this.namespace, this.pipeline, {
  12534. ...this.cursorOptions,
  12535. ...this.options,
  12536. session
  12537. });
  12538. (0, execute_operation_1.executeOperation)(session.client, aggregateOperation, (err, response) => {
  12539. if (err || response == null) {
  12540. return callback(err);
  12541. }
  12542. const server = aggregateOperation.server;
  12543. this.maxWireVersion = (0, utils_1.maxWireVersion)(server);
  12544. if (this.startAtOperationTime == null && this.resumeAfter == null && this.startAfter == null && this.maxWireVersion >= 7) {
  12545. this.startAtOperationTime = response.operationTime;
  12546. }
  12547. this._processBatch(response);
  12548. this.emit(constants_1.INIT, response);
  12549. this.emit(constants_1.RESPONSE);
  12550. callback(void 0, { server, session, response });
  12551. });
  12552. }
  12553. _getMore(batchSize, callback) {
  12554. super._getMore(batchSize, (err, response) => {
  12555. if (err) {
  12556. return callback(err);
  12557. }
  12558. this.maxWireVersion = (0, utils_1.maxWireVersion)(this.server);
  12559. this._processBatch(response);
  12560. this.emit(change_stream_1.ChangeStream.MORE, response);
  12561. this.emit(change_stream_1.ChangeStream.RESPONSE);
  12562. callback(err, response);
  12563. });
  12564. }
  12565. };
  12566. exports2.ChangeStreamCursor = ChangeStreamCursor;
  12567. }
  12568. });
  12569. // node_modules/mongodb/lib/operations/list_collections.js
  12570. var require_list_collections = __commonJS({
  12571. "node_modules/mongodb/lib/operations/list_collections.js"(exports2) {
  12572. "use strict";
  12573. Object.defineProperty(exports2, "__esModule", { value: true });
  12574. exports2.ListCollectionsOperation = void 0;
  12575. var utils_1 = require_utils();
  12576. var command_1 = require_command();
  12577. var operation_1 = require_operation();
  12578. var ListCollectionsOperation = class extends command_1.CommandCallbackOperation {
  12579. constructor(db, filter, options) {
  12580. super(db, options);
  12581. this.options = { ...options };
  12582. delete this.options.writeConcern;
  12583. this.db = db;
  12584. this.filter = filter;
  12585. this.nameOnly = !!this.options.nameOnly;
  12586. this.authorizedCollections = !!this.options.authorizedCollections;
  12587. if (typeof this.options.batchSize === "number") {
  12588. this.batchSize = this.options.batchSize;
  12589. }
  12590. }
  12591. executeCallback(server, session, callback) {
  12592. return super.executeCommandCallback(server, session, this.generateCommand((0, utils_1.maxWireVersion)(server)), callback);
  12593. }
  12594. /* This is here for the purpose of unit testing the final command that gets sent. */
  12595. generateCommand(wireVersion) {
  12596. const command = {
  12597. listCollections: 1,
  12598. filter: this.filter,
  12599. cursor: this.batchSize ? { batchSize: this.batchSize } : {},
  12600. nameOnly: this.nameOnly,
  12601. authorizedCollections: this.authorizedCollections
  12602. };
  12603. if (wireVersion >= 9 && this.options.comment !== void 0) {
  12604. command.comment = this.options.comment;
  12605. }
  12606. return command;
  12607. }
  12608. };
  12609. exports2.ListCollectionsOperation = ListCollectionsOperation;
  12610. (0, operation_1.defineAspects)(ListCollectionsOperation, [
  12611. operation_1.Aspect.READ_OPERATION,
  12612. operation_1.Aspect.RETRYABLE,
  12613. operation_1.Aspect.CURSOR_CREATING
  12614. ]);
  12615. }
  12616. });
  12617. // node_modules/mongodb/lib/cursor/list_collections_cursor.js
  12618. var require_list_collections_cursor = __commonJS({
  12619. "node_modules/mongodb/lib/cursor/list_collections_cursor.js"(exports2) {
  12620. "use strict";
  12621. Object.defineProperty(exports2, "__esModule", { value: true });
  12622. exports2.ListCollectionsCursor = void 0;
  12623. var execute_operation_1 = require_execute_operation();
  12624. var list_collections_1 = require_list_collections();
  12625. var abstract_cursor_1 = require_abstract_cursor();
  12626. var ListCollectionsCursor = class _ListCollectionsCursor extends abstract_cursor_1.AbstractCursor {
  12627. constructor(db, filter, options) {
  12628. super(db.client, db.s.namespace, options);
  12629. this.parent = db;
  12630. this.filter = filter;
  12631. this.options = options;
  12632. }
  12633. clone() {
  12634. return new _ListCollectionsCursor(this.parent, this.filter, {
  12635. ...this.options,
  12636. ...this.cursorOptions
  12637. });
  12638. }
  12639. /** @internal */
  12640. _initialize(session, callback) {
  12641. const operation = new list_collections_1.ListCollectionsOperation(this.parent, this.filter, {
  12642. ...this.cursorOptions,
  12643. ...this.options,
  12644. session
  12645. });
  12646. (0, execute_operation_1.executeOperation)(this.parent.client, operation, (err, response) => {
  12647. if (err || response == null)
  12648. return callback(err);
  12649. callback(void 0, { server: operation.server, session, response });
  12650. });
  12651. }
  12652. };
  12653. exports2.ListCollectionsCursor = ListCollectionsCursor;
  12654. }
  12655. });
  12656. // node_modules/mongodb/lib/cursor/run_command_cursor.js
  12657. var require_run_command_cursor = __commonJS({
  12658. "node_modules/mongodb/lib/cursor/run_command_cursor.js"(exports2) {
  12659. "use strict";
  12660. Object.defineProperty(exports2, "__esModule", { value: true });
  12661. exports2.RunCommandCursor = void 0;
  12662. var error_1 = require_error();
  12663. var execute_operation_1 = require_execute_operation();
  12664. var get_more_1 = require_get_more();
  12665. var run_command_1 = require_run_command();
  12666. var utils_1 = require_utils();
  12667. var abstract_cursor_1 = require_abstract_cursor();
  12668. var RunCommandCursor = class extends abstract_cursor_1.AbstractCursor {
  12669. /**
  12670. * Controls the `getMore.comment` field
  12671. * @param comment - any BSON value
  12672. */
  12673. setComment(comment) {
  12674. this.getMoreOptions.comment = comment;
  12675. return this;
  12676. }
  12677. /**
  12678. * Controls the `getMore.maxTimeMS` field. Only valid when cursor is tailable await
  12679. * @param maxTimeMS - the number of milliseconds to wait for new data
  12680. */
  12681. setMaxTimeMS(maxTimeMS) {
  12682. this.getMoreOptions.maxAwaitTimeMS = maxTimeMS;
  12683. return this;
  12684. }
  12685. /**
  12686. * Controls the `getMore.batchSize` field
  12687. * @param maxTimeMS - the number documents to return in the `nextBatch`
  12688. */
  12689. setBatchSize(batchSize) {
  12690. this.getMoreOptions.batchSize = batchSize;
  12691. return this;
  12692. }
  12693. /** Unsupported for RunCommandCursor */
  12694. clone() {
  12695. throw new error_1.MongoAPIError("Clone not supported, create a new cursor with db.runCursorCommand");
  12696. }
  12697. /** Unsupported for RunCommandCursor: readConcern must be configured directly on command document */
  12698. withReadConcern(_) {
  12699. throw new error_1.MongoAPIError("RunCommandCursor does not support readConcern it must be attached to the command being run");
  12700. }
  12701. /** Unsupported for RunCommandCursor: various cursor flags must be configured directly on command document */
  12702. addCursorFlag(_, __) {
  12703. throw new error_1.MongoAPIError("RunCommandCursor does not support cursor flags, they must be attached to the command being run");
  12704. }
  12705. /** Unsupported for RunCommandCursor: maxTimeMS must be configured directly on command document */
  12706. maxTimeMS(_) {
  12707. throw new error_1.MongoAPIError("maxTimeMS must be configured on the command document directly, to configure getMore.maxTimeMS use cursor.setMaxTimeMS()");
  12708. }
  12709. /** Unsupported for RunCommandCursor: batchSize must be configured directly on command document */
  12710. batchSize(_) {
  12711. throw new error_1.MongoAPIError("batchSize must be configured on the command document directly, to configure getMore.batchSize use cursor.setBatchSize()");
  12712. }
  12713. /** @internal */
  12714. constructor(db, command, options = {}) {
  12715. super(db.client, (0, utils_1.ns)(db.namespace), options);
  12716. this.getMoreOptions = {};
  12717. this.db = db;
  12718. this.command = Object.freeze({ ...command });
  12719. }
  12720. /** @internal */
  12721. _initialize(session, callback) {
  12722. const operation = new run_command_1.RunCommandOperation(this.db, this.command, {
  12723. ...this.cursorOptions,
  12724. session,
  12725. readPreference: this.cursorOptions.readPreference
  12726. });
  12727. (0, execute_operation_1.executeOperation)(this.client, operation).then((response) => {
  12728. if (response.cursor == null) {
  12729. callback(new error_1.MongoUnexpectedServerResponseError("Expected server to respond with cursor"));
  12730. return;
  12731. }
  12732. callback(void 0, {
  12733. server: operation.server,
  12734. session,
  12735. response
  12736. });
  12737. }, (err) => callback(err));
  12738. }
  12739. /** @internal */
  12740. _getMore(_batchSize, callback) {
  12741. const getMoreOperation = new get_more_1.GetMoreOperation(this.namespace, this.id, this.server, {
  12742. ...this.cursorOptions,
  12743. session: this.session,
  12744. ...this.getMoreOptions
  12745. });
  12746. (0, execute_operation_1.executeOperation)(this.client, getMoreOperation, callback);
  12747. }
  12748. };
  12749. exports2.RunCommandCursor = RunCommandCursor;
  12750. }
  12751. });
  12752. // node_modules/mongodb/lib/operations/collections.js
  12753. var require_collections = __commonJS({
  12754. "node_modules/mongodb/lib/operations/collections.js"(exports2) {
  12755. "use strict";
  12756. Object.defineProperty(exports2, "__esModule", { value: true });
  12757. exports2.CollectionsOperation = void 0;
  12758. var collection_1 = require_collection();
  12759. var operation_1 = require_operation();
  12760. var CollectionsOperation = class extends operation_1.AbstractCallbackOperation {
  12761. constructor(db, options) {
  12762. super(options);
  12763. this.options = options;
  12764. this.db = db;
  12765. }
  12766. executeCallback(server, session, callback) {
  12767. this.db.listCollections({}, { ...this.options, nameOnly: true, readPreference: this.readPreference, session }).toArray().then((documents) => {
  12768. const collections = [];
  12769. for (const { name } of documents) {
  12770. if (!name.includes("$")) {
  12771. collections.push(new collection_1.Collection(this.db, name, this.db.s.options));
  12772. }
  12773. }
  12774. callback(void 0, collections);
  12775. }, (error) => callback(error));
  12776. }
  12777. };
  12778. exports2.CollectionsOperation = CollectionsOperation;
  12779. }
  12780. });
  12781. // node_modules/mongodb/lib/operations/create_collection.js
  12782. var require_create_collection = __commonJS({
  12783. "node_modules/mongodb/lib/operations/create_collection.js"(exports2) {
  12784. "use strict";
  12785. Object.defineProperty(exports2, "__esModule", { value: true });
  12786. exports2.CreateCollectionOperation = void 0;
  12787. var constants_1 = require_constants();
  12788. var collection_1 = require_collection();
  12789. var error_1 = require_error();
  12790. var command_1 = require_command();
  12791. var indexes_1 = require_indexes();
  12792. var operation_1 = require_operation();
  12793. var ILLEGAL_COMMAND_FIELDS = /* @__PURE__ */ new Set([
  12794. "w",
  12795. "wtimeout",
  12796. "j",
  12797. "fsync",
  12798. "autoIndexId",
  12799. "pkFactory",
  12800. "raw",
  12801. "readPreference",
  12802. "session",
  12803. "readConcern",
  12804. "writeConcern",
  12805. "raw",
  12806. "fieldsAsRaw",
  12807. "useBigInt64",
  12808. "promoteLongs",
  12809. "promoteValues",
  12810. "promoteBuffers",
  12811. "bsonRegExp",
  12812. "serializeFunctions",
  12813. "ignoreUndefined",
  12814. "enableUtf8Validation"
  12815. ]);
  12816. var INVALID_QE_VERSION = "Driver support of Queryable Encryption is incompatible with server. Upgrade server to use Queryable Encryption.";
  12817. var CreateCollectionOperation = class _CreateCollectionOperation extends command_1.CommandCallbackOperation {
  12818. constructor(db, name, options = {}) {
  12819. super(db, options);
  12820. this.options = options;
  12821. this.db = db;
  12822. this.name = name;
  12823. }
  12824. executeCallback(server, session, callback) {
  12825. (async () => {
  12826. var _a, _b;
  12827. const db = this.db;
  12828. const name = this.name;
  12829. const options = this.options;
  12830. const encryptedFields = options.encryptedFields ?? ((_b = (_a = db.client.options.autoEncryption) == null ? void 0 : _a.encryptedFieldsMap) == null ? void 0 : _b[`${db.databaseName}.${name}`]);
  12831. if (encryptedFields) {
  12832. if (!server.loadBalanced && server.description.maxWireVersion < constants_1.MIN_SUPPORTED_QE_WIRE_VERSION) {
  12833. throw new error_1.MongoCompatibilityError(`${INVALID_QE_VERSION} The minimum server version required is ${constants_1.MIN_SUPPORTED_QE_SERVER_VERSION}`);
  12834. }
  12835. const escCollection = encryptedFields.escCollection ?? `enxcol_.${name}.esc`;
  12836. const ecocCollection = encryptedFields.ecocCollection ?? `enxcol_.${name}.ecoc`;
  12837. for (const collectionName of [escCollection, ecocCollection]) {
  12838. const createOp = new _CreateCollectionOperation(db, collectionName, {
  12839. clusteredIndex: {
  12840. key: { _id: 1 },
  12841. unique: true
  12842. }
  12843. });
  12844. await createOp.executeWithoutEncryptedFieldsCheck(server, session);
  12845. }
  12846. if (!options.encryptedFields) {
  12847. this.options = { ...this.options, encryptedFields };
  12848. }
  12849. }
  12850. const coll = await this.executeWithoutEncryptedFieldsCheck(server, session);
  12851. if (encryptedFields) {
  12852. const createIndexOp = new indexes_1.CreateIndexOperation(db, name, { __safeContent__: 1 }, {});
  12853. await createIndexOp.execute(server, session);
  12854. }
  12855. return coll;
  12856. })().then((coll) => callback(void 0, coll), (err) => callback(err));
  12857. }
  12858. executeWithoutEncryptedFieldsCheck(server, session) {
  12859. return new Promise((resolve, reject) => {
  12860. const db = this.db;
  12861. const name = this.name;
  12862. const options = this.options;
  12863. const done = (err) => {
  12864. if (err) {
  12865. return reject(err);
  12866. }
  12867. resolve(new collection_1.Collection(db, name, options));
  12868. };
  12869. const cmd = { create: name };
  12870. for (const n in options) {
  12871. if (options[n] != null && typeof options[n] !== "function" && !ILLEGAL_COMMAND_FIELDS.has(n)) {
  12872. cmd[n] = options[n];
  12873. }
  12874. }
  12875. super.executeCommandCallback(server, session, cmd, done);
  12876. });
  12877. }
  12878. };
  12879. exports2.CreateCollectionOperation = CreateCollectionOperation;
  12880. (0, operation_1.defineAspects)(CreateCollectionOperation, [operation_1.Aspect.WRITE_OPERATION]);
  12881. }
  12882. });
  12883. // node_modules/mongodb/lib/operations/profiling_level.js
  12884. var require_profiling_level = __commonJS({
  12885. "node_modules/mongodb/lib/operations/profiling_level.js"(exports2) {
  12886. "use strict";
  12887. Object.defineProperty(exports2, "__esModule", { value: true });
  12888. exports2.ProfilingLevelOperation = void 0;
  12889. var error_1 = require_error();
  12890. var command_1 = require_command();
  12891. var ProfilingLevelOperation = class extends command_1.CommandCallbackOperation {
  12892. constructor(db, options) {
  12893. super(db, options);
  12894. this.options = options;
  12895. }
  12896. executeCallback(server, session, callback) {
  12897. super.executeCommandCallback(server, session, { profile: -1 }, (err, doc) => {
  12898. if (err == null && doc.ok === 1) {
  12899. const was = doc.was;
  12900. if (was === 0)
  12901. return callback(void 0, "off");
  12902. if (was === 1)
  12903. return callback(void 0, "slow_only");
  12904. if (was === 2)
  12905. return callback(void 0, "all");
  12906. return callback(new error_1.MongoRuntimeError(`Illegal profiling level value ${was}`));
  12907. } else {
  12908. err != null ? callback(err) : callback(new error_1.MongoRuntimeError("Error with profile command"));
  12909. }
  12910. });
  12911. }
  12912. };
  12913. exports2.ProfilingLevelOperation = ProfilingLevelOperation;
  12914. }
  12915. });
  12916. // node_modules/mongodb/lib/operations/set_profiling_level.js
  12917. var require_set_profiling_level = __commonJS({
  12918. "node_modules/mongodb/lib/operations/set_profiling_level.js"(exports2) {
  12919. "use strict";
  12920. Object.defineProperty(exports2, "__esModule", { value: true });
  12921. exports2.SetProfilingLevelOperation = exports2.ProfilingLevel = void 0;
  12922. var error_1 = require_error();
  12923. var utils_1 = require_utils();
  12924. var command_1 = require_command();
  12925. var levelValues = /* @__PURE__ */ new Set(["off", "slow_only", "all"]);
  12926. exports2.ProfilingLevel = Object.freeze({
  12927. off: "off",
  12928. slowOnly: "slow_only",
  12929. all: "all"
  12930. });
  12931. var SetProfilingLevelOperation = class extends command_1.CommandCallbackOperation {
  12932. constructor(db, level, options) {
  12933. super(db, options);
  12934. this.options = options;
  12935. switch (level) {
  12936. case exports2.ProfilingLevel.off:
  12937. this.profile = 0;
  12938. break;
  12939. case exports2.ProfilingLevel.slowOnly:
  12940. this.profile = 1;
  12941. break;
  12942. case exports2.ProfilingLevel.all:
  12943. this.profile = 2;
  12944. break;
  12945. default:
  12946. this.profile = 0;
  12947. break;
  12948. }
  12949. this.level = level;
  12950. }
  12951. executeCallback(server, session, callback) {
  12952. const level = this.level;
  12953. if (!levelValues.has(level)) {
  12954. return callback(new error_1.MongoInvalidArgumentError(`Profiling level must be one of "${(0, utils_1.enumToString)(exports2.ProfilingLevel)}"`));
  12955. }
  12956. super.executeCommandCallback(server, session, { profile: this.profile }, (err, doc) => {
  12957. if (err == null && doc.ok === 1)
  12958. return callback(void 0, level);
  12959. return err != null ? callback(err) : callback(new error_1.MongoRuntimeError("Error with profile command"));
  12960. });
  12961. }
  12962. };
  12963. exports2.SetProfilingLevelOperation = SetProfilingLevelOperation;
  12964. }
  12965. });
  12966. // node_modules/mongodb/lib/db.js
  12967. var require_db = __commonJS({
  12968. "node_modules/mongodb/lib/db.js"(exports2) {
  12969. "use strict";
  12970. Object.defineProperty(exports2, "__esModule", { value: true });
  12971. exports2.Db = void 0;
  12972. var admin_1 = require_admin();
  12973. var bson_1 = require_bson2();
  12974. var change_stream_1 = require_change_stream();
  12975. var collection_1 = require_collection();
  12976. var CONSTANTS = require_constants2();
  12977. var aggregation_cursor_1 = require_aggregation_cursor();
  12978. var list_collections_cursor_1 = require_list_collections_cursor();
  12979. var run_command_cursor_1 = require_run_command_cursor();
  12980. var error_1 = require_error();
  12981. var add_user_1 = require_add_user();
  12982. var collections_1 = require_collections();
  12983. var create_collection_1 = require_create_collection();
  12984. var drop_1 = require_drop();
  12985. var execute_operation_1 = require_execute_operation();
  12986. var indexes_1 = require_indexes();
  12987. var profiling_level_1 = require_profiling_level();
  12988. var remove_user_1 = require_remove_user();
  12989. var rename_1 = require_rename();
  12990. var run_command_1 = require_run_command();
  12991. var set_profiling_level_1 = require_set_profiling_level();
  12992. var stats_1 = require_stats();
  12993. var read_concern_1 = require_read_concern();
  12994. var read_preference_1 = require_read_preference();
  12995. var utils_1 = require_utils();
  12996. var write_concern_1 = require_write_concern();
  12997. var DB_OPTIONS_ALLOW_LIST = [
  12998. "writeConcern",
  12999. "readPreference",
  13000. "readPreferenceTags",
  13001. "native_parser",
  13002. "forceServerObjectId",
  13003. "pkFactory",
  13004. "serializeFunctions",
  13005. "raw",
  13006. "authSource",
  13007. "ignoreUndefined",
  13008. "readConcern",
  13009. "retryMiliSeconds",
  13010. "numberOfRetries",
  13011. "useBigInt64",
  13012. "promoteBuffers",
  13013. "promoteLongs",
  13014. "bsonRegExp",
  13015. "enableUtf8Validation",
  13016. "promoteValues",
  13017. "compression",
  13018. "retryWrites"
  13019. ];
  13020. var Db = class {
  13021. /**
  13022. * Creates a new Db instance
  13023. *
  13024. * @param client - The MongoClient for the database.
  13025. * @param databaseName - The name of the database this instance represents.
  13026. * @param options - Optional settings for Db construction
  13027. */
  13028. constructor(client, databaseName, options) {
  13029. options = options ?? {};
  13030. options = (0, utils_1.filterOptions)(options, DB_OPTIONS_ALLOW_LIST);
  13031. validateDatabaseName(databaseName);
  13032. this.s = {
  13033. // Options
  13034. options,
  13035. // Unpack read preference
  13036. readPreference: read_preference_1.ReadPreference.fromOptions(options),
  13037. // Merge bson options
  13038. bsonOptions: (0, bson_1.resolveBSONOptions)(options, client),
  13039. // Set up the primary key factory or fallback to ObjectId
  13040. pkFactory: (options == null ? void 0 : options.pkFactory) ?? utils_1.DEFAULT_PK_FACTORY,
  13041. // ReadConcern
  13042. readConcern: read_concern_1.ReadConcern.fromOptions(options),
  13043. writeConcern: write_concern_1.WriteConcern.fromOptions(options),
  13044. // Namespace
  13045. namespace: new utils_1.MongoDBNamespace(databaseName)
  13046. };
  13047. this.client = client;
  13048. }
  13049. get databaseName() {
  13050. return this.s.namespace.db;
  13051. }
  13052. // Options
  13053. get options() {
  13054. return this.s.options;
  13055. }
  13056. /**
  13057. * Check if a secondary can be used (because the read preference is *not* set to primary)
  13058. */
  13059. get secondaryOk() {
  13060. var _a;
  13061. return ((_a = this.s.readPreference) == null ? void 0 : _a.preference) !== "primary" || false;
  13062. }
  13063. get readConcern() {
  13064. return this.s.readConcern;
  13065. }
  13066. /**
  13067. * The current readPreference of the Db. If not explicitly defined for
  13068. * this Db, will be inherited from the parent MongoClient
  13069. */
  13070. get readPreference() {
  13071. if (this.s.readPreference == null) {
  13072. return this.client.readPreference;
  13073. }
  13074. return this.s.readPreference;
  13075. }
  13076. get bsonOptions() {
  13077. return this.s.bsonOptions;
  13078. }
  13079. // get the write Concern
  13080. get writeConcern() {
  13081. return this.s.writeConcern;
  13082. }
  13083. get namespace() {
  13084. return this.s.namespace.toString();
  13085. }
  13086. /**
  13087. * Create a new collection on a server with the specified options. Use this to create capped collections.
  13088. * More information about command options available at https://www.mongodb.com/docs/manual/reference/command/create/
  13089. *
  13090. * @param name - The name of the collection to create
  13091. * @param options - Optional settings for the command
  13092. */
  13093. async createCollection(name, options) {
  13094. return (0, execute_operation_1.executeOperation)(this.client, new create_collection_1.CreateCollectionOperation(this, name, (0, utils_1.resolveOptions)(this, options)));
  13095. }
  13096. /**
  13097. * Execute a command
  13098. *
  13099. * @remarks
  13100. * This command does not inherit options from the MongoClient.
  13101. *
  13102. * The driver will ensure the following fields are attached to the command sent to the server:
  13103. * - `lsid` - sourced from an implicit session or options.session
  13104. * - `$readPreference` - defaults to primary or can be configured by options.readPreference
  13105. * - `$db` - sourced from the name of this database
  13106. *
  13107. * If the client has a serverApi setting:
  13108. * - `apiVersion`
  13109. * - `apiStrict`
  13110. * - `apiDeprecationErrors`
  13111. *
  13112. * When in a transaction:
  13113. * - `readConcern` - sourced from readConcern set on the TransactionOptions
  13114. * - `writeConcern` - sourced from writeConcern set on the TransactionOptions
  13115. *
  13116. * Attaching any of the above fields to the command will have no effect as the driver will overwrite the value.
  13117. *
  13118. * @param command - The command to run
  13119. * @param options - Optional settings for the command
  13120. */
  13121. async command(command, options) {
  13122. return (0, execute_operation_1.executeOperation)(this.client, new run_command_1.RunCommandOperation(this, command, options));
  13123. }
  13124. /**
  13125. * Execute an aggregation framework pipeline against the database, needs MongoDB \>= 3.6
  13126. *
  13127. * @param pipeline - An array of aggregation stages to be executed
  13128. * @param options - Optional settings for the command
  13129. */
  13130. aggregate(pipeline = [], options) {
  13131. return new aggregation_cursor_1.AggregationCursor(this.client, this.s.namespace, pipeline, (0, utils_1.resolveOptions)(this, options));
  13132. }
  13133. /** Return the Admin db instance */
  13134. admin() {
  13135. return new admin_1.Admin(this);
  13136. }
  13137. /**
  13138. * Returns a reference to a MongoDB Collection. If it does not exist it will be created implicitly.
  13139. *
  13140. * @param name - the collection name we wish to access.
  13141. * @returns return the new Collection instance
  13142. */
  13143. collection(name, options = {}) {
  13144. if (typeof options === "function") {
  13145. throw new error_1.MongoInvalidArgumentError("The callback form of this helper has been removed.");
  13146. }
  13147. return new collection_1.Collection(this, name, (0, utils_1.resolveOptions)(this, options));
  13148. }
  13149. /**
  13150. * Get all the db statistics.
  13151. *
  13152. * @param options - Optional settings for the command
  13153. */
  13154. async stats(options) {
  13155. return (0, execute_operation_1.executeOperation)(this.client, new stats_1.DbStatsOperation(this, (0, utils_1.resolveOptions)(this, options)));
  13156. }
  13157. listCollections(filter = {}, options = {}) {
  13158. return new list_collections_cursor_1.ListCollectionsCursor(this, filter, (0, utils_1.resolveOptions)(this, options));
  13159. }
  13160. /**
  13161. * Rename a collection.
  13162. *
  13163. * @remarks
  13164. * This operation does not inherit options from the MongoClient.
  13165. *
  13166. * @param fromCollection - Name of current collection to rename
  13167. * @param toCollection - New name of of the collection
  13168. * @param options - Optional settings for the command
  13169. */
  13170. async renameCollection(fromCollection, toCollection, options) {
  13171. return (0, execute_operation_1.executeOperation)(this.client, new rename_1.RenameOperation(this.collection(fromCollection), toCollection, { ...options, new_collection: true, readPreference: read_preference_1.ReadPreference.primary }));
  13172. }
  13173. /**
  13174. * Drop a collection from the database, removing it permanently. New accesses will create a new collection.
  13175. *
  13176. * @param name - Name of collection to drop
  13177. * @param options - Optional settings for the command
  13178. */
  13179. async dropCollection(name, options) {
  13180. return (0, execute_operation_1.executeOperation)(this.client, new drop_1.DropCollectionOperation(this, name, (0, utils_1.resolveOptions)(this, options)));
  13181. }
  13182. /**
  13183. * Drop a database, removing it permanently from the server.
  13184. *
  13185. * @param options - Optional settings for the command
  13186. */
  13187. async dropDatabase(options) {
  13188. return (0, execute_operation_1.executeOperation)(this.client, new drop_1.DropDatabaseOperation(this, (0, utils_1.resolveOptions)(this, options)));
  13189. }
  13190. /**
  13191. * Fetch all collections for the current db.
  13192. *
  13193. * @param options - Optional settings for the command
  13194. */
  13195. async collections(options) {
  13196. return (0, execute_operation_1.executeOperation)(this.client, new collections_1.CollectionsOperation(this, (0, utils_1.resolveOptions)(this, options)));
  13197. }
  13198. /**
  13199. * Creates an index on the db and collection.
  13200. *
  13201. * @param name - Name of the collection to create the index on.
  13202. * @param indexSpec - Specify the field to index, or an index specification
  13203. * @param options - Optional settings for the command
  13204. */
  13205. async createIndex(name, indexSpec, options) {
  13206. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.CreateIndexOperation(this, name, indexSpec, (0, utils_1.resolveOptions)(this, options)));
  13207. }
  13208. /**
  13209. * Add a user to the database
  13210. *
  13211. * @param username - The username for the new user
  13212. * @param passwordOrOptions - An optional password for the new user, or the options for the command
  13213. * @param options - Optional settings for the command
  13214. * @deprecated Use the createUser command in `db.command()` instead.
  13215. * @see https://www.mongodb.com/docs/manual/reference/command/createUser/
  13216. */
  13217. async addUser(username, passwordOrOptions, options) {
  13218. options = options != null && typeof options === "object" ? options : passwordOrOptions != null && typeof passwordOrOptions === "object" ? passwordOrOptions : void 0;
  13219. const password = typeof passwordOrOptions === "string" ? passwordOrOptions : void 0;
  13220. return (0, execute_operation_1.executeOperation)(this.client, new add_user_1.AddUserOperation(this, username, password, (0, utils_1.resolveOptions)(this, options)));
  13221. }
  13222. /**
  13223. * Remove a user from a database
  13224. *
  13225. * @param username - The username to remove
  13226. * @param options - Optional settings for the command
  13227. */
  13228. async removeUser(username, options) {
  13229. return (0, execute_operation_1.executeOperation)(this.client, new remove_user_1.RemoveUserOperation(this, username, (0, utils_1.resolveOptions)(this, options)));
  13230. }
  13231. /**
  13232. * Set the current profiling level of MongoDB
  13233. *
  13234. * @param level - The new profiling level (off, slow_only, all).
  13235. * @param options - Optional settings for the command
  13236. */
  13237. async setProfilingLevel(level, options) {
  13238. return (0, execute_operation_1.executeOperation)(this.client, new set_profiling_level_1.SetProfilingLevelOperation(this, level, (0, utils_1.resolveOptions)(this, options)));
  13239. }
  13240. /**
  13241. * Retrieve the current profiling Level for MongoDB
  13242. *
  13243. * @param options - Optional settings for the command
  13244. */
  13245. async profilingLevel(options) {
  13246. return (0, execute_operation_1.executeOperation)(this.client, new profiling_level_1.ProfilingLevelOperation(this, (0, utils_1.resolveOptions)(this, options)));
  13247. }
  13248. /**
  13249. * Retrieves this collections index info.
  13250. *
  13251. * @param name - The name of the collection.
  13252. * @param options - Optional settings for the command
  13253. */
  13254. async indexInformation(name, options) {
  13255. return (0, execute_operation_1.executeOperation)(this.client, new indexes_1.IndexInformationOperation(this, name, (0, utils_1.resolveOptions)(this, options)));
  13256. }
  13257. /**
  13258. * Create a new Change Stream, watching for new changes (insertions, updates,
  13259. * replacements, deletions, and invalidations) in this database. Will ignore all
  13260. * changes to system collections.
  13261. *
  13262. * @remarks
  13263. * watch() accepts two generic arguments for distinct use cases:
  13264. * - The first is to provide the schema that may be defined for all the collections within this database
  13265. * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
  13266. *
  13267. * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
  13268. * @param options - Optional settings for the command
  13269. * @typeParam TSchema - Type of the data being detected by the change stream
  13270. * @typeParam TChange - Type of the whole change stream document emitted
  13271. */
  13272. watch(pipeline = [], options = {}) {
  13273. if (!Array.isArray(pipeline)) {
  13274. options = pipeline;
  13275. pipeline = [];
  13276. }
  13277. return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
  13278. }
  13279. /**
  13280. * A low level cursor API providing basic driver functionality:
  13281. * - ClientSession management
  13282. * - ReadPreference for server selection
  13283. * - Running getMores automatically when a local batch is exhausted
  13284. *
  13285. * @param command - The command that will start a cursor on the server.
  13286. * @param options - Configurations for running the command, bson options will apply to getMores
  13287. */
  13288. runCursorCommand(command, options) {
  13289. return new run_command_cursor_1.RunCommandCursor(this, command, options);
  13290. }
  13291. };
  13292. Db.SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION;
  13293. Db.SYSTEM_INDEX_COLLECTION = CONSTANTS.SYSTEM_INDEX_COLLECTION;
  13294. Db.SYSTEM_PROFILE_COLLECTION = CONSTANTS.SYSTEM_PROFILE_COLLECTION;
  13295. Db.SYSTEM_USER_COLLECTION = CONSTANTS.SYSTEM_USER_COLLECTION;
  13296. Db.SYSTEM_COMMAND_COLLECTION = CONSTANTS.SYSTEM_COMMAND_COLLECTION;
  13297. Db.SYSTEM_JS_COLLECTION = CONSTANTS.SYSTEM_JS_COLLECTION;
  13298. exports2.Db = Db;
  13299. function validateDatabaseName(databaseName) {
  13300. if (typeof databaseName !== "string")
  13301. throw new error_1.MongoInvalidArgumentError("Database name must be a string");
  13302. if (databaseName.length === 0)
  13303. throw new error_1.MongoInvalidArgumentError("Database name cannot be the empty string");
  13304. if (databaseName === "$external")
  13305. return;
  13306. const invalidChars = [" ", ".", "$", "/", "\\"];
  13307. for (let i = 0; i < invalidChars.length; i++) {
  13308. if (databaseName.indexOf(invalidChars[i]) !== -1)
  13309. throw new error_1.MongoAPIError(`database names cannot contain the character '${invalidChars[i]}'`);
  13310. }
  13311. }
  13312. }
  13313. });
  13314. // node_modules/@mongodb-js/saslprep/dist/index.js
  13315. var require_dist = __commonJS({
  13316. "node_modules/@mongodb-js/saslprep/dist/index.js"(exports2, module2) {
  13317. "use strict";
  13318. var getCodePoint = (character) => character.codePointAt(0);
  13319. var first = (x) => x[0];
  13320. var last = (x) => x[x.length - 1];
  13321. function toCodePoints(input) {
  13322. const codepoints = [];
  13323. const size = input.length;
  13324. for (let i = 0; i < size; i += 1) {
  13325. const before = input.charCodeAt(i);
  13326. if (before >= 55296 && before <= 56319 && size > i + 1) {
  13327. const next = input.charCodeAt(i + 1);
  13328. if (next >= 56320 && next <= 57343) {
  13329. codepoints.push((before - 55296) * 1024 + next - 56320 + 65536);
  13330. i += 1;
  13331. continue;
  13332. }
  13333. }
  13334. codepoints.push(before);
  13335. }
  13336. return codepoints;
  13337. }
  13338. function saslprep({ unassigned_code_points, commonly_mapped_to_nothing, non_ASCII_space_characters, prohibited_characters, bidirectional_r_al, bidirectional_l }, input, opts = {}) {
  13339. const mapping2space = non_ASCII_space_characters;
  13340. const mapping2nothing = commonly_mapped_to_nothing;
  13341. if (typeof input !== "string") {
  13342. throw new TypeError("Expected string.");
  13343. }
  13344. if (input.length === 0) {
  13345. return "";
  13346. }
  13347. const mapped_input = toCodePoints(input).map((character) => mapping2space.get(character) ? 32 : character).filter((character) => !mapping2nothing.get(character));
  13348. const normalized_input = String.fromCodePoint.apply(null, mapped_input).normalize("NFKC");
  13349. const normalized_map = toCodePoints(normalized_input);
  13350. const hasProhibited = normalized_map.some((character) => prohibited_characters.get(character));
  13351. if (hasProhibited) {
  13352. throw new Error("Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3");
  13353. }
  13354. if (opts.allowUnassigned !== true) {
  13355. const hasUnassigned = normalized_map.some((character) => unassigned_code_points.get(character));
  13356. if (hasUnassigned) {
  13357. throw new Error("Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5");
  13358. }
  13359. }
  13360. const hasBidiRAL = normalized_map.some((character) => bidirectional_r_al.get(character));
  13361. const hasBidiL = normalized_map.some((character) => bidirectional_l.get(character));
  13362. if (hasBidiRAL && hasBidiL) {
  13363. throw new Error("String must not contain RandALCat and LCat at the same time, see https://tools.ietf.org/html/rfc3454#section-6");
  13364. }
  13365. const isFirstBidiRAL = bidirectional_r_al.get(getCodePoint(first(normalized_input)));
  13366. const isLastBidiRAL = bidirectional_r_al.get(getCodePoint(last(normalized_input)));
  13367. if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) {
  13368. throw new Error("Bidirectional RandALCat character must be the first and the last character of the string, see https://tools.ietf.org/html/rfc3454#section-6");
  13369. }
  13370. return normalized_input;
  13371. }
  13372. saslprep.saslprep = saslprep;
  13373. saslprep.default = saslprep;
  13374. module2.exports = saslprep;
  13375. }
  13376. });
  13377. // node_modules/memory-pager/index.js
  13378. var require_memory_pager = __commonJS({
  13379. "node_modules/memory-pager/index.js"(exports2, module2) {
  13380. module2.exports = Pager;
  13381. function Pager(pageSize, opts) {
  13382. if (!(this instanceof Pager)) return new Pager(pageSize, opts);
  13383. this.length = 0;
  13384. this.updates = [];
  13385. this.path = new Uint16Array(4);
  13386. this.pages = new Array(32768);
  13387. this.maxPages = this.pages.length;
  13388. this.level = 0;
  13389. this.pageSize = pageSize || 1024;
  13390. this.deduplicate = opts ? opts.deduplicate : null;
  13391. this.zeros = this.deduplicate ? alloc(this.deduplicate.length) : null;
  13392. }
  13393. Pager.prototype.updated = function(page) {
  13394. while (this.deduplicate && page.buffer[page.deduplicate] === this.deduplicate[page.deduplicate]) {
  13395. page.deduplicate++;
  13396. if (page.deduplicate === this.deduplicate.length) {
  13397. page.deduplicate = 0;
  13398. if (page.buffer.equals && page.buffer.equals(this.deduplicate)) page.buffer = this.deduplicate;
  13399. break;
  13400. }
  13401. }
  13402. if (page.updated || !this.updates) return;
  13403. page.updated = true;
  13404. this.updates.push(page);
  13405. };
  13406. Pager.prototype.lastUpdate = function() {
  13407. if (!this.updates || !this.updates.length) return null;
  13408. var page = this.updates.pop();
  13409. page.updated = false;
  13410. return page;
  13411. };
  13412. Pager.prototype._array = function(i, noAllocate) {
  13413. if (i >= this.maxPages) {
  13414. if (noAllocate) return;
  13415. grow(this, i);
  13416. }
  13417. factor(i, this.path);
  13418. var arr = this.pages;
  13419. for (var j = this.level; j > 0; j--) {
  13420. var p = this.path[j];
  13421. var next = arr[p];
  13422. if (!next) {
  13423. if (noAllocate) return;
  13424. next = arr[p] = new Array(32768);
  13425. }
  13426. arr = next;
  13427. }
  13428. return arr;
  13429. };
  13430. Pager.prototype.get = function(i, noAllocate) {
  13431. var arr = this._array(i, noAllocate);
  13432. var first = this.path[0];
  13433. var page = arr && arr[first];
  13434. if (!page && !noAllocate) {
  13435. page = arr[first] = new Page(i, alloc(this.pageSize));
  13436. if (i >= this.length) this.length = i + 1;
  13437. }
  13438. if (page && page.buffer === this.deduplicate && this.deduplicate && !noAllocate) {
  13439. page.buffer = copy(page.buffer);
  13440. page.deduplicate = 0;
  13441. }
  13442. return page;
  13443. };
  13444. Pager.prototype.set = function(i, buf) {
  13445. var arr = this._array(i, false);
  13446. var first = this.path[0];
  13447. if (i >= this.length) this.length = i + 1;
  13448. if (!buf || this.zeros && buf.equals && buf.equals(this.zeros)) {
  13449. arr[first] = void 0;
  13450. return;
  13451. }
  13452. if (this.deduplicate && buf.equals && buf.equals(this.deduplicate)) {
  13453. buf = this.deduplicate;
  13454. }
  13455. var page = arr[first];
  13456. var b = truncate(buf, this.pageSize);
  13457. if (page) page.buffer = b;
  13458. else arr[first] = new Page(i, b);
  13459. };
  13460. Pager.prototype.toBuffer = function() {
  13461. var list = new Array(this.length);
  13462. var empty = alloc(this.pageSize);
  13463. var ptr = 0;
  13464. while (ptr < list.length) {
  13465. var arr = this._array(ptr, true);
  13466. for (var i = 0; i < 32768 && ptr < list.length; i++) {
  13467. list[ptr++] = arr && arr[i] ? arr[i].buffer : empty;
  13468. }
  13469. }
  13470. return Buffer.concat(list);
  13471. };
  13472. function grow(pager, index) {
  13473. while (pager.maxPages < index) {
  13474. var old = pager.pages;
  13475. pager.pages = new Array(32768);
  13476. pager.pages[0] = old;
  13477. pager.level++;
  13478. pager.maxPages *= 32768;
  13479. }
  13480. }
  13481. function truncate(buf, len) {
  13482. if (buf.length === len) return buf;
  13483. if (buf.length > len) return buf.slice(0, len);
  13484. var cpy = alloc(len);
  13485. buf.copy(cpy);
  13486. return cpy;
  13487. }
  13488. function alloc(size) {
  13489. if (Buffer.alloc) return Buffer.alloc(size);
  13490. var buf = new Buffer(size);
  13491. buf.fill(0);
  13492. return buf;
  13493. }
  13494. function copy(buf) {
  13495. var cpy = Buffer.allocUnsafe ? Buffer.allocUnsafe(buf.length) : new Buffer(buf.length);
  13496. buf.copy(cpy);
  13497. return cpy;
  13498. }
  13499. function Page(i, buf) {
  13500. this.offset = i * buf.length;
  13501. this.buffer = buf;
  13502. this.updated = false;
  13503. this.deduplicate = 0;
  13504. }
  13505. function factor(n, out) {
  13506. n = (n - (out[0] = n & 32767)) / 32768;
  13507. n = (n - (out[1] = n & 32767)) / 32768;
  13508. out[3] = (n - (out[2] = n & 32767)) / 32768 & 32767;
  13509. }
  13510. }
  13511. });
  13512. // node_modules/sparse-bitfield/index.js
  13513. var require_sparse_bitfield = __commonJS({
  13514. "node_modules/sparse-bitfield/index.js"(exports2, module2) {
  13515. var pager = require_memory_pager();
  13516. module2.exports = Bitfield;
  13517. function Bitfield(opts) {
  13518. if (!(this instanceof Bitfield)) return new Bitfield(opts);
  13519. if (!opts) opts = {};
  13520. if (Buffer.isBuffer(opts)) opts = { buffer: opts };
  13521. this.pageOffset = opts.pageOffset || 0;
  13522. this.pageSize = opts.pageSize || 1024;
  13523. this.pages = opts.pages || pager(this.pageSize);
  13524. this.byteLength = this.pages.length * this.pageSize;
  13525. this.length = 8 * this.byteLength;
  13526. if (!powerOfTwo(this.pageSize)) throw new Error("The page size should be a power of two");
  13527. this._trackUpdates = !!opts.trackUpdates;
  13528. this._pageMask = this.pageSize - 1;
  13529. if (opts.buffer) {
  13530. for (var i = 0; i < opts.buffer.length; i += this.pageSize) {
  13531. this.pages.set(i / this.pageSize, opts.buffer.slice(i, i + this.pageSize));
  13532. }
  13533. this.byteLength = opts.buffer.length;
  13534. this.length = 8 * this.byteLength;
  13535. }
  13536. }
  13537. Bitfield.prototype.get = function(i) {
  13538. var o = i & 7;
  13539. var j = (i - o) / 8;
  13540. return !!(this.getByte(j) & 128 >> o);
  13541. };
  13542. Bitfield.prototype.getByte = function(i) {
  13543. var o = i & this._pageMask;
  13544. var j = (i - o) / this.pageSize;
  13545. var page = this.pages.get(j, true);
  13546. return page ? page.buffer[o + this.pageOffset] : 0;
  13547. };
  13548. Bitfield.prototype.set = function(i, v) {
  13549. var o = i & 7;
  13550. var j = (i - o) / 8;
  13551. var b = this.getByte(j);
  13552. return this.setByte(j, v ? b | 128 >> o : b & (255 ^ 128 >> o));
  13553. };
  13554. Bitfield.prototype.toBuffer = function() {
  13555. var all = alloc(this.pages.length * this.pageSize);
  13556. for (var i = 0; i < this.pages.length; i++) {
  13557. var next = this.pages.get(i, true);
  13558. var allOffset = i * this.pageSize;
  13559. if (next) next.buffer.copy(all, allOffset, this.pageOffset, this.pageOffset + this.pageSize);
  13560. }
  13561. return all;
  13562. };
  13563. Bitfield.prototype.setByte = function(i, b) {
  13564. var o = i & this._pageMask;
  13565. var j = (i - o) / this.pageSize;
  13566. var page = this.pages.get(j, false);
  13567. o += this.pageOffset;
  13568. if (page.buffer[o] === b) return false;
  13569. page.buffer[o] = b;
  13570. if (i >= this.byteLength) {
  13571. this.byteLength = i + 1;
  13572. this.length = this.byteLength * 8;
  13573. }
  13574. if (this._trackUpdates) this.pages.updated(page);
  13575. return true;
  13576. };
  13577. function alloc(n) {
  13578. if (Buffer.alloc) return Buffer.alloc(n);
  13579. var b = new Buffer(n);
  13580. b.fill(0);
  13581. return b;
  13582. }
  13583. function powerOfTwo(x) {
  13584. return !(x & x - 1);
  13585. }
  13586. }
  13587. });
  13588. // node_modules/@mongodb-js/saslprep/dist/memory-code-points.js
  13589. var require_memory_code_points = __commonJS({
  13590. "node_modules/@mongodb-js/saslprep/dist/memory-code-points.js"(exports2) {
  13591. "use strict";
  13592. var __importDefault = exports2 && exports2.__importDefault || function(mod) {
  13593. return mod && mod.__esModule ? mod : { "default": mod };
  13594. };
  13595. Object.defineProperty(exports2, "__esModule", { value: true });
  13596. exports2.createMemoryCodePoints = void 0;
  13597. var sparse_bitfield_1 = __importDefault(require_sparse_bitfield());
  13598. function createMemoryCodePoints(data) {
  13599. let offset = 0;
  13600. function read() {
  13601. const size = data.readUInt32BE(offset);
  13602. offset += 4;
  13603. const codepoints = data.slice(offset, offset + size);
  13604. offset += size;
  13605. return (0, sparse_bitfield_1.default)({ buffer: codepoints });
  13606. }
  13607. const unassigned_code_points = read();
  13608. const commonly_mapped_to_nothing = read();
  13609. const non_ASCII_space_characters = read();
  13610. const prohibited_characters = read();
  13611. const bidirectional_r_al = read();
  13612. const bidirectional_l = read();
  13613. return {
  13614. unassigned_code_points,
  13615. commonly_mapped_to_nothing,
  13616. non_ASCII_space_characters,
  13617. prohibited_characters,
  13618. bidirectional_r_al,
  13619. bidirectional_l
  13620. };
  13621. }
  13622. exports2.createMemoryCodePoints = createMemoryCodePoints;
  13623. }
  13624. });
  13625. // node_modules/@mongodb-js/saslprep/dist/code-points-data.js
  13626. var require_code_points_data = __commonJS({
  13627. "node_modules/@mongodb-js/saslprep/dist/code-points-data.js"(exports2) {
  13628. "use strict";
  13629. Object.defineProperty(exports2, "__esModule", { value: true });
  13630. var zlib_1 = require("zlib");
  13631. exports2.default = (0, zlib_1.gunzipSync)(Buffer.from("H4sIAAAAAAACA+3dTYgcaRkA4LemO9Mhxm0FITnE9Cwr4jHgwgZ22B6YywqCJ0HQg5CL4sGTuOjCtGSF4CkHEW856MlTQHD3EJnWkU0Owh5VxE3LHlYQdNxd2U6mU59UV/d09fw4M2EySSXPAzNdP1/9fX/99bzVNZEN4jisRDulVFnQmLxm1aXF9Id/2/xMxNJ4XZlg576yuYlGt9gupV6xoFf8jhu9YvulVrFlp5XSx+lfvYhORGPXvqIRWSxERKtIm8bKFd10WNfKDS5Fo9jJWrq2+M2IlW+8uHgl/+BsROfPF4v5L7148Ur68Sha6dqZpYiVVy8tvLCWXo80Sf/lS89dGX2wHGvpzoXVn75/YWH5wmqe8uika82ViJXTy83Ve2k5Urozm38wm4/ls6t5uT6yfsTSJ7J3T0VKt8c5ExEXI8aFkH729c3eT+7EC6ca8cVULZUiYacX0R5PNWNxlh9L1y90q5kyzrpyy+9WcvOV6URntqw7La9sNVstXyczWVaWYbaaTYqzOHpr7pyiNT3/YzKuT63Z/FqKZlFTiuXtFM2vVOtIq7jiyKJbWZaOWD0euz0yoV2Z7kY0xq2x0YhfzVpmM5px9nTEH7JZ0ot5u39p0ma75Z472/s/H+2yr2inYyuq7fMvJivH2rM72N/Z3lyL31F2b1ya1P0zn816k2KP6JU9UzseucdQH5YqVeH/lFajSN2udg+TLJ9rksNxlvV2lki19rXKI43TPLejFu4ov7k3nMbhyhfY3Xb37f8BAGCf0eMTOH5szf154KmnNgKcnLb+Fzi2AfXktbN7fJelwTAiO/W5uQ2KINXRYu+znqo/WTAdLadURHmy3qciazd3bra4T3w16/f7t7Ms9U5gfJu10955sx1r3vmhBAAAAAAAgId20J1iZbDowNvIjuH427Gr5l/eiC+8OplZON8sVjx/qr9y+Pj+YRItT+NqAM+kkZs3AAAAAID6yfx1FwCAI97/dCh1/ub6SA0AAAAAAAAAgNoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hP/BwAAAAAAAID6E/8HAAAAAAAAgPoT/wcAAAAAAACA+hutp5SiQpYAAAAAAAAAQO2MIpZiT804flnAE2fhwjOeAZXr76kOAAAAAAAA8FjNf4N/l0NE3U/vuVQskLpSd4/Yh2xu9xTu0tFeeNYsLI2f/VMdNxTzj6Je9E/+6pp6Nn3awW3A54goe4Bss6v+PGsjQGMAAAAAAOBp5XEgwH6e7J7rwEQHRb/XvAMAAAAAAAA8yzoDeQDwVGjIAgAAAAAAAACoPfF/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqD/xfwAAAAAAAACoP/F/AAAAAAAAAKg/8X8AAAAAAAAAqL/GSkSkClkCAAAAAAAAALXTSAAAAAAAAABA3Y1kAQAAAAAAAADUX8RSXZ9dsHC9+M8Fg2Ex/em1lAZpEBGttcrVjZqLEa+k0XpKw9mG4zWx4ukPUMhkAQAAAAAAABzBqbSe3//rXOS9HxGdo4TqR2XkutCdBu+LaPZw/lBbO7cbHnh2C7N7AIo4evEznllqLqWUp/LnYOtpM2bnOH66wI1+9GO4sOuISwv/TOlumu56FDv3NZhc4mR9v7zYIrafr40j/Cccvj9Xns3t3mu99E7qxUv3bqS0/ouNH/08++RGemfQ+nsx/5uNXsQPGulynPvv3ZTW37zd+1ovrqaYpP/122X6Xpx779Z3zr/3YOPKW1lkaRDf31pPaf3j/msRsVGkL+d/f+/m4sJsPm1cfSsr16e8m9Ldj/KsnyIuR3nXw83Is3EhxLd/2V773ks3m/cj/THKUummdP9qKhIOImuOU0Xjwb3y+oqt735rpTetVbF9n8R4x9crRfO77TKqVOZpDclv5bfK18lMnk+q0K18UpxF/RrGXE0Zxtqx3tWSj+vxbL4XaasfKb0dRbtLW73JsfPGg177H+OmGKlfvS1msllt7JEJm9XOJqXR+Fkfo1H66uy5H1v3Xx5+uJmGLw9jro2u7Loj4PnuR6+f+e3d261+eazNhzrL7X83MohoHpS4PddV8ki1it61//pw1g7z6p1U/26Nm2llST57B5rUvuG0XqSU/rPd7jYrqWcbd+beJQ77BgPMDwn37/8BAGCf0eMTOH4cPlufv9VGgJOzqf8Fjm1APXkd7B7f5dF57GPMaWy/MTvjvNvtXj6h8W2+GXvnzXaseeeHEgAAAAAAAB7aQXeKlcGiadBoEOeLb2dtpGOL2MyOtf391a3P/zD96c3JzIP3t4oV797vrh8+vn+YRL5bBuj/AQAAAABqJvfHXQAAHkX82zfXAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACeAgkAAAAAAAAAqLuRLAAAAAAAAACA2hv9D1iu/VAYaAYA", "base64"));
  13632. }
  13633. });
  13634. // node_modules/@mongodb-js/saslprep/dist/node.js
  13635. var require_node = __commonJS({
  13636. "node_modules/@mongodb-js/saslprep/dist/node.js"(exports2, module2) {
  13637. "use strict";
  13638. var __importDefault = exports2 && exports2.__importDefault || function(mod) {
  13639. return mod && mod.__esModule ? mod : { "default": mod };
  13640. };
  13641. var index_1 = __importDefault(require_dist());
  13642. var memory_code_points_1 = require_memory_code_points();
  13643. var code_points_data_1 = __importDefault(require_code_points_data());
  13644. var codePoints = (0, memory_code_points_1.createMemoryCodePoints)(code_points_data_1.default);
  13645. function saslprep(input, opts) {
  13646. return (0, index_1.default)(codePoints, input, opts);
  13647. }
  13648. saslprep.saslprep = saslprep;
  13649. saslprep.default = saslprep;
  13650. module2.exports = saslprep;
  13651. }
  13652. });
  13653. // node_modules/mongodb/lib/deps.js
  13654. var require_deps = __commonJS({
  13655. "node_modules/mongodb/lib/deps.js"(exports2) {
  13656. "use strict";
  13657. Object.defineProperty(exports2, "__esModule", { value: true });
  13658. exports2.AutoEncryptionLoggerLevel = exports2.aws4 = exports2.saslprep = exports2.getSnappy = exports2.getAwsCredentialProvider = exports2.getZstdLibrary = exports2.ZStandard = exports2.getKerberos = exports2.Kerberos = void 0;
  13659. var error_1 = require_error();
  13660. function makeErrorModule(error) {
  13661. const props = error ? { kModuleError: error } : {};
  13662. return new Proxy(props, {
  13663. get: (_, key) => {
  13664. if (key === "kModuleError") {
  13665. return error;
  13666. }
  13667. throw error;
  13668. },
  13669. set: () => {
  13670. throw error;
  13671. }
  13672. });
  13673. }
  13674. exports2.Kerberos = makeErrorModule(new error_1.MongoMissingDependencyError("Optional module `kerberos` not found. Please install it to enable kerberos authentication"));
  13675. function getKerberos() {
  13676. try {
  13677. exports2.Kerberos = require("kerberos");
  13678. return exports2.Kerberos;
  13679. } catch {
  13680. return exports2.Kerberos;
  13681. }
  13682. }
  13683. exports2.getKerberos = getKerberos;
  13684. exports2.ZStandard = makeErrorModule(new error_1.MongoMissingDependencyError("Optional module `@mongodb-js/zstd` not found. Please install it to enable zstd compression"));
  13685. function getZstdLibrary() {
  13686. try {
  13687. exports2.ZStandard = require("@mongodb-js/zstd");
  13688. return exports2.ZStandard;
  13689. } catch {
  13690. return exports2.ZStandard;
  13691. }
  13692. }
  13693. exports2.getZstdLibrary = getZstdLibrary;
  13694. function getAwsCredentialProvider() {
  13695. try {
  13696. const credentialProvider = require("@aws-sdk/credential-providers");
  13697. return credentialProvider;
  13698. } catch {
  13699. return makeErrorModule(new error_1.MongoMissingDependencyError("Optional module `@aws-sdk/credential-providers` not found. Please install it to enable getting aws credentials via the official sdk."));
  13700. }
  13701. }
  13702. exports2.getAwsCredentialProvider = getAwsCredentialProvider;
  13703. function getSnappy() {
  13704. try {
  13705. const value = require("snappy");
  13706. return value;
  13707. } catch (cause) {
  13708. const kModuleError = new error_1.MongoMissingDependencyError("Optional module `snappy` not found. Please install it to enable snappy compression", { cause });
  13709. return { kModuleError };
  13710. }
  13711. }
  13712. exports2.getSnappy = getSnappy;
  13713. exports2.saslprep = makeErrorModule(new error_1.MongoMissingDependencyError("Optional module `saslprep` not found. Please install it to enable Stringprep Profile for User Names and Passwords"));
  13714. try {
  13715. exports2.saslprep = require_node();
  13716. } catch {
  13717. }
  13718. exports2.aws4 = makeErrorModule(new error_1.MongoMissingDependencyError("Optional module `aws4` not found. Please install it to enable AWS authentication"));
  13719. try {
  13720. exports2.aws4 = require("aws4");
  13721. } catch {
  13722. }
  13723. exports2.AutoEncryptionLoggerLevel = Object.freeze({
  13724. FatalError: 0,
  13725. Error: 1,
  13726. Warning: 2,
  13727. Info: 3,
  13728. Trace: 4
  13729. });
  13730. }
  13731. });
  13732. // node_modules/mongodb/lib/cmap/auth/auth_provider.js
  13733. var require_auth_provider = __commonJS({
  13734. "node_modules/mongodb/lib/cmap/auth/auth_provider.js"(exports2) {
  13735. "use strict";
  13736. Object.defineProperty(exports2, "__esModule", { value: true });
  13737. exports2.AuthProvider = exports2.AuthContext = void 0;
  13738. var error_1 = require_error();
  13739. var AuthContext = class {
  13740. constructor(connection, credentials, options) {
  13741. this.reauthenticating = false;
  13742. this.connection = connection;
  13743. this.credentials = credentials;
  13744. this.options = options;
  13745. }
  13746. };
  13747. exports2.AuthContext = AuthContext;
  13748. var AuthProvider = class {
  13749. /**
  13750. * Prepare the handshake document before the initial handshake.
  13751. *
  13752. * @param handshakeDoc - The document used for the initial handshake on a connection
  13753. * @param authContext - Context for authentication flow
  13754. */
  13755. async prepare(handshakeDoc, _authContext) {
  13756. return handshakeDoc;
  13757. }
  13758. /**
  13759. * Reauthenticate.
  13760. * @param context - The shared auth context.
  13761. */
  13762. async reauth(context) {
  13763. if (context.reauthenticating) {
  13764. throw new error_1.MongoRuntimeError("Reauthentication already in progress.");
  13765. }
  13766. try {
  13767. context.reauthenticating = true;
  13768. await this.auth(context);
  13769. } finally {
  13770. context.reauthenticating = false;
  13771. }
  13772. }
  13773. };
  13774. exports2.AuthProvider = AuthProvider;
  13775. }
  13776. });
  13777. // node_modules/mongodb/lib/cmap/auth/gssapi.js
  13778. var require_gssapi = __commonJS({
  13779. "node_modules/mongodb/lib/cmap/auth/gssapi.js"(exports2) {
  13780. "use strict";
  13781. Object.defineProperty(exports2, "__esModule", { value: true });
  13782. exports2.resolveCname = exports2.performGSSAPICanonicalizeHostName = exports2.GSSAPI = exports2.GSSAPICanonicalizationValue = void 0;
  13783. var dns = require("dns");
  13784. var deps_1 = require_deps();
  13785. var error_1 = require_error();
  13786. var utils_1 = require_utils();
  13787. var auth_provider_1 = require_auth_provider();
  13788. exports2.GSSAPICanonicalizationValue = Object.freeze({
  13789. on: true,
  13790. off: false,
  13791. none: "none",
  13792. forward: "forward",
  13793. forwardAndReverse: "forwardAndReverse"
  13794. });
  13795. async function externalCommand(connection, command) {
  13796. return connection.commandAsync((0, utils_1.ns)("$external.$cmd"), command, void 0);
  13797. }
  13798. var krb;
  13799. var GSSAPI = class extends auth_provider_1.AuthProvider {
  13800. async auth(authContext) {
  13801. const { connection, credentials } = authContext;
  13802. if (credentials == null) {
  13803. throw new error_1.MongoMissingCredentialsError("Credentials required for GSSAPI authentication");
  13804. }
  13805. const { username } = credentials;
  13806. const client = await makeKerberosClient(authContext);
  13807. const payload = await client.step("");
  13808. const saslStartResponse = await externalCommand(connection, saslStart(payload));
  13809. const negotiatedPayload = await negotiate(client, 10, saslStartResponse.payload);
  13810. const saslContinueResponse = await externalCommand(connection, saslContinue(negotiatedPayload, saslStartResponse.conversationId));
  13811. const finalizePayload = await finalize(client, username, saslContinueResponse.payload);
  13812. await externalCommand(connection, {
  13813. saslContinue: 1,
  13814. conversationId: saslContinueResponse.conversationId,
  13815. payload: finalizePayload
  13816. });
  13817. }
  13818. };
  13819. exports2.GSSAPI = GSSAPI;
  13820. async function makeKerberosClient(authContext) {
  13821. const { hostAddress } = authContext.options;
  13822. const { credentials } = authContext;
  13823. if (!hostAddress || typeof hostAddress.host !== "string" || !credentials) {
  13824. throw new error_1.MongoInvalidArgumentError("Connection must have host and port and credentials defined.");
  13825. }
  13826. loadKrb();
  13827. if ("kModuleError" in krb) {
  13828. throw krb["kModuleError"];
  13829. }
  13830. const { initializeClient } = krb;
  13831. const { username, password } = credentials;
  13832. const mechanismProperties = credentials.mechanismProperties;
  13833. const serviceName = mechanismProperties.SERVICE_NAME ?? "mongodb";
  13834. const host = await performGSSAPICanonicalizeHostName(hostAddress.host, mechanismProperties);
  13835. const initOptions = {};
  13836. if (password != null) {
  13837. Object.assign(initOptions, { user: username, password });
  13838. }
  13839. const spnHost = mechanismProperties.SERVICE_HOST ?? host;
  13840. let spn = `${serviceName}${process.platform === "win32" ? "/" : "@"}${spnHost}`;
  13841. if ("SERVICE_REALM" in mechanismProperties) {
  13842. spn = `${spn}@${mechanismProperties.SERVICE_REALM}`;
  13843. }
  13844. return initializeClient(spn, initOptions);
  13845. }
  13846. function saslStart(payload) {
  13847. return {
  13848. saslStart: 1,
  13849. mechanism: "GSSAPI",
  13850. payload,
  13851. autoAuthorize: 1
  13852. };
  13853. }
  13854. function saslContinue(payload, conversationId) {
  13855. return {
  13856. saslContinue: 1,
  13857. conversationId,
  13858. payload
  13859. };
  13860. }
  13861. async function negotiate(client, retries, payload) {
  13862. try {
  13863. const response = await client.step(payload);
  13864. return response || "";
  13865. } catch (error) {
  13866. if (retries === 0) {
  13867. throw error;
  13868. }
  13869. return negotiate(client, retries - 1, payload);
  13870. }
  13871. }
  13872. async function finalize(client, user, payload) {
  13873. const response = await client.unwrap(payload);
  13874. return client.wrap(response || "", { user });
  13875. }
  13876. async function performGSSAPICanonicalizeHostName(host, mechanismProperties) {
  13877. const mode = mechanismProperties.CANONICALIZE_HOST_NAME;
  13878. if (!mode || mode === exports2.GSSAPICanonicalizationValue.none) {
  13879. return host;
  13880. }
  13881. if (mode === exports2.GSSAPICanonicalizationValue.on || mode === exports2.GSSAPICanonicalizationValue.forwardAndReverse) {
  13882. const { address } = await dns.promises.lookup(host);
  13883. try {
  13884. const results = await dns.promises.resolvePtr(address);
  13885. return results.length > 0 ? results[0] : host;
  13886. } catch (error) {
  13887. return resolveCname(host);
  13888. }
  13889. } else {
  13890. return resolveCname(host);
  13891. }
  13892. }
  13893. exports2.performGSSAPICanonicalizeHostName = performGSSAPICanonicalizeHostName;
  13894. async function resolveCname(host) {
  13895. try {
  13896. const results = await dns.promises.resolveCname(host);
  13897. return results.length > 0 ? results[0] : host;
  13898. } catch {
  13899. return host;
  13900. }
  13901. }
  13902. exports2.resolveCname = resolveCname;
  13903. function loadKrb() {
  13904. if (!krb) {
  13905. krb = (0, deps_1.getKerberos)();
  13906. }
  13907. }
  13908. }
  13909. });
  13910. // node_modules/mongodb/lib/cmap/auth/providers.js
  13911. var require_providers = __commonJS({
  13912. "node_modules/mongodb/lib/cmap/auth/providers.js"(exports2) {
  13913. "use strict";
  13914. Object.defineProperty(exports2, "__esModule", { value: true });
  13915. exports2.AUTH_MECHS_AUTH_SRC_EXTERNAL = exports2.AuthMechanism = void 0;
  13916. exports2.AuthMechanism = Object.freeze({
  13917. MONGODB_AWS: "MONGODB-AWS",
  13918. MONGODB_CR: "MONGODB-CR",
  13919. MONGODB_DEFAULT: "DEFAULT",
  13920. MONGODB_GSSAPI: "GSSAPI",
  13921. MONGODB_PLAIN: "PLAIN",
  13922. MONGODB_SCRAM_SHA1: "SCRAM-SHA-1",
  13923. MONGODB_SCRAM_SHA256: "SCRAM-SHA-256",
  13924. MONGODB_X509: "MONGODB-X509",
  13925. /** @experimental */
  13926. MONGODB_OIDC: "MONGODB-OIDC"
  13927. });
  13928. exports2.AUTH_MECHS_AUTH_SRC_EXTERNAL = /* @__PURE__ */ new Set([
  13929. exports2.AuthMechanism.MONGODB_GSSAPI,
  13930. exports2.AuthMechanism.MONGODB_AWS,
  13931. exports2.AuthMechanism.MONGODB_OIDC,
  13932. exports2.AuthMechanism.MONGODB_X509
  13933. ]);
  13934. }
  13935. });
  13936. // node_modules/mongodb/lib/cmap/auth/mongo_credentials.js
  13937. var require_mongo_credentials = __commonJS({
  13938. "node_modules/mongodb/lib/cmap/auth/mongo_credentials.js"(exports2) {
  13939. "use strict";
  13940. Object.defineProperty(exports2, "__esModule", { value: true });
  13941. exports2.MongoCredentials = exports2.DEFAULT_ALLOWED_HOSTS = void 0;
  13942. var error_1 = require_error();
  13943. var gssapi_1 = require_gssapi();
  13944. var providers_1 = require_providers();
  13945. function getDefaultAuthMechanism(hello) {
  13946. if (hello) {
  13947. if (Array.isArray(hello.saslSupportedMechs)) {
  13948. return hello.saslSupportedMechs.includes(providers_1.AuthMechanism.MONGODB_SCRAM_SHA256) ? providers_1.AuthMechanism.MONGODB_SCRAM_SHA256 : providers_1.AuthMechanism.MONGODB_SCRAM_SHA1;
  13949. }
  13950. if (hello.maxWireVersion >= 3) {
  13951. return providers_1.AuthMechanism.MONGODB_SCRAM_SHA1;
  13952. }
  13953. }
  13954. return providers_1.AuthMechanism.MONGODB_CR;
  13955. }
  13956. var ALLOWED_PROVIDER_NAMES = ["aws", "azure"];
  13957. var ALLOWED_HOSTS_ERROR = "Auth mechanism property ALLOWED_HOSTS must be an array of strings.";
  13958. exports2.DEFAULT_ALLOWED_HOSTS = [
  13959. "*.mongodb.net",
  13960. "*.mongodb-dev.net",
  13961. "*.mongodbgov.net",
  13962. "localhost",
  13963. "127.0.0.1",
  13964. "::1"
  13965. ];
  13966. var TOKEN_AUDIENCE_MISSING_ERROR = "TOKEN_AUDIENCE must be set in the auth mechanism properties when PROVIDER_NAME is azure.";
  13967. var MongoCredentials = class _MongoCredentials {
  13968. constructor(options) {
  13969. this.username = options.username ?? "";
  13970. this.password = options.password;
  13971. this.source = options.source;
  13972. if (!this.source && options.db) {
  13973. this.source = options.db;
  13974. }
  13975. this.mechanism = options.mechanism || providers_1.AuthMechanism.MONGODB_DEFAULT;
  13976. this.mechanismProperties = options.mechanismProperties || {};
  13977. if (this.mechanism.match(/MONGODB-AWS/i)) {
  13978. if (!this.username && process.env.AWS_ACCESS_KEY_ID) {
  13979. this.username = process.env.AWS_ACCESS_KEY_ID;
  13980. }
  13981. if (!this.password && process.env.AWS_SECRET_ACCESS_KEY) {
  13982. this.password = process.env.AWS_SECRET_ACCESS_KEY;
  13983. }
  13984. if (this.mechanismProperties.AWS_SESSION_TOKEN == null && process.env.AWS_SESSION_TOKEN != null) {
  13985. this.mechanismProperties = {
  13986. ...this.mechanismProperties,
  13987. AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN
  13988. };
  13989. }
  13990. }
  13991. if (this.mechanism === providers_1.AuthMechanism.MONGODB_OIDC && !this.mechanismProperties.ALLOWED_HOSTS) {
  13992. this.mechanismProperties = {
  13993. ...this.mechanismProperties,
  13994. ALLOWED_HOSTS: exports2.DEFAULT_ALLOWED_HOSTS
  13995. };
  13996. }
  13997. Object.freeze(this.mechanismProperties);
  13998. Object.freeze(this);
  13999. }
  14000. /** Determines if two MongoCredentials objects are equivalent */
  14001. equals(other) {
  14002. return this.mechanism === other.mechanism && this.username === other.username && this.password === other.password && this.source === other.source;
  14003. }
  14004. /**
  14005. * If the authentication mechanism is set to "default", resolves the authMechanism
  14006. * based on the server version and server supported sasl mechanisms.
  14007. *
  14008. * @param hello - A hello response from the server
  14009. */
  14010. resolveAuthMechanism(hello) {
  14011. if (this.mechanism.match(/DEFAULT/i)) {
  14012. return new _MongoCredentials({
  14013. username: this.username,
  14014. password: this.password,
  14015. source: this.source,
  14016. mechanism: getDefaultAuthMechanism(hello),
  14017. mechanismProperties: this.mechanismProperties
  14018. });
  14019. }
  14020. return this;
  14021. }
  14022. validate() {
  14023. if ((this.mechanism === providers_1.AuthMechanism.MONGODB_GSSAPI || this.mechanism === providers_1.AuthMechanism.MONGODB_CR || this.mechanism === providers_1.AuthMechanism.MONGODB_PLAIN || this.mechanism === providers_1.AuthMechanism.MONGODB_SCRAM_SHA1 || this.mechanism === providers_1.AuthMechanism.MONGODB_SCRAM_SHA256) && !this.username) {
  14024. throw new error_1.MongoMissingCredentialsError(`Username required for mechanism '${this.mechanism}'`);
  14025. }
  14026. if (this.mechanism === providers_1.AuthMechanism.MONGODB_OIDC) {
  14027. if (this.username && this.mechanismProperties.PROVIDER_NAME) {
  14028. throw new error_1.MongoInvalidArgumentError(`username and PROVIDER_NAME may not be used together for mechanism '${this.mechanism}'.`);
  14029. }
  14030. if (this.mechanismProperties.PROVIDER_NAME === "azure" && !this.mechanismProperties.TOKEN_AUDIENCE) {
  14031. throw new error_1.MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
  14032. }
  14033. if (this.mechanismProperties.PROVIDER_NAME && !ALLOWED_PROVIDER_NAMES.includes(this.mechanismProperties.PROVIDER_NAME)) {
  14034. throw new error_1.MongoInvalidArgumentError(`Currently only a PROVIDER_NAME in ${ALLOWED_PROVIDER_NAMES.join(",")} is supported for mechanism '${this.mechanism}'.`);
  14035. }
  14036. if (this.mechanismProperties.REFRESH_TOKEN_CALLBACK && !this.mechanismProperties.REQUEST_TOKEN_CALLBACK) {
  14037. throw new error_1.MongoInvalidArgumentError(`A REQUEST_TOKEN_CALLBACK must be provided when using a REFRESH_TOKEN_CALLBACK for mechanism '${this.mechanism}'`);
  14038. }
  14039. if (!this.mechanismProperties.PROVIDER_NAME && !this.mechanismProperties.REQUEST_TOKEN_CALLBACK) {
  14040. throw new error_1.MongoInvalidArgumentError(`Either a PROVIDER_NAME or a REQUEST_TOKEN_CALLBACK must be specified for mechanism '${this.mechanism}'.`);
  14041. }
  14042. if (this.mechanismProperties.ALLOWED_HOSTS) {
  14043. const hosts = this.mechanismProperties.ALLOWED_HOSTS;
  14044. if (!Array.isArray(hosts)) {
  14045. throw new error_1.MongoInvalidArgumentError(ALLOWED_HOSTS_ERROR);
  14046. }
  14047. for (const host of hosts) {
  14048. if (typeof host !== "string") {
  14049. throw new error_1.MongoInvalidArgumentError(ALLOWED_HOSTS_ERROR);
  14050. }
  14051. }
  14052. }
  14053. }
  14054. if (providers_1.AUTH_MECHS_AUTH_SRC_EXTERNAL.has(this.mechanism)) {
  14055. if (this.source != null && this.source !== "$external") {
  14056. throw new error_1.MongoAPIError(`Invalid source '${this.source}' for mechanism '${this.mechanism}' specified.`);
  14057. }
  14058. }
  14059. if (this.mechanism === providers_1.AuthMechanism.MONGODB_PLAIN && this.source == null) {
  14060. throw new error_1.MongoAPIError("PLAIN Authentication Mechanism needs an auth source");
  14061. }
  14062. if (this.mechanism === providers_1.AuthMechanism.MONGODB_X509 && this.password != null) {
  14063. if (this.password === "") {
  14064. Reflect.set(this, "password", void 0);
  14065. return;
  14066. }
  14067. throw new error_1.MongoAPIError(`Password not allowed for mechanism MONGODB-X509`);
  14068. }
  14069. const canonicalization = this.mechanismProperties.CANONICALIZE_HOST_NAME ?? false;
  14070. if (!Object.values(gssapi_1.GSSAPICanonicalizationValue).includes(canonicalization)) {
  14071. throw new error_1.MongoAPIError(`Invalid CANONICALIZE_HOST_NAME value: ${canonicalization}`);
  14072. }
  14073. }
  14074. static merge(creds, options) {
  14075. return new _MongoCredentials({
  14076. username: options.username ?? (creds == null ? void 0 : creds.username) ?? "",
  14077. password: options.password ?? (creds == null ? void 0 : creds.password) ?? "",
  14078. mechanism: options.mechanism ?? (creds == null ? void 0 : creds.mechanism) ?? providers_1.AuthMechanism.MONGODB_DEFAULT,
  14079. mechanismProperties: options.mechanismProperties ?? (creds == null ? void 0 : creds.mechanismProperties) ?? {},
  14080. source: options.source ?? options.db ?? (creds == null ? void 0 : creds.source) ?? "admin"
  14081. });
  14082. }
  14083. };
  14084. exports2.MongoCredentials = MongoCredentials;
  14085. }
  14086. });
  14087. // node_modules/webidl-conversions/lib/index.js
  14088. var require_lib = __commonJS({
  14089. "node_modules/webidl-conversions/lib/index.js"(exports2) {
  14090. "use strict";
  14091. function makeException(ErrorType, message, options) {
  14092. if (options.globals) {
  14093. ErrorType = options.globals[ErrorType.name];
  14094. }
  14095. return new ErrorType(`${options.context ? options.context : "Value"} ${message}.`);
  14096. }
  14097. function toNumber(value, options) {
  14098. if (typeof value === "bigint") {
  14099. throw makeException(TypeError, "is a BigInt which cannot be converted to a number", options);
  14100. }
  14101. if (!options.globals) {
  14102. return Number(value);
  14103. }
  14104. return options.globals.Number(value);
  14105. }
  14106. function evenRound(x) {
  14107. if (x > 0 && x % 1 === 0.5 && (x & 1) === 0 || x < 0 && x % 1 === -0.5 && (x & 1) === 1) {
  14108. return censorNegativeZero(Math.floor(x));
  14109. }
  14110. return censorNegativeZero(Math.round(x));
  14111. }
  14112. function integerPart(n) {
  14113. return censorNegativeZero(Math.trunc(n));
  14114. }
  14115. function sign(x) {
  14116. return x < 0 ? -1 : 1;
  14117. }
  14118. function modulo(x, y) {
  14119. const signMightNotMatch = x % y;
  14120. if (sign(y) !== sign(signMightNotMatch)) {
  14121. return signMightNotMatch + y;
  14122. }
  14123. return signMightNotMatch;
  14124. }
  14125. function censorNegativeZero(x) {
  14126. return x === 0 ? 0 : x;
  14127. }
  14128. function createIntegerConversion(bitLength, { unsigned }) {
  14129. let lowerBound, upperBound;
  14130. if (unsigned) {
  14131. lowerBound = 0;
  14132. upperBound = 2 ** bitLength - 1;
  14133. } else {
  14134. lowerBound = -(2 ** (bitLength - 1));
  14135. upperBound = 2 ** (bitLength - 1) - 1;
  14136. }
  14137. const twoToTheBitLength = 2 ** bitLength;
  14138. const twoToOneLessThanTheBitLength = 2 ** (bitLength - 1);
  14139. return (value, options = {}) => {
  14140. let x = toNumber(value, options);
  14141. x = censorNegativeZero(x);
  14142. if (options.enforceRange) {
  14143. if (!Number.isFinite(x)) {
  14144. throw makeException(TypeError, "is not a finite number", options);
  14145. }
  14146. x = integerPart(x);
  14147. if (x < lowerBound || x > upperBound) {
  14148. throw makeException(
  14149. TypeError,
  14150. `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
  14151. options
  14152. );
  14153. }
  14154. return x;
  14155. }
  14156. if (!Number.isNaN(x) && options.clamp) {
  14157. x = Math.min(Math.max(x, lowerBound), upperBound);
  14158. x = evenRound(x);
  14159. return x;
  14160. }
  14161. if (!Number.isFinite(x) || x === 0) {
  14162. return 0;
  14163. }
  14164. x = integerPart(x);
  14165. if (x >= lowerBound && x <= upperBound) {
  14166. return x;
  14167. }
  14168. x = modulo(x, twoToTheBitLength);
  14169. if (!unsigned && x >= twoToOneLessThanTheBitLength) {
  14170. return x - twoToTheBitLength;
  14171. }
  14172. return x;
  14173. };
  14174. }
  14175. function createLongLongConversion(bitLength, { unsigned }) {
  14176. const upperBound = Number.MAX_SAFE_INTEGER;
  14177. const lowerBound = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
  14178. const asBigIntN = unsigned ? BigInt.asUintN : BigInt.asIntN;
  14179. return (value, options = {}) => {
  14180. let x = toNumber(value, options);
  14181. x = censorNegativeZero(x);
  14182. if (options.enforceRange) {
  14183. if (!Number.isFinite(x)) {
  14184. throw makeException(TypeError, "is not a finite number", options);
  14185. }
  14186. x = integerPart(x);
  14187. if (x < lowerBound || x > upperBound) {
  14188. throw makeException(
  14189. TypeError,
  14190. `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
  14191. options
  14192. );
  14193. }
  14194. return x;
  14195. }
  14196. if (!Number.isNaN(x) && options.clamp) {
  14197. x = Math.min(Math.max(x, lowerBound), upperBound);
  14198. x = evenRound(x);
  14199. return x;
  14200. }
  14201. if (!Number.isFinite(x) || x === 0) {
  14202. return 0;
  14203. }
  14204. let xBigInt = BigInt(integerPart(x));
  14205. xBigInt = asBigIntN(bitLength, xBigInt);
  14206. return Number(xBigInt);
  14207. };
  14208. }
  14209. exports2.any = (value) => {
  14210. return value;
  14211. };
  14212. exports2.undefined = () => {
  14213. return void 0;
  14214. };
  14215. exports2.boolean = (value) => {
  14216. return Boolean(value);
  14217. };
  14218. exports2.byte = createIntegerConversion(8, { unsigned: false });
  14219. exports2.octet = createIntegerConversion(8, { unsigned: true });
  14220. exports2.short = createIntegerConversion(16, { unsigned: false });
  14221. exports2["unsigned short"] = createIntegerConversion(16, { unsigned: true });
  14222. exports2.long = createIntegerConversion(32, { unsigned: false });
  14223. exports2["unsigned long"] = createIntegerConversion(32, { unsigned: true });
  14224. exports2["long long"] = createLongLongConversion(64, { unsigned: false });
  14225. exports2["unsigned long long"] = createLongLongConversion(64, { unsigned: true });
  14226. exports2.double = (value, options = {}) => {
  14227. const x = toNumber(value, options);
  14228. if (!Number.isFinite(x)) {
  14229. throw makeException(TypeError, "is not a finite floating-point value", options);
  14230. }
  14231. return x;
  14232. };
  14233. exports2["unrestricted double"] = (value, options = {}) => {
  14234. const x = toNumber(value, options);
  14235. return x;
  14236. };
  14237. exports2.float = (value, options = {}) => {
  14238. const x = toNumber(value, options);
  14239. if (!Number.isFinite(x)) {
  14240. throw makeException(TypeError, "is not a finite floating-point value", options);
  14241. }
  14242. if (Object.is(x, -0)) {
  14243. return x;
  14244. }
  14245. const y = Math.fround(x);
  14246. if (!Number.isFinite(y)) {
  14247. throw makeException(TypeError, "is outside the range of a single-precision floating-point value", options);
  14248. }
  14249. return y;
  14250. };
  14251. exports2["unrestricted float"] = (value, options = {}) => {
  14252. const x = toNumber(value, options);
  14253. if (isNaN(x)) {
  14254. return x;
  14255. }
  14256. if (Object.is(x, -0)) {
  14257. return x;
  14258. }
  14259. return Math.fround(x);
  14260. };
  14261. exports2.DOMString = (value, options = {}) => {
  14262. if (options.treatNullAsEmptyString && value === null) {
  14263. return "";
  14264. }
  14265. if (typeof value === "symbol") {
  14266. throw makeException(TypeError, "is a symbol, which cannot be converted to a string", options);
  14267. }
  14268. const StringCtor = options.globals ? options.globals.String : String;
  14269. return StringCtor(value);
  14270. };
  14271. exports2.ByteString = (value, options = {}) => {
  14272. const x = exports2.DOMString(value, options);
  14273. let c;
  14274. for (let i = 0; (c = x.codePointAt(i)) !== void 0; ++i) {
  14275. if (c > 255) {
  14276. throw makeException(TypeError, "is not a valid ByteString", options);
  14277. }
  14278. }
  14279. return x;
  14280. };
  14281. exports2.USVString = (value, options = {}) => {
  14282. const S = exports2.DOMString(value, options);
  14283. const n = S.length;
  14284. const U = [];
  14285. for (let i = 0; i < n; ++i) {
  14286. const c = S.charCodeAt(i);
  14287. if (c < 55296 || c > 57343) {
  14288. U.push(String.fromCodePoint(c));
  14289. } else if (56320 <= c && c <= 57343) {
  14290. U.push(String.fromCodePoint(65533));
  14291. } else if (i === n - 1) {
  14292. U.push(String.fromCodePoint(65533));
  14293. } else {
  14294. const d = S.charCodeAt(i + 1);
  14295. if (56320 <= d && d <= 57343) {
  14296. const a = c & 1023;
  14297. const b = d & 1023;
  14298. U.push(String.fromCodePoint((2 << 15) + (2 << 9) * a + b));
  14299. ++i;
  14300. } else {
  14301. U.push(String.fromCodePoint(65533));
  14302. }
  14303. }
  14304. }
  14305. return U.join("");
  14306. };
  14307. exports2.object = (value, options = {}) => {
  14308. if (value === null || typeof value !== "object" && typeof value !== "function") {
  14309. throw makeException(TypeError, "is not an object", options);
  14310. }
  14311. return value;
  14312. };
  14313. var abByteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
  14314. var sabByteLengthGetter = typeof SharedArrayBuffer === "function" ? Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get : null;
  14315. function isNonSharedArrayBuffer(value) {
  14316. try {
  14317. abByteLengthGetter.call(value);
  14318. return true;
  14319. } catch {
  14320. return false;
  14321. }
  14322. }
  14323. function isSharedArrayBuffer(value) {
  14324. try {
  14325. sabByteLengthGetter.call(value);
  14326. return true;
  14327. } catch {
  14328. return false;
  14329. }
  14330. }
  14331. function isArrayBufferDetached(value) {
  14332. try {
  14333. new Uint8Array(value);
  14334. return false;
  14335. } catch {
  14336. return true;
  14337. }
  14338. }
  14339. exports2.ArrayBuffer = (value, options = {}) => {
  14340. if (!isNonSharedArrayBuffer(value)) {
  14341. if (options.allowShared && !isSharedArrayBuffer(value)) {
  14342. throw makeException(TypeError, "is not an ArrayBuffer or SharedArrayBuffer", options);
  14343. }
  14344. throw makeException(TypeError, "is not an ArrayBuffer", options);
  14345. }
  14346. if (isArrayBufferDetached(value)) {
  14347. throw makeException(TypeError, "is a detached ArrayBuffer", options);
  14348. }
  14349. return value;
  14350. };
  14351. var dvByteLengthGetter = Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength").get;
  14352. exports2.DataView = (value, options = {}) => {
  14353. try {
  14354. dvByteLengthGetter.call(value);
  14355. } catch (e) {
  14356. throw makeException(TypeError, "is not a DataView", options);
  14357. }
  14358. if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
  14359. throw makeException(TypeError, "is backed by a SharedArrayBuffer, which is not allowed", options);
  14360. }
  14361. if (isArrayBufferDetached(value.buffer)) {
  14362. throw makeException(TypeError, "is backed by a detached ArrayBuffer", options);
  14363. }
  14364. return value;
  14365. };
  14366. var typedArrayNameGetter = Object.getOwnPropertyDescriptor(
  14367. Object.getPrototypeOf(Uint8Array).prototype,
  14368. Symbol.toStringTag
  14369. ).get;
  14370. [
  14371. Int8Array,
  14372. Int16Array,
  14373. Int32Array,
  14374. Uint8Array,
  14375. Uint16Array,
  14376. Uint32Array,
  14377. Uint8ClampedArray,
  14378. Float32Array,
  14379. Float64Array
  14380. ].forEach((func) => {
  14381. const { name } = func;
  14382. const article = /^[AEIOU]/u.test(name) ? "an" : "a";
  14383. exports2[name] = (value, options = {}) => {
  14384. if (!ArrayBuffer.isView(value) || typedArrayNameGetter.call(value) !== name) {
  14385. throw makeException(TypeError, `is not ${article} ${name} object`, options);
  14386. }
  14387. if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
  14388. throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
  14389. }
  14390. if (isArrayBufferDetached(value.buffer)) {
  14391. throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
  14392. }
  14393. return value;
  14394. };
  14395. });
  14396. exports2.ArrayBufferView = (value, options = {}) => {
  14397. if (!ArrayBuffer.isView(value)) {
  14398. throw makeException(TypeError, "is not a view on an ArrayBuffer or SharedArrayBuffer", options);
  14399. }
  14400. if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
  14401. throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
  14402. }
  14403. if (isArrayBufferDetached(value.buffer)) {
  14404. throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
  14405. }
  14406. return value;
  14407. };
  14408. exports2.BufferSource = (value, options = {}) => {
  14409. if (ArrayBuffer.isView(value)) {
  14410. if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
  14411. throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
  14412. }
  14413. if (isArrayBufferDetached(value.buffer)) {
  14414. throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
  14415. }
  14416. return value;
  14417. }
  14418. if (!options.allowShared && !isNonSharedArrayBuffer(value)) {
  14419. throw makeException(TypeError, "is not an ArrayBuffer or a view on one", options);
  14420. }
  14421. if (options.allowShared && !isSharedArrayBuffer(value) && !isNonSharedArrayBuffer(value)) {
  14422. throw makeException(TypeError, "is not an ArrayBuffer, SharedArrayBuffer, or a view on one", options);
  14423. }
  14424. if (isArrayBufferDetached(value)) {
  14425. throw makeException(TypeError, "is a detached ArrayBuffer", options);
  14426. }
  14427. return value;
  14428. };
  14429. exports2.DOMTimeStamp = exports2["unsigned long long"];
  14430. }
  14431. });
  14432. // node_modules/whatwg-url/lib/utils.js
  14433. var require_utils2 = __commonJS({
  14434. "node_modules/whatwg-url/lib/utils.js"(exports2, module2) {
  14435. "use strict";
  14436. function isObject(value) {
  14437. return typeof value === "object" && value !== null || typeof value === "function";
  14438. }
  14439. var hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
  14440. function define2(target, source) {
  14441. for (const key of Reflect.ownKeys(source)) {
  14442. const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
  14443. if (descriptor && !Reflect.defineProperty(target, key, descriptor)) {
  14444. throw new TypeError(`Cannot redefine property: ${String(key)}`);
  14445. }
  14446. }
  14447. }
  14448. function newObjectInRealm(globalObject, object) {
  14449. const ctorRegistry = initCtorRegistry(globalObject);
  14450. return Object.defineProperties(
  14451. Object.create(ctorRegistry["%Object.prototype%"]),
  14452. Object.getOwnPropertyDescriptors(object)
  14453. );
  14454. }
  14455. var wrapperSymbol = Symbol("wrapper");
  14456. var implSymbol = Symbol("impl");
  14457. var sameObjectCaches = Symbol("SameObject caches");
  14458. var ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
  14459. var AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
  14460. }).prototype);
  14461. function initCtorRegistry(globalObject) {
  14462. if (hasOwn(globalObject, ctorRegistrySymbol)) {
  14463. return globalObject[ctorRegistrySymbol];
  14464. }
  14465. const ctorRegistry = /* @__PURE__ */ Object.create(null);
  14466. ctorRegistry["%Object.prototype%"] = globalObject.Object.prototype;
  14467. ctorRegistry["%IteratorPrototype%"] = Object.getPrototypeOf(
  14468. Object.getPrototypeOf(new globalObject.Array()[Symbol.iterator]())
  14469. );
  14470. try {
  14471. ctorRegistry["%AsyncIteratorPrototype%"] = Object.getPrototypeOf(
  14472. Object.getPrototypeOf(
  14473. globalObject.eval("(async function* () {})").prototype
  14474. )
  14475. );
  14476. } catch {
  14477. ctorRegistry["%AsyncIteratorPrototype%"] = AsyncIteratorPrototype;
  14478. }
  14479. globalObject[ctorRegistrySymbol] = ctorRegistry;
  14480. return ctorRegistry;
  14481. }
  14482. function getSameObject(wrapper, prop, creator) {
  14483. if (!wrapper[sameObjectCaches]) {
  14484. wrapper[sameObjectCaches] = /* @__PURE__ */ Object.create(null);
  14485. }
  14486. if (prop in wrapper[sameObjectCaches]) {
  14487. return wrapper[sameObjectCaches][prop];
  14488. }
  14489. wrapper[sameObjectCaches][prop] = creator();
  14490. return wrapper[sameObjectCaches][prop];
  14491. }
  14492. function wrapperForImpl(impl) {
  14493. return impl ? impl[wrapperSymbol] : null;
  14494. }
  14495. function implForWrapper(wrapper) {
  14496. return wrapper ? wrapper[implSymbol] : null;
  14497. }
  14498. function tryWrapperForImpl(impl) {
  14499. const wrapper = wrapperForImpl(impl);
  14500. return wrapper ? wrapper : impl;
  14501. }
  14502. function tryImplForWrapper(wrapper) {
  14503. const impl = implForWrapper(wrapper);
  14504. return impl ? impl : wrapper;
  14505. }
  14506. var iterInternalSymbol = Symbol("internal");
  14507. function isArrayIndexPropName(P) {
  14508. if (typeof P !== "string") {
  14509. return false;
  14510. }
  14511. const i = P >>> 0;
  14512. if (i === 2 ** 32 - 1) {
  14513. return false;
  14514. }
  14515. const s = `${i}`;
  14516. if (P !== s) {
  14517. return false;
  14518. }
  14519. return true;
  14520. }
  14521. var byteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
  14522. function isArrayBuffer(value) {
  14523. try {
  14524. byteLengthGetter.call(value);
  14525. return true;
  14526. } catch (e) {
  14527. return false;
  14528. }
  14529. }
  14530. function iteratorResult([key, value], kind) {
  14531. let result;
  14532. switch (kind) {
  14533. case "key":
  14534. result = key;
  14535. break;
  14536. case "value":
  14537. result = value;
  14538. break;
  14539. case "key+value":
  14540. result = [key, value];
  14541. break;
  14542. }
  14543. return { value: result, done: false };
  14544. }
  14545. var supportsPropertyIndex = Symbol("supports property index");
  14546. var supportedPropertyIndices = Symbol("supported property indices");
  14547. var supportsPropertyName = Symbol("supports property name");
  14548. var supportedPropertyNames = Symbol("supported property names");
  14549. var indexedGet = Symbol("indexed property get");
  14550. var indexedSetNew = Symbol("indexed property set new");
  14551. var indexedSetExisting = Symbol("indexed property set existing");
  14552. var namedGet = Symbol("named property get");
  14553. var namedSetNew = Symbol("named property set new");
  14554. var namedSetExisting = Symbol("named property set existing");
  14555. var namedDelete = Symbol("named property delete");
  14556. var asyncIteratorNext = Symbol("async iterator get the next iteration result");
  14557. var asyncIteratorReturn = Symbol("async iterator return steps");
  14558. var asyncIteratorInit = Symbol("async iterator initialization steps");
  14559. var asyncIteratorEOI = Symbol("async iterator end of iteration");
  14560. module2.exports = exports2 = {
  14561. isObject,
  14562. hasOwn,
  14563. define: define2,
  14564. newObjectInRealm,
  14565. wrapperSymbol,
  14566. implSymbol,
  14567. getSameObject,
  14568. ctorRegistrySymbol,
  14569. initCtorRegistry,
  14570. wrapperForImpl,
  14571. implForWrapper,
  14572. tryWrapperForImpl,
  14573. tryImplForWrapper,
  14574. iterInternalSymbol,
  14575. isArrayBuffer,
  14576. isArrayIndexPropName,
  14577. supportsPropertyIndex,
  14578. supportedPropertyIndices,
  14579. supportsPropertyName,
  14580. supportedPropertyNames,
  14581. indexedGet,
  14582. indexedSetNew,
  14583. indexedSetExisting,
  14584. namedGet,
  14585. namedSetNew,
  14586. namedSetExisting,
  14587. namedDelete,
  14588. asyncIteratorNext,
  14589. asyncIteratorReturn,
  14590. asyncIteratorInit,
  14591. asyncIteratorEOI,
  14592. iteratorResult
  14593. };
  14594. }
  14595. });
  14596. // node_modules/tr46/lib/regexes.js
  14597. var require_regexes = __commonJS({
  14598. "node_modules/tr46/lib/regexes.js"(exports2, module2) {
  14599. "use strict";
  14600. var combiningMarks = /[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3C\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D81-\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1715\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u180F\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA82C\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10D24}-\u{10D27}\u{10EAB}\u{10EAC}\u{10F46}-\u{10F50}\u{10F82}-\u{10F85}\u{11000}-\u{11002}\u{11038}-\u{11046}\u{11070}\u{11073}\u{11074}\u{1107F}-\u{11082}\u{110B0}-\u{110BA}\u{110C2}\u{11100}-\u{11102}\u{11127}-\u{11134}\u{11145}\u{11146}\u{11173}\u{11180}-\u{11182}\u{111B3}-\u{111C0}\u{111C9}-\u{111CC}\u{111CE}\u{111CF}\u{1122C}-\u{11237}\u{1123E}\u{112DF}-\u{112EA}\u{11300}-\u{11303}\u{1133B}\u{1133C}\u{1133E}-\u{11344}\u{11347}\u{11348}\u{1134B}-\u{1134D}\u{11357}\u{11362}\u{11363}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11435}-\u{11446}\u{1145E}\u{114B0}-\u{114C3}\u{115AF}-\u{115B5}\u{115B8}-\u{115C0}\u{115DC}\u{115DD}\u{11630}-\u{11640}\u{116AB}-\u{116B7}\u{1171D}-\u{1172B}\u{1182C}-\u{1183A}\u{11930}-\u{11935}\u{11937}\u{11938}\u{1193B}-\u{1193E}\u{11940}\u{11942}\u{11943}\u{119D1}-\u{119D7}\u{119DA}-\u{119E0}\u{119E4}\u{11A01}-\u{11A0A}\u{11A33}-\u{11A39}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A5B}\u{11A8A}-\u{11A99}\u{11C2F}-\u{11C36}\u{11C38}-\u{11C3F}\u{11C92}-\u{11CA7}\u{11CA9}-\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D8A}-\u{11D8E}\u{11D90}\u{11D91}\u{11D93}-\u{11D97}\u{11EF3}-\u{11EF6}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F51}-\u{16F87}\u{16F8F}-\u{16F92}\u{16FE4}\u{16FF0}\u{16FF1}\u{1BC9D}\u{1BC9E}\u{1CF00}-\u{1CF2D}\u{1CF30}-\u{1CF46}\u{1D165}-\u{1D169}\u{1D16D}-\u{1D172}\u{1D17B}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D242}-\u{1D244}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2AE}\u{1E2EC}-\u{1E2EF}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94A}\u{E0100}-\u{E01EF}]/u;
  14601. var combiningClassVirama = /[\u094D\u09CD\u0A4D\u0ACD\u0B4D\u0BCD\u0C4D\u0CCD\u0D3B\u0D3C\u0D4D\u0DCA\u0E3A\u0EBA\u0F84\u1039\u103A\u1714\u1734\u17D2\u1A60\u1B44\u1BAA\u1BAB\u1BF2\u1BF3\u2D7F\uA806\uA8C4\uA953\uA9C0\uAAF6\uABED\u{10A3F}\u{11046}\u{1107F}\u{110B9}\u{11133}\u{11134}\u{111C0}\u{11235}\u{112EA}\u{1134D}\u{11442}\u{114C2}\u{115BF}\u{1163F}\u{116B6}\u{1172B}\u{11839}\u{119E0}\u{11A34}\u{11A47}\u{11A99}\u{11C3F}\u{11D44}\u{11D45}\u{11D97}]/u;
  14602. var validZWNJ = /[\u0620\u0626\u0628\u062A-\u062E\u0633-\u063F\u0641-\u0647\u0649\u064A\u066E\u066F\u0678-\u0687\u069A-\u06BF\u06C1\u06C2\u06CC\u06CE\u06D0\u06D1\u06FA-\u06FC\u06FF\u0712-\u0714\u071A-\u071D\u071F-\u0727\u0729\u072B\u072D\u072E\u074E-\u0758\u075C-\u076A\u076D-\u0770\u0772\u0775-\u0777\u077A-\u077F\u07CA-\u07EA\u0841-\u0845\u0848\u084A-\u0853\u0855\u0860\u0862-\u0865\u0868\u08A0-\u08A9\u08AF\u08B0\u08B3\u08B4\u08B6-\u08B8\u08BA-\u08BD\u1807\u1820-\u1878\u1887-\u18A8\u18AA\uA840-\uA872\u{10AC0}-\u{10AC4}\u{10ACD}\u{10AD3}-\u{10ADC}\u{10ADE}-\u{10AE0}\u{10AEB}-\u{10AEE}\u{10B80}\u{10B82}\u{10B86}-\u{10B88}\u{10B8A}\u{10B8B}\u{10B8D}\u{10B90}\u{10BAD}\u{10BAE}\u{10D00}-\u{10D21}\u{10D23}\u{10F30}-\u{10F32}\u{10F34}-\u{10F44}\u{10F51}-\u{10F53}\u{1E900}-\u{1E943}][\xAD\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u061C\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u070F\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B56\u0B62\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C04\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CBF\u0CC6\u0CCC\u0CCD\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D41-\u0D44\u0D4D\u0D62\u0D63\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039\u103A\u103D\u103E\u1058\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80\u1B81\u1BA2-\u1BA5\u1BA8\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u200B\u200E\u200F\u202A-\u202E\u2060-\u2064\u206A-\u206F\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\uA9E5\uAA29-\uAA2E\uAA31\uAA32\uAA35\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEC\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFEFF\uFFF9-\uFFFB\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10D24}-\u{10D27}\u{10F46}-\u{10F50}\u{11001}\u{11038}-\u{11046}\u{1107F}-\u{11081}\u{110B3}-\u{110B6}\u{110B9}\u{110BA}\u{11100}-\u{11102}\u{11127}-\u{1112B}\u{1112D}-\u{11134}\u{11173}\u{11180}\u{11181}\u{111B6}-\u{111BE}\u{111C9}-\u{111CC}\u{1122F}-\u{11231}\u{11234}\u{11236}\u{11237}\u{1123E}\u{112DF}\u{112E3}-\u{112EA}\u{11300}\u{11301}\u{1133B}\u{1133C}\u{11340}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11438}-\u{1143F}\u{11442}-\u{11444}\u{11446}\u{1145E}\u{114B3}-\u{114B8}\u{114BA}\u{114BF}\u{114C0}\u{114C2}\u{114C3}\u{115B2}-\u{115B5}\u{115BC}\u{115BD}\u{115BF}\u{115C0}\u{115DC}\u{115DD}\u{11633}-\u{1163A}\u{1163D}\u{1163F}\u{11640}\u{116AB}\u{116AD}\u{116B0}-\u{116B5}\u{116B7}\u{1171D}-\u{1171F}\u{11722}-\u{11725}\u{11727}-\u{1172B}\u{1182F}-\u{11837}\u{11839}\u{1183A}\u{119D4}-\u{119D7}\u{119DA}\u{119DB}\u{119E0}\u{11A01}-\u{11A0A}\u{11A33}-\u{11A38}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A56}\u{11A59}-\u{11A5B}\u{11A8A}-\u{11A96}\u{11A98}\u{11A99}\u{11C30}-\u{11C36}\u{11C38}-\u{11C3D}\u{11C3F}\u{11C92}-\u{11CA7}\u{11CAA}-\u{11CB0}\u{11CB2}\u{11CB3}\u{11CB5}\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D90}\u{11D91}\u{11D95}\u{11D97}\u{11EF3}\u{11EF4}\u{13430}-\u{13438}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F8F}-\u{16F92}\u{1BC9D}\u{1BC9E}\u{1BCA0}-\u{1BCA3}\u{1D167}-\u{1D169}\u{1D173}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D242}-\u{1D244}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2EC}-\u{1E2EF}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94B}\u{E0001}\u{E0020}-\u{E007F}\u{E0100}-\u{E01EF}]*\u200C[\xAD\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u061C\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u070F\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B56\u0B62\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C04\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CBF\u0CC6\u0CCC\u0CCD\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D41-\u0D44\u0D4D\u0D62\u0D63\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039\u103A\u103D\u103E\u1058\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80\u1B81\u1BA2-\u1BA5\u1BA8\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u200B\u200E\u200F\u202A-\u202E\u2060-\u2064\u206A-\u206F\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\uA9E5\uAA29-\uAA2E\uAA31\uAA32\uAA35\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEC\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\uFEFF\uFFF9-\uFFFB\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10D24}-\u{10D27}\u{10F46}-\u{10F50}\u{11001}\u{11038}-\u{11046}\u{1107F}-\u{11081}\u{110B3}-\u{110B6}\u{110B9}\u{110BA}\u{11100}-\u{11102}\u{11127}-\u{1112B}\u{1112D}-\u{11134}\u{11173}\u{11180}\u{11181}\u{111B6}-\u{111BE}\u{111C9}-\u{111CC}\u{1122F}-\u{11231}\u{11234}\u{11236}\u{11237}\u{1123E}\u{112DF}\u{112E3}-\u{112EA}\u{11300}\u{11301}\u{1133B}\u{1133C}\u{11340}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11438}-\u{1143F}\u{11442}-\u{11444}\u{11446}\u{1145E}\u{114B3}-\u{114B8}\u{114BA}\u{114BF}\u{114C0}\u{114C2}\u{114C3}\u{115B2}-\u{115B5}\u{115BC}\u{115BD}\u{115BF}\u{115C0}\u{115DC}\u{115DD}\u{11633}-\u{1163A}\u{1163D}\u{1163F}\u{11640}\u{116AB}\u{116AD}\u{116B0}-\u{116B5}\u{116B7}\u{1171D}-\u{1171F}\u{11722}-\u{11725}\u{11727}-\u{1172B}\u{1182F}-\u{11837}\u{11839}\u{1183A}\u{119D4}-\u{119D7}\u{119DA}\u{119DB}\u{119E0}\u{11A01}-\u{11A0A}\u{11A33}-\u{11A38}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A56}\u{11A59}-\u{11A5B}\u{11A8A}-\u{11A96}\u{11A98}\u{11A99}\u{11C30}-\u{11C36}\u{11C38}-\u{11C3D}\u{11C3F}\u{11C92}-\u{11CA7}\u{11CAA}-\u{11CB0}\u{11CB2}\u{11CB3}\u{11CB5}\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D90}\u{11D91}\u{11D95}\u{11D97}\u{11EF3}\u{11EF4}\u{13430}-\u{13438}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F8F}-\u{16F92}\u{1BC9D}\u{1BC9E}\u{1BCA0}-\u{1BCA3}\u{1D167}-\u{1D169}\u{1D173}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D242}-\u{1D244}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2EC}-\u{1E2EF}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94B}\u{E0001}\u{E0020}-\u{E007F}\u{E0100}-\u{E01EF}]*[\u0620\u0622-\u063F\u0641-\u064A\u066E\u066F\u0671-\u0673\u0675-\u06D3\u06D5\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u077F\u07CA-\u07EA\u0840-\u0855\u0860\u0862-\u0865\u0867-\u086A\u08A0-\u08AC\u08AE-\u08B4\u08B6-\u08BD\u1807\u1820-\u1878\u1887-\u18A8\u18AA\uA840-\uA871\u{10AC0}-\u{10AC5}\u{10AC7}\u{10AC9}\u{10ACA}\u{10ACE}-\u{10AD6}\u{10AD8}-\u{10AE1}\u{10AE4}\u{10AEB}-\u{10AEF}\u{10B80}-\u{10B91}\u{10BA9}-\u{10BAE}\u{10D01}-\u{10D23}\u{10F30}-\u{10F44}\u{10F51}-\u{10F54}\u{1E900}-\u{1E943}]/u;
  14603. var bidiDomain = /[\u05BE\u05C0\u05C3\u05C6\u05D0-\u05EA\u05EF-\u05F4\u0600-\u0605\u0608\u060B\u060D\u061B-\u064A\u0660-\u0669\u066B-\u066F\u0671-\u06D5\u06DD\u06E5\u06E6\u06EE\u06EF\u06FA-\u070D\u070F\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u07FE-\u0815\u081A\u0824\u0828\u0830-\u083E\u0840-\u0858\u085E\u0860-\u086A\u0870-\u088E\u0890\u0891\u08A0-\u08C9\u08E2\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBC2\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFC\uFE70-\uFE74\uFE76-\uFEFC\u{10800}-\u{10805}\u{10808}\u{1080A}-\u{10835}\u{10837}\u{10838}\u{1083C}\u{1083F}-\u{10855}\u{10857}-\u{1089E}\u{108A7}-\u{108AF}\u{108E0}-\u{108F2}\u{108F4}\u{108F5}\u{108FB}-\u{1091B}\u{10920}-\u{10939}\u{1093F}\u{10980}-\u{109B7}\u{109BC}-\u{109CF}\u{109D2}-\u{10A00}\u{10A10}-\u{10A13}\u{10A15}-\u{10A17}\u{10A19}-\u{10A35}\u{10A40}-\u{10A48}\u{10A50}-\u{10A58}\u{10A60}-\u{10A9F}\u{10AC0}-\u{10AE4}\u{10AEB}-\u{10AF6}\u{10B00}-\u{10B35}\u{10B40}-\u{10B55}\u{10B58}-\u{10B72}\u{10B78}-\u{10B91}\u{10B99}-\u{10B9C}\u{10BA9}-\u{10BAF}\u{10C00}-\u{10C48}\u{10C80}-\u{10CB2}\u{10CC0}-\u{10CF2}\u{10CFA}-\u{10D23}\u{10D30}-\u{10D39}\u{10E60}-\u{10E7E}\u{10E80}-\u{10EA9}\u{10EAD}\u{10EB0}\u{10EB1}\u{10F00}-\u{10F27}\u{10F30}-\u{10F45}\u{10F51}-\u{10F59}\u{10F70}-\u{10F81}\u{10F86}-\u{10F89}\u{10FB0}-\u{10FCB}\u{10FE0}-\u{10FF6}\u{1E800}-\u{1E8C4}\u{1E8C7}-\u{1E8CF}\u{1E900}-\u{1E943}\u{1E94B}\u{1E950}-\u{1E959}\u{1E95E}\u{1E95F}\u{1EC71}-\u{1ECB4}\u{1ED01}-\u{1ED3D}\u{1EE00}-\u{1EE03}\u{1EE05}-\u{1EE1F}\u{1EE21}\u{1EE22}\u{1EE24}\u{1EE27}\u{1EE29}-\u{1EE32}\u{1EE34}-\u{1EE37}\u{1EE39}\u{1EE3B}\u{1EE42}\u{1EE47}\u{1EE49}\u{1EE4B}\u{1EE4D}-\u{1EE4F}\u{1EE51}\u{1EE52}\u{1EE54}\u{1EE57}\u{1EE59}\u{1EE5B}\u{1EE5D}\u{1EE5F}\u{1EE61}\u{1EE62}\u{1EE64}\u{1EE67}-\u{1EE6A}\u{1EE6C}-\u{1EE72}\u{1EE74}-\u{1EE77}\u{1EE79}-\u{1EE7C}\u{1EE7E}\u{1EE80}-\u{1EE89}\u{1EE8B}-\u{1EE9B}\u{1EEA1}-\u{1EEA3}\u{1EEA5}-\u{1EEA9}\u{1EEAB}-\u{1EEBB}]/u;
  14604. var bidiS1LTR = /[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02B8\u02BB-\u02C1\u02D0\u02D1\u02E0-\u02E4\u02EE\u0370-\u0373\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0482\u048A-\u052F\u0531-\u0556\u0559-\u0589\u0903-\u0939\u093B\u093D-\u0940\u0949-\u094C\u094E-\u0950\u0958-\u0961\u0964-\u0980\u0982\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD-\u09C0\u09C7\u09C8\u09CB\u09CC\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09FA\u09FC\u09FD\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3E-\u0A40\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A76\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD-\u0AC0\u0AC9\u0ACB\u0ACC\u0AD0\u0AE0\u0AE1\u0AE6-\u0AF0\u0AF9\u0B02\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B3E\u0B40\u0B47\u0B48\u0B4B\u0B4C\u0B57\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE\u0BBF\u0BC1\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD0\u0BD7\u0BE6-\u0BF2\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C41-\u0C44\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C77\u0C7F\u0C80\u0C82-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD-\u0CC4\u0CC6-\u0CC8\u0CCA\u0CCB\u0CD5\u0CD6\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D02-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D4E\u0D4F\u0D54-\u0D61\u0D66-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCF-\u0DD1\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2-\u0DF4\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E4F-\u0E5B\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00-\u0F17\u0F1A-\u0F34\u0F36\u0F38\u0F3E-\u0F47\u0F49-\u0F6C\u0F7F\u0F85\u0F88-\u0F8C\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FDA\u1000-\u102C\u1031\u1038\u103B\u103C\u103F-\u1057\u105A-\u105D\u1061-\u1070\u1075-\u1081\u1083\u1084\u1087-\u108C\u108E-\u109C\u109E-\u10C5\u10C7\u10CD\u10D0-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1360-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u167F\u1681-\u169A\u16A0-\u16F8\u1700-\u1711\u1715\u171F-\u1731\u1734-\u1736\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17B6\u17BE-\u17C5\u17C7\u17C8\u17D4-\u17DA\u17DC\u17E0-\u17E9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1923-\u1926\u1929-\u192B\u1930\u1931\u1933-\u1938\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A19\u1A1A\u1A1E-\u1A55\u1A57\u1A61\u1A63\u1A64\u1A6D-\u1A72\u1A80-\u1A89\u1A90-\u1A99\u1AA0-\u1AAD\u1B04-\u1B33\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B4C\u1B50-\u1B6A\u1B74-\u1B7E\u1B82-\u1BA1\u1BA6\u1BA7\u1BAA\u1BAE-\u1BE5\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2\u1BF3\u1BFC-\u1C2B\u1C34\u1C35\u1C3B-\u1C49\u1C4D-\u1C88\u1C90-\u1CBA\u1CBD-\u1CC7\u1CD3\u1CE1\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5-\u1CF7\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200E\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u214F\u2160-\u2188\u2336-\u237A\u2395\u249C-\u24E9\u26AC\u2800-\u28FF\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D70\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u302E\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3190-\u31BF\u31F0-\u321C\u3220-\u324F\u3260-\u327B\u327F-\u32B0\u32C0-\u32CB\u32D0-\u3376\u337B-\u33DD\u33E0-\u33FE\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA60C\uA610-\uA62B\uA640-\uA66E\uA680-\uA69D\uA6A0-\uA6EF\uA6F2-\uA6F7\uA722-\uA787\uA789-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA824\uA827\uA830-\uA837\uA840-\uA873\uA880-\uA8C3\uA8CE-\uA8D9\uA8F2-\uA8FE\uA900-\uA925\uA92E-\uA946\uA952\uA953\uA95F-\uA97C\uA983-\uA9B2\uA9B4\uA9B5\uA9BA\uA9BB\uA9BE-\uA9CD\uA9CF-\uA9D9\uA9DE-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA2F\uAA30\uAA33\uAA34\uAA40-\uAA42\uAA44-\uAA4B\uAA4D\uAA50-\uAA59\uAA5C-\uAA7B\uAA7D-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAAEB\uAAEE-\uAAF5\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB69\uAB70-\uABE4\uABE6\uABE7\uABE9-\uABEC\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uD800-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\u{10000}-\u{1000B}\u{1000D}-\u{10026}\u{10028}-\u{1003A}\u{1003C}\u{1003D}\u{1003F}-\u{1004D}\u{10050}-\u{1005D}\u{10080}-\u{100FA}\u{10100}\u{10102}\u{10107}-\u{10133}\u{10137}-\u{1013F}\u{1018D}\u{1018E}\u{101D0}-\u{101FC}\u{10280}-\u{1029C}\u{102A0}-\u{102D0}\u{10300}-\u{10323}\u{1032D}-\u{1034A}\u{10350}-\u{10375}\u{10380}-\u{1039D}\u{1039F}-\u{103C3}\u{103C8}-\u{103D5}\u{10400}-\u{1049D}\u{104A0}-\u{104A9}\u{104B0}-\u{104D3}\u{104D8}-\u{104FB}\u{10500}-\u{10527}\u{10530}-\u{10563}\u{1056F}-\u{1057A}\u{1057C}-\u{1058A}\u{1058C}-\u{10592}\u{10594}\u{10595}\u{10597}-\u{105A1}\u{105A3}-\u{105B1}\u{105B3}-\u{105B9}\u{105BB}\u{105BC}\u{10600}-\u{10736}\u{10740}-\u{10755}\u{10760}-\u{10767}\u{10780}-\u{10785}\u{10787}-\u{107B0}\u{107B2}-\u{107BA}\u{11000}\u{11002}-\u{11037}\u{11047}-\u{1104D}\u{11066}-\u{1106F}\u{11071}\u{11072}\u{11075}\u{11082}-\u{110B2}\u{110B7}\u{110B8}\u{110BB}-\u{110C1}\u{110CD}\u{110D0}-\u{110E8}\u{110F0}-\u{110F9}\u{11103}-\u{11126}\u{1112C}\u{11136}-\u{11147}\u{11150}-\u{11172}\u{11174}-\u{11176}\u{11182}-\u{111B5}\u{111BF}-\u{111C8}\u{111CD}\u{111CE}\u{111D0}-\u{111DF}\u{111E1}-\u{111F4}\u{11200}-\u{11211}\u{11213}-\u{1122E}\u{11232}\u{11233}\u{11235}\u{11238}-\u{1123D}\u{11280}-\u{11286}\u{11288}\u{1128A}-\u{1128D}\u{1128F}-\u{1129D}\u{1129F}-\u{112A9}\u{112B0}-\u{112DE}\u{112E0}-\u{112E2}\u{112F0}-\u{112F9}\u{11302}\u{11303}\u{11305}-\u{1130C}\u{1130F}\u{11310}\u{11313}-\u{11328}\u{1132A}-\u{11330}\u{11332}\u{11333}\u{11335}-\u{11339}\u{1133D}-\u{1133F}\u{11341}-\u{11344}\u{11347}\u{11348}\u{1134B}-\u{1134D}\u{11350}\u{11357}\u{1135D}-\u{11363}\u{11400}-\u{11437}\u{11440}\u{11441}\u{11445}\u{11447}-\u{1145B}\u{1145D}\u{1145F}-\u{11461}\u{11480}-\u{114B2}\u{114B9}\u{114BB}-\u{114BE}\u{114C1}\u{114C4}-\u{114C7}\u{114D0}-\u{114D9}\u{11580}-\u{115B1}\u{115B8}-\u{115BB}\u{115BE}\u{115C1}-\u{115DB}\u{11600}-\u{11632}\u{1163B}\u{1163C}\u{1163E}\u{11641}-\u{11644}\u{11650}-\u{11659}\u{11680}-\u{116AA}\u{116AC}\u{116AE}\u{116AF}\u{116B6}\u{116B8}\u{116B9}\u{116C0}-\u{116C9}\u{11700}-\u{1171A}\u{11720}\u{11721}\u{11726}\u{11730}-\u{11746}\u{11800}-\u{1182E}\u{11838}\u{1183B}\u{118A0}-\u{118F2}\u{118FF}-\u{11906}\u{11909}\u{1190C}-\u{11913}\u{11915}\u{11916}\u{11918}-\u{11935}\u{11937}\u{11938}\u{1193D}\u{1193F}-\u{11942}\u{11944}-\u{11946}\u{11950}-\u{11959}\u{119A0}-\u{119A7}\u{119AA}-\u{119D3}\u{119DC}-\u{119DF}\u{119E1}-\u{119E4}\u{11A00}\u{11A07}\u{11A08}\u{11A0B}-\u{11A32}\u{11A39}\u{11A3A}\u{11A3F}-\u{11A46}\u{11A50}\u{11A57}\u{11A58}\u{11A5C}-\u{11A89}\u{11A97}\u{11A9A}-\u{11AA2}\u{11AB0}-\u{11AF8}\u{11C00}-\u{11C08}\u{11C0A}-\u{11C2F}\u{11C3E}-\u{11C45}\u{11C50}-\u{11C6C}\u{11C70}-\u{11C8F}\u{11CA9}\u{11CB1}\u{11CB4}\u{11D00}-\u{11D06}\u{11D08}\u{11D09}\u{11D0B}-\u{11D30}\u{11D46}\u{11D50}-\u{11D59}\u{11D60}-\u{11D65}\u{11D67}\u{11D68}\u{11D6A}-\u{11D8E}\u{11D93}\u{11D94}\u{11D96}\u{11D98}\u{11DA0}-\u{11DA9}\u{11EE0}-\u{11EF2}\u{11EF5}-\u{11EF8}\u{11FB0}\u{11FC0}-\u{11FD4}\u{11FFF}-\u{12399}\u{12400}-\u{1246E}\u{12470}-\u{12474}\u{12480}-\u{12543}\u{12F90}-\u{12FF2}\u{13000}-\u{1342E}\u{13430}-\u{13438}\u{14400}-\u{14646}\u{16800}-\u{16A38}\u{16A40}-\u{16A5E}\u{16A60}-\u{16A69}\u{16A6E}-\u{16ABE}\u{16AC0}-\u{16AC9}\u{16AD0}-\u{16AED}\u{16AF5}\u{16B00}-\u{16B2F}\u{16B37}-\u{16B45}\u{16B50}-\u{16B59}\u{16B5B}-\u{16B61}\u{16B63}-\u{16B77}\u{16B7D}-\u{16B8F}\u{16E40}-\u{16E9A}\u{16F00}-\u{16F4A}\u{16F50}-\u{16F87}\u{16F93}-\u{16F9F}\u{16FE0}\u{16FE1}\u{16FE3}\u{16FF0}\u{16FF1}\u{17000}-\u{187F7}\u{18800}-\u{18CD5}\u{18D00}-\u{18D08}\u{1AFF0}-\u{1AFF3}\u{1AFF5}-\u{1AFFB}\u{1AFFD}\u{1AFFE}\u{1B000}-\u{1B122}\u{1B150}-\u{1B152}\u{1B164}-\u{1B167}\u{1B170}-\u{1B2FB}\u{1BC00}-\u{1BC6A}\u{1BC70}-\u{1BC7C}\u{1BC80}-\u{1BC88}\u{1BC90}-\u{1BC99}\u{1BC9C}\u{1BC9F}\u{1CF50}-\u{1CFC3}\u{1D000}-\u{1D0F5}\u{1D100}-\u{1D126}\u{1D129}-\u{1D166}\u{1D16A}-\u{1D172}\u{1D183}\u{1D184}\u{1D18C}-\u{1D1A9}\u{1D1AE}-\u{1D1E8}\u{1D2E0}-\u{1D2F3}\u{1D360}-\u{1D378}\u{1D400}-\u{1D454}\u{1D456}-\u{1D49C}\u{1D49E}\u{1D49F}\u{1D4A2}\u{1D4A5}\u{1D4A6}\u{1D4A9}-\u{1D4AC}\u{1D4AE}-\u{1D4B9}\u{1D4BB}\u{1D4BD}-\u{1D4C3}\u{1D4C5}-\u{1D505}\u{1D507}-\u{1D50A}\u{1D50D}-\u{1D514}\u{1D516}-\u{1D51C}\u{1D51E}-\u{1D539}\u{1D53B}-\u{1D53E}\u{1D540}-\u{1D544}\u{1D546}\u{1D54A}-\u{1D550}\u{1D552}-\u{1D6A5}\u{1D6A8}-\u{1D6DA}\u{1D6DC}-\u{1D714}\u{1D716}-\u{1D74E}\u{1D750}-\u{1D788}\u{1D78A}-\u{1D7C2}\u{1D7C4}-\u{1D7CB}\u{1D800}-\u{1D9FF}\u{1DA37}-\u{1DA3A}\u{1DA6D}-\u{1DA74}\u{1DA76}-\u{1DA83}\u{1DA85}-\u{1DA8B}\u{1DF00}-\u{1DF1E}\u{1E100}-\u{1E12C}\u{1E137}-\u{1E13D}\u{1E140}-\u{1E149}\u{1E14E}\u{1E14F}\u{1E290}-\u{1E2AD}\u{1E2C0}-\u{1E2EB}\u{1E2F0}-\u{1E2F9}\u{1E7E0}-\u{1E7E6}\u{1E7E8}-\u{1E7EB}\u{1E7ED}\u{1E7EE}\u{1E7F0}-\u{1E7FE}\u{1F110}-\u{1F12E}\u{1F130}-\u{1F169}\u{1F170}-\u{1F1AC}\u{1F1E6}-\u{1F202}\u{1F210}-\u{1F23B}\u{1F240}-\u{1F248}\u{1F250}\u{1F251}\u{20000}-\u{2A6DF}\u{2A700}-\u{2B738}\u{2B740}-\u{2B81D}\u{2B820}-\u{2CEA1}\u{2CEB0}-\u{2EBE0}\u{2F800}-\u{2FA1D}\u{30000}-\u{3134A}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]/u;
  14605. var bidiS1RTL = /[\u05BE\u05C0\u05C3\u05C6\u05D0-\u05EA\u05EF-\u05F4\u0608\u060B\u060D\u061B-\u064A\u066D-\u066F\u0671-\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u070D\u070F\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u07FE-\u0815\u081A\u0824\u0828\u0830-\u083E\u0840-\u0858\u085E\u0860-\u086A\u0870-\u088E\u08A0-\u08C9\u200F\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBC2\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFC\uFE70-\uFE74\uFE76-\uFEFC\u{10800}-\u{10805}\u{10808}\u{1080A}-\u{10835}\u{10837}\u{10838}\u{1083C}\u{1083F}-\u{10855}\u{10857}-\u{1089E}\u{108A7}-\u{108AF}\u{108E0}-\u{108F2}\u{108F4}\u{108F5}\u{108FB}-\u{1091B}\u{10920}-\u{10939}\u{1093F}\u{10980}-\u{109B7}\u{109BC}-\u{109CF}\u{109D2}-\u{10A00}\u{10A10}-\u{10A13}\u{10A15}-\u{10A17}\u{10A19}-\u{10A35}\u{10A40}-\u{10A48}\u{10A50}-\u{10A58}\u{10A60}-\u{10A9F}\u{10AC0}-\u{10AE4}\u{10AEB}-\u{10AF6}\u{10B00}-\u{10B35}\u{10B40}-\u{10B55}\u{10B58}-\u{10B72}\u{10B78}-\u{10B91}\u{10B99}-\u{10B9C}\u{10BA9}-\u{10BAF}\u{10C00}-\u{10C48}\u{10C80}-\u{10CB2}\u{10CC0}-\u{10CF2}\u{10CFA}-\u{10D23}\u{10E80}-\u{10EA9}\u{10EAD}\u{10EB0}\u{10EB1}\u{10F00}-\u{10F27}\u{10F30}-\u{10F45}\u{10F51}-\u{10F59}\u{10F70}-\u{10F81}\u{10F86}-\u{10F89}\u{10FB0}-\u{10FCB}\u{10FE0}-\u{10FF6}\u{1E800}-\u{1E8C4}\u{1E8C7}-\u{1E8CF}\u{1E900}-\u{1E943}\u{1E94B}\u{1E950}-\u{1E959}\u{1E95E}\u{1E95F}\u{1EC71}-\u{1ECB4}\u{1ED01}-\u{1ED3D}\u{1EE00}-\u{1EE03}\u{1EE05}-\u{1EE1F}\u{1EE21}\u{1EE22}\u{1EE24}\u{1EE27}\u{1EE29}-\u{1EE32}\u{1EE34}-\u{1EE37}\u{1EE39}\u{1EE3B}\u{1EE42}\u{1EE47}\u{1EE49}\u{1EE4B}\u{1EE4D}-\u{1EE4F}\u{1EE51}\u{1EE52}\u{1EE54}\u{1EE57}\u{1EE59}\u{1EE5B}\u{1EE5D}\u{1EE5F}\u{1EE61}\u{1EE62}\u{1EE64}\u{1EE67}-\u{1EE6A}\u{1EE6C}-\u{1EE72}\u{1EE74}-\u{1EE77}\u{1EE79}-\u{1EE7C}\u{1EE7E}\u{1EE80}-\u{1EE89}\u{1EE8B}-\u{1EE9B}\u{1EEA1}-\u{1EEA3}\u{1EEA5}-\u{1EEA9}\u{1EEAB}-\u{1EEBB}]/u;
  14606. var bidiS2 = /^[\0-\x08\x0E-\x1B!-@\[-`\{-\x84\x86-\xA9\xAB-\xB4\xB6-\xB9\xBB-\xBF\xD7\xF7\u02B9\u02BA\u02C2-\u02CF\u02D2-\u02DF\u02E5-\u02ED\u02EF-\u036F\u0374\u0375\u037E\u0384\u0385\u0387\u03F6\u0483-\u0489\u058A\u058D-\u058F\u0591-\u05C7\u05D0-\u05EA\u05EF-\u05F4\u0600-\u070D\u070F-\u074A\u074D-\u07B1\u07C0-\u07FA\u07FD-\u082D\u0830-\u083E\u0840-\u085B\u085E\u0860-\u086A\u0870-\u088E\u0890\u0891\u0898-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2\u09E3\u09F2\u09F3\u09FB\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AF1\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B55\u0B56\u0B62\u0B63\u0B82\u0BC0\u0BCD\u0BF3-\u0BFA\u0C00\u0C04\u0C3C\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C78-\u0C7E\u0C81\u0CBC\u0CCC\u0CCD\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D41-\u0D44\u0D4D\u0D62\u0D63\u0D81\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E3F\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39-\u0F3D\u0F71-\u0F7E\u0F80-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039\u103A\u103D\u103E\u1058\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085\u1086\u108D\u109D\u135D-\u135F\u1390-\u1399\u1400\u169B\u169C\u1712-\u1714\u1732\u1733\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DB\u17DD\u17F0-\u17F9\u1800-\u180F\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1940\u1944\u1945\u19DE-\u19FF\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80\u1B81\u1BA2-\u1BA5\u1BA8\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8\u1CF9\u1DC0-\u1DFF\u1FBD\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF\u1FFD\u1FFE\u200B-\u200D\u200F-\u2027\u202F-\u205E\u2060-\u2064\u206A-\u2070\u2074-\u207E\u2080-\u208E\u20A0-\u20C0\u20D0-\u20F0\u2100\u2101\u2103-\u2106\u2108\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A\u213B\u2140-\u2144\u214A-\u214D\u2150-\u215F\u2189-\u218B\u2190-\u2335\u237B-\u2394\u2396-\u2426\u2440-\u244A\u2460-\u249B\u24EA-\u26AB\u26AD-\u27FF\u2900-\u2B73\u2B76-\u2B95\u2B97-\u2BFF\u2CE5-\u2CEA\u2CEF-\u2CF1\u2CF9-\u2CFF\u2D7F\u2DE0-\u2E5D\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\u3004\u3008-\u3020\u302A-\u302D\u3030\u3036\u3037\u303D-\u303F\u3099-\u309C\u30A0\u30FB\u31C0-\u31E3\u321D\u321E\u3250-\u325F\u327C-\u327E\u32B1-\u32BF\u32CC-\u32CF\u3377-\u337A\u33DE\u33DF\u33FF\u4DC0-\u4DFF\uA490-\uA4C6\uA60D-\uA60F\uA66F-\uA67F\uA69E\uA69F\uA6F0\uA6F1\uA700-\uA721\uA788\uA802\uA806\uA80B\uA825\uA826\uA828-\uA82C\uA838\uA839\uA874-\uA877\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\uA9E5\uAA29-\uAA2E\uAA31\uAA32\uAA35\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEC\uAAED\uAAF6\uAB6A\uAB6B\uABE5\uABE8\uABED\uFB1D-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBC2\uFBD3-\uFD8F\uFD92-\uFDC7\uFDCF\uFDF0-\uFE19\uFE20-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFE70-\uFE74\uFE76-\uFEFC\uFEFF\uFF01-\uFF20\uFF3B-\uFF40\uFF5B-\uFF65\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFF9-\uFFFD\u{10101}\u{10140}-\u{1018C}\u{10190}-\u{1019C}\u{101A0}\u{101FD}\u{102E0}-\u{102FB}\u{10376}-\u{1037A}\u{10800}-\u{10805}\u{10808}\u{1080A}-\u{10835}\u{10837}\u{10838}\u{1083C}\u{1083F}-\u{10855}\u{10857}-\u{1089E}\u{108A7}-\u{108AF}\u{108E0}-\u{108F2}\u{108F4}\u{108F5}\u{108FB}-\u{1091B}\u{1091F}-\u{10939}\u{1093F}\u{10980}-\u{109B7}\u{109BC}-\u{109CF}\u{109D2}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A13}\u{10A15}-\u{10A17}\u{10A19}-\u{10A35}\u{10A38}-\u{10A3A}\u{10A3F}-\u{10A48}\u{10A50}-\u{10A58}\u{10A60}-\u{10A9F}\u{10AC0}-\u{10AE6}\u{10AEB}-\u{10AF6}\u{10B00}-\u{10B35}\u{10B39}-\u{10B55}\u{10B58}-\u{10B72}\u{10B78}-\u{10B91}\u{10B99}-\u{10B9C}\u{10BA9}-\u{10BAF}\u{10C00}-\u{10C48}\u{10C80}-\u{10CB2}\u{10CC0}-\u{10CF2}\u{10CFA}-\u{10D27}\u{10D30}-\u{10D39}\u{10E60}-\u{10E7E}\u{10E80}-\u{10EA9}\u{10EAB}-\u{10EAD}\u{10EB0}\u{10EB1}\u{10F00}-\u{10F27}\u{10F30}-\u{10F59}\u{10F70}-\u{10F89}\u{10FB0}-\u{10FCB}\u{10FE0}-\u{10FF6}\u{11001}\u{11038}-\u{11046}\u{11052}-\u{11065}\u{11070}\u{11073}\u{11074}\u{1107F}-\u{11081}\u{110B3}-\u{110B6}\u{110B9}\u{110BA}\u{110C2}\u{11100}-\u{11102}\u{11127}-\u{1112B}\u{1112D}-\u{11134}\u{11173}\u{11180}\u{11181}\u{111B6}-\u{111BE}\u{111C9}-\u{111CC}\u{111CF}\u{1122F}-\u{11231}\u{11234}\u{11236}\u{11237}\u{1123E}\u{112DF}\u{112E3}-\u{112EA}\u{11300}\u{11301}\u{1133B}\u{1133C}\u{11340}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11438}-\u{1143F}\u{11442}-\u{11444}\u{11446}\u{1145E}\u{114B3}-\u{114B8}\u{114BA}\u{114BF}\u{114C0}\u{114C2}\u{114C3}\u{115B2}-\u{115B5}\u{115BC}\u{115BD}\u{115BF}\u{115C0}\u{115DC}\u{115DD}\u{11633}-\u{1163A}\u{1163D}\u{1163F}\u{11640}\u{11660}-\u{1166C}\u{116AB}\u{116AD}\u{116B0}-\u{116B5}\u{116B7}\u{1171D}-\u{1171F}\u{11722}-\u{11725}\u{11727}-\u{1172B}\u{1182F}-\u{11837}\u{11839}\u{1183A}\u{1193B}\u{1193C}\u{1193E}\u{11943}\u{119D4}-\u{119D7}\u{119DA}\u{119DB}\u{119E0}\u{11A01}-\u{11A06}\u{11A09}\u{11A0A}\u{11A33}-\u{11A38}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A56}\u{11A59}-\u{11A5B}\u{11A8A}-\u{11A96}\u{11A98}\u{11A99}\u{11C30}-\u{11C36}\u{11C38}-\u{11C3D}\u{11C92}-\u{11CA7}\u{11CAA}-\u{11CB0}\u{11CB2}\u{11CB3}\u{11CB5}\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D90}\u{11D91}\u{11D95}\u{11D97}\u{11EF3}\u{11EF4}\u{11FD5}-\u{11FF1}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F8F}-\u{16F92}\u{16FE2}\u{16FE4}\u{1BC9D}\u{1BC9E}\u{1BCA0}-\u{1BCA3}\u{1CF00}-\u{1CF2D}\u{1CF30}-\u{1CF46}\u{1D167}-\u{1D169}\u{1D173}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D1E9}\u{1D1EA}\u{1D200}-\u{1D245}\u{1D300}-\u{1D356}\u{1D6DB}\u{1D715}\u{1D74F}\u{1D789}\u{1D7C3}\u{1D7CE}-\u{1D7FF}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2AE}\u{1E2EC}-\u{1E2EF}\u{1E2FF}\u{1E800}-\u{1E8C4}\u{1E8C7}-\u{1E8D6}\u{1E900}-\u{1E94B}\u{1E950}-\u{1E959}\u{1E95E}\u{1E95F}\u{1EC71}-\u{1ECB4}\u{1ED01}-\u{1ED3D}\u{1EE00}-\u{1EE03}\u{1EE05}-\u{1EE1F}\u{1EE21}\u{1EE22}\u{1EE24}\u{1EE27}\u{1EE29}-\u{1EE32}\u{1EE34}-\u{1EE37}\u{1EE39}\u{1EE3B}\u{1EE42}\u{1EE47}\u{1EE49}\u{1EE4B}\u{1EE4D}-\u{1EE4F}\u{1EE51}\u{1EE52}\u{1EE54}\u{1EE57}\u{1EE59}\u{1EE5B}\u{1EE5D}\u{1EE5F}\u{1EE61}\u{1EE62}\u{1EE64}\u{1EE67}-\u{1EE6A}\u{1EE6C}-\u{1EE72}\u{1EE74}-\u{1EE77}\u{1EE79}-\u{1EE7C}\u{1EE7E}\u{1EE80}-\u{1EE89}\u{1EE8B}-\u{1EE9B}\u{1EEA1}-\u{1EEA3}\u{1EEA5}-\u{1EEA9}\u{1EEAB}-\u{1EEBB}\u{1EEF0}\u{1EEF1}\u{1F000}-\u{1F02B}\u{1F030}-\u{1F093}\u{1F0A0}-\u{1F0AE}\u{1F0B1}-\u{1F0BF}\u{1F0C1}-\u{1F0CF}\u{1F0D1}-\u{1F0F5}\u{1F100}-\u{1F10F}\u{1F12F}\u{1F16A}-\u{1F16F}\u{1F1AD}\u{1F260}-\u{1F265}\u{1F300}-\u{1F6D7}\u{1F6DD}-\u{1F6EC}\u{1F6F0}-\u{1F6FC}\u{1F700}-\u{1F773}\u{1F780}-\u{1F7D8}\u{1F7E0}-\u{1F7EB}\u{1F7F0}\u{1F800}-\u{1F80B}\u{1F810}-\u{1F847}\u{1F850}-\u{1F859}\u{1F860}-\u{1F887}\u{1F890}-\u{1F8AD}\u{1F8B0}\u{1F8B1}\u{1F900}-\u{1FA53}\u{1FA60}-\u{1FA6D}\u{1FA70}-\u{1FA74}\u{1FA78}-\u{1FA7C}\u{1FA80}-\u{1FA86}\u{1FA90}-\u{1FAAC}\u{1FAB0}-\u{1FABA}\u{1FAC0}-\u{1FAC5}\u{1FAD0}-\u{1FAD9}\u{1FAE0}-\u{1FAE7}\u{1FAF0}-\u{1FAF6}\u{1FB00}-\u{1FB92}\u{1FB94}-\u{1FBCA}\u{1FBF0}-\u{1FBF9}\u{E0001}\u{E0020}-\u{E007F}\u{E0100}-\u{E01EF}]*$/u;
  14607. var bidiS3 = /[0-9\xB2\xB3\xB9\u05BE\u05C0\u05C3\u05C6\u05D0-\u05EA\u05EF-\u05F4\u0600-\u0605\u0608\u060B\u060D\u061B-\u064A\u0660-\u0669\u066B-\u066F\u0671-\u06D5\u06DD\u06E5\u06E6\u06EE-\u070D\u070F\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u07FE-\u0815\u081A\u0824\u0828\u0830-\u083E\u0840-\u0858\u085E\u0860-\u086A\u0870-\u088E\u0890\u0891\u08A0-\u08C9\u08E2\u200F\u2070\u2074-\u2079\u2080-\u2089\u2488-\u249B\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBC2\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFC\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\u{102E1}-\u{102FB}\u{10800}-\u{10805}\u{10808}\u{1080A}-\u{10835}\u{10837}\u{10838}\u{1083C}\u{1083F}-\u{10855}\u{10857}-\u{1089E}\u{108A7}-\u{108AF}\u{108E0}-\u{108F2}\u{108F4}\u{108F5}\u{108FB}-\u{1091B}\u{10920}-\u{10939}\u{1093F}\u{10980}-\u{109B7}\u{109BC}-\u{109CF}\u{109D2}-\u{10A00}\u{10A10}-\u{10A13}\u{10A15}-\u{10A17}\u{10A19}-\u{10A35}\u{10A40}-\u{10A48}\u{10A50}-\u{10A58}\u{10A60}-\u{10A9F}\u{10AC0}-\u{10AE4}\u{10AEB}-\u{10AF6}\u{10B00}-\u{10B35}\u{10B40}-\u{10B55}\u{10B58}-\u{10B72}\u{10B78}-\u{10B91}\u{10B99}-\u{10B9C}\u{10BA9}-\u{10BAF}\u{10C00}-\u{10C48}\u{10C80}-\u{10CB2}\u{10CC0}-\u{10CF2}\u{10CFA}-\u{10D23}\u{10D30}-\u{10D39}\u{10E60}-\u{10E7E}\u{10E80}-\u{10EA9}\u{10EAD}\u{10EB0}\u{10EB1}\u{10F00}-\u{10F27}\u{10F30}-\u{10F45}\u{10F51}-\u{10F59}\u{10F70}-\u{10F81}\u{10F86}-\u{10F89}\u{10FB0}-\u{10FCB}\u{10FE0}-\u{10FF6}\u{1D7CE}-\u{1D7FF}\u{1E800}-\u{1E8C4}\u{1E8C7}-\u{1E8CF}\u{1E900}-\u{1E943}\u{1E94B}\u{1E950}-\u{1E959}\u{1E95E}\u{1E95F}\u{1EC71}-\u{1ECB4}\u{1ED01}-\u{1ED3D}\u{1EE00}-\u{1EE03}\u{1EE05}-\u{1EE1F}\u{1EE21}\u{1EE22}\u{1EE24}\u{1EE27}\u{1EE29}-\u{1EE32}\u{1EE34}-\u{1EE37}\u{1EE39}\u{1EE3B}\u{1EE42}\u{1EE47}\u{1EE49}\u{1EE4B}\u{1EE4D}-\u{1EE4F}\u{1EE51}\u{1EE52}\u{1EE54}\u{1EE57}\u{1EE59}\u{1EE5B}\u{1EE5D}\u{1EE5F}\u{1EE61}\u{1EE62}\u{1EE64}\u{1EE67}-\u{1EE6A}\u{1EE6C}-\u{1EE72}\u{1EE74}-\u{1EE77}\u{1EE79}-\u{1EE7C}\u{1EE7E}\u{1EE80}-\u{1EE89}\u{1EE8B}-\u{1EE9B}\u{1EEA1}-\u{1EEA3}\u{1EEA5}-\u{1EEA9}\u{1EEAB}-\u{1EEBB}\u{1F100}-\u{1F10A}\u{1FBF0}-\u{1FBF9}][\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B55\u0B56\u0B62\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C04\u0C3C\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CCC\u0CCD\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D41-\u0D44\u0D4D\u0D62\u0D63\u0D81\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039\u103A\u103D\u103E\u1058\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732\u1733\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u180F\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80\u1B81\u1BA2-\u1BA5\u1BA8\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8\u1CF9\u1DC0-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA82C\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\uA9E5\uAA29-\uAA2E\uAA31\uAA32\uAA35\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEC\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10D24}-\u{10D27}\u{10EAB}\u{10EAC}\u{10F46}-\u{10F50}\u{10F82}-\u{10F85}\u{11001}\u{11038}-\u{11046}\u{11070}\u{11073}\u{11074}\u{1107F}-\u{11081}\u{110B3}-\u{110B6}\u{110B9}\u{110BA}\u{110C2}\u{11100}-\u{11102}\u{11127}-\u{1112B}\u{1112D}-\u{11134}\u{11173}\u{11180}\u{11181}\u{111B6}-\u{111BE}\u{111C9}-\u{111CC}\u{111CF}\u{1122F}-\u{11231}\u{11234}\u{11236}\u{11237}\u{1123E}\u{112DF}\u{112E3}-\u{112EA}\u{11300}\u{11301}\u{1133B}\u{1133C}\u{11340}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11438}-\u{1143F}\u{11442}-\u{11444}\u{11446}\u{1145E}\u{114B3}-\u{114B8}\u{114BA}\u{114BF}\u{114C0}\u{114C2}\u{114C3}\u{115B2}-\u{115B5}\u{115BC}\u{115BD}\u{115BF}\u{115C0}\u{115DC}\u{115DD}\u{11633}-\u{1163A}\u{1163D}\u{1163F}\u{11640}\u{116AB}\u{116AD}\u{116B0}-\u{116B5}\u{116B7}\u{1171D}-\u{1171F}\u{11722}-\u{11725}\u{11727}-\u{1172B}\u{1182F}-\u{11837}\u{11839}\u{1183A}\u{1193B}\u{1193C}\u{1193E}\u{11943}\u{119D4}-\u{119D7}\u{119DA}\u{119DB}\u{119E0}\u{11A01}-\u{11A06}\u{11A09}\u{11A0A}\u{11A33}-\u{11A38}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A56}\u{11A59}-\u{11A5B}\u{11A8A}-\u{11A96}\u{11A98}\u{11A99}\u{11C30}-\u{11C36}\u{11C38}-\u{11C3D}\u{11C92}-\u{11CA7}\u{11CAA}-\u{11CB0}\u{11CB2}\u{11CB3}\u{11CB5}\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D90}\u{11D91}\u{11D95}\u{11D97}\u{11EF3}\u{11EF4}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F8F}-\u{16F92}\u{16FE4}\u{1BC9D}\u{1BC9E}\u{1CF00}-\u{1CF2D}\u{1CF30}-\u{1CF46}\u{1D167}-\u{1D169}\u{1D17B}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D242}-\u{1D244}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2AE}\u{1E2EC}-\u{1E2EF}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94A}\u{E0100}-\u{E01EF}]*$/u;
  14608. var bidiS4EN = /[0-9\xB2\xB3\xB9\u06F0-\u06F9\u2070\u2074-\u2079\u2080-\u2089\u2488-\u249B\uFF10-\uFF19\u{102E1}-\u{102FB}\u{1D7CE}-\u{1D7FF}\u{1F100}-\u{1F10A}\u{1FBF0}-\u{1FBF9}]/u;
  14609. var bidiS4AN = /[\u0600-\u0605\u0660-\u0669\u066B\u066C\u06DD\u0890\u0891\u08E2\u{10D30}-\u{10D39}\u{10E60}-\u{10E7E}]/u;
  14610. var bidiS5 = /^[\0-\x08\x0E-\x1B!-\x84\x86-\u0377\u037A-\u037F\u0384-\u038A\u038C\u038E-\u03A1\u03A3-\u052F\u0531-\u0556\u0559-\u058A\u058D-\u058F\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0606\u0607\u0609\u060A\u060C\u060E-\u061A\u064B-\u065F\u066A\u0670\u06D6-\u06DC\u06DE-\u06E4\u06E7-\u06ED\u06F0-\u06F9\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07F6-\u07F9\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09FE\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A76\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AF1\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B55-\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B77\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BFA\u0C00-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3C-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C5D\u0C60-\u0C63\u0C66-\u0C6F\u0C77-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDD\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4F\u0D54-\u0D63\u0D66-\u0D7F\u0D81-\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2-\u0DF4\u0E01-\u0E3A\u0E3F-\u0E5B\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00-\u0F47\u0F49-\u0F6C\u0F71-\u0F97\u0F99-\u0FBC\u0FBE-\u0FCC\u0FCE-\u0FDA\u1000-\u10C5\u10C7\u10CD\u10D0-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u137C\u1380-\u1399\u13A0-\u13F5\u13F8-\u13FD\u1400-\u167F\u1681-\u169C\u16A0-\u16F8\u1700-\u1715\u171F-\u1736\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17DD\u17E0-\u17E9\u17F0-\u17F9\u1800-\u1819\u1820-\u1878\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1940\u1944-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u19DE-\u1A1B\u1A1E-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA0-\u1AAD\u1AB0-\u1ACE\u1B00-\u1B4C\u1B50-\u1B7E\u1B80-\u1BF3\u1BFC-\u1C37\u1C3B-\u1C49\u1C4D-\u1C88\u1C90-\u1CBA\u1CBD-\u1CC7\u1CD0-\u1CFA\u1D00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FC4\u1FC6-\u1FD3\u1FD6-\u1FDB\u1FDD-\u1FEF\u1FF2-\u1FF4\u1FF6-\u1FFE\u200B-\u200E\u2010-\u2027\u202F-\u205E\u2060-\u2064\u206A-\u2071\u2074-\u208E\u2090-\u209C\u20A0-\u20C0\u20D0-\u20F0\u2100-\u218B\u2190-\u2426\u2440-\u244A\u2460-\u2B73\u2B76-\u2B95\u2B97-\u2CF3\u2CF9-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D70\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2E5D\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3001-\u303F\u3041-\u3096\u3099-\u30FF\u3105-\u312F\u3131-\u318E\u3190-\u31E3\u31F0-\u321E\u3220-\uA48C\uA490-\uA4C6\uA4D0-\uA62B\uA640-\uA6F7\uA700-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA82C\uA830-\uA839\uA840-\uA877\uA880-\uA8C5\uA8CE-\uA8D9\uA8E0-\uA953\uA95F-\uA97C\uA980-\uA9CD\uA9CF-\uA9D9\uA9DE-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA5C-\uAAC2\uAADB-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB6B\uAB70-\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uD800-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1E\uFB29\uFD3E-\uFD4F\uFDCF\uFDFD-\uFE19\uFE20-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFEFF\uFF01-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\uFFE0-\uFFE6\uFFE8-\uFFEE\uFFF9-\uFFFD\u{10000}-\u{1000B}\u{1000D}-\u{10026}\u{10028}-\u{1003A}\u{1003C}\u{1003D}\u{1003F}-\u{1004D}\u{10050}-\u{1005D}\u{10080}-\u{100FA}\u{10100}-\u{10102}\u{10107}-\u{10133}\u{10137}-\u{1018E}\u{10190}-\u{1019C}\u{101A0}\u{101D0}-\u{101FD}\u{10280}-\u{1029C}\u{102A0}-\u{102D0}\u{102E0}-\u{102FB}\u{10300}-\u{10323}\u{1032D}-\u{1034A}\u{10350}-\u{1037A}\u{10380}-\u{1039D}\u{1039F}-\u{103C3}\u{103C8}-\u{103D5}\u{10400}-\u{1049D}\u{104A0}-\u{104A9}\u{104B0}-\u{104D3}\u{104D8}-\u{104FB}\u{10500}-\u{10527}\u{10530}-\u{10563}\u{1056F}-\u{1057A}\u{1057C}-\u{1058A}\u{1058C}-\u{10592}\u{10594}\u{10595}\u{10597}-\u{105A1}\u{105A3}-\u{105B1}\u{105B3}-\u{105B9}\u{105BB}\u{105BC}\u{10600}-\u{10736}\u{10740}-\u{10755}\u{10760}-\u{10767}\u{10780}-\u{10785}\u{10787}-\u{107B0}\u{107B2}-\u{107BA}\u{1091F}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10B39}-\u{10B3F}\u{10D24}-\u{10D27}\u{10EAB}\u{10EAC}\u{10F46}-\u{10F50}\u{10F82}-\u{10F85}\u{11000}-\u{1104D}\u{11052}-\u{11075}\u{1107F}-\u{110C2}\u{110CD}\u{110D0}-\u{110E8}\u{110F0}-\u{110F9}\u{11100}-\u{11134}\u{11136}-\u{11147}\u{11150}-\u{11176}\u{11180}-\u{111DF}\u{111E1}-\u{111F4}\u{11200}-\u{11211}\u{11213}-\u{1123E}\u{11280}-\u{11286}\u{11288}\u{1128A}-\u{1128D}\u{1128F}-\u{1129D}\u{1129F}-\u{112A9}\u{112B0}-\u{112EA}\u{112F0}-\u{112F9}\u{11300}-\u{11303}\u{11305}-\u{1130C}\u{1130F}\u{11310}\u{11313}-\u{11328}\u{1132A}-\u{11330}\u{11332}\u{11333}\u{11335}-\u{11339}\u{1133B}-\u{11344}\u{11347}\u{11348}\u{1134B}-\u{1134D}\u{11350}\u{11357}\u{1135D}-\u{11363}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11400}-\u{1145B}\u{1145D}-\u{11461}\u{11480}-\u{114C7}\u{114D0}-\u{114D9}\u{11580}-\u{115B5}\u{115B8}-\u{115DD}\u{11600}-\u{11644}\u{11650}-\u{11659}\u{11660}-\u{1166C}\u{11680}-\u{116B9}\u{116C0}-\u{116C9}\u{11700}-\u{1171A}\u{1171D}-\u{1172B}\u{11730}-\u{11746}\u{11800}-\u{1183B}\u{118A0}-\u{118F2}\u{118FF}-\u{11906}\u{11909}\u{1190C}-\u{11913}\u{11915}\u{11916}\u{11918}-\u{11935}\u{11937}\u{11938}\u{1193B}-\u{11946}\u{11950}-\u{11959}\u{119A0}-\u{119A7}\u{119AA}-\u{119D7}\u{119DA}-\u{119E4}\u{11A00}-\u{11A47}\u{11A50}-\u{11AA2}\u{11AB0}-\u{11AF8}\u{11C00}-\u{11C08}\u{11C0A}-\u{11C36}\u{11C38}-\u{11C45}\u{11C50}-\u{11C6C}\u{11C70}-\u{11C8F}\u{11C92}-\u{11CA7}\u{11CA9}-\u{11CB6}\u{11D00}-\u{11D06}\u{11D08}\u{11D09}\u{11D0B}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D47}\u{11D50}-\u{11D59}\u{11D60}-\u{11D65}\u{11D67}\u{11D68}\u{11D6A}-\u{11D8E}\u{11D90}\u{11D91}\u{11D93}-\u{11D98}\u{11DA0}-\u{11DA9}\u{11EE0}-\u{11EF8}\u{11FB0}\u{11FC0}-\u{11FF1}\u{11FFF}-\u{12399}\u{12400}-\u{1246E}\u{12470}-\u{12474}\u{12480}-\u{12543}\u{12F90}-\u{12FF2}\u{13000}-\u{1342E}\u{13430}-\u{13438}\u{14400}-\u{14646}\u{16800}-\u{16A38}\u{16A40}-\u{16A5E}\u{16A60}-\u{16A69}\u{16A6E}-\u{16ABE}\u{16AC0}-\u{16AC9}\u{16AD0}-\u{16AED}\u{16AF0}-\u{16AF5}\u{16B00}-\u{16B45}\u{16B50}-\u{16B59}\u{16B5B}-\u{16B61}\u{16B63}-\u{16B77}\u{16B7D}-\u{16B8F}\u{16E40}-\u{16E9A}\u{16F00}-\u{16F4A}\u{16F4F}-\u{16F87}\u{16F8F}-\u{16F9F}\u{16FE0}-\u{16FE4}\u{16FF0}\u{16FF1}\u{17000}-\u{187F7}\u{18800}-\u{18CD5}\u{18D00}-\u{18D08}\u{1AFF0}-\u{1AFF3}\u{1AFF5}-\u{1AFFB}\u{1AFFD}\u{1AFFE}\u{1B000}-\u{1B122}\u{1B150}-\u{1B152}\u{1B164}-\u{1B167}\u{1B170}-\u{1B2FB}\u{1BC00}-\u{1BC6A}\u{1BC70}-\u{1BC7C}\u{1BC80}-\u{1BC88}\u{1BC90}-\u{1BC99}\u{1BC9C}-\u{1BCA3}\u{1CF00}-\u{1CF2D}\u{1CF30}-\u{1CF46}\u{1CF50}-\u{1CFC3}\u{1D000}-\u{1D0F5}\u{1D100}-\u{1D126}\u{1D129}-\u{1D1EA}\u{1D200}-\u{1D245}\u{1D2E0}-\u{1D2F3}\u{1D300}-\u{1D356}\u{1D360}-\u{1D378}\u{1D400}-\u{1D454}\u{1D456}-\u{1D49C}\u{1D49E}\u{1D49F}\u{1D4A2}\u{1D4A5}\u{1D4A6}\u{1D4A9}-\u{1D4AC}\u{1D4AE}-\u{1D4B9}\u{1D4BB}\u{1D4BD}-\u{1D4C3}\u{1D4C5}-\u{1D505}\u{1D507}-\u{1D50A}\u{1D50D}-\u{1D514}\u{1D516}-\u{1D51C}\u{1D51E}-\u{1D539}\u{1D53B}-\u{1D53E}\u{1D540}-\u{1D544}\u{1D546}\u{1D54A}-\u{1D550}\u{1D552}-\u{1D6A5}\u{1D6A8}-\u{1D7CB}\u{1D7CE}-\u{1DA8B}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1DF00}-\u{1DF1E}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E100}-\u{1E12C}\u{1E130}-\u{1E13D}\u{1E140}-\u{1E149}\u{1E14E}\u{1E14F}\u{1E290}-\u{1E2AE}\u{1E2C0}-\u{1E2F9}\u{1E2FF}\u{1E7E0}-\u{1E7E6}\u{1E7E8}-\u{1E7EB}\u{1E7ED}\u{1E7EE}\u{1E7F0}-\u{1E7FE}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94A}\u{1EEF0}\u{1EEF1}\u{1F000}-\u{1F02B}\u{1F030}-\u{1F093}\u{1F0A0}-\u{1F0AE}\u{1F0B1}-\u{1F0BF}\u{1F0C1}-\u{1F0CF}\u{1F0D1}-\u{1F0F5}\u{1F100}-\u{1F1AD}\u{1F1E6}-\u{1F202}\u{1F210}-\u{1F23B}\u{1F240}-\u{1F248}\u{1F250}\u{1F251}\u{1F260}-\u{1F265}\u{1F300}-\u{1F6D7}\u{1F6DD}-\u{1F6EC}\u{1F6F0}-\u{1F6FC}\u{1F700}-\u{1F773}\u{1F780}-\u{1F7D8}\u{1F7E0}-\u{1F7EB}\u{1F7F0}\u{1F800}-\u{1F80B}\u{1F810}-\u{1F847}\u{1F850}-\u{1F859}\u{1F860}-\u{1F887}\u{1F890}-\u{1F8AD}\u{1F8B0}\u{1F8B1}\u{1F900}-\u{1FA53}\u{1FA60}-\u{1FA6D}\u{1FA70}-\u{1FA74}\u{1FA78}-\u{1FA7C}\u{1FA80}-\u{1FA86}\u{1FA90}-\u{1FAAC}\u{1FAB0}-\u{1FABA}\u{1FAC0}-\u{1FAC5}\u{1FAD0}-\u{1FAD9}\u{1FAE0}-\u{1FAE7}\u{1FAF0}-\u{1FAF6}\u{1FB00}-\u{1FB92}\u{1FB94}-\u{1FBCA}\u{1FBF0}-\u{1FBF9}\u{20000}-\u{2A6DF}\u{2A700}-\u{2B738}\u{2B740}-\u{2B81D}\u{2B820}-\u{2CEA1}\u{2CEB0}-\u{2EBE0}\u{2F800}-\u{2FA1D}\u{30000}-\u{3134A}\u{E0001}\u{E0020}-\u{E007F}\u{E0100}-\u{E01EF}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}]*$/u;
  14611. var bidiS6 = /[0-9A-Za-z\xAA\xB2\xB3\xB5\xB9\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02B8\u02BB-\u02C1\u02D0\u02D1\u02E0-\u02E4\u02EE\u0370-\u0373\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0482\u048A-\u052F\u0531-\u0556\u0559-\u0589\u06F0-\u06F9\u0903-\u0939\u093B\u093D-\u0940\u0949-\u094C\u094E-\u0950\u0958-\u0961\u0964-\u0980\u0982\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD-\u09C0\u09C7\u09C8\u09CB\u09CC\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09FA\u09FC\u09FD\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3E-\u0A40\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A76\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD-\u0AC0\u0AC9\u0ACB\u0ACC\u0AD0\u0AE0\u0AE1\u0AE6-\u0AF0\u0AF9\u0B02\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B3E\u0B40\u0B47\u0B48\u0B4B\u0B4C\u0B57\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE\u0BBF\u0BC1\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCC\u0BD0\u0BD7\u0BE6-\u0BF2\u0C01-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C41-\u0C44\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C77\u0C7F\u0C80\u0C82-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD-\u0CC4\u0CC6-\u0CC8\u0CCA\u0CCB\u0CD5\u0CD6\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D02-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D-\u0D40\u0D46-\u0D48\u0D4A-\u0D4C\u0D4E\u0D4F\u0D54-\u0D61\u0D66-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCF-\u0DD1\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2-\u0DF4\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E4F-\u0E5B\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00-\u0F17\u0F1A-\u0F34\u0F36\u0F38\u0F3E-\u0F47\u0F49-\u0F6C\u0F7F\u0F85\u0F88-\u0F8C\u0FBE-\u0FC5\u0FC7-\u0FCC\u0FCE-\u0FDA\u1000-\u102C\u1031\u1038\u103B\u103C\u103F-\u1057\u105A-\u105D\u1061-\u1070\u1075-\u1081\u1083\u1084\u1087-\u108C\u108E-\u109C\u109E-\u10C5\u10C7\u10CD\u10D0-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1360-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u167F\u1681-\u169A\u16A0-\u16F8\u1700-\u1711\u1715\u171F-\u1731\u1734-\u1736\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17B6\u17BE-\u17C5\u17C7\u17C8\u17D4-\u17DA\u17DC\u17E0-\u17E9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1923-\u1926\u1929-\u192B\u1930\u1931\u1933-\u1938\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A19\u1A1A\u1A1E-\u1A55\u1A57\u1A61\u1A63\u1A64\u1A6D-\u1A72\u1A80-\u1A89\u1A90-\u1A99\u1AA0-\u1AAD\u1B04-\u1B33\u1B35\u1B3B\u1B3D-\u1B41\u1B43-\u1B4C\u1B50-\u1B6A\u1B74-\u1B7E\u1B82-\u1BA1\u1BA6\u1BA7\u1BAA\u1BAE-\u1BE5\u1BE7\u1BEA-\u1BEC\u1BEE\u1BF2\u1BF3\u1BFC-\u1C2B\u1C34\u1C35\u1C3B-\u1C49\u1C4D-\u1C88\u1C90-\u1CBA\u1CBD-\u1CC7\u1CD3\u1CE1\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5-\u1CF7\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u200E\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u214F\u2160-\u2188\u2336-\u237A\u2395\u2488-\u24E9\u26AC\u2800-\u28FF\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D70\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u3005-\u3007\u3021-\u3029\u302E\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3190-\u31BF\u31F0-\u321C\u3220-\u324F\u3260-\u327B\u327F-\u32B0\u32C0-\u32CB\u32D0-\u3376\u337B-\u33DD\u33E0-\u33FE\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA60C\uA610-\uA62B\uA640-\uA66E\uA680-\uA69D\uA6A0-\uA6EF\uA6F2-\uA6F7\uA722-\uA787\uA789-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA824\uA827\uA830-\uA837\uA840-\uA873\uA880-\uA8C3\uA8CE-\uA8D9\uA8F2-\uA8FE\uA900-\uA925\uA92E-\uA946\uA952\uA953\uA95F-\uA97C\uA983-\uA9B2\uA9B4\uA9B5\uA9BA\uA9BB\uA9BE-\uA9CD\uA9CF-\uA9D9\uA9DE-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA2F\uAA30\uAA33\uAA34\uAA40-\uAA42\uAA44-\uAA4B\uAA4D\uAA50-\uAA59\uAA5C-\uAA7B\uAA7D-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAAEB\uAAEE-\uAAF5\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB69\uAB70-\uABE4\uABE6\uABE7\uABE9-\uABEC\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uD800-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC\u{10000}-\u{1000B}\u{1000D}-\u{10026}\u{10028}-\u{1003A}\u{1003C}\u{1003D}\u{1003F}-\u{1004D}\u{10050}-\u{1005D}\u{10080}-\u{100FA}\u{10100}\u{10102}\u{10107}-\u{10133}\u{10137}-\u{1013F}\u{1018D}\u{1018E}\u{101D0}-\u{101FC}\u{10280}-\u{1029C}\u{102A0}-\u{102D0}\u{102E1}-\u{102FB}\u{10300}-\u{10323}\u{1032D}-\u{1034A}\u{10350}-\u{10375}\u{10380}-\u{1039D}\u{1039F}-\u{103C3}\u{103C8}-\u{103D5}\u{10400}-\u{1049D}\u{104A0}-\u{104A9}\u{104B0}-\u{104D3}\u{104D8}-\u{104FB}\u{10500}-\u{10527}\u{10530}-\u{10563}\u{1056F}-\u{1057A}\u{1057C}-\u{1058A}\u{1058C}-\u{10592}\u{10594}\u{10595}\u{10597}-\u{105A1}\u{105A3}-\u{105B1}\u{105B3}-\u{105B9}\u{105BB}\u{105BC}\u{10600}-\u{10736}\u{10740}-\u{10755}\u{10760}-\u{10767}\u{10780}-\u{10785}\u{10787}-\u{107B0}\u{107B2}-\u{107BA}\u{11000}\u{11002}-\u{11037}\u{11047}-\u{1104D}\u{11066}-\u{1106F}\u{11071}\u{11072}\u{11075}\u{11082}-\u{110B2}\u{110B7}\u{110B8}\u{110BB}-\u{110C1}\u{110CD}\u{110D0}-\u{110E8}\u{110F0}-\u{110F9}\u{11103}-\u{11126}\u{1112C}\u{11136}-\u{11147}\u{11150}-\u{11172}\u{11174}-\u{11176}\u{11182}-\u{111B5}\u{111BF}-\u{111C8}\u{111CD}\u{111CE}\u{111D0}-\u{111DF}\u{111E1}-\u{111F4}\u{11200}-\u{11211}\u{11213}-\u{1122E}\u{11232}\u{11233}\u{11235}\u{11238}-\u{1123D}\u{11280}-\u{11286}\u{11288}\u{1128A}-\u{1128D}\u{1128F}-\u{1129D}\u{1129F}-\u{112A9}\u{112B0}-\u{112DE}\u{112E0}-\u{112E2}\u{112F0}-\u{112F9}\u{11302}\u{11303}\u{11305}-\u{1130C}\u{1130F}\u{11310}\u{11313}-\u{11328}\u{1132A}-\u{11330}\u{11332}\u{11333}\u{11335}-\u{11339}\u{1133D}-\u{1133F}\u{11341}-\u{11344}\u{11347}\u{11348}\u{1134B}-\u{1134D}\u{11350}\u{11357}\u{1135D}-\u{11363}\u{11400}-\u{11437}\u{11440}\u{11441}\u{11445}\u{11447}-\u{1145B}\u{1145D}\u{1145F}-\u{11461}\u{11480}-\u{114B2}\u{114B9}\u{114BB}-\u{114BE}\u{114C1}\u{114C4}-\u{114C7}\u{114D0}-\u{114D9}\u{11580}-\u{115B1}\u{115B8}-\u{115BB}\u{115BE}\u{115C1}-\u{115DB}\u{11600}-\u{11632}\u{1163B}\u{1163C}\u{1163E}\u{11641}-\u{11644}\u{11650}-\u{11659}\u{11680}-\u{116AA}\u{116AC}\u{116AE}\u{116AF}\u{116B6}\u{116B8}\u{116B9}\u{116C0}-\u{116C9}\u{11700}-\u{1171A}\u{11720}\u{11721}\u{11726}\u{11730}-\u{11746}\u{11800}-\u{1182E}\u{11838}\u{1183B}\u{118A0}-\u{118F2}\u{118FF}-\u{11906}\u{11909}\u{1190C}-\u{11913}\u{11915}\u{11916}\u{11918}-\u{11935}\u{11937}\u{11938}\u{1193D}\u{1193F}-\u{11942}\u{11944}-\u{11946}\u{11950}-\u{11959}\u{119A0}-\u{119A7}\u{119AA}-\u{119D3}\u{119DC}-\u{119DF}\u{119E1}-\u{119E4}\u{11A00}\u{11A07}\u{11A08}\u{11A0B}-\u{11A32}\u{11A39}\u{11A3A}\u{11A3F}-\u{11A46}\u{11A50}\u{11A57}\u{11A58}\u{11A5C}-\u{11A89}\u{11A97}\u{11A9A}-\u{11AA2}\u{11AB0}-\u{11AF8}\u{11C00}-\u{11C08}\u{11C0A}-\u{11C2F}\u{11C3E}-\u{11C45}\u{11C50}-\u{11C6C}\u{11C70}-\u{11C8F}\u{11CA9}\u{11CB1}\u{11CB4}\u{11D00}-\u{11D06}\u{11D08}\u{11D09}\u{11D0B}-\u{11D30}\u{11D46}\u{11D50}-\u{11D59}\u{11D60}-\u{11D65}\u{11D67}\u{11D68}\u{11D6A}-\u{11D8E}\u{11D93}\u{11D94}\u{11D96}\u{11D98}\u{11DA0}-\u{11DA9}\u{11EE0}-\u{11EF2}\u{11EF5}-\u{11EF8}\u{11FB0}\u{11FC0}-\u{11FD4}\u{11FFF}-\u{12399}\u{12400}-\u{1246E}\u{12470}-\u{12474}\u{12480}-\u{12543}\u{12F90}-\u{12FF2}\u{13000}-\u{1342E}\u{13430}-\u{13438}\u{14400}-\u{14646}\u{16800}-\u{16A38}\u{16A40}-\u{16A5E}\u{16A60}-\u{16A69}\u{16A6E}-\u{16ABE}\u{16AC0}-\u{16AC9}\u{16AD0}-\u{16AED}\u{16AF5}\u{16B00}-\u{16B2F}\u{16B37}-\u{16B45}\u{16B50}-\u{16B59}\u{16B5B}-\u{16B61}\u{16B63}-\u{16B77}\u{16B7D}-\u{16B8F}\u{16E40}-\u{16E9A}\u{16F00}-\u{16F4A}\u{16F50}-\u{16F87}\u{16F93}-\u{16F9F}\u{16FE0}\u{16FE1}\u{16FE3}\u{16FF0}\u{16FF1}\u{17000}-\u{187F7}\u{18800}-\u{18CD5}\u{18D00}-\u{18D08}\u{1AFF0}-\u{1AFF3}\u{1AFF5}-\u{1AFFB}\u{1AFFD}\u{1AFFE}\u{1B000}-\u{1B122}\u{1B150}-\u{1B152}\u{1B164}-\u{1B167}\u{1B170}-\u{1B2FB}\u{1BC00}-\u{1BC6A}\u{1BC70}-\u{1BC7C}\u{1BC80}-\u{1BC88}\u{1BC90}-\u{1BC99}\u{1BC9C}\u{1BC9F}\u{1CF50}-\u{1CFC3}\u{1D000}-\u{1D0F5}\u{1D100}-\u{1D126}\u{1D129}-\u{1D166}\u{1D16A}-\u{1D172}\u{1D183}\u{1D184}\u{1D18C}-\u{1D1A9}\u{1D1AE}-\u{1D1E8}\u{1D2E0}-\u{1D2F3}\u{1D360}-\u{1D378}\u{1D400}-\u{1D454}\u{1D456}-\u{1D49C}\u{1D49E}\u{1D49F}\u{1D4A2}\u{1D4A5}\u{1D4A6}\u{1D4A9}-\u{1D4AC}\u{1D4AE}-\u{1D4B9}\u{1D4BB}\u{1D4BD}-\u{1D4C3}\u{1D4C5}-\u{1D505}\u{1D507}-\u{1D50A}\u{1D50D}-\u{1D514}\u{1D516}-\u{1D51C}\u{1D51E}-\u{1D539}\u{1D53B}-\u{1D53E}\u{1D540}-\u{1D544}\u{1D546}\u{1D54A}-\u{1D550}\u{1D552}-\u{1D6A5}\u{1D6A8}-\u{1D6DA}\u{1D6DC}-\u{1D714}\u{1D716}-\u{1D74E}\u{1D750}-\u{1D788}\u{1D78A}-\u{1D7C2}\u{1D7C4}-\u{1D7CB}\u{1D7CE}-\u{1D9FF}\u{1DA37}-\u{1DA3A}\u{1DA6D}-\u{1DA74}\u{1DA76}-\u{1DA83}\u{1DA85}-\u{1DA8B}\u{1DF00}-\u{1DF1E}\u{1E100}-\u{1E12C}\u{1E137}-\u{1E13D}\u{1E140}-\u{1E149}\u{1E14E}\u{1E14F}\u{1E290}-\u{1E2AD}\u{1E2C0}-\u{1E2EB}\u{1E2F0}-\u{1E2F9}\u{1E7E0}-\u{1E7E6}\u{1E7E8}-\u{1E7EB}\u{1E7ED}\u{1E7EE}\u{1E7F0}-\u{1E7FE}\u{1F100}-\u{1F10A}\u{1F110}-\u{1F12E}\u{1F130}-\u{1F169}\u{1F170}-\u{1F1AC}\u{1F1E6}-\u{1F202}\u{1F210}-\u{1F23B}\u{1F240}-\u{1F248}\u{1F250}\u{1F251}\u{1FBF0}-\u{1FBF9}\u{20000}-\u{2A6DF}\u{2A700}-\u{2B738}\u{2B740}-\u{2B81D}\u{2B820}-\u{2CEA1}\u{2CEB0}-\u{2EBE0}\u{2F800}-\u{2FA1D}\u{30000}-\u{3134A}\u{F0000}-\u{FFFFD}\u{100000}-\u{10FFFD}][\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u0898-\u089F\u08CA-\u08E1\u08E3-\u0902\u093A\u093C\u0941-\u0948\u094D\u0951-\u0957\u0962\u0963\u0981\u09BC\u09C1-\u09C4\u09CD\u09E2\u09E3\u09FE\u0A01\u0A02\u0A3C\u0A41\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81\u0A82\u0ABC\u0AC1-\u0AC5\u0AC7\u0AC8\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01\u0B3C\u0B3F\u0B41-\u0B44\u0B4D\u0B55\u0B56\u0B62\u0B63\u0B82\u0BC0\u0BCD\u0C00\u0C04\u0C3C\u0C3E-\u0C40\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81\u0CBC\u0CCC\u0CCD\u0CE2\u0CE3\u0D00\u0D01\u0D3B\u0D3C\u0D41-\u0D44\u0D4D\u0D62\u0D63\u0D81\u0DCA\u0DD2-\u0DD4\u0DD6\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F71-\u0F7E\u0F80-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102D-\u1030\u1032-\u1037\u1039\u103A\u103D\u103E\u1058\u1059\u105E-\u1060\u1071-\u1074\u1082\u1085\u1086\u108D\u109D\u135D-\u135F\u1712-\u1714\u1732\u1733\u1752\u1753\u1772\u1773\u17B4\u17B5\u17B7-\u17BD\u17C6\u17C9-\u17D3\u17DD\u180B-\u180D\u180F\u1885\u1886\u18A9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193B\u1A17\u1A18\u1A1B\u1A56\u1A58-\u1A5E\u1A60\u1A62\u1A65-\u1A6C\u1A73-\u1A7C\u1A7F\u1AB0-\u1ACE\u1B00-\u1B03\u1B34\u1B36-\u1B3A\u1B3C\u1B42\u1B6B-\u1B73\u1B80\u1B81\u1BA2-\u1BA5\u1BA8\u1BA9\u1BAB-\u1BAD\u1BE6\u1BE8\u1BE9\u1BED\u1BEF-\u1BF1\u1C2C-\u1C33\u1C36\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE0\u1CE2-\u1CE8\u1CED\u1CF4\u1CF8\u1CF9\u1DC0-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302D\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA825\uA826\uA82C\uA8C4\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA951\uA980-\uA982\uA9B3\uA9B6-\uA9B9\uA9BC\uA9BD\uA9E5\uAA29-\uAA2E\uAA31\uAA32\uAA35\uAA36\uAA43\uAA4C\uAA7C\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEC\uAAED\uAAF6\uABE5\uABE8\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F\u{101FD}\u{102E0}\u{10376}-\u{1037A}\u{10A01}-\u{10A03}\u{10A05}\u{10A06}\u{10A0C}-\u{10A0F}\u{10A38}-\u{10A3A}\u{10A3F}\u{10AE5}\u{10AE6}\u{10D24}-\u{10D27}\u{10EAB}\u{10EAC}\u{10F46}-\u{10F50}\u{10F82}-\u{10F85}\u{11001}\u{11038}-\u{11046}\u{11070}\u{11073}\u{11074}\u{1107F}-\u{11081}\u{110B3}-\u{110B6}\u{110B9}\u{110BA}\u{110C2}\u{11100}-\u{11102}\u{11127}-\u{1112B}\u{1112D}-\u{11134}\u{11173}\u{11180}\u{11181}\u{111B6}-\u{111BE}\u{111C9}-\u{111CC}\u{111CF}\u{1122F}-\u{11231}\u{11234}\u{11236}\u{11237}\u{1123E}\u{112DF}\u{112E3}-\u{112EA}\u{11300}\u{11301}\u{1133B}\u{1133C}\u{11340}\u{11366}-\u{1136C}\u{11370}-\u{11374}\u{11438}-\u{1143F}\u{11442}-\u{11444}\u{11446}\u{1145E}\u{114B3}-\u{114B8}\u{114BA}\u{114BF}\u{114C0}\u{114C2}\u{114C3}\u{115B2}-\u{115B5}\u{115BC}\u{115BD}\u{115BF}\u{115C0}\u{115DC}\u{115DD}\u{11633}-\u{1163A}\u{1163D}\u{1163F}\u{11640}\u{116AB}\u{116AD}\u{116B0}-\u{116B5}\u{116B7}\u{1171D}-\u{1171F}\u{11722}-\u{11725}\u{11727}-\u{1172B}\u{1182F}-\u{11837}\u{11839}\u{1183A}\u{1193B}\u{1193C}\u{1193E}\u{11943}\u{119D4}-\u{119D7}\u{119DA}\u{119DB}\u{119E0}\u{11A01}-\u{11A06}\u{11A09}\u{11A0A}\u{11A33}-\u{11A38}\u{11A3B}-\u{11A3E}\u{11A47}\u{11A51}-\u{11A56}\u{11A59}-\u{11A5B}\u{11A8A}-\u{11A96}\u{11A98}\u{11A99}\u{11C30}-\u{11C36}\u{11C38}-\u{11C3D}\u{11C92}-\u{11CA7}\u{11CAA}-\u{11CB0}\u{11CB2}\u{11CB3}\u{11CB5}\u{11CB6}\u{11D31}-\u{11D36}\u{11D3A}\u{11D3C}\u{11D3D}\u{11D3F}-\u{11D45}\u{11D47}\u{11D90}\u{11D91}\u{11D95}\u{11D97}\u{11EF3}\u{11EF4}\u{16AF0}-\u{16AF4}\u{16B30}-\u{16B36}\u{16F4F}\u{16F8F}-\u{16F92}\u{16FE4}\u{1BC9D}\u{1BC9E}\u{1CF00}-\u{1CF2D}\u{1CF30}-\u{1CF46}\u{1D167}-\u{1D169}\u{1D17B}-\u{1D182}\u{1D185}-\u{1D18B}\u{1D1AA}-\u{1D1AD}\u{1D242}-\u{1D244}\u{1DA00}-\u{1DA36}\u{1DA3B}-\u{1DA6C}\u{1DA75}\u{1DA84}\u{1DA9B}-\u{1DA9F}\u{1DAA1}-\u{1DAAF}\u{1E000}-\u{1E006}\u{1E008}-\u{1E018}\u{1E01B}-\u{1E021}\u{1E023}\u{1E024}\u{1E026}-\u{1E02A}\u{1E130}-\u{1E136}\u{1E2AE}\u{1E2EC}-\u{1E2EF}\u{1E8D0}-\u{1E8D6}\u{1E944}-\u{1E94A}\u{E0100}-\u{E01EF}]*$/u;
  14612. module2.exports = {
  14613. combiningMarks,
  14614. combiningClassVirama,
  14615. validZWNJ,
  14616. bidiDomain,
  14617. bidiS1LTR,
  14618. bidiS1RTL,
  14619. bidiS2,
  14620. bidiS3,
  14621. bidiS4EN,
  14622. bidiS4AN,
  14623. bidiS5,
  14624. bidiS6
  14625. };
  14626. }
  14627. });
  14628. // node_modules/tr46/lib/mappingTable.json
  14629. var require_mappingTable = __commonJS({
  14630. "node_modules/tr46/lib/mappingTable.json"(exports2, module2) {
  14631. module2.exports = [[[0, 44], 4], [[45, 46], 2], [47, 4], [[48, 57], 2], [[58, 64], 4], [65, 1, "a"], [66, 1, "b"], [67, 1, "c"], [68, 1, "d"], [69, 1, "e"], [70, 1, "f"], [71, 1, "g"], [72, 1, "h"], [73, 1, "i"], [74, 1, "j"], [75, 1, "k"], [76, 1, "l"], [77, 1, "m"], [78, 1, "n"], [79, 1, "o"], [80, 1, "p"], [81, 1, "q"], [82, 1, "r"], [83, 1, "s"], [84, 1, "t"], [85, 1, "u"], [86, 1, "v"], [87, 1, "w"], [88, 1, "x"], [89, 1, "y"], [90, 1, "z"], [[91, 96], 4], [[97, 122], 2], [[123, 127], 4], [[128, 159], 3], [160, 5, " "], [[161, 167], 2], [168, 5, " \u0308"], [169, 2], [170, 1, "a"], [[171, 172], 2], [173, 7], [174, 2], [175, 5, " \u0304"], [[176, 177], 2], [178, 1, "2"], [179, 1, "3"], [180, 5, " \u0301"], [181, 1, "\u03BC"], [182, 2], [183, 2], [184, 5, " \u0327"], [185, 1, "1"], [186, 1, "o"], [187, 2], [188, 1, "1\u20444"], [189, 1, "1\u20442"], [190, 1, "3\u20444"], [191, 2], [192, 1, "\xE0"], [193, 1, "\xE1"], [194, 1, "\xE2"], [195, 1, "\xE3"], [196, 1, "\xE4"], [197, 1, "\xE5"], [198, 1, "\xE6"], [199, 1, "\xE7"], [200, 1, "\xE8"], [201, 1, "\xE9"], [202, 1, "\xEA"], [203, 1, "\xEB"], [204, 1, "\xEC"], [205, 1, "\xED"], [206, 1, "\xEE"], [207, 1, "\xEF"], [208, 1, "\xF0"], [209, 1, "\xF1"], [210, 1, "\xF2"], [211, 1, "\xF3"], [212, 1, "\xF4"], [213, 1, "\xF5"], [214, 1, "\xF6"], [215, 2], [216, 1, "\xF8"], [217, 1, "\xF9"], [218, 1, "\xFA"], [219, 1, "\xFB"], [220, 1, "\xFC"], [221, 1, "\xFD"], [222, 1, "\xFE"], [223, 6, "ss"], [[224, 246], 2], [247, 2], [[248, 255], 2], [256, 1, "\u0101"], [257, 2], [258, 1, "\u0103"], [259, 2], [260, 1, "\u0105"], [261, 2], [262, 1, "\u0107"], [263, 2], [264, 1, "\u0109"], [265, 2], [266, 1, "\u010B"], [267, 2], [268, 1, "\u010D"], [269, 2], [270, 1, "\u010F"], [271, 2], [272, 1, "\u0111"], [273, 2], [274, 1, "\u0113"], [275, 2], [276, 1, "\u0115"], [277, 2], [278, 1, "\u0117"], [279, 2], [280, 1, "\u0119"], [281, 2], [282, 1, "\u011B"], [283, 2], [284, 1, "\u011D"], [285, 2], [286, 1, "\u011F"], [287, 2], [288, 1, "\u0121"], [289, 2], [290, 1, "\u0123"], [291, 2], [292, 1, "\u0125"], [293, 2], [294, 1, "\u0127"], [295, 2], [296, 1, "\u0129"], [297, 2], [298, 1, "\u012B"], [299, 2], [300, 1, "\u012D"], [301, 2], [302, 1, "\u012F"], [303, 2], [304, 1, "i\u0307"], [305, 2], [[306, 307], 1, "ij"], [308, 1, "\u0135"], [309, 2], [310, 1, "\u0137"], [[311, 312], 2], [313, 1, "\u013A"], [314, 2], [315, 1, "\u013C"], [316, 2], [317, 1, "\u013E"], [318, 2], [[319, 320], 1, "l\xB7"], [321, 1, "\u0142"], [322, 2], [323, 1, "\u0144"], [324, 2], [325, 1, "\u0146"], [326, 2], [327, 1, "\u0148"], [328, 2], [329, 1, "\u02BCn"], [330, 1, "\u014B"], [331, 2], [332, 1, "\u014D"], [333, 2], [334, 1, "\u014F"], [335, 2], [336, 1, "\u0151"], [337, 2], [338, 1, "\u0153"], [339, 2], [340, 1, "\u0155"], [341, 2], [342, 1, "\u0157"], [343, 2], [344, 1, "\u0159"], [345, 2], [346, 1, "\u015B"], [347, 2], [348, 1, "\u015D"], [349, 2], [350, 1, "\u015F"], [351, 2], [352, 1, "\u0161"], [353, 2], [354, 1, "\u0163"], [355, 2], [356, 1, "\u0165"], [357, 2], [358, 1, "\u0167"], [359, 2], [360, 1, "\u0169"], [361, 2], [362, 1, "\u016B"], [363, 2], [364, 1, "\u016D"], [365, 2], [366, 1, "\u016F"], [367, 2], [368, 1, "\u0171"], [369, 2], [370, 1, "\u0173"], [371, 2], [372, 1, "\u0175"], [373, 2], [374, 1, "\u0177"], [375, 2], [376, 1, "\xFF"], [377, 1, "\u017A"], [378, 2], [379, 1, "\u017C"], [380, 2], [381, 1, "\u017E"], [382, 2], [383, 1, "s"], [384, 2], [385, 1, "\u0253"], [386, 1, "\u0183"], [387, 2], [388, 1, "\u0185"], [389, 2], [390, 1, "\u0254"], [391, 1, "\u0188"], [392, 2], [393, 1, "\u0256"], [394, 1, "\u0257"], [395, 1, "\u018C"], [[396, 397], 2], [398, 1, "\u01DD"], [399, 1, "\u0259"], [400, 1, "\u025B"], [401, 1, "\u0192"], [402, 2], [403, 1, "\u0260"], [404, 1, "\u0263"], [405, 2], [406, 1, "\u0269"], [407, 1, "\u0268"], [408, 1, "\u0199"], [[409, 411], 2], [412, 1, "\u026F"], [413, 1, "\u0272"], [414, 2], [415, 1, "\u0275"], [416, 1, "\u01A1"], [417, 2], [418, 1, "\u01A3"], [419, 2], [420, 1, "\u01A5"], [421, 2], [422, 1, "\u0280"], [423, 1, "\u01A8"], [424, 2], [425, 1, "\u0283"], [[426, 427], 2], [428, 1, "\u01AD"], [429, 2], [430, 1, "\u0288"], [431, 1, "\u01B0"], [432, 2], [433, 1, "\u028A"], [434, 1, "\u028B"], [435, 1, "\u01B4"], [436, 2], [437, 1, "\u01B6"], [438, 2], [439, 1, "\u0292"], [440, 1, "\u01B9"], [[441, 443], 2], [444, 1, "\u01BD"], [[445, 451], 2], [[452, 454], 1, "d\u017E"], [[455, 457], 1, "lj"], [[458, 460], 1, "nj"], [461, 1, "\u01CE"], [462, 2], [463, 1, "\u01D0"], [464, 2], [465, 1, "\u01D2"], [466, 2], [467, 1, "\u01D4"], [468, 2], [469, 1, "\u01D6"], [470, 2], [471, 1, "\u01D8"], [472, 2], [473, 1, "\u01DA"], [474, 2], [475, 1, "\u01DC"], [[476, 477], 2], [478, 1, "\u01DF"], [479, 2], [480, 1, "\u01E1"], [481, 2], [482, 1, "\u01E3"], [483, 2], [484, 1, "\u01E5"], [485, 2], [486, 1, "\u01E7"], [487, 2], [488, 1, "\u01E9"], [489, 2], [490, 1, "\u01EB"], [491, 2], [492, 1, "\u01ED"], [493, 2], [494, 1, "\u01EF"], [[495, 496], 2], [[497, 499], 1, "dz"], [500, 1, "\u01F5"], [501, 2], [502, 1, "\u0195"], [503, 1, "\u01BF"], [504, 1, "\u01F9"], [505, 2], [506, 1, "\u01FB"], [507, 2], [508, 1, "\u01FD"], [509, 2], [510, 1, "\u01FF"], [511, 2], [512, 1, "\u0201"], [513, 2], [514, 1, "\u0203"], [515, 2], [516, 1, "\u0205"], [517, 2], [518, 1, "\u0207"], [519, 2], [520, 1, "\u0209"], [521, 2], [522, 1, "\u020B"], [523, 2], [524, 1, "\u020D"], [525, 2], [526, 1, "\u020F"], [527, 2], [528, 1, "\u0211"], [529, 2], [530, 1, "\u0213"], [531, 2], [532, 1, "\u0215"], [533, 2], [534, 1, "\u0217"], [535, 2], [536, 1, "\u0219"], [537, 2], [538, 1, "\u021B"], [539, 2], [540, 1, "\u021D"], [541, 2], [542, 1, "\u021F"], [543, 2], [544, 1, "\u019E"], [545, 2], [546, 1, "\u0223"], [547, 2], [548, 1, "\u0225"], [549, 2], [550, 1, "\u0227"], [551, 2], [552, 1, "\u0229"], [553, 2], [554, 1, "\u022B"], [555, 2], [556, 1, "\u022D"], [557, 2], [558, 1, "\u022F"], [559, 2], [560, 1, "\u0231"], [561, 2], [562, 1, "\u0233"], [563, 2], [[564, 566], 2], [[567, 569], 2], [570, 1, "\u2C65"], [571, 1, "\u023C"], [572, 2], [573, 1, "\u019A"], [574, 1, "\u2C66"], [[575, 576], 2], [577, 1, "\u0242"], [578, 2], [579, 1, "\u0180"], [580, 1, "\u0289"], [581, 1, "\u028C"], [582, 1, "\u0247"], [583, 2], [584, 1, "\u0249"], [585, 2], [586, 1, "\u024B"], [587, 2], [588, 1, "\u024D"], [589, 2], [590, 1, "\u024F"], [591, 2], [[592, 680], 2], [[681, 685], 2], [[686, 687], 2], [688, 1, "h"], [689, 1, "\u0266"], [690, 1, "j"], [691, 1, "r"], [692, 1, "\u0279"], [693, 1, "\u027B"], [694, 1, "\u0281"], [695, 1, "w"], [696, 1, "y"], [[697, 705], 2], [[706, 709], 2], [[710, 721], 2], [[722, 727], 2], [728, 5, " \u0306"], [729, 5, " \u0307"], [730, 5, " \u030A"], [731, 5, " \u0328"], [732, 5, " \u0303"], [733, 5, " \u030B"], [734, 2], [735, 2], [736, 1, "\u0263"], [737, 1, "l"], [738, 1, "s"], [739, 1, "x"], [740, 1, "\u0295"], [[741, 745], 2], [[746, 747], 2], [748, 2], [749, 2], [750, 2], [[751, 767], 2], [[768, 831], 2], [832, 1, "\u0300"], [833, 1, "\u0301"], [834, 2], [835, 1, "\u0313"], [836, 1, "\u0308\u0301"], [837, 1, "\u03B9"], [[838, 846], 2], [847, 7], [[848, 855], 2], [[856, 860], 2], [[861, 863], 2], [[864, 865], 2], [866, 2], [[867, 879], 2], [880, 1, "\u0371"], [881, 2], [882, 1, "\u0373"], [883, 2], [884, 1, "\u02B9"], [885, 2], [886, 1, "\u0377"], [887, 2], [[888, 889], 3], [890, 5, " \u03B9"], [[891, 893], 2], [894, 5, ";"], [895, 1, "\u03F3"], [[896, 899], 3], [900, 5, " \u0301"], [901, 5, " \u0308\u0301"], [902, 1, "\u03AC"], [903, 1, "\xB7"], [904, 1, "\u03AD"], [905, 1, "\u03AE"], [906, 1, "\u03AF"], [907, 3], [908, 1, "\u03CC"], [909, 3], [910, 1, "\u03CD"], [911, 1, "\u03CE"], [912, 2], [913, 1, "\u03B1"], [914, 1, "\u03B2"], [915, 1, "\u03B3"], [916, 1, "\u03B4"], [917, 1, "\u03B5"], [918, 1, "\u03B6"], [919, 1, "\u03B7"], [920, 1, "\u03B8"], [921, 1, "\u03B9"], [922, 1, "\u03BA"], [923, 1, "\u03BB"], [924, 1, "\u03BC"], [925, 1, "\u03BD"], [926, 1, "\u03BE"], [927, 1, "\u03BF"], [928, 1, "\u03C0"], [929, 1, "\u03C1"], [930, 3], [931, 1, "\u03C3"], [932, 1, "\u03C4"], [933, 1, "\u03C5"], [934, 1, "\u03C6"], [935, 1, "\u03C7"], [936, 1, "\u03C8"], [937, 1, "\u03C9"], [938, 1, "\u03CA"], [939, 1, "\u03CB"], [[940, 961], 2], [962, 6, "\u03C3"], [[963, 974], 2], [975, 1, "\u03D7"], [976, 1, "\u03B2"], [977, 1, "\u03B8"], [978, 1, "\u03C5"], [979, 1, "\u03CD"], [980, 1, "\u03CB"], [981, 1, "\u03C6"], [982, 1, "\u03C0"], [983, 2], [984, 1, "\u03D9"], [985, 2], [986, 1, "\u03DB"], [987, 2], [988, 1, "\u03DD"], [989, 2], [990, 1, "\u03DF"], [991, 2], [992, 1, "\u03E1"], [993, 2], [994, 1, "\u03E3"], [995, 2], [996, 1, "\u03E5"], [997, 2], [998, 1, "\u03E7"], [999, 2], [1e3, 1, "\u03E9"], [1001, 2], [1002, 1, "\u03EB"], [1003, 2], [1004, 1, "\u03ED"], [1005, 2], [1006, 1, "\u03EF"], [1007, 2], [1008, 1, "\u03BA"], [1009, 1, "\u03C1"], [1010, 1, "\u03C3"], [1011, 2], [1012, 1, "\u03B8"], [1013, 1, "\u03B5"], [1014, 2], [1015, 1, "\u03F8"], [1016, 2], [1017, 1, "\u03C3"], [1018, 1, "\u03FB"], [1019, 2], [1020, 2], [1021, 1, "\u037B"], [1022, 1, "\u037C"], [1023, 1, "\u037D"], [1024, 1, "\u0450"], [1025, 1, "\u0451"], [1026, 1, "\u0452"], [1027, 1, "\u0453"], [1028, 1, "\u0454"], [1029, 1, "\u0455"], [1030, 1, "\u0456"], [1031, 1, "\u0457"], [1032, 1, "\u0458"], [1033, 1, "\u0459"], [1034, 1, "\u045A"], [1035, 1, "\u045B"], [1036, 1, "\u045C"], [1037, 1, "\u045D"], [1038, 1, "\u045E"], [1039, 1, "\u045F"], [1040, 1, "\u0430"], [1041, 1, "\u0431"], [1042, 1, "\u0432"], [1043, 1, "\u0433"], [1044, 1, "\u0434"], [1045, 1, "\u0435"], [1046, 1, "\u0436"], [1047, 1, "\u0437"], [1048, 1, "\u0438"], [1049, 1, "\u0439"], [1050, 1, "\u043A"], [1051, 1, "\u043B"], [1052, 1, "\u043C"], [1053, 1, "\u043D"], [1054, 1, "\u043E"], [1055, 1, "\u043F"], [1056, 1, "\u0440"], [1057, 1, "\u0441"], [1058, 1, "\u0442"], [1059, 1, "\u0443"], [1060, 1, "\u0444"], [1061, 1, "\u0445"], [1062, 1, "\u0446"], [1063, 1, "\u0447"], [1064, 1, "\u0448"], [1065, 1, "\u0449"], [1066, 1, "\u044A"], [1067, 1, "\u044B"], [1068, 1, "\u044C"], [1069, 1, "\u044D"], [1070, 1, "\u044E"], [1071, 1, "\u044F"], [[1072, 1103], 2], [1104, 2], [[1105, 1116], 2], [1117, 2], [[1118, 1119], 2], [1120, 1, "\u0461"], [1121, 2], [1122, 1, "\u0463"], [1123, 2], [1124, 1, "\u0465"], [1125, 2], [1126, 1, "\u0467"], [1127, 2], [1128, 1, "\u0469"], [1129, 2], [1130, 1, "\u046B"], [1131, 2], [1132, 1, "\u046D"], [1133, 2], [1134, 1, "\u046F"], [1135, 2], [1136, 1, "\u0471"], [1137, 2], [1138, 1, "\u0473"], [1139, 2], [1140, 1, "\u0475"], [1141, 2], [1142, 1, "\u0477"], [1143, 2], [1144, 1, "\u0479"], [1145, 2], [1146, 1, "\u047B"], [1147, 2], [1148, 1, "\u047D"], [1149, 2], [1150, 1, "\u047F"], [1151, 2], [1152, 1, "\u0481"], [1153, 2], [1154, 2], [[1155, 1158], 2], [1159, 2], [[1160, 1161], 2], [1162, 1, "\u048B"], [1163, 2], [1164, 1, "\u048D"], [1165, 2], [1166, 1, "\u048F"], [1167, 2], [1168, 1, "\u0491"], [1169, 2], [1170, 1, "\u0493"], [1171, 2], [1172, 1, "\u0495"], [1173, 2], [1174, 1, "\u0497"], [1175, 2], [1176, 1, "\u0499"], [1177, 2], [1178, 1, "\u049B"], [1179, 2], [1180, 1, "\u049D"], [1181, 2], [1182, 1, "\u049F"], [1183, 2], [1184, 1, "\u04A1"], [1185, 2], [1186, 1, "\u04A3"], [1187, 2], [1188, 1, "\u04A5"], [1189, 2], [1190, 1, "\u04A7"], [1191, 2], [1192, 1, "\u04A9"], [1193, 2], [1194, 1, "\u04AB"], [1195, 2], [1196, 1, "\u04AD"], [1197, 2], [1198, 1, "\u04AF"], [1199, 2], [1200, 1, "\u04B1"], [1201, 2], [1202, 1, "\u04B3"], [1203, 2], [1204, 1, "\u04B5"], [1205, 2], [1206, 1, "\u04B7"], [1207, 2], [1208, 1, "\u04B9"], [1209, 2], [1210, 1, "\u04BB"], [1211, 2], [1212, 1, "\u04BD"], [1213, 2], [1214, 1, "\u04BF"], [1215, 2], [1216, 3], [1217, 1, "\u04C2"], [1218, 2], [1219, 1, "\u04C4"], [1220, 2], [1221, 1, "\u04C6"], [1222, 2], [1223, 1, "\u04C8"], [1224, 2], [1225, 1, "\u04CA"], [1226, 2], [1227, 1, "\u04CC"], [1228, 2], [1229, 1, "\u04CE"], [1230, 2], [1231, 2], [1232, 1, "\u04D1"], [1233, 2], [1234, 1, "\u04D3"], [1235, 2], [1236, 1, "\u04D5"], [1237, 2], [1238, 1, "\u04D7"], [1239, 2], [1240, 1, "\u04D9"], [1241, 2], [1242, 1, "\u04DB"], [1243, 2], [1244, 1, "\u04DD"], [1245, 2], [1246, 1, "\u04DF"], [1247, 2], [1248, 1, "\u04E1"], [1249, 2], [1250, 1, "\u04E3"], [1251, 2], [1252, 1, "\u04E5"], [1253, 2], [1254, 1, "\u04E7"], [1255, 2], [1256, 1, "\u04E9"], [1257, 2], [1258, 1, "\u04EB"], [1259, 2], [1260, 1, "\u04ED"], [1261, 2], [1262, 1, "\u04EF"], [1263, 2], [1264, 1, "\u04F1"], [1265, 2], [1266, 1, "\u04F3"], [1267, 2], [1268, 1, "\u04F5"], [1269, 2], [1270, 1, "\u04F7"], [1271, 2], [1272, 1, "\u04F9"], [1273, 2], [1274, 1, "\u04FB"], [1275, 2], [1276, 1, "\u04FD"], [1277, 2], [1278, 1, "\u04FF"], [1279, 2], [1280, 1, "\u0501"], [1281, 2], [1282, 1, "\u0503"], [1283, 2], [1284, 1, "\u0505"], [1285, 2], [1286, 1, "\u0507"], [1287, 2], [1288, 1, "\u0509"], [1289, 2], [1290, 1, "\u050B"], [1291, 2], [1292, 1, "\u050D"], [1293, 2], [1294, 1, "\u050F"], [1295, 2], [1296, 1, "\u0511"], [1297, 2], [1298, 1, "\u0513"], [1299, 2], [1300, 1, "\u0515"], [1301, 2], [1302, 1, "\u0517"], [1303, 2], [1304, 1, "\u0519"], [1305, 2], [1306, 1, "\u051B"], [1307, 2], [1308, 1, "\u051D"], [1309, 2], [1310, 1, "\u051F"], [1311, 2], [1312, 1, "\u0521"], [1313, 2], [1314, 1, "\u0523"], [1315, 2], [1316, 1, "\u0525"], [1317, 2], [1318, 1, "\u0527"], [1319, 2], [1320, 1, "\u0529"], [1321, 2], [1322, 1, "\u052B"], [1323, 2], [1324, 1, "\u052D"], [1325, 2], [1326, 1, "\u052F"], [1327, 2], [1328, 3], [1329, 1, "\u0561"], [1330, 1, "\u0562"], [1331, 1, "\u0563"], [1332, 1, "\u0564"], [1333, 1, "\u0565"], [1334, 1, "\u0566"], [1335, 1, "\u0567"], [1336, 1, "\u0568"], [1337, 1, "\u0569"], [1338, 1, "\u056A"], [1339, 1, "\u056B"], [1340, 1, "\u056C"], [1341, 1, "\u056D"], [1342, 1, "\u056E"], [1343, 1, "\u056F"], [1344, 1, "\u0570"], [1345, 1, "\u0571"], [1346, 1, "\u0572"], [1347, 1, "\u0573"], [1348, 1, "\u0574"], [1349, 1, "\u0575"], [1350, 1, "\u0576"], [1351, 1, "\u0577"], [1352, 1, "\u0578"], [1353, 1, "\u0579"], [1354, 1, "\u057A"], [1355, 1, "\u057B"], [1356, 1, "\u057C"], [1357, 1, "\u057D"], [1358, 1, "\u057E"], [1359, 1, "\u057F"], [1360, 1, "\u0580"], [1361, 1, "\u0581"], [1362, 1, "\u0582"], [1363, 1, "\u0583"], [1364, 1, "\u0584"], [1365, 1, "\u0585"], [1366, 1, "\u0586"], [[1367, 1368], 3], [1369, 2], [[1370, 1375], 2], [1376, 2], [[1377, 1414], 2], [1415, 1, "\u0565\u0582"], [1416, 2], [1417, 2], [1418, 2], [[1419, 1420], 3], [[1421, 1422], 2], [1423, 2], [1424, 3], [[1425, 1441], 2], [1442, 2], [[1443, 1455], 2], [[1456, 1465], 2], [1466, 2], [[1467, 1469], 2], [1470, 2], [1471, 2], [1472, 2], [[1473, 1474], 2], [1475, 2], [1476, 2], [1477, 2], [1478, 2], [1479, 2], [[1480, 1487], 3], [[1488, 1514], 2], [[1515, 1518], 3], [1519, 2], [[1520, 1524], 2], [[1525, 1535], 3], [[1536, 1539], 3], [1540, 3], [1541, 3], [[1542, 1546], 2], [1547, 2], [1548, 2], [[1549, 1551], 2], [[1552, 1557], 2], [[1558, 1562], 2], [1563, 2], [1564, 3], [1565, 2], [1566, 2], [1567, 2], [1568, 2], [[1569, 1594], 2], [[1595, 1599], 2], [1600, 2], [[1601, 1618], 2], [[1619, 1621], 2], [[1622, 1624], 2], [[1625, 1630], 2], [1631, 2], [[1632, 1641], 2], [[1642, 1645], 2], [[1646, 1647], 2], [[1648, 1652], 2], [1653, 1, "\u0627\u0674"], [1654, 1, "\u0648\u0674"], [1655, 1, "\u06C7\u0674"], [1656, 1, "\u064A\u0674"], [[1657, 1719], 2], [[1720, 1721], 2], [[1722, 1726], 2], [1727, 2], [[1728, 1742], 2], [1743, 2], [[1744, 1747], 2], [1748, 2], [[1749, 1756], 2], [1757, 3], [1758, 2], [[1759, 1768], 2], [1769, 2], [[1770, 1773], 2], [[1774, 1775], 2], [[1776, 1785], 2], [[1786, 1790], 2], [1791, 2], [[1792, 1805], 2], [1806, 3], [1807, 3], [[1808, 1836], 2], [[1837, 1839], 2], [[1840, 1866], 2], [[1867, 1868], 3], [[1869, 1871], 2], [[1872, 1901], 2], [[1902, 1919], 2], [[1920, 1968], 2], [1969, 2], [[1970, 1983], 3], [[1984, 2037], 2], [[2038, 2042], 2], [[2043, 2044], 3], [2045, 2], [[2046, 2047], 2], [[2048, 2093], 2], [[2094, 2095], 3], [[2096, 2110], 2], [2111, 3], [[2112, 2139], 2], [[2140, 2141], 3], [2142, 2], [2143, 3], [[2144, 2154], 2], [[2155, 2159], 3], [[2160, 2183], 2], [2184, 2], [[2185, 2190], 2], [2191, 3], [[2192, 2193], 3], [[2194, 2199], 3], [[2200, 2207], 2], [2208, 2], [2209, 2], [[2210, 2220], 2], [[2221, 2226], 2], [[2227, 2228], 2], [2229, 2], [[2230, 2237], 2], [[2238, 2247], 2], [[2248, 2258], 2], [2259, 2], [[2260, 2273], 2], [2274, 3], [2275, 2], [[2276, 2302], 2], [2303, 2], [2304, 2], [[2305, 2307], 2], [2308, 2], [[2309, 2361], 2], [[2362, 2363], 2], [[2364, 2381], 2], [2382, 2], [2383, 2], [[2384, 2388], 2], [2389, 2], [[2390, 2391], 2], [2392, 1, "\u0915\u093C"], [2393, 1, "\u0916\u093C"], [2394, 1, "\u0917\u093C"], [2395, 1, "\u091C\u093C"], [2396, 1, "\u0921\u093C"], [2397, 1, "\u0922\u093C"], [2398, 1, "\u092B\u093C"], [2399, 1, "\u092F\u093C"], [[2400, 2403], 2], [[2404, 2405], 2], [[2406, 2415], 2], [2416, 2], [[2417, 2418], 2], [[2419, 2423], 2], [2424, 2], [[2425, 2426], 2], [[2427, 2428], 2], [2429, 2], [[2430, 2431], 2], [2432, 2], [[2433, 2435], 2], [2436, 3], [[2437, 2444], 2], [[2445, 2446], 3], [[2447, 2448], 2], [[2449, 2450], 3], [[2451, 2472], 2], [2473, 3], [[2474, 2480], 2], [2481, 3], [2482, 2], [[2483, 2485], 3], [[2486, 2489], 2], [[2490, 2491], 3], [2492, 2], [2493, 2], [[2494, 2500], 2], [[2501, 2502], 3], [[2503, 2504], 2], [[2505, 2506], 3], [[2507, 2509], 2], [2510, 2], [[2511, 2518], 3], [2519, 2], [[2520, 2523], 3], [2524, 1, "\u09A1\u09BC"], [2525, 1, "\u09A2\u09BC"], [2526, 3], [2527, 1, "\u09AF\u09BC"], [[2528, 2531], 2], [[2532, 2533], 3], [[2534, 2545], 2], [[2546, 2554], 2], [2555, 2], [2556, 2], [2557, 2], [2558, 2], [[2559, 2560], 3], [2561, 2], [2562, 2], [2563, 2], [2564, 3], [[2565, 2570], 2], [[2571, 2574], 3], [[2575, 2576], 2], [[2577, 2578], 3], [[2579, 2600], 2], [2601, 3], [[2602, 2608], 2], [2609, 3], [2610, 2], [2611, 1, "\u0A32\u0A3C"], [2612, 3], [2613, 2], [2614, 1, "\u0A38\u0A3C"], [2615, 3], [[2616, 2617], 2], [[2618, 2619], 3], [2620, 2], [2621, 3], [[2622, 2626], 2], [[2627, 2630], 3], [[2631, 2632], 2], [[2633, 2634], 3], [[2635, 2637], 2], [[2638, 2640], 3], [2641, 2], [[2642, 2648], 3], [2649, 1, "\u0A16\u0A3C"], [2650, 1, "\u0A17\u0A3C"], [2651, 1, "\u0A1C\u0A3C"], [2652, 2], [2653, 3], [2654, 1, "\u0A2B\u0A3C"], [[2655, 2661], 3], [[2662, 2676], 2], [2677, 2], [2678, 2], [[2679, 2688], 3], [[2689, 2691], 2], [2692, 3], [[2693, 2699], 2], [2700, 2], [2701, 2], [2702, 3], [[2703, 2705], 2], [2706, 3], [[2707, 2728], 2], [2729, 3], [[2730, 2736], 2], [2737, 3], [[2738, 2739], 2], [2740, 3], [[2741, 2745], 2], [[2746, 2747], 3], [[2748, 2757], 2], [2758, 3], [[2759, 2761], 2], [2762, 3], [[2763, 2765], 2], [[2766, 2767], 3], [2768, 2], [[2769, 2783], 3], [2784, 2], [[2785, 2787], 2], [[2788, 2789], 3], [[2790, 2799], 2], [2800, 2], [2801, 2], [[2802, 2808], 3], [2809, 2], [[2810, 2815], 2], [2816, 3], [[2817, 2819], 2], [2820, 3], [[2821, 2828], 2], [[2829, 2830], 3], [[2831, 2832], 2], [[2833, 2834], 3], [[2835, 2856], 2], [2857, 3], [[2858, 2864], 2], [2865, 3], [[2866, 2867], 2], [2868, 3], [2869, 2], [[2870, 2873], 2], [[2874, 2875], 3], [[2876, 2883], 2], [2884, 2], [[2885, 2886], 3], [[2887, 2888], 2], [[2889, 2890], 3], [[2891, 2893], 2], [[2894, 2900], 3], [2901, 2], [[2902, 2903], 2], [[2904, 2907], 3], [2908, 1, "\u0B21\u0B3C"], [2909, 1, "\u0B22\u0B3C"], [2910, 3], [[2911, 2913], 2], [[2914, 2915], 2], [[2916, 2917], 3], [[2918, 2927], 2], [2928, 2], [2929, 2], [[2930, 2935], 2], [[2936, 2945], 3], [[2946, 2947], 2], [2948, 3], [[2949, 2954], 2], [[2955, 2957], 3], [[2958, 2960], 2], [2961, 3], [[2962, 2965], 2], [[2966, 2968], 3], [[2969, 2970], 2], [2971, 3], [2972, 2], [2973, 3], [[2974, 2975], 2], [[2976, 2978], 3], [[2979, 2980], 2], [[2981, 2983], 3], [[2984, 2986], 2], [[2987, 2989], 3], [[2990, 2997], 2], [2998, 2], [[2999, 3001], 2], [[3002, 3005], 3], [[3006, 3010], 2], [[3011, 3013], 3], [[3014, 3016], 2], [3017, 3], [[3018, 3021], 2], [[3022, 3023], 3], [3024, 2], [[3025, 3030], 3], [3031, 2], [[3032, 3045], 3], [3046, 2], [[3047, 3055], 2], [[3056, 3058], 2], [[3059, 3066], 2], [[3067, 3071], 3], [3072, 2], [[3073, 3075], 2], [3076, 2], [[3077, 3084], 2], [3085, 3], [[3086, 3088], 2], [3089, 3], [[3090, 3112], 2], [3113, 3], [[3114, 3123], 2], [3124, 2], [[3125, 3129], 2], [[3130, 3131], 3], [3132, 2], [3133, 2], [[3134, 3140], 2], [3141, 3], [[3142, 3144], 2], [3145, 3], [[3146, 3149], 2], [[3150, 3156], 3], [[3157, 3158], 2], [3159, 3], [[3160, 3161], 2], [3162, 2], [[3163, 3164], 3], [3165, 2], [[3166, 3167], 3], [[3168, 3169], 2], [[3170, 3171], 2], [[3172, 3173], 3], [[3174, 3183], 2], [[3184, 3190], 3], [3191, 2], [[3192, 3199], 2], [3200, 2], [3201, 2], [[3202, 3203], 2], [3204, 2], [[3205, 3212], 2], [3213, 3], [[3214, 3216], 2], [3217, 3], [[3218, 3240], 2], [3241, 3], [[3242, 3251], 2], [3252, 3], [[3253, 3257], 2], [[3258, 3259], 3], [[3260, 3261], 2], [[3262, 3268], 2], [3269, 3], [[3270, 3272], 2], [3273, 3], [[3274, 3277], 2], [[3278, 3284], 3], [[3285, 3286], 2], [[3287, 3292], 3], [3293, 2], [3294, 2], [3295, 3], [[3296, 3297], 2], [[3298, 3299], 2], [[3300, 3301], 3], [[3302, 3311], 2], [3312, 3], [[3313, 3314], 2], [[3315, 3327], 3], [3328, 2], [3329, 2], [[3330, 3331], 2], [3332, 2], [[3333, 3340], 2], [3341, 3], [[3342, 3344], 2], [3345, 3], [[3346, 3368], 2], [3369, 2], [[3370, 3385], 2], [3386, 2], [[3387, 3388], 2], [3389, 2], [[3390, 3395], 2], [3396, 2], [3397, 3], [[3398, 3400], 2], [3401, 3], [[3402, 3405], 2], [3406, 2], [3407, 2], [[3408, 3411], 3], [[3412, 3414], 2], [3415, 2], [[3416, 3422], 2], [3423, 2], [[3424, 3425], 2], [[3426, 3427], 2], [[3428, 3429], 3], [[3430, 3439], 2], [[3440, 3445], 2], [[3446, 3448], 2], [3449, 2], [[3450, 3455], 2], [3456, 3], [3457, 2], [[3458, 3459], 2], [3460, 3], [[3461, 3478], 2], [[3479, 3481], 3], [[3482, 3505], 2], [3506, 3], [[3507, 3515], 2], [3516, 3], [3517, 2], [[3518, 3519], 3], [[3520, 3526], 2], [[3527, 3529], 3], [3530, 2], [[3531, 3534], 3], [[3535, 3540], 2], [3541, 3], [3542, 2], [3543, 3], [[3544, 3551], 2], [[3552, 3557], 3], [[3558, 3567], 2], [[3568, 3569], 3], [[3570, 3571], 2], [3572, 2], [[3573, 3584], 3], [[3585, 3634], 2], [3635, 1, "\u0E4D\u0E32"], [[3636, 3642], 2], [[3643, 3646], 3], [3647, 2], [[3648, 3662], 2], [3663, 2], [[3664, 3673], 2], [[3674, 3675], 2], [[3676, 3712], 3], [[3713, 3714], 2], [3715, 3], [3716, 2], [3717, 3], [3718, 2], [[3719, 3720], 2], [3721, 2], [3722, 2], [3723, 3], [3724, 2], [3725, 2], [[3726, 3731], 2], [[3732, 3735], 2], [3736, 2], [[3737, 3743], 2], [3744, 2], [[3745, 3747], 2], [3748, 3], [3749, 2], [3750, 3], [3751, 2], [[3752, 3753], 2], [[3754, 3755], 2], [3756, 2], [[3757, 3762], 2], [3763, 1, "\u0ECD\u0EB2"], [[3764, 3769], 2], [3770, 2], [[3771, 3773], 2], [[3774, 3775], 3], [[3776, 3780], 2], [3781, 3], [3782, 2], [3783, 3], [[3784, 3789], 2], [[3790, 3791], 3], [[3792, 3801], 2], [[3802, 3803], 3], [3804, 1, "\u0EAB\u0E99"], [3805, 1, "\u0EAB\u0EA1"], [[3806, 3807], 2], [[3808, 3839], 3], [3840, 2], [[3841, 3850], 2], [3851, 2], [3852, 1, "\u0F0B"], [[3853, 3863], 2], [[3864, 3865], 2], [[3866, 3871], 2], [[3872, 3881], 2], [[3882, 3892], 2], [3893, 2], [3894, 2], [3895, 2], [3896, 2], [3897, 2], [[3898, 3901], 2], [[3902, 3906], 2], [3907, 1, "\u0F42\u0FB7"], [[3908, 3911], 2], [3912, 3], [[3913, 3916], 2], [3917, 1, "\u0F4C\u0FB7"], [[3918, 3921], 2], [3922, 1, "\u0F51\u0FB7"], [[3923, 3926], 2], [3927, 1, "\u0F56\u0FB7"], [[3928, 3931], 2], [3932, 1, "\u0F5B\u0FB7"], [[3933, 3944], 2], [3945, 1, "\u0F40\u0FB5"], [3946, 2], [[3947, 3948], 2], [[3949, 3952], 3], [[3953, 3954], 2], [3955, 1, "\u0F71\u0F72"], [3956, 2], [3957, 1, "\u0F71\u0F74"], [3958, 1, "\u0FB2\u0F80"], [3959, 1, "\u0FB2\u0F71\u0F80"], [3960, 1, "\u0FB3\u0F80"], [3961, 1, "\u0FB3\u0F71\u0F80"], [[3962, 3968], 2], [3969, 1, "\u0F71\u0F80"], [[3970, 3972], 2], [3973, 2], [[3974, 3979], 2], [[3980, 3983], 2], [[3984, 3986], 2], [3987, 1, "\u0F92\u0FB7"], [[3988, 3989], 2], [3990, 2], [3991, 2], [3992, 3], [[3993, 3996], 2], [3997, 1, "\u0F9C\u0FB7"], [[3998, 4001], 2], [4002, 1, "\u0FA1\u0FB7"], [[4003, 4006], 2], [4007, 1, "\u0FA6\u0FB7"], [[4008, 4011], 2], [4012, 1, "\u0FAB\u0FB7"], [4013, 2], [[4014, 4016], 2], [[4017, 4023], 2], [4024, 2], [4025, 1, "\u0F90\u0FB5"], [[4026, 4028], 2], [4029, 3], [[4030, 4037], 2], [4038, 2], [[4039, 4044], 2], [4045, 3], [4046, 2], [4047, 2], [[4048, 4049], 2], [[4050, 4052], 2], [[4053, 4056], 2], [[4057, 4058], 2], [[4059, 4095], 3], [[4096, 4129], 2], [4130, 2], [[4131, 4135], 2], [4136, 2], [[4137, 4138], 2], [4139, 2], [[4140, 4146], 2], [[4147, 4149], 2], [[4150, 4153], 2], [[4154, 4159], 2], [[4160, 4169], 2], [[4170, 4175], 2], [[4176, 4185], 2], [[4186, 4249], 2], [[4250, 4253], 2], [[4254, 4255], 2], [[4256, 4293], 3], [4294, 3], [4295, 1, "\u2D27"], [[4296, 4300], 3], [4301, 1, "\u2D2D"], [[4302, 4303], 3], [[4304, 4342], 2], [[4343, 4344], 2], [[4345, 4346], 2], [4347, 2], [4348, 1, "\u10DC"], [[4349, 4351], 2], [[4352, 4441], 2], [[4442, 4446], 2], [[4447, 4448], 3], [[4449, 4514], 2], [[4515, 4519], 2], [[4520, 4601], 2], [[4602, 4607], 2], [[4608, 4614], 2], [4615, 2], [[4616, 4678], 2], [4679, 2], [4680, 2], [4681, 3], [[4682, 4685], 2], [[4686, 4687], 3], [[4688, 4694], 2], [4695, 3], [4696, 2], [4697, 3], [[4698, 4701], 2], [[4702, 4703], 3], [[4704, 4742], 2], [4743, 2], [4744, 2], [4745, 3], [[4746, 4749], 2], [[4750, 4751], 3], [[4752, 4782], 2], [4783, 2], [4784, 2], [4785, 3], [[4786, 4789], 2], [[4790, 4791], 3], [[4792, 4798], 2], [4799, 3], [4800, 2], [4801, 3], [[4802, 4805], 2], [[4806, 4807], 3], [[4808, 4814], 2], [4815, 2], [[4816, 4822], 2], [4823, 3], [[4824, 4846], 2], [4847, 2], [[4848, 4878], 2], [4879, 2], [4880, 2], [4881, 3], [[4882, 4885], 2], [[4886, 4887], 3], [[4888, 4894], 2], [4895, 2], [[4896, 4934], 2], [4935, 2], [[4936, 4954], 2], [[4955, 4956], 3], [[4957, 4958], 2], [4959, 2], [4960, 2], [[4961, 4988], 2], [[4989, 4991], 3], [[4992, 5007], 2], [[5008, 5017], 2], [[5018, 5023], 3], [[5024, 5108], 2], [5109, 2], [[5110, 5111], 3], [5112, 1, "\u13F0"], [5113, 1, "\u13F1"], [5114, 1, "\u13F2"], [5115, 1, "\u13F3"], [5116, 1, "\u13F4"], [5117, 1, "\u13F5"], [[5118, 5119], 3], [5120, 2], [[5121, 5740], 2], [[5741, 5742], 2], [[5743, 5750], 2], [[5751, 5759], 2], [5760, 3], [[5761, 5786], 2], [[5787, 5788], 2], [[5789, 5791], 3], [[5792, 5866], 2], [[5867, 5872], 2], [[5873, 5880], 2], [[5881, 5887], 3], [[5888, 5900], 2], [5901, 2], [[5902, 5908], 2], [5909, 2], [[5910, 5918], 3], [5919, 2], [[5920, 5940], 2], [[5941, 5942], 2], [[5943, 5951], 3], [[5952, 5971], 2], [[5972, 5983], 3], [[5984, 5996], 2], [5997, 3], [[5998, 6e3], 2], [6001, 3], [[6002, 6003], 2], [[6004, 6015], 3], [[6016, 6067], 2], [[6068, 6069], 3], [[6070, 6099], 2], [[6100, 6102], 2], [6103, 2], [[6104, 6107], 2], [6108, 2], [6109, 2], [[6110, 6111], 3], [[6112, 6121], 2], [[6122, 6127], 3], [[6128, 6137], 2], [[6138, 6143], 3], [[6144, 6149], 2], [6150, 3], [[6151, 6154], 2], [[6155, 6157], 7], [6158, 3], [6159, 7], [[6160, 6169], 2], [[6170, 6175], 3], [[6176, 6263], 2], [6264, 2], [[6265, 6271], 3], [[6272, 6313], 2], [6314, 2], [[6315, 6319], 3], [[6320, 6389], 2], [[6390, 6399], 3], [[6400, 6428], 2], [[6429, 6430], 2], [6431, 3], [[6432, 6443], 2], [[6444, 6447], 3], [[6448, 6459], 2], [[6460, 6463], 3], [6464, 2], [[6465, 6467], 3], [[6468, 6469], 2], [[6470, 6509], 2], [[6510, 6511], 3], [[6512, 6516], 2], [[6517, 6527], 3], [[6528, 6569], 2], [[6570, 6571], 2], [[6572, 6575], 3], [[6576, 6601], 2], [[6602, 6607], 3], [[6608, 6617], 2], [6618, 2], [[6619, 6621], 3], [[6622, 6623], 2], [[6624, 6655], 2], [[6656, 6683], 2], [[6684, 6685], 3], [[6686, 6687], 2], [[6688, 6750], 2], [6751, 3], [[6752, 6780], 2], [[6781, 6782], 3], [[6783, 6793], 2], [[6794, 6799], 3], [[6800, 6809], 2], [[6810, 6815], 3], [[6816, 6822], 2], [6823, 2], [[6824, 6829], 2], [[6830, 6831], 3], [[6832, 6845], 2], [6846, 2], [[6847, 6848], 2], [[6849, 6862], 2], [[6863, 6911], 3], [[6912, 6987], 2], [6988, 2], [[6989, 6991], 3], [[6992, 7001], 2], [[7002, 7018], 2], [[7019, 7027], 2], [[7028, 7036], 2], [[7037, 7038], 2], [7039, 3], [[7040, 7082], 2], [[7083, 7085], 2], [[7086, 7097], 2], [[7098, 7103], 2], [[7104, 7155], 2], [[7156, 7163], 3], [[7164, 7167], 2], [[7168, 7223], 2], [[7224, 7226], 3], [[7227, 7231], 2], [[7232, 7241], 2], [[7242, 7244], 3], [[7245, 7293], 2], [[7294, 7295], 2], [7296, 1, "\u0432"], [7297, 1, "\u0434"], [7298, 1, "\u043E"], [7299, 1, "\u0441"], [[7300, 7301], 1, "\u0442"], [7302, 1, "\u044A"], [7303, 1, "\u0463"], [7304, 1, "\uA64B"], [[7305, 7311], 3], [7312, 1, "\u10D0"], [7313, 1, "\u10D1"], [7314, 1, "\u10D2"], [7315, 1, "\u10D3"], [7316, 1, "\u10D4"], [7317, 1, "\u10D5"], [7318, 1, "\u10D6"], [7319, 1, "\u10D7"], [7320, 1, "\u10D8"], [7321, 1, "\u10D9"], [7322, 1, "\u10DA"], [7323, 1, "\u10DB"], [7324, 1, "\u10DC"], [7325, 1, "\u10DD"], [7326, 1, "\u10DE"], [7327, 1, "\u10DF"], [7328, 1, "\u10E0"], [7329, 1, "\u10E1"], [7330, 1, "\u10E2"], [7331, 1, "\u10E3"], [7332, 1, "\u10E4"], [7333, 1, "\u10E5"], [7334, 1, "\u10E6"], [7335, 1, "\u10E7"], [7336, 1, "\u10E8"], [7337, 1, "\u10E9"], [7338, 1, "\u10EA"], [7339, 1, "\u10EB"], [7340, 1, "\u10EC"], [7341, 1, "\u10ED"], [7342, 1, "\u10EE"], [7343, 1, "\u10EF"], [7344, 1, "\u10F0"], [7345, 1, "\u10F1"], [7346, 1, "\u10F2"], [7347, 1, "\u10F3"], [7348, 1, "\u10F4"], [7349, 1, "\u10F5"], [7350, 1, "\u10F6"], [7351, 1, "\u10F7"], [7352, 1, "\u10F8"], [7353, 1, "\u10F9"], [7354, 1, "\u10FA"], [[7355, 7356], 3], [7357, 1, "\u10FD"], [7358, 1, "\u10FE"], [7359, 1, "\u10FF"], [[7360, 7367], 2], [[7368, 7375], 3], [[7376, 7378], 2], [7379, 2], [[7380, 7410], 2], [[7411, 7414], 2], [7415, 2], [[7416, 7417], 2], [7418, 2], [[7419, 7423], 3], [[7424, 7467], 2], [7468, 1, "a"], [7469, 1, "\xE6"], [7470, 1, "b"], [7471, 2], [7472, 1, "d"], [7473, 1, "e"], [7474, 1, "\u01DD"], [7475, 1, "g"], [7476, 1, "h"], [7477, 1, "i"], [7478, 1, "j"], [7479, 1, "k"], [7480, 1, "l"], [7481, 1, "m"], [7482, 1, "n"], [7483, 2], [7484, 1, "o"], [7485, 1, "\u0223"], [7486, 1, "p"], [7487, 1, "r"], [7488, 1, "t"], [7489, 1, "u"], [7490, 1, "w"], [7491, 1, "a"], [7492, 1, "\u0250"], [7493, 1, "\u0251"], [7494, 1, "\u1D02"], [7495, 1, "b"], [7496, 1, "d"], [7497, 1, "e"], [7498, 1, "\u0259"], [7499, 1, "\u025B"], [7500, 1, "\u025C"], [7501, 1, "g"], [7502, 2], [7503, 1, "k"], [7504, 1, "m"], [7505, 1, "\u014B"], [7506, 1, "o"], [7507, 1, "\u0254"], [7508, 1, "\u1D16"], [7509, 1, "\u1D17"], [7510, 1, "p"], [7511, 1, "t"], [7512, 1, "u"], [7513, 1, "\u1D1D"], [7514, 1, "\u026F"], [7515, 1, "v"], [7516, 1, "\u1D25"], [7517, 1, "\u03B2"], [7518, 1, "\u03B3"], [7519, 1, "\u03B4"], [7520, 1, "\u03C6"], [7521, 1, "\u03C7"], [7522, 1, "i"], [7523, 1, "r"], [7524, 1, "u"], [7525, 1, "v"], [7526, 1, "\u03B2"], [7527, 1, "\u03B3"], [7528, 1, "\u03C1"], [7529, 1, "\u03C6"], [7530, 1, "\u03C7"], [7531, 2], [[7532, 7543], 2], [7544, 1, "\u043D"], [[7545, 7578], 2], [7579, 1, "\u0252"], [7580, 1, "c"], [7581, 1, "\u0255"], [7582, 1, "\xF0"], [7583, 1, "\u025C"], [7584, 1, "f"], [7585, 1, "\u025F"], [7586, 1, "\u0261"], [7587, 1, "\u0265"], [7588, 1, "\u0268"], [7589, 1, "\u0269"], [7590, 1, "\u026A"], [7591, 1, "\u1D7B"], [7592, 1, "\u029D"], [7593, 1, "\u026D"], [7594, 1, "\u1D85"], [7595, 1, "\u029F"], [7596, 1, "\u0271"], [7597, 1, "\u0270"], [7598, 1, "\u0272"], [7599, 1, "\u0273"], [7600, 1, "\u0274"], [7601, 1, "\u0275"], [7602, 1, "\u0278"], [7603, 1, "\u0282"], [7604, 1, "\u0283"], [7605, 1, "\u01AB"], [7606, 1, "\u0289"], [7607, 1, "\u028A"], [7608, 1, "\u1D1C"], [7609, 1, "\u028B"], [7610, 1, "\u028C"], [7611, 1, "z"], [7612, 1, "\u0290"], [7613, 1, "\u0291"], [7614, 1, "\u0292"], [7615, 1, "\u03B8"], [[7616, 7619], 2], [[7620, 7626], 2], [[7627, 7654], 2], [[7655, 7669], 2], [[7670, 7673], 2], [7674, 2], [7675, 2], [7676, 2], [7677, 2], [[7678, 7679], 2], [7680, 1, "\u1E01"], [7681, 2], [7682, 1, "\u1E03"], [7683, 2], [7684, 1, "\u1E05"], [7685, 2], [7686, 1, "\u1E07"], [7687, 2], [7688, 1, "\u1E09"], [7689, 2], [7690, 1, "\u1E0B"], [7691, 2], [7692, 1, "\u1E0D"], [7693, 2], [7694, 1, "\u1E0F"], [7695, 2], [7696, 1, "\u1E11"], [7697, 2], [7698, 1, "\u1E13"], [7699, 2], [7700, 1, "\u1E15"], [7701, 2], [7702, 1, "\u1E17"], [7703, 2], [7704, 1, "\u1E19"], [7705, 2], [7706, 1, "\u1E1B"], [7707, 2], [7708, 1, "\u1E1D"], [7709, 2], [7710, 1, "\u1E1F"], [7711, 2], [7712, 1, "\u1E21"], [7713, 2], [7714, 1, "\u1E23"], [7715, 2], [7716, 1, "\u1E25"], [7717, 2], [7718, 1, "\u1E27"], [7719, 2], [7720, 1, "\u1E29"], [7721, 2], [7722, 1, "\u1E2B"], [7723, 2], [7724, 1, "\u1E2D"], [7725, 2], [7726, 1, "\u1E2F"], [7727, 2], [7728, 1, "\u1E31"], [7729, 2], [7730, 1, "\u1E33"], [7731, 2], [7732, 1, "\u1E35"], [7733, 2], [7734, 1, "\u1E37"], [7735, 2], [7736, 1, "\u1E39"], [7737, 2], [7738, 1, "\u1E3B"], [7739, 2], [7740, 1, "\u1E3D"], [7741, 2], [7742, 1, "\u1E3F"], [7743, 2], [7744, 1, "\u1E41"], [7745, 2], [7746, 1, "\u1E43"], [7747, 2], [7748, 1, "\u1E45"], [7749, 2], [7750, 1, "\u1E47"], [7751, 2], [7752, 1, "\u1E49"], [7753, 2], [7754, 1, "\u1E4B"], [7755, 2], [7756, 1, "\u1E4D"], [7757, 2], [7758, 1, "\u1E4F"], [7759, 2], [7760, 1, "\u1E51"], [7761, 2], [7762, 1, "\u1E53"], [7763, 2], [7764, 1, "\u1E55"], [7765, 2], [7766, 1, "\u1E57"], [7767, 2], [7768, 1, "\u1E59"], [7769, 2], [7770, 1, "\u1E5B"], [7771, 2], [7772, 1, "\u1E5D"], [7773, 2], [7774, 1, "\u1E5F"], [7775, 2], [7776, 1, "\u1E61"], [7777, 2], [7778, 1, "\u1E63"], [7779, 2], [7780, 1, "\u1E65"], [7781, 2], [7782, 1, "\u1E67"], [7783, 2], [7784, 1, "\u1E69"], [7785, 2], [7786, 1, "\u1E6B"], [7787, 2], [7788, 1, "\u1E6D"], [7789, 2], [7790, 1, "\u1E6F"], [7791, 2], [7792, 1, "\u1E71"], [7793, 2], [7794, 1, "\u1E73"], [7795, 2], [7796, 1, "\u1E75"], [7797, 2], [7798, 1, "\u1E77"], [7799, 2], [7800, 1, "\u1E79"], [7801, 2], [7802, 1, "\u1E7B"], [7803, 2], [7804, 1, "\u1E7D"], [7805, 2], [7806, 1, "\u1E7F"], [7807, 2], [7808, 1, "\u1E81"], [7809, 2], [7810, 1, "\u1E83"], [7811, 2], [7812, 1, "\u1E85"], [7813, 2], [7814, 1, "\u1E87"], [7815, 2], [7816, 1, "\u1E89"], [7817, 2], [7818, 1, "\u1E8B"], [7819, 2], [7820, 1, "\u1E8D"], [7821, 2], [7822, 1, "\u1E8F"], [7823, 2], [7824, 1, "\u1E91"], [7825, 2], [7826, 1, "\u1E93"], [7827, 2], [7828, 1, "\u1E95"], [[7829, 7833], 2], [7834, 1, "a\u02BE"], [7835, 1, "\u1E61"], [[7836, 7837], 2], [7838, 1, "ss"], [7839, 2], [7840, 1, "\u1EA1"], [7841, 2], [7842, 1, "\u1EA3"], [7843, 2], [7844, 1, "\u1EA5"], [7845, 2], [7846, 1, "\u1EA7"], [7847, 2], [7848, 1, "\u1EA9"], [7849, 2], [7850, 1, "\u1EAB"], [7851, 2], [7852, 1, "\u1EAD"], [7853, 2], [7854, 1, "\u1EAF"], [7855, 2], [7856, 1, "\u1EB1"], [7857, 2], [7858, 1, "\u1EB3"], [7859, 2], [7860, 1, "\u1EB5"], [7861, 2], [7862, 1, "\u1EB7"], [7863, 2], [7864, 1, "\u1EB9"], [7865, 2], [7866, 1, "\u1EBB"], [7867, 2], [7868, 1, "\u1EBD"], [7869, 2], [7870, 1, "\u1EBF"], [7871, 2], [7872, 1, "\u1EC1"], [7873, 2], [7874, 1, "\u1EC3"], [7875, 2], [7876, 1, "\u1EC5"], [7877, 2], [7878, 1, "\u1EC7"], [7879, 2], [7880, 1, "\u1EC9"], [7881, 2], [7882, 1, "\u1ECB"], [7883, 2], [7884, 1, "\u1ECD"], [7885, 2], [7886, 1, "\u1ECF"], [7887, 2], [7888, 1, "\u1ED1"], [7889, 2], [7890, 1, "\u1ED3"], [7891, 2], [7892, 1, "\u1ED5"], [7893, 2], [7894, 1, "\u1ED7"], [7895, 2], [7896, 1, "\u1ED9"], [7897, 2], [7898, 1, "\u1EDB"], [7899, 2], [7900, 1, "\u1EDD"], [7901, 2], [7902, 1, "\u1EDF"], [7903, 2], [7904, 1, "\u1EE1"], [7905, 2], [7906, 1, "\u1EE3"], [7907, 2], [7908, 1, "\u1EE5"], [7909, 2], [7910, 1, "\u1EE7"], [7911, 2], [7912, 1, "\u1EE9"], [7913, 2], [7914, 1, "\u1EEB"], [7915, 2], [7916, 1, "\u1EED"], [7917, 2], [7918, 1, "\u1EEF"], [7919, 2], [7920, 1, "\u1EF1"], [7921, 2], [7922, 1, "\u1EF3"], [7923, 2], [7924, 1, "\u1EF5"], [7925, 2], [7926, 1, "\u1EF7"], [7927, 2], [7928, 1, "\u1EF9"], [7929, 2], [7930, 1, "\u1EFB"], [7931, 2], [7932, 1, "\u1EFD"], [7933, 2], [7934, 1, "\u1EFF"], [7935, 2], [[7936, 7943], 2], [7944, 1, "\u1F00"], [7945, 1, "\u1F01"], [7946, 1, "\u1F02"], [7947, 1, "\u1F03"], [7948, 1, "\u1F04"], [7949, 1, "\u1F05"], [7950, 1, "\u1F06"], [7951, 1, "\u1F07"], [[7952, 7957], 2], [[7958, 7959], 3], [7960, 1, "\u1F10"], [7961, 1, "\u1F11"], [7962, 1, "\u1F12"], [7963, 1, "\u1F13"], [7964, 1, "\u1F14"], [7965, 1, "\u1F15"], [[7966, 7967], 3], [[7968, 7975], 2], [7976, 1, "\u1F20"], [7977, 1, "\u1F21"], [7978, 1, "\u1F22"], [7979, 1, "\u1F23"], [7980, 1, "\u1F24"], [7981, 1, "\u1F25"], [7982, 1, "\u1F26"], [7983, 1, "\u1F27"], [[7984, 7991], 2], [7992, 1, "\u1F30"], [7993, 1, "\u1F31"], [7994, 1, "\u1F32"], [7995, 1, "\u1F33"], [7996, 1, "\u1F34"], [7997, 1, "\u1F35"], [7998, 1, "\u1F36"], [7999, 1, "\u1F37"], [[8e3, 8005], 2], [[8006, 8007], 3], [8008, 1, "\u1F40"], [8009, 1, "\u1F41"], [8010, 1, "\u1F42"], [8011, 1, "\u1F43"], [8012, 1, "\u1F44"], [8013, 1, "\u1F45"], [[8014, 8015], 3], [[8016, 8023], 2], [8024, 3], [8025, 1, "\u1F51"], [8026, 3], [8027, 1, "\u1F53"], [8028, 3], [8029, 1, "\u1F55"], [8030, 3], [8031, 1, "\u1F57"], [[8032, 8039], 2], [8040, 1, "\u1F60"], [8041, 1, "\u1F61"], [8042, 1, "\u1F62"], [8043, 1, "\u1F63"], [8044, 1, "\u1F64"], [8045, 1, "\u1F65"], [8046, 1, "\u1F66"], [8047, 1, "\u1F67"], [8048, 2], [8049, 1, "\u03AC"], [8050, 2], [8051, 1, "\u03AD"], [8052, 2], [8053, 1, "\u03AE"], [8054, 2], [8055, 1, "\u03AF"], [8056, 2], [8057, 1, "\u03CC"], [8058, 2], [8059, 1, "\u03CD"], [8060, 2], [8061, 1, "\u03CE"], [[8062, 8063], 3], [8064, 1, "\u1F00\u03B9"], [8065, 1, "\u1F01\u03B9"], [8066, 1, "\u1F02\u03B9"], [8067, 1, "\u1F03\u03B9"], [8068, 1, "\u1F04\u03B9"], [8069, 1, "\u1F05\u03B9"], [8070, 1, "\u1F06\u03B9"], [8071, 1, "\u1F07\u03B9"], [8072, 1, "\u1F00\u03B9"], [8073, 1, "\u1F01\u03B9"], [8074, 1, "\u1F02\u03B9"], [8075, 1, "\u1F03\u03B9"], [8076, 1, "\u1F04\u03B9"], [8077, 1, "\u1F05\u03B9"], [8078, 1, "\u1F06\u03B9"], [8079, 1, "\u1F07\u03B9"], [8080, 1, "\u1F20\u03B9"], [8081, 1, "\u1F21\u03B9"], [8082, 1, "\u1F22\u03B9"], [8083, 1, "\u1F23\u03B9"], [8084, 1, "\u1F24\u03B9"], [8085, 1, "\u1F25\u03B9"], [8086, 1, "\u1F26\u03B9"], [8087, 1, "\u1F27\u03B9"], [8088, 1, "\u1F20\u03B9"], [8089, 1, "\u1F21\u03B9"], [8090, 1, "\u1F22\u03B9"], [8091, 1, "\u1F23\u03B9"], [8092, 1, "\u1F24\u03B9"], [8093, 1, "\u1F25\u03B9"], [8094, 1, "\u1F26\u03B9"], [8095, 1, "\u1F27\u03B9"], [8096, 1, "\u1F60\u03B9"], [8097, 1, "\u1F61\u03B9"], [8098, 1, "\u1F62\u03B9"], [8099, 1, "\u1F63\u03B9"], [8100, 1, "\u1F64\u03B9"], [8101, 1, "\u1F65\u03B9"], [8102, 1, "\u1F66\u03B9"], [8103, 1, "\u1F67\u03B9"], [8104, 1, "\u1F60\u03B9"], [8105, 1, "\u1F61\u03B9"], [8106, 1, "\u1F62\u03B9"], [8107, 1, "\u1F63\u03B9"], [8108, 1, "\u1F64\u03B9"], [8109, 1, "\u1F65\u03B9"], [8110, 1, "\u1F66\u03B9"], [8111, 1, "\u1F67\u03B9"], [[8112, 8113], 2], [8114, 1, "\u1F70\u03B9"], [8115, 1, "\u03B1\u03B9"], [8116, 1, "\u03AC\u03B9"], [8117, 3], [8118, 2], [8119, 1, "\u1FB6\u03B9"], [8120, 1, "\u1FB0"], [8121, 1, "\u1FB1"], [8122, 1, "\u1F70"], [8123, 1, "\u03AC"], [8124, 1, "\u03B1\u03B9"], [8125, 5, " \u0313"], [8126, 1, "\u03B9"], [8127, 5, " \u0313"], [8128, 5, " \u0342"], [8129, 5, " \u0308\u0342"], [8130, 1, "\u1F74\u03B9"], [8131, 1, "\u03B7\u03B9"], [8132, 1, "\u03AE\u03B9"], [8133, 3], [8134, 2], [8135, 1, "\u1FC6\u03B9"], [8136, 1, "\u1F72"], [8137, 1, "\u03AD"], [8138, 1, "\u1F74"], [8139, 1, "\u03AE"], [8140, 1, "\u03B7\u03B9"], [8141, 5, " \u0313\u0300"], [8142, 5, " \u0313\u0301"], [8143, 5, " \u0313\u0342"], [[8144, 8146], 2], [8147, 1, "\u0390"], [[8148, 8149], 3], [[8150, 8151], 2], [8152, 1, "\u1FD0"], [8153, 1, "\u1FD1"], [8154, 1, "\u1F76"], [8155, 1, "\u03AF"], [8156, 3], [8157, 5, " \u0314\u0300"], [8158, 5, " \u0314\u0301"], [8159, 5, " \u0314\u0342"], [[8160, 8162], 2], [8163, 1, "\u03B0"], [[8164, 8167], 2], [8168, 1, "\u1FE0"], [8169, 1, "\u1FE1"], [8170, 1, "\u1F7A"], [8171, 1, "\u03CD"], [8172, 1, "\u1FE5"], [8173, 5, " \u0308\u0300"], [8174, 5, " \u0308\u0301"], [8175, 5, "`"], [[8176, 8177], 3], [8178, 1, "\u1F7C\u03B9"], [8179, 1, "\u03C9\u03B9"], [8180, 1, "\u03CE\u03B9"], [8181, 3], [8182, 2], [8183, 1, "\u1FF6\u03B9"], [8184, 1, "\u1F78"], [8185, 1, "\u03CC"], [8186, 1, "\u1F7C"], [8187, 1, "\u03CE"], [8188, 1, "\u03C9\u03B9"], [8189, 5, " \u0301"], [8190, 5, " \u0314"], [8191, 3], [[8192, 8202], 5, " "], [8203, 7], [[8204, 8205], 6, ""], [[8206, 8207], 3], [8208, 2], [8209, 1, "\u2010"], [[8210, 8214], 2], [8215, 5, " \u0333"], [[8216, 8227], 2], [[8228, 8230], 3], [8231, 2], [[8232, 8238], 3], [8239, 5, " "], [[8240, 8242], 2], [8243, 1, "\u2032\u2032"], [8244, 1, "\u2032\u2032\u2032"], [8245, 2], [8246, 1, "\u2035\u2035"], [8247, 1, "\u2035\u2035\u2035"], [[8248, 8251], 2], [8252, 5, "!!"], [8253, 2], [8254, 5, " \u0305"], [[8255, 8262], 2], [8263, 5, "??"], [8264, 5, "?!"], [8265, 5, "!?"], [[8266, 8269], 2], [[8270, 8274], 2], [[8275, 8276], 2], [[8277, 8278], 2], [8279, 1, "\u2032\u2032\u2032\u2032"], [[8280, 8286], 2], [8287, 5, " "], [8288, 7], [[8289, 8291], 3], [8292, 7], [8293, 3], [[8294, 8297], 3], [[8298, 8303], 3], [8304, 1, "0"], [8305, 1, "i"], [[8306, 8307], 3], [8308, 1, "4"], [8309, 1, "5"], [8310, 1, "6"], [8311, 1, "7"], [8312, 1, "8"], [8313, 1, "9"], [8314, 5, "+"], [8315, 1, "\u2212"], [8316, 5, "="], [8317, 5, "("], [8318, 5, ")"], [8319, 1, "n"], [8320, 1, "0"], [8321, 1, "1"], [8322, 1, "2"], [8323, 1, "3"], [8324, 1, "4"], [8325, 1, "5"], [8326, 1, "6"], [8327, 1, "7"], [8328, 1, "8"], [8329, 1, "9"], [8330, 5, "+"], [8331, 1, "\u2212"], [8332, 5, "="], [8333, 5, "("], [8334, 5, ")"], [8335, 3], [8336, 1, "a"], [8337, 1, "e"], [8338, 1, "o"], [8339, 1, "x"], [8340, 1, "\u0259"], [8341, 1, "h"], [8342, 1, "k"], [8343, 1, "l"], [8344, 1, "m"], [8345, 1, "n"], [8346, 1, "p"], [8347, 1, "s"], [8348, 1, "t"], [[8349, 8351], 3], [[8352, 8359], 2], [8360, 1, "rs"], [[8361, 8362], 2], [8363, 2], [8364, 2], [[8365, 8367], 2], [[8368, 8369], 2], [[8370, 8373], 2], [[8374, 8376], 2], [8377, 2], [8378, 2], [[8379, 8381], 2], [8382, 2], [8383, 2], [8384, 2], [[8385, 8399], 3], [[8400, 8417], 2], [[8418, 8419], 2], [[8420, 8426], 2], [8427, 2], [[8428, 8431], 2], [8432, 2], [[8433, 8447], 3], [8448, 5, "a/c"], [8449, 5, "a/s"], [8450, 1, "c"], [8451, 1, "\xB0c"], [8452, 2], [8453, 5, "c/o"], [8454, 5, "c/u"], [8455, 1, "\u025B"], [8456, 2], [8457, 1, "\xB0f"], [8458, 1, "g"], [[8459, 8462], 1, "h"], [8463, 1, "\u0127"], [[8464, 8465], 1, "i"], [[8466, 8467], 1, "l"], [8468, 2], [8469, 1, "n"], [8470, 1, "no"], [[8471, 8472], 2], [8473, 1, "p"], [8474, 1, "q"], [[8475, 8477], 1, "r"], [[8478, 8479], 2], [8480, 1, "sm"], [8481, 1, "tel"], [8482, 1, "tm"], [8483, 2], [8484, 1, "z"], [8485, 2], [8486, 1, "\u03C9"], [8487, 2], [8488, 1, "z"], [8489, 2], [8490, 1, "k"], [8491, 1, "\xE5"], [8492, 1, "b"], [8493, 1, "c"], [8494, 2], [[8495, 8496], 1, "e"], [8497, 1, "f"], [8498, 3], [8499, 1, "m"], [8500, 1, "o"], [8501, 1, "\u05D0"], [8502, 1, "\u05D1"], [8503, 1, "\u05D2"], [8504, 1, "\u05D3"], [8505, 1, "i"], [8506, 2], [8507, 1, "fax"], [8508, 1, "\u03C0"], [[8509, 8510], 1, "\u03B3"], [8511, 1, "\u03C0"], [8512, 1, "\u2211"], [[8513, 8516], 2], [[8517, 8518], 1, "d"], [8519, 1, "e"], [8520, 1, "i"], [8521, 1, "j"], [[8522, 8523], 2], [8524, 2], [8525, 2], [8526, 2], [8527, 2], [8528, 1, "1\u20447"], [8529, 1, "1\u20449"], [8530, 1, "1\u204410"], [8531, 1, "1\u20443"], [8532, 1, "2\u20443"], [8533, 1, "1\u20445"], [8534, 1, "2\u20445"], [8535, 1, "3\u20445"], [8536, 1, "4\u20445"], [8537, 1, "1\u20446"], [8538, 1, "5\u20446"], [8539, 1, "1\u20448"], [8540, 1, "3\u20448"], [8541, 1, "5\u20448"], [8542, 1, "7\u20448"], [8543, 1, "1\u2044"], [8544, 1, "i"], [8545, 1, "ii"], [8546, 1, "iii"], [8547, 1, "iv"], [8548, 1, "v"], [8549, 1, "vi"], [8550, 1, "vii"], [8551, 1, "viii"], [8552, 1, "ix"], [8553, 1, "x"], [8554, 1, "xi"], [8555, 1, "xii"], [8556, 1, "l"], [8557, 1, "c"], [8558, 1, "d"], [8559, 1, "m"], [8560, 1, "i"], [8561, 1, "ii"], [8562, 1, "iii"], [8563, 1, "iv"], [8564, 1, "v"], [8565, 1, "vi"], [8566, 1, "vii"], [8567, 1, "viii"], [8568, 1, "ix"], [8569, 1, "x"], [8570, 1, "xi"], [8571, 1, "xii"], [8572, 1, "l"], [8573, 1, "c"], [8574, 1, "d"], [8575, 1, "m"], [[8576, 8578], 2], [8579, 3], [8580, 2], [[8581, 8584], 2], [8585, 1, "0\u20443"], [[8586, 8587], 2], [[8588, 8591], 3], [[8592, 8682], 2], [[8683, 8691], 2], [[8692, 8703], 2], [[8704, 8747], 2], [8748, 1, "\u222B\u222B"], [8749, 1, "\u222B\u222B\u222B"], [8750, 2], [8751, 1, "\u222E\u222E"], [8752, 1, "\u222E\u222E\u222E"], [[8753, 8799], 2], [8800, 4], [[8801, 8813], 2], [[8814, 8815], 4], [[8816, 8945], 2], [[8946, 8959], 2], [8960, 2], [8961, 2], [[8962, 9e3], 2], [9001, 1, "\u3008"], [9002, 1, "\u3009"], [[9003, 9082], 2], [9083, 2], [9084, 2], [[9085, 9114], 2], [[9115, 9166], 2], [[9167, 9168], 2], [[9169, 9179], 2], [[9180, 9191], 2], [9192, 2], [[9193, 9203], 2], [[9204, 9210], 2], [[9211, 9214], 2], [9215, 2], [[9216, 9252], 2], [[9253, 9254], 2], [[9255, 9279], 3], [[9280, 9290], 2], [[9291, 9311], 3], [9312, 1, "1"], [9313, 1, "2"], [9314, 1, "3"], [9315, 1, "4"], [9316, 1, "5"], [9317, 1, "6"], [9318, 1, "7"], [9319, 1, "8"], [9320, 1, "9"], [9321, 1, "10"], [9322, 1, "11"], [9323, 1, "12"], [9324, 1, "13"], [9325, 1, "14"], [9326, 1, "15"], [9327, 1, "16"], [9328, 1, "17"], [9329, 1, "18"], [9330, 1, "19"], [9331, 1, "20"], [9332, 5, "(1)"], [9333, 5, "(2)"], [9334, 5, "(3)"], [9335, 5, "(4)"], [9336, 5, "(5)"], [9337, 5, "(6)"], [9338, 5, "(7)"], [9339, 5, "(8)"], [9340, 5, "(9)"], [9341, 5, "(10)"], [9342, 5, "(11)"], [9343, 5, "(12)"], [9344, 5, "(13)"], [9345, 5, "(14)"], [9346, 5, "(15)"], [9347, 5, "(16)"], [9348, 5, "(17)"], [9349, 5, "(18)"], [9350, 5, "(19)"], [9351, 5, "(20)"], [[9352, 9371], 3], [9372, 5, "(a)"], [9373, 5, "(b)"], [9374, 5, "(c)"], [9375, 5, "(d)"], [9376, 5, "(e)"], [9377, 5, "(f)"], [9378, 5, "(g)"], [9379, 5, "(h)"], [9380, 5, "(i)"], [9381, 5, "(j)"], [9382, 5, "(k)"], [9383, 5, "(l)"], [9384, 5, "(m)"], [9385, 5, "(n)"], [9386, 5, "(o)"], [9387, 5, "(p)"], [9388, 5, "(q)"], [9389, 5, "(r)"], [9390, 5, "(s)"], [9391, 5, "(t)"], [9392, 5, "(u)"], [9393, 5, "(v)"], [9394, 5, "(w)"], [9395, 5, "(x)"], [9396, 5, "(y)"], [9397, 5, "(z)"], [9398, 1, "a"], [9399, 1, "b"], [9400, 1, "c"], [9401, 1, "d"], [9402, 1, "e"], [9403, 1, "f"], [9404, 1, "g"], [9405, 1, "h"], [9406, 1, "i"], [9407, 1, "j"], [9408, 1, "k"], [9409, 1, "l"], [9410, 1, "m"], [9411, 1, "n"], [9412, 1, "o"], [9413, 1, "p"], [9414, 1, "q"], [9415, 1, "r"], [9416, 1, "s"], [9417, 1, "t"], [9418, 1, "u"], [9419, 1, "v"], [9420, 1, "w"], [9421, 1, "x"], [9422, 1, "y"], [9423, 1, "z"], [9424, 1, "a"], [9425, 1, "b"], [9426, 1, "c"], [9427, 1, "d"], [9428, 1, "e"], [9429, 1, "f"], [9430, 1, "g"], [9431, 1, "h"], [9432, 1, "i"], [9433, 1, "j"], [9434, 1, "k"], [9435, 1, "l"], [9436, 1, "m"], [9437, 1, "n"], [9438, 1, "o"], [9439, 1, "p"], [9440, 1, "q"], [9441, 1, "r"], [9442, 1, "s"], [9443, 1, "t"], [9444, 1, "u"], [9445, 1, "v"], [9446, 1, "w"], [9447, 1, "x"], [9448, 1, "y"], [9449, 1, "z"], [9450, 1, "0"], [[9451, 9470], 2], [9471, 2], [[9472, 9621], 2], [[9622, 9631], 2], [[9632, 9711], 2], [[9712, 9719], 2], [[9720, 9727], 2], [[9728, 9747], 2], [[9748, 9749], 2], [[9750, 9751], 2], [9752, 2], [9753, 2], [[9754, 9839], 2], [[9840, 9841], 2], [[9842, 9853], 2], [[9854, 9855], 2], [[9856, 9865], 2], [[9866, 9873], 2], [[9874, 9884], 2], [9885, 2], [[9886, 9887], 2], [[9888, 9889], 2], [[9890, 9905], 2], [9906, 2], [[9907, 9916], 2], [[9917, 9919], 2], [[9920, 9923], 2], [[9924, 9933], 2], [9934, 2], [[9935, 9953], 2], [9954, 2], [9955, 2], [[9956, 9959], 2], [[9960, 9983], 2], [9984, 2], [[9985, 9988], 2], [9989, 2], [[9990, 9993], 2], [[9994, 9995], 2], [[9996, 10023], 2], [10024, 2], [[10025, 10059], 2], [10060, 2], [10061, 2], [10062, 2], [[10063, 10066], 2], [[10067, 10069], 2], [10070, 2], [10071, 2], [[10072, 10078], 2], [[10079, 10080], 2], [[10081, 10087], 2], [[10088, 10101], 2], [[10102, 10132], 2], [[10133, 10135], 2], [[10136, 10159], 2], [10160, 2], [[10161, 10174], 2], [10175, 2], [[10176, 10182], 2], [[10183, 10186], 2], [10187, 2], [10188, 2], [10189, 2], [[10190, 10191], 2], [[10192, 10219], 2], [[10220, 10223], 2], [[10224, 10239], 2], [[10240, 10495], 2], [[10496, 10763], 2], [10764, 1, "\u222B\u222B\u222B\u222B"], [[10765, 10867], 2], [10868, 5, "::="], [10869, 5, "=="], [10870, 5, "==="], [[10871, 10971], 2], [10972, 1, "\u2ADD\u0338"], [[10973, 11007], 2], [[11008, 11021], 2], [[11022, 11027], 2], [[11028, 11034], 2], [[11035, 11039], 2], [[11040, 11043], 2], [[11044, 11084], 2], [[11085, 11087], 2], [[11088, 11092], 2], [[11093, 11097], 2], [[11098, 11123], 2], [[11124, 11125], 3], [[11126, 11157], 2], [11158, 3], [11159, 2], [[11160, 11193], 2], [[11194, 11196], 2], [[11197, 11208], 2], [11209, 2], [[11210, 11217], 2], [11218, 2], [[11219, 11243], 2], [[11244, 11247], 2], [[11248, 11262], 2], [11263, 2], [11264, 1, "\u2C30"], [11265, 1, "\u2C31"], [11266, 1, "\u2C32"], [11267, 1, "\u2C33"], [11268, 1, "\u2C34"], [11269, 1, "\u2C35"], [11270, 1, "\u2C36"], [11271, 1, "\u2C37"], [11272, 1, "\u2C38"], [11273, 1, "\u2C39"], [11274, 1, "\u2C3A"], [11275, 1, "\u2C3B"], [11276, 1, "\u2C3C"], [11277, 1, "\u2C3D"], [11278, 1, "\u2C3E"], [11279, 1, "\u2C3F"], [11280, 1, "\u2C40"], [11281, 1, "\u2C41"], [11282, 1, "\u2C42"], [11283, 1, "\u2C43"], [11284, 1, "\u2C44"], [11285, 1, "\u2C45"], [11286, 1, "\u2C46"], [11287, 1, "\u2C47"], [11288, 1, "\u2C48"], [11289, 1, "\u2C49"], [11290, 1, "\u2C4A"], [11291, 1, "\u2C4B"], [11292, 1, "\u2C4C"], [11293, 1, "\u2C4D"], [11294, 1, "\u2C4E"], [11295, 1, "\u2C4F"], [11296, 1, "\u2C50"], [11297, 1, "\u2C51"], [11298, 1, "\u2C52"], [11299, 1, "\u2C53"], [11300, 1, "\u2C54"], [11301, 1, "\u2C55"], [11302, 1, "\u2C56"], [11303, 1, "\u2C57"], [11304, 1, "\u2C58"], [11305, 1, "\u2C59"], [11306, 1, "\u2C5A"], [11307, 1, "\u2C5B"], [11308, 1, "\u2C5C"], [11309, 1, "\u2C5D"], [11310, 1, "\u2C5E"], [11311, 1, "\u2C5F"], [[11312, 11358], 2], [11359, 2], [11360, 1, "\u2C61"], [11361, 2], [11362, 1, "\u026B"], [11363, 1, "\u1D7D"], [11364, 1, "\u027D"], [[11365, 11366], 2], [11367, 1, "\u2C68"], [11368, 2], [11369, 1, "\u2C6A"], [11370, 2], [11371, 1, "\u2C6C"], [11372, 2], [11373, 1, "\u0251"], [11374, 1, "\u0271"], [11375, 1, "\u0250"], [11376, 1, "\u0252"], [11377, 2], [11378, 1, "\u2C73"], [11379, 2], [11380, 2], [11381, 1, "\u2C76"], [[11382, 11383], 2], [[11384, 11387], 2], [11388, 1, "j"], [11389, 1, "v"], [11390, 1, "\u023F"], [11391, 1, "\u0240"], [11392, 1, "\u2C81"], [11393, 2], [11394, 1, "\u2C83"], [11395, 2], [11396, 1, "\u2C85"], [11397, 2], [11398, 1, "\u2C87"], [11399, 2], [11400, 1, "\u2C89"], [11401, 2], [11402, 1, "\u2C8B"], [11403, 2], [11404, 1, "\u2C8D"], [11405, 2], [11406, 1, "\u2C8F"], [11407, 2], [11408, 1, "\u2C91"], [11409, 2], [11410, 1, "\u2C93"], [11411, 2], [11412, 1, "\u2C95"], [11413, 2], [11414, 1, "\u2C97"], [11415, 2], [11416, 1, "\u2C99"], [11417, 2], [11418, 1, "\u2C9B"], [11419, 2], [11420, 1, "\u2C9D"], [11421, 2], [11422, 1, "\u2C9F"], [11423, 2], [11424, 1, "\u2CA1"], [11425, 2], [11426, 1, "\u2CA3"], [11427, 2], [11428, 1, "\u2CA5"], [11429, 2], [11430, 1, "\u2CA7"], [11431, 2], [11432, 1, "\u2CA9"], [11433, 2], [11434, 1, "\u2CAB"], [11435, 2], [11436, 1, "\u2CAD"], [11437, 2], [11438, 1, "\u2CAF"], [11439, 2], [11440, 1, "\u2CB1"], [11441, 2], [11442, 1, "\u2CB3"], [11443, 2], [11444, 1, "\u2CB5"], [11445, 2], [11446, 1, "\u2CB7"], [11447, 2], [11448, 1, "\u2CB9"], [11449, 2], [11450, 1, "\u2CBB"], [11451, 2], [11452, 1, "\u2CBD"], [11453, 2], [11454, 1, "\u2CBF"], [11455, 2], [11456, 1, "\u2CC1"], [11457, 2], [11458, 1, "\u2CC3"], [11459, 2], [11460, 1, "\u2CC5"], [11461, 2], [11462, 1, "\u2CC7"], [11463, 2], [11464, 1, "\u2CC9"], [11465, 2], [11466, 1, "\u2CCB"], [11467, 2], [11468, 1, "\u2CCD"], [11469, 2], [11470, 1, "\u2CCF"], [11471, 2], [11472, 1, "\u2CD1"], [11473, 2], [11474, 1, "\u2CD3"], [11475, 2], [11476, 1, "\u2CD5"], [11477, 2], [11478, 1, "\u2CD7"], [11479, 2], [11480, 1, "\u2CD9"], [11481, 2], [11482, 1, "\u2CDB"], [11483, 2], [11484, 1, "\u2CDD"], [11485, 2], [11486, 1, "\u2CDF"], [11487, 2], [11488, 1, "\u2CE1"], [11489, 2], [11490, 1, "\u2CE3"], [[11491, 11492], 2], [[11493, 11498], 2], [11499, 1, "\u2CEC"], [11500, 2], [11501, 1, "\u2CEE"], [[11502, 11505], 2], [11506, 1, "\u2CF3"], [11507, 2], [[11508, 11512], 3], [[11513, 11519], 2], [[11520, 11557], 2], [11558, 3], [11559, 2], [[11560, 11564], 3], [11565, 2], [[11566, 11567], 3], [[11568, 11621], 2], [[11622, 11623], 2], [[11624, 11630], 3], [11631, 1, "\u2D61"], [11632, 2], [[11633, 11646], 3], [11647, 2], [[11648, 11670], 2], [[11671, 11679], 3], [[11680, 11686], 2], [11687, 3], [[11688, 11694], 2], [11695, 3], [[11696, 11702], 2], [11703, 3], [[11704, 11710], 2], [11711, 3], [[11712, 11718], 2], [11719, 3], [[11720, 11726], 2], [11727, 3], [[11728, 11734], 2], [11735, 3], [[11736, 11742], 2], [11743, 3], [[11744, 11775], 2], [[11776, 11799], 2], [[11800, 11803], 2], [[11804, 11805], 2], [[11806, 11822], 2], [11823, 2], [11824, 2], [11825, 2], [[11826, 11835], 2], [[11836, 11842], 2], [[11843, 11844], 2], [[11845, 11849], 2], [[11850, 11854], 2], [11855, 2], [[11856, 11858], 2], [[11859, 11869], 2], [[11870, 11903], 3], [[11904, 11929], 2], [11930, 3], [[11931, 11934], 2], [11935, 1, "\u6BCD"], [[11936, 12018], 2], [12019, 1, "\u9F9F"], [[12020, 12031], 3], [12032, 1, "\u4E00"], [12033, 1, "\u4E28"], [12034, 1, "\u4E36"], [12035, 1, "\u4E3F"], [12036, 1, "\u4E59"], [12037, 1, "\u4E85"], [12038, 1, "\u4E8C"], [12039, 1, "\u4EA0"], [12040, 1, "\u4EBA"], [12041, 1, "\u513F"], [12042, 1, "\u5165"], [12043, 1, "\u516B"], [12044, 1, "\u5182"], [12045, 1, "\u5196"], [12046, 1, "\u51AB"], [12047, 1, "\u51E0"], [12048, 1, "\u51F5"], [12049, 1, "\u5200"], [12050, 1, "\u529B"], [12051, 1, "\u52F9"], [12052, 1, "\u5315"], [12053, 1, "\u531A"], [12054, 1, "\u5338"], [12055, 1, "\u5341"], [12056, 1, "\u535C"], [12057, 1, "\u5369"], [12058, 1, "\u5382"], [12059, 1, "\u53B6"], [12060, 1, "\u53C8"], [12061, 1, "\u53E3"], [12062, 1, "\u56D7"], [12063, 1, "\u571F"], [12064, 1, "\u58EB"], [12065, 1, "\u5902"], [12066, 1, "\u590A"], [12067, 1, "\u5915"], [12068, 1, "\u5927"], [12069, 1, "\u5973"], [12070, 1, "\u5B50"], [12071, 1, "\u5B80"], [12072, 1, "\u5BF8"], [12073, 1, "\u5C0F"], [12074, 1, "\u5C22"], [12075, 1, "\u5C38"], [12076, 1, "\u5C6E"], [12077, 1, "\u5C71"], [12078, 1, "\u5DDB"], [12079, 1, "\u5DE5"], [12080, 1, "\u5DF1"], [12081, 1, "\u5DFE"], [12082, 1, "\u5E72"], [12083, 1, "\u5E7A"], [12084, 1, "\u5E7F"], [12085, 1, "\u5EF4"], [12086, 1, "\u5EFE"], [12087, 1, "\u5F0B"], [12088, 1, "\u5F13"], [12089, 1, "\u5F50"], [12090, 1, "\u5F61"], [12091, 1, "\u5F73"], [12092, 1, "\u5FC3"], [12093, 1, "\u6208"], [12094, 1, "\u6236"], [12095, 1, "\u624B"], [12096, 1, "\u652F"], [12097, 1, "\u6534"], [12098, 1, "\u6587"], [12099, 1, "\u6597"], [12100, 1, "\u65A4"], [12101, 1, "\u65B9"], [12102, 1, "\u65E0"], [12103, 1, "\u65E5"], [12104, 1, "\u66F0"], [12105, 1, "\u6708"], [12106, 1, "\u6728"], [12107, 1, "\u6B20"], [12108, 1, "\u6B62"], [12109, 1, "\u6B79"], [12110, 1, "\u6BB3"], [12111, 1, "\u6BCB"], [12112, 1, "\u6BD4"], [12113, 1, "\u6BDB"], [12114, 1, "\u6C0F"], [12115, 1, "\u6C14"], [12116, 1, "\u6C34"], [12117, 1, "\u706B"], [12118, 1, "\u722A"], [12119, 1, "\u7236"], [12120, 1, "\u723B"], [12121, 1, "\u723F"], [12122, 1, "\u7247"], [12123, 1, "\u7259"], [12124, 1, "\u725B"], [12125, 1, "\u72AC"], [12126, 1, "\u7384"], [12127, 1, "\u7389"], [12128, 1, "\u74DC"], [12129, 1, "\u74E6"], [12130, 1, "\u7518"], [12131, 1, "\u751F"], [12132, 1, "\u7528"], [12133, 1, "\u7530"], [12134, 1, "\u758B"], [12135, 1, "\u7592"], [12136, 1, "\u7676"], [12137, 1, "\u767D"], [12138, 1, "\u76AE"], [12139, 1, "\u76BF"], [12140, 1, "\u76EE"], [12141, 1, "\u77DB"], [12142, 1, "\u77E2"], [12143, 1, "\u77F3"], [12144, 1, "\u793A"], [12145, 1, "\u79B8"], [12146, 1, "\u79BE"], [12147, 1, "\u7A74"], [12148, 1, "\u7ACB"], [12149, 1, "\u7AF9"], [12150, 1, "\u7C73"], [12151, 1, "\u7CF8"], [12152, 1, "\u7F36"], [12153, 1, "\u7F51"], [12154, 1, "\u7F8A"], [12155, 1, "\u7FBD"], [12156, 1, "\u8001"], [12157, 1, "\u800C"], [12158, 1, "\u8012"], [12159, 1, "\u8033"], [12160, 1, "\u807F"], [12161, 1, "\u8089"], [12162, 1, "\u81E3"], [12163, 1, "\u81EA"], [12164, 1, "\u81F3"], [12165, 1, "\u81FC"], [12166, 1, "\u820C"], [12167, 1, "\u821B"], [12168, 1, "\u821F"], [12169, 1, "\u826E"], [12170, 1, "\u8272"], [12171, 1, "\u8278"], [12172, 1, "\u864D"], [12173, 1, "\u866B"], [12174, 1, "\u8840"], [12175, 1, "\u884C"], [12176, 1, "\u8863"], [12177, 1, "\u897E"], [12178, 1, "\u898B"], [12179, 1, "\u89D2"], [12180, 1, "\u8A00"], [12181, 1, "\u8C37"], [12182, 1, "\u8C46"], [12183, 1, "\u8C55"], [12184, 1, "\u8C78"], [12185, 1, "\u8C9D"], [12186, 1, "\u8D64"], [12187, 1, "\u8D70"], [12188, 1, "\u8DB3"], [12189, 1, "\u8EAB"], [12190, 1, "\u8ECA"], [12191, 1, "\u8F9B"], [12192, 1, "\u8FB0"], [12193, 1, "\u8FB5"], [12194, 1, "\u9091"], [12195, 1, "\u9149"], [12196, 1, "\u91C6"], [12197, 1, "\u91CC"], [12198, 1, "\u91D1"], [12199, 1, "\u9577"], [12200, 1, "\u9580"], [12201, 1, "\u961C"], [12202, 1, "\u96B6"], [12203, 1, "\u96B9"], [12204, 1, "\u96E8"], [12205, 1, "\u9751"], [12206, 1, "\u975E"], [12207, 1, "\u9762"], [12208, 1, "\u9769"], [12209, 1, "\u97CB"], [12210, 1, "\u97ED"], [12211, 1, "\u97F3"], [12212, 1, "\u9801"], [12213, 1, "\u98A8"], [12214, 1, "\u98DB"], [12215, 1, "\u98DF"], [12216, 1, "\u9996"], [12217, 1, "\u9999"], [12218, 1, "\u99AC"], [12219, 1, "\u9AA8"], [12220, 1, "\u9AD8"], [12221, 1, "\u9ADF"], [12222, 1, "\u9B25"], [12223, 1, "\u9B2F"], [12224, 1, "\u9B32"], [12225, 1, "\u9B3C"], [12226, 1, "\u9B5A"], [12227, 1, "\u9CE5"], [12228, 1, "\u9E75"], [12229, 1, "\u9E7F"], [12230, 1, "\u9EA5"], [12231, 1, "\u9EBB"], [12232, 1, "\u9EC3"], [12233, 1, "\u9ECD"], [12234, 1, "\u9ED1"], [12235, 1, "\u9EF9"], [12236, 1, "\u9EFD"], [12237, 1, "\u9F0E"], [12238, 1, "\u9F13"], [12239, 1, "\u9F20"], [12240, 1, "\u9F3B"], [12241, 1, "\u9F4A"], [12242, 1, "\u9F52"], [12243, 1, "\u9F8D"], [12244, 1, "\u9F9C"], [12245, 1, "\u9FA0"], [[12246, 12271], 3], [[12272, 12283], 3], [[12284, 12287], 3], [12288, 5, " "], [12289, 2], [12290, 1, "."], [[12291, 12292], 2], [[12293, 12295], 2], [[12296, 12329], 2], [[12330, 12333], 2], [[12334, 12341], 2], [12342, 1, "\u3012"], [12343, 2], [12344, 1, "\u5341"], [12345, 1, "\u5344"], [12346, 1, "\u5345"], [12347, 2], [12348, 2], [12349, 2], [12350, 2], [12351, 2], [12352, 3], [[12353, 12436], 2], [[12437, 12438], 2], [[12439, 12440], 3], [[12441, 12442], 2], [12443, 5, " \u3099"], [12444, 5, " \u309A"], [[12445, 12446], 2], [12447, 1, "\u3088\u308A"], [12448, 2], [[12449, 12542], 2], [12543, 1, "\u30B3\u30C8"], [[12544, 12548], 3], [[12549, 12588], 2], [12589, 2], [12590, 2], [12591, 2], [12592, 3], [12593, 1, "\u1100"], [12594, 1, "\u1101"], [12595, 1, "\u11AA"], [12596, 1, "\u1102"], [12597, 1, "\u11AC"], [12598, 1, "\u11AD"], [12599, 1, "\u1103"], [12600, 1, "\u1104"], [12601, 1, "\u1105"], [12602, 1, "\u11B0"], [12603, 1, "\u11B1"], [12604, 1, "\u11B2"], [12605, 1, "\u11B3"], [12606, 1, "\u11B4"], [12607, 1, "\u11B5"], [12608, 1, "\u111A"], [12609, 1, "\u1106"], [12610, 1, "\u1107"], [12611, 1, "\u1108"], [12612, 1, "\u1121"], [12613, 1, "\u1109"], [12614, 1, "\u110A"], [12615, 1, "\u110B"], [12616, 1, "\u110C"], [12617, 1, "\u110D"], [12618, 1, "\u110E"], [12619, 1, "\u110F"], [12620, 1, "\u1110"], [12621, 1, "\u1111"], [12622, 1, "\u1112"], [12623, 1, "\u1161"], [12624, 1, "\u1162"], [12625, 1, "\u1163"], [12626, 1, "\u1164"], [12627, 1, "\u1165"], [12628, 1, "\u1166"], [12629, 1, "\u1167"], [12630, 1, "\u1168"], [12631, 1, "\u1169"], [12632, 1, "\u116A"], [12633, 1, "\u116B"], [12634, 1, "\u116C"], [12635, 1, "\u116D"], [12636, 1, "\u116E"], [12637, 1, "\u116F"], [12638, 1, "\u1170"], [12639, 1, "\u1171"], [12640, 1, "\u1172"], [12641, 1, "\u1173"], [12642, 1, "\u1174"], [12643, 1, "\u1175"], [12644, 3], [12645, 1, "\u1114"], [12646, 1, "\u1115"], [12647, 1, "\u11C7"], [12648, 1, "\u11C8"], [12649, 1, "\u11CC"], [12650, 1, "\u11CE"], [12651, 1, "\u11D3"], [12652, 1, "\u11D7"], [12653, 1, "\u11D9"], [12654, 1, "\u111C"], [12655, 1, "\u11DD"], [12656, 1, "\u11DF"], [12657, 1, "\u111D"], [12658, 1, "\u111E"], [12659, 1, "\u1120"], [12660, 1, "\u1122"], [12661, 1, "\u1123"], [12662, 1, "\u1127"], [12663, 1, "\u1129"], [12664, 1, "\u112B"], [12665, 1, "\u112C"], [12666, 1, "\u112D"], [12667, 1, "\u112E"], [12668, 1, "\u112F"], [12669, 1, "\u1132"], [12670, 1, "\u1136"], [12671, 1, "\u1140"], [12672, 1, "\u1147"], [12673, 1, "\u114C"], [12674, 1, "\u11F1"], [12675, 1, "\u11F2"], [12676, 1, "\u1157"], [12677, 1, "\u1158"], [12678, 1, "\u1159"], [12679, 1, "\u1184"], [12680, 1, "\u1185"], [12681, 1, "\u1188"], [12682, 1, "\u1191"], [12683, 1, "\u1192"], [12684, 1, "\u1194"], [12685, 1, "\u119E"], [12686, 1, "\u11A1"], [12687, 3], [[12688, 12689], 2], [12690, 1, "\u4E00"], [12691, 1, "\u4E8C"], [12692, 1, "\u4E09"], [12693, 1, "\u56DB"], [12694, 1, "\u4E0A"], [12695, 1, "\u4E2D"], [12696, 1, "\u4E0B"], [12697, 1, "\u7532"], [12698, 1, "\u4E59"], [12699, 1, "\u4E19"], [12700, 1, "\u4E01"], [12701, 1, "\u5929"], [12702, 1, "\u5730"], [12703, 1, "\u4EBA"], [[12704, 12727], 2], [[12728, 12730], 2], [[12731, 12735], 2], [[12736, 12751], 2], [[12752, 12771], 2], [[12772, 12783], 3], [[12784, 12799], 2], [12800, 5, "(\u1100)"], [12801, 5, "(\u1102)"], [12802, 5, "(\u1103)"], [12803, 5, "(\u1105)"], [12804, 5, "(\u1106)"], [12805, 5, "(\u1107)"], [12806, 5, "(\u1109)"], [12807, 5, "(\u110B)"], [12808, 5, "(\u110C)"], [12809, 5, "(\u110E)"], [12810, 5, "(\u110F)"], [12811, 5, "(\u1110)"], [12812, 5, "(\u1111)"], [12813, 5, "(\u1112)"], [12814, 5, "(\uAC00)"], [12815, 5, "(\uB098)"], [12816, 5, "(\uB2E4)"], [12817, 5, "(\uB77C)"], [12818, 5, "(\uB9C8)"], [12819, 5, "(\uBC14)"], [12820, 5, "(\uC0AC)"], [12821, 5, "(\uC544)"], [12822, 5, "(\uC790)"], [12823, 5, "(\uCC28)"], [12824, 5, "(\uCE74)"], [12825, 5, "(\uD0C0)"], [12826, 5, "(\uD30C)"], [12827, 5, "(\uD558)"], [12828, 5, "(\uC8FC)"], [12829, 5, "(\uC624\uC804)"], [12830, 5, "(\uC624\uD6C4)"], [12831, 3], [12832, 5, "(\u4E00)"], [12833, 5, "(\u4E8C)"], [12834, 5, "(\u4E09)"], [12835, 5, "(\u56DB)"], [12836, 5, "(\u4E94)"], [12837, 5, "(\u516D)"], [12838, 5, "(\u4E03)"], [12839, 5, "(\u516B)"], [12840, 5, "(\u4E5D)"], [12841, 5, "(\u5341)"], [12842, 5, "(\u6708)"], [12843, 5, "(\u706B)"], [12844, 5, "(\u6C34)"], [12845, 5, "(\u6728)"], [12846, 5, "(\u91D1)"], [12847, 5, "(\u571F)"], [12848, 5, "(\u65E5)"], [12849, 5, "(\u682A)"], [12850, 5, "(\u6709)"], [12851, 5, "(\u793E)"], [12852, 5, "(\u540D)"], [12853, 5, "(\u7279)"], [12854, 5, "(\u8CA1)"], [12855, 5, "(\u795D)"], [12856, 5, "(\u52B4)"], [12857, 5, "(\u4EE3)"], [12858, 5, "(\u547C)"], [12859, 5, "(\u5B66)"], [12860, 5, "(\u76E3)"], [12861, 5, "(\u4F01)"], [12862, 5, "(\u8CC7)"], [12863, 5, "(\u5354)"], [12864, 5, "(\u796D)"], [12865, 5, "(\u4F11)"], [12866, 5, "(\u81EA)"], [12867, 5, "(\u81F3)"], [12868, 1, "\u554F"], [12869, 1, "\u5E7C"], [12870, 1, "\u6587"], [12871, 1, "\u7B8F"], [[12872, 12879], 2], [12880, 1, "pte"], [12881, 1, "21"], [12882, 1, "22"], [12883, 1, "23"], [12884, 1, "24"], [12885, 1, "25"], [12886, 1, "26"], [12887, 1, "27"], [12888, 1, "28"], [12889, 1, "29"], [12890, 1, "30"], [12891, 1, "31"], [12892, 1, "32"], [12893, 1, "33"], [12894, 1, "34"], [12895, 1, "35"], [12896, 1, "\u1100"], [12897, 1, "\u1102"], [12898, 1, "\u1103"], [12899, 1, "\u1105"], [12900, 1, "\u1106"], [12901, 1, "\u1107"], [12902, 1, "\u1109"], [12903, 1, "\u110B"], [12904, 1, "\u110C"], [12905, 1, "\u110E"], [12906, 1, "\u110F"], [12907, 1, "\u1110"], [12908, 1, "\u1111"], [12909, 1, "\u1112"], [12910, 1, "\uAC00"], [12911, 1, "\uB098"], [12912, 1, "\uB2E4"], [12913, 1, "\uB77C"], [12914, 1, "\uB9C8"], [12915, 1, "\uBC14"], [12916, 1, "\uC0AC"], [12917, 1, "\uC544"], [12918, 1, "\uC790"], [12919, 1, "\uCC28"], [12920, 1, "\uCE74"], [12921, 1, "\uD0C0"], [12922, 1, "\uD30C"], [12923, 1, "\uD558"], [12924, 1, "\uCC38\uACE0"], [12925, 1, "\uC8FC\uC758"], [12926, 1, "\uC6B0"], [12927, 2], [12928, 1, "\u4E00"], [12929, 1, "\u4E8C"], [12930, 1, "\u4E09"], [12931, 1, "\u56DB"], [12932, 1, "\u4E94"], [12933, 1, "\u516D"], [12934, 1, "\u4E03"], [12935, 1, "\u516B"], [12936, 1, "\u4E5D"], [12937, 1, "\u5341"], [12938, 1, "\u6708"], [12939, 1, "\u706B"], [12940, 1, "\u6C34"], [12941, 1, "\u6728"], [12942, 1, "\u91D1"], [12943, 1, "\u571F"], [12944, 1, "\u65E5"], [12945, 1, "\u682A"], [12946, 1, "\u6709"], [12947, 1, "\u793E"], [12948, 1, "\u540D"], [12949, 1, "\u7279"], [12950, 1, "\u8CA1"], [12951, 1, "\u795D"], [12952, 1, "\u52B4"], [12953, 1, "\u79D8"], [12954, 1, "\u7537"], [12955, 1, "\u5973"], [12956, 1, "\u9069"], [12957, 1, "\u512A"], [12958, 1, "\u5370"], [12959, 1, "\u6CE8"], [12960, 1, "\u9805"], [12961, 1, "\u4F11"], [12962, 1, "\u5199"], [12963, 1, "\u6B63"], [12964, 1, "\u4E0A"], [12965, 1, "\u4E2D"], [12966, 1, "\u4E0B"], [12967, 1, "\u5DE6"], [12968, 1, "\u53F3"], [12969, 1, "\u533B"], [12970, 1, "\u5B97"], [12971, 1, "\u5B66"], [12972, 1, "\u76E3"], [12973, 1, "\u4F01"], [12974, 1, "\u8CC7"], [12975, 1, "\u5354"], [12976, 1, "\u591C"], [12977, 1, "36"], [12978, 1, "37"], [12979, 1, "38"], [12980, 1, "39"], [12981, 1, "40"], [12982, 1, "41"], [12983, 1, "42"], [12984, 1, "43"], [12985, 1, "44"], [12986, 1, "45"], [12987, 1, "46"], [12988, 1, "47"], [12989, 1, "48"], [12990, 1, "49"], [12991, 1, "50"], [12992, 1, "1\u6708"], [12993, 1, "2\u6708"], [12994, 1, "3\u6708"], [12995, 1, "4\u6708"], [12996, 1, "5\u6708"], [12997, 1, "6\u6708"], [12998, 1, "7\u6708"], [12999, 1, "8\u6708"], [13e3, 1, "9\u6708"], [13001, 1, "10\u6708"], [13002, 1, "11\u6708"], [13003, 1, "12\u6708"], [13004, 1, "hg"], [13005, 1, "erg"], [13006, 1, "ev"], [13007, 1, "ltd"], [13008, 1, "\u30A2"], [13009, 1, "\u30A4"], [13010, 1, "\u30A6"], [13011, 1, "\u30A8"], [13012, 1, "\u30AA"], [13013, 1, "\u30AB"], [13014, 1, "\u30AD"], [13015, 1, "\u30AF"], [13016, 1, "\u30B1"], [13017, 1, "\u30B3"], [13018, 1, "\u30B5"], [13019, 1, "\u30B7"], [13020, 1, "\u30B9"], [13021, 1, "\u30BB"], [13022, 1, "\u30BD"], [13023, 1, "\u30BF"], [13024, 1, "\u30C1"], [13025, 1, "\u30C4"], [13026, 1, "\u30C6"], [13027, 1, "\u30C8"], [13028, 1, "\u30CA"], [13029, 1, "\u30CB"], [13030, 1, "\u30CC"], [13031, 1, "\u30CD"], [13032, 1, "\u30CE"], [13033, 1, "\u30CF"], [13034, 1, "\u30D2"], [13035, 1, "\u30D5"], [13036, 1, "\u30D8"], [13037, 1, "\u30DB"], [13038, 1, "\u30DE"], [13039, 1, "\u30DF"], [13040, 1, "\u30E0"], [13041, 1, "\u30E1"], [13042, 1, "\u30E2"], [13043, 1, "\u30E4"], [13044, 1, "\u30E6"], [13045, 1, "\u30E8"], [13046, 1, "\u30E9"], [13047, 1, "\u30EA"], [13048, 1, "\u30EB"], [13049, 1, "\u30EC"], [13050, 1, "\u30ED"], [13051, 1, "\u30EF"], [13052, 1, "\u30F0"], [13053, 1, "\u30F1"], [13054, 1, "\u30F2"], [13055, 1, "\u4EE4\u548C"], [13056, 1, "\u30A2\u30D1\u30FC\u30C8"], [13057, 1, "\u30A2\u30EB\u30D5\u30A1"], [13058, 1, "\u30A2\u30F3\u30DA\u30A2"], [13059, 1, "\u30A2\u30FC\u30EB"], [13060, 1, "\u30A4\u30CB\u30F3\u30B0"], [13061, 1, "\u30A4\u30F3\u30C1"], [13062, 1, "\u30A6\u30A9\u30F3"], [13063, 1, "\u30A8\u30B9\u30AF\u30FC\u30C9"], [13064, 1, "\u30A8\u30FC\u30AB\u30FC"], [13065, 1, "\u30AA\u30F3\u30B9"], [13066, 1, "\u30AA\u30FC\u30E0"], [13067, 1, "\u30AB\u30A4\u30EA"], [13068, 1, "\u30AB\u30E9\u30C3\u30C8"], [13069, 1, "\u30AB\u30ED\u30EA\u30FC"], [13070, 1, "\u30AC\u30ED\u30F3"], [13071, 1, "\u30AC\u30F3\u30DE"], [13072, 1, "\u30AE\u30AC"], [13073, 1, "\u30AE\u30CB\u30FC"], [13074, 1, "\u30AD\u30E5\u30EA\u30FC"], [13075, 1, "\u30AE\u30EB\u30C0\u30FC"], [13076, 1, "\u30AD\u30ED"], [13077, 1, "\u30AD\u30ED\u30B0\u30E9\u30E0"], [13078, 1, "\u30AD\u30ED\u30E1\u30FC\u30C8\u30EB"], [13079, 1, "\u30AD\u30ED\u30EF\u30C3\u30C8"], [13080, 1, "\u30B0\u30E9\u30E0"], [13081, 1, "\u30B0\u30E9\u30E0\u30C8\u30F3"], [13082, 1, "\u30AF\u30EB\u30BC\u30A4\u30ED"], [13083, 1, "\u30AF\u30ED\u30FC\u30CD"], [13084, 1, "\u30B1\u30FC\u30B9"], [13085, 1, "\u30B3\u30EB\u30CA"], [13086, 1, "\u30B3\u30FC\u30DD"], [13087, 1, "\u30B5\u30A4\u30AF\u30EB"], [13088, 1, "\u30B5\u30F3\u30C1\u30FC\u30E0"], [13089, 1, "\u30B7\u30EA\u30F3\u30B0"], [13090, 1, "\u30BB\u30F3\u30C1"], [13091, 1, "\u30BB\u30F3\u30C8"], [13092, 1, "\u30C0\u30FC\u30B9"], [13093, 1, "\u30C7\u30B7"], [13094, 1, "\u30C9\u30EB"], [13095, 1, "\u30C8\u30F3"], [13096, 1, "\u30CA\u30CE"], [13097, 1, "\u30CE\u30C3\u30C8"], [13098, 1, "\u30CF\u30A4\u30C4"], [13099, 1, "\u30D1\u30FC\u30BB\u30F3\u30C8"], [13100, 1, "\u30D1\u30FC\u30C4"], [13101, 1, "\u30D0\u30FC\u30EC\u30EB"], [13102, 1, "\u30D4\u30A2\u30B9\u30C8\u30EB"], [13103, 1, "\u30D4\u30AF\u30EB"], [13104, 1, "\u30D4\u30B3"], [13105, 1, "\u30D3\u30EB"], [13106, 1, "\u30D5\u30A1\u30E9\u30C3\u30C9"], [13107, 1, "\u30D5\u30A3\u30FC\u30C8"], [13108, 1, "\u30D6\u30C3\u30B7\u30A7\u30EB"], [13109, 1, "\u30D5\u30E9\u30F3"], [13110, 1, "\u30D8\u30AF\u30BF\u30FC\u30EB"], [13111, 1, "\u30DA\u30BD"], [13112, 1, "\u30DA\u30CB\u30D2"], [13113, 1, "\u30D8\u30EB\u30C4"], [13114, 1, "\u30DA\u30F3\u30B9"], [13115, 1, "\u30DA\u30FC\u30B8"], [13116, 1, "\u30D9\u30FC\u30BF"], [13117, 1, "\u30DD\u30A4\u30F3\u30C8"], [13118, 1, "\u30DC\u30EB\u30C8"], [13119, 1, "\u30DB\u30F3"], [13120, 1, "\u30DD\u30F3\u30C9"], [13121, 1, "\u30DB\u30FC\u30EB"], [13122, 1, "\u30DB\u30FC\u30F3"], [13123, 1, "\u30DE\u30A4\u30AF\u30ED"], [13124, 1, "\u30DE\u30A4\u30EB"], [13125, 1, "\u30DE\u30C3\u30CF"], [13126, 1, "\u30DE\u30EB\u30AF"], [13127, 1, "\u30DE\u30F3\u30B7\u30E7\u30F3"], [13128, 1, "\u30DF\u30AF\u30ED\u30F3"], [13129, 1, "\u30DF\u30EA"], [13130, 1, "\u30DF\u30EA\u30D0\u30FC\u30EB"], [13131, 1, "\u30E1\u30AC"], [13132, 1, "\u30E1\u30AC\u30C8\u30F3"], [13133, 1, "\u30E1\u30FC\u30C8\u30EB"], [13134, 1, "\u30E4\u30FC\u30C9"], [13135, 1, "\u30E4\u30FC\u30EB"], [13136, 1, "\u30E6\u30A2\u30F3"], [13137, 1, "\u30EA\u30C3\u30C8\u30EB"], [13138, 1, "\u30EA\u30E9"], [13139, 1, "\u30EB\u30D4\u30FC"], [13140, 1, "\u30EB\u30FC\u30D6\u30EB"], [13141, 1, "\u30EC\u30E0"], [13142, 1, "\u30EC\u30F3\u30C8\u30B2\u30F3"], [13143, 1, "\u30EF\u30C3\u30C8"], [13144, 1, "0\u70B9"], [13145, 1, "1\u70B9"], [13146, 1, "2\u70B9"], [13147, 1, "3\u70B9"], [13148, 1, "4\u70B9"], [13149, 1, "5\u70B9"], [13150, 1, "6\u70B9"], [13151, 1, "7\u70B9"], [13152, 1, "8\u70B9"], [13153, 1, "9\u70B9"], [13154, 1, "10\u70B9"], [13155, 1, "11\u70B9"], [13156, 1, "12\u70B9"], [13157, 1, "13\u70B9"], [13158, 1, "14\u70B9"], [13159, 1, "15\u70B9"], [13160, 1, "16\u70B9"], [13161, 1, "17\u70B9"], [13162, 1, "18\u70B9"], [13163, 1, "19\u70B9"], [13164, 1, "20\u70B9"], [13165, 1, "21\u70B9"], [13166, 1, "22\u70B9"], [13167, 1, "23\u70B9"], [13168, 1, "24\u70B9"], [13169, 1, "hpa"], [13170, 1, "da"], [13171, 1, "au"], [13172, 1, "bar"], [13173, 1, "ov"], [13174, 1, "pc"], [13175, 1, "dm"], [13176, 1, "dm2"], [13177, 1, "dm3"], [13178, 1, "iu"], [13179, 1, "\u5E73\u6210"], [13180, 1, "\u662D\u548C"], [13181, 1, "\u5927\u6B63"], [13182, 1, "\u660E\u6CBB"], [13183, 1, "\u682A\u5F0F\u4F1A\u793E"], [13184, 1, "pa"], [13185, 1, "na"], [13186, 1, "\u03BCa"], [13187, 1, "ma"], [13188, 1, "ka"], [13189, 1, "kb"], [13190, 1, "mb"], [13191, 1, "gb"], [13192, 1, "cal"], [13193, 1, "kcal"], [13194, 1, "pf"], [13195, 1, "nf"], [13196, 1, "\u03BCf"], [13197, 1, "\u03BCg"], [13198, 1, "mg"], [13199, 1, "kg"], [13200, 1, "hz"], [13201, 1, "khz"], [13202, 1, "mhz"], [13203, 1, "ghz"], [13204, 1, "thz"], [13205, 1, "\u03BCl"], [13206, 1, "ml"], [13207, 1, "dl"], [13208, 1, "kl"], [13209, 1, "fm"], [13210, 1, "nm"], [13211, 1, "\u03BCm"], [13212, 1, "mm"], [13213, 1, "cm"], [13214, 1, "km"], [13215, 1, "mm2"], [13216, 1, "cm2"], [13217, 1, "m2"], [13218, 1, "km2"], [13219, 1, "mm3"], [13220, 1, "cm3"], [13221, 1, "m3"], [13222, 1, "km3"], [13223, 1, "m\u2215s"], [13224, 1, "m\u2215s2"], [13225, 1, "pa"], [13226, 1, "kpa"], [13227, 1, "mpa"], [13228, 1, "gpa"], [13229, 1, "rad"], [13230, 1, "rad\u2215s"], [13231, 1, "rad\u2215s2"], [13232, 1, "ps"], [13233, 1, "ns"], [13234, 1, "\u03BCs"], [13235, 1, "ms"], [13236, 1, "pv"], [13237, 1, "nv"], [13238, 1, "\u03BCv"], [13239, 1, "mv"], [13240, 1, "kv"], [13241, 1, "mv"], [13242, 1, "pw"], [13243, 1, "nw"], [13244, 1, "\u03BCw"], [13245, 1, "mw"], [13246, 1, "kw"], [13247, 1, "mw"], [13248, 1, "k\u03C9"], [13249, 1, "m\u03C9"], [13250, 3], [13251, 1, "bq"], [13252, 1, "cc"], [13253, 1, "cd"], [13254, 1, "c\u2215kg"], [13255, 3], [13256, 1, "db"], [13257, 1, "gy"], [13258, 1, "ha"], [13259, 1, "hp"], [13260, 1, "in"], [13261, 1, "kk"], [13262, 1, "km"], [13263, 1, "kt"], [13264, 1, "lm"], [13265, 1, "ln"], [13266, 1, "log"], [13267, 1, "lx"], [13268, 1, "mb"], [13269, 1, "mil"], [13270, 1, "mol"], [13271, 1, "ph"], [13272, 3], [13273, 1, "ppm"], [13274, 1, "pr"], [13275, 1, "sr"], [13276, 1, "sv"], [13277, 1, "wb"], [13278, 1, "v\u2215m"], [13279, 1, "a\u2215m"], [13280, 1, "1\u65E5"], [13281, 1, "2\u65E5"], [13282, 1, "3\u65E5"], [13283, 1, "4\u65E5"], [13284, 1, "5\u65E5"], [13285, 1, "6\u65E5"], [13286, 1, "7\u65E5"], [13287, 1, "8\u65E5"], [13288, 1, "9\u65E5"], [13289, 1, "10\u65E5"], [13290, 1, "11\u65E5"], [13291, 1, "12\u65E5"], [13292, 1, "13\u65E5"], [13293, 1, "14\u65E5"], [13294, 1, "15\u65E5"], [13295, 1, "16\u65E5"], [13296, 1, "17\u65E5"], [13297, 1, "18\u65E5"], [13298, 1, "19\u65E5"], [13299, 1, "20\u65E5"], [13300, 1, "21\u65E5"], [13301, 1, "22\u65E5"], [13302, 1, "23\u65E5"], [13303, 1, "24\u65E5"], [13304, 1, "25\u65E5"], [13305, 1, "26\u65E5"], [13306, 1, "27\u65E5"], [13307, 1, "28\u65E5"], [13308, 1, "29\u65E5"], [13309, 1, "30\u65E5"], [13310, 1, "31\u65E5"], [13311, 1, "gal"], [[13312, 19893], 2], [[19894, 19903], 2], [[19904, 19967], 2], [[19968, 40869], 2], [[40870, 40891], 2], [[40892, 40899], 2], [[40900, 40907], 2], [40908, 2], [[40909, 40917], 2], [[40918, 40938], 2], [[40939, 40943], 2], [[40944, 40956], 2], [[40957, 40959], 2], [[40960, 42124], 2], [[42125, 42127], 3], [[42128, 42145], 2], [[42146, 42147], 2], [[42148, 42163], 2], [42164, 2], [[42165, 42176], 2], [42177, 2], [[42178, 42180], 2], [42181, 2], [42182, 2], [[42183, 42191], 3], [[42192, 42237], 2], [[42238, 42239], 2], [[42240, 42508], 2], [[42509, 42511], 2], [[42512, 42539], 2], [[42540, 42559], 3], [42560, 1, "\uA641"], [42561, 2], [42562, 1, "\uA643"], [42563, 2], [42564, 1, "\uA645"], [42565, 2], [42566, 1, "\uA647"], [42567, 2], [42568, 1, "\uA649"], [42569, 2], [42570, 1, "\uA64B"], [42571, 2], [42572, 1, "\uA64D"], [42573, 2], [42574, 1, "\uA64F"], [42575, 2], [42576, 1, "\uA651"], [42577, 2], [42578, 1, "\uA653"], [42579, 2], [42580, 1, "\uA655"], [42581, 2], [42582, 1, "\uA657"], [42583, 2], [42584, 1, "\uA659"], [42585, 2], [42586, 1, "\uA65B"], [42587, 2], [42588, 1, "\uA65D"], [42589, 2], [42590, 1, "\uA65F"], [42591, 2], [42592, 1, "\uA661"], [42593, 2], [42594, 1, "\uA663"], [42595, 2], [42596, 1, "\uA665"], [42597, 2], [42598, 1, "\uA667"], [42599, 2], [42600, 1, "\uA669"], [42601, 2], [42602, 1, "\uA66B"], [42603, 2], [42604, 1, "\uA66D"], [[42605, 42607], 2], [[42608, 42611], 2], [[42612, 42619], 2], [[42620, 42621], 2], [42622, 2], [42623, 2], [42624, 1, "\uA681"], [42625, 2], [42626, 1, "\uA683"], [42627, 2], [42628, 1, "\uA685"], [42629, 2], [42630, 1, "\uA687"], [42631, 2], [42632, 1, "\uA689"], [42633, 2], [42634, 1, "\uA68B"], [42635, 2], [42636, 1, "\uA68D"], [42637, 2], [42638, 1, "\uA68F"], [42639, 2], [42640, 1, "\uA691"], [42641, 2], [42642, 1, "\uA693"], [42643, 2], [42644, 1, "\uA695"], [42645, 2], [42646, 1, "\uA697"], [42647, 2], [42648, 1, "\uA699"], [42649, 2], [42650, 1, "\uA69B"], [42651, 2], [42652, 1, "\u044A"], [42653, 1, "\u044C"], [42654, 2], [42655, 2], [[42656, 42725], 2], [[42726, 42735], 2], [[42736, 42737], 2], [[42738, 42743], 2], [[42744, 42751], 3], [[42752, 42774], 2], [[42775, 42778], 2], [[42779, 42783], 2], [[42784, 42785], 2], [42786, 1, "\uA723"], [42787, 2], [42788, 1, "\uA725"], [42789, 2], [42790, 1, "\uA727"], [42791, 2], [42792, 1, "\uA729"], [42793, 2], [42794, 1, "\uA72B"], [42795, 2], [42796, 1, "\uA72D"], [42797, 2], [42798, 1, "\uA72F"], [[42799, 42801], 2], [42802, 1, "\uA733"], [42803, 2], [42804, 1, "\uA735"], [42805, 2], [42806, 1, "\uA737"], [42807, 2], [42808, 1, "\uA739"], [42809, 2], [42810, 1, "\uA73B"], [42811, 2], [42812, 1, "\uA73D"], [42813, 2], [42814, 1, "\uA73F"], [42815, 2], [42816, 1, "\uA741"], [42817, 2], [42818, 1, "\uA743"], [42819, 2], [42820, 1, "\uA745"], [42821, 2], [42822, 1, "\uA747"], [42823, 2], [42824, 1, "\uA749"], [42825, 2], [42826, 1, "\uA74B"], [42827, 2], [42828, 1, "\uA74D"], [42829, 2], [42830, 1, "\uA74F"], [42831, 2], [42832, 1, "\uA751"], [42833, 2], [42834, 1, "\uA753"], [42835, 2], [42836, 1, "\uA755"], [42837, 2], [42838, 1, "\uA757"], [42839, 2], [42840, 1, "\uA759"], [42841, 2], [42842, 1, "\uA75B"], [42843, 2], [42844, 1, "\uA75D"], [42845, 2], [42846, 1, "\uA75F"], [42847, 2], [42848, 1, "\uA761"], [42849, 2], [42850, 1, "\uA763"], [42851, 2], [42852, 1, "\uA765"], [42853, 2], [42854, 1, "\uA767"], [42855, 2], [42856, 1, "\uA769"], [42857, 2], [42858, 1, "\uA76B"], [42859, 2], [42860, 1, "\uA76D"], [42861, 2], [42862, 1, "\uA76F"], [42863, 2], [42864, 1, "\uA76F"], [[42865, 42872], 2], [42873, 1, "\uA77A"], [42874, 2], [42875, 1, "\uA77C"], [42876, 2], [42877, 1, "\u1D79"], [42878, 1, "\uA77F"], [42879, 2], [42880, 1, "\uA781"], [42881, 2], [42882, 1, "\uA783"], [42883, 2], [42884, 1, "\uA785"], [42885, 2], [42886, 1, "\uA787"], [[42887, 42888], 2], [[42889, 42890], 2], [42891, 1, "\uA78C"], [42892, 2], [42893, 1, "\u0265"], [42894, 2], [42895, 2], [42896, 1, "\uA791"], [42897, 2], [42898, 1, "\uA793"], [42899, 2], [[42900, 42901], 2], [42902, 1, "\uA797"], [42903, 2], [42904, 1, "\uA799"], [42905, 2], [42906, 1, "\uA79B"], [42907, 2], [42908, 1, "\uA79D"], [42909, 2], [42910, 1, "\uA79F"], [42911, 2], [42912, 1, "\uA7A1"], [42913, 2], [42914, 1, "\uA7A3"], [42915, 2], [42916, 1, "\uA7A5"], [42917, 2], [42918, 1, "\uA7A7"], [42919, 2], [42920, 1, "\uA7A9"], [42921, 2], [42922, 1, "\u0266"], [42923, 1, "\u025C"], [42924, 1, "\u0261"], [42925, 1, "\u026C"], [42926, 1, "\u026A"], [42927, 2], [42928, 1, "\u029E"], [42929, 1, "\u0287"], [42930, 1, "\u029D"], [42931, 1, "\uAB53"], [42932, 1, "\uA7B5"], [42933, 2], [42934, 1, "\uA7B7"], [42935, 2], [42936, 1, "\uA7B9"], [42937, 2], [42938, 1, "\uA7BB"], [42939, 2], [42940, 1, "\uA7BD"], [42941, 2], [42942, 1, "\uA7BF"], [42943, 2], [42944, 1, "\uA7C1"], [42945, 2], [42946, 1, "\uA7C3"], [42947, 2], [42948, 1, "\uA794"], [42949, 1, "\u0282"], [42950, 1, "\u1D8E"], [42951, 1, "\uA7C8"], [42952, 2], [42953, 1, "\uA7CA"], [42954, 2], [[42955, 42959], 3], [42960, 1, "\uA7D1"], [42961, 2], [42962, 3], [42963, 2], [42964, 3], [42965, 2], [42966, 1, "\uA7D7"], [42967, 2], [42968, 1, "\uA7D9"], [42969, 2], [[42970, 42993], 3], [42994, 1, "c"], [42995, 1, "f"], [42996, 1, "q"], [42997, 1, "\uA7F6"], [42998, 2], [42999, 2], [43e3, 1, "\u0127"], [43001, 1, "\u0153"], [43002, 2], [[43003, 43007], 2], [[43008, 43047], 2], [[43048, 43051], 2], [43052, 2], [[43053, 43055], 3], [[43056, 43065], 2], [[43066, 43071], 3], [[43072, 43123], 2], [[43124, 43127], 2], [[43128, 43135], 3], [[43136, 43204], 2], [43205, 2], [[43206, 43213], 3], [[43214, 43215], 2], [[43216, 43225], 2], [[43226, 43231], 3], [[43232, 43255], 2], [[43256, 43258], 2], [43259, 2], [43260, 2], [43261, 2], [[43262, 43263], 2], [[43264, 43309], 2], [[43310, 43311], 2], [[43312, 43347], 2], [[43348, 43358], 3], [43359, 2], [[43360, 43388], 2], [[43389, 43391], 3], [[43392, 43456], 2], [[43457, 43469], 2], [43470, 3], [[43471, 43481], 2], [[43482, 43485], 3], [[43486, 43487], 2], [[43488, 43518], 2], [43519, 3], [[43520, 43574], 2], [[43575, 43583], 3], [[43584, 43597], 2], [[43598, 43599], 3], [[43600, 43609], 2], [[43610, 43611], 3], [[43612, 43615], 2], [[43616, 43638], 2], [[43639, 43641], 2], [[43642, 43643], 2], [[43644, 43647], 2], [[43648, 43714], 2], [[43715, 43738], 3], [[43739, 43741], 2], [[43742, 43743], 2], [[43744, 43759], 2], [[43760, 43761], 2], [[43762, 43766], 2], [[43767, 43776], 3], [[43777, 43782], 2], [[43783, 43784], 3], [[43785, 43790], 2], [[43791, 43792], 3], [[43793, 43798], 2], [[43799, 43807], 3], [[43808, 43814], 2], [43815, 3], [[43816, 43822], 2], [43823, 3], [[43824, 43866], 2], [43867, 2], [43868, 1, "\uA727"], [43869, 1, "\uAB37"], [43870, 1, "\u026B"], [43871, 1, "\uAB52"], [[43872, 43875], 2], [[43876, 43877], 2], [[43878, 43879], 2], [43880, 2], [43881, 1, "\u028D"], [[43882, 43883], 2], [[43884, 43887], 3], [43888, 1, "\u13A0"], [43889, 1, "\u13A1"], [43890, 1, "\u13A2"], [43891, 1, "\u13A3"], [43892, 1, "\u13A4"], [43893, 1, "\u13A5"], [43894, 1, "\u13A6"], [43895, 1, "\u13A7"], [43896, 1, "\u13A8"], [43897, 1, "\u13A9"], [43898, 1, "\u13AA"], [43899, 1, "\u13AB"], [43900, 1, "\u13AC"], [43901, 1, "\u13AD"], [43902, 1, "\u13AE"], [43903, 1, "\u13AF"], [43904, 1, "\u13B0"], [43905, 1, "\u13B1"], [43906, 1, "\u13B2"], [43907, 1, "\u13B3"], [43908, 1, "\u13B4"], [43909, 1, "\u13B5"], [43910, 1, "\u13B6"], [43911, 1, "\u13B7"], [43912, 1, "\u13B8"], [43913, 1, "\u13B9"], [43914, 1, "\u13BA"], [43915, 1, "\u13BB"], [43916, 1, "\u13BC"], [43917, 1, "\u13BD"], [43918, 1, "\u13BE"], [43919, 1, "\u13BF"], [43920, 1, "\u13C0"], [43921, 1, "\u13C1"], [43922, 1, "\u13C2"], [43923, 1, "\u13C3"], [43924, 1, "\u13C4"], [43925, 1, "\u13C5"], [43926, 1, "\u13C6"], [43927, 1, "\u13C7"], [43928, 1, "\u13C8"], [43929, 1, "\u13C9"], [43930, 1, "\u13CA"], [43931, 1, "\u13CB"], [43932, 1, "\u13CC"], [43933, 1, "\u13CD"], [43934, 1, "\u13CE"], [43935, 1, "\u13CF"], [43936, 1, "\u13D0"], [43937, 1, "\u13D1"], [43938, 1, "\u13D2"], [43939, 1, "\u13D3"], [43940, 1, "\u13D4"], [43941, 1, "\u13D5"], [43942, 1, "\u13D6"], [43943, 1, "\u13D7"], [43944, 1, "\u13D8"], [43945, 1, "\u13D9"], [43946, 1, "\u13DA"], [43947, 1, "\u13DB"], [43948, 1, "\u13DC"], [43949, 1, "\u13DD"], [43950, 1, "\u13DE"], [43951, 1, "\u13DF"], [43952, 1, "\u13E0"], [43953, 1, "\u13E1"], [43954, 1, "\u13E2"], [43955, 1, "\u13E3"], [43956, 1, "\u13E4"], [43957, 1, "\u13E5"], [43958, 1, "\u13E6"], [43959, 1, "\u13E7"], [43960, 1, "\u13E8"], [43961, 1, "\u13E9"], [43962, 1, "\u13EA"], [43963, 1, "\u13EB"], [43964, 1, "\u13EC"], [43965, 1, "\u13ED"], [43966, 1, "\u13EE"], [43967, 1, "\u13EF"], [[43968, 44010], 2], [44011, 2], [[44012, 44013], 2], [[44014, 44015], 3], [[44016, 44025], 2], [[44026, 44031], 3], [[44032, 55203], 2], [[55204, 55215], 3], [[55216, 55238], 2], [[55239, 55242], 3], [[55243, 55291], 2], [[55292, 55295], 3], [[55296, 57343], 3], [[57344, 63743], 3], [63744, 1, "\u8C48"], [63745, 1, "\u66F4"], [63746, 1, "\u8ECA"], [63747, 1, "\u8CC8"], [63748, 1, "\u6ED1"], [63749, 1, "\u4E32"], [63750, 1, "\u53E5"], [[63751, 63752], 1, "\u9F9C"], [63753, 1, "\u5951"], [63754, 1, "\u91D1"], [63755, 1, "\u5587"], [63756, 1, "\u5948"], [63757, 1, "\u61F6"], [63758, 1, "\u7669"], [63759, 1, "\u7F85"], [63760, 1, "\u863F"], [63761, 1, "\u87BA"], [63762, 1, "\u88F8"], [63763, 1, "\u908F"], [63764, 1, "\u6A02"], [63765, 1, "\u6D1B"], [63766, 1, "\u70D9"], [63767, 1, "\u73DE"], [63768, 1, "\u843D"], [63769, 1, "\u916A"], [63770, 1, "\u99F1"], [63771, 1, "\u4E82"], [63772, 1, "\u5375"], [63773, 1, "\u6B04"], [63774, 1, "\u721B"], [63775, 1, "\u862D"], [63776, 1, "\u9E1E"], [63777, 1, "\u5D50"], [63778, 1, "\u6FEB"], [63779, 1, "\u85CD"], [63780, 1, "\u8964"], [63781, 1, "\u62C9"], [63782, 1, "\u81D8"], [63783, 1, "\u881F"], [63784, 1, "\u5ECA"], [63785, 1, "\u6717"], [63786, 1, "\u6D6A"], [63787, 1, "\u72FC"], [63788, 1, "\u90CE"], [63789, 1, "\u4F86"], [63790, 1, "\u51B7"], [63791, 1, "\u52DE"], [63792, 1, "\u64C4"], [63793, 1, "\u6AD3"], [63794, 1, "\u7210"], [63795, 1, "\u76E7"], [63796, 1, "\u8001"], [63797, 1, "\u8606"], [63798, 1, "\u865C"], [63799, 1, "\u8DEF"], [63800, 1, "\u9732"], [63801, 1, "\u9B6F"], [63802, 1, "\u9DFA"], [63803, 1, "\u788C"], [63804, 1, "\u797F"], [63805, 1, "\u7DA0"], [63806, 1, "\u83C9"], [63807, 1, "\u9304"], [63808, 1, "\u9E7F"], [63809, 1, "\u8AD6"], [63810, 1, "\u58DF"], [63811, 1, "\u5F04"], [63812, 1, "\u7C60"], [63813, 1, "\u807E"], [63814, 1, "\u7262"], [63815, 1, "\u78CA"], [63816, 1, "\u8CC2"], [63817, 1, "\u96F7"], [63818, 1, "\u58D8"], [63819, 1, "\u5C62"], [63820, 1, "\u6A13"], [63821, 1, "\u6DDA"], [63822, 1, "\u6F0F"], [63823, 1, "\u7D2F"], [63824, 1, "\u7E37"], [63825, 1, "\u964B"], [63826, 1, "\u52D2"], [63827, 1, "\u808B"], [63828, 1, "\u51DC"], [63829, 1, "\u51CC"], [63830, 1, "\u7A1C"], [63831, 1, "\u7DBE"], [63832, 1, "\u83F1"], [63833, 1, "\u9675"], [63834, 1, "\u8B80"], [63835, 1, "\u62CF"], [63836, 1, "\u6A02"], [63837, 1, "\u8AFE"], [63838, 1, "\u4E39"], [63839, 1, "\u5BE7"], [63840, 1, "\u6012"], [63841, 1, "\u7387"], [63842, 1, "\u7570"], [63843, 1, "\u5317"], [63844, 1, "\u78FB"], [63845, 1, "\u4FBF"], [63846, 1, "\u5FA9"], [63847, 1, "\u4E0D"], [63848, 1, "\u6CCC"], [63849, 1, "\u6578"], [63850, 1, "\u7D22"], [63851, 1, "\u53C3"], [63852, 1, "\u585E"], [63853, 1, "\u7701"], [63854, 1, "\u8449"], [63855, 1, "\u8AAA"], [63856, 1, "\u6BBA"], [63857, 1, "\u8FB0"], [63858, 1, "\u6C88"], [63859, 1, "\u62FE"], [63860, 1, "\u82E5"], [63861, 1, "\u63A0"], [63862, 1, "\u7565"], [63863, 1, "\u4EAE"], [63864, 1, "\u5169"], [63865, 1, "\u51C9"], [63866, 1, "\u6881"], [63867, 1, "\u7CE7"], [63868, 1, "\u826F"], [63869, 1, "\u8AD2"], [63870, 1, "\u91CF"], [63871, 1, "\u52F5"], [63872, 1, "\u5442"], [63873, 1, "\u5973"], [63874, 1, "\u5EEC"], [63875, 1, "\u65C5"], [63876, 1, "\u6FFE"], [63877, 1, "\u792A"], [63878, 1, "\u95AD"], [63879, 1, "\u9A6A"], [63880, 1, "\u9E97"], [63881, 1, "\u9ECE"], [63882, 1, "\u529B"], [63883, 1, "\u66C6"], [63884, 1, "\u6B77"], [63885, 1, "\u8F62"], [63886, 1, "\u5E74"], [63887, 1, "\u6190"], [63888, 1, "\u6200"], [63889, 1, "\u649A"], [63890, 1, "\u6F23"], [63891, 1, "\u7149"], [63892, 1, "\u7489"], [63893, 1, "\u79CA"], [63894, 1, "\u7DF4"], [63895, 1, "\u806F"], [63896, 1, "\u8F26"], [63897, 1, "\u84EE"], [63898, 1, "\u9023"], [63899, 1, "\u934A"], [63900, 1, "\u5217"], [63901, 1, "\u52A3"], [63902, 1, "\u54BD"], [63903, 1, "\u70C8"], [63904, 1, "\u88C2"], [63905, 1, "\u8AAA"], [63906, 1, "\u5EC9"], [63907, 1, "\u5FF5"], [63908, 1, "\u637B"], [63909, 1, "\u6BAE"], [63910, 1, "\u7C3E"], [63911, 1, "\u7375"], [63912, 1, "\u4EE4"], [63913, 1, "\u56F9"], [63914, 1, "\u5BE7"], [63915, 1, "\u5DBA"], [63916, 1, "\u601C"], [63917, 1, "\u73B2"], [63918, 1, "\u7469"], [63919, 1, "\u7F9A"], [63920, 1, "\u8046"], [63921, 1, "\u9234"], [63922, 1, "\u96F6"], [63923, 1, "\u9748"], [63924, 1, "\u9818"], [63925, 1, "\u4F8B"], [63926, 1, "\u79AE"], [63927, 1, "\u91B4"], [63928, 1, "\u96B8"], [63929, 1, "\u60E1"], [63930, 1, "\u4E86"], [63931, 1, "\u50DA"], [63932, 1, "\u5BEE"], [63933, 1, "\u5C3F"], [63934, 1, "\u6599"], [63935, 1, "\u6A02"], [63936, 1, "\u71CE"], [63937, 1, "\u7642"], [63938, 1, "\u84FC"], [63939, 1, "\u907C"], [63940, 1, "\u9F8D"], [63941, 1, "\u6688"], [63942, 1, "\u962E"], [63943, 1, "\u5289"], [63944, 1, "\u677B"], [63945, 1, "\u67F3"], [63946, 1, "\u6D41"], [63947, 1, "\u6E9C"], [63948, 1, "\u7409"], [63949, 1, "\u7559"], [63950, 1, "\u786B"], [63951, 1, "\u7D10"], [63952, 1, "\u985E"], [63953, 1, "\u516D"], [63954, 1, "\u622E"], [63955, 1, "\u9678"], [63956, 1, "\u502B"], [63957, 1, "\u5D19"], [63958, 1, "\u6DEA"], [63959, 1, "\u8F2A"], [63960, 1, "\u5F8B"], [63961, 1, "\u6144"], [63962, 1, "\u6817"], [63963, 1, "\u7387"], [63964, 1, "\u9686"], [63965, 1, "\u5229"], [63966, 1, "\u540F"], [63967, 1, "\u5C65"], [63968, 1, "\u6613"], [63969, 1, "\u674E"], [63970, 1, "\u68A8"], [63971, 1, "\u6CE5"], [63972, 1, "\u7406"], [63973, 1, "\u75E2"], [63974, 1, "\u7F79"], [63975, 1, "\u88CF"], [63976, 1, "\u88E1"], [63977, 1, "\u91CC"], [63978, 1, "\u96E2"], [63979, 1, "\u533F"], [63980, 1, "\u6EBA"], [63981, 1, "\u541D"], [63982, 1, "\u71D0"], [63983, 1, "\u7498"], [63984, 1, "\u85FA"], [63985, 1, "\u96A3"], [63986, 1, "\u9C57"], [63987, 1, "\u9E9F"], [63988, 1, "\u6797"], [63989, 1, "\u6DCB"], [63990, 1, "\u81E8"], [63991, 1, "\u7ACB"], [63992, 1, "\u7B20"], [63993, 1, "\u7C92"], [63994, 1, "\u72C0"], [63995, 1, "\u7099"], [63996, 1, "\u8B58"], [63997, 1, "\u4EC0"], [63998, 1, "\u8336"], [63999, 1, "\u523A"], [64e3, 1, "\u5207"], [64001, 1, "\u5EA6"], [64002, 1, "\u62D3"], [64003, 1, "\u7CD6"], [64004, 1, "\u5B85"], [64005, 1, "\u6D1E"], [64006, 1, "\u66B4"], [64007, 1, "\u8F3B"], [64008, 1, "\u884C"], [64009, 1, "\u964D"], [64010, 1, "\u898B"], [64011, 1, "\u5ED3"], [64012, 1, "\u5140"], [64013, 1, "\u55C0"], [[64014, 64015], 2], [64016, 1, "\u585A"], [64017, 2], [64018, 1, "\u6674"], [[64019, 64020], 2], [64021, 1, "\u51DE"], [64022, 1, "\u732A"], [64023, 1, "\u76CA"], [64024, 1, "\u793C"], [64025, 1, "\u795E"], [64026, 1, "\u7965"], [64027, 1, "\u798F"], [64028, 1, "\u9756"], [64029, 1, "\u7CBE"], [64030, 1, "\u7FBD"], [64031, 2], [64032, 1, "\u8612"], [64033, 2], [64034, 1, "\u8AF8"], [[64035, 64036], 2], [64037, 1, "\u9038"], [64038, 1, "\u90FD"], [[64039, 64041], 2], [64042, 1, "\u98EF"], [64043, 1, "\u98FC"], [64044, 1, "\u9928"], [64045, 1, "\u9DB4"], [64046, 1, "\u90DE"], [64047, 1, "\u96B7"], [64048, 1, "\u4FAE"], [64049, 1, "\u50E7"], [64050, 1, "\u514D"], [64051, 1, "\u52C9"], [64052, 1, "\u52E4"], [64053, 1, "\u5351"], [64054, 1, "\u559D"], [64055, 1, "\u5606"], [64056, 1, "\u5668"], [64057, 1, "\u5840"], [64058, 1, "\u58A8"], [64059, 1, "\u5C64"], [64060, 1, "\u5C6E"], [64061, 1, "\u6094"], [64062, 1, "\u6168"], [64063, 1, "\u618E"], [64064, 1, "\u61F2"], [64065, 1, "\u654F"], [64066, 1, "\u65E2"], [64067, 1, "\u6691"], [64068, 1, "\u6885"], [64069, 1, "\u6D77"], [64070, 1, "\u6E1A"], [64071, 1, "\u6F22"], [64072, 1, "\u716E"], [64073, 1, "\u722B"], [64074, 1, "\u7422"], [64075, 1, "\u7891"], [64076, 1, "\u793E"], [64077, 1, "\u7949"], [64078, 1, "\u7948"], [64079, 1, "\u7950"], [64080, 1, "\u7956"], [64081, 1, "\u795D"], [64082, 1, "\u798D"], [64083, 1, "\u798E"], [64084, 1, "\u7A40"], [64085, 1, "\u7A81"], [64086, 1, "\u7BC0"], [64087, 1, "\u7DF4"], [64088, 1, "\u7E09"], [64089, 1, "\u7E41"], [64090, 1, "\u7F72"], [64091, 1, "\u8005"], [64092, 1, "\u81ED"], [[64093, 64094], 1, "\u8279"], [64095, 1, "\u8457"], [64096, 1, "\u8910"], [64097, 1, "\u8996"], [64098, 1, "\u8B01"], [64099, 1, "\u8B39"], [64100, 1, "\u8CD3"], [64101, 1, "\u8D08"], [64102, 1, "\u8FB6"], [64103, 1, "\u9038"], [64104, 1, "\u96E3"], [64105, 1, "\u97FF"], [64106, 1, "\u983B"], [64107, 1, "\u6075"], [64108, 1, "\u{242EE}"], [64109, 1, "\u8218"], [[64110, 64111], 3], [64112, 1, "\u4E26"], [64113, 1, "\u51B5"], [64114, 1, "\u5168"], [64115, 1, "\u4F80"], [64116, 1, "\u5145"], [64117, 1, "\u5180"], [64118, 1, "\u52C7"], [64119, 1, "\u52FA"], [64120, 1, "\u559D"], [64121, 1, "\u5555"], [64122, 1, "\u5599"], [64123, 1, "\u55E2"], [64124, 1, "\u585A"], [64125, 1, "\u58B3"], [64126, 1, "\u5944"], [64127, 1, "\u5954"], [64128, 1, "\u5A62"], [64129, 1, "\u5B28"], [64130, 1, "\u5ED2"], [64131, 1, "\u5ED9"], [64132, 1, "\u5F69"], [64133, 1, "\u5FAD"], [64134, 1, "\u60D8"], [64135, 1, "\u614E"], [64136, 1, "\u6108"], [64137, 1, "\u618E"], [64138, 1, "\u6160"], [64139, 1, "\u61F2"], [64140, 1, "\u6234"], [64141, 1, "\u63C4"], [64142, 1, "\u641C"], [64143, 1, "\u6452"], [64144, 1, "\u6556"], [64145, 1, "\u6674"], [64146, 1, "\u6717"], [64147, 1, "\u671B"], [64148, 1, "\u6756"], [64149, 1, "\u6B79"], [64150, 1, "\u6BBA"], [64151, 1, "\u6D41"], [64152, 1, "\u6EDB"], [64153, 1, "\u6ECB"], [64154, 1, "\u6F22"], [64155, 1, "\u701E"], [64156, 1, "\u716E"], [64157, 1, "\u77A7"], [64158, 1, "\u7235"], [64159, 1, "\u72AF"], [64160, 1, "\u732A"], [64161, 1, "\u7471"], [64162, 1, "\u7506"], [64163, 1, "\u753B"], [64164, 1, "\u761D"], [64165, 1, "\u761F"], [64166, 1, "\u76CA"], [64167, 1, "\u76DB"], [64168, 1, "\u76F4"], [64169, 1, "\u774A"], [64170, 1, "\u7740"], [64171, 1, "\u78CC"], [64172, 1, "\u7AB1"], [64173, 1, "\u7BC0"], [64174, 1, "\u7C7B"], [64175, 1, "\u7D5B"], [64176, 1, "\u7DF4"], [64177, 1, "\u7F3E"], [64178, 1, "\u8005"], [64179, 1, "\u8352"], [64180, 1, "\u83EF"], [64181, 1, "\u8779"], [64182, 1, "\u8941"], [64183, 1, "\u8986"], [64184, 1, "\u8996"], [64185, 1, "\u8ABF"], [64186, 1, "\u8AF8"], [64187, 1, "\u8ACB"], [64188, 1, "\u8B01"], [64189, 1, "\u8AFE"], [64190, 1, "\u8AED"], [64191, 1, "\u8B39"], [64192, 1, "\u8B8A"], [64193, 1, "\u8D08"], [64194, 1, "\u8F38"], [64195, 1, "\u9072"], [64196, 1, "\u9199"], [64197, 1, "\u9276"], [64198, 1, "\u967C"], [64199, 1, "\u96E3"], [64200, 1, "\u9756"], [64201, 1, "\u97DB"], [64202, 1, "\u97FF"], [64203, 1, "\u980B"], [64204, 1, "\u983B"], [64205, 1, "\u9B12"], [64206, 1, "\u9F9C"], [64207, 1, "\u{2284A}"], [64208, 1, "\u{22844}"], [64209, 1, "\u{233D5}"], [64210, 1, "\u3B9D"], [64211, 1, "\u4018"], [64212, 1, "\u4039"], [64213, 1, "\u{25249}"], [64214, 1, "\u{25CD0}"], [64215, 1, "\u{27ED3}"], [64216, 1, "\u9F43"], [64217, 1, "\u9F8E"], [[64218, 64255], 3], [64256, 1, "ff"], [64257, 1, "fi"], [64258, 1, "fl"], [64259, 1, "ffi"], [64260, 1, "ffl"], [[64261, 64262], 1, "st"], [[64263, 64274], 3], [64275, 1, "\u0574\u0576"], [64276, 1, "\u0574\u0565"], [64277, 1, "\u0574\u056B"], [64278, 1, "\u057E\u0576"], [64279, 1, "\u0574\u056D"], [[64280, 64284], 3], [64285, 1, "\u05D9\u05B4"], [64286, 2], [64287, 1, "\u05F2\u05B7"], [64288, 1, "\u05E2"], [64289, 1, "\u05D0"], [64290, 1, "\u05D3"], [64291, 1, "\u05D4"], [64292, 1, "\u05DB"], [64293, 1, "\u05DC"], [64294, 1, "\u05DD"], [64295, 1, "\u05E8"], [64296, 1, "\u05EA"], [64297, 5, "+"], [64298, 1, "\u05E9\u05C1"], [64299, 1, "\u05E9\u05C2"], [64300, 1, "\u05E9\u05BC\u05C1"], [64301, 1, "\u05E9\u05BC\u05C2"], [64302, 1, "\u05D0\u05B7"], [64303, 1, "\u05D0\u05B8"], [64304, 1, "\u05D0\u05BC"], [64305, 1, "\u05D1\u05BC"], [64306, 1, "\u05D2\u05BC"], [64307, 1, "\u05D3\u05BC"], [64308, 1, "\u05D4\u05BC"], [64309, 1, "\u05D5\u05BC"], [64310, 1, "\u05D6\u05BC"], [64311, 3], [64312, 1, "\u05D8\u05BC"], [64313, 1, "\u05D9\u05BC"], [64314, 1, "\u05DA\u05BC"], [64315, 1, "\u05DB\u05BC"], [64316, 1, "\u05DC\u05BC"], [64317, 3], [64318, 1, "\u05DE\u05BC"], [64319, 3], [64320, 1, "\u05E0\u05BC"], [64321, 1, "\u05E1\u05BC"], [64322, 3], [64323, 1, "\u05E3\u05BC"], [64324, 1, "\u05E4\u05BC"], [64325, 3], [64326, 1, "\u05E6\u05BC"], [64327, 1, "\u05E7\u05BC"], [64328, 1, "\u05E8\u05BC"], [64329, 1, "\u05E9\u05BC"], [64330, 1, "\u05EA\u05BC"], [64331, 1, "\u05D5\u05B9"], [64332, 1, "\u05D1\u05BF"], [64333, 1, "\u05DB\u05BF"], [64334, 1, "\u05E4\u05BF"], [64335, 1, "\u05D0\u05DC"], [[64336, 64337], 1, "\u0671"], [[64338, 64341], 1, "\u067B"], [[64342, 64345], 1, "\u067E"], [[64346, 64349], 1, "\u0680"], [[64350, 64353], 1, "\u067A"], [[64354, 64357], 1, "\u067F"], [[64358, 64361], 1, "\u0679"], [[64362, 64365], 1, "\u06A4"], [[64366, 64369], 1, "\u06A6"], [[64370, 64373], 1, "\u0684"], [[64374, 64377], 1, "\u0683"], [[64378, 64381], 1, "\u0686"], [[64382, 64385], 1, "\u0687"], [[64386, 64387], 1, "\u068D"], [[64388, 64389], 1, "\u068C"], [[64390, 64391], 1, "\u068E"], [[64392, 64393], 1, "\u0688"], [[64394, 64395], 1, "\u0698"], [[64396, 64397], 1, "\u0691"], [[64398, 64401], 1, "\u06A9"], [[64402, 64405], 1, "\u06AF"], [[64406, 64409], 1, "\u06B3"], [[64410, 64413], 1, "\u06B1"], [[64414, 64415], 1, "\u06BA"], [[64416, 64419], 1, "\u06BB"], [[64420, 64421], 1, "\u06C0"], [[64422, 64425], 1, "\u06C1"], [[64426, 64429], 1, "\u06BE"], [[64430, 64431], 1, "\u06D2"], [[64432, 64433], 1, "\u06D3"], [[64434, 64449], 2], [64450, 2], [[64451, 64466], 3], [[64467, 64470], 1, "\u06AD"], [[64471, 64472], 1, "\u06C7"], [[64473, 64474], 1, "\u06C6"], [[64475, 64476], 1, "\u06C8"], [64477, 1, "\u06C7\u0674"], [[64478, 64479], 1, "\u06CB"], [[64480, 64481], 1, "\u06C5"], [[64482, 64483], 1, "\u06C9"], [[64484, 64487], 1, "\u06D0"], [[64488, 64489], 1, "\u0649"], [[64490, 64491], 1, "\u0626\u0627"], [[64492, 64493], 1, "\u0626\u06D5"], [[64494, 64495], 1, "\u0626\u0648"], [[64496, 64497], 1, "\u0626\u06C7"], [[64498, 64499], 1, "\u0626\u06C6"], [[64500, 64501], 1, "\u0626\u06C8"], [[64502, 64504], 1, "\u0626\u06D0"], [[64505, 64507], 1, "\u0626\u0649"], [[64508, 64511], 1, "\u06CC"], [64512, 1, "\u0626\u062C"], [64513, 1, "\u0626\u062D"], [64514, 1, "\u0626\u0645"], [64515, 1, "\u0626\u0649"], [64516, 1, "\u0626\u064A"], [64517, 1, "\u0628\u062C"], [64518, 1, "\u0628\u062D"], [64519, 1, "\u0628\u062E"], [64520, 1, "\u0628\u0645"], [64521, 1, "\u0628\u0649"], [64522, 1, "\u0628\u064A"], [64523, 1, "\u062A\u062C"], [64524, 1, "\u062A\u062D"], [64525, 1, "\u062A\u062E"], [64526, 1, "\u062A\u0645"], [64527, 1, "\u062A\u0649"], [64528, 1, "\u062A\u064A"], [64529, 1, "\u062B\u062C"], [64530, 1, "\u062B\u0645"], [64531, 1, "\u062B\u0649"], [64532, 1, "\u062B\u064A"], [64533, 1, "\u062C\u062D"], [64534, 1, "\u062C\u0645"], [64535, 1, "\u062D\u062C"], [64536, 1, "\u062D\u0645"], [64537, 1, "\u062E\u062C"], [64538, 1, "\u062E\u062D"], [64539, 1, "\u062E\u0645"], [64540, 1, "\u0633\u062C"], [64541, 1, "\u0633\u062D"], [64542, 1, "\u0633\u062E"], [64543, 1, "\u0633\u0645"], [64544, 1, "\u0635\u062D"], [64545, 1, "\u0635\u0645"], [64546, 1, "\u0636\u062C"], [64547, 1, "\u0636\u062D"], [64548, 1, "\u0636\u062E"], [64549, 1, "\u0636\u0645"], [64550, 1, "\u0637\u062D"], [64551, 1, "\u0637\u0645"], [64552, 1, "\u0638\u0645"], [64553, 1, "\u0639\u062C"], [64554, 1, "\u0639\u0645"], [64555, 1, "\u063A\u062C"], [64556, 1, "\u063A\u0645"], [64557, 1, "\u0641\u062C"], [64558, 1, "\u0641\u062D"], [64559, 1, "\u0641\u062E"], [64560, 1, "\u0641\u0645"], [64561, 1, "\u0641\u0649"], [64562, 1, "\u0641\u064A"], [64563, 1, "\u0642\u062D"], [64564, 1, "\u0642\u0645"], [64565, 1, "\u0642\u0649"], [64566, 1, "\u0642\u064A"], [64567, 1, "\u0643\u0627"], [64568, 1, "\u0643\u062C"], [64569, 1, "\u0643\u062D"], [64570, 1, "\u0643\u062E"], [64571, 1, "\u0643\u0644"], [64572, 1, "\u0643\u0645"], [64573, 1, "\u0643\u0649"], [64574, 1, "\u0643\u064A"], [64575, 1, "\u0644\u062C"], [64576, 1, "\u0644\u062D"], [64577, 1, "\u0644\u062E"], [64578, 1, "\u0644\u0645"], [64579, 1, "\u0644\u0649"], [64580, 1, "\u0644\u064A"], [64581, 1, "\u0645\u062C"], [64582, 1, "\u0645\u062D"], [64583, 1, "\u0645\u062E"], [64584, 1, "\u0645\u0645"], [64585, 1, "\u0645\u0649"], [64586, 1, "\u0645\u064A"], [64587, 1, "\u0646\u062C"], [64588, 1, "\u0646\u062D"], [64589, 1, "\u0646\u062E"], [64590, 1, "\u0646\u0645"], [64591, 1, "\u0646\u0649"], [64592, 1, "\u0646\u064A"], [64593, 1, "\u0647\u062C"], [64594, 1, "\u0647\u0645"], [64595, 1, "\u0647\u0649"], [64596, 1, "\u0647\u064A"], [64597, 1, "\u064A\u062C"], [64598, 1, "\u064A\u062D"], [64599, 1, "\u064A\u062E"], [64600, 1, "\u064A\u0645"], [64601, 1, "\u064A\u0649"], [64602, 1, "\u064A\u064A"], [64603, 1, "\u0630\u0670"], [64604, 1, "\u0631\u0670"], [64605, 1, "\u0649\u0670"], [64606, 5, " \u064C\u0651"], [64607, 5, " \u064D\u0651"], [64608, 5, " \u064E\u0651"], [64609, 5, " \u064F\u0651"], [64610, 5, " \u0650\u0651"], [64611, 5, " \u0651\u0670"], [64612, 1, "\u0626\u0631"], [64613, 1, "\u0626\u0632"], [64614, 1, "\u0626\u0645"], [64615, 1, "\u0626\u0646"], [64616, 1, "\u0626\u0649"], [64617, 1, "\u0626\u064A"], [64618, 1, "\u0628\u0631"], [64619, 1, "\u0628\u0632"], [64620, 1, "\u0628\u0645"], [64621, 1, "\u0628\u0646"], [64622, 1, "\u0628\u0649"], [64623, 1, "\u0628\u064A"], [64624, 1, "\u062A\u0631"], [64625, 1, "\u062A\u0632"], [64626, 1, "\u062A\u0645"], [64627, 1, "\u062A\u0646"], [64628, 1, "\u062A\u0649"], [64629, 1, "\u062A\u064A"], [64630, 1, "\u062B\u0631"], [64631, 1, "\u062B\u0632"], [64632, 1, "\u062B\u0645"], [64633, 1, "\u062B\u0646"], [64634, 1, "\u062B\u0649"], [64635, 1, "\u062B\u064A"], [64636, 1, "\u0641\u0649"], [64637, 1, "\u0641\u064A"], [64638, 1, "\u0642\u0649"], [64639, 1, "\u0642\u064A"], [64640, 1, "\u0643\u0627"], [64641, 1, "\u0643\u0644"], [64642, 1, "\u0643\u0645"], [64643, 1, "\u0643\u0649"], [64644, 1, "\u0643\u064A"], [64645, 1, "\u0644\u0645"], [64646, 1, "\u0644\u0649"], [64647, 1, "\u0644\u064A"], [64648, 1, "\u0645\u0627"], [64649, 1, "\u0645\u0645"], [64650, 1, "\u0646\u0631"], [64651, 1, "\u0646\u0632"], [64652, 1, "\u0646\u0645"], [64653, 1, "\u0646\u0646"], [64654, 1, "\u0646\u0649"], [64655, 1, "\u0646\u064A"], [64656, 1, "\u0649\u0670"], [64657, 1, "\u064A\u0631"], [64658, 1, "\u064A\u0632"], [64659, 1, "\u064A\u0645"], [64660, 1, "\u064A\u0646"], [64661, 1, "\u064A\u0649"], [64662, 1, "\u064A\u064A"], [64663, 1, "\u0626\u062C"], [64664, 1, "\u0626\u062D"], [64665, 1, "\u0626\u062E"], [64666, 1, "\u0626\u0645"], [64667, 1, "\u0626\u0647"], [64668, 1, "\u0628\u062C"], [64669, 1, "\u0628\u062D"], [64670, 1, "\u0628\u062E"], [64671, 1, "\u0628\u0645"], [64672, 1, "\u0628\u0647"], [64673, 1, "\u062A\u062C"], [64674, 1, "\u062A\u062D"], [64675, 1, "\u062A\u062E"], [64676, 1, "\u062A\u0645"], [64677, 1, "\u062A\u0647"], [64678, 1, "\u062B\u0645"], [64679, 1, "\u062C\u062D"], [64680, 1, "\u062C\u0645"], [64681, 1, "\u062D\u062C"], [64682, 1, "\u062D\u0645"], [64683, 1, "\u062E\u062C"], [64684, 1, "\u062E\u0645"], [64685, 1, "\u0633\u062C"], [64686, 1, "\u0633\u062D"], [64687, 1, "\u0633\u062E"], [64688, 1, "\u0633\u0645"], [64689, 1, "\u0635\u062D"], [64690, 1, "\u0635\u062E"], [64691, 1, "\u0635\u0645"], [64692, 1, "\u0636\u062C"], [64693, 1, "\u0636\u062D"], [64694, 1, "\u0636\u062E"], [64695, 1, "\u0636\u0645"], [64696, 1, "\u0637\u062D"], [64697, 1, "\u0638\u0645"], [64698, 1, "\u0639\u062C"], [64699, 1, "\u0639\u0645"], [64700, 1, "\u063A\u062C"], [64701, 1, "\u063A\u0645"], [64702, 1, "\u0641\u062C"], [64703, 1, "\u0641\u062D"], [64704, 1, "\u0641\u062E"], [64705, 1, "\u0641\u0645"], [64706, 1, "\u0642\u062D"], [64707, 1, "\u0642\u0645"], [64708, 1, "\u0643\u062C"], [64709, 1, "\u0643\u062D"], [64710, 1, "\u0643\u062E"], [64711, 1, "\u0643\u0644"], [64712, 1, "\u0643\u0645"], [64713, 1, "\u0644\u062C"], [64714, 1, "\u0644\u062D"], [64715, 1, "\u0644\u062E"], [64716, 1, "\u0644\u0645"], [64717, 1, "\u0644\u0647"], [64718, 1, "\u0645\u062C"], [64719, 1, "\u0645\u062D"], [64720, 1, "\u0645\u062E"], [64721, 1, "\u0645\u0645"], [64722, 1, "\u0646\u062C"], [64723, 1, "\u0646\u062D"], [64724, 1, "\u0646\u062E"], [64725, 1, "\u0646\u0645"], [64726, 1, "\u0646\u0647"], [64727, 1, "\u0647\u062C"], [64728, 1, "\u0647\u0645"], [64729, 1, "\u0647\u0670"], [64730, 1, "\u064A\u062C"], [64731, 1, "\u064A\u062D"], [64732, 1, "\u064A\u062E"], [64733, 1, "\u064A\u0645"], [64734, 1, "\u064A\u0647"], [64735, 1, "\u0626\u0645"], [64736, 1, "\u0626\u0647"], [64737, 1, "\u0628\u0645"], [64738, 1, "\u0628\u0647"], [64739, 1, "\u062A\u0645"], [64740, 1, "\u062A\u0647"], [64741, 1, "\u062B\u0645"], [64742, 1, "\u062B\u0647"], [64743, 1, "\u0633\u0645"], [64744, 1, "\u0633\u0647"], [64745, 1, "\u0634\u0645"], [64746, 1, "\u0634\u0647"], [64747, 1, "\u0643\u0644"], [64748, 1, "\u0643\u0645"], [64749, 1, "\u0644\u0645"], [64750, 1, "\u0646\u0645"], [64751, 1, "\u0646\u0647"], [64752, 1, "\u064A\u0645"], [64753, 1, "\u064A\u0647"], [64754, 1, "\u0640\u064E\u0651"], [64755, 1, "\u0640\u064F\u0651"], [64756, 1, "\u0640\u0650\u0651"], [64757, 1, "\u0637\u0649"], [64758, 1, "\u0637\u064A"], [64759, 1, "\u0639\u0649"], [64760, 1, "\u0639\u064A"], [64761, 1, "\u063A\u0649"], [64762, 1, "\u063A\u064A"], [64763, 1, "\u0633\u0649"], [64764, 1, "\u0633\u064A"], [64765, 1, "\u0634\u0649"], [64766, 1, "\u0634\u064A"], [64767, 1, "\u062D\u0649"], [64768, 1, "\u062D\u064A"], [64769, 1, "\u062C\u0649"], [64770, 1, "\u062C\u064A"], [64771, 1, "\u062E\u0649"], [64772, 1, "\u062E\u064A"], [64773, 1, "\u0635\u0649"], [64774, 1, "\u0635\u064A"], [64775, 1, "\u0636\u0649"], [64776, 1, "\u0636\u064A"], [64777, 1, "\u0634\u062C"], [64778, 1, "\u0634\u062D"], [64779, 1, "\u0634\u062E"], [64780, 1, "\u0634\u0645"], [64781, 1, "\u0634\u0631"], [64782, 1, "\u0633\u0631"], [64783, 1, "\u0635\u0631"], [64784, 1, "\u0636\u0631"], [64785, 1, "\u0637\u0649"], [64786, 1, "\u0637\u064A"], [64787, 1, "\u0639\u0649"], [64788, 1, "\u0639\u064A"], [64789, 1, "\u063A\u0649"], [64790, 1, "\u063A\u064A"], [64791, 1, "\u0633\u0649"], [64792, 1, "\u0633\u064A"], [64793, 1, "\u0634\u0649"], [64794, 1, "\u0634\u064A"], [64795, 1, "\u062D\u0649"], [64796, 1, "\u062D\u064A"], [64797, 1, "\u062C\u0649"], [64798, 1, "\u062C\u064A"], [64799, 1, "\u062E\u0649"], [64800, 1, "\u062E\u064A"], [64801, 1, "\u0635\u0649"], [64802, 1, "\u0635\u064A"], [64803, 1, "\u0636\u0649"], [64804, 1, "\u0636\u064A"], [64805, 1, "\u0634\u062C"], [64806, 1, "\u0634\u062D"], [64807, 1, "\u0634\u062E"], [64808, 1, "\u0634\u0645"], [64809, 1, "\u0634\u0631"], [64810, 1, "\u0633\u0631"], [64811, 1, "\u0635\u0631"], [64812, 1, "\u0636\u0631"], [64813, 1, "\u0634\u062C"], [64814, 1, "\u0634\u062D"], [64815, 1, "\u0634\u062E"], [64816, 1, "\u0634\u0645"], [64817, 1, "\u0633\u0647"], [64818, 1, "\u0634\u0647"], [64819, 1, "\u0637\u0645"], [64820, 1, "\u0633\u062C"], [64821, 1, "\u0633\u062D"], [64822, 1, "\u0633\u062E"], [64823, 1, "\u0634\u062C"], [64824, 1, "\u0634\u062D"], [64825, 1, "\u0634\u062E"], [64826, 1, "\u0637\u0645"], [64827, 1, "\u0638\u0645"], [[64828, 64829], 1, "\u0627\u064B"], [[64830, 64831], 2], [[64832, 64847], 2], [64848, 1, "\u062A\u062C\u0645"], [[64849, 64850], 1, "\u062A\u062D\u062C"], [64851, 1, "\u062A\u062D\u0645"], [64852, 1, "\u062A\u062E\u0645"], [64853, 1, "\u062A\u0645\u062C"], [64854, 1, "\u062A\u0645\u062D"], [64855, 1, "\u062A\u0645\u062E"], [[64856, 64857], 1, "\u062C\u0645\u062D"], [64858, 1, "\u062D\u0645\u064A"], [64859, 1, "\u062D\u0645\u0649"], [64860, 1, "\u0633\u062D\u062C"], [64861, 1, "\u0633\u062C\u062D"], [64862, 1, "\u0633\u062C\u0649"], [[64863, 64864], 1, "\u0633\u0645\u062D"], [64865, 1, "\u0633\u0645\u062C"], [[64866, 64867], 1, "\u0633\u0645\u0645"], [[64868, 64869], 1, "\u0635\u062D\u062D"], [64870, 1, "\u0635\u0645\u0645"], [[64871, 64872], 1, "\u0634\u062D\u0645"], [64873, 1, "\u0634\u062C\u064A"], [[64874, 64875], 1, "\u0634\u0645\u062E"], [[64876, 64877], 1, "\u0634\u0645\u0645"], [64878, 1, "\u0636\u062D\u0649"], [[64879, 64880], 1, "\u0636\u062E\u0645"], [[64881, 64882], 1, "\u0637\u0645\u062D"], [64883, 1, "\u0637\u0645\u0645"], [64884, 1, "\u0637\u0645\u064A"], [64885, 1, "\u0639\u062C\u0645"], [[64886, 64887], 1, "\u0639\u0645\u0645"], [64888, 1, "\u0639\u0645\u0649"], [64889, 1, "\u063A\u0645\u0645"], [64890, 1, "\u063A\u0645\u064A"], [64891, 1, "\u063A\u0645\u0649"], [[64892, 64893], 1, "\u0641\u062E\u0645"], [64894, 1, "\u0642\u0645\u062D"], [64895, 1, "\u0642\u0645\u0645"], [64896, 1, "\u0644\u062D\u0645"], [64897, 1, "\u0644\u062D\u064A"], [64898, 1, "\u0644\u062D\u0649"], [[64899, 64900], 1, "\u0644\u062C\u062C"], [[64901, 64902], 1, "\u0644\u062E\u0645"], [[64903, 64904], 1, "\u0644\u0645\u062D"], [64905, 1, "\u0645\u062D\u062C"], [64906, 1, "\u0645\u062D\u0645"], [64907, 1, "\u0645\u062D\u064A"], [64908, 1, "\u0645\u062C\u062D"], [64909, 1, "\u0645\u062C\u0645"], [64910, 1, "\u0645\u062E\u062C"], [64911, 1, "\u0645\u062E\u0645"], [[64912, 64913], 3], [64914, 1, "\u0645\u062C\u062E"], [64915, 1, "\u0647\u0645\u062C"], [64916, 1, "\u0647\u0645\u0645"], [64917, 1, "\u0646\u062D\u0645"], [64918, 1, "\u0646\u062D\u0649"], [[64919, 64920], 1, "\u0646\u062C\u0645"], [64921, 1, "\u0646\u062C\u0649"], [64922, 1, "\u0646\u0645\u064A"], [64923, 1, "\u0646\u0645\u0649"], [[64924, 64925], 1, "\u064A\u0645\u0645"], [64926, 1, "\u0628\u062E\u064A"], [64927, 1, "\u062A\u062C\u064A"], [64928, 1, "\u062A\u062C\u0649"], [64929, 1, "\u062A\u062E\u064A"], [64930, 1, "\u062A\u062E\u0649"], [64931, 1, "\u062A\u0645\u064A"], [64932, 1, "\u062A\u0645\u0649"], [64933, 1, "\u062C\u0645\u064A"], [64934, 1, "\u062C\u062D\u0649"], [64935, 1, "\u062C\u0645\u0649"], [64936, 1, "\u0633\u062E\u0649"], [64937, 1, "\u0635\u062D\u064A"], [64938, 1, "\u0634\u062D\u064A"], [64939, 1, "\u0636\u062D\u064A"], [64940, 1, "\u0644\u062C\u064A"], [64941, 1, "\u0644\u0645\u064A"], [64942, 1, "\u064A\u062D\u064A"], [64943, 1, "\u064A\u062C\u064A"], [64944, 1, "\u064A\u0645\u064A"], [64945, 1, "\u0645\u0645\u064A"], [64946, 1, "\u0642\u0645\u064A"], [64947, 1, "\u0646\u062D\u064A"], [64948, 1, "\u0642\u0645\u062D"], [64949, 1, "\u0644\u062D\u0645"], [64950, 1, "\u0639\u0645\u064A"], [64951, 1, "\u0643\u0645\u064A"], [64952, 1, "\u0646\u062C\u062D"], [64953, 1, "\u0645\u062E\u064A"], [64954, 1, "\u0644\u062C\u0645"], [64955, 1, "\u0643\u0645\u0645"], [64956, 1, "\u0644\u062C\u0645"], [64957, 1, "\u0646\u062C\u062D"], [64958, 1, "\u062C\u062D\u064A"], [64959, 1, "\u062D\u062C\u064A"], [64960, 1, "\u0645\u062C\u064A"], [64961, 1, "\u0641\u0645\u064A"], [64962, 1, "\u0628\u062D\u064A"], [64963, 1, "\u0643\u0645\u0645"], [64964, 1, "\u0639\u062C\u0645"], [64965, 1, "\u0635\u0645\u0645"], [64966, 1, "\u0633\u062E\u064A"], [64967, 1, "\u0646\u062C\u064A"], [[64968, 64974], 3], [64975, 2], [[64976, 65007], 3], [65008, 1, "\u0635\u0644\u06D2"], [65009, 1, "\u0642\u0644\u06D2"], [65010, 1, "\u0627\u0644\u0644\u0647"], [65011, 1, "\u0627\u0643\u0628\u0631"], [65012, 1, "\u0645\u062D\u0645\u062F"], [65013, 1, "\u0635\u0644\u0639\u0645"], [65014, 1, "\u0631\u0633\u0648\u0644"], [65015, 1, "\u0639\u0644\u064A\u0647"], [65016, 1, "\u0648\u0633\u0644\u0645"], [65017, 1, "\u0635\u0644\u0649"], [65018, 5, "\u0635\u0644\u0649 \u0627\u0644\u0644\u0647 \u0639\u0644\u064A\u0647 \u0648\u0633\u0644\u0645"], [65019, 5, "\u062C\u0644 \u062C\u0644\u0627\u0644\u0647"], [65020, 1, "\u0631\u06CC\u0627\u0644"], [65021, 2], [[65022, 65023], 2], [[65024, 65039], 7], [65040, 5, ","], [65041, 1, "\u3001"], [65042, 3], [65043, 5, ":"], [65044, 5, ";"], [65045, 5, "!"], [65046, 5, "?"], [65047, 1, "\u3016"], [65048, 1, "\u3017"], [65049, 3], [[65050, 65055], 3], [[65056, 65059], 2], [[65060, 65062], 2], [[65063, 65069], 2], [[65070, 65071], 2], [65072, 3], [65073, 1, "\u2014"], [65074, 1, "\u2013"], [[65075, 65076], 5, "_"], [65077, 5, "("], [65078, 5, ")"], [65079, 5, "{"], [65080, 5, "}"], [65081, 1, "\u3014"], [65082, 1, "\u3015"], [65083, 1, "\u3010"], [65084, 1, "\u3011"], [65085, 1, "\u300A"], [65086, 1, "\u300B"], [65087, 1, "\u3008"], [65088, 1, "\u3009"], [65089, 1, "\u300C"], [65090, 1, "\u300D"], [65091, 1, "\u300E"], [65092, 1, "\u300F"], [[65093, 65094], 2], [65095, 5, "["], [65096, 5, "]"], [[65097, 65100], 5, " \u0305"], [[65101, 65103], 5, "_"], [65104, 5, ","], [65105, 1, "\u3001"], [65106, 3], [65107, 3], [65108, 5, ";"], [65109, 5, ":"], [65110, 5, "?"], [65111, 5, "!"], [65112, 1, "\u2014"], [65113, 5, "("], [65114, 5, ")"], [65115, 5, "{"], [65116, 5, "}"], [65117, 1, "\u3014"], [65118, 1, "\u3015"], [65119, 5, "#"], [65120, 5, "&"], [65121, 5, "*"], [65122, 5, "+"], [65123, 1, "-"], [65124, 5, "<"], [65125, 5, ">"], [65126, 5, "="], [65127, 3], [65128, 5, "\\"], [65129, 5, "$"], [65130, 5, "%"], [65131, 5, "@"], [[65132, 65135], 3], [65136, 5, " \u064B"], [65137, 1, "\u0640\u064B"], [65138, 5, " \u064C"], [65139, 2], [65140, 5, " \u064D"], [65141, 3], [65142, 5, " \u064E"], [65143, 1, "\u0640\u064E"], [65144, 5, " \u064F"], [65145, 1, "\u0640\u064F"], [65146, 5, " \u0650"], [65147, 1, "\u0640\u0650"], [65148, 5, " \u0651"], [65149, 1, "\u0640\u0651"], [65150, 5, " \u0652"], [65151, 1, "\u0640\u0652"], [65152, 1, "\u0621"], [[65153, 65154], 1, "\u0622"], [[65155, 65156], 1, "\u0623"], [[65157, 65158], 1, "\u0624"], [[65159, 65160], 1, "\u0625"], [[65161, 65164], 1, "\u0626"], [[65165, 65166], 1, "\u0627"], [[65167, 65170], 1, "\u0628"], [[65171, 65172], 1, "\u0629"], [[65173, 65176], 1, "\u062A"], [[65177, 65180], 1, "\u062B"], [[65181, 65184], 1, "\u062C"], [[65185, 65188], 1, "\u062D"], [[65189, 65192], 1, "\u062E"], [[65193, 65194], 1, "\u062F"], [[65195, 65196], 1, "\u0630"], [[65197, 65198], 1, "\u0631"], [[65199, 65200], 1, "\u0632"], [[65201, 65204], 1, "\u0633"], [[65205, 65208], 1, "\u0634"], [[65209, 65212], 1, "\u0635"], [[65213, 65216], 1, "\u0636"], [[65217, 65220], 1, "\u0637"], [[65221, 65224], 1, "\u0638"], [[65225, 65228], 1, "\u0639"], [[65229, 65232], 1, "\u063A"], [[65233, 65236], 1, "\u0641"], [[65237, 65240], 1, "\u0642"], [[65241, 65244], 1, "\u0643"], [[65245, 65248], 1, "\u0644"], [[65249, 65252], 1, "\u0645"], [[65253, 65256], 1, "\u0646"], [[65257, 65260], 1, "\u0647"], [[65261, 65262], 1, "\u0648"], [[65263, 65264], 1, "\u0649"], [[65265, 65268], 1, "\u064A"], [[65269, 65270], 1, "\u0644\u0622"], [[65271, 65272], 1, "\u0644\u0623"], [[65273, 65274], 1, "\u0644\u0625"], [[65275, 65276], 1, "\u0644\u0627"], [[65277, 65278], 3], [65279, 7], [65280, 3], [65281, 5, "!"], [65282, 5, '"'], [65283, 5, "#"], [65284, 5, "$"], [65285, 5, "%"], [65286, 5, "&"], [65287, 5, "'"], [65288, 5, "("], [65289, 5, ")"], [65290, 5, "*"], [65291, 5, "+"], [65292, 5, ","], [65293, 1, "-"], [65294, 1, "."], [65295, 5, "/"], [65296, 1, "0"], [65297, 1, "1"], [65298, 1, "2"], [65299, 1, "3"], [65300, 1, "4"], [65301, 1, "5"], [65302, 1, "6"], [65303, 1, "7"], [65304, 1, "8"], [65305, 1, "9"], [65306, 5, ":"], [65307, 5, ";"], [65308, 5, "<"], [65309, 5, "="], [65310, 5, ">"], [65311, 5, "?"], [65312, 5, "@"], [65313, 1, "a"], [65314, 1, "b"], [65315, 1, "c"], [65316, 1, "d"], [65317, 1, "e"], [65318, 1, "f"], [65319, 1, "g"], [65320, 1, "h"], [65321, 1, "i"], [65322, 1, "j"], [65323, 1, "k"], [65324, 1, "l"], [65325, 1, "m"], [65326, 1, "n"], [65327, 1, "o"], [65328, 1, "p"], [65329, 1, "q"], [65330, 1, "r"], [65331, 1, "s"], [65332, 1, "t"], [65333, 1, "u"], [65334, 1, "v"], [65335, 1, "w"], [65336, 1, "x"], [65337, 1, "y"], [65338, 1, "z"], [65339, 5, "["], [65340, 5, "\\"], [65341, 5, "]"], [65342, 5, "^"], [65343, 5, "_"], [65344, 5, "`"], [65345, 1, "a"], [65346, 1, "b"], [65347, 1, "c"], [65348, 1, "d"], [65349, 1, "e"], [65350, 1, "f"], [65351, 1, "g"], [65352, 1, "h"], [65353, 1, "i"], [65354, 1, "j"], [65355, 1, "k"], [65356, 1, "l"], [65357, 1, "m"], [65358, 1, "n"], [65359, 1, "o"], [65360, 1, "p"], [65361, 1, "q"], [65362, 1, "r"], [65363, 1, "s"], [65364, 1, "t"], [65365, 1, "u"], [65366, 1, "v"], [65367, 1, "w"], [65368, 1, "x"], [65369, 1, "y"], [65370, 1, "z"], [65371, 5, "{"], [65372, 5, "|"], [65373, 5, "}"], [65374, 5, "~"], [65375, 1, "\u2985"], [65376, 1, "\u2986"], [65377, 1, "."], [65378, 1, "\u300C"], [65379, 1, "\u300D"], [65380, 1, "\u3001"], [65381, 1, "\u30FB"], [65382, 1, "\u30F2"], [65383, 1, "\u30A1"], [65384, 1, "\u30A3"], [65385, 1, "\u30A5"], [65386, 1, "\u30A7"], [65387, 1, "\u30A9"], [65388, 1, "\u30E3"], [65389, 1, "\u30E5"], [65390, 1, "\u30E7"], [65391, 1, "\u30C3"], [65392, 1, "\u30FC"], [65393, 1, "\u30A2"], [65394, 1, "\u30A4"], [65395, 1, "\u30A6"], [65396, 1, "\u30A8"], [65397, 1, "\u30AA"], [65398, 1, "\u30AB"], [65399, 1, "\u30AD"], [65400, 1, "\u30AF"], [65401, 1, "\u30B1"], [65402, 1, "\u30B3"], [65403, 1, "\u30B5"], [65404, 1, "\u30B7"], [65405, 1, "\u30B9"], [65406, 1, "\u30BB"], [65407, 1, "\u30BD"], [65408, 1, "\u30BF"], [65409, 1, "\u30C1"], [65410, 1, "\u30C4"], [65411, 1, "\u30C6"], [65412, 1, "\u30C8"], [65413, 1, "\u30CA"], [65414, 1, "\u30CB"], [65415, 1, "\u30CC"], [65416, 1, "\u30CD"], [65417, 1, "\u30CE"], [65418, 1, "\u30CF"], [65419, 1, "\u30D2"], [65420, 1, "\u30D5"], [65421, 1, "\u30D8"], [65422, 1, "\u30DB"], [65423, 1, "\u30DE"], [65424, 1, "\u30DF"], [65425, 1, "\u30E0"], [65426, 1, "\u30E1"], [65427, 1, "\u30E2"], [65428, 1, "\u30E4"], [65429, 1, "\u30E6"], [65430, 1, "\u30E8"], [65431, 1, "\u30E9"], [65432, 1, "\u30EA"], [65433, 1, "\u30EB"], [65434, 1, "\u30EC"], [65435, 1, "\u30ED"], [65436, 1, "\u30EF"], [65437, 1, "\u30F3"], [65438, 1, "\u3099"], [65439, 1, "\u309A"], [65440, 3], [65441, 1, "\u1100"], [65442, 1, "\u1101"], [65443, 1, "\u11AA"], [65444, 1, "\u1102"], [65445, 1, "\u11AC"], [65446, 1, "\u11AD"], [65447, 1, "\u1103"], [65448, 1, "\u1104"], [65449, 1, "\u1105"], [65450, 1, "\u11B0"], [65451, 1, "\u11B1"], [65452, 1, "\u11B2"], [65453, 1, "\u11B3"], [65454, 1, "\u11B4"], [65455, 1, "\u11B5"], [65456, 1, "\u111A"], [65457, 1, "\u1106"], [65458, 1, "\u1107"], [65459, 1, "\u1108"], [65460, 1, "\u1121"], [65461, 1, "\u1109"], [65462, 1, "\u110A"], [65463, 1, "\u110B"], [65464, 1, "\u110C"], [65465, 1, "\u110D"], [65466, 1, "\u110E"], [65467, 1, "\u110F"], [65468, 1, "\u1110"], [65469, 1, "\u1111"], [65470, 1, "\u1112"], [[65471, 65473], 3], [65474, 1, "\u1161"], [65475, 1, "\u1162"], [65476, 1, "\u1163"], [65477, 1, "\u1164"], [65478, 1, "\u1165"], [65479, 1, "\u1166"], [[65480, 65481], 3], [65482, 1, "\u1167"], [65483, 1, "\u1168"], [65484, 1, "\u1169"], [65485, 1, "\u116A"], [65486, 1, "\u116B"], [65487, 1, "\u116C"], [[65488, 65489], 3], [65490, 1, "\u116D"], [65491, 1, "\u116E"], [65492, 1, "\u116F"], [65493, 1, "\u1170"], [65494, 1, "\u1171"], [65495, 1, "\u1172"], [[65496, 65497], 3], [65498, 1, "\u1173"], [65499, 1, "\u1174"], [65500, 1, "\u1175"], [[65501, 65503], 3], [65504, 1, "\xA2"], [65505, 1, "\xA3"], [65506, 1, "\xAC"], [65507, 5, " \u0304"], [65508, 1, "\xA6"], [65509, 1, "\xA5"], [65510, 1, "\u20A9"], [65511, 3], [65512, 1, "\u2502"], [65513, 1, "\u2190"], [65514, 1, "\u2191"], [65515, 1, "\u2192"], [65516, 1, "\u2193"], [65517, 1, "\u25A0"], [65518, 1, "\u25CB"], [[65519, 65528], 3], [[65529, 65531], 3], [65532, 3], [65533, 3], [[65534, 65535], 3], [[65536, 65547], 2], [65548, 3], [[65549, 65574], 2], [65575, 3], [[65576, 65594], 2], [65595, 3], [[65596, 65597], 2], [65598, 3], [[65599, 65613], 2], [[65614, 65615], 3], [[65616, 65629], 2], [[65630, 65663], 3], [[65664, 65786], 2], [[65787, 65791], 3], [[65792, 65794], 2], [[65795, 65798], 3], [[65799, 65843], 2], [[65844, 65846], 3], [[65847, 65855], 2], [[65856, 65930], 2], [[65931, 65932], 2], [[65933, 65934], 2], [65935, 3], [[65936, 65947], 2], [65948, 2], [[65949, 65951], 3], [65952, 2], [[65953, 65999], 3], [[66e3, 66044], 2], [66045, 2], [[66046, 66175], 3], [[66176, 66204], 2], [[66205, 66207], 3], [[66208, 66256], 2], [[66257, 66271], 3], [66272, 2], [[66273, 66299], 2], [[66300, 66303], 3], [[66304, 66334], 2], [66335, 2], [[66336, 66339], 2], [[66340, 66348], 3], [[66349, 66351], 2], [[66352, 66368], 2], [66369, 2], [[66370, 66377], 2], [66378, 2], [[66379, 66383], 3], [[66384, 66426], 2], [[66427, 66431], 3], [[66432, 66461], 2], [66462, 3], [66463, 2], [[66464, 66499], 2], [[66500, 66503], 3], [[66504, 66511], 2], [[66512, 66517], 2], [[66518, 66559], 3], [66560, 1, "\u{10428}"], [66561, 1, "\u{10429}"], [66562, 1, "\u{1042A}"], [66563, 1, "\u{1042B}"], [66564, 1, "\u{1042C}"], [66565, 1, "\u{1042D}"], [66566, 1, "\u{1042E}"], [66567, 1, "\u{1042F}"], [66568, 1, "\u{10430}"], [66569, 1, "\u{10431}"], [66570, 1, "\u{10432}"], [66571, 1, "\u{10433}"], [66572, 1, "\u{10434}"], [66573, 1, "\u{10435}"], [66574, 1, "\u{10436}"], [66575, 1, "\u{10437}"], [66576, 1, "\u{10438}"], [66577, 1, "\u{10439}"], [66578, 1, "\u{1043A}"], [66579, 1, "\u{1043B}"], [66580, 1, "\u{1043C}"], [66581, 1, "\u{1043D}"], [66582, 1, "\u{1043E}"], [66583, 1, "\u{1043F}"], [66584, 1, "\u{10440}"], [66585, 1, "\u{10441}"], [66586, 1, "\u{10442}"], [66587, 1, "\u{10443}"], [66588, 1, "\u{10444}"], [66589, 1, "\u{10445}"], [66590, 1, "\u{10446}"], [66591, 1, "\u{10447}"], [66592, 1, "\u{10448}"], [66593, 1, "\u{10449}"], [66594, 1, "\u{1044A}"], [66595, 1, "\u{1044B}"], [66596, 1, "\u{1044C}"], [66597, 1, "\u{1044D}"], [66598, 1, "\u{1044E}"], [66599, 1, "\u{1044F}"], [[66600, 66637], 2], [[66638, 66717], 2], [[66718, 66719], 3], [[66720, 66729], 2], [[66730, 66735], 3], [66736, 1, "\u{104D8}"], [66737, 1, "\u{104D9}"], [66738, 1, "\u{104DA}"], [66739, 1, "\u{104DB}"], [66740, 1, "\u{104DC}"], [66741, 1, "\u{104DD}"], [66742, 1, "\u{104DE}"], [66743, 1, "\u{104DF}"], [66744, 1, "\u{104E0}"], [66745, 1, "\u{104E1}"], [66746, 1, "\u{104E2}"], [66747, 1, "\u{104E3}"], [66748, 1, "\u{104E4}"], [66749, 1, "\u{104E5}"], [66750, 1, "\u{104E6}"], [66751, 1, "\u{104E7}"], [66752, 1, "\u{104E8}"], [66753, 1, "\u{104E9}"], [66754, 1, "\u{104EA}"], [66755, 1, "\u{104EB}"], [66756, 1, "\u{104EC}"], [66757, 1, "\u{104ED}"], [66758, 1, "\u{104EE}"], [66759, 1, "\u{104EF}"], [66760, 1, "\u{104F0}"], [66761, 1, "\u{104F1}"], [66762, 1, "\u{104F2}"], [66763, 1, "\u{104F3}"], [66764, 1, "\u{104F4}"], [66765, 1, "\u{104F5}"], [66766, 1, "\u{104F6}"], [66767, 1, "\u{104F7}"], [66768, 1, "\u{104F8}"], [66769, 1, "\u{104F9}"], [66770, 1, "\u{104FA}"], [66771, 1, "\u{104FB}"], [[66772, 66775], 3], [[66776, 66811], 2], [[66812, 66815], 3], [[66816, 66855], 2], [[66856, 66863], 3], [[66864, 66915], 2], [[66916, 66926], 3], [66927, 2], [66928, 1, "\u{10597}"], [66929, 1, "\u{10598}"], [66930, 1, "\u{10599}"], [66931, 1, "\u{1059A}"], [66932, 1, "\u{1059B}"], [66933, 1, "\u{1059C}"], [66934, 1, "\u{1059D}"], [66935, 1, "\u{1059E}"], [66936, 1, "\u{1059F}"], [66937, 1, "\u{105A0}"], [66938, 1, "\u{105A1}"], [66939, 3], [66940, 1, "\u{105A3}"], [66941, 1, "\u{105A4}"], [66942, 1, "\u{105A5}"], [66943, 1, "\u{105A6}"], [66944, 1, "\u{105A7}"], [66945, 1, "\u{105A8}"], [66946, 1, "\u{105A9}"], [66947, 1, "\u{105AA}"], [66948, 1, "\u{105AB}"], [66949, 1, "\u{105AC}"], [66950, 1, "\u{105AD}"], [66951, 1, "\u{105AE}"], [66952, 1, "\u{105AF}"], [66953, 1, "\u{105B0}"], [66954, 1, "\u{105B1}"], [66955, 3], [66956, 1, "\u{105B3}"], [66957, 1, "\u{105B4}"], [66958, 1, "\u{105B5}"], [66959, 1, "\u{105B6}"], [66960, 1, "\u{105B7}"], [66961, 1, "\u{105B8}"], [66962, 1, "\u{105B9}"], [66963, 3], [66964, 1, "\u{105BB}"], [66965, 1, "\u{105BC}"], [66966, 3], [[66967, 66977], 2], [66978, 3], [[66979, 66993], 2], [66994, 3], [[66995, 67001], 2], [67002, 3], [[67003, 67004], 2], [[67005, 67071], 3], [[67072, 67382], 2], [[67383, 67391], 3], [[67392, 67413], 2], [[67414, 67423], 3], [[67424, 67431], 2], [[67432, 67455], 3], [67456, 2], [67457, 1, "\u02D0"], [67458, 1, "\u02D1"], [67459, 1, "\xE6"], [67460, 1, "\u0299"], [67461, 1, "\u0253"], [67462, 3], [67463, 1, "\u02A3"], [67464, 1, "\uAB66"], [67465, 1, "\u02A5"], [67466, 1, "\u02A4"], [67467, 1, "\u0256"], [67468, 1, "\u0257"], [67469, 1, "\u1D91"], [67470, 1, "\u0258"], [67471, 1, "\u025E"], [67472, 1, "\u02A9"], [67473, 1, "\u0264"], [67474, 1, "\u0262"], [67475, 1, "\u0260"], [67476, 1, "\u029B"], [67477, 1, "\u0127"], [67478, 1, "\u029C"], [67479, 1, "\u0267"], [67480, 1, "\u0284"], [67481, 1, "\u02AA"], [67482, 1, "\u02AB"], [67483, 1, "\u026C"], [67484, 1, "\u{1DF04}"], [67485, 1, "\uA78E"], [67486, 1, "\u026E"], [67487, 1, "\u{1DF05}"], [67488, 1, "\u028E"], [67489, 1, "\u{1DF06}"], [67490, 1, "\xF8"], [67491, 1, "\u0276"], [67492, 1, "\u0277"], [67493, 1, "q"], [67494, 1, "\u027A"], [67495, 1, "\u{1DF08}"], [67496, 1, "\u027D"], [67497, 1, "\u027E"], [67498, 1, "\u0280"], [67499, 1, "\u02A8"], [67500, 1, "\u02A6"], [67501, 1, "\uAB67"], [67502, 1, "\u02A7"], [67503, 1, "\u0288"], [67504, 1, "\u2C71"], [67505, 3], [67506, 1, "\u028F"], [67507, 1, "\u02A1"], [67508, 1, "\u02A2"], [67509, 1, "\u0298"], [67510, 1, "\u01C0"], [67511, 1, "\u01C1"], [67512, 1, "\u01C2"], [67513, 1, "\u{1DF0A}"], [67514, 1, "\u{1DF1E}"], [[67515, 67583], 3], [[67584, 67589], 2], [[67590, 67591], 3], [67592, 2], [67593, 3], [[67594, 67637], 2], [67638, 3], [[67639, 67640], 2], [[67641, 67643], 3], [67644, 2], [[67645, 67646], 3], [67647, 2], [[67648, 67669], 2], [67670, 3], [[67671, 67679], 2], [[67680, 67702], 2], [[67703, 67711], 2], [[67712, 67742], 2], [[67743, 67750], 3], [[67751, 67759], 2], [[67760, 67807], 3], [[67808, 67826], 2], [67827, 3], [[67828, 67829], 2], [[67830, 67834], 3], [[67835, 67839], 2], [[67840, 67861], 2], [[67862, 67865], 2], [[67866, 67867], 2], [[67868, 67870], 3], [67871, 2], [[67872, 67897], 2], [[67898, 67902], 3], [67903, 2], [[67904, 67967], 3], [[67968, 68023], 2], [[68024, 68027], 3], [[68028, 68029], 2], [[68030, 68031], 2], [[68032, 68047], 2], [[68048, 68049], 3], [[68050, 68095], 2], [[68096, 68099], 2], [68100, 3], [[68101, 68102], 2], [[68103, 68107], 3], [[68108, 68115], 2], [68116, 3], [[68117, 68119], 2], [68120, 3], [[68121, 68147], 2], [[68148, 68149], 2], [[68150, 68151], 3], [[68152, 68154], 2], [[68155, 68158], 3], [68159, 2], [[68160, 68167], 2], [68168, 2], [[68169, 68175], 3], [[68176, 68184], 2], [[68185, 68191], 3], [[68192, 68220], 2], [[68221, 68223], 2], [[68224, 68252], 2], [[68253, 68255], 2], [[68256, 68287], 3], [[68288, 68295], 2], [68296, 2], [[68297, 68326], 2], [[68327, 68330], 3], [[68331, 68342], 2], [[68343, 68351], 3], [[68352, 68405], 2], [[68406, 68408], 3], [[68409, 68415], 2], [[68416, 68437], 2], [[68438, 68439], 3], [[68440, 68447], 2], [[68448, 68466], 2], [[68467, 68471], 3], [[68472, 68479], 2], [[68480, 68497], 2], [[68498, 68504], 3], [[68505, 68508], 2], [[68509, 68520], 3], [[68521, 68527], 2], [[68528, 68607], 3], [[68608, 68680], 2], [[68681, 68735], 3], [68736, 1, "\u{10CC0}"], [68737, 1, "\u{10CC1}"], [68738, 1, "\u{10CC2}"], [68739, 1, "\u{10CC3}"], [68740, 1, "\u{10CC4}"], [68741, 1, "\u{10CC5}"], [68742, 1, "\u{10CC6}"], [68743, 1, "\u{10CC7}"], [68744, 1, "\u{10CC8}"], [68745, 1, "\u{10CC9}"], [68746, 1, "\u{10CCA}"], [68747, 1, "\u{10CCB}"], [68748, 1, "\u{10CCC}"], [68749, 1, "\u{10CCD}"], [68750, 1, "\u{10CCE}"], [68751, 1, "\u{10CCF}"], [68752, 1, "\u{10CD0}"], [68753, 1, "\u{10CD1}"], [68754, 1, "\u{10CD2}"], [68755, 1, "\u{10CD3}"], [68756, 1, "\u{10CD4}"], [68757, 1, "\u{10CD5}"], [68758, 1, "\u{10CD6}"], [68759, 1, "\u{10CD7}"], [68760, 1, "\u{10CD8}"], [68761, 1, "\u{10CD9}"], [68762, 1, "\u{10CDA}"], [68763, 1, "\u{10CDB}"], [68764, 1, "\u{10CDC}"], [68765, 1, "\u{10CDD}"], [68766, 1, "\u{10CDE}"], [68767, 1, "\u{10CDF}"], [68768, 1, "\u{10CE0}"], [68769, 1, "\u{10CE1}"], [68770, 1, "\u{10CE2}"], [68771, 1, "\u{10CE3}"], [68772, 1, "\u{10CE4}"], [68773, 1, "\u{10CE5}"], [68774, 1, "\u{10CE6}"], [68775, 1, "\u{10CE7}"], [68776, 1, "\u{10CE8}"], [68777, 1, "\u{10CE9}"], [68778, 1, "\u{10CEA}"], [68779, 1, "\u{10CEB}"], [68780, 1, "\u{10CEC}"], [68781, 1, "\u{10CED}"], [68782, 1, "\u{10CEE}"], [68783, 1, "\u{10CEF}"], [68784, 1, "\u{10CF0}"], [68785, 1, "\u{10CF1}"], [68786, 1, "\u{10CF2}"], [[68787, 68799], 3], [[68800, 68850], 2], [[68851, 68857], 3], [[68858, 68863], 2], [[68864, 68903], 2], [[68904, 68911], 3], [[68912, 68921], 2], [[68922, 69215], 3], [[69216, 69246], 2], [69247, 3], [[69248, 69289], 2], [69290, 3], [[69291, 69292], 2], [69293, 2], [[69294, 69295], 3], [[69296, 69297], 2], [[69298, 69375], 3], [[69376, 69404], 2], [[69405, 69414], 2], [69415, 2], [[69416, 69423], 3], [[69424, 69456], 2], [[69457, 69465], 2], [[69466, 69487], 3], [[69488, 69509], 2], [[69510, 69513], 2], [[69514, 69551], 3], [[69552, 69572], 2], [[69573, 69579], 2], [[69580, 69599], 3], [[69600, 69622], 2], [[69623, 69631], 3], [[69632, 69702], 2], [[69703, 69709], 2], [[69710, 69713], 3], [[69714, 69733], 2], [[69734, 69743], 2], [[69744, 69749], 2], [[69750, 69758], 3], [69759, 2], [[69760, 69818], 2], [[69819, 69820], 2], [69821, 3], [[69822, 69825], 2], [69826, 2], [[69827, 69836], 3], [69837, 3], [[69838, 69839], 3], [[69840, 69864], 2], [[69865, 69871], 3], [[69872, 69881], 2], [[69882, 69887], 3], [[69888, 69940], 2], [69941, 3], [[69942, 69951], 2], [[69952, 69955], 2], [[69956, 69958], 2], [69959, 2], [[69960, 69967], 3], [[69968, 70003], 2], [[70004, 70005], 2], [70006, 2], [[70007, 70015], 3], [[70016, 70084], 2], [[70085, 70088], 2], [[70089, 70092], 2], [70093, 2], [[70094, 70095], 2], [[70096, 70105], 2], [70106, 2], [70107, 2], [70108, 2], [[70109, 70111], 2], [70112, 3], [[70113, 70132], 2], [[70133, 70143], 3], [[70144, 70161], 2], [70162, 3], [[70163, 70199], 2], [[70200, 70205], 2], [70206, 2], [[70207, 70271], 3], [[70272, 70278], 2], [70279, 3], [70280, 2], [70281, 3], [[70282, 70285], 2], [70286, 3], [[70287, 70301], 2], [70302, 3], [[70303, 70312], 2], [70313, 2], [[70314, 70319], 3], [[70320, 70378], 2], [[70379, 70383], 3], [[70384, 70393], 2], [[70394, 70399], 3], [70400, 2], [[70401, 70403], 2], [70404, 3], [[70405, 70412], 2], [[70413, 70414], 3], [[70415, 70416], 2], [[70417, 70418], 3], [[70419, 70440], 2], [70441, 3], [[70442, 70448], 2], [70449, 3], [[70450, 70451], 2], [70452, 3], [[70453, 70457], 2], [70458, 3], [70459, 2], [[70460, 70468], 2], [[70469, 70470], 3], [[70471, 70472], 2], [[70473, 70474], 3], [[70475, 70477], 2], [[70478, 70479], 3], [70480, 2], [[70481, 70486], 3], [70487, 2], [[70488, 70492], 3], [[70493, 70499], 2], [[70500, 70501], 3], [[70502, 70508], 2], [[70509, 70511], 3], [[70512, 70516], 2], [[70517, 70655], 3], [[70656, 70730], 2], [[70731, 70735], 2], [[70736, 70745], 2], [70746, 2], [70747, 2], [70748, 3], [70749, 2], [70750, 2], [70751, 2], [[70752, 70753], 2], [[70754, 70783], 3], [[70784, 70853], 2], [70854, 2], [70855, 2], [[70856, 70863], 3], [[70864, 70873], 2], [[70874, 71039], 3], [[71040, 71093], 2], [[71094, 71095], 3], [[71096, 71104], 2], [[71105, 71113], 2], [[71114, 71127], 2], [[71128, 71133], 2], [[71134, 71167], 3], [[71168, 71232], 2], [[71233, 71235], 2], [71236, 2], [[71237, 71247], 3], [[71248, 71257], 2], [[71258, 71263], 3], [[71264, 71276], 2], [[71277, 71295], 3], [[71296, 71351], 2], [71352, 2], [71353, 2], [[71354, 71359], 3], [[71360, 71369], 2], [[71370, 71423], 3], [[71424, 71449], 2], [71450, 2], [[71451, 71452], 3], [[71453, 71467], 2], [[71468, 71471], 3], [[71472, 71481], 2], [[71482, 71487], 2], [[71488, 71494], 2], [[71495, 71679], 3], [[71680, 71738], 2], [71739, 2], [[71740, 71839], 3], [71840, 1, "\u{118C0}"], [71841, 1, "\u{118C1}"], [71842, 1, "\u{118C2}"], [71843, 1, "\u{118C3}"], [71844, 1, "\u{118C4}"], [71845, 1, "\u{118C5}"], [71846, 1, "\u{118C6}"], [71847, 1, "\u{118C7}"], [71848, 1, "\u{118C8}"], [71849, 1, "\u{118C9}"], [71850, 1, "\u{118CA}"], [71851, 1, "\u{118CB}"], [71852, 1, "\u{118CC}"], [71853, 1, "\u{118CD}"], [71854, 1, "\u{118CE}"], [71855, 1, "\u{118CF}"], [71856, 1, "\u{118D0}"], [71857, 1, "\u{118D1}"], [71858, 1, "\u{118D2}"], [71859, 1, "\u{118D3}"], [71860, 1, "\u{118D4}"], [71861, 1, "\u{118D5}"], [71862, 1, "\u{118D6}"], [71863, 1, "\u{118D7}"], [71864, 1, "\u{118D8}"], [71865, 1, "\u{118D9}"], [71866, 1, "\u{118DA}"], [71867, 1, "\u{118DB}"], [71868, 1, "\u{118DC}"], [71869, 1, "\u{118DD}"], [71870, 1, "\u{118DE}"], [71871, 1, "\u{118DF}"], [[71872, 71913], 2], [[71914, 71922], 2], [[71923, 71934], 3], [71935, 2], [[71936, 71942], 2], [[71943, 71944], 3], [71945, 2], [[71946, 71947], 3], [[71948, 71955], 2], [71956, 3], [[71957, 71958], 2], [71959, 3], [[71960, 71989], 2], [71990, 3], [[71991, 71992], 2], [[71993, 71994], 3], [[71995, 72003], 2], [[72004, 72006], 2], [[72007, 72015], 3], [[72016, 72025], 2], [[72026, 72095], 3], [[72096, 72103], 2], [[72104, 72105], 3], [[72106, 72151], 2], [[72152, 72153], 3], [[72154, 72161], 2], [72162, 2], [[72163, 72164], 2], [[72165, 72191], 3], [[72192, 72254], 2], [[72255, 72262], 2], [72263, 2], [[72264, 72271], 3], [[72272, 72323], 2], [[72324, 72325], 2], [[72326, 72345], 2], [[72346, 72348], 2], [72349, 2], [[72350, 72354], 2], [[72355, 72367], 3], [[72368, 72383], 2], [[72384, 72440], 2], [[72441, 72703], 3], [[72704, 72712], 2], [72713, 3], [[72714, 72758], 2], [72759, 3], [[72760, 72768], 2], [[72769, 72773], 2], [[72774, 72783], 3], [[72784, 72793], 2], [[72794, 72812], 2], [[72813, 72815], 3], [[72816, 72817], 2], [[72818, 72847], 2], [[72848, 72849], 3], [[72850, 72871], 2], [72872, 3], [[72873, 72886], 2], [[72887, 72959], 3], [[72960, 72966], 2], [72967, 3], [[72968, 72969], 2], [72970, 3], [[72971, 73014], 2], [[73015, 73017], 3], [73018, 2], [73019, 3], [[73020, 73021], 2], [73022, 3], [[73023, 73031], 2], [[73032, 73039], 3], [[73040, 73049], 2], [[73050, 73055], 3], [[73056, 73061], 2], [73062, 3], [[73063, 73064], 2], [73065, 3], [[73066, 73102], 2], [73103, 3], [[73104, 73105], 2], [73106, 3], [[73107, 73112], 2], [[73113, 73119], 3], [[73120, 73129], 2], [[73130, 73439], 3], [[73440, 73462], 2], [[73463, 73464], 2], [[73465, 73647], 3], [73648, 2], [[73649, 73663], 3], [[73664, 73713], 2], [[73714, 73726], 3], [73727, 2], [[73728, 74606], 2], [[74607, 74648], 2], [74649, 2], [[74650, 74751], 3], [[74752, 74850], 2], [[74851, 74862], 2], [74863, 3], [[74864, 74867], 2], [74868, 2], [[74869, 74879], 3], [[74880, 75075], 2], [[75076, 77711], 3], [[77712, 77808], 2], [[77809, 77810], 2], [[77811, 77823], 3], [[77824, 78894], 2], [78895, 3], [[78896, 78904], 3], [[78905, 82943], 3], [[82944, 83526], 2], [[83527, 92159], 3], [[92160, 92728], 2], [[92729, 92735], 3], [[92736, 92766], 2], [92767, 3], [[92768, 92777], 2], [[92778, 92781], 3], [[92782, 92783], 2], [[92784, 92862], 2], [92863, 3], [[92864, 92873], 2], [[92874, 92879], 3], [[92880, 92909], 2], [[92910, 92911], 3], [[92912, 92916], 2], [92917, 2], [[92918, 92927], 3], [[92928, 92982], 2], [[92983, 92991], 2], [[92992, 92995], 2], [[92996, 92997], 2], [[92998, 93007], 3], [[93008, 93017], 2], [93018, 3], [[93019, 93025], 2], [93026, 3], [[93027, 93047], 2], [[93048, 93052], 3], [[93053, 93071], 2], [[93072, 93759], 3], [93760, 1, "\u{16E60}"], [93761, 1, "\u{16E61}"], [93762, 1, "\u{16E62}"], [93763, 1, "\u{16E63}"], [93764, 1, "\u{16E64}"], [93765, 1, "\u{16E65}"], [93766, 1, "\u{16E66}"], [93767, 1, "\u{16E67}"], [93768, 1, "\u{16E68}"], [93769, 1, "\u{16E69}"], [93770, 1, "\u{16E6A}"], [93771, 1, "\u{16E6B}"], [93772, 1, "\u{16E6C}"], [93773, 1, "\u{16E6D}"], [93774, 1, "\u{16E6E}"], [93775, 1, "\u{16E6F}"], [93776, 1, "\u{16E70}"], [93777, 1, "\u{16E71}"], [93778, 1, "\u{16E72}"], [93779, 1, "\u{16E73}"], [93780, 1, "\u{16E74}"], [93781, 1, "\u{16E75}"], [93782, 1, "\u{16E76}"], [93783, 1, "\u{16E77}"], [93784, 1, "\u{16E78}"], [93785, 1, "\u{16E79}"], [93786, 1, "\u{16E7A}"], [93787, 1, "\u{16E7B}"], [93788, 1, "\u{16E7C}"], [93789, 1, "\u{16E7D}"], [93790, 1, "\u{16E7E}"], [93791, 1, "\u{16E7F}"], [[93792, 93823], 2], [[93824, 93850], 2], [[93851, 93951], 3], [[93952, 94020], 2], [[94021, 94026], 2], [[94027, 94030], 3], [94031, 2], [[94032, 94078], 2], [[94079, 94087], 2], [[94088, 94094], 3], [[94095, 94111], 2], [[94112, 94175], 3], [94176, 2], [94177, 2], [94178, 2], [94179, 2], [94180, 2], [[94181, 94191], 3], [[94192, 94193], 2], [[94194, 94207], 3], [[94208, 100332], 2], [[100333, 100337], 2], [[100338, 100343], 2], [[100344, 100351], 3], [[100352, 101106], 2], [[101107, 101589], 2], [[101590, 101631], 3], [[101632, 101640], 2], [[101641, 110575], 3], [[110576, 110579], 2], [110580, 3], [[110581, 110587], 2], [110588, 3], [[110589, 110590], 2], [110591, 3], [[110592, 110593], 2], [[110594, 110878], 2], [[110879, 110882], 2], [[110883, 110927], 3], [[110928, 110930], 2], [[110931, 110947], 3], [[110948, 110951], 2], [[110952, 110959], 3], [[110960, 111355], 2], [[111356, 113663], 3], [[113664, 113770], 2], [[113771, 113775], 3], [[113776, 113788], 2], [[113789, 113791], 3], [[113792, 113800], 2], [[113801, 113807], 3], [[113808, 113817], 2], [[113818, 113819], 3], [113820, 2], [[113821, 113822], 2], [113823, 2], [[113824, 113827], 7], [[113828, 118527], 3], [[118528, 118573], 2], [[118574, 118575], 3], [[118576, 118598], 2], [[118599, 118607], 3], [[118608, 118723], 2], [[118724, 118783], 3], [[118784, 119029], 2], [[119030, 119039], 3], [[119040, 119078], 2], [[119079, 119080], 3], [119081, 2], [[119082, 119133], 2], [119134, 1, "\u{1D157}\u{1D165}"], [119135, 1, "\u{1D158}\u{1D165}"], [119136, 1, "\u{1D158}\u{1D165}\u{1D16E}"], [119137, 1, "\u{1D158}\u{1D165}\u{1D16F}"], [119138, 1, "\u{1D158}\u{1D165}\u{1D170}"], [119139, 1, "\u{1D158}\u{1D165}\u{1D171}"], [119140, 1, "\u{1D158}\u{1D165}\u{1D172}"], [[119141, 119154], 2], [[119155, 119162], 3], [[119163, 119226], 2], [119227, 1, "\u{1D1B9}\u{1D165}"], [119228, 1, "\u{1D1BA}\u{1D165}"], [119229, 1, "\u{1D1B9}\u{1D165}\u{1D16E}"], [119230, 1, "\u{1D1BA}\u{1D165}\u{1D16E}"], [119231, 1, "\u{1D1B9}\u{1D165}\u{1D16F}"], [119232, 1, "\u{1D1BA}\u{1D165}\u{1D16F}"], [[119233, 119261], 2], [[119262, 119272], 2], [[119273, 119274], 2], [[119275, 119295], 3], [[119296, 119365], 2], [[119366, 119519], 3], [[119520, 119539], 2], [[119540, 119551], 3], [[119552, 119638], 2], [[119639, 119647], 3], [[119648, 119665], 2], [[119666, 119672], 2], [[119673, 119807], 3], [119808, 1, "a"], [119809, 1, "b"], [119810, 1, "c"], [119811, 1, "d"], [119812, 1, "e"], [119813, 1, "f"], [119814, 1, "g"], [119815, 1, "h"], [119816, 1, "i"], [119817, 1, "j"], [119818, 1, "k"], [119819, 1, "l"], [119820, 1, "m"], [119821, 1, "n"], [119822, 1, "o"], [119823, 1, "p"], [119824, 1, "q"], [119825, 1, "r"], [119826, 1, "s"], [119827, 1, "t"], [119828, 1, "u"], [119829, 1, "v"], [119830, 1, "w"], [119831, 1, "x"], [119832, 1, "y"], [119833, 1, "z"], [119834, 1, "a"], [119835, 1, "b"], [119836, 1, "c"], [119837, 1, "d"], [119838, 1, "e"], [119839, 1, "f"], [119840, 1, "g"], [119841, 1, "h"], [119842, 1, "i"], [119843, 1, "j"], [119844, 1, "k"], [119845, 1, "l"], [119846, 1, "m"], [119847, 1, "n"], [119848, 1, "o"], [119849, 1, "p"], [119850, 1, "q"], [119851, 1, "r"], [119852, 1, "s"], [119853, 1, "t"], [119854, 1, "u"], [119855, 1, "v"], [119856, 1, "w"], [119857, 1, "x"], [119858, 1, "y"], [119859, 1, "z"], [119860, 1, "a"], [119861, 1, "b"], [119862, 1, "c"], [119863, 1, "d"], [119864, 1, "e"], [119865, 1, "f"], [119866, 1, "g"], [119867, 1, "h"], [119868, 1, "i"], [119869, 1, "j"], [119870, 1, "k"], [119871, 1, "l"], [119872, 1, "m"], [119873, 1, "n"], [119874, 1, "o"], [119875, 1, "p"], [119876, 1, "q"], [119877, 1, "r"], [119878, 1, "s"], [119879, 1, "t"], [119880, 1, "u"], [119881, 1, "v"], [119882, 1, "w"], [119883, 1, "x"], [119884, 1, "y"], [119885, 1, "z"], [119886, 1, "a"], [119887, 1, "b"], [119888, 1, "c"], [119889, 1, "d"], [119890, 1, "e"], [119891, 1, "f"], [119892, 1, "g"], [119893, 3], [119894, 1, "i"], [119895, 1, "j"], [119896, 1, "k"], [119897, 1, "l"], [119898, 1, "m"], [119899, 1, "n"], [119900, 1, "o"], [119901, 1, "p"], [119902, 1, "q"], [119903, 1, "r"], [119904, 1, "s"], [119905, 1, "t"], [119906, 1, "u"], [119907, 1, "v"], [119908, 1, "w"], [119909, 1, "x"], [119910, 1, "y"], [119911, 1, "z"], [119912, 1, "a"], [119913, 1, "b"], [119914, 1, "c"], [119915, 1, "d"], [119916, 1, "e"], [119917, 1, "f"], [119918, 1, "g"], [119919, 1, "h"], [119920, 1, "i"], [119921, 1, "j"], [119922, 1, "k"], [119923, 1, "l"], [119924, 1, "m"], [119925, 1, "n"], [119926, 1, "o"], [119927, 1, "p"], [119928, 1, "q"], [119929, 1, "r"], [119930, 1, "s"], [119931, 1, "t"], [119932, 1, "u"], [119933, 1, "v"], [119934, 1, "w"], [119935, 1, "x"], [119936, 1, "y"], [119937, 1, "z"], [119938, 1, "a"], [119939, 1, "b"], [119940, 1, "c"], [119941, 1, "d"], [119942, 1, "e"], [119943, 1, "f"], [119944, 1, "g"], [119945, 1, "h"], [119946, 1, "i"], [119947, 1, "j"], [119948, 1, "k"], [119949, 1, "l"], [119950, 1, "m"], [119951, 1, "n"], [119952, 1, "o"], [119953, 1, "p"], [119954, 1, "q"], [119955, 1, "r"], [119956, 1, "s"], [119957, 1, "t"], [119958, 1, "u"], [119959, 1, "v"], [119960, 1, "w"], [119961, 1, "x"], [119962, 1, "y"], [119963, 1, "z"], [119964, 1, "a"], [119965, 3], [119966, 1, "c"], [119967, 1, "d"], [[119968, 119969], 3], [119970, 1, "g"], [[119971, 119972], 3], [119973, 1, "j"], [119974, 1, "k"], [[119975, 119976], 3], [119977, 1, "n"], [119978, 1, "o"], [119979, 1, "p"], [119980, 1, "q"], [119981, 3], [119982, 1, "s"], [119983, 1, "t"], [119984, 1, "u"], [119985, 1, "v"], [119986, 1, "w"], [119987, 1, "x"], [119988, 1, "y"], [119989, 1, "z"], [119990, 1, "a"], [119991, 1, "b"], [119992, 1, "c"], [119993, 1, "d"], [119994, 3], [119995, 1, "f"], [119996, 3], [119997, 1, "h"], [119998, 1, "i"], [119999, 1, "j"], [12e4, 1, "k"], [120001, 1, "l"], [120002, 1, "m"], [120003, 1, "n"], [120004, 3], [120005, 1, "p"], [120006, 1, "q"], [120007, 1, "r"], [120008, 1, "s"], [120009, 1, "t"], [120010, 1, "u"], [120011, 1, "v"], [120012, 1, "w"], [120013, 1, "x"], [120014, 1, "y"], [120015, 1, "z"], [120016, 1, "a"], [120017, 1, "b"], [120018, 1, "c"], [120019, 1, "d"], [120020, 1, "e"], [120021, 1, "f"], [120022, 1, "g"], [120023, 1, "h"], [120024, 1, "i"], [120025, 1, "j"], [120026, 1, "k"], [120027, 1, "l"], [120028, 1, "m"], [120029, 1, "n"], [120030, 1, "o"], [120031, 1, "p"], [120032, 1, "q"], [120033, 1, "r"], [120034, 1, "s"], [120035, 1, "t"], [120036, 1, "u"], [120037, 1, "v"], [120038, 1, "w"], [120039, 1, "x"], [120040, 1, "y"], [120041, 1, "z"], [120042, 1, "a"], [120043, 1, "b"], [120044, 1, "c"], [120045, 1, "d"], [120046, 1, "e"], [120047, 1, "f"], [120048, 1, "g"], [120049, 1, "h"], [120050, 1, "i"], [120051, 1, "j"], [120052, 1, "k"], [120053, 1, "l"], [120054, 1, "m"], [120055, 1, "n"], [120056, 1, "o"], [120057, 1, "p"], [120058, 1, "q"], [120059, 1, "r"], [120060, 1, "s"], [120061, 1, "t"], [120062, 1, "u"], [120063, 1, "v"], [120064, 1, "w"], [120065, 1, "x"], [120066, 1, "y"], [120067, 1, "z"], [120068, 1, "a"], [120069, 1, "b"], [120070, 3], [120071, 1, "d"], [120072, 1, "e"], [120073, 1, "f"], [120074, 1, "g"], [[120075, 120076], 3], [120077, 1, "j"], [120078, 1, "k"], [120079, 1, "l"], [120080, 1, "m"], [120081, 1, "n"], [120082, 1, "o"], [120083, 1, "p"], [120084, 1, "q"], [120085, 3], [120086, 1, "s"], [120087, 1, "t"], [120088, 1, "u"], [120089, 1, "v"], [120090, 1, "w"], [120091, 1, "x"], [120092, 1, "y"], [120093, 3], [120094, 1, "a"], [120095, 1, "b"], [120096, 1, "c"], [120097, 1, "d"], [120098, 1, "e"], [120099, 1, "f"], [120100, 1, "g"], [120101, 1, "h"], [120102, 1, "i"], [120103, 1, "j"], [120104, 1, "k"], [120105, 1, "l"], [120106, 1, "m"], [120107, 1, "n"], [120108, 1, "o"], [120109, 1, "p"], [120110, 1, "q"], [120111, 1, "r"], [120112, 1, "s"], [120113, 1, "t"], [120114, 1, "u"], [120115, 1, "v"], [120116, 1, "w"], [120117, 1, "x"], [120118, 1, "y"], [120119, 1, "z"], [120120, 1, "a"], [120121, 1, "b"], [120122, 3], [120123, 1, "d"], [120124, 1, "e"], [120125, 1, "f"], [120126, 1, "g"], [120127, 3], [120128, 1, "i"], [120129, 1, "j"], [120130, 1, "k"], [120131, 1, "l"], [120132, 1, "m"], [120133, 3], [120134, 1, "o"], [[120135, 120137], 3], [120138, 1, "s"], [120139, 1, "t"], [120140, 1, "u"], [120141, 1, "v"], [120142, 1, "w"], [120143, 1, "x"], [120144, 1, "y"], [120145, 3], [120146, 1, "a"], [120147, 1, "b"], [120148, 1, "c"], [120149, 1, "d"], [120150, 1, "e"], [120151, 1, "f"], [120152, 1, "g"], [120153, 1, "h"], [120154, 1, "i"], [120155, 1, "j"], [120156, 1, "k"], [120157, 1, "l"], [120158, 1, "m"], [120159, 1, "n"], [120160, 1, "o"], [120161, 1, "p"], [120162, 1, "q"], [120163, 1, "r"], [120164, 1, "s"], [120165, 1, "t"], [120166, 1, "u"], [120167, 1, "v"], [120168, 1, "w"], [120169, 1, "x"], [120170, 1, "y"], [120171, 1, "z"], [120172, 1, "a"], [120173, 1, "b"], [120174, 1, "c"], [120175, 1, "d"], [120176, 1, "e"], [120177, 1, "f"], [120178, 1, "g"], [120179, 1, "h"], [120180, 1, "i"], [120181, 1, "j"], [120182, 1, "k"], [120183, 1, "l"], [120184, 1, "m"], [120185, 1, "n"], [120186, 1, "o"], [120187, 1, "p"], [120188, 1, "q"], [120189, 1, "r"], [120190, 1, "s"], [120191, 1, "t"], [120192, 1, "u"], [120193, 1, "v"], [120194, 1, "w"], [120195, 1, "x"], [120196, 1, "y"], [120197, 1, "z"], [120198, 1, "a"], [120199, 1, "b"], [120200, 1, "c"], [120201, 1, "d"], [120202, 1, "e"], [120203, 1, "f"], [120204, 1, "g"], [120205, 1, "h"], [120206, 1, "i"], [120207, 1, "j"], [120208, 1, "k"], [120209, 1, "l"], [120210, 1, "m"], [120211, 1, "n"], [120212, 1, "o"], [120213, 1, "p"], [120214, 1, "q"], [120215, 1, "r"], [120216, 1, "s"], [120217, 1, "t"], [120218, 1, "u"], [120219, 1, "v"], [120220, 1, "w"], [120221, 1, "x"], [120222, 1, "y"], [120223, 1, "z"], [120224, 1, "a"], [120225, 1, "b"], [120226, 1, "c"], [120227, 1, "d"], [120228, 1, "e"], [120229, 1, "f"], [120230, 1, "g"], [120231, 1, "h"], [120232, 1, "i"], [120233, 1, "j"], [120234, 1, "k"], [120235, 1, "l"], [120236, 1, "m"], [120237, 1, "n"], [120238, 1, "o"], [120239, 1, "p"], [120240, 1, "q"], [120241, 1, "r"], [120242, 1, "s"], [120243, 1, "t"], [120244, 1, "u"], [120245, 1, "v"], [120246, 1, "w"], [120247, 1, "x"], [120248, 1, "y"], [120249, 1, "z"], [120250, 1, "a"], [120251, 1, "b"], [120252, 1, "c"], [120253, 1, "d"], [120254, 1, "e"], [120255, 1, "f"], [120256, 1, "g"], [120257, 1, "h"], [120258, 1, "i"], [120259, 1, "j"], [120260, 1, "k"], [120261, 1, "l"], [120262, 1, "m"], [120263, 1, "n"], [120264, 1, "o"], [120265, 1, "p"], [120266, 1, "q"], [120267, 1, "r"], [120268, 1, "s"], [120269, 1, "t"], [120270, 1, "u"], [120271, 1, "v"], [120272, 1, "w"], [120273, 1, "x"], [120274, 1, "y"], [120275, 1, "z"], [120276, 1, "a"], [120277, 1, "b"], [120278, 1, "c"], [120279, 1, "d"], [120280, 1, "e"], [120281, 1, "f"], [120282, 1, "g"], [120283, 1, "h"], [120284, 1, "i"], [120285, 1, "j"], [120286, 1, "k"], [120287, 1, "l"], [120288, 1, "m"], [120289, 1, "n"], [120290, 1, "o"], [120291, 1, "p"], [120292, 1, "q"], [120293, 1, "r"], [120294, 1, "s"], [120295, 1, "t"], [120296, 1, "u"], [120297, 1, "v"], [120298, 1, "w"], [120299, 1, "x"], [120300, 1, "y"], [120301, 1, "z"], [120302, 1, "a"], [120303, 1, "b"], [120304, 1, "c"], [120305, 1, "d"], [120306, 1, "e"], [120307, 1, "f"], [120308, 1, "g"], [120309, 1, "h"], [120310, 1, "i"], [120311, 1, "j"], [120312, 1, "k"], [120313, 1, "l"], [120314, 1, "m"], [120315, 1, "n"], [120316, 1, "o"], [120317, 1, "p"], [120318, 1, "q"], [120319, 1, "r"], [120320, 1, "s"], [120321, 1, "t"], [120322, 1, "u"], [120323, 1, "v"], [120324, 1, "w"], [120325, 1, "x"], [120326, 1, "y"], [120327, 1, "z"], [120328, 1, "a"], [120329, 1, "b"], [120330, 1, "c"], [120331, 1, "d"], [120332, 1, "e"], [120333, 1, "f"], [120334, 1, "g"], [120335, 1, "h"], [120336, 1, "i"], [120337, 1, "j"], [120338, 1, "k"], [120339, 1, "l"], [120340, 1, "m"], [120341, 1, "n"], [120342, 1, "o"], [120343, 1, "p"], [120344, 1, "q"], [120345, 1, "r"], [120346, 1, "s"], [120347, 1, "t"], [120348, 1, "u"], [120349, 1, "v"], [120350, 1, "w"], [120351, 1, "x"], [120352, 1, "y"], [120353, 1, "z"], [120354, 1, "a"], [120355, 1, "b"], [120356, 1, "c"], [120357, 1, "d"], [120358, 1, "e"], [120359, 1, "f"], [120360, 1, "g"], [120361, 1, "h"], [120362, 1, "i"], [120363, 1, "j"], [120364, 1, "k"], [120365, 1, "l"], [120366, 1, "m"], [120367, 1, "n"], [120368, 1, "o"], [120369, 1, "p"], [120370, 1, "q"], [120371, 1, "r"], [120372, 1, "s"], [120373, 1, "t"], [120374, 1, "u"], [120375, 1, "v"], [120376, 1, "w"], [120377, 1, "x"], [120378, 1, "y"], [120379, 1, "z"], [120380, 1, "a"], [120381, 1, "b"], [120382, 1, "c"], [120383, 1, "d"], [120384, 1, "e"], [120385, 1, "f"], [120386, 1, "g"], [120387, 1, "h"], [120388, 1, "i"], [120389, 1, "j"], [120390, 1, "k"], [120391, 1, "l"], [120392, 1, "m"], [120393, 1, "n"], [120394, 1, "o"], [120395, 1, "p"], [120396, 1, "q"], [120397, 1, "r"], [120398, 1, "s"], [120399, 1, "t"], [120400, 1, "u"], [120401, 1, "v"], [120402, 1, "w"], [120403, 1, "x"], [120404, 1, "y"], [120405, 1, "z"], [120406, 1, "a"], [120407, 1, "b"], [120408, 1, "c"], [120409, 1, "d"], [120410, 1, "e"], [120411, 1, "f"], [120412, 1, "g"], [120413, 1, "h"], [120414, 1, "i"], [120415, 1, "j"], [120416, 1, "k"], [120417, 1, "l"], [120418, 1, "m"], [120419, 1, "n"], [120420, 1, "o"], [120421, 1, "p"], [120422, 1, "q"], [120423, 1, "r"], [120424, 1, "s"], [120425, 1, "t"], [120426, 1, "u"], [120427, 1, "v"], [120428, 1, "w"], [120429, 1, "x"], [120430, 1, "y"], [120431, 1, "z"], [120432, 1, "a"], [120433, 1, "b"], [120434, 1, "c"], [120435, 1, "d"], [120436, 1, "e"], [120437, 1, "f"], [120438, 1, "g"], [120439, 1, "h"], [120440, 1, "i"], [120441, 1, "j"], [120442, 1, "k"], [120443, 1, "l"], [120444, 1, "m"], [120445, 1, "n"], [120446, 1, "o"], [120447, 1, "p"], [120448, 1, "q"], [120449, 1, "r"], [120450, 1, "s"], [120451, 1, "t"], [120452, 1, "u"], [120453, 1, "v"], [120454, 1, "w"], [120455, 1, "x"], [120456, 1, "y"], [120457, 1, "z"], [120458, 1, "a"], [120459, 1, "b"], [120460, 1, "c"], [120461, 1, "d"], [120462, 1, "e"], [120463, 1, "f"], [120464, 1, "g"], [120465, 1, "h"], [120466, 1, "i"], [120467, 1, "j"], [120468, 1, "k"], [120469, 1, "l"], [120470, 1, "m"], [120471, 1, "n"], [120472, 1, "o"], [120473, 1, "p"], [120474, 1, "q"], [120475, 1, "r"], [120476, 1, "s"], [120477, 1, "t"], [120478, 1, "u"], [120479, 1, "v"], [120480, 1, "w"], [120481, 1, "x"], [120482, 1, "y"], [120483, 1, "z"], [120484, 1, "\u0131"], [120485, 1, "\u0237"], [[120486, 120487], 3], [120488, 1, "\u03B1"], [120489, 1, "\u03B2"], [120490, 1, "\u03B3"], [120491, 1, "\u03B4"], [120492, 1, "\u03B5"], [120493, 1, "\u03B6"], [120494, 1, "\u03B7"], [120495, 1, "\u03B8"], [120496, 1, "\u03B9"], [120497, 1, "\u03BA"], [120498, 1, "\u03BB"], [120499, 1, "\u03BC"], [120500, 1, "\u03BD"], [120501, 1, "\u03BE"], [120502, 1, "\u03BF"], [120503, 1, "\u03C0"], [120504, 1, "\u03C1"], [120505, 1, "\u03B8"], [120506, 1, "\u03C3"], [120507, 1, "\u03C4"], [120508, 1, "\u03C5"], [120509, 1, "\u03C6"], [120510, 1, "\u03C7"], [120511, 1, "\u03C8"], [120512, 1, "\u03C9"], [120513, 1, "\u2207"], [120514, 1, "\u03B1"], [120515, 1, "\u03B2"], [120516, 1, "\u03B3"], [120517, 1, "\u03B4"], [120518, 1, "\u03B5"], [120519, 1, "\u03B6"], [120520, 1, "\u03B7"], [120521, 1, "\u03B8"], [120522, 1, "\u03B9"], [120523, 1, "\u03BA"], [120524, 1, "\u03BB"], [120525, 1, "\u03BC"], [120526, 1, "\u03BD"], [120527, 1, "\u03BE"], [120528, 1, "\u03BF"], [120529, 1, "\u03C0"], [120530, 1, "\u03C1"], [[120531, 120532], 1, "\u03C3"], [120533, 1, "\u03C4"], [120534, 1, "\u03C5"], [120535, 1, "\u03C6"], [120536, 1, "\u03C7"], [120537, 1, "\u03C8"], [120538, 1, "\u03C9"], [120539, 1, "\u2202"], [120540, 1, "\u03B5"], [120541, 1, "\u03B8"], [120542, 1, "\u03BA"], [120543, 1, "\u03C6"], [120544, 1, "\u03C1"], [120545, 1, "\u03C0"], [120546, 1, "\u03B1"], [120547, 1, "\u03B2"], [120548, 1, "\u03B3"], [120549, 1, "\u03B4"], [120550, 1, "\u03B5"], [120551, 1, "\u03B6"], [120552, 1, "\u03B7"], [120553, 1, "\u03B8"], [120554, 1, "\u03B9"], [120555, 1, "\u03BA"], [120556, 1, "\u03BB"], [120557, 1, "\u03BC"], [120558, 1, "\u03BD"], [120559, 1, "\u03BE"], [120560, 1, "\u03BF"], [120561, 1, "\u03C0"], [120562, 1, "\u03C1"], [120563, 1, "\u03B8"], [120564, 1, "\u03C3"], [120565, 1, "\u03C4"], [120566, 1, "\u03C5"], [120567, 1, "\u03C6"], [120568, 1, "\u03C7"], [120569, 1, "\u03C8"], [120570, 1, "\u03C9"], [120571, 1, "\u2207"], [120572, 1, "\u03B1"], [120573, 1, "\u03B2"], [120574, 1, "\u03B3"], [120575, 1, "\u03B4"], [120576, 1, "\u03B5"], [120577, 1, "\u03B6"], [120578, 1, "\u03B7"], [120579, 1, "\u03B8"], [120580, 1, "\u03B9"], [120581, 1, "\u03BA"], [120582, 1, "\u03BB"], [120583, 1, "\u03BC"], [120584, 1, "\u03BD"], [120585, 1, "\u03BE"], [120586, 1, "\u03BF"], [120587, 1, "\u03C0"], [120588, 1, "\u03C1"], [[120589, 120590], 1, "\u03C3"], [120591, 1, "\u03C4"], [120592, 1, "\u03C5"], [120593, 1, "\u03C6"], [120594, 1, "\u03C7"], [120595, 1, "\u03C8"], [120596, 1, "\u03C9"], [120597, 1, "\u2202"], [120598, 1, "\u03B5"], [120599, 1, "\u03B8"], [120600, 1, "\u03BA"], [120601, 1, "\u03C6"], [120602, 1, "\u03C1"], [120603, 1, "\u03C0"], [120604, 1, "\u03B1"], [120605, 1, "\u03B2"], [120606, 1, "\u03B3"], [120607, 1, "\u03B4"], [120608, 1, "\u03B5"], [120609, 1, "\u03B6"], [120610, 1, "\u03B7"], [120611, 1, "\u03B8"], [120612, 1, "\u03B9"], [120613, 1, "\u03BA"], [120614, 1, "\u03BB"], [120615, 1, "\u03BC"], [120616, 1, "\u03BD"], [120617, 1, "\u03BE"], [120618, 1, "\u03BF"], [120619, 1, "\u03C0"], [120620, 1, "\u03C1"], [120621, 1, "\u03B8"], [120622, 1, "\u03C3"], [120623, 1, "\u03C4"], [120624, 1, "\u03C5"], [120625, 1, "\u03C6"], [120626, 1, "\u03C7"], [120627, 1, "\u03C8"], [120628, 1, "\u03C9"], [120629, 1, "\u2207"], [120630, 1, "\u03B1"], [120631, 1, "\u03B2"], [120632, 1, "\u03B3"], [120633, 1, "\u03B4"], [120634, 1, "\u03B5"], [120635, 1, "\u03B6"], [120636, 1, "\u03B7"], [120637, 1, "\u03B8"], [120638, 1, "\u03B9"], [120639, 1, "\u03BA"], [120640, 1, "\u03BB"], [120641, 1, "\u03BC"], [120642, 1, "\u03BD"], [120643, 1, "\u03BE"], [120644, 1, "\u03BF"], [120645, 1, "\u03C0"], [120646, 1, "\u03C1"], [[120647, 120648], 1, "\u03C3"], [120649, 1, "\u03C4"], [120650, 1, "\u03C5"], [120651, 1, "\u03C6"], [120652, 1, "\u03C7"], [120653, 1, "\u03C8"], [120654, 1, "\u03C9"], [120655, 1, "\u2202"], [120656, 1, "\u03B5"], [120657, 1, "\u03B8"], [120658, 1, "\u03BA"], [120659, 1, "\u03C6"], [120660, 1, "\u03C1"], [120661, 1, "\u03C0"], [120662, 1, "\u03B1"], [120663, 1, "\u03B2"], [120664, 1, "\u03B3"], [120665, 1, "\u03B4"], [120666, 1, "\u03B5"], [120667, 1, "\u03B6"], [120668, 1, "\u03B7"], [120669, 1, "\u03B8"], [120670, 1, "\u03B9"], [120671, 1, "\u03BA"], [120672, 1, "\u03BB"], [120673, 1, "\u03BC"], [120674, 1, "\u03BD"], [120675, 1, "\u03BE"], [120676, 1, "\u03BF"], [120677, 1, "\u03C0"], [120678, 1, "\u03C1"], [120679, 1, "\u03B8"], [120680, 1, "\u03C3"], [120681, 1, "\u03C4"], [120682, 1, "\u03C5"], [120683, 1, "\u03C6"], [120684, 1, "\u03C7"], [120685, 1, "\u03C8"], [120686, 1, "\u03C9"], [120687, 1, "\u2207"], [120688, 1, "\u03B1"], [120689, 1, "\u03B2"], [120690, 1, "\u03B3"], [120691, 1, "\u03B4"], [120692, 1, "\u03B5"], [120693, 1, "\u03B6"], [120694, 1, "\u03B7"], [120695, 1, "\u03B8"], [120696, 1, "\u03B9"], [120697, 1, "\u03BA"], [120698, 1, "\u03BB"], [120699, 1, "\u03BC"], [120700, 1, "\u03BD"], [120701, 1, "\u03BE"], [120702, 1, "\u03BF"], [120703, 1, "\u03C0"], [120704, 1, "\u03C1"], [[120705, 120706], 1, "\u03C3"], [120707, 1, "\u03C4"], [120708, 1, "\u03C5"], [120709, 1, "\u03C6"], [120710, 1, "\u03C7"], [120711, 1, "\u03C8"], [120712, 1, "\u03C9"], [120713, 1, "\u2202"], [120714, 1, "\u03B5"], [120715, 1, "\u03B8"], [120716, 1, "\u03BA"], [120717, 1, "\u03C6"], [120718, 1, "\u03C1"], [120719, 1, "\u03C0"], [120720, 1, "\u03B1"], [120721, 1, "\u03B2"], [120722, 1, "\u03B3"], [120723, 1, "\u03B4"], [120724, 1, "\u03B5"], [120725, 1, "\u03B6"], [120726, 1, "\u03B7"], [120727, 1, "\u03B8"], [120728, 1, "\u03B9"], [120729, 1, "\u03BA"], [120730, 1, "\u03BB"], [120731, 1, "\u03BC"], [120732, 1, "\u03BD"], [120733, 1, "\u03BE"], [120734, 1, "\u03BF"], [120735, 1, "\u03C0"], [120736, 1, "\u03C1"], [120737, 1, "\u03B8"], [120738, 1, "\u03C3"], [120739, 1, "\u03C4"], [120740, 1, "\u03C5"], [120741, 1, "\u03C6"], [120742, 1, "\u03C7"], [120743, 1, "\u03C8"], [120744, 1, "\u03C9"], [120745, 1, "\u2207"], [120746, 1, "\u03B1"], [120747, 1, "\u03B2"], [120748, 1, "\u03B3"], [120749, 1, "\u03B4"], [120750, 1, "\u03B5"], [120751, 1, "\u03B6"], [120752, 1, "\u03B7"], [120753, 1, "\u03B8"], [120754, 1, "\u03B9"], [120755, 1, "\u03BA"], [120756, 1, "\u03BB"], [120757, 1, "\u03BC"], [120758, 1, "\u03BD"], [120759, 1, "\u03BE"], [120760, 1, "\u03BF"], [120761, 1, "\u03C0"], [120762, 1, "\u03C1"], [[120763, 120764], 1, "\u03C3"], [120765, 1, "\u03C4"], [120766, 1, "\u03C5"], [120767, 1, "\u03C6"], [120768, 1, "\u03C7"], [120769, 1, "\u03C8"], [120770, 1, "\u03C9"], [120771, 1, "\u2202"], [120772, 1, "\u03B5"], [120773, 1, "\u03B8"], [120774, 1, "\u03BA"], [120775, 1, "\u03C6"], [120776, 1, "\u03C1"], [120777, 1, "\u03C0"], [[120778, 120779], 1, "\u03DD"], [[120780, 120781], 3], [120782, 1, "0"], [120783, 1, "1"], [120784, 1, "2"], [120785, 1, "3"], [120786, 1, "4"], [120787, 1, "5"], [120788, 1, "6"], [120789, 1, "7"], [120790, 1, "8"], [120791, 1, "9"], [120792, 1, "0"], [120793, 1, "1"], [120794, 1, "2"], [120795, 1, "3"], [120796, 1, "4"], [120797, 1, "5"], [120798, 1, "6"], [120799, 1, "7"], [120800, 1, "8"], [120801, 1, "9"], [120802, 1, "0"], [120803, 1, "1"], [120804, 1, "2"], [120805, 1, "3"], [120806, 1, "4"], [120807, 1, "5"], [120808, 1, "6"], [120809, 1, "7"], [120810, 1, "8"], [120811, 1, "9"], [120812, 1, "0"], [120813, 1, "1"], [120814, 1, "2"], [120815, 1, "3"], [120816, 1, "4"], [120817, 1, "5"], [120818, 1, "6"], [120819, 1, "7"], [120820, 1, "8"], [120821, 1, "9"], [120822, 1, "0"], [120823, 1, "1"], [120824, 1, "2"], [120825, 1, "3"], [120826, 1, "4"], [120827, 1, "5"], [120828, 1, "6"], [120829, 1, "7"], [120830, 1, "8"], [120831, 1, "9"], [[120832, 121343], 2], [[121344, 121398], 2], [[121399, 121402], 2], [[121403, 121452], 2], [[121453, 121460], 2], [121461, 2], [[121462, 121475], 2], [121476, 2], [[121477, 121483], 2], [[121484, 121498], 3], [[121499, 121503], 2], [121504, 3], [[121505, 121519], 2], [[121520, 122623], 3], [[122624, 122654], 2], [[122655, 122879], 3], [[122880, 122886], 2], [122887, 3], [[122888, 122904], 2], [[122905, 122906], 3], [[122907, 122913], 2], [122914, 3], [[122915, 122916], 2], [122917, 3], [[122918, 122922], 2], [[122923, 123135], 3], [[123136, 123180], 2], [[123181, 123183], 3], [[123184, 123197], 2], [[123198, 123199], 3], [[123200, 123209], 2], [[123210, 123213], 3], [123214, 2], [123215, 2], [[123216, 123535], 3], [[123536, 123566], 2], [[123567, 123583], 3], [[123584, 123641], 2], [[123642, 123646], 3], [123647, 2], [[123648, 124895], 3], [[124896, 124902], 2], [124903, 3], [[124904, 124907], 2], [124908, 3], [[124909, 124910], 2], [124911, 3], [[124912, 124926], 2], [124927, 3], [[124928, 125124], 2], [[125125, 125126], 3], [[125127, 125135], 2], [[125136, 125142], 2], [[125143, 125183], 3], [125184, 1, "\u{1E922}"], [125185, 1, "\u{1E923}"], [125186, 1, "\u{1E924}"], [125187, 1, "\u{1E925}"], [125188, 1, "\u{1E926}"], [125189, 1, "\u{1E927}"], [125190, 1, "\u{1E928}"], [125191, 1, "\u{1E929}"], [125192, 1, "\u{1E92A}"], [125193, 1, "\u{1E92B}"], [125194, 1, "\u{1E92C}"], [125195, 1, "\u{1E92D}"], [125196, 1, "\u{1E92E}"], [125197, 1, "\u{1E92F}"], [125198, 1, "\u{1E930}"], [125199, 1, "\u{1E931}"], [125200, 1, "\u{1E932}"], [125201, 1, "\u{1E933}"], [125202, 1, "\u{1E934}"], [125203, 1, "\u{1E935}"], [125204, 1, "\u{1E936}"], [125205, 1, "\u{1E937}"], [125206, 1, "\u{1E938}"], [125207, 1, "\u{1E939}"], [125208, 1, "\u{1E93A}"], [125209, 1, "\u{1E93B}"], [125210, 1, "\u{1E93C}"], [125211, 1, "\u{1E93D}"], [125212, 1, "\u{1E93E}"], [125213, 1, "\u{1E93F}"], [125214, 1, "\u{1E940}"], [125215, 1, "\u{1E941}"], [125216, 1, "\u{1E942}"], [125217, 1, "\u{1E943}"], [[125218, 125258], 2], [125259, 2], [[125260, 125263], 3], [[125264, 125273], 2], [[125274, 125277], 3], [[125278, 125279], 2], [[125280, 126064], 3], [[126065, 126132], 2], [[126133, 126208], 3], [[126209, 126269], 2], [[126270, 126463], 3], [126464, 1, "\u0627"], [126465, 1, "\u0628"], [126466, 1, "\u062C"], [126467, 1, "\u062F"], [126468, 3], [126469, 1, "\u0648"], [126470, 1, "\u0632"], [126471, 1, "\u062D"], [126472, 1, "\u0637"], [126473, 1, "\u064A"], [126474, 1, "\u0643"], [126475, 1, "\u0644"], [126476, 1, "\u0645"], [126477, 1, "\u0646"], [126478, 1, "\u0633"], [126479, 1, "\u0639"], [126480, 1, "\u0641"], [126481, 1, "\u0635"], [126482, 1, "\u0642"], [126483, 1, "\u0631"], [126484, 1, "\u0634"], [126485, 1, "\u062A"], [126486, 1, "\u062B"], [126487, 1, "\u062E"], [126488, 1, "\u0630"], [126489, 1, "\u0636"], [126490, 1, "\u0638"], [126491, 1, "\u063A"], [126492, 1, "\u066E"], [126493, 1, "\u06BA"], [126494, 1, "\u06A1"], [126495, 1, "\u066F"], [126496, 3], [126497, 1, "\u0628"], [126498, 1, "\u062C"], [126499, 3], [126500, 1, "\u0647"], [[126501, 126502], 3], [126503, 1, "\u062D"], [126504, 3], [126505, 1, "\u064A"], [126506, 1, "\u0643"], [126507, 1, "\u0644"], [126508, 1, "\u0645"], [126509, 1, "\u0646"], [126510, 1, "\u0633"], [126511, 1, "\u0639"], [126512, 1, "\u0641"], [126513, 1, "\u0635"], [126514, 1, "\u0642"], [126515, 3], [126516, 1, "\u0634"], [126517, 1, "\u062A"], [126518, 1, "\u062B"], [126519, 1, "\u062E"], [126520, 3], [126521, 1, "\u0636"], [126522, 3], [126523, 1, "\u063A"], [[126524, 126529], 3], [126530, 1, "\u062C"], [[126531, 126534], 3], [126535, 1, "\u062D"], [126536, 3], [126537, 1, "\u064A"], [126538, 3], [126539, 1, "\u0644"], [126540, 3], [126541, 1, "\u0646"], [126542, 1, "\u0633"], [126543, 1, "\u0639"], [126544, 3], [126545, 1, "\u0635"], [126546, 1, "\u0642"], [126547, 3], [126548, 1, "\u0634"], [[126549, 126550], 3], [126551, 1, "\u062E"], [126552, 3], [126553, 1, "\u0636"], [126554, 3], [126555, 1, "\u063A"], [126556, 3], [126557, 1, "\u06BA"], [126558, 3], [126559, 1, "\u066F"], [126560, 3], [126561, 1, "\u0628"], [126562, 1, "\u062C"], [126563, 3], [126564, 1, "\u0647"], [[126565, 126566], 3], [126567, 1, "\u062D"], [126568, 1, "\u0637"], [126569, 1, "\u064A"], [126570, 1, "\u0643"], [126571, 3], [126572, 1, "\u0645"], [126573, 1, "\u0646"], [126574, 1, "\u0633"], [126575, 1, "\u0639"], [126576, 1, "\u0641"], [126577, 1, "\u0635"], [126578, 1, "\u0642"], [126579, 3], [126580, 1, "\u0634"], [126581, 1, "\u062A"], [126582, 1, "\u062B"], [126583, 1, "\u062E"], [126584, 3], [126585, 1, "\u0636"], [126586, 1, "\u0638"], [126587, 1, "\u063A"], [126588, 1, "\u066E"], [126589, 3], [126590, 1, "\u06A1"], [126591, 3], [126592, 1, "\u0627"], [126593, 1, "\u0628"], [126594, 1, "\u062C"], [126595, 1, "\u062F"], [126596, 1, "\u0647"], [126597, 1, "\u0648"], [126598, 1, "\u0632"], [126599, 1, "\u062D"], [126600, 1, "\u0637"], [126601, 1, "\u064A"], [126602, 3], [126603, 1, "\u0644"], [126604, 1, "\u0645"], [126605, 1, "\u0646"], [126606, 1, "\u0633"], [126607, 1, "\u0639"], [126608, 1, "\u0641"], [126609, 1, "\u0635"], [126610, 1, "\u0642"], [126611, 1, "\u0631"], [126612, 1, "\u0634"], [126613, 1, "\u062A"], [126614, 1, "\u062B"], [126615, 1, "\u062E"], [126616, 1, "\u0630"], [126617, 1, "\u0636"], [126618, 1, "\u0638"], [126619, 1, "\u063A"], [[126620, 126624], 3], [126625, 1, "\u0628"], [126626, 1, "\u062C"], [126627, 1, "\u062F"], [126628, 3], [126629, 1, "\u0648"], [126630, 1, "\u0632"], [126631, 1, "\u062D"], [126632, 1, "\u0637"], [126633, 1, "\u064A"], [126634, 3], [126635, 1, "\u0644"], [126636, 1, "\u0645"], [126637, 1, "\u0646"], [126638, 1, "\u0633"], [126639, 1, "\u0639"], [126640, 1, "\u0641"], [126641, 1, "\u0635"], [126642, 1, "\u0642"], [126643, 1, "\u0631"], [126644, 1, "\u0634"], [126645, 1, "\u062A"], [126646, 1, "\u062B"], [126647, 1, "\u062E"], [126648, 1, "\u0630"], [126649, 1, "\u0636"], [126650, 1, "\u0638"], [126651, 1, "\u063A"], [[126652, 126703], 3], [[126704, 126705], 2], [[126706, 126975], 3], [[126976, 127019], 2], [[127020, 127023], 3], [[127024, 127123], 2], [[127124, 127135], 3], [[127136, 127150], 2], [[127151, 127152], 3], [[127153, 127166], 2], [127167, 2], [127168, 3], [[127169, 127183], 2], [127184, 3], [[127185, 127199], 2], [[127200, 127221], 2], [[127222, 127231], 3], [127232, 3], [127233, 5, "0,"], [127234, 5, "1,"], [127235, 5, "2,"], [127236, 5, "3,"], [127237, 5, "4,"], [127238, 5, "5,"], [127239, 5, "6,"], [127240, 5, "7,"], [127241, 5, "8,"], [127242, 5, "9,"], [[127243, 127244], 2], [[127245, 127247], 2], [127248, 5, "(a)"], [127249, 5, "(b)"], [127250, 5, "(c)"], [127251, 5, "(d)"], [127252, 5, "(e)"], [127253, 5, "(f)"], [127254, 5, "(g)"], [127255, 5, "(h)"], [127256, 5, "(i)"], [127257, 5, "(j)"], [127258, 5, "(k)"], [127259, 5, "(l)"], [127260, 5, "(m)"], [127261, 5, "(n)"], [127262, 5, "(o)"], [127263, 5, "(p)"], [127264, 5, "(q)"], [127265, 5, "(r)"], [127266, 5, "(s)"], [127267, 5, "(t)"], [127268, 5, "(u)"], [127269, 5, "(v)"], [127270, 5, "(w)"], [127271, 5, "(x)"], [127272, 5, "(y)"], [127273, 5, "(z)"], [127274, 1, "\u3014s\u3015"], [127275, 1, "c"], [127276, 1, "r"], [127277, 1, "cd"], [127278, 1, "wz"], [127279, 2], [127280, 1, "a"], [127281, 1, "b"], [127282, 1, "c"], [127283, 1, "d"], [127284, 1, "e"], [127285, 1, "f"], [127286, 1, "g"], [127287, 1, "h"], [127288, 1, "i"], [127289, 1, "j"], [127290, 1, "k"], [127291, 1, "l"], [127292, 1, "m"], [127293, 1, "n"], [127294, 1, "o"], [127295, 1, "p"], [127296, 1, "q"], [127297, 1, "r"], [127298, 1, "s"], [127299, 1, "t"], [127300, 1, "u"], [127301, 1, "v"], [127302, 1, "w"], [127303, 1, "x"], [127304, 1, "y"], [127305, 1, "z"], [127306, 1, "hv"], [127307, 1, "mv"], [127308, 1, "sd"], [127309, 1, "ss"], [127310, 1, "ppv"], [127311, 1, "wc"], [[127312, 127318], 2], [127319, 2], [[127320, 127326], 2], [127327, 2], [[127328, 127337], 2], [127338, 1, "mc"], [127339, 1, "md"], [127340, 1, "mr"], [[127341, 127343], 2], [[127344, 127352], 2], [127353, 2], [127354, 2], [[127355, 127356], 2], [[127357, 127358], 2], [127359, 2], [[127360, 127369], 2], [[127370, 127373], 2], [[127374, 127375], 2], [127376, 1, "dj"], [[127377, 127386], 2], [[127387, 127404], 2], [127405, 2], [[127406, 127461], 3], [[127462, 127487], 2], [127488, 1, "\u307B\u304B"], [127489, 1, "\u30B3\u30B3"], [127490, 1, "\u30B5"], [[127491, 127503], 3], [127504, 1, "\u624B"], [127505, 1, "\u5B57"], [127506, 1, "\u53CC"], [127507, 1, "\u30C7"], [127508, 1, "\u4E8C"], [127509, 1, "\u591A"], [127510, 1, "\u89E3"], [127511, 1, "\u5929"], [127512, 1, "\u4EA4"], [127513, 1, "\u6620"], [127514, 1, "\u7121"], [127515, 1, "\u6599"], [127516, 1, "\u524D"], [127517, 1, "\u5F8C"], [127518, 1, "\u518D"], [127519, 1, "\u65B0"], [127520, 1, "\u521D"], [127521, 1, "\u7D42"], [127522, 1, "\u751F"], [127523, 1, "\u8CA9"], [127524, 1, "\u58F0"], [127525, 1, "\u5439"], [127526, 1, "\u6F14"], [127527, 1, "\u6295"], [127528, 1, "\u6355"], [127529, 1, "\u4E00"], [127530, 1, "\u4E09"], [127531, 1, "\u904A"], [127532, 1, "\u5DE6"], [127533, 1, "\u4E2D"], [127534, 1, "\u53F3"], [127535, 1, "\u6307"], [127536, 1, "\u8D70"], [127537, 1, "\u6253"], [127538, 1, "\u7981"], [127539, 1, "\u7A7A"], [127540, 1, "\u5408"], [127541, 1, "\u6E80"], [127542, 1, "\u6709"], [127543, 1, "\u6708"], [127544, 1, "\u7533"], [127545, 1, "\u5272"], [127546, 1, "\u55B6"], [127547, 1, "\u914D"], [[127548, 127551], 3], [127552, 1, "\u3014\u672C\u3015"], [127553, 1, "\u3014\u4E09\u3015"], [127554, 1, "\u3014\u4E8C\u3015"], [127555, 1, "\u3014\u5B89\u3015"], [127556, 1, "\u3014\u70B9\u3015"], [127557, 1, "\u3014\u6253\u3015"], [127558, 1, "\u3014\u76D7\u3015"], [127559, 1, "\u3014\u52DD\u3015"], [127560, 1, "\u3014\u6557\u3015"], [[127561, 127567], 3], [127568, 1, "\u5F97"], [127569, 1, "\u53EF"], [[127570, 127583], 3], [[127584, 127589], 2], [[127590, 127743], 3], [[127744, 127776], 2], [[127777, 127788], 2], [[127789, 127791], 2], [[127792, 127797], 2], [127798, 2], [[127799, 127868], 2], [127869, 2], [[127870, 127871], 2], [[127872, 127891], 2], [[127892, 127903], 2], [[127904, 127940], 2], [127941, 2], [[127942, 127946], 2], [[127947, 127950], 2], [[127951, 127955], 2], [[127956, 127967], 2], [[127968, 127984], 2], [[127985, 127991], 2], [[127992, 127999], 2], [[128e3, 128062], 2], [128063, 2], [128064, 2], [128065, 2], [[128066, 128247], 2], [128248, 2], [[128249, 128252], 2], [[128253, 128254], 2], [128255, 2], [[128256, 128317], 2], [[128318, 128319], 2], [[128320, 128323], 2], [[128324, 128330], 2], [[128331, 128335], 2], [[128336, 128359], 2], [[128360, 128377], 2], [128378, 2], [[128379, 128419], 2], [128420, 2], [[128421, 128506], 2], [[128507, 128511], 2], [128512, 2], [[128513, 128528], 2], [128529, 2], [[128530, 128532], 2], [128533, 2], [128534, 2], [128535, 2], [128536, 2], [128537, 2], [128538, 2], [128539, 2], [[128540, 128542], 2], [128543, 2], [[128544, 128549], 2], [[128550, 128551], 2], [[128552, 128555], 2], [128556, 2], [128557, 2], [[128558, 128559], 2], [[128560, 128563], 2], [128564, 2], [[128565, 128576], 2], [[128577, 128578], 2], [[128579, 128580], 2], [[128581, 128591], 2], [[128592, 128639], 2], [[128640, 128709], 2], [[128710, 128719], 2], [128720, 2], [[128721, 128722], 2], [[128723, 128724], 2], [128725, 2], [[128726, 128727], 2], [[128728, 128732], 3], [[128733, 128735], 2], [[128736, 128748], 2], [[128749, 128751], 3], [[128752, 128755], 2], [[128756, 128758], 2], [[128759, 128760], 2], [128761, 2], [128762, 2], [[128763, 128764], 2], [[128765, 128767], 3], [[128768, 128883], 2], [[128884, 128895], 3], [[128896, 128980], 2], [[128981, 128984], 2], [[128985, 128991], 3], [[128992, 129003], 2], [[129004, 129007], 3], [129008, 2], [[129009, 129023], 3], [[129024, 129035], 2], [[129036, 129039], 3], [[129040, 129095], 2], [[129096, 129103], 3], [[129104, 129113], 2], [[129114, 129119], 3], [[129120, 129159], 2], [[129160, 129167], 3], [[129168, 129197], 2], [[129198, 129199], 3], [[129200, 129201], 2], [[129202, 129279], 3], [[129280, 129291], 2], [129292, 2], [[129293, 129295], 2], [[129296, 129304], 2], [[129305, 129310], 2], [129311, 2], [[129312, 129319], 2], [[129320, 129327], 2], [129328, 2], [[129329, 129330], 2], [[129331, 129342], 2], [129343, 2], [[129344, 129355], 2], [129356, 2], [[129357, 129359], 2], [[129360, 129374], 2], [[129375, 129387], 2], [[129388, 129392], 2], [129393, 2], [129394, 2], [[129395, 129398], 2], [[129399, 129400], 2], [129401, 2], [129402, 2], [129403, 2], [[129404, 129407], 2], [[129408, 129412], 2], [[129413, 129425], 2], [[129426, 129431], 2], [[129432, 129442], 2], [[129443, 129444], 2], [[129445, 129450], 2], [[129451, 129453], 2], [[129454, 129455], 2], [[129456, 129465], 2], [[129466, 129471], 2], [129472, 2], [[129473, 129474], 2], [[129475, 129482], 2], [129483, 2], [129484, 2], [[129485, 129487], 2], [[129488, 129510], 2], [[129511, 129535], 2], [[129536, 129619], 2], [[129620, 129631], 3], [[129632, 129645], 2], [[129646, 129647], 3], [[129648, 129651], 2], [129652, 2], [[129653, 129655], 3], [[129656, 129658], 2], [[129659, 129660], 2], [[129661, 129663], 3], [[129664, 129666], 2], [[129667, 129670], 2], [[129671, 129679], 3], [[129680, 129685], 2], [[129686, 129704], 2], [[129705, 129708], 2], [[129709, 129711], 3], [[129712, 129718], 2], [[129719, 129722], 2], [[129723, 129727], 3], [[129728, 129730], 2], [[129731, 129733], 2], [[129734, 129743], 3], [[129744, 129750], 2], [[129751, 129753], 2], [[129754, 129759], 3], [[129760, 129767], 2], [[129768, 129775], 3], [[129776, 129782], 2], [[129783, 129791], 3], [[129792, 129938], 2], [129939, 3], [[129940, 129994], 2], [[129995, 130031], 3], [130032, 1, "0"], [130033, 1, "1"], [130034, 1, "2"], [130035, 1, "3"], [130036, 1, "4"], [130037, 1, "5"], [130038, 1, "6"], [130039, 1, "7"], [130040, 1, "8"], [130041, 1, "9"], [[130042, 131069], 3], [[131070, 131071], 3], [[131072, 173782], 2], [[173783, 173789], 2], [[173790, 173791], 2], [[173792, 173823], 3], [[173824, 177972], 2], [[177973, 177976], 2], [[177977, 177983], 3], [[177984, 178205], 2], [[178206, 178207], 3], [[178208, 183969], 2], [[183970, 183983], 3], [[183984, 191456], 2], [[191457, 194559], 3], [194560, 1, "\u4E3D"], [194561, 1, "\u4E38"], [194562, 1, "\u4E41"], [194563, 1, "\u{20122}"], [194564, 1, "\u4F60"], [194565, 1, "\u4FAE"], [194566, 1, "\u4FBB"], [194567, 1, "\u5002"], [194568, 1, "\u507A"], [194569, 1, "\u5099"], [194570, 1, "\u50E7"], [194571, 1, "\u50CF"], [194572, 1, "\u349E"], [194573, 1, "\u{2063A}"], [194574, 1, "\u514D"], [194575, 1, "\u5154"], [194576, 1, "\u5164"], [194577, 1, "\u5177"], [194578, 1, "\u{2051C}"], [194579, 1, "\u34B9"], [194580, 1, "\u5167"], [194581, 1, "\u518D"], [194582, 1, "\u{2054B}"], [194583, 1, "\u5197"], [194584, 1, "\u51A4"], [194585, 1, "\u4ECC"], [194586, 1, "\u51AC"], [194587, 1, "\u51B5"], [194588, 1, "\u{291DF}"], [194589, 1, "\u51F5"], [194590, 1, "\u5203"], [194591, 1, "\u34DF"], [194592, 1, "\u523B"], [194593, 1, "\u5246"], [194594, 1, "\u5272"], [194595, 1, "\u5277"], [194596, 1, "\u3515"], [194597, 1, "\u52C7"], [194598, 1, "\u52C9"], [194599, 1, "\u52E4"], [194600, 1, "\u52FA"], [194601, 1, "\u5305"], [194602, 1, "\u5306"], [194603, 1, "\u5317"], [194604, 1, "\u5349"], [194605, 1, "\u5351"], [194606, 1, "\u535A"], [194607, 1, "\u5373"], [194608, 1, "\u537D"], [[194609, 194611], 1, "\u537F"], [194612, 1, "\u{20A2C}"], [194613, 1, "\u7070"], [194614, 1, "\u53CA"], [194615, 1, "\u53DF"], [194616, 1, "\u{20B63}"], [194617, 1, "\u53EB"], [194618, 1, "\u53F1"], [194619, 1, "\u5406"], [194620, 1, "\u549E"], [194621, 1, "\u5438"], [194622, 1, "\u5448"], [194623, 1, "\u5468"], [194624, 1, "\u54A2"], [194625, 1, "\u54F6"], [194626, 1, "\u5510"], [194627, 1, "\u5553"], [194628, 1, "\u5563"], [[194629, 194630], 1, "\u5584"], [194631, 1, "\u5599"], [194632, 1, "\u55AB"], [194633, 1, "\u55B3"], [194634, 1, "\u55C2"], [194635, 1, "\u5716"], [194636, 1, "\u5606"], [194637, 1, "\u5717"], [194638, 1, "\u5651"], [194639, 1, "\u5674"], [194640, 1, "\u5207"], [194641, 1, "\u58EE"], [194642, 1, "\u57CE"], [194643, 1, "\u57F4"], [194644, 1, "\u580D"], [194645, 1, "\u578B"], [194646, 1, "\u5832"], [194647, 1, "\u5831"], [194648, 1, "\u58AC"], [194649, 1, "\u{214E4}"], [194650, 1, "\u58F2"], [194651, 1, "\u58F7"], [194652, 1, "\u5906"], [194653, 1, "\u591A"], [194654, 1, "\u5922"], [194655, 1, "\u5962"], [194656, 1, "\u{216A8}"], [194657, 1, "\u{216EA}"], [194658, 1, "\u59EC"], [194659, 1, "\u5A1B"], [194660, 1, "\u5A27"], [194661, 1, "\u59D8"], [194662, 1, "\u5A66"], [194663, 1, "\u36EE"], [194664, 3], [194665, 1, "\u5B08"], [[194666, 194667], 1, "\u5B3E"], [194668, 1, "\u{219C8}"], [194669, 1, "\u5BC3"], [194670, 1, "\u5BD8"], [194671, 1, "\u5BE7"], [194672, 1, "\u5BF3"], [194673, 1, "\u{21B18}"], [194674, 1, "\u5BFF"], [194675, 1, "\u5C06"], [194676, 3], [194677, 1, "\u5C22"], [194678, 1, "\u3781"], [194679, 1, "\u5C60"], [194680, 1, "\u5C6E"], [194681, 1, "\u5CC0"], [194682, 1, "\u5C8D"], [194683, 1, "\u{21DE4}"], [194684, 1, "\u5D43"], [194685, 1, "\u{21DE6}"], [194686, 1, "\u5D6E"], [194687, 1, "\u5D6B"], [194688, 1, "\u5D7C"], [194689, 1, "\u5DE1"], [194690, 1, "\u5DE2"], [194691, 1, "\u382F"], [194692, 1, "\u5DFD"], [194693, 1, "\u5E28"], [194694, 1, "\u5E3D"], [194695, 1, "\u5E69"], [194696, 1, "\u3862"], [194697, 1, "\u{22183}"], [194698, 1, "\u387C"], [194699, 1, "\u5EB0"], [194700, 1, "\u5EB3"], [194701, 1, "\u5EB6"], [194702, 1, "\u5ECA"], [194703, 1, "\u{2A392}"], [194704, 1, "\u5EFE"], [[194705, 194706], 1, "\u{22331}"], [194707, 1, "\u8201"], [[194708, 194709], 1, "\u5F22"], [194710, 1, "\u38C7"], [194711, 1, "\u{232B8}"], [194712, 1, "\u{261DA}"], [194713, 1, "\u5F62"], [194714, 1, "\u5F6B"], [194715, 1, "\u38E3"], [194716, 1, "\u5F9A"], [194717, 1, "\u5FCD"], [194718, 1, "\u5FD7"], [194719, 1, "\u5FF9"], [194720, 1, "\u6081"], [194721, 1, "\u393A"], [194722, 1, "\u391C"], [194723, 1, "\u6094"], [194724, 1, "\u{226D4}"], [194725, 1, "\u60C7"], [194726, 1, "\u6148"], [194727, 1, "\u614C"], [194728, 1, "\u614E"], [194729, 1, "\u614C"], [194730, 1, "\u617A"], [194731, 1, "\u618E"], [194732, 1, "\u61B2"], [194733, 1, "\u61A4"], [194734, 1, "\u61AF"], [194735, 1, "\u61DE"], [194736, 1, "\u61F2"], [194737, 1, "\u61F6"], [194738, 1, "\u6210"], [194739, 1, "\u621B"], [194740, 1, "\u625D"], [194741, 1, "\u62B1"], [194742, 1, "\u62D4"], [194743, 1, "\u6350"], [194744, 1, "\u{22B0C}"], [194745, 1, "\u633D"], [194746, 1, "\u62FC"], [194747, 1, "\u6368"], [194748, 1, "\u6383"], [194749, 1, "\u63E4"], [194750, 1, "\u{22BF1}"], [194751, 1, "\u6422"], [194752, 1, "\u63C5"], [194753, 1, "\u63A9"], [194754, 1, "\u3A2E"], [194755, 1, "\u6469"], [194756, 1, "\u647E"], [194757, 1, "\u649D"], [194758, 1, "\u6477"], [194759, 1, "\u3A6C"], [194760, 1, "\u654F"], [194761, 1, "\u656C"], [194762, 1, "\u{2300A}"], [194763, 1, "\u65E3"], [194764, 1, "\u66F8"], [194765, 1, "\u6649"], [194766, 1, "\u3B19"], [194767, 1, "\u6691"], [194768, 1, "\u3B08"], [194769, 1, "\u3AE4"], [194770, 1, "\u5192"], [194771, 1, "\u5195"], [194772, 1, "\u6700"], [194773, 1, "\u669C"], [194774, 1, "\u80AD"], [194775, 1, "\u43D9"], [194776, 1, "\u6717"], [194777, 1, "\u671B"], [194778, 1, "\u6721"], [194779, 1, "\u675E"], [194780, 1, "\u6753"], [194781, 1, "\u{233C3}"], [194782, 1, "\u3B49"], [194783, 1, "\u67FA"], [194784, 1, "\u6785"], [194785, 1, "\u6852"], [194786, 1, "\u6885"], [194787, 1, "\u{2346D}"], [194788, 1, "\u688E"], [194789, 1, "\u681F"], [194790, 1, "\u6914"], [194791, 1, "\u3B9D"], [194792, 1, "\u6942"], [194793, 1, "\u69A3"], [194794, 1, "\u69EA"], [194795, 1, "\u6AA8"], [194796, 1, "\u{236A3}"], [194797, 1, "\u6ADB"], [194798, 1, "\u3C18"], [194799, 1, "\u6B21"], [194800, 1, "\u{238A7}"], [194801, 1, "\u6B54"], [194802, 1, "\u3C4E"], [194803, 1, "\u6B72"], [194804, 1, "\u6B9F"], [194805, 1, "\u6BBA"], [194806, 1, "\u6BBB"], [194807, 1, "\u{23A8D}"], [194808, 1, "\u{21D0B}"], [194809, 1, "\u{23AFA}"], [194810, 1, "\u6C4E"], [194811, 1, "\u{23CBC}"], [194812, 1, "\u6CBF"], [194813, 1, "\u6CCD"], [194814, 1, "\u6C67"], [194815, 1, "\u6D16"], [194816, 1, "\u6D3E"], [194817, 1, "\u6D77"], [194818, 1, "\u6D41"], [194819, 1, "\u6D69"], [194820, 1, "\u6D78"], [194821, 1, "\u6D85"], [194822, 1, "\u{23D1E}"], [194823, 1, "\u6D34"], [194824, 1, "\u6E2F"], [194825, 1, "\u6E6E"], [194826, 1, "\u3D33"], [194827, 1, "\u6ECB"], [194828, 1, "\u6EC7"], [194829, 1, "\u{23ED1}"], [194830, 1, "\u6DF9"], [194831, 1, "\u6F6E"], [194832, 1, "\u{23F5E}"], [194833, 1, "\u{23F8E}"], [194834, 1, "\u6FC6"], [194835, 1, "\u7039"], [194836, 1, "\u701E"], [194837, 1, "\u701B"], [194838, 1, "\u3D96"], [194839, 1, "\u704A"], [194840, 1, "\u707D"], [194841, 1, "\u7077"], [194842, 1, "\u70AD"], [194843, 1, "\u{20525}"], [194844, 1, "\u7145"], [194845, 1, "\u{24263}"], [194846, 1, "\u719C"], [194847, 3], [194848, 1, "\u7228"], [194849, 1, "\u7235"], [194850, 1, "\u7250"], [194851, 1, "\u{24608}"], [194852, 1, "\u7280"], [194853, 1, "\u7295"], [194854, 1, "\u{24735}"], [194855, 1, "\u{24814}"], [194856, 1, "\u737A"], [194857, 1, "\u738B"], [194858, 1, "\u3EAC"], [194859, 1, "\u73A5"], [[194860, 194861], 1, "\u3EB8"], [194862, 1, "\u7447"], [194863, 1, "\u745C"], [194864, 1, "\u7471"], [194865, 1, "\u7485"], [194866, 1, "\u74CA"], [194867, 1, "\u3F1B"], [194868, 1, "\u7524"], [194869, 1, "\u{24C36}"], [194870, 1, "\u753E"], [194871, 1, "\u{24C92}"], [194872, 1, "\u7570"], [194873, 1, "\u{2219F}"], [194874, 1, "\u7610"], [194875, 1, "\u{24FA1}"], [194876, 1, "\u{24FB8}"], [194877, 1, "\u{25044}"], [194878, 1, "\u3FFC"], [194879, 1, "\u4008"], [194880, 1, "\u76F4"], [194881, 1, "\u{250F3}"], [194882, 1, "\u{250F2}"], [194883, 1, "\u{25119}"], [194884, 1, "\u{25133}"], [194885, 1, "\u771E"], [[194886, 194887], 1, "\u771F"], [194888, 1, "\u774A"], [194889, 1, "\u4039"], [194890, 1, "\u778B"], [194891, 1, "\u4046"], [194892, 1, "\u4096"], [194893, 1, "\u{2541D}"], [194894, 1, "\u784E"], [194895, 1, "\u788C"], [194896, 1, "\u78CC"], [194897, 1, "\u40E3"], [194898, 1, "\u{25626}"], [194899, 1, "\u7956"], [194900, 1, "\u{2569A}"], [194901, 1, "\u{256C5}"], [194902, 1, "\u798F"], [194903, 1, "\u79EB"], [194904, 1, "\u412F"], [194905, 1, "\u7A40"], [194906, 1, "\u7A4A"], [194907, 1, "\u7A4F"], [194908, 1, "\u{2597C}"], [[194909, 194910], 1, "\u{25AA7}"], [194911, 3], [194912, 1, "\u4202"], [194913, 1, "\u{25BAB}"], [194914, 1, "\u7BC6"], [194915, 1, "\u7BC9"], [194916, 1, "\u4227"], [194917, 1, "\u{25C80}"], [194918, 1, "\u7CD2"], [194919, 1, "\u42A0"], [194920, 1, "\u7CE8"], [194921, 1, "\u7CE3"], [194922, 1, "\u7D00"], [194923, 1, "\u{25F86}"], [194924, 1, "\u7D63"], [194925, 1, "\u4301"], [194926, 1, "\u7DC7"], [194927, 1, "\u7E02"], [194928, 1, "\u7E45"], [194929, 1, "\u4334"], [194930, 1, "\u{26228}"], [194931, 1, "\u{26247}"], [194932, 1, "\u4359"], [194933, 1, "\u{262D9}"], [194934, 1, "\u7F7A"], [194935, 1, "\u{2633E}"], [194936, 1, "\u7F95"], [194937, 1, "\u7FFA"], [194938, 1, "\u8005"], [194939, 1, "\u{264DA}"], [194940, 1, "\u{26523}"], [194941, 1, "\u8060"], [194942, 1, "\u{265A8}"], [194943, 1, "\u8070"], [194944, 1, "\u{2335F}"], [194945, 1, "\u43D5"], [194946, 1, "\u80B2"], [194947, 1, "\u8103"], [194948, 1, "\u440B"], [194949, 1, "\u813E"], [194950, 1, "\u5AB5"], [194951, 1, "\u{267A7}"], [194952, 1, "\u{267B5}"], [194953, 1, "\u{23393}"], [194954, 1, "\u{2339C}"], [194955, 1, "\u8201"], [194956, 1, "\u8204"], [194957, 1, "\u8F9E"], [194958, 1, "\u446B"], [194959, 1, "\u8291"], [194960, 1, "\u828B"], [194961, 1, "\u829D"], [194962, 1, "\u52B3"], [194963, 1, "\u82B1"], [194964, 1, "\u82B3"], [194965, 1, "\u82BD"], [194966, 1, "\u82E6"], [194967, 1, "\u{26B3C}"], [194968, 1, "\u82E5"], [194969, 1, "\u831D"], [194970, 1, "\u8363"], [194971, 1, "\u83AD"], [194972, 1, "\u8323"], [194973, 1, "\u83BD"], [194974, 1, "\u83E7"], [194975, 1, "\u8457"], [194976, 1, "\u8353"], [194977, 1, "\u83CA"], [194978, 1, "\u83CC"], [194979, 1, "\u83DC"], [194980, 1, "\u{26C36}"], [194981, 1, "\u{26D6B}"], [194982, 1, "\u{26CD5}"], [194983, 1, "\u452B"], [194984, 1, "\u84F1"], [194985, 1, "\u84F3"], [194986, 1, "\u8516"], [194987, 1, "\u{273CA}"], [194988, 1, "\u8564"], [194989, 1, "\u{26F2C}"], [194990, 1, "\u455D"], [194991, 1, "\u4561"], [194992, 1, "\u{26FB1}"], [194993, 1, "\u{270D2}"], [194994, 1, "\u456B"], [194995, 1, "\u8650"], [194996, 1, "\u865C"], [194997, 1, "\u8667"], [194998, 1, "\u8669"], [194999, 1, "\u86A9"], [195e3, 1, "\u8688"], [195001, 1, "\u870E"], [195002, 1, "\u86E2"], [195003, 1, "\u8779"], [195004, 1, "\u8728"], [195005, 1, "\u876B"], [195006, 1, "\u8786"], [195007, 3], [195008, 1, "\u87E1"], [195009, 1, "\u8801"], [195010, 1, "\u45F9"], [195011, 1, "\u8860"], [195012, 1, "\u8863"], [195013, 1, "\u{27667}"], [195014, 1, "\u88D7"], [195015, 1, "\u88DE"], [195016, 1, "\u4635"], [195017, 1, "\u88FA"], [195018, 1, "\u34BB"], [195019, 1, "\u{278AE}"], [195020, 1, "\u{27966}"], [195021, 1, "\u46BE"], [195022, 1, "\u46C7"], [195023, 1, "\u8AA0"], [195024, 1, "\u8AED"], [195025, 1, "\u8B8A"], [195026, 1, "\u8C55"], [195027, 1, "\u{27CA8}"], [195028, 1, "\u8CAB"], [195029, 1, "\u8CC1"], [195030, 1, "\u8D1B"], [195031, 1, "\u8D77"], [195032, 1, "\u{27F2F}"], [195033, 1, "\u{20804}"], [195034, 1, "\u8DCB"], [195035, 1, "\u8DBC"], [195036, 1, "\u8DF0"], [195037, 1, "\u{208DE}"], [195038, 1, "\u8ED4"], [195039, 1, "\u8F38"], [195040, 1, "\u{285D2}"], [195041, 1, "\u{285ED}"], [195042, 1, "\u9094"], [195043, 1, "\u90F1"], [195044, 1, "\u9111"], [195045, 1, "\u{2872E}"], [195046, 1, "\u911B"], [195047, 1, "\u9238"], [195048, 1, "\u92D7"], [195049, 1, "\u92D8"], [195050, 1, "\u927C"], [195051, 1, "\u93F9"], [195052, 1, "\u9415"], [195053, 1, "\u{28BFA}"], [195054, 1, "\u958B"], [195055, 1, "\u4995"], [195056, 1, "\u95B7"], [195057, 1, "\u{28D77}"], [195058, 1, "\u49E6"], [195059, 1, "\u96C3"], [195060, 1, "\u5DB2"], [195061, 1, "\u9723"], [195062, 1, "\u{29145}"], [195063, 1, "\u{2921A}"], [195064, 1, "\u4A6E"], [195065, 1, "\u4A76"], [195066, 1, "\u97E0"], [195067, 1, "\u{2940A}"], [195068, 1, "\u4AB2"], [195069, 1, "\u{29496}"], [[195070, 195071], 1, "\u980B"], [195072, 1, "\u9829"], [195073, 1, "\u{295B6}"], [195074, 1, "\u98E2"], [195075, 1, "\u4B33"], [195076, 1, "\u9929"], [195077, 1, "\u99A7"], [195078, 1, "\u99C2"], [195079, 1, "\u99FE"], [195080, 1, "\u4BCE"], [195081, 1, "\u{29B30}"], [195082, 1, "\u9B12"], [195083, 1, "\u9C40"], [195084, 1, "\u9CFD"], [195085, 1, "\u4CCE"], [195086, 1, "\u4CED"], [195087, 1, "\u9D67"], [195088, 1, "\u{2A0CE}"], [195089, 1, "\u4CF8"], [195090, 1, "\u{2A105}"], [195091, 1, "\u{2A20E}"], [195092, 1, "\u{2A291}"], [195093, 1, "\u9EBB"], [195094, 1, "\u4D56"], [195095, 1, "\u9EF9"], [195096, 1, "\u9EFE"], [195097, 1, "\u9F05"], [195098, 1, "\u9F0F"], [195099, 1, "\u9F16"], [195100, 1, "\u9F3B"], [195101, 1, "\u{2A600}"], [[195102, 196605], 3], [[196606, 196607], 3], [[196608, 201546], 2], [[201547, 262141], 3], [[262142, 262143], 3], [[262144, 327677], 3], [[327678, 327679], 3], [[327680, 393213], 3], [[393214, 393215], 3], [[393216, 458749], 3], [[458750, 458751], 3], [[458752, 524285], 3], [[524286, 524287], 3], [[524288, 589821], 3], [[589822, 589823], 3], [[589824, 655357], 3], [[655358, 655359], 3], [[655360, 720893], 3], [[720894, 720895], 3], [[720896, 786429], 3], [[786430, 786431], 3], [[786432, 851965], 3], [[851966, 851967], 3], [[851968, 917501], 3], [[917502, 917503], 3], [917504, 3], [917505, 3], [[917506, 917535], 3], [[917536, 917631], 3], [[917632, 917759], 3], [[917760, 917999], 7], [[918e3, 983037], 3], [[983038, 983039], 3], [[983040, 1048573], 3], [[1048574, 1048575], 3], [[1048576, 1114109], 3], [[1114110, 1114111], 3]];
  14632. }
  14633. });
  14634. // node_modules/tr46/lib/statusMapping.js
  14635. var require_statusMapping = __commonJS({
  14636. "node_modules/tr46/lib/statusMapping.js"(exports2, module2) {
  14637. "use strict";
  14638. module2.exports.STATUS_MAPPING = {
  14639. mapped: 1,
  14640. valid: 2,
  14641. disallowed: 3,
  14642. disallowed_STD3_valid: 4,
  14643. disallowed_STD3_mapped: 5,
  14644. deviation: 6,
  14645. ignored: 7
  14646. };
  14647. }
  14648. });
  14649. // node_modules/tr46/index.js
  14650. var require_tr46 = __commonJS({
  14651. "node_modules/tr46/index.js"(exports2, module2) {
  14652. "use strict";
  14653. var punycode = require("punycode");
  14654. var regexes = require_regexes();
  14655. var mappingTable = require_mappingTable();
  14656. var { STATUS_MAPPING } = require_statusMapping();
  14657. function containsNonASCII(str) {
  14658. return /[^\x00-\x7F]/u.test(str);
  14659. }
  14660. function findStatus(val, { useSTD3ASCIIRules }) {
  14661. let start = 0;
  14662. let end = mappingTable.length - 1;
  14663. while (start <= end) {
  14664. const mid = Math.floor((start + end) / 2);
  14665. const target = mappingTable[mid];
  14666. const min = Array.isArray(target[0]) ? target[0][0] : target[0];
  14667. const max = Array.isArray(target[0]) ? target[0][1] : target[0];
  14668. if (min <= val && max >= val) {
  14669. if (useSTD3ASCIIRules && (target[1] === STATUS_MAPPING.disallowed_STD3_valid || target[1] === STATUS_MAPPING.disallowed_STD3_mapped)) {
  14670. return [STATUS_MAPPING.disallowed, ...target.slice(2)];
  14671. } else if (target[1] === STATUS_MAPPING.disallowed_STD3_valid) {
  14672. return [STATUS_MAPPING.valid, ...target.slice(2)];
  14673. } else if (target[1] === STATUS_MAPPING.disallowed_STD3_mapped) {
  14674. return [STATUS_MAPPING.mapped, ...target.slice(2)];
  14675. }
  14676. return target.slice(1);
  14677. } else if (min > val) {
  14678. end = mid - 1;
  14679. } else {
  14680. start = mid + 1;
  14681. }
  14682. }
  14683. return null;
  14684. }
  14685. function mapChars(domainName, { useSTD3ASCIIRules, processingOption }) {
  14686. let hasError = false;
  14687. let processed = "";
  14688. for (const ch of domainName) {
  14689. const [status, mapping] = findStatus(ch.codePointAt(0), { useSTD3ASCIIRules });
  14690. switch (status) {
  14691. case STATUS_MAPPING.disallowed:
  14692. hasError = true;
  14693. processed += ch;
  14694. break;
  14695. case STATUS_MAPPING.ignored:
  14696. break;
  14697. case STATUS_MAPPING.mapped:
  14698. processed += mapping;
  14699. break;
  14700. case STATUS_MAPPING.deviation:
  14701. if (processingOption === "transitional") {
  14702. processed += mapping;
  14703. } else {
  14704. processed += ch;
  14705. }
  14706. break;
  14707. case STATUS_MAPPING.valid:
  14708. processed += ch;
  14709. break;
  14710. }
  14711. }
  14712. return {
  14713. string: processed,
  14714. error: hasError
  14715. };
  14716. }
  14717. function validateLabel(label, { checkHyphens, checkBidi, checkJoiners, processingOption, useSTD3ASCIIRules }) {
  14718. if (label.normalize("NFC") !== label) {
  14719. return false;
  14720. }
  14721. const codePoints = Array.from(label);
  14722. if (checkHyphens) {
  14723. if (codePoints[2] === "-" && codePoints[3] === "-" || (label.startsWith("-") || label.endsWith("-"))) {
  14724. return false;
  14725. }
  14726. }
  14727. if (label.includes(".") || codePoints.length > 0 && regexes.combiningMarks.test(codePoints[0])) {
  14728. return false;
  14729. }
  14730. for (const ch of codePoints) {
  14731. const [status] = findStatus(ch.codePointAt(0), { useSTD3ASCIIRules });
  14732. if (processingOption === "transitional" && status !== STATUS_MAPPING.valid || processingOption === "nontransitional" && status !== STATUS_MAPPING.valid && status !== STATUS_MAPPING.deviation) {
  14733. return false;
  14734. }
  14735. }
  14736. if (checkJoiners) {
  14737. let last = 0;
  14738. for (const [i, ch] of codePoints.entries()) {
  14739. if (ch === "\u200C" || ch === "\u200D") {
  14740. if (i > 0) {
  14741. if (regexes.combiningClassVirama.test(codePoints[i - 1])) {
  14742. continue;
  14743. }
  14744. if (ch === "\u200C") {
  14745. const next = codePoints.indexOf("\u200C", i + 1);
  14746. const test = next < 0 ? codePoints.slice(last) : codePoints.slice(last, next);
  14747. if (regexes.validZWNJ.test(test.join(""))) {
  14748. last = i + 1;
  14749. continue;
  14750. }
  14751. }
  14752. }
  14753. return false;
  14754. }
  14755. }
  14756. }
  14757. if (checkBidi) {
  14758. let rtl;
  14759. if (regexes.bidiS1LTR.test(codePoints[0])) {
  14760. rtl = false;
  14761. } else if (regexes.bidiS1RTL.test(codePoints[0])) {
  14762. rtl = true;
  14763. } else {
  14764. return false;
  14765. }
  14766. if (rtl) {
  14767. if (!regexes.bidiS2.test(label) || !regexes.bidiS3.test(label) || regexes.bidiS4EN.test(label) && regexes.bidiS4AN.test(label)) {
  14768. return false;
  14769. }
  14770. } else if (!regexes.bidiS5.test(label) || !regexes.bidiS6.test(label)) {
  14771. return false;
  14772. }
  14773. }
  14774. return true;
  14775. }
  14776. function isBidiDomain(labels) {
  14777. const domain = labels.map((label) => {
  14778. if (label.startsWith("xn--")) {
  14779. try {
  14780. return punycode.decode(label.substring(4));
  14781. } catch (err) {
  14782. return "";
  14783. }
  14784. }
  14785. return label;
  14786. }).join(".");
  14787. return regexes.bidiDomain.test(domain);
  14788. }
  14789. function processing(domainName, options) {
  14790. const { processingOption } = options;
  14791. let { string, error } = mapChars(domainName, options);
  14792. string = string.normalize("NFC");
  14793. const labels = string.split(".");
  14794. const isBidi = isBidiDomain(labels);
  14795. for (const [i, origLabel] of labels.entries()) {
  14796. let label = origLabel;
  14797. let curProcessing = processingOption;
  14798. if (label.startsWith("xn--")) {
  14799. try {
  14800. label = punycode.decode(label.substring(4));
  14801. labels[i] = label;
  14802. } catch (err) {
  14803. error = true;
  14804. continue;
  14805. }
  14806. curProcessing = "nontransitional";
  14807. }
  14808. if (error) {
  14809. continue;
  14810. }
  14811. const validation = validateLabel(label, {
  14812. ...options,
  14813. processingOption: curProcessing,
  14814. checkBidi: options.checkBidi && isBidi
  14815. });
  14816. if (!validation) {
  14817. error = true;
  14818. }
  14819. }
  14820. return {
  14821. string: labels.join("."),
  14822. error
  14823. };
  14824. }
  14825. function toASCII(domainName, {
  14826. checkHyphens = false,
  14827. checkBidi = false,
  14828. checkJoiners = false,
  14829. useSTD3ASCIIRules = false,
  14830. processingOption = "nontransitional",
  14831. verifyDNSLength = false
  14832. } = {}) {
  14833. if (processingOption !== "transitional" && processingOption !== "nontransitional") {
  14834. throw new RangeError("processingOption must be either transitional or nontransitional");
  14835. }
  14836. const result = processing(domainName, {
  14837. processingOption,
  14838. checkHyphens,
  14839. checkBidi,
  14840. checkJoiners,
  14841. useSTD3ASCIIRules
  14842. });
  14843. let labels = result.string.split(".");
  14844. labels = labels.map((l) => {
  14845. if (containsNonASCII(l)) {
  14846. try {
  14847. return `xn--${punycode.encode(l)}`;
  14848. } catch (e) {
  14849. result.error = true;
  14850. }
  14851. }
  14852. return l;
  14853. });
  14854. if (verifyDNSLength) {
  14855. const total = labels.join(".").length;
  14856. if (total > 253 || total === 0) {
  14857. result.error = true;
  14858. }
  14859. for (let i = 0; i < labels.length; ++i) {
  14860. if (labels[i].length > 63 || labels[i].length === 0) {
  14861. result.error = true;
  14862. break;
  14863. }
  14864. }
  14865. }
  14866. if (result.error) {
  14867. return null;
  14868. }
  14869. return labels.join(".");
  14870. }
  14871. function toUnicode(domainName, {
  14872. checkHyphens = false,
  14873. checkBidi = false,
  14874. checkJoiners = false,
  14875. useSTD3ASCIIRules = false,
  14876. processingOption = "nontransitional"
  14877. } = {}) {
  14878. const result = processing(domainName, {
  14879. processingOption,
  14880. checkHyphens,
  14881. checkBidi,
  14882. checkJoiners,
  14883. useSTD3ASCIIRules
  14884. });
  14885. return {
  14886. domain: result.string,
  14887. error: result.error
  14888. };
  14889. }
  14890. module2.exports = {
  14891. toASCII,
  14892. toUnicode
  14893. };
  14894. }
  14895. });
  14896. // node_modules/whatwg-url/lib/infra.js
  14897. var require_infra = __commonJS({
  14898. "node_modules/whatwg-url/lib/infra.js"(exports2, module2) {
  14899. "use strict";
  14900. function isASCIIDigit(c) {
  14901. return c >= 48 && c <= 57;
  14902. }
  14903. function isASCIIAlpha(c) {
  14904. return c >= 65 && c <= 90 || c >= 97 && c <= 122;
  14905. }
  14906. function isASCIIAlphanumeric(c) {
  14907. return isASCIIAlpha(c) || isASCIIDigit(c);
  14908. }
  14909. function isASCIIHex(c) {
  14910. return isASCIIDigit(c) || c >= 65 && c <= 70 || c >= 97 && c <= 102;
  14911. }
  14912. module2.exports = {
  14913. isASCIIDigit,
  14914. isASCIIAlpha,
  14915. isASCIIAlphanumeric,
  14916. isASCIIHex
  14917. };
  14918. }
  14919. });
  14920. // node_modules/whatwg-url/lib/encoding.js
  14921. var require_encoding = __commonJS({
  14922. "node_modules/whatwg-url/lib/encoding.js"(exports2, module2) {
  14923. "use strict";
  14924. var utf8Encoder = new TextEncoder();
  14925. var utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });
  14926. function utf8Encode(string) {
  14927. return utf8Encoder.encode(string);
  14928. }
  14929. function utf8DecodeWithoutBOM(bytes) {
  14930. return utf8Decoder.decode(bytes);
  14931. }
  14932. module2.exports = {
  14933. utf8Encode,
  14934. utf8DecodeWithoutBOM
  14935. };
  14936. }
  14937. });
  14938. // node_modules/whatwg-url/lib/percent-encoding.js
  14939. var require_percent_encoding = __commonJS({
  14940. "node_modules/whatwg-url/lib/percent-encoding.js"(exports2, module2) {
  14941. "use strict";
  14942. var { isASCIIHex } = require_infra();
  14943. var { utf8Encode } = require_encoding();
  14944. function p(char) {
  14945. return char.codePointAt(0);
  14946. }
  14947. function percentEncode(c) {
  14948. let hex = c.toString(16).toUpperCase();
  14949. if (hex.length === 1) {
  14950. hex = `0${hex}`;
  14951. }
  14952. return `%${hex}`;
  14953. }
  14954. function percentDecodeBytes(input) {
  14955. const output = new Uint8Array(input.byteLength);
  14956. let outputIndex = 0;
  14957. for (let i = 0; i < input.byteLength; ++i) {
  14958. const byte = input[i];
  14959. if (byte !== 37) {
  14960. output[outputIndex++] = byte;
  14961. } else if (byte === 37 && (!isASCIIHex(input[i + 1]) || !isASCIIHex(input[i + 2]))) {
  14962. output[outputIndex++] = byte;
  14963. } else {
  14964. const bytePoint = parseInt(String.fromCodePoint(input[i + 1], input[i + 2]), 16);
  14965. output[outputIndex++] = bytePoint;
  14966. i += 2;
  14967. }
  14968. }
  14969. return output.slice(0, outputIndex);
  14970. }
  14971. function percentDecodeString(input) {
  14972. const bytes = utf8Encode(input);
  14973. return percentDecodeBytes(bytes);
  14974. }
  14975. function isC0ControlPercentEncode(c) {
  14976. return c <= 31 || c > 126;
  14977. }
  14978. var extraFragmentPercentEncodeSet = /* @__PURE__ */ new Set([p(" "), p('"'), p("<"), p(">"), p("`")]);
  14979. function isFragmentPercentEncode(c) {
  14980. return isC0ControlPercentEncode(c) || extraFragmentPercentEncodeSet.has(c);
  14981. }
  14982. var extraQueryPercentEncodeSet = /* @__PURE__ */ new Set([p(" "), p('"'), p("#"), p("<"), p(">")]);
  14983. function isQueryPercentEncode(c) {
  14984. return isC0ControlPercentEncode(c) || extraQueryPercentEncodeSet.has(c);
  14985. }
  14986. function isSpecialQueryPercentEncode(c) {
  14987. return isQueryPercentEncode(c) || c === p("'");
  14988. }
  14989. var extraPathPercentEncodeSet = /* @__PURE__ */ new Set([p("?"), p("`"), p("{"), p("}")]);
  14990. function isPathPercentEncode(c) {
  14991. return isQueryPercentEncode(c) || extraPathPercentEncodeSet.has(c);
  14992. }
  14993. var extraUserinfoPercentEncodeSet = /* @__PURE__ */ new Set([p("/"), p(":"), p(";"), p("="), p("@"), p("["), p("\\"), p("]"), p("^"), p("|")]);
  14994. function isUserinfoPercentEncode(c) {
  14995. return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c);
  14996. }
  14997. var extraComponentPercentEncodeSet = /* @__PURE__ */ new Set([p("$"), p("%"), p("&"), p("+"), p(",")]);
  14998. function isComponentPercentEncode(c) {
  14999. return isUserinfoPercentEncode(c) || extraComponentPercentEncodeSet.has(c);
  15000. }
  15001. var extraURLEncodedPercentEncodeSet = /* @__PURE__ */ new Set([p("!"), p("'"), p("("), p(")"), p("~")]);
  15002. function isURLEncodedPercentEncode(c) {
  15003. return isComponentPercentEncode(c) || extraURLEncodedPercentEncodeSet.has(c);
  15004. }
  15005. function utf8PercentEncodeCodePointInternal(codePoint, percentEncodePredicate) {
  15006. const bytes = utf8Encode(codePoint);
  15007. let output = "";
  15008. for (const byte of bytes) {
  15009. if (!percentEncodePredicate(byte)) {
  15010. output += String.fromCharCode(byte);
  15011. } else {
  15012. output += percentEncode(byte);
  15013. }
  15014. }
  15015. return output;
  15016. }
  15017. function utf8PercentEncodeCodePoint(codePoint, percentEncodePredicate) {
  15018. return utf8PercentEncodeCodePointInternal(String.fromCodePoint(codePoint), percentEncodePredicate);
  15019. }
  15020. function utf8PercentEncodeString(input, percentEncodePredicate, spaceAsPlus = false) {
  15021. let output = "";
  15022. for (const codePoint of input) {
  15023. if (spaceAsPlus && codePoint === " ") {
  15024. output += "+";
  15025. } else {
  15026. output += utf8PercentEncodeCodePointInternal(codePoint, percentEncodePredicate);
  15027. }
  15028. }
  15029. return output;
  15030. }
  15031. module2.exports = {
  15032. isC0ControlPercentEncode,
  15033. isFragmentPercentEncode,
  15034. isQueryPercentEncode,
  15035. isSpecialQueryPercentEncode,
  15036. isPathPercentEncode,
  15037. isUserinfoPercentEncode,
  15038. isURLEncodedPercentEncode,
  15039. percentDecodeString,
  15040. percentDecodeBytes,
  15041. utf8PercentEncodeString,
  15042. utf8PercentEncodeCodePoint
  15043. };
  15044. }
  15045. });
  15046. // node_modules/whatwg-url/lib/url-state-machine.js
  15047. var require_url_state_machine = __commonJS({
  15048. "node_modules/whatwg-url/lib/url-state-machine.js"(exports2, module2) {
  15049. "use strict";
  15050. var tr46 = require_tr46();
  15051. var infra = require_infra();
  15052. var { utf8DecodeWithoutBOM } = require_encoding();
  15053. var {
  15054. percentDecodeString,
  15055. utf8PercentEncodeCodePoint,
  15056. utf8PercentEncodeString,
  15057. isC0ControlPercentEncode,
  15058. isFragmentPercentEncode,
  15059. isQueryPercentEncode,
  15060. isSpecialQueryPercentEncode,
  15061. isPathPercentEncode,
  15062. isUserinfoPercentEncode
  15063. } = require_percent_encoding();
  15064. function p(char) {
  15065. return char.codePointAt(0);
  15066. }
  15067. var specialSchemes = {
  15068. ftp: 21,
  15069. file: null,
  15070. http: 80,
  15071. https: 443,
  15072. ws: 80,
  15073. wss: 443
  15074. };
  15075. var failure = Symbol("failure");
  15076. function countSymbols(str) {
  15077. return [...str].length;
  15078. }
  15079. function at(input, idx) {
  15080. const c = input[idx];
  15081. return isNaN(c) ? void 0 : String.fromCodePoint(c);
  15082. }
  15083. function isSingleDot(buffer) {
  15084. return buffer === "." || buffer.toLowerCase() === "%2e";
  15085. }
  15086. function isDoubleDot(buffer) {
  15087. buffer = buffer.toLowerCase();
  15088. return buffer === ".." || buffer === "%2e." || buffer === ".%2e" || buffer === "%2e%2e";
  15089. }
  15090. function isWindowsDriveLetterCodePoints(cp1, cp2) {
  15091. return infra.isASCIIAlpha(cp1) && (cp2 === p(":") || cp2 === p("|"));
  15092. }
  15093. function isWindowsDriveLetterString(string) {
  15094. return string.length === 2 && infra.isASCIIAlpha(string.codePointAt(0)) && (string[1] === ":" || string[1] === "|");
  15095. }
  15096. function isNormalizedWindowsDriveLetterString(string) {
  15097. return string.length === 2 && infra.isASCIIAlpha(string.codePointAt(0)) && string[1] === ":";
  15098. }
  15099. function containsForbiddenHostCodePoint(string) {
  15100. return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
  15101. }
  15102. function containsForbiddenHostCodePointExcludingPercent(string) {
  15103. return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
  15104. }
  15105. function isSpecialScheme(scheme) {
  15106. return specialSchemes[scheme] !== void 0;
  15107. }
  15108. function isSpecial(url) {
  15109. return isSpecialScheme(url.scheme);
  15110. }
  15111. function isNotSpecial(url) {
  15112. return !isSpecialScheme(url.scheme);
  15113. }
  15114. function defaultPort(scheme) {
  15115. return specialSchemes[scheme];
  15116. }
  15117. function parseIPv4Number(input) {
  15118. if (input === "") {
  15119. return failure;
  15120. }
  15121. let R = 10;
  15122. if (input.length >= 2 && input.charAt(0) === "0" && input.charAt(1).toLowerCase() === "x") {
  15123. input = input.substring(2);
  15124. R = 16;
  15125. } else if (input.length >= 2 && input.charAt(0) === "0") {
  15126. input = input.substring(1);
  15127. R = 8;
  15128. }
  15129. if (input === "") {
  15130. return 0;
  15131. }
  15132. let regex = /[^0-7]/u;
  15133. if (R === 10) {
  15134. regex = /[^0-9]/u;
  15135. }
  15136. if (R === 16) {
  15137. regex = /[^0-9A-Fa-f]/u;
  15138. }
  15139. if (regex.test(input)) {
  15140. return failure;
  15141. }
  15142. return parseInt(input, R);
  15143. }
  15144. function parseIPv4(input) {
  15145. const parts = input.split(".");
  15146. if (parts[parts.length - 1] === "") {
  15147. if (parts.length > 1) {
  15148. parts.pop();
  15149. }
  15150. }
  15151. if (parts.length > 4) {
  15152. return failure;
  15153. }
  15154. const numbers = [];
  15155. for (const part of parts) {
  15156. const n = parseIPv4Number(part);
  15157. if (n === failure) {
  15158. return failure;
  15159. }
  15160. numbers.push(n);
  15161. }
  15162. for (let i = 0; i < numbers.length - 1; ++i) {
  15163. if (numbers[i] > 255) {
  15164. return failure;
  15165. }
  15166. }
  15167. if (numbers[numbers.length - 1] >= 256 ** (5 - numbers.length)) {
  15168. return failure;
  15169. }
  15170. let ipv4 = numbers.pop();
  15171. let counter = 0;
  15172. for (const n of numbers) {
  15173. ipv4 += n * 256 ** (3 - counter);
  15174. ++counter;
  15175. }
  15176. return ipv4;
  15177. }
  15178. function serializeIPv4(address) {
  15179. let output = "";
  15180. let n = address;
  15181. for (let i = 1; i <= 4; ++i) {
  15182. output = String(n % 256) + output;
  15183. if (i !== 4) {
  15184. output = `.${output}`;
  15185. }
  15186. n = Math.floor(n / 256);
  15187. }
  15188. return output;
  15189. }
  15190. function parseIPv6(input) {
  15191. const address = [0, 0, 0, 0, 0, 0, 0, 0];
  15192. let pieceIndex = 0;
  15193. let compress = null;
  15194. let pointer = 0;
  15195. input = Array.from(input, (c) => c.codePointAt(0));
  15196. if (input[pointer] === p(":")) {
  15197. if (input[pointer + 1] !== p(":")) {
  15198. return failure;
  15199. }
  15200. pointer += 2;
  15201. ++pieceIndex;
  15202. compress = pieceIndex;
  15203. }
  15204. while (pointer < input.length) {
  15205. if (pieceIndex === 8) {
  15206. return failure;
  15207. }
  15208. if (input[pointer] === p(":")) {
  15209. if (compress !== null) {
  15210. return failure;
  15211. }
  15212. ++pointer;
  15213. ++pieceIndex;
  15214. compress = pieceIndex;
  15215. continue;
  15216. }
  15217. let value = 0;
  15218. let length = 0;
  15219. while (length < 4 && infra.isASCIIHex(input[pointer])) {
  15220. value = value * 16 + parseInt(at(input, pointer), 16);
  15221. ++pointer;
  15222. ++length;
  15223. }
  15224. if (input[pointer] === p(".")) {
  15225. if (length === 0) {
  15226. return failure;
  15227. }
  15228. pointer -= length;
  15229. if (pieceIndex > 6) {
  15230. return failure;
  15231. }
  15232. let numbersSeen = 0;
  15233. while (input[pointer] !== void 0) {
  15234. let ipv4Piece = null;
  15235. if (numbersSeen > 0) {
  15236. if (input[pointer] === p(".") && numbersSeen < 4) {
  15237. ++pointer;
  15238. } else {
  15239. return failure;
  15240. }
  15241. }
  15242. if (!infra.isASCIIDigit(input[pointer])) {
  15243. return failure;
  15244. }
  15245. while (infra.isASCIIDigit(input[pointer])) {
  15246. const number = parseInt(at(input, pointer));
  15247. if (ipv4Piece === null) {
  15248. ipv4Piece = number;
  15249. } else if (ipv4Piece === 0) {
  15250. return failure;
  15251. } else {
  15252. ipv4Piece = ipv4Piece * 10 + number;
  15253. }
  15254. if (ipv4Piece > 255) {
  15255. return failure;
  15256. }
  15257. ++pointer;
  15258. }
  15259. address[pieceIndex] = address[pieceIndex] * 256 + ipv4Piece;
  15260. ++numbersSeen;
  15261. if (numbersSeen === 2 || numbersSeen === 4) {
  15262. ++pieceIndex;
  15263. }
  15264. }
  15265. if (numbersSeen !== 4) {
  15266. return failure;
  15267. }
  15268. break;
  15269. } else if (input[pointer] === p(":")) {
  15270. ++pointer;
  15271. if (input[pointer] === void 0) {
  15272. return failure;
  15273. }
  15274. } else if (input[pointer] !== void 0) {
  15275. return failure;
  15276. }
  15277. address[pieceIndex] = value;
  15278. ++pieceIndex;
  15279. }
  15280. if (compress !== null) {
  15281. let swaps = pieceIndex - compress;
  15282. pieceIndex = 7;
  15283. while (pieceIndex !== 0 && swaps > 0) {
  15284. const temp = address[compress + swaps - 1];
  15285. address[compress + swaps - 1] = address[pieceIndex];
  15286. address[pieceIndex] = temp;
  15287. --pieceIndex;
  15288. --swaps;
  15289. }
  15290. } else if (compress === null && pieceIndex !== 8) {
  15291. return failure;
  15292. }
  15293. return address;
  15294. }
  15295. function serializeIPv6(address) {
  15296. let output = "";
  15297. const compress = findLongestZeroSequence(address);
  15298. let ignore0 = false;
  15299. for (let pieceIndex = 0; pieceIndex <= 7; ++pieceIndex) {
  15300. if (ignore0 && address[pieceIndex] === 0) {
  15301. continue;
  15302. } else if (ignore0) {
  15303. ignore0 = false;
  15304. }
  15305. if (compress === pieceIndex) {
  15306. const separator = pieceIndex === 0 ? "::" : ":";
  15307. output += separator;
  15308. ignore0 = true;
  15309. continue;
  15310. }
  15311. output += address[pieceIndex].toString(16);
  15312. if (pieceIndex !== 7) {
  15313. output += ":";
  15314. }
  15315. }
  15316. return output;
  15317. }
  15318. function parseHost(input, isNotSpecialArg = false) {
  15319. if (input[0] === "[") {
  15320. if (input[input.length - 1] !== "]") {
  15321. return failure;
  15322. }
  15323. return parseIPv6(input.substring(1, input.length - 1));
  15324. }
  15325. if (isNotSpecialArg) {
  15326. return parseOpaqueHost(input);
  15327. }
  15328. const domain = utf8DecodeWithoutBOM(percentDecodeString(input));
  15329. const asciiDomain = domainToASCII(domain);
  15330. if (asciiDomain === failure) {
  15331. return failure;
  15332. }
  15333. if (containsForbiddenHostCodePoint(asciiDomain)) {
  15334. return failure;
  15335. }
  15336. if (endsInANumber(asciiDomain)) {
  15337. return parseIPv4(asciiDomain);
  15338. }
  15339. return asciiDomain;
  15340. }
  15341. function endsInANumber(input) {
  15342. const parts = input.split(".");
  15343. if (parts[parts.length - 1] === "") {
  15344. if (parts.length === 1) {
  15345. return false;
  15346. }
  15347. parts.pop();
  15348. }
  15349. const last = parts[parts.length - 1];
  15350. if (parseIPv4Number(last) !== failure) {
  15351. return true;
  15352. }
  15353. if (/^[0-9]+$/u.test(last)) {
  15354. return true;
  15355. }
  15356. return false;
  15357. }
  15358. function parseOpaqueHost(input) {
  15359. if (containsForbiddenHostCodePointExcludingPercent(input)) {
  15360. return failure;
  15361. }
  15362. return utf8PercentEncodeString(input, isC0ControlPercentEncode);
  15363. }
  15364. function findLongestZeroSequence(arr) {
  15365. let maxIdx = null;
  15366. let maxLen = 1;
  15367. let currStart = null;
  15368. let currLen = 0;
  15369. for (let i = 0; i < arr.length; ++i) {
  15370. if (arr[i] !== 0) {
  15371. if (currLen > maxLen) {
  15372. maxIdx = currStart;
  15373. maxLen = currLen;
  15374. }
  15375. currStart = null;
  15376. currLen = 0;
  15377. } else {
  15378. if (currStart === null) {
  15379. currStart = i;
  15380. }
  15381. ++currLen;
  15382. }
  15383. }
  15384. if (currLen > maxLen) {
  15385. return currStart;
  15386. }
  15387. return maxIdx;
  15388. }
  15389. function serializeHost(host) {
  15390. if (typeof host === "number") {
  15391. return serializeIPv4(host);
  15392. }
  15393. if (host instanceof Array) {
  15394. return `[${serializeIPv6(host)}]`;
  15395. }
  15396. return host;
  15397. }
  15398. function domainToASCII(domain, beStrict = false) {
  15399. const result = tr46.toASCII(domain, {
  15400. checkBidi: true,
  15401. checkHyphens: false,
  15402. checkJoiners: true,
  15403. useSTD3ASCIIRules: beStrict,
  15404. verifyDNSLength: beStrict
  15405. });
  15406. if (result === null || result === "") {
  15407. return failure;
  15408. }
  15409. return result;
  15410. }
  15411. function trimControlChars(url) {
  15412. return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/ug, "");
  15413. }
  15414. function trimTabAndNewline(url) {
  15415. return url.replace(/\u0009|\u000A|\u000D/ug, "");
  15416. }
  15417. function shortenPath(url) {
  15418. const { path } = url;
  15419. if (path.length === 0) {
  15420. return;
  15421. }
  15422. if (url.scheme === "file" && path.length === 1 && isNormalizedWindowsDriveLetter(path[0])) {
  15423. return;
  15424. }
  15425. path.pop();
  15426. }
  15427. function includesCredentials(url) {
  15428. return url.username !== "" || url.password !== "";
  15429. }
  15430. function cannotHaveAUsernamePasswordPort(url) {
  15431. return url.host === null || url.host === "" || hasAnOpaquePath(url) || url.scheme === "file";
  15432. }
  15433. function hasAnOpaquePath(url) {
  15434. return typeof url.path === "string";
  15435. }
  15436. function isNormalizedWindowsDriveLetter(string) {
  15437. return /^[A-Za-z]:$/u.test(string);
  15438. }
  15439. function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
  15440. this.pointer = 0;
  15441. this.input = input;
  15442. this.base = base || null;
  15443. this.encodingOverride = encodingOverride || "utf-8";
  15444. this.stateOverride = stateOverride;
  15445. this.url = url;
  15446. this.failure = false;
  15447. this.parseError = false;
  15448. if (!this.url) {
  15449. this.url = {
  15450. scheme: "",
  15451. username: "",
  15452. password: "",
  15453. host: null,
  15454. port: null,
  15455. path: [],
  15456. query: null,
  15457. fragment: null
  15458. };
  15459. const res2 = trimControlChars(this.input);
  15460. if (res2 !== this.input) {
  15461. this.parseError = true;
  15462. }
  15463. this.input = res2;
  15464. }
  15465. const res = trimTabAndNewline(this.input);
  15466. if (res !== this.input) {
  15467. this.parseError = true;
  15468. }
  15469. this.input = res;
  15470. this.state = stateOverride || "scheme start";
  15471. this.buffer = "";
  15472. this.atFlag = false;
  15473. this.arrFlag = false;
  15474. this.passwordTokenSeenFlag = false;
  15475. this.input = Array.from(this.input, (c) => c.codePointAt(0));
  15476. for (; this.pointer <= this.input.length; ++this.pointer) {
  15477. const c = this.input[this.pointer];
  15478. const cStr = isNaN(c) ? void 0 : String.fromCodePoint(c);
  15479. const ret = this[`parse ${this.state}`](c, cStr);
  15480. if (!ret) {
  15481. break;
  15482. } else if (ret === failure) {
  15483. this.failure = true;
  15484. break;
  15485. }
  15486. }
  15487. }
  15488. URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, cStr) {
  15489. if (infra.isASCIIAlpha(c)) {
  15490. this.buffer += cStr.toLowerCase();
  15491. this.state = "scheme";
  15492. } else if (!this.stateOverride) {
  15493. this.state = "no scheme";
  15494. --this.pointer;
  15495. } else {
  15496. this.parseError = true;
  15497. return failure;
  15498. }
  15499. return true;
  15500. };
  15501. URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
  15502. if (infra.isASCIIAlphanumeric(c) || c === p("+") || c === p("-") || c === p(".")) {
  15503. this.buffer += cStr.toLowerCase();
  15504. } else if (c === p(":")) {
  15505. if (this.stateOverride) {
  15506. if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {
  15507. return false;
  15508. }
  15509. if (!isSpecial(this.url) && isSpecialScheme(this.buffer)) {
  15510. return false;
  15511. }
  15512. if ((includesCredentials(this.url) || this.url.port !== null) && this.buffer === "file") {
  15513. return false;
  15514. }
  15515. if (this.url.scheme === "file" && this.url.host === "") {
  15516. return false;
  15517. }
  15518. }
  15519. this.url.scheme = this.buffer;
  15520. if (this.stateOverride) {
  15521. if (this.url.port === defaultPort(this.url.scheme)) {
  15522. this.url.port = null;
  15523. }
  15524. return false;
  15525. }
  15526. this.buffer = "";
  15527. if (this.url.scheme === "file") {
  15528. if (this.input[this.pointer + 1] !== p("/") || this.input[this.pointer + 2] !== p("/")) {
  15529. this.parseError = true;
  15530. }
  15531. this.state = "file";
  15532. } else if (isSpecial(this.url) && this.base !== null && this.base.scheme === this.url.scheme) {
  15533. this.state = "special relative or authority";
  15534. } else if (isSpecial(this.url)) {
  15535. this.state = "special authority slashes";
  15536. } else if (this.input[this.pointer + 1] === p("/")) {
  15537. this.state = "path or authority";
  15538. ++this.pointer;
  15539. } else {
  15540. this.url.path = "";
  15541. this.state = "opaque path";
  15542. }
  15543. } else if (!this.stateOverride) {
  15544. this.buffer = "";
  15545. this.state = "no scheme";
  15546. this.pointer = -1;
  15547. } else {
  15548. this.parseError = true;
  15549. return failure;
  15550. }
  15551. return true;
  15552. };
  15553. URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) {
  15554. if (this.base === null || hasAnOpaquePath(this.base) && c !== p("#")) {
  15555. return failure;
  15556. } else if (hasAnOpaquePath(this.base) && c === p("#")) {
  15557. this.url.scheme = this.base.scheme;
  15558. this.url.path = this.base.path;
  15559. this.url.query = this.base.query;
  15560. this.url.fragment = "";
  15561. this.state = "fragment";
  15562. } else if (this.base.scheme === "file") {
  15563. this.state = "file";
  15564. --this.pointer;
  15565. } else {
  15566. this.state = "relative";
  15567. --this.pointer;
  15568. }
  15569. return true;
  15570. };
  15571. URLStateMachine.prototype["parse special relative or authority"] = function parseSpecialRelativeOrAuthority(c) {
  15572. if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
  15573. this.state = "special authority ignore slashes";
  15574. ++this.pointer;
  15575. } else {
  15576. this.parseError = true;
  15577. this.state = "relative";
  15578. --this.pointer;
  15579. }
  15580. return true;
  15581. };
  15582. URLStateMachine.prototype["parse path or authority"] = function parsePathOrAuthority(c) {
  15583. if (c === p("/")) {
  15584. this.state = "authority";
  15585. } else {
  15586. this.state = "path";
  15587. --this.pointer;
  15588. }
  15589. return true;
  15590. };
  15591. URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
  15592. this.url.scheme = this.base.scheme;
  15593. if (c === p("/")) {
  15594. this.state = "relative slash";
  15595. } else if (isSpecial(this.url) && c === p("\\")) {
  15596. this.parseError = true;
  15597. this.state = "relative slash";
  15598. } else {
  15599. this.url.username = this.base.username;
  15600. this.url.password = this.base.password;
  15601. this.url.host = this.base.host;
  15602. this.url.port = this.base.port;
  15603. this.url.path = this.base.path.slice();
  15604. this.url.query = this.base.query;
  15605. if (c === p("?")) {
  15606. this.url.query = "";
  15607. this.state = "query";
  15608. } else if (c === p("#")) {
  15609. this.url.fragment = "";
  15610. this.state = "fragment";
  15611. } else if (!isNaN(c)) {
  15612. this.url.query = null;
  15613. this.url.path.pop();
  15614. this.state = "path";
  15615. --this.pointer;
  15616. }
  15617. }
  15618. return true;
  15619. };
  15620. URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) {
  15621. if (isSpecial(this.url) && (c === p("/") || c === p("\\"))) {
  15622. if (c === p("\\")) {
  15623. this.parseError = true;
  15624. }
  15625. this.state = "special authority ignore slashes";
  15626. } else if (c === p("/")) {
  15627. this.state = "authority";
  15628. } else {
  15629. this.url.username = this.base.username;
  15630. this.url.password = this.base.password;
  15631. this.url.host = this.base.host;
  15632. this.url.port = this.base.port;
  15633. this.state = "path";
  15634. --this.pointer;
  15635. }
  15636. return true;
  15637. };
  15638. URLStateMachine.prototype["parse special authority slashes"] = function parseSpecialAuthoritySlashes(c) {
  15639. if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
  15640. this.state = "special authority ignore slashes";
  15641. ++this.pointer;
  15642. } else {
  15643. this.parseError = true;
  15644. this.state = "special authority ignore slashes";
  15645. --this.pointer;
  15646. }
  15647. return true;
  15648. };
  15649. URLStateMachine.prototype["parse special authority ignore slashes"] = function parseSpecialAuthorityIgnoreSlashes(c) {
  15650. if (c !== p("/") && c !== p("\\")) {
  15651. this.state = "authority";
  15652. --this.pointer;
  15653. } else {
  15654. this.parseError = true;
  15655. }
  15656. return true;
  15657. };
  15658. URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr) {
  15659. if (c === p("@")) {
  15660. this.parseError = true;
  15661. if (this.atFlag) {
  15662. this.buffer = `%40${this.buffer}`;
  15663. }
  15664. this.atFlag = true;
  15665. const len = countSymbols(this.buffer);
  15666. for (let pointer = 0; pointer < len; ++pointer) {
  15667. const codePoint = this.buffer.codePointAt(pointer);
  15668. if (codePoint === p(":") && !this.passwordTokenSeenFlag) {
  15669. this.passwordTokenSeenFlag = true;
  15670. continue;
  15671. }
  15672. const encodedCodePoints = utf8PercentEncodeCodePoint(codePoint, isUserinfoPercentEncode);
  15673. if (this.passwordTokenSeenFlag) {
  15674. this.url.password += encodedCodePoints;
  15675. } else {
  15676. this.url.username += encodedCodePoints;
  15677. }
  15678. }
  15679. this.buffer = "";
  15680. } else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") || isSpecial(this.url) && c === p("\\")) {
  15681. if (this.atFlag && this.buffer === "") {
  15682. this.parseError = true;
  15683. return failure;
  15684. }
  15685. this.pointer -= countSymbols(this.buffer) + 1;
  15686. this.buffer = "";
  15687. this.state = "host";
  15688. } else {
  15689. this.buffer += cStr;
  15690. }
  15691. return true;
  15692. };
  15693. URLStateMachine.prototype["parse hostname"] = URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
  15694. if (this.stateOverride && this.url.scheme === "file") {
  15695. --this.pointer;
  15696. this.state = "file host";
  15697. } else if (c === p(":") && !this.arrFlag) {
  15698. if (this.buffer === "") {
  15699. this.parseError = true;
  15700. return failure;
  15701. }
  15702. if (this.stateOverride === "hostname") {
  15703. return false;
  15704. }
  15705. const host = parseHost(this.buffer, isNotSpecial(this.url));
  15706. if (host === failure) {
  15707. return failure;
  15708. }
  15709. this.url.host = host;
  15710. this.buffer = "";
  15711. this.state = "port";
  15712. } else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") || isSpecial(this.url) && c === p("\\")) {
  15713. --this.pointer;
  15714. if (isSpecial(this.url) && this.buffer === "") {
  15715. this.parseError = true;
  15716. return failure;
  15717. } else if (this.stateOverride && this.buffer === "" && (includesCredentials(this.url) || this.url.port !== null)) {
  15718. this.parseError = true;
  15719. return false;
  15720. }
  15721. const host = parseHost(this.buffer, isNotSpecial(this.url));
  15722. if (host === failure) {
  15723. return failure;
  15724. }
  15725. this.url.host = host;
  15726. this.buffer = "";
  15727. this.state = "path start";
  15728. if (this.stateOverride) {
  15729. return false;
  15730. }
  15731. } else {
  15732. if (c === p("[")) {
  15733. this.arrFlag = true;
  15734. } else if (c === p("]")) {
  15735. this.arrFlag = false;
  15736. }
  15737. this.buffer += cStr;
  15738. }
  15739. return true;
  15740. };
  15741. URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) {
  15742. if (infra.isASCIIDigit(c)) {
  15743. this.buffer += cStr;
  15744. } else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") || isSpecial(this.url) && c === p("\\") || this.stateOverride) {
  15745. if (this.buffer !== "") {
  15746. const port = parseInt(this.buffer);
  15747. if (port > 2 ** 16 - 1) {
  15748. this.parseError = true;
  15749. return failure;
  15750. }
  15751. this.url.port = port === defaultPort(this.url.scheme) ? null : port;
  15752. this.buffer = "";
  15753. }
  15754. if (this.stateOverride) {
  15755. return false;
  15756. }
  15757. this.state = "path start";
  15758. --this.pointer;
  15759. } else {
  15760. this.parseError = true;
  15761. return failure;
  15762. }
  15763. return true;
  15764. };
  15765. var fileOtherwiseCodePoints = /* @__PURE__ */ new Set([p("/"), p("\\"), p("?"), p("#")]);
  15766. function startsWithWindowsDriveLetter(input, pointer) {
  15767. const length = input.length - pointer;
  15768. return length >= 2 && isWindowsDriveLetterCodePoints(input[pointer], input[pointer + 1]) && (length === 2 || fileOtherwiseCodePoints.has(input[pointer + 2]));
  15769. }
  15770. URLStateMachine.prototype["parse file"] = function parseFile(c) {
  15771. this.url.scheme = "file";
  15772. this.url.host = "";
  15773. if (c === p("/") || c === p("\\")) {
  15774. if (c === p("\\")) {
  15775. this.parseError = true;
  15776. }
  15777. this.state = "file slash";
  15778. } else if (this.base !== null && this.base.scheme === "file") {
  15779. this.url.host = this.base.host;
  15780. this.url.path = this.base.path.slice();
  15781. this.url.query = this.base.query;
  15782. if (c === p("?")) {
  15783. this.url.query = "";
  15784. this.state = "query";
  15785. } else if (c === p("#")) {
  15786. this.url.fragment = "";
  15787. this.state = "fragment";
  15788. } else if (!isNaN(c)) {
  15789. this.url.query = null;
  15790. if (!startsWithWindowsDriveLetter(this.input, this.pointer)) {
  15791. shortenPath(this.url);
  15792. } else {
  15793. this.parseError = true;
  15794. this.url.path = [];
  15795. }
  15796. this.state = "path";
  15797. --this.pointer;
  15798. }
  15799. } else {
  15800. this.state = "path";
  15801. --this.pointer;
  15802. }
  15803. return true;
  15804. };
  15805. URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
  15806. if (c === p("/") || c === p("\\")) {
  15807. if (c === p("\\")) {
  15808. this.parseError = true;
  15809. }
  15810. this.state = "file host";
  15811. } else {
  15812. if (this.base !== null && this.base.scheme === "file") {
  15813. if (!startsWithWindowsDriveLetter(this.input, this.pointer) && isNormalizedWindowsDriveLetterString(this.base.path[0])) {
  15814. this.url.path.push(this.base.path[0]);
  15815. }
  15816. this.url.host = this.base.host;
  15817. }
  15818. this.state = "path";
  15819. --this.pointer;
  15820. }
  15821. return true;
  15822. };
  15823. URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
  15824. if (isNaN(c) || c === p("/") || c === p("\\") || c === p("?") || c === p("#")) {
  15825. --this.pointer;
  15826. if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) {
  15827. this.parseError = true;
  15828. this.state = "path";
  15829. } else if (this.buffer === "") {
  15830. this.url.host = "";
  15831. if (this.stateOverride) {
  15832. return false;
  15833. }
  15834. this.state = "path start";
  15835. } else {
  15836. let host = parseHost(this.buffer, isNotSpecial(this.url));
  15837. if (host === failure) {
  15838. return failure;
  15839. }
  15840. if (host === "localhost") {
  15841. host = "";
  15842. }
  15843. this.url.host = host;
  15844. if (this.stateOverride) {
  15845. return false;
  15846. }
  15847. this.buffer = "";
  15848. this.state = "path start";
  15849. }
  15850. } else {
  15851. this.buffer += cStr;
  15852. }
  15853. return true;
  15854. };
  15855. URLStateMachine.prototype["parse path start"] = function parsePathStart(c) {
  15856. if (isSpecial(this.url)) {
  15857. if (c === p("\\")) {
  15858. this.parseError = true;
  15859. }
  15860. this.state = "path";
  15861. if (c !== p("/") && c !== p("\\")) {
  15862. --this.pointer;
  15863. }
  15864. } else if (!this.stateOverride && c === p("?")) {
  15865. this.url.query = "";
  15866. this.state = "query";
  15867. } else if (!this.stateOverride && c === p("#")) {
  15868. this.url.fragment = "";
  15869. this.state = "fragment";
  15870. } else if (c !== void 0) {
  15871. this.state = "path";
  15872. if (c !== p("/")) {
  15873. --this.pointer;
  15874. }
  15875. } else if (this.stateOverride && this.url.host === null) {
  15876. this.url.path.push("");
  15877. }
  15878. return true;
  15879. };
  15880. URLStateMachine.prototype["parse path"] = function parsePath(c) {
  15881. if (isNaN(c) || c === p("/") || isSpecial(this.url) && c === p("\\") || !this.stateOverride && (c === p("?") || c === p("#"))) {
  15882. if (isSpecial(this.url) && c === p("\\")) {
  15883. this.parseError = true;
  15884. }
  15885. if (isDoubleDot(this.buffer)) {
  15886. shortenPath(this.url);
  15887. if (c !== p("/") && !(isSpecial(this.url) && c === p("\\"))) {
  15888. this.url.path.push("");
  15889. }
  15890. } else if (isSingleDot(this.buffer) && c !== p("/") && !(isSpecial(this.url) && c === p("\\"))) {
  15891. this.url.path.push("");
  15892. } else if (!isSingleDot(this.buffer)) {
  15893. if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) {
  15894. this.buffer = `${this.buffer[0]}:`;
  15895. }
  15896. this.url.path.push(this.buffer);
  15897. }
  15898. this.buffer = "";
  15899. if (c === p("?")) {
  15900. this.url.query = "";
  15901. this.state = "query";
  15902. }
  15903. if (c === p("#")) {
  15904. this.url.fragment = "";
  15905. this.state = "fragment";
  15906. }
  15907. } else {
  15908. if (c === p("%") && (!infra.isASCIIHex(this.input[this.pointer + 1]) || !infra.isASCIIHex(this.input[this.pointer + 2]))) {
  15909. this.parseError = true;
  15910. }
  15911. this.buffer += utf8PercentEncodeCodePoint(c, isPathPercentEncode);
  15912. }
  15913. return true;
  15914. };
  15915. URLStateMachine.prototype["parse opaque path"] = function parseOpaquePath(c) {
  15916. if (c === p("?")) {
  15917. this.url.query = "";
  15918. this.state = "query";
  15919. } else if (c === p("#")) {
  15920. this.url.fragment = "";
  15921. this.state = "fragment";
  15922. } else {
  15923. if (!isNaN(c) && c !== p("%")) {
  15924. this.parseError = true;
  15925. }
  15926. if (c === p("%") && (!infra.isASCIIHex(this.input[this.pointer + 1]) || !infra.isASCIIHex(this.input[this.pointer + 2]))) {
  15927. this.parseError = true;
  15928. }
  15929. if (!isNaN(c)) {
  15930. this.url.path += utf8PercentEncodeCodePoint(c, isC0ControlPercentEncode);
  15931. }
  15932. }
  15933. return true;
  15934. };
  15935. URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
  15936. if (!isSpecial(this.url) || this.url.scheme === "ws" || this.url.scheme === "wss") {
  15937. this.encodingOverride = "utf-8";
  15938. }
  15939. if (!this.stateOverride && c === p("#") || isNaN(c)) {
  15940. const queryPercentEncodePredicate = isSpecial(this.url) ? isSpecialQueryPercentEncode : isQueryPercentEncode;
  15941. this.url.query += utf8PercentEncodeString(this.buffer, queryPercentEncodePredicate);
  15942. this.buffer = "";
  15943. if (c === p("#")) {
  15944. this.url.fragment = "";
  15945. this.state = "fragment";
  15946. }
  15947. } else if (!isNaN(c)) {
  15948. if (c === p("%") && (!infra.isASCIIHex(this.input[this.pointer + 1]) || !infra.isASCIIHex(this.input[this.pointer + 2]))) {
  15949. this.parseError = true;
  15950. }
  15951. this.buffer += cStr;
  15952. }
  15953. return true;
  15954. };
  15955. URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
  15956. if (!isNaN(c)) {
  15957. if (c === p("%") && (!infra.isASCIIHex(this.input[this.pointer + 1]) || !infra.isASCIIHex(this.input[this.pointer + 2]))) {
  15958. this.parseError = true;
  15959. }
  15960. this.url.fragment += utf8PercentEncodeCodePoint(c, isFragmentPercentEncode);
  15961. }
  15962. return true;
  15963. };
  15964. function serializeURL(url, excludeFragment) {
  15965. let output = `${url.scheme}:`;
  15966. if (url.host !== null) {
  15967. output += "//";
  15968. if (url.username !== "" || url.password !== "") {
  15969. output += url.username;
  15970. if (url.password !== "") {
  15971. output += `:${url.password}`;
  15972. }
  15973. output += "@";
  15974. }
  15975. output += serializeHost(url.host);
  15976. if (url.port !== null) {
  15977. output += `:${url.port}`;
  15978. }
  15979. }
  15980. if (url.host === null && !hasAnOpaquePath(url) && url.path.length > 1 && url.path[0] === "") {
  15981. output += "/.";
  15982. }
  15983. output += serializePath(url);
  15984. if (url.query !== null) {
  15985. output += `?${url.query}`;
  15986. }
  15987. if (!excludeFragment && url.fragment !== null) {
  15988. output += `#${url.fragment}`;
  15989. }
  15990. return output;
  15991. }
  15992. function serializeOrigin(tuple) {
  15993. let result = `${tuple.scheme}://`;
  15994. result += serializeHost(tuple.host);
  15995. if (tuple.port !== null) {
  15996. result += `:${tuple.port}`;
  15997. }
  15998. return result;
  15999. }
  16000. function serializePath(url) {
  16001. if (hasAnOpaquePath(url)) {
  16002. return url.path;
  16003. }
  16004. let output = "";
  16005. for (const segment of url.path) {
  16006. output += `/${segment}`;
  16007. }
  16008. return output;
  16009. }
  16010. module2.exports.serializeURL = serializeURL;
  16011. module2.exports.serializePath = serializePath;
  16012. module2.exports.serializeURLOrigin = function(url) {
  16013. switch (url.scheme) {
  16014. case "blob":
  16015. try {
  16016. return module2.exports.serializeURLOrigin(module2.exports.parseURL(serializePath(url)));
  16017. } catch (e) {
  16018. return "null";
  16019. }
  16020. case "ftp":
  16021. case "http":
  16022. case "https":
  16023. case "ws":
  16024. case "wss":
  16025. return serializeOrigin({
  16026. scheme: url.scheme,
  16027. host: url.host,
  16028. port: url.port
  16029. });
  16030. case "file":
  16031. return "null";
  16032. default:
  16033. return "null";
  16034. }
  16035. };
  16036. module2.exports.basicURLParse = function(input, options) {
  16037. if (options === void 0) {
  16038. options = {};
  16039. }
  16040. const usm = new URLStateMachine(input, options.baseURL, options.encodingOverride, options.url, options.stateOverride);
  16041. if (usm.failure) {
  16042. return null;
  16043. }
  16044. return usm.url;
  16045. };
  16046. module2.exports.setTheUsername = function(url, username) {
  16047. url.username = utf8PercentEncodeString(username, isUserinfoPercentEncode);
  16048. };
  16049. module2.exports.setThePassword = function(url, password) {
  16050. url.password = utf8PercentEncodeString(password, isUserinfoPercentEncode);
  16051. };
  16052. module2.exports.serializeHost = serializeHost;
  16053. module2.exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort;
  16054. module2.exports.hasAnOpaquePath = hasAnOpaquePath;
  16055. module2.exports.serializeInteger = function(integer) {
  16056. return String(integer);
  16057. };
  16058. module2.exports.parseURL = function(input, options) {
  16059. if (options === void 0) {
  16060. options = {};
  16061. }
  16062. return module2.exports.basicURLParse(input, { baseURL: options.baseURL, encodingOverride: options.encodingOverride });
  16063. };
  16064. }
  16065. });
  16066. // node_modules/whatwg-url/lib/urlencoded.js
  16067. var require_urlencoded = __commonJS({
  16068. "node_modules/whatwg-url/lib/urlencoded.js"(exports2, module2) {
  16069. "use strict";
  16070. var { utf8Encode, utf8DecodeWithoutBOM } = require_encoding();
  16071. var { percentDecodeBytes, utf8PercentEncodeString, isURLEncodedPercentEncode } = require_percent_encoding();
  16072. function p(char) {
  16073. return char.codePointAt(0);
  16074. }
  16075. function parseUrlencoded(input) {
  16076. const sequences = strictlySplitByteSequence(input, p("&"));
  16077. const output = [];
  16078. for (const bytes of sequences) {
  16079. if (bytes.length === 0) {
  16080. continue;
  16081. }
  16082. let name, value;
  16083. const indexOfEqual = bytes.indexOf(p("="));
  16084. if (indexOfEqual >= 0) {
  16085. name = bytes.slice(0, indexOfEqual);
  16086. value = bytes.slice(indexOfEqual + 1);
  16087. } else {
  16088. name = bytes;
  16089. value = new Uint8Array(0);
  16090. }
  16091. name = replaceByteInByteSequence(name, 43, 32);
  16092. value = replaceByteInByteSequence(value, 43, 32);
  16093. const nameString = utf8DecodeWithoutBOM(percentDecodeBytes(name));
  16094. const valueString = utf8DecodeWithoutBOM(percentDecodeBytes(value));
  16095. output.push([nameString, valueString]);
  16096. }
  16097. return output;
  16098. }
  16099. function parseUrlencodedString(input) {
  16100. return parseUrlencoded(utf8Encode(input));
  16101. }
  16102. function serializeUrlencoded(tuples, encodingOverride = void 0) {
  16103. let encoding = "utf-8";
  16104. if (encodingOverride !== void 0) {
  16105. encoding = encodingOverride;
  16106. }
  16107. let output = "";
  16108. for (const [i, tuple] of tuples.entries()) {
  16109. const name = utf8PercentEncodeString(tuple[0], isURLEncodedPercentEncode, true);
  16110. let value = tuple[1];
  16111. if (tuple.length > 2 && tuple[2] !== void 0) {
  16112. if (tuple[2] === "hidden" && name === "_charset_") {
  16113. value = encoding;
  16114. } else if (tuple[2] === "file") {
  16115. value = value.name;
  16116. }
  16117. }
  16118. value = utf8PercentEncodeString(value, isURLEncodedPercentEncode, true);
  16119. if (i !== 0) {
  16120. output += "&";
  16121. }
  16122. output += `${name}=${value}`;
  16123. }
  16124. return output;
  16125. }
  16126. function strictlySplitByteSequence(buf, cp) {
  16127. const list = [];
  16128. let last = 0;
  16129. let i = buf.indexOf(cp);
  16130. while (i >= 0) {
  16131. list.push(buf.slice(last, i));
  16132. last = i + 1;
  16133. i = buf.indexOf(cp, last);
  16134. }
  16135. if (last !== buf.length) {
  16136. list.push(buf.slice(last));
  16137. }
  16138. return list;
  16139. }
  16140. function replaceByteInByteSequence(buf, from, to) {
  16141. let i = buf.indexOf(from);
  16142. while (i >= 0) {
  16143. buf[i] = to;
  16144. i = buf.indexOf(from, i + 1);
  16145. }
  16146. return buf;
  16147. }
  16148. module2.exports = {
  16149. parseUrlencodedString,
  16150. serializeUrlencoded
  16151. };
  16152. }
  16153. });
  16154. // node_modules/whatwg-url/lib/Function.js
  16155. var require_Function = __commonJS({
  16156. "node_modules/whatwg-url/lib/Function.js"(exports2) {
  16157. "use strict";
  16158. var conversions = require_lib();
  16159. var utils = require_utils2();
  16160. exports2.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  16161. if (typeof value !== "function") {
  16162. throw new globalObject.TypeError(context + " is not a function");
  16163. }
  16164. function invokeTheCallbackFunction(...args) {
  16165. const thisArg = utils.tryWrapperForImpl(this);
  16166. let callResult;
  16167. for (let i = 0; i < args.length; i++) {
  16168. args[i] = utils.tryWrapperForImpl(args[i]);
  16169. }
  16170. callResult = Reflect.apply(value, thisArg, args);
  16171. callResult = conversions["any"](callResult, { context, globals: globalObject });
  16172. return callResult;
  16173. }
  16174. invokeTheCallbackFunction.construct = (...args) => {
  16175. for (let i = 0; i < args.length; i++) {
  16176. args[i] = utils.tryWrapperForImpl(args[i]);
  16177. }
  16178. let callResult = Reflect.construct(value, args);
  16179. callResult = conversions["any"](callResult, { context, globals: globalObject });
  16180. return callResult;
  16181. };
  16182. invokeTheCallbackFunction[utils.wrapperSymbol] = value;
  16183. invokeTheCallbackFunction.objectReference = value;
  16184. return invokeTheCallbackFunction;
  16185. };
  16186. }
  16187. });
  16188. // node_modules/whatwg-url/lib/URLSearchParams-impl.js
  16189. var require_URLSearchParams_impl = __commonJS({
  16190. "node_modules/whatwg-url/lib/URLSearchParams-impl.js"(exports2) {
  16191. "use strict";
  16192. var urlencoded = require_urlencoded();
  16193. exports2.implementation = class URLSearchParamsImpl {
  16194. constructor(globalObject, constructorArgs, { doNotStripQMark = false }) {
  16195. let init = constructorArgs[0];
  16196. this._list = [];
  16197. this._url = null;
  16198. if (!doNotStripQMark && typeof init === "string" && init[0] === "?") {
  16199. init = init.slice(1);
  16200. }
  16201. if (Array.isArray(init)) {
  16202. for (const pair of init) {
  16203. if (pair.length !== 2) {
  16204. throw new TypeError("Failed to construct 'URLSearchParams': parameter 1 sequence's element does not contain exactly two elements.");
  16205. }
  16206. this._list.push([pair[0], pair[1]]);
  16207. }
  16208. } else if (typeof init === "object" && Object.getPrototypeOf(init) === null) {
  16209. for (const name of Object.keys(init)) {
  16210. const value = init[name];
  16211. this._list.push([name, value]);
  16212. }
  16213. } else {
  16214. this._list = urlencoded.parseUrlencodedString(init);
  16215. }
  16216. }
  16217. _updateSteps() {
  16218. if (this._url !== null) {
  16219. let query = urlencoded.serializeUrlencoded(this._list);
  16220. if (query === "") {
  16221. query = null;
  16222. }
  16223. this._url._url.query = query;
  16224. }
  16225. }
  16226. append(name, value) {
  16227. this._list.push([name, value]);
  16228. this._updateSteps();
  16229. }
  16230. delete(name) {
  16231. let i = 0;
  16232. while (i < this._list.length) {
  16233. if (this._list[i][0] === name) {
  16234. this._list.splice(i, 1);
  16235. } else {
  16236. i++;
  16237. }
  16238. }
  16239. this._updateSteps();
  16240. }
  16241. get(name) {
  16242. for (const tuple of this._list) {
  16243. if (tuple[0] === name) {
  16244. return tuple[1];
  16245. }
  16246. }
  16247. return null;
  16248. }
  16249. getAll(name) {
  16250. const output = [];
  16251. for (const tuple of this._list) {
  16252. if (tuple[0] === name) {
  16253. output.push(tuple[1]);
  16254. }
  16255. }
  16256. return output;
  16257. }
  16258. has(name) {
  16259. for (const tuple of this._list) {
  16260. if (tuple[0] === name) {
  16261. return true;
  16262. }
  16263. }
  16264. return false;
  16265. }
  16266. set(name, value) {
  16267. let found = false;
  16268. let i = 0;
  16269. while (i < this._list.length) {
  16270. if (this._list[i][0] === name) {
  16271. if (found) {
  16272. this._list.splice(i, 1);
  16273. } else {
  16274. found = true;
  16275. this._list[i][1] = value;
  16276. i++;
  16277. }
  16278. } else {
  16279. i++;
  16280. }
  16281. }
  16282. if (!found) {
  16283. this._list.push([name, value]);
  16284. }
  16285. this._updateSteps();
  16286. }
  16287. sort() {
  16288. this._list.sort((a, b) => {
  16289. if (a[0] < b[0]) {
  16290. return -1;
  16291. }
  16292. if (a[0] > b[0]) {
  16293. return 1;
  16294. }
  16295. return 0;
  16296. });
  16297. this._updateSteps();
  16298. }
  16299. [Symbol.iterator]() {
  16300. return this._list[Symbol.iterator]();
  16301. }
  16302. toString() {
  16303. return urlencoded.serializeUrlencoded(this._list);
  16304. }
  16305. };
  16306. }
  16307. });
  16308. // node_modules/whatwg-url/lib/URLSearchParams.js
  16309. var require_URLSearchParams = __commonJS({
  16310. "node_modules/whatwg-url/lib/URLSearchParams.js"(exports2) {
  16311. "use strict";
  16312. var conversions = require_lib();
  16313. var utils = require_utils2();
  16314. var Function2 = require_Function();
  16315. var newObjectInRealm = utils.newObjectInRealm;
  16316. var implSymbol = utils.implSymbol;
  16317. var ctorRegistrySymbol = utils.ctorRegistrySymbol;
  16318. var interfaceName = "URLSearchParams";
  16319. exports2.is = (value) => {
  16320. return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  16321. };
  16322. exports2.isImpl = (value) => {
  16323. return utils.isObject(value) && value instanceof Impl.implementation;
  16324. };
  16325. exports2.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  16326. if (exports2.is(value)) {
  16327. return utils.implForWrapper(value);
  16328. }
  16329. throw new globalObject.TypeError(`${context} is not of type 'URLSearchParams'.`);
  16330. };
  16331. exports2.createDefaultIterator = (globalObject, target, kind) => {
  16332. const ctorRegistry = globalObject[ctorRegistrySymbol];
  16333. const iteratorPrototype = ctorRegistry["URLSearchParams Iterator"];
  16334. const iterator = Object.create(iteratorPrototype);
  16335. Object.defineProperty(iterator, utils.iterInternalSymbol, {
  16336. value: { target, kind, index: 0 },
  16337. configurable: true
  16338. });
  16339. return iterator;
  16340. };
  16341. function makeWrapper(globalObject, newTarget) {
  16342. let proto;
  16343. if (newTarget !== void 0) {
  16344. proto = newTarget.prototype;
  16345. }
  16346. if (!utils.isObject(proto)) {
  16347. proto = globalObject[ctorRegistrySymbol]["URLSearchParams"].prototype;
  16348. }
  16349. return Object.create(proto);
  16350. }
  16351. exports2.create = (globalObject, constructorArgs, privateData) => {
  16352. const wrapper = makeWrapper(globalObject);
  16353. return exports2.setup(wrapper, globalObject, constructorArgs, privateData);
  16354. };
  16355. exports2.createImpl = (globalObject, constructorArgs, privateData) => {
  16356. const wrapper = exports2.create(globalObject, constructorArgs, privateData);
  16357. return utils.implForWrapper(wrapper);
  16358. };
  16359. exports2._internalSetup = (wrapper, globalObject) => {
  16360. };
  16361. exports2.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  16362. privateData.wrapper = wrapper;
  16363. exports2._internalSetup(wrapper, globalObject);
  16364. Object.defineProperty(wrapper, implSymbol, {
  16365. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  16366. configurable: true
  16367. });
  16368. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  16369. if (Impl.init) {
  16370. Impl.init(wrapper[implSymbol]);
  16371. }
  16372. return wrapper;
  16373. };
  16374. exports2.new = (globalObject, newTarget) => {
  16375. const wrapper = makeWrapper(globalObject, newTarget);
  16376. exports2._internalSetup(wrapper, globalObject);
  16377. Object.defineProperty(wrapper, implSymbol, {
  16378. value: Object.create(Impl.implementation.prototype),
  16379. configurable: true
  16380. });
  16381. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  16382. if (Impl.init) {
  16383. Impl.init(wrapper[implSymbol]);
  16384. }
  16385. return wrapper[implSymbol];
  16386. };
  16387. var exposed = /* @__PURE__ */ new Set(["Window", "Worker"]);
  16388. exports2.install = (globalObject, globalNames) => {
  16389. if (!globalNames.some((globalName) => exposed.has(globalName))) {
  16390. return;
  16391. }
  16392. const ctorRegistry = utils.initCtorRegistry(globalObject);
  16393. class URLSearchParams {
  16394. constructor() {
  16395. const args = [];
  16396. {
  16397. let curArg = arguments[0];
  16398. if (curArg !== void 0) {
  16399. if (utils.isObject(curArg)) {
  16400. if (curArg[Symbol.iterator] !== void 0) {
  16401. if (!utils.isObject(curArg)) {
  16402. throw new globalObject.TypeError(
  16403. "Failed to construct 'URLSearchParams': parameter 1 sequence is not an iterable object."
  16404. );
  16405. } else {
  16406. const V = [];
  16407. const tmp = curArg;
  16408. for (let nextItem of tmp) {
  16409. if (!utils.isObject(nextItem)) {
  16410. throw new globalObject.TypeError(
  16411. "Failed to construct 'URLSearchParams': parameter 1 sequence's element is not an iterable object."
  16412. );
  16413. } else {
  16414. const V2 = [];
  16415. const tmp2 = nextItem;
  16416. for (let nextItem2 of tmp2) {
  16417. nextItem2 = conversions["USVString"](nextItem2, {
  16418. context: "Failed to construct 'URLSearchParams': parameter 1 sequence's element's element",
  16419. globals: globalObject
  16420. });
  16421. V2.push(nextItem2);
  16422. }
  16423. nextItem = V2;
  16424. }
  16425. V.push(nextItem);
  16426. }
  16427. curArg = V;
  16428. }
  16429. } else {
  16430. if (!utils.isObject(curArg)) {
  16431. throw new globalObject.TypeError(
  16432. "Failed to construct 'URLSearchParams': parameter 1 record is not an object."
  16433. );
  16434. } else {
  16435. const result = /* @__PURE__ */ Object.create(null);
  16436. for (const key of Reflect.ownKeys(curArg)) {
  16437. const desc = Object.getOwnPropertyDescriptor(curArg, key);
  16438. if (desc && desc.enumerable) {
  16439. let typedKey = key;
  16440. typedKey = conversions["USVString"](typedKey, {
  16441. context: "Failed to construct 'URLSearchParams': parameter 1 record's key",
  16442. globals: globalObject
  16443. });
  16444. let typedValue = curArg[key];
  16445. typedValue = conversions["USVString"](typedValue, {
  16446. context: "Failed to construct 'URLSearchParams': parameter 1 record's value",
  16447. globals: globalObject
  16448. });
  16449. result[typedKey] = typedValue;
  16450. }
  16451. }
  16452. curArg = result;
  16453. }
  16454. }
  16455. } else {
  16456. curArg = conversions["USVString"](curArg, {
  16457. context: "Failed to construct 'URLSearchParams': parameter 1",
  16458. globals: globalObject
  16459. });
  16460. }
  16461. } else {
  16462. curArg = "";
  16463. }
  16464. args.push(curArg);
  16465. }
  16466. return exports2.setup(Object.create(new.target.prototype), globalObject, args);
  16467. }
  16468. append(name, value) {
  16469. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16470. if (!exports2.is(esValue)) {
  16471. throw new globalObject.TypeError(
  16472. "'append' called on an object that is not a valid instance of URLSearchParams."
  16473. );
  16474. }
  16475. if (arguments.length < 2) {
  16476. throw new globalObject.TypeError(
  16477. `Failed to execute 'append' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
  16478. );
  16479. }
  16480. const args = [];
  16481. {
  16482. let curArg = arguments[0];
  16483. curArg = conversions["USVString"](curArg, {
  16484. context: "Failed to execute 'append' on 'URLSearchParams': parameter 1",
  16485. globals: globalObject
  16486. });
  16487. args.push(curArg);
  16488. }
  16489. {
  16490. let curArg = arguments[1];
  16491. curArg = conversions["USVString"](curArg, {
  16492. context: "Failed to execute 'append' on 'URLSearchParams': parameter 2",
  16493. globals: globalObject
  16494. });
  16495. args.push(curArg);
  16496. }
  16497. return utils.tryWrapperForImpl(esValue[implSymbol].append(...args));
  16498. }
  16499. delete(name) {
  16500. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16501. if (!exports2.is(esValue)) {
  16502. throw new globalObject.TypeError(
  16503. "'delete' called on an object that is not a valid instance of URLSearchParams."
  16504. );
  16505. }
  16506. if (arguments.length < 1) {
  16507. throw new globalObject.TypeError(
  16508. `Failed to execute 'delete' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
  16509. );
  16510. }
  16511. const args = [];
  16512. {
  16513. let curArg = arguments[0];
  16514. curArg = conversions["USVString"](curArg, {
  16515. context: "Failed to execute 'delete' on 'URLSearchParams': parameter 1",
  16516. globals: globalObject
  16517. });
  16518. args.push(curArg);
  16519. }
  16520. return utils.tryWrapperForImpl(esValue[implSymbol].delete(...args));
  16521. }
  16522. get(name) {
  16523. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16524. if (!exports2.is(esValue)) {
  16525. throw new globalObject.TypeError("'get' called on an object that is not a valid instance of URLSearchParams.");
  16526. }
  16527. if (arguments.length < 1) {
  16528. throw new globalObject.TypeError(
  16529. `Failed to execute 'get' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
  16530. );
  16531. }
  16532. const args = [];
  16533. {
  16534. let curArg = arguments[0];
  16535. curArg = conversions["USVString"](curArg, {
  16536. context: "Failed to execute 'get' on 'URLSearchParams': parameter 1",
  16537. globals: globalObject
  16538. });
  16539. args.push(curArg);
  16540. }
  16541. return esValue[implSymbol].get(...args);
  16542. }
  16543. getAll(name) {
  16544. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16545. if (!exports2.is(esValue)) {
  16546. throw new globalObject.TypeError(
  16547. "'getAll' called on an object that is not a valid instance of URLSearchParams."
  16548. );
  16549. }
  16550. if (arguments.length < 1) {
  16551. throw new globalObject.TypeError(
  16552. `Failed to execute 'getAll' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
  16553. );
  16554. }
  16555. const args = [];
  16556. {
  16557. let curArg = arguments[0];
  16558. curArg = conversions["USVString"](curArg, {
  16559. context: "Failed to execute 'getAll' on 'URLSearchParams': parameter 1",
  16560. globals: globalObject
  16561. });
  16562. args.push(curArg);
  16563. }
  16564. return utils.tryWrapperForImpl(esValue[implSymbol].getAll(...args));
  16565. }
  16566. has(name) {
  16567. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16568. if (!exports2.is(esValue)) {
  16569. throw new globalObject.TypeError("'has' called on an object that is not a valid instance of URLSearchParams.");
  16570. }
  16571. if (arguments.length < 1) {
  16572. throw new globalObject.TypeError(
  16573. `Failed to execute 'has' on 'URLSearchParams': 1 argument required, but only ${arguments.length} present.`
  16574. );
  16575. }
  16576. const args = [];
  16577. {
  16578. let curArg = arguments[0];
  16579. curArg = conversions["USVString"](curArg, {
  16580. context: "Failed to execute 'has' on 'URLSearchParams': parameter 1",
  16581. globals: globalObject
  16582. });
  16583. args.push(curArg);
  16584. }
  16585. return esValue[implSymbol].has(...args);
  16586. }
  16587. set(name, value) {
  16588. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16589. if (!exports2.is(esValue)) {
  16590. throw new globalObject.TypeError("'set' called on an object that is not a valid instance of URLSearchParams.");
  16591. }
  16592. if (arguments.length < 2) {
  16593. throw new globalObject.TypeError(
  16594. `Failed to execute 'set' on 'URLSearchParams': 2 arguments required, but only ${arguments.length} present.`
  16595. );
  16596. }
  16597. const args = [];
  16598. {
  16599. let curArg = arguments[0];
  16600. curArg = conversions["USVString"](curArg, {
  16601. context: "Failed to execute 'set' on 'URLSearchParams': parameter 1",
  16602. globals: globalObject
  16603. });
  16604. args.push(curArg);
  16605. }
  16606. {
  16607. let curArg = arguments[1];
  16608. curArg = conversions["USVString"](curArg, {
  16609. context: "Failed to execute 'set' on 'URLSearchParams': parameter 2",
  16610. globals: globalObject
  16611. });
  16612. args.push(curArg);
  16613. }
  16614. return utils.tryWrapperForImpl(esValue[implSymbol].set(...args));
  16615. }
  16616. sort() {
  16617. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16618. if (!exports2.is(esValue)) {
  16619. throw new globalObject.TypeError("'sort' called on an object that is not a valid instance of URLSearchParams.");
  16620. }
  16621. return utils.tryWrapperForImpl(esValue[implSymbol].sort());
  16622. }
  16623. toString() {
  16624. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16625. if (!exports2.is(esValue)) {
  16626. throw new globalObject.TypeError(
  16627. "'toString' called on an object that is not a valid instance of URLSearchParams."
  16628. );
  16629. }
  16630. return esValue[implSymbol].toString();
  16631. }
  16632. keys() {
  16633. if (!exports2.is(this)) {
  16634. throw new globalObject.TypeError("'keys' called on an object that is not a valid instance of URLSearchParams.");
  16635. }
  16636. return exports2.createDefaultIterator(globalObject, this, "key");
  16637. }
  16638. values() {
  16639. if (!exports2.is(this)) {
  16640. throw new globalObject.TypeError(
  16641. "'values' called on an object that is not a valid instance of URLSearchParams."
  16642. );
  16643. }
  16644. return exports2.createDefaultIterator(globalObject, this, "value");
  16645. }
  16646. entries() {
  16647. if (!exports2.is(this)) {
  16648. throw new globalObject.TypeError(
  16649. "'entries' called on an object that is not a valid instance of URLSearchParams."
  16650. );
  16651. }
  16652. return exports2.createDefaultIterator(globalObject, this, "key+value");
  16653. }
  16654. forEach(callback) {
  16655. if (!exports2.is(this)) {
  16656. throw new globalObject.TypeError(
  16657. "'forEach' called on an object that is not a valid instance of URLSearchParams."
  16658. );
  16659. }
  16660. if (arguments.length < 1) {
  16661. throw new globalObject.TypeError(
  16662. "Failed to execute 'forEach' on 'iterable': 1 argument required, but only 0 present."
  16663. );
  16664. }
  16665. callback = Function2.convert(globalObject, callback, {
  16666. context: "Failed to execute 'forEach' on 'iterable': The callback provided as parameter 1"
  16667. });
  16668. const thisArg = arguments[1];
  16669. let pairs = Array.from(this[implSymbol]);
  16670. let i = 0;
  16671. while (i < pairs.length) {
  16672. const [key, value] = pairs[i].map(utils.tryWrapperForImpl);
  16673. callback.call(thisArg, value, key, this);
  16674. pairs = Array.from(this[implSymbol]);
  16675. i++;
  16676. }
  16677. }
  16678. }
  16679. Object.defineProperties(URLSearchParams.prototype, {
  16680. append: { enumerable: true },
  16681. delete: { enumerable: true },
  16682. get: { enumerable: true },
  16683. getAll: { enumerable: true },
  16684. has: { enumerable: true },
  16685. set: { enumerable: true },
  16686. sort: { enumerable: true },
  16687. toString: { enumerable: true },
  16688. keys: { enumerable: true },
  16689. values: { enumerable: true },
  16690. entries: { enumerable: true },
  16691. forEach: { enumerable: true },
  16692. [Symbol.toStringTag]: { value: "URLSearchParams", configurable: true },
  16693. [Symbol.iterator]: { value: URLSearchParams.prototype.entries, configurable: true, writable: true }
  16694. });
  16695. ctorRegistry[interfaceName] = URLSearchParams;
  16696. ctorRegistry["URLSearchParams Iterator"] = Object.create(ctorRegistry["%IteratorPrototype%"], {
  16697. [Symbol.toStringTag]: {
  16698. configurable: true,
  16699. value: "URLSearchParams Iterator"
  16700. }
  16701. });
  16702. utils.define(ctorRegistry["URLSearchParams Iterator"], {
  16703. next() {
  16704. const internal = this && this[utils.iterInternalSymbol];
  16705. if (!internal) {
  16706. throw new globalObject.TypeError("next() called on a value that is not a URLSearchParams iterator object");
  16707. }
  16708. const { target, kind, index } = internal;
  16709. const values = Array.from(target[implSymbol]);
  16710. const len = values.length;
  16711. if (index >= len) {
  16712. return newObjectInRealm(globalObject, { value: void 0, done: true });
  16713. }
  16714. const pair = values[index];
  16715. internal.index = index + 1;
  16716. return newObjectInRealm(globalObject, utils.iteratorResult(pair.map(utils.tryWrapperForImpl), kind));
  16717. }
  16718. });
  16719. Object.defineProperty(globalObject, interfaceName, {
  16720. configurable: true,
  16721. writable: true,
  16722. value: URLSearchParams
  16723. });
  16724. };
  16725. var Impl = require_URLSearchParams_impl();
  16726. }
  16727. });
  16728. // node_modules/whatwg-url/lib/URL-impl.js
  16729. var require_URL_impl = __commonJS({
  16730. "node_modules/whatwg-url/lib/URL-impl.js"(exports2) {
  16731. "use strict";
  16732. var usm = require_url_state_machine();
  16733. var urlencoded = require_urlencoded();
  16734. var URLSearchParams = require_URLSearchParams();
  16735. exports2.implementation = class URLImpl {
  16736. constructor(globalObject, constructorArgs) {
  16737. const url = constructorArgs[0];
  16738. const base = constructorArgs[1];
  16739. let parsedBase = null;
  16740. if (base !== void 0) {
  16741. parsedBase = usm.basicURLParse(base);
  16742. if (parsedBase === null) {
  16743. throw new TypeError(`Invalid base URL: ${base}`);
  16744. }
  16745. }
  16746. const parsedURL = usm.basicURLParse(url, { baseURL: parsedBase });
  16747. if (parsedURL === null) {
  16748. throw new TypeError(`Invalid URL: ${url}`);
  16749. }
  16750. const query = parsedURL.query !== null ? parsedURL.query : "";
  16751. this._url = parsedURL;
  16752. this._query = URLSearchParams.createImpl(globalObject, [query], { doNotStripQMark: true });
  16753. this._query._url = this;
  16754. }
  16755. get href() {
  16756. return usm.serializeURL(this._url);
  16757. }
  16758. set href(v) {
  16759. const parsedURL = usm.basicURLParse(v);
  16760. if (parsedURL === null) {
  16761. throw new TypeError(`Invalid URL: ${v}`);
  16762. }
  16763. this._url = parsedURL;
  16764. this._query._list.splice(0);
  16765. const { query } = parsedURL;
  16766. if (query !== null) {
  16767. this._query._list = urlencoded.parseUrlencodedString(query);
  16768. }
  16769. }
  16770. get origin() {
  16771. return usm.serializeURLOrigin(this._url);
  16772. }
  16773. get protocol() {
  16774. return `${this._url.scheme}:`;
  16775. }
  16776. set protocol(v) {
  16777. usm.basicURLParse(`${v}:`, { url: this._url, stateOverride: "scheme start" });
  16778. }
  16779. get username() {
  16780. return this._url.username;
  16781. }
  16782. set username(v) {
  16783. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  16784. return;
  16785. }
  16786. usm.setTheUsername(this._url, v);
  16787. }
  16788. get password() {
  16789. return this._url.password;
  16790. }
  16791. set password(v) {
  16792. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  16793. return;
  16794. }
  16795. usm.setThePassword(this._url, v);
  16796. }
  16797. get host() {
  16798. const url = this._url;
  16799. if (url.host === null) {
  16800. return "";
  16801. }
  16802. if (url.port === null) {
  16803. return usm.serializeHost(url.host);
  16804. }
  16805. return `${usm.serializeHost(url.host)}:${usm.serializeInteger(url.port)}`;
  16806. }
  16807. set host(v) {
  16808. if (usm.hasAnOpaquePath(this._url)) {
  16809. return;
  16810. }
  16811. usm.basicURLParse(v, { url: this._url, stateOverride: "host" });
  16812. }
  16813. get hostname() {
  16814. if (this._url.host === null) {
  16815. return "";
  16816. }
  16817. return usm.serializeHost(this._url.host);
  16818. }
  16819. set hostname(v) {
  16820. if (usm.hasAnOpaquePath(this._url)) {
  16821. return;
  16822. }
  16823. usm.basicURLParse(v, { url: this._url, stateOverride: "hostname" });
  16824. }
  16825. get port() {
  16826. if (this._url.port === null) {
  16827. return "";
  16828. }
  16829. return usm.serializeInteger(this._url.port);
  16830. }
  16831. set port(v) {
  16832. if (usm.cannotHaveAUsernamePasswordPort(this._url)) {
  16833. return;
  16834. }
  16835. if (v === "") {
  16836. this._url.port = null;
  16837. } else {
  16838. usm.basicURLParse(v, { url: this._url, stateOverride: "port" });
  16839. }
  16840. }
  16841. get pathname() {
  16842. return usm.serializePath(this._url);
  16843. }
  16844. set pathname(v) {
  16845. if (usm.hasAnOpaquePath(this._url)) {
  16846. return;
  16847. }
  16848. this._url.path = [];
  16849. usm.basicURLParse(v, { url: this._url, stateOverride: "path start" });
  16850. }
  16851. get search() {
  16852. if (this._url.query === null || this._url.query === "") {
  16853. return "";
  16854. }
  16855. return `?${this._url.query}`;
  16856. }
  16857. set search(v) {
  16858. const url = this._url;
  16859. if (v === "") {
  16860. url.query = null;
  16861. this._query._list = [];
  16862. return;
  16863. }
  16864. const input = v[0] === "?" ? v.substring(1) : v;
  16865. url.query = "";
  16866. usm.basicURLParse(input, { url, stateOverride: "query" });
  16867. this._query._list = urlencoded.parseUrlencodedString(input);
  16868. }
  16869. get searchParams() {
  16870. return this._query;
  16871. }
  16872. get hash() {
  16873. if (this._url.fragment === null || this._url.fragment === "") {
  16874. return "";
  16875. }
  16876. return `#${this._url.fragment}`;
  16877. }
  16878. set hash(v) {
  16879. if (v === "") {
  16880. this._url.fragment = null;
  16881. return;
  16882. }
  16883. const input = v[0] === "#" ? v.substring(1) : v;
  16884. this._url.fragment = "";
  16885. usm.basicURLParse(input, { url: this._url, stateOverride: "fragment" });
  16886. }
  16887. toJSON() {
  16888. return this.href;
  16889. }
  16890. };
  16891. }
  16892. });
  16893. // node_modules/whatwg-url/lib/URL.js
  16894. var require_URL = __commonJS({
  16895. "node_modules/whatwg-url/lib/URL.js"(exports2) {
  16896. "use strict";
  16897. var conversions = require_lib();
  16898. var utils = require_utils2();
  16899. var implSymbol = utils.implSymbol;
  16900. var ctorRegistrySymbol = utils.ctorRegistrySymbol;
  16901. var interfaceName = "URL";
  16902. exports2.is = (value) => {
  16903. return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  16904. };
  16905. exports2.isImpl = (value) => {
  16906. return utils.isObject(value) && value instanceof Impl.implementation;
  16907. };
  16908. exports2.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  16909. if (exports2.is(value)) {
  16910. return utils.implForWrapper(value);
  16911. }
  16912. throw new globalObject.TypeError(`${context} is not of type 'URL'.`);
  16913. };
  16914. function makeWrapper(globalObject, newTarget) {
  16915. let proto;
  16916. if (newTarget !== void 0) {
  16917. proto = newTarget.prototype;
  16918. }
  16919. if (!utils.isObject(proto)) {
  16920. proto = globalObject[ctorRegistrySymbol]["URL"].prototype;
  16921. }
  16922. return Object.create(proto);
  16923. }
  16924. exports2.create = (globalObject, constructorArgs, privateData) => {
  16925. const wrapper = makeWrapper(globalObject);
  16926. return exports2.setup(wrapper, globalObject, constructorArgs, privateData);
  16927. };
  16928. exports2.createImpl = (globalObject, constructorArgs, privateData) => {
  16929. const wrapper = exports2.create(globalObject, constructorArgs, privateData);
  16930. return utils.implForWrapper(wrapper);
  16931. };
  16932. exports2._internalSetup = (wrapper, globalObject) => {
  16933. };
  16934. exports2.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  16935. privateData.wrapper = wrapper;
  16936. exports2._internalSetup(wrapper, globalObject);
  16937. Object.defineProperty(wrapper, implSymbol, {
  16938. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  16939. configurable: true
  16940. });
  16941. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  16942. if (Impl.init) {
  16943. Impl.init(wrapper[implSymbol]);
  16944. }
  16945. return wrapper;
  16946. };
  16947. exports2.new = (globalObject, newTarget) => {
  16948. const wrapper = makeWrapper(globalObject, newTarget);
  16949. exports2._internalSetup(wrapper, globalObject);
  16950. Object.defineProperty(wrapper, implSymbol, {
  16951. value: Object.create(Impl.implementation.prototype),
  16952. configurable: true
  16953. });
  16954. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  16955. if (Impl.init) {
  16956. Impl.init(wrapper[implSymbol]);
  16957. }
  16958. return wrapper[implSymbol];
  16959. };
  16960. var exposed = /* @__PURE__ */ new Set(["Window", "Worker"]);
  16961. exports2.install = (globalObject, globalNames) => {
  16962. if (!globalNames.some((globalName) => exposed.has(globalName))) {
  16963. return;
  16964. }
  16965. const ctorRegistry = utils.initCtorRegistry(globalObject);
  16966. class URL {
  16967. constructor(url) {
  16968. if (arguments.length < 1) {
  16969. throw new globalObject.TypeError(
  16970. `Failed to construct 'URL': 1 argument required, but only ${arguments.length} present.`
  16971. );
  16972. }
  16973. const args = [];
  16974. {
  16975. let curArg = arguments[0];
  16976. curArg = conversions["USVString"](curArg, {
  16977. context: "Failed to construct 'URL': parameter 1",
  16978. globals: globalObject
  16979. });
  16980. args.push(curArg);
  16981. }
  16982. {
  16983. let curArg = arguments[1];
  16984. if (curArg !== void 0) {
  16985. curArg = conversions["USVString"](curArg, {
  16986. context: "Failed to construct 'URL': parameter 2",
  16987. globals: globalObject
  16988. });
  16989. }
  16990. args.push(curArg);
  16991. }
  16992. return exports2.setup(Object.create(new.target.prototype), globalObject, args);
  16993. }
  16994. toJSON() {
  16995. const esValue = this !== null && this !== void 0 ? this : globalObject;
  16996. if (!exports2.is(esValue)) {
  16997. throw new globalObject.TypeError("'toJSON' called on an object that is not a valid instance of URL.");
  16998. }
  16999. return esValue[implSymbol].toJSON();
  17000. }
  17001. get href() {
  17002. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17003. if (!exports2.is(esValue)) {
  17004. throw new globalObject.TypeError("'get href' called on an object that is not a valid instance of URL.");
  17005. }
  17006. return esValue[implSymbol]["href"];
  17007. }
  17008. set href(V) {
  17009. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17010. if (!exports2.is(esValue)) {
  17011. throw new globalObject.TypeError("'set href' called on an object that is not a valid instance of URL.");
  17012. }
  17013. V = conversions["USVString"](V, {
  17014. context: "Failed to set the 'href' property on 'URL': The provided value",
  17015. globals: globalObject
  17016. });
  17017. esValue[implSymbol]["href"] = V;
  17018. }
  17019. toString() {
  17020. const esValue = this;
  17021. if (!exports2.is(esValue)) {
  17022. throw new globalObject.TypeError("'toString' called on an object that is not a valid instance of URL.");
  17023. }
  17024. return esValue[implSymbol]["href"];
  17025. }
  17026. get origin() {
  17027. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17028. if (!exports2.is(esValue)) {
  17029. throw new globalObject.TypeError("'get origin' called on an object that is not a valid instance of URL.");
  17030. }
  17031. return esValue[implSymbol]["origin"];
  17032. }
  17033. get protocol() {
  17034. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17035. if (!exports2.is(esValue)) {
  17036. throw new globalObject.TypeError("'get protocol' called on an object that is not a valid instance of URL.");
  17037. }
  17038. return esValue[implSymbol]["protocol"];
  17039. }
  17040. set protocol(V) {
  17041. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17042. if (!exports2.is(esValue)) {
  17043. throw new globalObject.TypeError("'set protocol' called on an object that is not a valid instance of URL.");
  17044. }
  17045. V = conversions["USVString"](V, {
  17046. context: "Failed to set the 'protocol' property on 'URL': The provided value",
  17047. globals: globalObject
  17048. });
  17049. esValue[implSymbol]["protocol"] = V;
  17050. }
  17051. get username() {
  17052. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17053. if (!exports2.is(esValue)) {
  17054. throw new globalObject.TypeError("'get username' called on an object that is not a valid instance of URL.");
  17055. }
  17056. return esValue[implSymbol]["username"];
  17057. }
  17058. set username(V) {
  17059. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17060. if (!exports2.is(esValue)) {
  17061. throw new globalObject.TypeError("'set username' called on an object that is not a valid instance of URL.");
  17062. }
  17063. V = conversions["USVString"](V, {
  17064. context: "Failed to set the 'username' property on 'URL': The provided value",
  17065. globals: globalObject
  17066. });
  17067. esValue[implSymbol]["username"] = V;
  17068. }
  17069. get password() {
  17070. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17071. if (!exports2.is(esValue)) {
  17072. throw new globalObject.TypeError("'get password' called on an object that is not a valid instance of URL.");
  17073. }
  17074. return esValue[implSymbol]["password"];
  17075. }
  17076. set password(V) {
  17077. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17078. if (!exports2.is(esValue)) {
  17079. throw new globalObject.TypeError("'set password' called on an object that is not a valid instance of URL.");
  17080. }
  17081. V = conversions["USVString"](V, {
  17082. context: "Failed to set the 'password' property on 'URL': The provided value",
  17083. globals: globalObject
  17084. });
  17085. esValue[implSymbol]["password"] = V;
  17086. }
  17087. get host() {
  17088. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17089. if (!exports2.is(esValue)) {
  17090. throw new globalObject.TypeError("'get host' called on an object that is not a valid instance of URL.");
  17091. }
  17092. return esValue[implSymbol]["host"];
  17093. }
  17094. set host(V) {
  17095. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17096. if (!exports2.is(esValue)) {
  17097. throw new globalObject.TypeError("'set host' called on an object that is not a valid instance of URL.");
  17098. }
  17099. V = conversions["USVString"](V, {
  17100. context: "Failed to set the 'host' property on 'URL': The provided value",
  17101. globals: globalObject
  17102. });
  17103. esValue[implSymbol]["host"] = V;
  17104. }
  17105. get hostname() {
  17106. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17107. if (!exports2.is(esValue)) {
  17108. throw new globalObject.TypeError("'get hostname' called on an object that is not a valid instance of URL.");
  17109. }
  17110. return esValue[implSymbol]["hostname"];
  17111. }
  17112. set hostname(V) {
  17113. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17114. if (!exports2.is(esValue)) {
  17115. throw new globalObject.TypeError("'set hostname' called on an object that is not a valid instance of URL.");
  17116. }
  17117. V = conversions["USVString"](V, {
  17118. context: "Failed to set the 'hostname' property on 'URL': The provided value",
  17119. globals: globalObject
  17120. });
  17121. esValue[implSymbol]["hostname"] = V;
  17122. }
  17123. get port() {
  17124. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17125. if (!exports2.is(esValue)) {
  17126. throw new globalObject.TypeError("'get port' called on an object that is not a valid instance of URL.");
  17127. }
  17128. return esValue[implSymbol]["port"];
  17129. }
  17130. set port(V) {
  17131. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17132. if (!exports2.is(esValue)) {
  17133. throw new globalObject.TypeError("'set port' called on an object that is not a valid instance of URL.");
  17134. }
  17135. V = conversions["USVString"](V, {
  17136. context: "Failed to set the 'port' property on 'URL': The provided value",
  17137. globals: globalObject
  17138. });
  17139. esValue[implSymbol]["port"] = V;
  17140. }
  17141. get pathname() {
  17142. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17143. if (!exports2.is(esValue)) {
  17144. throw new globalObject.TypeError("'get pathname' called on an object that is not a valid instance of URL.");
  17145. }
  17146. return esValue[implSymbol]["pathname"];
  17147. }
  17148. set pathname(V) {
  17149. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17150. if (!exports2.is(esValue)) {
  17151. throw new globalObject.TypeError("'set pathname' called on an object that is not a valid instance of URL.");
  17152. }
  17153. V = conversions["USVString"](V, {
  17154. context: "Failed to set the 'pathname' property on 'URL': The provided value",
  17155. globals: globalObject
  17156. });
  17157. esValue[implSymbol]["pathname"] = V;
  17158. }
  17159. get search() {
  17160. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17161. if (!exports2.is(esValue)) {
  17162. throw new globalObject.TypeError("'get search' called on an object that is not a valid instance of URL.");
  17163. }
  17164. return esValue[implSymbol]["search"];
  17165. }
  17166. set search(V) {
  17167. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17168. if (!exports2.is(esValue)) {
  17169. throw new globalObject.TypeError("'set search' called on an object that is not a valid instance of URL.");
  17170. }
  17171. V = conversions["USVString"](V, {
  17172. context: "Failed to set the 'search' property on 'URL': The provided value",
  17173. globals: globalObject
  17174. });
  17175. esValue[implSymbol]["search"] = V;
  17176. }
  17177. get searchParams() {
  17178. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17179. if (!exports2.is(esValue)) {
  17180. throw new globalObject.TypeError("'get searchParams' called on an object that is not a valid instance of URL.");
  17181. }
  17182. return utils.getSameObject(this, "searchParams", () => {
  17183. return utils.tryWrapperForImpl(esValue[implSymbol]["searchParams"]);
  17184. });
  17185. }
  17186. get hash() {
  17187. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17188. if (!exports2.is(esValue)) {
  17189. throw new globalObject.TypeError("'get hash' called on an object that is not a valid instance of URL.");
  17190. }
  17191. return esValue[implSymbol]["hash"];
  17192. }
  17193. set hash(V) {
  17194. const esValue = this !== null && this !== void 0 ? this : globalObject;
  17195. if (!exports2.is(esValue)) {
  17196. throw new globalObject.TypeError("'set hash' called on an object that is not a valid instance of URL.");
  17197. }
  17198. V = conversions["USVString"](V, {
  17199. context: "Failed to set the 'hash' property on 'URL': The provided value",
  17200. globals: globalObject
  17201. });
  17202. esValue[implSymbol]["hash"] = V;
  17203. }
  17204. }
  17205. Object.defineProperties(URL.prototype, {
  17206. toJSON: { enumerable: true },
  17207. href: { enumerable: true },
  17208. toString: { enumerable: true },
  17209. origin: { enumerable: true },
  17210. protocol: { enumerable: true },
  17211. username: { enumerable: true },
  17212. password: { enumerable: true },
  17213. host: { enumerable: true },
  17214. hostname: { enumerable: true },
  17215. port: { enumerable: true },
  17216. pathname: { enumerable: true },
  17217. search: { enumerable: true },
  17218. searchParams: { enumerable: true },
  17219. hash: { enumerable: true },
  17220. [Symbol.toStringTag]: { value: "URL", configurable: true }
  17221. });
  17222. ctorRegistry[interfaceName] = URL;
  17223. Object.defineProperty(globalObject, interfaceName, {
  17224. configurable: true,
  17225. writable: true,
  17226. value: URL
  17227. });
  17228. if (globalNames.includes("Window")) {
  17229. Object.defineProperty(globalObject, "webkitURL", {
  17230. configurable: true,
  17231. writable: true,
  17232. value: URL
  17233. });
  17234. }
  17235. };
  17236. var Impl = require_URL_impl();
  17237. }
  17238. });
  17239. // node_modules/whatwg-url/webidl2js-wrapper.js
  17240. var require_webidl2js_wrapper = __commonJS({
  17241. "node_modules/whatwg-url/webidl2js-wrapper.js"(exports2) {
  17242. "use strict";
  17243. var URL = require_URL();
  17244. var URLSearchParams = require_URLSearchParams();
  17245. exports2.URL = URL;
  17246. exports2.URLSearchParams = URLSearchParams;
  17247. }
  17248. });
  17249. // node_modules/whatwg-url/index.js
  17250. var require_whatwg_url = __commonJS({
  17251. "node_modules/whatwg-url/index.js"(exports2) {
  17252. "use strict";
  17253. var { URL, URLSearchParams } = require_webidl2js_wrapper();
  17254. var urlStateMachine = require_url_state_machine();
  17255. var percentEncoding = require_percent_encoding();
  17256. var sharedGlobalObject = { Array, Object, Promise, String, TypeError };
  17257. URL.install(sharedGlobalObject, ["Window"]);
  17258. URLSearchParams.install(sharedGlobalObject, ["Window"]);
  17259. exports2.URL = sharedGlobalObject.URL;
  17260. exports2.URLSearchParams = sharedGlobalObject.URLSearchParams;
  17261. exports2.parseURL = urlStateMachine.parseURL;
  17262. exports2.basicURLParse = urlStateMachine.basicURLParse;
  17263. exports2.serializeURL = urlStateMachine.serializeURL;
  17264. exports2.serializePath = urlStateMachine.serializePath;
  17265. exports2.serializeHost = urlStateMachine.serializeHost;
  17266. exports2.serializeInteger = urlStateMachine.serializeInteger;
  17267. exports2.serializeURLOrigin = urlStateMachine.serializeURLOrigin;
  17268. exports2.setTheUsername = urlStateMachine.setTheUsername;
  17269. exports2.setThePassword = urlStateMachine.setThePassword;
  17270. exports2.cannotHaveAUsernamePasswordPort = urlStateMachine.cannotHaveAUsernamePasswordPort;
  17271. exports2.hasAnOpaquePath = urlStateMachine.hasAnOpaquePath;
  17272. exports2.percentDecodeString = percentEncoding.percentDecodeString;
  17273. exports2.percentDecodeBytes = percentEncoding.percentDecodeBytes;
  17274. }
  17275. });
  17276. // node_modules/mongodb-connection-string-url/lib/redact.js
  17277. var require_redact = __commonJS({
  17278. "node_modules/mongodb-connection-string-url/lib/redact.js"(exports2) {
  17279. "use strict";
  17280. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  17281. if (k2 === void 0) k2 = k;
  17282. var desc = Object.getOwnPropertyDescriptor(m, k);
  17283. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  17284. desc = { enumerable: true, get: function() {
  17285. return m[k];
  17286. } };
  17287. }
  17288. Object.defineProperty(o, k2, desc);
  17289. } : function(o, m, k, k2) {
  17290. if (k2 === void 0) k2 = k;
  17291. o[k2] = m[k];
  17292. });
  17293. var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
  17294. Object.defineProperty(o, "default", { enumerable: true, value: v });
  17295. } : function(o, v) {
  17296. o["default"] = v;
  17297. });
  17298. var __importStar = exports2 && exports2.__importStar || function(mod) {
  17299. if (mod && mod.__esModule) return mod;
  17300. var result = {};
  17301. if (mod != null) {
  17302. for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  17303. }
  17304. __setModuleDefault(result, mod);
  17305. return result;
  17306. };
  17307. Object.defineProperty(exports2, "__esModule", { value: true });
  17308. exports2.redactConnectionString = exports2.redactValidConnectionString = void 0;
  17309. var index_1 = __importStar(require_lib2());
  17310. function redactValidConnectionString(inputUrl, options) {
  17311. var _a, _b;
  17312. const url = inputUrl.clone();
  17313. const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : "_credentials_";
  17314. const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;
  17315. if ((url.username || url.password) && redactUsernames) {
  17316. url.username = replacementString;
  17317. url.password = "";
  17318. } else if (url.password) {
  17319. url.password = replacementString;
  17320. }
  17321. if (url.searchParams.has("authMechanismProperties")) {
  17322. const props = new index_1.CommaAndColonSeparatedRecord(url.searchParams.get("authMechanismProperties"));
  17323. if (props.get("AWS_SESSION_TOKEN")) {
  17324. props.set("AWS_SESSION_TOKEN", replacementString);
  17325. url.searchParams.set("authMechanismProperties", props.toString());
  17326. }
  17327. }
  17328. if (url.searchParams.has("tlsCertificateKeyFilePassword")) {
  17329. url.searchParams.set("tlsCertificateKeyFilePassword", replacementString);
  17330. }
  17331. if (url.searchParams.has("proxyUsername") && redactUsernames) {
  17332. url.searchParams.set("proxyUsername", replacementString);
  17333. }
  17334. if (url.searchParams.has("proxyPassword")) {
  17335. url.searchParams.set("proxyPassword", replacementString);
  17336. }
  17337. return url;
  17338. }
  17339. exports2.redactValidConnectionString = redactValidConnectionString;
  17340. function redactConnectionString(uri, options) {
  17341. var _a, _b;
  17342. const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : "<credentials>";
  17343. const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;
  17344. let parsed;
  17345. try {
  17346. parsed = new index_1.default(uri);
  17347. } catch (_c) {
  17348. }
  17349. if (parsed) {
  17350. options = { ...options, replacementString: "___credentials___" };
  17351. return parsed.redact(options).toString().replace(/___credentials___/g, replacementString);
  17352. }
  17353. const R = replacementString;
  17354. const replacements = [
  17355. (uri2) => uri2.replace(redactUsernames ? /(\/\/)(.*)(@)/g : /(\/\/[^@]*:)(.*)(@)/g, `$1${R}$3`),
  17356. (uri2) => uri2.replace(/(AWS_SESSION_TOKEN(:|%3A))([^,&]+)/gi, `$1${R}`),
  17357. (uri2) => uri2.replace(/(tlsCertificateKeyFilePassword=)([^&]+)/gi, `$1${R}`),
  17358. (uri2) => redactUsernames ? uri2.replace(/(proxyUsername=)([^&]+)/gi, `$1${R}`) : uri2,
  17359. (uri2) => uri2.replace(/(proxyPassword=)([^&]+)/gi, `$1${R}`)
  17360. ];
  17361. for (const replacer of replacements) {
  17362. uri = replacer(uri);
  17363. }
  17364. return uri;
  17365. }
  17366. exports2.redactConnectionString = redactConnectionString;
  17367. }
  17368. });
  17369. // node_modules/mongodb-connection-string-url/lib/index.js
  17370. var require_lib2 = __commonJS({
  17371. "node_modules/mongodb-connection-string-url/lib/index.js"(exports2) {
  17372. "use strict";
  17373. Object.defineProperty(exports2, "__esModule", { value: true });
  17374. exports2.CommaAndColonSeparatedRecord = exports2.ConnectionString = exports2.redactConnectionString = void 0;
  17375. var whatwg_url_1 = require_whatwg_url();
  17376. var redact_1 = require_redact();
  17377. Object.defineProperty(exports2, "redactConnectionString", { enumerable: true, get: function() {
  17378. return redact_1.redactConnectionString;
  17379. } });
  17380. var DUMMY_HOSTNAME = "__this_is_a_placeholder__";
  17381. function connectionStringHasValidScheme(connectionString) {
  17382. return connectionString.startsWith("mongodb://") || connectionString.startsWith("mongodb+srv://");
  17383. }
  17384. var HOSTS_REGEX = /^(?<protocol>[^/]+):\/\/(?:(?<username>[^:@]*)(?::(?<password>[^@]*))?@)?(?<hosts>(?!:)[^/?@]*)(?<rest>.*)/;
  17385. var CaseInsensitiveMap = class extends Map {
  17386. delete(name) {
  17387. return super.delete(this._normalizeKey(name));
  17388. }
  17389. get(name) {
  17390. return super.get(this._normalizeKey(name));
  17391. }
  17392. has(name) {
  17393. return super.has(this._normalizeKey(name));
  17394. }
  17395. set(name, value) {
  17396. return super.set(this._normalizeKey(name), value);
  17397. }
  17398. _normalizeKey(name) {
  17399. name = `${name}`;
  17400. for (const key of this.keys()) {
  17401. if (key.toLowerCase() === name.toLowerCase()) {
  17402. name = key;
  17403. break;
  17404. }
  17405. }
  17406. return name;
  17407. }
  17408. };
  17409. function caseInsenstiveURLSearchParams(Ctor) {
  17410. return class CaseInsenstiveURLSearchParams extends Ctor {
  17411. append(name, value) {
  17412. return super.append(this._normalizeKey(name), value);
  17413. }
  17414. delete(name) {
  17415. return super.delete(this._normalizeKey(name));
  17416. }
  17417. get(name) {
  17418. return super.get(this._normalizeKey(name));
  17419. }
  17420. getAll(name) {
  17421. return super.getAll(this._normalizeKey(name));
  17422. }
  17423. has(name) {
  17424. return super.has(this._normalizeKey(name));
  17425. }
  17426. set(name, value) {
  17427. return super.set(this._normalizeKey(name), value);
  17428. }
  17429. keys() {
  17430. return super.keys();
  17431. }
  17432. values() {
  17433. return super.values();
  17434. }
  17435. entries() {
  17436. return super.entries();
  17437. }
  17438. [Symbol.iterator]() {
  17439. return super[Symbol.iterator]();
  17440. }
  17441. _normalizeKey(name) {
  17442. return CaseInsensitiveMap.prototype._normalizeKey.call(this, name);
  17443. }
  17444. };
  17445. }
  17446. var URLWithoutHost = class extends whatwg_url_1.URL {
  17447. };
  17448. var MongoParseError = class extends Error {
  17449. get name() {
  17450. return "MongoParseError";
  17451. }
  17452. };
  17453. var ConnectionString = class _ConnectionString extends URLWithoutHost {
  17454. constructor(uri, options = {}) {
  17455. var _a;
  17456. const { looseValidation } = options;
  17457. if (!looseValidation && !connectionStringHasValidScheme(uri)) {
  17458. throw new MongoParseError('Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"');
  17459. }
  17460. const match = uri.match(HOSTS_REGEX);
  17461. if (!match) {
  17462. throw new MongoParseError(`Invalid connection string "${uri}"`);
  17463. }
  17464. const { protocol, username, password, hosts, rest } = (_a = match.groups) !== null && _a !== void 0 ? _a : {};
  17465. if (!looseValidation) {
  17466. if (!protocol || !hosts) {
  17467. throw new MongoParseError(`Protocol and host list are required in "${uri}"`);
  17468. }
  17469. try {
  17470. decodeURIComponent(username !== null && username !== void 0 ? username : "");
  17471. decodeURIComponent(password !== null && password !== void 0 ? password : "");
  17472. } catch (err) {
  17473. throw new MongoParseError(err.message);
  17474. }
  17475. const illegalCharacters = /[:/?#[\]@]/gi;
  17476. if (username === null || username === void 0 ? void 0 : username.match(illegalCharacters)) {
  17477. throw new MongoParseError(`Username contains unescaped characters ${username}`);
  17478. }
  17479. if (!username || !password) {
  17480. const uriWithoutProtocol = uri.replace(`${protocol}://`, "");
  17481. if (uriWithoutProtocol.startsWith("@") || uriWithoutProtocol.startsWith(":")) {
  17482. throw new MongoParseError("URI contained empty userinfo section");
  17483. }
  17484. }
  17485. if (password === null || password === void 0 ? void 0 : password.match(illegalCharacters)) {
  17486. throw new MongoParseError("Password contains unescaped characters");
  17487. }
  17488. }
  17489. let authString = "";
  17490. if (typeof username === "string")
  17491. authString += username;
  17492. if (typeof password === "string")
  17493. authString += `:${password}`;
  17494. if (authString)
  17495. authString += "@";
  17496. try {
  17497. super(`${protocol.toLowerCase()}://${authString}${DUMMY_HOSTNAME}${rest}`);
  17498. } catch (err) {
  17499. if (looseValidation) {
  17500. new _ConnectionString(uri, {
  17501. ...options,
  17502. looseValidation: false
  17503. });
  17504. }
  17505. if (typeof err.message === "string") {
  17506. err.message = err.message.replace(DUMMY_HOSTNAME, hosts);
  17507. }
  17508. throw err;
  17509. }
  17510. this._hosts = hosts.split(",");
  17511. if (!looseValidation) {
  17512. if (this.isSRV && this.hosts.length !== 1) {
  17513. throw new MongoParseError("mongodb+srv URI cannot have multiple service names");
  17514. }
  17515. if (this.isSRV && this.hosts.some((host) => host.includes(":"))) {
  17516. throw new MongoParseError("mongodb+srv URI cannot have port number");
  17517. }
  17518. }
  17519. if (!this.pathname) {
  17520. this.pathname = "/";
  17521. }
  17522. Object.setPrototypeOf(this.searchParams, caseInsenstiveURLSearchParams(this.searchParams.constructor).prototype);
  17523. }
  17524. get host() {
  17525. return DUMMY_HOSTNAME;
  17526. }
  17527. set host(_ignored) {
  17528. throw new Error("No single host for connection string");
  17529. }
  17530. get hostname() {
  17531. return DUMMY_HOSTNAME;
  17532. }
  17533. set hostname(_ignored) {
  17534. throw new Error("No single host for connection string");
  17535. }
  17536. get port() {
  17537. return "";
  17538. }
  17539. set port(_ignored) {
  17540. throw new Error("No single host for connection string");
  17541. }
  17542. get href() {
  17543. return this.toString();
  17544. }
  17545. set href(_ignored) {
  17546. throw new Error("Cannot set href for connection strings");
  17547. }
  17548. get isSRV() {
  17549. return this.protocol.includes("srv");
  17550. }
  17551. get hosts() {
  17552. return this._hosts;
  17553. }
  17554. set hosts(list) {
  17555. this._hosts = list;
  17556. }
  17557. toString() {
  17558. return super.toString().replace(DUMMY_HOSTNAME, this.hosts.join(","));
  17559. }
  17560. clone() {
  17561. return new _ConnectionString(this.toString(), {
  17562. looseValidation: true
  17563. });
  17564. }
  17565. redact(options) {
  17566. return (0, redact_1.redactValidConnectionString)(this, options);
  17567. }
  17568. typedSearchParams() {
  17569. const sametype = false;
  17570. return this.searchParams;
  17571. }
  17572. [Symbol.for("nodejs.util.inspect.custom")]() {
  17573. const { href, origin, protocol, username, password, hosts, pathname, search, searchParams, hash } = this;
  17574. return { href, origin, protocol, username, password, hosts, pathname, search, searchParams, hash };
  17575. }
  17576. };
  17577. exports2.ConnectionString = ConnectionString;
  17578. var CommaAndColonSeparatedRecord = class extends CaseInsensitiveMap {
  17579. constructor(from) {
  17580. super();
  17581. for (const entry of (from !== null && from !== void 0 ? from : "").split(",")) {
  17582. if (!entry)
  17583. continue;
  17584. const colonIndex = entry.indexOf(":");
  17585. if (colonIndex === -1) {
  17586. this.set(entry, "");
  17587. } else {
  17588. this.set(entry.slice(0, colonIndex), entry.slice(colonIndex + 1));
  17589. }
  17590. }
  17591. }
  17592. toString() {
  17593. return [...this].map((entry) => entry.join(":")).join(",");
  17594. }
  17595. };
  17596. exports2.CommaAndColonSeparatedRecord = CommaAndColonSeparatedRecord;
  17597. exports2.default = ConnectionString;
  17598. }
  17599. });
  17600. // node_modules/mongodb/package.json
  17601. var require_package = __commonJS({
  17602. "node_modules/mongodb/package.json"(exports2, module2) {
  17603. module2.exports = {
  17604. name: "mongodb",
  17605. version: "5.9.2",
  17606. description: "The official MongoDB driver for Node.js",
  17607. main: "lib/index.js",
  17608. files: [
  17609. "lib",
  17610. "src",
  17611. "etc/prepare.js",
  17612. "mongodb.d.ts",
  17613. "tsconfig.json"
  17614. ],
  17615. types: "mongodb.d.ts",
  17616. repository: {
  17617. type: "git",
  17618. url: "git@github.com:mongodb/node-mongodb-native.git"
  17619. },
  17620. keywords: [
  17621. "mongodb",
  17622. "driver",
  17623. "official"
  17624. ],
  17625. author: {
  17626. name: "The MongoDB NodeJS Team",
  17627. email: "dbx-node@mongodb.com"
  17628. },
  17629. dependencies: {
  17630. bson: "^5.5.0",
  17631. "mongodb-connection-string-url": "^2.6.0",
  17632. socks: "^2.7.1"
  17633. },
  17634. optionalDependencies: {
  17635. "@mongodb-js/saslprep": "^1.1.0"
  17636. },
  17637. peerDependencies: {
  17638. "@aws-sdk/credential-providers": "^3.188.0",
  17639. "@mongodb-js/zstd": "^1.0.0",
  17640. kerberos: "^1.0.0 || ^2.0.0",
  17641. "mongodb-client-encryption": ">=2.3.0 <3",
  17642. snappy: "^7.2.2"
  17643. },
  17644. peerDependenciesMeta: {
  17645. "@aws-sdk/credential-providers": {
  17646. optional: true
  17647. },
  17648. "@mongodb-js/zstd": {
  17649. optional: true
  17650. },
  17651. kerberos: {
  17652. optional: true
  17653. },
  17654. snappy: {
  17655. optional: true
  17656. },
  17657. "mongodb-client-encryption": {
  17658. optional: true
  17659. }
  17660. },
  17661. devDependencies: {
  17662. "@iarna/toml": "^2.2.5",
  17663. "@istanbuljs/nyc-config-typescript": "^1.0.2",
  17664. "@microsoft/api-extractor": "^7.35.1",
  17665. "@microsoft/tsdoc-config": "^0.16.2",
  17666. "@mongodb-js/zstd": "^1.1.0",
  17667. "@octokit/core": "^4.2.4",
  17668. "@types/chai": "^4.3.5",
  17669. "@types/chai-subset": "^1.3.3",
  17670. "@types/express": "^4.17.17",
  17671. "@types/kerberos": "^1.1.2",
  17672. "@types/mocha": "^10.0.1",
  17673. "@types/node": "^20.1.0",
  17674. "@types/semver": "^7.5.0",
  17675. "@types/sinon": "^10.0.14",
  17676. "@types/sinon-chai": "^3.2.9",
  17677. "@types/whatwg-url": "^11.0.0",
  17678. "@typescript-eslint/eslint-plugin": "^5.59.5",
  17679. "@typescript-eslint/parser": "^5.59.5",
  17680. chai: "^4.3.7",
  17681. "chai-subset": "^1.6.0",
  17682. chalk: "^4.1.2",
  17683. eslint: "^8.40.0",
  17684. "eslint-config-prettier": "^8.8.0",
  17685. "eslint-plugin-import": "^2.27.5",
  17686. "eslint-plugin-prettier": "^4.2.1",
  17687. "eslint-plugin-simple-import-sort": "^10.0.0",
  17688. "eslint-plugin-tsdoc": "^0.2.17",
  17689. express: "^4.18.2",
  17690. "js-yaml": "^4.1.0",
  17691. mocha: "^10.2.0",
  17692. "mocha-sinon": "^2.1.2",
  17693. "mongodb-legacy": "^5.0.0",
  17694. nyc: "^15.1.0",
  17695. prettier: "^2.8.8",
  17696. semver: "^7.5.0",
  17697. sinon: "^15.0.4",
  17698. "sinon-chai": "^3.7.0",
  17699. snappy: "^7.2.2",
  17700. "source-map-support": "^0.5.21",
  17701. "ts-node": "^10.9.1",
  17702. tsd: "^0.28.1",
  17703. typescript: "^5.0.4",
  17704. "typescript-cached-transpile": "^0.0.6",
  17705. "v8-heapsnapshot": "^1.2.0",
  17706. yargs: "^17.7.2"
  17707. },
  17708. license: "Apache-2.0",
  17709. engines: {
  17710. node: ">=14.20.1"
  17711. },
  17712. bugs: {
  17713. url: "https://jira.mongodb.org/projects/NODE/issues/"
  17714. },
  17715. homepage: "https://github.com/mongodb/node-mongodb-native",
  17716. scripts: {
  17717. "build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
  17718. "build:ts": "node ./node_modules/typescript/bin/tsc",
  17719. "build:dts": "npm run build:ts && api-extractor run && node etc/clean_definition_files.cjs",
  17720. "build:docs": "./etc/docs/build.ts",
  17721. "build:typedoc": "typedoc",
  17722. "build:nightly": "node ./.github/scripts/nightly.mjs",
  17723. "check:bench": "node test/benchmarks/driverBench",
  17724. "check:coverage": "nyc npm run test:all",
  17725. "check:integration-coverage": "nyc npm run check:test",
  17726. "check:lambda": "mocha --config test/mocha_lambda.json test/integration/node-specific/examples/handler.test.js",
  17727. "check:lambda:aws": "mocha --config test/mocha_lambda.json test/integration/node-specific/examples/aws_handler.test.js",
  17728. "check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
  17729. "check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
  17730. "check:tsd": "tsd --version && tsd",
  17731. "check:dependencies": "mocha test/action/dependency.test.ts",
  17732. "check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
  17733. "check:search-indexes": "nyc mocha --config test/mocha_mongodb.json test/manual/search-index-management.spec.test.ts",
  17734. "check:test": "mocha --config test/mocha_mongodb.json test/integration",
  17735. "check:unit": "mocha test/unit",
  17736. "check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
  17737. "check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
  17738. "check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
  17739. "check:aws": "nyc mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.ts",
  17740. "check:oidc": "mocha --config test/mocha_mongodb.json test/manual/mongodb_oidc.prose.test.ts",
  17741. "check:oidc-azure": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_oidc_azure.prose.test.ts",
  17742. "check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
  17743. "check:kerberos": "nyc mocha --config test/manual/mocharc.json test/manual/kerberos.test.ts",
  17744. "check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
  17745. "check:ldap": "nyc mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
  17746. "check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
  17747. "check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
  17748. "check:snappy": "mocha test/unit/assorted/snappy.test.js",
  17749. "fix:eslint": "npm run check:eslint -- --fix",
  17750. prepare: "node etc/prepare.js",
  17751. "preview:docs": "ts-node etc/docs/preview.ts",
  17752. test: "npm run check:lint && npm run test:all",
  17753. "test:all": "npm run check:unit && npm run check:test",
  17754. "update:docs": "npm run build:docs -- --yes"
  17755. },
  17756. tsd: {
  17757. directory: "test/types",
  17758. compilerOptions: {
  17759. strict: true,
  17760. target: "esnext",
  17761. module: "commonjs",
  17762. moduleResolution: "node"
  17763. }
  17764. }
  17765. };
  17766. }
  17767. });
  17768. // node_modules/mongodb/lib/cmap/handshake/client_metadata.js
  17769. var require_client_metadata = __commonJS({
  17770. "node_modules/mongodb/lib/cmap/handshake/client_metadata.js"(exports2) {
  17771. "use strict";
  17772. Object.defineProperty(exports2, "__esModule", { value: true });
  17773. exports2.getFAASEnv = exports2.makeClientMetadata = exports2.LimitedSizeDocument = void 0;
  17774. var os = require("os");
  17775. var process2 = require("process");
  17776. var bson_1 = require_bson2();
  17777. var error_1 = require_error();
  17778. var NODE_DRIVER_VERSION = require_package().version;
  17779. var LimitedSizeDocument = class {
  17780. constructor(maxSize) {
  17781. this.maxSize = maxSize;
  17782. this.document = /* @__PURE__ */ new Map();
  17783. this.documentSize = 5;
  17784. }
  17785. /** Only adds key/value if the bsonByteLength is less than MAX_SIZE */
  17786. ifItFitsItSits(key, value) {
  17787. const newElementSize = bson_1.BSON.serialize((/* @__PURE__ */ new Map()).set(key, value)).byteLength - 5;
  17788. if (newElementSize + this.documentSize > this.maxSize) {
  17789. return false;
  17790. }
  17791. this.documentSize += newElementSize;
  17792. this.document.set(key, value);
  17793. return true;
  17794. }
  17795. toObject() {
  17796. return bson_1.BSON.deserialize(bson_1.BSON.serialize(this.document), {
  17797. promoteLongs: false,
  17798. promoteBuffers: false,
  17799. promoteValues: false,
  17800. useBigInt64: false
  17801. });
  17802. }
  17803. };
  17804. exports2.LimitedSizeDocument = LimitedSizeDocument;
  17805. function makeClientMetadata(options) {
  17806. const metadataDocument = new LimitedSizeDocument(512);
  17807. const { appName = "" } = options;
  17808. if (appName.length > 0) {
  17809. const name2 = Buffer.byteLength(appName, "utf8") <= 128 ? options.appName : Buffer.from(appName, "utf8").subarray(0, 128).toString("utf8");
  17810. metadataDocument.ifItFitsItSits("application", { name: name2 });
  17811. }
  17812. const { name = "", version = "", platform = "" } = options.driverInfo;
  17813. const driverInfo = {
  17814. name: name.length > 0 ? `nodejs|${name}` : "nodejs",
  17815. version: version.length > 0 ? `${NODE_DRIVER_VERSION}|${version}` : NODE_DRIVER_VERSION
  17816. };
  17817. if (!metadataDocument.ifItFitsItSits("driver", driverInfo)) {
  17818. throw new error_1.MongoInvalidArgumentError("Unable to include driverInfo name and version, metadata cannot exceed 512 bytes");
  17819. }
  17820. let runtimeInfo = getRuntimeInfo();
  17821. if (platform.length > 0) {
  17822. runtimeInfo = `${runtimeInfo}|${platform}`;
  17823. }
  17824. if (!metadataDocument.ifItFitsItSits("platform", runtimeInfo)) {
  17825. throw new error_1.MongoInvalidArgumentError("Unable to include driverInfo platform, metadata cannot exceed 512 bytes");
  17826. }
  17827. const osInfo = (/* @__PURE__ */ new Map()).set("name", process2.platform).set("architecture", process2.arch).set("version", os.release()).set("type", os.type());
  17828. if (!metadataDocument.ifItFitsItSits("os", osInfo)) {
  17829. for (const key of osInfo.keys()) {
  17830. osInfo.delete(key);
  17831. if (osInfo.size === 0)
  17832. break;
  17833. if (metadataDocument.ifItFitsItSits("os", osInfo))
  17834. break;
  17835. }
  17836. }
  17837. const faasEnv = getFAASEnv();
  17838. if (faasEnv != null) {
  17839. if (!metadataDocument.ifItFitsItSits("env", faasEnv)) {
  17840. for (const key of faasEnv.keys()) {
  17841. faasEnv.delete(key);
  17842. if (faasEnv.size === 0)
  17843. break;
  17844. if (metadataDocument.ifItFitsItSits("env", faasEnv))
  17845. break;
  17846. }
  17847. }
  17848. }
  17849. return metadataDocument.toObject();
  17850. }
  17851. exports2.makeClientMetadata = makeClientMetadata;
  17852. function getFAASEnv() {
  17853. const { AWS_EXECUTION_ENV = "", AWS_LAMBDA_RUNTIME_API = "", FUNCTIONS_WORKER_RUNTIME = "", K_SERVICE = "", FUNCTION_NAME = "", VERCEL = "", AWS_LAMBDA_FUNCTION_MEMORY_SIZE = "", AWS_REGION = "", FUNCTION_MEMORY_MB = "", FUNCTION_REGION = "", FUNCTION_TIMEOUT_SEC = "", VERCEL_REGION = "" } = process2.env;
  17854. const isAWSFaaS = AWS_EXECUTION_ENV.startsWith("AWS_Lambda_") || AWS_LAMBDA_RUNTIME_API.length > 0;
  17855. const isAzureFaaS = FUNCTIONS_WORKER_RUNTIME.length > 0;
  17856. const isGCPFaaS = K_SERVICE.length > 0 || FUNCTION_NAME.length > 0;
  17857. const isVercelFaaS = VERCEL.length > 0;
  17858. const faasEnv = /* @__PURE__ */ new Map();
  17859. if (isVercelFaaS && !(isAzureFaaS || isGCPFaaS)) {
  17860. if (VERCEL_REGION.length > 0) {
  17861. faasEnv.set("region", VERCEL_REGION);
  17862. }
  17863. faasEnv.set("name", "vercel");
  17864. return faasEnv;
  17865. }
  17866. if (isAWSFaaS && !(isAzureFaaS || isGCPFaaS || isVercelFaaS)) {
  17867. if (AWS_REGION.length > 0) {
  17868. faasEnv.set("region", AWS_REGION);
  17869. }
  17870. if (AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 && Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)) {
  17871. faasEnv.set("memory_mb", new bson_1.Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
  17872. }
  17873. faasEnv.set("name", "aws.lambda");
  17874. return faasEnv;
  17875. }
  17876. if (isAzureFaaS && !(isGCPFaaS || isAWSFaaS || isVercelFaaS)) {
  17877. faasEnv.set("name", "azure.func");
  17878. return faasEnv;
  17879. }
  17880. if (isGCPFaaS && !(isAzureFaaS || isAWSFaaS || isVercelFaaS)) {
  17881. if (FUNCTION_REGION.length > 0) {
  17882. faasEnv.set("region", FUNCTION_REGION);
  17883. }
  17884. if (FUNCTION_MEMORY_MB.length > 0 && Number.isInteger(+FUNCTION_MEMORY_MB)) {
  17885. faasEnv.set("memory_mb", new bson_1.Int32(FUNCTION_MEMORY_MB));
  17886. }
  17887. if (FUNCTION_TIMEOUT_SEC.length > 0 && Number.isInteger(+FUNCTION_TIMEOUT_SEC)) {
  17888. faasEnv.set("timeout_sec", new bson_1.Int32(FUNCTION_TIMEOUT_SEC));
  17889. }
  17890. faasEnv.set("name", "gcp.func");
  17891. return faasEnv;
  17892. }
  17893. return null;
  17894. }
  17895. exports2.getFAASEnv = getFAASEnv;
  17896. function getRuntimeInfo() {
  17897. var _a, _b;
  17898. if ("Deno" in globalThis) {
  17899. const version = typeof ((_a = Deno == null ? void 0 : Deno.version) == null ? void 0 : _a.deno) === "string" ? (_b = Deno == null ? void 0 : Deno.version) == null ? void 0 : _b.deno : "0.0.0-unknown";
  17900. return `Deno v${version}, ${os.endianness()}`;
  17901. }
  17902. if ("Bun" in globalThis) {
  17903. const version = typeof (Bun == null ? void 0 : Bun.version) === "string" ? Bun == null ? void 0 : Bun.version : "0.0.0-unknown";
  17904. return `Bun v${version}, ${os.endianness()}`;
  17905. }
  17906. return `Node.js ${process2.version}, ${os.endianness()}`;
  17907. }
  17908. }
  17909. });
  17910. // node_modules/mongodb/lib/cmap/wire_protocol/compression.js
  17911. var require_compression = __commonJS({
  17912. "node_modules/mongodb/lib/cmap/wire_protocol/compression.js"(exports2) {
  17913. "use strict";
  17914. Object.defineProperty(exports2, "__esModule", { value: true });
  17915. exports2.decompress = exports2.compress = exports2.uncompressibleCommands = exports2.Compressor = void 0;
  17916. var util_1 = require("util");
  17917. var zlib = require("zlib");
  17918. var constants_1 = require_constants2();
  17919. var deps_1 = require_deps();
  17920. var error_1 = require_error();
  17921. exports2.Compressor = Object.freeze({
  17922. none: 0,
  17923. snappy: 1,
  17924. zlib: 2,
  17925. zstd: 3
  17926. });
  17927. exports2.uncompressibleCommands = /* @__PURE__ */ new Set([
  17928. constants_1.LEGACY_HELLO_COMMAND,
  17929. "saslStart",
  17930. "saslContinue",
  17931. "getnonce",
  17932. "authenticate",
  17933. "createUser",
  17934. "updateUser",
  17935. "copydbSaslStart",
  17936. "copydbgetnonce",
  17937. "copydb"
  17938. ]);
  17939. var ZSTD_COMPRESSION_LEVEL = 3;
  17940. var zlibInflate = (0, util_1.promisify)(zlib.inflate.bind(zlib));
  17941. var zlibDeflate = (0, util_1.promisify)(zlib.deflate.bind(zlib));
  17942. var zstd;
  17943. var Snappy = null;
  17944. function loadSnappy() {
  17945. if (Snappy == null) {
  17946. const snappyImport = (0, deps_1.getSnappy)();
  17947. if ("kModuleError" in snappyImport) {
  17948. throw snappyImport.kModuleError;
  17949. }
  17950. Snappy = snappyImport;
  17951. }
  17952. return Snappy;
  17953. }
  17954. async function compress(options, dataToBeCompressed) {
  17955. const zlibOptions = {};
  17956. switch (options.agreedCompressor) {
  17957. case "snappy": {
  17958. Snappy ?? (Snappy = loadSnappy());
  17959. return Snappy.compress(dataToBeCompressed);
  17960. }
  17961. case "zstd": {
  17962. loadZstd();
  17963. if ("kModuleError" in zstd) {
  17964. throw zstd["kModuleError"];
  17965. }
  17966. return zstd.compress(dataToBeCompressed, ZSTD_COMPRESSION_LEVEL);
  17967. }
  17968. case "zlib": {
  17969. if (options.zlibCompressionLevel) {
  17970. zlibOptions.level = options.zlibCompressionLevel;
  17971. }
  17972. return zlibDeflate(dataToBeCompressed, zlibOptions);
  17973. }
  17974. default: {
  17975. throw new error_1.MongoInvalidArgumentError(`Unknown compressor ${options.agreedCompressor} failed to compress`);
  17976. }
  17977. }
  17978. }
  17979. exports2.compress = compress;
  17980. async function decompress(compressorID, compressedData) {
  17981. if (compressorID !== exports2.Compressor.snappy && compressorID !== exports2.Compressor.zstd && compressorID !== exports2.Compressor.zlib && compressorID !== exports2.Compressor.none) {
  17982. throw new error_1.MongoDecompressionError(`Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`);
  17983. }
  17984. switch (compressorID) {
  17985. case exports2.Compressor.snappy: {
  17986. Snappy ?? (Snappy = loadSnappy());
  17987. return Snappy.uncompress(compressedData, { asBuffer: true });
  17988. }
  17989. case exports2.Compressor.zstd: {
  17990. loadZstd();
  17991. if ("kModuleError" in zstd) {
  17992. throw zstd["kModuleError"];
  17993. }
  17994. return zstd.decompress(compressedData);
  17995. }
  17996. case exports2.Compressor.zlib: {
  17997. return zlibInflate(compressedData);
  17998. }
  17999. default: {
  18000. return compressedData;
  18001. }
  18002. }
  18003. }
  18004. exports2.decompress = decompress;
  18005. function loadZstd() {
  18006. if (!zstd) {
  18007. zstd = (0, deps_1.getZstdLibrary)();
  18008. }
  18009. }
  18010. }
  18011. });
  18012. // node_modules/mongodb/lib/encrypter.js
  18013. var require_encrypter = __commonJS({
  18014. "node_modules/mongodb/lib/encrypter.js"(exports2) {
  18015. "use strict";
  18016. Object.defineProperty(exports2, "__esModule", { value: true });
  18017. exports2.Encrypter = void 0;
  18018. var constants_1 = require_constants2();
  18019. var error_1 = require_error();
  18020. var mongo_client_1 = require_mongo_client();
  18021. var utils_1 = require_utils();
  18022. var AutoEncrypterClass;
  18023. var kInternalClient = Symbol("internalClient");
  18024. var Encrypter = class {
  18025. constructor(client, uri, options) {
  18026. if (typeof options.autoEncryption !== "object") {
  18027. throw new error_1.MongoInvalidArgumentError('Option "autoEncryption" must be specified');
  18028. }
  18029. this[kInternalClient] = null;
  18030. this.bypassAutoEncryption = !!options.autoEncryption.bypassAutoEncryption;
  18031. this.needsConnecting = false;
  18032. if (options.maxPoolSize === 0 && options.autoEncryption.keyVaultClient == null) {
  18033. options.autoEncryption.keyVaultClient = client;
  18034. } else if (options.autoEncryption.keyVaultClient == null) {
  18035. options.autoEncryption.keyVaultClient = this.getInternalClient(client, uri, options);
  18036. }
  18037. if (this.bypassAutoEncryption) {
  18038. options.autoEncryption.metadataClient = void 0;
  18039. } else if (options.maxPoolSize === 0) {
  18040. options.autoEncryption.metadataClient = client;
  18041. } else {
  18042. options.autoEncryption.metadataClient = this.getInternalClient(client, uri, options);
  18043. }
  18044. if (options.proxyHost) {
  18045. options.autoEncryption.proxyOptions = {
  18046. proxyHost: options.proxyHost,
  18047. proxyPort: options.proxyPort,
  18048. proxyUsername: options.proxyUsername,
  18049. proxyPassword: options.proxyPassword
  18050. };
  18051. }
  18052. this.autoEncrypter = new AutoEncrypterClass(client, options.autoEncryption);
  18053. }
  18054. getInternalClient(client, uri, options) {
  18055. let internalClient = this[kInternalClient];
  18056. if (internalClient == null) {
  18057. const clonedOptions = {};
  18058. for (const key of [
  18059. ...Object.getOwnPropertyNames(options),
  18060. ...Object.getOwnPropertySymbols(options)
  18061. ]) {
  18062. if (["autoEncryption", "minPoolSize", "servers", "caseTranslate", "dbName"].includes(key))
  18063. continue;
  18064. Reflect.set(clonedOptions, key, Reflect.get(options, key));
  18065. }
  18066. clonedOptions.minPoolSize = 0;
  18067. internalClient = new mongo_client_1.MongoClient(uri, clonedOptions);
  18068. this[kInternalClient] = internalClient;
  18069. for (const eventName of constants_1.MONGO_CLIENT_EVENTS) {
  18070. for (const listener of client.listeners(eventName)) {
  18071. internalClient.on(eventName, listener);
  18072. }
  18073. }
  18074. client.on("newListener", (eventName, listener) => {
  18075. internalClient == null ? void 0 : internalClient.on(eventName, listener);
  18076. });
  18077. this.needsConnecting = true;
  18078. }
  18079. return internalClient;
  18080. }
  18081. async connectInternalClient() {
  18082. const internalClient = this[kInternalClient];
  18083. if (this.needsConnecting && internalClient != null) {
  18084. this.needsConnecting = false;
  18085. await internalClient.connect();
  18086. }
  18087. }
  18088. close(client, force, callback) {
  18089. this.autoEncrypter.teardown(!!force, (e) => {
  18090. const internalClient = this[kInternalClient];
  18091. if (internalClient != null && client !== internalClient) {
  18092. internalClient.close(force).then(() => callback(), (error) => callback(error));
  18093. return;
  18094. }
  18095. callback(e);
  18096. });
  18097. }
  18098. static checkForMongoCrypt() {
  18099. const mongodbClientEncryption = (0, utils_1.getMongoDBClientEncryption)();
  18100. if (mongodbClientEncryption == null) {
  18101. throw new error_1.MongoMissingDependencyError("Auto-encryption requested, but the module is not installed. Please add `mongodb-client-encryption` as a dependency of your project");
  18102. }
  18103. AutoEncrypterClass = mongodbClientEncryption.extension(require_lib3()).AutoEncrypter;
  18104. }
  18105. };
  18106. exports2.Encrypter = Encrypter;
  18107. }
  18108. });
  18109. // node_modules/mongodb/lib/mongo_logger.js
  18110. var require_mongo_logger = __commonJS({
  18111. "node_modules/mongodb/lib/mongo_logger.js"(exports2) {
  18112. "use strict";
  18113. Object.defineProperty(exports2, "__esModule", { value: true });
  18114. exports2.MongoLogger = exports2.stringifyWithMaxLen = exports2.createStdioLogger = exports2.MongoLoggableComponent = exports2.SEVERITY_LEVEL_MAP = exports2.DEFAULT_MAX_DOCUMENT_LENGTH = exports2.SeverityLevel = void 0;
  18115. var bson_1 = require_bson();
  18116. var util_1 = require("util");
  18117. var constants_1 = require_constants2();
  18118. var utils_1 = require_utils();
  18119. exports2.SeverityLevel = Object.freeze({
  18120. EMERGENCY: "emergency",
  18121. ALERT: "alert",
  18122. CRITICAL: "critical",
  18123. ERROR: "error",
  18124. WARNING: "warn",
  18125. NOTICE: "notice",
  18126. INFORMATIONAL: "info",
  18127. DEBUG: "debug",
  18128. TRACE: "trace",
  18129. OFF: "off"
  18130. });
  18131. exports2.DEFAULT_MAX_DOCUMENT_LENGTH = 1e3;
  18132. var SeverityLevelMap = class extends Map {
  18133. constructor(entries) {
  18134. const newEntries = [];
  18135. for (const [level, value] of entries) {
  18136. newEntries.push([value, level]);
  18137. }
  18138. newEntries.push(...entries);
  18139. super(newEntries);
  18140. }
  18141. getNumericSeverityLevel(severity) {
  18142. return this.get(severity);
  18143. }
  18144. getSeverityLevelName(level) {
  18145. return this.get(level);
  18146. }
  18147. };
  18148. exports2.SEVERITY_LEVEL_MAP = new SeverityLevelMap([
  18149. [exports2.SeverityLevel.OFF, -Infinity],
  18150. [exports2.SeverityLevel.EMERGENCY, 0],
  18151. [exports2.SeverityLevel.ALERT, 1],
  18152. [exports2.SeverityLevel.CRITICAL, 2],
  18153. [exports2.SeverityLevel.ERROR, 3],
  18154. [exports2.SeverityLevel.WARNING, 4],
  18155. [exports2.SeverityLevel.NOTICE, 5],
  18156. [exports2.SeverityLevel.INFORMATIONAL, 6],
  18157. [exports2.SeverityLevel.DEBUG, 7],
  18158. [exports2.SeverityLevel.TRACE, 8]
  18159. ]);
  18160. exports2.MongoLoggableComponent = Object.freeze({
  18161. COMMAND: "command",
  18162. TOPOLOGY: "topology",
  18163. SERVER_SELECTION: "serverSelection",
  18164. CONNECTION: "connection"
  18165. });
  18166. function parseSeverityFromString(s) {
  18167. const validSeverities = Object.values(exports2.SeverityLevel);
  18168. const lowerSeverity = s == null ? void 0 : s.toLowerCase();
  18169. if (lowerSeverity != null && validSeverities.includes(lowerSeverity)) {
  18170. return lowerSeverity;
  18171. }
  18172. return null;
  18173. }
  18174. function createStdioLogger(stream) {
  18175. return {
  18176. write: (log) => {
  18177. stream.write((0, util_1.inspect)(log, { compact: true, breakLength: Infinity }), "utf-8");
  18178. return;
  18179. }
  18180. };
  18181. }
  18182. exports2.createStdioLogger = createStdioLogger;
  18183. function resolveLogPath({ MONGODB_LOG_PATH }, { mongodbLogPath }) {
  18184. if (typeof mongodbLogPath === "string" && /^stderr$/i.test(mongodbLogPath)) {
  18185. return createStdioLogger(process.stderr);
  18186. }
  18187. if (typeof mongodbLogPath === "string" && /^stdout$/i.test(mongodbLogPath)) {
  18188. return createStdioLogger(process.stdout);
  18189. }
  18190. if (typeof mongodbLogPath === "object" && typeof (mongodbLogPath == null ? void 0 : mongodbLogPath.write) === "function") {
  18191. return mongodbLogPath;
  18192. }
  18193. if (MONGODB_LOG_PATH && /^stderr$/i.test(MONGODB_LOG_PATH)) {
  18194. return createStdioLogger(process.stderr);
  18195. }
  18196. if (MONGODB_LOG_PATH && /^stdout$/i.test(MONGODB_LOG_PATH)) {
  18197. return createStdioLogger(process.stdout);
  18198. }
  18199. return createStdioLogger(process.stderr);
  18200. }
  18201. function compareSeverity(s0, s1) {
  18202. const s0Num = exports2.SEVERITY_LEVEL_MAP.getNumericSeverityLevel(s0);
  18203. const s1Num = exports2.SEVERITY_LEVEL_MAP.getNumericSeverityLevel(s1);
  18204. return s0Num < s1Num ? -1 : s0Num > s1Num ? 1 : 0;
  18205. }
  18206. function stringifyWithMaxLen(value, maxDocumentLength) {
  18207. const ejson = bson_1.EJSON.stringify(value);
  18208. return maxDocumentLength !== 0 && ejson.length > maxDocumentLength ? `${ejson.slice(0, maxDocumentLength)}...` : ejson;
  18209. }
  18210. exports2.stringifyWithMaxLen = stringifyWithMaxLen;
  18211. function isLogConvertible(obj) {
  18212. const objAsLogConvertible = obj;
  18213. return objAsLogConvertible.toLog !== void 0 && typeof objAsLogConvertible.toLog === "function";
  18214. }
  18215. function attachCommandFields(log, commandEvent) {
  18216. log.commandName = commandEvent.commandName;
  18217. log.requestId = commandEvent.requestId;
  18218. log.driverConnectionId = commandEvent == null ? void 0 : commandEvent.connectionId;
  18219. const { host, port } = utils_1.HostAddress.fromString(commandEvent.address).toHostPort();
  18220. log.serverHost = host;
  18221. log.serverPort = port;
  18222. if (commandEvent == null ? void 0 : commandEvent.serviceId) {
  18223. log.serviceId = commandEvent.serviceId.toHexString();
  18224. }
  18225. return log;
  18226. }
  18227. function attachConnectionFields(log, connectionPoolEvent) {
  18228. const { host, port } = utils_1.HostAddress.fromString(connectionPoolEvent.address).toHostPort();
  18229. log.serverHost = host;
  18230. log.serverPort = port;
  18231. return log;
  18232. }
  18233. function defaultLogTransform(logObject, maxDocumentLength = exports2.DEFAULT_MAX_DOCUMENT_LENGTH) {
  18234. var _a;
  18235. let log = /* @__PURE__ */ Object.create(null);
  18236. switch (logObject.name) {
  18237. case constants_1.COMMAND_STARTED:
  18238. log = attachCommandFields(log, logObject);
  18239. log.message = "Command started";
  18240. log.command = stringifyWithMaxLen(logObject.command, maxDocumentLength);
  18241. log.databaseName = logObject.databaseName;
  18242. return log;
  18243. case constants_1.COMMAND_SUCCEEDED:
  18244. log = attachCommandFields(log, logObject);
  18245. log.message = "Command succeeded";
  18246. log.durationMS = logObject.duration;
  18247. log.reply = stringifyWithMaxLen(logObject.reply, maxDocumentLength);
  18248. return log;
  18249. case constants_1.COMMAND_FAILED:
  18250. log = attachCommandFields(log, logObject);
  18251. log.message = "Command failed";
  18252. log.durationMS = logObject.duration;
  18253. log.failure = logObject.failure;
  18254. return log;
  18255. case constants_1.CONNECTION_POOL_CREATED:
  18256. log = attachConnectionFields(log, logObject);
  18257. log.message = "Connection pool created";
  18258. if (logObject.options) {
  18259. const { maxIdleTimeMS, minPoolSize, maxPoolSize, maxConnecting, waitQueueTimeoutMS } = logObject.options;
  18260. log = {
  18261. ...log,
  18262. maxIdleTimeMS,
  18263. minPoolSize,
  18264. maxPoolSize,
  18265. maxConnecting,
  18266. waitQueueTimeoutMS
  18267. };
  18268. }
  18269. return log;
  18270. case constants_1.CONNECTION_POOL_READY:
  18271. log = attachConnectionFields(log, logObject);
  18272. log.message = "Connection pool ready";
  18273. return log;
  18274. case constants_1.CONNECTION_POOL_CLEARED:
  18275. log = attachConnectionFields(log, logObject);
  18276. log.message = "Connection pool cleared";
  18277. if (((_a = logObject.serviceId) == null ? void 0 : _a._bsontype) === "ObjectId") {
  18278. log.serviceId = logObject.serviceId.toHexString();
  18279. }
  18280. return log;
  18281. case constants_1.CONNECTION_POOL_CLOSED:
  18282. log = attachConnectionFields(log, logObject);
  18283. log.message = "Connection pool closed";
  18284. return log;
  18285. case constants_1.CONNECTION_CREATED:
  18286. log = attachConnectionFields(log, logObject);
  18287. log.message = "Connection created";
  18288. log.driverConnectionId = logObject.connectionId;
  18289. return log;
  18290. case constants_1.CONNECTION_READY:
  18291. log = attachConnectionFields(log, logObject);
  18292. log.message = "Connection ready";
  18293. log.driverConnectionId = logObject.connectionId;
  18294. return log;
  18295. case constants_1.CONNECTION_CLOSED:
  18296. log = attachConnectionFields(log, logObject);
  18297. log.message = "Connection closed";
  18298. log.driverConnectionId = logObject.connectionId;
  18299. switch (logObject.reason) {
  18300. case "stale":
  18301. log.reason = "Connection became stale because the pool was cleared";
  18302. break;
  18303. case "idle":
  18304. log.reason = "Connection has been available but unused for longer than the configured max idle time";
  18305. break;
  18306. case "error":
  18307. log.reason = "An error occurred while using the connection";
  18308. if (logObject.error) {
  18309. log.error = logObject.error;
  18310. }
  18311. break;
  18312. case "poolClosed":
  18313. log.reason = "Connection pool was closed";
  18314. break;
  18315. default:
  18316. log.reason = `Unknown close reason: ${logObject.reason}`;
  18317. }
  18318. return log;
  18319. case constants_1.CONNECTION_CHECK_OUT_STARTED:
  18320. log = attachConnectionFields(log, logObject);
  18321. log.message = "Connection checkout started";
  18322. return log;
  18323. case constants_1.CONNECTION_CHECK_OUT_FAILED:
  18324. log = attachConnectionFields(log, logObject);
  18325. log.message = "Connection checkout failed";
  18326. switch (logObject.reason) {
  18327. case "poolClosed":
  18328. log.reason = "Connection pool was closed";
  18329. break;
  18330. case "timeout":
  18331. log.reason = "Wait queue timeout elapsed without a connection becoming available";
  18332. break;
  18333. case "connectionError":
  18334. log.reason = "An error occurred while trying to establish a new connection";
  18335. if (logObject.error) {
  18336. log.error = logObject.error;
  18337. }
  18338. break;
  18339. default:
  18340. log.reason = `Unknown close reason: ${logObject.reason}`;
  18341. }
  18342. return log;
  18343. case constants_1.CONNECTION_CHECKED_OUT:
  18344. log = attachConnectionFields(log, logObject);
  18345. log.message = "Connection checked out";
  18346. log.driverConnectionId = logObject.connectionId;
  18347. return log;
  18348. case constants_1.CONNECTION_CHECKED_IN:
  18349. log = attachConnectionFields(log, logObject);
  18350. log.message = "Connection checked in";
  18351. log.driverConnectionId = logObject.connectionId;
  18352. return log;
  18353. default:
  18354. for (const [key, value] of Object.entries(logObject)) {
  18355. if (value != null)
  18356. log[key] = value;
  18357. }
  18358. }
  18359. return log;
  18360. }
  18361. var MongoLogger = class {
  18362. constructor(options) {
  18363. this.error = this.log.bind(this, "error");
  18364. this.warn = this.log.bind(this, "warn");
  18365. this.info = this.log.bind(this, "info");
  18366. this.debug = this.log.bind(this, "debug");
  18367. this.trace = this.log.bind(this, "trace");
  18368. this.componentSeverities = options.componentSeverities;
  18369. this.maxDocumentLength = options.maxDocumentLength;
  18370. this.logDestination = options.logDestination;
  18371. }
  18372. log(severity, component, message) {
  18373. if (compareSeverity(severity, this.componentSeverities[component]) > 0)
  18374. return;
  18375. let logMessage = { t: /* @__PURE__ */ new Date(), c: component, s: severity };
  18376. if (typeof message === "string") {
  18377. logMessage.message = message;
  18378. } else if (typeof message === "object") {
  18379. if (isLogConvertible(message)) {
  18380. logMessage = { ...logMessage, ...message.toLog() };
  18381. } else {
  18382. logMessage = { ...logMessage, ...defaultLogTransform(message, this.maxDocumentLength) };
  18383. }
  18384. }
  18385. this.logDestination.write(logMessage);
  18386. }
  18387. /**
  18388. * Merges options set through environment variables and the MongoClient, preferring environment
  18389. * variables when both are set, and substituting defaults for values not set. Options set in
  18390. * constructor take precedence over both environment variables and MongoClient options.
  18391. *
  18392. * @remarks
  18393. * When parsing component severity levels, invalid values are treated as unset and replaced with
  18394. * the default severity.
  18395. *
  18396. * @param envOptions - options set for the logger from the environment
  18397. * @param clientOptions - options set for the logger in the MongoClient options
  18398. * @returns a MongoLoggerOptions object to be used when instantiating a new MongoLogger
  18399. */
  18400. static resolveOptions(envOptions, clientOptions) {
  18401. const combinedOptions = {
  18402. ...envOptions,
  18403. ...clientOptions,
  18404. mongodbLogPath: resolveLogPath(envOptions, clientOptions)
  18405. };
  18406. const defaultSeverity = parseSeverityFromString(combinedOptions.MONGODB_LOG_ALL) ?? exports2.SeverityLevel.OFF;
  18407. return {
  18408. componentSeverities: {
  18409. command: parseSeverityFromString(combinedOptions.MONGODB_LOG_COMMAND) ?? defaultSeverity,
  18410. topology: parseSeverityFromString(combinedOptions.MONGODB_LOG_TOPOLOGY) ?? defaultSeverity,
  18411. serverSelection: parseSeverityFromString(combinedOptions.MONGODB_LOG_SERVER_SELECTION) ?? defaultSeverity,
  18412. connection: parseSeverityFromString(combinedOptions.MONGODB_LOG_CONNECTION) ?? defaultSeverity,
  18413. default: defaultSeverity
  18414. },
  18415. maxDocumentLength: (0, utils_1.parseUnsignedInteger)(combinedOptions.MONGODB_LOG_MAX_DOCUMENT_LENGTH) ?? 1e3,
  18416. logDestination: combinedOptions.mongodbLogPath
  18417. };
  18418. }
  18419. };
  18420. exports2.MongoLogger = MongoLogger;
  18421. }
  18422. });
  18423. // node_modules/mongodb/lib/connection_string.js
  18424. var require_connection_string = __commonJS({
  18425. "node_modules/mongodb/lib/connection_string.js"(exports2) {
  18426. "use strict";
  18427. Object.defineProperty(exports2, "__esModule", { value: true });
  18428. exports2.FEATURE_FLAGS = exports2.DEFAULT_OPTIONS = exports2.OPTIONS = exports2.parseOptions = exports2.resolveSRVRecord = void 0;
  18429. var dns = require("dns");
  18430. var fs = require("fs");
  18431. var mongodb_connection_string_url_1 = require_lib2();
  18432. var url_1 = require("url");
  18433. var mongo_credentials_1 = require_mongo_credentials();
  18434. var providers_1 = require_providers();
  18435. var client_metadata_1 = require_client_metadata();
  18436. var compression_1 = require_compression();
  18437. var encrypter_1 = require_encrypter();
  18438. var error_1 = require_error();
  18439. var mongo_client_1 = require_mongo_client();
  18440. var mongo_logger_1 = require_mongo_logger();
  18441. var read_concern_1 = require_read_concern();
  18442. var read_preference_1 = require_read_preference();
  18443. var utils_1 = require_utils();
  18444. var write_concern_1 = require_write_concern();
  18445. var VALID_TXT_RECORDS = ["authSource", "replicaSet", "loadBalanced"];
  18446. var LB_SINGLE_HOST_ERROR = "loadBalanced option only supported with a single host in the URI";
  18447. var LB_REPLICA_SET_ERROR = "loadBalanced option not supported with a replicaSet option";
  18448. var LB_DIRECT_CONNECTION_ERROR = "loadBalanced option not supported when directConnection is provided";
  18449. async function resolveSRVRecord(options) {
  18450. if (typeof options.srvHost !== "string") {
  18451. throw new error_1.MongoAPIError('Option "srvHost" must not be empty');
  18452. }
  18453. if (options.srvHost.split(".").length < 3) {
  18454. throw new error_1.MongoAPIError("URI must include hostname, domain name, and tld");
  18455. }
  18456. const lookupAddress = options.srvHost;
  18457. const addresses = await dns.promises.resolveSrv(`_${options.srvServiceName}._tcp.${lookupAddress}`);
  18458. if (addresses.length === 0) {
  18459. throw new error_1.MongoAPIError("No addresses found at host");
  18460. }
  18461. for (const { name } of addresses) {
  18462. if (!(0, utils_1.matchesParentDomain)(name, lookupAddress)) {
  18463. throw new error_1.MongoAPIError("Server record does not share hostname with parent URI");
  18464. }
  18465. }
  18466. const hostAddresses = addresses.map((r) => utils_1.HostAddress.fromString(`${r.name}:${r.port ?? 27017}`));
  18467. validateLoadBalancedOptions(hostAddresses, options, true);
  18468. let record;
  18469. try {
  18470. record = await dns.promises.resolveTxt(lookupAddress);
  18471. } catch (error) {
  18472. if (error.code !== "ENODATA" && error.code !== "ENOTFOUND") {
  18473. throw error;
  18474. }
  18475. return hostAddresses;
  18476. }
  18477. if (record.length > 1) {
  18478. throw new error_1.MongoParseError("Multiple text records not allowed");
  18479. }
  18480. const txtRecordOptions = new url_1.URLSearchParams(record[0].join(""));
  18481. const txtRecordOptionKeys = [...txtRecordOptions.keys()];
  18482. if (txtRecordOptionKeys.some((key) => !VALID_TXT_RECORDS.includes(key))) {
  18483. throw new error_1.MongoParseError(`Text record may only set any of: ${VALID_TXT_RECORDS.join(", ")}`);
  18484. }
  18485. if (VALID_TXT_RECORDS.some((option) => txtRecordOptions.get(option) === "")) {
  18486. throw new error_1.MongoParseError("Cannot have empty URI params in DNS TXT Record");
  18487. }
  18488. const source = txtRecordOptions.get("authSource") ?? void 0;
  18489. const replicaSet = txtRecordOptions.get("replicaSet") ?? void 0;
  18490. const loadBalanced = txtRecordOptions.get("loadBalanced") ?? void 0;
  18491. if (!options.userSpecifiedAuthSource && source && options.credentials && !providers_1.AUTH_MECHS_AUTH_SRC_EXTERNAL.has(options.credentials.mechanism)) {
  18492. options.credentials = mongo_credentials_1.MongoCredentials.merge(options.credentials, { source });
  18493. }
  18494. if (!options.userSpecifiedReplicaSet && replicaSet) {
  18495. options.replicaSet = replicaSet;
  18496. }
  18497. if (loadBalanced === "true") {
  18498. options.loadBalanced = true;
  18499. }
  18500. if (options.replicaSet && options.srvMaxHosts > 0) {
  18501. throw new error_1.MongoParseError("Cannot combine replicaSet option with srvMaxHosts");
  18502. }
  18503. validateLoadBalancedOptions(hostAddresses, options, true);
  18504. return hostAddresses;
  18505. }
  18506. exports2.resolveSRVRecord = resolveSRVRecord;
  18507. function checkTLSOptions(allOptions) {
  18508. if (!allOptions)
  18509. return;
  18510. const check = (a, b) => {
  18511. if (allOptions.has(a) && allOptions.has(b)) {
  18512. throw new error_1.MongoAPIError(`The '${a}' option cannot be used with the '${b}' option`);
  18513. }
  18514. };
  18515. check("tlsInsecure", "tlsAllowInvalidCertificates");
  18516. check("tlsInsecure", "tlsAllowInvalidHostnames");
  18517. check("tlsInsecure", "tlsDisableCertificateRevocationCheck");
  18518. check("tlsInsecure", "tlsDisableOCSPEndpointCheck");
  18519. check("tlsAllowInvalidCertificates", "tlsDisableCertificateRevocationCheck");
  18520. check("tlsAllowInvalidCertificates", "tlsDisableOCSPEndpointCheck");
  18521. check("tlsDisableCertificateRevocationCheck", "tlsDisableOCSPEndpointCheck");
  18522. }
  18523. var TRUTHS = /* @__PURE__ */ new Set(["true", "t", "1", "y", "yes"]);
  18524. var FALSEHOODS = /* @__PURE__ */ new Set(["false", "f", "0", "n", "no", "-1"]);
  18525. function getBoolean(name, value) {
  18526. if (typeof value === "boolean")
  18527. return value;
  18528. const valueString = String(value).toLowerCase();
  18529. if (TRUTHS.has(valueString)) {
  18530. if (valueString !== "true") {
  18531. (0, utils_1.emitWarningOnce)(`deprecated value for ${name} : ${valueString} - please update to ${name} : true instead`);
  18532. }
  18533. return true;
  18534. }
  18535. if (FALSEHOODS.has(valueString)) {
  18536. if (valueString !== "false") {
  18537. (0, utils_1.emitWarningOnce)(`deprecated value for ${name} : ${valueString} - please update to ${name} : false instead`);
  18538. }
  18539. return false;
  18540. }
  18541. throw new error_1.MongoParseError(`Expected ${name} to be stringified boolean value, got: ${value}`);
  18542. }
  18543. function getIntFromOptions(name, value) {
  18544. const parsedInt = (0, utils_1.parseInteger)(value);
  18545. if (parsedInt != null) {
  18546. return parsedInt;
  18547. }
  18548. throw new error_1.MongoParseError(`Expected ${name} to be stringified int value, got: ${value}`);
  18549. }
  18550. function getUIntFromOptions(name, value) {
  18551. const parsedValue = getIntFromOptions(name, value);
  18552. if (parsedValue < 0) {
  18553. throw new error_1.MongoParseError(`${name} can only be a positive int value, got: ${value}`);
  18554. }
  18555. return parsedValue;
  18556. }
  18557. function* entriesFromString(value) {
  18558. const keyValuePairs = value.split(",");
  18559. for (const keyValue of keyValuePairs) {
  18560. const [key, value2] = keyValue.split(/:(.*)/);
  18561. if (value2 == null) {
  18562. throw new error_1.MongoParseError("Cannot have undefined values in key value pairs");
  18563. }
  18564. yield [key, value2];
  18565. }
  18566. }
  18567. var CaseInsensitiveMap = class extends Map {
  18568. constructor(entries = []) {
  18569. super(entries.map(([k, v]) => [k.toLowerCase(), v]));
  18570. }
  18571. has(k) {
  18572. return super.has(k.toLowerCase());
  18573. }
  18574. get(k) {
  18575. return super.get(k.toLowerCase());
  18576. }
  18577. set(k, v) {
  18578. return super.set(k.toLowerCase(), v);
  18579. }
  18580. delete(k) {
  18581. return super.delete(k.toLowerCase());
  18582. }
  18583. };
  18584. function parseOptions(uri, mongoClient = void 0, options = {}) {
  18585. if (mongoClient != null && !(mongoClient instanceof mongo_client_1.MongoClient)) {
  18586. options = mongoClient;
  18587. mongoClient = void 0;
  18588. }
  18589. if (options.useBigInt64 && typeof options.promoteLongs === "boolean" && !options.promoteLongs) {
  18590. throw new error_1.MongoAPIError("Must request either bigint or Long for int64 deserialization");
  18591. }
  18592. if (options.useBigInt64 && typeof options.promoteValues === "boolean" && !options.promoteValues) {
  18593. throw new error_1.MongoAPIError("Must request either bigint or Long for int64 deserialization");
  18594. }
  18595. const url = new mongodb_connection_string_url_1.default(uri);
  18596. const { hosts, isSRV } = url;
  18597. const mongoOptions = /* @__PURE__ */ Object.create(null);
  18598. for (const flag of Object.getOwnPropertySymbols(options)) {
  18599. if (exports2.FEATURE_FLAGS.has(flag)) {
  18600. mongoOptions[flag] = options[flag];
  18601. }
  18602. }
  18603. mongoOptions.hosts = isSRV ? [] : hosts.map(utils_1.HostAddress.fromString);
  18604. const urlOptions = new CaseInsensitiveMap();
  18605. if (url.pathname !== "/" && url.pathname !== "") {
  18606. const dbName = decodeURIComponent(url.pathname[0] === "/" ? url.pathname.slice(1) : url.pathname);
  18607. if (dbName) {
  18608. urlOptions.set("dbName", [dbName]);
  18609. }
  18610. }
  18611. if (url.username !== "") {
  18612. const auth = {
  18613. username: decodeURIComponent(url.username)
  18614. };
  18615. if (typeof url.password === "string") {
  18616. auth.password = decodeURIComponent(url.password);
  18617. }
  18618. urlOptions.set("auth", [auth]);
  18619. }
  18620. for (const key of url.searchParams.keys()) {
  18621. const values = [...url.searchParams.getAll(key)];
  18622. if (values.includes("")) {
  18623. throw new error_1.MongoAPIError("URI cannot contain options with no value");
  18624. }
  18625. if (!urlOptions.has(key)) {
  18626. urlOptions.set(key, values);
  18627. }
  18628. }
  18629. const objectOptions = new CaseInsensitiveMap(Object.entries(options).filter(([, v]) => v != null));
  18630. if (urlOptions.has("serverApi")) {
  18631. throw new error_1.MongoParseError("URI cannot contain `serverApi`, it can only be passed to the client");
  18632. }
  18633. const uriMechanismProperties = urlOptions.get("authMechanismProperties");
  18634. if (uriMechanismProperties) {
  18635. for (const property of uriMechanismProperties) {
  18636. if (/(^|,)ALLOWED_HOSTS:/.test(property)) {
  18637. throw new error_1.MongoParseError("Auth mechanism property ALLOWED_HOSTS is not allowed in the connection string.");
  18638. }
  18639. }
  18640. }
  18641. if (objectOptions.has("loadBalanced")) {
  18642. throw new error_1.MongoParseError("loadBalanced is only a valid option in the URI");
  18643. }
  18644. const allProvidedOptions = new CaseInsensitiveMap();
  18645. const allProvidedKeys = /* @__PURE__ */ new Set([...urlOptions.keys(), ...objectOptions.keys()]);
  18646. for (const key of allProvidedKeys) {
  18647. const values = [];
  18648. const objectOptionValue = objectOptions.get(key);
  18649. if (objectOptionValue != null) {
  18650. values.push(objectOptionValue);
  18651. }
  18652. const urlValues = urlOptions.get(key) ?? [];
  18653. values.push(...urlValues);
  18654. allProvidedOptions.set(key, values);
  18655. }
  18656. const didMapTLSCertificateFile = allProvidedOptions.has("tlsCertificateKeyFile") && !allProvidedOptions.has("tlsCertificateFile");
  18657. if (didMapTLSCertificateFile) {
  18658. allProvidedOptions.set("tlsCertificateFile", allProvidedOptions.get("tlsCertificateKeyFile"));
  18659. }
  18660. if (allProvidedOptions.has("tls") || allProvidedOptions.has("ssl")) {
  18661. const tlsAndSslOpts = (allProvidedOptions.get("tls") || []).concat(allProvidedOptions.get("ssl") || []).map(getBoolean.bind(null, "tls/ssl"));
  18662. if (new Set(tlsAndSslOpts).size !== 1) {
  18663. throw new error_1.MongoParseError("All values of tls/ssl must be the same.");
  18664. }
  18665. }
  18666. checkTLSOptions(allProvidedOptions);
  18667. const unsupportedOptions = (0, utils_1.setDifference)(allProvidedKeys, Array.from(Object.keys(exports2.OPTIONS)).map((s) => s.toLowerCase()));
  18668. if (unsupportedOptions.size !== 0) {
  18669. const optionWord = unsupportedOptions.size > 1 ? "options" : "option";
  18670. const isOrAre = unsupportedOptions.size > 1 ? "are" : "is";
  18671. throw new error_1.MongoParseError(`${optionWord} ${Array.from(unsupportedOptions).join(", ")} ${isOrAre} not supported`);
  18672. }
  18673. for (const [key, descriptor] of Object.entries(exports2.OPTIONS)) {
  18674. const values = allProvidedOptions.get(key);
  18675. if (!values || values.length === 0) {
  18676. if (exports2.DEFAULT_OPTIONS.has(key)) {
  18677. setOption(mongoOptions, key, descriptor, [exports2.DEFAULT_OPTIONS.get(key)]);
  18678. }
  18679. } else {
  18680. const { deprecated } = descriptor;
  18681. const shouldEmitTLSCertificateFileDeprecation = didMapTLSCertificateFile && key === "tlsCertificateFile";
  18682. if (deprecated && !shouldEmitTLSCertificateFileDeprecation) {
  18683. const deprecatedMsg = typeof deprecated === "string" ? `: ${deprecated}` : "";
  18684. (0, utils_1.emitWarning)(`${key} is a deprecated option${deprecatedMsg}`);
  18685. }
  18686. setOption(mongoOptions, key, descriptor, values);
  18687. }
  18688. }
  18689. if (mongoOptions.credentials) {
  18690. const isGssapi = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_GSSAPI;
  18691. const isX509 = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_X509;
  18692. const isAws = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_AWS;
  18693. const isOidc = mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_OIDC;
  18694. if ((isGssapi || isX509) && allProvidedOptions.has("authSource") && mongoOptions.credentials.source !== "$external") {
  18695. throw new error_1.MongoParseError(`authMechanism ${mongoOptions.credentials.mechanism} requires an authSource of '$external'`);
  18696. }
  18697. if (!(isGssapi || isX509 || isAws || isOidc) && mongoOptions.dbName && !allProvidedOptions.has("authSource")) {
  18698. mongoOptions.credentials = mongo_credentials_1.MongoCredentials.merge(mongoOptions.credentials, {
  18699. source: mongoOptions.dbName
  18700. });
  18701. }
  18702. if (isAws && mongoOptions.credentials.username && !mongoOptions.credentials.password) {
  18703. throw new error_1.MongoMissingCredentialsError(`When using ${mongoOptions.credentials.mechanism} password must be set when a username is specified`);
  18704. }
  18705. mongoOptions.credentials.validate();
  18706. if (mongoOptions.credentials.password === "" && mongoOptions.credentials.username === "" && mongoOptions.credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT && Object.keys(mongoOptions.credentials.mechanismProperties).length === 0) {
  18707. delete mongoOptions.credentials;
  18708. }
  18709. }
  18710. if (!mongoOptions.dbName) {
  18711. mongoOptions.dbName = "test";
  18712. }
  18713. validateLoadBalancedOptions(hosts, mongoOptions, isSRV);
  18714. if (mongoClient && mongoOptions.autoEncryption) {
  18715. encrypter_1.Encrypter.checkForMongoCrypt();
  18716. mongoOptions.encrypter = new encrypter_1.Encrypter(mongoClient, uri, options);
  18717. mongoOptions.autoEncrypter = mongoOptions.encrypter.autoEncrypter;
  18718. }
  18719. mongoOptions.userSpecifiedAuthSource = objectOptions.has("authSource") || urlOptions.has("authSource");
  18720. mongoOptions.userSpecifiedReplicaSet = objectOptions.has("replicaSet") || urlOptions.has("replicaSet");
  18721. if (isSRV) {
  18722. mongoOptions.srvHost = hosts[0];
  18723. if (mongoOptions.directConnection) {
  18724. throw new error_1.MongoAPIError("SRV URI does not support directConnection");
  18725. }
  18726. if (mongoOptions.srvMaxHosts > 0 && typeof mongoOptions.replicaSet === "string") {
  18727. throw new error_1.MongoParseError("Cannot use srvMaxHosts option with replicaSet");
  18728. }
  18729. const noUserSpecifiedTLS = !objectOptions.has("tls") && !urlOptions.has("tls");
  18730. const noUserSpecifiedSSL = !objectOptions.has("ssl") && !urlOptions.has("ssl");
  18731. if (noUserSpecifiedTLS && noUserSpecifiedSSL) {
  18732. mongoOptions.tls = true;
  18733. }
  18734. } else {
  18735. const userSpecifiedSrvOptions = urlOptions.has("srvMaxHosts") || objectOptions.has("srvMaxHosts") || urlOptions.has("srvServiceName") || objectOptions.has("srvServiceName");
  18736. if (userSpecifiedSrvOptions) {
  18737. throw new error_1.MongoParseError("Cannot use srvMaxHosts or srvServiceName with a non-srv connection string");
  18738. }
  18739. }
  18740. if (mongoOptions.directConnection && mongoOptions.hosts.length !== 1) {
  18741. throw new error_1.MongoParseError("directConnection option requires exactly one host");
  18742. }
  18743. if (!mongoOptions.proxyHost && (mongoOptions.proxyPort || mongoOptions.proxyUsername || mongoOptions.proxyPassword)) {
  18744. throw new error_1.MongoParseError("Must specify proxyHost if other proxy options are passed");
  18745. }
  18746. if (mongoOptions.proxyUsername && !mongoOptions.proxyPassword || !mongoOptions.proxyUsername && mongoOptions.proxyPassword) {
  18747. throw new error_1.MongoParseError("Can only specify both of proxy username/password or neither");
  18748. }
  18749. const proxyOptions = ["proxyHost", "proxyPort", "proxyUsername", "proxyPassword"].map((key) => urlOptions.get(key) ?? []);
  18750. if (proxyOptions.some((options2) => options2.length > 1)) {
  18751. throw new error_1.MongoParseError("Proxy options cannot be specified multiple times in the connection string");
  18752. }
  18753. const loggerFeatureFlag = Symbol.for("@@mdb.enableMongoLogger");
  18754. mongoOptions[loggerFeatureFlag] = mongoOptions[loggerFeatureFlag] ?? false;
  18755. let loggerEnvOptions = {};
  18756. let loggerClientOptions = {};
  18757. if (mongoOptions[loggerFeatureFlag]) {
  18758. loggerEnvOptions = {
  18759. MONGODB_LOG_COMMAND: process.env.MONGODB_LOG_COMMAND,
  18760. MONGODB_LOG_TOPOLOGY: process.env.MONGODB_LOG_TOPOLOGY,
  18761. MONGODB_LOG_SERVER_SELECTION: process.env.MONGODB_LOG_SERVER_SELECTION,
  18762. MONGODB_LOG_CONNECTION: process.env.MONGODB_LOG_CONNECTION,
  18763. MONGODB_LOG_ALL: process.env.MONGODB_LOG_ALL,
  18764. MONGODB_LOG_MAX_DOCUMENT_LENGTH: process.env.MONGODB_LOG_MAX_DOCUMENT_LENGTH,
  18765. MONGODB_LOG_PATH: process.env.MONGODB_LOG_PATH,
  18766. ...mongoOptions[Symbol.for("@@mdb.internalLoggerConfig")]
  18767. };
  18768. loggerClientOptions = {
  18769. mongodbLogPath: mongoOptions.mongodbLogPath
  18770. };
  18771. }
  18772. mongoOptions.mongoLoggerOptions = mongo_logger_1.MongoLogger.resolveOptions(loggerEnvOptions, loggerClientOptions);
  18773. mongoOptions.metadata = (0, client_metadata_1.makeClientMetadata)(mongoOptions);
  18774. return mongoOptions;
  18775. }
  18776. exports2.parseOptions = parseOptions;
  18777. function validateLoadBalancedOptions(hosts, mongoOptions, isSrv) {
  18778. if (mongoOptions.loadBalanced) {
  18779. if (hosts.length > 1) {
  18780. throw new error_1.MongoParseError(LB_SINGLE_HOST_ERROR);
  18781. }
  18782. if (mongoOptions.replicaSet) {
  18783. throw new error_1.MongoParseError(LB_REPLICA_SET_ERROR);
  18784. }
  18785. if (mongoOptions.directConnection) {
  18786. throw new error_1.MongoParseError(LB_DIRECT_CONNECTION_ERROR);
  18787. }
  18788. if (isSrv && mongoOptions.srvMaxHosts > 0) {
  18789. throw new error_1.MongoParseError("Cannot limit srv hosts with loadBalanced enabled");
  18790. }
  18791. }
  18792. return;
  18793. }
  18794. function setOption(mongoOptions, key, descriptor, values) {
  18795. const { target, type, transform } = descriptor;
  18796. const name = target ?? key;
  18797. switch (type) {
  18798. case "boolean":
  18799. mongoOptions[name] = getBoolean(name, values[0]);
  18800. break;
  18801. case "int":
  18802. mongoOptions[name] = getIntFromOptions(name, values[0]);
  18803. break;
  18804. case "uint":
  18805. mongoOptions[name] = getUIntFromOptions(name, values[0]);
  18806. break;
  18807. case "string":
  18808. if (values[0] == null) {
  18809. break;
  18810. }
  18811. mongoOptions[name] = String(values[0]);
  18812. break;
  18813. case "record":
  18814. if (!(0, utils_1.isRecord)(values[0])) {
  18815. throw new error_1.MongoParseError(`${name} must be an object`);
  18816. }
  18817. mongoOptions[name] = values[0];
  18818. break;
  18819. case "any":
  18820. mongoOptions[name] = values[0];
  18821. break;
  18822. default: {
  18823. if (!transform) {
  18824. throw new error_1.MongoParseError("Descriptors missing a type must define a transform");
  18825. }
  18826. const transformValue = transform({ name, options: mongoOptions, values });
  18827. mongoOptions[name] = transformValue;
  18828. break;
  18829. }
  18830. }
  18831. }
  18832. exports2.OPTIONS = {
  18833. appName: {
  18834. type: "string"
  18835. },
  18836. auth: {
  18837. target: "credentials",
  18838. transform({ name, options, values: [value] }) {
  18839. if (!(0, utils_1.isRecord)(value, ["username", "password"])) {
  18840. throw new error_1.MongoParseError(`${name} must be an object with 'username' and 'password' properties`);
  18841. }
  18842. return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
  18843. username: value.username,
  18844. password: value.password
  18845. });
  18846. }
  18847. },
  18848. authMechanism: {
  18849. target: "credentials",
  18850. transform({ options, values: [value] }) {
  18851. var _a, _b;
  18852. const mechanisms = Object.values(providers_1.AuthMechanism);
  18853. const [mechanism] = mechanisms.filter((m) => m.match(RegExp(String.raw`\b${value}\b`, "i")));
  18854. if (!mechanism) {
  18855. throw new error_1.MongoParseError(`authMechanism one of ${mechanisms}, got ${value}`);
  18856. }
  18857. let source = (_a = options.credentials) == null ? void 0 : _a.source;
  18858. if (mechanism === providers_1.AuthMechanism.MONGODB_PLAIN || providers_1.AUTH_MECHS_AUTH_SRC_EXTERNAL.has(mechanism)) {
  18859. source = "$external";
  18860. }
  18861. let password = (_b = options.credentials) == null ? void 0 : _b.password;
  18862. if (mechanism === providers_1.AuthMechanism.MONGODB_X509 && password === "") {
  18863. password = void 0;
  18864. }
  18865. return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
  18866. mechanism,
  18867. source,
  18868. password
  18869. });
  18870. }
  18871. },
  18872. authMechanismProperties: {
  18873. target: "credentials",
  18874. transform({ options, values }) {
  18875. let mechanismProperties = /* @__PURE__ */ Object.create(null);
  18876. for (const optionValue of values) {
  18877. if (typeof optionValue === "string") {
  18878. for (const [key, value] of entriesFromString(optionValue)) {
  18879. try {
  18880. mechanismProperties[key] = getBoolean(key, value);
  18881. } catch {
  18882. mechanismProperties[key] = value;
  18883. }
  18884. }
  18885. } else {
  18886. if (!(0, utils_1.isRecord)(optionValue)) {
  18887. throw new error_1.MongoParseError("AuthMechanismProperties must be an object");
  18888. }
  18889. mechanismProperties = { ...optionValue };
  18890. }
  18891. }
  18892. return mongo_credentials_1.MongoCredentials.merge(options.credentials, {
  18893. mechanismProperties
  18894. });
  18895. }
  18896. },
  18897. authSource: {
  18898. target: "credentials",
  18899. transform({ options, values: [value] }) {
  18900. const source = String(value);
  18901. return mongo_credentials_1.MongoCredentials.merge(options.credentials, { source });
  18902. }
  18903. },
  18904. autoEncryption: {
  18905. type: "record"
  18906. },
  18907. bsonRegExp: {
  18908. type: "boolean"
  18909. },
  18910. serverApi: {
  18911. target: "serverApi",
  18912. transform({ values: [version] }) {
  18913. const serverApiToValidate = typeof version === "string" ? { version } : version;
  18914. const versionToValidate = serverApiToValidate && serverApiToValidate.version;
  18915. if (!versionToValidate) {
  18916. throw new error_1.MongoParseError(`Invalid \`serverApi\` property; must specify a version from the following enum: ["${Object.values(mongo_client_1.ServerApiVersion).join('", "')}"]`);
  18917. }
  18918. if (!Object.values(mongo_client_1.ServerApiVersion).some((v) => v === versionToValidate)) {
  18919. throw new error_1.MongoParseError(`Invalid server API version=${versionToValidate}; must be in the following enum: ["${Object.values(mongo_client_1.ServerApiVersion).join('", "')}"]`);
  18920. }
  18921. return serverApiToValidate;
  18922. }
  18923. },
  18924. checkKeys: {
  18925. type: "boolean"
  18926. },
  18927. compressors: {
  18928. default: "none",
  18929. target: "compressors",
  18930. transform({ values }) {
  18931. const compressionList = /* @__PURE__ */ new Set();
  18932. for (const compVal of values) {
  18933. const compValArray = typeof compVal === "string" ? compVal.split(",") : compVal;
  18934. if (!Array.isArray(compValArray)) {
  18935. throw new error_1.MongoInvalidArgumentError("compressors must be an array or a comma-delimited list of strings");
  18936. }
  18937. for (const c of compValArray) {
  18938. if (Object.keys(compression_1.Compressor).includes(String(c))) {
  18939. compressionList.add(String(c));
  18940. } else {
  18941. throw new error_1.MongoInvalidArgumentError(`${c} is not a valid compression mechanism. Must be one of: ${Object.keys(compression_1.Compressor)}.`);
  18942. }
  18943. }
  18944. }
  18945. return [...compressionList];
  18946. }
  18947. },
  18948. connectTimeoutMS: {
  18949. default: 3e4,
  18950. type: "uint"
  18951. },
  18952. dbName: {
  18953. type: "string"
  18954. },
  18955. directConnection: {
  18956. default: false,
  18957. type: "boolean"
  18958. },
  18959. driverInfo: {
  18960. default: {},
  18961. type: "record"
  18962. },
  18963. enableUtf8Validation: { type: "boolean", default: true },
  18964. family: {
  18965. transform({ name, values: [value] }) {
  18966. const transformValue = getIntFromOptions(name, value);
  18967. if (transformValue === 4 || transformValue === 6) {
  18968. return transformValue;
  18969. }
  18970. throw new error_1.MongoParseError(`Option 'family' must be 4 or 6 got ${transformValue}.`);
  18971. }
  18972. },
  18973. fieldsAsRaw: {
  18974. type: "record"
  18975. },
  18976. forceServerObjectId: {
  18977. default: false,
  18978. type: "boolean"
  18979. },
  18980. fsync: {
  18981. deprecated: "Please use journal instead",
  18982. target: "writeConcern",
  18983. transform({ name, options, values: [value] }) {
  18984. const wc = write_concern_1.WriteConcern.fromOptions({
  18985. writeConcern: {
  18986. ...options.writeConcern,
  18987. fsync: getBoolean(name, value)
  18988. }
  18989. });
  18990. if (!wc)
  18991. throw new error_1.MongoParseError(`Unable to make a writeConcern from fsync=${value}`);
  18992. return wc;
  18993. }
  18994. },
  18995. heartbeatFrequencyMS: {
  18996. default: 1e4,
  18997. type: "uint"
  18998. },
  18999. ignoreUndefined: {
  19000. type: "boolean"
  19001. },
  19002. j: {
  19003. deprecated: "Please use journal instead",
  19004. target: "writeConcern",
  19005. transform({ name, options, values: [value] }) {
  19006. const wc = write_concern_1.WriteConcern.fromOptions({
  19007. writeConcern: {
  19008. ...options.writeConcern,
  19009. journal: getBoolean(name, value)
  19010. }
  19011. });
  19012. if (!wc)
  19013. throw new error_1.MongoParseError(`Unable to make a writeConcern from journal=${value}`);
  19014. return wc;
  19015. }
  19016. },
  19017. journal: {
  19018. target: "writeConcern",
  19019. transform({ name, options, values: [value] }) {
  19020. const wc = write_concern_1.WriteConcern.fromOptions({
  19021. writeConcern: {
  19022. ...options.writeConcern,
  19023. journal: getBoolean(name, value)
  19024. }
  19025. });
  19026. if (!wc)
  19027. throw new error_1.MongoParseError(`Unable to make a writeConcern from journal=${value}`);
  19028. return wc;
  19029. }
  19030. },
  19031. keepAlive: {
  19032. default: true,
  19033. type: "boolean",
  19034. deprecated: "Will not be able to turn off in the future."
  19035. },
  19036. keepAliveInitialDelay: {
  19037. default: 12e4,
  19038. type: "uint",
  19039. deprecated: "Will not be configurable in the future."
  19040. },
  19041. loadBalanced: {
  19042. default: false,
  19043. type: "boolean"
  19044. },
  19045. localThresholdMS: {
  19046. default: 15,
  19047. type: "uint"
  19048. },
  19049. maxConnecting: {
  19050. default: 2,
  19051. transform({ name, values: [value] }) {
  19052. const maxConnecting = getUIntFromOptions(name, value);
  19053. if (maxConnecting === 0) {
  19054. throw new error_1.MongoInvalidArgumentError("maxConnecting must be > 0 if specified");
  19055. }
  19056. return maxConnecting;
  19057. }
  19058. },
  19059. maxIdleTimeMS: {
  19060. default: 0,
  19061. type: "uint"
  19062. },
  19063. maxPoolSize: {
  19064. default: 100,
  19065. type: "uint"
  19066. },
  19067. maxStalenessSeconds: {
  19068. target: "readPreference",
  19069. transform({ name, options, values: [value] }) {
  19070. const maxStalenessSeconds = getUIntFromOptions(name, value);
  19071. if (options.readPreference) {
  19072. return read_preference_1.ReadPreference.fromOptions({
  19073. readPreference: { ...options.readPreference, maxStalenessSeconds }
  19074. });
  19075. } else {
  19076. return new read_preference_1.ReadPreference("secondary", void 0, { maxStalenessSeconds });
  19077. }
  19078. }
  19079. },
  19080. minInternalBufferSize: {
  19081. type: "uint"
  19082. },
  19083. minPoolSize: {
  19084. default: 0,
  19085. type: "uint"
  19086. },
  19087. minHeartbeatFrequencyMS: {
  19088. default: 500,
  19089. type: "uint"
  19090. },
  19091. monitorCommands: {
  19092. default: false,
  19093. type: "boolean"
  19094. },
  19095. name: {
  19096. target: "driverInfo",
  19097. transform({ values: [value], options }) {
  19098. return { ...options.driverInfo, name: String(value) };
  19099. }
  19100. },
  19101. noDelay: {
  19102. default: true,
  19103. type: "boolean"
  19104. },
  19105. pkFactory: {
  19106. default: utils_1.DEFAULT_PK_FACTORY,
  19107. transform({ values: [value] }) {
  19108. if ((0, utils_1.isRecord)(value, ["createPk"]) && typeof value.createPk === "function") {
  19109. return value;
  19110. }
  19111. throw new error_1.MongoParseError(`Option pkFactory must be an object with a createPk function, got ${value}`);
  19112. }
  19113. },
  19114. promoteBuffers: {
  19115. type: "boolean"
  19116. },
  19117. promoteLongs: {
  19118. type: "boolean"
  19119. },
  19120. promoteValues: {
  19121. type: "boolean"
  19122. },
  19123. useBigInt64: {
  19124. type: "boolean"
  19125. },
  19126. proxyHost: {
  19127. type: "string"
  19128. },
  19129. proxyPassword: {
  19130. type: "string"
  19131. },
  19132. proxyPort: {
  19133. type: "uint"
  19134. },
  19135. proxyUsername: {
  19136. type: "string"
  19137. },
  19138. raw: {
  19139. default: false,
  19140. type: "boolean"
  19141. },
  19142. readConcern: {
  19143. transform({ values: [value], options }) {
  19144. if (value instanceof read_concern_1.ReadConcern || (0, utils_1.isRecord)(value, ["level"])) {
  19145. return read_concern_1.ReadConcern.fromOptions({ ...options.readConcern, ...value });
  19146. }
  19147. throw new error_1.MongoParseError(`ReadConcern must be an object, got ${JSON.stringify(value)}`);
  19148. }
  19149. },
  19150. readConcernLevel: {
  19151. target: "readConcern",
  19152. transform({ values: [level], options }) {
  19153. return read_concern_1.ReadConcern.fromOptions({
  19154. ...options.readConcern,
  19155. level
  19156. });
  19157. }
  19158. },
  19159. readPreference: {
  19160. default: read_preference_1.ReadPreference.primary,
  19161. transform({ values: [value], options }) {
  19162. var _a, _b, _c;
  19163. if (value instanceof read_preference_1.ReadPreference) {
  19164. return read_preference_1.ReadPreference.fromOptions({
  19165. readPreference: { ...options.readPreference, ...value },
  19166. ...value
  19167. });
  19168. }
  19169. if ((0, utils_1.isRecord)(value, ["mode"])) {
  19170. const rp = read_preference_1.ReadPreference.fromOptions({
  19171. readPreference: { ...options.readPreference, ...value },
  19172. ...value
  19173. });
  19174. if (rp)
  19175. return rp;
  19176. else
  19177. throw new error_1.MongoParseError(`Cannot make read preference from ${JSON.stringify(value)}`);
  19178. }
  19179. if (typeof value === "string") {
  19180. const rpOpts = {
  19181. hedge: (_a = options.readPreference) == null ? void 0 : _a.hedge,
  19182. maxStalenessSeconds: (_b = options.readPreference) == null ? void 0 : _b.maxStalenessSeconds
  19183. };
  19184. return new read_preference_1.ReadPreference(value, (_c = options.readPreference) == null ? void 0 : _c.tags, rpOpts);
  19185. }
  19186. throw new error_1.MongoParseError(`Unknown ReadPreference value: ${value}`);
  19187. }
  19188. },
  19189. readPreferenceTags: {
  19190. target: "readPreference",
  19191. transform({ values, options }) {
  19192. const tags = Array.isArray(values[0]) ? values[0] : values;
  19193. const readPreferenceTags = [];
  19194. for (const tag of tags) {
  19195. const readPreferenceTag = /* @__PURE__ */ Object.create(null);
  19196. if (typeof tag === "string") {
  19197. for (const [k, v] of entriesFromString(tag)) {
  19198. readPreferenceTag[k] = v;
  19199. }
  19200. }
  19201. if ((0, utils_1.isRecord)(tag)) {
  19202. for (const [k, v] of Object.entries(tag)) {
  19203. readPreferenceTag[k] = v;
  19204. }
  19205. }
  19206. readPreferenceTags.push(readPreferenceTag);
  19207. }
  19208. return read_preference_1.ReadPreference.fromOptions({
  19209. readPreference: options.readPreference,
  19210. readPreferenceTags
  19211. });
  19212. }
  19213. },
  19214. replicaSet: {
  19215. type: "string"
  19216. },
  19217. retryReads: {
  19218. default: true,
  19219. type: "boolean"
  19220. },
  19221. retryWrites: {
  19222. default: true,
  19223. type: "boolean"
  19224. },
  19225. serializeFunctions: {
  19226. type: "boolean"
  19227. },
  19228. serverSelectionTimeoutMS: {
  19229. default: 3e4,
  19230. type: "uint"
  19231. },
  19232. servername: {
  19233. type: "string"
  19234. },
  19235. socketTimeoutMS: {
  19236. default: 0,
  19237. type: "uint"
  19238. },
  19239. srvMaxHosts: {
  19240. type: "uint",
  19241. default: 0
  19242. },
  19243. srvServiceName: {
  19244. type: "string",
  19245. default: "mongodb"
  19246. },
  19247. ssl: {
  19248. target: "tls",
  19249. type: "boolean"
  19250. },
  19251. sslCA: {
  19252. deprecated: "sslCA is deprecated and will be removed in the next major version. Please use tlsCAFile instead.",
  19253. target: "ca",
  19254. transform({ values: [value] }) {
  19255. return fs.readFileSync(String(value), { encoding: "ascii" });
  19256. }
  19257. },
  19258. sslCRL: {
  19259. deprecated: "sslCRL is deprecated and will be removed in the next major version and be replaced by tlsCRLFile in that release.",
  19260. target: "crl",
  19261. transform({ values: [value] }) {
  19262. return fs.readFileSync(String(value), { encoding: "ascii" });
  19263. }
  19264. },
  19265. sslCert: {
  19266. deprecated: "sslCert is deprecated and will be removed in the next major version. Please use tlsCertificateKeyFile instead.",
  19267. target: "cert",
  19268. transform({ values: [value] }) {
  19269. return fs.readFileSync(String(value), { encoding: "ascii" });
  19270. }
  19271. },
  19272. sslKey: {
  19273. deprecated: "sslKey is deprecated and will be removed in the next major version. Please use tlsCertificateKeyFile instead.",
  19274. target: "key",
  19275. transform({ values: [value] }) {
  19276. return fs.readFileSync(String(value), { encoding: "ascii" });
  19277. }
  19278. },
  19279. sslPass: {
  19280. deprecated: "sslPass is deprecated and will be removed in the next major version. Please use tlsCertificateKeyFilePassword instead.",
  19281. target: "passphrase",
  19282. type: "string"
  19283. },
  19284. sslValidate: {
  19285. deprecated: "sslValidate is deprecated and will be removed in the next major version. Please use tlsAllowInvalidCertificates instead.",
  19286. target: "rejectUnauthorized",
  19287. type: "boolean"
  19288. },
  19289. tls: {
  19290. type: "boolean"
  19291. },
  19292. tlsAllowInvalidCertificates: {
  19293. target: "rejectUnauthorized",
  19294. transform({ name, values: [value] }) {
  19295. return !getBoolean(name, value);
  19296. }
  19297. },
  19298. tlsAllowInvalidHostnames: {
  19299. target: "checkServerIdentity",
  19300. transform({ name, values: [value] }) {
  19301. return getBoolean(name, value) ? () => void 0 : void 0;
  19302. }
  19303. },
  19304. tlsCAFile: {
  19305. target: "ca",
  19306. transform({ values: [value] }) {
  19307. return fs.readFileSync(String(value), { encoding: "ascii" });
  19308. }
  19309. },
  19310. tlsCertificateFile: {
  19311. deprecated: "tlsCertificateFile is deprecated and will be removed in the next major version. Please use tlsCertificateKeyFile instead.",
  19312. target: "cert",
  19313. transform({ values: [value] }) {
  19314. return fs.readFileSync(String(value), { encoding: "ascii" });
  19315. }
  19316. },
  19317. tlsCertificateKeyFile: {
  19318. target: "key",
  19319. transform({ values: [value] }) {
  19320. return fs.readFileSync(String(value), { encoding: "ascii" });
  19321. }
  19322. },
  19323. tlsCertificateKeyFilePassword: {
  19324. target: "passphrase",
  19325. type: "any"
  19326. },
  19327. tlsInsecure: {
  19328. transform({ name, options, values: [value] }) {
  19329. const tlsInsecure = getBoolean(name, value);
  19330. if (tlsInsecure) {
  19331. options.checkServerIdentity = () => void 0;
  19332. options.rejectUnauthorized = false;
  19333. } else {
  19334. options.checkServerIdentity = options.tlsAllowInvalidHostnames ? () => void 0 : void 0;
  19335. options.rejectUnauthorized = options.tlsAllowInvalidCertificates ? false : true;
  19336. }
  19337. return tlsInsecure;
  19338. }
  19339. },
  19340. w: {
  19341. target: "writeConcern",
  19342. transform({ values: [value], options }) {
  19343. return write_concern_1.WriteConcern.fromOptions({ writeConcern: { ...options.writeConcern, w: value } });
  19344. }
  19345. },
  19346. waitQueueTimeoutMS: {
  19347. default: 0,
  19348. type: "uint"
  19349. },
  19350. writeConcern: {
  19351. target: "writeConcern",
  19352. transform({ values: [value], options }) {
  19353. if ((0, utils_1.isRecord)(value) || value instanceof write_concern_1.WriteConcern) {
  19354. return write_concern_1.WriteConcern.fromOptions({
  19355. writeConcern: {
  19356. ...options.writeConcern,
  19357. ...value
  19358. }
  19359. });
  19360. } else if (value === "majority" || typeof value === "number") {
  19361. return write_concern_1.WriteConcern.fromOptions({
  19362. writeConcern: {
  19363. ...options.writeConcern,
  19364. w: value
  19365. }
  19366. });
  19367. }
  19368. throw new error_1.MongoParseError(`Invalid WriteConcern cannot parse: ${JSON.stringify(value)}`);
  19369. }
  19370. },
  19371. wtimeout: {
  19372. deprecated: "Please use wtimeoutMS instead",
  19373. target: "writeConcern",
  19374. transform({ values: [value], options }) {
  19375. const wc = write_concern_1.WriteConcern.fromOptions({
  19376. writeConcern: {
  19377. ...options.writeConcern,
  19378. wtimeout: getUIntFromOptions("wtimeout", value)
  19379. }
  19380. });
  19381. if (wc)
  19382. return wc;
  19383. throw new error_1.MongoParseError(`Cannot make WriteConcern from wtimeout`);
  19384. }
  19385. },
  19386. wtimeoutMS: {
  19387. target: "writeConcern",
  19388. transform({ values: [value], options }) {
  19389. const wc = write_concern_1.WriteConcern.fromOptions({
  19390. writeConcern: {
  19391. ...options.writeConcern,
  19392. wtimeoutMS: getUIntFromOptions("wtimeoutMS", value)
  19393. }
  19394. });
  19395. if (wc)
  19396. return wc;
  19397. throw new error_1.MongoParseError(`Cannot make WriteConcern from wtimeout`);
  19398. }
  19399. },
  19400. zlibCompressionLevel: {
  19401. default: 0,
  19402. type: "int"
  19403. },
  19404. // Custom types for modifying core behavior
  19405. connectionType: { type: "any" },
  19406. srvPoller: { type: "any" },
  19407. // Accepted NodeJS Options
  19408. minDHSize: { type: "any" },
  19409. pskCallback: { type: "any" },
  19410. secureContext: { type: "any" },
  19411. enableTrace: { type: "any" },
  19412. requestCert: { type: "any" },
  19413. rejectUnauthorized: { type: "any" },
  19414. checkServerIdentity: { type: "any" },
  19415. ALPNProtocols: { type: "any" },
  19416. SNICallback: { type: "any" },
  19417. session: { type: "any" },
  19418. requestOCSP: { type: "any" },
  19419. localAddress: { type: "any" },
  19420. localPort: { type: "any" },
  19421. hints: { type: "any" },
  19422. lookup: { type: "any" },
  19423. ca: { type: "any" },
  19424. cert: { type: "any" },
  19425. ciphers: { type: "any" },
  19426. crl: { type: "any" },
  19427. ecdhCurve: { type: "any" },
  19428. key: { type: "any" },
  19429. passphrase: { type: "any" },
  19430. pfx: { type: "any" },
  19431. secureProtocol: { type: "any" },
  19432. index: { type: "any" },
  19433. // Legacy Options, these are unused but left here to avoid errors with CSFLE lib
  19434. useNewUrlParser: { type: "boolean" },
  19435. useUnifiedTopology: { type: "boolean" },
  19436. // MongoLogger
  19437. // TODO(NODE-4849): Tighten the type of mongodbLogPath
  19438. mongodbLogPath: { type: "any" }
  19439. };
  19440. exports2.DEFAULT_OPTIONS = new CaseInsensitiveMap(Object.entries(exports2.OPTIONS).filter(([, descriptor]) => descriptor.default != null).map(([k, d]) => [k, d.default]));
  19441. exports2.FEATURE_FLAGS = /* @__PURE__ */ new Set([
  19442. Symbol.for("@@mdb.skipPingOnConnect"),
  19443. Symbol.for("@@mdb.enableMongoLogger"),
  19444. Symbol.for("@@mdb.internalLoggerConfig")
  19445. ]);
  19446. }
  19447. });
  19448. // node_modules/mongodb/lib/sdam/events.js
  19449. var require_events = __commonJS({
  19450. "node_modules/mongodb/lib/sdam/events.js"(exports2) {
  19451. "use strict";
  19452. Object.defineProperty(exports2, "__esModule", { value: true });
  19453. exports2.ServerHeartbeatFailedEvent = exports2.ServerHeartbeatSucceededEvent = exports2.ServerHeartbeatStartedEvent = exports2.TopologyClosedEvent = exports2.TopologyOpeningEvent = exports2.TopologyDescriptionChangedEvent = exports2.ServerClosedEvent = exports2.ServerOpeningEvent = exports2.ServerDescriptionChangedEvent = void 0;
  19454. var ServerDescriptionChangedEvent = class {
  19455. /** @internal */
  19456. constructor(topologyId, address, previousDescription, newDescription) {
  19457. this.topologyId = topologyId;
  19458. this.address = address;
  19459. this.previousDescription = previousDescription;
  19460. this.newDescription = newDescription;
  19461. }
  19462. };
  19463. exports2.ServerDescriptionChangedEvent = ServerDescriptionChangedEvent;
  19464. var ServerOpeningEvent = class {
  19465. /** @internal */
  19466. constructor(topologyId, address) {
  19467. this.topologyId = topologyId;
  19468. this.address = address;
  19469. }
  19470. };
  19471. exports2.ServerOpeningEvent = ServerOpeningEvent;
  19472. var ServerClosedEvent = class {
  19473. /** @internal */
  19474. constructor(topologyId, address) {
  19475. this.topologyId = topologyId;
  19476. this.address = address;
  19477. }
  19478. };
  19479. exports2.ServerClosedEvent = ServerClosedEvent;
  19480. var TopologyDescriptionChangedEvent = class {
  19481. /** @internal */
  19482. constructor(topologyId, previousDescription, newDescription) {
  19483. this.topologyId = topologyId;
  19484. this.previousDescription = previousDescription;
  19485. this.newDescription = newDescription;
  19486. }
  19487. };
  19488. exports2.TopologyDescriptionChangedEvent = TopologyDescriptionChangedEvent;
  19489. var TopologyOpeningEvent = class {
  19490. /** @internal */
  19491. constructor(topologyId) {
  19492. this.topologyId = topologyId;
  19493. }
  19494. };
  19495. exports2.TopologyOpeningEvent = TopologyOpeningEvent;
  19496. var TopologyClosedEvent = class {
  19497. /** @internal */
  19498. constructor(topologyId) {
  19499. this.topologyId = topologyId;
  19500. }
  19501. };
  19502. exports2.TopologyClosedEvent = TopologyClosedEvent;
  19503. var ServerHeartbeatStartedEvent = class {
  19504. /** @internal */
  19505. constructor(connectionId) {
  19506. this.connectionId = connectionId;
  19507. }
  19508. };
  19509. exports2.ServerHeartbeatStartedEvent = ServerHeartbeatStartedEvent;
  19510. var ServerHeartbeatSucceededEvent = class {
  19511. /** @internal */
  19512. constructor(connectionId, duration, reply) {
  19513. this.connectionId = connectionId;
  19514. this.duration = duration;
  19515. this.reply = reply ?? {};
  19516. }
  19517. };
  19518. exports2.ServerHeartbeatSucceededEvent = ServerHeartbeatSucceededEvent;
  19519. var ServerHeartbeatFailedEvent = class {
  19520. /** @internal */
  19521. constructor(connectionId, duration, failure) {
  19522. this.connectionId = connectionId;
  19523. this.duration = duration;
  19524. this.failure = failure;
  19525. }
  19526. };
  19527. exports2.ServerHeartbeatFailedEvent = ServerHeartbeatFailedEvent;
  19528. }
  19529. });
  19530. // node_modules/mongodb/lib/cmap/commands.js
  19531. var require_commands = __commonJS({
  19532. "node_modules/mongodb/lib/cmap/commands.js"(exports2) {
  19533. "use strict";
  19534. Object.defineProperty(exports2, "__esModule", { value: true });
  19535. exports2.BinMsg = exports2.Msg = exports2.Response = exports2.Query = void 0;
  19536. var BSON = require_bson2();
  19537. var error_1 = require_error();
  19538. var read_preference_1 = require_read_preference();
  19539. var utils_1 = require_utils();
  19540. var constants_1 = require_constants();
  19541. var _requestId = 0;
  19542. var OPTS_TAILABLE_CURSOR = 2;
  19543. var OPTS_SECONDARY = 4;
  19544. var OPTS_OPLOG_REPLAY = 8;
  19545. var OPTS_NO_CURSOR_TIMEOUT = 16;
  19546. var OPTS_AWAIT_DATA = 32;
  19547. var OPTS_EXHAUST = 64;
  19548. var OPTS_PARTIAL = 128;
  19549. var CURSOR_NOT_FOUND = 1;
  19550. var QUERY_FAILURE = 2;
  19551. var SHARD_CONFIG_STALE = 4;
  19552. var AWAIT_CAPABLE = 8;
  19553. var Query = class _Query {
  19554. constructor(ns, query, options) {
  19555. if (ns == null)
  19556. throw new error_1.MongoRuntimeError("Namespace must be specified for query");
  19557. if (query == null)
  19558. throw new error_1.MongoRuntimeError("A query document must be specified for query");
  19559. if (ns.indexOf("\0") !== -1) {
  19560. throw new error_1.MongoRuntimeError("Namespace cannot contain a null character");
  19561. }
  19562. this.ns = ns;
  19563. this.query = query;
  19564. this.numberToSkip = options.numberToSkip || 0;
  19565. this.numberToReturn = options.numberToReturn || 0;
  19566. this.returnFieldSelector = options.returnFieldSelector || void 0;
  19567. this.requestId = _Query.getRequestId();
  19568. this.pre32Limit = options.pre32Limit;
  19569. this.serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
  19570. this.ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : false;
  19571. this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16;
  19572. this.checkKeys = typeof options.checkKeys === "boolean" ? options.checkKeys : false;
  19573. this.batchSize = this.numberToReturn;
  19574. this.tailable = false;
  19575. this.secondaryOk = typeof options.secondaryOk === "boolean" ? options.secondaryOk : false;
  19576. this.oplogReplay = false;
  19577. this.noCursorTimeout = false;
  19578. this.awaitData = false;
  19579. this.exhaust = false;
  19580. this.partial = false;
  19581. }
  19582. /** Assign next request Id. */
  19583. incRequestId() {
  19584. this.requestId = _requestId++;
  19585. }
  19586. /** Peek next request Id. */
  19587. nextRequestId() {
  19588. return _requestId + 1;
  19589. }
  19590. /** Increment then return next request Id. */
  19591. static getRequestId() {
  19592. return ++_requestId;
  19593. }
  19594. // Uses a single allocated buffer for the process, avoiding multiple memory allocations
  19595. toBin() {
  19596. const buffers = [];
  19597. let projection = null;
  19598. let flags = 0;
  19599. if (this.tailable) {
  19600. flags |= OPTS_TAILABLE_CURSOR;
  19601. }
  19602. if (this.secondaryOk) {
  19603. flags |= OPTS_SECONDARY;
  19604. }
  19605. if (this.oplogReplay) {
  19606. flags |= OPTS_OPLOG_REPLAY;
  19607. }
  19608. if (this.noCursorTimeout) {
  19609. flags |= OPTS_NO_CURSOR_TIMEOUT;
  19610. }
  19611. if (this.awaitData) {
  19612. flags |= OPTS_AWAIT_DATA;
  19613. }
  19614. if (this.exhaust) {
  19615. flags |= OPTS_EXHAUST;
  19616. }
  19617. if (this.partial) {
  19618. flags |= OPTS_PARTIAL;
  19619. }
  19620. if (this.batchSize !== this.numberToReturn)
  19621. this.numberToReturn = this.batchSize;
  19622. const header = Buffer.alloc(
  19623. 4 * 4 + // Header
  19624. 4 + // Flags
  19625. Buffer.byteLength(this.ns) + 1 + // namespace
  19626. 4 + // numberToSkip
  19627. 4
  19628. // numberToReturn
  19629. );
  19630. buffers.push(header);
  19631. const query = BSON.serialize(this.query, {
  19632. checkKeys: this.checkKeys,
  19633. serializeFunctions: this.serializeFunctions,
  19634. ignoreUndefined: this.ignoreUndefined
  19635. });
  19636. buffers.push(query);
  19637. if (this.returnFieldSelector && Object.keys(this.returnFieldSelector).length > 0) {
  19638. projection = BSON.serialize(this.returnFieldSelector, {
  19639. checkKeys: this.checkKeys,
  19640. serializeFunctions: this.serializeFunctions,
  19641. ignoreUndefined: this.ignoreUndefined
  19642. });
  19643. buffers.push(projection);
  19644. }
  19645. const totalLength = header.length + query.length + (projection ? projection.length : 0);
  19646. let index = 4;
  19647. header[3] = totalLength >> 24 & 255;
  19648. header[2] = totalLength >> 16 & 255;
  19649. header[1] = totalLength >> 8 & 255;
  19650. header[0] = totalLength & 255;
  19651. header[index + 3] = this.requestId >> 24 & 255;
  19652. header[index + 2] = this.requestId >> 16 & 255;
  19653. header[index + 1] = this.requestId >> 8 & 255;
  19654. header[index] = this.requestId & 255;
  19655. index = index + 4;
  19656. header[index + 3] = 0 >> 24 & 255;
  19657. header[index + 2] = 0 >> 16 & 255;
  19658. header[index + 1] = 0 >> 8 & 255;
  19659. header[index] = 0 & 255;
  19660. index = index + 4;
  19661. header[index + 3] = constants_1.OP_QUERY >> 24 & 255;
  19662. header[index + 2] = constants_1.OP_QUERY >> 16 & 255;
  19663. header[index + 1] = constants_1.OP_QUERY >> 8 & 255;
  19664. header[index] = constants_1.OP_QUERY & 255;
  19665. index = index + 4;
  19666. header[index + 3] = flags >> 24 & 255;
  19667. header[index + 2] = flags >> 16 & 255;
  19668. header[index + 1] = flags >> 8 & 255;
  19669. header[index] = flags & 255;
  19670. index = index + 4;
  19671. index = index + header.write(this.ns, index, "utf8") + 1;
  19672. header[index - 1] = 0;
  19673. header[index + 3] = this.numberToSkip >> 24 & 255;
  19674. header[index + 2] = this.numberToSkip >> 16 & 255;
  19675. header[index + 1] = this.numberToSkip >> 8 & 255;
  19676. header[index] = this.numberToSkip & 255;
  19677. index = index + 4;
  19678. header[index + 3] = this.numberToReturn >> 24 & 255;
  19679. header[index + 2] = this.numberToReturn >> 16 & 255;
  19680. header[index + 1] = this.numberToReturn >> 8 & 255;
  19681. header[index] = this.numberToReturn & 255;
  19682. index = index + 4;
  19683. return buffers;
  19684. }
  19685. };
  19686. exports2.Query = Query;
  19687. var Response = class {
  19688. constructor(message, msgHeader, msgBody, opts) {
  19689. this.documents = new Array(0);
  19690. this.parsed = false;
  19691. this.raw = message;
  19692. this.data = msgBody;
  19693. this.opts = opts ?? {
  19694. useBigInt64: false,
  19695. promoteLongs: true,
  19696. promoteValues: true,
  19697. promoteBuffers: false,
  19698. bsonRegExp: false
  19699. };
  19700. this.length = msgHeader.length;
  19701. this.requestId = msgHeader.requestId;
  19702. this.responseTo = msgHeader.responseTo;
  19703. this.opCode = msgHeader.opCode;
  19704. this.fromCompressed = msgHeader.fromCompressed;
  19705. this.useBigInt64 = typeof this.opts.useBigInt64 === "boolean" ? this.opts.useBigInt64 : false;
  19706. this.promoteLongs = typeof this.opts.promoteLongs === "boolean" ? this.opts.promoteLongs : true;
  19707. this.promoteValues = typeof this.opts.promoteValues === "boolean" ? this.opts.promoteValues : true;
  19708. this.promoteBuffers = typeof this.opts.promoteBuffers === "boolean" ? this.opts.promoteBuffers : false;
  19709. this.bsonRegExp = typeof this.opts.bsonRegExp === "boolean" ? this.opts.bsonRegExp : false;
  19710. }
  19711. isParsed() {
  19712. return this.parsed;
  19713. }
  19714. parse(options) {
  19715. if (this.parsed)
  19716. return;
  19717. options = options ?? {};
  19718. const raw = options.raw || false;
  19719. const documentsReturnedIn = options.documentsReturnedIn || null;
  19720. const useBigInt64 = options.useBigInt64 ?? this.opts.useBigInt64;
  19721. const promoteLongs = options.promoteLongs ?? this.opts.promoteLongs;
  19722. const promoteValues = options.promoteValues ?? this.opts.promoteValues;
  19723. const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
  19724. const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
  19725. let bsonSize;
  19726. const _options = {
  19727. useBigInt64,
  19728. promoteLongs,
  19729. promoteValues,
  19730. promoteBuffers,
  19731. bsonRegExp
  19732. };
  19733. this.index = 20;
  19734. this.responseFlags = this.data.readInt32LE(0);
  19735. this.cursorId = new BSON.Long(this.data.readInt32LE(4), this.data.readInt32LE(8));
  19736. this.startingFrom = this.data.readInt32LE(12);
  19737. this.numberReturned = this.data.readInt32LE(16);
  19738. this.documents = new Array(this.numberReturned);
  19739. this.cursorNotFound = (this.responseFlags & CURSOR_NOT_FOUND) !== 0;
  19740. this.queryFailure = (this.responseFlags & QUERY_FAILURE) !== 0;
  19741. this.shardConfigStale = (this.responseFlags & SHARD_CONFIG_STALE) !== 0;
  19742. this.awaitCapable = (this.responseFlags & AWAIT_CAPABLE) !== 0;
  19743. for (let i = 0; i < this.numberReturned; i++) {
  19744. bsonSize = this.data[this.index] | this.data[this.index + 1] << 8 | this.data[this.index + 2] << 16 | this.data[this.index + 3] << 24;
  19745. if (raw) {
  19746. this.documents[i] = this.data.slice(this.index, this.index + bsonSize);
  19747. } else {
  19748. this.documents[i] = BSON.deserialize(this.data.slice(this.index, this.index + bsonSize), _options);
  19749. }
  19750. this.index = this.index + bsonSize;
  19751. }
  19752. if (this.documents.length === 1 && documentsReturnedIn != null && raw) {
  19753. const fieldsAsRaw = {};
  19754. fieldsAsRaw[documentsReturnedIn] = true;
  19755. _options.fieldsAsRaw = fieldsAsRaw;
  19756. const doc = BSON.deserialize(this.documents[0], _options);
  19757. this.documents = [doc];
  19758. }
  19759. this.parsed = true;
  19760. }
  19761. };
  19762. exports2.Response = Response;
  19763. var OPTS_CHECKSUM_PRESENT = 1;
  19764. var OPTS_MORE_TO_COME = 2;
  19765. var OPTS_EXHAUST_ALLOWED = 1 << 16;
  19766. var Msg = class _Msg {
  19767. constructor(ns, command, options) {
  19768. if (command == null)
  19769. throw new error_1.MongoInvalidArgumentError("Query document must be specified for query");
  19770. this.ns = ns;
  19771. this.command = command;
  19772. this.command.$db = (0, utils_1.databaseNamespace)(ns);
  19773. if (options.readPreference && options.readPreference.mode !== read_preference_1.ReadPreference.PRIMARY) {
  19774. this.command.$readPreference = options.readPreference.toJSON();
  19775. }
  19776. this.options = options ?? {};
  19777. this.requestId = options.requestId ? options.requestId : _Msg.getRequestId();
  19778. this.serializeFunctions = typeof options.serializeFunctions === "boolean" ? options.serializeFunctions : false;
  19779. this.ignoreUndefined = typeof options.ignoreUndefined === "boolean" ? options.ignoreUndefined : false;
  19780. this.checkKeys = typeof options.checkKeys === "boolean" ? options.checkKeys : false;
  19781. this.maxBsonSize = options.maxBsonSize || 1024 * 1024 * 16;
  19782. this.checksumPresent = false;
  19783. this.moreToCome = options.moreToCome || false;
  19784. this.exhaustAllowed = typeof options.exhaustAllowed === "boolean" ? options.exhaustAllowed : false;
  19785. }
  19786. toBin() {
  19787. const buffers = [];
  19788. let flags = 0;
  19789. if (this.checksumPresent) {
  19790. flags |= OPTS_CHECKSUM_PRESENT;
  19791. }
  19792. if (this.moreToCome) {
  19793. flags |= OPTS_MORE_TO_COME;
  19794. }
  19795. if (this.exhaustAllowed) {
  19796. flags |= OPTS_EXHAUST_ALLOWED;
  19797. }
  19798. const header = Buffer.alloc(
  19799. 4 * 4 + // Header
  19800. 4
  19801. // Flags
  19802. );
  19803. buffers.push(header);
  19804. let totalLength = header.length;
  19805. const command = this.command;
  19806. totalLength += this.makeDocumentSegment(buffers, command);
  19807. header.writeInt32LE(totalLength, 0);
  19808. header.writeInt32LE(this.requestId, 4);
  19809. header.writeInt32LE(0, 8);
  19810. header.writeInt32LE(constants_1.OP_MSG, 12);
  19811. header.writeUInt32LE(flags, 16);
  19812. return buffers;
  19813. }
  19814. makeDocumentSegment(buffers, document) {
  19815. const payloadTypeBuffer = Buffer.alloc(1);
  19816. payloadTypeBuffer[0] = 0;
  19817. const documentBuffer = this.serializeBson(document);
  19818. buffers.push(payloadTypeBuffer);
  19819. buffers.push(documentBuffer);
  19820. return payloadTypeBuffer.length + documentBuffer.length;
  19821. }
  19822. serializeBson(document) {
  19823. return BSON.serialize(document, {
  19824. checkKeys: this.checkKeys,
  19825. serializeFunctions: this.serializeFunctions,
  19826. ignoreUndefined: this.ignoreUndefined
  19827. });
  19828. }
  19829. static getRequestId() {
  19830. _requestId = _requestId + 1 & 2147483647;
  19831. return _requestId;
  19832. }
  19833. };
  19834. exports2.Msg = Msg;
  19835. var BinMsg = class {
  19836. constructor(message, msgHeader, msgBody, opts) {
  19837. this.parsed = false;
  19838. this.raw = message;
  19839. this.data = msgBody;
  19840. this.opts = opts ?? {
  19841. useBigInt64: false,
  19842. promoteLongs: true,
  19843. promoteValues: true,
  19844. promoteBuffers: false,
  19845. bsonRegExp: false
  19846. };
  19847. this.length = msgHeader.length;
  19848. this.requestId = msgHeader.requestId;
  19849. this.responseTo = msgHeader.responseTo;
  19850. this.opCode = msgHeader.opCode;
  19851. this.fromCompressed = msgHeader.fromCompressed;
  19852. this.responseFlags = msgBody.readInt32LE(0);
  19853. this.checksumPresent = (this.responseFlags & OPTS_CHECKSUM_PRESENT) !== 0;
  19854. this.moreToCome = (this.responseFlags & OPTS_MORE_TO_COME) !== 0;
  19855. this.exhaustAllowed = (this.responseFlags & OPTS_EXHAUST_ALLOWED) !== 0;
  19856. this.useBigInt64 = typeof this.opts.useBigInt64 === "boolean" ? this.opts.useBigInt64 : false;
  19857. this.promoteLongs = typeof this.opts.promoteLongs === "boolean" ? this.opts.promoteLongs : true;
  19858. this.promoteValues = typeof this.opts.promoteValues === "boolean" ? this.opts.promoteValues : true;
  19859. this.promoteBuffers = typeof this.opts.promoteBuffers === "boolean" ? this.opts.promoteBuffers : false;
  19860. this.bsonRegExp = typeof this.opts.bsonRegExp === "boolean" ? this.opts.bsonRegExp : false;
  19861. this.documents = [];
  19862. }
  19863. isParsed() {
  19864. return this.parsed;
  19865. }
  19866. parse(options) {
  19867. if (this.parsed)
  19868. return;
  19869. options = options ?? {};
  19870. this.index = 4;
  19871. const raw = options.raw || false;
  19872. const documentsReturnedIn = options.documentsReturnedIn || null;
  19873. const useBigInt64 = options.useBigInt64 ?? this.opts.useBigInt64;
  19874. const promoteLongs = options.promoteLongs ?? this.opts.promoteLongs;
  19875. const promoteValues = options.promoteValues ?? this.opts.promoteValues;
  19876. const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
  19877. const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
  19878. const validation = this.parseBsonSerializationOptions(options);
  19879. const bsonOptions = {
  19880. useBigInt64,
  19881. promoteLongs,
  19882. promoteValues,
  19883. promoteBuffers,
  19884. bsonRegExp,
  19885. validation
  19886. // Due to the strictness of the BSON libraries validation option we need this cast
  19887. };
  19888. while (this.index < this.data.length) {
  19889. const payloadType = this.data.readUInt8(this.index++);
  19890. if (payloadType === 0) {
  19891. const bsonSize = this.data.readUInt32LE(this.index);
  19892. const bin = this.data.slice(this.index, this.index + bsonSize);
  19893. this.documents.push(raw ? bin : BSON.deserialize(bin, bsonOptions));
  19894. this.index += bsonSize;
  19895. } else if (payloadType === 1) {
  19896. throw new error_1.MongoRuntimeError("OP_MSG Payload Type 1 detected unsupported protocol");
  19897. }
  19898. }
  19899. if (this.documents.length === 1 && documentsReturnedIn != null && raw) {
  19900. const fieldsAsRaw = {};
  19901. fieldsAsRaw[documentsReturnedIn] = true;
  19902. bsonOptions.fieldsAsRaw = fieldsAsRaw;
  19903. const doc = BSON.deserialize(this.documents[0], bsonOptions);
  19904. this.documents = [doc];
  19905. }
  19906. this.parsed = true;
  19907. }
  19908. parseBsonSerializationOptions({ enableUtf8Validation }) {
  19909. if (enableUtf8Validation === false) {
  19910. return { utf8: false };
  19911. }
  19912. return { utf8: { writeErrors: false } };
  19913. }
  19914. };
  19915. exports2.BinMsg = BinMsg;
  19916. }
  19917. });
  19918. // node_modules/mongodb/lib/cmap/command_monitoring_events.js
  19919. var require_command_monitoring_events = __commonJS({
  19920. "node_modules/mongodb/lib/cmap/command_monitoring_events.js"(exports2) {
  19921. "use strict";
  19922. Object.defineProperty(exports2, "__esModule", { value: true });
  19923. exports2.SENSITIVE_COMMANDS = exports2.CommandFailedEvent = exports2.CommandSucceededEvent = exports2.CommandStartedEvent = void 0;
  19924. var constants_1 = require_constants2();
  19925. var utils_1 = require_utils();
  19926. var commands_1 = require_commands();
  19927. var CommandStartedEvent = class {
  19928. /**
  19929. * Create a started event
  19930. *
  19931. * @internal
  19932. * @param pool - the pool that originated the command
  19933. * @param command - the command
  19934. */
  19935. constructor(connection, command) {
  19936. this.name = constants_1.COMMAND_STARTED;
  19937. const cmd = extractCommand(command);
  19938. const commandName = extractCommandName(cmd);
  19939. const { address, connectionId, serviceId } = extractConnectionDetails(connection);
  19940. if (exports2.SENSITIVE_COMMANDS.has(commandName)) {
  19941. this.commandObj = {};
  19942. this.commandObj[commandName] = true;
  19943. }
  19944. this.address = address;
  19945. this.connectionId = connectionId;
  19946. this.serviceId = serviceId;
  19947. this.requestId = command.requestId;
  19948. this.databaseName = databaseName(command);
  19949. this.commandName = commandName;
  19950. this.command = maybeRedact(commandName, cmd, cmd);
  19951. }
  19952. /* @internal */
  19953. get hasServiceId() {
  19954. return !!this.serviceId;
  19955. }
  19956. };
  19957. exports2.CommandStartedEvent = CommandStartedEvent;
  19958. var CommandSucceededEvent = class {
  19959. /**
  19960. * Create a succeeded event
  19961. *
  19962. * @internal
  19963. * @param pool - the pool that originated the command
  19964. * @param command - the command
  19965. * @param reply - the reply for this command from the server
  19966. * @param started - a high resolution tuple timestamp of when the command was first sent, to calculate duration
  19967. */
  19968. constructor(connection, command, reply, started) {
  19969. this.name = constants_1.COMMAND_SUCCEEDED;
  19970. const cmd = extractCommand(command);
  19971. const commandName = extractCommandName(cmd);
  19972. const { address, connectionId, serviceId } = extractConnectionDetails(connection);
  19973. this.address = address;
  19974. this.connectionId = connectionId;
  19975. this.serviceId = serviceId;
  19976. this.requestId = command.requestId;
  19977. this.commandName = commandName;
  19978. this.duration = (0, utils_1.calculateDurationInMs)(started);
  19979. this.reply = maybeRedact(commandName, cmd, extractReply(command, reply));
  19980. }
  19981. /* @internal */
  19982. get hasServiceId() {
  19983. return !!this.serviceId;
  19984. }
  19985. };
  19986. exports2.CommandSucceededEvent = CommandSucceededEvent;
  19987. var CommandFailedEvent = class {
  19988. /**
  19989. * Create a failure event
  19990. *
  19991. * @internal
  19992. * @param pool - the pool that originated the command
  19993. * @param command - the command
  19994. * @param error - the generated error or a server error response
  19995. * @param started - a high resolution tuple timestamp of when the command was first sent, to calculate duration
  19996. */
  19997. constructor(connection, command, error, started) {
  19998. this.name = constants_1.COMMAND_FAILED;
  19999. const cmd = extractCommand(command);
  20000. const commandName = extractCommandName(cmd);
  20001. const { address, connectionId, serviceId } = extractConnectionDetails(connection);
  20002. this.address = address;
  20003. this.connectionId = connectionId;
  20004. this.serviceId = serviceId;
  20005. this.requestId = command.requestId;
  20006. this.commandName = commandName;
  20007. this.duration = (0, utils_1.calculateDurationInMs)(started);
  20008. this.failure = maybeRedact(commandName, cmd, error);
  20009. }
  20010. /* @internal */
  20011. get hasServiceId() {
  20012. return !!this.serviceId;
  20013. }
  20014. };
  20015. exports2.CommandFailedEvent = CommandFailedEvent;
  20016. exports2.SENSITIVE_COMMANDS = /* @__PURE__ */ new Set([
  20017. "authenticate",
  20018. "saslStart",
  20019. "saslContinue",
  20020. "getnonce",
  20021. "createUser",
  20022. "updateUser",
  20023. "copydbgetnonce",
  20024. "copydbsaslstart",
  20025. "copydb"
  20026. ]);
  20027. var HELLO_COMMANDS = /* @__PURE__ */ new Set(["hello", constants_1.LEGACY_HELLO_COMMAND, constants_1.LEGACY_HELLO_COMMAND_CAMEL_CASE]);
  20028. var extractCommandName = (commandDoc) => Object.keys(commandDoc)[0];
  20029. var namespace = (command) => command.ns;
  20030. var databaseName = (command) => command.ns.split(".")[0];
  20031. var collectionName = (command) => command.ns.split(".")[1];
  20032. var maybeRedact = (commandName, commandDoc, result) => exports2.SENSITIVE_COMMANDS.has(commandName) || HELLO_COMMANDS.has(commandName) && commandDoc.speculativeAuthenticate ? {} : result;
  20033. var LEGACY_FIND_QUERY_MAP = {
  20034. $query: "filter",
  20035. $orderby: "sort",
  20036. $hint: "hint",
  20037. $comment: "comment",
  20038. $maxScan: "maxScan",
  20039. $max: "max",
  20040. $min: "min",
  20041. $returnKey: "returnKey",
  20042. $showDiskLoc: "showRecordId",
  20043. $maxTimeMS: "maxTimeMS",
  20044. $snapshot: "snapshot"
  20045. };
  20046. var LEGACY_FIND_OPTIONS_MAP = {
  20047. numberToSkip: "skip",
  20048. numberToReturn: "batchSize",
  20049. returnFieldSelector: "projection"
  20050. };
  20051. var OP_QUERY_KEYS = [
  20052. "tailable",
  20053. "oplogReplay",
  20054. "noCursorTimeout",
  20055. "awaitData",
  20056. "partial",
  20057. "exhaust"
  20058. ];
  20059. function extractCommand(command) {
  20060. var _a;
  20061. if (command instanceof commands_1.Msg) {
  20062. return (0, utils_1.deepCopy)(command.command);
  20063. }
  20064. if ((_a = command.query) == null ? void 0 : _a.$query) {
  20065. let result;
  20066. if (command.ns === "admin.$cmd") {
  20067. result = Object.assign({}, command.query.$query);
  20068. } else {
  20069. result = { find: collectionName(command) };
  20070. Object.keys(LEGACY_FIND_QUERY_MAP).forEach((key) => {
  20071. if (command.query[key] != null) {
  20072. result[LEGACY_FIND_QUERY_MAP[key]] = (0, utils_1.deepCopy)(command.query[key]);
  20073. }
  20074. });
  20075. }
  20076. Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach((key) => {
  20077. const legacyKey = key;
  20078. if (command[legacyKey] != null) {
  20079. result[LEGACY_FIND_OPTIONS_MAP[legacyKey]] = (0, utils_1.deepCopy)(command[legacyKey]);
  20080. }
  20081. });
  20082. OP_QUERY_KEYS.forEach((key) => {
  20083. if (command[key]) {
  20084. result[key] = command[key];
  20085. }
  20086. });
  20087. if (command.pre32Limit != null) {
  20088. result.limit = command.pre32Limit;
  20089. }
  20090. if (command.query.$explain) {
  20091. return { explain: result };
  20092. }
  20093. return result;
  20094. }
  20095. const clonedQuery = {};
  20096. const clonedCommand = {};
  20097. if (command.query) {
  20098. for (const k in command.query) {
  20099. clonedQuery[k] = (0, utils_1.deepCopy)(command.query[k]);
  20100. }
  20101. clonedCommand.query = clonedQuery;
  20102. }
  20103. for (const k in command) {
  20104. if (k === "query")
  20105. continue;
  20106. clonedCommand[k] = (0, utils_1.deepCopy)(command[k]);
  20107. }
  20108. return command.query ? clonedQuery : clonedCommand;
  20109. }
  20110. function extractReply(command, reply) {
  20111. if (!reply) {
  20112. return reply;
  20113. }
  20114. if (command instanceof commands_1.Msg) {
  20115. return (0, utils_1.deepCopy)(reply.result ? reply.result : reply);
  20116. }
  20117. if (command.query && command.query.$query != null) {
  20118. return {
  20119. ok: 1,
  20120. cursor: {
  20121. id: (0, utils_1.deepCopy)(reply.cursorId),
  20122. ns: namespace(command),
  20123. firstBatch: (0, utils_1.deepCopy)(reply.documents)
  20124. }
  20125. };
  20126. }
  20127. return (0, utils_1.deepCopy)(reply.result ? reply.result : reply);
  20128. }
  20129. function extractConnectionDetails(connection) {
  20130. let connectionId;
  20131. if ("id" in connection) {
  20132. connectionId = connection.id;
  20133. }
  20134. return {
  20135. address: connection.address,
  20136. serviceId: connection.serviceId,
  20137. connectionId
  20138. };
  20139. }
  20140. }
  20141. });
  20142. // node_modules/mongodb/lib/cmap/message_stream.js
  20143. var require_message_stream = __commonJS({
  20144. "node_modules/mongodb/lib/cmap/message_stream.js"(exports2) {
  20145. "use strict";
  20146. Object.defineProperty(exports2, "__esModule", { value: true });
  20147. exports2.MessageStream = void 0;
  20148. var stream_1 = require("stream");
  20149. var error_1 = require_error();
  20150. var utils_1 = require_utils();
  20151. var commands_1 = require_commands();
  20152. var compression_1 = require_compression();
  20153. var constants_1 = require_constants();
  20154. var MESSAGE_HEADER_SIZE = 16;
  20155. var COMPRESSION_DETAILS_SIZE = 9;
  20156. var kDefaultMaxBsonMessageSize = 1024 * 1024 * 16 * 4;
  20157. var kBuffer = Symbol("buffer");
  20158. var MessageStream = class extends stream_1.Duplex {
  20159. constructor(options = {}) {
  20160. super(options);
  20161. this.isMonitoringConnection = false;
  20162. this.maxBsonMessageSize = options.maxBsonMessageSize || kDefaultMaxBsonMessageSize;
  20163. this[kBuffer] = new utils_1.BufferPool();
  20164. }
  20165. get buffer() {
  20166. return this[kBuffer];
  20167. }
  20168. _write(chunk, _, callback) {
  20169. this[kBuffer].append(chunk);
  20170. processIncomingData(this, callback);
  20171. }
  20172. _read() {
  20173. return;
  20174. }
  20175. writeCommand(command, operationDescription) {
  20176. const agreedCompressor = operationDescription.agreedCompressor ?? "none";
  20177. if (agreedCompressor === "none" || !canCompress(command)) {
  20178. const data = command.toBin();
  20179. this.push(Array.isArray(data) ? Buffer.concat(data) : data);
  20180. return;
  20181. }
  20182. const concatenatedOriginalCommandBuffer = Buffer.concat(command.toBin());
  20183. const messageToBeCompressed = concatenatedOriginalCommandBuffer.slice(MESSAGE_HEADER_SIZE);
  20184. const originalCommandOpCode = concatenatedOriginalCommandBuffer.readInt32LE(12);
  20185. const options = {
  20186. agreedCompressor,
  20187. zlibCompressionLevel: operationDescription.zlibCompressionLevel ?? 0
  20188. };
  20189. (0, compression_1.compress)(options, messageToBeCompressed).then((compressedMessage) => {
  20190. const msgHeader = Buffer.alloc(MESSAGE_HEADER_SIZE);
  20191. msgHeader.writeInt32LE(MESSAGE_HEADER_SIZE + COMPRESSION_DETAILS_SIZE + compressedMessage.length, 0);
  20192. msgHeader.writeInt32LE(command.requestId, 4);
  20193. msgHeader.writeInt32LE(0, 8);
  20194. msgHeader.writeInt32LE(constants_1.OP_COMPRESSED, 12);
  20195. const compressionDetails = Buffer.alloc(COMPRESSION_DETAILS_SIZE);
  20196. compressionDetails.writeInt32LE(originalCommandOpCode, 0);
  20197. compressionDetails.writeInt32LE(messageToBeCompressed.length, 4);
  20198. compressionDetails.writeUInt8(compression_1.Compressor[agreedCompressor], 8);
  20199. this.push(Buffer.concat([msgHeader, compressionDetails, compressedMessage]));
  20200. }, (error) => {
  20201. operationDescription.cb(error);
  20202. });
  20203. }
  20204. };
  20205. exports2.MessageStream = MessageStream;
  20206. function canCompress(command) {
  20207. const commandDoc = command instanceof commands_1.Msg ? command.command : command.query;
  20208. const commandName = Object.keys(commandDoc)[0];
  20209. return !compression_1.uncompressibleCommands.has(commandName);
  20210. }
  20211. function processIncomingData(stream, callback) {
  20212. const buffer = stream[kBuffer];
  20213. const sizeOfMessage = buffer.getInt32();
  20214. if (sizeOfMessage == null) {
  20215. return callback();
  20216. }
  20217. if (sizeOfMessage < 0) {
  20218. return callback(new error_1.MongoParseError(`Invalid message size: ${sizeOfMessage}`));
  20219. }
  20220. if (sizeOfMessage > stream.maxBsonMessageSize) {
  20221. return callback(new error_1.MongoParseError(`Invalid message size: ${sizeOfMessage}, max allowed: ${stream.maxBsonMessageSize}`));
  20222. }
  20223. if (sizeOfMessage > buffer.length) {
  20224. return callback();
  20225. }
  20226. const message = buffer.read(sizeOfMessage);
  20227. const messageHeader = {
  20228. length: message.readInt32LE(0),
  20229. requestId: message.readInt32LE(4),
  20230. responseTo: message.readInt32LE(8),
  20231. opCode: message.readInt32LE(12)
  20232. };
  20233. const monitorHasAnotherHello = () => {
  20234. if (stream.isMonitoringConnection) {
  20235. const sizeOfMessage2 = buffer.getInt32();
  20236. if (sizeOfMessage2 != null && sizeOfMessage2 <= buffer.length) {
  20237. return true;
  20238. }
  20239. }
  20240. return false;
  20241. };
  20242. let ResponseType = messageHeader.opCode === constants_1.OP_MSG ? commands_1.BinMsg : commands_1.Response;
  20243. if (messageHeader.opCode !== constants_1.OP_COMPRESSED) {
  20244. const messageBody = message.subarray(MESSAGE_HEADER_SIZE);
  20245. if (monitorHasAnotherHello()) {
  20246. return processIncomingData(stream, callback);
  20247. }
  20248. stream.emit("message", new ResponseType(message, messageHeader, messageBody));
  20249. if (buffer.length >= 4) {
  20250. return processIncomingData(stream, callback);
  20251. }
  20252. return callback();
  20253. }
  20254. messageHeader.fromCompressed = true;
  20255. messageHeader.opCode = message.readInt32LE(MESSAGE_HEADER_SIZE);
  20256. messageHeader.length = message.readInt32LE(MESSAGE_HEADER_SIZE + 4);
  20257. const compressorID = message[MESSAGE_HEADER_SIZE + 8];
  20258. const compressedBuffer = message.slice(MESSAGE_HEADER_SIZE + 9);
  20259. ResponseType = messageHeader.opCode === constants_1.OP_MSG ? commands_1.BinMsg : commands_1.Response;
  20260. (0, compression_1.decompress)(compressorID, compressedBuffer).then((messageBody) => {
  20261. if (messageBody.length !== messageHeader.length) {
  20262. return callback(new error_1.MongoDecompressionError("Message body and message header must be the same length"));
  20263. }
  20264. if (monitorHasAnotherHello()) {
  20265. return processIncomingData(stream, callback);
  20266. }
  20267. stream.emit("message", new ResponseType(message, messageHeader, messageBody));
  20268. if (buffer.length >= 4) {
  20269. return processIncomingData(stream, callback);
  20270. }
  20271. return callback();
  20272. }, (error) => {
  20273. return callback(error);
  20274. });
  20275. }
  20276. }
  20277. });
  20278. // node_modules/mongodb/lib/cmap/stream_description.js
  20279. var require_stream_description = __commonJS({
  20280. "node_modules/mongodb/lib/cmap/stream_description.js"(exports2) {
  20281. "use strict";
  20282. Object.defineProperty(exports2, "__esModule", { value: true });
  20283. exports2.StreamDescription = void 0;
  20284. var common_1 = require_common();
  20285. var server_description_1 = require_server_description();
  20286. var RESPONSE_FIELDS = [
  20287. "minWireVersion",
  20288. "maxWireVersion",
  20289. "maxBsonObjectSize",
  20290. "maxMessageSizeBytes",
  20291. "maxWriteBatchSize",
  20292. "logicalSessionTimeoutMinutes"
  20293. ];
  20294. var StreamDescription = class {
  20295. constructor(address, options) {
  20296. this.address = address;
  20297. this.type = common_1.ServerType.Unknown;
  20298. this.minWireVersion = void 0;
  20299. this.maxWireVersion = void 0;
  20300. this.maxBsonObjectSize = 16777216;
  20301. this.maxMessageSizeBytes = 48e6;
  20302. this.maxWriteBatchSize = 1e5;
  20303. this.logicalSessionTimeoutMinutes = options == null ? void 0 : options.logicalSessionTimeoutMinutes;
  20304. this.loadBalanced = !!(options == null ? void 0 : options.loadBalanced);
  20305. this.compressors = options && options.compressors && Array.isArray(options.compressors) ? options.compressors : [];
  20306. }
  20307. receiveResponse(response) {
  20308. if (response == null) {
  20309. return;
  20310. }
  20311. this.type = (0, server_description_1.parseServerType)(response);
  20312. for (const field of RESPONSE_FIELDS) {
  20313. if (response[field] != null) {
  20314. this[field] = response[field];
  20315. }
  20316. if ("__nodejs_mock_server__" in response) {
  20317. this.__nodejs_mock_server__ = response["__nodejs_mock_server__"];
  20318. }
  20319. }
  20320. if (response.compression) {
  20321. this.compressor = this.compressors.filter((c) => {
  20322. var _a;
  20323. return (_a = response.compression) == null ? void 0 : _a.includes(c);
  20324. })[0];
  20325. }
  20326. }
  20327. };
  20328. exports2.StreamDescription = StreamDescription;
  20329. }
  20330. });
  20331. // node_modules/mongodb/lib/cmap/connection.js
  20332. var require_connection = __commonJS({
  20333. "node_modules/mongodb/lib/cmap/connection.js"(exports2) {
  20334. "use strict";
  20335. Object.defineProperty(exports2, "__esModule", { value: true });
  20336. exports2.hasSessionSupport = exports2.CryptoConnection = exports2.Connection = void 0;
  20337. var timers_1 = require("timers");
  20338. var util_1 = require("util");
  20339. var constants_1 = require_constants2();
  20340. var error_1 = require_error();
  20341. var mongo_types_1 = require_mongo_types();
  20342. var sessions_1 = require_sessions();
  20343. var utils_1 = require_utils();
  20344. var command_monitoring_events_1 = require_command_monitoring_events();
  20345. var commands_1 = require_commands();
  20346. var message_stream_1 = require_message_stream();
  20347. var stream_description_1 = require_stream_description();
  20348. var shared_1 = require_shared();
  20349. var kStream = Symbol("stream");
  20350. var kQueue = Symbol("queue");
  20351. var kMessageStream = Symbol("messageStream");
  20352. var kGeneration = Symbol("generation");
  20353. var kLastUseTime = Symbol("lastUseTime");
  20354. var kClusterTime = Symbol("clusterTime");
  20355. var kDescription = Symbol("description");
  20356. var kHello = Symbol("hello");
  20357. var kAutoEncrypter = Symbol("autoEncrypter");
  20358. var kDelayedTimeoutId = Symbol("delayedTimeoutId");
  20359. var INVALID_QUEUE_SIZE = "Connection internal queue contains more than 1 operation description";
  20360. var Connection = class _Connection extends mongo_types_1.TypedEventEmitter {
  20361. constructor(stream, options) {
  20362. var _a;
  20363. super();
  20364. this.commandAsync = (0, util_1.promisify)((ns, cmd, options2, callback) => this.command(ns, cmd, options2, callback));
  20365. this.id = options.id;
  20366. this.address = streamIdentifier(stream, options);
  20367. this.socketTimeoutMS = options.socketTimeoutMS ?? 0;
  20368. this.monitorCommands = options.monitorCommands;
  20369. this.serverApi = options.serverApi;
  20370. this.closed = false;
  20371. this[kHello] = null;
  20372. this[kClusterTime] = null;
  20373. this[kDescription] = new stream_description_1.StreamDescription(this.address, options);
  20374. this[kGeneration] = options.generation;
  20375. this[kLastUseTime] = (0, utils_1.now)();
  20376. this[kQueue] = /* @__PURE__ */ new Map();
  20377. this[kMessageStream] = new message_stream_1.MessageStream({
  20378. ...options,
  20379. maxBsonMessageSize: (_a = this.hello) == null ? void 0 : _a.maxBsonMessageSize
  20380. });
  20381. this[kStream] = stream;
  20382. this[kDelayedTimeoutId] = null;
  20383. this[kMessageStream].on("message", (message) => this.onMessage(message));
  20384. this[kMessageStream].on("error", (error) => this.onError(error));
  20385. this[kStream].on("close", () => this.onClose());
  20386. this[kStream].on("timeout", () => this.onTimeout());
  20387. this[kStream].on("error", () => {
  20388. });
  20389. this[kStream].pipe(this[kMessageStream]);
  20390. this[kMessageStream].pipe(this[kStream]);
  20391. }
  20392. get description() {
  20393. return this[kDescription];
  20394. }
  20395. get hello() {
  20396. return this[kHello];
  20397. }
  20398. // the `connect` method stores the result of the handshake hello on the connection
  20399. set hello(response) {
  20400. this[kDescription].receiveResponse(response);
  20401. this[kDescription] = Object.freeze(this[kDescription]);
  20402. this[kHello] = response;
  20403. }
  20404. // Set the whether the message stream is for a monitoring connection.
  20405. set isMonitoringConnection(value) {
  20406. this[kMessageStream].isMonitoringConnection = value;
  20407. }
  20408. get isMonitoringConnection() {
  20409. return this[kMessageStream].isMonitoringConnection;
  20410. }
  20411. get serviceId() {
  20412. var _a;
  20413. return (_a = this.hello) == null ? void 0 : _a.serviceId;
  20414. }
  20415. get loadBalanced() {
  20416. return this.description.loadBalanced;
  20417. }
  20418. get generation() {
  20419. return this[kGeneration] || 0;
  20420. }
  20421. set generation(generation) {
  20422. this[kGeneration] = generation;
  20423. }
  20424. get idleTime() {
  20425. return (0, utils_1.calculateDurationInMs)(this[kLastUseTime]);
  20426. }
  20427. get clusterTime() {
  20428. return this[kClusterTime];
  20429. }
  20430. get stream() {
  20431. return this[kStream];
  20432. }
  20433. markAvailable() {
  20434. this[kLastUseTime] = (0, utils_1.now)();
  20435. }
  20436. onError(error) {
  20437. this.cleanup(true, error);
  20438. }
  20439. onClose() {
  20440. const message = `connection ${this.id} to ${this.address} closed`;
  20441. this.cleanup(true, new error_1.MongoNetworkError(message));
  20442. }
  20443. onTimeout() {
  20444. this[kDelayedTimeoutId] = (0, timers_1.setTimeout)(() => {
  20445. const message = `connection ${this.id} to ${this.address} timed out`;
  20446. const beforeHandshake = this.hello == null;
  20447. this.cleanup(true, new error_1.MongoNetworkTimeoutError(message, { beforeHandshake }));
  20448. }, 1).unref();
  20449. }
  20450. onMessage(message) {
  20451. const delayedTimeoutId = this[kDelayedTimeoutId];
  20452. if (delayedTimeoutId != null) {
  20453. (0, timers_1.clearTimeout)(delayedTimeoutId);
  20454. this[kDelayedTimeoutId] = null;
  20455. }
  20456. const socketTimeoutMS = this[kStream].timeout ?? 0;
  20457. this[kStream].setTimeout(0);
  20458. this.emit("message", message);
  20459. let operationDescription = this[kQueue].get(message.responseTo);
  20460. if (!operationDescription && this.isMonitoringConnection) {
  20461. if (this[kQueue].size > 1) {
  20462. this.cleanup(true, new error_1.MongoRuntimeError(INVALID_QUEUE_SIZE));
  20463. } else {
  20464. const entry = this[kQueue].entries().next();
  20465. if (entry.value != null) {
  20466. const [requestId, orphaned] = entry.value;
  20467. operationDescription = orphaned;
  20468. this[kQueue].delete(requestId);
  20469. }
  20470. }
  20471. }
  20472. if (!operationDescription) {
  20473. return;
  20474. }
  20475. const callback = operationDescription.cb;
  20476. this[kQueue].delete(message.responseTo);
  20477. if ("moreToCome" in message && message.moreToCome) {
  20478. this[kQueue].set(message.requestId, operationDescription);
  20479. this[kStream].setTimeout(socketTimeoutMS);
  20480. }
  20481. try {
  20482. message.parse(operationDescription);
  20483. } catch (err) {
  20484. callback(err);
  20485. return;
  20486. }
  20487. if (message.documents[0]) {
  20488. const document = message.documents[0];
  20489. const session = operationDescription.session;
  20490. if (session) {
  20491. (0, sessions_1.updateSessionFromResponse)(session, document);
  20492. }
  20493. if (document.$clusterTime) {
  20494. this[kClusterTime] = document.$clusterTime;
  20495. this.emit(_Connection.CLUSTER_TIME_RECEIVED, document.$clusterTime);
  20496. }
  20497. if (document.writeConcernError) {
  20498. callback(new error_1.MongoWriteConcernError(document.writeConcernError, document), document);
  20499. return;
  20500. }
  20501. if (document.ok === 0 || document.$err || document.errmsg || document.code) {
  20502. callback(new error_1.MongoServerError(document));
  20503. return;
  20504. }
  20505. }
  20506. callback(void 0, message.documents[0]);
  20507. }
  20508. destroy(options, callback) {
  20509. if (this.closed) {
  20510. process.nextTick(() => callback == null ? void 0 : callback());
  20511. return;
  20512. }
  20513. if (typeof callback === "function") {
  20514. this.once("close", () => process.nextTick(() => callback()));
  20515. }
  20516. this.removeAllListeners(_Connection.PINNED);
  20517. this.removeAllListeners(_Connection.UNPINNED);
  20518. const message = `connection ${this.id} to ${this.address} closed`;
  20519. this.cleanup(options.force, new error_1.MongoNetworkError(message));
  20520. }
  20521. /**
  20522. * A method that cleans up the connection. When `force` is true, this method
  20523. * forcibly destroys the socket.
  20524. *
  20525. * If an error is provided, any in-flight operations will be closed with the error.
  20526. *
  20527. * This method does nothing if the connection is already closed.
  20528. */
  20529. cleanup(force, error) {
  20530. if (this.closed) {
  20531. return;
  20532. }
  20533. this.closed = true;
  20534. const completeCleanup = () => {
  20535. for (const op of this[kQueue].values()) {
  20536. op.cb(error);
  20537. }
  20538. this[kQueue].clear();
  20539. this.emit(_Connection.CLOSE);
  20540. };
  20541. this[kStream].removeAllListeners();
  20542. this[kMessageStream].removeAllListeners();
  20543. this[kMessageStream].destroy();
  20544. if (force) {
  20545. this[kStream].destroy();
  20546. completeCleanup();
  20547. return;
  20548. }
  20549. if (!this[kStream].writableEnded) {
  20550. this[kStream].end(() => {
  20551. this[kStream].destroy();
  20552. completeCleanup();
  20553. });
  20554. } else {
  20555. completeCleanup();
  20556. }
  20557. }
  20558. command(ns, command, options, callback) {
  20559. let cmd = { ...command };
  20560. const readPreference = (0, shared_1.getReadPreference)(options);
  20561. const shouldUseOpMsg = supportsOpMsg(this);
  20562. const session = options == null ? void 0 : options.session;
  20563. let clusterTime = this.clusterTime;
  20564. if (this.serverApi) {
  20565. const { version, strict, deprecationErrors } = this.serverApi;
  20566. cmd.apiVersion = version;
  20567. if (strict != null)
  20568. cmd.apiStrict = strict;
  20569. if (deprecationErrors != null)
  20570. cmd.apiDeprecationErrors = deprecationErrors;
  20571. }
  20572. if (hasSessionSupport(this) && session) {
  20573. if (session.clusterTime && clusterTime && session.clusterTime.clusterTime.greaterThan(clusterTime.clusterTime)) {
  20574. clusterTime = session.clusterTime;
  20575. }
  20576. const err = (0, sessions_1.applySession)(session, cmd, options);
  20577. if (err) {
  20578. return callback(err);
  20579. }
  20580. } else if (session == null ? void 0 : session.explicit) {
  20581. return callback(new error_1.MongoCompatibilityError("Current topology does not support sessions"));
  20582. }
  20583. if (clusterTime) {
  20584. cmd.$clusterTime = clusterTime;
  20585. }
  20586. if ((0, shared_1.isSharded)(this) && !shouldUseOpMsg && readPreference && readPreference.mode !== "primary") {
  20587. cmd = {
  20588. $query: cmd,
  20589. $readPreference: readPreference.toJSON()
  20590. };
  20591. }
  20592. const commandOptions = Object.assign({
  20593. numberToSkip: 0,
  20594. numberToReturn: -1,
  20595. checkKeys: false,
  20596. // This value is not overridable
  20597. secondaryOk: readPreference.secondaryOk()
  20598. }, options);
  20599. const cmdNs = `${ns.db}.$cmd`;
  20600. const message = shouldUseOpMsg ? new commands_1.Msg(cmdNs, cmd, commandOptions) : new commands_1.Query(cmdNs, cmd, commandOptions);
  20601. try {
  20602. write(this, message, commandOptions, callback);
  20603. } catch (err) {
  20604. callback(err);
  20605. }
  20606. }
  20607. };
  20608. Connection.COMMAND_STARTED = constants_1.COMMAND_STARTED;
  20609. Connection.COMMAND_SUCCEEDED = constants_1.COMMAND_SUCCEEDED;
  20610. Connection.COMMAND_FAILED = constants_1.COMMAND_FAILED;
  20611. Connection.CLUSTER_TIME_RECEIVED = constants_1.CLUSTER_TIME_RECEIVED;
  20612. Connection.CLOSE = constants_1.CLOSE;
  20613. Connection.MESSAGE = constants_1.MESSAGE;
  20614. Connection.PINNED = constants_1.PINNED;
  20615. Connection.UNPINNED = constants_1.UNPINNED;
  20616. exports2.Connection = Connection;
  20617. var CryptoConnection = class extends Connection {
  20618. constructor(stream, options) {
  20619. super(stream, options);
  20620. this[kAutoEncrypter] = options.autoEncrypter;
  20621. }
  20622. /** @internal @override */
  20623. command(ns, cmd, options, callback) {
  20624. const autoEncrypter = this[kAutoEncrypter];
  20625. if (!autoEncrypter) {
  20626. return callback(new error_1.MongoMissingDependencyError("No AutoEncrypter available for encryption"));
  20627. }
  20628. const serverWireVersion = (0, utils_1.maxWireVersion)(this);
  20629. if (serverWireVersion === 0) {
  20630. return super.command(ns, cmd, options, callback);
  20631. }
  20632. if (serverWireVersion < 8) {
  20633. callback(new error_1.MongoCompatibilityError("Auto-encryption requires a minimum MongoDB version of 4.2"));
  20634. return;
  20635. }
  20636. const sort = cmd.find || cmd.findAndModify ? cmd.sort : null;
  20637. const indexKeys = cmd.createIndexes ? cmd.indexes.map((index) => index.key) : null;
  20638. autoEncrypter.encrypt(ns.toString(), cmd, options, (err, encrypted) => {
  20639. if (err || encrypted == null) {
  20640. callback(err, null);
  20641. return;
  20642. }
  20643. if (sort != null && (cmd.find || cmd.findAndModify)) {
  20644. encrypted.sort = sort;
  20645. }
  20646. if (indexKeys != null && cmd.createIndexes) {
  20647. for (const [offset, index] of indexKeys.entries()) {
  20648. encrypted.indexes[offset].key = index;
  20649. }
  20650. }
  20651. super.command(ns, encrypted, options, (err2, response) => {
  20652. if (err2 || response == null) {
  20653. callback(err2, response);
  20654. return;
  20655. }
  20656. autoEncrypter.decrypt(response, options, callback);
  20657. });
  20658. });
  20659. }
  20660. };
  20661. exports2.CryptoConnection = CryptoConnection;
  20662. function hasSessionSupport(conn) {
  20663. const description = conn.description;
  20664. return description.logicalSessionTimeoutMinutes != null;
  20665. }
  20666. exports2.hasSessionSupport = hasSessionSupport;
  20667. function supportsOpMsg(conn) {
  20668. const description = conn.description;
  20669. if (description == null) {
  20670. return false;
  20671. }
  20672. return (0, utils_1.maxWireVersion)(conn) >= 6 && !description.__nodejs_mock_server__;
  20673. }
  20674. function streamIdentifier(stream, options) {
  20675. if (options.proxyHost) {
  20676. return options.hostAddress.toString();
  20677. }
  20678. const { remoteAddress, remotePort } = stream;
  20679. if (typeof remoteAddress === "string" && typeof remotePort === "number") {
  20680. return utils_1.HostAddress.fromHostPort(remoteAddress, remotePort).toString();
  20681. }
  20682. return (0, utils_1.uuidV4)().toString("hex");
  20683. }
  20684. function write(conn, command, options, callback) {
  20685. options = options ?? {};
  20686. const operationDescription = {
  20687. requestId: command.requestId,
  20688. cb: callback,
  20689. session: options.session,
  20690. noResponse: typeof options.noResponse === "boolean" ? options.noResponse : false,
  20691. documentsReturnedIn: options.documentsReturnedIn,
  20692. // for BSON parsing
  20693. useBigInt64: typeof options.useBigInt64 === "boolean" ? options.useBigInt64 : false,
  20694. promoteLongs: typeof options.promoteLongs === "boolean" ? options.promoteLongs : true,
  20695. promoteValues: typeof options.promoteValues === "boolean" ? options.promoteValues : true,
  20696. promoteBuffers: typeof options.promoteBuffers === "boolean" ? options.promoteBuffers : false,
  20697. bsonRegExp: typeof options.bsonRegExp === "boolean" ? options.bsonRegExp : false,
  20698. enableUtf8Validation: typeof options.enableUtf8Validation === "boolean" ? options.enableUtf8Validation : true,
  20699. raw: typeof options.raw === "boolean" ? options.raw : false,
  20700. started: 0
  20701. };
  20702. if (conn[kDescription] && conn[kDescription].compressor) {
  20703. operationDescription.agreedCompressor = conn[kDescription].compressor;
  20704. if (conn[kDescription].zlibCompressionLevel) {
  20705. operationDescription.zlibCompressionLevel = conn[kDescription].zlibCompressionLevel;
  20706. }
  20707. }
  20708. if (typeof options.socketTimeoutMS === "number") {
  20709. conn[kStream].setTimeout(options.socketTimeoutMS);
  20710. } else if (conn.socketTimeoutMS !== 0) {
  20711. conn[kStream].setTimeout(conn.socketTimeoutMS);
  20712. }
  20713. if (conn.monitorCommands) {
  20714. conn.emit(Connection.COMMAND_STARTED, new command_monitoring_events_1.CommandStartedEvent(conn, command));
  20715. operationDescription.started = (0, utils_1.now)();
  20716. operationDescription.cb = (err, reply) => {
  20717. if (err && (reply == null ? void 0 : reply.ok) !== 1) {
  20718. conn.emit(Connection.COMMAND_FAILED, new command_monitoring_events_1.CommandFailedEvent(conn, command, err, operationDescription.started));
  20719. } else {
  20720. if (reply && (reply.ok === 0 || reply.$err)) {
  20721. conn.emit(Connection.COMMAND_FAILED, new command_monitoring_events_1.CommandFailedEvent(conn, command, reply, operationDescription.started));
  20722. } else {
  20723. conn.emit(Connection.COMMAND_SUCCEEDED, new command_monitoring_events_1.CommandSucceededEvent(conn, command, reply, operationDescription.started));
  20724. }
  20725. }
  20726. if (typeof callback === "function") {
  20727. callback(err, err instanceof error_1.MongoWriteConcernError ? void 0 : reply);
  20728. }
  20729. };
  20730. }
  20731. if (!operationDescription.noResponse) {
  20732. conn[kQueue].set(operationDescription.requestId, operationDescription);
  20733. }
  20734. try {
  20735. conn[kMessageStream].writeCommand(command, operationDescription);
  20736. } catch (e) {
  20737. if (!operationDescription.noResponse) {
  20738. conn[kQueue].delete(operationDescription.requestId);
  20739. operationDescription.cb(e);
  20740. return;
  20741. }
  20742. }
  20743. if (operationDescription.noResponse) {
  20744. operationDescription.cb();
  20745. }
  20746. }
  20747. }
  20748. });
  20749. // node_modules/smart-buffer/build/utils.js
  20750. var require_utils3 = __commonJS({
  20751. "node_modules/smart-buffer/build/utils.js"(exports2) {
  20752. "use strict";
  20753. Object.defineProperty(exports2, "__esModule", { value: true });
  20754. var buffer_1 = require("buffer");
  20755. var ERRORS = {
  20756. INVALID_ENCODING: "Invalid encoding provided. Please specify a valid encoding the internal Node.js Buffer supports.",
  20757. INVALID_SMARTBUFFER_SIZE: "Invalid size provided. Size must be a valid integer greater than zero.",
  20758. INVALID_SMARTBUFFER_BUFFER: "Invalid Buffer provided in SmartBufferOptions.",
  20759. INVALID_SMARTBUFFER_OBJECT: "Invalid SmartBufferOptions object supplied to SmartBuffer constructor or factory methods.",
  20760. INVALID_OFFSET: "An invalid offset value was provided.",
  20761. INVALID_OFFSET_NON_NUMBER: "An invalid offset value was provided. A numeric value is required.",
  20762. INVALID_LENGTH: "An invalid length value was provided.",
  20763. INVALID_LENGTH_NON_NUMBER: "An invalid length value was provived. A numeric value is required.",
  20764. INVALID_TARGET_OFFSET: "Target offset is beyond the bounds of the internal SmartBuffer data.",
  20765. INVALID_TARGET_LENGTH: "Specified length value moves cursor beyong the bounds of the internal SmartBuffer data.",
  20766. INVALID_READ_BEYOND_BOUNDS: "Attempted to read beyond the bounds of the managed data.",
  20767. INVALID_WRITE_BEYOND_BOUNDS: "Attempted to write beyond the bounds of the managed data."
  20768. };
  20769. exports2.ERRORS = ERRORS;
  20770. function checkEncoding(encoding) {
  20771. if (!buffer_1.Buffer.isEncoding(encoding)) {
  20772. throw new Error(ERRORS.INVALID_ENCODING);
  20773. }
  20774. }
  20775. exports2.checkEncoding = checkEncoding;
  20776. function isFiniteInteger(value) {
  20777. return typeof value === "number" && isFinite(value) && isInteger(value);
  20778. }
  20779. exports2.isFiniteInteger = isFiniteInteger;
  20780. function checkOffsetOrLengthValue(value, offset) {
  20781. if (typeof value === "number") {
  20782. if (!isFiniteInteger(value) || value < 0) {
  20783. throw new Error(offset ? ERRORS.INVALID_OFFSET : ERRORS.INVALID_LENGTH);
  20784. }
  20785. } else {
  20786. throw new Error(offset ? ERRORS.INVALID_OFFSET_NON_NUMBER : ERRORS.INVALID_LENGTH_NON_NUMBER);
  20787. }
  20788. }
  20789. function checkLengthValue(length) {
  20790. checkOffsetOrLengthValue(length, false);
  20791. }
  20792. exports2.checkLengthValue = checkLengthValue;
  20793. function checkOffsetValue(offset) {
  20794. checkOffsetOrLengthValue(offset, true);
  20795. }
  20796. exports2.checkOffsetValue = checkOffsetValue;
  20797. function checkTargetOffset(offset, buff) {
  20798. if (offset < 0 || offset > buff.length) {
  20799. throw new Error(ERRORS.INVALID_TARGET_OFFSET);
  20800. }
  20801. }
  20802. exports2.checkTargetOffset = checkTargetOffset;
  20803. function isInteger(value) {
  20804. return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
  20805. }
  20806. function bigIntAndBufferInt64Check(bufferMethod) {
  20807. if (typeof BigInt === "undefined") {
  20808. throw new Error("Platform does not support JS BigInt type.");
  20809. }
  20810. if (typeof buffer_1.Buffer.prototype[bufferMethod] === "undefined") {
  20811. throw new Error(`Platform does not support Buffer.prototype.${bufferMethod}.`);
  20812. }
  20813. }
  20814. exports2.bigIntAndBufferInt64Check = bigIntAndBufferInt64Check;
  20815. }
  20816. });
  20817. // node_modules/smart-buffer/build/smartbuffer.js
  20818. var require_smartbuffer = __commonJS({
  20819. "node_modules/smart-buffer/build/smartbuffer.js"(exports2) {
  20820. "use strict";
  20821. Object.defineProperty(exports2, "__esModule", { value: true });
  20822. var utils_1 = require_utils3();
  20823. var DEFAULT_SMARTBUFFER_SIZE = 4096;
  20824. var DEFAULT_SMARTBUFFER_ENCODING = "utf8";
  20825. var SmartBuffer = class _SmartBuffer {
  20826. /**
  20827. * Creates a new SmartBuffer instance.
  20828. *
  20829. * @param options { SmartBufferOptions } The SmartBufferOptions to apply to this instance.
  20830. */
  20831. constructor(options) {
  20832. this.length = 0;
  20833. this._encoding = DEFAULT_SMARTBUFFER_ENCODING;
  20834. this._writeOffset = 0;
  20835. this._readOffset = 0;
  20836. if (_SmartBuffer.isSmartBufferOptions(options)) {
  20837. if (options.encoding) {
  20838. utils_1.checkEncoding(options.encoding);
  20839. this._encoding = options.encoding;
  20840. }
  20841. if (options.size) {
  20842. if (utils_1.isFiniteInteger(options.size) && options.size > 0) {
  20843. this._buff = Buffer.allocUnsafe(options.size);
  20844. } else {
  20845. throw new Error(utils_1.ERRORS.INVALID_SMARTBUFFER_SIZE);
  20846. }
  20847. } else if (options.buff) {
  20848. if (Buffer.isBuffer(options.buff)) {
  20849. this._buff = options.buff;
  20850. this.length = options.buff.length;
  20851. } else {
  20852. throw new Error(utils_1.ERRORS.INVALID_SMARTBUFFER_BUFFER);
  20853. }
  20854. } else {
  20855. this._buff = Buffer.allocUnsafe(DEFAULT_SMARTBUFFER_SIZE);
  20856. }
  20857. } else {
  20858. if (typeof options !== "undefined") {
  20859. throw new Error(utils_1.ERRORS.INVALID_SMARTBUFFER_OBJECT);
  20860. }
  20861. this._buff = Buffer.allocUnsafe(DEFAULT_SMARTBUFFER_SIZE);
  20862. }
  20863. }
  20864. /**
  20865. * Creates a new SmartBuffer instance with the provided internal Buffer size and optional encoding.
  20866. *
  20867. * @param size { Number } The size of the internal Buffer.
  20868. * @param encoding { String } The BufferEncoding to use for strings.
  20869. *
  20870. * @return { SmartBuffer }
  20871. */
  20872. static fromSize(size, encoding) {
  20873. return new this({
  20874. size,
  20875. encoding
  20876. });
  20877. }
  20878. /**
  20879. * Creates a new SmartBuffer instance with the provided Buffer and optional encoding.
  20880. *
  20881. * @param buffer { Buffer } The Buffer to use as the internal Buffer value.
  20882. * @param encoding { String } The BufferEncoding to use for strings.
  20883. *
  20884. * @return { SmartBuffer }
  20885. */
  20886. static fromBuffer(buff, encoding) {
  20887. return new this({
  20888. buff,
  20889. encoding
  20890. });
  20891. }
  20892. /**
  20893. * Creates a new SmartBuffer instance with the provided SmartBufferOptions options.
  20894. *
  20895. * @param options { SmartBufferOptions } The options to use when creating the SmartBuffer instance.
  20896. */
  20897. static fromOptions(options) {
  20898. return new this(options);
  20899. }
  20900. /**
  20901. * Type checking function that determines if an object is a SmartBufferOptions object.
  20902. */
  20903. static isSmartBufferOptions(options) {
  20904. const castOptions = options;
  20905. return castOptions && (castOptions.encoding !== void 0 || castOptions.size !== void 0 || castOptions.buff !== void 0);
  20906. }
  20907. // Signed integers
  20908. /**
  20909. * Reads an Int8 value from the current read position or an optionally provided offset.
  20910. *
  20911. * @param offset { Number } The offset to read data from (optional)
  20912. * @return { Number }
  20913. */
  20914. readInt8(offset) {
  20915. return this._readNumberValue(Buffer.prototype.readInt8, 1, offset);
  20916. }
  20917. /**
  20918. * Reads an Int16BE value from the current read position or an optionally provided offset.
  20919. *
  20920. * @param offset { Number } The offset to read data from (optional)
  20921. * @return { Number }
  20922. */
  20923. readInt16BE(offset) {
  20924. return this._readNumberValue(Buffer.prototype.readInt16BE, 2, offset);
  20925. }
  20926. /**
  20927. * Reads an Int16LE value from the current read position or an optionally provided offset.
  20928. *
  20929. * @param offset { Number } The offset to read data from (optional)
  20930. * @return { Number }
  20931. */
  20932. readInt16LE(offset) {
  20933. return this._readNumberValue(Buffer.prototype.readInt16LE, 2, offset);
  20934. }
  20935. /**
  20936. * Reads an Int32BE value from the current read position or an optionally provided offset.
  20937. *
  20938. * @param offset { Number } The offset to read data from (optional)
  20939. * @return { Number }
  20940. */
  20941. readInt32BE(offset) {
  20942. return this._readNumberValue(Buffer.prototype.readInt32BE, 4, offset);
  20943. }
  20944. /**
  20945. * Reads an Int32LE value from the current read position or an optionally provided offset.
  20946. *
  20947. * @param offset { Number } The offset to read data from (optional)
  20948. * @return { Number }
  20949. */
  20950. readInt32LE(offset) {
  20951. return this._readNumberValue(Buffer.prototype.readInt32LE, 4, offset);
  20952. }
  20953. /**
  20954. * Reads a BigInt64BE value from the current read position or an optionally provided offset.
  20955. *
  20956. * @param offset { Number } The offset to read data from (optional)
  20957. * @return { BigInt }
  20958. */
  20959. readBigInt64BE(offset) {
  20960. utils_1.bigIntAndBufferInt64Check("readBigInt64BE");
  20961. return this._readNumberValue(Buffer.prototype.readBigInt64BE, 8, offset);
  20962. }
  20963. /**
  20964. * Reads a BigInt64LE value from the current read position or an optionally provided offset.
  20965. *
  20966. * @param offset { Number } The offset to read data from (optional)
  20967. * @return { BigInt }
  20968. */
  20969. readBigInt64LE(offset) {
  20970. utils_1.bigIntAndBufferInt64Check("readBigInt64LE");
  20971. return this._readNumberValue(Buffer.prototype.readBigInt64LE, 8, offset);
  20972. }
  20973. /**
  20974. * Writes an Int8 value to the current write position (or at optional offset).
  20975. *
  20976. * @param value { Number } The value to write.
  20977. * @param offset { Number } The offset to write the value at.
  20978. *
  20979. * @return this
  20980. */
  20981. writeInt8(value, offset) {
  20982. this._writeNumberValue(Buffer.prototype.writeInt8, 1, value, offset);
  20983. return this;
  20984. }
  20985. /**
  20986. * Inserts an Int8 value at the given offset value.
  20987. *
  20988. * @param value { Number } The value to insert.
  20989. * @param offset { Number } The offset to insert the value at.
  20990. *
  20991. * @return this
  20992. */
  20993. insertInt8(value, offset) {
  20994. return this._insertNumberValue(Buffer.prototype.writeInt8, 1, value, offset);
  20995. }
  20996. /**
  20997. * Writes an Int16BE value to the current write position (or at optional offset).
  20998. *
  20999. * @param value { Number } The value to write.
  21000. * @param offset { Number } The offset to write the value at.
  21001. *
  21002. * @return this
  21003. */
  21004. writeInt16BE(value, offset) {
  21005. return this._writeNumberValue(Buffer.prototype.writeInt16BE, 2, value, offset);
  21006. }
  21007. /**
  21008. * Inserts an Int16BE value at the given offset value.
  21009. *
  21010. * @param value { Number } The value to insert.
  21011. * @param offset { Number } The offset to insert the value at.
  21012. *
  21013. * @return this
  21014. */
  21015. insertInt16BE(value, offset) {
  21016. return this._insertNumberValue(Buffer.prototype.writeInt16BE, 2, value, offset);
  21017. }
  21018. /**
  21019. * Writes an Int16LE value to the current write position (or at optional offset).
  21020. *
  21021. * @param value { Number } The value to write.
  21022. * @param offset { Number } The offset to write the value at.
  21023. *
  21024. * @return this
  21025. */
  21026. writeInt16LE(value, offset) {
  21027. return this._writeNumberValue(Buffer.prototype.writeInt16LE, 2, value, offset);
  21028. }
  21029. /**
  21030. * Inserts an Int16LE value at the given offset value.
  21031. *
  21032. * @param value { Number } The value to insert.
  21033. * @param offset { Number } The offset to insert the value at.
  21034. *
  21035. * @return this
  21036. */
  21037. insertInt16LE(value, offset) {
  21038. return this._insertNumberValue(Buffer.prototype.writeInt16LE, 2, value, offset);
  21039. }
  21040. /**
  21041. * Writes an Int32BE value to the current write position (or at optional offset).
  21042. *
  21043. * @param value { Number } The value to write.
  21044. * @param offset { Number } The offset to write the value at.
  21045. *
  21046. * @return this
  21047. */
  21048. writeInt32BE(value, offset) {
  21049. return this._writeNumberValue(Buffer.prototype.writeInt32BE, 4, value, offset);
  21050. }
  21051. /**
  21052. * Inserts an Int32BE value at the given offset value.
  21053. *
  21054. * @param value { Number } The value to insert.
  21055. * @param offset { Number } The offset to insert the value at.
  21056. *
  21057. * @return this
  21058. */
  21059. insertInt32BE(value, offset) {
  21060. return this._insertNumberValue(Buffer.prototype.writeInt32BE, 4, value, offset);
  21061. }
  21062. /**
  21063. * Writes an Int32LE value to the current write position (or at optional offset).
  21064. *
  21065. * @param value { Number } The value to write.
  21066. * @param offset { Number } The offset to write the value at.
  21067. *
  21068. * @return this
  21069. */
  21070. writeInt32LE(value, offset) {
  21071. return this._writeNumberValue(Buffer.prototype.writeInt32LE, 4, value, offset);
  21072. }
  21073. /**
  21074. * Inserts an Int32LE value at the given offset value.
  21075. *
  21076. * @param value { Number } The value to insert.
  21077. * @param offset { Number } The offset to insert the value at.
  21078. *
  21079. * @return this
  21080. */
  21081. insertInt32LE(value, offset) {
  21082. return this._insertNumberValue(Buffer.prototype.writeInt32LE, 4, value, offset);
  21083. }
  21084. /**
  21085. * Writes a BigInt64BE value to the current write position (or at optional offset).
  21086. *
  21087. * @param value { BigInt } The value to write.
  21088. * @param offset { Number } The offset to write the value at.
  21089. *
  21090. * @return this
  21091. */
  21092. writeBigInt64BE(value, offset) {
  21093. utils_1.bigIntAndBufferInt64Check("writeBigInt64BE");
  21094. return this._writeNumberValue(Buffer.prototype.writeBigInt64BE, 8, value, offset);
  21095. }
  21096. /**
  21097. * Inserts a BigInt64BE value at the given offset value.
  21098. *
  21099. * @param value { BigInt } The value to insert.
  21100. * @param offset { Number } The offset to insert the value at.
  21101. *
  21102. * @return this
  21103. */
  21104. insertBigInt64BE(value, offset) {
  21105. utils_1.bigIntAndBufferInt64Check("writeBigInt64BE");
  21106. return this._insertNumberValue(Buffer.prototype.writeBigInt64BE, 8, value, offset);
  21107. }
  21108. /**
  21109. * Writes a BigInt64LE value to the current write position (or at optional offset).
  21110. *
  21111. * @param value { BigInt } The value to write.
  21112. * @param offset { Number } The offset to write the value at.
  21113. *
  21114. * @return this
  21115. */
  21116. writeBigInt64LE(value, offset) {
  21117. utils_1.bigIntAndBufferInt64Check("writeBigInt64LE");
  21118. return this._writeNumberValue(Buffer.prototype.writeBigInt64LE, 8, value, offset);
  21119. }
  21120. /**
  21121. * Inserts a Int64LE value at the given offset value.
  21122. *
  21123. * @param value { BigInt } The value to insert.
  21124. * @param offset { Number } The offset to insert the value at.
  21125. *
  21126. * @return this
  21127. */
  21128. insertBigInt64LE(value, offset) {
  21129. utils_1.bigIntAndBufferInt64Check("writeBigInt64LE");
  21130. return this._insertNumberValue(Buffer.prototype.writeBigInt64LE, 8, value, offset);
  21131. }
  21132. // Unsigned Integers
  21133. /**
  21134. * Reads an UInt8 value from the current read position or an optionally provided offset.
  21135. *
  21136. * @param offset { Number } The offset to read data from (optional)
  21137. * @return { Number }
  21138. */
  21139. readUInt8(offset) {
  21140. return this._readNumberValue(Buffer.prototype.readUInt8, 1, offset);
  21141. }
  21142. /**
  21143. * Reads an UInt16BE value from the current read position or an optionally provided offset.
  21144. *
  21145. * @param offset { Number } The offset to read data from (optional)
  21146. * @return { Number }
  21147. */
  21148. readUInt16BE(offset) {
  21149. return this._readNumberValue(Buffer.prototype.readUInt16BE, 2, offset);
  21150. }
  21151. /**
  21152. * Reads an UInt16LE value from the current read position or an optionally provided offset.
  21153. *
  21154. * @param offset { Number } The offset to read data from (optional)
  21155. * @return { Number }
  21156. */
  21157. readUInt16LE(offset) {
  21158. return this._readNumberValue(Buffer.prototype.readUInt16LE, 2, offset);
  21159. }
  21160. /**
  21161. * Reads an UInt32BE value from the current read position or an optionally provided offset.
  21162. *
  21163. * @param offset { Number } The offset to read data from (optional)
  21164. * @return { Number }
  21165. */
  21166. readUInt32BE(offset) {
  21167. return this._readNumberValue(Buffer.prototype.readUInt32BE, 4, offset);
  21168. }
  21169. /**
  21170. * Reads an UInt32LE value from the current read position or an optionally provided offset.
  21171. *
  21172. * @param offset { Number } The offset to read data from (optional)
  21173. * @return { Number }
  21174. */
  21175. readUInt32LE(offset) {
  21176. return this._readNumberValue(Buffer.prototype.readUInt32LE, 4, offset);
  21177. }
  21178. /**
  21179. * Reads a BigUInt64BE value from the current read position or an optionally provided offset.
  21180. *
  21181. * @param offset { Number } The offset to read data from (optional)
  21182. * @return { BigInt }
  21183. */
  21184. readBigUInt64BE(offset) {
  21185. utils_1.bigIntAndBufferInt64Check("readBigUInt64BE");
  21186. return this._readNumberValue(Buffer.prototype.readBigUInt64BE, 8, offset);
  21187. }
  21188. /**
  21189. * Reads a BigUInt64LE value from the current read position or an optionally provided offset.
  21190. *
  21191. * @param offset { Number } The offset to read data from (optional)
  21192. * @return { BigInt }
  21193. */
  21194. readBigUInt64LE(offset) {
  21195. utils_1.bigIntAndBufferInt64Check("readBigUInt64LE");
  21196. return this._readNumberValue(Buffer.prototype.readBigUInt64LE, 8, offset);
  21197. }
  21198. /**
  21199. * Writes an UInt8 value to the current write position (or at optional offset).
  21200. *
  21201. * @param value { Number } The value to write.
  21202. * @param offset { Number } The offset to write the value at.
  21203. *
  21204. * @return this
  21205. */
  21206. writeUInt8(value, offset) {
  21207. return this._writeNumberValue(Buffer.prototype.writeUInt8, 1, value, offset);
  21208. }
  21209. /**
  21210. * Inserts an UInt8 value at the given offset value.
  21211. *
  21212. * @param value { Number } The value to insert.
  21213. * @param offset { Number } The offset to insert the value at.
  21214. *
  21215. * @return this
  21216. */
  21217. insertUInt8(value, offset) {
  21218. return this._insertNumberValue(Buffer.prototype.writeUInt8, 1, value, offset);
  21219. }
  21220. /**
  21221. * Writes an UInt16BE value to the current write position (or at optional offset).
  21222. *
  21223. * @param value { Number } The value to write.
  21224. * @param offset { Number } The offset to write the value at.
  21225. *
  21226. * @return this
  21227. */
  21228. writeUInt16BE(value, offset) {
  21229. return this._writeNumberValue(Buffer.prototype.writeUInt16BE, 2, value, offset);
  21230. }
  21231. /**
  21232. * Inserts an UInt16BE value at the given offset value.
  21233. *
  21234. * @param value { Number } The value to insert.
  21235. * @param offset { Number } The offset to insert the value at.
  21236. *
  21237. * @return this
  21238. */
  21239. insertUInt16BE(value, offset) {
  21240. return this._insertNumberValue(Buffer.prototype.writeUInt16BE, 2, value, offset);
  21241. }
  21242. /**
  21243. * Writes an UInt16LE value to the current write position (or at optional offset).
  21244. *
  21245. * @param value { Number } The value to write.
  21246. * @param offset { Number } The offset to write the value at.
  21247. *
  21248. * @return this
  21249. */
  21250. writeUInt16LE(value, offset) {
  21251. return this._writeNumberValue(Buffer.prototype.writeUInt16LE, 2, value, offset);
  21252. }
  21253. /**
  21254. * Inserts an UInt16LE value at the given offset value.
  21255. *
  21256. * @param value { Number } The value to insert.
  21257. * @param offset { Number } The offset to insert the value at.
  21258. *
  21259. * @return this
  21260. */
  21261. insertUInt16LE(value, offset) {
  21262. return this._insertNumberValue(Buffer.prototype.writeUInt16LE, 2, value, offset);
  21263. }
  21264. /**
  21265. * Writes an UInt32BE value to the current write position (or at optional offset).
  21266. *
  21267. * @param value { Number } The value to write.
  21268. * @param offset { Number } The offset to write the value at.
  21269. *
  21270. * @return this
  21271. */
  21272. writeUInt32BE(value, offset) {
  21273. return this._writeNumberValue(Buffer.prototype.writeUInt32BE, 4, value, offset);
  21274. }
  21275. /**
  21276. * Inserts an UInt32BE value at the given offset value.
  21277. *
  21278. * @param value { Number } The value to insert.
  21279. * @param offset { Number } The offset to insert the value at.
  21280. *
  21281. * @return this
  21282. */
  21283. insertUInt32BE(value, offset) {
  21284. return this._insertNumberValue(Buffer.prototype.writeUInt32BE, 4, value, offset);
  21285. }
  21286. /**
  21287. * Writes an UInt32LE value to the current write position (or at optional offset).
  21288. *
  21289. * @param value { Number } The value to write.
  21290. * @param offset { Number } The offset to write the value at.
  21291. *
  21292. * @return this
  21293. */
  21294. writeUInt32LE(value, offset) {
  21295. return this._writeNumberValue(Buffer.prototype.writeUInt32LE, 4, value, offset);
  21296. }
  21297. /**
  21298. * Inserts an UInt32LE value at the given offset value.
  21299. *
  21300. * @param value { Number } The value to insert.
  21301. * @param offset { Number } The offset to insert the value at.
  21302. *
  21303. * @return this
  21304. */
  21305. insertUInt32LE(value, offset) {
  21306. return this._insertNumberValue(Buffer.prototype.writeUInt32LE, 4, value, offset);
  21307. }
  21308. /**
  21309. * Writes a BigUInt64BE value to the current write position (or at optional offset).
  21310. *
  21311. * @param value { Number } The value to write.
  21312. * @param offset { Number } The offset to write the value at.
  21313. *
  21314. * @return this
  21315. */
  21316. writeBigUInt64BE(value, offset) {
  21317. utils_1.bigIntAndBufferInt64Check("writeBigUInt64BE");
  21318. return this._writeNumberValue(Buffer.prototype.writeBigUInt64BE, 8, value, offset);
  21319. }
  21320. /**
  21321. * Inserts a BigUInt64BE value at the given offset value.
  21322. *
  21323. * @param value { Number } The value to insert.
  21324. * @param offset { Number } The offset to insert the value at.
  21325. *
  21326. * @return this
  21327. */
  21328. insertBigUInt64BE(value, offset) {
  21329. utils_1.bigIntAndBufferInt64Check("writeBigUInt64BE");
  21330. return this._insertNumberValue(Buffer.prototype.writeBigUInt64BE, 8, value, offset);
  21331. }
  21332. /**
  21333. * Writes a BigUInt64LE value to the current write position (or at optional offset).
  21334. *
  21335. * @param value { Number } The value to write.
  21336. * @param offset { Number } The offset to write the value at.
  21337. *
  21338. * @return this
  21339. */
  21340. writeBigUInt64LE(value, offset) {
  21341. utils_1.bigIntAndBufferInt64Check("writeBigUInt64LE");
  21342. return this._writeNumberValue(Buffer.prototype.writeBigUInt64LE, 8, value, offset);
  21343. }
  21344. /**
  21345. * Inserts a BigUInt64LE value at the given offset value.
  21346. *
  21347. * @param value { Number } The value to insert.
  21348. * @param offset { Number } The offset to insert the value at.
  21349. *
  21350. * @return this
  21351. */
  21352. insertBigUInt64LE(value, offset) {
  21353. utils_1.bigIntAndBufferInt64Check("writeBigUInt64LE");
  21354. return this._insertNumberValue(Buffer.prototype.writeBigUInt64LE, 8, value, offset);
  21355. }
  21356. // Floating Point
  21357. /**
  21358. * Reads an FloatBE value from the current read position or an optionally provided offset.
  21359. *
  21360. * @param offset { Number } The offset to read data from (optional)
  21361. * @return { Number }
  21362. */
  21363. readFloatBE(offset) {
  21364. return this._readNumberValue(Buffer.prototype.readFloatBE, 4, offset);
  21365. }
  21366. /**
  21367. * Reads an FloatLE value from the current read position or an optionally provided offset.
  21368. *
  21369. * @param offset { Number } The offset to read data from (optional)
  21370. * @return { Number }
  21371. */
  21372. readFloatLE(offset) {
  21373. return this._readNumberValue(Buffer.prototype.readFloatLE, 4, offset);
  21374. }
  21375. /**
  21376. * Writes a FloatBE value to the current write position (or at optional offset).
  21377. *
  21378. * @param value { Number } The value to write.
  21379. * @param offset { Number } The offset to write the value at.
  21380. *
  21381. * @return this
  21382. */
  21383. writeFloatBE(value, offset) {
  21384. return this._writeNumberValue(Buffer.prototype.writeFloatBE, 4, value, offset);
  21385. }
  21386. /**
  21387. * Inserts a FloatBE value at the given offset value.
  21388. *
  21389. * @param value { Number } The value to insert.
  21390. * @param offset { Number } The offset to insert the value at.
  21391. *
  21392. * @return this
  21393. */
  21394. insertFloatBE(value, offset) {
  21395. return this._insertNumberValue(Buffer.prototype.writeFloatBE, 4, value, offset);
  21396. }
  21397. /**
  21398. * Writes a FloatLE value to the current write position (or at optional offset).
  21399. *
  21400. * @param value { Number } The value to write.
  21401. * @param offset { Number } The offset to write the value at.
  21402. *
  21403. * @return this
  21404. */
  21405. writeFloatLE(value, offset) {
  21406. return this._writeNumberValue(Buffer.prototype.writeFloatLE, 4, value, offset);
  21407. }
  21408. /**
  21409. * Inserts a FloatLE value at the given offset value.
  21410. *
  21411. * @param value { Number } The value to insert.
  21412. * @param offset { Number } The offset to insert the value at.
  21413. *
  21414. * @return this
  21415. */
  21416. insertFloatLE(value, offset) {
  21417. return this._insertNumberValue(Buffer.prototype.writeFloatLE, 4, value, offset);
  21418. }
  21419. // Double Floating Point
  21420. /**
  21421. * Reads an DoublEBE value from the current read position or an optionally provided offset.
  21422. *
  21423. * @param offset { Number } The offset to read data from (optional)
  21424. * @return { Number }
  21425. */
  21426. readDoubleBE(offset) {
  21427. return this._readNumberValue(Buffer.prototype.readDoubleBE, 8, offset);
  21428. }
  21429. /**
  21430. * Reads an DoubleLE value from the current read position or an optionally provided offset.
  21431. *
  21432. * @param offset { Number } The offset to read data from (optional)
  21433. * @return { Number }
  21434. */
  21435. readDoubleLE(offset) {
  21436. return this._readNumberValue(Buffer.prototype.readDoubleLE, 8, offset);
  21437. }
  21438. /**
  21439. * Writes a DoubleBE value to the current write position (or at optional offset).
  21440. *
  21441. * @param value { Number } The value to write.
  21442. * @param offset { Number } The offset to write the value at.
  21443. *
  21444. * @return this
  21445. */
  21446. writeDoubleBE(value, offset) {
  21447. return this._writeNumberValue(Buffer.prototype.writeDoubleBE, 8, value, offset);
  21448. }
  21449. /**
  21450. * Inserts a DoubleBE value at the given offset value.
  21451. *
  21452. * @param value { Number } The value to insert.
  21453. * @param offset { Number } The offset to insert the value at.
  21454. *
  21455. * @return this
  21456. */
  21457. insertDoubleBE(value, offset) {
  21458. return this._insertNumberValue(Buffer.prototype.writeDoubleBE, 8, value, offset);
  21459. }
  21460. /**
  21461. * Writes a DoubleLE value to the current write position (or at optional offset).
  21462. *
  21463. * @param value { Number } The value to write.
  21464. * @param offset { Number } The offset to write the value at.
  21465. *
  21466. * @return this
  21467. */
  21468. writeDoubleLE(value, offset) {
  21469. return this._writeNumberValue(Buffer.prototype.writeDoubleLE, 8, value, offset);
  21470. }
  21471. /**
  21472. * Inserts a DoubleLE value at the given offset value.
  21473. *
  21474. * @param value { Number } The value to insert.
  21475. * @param offset { Number } The offset to insert the value at.
  21476. *
  21477. * @return this
  21478. */
  21479. insertDoubleLE(value, offset) {
  21480. return this._insertNumberValue(Buffer.prototype.writeDoubleLE, 8, value, offset);
  21481. }
  21482. // Strings
  21483. /**
  21484. * Reads a String from the current read position.
  21485. *
  21486. * @param arg1 { Number | String } The number of bytes to read as a String, or the BufferEncoding to use for
  21487. * the string (Defaults to instance level encoding).
  21488. * @param encoding { String } The BufferEncoding to use for the string (Defaults to instance level encoding).
  21489. *
  21490. * @return { String }
  21491. */
  21492. readString(arg1, encoding) {
  21493. let lengthVal;
  21494. if (typeof arg1 === "number") {
  21495. utils_1.checkLengthValue(arg1);
  21496. lengthVal = Math.min(arg1, this.length - this._readOffset);
  21497. } else {
  21498. encoding = arg1;
  21499. lengthVal = this.length - this._readOffset;
  21500. }
  21501. if (typeof encoding !== "undefined") {
  21502. utils_1.checkEncoding(encoding);
  21503. }
  21504. const value = this._buff.slice(this._readOffset, this._readOffset + lengthVal).toString(encoding || this._encoding);
  21505. this._readOffset += lengthVal;
  21506. return value;
  21507. }
  21508. /**
  21509. * Inserts a String
  21510. *
  21511. * @param value { String } The String value to insert.
  21512. * @param offset { Number } The offset to insert the string at.
  21513. * @param encoding { String } The BufferEncoding to use for writing strings (defaults to instance encoding).
  21514. *
  21515. * @return this
  21516. */
  21517. insertString(value, offset, encoding) {
  21518. utils_1.checkOffsetValue(offset);
  21519. return this._handleString(value, true, offset, encoding);
  21520. }
  21521. /**
  21522. * Writes a String
  21523. *
  21524. * @param value { String } The String value to write.
  21525. * @param arg2 { Number | String } The offset to write the string at, or the BufferEncoding to use.
  21526. * @param encoding { String } The BufferEncoding to use for writing strings (defaults to instance encoding).
  21527. *
  21528. * @return this
  21529. */
  21530. writeString(value, arg2, encoding) {
  21531. return this._handleString(value, false, arg2, encoding);
  21532. }
  21533. /**
  21534. * Reads a null-terminated String from the current read position.
  21535. *
  21536. * @param encoding { String } The BufferEncoding to use for the string (Defaults to instance level encoding).
  21537. *
  21538. * @return { String }
  21539. */
  21540. readStringNT(encoding) {
  21541. if (typeof encoding !== "undefined") {
  21542. utils_1.checkEncoding(encoding);
  21543. }
  21544. let nullPos = this.length;
  21545. for (let i = this._readOffset; i < this.length; i++) {
  21546. if (this._buff[i] === 0) {
  21547. nullPos = i;
  21548. break;
  21549. }
  21550. }
  21551. const value = this._buff.slice(this._readOffset, nullPos);
  21552. this._readOffset = nullPos + 1;
  21553. return value.toString(encoding || this._encoding);
  21554. }
  21555. /**
  21556. * Inserts a null-terminated String.
  21557. *
  21558. * @param value { String } The String value to write.
  21559. * @param arg2 { Number | String } The offset to write the string to, or the BufferEncoding to use.
  21560. * @param encoding { String } The BufferEncoding to use for writing strings (defaults to instance encoding).
  21561. *
  21562. * @return this
  21563. */
  21564. insertStringNT(value, offset, encoding) {
  21565. utils_1.checkOffsetValue(offset);
  21566. this.insertString(value, offset, encoding);
  21567. this.insertUInt8(0, offset + value.length);
  21568. return this;
  21569. }
  21570. /**
  21571. * Writes a null-terminated String.
  21572. *
  21573. * @param value { String } The String value to write.
  21574. * @param arg2 { Number | String } The offset to write the string to, or the BufferEncoding to use.
  21575. * @param encoding { String } The BufferEncoding to use for writing strings (defaults to instance encoding).
  21576. *
  21577. * @return this
  21578. */
  21579. writeStringNT(value, arg2, encoding) {
  21580. this.writeString(value, arg2, encoding);
  21581. this.writeUInt8(0, typeof arg2 === "number" ? arg2 + value.length : this.writeOffset);
  21582. return this;
  21583. }
  21584. // Buffers
  21585. /**
  21586. * Reads a Buffer from the internal read position.
  21587. *
  21588. * @param length { Number } The length of data to read as a Buffer.
  21589. *
  21590. * @return { Buffer }
  21591. */
  21592. readBuffer(length) {
  21593. if (typeof length !== "undefined") {
  21594. utils_1.checkLengthValue(length);
  21595. }
  21596. const lengthVal = typeof length === "number" ? length : this.length;
  21597. const endPoint = Math.min(this.length, this._readOffset + lengthVal);
  21598. const value = this._buff.slice(this._readOffset, endPoint);
  21599. this._readOffset = endPoint;
  21600. return value;
  21601. }
  21602. /**
  21603. * Writes a Buffer to the current write position.
  21604. *
  21605. * @param value { Buffer } The Buffer to write.
  21606. * @param offset { Number } The offset to write the Buffer to.
  21607. *
  21608. * @return this
  21609. */
  21610. insertBuffer(value, offset) {
  21611. utils_1.checkOffsetValue(offset);
  21612. return this._handleBuffer(value, true, offset);
  21613. }
  21614. /**
  21615. * Writes a Buffer to the current write position.
  21616. *
  21617. * @param value { Buffer } The Buffer to write.
  21618. * @param offset { Number } The offset to write the Buffer to.
  21619. *
  21620. * @return this
  21621. */
  21622. writeBuffer(value, offset) {
  21623. return this._handleBuffer(value, false, offset);
  21624. }
  21625. /**
  21626. * Reads a null-terminated Buffer from the current read poisiton.
  21627. *
  21628. * @return { Buffer }
  21629. */
  21630. readBufferNT() {
  21631. let nullPos = this.length;
  21632. for (let i = this._readOffset; i < this.length; i++) {
  21633. if (this._buff[i] === 0) {
  21634. nullPos = i;
  21635. break;
  21636. }
  21637. }
  21638. const value = this._buff.slice(this._readOffset, nullPos);
  21639. this._readOffset = nullPos + 1;
  21640. return value;
  21641. }
  21642. /**
  21643. * Inserts a null-terminated Buffer.
  21644. *
  21645. * @param value { Buffer } The Buffer to write.
  21646. * @param offset { Number } The offset to write the Buffer to.
  21647. *
  21648. * @return this
  21649. */
  21650. insertBufferNT(value, offset) {
  21651. utils_1.checkOffsetValue(offset);
  21652. this.insertBuffer(value, offset);
  21653. this.insertUInt8(0, offset + value.length);
  21654. return this;
  21655. }
  21656. /**
  21657. * Writes a null-terminated Buffer.
  21658. *
  21659. * @param value { Buffer } The Buffer to write.
  21660. * @param offset { Number } The offset to write the Buffer to.
  21661. *
  21662. * @return this
  21663. */
  21664. writeBufferNT(value, offset) {
  21665. if (typeof offset !== "undefined") {
  21666. utils_1.checkOffsetValue(offset);
  21667. }
  21668. this.writeBuffer(value, offset);
  21669. this.writeUInt8(0, typeof offset === "number" ? offset + value.length : this._writeOffset);
  21670. return this;
  21671. }
  21672. /**
  21673. * Clears the SmartBuffer instance to its original empty state.
  21674. */
  21675. clear() {
  21676. this._writeOffset = 0;
  21677. this._readOffset = 0;
  21678. this.length = 0;
  21679. return this;
  21680. }
  21681. /**
  21682. * Gets the remaining data left to be read from the SmartBuffer instance.
  21683. *
  21684. * @return { Number }
  21685. */
  21686. remaining() {
  21687. return this.length - this._readOffset;
  21688. }
  21689. /**
  21690. * Gets the current read offset value of the SmartBuffer instance.
  21691. *
  21692. * @return { Number }
  21693. */
  21694. get readOffset() {
  21695. return this._readOffset;
  21696. }
  21697. /**
  21698. * Sets the read offset value of the SmartBuffer instance.
  21699. *
  21700. * @param offset { Number } - The offset value to set.
  21701. */
  21702. set readOffset(offset) {
  21703. utils_1.checkOffsetValue(offset);
  21704. utils_1.checkTargetOffset(offset, this);
  21705. this._readOffset = offset;
  21706. }
  21707. /**
  21708. * Gets the current write offset value of the SmartBuffer instance.
  21709. *
  21710. * @return { Number }
  21711. */
  21712. get writeOffset() {
  21713. return this._writeOffset;
  21714. }
  21715. /**
  21716. * Sets the write offset value of the SmartBuffer instance.
  21717. *
  21718. * @param offset { Number } - The offset value to set.
  21719. */
  21720. set writeOffset(offset) {
  21721. utils_1.checkOffsetValue(offset);
  21722. utils_1.checkTargetOffset(offset, this);
  21723. this._writeOffset = offset;
  21724. }
  21725. /**
  21726. * Gets the currently set string encoding of the SmartBuffer instance.
  21727. *
  21728. * @return { BufferEncoding } The string Buffer encoding currently set.
  21729. */
  21730. get encoding() {
  21731. return this._encoding;
  21732. }
  21733. /**
  21734. * Sets the string encoding of the SmartBuffer instance.
  21735. *
  21736. * @param encoding { BufferEncoding } The string Buffer encoding to set.
  21737. */
  21738. set encoding(encoding) {
  21739. utils_1.checkEncoding(encoding);
  21740. this._encoding = encoding;
  21741. }
  21742. /**
  21743. * Gets the underlying internal Buffer. (This includes unmanaged data in the Buffer)
  21744. *
  21745. * @return { Buffer } The Buffer value.
  21746. */
  21747. get internalBuffer() {
  21748. return this._buff;
  21749. }
  21750. /**
  21751. * Gets the value of the internal managed Buffer (Includes managed data only)
  21752. *
  21753. * @param { Buffer }
  21754. */
  21755. toBuffer() {
  21756. return this._buff.slice(0, this.length);
  21757. }
  21758. /**
  21759. * Gets the String value of the internal managed Buffer
  21760. *
  21761. * @param encoding { String } The BufferEncoding to display the Buffer as (defaults to instance level encoding).
  21762. */
  21763. toString(encoding) {
  21764. const encodingVal = typeof encoding === "string" ? encoding : this._encoding;
  21765. utils_1.checkEncoding(encodingVal);
  21766. return this._buff.toString(encodingVal, 0, this.length);
  21767. }
  21768. /**
  21769. * Destroys the SmartBuffer instance.
  21770. */
  21771. destroy() {
  21772. this.clear();
  21773. return this;
  21774. }
  21775. /**
  21776. * Handles inserting and writing strings.
  21777. *
  21778. * @param value { String } The String value to insert.
  21779. * @param isInsert { Boolean } True if inserting a string, false if writing.
  21780. * @param arg2 { Number | String } The offset to insert the string at, or the BufferEncoding to use.
  21781. * @param encoding { String } The BufferEncoding to use for writing strings (defaults to instance encoding).
  21782. */
  21783. _handleString(value, isInsert, arg3, encoding) {
  21784. let offsetVal = this._writeOffset;
  21785. let encodingVal = this._encoding;
  21786. if (typeof arg3 === "number") {
  21787. offsetVal = arg3;
  21788. } else if (typeof arg3 === "string") {
  21789. utils_1.checkEncoding(arg3);
  21790. encodingVal = arg3;
  21791. }
  21792. if (typeof encoding === "string") {
  21793. utils_1.checkEncoding(encoding);
  21794. encodingVal = encoding;
  21795. }
  21796. const byteLength = Buffer.byteLength(value, encodingVal);
  21797. if (isInsert) {
  21798. this.ensureInsertable(byteLength, offsetVal);
  21799. } else {
  21800. this._ensureWriteable(byteLength, offsetVal);
  21801. }
  21802. this._buff.write(value, offsetVal, byteLength, encodingVal);
  21803. if (isInsert) {
  21804. this._writeOffset += byteLength;
  21805. } else {
  21806. if (typeof arg3 === "number") {
  21807. this._writeOffset = Math.max(this._writeOffset, offsetVal + byteLength);
  21808. } else {
  21809. this._writeOffset += byteLength;
  21810. }
  21811. }
  21812. return this;
  21813. }
  21814. /**
  21815. * Handles writing or insert of a Buffer.
  21816. *
  21817. * @param value { Buffer } The Buffer to write.
  21818. * @param offset { Number } The offset to write the Buffer to.
  21819. */
  21820. _handleBuffer(value, isInsert, offset) {
  21821. const offsetVal = typeof offset === "number" ? offset : this._writeOffset;
  21822. if (isInsert) {
  21823. this.ensureInsertable(value.length, offsetVal);
  21824. } else {
  21825. this._ensureWriteable(value.length, offsetVal);
  21826. }
  21827. value.copy(this._buff, offsetVal);
  21828. if (isInsert) {
  21829. this._writeOffset += value.length;
  21830. } else {
  21831. if (typeof offset === "number") {
  21832. this._writeOffset = Math.max(this._writeOffset, offsetVal + value.length);
  21833. } else {
  21834. this._writeOffset += value.length;
  21835. }
  21836. }
  21837. return this;
  21838. }
  21839. /**
  21840. * Ensures that the internal Buffer is large enough to read data.
  21841. *
  21842. * @param length { Number } The length of the data that needs to be read.
  21843. * @param offset { Number } The offset of the data that needs to be read.
  21844. */
  21845. ensureReadable(length, offset) {
  21846. let offsetVal = this._readOffset;
  21847. if (typeof offset !== "undefined") {
  21848. utils_1.checkOffsetValue(offset);
  21849. offsetVal = offset;
  21850. }
  21851. if (offsetVal < 0 || offsetVal + length > this.length) {
  21852. throw new Error(utils_1.ERRORS.INVALID_READ_BEYOND_BOUNDS);
  21853. }
  21854. }
  21855. /**
  21856. * Ensures that the internal Buffer is large enough to insert data.
  21857. *
  21858. * @param dataLength { Number } The length of the data that needs to be written.
  21859. * @param offset { Number } The offset of the data to be written.
  21860. */
  21861. ensureInsertable(dataLength, offset) {
  21862. utils_1.checkOffsetValue(offset);
  21863. this._ensureCapacity(this.length + dataLength);
  21864. if (offset < this.length) {
  21865. this._buff.copy(this._buff, offset + dataLength, offset, this._buff.length);
  21866. }
  21867. if (offset + dataLength > this.length) {
  21868. this.length = offset + dataLength;
  21869. } else {
  21870. this.length += dataLength;
  21871. }
  21872. }
  21873. /**
  21874. * Ensures that the internal Buffer is large enough to write data.
  21875. *
  21876. * @param dataLength { Number } The length of the data that needs to be written.
  21877. * @param offset { Number } The offset of the data to be written (defaults to writeOffset).
  21878. */
  21879. _ensureWriteable(dataLength, offset) {
  21880. const offsetVal = typeof offset === "number" ? offset : this._writeOffset;
  21881. this._ensureCapacity(offsetVal + dataLength);
  21882. if (offsetVal + dataLength > this.length) {
  21883. this.length = offsetVal + dataLength;
  21884. }
  21885. }
  21886. /**
  21887. * Ensures that the internal Buffer is large enough to write at least the given amount of data.
  21888. *
  21889. * @param minLength { Number } The minimum length of the data needs to be written.
  21890. */
  21891. _ensureCapacity(minLength) {
  21892. const oldLength = this._buff.length;
  21893. if (minLength > oldLength) {
  21894. let data = this._buff;
  21895. let newLength = oldLength * 3 / 2 + 1;
  21896. if (newLength < minLength) {
  21897. newLength = minLength;
  21898. }
  21899. this._buff = Buffer.allocUnsafe(newLength);
  21900. data.copy(this._buff, 0, 0, oldLength);
  21901. }
  21902. }
  21903. /**
  21904. * Reads a numeric number value using the provided function.
  21905. *
  21906. * @typeparam T { number | bigint } The type of the value to be read
  21907. *
  21908. * @param func { Function(offset: number) => number } The function to read data on the internal Buffer with.
  21909. * @param byteSize { Number } The number of bytes read.
  21910. * @param offset { Number } The offset to read from (optional). When this is not provided, the managed readOffset is used instead.
  21911. *
  21912. * @returns { T } the number value
  21913. */
  21914. _readNumberValue(func, byteSize, offset) {
  21915. this.ensureReadable(byteSize, offset);
  21916. const value = func.call(this._buff, typeof offset === "number" ? offset : this._readOffset);
  21917. if (typeof offset === "undefined") {
  21918. this._readOffset += byteSize;
  21919. }
  21920. return value;
  21921. }
  21922. /**
  21923. * Inserts a numeric number value based on the given offset and value.
  21924. *
  21925. * @typeparam T { number | bigint } The type of the value to be written
  21926. *
  21927. * @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
  21928. * @param byteSize { Number } The number of bytes written.
  21929. * @param value { T } The number value to write.
  21930. * @param offset { Number } the offset to write the number at (REQUIRED).
  21931. *
  21932. * @returns SmartBuffer this buffer
  21933. */
  21934. _insertNumberValue(func, byteSize, value, offset) {
  21935. utils_1.checkOffsetValue(offset);
  21936. this.ensureInsertable(byteSize, offset);
  21937. func.call(this._buff, value, offset);
  21938. this._writeOffset += byteSize;
  21939. return this;
  21940. }
  21941. /**
  21942. * Writes a numeric number value based on the given offset and value.
  21943. *
  21944. * @typeparam T { number | bigint } The type of the value to be written
  21945. *
  21946. * @param func { Function(offset: T, offset?) => number} The function to write data on the internal Buffer with.
  21947. * @param byteSize { Number } The number of bytes written.
  21948. * @param value { T } The number value to write.
  21949. * @param offset { Number } the offset to write the number at (REQUIRED).
  21950. *
  21951. * @returns SmartBuffer this buffer
  21952. */
  21953. _writeNumberValue(func, byteSize, value, offset) {
  21954. if (typeof offset === "number") {
  21955. if (offset < 0) {
  21956. throw new Error(utils_1.ERRORS.INVALID_WRITE_BEYOND_BOUNDS);
  21957. }
  21958. utils_1.checkOffsetValue(offset);
  21959. }
  21960. const offsetVal = typeof offset === "number" ? offset : this._writeOffset;
  21961. this._ensureWriteable(byteSize, offsetVal);
  21962. func.call(this._buff, value, offsetVal);
  21963. if (typeof offset === "number") {
  21964. this._writeOffset = Math.max(this._writeOffset, offsetVal + byteSize);
  21965. } else {
  21966. this._writeOffset += byteSize;
  21967. }
  21968. return this;
  21969. }
  21970. };
  21971. exports2.SmartBuffer = SmartBuffer;
  21972. }
  21973. });
  21974. // node_modules/socks/build/common/constants.js
  21975. var require_constants3 = __commonJS({
  21976. "node_modules/socks/build/common/constants.js"(exports2) {
  21977. "use strict";
  21978. Object.defineProperty(exports2, "__esModule", { value: true });
  21979. exports2.SOCKS5_NO_ACCEPTABLE_AUTH = exports2.SOCKS5_CUSTOM_AUTH_END = exports2.SOCKS5_CUSTOM_AUTH_START = exports2.SOCKS_INCOMING_PACKET_SIZES = exports2.SocksClientState = exports2.Socks5Response = exports2.Socks5HostType = exports2.Socks5Auth = exports2.Socks4Response = exports2.SocksCommand = exports2.ERRORS = exports2.DEFAULT_TIMEOUT = void 0;
  21980. var DEFAULT_TIMEOUT = 3e4;
  21981. exports2.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
  21982. var ERRORS = {
  21983. InvalidSocksCommand: "An invalid SOCKS command was provided. Valid options are connect, bind, and associate.",
  21984. InvalidSocksCommandForOperation: "An invalid SOCKS command was provided. Only a subset of commands are supported for this operation.",
  21985. InvalidSocksCommandChain: "An invalid SOCKS command was provided. Chaining currently only supports the connect command.",
  21986. InvalidSocksClientOptionsDestination: "An invalid destination host was provided.",
  21987. InvalidSocksClientOptionsExistingSocket: "An invalid existing socket was provided. This should be an instance of stream.Duplex.",
  21988. InvalidSocksClientOptionsProxy: "Invalid SOCKS proxy details were provided.",
  21989. InvalidSocksClientOptionsTimeout: "An invalid timeout value was provided. Please enter a value above 0 (in ms).",
  21990. InvalidSocksClientOptionsProxiesLength: "At least two socks proxies must be provided for chaining.",
  21991. InvalidSocksClientOptionsCustomAuthRange: "Custom auth must be a value between 0x80 and 0xFE.",
  21992. InvalidSocksClientOptionsCustomAuthOptions: "When a custom_auth_method is provided, custom_auth_request_handler, custom_auth_response_size, and custom_auth_response_handler must also be provided and valid.",
  21993. NegotiationError: "Negotiation error",
  21994. SocketClosed: "Socket closed",
  21995. ProxyConnectionTimedOut: "Proxy connection timed out",
  21996. InternalError: "SocksClient internal error (this should not happen)",
  21997. InvalidSocks4HandshakeResponse: "Received invalid Socks4 handshake response",
  21998. Socks4ProxyRejectedConnection: "Socks4 Proxy rejected connection",
  21999. InvalidSocks4IncomingConnectionResponse: "Socks4 invalid incoming connection response",
  22000. Socks4ProxyRejectedIncomingBoundConnection: "Socks4 Proxy rejected incoming bound connection",
  22001. InvalidSocks5InitialHandshakeResponse: "Received invalid Socks5 initial handshake response",
  22002. InvalidSocks5IntiailHandshakeSocksVersion: "Received invalid Socks5 initial handshake (invalid socks version)",
  22003. InvalidSocks5InitialHandshakeNoAcceptedAuthType: "Received invalid Socks5 initial handshake (no accepted authentication type)",
  22004. InvalidSocks5InitialHandshakeUnknownAuthType: "Received invalid Socks5 initial handshake (unknown authentication type)",
  22005. Socks5AuthenticationFailed: "Socks5 Authentication failed",
  22006. InvalidSocks5FinalHandshake: "Received invalid Socks5 final handshake response",
  22007. InvalidSocks5FinalHandshakeRejected: "Socks5 proxy rejected connection",
  22008. InvalidSocks5IncomingConnectionResponse: "Received invalid Socks5 incoming connection response",
  22009. Socks5ProxyRejectedIncomingBoundConnection: "Socks5 Proxy rejected incoming bound connection"
  22010. };
  22011. exports2.ERRORS = ERRORS;
  22012. var SOCKS_INCOMING_PACKET_SIZES = {
  22013. Socks5InitialHandshakeResponse: 2,
  22014. Socks5UserPassAuthenticationResponse: 2,
  22015. // Command response + incoming connection (bind)
  22016. Socks5ResponseHeader: 5,
  22017. // We need at least 5 to read the hostname length, then we wait for the address+port information.
  22018. Socks5ResponseIPv4: 10,
  22019. // 4 header + 4 ip + 2 port
  22020. Socks5ResponseIPv6: 22,
  22021. // 4 header + 16 ip + 2 port
  22022. Socks5ResponseHostname: (hostNameLength) => hostNameLength + 7,
  22023. // 4 header + 1 host length + host + 2 port
  22024. // Command response + incoming connection (bind)
  22025. Socks4Response: 8
  22026. // 2 header + 2 port + 4 ip
  22027. };
  22028. exports2.SOCKS_INCOMING_PACKET_SIZES = SOCKS_INCOMING_PACKET_SIZES;
  22029. var SocksCommand;
  22030. (function(SocksCommand2) {
  22031. SocksCommand2[SocksCommand2["connect"] = 1] = "connect";
  22032. SocksCommand2[SocksCommand2["bind"] = 2] = "bind";
  22033. SocksCommand2[SocksCommand2["associate"] = 3] = "associate";
  22034. })(SocksCommand || (exports2.SocksCommand = SocksCommand = {}));
  22035. var Socks4Response;
  22036. (function(Socks4Response2) {
  22037. Socks4Response2[Socks4Response2["Granted"] = 90] = "Granted";
  22038. Socks4Response2[Socks4Response2["Failed"] = 91] = "Failed";
  22039. Socks4Response2[Socks4Response2["Rejected"] = 92] = "Rejected";
  22040. Socks4Response2[Socks4Response2["RejectedIdent"] = 93] = "RejectedIdent";
  22041. })(Socks4Response || (exports2.Socks4Response = Socks4Response = {}));
  22042. var Socks5Auth;
  22043. (function(Socks5Auth2) {
  22044. Socks5Auth2[Socks5Auth2["NoAuth"] = 0] = "NoAuth";
  22045. Socks5Auth2[Socks5Auth2["GSSApi"] = 1] = "GSSApi";
  22046. Socks5Auth2[Socks5Auth2["UserPass"] = 2] = "UserPass";
  22047. })(Socks5Auth || (exports2.Socks5Auth = Socks5Auth = {}));
  22048. var SOCKS5_CUSTOM_AUTH_START = 128;
  22049. exports2.SOCKS5_CUSTOM_AUTH_START = SOCKS5_CUSTOM_AUTH_START;
  22050. var SOCKS5_CUSTOM_AUTH_END = 254;
  22051. exports2.SOCKS5_CUSTOM_AUTH_END = SOCKS5_CUSTOM_AUTH_END;
  22052. var SOCKS5_NO_ACCEPTABLE_AUTH = 255;
  22053. exports2.SOCKS5_NO_ACCEPTABLE_AUTH = SOCKS5_NO_ACCEPTABLE_AUTH;
  22054. var Socks5Response;
  22055. (function(Socks5Response2) {
  22056. Socks5Response2[Socks5Response2["Granted"] = 0] = "Granted";
  22057. Socks5Response2[Socks5Response2["Failure"] = 1] = "Failure";
  22058. Socks5Response2[Socks5Response2["NotAllowed"] = 2] = "NotAllowed";
  22059. Socks5Response2[Socks5Response2["NetworkUnreachable"] = 3] = "NetworkUnreachable";
  22060. Socks5Response2[Socks5Response2["HostUnreachable"] = 4] = "HostUnreachable";
  22061. Socks5Response2[Socks5Response2["ConnectionRefused"] = 5] = "ConnectionRefused";
  22062. Socks5Response2[Socks5Response2["TTLExpired"] = 6] = "TTLExpired";
  22063. Socks5Response2[Socks5Response2["CommandNotSupported"] = 7] = "CommandNotSupported";
  22064. Socks5Response2[Socks5Response2["AddressNotSupported"] = 8] = "AddressNotSupported";
  22065. })(Socks5Response || (exports2.Socks5Response = Socks5Response = {}));
  22066. var Socks5HostType;
  22067. (function(Socks5HostType2) {
  22068. Socks5HostType2[Socks5HostType2["IPv4"] = 1] = "IPv4";
  22069. Socks5HostType2[Socks5HostType2["Hostname"] = 3] = "Hostname";
  22070. Socks5HostType2[Socks5HostType2["IPv6"] = 4] = "IPv6";
  22071. })(Socks5HostType || (exports2.Socks5HostType = Socks5HostType = {}));
  22072. var SocksClientState;
  22073. (function(SocksClientState2) {
  22074. SocksClientState2[SocksClientState2["Created"] = 0] = "Created";
  22075. SocksClientState2[SocksClientState2["Connecting"] = 1] = "Connecting";
  22076. SocksClientState2[SocksClientState2["Connected"] = 2] = "Connected";
  22077. SocksClientState2[SocksClientState2["SentInitialHandshake"] = 3] = "SentInitialHandshake";
  22078. SocksClientState2[SocksClientState2["ReceivedInitialHandshakeResponse"] = 4] = "ReceivedInitialHandshakeResponse";
  22079. SocksClientState2[SocksClientState2["SentAuthentication"] = 5] = "SentAuthentication";
  22080. SocksClientState2[SocksClientState2["ReceivedAuthenticationResponse"] = 6] = "ReceivedAuthenticationResponse";
  22081. SocksClientState2[SocksClientState2["SentFinalHandshake"] = 7] = "SentFinalHandshake";
  22082. SocksClientState2[SocksClientState2["ReceivedFinalResponse"] = 8] = "ReceivedFinalResponse";
  22083. SocksClientState2[SocksClientState2["BoundWaitingForConnection"] = 9] = "BoundWaitingForConnection";
  22084. SocksClientState2[SocksClientState2["Established"] = 10] = "Established";
  22085. SocksClientState2[SocksClientState2["Disconnected"] = 11] = "Disconnected";
  22086. SocksClientState2[SocksClientState2["Error"] = 99] = "Error";
  22087. })(SocksClientState || (exports2.SocksClientState = SocksClientState = {}));
  22088. }
  22089. });
  22090. // node_modules/socks/build/common/util.js
  22091. var require_util = __commonJS({
  22092. "node_modules/socks/build/common/util.js"(exports2) {
  22093. "use strict";
  22094. Object.defineProperty(exports2, "__esModule", { value: true });
  22095. exports2.shuffleArray = exports2.SocksClientError = void 0;
  22096. var SocksClientError = class extends Error {
  22097. constructor(message, options) {
  22098. super(message);
  22099. this.options = options;
  22100. }
  22101. };
  22102. exports2.SocksClientError = SocksClientError;
  22103. function shuffleArray(array) {
  22104. for (let i = array.length - 1; i > 0; i--) {
  22105. const j = Math.floor(Math.random() * (i + 1));
  22106. [array[i], array[j]] = [array[j], array[i]];
  22107. }
  22108. }
  22109. exports2.shuffleArray = shuffleArray;
  22110. }
  22111. });
  22112. // node_modules/ip-address/dist/common.js
  22113. var require_common3 = __commonJS({
  22114. "node_modules/ip-address/dist/common.js"(exports2) {
  22115. "use strict";
  22116. Object.defineProperty(exports2, "__esModule", { value: true });
  22117. exports2.isCorrect = exports2.isInSubnet = void 0;
  22118. function isInSubnet(address) {
  22119. if (this.subnetMask < address.subnetMask) {
  22120. return false;
  22121. }
  22122. if (this.mask(address.subnetMask) === address.mask()) {
  22123. return true;
  22124. }
  22125. return false;
  22126. }
  22127. exports2.isInSubnet = isInSubnet;
  22128. function isCorrect(defaultBits) {
  22129. return function() {
  22130. if (this.addressMinusSuffix !== this.correctForm()) {
  22131. return false;
  22132. }
  22133. if (this.subnetMask === defaultBits && !this.parsedSubnet) {
  22134. return true;
  22135. }
  22136. return this.parsedSubnet === String(this.subnetMask);
  22137. };
  22138. }
  22139. exports2.isCorrect = isCorrect;
  22140. }
  22141. });
  22142. // node_modules/ip-address/dist/v4/constants.js
  22143. var require_constants4 = __commonJS({
  22144. "node_modules/ip-address/dist/v4/constants.js"(exports2) {
  22145. "use strict";
  22146. Object.defineProperty(exports2, "__esModule", { value: true });
  22147. exports2.RE_SUBNET_STRING = exports2.RE_ADDRESS = exports2.GROUPS = exports2.BITS = void 0;
  22148. exports2.BITS = 32;
  22149. exports2.GROUPS = 4;
  22150. exports2.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
  22151. exports2.RE_SUBNET_STRING = /\/\d{1,2}$/;
  22152. }
  22153. });
  22154. // node_modules/ip-address/dist/address-error.js
  22155. var require_address_error = __commonJS({
  22156. "node_modules/ip-address/dist/address-error.js"(exports2) {
  22157. "use strict";
  22158. Object.defineProperty(exports2, "__esModule", { value: true });
  22159. exports2.AddressError = void 0;
  22160. var AddressError = class extends Error {
  22161. constructor(message, parseMessage) {
  22162. super(message);
  22163. this.name = "AddressError";
  22164. if (parseMessage !== null) {
  22165. this.parseMessage = parseMessage;
  22166. }
  22167. }
  22168. };
  22169. exports2.AddressError = AddressError;
  22170. }
  22171. });
  22172. // node_modules/jsbn/index.js
  22173. var require_jsbn = __commonJS({
  22174. "node_modules/jsbn/index.js"(exports2, module2) {
  22175. (function() {
  22176. var dbits;
  22177. var canary = 244837814094590;
  22178. var j_lm = (canary & 16777215) == 15715070;
  22179. function BigInteger(a, b, c) {
  22180. if (a != null)
  22181. if ("number" == typeof a) this.fromNumber(a, b, c);
  22182. else if (b == null && "string" != typeof a) this.fromString(a, 256);
  22183. else this.fromString(a, b);
  22184. }
  22185. function nbi() {
  22186. return new BigInteger(null);
  22187. }
  22188. function am1(i, x, w, j, c, n) {
  22189. while (--n >= 0) {
  22190. var v = x * this[i++] + w[j] + c;
  22191. c = Math.floor(v / 67108864);
  22192. w[j++] = v & 67108863;
  22193. }
  22194. return c;
  22195. }
  22196. function am2(i, x, w, j, c, n) {
  22197. var xl = x & 32767, xh = x >> 15;
  22198. while (--n >= 0) {
  22199. var l = this[i] & 32767;
  22200. var h = this[i++] >> 15;
  22201. var m = xh * l + h * xl;
  22202. l = xl * l + ((m & 32767) << 15) + w[j] + (c & 1073741823);
  22203. c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
  22204. w[j++] = l & 1073741823;
  22205. }
  22206. return c;
  22207. }
  22208. function am3(i, x, w, j, c, n) {
  22209. var xl = x & 16383, xh = x >> 14;
  22210. while (--n >= 0) {
  22211. var l = this[i] & 16383;
  22212. var h = this[i++] >> 14;
  22213. var m = xh * l + h * xl;
  22214. l = xl * l + ((m & 16383) << 14) + w[j] + c;
  22215. c = (l >> 28) + (m >> 14) + xh * h;
  22216. w[j++] = l & 268435455;
  22217. }
  22218. return c;
  22219. }
  22220. var inBrowser = typeof navigator !== "undefined";
  22221. if (inBrowser && j_lm && navigator.appName == "Microsoft Internet Explorer") {
  22222. BigInteger.prototype.am = am2;
  22223. dbits = 30;
  22224. } else if (inBrowser && j_lm && navigator.appName != "Netscape") {
  22225. BigInteger.prototype.am = am1;
  22226. dbits = 26;
  22227. } else {
  22228. BigInteger.prototype.am = am3;
  22229. dbits = 28;
  22230. }
  22231. BigInteger.prototype.DB = dbits;
  22232. BigInteger.prototype.DM = (1 << dbits) - 1;
  22233. BigInteger.prototype.DV = 1 << dbits;
  22234. var BI_FP = 52;
  22235. BigInteger.prototype.FV = Math.pow(2, BI_FP);
  22236. BigInteger.prototype.F1 = BI_FP - dbits;
  22237. BigInteger.prototype.F2 = 2 * dbits - BI_FP;
  22238. var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
  22239. var BI_RC = new Array();
  22240. var rr, vv;
  22241. rr = "0".charCodeAt(0);
  22242. for (vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
  22243. rr = "a".charCodeAt(0);
  22244. for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  22245. rr = "A".charCodeAt(0);
  22246. for (vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
  22247. function int2char(n) {
  22248. return BI_RM.charAt(n);
  22249. }
  22250. function intAt(s, i) {
  22251. var c = BI_RC[s.charCodeAt(i)];
  22252. return c == null ? -1 : c;
  22253. }
  22254. function bnpCopyTo(r) {
  22255. for (var i = this.t - 1; i >= 0; --i) r[i] = this[i];
  22256. r.t = this.t;
  22257. r.s = this.s;
  22258. }
  22259. function bnpFromInt(x) {
  22260. this.t = 1;
  22261. this.s = x < 0 ? -1 : 0;
  22262. if (x > 0) this[0] = x;
  22263. else if (x < -1) this[0] = x + this.DV;
  22264. else this.t = 0;
  22265. }
  22266. function nbv(i) {
  22267. var r = nbi();
  22268. r.fromInt(i);
  22269. return r;
  22270. }
  22271. function bnpFromString(s, b) {
  22272. var k;
  22273. if (b == 16) k = 4;
  22274. else if (b == 8) k = 3;
  22275. else if (b == 256) k = 8;
  22276. else if (b == 2) k = 1;
  22277. else if (b == 32) k = 5;
  22278. else if (b == 4) k = 2;
  22279. else {
  22280. this.fromRadix(s, b);
  22281. return;
  22282. }
  22283. this.t = 0;
  22284. this.s = 0;
  22285. var i = s.length, mi = false, sh = 0;
  22286. while (--i >= 0) {
  22287. var x = k == 8 ? s[i] & 255 : intAt(s, i);
  22288. if (x < 0) {
  22289. if (s.charAt(i) == "-") mi = true;
  22290. continue;
  22291. }
  22292. mi = false;
  22293. if (sh == 0)
  22294. this[this.t++] = x;
  22295. else if (sh + k > this.DB) {
  22296. this[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh;
  22297. this[this.t++] = x >> this.DB - sh;
  22298. } else
  22299. this[this.t - 1] |= x << sh;
  22300. sh += k;
  22301. if (sh >= this.DB) sh -= this.DB;
  22302. }
  22303. if (k == 8 && (s[0] & 128) != 0) {
  22304. this.s = -1;
  22305. if (sh > 0) this[this.t - 1] |= (1 << this.DB - sh) - 1 << sh;
  22306. }
  22307. this.clamp();
  22308. if (mi) BigInteger.ZERO.subTo(this, this);
  22309. }
  22310. function bnpClamp() {
  22311. var c = this.s & this.DM;
  22312. while (this.t > 0 && this[this.t - 1] == c) --this.t;
  22313. }
  22314. function bnToString(b) {
  22315. if (this.s < 0) return "-" + this.negate().toString(b);
  22316. var k;
  22317. if (b == 16) k = 4;
  22318. else if (b == 8) k = 3;
  22319. else if (b == 2) k = 1;
  22320. else if (b == 32) k = 5;
  22321. else if (b == 4) k = 2;
  22322. else return this.toRadix(b);
  22323. var km = (1 << k) - 1, d, m = false, r = "", i = this.t;
  22324. var p = this.DB - i * this.DB % k;
  22325. if (i-- > 0) {
  22326. if (p < this.DB && (d = this[i] >> p) > 0) {
  22327. m = true;
  22328. r = int2char(d);
  22329. }
  22330. while (i >= 0) {
  22331. if (p < k) {
  22332. d = (this[i] & (1 << p) - 1) << k - p;
  22333. d |= this[--i] >> (p += this.DB - k);
  22334. } else {
  22335. d = this[i] >> (p -= k) & km;
  22336. if (p <= 0) {
  22337. p += this.DB;
  22338. --i;
  22339. }
  22340. }
  22341. if (d > 0) m = true;
  22342. if (m) r += int2char(d);
  22343. }
  22344. }
  22345. return m ? r : "0";
  22346. }
  22347. function bnNegate() {
  22348. var r = nbi();
  22349. BigInteger.ZERO.subTo(this, r);
  22350. return r;
  22351. }
  22352. function bnAbs() {
  22353. return this.s < 0 ? this.negate() : this;
  22354. }
  22355. function bnCompareTo(a) {
  22356. var r = this.s - a.s;
  22357. if (r != 0) return r;
  22358. var i = this.t;
  22359. r = i - a.t;
  22360. if (r != 0) return this.s < 0 ? -r : r;
  22361. while (--i >= 0) if ((r = this[i] - a[i]) != 0) return r;
  22362. return 0;
  22363. }
  22364. function nbits(x) {
  22365. var r = 1, t2;
  22366. if ((t2 = x >>> 16) != 0) {
  22367. x = t2;
  22368. r += 16;
  22369. }
  22370. if ((t2 = x >> 8) != 0) {
  22371. x = t2;
  22372. r += 8;
  22373. }
  22374. if ((t2 = x >> 4) != 0) {
  22375. x = t2;
  22376. r += 4;
  22377. }
  22378. if ((t2 = x >> 2) != 0) {
  22379. x = t2;
  22380. r += 2;
  22381. }
  22382. if ((t2 = x >> 1) != 0) {
  22383. x = t2;
  22384. r += 1;
  22385. }
  22386. return r;
  22387. }
  22388. function bnBitLength() {
  22389. if (this.t <= 0) return 0;
  22390. return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM);
  22391. }
  22392. function bnpDLShiftTo(n, r) {
  22393. var i;
  22394. for (i = this.t - 1; i >= 0; --i) r[i + n] = this[i];
  22395. for (i = n - 1; i >= 0; --i) r[i] = 0;
  22396. r.t = this.t + n;
  22397. r.s = this.s;
  22398. }
  22399. function bnpDRShiftTo(n, r) {
  22400. for (var i = n; i < this.t; ++i) r[i - n] = this[i];
  22401. r.t = Math.max(this.t - n, 0);
  22402. r.s = this.s;
  22403. }
  22404. function bnpLShiftTo(n, r) {
  22405. var bs = n % this.DB;
  22406. var cbs = this.DB - bs;
  22407. var bm = (1 << cbs) - 1;
  22408. var ds = Math.floor(n / this.DB), c = this.s << bs & this.DM, i;
  22409. for (i = this.t - 1; i >= 0; --i) {
  22410. r[i + ds + 1] = this[i] >> cbs | c;
  22411. c = (this[i] & bm) << bs;
  22412. }
  22413. for (i = ds - 1; i >= 0; --i) r[i] = 0;
  22414. r[ds] = c;
  22415. r.t = this.t + ds + 1;
  22416. r.s = this.s;
  22417. r.clamp();
  22418. }
  22419. function bnpRShiftTo(n, r) {
  22420. r.s = this.s;
  22421. var ds = Math.floor(n / this.DB);
  22422. if (ds >= this.t) {
  22423. r.t = 0;
  22424. return;
  22425. }
  22426. var bs = n % this.DB;
  22427. var cbs = this.DB - bs;
  22428. var bm = (1 << bs) - 1;
  22429. r[0] = this[ds] >> bs;
  22430. for (var i = ds + 1; i < this.t; ++i) {
  22431. r[i - ds - 1] |= (this[i] & bm) << cbs;
  22432. r[i - ds] = this[i] >> bs;
  22433. }
  22434. if (bs > 0) r[this.t - ds - 1] |= (this.s & bm) << cbs;
  22435. r.t = this.t - ds;
  22436. r.clamp();
  22437. }
  22438. function bnpSubTo(a, r) {
  22439. var i = 0, c = 0, m = Math.min(a.t, this.t);
  22440. while (i < m) {
  22441. c += this[i] - a[i];
  22442. r[i++] = c & this.DM;
  22443. c >>= this.DB;
  22444. }
  22445. if (a.t < this.t) {
  22446. c -= a.s;
  22447. while (i < this.t) {
  22448. c += this[i];
  22449. r[i++] = c & this.DM;
  22450. c >>= this.DB;
  22451. }
  22452. c += this.s;
  22453. } else {
  22454. c += this.s;
  22455. while (i < a.t) {
  22456. c -= a[i];
  22457. r[i++] = c & this.DM;
  22458. c >>= this.DB;
  22459. }
  22460. c -= a.s;
  22461. }
  22462. r.s = c < 0 ? -1 : 0;
  22463. if (c < -1) r[i++] = this.DV + c;
  22464. else if (c > 0) r[i++] = c;
  22465. r.t = i;
  22466. r.clamp();
  22467. }
  22468. function bnpMultiplyTo(a, r) {
  22469. var x = this.abs(), y = a.abs();
  22470. var i = x.t;
  22471. r.t = i + y.t;
  22472. while (--i >= 0) r[i] = 0;
  22473. for (i = 0; i < y.t; ++i) r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
  22474. r.s = 0;
  22475. r.clamp();
  22476. if (this.s != a.s) BigInteger.ZERO.subTo(r, r);
  22477. }
  22478. function bnpSquareTo(r) {
  22479. var x = this.abs();
  22480. var i = r.t = 2 * x.t;
  22481. while (--i >= 0) r[i] = 0;
  22482. for (i = 0; i < x.t - 1; ++i) {
  22483. var c = x.am(i, x[i], r, 2 * i, 0, 1);
  22484. if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
  22485. r[i + x.t] -= x.DV;
  22486. r[i + x.t + 1] = 1;
  22487. }
  22488. }
  22489. if (r.t > 0) r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
  22490. r.s = 0;
  22491. r.clamp();
  22492. }
  22493. function bnpDivRemTo(m, q, r) {
  22494. var pm = m.abs();
  22495. if (pm.t <= 0) return;
  22496. var pt = this.abs();
  22497. if (pt.t < pm.t) {
  22498. if (q != null) q.fromInt(0);
  22499. if (r != null) this.copyTo(r);
  22500. return;
  22501. }
  22502. if (r == null) r = nbi();
  22503. var y = nbi(), ts = this.s, ms = m.s;
  22504. var nsh = this.DB - nbits(pm[pm.t - 1]);
  22505. if (nsh > 0) {
  22506. pm.lShiftTo(nsh, y);
  22507. pt.lShiftTo(nsh, r);
  22508. } else {
  22509. pm.copyTo(y);
  22510. pt.copyTo(r);
  22511. }
  22512. var ys = y.t;
  22513. var y0 = y[ys - 1];
  22514. if (y0 == 0) return;
  22515. var yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0);
  22516. var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2;
  22517. var i = r.t, j = i - ys, t2 = q == null ? nbi() : q;
  22518. y.dlShiftTo(j, t2);
  22519. if (r.compareTo(t2) >= 0) {
  22520. r[r.t++] = 1;
  22521. r.subTo(t2, r);
  22522. }
  22523. BigInteger.ONE.dlShiftTo(ys, t2);
  22524. t2.subTo(y, y);
  22525. while (y.t < ys) y[y.t++] = 0;
  22526. while (--j >= 0) {
  22527. var qd = r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
  22528. if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) {
  22529. y.dlShiftTo(j, t2);
  22530. r.subTo(t2, r);
  22531. while (r[i] < --qd) r.subTo(t2, r);
  22532. }
  22533. }
  22534. if (q != null) {
  22535. r.drShiftTo(ys, q);
  22536. if (ts != ms) BigInteger.ZERO.subTo(q, q);
  22537. }
  22538. r.t = ys;
  22539. r.clamp();
  22540. if (nsh > 0) r.rShiftTo(nsh, r);
  22541. if (ts < 0) BigInteger.ZERO.subTo(r, r);
  22542. }
  22543. function bnMod(a) {
  22544. var r = nbi();
  22545. this.abs().divRemTo(a, null, r);
  22546. if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r, r);
  22547. return r;
  22548. }
  22549. function Classic(m) {
  22550. this.m = m;
  22551. }
  22552. function cConvert(x) {
  22553. if (x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
  22554. else return x;
  22555. }
  22556. function cRevert(x) {
  22557. return x;
  22558. }
  22559. function cReduce(x) {
  22560. x.divRemTo(this.m, null, x);
  22561. }
  22562. function cMulTo(x, y, r) {
  22563. x.multiplyTo(y, r);
  22564. this.reduce(r);
  22565. }
  22566. function cSqrTo(x, r) {
  22567. x.squareTo(r);
  22568. this.reduce(r);
  22569. }
  22570. Classic.prototype.convert = cConvert;
  22571. Classic.prototype.revert = cRevert;
  22572. Classic.prototype.reduce = cReduce;
  22573. Classic.prototype.mulTo = cMulTo;
  22574. Classic.prototype.sqrTo = cSqrTo;
  22575. function bnpInvDigit() {
  22576. if (this.t < 1) return 0;
  22577. var x = this[0];
  22578. if ((x & 1) == 0) return 0;
  22579. var y = x & 3;
  22580. y = y * (2 - (x & 15) * y) & 15;
  22581. y = y * (2 - (x & 255) * y) & 255;
  22582. y = y * (2 - ((x & 65535) * y & 65535)) & 65535;
  22583. y = y * (2 - x * y % this.DV) % this.DV;
  22584. return y > 0 ? this.DV - y : -y;
  22585. }
  22586. function Montgomery(m) {
  22587. this.m = m;
  22588. this.mp = m.invDigit();
  22589. this.mpl = this.mp & 32767;
  22590. this.mph = this.mp >> 15;
  22591. this.um = (1 << m.DB - 15) - 1;
  22592. this.mt2 = 2 * m.t;
  22593. }
  22594. function montConvert(x) {
  22595. var r = nbi();
  22596. x.abs().dlShiftTo(this.m.t, r);
  22597. r.divRemTo(this.m, null, r);
  22598. if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r, r);
  22599. return r;
  22600. }
  22601. function montRevert(x) {
  22602. var r = nbi();
  22603. x.copyTo(r);
  22604. this.reduce(r);
  22605. return r;
  22606. }
  22607. function montReduce(x) {
  22608. while (x.t <= this.mt2)
  22609. x[x.t++] = 0;
  22610. for (var i = 0; i < this.m.t; ++i) {
  22611. var j = x[i] & 32767;
  22612. var u0 = j * this.mpl + ((j * this.mph + (x[i] >> 15) * this.mpl & this.um) << 15) & x.DM;
  22613. j = i + this.m.t;
  22614. x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
  22615. while (x[j] >= x.DV) {
  22616. x[j] -= x.DV;
  22617. x[++j]++;
  22618. }
  22619. }
  22620. x.clamp();
  22621. x.drShiftTo(this.m.t, x);
  22622. if (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
  22623. }
  22624. function montSqrTo(x, r) {
  22625. x.squareTo(r);
  22626. this.reduce(r);
  22627. }
  22628. function montMulTo(x, y, r) {
  22629. x.multiplyTo(y, r);
  22630. this.reduce(r);
  22631. }
  22632. Montgomery.prototype.convert = montConvert;
  22633. Montgomery.prototype.revert = montRevert;
  22634. Montgomery.prototype.reduce = montReduce;
  22635. Montgomery.prototype.mulTo = montMulTo;
  22636. Montgomery.prototype.sqrTo = montSqrTo;
  22637. function bnpIsEven() {
  22638. return (this.t > 0 ? this[0] & 1 : this.s) == 0;
  22639. }
  22640. function bnpExp(e, z2) {
  22641. if (e > 4294967295 || e < 1) return BigInteger.ONE;
  22642. var r = nbi(), r2 = nbi(), g = z2.convert(this), i = nbits(e) - 1;
  22643. g.copyTo(r);
  22644. while (--i >= 0) {
  22645. z2.sqrTo(r, r2);
  22646. if ((e & 1 << i) > 0) z2.mulTo(r2, g, r);
  22647. else {
  22648. var t2 = r;
  22649. r = r2;
  22650. r2 = t2;
  22651. }
  22652. }
  22653. return z2.revert(r);
  22654. }
  22655. function bnModPowInt(e, m) {
  22656. var z2;
  22657. if (e < 256 || m.isEven()) z2 = new Classic(m);
  22658. else z2 = new Montgomery(m);
  22659. return this.exp(e, z2);
  22660. }
  22661. BigInteger.prototype.copyTo = bnpCopyTo;
  22662. BigInteger.prototype.fromInt = bnpFromInt;
  22663. BigInteger.prototype.fromString = bnpFromString;
  22664. BigInteger.prototype.clamp = bnpClamp;
  22665. BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
  22666. BigInteger.prototype.drShiftTo = bnpDRShiftTo;
  22667. BigInteger.prototype.lShiftTo = bnpLShiftTo;
  22668. BigInteger.prototype.rShiftTo = bnpRShiftTo;
  22669. BigInteger.prototype.subTo = bnpSubTo;
  22670. BigInteger.prototype.multiplyTo = bnpMultiplyTo;
  22671. BigInteger.prototype.squareTo = bnpSquareTo;
  22672. BigInteger.prototype.divRemTo = bnpDivRemTo;
  22673. BigInteger.prototype.invDigit = bnpInvDigit;
  22674. BigInteger.prototype.isEven = bnpIsEven;
  22675. BigInteger.prototype.exp = bnpExp;
  22676. BigInteger.prototype.toString = bnToString;
  22677. BigInteger.prototype.negate = bnNegate;
  22678. BigInteger.prototype.abs = bnAbs;
  22679. BigInteger.prototype.compareTo = bnCompareTo;
  22680. BigInteger.prototype.bitLength = bnBitLength;
  22681. BigInteger.prototype.mod = bnMod;
  22682. BigInteger.prototype.modPowInt = bnModPowInt;
  22683. BigInteger.ZERO = nbv(0);
  22684. BigInteger.ONE = nbv(1);
  22685. function bnClone() {
  22686. var r = nbi();
  22687. this.copyTo(r);
  22688. return r;
  22689. }
  22690. function bnIntValue() {
  22691. if (this.s < 0) {
  22692. if (this.t == 1) return this[0] - this.DV;
  22693. else if (this.t == 0) return -1;
  22694. } else if (this.t == 1) return this[0];
  22695. else if (this.t == 0) return 0;
  22696. return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0];
  22697. }
  22698. function bnByteValue() {
  22699. return this.t == 0 ? this.s : this[0] << 24 >> 24;
  22700. }
  22701. function bnShortValue() {
  22702. return this.t == 0 ? this.s : this[0] << 16 >> 16;
  22703. }
  22704. function bnpChunkSize(r) {
  22705. return Math.floor(Math.LN2 * this.DB / Math.log(r));
  22706. }
  22707. function bnSigNum() {
  22708. if (this.s < 0) return -1;
  22709. else if (this.t <= 0 || this.t == 1 && this[0] <= 0) return 0;
  22710. else return 1;
  22711. }
  22712. function bnpToRadix(b) {
  22713. if (b == null) b = 10;
  22714. if (this.signum() == 0 || b < 2 || b > 36) return "0";
  22715. var cs = this.chunkSize(b);
  22716. var a = Math.pow(b, cs);
  22717. var d = nbv(a), y = nbi(), z2 = nbi(), r = "";
  22718. this.divRemTo(d, y, z2);
  22719. while (y.signum() > 0) {
  22720. r = (a + z2.intValue()).toString(b).substr(1) + r;
  22721. y.divRemTo(d, y, z2);
  22722. }
  22723. return z2.intValue().toString(b) + r;
  22724. }
  22725. function bnpFromRadix(s, b) {
  22726. this.fromInt(0);
  22727. if (b == null) b = 10;
  22728. var cs = this.chunkSize(b);
  22729. var d = Math.pow(b, cs), mi = false, j = 0, w = 0;
  22730. for (var i = 0; i < s.length; ++i) {
  22731. var x = intAt(s, i);
  22732. if (x < 0) {
  22733. if (s.charAt(i) == "-" && this.signum() == 0) mi = true;
  22734. continue;
  22735. }
  22736. w = b * w + x;
  22737. if (++j >= cs) {
  22738. this.dMultiply(d);
  22739. this.dAddOffset(w, 0);
  22740. j = 0;
  22741. w = 0;
  22742. }
  22743. }
  22744. if (j > 0) {
  22745. this.dMultiply(Math.pow(b, j));
  22746. this.dAddOffset(w, 0);
  22747. }
  22748. if (mi) BigInteger.ZERO.subTo(this, this);
  22749. }
  22750. function bnpFromNumber(a, b, c) {
  22751. if ("number" == typeof b) {
  22752. if (a < 2) this.fromInt(1);
  22753. else {
  22754. this.fromNumber(a, c);
  22755. if (!this.testBit(a - 1))
  22756. this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
  22757. if (this.isEven()) this.dAddOffset(1, 0);
  22758. while (!this.isProbablePrime(b)) {
  22759. this.dAddOffset(2, 0);
  22760. if (this.bitLength() > a) this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
  22761. }
  22762. }
  22763. } else {
  22764. var x = new Array(), t2 = a & 7;
  22765. x.length = (a >> 3) + 1;
  22766. b.nextBytes(x);
  22767. if (t2 > 0) x[0] &= (1 << t2) - 1;
  22768. else x[0] = 0;
  22769. this.fromString(x, 256);
  22770. }
  22771. }
  22772. function bnToByteArray() {
  22773. var i = this.t, r = new Array();
  22774. r[0] = this.s;
  22775. var p = this.DB - i * this.DB % 8, d, k = 0;
  22776. if (i-- > 0) {
  22777. if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p)
  22778. r[k++] = d | this.s << this.DB - p;
  22779. while (i >= 0) {
  22780. if (p < 8) {
  22781. d = (this[i] & (1 << p) - 1) << 8 - p;
  22782. d |= this[--i] >> (p += this.DB - 8);
  22783. } else {
  22784. d = this[i] >> (p -= 8) & 255;
  22785. if (p <= 0) {
  22786. p += this.DB;
  22787. --i;
  22788. }
  22789. }
  22790. if ((d & 128) != 0) d |= -256;
  22791. if (k == 0 && (this.s & 128) != (d & 128)) ++k;
  22792. if (k > 0 || d != this.s) r[k++] = d;
  22793. }
  22794. }
  22795. return r;
  22796. }
  22797. function bnEquals(a) {
  22798. return this.compareTo(a) == 0;
  22799. }
  22800. function bnMin(a) {
  22801. return this.compareTo(a) < 0 ? this : a;
  22802. }
  22803. function bnMax(a) {
  22804. return this.compareTo(a) > 0 ? this : a;
  22805. }
  22806. function bnpBitwiseTo(a, op, r) {
  22807. var i, f, m = Math.min(a.t, this.t);
  22808. for (i = 0; i < m; ++i) r[i] = op(this[i], a[i]);
  22809. if (a.t < this.t) {
  22810. f = a.s & this.DM;
  22811. for (i = m; i < this.t; ++i) r[i] = op(this[i], f);
  22812. r.t = this.t;
  22813. } else {
  22814. f = this.s & this.DM;
  22815. for (i = m; i < a.t; ++i) r[i] = op(f, a[i]);
  22816. r.t = a.t;
  22817. }
  22818. r.s = op(this.s, a.s);
  22819. r.clamp();
  22820. }
  22821. function op_and(x, y) {
  22822. return x & y;
  22823. }
  22824. function bnAnd(a) {
  22825. var r = nbi();
  22826. this.bitwiseTo(a, op_and, r);
  22827. return r;
  22828. }
  22829. function op_or(x, y) {
  22830. return x | y;
  22831. }
  22832. function bnOr(a) {
  22833. var r = nbi();
  22834. this.bitwiseTo(a, op_or, r);
  22835. return r;
  22836. }
  22837. function op_xor(x, y) {
  22838. return x ^ y;
  22839. }
  22840. function bnXor(a) {
  22841. var r = nbi();
  22842. this.bitwiseTo(a, op_xor, r);
  22843. return r;
  22844. }
  22845. function op_andnot(x, y) {
  22846. return x & ~y;
  22847. }
  22848. function bnAndNot(a) {
  22849. var r = nbi();
  22850. this.bitwiseTo(a, op_andnot, r);
  22851. return r;
  22852. }
  22853. function bnNot() {
  22854. var r = nbi();
  22855. for (var i = 0; i < this.t; ++i) r[i] = this.DM & ~this[i];
  22856. r.t = this.t;
  22857. r.s = ~this.s;
  22858. return r;
  22859. }
  22860. function bnShiftLeft(n) {
  22861. var r = nbi();
  22862. if (n < 0) this.rShiftTo(-n, r);
  22863. else this.lShiftTo(n, r);
  22864. return r;
  22865. }
  22866. function bnShiftRight(n) {
  22867. var r = nbi();
  22868. if (n < 0) this.lShiftTo(-n, r);
  22869. else this.rShiftTo(n, r);
  22870. return r;
  22871. }
  22872. function lbit(x) {
  22873. if (x == 0) return -1;
  22874. var r = 0;
  22875. if ((x & 65535) == 0) {
  22876. x >>= 16;
  22877. r += 16;
  22878. }
  22879. if ((x & 255) == 0) {
  22880. x >>= 8;
  22881. r += 8;
  22882. }
  22883. if ((x & 15) == 0) {
  22884. x >>= 4;
  22885. r += 4;
  22886. }
  22887. if ((x & 3) == 0) {
  22888. x >>= 2;
  22889. r += 2;
  22890. }
  22891. if ((x & 1) == 0) ++r;
  22892. return r;
  22893. }
  22894. function bnGetLowestSetBit() {
  22895. for (var i = 0; i < this.t; ++i)
  22896. if (this[i] != 0) return i * this.DB + lbit(this[i]);
  22897. if (this.s < 0) return this.t * this.DB;
  22898. return -1;
  22899. }
  22900. function cbit(x) {
  22901. var r = 0;
  22902. while (x != 0) {
  22903. x &= x - 1;
  22904. ++r;
  22905. }
  22906. return r;
  22907. }
  22908. function bnBitCount() {
  22909. var r = 0, x = this.s & this.DM;
  22910. for (var i = 0; i < this.t; ++i) r += cbit(this[i] ^ x);
  22911. return r;
  22912. }
  22913. function bnTestBit(n) {
  22914. var j = Math.floor(n / this.DB);
  22915. if (j >= this.t) return this.s != 0;
  22916. return (this[j] & 1 << n % this.DB) != 0;
  22917. }
  22918. function bnpChangeBit(n, op) {
  22919. var r = BigInteger.ONE.shiftLeft(n);
  22920. this.bitwiseTo(r, op, r);
  22921. return r;
  22922. }
  22923. function bnSetBit(n) {
  22924. return this.changeBit(n, op_or);
  22925. }
  22926. function bnClearBit(n) {
  22927. return this.changeBit(n, op_andnot);
  22928. }
  22929. function bnFlipBit(n) {
  22930. return this.changeBit(n, op_xor);
  22931. }
  22932. function bnpAddTo(a, r) {
  22933. var i = 0, c = 0, m = Math.min(a.t, this.t);
  22934. while (i < m) {
  22935. c += this[i] + a[i];
  22936. r[i++] = c & this.DM;
  22937. c >>= this.DB;
  22938. }
  22939. if (a.t < this.t) {
  22940. c += a.s;
  22941. while (i < this.t) {
  22942. c += this[i];
  22943. r[i++] = c & this.DM;
  22944. c >>= this.DB;
  22945. }
  22946. c += this.s;
  22947. } else {
  22948. c += this.s;
  22949. while (i < a.t) {
  22950. c += a[i];
  22951. r[i++] = c & this.DM;
  22952. c >>= this.DB;
  22953. }
  22954. c += a.s;
  22955. }
  22956. r.s = c < 0 ? -1 : 0;
  22957. if (c > 0) r[i++] = c;
  22958. else if (c < -1) r[i++] = this.DV + c;
  22959. r.t = i;
  22960. r.clamp();
  22961. }
  22962. function bnAdd(a) {
  22963. var r = nbi();
  22964. this.addTo(a, r);
  22965. return r;
  22966. }
  22967. function bnSubtract(a) {
  22968. var r = nbi();
  22969. this.subTo(a, r);
  22970. return r;
  22971. }
  22972. function bnMultiply(a) {
  22973. var r = nbi();
  22974. this.multiplyTo(a, r);
  22975. return r;
  22976. }
  22977. function bnSquare() {
  22978. var r = nbi();
  22979. this.squareTo(r);
  22980. return r;
  22981. }
  22982. function bnDivide(a) {
  22983. var r = nbi();
  22984. this.divRemTo(a, r, null);
  22985. return r;
  22986. }
  22987. function bnRemainder(a) {
  22988. var r = nbi();
  22989. this.divRemTo(a, null, r);
  22990. return r;
  22991. }
  22992. function bnDivideAndRemainder(a) {
  22993. var q = nbi(), r = nbi();
  22994. this.divRemTo(a, q, r);
  22995. return new Array(q, r);
  22996. }
  22997. function bnpDMultiply(n) {
  22998. this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
  22999. ++this.t;
  23000. this.clamp();
  23001. }
  23002. function bnpDAddOffset(n, w) {
  23003. if (n == 0) return;
  23004. while (this.t <= w) this[this.t++] = 0;
  23005. this[w] += n;
  23006. while (this[w] >= this.DV) {
  23007. this[w] -= this.DV;
  23008. if (++w >= this.t) this[this.t++] = 0;
  23009. ++this[w];
  23010. }
  23011. }
  23012. function NullExp() {
  23013. }
  23014. function nNop(x) {
  23015. return x;
  23016. }
  23017. function nMulTo(x, y, r) {
  23018. x.multiplyTo(y, r);
  23019. }
  23020. function nSqrTo(x, r) {
  23021. x.squareTo(r);
  23022. }
  23023. NullExp.prototype.convert = nNop;
  23024. NullExp.prototype.revert = nNop;
  23025. NullExp.prototype.mulTo = nMulTo;
  23026. NullExp.prototype.sqrTo = nSqrTo;
  23027. function bnPow(e) {
  23028. return this.exp(e, new NullExp());
  23029. }
  23030. function bnpMultiplyLowerTo(a, n, r) {
  23031. var i = Math.min(this.t + a.t, n);
  23032. r.s = 0;
  23033. r.t = i;
  23034. while (i > 0) r[--i] = 0;
  23035. var j;
  23036. for (j = r.t - this.t; i < j; ++i) r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
  23037. for (j = Math.min(a.t, n); i < j; ++i) this.am(0, a[i], r, i, 0, n - i);
  23038. r.clamp();
  23039. }
  23040. function bnpMultiplyUpperTo(a, n, r) {
  23041. --n;
  23042. var i = r.t = this.t + a.t - n;
  23043. r.s = 0;
  23044. while (--i >= 0) r[i] = 0;
  23045. for (i = Math.max(n - this.t, 0); i < a.t; ++i)
  23046. r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
  23047. r.clamp();
  23048. r.drShiftTo(1, r);
  23049. }
  23050. function Barrett(m) {
  23051. this.r2 = nbi();
  23052. this.q3 = nbi();
  23053. BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
  23054. this.mu = this.r2.divide(m);
  23055. this.m = m;
  23056. }
  23057. function barrettConvert(x) {
  23058. if (x.s < 0 || x.t > 2 * this.m.t) return x.mod(this.m);
  23059. else if (x.compareTo(this.m) < 0) return x;
  23060. else {
  23061. var r = nbi();
  23062. x.copyTo(r);
  23063. this.reduce(r);
  23064. return r;
  23065. }
  23066. }
  23067. function barrettRevert(x) {
  23068. return x;
  23069. }
  23070. function barrettReduce(x) {
  23071. x.drShiftTo(this.m.t - 1, this.r2);
  23072. if (x.t > this.m.t + 1) {
  23073. x.t = this.m.t + 1;
  23074. x.clamp();
  23075. }
  23076. this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
  23077. this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
  23078. while (x.compareTo(this.r2) < 0) x.dAddOffset(1, this.m.t + 1);
  23079. x.subTo(this.r2, x);
  23080. while (x.compareTo(this.m) >= 0) x.subTo(this.m, x);
  23081. }
  23082. function barrettSqrTo(x, r) {
  23083. x.squareTo(r);
  23084. this.reduce(r);
  23085. }
  23086. function barrettMulTo(x, y, r) {
  23087. x.multiplyTo(y, r);
  23088. this.reduce(r);
  23089. }
  23090. Barrett.prototype.convert = barrettConvert;
  23091. Barrett.prototype.revert = barrettRevert;
  23092. Barrett.prototype.reduce = barrettReduce;
  23093. Barrett.prototype.mulTo = barrettMulTo;
  23094. Barrett.prototype.sqrTo = barrettSqrTo;
  23095. function bnModPow(e, m) {
  23096. var i = e.bitLength(), k, r = nbv(1), z2;
  23097. if (i <= 0) return r;
  23098. else if (i < 18) k = 1;
  23099. else if (i < 48) k = 3;
  23100. else if (i < 144) k = 4;
  23101. else if (i < 768) k = 5;
  23102. else k = 6;
  23103. if (i < 8)
  23104. z2 = new Classic(m);
  23105. else if (m.isEven())
  23106. z2 = new Barrett(m);
  23107. else
  23108. z2 = new Montgomery(m);
  23109. var g = new Array(), n = 3, k1 = k - 1, km = (1 << k) - 1;
  23110. g[1] = z2.convert(this);
  23111. if (k > 1) {
  23112. var g2 = nbi();
  23113. z2.sqrTo(g[1], g2);
  23114. while (n <= km) {
  23115. g[n] = nbi();
  23116. z2.mulTo(g2, g[n - 2], g[n]);
  23117. n += 2;
  23118. }
  23119. }
  23120. var j = e.t - 1, w, is1 = true, r2 = nbi(), t2;
  23121. i = nbits(e[j]) - 1;
  23122. while (j >= 0) {
  23123. if (i >= k1) w = e[j] >> i - k1 & km;
  23124. else {
  23125. w = (e[j] & (1 << i + 1) - 1) << k1 - i;
  23126. if (j > 0) w |= e[j - 1] >> this.DB + i - k1;
  23127. }
  23128. n = k;
  23129. while ((w & 1) == 0) {
  23130. w >>= 1;
  23131. --n;
  23132. }
  23133. if ((i -= n) < 0) {
  23134. i += this.DB;
  23135. --j;
  23136. }
  23137. if (is1) {
  23138. g[w].copyTo(r);
  23139. is1 = false;
  23140. } else {
  23141. while (n > 1) {
  23142. z2.sqrTo(r, r2);
  23143. z2.sqrTo(r2, r);
  23144. n -= 2;
  23145. }
  23146. if (n > 0) z2.sqrTo(r, r2);
  23147. else {
  23148. t2 = r;
  23149. r = r2;
  23150. r2 = t2;
  23151. }
  23152. z2.mulTo(r2, g[w], r);
  23153. }
  23154. while (j >= 0 && (e[j] & 1 << i) == 0) {
  23155. z2.sqrTo(r, r2);
  23156. t2 = r;
  23157. r = r2;
  23158. r2 = t2;
  23159. if (--i < 0) {
  23160. i = this.DB - 1;
  23161. --j;
  23162. }
  23163. }
  23164. }
  23165. return z2.revert(r);
  23166. }
  23167. function bnGCD(a) {
  23168. var x = this.s < 0 ? this.negate() : this.clone();
  23169. var y = a.s < 0 ? a.negate() : a.clone();
  23170. if (x.compareTo(y) < 0) {
  23171. var t2 = x;
  23172. x = y;
  23173. y = t2;
  23174. }
  23175. var i = x.getLowestSetBit(), g = y.getLowestSetBit();
  23176. if (g < 0) return x;
  23177. if (i < g) g = i;
  23178. if (g > 0) {
  23179. x.rShiftTo(g, x);
  23180. y.rShiftTo(g, y);
  23181. }
  23182. while (x.signum() > 0) {
  23183. if ((i = x.getLowestSetBit()) > 0) x.rShiftTo(i, x);
  23184. if ((i = y.getLowestSetBit()) > 0) y.rShiftTo(i, y);
  23185. if (x.compareTo(y) >= 0) {
  23186. x.subTo(y, x);
  23187. x.rShiftTo(1, x);
  23188. } else {
  23189. y.subTo(x, y);
  23190. y.rShiftTo(1, y);
  23191. }
  23192. }
  23193. if (g > 0) y.lShiftTo(g, y);
  23194. return y;
  23195. }
  23196. function bnpModInt(n) {
  23197. if (n <= 0) return 0;
  23198. var d = this.DV % n, r = this.s < 0 ? n - 1 : 0;
  23199. if (this.t > 0)
  23200. if (d == 0) r = this[0] % n;
  23201. else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n;
  23202. return r;
  23203. }
  23204. function bnModInverse(m) {
  23205. var ac = m.isEven();
  23206. if (this.isEven() && ac || m.signum() == 0) return BigInteger.ZERO;
  23207. var u = m.clone(), v = this.clone();
  23208. var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
  23209. while (u.signum() != 0) {
  23210. while (u.isEven()) {
  23211. u.rShiftTo(1, u);
  23212. if (ac) {
  23213. if (!a.isEven() || !b.isEven()) {
  23214. a.addTo(this, a);
  23215. b.subTo(m, b);
  23216. }
  23217. a.rShiftTo(1, a);
  23218. } else if (!b.isEven()) b.subTo(m, b);
  23219. b.rShiftTo(1, b);
  23220. }
  23221. while (v.isEven()) {
  23222. v.rShiftTo(1, v);
  23223. if (ac) {
  23224. if (!c.isEven() || !d.isEven()) {
  23225. c.addTo(this, c);
  23226. d.subTo(m, d);
  23227. }
  23228. c.rShiftTo(1, c);
  23229. } else if (!d.isEven()) d.subTo(m, d);
  23230. d.rShiftTo(1, d);
  23231. }
  23232. if (u.compareTo(v) >= 0) {
  23233. u.subTo(v, u);
  23234. if (ac) a.subTo(c, a);
  23235. b.subTo(d, b);
  23236. } else {
  23237. v.subTo(u, v);
  23238. if (ac) c.subTo(a, c);
  23239. d.subTo(b, d);
  23240. }
  23241. }
  23242. if (v.compareTo(BigInteger.ONE) != 0) return BigInteger.ZERO;
  23243. if (d.compareTo(m) >= 0) return d.subtract(m);
  23244. if (d.signum() < 0) d.addTo(m, d);
  23245. else return d;
  23246. if (d.signum() < 0) return d.add(m);
  23247. else return d;
  23248. }
  23249. var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
  23250. var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
  23251. function bnIsProbablePrime(t2) {
  23252. var i, x = this.abs();
  23253. if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
  23254. for (i = 0; i < lowprimes.length; ++i)
  23255. if (x[0] == lowprimes[i]) return true;
  23256. return false;
  23257. }
  23258. if (x.isEven()) return false;
  23259. i = 1;
  23260. while (i < lowprimes.length) {
  23261. var m = lowprimes[i], j = i + 1;
  23262. while (j < lowprimes.length && m < lplim) m *= lowprimes[j++];
  23263. m = x.modInt(m);
  23264. while (i < j) if (m % lowprimes[i++] == 0) return false;
  23265. }
  23266. return x.millerRabin(t2);
  23267. }
  23268. function bnpMillerRabin(t2) {
  23269. var n1 = this.subtract(BigInteger.ONE);
  23270. var k = n1.getLowestSetBit();
  23271. if (k <= 0) return false;
  23272. var r = n1.shiftRight(k);
  23273. t2 = t2 + 1 >> 1;
  23274. if (t2 > lowprimes.length) t2 = lowprimes.length;
  23275. var a = nbi();
  23276. for (var i = 0; i < t2; ++i) {
  23277. a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
  23278. var y = a.modPow(r, this);
  23279. if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
  23280. var j = 1;
  23281. while (j++ < k && y.compareTo(n1) != 0) {
  23282. y = y.modPowInt(2, this);
  23283. if (y.compareTo(BigInteger.ONE) == 0) return false;
  23284. }
  23285. if (y.compareTo(n1) != 0) return false;
  23286. }
  23287. }
  23288. return true;
  23289. }
  23290. BigInteger.prototype.chunkSize = bnpChunkSize;
  23291. BigInteger.prototype.toRadix = bnpToRadix;
  23292. BigInteger.prototype.fromRadix = bnpFromRadix;
  23293. BigInteger.prototype.fromNumber = bnpFromNumber;
  23294. BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
  23295. BigInteger.prototype.changeBit = bnpChangeBit;
  23296. BigInteger.prototype.addTo = bnpAddTo;
  23297. BigInteger.prototype.dMultiply = bnpDMultiply;
  23298. BigInteger.prototype.dAddOffset = bnpDAddOffset;
  23299. BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
  23300. BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
  23301. BigInteger.prototype.modInt = bnpModInt;
  23302. BigInteger.prototype.millerRabin = bnpMillerRabin;
  23303. BigInteger.prototype.clone = bnClone;
  23304. BigInteger.prototype.intValue = bnIntValue;
  23305. BigInteger.prototype.byteValue = bnByteValue;
  23306. BigInteger.prototype.shortValue = bnShortValue;
  23307. BigInteger.prototype.signum = bnSigNum;
  23308. BigInteger.prototype.toByteArray = bnToByteArray;
  23309. BigInteger.prototype.equals = bnEquals;
  23310. BigInteger.prototype.min = bnMin;
  23311. BigInteger.prototype.max = bnMax;
  23312. BigInteger.prototype.and = bnAnd;
  23313. BigInteger.prototype.or = bnOr;
  23314. BigInteger.prototype.xor = bnXor;
  23315. BigInteger.prototype.andNot = bnAndNot;
  23316. BigInteger.prototype.not = bnNot;
  23317. BigInteger.prototype.shiftLeft = bnShiftLeft;
  23318. BigInteger.prototype.shiftRight = bnShiftRight;
  23319. BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
  23320. BigInteger.prototype.bitCount = bnBitCount;
  23321. BigInteger.prototype.testBit = bnTestBit;
  23322. BigInteger.prototype.setBit = bnSetBit;
  23323. BigInteger.prototype.clearBit = bnClearBit;
  23324. BigInteger.prototype.flipBit = bnFlipBit;
  23325. BigInteger.prototype.add = bnAdd;
  23326. BigInteger.prototype.subtract = bnSubtract;
  23327. BigInteger.prototype.multiply = bnMultiply;
  23328. BigInteger.prototype.divide = bnDivide;
  23329. BigInteger.prototype.remainder = bnRemainder;
  23330. BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
  23331. BigInteger.prototype.modPow = bnModPow;
  23332. BigInteger.prototype.modInverse = bnModInverse;
  23333. BigInteger.prototype.pow = bnPow;
  23334. BigInteger.prototype.gcd = bnGCD;
  23335. BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
  23336. BigInteger.prototype.square = bnSquare;
  23337. BigInteger.prototype.Barrett = Barrett;
  23338. var rng_state;
  23339. var rng_pool;
  23340. var rng_pptr;
  23341. function rng_seed_int(x) {
  23342. rng_pool[rng_pptr++] ^= x & 255;
  23343. rng_pool[rng_pptr++] ^= x >> 8 & 255;
  23344. rng_pool[rng_pptr++] ^= x >> 16 & 255;
  23345. rng_pool[rng_pptr++] ^= x >> 24 & 255;
  23346. if (rng_pptr >= rng_psize) rng_pptr -= rng_psize;
  23347. }
  23348. function rng_seed_time() {
  23349. rng_seed_int((/* @__PURE__ */ new Date()).getTime());
  23350. }
  23351. if (rng_pool == null) {
  23352. rng_pool = new Array();
  23353. rng_pptr = 0;
  23354. var t;
  23355. if (typeof window !== "undefined" && window.crypto) {
  23356. if (window.crypto.getRandomValues) {
  23357. var ua = new Uint8Array(32);
  23358. window.crypto.getRandomValues(ua);
  23359. for (t = 0; t < 32; ++t)
  23360. rng_pool[rng_pptr++] = ua[t];
  23361. } else if (navigator.appName == "Netscape" && navigator.appVersion < "5") {
  23362. var z = window.crypto.random(32);
  23363. for (t = 0; t < z.length; ++t)
  23364. rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
  23365. }
  23366. }
  23367. while (rng_pptr < rng_psize) {
  23368. t = Math.floor(65536 * Math.random());
  23369. rng_pool[rng_pptr++] = t >>> 8;
  23370. rng_pool[rng_pptr++] = t & 255;
  23371. }
  23372. rng_pptr = 0;
  23373. rng_seed_time();
  23374. }
  23375. function rng_get_byte() {
  23376. if (rng_state == null) {
  23377. rng_seed_time();
  23378. rng_state = prng_newstate();
  23379. rng_state.init(rng_pool);
  23380. for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
  23381. rng_pool[rng_pptr] = 0;
  23382. rng_pptr = 0;
  23383. }
  23384. return rng_state.next();
  23385. }
  23386. function rng_get_bytes(ba) {
  23387. var i;
  23388. for (i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
  23389. }
  23390. function SecureRandom() {
  23391. }
  23392. SecureRandom.prototype.nextBytes = rng_get_bytes;
  23393. function Arcfour() {
  23394. this.i = 0;
  23395. this.j = 0;
  23396. this.S = new Array();
  23397. }
  23398. function ARC4init(key) {
  23399. var i, j, t2;
  23400. for (i = 0; i < 256; ++i)
  23401. this.S[i] = i;
  23402. j = 0;
  23403. for (i = 0; i < 256; ++i) {
  23404. j = j + this.S[i] + key[i % key.length] & 255;
  23405. t2 = this.S[i];
  23406. this.S[i] = this.S[j];
  23407. this.S[j] = t2;
  23408. }
  23409. this.i = 0;
  23410. this.j = 0;
  23411. }
  23412. function ARC4next() {
  23413. var t2;
  23414. this.i = this.i + 1 & 255;
  23415. this.j = this.j + this.S[this.i] & 255;
  23416. t2 = this.S[this.i];
  23417. this.S[this.i] = this.S[this.j];
  23418. this.S[this.j] = t2;
  23419. return this.S[t2 + this.S[this.i] & 255];
  23420. }
  23421. Arcfour.prototype.init = ARC4init;
  23422. Arcfour.prototype.next = ARC4next;
  23423. function prng_newstate() {
  23424. return new Arcfour();
  23425. }
  23426. var rng_psize = 256;
  23427. if (typeof exports2 !== "undefined") {
  23428. exports2 = module2.exports = {
  23429. default: BigInteger,
  23430. BigInteger,
  23431. SecureRandom
  23432. };
  23433. } else {
  23434. this.jsbn = {
  23435. BigInteger,
  23436. SecureRandom
  23437. };
  23438. }
  23439. }).call(exports2);
  23440. }
  23441. });
  23442. // node_modules/sprintf-js/src/sprintf.js
  23443. var require_sprintf = __commonJS({
  23444. "node_modules/sprintf-js/src/sprintf.js"(exports2) {
  23445. !function() {
  23446. "use strict";
  23447. var re = {
  23448. not_string: /[^s]/,
  23449. not_bool: /[^t]/,
  23450. not_type: /[^T]/,
  23451. not_primitive: /[^v]/,
  23452. number: /[diefg]/,
  23453. numeric_arg: /[bcdiefguxX]/,
  23454. json: /[j]/,
  23455. not_json: /[^j]/,
  23456. text: /^[^\x25]+/,
  23457. modulo: /^\x25{2}/,
  23458. placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
  23459. key: /^([a-z_][a-z_\d]*)/i,
  23460. key_access: /^\.([a-z_][a-z_\d]*)/i,
  23461. index_access: /^\[(\d+)\]/,
  23462. sign: /^[+-]/
  23463. };
  23464. function sprintf(key) {
  23465. return sprintf_format(sprintf_parse(key), arguments);
  23466. }
  23467. function vsprintf(fmt, argv) {
  23468. return sprintf.apply(null, [fmt].concat(argv || []));
  23469. }
  23470. function sprintf_format(parse_tree, argv) {
  23471. var cursor = 1, tree_length = parse_tree.length, arg, output = "", i, k, ph, pad, pad_character, pad_length, is_positive, sign;
  23472. for (i = 0; i < tree_length; i++) {
  23473. if (typeof parse_tree[i] === "string") {
  23474. output += parse_tree[i];
  23475. } else if (typeof parse_tree[i] === "object") {
  23476. ph = parse_tree[i];
  23477. if (ph.keys) {
  23478. arg = argv[cursor];
  23479. for (k = 0; k < ph.keys.length; k++) {
  23480. if (arg == void 0) {
  23481. throw new Error(sprintf('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k - 1]));
  23482. }
  23483. arg = arg[ph.keys[k]];
  23484. }
  23485. } else if (ph.param_no) {
  23486. arg = argv[ph.param_no];
  23487. } else {
  23488. arg = argv[cursor++];
  23489. }
  23490. if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
  23491. arg = arg();
  23492. }
  23493. if (re.numeric_arg.test(ph.type) && (typeof arg !== "number" && isNaN(arg))) {
  23494. throw new TypeError(sprintf("[sprintf] expecting number but found %T", arg));
  23495. }
  23496. if (re.number.test(ph.type)) {
  23497. is_positive = arg >= 0;
  23498. }
  23499. switch (ph.type) {
  23500. case "b":
  23501. arg = parseInt(arg, 10).toString(2);
  23502. break;
  23503. case "c":
  23504. arg = String.fromCharCode(parseInt(arg, 10));
  23505. break;
  23506. case "d":
  23507. case "i":
  23508. arg = parseInt(arg, 10);
  23509. break;
  23510. case "j":
  23511. arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0);
  23512. break;
  23513. case "e":
  23514. arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential();
  23515. break;
  23516. case "f":
  23517. arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg);
  23518. break;
  23519. case "g":
  23520. arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg);
  23521. break;
  23522. case "o":
  23523. arg = (parseInt(arg, 10) >>> 0).toString(8);
  23524. break;
  23525. case "s":
  23526. arg = String(arg);
  23527. arg = ph.precision ? arg.substring(0, ph.precision) : arg;
  23528. break;
  23529. case "t":
  23530. arg = String(!!arg);
  23531. arg = ph.precision ? arg.substring(0, ph.precision) : arg;
  23532. break;
  23533. case "T":
  23534. arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase();
  23535. arg = ph.precision ? arg.substring(0, ph.precision) : arg;
  23536. break;
  23537. case "u":
  23538. arg = parseInt(arg, 10) >>> 0;
  23539. break;
  23540. case "v":
  23541. arg = arg.valueOf();
  23542. arg = ph.precision ? arg.substring(0, ph.precision) : arg;
  23543. break;
  23544. case "x":
  23545. arg = (parseInt(arg, 10) >>> 0).toString(16);
  23546. break;
  23547. case "X":
  23548. arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase();
  23549. break;
  23550. }
  23551. if (re.json.test(ph.type)) {
  23552. output += arg;
  23553. } else {
  23554. if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
  23555. sign = is_positive ? "+" : "-";
  23556. arg = arg.toString().replace(re.sign, "");
  23557. } else {
  23558. sign = "";
  23559. }
  23560. pad_character = ph.pad_char ? ph.pad_char === "0" ? "0" : ph.pad_char.charAt(1) : " ";
  23561. pad_length = ph.width - (sign + arg).length;
  23562. pad = ph.width ? pad_length > 0 ? pad_character.repeat(pad_length) : "" : "";
  23563. output += ph.align ? sign + arg + pad : pad_character === "0" ? sign + pad + arg : pad + sign + arg;
  23564. }
  23565. }
  23566. }
  23567. return output;
  23568. }
  23569. var sprintf_cache = /* @__PURE__ */ Object.create(null);
  23570. function sprintf_parse(fmt) {
  23571. if (sprintf_cache[fmt]) {
  23572. return sprintf_cache[fmt];
  23573. }
  23574. var _fmt = fmt, match, parse_tree = [], arg_names = 0;
  23575. while (_fmt) {
  23576. if ((match = re.text.exec(_fmt)) !== null) {
  23577. parse_tree.push(match[0]);
  23578. } else if ((match = re.modulo.exec(_fmt)) !== null) {
  23579. parse_tree.push("%");
  23580. } else if ((match = re.placeholder.exec(_fmt)) !== null) {
  23581. if (match[2]) {
  23582. arg_names |= 1;
  23583. var field_list = [], replacement_field = match[2], field_match = [];
  23584. if ((field_match = re.key.exec(replacement_field)) !== null) {
  23585. field_list.push(field_match[1]);
  23586. while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") {
  23587. if ((field_match = re.key_access.exec(replacement_field)) !== null) {
  23588. field_list.push(field_match[1]);
  23589. } else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
  23590. field_list.push(field_match[1]);
  23591. } else {
  23592. throw new SyntaxError("[sprintf] failed to parse named argument key");
  23593. }
  23594. }
  23595. } else {
  23596. throw new SyntaxError("[sprintf] failed to parse named argument key");
  23597. }
  23598. match[2] = field_list;
  23599. } else {
  23600. arg_names |= 2;
  23601. }
  23602. if (arg_names === 3) {
  23603. throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");
  23604. }
  23605. parse_tree.push(
  23606. {
  23607. placeholder: match[0],
  23608. param_no: match[1],
  23609. keys: match[2],
  23610. sign: match[3],
  23611. pad_char: match[4],
  23612. align: match[5],
  23613. width: match[6],
  23614. precision: match[7],
  23615. type: match[8]
  23616. }
  23617. );
  23618. } else {
  23619. throw new SyntaxError("[sprintf] unexpected placeholder");
  23620. }
  23621. _fmt = _fmt.substring(match[0].length);
  23622. }
  23623. return sprintf_cache[fmt] = parse_tree;
  23624. }
  23625. if (typeof exports2 !== "undefined") {
  23626. exports2["sprintf"] = sprintf;
  23627. exports2["vsprintf"] = vsprintf;
  23628. }
  23629. if (typeof window !== "undefined") {
  23630. window["sprintf"] = sprintf;
  23631. window["vsprintf"] = vsprintf;
  23632. if (typeof define === "function" && define["amd"]) {
  23633. define(function() {
  23634. return {
  23635. "sprintf": sprintf,
  23636. "vsprintf": vsprintf
  23637. };
  23638. });
  23639. }
  23640. }
  23641. }();
  23642. }
  23643. });
  23644. // node_modules/ip-address/dist/ipv4.js
  23645. var require_ipv4 = __commonJS({
  23646. "node_modules/ip-address/dist/ipv4.js"(exports2) {
  23647. "use strict";
  23648. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  23649. if (k2 === void 0) k2 = k;
  23650. var desc = Object.getOwnPropertyDescriptor(m, k);
  23651. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  23652. desc = { enumerable: true, get: function() {
  23653. return m[k];
  23654. } };
  23655. }
  23656. Object.defineProperty(o, k2, desc);
  23657. } : function(o, m, k, k2) {
  23658. if (k2 === void 0) k2 = k;
  23659. o[k2] = m[k];
  23660. });
  23661. var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
  23662. Object.defineProperty(o, "default", { enumerable: true, value: v });
  23663. } : function(o, v) {
  23664. o["default"] = v;
  23665. });
  23666. var __importStar = exports2 && exports2.__importStar || function(mod) {
  23667. if (mod && mod.__esModule) return mod;
  23668. var result = {};
  23669. if (mod != null) {
  23670. for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  23671. }
  23672. __setModuleDefault(result, mod);
  23673. return result;
  23674. };
  23675. Object.defineProperty(exports2, "__esModule", { value: true });
  23676. exports2.Address4 = void 0;
  23677. var common = __importStar(require_common3());
  23678. var constants = __importStar(require_constants4());
  23679. var address_error_1 = require_address_error();
  23680. var jsbn_1 = require_jsbn();
  23681. var sprintf_js_1 = require_sprintf();
  23682. var Address4 = class _Address4 {
  23683. constructor(address) {
  23684. this.groups = constants.GROUPS;
  23685. this.parsedAddress = [];
  23686. this.parsedSubnet = "";
  23687. this.subnet = "/32";
  23688. this.subnetMask = 32;
  23689. this.v4 = true;
  23690. this.isCorrect = common.isCorrect(constants.BITS);
  23691. this.isInSubnet = common.isInSubnet;
  23692. this.address = address;
  23693. const subnet = constants.RE_SUBNET_STRING.exec(address);
  23694. if (subnet) {
  23695. this.parsedSubnet = subnet[0].replace("/", "");
  23696. this.subnetMask = parseInt(this.parsedSubnet, 10);
  23697. this.subnet = `/${this.subnetMask}`;
  23698. if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {
  23699. throw new address_error_1.AddressError("Invalid subnet mask.");
  23700. }
  23701. address = address.replace(constants.RE_SUBNET_STRING, "");
  23702. }
  23703. this.addressMinusSuffix = address;
  23704. this.parsedAddress = this.parse(address);
  23705. }
  23706. static isValid(address) {
  23707. try {
  23708. new _Address4(address);
  23709. return true;
  23710. } catch (e) {
  23711. return false;
  23712. }
  23713. }
  23714. /*
  23715. * Parses a v4 address
  23716. */
  23717. parse(address) {
  23718. const groups = address.split(".");
  23719. if (!address.match(constants.RE_ADDRESS)) {
  23720. throw new address_error_1.AddressError("Invalid IPv4 address.");
  23721. }
  23722. return groups;
  23723. }
  23724. /**
  23725. * Returns the correct form of an address
  23726. * @memberof Address4
  23727. * @instance
  23728. * @returns {String}
  23729. */
  23730. correctForm() {
  23731. return this.parsedAddress.map((part) => parseInt(part, 10)).join(".");
  23732. }
  23733. /**
  23734. * Converts a hex string to an IPv4 address object
  23735. * @memberof Address4
  23736. * @static
  23737. * @param {string} hex - a hex string to convert
  23738. * @returns {Address4}
  23739. */
  23740. static fromHex(hex) {
  23741. const padded = hex.replace(/:/g, "").padStart(8, "0");
  23742. const groups = [];
  23743. let i;
  23744. for (i = 0; i < 8; i += 2) {
  23745. const h = padded.slice(i, i + 2);
  23746. groups.push(parseInt(h, 16));
  23747. }
  23748. return new _Address4(groups.join("."));
  23749. }
  23750. /**
  23751. * Converts an integer into a IPv4 address object
  23752. * @memberof Address4
  23753. * @static
  23754. * @param {integer} integer - a number to convert
  23755. * @returns {Address4}
  23756. */
  23757. static fromInteger(integer) {
  23758. return _Address4.fromHex(integer.toString(16));
  23759. }
  23760. /**
  23761. * Return an address from in-addr.arpa form
  23762. * @memberof Address4
  23763. * @static
  23764. * @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address
  23765. * @returns {Adress4}
  23766. * @example
  23767. * var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)
  23768. * address.correctForm(); // '192.0.2.42'
  23769. */
  23770. static fromArpa(arpaFormAddress) {
  23771. const leader = arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, "");
  23772. const address = leader.split(".").reverse().join(".");
  23773. return new _Address4(address);
  23774. }
  23775. /**
  23776. * Converts an IPv4 address object to a hex string
  23777. * @memberof Address4
  23778. * @instance
  23779. * @returns {String}
  23780. */
  23781. toHex() {
  23782. return this.parsedAddress.map((part) => (0, sprintf_js_1.sprintf)("%02x", parseInt(part, 10))).join(":");
  23783. }
  23784. /**
  23785. * Converts an IPv4 address object to an array of bytes
  23786. * @memberof Address4
  23787. * @instance
  23788. * @returns {Array}
  23789. */
  23790. toArray() {
  23791. return this.parsedAddress.map((part) => parseInt(part, 10));
  23792. }
  23793. /**
  23794. * Converts an IPv4 address object to an IPv6 address group
  23795. * @memberof Address4
  23796. * @instance
  23797. * @returns {String}
  23798. */
  23799. toGroup6() {
  23800. const output = [];
  23801. let i;
  23802. for (i = 0; i < constants.GROUPS; i += 2) {
  23803. const hex = (0, sprintf_js_1.sprintf)("%02x%02x", parseInt(this.parsedAddress[i], 10), parseInt(this.parsedAddress[i + 1], 10));
  23804. output.push((0, sprintf_js_1.sprintf)("%x", parseInt(hex, 16)));
  23805. }
  23806. return output.join(":");
  23807. }
  23808. /**
  23809. * Returns the address as a BigInteger
  23810. * @memberof Address4
  23811. * @instance
  23812. * @returns {BigInteger}
  23813. */
  23814. bigInteger() {
  23815. return new jsbn_1.BigInteger(this.parsedAddress.map((n) => (0, sprintf_js_1.sprintf)("%02x", parseInt(n, 10))).join(""), 16);
  23816. }
  23817. /**
  23818. * Helper function getting start address.
  23819. * @memberof Address4
  23820. * @instance
  23821. * @returns {BigInteger}
  23822. */
  23823. _startAddress() {
  23824. return new jsbn_1.BigInteger(this.mask() + "0".repeat(constants.BITS - this.subnetMask), 2);
  23825. }
  23826. /**
  23827. * The first address in the range given by this address' subnet.
  23828. * Often referred to as the Network Address.
  23829. * @memberof Address4
  23830. * @instance
  23831. * @returns {Address4}
  23832. */
  23833. startAddress() {
  23834. return _Address4.fromBigInteger(this._startAddress());
  23835. }
  23836. /**
  23837. * The first host address in the range given by this address's subnet ie
  23838. * the first address after the Network Address
  23839. * @memberof Address4
  23840. * @instance
  23841. * @returns {Address4}
  23842. */
  23843. startAddressExclusive() {
  23844. const adjust = new jsbn_1.BigInteger("1");
  23845. return _Address4.fromBigInteger(this._startAddress().add(adjust));
  23846. }
  23847. /**
  23848. * Helper function getting end address.
  23849. * @memberof Address4
  23850. * @instance
  23851. * @returns {BigInteger}
  23852. */
  23853. _endAddress() {
  23854. return new jsbn_1.BigInteger(this.mask() + "1".repeat(constants.BITS - this.subnetMask), 2);
  23855. }
  23856. /**
  23857. * The last address in the range given by this address' subnet
  23858. * Often referred to as the Broadcast
  23859. * @memberof Address4
  23860. * @instance
  23861. * @returns {Address4}
  23862. */
  23863. endAddress() {
  23864. return _Address4.fromBigInteger(this._endAddress());
  23865. }
  23866. /**
  23867. * The last host address in the range given by this address's subnet ie
  23868. * the last address prior to the Broadcast Address
  23869. * @memberof Address4
  23870. * @instance
  23871. * @returns {Address4}
  23872. */
  23873. endAddressExclusive() {
  23874. const adjust = new jsbn_1.BigInteger("1");
  23875. return _Address4.fromBigInteger(this._endAddress().subtract(adjust));
  23876. }
  23877. /**
  23878. * Converts a BigInteger to a v4 address object
  23879. * @memberof Address4
  23880. * @static
  23881. * @param {BigInteger} bigInteger - a BigInteger to convert
  23882. * @returns {Address4}
  23883. */
  23884. static fromBigInteger(bigInteger) {
  23885. return _Address4.fromInteger(parseInt(bigInteger.toString(), 10));
  23886. }
  23887. /**
  23888. * Returns the first n bits of the address, defaulting to the
  23889. * subnet mask
  23890. * @memberof Address4
  23891. * @instance
  23892. * @returns {String}
  23893. */
  23894. mask(mask) {
  23895. if (mask === void 0) {
  23896. mask = this.subnetMask;
  23897. }
  23898. return this.getBitsBase2(0, mask);
  23899. }
  23900. /**
  23901. * Returns the bits in the given range as a base-2 string
  23902. * @memberof Address4
  23903. * @instance
  23904. * @returns {string}
  23905. */
  23906. getBitsBase2(start, end) {
  23907. return this.binaryZeroPad().slice(start, end);
  23908. }
  23909. /**
  23910. * Return the reversed ip6.arpa form of the address
  23911. * @memberof Address4
  23912. * @param {Object} options
  23913. * @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix
  23914. * @instance
  23915. * @returns {String}
  23916. */
  23917. reverseForm(options) {
  23918. if (!options) {
  23919. options = {};
  23920. }
  23921. const reversed = this.correctForm().split(".").reverse().join(".");
  23922. if (options.omitSuffix) {
  23923. return reversed;
  23924. }
  23925. return (0, sprintf_js_1.sprintf)("%s.in-addr.arpa.", reversed);
  23926. }
  23927. /**
  23928. * Returns true if the given address is a multicast address
  23929. * @memberof Address4
  23930. * @instance
  23931. * @returns {boolean}
  23932. */
  23933. isMulticast() {
  23934. return this.isInSubnet(new _Address4("224.0.0.0/4"));
  23935. }
  23936. /**
  23937. * Returns a zero-padded base-2 string representation of the address
  23938. * @memberof Address4
  23939. * @instance
  23940. * @returns {string}
  23941. */
  23942. binaryZeroPad() {
  23943. return this.bigInteger().toString(2).padStart(constants.BITS, "0");
  23944. }
  23945. /**
  23946. * Groups an IPv4 address for inclusion at the end of an IPv6 address
  23947. * @returns {String}
  23948. */
  23949. groupForV6() {
  23950. const segments = this.parsedAddress;
  23951. return this.address.replace(constants.RE_ADDRESS, (0, sprintf_js_1.sprintf)('<span class="hover-group group-v4 group-6">%s</span>.<span class="hover-group group-v4 group-7">%s</span>', segments.slice(0, 2).join("."), segments.slice(2, 4).join(".")));
  23952. }
  23953. };
  23954. exports2.Address4 = Address4;
  23955. }
  23956. });
  23957. // node_modules/ip-address/dist/v6/constants.js
  23958. var require_constants5 = __commonJS({
  23959. "node_modules/ip-address/dist/v6/constants.js"(exports2) {
  23960. "use strict";
  23961. Object.defineProperty(exports2, "__esModule", { value: true });
  23962. exports2.RE_URL_WITH_PORT = exports2.RE_URL = exports2.RE_ZONE_STRING = exports2.RE_SUBNET_STRING = exports2.RE_BAD_ADDRESS = exports2.RE_BAD_CHARACTERS = exports2.TYPES = exports2.SCOPES = exports2.GROUPS = exports2.BITS = void 0;
  23963. exports2.BITS = 128;
  23964. exports2.GROUPS = 8;
  23965. exports2.SCOPES = {
  23966. 0: "Reserved",
  23967. 1: "Interface local",
  23968. 2: "Link local",
  23969. 4: "Admin local",
  23970. 5: "Site local",
  23971. 8: "Organization local",
  23972. 14: "Global",
  23973. 15: "Reserved"
  23974. };
  23975. exports2.TYPES = {
  23976. "ff01::1/128": "Multicast (All nodes on this interface)",
  23977. "ff01::2/128": "Multicast (All routers on this interface)",
  23978. "ff02::1/128": "Multicast (All nodes on this link)",
  23979. "ff02::2/128": "Multicast (All routers on this link)",
  23980. "ff05::2/128": "Multicast (All routers in this site)",
  23981. "ff02::5/128": "Multicast (OSPFv3 AllSPF routers)",
  23982. "ff02::6/128": "Multicast (OSPFv3 AllDR routers)",
  23983. "ff02::9/128": "Multicast (RIP routers)",
  23984. "ff02::a/128": "Multicast (EIGRP routers)",
  23985. "ff02::d/128": "Multicast (PIM routers)",
  23986. "ff02::16/128": "Multicast (MLDv2 reports)",
  23987. "ff01::fb/128": "Multicast (mDNSv6)",
  23988. "ff02::fb/128": "Multicast (mDNSv6)",
  23989. "ff05::fb/128": "Multicast (mDNSv6)",
  23990. "ff02::1:2/128": "Multicast (All DHCP servers and relay agents on this link)",
  23991. "ff05::1:2/128": "Multicast (All DHCP servers and relay agents in this site)",
  23992. "ff02::1:3/128": "Multicast (All DHCP servers on this link)",
  23993. "ff05::1:3/128": "Multicast (All DHCP servers in this site)",
  23994. "::/128": "Unspecified",
  23995. "::1/128": "Loopback",
  23996. "ff00::/8": "Multicast",
  23997. "fe80::/10": "Link-local unicast"
  23998. };
  23999. exports2.RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi;
  24000. exports2.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi;
  24001. exports2.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
  24002. exports2.RE_ZONE_STRING = /%.*$/;
  24003. exports2.RE_URL = new RegExp(/^\[{0,1}([0-9a-f:]+)\]{0,1}/);
  24004. exports2.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
  24005. }
  24006. });
  24007. // node_modules/ip-address/dist/v6/helpers.js
  24008. var require_helpers = __commonJS({
  24009. "node_modules/ip-address/dist/v6/helpers.js"(exports2) {
  24010. "use strict";
  24011. Object.defineProperty(exports2, "__esModule", { value: true });
  24012. exports2.simpleGroup = exports2.spanLeadingZeroes = exports2.spanAll = exports2.spanAllZeroes = void 0;
  24013. var sprintf_js_1 = require_sprintf();
  24014. function spanAllZeroes(s) {
  24015. return s.replace(/(0+)/g, '<span class="zero">$1</span>');
  24016. }
  24017. exports2.spanAllZeroes = spanAllZeroes;
  24018. function spanAll(s, offset = 0) {
  24019. const letters = s.split("");
  24020. return letters.map(
  24021. (n, i) => (0, sprintf_js_1.sprintf)('<span class="digit value-%s position-%d">%s</span>', n, i + offset, spanAllZeroes(n))
  24022. // XXX Use #base-2 .value-0 instead?
  24023. ).join("");
  24024. }
  24025. exports2.spanAll = spanAll;
  24026. function spanLeadingZeroesSimple(group) {
  24027. return group.replace(/^(0+)/, '<span class="zero">$1</span>');
  24028. }
  24029. function spanLeadingZeroes(address) {
  24030. const groups = address.split(":");
  24031. return groups.map((g) => spanLeadingZeroesSimple(g)).join(":");
  24032. }
  24033. exports2.spanLeadingZeroes = spanLeadingZeroes;
  24034. function simpleGroup(addressString, offset = 0) {
  24035. const groups = addressString.split(":");
  24036. return groups.map((g, i) => {
  24037. if (/group-v4/.test(g)) {
  24038. return g;
  24039. }
  24040. return (0, sprintf_js_1.sprintf)('<span class="hover-group group-%d">%s</span>', i + offset, spanLeadingZeroesSimple(g));
  24041. });
  24042. }
  24043. exports2.simpleGroup = simpleGroup;
  24044. }
  24045. });
  24046. // node_modules/ip-address/dist/v6/regular-expressions.js
  24047. var require_regular_expressions = __commonJS({
  24048. "node_modules/ip-address/dist/v6/regular-expressions.js"(exports2) {
  24049. "use strict";
  24050. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  24051. if (k2 === void 0) k2 = k;
  24052. var desc = Object.getOwnPropertyDescriptor(m, k);
  24053. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  24054. desc = { enumerable: true, get: function() {
  24055. return m[k];
  24056. } };
  24057. }
  24058. Object.defineProperty(o, k2, desc);
  24059. } : function(o, m, k, k2) {
  24060. if (k2 === void 0) k2 = k;
  24061. o[k2] = m[k];
  24062. });
  24063. var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
  24064. Object.defineProperty(o, "default", { enumerable: true, value: v });
  24065. } : function(o, v) {
  24066. o["default"] = v;
  24067. });
  24068. var __importStar = exports2 && exports2.__importStar || function(mod) {
  24069. if (mod && mod.__esModule) return mod;
  24070. var result = {};
  24071. if (mod != null) {
  24072. for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  24073. }
  24074. __setModuleDefault(result, mod);
  24075. return result;
  24076. };
  24077. Object.defineProperty(exports2, "__esModule", { value: true });
  24078. exports2.possibleElisions = exports2.simpleRegularExpression = exports2.ADDRESS_BOUNDARY = exports2.padGroup = exports2.groupPossibilities = void 0;
  24079. var v6 = __importStar(require_constants5());
  24080. var sprintf_js_1 = require_sprintf();
  24081. function groupPossibilities(possibilities) {
  24082. return (0, sprintf_js_1.sprintf)("(%s)", possibilities.join("|"));
  24083. }
  24084. exports2.groupPossibilities = groupPossibilities;
  24085. function padGroup(group) {
  24086. if (group.length < 4) {
  24087. return (0, sprintf_js_1.sprintf)("0{0,%d}%s", 4 - group.length, group);
  24088. }
  24089. return group;
  24090. }
  24091. exports2.padGroup = padGroup;
  24092. exports2.ADDRESS_BOUNDARY = "[^A-Fa-f0-9:]";
  24093. function simpleRegularExpression(groups) {
  24094. const zeroIndexes = [];
  24095. groups.forEach((group, i) => {
  24096. const groupInteger = parseInt(group, 16);
  24097. if (groupInteger === 0) {
  24098. zeroIndexes.push(i);
  24099. }
  24100. });
  24101. const possibilities = zeroIndexes.map((zeroIndex) => groups.map((group, i) => {
  24102. if (i === zeroIndex) {
  24103. const elision = i === 0 || i === v6.GROUPS - 1 ? ":" : "";
  24104. return groupPossibilities([padGroup(group), elision]);
  24105. }
  24106. return padGroup(group);
  24107. }).join(":"));
  24108. possibilities.push(groups.map(padGroup).join(":"));
  24109. return groupPossibilities(possibilities);
  24110. }
  24111. exports2.simpleRegularExpression = simpleRegularExpression;
  24112. function possibleElisions(elidedGroups, moreLeft, moreRight) {
  24113. const left = moreLeft ? "" : ":";
  24114. const right = moreRight ? "" : ":";
  24115. const possibilities = [];
  24116. if (!moreLeft && !moreRight) {
  24117. possibilities.push("::");
  24118. }
  24119. if (moreLeft && moreRight) {
  24120. possibilities.push("");
  24121. }
  24122. if (moreRight && !moreLeft || !moreRight && moreLeft) {
  24123. possibilities.push(":");
  24124. }
  24125. possibilities.push((0, sprintf_js_1.sprintf)("%s(:0{1,4}){1,%d}", left, elidedGroups - 1));
  24126. possibilities.push((0, sprintf_js_1.sprintf)("(0{1,4}:){1,%d}%s", elidedGroups - 1, right));
  24127. possibilities.push((0, sprintf_js_1.sprintf)("(0{1,4}:){%d}0{1,4}", elidedGroups - 1));
  24128. for (let groups = 1; groups < elidedGroups - 1; groups++) {
  24129. for (let position = 1; position < elidedGroups - groups; position++) {
  24130. possibilities.push((0, sprintf_js_1.sprintf)("(0{1,4}:){%d}:(0{1,4}:){%d}0{1,4}", position, elidedGroups - position - groups - 1));
  24131. }
  24132. }
  24133. return groupPossibilities(possibilities);
  24134. }
  24135. exports2.possibleElisions = possibleElisions;
  24136. }
  24137. });
  24138. // node_modules/ip-address/dist/ipv6.js
  24139. var require_ipv6 = __commonJS({
  24140. "node_modules/ip-address/dist/ipv6.js"(exports2) {
  24141. "use strict";
  24142. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  24143. if (k2 === void 0) k2 = k;
  24144. var desc = Object.getOwnPropertyDescriptor(m, k);
  24145. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  24146. desc = { enumerable: true, get: function() {
  24147. return m[k];
  24148. } };
  24149. }
  24150. Object.defineProperty(o, k2, desc);
  24151. } : function(o, m, k, k2) {
  24152. if (k2 === void 0) k2 = k;
  24153. o[k2] = m[k];
  24154. });
  24155. var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
  24156. Object.defineProperty(o, "default", { enumerable: true, value: v });
  24157. } : function(o, v) {
  24158. o["default"] = v;
  24159. });
  24160. var __importStar = exports2 && exports2.__importStar || function(mod) {
  24161. if (mod && mod.__esModule) return mod;
  24162. var result = {};
  24163. if (mod != null) {
  24164. for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  24165. }
  24166. __setModuleDefault(result, mod);
  24167. return result;
  24168. };
  24169. Object.defineProperty(exports2, "__esModule", { value: true });
  24170. exports2.Address6 = void 0;
  24171. var common = __importStar(require_common3());
  24172. var constants4 = __importStar(require_constants4());
  24173. var constants6 = __importStar(require_constants5());
  24174. var helpers = __importStar(require_helpers());
  24175. var ipv4_1 = require_ipv4();
  24176. var regular_expressions_1 = require_regular_expressions();
  24177. var address_error_1 = require_address_error();
  24178. var jsbn_1 = require_jsbn();
  24179. var sprintf_js_1 = require_sprintf();
  24180. function assert(condition) {
  24181. if (!condition) {
  24182. throw new Error("Assertion failed.");
  24183. }
  24184. }
  24185. function addCommas(number) {
  24186. const r = /(\d+)(\d{3})/;
  24187. while (r.test(number)) {
  24188. number = number.replace(r, "$1,$2");
  24189. }
  24190. return number;
  24191. }
  24192. function spanLeadingZeroes4(n) {
  24193. n = n.replace(/^(0{1,})([1-9]+)$/, '<span class="parse-error">$1</span>$2');
  24194. n = n.replace(/^(0{1,})(0)$/, '<span class="parse-error">$1</span>$2');
  24195. return n;
  24196. }
  24197. function compact(address, slice) {
  24198. const s1 = [];
  24199. const s2 = [];
  24200. let i;
  24201. for (i = 0; i < address.length; i++) {
  24202. if (i < slice[0]) {
  24203. s1.push(address[i]);
  24204. } else if (i > slice[1]) {
  24205. s2.push(address[i]);
  24206. }
  24207. }
  24208. return s1.concat(["compact"]).concat(s2);
  24209. }
  24210. function paddedHex(octet) {
  24211. return (0, sprintf_js_1.sprintf)("%04x", parseInt(octet, 16));
  24212. }
  24213. function unsignByte(b) {
  24214. return b & 255;
  24215. }
  24216. var Address6 = class _Address6 {
  24217. constructor(address, optionalGroups) {
  24218. this.addressMinusSuffix = "";
  24219. this.parsedSubnet = "";
  24220. this.subnet = "/128";
  24221. this.subnetMask = 128;
  24222. this.v4 = false;
  24223. this.zone = "";
  24224. this.isInSubnet = common.isInSubnet;
  24225. this.isCorrect = common.isCorrect(constants6.BITS);
  24226. if (optionalGroups === void 0) {
  24227. this.groups = constants6.GROUPS;
  24228. } else {
  24229. this.groups = optionalGroups;
  24230. }
  24231. this.address = address;
  24232. const subnet = constants6.RE_SUBNET_STRING.exec(address);
  24233. if (subnet) {
  24234. this.parsedSubnet = subnet[0].replace("/", "");
  24235. this.subnetMask = parseInt(this.parsedSubnet, 10);
  24236. this.subnet = `/${this.subnetMask}`;
  24237. if (Number.isNaN(this.subnetMask) || this.subnetMask < 0 || this.subnetMask > constants6.BITS) {
  24238. throw new address_error_1.AddressError("Invalid subnet mask.");
  24239. }
  24240. address = address.replace(constants6.RE_SUBNET_STRING, "");
  24241. } else if (/\//.test(address)) {
  24242. throw new address_error_1.AddressError("Invalid subnet mask.");
  24243. }
  24244. const zone = constants6.RE_ZONE_STRING.exec(address);
  24245. if (zone) {
  24246. this.zone = zone[0];
  24247. address = address.replace(constants6.RE_ZONE_STRING, "");
  24248. }
  24249. this.addressMinusSuffix = address;
  24250. this.parsedAddress = this.parse(this.addressMinusSuffix);
  24251. }
  24252. static isValid(address) {
  24253. try {
  24254. new _Address6(address);
  24255. return true;
  24256. } catch (e) {
  24257. return false;
  24258. }
  24259. }
  24260. /**
  24261. * Convert a BigInteger to a v6 address object
  24262. * @memberof Address6
  24263. * @static
  24264. * @param {BigInteger} bigInteger - a BigInteger to convert
  24265. * @returns {Address6}
  24266. * @example
  24267. * var bigInteger = new BigInteger('1000000000000');
  24268. * var address = Address6.fromBigInteger(bigInteger);
  24269. * address.correctForm(); // '::e8:d4a5:1000'
  24270. */
  24271. static fromBigInteger(bigInteger) {
  24272. const hex = bigInteger.toString(16).padStart(32, "0");
  24273. const groups = [];
  24274. let i;
  24275. for (i = 0; i < constants6.GROUPS; i++) {
  24276. groups.push(hex.slice(i * 4, (i + 1) * 4));
  24277. }
  24278. return new _Address6(groups.join(":"));
  24279. }
  24280. /**
  24281. * Convert a URL (with optional port number) to an address object
  24282. * @memberof Address6
  24283. * @static
  24284. * @param {string} url - a URL with optional port number
  24285. * @example
  24286. * var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
  24287. * addressAndPort.address.correctForm(); // 'ffff::'
  24288. * addressAndPort.port; // 8080
  24289. */
  24290. static fromURL(url) {
  24291. let host;
  24292. let port = null;
  24293. let result;
  24294. if (url.indexOf("[") !== -1 && url.indexOf("]:") !== -1) {
  24295. result = constants6.RE_URL_WITH_PORT.exec(url);
  24296. if (result === null) {
  24297. return {
  24298. error: "failed to parse address with port",
  24299. address: null,
  24300. port: null
  24301. };
  24302. }
  24303. host = result[1];
  24304. port = result[2];
  24305. } else if (url.indexOf("/") !== -1) {
  24306. url = url.replace(/^[a-z0-9]+:\/\//, "");
  24307. result = constants6.RE_URL.exec(url);
  24308. if (result === null) {
  24309. return {
  24310. error: "failed to parse address from URL",
  24311. address: null,
  24312. port: null
  24313. };
  24314. }
  24315. host = result[1];
  24316. } else {
  24317. host = url;
  24318. }
  24319. if (port) {
  24320. port = parseInt(port, 10);
  24321. if (port < 0 || port > 65536) {
  24322. port = null;
  24323. }
  24324. } else {
  24325. port = null;
  24326. }
  24327. return {
  24328. address: new _Address6(host),
  24329. port
  24330. };
  24331. }
  24332. /**
  24333. * Create an IPv6-mapped address given an IPv4 address
  24334. * @memberof Address6
  24335. * @static
  24336. * @param {string} address - An IPv4 address string
  24337. * @returns {Address6}
  24338. * @example
  24339. * var address = Address6.fromAddress4('192.168.0.1');
  24340. * address.correctForm(); // '::ffff:c0a8:1'
  24341. * address.to4in6(); // '::ffff:192.168.0.1'
  24342. */
  24343. static fromAddress4(address) {
  24344. const address4 = new ipv4_1.Address4(address);
  24345. const mask6 = constants6.BITS - (constants4.BITS - address4.subnetMask);
  24346. return new _Address6(`::ffff:${address4.correctForm()}/${mask6}`);
  24347. }
  24348. /**
  24349. * Return an address from ip6.arpa form
  24350. * @memberof Address6
  24351. * @static
  24352. * @param {string} arpaFormAddress - an 'ip6.arpa' form address
  24353. * @returns {Adress6}
  24354. * @example
  24355. * var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
  24356. * address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
  24357. */
  24358. static fromArpa(arpaFormAddress) {
  24359. let address = arpaFormAddress.replace(/(\.ip6\.arpa)?\.$/, "");
  24360. const semicolonAmount = 7;
  24361. if (address.length !== 63) {
  24362. throw new address_error_1.AddressError("Invalid 'ip6.arpa' form.");
  24363. }
  24364. const parts = address.split(".").reverse();
  24365. for (let i = semicolonAmount; i > 0; i--) {
  24366. const insertIndex = i * 4;
  24367. parts.splice(insertIndex, 0, ":");
  24368. }
  24369. address = parts.join("");
  24370. return new _Address6(address);
  24371. }
  24372. /**
  24373. * Return the Microsoft UNC transcription of the address
  24374. * @memberof Address6
  24375. * @instance
  24376. * @returns {String} the Microsoft UNC transcription of the address
  24377. */
  24378. microsoftTranscription() {
  24379. return (0, sprintf_js_1.sprintf)("%s.ipv6-literal.net", this.correctForm().replace(/:/g, "-"));
  24380. }
  24381. /**
  24382. * Return the first n bits of the address, defaulting to the subnet mask
  24383. * @memberof Address6
  24384. * @instance
  24385. * @param {number} [mask=subnet] - the number of bits to mask
  24386. * @returns {String} the first n bits of the address as a string
  24387. */
  24388. mask(mask = this.subnetMask) {
  24389. return this.getBitsBase2(0, mask);
  24390. }
  24391. /**
  24392. * Return the number of possible subnets of a given size in the address
  24393. * @memberof Address6
  24394. * @instance
  24395. * @param {number} [size=128] - the subnet size
  24396. * @returns {String}
  24397. */
  24398. // TODO: probably useful to have a numeric version of this too
  24399. possibleSubnets(subnetSize = 128) {
  24400. const availableBits = constants6.BITS - this.subnetMask;
  24401. const subnetBits = Math.abs(subnetSize - constants6.BITS);
  24402. const subnetPowers = availableBits - subnetBits;
  24403. if (subnetPowers < 0) {
  24404. return "0";
  24405. }
  24406. return addCommas(new jsbn_1.BigInteger("2", 10).pow(subnetPowers).toString(10));
  24407. }
  24408. /**
  24409. * Helper function getting start address.
  24410. * @memberof Address6
  24411. * @instance
  24412. * @returns {BigInteger}
  24413. */
  24414. _startAddress() {
  24415. return new jsbn_1.BigInteger(this.mask() + "0".repeat(constants6.BITS - this.subnetMask), 2);
  24416. }
  24417. /**
  24418. * The first address in the range given by this address' subnet
  24419. * Often referred to as the Network Address.
  24420. * @memberof Address6
  24421. * @instance
  24422. * @returns {Address6}
  24423. */
  24424. startAddress() {
  24425. return _Address6.fromBigInteger(this._startAddress());
  24426. }
  24427. /**
  24428. * The first host address in the range given by this address's subnet ie
  24429. * the first address after the Network Address
  24430. * @memberof Address6
  24431. * @instance
  24432. * @returns {Address6}
  24433. */
  24434. startAddressExclusive() {
  24435. const adjust = new jsbn_1.BigInteger("1");
  24436. return _Address6.fromBigInteger(this._startAddress().add(adjust));
  24437. }
  24438. /**
  24439. * Helper function getting end address.
  24440. * @memberof Address6
  24441. * @instance
  24442. * @returns {BigInteger}
  24443. */
  24444. _endAddress() {
  24445. return new jsbn_1.BigInteger(this.mask() + "1".repeat(constants6.BITS - this.subnetMask), 2);
  24446. }
  24447. /**
  24448. * The last address in the range given by this address' subnet
  24449. * Often referred to as the Broadcast
  24450. * @memberof Address6
  24451. * @instance
  24452. * @returns {Address6}
  24453. */
  24454. endAddress() {
  24455. return _Address6.fromBigInteger(this._endAddress());
  24456. }
  24457. /**
  24458. * The last host address in the range given by this address's subnet ie
  24459. * the last address prior to the Broadcast Address
  24460. * @memberof Address6
  24461. * @instance
  24462. * @returns {Address6}
  24463. */
  24464. endAddressExclusive() {
  24465. const adjust = new jsbn_1.BigInteger("1");
  24466. return _Address6.fromBigInteger(this._endAddress().subtract(adjust));
  24467. }
  24468. /**
  24469. * Return the scope of the address
  24470. * @memberof Address6
  24471. * @instance
  24472. * @returns {String}
  24473. */
  24474. getScope() {
  24475. let scope = constants6.SCOPES[this.getBits(12, 16).intValue()];
  24476. if (this.getType() === "Global unicast" && scope !== "Link local") {
  24477. scope = "Global";
  24478. }
  24479. return scope || "Unknown";
  24480. }
  24481. /**
  24482. * Return the type of the address
  24483. * @memberof Address6
  24484. * @instance
  24485. * @returns {String}
  24486. */
  24487. getType() {
  24488. for (const subnet of Object.keys(constants6.TYPES)) {
  24489. if (this.isInSubnet(new _Address6(subnet))) {
  24490. return constants6.TYPES[subnet];
  24491. }
  24492. }
  24493. return "Global unicast";
  24494. }
  24495. /**
  24496. * Return the bits in the given range as a BigInteger
  24497. * @memberof Address6
  24498. * @instance
  24499. * @returns {BigInteger}
  24500. */
  24501. getBits(start, end) {
  24502. return new jsbn_1.BigInteger(this.getBitsBase2(start, end), 2);
  24503. }
  24504. /**
  24505. * Return the bits in the given range as a base-2 string
  24506. * @memberof Address6
  24507. * @instance
  24508. * @returns {String}
  24509. */
  24510. getBitsBase2(start, end) {
  24511. return this.binaryZeroPad().slice(start, end);
  24512. }
  24513. /**
  24514. * Return the bits in the given range as a base-16 string
  24515. * @memberof Address6
  24516. * @instance
  24517. * @returns {String}
  24518. */
  24519. getBitsBase16(start, end) {
  24520. const length = end - start;
  24521. if (length % 4 !== 0) {
  24522. throw new Error("Length of bits to retrieve must be divisible by four");
  24523. }
  24524. return this.getBits(start, end).toString(16).padStart(length / 4, "0");
  24525. }
  24526. /**
  24527. * Return the bits that are set past the subnet mask length
  24528. * @memberof Address6
  24529. * @instance
  24530. * @returns {String}
  24531. */
  24532. getBitsPastSubnet() {
  24533. return this.getBitsBase2(this.subnetMask, constants6.BITS);
  24534. }
  24535. /**
  24536. * Return the reversed ip6.arpa form of the address
  24537. * @memberof Address6
  24538. * @param {Object} options
  24539. * @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
  24540. * @instance
  24541. * @returns {String}
  24542. */
  24543. reverseForm(options) {
  24544. if (!options) {
  24545. options = {};
  24546. }
  24547. const characters = Math.floor(this.subnetMask / 4);
  24548. const reversed = this.canonicalForm().replace(/:/g, "").split("").slice(0, characters).reverse().join(".");
  24549. if (characters > 0) {
  24550. if (options.omitSuffix) {
  24551. return reversed;
  24552. }
  24553. return (0, sprintf_js_1.sprintf)("%s.ip6.arpa.", reversed);
  24554. }
  24555. if (options.omitSuffix) {
  24556. return "";
  24557. }
  24558. return "ip6.arpa.";
  24559. }
  24560. /**
  24561. * Return the correct form of the address
  24562. * @memberof Address6
  24563. * @instance
  24564. * @returns {String}
  24565. */
  24566. correctForm() {
  24567. let i;
  24568. let groups = [];
  24569. let zeroCounter = 0;
  24570. const zeroes = [];
  24571. for (i = 0; i < this.parsedAddress.length; i++) {
  24572. const value = parseInt(this.parsedAddress[i], 16);
  24573. if (value === 0) {
  24574. zeroCounter++;
  24575. }
  24576. if (value !== 0 && zeroCounter > 0) {
  24577. if (zeroCounter > 1) {
  24578. zeroes.push([i - zeroCounter, i - 1]);
  24579. }
  24580. zeroCounter = 0;
  24581. }
  24582. }
  24583. if (zeroCounter > 1) {
  24584. zeroes.push([this.parsedAddress.length - zeroCounter, this.parsedAddress.length - 1]);
  24585. }
  24586. const zeroLengths = zeroes.map((n) => n[1] - n[0] + 1);
  24587. if (zeroes.length > 0) {
  24588. const index = zeroLengths.indexOf(Math.max(...zeroLengths));
  24589. groups = compact(this.parsedAddress, zeroes[index]);
  24590. } else {
  24591. groups = this.parsedAddress;
  24592. }
  24593. for (i = 0; i < groups.length; i++) {
  24594. if (groups[i] !== "compact") {
  24595. groups[i] = parseInt(groups[i], 16).toString(16);
  24596. }
  24597. }
  24598. let correct = groups.join(":");
  24599. correct = correct.replace(/^compact$/, "::");
  24600. correct = correct.replace(/^compact|compact$/, ":");
  24601. correct = correct.replace(/compact/, "");
  24602. return correct;
  24603. }
  24604. /**
  24605. * Return a zero-padded base-2 string representation of the address
  24606. * @memberof Address6
  24607. * @instance
  24608. * @returns {String}
  24609. * @example
  24610. * var address = new Address6('2001:4860:4001:803::1011');
  24611. * address.binaryZeroPad();
  24612. * // '0010000000000001010010000110000001000000000000010000100000000011
  24613. * // 0000000000000000000000000000000000000000000000000001000000010001'
  24614. */
  24615. binaryZeroPad() {
  24616. return this.bigInteger().toString(2).padStart(constants6.BITS, "0");
  24617. }
  24618. // TODO: Improve the semantics of this helper function
  24619. parse4in6(address) {
  24620. const groups = address.split(":");
  24621. const lastGroup = groups.slice(-1)[0];
  24622. const address4 = lastGroup.match(constants4.RE_ADDRESS);
  24623. if (address4) {
  24624. this.parsedAddress4 = address4[0];
  24625. this.address4 = new ipv4_1.Address4(this.parsedAddress4);
  24626. for (let i = 0; i < this.address4.groups; i++) {
  24627. if (/^0[0-9]+/.test(this.address4.parsedAddress[i])) {
  24628. throw new address_error_1.AddressError("IPv4 addresses can't have leading zeroes.", address.replace(constants4.RE_ADDRESS, this.address4.parsedAddress.map(spanLeadingZeroes4).join(".")));
  24629. }
  24630. }
  24631. this.v4 = true;
  24632. groups[groups.length - 1] = this.address4.toGroup6();
  24633. address = groups.join(":");
  24634. }
  24635. return address;
  24636. }
  24637. // TODO: Make private?
  24638. parse(address) {
  24639. address = this.parse4in6(address);
  24640. const badCharacters = address.match(constants6.RE_BAD_CHARACTERS);
  24641. if (badCharacters) {
  24642. throw new address_error_1.AddressError((0, sprintf_js_1.sprintf)("Bad character%s detected in address: %s", badCharacters.length > 1 ? "s" : "", badCharacters.join("")), address.replace(constants6.RE_BAD_CHARACTERS, '<span class="parse-error">$1</span>'));
  24643. }
  24644. const badAddress = address.match(constants6.RE_BAD_ADDRESS);
  24645. if (badAddress) {
  24646. throw new address_error_1.AddressError((0, sprintf_js_1.sprintf)("Address failed regex: %s", badAddress.join("")), address.replace(constants6.RE_BAD_ADDRESS, '<span class="parse-error">$1</span>'));
  24647. }
  24648. let groups = [];
  24649. const halves = address.split("::");
  24650. if (halves.length === 2) {
  24651. let first = halves[0].split(":");
  24652. let last = halves[1].split(":");
  24653. if (first.length === 1 && first[0] === "") {
  24654. first = [];
  24655. }
  24656. if (last.length === 1 && last[0] === "") {
  24657. last = [];
  24658. }
  24659. const remaining = this.groups - (first.length + last.length);
  24660. if (!remaining) {
  24661. throw new address_error_1.AddressError("Error parsing groups");
  24662. }
  24663. this.elidedGroups = remaining;
  24664. this.elisionBegin = first.length;
  24665. this.elisionEnd = first.length + this.elidedGroups;
  24666. groups = groups.concat(first);
  24667. for (let i = 0; i < remaining; i++) {
  24668. groups.push("0");
  24669. }
  24670. groups = groups.concat(last);
  24671. } else if (halves.length === 1) {
  24672. groups = address.split(":");
  24673. this.elidedGroups = 0;
  24674. } else {
  24675. throw new address_error_1.AddressError("Too many :: groups found");
  24676. }
  24677. groups = groups.map((group) => (0, sprintf_js_1.sprintf)("%x", parseInt(group, 16)));
  24678. if (groups.length !== this.groups) {
  24679. throw new address_error_1.AddressError("Incorrect number of groups found");
  24680. }
  24681. return groups;
  24682. }
  24683. /**
  24684. * Return the canonical form of the address
  24685. * @memberof Address6
  24686. * @instance
  24687. * @returns {String}
  24688. */
  24689. canonicalForm() {
  24690. return this.parsedAddress.map(paddedHex).join(":");
  24691. }
  24692. /**
  24693. * Return the decimal form of the address
  24694. * @memberof Address6
  24695. * @instance
  24696. * @returns {String}
  24697. */
  24698. decimal() {
  24699. return this.parsedAddress.map((n) => (0, sprintf_js_1.sprintf)("%05d", parseInt(n, 16))).join(":");
  24700. }
  24701. /**
  24702. * Return the address as a BigInteger
  24703. * @memberof Address6
  24704. * @instance
  24705. * @returns {BigInteger}
  24706. */
  24707. bigInteger() {
  24708. return new jsbn_1.BigInteger(this.parsedAddress.map(paddedHex).join(""), 16);
  24709. }
  24710. /**
  24711. * Return the last two groups of this address as an IPv4 address string
  24712. * @memberof Address6
  24713. * @instance
  24714. * @returns {Address4}
  24715. * @example
  24716. * var address = new Address6('2001:4860:4001::1825:bf11');
  24717. * address.to4().correctForm(); // '24.37.191.17'
  24718. */
  24719. to4() {
  24720. const binary = this.binaryZeroPad().split("");
  24721. return ipv4_1.Address4.fromHex(new jsbn_1.BigInteger(binary.slice(96, 128).join(""), 2).toString(16));
  24722. }
  24723. /**
  24724. * Return the v4-in-v6 form of the address
  24725. * @memberof Address6
  24726. * @instance
  24727. * @returns {String}
  24728. */
  24729. to4in6() {
  24730. const address4 = this.to4();
  24731. const address6 = new _Address6(this.parsedAddress.slice(0, 6).join(":"), 6);
  24732. const correct = address6.correctForm();
  24733. let infix = "";
  24734. if (!/:$/.test(correct)) {
  24735. infix = ":";
  24736. }
  24737. return correct + infix + address4.address;
  24738. }
  24739. /**
  24740. * Return an object containing the Teredo properties of the address
  24741. * @memberof Address6
  24742. * @instance
  24743. * @returns {Object}
  24744. */
  24745. inspectTeredo() {
  24746. const prefix = this.getBitsBase16(0, 32);
  24747. const udpPort = this.getBits(80, 96).xor(new jsbn_1.BigInteger("ffff", 16)).toString();
  24748. const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64));
  24749. const client4 = ipv4_1.Address4.fromHex(this.getBits(96, 128).xor(new jsbn_1.BigInteger("ffffffff", 16)).toString(16));
  24750. const flags = this.getBits(64, 80);
  24751. const flagsBase2 = this.getBitsBase2(64, 80);
  24752. const coneNat = flags.testBit(15);
  24753. const reserved = flags.testBit(14);
  24754. const groupIndividual = flags.testBit(8);
  24755. const universalLocal = flags.testBit(9);
  24756. const nonce = new jsbn_1.BigInteger(flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16), 2).toString(10);
  24757. return {
  24758. prefix: (0, sprintf_js_1.sprintf)("%s:%s", prefix.slice(0, 4), prefix.slice(4, 8)),
  24759. server4: server4.address,
  24760. client4: client4.address,
  24761. flags: flagsBase2,
  24762. coneNat,
  24763. microsoft: {
  24764. reserved,
  24765. universalLocal,
  24766. groupIndividual,
  24767. nonce
  24768. },
  24769. udpPort
  24770. };
  24771. }
  24772. /**
  24773. * Return an object containing the 6to4 properties of the address
  24774. * @memberof Address6
  24775. * @instance
  24776. * @returns {Object}
  24777. */
  24778. inspect6to4() {
  24779. const prefix = this.getBitsBase16(0, 16);
  24780. const gateway = ipv4_1.Address4.fromHex(this.getBitsBase16(16, 48));
  24781. return {
  24782. prefix: (0, sprintf_js_1.sprintf)("%s", prefix.slice(0, 4)),
  24783. gateway: gateway.address
  24784. };
  24785. }
  24786. /**
  24787. * Return a v6 6to4 address from a v6 v4inv6 address
  24788. * @memberof Address6
  24789. * @instance
  24790. * @returns {Address6}
  24791. */
  24792. to6to4() {
  24793. if (!this.is4()) {
  24794. return null;
  24795. }
  24796. const addr6to4 = [
  24797. "2002",
  24798. this.getBitsBase16(96, 112),
  24799. this.getBitsBase16(112, 128),
  24800. "",
  24801. "/16"
  24802. ].join(":");
  24803. return new _Address6(addr6to4);
  24804. }
  24805. /**
  24806. * Return a byte array
  24807. * @memberof Address6
  24808. * @instance
  24809. * @returns {Array}
  24810. */
  24811. toByteArray() {
  24812. const byteArray = this.bigInteger().toByteArray();
  24813. if (byteArray.length === 17 && byteArray[0] === 0) {
  24814. return byteArray.slice(1);
  24815. }
  24816. return byteArray;
  24817. }
  24818. /**
  24819. * Return an unsigned byte array
  24820. * @memberof Address6
  24821. * @instance
  24822. * @returns {Array}
  24823. */
  24824. toUnsignedByteArray() {
  24825. return this.toByteArray().map(unsignByte);
  24826. }
  24827. /**
  24828. * Convert a byte array to an Address6 object
  24829. * @memberof Address6
  24830. * @static
  24831. * @returns {Address6}
  24832. */
  24833. static fromByteArray(bytes) {
  24834. return this.fromUnsignedByteArray(bytes.map(unsignByte));
  24835. }
  24836. /**
  24837. * Convert an unsigned byte array to an Address6 object
  24838. * @memberof Address6
  24839. * @static
  24840. * @returns {Address6}
  24841. */
  24842. static fromUnsignedByteArray(bytes) {
  24843. const BYTE_MAX = new jsbn_1.BigInteger("256", 10);
  24844. let result = new jsbn_1.BigInteger("0", 10);
  24845. let multiplier = new jsbn_1.BigInteger("1", 10);
  24846. for (let i = bytes.length - 1; i >= 0; i--) {
  24847. result = result.add(multiplier.multiply(new jsbn_1.BigInteger(bytes[i].toString(10), 10)));
  24848. multiplier = multiplier.multiply(BYTE_MAX);
  24849. }
  24850. return _Address6.fromBigInteger(result);
  24851. }
  24852. /**
  24853. * Returns true if the address is in the canonical form, false otherwise
  24854. * @memberof Address6
  24855. * @instance
  24856. * @returns {boolean}
  24857. */
  24858. isCanonical() {
  24859. return this.addressMinusSuffix === this.canonicalForm();
  24860. }
  24861. /**
  24862. * Returns true if the address is a link local address, false otherwise
  24863. * @memberof Address6
  24864. * @instance
  24865. * @returns {boolean}
  24866. */
  24867. isLinkLocal() {
  24868. if (this.getBitsBase2(0, 64) === "1111111010000000000000000000000000000000000000000000000000000000") {
  24869. return true;
  24870. }
  24871. return false;
  24872. }
  24873. /**
  24874. * Returns true if the address is a multicast address, false otherwise
  24875. * @memberof Address6
  24876. * @instance
  24877. * @returns {boolean}
  24878. */
  24879. isMulticast() {
  24880. return this.getType() === "Multicast";
  24881. }
  24882. /**
  24883. * Returns true if the address is a v4-in-v6 address, false otherwise
  24884. * @memberof Address6
  24885. * @instance
  24886. * @returns {boolean}
  24887. */
  24888. is4() {
  24889. return this.v4;
  24890. }
  24891. /**
  24892. * Returns true if the address is a Teredo address, false otherwise
  24893. * @memberof Address6
  24894. * @instance
  24895. * @returns {boolean}
  24896. */
  24897. isTeredo() {
  24898. return this.isInSubnet(new _Address6("2001::/32"));
  24899. }
  24900. /**
  24901. * Returns true if the address is a 6to4 address, false otherwise
  24902. * @memberof Address6
  24903. * @instance
  24904. * @returns {boolean}
  24905. */
  24906. is6to4() {
  24907. return this.isInSubnet(new _Address6("2002::/16"));
  24908. }
  24909. /**
  24910. * Returns true if the address is a loopback address, false otherwise
  24911. * @memberof Address6
  24912. * @instance
  24913. * @returns {boolean}
  24914. */
  24915. isLoopback() {
  24916. return this.getType() === "Loopback";
  24917. }
  24918. // #endregion
  24919. // #region HTML
  24920. /**
  24921. * @returns {String} the address in link form with a default port of 80
  24922. */
  24923. href(optionalPort) {
  24924. if (optionalPort === void 0) {
  24925. optionalPort = "";
  24926. } else {
  24927. optionalPort = (0, sprintf_js_1.sprintf)(":%s", optionalPort);
  24928. }
  24929. return (0, sprintf_js_1.sprintf)("http://[%s]%s/", this.correctForm(), optionalPort);
  24930. }
  24931. /**
  24932. * @returns {String} a link suitable for conveying the address via a URL hash
  24933. */
  24934. link(options) {
  24935. if (!options) {
  24936. options = {};
  24937. }
  24938. if (options.className === void 0) {
  24939. options.className = "";
  24940. }
  24941. if (options.prefix === void 0) {
  24942. options.prefix = "/#address=";
  24943. }
  24944. if (options.v4 === void 0) {
  24945. options.v4 = false;
  24946. }
  24947. let formFunction = this.correctForm;
  24948. if (options.v4) {
  24949. formFunction = this.to4in6;
  24950. }
  24951. if (options.className) {
  24952. return (0, sprintf_js_1.sprintf)('<a href="%1$s%2$s" class="%3$s">%2$s</a>', options.prefix, formFunction.call(this), options.className);
  24953. }
  24954. return (0, sprintf_js_1.sprintf)('<a href="%1$s%2$s">%2$s</a>', options.prefix, formFunction.call(this));
  24955. }
  24956. /**
  24957. * Groups an address
  24958. * @returns {String}
  24959. */
  24960. group() {
  24961. if (this.elidedGroups === 0) {
  24962. return helpers.simpleGroup(this.address).join(":");
  24963. }
  24964. assert(typeof this.elidedGroups === "number");
  24965. assert(typeof this.elisionBegin === "number");
  24966. const output = [];
  24967. const [left, right] = this.address.split("::");
  24968. if (left.length) {
  24969. output.push(...helpers.simpleGroup(left));
  24970. } else {
  24971. output.push("");
  24972. }
  24973. const classes = ["hover-group"];
  24974. for (let i = this.elisionBegin; i < this.elisionBegin + this.elidedGroups; i++) {
  24975. classes.push((0, sprintf_js_1.sprintf)("group-%d", i));
  24976. }
  24977. output.push((0, sprintf_js_1.sprintf)('<span class="%s"></span>', classes.join(" ")));
  24978. if (right.length) {
  24979. output.push(...helpers.simpleGroup(right, this.elisionEnd));
  24980. } else {
  24981. output.push("");
  24982. }
  24983. if (this.is4()) {
  24984. assert(this.address4 instanceof ipv4_1.Address4);
  24985. output.pop();
  24986. output.push(this.address4.groupForV6());
  24987. }
  24988. return output.join(":");
  24989. }
  24990. // #endregion
  24991. // #region Regular expressions
  24992. /**
  24993. * Generate a regular expression string that can be used to find or validate
  24994. * all variations of this address
  24995. * @memberof Address6
  24996. * @instance
  24997. * @param {boolean} substringSearch
  24998. * @returns {string}
  24999. */
  25000. regularExpressionString(substringSearch = false) {
  25001. let output = [];
  25002. const address6 = new _Address6(this.correctForm());
  25003. if (address6.elidedGroups === 0) {
  25004. output.push((0, regular_expressions_1.simpleRegularExpression)(address6.parsedAddress));
  25005. } else if (address6.elidedGroups === constants6.GROUPS) {
  25006. output.push((0, regular_expressions_1.possibleElisions)(constants6.GROUPS));
  25007. } else {
  25008. const halves = address6.address.split("::");
  25009. if (halves[0].length) {
  25010. output.push((0, regular_expressions_1.simpleRegularExpression)(halves[0].split(":")));
  25011. }
  25012. assert(typeof address6.elidedGroups === "number");
  25013. output.push((0, regular_expressions_1.possibleElisions)(address6.elidedGroups, halves[0].length !== 0, halves[1].length !== 0));
  25014. if (halves[1].length) {
  25015. output.push((0, regular_expressions_1.simpleRegularExpression)(halves[1].split(":")));
  25016. }
  25017. output = [output.join(":")];
  25018. }
  25019. if (!substringSearch) {
  25020. output = [
  25021. "(?=^|",
  25022. regular_expressions_1.ADDRESS_BOUNDARY,
  25023. "|[^\\w\\:])(",
  25024. ...output,
  25025. ")(?=[^\\w\\:]|",
  25026. regular_expressions_1.ADDRESS_BOUNDARY,
  25027. "|$)"
  25028. ];
  25029. }
  25030. return output.join("");
  25031. }
  25032. /**
  25033. * Generate a regular expression that can be used to find or validate all
  25034. * variations of this address.
  25035. * @memberof Address6
  25036. * @instance
  25037. * @param {boolean} substringSearch
  25038. * @returns {RegExp}
  25039. */
  25040. regularExpression(substringSearch = false) {
  25041. return new RegExp(this.regularExpressionString(substringSearch), "i");
  25042. }
  25043. };
  25044. exports2.Address6 = Address6;
  25045. }
  25046. });
  25047. // node_modules/ip-address/dist/ip-address.js
  25048. var require_ip_address = __commonJS({
  25049. "node_modules/ip-address/dist/ip-address.js"(exports2) {
  25050. "use strict";
  25051. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  25052. if (k2 === void 0) k2 = k;
  25053. var desc = Object.getOwnPropertyDescriptor(m, k);
  25054. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  25055. desc = { enumerable: true, get: function() {
  25056. return m[k];
  25057. } };
  25058. }
  25059. Object.defineProperty(o, k2, desc);
  25060. } : function(o, m, k, k2) {
  25061. if (k2 === void 0) k2 = k;
  25062. o[k2] = m[k];
  25063. });
  25064. var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) {
  25065. Object.defineProperty(o, "default", { enumerable: true, value: v });
  25066. } : function(o, v) {
  25067. o["default"] = v;
  25068. });
  25069. var __importStar = exports2 && exports2.__importStar || function(mod) {
  25070. if (mod && mod.__esModule) return mod;
  25071. var result = {};
  25072. if (mod != null) {
  25073. for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  25074. }
  25075. __setModuleDefault(result, mod);
  25076. return result;
  25077. };
  25078. Object.defineProperty(exports2, "__esModule", { value: true });
  25079. exports2.v6 = exports2.AddressError = exports2.Address6 = exports2.Address4 = void 0;
  25080. var ipv4_1 = require_ipv4();
  25081. Object.defineProperty(exports2, "Address4", { enumerable: true, get: function() {
  25082. return ipv4_1.Address4;
  25083. } });
  25084. var ipv6_1 = require_ipv6();
  25085. Object.defineProperty(exports2, "Address6", { enumerable: true, get: function() {
  25086. return ipv6_1.Address6;
  25087. } });
  25088. var address_error_1 = require_address_error();
  25089. Object.defineProperty(exports2, "AddressError", { enumerable: true, get: function() {
  25090. return address_error_1.AddressError;
  25091. } });
  25092. var helpers = __importStar(require_helpers());
  25093. exports2.v6 = { helpers };
  25094. }
  25095. });
  25096. // node_modules/socks/build/common/helpers.js
  25097. var require_helpers2 = __commonJS({
  25098. "node_modules/socks/build/common/helpers.js"(exports2) {
  25099. "use strict";
  25100. Object.defineProperty(exports2, "__esModule", { value: true });
  25101. exports2.ipToBuffer = exports2.int32ToIpv4 = exports2.ipv4ToInt32 = exports2.validateSocksClientChainOptions = exports2.validateSocksClientOptions = void 0;
  25102. var util_1 = require_util();
  25103. var constants_1 = require_constants3();
  25104. var stream = require("stream");
  25105. var ip_address_1 = require_ip_address();
  25106. var net = require("net");
  25107. function validateSocksClientOptions(options, acceptedCommands = ["connect", "bind", "associate"]) {
  25108. if (!constants_1.SocksCommand[options.command]) {
  25109. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksCommand, options);
  25110. }
  25111. if (acceptedCommands.indexOf(options.command) === -1) {
  25112. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksCommandForOperation, options);
  25113. }
  25114. if (!isValidSocksRemoteHost(options.destination)) {
  25115. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsDestination, options);
  25116. }
  25117. if (!isValidSocksProxy(options.proxy)) {
  25118. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsProxy, options);
  25119. }
  25120. validateCustomProxyAuth(options.proxy, options);
  25121. if (options.timeout && !isValidTimeoutValue(options.timeout)) {
  25122. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsTimeout, options);
  25123. }
  25124. if (options.existing_socket && !(options.existing_socket instanceof stream.Duplex)) {
  25125. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsExistingSocket, options);
  25126. }
  25127. }
  25128. exports2.validateSocksClientOptions = validateSocksClientOptions;
  25129. function validateSocksClientChainOptions(options) {
  25130. if (options.command !== "connect") {
  25131. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksCommandChain, options);
  25132. }
  25133. if (!isValidSocksRemoteHost(options.destination)) {
  25134. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsDestination, options);
  25135. }
  25136. if (!(options.proxies && Array.isArray(options.proxies) && options.proxies.length >= 2)) {
  25137. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsProxiesLength, options);
  25138. }
  25139. options.proxies.forEach((proxy) => {
  25140. if (!isValidSocksProxy(proxy)) {
  25141. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsProxy, options);
  25142. }
  25143. validateCustomProxyAuth(proxy, options);
  25144. });
  25145. if (options.timeout && !isValidTimeoutValue(options.timeout)) {
  25146. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsTimeout, options);
  25147. }
  25148. }
  25149. exports2.validateSocksClientChainOptions = validateSocksClientChainOptions;
  25150. function validateCustomProxyAuth(proxy, options) {
  25151. if (proxy.custom_auth_method !== void 0) {
  25152. if (proxy.custom_auth_method < constants_1.SOCKS5_CUSTOM_AUTH_START || proxy.custom_auth_method > constants_1.SOCKS5_CUSTOM_AUTH_END) {
  25153. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsCustomAuthRange, options);
  25154. }
  25155. if (proxy.custom_auth_request_handler === void 0 || typeof proxy.custom_auth_request_handler !== "function") {
  25156. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsCustomAuthOptions, options);
  25157. }
  25158. if (proxy.custom_auth_response_size === void 0) {
  25159. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsCustomAuthOptions, options);
  25160. }
  25161. if (proxy.custom_auth_response_handler === void 0 || typeof proxy.custom_auth_response_handler !== "function") {
  25162. throw new util_1.SocksClientError(constants_1.ERRORS.InvalidSocksClientOptionsCustomAuthOptions, options);
  25163. }
  25164. }
  25165. }
  25166. function isValidSocksRemoteHost(remoteHost) {
  25167. return remoteHost && typeof remoteHost.host === "string" && typeof remoteHost.port === "number" && remoteHost.port >= 0 && remoteHost.port <= 65535;
  25168. }
  25169. function isValidSocksProxy(proxy) {
  25170. return proxy && (typeof proxy.host === "string" || typeof proxy.ipaddress === "string") && typeof proxy.port === "number" && proxy.port >= 0 && proxy.port <= 65535 && (proxy.type === 4 || proxy.type === 5);
  25171. }
  25172. function isValidTimeoutValue(value) {
  25173. return typeof value === "number" && value > 0;
  25174. }
  25175. function ipv4ToInt32(ip) {
  25176. const address = new ip_address_1.Address4(ip);
  25177. return address.toArray().reduce((acc, part) => (acc << 8) + part, 0);
  25178. }
  25179. exports2.ipv4ToInt32 = ipv4ToInt32;
  25180. function int32ToIpv4(int32) {
  25181. const octet1 = int32 >>> 24 & 255;
  25182. const octet2 = int32 >>> 16 & 255;
  25183. const octet3 = int32 >>> 8 & 255;
  25184. const octet4 = int32 & 255;
  25185. return [octet1, octet2, octet3, octet4].join(".");
  25186. }
  25187. exports2.int32ToIpv4 = int32ToIpv4;
  25188. function ipToBuffer(ip) {
  25189. if (net.isIPv4(ip)) {
  25190. const address = new ip_address_1.Address4(ip);
  25191. return Buffer.from(address.toArray());
  25192. } else if (net.isIPv6(ip)) {
  25193. const address = new ip_address_1.Address6(ip);
  25194. return Buffer.from(address.canonicalForm().split(":").map((segment) => segment.padStart(4, "0")).join(""), "hex");
  25195. } else {
  25196. throw new Error("Invalid IP address format");
  25197. }
  25198. }
  25199. exports2.ipToBuffer = ipToBuffer;
  25200. }
  25201. });
  25202. // node_modules/socks/build/common/receivebuffer.js
  25203. var require_receivebuffer = __commonJS({
  25204. "node_modules/socks/build/common/receivebuffer.js"(exports2) {
  25205. "use strict";
  25206. Object.defineProperty(exports2, "__esModule", { value: true });
  25207. exports2.ReceiveBuffer = void 0;
  25208. var ReceiveBuffer = class {
  25209. constructor(size = 4096) {
  25210. this.buffer = Buffer.allocUnsafe(size);
  25211. this.offset = 0;
  25212. this.originalSize = size;
  25213. }
  25214. get length() {
  25215. return this.offset;
  25216. }
  25217. append(data) {
  25218. if (!Buffer.isBuffer(data)) {
  25219. throw new Error("Attempted to append a non-buffer instance to ReceiveBuffer.");
  25220. }
  25221. if (this.offset + data.length >= this.buffer.length) {
  25222. const tmp = this.buffer;
  25223. this.buffer = Buffer.allocUnsafe(Math.max(this.buffer.length + this.originalSize, this.buffer.length + data.length));
  25224. tmp.copy(this.buffer);
  25225. }
  25226. data.copy(this.buffer, this.offset);
  25227. return this.offset += data.length;
  25228. }
  25229. peek(length) {
  25230. if (length > this.offset) {
  25231. throw new Error("Attempted to read beyond the bounds of the managed internal data.");
  25232. }
  25233. return this.buffer.slice(0, length);
  25234. }
  25235. get(length) {
  25236. if (length > this.offset) {
  25237. throw new Error("Attempted to read beyond the bounds of the managed internal data.");
  25238. }
  25239. const value = Buffer.allocUnsafe(length);
  25240. this.buffer.slice(0, length).copy(value);
  25241. this.buffer.copyWithin(0, length, length + this.offset - length);
  25242. this.offset -= length;
  25243. return value;
  25244. }
  25245. };
  25246. exports2.ReceiveBuffer = ReceiveBuffer;
  25247. }
  25248. });
  25249. // node_modules/socks/build/client/socksclient.js
  25250. var require_socksclient = __commonJS({
  25251. "node_modules/socks/build/client/socksclient.js"(exports2) {
  25252. "use strict";
  25253. var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) {
  25254. function adopt(value) {
  25255. return value instanceof P ? value : new P(function(resolve) {
  25256. resolve(value);
  25257. });
  25258. }
  25259. return new (P || (P = Promise))(function(resolve, reject) {
  25260. function fulfilled(value) {
  25261. try {
  25262. step(generator.next(value));
  25263. } catch (e) {
  25264. reject(e);
  25265. }
  25266. }
  25267. function rejected(value) {
  25268. try {
  25269. step(generator["throw"](value));
  25270. } catch (e) {
  25271. reject(e);
  25272. }
  25273. }
  25274. function step(result) {
  25275. result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
  25276. }
  25277. step((generator = generator.apply(thisArg, _arguments || [])).next());
  25278. });
  25279. };
  25280. Object.defineProperty(exports2, "__esModule", { value: true });
  25281. exports2.SocksClientError = exports2.SocksClient = void 0;
  25282. var events_1 = require("events");
  25283. var net = require("net");
  25284. var smart_buffer_1 = require_smartbuffer();
  25285. var constants_1 = require_constants3();
  25286. var helpers_1 = require_helpers2();
  25287. var receivebuffer_1 = require_receivebuffer();
  25288. var util_1 = require_util();
  25289. Object.defineProperty(exports2, "SocksClientError", { enumerable: true, get: function() {
  25290. return util_1.SocksClientError;
  25291. } });
  25292. var ip_address_1 = require_ip_address();
  25293. var SocksClient = class _SocksClient extends events_1.EventEmitter {
  25294. constructor(options) {
  25295. super();
  25296. this.options = Object.assign({}, options);
  25297. (0, helpers_1.validateSocksClientOptions)(options);
  25298. this.setState(constants_1.SocksClientState.Created);
  25299. }
  25300. /**
  25301. * Creates a new SOCKS connection.
  25302. *
  25303. * Note: Supports callbacks and promises. Only supports the connect command.
  25304. * @param options { SocksClientOptions } Options.
  25305. * @param callback { Function } An optional callback function.
  25306. * @returns { Promise }
  25307. */
  25308. static createConnection(options, callback) {
  25309. return new Promise((resolve, reject) => {
  25310. try {
  25311. (0, helpers_1.validateSocksClientOptions)(options, ["connect"]);
  25312. } catch (err) {
  25313. if (typeof callback === "function") {
  25314. callback(err);
  25315. return resolve(err);
  25316. } else {
  25317. return reject(err);
  25318. }
  25319. }
  25320. const client = new _SocksClient(options);
  25321. client.connect(options.existing_socket);
  25322. client.once("established", (info) => {
  25323. client.removeAllListeners();
  25324. if (typeof callback === "function") {
  25325. callback(null, info);
  25326. resolve(info);
  25327. } else {
  25328. resolve(info);
  25329. }
  25330. });
  25331. client.once("error", (err) => {
  25332. client.removeAllListeners();
  25333. if (typeof callback === "function") {
  25334. callback(err);
  25335. resolve(err);
  25336. } else {
  25337. reject(err);
  25338. }
  25339. });
  25340. });
  25341. }
  25342. /**
  25343. * Creates a new SOCKS connection chain to a destination host through 2 or more SOCKS proxies.
  25344. *
  25345. * Note: Supports callbacks and promises. Only supports the connect method.
  25346. * Note: Implemented via createConnection() factory function.
  25347. * @param options { SocksClientChainOptions } Options
  25348. * @param callback { Function } An optional callback function.
  25349. * @returns { Promise }
  25350. */
  25351. static createConnectionChain(options, callback) {
  25352. return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
  25353. try {
  25354. (0, helpers_1.validateSocksClientChainOptions)(options);
  25355. } catch (err) {
  25356. if (typeof callback === "function") {
  25357. callback(err);
  25358. return resolve(err);
  25359. } else {
  25360. return reject(err);
  25361. }
  25362. }
  25363. if (options.randomizeChain) {
  25364. (0, util_1.shuffleArray)(options.proxies);
  25365. }
  25366. try {
  25367. let sock;
  25368. for (let i = 0; i < options.proxies.length; i++) {
  25369. const nextProxy = options.proxies[i];
  25370. const nextDestination = i === options.proxies.length - 1 ? options.destination : {
  25371. host: options.proxies[i + 1].host || options.proxies[i + 1].ipaddress,
  25372. port: options.proxies[i + 1].port
  25373. };
  25374. const result = yield _SocksClient.createConnection({
  25375. command: "connect",
  25376. proxy: nextProxy,
  25377. destination: nextDestination,
  25378. existing_socket: sock
  25379. });
  25380. sock = sock || result.socket;
  25381. }
  25382. if (typeof callback === "function") {
  25383. callback(null, { socket: sock });
  25384. resolve({ socket: sock });
  25385. } else {
  25386. resolve({ socket: sock });
  25387. }
  25388. } catch (err) {
  25389. if (typeof callback === "function") {
  25390. callback(err);
  25391. resolve(err);
  25392. } else {
  25393. reject(err);
  25394. }
  25395. }
  25396. }));
  25397. }
  25398. /**
  25399. * Creates a SOCKS UDP Frame.
  25400. * @param options
  25401. */
  25402. static createUDPFrame(options) {
  25403. const buff = new smart_buffer_1.SmartBuffer();
  25404. buff.writeUInt16BE(0);
  25405. buff.writeUInt8(options.frameNumber || 0);
  25406. if (net.isIPv4(options.remoteHost.host)) {
  25407. buff.writeUInt8(constants_1.Socks5HostType.IPv4);
  25408. buff.writeUInt32BE((0, helpers_1.ipv4ToInt32)(options.remoteHost.host));
  25409. } else if (net.isIPv6(options.remoteHost.host)) {
  25410. buff.writeUInt8(constants_1.Socks5HostType.IPv6);
  25411. buff.writeBuffer((0, helpers_1.ipToBuffer)(options.remoteHost.host));
  25412. } else {
  25413. buff.writeUInt8(constants_1.Socks5HostType.Hostname);
  25414. buff.writeUInt8(Buffer.byteLength(options.remoteHost.host));
  25415. buff.writeString(options.remoteHost.host);
  25416. }
  25417. buff.writeUInt16BE(options.remoteHost.port);
  25418. buff.writeBuffer(options.data);
  25419. return buff.toBuffer();
  25420. }
  25421. /**
  25422. * Parses a SOCKS UDP frame.
  25423. * @param data
  25424. */
  25425. static parseUDPFrame(data) {
  25426. const buff = smart_buffer_1.SmartBuffer.fromBuffer(data);
  25427. buff.readOffset = 2;
  25428. const frameNumber = buff.readUInt8();
  25429. const hostType = buff.readUInt8();
  25430. let remoteHost;
  25431. if (hostType === constants_1.Socks5HostType.IPv4) {
  25432. remoteHost = (0, helpers_1.int32ToIpv4)(buff.readUInt32BE());
  25433. } else if (hostType === constants_1.Socks5HostType.IPv6) {
  25434. remoteHost = ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm();
  25435. } else {
  25436. remoteHost = buff.readString(buff.readUInt8());
  25437. }
  25438. const remotePort = buff.readUInt16BE();
  25439. return {
  25440. frameNumber,
  25441. remoteHost: {
  25442. host: remoteHost,
  25443. port: remotePort
  25444. },
  25445. data: buff.readBuffer()
  25446. };
  25447. }
  25448. /**
  25449. * Internal state setter. If the SocksClient is in an error state, it cannot be changed to a non error state.
  25450. */
  25451. setState(newState) {
  25452. if (this.state !== constants_1.SocksClientState.Error) {
  25453. this.state = newState;
  25454. }
  25455. }
  25456. /**
  25457. * Starts the connection establishment to the proxy and destination.
  25458. * @param existingSocket Connected socket to use instead of creating a new one (internal use).
  25459. */
  25460. connect(existingSocket) {
  25461. this.onDataReceived = (data) => this.onDataReceivedHandler(data);
  25462. this.onClose = () => this.onCloseHandler();
  25463. this.onError = (err) => this.onErrorHandler(err);
  25464. this.onConnect = () => this.onConnectHandler();
  25465. const timer = setTimeout(() => this.onEstablishedTimeout(), this.options.timeout || constants_1.DEFAULT_TIMEOUT);
  25466. if (timer.unref && typeof timer.unref === "function") {
  25467. timer.unref();
  25468. }
  25469. if (existingSocket) {
  25470. this.socket = existingSocket;
  25471. } else {
  25472. this.socket = new net.Socket();
  25473. }
  25474. this.socket.once("close", this.onClose);
  25475. this.socket.once("error", this.onError);
  25476. this.socket.once("connect", this.onConnect);
  25477. this.socket.on("data", this.onDataReceived);
  25478. this.setState(constants_1.SocksClientState.Connecting);
  25479. this.receiveBuffer = new receivebuffer_1.ReceiveBuffer();
  25480. if (existingSocket) {
  25481. this.socket.emit("connect");
  25482. } else {
  25483. this.socket.connect(this.getSocketOptions());
  25484. if (this.options.set_tcp_nodelay !== void 0 && this.options.set_tcp_nodelay !== null) {
  25485. this.socket.setNoDelay(!!this.options.set_tcp_nodelay);
  25486. }
  25487. }
  25488. this.prependOnceListener("established", (info) => {
  25489. setImmediate(() => {
  25490. if (this.receiveBuffer.length > 0) {
  25491. const excessData = this.receiveBuffer.get(this.receiveBuffer.length);
  25492. info.socket.emit("data", excessData);
  25493. }
  25494. info.socket.resume();
  25495. });
  25496. });
  25497. }
  25498. // Socket options (defaults host/port to options.proxy.host/options.proxy.port)
  25499. getSocketOptions() {
  25500. return Object.assign(Object.assign({}, this.options.socket_options), { host: this.options.proxy.host || this.options.proxy.ipaddress, port: this.options.proxy.port });
  25501. }
  25502. /**
  25503. * Handles internal Socks timeout callback.
  25504. * Note: If the Socks client is not BoundWaitingForConnection or Established, the connection will be closed.
  25505. */
  25506. onEstablishedTimeout() {
  25507. if (this.state !== constants_1.SocksClientState.Established && this.state !== constants_1.SocksClientState.BoundWaitingForConnection) {
  25508. this.closeSocket(constants_1.ERRORS.ProxyConnectionTimedOut);
  25509. }
  25510. }
  25511. /**
  25512. * Handles Socket connect event.
  25513. */
  25514. onConnectHandler() {
  25515. this.setState(constants_1.SocksClientState.Connected);
  25516. if (this.options.proxy.type === 4) {
  25517. this.sendSocks4InitialHandshake();
  25518. } else {
  25519. this.sendSocks5InitialHandshake();
  25520. }
  25521. this.setState(constants_1.SocksClientState.SentInitialHandshake);
  25522. }
  25523. /**
  25524. * Handles Socket data event.
  25525. * @param data
  25526. */
  25527. onDataReceivedHandler(data) {
  25528. this.receiveBuffer.append(data);
  25529. this.processData();
  25530. }
  25531. /**
  25532. * Handles processing of the data we have received.
  25533. */
  25534. processData() {
  25535. while (this.state !== constants_1.SocksClientState.Established && this.state !== constants_1.SocksClientState.Error && this.receiveBuffer.length >= this.nextRequiredPacketBufferSize) {
  25536. if (this.state === constants_1.SocksClientState.SentInitialHandshake) {
  25537. if (this.options.proxy.type === 4) {
  25538. this.handleSocks4FinalHandshakeResponse();
  25539. } else {
  25540. this.handleInitialSocks5HandshakeResponse();
  25541. }
  25542. } else if (this.state === constants_1.SocksClientState.SentAuthentication) {
  25543. this.handleInitialSocks5AuthenticationHandshakeResponse();
  25544. } else if (this.state === constants_1.SocksClientState.SentFinalHandshake) {
  25545. this.handleSocks5FinalHandshakeResponse();
  25546. } else if (this.state === constants_1.SocksClientState.BoundWaitingForConnection) {
  25547. if (this.options.proxy.type === 4) {
  25548. this.handleSocks4IncomingConnectionResponse();
  25549. } else {
  25550. this.handleSocks5IncomingConnectionResponse();
  25551. }
  25552. } else {
  25553. this.closeSocket(constants_1.ERRORS.InternalError);
  25554. break;
  25555. }
  25556. }
  25557. }
  25558. /**
  25559. * Handles Socket close event.
  25560. * @param had_error
  25561. */
  25562. onCloseHandler() {
  25563. this.closeSocket(constants_1.ERRORS.SocketClosed);
  25564. }
  25565. /**
  25566. * Handles Socket error event.
  25567. * @param err
  25568. */
  25569. onErrorHandler(err) {
  25570. this.closeSocket(err.message);
  25571. }
  25572. /**
  25573. * Removes internal event listeners on the underlying Socket.
  25574. */
  25575. removeInternalSocketHandlers() {
  25576. this.socket.pause();
  25577. this.socket.removeListener("data", this.onDataReceived);
  25578. this.socket.removeListener("close", this.onClose);
  25579. this.socket.removeListener("error", this.onError);
  25580. this.socket.removeListener("connect", this.onConnect);
  25581. }
  25582. /**
  25583. * Closes and destroys the underlying Socket. Emits an error event.
  25584. * @param err { String } An error string to include in error event.
  25585. */
  25586. closeSocket(err) {
  25587. if (this.state !== constants_1.SocksClientState.Error) {
  25588. this.setState(constants_1.SocksClientState.Error);
  25589. this.socket.destroy();
  25590. this.removeInternalSocketHandlers();
  25591. this.emit("error", new util_1.SocksClientError(err, this.options));
  25592. }
  25593. }
  25594. /**
  25595. * Sends initial Socks v4 handshake request.
  25596. */
  25597. sendSocks4InitialHandshake() {
  25598. const userId = this.options.proxy.userId || "";
  25599. const buff = new smart_buffer_1.SmartBuffer();
  25600. buff.writeUInt8(4);
  25601. buff.writeUInt8(constants_1.SocksCommand[this.options.command]);
  25602. buff.writeUInt16BE(this.options.destination.port);
  25603. if (net.isIPv4(this.options.destination.host)) {
  25604. buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host));
  25605. buff.writeStringNT(userId);
  25606. } else {
  25607. buff.writeUInt8(0);
  25608. buff.writeUInt8(0);
  25609. buff.writeUInt8(0);
  25610. buff.writeUInt8(1);
  25611. buff.writeStringNT(userId);
  25612. buff.writeStringNT(this.options.destination.host);
  25613. }
  25614. this.nextRequiredPacketBufferSize = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks4Response;
  25615. this.socket.write(buff.toBuffer());
  25616. }
  25617. /**
  25618. * Handles Socks v4 handshake response.
  25619. * @param data
  25620. */
  25621. handleSocks4FinalHandshakeResponse() {
  25622. const data = this.receiveBuffer.get(8);
  25623. if (data[1] !== constants_1.Socks4Response.Granted) {
  25624. this.closeSocket(`${constants_1.ERRORS.Socks4ProxyRejectedConnection} - (${constants_1.Socks4Response[data[1]]})`);
  25625. } else {
  25626. if (constants_1.SocksCommand[this.options.command] === constants_1.SocksCommand.bind) {
  25627. const buff = smart_buffer_1.SmartBuffer.fromBuffer(data);
  25628. buff.readOffset = 2;
  25629. const remoteHost = {
  25630. port: buff.readUInt16BE(),
  25631. host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE())
  25632. };
  25633. if (remoteHost.host === "0.0.0.0") {
  25634. remoteHost.host = this.options.proxy.ipaddress;
  25635. }
  25636. this.setState(constants_1.SocksClientState.BoundWaitingForConnection);
  25637. this.emit("bound", { remoteHost, socket: this.socket });
  25638. } else {
  25639. this.setState(constants_1.SocksClientState.Established);
  25640. this.removeInternalSocketHandlers();
  25641. this.emit("established", { socket: this.socket });
  25642. }
  25643. }
  25644. }
  25645. /**
  25646. * Handles Socks v4 incoming connection request (BIND)
  25647. * @param data
  25648. */
  25649. handleSocks4IncomingConnectionResponse() {
  25650. const data = this.receiveBuffer.get(8);
  25651. if (data[1] !== constants_1.Socks4Response.Granted) {
  25652. this.closeSocket(`${constants_1.ERRORS.Socks4ProxyRejectedIncomingBoundConnection} - (${constants_1.Socks4Response[data[1]]})`);
  25653. } else {
  25654. const buff = smart_buffer_1.SmartBuffer.fromBuffer(data);
  25655. buff.readOffset = 2;
  25656. const remoteHost = {
  25657. port: buff.readUInt16BE(),
  25658. host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE())
  25659. };
  25660. this.setState(constants_1.SocksClientState.Established);
  25661. this.removeInternalSocketHandlers();
  25662. this.emit("established", { remoteHost, socket: this.socket });
  25663. }
  25664. }
  25665. /**
  25666. * Sends initial Socks v5 handshake request.
  25667. */
  25668. sendSocks5InitialHandshake() {
  25669. const buff = new smart_buffer_1.SmartBuffer();
  25670. const supportedAuthMethods = [constants_1.Socks5Auth.NoAuth];
  25671. if (this.options.proxy.userId || this.options.proxy.password) {
  25672. supportedAuthMethods.push(constants_1.Socks5Auth.UserPass);
  25673. }
  25674. if (this.options.proxy.custom_auth_method !== void 0) {
  25675. supportedAuthMethods.push(this.options.proxy.custom_auth_method);
  25676. }
  25677. buff.writeUInt8(5);
  25678. buff.writeUInt8(supportedAuthMethods.length);
  25679. for (const authMethod of supportedAuthMethods) {
  25680. buff.writeUInt8(authMethod);
  25681. }
  25682. this.nextRequiredPacketBufferSize = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5InitialHandshakeResponse;
  25683. this.socket.write(buff.toBuffer());
  25684. this.setState(constants_1.SocksClientState.SentInitialHandshake);
  25685. }
  25686. /**
  25687. * Handles initial Socks v5 handshake response.
  25688. * @param data
  25689. */
  25690. handleInitialSocks5HandshakeResponse() {
  25691. const data = this.receiveBuffer.get(2);
  25692. if (data[0] !== 5) {
  25693. this.closeSocket(constants_1.ERRORS.InvalidSocks5IntiailHandshakeSocksVersion);
  25694. } else if (data[1] === constants_1.SOCKS5_NO_ACCEPTABLE_AUTH) {
  25695. this.closeSocket(constants_1.ERRORS.InvalidSocks5InitialHandshakeNoAcceptedAuthType);
  25696. } else {
  25697. if (data[1] === constants_1.Socks5Auth.NoAuth) {
  25698. this.socks5ChosenAuthType = constants_1.Socks5Auth.NoAuth;
  25699. this.sendSocks5CommandRequest();
  25700. } else if (data[1] === constants_1.Socks5Auth.UserPass) {
  25701. this.socks5ChosenAuthType = constants_1.Socks5Auth.UserPass;
  25702. this.sendSocks5UserPassAuthentication();
  25703. } else if (data[1] === this.options.proxy.custom_auth_method) {
  25704. this.socks5ChosenAuthType = this.options.proxy.custom_auth_method;
  25705. this.sendSocks5CustomAuthentication();
  25706. } else {
  25707. this.closeSocket(constants_1.ERRORS.InvalidSocks5InitialHandshakeUnknownAuthType);
  25708. }
  25709. }
  25710. }
  25711. /**
  25712. * Sends Socks v5 user & password auth handshake.
  25713. *
  25714. * Note: No auth and user/pass are currently supported.
  25715. */
  25716. sendSocks5UserPassAuthentication() {
  25717. const userId = this.options.proxy.userId || "";
  25718. const password = this.options.proxy.password || "";
  25719. const buff = new smart_buffer_1.SmartBuffer();
  25720. buff.writeUInt8(1);
  25721. buff.writeUInt8(Buffer.byteLength(userId));
  25722. buff.writeString(userId);
  25723. buff.writeUInt8(Buffer.byteLength(password));
  25724. buff.writeString(password);
  25725. this.nextRequiredPacketBufferSize = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5UserPassAuthenticationResponse;
  25726. this.socket.write(buff.toBuffer());
  25727. this.setState(constants_1.SocksClientState.SentAuthentication);
  25728. }
  25729. sendSocks5CustomAuthentication() {
  25730. return __awaiter(this, void 0, void 0, function* () {
  25731. this.nextRequiredPacketBufferSize = this.options.proxy.custom_auth_response_size;
  25732. this.socket.write(yield this.options.proxy.custom_auth_request_handler());
  25733. this.setState(constants_1.SocksClientState.SentAuthentication);
  25734. });
  25735. }
  25736. handleSocks5CustomAuthHandshakeResponse(data) {
  25737. return __awaiter(this, void 0, void 0, function* () {
  25738. return yield this.options.proxy.custom_auth_response_handler(data);
  25739. });
  25740. }
  25741. handleSocks5AuthenticationNoAuthHandshakeResponse(data) {
  25742. return __awaiter(this, void 0, void 0, function* () {
  25743. return data[1] === 0;
  25744. });
  25745. }
  25746. handleSocks5AuthenticationUserPassHandshakeResponse(data) {
  25747. return __awaiter(this, void 0, void 0, function* () {
  25748. return data[1] === 0;
  25749. });
  25750. }
  25751. /**
  25752. * Handles Socks v5 auth handshake response.
  25753. * @param data
  25754. */
  25755. handleInitialSocks5AuthenticationHandshakeResponse() {
  25756. return __awaiter(this, void 0, void 0, function* () {
  25757. this.setState(constants_1.SocksClientState.ReceivedAuthenticationResponse);
  25758. let authResult = false;
  25759. if (this.socks5ChosenAuthType === constants_1.Socks5Auth.NoAuth) {
  25760. authResult = yield this.handleSocks5AuthenticationNoAuthHandshakeResponse(this.receiveBuffer.get(2));
  25761. } else if (this.socks5ChosenAuthType === constants_1.Socks5Auth.UserPass) {
  25762. authResult = yield this.handleSocks5AuthenticationUserPassHandshakeResponse(this.receiveBuffer.get(2));
  25763. } else if (this.socks5ChosenAuthType === this.options.proxy.custom_auth_method) {
  25764. authResult = yield this.handleSocks5CustomAuthHandshakeResponse(this.receiveBuffer.get(this.options.proxy.custom_auth_response_size));
  25765. }
  25766. if (!authResult) {
  25767. this.closeSocket(constants_1.ERRORS.Socks5AuthenticationFailed);
  25768. } else {
  25769. this.sendSocks5CommandRequest();
  25770. }
  25771. });
  25772. }
  25773. /**
  25774. * Sends Socks v5 final handshake request.
  25775. */
  25776. sendSocks5CommandRequest() {
  25777. const buff = new smart_buffer_1.SmartBuffer();
  25778. buff.writeUInt8(5);
  25779. buff.writeUInt8(constants_1.SocksCommand[this.options.command]);
  25780. buff.writeUInt8(0);
  25781. if (net.isIPv4(this.options.destination.host)) {
  25782. buff.writeUInt8(constants_1.Socks5HostType.IPv4);
  25783. buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host));
  25784. } else if (net.isIPv6(this.options.destination.host)) {
  25785. buff.writeUInt8(constants_1.Socks5HostType.IPv6);
  25786. buff.writeBuffer((0, helpers_1.ipToBuffer)(this.options.destination.host));
  25787. } else {
  25788. buff.writeUInt8(constants_1.Socks5HostType.Hostname);
  25789. buff.writeUInt8(this.options.destination.host.length);
  25790. buff.writeString(this.options.destination.host);
  25791. }
  25792. buff.writeUInt16BE(this.options.destination.port);
  25793. this.nextRequiredPacketBufferSize = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
  25794. this.socket.write(buff.toBuffer());
  25795. this.setState(constants_1.SocksClientState.SentFinalHandshake);
  25796. }
  25797. /**
  25798. * Handles Socks v5 final handshake response.
  25799. * @param data
  25800. */
  25801. handleSocks5FinalHandshakeResponse() {
  25802. const header = this.receiveBuffer.peek(5);
  25803. if (header[0] !== 5 || header[1] !== constants_1.Socks5Response.Granted) {
  25804. this.closeSocket(`${constants_1.ERRORS.InvalidSocks5FinalHandshakeRejected} - ${constants_1.Socks5Response[header[1]]}`);
  25805. } else {
  25806. const addressType = header[3];
  25807. let remoteHost;
  25808. let buff;
  25809. if (addressType === constants_1.Socks5HostType.IPv4) {
  25810. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;
  25811. if (this.receiveBuffer.length < dataNeeded) {
  25812. this.nextRequiredPacketBufferSize = dataNeeded;
  25813. return;
  25814. }
  25815. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(4));
  25816. remoteHost = {
  25817. host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()),
  25818. port: buff.readUInt16BE()
  25819. };
  25820. if (remoteHost.host === "0.0.0.0") {
  25821. remoteHost.host = this.options.proxy.ipaddress;
  25822. }
  25823. } else if (addressType === constants_1.Socks5HostType.Hostname) {
  25824. const hostLength = header[4];
  25825. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(hostLength);
  25826. if (this.receiveBuffer.length < dataNeeded) {
  25827. this.nextRequiredPacketBufferSize = dataNeeded;
  25828. return;
  25829. }
  25830. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(5));
  25831. remoteHost = {
  25832. host: buff.readString(hostLength),
  25833. port: buff.readUInt16BE()
  25834. };
  25835. } else if (addressType === constants_1.Socks5HostType.IPv6) {
  25836. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
  25837. if (this.receiveBuffer.length < dataNeeded) {
  25838. this.nextRequiredPacketBufferSize = dataNeeded;
  25839. return;
  25840. }
  25841. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(4));
  25842. remoteHost = {
  25843. host: ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm(),
  25844. port: buff.readUInt16BE()
  25845. };
  25846. }
  25847. this.setState(constants_1.SocksClientState.ReceivedFinalResponse);
  25848. if (constants_1.SocksCommand[this.options.command] === constants_1.SocksCommand.connect) {
  25849. this.setState(constants_1.SocksClientState.Established);
  25850. this.removeInternalSocketHandlers();
  25851. this.emit("established", { remoteHost, socket: this.socket });
  25852. } else if (constants_1.SocksCommand[this.options.command] === constants_1.SocksCommand.bind) {
  25853. this.setState(constants_1.SocksClientState.BoundWaitingForConnection);
  25854. this.nextRequiredPacketBufferSize = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHeader;
  25855. this.emit("bound", { remoteHost, socket: this.socket });
  25856. } else if (constants_1.SocksCommand[this.options.command] === constants_1.SocksCommand.associate) {
  25857. this.setState(constants_1.SocksClientState.Established);
  25858. this.removeInternalSocketHandlers();
  25859. this.emit("established", {
  25860. remoteHost,
  25861. socket: this.socket
  25862. });
  25863. }
  25864. }
  25865. }
  25866. /**
  25867. * Handles Socks v5 incoming connection request (BIND).
  25868. */
  25869. handleSocks5IncomingConnectionResponse() {
  25870. const header = this.receiveBuffer.peek(5);
  25871. if (header[0] !== 5 || header[1] !== constants_1.Socks5Response.Granted) {
  25872. this.closeSocket(`${constants_1.ERRORS.Socks5ProxyRejectedIncomingBoundConnection} - ${constants_1.Socks5Response[header[1]]}`);
  25873. } else {
  25874. const addressType = header[3];
  25875. let remoteHost;
  25876. let buff;
  25877. if (addressType === constants_1.Socks5HostType.IPv4) {
  25878. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv4;
  25879. if (this.receiveBuffer.length < dataNeeded) {
  25880. this.nextRequiredPacketBufferSize = dataNeeded;
  25881. return;
  25882. }
  25883. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(4));
  25884. remoteHost = {
  25885. host: (0, helpers_1.int32ToIpv4)(buff.readUInt32BE()),
  25886. port: buff.readUInt16BE()
  25887. };
  25888. if (remoteHost.host === "0.0.0.0") {
  25889. remoteHost.host = this.options.proxy.ipaddress;
  25890. }
  25891. } else if (addressType === constants_1.Socks5HostType.Hostname) {
  25892. const hostLength = header[4];
  25893. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseHostname(hostLength);
  25894. if (this.receiveBuffer.length < dataNeeded) {
  25895. this.nextRequiredPacketBufferSize = dataNeeded;
  25896. return;
  25897. }
  25898. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(5));
  25899. remoteHost = {
  25900. host: buff.readString(hostLength),
  25901. port: buff.readUInt16BE()
  25902. };
  25903. } else if (addressType === constants_1.Socks5HostType.IPv6) {
  25904. const dataNeeded = constants_1.SOCKS_INCOMING_PACKET_SIZES.Socks5ResponseIPv6;
  25905. if (this.receiveBuffer.length < dataNeeded) {
  25906. this.nextRequiredPacketBufferSize = dataNeeded;
  25907. return;
  25908. }
  25909. buff = smart_buffer_1.SmartBuffer.fromBuffer(this.receiveBuffer.get(dataNeeded).slice(4));
  25910. remoteHost = {
  25911. host: ip_address_1.Address6.fromByteArray(Array.from(buff.readBuffer(16))).canonicalForm(),
  25912. port: buff.readUInt16BE()
  25913. };
  25914. }
  25915. this.setState(constants_1.SocksClientState.Established);
  25916. this.removeInternalSocketHandlers();
  25917. this.emit("established", { remoteHost, socket: this.socket });
  25918. }
  25919. }
  25920. get socksClientOptions() {
  25921. return Object.assign({}, this.options);
  25922. }
  25923. };
  25924. exports2.SocksClient = SocksClient;
  25925. }
  25926. });
  25927. // node_modules/socks/build/index.js
  25928. var require_build = __commonJS({
  25929. "node_modules/socks/build/index.js"(exports2) {
  25930. "use strict";
  25931. var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
  25932. if (k2 === void 0) k2 = k;
  25933. var desc = Object.getOwnPropertyDescriptor(m, k);
  25934. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  25935. desc = { enumerable: true, get: function() {
  25936. return m[k];
  25937. } };
  25938. }
  25939. Object.defineProperty(o, k2, desc);
  25940. } : function(o, m, k, k2) {
  25941. if (k2 === void 0) k2 = k;
  25942. o[k2] = m[k];
  25943. });
  25944. var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
  25945. for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
  25946. };
  25947. Object.defineProperty(exports2, "__esModule", { value: true });
  25948. __exportStar(require_socksclient(), exports2);
  25949. }
  25950. });
  25951. // node_modules/mongodb/lib/cmap/auth/mongocr.js
  25952. var require_mongocr = __commonJS({
  25953. "node_modules/mongodb/lib/cmap/auth/mongocr.js"(exports2) {
  25954. "use strict";
  25955. Object.defineProperty(exports2, "__esModule", { value: true });
  25956. exports2.MongoCR = void 0;
  25957. var crypto = require("crypto");
  25958. var error_1 = require_error();
  25959. var utils_1 = require_utils();
  25960. var auth_provider_1 = require_auth_provider();
  25961. var MongoCR = class extends auth_provider_1.AuthProvider {
  25962. async auth(authContext) {
  25963. const { connection, credentials } = authContext;
  25964. if (!credentials) {
  25965. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  25966. }
  25967. const { username, password, source } = credentials;
  25968. const { nonce } = await connection.commandAsync((0, utils_1.ns)(`${source}.$cmd`), { getnonce: 1 }, void 0);
  25969. const hashPassword = crypto.createHash("md5").update(`${username}:mongo:${password}`, "utf8").digest("hex");
  25970. const key = crypto.createHash("md5").update(`${nonce}${username}${hashPassword}`, "utf8").digest("hex");
  25971. const authenticateCommand = {
  25972. authenticate: 1,
  25973. user: username,
  25974. nonce,
  25975. key
  25976. };
  25977. await connection.commandAsync((0, utils_1.ns)(`${source}.$cmd`), authenticateCommand, void 0);
  25978. }
  25979. };
  25980. exports2.MongoCR = MongoCR;
  25981. }
  25982. });
  25983. // node_modules/mongodb/lib/cmap/auth/mongodb_aws.js
  25984. var require_mongodb_aws = __commonJS({
  25985. "node_modules/mongodb/lib/cmap/auth/mongodb_aws.js"(exports2) {
  25986. "use strict";
  25987. Object.defineProperty(exports2, "__esModule", { value: true });
  25988. exports2.MongoDBAWS = void 0;
  25989. var crypto = require("crypto");
  25990. var process2 = require("process");
  25991. var util_1 = require("util");
  25992. var BSON = require_bson2();
  25993. var deps_1 = require_deps();
  25994. var error_1 = require_error();
  25995. var utils_1 = require_utils();
  25996. var auth_provider_1 = require_auth_provider();
  25997. var mongo_credentials_1 = require_mongo_credentials();
  25998. var providers_1 = require_providers();
  25999. var LEGACY_REGIONS = /* @__PURE__ */ new Set([
  26000. "ap-northeast-1",
  26001. "ap-south-1",
  26002. "ap-southeast-1",
  26003. "ap-southeast-2",
  26004. "aws-global",
  26005. "ca-central-1",
  26006. "eu-central-1",
  26007. "eu-north-1",
  26008. "eu-west-1",
  26009. "eu-west-2",
  26010. "eu-west-3",
  26011. "sa-east-1",
  26012. "us-east-1",
  26013. "us-east-2",
  26014. "us-west-1",
  26015. "us-west-2"
  26016. ]);
  26017. var ASCII_N = 110;
  26018. var AWS_RELATIVE_URI = "http://169.254.170.2";
  26019. var AWS_EC2_URI = "http://169.254.169.254";
  26020. var AWS_EC2_PATH = "/latest/meta-data/iam/security-credentials";
  26021. var bsonOptions = {
  26022. useBigInt64: false,
  26023. promoteLongs: true,
  26024. promoteValues: true,
  26025. promoteBuffers: false,
  26026. bsonRegExp: false
  26027. };
  26028. var MongoDBAWS = class extends auth_provider_1.AuthProvider {
  26029. constructor() {
  26030. super();
  26031. this.randomBytesAsync = (0, util_1.promisify)(crypto.randomBytes);
  26032. }
  26033. async auth(authContext) {
  26034. const { connection } = authContext;
  26035. if (!authContext.credentials) {
  26036. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  26037. }
  26038. if ("kModuleError" in deps_1.aws4) {
  26039. throw deps_1.aws4["kModuleError"];
  26040. }
  26041. const { sign } = deps_1.aws4;
  26042. if ((0, utils_1.maxWireVersion)(connection) < 9) {
  26043. throw new error_1.MongoCompatibilityError("MONGODB-AWS authentication requires MongoDB version 4.4 or later");
  26044. }
  26045. if (!authContext.credentials.username) {
  26046. authContext.credentials = await makeTempCredentials(authContext.credentials);
  26047. }
  26048. const { credentials } = authContext;
  26049. const accessKeyId = credentials.username;
  26050. const secretAccessKey = credentials.password;
  26051. const sessionToken = credentials.mechanismProperties.AWS_SESSION_TOKEN;
  26052. const awsCredentials = accessKeyId && secretAccessKey && sessionToken ? { accessKeyId, secretAccessKey, sessionToken } : accessKeyId && secretAccessKey ? { accessKeyId, secretAccessKey } : void 0;
  26053. const db = credentials.source;
  26054. const nonce = await this.randomBytesAsync(32);
  26055. const saslStart = {
  26056. saslStart: 1,
  26057. mechanism: "MONGODB-AWS",
  26058. payload: BSON.serialize({ r: nonce, p: ASCII_N }, bsonOptions)
  26059. };
  26060. const saslStartResponse = await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslStart, void 0);
  26061. const serverResponse = BSON.deserialize(saslStartResponse.payload.buffer, bsonOptions);
  26062. const host = serverResponse.h;
  26063. const serverNonce = serverResponse.s.buffer;
  26064. if (serverNonce.length !== 64) {
  26065. throw new error_1.MongoRuntimeError(`Invalid server nonce length ${serverNonce.length}, expected 64`);
  26066. }
  26067. if (!utils_1.ByteUtils.equals(serverNonce.subarray(0, nonce.byteLength), nonce)) {
  26068. throw new error_1.MongoRuntimeError("Server nonce does not begin with client nonce");
  26069. }
  26070. if (host.length < 1 || host.length > 255 || host.indexOf("..") !== -1) {
  26071. throw new error_1.MongoRuntimeError(`Server returned an invalid host: "${host}"`);
  26072. }
  26073. const body = "Action=GetCallerIdentity&Version=2011-06-15";
  26074. const options = sign({
  26075. method: "POST",
  26076. host,
  26077. region: deriveRegion(serverResponse.h),
  26078. service: "sts",
  26079. headers: {
  26080. "Content-Type": "application/x-www-form-urlencoded",
  26081. "Content-Length": body.length,
  26082. "X-MongoDB-Server-Nonce": utils_1.ByteUtils.toBase64(serverNonce),
  26083. "X-MongoDB-GS2-CB-Flag": "n"
  26084. },
  26085. path: "/",
  26086. body
  26087. }, awsCredentials);
  26088. const payload = {
  26089. a: options.headers.Authorization,
  26090. d: options.headers["X-Amz-Date"]
  26091. };
  26092. if (sessionToken) {
  26093. payload.t = sessionToken;
  26094. }
  26095. const saslContinue = {
  26096. saslContinue: 1,
  26097. conversationId: 1,
  26098. payload: BSON.serialize(payload, bsonOptions)
  26099. };
  26100. await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslContinue, void 0);
  26101. }
  26102. };
  26103. MongoDBAWS.credentialProvider = null;
  26104. exports2.MongoDBAWS = MongoDBAWS;
  26105. async function makeTempCredentials(credentials) {
  26106. function makeMongoCredentialsFromAWSTemp(creds) {
  26107. if (!creds.AccessKeyId || !creds.SecretAccessKey || !creds.Token) {
  26108. throw new error_1.MongoMissingCredentialsError("Could not obtain temporary MONGODB-AWS credentials");
  26109. }
  26110. return new mongo_credentials_1.MongoCredentials({
  26111. username: creds.AccessKeyId,
  26112. password: creds.SecretAccessKey,
  26113. source: credentials.source,
  26114. mechanism: providers_1.AuthMechanism.MONGODB_AWS,
  26115. mechanismProperties: {
  26116. AWS_SESSION_TOKEN: creds.Token
  26117. }
  26118. });
  26119. }
  26120. MongoDBAWS.credentialProvider ?? (MongoDBAWS.credentialProvider = (0, deps_1.getAwsCredentialProvider)());
  26121. if ("kModuleError" in MongoDBAWS.credentialProvider) {
  26122. if (process2.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
  26123. return makeMongoCredentialsFromAWSTemp(await (0, utils_1.request)(`${AWS_RELATIVE_URI}${process2.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`));
  26124. }
  26125. const token = await (0, utils_1.request)(`${AWS_EC2_URI}/latest/api/token`, {
  26126. method: "PUT",
  26127. json: false,
  26128. headers: { "X-aws-ec2-metadata-token-ttl-seconds": 30 }
  26129. });
  26130. const roleName = await (0, utils_1.request)(`${AWS_EC2_URI}/${AWS_EC2_PATH}`, {
  26131. json: false,
  26132. headers: { "X-aws-ec2-metadata-token": token }
  26133. });
  26134. const creds = await (0, utils_1.request)(`${AWS_EC2_URI}/${AWS_EC2_PATH}/${roleName}`, {
  26135. headers: { "X-aws-ec2-metadata-token": token }
  26136. });
  26137. return makeMongoCredentialsFromAWSTemp(creds);
  26138. } else {
  26139. let { AWS_STS_REGIONAL_ENDPOINTS = "", AWS_REGION = "" } = process2.env;
  26140. AWS_STS_REGIONAL_ENDPOINTS = AWS_STS_REGIONAL_ENDPOINTS.toLowerCase();
  26141. AWS_REGION = AWS_REGION.toLowerCase();
  26142. const awsRegionSettingsExist = AWS_REGION.length !== 0 && AWS_STS_REGIONAL_ENDPOINTS.length !== 0;
  26143. const useRegionalSts = AWS_STS_REGIONAL_ENDPOINTS === "regional" || AWS_STS_REGIONAL_ENDPOINTS === "legacy" && !LEGACY_REGIONS.has(AWS_REGION);
  26144. const provider = awsRegionSettingsExist && useRegionalSts ? MongoDBAWS.credentialProvider.fromNodeProviderChain({
  26145. clientConfig: { region: AWS_REGION }
  26146. }) : MongoDBAWS.credentialProvider.fromNodeProviderChain();
  26147. try {
  26148. const creds = await provider();
  26149. return makeMongoCredentialsFromAWSTemp({
  26150. AccessKeyId: creds.accessKeyId,
  26151. SecretAccessKey: creds.secretAccessKey,
  26152. Token: creds.sessionToken,
  26153. Expiration: creds.expiration
  26154. });
  26155. } catch (error) {
  26156. throw new error_1.MongoAWSError(error.message);
  26157. }
  26158. }
  26159. }
  26160. function deriveRegion(host) {
  26161. const parts = host.split(".");
  26162. if (parts.length === 1 || parts[1] === "amazonaws") {
  26163. return "us-east-1";
  26164. }
  26165. return parts[1];
  26166. }
  26167. }
  26168. });
  26169. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/service_workflow.js
  26170. var require_service_workflow = __commonJS({
  26171. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/service_workflow.js"(exports2) {
  26172. "use strict";
  26173. Object.defineProperty(exports2, "__esModule", { value: true });
  26174. exports2.commandDocument = exports2.ServiceWorkflow = void 0;
  26175. var bson_1 = require_bson();
  26176. var utils_1 = require_utils();
  26177. var providers_1 = require_providers();
  26178. var ServiceWorkflow = class {
  26179. /**
  26180. * Execute the workflow. Looks for AWS_WEB_IDENTITY_TOKEN_FILE in the environment
  26181. * and then attempts to read the token from that path.
  26182. */
  26183. async execute(connection, credentials) {
  26184. const token = await this.getToken(credentials);
  26185. const command = commandDocument(token);
  26186. return connection.commandAsync((0, utils_1.ns)(credentials.source), command, void 0);
  26187. }
  26188. /**
  26189. * Get the document to add for speculative authentication.
  26190. */
  26191. async speculativeAuth(credentials) {
  26192. const token = await this.getToken(credentials);
  26193. const document = commandDocument(token);
  26194. document.db = credentials.source;
  26195. return { speculativeAuthenticate: document };
  26196. }
  26197. };
  26198. exports2.ServiceWorkflow = ServiceWorkflow;
  26199. function commandDocument(token) {
  26200. return {
  26201. saslStart: 1,
  26202. mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
  26203. payload: bson_1.BSON.serialize({ jwt: token })
  26204. };
  26205. }
  26206. exports2.commandDocument = commandDocument;
  26207. }
  26208. });
  26209. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js
  26210. var require_aws_service_workflow = __commonJS({
  26211. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js"(exports2) {
  26212. "use strict";
  26213. Object.defineProperty(exports2, "__esModule", { value: true });
  26214. exports2.AwsServiceWorkflow = void 0;
  26215. var fs = require("fs");
  26216. var error_1 = require_error();
  26217. var service_workflow_1 = require_service_workflow();
  26218. var TOKEN_MISSING_ERROR = "AWS_WEB_IDENTITY_TOKEN_FILE must be set in the environment.";
  26219. var AwsServiceWorkflow = class extends service_workflow_1.ServiceWorkflow {
  26220. constructor() {
  26221. super();
  26222. }
  26223. /**
  26224. * Get the token from the environment.
  26225. */
  26226. async getToken() {
  26227. const tokenFile = process.env.AWS_WEB_IDENTITY_TOKEN_FILE;
  26228. if (!tokenFile) {
  26229. throw new error_1.MongoAWSError(TOKEN_MISSING_ERROR);
  26230. }
  26231. return fs.promises.readFile(tokenFile, "utf8");
  26232. }
  26233. };
  26234. exports2.AwsServiceWorkflow = AwsServiceWorkflow;
  26235. }
  26236. });
  26237. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/cache.js
  26238. var require_cache = __commonJS({
  26239. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/cache.js"(exports2) {
  26240. "use strict";
  26241. Object.defineProperty(exports2, "__esModule", { value: true });
  26242. exports2.Cache = exports2.ExpiringCacheEntry = void 0;
  26243. var EXPIRATION_BUFFER_MS = 3e5;
  26244. var ExpiringCacheEntry = class {
  26245. /**
  26246. * Create a new expiring token entry.
  26247. */
  26248. constructor(expiration) {
  26249. this.expiration = this.expirationTime(expiration);
  26250. }
  26251. /**
  26252. * The entry is still valid if the expiration is more than
  26253. * 5 minutes from the expiration time.
  26254. */
  26255. isValid() {
  26256. return this.expiration - Date.now() > EXPIRATION_BUFFER_MS;
  26257. }
  26258. /**
  26259. * Get an expiration time in milliseconds past epoch.
  26260. */
  26261. expirationTime(expiresInSeconds) {
  26262. return Date.now() + expiresInSeconds * 1e3;
  26263. }
  26264. };
  26265. exports2.ExpiringCacheEntry = ExpiringCacheEntry;
  26266. var Cache = class {
  26267. /**
  26268. * Create a new cache.
  26269. */
  26270. constructor() {
  26271. this.entries = /* @__PURE__ */ new Map();
  26272. }
  26273. /**
  26274. * Clear the cache.
  26275. */
  26276. clear() {
  26277. this.entries.clear();
  26278. }
  26279. /**
  26280. * Create a cache key from the address and username.
  26281. */
  26282. hashedCacheKey(address, username, callbackHash) {
  26283. return JSON.stringify([address, username, callbackHash]);
  26284. }
  26285. };
  26286. exports2.Cache = Cache;
  26287. }
  26288. });
  26289. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_token_cache.js
  26290. var require_azure_token_cache = __commonJS({
  26291. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_token_cache.js"(exports2) {
  26292. "use strict";
  26293. Object.defineProperty(exports2, "__esModule", { value: true });
  26294. exports2.AzureTokenCache = exports2.AzureTokenEntry = void 0;
  26295. var cache_1 = require_cache();
  26296. var AzureTokenEntry = class extends cache_1.ExpiringCacheEntry {
  26297. /**
  26298. * Instantiate the entry.
  26299. */
  26300. constructor(token, expiration) {
  26301. super(expiration);
  26302. this.token = token;
  26303. }
  26304. };
  26305. exports2.AzureTokenEntry = AzureTokenEntry;
  26306. var AzureTokenCache = class extends cache_1.Cache {
  26307. /**
  26308. * Add an entry to the cache.
  26309. */
  26310. addEntry(tokenAudience, token) {
  26311. const entry = new AzureTokenEntry(token.access_token, token.expires_in);
  26312. this.entries.set(tokenAudience, entry);
  26313. return entry;
  26314. }
  26315. /**
  26316. * Create a cache key.
  26317. */
  26318. cacheKey(tokenAudience) {
  26319. return tokenAudience;
  26320. }
  26321. /**
  26322. * Delete an entry from the cache.
  26323. */
  26324. deleteEntry(tokenAudience) {
  26325. this.entries.delete(tokenAudience);
  26326. }
  26327. /**
  26328. * Get an Azure token entry from the cache.
  26329. */
  26330. getEntry(tokenAudience) {
  26331. return this.entries.get(tokenAudience);
  26332. }
  26333. };
  26334. exports2.AzureTokenCache = AzureTokenCache;
  26335. }
  26336. });
  26337. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_service_workflow.js
  26338. var require_azure_service_workflow = __commonJS({
  26339. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/azure_service_workflow.js"(exports2) {
  26340. "use strict";
  26341. Object.defineProperty(exports2, "__esModule", { value: true });
  26342. exports2.AzureServiceWorkflow = void 0;
  26343. var error_1 = require_error();
  26344. var utils_1 = require_utils();
  26345. var azure_token_cache_1 = require_azure_token_cache();
  26346. var service_workflow_1 = require_service_workflow();
  26347. var AZURE_BASE_URL = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01";
  26348. var AZURE_HEADERS = Object.freeze({ Metadata: "true", Accept: "application/json" });
  26349. var ENDPOINT_RESULT_ERROR = "Azure endpoint did not return a value with only access_token and expires_in properties";
  26350. var TOKEN_AUDIENCE_MISSING_ERROR = "TOKEN_AUDIENCE must be set in the auth mechanism properties when PROVIDER_NAME is azure.";
  26351. var AzureServiceWorkflow = class extends service_workflow_1.ServiceWorkflow {
  26352. constructor() {
  26353. super(...arguments);
  26354. this.cache = new azure_token_cache_1.AzureTokenCache();
  26355. }
  26356. /**
  26357. * Get the token from the environment.
  26358. */
  26359. async getToken(credentials) {
  26360. const tokenAudience = credentials == null ? void 0 : credentials.mechanismProperties.TOKEN_AUDIENCE;
  26361. if (!tokenAudience) {
  26362. throw new error_1.MongoAzureError(TOKEN_AUDIENCE_MISSING_ERROR);
  26363. }
  26364. let token;
  26365. const entry = this.cache.getEntry(tokenAudience);
  26366. if (entry == null ? void 0 : entry.isValid()) {
  26367. token = entry.token;
  26368. } else {
  26369. this.cache.deleteEntry(tokenAudience);
  26370. const response = await getAzureTokenData(tokenAudience);
  26371. if (!isEndpointResultValid(response)) {
  26372. throw new error_1.MongoAzureError(ENDPOINT_RESULT_ERROR);
  26373. }
  26374. this.cache.addEntry(tokenAudience, response);
  26375. token = response.access_token;
  26376. }
  26377. return token;
  26378. }
  26379. };
  26380. exports2.AzureServiceWorkflow = AzureServiceWorkflow;
  26381. async function getAzureTokenData(tokenAudience) {
  26382. const url = `${AZURE_BASE_URL}&resource=${tokenAudience}`;
  26383. const data = await (0, utils_1.request)(url, {
  26384. json: true,
  26385. headers: AZURE_HEADERS
  26386. });
  26387. return data;
  26388. }
  26389. function isEndpointResultValid(token) {
  26390. if (token == null || typeof token !== "object")
  26391. return false;
  26392. return "access_token" in token && "expires_in" in token;
  26393. }
  26394. }
  26395. });
  26396. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js
  26397. var require_callback_lock_cache = __commonJS({
  26398. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js"(exports2) {
  26399. "use strict";
  26400. Object.defineProperty(exports2, "__esModule", { value: true });
  26401. exports2.CallbackLockCache = void 0;
  26402. var error_1 = require_error();
  26403. var cache_1 = require_cache();
  26404. var REQUEST_CALLBACK_REQUIRED_ERROR = "Auth mechanism property REQUEST_TOKEN_CALLBACK is required.";
  26405. var FN_HASH_COUNTER = 0;
  26406. var NO_FUNCTION = async () => ({ accessToken: "test" });
  26407. var FN_HASHES = /* @__PURE__ */ new WeakMap();
  26408. FN_HASHES.set(NO_FUNCTION, FN_HASH_COUNTER);
  26409. var CallbackLockCache = class extends cache_1.Cache {
  26410. /**
  26411. * Get the callbacks for the connection and credentials. If an entry does not
  26412. * exist a new one will get set.
  26413. */
  26414. getEntry(connection, credentials) {
  26415. const requestCallback = credentials.mechanismProperties.REQUEST_TOKEN_CALLBACK;
  26416. const refreshCallback = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
  26417. if (!requestCallback) {
  26418. throw new error_1.MongoInvalidArgumentError(REQUEST_CALLBACK_REQUIRED_ERROR);
  26419. }
  26420. const callbackHash = hashFunctions(requestCallback, refreshCallback);
  26421. const key = this.cacheKey(connection.address, credentials.username, callbackHash);
  26422. const entry = this.entries.get(key);
  26423. if (entry) {
  26424. return entry;
  26425. }
  26426. return this.addEntry(key, callbackHash, requestCallback, refreshCallback);
  26427. }
  26428. /**
  26429. * Set locked callbacks on for connection and credentials.
  26430. */
  26431. addEntry(key, callbackHash, requestCallback, refreshCallback) {
  26432. const entry = {
  26433. requestCallback: withLock(requestCallback),
  26434. refreshCallback: refreshCallback ? withLock(refreshCallback) : void 0,
  26435. callbackHash
  26436. };
  26437. this.entries.set(key, entry);
  26438. return entry;
  26439. }
  26440. /**
  26441. * Create a cache key from the address and username.
  26442. */
  26443. cacheKey(address, username, callbackHash) {
  26444. return this.hashedCacheKey(address, username, callbackHash);
  26445. }
  26446. };
  26447. exports2.CallbackLockCache = CallbackLockCache;
  26448. function withLock(callback) {
  26449. let lock = Promise.resolve();
  26450. return async (info, context) => {
  26451. await lock;
  26452. lock = lock.then(() => callback(info, context));
  26453. return lock;
  26454. };
  26455. }
  26456. function hashFunctions(requestFn, refreshFn) {
  26457. let requestHash = FN_HASHES.get(requestFn);
  26458. let refreshHash = FN_HASHES.get(refreshFn ?? NO_FUNCTION);
  26459. if (requestHash == null) {
  26460. FN_HASH_COUNTER++;
  26461. requestHash = FN_HASH_COUNTER;
  26462. FN_HASHES.set(requestFn, FN_HASH_COUNTER);
  26463. }
  26464. if (refreshHash == null && refreshFn) {
  26465. FN_HASH_COUNTER++;
  26466. refreshHash = FN_HASH_COUNTER;
  26467. FN_HASHES.set(refreshFn, FN_HASH_COUNTER);
  26468. }
  26469. return `${requestHash}-${refreshHash}`;
  26470. }
  26471. }
  26472. });
  26473. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_entry_cache.js
  26474. var require_token_entry_cache = __commonJS({
  26475. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/token_entry_cache.js"(exports2) {
  26476. "use strict";
  26477. Object.defineProperty(exports2, "__esModule", { value: true });
  26478. exports2.TokenEntryCache = exports2.TokenEntry = void 0;
  26479. var cache_1 = require_cache();
  26480. var DEFAULT_EXPIRATION_SECS = 0;
  26481. var TokenEntry = class extends cache_1.ExpiringCacheEntry {
  26482. /**
  26483. * Instantiate the entry.
  26484. */
  26485. constructor(tokenResult, serverInfo, expiration) {
  26486. super(expiration);
  26487. this.tokenResult = tokenResult;
  26488. this.serverInfo = serverInfo;
  26489. }
  26490. };
  26491. exports2.TokenEntry = TokenEntry;
  26492. var TokenEntryCache = class extends cache_1.Cache {
  26493. /**
  26494. * Set an entry in the token cache.
  26495. */
  26496. addEntry(address, username, callbackHash, tokenResult, serverInfo) {
  26497. const entry = new TokenEntry(tokenResult, serverInfo, tokenResult.expiresInSeconds ?? DEFAULT_EXPIRATION_SECS);
  26498. this.entries.set(this.cacheKey(address, username, callbackHash), entry);
  26499. return entry;
  26500. }
  26501. /**
  26502. * Delete an entry from the cache.
  26503. */
  26504. deleteEntry(address, username, callbackHash) {
  26505. this.entries.delete(this.cacheKey(address, username, callbackHash));
  26506. }
  26507. /**
  26508. * Get an entry from the cache.
  26509. */
  26510. getEntry(address, username, callbackHash) {
  26511. return this.entries.get(this.cacheKey(address, username, callbackHash));
  26512. }
  26513. /**
  26514. * Delete all expired entries from the cache.
  26515. */
  26516. deleteExpiredEntries() {
  26517. for (const [key, entry] of this.entries) {
  26518. if (!entry.isValid()) {
  26519. this.entries.delete(key);
  26520. }
  26521. }
  26522. }
  26523. /**
  26524. * Create a cache key from the address and username.
  26525. */
  26526. cacheKey(address, username, callbackHash) {
  26527. return this.hashedCacheKey(address, username, callbackHash);
  26528. }
  26529. };
  26530. exports2.TokenEntryCache = TokenEntryCache;
  26531. }
  26532. });
  26533. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc/callback_workflow.js
  26534. var require_callback_workflow = __commonJS({
  26535. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc/callback_workflow.js"(exports2) {
  26536. "use strict";
  26537. Object.defineProperty(exports2, "__esModule", { value: true });
  26538. exports2.CallbackWorkflow = void 0;
  26539. var bson_1 = require_bson();
  26540. var error_1 = require_error();
  26541. var utils_1 = require_utils();
  26542. var providers_1 = require_providers();
  26543. var callback_lock_cache_1 = require_callback_lock_cache();
  26544. var token_entry_cache_1 = require_token_entry_cache();
  26545. var OIDC_VERSION = 0;
  26546. var TIMEOUT_S = 300;
  26547. var RESULT_PROPERTIES = ["accessToken", "expiresInSeconds", "refreshToken"];
  26548. var CALLBACK_RESULT_ERROR = "User provided OIDC callbacks must return a valid object with an accessToken.";
  26549. var CallbackWorkflow = class {
  26550. /**
  26551. * Instantiate the workflow
  26552. */
  26553. constructor() {
  26554. this.cache = new token_entry_cache_1.TokenEntryCache();
  26555. this.callbackCache = new callback_lock_cache_1.CallbackLockCache();
  26556. }
  26557. /**
  26558. * Get the document to add for speculative authentication. This also needs
  26559. * to add a db field from the credentials source.
  26560. */
  26561. async speculativeAuth(credentials) {
  26562. const document = startCommandDocument(credentials);
  26563. document.db = credentials.source;
  26564. return { speculativeAuthenticate: document };
  26565. }
  26566. /**
  26567. * Execute the OIDC callback workflow.
  26568. */
  26569. async execute(connection, credentials, reauthenticating, response) {
  26570. var _a, _b;
  26571. const { requestCallback, refreshCallback, callbackHash } = this.callbackCache.getEntry(connection, credentials);
  26572. const entry = this.cache.getEntry(connection.address, credentials.username, callbackHash);
  26573. let result;
  26574. if (entry) {
  26575. if (entry.isValid() && !reauthenticating) {
  26576. result = await this.finishAuthentication(connection, credentials, entry.tokenResult, (_a = response == null ? void 0 : response.speculativeAuthenticate) == null ? void 0 : _a.conversationId);
  26577. } else {
  26578. const tokenResult = await this.fetchAccessToken(connection, credentials, entry.serverInfo, reauthenticating, callbackHash, requestCallback, refreshCallback);
  26579. try {
  26580. result = await this.finishAuthentication(connection, credentials, tokenResult, reauthenticating ? void 0 : (_b = response == null ? void 0 : response.speculativeAuthenticate) == null ? void 0 : _b.conversationId);
  26581. } catch (error) {
  26582. if (reauthenticating && error instanceof error_1.MongoError && error.code === error_1.MONGODB_ERROR_CODES.Reauthenticate) {
  26583. this.cache.deleteEntry(connection.address, credentials.username, callbackHash);
  26584. result = await this.execute(connection, credentials, reauthenticating);
  26585. } else {
  26586. throw error;
  26587. }
  26588. }
  26589. }
  26590. } else {
  26591. const startDocument = await this.startAuthentication(connection, credentials, reauthenticating, response);
  26592. const conversationId = startDocument.conversationId;
  26593. const serverResult = bson_1.BSON.deserialize(startDocument.payload.buffer);
  26594. const tokenResult = await this.fetchAccessToken(connection, credentials, serverResult, reauthenticating, callbackHash, requestCallback, refreshCallback);
  26595. result = await this.finishAuthentication(connection, credentials, tokenResult, conversationId);
  26596. }
  26597. return result;
  26598. }
  26599. /**
  26600. * Starts the callback authentication process. If there is a speculative
  26601. * authentication document from the initial handshake, then we will use that
  26602. * value to get the issuer, otherwise we will send the saslStart command.
  26603. */
  26604. async startAuthentication(connection, credentials, reauthenticating, response) {
  26605. let result;
  26606. if (!reauthenticating && (response == null ? void 0 : response.speculativeAuthenticate)) {
  26607. result = response.speculativeAuthenticate;
  26608. } else {
  26609. result = await connection.commandAsync((0, utils_1.ns)(credentials.source), startCommandDocument(credentials), void 0);
  26610. }
  26611. return result;
  26612. }
  26613. /**
  26614. * Finishes the callback authentication process.
  26615. */
  26616. async finishAuthentication(connection, credentials, tokenResult, conversationId) {
  26617. const result = await connection.commandAsync((0, utils_1.ns)(credentials.source), finishCommandDocument(tokenResult.accessToken, conversationId), void 0);
  26618. return result;
  26619. }
  26620. /**
  26621. * Fetches an access token using either the request or refresh callbacks and
  26622. * puts it in the cache.
  26623. */
  26624. async fetchAccessToken(connection, credentials, serverInfo, reauthenticating, callbackHash, requestCallback, refreshCallback) {
  26625. const entry = this.cache.getEntry(connection.address, credentials.username, callbackHash);
  26626. let result;
  26627. const context = { timeoutSeconds: TIMEOUT_S, version: OIDC_VERSION };
  26628. if (entry) {
  26629. if (entry.isValid() && !reauthenticating) {
  26630. return entry.tokenResult;
  26631. }
  26632. if (refreshCallback) {
  26633. context.refreshToken = entry.tokenResult.refreshToken;
  26634. result = await refreshCallback(serverInfo, context);
  26635. } else {
  26636. result = await requestCallback(serverInfo, context);
  26637. }
  26638. } else {
  26639. result = await requestCallback(serverInfo, context);
  26640. }
  26641. if (isCallbackResultInvalid(result)) {
  26642. this.cache.deleteEntry(connection.address, credentials.username, callbackHash);
  26643. throw new error_1.MongoMissingCredentialsError(CALLBACK_RESULT_ERROR);
  26644. }
  26645. this.cache.deleteExpiredEntries();
  26646. this.cache.addEntry(connection.address, credentials.username || "", callbackHash, result, serverInfo);
  26647. return result;
  26648. }
  26649. };
  26650. exports2.CallbackWorkflow = CallbackWorkflow;
  26651. function finishCommandDocument(token, conversationId) {
  26652. if (conversationId != null && typeof conversationId === "number") {
  26653. return {
  26654. saslContinue: 1,
  26655. conversationId,
  26656. payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
  26657. };
  26658. }
  26659. return {
  26660. saslStart: 1,
  26661. mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
  26662. payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
  26663. };
  26664. }
  26665. function isCallbackResultInvalid(tokenResult) {
  26666. if (tokenResult == null || typeof tokenResult !== "object")
  26667. return true;
  26668. if (!("accessToken" in tokenResult))
  26669. return true;
  26670. return !Object.getOwnPropertyNames(tokenResult).every((prop) => RESULT_PROPERTIES.includes(prop));
  26671. }
  26672. function startCommandDocument(credentials) {
  26673. const payload = {};
  26674. if (credentials.username) {
  26675. payload.n = credentials.username;
  26676. }
  26677. return {
  26678. saslStart: 1,
  26679. autoAuthorize: 1,
  26680. mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
  26681. payload: new bson_1.Binary(bson_1.BSON.serialize(payload))
  26682. };
  26683. }
  26684. }
  26685. });
  26686. // node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js
  26687. var require_mongodb_oidc = __commonJS({
  26688. "node_modules/mongodb/lib/cmap/auth/mongodb_oidc.js"(exports2) {
  26689. "use strict";
  26690. Object.defineProperty(exports2, "__esModule", { value: true });
  26691. exports2.MongoDBOIDC = exports2.OIDC_WORKFLOWS = void 0;
  26692. var error_1 = require_error();
  26693. var auth_provider_1 = require_auth_provider();
  26694. var aws_service_workflow_1 = require_aws_service_workflow();
  26695. var azure_service_workflow_1 = require_azure_service_workflow();
  26696. var callback_workflow_1 = require_callback_workflow();
  26697. var MISSING_CREDENTIALS_ERROR = "AuthContext must provide credentials.";
  26698. exports2.OIDC_WORKFLOWS = /* @__PURE__ */ new Map();
  26699. exports2.OIDC_WORKFLOWS.set("callback", new callback_workflow_1.CallbackWorkflow());
  26700. exports2.OIDC_WORKFLOWS.set("aws", new aws_service_workflow_1.AwsServiceWorkflow());
  26701. exports2.OIDC_WORKFLOWS.set("azure", new azure_service_workflow_1.AzureServiceWorkflow());
  26702. var MongoDBOIDC = class extends auth_provider_1.AuthProvider {
  26703. /**
  26704. * Instantiate the auth provider.
  26705. */
  26706. constructor() {
  26707. super();
  26708. }
  26709. /**
  26710. * Authenticate using OIDC
  26711. */
  26712. async auth(authContext) {
  26713. const { connection, reauthenticating, response } = authContext;
  26714. const credentials = getCredentials(authContext);
  26715. const workflow = getWorkflow(credentials);
  26716. await workflow.execute(connection, credentials, reauthenticating, response);
  26717. }
  26718. /**
  26719. * Add the speculative auth for the initial handshake.
  26720. */
  26721. async prepare(handshakeDoc, authContext) {
  26722. const credentials = getCredentials(authContext);
  26723. const workflow = getWorkflow(credentials);
  26724. const result = await workflow.speculativeAuth(credentials);
  26725. return { ...handshakeDoc, ...result };
  26726. }
  26727. };
  26728. exports2.MongoDBOIDC = MongoDBOIDC;
  26729. function getCredentials(authContext) {
  26730. const { credentials } = authContext;
  26731. if (!credentials) {
  26732. throw new error_1.MongoMissingCredentialsError(MISSING_CREDENTIALS_ERROR);
  26733. }
  26734. return credentials;
  26735. }
  26736. function getWorkflow(credentials) {
  26737. const providerName = credentials.mechanismProperties.PROVIDER_NAME;
  26738. const workflow = exports2.OIDC_WORKFLOWS.get(providerName || "callback");
  26739. if (!workflow) {
  26740. throw new error_1.MongoInvalidArgumentError(`Could not load workflow for provider ${credentials.mechanismProperties.PROVIDER_NAME}`);
  26741. }
  26742. return workflow;
  26743. }
  26744. }
  26745. });
  26746. // node_modules/mongodb/lib/cmap/auth/plain.js
  26747. var require_plain = __commonJS({
  26748. "node_modules/mongodb/lib/cmap/auth/plain.js"(exports2) {
  26749. "use strict";
  26750. Object.defineProperty(exports2, "__esModule", { value: true });
  26751. exports2.Plain = void 0;
  26752. var bson_1 = require_bson2();
  26753. var error_1 = require_error();
  26754. var utils_1 = require_utils();
  26755. var auth_provider_1 = require_auth_provider();
  26756. var Plain = class extends auth_provider_1.AuthProvider {
  26757. async auth(authContext) {
  26758. const { connection, credentials } = authContext;
  26759. if (!credentials) {
  26760. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  26761. }
  26762. const { username, password } = credentials;
  26763. const payload = new bson_1.Binary(Buffer.from(`\0${username}\0${password}`));
  26764. const command = {
  26765. saslStart: 1,
  26766. mechanism: "PLAIN",
  26767. payload,
  26768. autoAuthorize: 1
  26769. };
  26770. await connection.commandAsync((0, utils_1.ns)("$external.$cmd"), command, void 0);
  26771. }
  26772. };
  26773. exports2.Plain = Plain;
  26774. }
  26775. });
  26776. // node_modules/mongodb/lib/cmap/auth/scram.js
  26777. var require_scram = __commonJS({
  26778. "node_modules/mongodb/lib/cmap/auth/scram.js"(exports2) {
  26779. "use strict";
  26780. Object.defineProperty(exports2, "__esModule", { value: true });
  26781. exports2.ScramSHA256 = exports2.ScramSHA1 = void 0;
  26782. var crypto = require("crypto");
  26783. var util_1 = require("util");
  26784. var bson_1 = require_bson2();
  26785. var deps_1 = require_deps();
  26786. var error_1 = require_error();
  26787. var utils_1 = require_utils();
  26788. var auth_provider_1 = require_auth_provider();
  26789. var providers_1 = require_providers();
  26790. var ScramSHA = class extends auth_provider_1.AuthProvider {
  26791. constructor(cryptoMethod) {
  26792. super();
  26793. this.cryptoMethod = cryptoMethod || "sha1";
  26794. this.randomBytesAsync = (0, util_1.promisify)(crypto.randomBytes);
  26795. }
  26796. async prepare(handshakeDoc, authContext) {
  26797. const cryptoMethod = this.cryptoMethod;
  26798. const credentials = authContext.credentials;
  26799. if (!credentials) {
  26800. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  26801. }
  26802. if (cryptoMethod === "sha256" && ("kModuleError" in deps_1.saslprep || typeof deps_1.saslprep !== "function")) {
  26803. (0, utils_1.emitWarning)("Warning: no saslprep library specified. Passwords will not be sanitized");
  26804. }
  26805. const nonce = await this.randomBytesAsync(24);
  26806. authContext.nonce = nonce;
  26807. const request = {
  26808. ...handshakeDoc,
  26809. speculativeAuthenticate: {
  26810. ...makeFirstMessage(cryptoMethod, credentials, nonce),
  26811. db: credentials.source
  26812. }
  26813. };
  26814. return request;
  26815. }
  26816. async auth(authContext) {
  26817. const { reauthenticating, response } = authContext;
  26818. if ((response == null ? void 0 : response.speculativeAuthenticate) && !reauthenticating) {
  26819. return continueScramConversation(this.cryptoMethod, response.speculativeAuthenticate, authContext);
  26820. }
  26821. return executeScram(this.cryptoMethod, authContext);
  26822. }
  26823. };
  26824. function cleanUsername(username) {
  26825. return username.replace("=", "=3D").replace(",", "=2C");
  26826. }
  26827. function clientFirstMessageBare(username, nonce) {
  26828. return Buffer.concat([
  26829. Buffer.from("n=", "utf8"),
  26830. Buffer.from(username, "utf8"),
  26831. Buffer.from(",r=", "utf8"),
  26832. Buffer.from(nonce.toString("base64"), "utf8")
  26833. ]);
  26834. }
  26835. function makeFirstMessage(cryptoMethod, credentials, nonce) {
  26836. const username = cleanUsername(credentials.username);
  26837. const mechanism = cryptoMethod === "sha1" ? providers_1.AuthMechanism.MONGODB_SCRAM_SHA1 : providers_1.AuthMechanism.MONGODB_SCRAM_SHA256;
  26838. return {
  26839. saslStart: 1,
  26840. mechanism,
  26841. payload: new bson_1.Binary(Buffer.concat([Buffer.from("n,,", "utf8"), clientFirstMessageBare(username, nonce)])),
  26842. autoAuthorize: 1,
  26843. options: { skipEmptyExchange: true }
  26844. };
  26845. }
  26846. async function executeScram(cryptoMethod, authContext) {
  26847. const { connection, credentials } = authContext;
  26848. if (!credentials) {
  26849. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  26850. }
  26851. if (!authContext.nonce) {
  26852. throw new error_1.MongoInvalidArgumentError("AuthContext must contain a valid nonce property");
  26853. }
  26854. const nonce = authContext.nonce;
  26855. const db = credentials.source;
  26856. const saslStartCmd = makeFirstMessage(cryptoMethod, credentials, nonce);
  26857. const response = await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslStartCmd, void 0);
  26858. await continueScramConversation(cryptoMethod, response, authContext);
  26859. }
  26860. async function continueScramConversation(cryptoMethod, response, authContext) {
  26861. const connection = authContext.connection;
  26862. const credentials = authContext.credentials;
  26863. if (!credentials) {
  26864. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  26865. }
  26866. if (!authContext.nonce) {
  26867. throw new error_1.MongoInvalidArgumentError("Unable to continue SCRAM without valid nonce");
  26868. }
  26869. const nonce = authContext.nonce;
  26870. const db = credentials.source;
  26871. const username = cleanUsername(credentials.username);
  26872. const password = credentials.password;
  26873. let processedPassword;
  26874. if (cryptoMethod === "sha256") {
  26875. processedPassword = "kModuleError" in deps_1.saslprep || typeof deps_1.saslprep !== "function" ? password : (0, deps_1.saslprep)(password);
  26876. } else {
  26877. processedPassword = passwordDigest(username, password);
  26878. }
  26879. const payload = Buffer.isBuffer(response.payload) ? new bson_1.Binary(response.payload) : response.payload;
  26880. const dict = parsePayload(payload.value());
  26881. const iterations = parseInt(dict.i, 10);
  26882. if (iterations && iterations < 4096) {
  26883. throw new error_1.MongoRuntimeError(`Server returned an invalid iteration count ${iterations}`);
  26884. }
  26885. const salt = dict.s;
  26886. const rnonce = dict.r;
  26887. if (rnonce.startsWith("nonce")) {
  26888. throw new error_1.MongoRuntimeError(`Server returned an invalid nonce: ${rnonce}`);
  26889. }
  26890. const withoutProof = `c=biws,r=${rnonce}`;
  26891. const saltedPassword = HI(processedPassword, Buffer.from(salt, "base64"), iterations, cryptoMethod);
  26892. const clientKey = HMAC(cryptoMethod, saltedPassword, "Client Key");
  26893. const serverKey = HMAC(cryptoMethod, saltedPassword, "Server Key");
  26894. const storedKey = H(cryptoMethod, clientKey);
  26895. const authMessage = [clientFirstMessageBare(username, nonce), payload.value(), withoutProof].join(",");
  26896. const clientSignature = HMAC(cryptoMethod, storedKey, authMessage);
  26897. const clientProof = `p=${xor(clientKey, clientSignature)}`;
  26898. const clientFinal = [withoutProof, clientProof].join(",");
  26899. const serverSignature = HMAC(cryptoMethod, serverKey, authMessage);
  26900. const saslContinueCmd = {
  26901. saslContinue: 1,
  26902. conversationId: response.conversationId,
  26903. payload: new bson_1.Binary(Buffer.from(clientFinal))
  26904. };
  26905. const r = await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslContinueCmd, void 0);
  26906. const parsedResponse = parsePayload(r.payload.value());
  26907. if (!compareDigest(Buffer.from(parsedResponse.v, "base64"), serverSignature)) {
  26908. throw new error_1.MongoRuntimeError("Server returned an invalid signature");
  26909. }
  26910. if (r.done !== false) {
  26911. return;
  26912. }
  26913. const retrySaslContinueCmd = {
  26914. saslContinue: 1,
  26915. conversationId: r.conversationId,
  26916. payload: Buffer.alloc(0)
  26917. };
  26918. await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), retrySaslContinueCmd, void 0);
  26919. }
  26920. function parsePayload(payload) {
  26921. const dict = {};
  26922. const parts = payload.split(",");
  26923. for (let i = 0; i < parts.length; i++) {
  26924. const valueParts = parts[i].split("=");
  26925. dict[valueParts[0]] = valueParts[1];
  26926. }
  26927. return dict;
  26928. }
  26929. function passwordDigest(username, password) {
  26930. if (typeof username !== "string") {
  26931. throw new error_1.MongoInvalidArgumentError("Username must be a string");
  26932. }
  26933. if (typeof password !== "string") {
  26934. throw new error_1.MongoInvalidArgumentError("Password must be a string");
  26935. }
  26936. if (password.length === 0) {
  26937. throw new error_1.MongoInvalidArgumentError("Password cannot be empty");
  26938. }
  26939. let md5;
  26940. try {
  26941. md5 = crypto.createHash("md5");
  26942. } catch (err) {
  26943. if (crypto.getFips()) {
  26944. throw new Error("Auth mechanism SCRAM-SHA-1 is not supported in FIPS mode");
  26945. }
  26946. throw err;
  26947. }
  26948. md5.update(`${username}:mongo:${password}`, "utf8");
  26949. return md5.digest("hex");
  26950. }
  26951. function xor(a, b) {
  26952. if (!Buffer.isBuffer(a)) {
  26953. a = Buffer.from(a);
  26954. }
  26955. if (!Buffer.isBuffer(b)) {
  26956. b = Buffer.from(b);
  26957. }
  26958. const length = Math.max(a.length, b.length);
  26959. const res = [];
  26960. for (let i = 0; i < length; i += 1) {
  26961. res.push(a[i] ^ b[i]);
  26962. }
  26963. return Buffer.from(res).toString("base64");
  26964. }
  26965. function H(method, text) {
  26966. return crypto.createHash(method).update(text).digest();
  26967. }
  26968. function HMAC(method, key, text) {
  26969. return crypto.createHmac(method, key).update(text).digest();
  26970. }
  26971. var _hiCache = {};
  26972. var _hiCacheCount = 0;
  26973. function _hiCachePurge() {
  26974. _hiCache = {};
  26975. _hiCacheCount = 0;
  26976. }
  26977. var hiLengthMap = {
  26978. sha256: 32,
  26979. sha1: 20
  26980. };
  26981. function HI(data, salt, iterations, cryptoMethod) {
  26982. const key = [data, salt.toString("base64"), iterations].join("_");
  26983. if (_hiCache[key] != null) {
  26984. return _hiCache[key];
  26985. }
  26986. const saltedData = crypto.pbkdf2Sync(data, salt, iterations, hiLengthMap[cryptoMethod], cryptoMethod);
  26987. if (_hiCacheCount >= 200) {
  26988. _hiCachePurge();
  26989. }
  26990. _hiCache[key] = saltedData;
  26991. _hiCacheCount += 1;
  26992. return saltedData;
  26993. }
  26994. function compareDigest(lhs, rhs) {
  26995. if (lhs.length !== rhs.length) {
  26996. return false;
  26997. }
  26998. if (typeof crypto.timingSafeEqual === "function") {
  26999. return crypto.timingSafeEqual(lhs, rhs);
  27000. }
  27001. let result = 0;
  27002. for (let i = 0; i < lhs.length; i++) {
  27003. result |= lhs[i] ^ rhs[i];
  27004. }
  27005. return result === 0;
  27006. }
  27007. var ScramSHA1 = class extends ScramSHA {
  27008. constructor() {
  27009. super("sha1");
  27010. }
  27011. };
  27012. exports2.ScramSHA1 = ScramSHA1;
  27013. var ScramSHA256 = class extends ScramSHA {
  27014. constructor() {
  27015. super("sha256");
  27016. }
  27017. };
  27018. exports2.ScramSHA256 = ScramSHA256;
  27019. }
  27020. });
  27021. // node_modules/mongodb/lib/cmap/auth/x509.js
  27022. var require_x509 = __commonJS({
  27023. "node_modules/mongodb/lib/cmap/auth/x509.js"(exports2) {
  27024. "use strict";
  27025. Object.defineProperty(exports2, "__esModule", { value: true });
  27026. exports2.X509 = void 0;
  27027. var error_1 = require_error();
  27028. var utils_1 = require_utils();
  27029. var auth_provider_1 = require_auth_provider();
  27030. var X509 = class extends auth_provider_1.AuthProvider {
  27031. async prepare(handshakeDoc, authContext) {
  27032. const { credentials } = authContext;
  27033. if (!credentials) {
  27034. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  27035. }
  27036. return { ...handshakeDoc, speculativeAuthenticate: x509AuthenticateCommand(credentials) };
  27037. }
  27038. async auth(authContext) {
  27039. const connection = authContext.connection;
  27040. const credentials = authContext.credentials;
  27041. if (!credentials) {
  27042. throw new error_1.MongoMissingCredentialsError("AuthContext must provide credentials.");
  27043. }
  27044. const response = authContext.response;
  27045. if (response == null ? void 0 : response.speculativeAuthenticate) {
  27046. return;
  27047. }
  27048. await connection.commandAsync((0, utils_1.ns)("$external.$cmd"), x509AuthenticateCommand(credentials), void 0);
  27049. }
  27050. };
  27051. exports2.X509 = X509;
  27052. function x509AuthenticateCommand(credentials) {
  27053. const command = { authenticate: 1, mechanism: "MONGODB-X509" };
  27054. if (credentials.username) {
  27055. command.user = credentials.username;
  27056. }
  27057. return command;
  27058. }
  27059. }
  27060. });
  27061. // node_modules/mongodb/lib/cmap/connect.js
  27062. var require_connect = __commonJS({
  27063. "node_modules/mongodb/lib/cmap/connect.js"(exports2) {
  27064. "use strict";
  27065. Object.defineProperty(exports2, "__esModule", { value: true });
  27066. exports2.LEGAL_TCP_SOCKET_OPTIONS = exports2.LEGAL_TLS_SOCKET_OPTIONS = exports2.prepareHandshakeDocument = exports2.connect = exports2.AUTH_PROVIDERS = void 0;
  27067. var net = require("net");
  27068. var socks_1 = require_build();
  27069. var tls = require("tls");
  27070. var constants_1 = require_constants2();
  27071. var error_1 = require_error();
  27072. var utils_1 = require_utils();
  27073. var auth_provider_1 = require_auth_provider();
  27074. var gssapi_1 = require_gssapi();
  27075. var mongocr_1 = require_mongocr();
  27076. var mongodb_aws_1 = require_mongodb_aws();
  27077. var mongodb_oidc_1 = require_mongodb_oidc();
  27078. var plain_1 = require_plain();
  27079. var providers_1 = require_providers();
  27080. var scram_1 = require_scram();
  27081. var x509_1 = require_x509();
  27082. var connection_1 = require_connection();
  27083. var constants_2 = require_constants();
  27084. exports2.AUTH_PROVIDERS = /* @__PURE__ */ new Map([
  27085. [providers_1.AuthMechanism.MONGODB_AWS, new mongodb_aws_1.MongoDBAWS()],
  27086. [providers_1.AuthMechanism.MONGODB_CR, new mongocr_1.MongoCR()],
  27087. [providers_1.AuthMechanism.MONGODB_GSSAPI, new gssapi_1.GSSAPI()],
  27088. [providers_1.AuthMechanism.MONGODB_OIDC, new mongodb_oidc_1.MongoDBOIDC()],
  27089. [providers_1.AuthMechanism.MONGODB_PLAIN, new plain_1.Plain()],
  27090. [providers_1.AuthMechanism.MONGODB_SCRAM_SHA1, new scram_1.ScramSHA1()],
  27091. [providers_1.AuthMechanism.MONGODB_SCRAM_SHA256, new scram_1.ScramSHA256()],
  27092. [providers_1.AuthMechanism.MONGODB_X509, new x509_1.X509()]
  27093. ]);
  27094. function connect(options, callback) {
  27095. makeConnection({ ...options, existingSocket: void 0 }, (err, socket) => {
  27096. if (err || !socket) {
  27097. return callback(err);
  27098. }
  27099. let ConnectionType = options.connectionType ?? connection_1.Connection;
  27100. if (options.autoEncrypter) {
  27101. ConnectionType = connection_1.CryptoConnection;
  27102. }
  27103. const connection = new ConnectionType(socket, options);
  27104. performInitialHandshake(connection, options).then(() => callback(void 0, connection), (error) => {
  27105. connection.destroy({ force: false });
  27106. callback(error);
  27107. });
  27108. });
  27109. }
  27110. exports2.connect = connect;
  27111. function checkSupportedServer(hello, options) {
  27112. const maxWireVersion = Number(hello.maxWireVersion);
  27113. const minWireVersion = Number(hello.minWireVersion);
  27114. const serverVersionHighEnough = !Number.isNaN(maxWireVersion) && maxWireVersion >= constants_2.MIN_SUPPORTED_WIRE_VERSION;
  27115. const serverVersionLowEnough = !Number.isNaN(minWireVersion) && minWireVersion <= constants_2.MAX_SUPPORTED_WIRE_VERSION;
  27116. if (serverVersionHighEnough) {
  27117. if (serverVersionLowEnough) {
  27118. return null;
  27119. }
  27120. const message2 = `Server at ${options.hostAddress} reports minimum wire version ${JSON.stringify(hello.minWireVersion)}, but this version of the Node.js Driver requires at most ${constants_2.MAX_SUPPORTED_WIRE_VERSION} (MongoDB ${constants_2.MAX_SUPPORTED_SERVER_VERSION})`;
  27121. return new error_1.MongoCompatibilityError(message2);
  27122. }
  27123. const message = `Server at ${options.hostAddress} reports maximum wire version ${JSON.stringify(hello.maxWireVersion) ?? 0}, but this version of the Node.js Driver requires at least ${constants_2.MIN_SUPPORTED_WIRE_VERSION} (MongoDB ${constants_2.MIN_SUPPORTED_SERVER_VERSION})`;
  27124. return new error_1.MongoCompatibilityError(message);
  27125. }
  27126. async function performInitialHandshake(conn, options) {
  27127. const credentials = options.credentials;
  27128. if (credentials) {
  27129. if (!(credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT) && !exports2.AUTH_PROVIDERS.get(credentials.mechanism)) {
  27130. throw new error_1.MongoInvalidArgumentError(`AuthMechanism '${credentials.mechanism}' not supported`);
  27131. }
  27132. }
  27133. const authContext = new auth_provider_1.AuthContext(conn, credentials, options);
  27134. conn.authContext = authContext;
  27135. const handshakeDoc = await prepareHandshakeDocument(authContext);
  27136. const handshakeOptions = { ...options };
  27137. if (typeof options.connectTimeoutMS === "number") {
  27138. handshakeOptions.socketTimeoutMS = options.connectTimeoutMS;
  27139. }
  27140. const start = (/* @__PURE__ */ new Date()).getTime();
  27141. const response = await conn.commandAsync((0, utils_1.ns)("admin.$cmd"), handshakeDoc, handshakeOptions);
  27142. if (!("isWritablePrimary" in response)) {
  27143. response.isWritablePrimary = response[constants_1.LEGACY_HELLO_COMMAND];
  27144. }
  27145. if (response.helloOk) {
  27146. conn.helloOk = true;
  27147. }
  27148. const supportedServerErr = checkSupportedServer(response, options);
  27149. if (supportedServerErr) {
  27150. throw supportedServerErr;
  27151. }
  27152. if (options.loadBalanced) {
  27153. if (!response.serviceId) {
  27154. throw new error_1.MongoCompatibilityError("Driver attempted to initialize in load balancing mode, but the server does not support this mode.");
  27155. }
  27156. }
  27157. conn.hello = response;
  27158. conn.lastHelloMS = (/* @__PURE__ */ new Date()).getTime() - start;
  27159. if (!response.arbiterOnly && credentials) {
  27160. authContext.response = response;
  27161. const resolvedCredentials = credentials.resolveAuthMechanism(response);
  27162. const provider = exports2.AUTH_PROVIDERS.get(resolvedCredentials.mechanism);
  27163. if (!provider) {
  27164. throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${resolvedCredentials.mechanism} defined.`);
  27165. }
  27166. try {
  27167. await provider.auth(authContext);
  27168. } catch (error) {
  27169. if (error instanceof error_1.MongoError) {
  27170. error.addErrorLabel(error_1.MongoErrorLabel.HandshakeError);
  27171. if ((0, error_1.needsRetryableWriteLabel)(error, response.maxWireVersion)) {
  27172. error.addErrorLabel(error_1.MongoErrorLabel.RetryableWriteError);
  27173. }
  27174. }
  27175. throw error;
  27176. }
  27177. }
  27178. }
  27179. async function prepareHandshakeDocument(authContext) {
  27180. const options = authContext.options;
  27181. const compressors = options.compressors ? options.compressors : [];
  27182. const { serverApi } = authContext.connection;
  27183. const handshakeDoc = {
  27184. [(serverApi == null ? void 0 : serverApi.version) ? "hello" : constants_1.LEGACY_HELLO_COMMAND]: 1,
  27185. helloOk: true,
  27186. client: options.metadata,
  27187. compression: compressors
  27188. };
  27189. if (options.loadBalanced === true) {
  27190. handshakeDoc.loadBalanced = true;
  27191. }
  27192. const credentials = authContext.credentials;
  27193. if (credentials) {
  27194. if (credentials.mechanism === providers_1.AuthMechanism.MONGODB_DEFAULT && credentials.username) {
  27195. handshakeDoc.saslSupportedMechs = `${credentials.source}.${credentials.username}`;
  27196. const provider2 = exports2.AUTH_PROVIDERS.get(providers_1.AuthMechanism.MONGODB_SCRAM_SHA256);
  27197. if (!provider2) {
  27198. throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${providers_1.AuthMechanism.MONGODB_SCRAM_SHA256} defined.`);
  27199. }
  27200. return provider2.prepare(handshakeDoc, authContext);
  27201. }
  27202. const provider = exports2.AUTH_PROVIDERS.get(credentials.mechanism);
  27203. if (!provider) {
  27204. throw new error_1.MongoInvalidArgumentError(`No AuthProvider for ${credentials.mechanism} defined.`);
  27205. }
  27206. return provider.prepare(handshakeDoc, authContext);
  27207. }
  27208. return handshakeDoc;
  27209. }
  27210. exports2.prepareHandshakeDocument = prepareHandshakeDocument;
  27211. exports2.LEGAL_TLS_SOCKET_OPTIONS = [
  27212. "ALPNProtocols",
  27213. "ca",
  27214. "cert",
  27215. "checkServerIdentity",
  27216. "ciphers",
  27217. "crl",
  27218. "ecdhCurve",
  27219. "key",
  27220. "minDHSize",
  27221. "passphrase",
  27222. "pfx",
  27223. "rejectUnauthorized",
  27224. "secureContext",
  27225. "secureProtocol",
  27226. "servername",
  27227. "session"
  27228. ];
  27229. exports2.LEGAL_TCP_SOCKET_OPTIONS = [
  27230. "family",
  27231. "hints",
  27232. "localAddress",
  27233. "localPort",
  27234. "lookup"
  27235. ];
  27236. function parseConnectOptions(options) {
  27237. const hostAddress = options.hostAddress;
  27238. if (!hostAddress)
  27239. throw new error_1.MongoInvalidArgumentError('Option "hostAddress" is required');
  27240. const result = {};
  27241. for (const name of exports2.LEGAL_TCP_SOCKET_OPTIONS) {
  27242. if (options[name] != null) {
  27243. result[name] = options[name];
  27244. }
  27245. }
  27246. if (typeof hostAddress.socketPath === "string") {
  27247. result.path = hostAddress.socketPath;
  27248. return result;
  27249. } else if (typeof hostAddress.host === "string") {
  27250. result.host = hostAddress.host;
  27251. result.port = hostAddress.port;
  27252. return result;
  27253. } else {
  27254. throw new error_1.MongoRuntimeError(`Unexpected HostAddress ${JSON.stringify(hostAddress)}`);
  27255. }
  27256. }
  27257. function parseSslOptions(options) {
  27258. const result = parseConnectOptions(options);
  27259. for (const name of exports2.LEGAL_TLS_SOCKET_OPTIONS) {
  27260. if (options[name] != null) {
  27261. result[name] = options[name];
  27262. }
  27263. }
  27264. if (options.existingSocket) {
  27265. result.socket = options.existingSocket;
  27266. }
  27267. if (result.servername == null && result.host && !net.isIP(result.host)) {
  27268. result.servername = result.host;
  27269. }
  27270. return result;
  27271. }
  27272. var SOCKET_ERROR_EVENT_LIST = ["error", "close", "timeout", "parseError"];
  27273. var SOCKET_ERROR_EVENTS = new Set(SOCKET_ERROR_EVENT_LIST);
  27274. function makeConnection(options, _callback) {
  27275. const useTLS = options.tls ?? false;
  27276. const keepAlive = options.keepAlive ?? true;
  27277. const socketTimeoutMS = options.socketTimeoutMS ?? Reflect.get(options, "socketTimeout") ?? 0;
  27278. const noDelay = options.noDelay ?? true;
  27279. const connectTimeoutMS = options.connectTimeoutMS ?? 3e4;
  27280. const rejectUnauthorized = options.rejectUnauthorized ?? true;
  27281. const keepAliveInitialDelay = ((options.keepAliveInitialDelay ?? 12e4) > socketTimeoutMS ? Math.round(socketTimeoutMS / 2) : options.keepAliveInitialDelay) ?? 12e4;
  27282. const existingSocket = options.existingSocket;
  27283. let socket;
  27284. const callback = function(err, ret) {
  27285. if (err && socket) {
  27286. socket.destroy();
  27287. }
  27288. _callback(err, ret);
  27289. };
  27290. if (options.proxyHost != null) {
  27291. return makeSocks5Connection({
  27292. ...options,
  27293. connectTimeoutMS
  27294. // Should always be present for Socks5
  27295. }, callback);
  27296. }
  27297. if (useTLS) {
  27298. const tlsSocket = tls.connect(parseSslOptions(options));
  27299. if (typeof tlsSocket.disableRenegotiation === "function") {
  27300. tlsSocket.disableRenegotiation();
  27301. }
  27302. socket = tlsSocket;
  27303. } else if (existingSocket) {
  27304. socket = existingSocket;
  27305. } else {
  27306. socket = net.createConnection(parseConnectOptions(options));
  27307. }
  27308. socket.setKeepAlive(keepAlive, keepAliveInitialDelay);
  27309. socket.setTimeout(connectTimeoutMS);
  27310. socket.setNoDelay(noDelay);
  27311. const connectEvent = useTLS ? "secureConnect" : "connect";
  27312. let cancellationHandler;
  27313. function errorHandler(eventName) {
  27314. return (err) => {
  27315. SOCKET_ERROR_EVENTS.forEach((event) => socket.removeAllListeners(event));
  27316. if (cancellationHandler && options.cancellationToken) {
  27317. options.cancellationToken.removeListener("cancel", cancellationHandler);
  27318. }
  27319. socket.removeListener(connectEvent, connectHandler);
  27320. callback(connectionFailureError(eventName, err));
  27321. };
  27322. }
  27323. function connectHandler() {
  27324. SOCKET_ERROR_EVENTS.forEach((event) => socket.removeAllListeners(event));
  27325. if (cancellationHandler && options.cancellationToken) {
  27326. options.cancellationToken.removeListener("cancel", cancellationHandler);
  27327. }
  27328. if ("authorizationError" in socket) {
  27329. if (socket.authorizationError && rejectUnauthorized) {
  27330. return callback(socket.authorizationError);
  27331. }
  27332. }
  27333. socket.setTimeout(0);
  27334. callback(void 0, socket);
  27335. }
  27336. SOCKET_ERROR_EVENTS.forEach((event) => socket.once(event, errorHandler(event)));
  27337. if (options.cancellationToken) {
  27338. cancellationHandler = errorHandler("cancel");
  27339. options.cancellationToken.once("cancel", cancellationHandler);
  27340. }
  27341. if (existingSocket) {
  27342. process.nextTick(connectHandler);
  27343. } else {
  27344. socket.once(connectEvent, connectHandler);
  27345. }
  27346. }
  27347. function makeSocks5Connection(options, callback) {
  27348. const hostAddress = utils_1.HostAddress.fromHostPort(
  27349. options.proxyHost ?? "",
  27350. // proxyHost is guaranteed to set here
  27351. options.proxyPort ?? 1080
  27352. );
  27353. makeConnection({
  27354. ...options,
  27355. hostAddress,
  27356. tls: false,
  27357. proxyHost: void 0
  27358. }, (err, rawSocket) => {
  27359. if (err) {
  27360. return callback(err);
  27361. }
  27362. const destination = parseConnectOptions(options);
  27363. if (typeof destination.host !== "string" || typeof destination.port !== "number") {
  27364. return callback(new error_1.MongoInvalidArgumentError("Can only make Socks5 connections to TCP hosts"));
  27365. }
  27366. socks_1.SocksClient.createConnection({
  27367. existing_socket: rawSocket,
  27368. timeout: options.connectTimeoutMS,
  27369. command: "connect",
  27370. destination: {
  27371. host: destination.host,
  27372. port: destination.port
  27373. },
  27374. proxy: {
  27375. // host and port are ignored because we pass existing_socket
  27376. host: "iLoveJavaScript",
  27377. port: 0,
  27378. type: 5,
  27379. userId: options.proxyUsername || void 0,
  27380. password: options.proxyPassword || void 0
  27381. }
  27382. }).then(({ socket }) => {
  27383. makeConnection({
  27384. ...options,
  27385. existingSocket: socket,
  27386. proxyHost: void 0
  27387. }, callback);
  27388. }, (error) => callback(connectionFailureError("error", error)));
  27389. });
  27390. }
  27391. function connectionFailureError(type, err) {
  27392. switch (type) {
  27393. case "error":
  27394. return new error_1.MongoNetworkError(err);
  27395. case "timeout":
  27396. return new error_1.MongoNetworkTimeoutError("connection timed out");
  27397. case "close":
  27398. return new error_1.MongoNetworkError("connection closed");
  27399. case "cancel":
  27400. return new error_1.MongoNetworkError("connection establishment was cancelled");
  27401. default:
  27402. return new error_1.MongoNetworkError("unknown network error");
  27403. }
  27404. }
  27405. }
  27406. });
  27407. // node_modules/mongodb/lib/cmap/connection_pool_events.js
  27408. var require_connection_pool_events = __commonJS({
  27409. "node_modules/mongodb/lib/cmap/connection_pool_events.js"(exports2) {
  27410. "use strict";
  27411. Object.defineProperty(exports2, "__esModule", { value: true });
  27412. exports2.ConnectionPoolClearedEvent = exports2.ConnectionCheckedInEvent = exports2.ConnectionCheckedOutEvent = exports2.ConnectionCheckOutFailedEvent = exports2.ConnectionCheckOutStartedEvent = exports2.ConnectionClosedEvent = exports2.ConnectionReadyEvent = exports2.ConnectionCreatedEvent = exports2.ConnectionPoolClosedEvent = exports2.ConnectionPoolReadyEvent = exports2.ConnectionPoolCreatedEvent = exports2.ConnectionPoolMonitoringEvent = void 0;
  27413. var constants_1 = require_constants2();
  27414. var ConnectionPoolMonitoringEvent = class {
  27415. /** @internal */
  27416. constructor(pool) {
  27417. this.time = /* @__PURE__ */ new Date();
  27418. this.address = pool.address;
  27419. }
  27420. };
  27421. exports2.ConnectionPoolMonitoringEvent = ConnectionPoolMonitoringEvent;
  27422. var ConnectionPoolCreatedEvent = class extends ConnectionPoolMonitoringEvent {
  27423. /** @internal */
  27424. constructor(pool) {
  27425. super(pool);
  27426. this.name = constants_1.CONNECTION_POOL_CREATED;
  27427. if (pool.options.credentials != null) {
  27428. this.options = { ...pool.options, credentials: {} };
  27429. } else {
  27430. this.options = pool.options;
  27431. }
  27432. }
  27433. };
  27434. exports2.ConnectionPoolCreatedEvent = ConnectionPoolCreatedEvent;
  27435. var ConnectionPoolReadyEvent = class extends ConnectionPoolMonitoringEvent {
  27436. /** @internal */
  27437. constructor(pool) {
  27438. super(pool);
  27439. this.name = constants_1.CONNECTION_POOL_READY;
  27440. }
  27441. };
  27442. exports2.ConnectionPoolReadyEvent = ConnectionPoolReadyEvent;
  27443. var ConnectionPoolClosedEvent = class extends ConnectionPoolMonitoringEvent {
  27444. /** @internal */
  27445. constructor(pool) {
  27446. super(pool);
  27447. this.name = constants_1.CONNECTION_POOL_CLOSED;
  27448. }
  27449. };
  27450. exports2.ConnectionPoolClosedEvent = ConnectionPoolClosedEvent;
  27451. var ConnectionCreatedEvent = class extends ConnectionPoolMonitoringEvent {
  27452. /** @internal */
  27453. constructor(pool, connection) {
  27454. super(pool);
  27455. this.name = constants_1.CONNECTION_CREATED;
  27456. this.connectionId = connection.id;
  27457. }
  27458. };
  27459. exports2.ConnectionCreatedEvent = ConnectionCreatedEvent;
  27460. var ConnectionReadyEvent = class extends ConnectionPoolMonitoringEvent {
  27461. /** @internal */
  27462. constructor(pool, connection) {
  27463. super(pool);
  27464. this.name = constants_1.CONNECTION_READY;
  27465. this.connectionId = connection.id;
  27466. }
  27467. };
  27468. exports2.ConnectionReadyEvent = ConnectionReadyEvent;
  27469. var ConnectionClosedEvent = class extends ConnectionPoolMonitoringEvent {
  27470. /** @internal */
  27471. constructor(pool, connection, reason, error) {
  27472. super(pool);
  27473. this.name = constants_1.CONNECTION_CLOSED;
  27474. this.connectionId = connection.id;
  27475. this.reason = reason;
  27476. this.serviceId = connection.serviceId;
  27477. this.error = error ?? null;
  27478. }
  27479. };
  27480. exports2.ConnectionClosedEvent = ConnectionClosedEvent;
  27481. var ConnectionCheckOutStartedEvent = class extends ConnectionPoolMonitoringEvent {
  27482. /** @internal */
  27483. constructor(pool) {
  27484. super(pool);
  27485. this.name = constants_1.CONNECTION_CHECK_OUT_STARTED;
  27486. }
  27487. };
  27488. exports2.ConnectionCheckOutStartedEvent = ConnectionCheckOutStartedEvent;
  27489. var ConnectionCheckOutFailedEvent = class extends ConnectionPoolMonitoringEvent {
  27490. /** @internal */
  27491. constructor(pool, reason, error) {
  27492. super(pool);
  27493. this.name = constants_1.CONNECTION_CHECK_OUT_FAILED;
  27494. this.reason = reason;
  27495. this.error = error;
  27496. }
  27497. };
  27498. exports2.ConnectionCheckOutFailedEvent = ConnectionCheckOutFailedEvent;
  27499. var ConnectionCheckedOutEvent = class extends ConnectionPoolMonitoringEvent {
  27500. /** @internal */
  27501. constructor(pool, connection) {
  27502. super(pool);
  27503. this.name = constants_1.CONNECTION_CHECKED_OUT;
  27504. this.connectionId = connection.id;
  27505. }
  27506. };
  27507. exports2.ConnectionCheckedOutEvent = ConnectionCheckedOutEvent;
  27508. var ConnectionCheckedInEvent = class extends ConnectionPoolMonitoringEvent {
  27509. /** @internal */
  27510. constructor(pool, connection) {
  27511. super(pool);
  27512. this.name = constants_1.CONNECTION_CHECKED_IN;
  27513. this.connectionId = connection.id;
  27514. }
  27515. };
  27516. exports2.ConnectionCheckedInEvent = ConnectionCheckedInEvent;
  27517. var ConnectionPoolClearedEvent = class extends ConnectionPoolMonitoringEvent {
  27518. /** @internal */
  27519. constructor(pool, options = {}) {
  27520. super(pool);
  27521. this.name = constants_1.CONNECTION_POOL_CLEARED;
  27522. this.serviceId = options.serviceId;
  27523. this.interruptInUseConnections = options.interruptInUseConnections;
  27524. }
  27525. };
  27526. exports2.ConnectionPoolClearedEvent = ConnectionPoolClearedEvent;
  27527. }
  27528. });
  27529. // node_modules/mongodb/lib/cmap/errors.js
  27530. var require_errors = __commonJS({
  27531. "node_modules/mongodb/lib/cmap/errors.js"(exports2) {
  27532. "use strict";
  27533. Object.defineProperty(exports2, "__esModule", { value: true });
  27534. exports2.WaitQueueTimeoutError = exports2.PoolClearedOnNetworkError = exports2.PoolClearedError = exports2.PoolClosedError = void 0;
  27535. var error_1 = require_error();
  27536. var PoolClosedError = class extends error_1.MongoDriverError {
  27537. constructor(pool) {
  27538. super("Attempted to check out a connection from closed connection pool");
  27539. this.address = pool.address;
  27540. }
  27541. get name() {
  27542. return "MongoPoolClosedError";
  27543. }
  27544. };
  27545. exports2.PoolClosedError = PoolClosedError;
  27546. var PoolClearedError = class extends error_1.MongoNetworkError {
  27547. constructor(pool, message) {
  27548. var _a;
  27549. const errorMessage = message ? message : `Connection pool for ${pool.address} was cleared because another operation failed with: "${(_a = pool.serverError) == null ? void 0 : _a.message}"`;
  27550. super(errorMessage);
  27551. this.address = pool.address;
  27552. this.addErrorLabel(error_1.MongoErrorLabel.RetryableWriteError);
  27553. }
  27554. get name() {
  27555. return "MongoPoolClearedError";
  27556. }
  27557. };
  27558. exports2.PoolClearedError = PoolClearedError;
  27559. var PoolClearedOnNetworkError = class extends PoolClearedError {
  27560. constructor(pool) {
  27561. super(pool, `Connection to ${pool.address} interrupted due to server monitor timeout`);
  27562. }
  27563. get name() {
  27564. return "PoolClearedOnNetworkError";
  27565. }
  27566. };
  27567. exports2.PoolClearedOnNetworkError = PoolClearedOnNetworkError;
  27568. var WaitQueueTimeoutError = class extends error_1.MongoDriverError {
  27569. constructor(message, address) {
  27570. super(message);
  27571. this.address = address;
  27572. }
  27573. get name() {
  27574. return "MongoWaitQueueTimeoutError";
  27575. }
  27576. };
  27577. exports2.WaitQueueTimeoutError = WaitQueueTimeoutError;
  27578. }
  27579. });
  27580. // node_modules/mongodb/lib/cmap/connection_pool.js
  27581. var require_connection_pool = __commonJS({
  27582. "node_modules/mongodb/lib/cmap/connection_pool.js"(exports2) {
  27583. "use strict";
  27584. Object.defineProperty(exports2, "__esModule", { value: true });
  27585. exports2.ConnectionPool = exports2.PoolState = void 0;
  27586. var timers_1 = require("timers");
  27587. var constants_1 = require_constants2();
  27588. var error_1 = require_error();
  27589. var mongo_types_1 = require_mongo_types();
  27590. var utils_1 = require_utils();
  27591. var connect_1 = require_connect();
  27592. var connection_1 = require_connection();
  27593. var connection_pool_events_1 = require_connection_pool_events();
  27594. var errors_1 = require_errors();
  27595. var metrics_1 = require_metrics();
  27596. var kServer = Symbol("server");
  27597. var kConnections = Symbol("connections");
  27598. var kPending = Symbol("pending");
  27599. var kCheckedOut = Symbol("checkedOut");
  27600. var kMinPoolSizeTimer = Symbol("minPoolSizeTimer");
  27601. var kGeneration = Symbol("generation");
  27602. var kServiceGenerations = Symbol("serviceGenerations");
  27603. var kConnectionCounter = Symbol("connectionCounter");
  27604. var kCancellationToken = Symbol("cancellationToken");
  27605. var kWaitQueue = Symbol("waitQueue");
  27606. var kCancelled = Symbol("cancelled");
  27607. var kMetrics = Symbol("metrics");
  27608. var kProcessingWaitQueue = Symbol("processingWaitQueue");
  27609. var kPoolState = Symbol("poolState");
  27610. exports2.PoolState = Object.freeze({
  27611. paused: "paused",
  27612. ready: "ready",
  27613. closed: "closed"
  27614. });
  27615. var ConnectionPool = class _ConnectionPool extends mongo_types_1.TypedEventEmitter {
  27616. constructor(server, options) {
  27617. super();
  27618. this.options = Object.freeze({
  27619. ...options,
  27620. connectionType: connection_1.Connection,
  27621. maxPoolSize: options.maxPoolSize ?? 100,
  27622. minPoolSize: options.minPoolSize ?? 0,
  27623. maxConnecting: options.maxConnecting ?? 2,
  27624. maxIdleTimeMS: options.maxIdleTimeMS ?? 0,
  27625. waitQueueTimeoutMS: options.waitQueueTimeoutMS ?? 0,
  27626. minPoolSizeCheckFrequencyMS: options.minPoolSizeCheckFrequencyMS ?? 100,
  27627. autoEncrypter: options.autoEncrypter,
  27628. metadata: options.metadata
  27629. });
  27630. if (this.options.minPoolSize > this.options.maxPoolSize) {
  27631. throw new error_1.MongoInvalidArgumentError("Connection pool minimum size must not be greater than maximum pool size");
  27632. }
  27633. this[kPoolState] = exports2.PoolState.paused;
  27634. this[kServer] = server;
  27635. this[kConnections] = new utils_1.List();
  27636. this[kPending] = 0;
  27637. this[kCheckedOut] = /* @__PURE__ */ new Set();
  27638. this[kMinPoolSizeTimer] = void 0;
  27639. this[kGeneration] = 0;
  27640. this[kServiceGenerations] = /* @__PURE__ */ new Map();
  27641. this[kConnectionCounter] = (0, utils_1.makeCounter)(1);
  27642. this[kCancellationToken] = new mongo_types_1.CancellationToken();
  27643. this[kCancellationToken].setMaxListeners(Infinity);
  27644. this[kWaitQueue] = new utils_1.List();
  27645. this[kMetrics] = new metrics_1.ConnectionPoolMetrics();
  27646. this[kProcessingWaitQueue] = false;
  27647. this.mongoLogger = this[kServer].topology.client.mongoLogger;
  27648. this.component = "connection";
  27649. process.nextTick(() => {
  27650. this.emitAndLog(_ConnectionPool.CONNECTION_POOL_CREATED, new connection_pool_events_1.ConnectionPoolCreatedEvent(this));
  27651. });
  27652. }
  27653. /** The address of the endpoint the pool is connected to */
  27654. get address() {
  27655. return this.options.hostAddress.toString();
  27656. }
  27657. /**
  27658. * Check if the pool has been closed
  27659. *
  27660. * TODO(NODE-3263): We can remove this property once shell no longer needs it
  27661. */
  27662. get closed() {
  27663. return this[kPoolState] === exports2.PoolState.closed;
  27664. }
  27665. /** An integer representing the SDAM generation of the pool */
  27666. get generation() {
  27667. return this[kGeneration];
  27668. }
  27669. /** An integer expressing how many total connections (available + pending + in use) the pool currently has */
  27670. get totalConnectionCount() {
  27671. return this.availableConnectionCount + this.pendingConnectionCount + this.currentCheckedOutCount;
  27672. }
  27673. /** An integer expressing how many connections are currently available in the pool. */
  27674. get availableConnectionCount() {
  27675. return this[kConnections].length;
  27676. }
  27677. get pendingConnectionCount() {
  27678. return this[kPending];
  27679. }
  27680. get currentCheckedOutCount() {
  27681. return this[kCheckedOut].size;
  27682. }
  27683. get waitQueueSize() {
  27684. return this[kWaitQueue].length;
  27685. }
  27686. get loadBalanced() {
  27687. return this.options.loadBalanced;
  27688. }
  27689. get serviceGenerations() {
  27690. return this[kServiceGenerations];
  27691. }
  27692. get serverError() {
  27693. return this[kServer].description.error;
  27694. }
  27695. /**
  27696. * This is exposed ONLY for use in mongosh, to enable
  27697. * killing all connections if a user quits the shell with
  27698. * operations in progress.
  27699. *
  27700. * This property may be removed as a part of NODE-3263.
  27701. */
  27702. get checkedOutConnections() {
  27703. return this[kCheckedOut];
  27704. }
  27705. /**
  27706. * Get the metrics information for the pool when a wait queue timeout occurs.
  27707. */
  27708. waitQueueErrorMetrics() {
  27709. return this[kMetrics].info(this.options.maxPoolSize);
  27710. }
  27711. /**
  27712. * Set the pool state to "ready"
  27713. */
  27714. ready() {
  27715. if (this[kPoolState] !== exports2.PoolState.paused) {
  27716. return;
  27717. }
  27718. this[kPoolState] = exports2.PoolState.ready;
  27719. this.emitAndLog(_ConnectionPool.CONNECTION_POOL_READY, new connection_pool_events_1.ConnectionPoolReadyEvent(this));
  27720. (0, timers_1.clearTimeout)(this[kMinPoolSizeTimer]);
  27721. this.ensureMinPoolSize();
  27722. }
  27723. /**
  27724. * Check a connection out of this pool. The connection will continue to be tracked, but no reference to it
  27725. * will be held by the pool. This means that if a connection is checked out it MUST be checked back in or
  27726. * explicitly destroyed by the new owner.
  27727. */
  27728. checkOut(callback) {
  27729. this.emitAndLog(_ConnectionPool.CONNECTION_CHECK_OUT_STARTED, new connection_pool_events_1.ConnectionCheckOutStartedEvent(this));
  27730. const waitQueueMember = { callback };
  27731. const waitQueueTimeoutMS = this.options.waitQueueTimeoutMS;
  27732. if (waitQueueTimeoutMS) {
  27733. waitQueueMember.timer = (0, timers_1.setTimeout)(() => {
  27734. waitQueueMember[kCancelled] = true;
  27735. waitQueueMember.timer = void 0;
  27736. this.emitAndLog(_ConnectionPool.CONNECTION_CHECK_OUT_FAILED, new connection_pool_events_1.ConnectionCheckOutFailedEvent(this, "timeout"));
  27737. waitQueueMember.callback(new errors_1.WaitQueueTimeoutError(this.loadBalanced ? this.waitQueueErrorMetrics() : "Timed out while checking out a connection from connection pool", this.address));
  27738. }, waitQueueTimeoutMS);
  27739. }
  27740. this[kWaitQueue].push(waitQueueMember);
  27741. process.nextTick(() => this.processWaitQueue());
  27742. }
  27743. /**
  27744. * Check a connection into the pool.
  27745. *
  27746. * @param connection - The connection to check in
  27747. */
  27748. checkIn(connection) {
  27749. if (!this[kCheckedOut].has(connection)) {
  27750. return;
  27751. }
  27752. const poolClosed = this.closed;
  27753. const stale = this.connectionIsStale(connection);
  27754. const willDestroy = !!(poolClosed || stale || connection.closed);
  27755. if (!willDestroy) {
  27756. connection.markAvailable();
  27757. this[kConnections].unshift(connection);
  27758. }
  27759. this[kCheckedOut].delete(connection);
  27760. this.emitAndLog(_ConnectionPool.CONNECTION_CHECKED_IN, new connection_pool_events_1.ConnectionCheckedInEvent(this, connection));
  27761. if (willDestroy) {
  27762. const reason = connection.closed ? "error" : poolClosed ? "poolClosed" : "stale";
  27763. this.destroyConnection(connection, reason);
  27764. }
  27765. process.nextTick(() => this.processWaitQueue());
  27766. }
  27767. /**
  27768. * Clear the pool
  27769. *
  27770. * Pool reset is handled by incrementing the pool's generation count. Any existing connection of a
  27771. * previous generation will eventually be pruned during subsequent checkouts.
  27772. */
  27773. clear(options = {}) {
  27774. if (this.closed) {
  27775. return;
  27776. }
  27777. if (this.loadBalanced) {
  27778. const { serviceId } = options;
  27779. if (!serviceId) {
  27780. throw new error_1.MongoRuntimeError("ConnectionPool.clear() called in load balanced mode with no serviceId.");
  27781. }
  27782. const sid = serviceId.toHexString();
  27783. const generation = this.serviceGenerations.get(sid);
  27784. if (generation == null) {
  27785. throw new error_1.MongoRuntimeError("Service generations are required in load balancer mode.");
  27786. } else {
  27787. this.serviceGenerations.set(sid, generation + 1);
  27788. }
  27789. this.emitAndLog(_ConnectionPool.CONNECTION_POOL_CLEARED, new connection_pool_events_1.ConnectionPoolClearedEvent(this, { serviceId }));
  27790. return;
  27791. }
  27792. const interruptInUseConnections = options.interruptInUseConnections ?? false;
  27793. const oldGeneration = this[kGeneration];
  27794. this[kGeneration] += 1;
  27795. const alreadyPaused = this[kPoolState] === exports2.PoolState.paused;
  27796. this[kPoolState] = exports2.PoolState.paused;
  27797. this.clearMinPoolSizeTimer();
  27798. if (!alreadyPaused) {
  27799. this.emitAndLog(_ConnectionPool.CONNECTION_POOL_CLEARED, new connection_pool_events_1.ConnectionPoolClearedEvent(this, {
  27800. interruptInUseConnections
  27801. }));
  27802. }
  27803. if (interruptInUseConnections) {
  27804. process.nextTick(() => this.interruptInUseConnections(oldGeneration));
  27805. }
  27806. this.processWaitQueue();
  27807. }
  27808. /**
  27809. * Closes all stale in-use connections in the pool with a resumable PoolClearedOnNetworkError.
  27810. *
  27811. * Only connections where `connection.generation <= minGeneration` are killed.
  27812. */
  27813. interruptInUseConnections(minGeneration) {
  27814. for (const connection of this[kCheckedOut]) {
  27815. if (connection.generation <= minGeneration) {
  27816. this.checkIn(connection);
  27817. connection.onError(new errors_1.PoolClearedOnNetworkError(this));
  27818. }
  27819. }
  27820. }
  27821. close(_options, _cb) {
  27822. let options = _options;
  27823. const callback = _cb ?? _options;
  27824. if (typeof options === "function") {
  27825. options = {};
  27826. }
  27827. options = Object.assign({ force: false }, options);
  27828. if (this.closed) {
  27829. return callback();
  27830. }
  27831. this[kCancellationToken].emit("cancel");
  27832. if (typeof this[kConnectionCounter].return === "function") {
  27833. this[kConnectionCounter].return(void 0);
  27834. }
  27835. this[kPoolState] = exports2.PoolState.closed;
  27836. this.clearMinPoolSizeTimer();
  27837. this.processWaitQueue();
  27838. (0, utils_1.eachAsync)(this[kConnections].toArray(), (conn, cb) => {
  27839. this.emitAndLog(_ConnectionPool.CONNECTION_CLOSED, new connection_pool_events_1.ConnectionClosedEvent(this, conn, "poolClosed"));
  27840. conn.destroy({ force: !!options.force }, cb);
  27841. }, (err) => {
  27842. this[kConnections].clear();
  27843. this.emitAndLog(_ConnectionPool.CONNECTION_POOL_CLOSED, new connection_pool_events_1.ConnectionPoolClosedEvent(this));
  27844. callback(err);
  27845. });
  27846. }
  27847. /**
  27848. * Runs a lambda with an implicitly checked out connection, checking that connection back in when the lambda
  27849. * has completed by calling back.
  27850. *
  27851. * NOTE: please note the required signature of `fn`
  27852. *
  27853. * @remarks When in load balancer mode, connections can be pinned to cursors or transactions.
  27854. * In these cases we pass the connection in to this method to ensure it is used and a new
  27855. * connection is not checked out.
  27856. *
  27857. * @param conn - A pinned connection for use in load balancing mode.
  27858. * @param fn - A function which operates on a managed connection
  27859. * @param callback - The original callback
  27860. */
  27861. withConnection(conn, fn, callback) {
  27862. if (conn) {
  27863. fn(void 0, conn, (fnErr, result) => {
  27864. if (fnErr) {
  27865. return this.withReauthentication(fnErr, conn, fn, callback);
  27866. }
  27867. callback(void 0, result);
  27868. });
  27869. return;
  27870. }
  27871. this.checkOut((err, conn2) => {
  27872. fn(err, conn2, (fnErr, result) => {
  27873. if (fnErr) {
  27874. if (conn2) {
  27875. this.withReauthentication(fnErr, conn2, fn, callback);
  27876. } else {
  27877. callback(fnErr);
  27878. }
  27879. } else {
  27880. callback(void 0, result);
  27881. }
  27882. if (conn2) {
  27883. this.checkIn(conn2);
  27884. }
  27885. });
  27886. });
  27887. }
  27888. withReauthentication(fnErr, conn, fn, callback) {
  27889. if (fnErr instanceof error_1.MongoError && fnErr.code === error_1.MONGODB_ERROR_CODES.Reauthenticate) {
  27890. this.reauthenticate(conn, fn, (error, res) => {
  27891. if (error) {
  27892. return callback(error);
  27893. }
  27894. callback(void 0, res);
  27895. });
  27896. } else {
  27897. callback(fnErr);
  27898. }
  27899. }
  27900. /**
  27901. * Reauthenticate on the same connection and then retry the operation.
  27902. */
  27903. reauthenticate(connection, fn, callback) {
  27904. const authContext = connection.authContext;
  27905. if (!authContext) {
  27906. return callback(new error_1.MongoRuntimeError("No auth context found on connection."));
  27907. }
  27908. const credentials = authContext.credentials;
  27909. if (!credentials) {
  27910. return callback(new error_1.MongoMissingCredentialsError("Connection is missing credentials when asked to reauthenticate"));
  27911. }
  27912. const resolvedCredentials = credentials.resolveAuthMechanism(connection.hello || void 0);
  27913. const provider = connect_1.AUTH_PROVIDERS.get(resolvedCredentials.mechanism);
  27914. if (!provider) {
  27915. return callback(new error_1.MongoMissingCredentialsError(`Reauthenticate failed due to no auth provider for ${credentials.mechanism}`));
  27916. }
  27917. provider.reauth(authContext).then(() => {
  27918. fn(void 0, connection, (fnErr, fnResult) => {
  27919. if (fnErr) {
  27920. return callback(fnErr);
  27921. }
  27922. callback(void 0, fnResult);
  27923. });
  27924. }, (error) => callback(error));
  27925. }
  27926. /** Clear the min pool size timer */
  27927. clearMinPoolSizeTimer() {
  27928. const minPoolSizeTimer = this[kMinPoolSizeTimer];
  27929. if (minPoolSizeTimer) {
  27930. (0, timers_1.clearTimeout)(minPoolSizeTimer);
  27931. }
  27932. }
  27933. destroyConnection(connection, reason) {
  27934. this.emitAndLog(_ConnectionPool.CONNECTION_CLOSED, new connection_pool_events_1.ConnectionClosedEvent(this, connection, reason));
  27935. process.nextTick(() => connection.destroy({ force: false }));
  27936. }
  27937. connectionIsStale(connection) {
  27938. const serviceId = connection.serviceId;
  27939. if (this.loadBalanced && serviceId) {
  27940. const sid = serviceId.toHexString();
  27941. const generation = this.serviceGenerations.get(sid);
  27942. return connection.generation !== generation;
  27943. }
  27944. return connection.generation !== this[kGeneration];
  27945. }
  27946. connectionIsIdle(connection) {
  27947. return !!(this.options.maxIdleTimeMS && connection.idleTime > this.options.maxIdleTimeMS);
  27948. }
  27949. /**
  27950. * Destroys a connection if the connection is perished.
  27951. *
  27952. * @returns `true` if the connection was destroyed, `false` otherwise.
  27953. */
  27954. destroyConnectionIfPerished(connection) {
  27955. const isStale = this.connectionIsStale(connection);
  27956. const isIdle = this.connectionIsIdle(connection);
  27957. if (!isStale && !isIdle && !connection.closed) {
  27958. return false;
  27959. }
  27960. const reason = connection.closed ? "error" : isStale ? "stale" : "idle";
  27961. this.destroyConnection(connection, reason);
  27962. return true;
  27963. }
  27964. createConnection(callback) {
  27965. const connectOptions = {
  27966. ...this.options,
  27967. id: this[kConnectionCounter].next().value,
  27968. generation: this[kGeneration],
  27969. cancellationToken: this[kCancellationToken]
  27970. };
  27971. this[kPending]++;
  27972. this.emitAndLog(_ConnectionPool.CONNECTION_CREATED, new connection_pool_events_1.ConnectionCreatedEvent(this, { id: connectOptions.id }));
  27973. (0, connect_1.connect)(connectOptions, (err, connection) => {
  27974. if (err || !connection) {
  27975. this[kPending]--;
  27976. this.emitAndLog(_ConnectionPool.CONNECTION_CLOSED, new connection_pool_events_1.ConnectionClosedEvent(
  27977. this,
  27978. { id: connectOptions.id, serviceId: void 0 },
  27979. "error",
  27980. // TODO(NODE-5192): Remove this cast
  27981. err
  27982. ));
  27983. if (err instanceof error_1.MongoNetworkError || err instanceof error_1.MongoServerError) {
  27984. err.connectionGeneration = connectOptions.generation;
  27985. }
  27986. callback(err ?? new error_1.MongoRuntimeError("Connection creation failed without error"));
  27987. return;
  27988. }
  27989. if (this[kPoolState] !== exports2.PoolState.ready) {
  27990. this[kPending]--;
  27991. connection.destroy({ force: true });
  27992. callback(this.closed ? new errors_1.PoolClosedError(this) : new errors_1.PoolClearedError(this));
  27993. return;
  27994. }
  27995. for (const event of [...constants_1.APM_EVENTS, connection_1.Connection.CLUSTER_TIME_RECEIVED]) {
  27996. connection.on(event, (e) => this.emit(event, e));
  27997. }
  27998. if (this.loadBalanced) {
  27999. connection.on(connection_1.Connection.PINNED, (pinType) => this[kMetrics].markPinned(pinType));
  28000. connection.on(connection_1.Connection.UNPINNED, (pinType) => this[kMetrics].markUnpinned(pinType));
  28001. const serviceId = connection.serviceId;
  28002. if (serviceId) {
  28003. let generation;
  28004. const sid = serviceId.toHexString();
  28005. if (generation = this.serviceGenerations.get(sid)) {
  28006. connection.generation = generation;
  28007. } else {
  28008. this.serviceGenerations.set(sid, 0);
  28009. connection.generation = 0;
  28010. }
  28011. }
  28012. }
  28013. connection.markAvailable();
  28014. this.emitAndLog(_ConnectionPool.CONNECTION_READY, new connection_pool_events_1.ConnectionReadyEvent(this, connection));
  28015. this[kPending]--;
  28016. callback(void 0, connection);
  28017. return;
  28018. });
  28019. }
  28020. ensureMinPoolSize() {
  28021. const minPoolSize = this.options.minPoolSize;
  28022. if (this[kPoolState] !== exports2.PoolState.ready || minPoolSize === 0) {
  28023. return;
  28024. }
  28025. this[kConnections].prune((connection) => this.destroyConnectionIfPerished(connection));
  28026. if (this.totalConnectionCount < minPoolSize && this.pendingConnectionCount < this.options.maxConnecting) {
  28027. this.createConnection((err, connection) => {
  28028. if (err) {
  28029. this[kServer].handleError(err);
  28030. }
  28031. if (!err && connection) {
  28032. this[kConnections].push(connection);
  28033. process.nextTick(() => this.processWaitQueue());
  28034. }
  28035. if (this[kPoolState] === exports2.PoolState.ready) {
  28036. (0, timers_1.clearTimeout)(this[kMinPoolSizeTimer]);
  28037. this[kMinPoolSizeTimer] = (0, timers_1.setTimeout)(() => this.ensureMinPoolSize(), this.options.minPoolSizeCheckFrequencyMS);
  28038. }
  28039. });
  28040. } else {
  28041. (0, timers_1.clearTimeout)(this[kMinPoolSizeTimer]);
  28042. this[kMinPoolSizeTimer] = (0, timers_1.setTimeout)(() => this.ensureMinPoolSize(), this.options.minPoolSizeCheckFrequencyMS);
  28043. }
  28044. }
  28045. processWaitQueue() {
  28046. if (this[kProcessingWaitQueue]) {
  28047. return;
  28048. }
  28049. this[kProcessingWaitQueue] = true;
  28050. while (this.waitQueueSize) {
  28051. const waitQueueMember = this[kWaitQueue].first();
  28052. if (!waitQueueMember) {
  28053. this[kWaitQueue].shift();
  28054. continue;
  28055. }
  28056. if (waitQueueMember[kCancelled]) {
  28057. this[kWaitQueue].shift();
  28058. continue;
  28059. }
  28060. if (this[kPoolState] !== exports2.PoolState.ready) {
  28061. const reason = this.closed ? "poolClosed" : "connectionError";
  28062. const error = this.closed ? new errors_1.PoolClosedError(this) : new errors_1.PoolClearedError(this);
  28063. this.emitAndLog(_ConnectionPool.CONNECTION_CHECK_OUT_FAILED, new connection_pool_events_1.ConnectionCheckOutFailedEvent(this, reason, error));
  28064. if (waitQueueMember.timer) {
  28065. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  28066. }
  28067. this[kWaitQueue].shift();
  28068. waitQueueMember.callback(error);
  28069. continue;
  28070. }
  28071. if (!this.availableConnectionCount) {
  28072. break;
  28073. }
  28074. const connection = this[kConnections].shift();
  28075. if (!connection) {
  28076. break;
  28077. }
  28078. if (!this.destroyConnectionIfPerished(connection)) {
  28079. this[kCheckedOut].add(connection);
  28080. this.emitAndLog(_ConnectionPool.CONNECTION_CHECKED_OUT, new connection_pool_events_1.ConnectionCheckedOutEvent(this, connection));
  28081. if (waitQueueMember.timer) {
  28082. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  28083. }
  28084. this[kWaitQueue].shift();
  28085. waitQueueMember.callback(void 0, connection);
  28086. }
  28087. }
  28088. const { maxPoolSize, maxConnecting } = this.options;
  28089. while (this.waitQueueSize > 0 && this.pendingConnectionCount < maxConnecting && (maxPoolSize === 0 || this.totalConnectionCount < maxPoolSize)) {
  28090. const waitQueueMember = this[kWaitQueue].shift();
  28091. if (!waitQueueMember || waitQueueMember[kCancelled]) {
  28092. continue;
  28093. }
  28094. this.createConnection((err, connection) => {
  28095. if (waitQueueMember[kCancelled]) {
  28096. if (!err && connection) {
  28097. this[kConnections].push(connection);
  28098. }
  28099. } else {
  28100. if (err) {
  28101. this.emitAndLog(
  28102. _ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
  28103. // TODO(NODE-5192): Remove this cast
  28104. new connection_pool_events_1.ConnectionCheckOutFailedEvent(this, "connectionError", err)
  28105. );
  28106. } else if (connection) {
  28107. this[kCheckedOut].add(connection);
  28108. this.emitAndLog(_ConnectionPool.CONNECTION_CHECKED_OUT, new connection_pool_events_1.ConnectionCheckedOutEvent(this, connection));
  28109. }
  28110. if (waitQueueMember.timer) {
  28111. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  28112. }
  28113. waitQueueMember.callback(err, connection);
  28114. }
  28115. process.nextTick(() => this.processWaitQueue());
  28116. });
  28117. }
  28118. this[kProcessingWaitQueue] = false;
  28119. }
  28120. };
  28121. ConnectionPool.CONNECTION_POOL_CREATED = constants_1.CONNECTION_POOL_CREATED;
  28122. ConnectionPool.CONNECTION_POOL_CLOSED = constants_1.CONNECTION_POOL_CLOSED;
  28123. ConnectionPool.CONNECTION_POOL_CLEARED = constants_1.CONNECTION_POOL_CLEARED;
  28124. ConnectionPool.CONNECTION_POOL_READY = constants_1.CONNECTION_POOL_READY;
  28125. ConnectionPool.CONNECTION_CREATED = constants_1.CONNECTION_CREATED;
  28126. ConnectionPool.CONNECTION_READY = constants_1.CONNECTION_READY;
  28127. ConnectionPool.CONNECTION_CLOSED = constants_1.CONNECTION_CLOSED;
  28128. ConnectionPool.CONNECTION_CHECK_OUT_STARTED = constants_1.CONNECTION_CHECK_OUT_STARTED;
  28129. ConnectionPool.CONNECTION_CHECK_OUT_FAILED = constants_1.CONNECTION_CHECK_OUT_FAILED;
  28130. ConnectionPool.CONNECTION_CHECKED_OUT = constants_1.CONNECTION_CHECKED_OUT;
  28131. ConnectionPool.CONNECTION_CHECKED_IN = constants_1.CONNECTION_CHECKED_IN;
  28132. exports2.ConnectionPool = ConnectionPool;
  28133. }
  28134. });
  28135. // node_modules/mongodb/lib/sdam/monitor.js
  28136. var require_monitor = __commonJS({
  28137. "node_modules/mongodb/lib/sdam/monitor.js"(exports2) {
  28138. "use strict";
  28139. Object.defineProperty(exports2, "__esModule", { value: true });
  28140. exports2.MonitorInterval = exports2.RTTPinger = exports2.Monitor = void 0;
  28141. var timers_1 = require("timers");
  28142. var bson_1 = require_bson2();
  28143. var connect_1 = require_connect();
  28144. var connection_1 = require_connection();
  28145. var constants_1 = require_constants2();
  28146. var error_1 = require_error();
  28147. var mongo_types_1 = require_mongo_types();
  28148. var utils_1 = require_utils();
  28149. var common_1 = require_common();
  28150. var events_1 = require_events();
  28151. var server_1 = require_server();
  28152. var kServer = Symbol("server");
  28153. var kMonitorId = Symbol("monitorId");
  28154. var kConnection = Symbol("connection");
  28155. var kCancellationToken = Symbol("cancellationToken");
  28156. var kRoundTripTime = Symbol("roundTripTime");
  28157. var STATE_IDLE = "idle";
  28158. var STATE_MONITORING = "monitoring";
  28159. var stateTransition = (0, utils_1.makeStateMachine)({
  28160. [common_1.STATE_CLOSING]: [common_1.STATE_CLOSING, STATE_IDLE, common_1.STATE_CLOSED],
  28161. [common_1.STATE_CLOSED]: [common_1.STATE_CLOSED, STATE_MONITORING],
  28162. [STATE_IDLE]: [STATE_IDLE, STATE_MONITORING, common_1.STATE_CLOSING],
  28163. [STATE_MONITORING]: [STATE_MONITORING, STATE_IDLE, common_1.STATE_CLOSING]
  28164. });
  28165. var INVALID_REQUEST_CHECK_STATES = /* @__PURE__ */ new Set([common_1.STATE_CLOSING, common_1.STATE_CLOSED, STATE_MONITORING]);
  28166. function isInCloseState(monitor) {
  28167. return monitor.s.state === common_1.STATE_CLOSED || monitor.s.state === common_1.STATE_CLOSING;
  28168. }
  28169. var Monitor = class extends mongo_types_1.TypedEventEmitter {
  28170. get connection() {
  28171. return this[kConnection];
  28172. }
  28173. constructor(server, options) {
  28174. super();
  28175. this[kServer] = server;
  28176. this[kConnection] = void 0;
  28177. this[kCancellationToken] = new mongo_types_1.CancellationToken();
  28178. this[kCancellationToken].setMaxListeners(Infinity);
  28179. this[kMonitorId] = void 0;
  28180. this.s = {
  28181. state: common_1.STATE_CLOSED
  28182. };
  28183. this.address = server.description.address;
  28184. this.options = Object.freeze({
  28185. connectTimeoutMS: options.connectTimeoutMS ?? 1e4,
  28186. heartbeatFrequencyMS: options.heartbeatFrequencyMS ?? 1e4,
  28187. minHeartbeatFrequencyMS: options.minHeartbeatFrequencyMS ?? 500
  28188. });
  28189. const cancellationToken = this[kCancellationToken];
  28190. const connectOptions = Object.assign(
  28191. {
  28192. id: "<monitor>",
  28193. generation: server.pool.generation,
  28194. connectionType: connection_1.Connection,
  28195. cancellationToken,
  28196. hostAddress: server.description.hostAddress
  28197. },
  28198. options,
  28199. // force BSON serialization options
  28200. {
  28201. raw: false,
  28202. useBigInt64: false,
  28203. promoteLongs: true,
  28204. promoteValues: true,
  28205. promoteBuffers: true
  28206. }
  28207. );
  28208. delete connectOptions.credentials;
  28209. if (connectOptions.autoEncrypter) {
  28210. delete connectOptions.autoEncrypter;
  28211. }
  28212. this.connectOptions = Object.freeze(connectOptions);
  28213. }
  28214. connect() {
  28215. if (this.s.state !== common_1.STATE_CLOSED) {
  28216. return;
  28217. }
  28218. const heartbeatFrequencyMS = this.options.heartbeatFrequencyMS;
  28219. const minHeartbeatFrequencyMS = this.options.minHeartbeatFrequencyMS;
  28220. this[kMonitorId] = new MonitorInterval(monitorServer(this), {
  28221. heartbeatFrequencyMS,
  28222. minHeartbeatFrequencyMS,
  28223. immediate: true
  28224. });
  28225. }
  28226. requestCheck() {
  28227. var _a;
  28228. if (INVALID_REQUEST_CHECK_STATES.has(this.s.state)) {
  28229. return;
  28230. }
  28231. (_a = this[kMonitorId]) == null ? void 0 : _a.wake();
  28232. }
  28233. reset() {
  28234. const topologyVersion = this[kServer].description.topologyVersion;
  28235. if (isInCloseState(this) || topologyVersion == null) {
  28236. return;
  28237. }
  28238. stateTransition(this, common_1.STATE_CLOSING);
  28239. resetMonitorState(this);
  28240. stateTransition(this, STATE_IDLE);
  28241. const heartbeatFrequencyMS = this.options.heartbeatFrequencyMS;
  28242. const minHeartbeatFrequencyMS = this.options.minHeartbeatFrequencyMS;
  28243. this[kMonitorId] = new MonitorInterval(monitorServer(this), {
  28244. heartbeatFrequencyMS,
  28245. minHeartbeatFrequencyMS
  28246. });
  28247. }
  28248. close() {
  28249. if (isInCloseState(this)) {
  28250. return;
  28251. }
  28252. stateTransition(this, common_1.STATE_CLOSING);
  28253. resetMonitorState(this);
  28254. this.emit("close");
  28255. stateTransition(this, common_1.STATE_CLOSED);
  28256. }
  28257. };
  28258. exports2.Monitor = Monitor;
  28259. function resetMonitorState(monitor) {
  28260. var _a, _b, _c;
  28261. (_a = monitor[kMonitorId]) == null ? void 0 : _a.stop();
  28262. monitor[kMonitorId] = void 0;
  28263. (_b = monitor.rttPinger) == null ? void 0 : _b.close();
  28264. monitor.rttPinger = void 0;
  28265. monitor[kCancellationToken].emit("cancel");
  28266. (_c = monitor[kConnection]) == null ? void 0 : _c.destroy({ force: true });
  28267. monitor[kConnection] = void 0;
  28268. }
  28269. function checkServer(monitor, callback) {
  28270. let start = (0, utils_1.now)();
  28271. monitor.emit(server_1.Server.SERVER_HEARTBEAT_STARTED, new events_1.ServerHeartbeatStartedEvent(monitor.address));
  28272. function failureHandler(err) {
  28273. var _a;
  28274. (_a = monitor[kConnection]) == null ? void 0 : _a.destroy({ force: true });
  28275. monitor[kConnection] = void 0;
  28276. monitor.emit(server_1.Server.SERVER_HEARTBEAT_FAILED, new events_1.ServerHeartbeatFailedEvent(monitor.address, (0, utils_1.calculateDurationInMs)(start), err));
  28277. const error = !(err instanceof error_1.MongoError) ? new error_1.MongoError(err) : err;
  28278. error.addErrorLabel(error_1.MongoErrorLabel.ResetPool);
  28279. if (error instanceof error_1.MongoNetworkTimeoutError) {
  28280. error.addErrorLabel(error_1.MongoErrorLabel.InterruptInUseConnections);
  28281. }
  28282. monitor.emit("resetServer", error);
  28283. callback(err);
  28284. }
  28285. const connection = monitor[kConnection];
  28286. if (connection && !connection.closed) {
  28287. const { serverApi, helloOk } = connection;
  28288. const connectTimeoutMS = monitor.options.connectTimeoutMS;
  28289. const maxAwaitTimeMS = monitor.options.heartbeatFrequencyMS;
  28290. const topologyVersion = monitor[kServer].description.topologyVersion;
  28291. const isAwaitable = topologyVersion != null;
  28292. const cmd = {
  28293. [(serverApi == null ? void 0 : serverApi.version) || helloOk ? "hello" : constants_1.LEGACY_HELLO_COMMAND]: 1,
  28294. ...isAwaitable && topologyVersion ? { maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) } : {}
  28295. };
  28296. const options = isAwaitable ? {
  28297. socketTimeoutMS: connectTimeoutMS ? connectTimeoutMS + maxAwaitTimeMS : 0,
  28298. exhaustAllowed: true
  28299. } : { socketTimeoutMS: connectTimeoutMS };
  28300. if (isAwaitable && monitor.rttPinger == null) {
  28301. monitor.rttPinger = new RTTPinger(monitor[kCancellationToken], Object.assign({ heartbeatFrequencyMS: monitor.options.heartbeatFrequencyMS }, monitor.connectOptions));
  28302. }
  28303. connection.command((0, utils_1.ns)("admin.$cmd"), cmd, options, (err, hello) => {
  28304. var _a;
  28305. if (err) {
  28306. return failureHandler(err);
  28307. }
  28308. if (!("isWritablePrimary" in hello)) {
  28309. hello.isWritablePrimary = hello[constants_1.LEGACY_HELLO_COMMAND];
  28310. }
  28311. const duration = isAwaitable && monitor.rttPinger ? monitor.rttPinger.roundTripTime : (0, utils_1.calculateDurationInMs)(start);
  28312. monitor.emit(server_1.Server.SERVER_HEARTBEAT_SUCCEEDED, new events_1.ServerHeartbeatSucceededEvent(monitor.address, duration, hello));
  28313. if (isAwaitable && hello.topologyVersion) {
  28314. monitor.emit(server_1.Server.SERVER_HEARTBEAT_STARTED, new events_1.ServerHeartbeatStartedEvent(monitor.address));
  28315. start = (0, utils_1.now)();
  28316. } else {
  28317. (_a = monitor.rttPinger) == null ? void 0 : _a.close();
  28318. monitor.rttPinger = void 0;
  28319. callback(void 0, hello);
  28320. }
  28321. });
  28322. return;
  28323. }
  28324. (0, connect_1.connect)(monitor.connectOptions, (err, conn) => {
  28325. if (err) {
  28326. monitor[kConnection] = void 0;
  28327. failureHandler(err);
  28328. return;
  28329. }
  28330. if (conn) {
  28331. conn.isMonitoringConnection = true;
  28332. if (isInCloseState(monitor)) {
  28333. conn.destroy({ force: true });
  28334. return;
  28335. }
  28336. monitor[kConnection] = conn;
  28337. monitor.emit(server_1.Server.SERVER_HEARTBEAT_SUCCEEDED, new events_1.ServerHeartbeatSucceededEvent(monitor.address, (0, utils_1.calculateDurationInMs)(start), conn.hello));
  28338. callback(void 0, conn.hello);
  28339. }
  28340. });
  28341. }
  28342. function monitorServer(monitor) {
  28343. return (callback) => {
  28344. if (monitor.s.state === STATE_MONITORING) {
  28345. process.nextTick(callback);
  28346. return;
  28347. }
  28348. stateTransition(monitor, STATE_MONITORING);
  28349. function done() {
  28350. if (!isInCloseState(monitor)) {
  28351. stateTransition(monitor, STATE_IDLE);
  28352. }
  28353. callback();
  28354. }
  28355. checkServer(monitor, (err, hello) => {
  28356. if (err) {
  28357. if (monitor[kServer].description.type === common_1.ServerType.Unknown) {
  28358. return done();
  28359. }
  28360. }
  28361. if (hello && hello.topologyVersion) {
  28362. (0, timers_1.setTimeout)(() => {
  28363. var _a;
  28364. if (!isInCloseState(monitor)) {
  28365. (_a = monitor[kMonitorId]) == null ? void 0 : _a.wake();
  28366. }
  28367. }, 0);
  28368. }
  28369. done();
  28370. });
  28371. };
  28372. }
  28373. function makeTopologyVersion(tv) {
  28374. return {
  28375. processId: tv.processId,
  28376. // tests mock counter as just number, but in a real situation counter should always be a Long
  28377. // TODO(NODE-2674): Preserve int64 sent from MongoDB
  28378. counter: bson_1.Long.isLong(tv.counter) ? tv.counter : bson_1.Long.fromNumber(tv.counter)
  28379. };
  28380. }
  28381. var RTTPinger = class {
  28382. constructor(cancellationToken, options) {
  28383. this.connection = void 0;
  28384. this[kCancellationToken] = cancellationToken;
  28385. this[kRoundTripTime] = 0;
  28386. this.closed = false;
  28387. const heartbeatFrequencyMS = options.heartbeatFrequencyMS;
  28388. this[kMonitorId] = (0, timers_1.setTimeout)(() => measureRoundTripTime(this, options), heartbeatFrequencyMS);
  28389. }
  28390. get roundTripTime() {
  28391. return this[kRoundTripTime];
  28392. }
  28393. close() {
  28394. var _a;
  28395. this.closed = true;
  28396. (0, timers_1.clearTimeout)(this[kMonitorId]);
  28397. (_a = this.connection) == null ? void 0 : _a.destroy({ force: true });
  28398. this.connection = void 0;
  28399. }
  28400. };
  28401. exports2.RTTPinger = RTTPinger;
  28402. function measureRoundTripTime(rttPinger, options) {
  28403. var _a;
  28404. const start = (0, utils_1.now)();
  28405. options.cancellationToken = rttPinger[kCancellationToken];
  28406. const heartbeatFrequencyMS = options.heartbeatFrequencyMS;
  28407. if (rttPinger.closed) {
  28408. return;
  28409. }
  28410. function measureAndReschedule(conn) {
  28411. if (rttPinger.closed) {
  28412. conn == null ? void 0 : conn.destroy({ force: true });
  28413. return;
  28414. }
  28415. if (rttPinger.connection == null) {
  28416. rttPinger.connection = conn;
  28417. }
  28418. rttPinger[kRoundTripTime] = (0, utils_1.calculateDurationInMs)(start);
  28419. rttPinger[kMonitorId] = (0, timers_1.setTimeout)(() => measureRoundTripTime(rttPinger, options), heartbeatFrequencyMS);
  28420. }
  28421. const connection = rttPinger.connection;
  28422. if (connection == null) {
  28423. (0, connect_1.connect)(options, (err, conn) => {
  28424. if (err) {
  28425. rttPinger.connection = void 0;
  28426. rttPinger[kRoundTripTime] = 0;
  28427. return;
  28428. }
  28429. measureAndReschedule(conn);
  28430. });
  28431. return;
  28432. }
  28433. const commandName = ((_a = connection.serverApi) == null ? void 0 : _a.version) || connection.helloOk ? "hello" : constants_1.LEGACY_HELLO_COMMAND;
  28434. connection.commandAsync((0, utils_1.ns)("admin.$cmd"), { [commandName]: 1 }, void 0).then(() => measureAndReschedule(), () => {
  28435. var _a2;
  28436. (_a2 = rttPinger.connection) == null ? void 0 : _a2.destroy({ force: true });
  28437. rttPinger.connection = void 0;
  28438. rttPinger[kRoundTripTime] = 0;
  28439. });
  28440. }
  28441. var MonitorInterval = class {
  28442. constructor(fn, options = {}) {
  28443. this.isExpeditedCallToFnScheduled = false;
  28444. this.stopped = false;
  28445. this.isExecutionInProgress = false;
  28446. this.hasExecutedOnce = false;
  28447. this._executeAndReschedule = () => {
  28448. if (this.stopped)
  28449. return;
  28450. if (this.timerId) {
  28451. (0, timers_1.clearTimeout)(this.timerId);
  28452. }
  28453. this.isExpeditedCallToFnScheduled = false;
  28454. this.isExecutionInProgress = true;
  28455. this.fn(() => {
  28456. this.lastExecutionEnded = (0, utils_1.now)();
  28457. this.isExecutionInProgress = false;
  28458. this._reschedule(this.heartbeatFrequencyMS);
  28459. });
  28460. };
  28461. this.fn = fn;
  28462. this.lastExecutionEnded = -Infinity;
  28463. this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 1e3;
  28464. this.minHeartbeatFrequencyMS = options.minHeartbeatFrequencyMS ?? 500;
  28465. if (options.immediate) {
  28466. this._executeAndReschedule();
  28467. } else {
  28468. this._reschedule(void 0);
  28469. }
  28470. }
  28471. wake() {
  28472. const currentTime = (0, utils_1.now)();
  28473. const timeSinceLastCall = currentTime - this.lastExecutionEnded;
  28474. if (timeSinceLastCall < 0) {
  28475. return this._executeAndReschedule();
  28476. }
  28477. if (this.isExecutionInProgress) {
  28478. return;
  28479. }
  28480. if (this.isExpeditedCallToFnScheduled) {
  28481. return;
  28482. }
  28483. if (timeSinceLastCall < this.minHeartbeatFrequencyMS) {
  28484. this.isExpeditedCallToFnScheduled = true;
  28485. this._reschedule(this.minHeartbeatFrequencyMS - timeSinceLastCall);
  28486. return;
  28487. }
  28488. this._executeAndReschedule();
  28489. }
  28490. stop() {
  28491. this.stopped = true;
  28492. if (this.timerId) {
  28493. (0, timers_1.clearTimeout)(this.timerId);
  28494. this.timerId = void 0;
  28495. }
  28496. this.lastExecutionEnded = -Infinity;
  28497. this.isExpeditedCallToFnScheduled = false;
  28498. }
  28499. toString() {
  28500. return JSON.stringify(this);
  28501. }
  28502. toJSON() {
  28503. const currentTime = (0, utils_1.now)();
  28504. const timeSinceLastCall = currentTime - this.lastExecutionEnded;
  28505. return {
  28506. timerId: this.timerId != null ? "set" : "cleared",
  28507. lastCallTime: this.lastExecutionEnded,
  28508. isExpeditedCheckScheduled: this.isExpeditedCallToFnScheduled,
  28509. stopped: this.stopped,
  28510. heartbeatFrequencyMS: this.heartbeatFrequencyMS,
  28511. minHeartbeatFrequencyMS: this.minHeartbeatFrequencyMS,
  28512. currentTime,
  28513. timeSinceLastCall
  28514. };
  28515. }
  28516. _reschedule(ms) {
  28517. if (this.stopped)
  28518. return;
  28519. if (this.timerId) {
  28520. (0, timers_1.clearTimeout)(this.timerId);
  28521. }
  28522. this.timerId = (0, timers_1.setTimeout)(this._executeAndReschedule, ms || this.heartbeatFrequencyMS);
  28523. }
  28524. };
  28525. exports2.MonitorInterval = MonitorInterval;
  28526. }
  28527. });
  28528. // node_modules/mongodb/lib/sdam/server.js
  28529. var require_server = __commonJS({
  28530. "node_modules/mongodb/lib/sdam/server.js"(exports2) {
  28531. "use strict";
  28532. Object.defineProperty(exports2, "__esModule", { value: true });
  28533. exports2.Server = void 0;
  28534. var util_1 = require("util");
  28535. var connection_1 = require_connection();
  28536. var connection_pool_1 = require_connection_pool();
  28537. var errors_1 = require_errors();
  28538. var constants_1 = require_constants2();
  28539. var error_1 = require_error();
  28540. var mongo_types_1 = require_mongo_types();
  28541. var transactions_1 = require_transactions();
  28542. var utils_1 = require_utils();
  28543. var common_1 = require_common();
  28544. var monitor_1 = require_monitor();
  28545. var server_description_1 = require_server_description();
  28546. var stateTransition = (0, utils_1.makeStateMachine)({
  28547. [common_1.STATE_CLOSED]: [common_1.STATE_CLOSED, common_1.STATE_CONNECTING],
  28548. [common_1.STATE_CONNECTING]: [common_1.STATE_CONNECTING, common_1.STATE_CLOSING, common_1.STATE_CONNECTED, common_1.STATE_CLOSED],
  28549. [common_1.STATE_CONNECTED]: [common_1.STATE_CONNECTED, common_1.STATE_CLOSING, common_1.STATE_CLOSED],
  28550. [common_1.STATE_CLOSING]: [common_1.STATE_CLOSING, common_1.STATE_CLOSED]
  28551. });
  28552. var Server = class _Server extends mongo_types_1.TypedEventEmitter {
  28553. /**
  28554. * Create a server
  28555. */
  28556. constructor(topology, description, options) {
  28557. super();
  28558. this.commandAsync = (0, util_1.promisify)((ns, cmd, options2, callback) => this.command(ns, cmd, options2, callback));
  28559. this.serverApi = options.serverApi;
  28560. const poolOptions = { hostAddress: description.hostAddress, ...options };
  28561. this.topology = topology;
  28562. this.pool = new connection_pool_1.ConnectionPool(this, poolOptions);
  28563. this.s = {
  28564. description,
  28565. options,
  28566. state: common_1.STATE_CLOSED,
  28567. operationCount: 0
  28568. };
  28569. for (const event of [...constants_1.CMAP_EVENTS, ...constants_1.APM_EVENTS]) {
  28570. this.pool.on(event, (e) => this.emit(event, e));
  28571. }
  28572. this.pool.on(connection_1.Connection.CLUSTER_TIME_RECEIVED, (clusterTime) => {
  28573. this.clusterTime = clusterTime;
  28574. });
  28575. if (this.loadBalanced) {
  28576. this.monitor = null;
  28577. return;
  28578. }
  28579. this.monitor = new monitor_1.Monitor(this, this.s.options);
  28580. for (const event of constants_1.HEARTBEAT_EVENTS) {
  28581. this.monitor.on(event, (e) => this.emit(event, e));
  28582. }
  28583. this.monitor.on("resetServer", (error) => markServerUnknown(this, error));
  28584. this.monitor.on(_Server.SERVER_HEARTBEAT_SUCCEEDED, (event) => {
  28585. this.emit(_Server.DESCRIPTION_RECEIVED, new server_description_1.ServerDescription(this.description.hostAddress, event.reply, {
  28586. roundTripTime: calculateRoundTripTime(this.description.roundTripTime, event.duration)
  28587. }));
  28588. if (this.s.state === common_1.STATE_CONNECTING) {
  28589. stateTransition(this, common_1.STATE_CONNECTED);
  28590. this.emit(_Server.CONNECT, this);
  28591. }
  28592. });
  28593. }
  28594. get clusterTime() {
  28595. return this.topology.clusterTime;
  28596. }
  28597. set clusterTime(clusterTime) {
  28598. this.topology.clusterTime = clusterTime;
  28599. }
  28600. get description() {
  28601. return this.s.description;
  28602. }
  28603. get name() {
  28604. return this.s.description.address;
  28605. }
  28606. get autoEncrypter() {
  28607. if (this.s.options && this.s.options.autoEncrypter) {
  28608. return this.s.options.autoEncrypter;
  28609. }
  28610. return;
  28611. }
  28612. get loadBalanced() {
  28613. return this.topology.description.type === common_1.TopologyType.LoadBalanced;
  28614. }
  28615. /**
  28616. * Initiate server connect
  28617. */
  28618. connect() {
  28619. var _a;
  28620. if (this.s.state !== common_1.STATE_CLOSED) {
  28621. return;
  28622. }
  28623. stateTransition(this, common_1.STATE_CONNECTING);
  28624. if (!this.loadBalanced) {
  28625. (_a = this.monitor) == null ? void 0 : _a.connect();
  28626. } else {
  28627. stateTransition(this, common_1.STATE_CONNECTED);
  28628. this.emit(_Server.CONNECT, this);
  28629. }
  28630. }
  28631. /** Destroy the server connection */
  28632. destroy(options, callback) {
  28633. var _a;
  28634. if (typeof options === "function") {
  28635. callback = options;
  28636. options = { force: false };
  28637. }
  28638. options = Object.assign({}, { force: false }, options);
  28639. if (this.s.state === common_1.STATE_CLOSED) {
  28640. if (typeof callback === "function") {
  28641. callback();
  28642. }
  28643. return;
  28644. }
  28645. stateTransition(this, common_1.STATE_CLOSING);
  28646. if (!this.loadBalanced) {
  28647. (_a = this.monitor) == null ? void 0 : _a.close();
  28648. }
  28649. this.pool.close(options, (err) => {
  28650. stateTransition(this, common_1.STATE_CLOSED);
  28651. this.emit("closed");
  28652. if (typeof callback === "function") {
  28653. callback(err);
  28654. }
  28655. });
  28656. }
  28657. /**
  28658. * Immediately schedule monitoring of this server. If there already an attempt being made
  28659. * this will be a no-op.
  28660. */
  28661. requestCheck() {
  28662. var _a;
  28663. if (!this.loadBalanced) {
  28664. (_a = this.monitor) == null ? void 0 : _a.requestCheck();
  28665. }
  28666. }
  28667. /**
  28668. * Execute a command
  28669. * @internal
  28670. */
  28671. command(ns, cmd, options, callback) {
  28672. if (callback == null) {
  28673. throw new error_1.MongoInvalidArgumentError("Callback must be provided");
  28674. }
  28675. if (ns.db == null || typeof ns === "string") {
  28676. throw new error_1.MongoInvalidArgumentError("Namespace must not be a string");
  28677. }
  28678. if (this.s.state === common_1.STATE_CLOSING || this.s.state === common_1.STATE_CLOSED) {
  28679. callback(new error_1.MongoServerClosedError());
  28680. return;
  28681. }
  28682. const finalOptions = Object.assign({}, options, { wireProtocolCommand: false });
  28683. if (finalOptions.omitReadPreference) {
  28684. delete finalOptions.readPreference;
  28685. }
  28686. const session = finalOptions.session;
  28687. const conn = session == null ? void 0 : session.pinnedConnection;
  28688. if (this.loadBalanced && session && conn == null && isPinnableCommand(cmd, session)) {
  28689. this.pool.checkOut((err, checkedOut) => {
  28690. if (err || checkedOut == null) {
  28691. if (callback)
  28692. return callback(err);
  28693. return;
  28694. }
  28695. session.pin(checkedOut);
  28696. this.command(ns, cmd, finalOptions, callback);
  28697. });
  28698. return;
  28699. }
  28700. this.incrementOperationCount();
  28701. this.pool.withConnection(conn, (err, conn2, cb) => {
  28702. if (err || !conn2) {
  28703. this.decrementOperationCount();
  28704. if (!err) {
  28705. return cb(new error_1.MongoRuntimeError("Failed to create connection without error"));
  28706. }
  28707. if (!(err instanceof errors_1.PoolClearedError)) {
  28708. this.handleError(err);
  28709. }
  28710. return cb(err);
  28711. }
  28712. conn2.command(ns, cmd, finalOptions, makeOperationHandler(this, conn2, cmd, finalOptions, (error, response) => {
  28713. this.decrementOperationCount();
  28714. cb(error, response);
  28715. }));
  28716. }, callback);
  28717. }
  28718. /**
  28719. * Handle SDAM error
  28720. * @internal
  28721. */
  28722. handleError(error, connection) {
  28723. if (!(error instanceof error_1.MongoError)) {
  28724. return;
  28725. }
  28726. const isStaleError = error.connectionGeneration && error.connectionGeneration < this.pool.generation;
  28727. if (isStaleError) {
  28728. return;
  28729. }
  28730. const isNetworkNonTimeoutError = error instanceof error_1.MongoNetworkError && !(error instanceof error_1.MongoNetworkTimeoutError);
  28731. const isNetworkTimeoutBeforeHandshakeError = (0, error_1.isNetworkErrorBeforeHandshake)(error);
  28732. const isAuthHandshakeError = error.hasErrorLabel(error_1.MongoErrorLabel.HandshakeError);
  28733. if (isNetworkNonTimeoutError || isNetworkTimeoutBeforeHandshakeError || isAuthHandshakeError) {
  28734. if (!this.loadBalanced) {
  28735. error.addErrorLabel(error_1.MongoErrorLabel.ResetPool);
  28736. markServerUnknown(this, error);
  28737. } else if (connection) {
  28738. this.pool.clear({ serviceId: connection.serviceId });
  28739. }
  28740. } else {
  28741. if ((0, error_1.isSDAMUnrecoverableError)(error)) {
  28742. if (shouldHandleStateChangeError(this, error)) {
  28743. const shouldClearPool = (0, utils_1.maxWireVersion)(this) <= 7 || (0, error_1.isNodeShuttingDownError)(error);
  28744. if (this.loadBalanced && connection && shouldClearPool) {
  28745. this.pool.clear({ serviceId: connection.serviceId });
  28746. }
  28747. if (!this.loadBalanced) {
  28748. if (shouldClearPool) {
  28749. error.addErrorLabel(error_1.MongoErrorLabel.ResetPool);
  28750. }
  28751. markServerUnknown(this, error);
  28752. process.nextTick(() => this.requestCheck());
  28753. }
  28754. }
  28755. }
  28756. }
  28757. }
  28758. /**
  28759. * Decrement the operation count, returning the new count.
  28760. */
  28761. decrementOperationCount() {
  28762. return this.s.operationCount -= 1;
  28763. }
  28764. /**
  28765. * Increment the operation count, returning the new count.
  28766. */
  28767. incrementOperationCount() {
  28768. return this.s.operationCount += 1;
  28769. }
  28770. };
  28771. Server.SERVER_HEARTBEAT_STARTED = constants_1.SERVER_HEARTBEAT_STARTED;
  28772. Server.SERVER_HEARTBEAT_SUCCEEDED = constants_1.SERVER_HEARTBEAT_SUCCEEDED;
  28773. Server.SERVER_HEARTBEAT_FAILED = constants_1.SERVER_HEARTBEAT_FAILED;
  28774. Server.CONNECT = constants_1.CONNECT;
  28775. Server.DESCRIPTION_RECEIVED = constants_1.DESCRIPTION_RECEIVED;
  28776. Server.CLOSED = constants_1.CLOSED;
  28777. Server.ENDED = constants_1.ENDED;
  28778. exports2.Server = Server;
  28779. function calculateRoundTripTime(oldRtt, duration) {
  28780. if (oldRtt === -1) {
  28781. return duration;
  28782. }
  28783. const alpha = 0.2;
  28784. return alpha * duration + (1 - alpha) * oldRtt;
  28785. }
  28786. function markServerUnknown(server, error) {
  28787. var _a;
  28788. if (server.loadBalanced) {
  28789. return;
  28790. }
  28791. if (error instanceof error_1.MongoNetworkError && !(error instanceof error_1.MongoNetworkTimeoutError)) {
  28792. (_a = server.monitor) == null ? void 0 : _a.reset();
  28793. }
  28794. server.emit(Server.DESCRIPTION_RECEIVED, new server_description_1.ServerDescription(server.description.hostAddress, void 0, { error }));
  28795. }
  28796. function isPinnableCommand(cmd, session) {
  28797. if (session) {
  28798. return session.inTransaction() || "aggregate" in cmd || "find" in cmd || "getMore" in cmd || "listCollections" in cmd || "listIndexes" in cmd;
  28799. }
  28800. return false;
  28801. }
  28802. function connectionIsStale(pool, connection) {
  28803. if (connection.serviceId) {
  28804. return connection.generation !== pool.serviceGenerations.get(connection.serviceId.toHexString());
  28805. }
  28806. return connection.generation !== pool.generation;
  28807. }
  28808. function shouldHandleStateChangeError(server, err) {
  28809. const etv = err.topologyVersion;
  28810. const stv = server.description.topologyVersion;
  28811. return (0, server_description_1.compareTopologyVersion)(stv, etv) < 0;
  28812. }
  28813. function inActiveTransaction(session, cmd) {
  28814. return session && session.inTransaction() && !(0, transactions_1.isTransactionCommand)(cmd);
  28815. }
  28816. function isRetryableWritesEnabled(topology) {
  28817. return topology.s.options.retryWrites !== false;
  28818. }
  28819. function makeOperationHandler(server, connection, cmd, options, callback) {
  28820. const session = options == null ? void 0 : options.session;
  28821. return function handleOperationResult(error, result) {
  28822. if (error == null && result != null) {
  28823. return callback(void 0, result);
  28824. }
  28825. if (options != null && "noResponse" in options && options.noResponse === true) {
  28826. return callback(void 0, null);
  28827. }
  28828. if (!error) {
  28829. return callback(new error_1.MongoUnexpectedServerResponseError("Empty response with no error"));
  28830. }
  28831. if (!(error instanceof error_1.MongoError)) {
  28832. return callback(error);
  28833. }
  28834. if (connectionIsStale(server.pool, connection)) {
  28835. return callback(error);
  28836. }
  28837. if (error instanceof error_1.MongoNetworkError) {
  28838. if (session && !session.hasEnded && session.serverSession) {
  28839. session.serverSession.isDirty = true;
  28840. }
  28841. if (inActiveTransaction(session, cmd) && !error.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
  28842. error.addErrorLabel(error_1.MongoErrorLabel.TransientTransactionError);
  28843. }
  28844. if ((isRetryableWritesEnabled(server.topology) || (0, transactions_1.isTransactionCommand)(cmd)) && (0, utils_1.supportsRetryableWrites)(server) && !inActiveTransaction(session, cmd)) {
  28845. error.addErrorLabel(error_1.MongoErrorLabel.RetryableWriteError);
  28846. }
  28847. } else {
  28848. if ((isRetryableWritesEnabled(server.topology) || (0, transactions_1.isTransactionCommand)(cmd)) && (0, error_1.needsRetryableWriteLabel)(error, (0, utils_1.maxWireVersion)(server)) && !inActiveTransaction(session, cmd)) {
  28849. error.addErrorLabel(error_1.MongoErrorLabel.RetryableWriteError);
  28850. }
  28851. }
  28852. if (session && session.isPinned && error.hasErrorLabel(error_1.MongoErrorLabel.TransientTransactionError)) {
  28853. session.unpin({ force: true });
  28854. }
  28855. server.handleError(error, connection);
  28856. return callback(error);
  28857. };
  28858. }
  28859. }
  28860. });
  28861. // node_modules/mongodb/lib/sdam/srv_polling.js
  28862. var require_srv_polling = __commonJS({
  28863. "node_modules/mongodb/lib/sdam/srv_polling.js"(exports2) {
  28864. "use strict";
  28865. Object.defineProperty(exports2, "__esModule", { value: true });
  28866. exports2.SrvPoller = exports2.SrvPollingEvent = void 0;
  28867. var dns = require("dns");
  28868. var timers_1 = require("timers");
  28869. var error_1 = require_error();
  28870. var mongo_types_1 = require_mongo_types();
  28871. var utils_1 = require_utils();
  28872. var SrvPollingEvent = class {
  28873. constructor(srvRecords) {
  28874. this.srvRecords = srvRecords;
  28875. }
  28876. hostnames() {
  28877. return new Set(this.srvRecords.map((r) => utils_1.HostAddress.fromSrvRecord(r).toString()));
  28878. }
  28879. };
  28880. exports2.SrvPollingEvent = SrvPollingEvent;
  28881. var SrvPoller = class _SrvPoller extends mongo_types_1.TypedEventEmitter {
  28882. constructor(options) {
  28883. super();
  28884. if (!options || !options.srvHost) {
  28885. throw new error_1.MongoRuntimeError("Options for SrvPoller must exist and include srvHost");
  28886. }
  28887. this.srvHost = options.srvHost;
  28888. this.srvMaxHosts = options.srvMaxHosts ?? 0;
  28889. this.srvServiceName = options.srvServiceName ?? "mongodb";
  28890. this.rescanSrvIntervalMS = 6e4;
  28891. this.heartbeatFrequencyMS = options.heartbeatFrequencyMS ?? 1e4;
  28892. this.haMode = false;
  28893. this.generation = 0;
  28894. this._timeout = void 0;
  28895. }
  28896. get srvAddress() {
  28897. return `_${this.srvServiceName}._tcp.${this.srvHost}`;
  28898. }
  28899. get intervalMS() {
  28900. return this.haMode ? this.heartbeatFrequencyMS : this.rescanSrvIntervalMS;
  28901. }
  28902. start() {
  28903. if (!this._timeout) {
  28904. this.schedule();
  28905. }
  28906. }
  28907. stop() {
  28908. if (this._timeout) {
  28909. (0, timers_1.clearTimeout)(this._timeout);
  28910. this.generation += 1;
  28911. this._timeout = void 0;
  28912. }
  28913. }
  28914. // TODO(NODE-4994): implement new logging logic for SrvPoller failures
  28915. schedule() {
  28916. if (this._timeout) {
  28917. (0, timers_1.clearTimeout)(this._timeout);
  28918. }
  28919. this._timeout = (0, timers_1.setTimeout)(() => {
  28920. this._poll().catch(() => null);
  28921. }, this.intervalMS);
  28922. }
  28923. success(srvRecords) {
  28924. this.haMode = false;
  28925. this.schedule();
  28926. this.emit(_SrvPoller.SRV_RECORD_DISCOVERY, new SrvPollingEvent(srvRecords));
  28927. }
  28928. failure() {
  28929. this.haMode = true;
  28930. this.schedule();
  28931. }
  28932. async _poll() {
  28933. const generation = this.generation;
  28934. let srvRecords;
  28935. try {
  28936. srvRecords = await dns.promises.resolveSrv(this.srvAddress);
  28937. } catch (dnsError) {
  28938. this.failure();
  28939. return;
  28940. }
  28941. if (generation !== this.generation) {
  28942. return;
  28943. }
  28944. const finalAddresses = [];
  28945. for (const record of srvRecords) {
  28946. if ((0, utils_1.matchesParentDomain)(record.name, this.srvHost)) {
  28947. finalAddresses.push(record);
  28948. }
  28949. }
  28950. if (!finalAddresses.length) {
  28951. this.failure();
  28952. return;
  28953. }
  28954. this.success(finalAddresses);
  28955. }
  28956. };
  28957. SrvPoller.SRV_RECORD_DISCOVERY = "srvRecordDiscovery";
  28958. exports2.SrvPoller = SrvPoller;
  28959. }
  28960. });
  28961. // node_modules/mongodb/lib/sdam/topology.js
  28962. var require_topology = __commonJS({
  28963. "node_modules/mongodb/lib/sdam/topology.js"(exports2) {
  28964. "use strict";
  28965. Object.defineProperty(exports2, "__esModule", { value: true });
  28966. exports2.ServerCapabilities = exports2.Topology = void 0;
  28967. var timers_1 = require("timers");
  28968. var util_1 = require("util");
  28969. var connection_string_1 = require_connection_string();
  28970. var constants_1 = require_constants2();
  28971. var error_1 = require_error();
  28972. var mongo_types_1 = require_mongo_types();
  28973. var read_preference_1 = require_read_preference();
  28974. var utils_1 = require_utils();
  28975. var common_1 = require_common();
  28976. var events_1 = require_events();
  28977. var server_1 = require_server();
  28978. var server_description_1 = require_server_description();
  28979. var server_selection_1 = require_server_selection();
  28980. var srv_polling_1 = require_srv_polling();
  28981. var topology_description_1 = require_topology_description();
  28982. var globalTopologyCounter = 0;
  28983. var stateTransition = (0, utils_1.makeStateMachine)({
  28984. [common_1.STATE_CLOSED]: [common_1.STATE_CLOSED, common_1.STATE_CONNECTING],
  28985. [common_1.STATE_CONNECTING]: [common_1.STATE_CONNECTING, common_1.STATE_CLOSING, common_1.STATE_CONNECTED, common_1.STATE_CLOSED],
  28986. [common_1.STATE_CONNECTED]: [common_1.STATE_CONNECTED, common_1.STATE_CLOSING, common_1.STATE_CLOSED],
  28987. [common_1.STATE_CLOSING]: [common_1.STATE_CLOSING, common_1.STATE_CLOSED]
  28988. });
  28989. var kCancelled = Symbol("cancelled");
  28990. var kWaitQueue = Symbol("waitQueue");
  28991. var Topology = class _Topology extends mongo_types_1.TypedEventEmitter {
  28992. /**
  28993. * @param seedlist - a list of HostAddress instances to connect to
  28994. */
  28995. constructor(client, seeds, options) {
  28996. super();
  28997. this.client = client;
  28998. this.selectServerAsync = (0, util_1.promisify)((selector, options2, callback) => this.selectServer(selector, options2, callback));
  28999. options = options ?? {
  29000. hosts: [utils_1.HostAddress.fromString("localhost:27017")],
  29001. ...Object.fromEntries(connection_string_1.DEFAULT_OPTIONS.entries()),
  29002. ...Object.fromEntries(connection_string_1.FEATURE_FLAGS.entries())
  29003. };
  29004. if (typeof seeds === "string") {
  29005. seeds = [utils_1.HostAddress.fromString(seeds)];
  29006. } else if (!Array.isArray(seeds)) {
  29007. seeds = [seeds];
  29008. }
  29009. const seedlist = [];
  29010. for (const seed of seeds) {
  29011. if (typeof seed === "string") {
  29012. seedlist.push(utils_1.HostAddress.fromString(seed));
  29013. } else if (seed instanceof utils_1.HostAddress) {
  29014. seedlist.push(seed);
  29015. } else {
  29016. throw new error_1.MongoRuntimeError(`Topology cannot be constructed from ${JSON.stringify(seed)}`);
  29017. }
  29018. }
  29019. const topologyType = topologyTypeFromOptions(options);
  29020. const topologyId = globalTopologyCounter++;
  29021. const selectedHosts = options.srvMaxHosts == null || options.srvMaxHosts === 0 || options.srvMaxHosts >= seedlist.length ? seedlist : (0, utils_1.shuffle)(seedlist, options.srvMaxHosts);
  29022. const serverDescriptions = /* @__PURE__ */ new Map();
  29023. for (const hostAddress of selectedHosts) {
  29024. serverDescriptions.set(hostAddress.toString(), new server_description_1.ServerDescription(hostAddress));
  29025. }
  29026. this[kWaitQueue] = new utils_1.List();
  29027. this.s = {
  29028. // the id of this topology
  29029. id: topologyId,
  29030. // passed in options
  29031. options,
  29032. // initial seedlist of servers to connect to
  29033. seedlist,
  29034. // initial state
  29035. state: common_1.STATE_CLOSED,
  29036. // the topology description
  29037. description: new topology_description_1.TopologyDescription(topologyType, serverDescriptions, options.replicaSet, void 0, void 0, void 0, options),
  29038. serverSelectionTimeoutMS: options.serverSelectionTimeoutMS,
  29039. heartbeatFrequencyMS: options.heartbeatFrequencyMS,
  29040. minHeartbeatFrequencyMS: options.minHeartbeatFrequencyMS,
  29041. // a map of server instances to normalized addresses
  29042. servers: /* @__PURE__ */ new Map(),
  29043. credentials: options == null ? void 0 : options.credentials,
  29044. clusterTime: void 0,
  29045. // timer management
  29046. connectionTimers: /* @__PURE__ */ new Set(),
  29047. detectShardedTopology: (ev) => this.detectShardedTopology(ev),
  29048. detectSrvRecords: (ev) => this.detectSrvRecords(ev)
  29049. };
  29050. if (options.srvHost && !options.loadBalanced) {
  29051. this.s.srvPoller = options.srvPoller ?? new srv_polling_1.SrvPoller({
  29052. heartbeatFrequencyMS: this.s.heartbeatFrequencyMS,
  29053. srvHost: options.srvHost,
  29054. srvMaxHosts: options.srvMaxHosts,
  29055. srvServiceName: options.srvServiceName
  29056. });
  29057. this.on(_Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology);
  29058. }
  29059. }
  29060. detectShardedTopology(event) {
  29061. var _a, _b, _c;
  29062. const previousType = event.previousDescription.type;
  29063. const newType = event.newDescription.type;
  29064. const transitionToSharded = previousType !== common_1.TopologyType.Sharded && newType === common_1.TopologyType.Sharded;
  29065. const srvListeners = (_a = this.s.srvPoller) == null ? void 0 : _a.listeners(srv_polling_1.SrvPoller.SRV_RECORD_DISCOVERY);
  29066. const listeningToSrvPolling = !!(srvListeners == null ? void 0 : srvListeners.includes(this.s.detectSrvRecords));
  29067. if (transitionToSharded && !listeningToSrvPolling) {
  29068. (_b = this.s.srvPoller) == null ? void 0 : _b.on(srv_polling_1.SrvPoller.SRV_RECORD_DISCOVERY, this.s.detectSrvRecords);
  29069. (_c = this.s.srvPoller) == null ? void 0 : _c.start();
  29070. }
  29071. }
  29072. detectSrvRecords(ev) {
  29073. const previousTopologyDescription = this.s.description;
  29074. this.s.description = this.s.description.updateFromSrvPollingEvent(ev, this.s.options.srvMaxHosts);
  29075. if (this.s.description === previousTopologyDescription) {
  29076. return;
  29077. }
  29078. updateServers(this);
  29079. this.emit(_Topology.TOPOLOGY_DESCRIPTION_CHANGED, new events_1.TopologyDescriptionChangedEvent(this.s.id, previousTopologyDescription, this.s.description));
  29080. }
  29081. /**
  29082. * @returns A `TopologyDescription` for this topology
  29083. */
  29084. get description() {
  29085. return this.s.description;
  29086. }
  29087. get loadBalanced() {
  29088. return this.s.options.loadBalanced;
  29089. }
  29090. get capabilities() {
  29091. return new ServerCapabilities(this.lastHello());
  29092. }
  29093. connect(options, callback) {
  29094. if (typeof options === "function")
  29095. callback = options, options = {};
  29096. options = options ?? {};
  29097. if (this.s.state === common_1.STATE_CONNECTED) {
  29098. if (typeof callback === "function") {
  29099. callback();
  29100. }
  29101. return;
  29102. }
  29103. stateTransition(this, common_1.STATE_CONNECTING);
  29104. this.emit(_Topology.TOPOLOGY_OPENING, new events_1.TopologyOpeningEvent(this.s.id));
  29105. this.emit(_Topology.TOPOLOGY_DESCRIPTION_CHANGED, new events_1.TopologyDescriptionChangedEvent(
  29106. this.s.id,
  29107. new topology_description_1.TopologyDescription(common_1.TopologyType.Unknown),
  29108. // initial is always Unknown
  29109. this.s.description
  29110. ));
  29111. const serverDescriptions = Array.from(this.s.description.servers.values());
  29112. this.s.servers = new Map(serverDescriptions.map((serverDescription) => [
  29113. serverDescription.address,
  29114. createAndConnectServer(this, serverDescription)
  29115. ]));
  29116. if (this.s.options.loadBalanced) {
  29117. for (const description of serverDescriptions) {
  29118. const newDescription = new server_description_1.ServerDescription(description.hostAddress, void 0, {
  29119. loadBalanced: this.s.options.loadBalanced
  29120. });
  29121. this.serverUpdateHandler(newDescription);
  29122. }
  29123. }
  29124. const exitWithError = (error) => callback ? callback(error) : this.emit(_Topology.ERROR, error);
  29125. const readPreference = options.readPreference ?? read_preference_1.ReadPreference.primary;
  29126. this.selectServer((0, server_selection_1.readPreferenceServerSelector)(readPreference), options, (err, server) => {
  29127. if (err) {
  29128. return this.close({ force: false }, () => exitWithError(err));
  29129. }
  29130. const skipPingOnConnect = this.s.options[Symbol.for("@@mdb.skipPingOnConnect")] === true;
  29131. if (!skipPingOnConnect && server && this.s.credentials) {
  29132. server.command((0, utils_1.ns)("admin.$cmd"), { ping: 1 }, {}, (err2) => {
  29133. if (err2) {
  29134. return exitWithError(err2);
  29135. }
  29136. stateTransition(this, common_1.STATE_CONNECTED);
  29137. this.emit(_Topology.OPEN, this);
  29138. this.emit(_Topology.CONNECT, this);
  29139. callback == null ? void 0 : callback(void 0, this);
  29140. });
  29141. return;
  29142. }
  29143. stateTransition(this, common_1.STATE_CONNECTED);
  29144. this.emit(_Topology.OPEN, this);
  29145. this.emit(_Topology.CONNECT, this);
  29146. callback == null ? void 0 : callback(void 0, this);
  29147. });
  29148. }
  29149. close(options, callback) {
  29150. options = options ?? { force: false };
  29151. if (this.s.state === common_1.STATE_CLOSED || this.s.state === common_1.STATE_CLOSING) {
  29152. return callback == null ? void 0 : callback();
  29153. }
  29154. const destroyedServers = Array.from(this.s.servers.values(), (server) => {
  29155. return (0, util_1.promisify)(destroyServer)(server, this, { force: !!(options == null ? void 0 : options.force) });
  29156. });
  29157. Promise.all(destroyedServers).then(() => {
  29158. this.s.servers.clear();
  29159. stateTransition(this, common_1.STATE_CLOSING);
  29160. drainWaitQueue(this[kWaitQueue], new error_1.MongoTopologyClosedError());
  29161. (0, common_1.drainTimerQueue)(this.s.connectionTimers);
  29162. if (this.s.srvPoller) {
  29163. this.s.srvPoller.stop();
  29164. this.s.srvPoller.removeListener(srv_polling_1.SrvPoller.SRV_RECORD_DISCOVERY, this.s.detectSrvRecords);
  29165. }
  29166. this.removeListener(_Topology.TOPOLOGY_DESCRIPTION_CHANGED, this.s.detectShardedTopology);
  29167. stateTransition(this, common_1.STATE_CLOSED);
  29168. this.emit(_Topology.TOPOLOGY_CLOSED, new events_1.TopologyClosedEvent(this.s.id));
  29169. }).finally(() => callback == null ? void 0 : callback());
  29170. }
  29171. /**
  29172. * Selects a server according to the selection predicate provided
  29173. *
  29174. * @param selector - An optional selector to select servers by, defaults to a random selection within a latency window
  29175. * @param options - Optional settings related to server selection
  29176. * @param callback - The callback used to indicate success or failure
  29177. * @returns An instance of a `Server` meeting the criteria of the predicate provided
  29178. */
  29179. selectServer(selector, options, callback) {
  29180. let serverSelector;
  29181. if (typeof selector !== "function") {
  29182. if (typeof selector === "string") {
  29183. serverSelector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.fromString(selector));
  29184. } else {
  29185. let readPreference;
  29186. if (selector instanceof read_preference_1.ReadPreference) {
  29187. readPreference = selector;
  29188. } else {
  29189. read_preference_1.ReadPreference.translate(options);
  29190. readPreference = options.readPreference || read_preference_1.ReadPreference.primary;
  29191. }
  29192. serverSelector = (0, server_selection_1.readPreferenceServerSelector)(readPreference);
  29193. }
  29194. } else {
  29195. serverSelector = selector;
  29196. }
  29197. options = Object.assign({}, { serverSelectionTimeoutMS: this.s.serverSelectionTimeoutMS }, options);
  29198. const isSharded = this.description.type === common_1.TopologyType.Sharded;
  29199. const session = options.session;
  29200. const transaction = session && session.transaction;
  29201. if (isSharded && transaction && transaction.server) {
  29202. callback(void 0, transaction.server);
  29203. return;
  29204. }
  29205. const waitQueueMember = {
  29206. serverSelector,
  29207. transaction,
  29208. callback
  29209. };
  29210. const serverSelectionTimeoutMS = options.serverSelectionTimeoutMS;
  29211. if (serverSelectionTimeoutMS) {
  29212. waitQueueMember.timer = (0, timers_1.setTimeout)(() => {
  29213. waitQueueMember[kCancelled] = true;
  29214. waitQueueMember.timer = void 0;
  29215. const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
  29216. waitQueueMember.callback(timeoutError);
  29217. }, serverSelectionTimeoutMS);
  29218. }
  29219. this[kWaitQueue].push(waitQueueMember);
  29220. processWaitQueue(this);
  29221. }
  29222. /**
  29223. * Update the internal TopologyDescription with a ServerDescription
  29224. *
  29225. * @param serverDescription - The server to update in the internal list of server descriptions
  29226. */
  29227. serverUpdateHandler(serverDescription) {
  29228. if (!this.s.description.hasServer(serverDescription.address)) {
  29229. return;
  29230. }
  29231. if (isStaleServerDescription(this.s.description, serverDescription)) {
  29232. return;
  29233. }
  29234. const previousTopologyDescription = this.s.description;
  29235. const previousServerDescription = this.s.description.servers.get(serverDescription.address);
  29236. if (!previousServerDescription) {
  29237. return;
  29238. }
  29239. const clusterTime = serverDescription.$clusterTime;
  29240. if (clusterTime) {
  29241. (0, common_1._advanceClusterTime)(this, clusterTime);
  29242. }
  29243. const equalDescriptions = previousServerDescription && previousServerDescription.equals(serverDescription);
  29244. this.s.description = this.s.description.update(serverDescription);
  29245. if (this.s.description.compatibilityError) {
  29246. this.emit(_Topology.ERROR, new error_1.MongoCompatibilityError(this.s.description.compatibilityError));
  29247. return;
  29248. }
  29249. if (!equalDescriptions) {
  29250. const newDescription = this.s.description.servers.get(serverDescription.address);
  29251. if (newDescription) {
  29252. this.emit(_Topology.SERVER_DESCRIPTION_CHANGED, new events_1.ServerDescriptionChangedEvent(this.s.id, serverDescription.address, previousServerDescription, newDescription));
  29253. }
  29254. }
  29255. updateServers(this, serverDescription);
  29256. if (this[kWaitQueue].length > 0) {
  29257. processWaitQueue(this);
  29258. }
  29259. if (!equalDescriptions) {
  29260. this.emit(_Topology.TOPOLOGY_DESCRIPTION_CHANGED, new events_1.TopologyDescriptionChangedEvent(this.s.id, previousTopologyDescription, this.s.description));
  29261. }
  29262. }
  29263. auth(credentials, callback) {
  29264. if (typeof credentials === "function")
  29265. callback = credentials, credentials = void 0;
  29266. if (typeof callback === "function")
  29267. callback(void 0, true);
  29268. }
  29269. get clientMetadata() {
  29270. return this.s.options.metadata;
  29271. }
  29272. isConnected() {
  29273. return this.s.state === common_1.STATE_CONNECTED;
  29274. }
  29275. isDestroyed() {
  29276. return this.s.state === common_1.STATE_CLOSED;
  29277. }
  29278. // NOTE: There are many places in code where we explicitly check the last hello
  29279. // to do feature support detection. This should be done any other way, but for
  29280. // now we will just return the first hello seen, which should suffice.
  29281. lastHello() {
  29282. const serverDescriptions = Array.from(this.description.servers.values());
  29283. if (serverDescriptions.length === 0)
  29284. return {};
  29285. const sd = serverDescriptions.filter((sd2) => sd2.type !== common_1.ServerType.Unknown)[0];
  29286. const result = sd || { maxWireVersion: this.description.commonWireVersion };
  29287. return result;
  29288. }
  29289. get commonWireVersion() {
  29290. return this.description.commonWireVersion;
  29291. }
  29292. get logicalSessionTimeoutMinutes() {
  29293. return this.description.logicalSessionTimeoutMinutes;
  29294. }
  29295. get clusterTime() {
  29296. return this.s.clusterTime;
  29297. }
  29298. set clusterTime(clusterTime) {
  29299. this.s.clusterTime = clusterTime;
  29300. }
  29301. };
  29302. Topology.SERVER_OPENING = constants_1.SERVER_OPENING;
  29303. Topology.SERVER_CLOSED = constants_1.SERVER_CLOSED;
  29304. Topology.SERVER_DESCRIPTION_CHANGED = constants_1.SERVER_DESCRIPTION_CHANGED;
  29305. Topology.TOPOLOGY_OPENING = constants_1.TOPOLOGY_OPENING;
  29306. Topology.TOPOLOGY_CLOSED = constants_1.TOPOLOGY_CLOSED;
  29307. Topology.TOPOLOGY_DESCRIPTION_CHANGED = constants_1.TOPOLOGY_DESCRIPTION_CHANGED;
  29308. Topology.ERROR = constants_1.ERROR;
  29309. Topology.OPEN = constants_1.OPEN;
  29310. Topology.CONNECT = constants_1.CONNECT;
  29311. Topology.CLOSE = constants_1.CLOSE;
  29312. Topology.TIMEOUT = constants_1.TIMEOUT;
  29313. exports2.Topology = Topology;
  29314. function destroyServer(server, topology, options, callback) {
  29315. options = options ?? { force: false };
  29316. for (const event of constants_1.LOCAL_SERVER_EVENTS) {
  29317. server.removeAllListeners(event);
  29318. }
  29319. server.destroy(options, () => {
  29320. topology.emit(Topology.SERVER_CLOSED, new events_1.ServerClosedEvent(topology.s.id, server.description.address));
  29321. for (const event of constants_1.SERVER_RELAY_EVENTS) {
  29322. server.removeAllListeners(event);
  29323. }
  29324. if (typeof callback === "function") {
  29325. callback();
  29326. }
  29327. });
  29328. }
  29329. function topologyTypeFromOptions(options) {
  29330. if (options == null ? void 0 : options.directConnection) {
  29331. return common_1.TopologyType.Single;
  29332. }
  29333. if (options == null ? void 0 : options.replicaSet) {
  29334. return common_1.TopologyType.ReplicaSetNoPrimary;
  29335. }
  29336. if (options == null ? void 0 : options.loadBalanced) {
  29337. return common_1.TopologyType.LoadBalanced;
  29338. }
  29339. return common_1.TopologyType.Unknown;
  29340. }
  29341. function createAndConnectServer(topology, serverDescription) {
  29342. topology.emit(Topology.SERVER_OPENING, new events_1.ServerOpeningEvent(topology.s.id, serverDescription.address));
  29343. const server = new server_1.Server(topology, serverDescription, topology.s.options);
  29344. for (const event of constants_1.SERVER_RELAY_EVENTS) {
  29345. server.on(event, (e) => topology.emit(event, e));
  29346. }
  29347. server.on(server_1.Server.DESCRIPTION_RECEIVED, (description) => topology.serverUpdateHandler(description));
  29348. server.connect();
  29349. return server;
  29350. }
  29351. function updateServers(topology, incomingServerDescription) {
  29352. if (incomingServerDescription && topology.s.servers.has(incomingServerDescription.address)) {
  29353. const server = topology.s.servers.get(incomingServerDescription.address);
  29354. if (server) {
  29355. server.s.description = incomingServerDescription;
  29356. if (incomingServerDescription.error instanceof error_1.MongoError && incomingServerDescription.error.hasErrorLabel(error_1.MongoErrorLabel.ResetPool)) {
  29357. const interruptInUseConnections = incomingServerDescription.error.hasErrorLabel(error_1.MongoErrorLabel.InterruptInUseConnections);
  29358. server.pool.clear({ interruptInUseConnections });
  29359. } else if (incomingServerDescription.error == null) {
  29360. const newTopologyType = topology.s.description.type;
  29361. const shouldMarkPoolReady = incomingServerDescription.isDataBearing || incomingServerDescription.type !== common_1.ServerType.Unknown && newTopologyType === common_1.TopologyType.Single;
  29362. if (shouldMarkPoolReady) {
  29363. server.pool.ready();
  29364. }
  29365. }
  29366. }
  29367. }
  29368. for (const serverDescription of topology.description.servers.values()) {
  29369. if (!topology.s.servers.has(serverDescription.address)) {
  29370. const server = createAndConnectServer(topology, serverDescription);
  29371. topology.s.servers.set(serverDescription.address, server);
  29372. }
  29373. }
  29374. for (const entry of topology.s.servers) {
  29375. const serverAddress = entry[0];
  29376. if (topology.description.hasServer(serverAddress)) {
  29377. continue;
  29378. }
  29379. if (!topology.s.servers.has(serverAddress)) {
  29380. continue;
  29381. }
  29382. const server = topology.s.servers.get(serverAddress);
  29383. topology.s.servers.delete(serverAddress);
  29384. if (server) {
  29385. destroyServer(server, topology);
  29386. }
  29387. }
  29388. }
  29389. function drainWaitQueue(queue, err) {
  29390. while (queue.length) {
  29391. const waitQueueMember = queue.shift();
  29392. if (!waitQueueMember) {
  29393. continue;
  29394. }
  29395. if (waitQueueMember.timer) {
  29396. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  29397. }
  29398. if (!waitQueueMember[kCancelled]) {
  29399. waitQueueMember.callback(err);
  29400. }
  29401. }
  29402. }
  29403. function processWaitQueue(topology) {
  29404. if (topology.s.state === common_1.STATE_CLOSED) {
  29405. drainWaitQueue(topology[kWaitQueue], new error_1.MongoTopologyClosedError());
  29406. return;
  29407. }
  29408. const isSharded = topology.description.type === common_1.TopologyType.Sharded;
  29409. const serverDescriptions = Array.from(topology.description.servers.values());
  29410. const membersToProcess = topology[kWaitQueue].length;
  29411. for (let i = 0; i < membersToProcess; ++i) {
  29412. const waitQueueMember = topology[kWaitQueue].shift();
  29413. if (!waitQueueMember) {
  29414. continue;
  29415. }
  29416. if (waitQueueMember[kCancelled]) {
  29417. continue;
  29418. }
  29419. let selectedDescriptions;
  29420. try {
  29421. const serverSelector = waitQueueMember.serverSelector;
  29422. selectedDescriptions = serverSelector ? serverSelector(topology.description, serverDescriptions) : serverDescriptions;
  29423. } catch (e) {
  29424. if (waitQueueMember.timer) {
  29425. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  29426. }
  29427. waitQueueMember.callback(e);
  29428. continue;
  29429. }
  29430. let selectedServer;
  29431. if (selectedDescriptions.length === 0) {
  29432. topology[kWaitQueue].push(waitQueueMember);
  29433. continue;
  29434. } else if (selectedDescriptions.length === 1) {
  29435. selectedServer = topology.s.servers.get(selectedDescriptions[0].address);
  29436. } else {
  29437. const descriptions = (0, utils_1.shuffle)(selectedDescriptions, 2);
  29438. const server1 = topology.s.servers.get(descriptions[0].address);
  29439. const server2 = topology.s.servers.get(descriptions[1].address);
  29440. selectedServer = server1 && server2 && server1.s.operationCount < server2.s.operationCount ? server1 : server2;
  29441. }
  29442. if (!selectedServer) {
  29443. waitQueueMember.callback(new error_1.MongoServerSelectionError("server selection returned a server description but the server was not found in the topology", topology.description));
  29444. return;
  29445. }
  29446. const transaction = waitQueueMember.transaction;
  29447. if (isSharded && transaction && transaction.isActive && selectedServer) {
  29448. transaction.pinServer(selectedServer);
  29449. }
  29450. if (waitQueueMember.timer) {
  29451. (0, timers_1.clearTimeout)(waitQueueMember.timer);
  29452. }
  29453. waitQueueMember.callback(void 0, selectedServer);
  29454. }
  29455. if (topology[kWaitQueue].length > 0) {
  29456. for (const [, server] of topology.s.servers) {
  29457. process.nextTick(function scheduleServerCheck() {
  29458. return server.requestCheck();
  29459. });
  29460. }
  29461. }
  29462. }
  29463. function isStaleServerDescription(topologyDescription, incomingServerDescription) {
  29464. const currentServerDescription = topologyDescription.servers.get(incomingServerDescription.address);
  29465. const currentTopologyVersion = currentServerDescription == null ? void 0 : currentServerDescription.topologyVersion;
  29466. return (0, server_description_1.compareTopologyVersion)(currentTopologyVersion, incomingServerDescription.topologyVersion) > 0;
  29467. }
  29468. var ServerCapabilities = class {
  29469. constructor(hello) {
  29470. this.minWireVersion = hello.minWireVersion || 0;
  29471. this.maxWireVersion = hello.maxWireVersion || 0;
  29472. }
  29473. get hasAggregationCursor() {
  29474. return this.maxWireVersion >= 1;
  29475. }
  29476. get hasWriteCommands() {
  29477. return this.maxWireVersion >= 2;
  29478. }
  29479. get hasTextSearch() {
  29480. return this.minWireVersion >= 0;
  29481. }
  29482. get hasAuthCommands() {
  29483. return this.maxWireVersion >= 1;
  29484. }
  29485. get hasListCollectionsCommand() {
  29486. return this.maxWireVersion >= 3;
  29487. }
  29488. get hasListIndexesCommand() {
  29489. return this.maxWireVersion >= 3;
  29490. }
  29491. get supportsSnapshotReads() {
  29492. return this.maxWireVersion >= 13;
  29493. }
  29494. get commandsTakeWriteConcern() {
  29495. return this.maxWireVersion >= 5;
  29496. }
  29497. get commandsTakeCollation() {
  29498. return this.maxWireVersion >= 5;
  29499. }
  29500. };
  29501. exports2.ServerCapabilities = ServerCapabilities;
  29502. }
  29503. });
  29504. // node_modules/mongodb/lib/mongo_client.js
  29505. var require_mongo_client = __commonJS({
  29506. "node_modules/mongodb/lib/mongo_client.js"(exports2) {
  29507. "use strict";
  29508. Object.defineProperty(exports2, "__esModule", { value: true });
  29509. exports2.MongoClient = exports2.ServerApiVersion = void 0;
  29510. var util_1 = require("util");
  29511. var bson_1 = require_bson2();
  29512. var change_stream_1 = require_change_stream();
  29513. var mongo_credentials_1 = require_mongo_credentials();
  29514. var providers_1 = require_providers();
  29515. var connection_string_1 = require_connection_string();
  29516. var constants_1 = require_constants2();
  29517. var db_1 = require_db();
  29518. var error_1 = require_error();
  29519. var mongo_logger_1 = require_mongo_logger();
  29520. var mongo_types_1 = require_mongo_types();
  29521. var read_preference_1 = require_read_preference();
  29522. var server_selection_1 = require_server_selection();
  29523. var topology_1 = require_topology();
  29524. var sessions_1 = require_sessions();
  29525. var utils_1 = require_utils();
  29526. exports2.ServerApiVersion = Object.freeze({
  29527. v1: "1"
  29528. });
  29529. var kOptions = Symbol("options");
  29530. var MongoClient2 = class extends mongo_types_1.TypedEventEmitter {
  29531. constructor(url, options) {
  29532. super();
  29533. this[kOptions] = (0, connection_string_1.parseOptions)(url, this, options);
  29534. this.mongoLogger = new mongo_logger_1.MongoLogger(this[kOptions].mongoLoggerOptions);
  29535. const client = this;
  29536. this.s = {
  29537. url,
  29538. bsonOptions: (0, bson_1.resolveBSONOptions)(this[kOptions]),
  29539. namespace: (0, utils_1.ns)("admin"),
  29540. hasBeenClosed: false,
  29541. sessionPool: new sessions_1.ServerSessionPool(this),
  29542. activeSessions: /* @__PURE__ */ new Set(),
  29543. get options() {
  29544. return client[kOptions];
  29545. },
  29546. get readConcern() {
  29547. return client[kOptions].readConcern;
  29548. },
  29549. get writeConcern() {
  29550. return client[kOptions].writeConcern;
  29551. },
  29552. get readPreference() {
  29553. return client[kOptions].readPreference;
  29554. },
  29555. get isMongoClient() {
  29556. return true;
  29557. }
  29558. };
  29559. }
  29560. /** @see MongoOptions */
  29561. get options() {
  29562. return Object.freeze({ ...this[kOptions] });
  29563. }
  29564. get serverApi() {
  29565. return this[kOptions].serverApi && Object.freeze({ ...this[kOptions].serverApi });
  29566. }
  29567. /**
  29568. * Intended for APM use only
  29569. * @internal
  29570. */
  29571. get monitorCommands() {
  29572. return this[kOptions].monitorCommands;
  29573. }
  29574. set monitorCommands(value) {
  29575. this[kOptions].monitorCommands = value;
  29576. }
  29577. /**
  29578. * @deprecated This method will be removed in the next major version.
  29579. */
  29580. get autoEncrypter() {
  29581. return this[kOptions].autoEncrypter;
  29582. }
  29583. get readConcern() {
  29584. return this.s.readConcern;
  29585. }
  29586. get writeConcern() {
  29587. return this.s.writeConcern;
  29588. }
  29589. get readPreference() {
  29590. return this.s.readPreference;
  29591. }
  29592. get bsonOptions() {
  29593. return this.s.bsonOptions;
  29594. }
  29595. /**
  29596. * Connect to MongoDB using a url
  29597. *
  29598. * @see docs.mongodb.org/manual/reference/connection-string/
  29599. */
  29600. async connect() {
  29601. if (this.connectionLock) {
  29602. return this.connectionLock;
  29603. }
  29604. try {
  29605. this.connectionLock = this._connect();
  29606. await this.connectionLock;
  29607. } finally {
  29608. this.connectionLock = void 0;
  29609. }
  29610. return this;
  29611. }
  29612. /**
  29613. * Create a topology to open the connection, must be locked to avoid topology leaks in concurrency scenario.
  29614. * Locking is enforced by the connect method.
  29615. *
  29616. * @internal
  29617. */
  29618. async _connect() {
  29619. var _a, _b, _c, _d, _e;
  29620. if (this.topology && this.topology.isConnected()) {
  29621. return this;
  29622. }
  29623. const options = this[kOptions];
  29624. if (typeof options.srvHost === "string") {
  29625. const hosts = await (0, connection_string_1.resolveSRVRecord)(options);
  29626. for (const [index, host] of hosts.entries()) {
  29627. options.hosts[index] = host;
  29628. }
  29629. }
  29630. if (((_a = options.credentials) == null ? void 0 : _a.mechanism) === providers_1.AuthMechanism.MONGODB_OIDC) {
  29631. const allowedHosts = ((_c = (_b = options.credentials) == null ? void 0 : _b.mechanismProperties) == null ? void 0 : _c.ALLOWED_HOSTS) || mongo_credentials_1.DEFAULT_ALLOWED_HOSTS;
  29632. const isServiceAuth = !!((_e = (_d = options.credentials) == null ? void 0 : _d.mechanismProperties) == null ? void 0 : _e.PROVIDER_NAME);
  29633. if (!isServiceAuth) {
  29634. for (const host of options.hosts) {
  29635. if (!(0, utils_1.hostMatchesWildcards)(host.toHostPort().host, allowedHosts)) {
  29636. throw new error_1.MongoInvalidArgumentError(`Host '${host}' is not valid for OIDC authentication with ALLOWED_HOSTS of '${allowedHosts.join(",")}'`);
  29637. }
  29638. }
  29639. }
  29640. }
  29641. this.topology = new topology_1.Topology(this, options.hosts, options);
  29642. this.topology.once(topology_1.Topology.OPEN, () => this.emit("open", this));
  29643. for (const event of constants_1.MONGO_CLIENT_EVENTS) {
  29644. this.topology.on(event, (...args) => this.emit(event, ...args));
  29645. }
  29646. const topologyConnect = async () => {
  29647. var _a2;
  29648. try {
  29649. await (0, util_1.promisify)((callback) => {
  29650. var _a3;
  29651. return (_a3 = this.topology) == null ? void 0 : _a3.connect(options, callback);
  29652. })();
  29653. } catch (error) {
  29654. (_a2 = this.topology) == null ? void 0 : _a2.close({ force: true });
  29655. throw error;
  29656. }
  29657. };
  29658. if (this.autoEncrypter) {
  29659. const initAutoEncrypter = (0, util_1.promisify)((callback) => {
  29660. var _a2;
  29661. return (_a2 = this.autoEncrypter) == null ? void 0 : _a2.init(callback);
  29662. });
  29663. await initAutoEncrypter();
  29664. await topologyConnect();
  29665. await options.encrypter.connectInternalClient();
  29666. } else {
  29667. await topologyConnect();
  29668. }
  29669. return this;
  29670. }
  29671. /**
  29672. * Close the client and its underlying connections
  29673. *
  29674. * @param force - Force close, emitting no events
  29675. */
  29676. async close(force = false) {
  29677. Object.defineProperty(this.s, "hasBeenClosed", {
  29678. value: true,
  29679. enumerable: true,
  29680. configurable: false,
  29681. writable: false
  29682. });
  29683. const activeSessionEnds = Array.from(this.s.activeSessions, (session) => session.endSession());
  29684. this.s.activeSessions.clear();
  29685. await Promise.all(activeSessionEnds);
  29686. if (this.topology == null) {
  29687. return;
  29688. }
  29689. const selector = (0, server_selection_1.readPreferenceServerSelector)(read_preference_1.ReadPreference.primaryPreferred);
  29690. const topologyDescription = this.topology.description;
  29691. const serverDescriptions = Array.from(topologyDescription.servers.values());
  29692. const servers = selector(topologyDescription, serverDescriptions);
  29693. if (servers.length !== 0) {
  29694. const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
  29695. if (endSessions.length !== 0) {
  29696. await this.db("admin").command({ endSessions }, { readPreference: read_preference_1.ReadPreference.primaryPreferred, noResponse: true }).catch(() => null);
  29697. }
  29698. }
  29699. const topology = this.topology;
  29700. this.topology = void 0;
  29701. await new Promise((resolve, reject) => {
  29702. topology.close({ force }, (error) => {
  29703. if (error)
  29704. return reject(error);
  29705. const { encrypter } = this[kOptions];
  29706. if (encrypter) {
  29707. return encrypter.close(this, force, (error2) => {
  29708. if (error2)
  29709. return reject(error2);
  29710. resolve();
  29711. });
  29712. }
  29713. resolve();
  29714. });
  29715. });
  29716. }
  29717. /**
  29718. * Create a new Db instance sharing the current socket connections.
  29719. *
  29720. * @param dbName - The name of the database we want to use. If not provided, use database name from connection string.
  29721. * @param options - Optional settings for Db construction
  29722. */
  29723. db(dbName, options) {
  29724. options = options ?? {};
  29725. if (!dbName) {
  29726. dbName = this.options.dbName;
  29727. }
  29728. const finalOptions = Object.assign({}, this[kOptions], options);
  29729. const db = new db_1.Db(this, dbName, finalOptions);
  29730. return db;
  29731. }
  29732. /**
  29733. * Connect to MongoDB using a url
  29734. *
  29735. * @remarks
  29736. * The programmatically provided options take precedence over the URI options.
  29737. *
  29738. * @see https://www.mongodb.com/docs/manual/reference/connection-string/
  29739. */
  29740. static async connect(url, options) {
  29741. const client = new this(url, options);
  29742. return client.connect();
  29743. }
  29744. /** Starts a new session on the server */
  29745. startSession(options) {
  29746. const session = new sessions_1.ClientSession(this, this.s.sessionPool, { explicit: true, ...options }, this[kOptions]);
  29747. this.s.activeSessions.add(session);
  29748. session.once("ended", () => {
  29749. this.s.activeSessions.delete(session);
  29750. });
  29751. return session;
  29752. }
  29753. async withSession(optionsOrOperation, callback) {
  29754. const options = {
  29755. // Always define an owner
  29756. owner: Symbol(),
  29757. // If it's an object inherit the options
  29758. ...typeof optionsOrOperation === "object" ? optionsOrOperation : {}
  29759. };
  29760. const withSessionCallback = typeof optionsOrOperation === "function" ? optionsOrOperation : callback;
  29761. if (withSessionCallback == null) {
  29762. throw new error_1.MongoInvalidArgumentError("Missing required callback parameter");
  29763. }
  29764. const session = this.startSession(options);
  29765. try {
  29766. await withSessionCallback(session);
  29767. } finally {
  29768. try {
  29769. await session.endSession();
  29770. } catch {
  29771. }
  29772. }
  29773. }
  29774. /**
  29775. * Create a new Change Stream, watching for new changes (insertions, updates,
  29776. * replacements, deletions, and invalidations) in this cluster. Will ignore all
  29777. * changes to system collections, as well as the local, admin, and config databases.
  29778. *
  29779. * @remarks
  29780. * watch() accepts two generic arguments for distinct use cases:
  29781. * - The first is to provide the schema that may be defined for all the data within the current cluster
  29782. * - The second is to override the shape of the change stream document entirely, if it is not provided the type will default to ChangeStreamDocument of the first argument
  29783. *
  29784. * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
  29785. * @param options - Optional settings for the command
  29786. * @typeParam TSchema - Type of the data being detected by the change stream
  29787. * @typeParam TChange - Type of the whole change stream document emitted
  29788. */
  29789. watch(pipeline = [], options = {}) {
  29790. if (!Array.isArray(pipeline)) {
  29791. options = pipeline;
  29792. pipeline = [];
  29793. }
  29794. return new change_stream_1.ChangeStream(this, pipeline, (0, utils_1.resolveOptions)(this, options));
  29795. }
  29796. };
  29797. exports2.MongoClient = MongoClient2;
  29798. }
  29799. });
  29800. // node_modules/mongodb/lib/change_stream.js
  29801. var require_change_stream = __commonJS({
  29802. "node_modules/mongodb/lib/change_stream.js"(exports2) {
  29803. "use strict";
  29804. Object.defineProperty(exports2, "__esModule", { value: true });
  29805. exports2.ChangeStream = void 0;
  29806. var collection_1 = require_collection();
  29807. var constants_1 = require_constants2();
  29808. var change_stream_cursor_1 = require_change_stream_cursor();
  29809. var db_1 = require_db();
  29810. var error_1 = require_error();
  29811. var mongo_client_1 = require_mongo_client();
  29812. var mongo_types_1 = require_mongo_types();
  29813. var utils_1 = require_utils();
  29814. var kCursorStream = Symbol("cursorStream");
  29815. var kClosed = Symbol("closed");
  29816. var kMode = Symbol("mode");
  29817. var CHANGE_STREAM_OPTIONS = [
  29818. "resumeAfter",
  29819. "startAfter",
  29820. "startAtOperationTime",
  29821. "fullDocument",
  29822. "fullDocumentBeforeChange",
  29823. "showExpandedEvents"
  29824. ];
  29825. var CHANGE_DOMAIN_TYPES = {
  29826. COLLECTION: Symbol("Collection"),
  29827. DATABASE: Symbol("Database"),
  29828. CLUSTER: Symbol("Cluster")
  29829. };
  29830. var CHANGE_STREAM_EVENTS = [constants_1.RESUME_TOKEN_CHANGED, constants_1.END, constants_1.CLOSE];
  29831. var NO_RESUME_TOKEN_ERROR = "A change stream document has been received that lacks a resume token (_id).";
  29832. var CHANGESTREAM_CLOSED_ERROR = "ChangeStream is closed";
  29833. var ChangeStream = class _ChangeStream extends mongo_types_1.TypedEventEmitter {
  29834. /**
  29835. * @internal
  29836. *
  29837. * @param parent - The parent object that created this change stream
  29838. * @param pipeline - An array of {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents
  29839. */
  29840. constructor(parent, pipeline = [], options = {}) {
  29841. super();
  29842. this.pipeline = pipeline;
  29843. this.options = { ...options };
  29844. delete this.options.writeConcern;
  29845. if (parent instanceof collection_1.Collection) {
  29846. this.type = CHANGE_DOMAIN_TYPES.COLLECTION;
  29847. } else if (parent instanceof db_1.Db) {
  29848. this.type = CHANGE_DOMAIN_TYPES.DATABASE;
  29849. } else if (parent instanceof mongo_client_1.MongoClient) {
  29850. this.type = CHANGE_DOMAIN_TYPES.CLUSTER;
  29851. } else {
  29852. throw new error_1.MongoChangeStreamError("Parent provided to ChangeStream constructor must be an instance of Collection, Db, or MongoClient");
  29853. }
  29854. this.parent = parent;
  29855. this.namespace = parent.s.namespace;
  29856. if (!this.options.readPreference && parent.readPreference) {
  29857. this.options.readPreference = parent.readPreference;
  29858. }
  29859. this.cursor = this._createChangeStreamCursor(options);
  29860. this[kClosed] = false;
  29861. this[kMode] = false;
  29862. this.on("newListener", (eventName) => {
  29863. if (eventName === "change" && this.cursor && this.listenerCount("change") === 0) {
  29864. this._streamEvents(this.cursor);
  29865. }
  29866. });
  29867. this.on("removeListener", (eventName) => {
  29868. var _a;
  29869. if (eventName === "change" && this.listenerCount("change") === 0 && this.cursor) {
  29870. (_a = this[kCursorStream]) == null ? void 0 : _a.removeAllListeners("data");
  29871. }
  29872. });
  29873. }
  29874. /** @internal */
  29875. get cursorStream() {
  29876. return this[kCursorStream];
  29877. }
  29878. /** The cached resume token that is used to resume after the most recently returned change. */
  29879. get resumeToken() {
  29880. var _a;
  29881. return (_a = this.cursor) == null ? void 0 : _a.resumeToken;
  29882. }
  29883. /** Check if there is any document still available in the Change Stream */
  29884. async hasNext() {
  29885. this._setIsIterator();
  29886. while (true) {
  29887. try {
  29888. const hasNext = await this.cursor.hasNext();
  29889. return hasNext;
  29890. } catch (error) {
  29891. try {
  29892. await this._processErrorIteratorMode(error);
  29893. } catch (error2) {
  29894. try {
  29895. await this.close();
  29896. } catch {
  29897. }
  29898. throw error2;
  29899. }
  29900. }
  29901. }
  29902. }
  29903. /** Get the next available document from the Change Stream. */
  29904. async next() {
  29905. this._setIsIterator();
  29906. while (true) {
  29907. try {
  29908. const change = await this.cursor.next();
  29909. const processedChange = this._processChange(change ?? null);
  29910. return processedChange;
  29911. } catch (error) {
  29912. try {
  29913. await this._processErrorIteratorMode(error);
  29914. } catch (error2) {
  29915. try {
  29916. await this.close();
  29917. } catch {
  29918. }
  29919. throw error2;
  29920. }
  29921. }
  29922. }
  29923. }
  29924. /**
  29925. * Try to get the next available document from the Change Stream's cursor or `null` if an empty batch is returned
  29926. */
  29927. async tryNext() {
  29928. this._setIsIterator();
  29929. while (true) {
  29930. try {
  29931. const change = await this.cursor.tryNext();
  29932. return change ?? null;
  29933. } catch (error) {
  29934. try {
  29935. await this._processErrorIteratorMode(error);
  29936. } catch (error2) {
  29937. try {
  29938. await this.close();
  29939. } catch {
  29940. }
  29941. throw error2;
  29942. }
  29943. }
  29944. }
  29945. }
  29946. async *[Symbol.asyncIterator]() {
  29947. if (this.closed) {
  29948. return;
  29949. }
  29950. try {
  29951. while (true) {
  29952. yield await this.next();
  29953. }
  29954. } finally {
  29955. try {
  29956. await this.close();
  29957. } catch {
  29958. }
  29959. }
  29960. }
  29961. /** Is the cursor closed */
  29962. get closed() {
  29963. return this[kClosed] || this.cursor.closed;
  29964. }
  29965. /** Close the Change Stream */
  29966. async close() {
  29967. this[kClosed] = true;
  29968. const cursor = this.cursor;
  29969. try {
  29970. await cursor.close();
  29971. } finally {
  29972. this._endStream();
  29973. }
  29974. }
  29975. /**
  29976. * Return a modified Readable stream including a possible transform method.
  29977. *
  29978. * NOTE: When using a Stream to process change stream events, the stream will
  29979. * NOT automatically resume in the case a resumable error is encountered.
  29980. *
  29981. * @throws MongoChangeStreamError if the underlying cursor or the change stream is closed
  29982. */
  29983. stream(options) {
  29984. if (this.closed) {
  29985. throw new error_1.MongoChangeStreamError(CHANGESTREAM_CLOSED_ERROR);
  29986. }
  29987. this.streamOptions = options;
  29988. return this.cursor.stream(options);
  29989. }
  29990. /** @internal */
  29991. _setIsEmitter() {
  29992. if (this[kMode] === "iterator") {
  29993. throw new error_1.MongoAPIError("ChangeStream cannot be used as an EventEmitter after being used as an iterator");
  29994. }
  29995. this[kMode] = "emitter";
  29996. }
  29997. /** @internal */
  29998. _setIsIterator() {
  29999. if (this[kMode] === "emitter") {
  30000. throw new error_1.MongoAPIError("ChangeStream cannot be used as an iterator after being used as an EventEmitter");
  30001. }
  30002. this[kMode] = "iterator";
  30003. }
  30004. /**
  30005. * Create a new change stream cursor based on self's configuration
  30006. * @internal
  30007. */
  30008. _createChangeStreamCursor(options) {
  30009. const changeStreamStageOptions = (0, utils_1.filterOptions)(options, CHANGE_STREAM_OPTIONS);
  30010. if (this.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
  30011. changeStreamStageOptions.allChangesForCluster = true;
  30012. }
  30013. const pipeline = [{ $changeStream: changeStreamStageOptions }, ...this.pipeline];
  30014. const client = this.type === CHANGE_DOMAIN_TYPES.CLUSTER ? this.parent : this.type === CHANGE_DOMAIN_TYPES.DATABASE ? this.parent.client : this.type === CHANGE_DOMAIN_TYPES.COLLECTION ? this.parent.client : null;
  30015. if (client == null) {
  30016. throw new error_1.MongoRuntimeError(`Changestream type should only be one of cluster, database, collection. Found ${this.type.toString()}`);
  30017. }
  30018. const changeStreamCursor = new change_stream_cursor_1.ChangeStreamCursor(client, this.namespace, pipeline, options);
  30019. for (const event of CHANGE_STREAM_EVENTS) {
  30020. changeStreamCursor.on(event, (e) => this.emit(event, e));
  30021. }
  30022. if (this.listenerCount(_ChangeStream.CHANGE) > 0) {
  30023. this._streamEvents(changeStreamCursor);
  30024. }
  30025. return changeStreamCursor;
  30026. }
  30027. /** @internal */
  30028. _closeEmitterModeWithError(error) {
  30029. this.emit(_ChangeStream.ERROR, error);
  30030. this.close().catch(() => null);
  30031. }
  30032. /** @internal */
  30033. _streamEvents(cursor) {
  30034. this._setIsEmitter();
  30035. const stream = this[kCursorStream] ?? cursor.stream();
  30036. this[kCursorStream] = stream;
  30037. stream.on("data", (change) => {
  30038. try {
  30039. const processedChange = this._processChange(change);
  30040. this.emit(_ChangeStream.CHANGE, processedChange);
  30041. } catch (error) {
  30042. this.emit(_ChangeStream.ERROR, error);
  30043. }
  30044. });
  30045. stream.on("error", (error) => this._processErrorStreamMode(error));
  30046. }
  30047. /** @internal */
  30048. _endStream() {
  30049. const cursorStream = this[kCursorStream];
  30050. if (cursorStream) {
  30051. ["data", "close", "end", "error"].forEach((event) => cursorStream.removeAllListeners(event));
  30052. cursorStream.destroy();
  30053. }
  30054. this[kCursorStream] = void 0;
  30055. }
  30056. /** @internal */
  30057. _processChange(change) {
  30058. if (this[kClosed]) {
  30059. throw new error_1.MongoAPIError(CHANGESTREAM_CLOSED_ERROR);
  30060. }
  30061. if (change == null) {
  30062. throw new error_1.MongoRuntimeError(CHANGESTREAM_CLOSED_ERROR);
  30063. }
  30064. if (change && !change._id) {
  30065. throw new error_1.MongoChangeStreamError(NO_RESUME_TOKEN_ERROR);
  30066. }
  30067. this.cursor.cacheResumeToken(change._id);
  30068. this.options.startAtOperationTime = void 0;
  30069. return change;
  30070. }
  30071. /** @internal */
  30072. _processErrorStreamMode(changeStreamError) {
  30073. if (this[kClosed])
  30074. return;
  30075. if ((0, error_1.isResumableError)(changeStreamError, this.cursor.maxWireVersion)) {
  30076. this._endStream();
  30077. this.cursor.close().catch(() => null);
  30078. const topology = (0, utils_1.getTopology)(this.parent);
  30079. topology.selectServer(this.cursor.readPreference, {}, (serverSelectionError) => {
  30080. if (serverSelectionError)
  30081. return this._closeEmitterModeWithError(changeStreamError);
  30082. this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
  30083. });
  30084. } else {
  30085. this._closeEmitterModeWithError(changeStreamError);
  30086. }
  30087. }
  30088. /** @internal */
  30089. async _processErrorIteratorMode(changeStreamError) {
  30090. if (this[kClosed]) {
  30091. throw new error_1.MongoAPIError(CHANGESTREAM_CLOSED_ERROR);
  30092. }
  30093. if (!(0, error_1.isResumableError)(changeStreamError, this.cursor.maxWireVersion)) {
  30094. try {
  30095. await this.close();
  30096. } catch {
  30097. }
  30098. throw changeStreamError;
  30099. }
  30100. await this.cursor.close().catch(() => null);
  30101. const topology = (0, utils_1.getTopology)(this.parent);
  30102. try {
  30103. await topology.selectServerAsync(this.cursor.readPreference, {});
  30104. this.cursor = this._createChangeStreamCursor(this.cursor.resumeOptions);
  30105. } catch {
  30106. await this.close();
  30107. throw changeStreamError;
  30108. }
  30109. }
  30110. };
  30111. ChangeStream.RESPONSE = constants_1.RESPONSE;
  30112. ChangeStream.MORE = constants_1.MORE;
  30113. ChangeStream.INIT = constants_1.INIT;
  30114. ChangeStream.CLOSE = constants_1.CLOSE;
  30115. ChangeStream.CHANGE = constants_1.CHANGE;
  30116. ChangeStream.END = constants_1.END;
  30117. ChangeStream.ERROR = constants_1.ERROR;
  30118. ChangeStream.RESUME_TOKEN_CHANGED = constants_1.RESUME_TOKEN_CHANGED;
  30119. exports2.ChangeStream = ChangeStream;
  30120. }
  30121. });
  30122. // node_modules/mongodb/lib/gridfs/download.js
  30123. var require_download = __commonJS({
  30124. "node_modules/mongodb/lib/gridfs/download.js"(exports2) {
  30125. "use strict";
  30126. Object.defineProperty(exports2, "__esModule", { value: true });
  30127. exports2.GridFSBucketReadStream = void 0;
  30128. var stream_1 = require("stream");
  30129. var error_1 = require_error();
  30130. var GridFSBucketReadStream = class _GridFSBucketReadStream extends stream_1.Readable {
  30131. /**
  30132. * @param chunks - Handle for chunks collection
  30133. * @param files - Handle for files collection
  30134. * @param readPreference - The read preference to use
  30135. * @param filter - The filter to use to find the file document
  30136. * @internal
  30137. */
  30138. constructor(chunks, files, readPreference, filter, options) {
  30139. super();
  30140. this.s = {
  30141. bytesToTrim: 0,
  30142. bytesToSkip: 0,
  30143. bytesRead: 0,
  30144. chunks,
  30145. expected: 0,
  30146. files,
  30147. filter,
  30148. init: false,
  30149. expectedEnd: 0,
  30150. options: {
  30151. start: 0,
  30152. end: 0,
  30153. ...options
  30154. },
  30155. readPreference
  30156. };
  30157. }
  30158. /**
  30159. * Reads from the cursor and pushes to the stream.
  30160. * Private Impl, do not call directly
  30161. * @internal
  30162. */
  30163. _read() {
  30164. if (this.destroyed)
  30165. return;
  30166. waitForFile(this, () => doRead(this));
  30167. }
  30168. /**
  30169. * Sets the 0-based offset in bytes to start streaming from. Throws
  30170. * an error if this stream has entered flowing mode
  30171. * (e.g. if you've already called `on('data')`)
  30172. *
  30173. * @param start - 0-based offset in bytes to start streaming from
  30174. */
  30175. start(start = 0) {
  30176. throwIfInitialized(this);
  30177. this.s.options.start = start;
  30178. return this;
  30179. }
  30180. /**
  30181. * Sets the 0-based offset in bytes to start streaming from. Throws
  30182. * an error if this stream has entered flowing mode
  30183. * (e.g. if you've already called `on('data')`)
  30184. *
  30185. * @param end - Offset in bytes to stop reading at
  30186. */
  30187. end(end = 0) {
  30188. throwIfInitialized(this);
  30189. this.s.options.end = end;
  30190. return this;
  30191. }
  30192. /**
  30193. * Marks this stream as aborted (will never push another `data` event)
  30194. * and kills the underlying cursor. Will emit the 'end' event, and then
  30195. * the 'close' event once the cursor is successfully killed.
  30196. */
  30197. async abort() {
  30198. this.push(null);
  30199. this.destroyed = true;
  30200. if (this.s.cursor) {
  30201. try {
  30202. await this.s.cursor.close();
  30203. } finally {
  30204. this.emit(_GridFSBucketReadStream.CLOSE);
  30205. }
  30206. } else {
  30207. if (!this.s.init) {
  30208. this.emit(_GridFSBucketReadStream.CLOSE);
  30209. }
  30210. }
  30211. }
  30212. };
  30213. GridFSBucketReadStream.ERROR = "error";
  30214. GridFSBucketReadStream.FILE = "file";
  30215. GridFSBucketReadStream.DATA = "data";
  30216. GridFSBucketReadStream.END = "end";
  30217. GridFSBucketReadStream.CLOSE = "close";
  30218. exports2.GridFSBucketReadStream = GridFSBucketReadStream;
  30219. function throwIfInitialized(stream) {
  30220. if (stream.s.init) {
  30221. throw new error_1.MongoGridFSStreamError("Options cannot be changed after the stream is initialized");
  30222. }
  30223. }
  30224. function doRead(stream) {
  30225. if (stream.destroyed)
  30226. return;
  30227. if (!stream.s.cursor)
  30228. return;
  30229. if (!stream.s.file)
  30230. return;
  30231. const handleReadResult = ({ error, doc }) => {
  30232. var _a;
  30233. if (stream.destroyed) {
  30234. return;
  30235. }
  30236. if (error) {
  30237. stream.emit(GridFSBucketReadStream.ERROR, error);
  30238. return;
  30239. }
  30240. if (!doc) {
  30241. stream.push(null);
  30242. (_a = stream.s.cursor) == null ? void 0 : _a.close().then(() => {
  30243. stream.emit(GridFSBucketReadStream.CLOSE);
  30244. }, (error2) => {
  30245. stream.emit(GridFSBucketReadStream.ERROR, error2);
  30246. });
  30247. return;
  30248. }
  30249. if (!stream.s.file)
  30250. return;
  30251. const bytesRemaining = stream.s.file.length - stream.s.bytesRead;
  30252. const expectedN = stream.s.expected++;
  30253. const expectedLength = Math.min(stream.s.file.chunkSize, bytesRemaining);
  30254. if (doc.n > expectedN) {
  30255. return stream.emit(GridFSBucketReadStream.ERROR, new error_1.MongoGridFSChunkError(`ChunkIsMissing: Got unexpected n: ${doc.n}, expected: ${expectedN}`));
  30256. }
  30257. if (doc.n < expectedN) {
  30258. return stream.emit(GridFSBucketReadStream.ERROR, new error_1.MongoGridFSChunkError(`ExtraChunk: Got unexpected n: ${doc.n}, expected: ${expectedN}`));
  30259. }
  30260. let buf = Buffer.isBuffer(doc.data) ? doc.data : doc.data.buffer;
  30261. if (buf.byteLength !== expectedLength) {
  30262. if (bytesRemaining <= 0) {
  30263. return stream.emit(GridFSBucketReadStream.ERROR, new error_1.MongoGridFSChunkError(`ExtraChunk: Got unexpected n: ${doc.n}, expected file length ${stream.s.file.length} bytes but already read ${stream.s.bytesRead} bytes`));
  30264. }
  30265. return stream.emit(GridFSBucketReadStream.ERROR, new error_1.MongoGridFSChunkError(`ChunkIsWrongSize: Got unexpected length: ${buf.byteLength}, expected: ${expectedLength}`));
  30266. }
  30267. stream.s.bytesRead += buf.byteLength;
  30268. if (buf.byteLength === 0) {
  30269. return stream.push(null);
  30270. }
  30271. let sliceStart = null;
  30272. let sliceEnd = null;
  30273. if (stream.s.bytesToSkip != null) {
  30274. sliceStart = stream.s.bytesToSkip;
  30275. stream.s.bytesToSkip = 0;
  30276. }
  30277. const atEndOfStream = expectedN === stream.s.expectedEnd - 1;
  30278. const bytesLeftToRead = stream.s.options.end - stream.s.bytesToSkip;
  30279. if (atEndOfStream && stream.s.bytesToTrim != null) {
  30280. sliceEnd = stream.s.file.chunkSize - stream.s.bytesToTrim;
  30281. } else if (stream.s.options.end && bytesLeftToRead < doc.data.byteLength) {
  30282. sliceEnd = bytesLeftToRead;
  30283. }
  30284. if (sliceStart != null || sliceEnd != null) {
  30285. buf = buf.slice(sliceStart || 0, sliceEnd || buf.byteLength);
  30286. }
  30287. stream.push(buf);
  30288. return;
  30289. };
  30290. stream.s.cursor.next().then((doc) => handleReadResult({ error: null, doc }), (error) => handleReadResult({ error, doc: null }));
  30291. }
  30292. function init(stream) {
  30293. const findOneOptions = {};
  30294. if (stream.s.readPreference) {
  30295. findOneOptions.readPreference = stream.s.readPreference;
  30296. }
  30297. if (stream.s.options && stream.s.options.sort) {
  30298. findOneOptions.sort = stream.s.options.sort;
  30299. }
  30300. if (stream.s.options && stream.s.options.skip) {
  30301. findOneOptions.skip = stream.s.options.skip;
  30302. }
  30303. const handleReadResult = ({ error, doc }) => {
  30304. if (error) {
  30305. return stream.emit(GridFSBucketReadStream.ERROR, error);
  30306. }
  30307. if (!doc) {
  30308. const identifier = stream.s.filter._id ? stream.s.filter._id.toString() : stream.s.filter.filename;
  30309. const errmsg = `FileNotFound: file ${identifier} was not found`;
  30310. const err = new error_1.MongoRuntimeError(errmsg);
  30311. err.code = "ENOENT";
  30312. return stream.emit(GridFSBucketReadStream.ERROR, err);
  30313. }
  30314. if (doc.length <= 0) {
  30315. stream.push(null);
  30316. return;
  30317. }
  30318. if (stream.destroyed) {
  30319. stream.emit(GridFSBucketReadStream.CLOSE);
  30320. return;
  30321. }
  30322. try {
  30323. stream.s.bytesToSkip = handleStartOption(stream, doc, stream.s.options);
  30324. } catch (error2) {
  30325. return stream.emit(GridFSBucketReadStream.ERROR, error2);
  30326. }
  30327. const filter = { files_id: doc._id };
  30328. if (stream.s.options && stream.s.options.start != null) {
  30329. const skip = Math.floor(stream.s.options.start / doc.chunkSize);
  30330. if (skip > 0) {
  30331. filter["n"] = { $gte: skip };
  30332. }
  30333. }
  30334. stream.s.cursor = stream.s.chunks.find(filter).sort({ n: 1 });
  30335. if (stream.s.readPreference) {
  30336. stream.s.cursor.withReadPreference(stream.s.readPreference);
  30337. }
  30338. stream.s.expectedEnd = Math.ceil(doc.length / doc.chunkSize);
  30339. stream.s.file = doc;
  30340. try {
  30341. stream.s.bytesToTrim = handleEndOption(stream, doc, stream.s.cursor, stream.s.options);
  30342. } catch (error2) {
  30343. return stream.emit(GridFSBucketReadStream.ERROR, error2);
  30344. }
  30345. stream.emit(GridFSBucketReadStream.FILE, doc);
  30346. return;
  30347. };
  30348. stream.s.files.findOne(stream.s.filter, findOneOptions).then((doc) => handleReadResult({ error: null, doc }), (error) => handleReadResult({ error, doc: null }));
  30349. }
  30350. function waitForFile(stream, callback) {
  30351. if (stream.s.file) {
  30352. return callback();
  30353. }
  30354. if (!stream.s.init) {
  30355. init(stream);
  30356. stream.s.init = true;
  30357. }
  30358. stream.once("file", () => {
  30359. callback();
  30360. });
  30361. }
  30362. function handleStartOption(stream, doc, options) {
  30363. if (options && options.start != null) {
  30364. if (options.start > doc.length) {
  30365. throw new error_1.MongoInvalidArgumentError(`Stream start (${options.start}) must not be more than the length of the file (${doc.length})`);
  30366. }
  30367. if (options.start < 0) {
  30368. throw new error_1.MongoInvalidArgumentError(`Stream start (${options.start}) must not be negative`);
  30369. }
  30370. if (options.end != null && options.end < options.start) {
  30371. throw new error_1.MongoInvalidArgumentError(`Stream start (${options.start}) must not be greater than stream end (${options.end})`);
  30372. }
  30373. stream.s.bytesRead = Math.floor(options.start / doc.chunkSize) * doc.chunkSize;
  30374. stream.s.expected = Math.floor(options.start / doc.chunkSize);
  30375. return options.start - stream.s.bytesRead;
  30376. }
  30377. throw new error_1.MongoInvalidArgumentError("Start option must be defined");
  30378. }
  30379. function handleEndOption(stream, doc, cursor, options) {
  30380. if (options && options.end != null) {
  30381. if (options.end > doc.length) {
  30382. throw new error_1.MongoInvalidArgumentError(`Stream end (${options.end}) must not be more than the length of the file (${doc.length})`);
  30383. }
  30384. if (options.start == null || options.start < 0) {
  30385. throw new error_1.MongoInvalidArgumentError(`Stream end (${options.end}) must not be negative`);
  30386. }
  30387. const start = options.start != null ? Math.floor(options.start / doc.chunkSize) : 0;
  30388. cursor.limit(Math.ceil(options.end / doc.chunkSize) - start);
  30389. stream.s.expectedEnd = Math.ceil(options.end / doc.chunkSize);
  30390. return Math.ceil(options.end / doc.chunkSize) * doc.chunkSize - options.end;
  30391. }
  30392. throw new error_1.MongoInvalidArgumentError("End option must be defined");
  30393. }
  30394. }
  30395. });
  30396. // node_modules/mongodb/lib/gridfs/upload.js
  30397. var require_upload = __commonJS({
  30398. "node_modules/mongodb/lib/gridfs/upload.js"(exports2) {
  30399. "use strict";
  30400. Object.defineProperty(exports2, "__esModule", { value: true });
  30401. exports2.GridFSBucketWriteStream = void 0;
  30402. var stream_1 = require("stream");
  30403. var bson_1 = require_bson2();
  30404. var error_1 = require_error();
  30405. var write_concern_1 = require_write_concern();
  30406. var GridFSBucketWriteStream = class _GridFSBucketWriteStream extends stream_1.Writable {
  30407. /**
  30408. * @param bucket - Handle for this stream's corresponding bucket
  30409. * @param filename - The value of the 'filename' key in the files doc
  30410. * @param options - Optional settings.
  30411. * @internal
  30412. */
  30413. constructor(bucket, filename, options) {
  30414. super();
  30415. options = options ?? {};
  30416. this.bucket = bucket;
  30417. this.chunks = bucket.s._chunksCollection;
  30418. this.filename = filename;
  30419. this.files = bucket.s._filesCollection;
  30420. this.options = options;
  30421. this.writeConcern = write_concern_1.WriteConcern.fromOptions(options) || bucket.s.options.writeConcern;
  30422. this.done = false;
  30423. this.id = options.id ? options.id : new bson_1.ObjectId();
  30424. this.chunkSizeBytes = options.chunkSizeBytes || this.bucket.s.options.chunkSizeBytes;
  30425. this.bufToStore = Buffer.alloc(this.chunkSizeBytes);
  30426. this.length = 0;
  30427. this.n = 0;
  30428. this.pos = 0;
  30429. this.state = {
  30430. streamEnd: false,
  30431. outstandingRequests: 0,
  30432. errored: false,
  30433. aborted: false
  30434. };
  30435. if (!this.bucket.s.calledOpenUploadStream) {
  30436. this.bucket.s.calledOpenUploadStream = true;
  30437. checkIndexes(this).then(() => {
  30438. this.bucket.s.checkedIndexes = true;
  30439. this.bucket.emit("index");
  30440. }, () => null);
  30441. }
  30442. }
  30443. write(chunk, encodingOrCallback, callback) {
  30444. const encoding = typeof encodingOrCallback === "function" ? void 0 : encodingOrCallback;
  30445. callback = typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
  30446. return waitForIndexes(this, () => doWrite(this, chunk, encoding, callback));
  30447. }
  30448. /**
  30449. * Places this write stream into an aborted state (all future writes fail)
  30450. * and deletes all chunks that have already been written.
  30451. */
  30452. async abort() {
  30453. if (this.state.streamEnd) {
  30454. throw new error_1.MongoAPIError("Cannot abort a stream that has already completed");
  30455. }
  30456. if (this.state.aborted) {
  30457. throw new error_1.MongoAPIError("Cannot call abort() on a stream twice");
  30458. }
  30459. this.state.aborted = true;
  30460. await this.chunks.deleteMany({ files_id: this.id });
  30461. }
  30462. end(chunkOrCallback, encodingOrCallback, callback) {
  30463. const chunk = typeof chunkOrCallback === "function" ? void 0 : chunkOrCallback;
  30464. const encoding = typeof encodingOrCallback === "function" ? void 0 : encodingOrCallback;
  30465. callback = typeof chunkOrCallback === "function" ? chunkOrCallback : typeof encodingOrCallback === "function" ? encodingOrCallback : callback;
  30466. if (this.state.streamEnd || checkAborted(this, callback))
  30467. return this;
  30468. this.state.streamEnd = true;
  30469. if (callback) {
  30470. this.once(_GridFSBucketWriteStream.FINISH, (result) => {
  30471. if (callback)
  30472. callback(void 0, result);
  30473. });
  30474. }
  30475. if (!chunk) {
  30476. waitForIndexes(this, () => !!writeRemnant(this));
  30477. return this;
  30478. }
  30479. this.write(chunk, encoding, () => {
  30480. writeRemnant(this);
  30481. });
  30482. return this;
  30483. }
  30484. };
  30485. GridFSBucketWriteStream.CLOSE = "close";
  30486. GridFSBucketWriteStream.ERROR = "error";
  30487. GridFSBucketWriteStream.FINISH = "finish";
  30488. exports2.GridFSBucketWriteStream = GridFSBucketWriteStream;
  30489. function __handleError(stream, error, callback) {
  30490. if (stream.state.errored) {
  30491. return;
  30492. }
  30493. stream.state.errored = true;
  30494. if (callback) {
  30495. return callback(error);
  30496. }
  30497. stream.emit(GridFSBucketWriteStream.ERROR, error);
  30498. }
  30499. function createChunkDoc(filesId, n, data) {
  30500. return {
  30501. _id: new bson_1.ObjectId(),
  30502. files_id: filesId,
  30503. n,
  30504. data
  30505. };
  30506. }
  30507. async function checkChunksIndex(stream) {
  30508. const index = { files_id: 1, n: 1 };
  30509. let indexes;
  30510. try {
  30511. indexes = await stream.chunks.listIndexes().toArray();
  30512. } catch (error) {
  30513. if (error instanceof error_1.MongoError && error.code === error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
  30514. indexes = [];
  30515. } else {
  30516. throw error;
  30517. }
  30518. }
  30519. const hasChunksIndex = !!indexes.find((index2) => {
  30520. const keys = Object.keys(index2.key);
  30521. if (keys.length === 2 && index2.key.files_id === 1 && index2.key.n === 1) {
  30522. return true;
  30523. }
  30524. return false;
  30525. });
  30526. if (!hasChunksIndex) {
  30527. await stream.chunks.createIndex(index, {
  30528. ...stream.writeConcern,
  30529. background: true,
  30530. unique: true
  30531. });
  30532. }
  30533. }
  30534. function checkDone(stream, callback) {
  30535. if (stream.done)
  30536. return true;
  30537. if (stream.state.streamEnd && stream.state.outstandingRequests === 0 && !stream.state.errored) {
  30538. stream.done = true;
  30539. const filesDoc = createFilesDoc(stream.id, stream.length, stream.chunkSizeBytes, stream.filename, stream.options.contentType, stream.options.aliases, stream.options.metadata);
  30540. if (checkAborted(stream, callback)) {
  30541. return false;
  30542. }
  30543. stream.files.insertOne(filesDoc, { writeConcern: stream.writeConcern }).then(() => {
  30544. stream.emit(GridFSBucketWriteStream.FINISH, filesDoc);
  30545. stream.emit(GridFSBucketWriteStream.CLOSE);
  30546. }, (error) => {
  30547. return __handleError(stream, error, callback);
  30548. });
  30549. return true;
  30550. }
  30551. return false;
  30552. }
  30553. async function checkIndexes(stream) {
  30554. const doc = await stream.files.findOne({}, { projection: { _id: 1 } });
  30555. if (doc != null) {
  30556. return;
  30557. }
  30558. const index = { filename: 1, uploadDate: 1 };
  30559. let indexes;
  30560. try {
  30561. indexes = await stream.files.listIndexes().toArray();
  30562. } catch (error) {
  30563. if (error instanceof error_1.MongoError && error.code === error_1.MONGODB_ERROR_CODES.NamespaceNotFound) {
  30564. indexes = [];
  30565. } else {
  30566. throw error;
  30567. }
  30568. }
  30569. const hasFileIndex = !!indexes.find((index2) => {
  30570. const keys = Object.keys(index2.key);
  30571. if (keys.length === 2 && index2.key.filename === 1 && index2.key.uploadDate === 1) {
  30572. return true;
  30573. }
  30574. return false;
  30575. });
  30576. if (!hasFileIndex) {
  30577. await stream.files.createIndex(index, { background: false });
  30578. }
  30579. await checkChunksIndex(stream);
  30580. }
  30581. function createFilesDoc(_id, length, chunkSize, filename, contentType, aliases, metadata) {
  30582. const ret = {
  30583. _id,
  30584. length,
  30585. chunkSize,
  30586. uploadDate: /* @__PURE__ */ new Date(),
  30587. filename
  30588. };
  30589. if (contentType) {
  30590. ret.contentType = contentType;
  30591. }
  30592. if (aliases) {
  30593. ret.aliases = aliases;
  30594. }
  30595. if (metadata) {
  30596. ret.metadata = metadata;
  30597. }
  30598. return ret;
  30599. }
  30600. function doWrite(stream, chunk, encoding, callback) {
  30601. if (checkAborted(stream, callback)) {
  30602. return false;
  30603. }
  30604. const inputBuf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding);
  30605. stream.length += inputBuf.length;
  30606. if (stream.pos + inputBuf.length < stream.chunkSizeBytes) {
  30607. inputBuf.copy(stream.bufToStore, stream.pos);
  30608. stream.pos += inputBuf.length;
  30609. callback && callback();
  30610. return true;
  30611. }
  30612. let inputBufRemaining = inputBuf.length;
  30613. let spaceRemaining = stream.chunkSizeBytes - stream.pos;
  30614. let numToCopy = Math.min(spaceRemaining, inputBuf.length);
  30615. let outstandingRequests = 0;
  30616. while (inputBufRemaining > 0) {
  30617. const inputBufPos = inputBuf.length - inputBufRemaining;
  30618. inputBuf.copy(stream.bufToStore, stream.pos, inputBufPos, inputBufPos + numToCopy);
  30619. stream.pos += numToCopy;
  30620. spaceRemaining -= numToCopy;
  30621. let doc;
  30622. if (spaceRemaining === 0) {
  30623. doc = createChunkDoc(stream.id, stream.n, Buffer.from(stream.bufToStore));
  30624. ++stream.state.outstandingRequests;
  30625. ++outstandingRequests;
  30626. if (checkAborted(stream, callback)) {
  30627. return false;
  30628. }
  30629. stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(() => {
  30630. --stream.state.outstandingRequests;
  30631. --outstandingRequests;
  30632. if (!outstandingRequests) {
  30633. stream.emit("drain", doc);
  30634. callback && callback();
  30635. checkDone(stream);
  30636. }
  30637. }, (error) => {
  30638. return __handleError(stream, error);
  30639. });
  30640. spaceRemaining = stream.chunkSizeBytes;
  30641. stream.pos = 0;
  30642. ++stream.n;
  30643. }
  30644. inputBufRemaining -= numToCopy;
  30645. numToCopy = Math.min(spaceRemaining, inputBufRemaining);
  30646. }
  30647. return false;
  30648. }
  30649. function waitForIndexes(stream, callback) {
  30650. if (stream.bucket.s.checkedIndexes) {
  30651. return callback(false);
  30652. }
  30653. stream.bucket.once("index", () => {
  30654. callback(true);
  30655. });
  30656. return true;
  30657. }
  30658. function writeRemnant(stream, callback) {
  30659. if (stream.pos === 0) {
  30660. return checkDone(stream, callback);
  30661. }
  30662. ++stream.state.outstandingRequests;
  30663. const remnant = Buffer.alloc(stream.pos);
  30664. stream.bufToStore.copy(remnant, 0, 0, stream.pos);
  30665. const doc = createChunkDoc(stream.id, stream.n, remnant);
  30666. if (checkAborted(stream, callback)) {
  30667. return false;
  30668. }
  30669. stream.chunks.insertOne(doc, { writeConcern: stream.writeConcern }).then(() => {
  30670. --stream.state.outstandingRequests;
  30671. checkDone(stream);
  30672. }, (error) => {
  30673. return __handleError(stream, error);
  30674. });
  30675. return true;
  30676. }
  30677. function checkAborted(stream, callback) {
  30678. if (stream.state.aborted) {
  30679. if (typeof callback === "function") {
  30680. callback(new error_1.MongoAPIError("Stream has been aborted"));
  30681. }
  30682. return true;
  30683. }
  30684. return false;
  30685. }
  30686. }
  30687. });
  30688. // node_modules/mongodb/lib/gridfs/index.js
  30689. var require_gridfs = __commonJS({
  30690. "node_modules/mongodb/lib/gridfs/index.js"(exports2) {
  30691. "use strict";
  30692. Object.defineProperty(exports2, "__esModule", { value: true });
  30693. exports2.GridFSBucket = void 0;
  30694. var error_1 = require_error();
  30695. var mongo_types_1 = require_mongo_types();
  30696. var write_concern_1 = require_write_concern();
  30697. var download_1 = require_download();
  30698. var upload_1 = require_upload();
  30699. var DEFAULT_GRIDFS_BUCKET_OPTIONS = {
  30700. bucketName: "fs",
  30701. chunkSizeBytes: 255 * 1024
  30702. };
  30703. var GridFSBucket = class extends mongo_types_1.TypedEventEmitter {
  30704. constructor(db, options) {
  30705. super();
  30706. this.setMaxListeners(0);
  30707. const privateOptions = {
  30708. ...DEFAULT_GRIDFS_BUCKET_OPTIONS,
  30709. ...options,
  30710. writeConcern: write_concern_1.WriteConcern.fromOptions(options)
  30711. };
  30712. this.s = {
  30713. db,
  30714. options: privateOptions,
  30715. _chunksCollection: db.collection(privateOptions.bucketName + ".chunks"),
  30716. _filesCollection: db.collection(privateOptions.bucketName + ".files"),
  30717. checkedIndexes: false,
  30718. calledOpenUploadStream: false
  30719. };
  30720. }
  30721. /**
  30722. * Returns a writable stream (GridFSBucketWriteStream) for writing
  30723. * buffers to GridFS. The stream's 'id' property contains the resulting
  30724. * file's id.
  30725. *
  30726. * @param filename - The value of the 'filename' key in the files doc
  30727. * @param options - Optional settings.
  30728. */
  30729. openUploadStream(filename, options) {
  30730. return new upload_1.GridFSBucketWriteStream(this, filename, options);
  30731. }
  30732. /**
  30733. * Returns a writable stream (GridFSBucketWriteStream) for writing
  30734. * buffers to GridFS for a custom file id. The stream's 'id' property contains the resulting
  30735. * file's id.
  30736. */
  30737. openUploadStreamWithId(id, filename, options) {
  30738. return new upload_1.GridFSBucketWriteStream(this, filename, { ...options, id });
  30739. }
  30740. /** Returns a readable stream (GridFSBucketReadStream) for streaming file data from GridFS. */
  30741. openDownloadStream(id, options) {
  30742. return new download_1.GridFSBucketReadStream(this.s._chunksCollection, this.s._filesCollection, this.s.options.readPreference, { _id: id }, options);
  30743. }
  30744. /**
  30745. * Deletes a file with the given id
  30746. *
  30747. * @param id - The id of the file doc
  30748. */
  30749. async delete(id) {
  30750. const { deletedCount } = await this.s._filesCollection.deleteOne({ _id: id });
  30751. await this.s._chunksCollection.deleteMany({ files_id: id });
  30752. if (deletedCount === 0) {
  30753. throw new error_1.MongoRuntimeError(`File not found for id ${id}`);
  30754. }
  30755. }
  30756. /** Convenience wrapper around find on the files collection */
  30757. find(filter = {}, options = {}) {
  30758. return this.s._filesCollection.find(filter, options);
  30759. }
  30760. /**
  30761. * Returns a readable stream (GridFSBucketReadStream) for streaming the
  30762. * file with the given name from GridFS. If there are multiple files with
  30763. * the same name, this will stream the most recent file with the given name
  30764. * (as determined by the `uploadDate` field). You can set the `revision`
  30765. * option to change this behavior.
  30766. */
  30767. openDownloadStreamByName(filename, options) {
  30768. let sort = { uploadDate: -1 };
  30769. let skip = void 0;
  30770. if (options && options.revision != null) {
  30771. if (options.revision >= 0) {
  30772. sort = { uploadDate: 1 };
  30773. skip = options.revision;
  30774. } else {
  30775. skip = -options.revision - 1;
  30776. }
  30777. }
  30778. return new download_1.GridFSBucketReadStream(this.s._chunksCollection, this.s._filesCollection, this.s.options.readPreference, { filename }, { ...options, sort, skip });
  30779. }
  30780. /**
  30781. * Renames the file with the given _id to the given string
  30782. *
  30783. * @param id - the id of the file to rename
  30784. * @param filename - new name for the file
  30785. */
  30786. async rename(id, filename) {
  30787. const filter = { _id: id };
  30788. const update = { $set: { filename } };
  30789. const { matchedCount } = await this.s._filesCollection.updateOne(filter, update);
  30790. if (matchedCount === 0) {
  30791. throw new error_1.MongoRuntimeError(`File with id ${id} not found`);
  30792. }
  30793. }
  30794. /** Removes this bucket's files collection, followed by its chunks collection. */
  30795. async drop() {
  30796. await this.s._filesCollection.drop();
  30797. await this.s._chunksCollection.drop();
  30798. }
  30799. };
  30800. GridFSBucket.INDEX = "index";
  30801. exports2.GridFSBucket = GridFSBucket;
  30802. }
  30803. });
  30804. // node_modules/mongodb/lib/index.js
  30805. var require_lib3 = __commonJS({
  30806. "node_modules/mongodb/lib/index.js"(exports2) {
  30807. "use strict";
  30808. Object.defineProperty(exports2, "__esModule", { value: true });
  30809. exports2.AbstractCursor = exports2.MongoWriteConcernError = exports2.MongoUnexpectedServerResponseError = exports2.MongoTransactionError = exports2.MongoTopologyClosedError = exports2.MongoTailableCursorError = exports2.MongoSystemError = exports2.MongoServerSelectionError = exports2.MongoServerError = exports2.MongoServerClosedError = exports2.MongoRuntimeError = exports2.MongoParseError = exports2.MongoNotConnectedError = exports2.MongoNetworkTimeoutError = exports2.MongoNetworkError = exports2.MongoMissingDependencyError = exports2.MongoMissingCredentialsError = exports2.MongoKerberosError = exports2.MongoInvalidArgumentError = exports2.MongoGridFSStreamError = exports2.MongoGridFSChunkError = exports2.MongoExpiredSessionError = exports2.MongoError = exports2.MongoDriverError = exports2.MongoDecompressionError = exports2.MongoCursorInUseError = exports2.MongoCursorExhaustedError = exports2.MongoCompatibilityError = exports2.MongoChangeStreamError = exports2.MongoBatchReExecutionError = exports2.MongoAzureError = exports2.MongoAWSError = exports2.MongoAPIError = exports2.ChangeStreamCursor = exports2.MongoBulkWriteError = exports2.Timestamp = exports2.ObjectId = exports2.MinKey = exports2.MaxKey = exports2.Long = exports2.Int32 = exports2.Double = exports2.Decimal128 = exports2.DBRef = exports2.Code = exports2.BSONType = exports2.BSONSymbol = exports2.BSONRegExp = exports2.Binary = exports2.BSON = void 0;
  30810. exports2.ServerClosedEvent = exports2.ConnectionReadyEvent = exports2.ConnectionPoolReadyEvent = exports2.ConnectionPoolMonitoringEvent = exports2.ConnectionPoolCreatedEvent = exports2.ConnectionPoolClosedEvent = exports2.ConnectionPoolClearedEvent = exports2.ConnectionCreatedEvent = exports2.ConnectionClosedEvent = exports2.ConnectionCheckOutStartedEvent = exports2.ConnectionCheckOutFailedEvent = exports2.ConnectionCheckedOutEvent = exports2.ConnectionCheckedInEvent = exports2.CommandSucceededEvent = exports2.CommandStartedEvent = exports2.CommandFailedEvent = exports2.WriteConcern = exports2.ReadPreference = exports2.ReadConcern = exports2.TopologyType = exports2.ServerType = exports2.ReadPreferenceMode = exports2.ReadConcernLevel = exports2.ProfilingLevel = exports2.ReturnDocument = exports2.ServerApiVersion = exports2.ExplainVerbosity = exports2.MongoErrorLabel = exports2.AutoEncryptionLoggerLevel = exports2.CURSOR_FLAGS = exports2.Compressor = exports2.AuthMechanism = exports2.GSSAPICanonicalizationValue = exports2.BatchType = exports2.UnorderedBulkOperation = exports2.OrderedBulkOperation = exports2.MongoClient = exports2.ListIndexesCursor = exports2.ListCollectionsCursor = exports2.GridFSBucketWriteStream = exports2.GridFSBucketReadStream = exports2.GridFSBucket = exports2.FindCursor = exports2.Db = exports2.Collection = exports2.ClientSession = exports2.ChangeStream = exports2.CancellationToken = exports2.AggregationCursor = exports2.Admin = void 0;
  30811. exports2.SrvPollingEvent = exports2.TopologyOpeningEvent = exports2.TopologyDescriptionChangedEvent = exports2.TopologyClosedEvent = exports2.ServerOpeningEvent = exports2.ServerHeartbeatSucceededEvent = exports2.ServerHeartbeatStartedEvent = exports2.ServerHeartbeatFailedEvent = exports2.ServerDescriptionChangedEvent = void 0;
  30812. var admin_1 = require_admin();
  30813. Object.defineProperty(exports2, "Admin", { enumerable: true, get: function() {
  30814. return admin_1.Admin;
  30815. } });
  30816. var ordered_1 = require_ordered();
  30817. Object.defineProperty(exports2, "OrderedBulkOperation", { enumerable: true, get: function() {
  30818. return ordered_1.OrderedBulkOperation;
  30819. } });
  30820. var unordered_1 = require_unordered();
  30821. Object.defineProperty(exports2, "UnorderedBulkOperation", { enumerable: true, get: function() {
  30822. return unordered_1.UnorderedBulkOperation;
  30823. } });
  30824. var change_stream_1 = require_change_stream();
  30825. Object.defineProperty(exports2, "ChangeStream", { enumerable: true, get: function() {
  30826. return change_stream_1.ChangeStream;
  30827. } });
  30828. var collection_1 = require_collection();
  30829. Object.defineProperty(exports2, "Collection", { enumerable: true, get: function() {
  30830. return collection_1.Collection;
  30831. } });
  30832. var abstract_cursor_1 = require_abstract_cursor();
  30833. Object.defineProperty(exports2, "AbstractCursor", { enumerable: true, get: function() {
  30834. return abstract_cursor_1.AbstractCursor;
  30835. } });
  30836. var aggregation_cursor_1 = require_aggregation_cursor();
  30837. Object.defineProperty(exports2, "AggregationCursor", { enumerable: true, get: function() {
  30838. return aggregation_cursor_1.AggregationCursor;
  30839. } });
  30840. var find_cursor_1 = require_find_cursor();
  30841. Object.defineProperty(exports2, "FindCursor", { enumerable: true, get: function() {
  30842. return find_cursor_1.FindCursor;
  30843. } });
  30844. var list_collections_cursor_1 = require_list_collections_cursor();
  30845. Object.defineProperty(exports2, "ListCollectionsCursor", { enumerable: true, get: function() {
  30846. return list_collections_cursor_1.ListCollectionsCursor;
  30847. } });
  30848. var list_indexes_cursor_1 = require_list_indexes_cursor();
  30849. Object.defineProperty(exports2, "ListIndexesCursor", { enumerable: true, get: function() {
  30850. return list_indexes_cursor_1.ListIndexesCursor;
  30851. } });
  30852. var db_1 = require_db();
  30853. Object.defineProperty(exports2, "Db", { enumerable: true, get: function() {
  30854. return db_1.Db;
  30855. } });
  30856. var gridfs_1 = require_gridfs();
  30857. Object.defineProperty(exports2, "GridFSBucket", { enumerable: true, get: function() {
  30858. return gridfs_1.GridFSBucket;
  30859. } });
  30860. var download_1 = require_download();
  30861. Object.defineProperty(exports2, "GridFSBucketReadStream", { enumerable: true, get: function() {
  30862. return download_1.GridFSBucketReadStream;
  30863. } });
  30864. var upload_1 = require_upload();
  30865. Object.defineProperty(exports2, "GridFSBucketWriteStream", { enumerable: true, get: function() {
  30866. return upload_1.GridFSBucketWriteStream;
  30867. } });
  30868. var mongo_client_1 = require_mongo_client();
  30869. Object.defineProperty(exports2, "MongoClient", { enumerable: true, get: function() {
  30870. return mongo_client_1.MongoClient;
  30871. } });
  30872. var mongo_types_1 = require_mongo_types();
  30873. Object.defineProperty(exports2, "CancellationToken", { enumerable: true, get: function() {
  30874. return mongo_types_1.CancellationToken;
  30875. } });
  30876. var sessions_1 = require_sessions();
  30877. Object.defineProperty(exports2, "ClientSession", { enumerable: true, get: function() {
  30878. return sessions_1.ClientSession;
  30879. } });
  30880. var bson_1 = require_bson2();
  30881. Object.defineProperty(exports2, "BSON", { enumerable: true, get: function() {
  30882. return bson_1.BSON;
  30883. } });
  30884. var bson_2 = require_bson2();
  30885. Object.defineProperty(exports2, "Binary", { enumerable: true, get: function() {
  30886. return bson_2.Binary;
  30887. } });
  30888. Object.defineProperty(exports2, "BSONRegExp", { enumerable: true, get: function() {
  30889. return bson_2.BSONRegExp;
  30890. } });
  30891. Object.defineProperty(exports2, "BSONSymbol", { enumerable: true, get: function() {
  30892. return bson_2.BSONSymbol;
  30893. } });
  30894. Object.defineProperty(exports2, "BSONType", { enumerable: true, get: function() {
  30895. return bson_2.BSONType;
  30896. } });
  30897. Object.defineProperty(exports2, "Code", { enumerable: true, get: function() {
  30898. return bson_2.Code;
  30899. } });
  30900. Object.defineProperty(exports2, "DBRef", { enumerable: true, get: function() {
  30901. return bson_2.DBRef;
  30902. } });
  30903. Object.defineProperty(exports2, "Decimal128", { enumerable: true, get: function() {
  30904. return bson_2.Decimal128;
  30905. } });
  30906. Object.defineProperty(exports2, "Double", { enumerable: true, get: function() {
  30907. return bson_2.Double;
  30908. } });
  30909. Object.defineProperty(exports2, "Int32", { enumerable: true, get: function() {
  30910. return bson_2.Int32;
  30911. } });
  30912. Object.defineProperty(exports2, "Long", { enumerable: true, get: function() {
  30913. return bson_2.Long;
  30914. } });
  30915. Object.defineProperty(exports2, "MaxKey", { enumerable: true, get: function() {
  30916. return bson_2.MaxKey;
  30917. } });
  30918. Object.defineProperty(exports2, "MinKey", { enumerable: true, get: function() {
  30919. return bson_2.MinKey;
  30920. } });
  30921. Object.defineProperty(exports2, "ObjectId", { enumerable: true, get: function() {
  30922. return bson_2.ObjectId;
  30923. } });
  30924. Object.defineProperty(exports2, "Timestamp", { enumerable: true, get: function() {
  30925. return bson_2.Timestamp;
  30926. } });
  30927. var common_1 = require_common2();
  30928. Object.defineProperty(exports2, "MongoBulkWriteError", { enumerable: true, get: function() {
  30929. return common_1.MongoBulkWriteError;
  30930. } });
  30931. var change_stream_cursor_1 = require_change_stream_cursor();
  30932. Object.defineProperty(exports2, "ChangeStreamCursor", { enumerable: true, get: function() {
  30933. return change_stream_cursor_1.ChangeStreamCursor;
  30934. } });
  30935. var error_1 = require_error();
  30936. Object.defineProperty(exports2, "MongoAPIError", { enumerable: true, get: function() {
  30937. return error_1.MongoAPIError;
  30938. } });
  30939. Object.defineProperty(exports2, "MongoAWSError", { enumerable: true, get: function() {
  30940. return error_1.MongoAWSError;
  30941. } });
  30942. Object.defineProperty(exports2, "MongoAzureError", { enumerable: true, get: function() {
  30943. return error_1.MongoAzureError;
  30944. } });
  30945. Object.defineProperty(exports2, "MongoBatchReExecutionError", { enumerable: true, get: function() {
  30946. return error_1.MongoBatchReExecutionError;
  30947. } });
  30948. Object.defineProperty(exports2, "MongoChangeStreamError", { enumerable: true, get: function() {
  30949. return error_1.MongoChangeStreamError;
  30950. } });
  30951. Object.defineProperty(exports2, "MongoCompatibilityError", { enumerable: true, get: function() {
  30952. return error_1.MongoCompatibilityError;
  30953. } });
  30954. Object.defineProperty(exports2, "MongoCursorExhaustedError", { enumerable: true, get: function() {
  30955. return error_1.MongoCursorExhaustedError;
  30956. } });
  30957. Object.defineProperty(exports2, "MongoCursorInUseError", { enumerable: true, get: function() {
  30958. return error_1.MongoCursorInUseError;
  30959. } });
  30960. Object.defineProperty(exports2, "MongoDecompressionError", { enumerable: true, get: function() {
  30961. return error_1.MongoDecompressionError;
  30962. } });
  30963. Object.defineProperty(exports2, "MongoDriverError", { enumerable: true, get: function() {
  30964. return error_1.MongoDriverError;
  30965. } });
  30966. Object.defineProperty(exports2, "MongoError", { enumerable: true, get: function() {
  30967. return error_1.MongoError;
  30968. } });
  30969. Object.defineProperty(exports2, "MongoExpiredSessionError", { enumerable: true, get: function() {
  30970. return error_1.MongoExpiredSessionError;
  30971. } });
  30972. Object.defineProperty(exports2, "MongoGridFSChunkError", { enumerable: true, get: function() {
  30973. return error_1.MongoGridFSChunkError;
  30974. } });
  30975. Object.defineProperty(exports2, "MongoGridFSStreamError", { enumerable: true, get: function() {
  30976. return error_1.MongoGridFSStreamError;
  30977. } });
  30978. Object.defineProperty(exports2, "MongoInvalidArgumentError", { enumerable: true, get: function() {
  30979. return error_1.MongoInvalidArgumentError;
  30980. } });
  30981. Object.defineProperty(exports2, "MongoKerberosError", { enumerable: true, get: function() {
  30982. return error_1.MongoKerberosError;
  30983. } });
  30984. Object.defineProperty(exports2, "MongoMissingCredentialsError", { enumerable: true, get: function() {
  30985. return error_1.MongoMissingCredentialsError;
  30986. } });
  30987. Object.defineProperty(exports2, "MongoMissingDependencyError", { enumerable: true, get: function() {
  30988. return error_1.MongoMissingDependencyError;
  30989. } });
  30990. Object.defineProperty(exports2, "MongoNetworkError", { enumerable: true, get: function() {
  30991. return error_1.MongoNetworkError;
  30992. } });
  30993. Object.defineProperty(exports2, "MongoNetworkTimeoutError", { enumerable: true, get: function() {
  30994. return error_1.MongoNetworkTimeoutError;
  30995. } });
  30996. Object.defineProperty(exports2, "MongoNotConnectedError", { enumerable: true, get: function() {
  30997. return error_1.MongoNotConnectedError;
  30998. } });
  30999. Object.defineProperty(exports2, "MongoParseError", { enumerable: true, get: function() {
  31000. return error_1.MongoParseError;
  31001. } });
  31002. Object.defineProperty(exports2, "MongoRuntimeError", { enumerable: true, get: function() {
  31003. return error_1.MongoRuntimeError;
  31004. } });
  31005. Object.defineProperty(exports2, "MongoServerClosedError", { enumerable: true, get: function() {
  31006. return error_1.MongoServerClosedError;
  31007. } });
  31008. Object.defineProperty(exports2, "MongoServerError", { enumerable: true, get: function() {
  31009. return error_1.MongoServerError;
  31010. } });
  31011. Object.defineProperty(exports2, "MongoServerSelectionError", { enumerable: true, get: function() {
  31012. return error_1.MongoServerSelectionError;
  31013. } });
  31014. Object.defineProperty(exports2, "MongoSystemError", { enumerable: true, get: function() {
  31015. return error_1.MongoSystemError;
  31016. } });
  31017. Object.defineProperty(exports2, "MongoTailableCursorError", { enumerable: true, get: function() {
  31018. return error_1.MongoTailableCursorError;
  31019. } });
  31020. Object.defineProperty(exports2, "MongoTopologyClosedError", { enumerable: true, get: function() {
  31021. return error_1.MongoTopologyClosedError;
  31022. } });
  31023. Object.defineProperty(exports2, "MongoTransactionError", { enumerable: true, get: function() {
  31024. return error_1.MongoTransactionError;
  31025. } });
  31026. Object.defineProperty(exports2, "MongoUnexpectedServerResponseError", { enumerable: true, get: function() {
  31027. return error_1.MongoUnexpectedServerResponseError;
  31028. } });
  31029. Object.defineProperty(exports2, "MongoWriteConcernError", { enumerable: true, get: function() {
  31030. return error_1.MongoWriteConcernError;
  31031. } });
  31032. var common_2 = require_common2();
  31033. Object.defineProperty(exports2, "BatchType", { enumerable: true, get: function() {
  31034. return common_2.BatchType;
  31035. } });
  31036. var gssapi_1 = require_gssapi();
  31037. Object.defineProperty(exports2, "GSSAPICanonicalizationValue", { enumerable: true, get: function() {
  31038. return gssapi_1.GSSAPICanonicalizationValue;
  31039. } });
  31040. var providers_1 = require_providers();
  31041. Object.defineProperty(exports2, "AuthMechanism", { enumerable: true, get: function() {
  31042. return providers_1.AuthMechanism;
  31043. } });
  31044. var compression_1 = require_compression();
  31045. Object.defineProperty(exports2, "Compressor", { enumerable: true, get: function() {
  31046. return compression_1.Compressor;
  31047. } });
  31048. var abstract_cursor_2 = require_abstract_cursor();
  31049. Object.defineProperty(exports2, "CURSOR_FLAGS", { enumerable: true, get: function() {
  31050. return abstract_cursor_2.CURSOR_FLAGS;
  31051. } });
  31052. var deps_1 = require_deps();
  31053. Object.defineProperty(exports2, "AutoEncryptionLoggerLevel", { enumerable: true, get: function() {
  31054. return deps_1.AutoEncryptionLoggerLevel;
  31055. } });
  31056. var error_2 = require_error();
  31057. Object.defineProperty(exports2, "MongoErrorLabel", { enumerable: true, get: function() {
  31058. return error_2.MongoErrorLabel;
  31059. } });
  31060. var explain_1 = require_explain();
  31061. Object.defineProperty(exports2, "ExplainVerbosity", { enumerable: true, get: function() {
  31062. return explain_1.ExplainVerbosity;
  31063. } });
  31064. var mongo_client_2 = require_mongo_client();
  31065. Object.defineProperty(exports2, "ServerApiVersion", { enumerable: true, get: function() {
  31066. return mongo_client_2.ServerApiVersion;
  31067. } });
  31068. var find_and_modify_1 = require_find_and_modify();
  31069. Object.defineProperty(exports2, "ReturnDocument", { enumerable: true, get: function() {
  31070. return find_and_modify_1.ReturnDocument;
  31071. } });
  31072. var set_profiling_level_1 = require_set_profiling_level();
  31073. Object.defineProperty(exports2, "ProfilingLevel", { enumerable: true, get: function() {
  31074. return set_profiling_level_1.ProfilingLevel;
  31075. } });
  31076. var read_concern_1 = require_read_concern();
  31077. Object.defineProperty(exports2, "ReadConcernLevel", { enumerable: true, get: function() {
  31078. return read_concern_1.ReadConcernLevel;
  31079. } });
  31080. var read_preference_1 = require_read_preference();
  31081. Object.defineProperty(exports2, "ReadPreferenceMode", { enumerable: true, get: function() {
  31082. return read_preference_1.ReadPreferenceMode;
  31083. } });
  31084. var common_3 = require_common();
  31085. Object.defineProperty(exports2, "ServerType", { enumerable: true, get: function() {
  31086. return common_3.ServerType;
  31087. } });
  31088. Object.defineProperty(exports2, "TopologyType", { enumerable: true, get: function() {
  31089. return common_3.TopologyType;
  31090. } });
  31091. var read_concern_2 = require_read_concern();
  31092. Object.defineProperty(exports2, "ReadConcern", { enumerable: true, get: function() {
  31093. return read_concern_2.ReadConcern;
  31094. } });
  31095. var read_preference_2 = require_read_preference();
  31096. Object.defineProperty(exports2, "ReadPreference", { enumerable: true, get: function() {
  31097. return read_preference_2.ReadPreference;
  31098. } });
  31099. var write_concern_1 = require_write_concern();
  31100. Object.defineProperty(exports2, "WriteConcern", { enumerable: true, get: function() {
  31101. return write_concern_1.WriteConcern;
  31102. } });
  31103. var command_monitoring_events_1 = require_command_monitoring_events();
  31104. Object.defineProperty(exports2, "CommandFailedEvent", { enumerable: true, get: function() {
  31105. return command_monitoring_events_1.CommandFailedEvent;
  31106. } });
  31107. Object.defineProperty(exports2, "CommandStartedEvent", { enumerable: true, get: function() {
  31108. return command_monitoring_events_1.CommandStartedEvent;
  31109. } });
  31110. Object.defineProperty(exports2, "CommandSucceededEvent", { enumerable: true, get: function() {
  31111. return command_monitoring_events_1.CommandSucceededEvent;
  31112. } });
  31113. var connection_pool_events_1 = require_connection_pool_events();
  31114. Object.defineProperty(exports2, "ConnectionCheckedInEvent", { enumerable: true, get: function() {
  31115. return connection_pool_events_1.ConnectionCheckedInEvent;
  31116. } });
  31117. Object.defineProperty(exports2, "ConnectionCheckedOutEvent", { enumerable: true, get: function() {
  31118. return connection_pool_events_1.ConnectionCheckedOutEvent;
  31119. } });
  31120. Object.defineProperty(exports2, "ConnectionCheckOutFailedEvent", { enumerable: true, get: function() {
  31121. return connection_pool_events_1.ConnectionCheckOutFailedEvent;
  31122. } });
  31123. Object.defineProperty(exports2, "ConnectionCheckOutStartedEvent", { enumerable: true, get: function() {
  31124. return connection_pool_events_1.ConnectionCheckOutStartedEvent;
  31125. } });
  31126. Object.defineProperty(exports2, "ConnectionClosedEvent", { enumerable: true, get: function() {
  31127. return connection_pool_events_1.ConnectionClosedEvent;
  31128. } });
  31129. Object.defineProperty(exports2, "ConnectionCreatedEvent", { enumerable: true, get: function() {
  31130. return connection_pool_events_1.ConnectionCreatedEvent;
  31131. } });
  31132. Object.defineProperty(exports2, "ConnectionPoolClearedEvent", { enumerable: true, get: function() {
  31133. return connection_pool_events_1.ConnectionPoolClearedEvent;
  31134. } });
  31135. Object.defineProperty(exports2, "ConnectionPoolClosedEvent", { enumerable: true, get: function() {
  31136. return connection_pool_events_1.ConnectionPoolClosedEvent;
  31137. } });
  31138. Object.defineProperty(exports2, "ConnectionPoolCreatedEvent", { enumerable: true, get: function() {
  31139. return connection_pool_events_1.ConnectionPoolCreatedEvent;
  31140. } });
  31141. Object.defineProperty(exports2, "ConnectionPoolMonitoringEvent", { enumerable: true, get: function() {
  31142. return connection_pool_events_1.ConnectionPoolMonitoringEvent;
  31143. } });
  31144. Object.defineProperty(exports2, "ConnectionPoolReadyEvent", { enumerable: true, get: function() {
  31145. return connection_pool_events_1.ConnectionPoolReadyEvent;
  31146. } });
  31147. Object.defineProperty(exports2, "ConnectionReadyEvent", { enumerable: true, get: function() {
  31148. return connection_pool_events_1.ConnectionReadyEvent;
  31149. } });
  31150. var events_1 = require_events();
  31151. Object.defineProperty(exports2, "ServerClosedEvent", { enumerable: true, get: function() {
  31152. return events_1.ServerClosedEvent;
  31153. } });
  31154. Object.defineProperty(exports2, "ServerDescriptionChangedEvent", { enumerable: true, get: function() {
  31155. return events_1.ServerDescriptionChangedEvent;
  31156. } });
  31157. Object.defineProperty(exports2, "ServerHeartbeatFailedEvent", { enumerable: true, get: function() {
  31158. return events_1.ServerHeartbeatFailedEvent;
  31159. } });
  31160. Object.defineProperty(exports2, "ServerHeartbeatStartedEvent", { enumerable: true, get: function() {
  31161. return events_1.ServerHeartbeatStartedEvent;
  31162. } });
  31163. Object.defineProperty(exports2, "ServerHeartbeatSucceededEvent", { enumerable: true, get: function() {
  31164. return events_1.ServerHeartbeatSucceededEvent;
  31165. } });
  31166. Object.defineProperty(exports2, "ServerOpeningEvent", { enumerable: true, get: function() {
  31167. return events_1.ServerOpeningEvent;
  31168. } });
  31169. Object.defineProperty(exports2, "TopologyClosedEvent", { enumerable: true, get: function() {
  31170. return events_1.TopologyClosedEvent;
  31171. } });
  31172. Object.defineProperty(exports2, "TopologyDescriptionChangedEvent", { enumerable: true, get: function() {
  31173. return events_1.TopologyDescriptionChangedEvent;
  31174. } });
  31175. Object.defineProperty(exports2, "TopologyOpeningEvent", { enumerable: true, get: function() {
  31176. return events_1.TopologyOpeningEvent;
  31177. } });
  31178. var srv_polling_1 = require_srv_polling();
  31179. Object.defineProperty(exports2, "SrvPollingEvent", { enumerable: true, get: function() {
  31180. return srv_polling_1.SrvPollingEvent;
  31181. } });
  31182. }
  31183. });
  31184. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/utils/is-class.js
  31185. function isClass(value) {
  31186. if (!value) return false;
  31187. return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
  31188. }
  31189. var init_is_class = __esm({
  31190. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/utils/is-class.js"() {
  31191. }
  31192. });
  31193. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/utils/index.js
  31194. var init_utils = __esm({
  31195. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/utils/index.js"() {
  31196. init_is_class();
  31197. }
  31198. });
  31199. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/value-to-string.js
  31200. function valueToString(input) {
  31201. if (input == null) return String(input);
  31202. if (typeof input === "string") return `"${input}"`;
  31203. if (typeof input === "number" || typeof input === "boolean")
  31204. return String(input);
  31205. if (isClass(input)) return input.name ? input.name : "Class";
  31206. if (input.constructor && input.constructor.name)
  31207. return input.constructor.name;
  31208. if (typeof input === "object" && input.constructor == null) return "Object";
  31209. return String(input);
  31210. }
  31211. var init_value_to_string = __esm({
  31212. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/value-to-string.js"() {
  31213. init_utils();
  31214. }
  31215. });
  31216. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/array-to-list.js
  31217. function arrayToList(input) {
  31218. if (Array.isArray(input) && input.length)
  31219. return input.map(valueToString).join(SEPARATOR);
  31220. return valueToString(input);
  31221. }
  31222. var SEPARATOR;
  31223. var init_array_to_list = __esm({
  31224. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/array-to-list.js"() {
  31225. init_value_to_string();
  31226. SEPARATOR = ", ";
  31227. }
  31228. });
  31229. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/format.js
  31230. function format(pattern) {
  31231. if (pattern instanceof Date) {
  31232. pattern = pattern.toISOString();
  31233. } else if (typeof pattern !== "string") {
  31234. pattern = String(pattern);
  31235. }
  31236. const re = /(%?)(%([sdjvl]))/g;
  31237. const args = Array.prototype.slice.call(arguments, 1);
  31238. if (args.length) {
  31239. pattern = pattern.replace(re, function(match, escaped, ptn, flag) {
  31240. let arg = args.shift();
  31241. switch (flag) {
  31242. // eslint-disable-next-line no-fallthrough
  31243. case "s":
  31244. arg = String(arg);
  31245. break;
  31246. case "d":
  31247. arg = Number(arg);
  31248. break;
  31249. case "j":
  31250. arg = JSON.stringify(arg);
  31251. break;
  31252. case "v":
  31253. arg = valueToString(arg);
  31254. break;
  31255. case "l":
  31256. arg = arrayToList(arg);
  31257. break;
  31258. }
  31259. if (!escaped) return arg;
  31260. args.unshift(arg);
  31261. return match;
  31262. });
  31263. }
  31264. if (args.length) pattern += " " + args.join(" ");
  31265. pattern = pattern.replace(/%{2,2}/g, "%");
  31266. return "" + pattern;
  31267. }
  31268. var init_format = __esm({
  31269. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/format.js"() {
  31270. init_array_to_list();
  31271. init_value_to_string();
  31272. }
  31273. });
  31274. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/errorf.js
  31275. var Errorf;
  31276. var init_errorf = __esm({
  31277. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/errorf.js"() {
  31278. init_format();
  31279. Errorf = class extends Error {
  31280. /**
  31281. * Constructor.
  31282. *
  31283. * @param {string|undefined} pattern
  31284. * @param {any} args
  31285. */
  31286. constructor(pattern = void 0, ...args) {
  31287. const message = pattern != null ? format(pattern, ...args) : void 0;
  31288. super(message);
  31289. }
  31290. };
  31291. }
  31292. });
  31293. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/index.js
  31294. var init_src = __esm({
  31295. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-format/src/index.js"() {
  31296. init_format();
  31297. init_errorf();
  31298. }
  31299. });
  31300. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js
  31301. var InvalidArgumentError;
  31302. var init_invalid_argument_error = __esm({
  31303. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js"() {
  31304. init_src();
  31305. InvalidArgumentError = class extends Errorf {
  31306. };
  31307. }
  31308. });
  31309. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/errors/index.js
  31310. var init_errors = __esm({
  31311. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/errors/index.js"() {
  31312. init_invalid_argument_error();
  31313. }
  31314. });
  31315. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/service-container.js
  31316. var ServiceContainer;
  31317. var init_service_container = __esm({
  31318. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/service-container.js"() {
  31319. init_service();
  31320. init_errors();
  31321. ServiceContainer = class _ServiceContainer {
  31322. /**
  31323. * Services map.
  31324. *
  31325. * @type {Map<any, any>}
  31326. * @private
  31327. */
  31328. _services = /* @__PURE__ */ new Map();
  31329. /**
  31330. * Parent container.
  31331. *
  31332. * @type {ServiceContainer}
  31333. * @private
  31334. */
  31335. _parent;
  31336. /**
  31337. * Constructor.
  31338. *
  31339. * @param {ServiceContainer|undefined} parent
  31340. */
  31341. constructor(parent = void 0) {
  31342. if (parent != null) {
  31343. if (!(parent instanceof _ServiceContainer))
  31344. throw new InvalidArgumentError(
  31345. 'The provided parameter "parent" of ServicesContainer.constructor must be an instance ServiceContainer, but %v given.',
  31346. parent
  31347. );
  31348. this._parent = parent;
  31349. }
  31350. }
  31351. /**
  31352. * Получить существующий или новый экземпляр.
  31353. *
  31354. * @param {*} ctor
  31355. * @param {*} args
  31356. * @return {*}
  31357. */
  31358. get(ctor, ...args) {
  31359. if (!ctor || typeof ctor !== "function")
  31360. throw new InvalidArgumentError(
  31361. "The first argument of ServicesContainer.get must be a class constructor, but %v given.",
  31362. ctor
  31363. );
  31364. if (!this._services.has(ctor) && this._parent && this._parent.has(ctor)) {
  31365. return this._parent.get(ctor);
  31366. }
  31367. let service = this._services.get(ctor);
  31368. if (!service || args.length) {
  31369. service = "prototype" in ctor && ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31370. this._services.set(ctor, service);
  31371. } else if (typeof service === "function") {
  31372. service = service();
  31373. this._services.set(ctor, service);
  31374. }
  31375. return service;
  31376. }
  31377. /**
  31378. * Проверка существования конструктора в контейнере.
  31379. *
  31380. * @param {*} ctor
  31381. * @return {boolean}
  31382. */
  31383. has(ctor) {
  31384. if (this._services.has(ctor)) return true;
  31385. if (this._parent) return this._parent.has(ctor);
  31386. return false;
  31387. }
  31388. /**
  31389. * Добавить конструктор в контейнер.
  31390. *
  31391. * @param {*} ctor
  31392. * @param {*} args
  31393. * @return {this}
  31394. */
  31395. add(ctor, ...args) {
  31396. if (!ctor || typeof ctor !== "function")
  31397. throw new InvalidArgumentError(
  31398. "The first argument of ServicesContainer.add must be a class constructor, but %v given.",
  31399. ctor
  31400. );
  31401. const factory = () => ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31402. this._services.set(ctor, factory);
  31403. return this;
  31404. }
  31405. /**
  31406. * Добавить конструктор и создать экземпляр.
  31407. *
  31408. * @param {*} ctor
  31409. * @param {*} args
  31410. * @return {this}
  31411. */
  31412. use(ctor, ...args) {
  31413. if (!ctor || typeof ctor !== "function")
  31414. throw new InvalidArgumentError(
  31415. "The first argument of ServicesContainer.use must be a class constructor, but %v given.",
  31416. ctor
  31417. );
  31418. const service = ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31419. this._services.set(ctor, service);
  31420. return this;
  31421. }
  31422. /**
  31423. * Добавить конструктор и связанный экземпляр.
  31424. *
  31425. * @param {*} ctor
  31426. * @param {*} service
  31427. * @return {this}
  31428. */
  31429. set(ctor, service) {
  31430. if (!ctor || typeof ctor !== "function")
  31431. throw new InvalidArgumentError(
  31432. "The first argument of ServicesContainer.set must be a class constructor, but %v given.",
  31433. ctor
  31434. );
  31435. if (!service || typeof service !== "object" || Array.isArray(service))
  31436. throw new InvalidArgumentError(
  31437. "The second argument of ServicesContainer.set must be an Object, but %v given.",
  31438. service
  31439. );
  31440. this._services.set(ctor, service);
  31441. return this;
  31442. }
  31443. };
  31444. }
  31445. });
  31446. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/service.js
  31447. var Service;
  31448. var init_service = __esm({
  31449. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/service.js"() {
  31450. init_service_container();
  31451. Service = class {
  31452. /**
  31453. * Container.
  31454. *
  31455. * @type {ServiceContainer}
  31456. */
  31457. container;
  31458. /**
  31459. * Constructor.
  31460. *
  31461. * @param {ServiceContainer|undefined} container
  31462. */
  31463. constructor(container = void 0) {
  31464. this.container = container instanceof ServiceContainer ? container : new ServiceContainer();
  31465. }
  31466. /**
  31467. * Получить существующий или новый экземпляр.
  31468. *
  31469. * @param {*} ctor
  31470. * @param {*} args
  31471. * @return {*}
  31472. */
  31473. getService(ctor, ...args) {
  31474. return this.container.get(ctor, ...args);
  31475. }
  31476. /**
  31477. * Проверка существования конструктора в контейнере.
  31478. *
  31479. * @param {*} ctor
  31480. * @return {boolean}
  31481. */
  31482. hasService(ctor) {
  31483. return this.container.has(ctor);
  31484. }
  31485. /**
  31486. * Добавить конструктор в контейнер.
  31487. *
  31488. * @param {*} ctor
  31489. * @param {*} args
  31490. * @return {this}
  31491. */
  31492. addService(ctor, ...args) {
  31493. this.container.add(ctor, ...args);
  31494. return this;
  31495. }
  31496. /**
  31497. * Добавить конструктор и создать экземпляр.
  31498. *
  31499. * @param {*} ctor
  31500. * @param {*} args
  31501. * @return {this}
  31502. */
  31503. useService(ctor, ...args) {
  31504. this.container.use(ctor, ...args);
  31505. return this;
  31506. }
  31507. /**
  31508. * Добавить конструктор и связанный экземпляр.
  31509. *
  31510. * @param {*} ctor
  31511. * @param {*} service
  31512. * @return {this}
  31513. */
  31514. setService(ctor, service) {
  31515. this.container.set(ctor, service);
  31516. return this;
  31517. }
  31518. };
  31519. }
  31520. });
  31521. // node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/index.js
  31522. var init_src2 = __esm({
  31523. "node_modules/@e22m4u/js-repository/node_modules/@e22m4u/js-service/src/index.js"() {
  31524. init_service();
  31525. init_service_container();
  31526. }
  31527. });
  31528. // node_modules/@e22m4u/js-repository/src/errors/not-implemented-error.js
  31529. var NotImplementedError;
  31530. var init_not_implemented_error = __esm({
  31531. "node_modules/@e22m4u/js-repository/src/errors/not-implemented-error.js"() {
  31532. init_src();
  31533. NotImplementedError = class extends Errorf {
  31534. };
  31535. }
  31536. });
  31537. // node_modules/@e22m4u/js-repository/src/errors/invalid-argument-error.js
  31538. var InvalidArgumentError2;
  31539. var init_invalid_argument_error2 = __esm({
  31540. "node_modules/@e22m4u/js-repository/src/errors/invalid-argument-error.js"() {
  31541. init_src();
  31542. InvalidArgumentError2 = class extends Errorf {
  31543. };
  31544. }
  31545. });
  31546. // node_modules/@e22m4u/js-repository/src/errors/invalid-operator-value-error.js
  31547. var InvalidOperatorValueError;
  31548. var init_invalid_operator_value_error = __esm({
  31549. "node_modules/@e22m4u/js-repository/src/errors/invalid-operator-value-error.js"() {
  31550. init_src();
  31551. InvalidOperatorValueError = class extends Error {
  31552. /**
  31553. * Constructor.
  31554. *
  31555. * @param {string} operator
  31556. * @param {string} expected
  31557. * @param {*} value
  31558. */
  31559. constructor(operator, expected, value) {
  31560. super(
  31561. format(
  31562. "Condition of {%s: ...} should have %s, but %v given.",
  31563. operator,
  31564. expected,
  31565. value
  31566. )
  31567. );
  31568. }
  31569. };
  31570. }
  31571. });
  31572. // node_modules/@e22m4u/js-repository/src/errors/index.js
  31573. var init_errors2 = __esm({
  31574. "node_modules/@e22m4u/js-repository/src/errors/index.js"() {
  31575. init_not_implemented_error();
  31576. init_invalid_argument_error2();
  31577. init_invalid_operator_value_error();
  31578. }
  31579. });
  31580. // node_modules/@e22m4u/js-repository/src/filter/slice-clause-tool.js
  31581. var SliceClauseTool;
  31582. var init_slice_clause_tool = __esm({
  31583. "node_modules/@e22m4u/js-repository/src/filter/slice-clause-tool.js"() {
  31584. init_src2();
  31585. init_errors2();
  31586. SliceClauseTool = class extends Service {
  31587. /**
  31588. * Slice.
  31589. *
  31590. * @param {object[]} entities
  31591. * @param {number|undefined} skip
  31592. * @param {number|undefined} limit
  31593. * @returns {object[]}
  31594. */
  31595. slice(entities, skip = void 0, limit = void 0) {
  31596. if (!Array.isArray(entities))
  31597. throw new InvalidArgumentError2(
  31598. "The first argument of SliceClauseTool.slice should be an Array, but %v given.",
  31599. entities
  31600. );
  31601. if (skip != null && typeof skip !== "number")
  31602. throw new InvalidArgumentError2(
  31603. 'The provided option "skip" should be a Number, but %v given.',
  31604. skip
  31605. );
  31606. if (limit != null && typeof limit !== "number")
  31607. throw new InvalidArgumentError2(
  31608. 'The provided option "limit" should be a Number, but %v given.',
  31609. limit
  31610. );
  31611. skip = skip || 0;
  31612. limit = limit || entities.length;
  31613. return entities.slice(skip, skip + limit);
  31614. }
  31615. /**
  31616. * Validate skip clause.
  31617. *
  31618. * @param {number|undefined} skip
  31619. */
  31620. static validateSkipClause(skip) {
  31621. if (skip == null) return;
  31622. if (typeof skip !== "number")
  31623. throw new InvalidArgumentError2(
  31624. 'The provided option "skip" should be a Number, but %v given.',
  31625. skip
  31626. );
  31627. }
  31628. /**
  31629. * Validate limit clause.
  31630. *
  31631. * @param {number|undefined} limit
  31632. */
  31633. static validateLimitClause(limit) {
  31634. if (limit == null) return;
  31635. if (typeof limit !== "number")
  31636. throw new InvalidArgumentError2(
  31637. 'The provided option "limit" should be a Number, but %v given.',
  31638. limit
  31639. );
  31640. }
  31641. };
  31642. }
  31643. });
  31644. // node_modules/@e22m4u/js-repository/src/utils/is-ctor.js
  31645. var init_is_ctor = __esm({
  31646. "node_modules/@e22m4u/js-repository/src/utils/is-ctor.js"() {
  31647. }
  31648. });
  31649. // node_modules/@e22m4u/js-repository/src/utils/is-promise.js
  31650. function isPromise(value) {
  31651. if (!value) return false;
  31652. if (typeof value !== "object") return false;
  31653. return typeof value.then === "function";
  31654. }
  31655. var init_is_promise = __esm({
  31656. "node_modules/@e22m4u/js-repository/src/utils/is-promise.js"() {
  31657. }
  31658. });
  31659. // node_modules/@e22m4u/js-repository/src/utils/capitalize.js
  31660. function capitalize(string) {
  31661. if (!string || typeof string !== "string") return string;
  31662. return string.charAt(0).toUpperCase() + string.slice(1);
  31663. }
  31664. var init_capitalize = __esm({
  31665. "node_modules/@e22m4u/js-repository/src/utils/capitalize.js"() {
  31666. }
  31667. });
  31668. // node_modules/@e22m4u/js-repository/src/utils/clone-deep.js
  31669. function cloneDeep(value) {
  31670. if (!value) return value;
  31671. const types = [Number, String, Boolean];
  31672. let result;
  31673. types.forEach((type) => {
  31674. if (value instanceof type) result = type(value);
  31675. });
  31676. if (result === void 0) {
  31677. if (Array.isArray(value)) {
  31678. result = [];
  31679. value.forEach((child, index) => {
  31680. result[index] = cloneDeep(child);
  31681. });
  31682. } else if (typeof value === "object") {
  31683. if ("nodeType" in value && value.nodeType && "cloneNode" in value && typeof value.cloneNode === "function") {
  31684. result = value.cloneNode(true);
  31685. } else if (!("prototype" in value) || !value.prototype) {
  31686. if (value instanceof Date) {
  31687. result = new Date(value);
  31688. } else if (value.constructor && value.constructor.name === "Object") {
  31689. result = {};
  31690. for (const key in value) {
  31691. result[key] = cloneDeep(value[key]);
  31692. }
  31693. } else {
  31694. result = value;
  31695. }
  31696. } else {
  31697. result = value;
  31698. }
  31699. } else {
  31700. result = value;
  31701. }
  31702. }
  31703. return result;
  31704. }
  31705. var init_clone_deep = __esm({
  31706. "node_modules/@e22m4u/js-repository/src/utils/clone-deep.js"() {
  31707. }
  31708. });
  31709. // node_modules/@e22m4u/js-repository/src/utils/singularize.js
  31710. function singularize(noun) {
  31711. if (!noun || typeof noun !== "string") return noun;
  31712. const endings = {
  31713. ves: "fe",
  31714. ies: "y",
  31715. i: "us",
  31716. zes: "ze",
  31717. ses: "s",
  31718. es: "e",
  31719. s: ""
  31720. };
  31721. return noun.replace(
  31722. new RegExp(`(${Object.keys(endings).join("|")})$`),
  31723. (r) => endings[r]
  31724. );
  31725. }
  31726. var init_singularize = __esm({
  31727. "node_modules/@e22m4u/js-repository/src/utils/singularize.js"() {
  31728. }
  31729. });
  31730. // node_modules/@e22m4u/js-repository/src/utils/is-deep-equal.js
  31731. function isDeepEqual(firstValue, secondValue) {
  31732. const cached = /* @__PURE__ */ new WeakMap();
  31733. const compare = (a, b) => {
  31734. if (a === null || b === null) return a === b;
  31735. if (typeof a !== "object" || typeof b !== "object") return a === b;
  31736. const dataTypeA = Array.isArray(a) ? "array" : "object";
  31737. const dataTypeB = Array.isArray(b) ? "array" : "object";
  31738. if (dataTypeA !== dataTypeB) return false;
  31739. const keysA = Object.keys(a);
  31740. const keysB = Object.keys(b);
  31741. if (keysA.length !== keysB.length) return false;
  31742. const symbolsA = Object.getOwnPropertySymbols(a);
  31743. const symbolsB = Object.getOwnPropertySymbols(b);
  31744. if (symbolsA.length !== symbolsB.length) return false;
  31745. let setForA = cached.get(a);
  31746. if (setForA == null) {
  31747. setForA = /* @__PURE__ */ new Set();
  31748. cached.set(a, setForA);
  31749. } else if (setForA.has(b)) {
  31750. return true;
  31751. }
  31752. setForA.add(b);
  31753. let setForB = cached.get(b);
  31754. if (setForB == null) {
  31755. setForB = /* @__PURE__ */ new Set();
  31756. cached.set(b, setForB);
  31757. } else if (setForB.has(a)) {
  31758. return true;
  31759. }
  31760. setForB.add(a);
  31761. const propertyNamesA = [...keysA, ...symbolsA];
  31762. for (const propertyNameA of propertyNamesA) {
  31763. if (!b.hasOwnProperty(propertyNameA)) return false;
  31764. const propertyValueA = a[propertyNameA];
  31765. const propertyValueB = b[propertyNameA];
  31766. if (!compare(propertyValueA, propertyValueB)) return false;
  31767. }
  31768. return true;
  31769. };
  31770. return compare(firstValue, secondValue);
  31771. }
  31772. var init_is_deep_equal = __esm({
  31773. "node_modules/@e22m4u/js-repository/src/utils/is-deep-equal.js"() {
  31774. }
  31775. });
  31776. // node_modules/@e22m4u/js-repository/src/utils/get-ctor-name.js
  31777. function getCtorName(value) {
  31778. if (value === null) return "Null";
  31779. if (value === void 0) return "Undefined";
  31780. return value.constructor && value.constructor.name || void 0;
  31781. }
  31782. var init_get_ctor_name = __esm({
  31783. "node_modules/@e22m4u/js-repository/src/utils/get-ctor-name.js"() {
  31784. }
  31785. });
  31786. // node_modules/@e22m4u/js-repository/src/utils/is-pure-object.js
  31787. function isPureObject(value) {
  31788. return Boolean(
  31789. typeof value === "object" && value && !Array.isArray(value) && (!value.constructor || value.constructor && value.constructor.name === "Object")
  31790. );
  31791. }
  31792. var init_is_pure_object = __esm({
  31793. "node_modules/@e22m4u/js-repository/src/utils/is-pure-object.js"() {
  31794. }
  31795. });
  31796. // node_modules/@e22m4u/js-repository/src/utils/string-to-regexp.js
  31797. function stringToRegexp(pattern, flags = void 0) {
  31798. if (pattern instanceof RegExp) {
  31799. return new RegExp(pattern, flags);
  31800. }
  31801. let regex = "";
  31802. for (let i = 0, n = pattern.length; i < n; i++) {
  31803. const char = pattern.charAt(i);
  31804. if (char === "%") {
  31805. regex += ".*";
  31806. } else {
  31807. regex += char;
  31808. }
  31809. }
  31810. return new RegExp(regex, flags);
  31811. }
  31812. var init_string_to_regexp = __esm({
  31813. "node_modules/@e22m4u/js-repository/src/utils/string-to-regexp.js"() {
  31814. }
  31815. });
  31816. // node_modules/@e22m4u/js-repository/src/utils/get-value-by-path.js
  31817. function getValueByPath(obj, path, orElse = void 0) {
  31818. if (!obj || typeof obj !== "object") return orElse;
  31819. if (!path || typeof path !== "string") return orElse;
  31820. const keys = path.split(".");
  31821. let value = obj;
  31822. for (const key of keys) {
  31823. if (typeof value === "object" && value !== null && key in value) {
  31824. value = value[key];
  31825. } else {
  31826. value = orElse;
  31827. break;
  31828. }
  31829. }
  31830. return value;
  31831. }
  31832. var init_get_value_by_path = __esm({
  31833. "node_modules/@e22m4u/js-repository/src/utils/get-value-by-path.js"() {
  31834. }
  31835. });
  31836. // node_modules/@e22m4u/js-repository/src/utils/transform-promise.js
  31837. function transformPromise(valueOrPromise, transformer) {
  31838. return isPromise(valueOrPromise) ? valueOrPromise.then(transformer) : transformer(valueOrPromise);
  31839. }
  31840. var init_transform_promise = __esm({
  31841. "node_modules/@e22m4u/js-repository/src/utils/transform-promise.js"() {
  31842. init_is_promise();
  31843. }
  31844. });
  31845. // node_modules/@e22m4u/js-repository/src/utils/select-object-keys.js
  31846. function selectObjectKeys(obj, keys) {
  31847. if (!obj || typeof obj !== "object" || Array.isArray(obj))
  31848. throw new InvalidArgumentError2(
  31849. "The first argument of selectObjectKeys should be an Object, but %v given.",
  31850. obj
  31851. );
  31852. if (!Array.isArray(keys))
  31853. throw new InvalidArgumentError2(
  31854. "The second argument of selectObjectKeys should be an Array of String, but %v given.",
  31855. keys
  31856. );
  31857. keys.forEach((key) => {
  31858. if (typeof key !== "string")
  31859. throw new InvalidArgumentError2(
  31860. "The second argument of selectObjectKeys should be an Array of String, but %v given.",
  31861. key
  31862. );
  31863. });
  31864. const result = {};
  31865. const allKeys = Object.keys(obj);
  31866. allKeys.forEach((key) => {
  31867. if (keys.includes(key)) result[key] = obj[key];
  31868. });
  31869. return result;
  31870. }
  31871. var init_select_object_keys = __esm({
  31872. "node_modules/@e22m4u/js-repository/src/utils/select-object-keys.js"() {
  31873. init_errors2();
  31874. }
  31875. });
  31876. // node_modules/@e22m4u/js-repository/src/utils/exclude-object-keys.js
  31877. function excludeObjectKeys(obj, keys) {
  31878. if (typeof obj !== "object" || !obj || Array.isArray(obj))
  31879. throw new InvalidArgumentError2(
  31880. "Cannot exclude keys from a non-Object value, %v given.",
  31881. obj
  31882. );
  31883. const result = { ...obj };
  31884. keys = Array.isArray(keys) ? keys : [keys];
  31885. keys.forEach((key) => delete result[key]);
  31886. return result;
  31887. }
  31888. var init_exclude_object_keys = __esm({
  31889. "node_modules/@e22m4u/js-repository/src/utils/exclude-object-keys.js"() {
  31890. init_errors2();
  31891. }
  31892. });
  31893. // node_modules/@e22m4u/js-repository/src/utils/get-decorator-target-type.js
  31894. var init_get_decorator_target_type = __esm({
  31895. "node_modules/@e22m4u/js-repository/src/utils/get-decorator-target-type.js"() {
  31896. }
  31897. });
  31898. // node_modules/@e22m4u/js-repository/src/utils/index.js
  31899. var init_utils2 = __esm({
  31900. "node_modules/@e22m4u/js-repository/src/utils/index.js"() {
  31901. init_is_ctor();
  31902. init_is_promise();
  31903. init_capitalize();
  31904. init_clone_deep();
  31905. init_singularize();
  31906. init_is_deep_equal();
  31907. init_get_ctor_name();
  31908. init_is_pure_object();
  31909. init_string_to_regexp();
  31910. init_get_value_by_path();
  31911. init_transform_promise();
  31912. init_select_object_keys();
  31913. init_exclude_object_keys();
  31914. init_get_decorator_target_type();
  31915. }
  31916. });
  31917. // node_modules/@e22m4u/js-repository/src/filter/order-clause-tool.js
  31918. function compareFn(a, b) {
  31919. let undefinedA, undefinedB;
  31920. for (let i = 0, l = this.length; i < l; i++) {
  31921. const aVal = getValueByPath(a, this[i].key);
  31922. const bVal = getValueByPath(b, this[i].key);
  31923. undefinedB = bVal === void 0 && aVal !== void 0;
  31924. undefinedA = aVal === void 0 && bVal !== void 0;
  31925. if (undefinedB || aVal > bVal) {
  31926. return this[i].reverse;
  31927. } else if (undefinedA || aVal < bVal) {
  31928. return -1 * this[i].reverse;
  31929. }
  31930. }
  31931. return 0;
  31932. }
  31933. var OrderClauseTool;
  31934. var init_order_clause_tool = __esm({
  31935. "node_modules/@e22m4u/js-repository/src/filter/order-clause-tool.js"() {
  31936. init_src2();
  31937. init_utils2();
  31938. init_errors2();
  31939. OrderClauseTool = class extends Service {
  31940. /**
  31941. * Sort.
  31942. *
  31943. * @param {object[]} entities
  31944. * @param {string|string[]|undefined} clause
  31945. */
  31946. sort(entities, clause) {
  31947. if (clause == null) return;
  31948. if (Array.isArray(clause) === false) clause = [clause];
  31949. if (!clause.length) return;
  31950. const mapping = [];
  31951. clause.forEach((key, index) => {
  31952. if (!key || typeof key !== "string")
  31953. throw new InvalidArgumentError2(
  31954. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  31955. key
  31956. );
  31957. let reverse = 1;
  31958. const matches = key.match(/\s+(A|DE)SC$/i);
  31959. if (matches) {
  31960. key = key.replace(/\s+(A|DE)SC/i, "");
  31961. if (matches[1].toLowerCase() === "de") reverse = -1;
  31962. }
  31963. mapping[index] = { key, reverse };
  31964. });
  31965. entities.sort(compareFn.bind(mapping));
  31966. }
  31967. /**
  31968. * Validate order clause.
  31969. *
  31970. * @param {string|string[]|undefined} clause
  31971. */
  31972. static validateOrderClause(clause) {
  31973. if (clause == null) return;
  31974. if (Array.isArray(clause) === false) clause = [clause];
  31975. if (!clause.length) return;
  31976. clause.forEach((field) => {
  31977. if (!field || typeof field !== "string")
  31978. throw new InvalidArgumentError2(
  31979. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  31980. field
  31981. );
  31982. });
  31983. }
  31984. /**
  31985. * Normalize order clause.
  31986. *
  31987. * @param {string|string[]|undefined} clause
  31988. * @returns {string[]|undefined}
  31989. */
  31990. static normalizeOrderClause(clause) {
  31991. if (clause == null) return;
  31992. if (Array.isArray(clause) === false) clause = [clause];
  31993. if (!clause.length) return;
  31994. clause.forEach((field) => {
  31995. if (!field || typeof field !== "string")
  31996. throw new InvalidArgumentError2(
  31997. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  31998. field
  31999. );
  32000. });
  32001. return clause;
  32002. }
  32003. };
  32004. }
  32005. });
  32006. // node_modules/@e22m4u/js-repository/src/filter/operator-clause-tool.js
  32007. var OperatorClauseTool;
  32008. var init_operator_clause_tool = __esm({
  32009. "node_modules/@e22m4u/js-repository/src/filter/operator-clause-tool.js"() {
  32010. init_src2();
  32011. init_utils2();
  32012. init_errors2();
  32013. init_errors2();
  32014. OperatorClauseTool = class extends Service {
  32015. /**
  32016. * Compare.
  32017. *
  32018. * @param {*} val1 The 1st value
  32019. * @param {*} val2 The 2nd value
  32020. * @returns {number} 0: =, positive: >, negative <
  32021. */
  32022. compare(val1, val2) {
  32023. if (val1 == null || val2 == null) {
  32024. return val1 == val2 ? 0 : NaN;
  32025. }
  32026. if (typeof val1 === "number") {
  32027. if (typeof val2 === "number" || typeof val2 === "string" || typeof val2 === "boolean") {
  32028. if (val1 === val2) return 0;
  32029. return val1 - Number(val2);
  32030. }
  32031. return NaN;
  32032. }
  32033. if (typeof val1 === "string") {
  32034. const isDigits = /^\d+$/.test(val1);
  32035. if (isDigits) return this.compare(Number(val1), val2);
  32036. try {
  32037. if (val1 > val2) return 1;
  32038. if (val1 < val2) return -1;
  32039. if (val1 == val2) return 0;
  32040. } catch (e) {
  32041. }
  32042. return NaN;
  32043. }
  32044. if (typeof val1 === "boolean") {
  32045. return Number(val1) - Number(val2);
  32046. }
  32047. return val1 === val2 ? 0 : NaN;
  32048. }
  32049. /**
  32050. * Test all operators.
  32051. *
  32052. * @param {object} clause
  32053. * @param {*} value
  32054. * @returns {boolean|undefined}
  32055. */
  32056. testAll(clause, value) {
  32057. if (!clause || typeof clause !== "object" || Array.isArray(clause))
  32058. throw new InvalidArgumentError2(
  32059. "The first argument of OperatorUtils.testAll should be an Object, but %v given.",
  32060. clause
  32061. );
  32062. const eqNeqTest = this.testEqNeq(clause, value);
  32063. if (eqNeqTest !== void 0) return eqNeqTest;
  32064. const gtLtTest = this.testGtLt(clause, value);
  32065. if (gtLtTest !== void 0) return gtLtTest;
  32066. const incTest = this.testInq(clause, value);
  32067. if (incTest !== void 0) return incTest;
  32068. const ninTest = this.testNin(clause, value);
  32069. if (ninTest !== void 0) return ninTest;
  32070. const betweenTest = this.testBetween(clause, value);
  32071. if (betweenTest !== void 0) return betweenTest;
  32072. const existsTest = this.testExists(clause, value);
  32073. if (existsTest !== void 0) return existsTest;
  32074. const likeTest = this.testLike(clause, value);
  32075. if (likeTest !== void 0) return likeTest;
  32076. const nlikeTest = this.testNlike(clause, value);
  32077. if (nlikeTest !== void 0) return nlikeTest;
  32078. const ilikeTest = this.testIlike(clause, value);
  32079. if (ilikeTest !== void 0) return ilikeTest;
  32080. const nilikeTest = this.testNilike(clause, value);
  32081. if (nilikeTest !== void 0) return nilikeTest;
  32082. const regExpTest = this.testRegexp(clause, value);
  32083. if (regExpTest !== void 0) return regExpTest;
  32084. }
  32085. /**
  32086. * Test eq/neq operator.
  32087. *
  32088. * @example
  32089. * ```ts
  32090. * {
  32091. * eq: 'foo',
  32092. * }
  32093. * ```
  32094. *
  32095. * @example
  32096. * ```ts
  32097. * {
  32098. * neq: 'foo',
  32099. * }
  32100. * ```
  32101. *
  32102. * @param {object} clause
  32103. * @param {*} value
  32104. * @returns {boolean|undefined}
  32105. */
  32106. testEqNeq(clause, value) {
  32107. if (!clause || typeof clause !== "object")
  32108. throw new InvalidArgumentError2(
  32109. "The first argument of OperatorUtils.testEqNeq should be an Object, but %v given.",
  32110. clause
  32111. );
  32112. if ("eq" in clause) return this.compare(clause.eq, value) === 0;
  32113. if ("neq" in clause) return this.compare(clause.neq, value) !== 0;
  32114. }
  32115. /**
  32116. * Test lt/gt/lte/gte operator.
  32117. *
  32118. * @example
  32119. * ```ts
  32120. * {
  32121. * lt: 10,
  32122. * }
  32123. * ```
  32124. *
  32125. * @example
  32126. * ```ts
  32127. * {
  32128. * lte: 10,
  32129. * }
  32130. * ```
  32131. *
  32132. * @example
  32133. * ```ts
  32134. * {
  32135. * gt: 10,
  32136. * }
  32137. * ```
  32138. *
  32139. * @example
  32140. * ```ts
  32141. * {
  32142. * gte: 10,
  32143. * }
  32144. * ```
  32145. *
  32146. * @param {object} clause
  32147. * @param {*} value
  32148. * @returns {boolean|undefined}
  32149. */
  32150. testGtLt(clause, value) {
  32151. if (!clause || typeof clause !== "object")
  32152. throw new InvalidArgumentError2(
  32153. "The first argument of OperatorUtils.testGtLt should be an Object, but %v given.",
  32154. clause
  32155. );
  32156. if ("gt" in clause) return this.compare(value, clause.gt) > 0;
  32157. if ("gte" in clause) return this.compare(value, clause.gte) >= 0;
  32158. if ("lt" in clause) return this.compare(value, clause.lt) < 0;
  32159. if ("lte" in clause) return this.compare(value, clause.lte) <= 0;
  32160. }
  32161. /**
  32162. * Test inc operator.
  32163. *
  32164. * @example
  32165. * ```ts
  32166. * {
  32167. * inc: ['foo', 'bar'],
  32168. * }
  32169. * ```
  32170. *
  32171. * @param {object} clause
  32172. * @param {*} value
  32173. * @returns {boolean|undefined}
  32174. */
  32175. testInq(clause, value) {
  32176. if (!clause || typeof clause !== "object")
  32177. throw new InvalidArgumentError2(
  32178. "The first argument of OperatorUtils.testInq should be an Object, but %v given.",
  32179. clause
  32180. );
  32181. if ("inq" in clause && clause.inq !== void 0) {
  32182. if (!clause.inq || !Array.isArray(clause.inq)) {
  32183. throw new InvalidOperatorValueError(
  32184. "inq",
  32185. "an Array of possible values",
  32186. clause.inq
  32187. );
  32188. }
  32189. for (let i = 0; i < clause.inq.length; i++) {
  32190. if (clause.inq[i] == value) return true;
  32191. }
  32192. return false;
  32193. }
  32194. }
  32195. /**
  32196. * Test nin operator.
  32197. *
  32198. * @example
  32199. * ```ts
  32200. * {
  32201. * nin: ['foo', 'bar'],
  32202. * }
  32203. * ```
  32204. *
  32205. * @param {object} clause
  32206. * @param {*} value
  32207. * @returns {boolean|undefined}
  32208. */
  32209. testNin(clause, value) {
  32210. if (!clause || typeof clause !== "object")
  32211. throw new InvalidArgumentError2(
  32212. "The first argument of OperatorUtils.testNin should be an Object, but %v given.",
  32213. clause
  32214. );
  32215. if ("nin" in clause && clause.nin !== void 0) {
  32216. if (!clause.nin || !Array.isArray(clause.nin)) {
  32217. throw new InvalidOperatorValueError(
  32218. "nin",
  32219. "an Array of possible values",
  32220. clause.nin
  32221. );
  32222. }
  32223. for (let i = 0; i < clause.nin.length; i++) {
  32224. if (clause.nin[i] == value) return false;
  32225. }
  32226. return true;
  32227. }
  32228. }
  32229. /**
  32230. * Test between operator.
  32231. *
  32232. * @example
  32233. * ```ts
  32234. * {
  32235. * between: [10, 20],
  32236. * }
  32237. * ```
  32238. *
  32239. * @param {object} clause
  32240. * @param {*} value
  32241. * @returns {boolean|undefined}
  32242. */
  32243. testBetween(clause, value) {
  32244. if (!clause || typeof clause !== "object")
  32245. throw new InvalidArgumentError2(
  32246. "The first argument of OperatorUtils.testBetween should be an Object, but %v given.",
  32247. clause
  32248. );
  32249. if ("between" in clause && clause.between !== void 0) {
  32250. if (!Array.isArray(clause.between) || clause.between.length !== 2) {
  32251. throw new InvalidOperatorValueError(
  32252. "between",
  32253. "an Array of 2 elements",
  32254. clause.between
  32255. );
  32256. }
  32257. return this.testGtLt({ gte: clause.between[0] }, value) && this.testGtLt({ lte: clause.between[1] }, value);
  32258. }
  32259. }
  32260. /**
  32261. * Test exists operator.
  32262. *
  32263. * @example
  32264. * ```ts
  32265. * {
  32266. * exists: true,
  32267. * }
  32268. * ```
  32269. *
  32270. * @param {object} clause
  32271. * @param {*} value
  32272. * @returns {boolean|undefined}
  32273. */
  32274. testExists(clause, value) {
  32275. if (!clause || typeof clause !== "object")
  32276. throw new InvalidArgumentError2(
  32277. "The first argument of OperatorUtils.testExists should be an Object, but %v given.",
  32278. clause
  32279. );
  32280. if ("exists" in clause && clause.exists !== void 0) {
  32281. if (typeof clause.exists !== "boolean") {
  32282. throw new InvalidOperatorValueError(
  32283. "exists",
  32284. "a Boolean",
  32285. clause.exists
  32286. );
  32287. }
  32288. return clause.exists ? value !== void 0 : value === void 0;
  32289. }
  32290. }
  32291. /**
  32292. * Test like operator.
  32293. *
  32294. * @example
  32295. * ```ts
  32296. * {
  32297. * like: 'foo',
  32298. * }
  32299. * ```
  32300. *
  32301. * @param {object} clause
  32302. * @param {*} value
  32303. * @returns {boolean|undefined}
  32304. */
  32305. testLike(clause, value) {
  32306. if (!clause || typeof clause !== "object")
  32307. throw new InvalidArgumentError2(
  32308. "The first argument of OperatorUtils.testLike should be an Object, but %v given.",
  32309. clause
  32310. );
  32311. if ("like" in clause && clause.like !== void 0) {
  32312. if (typeof clause.like !== "string" && !(clause.like instanceof RegExp))
  32313. throw new InvalidOperatorValueError("like", "a String", clause.like);
  32314. return stringToRegexp(clause.like).test(value);
  32315. }
  32316. }
  32317. /**
  32318. * Test nlike operator.
  32319. *
  32320. * @example
  32321. * ```ts
  32322. * {
  32323. * nlike: 'foo',
  32324. * }
  32325. * ```
  32326. *
  32327. * @param {object} clause
  32328. * @param {*} value
  32329. * @returns {boolean|undefined}
  32330. */
  32331. testNlike(clause, value) {
  32332. if (!clause || typeof clause !== "object")
  32333. throw new InvalidArgumentError2(
  32334. "The first argument of OperatorUtils.testNlike should be an Object, but %v given.",
  32335. clause
  32336. );
  32337. if ("nlike" in clause && clause.nlike !== void 0) {
  32338. if (typeof clause.nlike !== "string" && !(clause.nlike instanceof RegExp)) {
  32339. throw new InvalidOperatorValueError("nlike", "a String", clause.nlike);
  32340. }
  32341. return !stringToRegexp(clause.nlike).test(value);
  32342. }
  32343. }
  32344. /**
  32345. * Test ilike operator.
  32346. *
  32347. * @example
  32348. * ```ts
  32349. * {
  32350. * ilike: 'foo',
  32351. * }
  32352. * ```
  32353. *
  32354. * @param {object} clause
  32355. * @param {*} value
  32356. * @returns {boolean|undefined}
  32357. */
  32358. testIlike(clause, value) {
  32359. if (!clause || typeof clause !== "object")
  32360. throw new InvalidArgumentError2(
  32361. "The first argument of OperatorUtils.testIlike should be an Object, but %v given.",
  32362. clause
  32363. );
  32364. if ("ilike" in clause && clause.ilike !== void 0) {
  32365. if (typeof clause.ilike !== "string" && !(clause.ilike instanceof RegExp)) {
  32366. throw new InvalidOperatorValueError("ilike", "a String", clause.ilike);
  32367. }
  32368. return stringToRegexp(clause.ilike, "i").test(value);
  32369. }
  32370. }
  32371. /**
  32372. * Test nilike operator.
  32373. *
  32374. * @example
  32375. * ```ts
  32376. * {
  32377. * nilike: 'foo',
  32378. * }
  32379. * ```
  32380. *
  32381. * @param {object} clause
  32382. * @param {*} value
  32383. * @returns {boolean|undefined}
  32384. */
  32385. testNilike(clause, value) {
  32386. if (!clause || typeof clause !== "object")
  32387. throw new InvalidArgumentError2(
  32388. "The first argument of OperatorUtils.testNilike should be an Object, but %v given.",
  32389. clause
  32390. );
  32391. if ("nilike" in clause && clause.nilike !== void 0) {
  32392. if (typeof clause.nilike !== "string" && !(clause.nilike instanceof RegExp)) {
  32393. throw new InvalidOperatorValueError(
  32394. "nilike",
  32395. "a String",
  32396. clause.nilike
  32397. );
  32398. }
  32399. return !stringToRegexp(clause.nilike, "i").test(value);
  32400. }
  32401. }
  32402. /**
  32403. * Test regexp.
  32404. *
  32405. * @example
  32406. * ```ts
  32407. * {
  32408. * regexp: 'foo.*',
  32409. * }
  32410. * ```
  32411. *
  32412. * @example
  32413. * ```ts
  32414. * {
  32415. * regexp: 'foo.*',
  32416. * flags: 'i',
  32417. * }
  32418. * ```
  32419. *
  32420. * @param {object} clause
  32421. * @param {*} value
  32422. * @returns {boolean|undefined}
  32423. */
  32424. testRegexp(clause, value) {
  32425. if (!clause || typeof clause !== "object")
  32426. throw new InvalidArgumentError2(
  32427. "The first argument of OperatorUtils.testRegexp should be an Object, but %v given.",
  32428. clause
  32429. );
  32430. if ("regexp" in clause && clause.regexp !== void 0) {
  32431. if (typeof clause.regexp !== "string" && !(clause.regexp instanceof RegExp)) {
  32432. throw new InvalidOperatorValueError(
  32433. "regexp",
  32434. "a String",
  32435. clause.regexp
  32436. );
  32437. }
  32438. const flags = clause.flags || void 0;
  32439. if (flags && typeof flags !== "string")
  32440. throw new InvalidArgumentError2(
  32441. "RegExp flags should be a String, but %v given.",
  32442. clause.flags
  32443. );
  32444. if (!value || typeof value !== "string") return false;
  32445. const regExp = stringToRegexp(clause.regexp, flags);
  32446. return !!value.match(regExp);
  32447. }
  32448. }
  32449. };
  32450. }
  32451. });
  32452. // node_modules/@e22m4u/js-repository/src/filter/where-clause-tool.js
  32453. var WhereClauseTool;
  32454. var init_where_clause_tool = __esm({
  32455. "node_modules/@e22m4u/js-repository/src/filter/where-clause-tool.js"() {
  32456. init_src2();
  32457. init_utils2();
  32458. init_errors2();
  32459. init_operator_clause_tool();
  32460. WhereClauseTool = class extends Service {
  32461. /**
  32462. * Filter by where clause.
  32463. *
  32464. * @example
  32465. * ```
  32466. * const entities = [
  32467. * {foo: 1, bar: 'a'},
  32468. * {foo: 2, bar: 'b'},
  32469. * {foo: 3, bar: 'b'},
  32470. * {foo: 4, bar: 'b'},
  32471. * ];
  32472. *
  32473. * const result = filterByWhereClause(entities, {
  32474. * foo: {gt: 2},
  32475. * bar: 'b',
  32476. * });
  32477. *
  32478. * console.log(result);
  32479. * // [
  32480. * // {foo: 3, bar: 'b'},
  32481. * // {foo: 4, bar: 'b'},
  32482. * // ];
  32483. *
  32484. * ```
  32485. *
  32486. * @param {object[]} entities
  32487. * @param {WhereClause|undefined} where
  32488. * @returns {object[]}
  32489. */
  32490. filter(entities, where = void 0) {
  32491. if (!Array.isArray(entities))
  32492. throw new InvalidArgumentError2(
  32493. "The first argument of WhereClauseTool.filter should be an Array of Object, but %v given.",
  32494. entities
  32495. );
  32496. if (where == null) return entities;
  32497. return entities.filter(this._createFilter(where));
  32498. }
  32499. /**
  32500. * Create where filter.
  32501. *
  32502. * @param {WhereClause} whereClause
  32503. * @returns {Function}
  32504. */
  32505. _createFilter(whereClause) {
  32506. if (typeof whereClause !== "object" || Array.isArray(whereClause))
  32507. throw new InvalidArgumentError2(
  32508. 'The provided option "where" should be an Object, but %v given.',
  32509. whereClause
  32510. );
  32511. const keys = Object.keys(whereClause);
  32512. return (data) => {
  32513. if (typeof data !== "object")
  32514. throw new InvalidArgumentError2(
  32515. "The first argument of WhereClauseTool.filter should be an Array of Object, but %v given.",
  32516. data
  32517. );
  32518. return keys.every((key) => {
  32519. if (key === "and" && key in whereClause) {
  32520. const andClause = whereClause[key];
  32521. if (Array.isArray(andClause))
  32522. return andClause.every((clause) => this._createFilter(clause)(data));
  32523. } else if (key === "or" && key in whereClause) {
  32524. const orClause = whereClause[key];
  32525. if (Array.isArray(orClause))
  32526. return orClause.some((clause) => this._createFilter(clause)(data));
  32527. }
  32528. const value = getValueByPath(data, key);
  32529. const matcher = whereClause[key];
  32530. if (Array.isArray(value)) {
  32531. if (typeof matcher === "object" && matcher !== null && "neq" in matcher && matcher.neq !== void 0) {
  32532. if (value.length === 0) return true;
  32533. return value.every((el, index) => {
  32534. const where = {};
  32535. where[index] = matcher;
  32536. return this._createFilter(where)({ ...value });
  32537. });
  32538. }
  32539. return value.some((el, index) => {
  32540. const where = {};
  32541. where[index] = matcher;
  32542. return this._createFilter(where)({ ...value });
  32543. });
  32544. }
  32545. if (this._test(matcher, value)) return true;
  32546. });
  32547. };
  32548. }
  32549. /**
  32550. * Value testing.
  32551. *
  32552. * @param {*} example
  32553. * @param {*} value
  32554. * @returns {boolean}
  32555. */
  32556. _test(example, value) {
  32557. if (example === null) {
  32558. return value === null;
  32559. }
  32560. if (example === void 0) {
  32561. return value === void 0;
  32562. }
  32563. if (example instanceof RegExp) {
  32564. if (typeof value === "string") return !!value.match(example);
  32565. return false;
  32566. }
  32567. if (typeof example === "object") {
  32568. const operatorsTest = this.getService(OperatorClauseTool).testAll(
  32569. example,
  32570. value
  32571. );
  32572. if (operatorsTest !== void 0) return operatorsTest;
  32573. }
  32574. return example == value;
  32575. }
  32576. /**
  32577. * Validate where clause.
  32578. *
  32579. * @param {WhereClause|undefined} clause
  32580. */
  32581. static validateWhereClause(clause) {
  32582. if (clause == null || typeof clause === "function") return;
  32583. if (typeof clause !== "object" || Array.isArray(clause))
  32584. throw new InvalidArgumentError2(
  32585. 'The provided option "where" should be an Object, but %v given.',
  32586. clause
  32587. );
  32588. }
  32589. };
  32590. }
  32591. });
  32592. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-type.js
  32593. var RelationType;
  32594. var init_relation_type = __esm({
  32595. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-type.js"() {
  32596. RelationType = {
  32597. BELONGS_TO: "belongsTo",
  32598. HAS_ONE: "hasOne",
  32599. HAS_MANY: "hasMany",
  32600. REFERENCES_MANY: "referencesMany"
  32601. };
  32602. }
  32603. });
  32604. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-definition.js
  32605. var init_relation_definition = __esm({
  32606. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-definition.js"() {
  32607. }
  32608. });
  32609. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relations-definition-validator.js
  32610. var RelationsDefinitionValidator;
  32611. var init_relations_definition_validator = __esm({
  32612. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relations-definition-validator.js"() {
  32613. init_src2();
  32614. init_relation_type();
  32615. init_relation_type();
  32616. init_errors2();
  32617. RelationsDefinitionValidator = class extends Service {
  32618. /**
  32619. * Validate.
  32620. *
  32621. * @param {string} modelName
  32622. * @param {object} relDefs
  32623. */
  32624. validate(modelName, relDefs) {
  32625. if (!modelName || typeof modelName !== "string")
  32626. throw new InvalidArgumentError2(
  32627. "The first argument of RelationsDefinitionValidator.validate should be a non-empty String, but %v given.",
  32628. modelName
  32629. );
  32630. if (!relDefs || typeof relDefs !== "object" || Array.isArray(relDefs))
  32631. throw new InvalidArgumentError2(
  32632. 'The provided option "relations" of the model %v should be an Object, but %v given.',
  32633. modelName,
  32634. relDefs
  32635. );
  32636. const relNames = Object.keys(relDefs);
  32637. relNames.forEach((relName) => {
  32638. const relDef = relDefs[relName];
  32639. this._validateRelation(modelName, relName, relDef);
  32640. });
  32641. }
  32642. /**
  32643. * Validate relation.
  32644. *
  32645. * @param {string} modelName
  32646. * @param {string} relName
  32647. * @param {object} relDef
  32648. */
  32649. _validateRelation(modelName, relName, relDef) {
  32650. if (!modelName || typeof modelName !== "string")
  32651. throw new InvalidArgumentError2(
  32652. "The first argument of RelationsDefinitionValidator._validateRelation should be a non-empty String, but %v given.",
  32653. modelName
  32654. );
  32655. if (!relName || typeof relName !== "string")
  32656. throw new InvalidArgumentError2(
  32657. "The relation name of the model %v should be a non-empty String, but %v given.",
  32658. modelName,
  32659. relName
  32660. );
  32661. if (!relDef || typeof relDef !== "object" || Array.isArray(relDef))
  32662. throw new InvalidArgumentError2(
  32663. "The relation %v of the model %v should be an Object, but %v given.",
  32664. relName,
  32665. modelName,
  32666. relDef
  32667. );
  32668. if (!relDef.type || !Object.values(RelationType).includes(relDef.type))
  32669. throw new InvalidArgumentError2(
  32670. 'The relation %v of the model %v requires the option "type" to have one of relation types: %l, but %v given.',
  32671. relName,
  32672. modelName,
  32673. Object.values(RelationType),
  32674. relDef.type
  32675. );
  32676. this._validateBelongsTo(modelName, relName, relDef);
  32677. this._validateHasOne(modelName, relName, relDef);
  32678. this._validateHasMany(modelName, relName, relDef);
  32679. this._validateReferencesMany(modelName, relName, relDef);
  32680. }
  32681. /**
  32682. * Validate "belongsTo".
  32683. *
  32684. * @example The regular "belongsTo" relation.
  32685. * ```
  32686. * {
  32687. * type: RelationType.BELONGS_TO,
  32688. * model: 'model',
  32689. * foreignKey: 'modelId', // optional
  32690. * }
  32691. * ```
  32692. *
  32693. * @example The polymorphic "belongsTo" relation.
  32694. * ```
  32695. * {
  32696. * type: RelationType.BELONGS_TO,
  32697. * polymorphic: true,
  32698. * foreignKey: 'referenceId', // optional
  32699. * discriminator: 'referenceType', // optional
  32700. * }
  32701. * ```
  32702. *
  32703. * @param {string} modelName
  32704. * @param {string} relName
  32705. * @param {object} relDef
  32706. * @private
  32707. */
  32708. _validateBelongsTo(modelName, relName, relDef) {
  32709. if (relDef.type !== RelationType.BELONGS_TO) return;
  32710. if (relDef.polymorphic) {
  32711. if (typeof relDef.polymorphic !== "boolean")
  32712. throw new InvalidArgumentError2(
  32713. 'The relation %v of the model %v has the type "belongsTo", so it expects the option "polymorphic" to be a Boolean, but %v given.',
  32714. relName,
  32715. modelName,
  32716. relDef.polymorphic
  32717. );
  32718. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32719. throw new InvalidArgumentError2(
  32720. 'The relation %v of the model %v is a polymorphic "belongsTo" relation, so it expects the provided option "foreignKey" to be a String, but %v given.',
  32721. relName,
  32722. modelName,
  32723. relDef.foreignKey
  32724. );
  32725. if (relDef.discriminator && typeof relDef.discriminator !== "string")
  32726. throw new InvalidArgumentError2(
  32727. 'The relation %v of the model %v is a polymorphic "belongsTo" relation, so it expects the provided option "discriminator" to be a String, but %v given.',
  32728. relName,
  32729. modelName,
  32730. relDef.discriminator
  32731. );
  32732. } else {
  32733. if (!relDef.model || typeof relDef.model !== "string")
  32734. throw new InvalidArgumentError2(
  32735. 'The relation %v of the model %v has the type "belongsTo", so it requires the option "model" to be a non-empty String, but %v given.',
  32736. relName,
  32737. modelName,
  32738. relDef.model
  32739. );
  32740. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32741. throw new InvalidArgumentError2(
  32742. 'The relation %v of the model %v has the type "belongsTo", so it expects the provided option "foreignKey" to be a String, but %v given.',
  32743. relName,
  32744. modelName,
  32745. relDef.foreignKey
  32746. );
  32747. if (relDef.discriminator)
  32748. throw new InvalidArgumentError2(
  32749. 'The relation %v of the model %v is a non-polymorphic "belongsTo" relation, so it should not have the option "discriminator" to be provided.',
  32750. relName,
  32751. modelName
  32752. );
  32753. }
  32754. }
  32755. /**
  32756. * Validate "hasOne".
  32757. *
  32758. * @example The regular "hasOne" relation.
  32759. * ```
  32760. * {
  32761. * type: RelationType.HAS_ONE,
  32762. * model: 'model',
  32763. * foreignKey: 'modelId',
  32764. * }
  32765. * ```
  32766. *
  32767. * @example The polymorphic "hasOne" relation with a target relation name.
  32768. * ```
  32769. * {
  32770. * type: RelationType.HAS_ONE,
  32771. * model: 'model',
  32772. * polymorphic: 'reference',
  32773. * }
  32774. * ```
  32775. *
  32776. * @example The polymorphic "hasOne" relation with target relation keys.
  32777. * ```
  32778. * {
  32779. * type: RelationType.HAS_ONE,
  32780. * model: 'model',
  32781. * polymorphic: true,
  32782. * foreignKey: 'referenceId',
  32783. * discriminator: 'referenceType',
  32784. * }
  32785. * ```
  32786. *
  32787. * @param {string} modelName
  32788. * @param {string} relName
  32789. * @param {object} relDef
  32790. * @private
  32791. */
  32792. _validateHasOne(modelName, relName, relDef) {
  32793. if (relDef.type !== RelationType.HAS_ONE) return;
  32794. if (!relDef.model || typeof relDef.model !== "string")
  32795. throw new InvalidArgumentError2(
  32796. 'The relation %v of the model %v has the type "hasOne", so it requires the option "model" to be a non-empty String, but %v given.',
  32797. relName,
  32798. modelName,
  32799. relDef.model
  32800. );
  32801. if (relDef.polymorphic) {
  32802. if (typeof relDef.polymorphic === "string") {
  32803. if (relDef.foreignKey)
  32804. throw new InvalidArgumentError2(
  32805. 'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "foreignKey" to be provided.',
  32806. relName,
  32807. modelName
  32808. );
  32809. if (relDef.discriminator)
  32810. throw new InvalidArgumentError2(
  32811. 'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "discriminator" to be provided.',
  32812. relName,
  32813. modelName
  32814. );
  32815. } else if (typeof relDef.polymorphic === "boolean") {
  32816. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32817. throw new InvalidArgumentError2(
  32818. 'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "foreignKey" to be a non-empty String, but %v given.',
  32819. relName,
  32820. modelName,
  32821. relDef.foreignKey
  32822. );
  32823. if (!relDef.discriminator || typeof relDef.discriminator !== "string")
  32824. throw new InvalidArgumentError2(
  32825. 'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "discriminator" to be a non-empty String, but %v given.',
  32826. relName,
  32827. modelName,
  32828. relDef.discriminator
  32829. );
  32830. } else {
  32831. throw new InvalidArgumentError2(
  32832. 'The relation %v of the model %v has the type "hasOne", so it expects the provided option "polymorphic" to be a String or a Boolean, but %v given.',
  32833. relName,
  32834. modelName,
  32835. relDef.polymorphic
  32836. );
  32837. }
  32838. } else {
  32839. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32840. throw new InvalidArgumentError2(
  32841. 'The relation %v of the model %v has the type "hasOne", so it requires the option "foreignKey" to be a non-empty String, but %v given.',
  32842. relName,
  32843. modelName,
  32844. relDef.foreignKey
  32845. );
  32846. if (relDef.discriminator)
  32847. throw new InvalidArgumentError2(
  32848. 'The relation %v of the model %v is a non-polymorphic "hasOne" relation, so it should not have the option "discriminator" to be provided.',
  32849. relName,
  32850. modelName
  32851. );
  32852. }
  32853. }
  32854. /**
  32855. * Validate "hasMany".
  32856. *
  32857. * @example The regular "hasMany" relation.
  32858. * ```
  32859. * {
  32860. * type: RelationType.HAS_MANY,
  32861. * model: 'model',
  32862. * foreignKey: 'modelId',
  32863. * }
  32864. * ```
  32865. *
  32866. * @example The polymorphic "hasMany" relation with a target relation name.
  32867. * ```
  32868. * {
  32869. * type: RelationType.HAS_MANY,
  32870. * model: 'model',
  32871. * polymorphic: 'reference',
  32872. * }
  32873. * ```
  32874. *
  32875. * @example The polymorphic "hasMany" relation with target relation keys.
  32876. * ```
  32877. * {
  32878. * type: RelationType.HAS_MANY,
  32879. * model: 'model',
  32880. * polymorphic: true,
  32881. * foreignKey: 'referenceId',
  32882. * discriminator: 'referenceType',
  32883. * }
  32884. * ```
  32885. *
  32886. * @param {string} modelName
  32887. * @param {string} relName
  32888. * @param {object} relDef
  32889. * @private
  32890. */
  32891. _validateHasMany(modelName, relName, relDef) {
  32892. if (relDef.type !== RelationType.HAS_MANY) return;
  32893. if (!relDef.model || typeof relDef.model !== "string")
  32894. throw new InvalidArgumentError2(
  32895. 'The relation %v of the model %v has the type "hasMany", so it requires the option "model" to be a non-empty String, but %v given.',
  32896. relName,
  32897. modelName,
  32898. relDef.model
  32899. );
  32900. if (relDef.polymorphic) {
  32901. if (typeof relDef.polymorphic === "string") {
  32902. if (relDef.foreignKey)
  32903. throw new InvalidArgumentError2(
  32904. 'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "foreignKey" to be provided.',
  32905. relName,
  32906. modelName
  32907. );
  32908. if (relDef.discriminator)
  32909. throw new InvalidArgumentError2(
  32910. 'The relation %v of the model %v has the option "polymorphic" with a String value, so it should not have the option "discriminator" to be provided.',
  32911. relName,
  32912. modelName
  32913. );
  32914. } else if (typeof relDef.polymorphic === "boolean") {
  32915. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32916. throw new InvalidArgumentError2(
  32917. 'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "foreignKey" to be a non-empty String, but %v given.',
  32918. relName,
  32919. modelName,
  32920. relDef.foreignKey
  32921. );
  32922. if (!relDef.discriminator || typeof relDef.discriminator !== "string")
  32923. throw new InvalidArgumentError2(
  32924. 'The relation %v of the model %v has the option "polymorphic" with "true" value, so it requires the option "discriminator" to be a non-empty String, but %v given.',
  32925. relName,
  32926. modelName,
  32927. relDef.discriminator
  32928. );
  32929. } else {
  32930. throw new InvalidArgumentError2(
  32931. 'The relation %v of the model %v has the type "hasMany", so it expects the provided option "polymorphic" to be a String or a Boolean, but %v given.',
  32932. relName,
  32933. modelName,
  32934. relDef.polymorphic
  32935. );
  32936. }
  32937. } else {
  32938. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32939. throw new InvalidArgumentError2(
  32940. 'The relation %v of the model %v has the type "hasMany", so it requires the option "foreignKey" to be a non-empty String, but %v given.',
  32941. relName,
  32942. modelName,
  32943. relDef.foreignKey
  32944. );
  32945. if (relDef.discriminator)
  32946. throw new InvalidArgumentError2(
  32947. 'The relation %v of the model %v is a non-polymorphic "hasMany" relation, so it should not have the option "discriminator" to be provided.',
  32948. relName,
  32949. modelName
  32950. );
  32951. }
  32952. }
  32953. /**
  32954. * Validate "referencesMany".
  32955. *
  32956. * @example
  32957. * ```
  32958. * {
  32959. * type: RelationType.REFERENCES_MANY,
  32960. * model: 'model',
  32961. * foreignKey: 'modelIds', // optional
  32962. * }
  32963. * ```
  32964. *
  32965. * @param {string} modelName
  32966. * @param {string} relName
  32967. * @param {object} relDef
  32968. * @private
  32969. */
  32970. _validateReferencesMany(modelName, relName, relDef) {
  32971. if (relDef.type !== RelationType.REFERENCES_MANY) return;
  32972. if (!relDef.model || typeof relDef.model !== "string")
  32973. throw new InvalidArgumentError2(
  32974. 'The relation %v of the model %v has the type "referencesMany", so it requires the option "model" to be a non-empty String, but %v given.',
  32975. relName,
  32976. modelName,
  32977. relDef.model
  32978. );
  32979. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32980. throw new InvalidArgumentError2(
  32981. 'The relation %v of the model %v has the type "referencesMany", so it expects the provided option "foreignKey" to be a String, but %v given.',
  32982. relName,
  32983. modelName,
  32984. relDef.foreignKey
  32985. );
  32986. if (relDef.discriminator)
  32987. throw new InvalidArgumentError2(
  32988. 'The relation %v of the model %v has the type "referencesMany", so it should not have the option "discriminator" to be provided.',
  32989. relName,
  32990. modelName
  32991. );
  32992. }
  32993. };
  32994. }
  32995. });
  32996. // node_modules/@e22m4u/js-repository/src/definition/model/relations/index.js
  32997. var init_relations = __esm({
  32998. "node_modules/@e22m4u/js-repository/src/definition/model/relations/index.js"() {
  32999. init_relation_type();
  33000. init_relation_definition();
  33001. init_relations_definition_validator();
  33002. }
  33003. });
  33004. // node_modules/@e22m4u/js-repository/src/definition/model/properties/data-type.js
  33005. var DataType;
  33006. var init_data_type = __esm({
  33007. "node_modules/@e22m4u/js-repository/src/definition/model/properties/data-type.js"() {
  33008. DataType = {
  33009. ANY: "any",
  33010. STRING: "string",
  33011. NUMBER: "number",
  33012. BOOLEAN: "boolean",
  33013. ARRAY: "array",
  33014. OBJECT: "object"
  33015. };
  33016. }
  33017. });
  33018. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-definition.js
  33019. var init_property_definition = __esm({
  33020. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-definition.js"() {
  33021. }
  33022. });
  33023. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness.js
  33024. var PropertyUniqueness;
  33025. var init_property_uniqueness = __esm({
  33026. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness.js"() {
  33027. PropertyUniqueness = {
  33028. STRICT: "strict",
  33029. SPARSE: "sparse",
  33030. NON_UNIQUE: "nonUnique"
  33031. };
  33032. }
  33033. });
  33034. // node_modules/@e22m4u/js-repository/src/definition/model/properties/empty-values-definer.js
  33035. var EmptyValuesDefiner;
  33036. var init_empty_values_definer = __esm({
  33037. "node_modules/@e22m4u/js-repository/src/definition/model/properties/empty-values-definer.js"() {
  33038. init_data_type();
  33039. init_src2();
  33040. init_utils2();
  33041. init_errors2();
  33042. EmptyValuesDefiner = class extends Service {
  33043. /**
  33044. * Empty values map.
  33045. *
  33046. * @type {Map<string, *[]>}
  33047. */
  33048. _emptyValuesMap = /* @__PURE__ */ new Map([
  33049. [DataType.ANY, [void 0, null]],
  33050. [DataType.STRING, [void 0, null, ""]],
  33051. [DataType.NUMBER, [void 0, null, 0]],
  33052. [DataType.BOOLEAN, [void 0, null]],
  33053. [DataType.ARRAY, [void 0, null, []]],
  33054. [DataType.OBJECT, [void 0, null, {}]]
  33055. ]);
  33056. /**
  33057. * Set empty values of data type.
  33058. *
  33059. * @param {string} dataType
  33060. * @param {*[]} emptyValues
  33061. * @returns {EmptyValuesDefiner}
  33062. */
  33063. setEmptyValuesOf(dataType, emptyValues) {
  33064. if (!Object.values(DataType).includes(dataType))
  33065. throw new InvalidArgumentError2(
  33066. 'The argument "dataType" of the EmptyValuesDefiner.setEmptyValuesOf must be one of data types: %l, but %v given.',
  33067. Object.values(DataType),
  33068. dataType
  33069. );
  33070. if (!Array.isArray(emptyValues))
  33071. throw new InvalidArgumentError2(
  33072. 'The argument "emptyValues" of the EmptyValuesDefiner.setEmptyValuesOf must be an Array, but %v given.',
  33073. emptyValues
  33074. );
  33075. this._emptyValuesMap.set(dataType, emptyValues);
  33076. return this;
  33077. }
  33078. /**
  33079. * Is empty.
  33080. *
  33081. * @param {string} dataType
  33082. * @param {*} value
  33083. * @returns {boolean}
  33084. */
  33085. isEmpty(dataType, value) {
  33086. if (!Object.values(DataType).includes(dataType))
  33087. throw new InvalidArgumentError2(
  33088. 'The argument "dataType" of the EmptyValuesDefiner.isEmpty must be one of data types: %l, but %v given.',
  33089. Object.values(DataType),
  33090. dataType
  33091. );
  33092. return this._emptyValuesMap.get(dataType).some((v) => isDeepEqual(v, value));
  33093. }
  33094. };
  33095. }
  33096. });
  33097. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator.js
  33098. var init_property_validator = __esm({
  33099. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator.js"() {
  33100. }
  33101. });
  33102. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/regexp-validator.js
  33103. function regexpValidator(value, options, context) {
  33104. if (value == null || options === false) return true;
  33105. if (typeof options !== "string" && !(options instanceof RegExp))
  33106. throw new InvalidArgumentError2(
  33107. 'The validator %v requires the "options" argument as a String or RegExp, but %v given.',
  33108. context.validatorName,
  33109. options
  33110. );
  33111. if (typeof value === "string") {
  33112. const regexp = stringToRegexp(options);
  33113. return regexp.test(value);
  33114. }
  33115. throw new InvalidArgumentError2(
  33116. "The property validator %v requires a String value, but %v given.",
  33117. context.validatorName,
  33118. value
  33119. );
  33120. }
  33121. var init_regexp_validator = __esm({
  33122. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/regexp-validator.js"() {
  33123. init_utils2();
  33124. init_errors2();
  33125. }
  33126. });
  33127. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/max-length-validator.js
  33128. function maxLengthValidator(value, options, context) {
  33129. if (value == null || options === false) return true;
  33130. if (typeof options !== "number")
  33131. throw new InvalidArgumentError2(
  33132. 'The validator %v requires the "options" argument as a Number, but %v given.',
  33133. context.validatorName,
  33134. options
  33135. );
  33136. if (typeof value === "string" || Array.isArray(value))
  33137. return value.length <= options;
  33138. throw new InvalidArgumentError2(
  33139. "The property validator %v requires a String or an Array value, but %v given.",
  33140. context.validatorName,
  33141. value
  33142. );
  33143. }
  33144. var init_max_length_validator = __esm({
  33145. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/max-length-validator.js"() {
  33146. init_errors2();
  33147. }
  33148. });
  33149. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/min-length-validator.js
  33150. function minLengthValidator(value, options, context) {
  33151. if (value == null || options === false) return true;
  33152. if (typeof options !== "number")
  33153. throw new InvalidArgumentError2(
  33154. 'The validator %v requires the "options" argument as a Number, but %v given.',
  33155. context.validatorName,
  33156. options
  33157. );
  33158. if (typeof value === "string" || Array.isArray(value))
  33159. return value.length >= options;
  33160. throw new InvalidArgumentError2(
  33161. "The property validator %v requires a String or an Array value, but %v given.",
  33162. context.validatorName,
  33163. value
  33164. );
  33165. }
  33166. var init_min_length_validator = __esm({
  33167. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/min-length-validator.js"() {
  33168. init_errors2();
  33169. }
  33170. });
  33171. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/index.js
  33172. var init_builtin = __esm({
  33173. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/index.js"() {
  33174. init_regexp_validator();
  33175. init_max_length_validator();
  33176. init_min_length_validator();
  33177. }
  33178. });
  33179. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator-registry.js
  33180. var PropertyValidatorRegistry;
  33181. var init_property_validator_registry = __esm({
  33182. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator-registry.js"() {
  33183. init_src2();
  33184. init_builtin();
  33185. init_builtin();
  33186. init_builtin();
  33187. init_errors2();
  33188. PropertyValidatorRegistry = class extends Service {
  33189. /**
  33190. * Validators.
  33191. *
  33192. * @type {object}
  33193. */
  33194. _validators = {
  33195. maxLength: maxLengthValidator,
  33196. minLength: minLengthValidator,
  33197. regexp: regexpValidator
  33198. };
  33199. /**
  33200. * Add validator.
  33201. *
  33202. * @param {string} name
  33203. * @param {Function} validator
  33204. * @returns {PropertyValidatorRegistry}
  33205. */
  33206. addValidator(name, validator) {
  33207. if (!name || typeof name !== "string")
  33208. throw new InvalidArgumentError2(
  33209. "A name of the property validator must be a non-empty String, but %v given.",
  33210. name
  33211. );
  33212. if (name in this._validators)
  33213. throw new InvalidArgumentError2(
  33214. "The property validator %v is already defined.",
  33215. name
  33216. );
  33217. if (typeof validator !== "function")
  33218. throw new InvalidArgumentError2(
  33219. "The property validator %v must be a Function, but %v given.",
  33220. name,
  33221. validator
  33222. );
  33223. this._validators[name] = validator;
  33224. return this;
  33225. }
  33226. /**
  33227. * Has validator.
  33228. *
  33229. * @param {string} name
  33230. * @returns {boolean}
  33231. */
  33232. hasValidator(name) {
  33233. return Boolean(this._validators[name]);
  33234. }
  33235. /**
  33236. * Get validator.
  33237. *
  33238. * @param {string} name
  33239. * @returns {Function}
  33240. */
  33241. getValidator(name) {
  33242. const validator = this._validators[name];
  33243. if (!validator)
  33244. throw new InvalidArgumentError2(
  33245. "The property validator %v is not defined.",
  33246. name
  33247. );
  33248. return validator;
  33249. }
  33250. };
  33251. }
  33252. });
  33253. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/index.js
  33254. var init_property_validator2 = __esm({
  33255. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/index.js"() {
  33256. init_property_validator();
  33257. init_property_validator_registry();
  33258. }
  33259. });
  33260. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer.js
  33261. var init_property_transformer = __esm({
  33262. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer.js"() {
  33263. }
  33264. });
  33265. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/trim-transformer.js
  33266. function trimTransformer(value, options, context) {
  33267. if (value == null) return value;
  33268. if (typeof value === "string") return value.trim();
  33269. throw new InvalidArgumentError2(
  33270. "The property transformer %v requires a String value, but %v given.",
  33271. context.transformerName,
  33272. value
  33273. );
  33274. }
  33275. var init_trim_transformer = __esm({
  33276. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/trim-transformer.js"() {
  33277. init_errors2();
  33278. }
  33279. });
  33280. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js
  33281. function toLowerCaseTransformer(value, options, context) {
  33282. if (value == null) return value;
  33283. if (typeof value === "string") return value.toLowerCase();
  33284. throw new InvalidArgumentError2(
  33285. "The property transformer %v requires a String value, but %v given.",
  33286. context.transformerName,
  33287. value
  33288. );
  33289. }
  33290. var init_to_lower_case_transformer = __esm({
  33291. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js"() {
  33292. init_errors2();
  33293. }
  33294. });
  33295. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js
  33296. function toUpperCaseTransformer(value, options, context) {
  33297. if (value == null) return value;
  33298. if (typeof value === "string") return value.toUpperCase();
  33299. throw new InvalidArgumentError2(
  33300. "The property transformer %v requires a String value, but %v given.",
  33301. context.transformerName,
  33302. value
  33303. );
  33304. }
  33305. var init_to_upper_case_transformer = __esm({
  33306. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js"() {
  33307. init_errors2();
  33308. }
  33309. });
  33310. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.js
  33311. function toTitleCaseTransformer(value, options, context) {
  33312. if (value == null) return value;
  33313. if (typeof value === "string")
  33314. return value.replace(new RegExp("\\p{L}\\S*", "gu"), (text) => {
  33315. return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase();
  33316. });
  33317. throw new InvalidArgumentError2(
  33318. "The property transformer %v requires a String value, but %v given.",
  33319. context.transformerName,
  33320. value
  33321. );
  33322. }
  33323. var init_to_title_case_transformer = __esm({
  33324. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.js"() {
  33325. init_errors2();
  33326. }
  33327. });
  33328. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/index.js
  33329. var init_builtin2 = __esm({
  33330. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/index.js"() {
  33331. init_trim_transformer();
  33332. init_to_lower_case_transformer();
  33333. init_to_upper_case_transformer();
  33334. init_to_title_case_transformer();
  33335. }
  33336. });
  33337. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer-registry.js
  33338. var PropertyTransformerRegistry;
  33339. var init_property_transformer_registry = __esm({
  33340. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer-registry.js"() {
  33341. init_src2();
  33342. init_builtin2();
  33343. init_builtin2();
  33344. init_builtin2();
  33345. init_builtin2();
  33346. init_errors2();
  33347. PropertyTransformerRegistry = class extends Service {
  33348. /**
  33349. * Transformers.
  33350. *
  33351. * @type {object}
  33352. */
  33353. _transformers = {
  33354. trim: trimTransformer,
  33355. toUpperCase: toUpperCaseTransformer,
  33356. toLowerCase: toLowerCaseTransformer,
  33357. toTitleCase: toTitleCaseTransformer
  33358. };
  33359. /**
  33360. * Add transformer.
  33361. *
  33362. * @param {string} name
  33363. * @param {Function} transformer
  33364. * @returns {PropertyTransformerRegistry}
  33365. */
  33366. addTransformer(name, transformer) {
  33367. if (!name || typeof name !== "string")
  33368. throw new InvalidArgumentError2(
  33369. "A name of the property transformer must be a non-empty String, but %v given.",
  33370. name
  33371. );
  33372. if (name in this._transformers)
  33373. throw new InvalidArgumentError2(
  33374. "The property transformer %v is already defined.",
  33375. name
  33376. );
  33377. if (typeof transformer !== "function")
  33378. throw new InvalidArgumentError2(
  33379. "The property transformer %v must be a Function, but %v given.",
  33380. name,
  33381. transformer
  33382. );
  33383. this._transformers[name] = transformer;
  33384. return this;
  33385. }
  33386. /**
  33387. * Has transformer.
  33388. *
  33389. * @param {string} name
  33390. * @returns {boolean}
  33391. */
  33392. hasTransformer(name) {
  33393. return Boolean(this._transformers[name]);
  33394. }
  33395. /**
  33396. * Get transformer.
  33397. *
  33398. * @param {string} name
  33399. * @returns {Function}
  33400. */
  33401. getTransformer(name) {
  33402. const transformer = this._transformers[name];
  33403. if (!transformer)
  33404. throw new InvalidArgumentError2(
  33405. "The property transformer %v is not defined.",
  33406. name
  33407. );
  33408. return transformer;
  33409. }
  33410. };
  33411. }
  33412. });
  33413. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/index.js
  33414. var init_property_transformer2 = __esm({
  33415. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/index.js"() {
  33416. init_property_transformer();
  33417. init_property_transformer_registry();
  33418. }
  33419. });
  33420. // node_modules/@e22m4u/js-repository/src/definition/definition-registry.js
  33421. var DefinitionRegistry;
  33422. var init_definition_registry = __esm({
  33423. "node_modules/@e22m4u/js-repository/src/definition/definition-registry.js"() {
  33424. init_src2();
  33425. init_errors2();
  33426. init_model();
  33427. init_definition();
  33428. DefinitionRegistry = class extends Service {
  33429. /**
  33430. * Datasources.
  33431. *
  33432. * @type {object}
  33433. */
  33434. _datasources = {};
  33435. /**
  33436. * Models.
  33437. *
  33438. * @type {object}
  33439. */
  33440. _models = {};
  33441. /**
  33442. * Add datasource.
  33443. *
  33444. * @param {object} datasourceDef
  33445. */
  33446. addDatasource(datasourceDef) {
  33447. this.getService(DatasourceDefinitionValidator).validate(datasourceDef);
  33448. const name = datasourceDef.name;
  33449. if (name in this._datasources)
  33450. throw new InvalidArgumentError2(
  33451. "The datasource %v is already defined.",
  33452. name
  33453. );
  33454. this._datasources[name] = datasourceDef;
  33455. }
  33456. /**
  33457. * Has datasource.
  33458. *
  33459. * @param {string} name
  33460. * @returns {boolean}
  33461. */
  33462. hasDatasource(name) {
  33463. return Boolean(this._datasources[name]);
  33464. }
  33465. /**
  33466. * Get datasource.
  33467. *
  33468. * @param {string} name
  33469. * @returns {object}
  33470. */
  33471. getDatasource(name) {
  33472. const datasourceDef = this._datasources[name];
  33473. if (!datasourceDef)
  33474. throw new InvalidArgumentError2("The datasource %v is not defined.", name);
  33475. return datasourceDef;
  33476. }
  33477. /**
  33478. * Add model.
  33479. *
  33480. * @param {object} modelDef
  33481. */
  33482. addModel(modelDef) {
  33483. this.getService(ModelDefinitionValidator).validate(modelDef);
  33484. const name = modelDef.name;
  33485. if (name in this._models)
  33486. throw new InvalidArgumentError2("The model %v is already defined.", name);
  33487. this._models[name] = modelDef;
  33488. }
  33489. /**
  33490. * Has model.
  33491. *
  33492. * @param {string} name
  33493. * @returns {boolean}
  33494. */
  33495. hasModel(name) {
  33496. return Boolean(this._models[name]);
  33497. }
  33498. /**
  33499. * Get model.
  33500. *
  33501. * @param {string} name
  33502. * @returns {object}
  33503. */
  33504. getModel(name) {
  33505. const modelDef = this._models[name];
  33506. if (!modelDef)
  33507. throw new InvalidArgumentError2("The model %v is not defined.", name);
  33508. return modelDef;
  33509. }
  33510. };
  33511. }
  33512. });
  33513. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition-utils.js
  33514. var DEFAULT_PRIMARY_KEY_PROPERTY_NAME, ModelDefinitionUtils;
  33515. var init_model_definition_utils = __esm({
  33516. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition-utils.js"() {
  33517. init_src2();
  33518. init_properties();
  33519. init_utils2();
  33520. init_utils2();
  33521. init_properties();
  33522. init_errors2();
  33523. init_definition_registry();
  33524. DEFAULT_PRIMARY_KEY_PROPERTY_NAME = "id";
  33525. ModelDefinitionUtils = class extends Service {
  33526. /**
  33527. * Get primary key as property name.
  33528. *
  33529. * @param {string} modelName
  33530. * @returns {string}
  33531. */
  33532. getPrimaryKeyAsPropertyName(modelName) {
  33533. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33534. const propNames = Object.keys(propDefs).filter((propName) => {
  33535. const propDef = propDefs[propName];
  33536. return propDef && typeof propDef === "object" && propDef.primaryKey;
  33537. });
  33538. if (propNames.length < 1) {
  33539. const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(
  33540. DEFAULT_PRIMARY_KEY_PROPERTY_NAME
  33541. );
  33542. if (isDefaultPrimaryKeyAlreadyInUse)
  33543. throw new InvalidArgumentError2(
  33544. 'The property name %v of the model %v is defined as a regular property. In this case, a primary key should be defined explicitly. Do use the option "primaryKey" to specify the primary key.',
  33545. DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
  33546. modelName
  33547. );
  33548. return DEFAULT_PRIMARY_KEY_PROPERTY_NAME;
  33549. }
  33550. return propNames[0];
  33551. }
  33552. /**
  33553. * Get primary key as column name.
  33554. *
  33555. * @param {string} modelName
  33556. * @returns {string}
  33557. */
  33558. getPrimaryKeyAsColumnName(modelName) {
  33559. const pkPropName = this.getPrimaryKeyAsPropertyName(modelName);
  33560. let pkColName;
  33561. try {
  33562. pkColName = this.getColumnNameByPropertyName(modelName, pkPropName);
  33563. } catch (error) {
  33564. if (!(error instanceof InvalidArgumentError2)) throw error;
  33565. }
  33566. if (pkColName === void 0) return pkPropName;
  33567. return pkColName;
  33568. }
  33569. /**
  33570. * Get table name by model name.
  33571. *
  33572. * @param {string} modelName
  33573. * @returns {string}
  33574. */
  33575. getTableNameByModelName(modelName) {
  33576. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33577. return modelDef.tableName ?? modelName;
  33578. }
  33579. /**
  33580. * Get column name by property name.
  33581. *
  33582. * @param {string} modelName
  33583. * @param {string} propertyName
  33584. * @returns {string}
  33585. */
  33586. getColumnNameByPropertyName(modelName, propertyName) {
  33587. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33588. const propDef = propDefs[propertyName];
  33589. if (!propDef)
  33590. throw new InvalidArgumentError2(
  33591. "The model %v does not have the property %v.",
  33592. modelName,
  33593. propertyName
  33594. );
  33595. if (propDef && typeof propDef === "object")
  33596. return propDef.columnName ?? propertyName;
  33597. return propertyName;
  33598. }
  33599. /**
  33600. * Get default property value.
  33601. *
  33602. * @param {string} modelName
  33603. * @param {string} propertyName
  33604. * @returns {*}
  33605. */
  33606. getDefaultPropertyValue(modelName, propertyName) {
  33607. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33608. const propDef = propDefs[propertyName];
  33609. if (!propDef)
  33610. throw new InvalidArgumentError2(
  33611. "The model %v does not have the property %v.",
  33612. modelName,
  33613. propertyName
  33614. );
  33615. if (propDef && typeof propDef === "object")
  33616. return propDef.default instanceof Function ? propDef.default() : propDef.default;
  33617. }
  33618. /**
  33619. * Set default values for empty properties.
  33620. *
  33621. * @param {string} modelName
  33622. * @param {object} modelData
  33623. * @param {boolean|undefined} onlyProvidedProperties
  33624. * @returns {object}
  33625. */
  33626. setDefaultValuesToEmptyProperties(modelName, modelData, onlyProvidedProperties = false) {
  33627. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33628. const propNames = onlyProvidedProperties ? Object.keys(modelData) : Object.keys(propDefs);
  33629. const extendedData = cloneDeep(modelData);
  33630. const emptyValueDefiner = this.getService(EmptyValuesDefiner);
  33631. propNames.forEach((propName) => {
  33632. const propDef = propDefs[propName];
  33633. const propValue = extendedData[propName];
  33634. const propType = propDef != null ? this.getDataTypeFromPropertyDefinition(propDef) : DataType.ANY;
  33635. const isEmpty = emptyValueDefiner.isEmpty(propType, propValue);
  33636. if (!isEmpty) return;
  33637. if (propDef && typeof propDef === "object" && propDef.default !== void 0) {
  33638. extendedData[propName] = this.getDefaultPropertyValue(
  33639. modelName,
  33640. propName
  33641. );
  33642. }
  33643. });
  33644. return extendedData;
  33645. }
  33646. /**
  33647. * Convert property names to column names.
  33648. *
  33649. * @param {string} modelName
  33650. * @param {object} modelData
  33651. * @returns {object}
  33652. */
  33653. convertPropertyNamesToColumnNames(modelName, modelData) {
  33654. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33655. const propNames = Object.keys(propDefs);
  33656. const convertedData = cloneDeep(modelData);
  33657. propNames.forEach((propName) => {
  33658. if (!(propName in convertedData)) return;
  33659. const colName = this.getColumnNameByPropertyName(modelName, propName);
  33660. if (propName === colName) return;
  33661. const propValue = convertedData[propName];
  33662. delete convertedData[propName];
  33663. convertedData[colName] = propValue;
  33664. });
  33665. return convertedData;
  33666. }
  33667. /**
  33668. * Convert column names to property names.
  33669. *
  33670. * @param {string} modelName
  33671. * @param {object} tableData
  33672. * @returns {object}
  33673. */
  33674. convertColumnNamesToPropertyNames(modelName, tableData) {
  33675. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33676. const propNames = Object.keys(propDefs);
  33677. const convertedData = cloneDeep(tableData);
  33678. propNames.forEach((propName) => {
  33679. const colName = this.getColumnNameByPropertyName(modelName, propName);
  33680. if (!(colName in convertedData) || colName === propName) return;
  33681. const colValue = convertedData[colName];
  33682. delete convertedData[colName];
  33683. convertedData[propName] = colValue;
  33684. });
  33685. return convertedData;
  33686. }
  33687. /**
  33688. * Get data type by property name.
  33689. *
  33690. * @param {string} modelName
  33691. * @param {string} propertyName
  33692. * @returns {string}
  33693. */
  33694. getDataTypeByPropertyName(modelName, propertyName) {
  33695. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33696. const propDef = propDefs[propertyName];
  33697. if (!propDef) {
  33698. const pkPropName = this.getPrimaryKeyAsPropertyName(modelName);
  33699. if (pkPropName === propertyName) return DataType.ANY;
  33700. throw new InvalidArgumentError2(
  33701. "The model %v does not have the property %v.",
  33702. modelName,
  33703. propertyName
  33704. );
  33705. }
  33706. if (typeof propDef === "string") return propDef;
  33707. return propDef.type;
  33708. }
  33709. /**
  33710. * Get data type from property definition.
  33711. *
  33712. * @param {object} propDef
  33713. * @returns {string}
  33714. */
  33715. getDataTypeFromPropertyDefinition(propDef) {
  33716. if ((!propDef || typeof propDef !== "object") && !Object.values(DataType).includes(propDef)) {
  33717. throw new InvalidArgumentError2(
  33718. 'The argument "propDef" of the ModelDefinitionUtils.getDataTypeFromPropertyDefinition should be an Object or the DataType enum, but %v given.',
  33719. propDef
  33720. );
  33721. }
  33722. if (typeof propDef === "string") return propDef;
  33723. const dataType = propDef.type;
  33724. if (!Object.values(DataType).includes(dataType))
  33725. throw new InvalidArgumentError2(
  33726. 'The given Object to the ModelDefinitionUtils.getDataTypeFromPropertyDefinition should have the "type" property with one of values: %l, but %v given.',
  33727. Object.values(DataType),
  33728. propDef.type
  33729. );
  33730. return dataType;
  33731. }
  33732. /**
  33733. * Get own properties definition of primary keys.
  33734. *
  33735. * @param {string} modelName
  33736. * @returns {object}
  33737. */
  33738. getOwnPropertiesDefinitionOfPrimaryKeys(modelName) {
  33739. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33740. const propDefs = modelDef.properties ?? {};
  33741. const pkPropNames = Object.keys(propDefs).filter((propName) => {
  33742. const propDef = propDefs[propName];
  33743. return typeof propDef === "object" && propDef.primaryKey;
  33744. });
  33745. return pkPropNames.reduce((a, k) => ({ ...a, [k]: propDefs[k] }), {});
  33746. }
  33747. /**
  33748. * Get own properties definition without primary keys.
  33749. *
  33750. * @param {string} modelName
  33751. * @returns {object}
  33752. */
  33753. getOwnPropertiesDefinitionWithoutPrimaryKeys(modelName) {
  33754. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33755. const propDefs = modelDef.properties ?? {};
  33756. return Object.keys(propDefs).reduce((result, propName) => {
  33757. const propDef = propDefs[propName];
  33758. if (typeof propDef === "object" && propDef.primaryKey) return result;
  33759. return { ...result, [propName]: propDef };
  33760. }, {});
  33761. }
  33762. /**
  33763. * Get properties definition in base model hierarchy.
  33764. *
  33765. * @param {string} modelName
  33766. * @returns {object}
  33767. */
  33768. getPropertiesDefinitionInBaseModelHierarchy(modelName) {
  33769. let result = {};
  33770. let pkPropDefs = {};
  33771. const recursion = (currModelName, prevModelName = void 0) => {
  33772. if (currModelName === prevModelName)
  33773. throw new InvalidArgumentError2(
  33774. "The model %v has a circular inheritance.",
  33775. currModelName
  33776. );
  33777. if (Object.keys(pkPropDefs).length === 0) {
  33778. pkPropDefs = this.getOwnPropertiesDefinitionOfPrimaryKeys(currModelName);
  33779. result = { ...result, ...pkPropDefs };
  33780. }
  33781. const regularPropDefs = this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName);
  33782. result = { ...regularPropDefs, ...result };
  33783. const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
  33784. if (modelDef.base) recursion(modelDef.base, currModelName);
  33785. };
  33786. recursion(modelName);
  33787. return result;
  33788. }
  33789. /**
  33790. * Get own relations definition.
  33791. *
  33792. * @param {string} modelName
  33793. * @returns {object}
  33794. */
  33795. getOwnRelationsDefinition(modelName) {
  33796. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33797. return modelDef.relations ?? {};
  33798. }
  33799. /**
  33800. * Get relations definition in base model hierarchy.
  33801. *
  33802. * @param {string} modelName
  33803. * @returns {object}
  33804. */
  33805. getRelationsDefinitionInBaseModelHierarchy(modelName) {
  33806. let result = {};
  33807. const recursion = (currModelName, prevModelName = void 0) => {
  33808. if (currModelName === prevModelName)
  33809. throw new InvalidArgumentError2(
  33810. "The model %v has a circular inheritance.",
  33811. currModelName
  33812. );
  33813. const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
  33814. const ownRelDefs = modelDef.relations ?? {};
  33815. result = { ...ownRelDefs, ...result };
  33816. if (modelDef.base) recursion(modelDef.base, currModelName);
  33817. };
  33818. recursion(modelName);
  33819. return result;
  33820. }
  33821. /**
  33822. * Get relation definition by name.
  33823. *
  33824. * @param {string} modelName
  33825. * @param {string} relationName
  33826. * @returns {object}
  33827. */
  33828. getRelationDefinitionByName(modelName, relationName) {
  33829. const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
  33830. const relNames = Object.keys(relDefs);
  33831. let foundDef;
  33832. for (const relName of relNames) {
  33833. if (relName === relationName) {
  33834. foundDef = relDefs[relName];
  33835. break;
  33836. }
  33837. }
  33838. if (!foundDef)
  33839. throw new InvalidArgumentError2(
  33840. "The model %v does not have relation name %v.",
  33841. modelName,
  33842. relationName
  33843. );
  33844. return foundDef;
  33845. }
  33846. /**
  33847. * Exclude object keys by relation names.
  33848. *
  33849. * @param {string} modelName
  33850. * @param {object} modelData
  33851. * @returns {object}
  33852. */
  33853. excludeObjectKeysByRelationNames(modelName, modelData) {
  33854. if (!modelData || typeof modelData !== "object" || Array.isArray(modelData))
  33855. throw new InvalidArgumentError2(
  33856. "The second argument of ModelDefinitionUtils.excludeObjectKeysByRelationNames should be an Object, but %v given.",
  33857. modelData
  33858. );
  33859. const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
  33860. const relNames = Object.keys(relDefs);
  33861. return excludeObjectKeys(modelData, relNames);
  33862. }
  33863. };
  33864. }
  33865. });
  33866. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness-validator.js
  33867. var PropertyUniquenessValidator;
  33868. var init_property_uniqueness_validator = __esm({
  33869. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness-validator.js"() {
  33870. init_data_type();
  33871. init_src2();
  33872. init_utils2();
  33873. init_property_uniqueness();
  33874. init_empty_values_definer();
  33875. init_errors2();
  33876. init_model_definition_utils();
  33877. PropertyUniquenessValidator = class extends Service {
  33878. /**
  33879. * Validate.
  33880. *
  33881. * @param {Function} countMethod
  33882. * @param {string} methodName
  33883. * @param {string} modelName
  33884. * @param {object} modelData
  33885. * @param {*} modelId
  33886. * @returns {Promise<undefined>}
  33887. */
  33888. async validate(countMethod, methodName, modelName, modelData, modelId = void 0) {
  33889. if (typeof countMethod !== "function")
  33890. throw new InvalidArgumentError2(
  33891. 'The parameter "countMethod" of the PropertyUniquenessValidator must be a Function, but %v given.',
  33892. countMethod
  33893. );
  33894. if (!methodName || typeof methodName !== "string")
  33895. throw new InvalidArgumentError2(
  33896. 'The parameter "methodName" of the PropertyUniquenessValidator must be a non-empty String, but %v given.',
  33897. methodName
  33898. );
  33899. if (!modelName || typeof modelName !== "string")
  33900. throw new InvalidArgumentError2(
  33901. 'The parameter "modelName" of the PropertyUniquenessValidator must be a non-empty String, but %v given.',
  33902. modelName
  33903. );
  33904. if (!isPureObject(modelData))
  33905. throw new InvalidArgumentError2(
  33906. "The data of the model %v should be an Object, but %v given.",
  33907. modelName,
  33908. modelData
  33909. );
  33910. const propDefs = this.getService(
  33911. ModelDefinitionUtils
  33912. ).getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33913. const isPartial = methodName === "patch" || methodName === "patchById";
  33914. const propNames = Object.keys(isPartial ? modelData : propDefs);
  33915. const idProp = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  33916. modelName
  33917. );
  33918. const createError = (propName, propValue) => new InvalidArgumentError2(
  33919. "An existing document of the model %v already has the property %v with the value %v and should be unique.",
  33920. modelName,
  33921. propName,
  33922. propValue
  33923. );
  33924. let willBeReplaced = void 0;
  33925. const emptyValuesDefiner = this.getService(EmptyValuesDefiner);
  33926. for (const propName of propNames) {
  33927. const propDef = propDefs[propName];
  33928. if (!propDef || typeof propDef === "string" || !propDef.unique || propDef.unique === PropertyUniqueness.NON_UNIQUE) {
  33929. continue;
  33930. }
  33931. const propValue = modelData[propName];
  33932. if (propDef.unique === PropertyUniqueness.SPARSE) {
  33933. const propType = propDef.type || DataType.ANY;
  33934. const isEmpty = emptyValuesDefiner.isEmpty(propType, propValue);
  33935. if (isEmpty) continue;
  33936. }
  33937. if (methodName === "create") {
  33938. const count = await countMethod({ [propName]: propValue });
  33939. if (count > 0) throw createError(propName, propValue);
  33940. } else if (methodName === "replaceById") {
  33941. const count = await countMethod({
  33942. [idProp]: { neq: modelId },
  33943. [propName]: propValue
  33944. });
  33945. if (count > 0) throw createError(propName, propValue);
  33946. } else if (methodName === "replaceOrCreate") {
  33947. const idFromData = modelData[idProp];
  33948. if (willBeReplaced == null && idFromData != null) {
  33949. const count = await countMethod({ [idProp]: idFromData });
  33950. willBeReplaced = count > 0;
  33951. }
  33952. if (willBeReplaced) {
  33953. const count = await countMethod({
  33954. [idProp]: { neq: idFromData },
  33955. [propName]: propValue
  33956. });
  33957. if (count > 0) throw createError(propName, propValue);
  33958. } else {
  33959. const count = await countMethod({ [propName]: propValue });
  33960. if (count > 0) throw createError(propName, propValue);
  33961. }
  33962. } else if (methodName === "patch") {
  33963. const count = await countMethod({ [propName]: propValue });
  33964. if (count > 0) throw createError(propName, propValue);
  33965. } else if (methodName === "patchById") {
  33966. const count = await countMethod({
  33967. [idProp]: { neq: modelId },
  33968. [propName]: propValue
  33969. });
  33970. if (count > 0) throw createError(propName, propValue);
  33971. } else {
  33972. throw new InvalidArgumentError2(
  33973. "The PropertyUniquenessValidator does not support the adapter method %v.",
  33974. methodName
  33975. );
  33976. }
  33977. }
  33978. }
  33979. };
  33980. }
  33981. });
  33982. // node_modules/@e22m4u/js-repository/src/definition/model/properties/primary-keys-definition-validator.js
  33983. var PrimaryKeysDefinitionValidator;
  33984. var init_primary_keys_definition_validator = __esm({
  33985. "node_modules/@e22m4u/js-repository/src/definition/model/properties/primary-keys-definition-validator.js"() {
  33986. init_src2();
  33987. init_errors2();
  33988. init_model_definition_utils();
  33989. PrimaryKeysDefinitionValidator = class extends Service {
  33990. /**
  33991. * Validate.
  33992. *
  33993. * @param {string} modelName
  33994. * @param {object} propDefs
  33995. */
  33996. validate(modelName, propDefs) {
  33997. const propNames = Object.keys(propDefs).filter((propName) => {
  33998. const propDef = propDefs[propName];
  33999. return propDef && typeof propDef === "object" && propDef.primaryKey;
  34000. });
  34001. if (propNames.length < 1) {
  34002. const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(DEFAULT_PRIMARY_KEY_PROPERTY_NAME);
  34003. if (isDefaultPrimaryKeyAlreadyInUse)
  34004. throw new InvalidArgumentError2(
  34005. 'The property name %v of the model %v is defined as a regular property. In this case, a primary key should be defined explicitly. Do use the option "primaryKey" to specify the primary key.',
  34006. DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
  34007. modelName
  34008. );
  34009. return;
  34010. }
  34011. if (propNames.length > 1)
  34012. throw new InvalidArgumentError2(
  34013. "The model definition %v should not have multiple primary keys, but %v keys given.",
  34014. modelName,
  34015. propNames.length
  34016. );
  34017. const pkPropName = propNames[0];
  34018. const pkPropDef = propDefs[pkPropName];
  34019. if (pkPropDef && typeof pkPropDef === "object" && pkPropDef.default !== void 0) {
  34020. throw new InvalidArgumentError2(
  34021. "Do not specify a default value for the primary key %v of the model %v.",
  34022. pkPropName,
  34023. modelName
  34024. );
  34025. }
  34026. }
  34027. };
  34028. }
  34029. });
  34030. // node_modules/@e22m4u/js-repository/src/definition/model/properties/properties-definition-validator.js
  34031. var PropertiesDefinitionValidator;
  34032. var init_properties_definition_validator = __esm({
  34033. "node_modules/@e22m4u/js-repository/src/definition/model/properties/properties-definition-validator.js"() {
  34034. init_src2();
  34035. init_data_type();
  34036. init_utils2();
  34037. init_property_uniqueness();
  34038. init_errors2();
  34039. init_property_validator2();
  34040. init_property_transformer2();
  34041. init_primary_keys_definition_validator();
  34042. PropertiesDefinitionValidator = class extends Service {
  34043. /**
  34044. * Validate.
  34045. *
  34046. * @param {string} modelName
  34047. * @param {object} propDefs
  34048. */
  34049. validate(modelName, propDefs) {
  34050. if (!modelName || typeof modelName !== "string")
  34051. throw new InvalidArgumentError2(
  34052. "The first argument of PropertiesDefinitionValidator.validate should be a non-empty String, but %v given.",
  34053. modelName
  34054. );
  34055. if (!propDefs || typeof propDefs !== "object" || Array.isArray(propDefs)) {
  34056. throw new InvalidArgumentError2(
  34057. 'The provided option "properties" of the model %v should be an Object, but %v given.',
  34058. modelName,
  34059. propDefs
  34060. );
  34061. }
  34062. const propNames = Object.keys(propDefs);
  34063. propNames.forEach((propName) => {
  34064. const propDef = propDefs[propName];
  34065. this._validateProperty(modelName, propName, propDef);
  34066. });
  34067. this.getService(PrimaryKeysDefinitionValidator).validate(
  34068. modelName,
  34069. propDefs
  34070. );
  34071. }
  34072. /**
  34073. * Validate property.
  34074. *
  34075. * @param {string} modelName
  34076. * @param {string} propName
  34077. * @param {object} propDef
  34078. */
  34079. _validateProperty(modelName, propName, propDef) {
  34080. if (!modelName || typeof modelName !== "string")
  34081. throw new InvalidArgumentError2(
  34082. "The first argument of PropertiesDefinitionValidator._validateProperty should be a non-empty String, but %v given.",
  34083. modelName
  34084. );
  34085. if (!propName || typeof propName !== "string")
  34086. throw new InvalidArgumentError2(
  34087. "The property name of the model %v should be a non-empty String, but %v given.",
  34088. modelName,
  34089. propName
  34090. );
  34091. if (!propDef)
  34092. throw new InvalidArgumentError2(
  34093. "The property %v of the model %v should have a property definition, but %v given.",
  34094. propName,
  34095. modelName,
  34096. propDef
  34097. );
  34098. if (typeof propDef === "string") {
  34099. if (!Object.values(DataType).includes(propDef))
  34100. throw new InvalidArgumentError2(
  34101. "In case of a short property definition, the property %v of the model %v should have one of data types: %l, but %v given.",
  34102. propName,
  34103. modelName,
  34104. Object.values(DataType),
  34105. propDef
  34106. );
  34107. return;
  34108. }
  34109. if (!propDef || typeof propDef !== "object" || Array.isArray(propDef)) {
  34110. throw new InvalidArgumentError2(
  34111. "In case of a full property definition, the property %v of the model %v should be an Object, but %v given.",
  34112. propName,
  34113. modelName,
  34114. propDef
  34115. );
  34116. }
  34117. if (!propDef.type || !Object.values(DataType).includes(propDef.type))
  34118. throw new InvalidArgumentError2(
  34119. 'The property %v of the model %v requires the option "type" to have one of data types: %l, but %v given.',
  34120. propName,
  34121. modelName,
  34122. Object.values(DataType),
  34123. propDef.type
  34124. );
  34125. if (propDef.itemType && !Object.values(DataType).includes(propDef.itemType)) {
  34126. throw new InvalidArgumentError2(
  34127. 'The provided option "itemType" of the property %v in the model %v should have one of data types: %l, but %v given.',
  34128. propName,
  34129. modelName,
  34130. Object.values(DataType),
  34131. propDef.itemType
  34132. );
  34133. }
  34134. if (propDef.model && typeof propDef.model !== "string")
  34135. throw new InvalidArgumentError2(
  34136. 'The provided option "model" of the property %v in the model %v should be a String, but %v given.',
  34137. propName,
  34138. modelName,
  34139. propDef.model
  34140. );
  34141. if (propDef.primaryKey && typeof propDef.primaryKey !== "boolean")
  34142. throw new InvalidArgumentError2(
  34143. 'The provided option "primaryKey" of the property %v in the model %v should be a Boolean, but %v given.',
  34144. propName,
  34145. modelName,
  34146. propDef.primaryKey
  34147. );
  34148. if (propDef.columnName && typeof propDef.columnName !== "string")
  34149. throw new InvalidArgumentError2(
  34150. 'The provided option "columnName" of the property %v in the model %v should be a String, but %v given.',
  34151. propName,
  34152. modelName,
  34153. propDef.columnName
  34154. );
  34155. if (propDef.columnType && typeof propDef.columnType !== "string")
  34156. throw new InvalidArgumentError2(
  34157. 'The provided option "columnType" of the property %v in the model %v should be a String, but %v given.',
  34158. propName,
  34159. modelName,
  34160. propDef.columnType
  34161. );
  34162. if (propDef.required && typeof propDef.required !== "boolean")
  34163. throw new InvalidArgumentError2(
  34164. 'The provided option "required" of the property %v in the model %v should be a Boolean, but %v given.',
  34165. propName,
  34166. modelName,
  34167. propDef.required
  34168. );
  34169. if (propDef.required && propDef.default !== void 0)
  34170. throw new InvalidArgumentError2(
  34171. 'The property %v of the model %v is a required property, so it should not have the option "default" to be provided.',
  34172. propName,
  34173. modelName
  34174. );
  34175. if (propDef.primaryKey && propDef.required)
  34176. throw new InvalidArgumentError2(
  34177. 'The property %v of the model %v is a primary key, so it should not have the option "required" to be provided.',
  34178. propName,
  34179. modelName
  34180. );
  34181. if (propDef.primaryKey && propDef.default !== void 0)
  34182. throw new InvalidArgumentError2(
  34183. 'The property %v of the model %v is a primary key, so it should not have the option "default" to be provided.',
  34184. propName,
  34185. modelName
  34186. );
  34187. if (propDef.itemType && propDef.type !== DataType.ARRAY)
  34188. throw new InvalidArgumentError2(
  34189. 'The property %v of the model %v has the non-array type, so it should not have the option "itemType" to be provided.',
  34190. propName,
  34191. modelName,
  34192. propDef.type
  34193. );
  34194. if (propDef.model && propDef.type !== DataType.OBJECT && propDef.itemType !== DataType.OBJECT) {
  34195. if (propDef.type !== DataType.ARRAY) {
  34196. throw new InvalidArgumentError2(
  34197. 'The option "model" is not supported for %s property type, so the property %v of the model %v should not have the option "model" to be provided.',
  34198. capitalize(propDef.type),
  34199. propName,
  34200. modelName
  34201. );
  34202. } else {
  34203. throw new InvalidArgumentError2(
  34204. 'The option "model" is not supported for Array property type of %s, so the property %v of the model %v should not have the option "model" to be provided.',
  34205. capitalize(propDef.itemType),
  34206. propName,
  34207. modelName
  34208. );
  34209. }
  34210. }
  34211. if (propDef.validate != null) {
  34212. const propertyValidatorRegistry = this.getService(
  34213. PropertyValidatorRegistry
  34214. );
  34215. if (propDef.validate && typeof propDef.validate === "string") {
  34216. if (!propertyValidatorRegistry.hasValidator(propDef.validate))
  34217. throw new InvalidArgumentError2(
  34218. "The property validator %v is not found.",
  34219. propDef.validate
  34220. );
  34221. } else if (Array.isArray(propDef.validate)) {
  34222. for (const validatorName of propDef.validate) {
  34223. if (typeof validatorName !== "string")
  34224. throw new InvalidArgumentError2(
  34225. 'The provided option "validate" of the property %v in the model %v has an Array value that should have a non-empty String, but %v given.',
  34226. propName,
  34227. modelName,
  34228. validatorName
  34229. );
  34230. if (!propertyValidatorRegistry.hasValidator(validatorName))
  34231. throw new InvalidArgumentError2(
  34232. "The property validator %v is not found.",
  34233. validatorName
  34234. );
  34235. }
  34236. } else if (typeof propDef.validate === "object") {
  34237. for (const validatorName in propDef.validate) {
  34238. if (!propertyValidatorRegistry.hasValidator(validatorName))
  34239. throw new InvalidArgumentError2(
  34240. "The property validator %v is not found.",
  34241. validatorName
  34242. );
  34243. }
  34244. } else {
  34245. throw new InvalidArgumentError2(
  34246. 'The provided option "validate" of the property %v in the model %v should be a non-empty String, an Array of String or an Object, but %v given.',
  34247. propName,
  34248. modelName,
  34249. propDef.validate
  34250. );
  34251. }
  34252. }
  34253. if (propDef.transform != null) {
  34254. const propertyTransformerRegistry = this.getService(
  34255. PropertyTransformerRegistry
  34256. );
  34257. if (propDef.transform && typeof propDef.transform === "string") {
  34258. if (!propertyTransformerRegistry.hasTransformer(propDef.transform))
  34259. throw new InvalidArgumentError2(
  34260. "The property transformer %v is not found.",
  34261. propDef.transform
  34262. );
  34263. } else if (Array.isArray(propDef.transform)) {
  34264. for (const transformerName of propDef.transform) {
  34265. if (typeof transformerName !== "string")
  34266. throw new InvalidArgumentError2(
  34267. 'The provided option "transform" of the property %v in the model %v has an Array value that should have a non-empty String, but %v given.',
  34268. propName,
  34269. modelName,
  34270. transformerName
  34271. );
  34272. if (!propertyTransformerRegistry.hasTransformer(transformerName))
  34273. throw new InvalidArgumentError2(
  34274. "The property transformer %v is not found.",
  34275. transformerName
  34276. );
  34277. }
  34278. } else if (typeof propDef.transform === "object") {
  34279. for (const transformerName in propDef.transform) {
  34280. if (!propertyTransformerRegistry.hasTransformer(transformerName))
  34281. throw new InvalidArgumentError2(
  34282. "The property transformer %v is not found.",
  34283. transformerName
  34284. );
  34285. }
  34286. } else {
  34287. throw new InvalidArgumentError2(
  34288. 'The provided option "transform" of the property %v in the model %v should be a non-empty String, an Array of String or an Object, but %v given.',
  34289. propName,
  34290. modelName,
  34291. propDef.transform
  34292. );
  34293. }
  34294. }
  34295. if (propDef.unique) {
  34296. if (typeof propDef.unique !== "boolean" && !Object.values(PropertyUniqueness).includes(propDef.unique)) {
  34297. throw new InvalidArgumentError2(
  34298. 'The provided option "unique" of the property %v in the model %v should be a Boolean or one of values: %l, but %v given.',
  34299. propName,
  34300. modelName,
  34301. Object.values(PropertyUniqueness),
  34302. propDef.unique
  34303. );
  34304. }
  34305. }
  34306. if (propDef.unique && propDef.primaryKey)
  34307. throw new InvalidArgumentError2(
  34308. 'The property %v of the model %v is a primary key, so it should not have the option "unique" to be provided.',
  34309. propName,
  34310. modelName
  34311. );
  34312. }
  34313. };
  34314. }
  34315. });
  34316. // node_modules/@e22m4u/js-repository/src/definition/model/properties/index.js
  34317. var init_properties = __esm({
  34318. "node_modules/@e22m4u/js-repository/src/definition/model/properties/index.js"() {
  34319. init_data_type();
  34320. init_property_definition();
  34321. init_property_uniqueness();
  34322. init_empty_values_definer();
  34323. init_property_validator2();
  34324. init_property_transformer2();
  34325. init_property_uniqueness_validator();
  34326. init_properties_definition_validator();
  34327. init_primary_keys_definition_validator();
  34328. }
  34329. });
  34330. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition.js
  34331. var init_model_definition = __esm({
  34332. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition.js"() {
  34333. }
  34334. });
  34335. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-validator.js
  34336. var ModelDataValidator;
  34337. var init_model_data_validator = __esm({
  34338. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-validator.js"() {
  34339. init_src2();
  34340. init_properties();
  34341. init_utils2();
  34342. init_utils2();
  34343. init_properties();
  34344. init_errors2();
  34345. init_properties();
  34346. init_model_definition_utils();
  34347. ModelDataValidator = class extends Service {
  34348. /**
  34349. * Validate.
  34350. *
  34351. * @param {string} modelName
  34352. * @param {object} modelData
  34353. * @param {boolean} isPartial
  34354. * @returns {undefined}
  34355. */
  34356. validate(modelName, modelData, isPartial = false) {
  34357. if (!isPureObject(modelData))
  34358. throw new InvalidArgumentError2(
  34359. "The data of the model %v should be an Object, but %v given.",
  34360. modelName,
  34361. modelData
  34362. );
  34363. const propDefs = this.getService(
  34364. ModelDefinitionUtils
  34365. ).getPropertiesDefinitionInBaseModelHierarchy(modelName);
  34366. const propNames = Object.keys(isPartial ? modelData : propDefs);
  34367. propNames.forEach((propName) => {
  34368. const propDef = propDefs[propName];
  34369. if (!propDef) return;
  34370. this._validatePropertyValue(
  34371. modelName,
  34372. propName,
  34373. propDef,
  34374. modelData[propName]
  34375. );
  34376. });
  34377. }
  34378. /**
  34379. * Validate property value.
  34380. *
  34381. * @param {string} modelName
  34382. * @param {string} propName
  34383. * @param {string|object} propDef
  34384. * @param {*} propValue
  34385. * @returns {undefined}
  34386. */
  34387. _validatePropertyValue(modelName, propName, propDef, propValue) {
  34388. const propType = this.getService(ModelDefinitionUtils).getDataTypeFromPropertyDefinition(
  34389. propDef
  34390. );
  34391. const isEmpty = this.getService(EmptyValuesDefiner).isEmpty(
  34392. propType,
  34393. propValue
  34394. );
  34395. if (isEmpty) {
  34396. const isRequired = typeof propDef === "string" ? false : Boolean(propDef.required);
  34397. if (!isRequired) return;
  34398. throw new InvalidArgumentError2(
  34399. "The property %v of the model %v is required, but %v given.",
  34400. propName,
  34401. modelName,
  34402. propValue
  34403. );
  34404. }
  34405. this._validateValueByPropertyValidators(
  34406. modelName,
  34407. propName,
  34408. propDef,
  34409. propValue
  34410. );
  34411. this._validateValueByPropertyType(modelName, propName, propDef, propValue);
  34412. }
  34413. /**
  34414. * Validate value by property type.
  34415. *
  34416. * @param {string} modelName
  34417. * @param {string} propName
  34418. * @param {string|object} propDef
  34419. * @param {*} propValue
  34420. * @param {boolean} isArrayValue
  34421. * @returns {undefined}
  34422. */
  34423. _validateValueByPropertyType(modelName, propName, propDef, propValue, isArrayValue = false) {
  34424. let expectingType;
  34425. if (isArrayValue) {
  34426. if (typeof propDef === "object") {
  34427. expectingType = propDef.itemType ?? DataType.ANY;
  34428. } else {
  34429. expectingType = DataType.ANY;
  34430. }
  34431. } else {
  34432. expectingType = typeof propDef !== "string" ? propDef.type : propDef;
  34433. }
  34434. const createError = (expected) => {
  34435. const pattern = isArrayValue ? "The array property %v of the model %v must have %s element, but %s given." : "The property %v of the model %v must have %s, but %s given.";
  34436. const ctorName = getCtorName(propValue);
  34437. const givenStr = ctorName ?? typeof propValue;
  34438. return new InvalidArgumentError2(
  34439. pattern,
  34440. propName,
  34441. modelName,
  34442. expected,
  34443. givenStr
  34444. );
  34445. };
  34446. switch (expectingType) {
  34447. // STRING
  34448. case DataType.STRING:
  34449. if (typeof propValue !== "string") throw createError("a String");
  34450. break;
  34451. // NUMBER
  34452. case DataType.NUMBER:
  34453. if (typeof propValue !== "number") throw createError("a Number");
  34454. break;
  34455. // BOOLEAN
  34456. case DataType.BOOLEAN:
  34457. if (typeof propValue !== "boolean") throw createError("a Boolean");
  34458. break;
  34459. // ARRAY
  34460. case DataType.ARRAY:
  34461. if (!Array.isArray(propValue)) throw createError("an Array");
  34462. propValue.forEach(
  34463. (value) => this._validateValueByPropertyType(
  34464. modelName,
  34465. propName,
  34466. propDef,
  34467. value,
  34468. true
  34469. )
  34470. );
  34471. break;
  34472. // OBJECT
  34473. case DataType.OBJECT:
  34474. if (!isPureObject(propValue)) throw createError("an Object");
  34475. if (typeof propDef === "object" && propDef.model)
  34476. this.validate(propDef.model, propValue);
  34477. break;
  34478. }
  34479. }
  34480. /**
  34481. * Validate value by property validators.
  34482. *
  34483. * @param {string} modelName
  34484. * @param {string} propName
  34485. * @param {string|object} propDef
  34486. * @param {*} propValue
  34487. * @returns {undefined}
  34488. */
  34489. _validateValueByPropertyValidators(modelName, propName, propDef, propValue) {
  34490. if (typeof propDef === "string" || propDef.validate == null) return;
  34491. const validateDef = propDef.validate;
  34492. const validatorRegistry = this.getService(PropertyValidatorRegistry);
  34493. const createError = (validatorName) => new InvalidArgumentError2(
  34494. "The property %v of the model %v has an invalid value %v that caught by the validator %v.",
  34495. propName,
  34496. modelName,
  34497. propValue,
  34498. validatorName
  34499. );
  34500. const validateBy = (validatorName, validatorOptions = void 0) => {
  34501. const validator = validatorRegistry.getValidator(validatorName);
  34502. const context = { validatorName, modelName, propName };
  34503. const valid = validator(propValue, validatorOptions, context);
  34504. if (valid instanceof Promise) {
  34505. throw new InvalidArgumentError2(
  34506. "Asynchronous property validators are not supported, but the property validator %v returns a Promise.",
  34507. validatorName
  34508. );
  34509. } else if (valid !== true) {
  34510. throw createError(validatorName);
  34511. }
  34512. };
  34513. if (validateDef && typeof validateDef === "string") {
  34514. validateBy(validateDef);
  34515. } else if (Array.isArray(validateDef)) {
  34516. validateDef.forEach((validatorName) => validateBy(validatorName));
  34517. } else if (validateDef !== null && typeof validateDef === "object") {
  34518. Object.keys(validateDef).forEach((validatorName) => {
  34519. if (Object.prototype.hasOwnProperty.call(validateDef, validatorName)) {
  34520. const validatorOptions = validateDef[validatorName];
  34521. validateBy(validatorName, validatorOptions);
  34522. }
  34523. });
  34524. } else {
  34525. throw new InvalidArgumentError2(
  34526. 'The provided option "validate" of the property %v in the model %v should be a non-empty String, an Array of String or an Object, but %v given.',
  34527. propName,
  34528. modelName,
  34529. validateDef
  34530. );
  34531. }
  34532. }
  34533. };
  34534. }
  34535. });
  34536. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-sanitizer.js
  34537. var ModelDataSanitizer;
  34538. var init_model_data_sanitizer = __esm({
  34539. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-sanitizer.js"() {
  34540. init_src2();
  34541. init_errors2();
  34542. init_model_definition_utils();
  34543. ModelDataSanitizer = class extends Service {
  34544. /**
  34545. * Validate.
  34546. *
  34547. * @param {string} modelName
  34548. * @param {object} modelData
  34549. * @returns {object}
  34550. */
  34551. sanitize(modelName, modelData) {
  34552. if (!modelName || typeof modelName !== "string")
  34553. throw new InvalidArgumentError2(
  34554. "The first argument of ModelDataSanitizer.sanitize should be a string, but %v given.",
  34555. modelName
  34556. );
  34557. if (!modelData || typeof modelData !== "object")
  34558. throw new InvalidArgumentError2(
  34559. "The second argument of ModelDataSanitizer.sanitize should be an Object, but %v given.",
  34560. modelData
  34561. );
  34562. return this.getService(
  34563. ModelDefinitionUtils
  34564. ).excludeObjectKeysByRelationNames(modelName, modelData);
  34565. }
  34566. };
  34567. }
  34568. });
  34569. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-transformer.js
  34570. var ModelDataTransformer;
  34571. var init_model_data_transformer = __esm({
  34572. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-transformer.js"() {
  34573. init_src2();
  34574. init_utils2();
  34575. init_utils2();
  34576. init_utils2();
  34577. init_properties();
  34578. init_errors2();
  34579. init_model_definition_utils();
  34580. init_properties();
  34581. ModelDataTransformer = class extends Service {
  34582. /**
  34583. * Transform.
  34584. *
  34585. * @param {string} modelName
  34586. * @param {object} modelData
  34587. * @param {boolean} isPartial
  34588. * @returns {object|Promise<object>}
  34589. */
  34590. transform(modelName, modelData, isPartial = false) {
  34591. if (!isPureObject(modelData))
  34592. throw new InvalidArgumentError2(
  34593. "The data of the model %v should be an Object, but %v given.",
  34594. modelName,
  34595. modelData
  34596. );
  34597. const emptyValuesDefiner = this.getService(EmptyValuesDefiner);
  34598. const modelDefinitionUtils = this.getService(ModelDefinitionUtils);
  34599. const propDefs = modelDefinitionUtils.getPropertiesDefinitionInBaseModelHierarchy(
  34600. modelName
  34601. );
  34602. const propNames = Object.keys(isPartial ? modelData : propDefs);
  34603. const transformedData = cloneDeep(modelData);
  34604. return propNames.reduce((transformedDataOrPromise, propName) => {
  34605. const propDef = propDefs[propName];
  34606. if (!propDef) return transformedDataOrPromise;
  34607. const propType = modelDefinitionUtils.getDataTypeFromPropertyDefinition(propDef);
  34608. const propValue = modelData[propName];
  34609. const isEmpty = emptyValuesDefiner.isEmpty(propType, propValue);
  34610. if (isEmpty) return transformedDataOrPromise;
  34611. const newPropValueOrPromise = this._transformPropertyValue(
  34612. modelName,
  34613. propName,
  34614. propDef,
  34615. propValue
  34616. );
  34617. return transformPromise(newPropValueOrPromise, (newPropValue) => {
  34618. return transformPromise(transformedDataOrPromise, (resolvedData) => {
  34619. if (newPropValue !== propValue) resolvedData[propName] = newPropValue;
  34620. return resolvedData;
  34621. });
  34622. });
  34623. }, transformedData);
  34624. }
  34625. /**
  34626. * Transform property value.
  34627. *
  34628. * @param {string} modelName
  34629. * @param {string} propName
  34630. * @param {string|object} propDef
  34631. * @param {*} propValue
  34632. * @returns {*}
  34633. */
  34634. _transformPropertyValue(modelName, propName, propDef, propValue) {
  34635. if (typeof propDef === "string" || propDef.transform == null)
  34636. return propValue;
  34637. const transformDef = propDef.transform;
  34638. const transformerRegistry = this.getService(PropertyTransformerRegistry);
  34639. const transformFn = (value, transformerName, transformerOptions = void 0) => {
  34640. const transformer = transformerRegistry.getTransformer(transformerName);
  34641. const context = { transformerName, modelName, propName };
  34642. return transformer(value, transformerOptions, context);
  34643. };
  34644. if (transformDef && typeof transformDef === "string") {
  34645. return transformFn(propValue, transformDef);
  34646. } else if (Array.isArray(transformDef)) {
  34647. return transformDef.reduce((valueOrPromise, transformerName) => {
  34648. return transformPromise(valueOrPromise, (value) => {
  34649. return transformFn(value, transformerName);
  34650. });
  34651. }, propValue);
  34652. } else if (transformDef !== null && typeof transformDef === "object") {
  34653. return Object.keys(transformDef).reduce(
  34654. (valueOrPromise, transformerName) => {
  34655. const transformerOptions = transformDef[transformerName];
  34656. return transformPromise(valueOrPromise, (value) => {
  34657. return transformFn(value, transformerName, transformerOptions);
  34658. });
  34659. },
  34660. propValue
  34661. );
  34662. } else {
  34663. throw new InvalidArgumentError2(
  34664. 'The provided option "transform" of the property %v in the model %v should be a non-empty String, an Array of String or an Object, but %v given.',
  34665. propName,
  34666. modelName,
  34667. transformDef
  34668. );
  34669. }
  34670. }
  34671. };
  34672. }
  34673. });
  34674. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition-validator.js
  34675. var ModelDefinitionValidator;
  34676. var init_model_definition_validator = __esm({
  34677. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition-validator.js"() {
  34678. init_src2();
  34679. init_errors2();
  34680. init_relations();
  34681. init_properties();
  34682. ModelDefinitionValidator = class extends Service {
  34683. /**
  34684. * Validate.
  34685. *
  34686. * @param {object} modelDef
  34687. */
  34688. validate(modelDef) {
  34689. if (!modelDef || typeof modelDef !== "object" || Array.isArray(modelDef))
  34690. throw new InvalidArgumentError2(
  34691. "The model definition should be an Object, but %v given.",
  34692. modelDef
  34693. );
  34694. if (!modelDef.name || typeof modelDef.name !== "string")
  34695. throw new InvalidArgumentError2(
  34696. 'The model definition requires the option "name" as a non-empty String, but %v given.',
  34697. modelDef.name
  34698. );
  34699. if (modelDef.datasource && typeof modelDef.datasource !== "string")
  34700. throw new InvalidArgumentError2(
  34701. 'The provided option "datasource" of the model %v should be a String, but %v given.',
  34702. modelDef.name,
  34703. modelDef.datasource
  34704. );
  34705. if (modelDef.base && typeof modelDef.base !== "string")
  34706. throw new InvalidArgumentError2(
  34707. 'The provided option "base" of the model %v should be a String, but %v given.',
  34708. modelDef.name,
  34709. modelDef.base
  34710. );
  34711. if (modelDef.tableName && typeof modelDef.tableName !== "string")
  34712. throw new InvalidArgumentError2(
  34713. 'The provided option "tableName" of the model %v should be a String, but %v given.',
  34714. modelDef.name,
  34715. modelDef.tableName
  34716. );
  34717. if (modelDef.properties) {
  34718. if (typeof modelDef.properties !== "object" || Array.isArray(modelDef.properties)) {
  34719. throw new InvalidArgumentError2(
  34720. 'The provided option "properties" of the model %v should be an Object, but %v given.',
  34721. modelDef.name,
  34722. modelDef.properties
  34723. );
  34724. }
  34725. this.getService(PropertiesDefinitionValidator).validate(
  34726. modelDef.name,
  34727. modelDef.properties
  34728. );
  34729. }
  34730. if (modelDef.relations) {
  34731. if (typeof modelDef.relations !== "object" || Array.isArray(modelDef.relations)) {
  34732. throw new InvalidArgumentError2(
  34733. 'The provided option "relations" of the model %v should be an Object, but %v given.',
  34734. modelDef.name,
  34735. modelDef.relations
  34736. );
  34737. }
  34738. this.getService(RelationsDefinitionValidator).validate(
  34739. modelDef.name,
  34740. modelDef.relations
  34741. );
  34742. }
  34743. }
  34744. };
  34745. }
  34746. });
  34747. // node_modules/@e22m4u/js-repository/src/definition/model/index.js
  34748. var init_model = __esm({
  34749. "node_modules/@e22m4u/js-repository/src/definition/model/index.js"() {
  34750. init_relations();
  34751. init_properties();
  34752. init_model_definition();
  34753. init_model_data_validator();
  34754. init_model_data_sanitizer();
  34755. init_model_data_transformer();
  34756. init_model_definition_utils();
  34757. init_model_definition_validator();
  34758. }
  34759. });
  34760. // node_modules/@e22m4u/js-repository/src/definition/datasource/datasource-definition-validator.js
  34761. var DatasourceDefinitionValidator;
  34762. var init_datasource_definition_validator = __esm({
  34763. "node_modules/@e22m4u/js-repository/src/definition/datasource/datasource-definition-validator.js"() {
  34764. init_src2();
  34765. init_errors2();
  34766. DatasourceDefinitionValidator = class extends Service {
  34767. /**
  34768. * Validate.
  34769. *
  34770. * @param {object} datasourceDef
  34771. */
  34772. validate(datasourceDef) {
  34773. if (!datasourceDef || typeof datasourceDef !== "object")
  34774. throw new InvalidArgumentError2(
  34775. "The datasource definition should be an Object, but %v given.",
  34776. datasourceDef
  34777. );
  34778. if (!datasourceDef.name || typeof datasourceDef.name !== "string")
  34779. throw new InvalidArgumentError2(
  34780. 'The datasource definition requires the option "name" as a non-empty String, but %v given.',
  34781. datasourceDef.name
  34782. );
  34783. if (!datasourceDef.adapter || typeof datasourceDef.adapter !== "string")
  34784. throw new InvalidArgumentError2(
  34785. 'The datasource %v requires the option "adapter" as a non-empty String, but %v given.',
  34786. datasourceDef.name,
  34787. datasourceDef.adapter
  34788. );
  34789. }
  34790. };
  34791. }
  34792. });
  34793. // node_modules/@e22m4u/js-repository/src/definition/datasource/index.js
  34794. var init_datasource = __esm({
  34795. "node_modules/@e22m4u/js-repository/src/definition/datasource/index.js"() {
  34796. init_datasource_definition_validator();
  34797. }
  34798. });
  34799. // node_modules/@e22m4u/js-repository/src/definition/index.js
  34800. var init_definition = __esm({
  34801. "node_modules/@e22m4u/js-repository/src/definition/index.js"() {
  34802. init_model();
  34803. init_datasource();
  34804. init_definition_registry();
  34805. }
  34806. });
  34807. // node_modules/@e22m4u/js-repository/src/filter/fields-clause-tool.js
  34808. var FieldsClauseTool;
  34809. var init_fields_clause_tool = __esm({
  34810. "node_modules/@e22m4u/js-repository/src/filter/fields-clause-tool.js"() {
  34811. init_src2();
  34812. init_utils2();
  34813. init_errors2();
  34814. init_definition();
  34815. FieldsClauseTool = class extends Service {
  34816. /**
  34817. * Filter.
  34818. *
  34819. * @param {object|object[]} input
  34820. * @param {string} modelName
  34821. * @param {string|string[]|undefined} clause
  34822. * @returns {object|object[]}
  34823. */
  34824. filter(input, modelName, clause) {
  34825. const isArray = Array.isArray(input);
  34826. let entities = isArray ? input : [input];
  34827. entities.forEach((entity) => {
  34828. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  34829. throw new InvalidArgumentError2(
  34830. "The first argument of FieldsClauseTool.filter should be an Object or an Array of Object, but %v given.",
  34831. entity
  34832. );
  34833. });
  34834. if (!modelName || typeof modelName !== "string")
  34835. throw new InvalidArgumentError2(
  34836. "The second argument of FieldsClauseTool.filter should be a non-empty String, but %v given.",
  34837. modelName
  34838. );
  34839. if (clause == null) return input;
  34840. const fields = Array.isArray(clause) ? clause.slice() : [clause];
  34841. if (!fields.length) return input;
  34842. fields.forEach((field) => {
  34843. if (!field || typeof field !== "string")
  34844. throw new InvalidArgumentError2(
  34845. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34846. field
  34847. );
  34848. });
  34849. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  34850. modelName
  34851. );
  34852. if (fields.indexOf(pkPropName) === -1) fields.push(pkPropName);
  34853. entities = entities.map((entity) => selectObjectKeys(entity, fields));
  34854. return isArray ? entities : entities[0];
  34855. }
  34856. /**
  34857. * Validate fields clause.
  34858. *
  34859. * @param {string|string[]|undefined} clause
  34860. */
  34861. static validateFieldsClause(clause) {
  34862. if (clause == null) return;
  34863. const fields = Array.isArray(clause) ? clause : [clause];
  34864. if (!fields.length) return;
  34865. fields.forEach((field) => {
  34866. if (!field || typeof field !== "string")
  34867. throw new InvalidArgumentError2(
  34868. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34869. field
  34870. );
  34871. });
  34872. }
  34873. /**
  34874. * Normalize fields clause.
  34875. *
  34876. * @param {string|string[]|undefined} clause
  34877. * @returns {string[]|undefined}
  34878. */
  34879. static normalizeFieldsClause(clause) {
  34880. if (clause == null) return;
  34881. const fields = Array.isArray(clause) ? clause : [clause];
  34882. if (!fields.length) return;
  34883. fields.forEach((field) => {
  34884. if (!field || typeof field !== "string")
  34885. throw new InvalidArgumentError2(
  34886. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34887. field
  34888. );
  34889. });
  34890. return fields;
  34891. }
  34892. };
  34893. }
  34894. });
  34895. // node_modules/@e22m4u/js-repository/src/relations/has-one-resolver.js
  34896. var HasOneResolver;
  34897. var init_has_one_resolver = __esm({
  34898. "node_modules/@e22m4u/js-repository/src/relations/has-one-resolver.js"() {
  34899. init_src2();
  34900. init_utils2();
  34901. init_definition();
  34902. init_errors2();
  34903. init_repository2();
  34904. init_definition();
  34905. HasOneResolver = class extends Service {
  34906. /**
  34907. * Include to.
  34908. *
  34909. * @param {object[]} entities
  34910. * @param {string} sourceName
  34911. * @param {string} targetName
  34912. * @param {string} relationName
  34913. * @param {string} foreignKey
  34914. * @param {object|undefined} scope
  34915. * @returns {Promise<void>}
  34916. */
  34917. async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
  34918. if (!entities || !Array.isArray(entities))
  34919. throw new InvalidArgumentError2(
  34920. 'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v given.',
  34921. entities
  34922. );
  34923. if (!sourceName || typeof sourceName !== "string")
  34924. throw new InvalidArgumentError2(
  34925. 'The parameter "sourceName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34926. sourceName
  34927. );
  34928. if (!targetName || typeof targetName !== "string")
  34929. throw new InvalidArgumentError2(
  34930. 'The parameter "targetName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34931. targetName
  34932. );
  34933. if (!relationName || typeof relationName !== "string")
  34934. throw new InvalidArgumentError2(
  34935. 'The parameter "relationName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34936. relationName
  34937. );
  34938. if (!foreignKey || typeof foreignKey !== "string")
  34939. throw new InvalidArgumentError2(
  34940. 'The parameter "foreignKey" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34941. foreignKey
  34942. );
  34943. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  34944. throw new InvalidArgumentError2(
  34945. 'The provided parameter "scope" of HasOneResolver.includeTo should be an Object, but %v given.',
  34946. scope
  34947. );
  34948. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  34949. sourceName
  34950. );
  34951. const sourceIds = [];
  34952. entities.forEach((entity) => {
  34953. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  34954. throw new InvalidArgumentError2(
  34955. 'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v given.',
  34956. entity
  34957. );
  34958. const sourceId = entity[sourcePkPropName];
  34959. if (sourceIds.includes(sourceId)) return;
  34960. sourceIds.push(sourceId);
  34961. });
  34962. const promises = [];
  34963. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  34964. scope = scope ? cloneDeep(scope) : {};
  34965. const targetBySourceId = /* @__PURE__ */ new Map();
  34966. sourceIds.forEach((sourceId) => {
  34967. const filter = cloneDeep(scope);
  34968. filter.where = {
  34969. and: [{ [foreignKey]: sourceId }, ...scope.where ? [scope.where] : []]
  34970. };
  34971. filter.limit = 1;
  34972. promises.push(
  34973. targetRepository.find(filter).then((result) => {
  34974. if (result.length) targetBySourceId.set(sourceId, result[0]);
  34975. })
  34976. );
  34977. });
  34978. await Promise.all(promises);
  34979. Array.from(targetBySourceId.keys()).forEach((sourceId) => {
  34980. const sources = entities.filter((v) => v[sourcePkPropName] === sourceId);
  34981. sources.forEach((v) => v[relationName] = targetBySourceId.get(sourceId));
  34982. });
  34983. }
  34984. /**
  34985. * Include polymorphic to.
  34986. *
  34987. * @param {object[]} entities
  34988. * @param {string} sourceName
  34989. * @param {string} targetName
  34990. * @param {string} relationName
  34991. * @param {string} foreignKey
  34992. * @param {string} discriminator
  34993. * @param {object|undefined} scope
  34994. * @returns {Promise<void>}
  34995. */
  34996. async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
  34997. if (!entities || !Array.isArray(entities))
  34998. throw new InvalidArgumentError2(
  34999. 'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35000. entities
  35001. );
  35002. if (!sourceName || typeof sourceName !== "string")
  35003. throw new InvalidArgumentError2(
  35004. 'The parameter "sourceName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35005. sourceName
  35006. );
  35007. if (!targetName || typeof targetName !== "string")
  35008. throw new InvalidArgumentError2(
  35009. 'The parameter "targetName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35010. targetName
  35011. );
  35012. if (!relationName || typeof relationName !== "string")
  35013. throw new InvalidArgumentError2(
  35014. 'The parameter "relationName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35015. relationName
  35016. );
  35017. if (!foreignKey || typeof foreignKey !== "string")
  35018. throw new InvalidArgumentError2(
  35019. 'The parameter "foreignKey" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35020. foreignKey
  35021. );
  35022. if (!discriminator || typeof discriminator !== "string")
  35023. throw new InvalidArgumentError2(
  35024. 'The parameter "discriminator" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35025. discriminator
  35026. );
  35027. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35028. throw new InvalidArgumentError2(
  35029. 'The provided parameter "scope" of HasOneResolver.includePolymorphicTo should be an Object, but %v given.',
  35030. scope
  35031. );
  35032. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35033. sourceName
  35034. );
  35035. const sourceIds = [];
  35036. entities.forEach((entity) => {
  35037. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35038. throw new InvalidArgumentError2(
  35039. 'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35040. entity
  35041. );
  35042. const sourceId = entity[sourcePkPropName];
  35043. if (sourceIds.includes(sourceId)) return;
  35044. sourceIds.push(sourceId);
  35045. });
  35046. const promises = [];
  35047. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35048. scope = scope ? cloneDeep(scope) : {};
  35049. const targetBySourceId = /* @__PURE__ */ new Map();
  35050. sourceIds.forEach((sourceId) => {
  35051. const filter = cloneDeep(scope);
  35052. filter.where = {
  35053. and: [
  35054. { [foreignKey]: sourceId, [discriminator]: sourceName },
  35055. ...scope.where ? [scope.where] : []
  35056. ]
  35057. };
  35058. filter.limit = 1;
  35059. promises.push(
  35060. targetRepository.find(filter).then((result) => {
  35061. if (result.length) targetBySourceId.set(sourceId, result[0]);
  35062. })
  35063. );
  35064. });
  35065. await Promise.all(promises);
  35066. Array.from(targetBySourceId.keys()).forEach((sourceId) => {
  35067. const sources = entities.filter((v) => v[sourcePkPropName] === sourceId);
  35068. sources.forEach((v) => v[relationName] = targetBySourceId.get(sourceId));
  35069. });
  35070. }
  35071. /**
  35072. * Include polymorphic by relation name.
  35073. *
  35074. * @param {object[]} entities
  35075. * @param {string} sourceName
  35076. * @param {string} targetName
  35077. * @param {string} relationName
  35078. * @param {string} targetRelationName
  35079. * @param {object|undefined} scope
  35080. * @returns {Promise<void>}
  35081. */
  35082. async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
  35083. if (!entities || !Array.isArray(entities))
  35084. throw new InvalidArgumentError2(
  35085. 'The parameter "entities" of HasOneResolver.includePolymorphicByRelationName requires an Array of Object, but %v given.',
  35086. entities
  35087. );
  35088. if (!sourceName || typeof sourceName !== "string")
  35089. throw new InvalidArgumentError2(
  35090. 'The parameter "sourceName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35091. sourceName
  35092. );
  35093. if (!targetName || typeof targetName !== "string")
  35094. throw new InvalidArgumentError2(
  35095. 'The parameter "targetName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35096. targetName
  35097. );
  35098. if (!relationName || typeof relationName !== "string")
  35099. throw new InvalidArgumentError2(
  35100. 'The parameter "relationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35101. relationName
  35102. );
  35103. if (!targetRelationName || typeof targetRelationName !== "string")
  35104. throw new InvalidArgumentError2(
  35105. 'The parameter "targetRelationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35106. targetRelationName
  35107. );
  35108. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35109. throw new InvalidArgumentError2(
  35110. 'The provided parameter "scope" of HasOneResolver.includePolymorphicByRelationName should be an Object, but %v given.',
  35111. scope
  35112. );
  35113. const targetRelationDef = this.getService(
  35114. ModelDefinitionUtils
  35115. ).getRelationDefinitionByName(targetName, targetRelationName);
  35116. if (targetRelationDef.type !== RelationType.BELONGS_TO)
  35117. throw new InvalidArgumentError2(
  35118. 'The relation %v of the model %v is a polymorphic "hasOne" relation, so it requires the target relation %v to be a polymorphic "belongsTo", but %v type given.',
  35119. relationName,
  35120. sourceName,
  35121. targetRelationName,
  35122. targetRelationDef.type
  35123. );
  35124. if (!targetRelationDef.polymorphic)
  35125. throw new InvalidArgumentError2(
  35126. 'The relation %v of the model %v is a polymorphic "hasOne" relation, so it requires the target relation %v to be a polymorphic too.',
  35127. relationName,
  35128. sourceName,
  35129. targetRelationName
  35130. );
  35131. const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
  35132. const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
  35133. return this.includePolymorphicTo(
  35134. entities,
  35135. sourceName,
  35136. targetName,
  35137. relationName,
  35138. foreignKey,
  35139. discriminator,
  35140. scope
  35141. );
  35142. }
  35143. };
  35144. }
  35145. });
  35146. // node_modules/@e22m4u/js-repository/src/relations/has-many-resolver.js
  35147. var HasManyResolver;
  35148. var init_has_many_resolver = __esm({
  35149. "node_modules/@e22m4u/js-repository/src/relations/has-many-resolver.js"() {
  35150. init_src2();
  35151. init_utils2();
  35152. init_definition();
  35153. init_errors2();
  35154. init_repository2();
  35155. init_definition();
  35156. HasManyResolver = class extends Service {
  35157. /**
  35158. * Include to.
  35159. *
  35160. * @param {object[]} entities
  35161. * @param {string} sourceName
  35162. * @param {string} targetName
  35163. * @param {string} relationName
  35164. * @param {string} foreignKey
  35165. * @param {object|undefined} scope
  35166. * @returns {Promise<void>}
  35167. */
  35168. async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
  35169. if (!entities || !Array.isArray(entities))
  35170. throw new InvalidArgumentError2(
  35171. 'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v given.',
  35172. entities
  35173. );
  35174. if (!sourceName || typeof sourceName !== "string")
  35175. throw new InvalidArgumentError2(
  35176. 'The parameter "sourceName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35177. sourceName
  35178. );
  35179. if (!targetName || typeof targetName !== "string")
  35180. throw new InvalidArgumentError2(
  35181. 'The parameter "targetName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35182. targetName
  35183. );
  35184. if (!relationName || typeof relationName !== "string")
  35185. throw new InvalidArgumentError2(
  35186. 'The parameter "relationName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35187. relationName
  35188. );
  35189. if (!foreignKey || typeof foreignKey !== "string")
  35190. throw new InvalidArgumentError2(
  35191. 'The parameter "foreignKey" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35192. foreignKey
  35193. );
  35194. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35195. throw new InvalidArgumentError2(
  35196. 'The provided parameter "scope" of HasManyResolver.includeTo should be an Object, but %v given.',
  35197. scope
  35198. );
  35199. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35200. sourceName
  35201. );
  35202. const sourceIds = [];
  35203. entities.forEach((entity) => {
  35204. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35205. throw new InvalidArgumentError2(
  35206. 'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v given.',
  35207. entity
  35208. );
  35209. const sourceId = entity[sourcePkPropName];
  35210. if (sourceIds.includes(sourceId)) return;
  35211. sourceIds.push(sourceId);
  35212. });
  35213. const promises = [];
  35214. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35215. scope = scope ? cloneDeep(scope) : {};
  35216. const targetsBySourceId = /* @__PURE__ */ new Map();
  35217. sourceIds.forEach((sourceId) => {
  35218. const filter = cloneDeep(scope);
  35219. filter.where = {
  35220. and: [{ [foreignKey]: sourceId }, ...scope.where ? [scope.where] : []]
  35221. };
  35222. promises.push(
  35223. targetRepository.find(filter).then((result) => {
  35224. if (result.length) {
  35225. let targets = targetsBySourceId.get(sourceId) ?? [];
  35226. targets = [...targets, ...result];
  35227. targetsBySourceId.set(sourceId, targets);
  35228. }
  35229. })
  35230. );
  35231. });
  35232. await Promise.all(promises);
  35233. entities.forEach((entity) => {
  35234. const sourceId = entity[sourcePkPropName];
  35235. entity[relationName] = targetsBySourceId.get(sourceId) ?? [];
  35236. });
  35237. }
  35238. /**
  35239. * Include polymorphic to.
  35240. *
  35241. * @param {object[]} entities
  35242. * @param {string} sourceName
  35243. * @param {string} targetName
  35244. * @param {string} relationName
  35245. * @param {string} foreignKey
  35246. * @param {string} discriminator
  35247. * @param {object|undefined} scope
  35248. * @returns {Promise<void>}
  35249. */
  35250. async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
  35251. if (!entities || !Array.isArray(entities))
  35252. throw new InvalidArgumentError2(
  35253. 'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35254. entities
  35255. );
  35256. if (!sourceName || typeof sourceName !== "string")
  35257. throw new InvalidArgumentError2(
  35258. 'The parameter "sourceName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35259. sourceName
  35260. );
  35261. if (!targetName || typeof targetName !== "string")
  35262. throw new InvalidArgumentError2(
  35263. 'The parameter "targetName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35264. targetName
  35265. );
  35266. if (!relationName || typeof relationName !== "string")
  35267. throw new InvalidArgumentError2(
  35268. 'The parameter "relationName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35269. relationName
  35270. );
  35271. if (!foreignKey || typeof foreignKey !== "string")
  35272. throw new InvalidArgumentError2(
  35273. 'The parameter "foreignKey" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35274. foreignKey
  35275. );
  35276. if (!discriminator || typeof discriminator !== "string")
  35277. throw new InvalidArgumentError2(
  35278. 'The parameter "discriminator" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35279. discriminator
  35280. );
  35281. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35282. throw new InvalidArgumentError2(
  35283. 'The provided parameter "scope" of HasManyResolver.includePolymorphicTo should be an Object, but %v given.',
  35284. scope
  35285. );
  35286. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35287. sourceName
  35288. );
  35289. const sourceIds = [];
  35290. entities.forEach((entity) => {
  35291. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35292. throw new InvalidArgumentError2(
  35293. 'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35294. entity
  35295. );
  35296. const sourceId = entity[sourcePkPropName];
  35297. if (sourceIds.includes(sourceId)) return;
  35298. sourceIds.push(sourceId);
  35299. });
  35300. const promises = [];
  35301. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35302. scope = scope ? cloneDeep(scope) : {};
  35303. const targetsBySourceId = /* @__PURE__ */ new Map();
  35304. sourceIds.forEach((sourceId) => {
  35305. const filter = cloneDeep(scope);
  35306. filter.where = {
  35307. and: [
  35308. { [foreignKey]: sourceId, [discriminator]: sourceName },
  35309. ...scope.where ? [scope.where] : []
  35310. ]
  35311. };
  35312. promises.push(
  35313. targetRepository.find(filter).then((result) => {
  35314. if (result.length) {
  35315. let targets = targetsBySourceId.get(sourceId) ?? [];
  35316. targets = [...targets, ...result];
  35317. targetsBySourceId.set(sourceId, targets);
  35318. }
  35319. })
  35320. );
  35321. });
  35322. await Promise.all(promises);
  35323. entities.forEach((entity) => {
  35324. const sourceId = entity[sourcePkPropName];
  35325. entity[relationName] = targetsBySourceId.get(sourceId) ?? [];
  35326. });
  35327. }
  35328. /**
  35329. * Include polymorphic by relation name.
  35330. *
  35331. * @param {object[]} entities
  35332. * @param {string} sourceName
  35333. * @param {string} targetName
  35334. * @param {string} relationName
  35335. * @param {string} targetRelationName
  35336. * @param {object|undefined} scope
  35337. * @returns {Promise<void>}
  35338. */
  35339. async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
  35340. if (!entities || !Array.isArray(entities))
  35341. throw new InvalidArgumentError2(
  35342. 'The parameter "entities" of HasManyResolver.includePolymorphicByRelationName requires an Array of Object, but %v given.',
  35343. entities
  35344. );
  35345. if (!sourceName || typeof sourceName !== "string")
  35346. throw new InvalidArgumentError2(
  35347. 'The parameter "sourceName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35348. sourceName
  35349. );
  35350. if (!targetName || typeof targetName !== "string")
  35351. throw new InvalidArgumentError2(
  35352. 'The parameter "targetName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35353. targetName
  35354. );
  35355. if (!relationName || typeof relationName !== "string")
  35356. throw new InvalidArgumentError2(
  35357. 'The parameter "relationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35358. relationName
  35359. );
  35360. if (!targetRelationName || typeof targetRelationName !== "string")
  35361. throw new InvalidArgumentError2(
  35362. 'The parameter "targetRelationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35363. targetRelationName
  35364. );
  35365. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35366. throw new InvalidArgumentError2(
  35367. 'The provided parameter "scope" of HasManyResolver.includePolymorphicByRelationName should be an Object, but %v given.',
  35368. scope
  35369. );
  35370. const targetRelationDef = this.getService(
  35371. ModelDefinitionUtils
  35372. ).getRelationDefinitionByName(targetName, targetRelationName);
  35373. if (targetRelationDef.type !== RelationType.BELONGS_TO)
  35374. throw new InvalidArgumentError2(
  35375. 'The relation %v of the model %v is a polymorphic "hasMany" relation, so it requires the target relation %v to be a polymorphic "belongsTo", but %v type given.',
  35376. relationName,
  35377. sourceName,
  35378. targetRelationName,
  35379. targetRelationDef.type
  35380. );
  35381. if (!targetRelationDef.polymorphic)
  35382. throw new InvalidArgumentError2(
  35383. 'The relation %v of the model %v is a polymorphic "hasMany" relation, so it requires the target relation %v to be a polymorphic too.',
  35384. relationName,
  35385. sourceName,
  35386. targetRelationName
  35387. );
  35388. const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
  35389. const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
  35390. return this.includePolymorphicTo(
  35391. entities,
  35392. sourceName,
  35393. targetName,
  35394. relationName,
  35395. foreignKey,
  35396. discriminator,
  35397. scope
  35398. );
  35399. }
  35400. };
  35401. }
  35402. });
  35403. // node_modules/@e22m4u/js-repository/src/relations/belongs-to-resolver.js
  35404. var BelongsToResolver;
  35405. var init_belongs_to_resolver = __esm({
  35406. "node_modules/@e22m4u/js-repository/src/relations/belongs-to-resolver.js"() {
  35407. init_src2();
  35408. init_utils2();
  35409. init_utils2();
  35410. init_errors2();
  35411. init_repository2();
  35412. init_definition();
  35413. BelongsToResolver = class extends Service {
  35414. /**
  35415. * Include to.
  35416. *
  35417. * @param {object[]} entities
  35418. * @param {string} sourceName
  35419. * @param {string} targetName
  35420. * @param {string} relationName
  35421. * @param {string|undefined} foreignKey
  35422. * @param {object|undefined} scope
  35423. * @returns {Promise<void>}
  35424. */
  35425. async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
  35426. if (!entities || !Array.isArray(entities))
  35427. throw new InvalidArgumentError2(
  35428. 'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v given.',
  35429. entities
  35430. );
  35431. if (!sourceName || typeof sourceName !== "string")
  35432. throw new InvalidArgumentError2(
  35433. 'The parameter "sourceName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35434. sourceName
  35435. );
  35436. if (!targetName || typeof targetName !== "string")
  35437. throw new InvalidArgumentError2(
  35438. 'The parameter "targetName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35439. targetName
  35440. );
  35441. if (!relationName || typeof relationName !== "string")
  35442. throw new InvalidArgumentError2(
  35443. 'The parameter "relationName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35444. relationName
  35445. );
  35446. if (foreignKey && typeof foreignKey !== "string")
  35447. throw new InvalidArgumentError2(
  35448. 'The provided parameter "foreignKey" of BelongsToResolver.includeTo should be a String, but %v given.',
  35449. foreignKey
  35450. );
  35451. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35452. throw new InvalidArgumentError2(
  35453. 'The provided parameter "scope" of BelongsToResolver.includeTo should be an Object, but %v given.',
  35454. scope
  35455. );
  35456. if (foreignKey == null) foreignKey = `${relationName}Id`;
  35457. const targetIds = entities.reduce((acc, entity) => {
  35458. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35459. throw new InvalidArgumentError2(
  35460. 'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v given.',
  35461. entity
  35462. );
  35463. const targetId = entity[foreignKey];
  35464. return targetId != null ? [...acc, targetId] : acc;
  35465. }, []);
  35466. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35467. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35468. targetName
  35469. );
  35470. scope = scope ? cloneDeep(scope) : {};
  35471. const filter = cloneDeep(scope);
  35472. filter.where = {
  35473. and: [
  35474. { [targetPkPropName]: { inq: targetIds } },
  35475. ...scope.where ? [scope.where] : []
  35476. ]
  35477. };
  35478. const targets = await targetRepository.find(filter);
  35479. entities.forEach((entity) => {
  35480. const target = targets.find(
  35481. (e) => e[targetPkPropName] === entity[foreignKey]
  35482. );
  35483. if (target) entity[relationName] = target;
  35484. });
  35485. }
  35486. /**
  35487. * Include polymorphic to.
  35488. *
  35489. * @param {object[]} entities
  35490. * @param {string} sourceName
  35491. * @param {string} relationName
  35492. * @param {string|undefined} foreignKey
  35493. * @param {string|undefined} discriminator
  35494. * @param {object|undefined} scope
  35495. * @returns {Promise<void>}
  35496. */
  35497. async includePolymorphicTo(entities, sourceName, relationName, foreignKey = void 0, discriminator = void 0, scope = void 0) {
  35498. if (!entities || !Array.isArray(entities))
  35499. throw new InvalidArgumentError2(
  35500. 'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35501. entities
  35502. );
  35503. if (!sourceName || typeof sourceName !== "string")
  35504. throw new InvalidArgumentError2(
  35505. 'The parameter "sourceName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35506. sourceName
  35507. );
  35508. if (!relationName || typeof relationName !== "string")
  35509. throw new InvalidArgumentError2(
  35510. 'The parameter "relationName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35511. relationName
  35512. );
  35513. if (foreignKey && typeof foreignKey !== "string")
  35514. throw new InvalidArgumentError2(
  35515. 'The provided parameter "foreignKey" of BelongsToResolver.includePolymorphicTo should be a String, but %v given.',
  35516. foreignKey
  35517. );
  35518. if (discriminator && typeof discriminator !== "string")
  35519. throw new InvalidArgumentError2(
  35520. 'The provided parameter "discriminator" of BelongsToResolver.includePolymorphicTo should be a String, but %v given.',
  35521. discriminator
  35522. );
  35523. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35524. throw new InvalidArgumentError2(
  35525. 'The provided parameter "scope" of BelongsToResolver.includePolymorphicTo should be an Object, but %v given.',
  35526. scope
  35527. );
  35528. if (foreignKey == null) {
  35529. const singularRelationName = singularize(relationName);
  35530. foreignKey = `${singularRelationName}Id`;
  35531. }
  35532. if (discriminator == null) {
  35533. const singularRelationName = singularize(relationName);
  35534. discriminator = `${singularRelationName}Type`;
  35535. }
  35536. const targetIdsByTargetName = {};
  35537. entities.forEach((entity) => {
  35538. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35539. throw new InvalidArgumentError2(
  35540. 'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35541. entity
  35542. );
  35543. const targetId = entity[foreignKey];
  35544. const targetName = entity[discriminator];
  35545. if (targetId == null || targetName == null) return;
  35546. if (targetIdsByTargetName[targetName] == null)
  35547. targetIdsByTargetName[targetName] = [];
  35548. if (!targetIdsByTargetName[targetName].includes(targetId))
  35549. targetIdsByTargetName[targetName].push(targetId);
  35550. });
  35551. const promises = [];
  35552. const targetNames = Object.keys(targetIdsByTargetName);
  35553. scope = scope ? cloneDeep(scope) : {};
  35554. const targetEntitiesByTargetNames = {};
  35555. targetNames.forEach((targetName) => {
  35556. let targetRepository;
  35557. try {
  35558. targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35559. } catch (error) {
  35560. if (error instanceof InvalidArgumentError2) {
  35561. if (error.message === `The model "${targetName}" is not defined.` || error.message === `The model "${targetName}" does not have a specified datasource.`) {
  35562. return;
  35563. }
  35564. } else {
  35565. throw error;
  35566. }
  35567. }
  35568. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35569. targetName
  35570. );
  35571. const targetFilter = cloneDeep(scope);
  35572. const targetIds = targetIdsByTargetName[targetName];
  35573. targetFilter.where = {
  35574. and: [
  35575. { [targetPkPropName]: { inq: targetIds } },
  35576. ...scope.where ? [scope.where] : []
  35577. ]
  35578. };
  35579. const promise = targetRepository.find(targetFilter).then((result) => {
  35580. targetEntitiesByTargetNames[targetName] = [
  35581. ...targetEntitiesByTargetNames[targetName] ?? [],
  35582. ...result
  35583. ];
  35584. });
  35585. promises.push(promise);
  35586. });
  35587. await Promise.all(promises);
  35588. entities.forEach((entity) => {
  35589. const targetId = entity[foreignKey];
  35590. const targetName = entity[discriminator];
  35591. if (targetId == null || targetName == null || targetEntitiesByTargetNames[targetName] == null) {
  35592. return;
  35593. }
  35594. const targetEntities = targetEntitiesByTargetNames[targetName] ?? [];
  35595. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35596. targetName
  35597. );
  35598. const target = targetEntities.find((e) => e[targetPkPropName] === targetId);
  35599. if (target) entity[relationName] = target;
  35600. });
  35601. }
  35602. };
  35603. }
  35604. });
  35605. // node_modules/@e22m4u/js-repository/src/relations/references-many-resolver.js
  35606. var ReferencesManyResolver;
  35607. var init_references_many_resolver = __esm({
  35608. "node_modules/@e22m4u/js-repository/src/relations/references-many-resolver.js"() {
  35609. init_src2();
  35610. init_utils2();
  35611. init_utils2();
  35612. init_errors2();
  35613. init_repository2();
  35614. init_definition();
  35615. ReferencesManyResolver = class extends Service {
  35616. /**
  35617. * Include to.
  35618. *
  35619. * @param {object[]} entities
  35620. * @param {string} sourceName
  35621. * @param {string} targetName
  35622. * @param {string} relationName
  35623. * @param {string|undefined} foreignKey
  35624. * @param {object|undefined} scope
  35625. * @returns {Promise<void>}
  35626. */
  35627. async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
  35628. if (!entities || !Array.isArray(entities))
  35629. throw new InvalidArgumentError2(
  35630. 'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v given.',
  35631. entities
  35632. );
  35633. if (!sourceName || typeof sourceName !== "string")
  35634. throw new InvalidArgumentError2(
  35635. 'The parameter "sourceName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35636. sourceName
  35637. );
  35638. if (!targetName || typeof targetName !== "string")
  35639. throw new InvalidArgumentError2(
  35640. 'The parameter "targetName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35641. targetName
  35642. );
  35643. if (!relationName || typeof relationName !== "string")
  35644. throw new InvalidArgumentError2(
  35645. 'The parameter "relationName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35646. relationName
  35647. );
  35648. if (foreignKey && typeof foreignKey !== "string")
  35649. throw new InvalidArgumentError2(
  35650. 'The provided parameter "foreignKey" of ReferencesManyResolver.includeTo should be a String, but %v given.',
  35651. foreignKey
  35652. );
  35653. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35654. throw new InvalidArgumentError2(
  35655. 'The provided parameter "scope" of ReferencesManyResolver.includeTo should be an Object, but %v given.',
  35656. scope
  35657. );
  35658. if (foreignKey == null) {
  35659. const singularRelationName = singularize(relationName);
  35660. foreignKey = `${singularRelationName}Ids`;
  35661. }
  35662. const targetIds = entities.reduce((acc, entity) => {
  35663. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35664. throw new InvalidArgumentError2(
  35665. 'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v given.',
  35666. entity
  35667. );
  35668. const ids = entity[foreignKey];
  35669. if (Array.isArray(ids))
  35670. ids.forEach((id) => {
  35671. if (id == null || acc.includes(id)) return;
  35672. acc.push(id);
  35673. });
  35674. return acc;
  35675. }, []);
  35676. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35677. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35678. targetName
  35679. );
  35680. scope = scope ? cloneDeep(scope) : {};
  35681. const filter = cloneDeep(scope);
  35682. filter.where = {
  35683. and: [
  35684. { [targetPkPropName]: { inq: targetIds } },
  35685. ...scope.where ? [scope.where] : []
  35686. ]
  35687. };
  35688. const targets = await targetRepository.find(filter);
  35689. entities.forEach((entity) => {
  35690. const ids = entity[foreignKey];
  35691. entity[relationName] = [];
  35692. if (Array.isArray(ids))
  35693. targets.forEach((target) => {
  35694. const targetId = target[targetPkPropName];
  35695. if (ids.includes(targetId)) entity[relationName].push(target);
  35696. });
  35697. });
  35698. }
  35699. };
  35700. }
  35701. });
  35702. // node_modules/@e22m4u/js-repository/src/relations/index.js
  35703. var init_relations2 = __esm({
  35704. "node_modules/@e22m4u/js-repository/src/relations/index.js"() {
  35705. init_has_one_resolver();
  35706. init_has_many_resolver();
  35707. init_belongs_to_resolver();
  35708. init_references_many_resolver();
  35709. }
  35710. });
  35711. // node_modules/@e22m4u/js-repository/src/filter/include-clause-tool.js
  35712. var IncludeClauseTool;
  35713. var init_include_clause_tool = __esm({
  35714. "node_modules/@e22m4u/js-repository/src/filter/include-clause-tool.js"() {
  35715. init_src2();
  35716. init_definition();
  35717. init_relations2();
  35718. init_relations2();
  35719. init_where_clause_tool();
  35720. init_order_clause_tool();
  35721. init_slice_clause_tool();
  35722. init_errors2();
  35723. init_relations2();
  35724. init_fields_clause_tool();
  35725. init_definition();
  35726. init_relations2();
  35727. IncludeClauseTool = class _IncludeClauseTool extends Service {
  35728. /**
  35729. * Include to.
  35730. *
  35731. * @param {object[]} entities
  35732. * @param {string} modelName
  35733. * @param {IncludeClause|undefined} clause
  35734. * @returns {Promise<void>}
  35735. */
  35736. async includeTo(entities, modelName, clause) {
  35737. clause = _IncludeClauseTool.normalizeIncludeClause(clause);
  35738. const promises = [];
  35739. clause.forEach((inclusion) => {
  35740. const relDef = this.getService(
  35741. ModelDefinitionUtils
  35742. ).getRelationDefinitionByName(modelName, inclusion.relation);
  35743. switch (relDef.type) {
  35744. // BELONGS_TO
  35745. case RelationType.BELONGS_TO:
  35746. if (relDef.polymorphic) {
  35747. promises.push(
  35748. this.getService(BelongsToResolver).includePolymorphicTo(
  35749. entities,
  35750. modelName,
  35751. inclusion.relation,
  35752. relDef.foreignKey,
  35753. relDef.discriminator,
  35754. inclusion.scope
  35755. )
  35756. );
  35757. } else {
  35758. promises.push(
  35759. this.getService(BelongsToResolver).includeTo(
  35760. entities,
  35761. modelName,
  35762. relDef.model,
  35763. inclusion.relation,
  35764. relDef.foreignKey,
  35765. inclusion.scope
  35766. )
  35767. );
  35768. }
  35769. break;
  35770. // HAS_ONE
  35771. case RelationType.HAS_ONE:
  35772. if (relDef.polymorphic && typeof relDef.polymorphic === "string") {
  35773. promises.push(
  35774. this.getService(HasOneResolver).includePolymorphicByRelationName(
  35775. entities,
  35776. modelName,
  35777. relDef.model,
  35778. inclusion.relation,
  35779. relDef.polymorphic,
  35780. inclusion.scope
  35781. )
  35782. );
  35783. } else if (relDef.polymorphic) {
  35784. promises.push(
  35785. this.getService(HasOneResolver).includePolymorphicTo(
  35786. entities,
  35787. modelName,
  35788. relDef.model,
  35789. inclusion.relation,
  35790. relDef.foreignKey,
  35791. relDef.discriminator,
  35792. inclusion.scope
  35793. )
  35794. );
  35795. } else {
  35796. promises.push(
  35797. this.getService(HasOneResolver).includeTo(
  35798. entities,
  35799. modelName,
  35800. relDef.model,
  35801. inclusion.relation,
  35802. relDef.foreignKey,
  35803. inclusion.scope
  35804. )
  35805. );
  35806. }
  35807. break;
  35808. // HAS_MANY
  35809. case RelationType.HAS_MANY:
  35810. if (relDef.polymorphic && typeof relDef.polymorphic === "string") {
  35811. promises.push(
  35812. this.getService(HasManyResolver).includePolymorphicByRelationName(
  35813. entities,
  35814. modelName,
  35815. relDef.model,
  35816. inclusion.relation,
  35817. relDef.polymorphic,
  35818. inclusion.scope
  35819. )
  35820. );
  35821. } else if (relDef.polymorphic) {
  35822. promises.push(
  35823. this.getService(HasManyResolver).includePolymorphicTo(
  35824. entities,
  35825. modelName,
  35826. relDef.model,
  35827. inclusion.relation,
  35828. relDef.foreignKey,
  35829. relDef.discriminator,
  35830. inclusion.scope
  35831. )
  35832. );
  35833. } else {
  35834. promises.push(
  35835. this.getService(HasManyResolver).includeTo(
  35836. entities,
  35837. modelName,
  35838. relDef.model,
  35839. inclusion.relation,
  35840. relDef.foreignKey,
  35841. inclusion.scope
  35842. )
  35843. );
  35844. }
  35845. break;
  35846. case RelationType.REFERENCES_MANY:
  35847. promises.push(
  35848. this.getService(ReferencesManyResolver).includeTo(
  35849. entities,
  35850. modelName,
  35851. relDef.model,
  35852. inclusion.relation,
  35853. relDef.foreignKey,
  35854. inclusion.scope
  35855. )
  35856. );
  35857. break;
  35858. default:
  35859. throw new InvalidArgumentError2(
  35860. "The relation type %v does not have an inclusion resolver.",
  35861. relDef.type
  35862. );
  35863. }
  35864. });
  35865. await Promise.all(promises);
  35866. }
  35867. /**
  35868. * Validate include clause.
  35869. *
  35870. * @param {IncludeClause|undefined} clause
  35871. */
  35872. static validateIncludeClause(clause) {
  35873. if (clause == null) {
  35874. } else if (clause && typeof clause === "string") {
  35875. } else if (Array.isArray(clause)) {
  35876. const relNames = [];
  35877. clause.flat(Infinity).forEach((el) => {
  35878. this.validateIncludeClause(el);
  35879. if (typeof el === "string") {
  35880. relNames.push(el);
  35881. } else if (typeof el === "object") {
  35882. Object.keys(el).forEach((key) => {
  35883. if (Object.prototype.hasOwnProperty.call(el, key))
  35884. relNames.push(key);
  35885. });
  35886. }
  35887. });
  35888. const duplicateNames = relNames.filter(
  35889. (name, i) => relNames.indexOf(name) !== i
  35890. );
  35891. if (duplicateNames.length)
  35892. throw new InvalidArgumentError2(
  35893. 'The provided option "include" has duplicates of %v.',
  35894. duplicateNames[0]
  35895. );
  35896. } else if (typeof clause === "object") {
  35897. if ("relation" in clause) {
  35898. if (!clause.relation || typeof clause.relation !== "string")
  35899. throw new InvalidArgumentError2(
  35900. 'The provided option "relation" should be a non-empty String, but %v given.',
  35901. clause.relation
  35902. );
  35903. if ("scope" in clause && clause) this.validateScopeClause(clause.scope);
  35904. } else {
  35905. Object.keys(clause).forEach((key) => {
  35906. if (!Object.prototype.hasOwnProperty.call(clause, key)) return;
  35907. this.validateIncludeClause(key);
  35908. this.validateIncludeClause(clause[key]);
  35909. });
  35910. }
  35911. } else {
  35912. throw new InvalidArgumentError2(
  35913. 'The provided option "include" should have a non-empty String, an Object or an Array, but %v given.',
  35914. clause
  35915. );
  35916. }
  35917. }
  35918. /**
  35919. * Validate scope clause.
  35920. *
  35921. * @param {object|undefined} clause
  35922. */
  35923. static validateScopeClause(clause) {
  35924. if (clause == null) return;
  35925. if (typeof clause !== "object" || Array.isArray(clause))
  35926. throw new InvalidArgumentError2(
  35927. 'The provided option "scope" should be an Object, but %v given.',
  35928. clause
  35929. );
  35930. if (clause.where != null) {
  35931. WhereClauseTool.validateWhereClause(clause.where);
  35932. }
  35933. if (clause.order != null) {
  35934. OrderClauseTool.validateOrderClause(clause.order);
  35935. }
  35936. if (clause.skip != null) {
  35937. SliceClauseTool.validateSkipClause(clause.skip);
  35938. }
  35939. if (clause.limit != null) {
  35940. SliceClauseTool.validateLimitClause(clause.limit);
  35941. }
  35942. if (clause.fields != null) {
  35943. FieldsClauseTool.validateFieldsClause(clause.fields);
  35944. }
  35945. if (clause.include != null) {
  35946. _IncludeClauseTool.validateIncludeClause(clause.include);
  35947. }
  35948. }
  35949. /**
  35950. * Normalize include clause.
  35951. *
  35952. * @param {IncludeClause|undefined} clause
  35953. * @returns {object[]}
  35954. */
  35955. static normalizeIncludeClause(clause) {
  35956. let result = [];
  35957. if (clause == null) {
  35958. return result;
  35959. } else if (clause && typeof clause === "string") {
  35960. result.push({ relation: clause });
  35961. } else if (Array.isArray(clause)) {
  35962. clause.flat(Infinity).forEach((el) => {
  35963. el = this.normalizeIncludeClause(el);
  35964. result = [...result, ...el];
  35965. });
  35966. const relNames = result.map((v) => v.relation);
  35967. const duplicateNames = relNames.filter(
  35968. (name, i) => relNames.indexOf(name) !== i
  35969. );
  35970. if (duplicateNames.length)
  35971. throw new InvalidArgumentError2(
  35972. 'The provided option "include" has duplicates of %v.',
  35973. duplicateNames[0]
  35974. );
  35975. } else if (typeof clause === "object") {
  35976. if ("relation" in clause) {
  35977. if (!clause.relation || typeof clause.relation !== "string")
  35978. throw new InvalidArgumentError2(
  35979. 'The provided option "relation" should be a non-empty String, but %v given.',
  35980. clause.relation
  35981. );
  35982. const normalized = { relation: clause.relation };
  35983. const scope = this.normalizeScopeClause(clause.scope);
  35984. if (scope) normalized.scope = scope;
  35985. result.push(normalized);
  35986. } else {
  35987. Object.keys(clause).forEach((key) => {
  35988. if (!Object.prototype.hasOwnProperty.call(clause, key)) return;
  35989. this.validateIncludeClause(key);
  35990. const normalized = { relation: key };
  35991. const include = this.normalizeIncludeClause(clause[key]);
  35992. if (include.length) normalized.scope = { include };
  35993. result.push(normalized);
  35994. });
  35995. }
  35996. } else {
  35997. throw new InvalidArgumentError2(
  35998. 'The provided option "include" should have a non-empty String, an Object or an Array, but %v given.',
  35999. clause
  36000. );
  36001. }
  36002. return result;
  36003. }
  36004. /**
  36005. * Normalize scope clause.
  36006. *
  36007. * @param {object|undefined} clause
  36008. * @returns {object|undefined}
  36009. */
  36010. static normalizeScopeClause(clause) {
  36011. if (clause == null) return;
  36012. if (typeof clause !== "object" || Array.isArray(clause))
  36013. throw new InvalidArgumentError2(
  36014. 'The provided option "scope" should be an Object, but %v given.',
  36015. clause
  36016. );
  36017. const result = {};
  36018. if (clause.where != null) {
  36019. WhereClauseTool.validateWhereClause(clause.where);
  36020. result.where = clause.where;
  36021. }
  36022. if (clause.order != null) {
  36023. OrderClauseTool.validateOrderClause(clause.order);
  36024. result.order = clause.order;
  36025. }
  36026. if (clause.skip != null) {
  36027. SliceClauseTool.validateSkipClause(clause.skip);
  36028. result.skip = clause.skip;
  36029. }
  36030. if (clause.limit != null) {
  36031. SliceClauseTool.validateLimitClause(clause.limit);
  36032. result.limit = clause.limit;
  36033. }
  36034. if (clause.fields != null) {
  36035. FieldsClauseTool.validateFieldsClause(clause.fields);
  36036. result.fields = clause.fields;
  36037. }
  36038. if (clause.include != null) {
  36039. result.include = this.normalizeIncludeClause(clause.include);
  36040. }
  36041. if (Object.keys(result).length) return result;
  36042. return void 0;
  36043. }
  36044. };
  36045. }
  36046. });
  36047. // node_modules/@e22m4u/js-repository/src/filter/index.js
  36048. var init_filter = __esm({
  36049. "node_modules/@e22m4u/js-repository/src/filter/index.js"() {
  36050. init_slice_clause_tool();
  36051. init_order_clause_tool();
  36052. init_where_clause_tool();
  36053. init_fields_clause_tool();
  36054. init_include_clause_tool();
  36055. init_operator_clause_tool();
  36056. }
  36057. });
  36058. // node_modules/@e22m4u/js-repository/src/adapter/decorator/inclusion-decorator.js
  36059. var InclusionDecorator;
  36060. var init_inclusion_decorator = __esm({
  36061. "node_modules/@e22m4u/js-repository/src/adapter/decorator/inclusion-decorator.js"() {
  36062. init_adapter();
  36063. init_src2();
  36064. init_filter();
  36065. init_errors2();
  36066. InclusionDecorator = class extends Service {
  36067. /**
  36068. * Decorate.
  36069. *
  36070. * @param {Adapter} adapter
  36071. */
  36072. decorate(adapter) {
  36073. if (!adapter || !(adapter instanceof Adapter))
  36074. throw new InvalidArgumentError2(
  36075. "The first argument of InclusionDecorator.decorate should be an Adapter instance, but %v given.",
  36076. adapter
  36077. );
  36078. const tool = adapter.getService(IncludeClauseTool);
  36079. const includeTo = (...args) => tool.includeTo(...args);
  36080. const create = adapter.create;
  36081. adapter.create = async function(modelName, modelData, filter) {
  36082. const retvalData = await create.call(this, modelName, modelData, filter);
  36083. if (filter && typeof filter === "object" && filter.include)
  36084. await includeTo([retvalData], modelName, filter.include);
  36085. return retvalData;
  36086. };
  36087. const replaceById = adapter.replaceById;
  36088. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36089. const retvalData = await replaceById.call(
  36090. this,
  36091. modelName,
  36092. id,
  36093. modelData,
  36094. filter
  36095. );
  36096. if (filter && typeof filter === "object" && filter.include)
  36097. await includeTo([retvalData], modelName, filter.include);
  36098. return retvalData;
  36099. };
  36100. const replaceOrCreate = adapter.replaceOrCreate;
  36101. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36102. const retvalData = await replaceOrCreate.call(
  36103. this,
  36104. modelName,
  36105. modelData,
  36106. filter
  36107. );
  36108. if (filter && typeof filter === "object" && filter.include)
  36109. await includeTo([retvalData], modelName, filter.include);
  36110. return retvalData;
  36111. };
  36112. const patchById = adapter.patchById;
  36113. adapter.patchById = async function(modelName, id, modelData, filter) {
  36114. const retvalData = await patchById.call(
  36115. this,
  36116. modelName,
  36117. id,
  36118. modelData,
  36119. filter
  36120. );
  36121. if (filter && typeof filter === "object" && filter.include)
  36122. await includeTo([retvalData], modelName, filter.include);
  36123. return retvalData;
  36124. };
  36125. const find = adapter.find;
  36126. adapter.find = async function(modelName, filter) {
  36127. const modelItems = await find.call(this, modelName, filter);
  36128. if (filter && typeof filter === "object" && filter.include)
  36129. await includeTo(modelItems, modelName, filter.include);
  36130. return modelItems;
  36131. };
  36132. const findById = adapter.findById;
  36133. adapter.findById = async function(modelName, id, filter) {
  36134. const retvalData = await findById.call(this, modelName, id, filter);
  36135. if (filter && typeof filter === "object" && filter.include)
  36136. await includeTo([retvalData], modelName, filter.include);
  36137. return retvalData;
  36138. };
  36139. }
  36140. };
  36141. }
  36142. });
  36143. // node_modules/@e22m4u/js-repository/src/adapter/decorator/default-values-decorator.js
  36144. var DefaultValuesDecorator;
  36145. var init_default_values_decorator = __esm({
  36146. "node_modules/@e22m4u/js-repository/src/adapter/decorator/default-values-decorator.js"() {
  36147. init_adapter();
  36148. init_src2();
  36149. init_errors2();
  36150. init_definition();
  36151. DefaultValuesDecorator = class extends Service {
  36152. /**
  36153. * Decorate.
  36154. *
  36155. * @param {Adapter} adapter
  36156. */
  36157. decorate(adapter) {
  36158. if (!adapter || !(adapter instanceof Adapter))
  36159. throw new InvalidArgumentError2(
  36160. "The first argument of DefaultValuesDecorator.decorate should be an Adapter instance, but %v given.",
  36161. adapter
  36162. );
  36163. const utils = adapter.getService(ModelDefinitionUtils);
  36164. const setDefaults = (...args) => utils.setDefaultValuesToEmptyProperties(...args);
  36165. const create = adapter.create;
  36166. adapter.create = function(modelName, modelData, filter) {
  36167. modelData = setDefaults(modelName, modelData);
  36168. return create.call(this, modelName, modelData, filter);
  36169. };
  36170. const replaceById = adapter.replaceById;
  36171. adapter.replaceById = function(modelName, id, modelData, filter) {
  36172. modelData = setDefaults(modelName, modelData);
  36173. return replaceById.call(this, modelName, id, modelData, filter);
  36174. };
  36175. const replaceOrCreate = adapter.replaceOrCreate;
  36176. adapter.replaceOrCreate = function(modelName, modelData, filter) {
  36177. modelData = setDefaults(modelName, modelData);
  36178. return replaceOrCreate.call(this, modelName, modelData, filter);
  36179. };
  36180. const patch = adapter.patch;
  36181. adapter.patch = function(modelName, modelData, where) {
  36182. modelData = setDefaults(modelName, modelData, true);
  36183. return patch.call(this, modelName, modelData, where);
  36184. };
  36185. const patchById = adapter.patchById;
  36186. adapter.patchById = function(modelName, id, modelData, filter) {
  36187. modelData = setDefaults(modelName, modelData, true);
  36188. return patchById.call(this, modelName, id, modelData, filter);
  36189. };
  36190. const find = adapter.find;
  36191. adapter.find = async function(modelName, filter) {
  36192. const modelItems = await find.call(this, modelName, filter);
  36193. return modelItems.map((modelItem) => setDefaults(modelName, modelItem));
  36194. };
  36195. const findById = adapter.findById;
  36196. adapter.findById = async function(modelName, id, filter) {
  36197. const retvalData = await findById.call(this, modelName, id, filter);
  36198. return setDefaults(modelName, retvalData);
  36199. };
  36200. }
  36201. };
  36202. }
  36203. });
  36204. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-sanitizing-decorator.js
  36205. var DataSanitizingDecorator;
  36206. var init_data_sanitizing_decorator = __esm({
  36207. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-sanitizing-decorator.js"() {
  36208. init_adapter();
  36209. init_src2();
  36210. init_errors2();
  36211. init_definition();
  36212. DataSanitizingDecorator = class extends Service {
  36213. /**
  36214. * Decorate.
  36215. *
  36216. * @param {Adapter} adapter
  36217. */
  36218. decorate(adapter) {
  36219. if (!adapter || !(adapter instanceof Adapter))
  36220. throw new InvalidArgumentError2(
  36221. "The first argument of DataSanitizingDecorator.decorate should be an Adapter instance, but %v given.",
  36222. adapter
  36223. );
  36224. const sanitizer = adapter.getService(ModelDataSanitizer);
  36225. const sanitize = (...args) => sanitizer.sanitize(...args);
  36226. const create = adapter.create;
  36227. adapter.create = async function(modelName, modelData, filter) {
  36228. modelData = sanitize(modelName, modelData);
  36229. return create.call(this, modelName, modelData, filter);
  36230. };
  36231. const replaceById = adapter.replaceById;
  36232. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36233. modelData = sanitize(modelName, modelData);
  36234. return replaceById.call(this, modelName, id, modelData, filter);
  36235. };
  36236. const replaceOrCreate = adapter.replaceOrCreate;
  36237. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36238. modelData = sanitize(modelName, modelData);
  36239. return replaceOrCreate.call(this, modelName, modelData, filter);
  36240. };
  36241. const patch = adapter.patch;
  36242. adapter.patch = async function(modelName, modelData, where) {
  36243. modelData = sanitize(modelName, modelData);
  36244. return patch.call(this, modelName, modelData, where);
  36245. };
  36246. const patchById = adapter.patchById;
  36247. adapter.patchById = async function(modelName, id, modelData, filter) {
  36248. modelData = sanitize(modelName, modelData);
  36249. return patchById.call(this, modelName, id, modelData, filter);
  36250. };
  36251. }
  36252. };
  36253. }
  36254. });
  36255. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-validation-decorator.js
  36256. var DataValidationDecorator;
  36257. var init_data_validation_decorator = __esm({
  36258. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-validation-decorator.js"() {
  36259. init_adapter();
  36260. init_src2();
  36261. init_errors2();
  36262. init_definition();
  36263. DataValidationDecorator = class extends Service {
  36264. /**
  36265. * Decorate.
  36266. *
  36267. * @param {Adapter} adapter
  36268. */
  36269. decorate(adapter) {
  36270. if (!adapter || !(adapter instanceof Adapter))
  36271. throw new InvalidArgumentError2(
  36272. "The first argument of DataValidationDecorator.decorate should be an Adapter instance, but %v given.",
  36273. adapter
  36274. );
  36275. const validator = this.getService(ModelDataValidator);
  36276. const create = adapter.create;
  36277. adapter.create = function(modelName, modelData, filter) {
  36278. validator.validate(modelName, modelData);
  36279. return create.call(this, modelName, modelData, filter);
  36280. };
  36281. const replaceById = adapter.replaceById;
  36282. adapter.replaceById = function(modelName, id, modelData, filter) {
  36283. validator.validate(modelName, modelData);
  36284. return replaceById.call(this, modelName, id, modelData, filter);
  36285. };
  36286. const replaceOrCreate = adapter.replaceOrCreate;
  36287. adapter.replaceOrCreate = function(modelName, modelData, filter) {
  36288. validator.validate(modelName, modelData);
  36289. return replaceOrCreate.call(this, modelName, modelData, filter);
  36290. };
  36291. const patch = adapter.patch;
  36292. adapter.patch = function(modelName, modelData, where) {
  36293. validator.validate(modelName, modelData, true);
  36294. return patch.call(this, modelName, modelData, where);
  36295. };
  36296. const patchById = adapter.patchById;
  36297. adapter.patchById = function(modelName, id, modelData, filter) {
  36298. validator.validate(modelName, modelData, true);
  36299. return patchById.call(this, modelName, id, modelData, filter);
  36300. };
  36301. }
  36302. };
  36303. }
  36304. });
  36305. // node_modules/@e22m4u/js-repository/src/adapter/decorator/fields-filtering-decorator.js
  36306. var FieldsFilteringDecorator;
  36307. var init_fields_filtering_decorator = __esm({
  36308. "node_modules/@e22m4u/js-repository/src/adapter/decorator/fields-filtering-decorator.js"() {
  36309. init_adapter();
  36310. init_src2();
  36311. init_filter();
  36312. init_errors2();
  36313. FieldsFilteringDecorator = class extends Service {
  36314. /**
  36315. * Decorate.
  36316. *
  36317. * @param {Adapter} adapter
  36318. */
  36319. decorate(adapter) {
  36320. if (!adapter || !(adapter instanceof Adapter))
  36321. throw new InvalidArgumentError2(
  36322. "The first argument of FieldsFilteringDecorator.decorate should be an Adapter instance, but %v given.",
  36323. adapter
  36324. );
  36325. const tool = adapter.getService(FieldsClauseTool);
  36326. const selectFields = (...args) => tool.filter(...args);
  36327. const create = adapter.create;
  36328. adapter.create = async function(modelName, modelData, filter) {
  36329. let result = await create.call(this, modelName, modelData, filter);
  36330. if (filter && typeof filter === "object" && filter.fields)
  36331. result = selectFields(result, modelName, filter.fields);
  36332. return result;
  36333. };
  36334. const replaceById = adapter.replaceById;
  36335. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36336. let result = await replaceById.call(
  36337. this,
  36338. modelName,
  36339. id,
  36340. modelData,
  36341. filter
  36342. );
  36343. if (filter && typeof filter === "object" && filter.fields)
  36344. result = selectFields(result, modelName, filter.fields);
  36345. return result;
  36346. };
  36347. const replaceOrCreate = adapter.replaceOrCreate;
  36348. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36349. let result = await replaceOrCreate.call(
  36350. this,
  36351. modelName,
  36352. modelData,
  36353. filter
  36354. );
  36355. if (filter && typeof filter === "object" && filter.fields)
  36356. result = selectFields(result, modelName, filter.fields);
  36357. return result;
  36358. };
  36359. const patchById = adapter.patchById;
  36360. adapter.patchById = async function(modelName, id, modelData, filter) {
  36361. let result = await patchById.call(this, modelName, id, modelData, filter);
  36362. if (filter && typeof filter === "object" && filter.fields)
  36363. result = selectFields(result, modelName, filter.fields);
  36364. return result;
  36365. };
  36366. const find = adapter.find;
  36367. adapter.find = async function(modelName, filter) {
  36368. let result = await find.call(this, modelName, filter);
  36369. if (filter && typeof filter === "object" && filter.fields)
  36370. result = selectFields(result, modelName, filter.fields);
  36371. return result;
  36372. };
  36373. const findById = adapter.findById;
  36374. adapter.findById = async function(modelName, id, filter) {
  36375. let result = await findById.call(this, modelName, id, filter);
  36376. if (filter && typeof filter === "object" && filter.fields)
  36377. result = selectFields(result, modelName, filter.fields);
  36378. return result;
  36379. };
  36380. }
  36381. };
  36382. }
  36383. });
  36384. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-transformation-decorator.js
  36385. var DataTransformationDecorator;
  36386. var init_data_transformation_decorator = __esm({
  36387. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-transformation-decorator.js"() {
  36388. init_adapter();
  36389. init_src2();
  36390. init_errors2();
  36391. init_definition();
  36392. DataTransformationDecorator = class extends Service {
  36393. /**
  36394. * Decorate.
  36395. *
  36396. * @param {Adapter} adapter
  36397. */
  36398. decorate(adapter) {
  36399. if (!adapter || !(adapter instanceof Adapter))
  36400. throw new InvalidArgumentError2(
  36401. "The first argument of DataTransformerDecorator.decorate should be an Adapter instance, but %v given.",
  36402. adapter
  36403. );
  36404. const transformer = this.getService(ModelDataTransformer);
  36405. const create = adapter.create;
  36406. adapter.create = async function(modelName, modelData, filter) {
  36407. modelData = await transformer.transform(modelName, modelData);
  36408. return create.call(this, modelName, modelData, filter);
  36409. };
  36410. const replaceById = adapter.replaceById;
  36411. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36412. modelData = await transformer.transform(modelName, modelData);
  36413. return replaceById.call(this, modelName, id, modelData, filter);
  36414. };
  36415. const replaceOrCreate = adapter.replaceOrCreate;
  36416. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36417. modelData = await transformer.transform(modelName, modelData);
  36418. return replaceOrCreate.call(this, modelName, modelData, filter);
  36419. };
  36420. const patch = adapter.patch;
  36421. adapter.patch = async function(modelName, modelData, where) {
  36422. modelData = await transformer.transform(modelName, modelData, true);
  36423. return patch.call(this, modelName, modelData, where);
  36424. };
  36425. const patchById = adapter.patchById;
  36426. adapter.patchById = async function(modelName, id, modelData, filter) {
  36427. modelData = await transformer.transform(modelName, modelData, true);
  36428. return patchById.call(this, modelName, id, modelData, filter);
  36429. };
  36430. }
  36431. };
  36432. }
  36433. });
  36434. // node_modules/@e22m4u/js-repository/src/adapter/decorator/property-uniqueness-decorator.js
  36435. var PropertyUniquenessDecorator;
  36436. var init_property_uniqueness_decorator = __esm({
  36437. "node_modules/@e22m4u/js-repository/src/adapter/decorator/property-uniqueness-decorator.js"() {
  36438. init_adapter();
  36439. init_src2();
  36440. init_errors2();
  36441. init_definition();
  36442. PropertyUniquenessDecorator = class extends Service {
  36443. /**
  36444. * Decorate.
  36445. *
  36446. * @param {Adapter} adapter
  36447. */
  36448. decorate(adapter) {
  36449. if (!adapter || !(adapter instanceof Adapter))
  36450. throw new InvalidArgumentError2(
  36451. "The first argument of PropertyUniquenessDecorator.decorate should be an Adapter instance, but %v given.",
  36452. adapter
  36453. );
  36454. const validator = this.getService(PropertyUniquenessValidator);
  36455. const create = adapter.create;
  36456. adapter.create = async function(modelName, modelData, filter) {
  36457. const countMethod = adapter.count.bind(adapter, modelName);
  36458. await validator.validate(countMethod, "create", modelName, modelData);
  36459. return create.call(this, modelName, modelData, filter);
  36460. };
  36461. const replaceById = adapter.replaceById;
  36462. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36463. const countMethod = adapter.count.bind(adapter, modelName);
  36464. await validator.validate(
  36465. countMethod,
  36466. "replaceById",
  36467. modelName,
  36468. modelData,
  36469. id
  36470. );
  36471. return replaceById.call(this, modelName, id, modelData, filter);
  36472. };
  36473. const replaceOrCreate = adapter.replaceOrCreate;
  36474. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36475. const countMethod = adapter.count.bind(adapter, modelName);
  36476. await validator.validate(
  36477. countMethod,
  36478. "replaceOrCreate",
  36479. modelName,
  36480. modelData
  36481. );
  36482. return replaceOrCreate.call(this, modelName, modelData, filter);
  36483. };
  36484. const patch = adapter.patch;
  36485. adapter.patch = async function(modelName, modelData, where) {
  36486. const countMethod = adapter.count.bind(adapter, modelName);
  36487. await validator.validate(countMethod, "patch", modelName, modelData);
  36488. return patch.call(this, modelName, modelData, where);
  36489. };
  36490. const patchById = adapter.patchById;
  36491. adapter.patchById = async function(modelName, id, modelData, filter) {
  36492. const countMethod = adapter.count.bind(adapter, modelName);
  36493. await validator.validate(
  36494. countMethod,
  36495. "patchById",
  36496. modelName,
  36497. modelData,
  36498. id
  36499. );
  36500. return patchById.call(this, modelName, id, modelData, filter);
  36501. };
  36502. }
  36503. };
  36504. }
  36505. });
  36506. // node_modules/@e22m4u/js-repository/src/adapter/decorator/index.js
  36507. var init_decorator = __esm({
  36508. "node_modules/@e22m4u/js-repository/src/adapter/decorator/index.js"() {
  36509. init_inclusion_decorator();
  36510. init_default_values_decorator();
  36511. init_data_sanitizing_decorator();
  36512. init_data_validation_decorator();
  36513. init_fields_filtering_decorator();
  36514. init_data_transformation_decorator();
  36515. init_property_uniqueness_decorator();
  36516. }
  36517. });
  36518. // node_modules/@e22m4u/js-repository/src/adapter/adapter.js
  36519. var Adapter;
  36520. var init_adapter = __esm({
  36521. "node_modules/@e22m4u/js-repository/src/adapter/adapter.js"() {
  36522. init_src2();
  36523. init_errors2();
  36524. init_decorator();
  36525. init_decorator();
  36526. init_decorator();
  36527. init_decorator();
  36528. init_decorator();
  36529. init_decorator();
  36530. init_decorator();
  36531. Adapter = class _Adapter extends Service {
  36532. /**
  36533. * Settings.
  36534. *
  36535. * @type {object|undefined}
  36536. */
  36537. _settings;
  36538. /**
  36539. * Settings.
  36540. *
  36541. * @returns {object|undefined}
  36542. */
  36543. get settings() {
  36544. return this._settings;
  36545. }
  36546. /**
  36547. * Constructor.
  36548. *
  36549. * @param {object|undefined} container
  36550. * @param {object|undefined} settings
  36551. */
  36552. constructor(container = void 0, settings = void 0) {
  36553. super(container);
  36554. this._settings = settings;
  36555. if (this.constructor !== _Adapter) {
  36556. this.getService(DataSanitizingDecorator).decorate(this);
  36557. this.getService(DefaultValuesDecorator).decorate(this);
  36558. this.getService(DataTransformationDecorator).decorate(this);
  36559. this.getService(DataValidationDecorator).decorate(this);
  36560. this.getService(PropertyUniquenessDecorator).decorate(this);
  36561. this.getService(FieldsFilteringDecorator).decorate(this);
  36562. this.getService(InclusionDecorator).decorate(this);
  36563. }
  36564. }
  36565. /**
  36566. * Create.
  36567. *
  36568. * @param {string} modelName
  36569. * @param {object} modelData
  36570. * @param {object|undefined} filter
  36571. * @returns {Promise<object>}
  36572. */
  36573. create(modelName, modelData, filter = void 0) {
  36574. throw new NotImplementedError(
  36575. "%s.create is not implemented.",
  36576. this.constructor.name
  36577. );
  36578. }
  36579. /**
  36580. * Replace by id.
  36581. *
  36582. * @param {string} modelName
  36583. * @param {number|string} id
  36584. * @param {object} modelData
  36585. * @param {object|undefined} filter
  36586. * @returns {Promise<object>}
  36587. */
  36588. replaceById(modelName, id, modelData, filter = void 0) {
  36589. throw new NotImplementedError(
  36590. "%s.replaceById is not implemented.",
  36591. this.constructor.name
  36592. );
  36593. }
  36594. /**
  36595. * Replace or create.
  36596. *
  36597. * @param {string} modelName
  36598. * @param {object} modelData
  36599. * @param {object|undefined} filter
  36600. * @returns {Promise<object>}
  36601. */
  36602. replaceOrCreate(modelName, modelData, filter = void 0) {
  36603. throw new NotImplementedError(
  36604. "%s.replaceOrCreate is not implemented.",
  36605. this.constructor.name
  36606. );
  36607. }
  36608. /**
  36609. * Patch.
  36610. *
  36611. * @param {string} modelName
  36612. * @param {object} modelData
  36613. * @param {object|undefined} where
  36614. * @returns {Promise<number>}
  36615. */
  36616. patch(modelName, modelData, where = void 0) {
  36617. throw new NotImplementedError(
  36618. "%s.patch is not implemented.",
  36619. this.constructor.name
  36620. );
  36621. }
  36622. /**
  36623. * Patch by id.
  36624. *
  36625. * @param {string} modelName
  36626. * @param {number|string} id
  36627. * @param {object} modelData
  36628. * @param {object|undefined} filter
  36629. * @returns {Promise<object>}
  36630. */
  36631. patchById(modelName, id, modelData, filter = void 0) {
  36632. throw new NotImplementedError(
  36633. "%s.patchById is not implemented.",
  36634. this.constructor.name
  36635. );
  36636. }
  36637. /**
  36638. * Find.
  36639. *
  36640. * @param {string} modelName
  36641. * @param {object|undefined} filter
  36642. * @returns {Promise<object[]>}
  36643. */
  36644. find(modelName, filter = void 0) {
  36645. throw new NotImplementedError(
  36646. "%s.find is not implemented.",
  36647. this.constructor.name
  36648. );
  36649. }
  36650. /**
  36651. * Find by id.
  36652. *
  36653. * @param {string} modelName
  36654. * @param {number|string} id
  36655. * @param {object|undefined} filter
  36656. * @returns {Promise<object>}
  36657. */
  36658. findById(modelName, id, filter = void 0) {
  36659. throw new NotImplementedError(
  36660. "%s.findById is not implemented.",
  36661. this.constructor.name
  36662. );
  36663. }
  36664. /**
  36665. * Delete.
  36666. *
  36667. * @param {string} modelName
  36668. * @param {object|undefined} where
  36669. * @returns {Promise<number>}
  36670. */
  36671. delete(modelName, where = void 0) {
  36672. throw new NotImplementedError(
  36673. "%s.delete is not implemented.",
  36674. this.constructor.name
  36675. );
  36676. }
  36677. /**
  36678. * Delete by id.
  36679. *
  36680. * @param {string} modelName
  36681. * @param {number|string} id
  36682. * @returns {Promise<boolean>}
  36683. */
  36684. deleteById(modelName, id) {
  36685. throw new NotImplementedError(
  36686. "%s.deleteById is not implemented.",
  36687. this.constructor.name
  36688. );
  36689. }
  36690. /**
  36691. * Exists.
  36692. *
  36693. * @param {string} modelName
  36694. * @param {number|string} id
  36695. * @returns {Promise<boolean>}
  36696. */
  36697. exists(modelName, id) {
  36698. throw new NotImplementedError(
  36699. "%s.exists is not implemented.",
  36700. this.constructor.name
  36701. );
  36702. }
  36703. /**
  36704. * Count.
  36705. *
  36706. * @param {string} modelName
  36707. * @param {object|undefined} where
  36708. * @returns {Promise<number>}
  36709. */
  36710. count(modelName, where = void 0) {
  36711. throw new NotImplementedError(
  36712. "%s.count is not implemented.",
  36713. this.constructor.name
  36714. );
  36715. }
  36716. };
  36717. }
  36718. });
  36719. // node_modules/@e22m4u/js-repository/src/adapter/builtin/memory-adapter.js
  36720. var memory_adapter_exports = {};
  36721. __export(memory_adapter_exports, {
  36722. MemoryAdapter: () => MemoryAdapter
  36723. });
  36724. var MemoryAdapter;
  36725. var init_memory_adapter = __esm({
  36726. "node_modules/@e22m4u/js-repository/src/adapter/builtin/memory-adapter.js"() {
  36727. init_adapter();
  36728. init_utils2();
  36729. init_utils2();
  36730. init_definition();
  36731. init_filter();
  36732. init_filter();
  36733. init_filter();
  36734. init_errors2();
  36735. init_definition();
  36736. MemoryAdapter = class extends Adapter {
  36737. /**
  36738. * Tables.
  36739. *
  36740. * @type {Map<string, Map<number, Record<string, any>>>}
  36741. */
  36742. _tables = /* @__PURE__ */ new Map();
  36743. /**
  36744. * Last ids.
  36745. *
  36746. * @type {Map<string, number>}
  36747. */
  36748. _lastIds = /* @__PURE__ */ new Map();
  36749. /**
  36750. * Get table or create.
  36751. *
  36752. * @param {string} modelName
  36753. * @returns {Map<number, object>}
  36754. */
  36755. _getTableOrCreate(modelName) {
  36756. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  36757. let table = this._tables.get(tableName);
  36758. if (table) return table;
  36759. table = /* @__PURE__ */ new Map();
  36760. this._tables.set(tableName, table);
  36761. return table;
  36762. }
  36763. /**
  36764. * Gen next id value.
  36765. *
  36766. * @param {string} modelName
  36767. * @param {string} propName
  36768. * @returns {number}
  36769. */
  36770. _genNextIdValue(modelName, propName) {
  36771. const propType = this.getService(
  36772. ModelDefinitionUtils
  36773. ).getDataTypeByPropertyName(modelName, propName);
  36774. if (propType !== DataType.ANY && propType !== DataType.NUMBER)
  36775. throw new InvalidArgumentError2(
  36776. "The memory adapter able to generate only Number identifiers, but the primary key %v of the model %v is defined as %s. Do provide your own value for the %v property, or change the type in the primary key definition to a Number that will be generated automatically.",
  36777. propName,
  36778. modelName,
  36779. capitalize(propType),
  36780. propName
  36781. );
  36782. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  36783. const lastId = this._lastIds.get(tableName) ?? 0;
  36784. const nextId = lastId + 1;
  36785. this._lastIds.set(tableName, nextId);
  36786. const table = this._getTableOrCreate(modelName);
  36787. const existedIds = Array.from(table.keys());
  36788. if (existedIds.includes(nextId))
  36789. return this._genNextIdValue(modelName, propName);
  36790. return nextId;
  36791. }
  36792. /**
  36793. * Create
  36794. *
  36795. * @param {string} modelName
  36796. * @param {object} modelData
  36797. * @param {object|undefined} filter
  36798. * @returns {Promise<object>}
  36799. */
  36800. // eslint-disable-next-line no-unused-vars
  36801. async create(modelName, modelData, filter = void 0) {
  36802. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36803. modelName
  36804. );
  36805. let idValue = modelData[pkPropName];
  36806. if (idValue == null || idValue === "" || idValue === 0) {
  36807. idValue = this._genNextIdValue(modelName, pkPropName);
  36808. }
  36809. const table = this._getTableOrCreate(modelName);
  36810. if (table.has(idValue))
  36811. throw new InvalidArgumentError2(
  36812. "The value %v of the primary key %v already exists in the model %v.",
  36813. idValue,
  36814. pkPropName,
  36815. modelName
  36816. );
  36817. modelData = cloneDeep(modelData);
  36818. modelData[pkPropName] = idValue;
  36819. const tableData = this.getService(
  36820. ModelDefinitionUtils
  36821. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36822. table.set(idValue, tableData);
  36823. return this.getService(
  36824. ModelDefinitionUtils
  36825. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36826. }
  36827. /**
  36828. * Replace by id.
  36829. *
  36830. * @param {string} modelName
  36831. * @param {string|number} id
  36832. * @param {object} modelData
  36833. * @param {object|undefined} filter
  36834. * @returns {Promise<object>}
  36835. */
  36836. // eslint-disable-next-line no-unused-vars
  36837. async replaceById(modelName, id, modelData, filter = void 0) {
  36838. const table = this._getTableOrCreate(modelName);
  36839. const isExists = table.has(id);
  36840. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36841. modelName
  36842. );
  36843. if (!isExists)
  36844. throw new InvalidArgumentError2(
  36845. "The value %v of the primary key %v does not exist in the model %v.",
  36846. id,
  36847. pkPropName,
  36848. modelName
  36849. );
  36850. modelData = cloneDeep(modelData);
  36851. modelData[pkPropName] = id;
  36852. const tableData = this.getService(
  36853. ModelDefinitionUtils
  36854. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36855. table.set(id, tableData);
  36856. return this.getService(
  36857. ModelDefinitionUtils
  36858. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36859. }
  36860. /**
  36861. * Replace or create.
  36862. *
  36863. * @param {string} modelName
  36864. * @param {object} modelData
  36865. * @param {object|undefined} filter
  36866. * @returns {Promise<object>}
  36867. */
  36868. async replaceOrCreate(modelName, modelData, filter = void 0) {
  36869. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36870. modelName
  36871. );
  36872. let idValue = modelData[pkPropName];
  36873. if (idValue == null || idValue === "" || idValue === 0) {
  36874. idValue = this._genNextIdValue(modelName, pkPropName);
  36875. }
  36876. const table = this._getTableOrCreate(modelName);
  36877. modelData = cloneDeep(modelData);
  36878. modelData[pkPropName] = idValue;
  36879. const tableData = this.getService(
  36880. ModelDefinitionUtils
  36881. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36882. table.set(idValue, tableData);
  36883. return this.getService(
  36884. ModelDefinitionUtils
  36885. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36886. }
  36887. /**
  36888. * Patch.
  36889. *
  36890. * @param {string} modelName
  36891. * @param {object} modelData
  36892. * @param {object|undefined} where
  36893. * @returns {Promise<number>}
  36894. */
  36895. async patch(modelName, modelData, where = void 0) {
  36896. const table = this._getTableOrCreate(modelName);
  36897. const tableItems = Array.from(table.values());
  36898. if (!tableItems.length) return 0;
  36899. let modelItems = tableItems.map(
  36900. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  36901. modelName,
  36902. tableItem
  36903. )
  36904. );
  36905. if (where && typeof where === "object")
  36906. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  36907. const size = modelItems.length;
  36908. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36909. modelName
  36910. );
  36911. modelData = cloneDeep(modelData);
  36912. delete modelData[pkPropName];
  36913. modelItems.forEach((existingModelData) => {
  36914. const mergedModelData = Object.assign({}, existingModelData, modelData);
  36915. const mergedTableData = this.getService(
  36916. ModelDefinitionUtils
  36917. ).convertPropertyNamesToColumnNames(modelName, mergedModelData);
  36918. const idValue = existingModelData[pkPropName];
  36919. table.set(idValue, mergedTableData);
  36920. });
  36921. return size;
  36922. }
  36923. /**
  36924. * Patch by id.
  36925. *
  36926. * @param {string} modelName
  36927. * @param {string|number} id
  36928. * @param {object} modelData
  36929. * @param {object|undefined} filter
  36930. * @returns {Promise<object>}
  36931. */
  36932. // eslint-disable-next-line no-unused-vars
  36933. async patchById(modelName, id, modelData, filter = void 0) {
  36934. const table = this._getTableOrCreate(modelName);
  36935. const existingTableData = table.get(id);
  36936. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36937. modelName
  36938. );
  36939. if (existingTableData == null)
  36940. throw new InvalidArgumentError2(
  36941. "The value %v of the primary key %v does not exist in the model %v.",
  36942. id,
  36943. pkPropName,
  36944. modelName
  36945. );
  36946. modelData = cloneDeep(modelData);
  36947. delete modelData[pkPropName];
  36948. const existingModelData = this.getService(
  36949. ModelDefinitionUtils
  36950. ).convertColumnNamesToPropertyNames(modelName, existingTableData);
  36951. const mergedModelData = Object.assign({}, existingModelData, modelData);
  36952. const mergedTableData = this.getService(
  36953. ModelDefinitionUtils
  36954. ).convertPropertyNamesToColumnNames(modelName, mergedModelData);
  36955. table.set(id, mergedTableData);
  36956. return this.getService(
  36957. ModelDefinitionUtils
  36958. ).convertColumnNamesToPropertyNames(modelName, mergedTableData);
  36959. }
  36960. /**
  36961. * Find.
  36962. *
  36963. * @param {string} modelName
  36964. * @param {object|undefined} filter
  36965. * @returns {Promise<object[]>}
  36966. */
  36967. async find(modelName, filter = void 0) {
  36968. const table = this._getTableOrCreate(modelName);
  36969. const tableItems = Array.from(table.values());
  36970. let modelItems = tableItems.map(
  36971. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  36972. modelName,
  36973. tableItem
  36974. )
  36975. );
  36976. if (filter && typeof filter === "object") {
  36977. if (filter.where)
  36978. modelItems = this.getService(WhereClauseTool).filter(
  36979. modelItems,
  36980. filter.where
  36981. );
  36982. if (filter.skip || filter.limit)
  36983. modelItems = this.getService(SliceClauseTool).slice(
  36984. modelItems,
  36985. filter.skip,
  36986. filter.limit
  36987. );
  36988. if (filter.order)
  36989. this.getService(OrderClauseTool).sort(modelItems, filter.order);
  36990. }
  36991. return modelItems;
  36992. }
  36993. /**
  36994. * Find by id.
  36995. *
  36996. * @param {string} modelName
  36997. * @param {string|number} id
  36998. * @param {object|undefined} filter
  36999. * @returns {Promise<object>}
  37000. */
  37001. // eslint-disable-next-line no-unused-vars
  37002. async findById(modelName, id, filter = void 0) {
  37003. const table = this._getTableOrCreate(modelName);
  37004. const tableData = table.get(id);
  37005. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37006. modelName
  37007. );
  37008. if (!tableData)
  37009. throw new InvalidArgumentError2(
  37010. "The value %v of the primary key %v does not exist in the model %v.",
  37011. id,
  37012. pkPropName,
  37013. modelName
  37014. );
  37015. return this.getService(
  37016. ModelDefinitionUtils
  37017. ).convertColumnNamesToPropertyNames(modelName, tableData);
  37018. }
  37019. /**
  37020. * Delete.
  37021. *
  37022. * @param {string} modelName
  37023. * @param {object|undefined} where
  37024. * @returns {Promise<number>}
  37025. */
  37026. async delete(modelName, where = void 0) {
  37027. const table = this._getTableOrCreate(modelName);
  37028. const tableItems = Array.from(table.values());
  37029. if (!tableItems.length) return 0;
  37030. let modelItems = tableItems.map(
  37031. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  37032. modelName,
  37033. tableItem
  37034. )
  37035. );
  37036. if (where && typeof where === "object")
  37037. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  37038. const size = modelItems.length;
  37039. const idPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37040. modelName
  37041. );
  37042. modelItems.forEach((modelData) => {
  37043. const idValue = modelData[idPropName];
  37044. table.delete(idValue);
  37045. });
  37046. return size;
  37047. }
  37048. /**
  37049. * Delete by id.
  37050. *
  37051. * @param {string} modelName
  37052. * @param {string|number} id
  37053. * @returns {Promise<boolean>}
  37054. */
  37055. async deleteById(modelName, id) {
  37056. const table = this._getTableOrCreate(modelName);
  37057. const isExists = table.has(id);
  37058. table.delete(id);
  37059. return isExists;
  37060. }
  37061. /**
  37062. * Exists.
  37063. *
  37064. * @param {string} modelName
  37065. * @param {string|number} id
  37066. * @returns {Promise<boolean>}
  37067. */
  37068. async exists(modelName, id) {
  37069. const table = this._getTableOrCreate(modelName);
  37070. return table.has(id);
  37071. }
  37072. /**
  37073. * Count.
  37074. *
  37075. * @param {string} modelName
  37076. * @param {object|undefined} where
  37077. * @returns {Promise<number>}
  37078. */
  37079. async count(modelName, where = void 0) {
  37080. const table = this._getTableOrCreate(modelName);
  37081. const tableItems = Array.from(table.values());
  37082. let modelItems = tableItems.map(
  37083. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  37084. modelName,
  37085. tableItem
  37086. )
  37087. );
  37088. if (where && typeof where === "object")
  37089. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  37090. return modelItems.length;
  37091. }
  37092. };
  37093. }
  37094. });
  37095. // import("./builtin/**/*-adapter.js") in node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js
  37096. var globImport_builtin_adapter_js;
  37097. var init_ = __esm({
  37098. 'import("./builtin/**/*-adapter.js") in node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js'() {
  37099. globImport_builtin_adapter_js = __glob({
  37100. "./builtin/memory-adapter.js": () => Promise.resolve().then(() => (init_memory_adapter(), memory_adapter_exports))
  37101. });
  37102. }
  37103. });
  37104. // node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js
  37105. function findAdapterCtorInModule(module2) {
  37106. let adapterCtor;
  37107. if (!module2 || typeof module2 !== "object" || Array.isArray(module2)) return;
  37108. for (const ctor of Object.values(module2)) {
  37109. if (typeof ctor === "function" && ctor.prototype instanceof Adapter) {
  37110. adapterCtor = ctor;
  37111. break;
  37112. }
  37113. }
  37114. return adapterCtor;
  37115. }
  37116. var AdapterLoader;
  37117. var init_adapter_loader = __esm({
  37118. "node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js"() {
  37119. init_adapter();
  37120. init_src2();
  37121. init_errors2();
  37122. init_();
  37123. AdapterLoader = class extends Service {
  37124. /**
  37125. * Load by name.
  37126. *
  37127. * @param {string} adapterName
  37128. * @param {object|undefined} settings
  37129. * @returns {Promise<Adapter>}
  37130. */
  37131. async loadByName(adapterName, settings = void 0) {
  37132. if (!adapterName || typeof adapterName !== "string")
  37133. throw new InvalidArgumentError2(
  37134. "The adapter name should be a non-empty String, but %v given.",
  37135. adapterName
  37136. );
  37137. let adapterCtor;
  37138. try {
  37139. const module2 = await globImport_builtin_adapter_js(`./builtin/${adapterName}-adapter.js`);
  37140. adapterCtor = findAdapterCtorInModule(module2);
  37141. } catch (e) {
  37142. }
  37143. if (!adapterCtor)
  37144. try {
  37145. const module2 = await import(`@e22m4u/js-repository-${adapterName}-adapter`);
  37146. adapterCtor = findAdapterCtorInModule(module2);
  37147. } catch (e) {
  37148. }
  37149. if (!adapterCtor)
  37150. throw new InvalidArgumentError2(
  37151. "The adapter %v is not found.",
  37152. adapterName
  37153. );
  37154. return new adapterCtor(this.container, settings);
  37155. }
  37156. };
  37157. }
  37158. });
  37159. // node_modules/@e22m4u/js-repository/src/adapter/adapter-registry.js
  37160. var AdapterRegistry;
  37161. var init_adapter_registry = __esm({
  37162. "node_modules/@e22m4u/js-repository/src/adapter/adapter-registry.js"() {
  37163. init_adapter();
  37164. init_src2();
  37165. init_adapter_loader();
  37166. init_definition();
  37167. AdapterRegistry = class extends Service {
  37168. /**
  37169. * Adapters.
  37170. *
  37171. * @type {object}
  37172. */
  37173. _adapters = {};
  37174. /**
  37175. * Get adapter.
  37176. *
  37177. * @param {string} datasourceName
  37178. * @returns {Promise<Adapter>}
  37179. */
  37180. async getAdapter(datasourceName) {
  37181. let adapter = this._adapters[datasourceName];
  37182. if (adapter) return adapter;
  37183. const datasource = this.getService(DefinitionRegistry).getDatasource(datasourceName);
  37184. const adapterName = datasource.adapter;
  37185. adapter = await this.getService(AdapterLoader).loadByName(
  37186. adapterName,
  37187. datasource
  37188. );
  37189. this._adapters[datasourceName] = adapter;
  37190. return adapter;
  37191. }
  37192. };
  37193. }
  37194. });
  37195. // node_modules/@e22m4u/js-repository/src/adapter/index.js
  37196. var init_adapter2 = __esm({
  37197. "node_modules/@e22m4u/js-repository/src/adapter/index.js"() {
  37198. init_adapter();
  37199. init_adapter_loader();
  37200. init_adapter_registry();
  37201. }
  37202. });
  37203. // node_modules/@e22m4u/js-repository/src/repository/repository.js
  37204. var Repository;
  37205. var init_repository = __esm({
  37206. "node_modules/@e22m4u/js-repository/src/repository/repository.js"() {
  37207. init_src2();
  37208. init_adapter2();
  37209. init_adapter2();
  37210. init_errors2();
  37211. init_definition();
  37212. Repository = class extends Service {
  37213. /**
  37214. * Model name.
  37215. *
  37216. * @type {string}
  37217. */
  37218. _modelName;
  37219. /**
  37220. * Model name.
  37221. *
  37222. * @returns {string}
  37223. */
  37224. get modelName() {
  37225. return this._modelName;
  37226. }
  37227. /**
  37228. * Datasource name.
  37229. *
  37230. * @type {string}
  37231. */
  37232. _datasourceName;
  37233. /**
  37234. * Datasource name.
  37235. *
  37236. * @returns {string}
  37237. */
  37238. get datasourceName() {
  37239. return this._datasourceName;
  37240. }
  37241. /**
  37242. * Constructor.
  37243. *
  37244. * @typedef {import('@e22m4u/js-service').ServiceContainer} ServiceContainer
  37245. * @param {ServiceContainer} container
  37246. * @param {string} modelName
  37247. */
  37248. constructor(container, modelName) {
  37249. super(container);
  37250. this._modelName = modelName;
  37251. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  37252. const datasourceName = modelDef.datasource;
  37253. if (!datasourceName)
  37254. throw new InvalidArgumentError2(
  37255. "The model %v does not have a specified datasource.",
  37256. modelName
  37257. );
  37258. this._datasourceName = datasourceName;
  37259. }
  37260. /**
  37261. * Get adapter.
  37262. *
  37263. * @returns {Adapter}
  37264. */
  37265. async getAdapter() {
  37266. return this.getService(AdapterRegistry).getAdapter(this.datasourceName);
  37267. }
  37268. /**
  37269. * Create.
  37270. *
  37271. * @param {object} data
  37272. * @param {object|undefined} filter
  37273. * @returns {Promise<object>}
  37274. */
  37275. async create(data, filter = void 0) {
  37276. const adapter = await this.getAdapter();
  37277. return adapter.create(this.modelName, data, filter);
  37278. }
  37279. /**
  37280. * Replace by id.
  37281. *
  37282. * @param {number|string} id
  37283. * @param {object} data
  37284. * @param {object|undefined} filter
  37285. * @returns {Promise<object>}
  37286. */
  37287. async replaceById(id, data, filter = void 0) {
  37288. const adapter = await this.getAdapter();
  37289. return adapter.replaceById(this.modelName, id, data, filter);
  37290. }
  37291. /**
  37292. * Replace or create.
  37293. *
  37294. * @param {object} data
  37295. * @param {object|undefined} filter
  37296. * @returns {Promise<object>}
  37297. */
  37298. async replaceOrCreate(data, filter = void 0) {
  37299. const adapter = await this.getAdapter();
  37300. return adapter.replaceOrCreate(this.modelName, data, filter);
  37301. }
  37302. /**
  37303. * Patch.
  37304. *
  37305. * @param {object} data
  37306. * @param {object|undefined} where
  37307. * @returns {Promise<number>}
  37308. */
  37309. async patch(data, where = void 0) {
  37310. const adapter = await this.getAdapter();
  37311. return adapter.patch(this.modelName, data, where);
  37312. }
  37313. /**
  37314. * Patch by id.
  37315. *
  37316. * @param {number|string} id
  37317. * @param {object} data
  37318. * @param {object|undefined} filter
  37319. * @returns {Promise<object>}
  37320. */
  37321. async patchById(id, data, filter = void 0) {
  37322. const adapter = await this.getAdapter();
  37323. return adapter.patchById(this.modelName, id, data, filter);
  37324. }
  37325. /**
  37326. * Find.
  37327. *
  37328. * @param {object|undefined} filter
  37329. * @returns {Promise<object[]>}
  37330. */
  37331. async find(filter = void 0) {
  37332. const adapter = await this.getAdapter();
  37333. return adapter.find(this.modelName, filter);
  37334. }
  37335. /**
  37336. * Find one.
  37337. *
  37338. * @param {object|undefined} filter
  37339. * @returns {Promise<object|undefined>}
  37340. */
  37341. async findOne(filter = void 0) {
  37342. const adapter = await this.getAdapter();
  37343. filter = filter ?? {};
  37344. filter.limit = 1;
  37345. const result = await adapter.find(this.modelName, filter);
  37346. return result.length ? result[0] : void 0;
  37347. }
  37348. /**
  37349. * Find by id.
  37350. *
  37351. * @param {number|string} id
  37352. * @param {object|undefined} filter
  37353. * @returns {Promise<object>}
  37354. */
  37355. async findById(id, filter = void 0) {
  37356. const adapter = await this.getAdapter();
  37357. return adapter.findById(this.modelName, id, filter);
  37358. }
  37359. /**
  37360. * Delete.
  37361. *
  37362. * @param {object|undefined} where
  37363. * @returns {Promise<number>}
  37364. */
  37365. async delete(where = void 0) {
  37366. const adapter = await this.getAdapter();
  37367. return adapter.delete(this.modelName, where);
  37368. }
  37369. /**
  37370. * Delete by id.
  37371. *
  37372. * @param {number|string} id
  37373. * @returns {Promise<boolean>}
  37374. */
  37375. async deleteById(id) {
  37376. const adapter = await this.getAdapter();
  37377. return adapter.deleteById(this.modelName, id);
  37378. }
  37379. /**
  37380. * Exists.
  37381. *
  37382. * @param {number|string} id
  37383. * @returns {Promise<boolean>}
  37384. */
  37385. async exists(id) {
  37386. const adapter = await this.getAdapter();
  37387. return adapter.exists(this.modelName, id);
  37388. }
  37389. /**
  37390. * Count.
  37391. *
  37392. * @param {object|undefined} where
  37393. * @returns {Promise<number>}
  37394. */
  37395. async count(where = void 0) {
  37396. const adapter = await this.getAdapter();
  37397. return adapter.count(this.modelName, where);
  37398. }
  37399. };
  37400. }
  37401. });
  37402. // node_modules/@e22m4u/js-repository/src/repository/repository-registry.js
  37403. var RepositoryRegistry;
  37404. var init_repository_registry = __esm({
  37405. "node_modules/@e22m4u/js-repository/src/repository/repository-registry.js"() {
  37406. init_src2();
  37407. init_repository();
  37408. init_errors2();
  37409. RepositoryRegistry = class extends Service {
  37410. /**
  37411. * Repositories.
  37412. *
  37413. * @type {object}
  37414. */
  37415. _repositories = {};
  37416. /**
  37417. * Repository ctor.
  37418. *
  37419. * @type {typeof Repository}
  37420. * @private
  37421. */
  37422. _repositoryCtor = Repository;
  37423. /**
  37424. * Set repository ctor.
  37425. *
  37426. * @param {typeof Repository} ctor
  37427. */
  37428. setRepositoryCtor(ctor) {
  37429. if (!ctor || typeof ctor !== "function" || !(ctor.prototype instanceof Repository)) {
  37430. throw new InvalidArgumentError2(
  37431. "The first argument of RepositoryRegistry.setRepositoryCtor must inherit from Repository class, but %v given.",
  37432. ctor
  37433. );
  37434. }
  37435. this._repositoryCtor = ctor;
  37436. }
  37437. /**
  37438. * Get repository.
  37439. *
  37440. * @param {string} modelName
  37441. * @returns {Repository}
  37442. */
  37443. getRepository(modelName) {
  37444. let repository = this._repositories[modelName];
  37445. if (repository) return repository;
  37446. repository = new this._repositoryCtor(this.container, modelName);
  37447. this._repositories[modelName] = repository;
  37448. return repository;
  37449. }
  37450. };
  37451. }
  37452. });
  37453. // node_modules/@e22m4u/js-repository/src/repository/index.js
  37454. var init_repository2 = __esm({
  37455. "node_modules/@e22m4u/js-repository/src/repository/index.js"() {
  37456. init_repository();
  37457. init_repository_registry();
  37458. }
  37459. });
  37460. // src/index.js
  37461. var src_exports = {};
  37462. __export(src_exports, {
  37463. MongodbAdapter: () => MongodbAdapter
  37464. });
  37465. module.exports = __toCommonJS(src_exports);
  37466. // src/mongodb-adapter.js
  37467. var import_mongodb2 = __toESM(require_lib3(), 1);
  37468. var import_mongodb3 = __toESM(require_lib3(), 1);
  37469. // src/utils/is-iso-date.js
  37470. function isIsoDate(value) {
  37471. if (!value) return false;
  37472. if (value instanceof Date) return true;
  37473. if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) return false;
  37474. const d = new Date(value);
  37475. return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === value;
  37476. }
  37477. // src/utils/is-object-id.js
  37478. var import_mongodb = __toESM(require_lib3(), 1);
  37479. function isObjectId(value) {
  37480. if (!value) return false;
  37481. if (value instanceof import_mongodb.ObjectId) return true;
  37482. if (typeof value !== "string") return false;
  37483. return value.match(/^[a-fA-F0-9]{24}$/) != null;
  37484. }
  37485. // node_modules/@e22m4u/js-repository/src/schema.js
  37486. init_src2();
  37487. init_repository2();
  37488. init_definition();
  37489. init_repository2();
  37490. // node_modules/@e22m4u/js-repository/src/index.js
  37491. init_utils2();
  37492. init_errors2();
  37493. init_filter();
  37494. init_adapter2();
  37495. init_relations2();
  37496. init_definition();
  37497. init_repository2();
  37498. // src/utils/create-mongodb-url.js
  37499. function createMongodbUrl(options = {}) {
  37500. if (!options || typeof options !== "object" || Array.isArray(options))
  37501. throw new InvalidArgumentError2(
  37502. 'The first argument of "createMongodbUrl" must be an Object, but %v given.',
  37503. options
  37504. );
  37505. if (options.protocol && typeof options.protocol !== "string")
  37506. throw new InvalidArgumentError2(
  37507. 'MongoDB option "protocol" must be a String, but %v given.',
  37508. options.protocol
  37509. );
  37510. if (options.hostname && typeof options.hostname !== "string")
  37511. throw new InvalidArgumentError2(
  37512. 'MongoDB option "hostname" must be a String, but %v given.',
  37513. options.hostname
  37514. );
  37515. if (options.host && typeof options.host !== "string")
  37516. throw new InvalidArgumentError2(
  37517. 'MongoDB option "host" must be a String, but %v given.',
  37518. options.host
  37519. );
  37520. if (options.port && typeof options.port !== "number" && typeof options.port !== "string") {
  37521. throw new InvalidArgumentError2(
  37522. 'MongoDB option "port" must be a Number or a String, but %v given.',
  37523. options.port
  37524. );
  37525. }
  37526. if (options.database && typeof options.database !== "string")
  37527. throw new InvalidArgumentError2(
  37528. 'MongoDB option "database" must be a String, but %v given.',
  37529. options.database
  37530. );
  37531. if (options.db && typeof options.db !== "string")
  37532. throw new InvalidArgumentError2(
  37533. 'MongoDB option "db" must be a String, but %v given.',
  37534. options.db
  37535. );
  37536. if (options.username && typeof options.username !== "string")
  37537. throw new InvalidArgumentError2(
  37538. 'MongoDB option "username" must be a String, but %v given.',
  37539. options.username
  37540. );
  37541. if (options.password && typeof options.password !== "string" && typeof options.password !== "number") {
  37542. throw new InvalidArgumentError2(
  37543. 'MongoDB option "password" must be a String or a Number, but %v given.',
  37544. options.password
  37545. );
  37546. }
  37547. if (options.pass && typeof options.pass !== "string" && typeof options.pass !== "number") {
  37548. throw new InvalidArgumentError2(
  37549. 'MongoDB option "pass" must be a String or a Number, but %v given.',
  37550. options.pass
  37551. );
  37552. }
  37553. const protocol = options.protocol || "mongodb";
  37554. const hostname = options.hostname || options.host || "127.0.0.1";
  37555. const port = options.port || 27017;
  37556. const database = options.database || options.db || "database";
  37557. const username = options.username || options.user;
  37558. const password = options.password || options.pass || void 0;
  37559. let portUrl = "";
  37560. if (protocol !== "mongodb+srv") {
  37561. portUrl = ":" + port;
  37562. }
  37563. if (username && password) {
  37564. return `${protocol}://${username}:${password}@${hostname}${portUrl}/${database}`;
  37565. } else {
  37566. return `${protocol}://${hostname}${portUrl}/${database}`;
  37567. }
  37568. }
  37569. // src/utils/transform-values-deep.js
  37570. function transformValuesDeep(value, transformer) {
  37571. if (!transformer || typeof transformer !== "function")
  37572. throw new InvalidArgumentError2(
  37573. 'The second argument of "transformValuesDeep" must be a Function, but %v given.',
  37574. transformer
  37575. );
  37576. if (Array.isArray(value)) {
  37577. value.forEach((v, i) => value[i] = transformValuesDeep(v, transformer));
  37578. return value;
  37579. } else if (value && typeof value === "object") {
  37580. if (!value.constructor || value.constructor && value.constructor.name === "Object") {
  37581. Object.keys(value).forEach((key) => {
  37582. if (Object.prototype.hasOwnProperty.call(value, key))
  37583. value[key] = transformValuesDeep(value[key], transformer);
  37584. });
  37585. return value;
  37586. } else {
  37587. return transformer(value);
  37588. }
  37589. } else {
  37590. return transformer(value);
  37591. }
  37592. }
  37593. // src/mongodb-adapter.js
  37594. var MONGODB_OPTION_NAMES = [
  37595. "appname",
  37596. "authMechanism",
  37597. "authMechanismProperties",
  37598. "authSource",
  37599. "compressors",
  37600. "connectTimeoutMS",
  37601. "directConnection",
  37602. "heartbeatFrequencyMS",
  37603. "journal",
  37604. "loadBalanced",
  37605. "localThresholdMS",
  37606. "maxIdleTimeMS",
  37607. "maxPoolSize",
  37608. "maxConnecting",
  37609. "maxStalenessSeconds",
  37610. "minPoolSize",
  37611. "proxyHost",
  37612. "proxyPort",
  37613. "proxyUsername",
  37614. "proxyPassword",
  37615. "readConcernLevel",
  37616. "readPreference",
  37617. "readPreferenceTags",
  37618. "replicaSet",
  37619. "retryReads",
  37620. "retryWrites",
  37621. "serverSelectionTimeoutMS",
  37622. "serverSelectionTryOnce",
  37623. "socketTimeoutMS",
  37624. "srvMaxHosts",
  37625. "srvServiceName",
  37626. "ssl",
  37627. "timeoutMS",
  37628. "tls",
  37629. "tlsAllowInvalidCertificates",
  37630. "tlsAllowInvalidHostnames",
  37631. "tlsCAFile",
  37632. "tlsCertificateKeyFile",
  37633. "tlsCertificateKeyFilePassword",
  37634. "tlsInsecure",
  37635. "w",
  37636. "waitQueueTimeoutMS",
  37637. "wTimeoutMS",
  37638. "zlibCompressionLevel"
  37639. ];
  37640. var DEFAULT_SETTINGS = {
  37641. // connectTimeoutMS: 2500,
  37642. // serverSelectionTimeoutMS: 2500,
  37643. };
  37644. var MongodbAdapter = class extends Adapter {
  37645. /**
  37646. * Mongodb instance.
  37647. *
  37648. * @type {MongoClient}
  37649. * @private
  37650. */
  37651. _client;
  37652. /**
  37653. * Client.
  37654. *
  37655. * @returns {MongoClient}
  37656. */
  37657. get client() {
  37658. return this._client;
  37659. }
  37660. /**
  37661. * Collections.
  37662. *
  37663. * @type {Map<any, any>}
  37664. * @private
  37665. */
  37666. _collections = /* @__PURE__ */ new Map();
  37667. /**
  37668. * Constructor.
  37669. *
  37670. * @param {ServiceContainer} container
  37671. * @param settings
  37672. */
  37673. constructor(container, settings) {
  37674. settings = Object.assign({}, DEFAULT_SETTINGS, settings || {});
  37675. settings.protocol = settings.protocol || "mongodb";
  37676. settings.hostname = settings.hostname || settings.host || "127.0.0.1";
  37677. settings.port = settings.port || 27017;
  37678. settings.database = settings.database || settings.db || "database";
  37679. super(container, settings);
  37680. const options = selectObjectKeys(this.settings, MONGODB_OPTION_NAMES);
  37681. const url = createMongodbUrl(this.settings);
  37682. this._client = new import_mongodb3.MongoClient(url, options);
  37683. }
  37684. /**
  37685. * Get id prop name.
  37686. *
  37687. * @param modelName
  37688. */
  37689. _getIdPropName(modelName) {
  37690. return this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37691. modelName
  37692. );
  37693. }
  37694. /**
  37695. * Get id col name.
  37696. *
  37697. * @param modelName
  37698. */
  37699. _getIdColName(modelName) {
  37700. return this.getService(ModelDefinitionUtils).getPrimaryKeyAsColumnName(
  37701. modelName
  37702. );
  37703. }
  37704. /**
  37705. * Coerce id.
  37706. *
  37707. * @param value
  37708. * @return {ObjectId|*}
  37709. * @private
  37710. */
  37711. _coerceId(value) {
  37712. if (value == null) return value;
  37713. if (isObjectId(value)) return new import_mongodb2.ObjectId(value);
  37714. return value;
  37715. }
  37716. /**
  37717. * Coerce date.
  37718. *
  37719. * @param value
  37720. * @returns {Date|*}
  37721. * @private
  37722. */
  37723. _coerceDate(value) {
  37724. if (value == null) return value;
  37725. if (value instanceof Date) return value;
  37726. if (isIsoDate(value)) return new Date(value);
  37727. return value;
  37728. }
  37729. /**
  37730. * To database.
  37731. *
  37732. * @param {string} modelName
  37733. * @param {object} modelData
  37734. * @return {object}
  37735. * @private
  37736. */
  37737. _toDatabase(modelName, modelData) {
  37738. const tableData = this.getService(
  37739. ModelDefinitionUtils
  37740. ).convertPropertyNamesToColumnNames(modelName, modelData);
  37741. const idColName = this._getIdColName(modelName);
  37742. if (idColName !== "id" && idColName !== "_id")
  37743. throw new InvalidArgumentError2(
  37744. 'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
  37745. idColName
  37746. );
  37747. if (idColName in tableData && idColName !== "_id") {
  37748. tableData._id = tableData[idColName];
  37749. delete tableData[idColName];
  37750. }
  37751. return transformValuesDeep(tableData, (value) => {
  37752. if (value instanceof import_mongodb2.ObjectId) return value;
  37753. if (value instanceof Date) return value;
  37754. if (isObjectId(value)) return new import_mongodb2.ObjectId(value);
  37755. if (isIsoDate(value)) return new Date(value);
  37756. return value;
  37757. });
  37758. }
  37759. /**
  37760. * From database.
  37761. *
  37762. * @param {string} modelName
  37763. * @param {object} tableData
  37764. * @return {object}
  37765. * @private
  37766. */
  37767. _fromDatabase(modelName, tableData) {
  37768. if ("_id" in tableData) {
  37769. const idColName = this._getIdColName(modelName);
  37770. if (idColName !== "id" && idColName !== "_id")
  37771. throw new InvalidArgumentError2(
  37772. 'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
  37773. idColName
  37774. );
  37775. if (idColName !== "_id") {
  37776. tableData[idColName] = tableData._id;
  37777. delete tableData._id;
  37778. }
  37779. }
  37780. const modelData = this.getService(
  37781. ModelDefinitionUtils
  37782. ).convertColumnNamesToPropertyNames(modelName, tableData);
  37783. return transformValuesDeep(modelData, (value) => {
  37784. if (value instanceof import_mongodb2.ObjectId) return String(value);
  37785. if (value instanceof Date) return value.toISOString();
  37786. return value;
  37787. });
  37788. }
  37789. /**
  37790. * Get collection.
  37791. *
  37792. * @param {string} modelName
  37793. * @return {*}
  37794. * @private
  37795. */
  37796. _getCollection(modelName) {
  37797. let collection = this._collections.get(modelName);
  37798. if (collection) return collection;
  37799. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  37800. collection = this.client.db(this.settings.database).collection(tableName);
  37801. this._collections.set(modelName, collection);
  37802. return collection;
  37803. }
  37804. /**
  37805. * Get id type.
  37806. *
  37807. * @param modelName
  37808. * @return {string|*}
  37809. * @private
  37810. */
  37811. _getIdType(modelName) {
  37812. const utils = this.getService(ModelDefinitionUtils);
  37813. const pkPropName = utils.getPrimaryKeyAsPropertyName(modelName);
  37814. return utils.getDataTypeByPropertyName(modelName, pkPropName);
  37815. }
  37816. /**
  37817. * Build projection.
  37818. *
  37819. * @param {string} modelName
  37820. * @param {string|string[]} fields
  37821. * @return {Record<string, number>|undefined}
  37822. * @private
  37823. */
  37824. _buildProjection(modelName, fields) {
  37825. if (fields == null) return;
  37826. if (Array.isArray(fields) === false) fields = [fields];
  37827. if (!fields.length) return;
  37828. if (fields.indexOf("_id") === -1) fields.push("_id");
  37829. return fields.reduce((acc, field) => {
  37830. if (!field || typeof field !== "string")
  37831. throw new InvalidArgumentError2(
  37832. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  37833. field
  37834. );
  37835. let colName = this._getColName(modelName, field);
  37836. acc[colName] = 1;
  37837. return acc;
  37838. }, {});
  37839. }
  37840. /**
  37841. * Get col name.
  37842. *
  37843. * @param {string} modelName
  37844. * @param {string} propName
  37845. * @return {string}
  37846. * @private
  37847. */
  37848. _getColName(modelName, propName) {
  37849. if (!propName || typeof propName !== "string")
  37850. throw new InvalidArgumentError2(
  37851. "A property name must be a non-empty String, but %v given.",
  37852. propName
  37853. );
  37854. const utils = this.getService(ModelDefinitionUtils);
  37855. let colName = propName;
  37856. try {
  37857. colName = utils.getColumnNameByPropertyName(modelName, propName);
  37858. } catch (error) {
  37859. if (!(error instanceof InvalidArgumentError2) || error.message.indexOf("does not have the property") === -1) {
  37860. throw error;
  37861. }
  37862. }
  37863. return colName;
  37864. }
  37865. /**
  37866. * Build sort.
  37867. *
  37868. * @param {string} modelName
  37869. * @param {string|string[]} clause
  37870. * @return {object|undefined}
  37871. * @private
  37872. */
  37873. _buildSort(modelName, clause) {
  37874. if (clause == null) return;
  37875. if (Array.isArray(clause) === false) clause = [clause];
  37876. if (!clause.length) return;
  37877. const utils = this.getService(ModelDefinitionUtils);
  37878. const idPropName = this._getIdPropName(modelName);
  37879. return clause.reduce((acc, order) => {
  37880. if (!order || typeof order !== "string")
  37881. throw new InvalidArgumentError2(
  37882. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  37883. order
  37884. );
  37885. const direction = order.match(/\s+(A|DE)SC$/);
  37886. let field = order.replace(/\s+(A|DE)SC$/, "").trim();
  37887. if (field === idPropName) {
  37888. field = "_id";
  37889. } else {
  37890. try {
  37891. field = utils.getColumnNameByPropertyName(modelName, field);
  37892. } catch (error) {
  37893. if (!(error instanceof InvalidArgumentError2) || error.message.indexOf("does not have the property") === -1) {
  37894. throw error;
  37895. }
  37896. }
  37897. }
  37898. acc[field] = direction && direction[1] === "DE" ? -1 : 1;
  37899. return acc;
  37900. }, {});
  37901. }
  37902. /**
  37903. * Build query.
  37904. *
  37905. * @param {string} modelName
  37906. * @param {object} clause
  37907. * @return {object}
  37908. * @private
  37909. */
  37910. _buildQuery(modelName, clause) {
  37911. if (clause == null) return;
  37912. if (typeof clause !== "object" || Array.isArray(clause))
  37913. throw new InvalidArgumentError2(
  37914. 'The provided option "where" should be an Object, but %v given.',
  37915. clause
  37916. );
  37917. const query = {};
  37918. const idPropName = this._getIdPropName(modelName);
  37919. Object.keys(clause).forEach((key) => {
  37920. if (String(key).indexOf("$") !== -1)
  37921. throw new InvalidArgumentError2(
  37922. 'The symbol "$" is not supported, but %v given.',
  37923. key
  37924. );
  37925. let cond = clause[key];
  37926. if (key === "and" || key === "or" || key === "nor") {
  37927. if (cond == null) return;
  37928. if (!Array.isArray(cond))
  37929. throw new InvalidOperatorValueError(key, "an Array", cond);
  37930. if (cond.length === 0) return;
  37931. cond = cond.map((c) => this._buildQuery(modelName, c));
  37932. cond = cond.filter((c) => c != null);
  37933. const opKey = "$" + key;
  37934. query[opKey] = query[opKey] ?? [];
  37935. query[opKey] = [...query[opKey], ...cond];
  37936. return;
  37937. }
  37938. if (key === idPropName) {
  37939. key = "_id";
  37940. } else {
  37941. key = this._getColName(modelName, key);
  37942. }
  37943. if (typeof cond === "string") {
  37944. query[key] = this._coerceId(cond);
  37945. query[key] = this._coerceDate(query[key]);
  37946. return;
  37947. }
  37948. if (cond instanceof import_mongodb2.ObjectId) {
  37949. query[key] = cond;
  37950. return;
  37951. }
  37952. if (cond && cond.constructor && cond.constructor.name === "Object") {
  37953. const opConds = [];
  37954. if ("eq" in cond) {
  37955. let eq = this._coerceId(cond.eq);
  37956. eq = this._coerceDate(eq);
  37957. opConds.push({ $eq: eq });
  37958. }
  37959. if ("neq" in cond) {
  37960. let neq = this._coerceId(cond.neq);
  37961. neq = this._coerceDate(neq);
  37962. opConds.push({ $ne: neq });
  37963. }
  37964. if ("gt" in cond) {
  37965. const gt = this._coerceDate(cond.gt);
  37966. opConds.push({ $gt: gt });
  37967. }
  37968. if ("lt" in cond) {
  37969. const lt = this._coerceDate(cond.lt);
  37970. opConds.push({ $lt: lt });
  37971. }
  37972. if ("gte" in cond) {
  37973. const gte = this._coerceDate(cond.gte);
  37974. opConds.push({ $gte: gte });
  37975. }
  37976. if ("lte" in cond) {
  37977. const lte = this._coerceDate(cond.lte);
  37978. opConds.push({ $lte: lte });
  37979. }
  37980. if ("inq" in cond) {
  37981. if (!cond.inq || !Array.isArray(cond.inq))
  37982. throw new InvalidOperatorValueError(
  37983. "inq",
  37984. "an Array of possible values",
  37985. cond.inq
  37986. );
  37987. const inq = cond.inq.map((v) => {
  37988. v = this._coerceId(v);
  37989. v = this._coerceDate(v);
  37990. return v;
  37991. });
  37992. opConds.push({ $in: inq });
  37993. }
  37994. if ("nin" in cond) {
  37995. if (!cond.nin || !Array.isArray(cond.nin))
  37996. throw new InvalidOperatorValueError(
  37997. "nin",
  37998. "an Array of possible values",
  37999. cond
  38000. );
  38001. const nin = cond.nin.map((v) => {
  38002. v = this._coerceId(v);
  38003. v = this._coerceDate(v);
  38004. return v;
  38005. });
  38006. opConds.push({ $nin: nin });
  38007. }
  38008. if ("between" in cond) {
  38009. if (!Array.isArray(cond.between) || cond.between.length !== 2)
  38010. throw new InvalidOperatorValueError(
  38011. "between",
  38012. "an Array of 2 elements",
  38013. cond.between
  38014. );
  38015. const gte = this._coerceDate(cond.between[0]);
  38016. const lte = this._coerceDate(cond.between[1]);
  38017. opConds.push({ $gte: gte, $lte: lte });
  38018. }
  38019. if ("exists" in cond) {
  38020. if (typeof cond.exists !== "boolean")
  38021. throw new InvalidOperatorValueError(
  38022. "exists",
  38023. "a Boolean",
  38024. cond.exists
  38025. );
  38026. opConds.push({ $exists: cond.exists });
  38027. }
  38028. if ("like" in cond) {
  38029. if (typeof cond.like !== "string" && !(cond.like instanceof RegExp))
  38030. throw new InvalidOperatorValueError(
  38031. "like",
  38032. "a String or RegExp",
  38033. cond.like
  38034. );
  38035. opConds.push({ $regex: stringToRegexp(cond.like) });
  38036. }
  38037. if ("nlike" in cond) {
  38038. if (typeof cond.nlike !== "string" && !(cond.nlike instanceof RegExp))
  38039. throw new InvalidOperatorValueError(
  38040. "nlike",
  38041. "a String or RegExp",
  38042. cond.nlike
  38043. );
  38044. opConds.push({ $not: stringToRegexp(cond.nlike) });
  38045. }
  38046. if ("ilike" in cond) {
  38047. if (typeof cond.ilike !== "string" && !(cond.ilike instanceof RegExp))
  38048. throw new InvalidOperatorValueError(
  38049. "ilike",
  38050. "a String or RegExp",
  38051. cond.ilike
  38052. );
  38053. opConds.push({ $regex: stringToRegexp(cond.ilike, "i") });
  38054. }
  38055. if ("nilike" in cond) {
  38056. if (typeof cond.nilike !== "string" && !(cond.nilike instanceof RegExp)) {
  38057. throw new InvalidOperatorValueError(
  38058. "nilike",
  38059. "a String or RegExp",
  38060. cond.nilike
  38061. );
  38062. }
  38063. opConds.push({ $not: stringToRegexp(cond.nilike, "i") });
  38064. }
  38065. if ("regexp" in cond) {
  38066. if (typeof cond.regexp !== "string" && !(cond.regexp instanceof RegExp)) {
  38067. throw new InvalidOperatorValueError(
  38068. "regexp",
  38069. "a String or RegExp",
  38070. cond.regexp
  38071. );
  38072. }
  38073. const flags = cond.flags || void 0;
  38074. if (flags && typeof flags !== "string")
  38075. throw new InvalidArgumentError2(
  38076. "RegExp flags must be a String, but %v given.",
  38077. cond.flags
  38078. );
  38079. opConds.push({ $regex: stringToRegexp(cond.regexp, flags) });
  38080. }
  38081. if (opConds.length === 1) {
  38082. query[key] = opConds[0];
  38083. } else if (opConds.length > 1) {
  38084. query["$and"] = query["$and"] ?? [];
  38085. opConds.forEach((c) => query["$and"].push({ [key]: c }));
  38086. }
  38087. return;
  38088. }
  38089. query[key] = cond;
  38090. });
  38091. return Object.keys(query).length ? query : void 0;
  38092. }
  38093. /**
  38094. * Create.
  38095. *
  38096. * @param {string} modelName
  38097. * @param {object} modelData
  38098. * @param {object|undefined} filter
  38099. * @return {Promise<object>}
  38100. */
  38101. async create(modelName, modelData, filter = void 0) {
  38102. const idPropName = this._getIdPropName(modelName);
  38103. const idValue = modelData[idPropName];
  38104. if (idValue == null || idValue === "" || idValue === 0) {
  38105. const pkType = this._getIdType(modelName);
  38106. if (pkType !== DataType.STRING && pkType !== DataType.ANY)
  38107. throw new InvalidArgumentError2(
  38108. "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
  38109. capitalize(pkType),
  38110. idPropName
  38111. );
  38112. delete modelData[idPropName];
  38113. }
  38114. const tableData = this._toDatabase(modelName, modelData);
  38115. const table = this._getCollection(modelName);
  38116. const { insertedId } = await table.insertOne(tableData);
  38117. const projection = this._buildProjection(
  38118. modelName,
  38119. filter && filter.fields
  38120. );
  38121. const insertedData = await table.findOne({ _id: insertedId }, { projection });
  38122. return this._fromDatabase(modelName, insertedData);
  38123. }
  38124. /**
  38125. * Replace by id.
  38126. *
  38127. * @param {string} modelName
  38128. * @param {string|number} id
  38129. * @param {object} modelData
  38130. * @param {object|undefined} filter
  38131. * @return {Promise<object>}
  38132. */
  38133. async replaceById(modelName, id, modelData, filter = void 0) {
  38134. id = this._coerceId(id);
  38135. const idPropName = this._getIdPropName(modelName);
  38136. modelData[idPropName] = id;
  38137. const tableData = this._toDatabase(modelName, modelData);
  38138. const table = this._getCollection(modelName);
  38139. const { matchedCount } = await table.replaceOne({ _id: id }, tableData);
  38140. if (matchedCount < 1)
  38141. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38142. const projection = this._buildProjection(
  38143. modelName,
  38144. filter && filter.fields
  38145. );
  38146. const replacedData = await table.findOne({ _id: id }, { projection });
  38147. return this._fromDatabase(modelName, replacedData);
  38148. }
  38149. /**
  38150. * Replace or create.
  38151. *
  38152. * @param {string} modelName
  38153. * @param {object} modelData
  38154. * @param {object|undefined} filter
  38155. * @return {Promise<object>}
  38156. */
  38157. async replaceOrCreate(modelName, modelData, filter = void 0) {
  38158. const idPropName = this._getIdPropName(modelName);
  38159. let idValue = modelData[idPropName];
  38160. idValue = this._coerceId(idValue);
  38161. if (idValue == null || idValue === "" || idValue === 0) {
  38162. const pkType = this._getIdType(modelName);
  38163. if (pkType !== DataType.STRING && pkType !== DataType.ANY)
  38164. throw new InvalidArgumentError2(
  38165. "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
  38166. capitalize(pkType),
  38167. idPropName
  38168. );
  38169. delete modelData[idPropName];
  38170. idValue = void 0;
  38171. }
  38172. const tableData = this._toDatabase(modelName, modelData);
  38173. const table = this._getCollection(modelName);
  38174. if (idValue == null) {
  38175. const { insertedId } = await table.insertOne(tableData);
  38176. idValue = insertedId;
  38177. } else {
  38178. const { upsertedId } = await table.replaceOne({ _id: idValue }, tableData, {
  38179. upsert: true
  38180. });
  38181. if (upsertedId) idValue = upsertedId;
  38182. }
  38183. const projection = this._buildProjection(
  38184. modelName,
  38185. filter && filter.fields
  38186. );
  38187. const upsertedData = await table.findOne({ _id: idValue }, { projection });
  38188. return this._fromDatabase(modelName, upsertedData);
  38189. }
  38190. /**
  38191. * Patch.
  38192. *
  38193. * @param {string} modelName
  38194. * @param {object} modelData
  38195. * @param {object|undefined} where
  38196. * @return {Promise<number>}
  38197. */
  38198. async patch(modelName, modelData, where = void 0) {
  38199. const idPropName = this._getIdPropName(modelName);
  38200. delete modelData[idPropName];
  38201. const query = this._buildQuery(modelName, where) || {};
  38202. const tableData = this._toDatabase(modelName, modelData);
  38203. const table = this._getCollection(modelName);
  38204. const { matchedCount } = await table.updateMany(query, { $set: tableData });
  38205. return matchedCount;
  38206. }
  38207. /**
  38208. * Patch by id.
  38209. *
  38210. * @param {string} modelName
  38211. * @param {string|number} id
  38212. * @param {object} modelData
  38213. * @param {object|undefined} filter
  38214. * @return {Promise<object>}
  38215. */
  38216. async patchById(modelName, id, modelData, filter = void 0) {
  38217. id = this._coerceId(id);
  38218. const idPropName = this._getIdPropName(modelName);
  38219. delete modelData[idPropName];
  38220. const tableData = this._toDatabase(modelName, modelData);
  38221. const table = this._getCollection(modelName);
  38222. const { matchedCount } = await table.updateOne({ _id: id }, { $set: tableData });
  38223. if (matchedCount < 1)
  38224. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38225. const projection = this._buildProjection(
  38226. modelName,
  38227. filter && filter.fields
  38228. );
  38229. const patchedData = await table.findOne({ _id: id }, { projection });
  38230. return this._fromDatabase(modelName, patchedData);
  38231. }
  38232. /**
  38233. * Find.
  38234. *
  38235. * @param {string} modelName
  38236. * @param {object|undefined} filter
  38237. * @return {Promise<object[]>}
  38238. */
  38239. async find(modelName, filter = void 0) {
  38240. filter = filter || {};
  38241. const query = this._buildQuery(modelName, filter.where);
  38242. const sort = this._buildSort(modelName, filter.order);
  38243. const limit = filter.limit || void 0;
  38244. const skip = filter.skip || void 0;
  38245. const projection = this._buildProjection(modelName, filter.fields);
  38246. const collection = this._getCollection(modelName);
  38247. const options = { sort, limit, skip, projection };
  38248. const tableItems = await collection.find(query, options).toArray();
  38249. return tableItems.map((v) => this._fromDatabase(modelName, v));
  38250. }
  38251. /**
  38252. * Find by id.
  38253. *
  38254. * @param {string} modelName
  38255. * @param {string|number} id
  38256. * @param {object|undefined} filter
  38257. * @return {Promise<object>}
  38258. */
  38259. async findById(modelName, id, filter = void 0) {
  38260. id = this._coerceId(id);
  38261. const table = this._getCollection(modelName);
  38262. const projection = this._buildProjection(
  38263. modelName,
  38264. filter && filter.fields
  38265. );
  38266. const patchedData = await table.findOne({ _id: id }, { projection });
  38267. if (!patchedData)
  38268. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38269. return this._fromDatabase(modelName, patchedData);
  38270. }
  38271. /**
  38272. * Delete.
  38273. *
  38274. * @param {string} modelName
  38275. * @param {object|undefined} where
  38276. * @return {Promise<number>}
  38277. */
  38278. async delete(modelName, where = void 0) {
  38279. const table = this._getCollection(modelName);
  38280. const query = this._buildQuery(modelName, where);
  38281. const { deletedCount } = await table.deleteMany(query);
  38282. return deletedCount;
  38283. }
  38284. /**
  38285. * Delete by id.
  38286. *
  38287. * @param {string} modelName
  38288. * @param {string|number} id
  38289. * @return {Promise<boolean>}
  38290. */
  38291. async deleteById(modelName, id) {
  38292. id = this._coerceId(id);
  38293. const table = this._getCollection(modelName);
  38294. const { deletedCount } = await table.deleteOne({ _id: id });
  38295. return deletedCount > 0;
  38296. }
  38297. /**
  38298. * Exists.
  38299. *
  38300. * @param {string} modelName
  38301. * @param {string|number} id
  38302. * @return {Promise<boolean>}
  38303. */
  38304. async exists(modelName, id) {
  38305. id = this._coerceId(id);
  38306. const table = this._getCollection(modelName);
  38307. const result = await table.findOne({ _id: id }, {});
  38308. return result != null;
  38309. }
  38310. /**
  38311. * Count.
  38312. *
  38313. * @param {string} modelName
  38314. * @param {object|undefined} where
  38315. * @return {Promise<number>}
  38316. */
  38317. async count(modelName, where = void 0) {
  38318. const query = this._buildQuery(modelName, where);
  38319. const table = this._getCollection(modelName);
  38320. return await table.count(query);
  38321. }
  38322. };
  38323. // Annotate the CommonJS export names for ESM import in node:
  38324. 0 && (module.exports = {
  38325. MongodbAdapter
  38326. });